@supacloud/elysia 0.18.0 → 0.19.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 +319 -0
- package/dist/command-binding.d.ts +33 -0
- package/dist/examples/fulfillment.d.ts +38 -0
- package/dist/fixtures/webhook-generated/application.d.ts +11 -1
- package/dist/http-policy-postgres.d.ts +12 -0
- package/dist/http-policy-stores.d.ts +33 -0
- package/dist/http-policy-suite.d.ts +75 -0
- package/dist/http-policy.d.ts +25 -0
- package/dist/http-response-cache.d.ts +14 -0
- package/dist/http-telemetry.d.ts +40 -0
- package/dist/index.d.ts +302 -11
- package/dist/index.js +771 -101
- package/dist/memory.d.ts +4 -3
- package/dist/schema_contract.d.ts +2 -2
- package/dist/testing.d.ts +3 -2
- package/dist/webhook-migration-example.d.ts +7 -1
- package/package.json +8 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,38 @@
|
|
|
1
|
-
import { Elysia } from "elysia";
|
|
1
|
+
import { Elysia, type AnyElysia, type InferContext, type StatusMap } from "elysia";
|
|
2
2
|
import type { CommandRuntimeAudit, CommandRuntimeAuthorizer, CommandRuntimeGovernance, CommandRuntimeInvocation, CommandRuntimeMiddleware } from "@supacloud/app";
|
|
3
3
|
import { type CommandPreview } from "@supacloud/contracts";
|
|
4
|
+
import { type HttpPolicyRegistry } from "./http-policy";
|
|
5
|
+
export { HttpPolicyConfigurationError } from "./http-policy";
|
|
6
|
+
export type { HttpPolicy, HttpPolicyContext, HttpPolicyResponseContext, HttpPolicyDeclaration, HttpPolicyRegistry } from "./http-policy";
|
|
7
|
+
export { createHttpPolicySuite } from "./http-policy-suite";
|
|
8
|
+
export type { HttpPolicySuiteOptions, BuiltinHttpPolicyDeclaration } from "./http-policy-suite";
|
|
9
|
+
export { createMemoryHttpRateLimitStore, createMemoryHttpCacheStore } from "./http-policy-stores";
|
|
10
|
+
export type { HttpRateLimitStore, HttpRateLimitResult, HttpCacheStore, HttpCacheEntry } from "./http-policy-stores";
|
|
11
|
+
export { createPostgresHttpPolicyStores, HTTP_POLICY_STORE_SQL } from "./http-policy-postgres";
|
|
12
|
+
export type { HttpPolicyDatabase } from "./http-policy-postgres";
|
|
13
|
+
export { createHttpTelemetry } from "./http-telemetry";
|
|
14
|
+
export type { HttpTelemetryEvent, HttpTelemetryObserver } from "./http-telemetry";
|
|
4
15
|
import { type ExecutionObserver } from "./execution";
|
|
5
16
|
import { type ApplicationDocumentationOptions } from "./documentation";
|
|
6
17
|
export type { ExecutionEvent, ExecutionObserver } from "./execution";
|
|
18
|
+
export { bindCompiledCommand } from "./command-binding";
|
|
19
|
+
export type { CompiledCommandBinding, CompiledCommandBindingOptions, CompiledCommandCallContext, } from "./command-binding";
|
|
7
20
|
export { createSchemaDecoder, assertResponseStatusDeclared, defineElysiaRoute, defineJsonContract, defineRouteContract, registerElysiaRoute, responseSchemaForStatus, responseStatusDeclared, responseStatusOf, SchemaContractError, toElysiaRouteSchema, } from "./schema_contract";
|
|
8
21
|
export type { ElysiaRouteContext, ElysiaRouteDefinition, ElysiaRouteHandler, ElysiaRouteSchema, ResponseMapSelector, RouteContractSchemas, SchemaDecoderOptions, SchemaNormalizeMode, } from "./schema_contract";
|
|
9
22
|
export { createPersistentCommandAdapter, type PersistentCommandHandler } from "./persistent-command";
|
|
10
23
|
export { createDocumentationPlugin } from "./documentation";
|
|
11
24
|
export type { ApplicationDocumentationOptions, DocumentationSource, GraphqlDocumentationOptions, OpenApiDocumentationOptions, } from "./documentation";
|
|
12
25
|
export interface CompiledRoute {
|
|
26
|
+
parse?: "none";
|
|
27
|
+
allowDeleteBody?: true;
|
|
28
|
+
/** Compiler-emitted route title, exposed as the OpenAPI operation summary. */
|
|
29
|
+
title?: string;
|
|
13
30
|
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
14
31
|
path: string;
|
|
15
32
|
/** Method name on the controller instance. */
|
|
16
33
|
handler: string;
|
|
34
|
+
/** Static metadata preserved by the compiler; HTTP policies are adapter-owned. */
|
|
35
|
+
data?: Record<string, unknown>;
|
|
17
36
|
/** TypeBox schema; validation is enabled only when the field is present. */
|
|
18
37
|
body?: unknown;
|
|
19
38
|
params?: unknown;
|
|
@@ -217,7 +236,73 @@ export interface ErrorContext {
|
|
|
217
236
|
frameworkCode: string | number | undefined;
|
|
218
237
|
}
|
|
219
238
|
export type ErrorMapper = (error: unknown, context: ErrorContext) => Response | undefined | Promise<Response | undefined>;
|
|
220
|
-
|
|
239
|
+
declare function mountHttp<const Http extends AnyElysia = Elysia>(http?: Http, name?: string, normalize?: boolean): Elysia<"", {
|
|
240
|
+
decorator: {} & Http["~Singleton"]["decorator"];
|
|
241
|
+
store: ({} & Http["~Singleton"]["store"] extends infer T_1 ? { [K_1 in keyof T_1]: T_1[K_1]; } : never) extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
242
|
+
derive: {} & Http["~Singleton"]["derive"];
|
|
243
|
+
resolve: {} & Http["~Singleton"]["resolve"];
|
|
244
|
+
}, {
|
|
245
|
+
typebox: {};
|
|
246
|
+
error: {};
|
|
247
|
+
} & Http["~Definitions"], {
|
|
248
|
+
schema: {};
|
|
249
|
+
standaloneSchema: {};
|
|
250
|
+
macro: {};
|
|
251
|
+
macroFn: {};
|
|
252
|
+
parser: {};
|
|
253
|
+
response: {};
|
|
254
|
+
} & Http["~Metadata"], {} & Http["~Routes"], {
|
|
255
|
+
derive: {};
|
|
256
|
+
resolve: {};
|
|
257
|
+
schema: {};
|
|
258
|
+
standaloneSchema: {};
|
|
259
|
+
response: {};
|
|
260
|
+
}, {
|
|
261
|
+
derive: {};
|
|
262
|
+
resolve: {};
|
|
263
|
+
schema: {};
|
|
264
|
+
standaloneSchema: {};
|
|
265
|
+
response: {};
|
|
266
|
+
} & {
|
|
267
|
+
derive: {} & ({
|
|
268
|
+
derive: {};
|
|
269
|
+
resolve: {};
|
|
270
|
+
schema: {};
|
|
271
|
+
standaloneSchema: {};
|
|
272
|
+
response: {};
|
|
273
|
+
} & Http["~Ephemeral"])["derive"];
|
|
274
|
+
resolve: {} & ({
|
|
275
|
+
derive: {};
|
|
276
|
+
resolve: {};
|
|
277
|
+
schema: {};
|
|
278
|
+
standaloneSchema: {};
|
|
279
|
+
response: {};
|
|
280
|
+
} & Http["~Ephemeral"])["resolve"];
|
|
281
|
+
schema: import("elysia").MergeSchema<({
|
|
282
|
+
derive: {};
|
|
283
|
+
resolve: {};
|
|
284
|
+
schema: {};
|
|
285
|
+
standaloneSchema: {};
|
|
286
|
+
response: {};
|
|
287
|
+
} & Http["~Ephemeral"])["schema"], {}, "">;
|
|
288
|
+
standaloneSchema: ({
|
|
289
|
+
derive: {};
|
|
290
|
+
resolve: {};
|
|
291
|
+
schema: {};
|
|
292
|
+
standaloneSchema: {};
|
|
293
|
+
response: {};
|
|
294
|
+
} & Http["~Ephemeral"])["standaloneSchema"] & {};
|
|
295
|
+
response: ({
|
|
296
|
+
derive: {};
|
|
297
|
+
resolve: {};
|
|
298
|
+
schema: {};
|
|
299
|
+
standaloneSchema: {};
|
|
300
|
+
response: {};
|
|
301
|
+
} & Http["~Ephemeral"])["response"] & {};
|
|
302
|
+
}>;
|
|
303
|
+
export type ApplicationHttpContext<Http extends AnyElysia = Elysia> = Omit<InferContext<ReturnType<typeof mountHttp<Http>>>, "body" | "params" | "query" | "headers" | "cookie"> & Pick<HttpContext, "body" | "params" | "query" | "headers" | "cookie">;
|
|
304
|
+
export type HttpRequestContextFactory<Http extends AnyElysia = Elysia, Value = unknown> = (request: Request, context: ApplicationHttpContext<Http>) => Value | Promise<Value>;
|
|
305
|
+
export interface ApplicationOptions<Http extends AnyElysia = Elysia, RequestContext = unknown> {
|
|
221
306
|
name?: string;
|
|
222
307
|
/** false rejects extra schema properties instead of silently removing them. */
|
|
223
308
|
normalize?: boolean;
|
|
@@ -225,8 +310,12 @@ export interface ApplicationOptions {
|
|
|
225
310
|
modules?: CompiledModule[];
|
|
226
311
|
/** Platform-level dependencies (db client etc.), passed to createServices. */
|
|
227
312
|
deps?: Record<string, unknown>;
|
|
228
|
-
/**
|
|
229
|
-
|
|
313
|
+
/** Native plugin. Use scoped/global derive/resolve hooks to extend compiled routes. */
|
|
314
|
+
http?: Http;
|
|
315
|
+
/** Startup-compiled policies selected by route.data.httpPolicies, in declaration order. */
|
|
316
|
+
httpPolicies?: HttpPolicyRegistry<Http>;
|
|
317
|
+
/** Runs after validation and HTTP resolvers, with the validated native context. */
|
|
318
|
+
requestContext?: HttpRequestContextFactory<Http, RequestContext>;
|
|
230
319
|
/** Enforces permission/audit/idempotency policy for command-bound routes. */
|
|
231
320
|
commandGovernance?: CommandGovernance;
|
|
232
321
|
/** Optional custom or composed executor. When provided alongside commandGovernance, it wraps or composes with governance. */
|
|
@@ -286,15 +375,91 @@ export declare function previewCompiledCommand<Input>(options: {
|
|
|
286
375
|
}): Promise<CommandPreview>;
|
|
287
376
|
export declare function requireTrustedIdentity(requestContext: unknown): Required<Pick<TrustedRequestIdentity, "subject" | "accessToken">> & TrustedRequestIdentity;
|
|
288
377
|
export declare function requireIdempotencyKey(invocation: CommandInvocation): string;
|
|
378
|
+
interface HttpContext {
|
|
379
|
+
body: unknown;
|
|
380
|
+
params: Record<string, unknown>;
|
|
381
|
+
query: Record<string, unknown>;
|
|
382
|
+
headers?: Record<string, unknown>;
|
|
383
|
+
cookie?: Record<string, unknown>;
|
|
384
|
+
request: Request;
|
|
385
|
+
set: {
|
|
386
|
+
status?: number | keyof StatusMap;
|
|
387
|
+
};
|
|
388
|
+
scope?: Record<string, unknown>;
|
|
389
|
+
requestContext?: unknown;
|
|
390
|
+
}
|
|
289
391
|
/**
|
|
290
392
|
* Adapt a single compiled module into an Elysia plugin.
|
|
291
393
|
*
|
|
292
|
-
* The plugin
|
|
293
|
-
* `createRequestScope`, a fresh
|
|
294
|
-
*
|
|
295
|
-
* looked up on
|
|
394
|
+
* The plugin resolves module-local `services`; when the module defines
|
|
395
|
+
* `createRequestScope`, a fresh scope is created inside the governed handler
|
|
396
|
+
* and passed to the controller input as `scope`. Request-scoped controllers
|
|
397
|
+
* are looked up on that scope, everything else on `services`.
|
|
296
398
|
*/
|
|
297
|
-
export declare function createModulePlugin(compiled: CompiledModule, services:
|
|
399
|
+
export declare function createModulePlugin<const Services extends Record<string, unknown>, const Http extends AnyElysia = Elysia>(compiled: CompiledModule, services: Services, ctxFactory?: HttpRequestContextFactory<Http>, options?: Pick<ApplicationOptions<Http>, "http" | "httpPolicies" | "commandGovernance" | "commandExecutor" | "errorMapper" | "onExecution" | "normalize">, imported?: Record<string, Record<string, unknown>>): Elysia<"", {
|
|
400
|
+
decorator: {} & Http["~Singleton"]["decorator"];
|
|
401
|
+
store: ({} & Http["~Singleton"]["store"] extends infer T_1 ? { [K_1 in keyof T_1]: T_1[K_1]; } : never) extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
402
|
+
derive: {} & Http["~Singleton"]["derive"];
|
|
403
|
+
resolve: {} & Http["~Singleton"]["resolve"];
|
|
404
|
+
}, {
|
|
405
|
+
typebox: {};
|
|
406
|
+
error: {};
|
|
407
|
+
} & Http["~Definitions"], {
|
|
408
|
+
schema: {};
|
|
409
|
+
standaloneSchema: {};
|
|
410
|
+
macro: {};
|
|
411
|
+
macroFn: {};
|
|
412
|
+
parser: {};
|
|
413
|
+
response: {};
|
|
414
|
+
} & Http["~Metadata"], {} & Http["~Routes"], {
|
|
415
|
+
derive: {};
|
|
416
|
+
resolve: {};
|
|
417
|
+
schema: {};
|
|
418
|
+
standaloneSchema: {};
|
|
419
|
+
response: {};
|
|
420
|
+
}, {
|
|
421
|
+
derive: {} & ({
|
|
422
|
+
derive: {};
|
|
423
|
+
resolve: {};
|
|
424
|
+
schema: {};
|
|
425
|
+
standaloneSchema: {};
|
|
426
|
+
response: {};
|
|
427
|
+
} & Http["~Ephemeral"])["derive"];
|
|
428
|
+
resolve: ({
|
|
429
|
+
derive: {};
|
|
430
|
+
resolve: {};
|
|
431
|
+
schema: {};
|
|
432
|
+
standaloneSchema: {};
|
|
433
|
+
response: {};
|
|
434
|
+
} & Http["~Ephemeral"])["resolve"] & {
|
|
435
|
+
readonly services: Services;
|
|
436
|
+
readonly requestContext: unknown;
|
|
437
|
+
};
|
|
438
|
+
schema: {} & import("elysia").MergeSchema<({
|
|
439
|
+
derive: {};
|
|
440
|
+
resolve: {};
|
|
441
|
+
schema: {};
|
|
442
|
+
standaloneSchema: {};
|
|
443
|
+
response: {};
|
|
444
|
+
} & Http["~Ephemeral"])["schema"], {}, "">;
|
|
445
|
+
standaloneSchema: {} & ({
|
|
446
|
+
derive: {};
|
|
447
|
+
resolve: {};
|
|
448
|
+
schema: {};
|
|
449
|
+
standaloneSchema: {};
|
|
450
|
+
response: {};
|
|
451
|
+
} & Http["~Ephemeral"])["standaloneSchema"];
|
|
452
|
+
response: import("elysia/types").UnionResponseStatus<{} & ({
|
|
453
|
+
derive: {};
|
|
454
|
+
resolve: {};
|
|
455
|
+
schema: {};
|
|
456
|
+
standaloneSchema: {};
|
|
457
|
+
response: {};
|
|
458
|
+
} & Http["~Ephemeral"])["response"], import("elysia").ExtractErrorFromHandle<{
|
|
459
|
+
readonly services: Services;
|
|
460
|
+
readonly requestContext: unknown;
|
|
461
|
+
}>>;
|
|
462
|
+
}>;
|
|
298
463
|
/**
|
|
299
464
|
* Execute one compiler-emitted Job descriptor.
|
|
300
465
|
*
|
|
@@ -311,9 +476,135 @@ export declare function defaultErrorResponse(error: unknown, frameworkCode?: str
|
|
|
311
476
|
* `createServices` receives `deps` plus the services of all previously
|
|
312
477
|
* created modules, keyed by module name.
|
|
313
478
|
*/
|
|
314
|
-
export declare function createApplication(options: ApplicationOptions): Elysia
|
|
479
|
+
export declare function createApplication<const Http extends AnyElysia = Elysia>(options: ApplicationOptions<Http>): Elysia<"", {
|
|
480
|
+
decorator: {} & Http["~Singleton"]["decorator"];
|
|
481
|
+
store: ({} & Http["~Singleton"]["store"] extends infer T_1 ? { [K_1 in keyof T_1]: T_1[K_1]; } : never) extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
482
|
+
derive: {} & Http["~Singleton"]["derive"];
|
|
483
|
+
resolve: {} & Http["~Singleton"]["resolve"];
|
|
484
|
+
}, {
|
|
485
|
+
typebox: {};
|
|
486
|
+
error: {};
|
|
487
|
+
} & Http["~Definitions"], {
|
|
488
|
+
schema: {};
|
|
489
|
+
standaloneSchema: {};
|
|
490
|
+
macro: {};
|
|
491
|
+
macroFn: {};
|
|
492
|
+
parser: {};
|
|
493
|
+
response: {};
|
|
494
|
+
} & Http["~Metadata"], {} & Http["~Routes"], {
|
|
495
|
+
derive: {};
|
|
496
|
+
resolve: {};
|
|
497
|
+
schema: {};
|
|
498
|
+
standaloneSchema: {};
|
|
499
|
+
response: {};
|
|
500
|
+
}, {
|
|
501
|
+
derive: {};
|
|
502
|
+
resolve: {};
|
|
503
|
+
schema: {};
|
|
504
|
+
standaloneSchema: {};
|
|
505
|
+
response: {};
|
|
506
|
+
} & {
|
|
507
|
+
derive: {} & ({
|
|
508
|
+
derive: {};
|
|
509
|
+
resolve: {};
|
|
510
|
+
schema: {};
|
|
511
|
+
standaloneSchema: {};
|
|
512
|
+
response: {};
|
|
513
|
+
} & Http["~Ephemeral"])["derive"];
|
|
514
|
+
resolve: {} & ({
|
|
515
|
+
derive: {};
|
|
516
|
+
resolve: {};
|
|
517
|
+
schema: {};
|
|
518
|
+
standaloneSchema: {};
|
|
519
|
+
response: {};
|
|
520
|
+
} & Http["~Ephemeral"])["resolve"];
|
|
521
|
+
schema: import("elysia").MergeSchema<({
|
|
522
|
+
derive: {};
|
|
523
|
+
resolve: {};
|
|
524
|
+
schema: {};
|
|
525
|
+
standaloneSchema: {};
|
|
526
|
+
response: {};
|
|
527
|
+
} & Http["~Ephemeral"])["schema"], {}, "">;
|
|
528
|
+
standaloneSchema: ({
|
|
529
|
+
derive: {};
|
|
530
|
+
resolve: {};
|
|
531
|
+
schema: {};
|
|
532
|
+
standaloneSchema: {};
|
|
533
|
+
response: {};
|
|
534
|
+
} & Http["~Ephemeral"])["standaloneSchema"] & {};
|
|
535
|
+
response: ({
|
|
536
|
+
derive: {};
|
|
537
|
+
resolve: {};
|
|
538
|
+
schema: {};
|
|
539
|
+
standaloneSchema: {};
|
|
540
|
+
response: {};
|
|
541
|
+
} & Http["~Ephemeral"])["response"] & {};
|
|
542
|
+
}>;
|
|
315
543
|
/** Semantic alias of createApplication for readable tests. */
|
|
316
|
-
export declare function createTestApp(options: ApplicationOptions): Elysia
|
|
544
|
+
export declare function createTestApp<const Http extends AnyElysia = Elysia>(options: ApplicationOptions<Http>): Elysia<"", {
|
|
545
|
+
decorator: {} & Http["~Singleton"]["decorator"];
|
|
546
|
+
store: ({} & Http["~Singleton"]["store"] extends infer T_1 ? { [K_1 in keyof T_1]: T_1[K_1]; } : never) extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
547
|
+
derive: {} & Http["~Singleton"]["derive"];
|
|
548
|
+
resolve: {} & Http["~Singleton"]["resolve"];
|
|
549
|
+
}, {
|
|
550
|
+
typebox: {};
|
|
551
|
+
error: {};
|
|
552
|
+
} & Http["~Definitions"], {
|
|
553
|
+
schema: {};
|
|
554
|
+
standaloneSchema: {};
|
|
555
|
+
macro: {};
|
|
556
|
+
macroFn: {};
|
|
557
|
+
parser: {};
|
|
558
|
+
response: {};
|
|
559
|
+
} & Http["~Metadata"], {} & Http["~Routes"], {
|
|
560
|
+
derive: {};
|
|
561
|
+
resolve: {};
|
|
562
|
+
schema: {};
|
|
563
|
+
standaloneSchema: {};
|
|
564
|
+
response: {};
|
|
565
|
+
}, {
|
|
566
|
+
derive: {};
|
|
567
|
+
resolve: {};
|
|
568
|
+
schema: {};
|
|
569
|
+
standaloneSchema: {};
|
|
570
|
+
response: {};
|
|
571
|
+
} & {
|
|
572
|
+
derive: {} & ({
|
|
573
|
+
derive: {};
|
|
574
|
+
resolve: {};
|
|
575
|
+
schema: {};
|
|
576
|
+
standaloneSchema: {};
|
|
577
|
+
response: {};
|
|
578
|
+
} & Http["~Ephemeral"])["derive"];
|
|
579
|
+
resolve: {} & ({
|
|
580
|
+
derive: {};
|
|
581
|
+
resolve: {};
|
|
582
|
+
schema: {};
|
|
583
|
+
standaloneSchema: {};
|
|
584
|
+
response: {};
|
|
585
|
+
} & Http["~Ephemeral"])["resolve"];
|
|
586
|
+
schema: import("elysia").MergeSchema<({
|
|
587
|
+
derive: {};
|
|
588
|
+
resolve: {};
|
|
589
|
+
schema: {};
|
|
590
|
+
standaloneSchema: {};
|
|
591
|
+
response: {};
|
|
592
|
+
} & Http["~Ephemeral"])["schema"], {}, "">;
|
|
593
|
+
standaloneSchema: ({
|
|
594
|
+
derive: {};
|
|
595
|
+
resolve: {};
|
|
596
|
+
schema: {};
|
|
597
|
+
standaloneSchema: {};
|
|
598
|
+
response: {};
|
|
599
|
+
} & Http["~Ephemeral"])["standaloneSchema"] & {};
|
|
600
|
+
response: ({
|
|
601
|
+
derive: {};
|
|
602
|
+
resolve: {};
|
|
603
|
+
schema: {};
|
|
604
|
+
standaloneSchema: {};
|
|
605
|
+
response: {};
|
|
606
|
+
} & Http["~Ephemeral"])["response"] & {};
|
|
607
|
+
}>;
|
|
317
608
|
export { createMemorySandbox, } from "./memory";
|
|
318
609
|
export type { HandleLike as MemoryHandleLike, MemoryDatabase, MemorySandbox, MemorySandboxOptions, MemoryStorage, MemoryStorageObject, } from "./memory";
|
|
319
610
|
export { createMemoryPolicy } from "./memory_policy";
|