@prisma/orm-family-sql 8.0.0-rc.12-dev.14 → 8.0.0-rc.12-dev.16

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 (108) hide show
  1. package/dist/{authoring-type-constructors-C1ogrr_x-ChQC5e1v.mjs → authoring-type-constructors-C1ogrr_x-DHiQB5ea.mjs} +2 -2
  2. package/dist/{authoring-type-constructors-C1ogrr_x-ChQC5e1v.mjs.map → authoring-type-constructors-C1ogrr_x-DHiQB5ea.mjs.map} +1 -1
  3. package/dist/builder__runtime.d.mts +2 -2
  4. package/dist/builder__runtime.mjs +7 -7
  5. package/dist/builder__runtime.mjs.map +1 -1
  6. package/dist/{config-types-Dqe0LWuW.mjs → config-types-CP-ThN5d.mjs} +2 -2
  7. package/dist/{config-types-Dqe0LWuW.mjs.map → config-types-CP-ThN5d.mjs.map} +1 -1
  8. package/dist/{contract-builder-CojarVwS.mjs → contract-builder-DKKqszA0.mjs} +2 -2
  9. package/dist/{contract-builder-CojarVwS.mjs.map → contract-builder-DKKqszA0.mjs.map} +1 -1
  10. package/dist/contract-emitter.mjs +1 -1
  11. package/dist/contract-prisma7__provider.mjs +4 -4
  12. package/dist/contract-prisma7__provider.mjs.map +1 -1
  13. package/dist/contract-psl.d.mts +3 -3
  14. package/dist/contract-psl.d.mts.map +1 -1
  15. package/dist/contract-psl.mjs +1 -1
  16. package/dist/contract-psl__attribute-specs.d.mts +1 -1
  17. package/dist/contract-psl__attribute-specs.d.mts.map +1 -1
  18. package/dist/contract-psl__map-names.d.mts +16 -0
  19. package/dist/contract-psl__map-names.d.mts.map +1 -0
  20. package/dist/contract-psl__map-names.mjs +21 -0
  21. package/dist/contract-psl__map-names.mjs.map +1 -0
  22. package/dist/contract-psl__provider.mjs +2 -2
  23. package/dist/contract-psl__provider.mjs.map +1 -1
  24. package/dist/contract-ts.mjs +3 -3
  25. package/dist/contract-ts__config-types.mjs +1 -1
  26. package/dist/contract-ts__contract-builder.mjs +2 -2
  27. package/dist/{control-BynSKZfp.mjs → control-BHPQ-Suo.mjs} +19 -3
  28. package/dist/control-BHPQ-Suo.mjs.map +1 -0
  29. package/dist/{control-BLOiyNq-.d.mts → control-BKwzdenn.d.mts} +21 -8
  30. package/dist/control-BKwzdenn.d.mts.map +1 -0
  31. package/dist/{derived-checks-BiClpWj6-Czjj2esH.mjs → derived-checks-FqUZ3g9z-DH15uJjN.mjs} +16 -24
  32. package/dist/derived-checks-FqUZ3g9z-DH15uJjN.mjs.map +1 -0
  33. package/dist/{diff-CHX4XHhC.d.mts → diff-B2b34L_E.d.mts} +4 -4
  34. package/dist/{diff-CHX4XHhC.d.mts.map → diff-B2b34L_E.d.mts.map} +1 -1
  35. package/dist/{dist-D5__KJs-.mjs → dist-U61NPKN3.mjs} +2 -2
  36. package/dist/{dist-D5__KJs-.mjs.map → dist-U61NPKN3.mjs.map} +1 -1
  37. package/dist/family.d.mts +10 -8
  38. package/dist/family.mjs +5 -3
  39. package/dist/family__control.d.mts +4 -4
  40. package/dist/family__control.mjs +1 -1
  41. package/dist/family__diff.d.mts +1 -1
  42. package/dist/family__migration.d.mts +1 -1
  43. package/dist/family__pack.mjs +1 -1
  44. package/dist/family__psl-build.d.mts +3 -0
  45. package/dist/family__psl-build.mjs +3 -0
  46. package/dist/family__psl-infer.d.mts +2 -2
  47. package/dist/family__psl-infer.mjs +2 -2
  48. package/dist/family__runtime.d.mts +1 -1
  49. package/dist/family__runtime.mjs +1 -1
  50. package/dist/{index-C10GDLBQ.d.mts → index-B-CraAhf.d.mts} +4 -4
  51. package/dist/{index-C10GDLBQ.d.mts.map → index-B-CraAhf.d.mts.map} +1 -1
  52. package/dist/{interpreter-Cy7S6Jh9-BIa0lyc-.mjs → interpreter-BrW0_y8Q-hqrOH5mg.mjs} +27 -41
  53. package/dist/interpreter-BrW0_y8Q-hqrOH5mg.mjs.map +1 -0
  54. package/dist/{migration-BwA1d1OP.d.mts → migration-9GrLWqGg.d.mts} +2 -2
  55. package/dist/{migration-BwA1d1OP.d.mts.map → migration-9GrLWqGg.d.mts.map} +1 -1
  56. package/dist/orm-client.d.mts +6 -6
  57. package/dist/orm-client.mjs +10 -10
  58. package/dist/orm-client.mjs.map +1 -1
  59. package/dist/{prepared-statement-B6zvhJej-Dl488oBR.d.mts → prepared-statement-BHSj2pDk-CRzjNpcv.d.mts} +9 -26
  60. package/dist/prepared-statement-BHSj2pDk-CRzjNpcv.d.mts.map +1 -0
  61. package/dist/psl-build-Cp32ahjI.mjs +224 -0
  62. package/dist/psl-build-Cp32ahjI.mjs.map +1 -0
  63. package/dist/psl-build-yBrQQN3r.d.mts +13 -0
  64. package/dist/psl-build-yBrQQN3r.d.mts.map +1 -0
  65. package/dist/{psl-infer-CuTqC9UV.d.mts → psl-infer-BzjA7U3b.d.mts} +3 -50
  66. package/dist/psl-infer-BzjA7U3b.d.mts.map +1 -0
  67. package/dist/psl-infer-DwMyO-IV.mjs +195 -0
  68. package/dist/psl-infer-DwMyO-IV.mjs.map +1 -0
  69. package/dist/psl-names-C3cwe0rg-CsuHOV7E.mjs +66 -0
  70. package/dist/psl-names-C3cwe0rg-CsuHOV7E.mjs.map +1 -0
  71. package/dist/query-lane-context-BcXiJasG.d.mts +1 -0
  72. package/dist/{query-lane-context-Bi1GUXHp-Bo4OTjhW.d.mts → query-lane-context-D6o9YrEV-bouFPM6u.d.mts} +5 -31
  73. package/dist/query-lane-context-D6o9YrEV-bouFPM6u.d.mts.map +1 -0
  74. package/dist/relational-core.d.mts +4 -4
  75. package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -1
  76. package/dist/relational-core__codec-descriptor-registry.d.mts +1 -1
  77. package/dist/relational-core__query-lane-context.d.mts +3 -3
  78. package/dist/relational-core__types.d.mts +2 -2
  79. package/dist/{runtime-DYpzLADy.d.mts → runtime-DgOeosYa.d.mts} +5 -6
  80. package/dist/runtime-DgOeosYa.d.mts.map +1 -0
  81. package/dist/{runtime-DzmRvRj_.mjs → runtime-Z3nD7ix1.mjs} +4 -4
  82. package/dist/{runtime-DzmRvRj_.mjs.map → runtime-Z3nD7ix1.mjs.map} +1 -1
  83. package/dist/runtime.d.mts +4 -4
  84. package/dist/runtime.mjs +7 -85
  85. package/dist/runtime.mjs.map +1 -1
  86. package/dist/runtime__internal__prepared-query.d.mts +1 -1
  87. package/dist/{schema-differ-DpG_gnur-CXVM1Oed.d.mts → schema-differ-DpG_gnur-B_rj2WAH.d.mts} +2 -2
  88. package/dist/{schema-differ-DpG_gnur-CXVM1Oed.d.mts.map → schema-differ-DpG_gnur-B_rj2WAH.d.mts.map} +1 -1
  89. package/dist/type-map-BwBI56i3-DDERtzxf.d.mts +49 -0
  90. package/dist/type-map-BwBI56i3-DDERtzxf.d.mts.map +1 -0
  91. package/dist/{types-BFPRCYGW-BheztqYQ.d.mts → types-BFPRCYGW-DWAEoFj7.d.mts} +2 -2
  92. package/dist/{types-BFPRCYGW-BheztqYQ.d.mts.map → types-BFPRCYGW-DWAEoFj7.d.mts.map} +1 -1
  93. package/dist/types-BvTYXSiS.d.mts +1 -0
  94. package/dist/{types-Bcujdkdw-2SDajXRo.d.mts → types-DFJNPLXY-vp6AGe5e.d.mts} +3 -3
  95. package/dist/{types-Bcujdkdw-2SDajXRo.d.mts.map → types-DFJNPLXY-vp6AGe5e.d.mts.map} +1 -1
  96. package/package.json +20 -18
  97. package/dist/control-BLOiyNq-.d.mts.map +0 -1
  98. package/dist/control-BynSKZfp.mjs.map +0 -1
  99. package/dist/derived-checks-BiClpWj6-Czjj2esH.mjs.map +0 -1
  100. package/dist/interpreter-Cy7S6Jh9-BIa0lyc-.mjs.map +0 -1
  101. package/dist/prepared-statement-B6zvhJej-Dl488oBR.d.mts.map +0 -1
  102. package/dist/psl-infer-CuTqC9UV.d.mts.map +0 -1
  103. package/dist/psl-infer-Df2DrvP-.mjs +0 -474
  104. package/dist/psl-infer-Df2DrvP-.mjs.map +0 -1
  105. package/dist/query-lane-context-Bi1GUXHp-Bo4OTjhW.d.mts.map +0 -1
  106. package/dist/query-lane-context-CJNBt8cm.d.mts +0 -1
  107. package/dist/runtime-DYpzLADy.d.mts.map +0 -1
  108. package/dist/types-nNy0nND_.d.mts +0 -1
