@dsqlbase/core 0.1.6 → 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 +195 -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":"column.d.ts","sourceRoot":"","sources":["../../src/runtime/column.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAkB,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAE9C,qBAAa,MAAM,CAAC,KAAK,SAAS,MAAM,EAAE,OAAO,SAAS,YAAY,EAAE,MAAM,SAAS,QAAQ,CAC7F,YAAW,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC;IAExC,SAAiB,MAAM,EAAE,OAAO,CAAC;IAEjC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC3D,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC;IACjE,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC;IAEjE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,SA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C,WAAW,CAAC,CAAC;gBAE7B,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC;IAmBvE;;;;;;;;OAQG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAEvC,4FAA4F;IACrF,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAU9D,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAY/D,OAAO,CAAC,aAAa;IAIrB,uFAAuF;IACvF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAC6C;IAE1E;;;;;;;;;;;;OAYG;IACI,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,GAAG,OAAO;IAQrD,cAAc,CACnB,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAgB/D,OAAO;IAGzB,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAgB5E,OAAO;IAGzB,KAAK,CAAC,GAAG,EAAE,UAAU,GAAG,YAAY;CAMrC"}
@@ -1,23 +1,63 @@
1
1
  import { SQLParam, isSQLNode, sql } from "../sql/index.js";
