@zenstackhq/server 3.5.5 → 3.6.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.
Files changed (105) hide show
  1. package/dist/api.cjs +2729 -4451
  2. package/dist/api.cjs.map +1 -1
  3. package/dist/api.d.cts +219 -207
  4. package/dist/api.d.mts +249 -0
  5. package/dist/api.mjs +2745 -0
  6. package/dist/api.mjs.map +1 -0
  7. package/dist/common-BjzwQE8S.d.mts +16 -0
  8. package/dist/common-Cdj4rLFr.mjs +9 -0
  9. package/dist/common-Cdj4rLFr.mjs.map +1 -0
  10. package/dist/common-D2RyWTAZ.cjs +14 -0
  11. package/dist/common-D2RyWTAZ.cjs.map +1 -0
  12. package/dist/common-D3fx-IHt.d.cts +16 -0
  13. package/dist/elysia.cjs +46 -114
  14. package/dist/elysia.cjs.map +1 -1
  15. package/dist/elysia.d.cts +37 -36
  16. package/dist/elysia.d.mts +54 -0
  17. package/dist/elysia.mjs +48 -0
  18. package/dist/elysia.mjs.map +1 -0
  19. package/dist/express.cjs +40 -110
  20. package/dist/express.cjs.map +1 -1
  21. package/dist/express.d.cts +21 -20
  22. package/dist/express.d.mts +32 -0
  23. package/dist/express.mjs +42 -0
  24. package/dist/express.mjs.map +1 -0
  25. package/dist/fastify.cjs +36 -100
  26. package/dist/fastify.cjs.map +1 -1
  27. package/dist/fastify.d.cts +15 -14
  28. package/dist/fastify.d.mts +23 -0
  29. package/dist/fastify.mjs +36 -0
  30. package/dist/fastify.mjs.map +1 -0
  31. package/dist/hono.cjs +31 -108
  32. package/dist/hono.cjs.map +1 -1
  33. package/dist/hono.d.cts +11 -10
  34. package/dist/hono.d.mts +19 -0
  35. package/dist/hono.mjs +33 -0
  36. package/dist/hono.mjs.map +1 -0
  37. package/dist/next.cjs +81 -169
  38. package/dist/next.cjs.map +1 -1
  39. package/dist/next.d.cts +32 -29
  40. package/dist/{next.d.ts → next.d.mts} +32 -29
  41. package/dist/next.mjs +86 -0
  42. package/dist/next.mjs.map +1 -0
  43. package/dist/nuxt.cjs +414 -104
  44. package/dist/nuxt.cjs.map +1 -1
  45. package/dist/nuxt.d.cts +538 -12
  46. package/dist/nuxt.d.mts +545 -0
  47. package/dist/nuxt.mjs +416 -0
  48. package/dist/nuxt.mjs.map +1 -0
  49. package/dist/openapi-BPFL4Hn6.mjs +585 -0
  50. package/dist/openapi-BPFL4Hn6.mjs.map +1 -0
  51. package/dist/openapi-BUzfCKi-.cjs +586 -0
  52. package/dist/openapi-BUzfCKi-.cjs.map +1 -0
  53. package/dist/spec-utils-C7vlChMD.cjs +278 -0
  54. package/dist/spec-utils-C7vlChMD.cjs.map +1 -0
  55. package/dist/spec-utils-Syk4SLCX.mjs +200 -0
  56. package/dist/spec-utils-Syk4SLCX.mjs.map +1 -0
  57. package/dist/sveltekit.cjs +87 -188
  58. package/dist/sveltekit.cjs.map +1 -1
  59. package/dist/sveltekit.d.cts +24 -22
  60. package/dist/sveltekit.d.mts +43 -0
  61. package/dist/sveltekit.mjs +88 -0
  62. package/dist/sveltekit.mjs.map +1 -0
  63. package/dist/tanstack-start.cjs +59 -133
  64. package/dist/tanstack-start.cjs.map +1 -1
  65. package/dist/tanstack-start.d.cts +19 -14
  66. package/dist/tanstack-start.d.mts +37 -0
  67. package/dist/tanstack-start.mjs +60 -0
  68. package/dist/tanstack-start.mjs.map +1 -0
  69. package/dist/types-6NFtxov5.d.mts +74 -0
  70. package/dist/types-DYdFPTkH.d.cts +74 -0
  71. package/dist/utils-B9NX7OcP.cjs +85 -0
  72. package/dist/utils-B9NX7OcP.cjs.map +1 -0
  73. package/dist/utils-Doc_CQNd.mjs +39 -0
  74. package/dist/utils-Doc_CQNd.mjs.map +1 -0
  75. package/package.json +28 -27
  76. package/dist/api.d.ts +0 -237
  77. package/dist/api.js +0 -4437
  78. package/dist/api.js.map +0 -1
  79. package/dist/common-Cuu8bjzK.d.cts +0 -14
  80. package/dist/common-WHbiInuf.d.ts +0 -14
  81. package/dist/elysia.d.ts +0 -53
  82. package/dist/elysia.js +0 -82
  83. package/dist/elysia.js.map +0 -1
  84. package/dist/express.d.ts +0 -31
  85. package/dist/express.js +0 -78
  86. package/dist/express.js.map +0 -1
  87. package/dist/fastify.d.ts +0 -22
  88. package/dist/fastify.js +0 -68
  89. package/dist/fastify.js.map +0 -1
  90. package/dist/hono.d.ts +0 -18
  91. package/dist/hono.js +0 -76
  92. package/dist/hono.js.map +0 -1
  93. package/dist/next.js +0 -140
  94. package/dist/next.js.map +0 -1
  95. package/dist/nuxt.d.ts +0 -19
  96. package/dist/nuxt.js +0 -73
  97. package/dist/nuxt.js.map +0 -1
  98. package/dist/sveltekit.d.ts +0 -41
  99. package/dist/sveltekit.js +0 -156
  100. package/dist/sveltekit.js.map +0 -1
  101. package/dist/tanstack-start.d.ts +0 -32
  102. package/dist/tanstack-start.js +0 -104
  103. package/dist/tanstack-start.js.map +0 -1
  104. package/dist/types-CU_PWKr9.d.cts +0 -72
  105. package/dist/types-CU_PWKr9.d.ts +0 -72
