silgi 0.0.13 → 0.1.0-beta.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/README.md +102 -1
- package/dist/_virtual/_rolldown/runtime.mjs +5 -0
- package/dist/adapters/astro.d.mts +17 -0
- package/dist/adapters/astro.mjs +24 -0
- package/dist/adapters/aws-lambda.d.mts +31 -0
- package/dist/adapters/aws-lambda.mjs +85 -0
- package/dist/adapters/elysia.d.mts +17 -0
- package/dist/adapters/elysia.mjs +76 -0
- package/dist/adapters/express.d.mts +16 -0
- package/dist/adapters/express.mjs +78 -0
- package/dist/adapters/fastify.d.mts +15 -0
- package/dist/adapters/fastify.mjs +78 -0
- package/dist/adapters/message-port.d.mts +37 -0
- package/dist/adapters/message-port.mjs +129 -0
- package/dist/adapters/nestjs.d.mts +25 -0
- package/dist/adapters/nestjs.mjs +91 -0
- package/dist/adapters/nextjs.d.mts +21 -0
- package/dist/adapters/nextjs.mjs +30 -0
- package/dist/adapters/peer.d.mts +27 -0
- package/dist/adapters/peer.mjs +36 -0
- package/dist/adapters/remix.d.mts +17 -0
- package/dist/adapters/remix.mjs +24 -0
- package/dist/adapters/solidstart.d.mts +14 -0
- package/dist/adapters/solidstart.mjs +30 -0
- package/dist/adapters/sveltekit.d.mts +18 -0
- package/dist/adapters/sveltekit.mjs +33 -0
- package/dist/analyze.mjs +26 -0
- package/dist/broker/index.d.mts +62 -0
- package/dist/broker/index.mjs +153 -0
- package/dist/broker/nats.d.mts +33 -0
- package/dist/broker/nats.mjs +31 -0
- package/dist/broker/redis.d.mts +51 -0
- package/dist/broker/redis.mjs +92 -0
- package/dist/builder.d.mts +36 -0
- package/dist/builder.mjs +51 -0
- package/dist/callable.d.mts +17 -0
- package/dist/callable.mjs +42 -0
- package/dist/client/adapters/fetch/index.d.mts +17 -0
- package/dist/client/adapters/fetch/index.mjs +61 -0
- package/dist/client/adapters/ofetch/index.d.mts +41 -0
- package/dist/client/adapters/ofetch/index.mjs +92 -0
- package/dist/client/client.d.mts +29 -0
- package/dist/client/client.mjs +54 -0
- package/dist/client/dynamic-link.d.mts +15 -0
- package/dist/client/dynamic-link.mjs +16 -0
- package/dist/client/index.d.mts +7 -0
- package/dist/client/index.mjs +6 -0
- package/dist/client/interceptor.d.mts +31 -0
- package/dist/client/interceptor.mjs +34 -0
- package/dist/client/merge.d.mts +28 -0
- package/dist/client/merge.mjs +30 -0
- package/dist/client/openapi.d.mts +29 -0
- package/dist/client/openapi.mjs +89 -0
- package/dist/client/plugins/batch.d.mts +20 -0
- package/dist/client/plugins/batch.mjs +64 -0
- package/dist/client/plugins/csrf.d.mts +13 -0
- package/dist/client/plugins/csrf.mjs +20 -0
- package/dist/client/plugins/dedupe.d.mts +10 -0
- package/dist/client/plugins/dedupe.mjs +28 -0
- package/dist/client/plugins/index.d.mts +5 -0
- package/dist/client/plugins/index.mjs +5 -0
- package/dist/client/plugins/retry.d.mts +11 -0
- package/dist/client/plugins/retry.mjs +21 -0
- package/dist/client/server.d.mts +16 -0
- package/dist/client/server.mjs +60 -0
- package/dist/client/types.d.mts +29 -0
- package/dist/codec/devalue.d.mts +21 -0
- package/dist/codec/devalue.mjs +32 -0
- package/dist/codec/msgpack.d.mts +21 -0
- package/dist/codec/msgpack.mjs +59 -0
- package/dist/compile.d.mts +52 -0
- package/dist/compile.mjs +304 -0
- package/dist/contract.d.mts +36 -0
- package/dist/contract.mjs +40 -0
- package/dist/core/error.d.mts +104 -0
- package/dist/core/error.mjs +139 -0
- package/dist/core/handler.mjs +546 -0
- package/dist/core/iterator.d.mts +17 -0
- package/dist/core/iterator.mjs +79 -0
- package/dist/core/router-utils.mjs +16 -0
- package/dist/core/schema.d.mts +19 -0
- package/dist/core/schema.mjs +26 -0
- package/dist/core/serve.mjs +38 -0
- package/dist/core/sse.d.mts +16 -0
- package/dist/core/sse.mjs +95 -0
- package/dist/core/storage.d.mts +21 -0
- package/dist/core/storage.mjs +63 -0
- package/dist/core/utils.mjs +21 -0
- package/dist/fast-stringify.mjs +125 -0
- package/dist/index.d.mts +15 -37
- package/dist/index.mjs +13 -7
- package/dist/integrations/ai/index.d.mts +25 -0
- package/dist/integrations/ai/index.mjs +116 -0
- package/dist/integrations/react/index.d.mts +83 -0
- package/dist/integrations/react/index.mjs +197 -0
- package/dist/integrations/tanstack-query/index.d.mts +120 -0
- package/dist/integrations/tanstack-query/index.mjs +100 -0
- package/dist/integrations/tanstack-query/ssr.d.mts +51 -0
- package/dist/integrations/tanstack-query/ssr.mjs +89 -0
- package/dist/integrations/zod/converter.d.mts +75 -0
- package/dist/integrations/zod/converter.mjs +345 -0
- package/dist/integrations/zod/index.d.mts +2 -0
- package/dist/integrations/zod/index.mjs +2 -0
- package/dist/lazy.d.mts +24 -0
- package/dist/lazy.mjs +27 -0
- package/dist/lifecycle.d.mts +36 -0
- package/dist/lifecycle.mjs +46 -0
- package/dist/map-input.d.mts +17 -0
- package/dist/map-input.mjs +24 -0
- package/dist/plugins/analytics.d.mts +168 -0
- package/dist/plugins/analytics.mjs +459 -0
- package/dist/plugins/batch-server.d.mts +20 -0
- package/dist/plugins/batch-server.mjs +86 -0
- package/dist/plugins/body-limit.d.mts +16 -0
- package/dist/plugins/body-limit.mjs +44 -0
- package/dist/plugins/cache.d.mts +170 -0
- package/dist/plugins/cache.mjs +200 -0
- package/dist/plugins/coerce.d.mts +21 -0
- package/dist/plugins/coerce.mjs +46 -0
- package/dist/plugins/compression.d.mts +19 -0
- package/dist/plugins/compression.mjs +23 -0
- package/dist/plugins/cookies.d.mts +44 -0
- package/dist/plugins/cookies.mjs +67 -0
- package/dist/plugins/cors.d.mts +39 -0
- package/dist/plugins/cors.mjs +56 -0
- package/dist/plugins/custom-serializer.d.mts +57 -0
- package/dist/plugins/custom-serializer.mjs +40 -0
- package/dist/plugins/file-upload.d.mts +38 -0
- package/dist/plugins/file-upload.mjs +100 -0
- package/dist/plugins/index.d.mts +16 -0
- package/dist/plugins/index.mjs +16 -0
- package/dist/plugins/otel.d.mts +35 -0
- package/dist/plugins/otel.mjs +40 -0
- package/dist/plugins/pino.d.mts +60 -0
- package/dist/plugins/pino.mjs +42 -0
- package/dist/plugins/pubsub.d.mts +50 -0
- package/dist/plugins/pubsub.mjs +53 -0
- package/dist/plugins/ratelimit.d.mts +51 -0
- package/dist/plugins/ratelimit.mjs +81 -0
- package/dist/plugins/signing.d.mts +41 -0
- package/dist/plugins/signing.mjs +115 -0
- package/dist/plugins/strict-get.d.mts +10 -0
- package/dist/plugins/strict-get.mjs +33 -0
- package/dist/route/add.mjs +240 -0
- package/dist/route/compiler.mjs +373 -0
- package/dist/route/context.mjs +12 -0
- package/dist/route/types.d.mts +11 -0
- package/dist/route/utils.mjs +17 -0
- package/dist/scalar.d.mts +53 -0
- package/dist/scalar.mjs +315 -0
- package/dist/silgi.d.mts +139 -0
- package/dist/silgi.mjs +113 -0
- package/dist/trpc-interop.d.mts +22 -0
- package/dist/trpc-interop.mjs +68 -0
- package/dist/types.d.mts +82 -0
- package/dist/ws.d.mts +42 -0
- package/dist/ws.mjs +137 -0
- package/lib/dashboard/index.html +123 -0
- package/lib/ocache.d.mts +1 -0
- package/lib/ocache.mjs +1 -0
- package/lib/ofetch.d.mts +1 -0
- package/lib/ofetch.mjs +1 -0
- package/lib/srvx.d.mts +1 -0
- package/lib/srvx.mjs +1 -0
- package/lib/unstorage.d.mts +1 -0
- package/lib/unstorage.mjs +1 -0
- package/package.json +291 -65
- package/bin/silgi.mjs +0 -3
- package/dist/chunks/generate.mjs +0 -933
- package/dist/chunks/init.mjs +0 -21
- package/dist/cli/config.d.mts +0 -19
- package/dist/cli/config.d.ts +0 -19
- package/dist/cli/config.mjs +0 -5
- package/dist/cli/index.d.mts +0 -2
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.mjs +0 -119
- package/dist/index.d.ts +0 -37
- package/dist/plugins/openapi.d.mts +0 -138
- package/dist/plugins/openapi.d.ts +0 -138
- package/dist/plugins/openapi.mjs +0 -204
- package/dist/plugins/scalar.d.mts +0 -14
- package/dist/plugins/scalar.d.ts +0 -14
- package/dist/plugins/scalar.mjs +0 -66
- package/dist/shared/silgi.BMCYk2cR.mjs +0 -841
- package/dist/shared/silgi.D5qK9QOm.d.mts +0 -301
- package/dist/shared/silgi.D5qK9QOm.d.ts +0 -301
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/contract.ts
|
|
2
|
+
/**
|
|
3
|
+
* Define an API contract — shared between client and server.
|
|
4
|
+
* Pure type information, no runtime behavior.
|
|
5
|
+
*/
|
|
6
|
+
function contract(definition) {
|
|
7
|
+
return definition;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Implement a contract — returns a silgi RouterDef.
|
|
11
|
+
* Type-safe: implementation must match the contract.
|
|
12
|
+
*/
|
|
13
|
+
function implement(contractDef, implementations) {
|
|
14
|
+
return buildRouter(contractDef, implementations);
|
|
15
|
+
}
|
|
16
|
+
function buildRouter(contractDef, impls) {
|
|
17
|
+
const router = {};
|
|
18
|
+
for (const [key, contractEntry] of Object.entries(contractDef)) {
|
|
19
|
+
const impl = impls[key];
|
|
20
|
+
if (!impl) continue;
|
|
21
|
+
if (isProcedureContract(contractEntry)) router[key] = {
|
|
22
|
+
type: contractEntry.type ?? "query",
|
|
23
|
+
input: contractEntry.input ?? null,
|
|
24
|
+
output: contractEntry.output ?? null,
|
|
25
|
+
errors: contractEntry.errors ?? null,
|
|
26
|
+
use: null,
|
|
27
|
+
resolve: impl,
|
|
28
|
+
route: contractEntry.route ?? null,
|
|
29
|
+
meta: null
|
|
30
|
+
};
|
|
31
|
+
else router[key] = buildRouter(contractEntry, impl);
|
|
32
|
+
}
|
|
33
|
+
return router;
|
|
34
|
+
}
|
|
35
|
+
function isProcedureContract(v) {
|
|
36
|
+
if (typeof v !== "object" || v === null) return false;
|
|
37
|
+
return "input" in v || "output" in v || "type" in v || "errors" in v;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { contract, implement };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//#region src/core/error.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* SilgiError — unified RPC error with cross-realm instanceof.
|
|
4
|
+
*/
|
|
5
|
+
declare const COMMON_ERRORS: Readonly<{
|
|
6
|
+
readonly BAD_REQUEST: {
|
|
7
|
+
readonly status: 400;
|
|
8
|
+
readonly message: "Bad Request";
|
|
9
|
+
};
|
|
10
|
+
readonly UNAUTHORIZED: {
|
|
11
|
+
readonly status: 401;
|
|
12
|
+
readonly message: "Unauthorized";
|
|
13
|
+
};
|
|
14
|
+
readonly FORBIDDEN: {
|
|
15
|
+
readonly status: 403;
|
|
16
|
+
readonly message: "Forbidden";
|
|
17
|
+
};
|
|
18
|
+
readonly NOT_FOUND: {
|
|
19
|
+
readonly status: 404;
|
|
20
|
+
readonly message: "Not Found";
|
|
21
|
+
};
|
|
22
|
+
readonly METHOD_NOT_ALLOWED: {
|
|
23
|
+
readonly status: 405;
|
|
24
|
+
readonly message: "Method Not Allowed";
|
|
25
|
+
};
|
|
26
|
+
readonly NOT_ACCEPTABLE: {
|
|
27
|
+
readonly status: 406;
|
|
28
|
+
readonly message: "Not Acceptable";
|
|
29
|
+
};
|
|
30
|
+
readonly CONFLICT: {
|
|
31
|
+
readonly status: 409;
|
|
32
|
+
readonly message: "Conflict";
|
|
33
|
+
};
|
|
34
|
+
readonly GONE: {
|
|
35
|
+
readonly status: 410;
|
|
36
|
+
readonly message: "Gone";
|
|
37
|
+
};
|
|
38
|
+
readonly UNPROCESSABLE_CONTENT: {
|
|
39
|
+
readonly status: 422;
|
|
40
|
+
readonly message: "Unprocessable Content";
|
|
41
|
+
};
|
|
42
|
+
readonly PRECONDITION_REQUIRED: {
|
|
43
|
+
readonly status: 428;
|
|
44
|
+
readonly message: "Precondition Required";
|
|
45
|
+
};
|
|
46
|
+
readonly TOO_MANY_REQUESTS: {
|
|
47
|
+
readonly status: 429;
|
|
48
|
+
readonly message: "Too Many Requests";
|
|
49
|
+
};
|
|
50
|
+
readonly CLIENT_CLOSED_REQUEST: {
|
|
51
|
+
readonly status: 499;
|
|
52
|
+
readonly message: "Client Closed Request";
|
|
53
|
+
};
|
|
54
|
+
readonly INTERNAL_SERVER_ERROR: {
|
|
55
|
+
readonly status: 500;
|
|
56
|
+
readonly message: "Internal Server Error";
|
|
57
|
+
};
|
|
58
|
+
readonly NOT_IMPLEMENTED: {
|
|
59
|
+
readonly status: 501;
|
|
60
|
+
readonly message: "Not Implemented";
|
|
61
|
+
};
|
|
62
|
+
readonly BAD_GATEWAY: {
|
|
63
|
+
readonly status: 502;
|
|
64
|
+
readonly message: "Bad Gateway";
|
|
65
|
+
};
|
|
66
|
+
readonly SERVICE_UNAVAILABLE: {
|
|
67
|
+
readonly status: 503;
|
|
68
|
+
readonly message: "Service Unavailable";
|
|
69
|
+
};
|
|
70
|
+
readonly GATEWAY_TIMEOUT: {
|
|
71
|
+
readonly status: 504;
|
|
72
|
+
readonly message: "Gateway Timeout";
|
|
73
|
+
};
|
|
74
|
+
}>;
|
|
75
|
+
type SilgiErrorCode = keyof typeof COMMON_ERRORS | (string & {});
|
|
76
|
+
interface SilgiErrorOptions<TData = unknown> {
|
|
77
|
+
status?: number;
|
|
78
|
+
message?: string;
|
|
79
|
+
data?: TData;
|
|
80
|
+
cause?: unknown;
|
|
81
|
+
defined?: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface SilgiErrorJSON<TCode extends string = string, TData = unknown> {
|
|
84
|
+
defined: boolean;
|
|
85
|
+
code: TCode;
|
|
86
|
+
status: number;
|
|
87
|
+
message: string;
|
|
88
|
+
data: TData;
|
|
89
|
+
}
|
|
90
|
+
declare class SilgiError<TCode extends string = string, TData = unknown> extends Error {
|
|
91
|
+
readonly code: TCode;
|
|
92
|
+
readonly status: number;
|
|
93
|
+
readonly data: TData;
|
|
94
|
+
readonly defined: boolean;
|
|
95
|
+
constructor(code: TCode, options?: SilgiErrorOptions<TData>);
|
|
96
|
+
toJSON(): SilgiErrorJSON<TCode, TData>;
|
|
97
|
+
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
98
|
+
}
|
|
99
|
+
declare function isDefinedError<TError>(error: TError): error is TError & SilgiError & {
|
|
100
|
+
defined: true;
|
|
101
|
+
};
|
|
102
|
+
declare function toSilgiError(error: unknown): SilgiError;
|
|
103
|
+
//#endregion
|
|
104
|
+
export { SilgiError, SilgiErrorCode, SilgiErrorJSON, SilgiErrorOptions, isDefinedError, toSilgiError };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
//#region src/core/error.ts
|
|
2
|
+
/**
|
|
3
|
+
* SilgiError — unified RPC error with cross-realm instanceof.
|
|
4
|
+
*/
|
|
5
|
+
const COMMON_ERRORS = /* @__PURE__ */ Object.freeze({
|
|
6
|
+
BAD_REQUEST: {
|
|
7
|
+
status: 400,
|
|
8
|
+
message: "Bad Request"
|
|
9
|
+
},
|
|
10
|
+
UNAUTHORIZED: {
|
|
11
|
+
status: 401,
|
|
12
|
+
message: "Unauthorized"
|
|
13
|
+
},
|
|
14
|
+
FORBIDDEN: {
|
|
15
|
+
status: 403,
|
|
16
|
+
message: "Forbidden"
|
|
17
|
+
},
|
|
18
|
+
NOT_FOUND: {
|
|
19
|
+
status: 404,
|
|
20
|
+
message: "Not Found"
|
|
21
|
+
},
|
|
22
|
+
METHOD_NOT_ALLOWED: {
|
|
23
|
+
status: 405,
|
|
24
|
+
message: "Method Not Allowed"
|
|
25
|
+
},
|
|
26
|
+
NOT_ACCEPTABLE: {
|
|
27
|
+
status: 406,
|
|
28
|
+
message: "Not Acceptable"
|
|
29
|
+
},
|
|
30
|
+
CONFLICT: {
|
|
31
|
+
status: 409,
|
|
32
|
+
message: "Conflict"
|
|
33
|
+
},
|
|
34
|
+
GONE: {
|
|
35
|
+
status: 410,
|
|
36
|
+
message: "Gone"
|
|
37
|
+
},
|
|
38
|
+
UNPROCESSABLE_CONTENT: {
|
|
39
|
+
status: 422,
|
|
40
|
+
message: "Unprocessable Content"
|
|
41
|
+
},
|
|
42
|
+
PRECONDITION_REQUIRED: {
|
|
43
|
+
status: 428,
|
|
44
|
+
message: "Precondition Required"
|
|
45
|
+
},
|
|
46
|
+
TOO_MANY_REQUESTS: {
|
|
47
|
+
status: 429,
|
|
48
|
+
message: "Too Many Requests"
|
|
49
|
+
},
|
|
50
|
+
CLIENT_CLOSED_REQUEST: {
|
|
51
|
+
status: 499,
|
|
52
|
+
message: "Client Closed Request"
|
|
53
|
+
},
|
|
54
|
+
INTERNAL_SERVER_ERROR: {
|
|
55
|
+
status: 500,
|
|
56
|
+
message: "Internal Server Error"
|
|
57
|
+
},
|
|
58
|
+
NOT_IMPLEMENTED: {
|
|
59
|
+
status: 501,
|
|
60
|
+
message: "Not Implemented"
|
|
61
|
+
},
|
|
62
|
+
BAD_GATEWAY: {
|
|
63
|
+
status: 502,
|
|
64
|
+
message: "Bad Gateway"
|
|
65
|
+
},
|
|
66
|
+
SERVICE_UNAVAILABLE: {
|
|
67
|
+
status: 503,
|
|
68
|
+
message: "Service Unavailable"
|
|
69
|
+
},
|
|
70
|
+
GATEWAY_TIMEOUT: {
|
|
71
|
+
status: 504,
|
|
72
|
+
message: "Gateway Timeout"
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const REGISTRY_KEY = Symbol.for("silgi.error.registry");
|
|
76
|
+
const registry = globalThis[REGISTRY_KEY] ??= /* @__PURE__ */ new WeakSet();
|
|
77
|
+
var SilgiError = class extends Error {
|
|
78
|
+
code;
|
|
79
|
+
status;
|
|
80
|
+
data;
|
|
81
|
+
defined;
|
|
82
|
+
constructor(code, options = {}) {
|
|
83
|
+
const defaults = COMMON_ERRORS[code];
|
|
84
|
+
const message = options.message ?? defaults?.message ?? code;
|
|
85
|
+
super(message, options.cause ? { cause: options.cause } : void 0);
|
|
86
|
+
this.code = code;
|
|
87
|
+
this.status = options.status ?? defaults?.status ?? 500;
|
|
88
|
+
this.data = options.data;
|
|
89
|
+
this.defined = options.defined ?? false;
|
|
90
|
+
this.name = "SilgiError";
|
|
91
|
+
}
|
|
92
|
+
toJSON() {
|
|
93
|
+
return {
|
|
94
|
+
defined: this.defined,
|
|
95
|
+
code: this.code,
|
|
96
|
+
status: this.status,
|
|
97
|
+
message: this.message,
|
|
98
|
+
data: this.data
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
static {
|
|
102
|
+
registry.add(this);
|
|
103
|
+
}
|
|
104
|
+
static [Symbol.hasInstance](instance) {
|
|
105
|
+
if (typeof instance !== "object" || instance === null) return false;
|
|
106
|
+
let proto = Object.getPrototypeOf(instance);
|
|
107
|
+
while (proto) {
|
|
108
|
+
if (proto.constructor && registry.has(proto.constructor)) return true;
|
|
109
|
+
proto = Object.getPrototypeOf(proto);
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
function isDefinedError(error) {
|
|
115
|
+
return error instanceof SilgiError && error.defined === true;
|
|
116
|
+
}
|
|
117
|
+
function toSilgiError(error) {
|
|
118
|
+
if (error instanceof SilgiError) return error;
|
|
119
|
+
return new SilgiError("INTERNAL_SERVER_ERROR", {
|
|
120
|
+
message: "Internal server error",
|
|
121
|
+
cause: error
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function isErrorStatus(status) {
|
|
125
|
+
return status >= 400;
|
|
126
|
+
}
|
|
127
|
+
function isSilgiErrorJSON(json) {
|
|
128
|
+
return typeof json === "object" && json !== null && "code" in json && "status" in json && typeof json.code === "string";
|
|
129
|
+
}
|
|
130
|
+
function fromSilgiErrorJSON(json) {
|
|
131
|
+
return new SilgiError(json.code, {
|
|
132
|
+
status: json.status,
|
|
133
|
+
message: json.message,
|
|
134
|
+
data: json.data,
|
|
135
|
+
defined: json.defined
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
export { SilgiError, fromSilgiErrorJSON, isDefinedError, isErrorStatus, isSilgiErrorJSON, toSilgiError };
|