@@ -8,17 +8,17 @@ import { n as SqlQueryPlan } from "./plan-B7g2kDfQ-Bw0784x6.mjs";
8
8
  import { a as CodecValue, i as CodecTypesBase, l as RawCodecInferer, o as Expression, t as AffectedCount } from "./expression-BPoA5eEl.mjs";
9
9
  import { t as SqlExecutionPlan } from "./sql-execution-plan-Db0j752I-CI5WbdLi.mjs";
10
10
  import "./plan-DiT00Rg8.mjs";
11
- import { r as ExecutionContext } from "./query-lane-context-Bi1GUXHp-Bo4OTjhW.mjs";
12
- import "./query-lane-context-CJNBt8cm.mjs";
11
+ import { n as ExecutionContext } from "./query-lane-context-D6o9YrEV-bouFPM6u.mjs";
12
+ import "./query-lane-context-BcXiJasG.mjs";
13
+ import { h as RuntimeScope } from "./types-DFJNPLXY-vp6AGe5e.mjs";
14
+ import "./types-BvTYXSiS.mjs";
13
15
  import { i as SqlParamRefMutator } from "./middleware-CuGBptK0-C88HCnh5.mjs";
14
16
  import "./middleware-aoqicpDI.mjs";
15
- import { h as RuntimeScope } from "./types-Bcujdkdw-2SDajXRo.mjs";
16
- import "./types-nNy0nND_.mjs";
17
17
  import { Contract, JsonValue, PlanMeta } from "@prisma/orm-framework/contract/types";
18
- import { AfterExecuteResult, AfterQueryResult, AsyncIterableResult, ExecuteInterceptResult, ExecutionPlan, QueryInterceptResult, RuntimeCore, RuntimeExecuteOptions, RuntimeLog, RuntimeMiddleware, RuntimeMiddlewareContext } from "@prisma/orm-framework/components/runtime";
18
+ import { AfterExecuteResult, AfterQueryResult, AsyncIterableResult, ExecuteInterceptResult, ExecutionPlan, MutationDefaultGeneratorContributor, QueryInterceptResult, RuntimeCore, RuntimeExecuteOptions, RuntimeLog, RuntimeMiddleware, RuntimeMiddlewareContext } from "@prisma/orm-framework/components/runtime";
19
19
  import { AnyCodecDescriptor, CodecDescriptor } from "@prisma/orm-framework/components/codec";
20
20
  import { ExecutionStack, RuntimeAdapterDescriptor, RuntimeAdapterInstance, RuntimeDriverDescriptor, RuntimeDriverInstance, RuntimeExtensionDescriptor, RuntimeExtensionInstance, RuntimeTargetDescriptor, RuntimeTargetInstance } from "@prisma/orm-framework/components/execution";
21
- //#region ../../../2-sql/5-runtime/dist/prepared-statement-B6zvhJej.d.mts
21
+ //#region ../../../2-sql/5-runtime/dist/prepared-statement-BHSj2pDk.d.mts
22
22
  //#region src/codecs/encoding.d.ts