@@ -0,0 +1,16 @@
1
+ import { t as ApiHandler } from "./types-6NFtxov5.mjs";
2
+ import { SchemaDef } from "@zenstackhq/orm/schema";
3
+
4
+ //#region src/adapter/common.d.ts
5
+ /**
6
+ * Options common to all adapters
7
+ */
8
+ interface CommonAdapterOptions<Schema extends SchemaDef> {
9
+ /**
10
+ * The API handler to process requests
11
+ */
12
+ apiHandler: ApiHandler<Schema>;
13
+ }
14
+ //#endregion
15
+ export { CommonAdapterOptions as t };
16
+ //# sourceMappingURL=common-BjzwQE8S.d.mts.map
@@ -0,0 +1,9 @@
1
+ import { n as log } from "./utils-Doc_CQNd.mjs";
2
+ //#region src/adapter/common.ts
3
+ function logInternalError(logger, err) {
4
+ log(logger, "error", `An unhandled error occurred while processing the request: ${err}${err instanceof Error ? "\n" + err.stack : ""}`);
5
+ }
6
+ //#endregion
7
+ export { logInternalError as t };
8
+
9
+ //# sourceMappingURL=common-Cdj4rLFr.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-Cdj4rLFr.mjs","names":[],"sources":["../src/adapter/common.ts"],"sourcesContent":["import type { SchemaDef } from '@zenstackhq/orm/schema';\nimport { log } from '../api/utils';\nimport type { ApiHandler, LogConfig } from '../types';\n\n/**\n * Options common to all adapters\n */\nexport interface CommonAdapterOptions<Schema extends SchemaDef> {\n /**\n * The API handler to process requests\n */\n apiHandler: ApiHandler<Schema>;\n}\n\nexport function logInternalError(logger: LogConfig | undefined, err: unknown) {\n log(\n logger,\n 'error',\n `An unhandled error occurred while processing the request: ${err}${err instanceof Error ? '\\n' + err.stack : ''}`,\n );\n}\n"],"mappings":";;AAcA,SAAgB,iBAAiB,QAA+B,KAAc;AAC1E,KACI,QACA,SACA,6DAA6D,MAAM,eAAe,QAAQ,OAAO,IAAI,QAAQ,KAChH"}
@@ -0,0 +1,14 @@
1
+ const require_utils = require("./utils-B9NX7OcP.cjs");
2
+ //#region src/adapter/common.ts
3
+ function logInternalError(logger, err) {
4
+ require_utils.log(logger, "error", `An unhandled error occurred while processing the request: ${err}${err instanceof Error ? "\n" + err.stack : ""}`);
5
+ }
6
+ //#endregion
7
+ Object.defineProperty(exports, "logInternalError", {
8
+ enumerable: true,
9
+ get: function() {
10
+ return logInternalError;
11
+ }
12
+ });
13
+
14
+ //# sourceMappingURL=common-D2RyWTAZ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-D2RyWTAZ.cjs","names":[],"sources":["../src/adapter/common.ts"],"sourcesContent":["import type { SchemaDef } from '@zenstackhq/orm/schema';\nimport { log } from '../api/utils';\nimport type { ApiHandler, LogConfig } from '../types';\n\n/**\n * Options common to all adapters\n */\nexport interface CommonAdapterOptions<Schema extends SchemaDef> {\n /**\n * The API handler to process requests\n */\n apiHandler: ApiHandler<Schema>;\n}\n\nexport function logInternalError(logger: LogConfig | undefined, err: unknown) {\n log(\n logger,\n 'error',\n `An unhandled error occurred while processing the request: ${err}${err instanceof Error ? '\\n' + err.stack : ''}`,\n );\n}\n"],"mappings":";;AAcA,SAAgB,iBAAiB,QAA+B,KAAc;AAC1E,eAAA,IACI,QACA,SACA,6DAA6D,MAAM,eAAe,QAAQ,OAAO,IAAI,QAAQ,KAChH"}
@@ -0,0 +1,16 @@
1
+ import { t as ApiHandler } from "./types-DYdFPTkH.cjs";
2
+ import { SchemaDef } from "@zenstackhq/orm/schema";
3
+
4
+ //#region src/adapter/common.d.ts
5
+ /**
6
+ * Options common to all adapters
7
+ */
8
+ interface CommonAdapterOptions<Schema extends SchemaDef> {
9
+ /**
10
+ * The API handler to process requests
11
+ */
12
+ apiHandler: ApiHandler<Schema>;
13
+ }
14
+ //#endregion
15
+ export { CommonAdapterOptions as t };
16
+ //# sourceMappingURL=common-D3fx-IHt.d.cts.map
package/dist/elysia.cjs CHANGED
@@ -1,117 +1,49 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/adapter/elysia/index.ts
32
- var elysia_exports = {};
33
- __export(elysia_exports, {
34
- createElysiaHandler: () => createElysiaHandler
35
- });
36
- module.exports = __toCommonJS(elysia_exports);
37
-
38
- // src/api/utils.ts
39
- var import_decimal = require("decimal.js");
40
- var import_superjson = __toESM(require("superjson"), 1);
41
- var import_ts_pattern = require("ts-pattern");
42
- var import_v3 = require("zod-validation-error/v3");
43
- var import_v4 = require("zod-validation-error/v4");
44
- function log(logger, level, message, error) {
45
- if (!logger) {
46
- return;
47
- }
48
- const getMessage = typeof message === "function" ? message : () => message;
49
- if (typeof logger === "function") {
50
- logger(level, getMessage(), error);
51
- } else if (logger.includes(level)) {
52
- const logFn = (0, import_ts_pattern.match)(level).with("debug", () => console.debug).with("info", () => console.info).with("warn", () => console.warn).with("error", () => console.error).exhaustive();
53
- logFn(`@zenstackhq/server: [${level}] ${getMessage()}${error ? `
54
- ${error}` : ""}`);
55
- }
56
- }
57
- __name(log, "log");
58
-
59
- // src/adapter/common.ts
60
- function logInternalError(logger, err) {
61
- log(logger, "error", `An unhandled error occurred while processing the request: ${err}${err instanceof Error ? "\n" + err.stack : ""}`);
62
- }
63
- __name(logInternalError, "logInternalError");
64
-
65
- // src/adapter/elysia/handler.ts
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_common = require("./common-D2RyWTAZ.cjs");
3
+ require("elysia");
4
+ //#region src/adapter/elysia/handler.ts
5
+ /**
6
+ * Creates an Elysia middleware handler for ZenStack.
7
+ * This handler provides automatic CRUD APIs through Elysia's routing system.
8
+ */
66
9
  function createElysiaHandler(options) {
67
- return async (app) => {
68
- app.all("/*", async (ctx) => {
69
- const { query, body, set, request } = ctx;
70
- const client = await options.getClient(ctx);
71
- if (!client) {
72
- set.status = 500;
73
- return {
74
- message: "unable to get ZenStackClient from request context"
75
- };
76
- }
77
- const url = new URL(request.url);
78
- let path = url.pathname;
79
- if (options.basePath && path.startsWith(options.basePath)) {
80
- path = path.slice(options.basePath.length);
81
- if (!path.startsWith("/")) {
82
- path = "/" + path;
83
- }
84
- }
85
- if (!path || path === "/") {
86
- set.status = 400;
87
- return {
88
- message: "missing path parameter"
89
- };
90
- }
91
- try {
92
- const r = await options.apiHandler.handleRequest({
93
- method: request.method,
94
- path,
95
- query,
96
- requestBody: body,
97
- client
98
- });
99
- set.status = r.status;
100
- return r.body;
101
- } catch (err) {
102
- set.status = 500;
103
- logInternalError(options.apiHandler.log, err);
104
- return {
105
- message: "An internal server error occurred"
106
- };
107
- }
108
- });
109
- return app;
110
- };
10
+ return async (app) => {
11
+ app.all("/*", async (ctx) => {
12
+ const { query, body, set, request } = ctx;
13
+ const client = await options.getClient(ctx);
14
+ if (!client) {
15
+ set.status = 500;
16
+ return { message: "unable to get ZenStackClient from request context" };
17
+ }
18
+ let path = new URL(request.url).pathname;
19
+ if (options.basePath && path.startsWith(options.basePath)) {
20
+ path = path.slice(options.basePath.length);
21
+ if (!path.startsWith("/")) path = "/" + path;
22
+ }
23
+ if (!path || path === "/") {
24
+ set.status = 400;
25
+ return { message: "missing path parameter" };
26
+ }
27
+ try {
28
+ const r = await options.apiHandler.handleRequest({
29
+ method: request.method,
30
+ path,
31
+ query,
32
+ requestBody: body,
33
+ client
34
+ });
35
+ set.status = r.status;
36
+ return r.body;
37
+ } catch (err) {
38
+ set.status = 500;
39
+ require_common.logInternalError(options.apiHandler.log, err);
40
+ return { message: "An internal server error occurred" };
41
+ }
42
+ });
43
+ return app;
44
+ };
111
45
  }
