@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,51 @@
|
|
|
1
|
+
import type { SnailContext } from "../core/context.js";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in parameter sources.
|
|
4
|
+
*
|
|
5
|
+
* `"params"` → path placeholders, `"query"` → query string, `"data"` → request
|
|
6
|
+
* body, `"header"` → request header.
|
|
7
|
+
*/
|
|
8
|
+
export type SnailBuiltinParamSource = "params" | "query" | "data" | "header";
|
|
9
|
+
/**
|
|
10
|
+
* A parameter source — a built-in name, or any string a plugin registered
|
|
11
|
+
* through `createParamDecorator`.
|
|
12
|
+
*/
|
|
13
|
+
export type SnailParamSource = SnailBuiltinParamSource | (string & {});
|
|
14
|
+
/** Everything a parameter resolver needs to place one argument. */
|
|
15
|
+
export interface SnailParamResolverInput {
|
|
16
|
+
/** Live request context; mutate `ctx.request` to affect the outgoing request. */
|
|
17
|
+
ctx: SnailContext;
|
|
18
|
+
/** The runtime argument value at `index`. */
|
|
19
|
+
value: unknown;
|
|
20
|
+
/** The key passed to the decorator, when one was given. */
|
|
21
|
+
key: string | undefined;
|
|
22
|
+
/** Extra options passed to the decorator, when any. */
|
|
23
|
+
options: unknown;
|
|
24
|
+
/** Position of the argument in the method signature. */
|
|
25
|
+
index: number;
|
|
26
|
+
/** Method name the argument belongs to. */
|
|
27
|
+
methodName: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Applies one decorated argument to the request context.
|
|
31
|
+
*
|
|
32
|
+
* Built-in sources use the resolvers in `core/args.ts`; plugins add their own
|
|
33
|
+
* through `createParamDecorator`.
|
|
34
|
+
*/
|
|
35
|
+
export type SnailParamResolver = (input: SnailParamResolverInput) => void;
|
|
36
|
+
/** One `@Query()` / `@Params()` / custom parameter decorator application. */
|
|
37
|
+
export interface SnailParamDescriptor {
|
|
38
|
+
/** e.g. `"query"`, `"params"`, `"data"`, `"header"`, or a plugin's source name. */
|
|
39
|
+
readonly source: SnailParamSource;
|
|
40
|
+
/** Position in the method signature. */
|
|
41
|
+
readonly index: number;
|
|
42
|
+
/** Key passed to the decorator, if any. */
|
|
43
|
+
readonly key?: string;
|
|
44
|
+
/** Extra options passed to the decorator, if any. */
|
|
45
|
+
readonly options?: unknown;
|
|
46
|
+
/** How to apply this argument to the context. */
|
|
47
|
+
readonly resolve: SnailParamResolver;
|
|
48
|
+
}
|
|
49
|
+
/** A record-shaped value contributed to the request. */
|
|
50
|
+
export type SnailParamRecord = Record<string, unknown>;
|
|
51
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/typings/args.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC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
|
9
|
-
export * from "./apiProxy";
|
|
10
|
-
export * from "./sse";
|
|
11
|
-
export * from "./snail.method";
|
|
12
|
-
export * from "./snail.event";
|
|
1
|
+
export type { SnailApiOptions, SnailApiProxy, SnailAxiosMethod, SnailMethodDecoratorOptions, SnailMethodMeta, SnailMethodOptions, SnailMethodType, SnailMethodTypeLower, SnailPayloadOf, SnailSendOptions } from "./api.js";
|
|
2
|
+
export type { SnailBuiltinParamSource, SnailParamDescriptor, SnailParamRecord, SnailParamResolver, SnailParamResolverInput, SnailParamSource } from "./args.js";
|
|
3
|
+
export type { SnailStateAdapter, SnailStateRef, SnailStrategyCommonOptions } from "./adapter.js";
|
|
4
|
+
export type { SnailMeta } from "./meta.js";
|
|
5
|
+
export type { SnailHookKind, SnailHookName, SnailNext, SnailPlugin, SnailPluginInstallContext, SnailPluginObject } from "./plugin.js";
|
|
6
|
+
export type { IsRawPayload, SnailCacheHitCallback, SnailCodeErrorCallback, SnailCodeOf, SnailCodeValidator, SnailEnvelope, SnailEnvelopeSchema, SnailErrorCallback, SnailFinishCallback, SnailMessageOf, SnailRawPayload, SnailResponseKeys, SnailResult, SnailSuccessCallback } from "./response.js";
|
|
7
|
+
export type { ResolvedServerOptions, SnailLogLevel, SnailServerEnvelope, SnailServerOptions } from "./server.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/typings/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,2BAA2B,EAC3B,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EACjB,MAAM,OAAO,CAAC;AAEf,YAAY,EACV,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,QAAQ,CAAC;AAEhB,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,0BAA0B,EAC3B,MAAM,WAAW,CAAC;AAEnB,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,YAAY,EACV,aAAa,EACb,aAAa,EACb,SAAS,EACT,WAAW,EACX,yBAAyB,EACzB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,EACtB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { SnailStateRef } from "./adapter.js";
|
|
2
|
+
/**
|
|
3
|
+
* The caller-visible handles a framework adapter publishes on
|
|
4
|
+
* `SnailMethod.meta`.
|
|
5
|
+
*
|
|
6
|
+
* ## Augmenting it
|
|
7
|
+
*
|
|
8
|
+
* This interface is the `declare module` extension point for the adapter types,
|
|
9
|
+
* mirroring how `SnailEnvelopeSchema` is the one for the response envelope:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* // app/env.d.ts
|
|
13
|
+
* import type { Ref } from "vue";
|
|
14
|
+
*
|
|
15
|
+
* declare module "@snail-js/api" {
|
|
16
|
+
* interface SnailMeta {
|
|
17
|
+
* data: Ref<User>;
|
|
18
|
+
* code: Ref<number>;
|
|
19
|
+
* message: Ref<string>;
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* const method = userApi.getUser("1");
|
|
24
|
+
* method.meta.data; // Ref<User>
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ## Why `data` / `code` / `message` are not declared here
|
|
28
|
+
*
|
|
29
|
+
* Their names come from `@Server({ dataKey, codeKey, messageKey })`, which is a
|
|
30
|
+
* runtime value — a static interface cannot name a key that is only known at
|
|
31
|
+
* configuration time. Declaring them with a placeholder type would make
|
|
32
|
+
* augmentation impossible (interface merging can only *add*, never narrow), so
|
|
33
|
+
* they are left to the application to declare with its real payload type.
|
|
34
|
+
*
|
|
35
|
+
* `loading` and `error` are different: every adapter owns those two names and
|
|
36
|
+
* their types are fixed, so they are declared here and typed precisely.
|
|
37
|
+
*/
|
|
38
|
+
export interface SnailMeta {
|
|
39
|
+
/** `true` while a request is in flight. Present with any state adapter. */
|
|
40
|
+
loading?: SnailStateRef<boolean>;
|
|
41
|
+
/** The most recent failure, or `undefined`. Present with any state adapter. */
|
|
42
|
+
error?: SnailStateRef<unknown>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../src/typings/meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,WAAW,SAAS;IACxB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IAEjC,+EAA+E;IAC/E,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAChC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { AxiosRequestConfig, InternalAxiosRequestConfig } from "axios";
|
|
2
|
+
import type { SnailContext } from "../core/context.js";
|
|
3
|
+
import type { ResolvedServerOptions } from "./server.js";
|
|
4
|
+
import type { SnailApiOptions, SnailMethodOptions } from "./api.js";
|
|
5
|
+
/**
|
|
6
|
+
* The `next` callback handed to every chain-style plugin hook.
|
|
7
|
+
*
|
|
8
|
+
* Calling it hands control to the next plugin in the chain. It resolves once
|
|
9
|
+
* every later plugin — and the actual HTTP request — has finished.
|
|
10
|
+
*/
|
|
11
|
+
export type SnailNext = () => Promise<void>;
|
|
12
|
+
/** Stage at which a plugin hook runs. */
|
|
13
|
+
export type SnailHookKind = "config" | "chain" | "effect";
|
|
14
|
+
/** Names of every lifecycle hook, in execution order. */
|
|
15
|
+
export type SnailHookName = "install" | "uninstall" | "configureServer" | "configureApi" | "configureMethod" | "initMeta" | "beforeCreate" | "beforeRequest" | "requestInterceptor" | "afterResponse" | "responseInterceptor" | "onError" | "afterRequest";
|
|
16
|
+
/**
|
|
17
|
+
* Object returned by a plugin factory. This is the whole plugin contract.
|
|
18
|
+
*
|
|
19
|
+
* Only `name` is required. Everything else is an optional lifecycle hook; a
|
|
20
|
+
* plugin implements just the hooks it cares about.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const Timing = definePlugin(() => ({
|
|
25
|
+
* name: "timing",
|
|
26
|
+
* beforeRequest: (ctx) => { ctx.state.set("t0", Date.now()); },
|
|
27
|
+
* afterRequest: (ctx) => console.log("took", Date.now() - ctx.state.get("t0"))
|
|
28
|
+
* }));
|
|
29
|
+
* Service.use(Timing());
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface SnailPluginObject<O = unknown> {
|
|
33
|
+
/** Unique plugin name. Re-registering the same name on one server is an error. */
|
|
34
|
+
readonly name: string;
|
|
35
|
+
/**
|
|
36
|
+
* Execution order inside each chain. **Higher runs first.** Defaults to `0`.
|
|
37
|
+
*
|
|
38
|
+
* Built-in plugins claim the following bands so third-party plugins can slot
|
|
39
|
+
* between them:
|
|
40
|
+
* - `100` interceptor
|
|
41
|
+
* - `50` version
|
|
42
|
+
* - `0` adapter / framework / user plugins
|
|
43
|
+
* - `-50` validate
|
|
44
|
+
* - `-100` cache
|
|
45
|
+
*/
|
|
46
|
+
readonly priority?: number;
|
|
47
|
+
/** Plugin names that must be registered before this one. */
|
|
48
|
+
readonly dependsOn?: readonly string[];
|
|
49
|
+
/** Options this instance was created with, surfaced for debugging. */
|
|
50
|
+
readonly options?: O;
|
|
51
|
+
/** Called once, when the plugin is added to a server. */
|
|
52
|
+
install?(ctx: SnailPluginInstallContext, options: O): void | Promise<void>;
|
|
53
|
+
/** Called when the plugin is removed, or when the server is disposed. */
|
|
54
|
+
uninstall?(ctx: SnailPluginInstallContext, options: O): void | Promise<void>;
|
|
55
|
+
/** Mutate the resolved server options. Runs when the server instance is built. */
|
|
56
|
+
configureServer?(options: ResolvedServerOptions): void;
|
|
57
|
+
/** Mutate the resolved api options. Runs the first time a method is proxied. */
|
|
58
|
+
configureApi?(options: SnailApiOptions, apiClass: new () => unknown): void;
|
|
59
|
+
/** Mutate the resolved method options. Runs the first time a method is proxied. */
|
|
60
|
+
configureMethod?(options: SnailMethodOptions, methodName: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* Add the reactive values this plugin owns to `ctx.meta`.
|
|
63
|
+
*
|
|
64
|
+
* Runs once per `send()`, before any request work. Framework adapters use it
|
|
65
|
+
* to expose `loading` / `data` / `error`.
|
|
66
|
+
*/
|
|
67
|
+
initMeta?(ctx: SnailContext): void;
|
|
68
|
+
/** Runs after `initMeta`, before the argument decorators are applied. */
|
|
69
|
+
beforeCreate?(ctx: SnailContext): void;
|
|
70
|
+
/**
|
|
71
|
+
* Runs before the request is handed to axios.
|
|
72
|
+
*
|
|
73
|
+
* Chain hook: `await next()` to continue. Skipping `next()` aborts the
|
|
74
|
+
* request. Setting `ctx.response` and calling `ctx.interrupt()` short-circuits
|
|
75
|
+
* the network call entirely — that is how the cache plugin serves a hit.
|
|
76
|
+
*/
|
|
77
|
+
beforeRequest?(ctx: SnailContext, next: SnailNext): Promise<void> | void;
|
|
78
|
+
/**
|
|
79
|
+
* Low-level rewrite of the final axios config.
|
|
80
|
+
*
|
|
81
|
+
* Runs synchronously, right before `axios.request`, in registration order.
|
|
82
|
+
* Return a new config to replace it. Use this for signing, tracing headers and
|
|
83
|
+
* anything that must run after every other plugin settled.
|
|
84
|
+
*/
|
|
85
|
+
requestInterceptor?(config: InternalAxiosRequestConfig, ctx: SnailContext): AxiosRequestConfig | void;
|
|
86
|
+
/**
|
|
87
|
+
* Runs after a successful HTTP round-trip, before the envelope is validated.
|
|
88
|
+
*
|
|
89
|
+
* Chain hook: `await next()` to continue. Skipping `next()` means later
|
|
90
|
+
* plugins and the caller see whatever `ctx.response` currently holds.
|
|
91
|
+
*/
|
|
92
|
+
afterResponse?(ctx: SnailContext, next: SnailNext): Promise<void> | void;
|
|
93
|
+
/** Low-level rewrite of the axios response, in registration order. */
|
|
94
|
+
responseInterceptor?(response: import("axios").AxiosResponse, ctx: SnailContext): import("axios").AxiosResponse | void;
|
|
95
|
+
/** Observe a failure. Cannot recover it; use `beforeRequest` for that. */
|
|
96
|
+
onError?(ctx: SnailContext, error: unknown): void;
|
|
97
|
+
/**
|
|
98
|
+
* Runs in `finally`, whether the request succeeded, failed or was cancelled.
|
|
99
|
+
* This is where plugins release resources and stop timers.
|
|
100
|
+
*/
|
|
101
|
+
afterRequest?(ctx: SnailContext): void;
|
|
102
|
+
}
|
|
103
|
+
/** The subset of server capabilities a plugin may use during install. */
|
|
104
|
+
export interface SnailPluginInstallContext {
|
|
105
|
+
/** Name of the server the plugin was installed on. */
|
|
106
|
+
readonly serverName: string;
|
|
107
|
+
/** Resolved server options (mutable, but prefer `configureServer`). */
|
|
108
|
+
readonly serverOptions: ResolvedServerOptions;
|
|
109
|
+
/** Names of every plugin currently registered on the server, in chain order. */
|
|
110
|
+
readonly pluginNames: readonly string[];
|
|
111
|
+
}
|
|
112
|
+
/** A plugin factory: `(options) => SnailPluginObject`. */
|
|
113
|
+
export type SnailPlugin<O = unknown> = (options?: O) => SnailPluginObject<O>;
|
|
114
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":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yBAAyB;IACxC,sDAAsD;IACtD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,uEAAuE;IACvE,QAAQ,CAAC,aAAa,EAAE,qBAAqB,CAAC;IAC9C,gFAAgF;IAChF,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC;AAED,0DAA0D;AAC1D,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response typing.
|
|
3
|
+
*
|
|
4
|
+
* The library assumes every JSON endpoint answers with a standard envelope:
|
|
5
|
+
*
|
|
6
|
+
* ```json
|
|
7
|
+
* { "code": 0, "message": "ok", "data": {} }
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Both the *shape* and the *key names* are overridable.
|
|
11
|
+
*
|
|
12
|
+
* ## Overriding the shape
|
|
13
|
+
*
|
|
14
|
+
* The default envelope is `SnailEnvelopeSchema`, which is module-augmentable:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* // app/env.d.ts
|
|
18
|
+
* declare module "@snail-js/api" {
|
|
19
|
+
* interface SnailEnvelopeSchema {
|
|
20
|
+
* status: number;
|
|
21
|
+
* msg: string;
|
|
22
|
+
* result: unknown;
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ## Overriding the key names
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* @Server({
|
|
31
|
+
* baseURL: "/api",
|
|
32
|
+
* codeKey: "status",
|
|
33
|
+
* messageKey: "msg",
|
|
34
|
+
* dataKey: "result"
|
|
35
|
+
* })
|
|
36
|
+
* class BackEnd extends SnailServer<SnailEnvelopeSchema, "result", "status", "msg"> {}
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* This module is types-only on purpose: it is safe to `import type` from, and it
|
|
40
|
+
* contributes nothing to the runtime bundle.
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* The envelope every JSON endpoint is assumed to return.
|
|
44
|
+
*
|
|
45
|
+
* Augment this interface to reshape the default for the whole application.
|
|
46
|
+
*/
|
|
47
|
+
export interface SnailEnvelopeSchema {
|
|
48
|
+
code: number;
|
|
49
|
+
message: string;
|
|
50
|
+
data: unknown;
|
|
51
|
+
}
|
|
52
|
+
/** Key names used to read the envelope. */
|
|
53
|
+
export interface SnailResponseKeys {
|
|
54
|
+
/** Key holding the business status code. Defaults to `"code"`. */
|
|
55
|
+
code: string;
|
|
56
|
+
/** Key holding the human readable message. Defaults to `"message"`. */
|
|
57
|
+
message: string;
|
|
58
|
+
/** Key holding the actual payload. Defaults to `"data"`. */
|
|
59
|
+
data: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Payloads that bypass the envelope entirely.
|
|
63
|
+
*
|
|
64
|
+
* A `blob` / `arraybuffer` / `stream` response has no `code`/`message`/`data`,
|
|
65
|
+
* so the typed result of such a request is the body itself.
|
|
66
|
+
*/
|
|
67
|
+
export type SnailRawPayload = Blob | ArrayBuffer | ReadableStream<Uint8Array> | FormData | Document;
|
|
68
|
+
/** `true` when `T` is a pass-through payload rather than a JSON envelope. */
|
|
69
|
+
export type IsRawPayload<T> = T extends SnailRawPayload ? true : false;
|
|
70
|
+
/**
|
|
71
|
+
* The full envelope for a payload of type `T`, or `T` itself when `T` is a raw
|
|
72
|
+
* pass-through payload.
|
|
73
|
+
*/
|
|
74
|
+
export type SnailEnvelope<S, T, D extends string = "data"> = IsRawPayload<T> extends true ? T : S extends Record<string, any> ? S & Record<D, T> : Record<D, T>;
|
|
75
|
+
/** Business status code type, derived from the envelope when possible. */
|
|
76
|
+
export type SnailCodeOf<S, C extends string = "code"> = C extends keyof S ? S[C] : number | string | undefined;
|
|
77
|
+
/** Business message type, derived from the envelope when possible. */
|
|
78
|
+
export type SnailMessageOf<S, M extends string = "message"> = M extends keyof S ? S[M] : string | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* What every `send()` resolves to.
|
|
81
|
+
*
|
|
82
|
+
* Deliberately richer than the old API's bare envelope: `data` is already
|
|
83
|
+
* unwrapped (the thing you want almost always) while `envelope` and `response`
|
|
84
|
+
* stay available for everything else.
|
|
85
|
+
*/
|
|
86
|
+
export interface SnailResult<S = SnailEnvelopeSchema, T = unknown, D extends string = "data", C extends string = "code", M extends string = "message"> {
|
|
87
|
+
/** The raw axios response. */
|
|
88
|
+
response: import("axios").AxiosResponse<SnailEnvelope<S, T, D>>;
|
|
89
|
+
/** The parsed backend envelope (`{ code, message, data }` by default). */
|
|
90
|
+
envelope: SnailEnvelope<S, T, D>;
|
|
91
|
+
/** The unwrapped payload — `envelope[dataKey]`. */
|
|
92
|
+
data: T;
|
|
93
|
+
/** Business code — `envelope[codeKey]`. */
|
|
94
|
+
code: SnailCodeOf<S, C>;
|
|
95
|
+
/** Business message — `envelope[messageKey]`. */
|
|
96
|
+
message: SnailMessageOf<S, M>;
|
|
97
|
+
/** `true` when the value came from a cache instead of the network. */
|
|
98
|
+
fromCache: boolean;
|
|
99
|
+
/** The final request config, after every plugin and strategy ran. */
|
|
100
|
+
config: import("axios").InternalAxiosRequestConfig;
|
|
101
|
+
}
|
|
102
|
+
/** Callback invoked when a request succeeds. */
|
|
103
|
+
export type SnailSuccessCallback<S, T, D extends string = "data"> = (result: SnailResult<S, T, D, any, any>) => void;
|
|
104
|
+
/** Callback invoked when a request fails. */
|
|
105
|
+
export type SnailErrorCallback = (error: unknown) => void;
|
|
106
|
+
/** Callback invoked when the business code is rejected. */
|
|
107
|
+
export type SnailCodeErrorCallback<T = unknown> = (code: number | string, payload: T, error: unknown) => void;
|
|
108
|
+
/** Callback invoked when a request settles, successfully or not. */
|
|
109
|
+
export type SnailFinishCallback = () => void;
|
|
110
|
+
/** Callback invoked when the response was served from a cache. */
|
|
111
|
+
export type SnailCacheHitCallback = () => void;
|
|
112
|
+
/**
|
|
113
|
+
* Verdict function deciding whether a business status code is acceptable.
|
|
114
|
+
*
|
|
115
|
+
* Return `true` to accept, `false` to reject with a `SnailResponseError`.
|
|
116
|
+
*/
|
|
117
|
+
export type SnailCodeValidator = (code: number | string, envelope: unknown) => boolean;
|
|
118
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/typings/response.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,2CAA2C;AAC3C,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GACvB,IAAI,GACJ,WAAW,GACX,cAAc,CAAC,UAAU,CAAC,GAC1B,QAAQ,GACR,QAAQ,CAAC;AAEb,6EAA6E;AAC7E,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,eAAe,GAAG,IAAI,GAAG,KAAK,CAAC;AAEvE;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,IACvD,YAAY,CAAC,CAAC,CAAC,SAAS,IAAI,GACxB,CAAC,GACD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC3B,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACh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G,MAAM,IAAI,CAClE,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,KACnC,IAAI,CAAC;AAEV,6CAA6C;AAC7C,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AAE1D,2DAA2D;AAC3D,MAAM,MAAM,sBAAsB,CAAC,CAAC,GAAG,OAAO,IAAI,CAChD,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,OAAO,KACX,IAAI,CAAC;AAEV,oEAAoE;AACpE,MAAM,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC;AAE7C,kEAAkE;AAClE,MAAM,MAAM,qBAAqB,GAAG,MAAM,IAAI,CAAC;AAE/C;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,QAAQ,EAAE,OAAO,KACd,OAAO,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from "axios";
|
|
2
|
+
import type { SnailCodeValidator, SnailEnvelopeSchema } from "./response.js";
|
|
3
|
+
/** Severity used by the logger. */
|
|
4
|
+
export type SnailLogLevel = "silent" | "error" | "warn" | "info" | "debug";
|
|
5
|
+
/**
|
|
6
|
+
* Options accepted by `@Server(...)`.
|
|
7
|
+
*
|
|
8
|
+
* Every field is optional; unspecified fields fall back to
|
|
9
|
+
* `DEFAULT_SERVER_OPTIONS`.
|
|
10
|
+
*/
|
|
11
|
+
export interface SnailServerOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Unique identifier of this server.
|
|
14
|
+
*
|
|
15
|
+
* Defaults to the decorated class name. It namespaces plugin registries,
|
|
16
|
+
* cache entries and log lines, so two servers in one app must not share it.
|
|
17
|
+
*/
|
|
18
|
+
name?: string;
|
|
19
|
+
/** Prefix every request url is resolved against. Defaults to `"/"`. */
|
|
20
|
+
baseURL?: string;
|
|
21
|
+
/** Request timeout in milliseconds. Defaults to `10000`. */
|
|
22
|
+
timeout?: number;
|
|
23
|
+
/**
|
|
24
|
+
* axios adapter. Leave unset to use axios' own default detection, which picks
|
|
25
|
+
* `xhr`/`fetch` in a browser and `http` in Node.
|
|
26
|
+
*/
|
|
27
|
+
adapter?: AxiosRequestConfig["adapter"];
|
|
28
|
+
/** Extra headers merged into every request of this server. */
|
|
29
|
+
headers?: AxiosRequestConfig["headers"];
|
|
30
|
+
/** Extra query params merged into every request of this server. */
|
|
31
|
+
params?: AxiosRequestConfig["params"];
|
|
32
|
+
/** Default `responseType` for every request of this server. */
|
|
33
|
+
responseType?: AxiosRequestConfig["responseType"];
|
|
34
|
+
/** Send cookies / auth headers on cross-site requests. */
|
|
35
|
+
withCredentials?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Key holding the business status code. Defaults to `"code"`.
|
|
38
|
+
* @see SnailResponseKeys
|
|
39
|
+
*/
|
|
40
|
+
codeKey?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Key holding the business message. Defaults to `"message"`.
|
|
43
|
+
* @see SnailResponseKeys
|
|
44
|
+
*/
|
|
45
|
+
messageKey?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Key holding the payload. Defaults to `"data"`.
|
|
48
|
+
* @see SnailResponseKeys
|
|
49
|
+
*/
|
|
50
|
+
dataKey?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Decides whether a business status code is acceptable.
|
|
53
|
+
*
|
|
54
|
+
* Defaults to accepting `0` and `200`. Returning `false` rejects the request
|
|
55
|
+
* with a `SnailResponseError` carrying the full envelope.
|
|
56
|
+
*/
|
|
57
|
+
validateCode?: SnailCodeValidator;
|
|
58
|
+
/**
|
|
59
|
+
* Log level. Defaults to `"silent"`, because a request library must not write
|
|
60
|
+
* to the console unless the application asked for it.
|
|
61
|
+
*/
|
|
62
|
+
logLevel?: SnailLogLevel;
|
|
63
|
+
/** Parse a JSON string body when the server forgot the content-type header. */
|
|
64
|
+
coerceJSONString?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* `SnailServerOptions` with every default applied.
|
|
68
|
+
*
|
|
69
|
+
* Plugins receive this, so they never have to re-apply defaults themselves.
|
|
70
|
+
*/
|
|
71
|
+
export interface ResolvedServerOptions extends SnailServerOptions {
|
|
72
|
+
name: string;
|
|
73
|
+
baseURL: string;
|
|
74
|
+
timeout: number;
|
|
75
|
+
codeKey: string;
|
|
76
|
+
messageKey: string;
|
|
77
|
+
dataKey: string;
|
|
78
|
+
logLevel: SnailLogLevel;
|
|
79
|
+
coerceJSONString: boolean;
|
|
80
|
+
}
|
|
81
|
+
/** Narrow an arbitrary value to a usable envelope schema. */
|
|
82
|
+
export type SnailServerEnvelope = SnailEnvelopeSchema;
|
|
83
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/typings/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE1E,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAExC,8DAA8D;IAC9D,OAAO,CAAC,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAExC,mEAAmE;IACnE,MAAM,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAEtC,+DAA+D;IAC/D,YAAY,CAAC,EAAE,kBAAkB,CAAC,cAAc,CAAC,CAAC;IAElD,0DAA0D;IAC1D,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAElC;;;OAGG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC;IAEzB,+EAA+E;IAC/E,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,aAAa,CAAC;IACxB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,6DAA6D;AAC7D,MAAM,MAAM,mBAAmB,GAAG,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/** Types for the SSE / WebSocket / HTTP-stream transports. */
|
|
2
|
+
/** Backoff policy shared by the reconnecting transports. */
|
|
3
|
+
export interface SnailReconnectPolicy {
|
|
4
|
+
/** Extra attempts after the first failure. Defaults to `3`. */
|
|
5
|
+
retries?: number;
|
|
6
|
+
/** First delay in milliseconds. Defaults to `1000`. */
|
|
7
|
+
delayMs?: number;
|
|
8
|
+
/** Upper bound for the delay. Defaults to `30000`. */
|
|
9
|
+
maxDelayMs?: number;
|
|
10
|
+
/** Multiplier applied to the delay after each failure. Defaults to `2`. */
|
|
11
|
+
factor?: number;
|
|
12
|
+
/** Add random jitter to avoid a thundering herd. Defaults to `true`. */
|
|
13
|
+
jitter?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** One decoded server-sent event. */
|
|
16
|
+
export interface SnailSseMessage {
|
|
17
|
+
/** Event name — `"message"` for the default event. */
|
|
18
|
+
event: string;
|
|
19
|
+
/** Raw payload text. */
|
|
20
|
+
data: string;
|
|
21
|
+
/** `id:` field, when the server sent one. */
|
|
22
|
+
id: string;
|
|
23
|
+
/** `retry:` hint in milliseconds, when the server sent one. */
|
|
24
|
+
retry: number | undefined;
|
|
25
|
+
}
|
|
26
|
+
/** Options accepted by `@Sse(path, options)`. */
|
|
27
|
+
export interface SnailSseOptions {
|
|
28
|
+
/** Request method. Defaults to `"GET"`. */
|
|
29
|
+
method?: "GET" | "POST";
|
|
30
|
+
/** Send cookies and auth headers cross-site. */
|
|
31
|
+
withCredentials?: boolean;
|
|
32
|
+
/** Extra request headers. */
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
/** Static request body, useful with `method: "POST"`. */
|
|
35
|
+
data?: unknown;
|
|
36
|
+
/** Auto-reconnect policy, or `false` to disable reconnecting. */
|
|
37
|
+
reconnect?: false | SnailReconnectPolicy;
|
|
38
|
+
}
|
|
39
|
+
/** Options accepted by `@WebSocket(path, options)`. */
|
|
40
|
+
export interface SnailWsOptions {
|
|
41
|
+
/** Sub-protocols passed to the `WebSocket` constructor. */
|
|
42
|
+
protocols?: string | string[];
|
|
43
|
+
/** Auto-reconnect policy, or `false` to disable reconnecting. */
|
|
44
|
+
reconnect?: false | SnailReconnectPolicy;
|
|
45
|
+
/**
|
|
46
|
+
* Serialiser used by `send()`.
|
|
47
|
+
* - `"json"` (default) → `JSON.stringify`
|
|
48
|
+
* - `"text"` → `String(value)`
|
|
49
|
+
* - a custom pair of functions
|
|
50
|
+
*/
|
|
51
|
+
serializer?: "json" | "text" | {
|
|
52
|
+
serialize?: (value: unknown) => string | ArrayBufferLike | Blob | ArrayBufferView;
|
|
53
|
+
deserialize?: (raw: string) => unknown;
|
|
54
|
+
};
|
|
55
|
+
/** Queue messages sent while the socket is still connecting. Defaults to `true`. */
|
|
56
|
+
queueWhileConnecting?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** Options accepted by `@HttpStream(path, options)`. */
|
|
59
|
+
export interface SnailHttpStreamOptions {
|
|
60
|
+
/** Request method. Defaults to `"POST"`. */
|
|
61
|
+
method?: import("./api.js").SnailMethodType;
|
|
62
|
+
/** Request headers, typically `{ accept: "text/event-stream" }`. */
|
|
63
|
+
headers?: Record<string, string>;
|
|
64
|
+
/** Decode each chunk as UTF-8 text rather than raw bytes. Defaults to `true`. */
|
|
65
|
+
decodeText?: boolean;
|
|
66
|
+
/** Split the stream into lines instead of raw chunks. Defaults to `false`. */
|
|
67
|
+
lineDelimited?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A live connection returned by `open()`.
|
|
71
|
+
*
|
|
72
|
+
* `Symbol.asyncDispose` is implemented so a connection can be driven with
|
|
73
|
+
* `await using` in runtimes that support explicit resource management.
|
|
74
|
+
*/
|
|
75
|
+
export interface SnailConnection {
|
|
76
|
+
/** Close the connection and release its resources. */
|
|
77
|
+
close(): void;
|
|
78
|
+
/** `true` while the transport is connected. */
|
|
79
|
+
connected: boolean;
|
|
80
|
+
/** Resolves once the connection is established. */
|
|
81
|
+
readonly opened: Promise<void>;
|
|
82
|
+
/** Resolves once the connection is closed, for any reason. */
|
|
83
|
+
readonly closed: Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Release the connection with `using` / `await using`.
|
|
86
|
+
*
|
|
87
|
+
* Both are attached at runtime whenever the running engine provides the well
|
|
88
|
+
* known symbols, and simply absent otherwise — so `close()` remains the one
|
|
89
|
+
* portable way to release a connection.
|
|
90
|
+
*/
|
|
91
|
+
[Symbol.dispose]?(): void;
|
|
92
|
+
[Symbol.asyncDispose]?(): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A WebSocket connection.
|
|
96
|
+
*
|
|
97
|
+
* `send` while the socket is still connecting queues the message (unless
|
|
98
|
+
* `queueWhileConnecting: false`), because a caller that just called `open()`
|
|
99
|
+
* should not have to race the handshake.
|
|
100
|
+
*/
|
|
101
|
+
export interface SnailSocketConnection extends SnailConnection {
|
|
102
|
+
/** Send a value, serialised according to the `serializer` option. */
|
|
103
|
+
send(data: unknown): void;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A streaming HTTP response.
|
|
107
|
+
*
|
|
108
|
+
* The connection is itself async-iterable, so it can be consumed directly:
|
|
109
|
+
*
|
|
110
|
+
* ```ts
|
|
111
|
+
* const stream = aiApi.chat(payload);
|
|
112
|
+
* for await (const chunk of stream) process(chunk);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export interface SnailHttpStreamConnection extends SnailConnection {
|
|
116
|
+
/** Iterate the decoded chunks. */
|
|
117
|
+
[Symbol.asyncIterator](): AsyncIterator<string>;
|
|
118
|
+
/** Buffer the whole stream into a single string. */
|
|
119
|
+
text(): Promise<string>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A Server-Sent Events connection.
|
|
123
|
+
*
|
|
124
|
+
* Carries a message surface of its own, on top of the shared connection handle.
|
|
125
|
+
* Without it the parsed events would only ever reach the decorated class's
|
|
126
|
+
* `@SseEvent()` handlers, so a hook like `useSSE` — which needs to observe the
|
|
127
|
+
* stream itself — would have nothing to subscribe to.
|
|
128
|
+
*/
|
|
129
|
+
export interface SnailSseConnection extends SnailConnection {
|
|
130
|
+
/** Subscribe to every decoded event, whatever its name. Returns an unsubscribe. */
|
|
131
|
+
onMessage(listener: (message: SnailSseMessage) => void): () => void;
|
|
132
|
+
/** Subscribe to one named event. Returns an unsubscribe function. */
|
|
133
|
+
on(event: string, listener: (message: SnailSseMessage) => void): () => void;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A Server-Sent Events endpoint created by `Service.createSse(EventStream)`.
|
|
137
|
+
*
|
|
138
|
+
* Nothing connects until `open()` is called, and every call to `open()` creates
|
|
139
|
+
* an independent connection with its own reconnect loop.
|
|
140
|
+
*/
|
|
141
|
+
export interface SnailSseEndpoint {
|
|
142
|
+
/** Open a connection and return its handle. */
|
|
143
|
+
open(): SnailSseConnection;
|
|
144
|
+
}
|
|
145
|
+
/** A WebSocket endpoint created by `Service.createWebSocket(ChatSocket)`. */
|
|
146
|
+
export interface SnailWsEndpoint {
|
|
147
|
+
/** Open a connection and return its handle. */
|
|
148
|
+
open(): SnailSocketConnection;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/typings/stream.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAE9D,4DAA4D;AAC5D,MAAM,WAAW,oBAAoB;IACnC,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,qCAAqC;AACrC,MAAM,WAAW,eAAe;IAC9B,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,+DAA+D;IAC/D,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;AAED,iDAAiD;AACjD,MAAM,WAAW,eAAe;IAC9B,2CAA2C;IAC3C,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAA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