@dsqlbase/core 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/definition/base.d.ts +3 -30
  3. package/dist/definition/base.d.ts.map +1 -1
  4. package/dist/definition/base.js +3 -14
  5. package/dist/definition/base.js.map +1 -1
  6. package/dist/definition/column.d.ts +22 -14
  7. package/dist/definition/column.d.ts.map +1 -1
  8. package/dist/definition/column.js +11 -37
  9. package/dist/definition/column.js.map +1 -1
  10. package/dist/definition/constraint.d.ts +9 -9
  11. package/dist/definition/constraint.d.ts.map +1 -1
  12. package/dist/definition/constraint.js.map +1 -1
  13. package/dist/definition/domain.d.ts +2 -1
  14. package/dist/definition/domain.d.ts.map +1 -1
  15. package/dist/definition/domain.js +2 -1
  16. package/dist/definition/domain.js.map +1 -1
  17. package/dist/definition/index.d.ts +5 -6
  18. package/dist/definition/index.d.ts.map +1 -1
  19. package/dist/definition/index.js +3 -4
  20. package/dist/definition/index.js.map +1 -1
  21. package/dist/definition/indexes.d.ts +9 -20
  22. package/dist/definition/indexes.d.ts.map +1 -1
  23. package/dist/definition/indexes.js +3 -6
  24. package/dist/definition/indexes.js.map +1 -1
  25. package/dist/definition/namespace.d.ts +2 -2
  26. package/dist/definition/namespace.d.ts.map +1 -1
  27. package/dist/definition/namespace.js.map +1 -1
  28. package/dist/definition/policy.d.ts +35 -0
  29. package/dist/definition/policy.d.ts.map +1 -0
  30. package/dist/definition/policy.js +42 -0
  31. package/dist/definition/policy.js.map +1 -0
  32. package/dist/definition/relations.d.ts +28 -33
  33. package/dist/definition/relations.d.ts.map +1 -1
  34. package/dist/definition/relations.js +1 -4
  35. package/dist/definition/relations.js.map +1 -1
  36. package/dist/definition/table.d.ts +39 -32
  37. package/dist/definition/table.d.ts.map +1 -1
  38. package/dist/definition/table.js +57 -67
  39. package/dist/definition/table.js.map +1 -1
  40. package/dist/definition/union.d.ts +18 -61
  41. package/dist/definition/union.d.ts.map +1 -1
  42. package/dist/definition/union.js +8 -69
  43. package/dist/definition/union.js.map +1 -1
  44. package/dist/index.d.ts +5 -3
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +5 -3
  47. package/dist/index.js.map +1 -1
  48. package/dist/resolvers/codec.d.ts +16 -0
  49. package/dist/resolvers/codec.d.ts.map +1 -0
  50. package/dist/resolvers/codec.js +9 -0
  51. package/dist/resolvers/codec.js.map +1 -0
  52. package/dist/resolvers/hooks.d.ts +39 -0
  53. package/dist/resolvers/hooks.d.ts.map +1 -0
  54. package/dist/resolvers/hooks.js +2 -0
  55. package/dist/resolvers/hooks.js.map +1 -0
  56. package/dist/resolvers/index.d.ts +5 -0
  57. package/dist/resolvers/index.d.ts.map +1 -0
  58. package/dist/resolvers/index.js +2 -0
  59. package/dist/resolvers/index.js.map +1 -0
  60. package/dist/resolvers/policy.d.ts +31 -0
  61. package/dist/resolvers/policy.d.ts.map +1 -0
  62. package/dist/resolvers/policy.js +2 -0
  63. package/dist/resolvers/policy.js.map +1 -0
  64. package/dist/resolvers/validator.d.ts +14 -0
  65. package/dist/resolvers/validator.d.ts.map +1 -0
  66. package/dist/resolvers/validator.js +2 -0
  67. package/dist/resolvers/validator.js.map +1 -0
  68. package/dist/runtime/base.d.ts +7 -4
  69. package/dist/runtime/base.d.ts.map +1 -1
  70. package/dist/runtime/base.js.map +1 -1
  71. package/dist/runtime/build.d.ts +22 -0
  72. package/dist/runtime/build.d.ts.map +1 -0
  73. package/dist/runtime/build.js +184 -0
  74. package/dist/runtime/build.js.map +1 -0
  75. package/dist/runtime/column.d.ts +40 -23
  76. package/dist/runtime/column.d.ts.map +1 -1
  77. package/dist/runtime/column.js +120 -28
  78. package/dist/runtime/column.js.map +1 -1
  79. package/dist/runtime/context.d.ts +17 -26
  80. package/dist/runtime/context.d.ts.map +1 -1
  81. package/dist/runtime/context.js +4 -6
  82. package/dist/runtime/context.js.map +1 -1
  83. package/dist/runtime/errors.d.ts +31 -9
  84. package/dist/runtime/errors.d.ts.map +1 -1
  85. package/dist/runtime/errors.js +54 -11
  86. package/dist/runtime/errors.js.map +1 -1
  87. package/dist/runtime/executor.d.ts.map +1 -1
  88. package/dist/runtime/executor.js +10 -1
  89. package/dist/runtime/executor.js.map +1 -1
  90. package/dist/runtime/index.d.ts +10 -6
  91. package/dist/runtime/index.d.ts.map +1 -1
  92. package/dist/runtime/index.js +5 -3
  93. package/dist/runtime/index.js.map +1 -1
  94. package/dist/runtime/operation.d.ts +62 -83
  95. package/dist/runtime/operation.d.ts.map +1 -1
  96. package/dist/runtime/operation.js +194 -260
  97. package/dist/runtime/operation.js.map +1 -1
  98. package/dist/runtime/policy.d.ts +35 -0
  99. package/dist/runtime/policy.d.ts.map +1 -0
  100. package/dist/runtime/policy.js +72 -0
  101. package/dist/runtime/policy.js.map +1 -0
  102. package/dist/runtime/reference.d.ts +87 -0
  103. package/dist/runtime/reference.d.ts.map +1 -0
  104. package/dist/runtime/reference.js +68 -0
  105. package/dist/runtime/reference.js.map +1 -0
  106. package/dist/runtime/registry.d.ts +26 -95
  107. package/dist/runtime/registry.d.ts.map +1 -1
  108. package/dist/runtime/registry.js +29 -408
  109. package/dist/runtime/registry.js.map +1 -1
  110. package/dist/runtime/relation.d.ts +45 -0
  111. package/dist/runtime/relation.d.ts.map +1 -0
  112. package/dist/runtime/relation.js +2 -0
  113. package/dist/runtime/relation.js.map +1 -0
  114. package/dist/runtime/table.d.ts +31 -35
  115. package/dist/runtime/table.d.ts.map +1 -1
  116. package/dist/runtime/table.js +78 -47
  117. package/dist/runtime/table.js.map +1 -1
  118. package/dist/runtime/union.d.ts +11 -4
  119. package/dist/runtime/union.d.ts.map +1 -1
  120. package/dist/runtime/union.js +18 -7
  121. package/dist/runtime/union.js.map +1 -1
  122. package/dist/sql/index.d.ts +2 -2
  123. package/dist/sql/index.d.ts.map +1 -1
  124. package/dist/sql/index.js +1 -1
  125. package/dist/sql/index.js.map +1 -1
  126. package/dist/sql/nodes.d.ts +22 -0
  127. package/dist/sql/nodes.d.ts.map +1 -1
  128. package/dist/sql/nodes.js +21 -0
  129. package/dist/sql/nodes.js.map +1 -1
  130. package/dist/sql/tag.d.ts +3 -15
  131. package/dist/sql/tag.d.ts.map +1 -1
  132. package/dist/sql/tag.js +5 -71
  133. package/dist/sql/tag.js.map +1 -1
  134. package/dist/utils/index.d.ts +1 -1
  135. package/dist/utils/index.d.ts.map +1 -1
  136. package/dist/utils/index.js.map +1 -1
  137. package/dist/utils/types.d.ts +2 -14
  138. package/dist/utils/types.d.ts.map +1 -1
  139. package/dist/utils/types.js.map +1 -1
  140. package/dist/validation/index.d.ts +2 -0
  141. package/dist/validation/index.d.ts.map +1 -0
  142. package/dist/validation/index.js +2 -0
  143. package/dist/validation/index.js.map +1 -0
  144. package/dist/validation/references.d.ts +23 -0
  145. package/dist/validation/references.d.ts.map +1 -0
  146. package/dist/validation/references.js +240 -0
  147. package/dist/validation/references.js.map +1 -0
  148. package/dist/validation/validate.d.ts +40 -0
  149. package/dist/validation/validate.d.ts.map +1 -0
  150. package/dist/validation/validate.js +354 -0
  151. package/dist/validation/validate.js.map +1 -0
  152. package/package.json +13 -4
  153. package/dist/definition/embedded.d.ts +0 -131
  154. package/dist/definition/embedded.d.ts.map +0 -1
  155. package/dist/definition/embedded.js +0 -133
  156. package/dist/definition/embedded.js.map +0 -1
  157. package/dist/definition/tenant.d.ts +0 -50
  158. package/dist/definition/tenant.d.ts.map +0 -1
  159. package/dist/definition/tenant.js +0 -73
  160. package/dist/definition/tenant.js.map +0 -1
  161. package/dist/runtime/group.d.ts +0 -54
  162. package/dist/runtime/group.d.ts.map +0 -1
  163. package/dist/runtime/group.js +0 -96
  164. package/dist/runtime/group.js.map +0 -1
