@supacloud/elysia 0.10.0 → 0.16.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.
@@ -0,0 +1,20 @@
1
+ import { type CommandIdentity, type DurableCommandReceipt } from "@supacloud/contracts";
2
+ import { type CommandInvocation } from "./index";
3
+ export interface PersistentCommandHandler<Result> {
4
+ readonly kind: "transactional" | "external";
5
+ execute(identity: CommandIdentity, key: string, value: unknown): Promise<DurableCommandReceipt<Result>>;
6
+ }
7
+ /** Registered persistence owns the operation; a second route handler is never invoked. */
8
+ export declare function createPersistentCommandAdapter<Result>(command: PersistentCommandHandler<Result>, options: {
9
+ /** Resolve verified tenant/actor identity from the host, never from request body. */
10
+ identity(invocation: CommandInvocation): CommandIdentity | Promise<CommandIdentity>;
11
+ input(invocation: CommandInvocation): unknown;
12
+ }): {
13
+ capabilities: {
14
+ audit: boolean;
15
+ idempotency: boolean;
16
+ transaction: boolean;
17
+ boundary: "external" | "database";
18
+ };
19
+ execute(invocation: CommandInvocation): Promise<DurableCommandReceipt<Result>>;
20
+ };
@@ -0,0 +1,160 @@
1
+ import { StatusMap, ElysiaCustomStatusResponse, type Cookie, type Elysia, type HTTPMethod, type InputSchema, type MaybePromise, type TSchema, type UnwrapSchema } from "elysia";
2
+ import type { ResponseMapSelector as AppResponseMapSelector, RouteContractSchemas as AppRouteContractSchemas } from "@supacloud/app";
3
+ /** Response selectors are owned by @supacloud/app and re-exported by the adapter. */
4
+ export type ResponseMapSelector = AppResponseMapSelector;
5
+ /** The schema fields shared by Elysia routes, generated clients and docs. */
6
+ export type RouteContractSchemas = AppRouteContractSchemas;
7
+ /**
8
+ * Response selectors supported by the shared contract. Numeric selectors are
9
+ * represented as both numbers and numeric strings at runtime; the latter are
10
+ * useful when contracts are loaded from JSON or generated source.
11
+ */
12
+ type StatusDigit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
13
+ type StatusFamily = 1 | 2 | 3 | 4 | 5;
14
+ type StatusCodeForFamily<Family extends StatusFamily> = `${Family}${StatusDigit}${StatusDigit}` extends infer Value ? Value extends `${infer Code extends number}` ? Code : never : never;
15
+ type AllHttpStatusCodes = StatusCodeForFamily<StatusFamily>;
16
+ type KeyMatchingLower<Value, Target extends string> = {
17
+ [Key in keyof Value & string]: Lowercase<Key> extends Target ? Key : never;
18
+ }[keyof Value & string];
19
+ type ExactResponseKey<Value, Code extends number> = Code extends keyof Value ? Code : `${Code}` extends keyof Value ? `${Code}` : never;
20
+ type FamilyResponseKey<Value, Code extends number> = `${Code}` extends `${infer Family extends StatusFamily}${StatusDigit}${StatusDigit}` ? KeyMatchingLower<Value, `${Family}xx`> : never;
21
+ type DefaultResponseKey<Value> = KeyMatchingLower<Value, "default">;
22
+ type HasExactResponseKey<Value, Code extends number> = [
23
+ ExactResponseKey<Value, Code>
24
+ ] extends [never] ? false : true;
25
+ type HasFamilyResponseKey<Value, Family extends StatusFamily> = [
26
+ KeyMatchingLower<Value, `${Family}xx`>
27
+ ] extends [never] ? false : true;
28
+ type AllowsPlainSuccessResponse<Value> = HasExactResponseKey<Value, 200> extends true ? true : HasFamilyResponseKey<Value, 2> extends true ? true : [DefaultResponseKey<Value>] extends [never] ? false : true;
29
+ type ResponseSchemaForCode<Value, Code extends number> = ExactResponseKey<Value, Code> extends infer Exact ? [Exact] extends [never] ? FamilyResponseKey<Value, Code> extends infer Family ? [Family] extends [never] ? DefaultResponseKey<Value> extends infer Default ? [Default] extends [never] ? never : Default extends keyof Value ? Value[Default] : never : never : Family extends keyof Value ? Value[Family] : never : never : Exact extends keyof Value ? Value[Exact] : never : never;
30
+ type DeclaredResponses<Schemas extends RouteContractSchemas> = "responses" extends keyof Schemas ? NonNullable<Schemas["responses"]> : never;
31
+ type LegacyResponse<Schemas extends RouteContractSchemas> = "response" extends keyof Schemas ? NonNullable<Schemas["response"]> : never;
32
+ type ResponseField<Schemas extends RouteContractSchemas> = [
33
+ DeclaredResponses<Schemas>
34
+ ] extends [never] ? [LegacyResponse<Schemas>] extends [never] ? undefined : LegacyResponse<Schemas> : DeclaredResponses<Schemas>;
35
+ type NumericResponseCodes<Value> = Value extends Readonly<Record<string | number, unknown>> ? {
36
+ [Key in keyof Value]: Key extends number ? Key : Key extends `${infer Numeric extends number}` ? Numeric : never;
37
+ }[keyof Value] : never;
38
+ type FamilyResponseCodes<Value> = Value extends Readonly<Record<string | number, unknown>> ? {
39
+ [Key in keyof Value & string]: Lowercase<Key> extends `${infer Family extends StatusFamily}xx` ? StatusCodeForFamily<Family> : never;
40
+ }[keyof Value & string] : never;
41
+ type ResponseStatusCodes<Value> = NumericResponseCodes<Value> | FamilyResponseCodes<Value> | ([DefaultResponseKey<Value>] extends [never] ? never : AllHttpStatusCodes);
42
+ type DecodedSchema<Value> = Value extends TSchema ? UnwrapSchema<Value> : unknown;
43
+ type DecodedResponse<Schemas extends RouteContractSchemas> = ResponseField<Schemas> extends infer Response ? Response extends TSchema ? DecodedSchema<Response> : Response extends Readonly<Record<string | number, unknown>> ? DecodedSchema<Response[keyof Response]> : DecodedSchema<Response> : unknown;
44
+ type StatusResponse<Schemas extends RouteContractSchemas> = ResponseField<Schemas> extends infer Response ? Response extends TSchema ? never : Response extends Readonly<Record<string | number, unknown>> ? {
45
+ [Code in ResponseStatusCodes<Response>]: ElysiaCustomStatusResponse<Code, DecodedSchema<ResponseSchemaForCode<Response, Code>>>;
46
+ }[ResponseStatusCodes<Response>] : never : never;
47
+ /**
48
+ * A plain handler return is sent as the default HTTP 200 response. When a
49
+ * status map declares several payloads, only the schema selected for 200 is
50
+ * valid here; every other payload must use `status(code, value)` so its
51
+ * status and schema stay coupled at runtime.
52
+ */
53
+ type PlainResponse<Schemas extends RouteContractSchemas> = ResponseField<Schemas> extends infer Response ? Response extends Readonly<Record<string | number, unknown>> ? AllowsPlainSuccessResponse<Response> extends true ? DecodedSchema<ResponseSchemaForCode<Response, 200>> : never : DecodedResponse<Schemas> : never;
54
+ type ElysiaRouteOutput<Schemas extends RouteContractSchemas> = PlainResponse<Schemas> | StatusResponse<Schemas> | Response | void;
55
+ /** Raw schema shape consumed by Elysia's route registration API. */
56
+ export interface ElysiaRouteSchema<Schemas extends RouteContractSchemas> {
57
+ body?: Schemas["body"] extends TSchema ? Schemas["body"] : undefined;
58
+ params?: Schemas["params"] extends TSchema ? Schemas["params"] : undefined;
59
+ query?: Schemas["query"] extends TSchema ? Schemas["query"] : undefined;
60
+ headers?: Schemas["headers"] extends TSchema ? Schemas["headers"] : undefined;
61
+ cookie?: Schemas["cookie"] extends TSchema ? Schemas["cookie"] : undefined;
62
+ response?: ResponseField<Schemas>;
63
+ }
64
+ type PathParameterNames<Path extends string> = Path extends `${string}:${infer Name}/${infer Rest}` ? Name | PathParameterNames<`/${Rest}`> : Path extends `${string}:${infer Name}` ? Name : never;
65
+ type PathParameters<Path extends string> = [PathParameterNames<Path>] extends [never] ? Record<string, string> : {
66
+ [Name in PathParameterNames<Path>]: string;
67
+ };
68
+ type DecodedField<Schemas extends RouteContractSchemas, Key extends keyof RouteContractSchemas> = [
69
+ Extract<Schemas[Key], TSchema>
70
+ ] extends [never] ? unknown : UnwrapSchema<Extract<Schemas[Key], TSchema>>;
71
+ type DecodedCookie<Schemas extends RouteContractSchemas> = DecodedField<Schemas, "cookie"> extends infer Value ? Value extends Record<string, unknown> ? Record<string, Cookie<unknown>> & {
72
+ [Key in keyof Value]-?: Cookie<Value[Key]>;
73
+ } : Record<string, Cookie<unknown>> : Record<string, Cookie<unknown>>;
74
+ type StatusCode<Schemas extends RouteContractSchemas> = ResponseField<Schemas> extends infer Response ? Response extends TSchema ? never : Response extends Readonly<Record<string | number, unknown>> ? ResponseStatusCodes<Response> : never : never;
75
+ type StatusResponseValue<Schemas extends RouteContractSchemas, Code extends number> = ResponseField<Schemas> extends infer Response ? Response extends TSchema ? DecodedSchema<Response> : Response extends Readonly<Record<string | number, unknown>> ? DecodedSchema<ResponseSchemaForCode<Response, Code>> : DecodedSchema<Response> : unknown;
76
+ type RouteStatus<Schemas extends RouteContractSchemas> = [StatusCode<Schemas>] extends [never] ? <const Code extends number, const Value>(code: Code, response: Value) => ElysiaCustomStatusResponse<Code, Value> : <const Code extends StatusCode<Schemas>, const Value extends StatusResponseValue<Schemas, Code>>(code: Code, response: Value) => ElysiaCustomStatusResponse<Code, Value>;
77
+ /** Elysia-compatible decoded context inferred from one route contract and path. */
78
+ export type ElysiaRouteContext<Schemas extends RouteContractSchemas, Path extends string = ""> = {
79
+ body: DecodedField<Schemas, "body">;
80
+ params: Schemas["params"] extends TSchema ? DecodedField<Schemas, "params"> : PathParameters<Path>;
81
+ query: Schemas["query"] extends TSchema ? DecodedField<Schemas, "query"> : Record<string, string>;
82
+ headers: Schemas["headers"] extends TSchema ? DecodedField<Schemas, "headers"> : Record<string, string | undefined>;
83
+ cookie: DecodedCookie<Schemas>;
84
+ request: Request;
85
+ path: string;
86
+ route: Path;
87
+ server: unknown;
88
+ store: Record<string, unknown>;
89
+ set: {
90
+ headers: Record<string, string>;
91
+ status?: number | keyof StatusMap;
92
+ redirect?: string;
93
+ cookie?: Record<string, unknown>;
94
+ };
95
+ status: RouteStatus<Schemas>;
96
+ redirect: (url: string, status?: number) => Response;
97
+ };
98
+ /** Handler type with Elysia's native decoded context and status-aware return type. */
99
+ export type ElysiaRouteHandler<Schemas extends RouteContractSchemas, Path extends string = ""> = (context: ElysiaRouteContext<Schemas, Path>) => MaybePromise<ElysiaRouteOutput<Schemas>>;
100
+ export interface ElysiaRouteDefinition<Method extends HTTPMethod, Path extends string, Schemas extends RouteContractSchemas> {
101
+ readonly method: Method;
102
+ readonly path: Path;
103
+ readonly contract: Readonly<Schemas>;
104
+ readonly handler: ElysiaRouteHandler<Schemas, Path>;
105
+ }
106
+ /**
107
+ * Keeps route schemas in one immutable value that can be reused by the
108
+ * compiler, generated clients and the Elysia route helper.
109
+ */
110
+ export declare function defineRouteContract<const Schemas extends RouteContractSchemas>(schemas: Schemas): Readonly<Schemas>;
111
+ /** Select the response schema using exact status > family > default precedence. */
112
+ export declare function responseSchemaForStatus(responses: Readonly<Record<string | number, unknown>>, status: number): unknown | undefined;
113
+ export declare function responseStatusDeclared(responses: Readonly<Record<string | number, unknown>>, status: number): boolean;
114
+ export declare function responseStatusOf(value: unknown, configuredStatus: number | string | undefined): number;
115
+ export declare function assertResponseStatusDeclared(responses: Readonly<Record<string | number, unknown>>, status: number): void;
116
+ /** Convert the shared contract shape to Elysia's `response` route option. */
117
+ export declare function toElysiaRouteSchema<const Schemas extends RouteContractSchemas>(contract: Schemas): InputSchema<never>;
118
+ /**
119
+ * Binds a shared contract to an Elysia-native handler. The handler callback is
120
+ * contextually typed from the same schemas that will be registered at runtime.
121
+ */
122
+ export declare function defineElysiaRoute<const Method extends HTTPMethod, const Path extends string, const Schemas extends RouteContractSchemas>(method: Method, path: Path, contract: Schemas, handler: ElysiaRouteHandler<NoInfer<Schemas>, Path>): ElysiaRouteDefinition<Method, Path, Schemas>;
123
+ /** Register a contract-bound route while preserving Elysia's fluent app API. */
124
+ export declare function registerElysiaRoute<const App extends Elysia, const Method extends HTTPMethod, const Path extends string, const Schemas extends RouteContractSchemas>(app: App, route: ElysiaRouteDefinition<Method, Path, Schemas>): App;
125
+ export declare class SchemaContractError extends Error {
126
+ readonly code = "SCHEMA_CONTRACT_INVALID";
127
+ constructor();
128
+ }
129
+ /** Shares Elysia's validation and transformation semantics without trusting a caller-supplied result type. */
130
+ export type SchemaNormalizeMode = boolean | "exactMirror" | "typebox";
131
+ export interface SchemaDecoderOptions {
132
+ /** Match Elysia's default route normalization unless explicitly disabled. */
133
+ normalize?: SchemaNormalizeMode;
134
+ /** Query/path coercion is opt-in because body and job payloads are normally typed JSON. */
135
+ coerce?: boolean;
136
+ }
137
+ export declare function createSchemaDecoder<const Schema extends TSchema>(schema: Schema, options?: SchemaDecoderOptions): (value: unknown) => UnwrapSchema<Schema>;
138
+ /**
139
+ * The body and response schemas are also route options. The decoder fields
140
+ * structurally implement @supacloud/app's HttpContract without a runtime import.
141
+ */
142
+ export declare function defineJsonContract<const Input extends TSchema, const Result extends TSchema>(schemas: {
143
+ body: Input;
144
+ response: Result;
145
+ }, request: (input: NoInfer<UnwrapSchema<Input>>) => {
146
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
147
+ url: string;
148
+ body?: unknown;
149
+ }, options?: SchemaDecoderOptions): Readonly<{
150
+ input: (value: unknown) => UnwrapSchema<Input, {}>;
151
+ result: (value: unknown) => UnwrapSchema<Result, {}>;
152
+ request: (input: NoInfer<UnwrapSchema<Input>>) => {
153
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
154
+ url: string;
155
+ body?: unknown;
156
+ };
157
+ body: Input;
158
+ response: Result;
159
+ }>;
160
+ export {};
@@ -0,0 +1,41 @@
1
+ import type { CommandAuthorization, CommandIdentity } from "@supacloud/contracts";
2
+ import { type CommandDatabase, type CommandTransaction } from "@supacloud/db";
3
+ export { decodeWebhookInput } from "./fixtures/webhook/contracts";
4
+ export declare const WEBHOOK_EXAMPLE_SQL = "CREATE TABLE IF NOT EXISTS public.webhook_module_example (\n tenant_id text NOT NULL, id text NOT NULL, enabled boolean NOT NULL,\n writes integer NOT NULL DEFAULT 0, PRIMARY KEY (tenant_id,id)\n);";
5
+ /** Composition only; the compiler generates factories and routes from the real module. */
6
+ export declare function createWebhookMigrationExample(options: {
7
+ database: CommandDatabase;
8
+ authenticate(request: Request): Promise<CommandIdentity>;
9
+ authorize(identity: CommandIdentity, transaction: CommandTransaction): Promise<CommandAuthorization>;
10
+ writeAudit?(transaction: CommandTransaction): Promise<void>;
11
+ }): {
12
+ app: import("elysia").default<"", {
13
+ decorator: {};
14
+ store: {};
15
+ derive: {};
16
+ resolve: {};
17
+ }, {
18
+ typebox: {};
19
+ error: {};
20
+ }, {
21
+ schema: {};
22
+ standaloneSchema: {};
23
+ macro: {};
24
+ macroFn: {};
25
+ parser: {};
26
+ response: {};
27
+ }, {}, {
28
+ derive: {};
29
+ resolve: {};
30
+ schema: {};
31
+ standaloneSchema: {};
32
+ response: {};
33
+ }, {
34
+ derive: {};
35
+ resolve: {};
36
+ schema: {};
37
+ standaloneSchema: {};
38
+ response: {};
39
+ }>;
40
+ modules: import("./fixtures/webhook-generated/application").CompiledModule[];
41
+ };
@@ -0,0 +1,150 @@
1
+ import { type CompiledJob, type CompiledModule, type ExecutionObserver, type JobExecutor } from "./index";
2
+ export type WorkerState = "idle" | "starting" | "running" | "stopping" | "stopped";
3
+ /** The transport-specific claim is mapped to this small execution contract. */
4
+ export interface WorkerClaim {
5
+ id: string;
6
+ jobName: string;
7
+ input: unknown;
8
+ attempt?: number;
9
+ requestContext?: unknown;
10
+ }
11
+ export interface WorkerReceiptContext {
12
+ readonly jobId: string;
13
+ readonly jobName: string;
14
+ readonly attempt: number;
15
+ readonly signal: AbortSignal;
16
+ }
17
+ export type WorkerAcknowledge<TClaim, TReceipt> = (claim: TClaim, output: unknown, context: WorkerReceiptContext) => TReceipt | Promise<TReceipt>;
18
+ export type WorkerFail<TClaim, TReceipt> = (claim: TClaim, error: unknown, context: WorkerReceiptContext) => TReceipt | Promise<TReceipt>;
19
+ /** Minimal queue message shape shared by the public SupaCloud queue client. */
20
+ export interface WorkerQueueMessage {
21
+ id: string | number;
22
+ payload: unknown;
23
+ }
24
+ export interface WorkerQueueReceiveOptions {
25
+ visibilityTimeoutSec?: number;
26
+ sleepSeconds?: number;
27
+ sleep_seconds?: number;
28
+ }
29
+ export interface WorkerQueueFailureOptions {
30
+ error?: string;
31
+ deadLetter?: boolean;
32
+ }
33
+ /** Structural port implemented by `client.queue(name)` without a package dependency. */
34
+ export interface WorkerQueuePort<TMessage extends WorkerQueueMessage = WorkerQueueMessage, TReceipt = unknown> {
35
+ receive(options?: WorkerQueueReceiveOptions): Promise<TMessage | null>;
36
+ ack(messageId: string | number): TReceipt | Promise<TReceipt>;
37
+ fail(messageId: string | number, options?: WorkerQueueFailureOptions): TReceipt | Promise<TReceipt>;
38
+ }
39
+ export interface QueueWorkerTransportOptions<TMessage extends WorkerQueueMessage, TClaim, TReceipt> {
40
+ queue: WorkerQueuePort<TMessage, TReceipt>;
41
+ decodeClaim: (message: TMessage) => TClaim;
42
+ messageId: (claim: TClaim) => string | number;
43
+ receive?: WorkerQueueReceiveOptions;
44
+ }
45
+ /**
46
+ * Adapts the existing SupaCloud queue client to the worker transport contract.
47
+ * Queue leasing and retry policy remain owned by the queue implementation.
48
+ */
49
+ export declare function createQueueWorkerTransport<TMessage extends WorkerQueueMessage, TClaim, TReceipt>(options: QueueWorkerTransportOptions<TMessage, TClaim, TReceipt>): WorkerTransport<TClaim, TReceipt>;
50
+ /**
51
+ * Queue/task ownership stays in the host adapter. The worker never interprets
52
+ * a receipt and therefore supports platform-specific receipt types unchanged.
53
+ */
54
+ export interface WorkerTransport<TClaim = WorkerClaim, TReceipt = unknown> {
55
+ claim(signal: AbortSignal): Promise<TClaim | null>;
56
+ /** Preferred spelling. */
57
+ ack?: WorkerAcknowledge<TClaim, TReceipt>;
58
+ /** Compatibility spelling for adapters that use the full verb. */
59
+ acknowledge?: WorkerAcknowledge<TClaim, TReceipt>;
60
+ fail: WorkerFail<TClaim, TReceipt>;
61
+ }
62
+ export interface WorkerRunResult<TReceipt> {
63
+ claimId: string;
64
+ jobName: string;
65
+ status: "acknowledged" | "failed";
66
+ receipt: TReceipt;
67
+ }
68
+ export interface WorkerOptions<TClaim = WorkerClaim, TReceipt = unknown> {
69
+ modules?: readonly CompiledModule[];
70
+ deps?: Record<string, unknown>;
71
+ transport: WorkerTransport<TClaim, TReceipt>;
72
+ /** Convert a platform claim into the framework's stable execution shape. */
73
+ mapClaim?: (claim: TClaim) => WorkerClaim;
74
+ /** Build a request-like context for the Job. */
75
+ requestContext?: (claim: WorkerClaim, signal: AbortSignal) => unknown | Promise<unknown>;
76
+ workerId?: string;
77
+ concurrency?: number;
78
+ pollIntervalMs?: number;
79
+ executor?: JobExecutor;
80
+ onExecution?: ExecutionObserver;
81
+ onError?: (error: unknown) => void | Promise<void>;
82
+ /** Optional application-service cleanup owned by the host/bootstrap. */
83
+ destroyServices?: (services: Record<string, unknown>, imported: Record<string, Record<string, unknown>>) => void | Promise<void>;
84
+ }
85
+ export declare class WorkerRegistrationError extends Error {
86
+ readonly code: "WORKER_DUPLICATE_JOB" | "WORKER_DUPLICATE_MODULE" | "WORKER_INVALID_JOB" | "WORKER_TRANSPORT_INVALID" | "WORKER_NOT_STARTED";
87
+ constructor(code: WorkerRegistrationError["code"], message: string);
88
+ }
89
+ export type WorkerReceiptOperation = "ack" | "fail";
90
+ /** A platform settlement may have applied even when its response was lost. */
91
+ export declare class WorkerReceiptUnconfirmedError extends Error {
92
+ readonly operation: WorkerReceiptOperation;
93
+ readonly claimId: string;
94
+ readonly code: "WORKER_RECEIPT_UNCONFIRMED";
95
+ readonly mutationMayHaveApplied: true;
96
+ constructor(operation: WorkerReceiptOperation, claimId: string);
97
+ }
98
+ /**
99
+ * Registers compiler-emitted Jobs and drives an existing claim/receipt
100
+ * transport. It deliberately does not implement queue leasing, retries, or
101
+ * DLQ policy; those are properties of the platform adapter.
102
+ */
103
+ export declare class SupaCloudWorker<TClaim = WorkerClaim, TReceipt = unknown> {
104
+ private readonly registry;
105
+ private readonly modules;
106
+ private readonly moduleServices;
107
+ private readonly deps;
108
+ private readonly transport;
109
+ private readonly mapClaim;
110
+ private readonly requestContextFactory;
111
+ private readonly workerId;
112
+ private readonly concurrency;
113
+ private readonly pollIntervalMs;
114
+ private readonly executor;
115
+ private readonly observer;
116
+ private readonly onError;
117
+ private readonly destroyServices;
118
+ private stateValue;
119
+ private claimController;
120
+ private loopPromise;
121
+ private startPromise;
122
+ private stopPromise;
123
+ private stopRequested;
124
+ private readonly inFlight;
125
+ private services;
126
+ private imported;
127
+ constructor(options: WorkerOptions<TClaim, TReceipt>);
128
+ get state(): WorkerState;
129
+ get id(): string;
130
+ get jobNames(): readonly string[];
131
+ get jobs(): readonly CompiledJob[];
132
+ /** Register a compiled module before the worker starts. */
133
+ registerModule(module: CompiledModule): void;
134
+ /** Alias useful for hosts that register generated modules incrementally. */
135
+ register(module: CompiledModule): void;
136
+ start(): Promise<void>;
137
+ stop(): Promise<void>;
138
+ /** Claim and process one item, primarily useful for deterministic hosts/tests. */
139
+ runOnce(): Promise<WorkerRunResult<TReceipt> | null>;
140
+ /** Process a host-provided claim without performing another claim operation. */
141
+ processClaim(rawClaim: TClaim): Promise<WorkerRunResult<TReceipt>>;
142
+ private failClaim;
143
+ private initialize;
144
+ private releaseServices;
145
+ private pollLoop;
146
+ private reportError;
147
+ private capturePositiveInteger;
148
+ private captureNonNegativeInteger;
149
+ }
150
+ export declare function createWorker<TClaim = WorkerClaim, TReceipt = unknown>(options: WorkerOptions<TClaim, TReceipt>): SupaCloudWorker<TClaim, TReceipt>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/elysia",
3
- "version": "0.10.0",
3
+ "version": "0.16.0",
4
4
  "description": "Elysia runtime adapter for SupaCloud compiled modules: application/request scopes, route registration and validation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,15 +15,20 @@
