@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
package/dist/memory.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AnyElysia, Elysia } from "elysia";
|
|
1
2
|
import { type ApplicationOptions, type TrustedRequestIdentity } from "./index";
|
|
2
3
|
import { type MemoryPolicy } from "./memory_policy";
|
|
3
4
|
export interface HandleLike {
|
|
@@ -33,7 +34,7 @@ export interface MemoryStorage {
|
|
|
33
34
|
failNext(error?: Error): void;
|
|
34
35
|
setPolicy(policy?: (operation: "put" | "get" | "delete" | "list", bucket: string, key: string) => boolean): void;
|
|
35
36
|
}
|
|
36
|
-
export interface MemorySandboxOptions extends Omit<ApplicationOptions
|
|
37
|
+
export interface MemorySandboxOptions<Http extends AnyElysia = Elysia> extends Omit<ApplicationOptions<Http>, "deps" | "requestContext"> {
|
|
37
38
|
/** Stable identity used by every request unless overridden by requestContext. */
|
|
38
39
|
identity?: TrustedRequestIdentity;
|
|
39
40
|
/** Stable request id used when the request does not provide x-request-id. */
|
|
@@ -41,7 +42,7 @@ export interface MemorySandboxOptions extends Omit<ApplicationOptions, "deps" |
|
|
|
41
42
|
/** Extend the platform dependency bag without replacing memory dependencies. */
|
|
42
43
|
deps?: Record<string, unknown>;
|
|
43
44
|
/** Replace the default deterministic request context factory. */
|
|
44
|
-
requestContext?: ApplicationOptions["requestContext"];
|
|
45
|
+
requestContext?: ApplicationOptions<Http>["requestContext"];
|
|
45
46
|
/** Enable the test-only permission, receipt, transaction and audit adapters. */
|
|
46
47
|
memoryGovernance?: boolean;
|
|
47
48
|
}
|
|
@@ -65,4 +66,4 @@ export interface MemorySandbox {
|
|
|
65
66
|
* PostgreSQL or S3 emulators. They are sufficient for fast command and HTTP
|
|
66
67
|
* behavior tests while keeping production adapters replaceable.
|
|
67
68
|
*/
|
|
68
|
-
export declare function createMemorySandbox(options?: MemorySandboxOptions): MemorySandbox;
|
|
69
|
+
export declare function createMemorySandbox<const Http extends AnyElysia = Elysia>(options?: MemorySandboxOptions<Http>): MemorySandbox;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { StatusMap,
|
|
1
|
+
import { StatusMap, ElysiaStatus, type Cookie, type AnyElysia, type InputSchema } from "elysia";
|
|
2
|
+
import type { HTTPMethod, MaybePromise } from "elysia/types";
|
|
3
|
+
import type { TSchema, StaticDecode as UnwrapSchema } from "typebox";
|
|
2
4
|
import type { ResponseMapSelector as AppResponseMapSelector, RouteContractSchemas as AppRouteContractSchemas } from "@supacloud/app";
|
|
3
5
|
/** Response selectors are owned by @supacloud/app and re-exported by the adapter. */
|
|
4
6
|
export type ResponseMapSelector = AppResponseMapSelector;
|
|
@@ -40,17 +42,20 @@ type FamilyResponseCodes<Value> = Value extends Readonly<Record<string | number,
|
|
|
40
42
|
}[keyof Value & string] : never;
|
|
41
43
|
type ResponseStatusCodes<Value> = NumericResponseCodes<Value> | FamilyResponseCodes<Value> | ([DefaultResponseKey<Value>] extends [never] ? never : AllHttpStatusCodes);
|
|
42
44
|
type DecodedSchema<Value> = Value extends TSchema ? UnwrapSchema<Value> : unknown;
|
|
43
|
-
type
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
type StatusResponse<Schemas extends RouteContractSchemas> = [
|
|
46
|
+
DeclaredResponses<Schemas>
|
|
47
|
+
] extends [never] ? never : {
|
|
48
|
+
[Code in ResponseStatusCodes<DeclaredResponses<Schemas>>]: ElysiaStatus<Code, DecodedSchema<ResponseSchemaForCode<DeclaredResponses<Schemas>, Code>>>;
|
|
49
|
+
}[ResponseStatusCodes<DeclaredResponses<Schemas>>];
|
|
47
50
|
/**
|
|
48
51
|
* A plain handler return is sent as the default HTTP 200 response. When a
|
|
49
52
|
* status map declares several payloads, only the schema selected for 200 is
|
|
50
53
|
* valid here; every other payload must use `status(code, value)` so its
|
|
51
54
|
* status and schema stay coupled at runtime.
|
|
52
55
|
*/
|
|
53
|
-
type PlainResponse<Schemas extends RouteContractSchemas> =
|
|
56
|
+
type PlainResponse<Schemas extends RouteContractSchemas> = [
|
|
57
|
+
DeclaredResponses<Schemas>
|
|
58
|
+
] extends [never] ? DecodedSchema<LegacyResponse<Schemas>> : AllowsPlainSuccessResponse<DeclaredResponses<Schemas>> extends true ? DecodedSchema<ResponseSchemaForCode<DeclaredResponses<Schemas>, 200>> : never;
|
|
54
59
|
type ElysiaRouteOutput<Schemas extends RouteContractSchemas> = PlainResponse<Schemas> | StatusResponse<Schemas> | Response | void;
|
|
55
60
|
/** Raw schema shape consumed by Elysia's route registration API. */
|
|
56
61
|
export interface ElysiaRouteSchema<Schemas extends RouteContractSchemas> {
|
|
@@ -71,9 +76,11 @@ type DecodedField<Schemas extends RouteContractSchemas, Key extends keyof RouteC
|
|
|
71
76
|
type DecodedCookie<Schemas extends RouteContractSchemas> = DecodedField<Schemas, "cookie"> extends infer Value ? Value extends Record<string, unknown> ? Record<string, Cookie<unknown>> & {
|
|
72
77
|
[Key in keyof Value]-?: Cookie<Value[Key]>;
|
|
73
78
|
} : Record<string, Cookie<unknown>> : Record<string, Cookie<unknown>>;
|
|
74
|
-
type StatusCode<Schemas extends RouteContractSchemas> =
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
type StatusCode<Schemas extends RouteContractSchemas> = [
|
|
80
|
+
DeclaredResponses<Schemas>
|
|
81
|
+
] extends [never] ? never : ResponseStatusCodes<DeclaredResponses<Schemas>>;
|
|
82
|
+
type StatusResponseValue<Schemas extends RouteContractSchemas, Code extends number> = DecodedSchema<ResponseSchemaForCode<DeclaredResponses<Schemas>, Code>>;
|
|
83
|
+
type RouteStatus<Schemas extends RouteContractSchemas> = [StatusCode<Schemas>] extends [never] ? <const Code extends number, const Value>(code: Code, response: Value) => ElysiaStatus<Code, Value> : <const Code extends StatusCode<Schemas>, const Value extends StatusResponseValue<Schemas, Code>>(code: Code, response: Value) => ElysiaStatus<Code, Value>;
|
|
77
84
|
/** Elysia-compatible decoded context inferred from one route contract and path. */
|
|
78
85
|
export type ElysiaRouteContext<Schemas extends RouteContractSchemas, Path extends string = ""> = {
|
|
79
86
|
body: DecodedField<Schemas, "body">;
|
|
@@ -121,7 +128,7 @@ export declare function toElysiaRouteSchema<const Schemas extends RouteContractS
|
|
|
121
128
|
*/
|
|
122
129
|
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
130
|
/** Register a contract-bound route while preserving Elysia's fluent app API. */
|
|
124
|
-
export declare function registerElysiaRoute<const App extends
|
|
131
|
+
export declare function registerElysiaRoute<const App extends AnyElysia, const Method extends HTTPMethod, const Path extends string, const Schemas extends RouteContractSchemas>(app: App, route: ElysiaRouteDefinition<Method, Path, Schemas>): App;
|
|
125
132
|
export declare class SchemaContractError extends Error {
|
|
126
133
|
readonly code = "SCHEMA_CONTRACT_INVALID";
|
|
127
134
|
constructor();
|
|
@@ -147,8 +154,8 @@ export declare function defineJsonContract<const Input extends TSchema, const Re
|
|
|
147
154
|
url: string;
|
|
148
155
|
body?: unknown;
|
|
149
156
|
}, options?: SchemaDecoderOptions): Readonly<{
|
|
150
|
-
input: (value: unknown) =>
|
|
151
|
-
result: (value: unknown) =>
|
|
157
|
+
input: (value: unknown) => import("typebox").StaticType<[], "Decode", {}, {}, Input>;
|
|
158
|
+
result: (value: unknown) => import("typebox").StaticType<[], "Decode", {}, {}, Result>;
|
|
152
159
|
request: (input: NoInfer<UnwrapSchema<Input>>) => {
|
|
153
160
|
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
154
161
|
url: string;
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { Elysia } from "elysia";
|
|
2
1
|
/** Issue an in-process request against an Elysia app. */
|
|
3
|
-
export declare function testRequest(app:
|
|
2
|
+
export declare function testRequest(app: {
|
|
3
|
+
handle(request: Request): Response | Promise<Response>;
|
|
4
|
+
}, path: string, init?: RequestInit): Promise<Response>;
|
|
@@ -18,33 +18,26 @@ export declare function createWebhookMigrationExample(options: {
|
|
|
18
18
|
authorize(identity: CommandIdentity, transaction: CommandTransaction): Promise<CommandAuthorization>;
|
|
19
19
|
writeAudit?(transaction: CommandTransaction): Promise<void>;
|
|
20
20
|
}): {
|
|
21
|
-
app: import("elysia").
|
|
21
|
+
app: import("elysia").Elysia<"", "local", {
|
|
22
22
|
decorator: {};
|
|
23
23
|
store: {};
|
|
24
24
|
derive: {};
|
|
25
|
-
resolve: {};
|
|
26
25
|
}, {
|
|
27
26
|
typebox: {};
|
|
28
|
-
error:
|
|
29
|
-
}, {
|
|
27
|
+
error: [];
|
|
28
|
+
}, import("elysia").DefaultMetadata & {
|
|
30
29
|
schema: {};
|
|
31
|
-
|
|
30
|
+
schemas: {};
|
|
32
31
|
macro: {};
|
|
33
32
|
macroFn: {};
|
|
34
33
|
parser: {};
|
|
35
34
|
response: {};
|
|
36
|
-
}, {}, {
|
|
37
|
-
derive: {};
|
|
38
|
-
resolve: {};
|
|
39
|
-
schema: {};
|
|
40
|
-
standaloneSchema: {};
|
|
41
|
-
response: {};
|
|
42
|
-
}, {
|
|
35
|
+
}, {}, import("elysia").DefaultEphemeral, {
|
|
43
36
|
derive: {};
|
|
44
|
-
resolve: {};
|
|
45
37
|
schema: {};
|
|
46
|
-
|
|
38
|
+
schemas: {};
|
|
47
39
|
response: {};
|
|
40
|
+
error: [];
|
|
48
41
|
}>;
|
|
49
|
-
modules: import("./fixtures/webhook-generated/application").
|
|
42
|
+
modules: import("./fixtures/webhook-generated/application").CompiledApplicationModule[];
|
|
50
43
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supacloud/elysia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"test:conformance": "bun test src/conformance.test.ts",
|
|
30
30
|
"test:runtime-safety": "SUPACLOUD_REQUIRE_RUNTIME_SAFETY=1 bun test src/runtime-safety.test.ts",
|
|
31
31
|
"test:contract-upgrade": "bun test src/contract-upgrade.test.ts",
|
|
32
|
+
"bench:http-policy": "bun bench/http-policy.ts",
|
|
32
33
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
33
34
|
"typecheck:test": "tsc -p tsconfig.test.json --noEmit"
|
|
34
35
|
},
|
|
@@ -46,23 +47,27 @@
|
|
|
46
47
|
"directory": "packages/elysia"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
|
-
"@supacloud/app": "0.
|
|
50
|
-
"@supacloud/contracts": "0.
|
|
51
|
-
"
|
|
50
|
+
"@supacloud/app": "0.18.0",
|
|
51
|
+
"@supacloud/contracts": "0.5.0",
|
|
52
|
+
"exact-mirror": "1.2.6",
|
|
53
|
+
"jose": "^6.2.11",
|
|
54
|
+
"typebox": "1.3.34"
|
|
52
55
|
},
|
|
53
56
|
"overrides": {
|
|
54
|
-
"@supacloud/
|
|
55
|
-
"@supacloud/
|
|
57
|
+
"@supacloud/delivery": "0.2.0",
|
|
58
|
+
"@supacloud/contracts": "0.5.0",
|
|
59
|
+
"@supacloud/commands": "0.7.0"
|
|
56
60
|
},
|
|
57
61
|
"peerDependencies": {
|
|
58
|
-
"elysia": "
|
|
62
|
+
"elysia": ">=2.0.0-beta.19 <3"
|
|
59
63
|
},
|
|
60
64
|
"devDependencies": {
|
|
61
|
-
"@supacloud/compiler": "0.
|
|
62
|
-
"@supacloud/
|
|
63
|
-
"@supacloud/
|
|
65
|
+
"@supacloud/compiler": "0.27.0",
|
|
66
|
+
"@supacloud/delivery": "0.2.0",
|
|
67
|
+
"@supacloud/commands": "0.7.0",
|
|
68
|
+
"@supacloud/db": "0.9.0",
|
|
64
69
|
"@types/bun": "^1.4.2",
|
|
65
|
-
"elysia": "
|
|
70
|
+
"elysia": "2.0.0-beta.19",
|
|
66
71
|
"typescript": "^7.0.2"
|
|
67
72
|
}
|
|
68
73
|
}
|