@spikard/wasm 0.6.2 → 0.7.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/README.md +356 -524
- package/dist/chunk-DYTZ4RA2.mjs +2267 -0
- package/dist/chunk-DYTZ4RA2.mjs.map +1 -0
- package/dist/index.d.mts +365 -0
- package/dist/index.d.ts +365 -0
- package/dist/index.js +2269 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/node.d.mts +9 -0
- package/dist/node.d.ts +9 -0
- package/dist/node.js +2400 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +120 -0
- package/dist/node.mjs.map +1 -0
- package/{dist-node → dist}/package.json +1 -1
- package/{dist-node → dist}/spikard_wasm.js +7 -4
- package/{dist-node → dist}/spikard_wasm_bg.wasm +0 -0
- package/package.json +54 -46
- package/dist-bundler/package.json +0 -34
- package/dist-bundler/spikard_wasm.d.ts +0 -28
- package/dist-bundler/spikard_wasm.js +0 -5
- package/dist-bundler/spikard_wasm_bg.js +0 -914
- package/dist-bundler/spikard_wasm_bg.wasm +0 -0
- package/dist-bundler/spikard_wasm_bg.wasm.d.ts +0 -26
- package/dist-node/README.md +0 -739
- package/dist-node/spikard_wasm.d.ts +0 -28
- package/dist-node/spikard_wasm_bg.wasm.d.ts +0 -26
- package/dist-web/README.md +0 -739
- package/dist-web/package.json +0 -32
- package/dist-web/spikard_wasm.d.ts +0 -79
- package/dist-web/spikard_wasm.js +0 -921
- package/dist-web/spikard_wasm_bg.wasm +0 -0
- package/dist-web/spikard_wasm_bg.wasm.d.ts +0 -26
- /package/{dist-bundler → dist}/README.md +0 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
declare const STREAM_HANDLE_PROP: unique symbol;
|
|
2
|
+
type StreamChunk = JsonValue | string | Uint8Array | ArrayBuffer | ArrayBufferView | null | undefined;
|
|
3
|
+
type AsyncIteratorLike<T> = AsyncIterator<T> & AsyncIterable<T>;
|
|
4
|
+
interface StreamingResponseInit {
|
|
5
|
+
statusCode?: number;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
declare class StreamingResponse {
|
|
9
|
+
readonly statusCode: number;
|
|
10
|
+
readonly headers: Record<string, string>;
|
|
11
|
+
readonly [STREAM_HANDLE_PROP]: AsyncIteratorLike<StreamChunk>;
|
|
12
|
+
readonly __spikard_streaming__: true;
|
|
13
|
+
constructor(stream: AsyncIterable<StreamChunk> | AsyncIterator<StreamChunk>, init?: StreamingResponseInit);
|
|
14
|
+
collect(): Promise<Uint8Array>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
18
|
+
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
19
|
+
[Key in string]: JsonValue;
|
|
20
|
+
};
|
|
21
|
+
type JsonRecord = Record<string, JsonValue>;
|
|
22
|
+
type BinaryLike = ArrayBuffer | ArrayBufferView | Uint8Array | Blob;
|
|
23
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
24
|
+
interface AbortSignalLike {
|
|
25
|
+
readonly aborted: boolean;
|
|
26
|
+
addEventListener(type: "abort", listener: () => void, options?: {
|
|
27
|
+
once?: boolean;
|
|
28
|
+
} | boolean): void;
|
|
29
|
+
removeEventListener(type: "abort", listener: () => void): void;
|
|
30
|
+
}
|
|
31
|
+
interface HandlerContext {
|
|
32
|
+
signal?: AbortSignalLike;
|
|
33
|
+
}
|
|
34
|
+
interface Base64EncodedBody {
|
|
35
|
+
__spikard_base64__: string;
|
|
36
|
+
}
|
|
37
|
+
type HandlerBody = JsonValue | Base64EncodedBody | null;
|
|
38
|
+
interface StructuredHandlerResponse {
|
|
39
|
+
status?: number;
|
|
40
|
+
statusCode?: number;
|
|
41
|
+
headers?: Record<string, string>;
|
|
42
|
+
body?: HandlerBody;
|
|
43
|
+
}
|
|
44
|
+
type HandlerPayload = Request$1 | JsonValue | string | BinaryLike | null | undefined;
|
|
45
|
+
type HandlerResult = StructuredHandlerResponse | JsonValue | StreamingResponse | undefined;
|
|
46
|
+
type HandlerFunction<TReturn extends HandlerResult = HandlerResult> = (payload: HandlerPayload, context?: HandlerContext) => MaybePromise<TReturn>;
|
|
47
|
+
interface WebSocketServerSocket {
|
|
48
|
+
sendText(message: string): MaybePromise<void>;
|
|
49
|
+
sendJson(payload: JsonValue): MaybePromise<void>;
|
|
50
|
+
sendBytes?(payload: BinaryLike): MaybePromise<void>;
|
|
51
|
+
close(code?: number, reason?: string): MaybePromise<void>;
|
|
52
|
+
broadcast?(payload: JsonValue | string): MaybePromise<void>;
|
|
53
|
+
isClosed(): boolean;
|
|
54
|
+
}
|
|
55
|
+
interface WebSocketHandler {
|
|
56
|
+
onOpen?: (socket: WebSocketServerSocket) => MaybePromise<void>;
|
|
57
|
+
onMessage?: (socket: WebSocketServerSocket, data: JsonValue | string | BinaryLike) => MaybePromise<void>;
|
|
58
|
+
onClose?: (socket: WebSocketServerSocket, code?: number, reason?: string) => MaybePromise<void>;
|
|
59
|
+
}
|
|
60
|
+
type WebSocketHandlerLike = WebSocketHandler | HandlerFunction;
|
|
61
|
+
|
|
62
|
+
interface Request$1 {
|
|
63
|
+
method: string;
|
|
64
|
+
path: string;
|
|
65
|
+
queryString: string;
|
|
66
|
+
params?: Record<string, JsonValue>;
|
|
67
|
+
pathParams?: Record<string, string>;
|
|
68
|
+
query?: Record<string, JsonValue>;
|
|
69
|
+
files?: Array<{
|
|
70
|
+
name: string;
|
|
71
|
+
filename?: string;
|
|
72
|
+
content?: string;
|
|
73
|
+
contentType?: string;
|
|
74
|
+
}>;
|
|
75
|
+
headers: Record<string, string>;
|
|
76
|
+
body: Buffer | Uint8Array | null;
|
|
77
|
+
json<T extends JsonValue = JsonValue>(): T;
|
|
78
|
+
form(): Record<string, string>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface CompressionConfig {
|
|
82
|
+
gzip?: boolean;
|
|
83
|
+
brotli?: boolean;
|
|
84
|
+
minSize?: number;
|
|
85
|
+
quality?: number;
|
|
86
|
+
}
|
|
87
|
+
interface RateLimitConfig {
|
|
88
|
+
perSecond: number;
|
|
89
|
+
burst: number;
|
|
90
|
+
ipBased?: boolean;
|
|
91
|
+
}
|
|
92
|
+
interface JwtConfig {
|
|
93
|
+
secret: string;
|
|
94
|
+
algorithm?: string;
|
|
95
|
+
audience?: string[];
|
|
96
|
+
issuer?: string;
|
|
97
|
+
leeway?: number;
|
|
98
|
+
}
|
|
99
|
+
interface ApiKeyConfig {
|
|
100
|
+
keys: string[];
|
|
101
|
+
headerName?: string;
|
|
102
|
+
}
|
|
103
|
+
interface ContactInfo {
|
|
104
|
+
name?: string;
|
|
105
|
+
email?: string;
|
|
106
|
+
url?: string;
|
|
107
|
+
}
|
|
108
|
+
interface LicenseInfo {
|
|
109
|
+
name: string;
|
|
110
|
+
url?: string;
|
|
111
|
+
}
|
|
112
|
+
interface ServerInfo {
|
|
113
|
+
url: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
}
|
|
116
|
+
interface SecuritySchemeInfo {
|
|
117
|
+
type: "http" | "apiKey";
|
|
118
|
+
scheme?: string;
|
|
119
|
+
bearerFormat?: string;
|
|
120
|
+
location?: "header" | "query" | "cookie";
|
|
121
|
+
name?: string;
|
|
122
|
+
}
|
|
123
|
+
interface OpenApiConfig {
|
|
124
|
+
enabled?: boolean;
|
|
125
|
+
title?: string;
|
|
126
|
+
version?: string;
|
|
127
|
+
description?: string;
|
|
128
|
+
swaggerUiPath?: string;
|
|
129
|
+
redocPath?: string;
|
|
130
|
+
openapiJsonPath?: string;
|
|
131
|
+
contact?: ContactInfo;
|
|
132
|
+
license?: LicenseInfo;
|
|
133
|
+
servers?: ServerInfo[];
|
|
134
|
+
securitySchemes?: Record<string, SecuritySchemeInfo>;
|
|
135
|
+
}
|
|
136
|
+
interface StaticFilesConfig {
|
|
137
|
+
directory: string;
|
|
138
|
+
routePrefix: string;
|
|
139
|
+
indexFile?: boolean;
|
|
140
|
+
cacheControl?: string;
|
|
141
|
+
}
|
|
142
|
+
interface StaticManifestEntry {
|
|
143
|
+
route: string;
|
|
144
|
+
headers: Record<string, string>;
|
|
145
|
+
body: string;
|
|
146
|
+
}
|
|
147
|
+
interface ServerConfig {
|
|
148
|
+
host?: string;
|
|
149
|
+
port?: number;
|
|
150
|
+
workers?: number;
|
|
151
|
+
enableRequestId?: boolean;
|
|
152
|
+
maxBodySize?: number | null;
|
|
153
|
+
requestTimeout?: number | null;
|
|
154
|
+
compression?: CompressionConfig | null;
|
|
155
|
+
rateLimit?: RateLimitConfig | null;
|
|
156
|
+
jwtAuth?: JwtConfig | null;
|
|
157
|
+
apiKeyAuth?: ApiKeyConfig | null;
|
|
158
|
+
staticFiles?: StaticFilesConfig[];
|
|
159
|
+
__wasmStaticManifest?: StaticManifestEntry[];
|
|
160
|
+
gracefulShutdown?: boolean;
|
|
161
|
+
shutdownTimeout?: number;
|
|
162
|
+
openapi?: OpenApiConfig | null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
interface ServerOptions {
|
|
166
|
+
host?: string;
|
|
167
|
+
port?: number;
|
|
168
|
+
}
|
|
169
|
+
type FetchHandler = (request: Request) => Promise<Response>;
|
|
170
|
+
declare function createFetchHandler(app: SpikardApp): FetchHandler;
|
|
171
|
+
declare function runServer(app: SpikardApp, config?: ServerConfig | ServerOptions): void;
|
|
172
|
+
|
|
173
|
+
type DependencyValue = unknown;
|
|
174
|
+
type DependencyFactory = (...args: unknown[]) => MaybePromise<unknown>;
|
|
175
|
+
interface DependencyOptions {
|
|
176
|
+
dependsOn?: string[];
|
|
177
|
+
singleton?: boolean;
|
|
178
|
+
cacheable?: boolean;
|
|
179
|
+
}
|
|
180
|
+
interface DependencyDescriptor {
|
|
181
|
+
isFactory: boolean;
|
|
182
|
+
value?: DependencyValue | undefined;
|
|
183
|
+
factory?: ((dependenciesJson: string) => Promise<string>) | undefined;
|
|
184
|
+
dependsOn: string[];
|
|
185
|
+
singleton: boolean;
|
|
186
|
+
cacheable: boolean;
|
|
187
|
+
}
|
|
188
|
+
type LifecycleHookFunction = (payload: unknown) => MaybePromise<unknown>;
|
|
189
|
+
interface LifecycleHooks {
|
|
190
|
+
onRequest: LifecycleHookFunction[];
|
|
191
|
+
preValidation: LifecycleHookFunction[];
|
|
192
|
+
preHandler: LifecycleHookFunction[];
|
|
193
|
+
onResponse: LifecycleHookFunction[];
|
|
194
|
+
onError: LifecycleHookFunction[];
|
|
195
|
+
}
|
|
196
|
+
declare class Spikard implements SpikardApp {
|
|
197
|
+
routes: RouteMetadata[];
|
|
198
|
+
handlers: Record<string, HandlerFunction>;
|
|
199
|
+
websocketRoutes: RouteMetadata[];
|
|
200
|
+
websocketHandlers: Record<string, WebSocketHandlerLike>;
|
|
201
|
+
lifecycleHooks: LifecycleHooks;
|
|
202
|
+
dependencies: Record<string, DependencyDescriptor>;
|
|
203
|
+
addRoute(metadata: RouteMetadata, handler: HandlerFunction): void;
|
|
204
|
+
websocket(path: string, handler: WebSocketHandlerLike, options?: WebSocketOptions): void;
|
|
205
|
+
run(options?: ServerOptions): void;
|
|
206
|
+
provide(key: string, valueOrFactory: DependencyValue | DependencyFactory, options?: DependencyOptions): this;
|
|
207
|
+
onRequest(hook: LifecycleHookFunction): LifecycleHookFunction;
|
|
208
|
+
preValidation(hook: LifecycleHookFunction): LifecycleHookFunction;
|
|
209
|
+
preHandler(hook: LifecycleHookFunction): LifecycleHookFunction;
|
|
210
|
+
onResponse(hook: LifecycleHookFunction): LifecycleHookFunction;
|
|
211
|
+
onError(hook: LifecycleHookFunction): LifecycleHookFunction;
|
|
212
|
+
getLifecycleHooks(): LifecycleHooks;
|
|
213
|
+
}
|
|
214
|
+
interface WebSocketOptions {
|
|
215
|
+
handlerName?: string;
|
|
216
|
+
messageSchema?: JsonSchema;
|
|
217
|
+
responseSchema?: JsonSchema;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
declare function run(work: () => void | Promise<void>): void;
|
|
221
|
+
|
|
222
|
+
declare const background_run: typeof run;
|
|
223
|
+
declare namespace background {
|
|
224
|
+
export { background_run as run };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
type Query<T> = T;
|
|
228
|
+
type Path<T> = T;
|
|
229
|
+
type Body<T> = T;
|
|
230
|
+
declare function QueryDefault<T>(value: T): T;
|
|
231
|
+
|
|
232
|
+
interface RouteOptions {
|
|
233
|
+
methods?: string | string[];
|
|
234
|
+
bodySchema?: JsonSchema;
|
|
235
|
+
responseSchema?: JsonSchema;
|
|
236
|
+
parameterSchema?: JsonSchema;
|
|
237
|
+
cors?: CorsConfig;
|
|
238
|
+
}
|
|
239
|
+
type RouteArgument = Request$1 | JsonValue | string | number | boolean | null | undefined;
|
|
240
|
+
type RouteHandler = (...args: RouteArgument[]) => MaybePromise<HandlerResult>;
|
|
241
|
+
declare function route(path: string, options?: RouteOptions): (handler: RouteHandler) => RouteHandler;
|
|
242
|
+
declare function get(path: string, options?: Omit<RouteOptions, "methods">): (handler: RouteHandler) => RouteHandler;
|
|
243
|
+
declare function post(path: string, options?: Omit<RouteOptions, "methods">): (handler: RouteHandler) => RouteHandler;
|
|
244
|
+
declare function put(path: string, options?: Omit<RouteOptions, "methods">): (handler: RouteHandler) => RouteHandler;
|
|
245
|
+
declare function del(path: string, options?: Omit<RouteOptions, "methods">): (handler: RouteHandler) => RouteHandler;
|
|
246
|
+
declare function patch(path: string, options?: Omit<RouteOptions, "methods">): (handler: RouteHandler) => RouteHandler;
|
|
247
|
+
|
|
248
|
+
type HeaderMap = Record<string, string>;
|
|
249
|
+
interface MultipartFile {
|
|
250
|
+
name: string;
|
|
251
|
+
filename?: string;
|
|
252
|
+
content: string;
|
|
253
|
+
contentType?: string;
|
|
254
|
+
}
|
|
255
|
+
interface RequestOptions {
|
|
256
|
+
headers?: HeaderMap;
|
|
257
|
+
json?: JsonValue;
|
|
258
|
+
form?: Record<string, JsonValue> | string;
|
|
259
|
+
formRaw?: string;
|
|
260
|
+
multipart?: {
|
|
261
|
+
fields?: Record<string, JsonValue>;
|
|
262
|
+
files?: MultipartFile[];
|
|
263
|
+
};
|
|
264
|
+
binary?: string;
|
|
265
|
+
}
|
|
266
|
+
declare class TestResponse {
|
|
267
|
+
private readonly status;
|
|
268
|
+
private readonly headersMap;
|
|
269
|
+
private readonly bodyBytes;
|
|
270
|
+
private decodedBody;
|
|
271
|
+
constructor(status: number, headersMap: HeaderMap, body: Uint8Array | ArrayBuffer | ArrayLike<number>);
|
|
272
|
+
get statusCode(): number;
|
|
273
|
+
headers(): HeaderMap;
|
|
274
|
+
text(): string;
|
|
275
|
+
json(): JsonValue | string | null;
|
|
276
|
+
bytes(): Uint8Array;
|
|
277
|
+
raw(): Uint8Array;
|
|
278
|
+
private getDecodedBody;
|
|
279
|
+
private getHeaderValue;
|
|
280
|
+
}
|
|
281
|
+
declare class TestClient {
|
|
282
|
+
private readonly routes;
|
|
283
|
+
private readonly websocketRoutes;
|
|
284
|
+
readonly websocketHandlers: Record<string, WebSocketHandlerLike>;
|
|
285
|
+
private readonly nativeClientPromise;
|
|
286
|
+
constructor(app: SpikardApp);
|
|
287
|
+
get(path: string, headers?: Record<string, string>): Promise<TestResponse>;
|
|
288
|
+
delete(path: string, headers?: Record<string, string>): Promise<TestResponse>;
|
|
289
|
+
head(path: string, headers?: Record<string, string>): Promise<TestResponse>;
|
|
290
|
+
options(path: string, headers?: Record<string, string>): Promise<TestResponse>;
|
|
291
|
+
trace(path: string, headers?: Record<string, string>): Promise<TestResponse>;
|
|
292
|
+
post(path: string, options?: RequestOptions): Promise<TestResponse>;
|
|
293
|
+
put(path: string, options?: RequestOptions): Promise<TestResponse>;
|
|
294
|
+
patch(path: string, options?: RequestOptions): Promise<TestResponse>;
|
|
295
|
+
websocketConnect(path: string): Promise<WebSocketTestConnection>;
|
|
296
|
+
private responseFromNative;
|
|
297
|
+
private dispatchWithHeaders;
|
|
298
|
+
private buildNativeOptions;
|
|
299
|
+
private buildHeaders;
|
|
300
|
+
private findRoute;
|
|
301
|
+
private findWebSocketRoute;
|
|
302
|
+
}
|
|
303
|
+
declare class WebSocketTestConnection {
|
|
304
|
+
private readonly handler;
|
|
305
|
+
private readonly pending;
|
|
306
|
+
private readonly socket;
|
|
307
|
+
private closed;
|
|
308
|
+
private constructor();
|
|
309
|
+
static connect(handler: WebSocketHandlerLike): Promise<WebSocketTestConnection>;
|
|
310
|
+
sendJson(payload: JsonValue): Promise<void>;
|
|
311
|
+
sendText(payload: string): Promise<void>;
|
|
312
|
+
sendBytes(payload: BinaryLike): Promise<void>;
|
|
313
|
+
receiveJson(): Promise<JsonValue>;
|
|
314
|
+
receiveText(): Promise<string>;
|
|
315
|
+
receiveBytes(): Promise<Uint8Array>;
|
|
316
|
+
close(code?: number, reason?: string): Promise<void>;
|
|
317
|
+
private dispatchMessage;
|
|
318
|
+
private shiftMessage;
|
|
319
|
+
private ensureOpen;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
interface JsonSchema {
|
|
323
|
+
type?: string | string[];
|
|
324
|
+
properties?: Record<string, JsonSchema>;
|
|
325
|
+
required?: string[];
|
|
326
|
+
items?: JsonSchema | JsonSchema[];
|
|
327
|
+
enum?: JsonValue[];
|
|
328
|
+
[key: string]: JsonSchema | JsonSchema[] | JsonValue | JsonValue[] | string | number | boolean | undefined;
|
|
329
|
+
}
|
|
330
|
+
interface CorsConfig {
|
|
331
|
+
allow_origin?: string | string[];
|
|
332
|
+
allow_methods?: string[];
|
|
333
|
+
allow_headers?: string[];
|
|
334
|
+
allow_credentials?: boolean;
|
|
335
|
+
max_age?: number;
|
|
336
|
+
}
|
|
337
|
+
interface FileParam {
|
|
338
|
+
name: string;
|
|
339
|
+
required?: boolean;
|
|
340
|
+
max_size?: number;
|
|
341
|
+
allowed_types?: string[];
|
|
342
|
+
}
|
|
343
|
+
interface RouteMetadata {
|
|
344
|
+
method: string;
|
|
345
|
+
path: string;
|
|
346
|
+
handler_name: string;
|
|
347
|
+
handler_dependencies?: string[];
|
|
348
|
+
request_schema?: JsonSchema;
|
|
349
|
+
response_schema?: JsonSchema;
|
|
350
|
+
parameter_schema?: JsonSchema;
|
|
351
|
+
file_params?: FileParam[];
|
|
352
|
+
is_async: boolean;
|
|
353
|
+
cors?: CorsConfig;
|
|
354
|
+
}
|
|
355
|
+
interface SpikardApp {
|
|
356
|
+
routes: RouteMetadata[];
|
|
357
|
+
handlers: Record<string, HandlerFunction>;
|
|
358
|
+
websocketRoutes?: RouteMetadata[];
|
|
359
|
+
websocketHandlers?: Record<string, WebSocketHandlerLike>;
|
|
360
|
+
config?: ServerConfig;
|
|
361
|
+
lifecycleHooks?: Partial<LifecycleHooks>;
|
|
362
|
+
dependencies?: Record<string, unknown>;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export { type ApiKeyConfig, type Base64EncodedBody, type Body, type CompressionConfig, type ContactInfo, type CorsConfig, type FileParam, type HandlerFunction, type HandlerPayload, type HandlerResult, type JsonPrimitive, type JsonRecord, type JsonSchema, type JsonValue, type JwtConfig, type LicenseInfo, type LifecycleHookFunction, type LifecycleHooks, type MaybePromise, type OpenApiConfig, type Path, type Query, QueryDefault, type RateLimitConfig, type Request$1 as Request, type RouteMetadata, type RouteOptions, type SecuritySchemeInfo, type ServerConfig, type ServerInfo, type ServerOptions, Spikard, type SpikardApp, type StaticFilesConfig, StreamingResponse, type StreamingResponseInit, type StructuredHandlerResponse, TestClient, TestResponse, type WebSocketHandler, type WebSocketHandlerLike, type WebSocketServerSocket, background, createFetchHandler, del, get, patch, post, put, route, runServer };
|