15
15
  },
16
16
  "files": [
17
17
  "dist",
18
- "README.md"
18
+ "README.md",
19
+ "compatibility.json"
19
20
  ],
20
21
  "scripts": {
22
+ "generate:example": "bun src/generate-webhook-example.ts",
21
23
  "build": "bun run clean && bun run build:js && bun run build:types",
22
- "build:js": "bun build src/index.ts --outdir dist --target node --external elysia --external jose",
24
+ "build:js": "bun build src/index.ts --outdir dist --target node --external elysia --external jose --external @supacloud/app --external @supacloud/db --external @supacloud/contracts",
23
25
  "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
24
26
  "clean": "rm -rf dist",
25
27
  "prepublishOnly": "bun run build",
26
28
  "test": "bun test",
29
+ "test:conformance": "bun test src/conformance.test.ts",
30
+ "test:runtime-safety": "SUPACLOUD_REQUIRE_RUNTIME_SAFETY=1 bun test src/runtime-safety.test.ts",
31
+ "test:contract-upgrade": "bun test src/contract-upgrade.test.ts",
27
32
  "typecheck": "tsc -p tsconfig.json --noEmit",
28
33
  "typecheck:test": "tsc -p tsconfig.test.json --noEmit"
29
34
  },
@@ -41,13 +46,22 @@
41
46
  "directory": "packages/elysia"
42
47
  },
43
48
  "dependencies": {
49
+ "@supacloud/app": "0.14.0",
50
+ "@supacloud/contracts": "0.4.0",
44
51
  "jose": "^6.2.11"
45
52
  },
53
+ "overrides": {
54
+ "@supacloud/contracts": "0.4.0",
55
+ "@supacloud/commands": "0.4.0"
56
+ },
46
57
  "peerDependencies": {
47
58
  "elysia": "^1.4.30"
48
59
  },
49
60
  "devDependencies": {
50
- "@types/bun": "^1.4.0",
61
+ "@supacloud/compiler": "0.21.0",
62
+ "@supacloud/commands": "0.4.0",
63
+ "@supacloud/db": "0.7.1",
64
+ "@types/bun": "^1.4.2",
51
65
  "elysia": "^1.4.30",
52
66
  "typescript": "^7.0.2"
53
67
  }