@palbase/backend 30.0.0 → 32.0.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/dist/bin/palbase-backend.cjs +136 -3
- package/dist/bin/palbase-backend.cjs.map +1 -1
- package/dist/bin/palbase-backend.js +7 -7
- package/dist/{chunk-TWX6JTGJ.js → chunk-26GH54D2.js} +3 -5
- package/dist/{chunk-TWX6JTGJ.js.map → chunk-26GH54D2.js.map} +1 -1
- package/dist/{chunk-5J5W75A6.js → chunk-5C5UCILO.js} +27 -325
- package/dist/chunk-5C5UCILO.js.map +1 -0
- package/dist/{chunk-VN7NMDUH.js → chunk-AZJIKCOR.js} +113 -15
- package/dist/chunk-AZJIKCOR.js.map +1 -0
- package/dist/{chunk-VVMJEVQP.js → chunk-BRLJOXWS.js} +2 -2
- package/dist/{chunk-3TUJWHC2.js → chunk-IXAX5CON.js} +378 -19
- package/dist/chunk-IXAX5CON.js.map +1 -0
- package/dist/{chunk-CGNN2PUH.js → chunk-KATPXCJ5.js} +37 -4
- package/dist/{chunk-CGNN2PUH.js.map → chunk-KATPXCJ5.js.map} +1 -1
- package/dist/chunk-KGP6ALIU.js +361 -0
- package/dist/chunk-KGP6ALIU.js.map +1 -0
- package/dist/chunk-XEGZ3S2Q.js +346 -0
- package/dist/chunk-XEGZ3S2Q.js.map +1 -0
- package/dist/{chunk-ENZ2RFFJ.js → chunk-Z4CZRMNF.js} +3 -310
- package/dist/chunk-Z4CZRMNF.js.map +1 -0
- package/dist/db/index.cjs +29 -0
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.d.cts +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +12 -13
- package/dist/engine/index.cjs +136 -3
- package/dist/engine/index.cjs.map +1 -1
- package/dist/engine/index.d.cts +3 -3
- package/dist/engine/index.d.ts +3 -3
- package/dist/engine/index.js +7 -7
- package/dist/{index-b-Q3l7W5.d.ts → index-BILC9WwS.d.ts} +9 -2
- package/dist/{index-8qy3kIuA.d.ts → index-BgWnP07a.d.ts} +119 -17
- package/dist/{index-Zi7MptvP.d.cts → index-CWGiJ2Up.d.cts} +9 -2
- package/dist/{index-DtCgaZAg.d.cts → index-DgYkdNT9.d.cts} +119 -17
- package/dist/index.cjs +87 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -23
- package/dist/index.d.ts +6 -23
- package/dist/index.js +48 -48
- package/dist/index.js.map +1 -1
- package/dist/openapi/index.d.cts +2 -2
- package/dist/openapi/index.d.ts +2 -2
- package/dist/openapi/index.js +3 -4
- package/dist/openapi/index.js.map +1 -1
- package/dist/{registry-CEYLH-Iz.d.cts → registry-BcRYIQ-R.d.cts} +1 -1
- package/dist/{registry-BGJ-Al6F.d.ts → registry-ClzjxIWy.d.ts} +1 -1
- package/dist/test/index.cjs +703 -14
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.d.cts +59 -4
- package/dist/test/index.d.ts +59 -4
- package/dist/test/index.js +51 -13
- package/dist/test/index.js.map +1 -1
- package/docs/README.md +1 -1
- package/docs/database.md +54 -0
- package/docs/llms-full.txt +87 -1
- package/docs/schema.md +32 -0
- package/package.json +1 -1
- package/template/package.json +1 -1
- package/dist/chunk-3TUJWHC2.js.map +0 -1
- package/dist/chunk-5J5W75A6.js.map +0 -1
- package/dist/chunk-ENZ2RFFJ.js.map +0 -1
- package/dist/chunk-SG4UTNOP.js +0 -374
- package/dist/chunk-SG4UTNOP.js.map +0 -1
- package/dist/chunk-VN7NMDUH.js.map +0 -1
- package/dist/chunk-VXPNPVAG.js +0 -40
- package/dist/chunk-VXPNPVAG.js.map +0 -1
- /package/dist/{chunk-VVMJEVQP.js.map → chunk-BRLJOXWS.js.map} +0 -0
|
@@ -3,17 +3,17 @@ import {
|
|
|
3
3
|
BootRefused,
|
|
4
4
|
createApp,
|
|
5
5
|
loadConfig
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-AZJIKCOR.js";
|
|
7
|
+
import "../chunk-5C5UCILO.js";
|
|
8
|
+
import "../chunk-XEGZ3S2Q.js";
|
|
9
|
+
import "../chunk-KGP6ALIU.js";
|
|
10
|
+
import "../chunk-IXAX5CON.js";
|
|
10
11
|
import {
|
|
11
12
|
getRegisteredControllers
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import "../chunk-CGNN2PUH.js";
|
|
13
|
+
} from "../chunk-BRLJOXWS.js";
|
|
14
14
|
import {
|
|
15
15
|
__name
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-KATPXCJ5.js";
|
|
17
17
|
|
|
18
18
|
// src/bin/palbase-backend.ts
|
|
19
19
|
import { readdir } from "fs/promises";
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
HttpError
|
|
3
|
-
} from "./chunk-CGNN2PUH.js";
|
|
4
|
-
import {
|
|
2
|
+
HttpError,
|
|
5
3
|
__name
|
|
6
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-KATPXCJ5.js";
|
|
7
5
|
|
|
8
6
|
// src/error-registry.ts
|
|
9
7
|
import { OpenAPIRegistry, OpenApiGeneratorV31, extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
|
|
@@ -161,4 +159,4 @@ export {
|
|
|
161
159
|
getErrorRegistry,
|
|
162
160
|
defineError
|
|
163
161
|
};
|
|
164
|
-
//# sourceMappingURL=chunk-
|
|
162
|
+
//# sourceMappingURL=chunk-26GH54D2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error-registry.ts"],"sourcesContent":["// defineError — project-defined typed error classes + the module-global error\n// registry the OpenAPI spec twins join against.\n//\n// `defineError(code, status, dataSchema?)` returns an `HttpError` subclass whose\n// constructor is typed by the zod schema (`new TodoLocked({ retryAfter: 30 })`).\n// Each call self-registers `{ code, status, className, dataSchema }` in a\n// registry anchored on `globalThis` under `Symbol.for(...)` — mirroring the\n// ROUTES pattern — so the deploy bundle's registrations land on the single SDK\n// instance the extractor `require()`s. The registry is pre-seeded with the named\n// built-in classes (`NotFound`, `Conflict`, …) so throw inference can resolve\n// ad-hoc `throw new NotFound(...)` sites by their canonical wire codes.\n//\n// Duplicate code with a DIFFERENT shape (status OR converted data schema) is a\n// hard error at registration time (deploy fails loudly — error codes are\n// project-unique); structurally-identical re-registration is idempotent (each\n// controller BUNDLE carries its own copy of a shared models/errors.ts, so the\n// same defineError line legitimately runs once per bundle in one process).\nimport {\n OpenAPIRegistry,\n OpenApiGeneratorV31,\n extendZodWithOpenApi,\n} from \"@asteasolutions/zod-to-openapi\";\nimport { z, type ZodTypeAny } from \"zod\";\nimport { HttpError } from \"./errors.js\";\n\nextendZodWithOpenApi(z);\n\n/** One registered error: the wire code, HTTP status, the class name the\n * analyzer sees, the optional data payload schema, and whether it is one of the\n * pre-seeded built-in named classes. */\nexport interface RegisteredError {\n code: string;\n status: number;\n className: string;\n dataSchema?: ZodTypeAny;\n /** JSON.stringify of the converted JSON schema — equal digest ⇔ the spec\n * twins would emit an identical `data` schema for this error. */\n dataDigest?: string;\n builtin: boolean;\n}\n\n/** The cross-module-instance registry anchor (the pinned contract symbol). */\nconst ERROR_REGISTRY: unique symbol = Symbol.for(\"palbase.backend.errorRegistry\");\n\ninterface RegistryCarrier {\n [ERROR_REGISTRY]?: Map<string, RegisteredError>;\n}\n\n/** Get (creating + pre-seeding if absent) the project-global error registry,\n * keyed by wire code. Anchored on `globalThis` so every copy of the SDK in a\n * process shares the one registry. */\n/** The fixed data schemas the built-in named errors ship. Declared HERE (not in\n * errors.ts, which stays zod-free) because this is where the registry converts\n * them to JSON-schema for the spec — keying codegen's typed `error.data`. Only\n * the errors that semantically carry a payload have a schema; the rest are\n * data-less. `.int()` is preserved so the wire/codegen sees an integer. */\nconst BUILTIN_DATA_SCHEMAS: Record<string, ZodTypeAny> = {\n bad_request: z.object({\n fields: z.array(z.object({ field: z.string(), message: z.string() })),\n }),\n too_many_requests: z.object({ retryAfter: z.number().int() }),\n};\n\nexport function getErrorRegistry(): Map<string, RegisteredError> {\n const g = globalThis as RegistryCarrier;\n if (!g[ERROR_REGISTRY]) {\n const m = new Map<string, RegisteredError>();\n for (const [code, status, className] of [\n [\"bad_request\", 400, \"BadRequest\"],\n [\"unauthorized\", 401, \"Unauthorized\"],\n [\"forbidden\", 403, \"Forbidden\"],\n [\"not_found\", 404, \"NotFound\"],\n [\"conflict\", 409, \"Conflict\"],\n // The engine's own 23505 conversion (engine/db.ts) throws this, and an\n // author may too. Registered like every other built-in so the spec\n // emitter resolves it — an unregistered code is SKIPPED silently there\n // (openapi/convert.ts) and would degrade to the client's `.other` case.\n [\"unique_violation\", 409, \"UniqueViolation\"],\n [\"too_many_requests\", 429, \"TooManyRequests\"],\n ] as const) {\n const dataSchema = BUILTIN_DATA_SCHEMAS[code];\n m.set(code, {\n code,\n status,\n className,\n builtin: true,\n ...(dataSchema ? { dataSchema, dataDigest: digestOf(code, dataSchema) } : {}),\n });\n }\n g[ERROR_REGISTRY] = m;\n }\n return g[ERROR_REGISTRY];\n}\n\n/** Class returned for schema-bearing errors: ctor(data, message?). */\nexport interface DefinedErrorWithData<S extends ZodTypeAny> {\n new (data: z.input<S>, message?: string): HttpError;\n readonly code: string;\n readonly status: number;\n}\n\n/** Class returned for schema-less errors: ctor(message?). */\nexport interface DefinedError {\n new (message?: string): HttpError;\n readonly code: string;\n readonly status: number;\n}\n\n/**\n * Define a project error class. MUST be called with literal args (string\n * literal `code`, numeric literal `status`) at module top level — the deploy\n * stager's static analyzer reads those literals to resolve throw sites.\n *\n * @example\n * // models/todos/errors.ts\n * export const TodoLocked = defineError(\"todo_locked\", 409, z.object({ retryAfter: z.number() }));\n * // services/todo.service.ts\n * throw new TodoLocked({ retryAfter: 30 });\n */\nexport function defineError<S extends ZodTypeAny>(\n code: string,\n status: number,\n dataSchema: S,\n): DefinedErrorWithData<S>;\nexport function defineError(code: string, status: number): DefinedError;\nexport function defineError(code: string, status: number, dataSchema?: ZodTypeAny): unknown {\n if (!Number.isInteger(status) || status < 400 || status > 599) {\n throw new Error(\n `defineError: status for \"${code}\" must be a 4xx/5xx integer, got ${status} — ` +\n `error responses must not clobber success responses in the project spec.`,\n );\n }\n const registry = getErrorRegistry();\n const existing = registry.get(code);\n const className = defaultClassName(code);\n const dataDigest = dataSchema ? digestOf(code, dataSchema) : undefined;\n if (existing) {\n const sameShape =\n existing.status === status && !existing.builtin && existing.dataDigest === dataDigest;\n if (!sameShape) {\n throw new Error(\n `defineError: duplicate error code \"${code}\" with a different shape ` +\n `(existing: status ${existing.status}${existing.builtin ? \", built-in\" : \"\"}` +\n `${existing.status === status && !existing.builtin ? \", different data schema\" : \"\"}). ` +\n `Error codes are project-unique.`,\n );\n }\n }\n // Local factories so the class-constructor closures capture a NON-optional\n // schema binding (narrowing does not flow into closures created in a branch).\n const makeWithData = (schema: ZodTypeAny) =>\n class extends HttpError {\n static readonly code = code;\n static readonly status = status;\n constructor(data: unknown, message?: string) {\n super(status, code, message ?? humanize(code), schema.parse(data));\n this.name = className;\n }\n };\n const makeWithoutData = () =>\n class extends HttpError {\n static readonly code = code;\n static readonly status = status;\n constructor(message?: string) {\n super(status, code, message ?? humanize(code));\n this.name = className;\n }\n };\n const cls = dataSchema ? makeWithData(dataSchema) : makeWithoutData();\n Object.defineProperty(cls, \"name\", { value: className });\n registry.set(code, {\n code,\n status,\n className,\n builtin: false,\n ...(dataSchema ? { dataSchema } : {}),\n ...(dataDigest !== undefined ? { dataDigest } : {}),\n });\n return cls;\n}\n\n/** Convert a data schema through the SAME library the spec twins use and\n * return its JSON-schema digest (the duplicate-shape comparison key). Doubles\n * as the self-containment guard: a schema carrying `.openapi(refId)` metadata\n * (top-level or nested) converts to `$ref` pointers into components the\n * project spec never emits — a dangling ref every spec consumer would choke\n * on — so it is rejected here, at the definition site, with a fixable message. */\nfunction digestOf(code: string, dataSchema: ZodTypeAny): string {\n const TMP_REF = \"__PalbaseErrorDataDigest\";\n const tmpRegistry = new OpenAPIRegistry();\n // Wrap the schema as a property — exactly how the envelope embeds it — so a\n // TOP-LEVEL .openapi(refId) is not masked by the registration refId and\n // surfaces as the same $ref the real emission would produce.\n tmpRegistry.register(TMP_REF, z.object({ data: dataSchema }).openapi(TMP_REF));\n const generated = new OpenApiGeneratorV31(tmpRegistry.definitions).generateComponents();\n const out = generated.components?.schemas?.[TMP_REF];\n const digest = JSON.stringify(out ?? null);\n if (digest.includes('\"$ref\"')) {\n throw new Error(\n `defineError: dataSchema for \"${code}\" carries .openapi(refId) metadata — ` +\n `it would emit dangling $ref pointers in the project spec. ` +\n `Use a plain zod schema (z.object({...})) without .openapi(...).`,\n );\n }\n return digest;\n}\n\n/** \"todo_locked\" → \"TodoLocked\" (used as Error.name; the source class NAME the\n * analyzer sees is whatever the user assigned the const to — they should match\n * by convention, and the descriptor carries the analyzed const name anyway). */\nfunction defaultClassName(code: string): string {\n return code\n .split(\"_\")\n .map((p) => p.charAt(0).toUpperCase() + p.slice(1))\n .join(\"\");\n}\n\n/** \"todo_locked\" → \"Todo locked\" — the default human-readable message. */\nfunction humanize(code: string): string {\n const s = code.replace(/_/g, \" \");\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n"],"mappings":";;;;;;;;AAiBA,SACEA,iBACAC,qBACAC,4BACK;AACP,SAASC,SAA0B;AAGnCC,qBAAqBC,CAAAA;AAiBrB,IAAMC,iBAAgCC,uBAAOC,IAAI,+BAAA;AAcjD,IAAMC,uBAAmD;EACvDC,aAAaL,EAAEM,OAAO;IACpBC,QAAQP,EAAEQ,MAAMR,EAAEM,OAAO;MAAEG,OAAOT,EAAEU,OAAM;MAAIC,SAASX,EAAEU,OAAM;IAAG,CAAA,CAAA;EACpE,CAAA;EACAE,mBAAmBZ,EAAEM,OAAO;IAAEO,YAAYb,EAAEc,OAAM,EAAGC,IAAG;EAAG,CAAA;AAC7D;AAEO,SAASC,mBAAAA;AACd,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E;AACA,SAAO0C;AACT;AAlBSnC;AAuBT,SAASQ,iBAAiBf,MAAY;AACpC,SAAOA,KACJ8C,MAAM,GAAA,EACNC,IAAI,CAACC,MAAMA,EAAEC,OAAO,CAAA,EAAGC,YAAW,IAAKF,EAAEG,MAAM,CAAA,CAAA,EAC/CC,KAAK,EAAA;AACV;AALSrC;AAQT,SAASO,SAAStB,MAAY;AAC5B,QAAMqD,IAAIrD,KAAKsD,QAAQ,MAAM,GAAA;AAC7B,SAAOD,EAAEJ,OAAO,CAAA,EAAGC,YAAW,IAAKG,EAAEF,MAAM,CAAA;AAC7C;AAHS7B;","names":["OpenAPIRegistry","OpenApiGeneratorV31","extendZodWithOpenApi","z","extendZodWithOpenApi","z","ERROR_REGISTRY","Symbol","for","BUILTIN_DATA_SCHEMAS","bad_request","object","fields","array","field","string","message","too_many_requests","retryAfter","number","int","getErrorRegistry","g","globalThis","m","Map","code","status","className","dataSchema","set","builtin","dataDigest","digestOf","defineError","Number","isInteger","Error","registry","existing","get","defaultClassName","undefined","sameShape","makeWithData","schema","HttpError","data","humanize","parse","name","makeWithoutData","cls","Object","defineProperty","value","TMP_REF","tmpRegistry","OpenAPIRegistry","register","openapi","generated","OpenApiGeneratorV31","definitions","generateComponents","out","components","schemas","digest","JSON","stringify","includes","split","map","p","charAt","toUpperCase","slice","join","s","replace"]}
|
|
1
|
+
{"version":3,"sources":["../src/error-registry.ts"],"sourcesContent":["// defineError — project-defined typed error classes + the module-global error\n// registry the OpenAPI spec twins join against.\n//\n// `defineError(code, status, dataSchema?)` returns an `HttpError` subclass whose\n// constructor is typed by the zod schema (`new TodoLocked({ retryAfter: 30 })`).\n// Each call self-registers `{ code, status, className, dataSchema }` in a\n// registry anchored on `globalThis` under `Symbol.for(...)` — mirroring the\n// ROUTES pattern — so the deploy bundle's registrations land on the single SDK\n// instance the extractor `require()`s. The registry is pre-seeded with the named\n// built-in classes (`NotFound`, `Conflict`, …) so throw inference can resolve\n// ad-hoc `throw new NotFound(...)` sites by their canonical wire codes.\n//\n// Duplicate code with a DIFFERENT shape (status OR converted data schema) is a\n// hard error at registration time (deploy fails loudly — error codes are\n// project-unique); structurally-identical re-registration is idempotent (each\n// controller BUNDLE carries its own copy of a shared models/errors.ts, so the\n// same defineError line legitimately runs once per bundle in one process).\nimport {\n OpenAPIRegistry,\n OpenApiGeneratorV31,\n extendZodWithOpenApi,\n} from \"@asteasolutions/zod-to-openapi\";\nimport { z, type ZodTypeAny } from \"zod\";\nimport { HttpError } from \"./errors.js\";\n\nextendZodWithOpenApi(z);\n\n/** One registered error: the wire code, HTTP status, the class name the\n * analyzer sees, the optional data payload schema, and whether it is one of the\n * pre-seeded built-in named classes. */\nexport interface RegisteredError {\n code: string;\n status: number;\n className: string;\n dataSchema?: ZodTypeAny;\n /** JSON.stringify of the converted JSON schema — equal digest ⇔ the spec\n * twins would emit an identical `data` schema for this error. */\n dataDigest?: string;\n builtin: boolean;\n}\n\n/** The cross-module-instance registry anchor (the pinned contract symbol). */\nconst ERROR_REGISTRY: unique symbol = Symbol.for(\"palbase.backend.errorRegistry\");\n\ninterface RegistryCarrier {\n [ERROR_REGISTRY]?: Map<string, RegisteredError>;\n}\n\n/** Get (creating + pre-seeding if absent) the project-global error registry,\n * keyed by wire code. Anchored on `globalThis` so every copy of the SDK in a\n * process shares the one registry. */\n/** The fixed data schemas the built-in named errors ship. Declared HERE (not in\n * errors.ts, which stays zod-free) because this is where the registry converts\n * them to JSON-schema for the spec — keying codegen's typed `error.data`. Only\n * the errors that semantically carry a payload have a schema; the rest are\n * data-less. `.int()` is preserved so the wire/codegen sees an integer. */\nconst BUILTIN_DATA_SCHEMAS: Record<string, ZodTypeAny> = {\n bad_request: z.object({\n fields: z.array(z.object({ field: z.string(), message: z.string() })),\n }),\n too_many_requests: z.object({ retryAfter: z.number().int() }),\n};\n\nexport function getErrorRegistry(): Map<string, RegisteredError> {\n const g = globalThis as RegistryCarrier;\n if (!g[ERROR_REGISTRY]) {\n const m = new Map<string, RegisteredError>();\n for (const [code, status, className] of [\n [\"bad_request\", 400, \"BadRequest\"],\n [\"unauthorized\", 401, \"Unauthorized\"],\n [\"forbidden\", 403, \"Forbidden\"],\n [\"not_found\", 404, \"NotFound\"],\n [\"conflict\", 409, \"Conflict\"],\n // The engine's own 23505 conversion (engine/db.ts) throws this, and an\n // author may too. Registered like every other built-in so the spec\n // emitter resolves it — an unregistered code is SKIPPED silently there\n // (openapi/convert.ts) and would degrade to the client's `.other` case.\n [\"unique_violation\", 409, \"UniqueViolation\"],\n [\"too_many_requests\", 429, \"TooManyRequests\"],\n ] as const) {\n const dataSchema = BUILTIN_DATA_SCHEMAS[code];\n m.set(code, {\n code,\n status,\n className,\n builtin: true,\n ...(dataSchema ? { dataSchema, dataDigest: digestOf(code, dataSchema) } : {}),\n });\n }\n g[ERROR_REGISTRY] = m;\n }\n return g[ERROR_REGISTRY];\n}\n\n/** Class returned for schema-bearing errors: ctor(data, message?). */\nexport interface DefinedErrorWithData<S extends ZodTypeAny> {\n new (data: z.input<S>, message?: string): HttpError;\n readonly code: string;\n readonly status: number;\n}\n\n/** Class returned for schema-less errors: ctor(message?). */\nexport interface DefinedError {\n new (message?: string): HttpError;\n readonly code: string;\n readonly status: number;\n}\n\n/**\n * Define a project error class. MUST be called with literal args (string\n * literal `code`, numeric literal `status`) at module top level — the deploy\n * stager's static analyzer reads those literals to resolve throw sites.\n *\n * @example\n * // models/todos/errors.ts\n * export const TodoLocked = defineError(\"todo_locked\", 409, z.object({ retryAfter: z.number() }));\n * // services/todo.service.ts\n * throw new TodoLocked({ retryAfter: 30 });\n */\nexport function defineError<S extends ZodTypeAny>(\n code: string,\n status: number,\n dataSchema: S,\n): DefinedErrorWithData<S>;\nexport function defineError(code: string, status: number): DefinedError;\nexport function defineError(code: string, status: number, dataSchema?: ZodTypeAny): unknown {\n if (!Number.isInteger(status) || status < 400 || status > 599) {\n throw new Error(\n `defineError: status for \"${code}\" must be a 4xx/5xx integer, got ${status} — ` +\n `error responses must not clobber success responses in the project spec.`,\n );\n }\n const registry = getErrorRegistry();\n const existing = registry.get(code);\n const className = defaultClassName(code);\n const dataDigest = dataSchema ? digestOf(code, dataSchema) : undefined;\n if (existing) {\n const sameShape =\n existing.status === status && !existing.builtin && existing.dataDigest === dataDigest;\n if (!sameShape) {\n throw new Error(\n `defineError: duplicate error code \"${code}\" with a different shape ` +\n `(existing: status ${existing.status}${existing.builtin ? \", built-in\" : \"\"}` +\n `${existing.status === status && !existing.builtin ? \", different data schema\" : \"\"}). ` +\n `Error codes are project-unique.`,\n );\n }\n }\n // Local factories so the class-constructor closures capture a NON-optional\n // schema binding (narrowing does not flow into closures created in a branch).\n const makeWithData = (schema: ZodTypeAny) =>\n class extends HttpError {\n static readonly code = code;\n static readonly status = status;\n constructor(data: unknown, message?: string) {\n super(status, code, message ?? humanize(code), schema.parse(data));\n this.name = className;\n }\n };\n const makeWithoutData = () =>\n class extends HttpError {\n static readonly code = code;\n static readonly status = status;\n constructor(message?: string) {\n super(status, code, message ?? humanize(code));\n this.name = className;\n }\n };\n const cls = dataSchema ? makeWithData(dataSchema) : makeWithoutData();\n Object.defineProperty(cls, \"name\", { value: className });\n registry.set(code, {\n code,\n status,\n className,\n builtin: false,\n ...(dataSchema ? { dataSchema } : {}),\n ...(dataDigest !== undefined ? { dataDigest } : {}),\n });\n return cls;\n}\n\n/** Convert a data schema through the SAME library the spec twins use and\n * return its JSON-schema digest (the duplicate-shape comparison key). Doubles\n * as the self-containment guard: a schema carrying `.openapi(refId)` metadata\n * (top-level or nested) converts to `$ref` pointers into components the\n * project spec never emits — a dangling ref every spec consumer would choke\n * on — so it is rejected here, at the definition site, with a fixable message. */\nfunction digestOf(code: string, dataSchema: ZodTypeAny): string {\n const TMP_REF = \"__PalbaseErrorDataDigest\";\n const tmpRegistry = new OpenAPIRegistry();\n // Wrap the schema as a property — exactly how the envelope embeds it — so a\n // TOP-LEVEL .openapi(refId) is not masked by the registration refId and\n // surfaces as the same $ref the real emission would produce.\n tmpRegistry.register(TMP_REF, z.object({ data: dataSchema }).openapi(TMP_REF));\n const generated = new OpenApiGeneratorV31(tmpRegistry.definitions).generateComponents();\n const out = generated.components?.schemas?.[TMP_REF];\n const digest = JSON.stringify(out ?? null);\n if (digest.includes('\"$ref\"')) {\n throw new Error(\n `defineError: dataSchema for \"${code}\" carries .openapi(refId) metadata — ` +\n `it would emit dangling $ref pointers in the project spec. ` +\n `Use a plain zod schema (z.object({...})) without .openapi(...).`,\n );\n }\n return digest;\n}\n\n/** \"todo_locked\" → \"TodoLocked\" (used as Error.name; the source class NAME the\n * analyzer sees is whatever the user assigned the const to — they should match\n * by convention, and the descriptor carries the analyzed const name anyway). */\nfunction defaultClassName(code: string): string {\n return code\n .split(\"_\")\n .map((p) => p.charAt(0).toUpperCase() + p.slice(1))\n .join(\"\");\n}\n\n/** \"todo_locked\" → \"Todo locked\" — the default human-readable message. */\nfunction humanize(code: string): string {\n const s = code.replace(/_/g, \" \");\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n"],"mappings":";;;;;;AAiBA,SACEA,iBACAC,qBACAC,4BACK;AACP,SAASC,SAA0B;AAGnCC,qBAAqBC,CAAAA;AAiBrB,IAAMC,iBAAgCC,uBAAOC,IAAI,+BAAA;AAcjD,IAAMC,uBAAmD;EACvDC,aAAaL,EAAEM,OAAO;IACpBC,QAAQP,EAAEQ,MAAMR,EAAEM,OAAO;MAAEG,OAAOT,EAAEU,OAAM;MAAIC,SAASX,EAAEU,OAAM;IAAG,CAAA,CAAA;EACpE,CAAA;EACAE,mBAAmBZ,EAAEM,OAAO;IAAEO,YAAYb,EAAEc,OAAM,EAAGC,IAAG;EAAG,CAAA;AAC7D;AAEO,SAASC,mBAAAA;AACd,QAAMC,IAAIC;AACV,MAAI,CAACD,EAAEhB,cAAAA,GAAiB;AACtB,UAAMkB,IAAI,oBAAIC,IAAAA;AACd,eAAW,CAACC,MAAMC,QAAQC,SAAAA,KAAc;MACtC;QAAC;QAAe;QAAK;;MACrB;QA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AM,CAAA,CAAA,EAC/CC,KAAK,EAAA;AACV;AALSrC;AAQT,SAASO,SAAStB,MAAY;AAC5B,QAAMqD,IAAIrD,KAAKsD,QAAQ,MAAM,GAAA;AAC7B,SAAOD,EAAEJ,OAAO,CAAA,EAAGC,YAAW,IAAKG,EAAEF,MAAM,CAAA;AAC7C;AAHS7B;","names":["OpenAPIRegistry","OpenApiGeneratorV31","extendZodWithOpenApi","z","extendZodWithOpenApi","z","ERROR_REGISTRY","Symbol","for","BUILTIN_DATA_SCHEMAS","bad_request","object","fields","array","field","string","message","too_many_requests","retryAfter","number","int","getErrorRegistry","g","globalThis","m","Map","code","status","className","dataSchema","set","builtin","dataDigest","digestOf","defineError","Number","isInteger","Error","registry","existing","get","defaultClassName","undefined","sameShape","makeWithData","schema","HttpError","data","humanize","parse","name","makeWithoutData","cls","Object","defineProperty","value","TMP_REF","tmpRegistry","OpenAPIRegistry","register","openapi","generated","OpenApiGeneratorV31","definitions","generateComponents","out","components","schemas","digest","JSON","stringify","includes","split","map","p","charAt","toUpperCase","slice","join","s","replace"]}
|
|
@@ -1,311 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-SG4UTNOP.js";
|
|
2
|
+
CODECS
|
|
3
|
+
} from "./chunk-KGP6ALIU.js";
|
|
5
4
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./chunk-3TUJWHC2.js";
|
|
5
|
+
qualifiedTableKey
|
|
6
|
+
} from "./chunk-IXAX5CON.js";
|
|
9
7
|
import {
|
|
10
8
|
__name
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
|
|
13
|
-
// src/runtime.ts
|
|
14
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
15
|
-
var __requestALS = new AsyncLocalStorage();
|
|
16
|
-
var runtime = null;
|
|
17
|
-
function __setRuntime(services) {
|
|
18
|
-
runtime = services;
|
|
19
|
-
}
|
|
20
|
-
__name(__setRuntime, "__setRuntime");
|
|
21
|
-
function __runWithRuntime(services, fn) {
|
|
22
|
-
return __requestALS.run({
|
|
23
|
-
runtime: services
|
|
24
|
-
}, fn);
|
|
25
|
-
}
|
|
26
|
-
__name(__runWithRuntime, "__runWithRuntime");
|
|
27
|
-
function __getRuntime() {
|
|
28
|
-
const scoped = __requestALS.getStore();
|
|
29
|
-
if (scoped) return scoped.runtime;
|
|
30
|
-
if (runtime === null) {
|
|
31
|
-
throw new Error("Palbase services accessed outside a request scope. The Database/Documents/\u2026 singletons are only available inside an endpoint handler (or after the runtime has called __runWithRuntime / __setRuntime).");
|
|
32
|
-
}
|
|
33
|
-
return runtime;
|
|
34
|
-
}
|
|
35
|
-
__name(__getRuntime, "__getRuntime");
|
|
36
|
-
var LIFECYCLE = /* @__PURE__ */ Symbol.for("palbase.backend.lifecycleHooks");
|
|
37
|
-
function declaredLifecycle() {
|
|
38
|
-
const g = globalThis;
|
|
39
|
-
return g[LIFECYCLE] ??= {
|
|
40
|
-
start: [],
|
|
41
|
-
shutdown: []
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
__name(declaredLifecycle, "declaredLifecycle");
|
|
45
|
-
function onStart(name, hook) {
|
|
46
|
-
declaredLifecycle().start.push({
|
|
47
|
-
name,
|
|
48
|
-
run: hook
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
__name(onStart, "onStart");
|
|
52
|
-
function onShutdown(name, hook) {
|
|
53
|
-
declaredLifecycle().shutdown.push({
|
|
54
|
-
name,
|
|
55
|
-
run: hook
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
__name(onShutdown, "onShutdown");
|
|
59
|
-
function reason(err) {
|
|
60
|
-
return err instanceof Error ? err.message : String(err);
|
|
61
|
-
}
|
|
62
|
-
__name(reason, "reason");
|
|
63
|
-
async function drain(hooks) {
|
|
64
|
-
for (const h of [
|
|
65
|
-
...hooks
|
|
66
|
-
].reverse()) {
|
|
67
|
-
try {
|
|
68
|
-
await h.run();
|
|
69
|
-
} catch (err) {
|
|
70
|
-
console.error(`[palbase] shutdown hook "${h.name}" failed: ${reason(err)}`, err);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
__name(drain, "drain");
|
|
75
|
-
async function __runStartHooks() {
|
|
76
|
-
const slot3 = declaredLifecycle();
|
|
77
|
-
const start = slot3.start.splice(0);
|
|
78
|
-
const shutdown = slot3.shutdown.splice(0);
|
|
79
|
-
for (const h of start) {
|
|
80
|
-
try {
|
|
81
|
-
await h.run();
|
|
82
|
-
} catch (err) {
|
|
83
|
-
await drain(shutdown);
|
|
84
|
-
throw new Error(`[palbase] start hook "${h.name}" failed: ${reason(err)}`, {
|
|
85
|
-
cause: err
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
let drained = false;
|
|
90
|
-
return async () => {
|
|
91
|
-
if (drained) return;
|
|
92
|
-
drained = true;
|
|
93
|
-
await drain(shutdown);
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
__name(__runStartHooks, "__runStartHooks");
|
|
97
|
-
function __resetLifecycleHooks() {
|
|
98
|
-
const g = globalThis;
|
|
99
|
-
delete g[LIFECYCLE];
|
|
100
|
-
}
|
|
101
|
-
__name(__resetLifecycleHooks, "__resetLifecycleHooks");
|
|
102
|
-
function makeServiceProxy(key) {
|
|
103
|
-
const handler = {
|
|
104
|
-
get(_target, prop, receiver) {
|
|
105
|
-
const client = __getRuntime()[key];
|
|
106
|
-
const value = Reflect.get(client, prop, receiver);
|
|
107
|
-
return typeof value === "function" ? value.bind(client) : value;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
return new Proxy({}, handler);
|
|
111
|
-
}
|
|
112
|
-
__name(makeServiceProxy, "makeServiceProxy");
|
|
113
|
-
function makeTableProxy(ops, prefix) {
|
|
114
|
-
return new Proxy({}, {
|
|
115
|
-
get(_t, prop) {
|
|
116
|
-
if (typeof prop !== "string") return void 0;
|
|
117
|
-
const name = `${prefix}${prop}`;
|
|
118
|
-
return {
|
|
119
|
-
insert: /* @__PURE__ */ __name((data) => ops().insert(name, data), "insert"),
|
|
120
|
-
// DÖRDÜNCÜ FİİL, aynı gerekçeyle: tip söz veriyor, ops katmanı
|
|
121
|
-
// uyguluyor, ve bir handler'ın gerçekten dokunduğu yer BURASI.
|
|
122
|
-
// `runtime-table-verbs` kapısı bunu adıyla saydı.
|
|
123
|
-
aggregate: /* @__PURE__ */ __name((q) => ops().aggregate(name, q), "aggregate"),
|
|
124
|
-
insertMany: /* @__PURE__ */ __name((rows, opts) => ops().insertMany(name, rows, opts), "insertMany"),
|
|
125
|
-
update: /* @__PURE__ */ __name((q) => ops().update(name, q.where.id, q.set), "update"),
|
|
126
|
-
delete: /* @__PURE__ */ __name((id) => ops().delete(name, id), "delete"),
|
|
127
|
-
findById: /* @__PURE__ */ __name((id) => ops().findById(name, id), "findById"),
|
|
128
|
-
findMany: /* @__PURE__ */ __name((q) => {
|
|
129
|
-
const { where, ...opts } = q ?? {};
|
|
130
|
-
return ops().findMany(name, where, opts);
|
|
131
|
-
}, "findMany"),
|
|
132
|
-
put: /* @__PURE__ */ __name((q) => ops().put(name, q.data, {
|
|
133
|
-
onConflict: q.onConflict
|
|
134
|
-
}), "put"),
|
|
135
|
-
// THREE VERBS THE TYPE PROMISED AND THIS PROXY DID NOT EMIT.
|
|
136
|
-
//
|
|
137
|
-
// `EnvTypedTableBase` declares `updateMany`, `deleteMany` and `count`
|
|
138
|
-
// (typed-db.ts) and the ops layer implements all three — only this
|
|
139
|
-
// proxy, which is what a handler actually touches, left them out. So
|
|
140
|
-
// the type said the verb exists, autocomplete offered it, and the call
|
|
141
|
-
// answered `undefined is not a function`.
|
|
142
|
-
//
|
|
143
|
-
// Older than this run, but the run rewrote this proxy for
|
|
144
|
-
// `Database.schema(name).tables.*` and would have carried the gap onto
|
|
145
|
-
// the new surface too.
|
|
146
|
-
updateMany: /* @__PURE__ */ __name((q) => ops().updateMany(name, q.where, q.set), "updateMany"),
|
|
147
|
-
deleteMany: /* @__PURE__ */ __name((q) => ops().deleteMany(name, q.where), "deleteMany"),
|
|
148
|
-
count: /* @__PURE__ */ __name((q) => ops().count(name, q?.where), "count"),
|
|
149
|
-
search: /* @__PURE__ */ __name((params) => ops().search(name, params), "search"),
|
|
150
|
-
similar: /* @__PURE__ */ __name((id, params) => ops().similar(name, id, params), "similar"),
|
|
151
|
-
recommend: /* @__PURE__ */ __name((params) => ops().recommend(name, params), "recommend"),
|
|
152
|
-
facets: /* @__PURE__ */ __name((params) => ops().facets(name, params), "facets"),
|
|
153
|
-
supersede: /* @__PURE__ */ __name((id, row) => ops().supersede(name, id, row), "supersede"),
|
|
154
|
-
claim: /* @__PURE__ */ __name((unique, extra) => ops().claim(name, unique, extra), "claim")
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
__name(makeTableProxy, "makeTableProxy");
|
|
160
|
-
var rawDatabase = makeServiceProxy("Database");
|
|
161
|
-
function makeTypedSurface(raw) {
|
|
162
|
-
const reco = raw;
|
|
163
|
-
const ops = {
|
|
164
|
-
$query: /* @__PURE__ */ __name((sql, params) => raw.query(sql, params), "$query"),
|
|
165
|
-
$insert: /* @__PURE__ */ __name((table, data) => raw.insert(table, data), "$insert"),
|
|
166
|
-
$update: /* @__PURE__ */ __name((table, id, data) => raw.update(table, id, data), "$update"),
|
|
167
|
-
$delete: /* @__PURE__ */ __name((table, id) => raw.delete(table, id), "$delete"),
|
|
168
|
-
$findById: /* @__PURE__ */ __name((table, id) => raw.findById(table, id), "$findById"),
|
|
169
|
-
$findMany: /* @__PURE__ */ __name((table, query, opts) => raw.findMany(table, query, opts), "$findMany"),
|
|
170
|
-
$put: /* @__PURE__ */ __name((table, data, opts) => raw.put(table, data, opts), "$put"),
|
|
171
|
-
$updateMany: /* @__PURE__ */ __name((table, where, set) => raw.updateMany(table, where, set), "$updateMany"),
|
|
172
|
-
$deleteMany: /* @__PURE__ */ __name((table, where) => raw.deleteMany(table, where), "$deleteMany"),
|
|
173
|
-
$count: /* @__PURE__ */ __name((table, where) => raw.count(table, where), "$count"),
|
|
174
|
-
$search: /* @__PURE__ */ __name((table, params) => raw.search(table, params), "$search"),
|
|
175
|
-
$similar: /* @__PURE__ */ __name((table, id, params) => reco.similar(table, id, params), "$similar"),
|
|
176
|
-
$recommend: /* @__PURE__ */ __name((table, params) => reco.recommend(table, params), "$recommend"),
|
|
177
|
-
$facets: /* @__PURE__ */ __name((table, params) => reco.facets(table, params), "$facets"),
|
|
178
|
-
$claim: /* @__PURE__ */ __name((table, unique, extra) => reco.claim(table, unique, extra), "$claim"),
|
|
179
|
-
$lockRows: /* @__PURE__ */ __name((table, ids) => reco.lockRows(table, ids), "$lockRows"),
|
|
180
|
-
$advisoryXactLock: /* @__PURE__ */ __name((key) => reco.advisoryXactLock(key), "$advisoryXactLock"),
|
|
181
|
-
$aggregate: /* @__PURE__ */ __name((table, q) => raw.aggregate(table, q), "$aggregate"),
|
|
182
|
-
$insertMany: /* @__PURE__ */ __name((table, rows, opts) => raw.insertMany(table, rows, opts), "$insertMany"),
|
|
183
|
-
$supersede: /* @__PURE__ */ __name((table, id, row) => raw.supersede(table, id, row), "$supersede")
|
|
184
|
-
};
|
|
185
|
-
const base = Object.assign(ops, {
|
|
186
|
-
// Both surfaces get it: a savepoint on the service transaction is as useful
|
|
187
|
-
// as one on the request's, and each is bound to its own connection.
|
|
188
|
-
$attempt: /* @__PURE__ */ __name((fn) => raw.attempt(fn), "$attempt"),
|
|
189
|
-
$transaction(fn, opts) {
|
|
190
|
-
return withRetry(() => {
|
|
191
|
-
const builder = new TxPlanBuilder();
|
|
192
|
-
return runTxPlan(raw, makeTxPlanHandle(builder), builder, fn);
|
|
193
|
-
}, opts ?? {});
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
return new Proxy(base, {
|
|
197
|
-
get(target, prop, receiver) {
|
|
198
|
-
if (prop === "tables") return makeTableProxy(() => reco, "");
|
|
199
|
-
if (typeof prop === "string" && !prop.startsWith("$") && !(prop in target)) {
|
|
200
|
-
return makeTableProxy(() => reco, qualifiedTableKey(prop, ""));
|
|
201
|
-
}
|
|
202
|
-
return Reflect.get(target, prop, receiver);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
__name(makeTypedSurface, "makeTypedSurface");
|
|
207
|
-
function makeTxTablesAccessor(builder, prefix = "") {
|
|
208
|
-
const tablesProxy = new Proxy({}, {
|
|
209
|
-
get(_t, prop) {
|
|
210
|
-
if (typeof prop !== "string") return void 0;
|
|
211
|
-
return builder.table(prefix + prop);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
return tablesProxy;
|
|
215
|
-
}
|
|
216
|
-
__name(makeTxTablesAccessor, "makeTxTablesAccessor");
|
|
217
|
-
function makeTxPlanHandle(builder) {
|
|
218
|
-
const publicTables = makeTxTablesAccessor(builder);
|
|
219
|
-
return new Proxy({}, {
|
|
220
|
-
get(_t, prop) {
|
|
221
|
-
if (typeof prop !== "string") return void 0;
|
|
222
|
-
if (prop === "tables") return publicTables;
|
|
223
|
-
return makeTxTablesAccessor(builder, qualifiedTableKey(prop, ""));
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
__name(makeTxPlanHandle, "makeTxPlanHandle");
|
|
228
|
-
var Database = Object.assign(makeTypedSurface(rawDatabase), {
|
|
229
|
-
/**
|
|
230
|
-
* Lazily resolve the runtime's service-role sibling on each call. We do NOT
|
|
231
|
-
* cache it: `rawDatabase.asService()` reads the CURRENT request scope through
|
|
232
|
-
* the runtime proxy, and the per-request runtime injects a service client
|
|
233
|
-
* bound to that request's identity headers — caching would leak one request's
|
|
234
|
-
* sibling into another concurrent request.
|
|
235
|
-
*/
|
|
236
|
-
$asService() {
|
|
237
|
-
return makeTypedSurface(rawDatabase.asService());
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
var Documents = makeServiceProxy("Documents");
|
|
241
|
-
function makeBucketsAccessor(storage) {
|
|
242
|
-
return new Proxy({}, {
|
|
243
|
-
get(_t, prop) {
|
|
244
|
-
if (typeof prop !== "string") return void 0;
|
|
245
|
-
return storage().bucket(prop);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
__name(makeBucketsAccessor, "makeBucketsAccessor");
|
|
250
|
-
var rawStorage = makeServiceProxy("Storage");
|
|
251
|
-
var Storage = Object.assign({
|
|
252
|
-
// FORWARDED explicitly, not assigned onto the service proxy.
|
|
253
|
-
//
|
|
254
|
-
// `Object.assign(rawStorage, {buckets})` writes onto the proxy's TARGET, and
|
|
255
|
-
// the proxy's only trap is `get`, which forwards every read to the module
|
|
256
|
-
// client — so the property landed somewhere nothing reads and
|
|
257
|
-
// `Storage.buckets.docs` was `undefined` in a deployed handler. It
|
|
258
|
-
// typechecked, every test passed, and the live call answered
|
|
259
|
-
// "TypeError: undefined is not an object". `Database` never had the bug
|
|
260
|
-
// because it builds a plain surface the same way this now does.
|
|
261
|
-
bucket: /* @__PURE__ */ __name((name) => rawStorage.bucket(name), "bucket")
|
|
262
|
-
}, {
|
|
263
|
-
buckets: makeBucketsAccessor(() => rawStorage)
|
|
264
|
-
});
|
|
265
|
-
var Cache = makeServiceProxy("Cache");
|
|
266
|
-
var Secrets = makeServiceProxy("Secrets");
|
|
267
|
-
var Auth = makeServiceProxy("Auth");
|
|
268
|
-
var Log = makeServiceProxy("Log");
|
|
269
|
-
var Notifications = makeServiceProxy("Notifications");
|
|
270
|
-
var rawFlags = makeServiceProxy("Flags");
|
|
271
|
-
var Flags = Object.assign({
|
|
272
|
-
isEnabled(flagName, context) {
|
|
273
|
-
return rawFlags.isEnabled(flagName, context);
|
|
274
|
-
},
|
|
275
|
-
getVariant(flagName, context) {
|
|
276
|
-
return rawFlags.getVariant(flagName, context);
|
|
277
|
-
},
|
|
278
|
-
getAll(context) {
|
|
279
|
-
return rawFlags.getAll(context);
|
|
280
|
-
},
|
|
281
|
-
/**
|
|
282
|
-
* Resolve a flag's value, with an optional fallback.
|
|
283
|
-
*
|
|
284
|
-
* FORWARDED as of 2026-08-15. This surface is written out by hand, method
|
|
285
|
-
* by method, and `get` was missing from it — so the client implemented it,
|
|
286
|
-
* thirty assertions covered it, and `Flags.get("x")` was `undefined` in a
|
|
287
|
-
* deployed handler. Exactly the shape of the `Storage.buckets` defect found
|
|
288
|
-
* the same day: a hand-maintained forwarding list is a list somebody has to
|
|
289
|
-
* remember to update.
|
|
290
|
-
*/
|
|
291
|
-
get(flagName, defaultOrContext, maybeContext) {
|
|
292
|
-
return rawFlags.get(flagName, defaultOrContext, maybeContext);
|
|
293
|
-
},
|
|
294
|
-
setOverride(key, value) {
|
|
295
|
-
return rawFlags.setOverride(key, value);
|
|
296
|
-
}
|
|
297
|
-
}, {
|
|
298
|
-
/**
|
|
299
|
-
* Lazily resolve the runtime's cross-user sibling on each call. We do NOT
|
|
300
|
-
* cache it: `rawFlags.asService()` reads the CURRENT request scope through
|
|
301
|
-
* the runtime proxy, so caching would leak one request's sibling into
|
|
302
|
-
* another concurrent request. Mirrors `Database.asService()`.
|
|
303
|
-
*/
|
|
304
|
-
asService() {
|
|
305
|
-
return rawFlags.asService();
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
var Realtime = makeServiceProxy("Realtime");
|
|
9
|
+
} from "./chunk-KATPXCJ5.js";
|
|
309
10
|
|
|
310
11
|
// src/refusals.ts
|
|
311
12
|
var DECLARATION_REFUSAL = /* @__PURE__ */ Symbol.for("palbase.backend.declarationRefusal");
|
|
@@ -327,6 +28,9 @@ __name(isDeclarationRefused, "isDeclarationRefused");
|
|
|
327
28
|
|
|
328
29
|
// src/db/env-gen.ts
|
|
329
30
|
function baseTsType(def) {
|
|
31
|
+
if (def.codec !== void 0 && def.codec in CODECS) {
|
|
32
|
+
return CODECS[def.codec].tsType;
|
|
33
|
+
}
|
|
330
34
|
switch (def.type) {
|
|
331
35
|
case "uuid":
|
|
332
36
|
case "text":
|
|
@@ -356,8 +60,10 @@ function baseTsType(def) {
|
|
|
356
60
|
if (values.length === 0) return "string";
|
|
357
61
|
return values.map((v) => JSON.stringify(v)).join(" | ");
|
|
358
62
|
}
|
|
359
|
-
default:
|
|
360
|
-
|
|
63
|
+
default: {
|
|
64
|
+
const unhandled = def.type;
|
|
65
|
+
throw new Error(`env-gen: "${String(unhandled)}" kolon tipinin TypeScript kar\u015F\u0131l\u0131\u011F\u0131 bildirilmemi\u015F. baseTsType'a bir case ekleyin \u2014 sessizce \`unknown\` d\xF6nmek o kolonu her kural\u0131n d\u0131\u015F\u0131na \xE7\u0131kar\u0131r.`);
|
|
66
|
+
}
|
|
361
67
|
}
|
|
362
68
|
}
|
|
363
69
|
__name(baseTsType, "baseTsType");
|
|
@@ -502,7 +208,21 @@ function tableBlock(table, relations, indent) {
|
|
|
502
208
|
].join("\n");
|
|
503
209
|
}
|
|
504
210
|
__name(tableBlock, "tableBlock");
|
|
211
|
+
function refuseFreeFormTransforms(schemas) {
|
|
212
|
+
for (const schema of schemas) {
|
|
213
|
+
for (const table of Object.values(schema.tables)) {
|
|
214
|
+
for (const [col, builder] of Object.entries(table.columns)) {
|
|
215
|
+
const def = builder._def;
|
|
216
|
+
if (def.transform === void 0 || def.codec !== void 0) continue;
|
|
217
|
+
const where = qualifiedTableKey(schema.name, table.name);
|
|
218
|
+
throw new DeclarationRefused(`table "${where}" column "${col}" declares .transform<T>(): its target type does not exist at runtime, so the generated types would say something the engine contradicts. Declare a named codec instead \u2014 .asNumber() for a JS number, .asDecimal() for the exact string.`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
__name(refuseFreeFormTransforms, "refuseFreeFormTransforms");
|
|
505
224
|
function makeEnvDts(schemas) {
|
|
225
|
+
refuseFreeFormTransforms(schemas);
|
|
506
226
|
const relations = buildRelations(schemas);
|
|
507
227
|
const publicSchema = schemas.find((s) => s.name === "public");
|
|
508
228
|
const others = schemas.filter((s) => s.name !== "public");
|
|
@@ -959,24 +679,6 @@ function assertNoOrphanEntryPoints(registered, owned2) {
|
|
|
959
679
|
__name(assertNoOrphanEntryPoints, "assertNoOrphanEntryPoints");
|
|
960
680
|
|
|
961
681
|
export {
|
|
962
|
-
__requestALS,
|
|
963
|
-
__setRuntime,
|
|
964
|
-
__runWithRuntime,
|
|
965
|
-
__getRuntime,
|
|
966
|
-
onStart,
|
|
967
|
-
onShutdown,
|
|
968
|
-
__runStartHooks,
|
|
969
|
-
__resetLifecycleHooks,
|
|
970
|
-
Database,
|
|
971
|
-
Documents,
|
|
972
|
-
Storage,
|
|
973
|
-
Cache,
|
|
974
|
-
Secrets,
|
|
975
|
-
Auth,
|
|
976
|
-
Log,
|
|
977
|
-
Notifications,
|
|
978
|
-
Flags,
|
|
979
|
-
Realtime,
|
|
980
682
|
DECLARATION_REFUSAL,
|
|
981
683
|
DeclarationRefused,
|
|
982
684
|
isDeclarationRefused,
|
|
@@ -995,4 +697,4 @@ export {
|
|
|
995
697
|
buildContainer,
|
|
996
698
|
assertNoOrphanEntryPoints
|
|
997
699
|
};
|
|
998
|
-
//# sourceMappingURL=chunk-
|
|
700
|
+
//# sourceMappingURL=chunk-5C5UCILO.js.map
|