@@ -1,82 +1,21 @@
1
1
  import { DefinitionNode, Kind } from "./base.js";
2
- import { ColumnGroupDefinition } from "./embedded.js";
3
- import { TableDefinition } from "./table.js";
4
- /**
5
- * A field every member of a union shares, addressed on the union rather than on one member —
6
- * `posts.columns.userId` in `hasMany(posts, { to: [posts.columns.userId] })`.
7
- *
8
- * It names a field, not a database column: members may store the same field under different
9
- * column names, so `name` is the field alias and `members` holds the real column per member.
10
- * Typed as the first member's column, which is what every member agrees on.
11
- */
12
- export class UnionColumnDefinition extends DefinitionNode {
13
- kind = Kind.UNION_COLUMN;
14
- members;
15
- constructor(field, members) {
16
- super(field);
17
- this.members = Object.freeze({ ...members });
18
- }
19
- }
20
2
  /**
21
3
  * A set of tables that can stand in for one another — a GraphQL union or interface.
22
4
  *
23
5
  * Each member is keyed by its schema alias, which the registry checks when the client is
24
- * built, because only there are aliases known. A union is not a table and produces no DDL:
25
- * relations target it, and the client reads it as one `UNION ALL` over its members.
6
+ * built, because only there are aliases known. The fields that work across the union — in a
7
+ * relation's `to`, and in shared `select` / `where` / `orderBy` — are the ones it declares. A
8
+ * union is not a table and produces no DDL: relations target it, and the client reads it as one
9
+ * `UNION ALL` over its members.
26
10
  */
