Skip to content

Commit bc9ab50

Browse files
authored
Merge pull request #150 from supercharge/remove-deprecated-contracts
Align and Remove deprecated contracts
2 parents 6e1b5d6 + 7d0a661 commit bc9ab50

21 files changed

+95
-96
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, cookieConfig: 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, cookieConfig: 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/hashing/src/base-hasher.ts

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

22
import { HashBuilder } from './hash-builder.js'
33
import Crypto, { BinaryLike, Encoding, Hash } from 'node:crypto'
4-
import { BaseHasher as BaseHasherContract, HashBuilderCallback, HashBuilderOptions } from '@supercharge/contracts'
4+
import { BaseHasher as BaseHasherContract, HashBuilderCallback, HashBuilderConfig } from '@supercharge/contracts'
55

66
export class BaseHasher implements BaseHasherContract {
77
/**
@@ -56,13 +56,13 @@ export class BaseHasher implements BaseHasherContract {
5656
}
5757

5858
if (typeof inputEncodingOrHashBuilder === 'function') {
59-
const hashBuilderOptions: HashBuilderOptions = { outputEncoding: 'base64' }
60-
const builder = new HashBuilder(hashBuilderOptions)
59+
const hashBuilderConfig: HashBuilderConfig = { outputEncoding: 'base64' }
60+
const builder = new HashBuilder(hashBuilderConfig)
6161
inputEncodingOrHashBuilder(builder)
6262

6363
return this
64-
.createHash(algorithm, input, hashBuilderOptions.inputEncoding)
65-
.digest(hashBuilderOptions.outputEncoding)
64+
.createHash(algorithm, input, hashBuilderConfig.inputEncoding)
65+
.digest(hashBuilderConfig.outputEncoding)
6666
}
6767

6868
return this

packages/hashing/src/hash-builder.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11

2-
import { HashBuilder as HashBuilderContract, HashBuilderOptions } from '@supercharge/contracts'
3-
import { BinaryToTextEncoding, Encoding } from 'crypto'
2+
import { BinaryToTextEncoding, Encoding } from 'node:crypto'
3+
import { HashBuilder as HashBuilderContract, HashBuilderConfig } from '@supercharge/contracts'
44

55
export class HashBuilder implements HashBuilderContract {
66
/**
7-
* Stores the hash builder options.
7+
* Stores the hash builder config.
88
*/
9-
private readonly options: HashBuilderOptions
9+
private readonly config: HashBuilderConfig
1010

11-
constructor (options: HashBuilderOptions) {
12-
this.options = options
11+
/**
12+
* Create a new instance.
13+
*/
14+
constructor (options: HashBuilderConfig) {
15+
this.config = options
1316
}
1417

18+
/**
19+
* Set the input encoding for the related value.
20+
*/
1521
inputEncoding (inputEncoding: Encoding): this {
16-
this.options.inputEncoding = inputEncoding
22+
this.config.inputEncoding = inputEncoding
1723
return this
1824
}
1925

26+
/**
27+
* Calculate the final hash string value.
28+
*/
2029
digest (encoding: BinaryToTextEncoding): void {
21-
this.options.outputEncoding = encoding
30+
this.config.outputEncoding = encoding
2231
}
2332

33+
/**
34+
* This is an alias for the `digest` method that calculates the final hash string.
35+
*/
2436
toString (encoding: BinaryToTextEncoding): void {
2537
this.digest(encoding)
2638
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Cookie from 'cookie'
33
import * as Cookies from 'cookies'
44
import { tap } from '@supercharge/goodies'
55
import { RequestCookieBuilder, ResponseCookieBuilder } from './cookies/index.js'
6-
import { CookieBag as CookieBagContract, CookieOptions, RequestCookieBuilderCallback, ResponseCookieBuilderCallback } from '@supercharge/contracts'
6+
import { CookieBag as CookieBagContract, CookieConfig, RequestCookieBuilderCallback, ResponseCookieBuilderCallback } from '@supercharge/contracts'
77

88
export class CookieBag implements CookieBagContract {
99
/**
@@ -14,12 +14,12 @@ export class CookieBag implements CookieBagContract {
1414
/**
1515
* Stores the default cookie options.
1616
*/
17-
private readonly options: CookieOptions & { signed: boolean }
17+
private readonly options: CookieConfig & { signed: boolean }
1818

1919
/**
2020
* Create a new instance.
2121
*/
22-
constructor (cookies: Cookies, options?: CookieOptions) {
22+
constructor (cookies: Cookies, options?: CookieConfig) {
2323
this.cookies = cookies
2424
this.options = { signed: true, ...options }
2525
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11

22
import { tap } from '@supercharge/goodies'
3-
import { CookieOptions, RequestCookieBuilder as RequestCookieContract } from '@supercharge/contracts'
3+
import { CookieConfig, RequestCookieBuilder as RequestCookieContract } from '@supercharge/contracts'
44

55
export class RequestCookieBuilder implements RequestCookieContract {
66
/**
77
* Stores the options used when retrieving a cookie value from the request.
88
*/
9-
private readonly cookieOptions: CookieOptions
9+
private readonly cookieConfig: CookieConfig
1010

1111
/**
1212
* Create a new instance.
1313
*/
14-
constructor (options: CookieOptions) {
15-
this.cookieOptions = options
14+
constructor (options: CookieConfig) {
15+
this.cookieConfig = options
1616
}
1717

1818
/**
1919
* Retrieve the unsigned cookie value.
2020
*/
2121
unsigned (): this {
2222
return tap(this, () => {
23-
this.cookieOptions.signed = false
23+
this.cookieConfig.signed = false
2424
})
2525
}
2626
}

0 commit comments

Comments
 (0)