@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
package/README_EN.md
DELETED
|
@@ -1,607 +0,0 @@
|
|
|
1
|
-
<p>
|
|
2
|
-
<img src="https://img.shields.io/badge/TypeScript-1e80ff"></img>
|
|
3
|
-
<img src="https://img.shields.io/npm/v/axios?label=axios&labelColor=1e80ff&color=67C23A"></img>
|
|
4
|
-
<img src="https://img.shields.io/npm/v/reflect-metadata?label=reflect-metadata&labelColor=1e80ff&color=67C23A"></img>
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
<a href='./README.md'>中文文档</a>|English Document
|
|
8
|
-
|
|
9
|
-
## Project Introduction
|
|
10
|
-
|
|
11
|
-
- Secondary encapsulation based on Axios
|
|
12
|
-
- Use `reflect-metadata` to create and process metadata
|
|
13
|
-
- Provide decorators to define request methods, supporting all HTTP methods and SSE
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
`npm install @snail-js/api`
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
1. Enable TypeScript decorator configuration:
|
|
22
|
-
|
|
23
|
-
```json
|
|
24
|
-
// tsconfig.json
|
|
25
|
-
{
|
|
26
|
-
"module": "ESNext",
|
|
27
|
-
// Module resolution strategy
|
|
28
|
-
"moduleResolution": "node",
|
|
29
|
-
"baseUrl": ".",
|
|
30
|
-
// Target must be higher than ES6
|
|
31
|
-
"target": "ESNext",
|
|
32
|
-
// lib should include ES versions above ES6
|
|
33
|
-
"lib": ["ESNext", "DOM"],
|
|
34
|
-
// Include reflect-metadata types
|
|
35
|
-
"types": ["reflect-metadata"],
|
|
36
|
-
"emitDecoratorMetadata": true,
|
|
37
|
-
"experimentalDecorators": true,
|
|
38
|
-
|
|
39
|
-
"skipLibCheck": true,
|
|
40
|
-
"strictNullChecks": false
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
2. Create Snail backend configuration instance:
|
|
45
|
-
|
|
46
|
-
```ts
|
|
47
|
-
// service.ts
|
|
48
|
-
import { SnailServer, Server } from "@snail-js/api";
|
|
49
|
-
|
|
50
|
-
@Server({
|
|
51
|
-
baseURL: "/api",
|
|
52
|
-
timeout: 5000,
|
|
53
|
-
})
|
|
54
|
-
class BackEnd extends SnailServer {}
|
|
55
|
-
|
|
56
|
-
export const Service = new BackEnd();
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
3. Create API instance:
|
|
60
|
-
|
|
61
|
-
```ts
|
|
62
|
-
// user.ts
|
|
63
|
-
import { Api, Get, Post, Query, Data, SnailApi } from "@snail-js/api";
|
|
64
|
-
import { Service } from "./service";
|
|
65
|
-
|
|
66
|
-
@Api("user")
|
|
67
|
-
class UserApi extends SnailApi {
|
|
68
|
-
@Get()
|
|
69
|
-
get(@Query("id") id: string) {}
|
|
70
|
-
|
|
71
|
-
@Post()
|
|
72
|
-
create(@Data() user: User) {}
|
|
73
|
-
}
|
|
74
|
-
// Create and export API
|
|
75
|
-
export const userApi = Service.createApi(UserApi);
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
4. Send requests:
|
|
79
|
-
|
|
80
|
-
```ts
|
|
81
|
-
import { userApi } from "./user";
|
|
82
|
-
|
|
83
|
-
const { send:getUser, onSuccess, onError, onHitCache } = await userApi.get();
|
|
84
|
-
|
|
85
|
-
const data = await getUser("1");
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## `SnailMethod` Instance
|
|
89
|
-
|
|
90
|
-
- When calling `Service.createApi(ApiInstance)`, creates a proxy for methods decorated with `RequestMethod` (e.g. @Get, @Post)
|
|
91
|
-
- Returns a function containing request parameters, which when called returns a `SnailMethod` instance
|
|
92
|
-
|
|
93
|
-
### `SnailMethod` Methods
|
|
94
|
-
|
|
95
|
-
- `send`: Send request
|
|
96
|
-
_Async function that executes the current request_
|
|
97
|
-
- `onSuccess`: Request success callback
|
|
98
|
-
_Register success event handler_
|
|
99
|
-
- `onError`: Request failure callback
|
|
100
|
-
_Register error event handler_
|
|
101
|
-
- `onHitCache`: Cache hit callback
|
|
102
|
-
_Register cache hit event handler_
|
|
103
|
-
- `onFinish`: Request completion callback
|
|
104
|
-
_Register completion event handler (fires on both success/error)_
|
|
105
|
-
- `registerStrategies` Register Strategies
|
|
106
|
-
_Register Strategies of this method instance_
|
|
107
|
-
|
|
108
|
-
### `SnailMethod` Properties
|
|
109
|
-
- `response`: AxiosResponse - Raw response object
|
|
110
|
-
- `request`: AxiosRequestConfig - Final processed request after applying Versioning and Strategies
|
|
111
|
-
- `version`: string - Effective request version (undefined if Versioning disabled)
|
|
112
|
-
- `name`: string - Full method identifier in `ServerName.ApiName.MethodName` format
|
|
113
|
-
- `error`: Error | null - Error object if request failed, null otherwise
|
|
114
|
-
|
|
115
|
-
### Server Configuration
|
|
116
|
-
|
|
117
|
-
<table>
|
|
118
|
-
<tr>
|
|
119
|
-
<th>Option</th>
|
|
120
|
-
<th>Type</th>
|
|
121
|
-
<th>Required</th>
|
|
122
|
-
<th>Default Value</th>
|
|
123
|
-
<th>Description</th>
|
|
124
|
-
</tr>
|
|
125
|
-
<tr>
|
|
126
|
-
<td>name</td>
|
|
127
|
-
<td>string</td>
|
|
128
|
-
<td>No</td>
|
|
129
|
-
<td>Class name inheriting SnailServer</td>
|
|
130
|
-
<td>Unique server identifier</td>
|
|
131
|
-
</tr>
|
|
132
|
-
<tr>
|
|
133
|
-
<td>baseUrl</td>
|
|
134
|
-
<td>string</td>
|
|
135
|
-
<td>No</td>
|
|
136
|
-
<td>'\'</td>
|
|
137
|
-
<td>API prefix (same as axios baseURL)</td>
|
|
138
|
-
</tr>
|
|
139
|
-
<tr>
|
|
140
|
-
<td>Versioning</td>
|
|
141
|
-
<td><a href="#versioningoption">VersioningOption</a></td>
|
|
142
|
-
<td>No</td>
|
|
143
|
-
<td>undefine</td>
|
|
144
|
-
<td>Versioning configuration</td>
|
|
145
|
-
</tr>
|
|
146
|
-
<tr>
|
|
147
|
-
<td>timeout</td>
|
|
148
|
-
<td>number</td>
|
|
149
|
-
<td>No</td>
|
|
150
|
-
<td>5000</td>
|
|
151
|
-
<td>Global timeout (ms)</td>
|
|
152
|
-
</tr>
|
|
153
|
-
<tr>
|
|
154
|
-
<td>cacheManage</td>
|
|
155
|
-
<td>{type:CacheType,ttl:number}</td>
|
|
156
|
-
<td>No</td>
|
|
157
|
-
<td>{
|
|
158
|
-
type: CacheType.Memory,
|
|
159
|
-
ttl: 500
|
|
160
|
-
}</td>
|
|
161
|
-
<td>Cache manager (ttl in seconds)</td>
|
|
162
|
-
</tr>
|
|
163
|
-
<tr>
|
|
164
|
-
<td>cacheFor</td>
|
|
165
|
-
<td>RequestMethod | RequestMethod[] | 'All' | 'all' </td>
|
|
166
|
-
<td>No</td>
|
|
167
|
-
<td>Get</td>
|
|
168
|
-
<td>Methods to enable caching</td>
|
|
169
|
-
</tr>
|
|
170
|
-
<tr>
|
|
171
|
-
<td>serverStatusCodeRule</td>
|
|
172
|
-
<td><a href="#SnailServerStatusCodeRuleOptions">SnailServerStatusCodeRuleOptions</a></td>
|
|
173
|
-
<td>否</td>
|
|
174
|
-
<td>undefined</td>
|
|
175
|
-
<td>Server status code validation rules (triggers error when rule function returns false)</td>
|
|
176
|
-
</tr>
|
|
177
|
-
<tr>
|
|
178
|
-
<td>enableLog</td>
|
|
179
|
-
<td>boolean</td>
|
|
180
|
-
<td>No</td>
|
|
181
|
-
<td>false</td>
|
|
182
|
-
<td>Enable debug logs</td>
|
|
183
|
-
</tr>
|
|
184
|
-
</table>
|
|
185
|
-
|
|
186
|
-
### API Configuration
|
|
187
|
-
- Decorate API classes with `@Api()` and extend `SnailApi`
|
|
188
|
-
|
|
189
|
-
<table>
|
|
190
|
-
<tr>
|
|
191
|
-
<th>Option</th>
|
|
192
|
-
<th>Type</th>
|
|
193
|
-
<th>Required</th>
|
|
194
|
-
<th>Default Value</th>
|
|
195
|
-
<th>Description</th>
|
|
196
|
-
</tr>
|
|
197
|
-
<tr>
|
|
198
|
-
<td>name</td>
|
|
199
|
-
<td>string</td>
|
|
200
|
-
<td>No</td>
|
|
201
|
-
<td>default use extends`SnailApi` class name</td>
|
|
202
|
-
<td>Unique API identifier</td>
|
|
203
|
-
</tr>
|
|
204
|
-
<tr>
|
|
205
|
-
<td>timeout</td>
|
|
206
|
-
<td>number</td>
|
|
207
|
-
<td>No</td>
|
|
208
|
-
<td></td>
|
|
209
|
-
<td>Overrides server timeout</td>
|
|
210
|
-
</tr>
|
|
211
|
-
<tr>
|
|
212
|
-
<td>version</td>
|
|
213
|
-
<td>string</td>
|
|
214
|
-
<td>No</td>
|
|
215
|
-
<td></td>
|
|
216
|
-
<td>Overrides server defaultVersion</td>
|
|
217
|
-
</tr>
|
|
218
|
-
</table>
|
|
219
|
-
|
|
220
|
-
## Request Method Decorators
|
|
221
|
-
- Used in API classes to mark request methods
|
|
222
|
-
- Supports all axios methods: Get, Post, Head, Put, Delete, Patch, Options
|
|
223
|
-
- Parameter: path?: string - Endpoint path (combined with baseURL)
|
|
224
|
-
|
|
225
|
-
## Parameter Decorators
|
|
226
|
-
### Query Parameters @Query
|
|
227
|
-
- @Query(key?:string)
|
|
228
|
-
Example:
|
|
229
|
-
|
|
230
|
-
```ts
|
|
231
|
-
@Api("user")
|
|
232
|
-
class UserApi {
|
|
233
|
-
@Get()
|
|
234
|
-
get(@Query("id") id: string, @Query("sign") sign: string) {}
|
|
235
|
-
}
|
|
236
|
-
```
|
|
237
|
-
> Parameters will be appended as ?k1=v1&k2=v2
|
|
238
|
-
|
|
239
|
-
### Route Parameters @Params
|
|
240
|
-
- @Params(key?:string)
|
|
241
|
-
Example with object:
|
|
242
|
-
```ts
|
|
243
|
-
class RouteParams {
|
|
244
|
-
id: string;
|
|
245
|
-
sign: string;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
@Api("user/:id/:sign")
|
|
249
|
-
class UserApi {
|
|
250
|
-
@Get()
|
|
251
|
-
get(@Params() params: RouteParams) {}
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
> Automatically maps object properties to route parameters
|
|
256
|
-
|
|
257
|
-
### Request Data
|
|
258
|
-
|
|
259
|
-
- `@Data(key?:string)`
|
|
260
|
-
- Usage pattern same as `@Params`, supports mixed usage
|
|
261
|
-
|
|
262
|
-
## Strategy Decorator `@UseStrategy`
|
|
263
|
-
|
|
264
|
-
- `@UseStrategy(...Strategy[])`
|
|
265
|
-
|
|
266
|
-
### Request Strategy
|
|
267
|
-
|
|
268
|
-
- Executed before request sending, subsequent strategy results override previous ones
|
|
269
|
-
- If returns processed request, uses it for sending; otherwise uses original or previous strategy's result
|
|
270
|
-
|
|
271
|
-
```typescript
|
|
272
|
-
class CustomStrategy extends Strategy {
|
|
273
|
-
applyRequest(request: AxiosRequestConfig) {
|
|
274
|
-
request.headers["Access-Token"] = "abcde";
|
|
275
|
-
return request;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Applied to Snail for global request strategies
|
|
280
|
-
@Server({
|
|
281
|
-
baseURL: "/api",
|
|
282
|
-
timeout: 5000,
|
|
283
|
-
})
|
|
284
|
-
@UseStrategy(CustomStrategy)
|
|
285
|
-
class BackEnd extends Snail<ShanheResponse> {}
|
|
286
|
-
export const Service = new BackEnd();
|
|
287
|
-
// Register strategy after instance creation
|
|
288
|
-
Service.registerStrategies(CustomStrategy);
|
|
289
|
-
|
|
290
|
-
// Applied to API for method-specific strategies
|
|
291
|
-
@Api("test")
|
|
292
|
-
@UseStrategy(CustomStrategy)
|
|
293
|
-
class Test {}
|
|
294
|
-
const TestApi = Service.createApi(Test);
|
|
295
|
-
TestApi.registerStrategies(CustomStrategy);
|
|
296
|
-
|
|
297
|
-
// Applied to method for endpoint-level strategies
|
|
298
|
-
@Api("test")
|
|
299
|
-
@UseStrategy(CustomStrategy)
|
|
300
|
-
class Test {
|
|
301
|
-
@Get()
|
|
302
|
-
@UseStrategy(CustomStrategy)
|
|
303
|
-
get() {}
|
|
304
|
-
}
|
|
305
|
-
// Register strategy before request
|
|
306
|
-
const TestApi = Service.createApi(Test);
|
|
307
|
-
const getSomething = TestApi.get();
|
|
308
|
-
{ send, registerStrategies } = getSomething;
|
|
309
|
-
registerStrategies(CustomStrategy);
|
|
310
|
-
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
### Response Strategy
|
|
314
|
-
- Executed after receiving server response
|
|
315
|
-
- Processed response propagates through strategy chain
|
|
316
|
-
|
|
317
|
-
```typescript
|
|
318
|
-
class CustomStrategy extends Strategy {
|
|
319
|
-
applyResponse(response: AxiosResponse) {
|
|
320
|
-
const { status } = response;
|
|
321
|
-
if (status == 200) {
|
|
322
|
-
// Custom processing
|
|
323
|
-
}
|
|
324
|
-
return response;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
## Version Management Decorators @Versioning & @Version
|
|
330
|
-
### Version Manager @Versioning(VersioningOption)
|
|
331
|
-
- Global version management
|
|
332
|
-
|
|
333
|
-
```typescript
|
|
334
|
-
@Server({
|
|
335
|
-
baseURL: "/api",
|
|
336
|
-
timeout: 5000,
|
|
337
|
-
})
|
|
338
|
-
@Versioning({
|
|
339
|
-
type: VersioningType.Header,
|
|
340
|
-
defaultVersion: "0.1.0",
|
|
341
|
-
})
|
|
342
|
-
class BackEnd extends Snail<ShanheResponse> {}
|
|
343
|
-
|
|
344
|
-
export const Service = new BackEnd();
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
### <a id='versioningOption'>VersioningOption Type</a>
|
|
348
|
-
|
|
349
|
-
```typescript
|
|
350
|
-
export enum VersioningType {
|
|
351
|
-
Uri,
|
|
352
|
-
Header,
|
|
353
|
-
Query,
|
|
354
|
-
Custom,
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
interface VersioningCommonOption {
|
|
358
|
-
defaultVersion: string;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
export interface VersioningUriOption extends VersioningCommonOption {
|
|
362
|
-
type: VersioningType.Uri;
|
|
363
|
-
prefix?: string;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
export interface VersioningHeaderOption extends VersioningCommonOption {
|
|
367
|
-
type: VersioningType.Header;
|
|
368
|
-
header?: string;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export interface VersioningQueryOption extends VersioningCommonOption {
|
|
372
|
-
type: VersioningType.Query;
|
|
373
|
-
key?: string;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
export interface VersioningCustomOption extends VersioningCommonOption {
|
|
377
|
-
type: VersioningType.Custom;
|
|
378
|
-
extractor: (requestOptions: unknown) => {
|
|
379
|
-
url: string;
|
|
380
|
-
headers: Record<string, any>;
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
export type VersioningOption =
|
|
385
|
-
| VersioningUriOption
|
|
386
|
-
| VersioningHeaderOption
|
|
387
|
-
| VersioningQueryOption
|
|
388
|
-
| VersioningCustomOption;
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
### <a id="SnailServerStatusCodeRuleOptions">SnailServerStatusCodeRuleOptions</a> Type
|
|
392
|
-
|
|
393
|
-
```typescript
|
|
394
|
-
export class SnailServerStatusCodeRuleOptions {
|
|
395
|
-
// Defines validation rules for server status codes
|
|
396
|
-
// Triggers error when rule function returns false
|
|
397
|
-
rule: (statusCode: number) => boolean;
|
|
398
|
-
// Specifies the key in response.data for status code (default: 'code')
|
|
399
|
-
key?: string;
|
|
400
|
-
}
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
### Temporary Version Modifier @Version
|
|
404
|
-
- Override version for specific methods
|
|
405
|
-
```typescript
|
|
406
|
-
@Api("test")
|
|
407
|
-
class Test {
|
|
408
|
-
@Get("HelloWorld")
|
|
409
|
-
@Version("0.2.0")
|
|
410
|
-
test() {}
|
|
411
|
-
}
|
|
412
|
-
```
|
|
413
|
-
|
|
414
|
-
> Enables temporary version override for testing
|
|
415
|
-
|
|
416
|
-
### Cache Decorator @HitSource
|
|
417
|
-
- @HitSource(name:string)
|
|
418
|
-
- Defines cache invalidation sources
|
|
419
|
-
- Name format: serverName:apiName:methodName
|
|
420
|
-
> Note: Use configured names if available, otherwise class names
|
|
421
|
-
|
|
422
|
-
```typescript
|
|
423
|
-
@Api("test",{name:'api1'})
|
|
424
|
-
@HitSource("api1")
|
|
425
|
-
class Test {
|
|
426
|
-
@Get("HelloWorld")
|
|
427
|
-
@HitSource("api1.test2")
|
|
428
|
-
test1() {}
|
|
429
|
-
|
|
430
|
-
@Post()
|
|
431
|
-
test2() {}
|
|
432
|
-
|
|
433
|
-
@Get()
|
|
434
|
-
// Invalidates cache for all Test class methods
|
|
435
|
-
@HitSource("api1")
|
|
436
|
-
test3() {}
|
|
437
|
-
}
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
> Successful [Post]test calls invalidate [Get]test/HelloWorld cache Default caching only for GET methods. Use @Server({cacheFor:'all'}) for other methods
|
|
441
|
-
|
|
442
|
-
> When `test3` method request succeeds, it won't be cached
|
|
443
|
-
|
|
444
|
-
> Note: To enable caching, configure `@Server({cacheManage})` cache manager
|
|
445
|
-
|
|
446
|
-
### Upload Progress Decorator `@UploadProgress`
|
|
447
|
-
|
|
448
|
-
- `@UploadProgress((progressEvent: AxiosProgressEvent) => void)`
|
|
449
|
-
|
|
450
|
-
### Download Progress Decorator `@DownloadProgress`
|
|
451
|
-
|
|
452
|
-
- `@DownloadProgress((progressEvent: AxiosProgressEvent) => void)`
|
|
453
|
-
|
|
454
|
-
## Server-Sent Events (SSE)
|
|
455
|
-
|
|
456
|
-
### Create SSE Endpoint
|
|
457
|
-
|
|
458
|
-
```typescript
|
|
459
|
-
@Sse("sse")
|
|
460
|
-
class ServerSend extends SnailSse {
|
|
461
|
-
|
|
462
|
-
@OnSseOpen()
|
|
463
|
-
handleOpen(event: Event) {
|
|
464
|
-
console.log("SSE connection opened:", event);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
@OnSseError()
|
|
468
|
-
handleError(event: Event) {
|
|
469
|
-
console.log("SSE error occurred:", event);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// Handle default message events
|
|
473
|
-
@SseEvent()
|
|
474
|
-
handleEvent(event: MessageEvent) {
|
|
475
|
-
console.log("SSE message event:", event.data);
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
// Handle custom named events
|
|
479
|
-
@SseEvent("chunk")
|
|
480
|
-
handleChunkEvent(event: Event) {
|
|
481
|
-
console.log("SSE chunk event:", event);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
export const Sse = Service.createSse(ServerSend);
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
### SSE Decorator @Sse
|
|
489
|
-
- @Sse(path: string, options?: { withCredentials?: boolean, version?: string })
|
|
490
|
-
- Creates a server-sent events connection, returns a function to open SSE connection:
|
|
491
|
-
- Returns { eventSource: EventSource, close: () => void } when called:
|
|
492
|
-
- eventSource: SSE connection instance
|
|
493
|
-
- close: Method to close the connection
|
|
494
|
-
### SSE Open Handler Decorator @OnSseOpen
|
|
495
|
-
- Registers decorated method as onopen handler for EventSource instances created by @Sse decorated methods
|
|
496
|
-
### SSE Error Handler Decorator @OnSseError
|
|
497
|
-
- Registers decorated method as onerror handler for EventSource instances created by @Sse decorated methods
|
|
498
|
-
### SSE Event Handler Decorator @SseEvent
|
|
499
|
-
- @SseEvent(eventName?: string)
|
|
500
|
-
- Without eventName : Registers as default message event handler
|
|
501
|
-
- With eventName : Registers as handler for specified custom event
|
|
502
|
-
|
|
503
|
-
------
|
|
504
|
-
|
|
505
|
-
## TypeScript Support
|
|
506
|
-
### Default Response Type
|
|
507
|
-
|
|
508
|
-
```typescript
|
|
509
|
-
export type StandardResponseData<
|
|
510
|
-
T extends ResponseJsonData = Record<string, any>
|
|
511
|
-
> = {
|
|
512
|
-
code: number;
|
|
513
|
-
message: string;
|
|
514
|
-
data: T;
|
|
515
|
-
};
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
### Custom Response Types
|
|
519
|
-
1. Define backend response format:
|
|
520
|
-
```typescript
|
|
521
|
-
export class CustomResponse {
|
|
522
|
-
status_code: number;
|
|
523
|
-
msg: string;
|
|
524
|
-
}
|
|
525
|
-
```
|
|
526
|
-
2. Apply type when creating service:
|
|
527
|
-
```typescript
|
|
528
|
-
// service.ts
|
|
529
|
-
import { SnailServer, Server } from "@snail-js/api";
|
|
530
|
-
|
|
531
|
-
@Server({
|
|
532
|
-
baseURL: "/api",
|
|
533
|
-
timeout: 5000,
|
|
534
|
-
})
|
|
535
|
-
class BackEnd extends SnailServer<CustomResponse> {}
|
|
536
|
-
|
|
537
|
-
export const Service = new BackEnd();
|
|
538
|
-
```
|
|
539
|
-
|
|
540
|
-
3. Type annotation when calling APIs:
|
|
541
|
-
```typescript
|
|
542
|
-
import { userApi } from "./user";
|
|
543
|
-
|
|
544
|
-
class User {
|
|
545
|
-
id: number;
|
|
546
|
-
name: string;
|
|
547
|
-
tel: string;
|
|
548
|
-
age: number;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
const getUser = userApi.get<User>();
|
|
552
|
-
const { send } = getUser;
|
|
553
|
-
|
|
554
|
-
const res = await send("1");
|
|
555
|
-
|
|
556
|
-
// Default data key:
|
|
557
|
-
// res.data => CustomResponse & { data: User }
|
|
558
|
-
```
|
|
559
|
-
|
|
560
|
-
> API response format:
|
|
561
|
-
```typescript
|
|
562
|
-
const getUser = userApi.get<User>();
|
|
563
|
-
const { send } = getUser;
|
|
564
|
-
const res = await send("1");
|
|
565
|
-
|
|
566
|
-
// res.data => CustomResponse & { data: User }
|
|
567
|
-
|
|
568
|
-
const getUser = userApi.get<Blob>();
|
|
569
|
-
const { send } = getUser;
|
|
570
|
-
const res = await send("1");
|
|
571
|
-
// res => AxiosResponse<Blob>
|
|
572
|
-
```
|
|
573
|
-
|
|
574
|
-
4. Custom data key configuration:
|
|
575
|
-
|
|
576
|
-
```typescript
|
|
577
|
-
@Server({
|
|
578
|
-
baseURL: "/api",
|
|
579
|
-
timeout: 5000,
|
|
580
|
-
})
|
|
581
|
-
class BackEnd extends Snail<CustomResponse, "record"> {}
|
|
582
|
-
|
|
583
|
-
const { send } = userApi.get<User>();
|
|
584
|
-
const res = await send("1");
|
|
585
|
-
// Custom data key:
|
|
586
|
-
// res.data => CustomResponse & { record: User }
|
|
587
|
-
```
|
|
588
|
-
|
|
589
|
-
### Non-JSON Responses
|
|
590
|
-
- For non-JSON content-type responses: send() returns AxiosResponse
|
|
591
|
-
- For JSON content-type responses: send() returns AxiosResponse.data
|
|
592
|
-
|
|
593
|
-
### Repository
|
|
594
|
-
<p>
|
|
595
|
-
<a href="https://gitee.com/limich/snail">
|
|
596
|
-
<img src="https://img.shields.io/badge/snail-js?style=flat&label=gitee&labelColor=F56C6C&link=https%3A%2F%2Fgitee.com%2Flimich%2Fsnail"></img>
|
|
597
|
-
</a>
|
|
598
|
-
</p>
|
|
599
|
-
<p>
|
|
600
|
-
<a href="https://github.com/limingchang/snail">
|
|
601
|
-
<img src="https://img.shields.io/badge/snail-js?style=flat&label=github&labelColor=F56C6C&link=https%3A%2F%2Fgihub.com%2Flimingchang%2Fsnail"></img>
|
|
602
|
-
</a>
|
|
603
|
-
</p>
|
|
604
|
-
|
|
605
|
-
### Author
|
|
606
|
-
|
|
607
|
-
- mc.lee
|
package/dist/cache/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import MemoryCache from "./memoryCache";
|
|
2
|
-
import LocalStorageCache from "./localstorageCache";
|
|
3
|
-
import IndexDBCache from "./indexDBCache";
|
|
4
|
-
import { CacheStorageAdapter, CacheStorage, MemoryCacheOption, IndexDBCacheOption, LocalStorageCacheOption, CustomCacheOption, CacheManagementOption } from "../typings";
|
|
5
|
-
export declare function createCache<T extends CacheManagementOption>(options: T): CacheStorage;
|
|
6
|
-
export declare function createCache<T extends MemoryCacheOption>(optios: T): MemoryCache;
|
|
7
|
-
export declare function createCache<T extends LocalStorageCacheOption>(optios: T): LocalStorageCache;
|
|
8
|
-
export declare function createCache<T extends IndexDBCacheOption>(optios: T): IndexDBCache;
|
|
9
|
-
export declare function createCache<T extends CustomCacheOption>(optios: T): CacheStorageAdapter;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { CacheGetData, CacheStorageAdapter } from "../typings";
|
|
2
|
-
export default class IndexDBCache implements CacheStorageAdapter {
|
|
3
|
-
ttl: number;
|
|
4
|
-
private db?;
|
|
5
|
-
constructor(ttl: number);
|
|
6
|
-
init(): Promise<void>;
|
|
7
|
-
private openDB;
|
|
8
|
-
get<T = any>(key: string): Promise<CacheGetData<T>>;
|
|
9
|
-
set<T = any>(key: string, value: T): Promise<boolean>;
|
|
10
|
-
delete(key: string): Promise<boolean>;
|
|
11
|
-
clear(): Promise<boolean>;
|
|
12
|
-
keys(): Promise<string[]>;
|
|
13
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { CacheGetData, CacheStorageAdapter } from "../typings";
|
|
2
|
-
export default class LocalStorageCache implements CacheStorageAdapter {
|
|
3
|
-
ttl: number;
|
|
4
|
-
constructor(ttl: number);
|
|
5
|
-
get<T = any>(key: string): Promise<CacheGetData<T>>;
|
|
6
|
-
set<T = any>(key: string, value: T): Promise<boolean>;
|
|
7
|
-
delete(key: string): Promise<boolean>;
|
|
8
|
-
clear(): Promise<boolean>;
|
|
9
|
-
keys(): Promise<string[]>;
|
|
10
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CacheGetData, CacheStorageAdapter } from "../typings";
|
|
2
|
-
export default class MemoryCache implements CacheStorageAdapter {
|
|
3
|
-
private CacheMap;
|
|
4
|
-
ttl: number;
|
|
5
|
-
constructor(ttl: number);
|
|
6
|
-
get<T = any>(key: string): Promise<CacheGetData<T>>;
|
|
7
|
-
set<T = any>(key: string, value: T): Promise<boolean>;
|
|
8
|
-
delete(key: string): Promise<boolean>;
|
|
9
|
-
clear(): Promise<boolean>;
|
|
10
|
-
keys(): Promise<string[]>;
|
|
11
|
-
}
|
package/dist/core/index.d.ts
DELETED
package/dist/core/snailApi.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Strategy, ApiInstanceOptions } from "../typings";
|
|
2
|
-
export declare class SnailApi {
|
|
3
|
-
private Name;
|
|
4
|
-
private serverInstance;
|
|
5
|
-
private Version?;
|
|
6
|
-
private Url?;
|
|
7
|
-
private Timeout?;
|
|
8
|
-
private EnableLog?;
|
|
9
|
-
constructor(options: ApiInstanceOptions);
|
|
10
|
-
private init;
|
|
11
|
-
private initStrategy;
|
|
12
|
-
registerStrategies: (...strategys: Array<new () => Strategy>) => void;
|
|
13
|
-
private initName;
|
|
14
|
-
private getApiConfig;
|
|
15
|
-
private isNoCache;
|
|
16
|
-
get version(): string | undefined;
|
|
17
|
-
get url(): string | undefined;
|
|
18
|
-
get name(): string;
|
|
19
|
-
get noCache(): boolean;
|
|
20
|
-
get enableLog(): boolean | undefined;
|
|
21
|
-
get timeout(): number | undefined;
|
|
22
|
-
}
|