27
11
  export class UnionDefinition extends DefinitionNode {
28
12
  kind = Kind.UNION;
29
13
  members;
30
- /** The shared fields — see {@link SharedFieldsOf}. */
31
14
  columns;
32
- constructor(members) {
33
- const aliases = Object.keys(members);
34
- // A union has no name of its own until the registry reads the key it is exported under;
35
- // this one exists for error messages raised before then.
36
- super(`union(${aliases.join("|")})`);
37
- if (aliases.length === 0) {
38
- throw new Error(`A union must have at least one member.`);
39
- }
40
- for (const [alias, member] of Object.entries(members)) {
41
- if (!(member instanceof TableDefinition)) {
42
- throw new Error(`Union member "${alias}" is not a table. Members are tables; a union cannot contain ` +
43
- `another union.`);
44
- }
45
- }
46
- this.members = Object.freeze({ ...members });
47
- this.columns = this._buildColumns();
48
- }
49
- /**
50
- * The fields present on every member with the same `dataType`. A field whose type differs
51
- * on one member is dropped rather than refused: it is still usable per member through `on`,
52
- * just not across the union.
53
- */
54
- _buildColumns() {
55
- const [first, ...rest] = Object.entries(this.members);
56
- const columns = {};
57
- for (const [field, column] of Object.entries(first[1].columns)) {
58
- // A column group is not shared across a union: the union members are due a restructure,
59
- // and a group's sharing rule waits for it.
60
- if (column instanceof ColumnGroupDefinition) {
61
- continue;
62
- }
63
- const members = { [first[0]]: column };
64
- let shared = true;
65
- for (const [alias, member] of rest) {
66
- const candidate = member.columns[field];
67
- if (!candidate ||
68
- candidate instanceof ColumnGroupDefinition ||
69
- candidate["_dataType"] !== column["_dataType"]) {
70
- shared = false;
71
- break;
72
- }
73
- members[alias] = candidate;
74
- }
75
- if (shared) {
76
- columns[field] = new UnionColumnDefinition(field, members);
77
- }
78
- }
79
- return Object.freeze(columns);
15
+ constructor(name, config) {
16
+ super(name);
17
+ this.members = Object.freeze({ ...config.members });
18
+ this.columns = Object.freeze({ ...config.columns });
80
19
  }
81
20
  toJSON() {
82
21
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"union.js","sourceRoot":"","sources":["../../src/definition/union.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAsB,eAAe,EAAE,MAAM,YAAY,CAAC;AAuCjE;;;;;;;GAOG;AACH,MAAM,OAAO,qBAGX,SAAQ,cAAyC;IACxC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC;IAEzB,OAAO,CAAgD;IAEhE,YAAY,KAAa,EAAE,OAA4C;QACrE,KAAK,CAAC,KAAK,CAAC,CAAC;QAEb,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC/C,CAAC;CACF;AAeD;;;;;;GAMG;AACH,MAAM,OAAO,eAEX,SAAQ,cAA6C;IAC5C,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;IAElB,OAAO,CAAqB;IAErC,sDAAsD;IAC7C,OAAO,CAAyB;IAEzC,YAAY,OAAiB;QAC3B,MAAM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AAI,CAAC;YAElB,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;gBACnC,MAAM,SAAS,GAAI,MAAM,CAAC,OAA+C,CAAC,KAAK,CAAC,CAAC;gBAEjF,IACE,CAAC,SAAS;oBACT,SAAqB,YAAY,qBAAqB;oBACvD,SAAS,CAAC,WAAW,CAAC,KAAK,MAAM,CAAC,WAAW,CAAC,EAC9C,CAAC;oBACD,MAAM,GAAG,KAAK,CAAC;oBACf,MAAM;gBACR,CAAC;gBAED,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;YAC7B,CAAC;YAED,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAEM,MAAM;QACX,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAC5E;SACO,CAAC;IACb,CAAC;CACF","sourcesContent":["import { DefinitionNode, Kind } from \"./base.js\";\nimport { AnyColumnDefinition } from \"./column.js\";\nimport { ColumnGroupDefinition } from \"./embedded.js\";\nimport { AnyTableDefinition, TableDefinition } from \"./table.js\";\n\nexport type AnyUnionMembers = Record<string, AnyTableDefinition>;\n\n/** A member's plain columns. A column group is not shared across a union (yet). */\ntype PlainColumnsOf<TColumns> = {\n [K in keyof TColumns as TColumns[K] extends AnyColumnDefinition ? K : never]: TColumns[K];\n};\n\ntype MemberColumnsOf<TMembers extends AnyUnionMembers> = {\n [A in keyof TMembers]: PlainColumnsOf<TMembers[A][\"__type\"][\"columns\"]>;\n}[keyof TMembers];\n\ntype MemberValueOf<TColumn> = TColumn extends { __type: { valueType: infer V } } ? V : never;\n\ntype ValueUnionOf<TMembers extends AnyUnionMembers, K extends PropertyKey> = {\n [A in keyof TMembers]: MemberValueOf<TMembers[A][\"__type\"][\"columns\"][K]>;\n}[keyof TMembers];\n\n/**\n * The fields every member of a union declares with the same value type.\n *\n * `keyof` over a union of column maps is already the intersection of their keys; a key then\n * survives only when no member's value type is narrower than the union of all of them. The\n * database type cannot be compared here — `dataType` is a runtime string on every column — so\n * the registry repeats the check against it when the client is built.\n */\nexport type SharedFieldsOf<TMembers extends AnyUnionMembers> = {\n [K in keyof MemberColumnsOf<TMembers> & string]: {\n [A in keyof TMembers]: [ValueUnionOf<TMembers, K>] extends [\n MemberValueOf<TMembers[A][\"__type\"][\"columns\"][K]>,\n ]\n ? never\n : A;\n }[keyof TMembers] extends never\n ? K\n : never;\n}[keyof MemberColumnsOf<TMembers> & string];\n\n/**\n * A field every member of a union shares, addressed on the union rather than on one member —\n * `posts.columns.userId` in `hasMany(posts, { to: [posts.columns.userId] })`.\n *\n * It names a field, not a database column: members may store the same field under different\n * column names, so `name` is the field alias and `members` holds the real column per member.\n * Typed as the first member's column, which is what every member agrees on.\n */\nexport class UnionColumnDefinition<\n TField extends string = string,\n TColumn extends AnyColumnDefinition = AnyColumnDefinition,\n> extends DefinitionNode<TField, TColumn[\"__type\"]> {\n readonly kind = Kind.UNION_COLUMN;\n\n readonly members: Readonly<Record<string, AnyColumnDefinition>>;\n\n constructor(field: TField, members: Record<string, AnyColumnDefinition>) {\n super(field);\n\n this.members = Object.freeze({ ...members });\n }\n}\n\nexport type AnyUnionColumnDefinition = UnionColumnDefinition<string, AnyColumnDefinition>;\n\nexport type UnionColumns<TMembers extends AnyUnionMembers> = {\n readonly [K in SharedFieldsOf<TMembers>]: UnionColumnDefinition<\n K,\n TMembers[keyof TMembers][\"__type\"][\"columns\"][K]\n >;\n};\n\nexport type UnionConfig<TMembers extends AnyUnionMembers> = {\n members: TMembers;\n};\n\n/**\n * A set of tables that can stand in for one another — a GraphQL union or interface.\n *\n * Each member is keyed by its schema alias, which the registry checks when the client is\n * built, because only there are aliases known. A union is not a table and produces no DDL:\n * relations target it, and the client reads it as one `UNION ALL` over its members.\n */\nexport class UnionDefinition<\n TMembers extends AnyUnionMembers = AnyUnionMembers,\n> extends DefinitionNode<string, UnionConfig<TMembers>> {\n readonly kind = Kind.UNION;\n\n readonly members: Readonly<TMembers>;\n\n /** The shared fields — see {@link SharedFieldsOf}. */\n readonly columns: UnionColumns<TMembers>;\n\n constructor(members: TMembers) {\n const aliases = Object.keys(members);\n\n // A union has no name of its own until the registry reads the key it is exported under;\n // this one exists for error messages raised before then.\n super(`union(${aliases.join(\"|\")})`);\n\n if (aliases.length === 0) {\n throw new Error(`A union must have at least one member.`);\n }\n\n for (const [alias, member] of Object.entries(members)) {\n if (!((member as unknown) instanceof TableDefinition)) {\n throw new Error(\n `Union member \"${alias}\" is not a table. Members are tables; a union cannot contain ` +\n `another union.`\n );\n }\n }\n\n this.members = Object.freeze({ ...members });\n this.columns = this._buildColumns() as UnionColumns<TMembers>;\n }\n\n /**\n * The fields present on every member with the same `dataType`. A field whose type differs\n * on one member is dropped rather than refused: it is still usable per member through `on`,\n * just not across the union.\n */\n private _buildColumns(): Record<string, AnyUnionColumnDefinition> {\n const [first, ...rest] = Object.entries(this.members);\n const columns: Record<string, AnyUnionColumnDefinition> = {};\n\n for (const [field, column] of Object.entries<AnyColumnDefinition>(first[1].columns)) {\n // A column group is not shared across a union: the union members are due a restructure,\n // and a group's sharing rule waits for it.\n if ((column as unknown) instanceof ColumnGroupDefinition) {\n continue;\n }\n\n const members: Record<string, AnyColumnDefinition> = { [first[0]]: column };\n let shared = true;\n\n for (const [alias, member] of rest) {\n const candidate = (member.columns as Record<string, AnyColumnDefinition>)[field];\n\n if (\n !candidate ||\n (candidate as unknown) instanceof ColumnGroupDefinition ||\n candidate[\"_dataType\"] !== column[\"_dataType\"]\n ) {\n shared = false;\n break;\n }\n\n members[alias] = candidate;\n }\n\n if (shared) {\n columns[field] = new UnionColumnDefinition(field, members);\n }\n }\n\n return Object.freeze(columns);\n }\n\n public toJSON() {\n return {\n kind: this.kind,\n name: this.name,\n members: Object.fromEntries(\n Object.entries(this.members).map(([alias, member]) => [alias, member.name])\n ),\n } as const;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyUnionDefinition = UnionDefinition<any>;\n"]}
1
+ {"version":3,"file":"union.js","sourceRoot":"","sources":["../../src/definition/union.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AA4BjD;;;;;;;;GAQG;AACH,MAAM,OAAO,eAIX,SAAQ,cAAsD;IACrD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;IAElB,OAAO,CAAqB;IAC5B,OAAO,CAAqB;IAErC,YAAY,IAAW,EAAE,MAAuC;QAC9D,KAAK,CAAC,IAAI,CAAC,CAAC;QAEZ,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;IAEM,MAAM;QACX,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAC5E;SACO,CAAC;IACb,CAAC;CACF","sourcesContent":["import { DefinitionNode, Kind } from \"./base.js\";\nimport { AnyColumnDefinition } from \"./column.js\";\nimport { AnyTableDefinition } from \"./table.js\";\n\nexport type AnyUnionMembers = Record<string, AnyTableDefinition>;\n\n/**\n * The fields every member of a union declares — `keyof` over a union of column maps is the\n * intersection of their keys. A union's declared columns are drawn from these.\n */\nexport type CommonFieldsOf<TMembers extends AnyUnionMembers> = keyof {\n [A in keyof TMembers]: TMembers[A][\"__type\"][\"columns\"];\n}[keyof TMembers] &\n string;\n\n/** What `union()` declares: shared field → the column every member stores it in. */\nexport type UnionColumnsConfig<TMembers extends AnyUnionMembers> = Partial<\n Record<CommonFieldsOf<TMembers>, AnyColumnDefinition>\n>;\n\nexport type UnionConfig<\n TMembers extends AnyUnionMembers,\n TColumns extends UnionColumnsConfig<TMembers>,\n> = {\n members: TMembers;\n columns: TColumns;\n};\n\n/**\n * A set of tables that can stand in for one another — a GraphQL union or interface.\n *\n * Each member is keyed by its schema alias, which the registry checks when the client is\n * built, because only there are aliases known. The fields that work across the union — in a\n * relation's `to`, and in shared `select` / `where` / `orderBy` — are the ones it declares. A\n * union is not a table and produces no DDL: relations target it, and the client reads it as one\n * `UNION ALL` over its members.\n */\nexport class UnionDefinition<\n TName extends string,\n TMembers extends AnyUnionMembers,\n TColumns extends UnionColumnsConfig<TMembers>,\n> extends DefinitionNode<TName, UnionConfig<TMembers, TColumns>> {\n readonly kind = Kind.UNION;\n\n readonly members: Readonly<TMembers>;\n readonly columns: Readonly<TColumns>;\n\n constructor(name: TName, config: UnionConfig<TMembers, TColumns>) {\n super(name);\n\n this.members = Object.freeze({ ...config.members });\n this.columns = Object.freeze({ ...config.columns });\n }\n\n public toJSON() {\n return {\n kind: this.kind,\n name: this.name,\n members: Object.fromEntries(\n Object.entries(this.members).map(([alias, member]) => [alias, member.name])\n ),\n } as const;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyUnionDefinition = UnionDefinition<any, any, any>;\n"]}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export { Kind, Relation, defaultCodec, ColumnDefinition, DomainDefinition, IndexDefinition, NamespaceDefinition, SequenceDefinition, TableDefinition, TenantScopeDefinition, ViewDefinition, RelationsDefinition, UnionDefinition, UnionColumnDefinition, EmbeddedObjectDefinition, ColumnGroupDefinition, DefinitionNode, type AnyColumnDefinition, type AnyColumnGroupDefinition, type AnyTableColumnDefinition, type TableColumnDefinitions, type AnyDomainDefinition, type AnyFieldRelation, type AnyIndexDefinition, type AnyNamespaceDefinition, type AnyRelationDefinition, type AnyTableDefinition, type AnyTableRelations, type AnyTenantScopeDefinition, type AnyRelationTarget, type AnyUnionDefinition, type AnyUnionMembers, type SharedFieldsOf, type ColumnCodec, type ColumnValidator, type ColumnConfig, type ColumnRuntimeType, type DefinitionSchema, type DomainConfig, type FieldRelation, type IndexConfig, type NodeKind, type RelationsConfig, type RelationType, type TableConfig, type TenantClaimColumns, type TypeArgOf, type UpdateGuard, } from "./definition/index.js";
2
- export { Column, ColumnGroup, CompositeQuery, ExecutionContext, ExecutableQuery, OperationsFactory, QueryBuilder, SchemaRegistry, Table, TenancyError, Union, UnionResolver, type AnyColumn, type AnyColumnGroup, type AnyField, type GroupReader, type GroupSelection, type ColumnRowDecoder, type AnySchema, type AnyTable, type AnyUnion, type CountOperation, type CountOperationArgs, type DefinitionRelationsTableName, type DefinitionTableName, type DefinitionTableRelations, type DeleteOperation, type DeleteOperationArgs, type DeleteParams, type Executable, type ExecutionContextOptions, type FieldMutation, type FieldRelationConfig, type FieldResolver, type FieldSelection, type InsertOperation, type InsertOperationArgs, type InsertParams, type JoinParams, type Operation, type OperationMode, type OperationRequest, type OperationResult, type OperationType, type PaginationOptions, type RuntimeTables, type Schema, type SchemaRelationDefinitions, type SchemaTableDefinitions, type SchemaTableRelations, type SchemaUnionDefinitions, type DefinitionUnionName, type SelectOperation, type SelectOperationArgs, type SelectParams, type Session, type TableByNameOrAlias, type TableRelationFieldName, type TenancyOptions, type TransactionSession, type UpdateOperation, type UpdateOperationArgs, type UnionOrderKey, type UnionSelectOperationArgs, type UnionSelectOperation, type UnionCountOperationArgs, type TableJoinParams, type UnionBranchParams, type UnionJoinParams, type UnionSelectParams, type UpdateParams, } from "./runtime/index.js";
3
- export { sql, isSQLNode, SQLQuery, SQLParam, SQLRaw, SQLIdentifier, SQLWrapper, type SQLNode, type SQLStatement, type SQLContext, type SQLValue, type KeysetKey, type KeysetBound, } from "./sql/index.js";
1
+ export { Kind, Relation, ColumnDefinition, DomainDefinition, IndexDefinition, NamespaceDefinition, SequenceDefinition, TableDefinition, ViewDefinition, RelationsDefinition, UnionDefinition, DefinitionNode, type AnyColumnDefinition, type AnyDomainDefinition, type AnyFieldRelation, type AnyIndexDefinition, type AnyNamespaceDefinition, type AnyRelationDefinition, type AnyTableDefinition, type AnyTableRelations, type AnyUnionDefinition, type AnyUnionMembers, type CommonFieldsOf, type UnionColumnsConfig, type ColumnConfig, type ColumnRuntimeType, type DefinitionSchema, type DomainConfig, type FieldRelation, type IndexConfig, type NodeKind, type RelationsConfig, type RelationType, type TableConfig, type TypeArgOf, type UpdateGuard, } from "./definition/index.js";
2
+ export { buildSchema, resolvePolicy, Column, CompositeQuery, ComputedDiscriminator, ExecutionContext, ExecutableQuery, OperationsFactory, QueryBuilder, SchemaRegistry, Policy, PolicyViolationError, Table, Union, UnionResolver, type AnyColumn, type AnyOperation, type AnyPolicy, type AnySchema, type AnyTable, type AnyUnion, type BuiltSchema, type ColumnReference, type CountOperation, type CountOperationArgs, type DefinitionRelationsTableName, type DefinitionTableName, type DefinitionTableRelations, type DefinitionUnionName, type DeleteOperation, type DeleteOperationArgs, type DeleteParams, type Executable, type ExecutionContextOptions, type FieldMutation, type FieldRelationConfig, type FieldResolver, type FieldResolverEntry, type FieldSelection, type InsertOperation, type InsertOperationArgs, type InsertParams, type JoinParams, type Operation, type OperationMode, type OperationRequest, type OperationResult, type OperationType, type OrderByEntry, type ReferenceEnd, type RelationSelection, type ResolvedReferences, type RuntimePolicyConfig, type RuntimeRelation, type RuntimeTables, type RuntimeUnions, type Schema, type SchemaRelationDefinitions, type SchemaTableDefinitions, type SchemaTableRelations, type SchemaUnionDefinitions, type SelectOperation, type SelectOperationArgs, type SelectParams, type Session, type TableByAlias, type TableByName, type TableByNameOrAlias, type TableJoinParams, type TableReference, type TableRelation, type TableRelationFieldName, type TransactionSession, type UnionBranchParams, type UnionCountOperationArgs, type UnionJoinParams, type UnionReference, type UnionRelation, type UnionSelectOperation, type UnionSelectOperationArgs, type UnionSelectParams, type UpdateOperation, type UpdateOperationArgs, type UpdateParams, } from "./runtime/index.js";
3
+ export { sql, isSQLNode, counter, escapeIdentifier, escapeValue, SQLQuery, SQLParam, SQLRaw, SQLIdentifier, SQLWrapper, SQLClaim, SQLScope, type ParamIndexCounter, type ValueSerializer, type SQLNode, type SQLStatement, type SQLContext, type SQLValue, } from "./sql/index.js";
4
+ export { defaultCodec, type ColumnCodec, type ColumnValidator, type ColumnHooks, type PolicyCommand, type PolicyConfig, type PolicyFor, type PolicyExpressionResolver, type ColumnHookContext, } from "./resolvers/index.js";
5
+ export { validateSchema, collectRelations, findColumnAlias, memberToColumns, type SourcedRelation, } from "./validation/index.js";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAA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
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
- export { Kind, Relation, defaultCodec, ColumnDefinition, DomainDefinition, IndexDefinition, NamespaceDefinition, SequenceDefinition, TableDefinition, TenantScopeDefinition, ViewDefinition, RelationsDefinition, UnionDefinition, UnionColumnDefinition, EmbeddedObjectDefinition, ColumnGroupDefinition, DefinitionNode, } from "./definition/index.js";
2
- export { Column, ColumnGroup, CompositeQuery, ExecutionContext, ExecutableQuery, OperationsFactory, QueryBuilder, SchemaRegistry, Table, TenancyError, Union, UnionResolver, } from "./runtime/index.js";
3
- export { sql, isSQLNode, SQLQuery, SQLParam, SQLRaw, SQLIdentifier, SQLWrapper, } from "./sql/index.js";
1
+ export { Kind, Relation, ColumnDefinition, DomainDefinition, IndexDefinition, NamespaceDefinition, SequenceDefinition, TableDefinition, ViewDefinition, RelationsDefinition, UnionDefinition, DefinitionNode, } from "./definition/index.js";
2
+ export { buildSchema, resolvePolicy, Column, CompositeQuery, ComputedDiscriminator, ExecutionContext, ExecutableQuery, OperationsFactory, QueryBuilder, SchemaRegistry, Policy, PolicyViolationError, Table, Union, UnionResolver, } from "./runtime/index.js";
3
+ export { sql, isSQLNode, counter, escapeIdentifier, escapeValue, SQLQuery, SQLParam, SQLRaw, SQLIdentifier, SQLWrapper, SQLClaim, SQLScope, } from "./sql/index.js";
4
+ export { defaultCodec, } from "./resolvers/index.js";
5
+ export { validateSchema, collectRelations, findColumnAlias, memberToColumns, } from "./validation/index.js";
4
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,cAAc,GAgCf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,MAAM,EACN,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,KAAK,EACL,YAAY,EACZ,KAAK,EACL,aAAa,GA4Dd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,GAAG,EACH,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,aAAa,EACb,UAAU,GAOX,MAAM,gBAAgB,CAAC","sourcesContent":["export {\n Kind,\n Relation,\n defaultCodec,\n ColumnDefinition,\n DomainDefinition,\n IndexDefinition,\n NamespaceDefinition,\n SequenceDefinition,\n TableDefinition,\n TenantScopeDefinition,\n ViewDefinition,\n RelationsDefinition,\n UnionDefinition,\n UnionColumnDefinition,\n EmbeddedObjectDefinition,\n ColumnGroupDefinition,\n DefinitionNode,\n type AnyColumnDefinition,\n type AnyColumnGroupDefinition,\n type AnyTableColumnDefinition,\n type TableColumnDefinitions,\n type AnyDomainDefinition,\n type AnyFieldRelation,\n type AnyIndexDefinition,\n type AnyNamespaceDefinition,\n type AnyRelationDefinition,\n type AnyTableDefinition,\n type AnyTableRelations,\n type AnyTenantScopeDefinition,\n type AnyRelationTarget,\n type AnyUnionDefinition,\n type AnyUnionMembers,\n type SharedFieldsOf,\n type ColumnCodec,\n type ColumnValidator,\n type ColumnConfig,\n type ColumnRuntimeType,\n type DefinitionSchema,\n type DomainConfig,\n type FieldRelation,\n type IndexConfig,\n type NodeKind,\n type RelationsConfig,\n type RelationType,\n type TableConfig,\n type TenantClaimColumns,\n type TypeArgOf,\n type UpdateGuard,\n} from \"./definition/index.js\";\nexport {\n Column,\n ColumnGroup,\n CompositeQuery,\n ExecutionContext,\n ExecutableQuery,\n OperationsFactory,\n QueryBuilder,\n SchemaRegistry,\n Table,\n TenancyError,\n Union,\n UnionResolver,\n type AnyColumn,\n type AnyColumnGroup,\n type AnyField,\n type GroupReader,\n type GroupSelection,\n type ColumnRowDecoder,\n type AnySchema,\n type AnyTable,\n type AnyUnion,\n type CountOperation,\n type CountOperationArgs,\n type DefinitionRelationsTableName,\n type DefinitionTableName,\n type DefinitionTableRelations,\n type DeleteOperation,\n type DeleteOperationArgs,\n type DeleteParams,\n type Executable,\n type ExecutionContextOptions,\n type FieldMutation,\n type FieldRelationConfig,\n type FieldResolver,\n type FieldSelection,\n type InsertOperation,\n type InsertOperationArgs,\n type InsertParams,\n type JoinParams,\n type Operation,\n type OperationMode,\n type OperationRequest,\n type OperationResult,\n type OperationType,\n type PaginationOptions,\n type RuntimeTables,\n type Schema,\n type SchemaRelationDefinitions,\n type SchemaTableDefinitions,\n type SchemaTableRelations,\n type SchemaUnionDefinitions,\n type DefinitionUnionName,\n type SelectOperation,\n type SelectOperationArgs,\n type SelectParams,\n type Session,\n type TableByNameOrAlias,\n type TableRelationFieldName,\n type TenancyOptions,\n type TransactionSession,\n type UpdateOperation,\n type UpdateOperationArgs,\n type UnionOrderKey,\n type UnionSelectOperationArgs,\n type UnionSelectOperation,\n type UnionCountOperationArgs,\n type TableJoinParams,\n type UnionBranchParams,\n type UnionJoinParams,\n type UnionSelectParams,\n type UpdateParams,\n} from \"./runtime/index.js\";\nexport {\n sql,\n isSQLNode,\n SQLQuery,\n SQLParam,\n SQLRaw,\n SQLIdentifier,\n SQLWrapper,\n type SQLNode,\n type SQLStatement,\n type SQLContext,\n type SQLValue,\n type KeysetKey,\n type KeysetBound,\n} from \"./sql/index.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,cAAc,GAyBf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,WAAW,EACX,aAAa,EACb,MAAM,EACN,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,MAAM,EACN,oBAAoB,EACpB,KAAK,EACL,KAAK,EACL,aAAa,GAsEd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,GAAG,EACH,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,aAAa,EACb,UAAU,EACV,QAAQ,EACR,QAAQ,GAOT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,YAAY,GASb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,eAAe,GAEhB,MAAM,uBAAuB,CAAC","sourcesContent":["export {\n Kind,\n Relation,\n ColumnDefinition,\n DomainDefinition,\n IndexDefinition,\n NamespaceDefinition,\n SequenceDefinition,\n TableDefinition,\n ViewDefinition,\n RelationsDefinition,\n UnionDefinition,\n DefinitionNode,\n type AnyColumnDefinition,\n type AnyDomainDefinition,\n type AnyFieldRelation,\n type AnyIndexDefinition,\n type AnyNamespaceDefinition,\n type AnyRelationDefinition,\n type AnyTableDefinition,\n type AnyTableRelations,\n type AnyUnionDefinition,\n type AnyUnionMembers,\n type CommonFieldsOf,\n type UnionColumnsConfig,\n type ColumnConfig,\n type ColumnRuntimeType,\n type DefinitionSchema,\n type DomainConfig,\n type FieldRelation,\n type IndexConfig,\n type NodeKind,\n type RelationsConfig,\n type RelationType,\n type TableConfig,\n type TypeArgOf,\n type UpdateGuard,\n} from \"./definition/index.js\";\nexport {\n buildSchema,\n resolvePolicy,\n Column,\n CompositeQuery,\n ComputedDiscriminator,\n ExecutionContext,\n ExecutableQuery,\n OperationsFactory,\n QueryBuilder,\n SchemaRegistry,\n Policy,\n PolicyViolationError,\n Table,\n Union,\n UnionResolver,\n type AnyColumn,\n type AnyOperation,\n type AnyPolicy,\n type AnySchema,\n type AnyTable,\n type AnyUnion,\n type BuiltSchema,\n type ColumnReference,\n type CountOperation,\n type CountOperationArgs,\n type DefinitionRelationsTableName,\n type DefinitionTableName,\n type DefinitionTableRelations,\n type DefinitionUnionName,\n type DeleteOperation,\n type DeleteOperationArgs,\n type DeleteParams,\n type Executable,\n type ExecutionContextOptions,\n type FieldMutation,\n type FieldRelationConfig,\n type FieldResolver,\n type FieldResolverEntry,\n type FieldSelection,\n type InsertOperation,\n type InsertOperationArgs,\n type InsertParams,\n type JoinParams,\n type Operation,\n type OperationMode,\n type OperationRequest,\n type OperationResult,\n type OperationType,\n type OrderByEntry,\n type ReferenceEnd,\n type RelationSelection,\n type ResolvedReferences,\n type RuntimePolicyConfig,\n type RuntimeRelation,\n type RuntimeTables,\n type RuntimeUnions,\n type Schema,\n type SchemaRelationDefinitions,\n type SchemaTableDefinitions,\n type SchemaTableRelations,\n type SchemaUnionDefinitions,\n type SelectOperation,\n type SelectOperationArgs,\n type SelectParams,\n type Session,\n type TableByAlias,\n type TableByName,\n type TableByNameOrAlias,\n type TableJoinParams,\n type TableReference,\n type TableRelation,\n type TableRelationFieldName,\n type TransactionSession,\n type UnionBranchParams,\n type UnionCountOperationArgs,\n type UnionJoinParams,\n type UnionReference,\n type UnionRelation,\n type UnionSelectOperation,\n type UnionSelectOperationArgs,\n type UnionSelectParams,\n type UpdateOperation,\n type UpdateOperationArgs,\n type UpdateParams,\n} from \"./runtime/index.js\";\nexport {\n sql,\n isSQLNode,\n counter,\n escapeIdentifier,\n escapeValue,\n SQLQuery,\n SQLParam,\n SQLRaw,\n SQLIdentifier,\n SQLWrapper,\n SQLClaim,\n SQLScope,\n type ParamIndexCounter,\n type ValueSerializer,\n type SQLNode,\n type SQLStatement,\n type SQLContext,\n type SQLValue,\n} from \"./sql/index.js\";\nexport {\n defaultCodec,\n type ColumnCodec,\n type ColumnValidator,\n type ColumnHooks,\n type PolicyCommand,\n type PolicyConfig,\n type PolicyFor,\n type PolicyExpressionResolver,\n type ColumnHookContext,\n} from \"./resolvers/index.js\";\nexport {\n validateSchema,\n collectRelations,\n findColumnAlias,\n memberToColumns,\n type SourcedRelation,\n} from \"./validation/index.js\";\n"]}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts a column's values to and from what the driver sends and returns. A codec translates
3
+ * and nothing else: every value bound for the column passes through `encode` — writes, filters,
4
+ * `Column.param`, a definition's `.default()` — so a codec that refused values would refuse
5
+ * filters too. Checking a value is `ColumnValidator`'s job.
6
+ *
7
+ * A codec is pure: it sees one value and nothing else, which is why a definition can run it
8
+ * for a DDL default. A transform that needs the column or the row it was read from is a
9
+ * {@link ColumnHooks} instead.
10
+ */
11
+ export type ColumnCodec<TRaw, TValue> = {
12
+ encode(value: TValue): TRaw;
13
+ decode(raw: TRaw): TValue;
14
+ };
15
+ export declare const defaultCodec: ColumnCodec<unknown, unknown>;
16
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/resolvers/codec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI;IACtC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,CAAC,GAAG,EAAE,IAAI,GAAG,MAAM,CAAC;CAC3B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,CAOtD,CAAC"}
@@ -0,0 +1,9 @@
1
+ export const defaultCodec = {
2
+ encode(value) {
3
+ return value;
4
+ },
5
+ decode(raw) {
6
+ return raw;
7
+ },
8
+ };
9
+ //# sourceMappingURL=codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/resolvers/codec.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,YAAY,GAAkC;IACzD,MAAM,CAAC,KAAK;QACV,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,CAAC,GAAG;QACR,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC","sourcesContent":["/**\n * Converts a column's values to and from what the driver sends and returns. A codec translates\n * and nothing else: every value bound for the column passes through `encode` — writes, filters,\n * `Column.param`, a definition's `.default()` — so a codec that refused values would refuse\n * filters too. Checking a value is `ColumnValidator`'s job.\n *\n * A codec is pure: it sees one value and nothing else, which is why a definition can run it\n * for a DDL default. A transform that needs the column or the row it was read from is a\n * {@link ColumnHooks} instead.\n */\nexport type ColumnCodec<TRaw, TValue> = {\n encode(value: TValue): TRaw;\n decode(raw: TRaw): TValue;\n};\n\nexport const defaultCodec: ColumnCodec<unknown, unknown> = {\n encode(value) {\n return value;\n },\n decode(raw) {\n return raw;\n },\n};\n"]}
@@ -0,0 +1,39 @@
1
+ import type { AnyColumn } from "../runtime/column.js";
2
+ /** What a {@link ColumnHooks} method is called with, besides the value. */
3
+ export type ColumnHookContext = {
4
+ /** The runtime column the value belongs to, its references already linked. */
5
+ readonly column: AnyColumn;
6
+ /**
7
+ * On a read: the raw row the value came from, keyed by column name — the root row, a joined
8
+ * level, or a union branch. It carries the column's `dependsOn`, which core projects with it.
9
+ * Absent on a write or a filter.
10
+ */
11
+ readonly row?: Readonly<Record<string, unknown>>;
12
+ };
13
+ /**
14
+ * Transforms around a column's codec that need more than the value: the runtime column — its
15
+ * table, its references — and, on a read, the row. Declared on a definition, run only by the
16
+ * runtime `Column`, so never for a definition's `.default()`: a DDL default has no runtime
17
+ * column.
18
+ *
19
+ * | Path | Order |
20
+ * |---|---|
21
+ * | insert, update, `$onCreate`, `$onUpdate` | `validator.write` → `write` → `codec.encode` |
22
+ * | filters (`Column.param`) | `write` → `codec.encode` |
23
+ * | reads, root and joined (`Column.resolve`) | `codec.decode` → `read` → `validator.read` |
24
+ *
25
+ * Both sides of a relation pair must carry the same hooks object, and a column with hooks must
26
+ * reference one target: `validateSchema` refuses otherwise, since the value read through the
27
+ * column depends on what it references.
28
+ */
29
+ export type ColumnHooks<TValue> = {
30
+ /** A value used in a filter, before it is encoded. */
31
+ filter?(value: TValue, context: ColumnHookContext): TValue;
32
+ /** A value decoded from the row, as the client returns it. `NULL` never reaches it. */
33
+ read?(value: TValue, context: ColumnHookContext): TValue;
34
+ /** A value bound for the column — a write or a filter — before it is encoded. */
35
+ write?(value: TValue, context: ColumnHookContext): TValue;
36
+ /** A value for the dependency columns, before it is encoded. When the value can be resoved from input or other sources, this hook allows transforming it accordingly.*/
37
+ writeDeps?(value: TValue, context: ColumnHookContext): TValue | null;
38
+ };
39
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/resolvers/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,2EAA2E;AAC3E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClD,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI;IAChC,sDAAsD;IACtD,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAAC;IAC3D,uFAAuF;IACvF,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAAC;IACzD,iFAAiF;IACjF,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAAC;IAC1D,wKAAwK;IACxK,SAAS,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAAC;CACtE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/resolvers/hooks.ts"],"names":[],"mappings":"","sourcesContent":["import type { AnyColumn } from \"../runtime/column.js\";\n\n/** What a {@link ColumnHooks} method is called with, besides the value. */\nexport type ColumnHookContext = {\n /** The runtime column the value belongs to, its references already linked. */\n readonly column: AnyColumn;\n /**\n * On a read: the raw row the value came from, keyed by column name — the root row, a joined\n * level, or a union branch. It carries the column's `dependsOn`, which core projects with it.\n * Absent on a write or a filter.\n */\n readonly row?: Readonly<Record<string, unknown>>;\n};\n\n/**\n * Transforms around a column's codec that need more than the value: the runtime column — its\n * table, its references — and, on a read, the row. Declared on a definition, run only by the\n * runtime `Column`, so never for a definition's `.default()`: a DDL default has no runtime\n * column.\n *\n * | Path | Order |\n * |---|---|\n * | insert, update, `$onCreate`, `$onUpdate` | `validator.write` → `write` → `codec.encode` |\n * | filters (`Column.param`) | `write` → `codec.encode` |\n * | reads, root and joined (`Column.resolve`) | `codec.decode` → `read` → `validator.read` |\n *\n * Both sides of a relation pair must carry the same hooks object, and a column with hooks must\n * reference one target: `validateSchema` refuses otherwise, since the value read through the\n * column depends on what it references.\n */\nexport type ColumnHooks<TValue> = {\n /** A value used in a filter, before it is encoded. */\n filter?(value: TValue, context: ColumnHookContext): TValue;\n /** A value decoded from the row, as the client returns it. `NULL` never reaches it. */\n read?(value: TValue, context: ColumnHookContext): TValue;\n /** A value bound for the column — a write or a filter — before it is encoded. */\n write?(value: TValue, context: ColumnHookContext): TValue;\n /** A value for the dependency columns, before it is encoded. When the value can be resoved from input or other sources, this hook allows transforming it accordingly.*/\n writeDeps?(value: TValue, context: ColumnHookContext): TValue | null;\n};\n"]}
@@ -0,0 +1,5 @@
1
+ export { defaultCodec, type ColumnCodec } from "./codec.js";
2
+ export { type ColumnValidator } from "./validator.js";
3
+ export { type ColumnHooks, type ColumnHookContext } from "./hooks.js";
4
+ export { type PolicyCommand, type PolicyConfig, type PolicyFor, type PolicyExpressionResolver, } from "./policy.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resolvers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,wBAAwB,GAC9B,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { defaultCodec } from "./codec.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resolvers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoB,MAAM,YAAY,CAAC","sourcesContent":["export { defaultCodec, type ColumnCodec } from \"./codec.js\";\nexport { type ColumnValidator } from \"./validator.js\";\nexport { type ColumnHooks, type ColumnHookContext } from \"./hooks.js\";\nexport {\n type PolicyCommand,\n type PolicyConfig,\n type PolicyFor,\n type PolicyExpressionResolver,\n} from \"./policy.js\";\n"]}
@@ -0,0 +1,31 @@
1
+ import type { SQLNode } from "../sql/nodes.js";
2
+ import type { Table, TableColumns } from "../runtime/table.js";
3
+ import { AnyTableDefinition, TableDefinition } from "../definition/table.js";
4
+ import { AnyTableRelations } from "../definition/relations.js";
5
+ /** A statement a policy applies to — PostgreSQL's `FOR` commands, `ALL` aside. */
6
+ export type PolicyCommand = "select" | "insert" | "update" | "delete";
7
+ /** What `for` accepts: one command, `"all"`, or several. */
8
+ export type PolicyFor = "all" | PolicyCommand;
9
+ /**
10
+ * A row policy, shaped like `CREATE POLICY … AS … FOR … USING (…) WITH CHECK (…)`.
11
+ *
12
+ * - `as`: permissive policies for a command are OR-ed, restrictive ones AND-ed onto them.
13
+ * Default `"permissive"`.
14
+ * - `for`: the commands it applies to. Default `"all"`. An array is one policy per command.
15
+ * - `using`: which existing rows a select, update or delete may see. Rows it rejects are
16
+ * skipped silently.
17
+ * - `check`: what a row written by an insert or update must satisfy; a write that fails it
18
+ * throws and writes nothing. Defaults to `using`.
19
+ */
20
+ export type PolicyConfig = {
21
+ readonly as?: "permissive" | "restrictive";
22
+ readonly for?: PolicyFor | readonly PolicyFor[];
23
+ readonly using?: SQLNode;
24
+ readonly check?: SQLNode;
25
+ };
26
+ /**
27
+ * Declares a policy against a table's runtime columns, so `${t.ownerId}` renders under whatever
28
+ * alias the level reading it is bound to. Runs once, when the client is built.
29
+ */
30
+ export type PolicyExpressionResolver<T extends AnyTableDefinition> = T extends TableDefinition<infer TName, infer TColumns, infer TNamespace> ? SQLNode | ((columns: TableColumns<Table<TName, TColumns, TNamespace, AnyTableRelations>>) => SQLNode) : never;
31
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/resolvers/policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,kFAAkF;AAClF,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEtE,4DAA4D;AAC5D,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,aAAa,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,EAAE,CAAC,EAAE,YAAY,GAAG,aAAa,CAAC;IAC3C,QAAQ,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG,SAAS,SAAS,EAAE,CAAC;IAChD,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;;GAGG;AAEH,MAAM,MAAM,wBAAwB,CAAC,CAAC,SAAS,kBAAkB,IAC/D,CAAC,SAAS,eAAe,CAAC,MAAM,KAAK,EAAE,MAAM,QAAQ,EAAE,MAAM,UAAU,CAAC,GAEhE,OAAO,GACP,CAAC,CACC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC,KACzE,OAAO,CAAC,GACjB,KAAK,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/resolvers/policy.ts"],"names":[],"mappings":"","sourcesContent":["import type { SQLNode } from \"../sql/nodes.js\";\nimport type { Table, TableColumns } from \"../runtime/table.js\";\nimport { AnyTableDefinition, TableDefinition } from \"../definition/table.js\";\nimport { AnyTableRelations } from \"../definition/relations.js\";\n\n/** A statement a policy applies to — PostgreSQL's `FOR` commands, `ALL` aside. */\nexport type PolicyCommand = \"select\" | \"insert\" | \"update\" | \"delete\";\n\n/** What `for` accepts: one command, `\"all\"`, or several. */\nexport type PolicyFor = \"all\" | PolicyCommand;\n\n/**\n * A row policy, shaped like `CREATE POLICY … AS … FOR … USING (…) WITH CHECK (…)`.\n *\n * - `as`: permissive policies for a command are OR-ed, restrictive ones AND-ed onto them.\n * Default `\"permissive\"`.\n * - `for`: the commands it applies to. Default `\"all\"`. An array is one policy per command.\n * - `using`: which existing rows a select, update or delete may see. Rows it rejects are\n * skipped silently.\n * - `check`: what a row written by an insert or update must satisfy; a write that fails it\n * throws and writes nothing. Defaults to `using`.\n */\nexport type PolicyConfig = {\n readonly as?: \"permissive\" | \"restrictive\";\n readonly for?: PolicyFor | readonly PolicyFor[];\n readonly using?: SQLNode;\n readonly check?: SQLNode;\n};\n\n/**\n * Declares a policy against a table's runtime columns, so `${t.ownerId}` renders under whatever\n * alias the level reading it is bound to. Runs once, when the client is built.\n */\n\nexport type PolicyExpressionResolver<T extends AnyTableDefinition> =\n T extends TableDefinition<infer TName, infer TColumns, infer TNamespace>\n ?\n | SQLNode\n | ((\n columns: TableColumns<Table<TName, TColumns, TNamespace, AnyTableRelations>>\n ) => SQLNode)\n : never;\n"]}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Checks a column's values on their way into and out of the database. Writes run `write` before
3
+ * the codec encodes; reads run `read` after it decodes. Filters run neither: a filter value is a
4
+ * pattern to compare with, not a value to store. Either method throws to refuse a value.
5
+ *
6
+ * `write` takes what a write accepts (`TInput`) and returns what is stored (`TValue`); they
7
+ * differ for a column whose writes accept more than its reads return — a JSON column validated
8
+ * by a schema with defaults, for one.
9
+ */
10
+ export type ColumnValidator<TValue, TInput = TValue> = {
11
+ write(input: TInput): TValue;
12
+ read(value: TValue): TValue;
13
+ };
14
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/resolvers/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI;IACrD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/resolvers/validator.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Checks a column's values on their way into and out of the database. Writes run `write` before\n * the codec encodes; reads run `read` after it decodes. Filters run neither: a filter value is a\n * pattern to compare with, not a value to store. Either method throws to refuse a value.\n *\n * `write` takes what a write accepts (`TInput`) and returns what is stored (`TValue`); they\n * differ for a column whose writes accept more than its reads return — a JSON column validated\n * by a schema with defaults, for one.\n */\nexport type ColumnValidator<TValue, TInput = TValue> = {\n write(input: TInput): TValue;\n read(value: TValue): TValue;\n};\n"]}
@@ -1,5 +1,5 @@
1
- import { AnyTableDefinition, AnyTableRelations, AnyUnionDefinition, DefinitionSchema, RelationsDefinition, TableDefinition } from "../definition/index.js";
2
- import { UnionToIntersection } from "../utils/types.js";
1
+ import { AnyTableDefinition, AnyTableRelations, AnyUnionDefinition, DefinitionSchema, RelationsDefinition, TableDefinition, UnionDefinition } from "../definition/index.js";
2
+ import { Prettify, UnionToIntersection } from "../utils/types.js";
3
3
  /**
4
4
  * Schema Definition Types
5
5
  */
