Skip to content

Commit 83dea4f

Browse files
committed
remove and refactor contracts from options to config
1 parent 6e1b5d6 commit 83dea4f

File tree

13 files changed

+32
-45
lines changed

13 files changed

+32
-45
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
- `@supercharge/contracts`
1818
- `StateBag`: add `exists` method to determine whether the state bag contains an entry `key`, no matter what value is assigned to the key
1919

20+
### Removed
21+
- `@supercharge/contracts`
22+
- removed `BodyparserOptions`: use `BodyparserConfig` instead
23+
- removed `CookieOptions`: use `CookieConfig` instead
24+
- removed `CorsOptions`: use `CorsConfig` instead
25+
- removed `HashBuilderOptions`: use `HashBuilderConfig` instead
26+
- removed `StaticAssetsOptions`: use `StaticAssetsConfig` instead
27+
2028
### Breaking Changes
2129
- all packages of the framework moved to ESM
2230
- require Node.js v20

packages/contracts/src/hashing/hash-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { BinaryToTextEncoding, Encoding } from 'node:crypto'
33

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

6-
export interface HashBuilderOptions {
6+
export interface HashBuilderConfig {
77
inputEncoding?: Encoding
88
outputEncoding: BinaryToTextEncoding
99
}

packages/contracts/src/http/bodyparser-config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11

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

4-
/**
5-
* @deprecated The `BodyparserOptions` is deprecated in favor of the `BodyparserConfig`
6-
* interface. We’ll remove the `BodyparserOptions` interface in the upcoming release
7-
* of the Supercharge framework. You might switch already to the renamed interface.
8-
*/
9-
export type BodyparserOptions = BodyparserConfig
10-
114
export interface BodyparserConfig {
125
/**
136
* --------------------------------------------------------------------------

packages/contracts/src/http/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

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

44
export interface HttpConfig {
55
/**
@@ -15,5 +15,5 @@ export interface HttpConfig {
1515
/**
1616
* The HTTP cookie options.
1717
*/
18-
cookie: CookieOptions
18+
cookie: CookieConfig
1919
}

packages/contracts/src/http/cookie-bag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

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

44
export interface CookieBag {
55
/**

packages/contracts/src/http/cookie-options-builder.ts renamed to packages/contracts/src/http/cookie-config-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

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

44
export type RequestCookieBuilderCallback = (cookieBuilder: RequestCookieBuilder) => void
55
export type ResponseCookieBuilderCallback = (cookieBuilder: ResponseCookieBuilder) => void
@@ -71,5 +71,5 @@ export interface ResponseCookieBuilder {
7171
/**
7272
* Merge the given `config` with the default HTTP cookie config.
7373
*/
74-
useConfig (config: Partial<CookieOptions>): this
74+
useConfig (config: Partial<CookieConfig>): this
7575
}

packages/contracts/src/http/cookie-options.ts renamed to packages/contracts/src/http/cookie-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
export interface CookieOptions {
2+
export interface CookieConfig {
33
/**
44
* The time or date in the future at which the cookie expires.
55
*/

packages/contracts/src/http/cors-config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11

2-
/**
3-
* @deprecated The `CorsOptions` is deprecated in favor of the `CorsConfig`
4-
* interface. We’ll remove the `CorsOptions` interface in the upcoming
5-
* release of the Supercharge framework. You may already switch to the renamed interface.
6-
*/
7-
export type CorsOptions = CorsConfig
8-
92
export interface CorsConfig {
103
/**
114
* Controls the `Access-Control-Max-Age` header in seconds.

packages/contracts/src/http/request.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import { HttpContext } from './context.js'
66
import { CookieBag } from './cookie-bag.js'
77
import { IncomingMessage } from 'node:http'
88
import { IncomingHttpHeaders } from 'node:http2'
9-
import { CookieOptions } from './cookie-options.js'
9+
import { CookieConfig } from './cookie-config.js'
1010
import { MacroableCtor } from '@supercharge/macroable'
1111
import { QueryParameterBag } from './query-parameter-bag.js'
1212
import { InteractsWithState } from './concerns/interacts-with-state.js'
13-
import { RequestCookieBuilderCallback } from './cookie-options-builder.js'
13+
import { RequestCookieBuilderCallback } from './cookie-config-builder.js'
1414
import { InteractsWithContentTypes } from './concerns/interacts-with-content-types.js'
1515

1616
export interface HttpRequestCtor extends MacroableCtor {
1717
/**
1818
* Create a new HTTP request instance.
1919
*/
20-
new (context: HttpContext, cookieOptions: CookieOptions): HttpRequest
20+
new (context: HttpContext, cookieOptions: CookieConfig): HttpRequest
2121
}
2222

2323
export type Protocol = 'http' | 'https' | string

packages/contracts/src/http/response.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { HttpContext } from './context.js'
44
import { CookieBag } from './cookie-bag.js'
55
import { OutgoingHttpHeaders } from 'http2'
66
import { HttpRedirect } from './redirect.js'
7-
import { CookieOptions } from './cookie-options.js'
7+
import { CookieConfig } from './cookie-config.js'
88
import { MacroableCtor } from '@supercharge/macroable'
99
import { InteractsWithState } from './concerns/interacts-with-state.js'
10-
import { ResponseCookieBuilderCallback } from './cookie-options-builder.js'
10+
import { ResponseCookieBuilderCallback } from './cookie-config-builder.js'
1111

1212
export interface HttpResponseCtor extends MacroableCtor {
1313
/**
1414
* Create a new HTTP response instance.
1515
*/
16-
new (context: HttpContext, cookieOptions: CookieOptions): HttpResponse
16+
new (context: HttpContext, cookieOptions: CookieConfig): HttpResponse
1717
}
1818

1919
export interface HttpResponse<T = any> extends InteractsWithState {

packages/contracts/src/http/static-assets-config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11

2-
/**
3-
* @deprecated The `StaticAssetsOptions` is deprecated in favor of the `StaticAssetsConfig`
4-
* interface. We’ll remove the `StaticAssetsOptions` interface in the upcoming release
5-
* of the Supercharge framework. You might switch already to the renamed interface.
6-
*/
7-
export type StaticAssetsOptions = StaticAssetsConfig
8-
92
export interface StaticAssetsConfig {
103
/**
114
* Define the maximum amount of seconds to cache a static resource

packages/contracts/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ export { EnvStore } from './env/env.js'
2020
export { Bootstrapper, BootstrapperCtor } from './core/bootstrapper.js'
2121
export { ErrorHandler, ErrorHandlerCtor } from './core/error-handler.js'
2222

23-
export { HashBuilder, HashBuilderCallback, HashBuilderOptions } from './hashing/hash-builder.js'
23+
export { HashBuilder, HashBuilderCallback, HashBuilderConfig } from './hashing/hash-builder.js'
2424
export { HashConfig } from './hashing/config.js'
2525
export { BaseHasher } from './hashing/base-hasher.js'
2626
export { Hasher } from './hashing/hasher.js'
2727

28-
export { BodyparserConfig, BodyparserOptions } from './http/bodyparser-config.js'
28+
export { BodyparserConfig } from './http/bodyparser-config.js'
2929
export { HttpConfig } from './http/config.js'
3030
export { HttpContext, NextHandler } from './http/context.js'
3131
export { HttpController } from './http/controller.js'
3232
export { CookieBag } from './http/cookie-bag.js'
33-
export { CookieOptions } from './http/cookie-options.js'
34-
export { RequestCookieBuilder, RequestCookieBuilderCallback, ResponseCookieBuilder, ResponseCookieBuilderCallback } from './http/cookie-options-builder.js'
35-
export { CorsConfig, CorsOptions } from './http/cors-config.js'
33+
export { CookieConfig } from './http/cookie-config.js'
34+
export { RequestCookieBuilder, RequestCookieBuilderCallback, ResponseCookieBuilder, ResponseCookieBuilderCallback } from './http/cookie-config-builder.js'
35+
export { CorsConfig } from './http/cors-config.js'
3636
export { InteractsWithContentTypes } from './http/concerns/interacts-with-content-types.js'
3737
export { InteractsWithState } from './http/concerns/interacts-with-state.js'
3838
export { StateBag, HttpStateData } from './http/concerns/state-bag.js'
@@ -52,7 +52,7 @@ export { HttpRouteGroup } from './http/route-group.js'
5252
export { HttpRoute, RouteObjectAttributes } from './http/route.js'
5353
export { HttpRouter, RouteHandler, RouteAttributes } from './http/router.js'
5454
export { HttpServer, HttpServerHandler } from './http/server.js'
55-
export { StaticAssetsConfig, StaticAssetsOptions } from './http/static-assets-config.js'
55+
export { StaticAssetsConfig } from './http/static-assets-config.js'
5656
export { UploadedFile } from './http/uploaded-file.js'
5757

5858
export { LoggingConfig, LogChannelConfig, LoggingChannels, ConsoleChannelConfig, FileChannelConfig } from './logging/config.js'

packages/view/src/engines/handlebars/compiler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import Path from 'node:path'
33
import Fs from '@supercharge/fs'
44
import { fileURLToPath } from 'node:url'
5-
import { resolveDefaultImport, tap } from '@supercharge/goodies'
65
import { Str } from '@supercharge/strings'
76
import { Collect } from '@supercharge/collections'
87
import Handlebars, { HelperDelegate } from 'handlebars'
8+
import { resolveDefaultImport, tap } from '@supercharge/goodies'
99
import { Logger, ViewConfig, ViewEngine, ViewResponseConfig } from '@supercharge/contracts'
1010

1111
export class HandlebarsCompiler implements ViewEngine {
@@ -288,16 +288,16 @@ export class HandlebarsCompiler implements ViewEngine {
288288
/**
289289
* Compile the given `template` to a render function.
290290
*/
291-
async compile (view: string, options: ReadTemplateOptions = {}): Promise<HandlebarsTemplateDelegate> {
291+
async compile (view: string, config: ReadTemplateConfig = {}): Promise<HandlebarsTemplateDelegate> {
292292
return this.handlebars.compile(
293-
await this.readTemplate(view, options)
293+
await this.readTemplate(view, config)
294294
)
295295
}
296296

297297
/**
298298
* Reads and returns the view `template` from the hard disk.
299299
*/
300-
async readTemplate (template: string, { isLayout = false }: ReadTemplateOptions): Promise<string> {
300+
async readTemplate (template: string, { isLayout = false }: ReadTemplateConfig): Promise<string> {
301301
const view = isLayout
302302
? Path.resolve(await this.layoutLocation(), template)
303303
: Path.resolve(await this.viewsLocation(), template)
@@ -328,6 +328,6 @@ export class HandlebarsCompiler implements ViewEngine {
328328
}
329329
}
330330

331-
interface ReadTemplateOptions {
331+
interface ReadTemplateConfig {
332332
isLayout?: boolean
333333
}

0 commit comments

Comments
 (0)