@snail-js/api 0.1.27 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +125 -605
- package/dist/adapter/plain.d.ts +12 -0
- package/dist/adapter/plain.d.ts.map +1 -0
- package/dist/adapter/react.d.ts +14 -0
- package/dist/adapter/react.d.ts.map +1 -0
- package/dist/adapter/registry.d.ts +16 -0
- package/dist/adapter/registry.d.ts.map +1 -0
- package/dist/adapter/vue.d.ts +15 -0
- package/dist/adapter/vue.d.ts.map +1 -0
- package/dist/chunks/custom-UchOSg_s.js +466 -0
- package/dist/chunks/custom-UchOSg_s.js.map +1 -0
- package/dist/chunks/download-lBC7oOTT.js +160 -0
- package/dist/chunks/download-lBC7oOTT.js.map +1 -0
- package/dist/chunks/object-Ct0w-h4i.js +74 -0
- package/dist/chunks/object-Ct0w-h4i.js.map +1 -0
- package/dist/chunks/plugin-D3RDffDG.js +742 -0
- package/dist/chunks/plugin-D3RDffDG.js.map +1 -0
- package/dist/chunks/react-C1em-gxy.js +62 -0
- package/dist/chunks/react-C1em-gxy.js.map +1 -0
- package/dist/chunks/request-qeRhihEF.js +40 -0
- package/dist/chunks/request-qeRhihEF.js.map +1 -0
- package/dist/chunks/response-D-ubkAFl.js +127 -0
- package/dist/chunks/response-D-ubkAFl.js.map +1 -0
- package/dist/chunks/use-download-FAjtdJ58.js +1816 -0
- package/dist/chunks/use-download-FAjtdJ58.js.map +1 -0
- package/dist/chunks/vue-Dd9EhkQ3.js +34 -0
- package/dist/chunks/vue-Dd9EhkQ3.js.map +1 -0
- package/dist/core/args.d.ts +54 -0
- package/dist/core/args.d.ts.map +1 -0
- package/dist/core/connection.d.ts +15 -0
- package/dist/core/connection.d.ts.map +1 -0
- package/dist/core/context.d.ts +124 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/http-stream.d.ts +28 -0
- package/dist/core/http-stream.d.ts.map +1 -0
- package/dist/core/logger.d.ts +22 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/metadata.d.ts +92 -0
- package/dist/core/metadata.d.ts.map +1 -0
- package/dist/core/metadata.keys.d.ts +41 -0
- package/dist/core/metadata.keys.d.ts.map +1 -0
- package/dist/core/method.d.ts +177 -0
- package/dist/core/method.d.ts.map +1 -0
- package/dist/core/plugin-manager.d.ts +106 -0
- package/dist/core/plugin-manager.d.ts.map +1 -0
- package/dist/core/plugin.d.ts +113 -0
- package/dist/core/plugin.d.ts.map +1 -0
- package/dist/core/reconnect.d.ts +22 -0
- package/dist/core/reconnect.d.ts.map +1 -0
- package/dist/core/resolve-stream.d.ts +45 -0
- package/dist/core/resolve-stream.d.ts.map +1 -0
- package/dist/core/resolve.d.ts +50 -0
- package/dist/core/resolve.d.ts.map +1 -0
- package/dist/core/response.d.ts +60 -0
- package/dist/core/response.d.ts.map +1 -0
- package/dist/core/server.d.ts +132 -0
- package/dist/core/server.d.ts.map +1 -0
- package/dist/core/sse.d.ts +27 -0
- package/dist/core/sse.d.ts.map +1 -0
- package/dist/core/state-bag.d.ts +36 -0
- package/dist/core/state-bag.d.ts.map +1 -0
- package/dist/core/websocket.d.ts +29 -0
- package/dist/core/websocket.d.ts.map +1 -0
- package/dist/decorators/api.d.ts +24 -4
- package/dist/decorators/api.d.ts.map +1 -0
- package/dist/decorators/args.d.ts +77 -14
- package/dist/decorators/args.d.ts.map +1 -0
- package/dist/decorators/custom.d.ts +81 -0
- package/dist/decorators/custom.d.ts.map +1 -0
- package/dist/decorators/header.d.ts +22 -0
- package/dist/decorators/header.d.ts.map +1 -0
- package/dist/decorators/index.d.ts +17 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/methods.d.ts +33 -0
- package/dist/decorators/methods.d.ts.map +1 -0
- package/dist/decorators/progress.d.ts +24 -6
- package/dist/decorators/progress.d.ts.map +1 -0
- package/dist/decorators/server.d.ts +28 -7
- package/dist/decorators/server.d.ts.map +1 -0
- package/dist/decorators/stream.d.ts +113 -0
- package/dist/decorators/stream.d.ts.map +1 -0
- package/dist/default/options.d.ts +19 -0
- package/dist/default/options.d.ts.map +1 -0
- package/dist/error/base.d.ts +20 -0
- package/dist/error/base.d.ts.map +1 -0
- package/dist/error/decorator.d.ts +14 -0
- package/dist/error/decorator.d.ts.map +1 -0
- package/dist/error/hook.d.ts +14 -0
- package/dist/error/hook.d.ts.map +1 -0
- package/dist/error/index.d.ts +8 -0
- package/dist/error/index.d.ts.map +1 -0
- package/dist/error/options.d.ts +12 -0
- package/dist/error/options.d.ts.map +1 -0
- package/dist/error/plugin.d.ts +11 -0
- package/dist/error/plugin.d.ts.map +1 -0
- package/dist/error/request.d.ts +29 -0
- package/dist/error/request.d.ts.map +1 -0
- package/dist/error/response.d.ts +36 -0
- package/dist/error/response.d.ts.map +1 -0
- package/dist/index.d.ts +56 -11
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2034 -0
- package/dist/index.js.map +1 -0
- package/dist/locale/en.d.ts +5 -0
- package/dist/locale/en.d.ts.map +1 -0
- package/dist/locale/index.d.ts +57 -0
- package/dist/locale/index.d.ts.map +1 -0
- package/dist/locale/types.d.ts +11 -0
- package/dist/locale/types.d.ts.map +1 -0
- package/dist/locale/zh.d.ts +5 -0
- package/dist/locale/zh.d.ts.map +1 -0
- package/dist/plugins/cache/adapters/indexeddb.d.ts +52 -0
- package/dist/plugins/cache/adapters/indexeddb.d.ts.map +1 -0
- package/dist/plugins/cache/adapters/memory.d.ts +60 -0
- package/dist/plugins/cache/adapters/memory.d.ts.map +1 -0
- package/dist/plugins/cache/adapters/web-storage.d.ts +43 -0
- package/dist/plugins/cache/adapters/web-storage.d.ts.map +1 -0
- package/dist/plugins/cache/decorators.d.ts +62 -0
- package/dist/plugins/cache/decorators.d.ts.map +1 -0
- package/dist/plugins/cache/index.d.ts +41 -0
- package/dist/plugins/cache/index.d.ts.map +1 -0
- package/dist/plugins/cache/key.d.ts +48 -0
- package/dist/plugins/cache/key.d.ts.map +1 -0
- package/dist/plugins/cache/manager.d.ts +124 -0
- package/dist/plugins/cache/manager.d.ts.map +1 -0
- package/dist/plugins/cache/plugin.d.ts +64 -0
- package/dist/plugins/cache/plugin.d.ts.map +1 -0
- package/dist/plugins/cache/type.d.ts +116 -0
- package/dist/plugins/cache/type.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +75 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +2265 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/interceptor/decorators.d.ts +44 -0
- package/dist/plugins/interceptor/decorators.d.ts.map +1 -0
- package/dist/plugins/interceptor/index.d.ts +31 -0
- package/dist/plugins/interceptor/index.d.ts.map +1 -0
- package/dist/plugins/interceptor/manager.d.ts +27 -0
- package/dist/plugins/interceptor/manager.d.ts.map +1 -0
- package/dist/plugins/interceptor/plugin.d.ts +65 -0
- package/dist/plugins/interceptor/plugin.d.ts.map +1 -0
- package/dist/plugins/interceptor/type.d.ts +45 -0
- package/dist/plugins/interceptor/type.d.ts.map +1 -0
- package/dist/plugins/pool/index.d.ts +26 -0
- package/dist/plugins/pool/index.d.ts.map +1 -0
- package/dist/plugins/pool/plugin.d.ts +83 -0
- package/dist/plugins/pool/plugin.d.ts.map +1 -0
- package/dist/plugins/pool/scheduler.d.ts +153 -0
- package/dist/plugins/pool/scheduler.d.ts.map +1 -0
- package/dist/plugins/pool/type.d.ts +38 -0
- package/dist/plugins/pool/type.d.ts.map +1 -0
- package/dist/plugins/react/index.d.ts +20 -0
- package/dist/plugins/react/index.d.ts.map +1 -0
- package/dist/plugins/react/index.js +145 -0
- package/dist/plugins/react/index.js.map +1 -0
- package/dist/plugins/react/plugin.d.ts +33 -0
- package/dist/plugins/react/plugin.d.ts.map +1 -0
- package/dist/plugins/react/type.d.ts +32 -0
- package/dist/plugins/react/type.d.ts.map +1 -0
- package/dist/plugins/transform/decorators.d.ts +54 -0
- package/dist/plugins/transform/decorators.d.ts.map +1 -0
- package/dist/plugins/transform/hydrate.d.ts +47 -0
- package/dist/plugins/transform/hydrate.d.ts.map +1 -0
- package/dist/plugins/transform/index.d.ts +41 -0
- package/dist/plugins/transform/index.d.ts.map +1 -0
- package/dist/plugins/transform/plugin.d.ts +20 -0
- package/dist/plugins/transform/plugin.d.ts.map +1 -0
- package/dist/plugins/transform/type.d.ts +67 -0
- package/dist/plugins/transform/type.d.ts.map +1 -0
- package/dist/plugins/validate/decorators.d.ts +24 -0
- package/dist/plugins/validate/decorators.d.ts.map +1 -0
- package/dist/plugins/validate/index.d.ts +40 -0
- package/dist/plugins/validate/index.d.ts.map +1 -0
- package/dist/plugins/validate/plugin.d.ts +13 -0
- package/dist/plugins/validate/plugin.d.ts.map +1 -0
- package/dist/plugins/validate/type.d.ts +54 -0
- package/dist/plugins/validate/type.d.ts.map +1 -0
- package/dist/plugins/version/decorators.d.ts +22 -0
- package/dist/plugins/version/decorators.d.ts.map +1 -0
- package/dist/plugins/version/index.d.ts +23 -0
- package/dist/plugins/version/index.d.ts.map +1 -0
- package/dist/plugins/version/plugin.d.ts +13 -0
- package/dist/plugins/version/plugin.d.ts.map +1 -0
- package/dist/plugins/version/type.d.ts +47 -0
- package/dist/plugins/version/type.d.ts.map +1 -0
- package/dist/plugins/vue/index.d.ts +21 -0
- package/dist/plugins/vue/index.d.ts.map +1 -0
- package/dist/plugins/vue/index.js +114 -0
- package/dist/plugins/vue/index.js.map +1 -0
- package/dist/plugins/vue/plugin.d.ts +15 -0
- package/dist/plugins/vue/plugin.d.ts.map +1 -0
- package/dist/plugins/vue/type.d.ts +34 -0
- package/dist/plugins/vue/type.d.ts.map +1 -0
- package/dist/strategies/index.d.ts +2 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +29 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/strategies/plain.d.ts +2 -0
- package/dist/strategies/plain.d.ts.map +1 -0
- package/dist/strategies/plain.js +23 -0
- package/dist/strategies/plain.js.map +1 -0
- package/dist/strategies/react.d.ts +2 -0
- package/dist/strategies/react.d.ts.map +1 -0
- package/dist/strategies/react.js +30 -0
- package/dist/strategies/react.js.map +1 -0
- package/dist/strategies/shared/adapter.d.ts +23 -0
- package/dist/strategies/shared/adapter.d.ts.map +1 -0
- package/dist/strategies/shared/dom.d.ts +53 -0
- package/dist/strategies/shared/dom.d.ts.map +1 -0
- package/dist/strategies/shared/error.d.ts +30 -0
- package/dist/strategies/shared/error.d.ts.map +1 -0
- package/dist/strategies/shared/method.d.ts +51 -0
- package/dist/strategies/shared/method.d.ts.map +1 -0
- package/dist/strategies/shared/public.d.ts +33 -0
- package/dist/strategies/shared/public.d.ts.map +1 -0
- package/dist/strategies/shared/queue.d.ts +30 -0
- package/dist/strategies/shared/queue.d.ts.map +1 -0
- package/dist/strategies/shared/retry.d.ts +51 -0
- package/dist/strategies/shared/retry.d.ts.map +1 -0
- package/dist/strategies/shared/state.d.ts +117 -0
- package/dist/strategies/shared/state.d.ts.map +1 -0
- package/dist/strategies/shared/timing.d.ts +53 -0
- package/dist/strategies/shared/timing.d.ts.map +1 -0
- package/dist/strategies/shared/watcher.d.ts +37 -0
- package/dist/strategies/shared/watcher.d.ts.map +1 -0
- package/dist/strategies/use-auto-request.d.ts +77 -0
- package/dist/strategies/use-auto-request.d.ts.map +1 -0
- package/dist/strategies/use-download.d.ts +103 -0
- package/dist/strategies/use-download.d.ts.map +1 -0
- package/dist/strategies/use-fetcher.d.ts +52 -0
- package/dist/strategies/use-fetcher.d.ts.map +1 -0
- package/dist/strategies/use-pagination.d.ts +101 -0
- package/dist/strategies/use-pagination.d.ts.map +1 -0
- package/dist/strategies/use-request.d.ts +50 -0
- package/dist/strategies/use-request.d.ts.map +1 -0
- package/dist/strategies/use-retriable-request.d.ts +46 -0
- package/dist/strategies/use-retriable-request.d.ts.map +1 -0
- package/dist/strategies/use-sse.d.ts +103 -0
- package/dist/strategies/use-sse.d.ts.map +1 -0
- package/dist/strategies/use-token-auth.d.ts +88 -0
- package/dist/strategies/use-token-auth.d.ts.map +1 -0
- package/dist/strategies/use-uploader.d.ts +88 -0
- package/dist/strategies/use-uploader.d.ts.map +1 -0
- package/dist/strategies/use-watcher.d.ts +69 -0
- package/dist/strategies/use-watcher.d.ts.map +1 -0
- package/dist/typings/adapter.d.ts +61 -0
- package/dist/typings/adapter.d.ts.map +1 -0
- package/dist/typings/api.d.ts +122 -0
- package/dist/typings/api.d.ts.map +1 -0
- package/dist/typings/args.d.ts +51 -0
- package/dist/typings/args.d.ts.map +1 -0
- package/dist/typings/index.d.ts +8 -12
- package/dist/typings/index.d.ts.map +1 -0
- package/dist/typings/meta.d.ts +44 -0
- package/dist/typings/meta.d.ts.map +1 -0
- package/dist/typings/plugin.d.ts +114 -0
- package/dist/typings/plugin.d.ts.map +1 -0
- package/dist/typings/response.d.ts +118 -0
- package/dist/typings/response.d.ts.map +1 -0
- package/dist/typings/server.d.ts +83 -0
- package/dist/typings/server.d.ts.map +1 -0
- package/dist/typings/stream.d.ts +150 -0
- package/dist/typings/stream.d.ts.map +1 -0
- package/dist/utils/download.d.ts +97 -0
- package/dist/utils/download.d.ts.map +1 -0
- package/dist/utils/emitter.d.ts +36 -0
- package/dist/utils/emitter.d.ts.map +1 -0
- package/dist/utils/index.d.ts +6 -1
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/is.d.ts +22 -0
- package/dist/utils/is.d.ts.map +1 -0
- package/dist/utils/object.d.ts +44 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/url.d.ts +44 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/package.json +90 -27
- package/README_EN.md +0 -607
- package/dist/cache/index.d.ts +0 -9
- package/dist/cache/indexDBCache.d.ts +0 -13
- package/dist/cache/localstorageCache.d.ts +0 -10
- package/dist/cache/memoryCache.d.ts +0 -11
- package/dist/core/index.d.ts +0 -4
- package/dist/core/snailApi.d.ts +0 -22
- package/dist/core/snailMethod.d.ts +0 -49
- package/dist/core/snailServer.d.ts +0 -35
- package/dist/core/snailSse.d.ts +0 -20
- package/dist/decorators/cache.d.ts +0 -15
- package/dist/decorators/method.d.ts +0 -38
- package/dist/decorators/sse.d.ts +0 -30
- package/dist/decorators/strategy.d.ts +0 -10
- package/dist/decorators/versioning.d.ts +0 -16
- package/dist/eventEmmit/index.d.ts +0 -1
- package/dist/eventEmmit/snail.event.d.ts +0 -10
- package/dist/snail-api.js +0 -4868
- package/dist/snail-api.umd.cjs +0 -4872
- package/dist/strategies/jwtStrategy.d.ts +0 -4
- package/dist/typings/api.option.d.ts +0 -10
- package/dist/typings/apiProxy.d.ts +0 -8
- package/dist/typings/cache.management.option.d.ts +0 -25
- package/dist/typings/cache.type.d.ts +0 -23
- package/dist/typings/content.type.d.ts +0 -5
- package/dist/typings/request.body.d.ts +0 -3
- package/dist/typings/response.data.d.ts +0 -13
- package/dist/typings/snail.event.d.ts +0 -6
- package/dist/typings/snail.method.d.ts +0 -14
- package/dist/typings/snail.option.d.ts +0 -16
- package/dist/typings/sse.d.ts +0 -15
- package/dist/typings/strategy.d.ts +0 -5
- package/dist/typings/versioning.option.d.ts +0 -30
- package/dist/utils/function.d.ts +0 -31
- package/dist/versioning/index.d.ts +0 -1
- package/dist/versioning/versioning.d.ts +0 -12
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { SnailSseHandlers, SnailWsHandlers } from "../decorators/stream.js";
|
|
2
|
+
import type { SnailHttpStreamOptions, SnailSseOptions, SnailWsOptions } from "../typings/stream.js";
|
|
3
|
+
/** Resolved description of an `@Sse` endpoint. */
|
|
4
|
+
export interface ResolvedSseEndpoint {
|
|
5
|
+
url: string;
|
|
6
|
+
options: SnailSseOptions;
|
|
7
|
+
handlers: SnailSseHandlers;
|
|
8
|
+
}
|
|
9
|
+
/** Resolved description of an `@WebSocket` endpoint. */
|
|
10
|
+
export interface ResolvedWsEndpoint {
|
|
11
|
+
url: string;
|
|
12
|
+
options: SnailWsOptions;
|
|
13
|
+
handlers: SnailWsHandlers;
|
|
14
|
+
}
|
|
15
|
+
/** Resolved description of an `@HttpStream` method. */
|
|
16
|
+
export interface ResolvedHttpStreamEndpoint {
|
|
17
|
+
url: string;
|
|
18
|
+
options: SnailHttpStreamOptions;
|
|
19
|
+
}
|
|
20
|
+
/** Read the `@Sse(...)` options and its registered handlers. */
|
|
21
|
+
export declare function resolveSseEndpoint(streamClass: unknown): ResolvedSseEndpoint | undefined;
|
|
22
|
+
/** Read the `@WebSocket(...)` options and its registered handlers. */
|
|
23
|
+
export declare function resolveWsEndpoint(streamClass: unknown): ResolvedWsEndpoint | undefined;
|
|
24
|
+
/** Read the `@HttpStream(...)` options of one method. */
|
|
25
|
+
export declare function resolveHttpStreamEndpoint(apiClass: unknown, methodName: string): ResolvedHttpStreamEndpoint | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Turn an http(s) `baseURL` into the matching WebSocket origin.
|
|
28
|
+
*
|
|
29
|
+
* `https://api.example.com` → `wss://api.example.com`. A relative `baseURL`
|
|
30
|
+
* (the common browser case) keeps working because `new WebSocket` resolves a
|
|
31
|
+
* relative url against the document base — but the scheme still has to be
|
|
32
|
+
* upgraded explicitly, which is what this does.
|
|
33
|
+
*/
|
|
34
|
+
export declare function toWebSocketURL(url: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Bind every SSE handler to the instance that will receive the events.
|
|
37
|
+
*
|
|
38
|
+
* Decorators only ever see the prototype, so the raw functions are stored and
|
|
39
|
+
* bound here — one binding per `open()`, against the instance actually created by
|
|
40
|
+
* `createSse`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function rebindSseHandlers(handlers: SnailSseHandlers, instance: object): SnailSseHandlers;
|
|
43
|
+
/** Bind every WebSocket handler to the instance. @see rebindSseHandlers */
|
|
44
|
+
export declare function rebindWsHandlers(handlers: SnailWsHandlers, instance: object): SnailWsHandlers;
|
|
45
|
+
//# sourceMappingURL=resolve-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-stream.d.ts","sourceRoot":"","sources":["../../src/core/resolve-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,cAAc,EACf,MAAM,mBAAmB,CAAC;AAS3B,kDAAkD;AAClD,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,eAAe,CAAC;IACzB,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED,wDAAwD;AACxD,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,cAAc,CAAC;IACxB,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,uDAAuD;AACvD,MAAM,WAAW,0BAA0B;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,sBAAsB,CAAC;CACjC;AAUD,gEAAgE;AAChE,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,OAAO,GACnB,mBAAmB,GAAG,SAAS,CAcjC;AAED,sEAAsE;AACtE,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,OAAO,GACnB,kBAAkB,GAAG,SAAS,CAchC;AAED,yDAAyD;AACzD,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,MAAM,GACjB,0BAA0B,GAAG,SAAS,CAQxC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIlD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,MAAM,GACf,gBAAgB,CASlB;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,eAAe,EACzB,QAAQ,EAAE,MAAM,GACf,eAAe,CAOjB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AxiosHeaders } from "axios";
|
|
2
|
+
import type { InternalAxiosRequestConfig } from "axios";
|
|
3
|
+
import type { SnailApiOptions, SnailMethodOptions, SnailMethodType } from "../typings/api.js";
|
|
4
|
+
import type { ResolvedServerOptions } from "../typings/server.js";
|
|
5
|
+
/**
|
|
6
|
+
* Turns raw decorator metadata into concrete, fully-defaulted options.
|
|
7
|
+
*
|
|
8
|
+
* Everything a request needs is resolved *here* rather than spread across the
|
|
9
|
+
* server, the proxy and the method. One place to read, one place to test.
|
|
10
|
+
*/
|
|
11
|
+
/** Read and default the options written by `@Server(...)`. */
|
|
12
|
+
export declare function resolveServerOptions(serverClass: unknown, fallbackName: string): ResolvedServerOptions;
|
|
13
|
+
/** Read and default the options written by `@Api(...)`. */
|
|
14
|
+
export declare function resolveApiOptions(apiClass: new () => unknown, fallbackName: string): Required<SnailApiOptions>;
|
|
15
|
+
/** Read the request verb written by `@Get()` / `@Post()` / … */
|
|
16
|
+
export declare function resolveRequestMethod(apiClass: new () => unknown, methodName: string): SnailMethodType | undefined;
|
|
17
|
+
/** Read the full request-method options written by `@Get(path, options)`. */
|
|
18
|
+
export declare function resolveMethodDecoratorOptions(apiClass: new () => unknown, methodName: string): (SnailMethodOptions & {
|
|
19
|
+
method: SnailMethodType;
|
|
20
|
+
url: string;
|
|
21
|
+
}) | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Merge the three levels of `@Header(...)` — api class, then method.
|
|
24
|
+
*
|
|
25
|
+
* Method-level headers win, which is the only ordering that lets a single
|
|
26
|
+
* endpoint override a class-wide default.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveHeaders(apiClass: new () => unknown, methodName: string): AxiosHeaders;
|
|
29
|
+
/** Progress callbacks written by `@UploadProgress()` / `@DownloadProgress()`. */
|
|
30
|
+
export declare function resolveProgress(apiClass: new () => unknown, methodName: string): {
|
|
31
|
+
onUploadProgress: SnailMethodOptions["onUploadProgress"];
|
|
32
|
+
onDownloadProgress: SnailMethodOptions["onDownloadProgress"];
|
|
33
|
+
};
|
|
34
|
+
/** Join the api prefix with a method path. */
|
|
35
|
+
export declare function resolveRoute(apiURL: string, methodPath: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Build the axios config a request starts from.
|
|
38
|
+
*
|
|
39
|
+
* Values cascade method → api → server, and only the winner survives. The
|
|
40
|
+
* argument decorators and the plugins refine this further during the pipeline.
|
|
41
|
+
*/ export declare function buildBaseRequestConfig(input: {
|
|
42
|
+
serverOptions: ResolvedServerOptions;
|
|
43
|
+
apiOptions: Required<SnailApiOptions>;
|
|
44
|
+
methodOptions: SnailMethodOptions & {
|
|
45
|
+
url: string;
|
|
46
|
+
};
|
|
47
|
+
methodType: SnailMethodType;
|
|
48
|
+
headers: AxiosHeaders;
|
|
49
|
+
}): InternalAxiosRequestConfig;
|
|
50
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/core/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,OAAO,CAAC;AAaxD,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,eAAe,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,qBAAqB,EAAsB,MAAM,mBAAmB,CAAC;AAGnF;;;;;GAKG;AAEH,8DAA8D;AAC9D,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,OAAO,EACpB,YAAY,EAAE,MAAM,GACnB,qBAAqB,CAuBvB;AAED,2DAA2D;AAC3D,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,UAAU,OAAO,EAC3B,YAAY,EAAE,MAAM,GACnB,QAAQ,CAAC,eAAe,CAAC,CAe3B;AAED,gEAAgE;AAChE,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,OAAO,EAC3B,UAAU,EAAE,MAAM,GACjB,eAAe,GAAG,SAAS,CAO7B;AAED,6EAA6E;AAC7E,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,UAAU,OAAO,EAC3B,UAAU,EAAE,MAAM,GACjB,CAAC,kBAAkB,GAAG;IAAE,MAAM,EAAE,eAAe,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,SAAS,CAM7E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,UAAU,OAAO,EAC3B,UAAU,EAAE,MAAM,GACjB,YAAY,CAKd;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,UAAU,OAAO,EAC3B,UAAU,EAAE,MAAM,GACjB;IACD,gBAAgB,EAAE,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IACzD,kBAAkB,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;CAC9D,CAKA;AAED,8CAA8C;AAC9C,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEvE;AAED;;;;;GAKG,CAAA,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC/C,aAAa,EAAE,qBAAqB,CAAC;IACrC,UAAU,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACtC,aAAa,EAAE,kBAAkB,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACpD,UAAU,EAAE,eAAe,CAAC;IAC5B,OAAO,EAAE,YAAY,CAAC;CACvB,GAAG,0BAA0B,CAkC7B"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { AxiosResponse, InternalAxiosRequestConfig } from "axios";
|
|
2
|
+
import type { SnailCodeValidator, SnailResult } from "../typings/response.js";
|
|
3
|
+
/**
|
|
4
|
+
* Response normalisation helpers.
|
|
5
|
+
*
|
|
6
|
+
* Responsibilities, in the order they run per request:
|
|
7
|
+
* 1. optionally repair a JSON body the server sent with the wrong content-type
|
|
8
|
+
* 2. decide whether the response *is* an envelope or a raw payload
|
|
9
|
+
* 3. validate the business status code
|
|
10
|
+
* 4. assemble the {@link SnailResult} handed to the caller
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Parse a JSON string body.
|
|
14
|
+
*
|
|
15
|
+
* Some gateways answer `Content-Type: text/plain` (or omit the header) while
|
|
16
|
+
* sending a JSON envelope. Without this repair the caller would receive a
|
|
17
|
+
* string where the types promise an object — a silent, very confusing bug.
|
|
18
|
+
*
|
|
19
|
+
* Returns the original response when parsing is disabled, when the caller asked
|
|
20
|
+
* for `responseType: "text"` explicitly (they want the raw string), or when the
|
|
21
|
+
* body does not look like JSON.
|
|
22
|
+
*/
|
|
23
|
+
export declare function coerceJSONStringBody<T>(response: AxiosResponse<T>, enabled: boolean): AxiosResponse<T>;
|
|
24
|
+
/** `true` when the response body looks like an envelope carrying `dataKey`. */
|
|
25
|
+
export declare function looksLikeEnvelope(body: unknown, dataKey: string): boolean;
|
|
26
|
+
/** Read one key off an unknown body, or `undefined`. */
|
|
27
|
+
export declare function readKey<T = unknown>(body: unknown, key: string): T | undefined;
|
|
28
|
+
/** Extract the payload out of an envelope, tolerating raw pass-through bodies. */
|
|
29
|
+
export declare function unwrapEnvelope<T>(body: unknown, dataKey: string): T;
|
|
30
|
+
/**
|
|
31
|
+
* The default business-code rule: accept `0` and `200`.
|
|
32
|
+
*
|
|
33
|
+
* Chosen because `0` is the overwhelmingly common "no error" code in Chinese
|
|
34
|
+
* backends and `200` mirrors HTTP for teams that reuse it. Applications with a
|
|
35
|
+
* different convention pass `validateCode` to `@Server(...)`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createDefaultCodeValidator(accepted?: readonly (number | string)[]): SnailCodeValidator;
|
|
38
|
+
/**
|
|
39
|
+
* Assert the business status code, throwing a {@link SnailResponseError} when
|
|
40
|
+
* the application's rule rejects it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function assertBusinessCode(options: {
|
|
43
|
+
body: unknown;
|
|
44
|
+
code: number | string | undefined;
|
|
45
|
+
dataKey: string;
|
|
46
|
+
validate: SnailCodeValidator | undefined;
|
|
47
|
+
fullName: string;
|
|
48
|
+
message: string;
|
|
49
|
+
}): void;
|
|
50
|
+
/** Assemble the value `send()` resolves to. */
|
|
51
|
+
export declare function buildResult<S, T, D extends string, C extends string, M extends string>(options: {
|
|
52
|
+
response: AxiosResponse;
|
|
53
|
+
envelope: unknown;
|
|
54
|
+
codeKey: string;
|
|
55
|
+
messageKey: string;
|
|
56
|
+
dataKey: string;
|
|
57
|
+
fromCache: boolean;
|
|
58
|
+
config: InternalAxiosRequestConfig;
|
|
59
|
+
}): SnailResult<S, T, D, C, M>;
|
|
60
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/core/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,OAAO,CAAC;AAGvE,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAC7B;;;;;;;;GAQG;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,OAAO,EAAE,OAAO,GACf,aAAa,CAAC,CAAC,CAAC,CAelB;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAOzE;AAED,wDAAwD;AACxD,wBAAgB,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAG9E;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CAKnE;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,GAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAA2B,GAC9D,kBAAkB,CAGpB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,IAAI,CAQP;AAED,+CAA+C;AAC/C,wBAAgB,WAAW,CACzB,CAAC,EACD,CAAC,EACD,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,EAChB,OAAO,EAAE;IACT,QAAQ,EAAE,aAAa,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,0BAA0B,CAAC;CACpC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAY7B"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
|
|
2
|
+
import type { SnailApiProxy } from "../typings/api.js";
|
|
3
|
+
import type { SnailPlugin, SnailPluginObject } from "../typings/plugin.js";
|
|
4
|
+
import type { SnailEnvelopeSchema } from "../typings/response.js";
|
|
5
|
+
import type { SnailSseEndpoint, SnailWsEndpoint } from "../typings/stream.js";
|
|
6
|
+
import type { ResolvedServerOptions } from "../typings/server.js";
|
|
7
|
+
import { PluginManager } from "./plugin-manager.js";
|
|
8
|
+
/**
|
|
9
|
+
* The server base class.
|
|
10
|
+
*
|
|
11
|
+
* Extend it, decorate the subclass with `@Server(...)` and instantiate once:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* @Server({ baseURL: "/api", timeout: 5000 })
|
|
15
|
+
* class BackEnd extends SnailServer {}
|
|
16
|
+
*
|
|
17
|
+
* export const Service = new BackEnd();
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The instance owns an axios instance, a plugin registry and the resolved
|
|
21
|
+
* options. It is created eagerly at module load, so `use()` is synchronous and
|
|
22
|
+
* chainable: `Service.use(A()).use(B())`.
|
|
23
|
+
*/
|
|
24
|
+
export declare class SnailServer<ServerResponse = SnailEnvelopeSchema, DataKey extends string = "data", CodeKey extends string = "code", MessageKey extends string = "message"> {
|
|
25
|
+
/** Server name — `@Server({ name })` or the subclass name. */
|
|
26
|
+
readonly name: string;
|
|
27
|
+
/** Fully resolved options, defaults applied. */
|
|
28
|
+
readonly options: ResolvedServerOptions;
|
|
29
|
+
/** The axios instance every request of this server goes through. */
|
|
30
|
+
readonly axios: AxiosInstance;
|
|
31
|
+
/** This server's plugin registry. */
|
|
32
|
+
readonly pluginManager: PluginManager;
|
|
33
|
+
private readonly logger;
|
|
34
|
+
private readonly apiCache;
|
|
35
|
+
constructor();
|
|
36
|
+
/**
|
|
37
|
+
* Register a plugin.
|
|
38
|
+
*
|
|
39
|
+
* Synchronous and chainable. Validation (name, duplicates, `dependsOn`) throws
|
|
40
|
+
* immediately; an async `install` hook is awaited once, before the first
|
|
41
|
+
* request, via the manager's `ready` promise.
|
|
42
|
+
*/
|
|
43
|
+
use(plugin: SnailPluginObject<any> | SnailPlugin<any>): this;
|
|
44
|
+
/** Unregister a plugin by instance or by name. */
|
|
45
|
+
remove(plugin: SnailPluginObject<any> | string): Promise<boolean>;
|
|
46
|
+
/** `true` when a plugin with this name is registered. */
|
|
47
|
+
hasPlugin(name: string): boolean;
|
|
48
|
+
/** Registered plugin names, in chain order. */
|
|
49
|
+
get plugins(): readonly string[];
|
|
50
|
+
/**
|
|
51
|
+
* Turn a decorated api class into a proxy whose methods build requests.
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* @Api("/user")
|
|
55
|
+
* class UserApi {
|
|
56
|
+
* @Get("/:id")
|
|
57
|
+
* getUser(@Params("id") id: string): Promise<User> { return null!; }
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* export const userApi = Service.createApi(UserApi);
|
|
61
|
+
* const method = userApi.getUser("1"); // nothing sent yet
|
|
62
|
+
* const { data } = await method.send();
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* A declared return type — `Promise<User>` above — becomes the payload type,
|
|
66
|
+
* so `data` is `User` with no explicit generic.
|
|
67
|
+
*/
|
|
68
|
+
createApi<TClass extends new (...args: any[]) => object>(apiClass: TClass): SnailApiProxy<InstanceType<TClass>, ServerResponse, DataKey, CodeKey, MessageKey>;
|
|
69
|
+
/**
|
|
70
|
+
* Turn a class decorated with `@Sse(...)` into an endpoint factory.
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* @Sse("/events")
|
|
74
|
+
* class Events { @SseEvent() onMessage(m: SnailSseMessage) {} }
|
|
75
|
+
*
|
|
76
|
+
* const events = Service.createSse(Events);
|
|
77
|
+
* const connection = events.open();
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
createSse<TClass extends new (...args: any[]) => object>(sseClass: TClass): SnailSseEndpoint;
|
|
81
|
+
/**
|
|
82
|
+
* Turn a class decorated with `@WebSocket(...)` into an endpoint factory.
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* @WebSocket("/ws")
|
|
86
|
+
* class Chat { @OnWsMessage() incoming(event: MessageEvent) {} }
|
|
87
|
+
*
|
|
88
|
+
* const chat = Service.createWebSocket(Chat);
|
|
89
|
+
* const socket = chat.open();
|
|
90
|
+
* socket.send({ hello: "world" });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
createWebSocket<TClass extends new (...args: any[]) => object>(wsClass: TClass): SnailWsEndpoint;
|
|
94
|
+
/**
|
|
95
|
+
* Send a one-off request that is **not** backed by a decorated api class.
|
|
96
|
+
*
|
|
97
|
+
* This is an escape hatch, and it is deliberately thin: it awaits plugin
|
|
98
|
+
* installation and then calls the axios instance directly. **No lifecycle hook
|
|
99
|
+
* runs** — no `beforeRequest`, no `afterResponse`, no caching, no validation, no
|
|
100
|
+
* response transformation — and the envelope is *not* unwrapped, so you get the
|
|
101
|
+
* raw `AxiosResponse` back.
|
|
102
|
+
*
|
|
103
|
+
* Prefer a decorated api method for anything that should participate in the
|
|
104
|
+
* plugin pipeline. Reach for this only for a call that genuinely has no place in
|
|
105
|
+
* a service definition, such as a health check against a third party.
|
|
106
|
+
*/
|
|
107
|
+
request<T = unknown, R = AxiosResponse<T>>(config: AxiosRequestConfig): Promise<R>;
|
|
108
|
+
/** Uninstall every plugin, running their cleanup hooks. */
|
|
109
|
+
dispose(): Promise<void>;
|
|
110
|
+
/** Metadata helper for tooling and tests. */
|
|
111
|
+
describe(): Record<string, unknown>;
|
|
112
|
+
/**
|
|
113
|
+
* Resolve everything static about one decorated method.
|
|
114
|
+
*
|
|
115
|
+
* Called once per method per api class. Returns `null` for a member that is not
|
|
116
|
+
* a decorated endpoint, which is how an api class may keep plain helpers next to
|
|
117
|
+
* its requests.
|
|
118
|
+
*/
|
|
119
|
+
private resolveMethodDescriptor;
|
|
120
|
+
/**
|
|
121
|
+
* Build the stream controller behind an `@HttpStream` method.
|
|
122
|
+
*
|
|
123
|
+
* A real context is constructed rather than a look-alike, so the `@Query()` /
|
|
124
|
+
* `@Data()` / `@HeaderValue()` resolvers behave exactly as they do for a normal
|
|
125
|
+
* request. The plugin pipeline is deliberately skipped: a byte stream has no
|
|
126
|
+
* envelope to cache or validate.
|
|
127
|
+
*/
|
|
128
|
+
private createHttpStream;
|
|
129
|
+
/** Construct the request object a proxied method call returns. */
|
|
130
|
+
private createMethod;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/core/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE9E,OAAO,KAAK,EAAE,aAAa,EAAuC,MAAM,gBAAgB,CAAC;AAEzF,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAEV,gBAAgB,EAChB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAS/D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAqBjD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,WAAW,CACtB,cAAc,GAAG,mBAAmB,EACpC,OAAO,SAAS,MAAM,GAAG,MAAM,EAC/B,OAAO,SAAS,MAAM,GAAG,MAAM,EAC/B,UAAU,SAAS,MAAM,GAAG,SAAS;IAErC,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,gDAAgD;IAChD,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IAExC,oEAAoE;IACpE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAE9B,qCAAqC;IACrC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IAEtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkC;IAE3D,cAiBC;IAED;;;;;;OAMG;IACH,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAI3D;IAED,kDAAkD;IAC5C,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAKtE;IAED,yDAAyD;IACzD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/B;IAED,+CAA+C;IAC/C,IAAI,OAAO,IAAI,SAAS,MAAM,EAAE,CAE/B;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAS,CAAC,MAAM,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,EACrD,QAAQ,EAAE,MAAM,GACf,aAAa,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,CAkEnF;IAED;;;;;;;;;;OAUG;IACH,SAAS,CAAC,MAAM,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,EACrD,QAAQ,EAAE,MAAM,GACf,gBAAgB,CAoBlB;IAED;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,MAAM,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,EAC3D,OAAO,EAAE,MAAM,GACd,eAAe,CAoBjB;IAED;;;;;;;;;;;;OAYG;IACG,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EAC7C,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,CAAC,CAAC,CAQZ;IAED,2DAA2D;IACrD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7B;IAED,6CAA6C;IAC7C,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAclC;IAID;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IA4D/B;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IAsDxB,kEAAkE;IAClE,OAAO,CAAC,YAAY;CAsCrB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SnailSseConnection, SnailSseOptions } from "../typings/stream.js";
|
|
2
|
+
import type { SnailSseHandlers } from "../decorators/stream.js";
|
|
3
|
+
import type { SnailLogger } from "./logger.js";
|
|
4
|
+
/** Everything the SSE transport needs to open a connection. */
|
|
5
|
+
export interface SseConnectionInit {
|
|
6
|
+
/** Fully qualified url. */
|
|
7
|
+
url: string;
|
|
8
|
+
/** Options from `@Sse(path, options)`. */
|
|
9
|
+
options: SnailSseOptions;
|
|
10
|
+
/** Handlers registered by the decorators. */
|
|
11
|
+
handlers: SnailSseHandlers;
|
|
12
|
+
/** Name used in log lines. */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Extra headers (server-level, auth, …). */
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
/** Logger. */
|
|
17
|
+
logger: SnailLogger;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Server-Sent Events over `fetch`.
|
|
21
|
+
*
|
|
22
|
+
* `EventSource` is deliberately not used: it cannot send request headers, cannot
|
|
23
|
+
* `POST`, cannot be aborted cleanly and reconnects on its own terms. A `fetch`
|
|
24
|
+
* stream reader supports all four, and the parser below is ~50 lines.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createSseConnection(init: SseConnectionInit): SnailSseConnection;
|
|
27
|
+
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/core/sse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAElB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAI7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,+DAA+D;AAC/D,MAAM,WAAW,iBAAiB;IAChC,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,0CAA0C;IAC1C,OAAO,EAAE,eAAe,CAAC;IACzB,6CAA6C;IAC7C,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,cAAc;IACd,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB,CAkN/E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed key/value bag.
|
|
3
|
+
*
|
|
4
|
+
* Two independent bags ride along every request:
|
|
5
|
+
*
|
|
6
|
+
* - `ctx.state` — **plugin scratch space**. Timers, cache keys, in-flight
|
|
7
|
+
* promises, tracing ids. Never exposed to the caller.
|
|
8
|
+
* - `ctx.meta` — **caller-visible reactive values** (`data`, `loading`, `error`)
|
|
9
|
+
* created by the framework adapter's `initMeta` hook.
|
|
10
|
+
*
|
|
11
|
+
* Keeping them separate matters: a plugin writing bookkeeping into `meta` would
|
|
12
|
+
* leak internal state into the object the UI renders.
|
|
13
|
+
*/
|
|
14
|
+
export declare class StateBag {
|
|
15
|
+
private readonly values;
|
|
16
|
+
/** Read a value, optionally falling back when the key is absent. */
|
|
17
|
+
get<T = unknown>(key: string): T | undefined;
|
|
18
|
+
get<T = unknown>(key: string, fallback: T): T;
|
|
19
|
+
/** Read a value, throwing when the key is absent. */
|
|
20
|
+
require<T = unknown>(key: string): T;
|
|
21
|
+
/** Write a value. */
|
|
22
|
+
set<T = unknown>(key: string, value: T): this;
|
|
23
|
+
/** Write a value only when the key is currently absent. */
|
|
24
|
+
setDefault<T = unknown>(key: string, value: T): T;
|
|
25
|
+
/** `true` when the key was ever set (even to `undefined`). */
|
|
26
|
+
has(key: string): boolean;
|
|
27
|
+
/** Remove a key. Returns whether it existed. */
|
|
28
|
+
delete(key: string): boolean;
|
|
29
|
+
/** Drop everything. */
|
|
30
|
+
clear(): void;
|
|
31
|
+
/** Current keys. */
|
|
32
|
+
keys(): string[];
|
|
33
|
+
/** Shallow snapshot, handy for logging and assertions. */
|
|
34
|
+
snapshot(): Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=state-bag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-bag.d.ts","sourceRoot":"","sources":["../../src/core/state-bag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8B;IAErD,oEAAoE;IACpE,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAC7C,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IAK9C,qDAAqD;IACrD,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAKnC;IAED,qBAAqB;IACrB,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAG5C;IAED,2DAA2D;IAC3D,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAGhD;IAED,8DAA8D;IAC9D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAExB;IAED,gDAAgD;IAChD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3B;IAED,uBAAuB;IACvB,KAAK,IAAI,IAAI,CAEZ;IAED,oBAAoB;IACpB,IAAI,IAAI,MAAM,EAAE,CAEf;IAED,0DAA0D;IAC1D,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAElC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SnailSocketConnection, SnailWsOptions } from "../typings/stream.js";
|
|
2
|
+
import type { SnailWsHandlers } from "../decorators/stream.js";
|
|
3
|
+
import type { SnailLogger } from "./logger.js";
|
|
4
|
+
/** Everything the WebSocket transport needs. */
|
|
5
|
+
export interface WsConnectionInit {
|
|
6
|
+
/** Fully qualified `ws://` / `wss://` url. */
|
|
7
|
+
url: string;
|
|
8
|
+
/** Options from `@WebSocket(path, options)`. */
|
|
9
|
+
options: SnailWsOptions;
|
|
10
|
+
/** Handlers registered by the decorators. */
|
|
11
|
+
handlers: SnailWsHandlers;
|
|
12
|
+
/** Name used in log lines. */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Logger. */
|
|
15
|
+
logger: SnailLogger;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* WebSocket with reconnecting and an outbound queue.
|
|
19
|
+
*
|
|
20
|
+
* Two behaviours the platform socket does not give you, and which every real
|
|
21
|
+
* application ends up writing by hand:
|
|
22
|
+
*
|
|
23
|
+
* - **Reconnect with backoff** — `close` is normal; without a policy the socket
|
|
24
|
+
* simply stays dead after a blip.
|
|
25
|
+
* - **Send-before-open queueing** — `open()` returns immediately, so a caller
|
|
26
|
+
* that sends on the next line would otherwise throw `InvalidStateError`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createWsConnection(init: WsConnectionInit): SnailSocketConnection;
|
|
29
|
+
//# sourceMappingURL=websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/core/websocket.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,gDAAgD;AAChD,MAAM,WAAW,gBAAgB;IAC/B,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,OAAO,EAAE,cAAc,CAAC;IACxB,6CAA6C;IAC7C,QAAQ,EAAE,eAAe,CAAC;IAC1B,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,qBAAqB,CA4IhF"}
|
package/dist/decorators/api.d.ts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
import "
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { SnailApiOptions } from "../typings/api.js";
|
|
2
|
+
/**
|
|
3
|
+
* Declare an api class.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* @Api("/user")
|
|
7
|
+
* class UserApi {
|
|
8
|
+
* @Get("/:id")
|
|
9
|
+
* getUser(@Params("id") id: string): Promise<User> { return null!; }
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* The url is a *prefix*: it is joined with the server `baseURL` and the method
|
|
14
|
+
* path, in that order.
|
|
15
|
+
*
|
|
16
|
+
* Always declare `@Api()` even when there is no prefix. It is what names the api
|
|
17
|
+
* for logging, cache namespacing and `@HitSource` targets; without it those fall
|
|
18
|
+
* back to the class name. The library does **not** enforce it at runtime —
|
|
19
|
+
* inherited api classes are legitimate and a base class may carry the decorator —
|
|
20
|
+
* so a missing `@Api()` silently degrades rather than throwing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function Api(url?: string): ClassDecorator;
|
|
23
|
+
export declare function Api(options: SnailApiOptions): ClassDecorator;
|
|
24
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/decorators/api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC;AAClD,wBAAgB,GAAG,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAAC"}
|
|
@@ -1,20 +1,83 @@
|
|
|
1
|
-
import "
|
|
2
|
-
export declare const REQUEST_ARGS_KEY: unique symbol;
|
|
1
|
+
import type { SnailParamResolver } from "../typings/args.js";
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* Parameter decorators.
|
|
4
|
+
*
|
|
5
|
+
* Two shapes, on purpose:
|
|
6
|
+
*
|
|
7
|
+
* - `@Query("page") page: number` — a **keyed** argument places one value.
|
|
8
|
+
* - `@Query() query: SomeShape` — a **key-less** argument spreads a plain object.
|
|
9
|
+
*
|
|
10
|
+
* A key-less argument that is not a plain object throws, naming the method and
|
|
11
|
+
* the parameter. The pre-rewrite code logged to `console.error` and then threw a
|
|
12
|
+
* message that did not say which method was at fault.
|
|
7
13
|
*/
|
|
8
|
-
|
|
14
|
+
/** A parameter decorator's accepted argument. */
|
|
15
|
+
export type ParamDecoratorInput<O = void> = string | (O & {
|
|
16
|
+
key?: string;
|
|
17
|
+
});
|
|
18
|
+
/** Normalise `"key"` / `{ key, ...options }` / `undefined`. */
|
|
19
|
+
export declare function normalizeParamInput<O>(input: ParamDecoratorInput<O> | undefined): {
|
|
20
|
+
key: string | undefined;
|
|
21
|
+
options: O | undefined;
|
|
22
|
+
};
|
|
9
23
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
24
|
+
* Write one parameter descriptor onto the decorated method.
|
|
25
|
+
*
|
|
26
|
+
* Parameter decorators run *before* the method decorator and in reverse index
|
|
27
|
+
* order, so this only ever appends — the descriptor list is sorted by index when
|
|
28
|
+
* the arguments are applied.
|
|
13
29
|
*/
|
|
14
|
-
export declare
|
|
30
|
+
export declare function defineParamDescriptor(source: string, resolver: SnailParamResolver, input: ParamDecoratorInput<any> | undefined, target: unknown, propertyKey: string | symbol | undefined, index: number): void;
|
|
15
31
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
32
|
+
* Build a parameter decorator for a registered source.
|
|
33
|
+
*
|
|
34
|
+
* Built-in sources are `params`, `query`, `data` and `header`. A plugin can add
|
|
35
|
+
* its own with `createPlugin`'s `defineParamSource`.
|
|
19
36
|
*/
|
|
20
|
-
export declare
|
|
37
|
+
export declare function createParamDecoratorFor<O = void>(source: string): (input?: ParamDecoratorInput<O>) => ParameterDecorator;
|
|
38
|
+
/**
|
|
39
|
+
* Path placeholders.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* @Api("/user")
|
|
43
|
+
* class UserApi {
|
|
44
|
+
* @Get("/:id/:tab")
|
|
45
|
+
* get(@Params("id") id: string, @Params("tab") tab: string) {}
|
|
46
|
+
* // or, equivalently
|
|
47
|
+
* @Get("/:id/:tab")
|
|
48
|
+
* get(@Params() params: { id: string; tab: string }) {}
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const Params: (input?: ParamDecoratorInput<void> | undefined) => ParameterDecorator;
|
|
53
|
+
/**
|
|
54
|
+
* Query string parameters.
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* @Get("/list")
|
|
58
|
+
* list(@Query("page") page: number, @Query() filters: { q?: string }) {}
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const Query: (input?: ParamDecoratorInput<void> | undefined) => ParameterDecorator;
|
|
62
|
+
/**
|
|
63
|
+
* Request body.
|
|
64
|
+
*
|
|
65
|
+
* Keyed arguments merge into an object body. A key-less plain object merges too,
|
|
66
|
+
* while any other value (`FormData`, `Blob`, a raw string, an array) replaces the
|
|
67
|
+
* body outright so non-JSON uploads stay possible.
|
|
68
|
+
*/
|
|
69
|
+
export declare const Data: (input?: ParamDecoratorInput<void> | undefined) => ParameterDecorator;
|
|
70
|
+
/**
|
|
71
|
+
* A single request header.
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* @Get("/me")
|
|
75
|
+
* me(@HeaderValue("authorization") token: string) {}
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* For *static* headers use the class/method level `@Header({ ... })` instead.
|
|
79
|
+
*/
|
|
80
|
+
export declare const HeaderValue: (input?: ParamDecoratorInput<void> | undefined) => ParameterDecorator;
|
|
81
|
+
/** Legacy alias — the pre-rewrite library exposed the header source as `Header`. */
|
|
82
|
+
export declare const HeaderParam: (input?: ParamDecoratorInput<void> | undefined) => ParameterDecorator;
|
|
83
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/decorators/args.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAwB,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAKhF;;;;;;;;;;;GAWG;AAEH,iDAAiD;AACjD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE5E,+DAA+D;AAC/D,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,SAAS,GACxC;IAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,OAAO,EAAE,CAAC,GAAG,SAAS,CAAA;CAAE,CAgBrD;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,kBAAkB,EAC5B,KAAK,EAAE,mBAAmB,CAAC,GAAG,CAAC,GAAG,SAAS,EAC3C,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EACxC,KAAK,EAAE,MAAM,GACZ,IAAI,CAgBN;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,GAAG,IAAI,EAC9C,MAAM,EAAE,MAAM,GACb,CAAC,KAAK,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,kBAAkB,CAgBxD;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM,qDAhCoB,kBAgCgB,CAAC;AAExD;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,qDA1CqB,kBA0Cc,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,qDAnDsB,kBAmDY,CAAC;AAEpD;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,qDA/De,kBA+DqB,CAAC;AAE7D,oFAAoF;AACpF,eAAO,MAAM,WAAW,qDAlEe,kBAkED,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { SnailParamResolver } from "../typings/args.js";
|
|
2
|
+
import { type ParamDecoratorInput } from "./args.js";
|
|
3
|
+
/**
|
|
4
|
+
* Extension factories for third-party decorators.
|
|
5
|
+
*
|
|
6
|
+
* The library's own decorators are built from these, so anything the core can do
|
|
7
|
+
* a plugin can do too.
|
|
8
|
+
*
|
|
9
|
+
* ## Key namespacing
|
|
10
|
+
*
|
|
11
|
+
* Custom keys are derived from a name you supply:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const TENANT = customMetadataKey("acme/tenant");
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Prefix your name with your package to make collisions impossible. The reserved
|
|
18
|
+
* prefix `@snail-js/api:` belongs to the core.
|
|
19
|
+
*/
|
|
20
|
+
/** Build a namespaced metadata key for a custom decorator. */
|
|
21
|
+
export declare function customMetadataKey(name: string): symbol;
|
|
22
|
+
/**
|
|
23
|
+
* Create a **parameter** decorator.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* // 1. register a source (usually inside a plugin's setup)
|
|
27
|
+
* api.defineParamSource("tenant", ({ ctx, value }) => {
|
|
28
|
+
* ctx.request.headers.set("x-tenant", String(value));
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // 2. expose a decorator built on it
|
|
32
|
+
* export const Tenant = createParamDecorator("tenant");
|
|
33
|
+
*
|
|
34
|
+
* // 3. use it
|
|
35
|
+
* @Get("/orders")
|
|
36
|
+
* orders(@Tenant() tenantId: string) {}
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* Pass an explicit `resolver` to skip step 1 and keep everything in one place.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createParamDecorator<O = void>(source: string, resolver?: SnailParamResolver): (input?: ParamDecoratorInput<O>) => ParameterDecorator;
|
|
42
|
+
/**
|
|
43
|
+
* Create a **class** decorator.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* export const Entity = createClassDecorator<string>("acme/entity");
|
|
47
|
+
* @Entity("orders") class OrderApi {}
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param name metadata key name
|
|
51
|
+
* @param merge when `true` (the default) repeated applications keep every value
|
|
52
|
+
* in an array instead of overwriting
|
|
53
|
+
*/
|
|
54
|
+
export declare function createClassDecorator<T = unknown>(name: string, merge?: boolean): (value: T) => ClassDecorator;
|
|
55
|
+
/**
|
|
56
|
+
* Create a **method** decorator.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* export const Retry = createMethodDecorator<number>("acme/retry");
|
|
60
|
+
* @Get("/flaky") @Retry(3) flaky() {}
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function createMethodDecorator<T = unknown>(name: string, merge?: boolean): (value: T) => MethodDecorator;
|
|
64
|
+
/** Read metadata written by a custom method decorator. */
|
|
65
|
+
export declare function getMethodMetadata<T>(name: string, target: unknown, methodName: string): T | undefined;
|
|
66
|
+
/** Read metadata written by a custom class decorator. */
|
|
67
|
+
export declare function getClassMetadata<T>(name: string, target: unknown): T | undefined;
|
|
68
|
+
/** Read metadata written by a custom method decorator on exactly this class. */
|
|
69
|
+
export declare function getOwnMethodMetadata<T>(name: string, target: unknown, methodName: string): T | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Create a **property** decorator.
|
|
72
|
+
*
|
|
73
|
+
* Property decorators are handy for DTO classes consumed by the transform plugin:
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const Alias = createPropertyDecorator<string>("acme/alias");
|
|
77
|
+
* class UserDto { @Alias("user_name") userName!: string }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function createPropertyDecorator<T = unknown>(name: string): (value: T) => PropertyDecorator;
|
|
81
|
+
//# sourceMappingURL=custom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/decorators/custom.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAEzE;;;;;;;;;;;;;;;;GAgBG;AAEH,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKtD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,IAAI,EAC3C,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,kBAAkB,GAC5B,CAAC,KAAK,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,kBAAkB,CAexD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,OAAO,EAC9C,IAAI,EAAE,MAAM,EACZ,KAAK,UAAO,GACX,CAAC,KAAK,EAAE,CAAC,KAAK,cAAc,CAM9B;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,GAAG,OAAO,EAC/C,IAAI,EAAE,MAAM,EACZ,KAAK,UAAO,GACX,CAAC,KAAK,EAAE,CAAC,KAAK,eAAe,CAW/B;AAED,0DAA0D;AAC1D,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAErG;AAED,yDAAyD;AACzD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,CAAC,GAAG,SAAS,CAEhF;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,MAAM,GACjB,CAAC,GAAG,SAAS,CAEf;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,GAAG,OAAO,EACjD,IAAI,EAAE,MAAM,GACX,CAAC,KAAK,EAAE,CAAC,KAAK,iBAAiB,CAKjC"}
|