@supacloud/elysia 0.18.0 → 0.20.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/compatibility.json +1 -1
- package/dist/command-binding.d.ts +33 -0
- package/dist/examples/fulfillment.d.ts +38 -0
- package/dist/fixtures/webhook/contracts.d.ts +31 -31
- 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 +51 -0
- package/dist/http-policy.d.ts +27 -0
- package/dist/http-response-cache.d.ts +14 -0
- package/dist/http-telemetry.d.ts +27 -0
- package/dist/index.d.ts +112 -11
- package/dist/index.js +817 -120
- package/dist/memory.d.ts +4 -3
- package/dist/schema_contract.d.ts +19 -12
- package/dist/testing.d.ts +3 -2
- package/dist/webhook-migration-example.d.ts +8 -15
- package/package.json +16 -11
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SupAuthRequestContext } from "./identity";
|
|
2
|
+
import type { HttpPolicy } from "./http-policy";
|
|
3
|
+
import type { HttpCacheStore } from "./http-policy-stores";
|
|
4
|
+
interface CachePolicyOptions {
|
|
5
|
+
store: HttpCacheStore;
|
|
6
|
+
requireAccess(request: Request): SupAuthRequestContext;
|
|
7
|
+
ttlMs: number;
|
|
8
|
+
maxBodyBytes: number;
|
|
9
|
+
route: string;
|
|
10
|
+
namespace: string;
|
|
11
|
+
onWriteError(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function createCachePolicy(options: CachePolicyOptions): HttpPolicy;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Elysia } from "elysia";
|
|
2
|
+
export declare function httpRequestId(request: Request): string | undefined;
|
|
3
|
+
export interface HttpTelemetryEvent {
|
|
4
|
+
requestId: string;
|
|
5
|
+
method: string;
|
|
6
|
+
/** Static route template only. Query strings and concrete paths are excluded. */
|
|
7
|
+
route: string;
|
|
8
|
+
status: number;
|
|
9
|
+
durationMs: number;
|
|
10
|
+
}
|
|
11
|
+
export type HttpTelemetryObserver = (event: Readonly<HttpTelemetryEvent>) => void | Promise<void>;
|
|
12
|
+
/** Request tracing is best effort, not a durable business audit. */
|
|
13
|
+
export declare function createHttpTelemetry(observe: HttpTelemetryObserver): Elysia<"", "local", {
|
|
14
|
+
decorator: {};
|
|
15
|
+
store: {};
|
|
16
|
+
derive: {};
|
|
17
|
+
}, {
|
|
18
|
+
typebox: {};
|
|
19
|
+
error: [];
|
|
20
|
+
}, {
|
|
21
|
+
schema: {};
|
|
22
|
+
schemas: {};
|
|
23
|
+
macro: {};
|
|
24
|
+
macroFn: {};
|
|
25
|
+
parser: {};
|
|
26
|
+
response: {};
|
|
27
|
+
}, {}, import("elysia").DefaultEphemeral, import("elysia").DefaultEphemeral>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,38 @@
|
|
|
1
|
-
import { Elysia } from "elysia";
|
|
1
|
+
import { Elysia, type AnyElysia, type Context, 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,13 @@ 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
|
-
export
|
|
239
|
+
export type ApplicationHttpContext<Http extends AnyElysia = Elysia> = Omit<Context<{}, {
|
|
240
|
+
decorator: Http["~Singleton"]["decorator"];
|
|
241
|
+
store: Http["~Singleton"]["store"];
|
|
242
|
+
derive: Http["~Singleton"]["derive"] & Http["~Ephemeral"]["derive"];
|
|
243
|
+
}>, "body" | "params" | "query" | "headers" | "cookie"> & Pick<HttpContext, "body" | "params" | "query" | "headers" | "cookie">;
|
|
244
|
+
export type HttpRequestContextFactory<Http extends AnyElysia = Elysia, Value = unknown> = (request: Request, context: ApplicationHttpContext<Http>) => Value | Promise<Value>;
|
|
245
|
+
export interface ApplicationOptions<Http extends AnyElysia = Elysia, RequestContext = unknown> {
|
|
221
246
|
name?: string;
|
|
222
247
|
/** false rejects extra schema properties instead of silently removing them. */
|
|
223
248
|
normalize?: boolean;
|
|
@@ -225,8 +250,12 @@ export interface ApplicationOptions {
|
|
|
225
250
|
modules?: CompiledModule[];
|
|
226
251
|
/** Platform-level dependencies (db client etc.), passed to createServices. */
|
|
227
252
|
deps?: Record<string, unknown>;
|
|
228
|
-
/**
|
|
229
|
-
|
|
253
|
+
/** Native plugin. Use scoped/global derive/resolve hooks to extend compiled routes. */
|
|
254
|
+
http?: Http;
|
|
255
|
+
/** Startup-compiled policies selected by route.data.httpPolicies, in declaration order. */
|
|
256
|
+
httpPolicies?: HttpPolicyRegistry<Http>;
|
|
257
|
+
/** Runs after validation and HTTP resolvers, with the validated native context. */
|
|
258
|
+
requestContext?: HttpRequestContextFactory<Http, RequestContext>;
|
|
230
259
|
/** Enforces permission/audit/idempotency policy for command-bound routes. */
|
|
231
260
|
commandGovernance?: CommandGovernance;
|
|
232
261
|
/** Optional custom or composed executor. When provided alongside commandGovernance, it wraps or composes with governance. */
|
|
@@ -286,15 +315,47 @@ export declare function previewCompiledCommand<Input>(options: {
|
|
|
286
315
|
}): Promise<CommandPreview>;
|
|
287
316
|
export declare function requireTrustedIdentity(requestContext: unknown): Required<Pick<TrustedRequestIdentity, "subject" | "accessToken">> & TrustedRequestIdentity;
|
|
288
317
|
export declare function requireIdempotencyKey(invocation: CommandInvocation): string;
|
|
318
|
+
interface HttpContext {
|
|
319
|
+
body: unknown;
|
|
320
|
+
params: Record<string, unknown>;
|
|
321
|
+
query: Record<string, unknown>;
|
|
322
|
+
headers?: Record<string, unknown>;
|
|
323
|
+
cookie?: Record<string, unknown>;
|
|
324
|
+
request: Request;
|
|
325
|
+
set: {
|
|
326
|
+
status?: number | keyof StatusMap;
|
|
327
|
+
};
|
|
328
|
+
scope?: Record<string, unknown>;
|
|
329
|
+
requestContext?: unknown;
|
|
330
|
+
}
|
|
289
331
|
/**
|
|
290
332
|
* Adapt a single compiled module into an Elysia plugin.
|
|
291
333
|
*
|
|
292
|
-
* The plugin
|
|
293
|
-
* `createRequestScope`, a fresh
|
|
294
|
-
*
|
|
295
|
-
* looked up on
|
|
334
|
+
* The plugin resolves module-local `services`; when the module defines
|
|
335
|
+
* `createRequestScope`, a fresh scope is created inside the governed handler
|
|
336
|
+
* and passed to the controller input as `scope`. Request-scoped controllers
|
|
337
|
+
* are looked up on that scope, everything else on `services`.
|
|
296
338
|
*/
|
|
297
|
-
export declare function createModulePlugin(compiled: CompiledModule, services:
|
|
339
|
+
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>>): import("elysia/types").LocalHookReturn<"", "local", {
|
|
340
|
+
decorator: {} & Http["~Singleton"]["decorator"];
|
|
341
|
+
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;
|
|
342
|
+
derive: {} & Http["~Singleton"]["derive"];
|
|
343
|
+
}, {
|
|
344
|
+
typebox: {} & Http["~Definitions"]["typebox"];
|
|
345
|
+
error: [...Http["~Definitions"]["error"]];
|
|
346
|
+
}, import("elysia").DefaultMetadata & Http["~Metadata"], import("elysia/types").ResolveRouteErrors<{}, [...Http["~Definitions"]["error"], ...Http["~Ephemeral"]["error"]]> & Http["~Routes"], import("elysia").DefaultEphemeral, {
|
|
347
|
+
derive: {} & Http["~Ephemeral"]["derive"];
|
|
348
|
+
schema: {} & import("elysia/types").MergeSchema<{} & Http["~Ephemeral"]["schema"], {}, "", false>;
|
|
349
|
+
schemas: {} & Http["~Ephemeral"]["schemas"];
|
|
350
|
+
response: {} & Http["~Ephemeral"]["response"];
|
|
351
|
+
error: [...Http["~Ephemeral"]["error"]];
|
|
352
|
+
}, import("elysia/types").ExtractErrorFromHandle<{
|
|
353
|
+
readonly services: Services;
|
|
354
|
+
readonly requestContext: unknown;
|
|
355
|
+
}>, {
|
|
356
|
+
readonly services: Services;
|
|
357
|
+
readonly requestContext: unknown;
|
|
358
|
+
}>;
|
|
298
359
|
/**
|
|
299
360
|
* Execute one compiler-emitted Job descriptor.
|
|
300
361
|
*
|
|
@@ -311,9 +372,49 @@ export declare function defaultErrorResponse(error: unknown, frameworkCode?: str
|
|
|
311
372
|
* `createServices` receives `deps` plus the services of all previously
|
|
312
373
|
* created modules, keyed by module name.
|
|
313
374
|
*/
|
|
314
|
-
export declare function createApplication(options: ApplicationOptions): Elysia
|
|
375
|
+
export declare function createApplication<const Http extends AnyElysia = Elysia>(options: ApplicationOptions<Http>): Elysia<"", "local", {
|
|
376
|
+
decorator: {} & Http["~Singleton"]["decorator"];
|
|
377
|
+
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;
|
|
378
|
+
derive: {} & Http["~Singleton"]["derive"] & Http["~Ephemeral"]["derive"];
|
|
379
|
+
}, {
|
|
380
|
+
typebox: {} & Http["~Definitions"]["typebox"];
|
|
381
|
+
error: [...Http["~Definitions"]["error"], ...Http["~Ephemeral"]["error"]];
|
|
382
|
+
}, import("elysia").DefaultMetadata & {
|
|
383
|
+
schema: import("elysia/types").MergeSchema<import("elysia/types").MergeSchema<{} & Http["~Ephemeral"]["schema"], {}, "", false>, (import("elysia").DefaultMetadata & Http["~Metadata"])["schema"], "", false>;
|
|
384
|
+
schemas: (import("elysia").DefaultMetadata & Http["~Metadata"])["schemas"] & {} & Http["~Ephemeral"]["schemas"];
|
|
385
|
+
macro: (import("elysia").DefaultMetadata & Http["~Metadata"])["macro"];
|
|
386
|
+
macroFn: (import("elysia").DefaultMetadata & Http["~Metadata"])["macroFn"];
|
|
387
|
+
parser: (import("elysia").DefaultMetadata & Http["~Metadata"])["parser"];
|
|
388
|
+
response: import("elysia/types").UnionResponseStatus<(import("elysia").DefaultMetadata & Http["~Metadata"])["response"], import("elysia/types").UnionResponseStatus<{} & Http["~Ephemeral"]["response"], {}>>;
|
|
389
|
+
}, import("elysia/types").ResolveRouteErrors<{}, [...Http["~Definitions"]["error"], ...Http["~Ephemeral"]["error"]]> & Http["~Routes"], import("elysia").DefaultEphemeral, {
|
|
390
|
+
derive: {};
|
|
391
|
+
schema: {};
|
|
392
|
+
schemas: {};
|
|
393
|
+
response: {};
|
|
394
|
+
error: [];
|
|
395
|
+
}>;
|
|
315
396
|
/** Semantic alias of createApplication for readable tests. */
|
|
316
|
-
export declare function createTestApp(options: ApplicationOptions): Elysia
|
|
397
|
+
export declare function createTestApp<const Http extends AnyElysia = Elysia>(options: ApplicationOptions<Http>): Elysia<"", "local", {
|
|
398
|
+
decorator: {} & Http["~Singleton"]["decorator"];
|
|
399
|
+
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;
|
|
400
|
+
derive: {} & Http["~Singleton"]["derive"] & Http["~Ephemeral"]["derive"];
|
|
401
|
+
}, {
|
|
402
|
+
typebox: {} & Http["~Definitions"]["typebox"];
|
|
403
|
+
error: [...Http["~Definitions"]["error"], ...Http["~Ephemeral"]["error"]];
|
|
404
|
+
}, import("elysia").DefaultMetadata & {
|
|
405
|
+
schema: import("elysia/types").MergeSchema<import("elysia/types").MergeSchema<{} & Http["~Ephemeral"]["schema"], {}, "", false>, (import("elysia").DefaultMetadata & Http["~Metadata"])["schema"], "", false>;
|
|
406
|
+
schemas: (import("elysia").DefaultMetadata & Http["~Metadata"])["schemas"] & {} & Http["~Ephemeral"]["schemas"];
|
|
407
|
+
macro: (import("elysia").DefaultMetadata & Http["~Metadata"])["macro"];
|
|
408
|
+
macroFn: (import("elysia").DefaultMetadata & Http["~Metadata"])["macroFn"];
|
|
409
|
+
parser: (import("elysia").DefaultMetadata & Http["~Metadata"])["parser"];
|
|
410
|
+
response: import("elysia/types").UnionResponseStatus<(import("elysia").DefaultMetadata & Http["~Metadata"])["response"], import("elysia/types").UnionResponseStatus<{} & Http["~Ephemeral"]["response"], {}>>;
|
|
411
|
+
}, import("elysia/types").ResolveRouteErrors<{}, [...Http["~Definitions"]["error"], ...Http["~Ephemeral"]["error"]]> & Http["~Routes"], import("elysia").DefaultEphemeral, {
|
|
412
|
+
derive: {};
|
|
413
|
+
schema: {};
|
|
414
|
+
schemas: {};
|
|
415
|
+
response: {};
|
|
416
|
+
error: [];
|
|
417
|
+
}>;
|
|
317
418
|
export { createMemorySandbox, } from "./memory";
|
|
318
419
|
export type { HandleLike as MemoryHandleLike, MemoryDatabase, MemorySandbox, MemorySandboxOptions, MemoryStorage, MemoryStorageObject, } from "./memory";
|
|
319
420
|
export { createMemoryPolicy } from "./memory_policy";
|