@dsqlbase/core 0.1.5 → 0.2.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 (134) hide show
  1. package/CHANGELOG.md +197 -0
  2. package/LICENSE +21 -0
  3. package/README.md +4 -0
  4. package/dist/definition/base.d.ts +50 -3
  5. package/dist/definition/base.d.ts.map +1 -1
  6. package/dist/definition/base.js +34 -1
  7. package/dist/definition/base.js.map +1 -1
  8. package/dist/definition/column.d.ts +87 -14
  9. package/dist/definition/column.d.ts.map +1 -1
  10. package/dist/definition/column.js +99 -5
  11. package/dist/definition/column.js.map +1 -1
  12. package/dist/definition/constraint.d.ts +16 -15
  13. package/dist/definition/constraint.d.ts.map +1 -1
  14. package/dist/definition/constraint.js +4 -1
  15. package/dist/definition/constraint.js.map +1 -1
  16. package/dist/definition/domain.d.ts +12 -8
  17. package/dist/definition/domain.d.ts.map +1 -1
  18. package/dist/definition/domain.js +10 -2
  19. package/dist/definition/domain.js.map +1 -1
  20. package/dist/definition/embedded.d.ts +131 -0
  21. package/dist/definition/embedded.d.ts.map +1 -0
  22. package/dist/definition/embedded.js +133 -0
  23. package/dist/definition/embedded.js.map +1 -0
  24. package/dist/definition/index.d.ts +7 -4
  25. package/dist/definition/index.d.ts.map +1 -1
  26. package/dist/definition/index.js +4 -1
  27. package/dist/definition/index.js.map +1 -1
  28. package/dist/definition/indexes.d.ts +49 -19
  29. package/dist/definition/indexes.d.ts.map +1 -1
  30. package/dist/definition/indexes.js +38 -9
  31. package/dist/definition/indexes.js.map +1 -1
  32. package/dist/definition/namespace.d.ts +2 -2
  33. package/dist/definition/namespace.d.ts.map +1 -1
  34. package/dist/definition/namespace.js.map +1 -1
  35. package/dist/definition/relations.d.ts +47 -15
  36. package/dist/definition/relations.d.ts.map +1 -1
  37. package/dist/definition/relations.js +17 -12
  38. package/dist/definition/relations.js.map +1 -1
  39. package/dist/definition/sequence.d.ts +4 -4
  40. package/dist/definition/sequence.d.ts.map +1 -1
  41. package/dist/definition/sequence.js.map +1 -1
  42. package/dist/definition/table.d.ts +118 -13
  43. package/dist/definition/table.d.ts.map +1 -1
  44. package/dist/definition/table.js +137 -4
  45. package/dist/definition/table.js.map +1 -1
  46. package/dist/definition/tenant.d.ts +50 -0
  47. package/dist/definition/tenant.d.ts.map +1 -0
  48. package/dist/definition/tenant.js +73 -0
  49. package/dist/definition/tenant.js.map +1 -0
  50. package/dist/definition/union.d.ts +84 -0
  51. package/dist/definition/union.d.ts.map +1 -0
  52. package/dist/definition/union.js +89 -0
  53. package/dist/definition/union.js.map +1 -0
  54. package/dist/definition/view.js.map +1 -1
  55. package/dist/index.d.ts +3 -3
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +2 -2
  58. package/dist/index.js.map +1 -1
  59. package/dist/runtime/base.d.ts +22 -4
  60. package/dist/runtime/base.d.ts.map +1 -1
  61. package/dist/runtime/base.js.map +1 -1
  62. package/dist/runtime/column.d.ts +54 -3
  63. package/dist/runtime/column.d.ts.map +1 -1
  64. package/dist/runtime/column.js +75 -7
  65. package/dist/runtime/column.js.map +1 -1
  66. package/dist/runtime/context.d.ts +30 -2
  67. package/dist/runtime/context.d.ts.map +1 -1
  68. package/dist/runtime/context.js +6 -0
  69. package/dist/runtime/context.js.map +1 -1
  70. package/dist/runtime/errors.d.ts +14 -0
  71. package/dist/runtime/errors.d.ts.map +1 -0
  72. package/dist/runtime/errors.js +19 -0
  73. package/dist/runtime/errors.js.map +1 -0
  74. package/dist/runtime/executor.d.ts +29 -1
  75. package/dist/runtime/executor.d.ts.map +1 -1
  76. package/dist/runtime/executor.js +23 -0
  77. package/dist/runtime/executor.js.map +1 -1
  78. package/dist/runtime/group.d.ts +54 -0
  79. package/dist/runtime/group.d.ts.map +1 -0
  80. package/dist/runtime/group.js +96 -0
  81. package/dist/runtime/group.js.map +1 -0
  82. package/dist/runtime/index.d.ts +9 -6
  83. package/dist/runtime/index.d.ts.map +1 -1
  84. package/dist/runtime/index.js +6 -3
  85. package/dist/runtime/index.js.map +1 -1
  86. package/dist/runtime/operation.d.ts +227 -29
  87. package/dist/runtime/operation.d.ts.map +1 -1
  88. package/dist/runtime/operation.js +525 -49
  89. package/dist/runtime/operation.js.map +1 -1
  90. package/dist/runtime/query.d.ts +102 -34
  91. package/dist/runtime/query.d.ts.map +1 -1
  92. package/dist/runtime/query.js +140 -31
  93. package/dist/runtime/query.js.map +1 -1
  94. package/dist/runtime/registry.d.ts +114 -4
  95. package/dist/runtime/registry.d.ts.map +1 -1
  96. package/dist/runtime/registry.js +366 -9
  97. package/dist/runtime/registry.js.map +1 -1
  98. package/dist/runtime/session.d.ts +10 -4
  99. package/dist/runtime/session.d.ts.map +1 -1
  100. package/dist/runtime/session.js.map +1 -1
  101. package/dist/runtime/table.d.ts +87 -8
  102. package/dist/runtime/table.d.ts.map +1 -1
  103. package/dist/runtime/table.js +142 -5
  104. package/dist/runtime/table.js.map +1 -1
  105. package/dist/runtime/union.d.ts +33 -0
  106. package/dist/runtime/union.d.ts.map +1 -0
  107. package/dist/runtime/union.js +69 -0
  108. package/dist/runtime/union.js.map +1 -0
  109. package/dist/sql/index.d.ts +1 -1
  110. package/dist/sql/index.d.ts.map +1 -1
  111. package/dist/sql/index.js.map +1 -1
  112. package/dist/sql/nodes.d.ts +33 -6
  113. package/dist/sql/nodes.d.ts.map +1 -1
  114. package/dist/sql/nodes.js +25 -0
  115. package/dist/sql/nodes.js.map +1 -1
  116. package/dist/sql/tag.d.ts +17 -0
  117. package/dist/sql/tag.d.ts.map +1 -1
  118. package/dist/sql/tag.js +95 -0
  119. package/dist/sql/tag.js.map +1 -1
  120. package/dist/sql/utils.d.ts +2 -2
  121. package/dist/sql/utils.d.ts.map +1 -1
  122. package/dist/sql/utils.js.map +1 -1
  123. package/dist/utils/index.d.ts +1 -1
  124. package/dist/utils/index.d.ts.map +1 -1
  125. package/dist/utils/index.js.map +1 -1
  126. package/dist/utils/thenable.js.map +1 -1
  127. package/dist/utils/types.d.ts +50 -2
  128. package/dist/utils/types.d.ts.map +1 -1
  129. package/dist/utils/types.js.map +1 -1
  130. package/package.json +27 -22
  131. package/dist/sql/expressions.d.ts +0 -25
  132. package/dist/sql/expressions.d.ts.map +0 -1
  133. package/dist/sql/expressions.js +0 -79
  134. package/dist/sql/expressions.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/definition/table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,EAEL,yBAAyB,EACzB,8BAA8B,EAC9B,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAmC,eAAe,EAAE,MAAM,cAAc,CAAC;AAkBhF,MAAM,OAAO,eAIX,SAAQ,cAAwD;IACvD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;IAEjB,UAAU,CAAuB;IACjC,QAAQ,GAAyB,EAAE,CAAC;IACpC,YAAY,GAA8B,EAAE,CAAC;IAE9C,OAAO,CAAqB;IAErC,YAAY,IAAW,EAAE,MAAyC;QAChE,KAAK,CAAC,IAAI,CAAC,CAAC;QAEZ,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAA6B,CAAC;IACtD,CAAC;IAED,gBAAgB;IAChB,cAAc;QACZ,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CACrD,CAAC;IACnC,CAAC;IAEM,KAAK,CACV,IAAc,EACd,SAA6C,EAAE;QAE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IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YACvE,CAAC,CAAC;YACF,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YACjD,WAAW;YACX,WAAW,EAAE,IAAI,CAAC,YAAY,IAAI,IAAI;SAC9B,CAAC;IACb,CAAC;CACF","sourcesContent":["import { WithMeta } from \"../utils/types.js\";\nimport { SQLNode, SQLQuery } from \"../sql/nodes.js\";\nimport { DefinitionNode, Kind, NodeRef, RESERVED_FIELD_NAMES } from \"./base.js\";\nimport {\n ColumnGroupDefinition,\n ColumnRefOf,\n ColumnRefs,\n columnEntries,\n TableColumnDefinitions,\n} from \"./embedded.js\";\nimport {\n AnyConstraintDefinition,\n CheckConstraintDefinition,\n PrimaryKeyConstraintDefinition,\n UniqueConstraintDefinition,\n} from \"./constraint.js\";\nimport { AnyIndexDefinition, IndexConfig, IndexDefinition } from \"./indexes.js\";\nimport { AnyNamespaceDefinition } from \"./namespace.js\";\n\nexport type TableConfig<\n TColumns extends TableColumnDefinitions,\n TSchema extends AnyNamespaceDefinition,\n> = {\n namespace?: NodeRef<TSchema>;\n columns: TColumns;\n /**\n * Arbitrary per-table metadata, surfaced on every result row as part of `$$meta`.\n * Describes the table to the application, never to the database: it is not DDL and is\n * deliberately absent from {@link TableDefinition.toJSON}, so it never reaches a migration.\n */\n meta?: unknown;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyTableDefinition = TableDefinition<any, any, any>;\n\nexport type { ColumnRefOf, ColumnRefs };\n\nexport class TableDefinition<\n TName extends string,\n TColumns extends TableColumnDefinitions,\n TNamespace extends AnyNamespaceDefinition,\n> extends DefinitionNode<TName, TableConfig<TColumns, TNamespace>> {\n readonly kind = Kind.TABLE;\n\n protected _namespace?: NodeRef<TNamespace>;\n protected _indexes: AnyIndexDefinition[] = [];\n protected _constraints: AnyConstraintDefinition[] = [];\n protected _meta?: Record<string, unknown>;\n protected _renamedFrom?: string;\n\n readonly columns: Readonly<TColumns>;\n\n constructor(name: TName, config: TableConfig<TColumns, TNamespace>) {\n super(name);\n\n this._namespace = config.namespace;\n this.columns = config.columns as Readonly<TColumns>;\n this._meta = config.meta as Record<string, unknown> | undefined;\n\n this._assertReservedFieldNames();\n this._assertDistinctColumnNames();\n this._assertDeprecations();\n this._assertTenantKeys();\n }\n\n /**\n * Field names the runtime writes onto result records itself cannot also be columns —\n * one would overwrite the other. Checked here rather than at `Table` build time so the\n * error names the definition the author wrote.\n */\n private _assertReservedFieldNames(): void {\n for (const field of Object.keys(this.columns)) {\n if (RESERVED_FIELD_NAMES.includes(field)) {\n throw new Error(\n `Table \"${this.name}\" declares a column named \"${field}\", which is reserved. ` +\n `The runtime writes ${RESERVED_FIELD_NAMES.join(\" and \")} onto every result row.`\n );\n }\n }\n }\n\n /**\n * Two fields mapping to one database column is always a mistake, and a silent one: the\n * result resolver reads a row by column name (`packages/core/src/runtime/operation.ts`),\n * so one field would shadow the other, and `toJSON` would emit the column twice. A group's\n * members count by their full path, so `netValue.amount` against a plain `net_value_amount`\n * is caught too.\n */\n /**\n * A deprecated column must be one the table can do without: not part of the primary key, and\n * not a member of an embedded object (which the client reads as a whole).\n */\n private _assertDeprecations(): void {\n for (const [path, column] of columnEntries(this.columns)) {\n if (!column[\"_deprecated\"]) continue;\n\n if (path.length > 1) {\n throw new Error(\n `Table \"${this.name}\" deprecates \"${path.join(\".\")}\", a member of an embedded object. ` +\n `Only a table's own columns can be deprecated.`\n );\n }\n\n if (column[\"_primaryKey\"]) {\n throw new Error(\n `Table \"${this.name}\" deprecates \"${path.join(\".\")}\", part of its primary key, which ` +\n `can't be dropped.`\n );\n }\n }\n }\n\n private _assertDistinctColumnNames(): void {\n const fieldsByColumn = new Map<string, string>();\n\n for (const [path, column] of columnEntries(this.columns)) {\n const field = path.join(\".\");\n const existing = fieldsByColumn.get(column.name);\n\n if (existing !== undefined) {\n throw new Error(\n `Table \"${this.name}\" maps fields \"${existing}\" and \"${field}\" to the same column ` +\n `\"${column.name}\". Every field must map to a distinct column.`\n );\n }\n\n fieldsByColumn.set(column.name, field);\n }\n }\n\n /**\n * A tenant claim column is filled by the runtime on every insert and AND-ed into every read,\n * so it can be neither null nor writable by the caller. `tenantScope()` sets both flags when\n * it hands the column over; this catches a column configured as a claim key any other way,\n * and catches it here — where the error can name the definition the author wrote.\n */\n private _assertTenantKeys(): void {\n for (const [path, column] of columnEntries(this.columns)) {\n const field = path.join(\".\");\n if (!column[\"_tenantKey\"]) {\n continue;\n }\n\n if (!column[\"_notNull\"]) {\n throw new Error(\n `Table \"${this.name}\" declares claim \"${field}\" as nullable. A claim column is ` +\n `filled by the runtime on every insert, so it is never null.`\n );\n }\n\n if (!column[\"_readOnly\"]) {\n throw new Error(\n `Table \"${this.name}\" declares claim \"${field}\" as writable. A claim column's value ` +\n `comes from the identity on the client, never from the caller.`\n );\n }\n }\n }\n\n /** @internal */\n _getColumnRefs(): ColumnRefs<this[\"columns\"]> {\n return Object.fromEntries(\n Object.entries(this.columns).map(([field, column]) => [\n field,\n column instanceof ColumnGroupDefinition ? column._getColumnRefs() : new NodeRef(column),\n ])\n ) as ColumnRefs<this[\"columns\"]>;\n }\n\n public index<TIdxName extends string, TIdxConfig extends IndexConfig>(\n name: TIdxName,\n config: Partial<Omit<TIdxConfig, \"table\">> = {}\n ): IndexDefinition<TIdxName, this> {\n const idx = new IndexDefinition(name, { ...config, table: this });\n this._indexes.push(idx);\n\n return idx as IndexDefinition<TIdxName, this>;\n }\n\n public check(cb: (columns: ColumnRefs<this[\"columns\"]>) => SQLNode, name?: string): this {\n const expression = new SQLQuery(cb(this._getColumnRefs()));\n this._constraints?.push(\n new CheckConstraintDefinition(name ?? `${this.name}_check`, { expression })\n );\n\n return this;\n }\n\n public unique(\n cb: (columns: ColumnRefs<this[\"columns\"]>) => ColumnRefOf<this[\"columns\"]>[]\n ): UniqueConstraintDefinition<string, this> {\n const cols = cb(this._getColumnRefs());\n\n const constraint = new UniqueConstraintDefinition(`${this.name}_unique`, {\n table: this,\n columns: cols,\n });\n this._constraints?.push(constraint);\n\n return constraint;\n }\n\n public primaryKey(\n cb: (columns: ColumnRefs<this[\"columns\"]>) => ColumnRefOf<this[\"columns\"]>[]\n ): PrimaryKeyConstraintDefinition<string, this> {\n const cols = cb(this._getColumnRefs());\n const members = new Set(\n columnEntries(this.columns)\n .filter(([path]) => path.length > 1)\n .map(([, column]) => column.name)\n );\n\n const deprecated = new Set(\n columnEntries(this.columns)\n .filter(([, column]) => column[\"_deprecated\"])\n .map(([, column]) => column.name)\n );\n\n for (const ref of cols) {\n if (deprecated.has(ref.name)) {\n throw new Error(\n `Table \"${this.name}\" declares a primary key on \"${ref.name}\", which is deprecated.`\n );\n }\n\n if (members.has(ref.name)) {\n throw new Error(\n `Table \"${this.name}\" declares a primary key on \"${ref.name}\", a member of an ` +\n `embedded object. A primary key spans plain columns only.`\n );\n }\n }\n\n const constraint = new PrimaryKeyConstraintDefinition(`${this.name}_primary_key`, {\n table: this,\n columns: cols,\n });\n\n this._constraints?.push(constraint);\n\n return constraint;\n }\n\n /**\n * Attaches arbitrary metadata to the table, surfaced on every result row under `$$meta`\n * alongside the built-in `key`, `table` and `schema`.\n *\n * Metadata describes the table to the application — a GraphQL typename, a display label —\n * and never to the database: it is absent from {@link TableDefinition.toJSON}, so it does\n * not participate in migrations. Built-in keys may not be overwritten; that throws when the\n * runtime `Table` is built.\n *\n * @example\n * ```ts\n * const users = table(\"users\", { id: uuid(\"id\").primaryKey() }).meta({ __typename: \"User\" });\n * // row.$$meta.__typename === \"User\"\n * ```\n */\n /**\n * The table's previous name: the migration renames it (`ALTER TABLE … RENAME TO`) instead of\n * dropping one table and creating another. Once the database has the new name the hint does\n * nothing, so it can stay for a release before it is removed.\n */\n public renamedFrom(previous: string): this {\n this._renamedFrom = previous;\n return this;\n }\n\n public meta<M extends Record<string, unknown>>(meta: M): WithMeta<this, M> {\n this._meta = meta;\n\n return this as WithMeta<this, M>;\n }\n\n public toJSON() {\n const constraints = this._constraints?.map((constraint) => constraint.toJSON());\n // PostgreSQL makes every primary-key column NOT NULL; a composite key's columns say so here.\n const keyColumns = new Set<string>(\n constraints.flatMap((constraint) =>\n constraint.kind === Kind.PRIMARY_KEY_CONSTRAINT ? constraint.columns : []\n )\n );\n\n return {\n kind: this.kind,\n name: this.name,\n namespace: this._namespace?.name ?? \"public\",\n columns: columnEntries(this.columns).map(([, column]) => {\n const json = column.toJSON();\n return keyColumns.has(json.name) ? { ...json, notNull: true } : json;\n }),\n indexes: this._indexes.map((idx) => idx.toJSON()),\n constraints,\n renamedFrom: this._renamedFrom ?? null,\n } as const;\n }\n}\n"]}