@@ -10,7 +10,7 @@ export type DefinitionUnionName<TDefinition extends DefinitionSchema> = {
10
10
  [K in keyof TDefinition]: TDefinition[K] extends AnyUnionDefinition ? K : never;
11
11
  }[keyof TDefinition];
12
12
  export type DefinitionRelationsTableName<TDefinition extends DefinitionSchema> = {
13
- [K in keyof TDefinition]: TDefinition[K] extends RelationsDefinition<infer TableDefinition, infer _> ? TableDefinition extends AnyTableDefinition ? TableDefinition["name"] : never : never;
13
+ [K in keyof TDefinition]: TDefinition[K] extends RelationsDefinition<infer TableDefinition, infer _> ? TableDefinition extends AnyTableDefinition ? TableDefinition["name"] : TableDefinition extends AnyUnionDefinition ? TableDefinition["name"] | TableDefinition["members"][keyof TableDefinition["members"]]["name"] : never : never;
14
14
  }[keyof TDefinition];
15
15
  /**
16
16
  * Every relation declared for `TTableName`, as one object.
@@ -22,7 +22,7 @@ export type DefinitionRelationsTableName<TDefinition extends DefinitionSchema> =
22
22
  * registry performs. A table with no block still yields `never`: the intersection of nothing is
23
23
  * `unknown`, which the final check rejects.
24
24
  */