112
- __name(createElysiaHandler, "createElysiaHandler");
113
- // Annotate the CommonJS export names for ESM import in node:
114
- 0 && (module.exports = {
115
- createElysiaHandler
116
- });
46
+ //#endregion
47
+ exports.createElysiaHandler = createElysiaHandler;
48
+
117
49
  //# sourceMappingURL=elysia.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/adapter/elysia/index.ts","../src/api/utils.ts","../src/adapter/common.ts","../src/adapter/elysia/handler.ts"],"sourcesContent":["export { createElysiaHandler, type ElysiaOptions } from './handler';\n","import { Decimal } from 'decimal.js';\nimport SuperJSON from 'superjson';\nimport { match } from 'ts-pattern';\nimport { ZodError } from 'zod';\nimport { fromError as fromError3 } from 'zod-validation-error/v3';\nimport { fromError as fromError4 } from 'zod-validation-error/v4';\nimport type { LogConfig, LogLevel } from '../types';\n\nexport function log(logger: LogConfig | undefined, level: LogLevel, message: string | (() => string), error?: unknown) {\n if (!logger) {\n return;\n }\n\n const getMessage = typeof message === 'function' ? message : () => message;\n\n if (typeof logger === 'function') {\n logger(level, getMessage(), error);\n } else if (logger.includes(level)) {\n const logFn = match(level)\n .with('debug', () => console.debug)\n .with('info', () => console.info)\n .with('warn', () => console.warn)\n .with('error', () => console.error)\n .exhaustive();\n logFn(`@zenstackhq/server: [${level}] ${getMessage()}${error ? `\\n${error}` : ''}`);\n }\n}\n\n/**\n * Registers custom superjson serializers.\n */\nexport function registerCustomSerializers() {\n SuperJSON.registerCustom<Decimal, string>(\n {\n isApplicable: (v): v is Decimal => Decimal.isDecimal(v),\n serialize: (v) => v.toJSON(),\n deserialize: (v) => new Decimal(v),\n },\n 'Decimal',\n );\n\n // `Buffer` is not available in edge runtime\n if (globalThis.Buffer) {\n SuperJSON.registerCustom<Buffer, string>(\n {\n isApplicable: (v): v is Buffer => Buffer.isBuffer(v),\n serialize: (v) => v.toString('base64'),\n deserialize: (v) => Buffer.from(v, 'base64'),\n },\n 'Bytes',\n );\n }\n}\n\n/**\n * Format ZodError into a readable string\n */\nexport function getZodErrorMessage(error: ZodError): string {\n if ('_zod' in error) {\n return fromError4(error).toString();\n } else {\n return fromError3(error).toString();\n }\n}\n","import type { SchemaDef } from '@zenstackhq/orm/schema';\nimport { log } from '../api/utils';\nimport type { ApiHandler, LogConfig } from '../types';\n\n/**\n * Options common to all adapters\n */\nexport interface CommonAdapterOptions<Schema extends SchemaDef> {\n /**\n * The API handler to process requests\n */\n apiHandler: ApiHandler<Schema>;\n}\n\nexport function logInternalError(logger: LogConfig | undefined, err: unknown) {\n log(\n logger,\n 'error',\n `An unhandled error occurred while processing the request: ${err}${err instanceof Error ? '\\n' + err.stack : ''}`,\n );\n}\n","import type { ClientContract } from '@zenstackhq/orm';\nimport type { SchemaDef } from '@zenstackhq/orm/schema';\nimport { Elysia, type Context as ElysiaContext } from 'elysia';\nimport { logInternalError, type CommonAdapterOptions } from '../common';\n\n/**\n * Options for initializing an Elysia middleware.\n */\nexport interface ElysiaOptions<Schema extends SchemaDef> extends CommonAdapterOptions<Schema> {\n /**\n * Callback method for getting a ZenStackClient instance for the given request context.\n */\n getClient: (context: ElysiaContext) => Promise<ClientContract<Schema>> | ClientContract<Schema>;\n\n /**\n * Optional base path to strip from the request path before passing to the API handler.\n */\n basePath?: string;\n}\n\n/**\n * Creates an Elysia middleware handler for ZenStack.\n * This handler provides automatic CRUD APIs through Elysia's routing system.\n */\nexport function createElysiaHandler<Schema extends SchemaDef>(options: ElysiaOptions<Schema>) {\n return async (app: Elysia) => {\n app.all('/*', async (ctx: ElysiaContext) => {\n const { query, body, set, request } = ctx;\n const client = await options.getClient(ctx);\n if (!client) {\n set.status = 500;\n return {\n message: 'unable to get ZenStackClient from request context',\n };\n }\n\n const url = new URL(request.url);\n let path = url.pathname;\n\n if (options.basePath && path.startsWith(options.basePath)) {\n path = path.slice(options.basePath.length);\n if (!path.startsWith('/')) {\n path = '/' + path;\n }\n }\n\n if (!path || path === '/') {\n set.status = 400;\n return {\n message: 'missing path parameter',\n };\n }\n\n try {\n const r = await options.apiHandler.handleRequest({\n method: request.method,\n path,\n query,\n requestBody: body,\n client,\n });\n\n set.status = r.status;\n return r.body;\n } catch (err) {\n set.status = 500;\n logInternalError(options.apiHandler.log, err);\n return {\n message: 'An internal server error occurred',\n };\n }\n });\n\n return app;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,qBAAwB;AACxB,uBAAsB;AACtB,wBAAsB;AAEtB,gBAAwC;AACxC,gBAAwC;AAGjC,SAASA,IAAIC,QAA+BC,OAAiBC,SAAkCC,OAAe;AACjH,MAAI,CAACH,QAAQ;AACT;EACJ;AAEA,QAAMI,aAAa,OAAOF,YAAY,aAAaA,UAAU,MAAMA;AAEnE,MAAI,OAAOF,WAAW,YAAY;AAC9BA,WAAOC,OAAOG,WAAAA,GAAcD,KAAAA;EAChC,WAAWH,OAAOK,SAASJ,KAAAA,GAAQ;AAC/B,UAAMK,YAAQC,yBAAMN,KAAAA,EACfO,KAAK,SAAS,MAAMC,QAAQC,KAAK,EACjCF,KAAK,QAAQ,MAAMC,QAAQE,IAAI,EAC/BH,KAAK,QAAQ,MAAMC,QAAQG,IAAI,EAC/BJ,KAAK,SAAS,MAAMC,QAAQN,KAAK,EACjCU,WAAU;AACfP,UAAM,wBAAwBL,KAAAA,KAAUG,WAAAA,CAAAA,GAAeD,QAAQ;EAAKA,KAAAA,KAAU,EAAA,EAAI;EACtF;AACJ;AAlBgBJ;;;ACMT,SAASe,iBAAiBC,QAA+BC,KAAY;AACxEC,MACIF,QACA,SACA,6DAA6DC,GAAAA,GAAMA,eAAeE,QAAQ,OAAOF,IAAIG,QAAQ,EAAA,EAAI;AAEzH;AANgBL;;;ACUT,SAASM,oBAA8CC,SAA8B;AACxF,SAAO,OAAOC,QAAAA;AACVA,QAAIC,IAAI,MAAM,OAAOC,QAAAA;AACjB,YAAM,EAAEC,OAAOC,MAAMC,KAAKC,QAAO,IAAKJ;AACtC,YAAMK,SAAS,MAAMR,QAAQS,UAAUN,GAAAA;AACvC,UAAI,CAACK,QAAQ;AACTF,YAAII,SAAS;AACb,eAAO;UACHC,SAAS;QACb;MACJ;AAEA,YAAMC,MAAM,IAAIC,IAAIN,QAAQK,GAAG;AAC/B,UAAIE,OAAOF,IAAIG;AAEf,UAAIf,QAAQgB,YAAYF,KAAKG,WAAWjB,QAAQgB,QAAQ,GAAG;AACvDF,eAAOA,KAAKI,MAAMlB,QAAQgB,SAASG,MAAM;AACzC,YAAI,CAACL,KAAKG,WAAW,GAAA,GAAM;AACvBH,iBAAO,MAAMA;QACjB;MACJ;AAEA,UAAI,CAACA,QAAQA,SAAS,KAAK;AACvBR,YAAII,SAAS;AACb,eAAO;UACHC,SAAS;QACb;MACJ;AAEA,UAAI;AACA,cAAMS,IAAI,MAAMpB,QAAQqB,WAAWC,cAAc;UAC7CC,QAAQhB,QAAQgB;UAChBT;UACAV;UACAoB,aAAanB;UACbG;QACJ,CAAA;AAEAF,YAAII,SAASU,EAAEV;AACf,eAAOU,EAAEf;MACb,SAASoB,KAAK;AACVnB,YAAII,SAAS;AACbgB,yBAAiB1B,QAAQqB,WAAWM,KAAKF,GAAAA;AACzC,eAAO;UACHd,SAAS;QACb;MACJ;IACJ,CAAA;AAEA,WAAOV;EACX;AACJ;AAnDgBF;","names":["log","logger","level","message","error","getMessage","includes","logFn","match","with","console","debug","info","warn","exhaustive","logInternalError","logger","err","log","Error","stack","createElysiaHandler","options","app","all","ctx","query","body","set","request","client","getClient","status","message","url","URL","path","pathname","basePath","startsWith","slice","length","r","apiHandler","handleRequest","method","requestBody","err","logInternalError","log"]}