@@ -0,0 +1,50 @@
1
+ import { Prettify, ReadOnly, TenantKey } from "../utils/index.js";
2
+ import { DefinitionNode } from "./base.js";
3
+ import { TableColumnDefinitions } from "./embedded.js";
4
+ import { AnyColumnDefinition } from "./column.js";
5
+ import { AnyNamespaceDefinition } from "./namespace.js";
6
+ import { TableDefinition } from "./table.js";
7
+ export type AnyTenantScopeDefinition = TenantScopeDefinition<any>;
8
+ /** The claim columns as a table receives them: system-managed and marked as claim keys. */
9
+ export type TenantClaimColumns<TClaims extends Record<string, AnyColumnDefinition>> = {
10
+ [K in keyof TClaims]: TenantKey<ReadOnly<TClaims[K]>>;
11
+ };
12
+ /** A table's own columns with the scope's claim columns merged in front of them. */
13
+ export type WithClaims<TClaims extends Record<string, AnyColumnDefinition>, TColumns extends TableColumnDefinitions> = Prettify<TenantClaimColumns<TClaims> & TColumns>;
14
+ export type TenantScopeConfig<TClaims extends Record<string, AnyColumnDefinition>> = {
15
+ claims: TClaims;
16
+ };
17
+ /**
18
+ * A named set of claim columns shared by every table in one tenant boundary.
19
+ *
20
+ * The scope is the only producer of the `tenantKey` marker: a column carries it by being
21
+ * declared here, never by a builder of its own. That is deliberate — a per-column marker would
22
+ * leave no single place that says "these are the claims", which is what
23
+ * `ExecutionContext.identity` has to be matched against.
24
+ *
25
+ * It is a definition node so it may be exported from a schema module beside the tables that use
26
+ * it; the registry keeps only tables and relations, and it is not a schema object, so no
27
+ * migration ever sees it.
28
+ */
29
+ export declare class TenantScopeDefinition<TClaims extends Record<string, AnyColumnDefinition>> extends DefinitionNode<string, TenantScopeConfig<TClaims>> {
30
+ readonly kind: "TENANT_SCOPE";
31
+ private readonly _claims;
32
+ constructor(claims: TClaims, name?: string);
33
+ /** The claim field names, in declaration order. */
34
+ get claims(): (keyof TClaims & string)[];
35
+ /**
36
+ * A fresh copy of every claim column, marked as a claim key and system-managed.
37
+ *
38
+ * Fresh on every call: the builders mutate a `ColumnDefinition` in place, so handing the same
39
+ * instance to two tables would let a later change on one reach the other.
40
+ */
41
+ columns(): TenantClaimColumns<TClaims>;
42
+ /**
43
+ * A table inside this scope: sugar for spreading {@link columns} into `table(name, { … })`.
44
+ *
45
+ * Use the spread form directly when the table needs a different constructor — a namespaced
46
+ * table is built by `namespace().table()`, which this cannot stand in for.
47
+ */
48
+ table<TName extends string, TColumns extends TableColumnDefinitions>(name: TName, columns: TColumns): TableDefinition<TName, WithClaims<TClaims, TColumns>, AnyNamespaceDefinition>;
49
+ }
50
+ //# sourceMappingURL=tenant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant.d.ts","sourceRoot":"","sources":["../../src/definition/tenant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAQ,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO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,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,sBAAsB,CAAC;CAgBjF"}
@@ -0,0 +1,73 @@
1
+ import { DefinitionNode, Kind } from "./base.js";
2
+ import { TableDefinition } from "./table.js";
3
+ /** The name a scope carries when none is given. It names nothing in the database. */
4
+ const DEFAULT_SCOPE_NAME = "tenant_scope";
5
+ /**
6
+ * A named set of claim columns shared by every table in one tenant boundary.
7
+ *
8
+ * The scope is the only producer of the `tenantKey` marker: a column carries it by being
9
+ * declared here, never by a builder of its own. That is deliberate — a per-column marker would
10
+ * leave no single place that says "these are the claims", which is what
11
+ * `ExecutionContext.identity` has to be matched against.
12
+ *
13
+ * It is a definition node so it may be exported from a schema module beside the tables that use
14
+ * it; the registry keeps only tables and relations, and it is not a schema object, so no
15
+ * migration ever sees it.
16
+ */
17
+ export class TenantScopeDefinition extends DefinitionNode {
18
+ kind = Kind.TENANT_SCOPE;
19
+ _claims;
20
+ constructor(claims, name = DEFAULT_SCOPE_NAME) {
21
+ super(name);
22
+ const fields = Object.keys(claims);
23
+ if (fields.length === 0) {
24
+ throw new Error(`Tenant scope "${name}" declares no claim columns.`);
25
+ }
26
+ for (const field of fields) {
27
+ if (!claims[field]["_notNull"]) {
28
+ throw new Error(`Claim "${field}" on tenant scope "${name}" must be notNull. ` +
29
+ `A claim column is filled by the runtime on every insert, so it is never null.`);
30
+ }
31
+ }
32
+ this._claims = claims;
33
+ }
34
+ /** The claim field names, in declaration order. */
35
+ get claims() {
36
+ return Object.keys(this._claims);
37
+ }
38
+ /**
39
+ * A fresh copy of every claim column, marked as a claim key and system-managed.
40
+ *
41
+ * Fresh on every call: the builders mutate a `ColumnDefinition` in place, so handing the same
42
+ * instance to two tables would let a later change on one reach the other.
43
+ */
44
+ columns() {
45
+ const columns = {};
46
+ for (const [field, claim] of Object.entries(this._claims)) {
47
+ const column = claim.clone();
48
+ column["_tenantKey"] = true;
49
+ column["_readOnly"] = true;
50
+ columns[field] = column;
51
+ }
52
+ return columns;
53
+ }
54
+ /**
55
+ * A table inside this scope: sugar for spreading {@link columns} into `table(name, { … })`.
56
+ *
57
+ * Use the spread form directly when the table needs a different constructor — a namespaced
58
+ * table is built by `namespace().table()`, which this cannot stand in for.
59
+ */
60
+ table(name, columns) {
61
+ const claims = this.columns();
62
+ for (const field of Object.keys(columns)) {
63
+ if (Object.hasOwn(claims, field)) {
64
+ throw new Error(`Table "${name}" redeclares claim "${field}" from tenant scope "${this.name}". ` +
65
+ `A claim column is declared once, on the scope.`);
66
+ }
67
+ }
68
+ return new TableDefinition(name, {
69
+ columns: { ...claims, ...columns },
70
+ });
71
+ }
72
+ }
73
+ //# sourceMappingURL=tenant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant.js","sourceRoot":"","sources":["../../src/definition/tenant.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,qFAAqF;AACrF,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAoB1C;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,qBAEX,SAAQ,cAAkD;IACjD,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC;IAEjB,OAAO,CAAU;IAElC,YAAY,MAAe,EAAE,OAAe,kBAAkB;QAC5D,KAAK,CAAC,IAAI,CAAC,CAAC;QAEZ,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEnC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,8BAA8B,CAAC,CAAC;QACvE,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC/B,MAAM,IAA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cesContent":["import { Prettify, ReadOnly, TenantKey } from \"../utils/index.js\";\nimport { DefinitionNode, Kind } from \"./base.js\";\nimport { TableColumnDefinitions } from \"./embedded.js\";\nimport { AnyColumnDefinition } from \"./column.js\";\nimport { AnyNamespaceDefinition } from \"./namespace.js\";\nimport { TableDefinition } from \"./table.js\";\n\n/** The name a scope carries when none is given. It names nothing in the database. */\nconst DEFAULT_SCOPE_NAME = \"tenant_scope\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyTenantScopeDefinition = TenantScopeDefinition<any>;\n\n/** The claim columns as a table receives them: system-managed and marked as claim keys. */\nexport type TenantClaimColumns<TClaims extends Record<string, AnyColumnDefinition>> = {\n [K in keyof TClaims]: TenantKey<ReadOnly<TClaims[K]>>;\n};\n\n/** A table's own columns with the scope's claim columns merged in front of them. */\nexport type WithClaims<\n TClaims extends Record<string, AnyColumnDefinition>,\n TColumns extends TableColumnDefinitions,\n> = Prettify<TenantClaimColumns<TClaims> & TColumns>;\n\nexport type TenantScopeConfig<TClaims extends Record<string, AnyColumnDefinition>> = {\n claims: TClaims;\n};\n\n/**\n * A named set of claim columns shared by every table in one tenant boundary.\n *\n * The scope is the only producer of the `tenantKey` marker: a column carries it by being\n * declared here, never by a builder of its own. That is deliberate — a per-column marker would\n * leave no single place that says \"these are the claims\", which is what\n * `ExecutionContext.identity` has to be matched against.\n *\n * It is a definition node so it may be exported from a schema module beside the tables that use\n * it; the registry keeps only tables and relations, and it is not a schema object, so no\n * migration ever sees it.\n */\nexport class TenantScopeDefinition<\n TClaims extends Record<string, AnyColumnDefinition>,\n> extends DefinitionNode<string, TenantScopeConfig<TClaims>> {\n readonly kind = Kind.TENANT_SCOPE;\n\n private readonly _claims: TClaims;\n\n constructor(claims: TClaims, name: string = DEFAULT_SCOPE_NAME) {\n super(name);\n\n const fields = Object.keys(claims);\n\n if (fields.length === 0) {\n throw new Error(`Tenant scope \"${name}\" declares no claim columns.`);\n }\n\n for (const field of fields) {\n if (!claims[field][\"_notNull\"]) {\n throw new Error(\n `Claim \"${field}\" on tenant scope \"${name}\" must be notNull. ` +\n `A claim column is filled by the runtime on every insert, so it is never null.`\n );\n }\n }\n\n this._claims = claims;\n }\n\n /** The claim field names, in declaration order. */\n public get claims(): (keyof TClaims & string)[] {\n return Object.keys(this._claims) as (keyof TClaims & string)[];\n }\n\n /**\n * A fresh copy of every claim column, marked as a claim key and system-managed.\n *\n * Fresh on every call: the builders mutate a `ColumnDefinition` in place, so handing the same\n * instance to two tables would let a later change on one reach the other.\n */\n public columns(): TenantClaimColumns<TClaims> {\n const columns = {} as Record<string, AnyColumnDefinition>;\n\n for (const [field, claim] of Object.entries<AnyColumnDefinition>(this._claims)) {\n const column = claim.clone();\n\n column[\"_tenantKey\"] = true;\n column[\"_readOnly\"] = true;\n\n columns[field] = column;\n }\n\n return columns as TenantClaimColumns<TClaims>;\n }\n\n /**\n * A table inside this scope: sugar for spreading {@link columns} into `table(name, { … })`.\n *\n * Use the spread form directly when the table needs a different constructor — a namespaced\n * table is built by `namespace().table()`, which this cannot stand in for.\n */\n public table<TName extends string, TColumns extends TableColumnDefinitions>(\n name: TName,\n columns: TColumns\n ): TableDefinition<TName, WithClaims<TClaims, TColumns>, AnyNamespaceDefinition> {\n const claims = this.columns() as Record<string, AnyColumnDefinition>;\n\n for (const field of Object.keys(columns)) {\n if (Object.hasOwn(claims, field)) {\n throw new Error(\n `Table \"${name}\" redeclares claim \"${field}\" from tenant scope \"${this.name}\". ` +\n `A claim column is declared once, on the scope.`\n );\n }\n }\n\n return new TableDefinition(name, {\n columns: { ...claims, ...columns } as WithClaims<TClaims, TColumns>,\n });\n }\n}\n"]}
@@ -0,0 +1,84 @@
1
+ import { DefinitionNode } from "./base.js";
2
+ import { AnyColumnDefinition } from "./column.js";
3
+ import { AnyTableDefinition } from "./table.js";
4
+ export type AnyUnionMembers = Record<string, AnyTableDefinition>;
5
+ /** A member's plain columns. A column group is not shared across a union (yet). */
6
+ type PlainColumnsOf<TColumns> = {
7
+ [K in keyof TColumns as TColumns[K] extends AnyColumnDefinition ? K : never]: TColumns[K];
8
+ };
9
+ type MemberColumnsOf<TMembers extends AnyUnionMembers> = {
10
+ [A in keyof TMembers]: PlainColumnsOf<TMembers[A]["__type"]["columns"]>;
11
+ }[keyof TMembers];
12
+ type MemberValueOf<TColumn> = TColumn extends {
13
+ __type: {
14
+ valueType: infer V;
15
+ };
16
+ } ? V : never;
17
+ type ValueUnionOf<TMembers extends AnyUnionMembers, K extends PropertyKey> = {
18
+ [A in keyof TMembers]: MemberValueOf<TMembers[A]["__type"]["columns"][K]>;
19
+ }[keyof TMembers];
20
+ /**
21
+ * The fields every member of a union declares with the same value type.
22
+ *
23
+ * `keyof` over a union of column maps is already the intersection of their keys; a key then
24
+ * survives only when no member's value type is narrower than the union of all of them. The
25
+ * database type cannot be compared here — `dataType` is a runtime string on every column — so
26
+ * the registry repeats the check against it when the client is built.
27
+ */
28
+ export type SharedFieldsOf<TMembers extends AnyUnionMembers> = {
29
+ [K in keyof MemberColumnsOf<TMembers> & string]: {
30
+ [A in keyof TMembers]: [ValueUnionOf<TMembers, K>] extends [
31
+ MemberValueOf<TMembers[A]["__type"]["columns"][K]>
32
+ ] ? never : A;
33
+ }[keyof TMembers] extends never ? K : never;
34
+ }[keyof MemberColumnsOf<TMembers> & string];
35
+ /**
36
+ * A field every member of a union shares, addressed on the union rather than on one member —
37
+ * `posts.columns.userId` in `hasMany(posts, { to: [posts.columns.userId] })`.
38
+ *
39
+ * It names a field, not a database column: members may store the same field under different
40
+ * column names, so `name` is the field alias and `members` holds the real column per member.
41
+ * Typed as the first member's column, which is what every member agrees on.
42
+ */
43
+ export declare class UnionColumnDefinition<TField extends string = string, TColumn extends AnyColumnDefinition = AnyColumnDefinition> extends DefinitionNode<TField, TColumn["__type"]> {
44
+ readonly kind: "UNION_COLUMN";
45
+ readonly members: Readonly<Record<string, AnyColumnDefinition>>;
46
+ constructor(field: TField, members: Record<string, AnyColumnDefinition>);
47
+ }
48
+ export type AnyUnionColumnDefinition = UnionColumnDefinition<string, AnyColumnDefinition>;
49
+ export type UnionColumns<TMembers extends AnyUnionMembers> = {
50
+ readonly [K in SharedFieldsOf<TMembers>]: UnionColumnDefinition<K, TMembers[keyof TMembers]["__type"]["columns"][K]>;
51
+ };
52
+ export type UnionConfig<TMembers extends AnyUnionMembers> = {
53
+ members: TMembers;
54
+ };
55
+ /**
56
+ * A set of tables that can stand in for one another — a GraphQL union or interface.
57
+ *
58
+ * Each member is keyed by its schema alias, which the registry checks when the client is
59
+ * built, because only there are aliases known. A union is not a table and produces no DDL:
60
+ * relations target it, and the client reads it as one `UNION ALL` over its members.
61
+ */
62
+ export declare class UnionDefinition<TMembers extends AnyUnionMembers = AnyUnionMembers> extends DefinitionNode<string, UnionConfig<TMembers>> {
63
+ readonly kind: "UNION";
64
+ readonly members: Readonly<TMembers>;
65
+ /** The shared fields — see {@link SharedFieldsOf}. */
66
+ readonly columns: UnionColumns<TMembers>;
67
+ constructor(members: TMembers);
68
+ /**
69
+ * The fields present on every member with the same `dataType`. A field whose type differs
70
+ * on one member is dropped rather than refused: it is still usable per member through `on`,
71
+ * just not across the union.
72
+ */
73
+ private _buildColumns;
74
+ toJSON(): {
75
+ readonly kind: "UNION";
76
+ readonly name: string;
77
+ readonly members: {
78
+ [k: string]: any;
79
+ };
80
+ };
81
+ }
82
+ export type AnyUnionDefinition = UnionDefinition<any>;
83
+ export {};
84
+ //# sourceMappingURL=union.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/definition/union.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAQ,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAmB,MAAM,YAAY,CAAC;AAEjE,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CA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AE7B,OAAO,EAAE,QAAQ;IAwB7B;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAqCd,MAAM;;;;;;;CASd;AAGD,MAAM,MAAM,kBAAkB,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC"}
@@ -0,0 +1,89 @@
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
+ /**
21
+ * A set of tables that can stand in for one another — a GraphQL union or interface.
22
+ *
23
+ * 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.
26
+ */
27
+ export class UnionDefinition extends DefinitionNode {
28
+ kind = Kind.UNION;
29
+ members;
30
+ /** The shared fields — see {@link SharedFieldsOf}. */
31
+ 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);
80
+ }
81
+ toJSON() {
82
+ return {
83
+ kind: this.kind,
84
+ name: this.name,
85
+ members: Object.fromEntries(Object.entries(this.members).map(([alias, member]) => [alias, member.name])),
86
+ };
87
+ }
88
+ }
89
+ //# sourceMappingURL=union.js.map
@@ -0,0 +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,CAA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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 +1 @@
1
- {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/definition/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,OAAO,cAAqC,SAAQ,cAAqB;IAC7D,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IAE1B,MAAM;QACX,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;SACP,CAAC;IACb,CAAC;CACF"}
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/definition/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,OAAO,cAAqC,SAAQ,cAAqB;IAC7D,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IAE1B,MAAM;QACX,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;SACP,CAAC;IACb,CAAC;CACF","sourcesContent":["import { DefinitionNode, Kind } from \"./base.js\";\n\nexport class ViewDefinition<TName extends string> extends DefinitionNode<TName> {\n public readonly kind = Kind.VIEW;\n\n public toJSON() {\n return {\n kind: this.kind,\n name: this.name,\n } as const;\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { Kind, Relation, defaultCodec, ColumnDefinition, DomainDefinition, IndexDefinition, NamespaceDefinition, SequenceDefinition, TableDefinition, ViewDefinition, RelationsDefinition, DefinitionNode, type AnyColumnDefinition, type AnyDomainDefinition, type AnyFieldRelation, type AnyIndexDefinition, type AnyNamespaceDefinition, type AnyRelationDefinition, type AnyTableDefinition, type AnyTableRelations, type ColumnCodec, type ColumnConfig, type DefinitionSchema, type DomainConfig, type FieldRelation, type IndexConfig, type NodeKind, type RelationsConfig, type RelationType, type TableConfig, type UpdateGuard, } from "./definition/index.js";
2
- export { Column, ExecutionContext, ExecutableQuery, OperationsFactory, QueryBuilder, SchemaRegistry, Table, type AnyColumn, type AnySchema, type AnyTable, type DefinitionRelationsTableName, type DefinitionTableName, type DefinitionTableRelations, type DeleteOperation, type DeleteOperationArgs, type DeleteParams, 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 RuntimeTables, type Schema, type SchemaRelationDefinitions, type SchemaTableDefinitions, type SchemaTableRelations, type SelectOperation, type SelectOperationArgs, type SelectParams, type Session, type TableByNameOrAlias, type TableRelationFieldName, type TransactionSession, type UpdateOperation, type UpdateOperationArgs, type UpdateParams, } from "./runtime/index.js";
3
- export { sql, isSQLNode, SQLQuery, SQLParam, SQLRaw, SQLIdentifier, SQLWrapper, type SQLNode, type SQLStatement, type SQLContext, type SQLValue, } from "./sql/index.js";
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";
4
4
  //# 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,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,WAAW,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,KAAK,EACL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,GAAG,EACH,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,aAAa,EACb,UAAU,EACV,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,QAAQ,GACd,MAAM,gBAAgB,CAAC"}
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,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK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AK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,YAAY,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,GAAG,EACH,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,aAAa,EACb,UAAU,EACV,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,WAAW,GACjB,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { Kind, Relation, defaultCodec, ColumnDefinition, DomainDefinition, IndexDefinition, NamespaceDefinition, SequenceDefinition, TableDefinition, ViewDefinition, RelationsDefinition, DefinitionNode, } from "./definition/index.js";
2
- export { Column, ExecutionContext, ExecutableQuery, OperationsFactory, QueryBuilder, SchemaRegistry, Table, } from "./runtime/index.js";
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
3
  export { sql, isSQLNode, SQLQuery, SQLParam, SQLRaw, SQLIdentifier, SQLWrapper, } from "./sql/index.js";
4
4
  //# 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,cAAc,EACd,mBAAmB,EACnB,cAAc,GAoBf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,KAAK,GAuCN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,GAAG,EACH,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,aAAa,EACb,UAAU,GAKX,MAAM,gBAAgB,CAAC"}
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,24 +1,42 @@
1
- import { AnyTableDefinition, AnyTableRelations, DefinitionSchema, RelationsDefinition, TableDefinition } from "../definition/index.js";
1
+ import { AnyTableDefinition, AnyTableRelations, AnyUnionDefinition, DefinitionSchema, RelationsDefinition, TableDefinition } from "../definition/index.js";
2
+ import { UnionToIntersection } from "../utils/types.js";
2
3
  /**
3
4
  * Schema Definition Types
4
5
  */
5
6
  export type DefinitionTableName<TDefinition extends DefinitionSchema> = {
6
7
  [K in keyof TDefinition]: TDefinition[K] extends AnyTableDefinition ? K : never;
7
8
  }[keyof TDefinition];
9
+ export type DefinitionUnionName<TDefinition extends DefinitionSchema> = {
10
+ [K in keyof TDefinition]: TDefinition[K] extends AnyUnionDefinition ? K : never;
11
+ }[keyof TDefinition];
8
12
  export type DefinitionRelationsTableName<TDefinition extends DefinitionSchema> = {
9
13
  [K in keyof TDefinition]: TDefinition[K] extends RelationsDefinition<infer TableDefinition, infer _> ? TableDefinition extends AnyTableDefinition ? TableDefinition["name"] : never : never;
10
14
  }[keyof TDefinition];
11
- export type DefinitionTableRelations<TDefinition extends DefinitionSchema, TTableName extends string> = 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;
15
+ /**
16
+ * Every relation declared for `TTableName`, as one object.
17
+ *
18
+ * A table may be given several `relations()` blocks — the registry merges them, refusing a
19
+ * name declared twice. Matching the blocks yields one map per block, as a union; `keyof` a
20
+ * union keeps only the keys every member shares, so left as a union a table with two blocks
21
+ * would have no relation names at all. The union is therefore collapsed into the merge the
22
+ * registry performs. A table with no block still yields `never`: the intersection of nothing is
23
+ * `unknown`, which the final check rejects.
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;
12
26
  export type SchemaTableDefinitions<TDefinition extends DefinitionSchema> = {
13
27
  [K in DefinitionTableName<TDefinition>]: TDefinition[K] extends AnyTableDefinition ? TDefinition[K] : never;
14
28
  };
15
29
  export type SchemaRelationDefinitions<T extends DefinitionSchema> = {
16
30
  [K in DefinitionRelationsTableName<T>]: DefinitionTableRelations<T, K>;
17
31
  };
18
- export interface Schema<T extends DefinitionSchema> {
32
+ export type SchemaUnionDefinitions<TDefinition extends DefinitionSchema> = {
33
+ [K in DefinitionUnionName<TDefinition>]: TDefinition[K] extends AnyUnionDefinition ? TDefinition[K] : never;
34
+ };
35
+ export type Schema<T extends DefinitionSchema> = {
19
36
  tables: SchemaTableDefinitions<T>;
20
37
  relations: SchemaRelationDefinitions<T>;
21
- }
38
+ unions: SchemaUnionDefinitions<T>;
39
+ };
22
40
  export type AnySchema = Schema<DefinitionSchema>;
23
41
  /**
24
42
  * Table Relation Types
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/runtime/base.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAEhC;;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,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,MAAM,MAAM,wBAAwB,CAClC,WAAW,SAAS,gBAAgB,EACpC,UAAU,SAAS,MAAM,IAEzB,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,GACzC,GAAG,SAAS,mBAAmB,CAAC,MAAM,MAAM,EAAE,MAAM,CAAC,CAAC,GACpD,MAAM,SAAS,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,GAC3D,CAAC,SAAS,iBAAiB,GACzB,CAAC,GACD,KAAK,GACP,KAAK,GACP,KAAK,GACP,KAAK,CAAC;AAEZ,MAAM,MAAM,sBAAsB,CAAC,WAAW,SAAS,gBAAgB,IAAI;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AAoB,CAAC,OAAO,SAAS,SAAS,EAAE,UAAU,SAAS,MAAM,IACnF,OAAO,CAAC,WAAW,CAAC,SAAS,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,GACpD,CAAC,SAAS,iBAAiB,GACzB,CAAC,GACD,KAAK,GACP,KAAK,CAAC;AAEZ,MAAM,MAAM,sBAAsB,CAChC,OAAO,SAAS,SAAS,EACzB,UAAU,SAAS,MAAM,IACvB,UAAU,SAAS,MAAM,OAAO,CAAC,WAAW,CAAC,GAC7C,OAAO,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,SAAS,iBAAiB,GACxD,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,GACtC,KAAK,GACP,KAAK,CAAC;AAEV,MAAM,MAAM,mBAAmB,CAC7B,OAAO,SAAS,SAAS,EACzB,UAAU,SAAS,MAAM,EACzB,UAAU,SAAS,MAAM,IACvB,UAAU,SAAS,MAAM,OAAO,CAAC,WAAW,CAAC,GAC7C,OAAO,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,SAAS,iBAAiB,GACxD,UAAU,SAAS,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,GACvD,OAAO,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,GAC5C,KAAK,GACP,KAAK,GACP,KAAK,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/runtime/base.ts"],"names":[],"mappings":"AAAA,sDAAsD"}
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} 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,22 +1,73 @@
1
1
  import { TypedObject } from "../utils/index.js";
2
- import { ColumnConfig, ColumnDefinition } from "../definition/index.js";
2
+ import { ColumnConfig, ColumnDefinition, ColumnRuntimeType } from "../definition/index.js";
3
3
  import { SQLContext, SQLNode, SQLParam, SQLStatement } from "../sql/index.js";
4
4
  import { AnyTable } from "./table.js";
5
5
  export type AnyColumn = Column<any, any, any>;
6
+ /** See {@link Column.rowDecoder}. */
7
+ export type ColumnRowDecoder = {
8
+ /** Columns of the same table the decode reads; projected alongside this one. */
9
+ readonly dependsOn: AnyColumn[];
10
+ /** The value from the column's raw value and the raw row it was read from, keyed by column name. */
11
+ decode(raw: unknown, row: Record<string, unknown>): unknown;
12
+ };
6
13
  export declare class Column<TName extends string, TConfig extends ColumnConfig, TTable extends AnyTable> implements SQLNode, TypedObject<TConfig> {
7
14
  readonly __type: TConfig;
8
15
  readonly codec: ColumnDefinition<TName, TConfig>["_codec"];
16
+ /** Checks writes before they are encoded and reads after they are decoded; never filters. */
17
+ readonly validator: ColumnDefinition<TName, TConfig>["_validator"];
9
18
  readonly onCreate: ColumnDefinition<TName, TConfig>["_onCreate"];
10
19
  readonly onUpdate: ColumnDefinition<TName, TConfig>["_onUpdate"];
11
20
  readonly table: TTable;
12
21
  readonly name: TName;
22
+ /** The database type, or the domain's name for a domain column. */
23
+ readonly dataType: string;
24
+ /** The kind of value the column holds, for querying; see {@link ColumnRuntimeType}. */
25
+ readonly runtimeType: ColumnRuntimeType;
26
+ /**
27
+ * Whether a JSON projection (a joined row, a union row) must carry this column as text. The
28
+ * driver hands a root read of `bigint` and `numeric` to the codec as the database's exact
29
+ * text; `row_to_json` would emit a JSON number, already rounded to a double before the codec
30
+ * sees it. Cast, the codec gets the same string either way.
31
+ */
32
+ readonly textInJson: boolean;
13
33
  readonly notNull: TConfig["notNull"];
14
34
  readonly primaryKey: TConfig["primaryKey"];
15
35
  readonly unique: TConfig["unique"];
36
+ readonly readOnly: TConfig["readOnly"];
37
+ readonly tenantKey: TConfig["tenantKey"];
16
38
  constructor(table: TTable, definition: ColumnDefinition<TName, TConfig>);
39
+ /**
40
+ * A decode that needs more than the column's own value — sibling columns of the same row.
41
+ *
42
+ * Unset by default; a client sets it on the built column when it is created, as it does a
43
+ * bound codec, for a value whose meaning depends on another column (a polymorphic reference
44
+ * whose target is named by a discriminator). When set, `dependsOn` is projected whenever this
45
+ * column is selected, and the value is read through {@link Column.resolveRow} instead of
46
+ * {@link Column.resolve}. Core applies no meaning to it.
47
+ */
48
+ readonly rowDecoder?: ColumnRowDecoder;
49
+ /** Reads this column's value from a whole row, through {@link Column.rowDecoder} if set. */
50
+ resolveRow(row: Record<string, unknown>): TConfig["valueType"];
17
51
  resolve(value: TConfig["rawType"]): TConfig["valueType"];
18
- getInsertValue(value: TConfig["valueType"] | SQLParam<TConfig["valueType"]> | null | undefined): SQLNode;
19
- getUpdateValue(value: TConfig["valueType"] | SQLParam<TConfig["valueType"]> | null | undefined): SQLNode;
52
+ private _validateRead;
53
+ /** A write's value as sent: validated, if the column has a validator, then encoded. */
54
+ private readonly _encodeInput;
55
+ /**
56
+ * Wraps a value as a parameter encoded by this column's codec. It is not validated: a filter
57
+ * value is compared with stored values, not stored, and may be a fragment of one.
58
+ *
59
+ * This is the filter counterpart to {@link Column.getInsertValue} and
60
+ * {@link Column.getUpdateValue}: a `date`, `bigint` or `interval` column only matches if
61
+ * the value on the wire is written the same way it was stored. A value that is already an
62
+ * `SQLNode` — another column, a sub-expression — is passed through untouched, since it is
63
+ * SQL rather than a value to encode.
64
+ *
65
+ * Also the way to filter by a codec column in raw `$query`:
66
+ * ``sql`${users.columns.createdAt} > ${users.columns.createdAt.param(cutoff)}` ``
67
+ */
68
+ param(value: TConfig["valueType"] | SQLNode): SQLNode;
69
+ getInsertValue(value: TConfig["inputType"] | SQLParam<TConfig["inputType"]> | null | undefined): SQLNode;
70
+ getUpdateValue(value: TConfig["inputType"] | SQLParam<TConfig["inputType"]> | null | undefined): SQLNode;
20
71
  toSQL(ctx: SQLContext): SQLStatement;
21
72
  }
22
73
  //# sourceMappingURL=column.d.ts.map