Skip to content

Commit

Permalink
remove and refactor contracts from options to config
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Nov 3, 2023
1 parent 6e1b5d6 commit 83dea4f
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 45 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
- `@supercharge/contracts`
- `StateBag`: add `exists` method to determine whether the state bag contains an entry `key`, no matter what value is assigned to the key

### Removed
- `@supercharge/contracts`
- removed `BodyparserOptions`: use `BodyparserConfig` instead
- removed `CookieOptions`: use `CookieConfig` instead
- removed `CorsOptions`: use `CorsConfig` instead
- removed `HashBuilderOptions`: use `HashBuilderConfig` instead
- removed `StaticAssetsOptions`: use `StaticAssetsConfig` instead

### Breaking Changes
- all packages of the framework moved to ESM
- require Node.js v20
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/hashing/hash-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { BinaryToTextEncoding, Encoding } from 'node:crypto'

export type HashBuilderCallback = (hashBuilder: HashBuilder) => unknown

export interface HashBuilderOptions {
export interface HashBuilderConfig {
inputEncoding?: Encoding
outputEncoding: BinaryToTextEncoding
}
Expand Down
7 changes: 0 additions & 7 deletions packages/contracts/src/http/bodyparser-config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@

import { HttpMethods } from './methods.js'

/**
* @deprecated The `BodyparserOptions` is deprecated in favor of the `BodyparserConfig`
* interface. We’ll remove the `BodyparserOptions` interface in the upcoming release
* of the Supercharge framework. You might switch already to the renamed interface.
*/
export type BodyparserOptions = BodyparserConfig

export interface BodyparserConfig {
/**
* --------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/http/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { CookieOptions } from './cookie-options.js'
import { CookieConfig } from './cookie-config.js'

export interface HttpConfig {
/**
Expand All @@ -15,5 +15,5 @@ export interface HttpConfig {
/**
* The HTTP cookie options.
*/
cookie: CookieOptions
cookie: CookieConfig
}
2 changes: 1 addition & 1 deletion packages/contracts/src/http/cookie-bag.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { RequestCookieBuilderCallback, ResponseCookieBuilderCallback } from './cookie-options-builder.js'
import { RequestCookieBuilderCallback, ResponseCookieBuilderCallback } from './cookie-config-builder.js'

export interface CookieBag {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { CookieOptions } from './cookie-options.js'
import { CookieConfig } from './cookie-config.js'

export type RequestCookieBuilderCallback = (cookieBuilder: RequestCookieBuilder) => void
export type ResponseCookieBuilderCallback = (cookieBuilder: ResponseCookieBuilder) => void
Expand Down Expand Up @@ -71,5 +71,5 @@ export interface ResponseCookieBuilder {
/**
* Merge the given `config` with the default HTTP cookie config.
*/
useConfig (config: Partial<CookieOptions>): this
useConfig (config: Partial<CookieConfig>): this
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

export interface CookieOptions {
export interface CookieConfig {
/**
* The time or date in the future at which the cookie expires.
*/
Expand Down
7 changes: 0 additions & 7 deletions packages/contracts/src/http/cors-config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@

/**
* @deprecated The `CorsOptions` is deprecated in favor of the `CorsConfig`
* interface. We’ll remove the `CorsOptions` interface in the upcoming
* release of the Supercharge framework. You may already switch to the renamed interface.
*/
export type CorsOptions = CorsConfig

export interface CorsConfig {
/**
* Controls the `Access-Control-Max-Age` header in seconds.
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/src/http/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { HttpContext } from './context.js'
import { CookieBag } from './cookie-bag.js'
import { IncomingMessage } from 'node:http'
import { IncomingHttpHeaders } from 'node:http2'
import { CookieOptions } from './cookie-options.js'
import { CookieConfig } from './cookie-config.js'
import { MacroableCtor } from '@supercharge/macroable'
import { QueryParameterBag } from './query-parameter-bag.js'
import { InteractsWithState } from './concerns/interacts-with-state.js'
import { RequestCookieBuilderCallback } from './cookie-options-builder.js'
import { RequestCookieBuilderCallback } from './cookie-config-builder.js'
import { InteractsWithContentTypes } from './concerns/interacts-with-content-types.js'

export interface HttpRequestCtor extends MacroableCtor {
/**
* Create a new HTTP request instance.
*/
new (context: HttpContext, cookieOptions: CookieOptions): HttpRequest
new (context: HttpContext, cookieOptions: CookieConfig): HttpRequest
}

export type Protocol = 'http' | 'https' | string
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/src/http/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { HttpContext } from './context.js'
import { CookieBag } from './cookie-bag.js'
import { OutgoingHttpHeaders } from 'http2'
import { HttpRedirect } from './redirect.js'
import { CookieOptions } from './cookie-options.js'
import { CookieConfig } from './cookie-config.js'
import { MacroableCtor } from '@supercharge/macroable'
import { InteractsWithState } from './concerns/interacts-with-state.js'
import { ResponseCookieBuilderCallback } from './cookie-options-builder.js'
import { ResponseCookieBuilderCallback } from './cookie-config-builder.js'

export interface HttpResponseCtor extends MacroableCtor {
/**
* Create a new HTTP response instance.
*/
new (context: HttpContext, cookieOptions: CookieOptions): HttpResponse
new (context: HttpContext, cookieOptions: CookieConfig): HttpResponse
}

export interface HttpResponse<T = any> extends InteractsWithState {
Expand Down
7 changes: 0 additions & 7 deletions packages/contracts/src/http/static-assets-config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@

/**
* @deprecated The `StaticAssetsOptions` is deprecated in favor of the `StaticAssetsConfig`
* interface. We’ll remove the `StaticAssetsOptions` interface in the upcoming release
* of the Supercharge framework. You might switch already to the renamed interface.
*/
export type StaticAssetsOptions = StaticAssetsConfig

export interface StaticAssetsConfig {
/**
* Define the maximum amount of seconds to cache a static resource
Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ export { EnvStore } from './env/env.js'
export { Bootstrapper, BootstrapperCtor } from './core/bootstrapper.js'
export { ErrorHandler, ErrorHandlerCtor } from './core/error-handler.js'

export { HashBuilder, HashBuilderCallback, HashBuilderOptions } from './hashing/hash-builder.js'
export { HashBuilder, HashBuilderCallback, HashBuilderConfig } from './hashing/hash-builder.js'
export { HashConfig } from './hashing/config.js'
export { BaseHasher } from './hashing/base-hasher.js'
export { Hasher } from './hashing/hasher.js'

export { BodyparserConfig, BodyparserOptions } from './http/bodyparser-config.js'
export { BodyparserConfig } from './http/bodyparser-config.js'
export { HttpConfig } from './http/config.js'
export { HttpContext, NextHandler } from './http/context.js'
export { HttpController } from './http/controller.js'
export { CookieBag } from './http/cookie-bag.js'
export { CookieOptions } from './http/cookie-options.js'
export { RequestCookieBuilder, RequestCookieBuilderCallback, ResponseCookieBuilder, ResponseCookieBuilderCallback } from './http/cookie-options-builder.js'
export { CorsConfig, CorsOptions } from './http/cors-config.js'
export { CookieConfig } from './http/cookie-config.js'
export { RequestCookieBuilder, RequestCookieBuilderCallback, ResponseCookieBuilder, ResponseCookieBuilderCallback } from './http/cookie-config-builder.js'
export { CorsConfig } from './http/cors-config.js'
export { InteractsWithContentTypes } from './http/concerns/interacts-with-content-types.js'
export { InteractsWithState } from './http/concerns/interacts-with-state.js'
export { StateBag, HttpStateData } from './http/concerns/state-bag.js'
Expand All @@ -52,7 +52,7 @@ export { HttpRouteGroup } from './http/route-group.js'
export { HttpRoute, RouteObjectAttributes } from './http/route.js'
export { HttpRouter, RouteHandler, RouteAttributes } from './http/router.js'
export { HttpServer, HttpServerHandler } from './http/server.js'
export { StaticAssetsConfig, StaticAssetsOptions } from './http/static-assets-config.js'
export { StaticAssetsConfig } from './http/static-assets-config.js'
export { UploadedFile } from './http/uploaded-file.js'

export { LoggingConfig, LogChannelConfig, LoggingChannels, ConsoleChannelConfig, FileChannelConfig } from './logging/config.js'
Expand Down
10 changes: 5 additions & 5 deletions packages/view/src/engines/handlebars/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import Path from 'node:path'
import Fs from '@supercharge/fs'
import { fileURLToPath } from 'node:url'
import { resolveDefaultImport, tap } from '@supercharge/goodies'
import { Str } from '@supercharge/strings'
import { Collect } from '@supercharge/collections'
import Handlebars, { HelperDelegate } from 'handlebars'
import { resolveDefaultImport, tap } from '@supercharge/goodies'
import { Logger, ViewConfig, ViewEngine, ViewResponseConfig } from '@supercharge/contracts'

export class HandlebarsCompiler implements ViewEngine {
Expand Down Expand Up @@ -288,16 +288,16 @@ export class HandlebarsCompiler implements ViewEngine {
/**
* Compile the given `template` to a render function.
*/
async compile (view: string, options: ReadTemplateOptions = {}): Promise<HandlebarsTemplateDelegate> {
async compile (view: string, config: ReadTemplateConfig = {}): Promise<HandlebarsTemplateDelegate> {
return this.handlebars.compile(
await this.readTemplate(view, options)
await this.readTemplate(view, config)
)
}

/**
* Reads and returns the view `template` from the hard disk.
*/
async readTemplate (template: string, { isLayout = false }: ReadTemplateOptions): Promise<string> {
async readTemplate (template: string, { isLayout = false }: ReadTemplateConfig): Promise<string> {
const view = isLayout
? Path.resolve(await this.layoutLocation(), template)
: Path.resolve(await this.viewsLocation(), template)
Expand Down Expand Up @@ -328,6 +328,6 @@ export class HandlebarsCompiler implements ViewEngine {
}
}

interface ReadTemplateOptions {
interface ReadTemplateConfig {
isLayout?: boolean
}

0 comments on commit 83dea4f

Please sign in to comment.