acrylblends 1.0.5 → 1.0.6
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/docs/framework/agents/index.md +1 -1
- package/lib/{audit-D5z9uwOP.d.ts → audit-GcLtvNLV.d.ts} +4 -2
- package/lib/cordis/door.d.ts +90 -4
- package/lib/cordis/door.js +524 -13
- package/lib/door/host.d.ts +2 -2
- package/lib/door/host.js +1 -1
- package/lib/door/page.d.ts +3 -1
- package/lib/door/page.js +1 -1
- package/lib/door/protocol.d.ts +1 -1
- package/lib/{protocol-C37gPePD.d.ts → protocol-CR31M7K_.d.ts} +2 -0
- package/lib/{snapshot-text-Bbx43mN0.js → snapshot-text-CtQm3n8n.js} +14 -5
- package/package.json +1 -1
- package/plugins/acryl-door/src/cli/acryl.ts +36 -5
- package/plugins/acryl-door/src/host/channel.ts +14 -6
- package/plugins/acryl-door/src/host/door.ts +78 -10
- package/plugins/acryl-door/src/host/page-routes.ts +3 -1
- package/plugins/acryl-door/src/host/shell.ts +147 -0
- package/plugins/acryl-door/src/host/shim.ts +39 -3
- package/plugins/acryl-door/src/host/verbs.ts +39 -2
- package/plugins/acryl-door/src/index.ts +7 -1
- package/plugins/acryl-door/src/page/channel.ts +3 -1
- package/plugins/acryl-door/src/page/index.ts +2 -1
- package/plugins/acryl-door/src/page/protocol.ts +2 -0
- package/plugins/acryl-door/src/shell/protocol.ts +130 -0
- package/plugins/agent-panel/headless.ts +29 -8
- package/plugins/agent-panel/launch.ts +67 -0
- package/plugins/desktop/door-shell.ts +379 -0
- package/plugins/desktop/main.ts +66 -12
- package/templates/agent/AGENTS.md +2 -0
- package/plugins/acryl-router/src/connection.d.ts +0 -25
- package/plugins/acryl-router/src/core/app-base.d.ts +0 -215
- package/plugins/acryl-router/src/core/app.d.ts +0 -19
- package/plugins/acryl-router/src/core/client/client.d.ts +0 -4
- package/plugins/acryl-router/src/core/client/fetch-result-please.d.ts +0 -35
- package/plugins/acryl-router/src/core/client/index.d.ts +0 -7
- package/plugins/acryl-router/src/core/client/types.d.ts +0 -229
- package/plugins/acryl-router/src/core/client/utils.d.ts +0 -18
- package/plugins/acryl-router/src/core/compose.d.ts +0 -14
- package/plugins/acryl-router/src/core/context.d.ts +0 -443
- package/plugins/acryl-router/src/core/helper/accepts/accepts.d.ts +0 -30
- package/plugins/acryl-router/src/core/helper/accepts/index.d.ts +0 -5
- package/plugins/acryl-router/src/core/helper/conninfo/index.d.ts +0 -5
- package/plugins/acryl-router/src/core/helper/conninfo/types.d.ts +0 -36
- package/plugins/acryl-router/src/core/helper/cookie/index.d.ts +0 -25
- package/plugins/acryl-router/src/core/helper/css/common.d.ts +0 -59
- package/plugins/acryl-router/src/core/helper/css/index.d.ts +0 -80
- package/plugins/acryl-router/src/core/helper/dev/index.d.ts +0 -20
- package/plugins/acryl-router/src/core/helper/factory/index.d.ts +0 -82
- package/plugins/acryl-router/src/core/helper/html/index.d.ts +0 -8
- package/plugins/acryl-router/src/core/helper/proxy/index.d.ts +0 -73
- package/plugins/acryl-router/src/core/helper/route/index.d.ts +0 -75
- package/plugins/acryl-router/src/core/helper/ssg/index.d.ts +0 -7
- package/plugins/acryl-router/src/core/helper/ssg/middleware.d.ts +0 -44
- package/plugins/acryl-router/src/core/helper/ssg/plugins.d.ts +0 -27
- package/plugins/acryl-router/src/core/helper/ssg/ssg.d.ts +0 -91
- package/plugins/acryl-router/src/core/helper/ssg/utils.d.ts +0 -16
- package/plugins/acryl-router/src/core/helper/streaming/index.d.ts +0 -8
- package/plugins/acryl-router/src/core/helper/streaming/sse.d.ts +0 -13
- package/plugins/acryl-router/src/core/helper/streaming/stream.d.ts +0 -3
- package/plugins/acryl-router/src/core/helper/streaming/text.d.ts +0 -3
- package/plugins/acryl-router/src/core/helper/streaming/utils.d.ts +0 -1
- package/plugins/acryl-router/src/core/helper/testing/index.d.ts +0 -13
- package/plugins/acryl-router/src/core/helper/websocket/index.d.ts +0 -70
- package/plugins/acryl-router/src/core/http-exception.d.ts +0 -58
- package/plugins/acryl-router/src/core/index.d.ts +0 -37
- package/plugins/acryl-router/src/core/jsx/base.d.ts +0 -61
- package/plugins/acryl-router/src/core/jsx/children.d.ts +0 -9
- package/plugins/acryl-router/src/core/jsx/components.d.ts +0 -15
- package/plugins/acryl-router/src/core/jsx/constants.d.ts +0 -6
- package/plugins/acryl-router/src/core/jsx/context.d.ts +0 -51
- package/plugins/acryl-router/src/core/jsx/dom/components.d.ts +0 -10
- package/plugins/acryl-router/src/core/jsx/dom/context.d.ts +0 -3
- package/plugins/acryl-router/src/core/jsx/dom/css.d.ts +0 -83
- package/plugins/acryl-router/src/core/jsx/dom/hooks/index.d.ts +0 -39
- package/plugins/acryl-router/src/core/jsx/dom/intrinsic-element/components.d.ts +0 -16
- package/plugins/acryl-router/src/core/jsx/dom/jsx-dev-runtime.d.ts +0 -8
- package/plugins/acryl-router/src/core/jsx/dom/jsx-runtime.d.ts +0 -7
- package/plugins/acryl-router/src/core/jsx/dom/render.d.ts +0 -73
- package/plugins/acryl-router/src/core/jsx/dom/utils.d.ts +0 -1
- package/plugins/acryl-router/src/core/jsx/hooks/index.d.ts +0 -47
- package/plugins/acryl-router/src/core/jsx/index.d.ts +0 -76
- package/plugins/acryl-router/src/core/jsx/intrinsic-element/common.d.ts +0 -6
- package/plugins/acryl-router/src/core/jsx/intrinsic-element/components.d.ts +0 -13
- package/plugins/acryl-router/src/core/jsx/intrinsic-elements.d.ts +0 -735
- package/plugins/acryl-router/src/core/jsx/streaming.d.ts +0 -36
- package/plugins/acryl-router/src/core/jsx/types.d.ts +0 -36
- package/plugins/acryl-router/src/core/jsx/utils.d.ts +0 -4
- package/plugins/acryl-router/src/core/request/constants.d.ts +0 -1
- package/plugins/acryl-router/src/core/request.d.ts +0 -306
- package/plugins/acryl-router/src/core/router/reg-exp-router/index.d.ts +0 -6
- package/plugins/acryl-router/src/core/router/reg-exp-router/matcher.d.ts +0 -7
- package/plugins/acryl-router/src/core/router/reg-exp-router/node.d.ts +0 -13
- package/plugins/acryl-router/src/core/router/reg-exp-router/prepared-router.d.ts +0 -17
- package/plugins/acryl-router/src/core/router/reg-exp-router/router.d.ts +0 -11
- package/plugins/acryl-router/src/core/router/reg-exp-router/trie.d.ts +0 -8
- package/plugins/acryl-router/src/core/router/smart-router/index.d.ts +0 -5
- package/plugins/acryl-router/src/core/router/smart-router/router.d.ts +0 -11
- package/plugins/acryl-router/src/core/router/trie-router/index.d.ts +0 -5
- package/plugins/acryl-router/src/core/router/trie-router/node.d.ts +0 -6
- package/plugins/acryl-router/src/core/router/trie-router/router.d.ts +0 -7
- package/plugins/acryl-router/src/core/router/utils.d.ts +0 -1
- package/plugins/acryl-router/src/core/router.d.ts +0 -97
- package/plugins/acryl-router/src/core/types.d.ts +0 -573
- package/plugins/acryl-router/src/core/utils/accept.d.ts +0 -6
- package/plugins/acryl-router/src/core/utils/body.d.ts +0 -79
- package/plugins/acryl-router/src/core/utils/buffer.d.ts +0 -17
- package/plugins/acryl-router/src/core/utils/color.d.ts +0 -21
- package/plugins/acryl-router/src/core/utils/concurrent.d.ts +0 -11
- package/plugins/acryl-router/src/core/utils/constants.d.ts +0 -4
- package/plugins/acryl-router/src/core/utils/cookie.d.ts +0 -41
- package/plugins/acryl-router/src/core/utils/crypto.d.ts +0 -15
- package/plugins/acryl-router/src/core/utils/handler.d.ts +0 -6
- package/plugins/acryl-router/src/core/utils/headers.d.ts +0 -8
- package/plugins/acryl-router/src/core/utils/html.d.ts +0 -44
- package/plugins/acryl-router/src/core/utils/http-status.d.ts +0 -32
- package/plugins/acryl-router/src/core/utils/mime.d.ts +0 -70
- package/plugins/acryl-router/src/core/utils/stream.d.ts +0 -31
- package/plugins/acryl-router/src/core/utils/types.d.ts +0 -128
- package/plugins/acryl-router/src/core/utils/url.d.ts +0 -44
- package/plugins/acryl-router/src/core/validator/index.d.ts +0 -7
- package/plugins/acryl-router/src/core/validator/utils.d.ts +0 -29
- package/plugins/acryl-router/src/core/validator/validator.d.ts +0 -16
- package/plugins/acryl-router/src/helpers/index.d.ts +0 -17
- package/plugins/acryl-router/src/helpers/schema-validator.d.ts +0 -54
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module
|
|
3
|
-
* This module is the base module for the Acryl object.
|
|
4
|
-
*/
|
|
5
|
-
import { Context } from './context.ts';
|
|
6
|
-
import type { ExecutionContext } from './context.ts';
|
|
7
|
-
import type { Router } from './router.ts';
|
|
8
|
-
import type { Env, ErrorHandler, H, HandlerInterface, MergePath, MergeSchemaPath, MiddlewareHandlerInterface, NotFoundHandler, OnHandlerInterface, RouterRoute, Schema } from './types.ts';
|
|
9
|
-
type GetPath<E extends Env> = (request: Request, options?: {
|
|
10
|
-
env?: E['Bindings'];
|
|
11
|
-
}) => string;
|
|
12
|
-
export type AcrylOptions<E extends Env> = {
|
|
13
|
-
/**
|
|
14
|
-
* `router` option specifies which router to use.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const app = new Acryl({ router: new RegExpRouter() })
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
router?: Router<[H, RouterRoute]>;
|
|
23
|
-
} & ({
|
|
24
|
-
/**
|
|
25
|
-
* `strict` option specifies whether to distinguish whether the last path is a directory or not.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @default true
|
|
29
|
-
*/
|
|
30
|
-
strict?: true;
|
|
31
|
-
/**
|
|
32
|
-
* `getPath` can handle the host header value.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const app = new Acryl({
|
|
38
|
-
* getPath: (req) =>
|
|
39
|
-
* '/' + req.headers.get('host') + req.url.replace(/^https?:\/\/[^/]+(\/[^?]*)/, '$1'),
|
|
40
|
-
* })
|
|
41
|
-
*
|
|
42
|
-
* app.get('/www1.example.com/hello', () => c.text('hello www1'))
|
|
43
|
-
*
|
|
44
|
-
* // A following request will match the route:
|
|
45
|
-
* // new Request('http://www1.example.com/hello', {
|
|
46
|
-
* // headers: { host: 'www1.example.com' },
|
|
47
|
-
* // })
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
getPath?: GetPath<E>;
|
|
51
|
-
} | {
|
|
52
|
-
/**
|
|
53
|
-
* `strict` option specifies whether to distinguish whether the last path is a directory or not.
|
|
54
|
-
* When `strict` is `false`, `getPath` is not used.
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* @default true
|
|
58
|
-
*/
|
|
59
|
-
strict: false;
|
|
60
|
-
getPath?: never;
|
|
61
|
-
});
|
|
62
|
-
type MountOptionHandler = (c: Context) => unknown;
|
|
63
|
-
type MountReplaceRequest = (originalRequest: Request) => Request;
|
|
64
|
-
type MountOptions = MountOptionHandler | {
|
|
65
|
-
optionHandler?: MountOptionHandler;
|
|
66
|
-
replaceRequest?: MountReplaceRequest | false;
|
|
67
|
-
};
|
|
68
|
-
declare class Acryl<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/', CurrentPath extends string = BasePath> {
|
|
69
|
-
#private;
|
|
70
|
-
get: HandlerInterface<E, 'get', S, BasePath, CurrentPath>;
|
|
71
|
-
post: HandlerInterface<E, 'post', S, BasePath, CurrentPath>;
|
|
72
|
-
put: HandlerInterface<E, 'put', S, BasePath, CurrentPath>;
|
|
73
|
-
delete: HandlerInterface<E, 'delete', S, BasePath, CurrentPath>;
|
|
74
|
-
options: HandlerInterface<E, 'options', S, BasePath, CurrentPath>;
|
|
75
|
-
patch: HandlerInterface<E, 'patch', S, BasePath, CurrentPath>;
|
|
76
|
-
query: HandlerInterface<E, 'query', S, BasePath, CurrentPath>;
|
|
77
|
-
all: HandlerInterface<E, 'all', S, BasePath, CurrentPath>;
|
|
78
|
-
on: OnHandlerInterface<E, S, BasePath>;
|
|
79
|
-
use: MiddlewareHandlerInterface<E, S, BasePath>;
|
|
80
|
-
router: Router<[H, RouterRoute]>;
|
|
81
|
-
readonly getPath: GetPath<E>;
|
|
82
|
-
private _basePath;
|
|
83
|
-
routes: RouterRoute[];
|
|
84
|
-
constructor(options?: AcrylOptions<E>);
|
|
85
|
-
private errorHandler;
|
|
86
|
-
/**
|
|
87
|
-
* `.route()` allows grouping other Acryl instance in routes.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* @param {string} path - base Path
|
|
91
|
-
* @param {Acryl} app - other Acryl instance
|
|
92
|
-
* @returns {Acryl} routed Acryl instance
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```ts
|
|
96
|
-
* const app = new Acryl()
|
|
97
|
-
* const app2 = new Acryl()
|
|
98
|
-
*
|
|
99
|
-
* app2.get("/user", (c) => c.text("user"))
|
|
100
|
-
* app.route("/api", app2) // GET /api/user
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string, SubCurrentPath extends string>(path: SubPath, app: Acryl<SubEnv, SubSchema, SubBasePath, SubCurrentPath>): Acryl<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> | S, BasePath, CurrentPath>;
|
|
104
|
-
/**
|
|
105
|
-
* `.basePath()` allows base paths to be specified.
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @param {string} path - base Path
|
|
109
|
-
* @returns {Acryl} changed Acryl instance
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* const api = new Acryl().basePath('/api')
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
basePath<SubPath extends string>(path: SubPath): Acryl<E, S, MergePath<BasePath, SubPath>, MergePath<BasePath, SubPath>>;
|
|
117
|
-
/**
|
|
118
|
-
* `.onError()` handles an error and returns a customized Response.
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* @param {ErrorHandler} handler - request Handler for error
|
|
122
|
-
* @returns {Acryl} changed Acryl instance
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```ts
|
|
126
|
-
* app.onError((err, c) => {
|
|
127
|
-
* console.error(`${err}`)
|
|
128
|
-
* return c.text('Custom Error Message', 500)
|
|
129
|
-
* })
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
onError: (handler: ErrorHandler<E>) => Acryl<E, S, BasePath, CurrentPath>;
|
|
133
|
-
/**
|
|
134
|
-
* `.notFound()` allows you to customize a Not Found Response.
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* @param {NotFoundHandler} handler - request handler for not-found
|
|
138
|
-
* @returns {Acryl} changed Acryl instance
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```ts
|
|
142
|
-
* app.notFound((c) => {
|
|
143
|
-
* return c.text('Custom 404 Message', 404)
|
|
144
|
-
* })
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
notFound: (handler: NotFoundHandler<E>) => Acryl<E, S, BasePath, CurrentPath>;
|
|
148
|
-
/**
|
|
149
|
-
* `.mount()` allows you to mount applications built with other frameworks into your Acryl application.
|
|
150
|
-
*
|
|
151
|
-
* @deprecated Use `mount()` from `acryl-router/mount` instead. `.mount()` will be removed in v5.
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* @param {string} path - base Path
|
|
155
|
-
* @param {Function} applicationHandler - other Request Handler
|
|
156
|
-
* @param {MountOptions} [options] - options of `.mount()`
|
|
157
|
-
* @returns {Acryl} mounted Acryl instance
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```ts
|
|
161
|
-
* import { Router as IttyRouter } from 'itty-router'
|
|
162
|
-
* import { Acryl } from 'acrylblends'
|
|
163
|
-
* // Create itty-router application
|
|
164
|
-
* const ittyRouter = IttyRouter()
|
|
165
|
-
* // GET /itty-router/hello
|
|
166
|
-
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
167
|
-
*
|
|
168
|
-
* const app = new Acryl()
|
|
169
|
-
* app.mount('/itty-router', ittyRouter.handle)
|
|
170
|
-
* ```
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```ts
|
|
174
|
-
* const app = new Acryl()
|
|
175
|
-
* // Send the request to another application without modification.
|
|
176
|
-
* app.mount('/app', anotherApp, {
|
|
177
|
-
* replaceRequest: (req) => req,
|
|
178
|
-
* })
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
mount(path: string, applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>, options?: MountOptions): Acryl<E, S, BasePath, CurrentPath>;
|
|
182
|
-
/**
|
|
183
|
-
* `.fetch()` will be entry point of your app.
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* @param {Request} request - request Object of request
|
|
187
|
-
* @param {Env} env - env Object
|
|
188
|
-
* @param {ExecutionContext} executionCtx - context of execution
|
|
189
|
-
* @returns {Response | Promise<Response>} response of request
|
|
190
|
-
*
|
|
191
|
-
*/
|
|
192
|
-
fetch: (request: Request, env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
|
|
193
|
-
/**
|
|
194
|
-
* `.request()` is a useful method for testing.
|
|
195
|
-
* You can pass a URL or pathname to send a GET request.
|
|
196
|
-
* app will return a Response object.
|
|
197
|
-
* ```ts
|
|
198
|
-
* test('GET /hello is ok', async () => {
|
|
199
|
-
* const res = await app.request('/hello')
|
|
200
|
-
* expect(res.status).toBe(200)
|
|
201
|
-
* })
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
request: (input: Request | string | URL, requestInit?: RequestInit, Env?: E["Bindings"] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
|
|
205
|
-
/**
|
|
206
|
-
* `.fire()` automatically adds a global fetch event listener.
|
|
207
|
-
* This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
|
|
208
|
-
* @deprecated
|
|
209
|
-
* ACRYL ships no service-worker adapter: mount the app with `ctx.router.route(path, app)` and serve it through an ACRYL adapter instead.
|
|
210
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
|
211
|
-
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
|
|
212
|
-
*/
|
|
213
|
-
fire: () => void;
|
|
214
|
-
}
|
|
215
|
-
export { Acryl as AcrylBase };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { AcrylBase } from './app-base.ts';
|
|
2
|
-
import type { AcrylOptions } from './app-base.ts';
|
|
3
|
-
import type { BlankEnv, BlankSchema, Env, Schema } from './types.ts';
|
|
4
|
-
/**
|
|
5
|
-
* The Acryl class extends the functionality of the AcrylBase class.
|
|
6
|
-
* It sets up routing and allows for custom options to be passed.
|
|
7
|
-
*
|
|
8
|
-
* @template E - The environment type.
|
|
9
|
-
* @template S - The schema type.
|
|
10
|
-
* @template BasePath - The base path type.
|
|
11
|
-
*/
|
|
12
|
-
export declare class Acryl<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = '/'> extends AcrylBase<E, S, BasePath> {
|
|
13
|
-
/**
|
|
14
|
-
* Creates an instance of the Acryl class.
|
|
15
|
-
*
|
|
16
|
-
* @param options - Optional configuration options for the Acryl instance.
|
|
17
|
-
*/
|
|
18
|
-
constructor(options?: AcrylOptions<E>);
|
|
19
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Acryl } from '../app.ts';
|
|
2
|
-
import type { UnionToIntersection } from '../utils/types.ts';
|
|
3
|
-
import type { Client, ClientRequestOptions } from './types.ts';
|
|
4
|
-
export declare const hc: <T extends Acryl<any, any, any>, Prefix extends string = string>(baseUrl: Prefix, options?: ClientRequestOptions) => UnionToIntersection<Client<T, Prefix>>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description This file is a modified version of `fetch-result-please` (`ofetch`), minimalized and adapted to Acryl's custom needs.
|
|
3
|
-
*
|
|
4
|
-
* @link https://www.npmjs.com/package/fetch-result-please
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Smartly parses and return the consumable result from a fetch `Response`.
|
|
8
|
-
*
|
|
9
|
-
* Throwing a structured error if the response is not `ok`. ({@link DetailedError})
|
|
10
|
-
*/
|
|
11
|
-
export declare function fetchRP(fetchRes: Response | Promise<Response>): Promise<any>;
|
|
12
|
-
export declare class DetailedError extends Error {
|
|
13
|
-
/**
|
|
14
|
-
* Additional `message` that will be logged AND returned to client
|
|
15
|
-
*/
|
|
16
|
-
detail?: any;
|
|
17
|
-
/**
|
|
18
|
-
* Additional `code` that will be logged AND returned to client
|
|
19
|
-
*/
|
|
20
|
-
code?: any;
|
|
21
|
-
/**
|
|
22
|
-
* Additional value that will be logged AND NOT returned to client
|
|
23
|
-
*/
|
|
24
|
-
log?: any;
|
|
25
|
-
/**
|
|
26
|
-
* Optionally set the status code to return, in a web server context
|
|
27
|
-
*/
|
|
28
|
-
statusCode?: any;
|
|
29
|
-
constructor(message: string, options?: {
|
|
30
|
-
detail?: any;
|
|
31
|
-
code?: any;
|
|
32
|
-
statusCode?: number;
|
|
33
|
-
log?: any;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module
|
|
3
|
-
* The HTTP Client for Acryl.
|
|
4
|
-
*/
|
|
5
|
-
export { hc } from './client.ts';
|
|
6
|
-
export { parseResponse, DetailedError } from './utils.ts';
|
|
7
|
-
export type { InferResponseType, InferRequestType, Fetch, ClientRequestOptions, ClientRequest, ClientResponse, ApplyGlobalResponse, PickResponseByStatusCode, } from './types.ts';
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import type { Acryl } from '../app.ts';
|
|
2
|
-
import type { AcrylBase } from '../app-base.ts';
|
|
3
|
-
import type { METHODS, METHOD_NAME_ALL_LOWERCASE } from '../router.ts';
|
|
4
|
-
import type { Endpoint, ExtractSchema, KnownResponseFormat, ResponseFormat, Schema } from '../types.ts';
|
|
5
|
-
import type { StatusCode, SuccessStatusCode } from '../utils/http-status.ts';
|
|
6
|
-
import type { HasRequiredKeys } from '../utils/types.ts';
|
|
7
|
-
/**
|
|
8
|
-
* Type representing the '$all' method name
|
|
9
|
-
*/
|
|
10
|
-
type MethodNameAll = `$${typeof METHOD_NAME_ALL_LOWERCASE}`;
|
|
11
|
-
/**
|
|
12
|
-
* Type representing all standard HTTP methods prefixed with '$'
|
|
13
|
-
* e.g., '$get' | '$post' | '$put' | '$delete' | '$options' | '$patch' | '$query'
|
|
14
|
-
*/
|
|
15
|
-
type StandardMethods = `$${(typeof METHODS)[number]}`;
|
|
16
|
-
/**
|
|
17
|
-
* Expands '$all' into all standard HTTP methods.
|
|
18
|
-
* If the schema contains '$all', it creates a type where all standard HTTP methods
|
|
19
|
-
* point to the same endpoint definition as '$all', while removing '$all' itself.
|
|
20
|
-
*/
|
|
21
|
-
type ExpandAllMethod<S> = MethodNameAll extends keyof S ? {
|
|
22
|
-
[M in StandardMethods]: S[MethodNameAll];
|
|
23
|
-
} & Omit<S, MethodNameAll> : S;
|
|
24
|
-
type AcrylRequest = (typeof Acryl.prototype)['request'];
|
|
25
|
-
export type BuildSearchParamsFn = (query: Record<string, string | string[]>) => URLSearchParams;
|
|
26
|
-
export type ClientRequestOptions<T = unknown> = {
|
|
27
|
-
fetch?: typeof fetch | AcrylRequest;
|
|
28
|
-
webSocket?: (...args: ConstructorParameters<typeof WebSocket>) => WebSocket;
|
|
29
|
-
/**
|
|
30
|
-
* Standard `RequestInit`, caution that this take highest priority
|
|
31
|
-
* and could be used to overwrite things that Acryl sets for you, like `body | method | headers`.
|
|
32
|
-
*
|
|
33
|
-
* If you want to add some headers, use in `headers` instead of `init`
|
|
34
|
-
*/
|
|
35
|
-
init?: RequestInit;
|
|
36
|
-
/**
|
|
37
|
-
* Custom function to serialize query parameters into URLSearchParams.
|
|
38
|
-
* By default, arrays are serialized as multiple parameters with the same key (e.g., `key=a&key=b`).
|
|
39
|
-
* You can provide a custom function to change this behavior, for example to use bracket notation (e.g., `key[]=a&key[]=b`).
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```ts
|
|
43
|
-
* const client = hc('http://localhost', {
|
|
44
|
-
* buildSearchParams: (query) => {
|
|
45
|
-
* return new URLSearchParams(qs.stringify(query))
|
|
46
|
-
* }
|
|
47
|
-
* })
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
buildSearchParams?: BuildSearchParamsFn;
|
|
51
|
-
} & (keyof T extends never ? {
|
|
52
|
-
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
53
|
-
} : {
|
|
54
|
-
headers: T | (() => T | Promise<T>);
|
|
55
|
-
});
|
|
56
|
-
export type ClientRequest<Prefix extends string, Path extends string, S extends Schema> = {
|
|
57
|
-
[M in keyof ExpandAllMethod<S>]: ExpandAllMethod<S>[M] extends Endpoint & {
|
|
58
|
-
input: infer R;
|
|
59
|
-
} ? R extends object ? HasRequiredKeys<R> extends true ? (args: R, options?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<ExpandAllMethod<S>[M]>> : (args?: R, options?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<ExpandAllMethod<S>[M]>> : never : never;
|
|
60
|
-
} & {
|
|
61
|
-
$url: <const Arg extends (S[keyof S] extends {
|
|
62
|
-
input: infer R;
|
|
63
|
-
} ? R extends {
|
|
64
|
-
param: infer P;
|
|
65
|
-
} ? R extends {
|
|
66
|
-
query: infer Q;
|
|
67
|
-
} ? {
|
|
68
|
-
param: P;
|
|
69
|
-
query: Q;
|
|
70
|
-
} : {
|
|
71
|
-
param: P;
|
|
72
|
-
} : R extends {
|
|
73
|
-
query: infer Q;
|
|
74
|
-
} ? {
|
|
75
|
-
query: Q;
|
|
76
|
-
} : {} : {}) | undefined = undefined>(arg?: Arg) => AcrylURL<Prefix, Path, Arg>;
|
|
77
|
-
$path: <const Arg extends (S[keyof S] extends {
|
|
78
|
-
input: infer R;
|
|
79
|
-
} ? R extends {
|
|
80
|
-
param: infer P;
|
|
81
|
-
} ? R extends {
|
|
82
|
-
query: infer Q;
|
|
83
|
-
} ? {
|
|
84
|
-
param: P;
|
|
85
|
-
query: Q;
|
|
86
|
-
} : {
|
|
87
|
-
param: P;
|
|
88
|
-
} : R extends {
|
|
89
|
-
query: infer Q;
|
|
90
|
-
} ? {
|
|
91
|
-
query: Q;
|
|
92
|
-
} : {} : {}) | undefined = undefined>(arg?: Arg) => BuildPath<Path, Arg>;
|
|
93
|
-
} & (S['$get'] extends {
|
|
94
|
-
outputFormat: 'ws';
|
|
95
|
-
} ? S['$get'] extends {
|
|
96
|
-
input: infer I;
|
|
97
|
-
} ? {
|
|
98
|
-
$ws: (args?: I) => WebSocket;
|
|
99
|
-
} : {} : {});
|
|
100
|
-
type ClientResponseOfEndpoint<T extends Endpoint = Endpoint> = T extends {
|
|
101
|
-
output: infer O;
|
|
102
|
-
outputFormat: infer F;
|
|
103
|
-
status: infer S;
|
|
104
|
-
} ? ClientResponse<O, S extends number ? S : never, F extends ResponseFormat ? F : never> : never;
|
|
105
|
-
export interface ClientResponse<T, U extends number = StatusCode, F extends ResponseFormat = ResponseFormat> {
|
|
106
|
-
readonly body: ReadableStream | null;
|
|
107
|
-
readonly bodyUsed: boolean;
|
|
108
|
-
ok: U extends SuccessStatusCode ? true : U extends Exclude<StatusCode, SuccessStatusCode> ? false : boolean;
|
|
109
|
-
redirected: boolean;
|
|
110
|
-
status: U;
|
|
111
|
-
statusText: string;
|
|
112
|
-
type: 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect';
|
|
113
|
-
headers: Headers;
|
|
114
|
-
url: string;
|
|
115
|
-
redirect(url: string, status: number): Response;
|
|
116
|
-
clone(): Response;
|
|
117
|
-
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
118
|
-
json(): F extends 'text' ? Promise<never> : F extends 'json' ? Promise<T> : Promise<unknown>;
|
|
119
|
-
text(): F extends 'text' ? (T extends string ? Promise<T> : Promise<never>) : Promise<string>;
|
|
120
|
-
blob(): Promise<Blob>;
|
|
121
|
-
formData(): Promise<FormData>;
|
|
122
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
123
|
-
}
|
|
124
|
-
type BuildSearch<Arg, Key extends 'query'> = Arg extends {
|
|
125
|
-
[K in Key]: infer Query;
|
|
126
|
-
} ? IsEmptyObject<Query> extends true ? '' : `?${string}` : '';
|
|
127
|
-
type BuildPathname<P extends string, Arg> = Arg extends {
|
|
128
|
-
param: infer Param;
|
|
129
|
-
} ? `${ApplyParam<TrimStartSlash<P>, Param>}` : `/${TrimStartSlash<P>}`;
|
|
130
|
-
type BuildPath<P extends string, Arg> = `${BuildPathname<P, Arg>}${BuildSearch<Arg, 'query'>}`;
|
|
131
|
-
type BuildTypedURL<Protocol extends string, Host extends string, Port extends string, P extends string, Arg> = TypedURL<`${Protocol}:`, Host, Port, BuildPathname<P, Arg>, BuildSearch<Arg, 'query'>>;
|
|
132
|
-
type AcrylURL<Prefix extends string, Path extends string, Arg> = IsLiteral<Prefix> extends true ? TrimEndSlash<Prefix> extends `${infer Protocol}://${infer Rest}` ? Rest extends `${infer Hostname}/${infer P}` ? ParseHostName<Hostname> extends [infer Host extends string, infer Port extends string] ? BuildTypedURL<Protocol, Host, Port, P, Arg> : never : ParseHostName<Rest> extends [infer Host extends string, infer Port extends string] ? BuildTypedURL<Protocol, Host, Port, Path, Arg> : never : URL : URL;
|
|
133
|
-
type ParseHostName<T extends string> = T extends `${infer Host}:${infer Port}` ? [Host, Port] : [T, ''];
|
|
134
|
-
type TrimStartSlash<T extends string> = T extends `/${infer R}` ? TrimStartSlash<R> : T;
|
|
135
|
-
type TrimEndSlash<T extends string> = T extends `${infer R}/` ? TrimEndSlash<R> : T;
|
|
136
|
-
type IsLiteral<T extends string> = [T] extends [never] ? false : string extends T ? false : true;
|
|
137
|
-
type ApplyParam<Path extends string, P, Result extends string = ''> = Path extends `${infer Head}/${infer Rest}` ? Head extends `:${infer Param}` ? P extends Record<Param, infer Value extends string> ? IsLiteral<Value> extends true ? ApplyParam<Rest, P, `${Result}/${Value & string}`> : ApplyParam<Rest, P, `${Result}/${Head}`> : ApplyParam<Rest, P, `${Result}/${Head}`> : ApplyParam<Rest, P, `${Result}/${Head}`> : Path extends `:${infer Param}` ? P extends Record<Param, infer Value extends string> ? IsLiteral<Value> extends true ? `${Result}/${Value & string}` : `${Result}/${Path}` : `${Result}/${Path}` : `${Result}/${Path}`;
|
|
138
|
-
type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
139
|
-
export interface TypedURL<Protocol extends string, Hostname extends string, Port extends string, Pathname extends string, Search extends string> extends URL {
|
|
140
|
-
protocol: Protocol;
|
|
141
|
-
hostname: Hostname;
|
|
142
|
-
port: Port;
|
|
143
|
-
host: Port extends '' ? Hostname : `${Hostname}:${Port}`;
|
|
144
|
-
origin: `${Protocol}//${Hostname}${Port extends '' ? '' : `:${Port}`}`;
|
|
145
|
-
pathname: Pathname;
|
|
146
|
-
search: Search;
|
|
147
|
-
href: `${Protocol}//${Hostname}${Port extends '' ? '' : `:${Port}`}${Pathname}${Search}`;
|
|
148
|
-
}
|
|
149
|
-
export interface Response extends ClientResponse<unknown> {
|
|
150
|
-
}
|
|
151
|
-
export type Fetch<T> = (args?: InferRequestType<T>, opt?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<InferEndpointType<T>>>;
|
|
152
|
-
type InferEndpointType<T> = T extends (args: infer R, options: any | undefined) => Promise<infer U> ? U extends ClientResponse<infer O, infer S, infer F> ? {
|
|
153
|
-
input: NonNullable<R>;
|
|
154
|
-
output: O;
|
|
155
|
-
outputFormat: F;
|
|
156
|
-
status: S;
|
|
157
|
-
} extends Endpoint ? {
|
|
158
|
-
input: NonNullable<R>;
|
|
159
|
-
output: O;
|
|
160
|
-
outputFormat: F;
|
|
161
|
-
status: S;
|
|
162
|
-
} : never : never : never;
|
|
163
|
-
export type InferResponseType<T, U extends StatusCode = StatusCode> = InferResponseTypeFromEndpoint<InferEndpointType<T>, U>;
|
|
164
|
-
type InferResponseTypeFromEndpoint<T extends Endpoint, U extends StatusCode> = T extends {
|
|
165
|
-
output: infer O;
|
|
166
|
-
status: infer S;
|
|
167
|
-
} ? S extends U ? O : never : never;
|
|
168
|
-
export type InferRequestType<T> = T extends (args: infer R, options: any | undefined) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
169
|
-
export type InferRequestOptionsType<T> = T extends (args: any, options: infer R) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
170
|
-
/**
|
|
171
|
-
* Filter a ClientResponse type so it only includes responses of specific status codes.
|
|
172
|
-
*/
|
|
173
|
-
export type FilterClientResponseByStatusCode<T extends ClientResponse<any, any, any>, U extends number = StatusCode> = T extends ClientResponse<infer RT, infer RC, infer RF> ? RC extends U ? ClientResponse<RT, RC, RF> : never : never;
|
|
174
|
-
type PathToChain<Prefix extends string, Path extends string, E extends Schema, Original extends string = Path> = Path extends `/${infer P}` ? PathToChain<Prefix, P, E, Path> : Path extends `${infer P}/${infer R}` ? {
|
|
175
|
-
[K in P]: PathToChain<Prefix, R, E, Original>;
|
|
176
|
-
} : {
|
|
177
|
-
[K in Path extends '' ? 'index' : Path]: ClientRequest<Prefix, Original, E extends Record<string, unknown> ? E[Original] : never>;
|
|
178
|
-
};
|
|
179
|
-
export type Client<T, Prefix extends string> = T extends AcrylBase<any, infer S, any> ? S extends Record<infer K, Schema> ? K extends string ? PathToChain<Prefix, K, S> : never : never : never;
|
|
180
|
-
export type Callback = (opts: CallbackOptions) => unknown;
|
|
181
|
-
interface CallbackOptions {
|
|
182
|
-
path: string[];
|
|
183
|
-
args: any[];
|
|
184
|
-
}
|
|
185
|
-
export type ObjectType<T = unknown> = {
|
|
186
|
-
[key: string]: T;
|
|
187
|
-
};
|
|
188
|
-
type GlobalResponseDefinition = {
|
|
189
|
-
[S in StatusCode]?: {
|
|
190
|
-
[F in KnownResponseFormat]?: unknown;
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
type ToEndpoints<Def extends GlobalResponseDefinition, R> = {
|
|
194
|
-
[S in keyof Def & StatusCode]: {
|
|
195
|
-
[F in keyof Def[S] & KnownResponseFormat]: Omit<R, 'output' | 'status' | 'outputFormat'> & {
|
|
196
|
-
output: Def[S][F];
|
|
197
|
-
status: S;
|
|
198
|
-
outputFormat: F;
|
|
199
|
-
};
|
|
200
|
-
}[keyof Def[S] & KnownResponseFormat];
|
|
201
|
-
}[keyof Def & StatusCode];
|
|
202
|
-
type ModRoute<R, Def extends GlobalResponseDefinition> = R extends Endpoint ? R | ToEndpoints<Def, R> : R;
|
|
203
|
-
type ModSchema<D, Def extends GlobalResponseDefinition> = {
|
|
204
|
-
[K in keyof D]: {
|
|
205
|
-
[M in keyof D[K]]: ModRoute<D[K][M], Def>;
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
export type ApplyGlobalResponse<App, Def extends GlobalResponseDefinition> = App extends AcrylBase<infer E, infer _ extends Schema, infer B> ? ModSchema<ExtractSchema<App>, Def> extends infer S extends Schema ? Acryl<E, S, B> : never : never;
|
|
209
|
-
type PickRoute<R, U extends StatusCode> = R extends Endpoint ? R extends {
|
|
210
|
-
status: U;
|
|
211
|
-
} ? R : never : R;
|
|
212
|
-
type PickSchema<D, U extends StatusCode> = {
|
|
213
|
-
[K in keyof D]: {
|
|
214
|
-
[M in keyof D[K]]: PickRoute<D[K][M], U>;
|
|
215
|
-
};
|
|
216
|
-
};
|
|
217
|
-
/**
|
|
218
|
-
* Keep only specific status code responses from all routes of an app.
|
|
219
|
-
* Useful when error responses are handled centrally (e.g., via custom fetch)
|
|
220
|
-
* and you want the client to only expose success response types.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```ts
|
|
224
|
-
* type AppSuccessOnly = PickResponseByStatusCode<typeof app, 200>
|
|
225
|
-
* const client = hc<AppSuccessOnly>('http://localhost')
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
export type PickResponseByStatusCode<App, U extends StatusCode> = App extends AcrylBase<infer E, infer _ extends Schema, infer B> ? PickSchema<ExtractSchema<App>, U> extends infer S extends Schema ? Acryl<E, S, B> : never : never;
|
|
229
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ClientErrorStatusCode, ContentfulStatusCode, ServerErrorStatusCode } from '../utils/http-status.ts';
|
|
2
|
-
import { DetailedError } from './fetch-result-please.ts';
|
|
3
|
-
import type { ClientResponse, FilterClientResponseByStatusCode } from './types.ts';
|
|
4
|
-
export { DetailedError };
|
|
5
|
-
export declare const mergePath: (base: string, path: string) => string;
|
|
6
|
-
export declare const replaceUrlParam: (urlString: string, params: Record<string, string | undefined>) => string;
|
|
7
|
-
export declare const buildSearchParams: (query: Record<string, string | string[]>) => URLSearchParams;
|
|
8
|
-
export declare const replaceUrlProtocol: (urlString: string, protocol: "ws" | "http") => string;
|
|
9
|
-
export declare const removeIndexString: (urlString: string) => string;
|
|
10
|
-
export declare function deepMerge<T>(target: T, source: Record<string, unknown>): T;
|
|
11
|
-
/**
|
|
12
|
-
* Shortcut to get a consumable response from `hc`'s fetch calls (Response), with types inference.
|
|
13
|
-
*
|
|
14
|
-
* Smartly parse the response data, throwing a structured error if the response is not `ok`. ({@link DetailedError})
|
|
15
|
-
*
|
|
16
|
-
* @example const result = await parseResponse(client.posts.$get())
|
|
17
|
-
*/
|
|
18
|
-
export declare function parseResponse<T extends ClientResponse<any>>(fetchRes: T | Promise<T>): Promise<FilterClientResponseByStatusCode<T, Exclude<ContentfulStatusCode, ClientErrorStatusCode | ServerErrorStatusCode>> extends never ? undefined : FilterClientResponseByStatusCode<T, Exclude<ContentfulStatusCode, ClientErrorStatusCode | ServerErrorStatusCode>> extends ClientResponse<infer RT, infer _, infer RF> ? RF extends 'json' ? RT : RT extends string ? RT : string : undefined>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Context } from './context.ts';
|
|
2
|
-
import type { Env, ErrorHandler, Next, NotFoundHandler } from './types.ts';
|
|
3
|
-
/**
|
|
4
|
-
* Compose middleware functions into a single function based on `koa-compose` package.
|
|
5
|
-
*
|
|
6
|
-
* @template E - The environment type.
|
|
7
|
-
*
|
|
8
|
-
* @param {[[Function, unknown], unknown][] | [[Function]][]} middleware - An array of middleware functions and their corresponding parameters.
|
|
9
|
-
* @param {ErrorHandler<E>} [onError] - An optional error handler function.
|
|
10
|
-
* @param {NotFoundHandler<E>} [onNotFound] - An optional not-found handler function.
|
|
11
|
-
*
|
|
12
|
-
* @returns {(context: Context, next?: Next) => Promise<Context>} - A composed middleware function.
|
|
13
|
-
*/
|
|
14
|
-
export declare const compose: <E extends Env = Env>(middleware: [[Function, unknown], unknown][] | [[Function]][], onError?: ErrorHandler<E>, onNotFound?: NotFoundHandler<E>) => ((context: Context, next?: Next) => Promise<Context>);
|