1
+ {"version":3,"file":"elysia.cjs","names":[],"sources":["../src/adapter/elysia/handler.ts"],"sourcesContent":["import type { ClientContract } from '@zenstackhq/orm';\nimport type { SchemaDef } from '@zenstackhq/orm/schema';\nimport { Elysia, type Context as ElysiaContext } from 'elysia';\nimport { logInternalError, type CommonAdapterOptions } from '../common';\n\n/**\n * Options for initializing an Elysia middleware.\n */\nexport interface ElysiaOptions<Schema extends SchemaDef> extends CommonAdapterOptions<Schema> {\n /**\n * Callback method for getting a ZenStackClient instance for the given request context.\n */\n getClient: (context: ElysiaContext) => Promise<ClientContract<Schema>> | ClientContract<Schema>;\n\n /**\n * Optional base path to strip from the request path before passing to the API handler.\n */\n basePath?: string;\n}\n\n/**\n * Creates an Elysia middleware handler for ZenStack.\n * This handler provides automatic CRUD APIs through Elysia's routing system.\n */\nexport function createElysiaHandler<Schema extends SchemaDef>(options: ElysiaOptions<Schema>) {\n return async (app: Elysia) => {\n app.all('/*', async (ctx: ElysiaContext) => {\n const { query, body, set, request } = ctx;\n const client = await options.getClient(ctx);\n if (!client) {\n set.status = 500;\n return {\n message: 'unable to get ZenStackClient from request context',\n };\n }\n\n const url = new URL(request.url);\n let path = url.pathname;\n\n if (options.basePath && path.startsWith(options.basePath)) {\n path = path.slice(options.basePath.length);\n if (!path.startsWith('/')) {\n path = '/' + path;\n }\n }\n\n if (!path || path === '/') {\n set.status = 400;\n return {\n message: 'missing path parameter',\n };\n }\n\n try {\n const r = await options.apiHandler.handleRequest({\n method: request.method,\n path,\n query,\n requestBody: body,\n client,\n });\n\n set.status = r.status;\n return r.body;\n } catch (err) {\n set.status = 500;\n logInternalError(options.apiHandler.log, err);\n return {\n message: 'An internal server error occurred',\n };\n }\n });\n\n return app;\n };\n}\n"],"mappings":";;;;;;;;AAwBA,SAAgB,oBAA8C,SAAgC;AAC1F,QAAO,OAAO,QAAgB;AAC1B,MAAI,IAAI,MAAM,OAAO,QAAuB;GACxC,MAAM,EAAE,OAAO,MAAM,KAAK,YAAY;GACtC,MAAM,SAAS,MAAM,QAAQ,UAAU,IAAI;AAC3C,OAAI,CAAC,QAAQ;AACT,QAAI,SAAS;AACb,WAAO,EACH,SAAS,qDACZ;;GAIL,IAAI,OADQ,IAAI,IAAI,QAAQ,IAAI,CACjB;AAEf,OAAI,QAAQ,YAAY,KAAK,WAAW,QAAQ,SAAS,EAAE;AACvD,WAAO,KAAK,MAAM,QAAQ,SAAS,OAAO;AAC1C,QAAI,CAAC,KAAK,WAAW,IAAI,CACrB,QAAO,MAAM;;AAIrB,OAAI,CAAC,QAAQ,SAAS,KAAK;AACvB,QAAI,SAAS;AACb,WAAO,EACH,SAAS,0BACZ;;AAGL,OAAI;IACA,MAAM,IAAI,MAAM,QAAQ,WAAW,cAAc;KAC7C,QAAQ,QAAQ;KAChB;KACA;KACA,aAAa;KACb;KACH,CAAC;AAEF,QAAI,SAAS,EAAE;AACf,WAAO,EAAE;YACJ,KAAK;AACV,QAAI,SAAS;AACb,mBAAA,iBAAiB,QAAQ,WAAW,KAAK,IAAI;AAC7C,WAAO,EACH,SAAS,qCACZ;;IAEP;AAEF,SAAO"}
package/dist/elysia.d.cts CHANGED
@@ -1,53 +1,54 @@
1
- import { ClientContract } from '@zenstackhq/orm';
2
- import { SchemaDef } from '@zenstackhq/orm/schema';
3
- import { Context, Elysia } from 'elysia';
4
- import { C as CommonAdapterOptions } from './common-Cuu8bjzK.cjs';
5
- import './types-CU_PWKr9.cjs';
1
+ import { t as CommonAdapterOptions } from "./common-D3fx-IHt.cjs";
2
+ import { ClientContract } from "@zenstackhq/orm";
3
+ import { SchemaDef } from "@zenstackhq/orm/schema";
4
+ import { Context, Elysia } from "elysia";
6
5
 