2
2
  export class Column {
3
3
  codec;
4
+ /** Checks writes before they are encoded and reads after they are decoded; never filters. */
5
+ validator;
4
6
  onCreate;
5
7
  onUpdate;
6
8
  table;
7
9
  name;
10
+ /** The database type, or the domain's name for a domain column. */
11
+ dataType;
12
+ /** The kind of value the column holds, for querying; see {@link ColumnRuntimeType}. */
13
+ runtimeType;
14
+ /**
15
+ * Whether a JSON projection (a joined row, a union row) must carry this column as text. The
16
+ * driver hands a root read of `bigint` and `numeric` to the codec as the database's exact
17
+ * text; `row_to_json` would emit a JSON number, already rounded to a double before the codec
18
+ * sees it. Cast, the codec gets the same string either way.
19
+ */
20
+ textInJson;
8
21
  notNull;
9
22
  primaryKey;
10
23
  unique;
24
+ readOnly;
25
+ tenantKey;
11
26
  constructor(table, definition) {
12
27
  this.table = table;
13
28
  this.name = definition.name;
29
+ this.dataType = definition["_dataType"];
30
+ this.runtimeType = definition["_runtimeType"];
31
+ this.textInJson =
32
+ this.runtimeType === "bigint" || /^(bigint|int8|numeric|decimal)\b/i.test(this.dataType);
14
33
  this.notNull = definition["_notNull"];
15
34
  this.primaryKey = definition["_primaryKey"];
16
35
  this.unique = definition["_unique"];
36
+ this.readOnly = definition["_readOnly"];
37
+ this.tenantKey = definition["_tenantKey"];
17
38
  this.codec = definition["_codec"];
39
+ this.validator = definition["_validator"];
18
40
  this.onCreate = definition["_onCreate"];
19
41
  this.onUpdate = definition["_onUpdate"];
20
42
  }
43
+ /**
44
+ * A decode that needs more than the column's own value — sibling columns of the same row.
45
+ *
46
+ * Unset by default; a client sets it on the built column when it is created, as it does a
47
+ * bound codec, for a value whose meaning depends on another column (a polymorphic reference
48
+ * whose target is named by a discriminator). When set, `dependsOn` is projected whenever this
49
+ * column is selected, and the value is read through {@link Column.resolveRow} instead of
50
+ * {@link Column.resolve}. Core applies no meaning to it.
51
+ */
52
+ rowDecoder;
53
+ /** Reads this column's value from a whole row, through {@link Column.rowDecoder} if set. */
54
+ resolveRow(row) {
55
+ const raw = row[this.name];
56
+ if (!this.rowDecoder || raw === null || raw === undefined) {
57
+ return this.resolve(raw);
58
+ }
59
+ return this._validateRead(this.rowDecoder.decode(raw, row));
60
+ }
21
61
  resolve(value) {
22
62
  if (value === null || value === undefined) {
23
63
  if (this.notNull) {
@@ -25,7 +65,31 @@ export class Column {
25
65
  }
26
66
  return null;
27
67
  }
28
- return this.codec.decode(value);
68
+ return this._validateRead(this.codec.decode(value));
69
+ }
70
+ _validateRead(value) {
71
+ return this.validator ? this.validator.read(value) : value;
72
+ }
73
+ /** A write's value as sent: validated, if the column has a validator, then encoded. */
74
+ _encodeInput = (input) => this.codec.encode(this.validator ? this.validator.write(input) : input);
75
+ /**
76
+ * Wraps a value as a parameter encoded by this column's codec. It is not validated: a filter
77
+ * value is compared with stored values, not stored, and may be a fragment of one.
78
+ *
79
+ * This is the filter counterpart to {@link Column.getInsertValue} and
80
+ * {@link Column.getUpdateValue}: a `date`, `bigint` or `interval` column only matches if
81
+ * the value on the wire is written the same way it was stored. A value that is already an
82
+ * `SQLNode` — another column, a sub-expression — is passed through untouched, since it is
83
+ * SQL rather than a value to encode.
84
+ *
85
+ * Also the way to filter by a codec column in raw `$query`:
86
+ * ``sql`${users.columns.createdAt} > ${users.columns.createdAt.param(cutoff)}` ``
87
+ */
88
+ param(value) {
89
+ if (isSQLNode(value)) {
90
+ return value;
91
+ }
92
+ return new SQLParam(value, this.codec.encode);
29
93
  }
30
94
  getInsertValue(value) {
31
95
  let param = value ?? undefined;
@@ -33,10 +97,10 @@ export class Column {
33
97
  param = this.onCreate?.() ?? sql.raw("DEFAULT");
34
98
  }
35
99
  if (param instanceof SQLParam) {
36
- param = new SQLParam(param["_value"], this.codec.encode);
100
+ param = new SQLParam(param["_value"], this._encodeInput);
37
101
  }
38
102
  if (!isSQLNode(param)) {
39
- param = new SQLParam(param, this.codec.encode);
103
+ param = new SQLParam(param, this._encodeInput);
40
104
  }
41
105
  return param;
42
106
  }
@@ -46,15 +110,19 @@ export class Column {
46
110
  param = this.onUpdate?.() ?? undefined;
47
111
  }
48
112
  if (param instanceof SQLParam) {
49
- param = new SQLParam(param["_value"], this.codec.encode);
113
+ param = new SQLParam(param["_value"], this._encodeInput);
50
114
  }
51
- if (value !== undefined && !isSQLNode(param)) {
52
- param = new SQLParam(param, this.codec.encode);
115
+ // `param`, not `value`: an `$onUpdate` result is a value to validate and encode as well.
116
+ if (param !== undefined && !isSQLNode(param)) {
117
+ param = new SQLParam(param, this._encodeInput);
53
118
  }
54
119
  return param;
55
120
  }
56
121
  toSQL(ctx) {
57
- return sql.join([sql.identifier(this.table.name), sql.identifier(this.name)], ".").toSQL(ctx);
122
+ // The table decides how it is named here: an alias when one is bound for it in this
123
+ // scope, otherwise its plain name. Outside a select tree nothing is bound, so this
124
+ // renders `"table"."column"` exactly as it always has.
125
+ return sql.join([this.table.ref(), sql.identifier(this.name)], ".").toSQL(ctx);
58
126
  }
59
127
  }
60
128
  //# sourceMappingURL=column.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"column.js","sourceRoot":"","sources":["../../src/runtime/column.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,QAAQ,EAAgB,SAAS,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAM9F,MAAM,OAAO,MAAM;IAKR,KAAK,CAA6C;IAClD,QAAQ,CAAgD;IACxD,QAAQ,CAAgD;IAExD,KAAK,CAAS;IACd,IAAI,CAAQ;IACZ,OAAO,CAAqB;IAC5B,UAAU,CAAwB;IAClC,MAAM,CAAoB;IAEnC,YAAY,KAAa,EAAE,UAA4C;QACrE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;QACtC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;QAEpC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;IAEM,OAAO,CAAC,KAAyB;QACtC,IAAI,KAAK,KAAK,IAAI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C3D,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,KAAK,GAAG,IAAI,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,KAAgB,CAAC;IAC1B,CAAC;IAED,cAAc,CAAC,KAA+E;QAC5F,IAAI,KAAK,GAAG,KAAK,CAAC;QAElB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,SAAS,CAAC;QACzC,CAAC;QAED,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;YAC9B,KAAK,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3D,CAAC;QAED,yFAAyF;QACzF,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7C,KAAK,GAAG,IAAI,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,KAAgB,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,GAAe;QACnB,oFAAoF;QACpF,mFAAmF;QACnF,uDAAuD;QACvD,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjF,CAAC;CACF","sourcesContent":["import { TypedObject } from \"../utils/index.js\";\nimport { ColumnConfig, ColumnDefinition, ColumnRuntimeType } from \"../definition/index.js\";\nimport { SQLContext, SQLNode, SQLParam, SQLStatement, isSQLNode, sql } from \"../sql/index.js\";\nimport { AnyTable } from \"./table.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyColumn = Column<any, any, any>;\n\n/** See {@link Column.rowDecoder}. */\nexport type ColumnRowDecoder = {\n /** Columns of the same table the decode reads; projected alongside this one. */\n readonly dependsOn: AnyColumn[];\n /** The value from the column's raw value and the raw row it was read from, keyed by column name. */\n decode(raw: unknown, row: Record<string, unknown>): unknown;\n};\n\nexport class Column<TName extends string, TConfig extends ColumnConfig, TTable extends AnyTable>\n implements SQLNode, TypedObject<TConfig>\n{\n declare readonly __type: TConfig;\n\n readonly codec: ColumnDefinition<TName, TConfig>[\"_codec\"];\n /** Checks writes before they are encoded and reads after they are decoded; never filters. */\n readonly validator: ColumnDefinition<TName, TConfig>[\"_validator\"];\n readonly onCreate: ColumnDefinition<TName, TConfig>[\"_onCreate\"];\n readonly onUpdate: ColumnDefinition<TName, TConfig>[\"_onUpdate\"];\n\n readonly table: TTable;\n readonly name: TName;\n /** The database type, or the domain's name for a domain column. */\n readonly dataType: string;\n /** The kind of value the column holds, for querying; see {@link ColumnRuntimeType}. */\n readonly runtimeType: ColumnRuntimeType;\n /**\n * Whether a JSON projection (a joined row, a union row) must carry this column as text. The\n * driver hands a root read of `bigint` and `numeric` to the codec as the database's exact\n * text; `row_to_json` would emit a JSON number, already rounded to a double before the codec\n * sees it. Cast, the codec gets the same string either way.\n */\n readonly textInJson: boolean;\n readonly notNull: TConfig[\"notNull\"];\n readonly primaryKey: TConfig[\"primaryKey\"];\n readonly unique: TConfig[\"unique\"];\n readonly readOnly: TConfig[\"readOnly\"];\n readonly tenantKey: TConfig[\"tenantKey\"];\n\n constructor(table: TTable, definition: ColumnDefinition<TName, TConfig>) {\n this.table = table;\n this.name = definition.name;\n this.dataType = definition[\"_dataType\"];\n this.runtimeType = definition[\"_runtimeType\"];\n this.textInJson =\n this.runtimeType === \"bigint\" || /^(bigint|int8|numeric|decimal)\\b/i.test(this.dataType);\n this.notNull = definition[\"_notNull\"];\n this.primaryKey = definition[\"_primaryKey\"];\n this.unique = definition[\"_unique\"];\n this.readOnly = definition[\"_readOnly\"];\n this.tenantKey = definition[\"_tenantKey\"];\n\n this.codec = definition[\"_codec\"];\n this.validator = definition[\"_validator\"];\n this.onCreate = definition[\"_onCreate\"];\n this.onUpdate = definition[\"_onUpdate\"];\n }\n\n /**\n * A decode that needs more than the column's own value — sibling columns of the same row.\n *\n * Unset by default; a client sets it on the built column when it is created, as it does a\n * bound codec, for a value whose meaning depends on another column (a polymorphic reference\n * whose target is named by a discriminator). When set, `dependsOn` is projected whenever this\n * column is selected, and the value is read through {@link Column.resolveRow} instead of\n * {@link Column.resolve}. Core applies no meaning to it.\n */\n readonly rowDecoder?: ColumnRowDecoder;\n\n /** Reads this column's value from a whole row, through {@link Column.rowDecoder} if set. */\n public resolveRow(row: Record<string, unknown>): TConfig[\"valueType\"] {\n const raw = row[this.name];\n\n if (!this.rowDecoder || raw === null || raw === undefined) {\n return this.resolve(raw as TConfig[\"rawType\"]);\n }\n\n return this._validateRead(this.rowDecoder.decode(raw, row) as TConfig[\"valueType\"]);\n }\n\n public resolve(value: TConfig[\"rawType\"]): TConfig[\"valueType\"] {\n if (value === null || value === undefined) {\n if (this.notNull) {\n throw new Error(`Column ${this.name} cannot be null`);\n }\n\n return null;\n }\n\n return this._validateRead(this.codec.decode(value));\n }\n\n private _validateRead(value: TConfig[\"valueType\"]): TConfig[\"valueType\"] {\n return this.validator ? this.validator.read(value) : value;\n }\n\n /** A write's value as sent: validated, if the column has a validator, then encoded. */\n private readonly _encodeInput = (input: TConfig[\"inputType\"]): TConfig[\"rawType\"] =>\n this.codec.encode(this.validator ? this.validator.write(input) : input);\n\n /**\n * Wraps a value as a parameter encoded by this column's codec. It is not validated: a filter\n * value is compared with stored values, not stored, and may be a fragment of one.\n *\n * This is the filter counterpart to {@link Column.getInsertValue} and\n * {@link Column.getUpdateValue}: a `date`, `bigint` or `interval` column only matches if\n * the value on the wire is written the same way it was stored. A value that is already an\n * `SQLNode` — another column, a sub-expression — is passed through untouched, since it is\n * SQL rather than a value to encode.\n *\n * Also the way to filter by a codec column in raw `$query`:\n * ``sql`${users.columns.createdAt} > ${users.columns.createdAt.param(cutoff)}` ``\n */\n public param(value: TConfig[\"valueType\"] | SQLNode): SQLNode {\n if (isSQLNode(value)) {\n return value;\n }\n\n return new SQLParam(value, this.codec.encode);\n }\n\n public getInsertValue(\n value: TConfig[\"inputType\"] | SQLParam<TConfig[\"inputType\"]> | null | undefined\n ) {\n let param = value ?? undefined;\n\n if (param === undefined) {\n param = this.onCreate?.() ?? sql.raw(\"DEFAULT\");\n }\n\n if (param instanceof SQLParam) {\n param = new SQLParam(param[\"_value\"], this._encodeInput);\n }\n\n if (!isSQLNode(param)) {\n param = new SQLParam(param, this._encodeInput);\n }\n\n return param as SQLNode;\n }\n\n getUpdateValue(value: TConfig[\"inputType\"] | SQLParam<TConfig[\"inputType\"]> | null | undefined) {\n let param = value;\n\n if (param === undefined) {\n param = this.onUpdate?.() ?? undefined;\n }\n\n if (param instanceof SQLParam) {\n param = new SQLParam(param[\"_value\"], this._encodeInput);\n }\n\n // `param`, not `value`: an `$onUpdate` result is a value to validate and encode as well.\n if (param !== undefined && !isSQLNode(param)) {\n param = new SQLParam(param, this._encodeInput);\n }\n\n return param as SQLNode;\n }\n\n toSQL(ctx: SQLContext): SQLStatement {\n // The table decides how it is named here: an alias when one is bound for it in this\n // scope, otherwise its plain name. Outside a select tree nothing is bound, so this\n // renders `\"table\".\"column\"` exactly as it always has.\n return sql.join([this.table.ref(), sql.identifier(this.name)], \".\").toSQL(ctx);\n }\n}\n"]}
@@ -5,17 +5,45 @@ import { Schema } from "./base.js";
5
5
  import { Session } from "./session.js";
6
6
  import { SchemaRegistry } from "./registry.js";
7
7
  import { OperationsFactory } from "./operation.js";
8
- export interface ExecutionContextOptions<TSchema extends DefinitionSchema> {
8
+ /** How a tenant table behaves on a client that carries no identity. */
9
+ export type TenancyOptions = {
10
+ /**
11
+ * Refuse to build an operation on a tenant table when there are no claims to scope it with.
12
+ * On by default: a query that silently runs unscoped is the bug this exists to prevent.
13
+ */
14
+ enforce?: boolean;
15
+ };
16
+ /** Page-size bounds for keyset pagination. Carried here for the client; core reads neither. */
17
+ export type PaginationOptions = {
18
+ /** The page size when a call names none. */
19
+ defaultLimit?: number;
20
+ /** The largest page size a call may ask for. Unbounded when absent. */
21
+ maxLimit?: number;
22
+ };
23
+ export type ExecutionContextOptions<TSchema extends DefinitionSchema> = {
9
24
  session: Session;
10
25
  dialect: QueryBuilder;
11
26
  schema: SchemaRegistry<TSchema>;
12
- }
27
+ /**
28
+ * The claims every tenant table on this context is scoped to, keyed by claim name.
29
+ *
30
+ * Absent on a base client and set once by `$identityClaims`, which builds a derived context
31
+ * rather than mutating this one — the reason a scoped and an unscoped client can coexist in
32
+ * one process, and why a query's SQL is fixed by the client that built it.
33
+ */
34
+ identity?: Record<string, unknown>;
35
+ tenancy?: TenancyOptions;
36
+ pagination?: PaginationOptions;
37
+ };
13
38
  export declare class ExecutionContext<TDefinition extends DefinitionSchema = DefinitionSchema> implements TypedObject<Schema<TDefinition>> {
14
39
  readonly __type: Schema<TDefinition>;
15
40
  readonly session: Session;
16
41
  readonly dialect: QueryBuilder;
17
42
  readonly schema: SchemaRegistry<TDefinition>;
18
43
  readonly operations: OperationsFactory<Schema<TDefinition>>;
44
+ readonly identity?: Record<string, unknown>;
45
+ readonly tenancy: Required<TenancyOptions>;
46
+ readonly pagination?: PaginationOptions;
19
47
  constructor(options: ExecutionContextOptions<TDefinition>);
20
48
  }
21
49
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/runtime/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;A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AAW,CAAC;CAS1D"}
@@ -4,10 +4,16 @@ export class ExecutionContext {
4
4
  dialect;
5
5
  schema;
6
6
  operations;
7
+ identity;
8
+ tenancy;
9
+ pagination;
7
10
  constructor(options) {
8
11
  this.session = options.session;
9
12
  this.dialect = options.dialect;
10
13
  this.schema = options.schema;
14
+ this.identity = options.identity;
15
+ this.tenancy = { enforce: options.tenancy?.enforce ?? true };
16
+ this.pagination = options.pagination;
11
17
  this.operations = new OperationsFactory(this);
12
18
  }
13
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/runtime/context.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAQnD,MAAM,OAAO,gBAAgB;IAKlB,OAAO,CAAU;IACjB,OAAO,CAAe;IACtB,MAAM,CAA8B;IACpC,UAAU,CAAyC;IAE5D,YAAY,OAA6C;QACvD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CAAsB,IAAI,CAAC,CAAC;IACrE,CAAC;CACF"}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/runtime/context.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAsCnD,MAAM,OAAO,gBAAgB;IAKlB,OAAO,CAAU;IACjB,OAAO,CAAe;IACtB,MAAM,CAA8B;IACpC,UAAU,CAAyC;IACnD,QAAQ,CAA2B;IACnC,OAAO,CAA2B;IAClC,UAAU,CAAqB;IAExC,YAAY,OAA6C;QACvD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,CAAC;QAC7D,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CAAsB,IAAI,CAAC,CAAC;IACrE,CAAC;CACF","sourcesContent":["import { TypedObject } from \"../utils/index.js\";\nimport { DefinitionSchema } from \"../definition/index.js\";\nimport { QueryBuilder } from \"./query.js\";\nimport { Schema } from \"./base.js\";\nimport { Session } from \"./session.js\";\nimport { SchemaRegistry } from \"./registry.js\";\nimport { OperationsFactory } from \"./operation.js\";\n\n/** How a tenant table behaves on a client that carries no identity. */\nexport type TenancyOptions = {\n /**\n * Refuse to build an operation on a tenant table when there are no claims to scope it with.\n * On by default: a query that silently runs unscoped is the bug this exists to prevent.\n */\n enforce?: boolean;\n};\n\n/** Page-size bounds for keyset pagination. Carried here for the client; core reads neither. */\nexport type PaginationOptions = {\n /** The page size when a call names none. */\n defaultLimit?: number;\n /** The largest page size a call may ask for. Unbounded when absent. */\n maxLimit?: number;\n};\n\nexport type ExecutionContextOptions<TSchema extends DefinitionSchema> = {\n session: Session;\n dialect: QueryBuilder;\n schema: SchemaRegistry<TSchema>;\n\n /**\n * The claims every tenant table on this context is scoped to, keyed by claim name.\n *\n * Absent on a base client and set once by `$identityClaims`, which builds a derived context\n * rather than mutating this one — the reason a scoped and an unscoped client can coexist in\n * one process, and why a query's SQL is fixed by the client that built it.\n */\n identity?: Record<string, unknown>;\n\n tenancy?: TenancyOptions;\n\n pagination?: PaginationOptions;\n};\n\nexport class ExecutionContext<\n TDefinition extends DefinitionSchema = DefinitionSchema,\n> implements TypedObject<Schema<TDefinition>> {\n declare readonly __type: Schema<TDefinition>;\n\n readonly session: Session;\n readonly dialect: QueryBuilder;\n readonly schema: SchemaRegistry<TDefinition>;\n readonly operations: OperationsFactory<Schema<TDefinition>>;\n readonly identity?: Record<string, unknown>;\n readonly tenancy: Required<TenancyOptions>;\n readonly pagination?: PaginationOptions;\n\n constructor(options: ExecutionContextOptions<TDefinition>) {\n this.session = options.session;\n this.dialect = options.dialect;\n this.schema = options.schema;\n this.identity = options.identity;\n this.tenancy = { enforce: options.tenancy?.enforce ?? true };\n this.pagination = options.pagination;\n this.operations = new OperationsFactory<Schema<TDefinition>>(this);\n }\n}\n"]}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A tenant boundary was crossed, or could not be established.
3
+ *
4
+ * Thrown when an operation is *built* — when `findMany()` is called, not when the query is
5
+ * executed — so a missing identity surfaces before anything reaches the database.
6
+ */
7
+ export declare class TenancyError extends Error {
8
+ /** The table whose tenant boundary could not be satisfied, when one table in particular is. */
9
+ readonly table?: string;
10
+ /** The claim that was missing, when one claim in particular was. */
11
+ readonly claim?: string;
12
+ constructor(message: string, table?: string, claim?: string);
13
+ }
14
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/runtime/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,+FAA+F;IAC/F,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAExB,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAO5D"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A tenant boundary was crossed, or could not be established.
3
+ *
4
+ * Thrown when an operation is *built* — when `findMany()` is called, not when the query is
5
+ * executed — so a missing identity surfaces before anything reaches the database.
6
+ */
7
+ export class TenancyError extends Error {
8
+ /** The table whose tenant boundary could not be satisfied, when one table in particular is. */
9
+ table;
10
+ /** The claim that was missing, when one claim in particular was. */
11
+ claim;
12
+ constructor(message, table, claim) {
13
+ super(message);
14
+ this.name = "TenancyError";
15
+ this.table = table;
16
+ this.claim = claim;
17
+ }
18
+ }
19
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/runtime/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,+FAA+F;IACtF,KAAK,CAAU;IAExB,oEAAoE;IAC3D,KAAK,CAAU;IAExB,YAAY,OAAe,EAAE,KAAc,EAAE,KAAc;QACzD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF","sourcesContent":["/**\n * A tenant boundary was crossed, or could not be established.\n *\n * Thrown when an operation is *built* — when `findMany()` is called, not when the query is\n * executed — so a missing identity surfaces before anything reaches the database.\n */\nexport class TenancyError extends Error {\n /** The table whose tenant boundary could not be satisfied, when one table in particular is. */\n readonly table?: string;\n\n /** The claim that was missing, when one claim in particular was. */\n readonly claim?: string;\n\n constructor(message: string, table?: string, claim?: string) {\n super(message);\n\n this.name = \"TenancyError\";\n this.table = table;\n this.claim = claim;\n }\n}\n"]}
@@ -1,7 +1,17 @@
1
1
  import { Thenable } from "../utils/thenable.js";
2
2
  import { AnyOperation } from "./operation.js";
3
3
  import { Session } from "./session.js";
4
- export declare class ExecutableQuery<TResult> extends Thenable<TResult> {
4
+ /**
5
+ * Anything a client hands back that runs when awaited, and can be re-bound to another session.
6
+ *
7
+ * `$transaction([...])` batches over this rather than over `ExecutableQuery`, so a result built
8
+ * from several statements batches the same way a single statement does.
9
+ */
10
+ export type Executable<TResult> = {
11
+ execute(): Promise<TResult>;
12
+ clone(session: Session): Executable<TResult>;
13
+ } & PromiseLike<TResult>;
14
+ export declare class ExecutableQuery<TResult> extends Thenable<TResult> implements Executable<TResult> {
5
15
  readonly $typeOf: TResult;
6
16
  private readonly _operation;
7
17
  private readonly _session;
@@ -9,4 +19,22 @@ export declare class ExecutableQuery<TResult> extends Thenable<TResult> {
9
19
  execute(): Promise<TResult>;
10
20
  clone(session: Session): ExecutableQuery<TResult>;
11
21
  }
22
+ type ResultsOf<TParts extends readonly Executable<unknown>[]> = {
23
+ -readonly [K in keyof TParts]: Awaited<TParts[K]>;
24
+ };
25
+ /**
26
+ * Several executables run together and combined into one result.
27
+ *
28
+ * The parts run concurrently. On a pool session each may take its own connection, so their
29
+ * snapshots can differ; re-bound to a transaction session by `clone`, they share one.
30
+ */
31
+ export declare class CompositeQuery<TParts extends readonly Executable<unknown>[], TResult> extends Thenable<TResult> implements Executable<TResult> {
32
+ readonly $typeOf: TResult;
33
+ private readonly _parts;
34
+ private readonly _combine;
35
+ constructor(parts: TParts, combine: (results: ResultsOf<TParts>) => TResult);
36
+ execute(): Promise<TResult>;
37
+ clone(session: Session): CompositeQuery<TParts, TResult>;
38
+ }
39
+ export {};
12
40
  //# sourceMappingURL=executor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/runtime/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,qBAAa,eAAe,CAAC,OAAO,CAAE,SAAQ,QAAQ,CAAC,OAAO,CAAC;IAC7D,SAAiB,OAAO,EAAE,OAAO,CAAC;IAElC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,Q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;GAKG;AACH,qBAAa,cAAc,CAAC,MAAM,SAAS,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAChF,SAAQ,QAAQ,CAAC,OAAO,CACxB,YAAW,UAAU,CAAC,OAAO,CAAC;IAE9B,SAAiB,OAAO,EAAE,OAAO,CAAC;IAElC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0C;gBAEvD,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,OAAO;IAO9D,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAKjC,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC;CAIhE"}
@@ -15,4 +15,27 @@ export class ExecutableQuery extends Thenable {
15
15
  return new ExecutableQuery(this._operation, session);
16
16
  }
17
17
  }
18
+ /**
19
+ * Several executables run together and combined into one result.
20
+ *
21
+ * The parts run concurrently. On a pool session each may take its own connection, so their
22
+ * snapshots can differ; re-bound to a transaction session by `clone`, they share one.
23
+ */
24
+ export class CompositeQuery extends Thenable {
25
+ _parts;
26
+ _combine;
27
+ constructor(parts, combine) {
28
+ super();
29
+ this._parts = parts;
30
+ this._combine = combine;
31
+ }
32
+ async execute() {
33
+ const results = await Promise.all(this._parts.map((part) => part.execute()));
34
+ return this._combine(results);
35
+ }
36
+ clone(session) {
37
+ const parts = this._parts.map((part) => part.clone(session));
38
+ return new CompositeQuery(parts, this._combine);
39
+ }
40
+ }
18
41
  //# sourceMappingURL=executor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/runtime/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIhD,MAAM,OAAO,eAAyB,SAAQ,QAAiB;IAG5C,UAAU,CAAe;IACzB,QAA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IAKR,MAAM,CAAS;IACf,QAAQ,CAA0C;IAEnE,YAAY,KAAa,EAAE,OAAgD;QACzE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC7E,OAAO,IAAI,CAAC,QAAQ,CAAC,OAA4B,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,OAAgB;QAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAsB,CAAC;QAClF,OAAO,IAAI,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import { Thenable } from \"../utils/thenable.js\";\nimport { AnyOperation } from \"./operation.js\";\nimport { Session } from \"./session.js\";\n\n/**\n * Anything a client hands back that runs when awaited, and can be re-bound to another session.\n *\n * `$transaction([...])` batches over this rather than over `ExecutableQuery`, so a result built\n * from several statements batches the same way a single statement does.\n */\nexport type Executable<TResult> = {\n execute(): Promise<TResult>;\n clone(session: Session): Executable<TResult>;\n} & PromiseLike<TResult>;\n\nexport class ExecutableQuery<TResult> extends Thenable<TResult> implements Executable<TResult> {\n declare readonly $typeOf: TResult;\n\n private readonly _operation: AnyOperation;\n private readonly _session: Session;\n\n constructor(operation: AnyOperation, session: Session) {\n super();\n\n this._operation = operation;\n this._session = session;\n }\n\n public async execute(): Promise<TResult> {\n const result = await this._session.execute(this._operation.query);\n return this._operation.resolve(result) as TResult;\n }\n\n public clone(session: Session): ExecutableQuery<TResult> {\n return new ExecutableQuery(this._operation, session);\n }\n}\n\ntype ResultsOf<TParts extends readonly Executable<unknown>[]> = {\n -readonly [K in keyof TParts]: Awaited<TParts[K]>;\n};\n\n/**\n * Several executables run together and combined into one result.\n *\n * The parts run concurrently. On a pool session each may take its own connection, so their\n * snapshots can differ; re-bound to a transaction session by `clone`, they share one.\n */\nexport class CompositeQuery<TParts extends readonly Executable<unknown>[], TResult>\n extends Thenable<TResult>\n implements Executable<TResult>\n{\n declare readonly $typeOf: TResult;\n\n private readonly _parts: TParts;\n private readonly _combine: (results: ResultsOf<TParts>) => TResult;\n\n constructor(parts: TParts, combine: (results: ResultsOf<TParts>) => TResult) {\n super();\n\n this._parts = parts;\n this._combine = combine;\n }\n\n public async execute(): Promise<TResult> {\n const results = await Promise.all(this._parts.map((part) => part.execute()));\n return this._combine(results as ResultsOf<TParts>);\n }\n\n public clone(session: Session): CompositeQuery<TParts, TResult> {\n const parts = this._parts.map((part) => part.clone(session)) as unknown as TParts;\n return new CompositeQuery(parts, this._combine);\n }\n}\n"]}
@@ -0,0 +1,54 @@
1
+ import { TypedObject } from "../utils/index.js";
2
+ import { ColumnGroupConfig, ColumnGroupDefinition, TableColumnDefinitions } from "../definition/index.js";
3
+ import { SQLNode } from "../sql/index.js";
4
+ import { AnyColumn } from "./column.js";
5
+ import type { AnyTable } from "./table.js";
6
+ export type AnyColumnGroup = ColumnGroup<any, any, any>;
7
+ /** A member of a group, or of a table: a column, or a group of them. */
8
+ export type AnyField = AnyColumn | AnyColumnGroup;
9
+ /**
10
+ * Which members of a group a read selects, as the operation receives it: each member with the
11
+ * column or group it resolves to, and for a group the members selected within it — none meaning
12
+ * all of them.
13
+ */
14
+ export type GroupSelection = [field: string, member: AnyField, selection?: GroupSelection][];
15
+ /** How a group is read: the columns to project, and how a row becomes the group's value. */
16
+ export type GroupReader = {
17
+ readonly columns: AnyColumn[];
18
+ resolve(row: Record<string, unknown>): Record<string, unknown> | null;
19
+ };
20
+ /**
21
+ * An embedded object placed in a table, at runtime: its members as built columns and groups.
22
+ *
23
+ * The group owns how it is read. Its columns are projected like any others, and the value is
24
+ * built from the row by {@link ColumnGroup.reader} — a resolver beside the column ones, not a
25
+ * column. A group is `null` exactly when it is {@link ColumnGroup.nullable} and every one of its
26
+ * columns is `NULL`; deciding that needs all of them, so a nullable group projects every column
27
+ * whatever the selection, and emits only the selected ones.
28
+ */
29
+ export declare class ColumnGroup<TName extends string, TColumns extends TableColumnDefinitions, TTable extends AnyTable> implements TypedObject<ColumnGroupConfig<TColumns, boolean>> {
30
+ readonly __type: ColumnGroupConfig<TColumns, boolean>;
31
+ readonly table: TTable;
32
+ /** The prefix of the group's columns — `net_value` for `net_value_amount`. */
33
+ readonly name: TName;
34
+ readonly columns: Readonly<Record<string, AnyField>>;
35
+ /** True when every member, nested groups included, is nullable: the group can be absent. */
36
+ readonly nullable: boolean;
37
+ constructor(table: TTable, definition: ColumnGroupDefinition<TName, TColumns, boolean>);
38
+ hasColumn(field: string): boolean;
39
+ getColumn(field: string): AnyField | undefined;
40
+ /** Every column under the group, nested groups walked depth first. */
41
+ leafColumns(): AnyColumn[];
42
+ /**
43
+ * The filter for whether the group is present — any of its columns not `NULL` — or absent,
44
+ * every one `NULL`. The same rule {@link ColumnGroup.reader} reads it `null` by, so a filter
45
+ * and a read never disagree.
46
+ */
47
+ exists(present: boolean): SQLNode;
48
+ /**
49
+ * How to read the group under `selection` — every member when it names none. A member column
50
+ * with a row decoder brings the columns it reads, as it does at table level.
51
+ */
52
+ reader(selection?: GroupSelection): GroupReader;
53
+ }
54
+ //# sourceMappingURL=group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/runtime/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAEL,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,wBAAwB,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M,EAAE,UAAU,EAAE,qBAAqB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC;IAmB/E,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIjC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAIrD,sEAAsE;IAC/D,WAAW,IAAI,SAAS,EAAE;IAMjC;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAQxC;;;OAGG;IACI,MAAM,CAAC,SAAS,CAAC,EAAE,cAAc,GAAG,WAAW;CA8CvD"}
@@ -0,0 +1,96 @@
1
+ import { ColumnGroupDefinition, } from "../definition/index.js";
2
+ import { sql } from "../sql/index.js";
3
+ import { Column } from "./column.js";
4
+ /**
5
+ * An embedded object placed in a table, at runtime: its members as built columns and groups.
6
+ *
7
+ * The group owns how it is read. Its columns are projected like any others, and the value is
8
+ * built from the row by {@link ColumnGroup.reader} — a resolver beside the column ones, not a
9
+ * column. A group is `null` exactly when it is {@link ColumnGroup.nullable} and every one of its
10
+ * columns is `NULL`; deciding that needs all of them, so a nullable group projects every column
11
+ * whatever the selection, and emits only the selected ones.
12
+ */
13
+ export class ColumnGroup {
14
+ table;
15
+ /** The prefix of the group's columns — `net_value` for `net_value_amount`. */
16
+ name;
17
+ columns;
18
+ /** True when every member, nested groups included, is nullable: the group can be absent. */
19
+ nullable;
20
+ constructor(table, definition) {
21
+ this.table = table;
22
+ this.name = definition.name;
23
+ const columns = {};
24
+ for (const [field, member] of Object.entries(definition.columns)) {
25
+ columns[field] =
26
+ member instanceof ColumnGroupDefinition
27
+ ? new ColumnGroup(table, member)
28
+ : new Column(table, member);
29
+ }
30
+ this.columns = Object.freeze(columns);
31
+ this.nullable = Object.values(columns).every((member) => member instanceof ColumnGroup ? member.nullable : !member.notNull);
32
+ }
33
+ hasColumn(field) {
34
+ return Object.hasOwn(this.columns, field);
35
+ }
36
+ getColumn(field) {
37
+ return this.hasColumn(field) ? this.columns[field] : undefined;
38
+ }
39
+ /** Every column under the group, nested groups walked depth first. */
40
+ leafColumns() {
41
+ return Object.values(this.columns).flatMap((member) => member instanceof ColumnGroup ? member.leafColumns() : [member]);
42
+ }
43
+ /**
44
+ * The filter for whether the group is present — any of its columns not `NULL` — or absent,
45
+ * every one `NULL`. The same rule {@link ColumnGroup.reader} reads it `null` by, so a filter
46
+ * and a read never disagree.
47
+ */
48
+ exists(present) {
49
+ const columns = this.leafColumns();
50
+ return present
51
+ ? sql.wrap(sql.or(columns.map((column) => sql.isNotNull(column))))
52
+ : sql.and(columns.map((column) => sql.isNull(column)));
53
+ }
54
+ /**
55
+ * How to read the group under `selection` — every member when it names none. A member column
56
+ * with a row decoder brings the columns it reads, as it does at table level.
57
+ */
58
+ reader(selection) {
59
+ const entries = selection && selection.length > 0
60
+ ? selection
61
+ : Object.entries(this.columns).map(([field, member]) => [field, member]);
62
+ const columns = [];
63
+ const fields = [];
64
+ const project = (column) => {
65
+ if (!columns.includes(column)) {
66
+ columns.push(column);
67
+ }
68
+ };
69
+ for (const [field, member, nested] of entries) {
70
+ if (this.columns[field] !== member) {
71
+ throw new Error(`Group "${this.name}" on "${this.table.name}" has no member "${field}".`);
72
+ }
73
+ if (member instanceof ColumnGroup) {
74
+ const reader = member.reader(nested);
75
+ reader.columns.forEach(project);
76
+ fields.push([field, (row) => reader.resolve(row)]);
77
+ continue;
78
+ }
79
+ project(member);
80
+ member.rowDecoder?.dependsOn.forEach(project);
81
+ fields.push([field, (row) => member.resolveRow(row)]);
82
+ }
83
+ const presence = this.nullable ? this.leafColumns() : [];
84
+ presence.forEach(project);
85
+ return {
86
+ columns,
87
+ resolve: (row) => {
88
+ if (this.nullable && presence.every((column) => row[column.name] == null)) {
89
+ return null;
90
+ }
91
+ return Object.fromEntries(fields.map(([field, read]) => [field, read(row)]));
92
+ },
93
+ };
94
+ }
95
+ }
96
+ //# sourceMappingURL=group.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.js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E,CAAC;QACzD,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE1B,OAAO;YACL,OAAO;YACP,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBACf,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC;oBAC1E,OAAO,IAAI,CAAC;gBACd,CAAC;gBAED,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/E,CAAC;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { TypedObject } from \"../utils/index.js\";\nimport {\n AnyColumnGroupDefinition,\n ColumnGroupConfig,\n ColumnGroupDefinition,\n TableColumnDefinitions,\n} from \"../definition/index.js\";\nimport { sql, SQLNode } from \"../sql/index.js\";\nimport { AnyColumn, Column } from \"./column.js\";\nimport type { AnyTable } from \"./table.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyColumnGroup = ColumnGroup<any, any, any>;\n\n/** A member of a group, or of a table: a column, or a group of them. */\nexport type AnyField = AnyColumn | AnyColumnGroup;\n\n/**\n * Which members of a group a read selects, as the operation receives it: each member with the\n * column or group it resolves to, and for a group the members selected within it — none meaning\n * all of them.\n */\nexport type GroupSelection = [field: string, member: AnyField, selection?: GroupSelection][];\n\n/** How a group is read: the columns to project, and how a row becomes the group's value. */\nexport type GroupReader = {\n readonly columns: AnyColumn[];\n resolve(row: Record<string, unknown>): Record<string, unknown> | null;\n};\n\n/**\n * An embedded object placed in a table, at runtime: its members as built columns and groups.\n *\n * The group owns how it is read. Its columns are projected like any others, and the value is\n * built from the row by {@link ColumnGroup.reader} — a resolver beside the column ones, not a\n * column. A group is `null` exactly when it is {@link ColumnGroup.nullable} and every one of its\n * columns is `NULL`; deciding that needs all of them, so a nullable group projects every column\n * whatever the selection, and emits only the selected ones.\n */\nexport class ColumnGroup<\n TName extends string,\n TColumns extends TableColumnDefinitions,\n TTable extends AnyTable,\n> implements TypedObject<ColumnGroupConfig<TColumns, boolean>> {\n declare readonly __type: ColumnGroupConfig<TColumns, boolean>;\n\n readonly table: TTable;\n /** The prefix of the group's columns — `net_value` for `net_value_amount`. */\n readonly name: TName;\n readonly columns: Readonly<Record<string, AnyField>>;\n\n /** True when every member, nested groups included, is nullable: the group can be absent. */\n readonly nullable: boolean;\n\n constructor(table: TTable, definition: ColumnGroupDefinition<TName, TColumns, boolean>) {\n this.table = table;\n this.name = definition.name;\n\n const columns: Record<string, AnyField> = {};\n\n for (const [field, member] of Object.entries(definition.columns)) {\n columns[field] =\n member instanceof ColumnGroupDefinition\n ? new ColumnGroup(table, member as AnyColumnGroupDefinition)\n : new Column(table, member);\n }\n\n this.columns = Object.freeze(columns);\n this.nullable = Object.values(columns).every((member) =>\n member instanceof ColumnGroup ? member.nullable : !member.notNull\n );\n }\n\n public hasColumn(field: string): boolean {\n return Object.hasOwn(this.columns, field);\n }\n\n public getColumn(field: string): AnyField | undefined {\n return this.hasColumn(field) ? this.columns[field] : undefined;\n }\n\n /** Every column under the group, nested groups walked depth first. */\n public leafColumns(): AnyColumn[] {\n return Object.values(this.columns).flatMap((member) =>\n member instanceof ColumnGroup ? member.leafColumns() : [member]\n );\n }\n\n /**\n * The filter for whether the group is present — any of its columns not `NULL` — or absent,\n * every one `NULL`. The same rule {@link ColumnGroup.reader} reads it `null` by, so a filter\n * and a read never disagree.\n */\n public exists(present: boolean): SQLNode {\n const columns = this.leafColumns();\n\n return present\n ? sql.wrap(sql.or(columns.map((column) => sql.isNotNull(column))))\n : sql.and(columns.map((column) => sql.isNull(column)));\n }\n\n /**\n * How to read the group under `selection` — every member when it names none. A member column\n * with a row decoder brings the columns it reads, as it does at table level.\n */\n public reader(selection?: GroupSelection): GroupReader {\n const entries: GroupSelection =\n selection && selection.length > 0\n ? selection\n : Object.entries(this.columns).map(([field, member]) => [field, member]);\n\n const columns: AnyColumn[] = [];\n const fields: [string, (row: Record<string, unknown>) => unknown][] = [];\n\n const project = (column: AnyColumn) => {\n if (!columns.includes(column)) {\n columns.push(column);\n }\n };\n\n for (const [field, member, nested] of entries) {\n if (this.columns[field] !== member) {\n throw new Error(`Group \"${this.name}\" on \"${this.table.name}\" has no member \"${field}\".`);\n }\n\n if (member instanceof ColumnGroup) {\n const reader = member.reader(nested);\n reader.columns.forEach(project);\n fields.push([field, (row) => reader.resolve(row)]);\n continue;\n }\n\n project(member);\n member.rowDecoder?.dependsOn.forEach(project);\n fields.push([field, (row) => member.resolveRow(row)]);\n }\n\n const presence = this.nullable ? this.leafColumns() : [];\n presence.forEach(project);\n\n return {\n columns,\n resolve: (row) => {\n if (this.nullable && presence.every((column) => row[column.name] == null)) {\n return null;\n }\n\n return Object.fromEntries(fields.map(([field, read]) => [field, read(row)]));\n },\n };\n }\n}\n"]}
@@ -1,10 +1,13 @@
1
- export type { AnySchema, DefinitionRelationsTableName, DefinitionTableName, DefinitionTableRelations, FieldRelationConfig, Schema, SchemaRelationDefinitions, SchemaTableDefinitions, SchemaTableRelations, TableRelationFieldName, } from "./base.js";
2
- export { Column, type AnyColumn } from "./column.js";
3
- export { ExecutionContext, type ExecutionContextOptions } from "./context.js";
4
- export { ExecutableQuery } from "./executor.js";
5
- export { OperationsFactory, type DeleteOperation, type DeleteOperationArgs, type FieldMutation, type FieldResolver, type FieldSelection, type InsertOperation, type InsertOperationArgs, type Operation, type OperationMode, type OperationRequest, type OperationResult, type OperationType, type SelectOperation, type SelectOperationArgs, type UpdateOperation, type UpdateOperationArgs, } from "./operation.js";
6
- export { QueryBuilder, type DeleteParams, type InsertParams, type JoinParams, type SelectParams, type UpdateParams, } from "./query.js";
1
+ export type { AnySchema, DefinitionRelationsTableName, DefinitionTableName, DefinitionTableRelations, FieldRelationConfig, Schema, SchemaRelationDefinitions, SchemaTableDefinitions, SchemaTableRelations, SchemaUnionDefinitions, DefinitionUnionName, TableRelationFieldName, } from "./base.js";
2
+ export { Column, type AnyColumn, type ColumnRowDecoder } from "./column.js";
3
+ export { ColumnGroup, type AnyColumnGroup, type AnyField, type GroupReader, type GroupSelection, } from "./group.js";
4
+ export { ExecutionContext, type ExecutionContextOptions, type PaginationOptions, type TenancyOptions, } from "./context.js";
5
+ export { TenancyError } from "./errors.js";
6
+ export { CompositeQuery, ExecutableQuery, type Executable } from "./executor.js";
7
+ export { OperationsFactory, type CountOperation, type CountOperationArgs, type DeleteOperation, type DeleteOperationArgs, type FieldMutation, type FieldResolver, type FieldSelection, type InsertOperation, type InsertOperationArgs, type Operation, type OperationMode, type OperationRequest, type OperationResult, type OperationType, type SelectOperation, type SelectOperationArgs, type UpdateOperation, type UpdateOperationArgs, type UnionOrderKey, type UnionSelectOperationArgs, type UnionSelectOperation, type UnionCountOperationArgs, UnionResolver, } from "./operation.js";
8
+ export { QueryBuilder, type DeleteParams, type InsertParams, type JoinParams, type SelectParams, type TableJoinParams, type UnionBranchParams, type UnionJoinParams, type UnionSelectParams, type UpdateParams, } from "./query.js";
7
9
  export { SchemaRegistry, type RuntimeTables, type TableByAlias, type TableByName, type TableByNameOrAlias, } from "./registry.js";
8
10
  export type { Session, TransactionSession } from "./session.js";
9
11
  export { Table, type AnyTable } from "./table.js";
12
+ export { Union, type AnyUnion } from "./union.js";
10
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,SAAS,EACT,4BAA4B,EAC5B,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,MAAM,EACN,yBAAyB,EACzB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,SAAS,EACT,4BAA4B,EAC5B,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,MAAM,EACN,yBAAyB,EACzB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,MAAM,EAA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