okmodel 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/README.md +727 -37
  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/enum.d.ts +31 -4
  13. package/dist/contracts/catalog/extension.d.ts +61 -0
  14. package/dist/contracts/catalog/object.d.ts +1 -0
  15. package/dist/contracts/catalog/privilege.d.ts +64 -0
  16. package/dist/contracts/catalog/routine.d.ts +56 -0
  17. package/dist/contracts/catalog/types.d.ts +179 -18
  18. package/dist/contracts/catalog/view.d.ts +73 -0
  19. package/dist/contracts/connection.d.ts +13 -0
  20. package/dist/contracts/driver.d.ts +18 -5
  21. package/dist/contracts/error.d.ts +17 -1
  22. package/dist/contracts/generator.d.ts +63 -0
  23. package/dist/contracts/index.d.ts +2 -2
  24. package/dist/contracts/index.js +1 -1
  25. package/dist/contracts/internal.js +11 -9
  26. package/dist/contracts/location.d.ts +24 -0
  27. package/dist/contracts/rows.d.ts +15 -0
  28. package/dist/dialects/pg/archive-bind.d.ts +22 -0
  29. package/dist/dialects/pg/column.d.ts +129 -10
  30. package/dist/dialects/pg/compile.d.ts +1 -0
  31. package/dist/dialects/pg/custom.d.ts +6 -0
  32. package/dist/dialects/pg/ddl.d.ts +65 -1
  33. package/dist/dialects/pg/enum.d.ts +10 -8
  34. package/dist/dialects/pg/ext/citext.d.ts +14 -0
  35. package/dist/dialects/pg/ext/citext.js +11 -0
  36. package/dist/dialects/pg/ext/index.d.ts +52 -0
  37. package/dist/dialects/pg/ext/index.js +6 -0
  38. package/dist/dialects/pg/ext/pg-trgm.d.ts +53 -0
  39. package/dist/dialects/pg/ext/pg-trgm.js +42 -0
  40. package/dist/dialects/pg/filter-parse.d.ts +19 -0
  41. package/dist/dialects/pg/filters.d.ts +19 -0
  42. package/dist/dialects/pg/fn/index.d.ts +107 -0
  43. package/dist/dialects/pg/fn/index.js +175 -0
  44. package/dist/dialects/pg/fn/touch.d.ts +14 -0
  45. package/dist/dialects/pg/index.d.ts +11 -2
  46. package/dist/dialects/pg/index.js +243 -1062
  47. package/dist/dialects/pg/introspect.d.ts +10 -1
  48. package/dist/dialects/pg/keys.d.ts +19 -3
  49. package/dist/dialects/pg/model.d.ts +223 -2
  50. package/dist/dialects/pg/operator-fit.d.ts +86 -0
  51. package/dist/dialects/pg/operators.d.ts +46 -1
  52. package/dist/dialects/pg/ops/arr-append.d.ts +9 -0
  53. package/dist/dialects/pg/ops/arr-ns.d.ts +7 -0
  54. package/dist/dialects/pg/ops/arr-remove.d.ts +9 -0
  55. package/dist/dialects/pg/ops/containedBy.d.ts +9 -0
  56. package/dist/dialects/pg/ops/contains.d.ts +8 -4
  57. package/dist/dialects/pg/ops/hasAnyKey.d.ts +8 -0
  58. package/dist/dialects/pg/ops/hasKey.d.ts +8 -0
  59. package/dist/dialects/pg/ops/json-ns.d.ts +6 -0
  60. package/dist/dialects/pg/ops/json-set.d.ts +12 -0
  61. package/dist/dialects/pg/ops/matches.d.ts +16 -0
  62. package/dist/dialects/pg/ops/overlaps.d.ts +9 -0
  63. package/dist/dialects/pg/ops/path.d.ts +13 -0
  64. package/dist/dialects/pg/preset.d.ts +76 -0
  65. package/dist/dialects/pg/relations.d.ts +59 -2
  66. package/dist/dialects/pg/role/check.d.ts +45 -0
  67. package/dist/dialects/pg/role/index.d.ts +50 -0
  68. package/dist/dialects/pg/role/sql.d.ts +44 -0
  69. package/dist/dialects/pg/schema.d.ts +109 -5
  70. package/dist/dialects/pg/table.d.ts +137 -11
  71. package/dist/dialects/pg/temporal.d.ts +9 -7
  72. package/dist/dialects/pg/tenancy.d.ts +103 -0
  73. package/dist/dialects/pg/through.d.ts +21 -0
  74. package/dist/dialects/pg/trait.d.ts +141 -0
  75. package/dist/dialects/pg/view/client.d.ts +30 -0
  76. package/dist/dialects/pg/view/depend.d.ts +35 -0
  77. package/dist/dialects/pg/view/index.d.ts +114 -0
  78. package/dist/dialects/pg/view/index.js +289 -0
  79. package/dist/dialects/pg/view/scratch.d.ts +21 -0
  80. package/dist/dialects/pg/where.d.ts +37 -0
  81. package/dist/runtime/aggregate.d.ts +25 -0
  82. package/dist/runtime/archive-handle.d.ts +18 -0
  83. package/dist/runtime/archive-rules.d.ts +12 -0
  84. package/dist/runtime/archive.d.ts +73 -0
  85. package/dist/runtime/batch.d.ts +20 -0
  86. package/dist/runtime/client.d.ts +114 -5
  87. package/dist/runtime/conflict.d.ts +2 -1
  88. package/dist/runtime/exposure.d.ts +27 -0
  89. package/dist/runtime/hookm.d.ts +39 -0
  90. package/dist/runtime/ids/index.d.ts +11 -0
  91. package/dist/runtime/ids/index.js +193 -0
  92. package/dist/runtime/ids/okid-extended.d.ts +19 -0
  93. package/dist/runtime/ids/okid-generator.d.ts +21 -0
  94. package/dist/runtime/ids/okid-shared.d.ts +89 -0
  95. package/dist/runtime/ids/okid.d.ts +24 -0
  96. package/dist/runtime/ids/uuid.d.ts +21 -0
  97. package/dist/runtime/lock.d.ts +22 -0
  98. package/dist/runtime/operator-sql.d.ts +8 -0
  99. package/dist/runtime/page.d.ts +25 -0
  100. package/dist/runtime/pg/bun.d.ts +30 -0
  101. package/dist/runtime/pg/bun.js +52 -0
  102. package/dist/runtime/pg/pg.d.ts +29 -0
  103. package/dist/runtime/pg/pg.js +52 -0
  104. package/dist/runtime/pg/pglite.js +16 -17
  105. package/dist/runtime/pg/postgresjs.js +14 -24
  106. package/dist/runtime/plan.d.ts +146 -7
  107. package/dist/runtime/preset-stack.d.ts +17 -0
  108. package/dist/runtime/presets.d.ts +48 -0
  109. package/dist/runtime/read-stream.d.ts +26 -0
  110. package/dist/runtime/safety/index.d.ts +159 -0
  111. package/dist/runtime/safety/index.js +294 -0
  112. package/dist/runtime/safety-hook.d.ts +42 -0
  113. package/dist/runtime/server-check.d.ts +34 -0
  114. package/dist/runtime/tenancy/index.d.ts +37 -0
  115. package/dist/runtime/tenancy/index.js +368 -0
  116. package/dist/runtime/trait-read.d.ts +30 -0
  117. package/dist/runtime/traits/index.d.ts +133 -0
  118. package/dist/runtime/traits/index.js +646 -0
  119. package/dist/runtime/transaction.d.ts +19 -0
  120. package/dist/runtime/tx.d.ts +22 -7
  121. package/dist/runtime/types.d.ts +376 -27
  122. package/dist/runtime/validate/bind.d.ts +11 -0
  123. package/dist/runtime/validate/closed.d.ts +16 -0
  124. package/dist/runtime/validate/engine.d.ts +41 -0
  125. package/dist/runtime/validate/hook.d.ts +17 -0
  126. package/dist/runtime/validate/index.d.ts +21 -0
  127. package/dist/runtime/validate/index.js +175 -0
  128. package/dist/runtime/validate/load.d.ts +13 -0
  129. package/dist/runtime/validate/places.d.ts +41 -0
  130. package/dist/runtime/validate/rules.d.ts +108 -0
  131. package/dist/runtime/validate/surface.d.ts +102 -0
  132. package/dist/runtime/write.d.ts +30 -5
  133. package/dist/shared/01yr20s5.js +149 -0
  134. package/dist/shared/0jc3ffzf.js +154 -0
  135. package/dist/shared/0v1g424p.js +26 -0
  136. package/dist/shared/1g0drakv.js +225 -0
  137. package/dist/shared/{kprcwaha.js → 1tfdfvhh.js} +5 -3
  138. package/dist/shared/{05w44d8g.js → 2ssqrv66.js} +767 -715
  139. package/dist/shared/3ekj9x92.js +210 -0
  140. package/dist/shared/49ypnfwt.js +1122 -0
  141. package/dist/shared/4e4c6vq2.js +62 -0
  142. package/dist/shared/4m9fn52z.js +70 -0
  143. package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
  144. package/dist/shared/5nmdenb6.js +1229 -0
  145. package/dist/shared/672t5vym.js +12 -0
  146. package/dist/shared/6bazvqwm.js +86 -0
  147. package/dist/shared/6w5j844a.js +201 -0
  148. package/dist/shared/{fgqgsb5z.js → 75xkjv0t.js} +2 -2
  149. package/dist/shared/7fvtrkwr.js +84 -0
  150. package/dist/shared/7m88x3e9.js +45 -0
  151. package/dist/shared/{mtkwv8wx.js → 7p2wbz7f.js} +1 -1
  152. package/dist/shared/83eaefwr.js +10 -0
  153. package/dist/shared/94ez8kzh.js +19 -0
  154. package/dist/shared/96ps4g1z.js +32 -0
  155. package/dist/shared/{xqbhg6cn.js → 999ade2q.js} +95 -10
  156. package/dist/shared/9m80mkac.js +158 -0
  157. package/dist/shared/9x25fxhc.js +150 -0
  158. package/dist/shared/a5sxz52y.js +13 -0
  159. package/dist/shared/axhk06q1.js +156 -0
  160. package/dist/shared/{dynq16vb.js → b066g80h.js} +8 -6
  161. package/dist/shared/bqha5cg6.js +229 -0
  162. package/dist/shared/bryqk9k9.js +31 -0
  163. package/dist/shared/c8aghh05.js +442 -0
  164. package/dist/shared/c9z5g0fm.js +309 -0
  165. package/dist/shared/{m3ypagh5.js → dbjej1tw.js} +124 -15
  166. package/dist/shared/dyj86cmj.js +69 -0
  167. package/dist/shared/e6wg00wd.js +164 -0
  168. package/dist/shared/{hadrfb9h.js → edwqqryd.js} +17 -14
  169. package/dist/shared/{qk3hxfja.js → fptpmvxp.js} +5 -5
  170. package/dist/shared/fs0ex00p.js +76 -0
  171. package/dist/shared/{jjb7yht9.js → g4f5kcx9.js} +3 -3
  172. package/dist/shared/gjthds9j.js +48 -0
  173. package/dist/shared/hcmdtwgh.js +102 -0
  174. package/dist/shared/{g5fhqmwe.js → jkc6ws1p.js} +6 -56
  175. package/dist/shared/{yd1kzwn2.js → jns2wx4t.js} +55 -12
  176. package/dist/shared/k34e0xf2.js +450 -0
  177. package/dist/shared/k3ted12y.js +33 -0
  178. package/dist/shared/k7dwkhvq.js +31 -0
  179. package/dist/shared/{8b04d28c.js → kgnc8grt.js} +2 -2
  180. package/dist/shared/{hd293j9g.js → kyxb62mc.js} +14 -2
  181. package/dist/shared/m78s7898.js +376 -0
  182. package/dist/shared/m9tv7xn7.js +404 -0
  183. package/dist/shared/meck53jv.js +99 -0
  184. package/dist/shared/mt5wswjz.js +90 -0
  185. package/dist/shared/n0dgs0pb.js +75 -0
  186. package/dist/shared/n442h54c.js +14 -0
  187. package/dist/shared/n4jqhpqz.js +27 -0
  188. package/dist/shared/n7mcc1gk.js +132 -0
  189. package/dist/shared/ne02ng5c.js +68 -0
  190. package/dist/shared/{mkjmqjv4.js → nfzc5z0w.js} +2 -104
  191. package/dist/shared/nsva2a6b.js +42 -0
  192. package/dist/shared/p24x2334.js +195 -0
  193. package/dist/shared/qbxzvwwc.js +88 -0
  194. package/dist/shared/{w8samvk1.js → qybh48nd.js} +1 -1
  195. package/dist/shared/r6nwkxnt.js +86 -0
  196. package/dist/shared/{xy79j5hq.js → rrstp3kb.js} +25 -36
  197. package/dist/shared/rwmrejjz.js +26 -0
  198. package/dist/shared/{zhc5vmgf.js → s6gqfn5j.js} +2 -2
  199. package/dist/shared/{523ft3e8.js → scwxrpx2.js} +7 -5
  200. package/dist/shared/{j5cn2963.js → t4tbsy9h.js} +13 -64
  201. package/dist/shared/{y9m15dfv.js → t616ynfn.js} +544 -32
  202. package/dist/shared/{ngk8gj61.js → tbszx8mz.js} +15 -1
  203. package/dist/shared/th14ygv2.js +69 -0
  204. package/dist/shared/tmbdywx0.js +178 -0
  205. package/dist/shared/ty3v3hfk.js +64 -0
  206. package/dist/shared/wekze34d.js +246 -0
  207. package/dist/shared/x6wysh83.js +1132 -0
  208. package/dist/shared/{rgs0st28.js → xrfnq5k8.js} +237 -434
  209. package/dist/shared/{x5x59srr.js → xva8v7qk.js} +416 -83
  210. package/dist/shared/{dkn3y60a.js → xw1d69vd.js} +76 -112
  211. package/dist/shared/y005b761.js +112 -0
  212. package/dist/shared/ydaz1sv3.js +55 -0
  213. package/dist/shared/{p0cbr3g2.js → zwmqxb0g.js} +1 -1
  214. package/dist/tooling/cli.js +40 -12
  215. package/dist/tooling/migrate/apply.d.ts +16 -0
  216. package/dist/tooling/migrate/commands.d.ts +12 -1
  217. package/dist/tooling/migrate/config.d.ts +8 -0
  218. package/dist/tooling/migrate/doctor.d.ts +25 -0
  219. package/dist/tooling/migrate/drift.d.ts +19 -0
  220. package/dist/tooling/migrate/engine.d.ts +36 -0
  221. package/dist/tooling/migrate/ext.d.ts +17 -0
  222. package/dist/tooling/migrate/extensions.d.ts +51 -0
  223. package/dist/tooling/migrate/managed.d.ts +17 -0
  224. package/dist/tooling/migrate/plan.d.ts +14 -1
  225. package/dist/tooling/migrate/project.d.ts +25 -1
  226. package/dist/tooling/migrate/type-name.d.ts +19 -0
  227. package/package.json +61 -4
  228. package/dist/shared/gk7cs7sp.js +0 -566