6
+ //#region src/adapter/elysia/handler.d.ts
7
7
  /**
8
8
  * Options for initializing an Elysia middleware.
9
9
  */
10
10
  interface ElysiaOptions<Schema extends SchemaDef> extends CommonAdapterOptions<Schema> {
11
- /**
12
- * Callback method for getting a ZenStackClient instance for the given request context.
13
- */
14
- getClient: (context: Context) => Promise<ClientContract<Schema>> | ClientContract<Schema>;
15
- /**
16
- * Optional base path to strip from the request path before passing to the API handler.
17
- */
18
- basePath?: string;
11
+ /**
12
+ * Callback method for getting a ZenStackClient instance for the given request context.
13
+ */
14
+ getClient: (context: Context) => Promise<ClientContract<Schema>> | ClientContract<Schema>;
15
+ /**
16
+ * Optional base path to strip from the request path before passing to the API handler.
17
+ */
18
+ basePath?: string;
19
19
  }
20
20
  /**
21
21
  * Creates an Elysia middleware handler for ZenStack.
22
22
  * This handler provides automatic CRUD APIs through Elysia's routing system.
23
23
  */
24
24
  declare function createElysiaHandler<Schema extends SchemaDef>(options: ElysiaOptions<Schema>): (app: Elysia) => Promise<Elysia<"", {
25
- decorator: {};
26
- store: {};
27
- derive: {};
28
- resolve: {};
25
+ decorator: {};
26
+ store: {};
27
+ derive: {};
28
+ resolve: {};
29
29
  }, {
30
- typebox: {};
31
- error: {};
30
+ typebox: {};
31
+ error: {};
32
32
  }, {
33
- schema: {};
34
- standaloneSchema: {};
35
- macro: {};
36
- macroFn: {};
37
- parser: {};
38
- response: {};
33
+ schema: {};
34
+ standaloneSchema: {};
35
+ macro: {};
36
+ macroFn: {};
37
+ parser: {};
38
+ response: {};
39
39
  }, {}, {
40
- derive: {};
41
- resolve: {};
42
- schema: {};
43
- standaloneSchema: {};
44
- response: {};
40
+ derive: {};
41
+ resolve: {};
42
+ schema: {};
43
+ standaloneSchema: {};
44
+ response: {};
45
45
  }, {
46
- derive: {};
47
- resolve: {};
48
- schema: {};
49
- standaloneSchema: {};
50
- response: {};
46
+ derive: {};
47
+ resolve: {};
48
+ schema: {};
49
+ standaloneSchema: {};
50
+ response: {};
51
51
  }>>;
