okmodel 0.1.0 → 0.2.1

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 (181) hide show
  1. package/README.md +237 -19
  2. package/dist/adapters/capabilities.d.ts +34 -0
  3. package/dist/adapters/pg/bunsql-extra.d.ts +17 -0
  4. package/dist/adapters/pg/bunsql.d.ts +60 -0
  5. package/dist/adapters/pg/call.d.ts +2 -12
  6. package/dist/adapters/pg/nodepostgres-extra.d.ts +18 -0
  7. package/dist/adapters/pg/nodepostgres.d.ts +57 -0
  8. package/dist/adapters/pg/postgres-extra.d.ts +50 -1
  9. package/dist/adapters/pg/postgresjs.d.ts +0 -4
  10. package/dist/adapters/pg/session.d.ts +94 -0
  11. package/dist/adapters/pg/watch.d.ts +18 -0
  12. package/dist/contracts/catalog/object.d.ts +1 -0
  13. package/dist/contracts/catalog/types.d.ts +15 -8
  14. package/dist/contracts/connection.d.ts +13 -0
  15. package/dist/contracts/driver.d.ts +18 -5
  16. package/dist/contracts/error.d.ts +17 -1
  17. package/dist/contracts/generator.d.ts +63 -0
  18. package/dist/contracts/index.d.ts +2 -2
  19. package/dist/contracts/index.js +1 -1
  20. package/dist/contracts/internal.js +11 -9
  21. package/dist/contracts/location.d.ts +24 -0
  22. package/dist/contracts/rows.d.ts +15 -0
  23. package/dist/dialects/pg/archive-bind.d.ts +22 -0
  24. package/dist/dialects/pg/column.d.ts +126 -9
  25. package/dist/dialects/pg/compile.d.ts +1 -0
  26. package/dist/dialects/pg/custom.d.ts +6 -0
  27. package/dist/dialects/pg/filter-parse.d.ts +19 -0
  28. package/dist/dialects/pg/filters.d.ts +19 -0
  29. package/dist/dialects/pg/index.d.ts +11 -2
  30. package/dist/dialects/pg/index.js +159 -1063
  31. package/dist/dialects/pg/keys.d.ts +19 -3
  32. package/dist/dialects/pg/model.d.ts +223 -2
  33. package/dist/dialects/pg/operator-fit.d.ts +86 -0
  34. package/dist/dialects/pg/operators.d.ts +39 -1
  35. package/dist/dialects/pg/ops/arr-append.d.ts +9 -0
  36. package/dist/dialects/pg/ops/arr-ns.d.ts +7 -0
  37. package/dist/dialects/pg/ops/arr-remove.d.ts +9 -0
  38. package/dist/dialects/pg/ops/containedBy.d.ts +9 -0
  39. package/dist/dialects/pg/ops/contains.d.ts +8 -4
  40. package/dist/dialects/pg/ops/hasAnyKey.d.ts +8 -0
  41. package/dist/dialects/pg/ops/hasKey.d.ts +8 -0
  42. package/dist/dialects/pg/ops/json-ns.d.ts +6 -0
  43. package/dist/dialects/pg/ops/json-set.d.ts +12 -0
  44. package/dist/dialects/pg/ops/matches.d.ts +16 -0
  45. package/dist/dialects/pg/ops/overlaps.d.ts +9 -0
  46. package/dist/dialects/pg/ops/path.d.ts +13 -0
  47. package/dist/dialects/pg/preset.d.ts +76 -0
  48. package/dist/dialects/pg/relations.d.ts +59 -2
  49. package/dist/dialects/pg/schema.d.ts +109 -5
  50. package/dist/dialects/pg/table.d.ts +130 -11
  51. package/dist/dialects/pg/temporal.d.ts +9 -7
  52. package/dist/dialects/pg/tenancy.d.ts +94 -0
  53. package/dist/dialects/pg/through.d.ts +21 -0
  54. package/dist/dialects/pg/trait.d.ts +141 -0
  55. package/dist/dialects/pg/where.d.ts +37 -0
  56. package/dist/runtime/aggregate.d.ts +25 -0
  57. package/dist/runtime/archive-handle.d.ts +18 -0
  58. package/dist/runtime/archive-rules.d.ts +12 -0
  59. package/dist/runtime/archive.d.ts +73 -0
  60. package/dist/runtime/batch.d.ts +20 -0
  61. package/dist/runtime/client.d.ts +114 -5
  62. package/dist/runtime/conflict.d.ts +2 -1
  63. package/dist/runtime/exposure.d.ts +27 -0
  64. package/dist/runtime/hookm.d.ts +39 -0
  65. package/dist/runtime/ids/index.d.ts +11 -0
  66. package/dist/runtime/ids/index.js +193 -0
  67. package/dist/runtime/ids/okid-extended.d.ts +19 -0
  68. package/dist/runtime/ids/okid-generator.d.ts +21 -0
  69. package/dist/runtime/ids/okid-shared.d.ts +89 -0
  70. package/dist/runtime/ids/okid.d.ts +24 -0
  71. package/dist/runtime/ids/uuid.d.ts +21 -0
  72. package/dist/runtime/lock.d.ts +22 -0
  73. package/dist/runtime/operator-sql.d.ts +8 -0
  74. package/dist/runtime/page.d.ts +25 -0
  75. package/dist/runtime/pg/bun.d.ts +30 -0
  76. package/dist/runtime/pg/bun.js +52 -0
  77. package/dist/runtime/pg/pg.d.ts +29 -0
  78. package/dist/runtime/pg/pg.js +52 -0
  79. package/dist/runtime/pg/pglite.js +16 -17
  80. package/dist/runtime/pg/postgresjs.js +14 -24
  81. package/dist/runtime/plan.d.ts +146 -7
  82. package/dist/runtime/preset-stack.d.ts +17 -0
  83. package/dist/runtime/presets.d.ts +48 -0
  84. package/dist/runtime/read-stream.d.ts +26 -0
  85. package/dist/runtime/safety/index.d.ts +159 -0
  86. package/dist/runtime/safety/index.js +294 -0
  87. package/dist/runtime/safety-hook.d.ts +42 -0
  88. package/dist/runtime/server-check.d.ts +34 -0
  89. package/dist/runtime/tenancy/index.d.ts +37 -0
  90. package/dist/runtime/tenancy/index.js +365 -0
  91. package/dist/runtime/trait-read.d.ts +30 -0
  92. package/dist/runtime/traits/index.d.ts +128 -0
  93. package/dist/runtime/traits/index.js +509 -0
  94. package/dist/runtime/transaction.d.ts +19 -0
  95. package/dist/runtime/tx.d.ts +22 -7
  96. package/dist/runtime/types.d.ts +390 -25
  97. package/dist/runtime/validate/bind.d.ts +11 -0
  98. package/dist/runtime/validate/closed.d.ts +16 -0
  99. package/dist/runtime/validate/engine.d.ts +41 -0
  100. package/dist/runtime/validate/hook.d.ts +17 -0
  101. package/dist/runtime/validate/index.d.ts +21 -0
  102. package/dist/runtime/validate/index.js +175 -0
  103. package/dist/runtime/validate/load.d.ts +13 -0
  104. package/dist/runtime/validate/places.d.ts +41 -0
  105. package/dist/runtime/validate/rules.d.ts +108 -0
  106. package/dist/runtime/validate/surface.d.ts +102 -0
  107. package/dist/runtime/write.d.ts +30 -5
  108. package/dist/shared/{fgqgsb5z.js → 0qkxbm1f.js} +2 -2
  109. package/dist/shared/0v1g424p.js +26 -0
  110. package/dist/shared/10tjenmd.js +210 -0
  111. package/dist/shared/{tb4ze1tr.js → 1dp5knt7.js} +95 -10
  112. package/dist/shared/38crxbgn.js +229 -0
  113. package/dist/shared/3a5ne750.js +158 -0
  114. package/dist/shared/4b9da9d7.js +138 -0
  115. package/dist/shared/4e4c6vq2.js +62 -0
  116. package/dist/shared/{ckb1p0a4.js → 4jzzghr6.js} +416 -83
  117. package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
  118. package/dist/shared/{kynx7vbm.js → 5z4q2zda.js} +604 -21
  119. package/dist/shared/672t5vym.js +12 -0
  120. package/dist/shared/7m88x3e9.js +45 -0
  121. package/dist/shared/7mht49yd.js +1091 -0
  122. package/dist/shared/{mtkwv8wx.js → 7p2wbz7f.js} +1 -1
  123. package/dist/shared/83eaefwr.js +10 -0
  124. package/dist/shared/96ps4g1z.js +32 -0
  125. package/dist/shared/97g2jnrw.js +76 -0
  126. package/dist/shared/{xy79j5hq.js → 9k6vetvf.js} +25 -36
  127. package/dist/shared/{w8samvk1.js → a1gdp7j9.js} +1 -1
  128. package/dist/shared/a5sxz52y.js +13 -0
  129. package/dist/shared/{dynq16vb.js → b066g80h.js} +8 -6
  130. package/dist/shared/cstgkzdx.js +154 -0
  131. package/dist/shared/{ax16zpvm.js → d04j53v8.js} +6 -5
  132. package/dist/shared/{y9m15dfv.js → d2whjz4k.js} +15 -9
  133. package/dist/shared/dd4f8mnx.js +307 -0
  134. package/dist/shared/e6wg00wd.js +164 -0
  135. package/dist/shared/e7a268fy.js +195 -0
  136. package/dist/shared/{vkm3q4x1.js → eaxwrgby.js} +4 -3
  137. package/dist/shared/{7ck0dtry.js → ecdzej21.js} +160 -81
  138. package/dist/shared/{px90pf9p.js → edwqqryd.js} +21 -16
  139. package/dist/shared/{g2v6gnc8.js → eqmtn1bj.js} +57 -5
  140. package/dist/shared/g1b5zzj9.js +75 -0
  141. package/dist/shared/g9f0zqce.js +376 -0
  142. package/dist/shared/ge03bfca.js +64 -0
  143. package/dist/shared/{79ggp945.js → jns2wx4t.js} +55 -12
  144. package/dist/shared/k3ted12y.js +33 -0
  145. package/dist/shared/k7dwkhvq.js +31 -0
  146. package/dist/shared/{hd293j9g.js → kyxb62mc.js} +14 -2
  147. package/dist/shared/m9tv7xn7.js +404 -0
  148. package/dist/shared/mrq77sgw.js +55 -0
  149. package/dist/shared/mxmcdsh5.js +450 -0
  150. package/dist/shared/n442h54c.js +14 -0
  151. package/dist/shared/n47rd821.js +442 -0
  152. package/dist/shared/n4jqhpqz.js +27 -0
  153. package/dist/shared/{mkjmqjv4.js → nfzc5z0w.js} +2 -104
  154. package/dist/shared/nsva2a6b.js +42 -0
  155. package/dist/shared/ps43134h.js +69 -0
  156. package/dist/shared/{8b04d28c.js → py3nh7jy.js} +2 -2
  157. package/dist/shared/qa5dsc7z.js +86 -0
  158. package/dist/shared/{g5fhqmwe.js → qxa0yb9j.js} +6 -4
  159. package/dist/shared/r6nwkxnt.js +86 -0
  160. package/dist/shared/{4j72449d.js → rtnaqre0.js} +3 -3
  161. package/dist/shared/rwmrejjz.js +26 -0
  162. package/dist/shared/{zhc5vmgf.js → s6gqfn5j.js} +2 -2
  163. package/dist/shared/sacqha1y.js +70 -0
  164. package/dist/shared/{qk3hxfja.js → sfh4pk75.js} +5 -5
  165. package/dist/shared/{j5cn2963.js → t4tbsy9h.js} +13 -64
  166. package/dist/shared/{ngk8gj61.js → tbszx8mz.js} +15 -1
  167. package/dist/shared/v18jva5b.js +90 -0
  168. package/dist/shared/x9v1qgeb.js +201 -0
  169. package/dist/shared/xatfg0gn.js +193 -0
  170. package/dist/shared/xkz8g6by.js +225 -0
  171. package/dist/shared/{f5thc1s0.js → xrfnq5k8.js} +237 -418
  172. package/dist/shared/ytg3xf9p.js +149 -0
  173. package/dist/shared/yw5c610b.js +48 -0
  174. package/dist/shared/zd93g3rq.js +31 -0
  175. package/dist/shared/zt8y0wzb.js +132 -0
  176. package/dist/shared/{p0cbr3g2.js → zwmqxb0g.js} +1 -1
  177. package/dist/tooling/cli.js +14 -10
  178. package/dist/tooling/migrate/commands.d.ts +10 -0
  179. package/dist/tooling/migrate/engine.d.ts +36 -0
  180. package/package.json +56 -4
  181. package/dist/shared/gk7cs7sp.js +0 -566