25
- export type DefinitionTableRelations<TDefinition extends DefinitionSchema, TTableName extends string> = UnionToIntersection<TDefinition extends Record<string, infer Def> ? Def extends RelationsDefinition<infer TTable, infer R> ? TTable extends TableDefinition<TTableName, infer _, infer __> ? R extends AnyTableRelations ? R : never : never : never : never> extends infer TMerged extends AnyTableRelations ? TMerged : never;
25
+ export type DefinitionTableRelations<TDefinition extends DefinitionSchema, TTableName extends string> = UnionToIntersection<TDefinition extends Record<string, infer Def> ? Def extends RelationsDefinition<infer TTable, infer R> ? TTable extends TableDefinition<TTableName, infer _, infer __> ? R extends AnyTableRelations ? R : never : TTable extends UnionDefinition<TTableName, infer _, infer __> ? R extends AnyTableRelations ? R : never : TTable extends AnyUnionDefinition ? TTable extends UnionDefinition<infer _, infer TMembers, infer __> ? TMembers[keyof TMembers] extends infer TMember ? TMember extends TableDefinition<TTableName, infer _, infer __> ? R extends AnyTableRelations ? R : never : never : never : never : never : never : never> extends infer TMerged extends AnyTableRelations ? Prettify<TMerged> : false;
26
26
  export type SchemaTableDefinitions<TDefinition extends DefinitionSchema> = {
27
27
  [K in DefinitionTableName<TDefinition>]: TDefinition[K] extends AnyTableDefinition ? TDefinition[K] : never;
28
28
  };