52
-
52
+ //#endregion
53
53
  export { type ElysiaOptions, createElysiaHandler };
54
+ //# sourceMappingURL=elysia.d.cts.map
@@ -0,0 +1,54 @@
1
+ import { t as CommonAdapterOptions } from "./common-BjzwQE8S.mjs";
2
+ import { ClientContract } from "@zenstackhq/orm";
3
+ import { SchemaDef } from "@zenstackhq/orm/schema";
4
+ import { Context, Elysia } from "elysia";
5
+
6
+ //#region src/adapter/elysia/handler.d.ts
7
+ /**
8
+ * Options for initializing an Elysia middleware.
9
+ */
10
+ interface ElysiaOptions<Schema extends SchemaDef> extends CommonAdapterOptions<Schema> {
11
+ /**
12
+ * Callback method for getting a ZenStackClient instance for the given request context.
13
+ */
14
+ getClient: (context: Context) => Promise<ClientContract<Schema>> | ClientContract<Schema>;
15
+ /**
16
+ * Optional base path to strip from the request path before passing to the API handler.
17
+ */
18
+ basePath?: string;
19
+ }
20
+ /**
21
+ * Creates an Elysia middleware handler for ZenStack.
22
+ * This handler provides automatic CRUD APIs through Elysia's routing system.
23
+ */
24
+ declare function createElysiaHandler<Schema extends SchemaDef>(options: ElysiaOptions<Schema>): (app: Elysia) => Promise<Elysia<"", {
25
+ decorator: {};
26
+ store: {};
27
+ derive: {};
28
+ resolve: {};
29
+ }, {
30
+ typebox: {};
31
+ error: {};
32
+ }, {
33
+ schema: {};
34
+ standaloneSchema: {};
35
+ macro: {};
36
+ macroFn: {};
37
+ parser: {};
38
+ response: {};
39
+ }, {}, {
40
+ derive: {};
41
+ resolve: {};
42
+ schema: {};
43
+ standaloneSchema: {};
44
+ response: {};
45
+ }, {
46
+ derive: {};
47
+ resolve: {};
48
+ schema: {};
49
+ standaloneSchema: {};
50
+ response: {};
51
+ }>>;
52
+ //#endregion
53
+ export { type ElysiaOptions, createElysiaHandler };
54
+ //# sourceMappingURL=elysia.d.mts.map
@@ -0,0 +1,48 @@
1
+ import { t as logInternalError } from "./common-Cdj4rLFr.mjs";
2
+ import "elysia";
3
+ //#region src/adapter/elysia/handler.ts
4
+ /**
5
+ * Creates an Elysia middleware handler for ZenStack.
6
+ * This handler provides automatic CRUD APIs through Elysia's routing system.
7
+ */
8
+ function createElysiaHandler(options) {
9
+ return async (app) => {
10
+ app.all("/*", async (ctx) => {
11
+ const { query, body, set, request } = ctx;
12
+ const client = await options.getClient(ctx);
13
+ if (!client) {
14
+ set.status = 500;
15
+ return { message: "unable to get ZenStackClient from request context" };
16
+ }
17
+ let path = new URL(request.url).pathname;
18
+ if (options.basePath && path.startsWith(options.basePath)) {
19
+ path = path.slice(options.basePath.length);
20
+ if (!path.startsWith("/")) path = "/" + path;
21
+ }
22
+ if (!path || path === "/") {
23
+ set.status = 400;
24
+ return { message: "missing path parameter" };
25
+ }
26
+ try {
27
+ const r = await options.apiHandler.handleRequest({
28
+ method: request.method,
29
+ path,
30
+ query,
31
+ requestBody: body,
32
+ client
33
+ });
34
+ set.status = r.status;
35
+ return r.body;
36
+ } catch (err) {
37
+ set.status = 500;
38
+ logInternalError(options.apiHandler.log, err);
39
+ return { message: "An internal server error occurred" };
40
+ }
41
+ });
42
+ return app;
43
+ };
44
+ }
45
+ //#endregion
46
+ export { createElysiaHandler };
47
+
48
+ //# sourceMappingURL=elysia.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elysia.mjs","names":[],"sources":["../src/adapter/elysia/handler.ts"],"sourcesContent":["import type { ClientContract } from '@zenstackhq/orm';\nimport type { SchemaDef } from '@zenstackhq/orm/schema';\nimport { Elysia, type Context as ElysiaContext } from 'elysia';\nimport { logInternalError, type CommonAdapterOptions } from '../common';\n\n/**\n * Options for initializing an Elysia middleware.\n */\nexport interface ElysiaOptions<Schema extends SchemaDef> extends CommonAdapterOptions<Schema> {\n /**\n * Callback method for getting a ZenStackClient instance for the given request context.\n */\n getClient: (context: ElysiaContext) => Promise<ClientContract<Schema>> | ClientContract<Schema>;\n\n /**\n * Optional base path to strip from the request path before passing to the API handler.\n */\n basePath?: string;\n}\n\n/**\n * Creates an Elysia middleware handler for ZenStack.\n * This handler provides automatic CRUD APIs through Elysia's routing system.\n */\nexport function createElysiaHandler<Schema extends SchemaDef>(options: ElysiaOptions<Schema>) {\n return async (app: Elysia) => {\n app.all('/*', async (ctx: ElysiaContext) => {\n const { query, body, set, request } = ctx;\n const client = await options.getClient(ctx);\n if (!client) {\n set.status = 500;\n return {\n message: 'unable to get ZenStackClient from request context',\n };\n }\n\n const url = new URL(request.url);\n let path = url.pathname;\n\n if (options.basePath && path.startsWith(options.basePath)) {\n path = path.slice(options.basePath.length);\n if (!path.startsWith('/')) {\n path = '/' + path;\n }\n }\n\n if (!path || path === '/') {\n set.status = 400;\n return {\n message: 'missing path parameter',\n };\n }\n\n try {\n const r = await options.apiHandler.handleRequest({\n method: request.method,\n path,\n query,\n requestBody: body,\n client,\n });\n\n set.status = r.status;\n return r.body;\n } catch (err) {\n set.status = 500;\n logInternalError(options.apiHandler.log, err);\n return {\n message: 'An internal server error occurred',\n };\n }\n });\n\n return app;\n };\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,oBAA8C,SAAgC;AAC1F,QAAO,OAAO,QAAgB;AAC1B,MAAI,IAAI,MAAM,OAAO,QAAuB;GACxC,MAAM,EAAE,OAAO,MAAM,KAAK,YAAY;GACtC,MAAM,SAAS,MAAM,QAAQ,UAAU,IAAI;AAC3C,OAAI,CAAC,QAAQ;AACT,QAAI,SAAS;AACb,WAAO,EACH,SAAS,qDACZ;;GAIL,IAAI,OADQ,IAAI,IAAI,QAAQ,IAAI,CACjB;AAEf,OAAI,QAAQ,YAAY,KAAK,WAAW,QAAQ,SAAS,EAAE;AACvD,WAAO,KAAK,MAAM,QAAQ,SAAS,OAAO;AAC1C,QAAI,CAAC,KAAK,WAAW,IAAI,CACrB,QAAO,MAAM;;AAIrB,OAAI,CAAC,QAAQ,SAAS,KAAK;AACvB,QAAI,SAAS;AACb,WAAO,EACH,SAAS,0BACZ;;AAGL,OAAI;IACA,MAAM,IAAI,MAAM,QAAQ,WAAW,cAAc;KAC7C,QAAQ,QAAQ;KAChB;KACA;KACA,aAAa;KACb;KACH,CAAC;AAEF,QAAI,SAAS,EAAE;AACf,WAAO,EAAE;YACJ,KAAK;AACV,QAAI,SAAS;AACb,qBAAiB,QAAQ,WAAW,KAAK,IAAI;AAC7C,WAAO,EACH,SAAS,qCACZ;;IAEP;AAEF,SAAO"}
package/dist/express.cjs CHANGED
@@ -1,113 +1,43 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_common = require("./common-D2RyWTAZ.cjs");
3
+ //#region src/adapter/express/middleware.ts
4
+ /**
5
+ * Creates an Express middleware for handling CRUD requests.
6
+ */
7
+ const factory = (options) => {
8
+ const requestHandler = options.apiHandler;
9
+ return async (request, response, next) => {
10
+ const client = await options.getClient(request, response);
11
+ const { sendResponse } = options;
12
+ if (sendResponse === false && !client) throw new Error("unable to get ZenStackClient from request context");
13
+ if (!client) return response.status(500).json({ message: "unable to get ZenStackClient from request context" });
14
+ const url = request.protocol + "://" + request.get("host") + request.originalUrl;
15
+ const searchParams = new URL(url).searchParams;
16
+ const query = Object.fromEntries(searchParams);
17
+ try {
18
+ const r = await requestHandler.handleRequest({
19
+ method: request.method,
20
+ path: request.path,
21
+ query,
22
+ requestBody: request.body,
23
+ client
24
+ });
25
+ if (sendResponse === false) {
26
+ response.locals["zenstack"] = {
27
+ status: r.status,
28
+ body: r.body
29
+ };
30
+ return next();
31
+ }
32
+ return response.status(r.status).json(r.body);
33
+ } catch (err) {
34
+ if (sendResponse === false) throw err;
35
+ require_common.logInternalError(options.apiHandler.log, err);
36
+ return response.status(500).json({ message: `An internal server error occurred` });
37
+ }
38
+ };
12
39
  };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/adapter/express/index.ts
