@supacloud/elysia 0.9.0 → 0.14.1

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/dist/index.d.ts CHANGED
@@ -1,4 +1,14 @@
1
1
  import { Elysia } from "elysia";
2
+ import { type CommandPreview } from "@supacloud/contracts";
3
+ import { type EnvironmentInjector } from "@supacloud/app";
4
+ import { type ExecutionObserver } from "./execution";
5
+ import { type ApplicationDocumentationOptions } from "./documentation";
6
+ export type { ExecutionEvent, ExecutionObserver } from "./execution";
7
+ export { createSchemaDecoder, assertResponseStatusDeclared, defineElysiaRoute, defineJsonContract, defineRouteContract, registerElysiaRoute, responseSchemaForStatus, responseStatusDeclared, responseStatusOf, SchemaContractError, toElysiaRouteSchema, } from "./schema_contract";
8
+ export type { ElysiaRouteContext, ElysiaRouteDefinition, ElysiaRouteHandler, ElysiaRouteSchema, ResponseMapSelector, RouteContractSchemas, SchemaDecoderOptions, SchemaNormalizeMode, } from "./schema_contract";
9
+ export { createPersistentCommandAdapter, type PersistentCommandHandler } from "./persistent-command";
10
+ export { createDocumentationPlugin } from "./documentation";
11
+ export type { ApplicationDocumentationOptions, DocumentationSource, GraphqlDocumentationOptions, OpenApiDocumentationOptions, } from "./documentation";
2
12
  export interface CompiledRoute {
3
13
  method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
4
14
  path: string;
@@ -8,13 +18,28 @@ export interface CompiledRoute {
8
18
  body?: unknown;
9
19
  params?: unknown;
10
20
  query?: unknown;
21
+ headers?: unknown;
22
+ cookie?: unknown;
23
+ /** @deprecated Use `responses` with an explicit HTTP status map. */
11
24
  response?: unknown;
25
+ responses?: Record<string | number, unknown>;
26
+ /** Compile-time ownership and transport classification for the route boundary. */
27
+ contract?: {
28
+ body?: "framework" | "domain";
29
+ response?: "framework" | "native-json" | "binary" | "stream";
30
+ evidence?: string;
31
+ };
32
+ /** Whether each declared schema is concrete or intentionally opaque. */
33
+ schemaKinds?: Partial<Record<"body" | "params" | "query" | "headers" | "cookie" | "response", "opaque" | "declared">>;
34
+ /** True when the handler returns a native Response rather than a framework value. */
35
+ nativeResponse?: boolean;
12
36
  /** Compiler-emitted positional invoker; used when available. */
13
37
  invoker?: (controller: unknown, request: {
14
38
  params?: Record<string, unknown>;
15
39
  query?: Record<string, unknown>;
16
40
  body?: unknown;
17
41
  headers?: Record<string, unknown>;
42
+ cookie?: Record<string, unknown>;
18
43
  context?: unknown;
19
44
  }) => Promise<unknown> | unknown;
20
45
  /** Class name of the @Command explicitly bound to this route. */
@@ -23,6 +48,7 @@ export interface CompiledRoute {
23
48
  aspects?: ApplicationAspect[];
24
49
  }
25
50
  export interface CompiledCommand {
51
+ rpc?: string;
26
52
  className: string;
27
53
  name: string;
28
54
  permission?: string;
@@ -37,6 +63,14 @@ export interface CompiledJob {
37
63
  name: string;
38
64
  serviceKey: string;
39
65
  scope: "application" | "request" | "job";
66
+ /** TypeBox input schema emitted by the compiler. */
67
+ input?: unknown;
68
+ /** TypeBox output schema emitted by the compiler. */
69
+ output?: unknown;
70
+ mode?: "task" | "workflow";
71
+ timeoutSec?: number;
72
+ maxAttempts?: number;
73
+ idempotency?: "required" | "none";
40
74
  aspects?: ApplicationAspect[];
41
75
  }
42
76
  export interface CompiledController {
@@ -61,6 +95,8 @@ export interface CompiledModule {
61
95
  aspects?: ApplicationAspect[];
62
96
  }
63
97
  export type RequestContextFactory = (request: Request) => unknown | Promise<unknown>;
98
+ export { createSupAuthRequestContext } from "./identity";
99
+ export type { SupAuthIdentity, SupAuthAccess, SupAuthRequestContext, SupAuthContextOptions } from "./identity";
64
100
  export declare const VERIFIED_JWT_SUBJECT_HEADER = "x-supacloud-jwt-sub";
65
101
  export declare const EXECUTION_ID_HEADER = "x-sb-execution-id";
66
102
  export declare const IDEMPOTENCY_KEY_HEADER = "idempotency-key";
@@ -116,6 +152,16 @@ export interface CommandAudit {
116
152
  failed(invocation: CommandInvocation, error: unknown): void | Promise<void>;
117
153
  }
118
154
  export interface CommandGovernance {
155
+ /** Application-owned adapters: a single RPC owns all declared persistence. */
156
+ rpc?: Record<string, {
157
+ capabilities: {
158
+ audit?: boolean;
159
+ transaction?: boolean;
160
+ idempotency?: boolean;
161
+ boundary?: "database" | "external";
162
+ };
163
+ execute: CommandMiddleware;
164
+ }>;
119
165
  authorize: CommandAuthorizer;
120
166
  idempotency?: CommandMiddleware;
121
167
  transaction?: CommandMiddleware;
@@ -159,10 +205,14 @@ export interface ErrorContext {
159
205
  export type ErrorMapper = (error: unknown, context: ErrorContext) => Response | undefined | Promise<Response | undefined>;
160
206
  export interface ApplicationOptions {
161
207
  name?: string;
208
+ /** false rejects extra schema properties instead of silently removing them. */
209
+ normalize?: boolean;
162
210
  /** Modules in topological import order. */
163
211
  modules?: CompiledModule[];
164
212
  /** Platform-level dependencies (db client etc.), passed to createServices. */
165
213
  deps?: Record<string, unknown>;
214
+ /** Optional Angular-backed root injector used for async request contexts. */
215
+ injector?: EnvironmentInjector;
166
216
  /** Builds the per-request context object. Defaults to { requestId, request }. */
167
217
  requestContext?: RequestContextFactory;
168
218
  /** Enforces permission/audit/idempotency policy for command-bound routes. */
@@ -171,6 +221,10 @@ export interface ApplicationOptions {
171
221
  commandExecutor?: CommandExecutor;
172
222
  /** Maps framework or application failures to the public HTTP contract. */
173
223
  errorMapper?: ErrorMapper;
224
+ /** Best-effort execution metadata only; durable audit belongs to governance. */
225
+ onExecution?: ExecutionObserver;
226
+ /** Optional read-only OpenAPI and GraphQL documentation endpoints. */
227
+ documentation?: ApplicationDocumentationOptions;
174
228
  }
175
229
  export interface JobInvocation {
176
230
  job: CompiledJob;
@@ -185,13 +239,39 @@ export type JobExecutor = (invocation: JobInvocation, next: () => unknown | Prom
185
239
  * Runtime. The runtime strips incoming x-supacloud-jwt-sub values and writes
186
240
  * the header only after JWT verification.
187
241
  */
188
- export declare const createSupaCloudRequestContext: RequestContextFactory;
242
+ export declare const createSupaCloudRequestContext: (request: Request) => SupaCloudRequestContext;
189
243
  /**
190
244
  * Compose the standard command governance order:
191
245
  * authorization -> idempotency -> transaction -> audit -> handler.
192
246
  * Declared governance metadata fails closed when its adapter is absent.
193
247
  */
194
- export declare function createCommandExecutor(governance: CommandGovernance): CommandExecutor;
248
+ export declare function createCommandExecutor(governance: CommandGovernance, observer?: ExecutionObserver): CommandExecutor;
249
+ /** Execute at the business-selected boundary without binding or re-entering an HTTP route. */
250
+ export declare function executeCompiledCommand<Input, Result>(options: {
251
+ module: Pick<CompiledModule, "name" | "commands" | "aspects">;
252
+ command: string;
253
+ input: Input;
254
+ request: Request;
255
+ requestContext: unknown;
256
+ services?: Record<string, unknown>;
257
+ scope?: Record<string, unknown>;
258
+ governance: CommandGovernance;
259
+ observer?: ExecutionObserver;
260
+ handler: (input: Input) => Result | Promise<Result>;
261
+ decode: (value: unknown) => Result;
262
+ }): Promise<Result>;
263
+ /** Read-only actionability. Accepts the same governance object as execute, but only runs authorize. */
264
+ export declare function previewCompiledCommand<Input>(options: {
265
+ module: Pick<CompiledModule, "name" | "commands">;
266
+ command: string;
267
+ input: Input;
268
+ request: Request;
269
+ requestContext: unknown;
270
+ services?: Record<string, unknown>;
271
+ scope?: Record<string, unknown>;
272
+ governance: CommandGovernance;
273
+ preview: (input: Input) => unknown;
274
+ }): Promise<CommandPreview>;
195
275
  export declare function requireTrustedIdentity(requestContext: unknown): Required<Pick<TrustedRequestIdentity, "subject" | "accessToken">> & TrustedRequestIdentity;
196
276
  export declare function requireIdempotencyKey(invocation: CommandInvocation): string;
197
277
  /**
@@ -202,7 +282,7 @@ export declare function requireIdempotencyKey(invocation: CommandInvocation): st
202
282
  * exposed on the `scope` context key. Request-scoped controller instances are
203
283
  * looked up on `scope`, everything else on `services`.
204
284
  */
205
- export declare function createModulePlugin(compiled: CompiledModule, services: Record<string, unknown>, ctxFactory?: RequestContextFactory, options?: Pick<ApplicationOptions, "commandGovernance" | "commandExecutor" | "errorMapper">, imported?: Record<string, Record<string, unknown>>): Elysia;
285
+ export declare function createModulePlugin(compiled: CompiledModule, services: Record<string, unknown>, ctxFactory?: RequestContextFactory, options?: Pick<ApplicationOptions, "commandGovernance" | "commandExecutor" | "errorMapper" | "onExecution" | "normalize" | "injector">, imported?: Record<string, Record<string, unknown>>): Elysia;
206
286
  /**
207
287
  * Execute one compiler-emitted Job descriptor.
208
288
  *
@@ -210,7 +290,7 @@ export declare function createModulePlugin(compiled: CompiledModule, services: R
210
290
  * accepted for command-like job implementations. The scope factory and
211
291
  * destruction hooks are generated statically by the compiler.
212
292
  */
213
- export declare function executeJob(compiled: CompiledModule, services: Record<string, unknown>, job: CompiledJob, input: unknown, requestContext: unknown, imported?: Record<string, Record<string, unknown>>, executor?: JobExecutor): Promise<unknown>;
293
+ export declare function executeJob(compiled: CompiledModule, services: Record<string, unknown>, job: CompiledJob, input: unknown, requestContext: unknown, imported?: Record<string, Record<string, unknown>>, executor?: JobExecutor, observer?: ExecutionObserver): Promise<unknown>;
214
294
  export declare function defaultErrorResponse(error: unknown, frameworkCode?: string | number): Response;
215
295
  /**
216
296
  * Create the root Elysia application from compiled modules.
@@ -226,3 +306,5 @@ export { createMemorySandbox, } from "./memory";
226
306
  export type { HandleLike as MemoryHandleLike, MemoryDatabase, MemorySandbox, MemorySandboxOptions, MemoryStorage, MemoryStorageObject, } from "./memory";
227
307
  export { createMemoryPolicy } from "./memory_policy";
228
308
  export type { MemoryPolicy } from "./memory_policy";
309
+ export { createQueueWorkerTransport, createWorker, SupaCloudWorker, WorkerRegistrationError, WorkerReceiptUnconfirmedError, } from "./worker";
310
+ export type { WorkerAcknowledge, WorkerClaim, WorkerFail, WorkerOptions, QueueWorkerTransportOptions, WorkerQueueFailureOptions, WorkerQueueMessage, WorkerQueuePort, WorkerQueueReceiveOptions, WorkerReceiptContext, WorkerReceiptOperation, WorkerRunResult, WorkerState, WorkerTransport, } from "./worker";