23
23
  interface ParamMetadata {
24
24
  readonly codec: CodecRef$1 | undefined;
@@ -273,26 +273,9 @@ type RuntimeParameterizedCodecDescriptor<P = Record<string, unknown>> = CodecDes
273
273
  /**
274
274
  * Contributor protocol for SQL components (target, adapter, extension pack). The unified `codecs:` slot returns the full {@link CodecDescriptor} list — non-parameterized and parameterized descriptors live side-by-side in the same array. The framework dispatches every codec id through the unified descriptor map without branching on parameterization.
275
275
  */
276
- interface SqlStaticContributions {
276
+ interface SqlStaticContributions extends Pick<MutationDefaultGeneratorContributor, 'mutationDefaultGenerators'> {
277
277
  readonly codecs: () => ReadonlyArray<AnyCodecDescriptor>;
278
278
  readonly queryOperations?: () => SqlOperationDescriptors;
279
- readonly mutationDefaultGenerators?: () => ReadonlyArray<RuntimeMutationDefaultGenerator>;
280
- }
281
- /**
282
- * Scope across which a generator's value is constant.
283
- *
284
- * - `'field'` — one value per defaulting site (one column, one row). Cache strategy: no cache; call per defaulting site. Right for per-row identifiers (UUIDs, CUIDs, ULIDs, nanoid, ksuid).
285
- * - `'row'` — one value across all defaulting sites of one row of one operation. Cache strategy: per-call cache keyed by `generatorId`. Right for correlation ids stamped into multiple columns of one row.
286
- * - `'query'` — one value across all rows and columns of one ORM operation. Cache strategy: caller-provided cache keyed by `generatorId`. Right for `timestampNow` (a single timestamp per bulk insert/update).
287
- */
288
- type GeneratorStability = 'field' | 'row' | 'query';
289
- interface RuntimeMutationDefaultGenerator {
290
- readonly id: string;
291
- readonly generate: (params?: Record<string, unknown>) => unknown;
292
- /**
293
- * Scope across which the generator's value is constant. The framework derives the cache strategy from this declaration; generator authors never need to know about cache keys. See `GeneratorStability` for the per-value semantics.
294
- */
295
- readonly stability: GeneratorStability;
296
279
  }
297
280
  interface SqlRuntimeTargetDescriptor<TTargetId extends string = string, TTargetInstance extends RuntimeTargetInstance<'sql', TTargetId> = RuntimeTargetInstance<'sql', TTargetId>> extends RuntimeTargetDescriptor<'sql', TTargetId, TTargetInstance>, SqlStaticContributions {}
298
281
  interface SqlRuntimeAdapterDescriptor<TTargetId extends string = string, TAdapterInstance extends RuntimeAdapterInstance<'sql', TTargetId> = SqlRuntimeAdapterInstance<TTargetId>> extends RuntimeAdapterDescriptor<'sql', TTargetId, TAdapterInstance>, SqlStaticContributions {
@@ -529,5 +512,5 @@ declare class PreparedExecutionImpl<Params> implements PreparedExecution<Params>
529
512
  execute(target: RuntimeQueryable, params: Params, options?: RuntimeExecuteOptions): Promise<SqlStatementStats>;
530
513
  }
531
514
  //#endregion
532
- export { SqlMiddleware as A, TelemetryOutcome as B, RuntimeOptions as C, RuntimeTransaction as D, RuntimeTelemetryEvent as E, SqlRuntimeDriverInstance as F, deriveParamMetadata as G, VerifyMarkerOption as H, SqlRuntimeExtensionDescriptor as I, preparedStatementQuery as J, encodeParamsWithMetadata as K, SqlRuntimeExtensionInstance as L, SqlRuntimeAdapterDescriptor as M, SqlRuntimeAdapterInstance as N, SqlExecutionStack as O, SqlRuntimeBase as P, SqlRuntimeTargetDescriptor as R, RuntimeMutationDefaultGenerator as S, RuntimeQueryable as T, createExecutionContext as U, TransactionContext as V, createSqlExecutionStack as W, withTransaction as Y, PreparedStatementInternals as _, DeclaredNullable as a, RuntimeConnection as b, ParamSpec as c, PreparedExecution as d, PreparedExecutionImpl as f, PreparedStatementImpl as g, PreparedStatementExecuteTarget as h, DeclaredCodecId as i, SqlMiddlewareContext as j, SqlExecutionStackWithDriver as k, ParamsFromDeclaration as l, PreparedStatement as m, ConnectionProvider as n, GeneratorStability as o, PreparedFor as p, preparedStatementExecute as q, Declaration as r, MarkerReader as s, BindSiteParams as t, PrepareCallback as u, PreparedStatementQueryTarget as v, RuntimeParameterizedCodecDescriptor as w, RuntimeFamilyAdapter as x, Runtime as y, SqlStaticContributions as z };
533
- //# sourceMappingURL=prepared-statement-B6zvhJej-Dl488oBR.d.mts.map
515
+ export { SqlRuntimeAdapterDescriptor as A, VerifyMarkerOption as B, RuntimeQueryable as C, SqlExecutionStackWithDriver as D, SqlExecutionStack as E, SqlRuntimeExtensionInstance as F, preparedStatementExecute as G, createSqlExecutionStack as H, SqlRuntimeTargetDescriptor as I, preparedStatementQuery as K, SqlStaticContributions as L, SqlRuntimeBase as M, SqlRuntimeDriverInstance as N, SqlMiddleware as O, SqlRuntimeExtensionDescriptor as P, TelemetryOutcome as R, RuntimeParameterizedCodecDescriptor as S, RuntimeTransaction as T, deriveParamMetadata as U, createExecutionContext as V, encodeParamsWithMetadata as W, PreparedStatementQueryTarget as _, DeclaredNullable as a, RuntimeFamilyAdapter as b, ParamsFromDeclaration as c, PreparedExecutionImpl as d, PreparedFor as f, PreparedStatementInternals as g, PreparedStatementImpl as h, DeclaredCodecId as i, SqlRuntimeAdapterInstance as j, SqlMiddlewareContext as k, PrepareCallback as l, PreparedStatementExecuteTarget as m, ConnectionProvider as n, MarkerReader as o, PreparedStatement as p, withTransaction as q, Declaration as r, ParamSpec as s, BindSiteParams as t, PreparedExecution as u, Runtime as v, RuntimeTelemetryEvent as w, RuntimeOptions as x, RuntimeConnection as y, TransactionContext as z };
516
+ //# sourceMappingURL=prepared-statement-BHSj2pDk-CRzjNpcv.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepared-statement-BHSj2pDk-CRzjNpcv.d.mts","names":[],"sources":["../../../../2-sql/5-runtime/dist/prepared-statement-BHSj2pDk.d.mts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;UAaU;WACC,OAAO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CAAiC,GAAG,KAAK,IAAI,sBAAsB,GAAG,MAAM,qBAAqB,WAAW,cAAc,UAAU,wBAAwB,oBAAoB;;YAEhL,mCAAmC,GAAG,IAAI,sBAAsB,IAAI,qBAAqB,WAAW,cAAc,UAAU,wBAAwB,QAAQ;EACtK,cAAc,QAAQ;UACd;EACR,aAAa;EACb,SAAS;UACD;UACA;UACA;;;UAGA;EACR,cAAc,QAAQ;;iBAEP,gBAAgB,GAAG,SAAS,oBAAoB,KAAK,IAAI,uBAAuB,YAAY,KAAK,QAAQ;;;UAGhH;WACC;WACA,KAAK;WACL,MAAM;WACN,gBAAgB;WAChB,eAAe;WACf,wBAAwB;;cAErB,sBAAsB,QAAQ,gBAAgB,kBAAkB,QAAQ,MAAM;WACjF;WACA,KAAK;WACL,MAAM;WACN,gBAAgB;WAChB,eAAe;WACf,wBAAwB;EACjC,YAAY,WAAW;EACvB,MAAM,QAAQ,kBAAkB,QAAQ,QAAQ,UAAU,wBAAwB,oBAAoB;;;;;;;;;;cAU1F,sBAAsB,mBAAmB,kBAAkB,SAAS;WACvE;WACA,KAAK;WACL,MAAM;WACN,gBAAgB;WAChB,eAAe;WACf,wBAAwB;EACjC,YAAY,WAAW;EACvB,QAAQ,QAAQ,kBAAkB,QAAQ,QAAQ,UAAU,wBAAwB,QAAQ"}
@@ -0,0 +1,224 @@
1
+ import { w as numeralText, x as escapePslString } from "./ast-Bhj549wG.mjs";
2
+ import { isDataTypeLoweringEntry } from "@prisma/orm-framework/components/authoring";
3
+ import { dataTypeId } from "@prisma/orm-framework/components/codec";
4
+ //#region ../../../2-sql/9-family/dist/psl-build.mjs
5
+ const DEFAULT_FUNCTION_ATTRIBUTES = {
6
+ "autoincrement()": "@default(autoincrement())",
7
+ "now()": "@default(now())"
8
+ };
9
+ /**
10
+ * The attribute a stored default prints as: a named function, a literal the column takes, or any
11
+ * other expression as a raw SQL tagged literal. `undefined` when a literal has no written form.
12
+ */
13
+ function mapDefault(columnDefault, options) {
14
+ switch (columnDefault.kind) {
15
+ case "literal": {
16
+ const text = writeDefaultLiteral(columnDefault.value, options);
17
+ return text === void 0 ? void 0 : { attribute: `@default(${text})` };
18
+ }
19
+ case "function": return { attribute: options?.functionAttributes?.[columnDefault.expression] ?? DEFAULT_FUNCTION_ATTRIBUTES[columnDefault.expression] ?? `@default(${sqlLiteralText(columnDefault.expression)})` };
20
+ }
21
+ }
22
+ /**
23
+ * A raw SQL default as a `sql` tagged literal. The backtick fence resolves only `` \` `` and `\\`,
24
+ * so a body holding a backtick is written inside the double-quote fence with PSL string escaping.
25
+ */
26
+ function sqlLiteralText(expression) {
27
+ if (expression.includes("`")) return `sql"${escapePslString(expression)}"`;
28
+ return `sql\`${expression.replace(/\\/g, "\\\\")}\``;
29
+ }
30
+ function writingSurface(entries) {
31
+ const entryOf = /* @__PURE__ */ new Map();
32
+ let classify;
33
+ let plainStringType;
34
+ let plainBooleanType;
35
+ const tagTypes = [];
36
+ for (const [key, entry] of Object.entries(entries)) {
37
+ if (isDataTypeLoweringEntry(entry)) continue;
38
+ const written = entry.written;
39
+ if (written.kind === "tag") {
40
+ entryOf.set(key, entry);
41
+ tagTypes.push(dataTypeId(key));
42
+ continue;
43
+ }
44
+ if (written.syntax === "number") {
45
+ classify = written.classify;
46
+ for (const type of written.types) entryOf.set(type, entry);
47
+ continue;
48
+ }
49
+ entryOf.set(key, entry);
50
+ if (written.syntax === "string") plainStringType = dataTypeId(key);
51
+ else plainBooleanType = dataTypeId(key);
52
+ }
53
+ return {
54
+ entryOf,
55
+ classify,
56
+ plainStringType,
57
+ plainBooleanType,
58
+ tagTypes
59
+ };
60
+ }
61
+ /**
62
+ * Every type the stored form could be a value of, in the order a written value would be read: a
63
+ * number or numeral text through the classifier first, then the plain syntax that matches the
64
+ * shape, then each tag, whose canonical form is a whole document.
65
+ */
66
+ function classifications(value, surface) {
67
+ const found = [];
68
+ if (typeof value === "number") {
69
+ const classified = surface.classify?.(numeralText(value));
70
+ return classified === void 0 ? [] : [classified];
71
+ }
72
+ if (typeof value === "boolean") return surface.plainBooleanType === void 0 ? [] : [{
73
+ type: surface.plainBooleanType,
74
+ value
75
+ }];
76
+ if (typeof value === "string") {
77
+ const classified = surface.classify?.(value);
78
+ if (classified !== void 0) found.push(classified);
79
+ if (surface.plainStringType !== void 0) found.push({
80
+ type: surface.plainStringType,
81
+ value
82
+ });
83
+ }
84
+ for (const type of surface.tagTypes) found.push({
85
+ type,
86
+ value
87
+ });
88
+ return found;
89
+ }
90
+ /** The stored form the column takes this value as, or `undefined` when its type takes no such value. */
91
+ function admitted(candidate, columnDataType, dataTypes) {
92
+ if (candidate.type === columnDataType) return candidate.value;
93
+ const cast = dataTypes.get(columnDataType)?.casts[candidate.type];
94
+ if (cast === void 0) return void 0;
95
+ try {
96
+ return cast(candidate.value);
97
+ } catch {
98
+ return;
99
+ }
100
+ }
101
+ /** The body of the literal: what the entry prints, before the syntax that fences it. */
102
+ function printedBody(entry, value) {
103
+ try {
104
+ return entry.print(value);
105
+ } catch {
106
+ return;
107
+ }
108
+ }
109
+ /** What the entry reads the printed body back as, which for a number is the classifier's answer. */
110
+ function readBack(entry, type, body) {
111
+ const written = entry.written;
112
+ try {
113
+ return written.kind === "plain" && written.syntax === "number" ? written.classify(body) : {
114
+ type,
115
+ value: written.parse(body)
116
+ };
117
+ } catch {
118
+ return;
119
+ }
120
+ }
121
+ /**
122
+ * The literal as PSL source. A tag body sits inside a backtick fence, which resolves `` \` `` and
123
+ * `\\` and nothing else, so a `\n` in the body survives as the two characters the entry wrote.
124
+ */
125
+ function literalText(entry, body) {
126
+ const written = entry.written;
127
+ if (written.kind === "tag") {
128
+ const fenced = body.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
129
+ return `${written.tag}\`${fenced}\``;
130
+ }
131
+ return written.syntax === "string" ? `"${escapePslString(body)}"` : body;
132
+ }
133
+ /**
134
+ * The value written as the literal of one of its types, proven by reading the text straight back:
135
+ * the same entry, the same cast, and the stored form again.
136
+ */
137
+ function writeScalar(value, columnDataType, dataTypes, surface) {
138
+ for (const candidate of classifications(value, surface)) {
139
+ const entry = surface.entryOf.get(candidate.type);
140
+ if (entry === void 0) continue;
141
+ const stored = admitted(candidate, columnDataType, dataTypes);
142
+ if (stored === void 0 || !sameForm(stored, value)) continue;
143
+ const body = printedBody(entry, candidate.value);
144
+ if (body === void 0) continue;
145
+ const reread = readBack(entry, candidate.type, body);
146
+ if (reread === void 0) continue;
147
+ const restored = admitted(reread, columnDataType, dataTypes);
148
+ if (restored === void 0 || !sameForm(restored, value)) continue;
149
+ return literalText(entry, body);
150
+ }
151
+ }
152
+ /** One written element of a list, printed as a value of any type, with no column type to admit it. */
153
+ function writeElement(value, of, surface) {
154
+ for (const candidate of classifications(value, surface)) {
155
+ if (!of.includes(candidate.type)) continue;
156
+ const entry = surface.entryOf.get(candidate.type);
157
+ if (entry === void 0) continue;
158
+ const body = printedBody(entry, candidate.value);
159
+ if (body === void 0) continue;
160
+ const reread = readBack(entry, candidate.type, body);
161
+ if (reread === void 0 || !of.includes(reread.type)) continue;
162
+ return {
163
+ text: literalText(entry, body),
164
+ value: reread.value
165
+ };
166
+ }
167
+ }
168
+ /**
169
+ * A written list on a scalar column, which the column type's list cast turns into its one value.
170
+ * Each element is classified on its own and must be of a type the cast takes.
171
+ */
172
+ function writeListCast(value, columnDataType, dataTypes, surface) {
173
+ const listCast = dataTypes.get(columnDataType)?.listCast;
174
+ if (listCast === void 0) return void 0;
175
+ const parts = [];
176
+ const elements = [];
177
+ for (const element of value) {
178
+ const written = writeElement(element, listCast.of, surface);
179
+ if (written === void 0) return void 0;
180
+ parts.push(written.text);
181
+ elements.push(written.value);
182
+ }
183
+ try {
184
+ if (!sameForm(listCast.cast(elements), value)) return void 0;
185
+ } catch {
186
+ return;
187
+ }
188
+ return `[${parts.join(", ")}]`;
189
+ }
190
+ function writeDefaultLiteral(value, options) {
191
+ if (value instanceof Date) return void 0;
192
+ const { dataTypeEntries, dataTypes, columnDataType } = options ?? {};
193
+ if (dataTypeEntries === void 0 || dataTypes === void 0 || columnDataType === void 0) return;
194
+ const surface = writingSurface(dataTypeEntries);
195
+ if (options?.list === true) {
196
+ if (!Array.isArray(value)) return void 0;
197
+ const parts = [];
198
+ for (const element of value) {
199
+ const written = writeScalar(element, columnDataType, dataTypes, surface);
200
+ if (written === void 0) return void 0;
201
+ parts.push(written);
202
+ }
203
+ return `[${parts.join(", ")}]`;
204
+ }
205
+ const written = writeScalar(value, columnDataType, dataTypes, surface);
206
+ if (written !== void 0) return written;
207
+ return Array.isArray(value) ? writeListCast(value, columnDataType, dataTypes, surface) : void 0;
208
+ }
209
+ /** Whether two canonical forms are the same JSON value, member by member and element by element. */
210
+ function sameForm(left, right) {
211
+ if (left === right) return true;
212
+ if (Array.isArray(left) !== Array.isArray(right)) return false;
213
+ if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) return false;
214
+ const members = Object.entries(left);
215
+ const others = new Map(Object.entries(right));
216
+ return members.length === others.size && members.every(([key, member]) => {
217
+ const other = others.get(key);
218
+ return other !== void 0 && sameForm(member, other);
219
+ });
220
+ }
221
+ //#endregion
222
+ export { mapDefault as t };
223
+
224
+ //# sourceMappingURL=psl-build-Cp32ahjI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"psl-build-Cp32ahjI.mjs","names":[],"sources":["../../../../2-sql/9-family/dist/psl-build.mjs"],"sourcesContent":["import { s as toEnumMemberName } from \"./psl-names-C3cwe0rg.mjs\";\nimport { isDataTypeLoweringEntry } from \"@internal/framework-components/authoring\";\nimport { dataTypeId } from \"@internal/framework-components/codec\";\nimport { escapePslString, numeralText } from \"@internal/sql-relational-core/ast\";\n//#region src/core/psl-build/default-mapping.ts\nconst DEFAULT_FUNCTION_ATTRIBUTES = {\n\t\"autoincrement()\": \"@default(autoincrement())\",\n\t\"now()\": \"@default(now())\"\n};\n/**\n* The attribute a stored default prints as: a named function, a literal the column takes, or any\n* other expression as a raw SQL tagged literal. `undefined` when a literal has no written form.\n*/\nfunction mapDefault(columnDefault, options) {\n\tswitch (columnDefault.kind) {\n\t\tcase \"literal\": {\n\t\t\tconst text = writeDefaultLiteral(columnDefault.value, options);\n\t\t\treturn text === void 0 ? void 0 : { attribute: `@default(${text})` };\n\t\t}\n\t\tcase \"function\": return { attribute: options?.functionAttributes?.[columnDefault.expression] ?? DEFAULT_FUNCTION_ATTRIBUTES[columnDefault.expression] ?? `@default(${sqlLiteralText(columnDefault.expression)})` };\n\t}\n}\n/**\n* A raw SQL default as a `sql` tagged literal. The backtick fence resolves only `` \\` `` and `\\\\`,\n* so a body holding a backtick is written inside the double-quote fence with PSL string escaping.\n*/\nfunction sqlLiteralText(expression) {\n\tif (expression.includes(\"`\")) return `sql\"${escapePslString(expression)}\"`;\n\treturn `sql\\`${expression.replace(/\\\\/g, \"\\\\\\\\\")}\\``;\n}\nfunction writingSurface(entries) {\n\tconst entryOf = /* @__PURE__ */ new Map();\n\tlet classify;\n\tlet plainStringType;\n\tlet plainBooleanType;\n\tconst tagTypes = [];\n\tfor (const [key, entry] of Object.entries(entries)) {\n\t\tif (isDataTypeLoweringEntry(entry)) continue;\n\t\tconst written = entry.written;\n\t\tif (written.kind === \"tag\") {\n\t\t\tentryOf.set(key, entry);\n\t\t\ttagTypes.push(dataTypeId(key));\n\t\t\tcontinue;\n\t\t}\n\t\tif (written.syntax === \"number\") {\n\t\t\tclassify = written.classify;\n\t\t\tfor (const type of written.types) entryOf.set(type, entry);\n\t\t\tcontinue;\n\t\t}\n\t\tentryOf.set(key, entry);\n\t\tif (written.syntax === \"string\") plainStringType = dataTypeId(key);\n\t\telse plainBooleanType = dataTypeId(key);\n\t}\n\treturn {\n\t\tentryOf,\n\t\tclassify,\n\t\tplainStringType,\n\t\tplainBooleanType,\n\t\ttagTypes\n\t};\n}\n/**\n* Every type the stored form could be a value of, in the order a written value would be read: a\n* number or numeral text through the classifier first, then the plain syntax that matches the\n* shape, then each tag, whose canonical form is a whole document.\n*/\nfunction classifications(value, surface) {\n\tconst found = [];\n\tif (typeof value === \"number\") {\n\t\tconst classified = surface.classify?.(numeralText(value));\n\t\treturn classified === void 0 ? [] : [classified];\n\t}\n\tif (typeof value === \"boolean\") return surface.plainBooleanType === void 0 ? [] : [{\n\t\ttype: surface.plainBooleanType,\n\t\tvalue\n\t}];\n\tif (typeof value === \"string\") {\n\t\tconst classified = surface.classify?.(value);\n\t\tif (classified !== void 0) found.push(classified);\n\t\tif (surface.plainStringType !== void 0) found.push({\n\t\t\ttype: surface.plainStringType,\n\t\t\tvalue\n\t\t});\n\t}\n\tfor (const type of surface.tagTypes) found.push({\n\t\ttype,\n\t\tvalue\n\t});\n\treturn found;\n}\n/** The stored form the column takes this value as, or `undefined` when its type takes no such value. */\nfunction admitted(candidate, columnDataType, dataTypes) {\n\tif (candidate.type === columnDataType) return candidate.value;\n\tconst cast = dataTypes.get(columnDataType)?.casts[candidate.type];\n\tif (cast === void 0) return void 0;\n\ttry {\n\t\treturn cast(candidate.value);\n\t} catch {\n\t\treturn;\n\t}\n}\n/** The body of the literal: what the entry prints, before the syntax that fences it. */\nfunction printedBody(entry, value) {\n\ttry {\n\t\treturn entry.print(value);\n\t} catch {\n\t\treturn;\n\t}\n}\n/** What the entry reads the printed body back as, which for a number is the classifier's answer. */\nfunction readBack(entry, type, body) {\n\tconst written = entry.written;\n\ttry {\n\t\treturn written.kind === \"plain\" && written.syntax === \"number\" ? written.classify(body) : {\n\t\t\ttype,\n\t\t\tvalue: written.parse(body)\n\t\t};\n\t} catch {\n\t\treturn;\n\t}\n}\n/**\n* The literal as PSL source. A tag body sits inside a backtick fence, which resolves `` \\` `` and\n* `\\\\` and nothing else, so a `\\n` in the body survives as the two characters the entry wrote.\n*/\nfunction literalText(entry, body) {\n\tconst written = entry.written;\n\tif (written.kind === \"tag\") {\n\t\tconst fenced = body.replace(/\\\\/g, \"\\\\\\\\\").replace(/`/g, \"\\\\`\");\n\t\treturn `${written.tag}\\`${fenced}\\``;\n\t}\n\treturn written.syntax === \"string\" ? `\"${escapePslString(body)}\"` : body;\n}\n/**\n* The value written as the literal of one of its types, proven by reading the text straight back:\n* the same entry, the same cast, and the stored form again.\n*/\nfunction writeScalar(value, columnDataType, dataTypes, surface) {\n\tfor (const candidate of classifications(value, surface)) {\n\t\tconst entry = surface.entryOf.get(candidate.type);\n\t\tif (entry === void 0) continue;\n\t\tconst stored = admitted(candidate, columnDataType, dataTypes);\n\t\tif (stored === void 0 || !sameForm(stored, value)) continue;\n\t\tconst body = printedBody(entry, candidate.value);\n\t\tif (body === void 0) continue;\n\t\tconst reread = readBack(entry, candidate.type, body);\n\t\tif (reread === void 0) continue;\n\t\tconst restored = admitted(reread, columnDataType, dataTypes);\n\t\tif (restored === void 0 || !sameForm(restored, value)) continue;\n\t\treturn literalText(entry, body);\n\t}\n}\n/** One written element of a list, printed as a value of any type, with no column type to admit it. */\nfunction writeElement(value, of, surface) {\n\tfor (const candidate of classifications(value, surface)) {\n\t\tif (!of.includes(candidate.type)) continue;\n\t\tconst entry = surface.entryOf.get(candidate.type);\n\t\tif (entry === void 0) continue;\n\t\tconst body = printedBody(entry, candidate.value);\n\t\tif (body === void 0) continue;\n\t\tconst reread = readBack(entry, candidate.type, body);\n\t\tif (reread === void 0 || !of.includes(reread.type)) continue;\n\t\treturn {\n\t\t\ttext: literalText(entry, body),\n\t\t\tvalue: reread.value\n\t\t};\n\t}\n}\n/**\n* A written list on a scalar column, which the column type's list cast turns into its one value.\n* Each element is classified on its own and must be of a type the cast takes.\n*/\nfunction writeListCast(value, columnDataType, dataTypes, surface) {\n\tconst listCast = dataTypes.get(columnDataType)?.listCast;\n\tif (listCast === void 0) return void 0;\n\tconst parts = [];\n\tconst elements = [];\n\tfor (const element of value) {\n\t\tconst written = writeElement(element, listCast.of, surface);\n\t\tif (written === void 0) return void 0;\n\t\tparts.push(written.text);\n\t\telements.push(written.value);\n\t}\n\ttry {\n\t\tif (!sameForm(listCast.cast(elements), value)) return void 0;\n\t} catch {\n\t\treturn;\n\t}\n\treturn `[${parts.join(\", \")}]`;\n}\nfunction writeDefaultLiteral(value, options) {\n\tif (value instanceof Date) return void 0;\n\tconst { dataTypeEntries, dataTypes, columnDataType } = options ?? {};\n\tif (dataTypeEntries === void 0 || dataTypes === void 0 || columnDataType === void 0) return;\n\tconst surface = writingSurface(dataTypeEntries);\n\tif (options?.list === true) {\n\t\tif (!Array.isArray(value)) return void 0;\n\t\tconst parts = [];\n\t\tfor (const element of value) {\n\t\t\tconst written = writeScalar(element, columnDataType, dataTypes, surface);\n\t\t\tif (written === void 0) return void 0;\n\t\t\tparts.push(written);\n\t\t}\n\t\treturn `[${parts.join(\", \")}]`;\n\t}\n\tconst written = writeScalar(value, columnDataType, dataTypes, surface);\n\tif (written !== void 0) return written;\n\treturn Array.isArray(value) ? writeListCast(value, columnDataType, dataTypes, surface) : void 0;\n}\n/** Whether two canonical forms are the same JSON value, member by member and element by element. */\nfunction sameForm(left, right) {\n\tif (left === right) return true;\n\tif (Array.isArray(left) !== Array.isArray(right)) return false;\n\tif (typeof left !== \"object\" || typeof right !== \"object\" || left === null || right === null) return false;\n\tconst members = Object.entries(left);\n\tconst others = new Map(Object.entries(right));\n\treturn members.length === others.size && members.every(([key, member]) => {\n\t\tconst other = others.get(key);\n\t\treturn other !== void 0 && sameForm(member, other);\n\t});\n}\n//#endregion\nexport { mapDefault, toEnumMemberName };\n\n//# sourceMappingURL=psl-build.mjs.map"],"mappings":";;;;AAKA,MAAM,8BAA8B;CACnC,mBAAmB;CACnB,SAAS;AACV;;;;;AAKA,SAAS,WAAW,eAAe,SAAS;CAC3C,QAAQ,cAAc,MAAtB;EACC,KAAK,WAAW;GACf,MAAM,OAAO,oBAAoB,cAAc,OAAO,OAAO;GAC7D,OAAO,SAAS,KAAK,IAAI,KAAK,IAAI,EAAE,WAAW,YAAY,KAAK,GAAG;EACpE;EACA,KAAK,YAAY,OAAO,EAAE,WAAW,SAAS,qBAAqB,cAAc,eAAe,4BAA4B,cAAc,eAAe,YAAY,eAAe,cAAc,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AQ,WAAW,OAAO,QAAQ,QAAQ,OAAO,CAAC,KAAK,YAAY;EACzE,MAAM,QAAQ,OAAO,IAAI,GAAG;EAC5B,OAAO,UAAU,KAAK,KAAK,SAAS,QAAQ,KAAK;CAClD,CAAC;AACF"}
@@ -0,0 +1,13 @@
1
+ import "./type-map-BwBI56i3-DDERtzxf.mjs";
2
+ //#region ../../../2-sql/9-family/dist/psl-build.d.mts
3
+ //#region src/core/psl-build/psl-names.d.ts
4
+ /**
5
+ * PSL member name for a native-enum value. The value itself always prints
6
+ * explicitly (`member = "value"`), so the returned name never needs a map:
7
+ * a value that already is a valid, non-reserved identifier is kept verbatim
8
+ * (case included); anything else is camelCased/escaped like a field name.
9
+ */
10
+ declare function toEnumMemberName(value: string): string;
11
+ //#endregion
12
+ export { toEnumMemberName as t };
13
+ //# sourceMappingURL=psl-build-yBrQQN3r.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"psl-build-yBrQQN3r.d.mts","names":[],"sources":["../../../../2-sql/9-family/dist/psl-build.d.mts"],"mappings":";;;;;;;;;iBAQiB,iBAAiB"}
@@ -1,33 +1,8 @@
1
1
  import { d as SqlForeignKeyIR, y as SqlTableIR } from "./types-CHOgKgHg-BxgkL3GS.mjs";
2
2
  import "./types-BijNazlM.mjs";
3
- import { AuthoringDataTypeEntry } from "@prisma/orm-framework/components/authoring";
3
+ import { r as PslTypeMap, t as DefaultMappingOptions } from "./type-map-BwBI56i3-DDERtzxf.mjs";
4
4
  import { ColumnDefault } from "@prisma/orm-framework/contract/types";
5
- import { DataTypeId, DataTypeLookup } from "@prisma/orm-framework/components/codec";
6
5
  //#region ../../../2-sql/9-family/dist/psl-infer.d.mts
7
- //#region src/core/psl-contract-infer/default-mapping.d.ts
8
- interface DefaultMappingOptions {
9
- readonly functionAttributes?: Readonly<Record<string, string>>;
10
- /** PSL support for the stack's data types, keyed by data type id. */
11
- readonly dataTypeEntries?: Readonly<Record<string, AuthoringDataTypeEntry>> | undefined;
12
- /** The stack's data types, whose casts say which other types' values each one takes. */
13
- readonly dataTypes?: DataTypeLookup | undefined;
14
- /** The data type of the column's codec. */
15
- readonly columnDataType?: DataTypeId | undefined;
16
- /**
17
- * Whether the column is a list, whose elements each carry the column's own data type. A written
18
- * list on a scalar column goes through that type's list cast instead.
19
- */
20
- readonly list?: boolean;
21
- }
22
- type DefaultMappingResult = {
23
- readonly attribute: string;
24
- };
25
- /**
26
- * The attribute a stored default prints as: a named function, a literal the column takes, or any
27
- * other expression as a raw SQL tagged literal. `undefined` when a literal has no written form.
28
- */
29
- declare function mapDefault(columnDefault: ColumnDefault, options?: DefaultMappingOptions): DefaultMappingResult | undefined;
30
- //#endregion
31
6
  //#region src/core/psl-contract-infer/name-transforms.d.ts
32
7
  type NameResult = {
33
8
  readonly name: string;
@@ -36,33 +11,11 @@ type NameResult = {
36
11
  declare function toModelName(tableName: string): NameResult;
37
12
  declare function toFieldName(columnName: string): NameResult;
38
13
  declare function toEnumName(pgTypeName: string): NameResult;
39
- /**
40
- * PSL member name for a native-enum value. The value itself always prints
41
- * explicitly (`member = "value"`), so the returned name never needs a map:
42
- * a value that already is a valid, non-reserved identifier is kept verbatim
43
- * (case included); anything else is camelCased/escaped like a field name.
44
- */
45
- declare function toEnumMemberName(value: string): string;
46
14
  declare function pluralize(word: string): string;
47
15
  declare function deriveRelationFieldName(fkColumns: readonly string[], referencedTableName: string): string;
48
16
  declare function deriveBackRelationFieldName(childModelName: string, isOneToOne: boolean): string;
49
17
  //#endregion
50
18
  //#region src/core/psl-contract-infer/printer-config.d.ts
51
- type PslTypeReference = {
52
- readonly name: string;
53
- readonly args?: readonly string[];
54
- };
55
- type PslTypeResolution = {
56
- readonly pslType: PslTypeReference;
57
- readonly nativeType: string;
58
- readonly typeParams?: Record<string, unknown>;
59
- } | {
60
- readonly unsupported: true;
61
- readonly nativeType: string;
62
- };
63
- interface PslTypeMap {
64
- resolve(nativeType: string, annotations?: Record<string, unknown>): PslTypeResolution;
65
- }
66
19
  interface EnumInfo {
67
20
  readonly typeNames: ReadonlySet<string>;
68
21
  readonly definitions: ReadonlyMap<string, readonly string[]>;
@@ -126,5 +79,5 @@ declare function inferRelations(tables: Record<string, SqlTableIR>, modelNameMap
126
79
  */
127
80
  declare function buildChildRelationField(fieldName: string, parentModelName: string, fk: SqlForeignKeyIR, optional: boolean, relationName?: string, hostTable?: SqlTableIR): RelationField;
128
81
  //#endregion
129
- export { toEnumName as _, PslPrinterOptions as a, PslTypeResolution as c, deriveBackRelationFieldName as d, deriveRelationFieldName as f, toEnumMemberName as g, pluralize as h, InferredRelations as i, RelationField as l, mapDefault as m, DefaultMappingResult as n, PslTypeMap as o, inferRelations as p, EnumInfo as r, PslTypeReference as s, DefaultMappingOptions as t, buildChildRelationField as u, toFieldName as v, toModelName as y };
130
- //# sourceMappingURL=psl-infer-CuTqC9UV.d.mts.map
82
+ export { buildChildRelationField as a, inferRelations as c, toFieldName as d, toModelName as f, RelationField as i, pluralize as l, InferredRelations as n, deriveBackRelationFieldName as o, PslPrinterOptions as r, deriveRelationFieldName as s, EnumInfo as t, toEnumName as u };
83
+ //# sourceMappingURL=psl-infer-BzjA7U3b.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"psl-infer-BzjA7U3b.d.mts","names":[],"sources":["../../../../2-sql/9-family/dist/psl-infer.d.mts"],"mappings":";;;;;;KAIK;WACM;WACA;;iBAEM,YAAY,oBAAoB;iBAChC,YAAY,qBAAqB;iBACjC,WAAW,qBAAqB;iBAChC,UAAU;iBACV,wBAAwB,8BAA8B;iBACtD,4BAA4B,wBAAwB;;;UAG3D;WACC,WAAW;WACX,aAAa;;UAEd;WACC,SAAS;WACT,iBAAiB;WACjB,WAAW;WACX,mBAAmB,oBAAoB,wBAAwB;;KAErE;WACM;WACA;;;;;;WAMA;;;;;;WAMA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;WAEA;;;;KAIN;WACM,kBAAkB,6BAA6B;;iBAEzC,eAAe,QAAQ,eAAe,aAAa,cAAc,8BAA8B;;;;;;;;;;;;;;;;;;;iBAmB/F,wBAAwB,mBAAmB,yBAAyB,IAAI,iBAAiB,mBAAmB,uBAAuB,YAAY,aAAa"}
@@ -0,0 +1,195 @@
1
+ import { n as isBackedByColumnKeys, t as backingIndexColumnKeys } from "./foreign-key-materialization-B3HQzQIA.mjs";
2
+ import { t as defaultTableName } from "./default-table-name-BfFY8qYR-lHNcVmY5.mjs";
3
+ import { a as snakeToCamelCase, i as needsEscaping, n as escapeName, o as snakeToPascalCase, r as hasSeparators, t as escapeIfNeeded } from "./psl-names-C3cwe0rg-CsuHOV7E.mjs";
4
+ import { InternalError } from "@prisma/orm-framework/utils/internal-error";
5
+ import pluralizeLib from "pluralize";
6
+ //#region ../../../2-sql/9-family/dist/psl-infer.mjs
7
+ function toModelName(tableName) {
8
+ let name;
9
+ if (hasSeparators(tableName)) name = snakeToPascalCase(tableName);
10
+ else name = tableName.charAt(0).toUpperCase() + tableName.slice(1);
11
+ if (needsEscaping(name)) return {
12
+ name: escapeName(name),
13
+ map: tableName
14
+ };
15
+ if (defaultTableName(name) !== tableName) return {
16
+ name,
17
+ map: tableName
18
+ };
19
+ return { name };
20
+ }
21
+ function toFieldName(columnName) {
22
+ let name;
23
+ if (hasSeparators(columnName)) name = snakeToCamelCase(columnName);
24
+ else name = columnName.charAt(0).toLowerCase() + columnName.slice(1);
25
+ if (needsEscaping(name)) return {
26
+ name: escapeName(name),
27
+ map: columnName
28
+ };
29
+ if (name !== columnName) return {
30
+ name,
31
+ map: columnName
32
+ };
33
+ return { name };
34
+ }
35
+ function toEnumName(pgTypeName) {
36
+ let name;
37
+ if (hasSeparators(pgTypeName)) name = snakeToPascalCase(pgTypeName);
38
+ else name = pgTypeName.charAt(0).toUpperCase() + pgTypeName.slice(1);
39
+ if (needsEscaping(name)) return {
40
+ name: escapeName(name),
41
+ map: pgTypeName
42
+ };
43
+ if (name !== pgTypeName) return {
44
+ name,
45
+ map: pgTypeName
46
+ };
47
+ return { name };
48
+ }
49
+ function pluralize(word) {
50
+ return pluralizeLib.plural(word);
51
+ }
52
+ function deriveRelationFieldName(fkColumns, referencedTableName) {
53
+ if (fkColumns.length === 1) {
54
+ const [col = referencedTableName] = fkColumns;
55
+ const stripped = col.replace(/_id$/i, "").replace(/Id$/, "");
56
+ if (stripped.length > 0 && stripped !== col) return escapeIfNeeded(snakeToCamelCase(stripped));
57
+ return escapeIfNeeded(snakeToCamelCase(referencedTableName));
58
+ }
59
+ return escapeIfNeeded(snakeToCamelCase(referencedTableName));
60
+ }
61
+ function deriveBackRelationFieldName(childModelName, isOneToOne) {
62
+ const base = childModelName.charAt(0).toLowerCase() + childModelName.slice(1);
63
+ return isOneToOne ? base : pluralize(base);
64
+ }
65
+ const DEFAULT_ON_DELETE = "noAction";
66
+ const DEFAULT_ON_UPDATE = "noAction";
67
+ const REFERENTIAL_ACTION_PSL = {
68
+ noAction: "NoAction",
69
+ restrict: "Restrict",
70
+ cascade: "Cascade",
71
+ setNull: "SetNull",
72
+ setDefault: "SetDefault"
73
+ };
74
+ function inferRelations(tables, modelNameMap) {
75
+ const relationsByTable = /* @__PURE__ */ new Map();
76
+ const fkCountByPair = /* @__PURE__ */ new Map();
77
+ for (const table of Object.values(tables)) for (const fk of table.foreignKeys) {
78
+ const pairKey = `${table.name}→${fk.referencedTable}`;
79
+ fkCountByPair.set(pairKey, (fkCountByPair.get(pairKey) ?? 0) + 1);
80
+ }
81
+ const usedFieldNames = /* @__PURE__ */ new Map();
82
+ for (const table of Object.values(tables)) {
83
+ const names = /* @__PURE__ */ new Set();
84
+ for (const col of Object.values(table.columns)) names.add(col.name);
85
+ usedFieldNames.set(table.name, names);
86
+ }
87
+ for (const table of Object.values(tables)) for (const fk of table.foreignKeys) {
88
+ const childTableName = table.name;
89
+ const parentTableName = fk.referencedTable;
90
+ const childUsed = usedFieldNames.get(childTableName);
91
+ if (childUsed === void 0) throw new InternalError(`Missing inferred field-name set for table "${childTableName}"`);
92
+ const childModelName = modelNameMap.get(childTableName) ?? childTableName;
93
+ const parentModelName = modelNameMap.get(parentTableName) ?? parentTableName;
94
+ const pairKey = `${childTableName}→${parentTableName}`;
95
+ const isSelfRelation = childTableName === parentTableName;
96
+ const needsRelationName = (fkCountByPair.get(pairKey) ?? 0) > 1 || isSelfRelation;
97
+ const isOneToOne = detectOneToOne(fk, table);
98
+ const childRelFieldName = resolveUniqueFieldName(deriveRelationFieldName(fk.columns, parentTableName), childUsed, parentModelName);
99
+ const relationName = needsRelationName ? deriveRelationName(fk, childRelFieldName, parentModelName, isSelfRelation) : void 0;
100
+ addRelationField(relationsByTable, childTableName, buildChildRelationField(childRelFieldName, parentModelName, fk, fk.columns.some((columnName) => table.columns[columnName]?.nullable ?? false), relationName, table));
101
+ childUsed.add(childRelFieldName);
102
+ const parentUsed = usedFieldNames.get(parentTableName) ?? /* @__PURE__ */ new Set();
103
+ usedFieldNames.set(parentTableName, parentUsed);
104
+ const backRelFieldName = resolveUniqueFieldName(deriveBackRelationFieldName(childModelName, isOneToOne), parentUsed, childModelName);
105
+ addRelationField(relationsByTable, parentTableName, {
106
+ fieldName: backRelFieldName,
107
+ typeName: childModelName,
108
+ optional: isOneToOne,
109
+ list: !isOneToOne,
110
+ relationName
111
+ });
112
+ parentUsed.add(backRelFieldName);
113
+ }
114
+ return { relationsByTable };
115
+ }
116
+ function detectOneToOne(fk, table) {
117
+ const fkCols = [...fk.columns].sort();
118
+ if (table.primaryKey) {
119
+ const pkCols = [...table.primaryKey.columns].sort();
120
+ if (pkCols.length === fkCols.length && pkCols.every((c, i) => c === fkCols[i])) return true;
121
+ }
122
+ for (const unique of table.uniques) {
123
+ const uniqueCols = [...unique.columns].sort();
124
+ if (uniqueCols.length === fkCols.length && uniqueCols.every((c, i) => c === fkCols[i])) return true;
125
+ }
126
+ for (const index of table.indexes) {
127
+ if (!index.unique || index.partial || index.columns === void 0) continue;
128
+ const indexCols = [...index.columns].sort();
129
+ if (indexCols.length === fkCols.length && indexCols.every((c, i) => c === fkCols[i])) return true;
130
+ }
131
+ return false;
132
+ }
133
+ function deriveRelationName(fk, childRelationFieldName, parentModelName, isSelfRelation) {
134
+ if (fk.name) return fk.name;
135
+ if (isSelfRelation) return `${childRelationFieldName.charAt(0).toUpperCase() + childRelationFieldName.slice(1)}${pluralize(parentModelName)}`;
136
+ return fk.columns.join("_");
137
+ }
138
+ /**
139
+ * Builds the child-side {@link RelationField} for a single foreign key:
140
+ * `typeName` is the parent model name, `fields`/`references` are the FK's raw
141
+ * columns, and `onDelete`/`onUpdate` are normalized to their PSL spelling.
142
+ * Exported so a caller resolving a foreign key against a model outside
143
+ * `tables` (e.g. a cross-space reference into another contract) can reuse the
144
+ * same normalization instead of duplicating it.
145
+ *
146
+ * `hostTable` is the table the FK is declared on (i.e. `table`, not the
147
+ * referenced parent) — its own indexes/uniques/primary key are what a
148
+ * backing index for this FK would be. When none of them exactly match the
149
+ * FK's source columns (in order), `index: false` is stamped so the emitted
150
+ * `@relation` opts out of the framework's default derived backing-index
151
+ * expectation, matching what `db verify` will find live. Passing the table
152
+ * is optional so existing single-FK callers (e.g. cross-space resolution
153
+ * before a host table reference is threaded through) can omit it and keep
154
+ * the framework default.
155
+ */
156
+ function buildChildRelationField(fieldName, parentModelName, fk, optional, relationName, hostTable) {
157
+ const onDelete = fk.onDelete && fk.onDelete !== DEFAULT_ON_DELETE ? fk.onDelete : void 0;
158
+ const onUpdate = fk.onUpdate && fk.onUpdate !== DEFAULT_ON_UPDATE ? fk.onUpdate : void 0;
159
+ const index = hostTable && !isBackedByColumnKeys(fk.columns, backingIndexColumnKeys({
160
+ indexes: hostTable.indexes.filter((i) => i.where === void 0),
161
+ uniques: hostTable.uniques,
162
+ primaryKey: hostTable.primaryKey
163
+ })) ? false : void 0;
164
+ return {
165
+ fieldName,
166
+ typeName: parentModelName,
167
+ referencedTableName: fk.referencedTable,
168
+ optional,
169
+ list: false,
170
+ relationName,
171
+ fkName: fk.name,
172
+ fields: fk.columns,
173
+ references: fk.referencedColumns,
174
+ onDelete: onDelete ? REFERENTIAL_ACTION_PSL[onDelete] : void 0,
175
+ onUpdate: onUpdate ? REFERENTIAL_ACTION_PSL[onUpdate] : void 0,
176
+ index
177
+ };
178
+ }
179
+ function resolveUniqueFieldName(desired, usedNames, fallbackSuffix) {
180
+ if (!usedNames.has(desired)) return desired;
181
+ const withSuffix = `${desired}${fallbackSuffix}`;
182
+ if (!usedNames.has(withSuffix)) return withSuffix;
183
+ let counter = 2;
184
+ while (usedNames.has(`${desired}${counter}`)) counter++;
185
+ return `${desired}${counter}`;
186
+ }
187
+ function addRelationField(map, tableName, field) {
188
+ const existing = map.get(tableName);
189
+ if (existing) existing.push(field);
190
+ else map.set(tableName, [field]);
191
+ }
192
+ //#endregion
193
+ export { pluralize as a, toModelName as c, inferRelations as i, deriveBackRelationFieldName as n, toEnumName as o, deriveRelationFieldName as r, toFieldName as s, buildChildRelationField as t };
194
+
195
+ //# sourceMappingURL=psl-infer-DwMyO-IV.mjs.map