32
- var express_exports = {};
33
- __export(express_exports, {
34
- ZenStackMiddleware: () => factory
35
- });
36
- module.exports = __toCommonJS(express_exports);
37
-
38
- // src/api/utils.ts
39
- var import_decimal = require("decimal.js");
40
- var import_superjson = __toESM(require("superjson"), 1);
41
- var import_ts_pattern = require("ts-pattern");
42
- var import_v3 = require("zod-validation-error/v3");
43
- var import_v4 = require("zod-validation-error/v4");
44
- function log(logger, level, message, error) {
45
- if (!logger) {
46
- return;
47
- }
48
- const getMessage = typeof message === "function" ? message : () => message;
49
- if (typeof logger === "function") {
50
- logger(level, getMessage(), error);
51
- } else if (logger.includes(level)) {
52
- const logFn = (0, import_ts_pattern.match)(level).with("debug", () => console.debug).with("info", () => console.info).with("warn", () => console.warn).with("error", () => console.error).exhaustive();
53
- logFn(`@zenstackhq/server: [${level}] ${getMessage()}${error ? `
54
- ${error}` : ""}`);
55
- }
56
- }
57
- __name(log, "log");
58
-
59
- // src/adapter/common.ts
60
- function logInternalError(logger, err) {
61
- log(logger, "error", `An unhandled error occurred while processing the request: ${err}${err instanceof Error ? "\n" + err.stack : ""}`);
62
- }
63
- __name(logInternalError, "logInternalError");
40
+ //#endregion
41
+ exports.ZenStackMiddleware = factory;
64
42
 