@@ -0,0 +1,107 @@
1
+ /**
2
+ * `okmodel/fn`.
3
+ *
4
+ * `fn()` and `trigger()` return objects that produce their own catalog
5
+ * records. `schema()` only asks each declared object for those records.
6
+ */
7
+ import type { CatalogObject, FunctionLanguage, FunctionSecurity, FunctionVolatility, TriggerEvent, TriggerLevel, TriggerTiming } from "../../../contracts/catalog/types.js";
8
+ import type { AnyTable, SqlText } from "../table.js";
9
+ /** One argument of {@link fn}. */
10
+ export type FunctionArgumentInput = {
11
+ readonly name: string;
12
+ readonly type: string;
13
+ };
14
+ /**
15
+ * A table, or one column of a table.
16
+ *
17
+ * A table is an object dependency. `{ table, column }` is a column dependency.
18
+ * `column` is the SQL name.
19
+ */
20
+ export type DependsOn = AnyTable | {
21
+ readonly table: AnyTable;
22
+ readonly column: string;
23
+ };
24
+ /** Options for {@link fn}. */
25
+ export type FunctionOptions = {
26
+ readonly arguments?: readonly FunctionArgumentInput[];
27
+ readonly returns: string;
28
+ readonly language: FunctionLanguage;
29
+ readonly volatility?: FunctionVolatility;
30
+ readonly security?: FunctionSecurity;
31
+ /** Required when `security` is `"definer"` (OKM1823). */
32
+ readonly searchPath?: string;
33
+ readonly body: SqlText | string;
34
+ /**
35
+ * Tables and columns the body uses.
36
+ *
37
+ * Required for plpgsql (OKM1824). Omitted for `LANGUAGE sql` that begins
38
+ * with `BEGIN ATOMIC`; those edges are read from `pg_depend`.
39
+ */
40
+ readonly dependsOn?: readonly DependsOn[];
41
+ /** Schema. The default is `public`. */
42
+ readonly schema?: string;
43
+ };
44
+ /**
45
+ * One declared function.
46
+ *
47
+ * `contribute` builds the catalog record. Overloads differ by argument types.
48
+ */
49
+ export type Routine = {
50
+ readonly name: string;
51
+ readonly schema: string;
52
+ readonly argTypes: readonly string[];
53
+ /**
54
+ * Catalog record for this declaration.
55
+ *
56
+ * @param peers - The `schema({ functions })` list
57
+ * @param built - Objects the schema has already staged
58
+ * @returns The function record
59
+ */
60
+ contribute(peers: unknown, built: unknown): readonly CatalogObject[];
61
+ };
62
+ /** Options for {@link trigger}. */
63
+ export type TriggerOptions = {
64
+ readonly on: AnyTable;
65
+ readonly timing: TriggerTiming;
66
+ readonly events: readonly TriggerEvent[];
67
+ readonly level: TriggerLevel;
68
+ /** `UPDATE OF` columns. SQL names. Each one is a column dependency. */
69
+ readonly updateOf?: readonly string[];
70
+ readonly when?: SqlText | string;
71
+ readonly calls: Routine;
72
+ };
73
+ /**
74
+ * One declared trigger.
75
+ *
76
+ * Identity is `(table, name)`.
77
+ */
78
+ export type TriggerDeclaration = {
79
+ readonly name: string;
80
+ /**
81
+ * Catalog record for this declaration.
82
+ *
83
+ * @param peers - The `schema({ triggers })` list
84
+ * @param built - Objects the schema has already staged
85
+ * @returns The trigger record
86
+ */
87
+ contribute(peers: unknown, built: unknown): readonly CatalogObject[];
88
+ };
89
+ /**
90
+ * Declares a function.
91
+ *
92
+ * plpgsql without `dependsOn` is OKM1824. `security: "definer"` without
93
+ * `searchPath` is OKM1823.
94
+ *
95
+ * @param name - Function name
96
+ * @param options - Signature, language, body, and dependencies
97
+ * @returns The definition object `schema({ functions })` stores
98
+ */
99
+ export declare function fn(name: string, options: FunctionOptions): Routine;
100
+ /**
101
+ * Declares a trigger.
102
+ *
103
+ * @param name - Trigger name, unique on its table
104
+ * @param options - Table, timing, events, and the function it calls
105
+ * @returns The definition object `schema({ triggers })` stores
106
+ */
107
+ export declare function trigger(name: string, options: TriggerOptions): TriggerDeclaration;
@@ -0,0 +1,175 @@
1
+ import {
2
+ functionObject,
3
+ triggerObject
4
+ } from "../../../shared/9x25fxhc.js";
5
+ import {
6
+ staticNamespace2
7
+ } from "../../../shared/t4tbsy9h.js";
8
+ import {
9
+ OkmError2
10
+ } from "../../../shared/52szzakm.js";
11
+
12
+ // src/dialects/pg/fn/index.ts
13
+ function fn(name, options) {
14
+ const language = options.language;
15
+ const body = bodyText(options.body);
16
+ const atomic = language === "sql" && /^\s*begin\s+atomic\b/i.test(body);
17
+ if (language === "plpgsql" && options.dependsOn === undefined) {
18
+ throw new OkmError2("OKM1824", `Function ${name} is plpgsql and has no dependsOn. Postgres does not record dependencies inside the body.`, {
19
+ fix: {
20
+ summary: "List dependsOn. LANGUAGE sql with BEGIN ATOMIC is inferred and does not need the list."
21
+ }
22
+ });
23
+ }
24
+ if (options.security === "definer" && (options.searchPath === undefined || options.searchPath.trim().length === 0)) {
25
+ throw new OkmError2("OKM1823", `Function ${name} is security definer and has no search_path.`, {
26
+ fix: { summary: "Set search_path on the function to the schemas it is allowed to see." }
27
+ });
28
+ }
29
+ const argTypes = (options.arguments ?? []).map((argument) => argument.type);
30
+ const schema = options.schema ?? "public";
31
+ return {
32
+ name,
33
+ schema,
34
+ argTypes,
35
+ contribute(peers, built) {
36
+ assertPeers(peers, "functions");
37
+ const namespace = staticNamespace2(schema);
38
+ const provenance = { origin: "file", name };
39
+ return [
40
+ functionObject({
41
+ namespace,
42
+ name,
43
+ ...options.arguments !== undefined ? { arguments: options.arguments } : {},
44
+ returns: options.returns,
45
+ language,
46
+ ...options.volatility !== undefined ? { volatility: options.volatility } : {},
47
+ ...options.security !== undefined ? { security: options.security } : {},
48
+ ...options.searchPath !== undefined ? { searchPath: options.searchPath } : {},
49
+ body,
50
+ ...atomic ? { atomic: true } : {},
51
+ provenance,
52
+ dependencies: dependencyEdges(options.dependsOn, built)
53
+ })
54
+ ];
55
+ }
56
+ };
57
+ }
58
+ function trigger(name, options) {
59
+ return {
60
+ name,
61
+ contribute(peers, built) {
62
+ assertPeers(peers, "triggers");
63
+ const parent = tableRef(options.on, built);
64
+ const namespace = staticNamespace2(options.calls.schema);
65
+ const calls = {
66
+ namespace,
67
+ name: options.calls.name,
68
+ argTypes: options.calls.argTypes
69
+ };
70
+ if (!hasIdentity(built, { kind: "function", ...calls })) {
71
+ throw new OkmError2("OKM1020", `Trigger ${name} calls ${options.calls.name}, which is not in the catalog.`, { fix: { summary: "List the function in schema({ functions }) before the trigger." } });
72
+ }
73
+ for (const column of options.updateOf ?? []) {
74
+ if (!hasIdentity(built, { kind: "column", parent, name: column })) {
75
+ throw new OkmError2("OKM1020", `Trigger ${name} names column ${column}, which ${parent.name} does not have.`, { fix: { summary: "Name a column of the table the trigger is on." } });
76
+ }
77
+ }
78
+ return [
79
+ triggerObject({
80
+ parent,
81
+ name,
82
+ timing: options.timing,
83
+ events: options.events,
84
+ level: options.level,
85
+ calls,
86
+ ...options.updateOf !== undefined ? { updateOf: options.updateOf } : {},
87
+ ...options.when !== undefined ? { when: bodyText(options.when) } : {},
88
+ provenance: { origin: "file", name }
89
+ })
90
+ ];
91
+ }
92
+ };
93
+ }
94
+ function bodyText(body) {
95
+ return typeof body === "string" ? body : body.text;
96
+ }
97
+ function assertPeers(peers, option) {
98
+ if (!Array.isArray(peers)) {
99
+ throw new OkmError2("OKM1020", `schema({ ${option} }) must be a list.`, {
100
+ fix: { summary: `Pass an array to schema({ ${option} }).` }
101
+ });
102
+ }
103
+ }
104
+ function dependencyEdges(dependsOn, built) {
105
+ if (dependsOn === undefined)
106
+ return [];
107
+ return dependsOn.map((item) => {
108
+ if ("column" in item && "table" in item) {
109
+ const parent = tableRef(item.table, built);
110
+ const edge = { kind: "column", parent, name: item.column };
111
+ if (!hasIdentity(built, edge)) {
112
+ throw new OkmError2("OKM1020", `dependsOn names column ${item.column}, which ${parent.name} does not have.`, { fix: { summary: "Name a column of a table in this schema." } });
113
+ }
114
+ return edge;
115
+ }
116
+ const parent = tableRef(item, built);
117
+ return { kind: "table", namespace: parent.namespace, name: parent.name };
118
+ });
119
+ }
120
+ function tableRef(table, built) {
121
+ if (!Array.isArray(built)) {
122
+ throw new OkmError2("OKM1020", `Table ${table.name} is not in the catalog.`, {
123
+ fix: { summary: "List the table in schema({ tables })." }
124
+ });
125
+ }
126
+ for (const object of built) {
127
+ if (!isRecord(object) || object.kind !== "table")
128
+ continue;
129
+ const identity = object.identity;
130
+ const provenance = object.provenance;
131
+ if (!isRecord(identity) || !isRecord(provenance))
132
+ continue;
133
+ if (provenance.origin === "file" && provenance.name === table.name && typeof identity.name === "string") {
134
+ const namespace = identity.namespace;
135
+ if (isRecord(namespace) && namespace.form === "static" && typeof namespace.name === "string") {
136
+ return { namespace: staticNamespace2(namespace.name), name: identity.name };
137
+ }
138
+ }
139
+ }
140
+ throw new OkmError2("OKM1020", `Table ${table.name} is not in the catalog.`, {
141
+ fix: { summary: "List the table in schema({ tables })." }
142
+ });
143
+ }
144
+ function hasIdentity(built, identity) {
145
+ if (!Array.isArray(built))
146
+ return false;
147
+ for (const object of built) {
148
+ if (!isRecord(object) || !isRecord(object.identity))
149
+ continue;
150
+ if (same(object.identity, identity))
151
+ return true;
152
+ }
153
+ return false;
154
+ }
155
+ function same(left, right) {
156
+ if (left.kind !== right.kind)
157
+ return false;
158
+ if (right.kind === "function") {
159
+ return left.name === right.name && JSON.stringify(left.argTypes) === JSON.stringify(right.argTypes);
160
+ }
161
+ if (right.kind === "column") {
162
+ const parent = left.parent;
163
+ return left.name === right.name && isRecord(parent) && parent.name === right.parent.name;
164
+ }
165
+ if (right.kind === "table")
166
+ return left.name === right.name;
167
+ return false;
168
+ }
169
+ function isRecord(value) {
170
+ return typeof value === "object" && value !== null;
171
+ }
172
+ export {
173
+ fn,
174
+ trigger
175
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The trigger and function `timestamps({ enforce: "trigger" })` contributes.
3
+ *
4
+ * One function per updated-column SQL name. One trigger per table. Provenance
5
+ * is the timestamps trait. The body writes `new.<column> = now()`.
6
+ */
7
+ import type { CatalogObject } from "../../../contracts/catalog/types.js";
8
+ /**
9
+ * Catalog records for tables that carry the timestamps trait.
10
+ *
11
+ * @param built - Objects already staged, including columns
12
+ * @returns The function and one trigger per table, or nothing when no table opted in
13
+ */
14
+ export declare function timestampRecords(built: unknown): readonly CatalogObject[];
@@ -6,13 +6,14 @@
6
6
  */
7
7
  export { schema, type BuiltSchema, type SchemaCodecs, type SchemaInput, type SchemaRequires, } from "./schema.js";
8
8
  export { index, sql, table, type AnyTable, type ColumnHandle, type IndexCall, type SqlText, type SqlValue, type Table, type TableOptions, } from "./table.js";
9
+ export type { PresetQuery } from "./preset.js";
9
10
  export { custom } from "./custom.js";
10
11
  export { ColumnBuilder } from "./column.js";
11
12
  export type { ArrayOf, ColumnFlags, ColumnInsert, ColumnInsertOf, ColumnRow, ColumnRowOf, ColumnUpdate, ColumnUpdateOf, FlagTrue, IdFlags, IdentityFlags, PlainFlags, ReferenceModifier, ReferenceOptions, SqlForm, ValidateModifier, WithGenerated, } from "./column.js";
12
13
  export { bigint, identity, integer, smallint, type BigintAs, type BigintValue } from "./integer.js";
13
14
  export { double, numeric, real, type NumericAs, type NumericValue } from "./decimal.js";
14
15
  export { boolean, bytea } from "./bool.js";
15
- export { json, jsonb, jsonReplacer } from "./json.js";
16
+ export { jsonb, jsonReplacer } from "./json.js";
16
17
  export { id, uuid } from "./keys.js";
17
18
  export { char, citext, text, varchar } from "./text.js";
18
19
  export { date, interval, time, timestamp, timestamptz, timetz } from "./time.js";
@@ -23,7 +24,10 @@ export { line, point, type Line, type Point } from "./geometry.js";
23
24
  export { ltree, tsvector } from "./search.js";
24
25
  export { domain, enumColumn as enum } from "./enum.js";
25
26
  export { t } from "./namespace.js";
27
+ export * as arr from "./ops/arr-ns.js";
28
+ export * as json from "./ops/json-ns.js";
26
29
  export { between } from "./ops/between.js";
30
+ export { containedBy } from "./ops/containedBy.js";
27
31
  export { contains } from "./ops/contains.js";
28
32
  export { endsWith } from "./ops/endsWith.js";
29
33
  export { eq } from "./ops/eq.js";
@@ -32,14 +36,19 @@ export { gt } from "./ops/gt.js";
32
36
  export { inc } from "./ops/inc.js";
33
37
  export { gte } from "./ops/gte.js";
34
38
  export { has } from "./ops/has.js";
39
+ export { hasAnyKey } from "./ops/hasAnyKey.js";
40
+ export { hasKey } from "./ops/hasKey.js";
35
41
  export { ilike } from "./ops/ilike.js";
36
42
  export { inList } from "./ops/inList.js";
37
43
  export { like } from "./ops/like.js";
44
+ export { matches } from "./ops/matches.js";
38
45
  export { lt } from "./ops/lt.js";
39
46
  export { lte } from "./ops/lte.js";
40
47
  export { none } from "./ops/none.js";
41
48
  export { not } from "./ops/not.js";
42
49
  export { notIn } from "./ops/notIn.js";
43
50
  export { or } from "./ops/or.js";
51
+ export { overlaps } from "./ops/overlaps.js";
52
+ export { path } from "./ops/path.js";
44
53
  export { startsWith } from "./ops/startsWith.js";
45
- export { many, one, type ManyRelation, type OneRelation, type RelationCall } from "./relations.js";
54
+ export { many, manyThrough, one, type ManyRelation, type ManyThroughRelation, type OneRelation, type RelationCall, } from "./relations.js";