@@ -44,4 +44,7 @@ export type AnySchema = Schema<DefinitionSchema>;
44
44
  export type SchemaTableRelations<TSchema extends AnySchema, TTableName extends string> = TSchema["relations"] extends Record<TTableName, infer R> ? R extends AnyTableRelations ? R : never : never;
45
45
  export type TableRelationFieldName<TSchema extends AnySchema, TTableName extends string> = TTableName extends keyof TSchema["relations"] ? TSchema["relations"][TTableName] extends AnyTableRelations ? keyof TSchema["relations"][TTableName] : never : never;
46
46
  export type FieldRelationConfig<TSchema extends AnySchema, TTableName extends string, TFieldName extends string> = TTableName extends keyof TSchema["relations"] ? TSchema["relations"][TTableName] extends AnyTableRelations ? TFieldName extends keyof TSchema["relations"][TTableName] ? TSchema["relations"][TTableName][TFieldName] : never : never : never;
47
+ export type WithRelations<T, TRelations extends AnyTableRelations | undefined> = T & {
48
+ relations: TRelations extends AnyTableRelations ? TRelations : never;
49
+ };
47
50
  //# sourceMappingURL=base.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/runtime/base.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AAEH,MAAM,MAAM,mBAAmB,CAAC,WAAW,SAAS,gBAAgB,IAAI;KACrE,CAAC,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,SAAS,kBAAkB,GAAG,CAAC,GAAG,KAAK;CAChF,CAAC,MAAM,WAAW,CAAC,CAAC;AAErB,MAAM,MAAM,mBAAmB,CAAC,WAAW,SAAS,gBAAgB,IAAI;KACrE,CAAC,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,SAAS,kBAAkB,GAAG,CAAC,GAAG,KAAK;CAChF,CAAC,MAAM,WAAW,CAAC,CAAC;AAErB,MAAM,MAAM,4BAA4B,CAAC,WAAW,SAAS,gBAAgB,IAAI;KAC9E,CAAC,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,SAAS,mBAAmB,CAClE,MAAM,eAAe,EACrB,MAAM,CAAC,CACR,GACG,eAAe,SAAS,kBAAkB,GACxC,eAAe,CAAC,MAAM,CAAC,GACvB,KAAK,GACP,KAAK;CACV,CAAC,MAAM,WAAW,CAAC,CAAC;AAErB;;;;;;;;;GASG;AACH,MAAM,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
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/runtime/base.ts"],"names":[],"mappings":"AAAA,sDAAsD","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\nimport {\n AnyTableDefinition,\n AnyTableRelations,\n AnyUnionDefinition,\n DefinitionSchema,\n RelationsDefinition,\n TableDefinition,\n} from \"../definition/index.js\";\nimport { UnionToIntersection } from \"../utils/types.js\";\n\n/**\n * Schema Definition Types\n */\n\nexport type DefinitionTableName<TDefinition extends DefinitionSchema> = {\n [K in keyof TDefinition]: TDefinition[K] extends AnyTableDefinition ? K : never;\n}[keyof TDefinition];\n\nexport type DefinitionUnionName<TDefinition extends DefinitionSchema> = {\n [K in keyof TDefinition]: TDefinition[K] extends AnyUnionDefinition ? K : never;\n}[keyof TDefinition];\n\nexport type DefinitionRelationsTableName<TDefinition extends DefinitionSchema> = {\n [K in keyof TDefinition]: TDefinition[K] extends RelationsDefinition<\n infer TableDefinition,\n infer _\n >\n ? TableDefinition extends AnyTableDefinition\n ? TableDefinition[\"name\"]\n : never\n : never;\n}[keyof TDefinition];\n\n/**\n * Every relation declared for `TTableName`, as one object.\n *\n * A table may be given several `relations()` blocks — the registry merges them, refusing a\n * name declared twice. Matching the blocks yields one map per block, as a union; `keyof` a\n * union keeps only the keys every member shares, so left as a union a table with two blocks\n * would have no relation names at all. The union is therefore collapsed into the merge the\n * registry performs. A table with no block still yields `never`: the intersection of nothing is\n * `unknown`, which the final check rejects.\n */\nexport type DefinitionTableRelations<\n TDefinition extends DefinitionSchema,\n TTableName extends string,\n> = UnionToIntersection<\n TDefinition extends Record<string, infer Def>\n ? Def extends RelationsDefinition<infer TTable, infer R>\n ? TTable extends TableDefinition<TTableName, infer _, infer __>\n ? R extends AnyTableRelations\n ? R\n : never\n : never\n : never\n : never\n> extends infer TMerged extends AnyTableRelations\n ? TMerged\n : never;\n\nexport type SchemaTableDefinitions<TDefinition extends DefinitionSchema> = {\n [K in DefinitionTableName<TDefinition>]: TDefinition[K] extends AnyTableDefinition\n ? TDefinition[K]\n : never;\n};\n\nexport type SchemaRelationDefinitions<T extends DefinitionSchema> = {\n [K in DefinitionRelationsTableName<T>]: DefinitionTableRelations<T, K>;\n};\n\nexport type SchemaUnionDefinitions<TDefinition extends DefinitionSchema> = {\n [K in DefinitionUnionName<TDefinition>]: TDefinition[K] extends AnyUnionDefinition\n ? TDefinition[K]\n : never;\n};\n\nexport type Schema<T extends DefinitionSchema> = {\n tables: SchemaTableDefinitions<T>;\n relations: SchemaRelationDefinitions<T>;\n unions: SchemaUnionDefinitions<T>;\n};\n\nexport type AnySchema = Schema<DefinitionSchema>;\n\n/**\n * Table Relation Types\n */\n\nexport type SchemaTableRelations<TSchema extends AnySchema, TTableName extends string> =\n TSchema[\"relations\"] extends Record<TTableName, infer R>\n ? R extends AnyTableRelations\n ? R\n : never\n : never;\n\nexport type TableRelationFieldName<\n TSchema extends AnySchema,\n TTableName extends string,\n> = TTableName extends keyof TSchema[\"relations\"]\n ? TSchema[\"relations\"][TTableName] extends AnyTableRelations\n ? keyof TSchema[\"relations\"][TTableName]\n : never\n : never;\n\nexport type FieldRelationConfig<\n TSchema extends AnySchema,\n TTableName extends string,\n TFieldName extends string,\n> = TTableName extends keyof TSchema[\"relations\"]\n ? TSchema[\"relations\"][TTableName] extends AnyTableRelations\n ? TFieldName extends keyof TSchema[\"relations\"][TTableName]\n ? TSchema[\"relations\"][TTableName][TFieldName]\n : never\n : never\n : never;\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/runtime/base.ts"],"names":[],"mappings":"AAAA,sDAAsD","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\nimport {\n AnyTableDefinition,\n AnyTableRelations,\n AnyUnionDefinition,\n DefinitionSchema,\n RelationsDefinition,\n TableDefinition,\n UnionDefinition,\n} from \"../definition/index.js\";\nimport { Prettify, UnionToIntersection } from \"../utils/types.js\";\n\n/**\n * Schema Definition Types\n */\n\nexport type DefinitionTableName<TDefinition extends DefinitionSchema> = {\n [K in keyof TDefinition]: TDefinition[K] extends AnyTableDefinition ? K : never;\n}[keyof TDefinition];\n\nexport type DefinitionUnionName<TDefinition extends DefinitionSchema> = {\n [K in keyof TDefinition]: TDefinition[K] extends AnyUnionDefinition ? K : never;\n}[keyof TDefinition];\n\nexport type DefinitionRelationsTableName<TDefinition extends DefinitionSchema> = {\n [K in keyof TDefinition]: TDefinition[K] extends RelationsDefinition<\n infer TableDefinition,\n infer _\n >\n ? TableDefinition extends AnyTableDefinition\n ? TableDefinition[\"name\"]\n : // A union's relations belong to every member.\n TableDefinition extends AnyUnionDefinition\n ?\n | TableDefinition[\"name\"]\n | TableDefinition[\"members\"][keyof TableDefinition[\"members\"]][\"name\"]\n : never\n : never;\n}[keyof TDefinition];\n\n/**\n * Every relation declared for `TTableName`, as one object.\n *\n * A table may be given several `relations()` blocks — the registry merges them, refusing a\n * name declared twice. Matching the blocks yields one map per block, as a union; `keyof` a\n * union keeps only the keys every member shares, so left as a union a table with two blocks\n * would have no relation names at all. The union is therefore collapsed into the merge the\n * registry performs. A table with no block still yields `never`: the intersection of nothing is\n * `unknown`, which the final check rejects.\n */\nexport type DefinitionTableRelations<\n TDefinition extends DefinitionSchema,\n TTableName extends string,\n> =\n UnionToIntersection<\n TDefinition extends Record<string, infer Def>\n ? Def extends RelationsDefinition<infer TTable, infer R>\n ? TTable extends TableDefinition<TTableName, infer _, infer __>\n ? R extends AnyTableRelations\n ? R\n : never\n : // A union's relations, which each member has from its own columns.\n TTable extends UnionDefinition<TTableName, infer _, infer __>\n ? R extends AnyTableRelations\n ? R\n : never\n : TTable extends AnyUnionDefinition\n ? TTable extends UnionDefinition<infer _, infer TMembers, infer __>\n ? TMembers[keyof TMembers] extends infer TMember\n ? TMember extends TableDefinition<TTableName, infer _, infer __>\n ? R extends AnyTableRelations\n ? R\n : never\n : never\n : never\n : never\n : never\n : never\n : never\n > extends infer TMerged extends AnyTableRelations\n ? Prettify<TMerged>\n : false;\n\nexport type SchemaTableDefinitions<TDefinition extends DefinitionSchema> = {\n [K in DefinitionTableName<TDefinition>]: TDefinition[K] extends AnyTableDefinition\n ? TDefinition[K]\n : never;\n};\n\nexport type SchemaRelationDefinitions<T extends DefinitionSchema> = {\n [K in DefinitionRelationsTableName<T>]: DefinitionTableRelations<T, K>;\n};\n\nexport type SchemaUnionDefinitions<TDefinition extends DefinitionSchema> = {\n [K in DefinitionUnionName<TDefinition>]: TDefinition[K] extends AnyUnionDefinition\n ? TDefinition[K]\n : never;\n};\n\nexport type Schema<T extends DefinitionSchema> = {\n tables: SchemaTableDefinitions<T>;\n relations: SchemaRelationDefinitions<T>;\n unions: SchemaUnionDefinitions<T>;\n};\n\nexport type AnySchema = Schema<DefinitionSchema>;\n\n/**\n * Table Relation Types\n */\n\nexport type SchemaTableRelations<TSchema extends AnySchema, TTableName extends string> =\n TSchema[\"relations\"] extends Record<TTableName, infer R>\n ? R extends AnyTableRelations\n ? R\n : never\n : never;\n\nexport type TableRelationFieldName<\n TSchema extends AnySchema,\n TTableName extends string,\n> = TTableName extends keyof TSchema[\"relations\"]\n ? TSchema[\"relations\"][TTableName] extends AnyTableRelations\n ? keyof TSchema[\"relations\"][TTableName]\n : never\n : never;\n\nexport type FieldRelationConfig<\n TSchema extends AnySchema,\n TTableName extends string,\n TFieldName extends string,\n> = TTableName extends keyof TSchema[\"relations\"]\n ? TSchema[\"relations\"][TTableName] extends AnyTableRelations\n ? TFieldName extends keyof TSchema[\"relations\"][TTableName]\n ? TSchema[\"relations\"][TTableName][TFieldName]\n : never\n : never\n : never;\n\nexport type WithRelations<T, TRelations extends AnyTableRelations | undefined> = T & {\n relations: TRelations extends AnyTableRelations ? TRelations : never;\n};\n"]}
@@ -0,0 +1,22 @@
1
+ import { DefinitionSchema } from "../definition/index.js";
2
+ import { RuntimeRelation } from "./relation.js";
3
+ import { AnyTable } from "./table.js";
4
+ import { AnyUnion } from "./union.js";
5
+ /** A schema's runtime objects, as `SchemaRegistry` holds them. */
6
+ export type BuiltSchema = {
7
+ /** Every table, under both its schema alias and its database name. */
8
+ readonly tables: Map<string, AnyTable>;
9
+ /** Every union, by schema alias. */
10
+ readonly unions: Map<string, AnyUnion>;
11
+ /** Every table's relations, by field. A table with none has no entry. */
12
+ readonly relations: Map<AnyTable, Readonly<Record<string, RuntimeRelation>>>;
13
+ };
14
+ /**
15
+ * Builds the runtime objects of a schema `validateSchema` accepted: tables, unions, relations
16
+ * resolved to runtime columns, and the references those relations set on their foreign keys.
17
+ *
18
+ * It checks nothing; given a schema that was not validated, it may build nonsense or throw on
19
+ * a missing column. Nothing it uses while building outlives the call.
20
+ */
21
+ export declare function buildSchema(schema: DefinitionSchema): BuiltSchema;
22
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/runtime/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,gBAAgB,EAIjB,MAAM,wBAAwB,CAAC;AAShC,OAAO,EAAE,eAAe,EAAiB,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAS,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAS,MAAM,YAAY,CAAC;AAE7C,kEAAkE;AAClE,MAAM,MAAM,WAAW,GAAG;IACxB,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACvC,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACvC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;CAC9E,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,WAAW,CA4DjE"}