65
- // src/adapter/express/middleware.ts
66
- var factory = /* @__PURE__ */ __name((options) => {
67
- const requestHandler = options.apiHandler;
68
- return async (request, response, next) => {
69
- const client = await options.getClient(request, response);
70
- const { sendResponse } = options;
71
- if (sendResponse === false && !client) {
72
- throw new Error("unable to get ZenStackClient from request context");
73
- }
74
- if (!client) {
75
- return response.status(500).json({
76
- message: "unable to get ZenStackClient from request context"
77
- });
78
- }
79
- const url = request.protocol + "://" + request.get("host") + request.originalUrl;
80
- const searchParams = new URL(url).searchParams;
81
- const query = Object.fromEntries(searchParams);
82
- try {
83
- const r = await requestHandler.handleRequest({
84
- method: request.method,
85
- path: request.path,
86
- query,
87
- requestBody: request.body,
88
- client
89
- });
90
- if (sendResponse === false) {
91
- response.locals["zenstack"] = {
92
- status: r.status,
93
- body: r.body
94
- };
95
- return next();
96
- }
97
- return response.status(r.status).json(r.body);
98
- } catch (err) {
99
- if (sendResponse === false) {
100
- throw err;
101
- }
102
- logInternalError(options.apiHandler.log, err);
103
- return response.status(500).json({
104
- message: `An internal server error occurred`
105
- });
106
- }
107
- };
108
- }, "factory");
109
- // Annotate the CommonJS export names for ESM import in node:
110
- 0 && (module.exports = {
111
- ZenStackMiddleware
112
- });
113
43
  //# sourceMappingURL=express.cjs.map