@@ -0,0 +1,294 @@
1
+ import {
2
+ callerLocation
3
+ } from "../../shared/k7dwkhvq.js";
4
+ import {
5
+ installSafetyHook
6
+ } from "../../shared/a5sxz52y.js";
7
+ import {
8
+ OkmError2
9
+ } from "../../shared/52szzakm.js";
10
+
11
+ // src/runtime/safety/index.ts
12
+ class SafetyError extends OkmError2 {
13
+ rule;
14
+ contribution;
15
+ violations;
16
+ constructor(violations) {
17
+ const first = violations[0];
18
+ const rule = first?.rule ?? "unknown";
19
+ const contribution = first?.contribution ?? "unknown";
20
+ const extra = violations.length > 1 ? ` (+${String(violations.length - 1)} more)` : "";
21
+ const source = first?.source === undefined ? "" : ` (${first.source})`;
22
+ super("OKM1190", first === undefined ? "A safety check failed." : `${rule} [${contribution}]${source}: ${first.detail}${extra}`);
23
+ this.rule = rule;
24
+ this.contribution = contribution;
25
+ this.violations = violations;
26
+ }
27
+ }
28
+ var rules = [];
29
+ function registerFieldExposure() {
30
+ return registerRule({
31
+ name: "exposure",
32
+ contribution: "field-exposure",
33
+ check(input) {
34
+ const allowed = new Set;
35
+ if (input.hatches !== undefined) {
36
+ for (const hatch of input.hatches) {
37
+ if (hatch.name === "allow" && hatch.reason.trim().length > 0)
38
+ allowed.add(hatch.reason);
39
+ }
40
+ }
41
+ const violations = [];
42
+ for (const item of input.contributions) {
43
+ if (!leaked(item.rule, item.contribution))
44
+ continue;
45
+ if (item.rule === "guarded" && permitted(item.contribution, allowed))
46
+ continue;
47
+ violations.push({
48
+ rule: item.rule,
49
+ contribution: item.contribution,
50
+ ...item.source !== undefined ? { source: item.source } : {},
51
+ detail: exposureDetail(item.rule)
52
+ });
53
+ }
54
+ return violations;
55
+ }
56
+ });
57
+ }
58
+ function registerTenancy() {
59
+ return registerRule({
60
+ name: "tenancy",
61
+ contribution: "tenancy",
62
+ check(input) {
63
+ const violations = [];
64
+ for (const item of input.contributions) {
65
+ if (item.rule !== "tenancy" || !item.contribution.includes("set by input"))
66
+ continue;
67
+ violations.push({
68
+ rule: item.rule,
69
+ contribution: item.contribution,
70
+ ...item.source !== undefined ? { source: item.source } : {},
71
+ detail: "The tenant key comes from the scope. Input cannot set it."
72
+ });
73
+ }
74
+ return violations;
75
+ }
76
+ });
77
+ }
78
+ function registerTimestamps() {
79
+ return registerRule({
80
+ name: "timestamps",
81
+ contribution: "timestamps",
82
+ check(input) {
83
+ const violations = [];
84
+ for (const item of input.contributions) {
85
+ if (item.rule !== "timestamps" || !item.contribution.includes("set by input"))
86
+ continue;
87
+ violations.push({
88
+ rule: item.rule,
89
+ contribution: item.contribution,
90
+ ...item.source !== undefined ? { source: item.source } : {},
91
+ detail: "A timestamp is set by the trait. Input cannot set it."
92
+ });
93
+ }
94
+ return violations;
95
+ }
96
+ });
97
+ }
98
+ function registerArchive() {
99
+ return registerRule({
100
+ name: "archive",
101
+ contribution: "archive",
102
+ check(input) {
103
+ const violations = [];
104
+ for (const item of input.contributions) {
105
+ if (item.rule !== "archive")
106
+ continue;
107
+ if (item.contribution.includes("active set dropped")) {
108
+ violations.push({
109
+ rule: item.rule,
110
+ contribution: item.contribution,
111
+ ...item.source !== undefined ? { source: item.source } : {},
112
+ detail: "Reads, updates, and deletes target the active set."
113
+ });
114
+ }
115
+ if (item.contribution.includes("cascade skipped")) {
116
+ violations.push({
117
+ rule: item.rule,
118
+ contribution: item.contribution,
119
+ ...item.source !== undefined ? { source: item.source } : {},
120
+ detail: "Cascade archives and restores the named children with the row."
121
+ });
122
+ }
123
+ }
124
+ return violations;
125
+ }
126
+ });
127
+ }
128
+ function registerPresets() {
129
+ return registerRule({
130
+ name: "presets",
131
+ contribution: "preset",
132
+ check(input) {
133
+ const violations = [];
134
+ for (const item of input.contributions) {
135
+ if (item.rule !== "preset")
136
+ continue;
137
+ if (!item.contribution.includes(" removed ") && !item.contribution.includes(" replaced ")) {
138
+ continue;
139
+ }
140
+ violations.push({
141
+ rule: item.rule,
142
+ contribution: item.contribution,
143
+ ...item.source !== undefined ? { source: item.source } : {},
144
+ detail: "A preset adds predicates. It cannot remove or replace one."
145
+ });
146
+ }
147
+ return violations;
148
+ }
149
+ });
150
+ }
151
+ function leaked(rule, contribution) {
152
+ if (rule === "hidden")
153
+ return contribution.includes(" shown");
154
+ if (rule === "sensitive")
155
+ return contribution.includes(" revealed");
156
+ if (rule === "guarded")
157
+ return contribution.includes(" set");
158
+ return false;
159
+ }
160
+ function permitted(contribution, allowed) {
161
+ for (const reason of allowed) {
162
+ if (contribution.includes(`${reason} set`))
163
+ return true;
164
+ }
165
+ return false;
166
+ }
167
+ function exposureDetail(rule) {
168
+ if (rule === "hidden")
169
+ return "A hidden field was returned.";
170
+ if (rule === "sensitive")
171
+ return "A sensitive value was shown.";
172
+ return "A guarded field was set from input.";
173
+ }
174
+ function registerRule(rule) {
175
+ const source = rule.source ?? callerLocation(1);
176
+ const stored = source === undefined || rule.source !== undefined ? rule : { ...rule, source };
177
+ rules.push(stored);
178
+ installSafetyHook(runHook);
179
+ return () => {
180
+ const index = rules.indexOf(stored);
181
+ if (index >= 0)
182
+ rules.splice(index, 1);
183
+ if (rules.length === 0)
184
+ installSafetyHook(undefined);
185
+ };
186
+ }
187
+ function review(input) {
188
+ const violations = [];
189
+ const hatches = [];
190
+ if (input.hatches !== undefined) {
191
+ for (const hatch of input.hatches) {
192
+ if (hatch.reason.trim().length === 0) {
193
+ violations.push({
194
+ rule: "hatch",
195
+ contribution: hatch.name,
196
+ detail: "An escape hatch needs a reason."
197
+ });
198
+ continue;
199
+ }
200
+ hatches.push(hatch);
201
+ }
202
+ }
203
+ if (input.recorded !== undefined) {
204
+ for (const item of input.recorded) {
205
+ if (present(item, input.contributions))
206
+ continue;
207
+ violations.push({
208
+ rule: "dropped",
209
+ contribution: item.contribution,
210
+ ...item.source !== undefined ? { source: item.source } : {},
211
+ detail: `${item.rule} was removed.`
212
+ });
213
+ }
214
+ }
215
+ const seen = input.hatches === undefined || hatches.length === input.hatches.length ? input : {
216
+ contributions: input.contributions,
217
+ ...input.recorded !== undefined ? { recorded: input.recorded } : {},
218
+ hatches
219
+ };
220
+ for (const rule of rules) {
221
+ for (const found of rule.check(seen)) {
222
+ violations.push(found.source === undefined && rule.source !== undefined ? { ...found, source: rule.source } : found);
223
+ }
224
+ }
225
+ violations.sort((left, right) => violationKey(left).localeCompare(violationKey(right)));
226
+ return violations;
227
+ }
228
+ function verify(input) {
229
+ const violations = review(input);
230
+ if (violations.length > 0)
231
+ throw new SafetyError(violations);
232
+ }
233
+ function safetyProperty(cases) {
234
+ const forward = cases.map((item) => review(item));
235
+ const snapshot = rules.slice();
236
+ rules.reverse();
237
+ try {
238
+ for (let index = 0;index < cases.length; index += 1) {
239
+ const item = cases[index];
240
+ if (item === undefined)
241
+ continue;
242
+ if (!sameViolations(forward[index] ?? [], review(item))) {
243
+ throw new Error("safety.property: rule order changed the verdict.");
244
+ }
245
+ }
246
+ } finally {
247
+ rules.length = 0;
248
+ for (const rule of snapshot)
249
+ rules.push(rule);
250
+ }
251
+ return forward;
252
+ }
253
+ function runHook(contributions, hatches) {
254
+ verify({
255
+ contributions,
256
+ ...hatches !== undefined ? { hatches } : {}
257
+ });
258
+ }
259
+ function present(needle, contributions) {
260
+ for (const item of contributions) {
261
+ if (item.rule === needle.rule && item.contribution === needle.contribution && item.provenance === needle.provenance) {
262
+ return true;
263
+ }
264
+ }
265
+ return false;
266
+ }
267
+ function violationKey(violation) {
268
+ return `${violation.rule}\x00${violation.contribution}\x00${violation.detail}`;
269
+ }
270
+ function sameViolations(left, right) {
271
+ if (left.length !== right.length)
272
+ return false;
273
+ for (let index = 0;index < left.length; index += 1) {
274
+ const a = left[index];
275
+ const b = right[index];
276
+ if (a === undefined || b === undefined)
277
+ return false;
278
+ if (violationKey(a) !== violationKey(b))
279
+ return false;
280
+ }
281
+ return true;
282
+ }
283
+ export {
284
+ SafetyError,
285
+ registerArchive,
286
+ registerFieldExposure,
287
+ registerPresets,
288
+ registerRule,
289
+ registerTenancy,
290
+ registerTimestamps,
291
+ review,
292
+ safetyProperty,
293
+ verify
294
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Slot the read path calls before planning.
3
+ *
4
+ * Empty until `okmodel/safety` registers a rule. The application startup
5
+ * graph pays for this call and not for the registry.
6
+ */
7
+ /** One recorded contribution. */
8
+ export type SafetyContribution = {
9
+ readonly rule: string;
10
+ readonly contribution: string;
11
+ readonly provenance: string;
12
+ readonly source?: string;
13
+ };
14
+ /** A named escape hatch with a reason. */
15
+ export type SafetyHatch = {
16
+ readonly name: "unscoped" | "all" | "trusted" | "allow";
17
+ readonly reason: string;
18
+ };
19
+ /** Installed by the safety registry. Absent until a rule is registered. */
20
+ export type SafetyHook = (contributions: readonly SafetyContribution[], hatches: readonly SafetyHatch[] | undefined) => void;
21
+ /**
22
+ * Reports whether a safety rule is registered.
23
+ *
24
+ * @returns `true` after the first {@link installSafetyHook} until the last rule is removed
25
+ */
26
+ export declare function safetyInstalled(): boolean;
27
+ /**
28
+ * Installs or clears the verifier the read path calls.
29
+ *
30
+ * @param next - Verifier, or `undefined` to remove it
31
+ */
32
+ export declare function installSafetyHook(next: SafetyHook | undefined): void;
33
+ /**
34
+ * Runs the installed verifier.
35
+ *
36
+ * A no-op when nothing is registered, and it does not allocate in that case
37
+ * because the caller returns first.
38
+ *
39
+ * @param contributions - Rules already recorded for this query
40
+ * @param hatches - Escape hatches the caller passed
41
+ */
42
+ export declare function runSafety(contributions: readonly SafetyContribution[], hatches: readonly SafetyHatch[] | undefined): void;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Dialect, catalog-hash, and Postgres major checks.
3
+ *
4
+ * Loaded on the first connection. The strings stay out of the startup graph.
5
+ */
6
+ import type { DriverPool, ExecuteOptions } from "../contracts/driver.js";
7
+ import { type ErrorStatuses } from "../contracts/error.js";
8
+ import type { QuerySchema } from "../dialects/pg/model.js";
9
+ import type { CatalogArtifact } from "./types.js";
10
+ /**
11
+ * Version, dialect, and the `okm_meta` hash in one round trip.
12
+ *
13
+ * The hash subquery is a string so a database with no `okm_meta` still plans.
14
+ * A null hash skips the compatibility check.
15
+ */
16
+ export declare const versionQuery = "select current_setting('server_version_num'), version(), (select (xpath('//catalog_hash/text()', query_to_xml('select catalog_hash from okm_meta where id = ''head''', true, false, '')))[1]::text where to_regclass('okm_meta') is not null)";
17
+ /**
18
+ * Accepts the `server_version_num` row, or throws OKM1801, OKM1520, OKM1802, or OKM1803.
19
+ *
20
+ * A declared `requires` is the minimum, including a major below 15 when the
21
+ * schema names it on purpose. With no `requires`, the floor is 15.
22
+ *
23
+ * @param pool - Connection that ran the version query
24
+ * @param schema - Schema whose `requires` is the declared minimum
25
+ * @param rows - `server_version_num`, `version()`, and the `okm_meta` hash
26
+ * @param http - Status overrides from `connect`
27
+ * @param requireMeta - When true, a missing hash is OKM1520
28
+ * @param options - Signal and timeout for the compatibility read
29
+ * @param source - Trusted catalog used when the hash does not match
30
+ */
31
+ export declare function acceptServer(pool: DriverPool, schema: QuerySchema, rows: readonly (readonly (string | null)[])[], http: ErrorStatuses | undefined, requireMeta: boolean, options: ExecuteOptions | undefined, source: {
32
+ readonly catalog?: CatalogArtifact;
33
+ readonly catalogDir?: string;
34
+ }): Promise<void>;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Column tenancy (`okmodel/tenancy`).
3
+ *
4
+ * Importing this module is what puts tenancy on a schema. `schema()` calls
5
+ * `rewrite` once and then compiles ordinary columns, uniques, and foreign keys.
6
+ * The predicate and the client methods stay on this object.
7
+ */
8
+ import type { ColumnTenancy } from "../../dialects/pg/tenancy.js";
9
+ export type { ColumnTenancy };
10
+ /**
11
+ * Opts a table out of column tenancy.
12
+ *
13
+ * The reason is stored on the table and shown by `inspect()`.
14
+ *
15
+ * @param reason - Why this table is shared across tenants
16
+ * @returns The marker `table({ tenancy })` stores
17
+ */
18
+ export declare function global(reason: string): {
19
+ readonly kind: "global";
20
+ readonly reason: string;
21
+ };
22
+ /**
23
+ * Column tenancy for `schema({ tenancy })`.
24
+ *
25
+ * Every table gains `key` unless it passes `global("reason")`. The key is a
26
+ * guarded uuid. Insert fills it from `for()`. Reads and writes filter on it.
27
+ *
28
+ * @typeParam Key - Field name of the tenant key
29
+ * @param input - Field name and `uuid`
30
+ * @returns The object `schema()` applies
31
+ */
32
+ export declare function columnTenancy<const Key extends string>(input: {
33
+ readonly key: Key;
34
+ readonly type: "uuid";
35
+ }): ColumnTenancy & {
36
+ readonly key: Key;
37
+ };