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,27 @@
1
+ // src/runtime/tx.ts
2
+ async function runWrite(host, statements, options, atomic) {
3
+ if (statements.length === 0)
4
+ return [];
5
+ const first = statements[0];
6
+ const limit = options?.timeout ?? host.timeouts?.statement;
7
+ const call = limit === undefined || limit === options?.timeout ? options : { ...options, timeout: limit };
8
+ const single = statements.length === 1 && first !== undefined && atomic === undefined;
9
+ const watched = host.hookm !== undefined && !single && host.tx === undefined ? await import("./96ps4g1z.js") : undefined;
10
+ watched?.phase(host.hookm, "start", 0);
11
+ let results;
12
+ try {
13
+ results = single ? [await host.pool.execute(first.text, first.params, call)] : await host.pool.batch(statements, call);
14
+ } catch (error) {
15
+ watched?.phase(host.hookm, "rollback", 0);
16
+ throw error;
17
+ }
18
+ watched?.phase(host.hookm, "commit", 0);
19
+ if (host.hookm !== undefined) {
20
+ const heard = results.flatMap((result) => result.notices);
21
+ if (heard.length > 0)
22
+ (await import("./96ps4g1z.js")).notices(host.hookm, heard);
23
+ }
24
+ return results;
25
+ }
26
+
27
+ export { runWrite };
@@ -0,0 +1,132 @@
1
+ import {
2
+ writeArray
3
+ } from "./tmbdywx0.js";
4
+ import {
5
+ OkmError2
6
+ } from "./52szzakm.js";
7
+
8
+ // src/dialects/pg/operator-fit.ts
9
+ var FAMILIES = {
10
+ startsWith: ["text"],
11
+ endsWith: ["text"],
12
+ like: ["text"],
13
+ ilike: ["text"],
14
+ contains: ["text", "array", "jsonb", "range"],
15
+ containedBy: ["array", "jsonb", "range"],
16
+ overlaps: ["array", "range"],
17
+ hasKey: ["jsonb"],
18
+ hasAnyKey: ["jsonb"],
19
+ path: ["json", "jsonb"],
20
+ matches: ["tsvector"],
21
+ "json.set": ["json", "jsonb"],
22
+ "arr.append": ["array"],
23
+ "arr.remove": ["array"]
24
+ };
25
+ var ACCEPTED = {
26
+ text: [
27
+ "eq",
28
+ "not",
29
+ "lt",
30
+ "lte",
31
+ "gt",
32
+ "gte",
33
+ "between",
34
+ "startsWith",
35
+ "contains",
36
+ "endsWith",
37
+ "like",
38
+ "ilike",
39
+ "inList",
40
+ "notIn"
41
+ ],
42
+ array: [
43
+ "eq",
44
+ "not",
45
+ "contains",
46
+ "containedBy",
47
+ "overlaps",
48
+ "inList",
49
+ "notIn",
50
+ "arr.append",
51
+ "arr.remove"
52
+ ],
53
+ jsonb: ["eq", "not", "contains", "containedBy", "hasKey", "hasAnyKey", "path", "json.set"],
54
+ json: ["eq", "not", "path", "json.set"],
55
+ range: ["eq", "not", "lt", "lte", "gt", "gte", "contains", "containedBy", "overlaps"],
56
+ tsvector: ["eq", "not", "matches"],
57
+ scalar: ["eq", "not", "lt", "lte", "gt", "gte", "between", "inList", "notIn", "inc"]
58
+ };
59
+ var SAFE_TYPE = /^[A-Za-z_][A-Za-z0-9_]*(\(\d+\))?(\[\])*$/;
60
+ var REGCONFIG = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?$/;
61
+ function columnFamily(dataType) {
62
+ if (dataType.endsWith("[]"))
63
+ return "array";
64
+ if (dataType === "jsonb")
65
+ return "jsonb";
66
+ if (dataType === "json")
67
+ return "json";
68
+ if (dataType === "tsvector")
69
+ return "tsvector";
70
+ if (dataType.endsWith("range"))
71
+ return "range";
72
+ if (dataType === "text" || dataType === "citext" || dataType.startsWith("varchar(") || dataType.startsWith("char(") || dataType.startsWith("character")) {
73
+ return "text";
74
+ }
75
+ return "scalar";
76
+ }
77
+ function assertOperatorFits(column, name) {
78
+ const families = FAMILIES[name];
79
+ if (families === undefined)
80
+ return;
81
+ if (families.includes(columnFamily(column.dataType)))
82
+ return;
83
+ const accepted = ACCEPTED[columnFamily(column.dataType)];
84
+ const search = name === "matches" && columnFamily(column.dataType) === "text" ? " Text search needs a tsvector column." : "";
85
+ throw new OkmError2("OKM1124", `Operator ${name} does not apply to ${column.dataType} column ${column.field}. Accepted operators: ${accepted.join(", ")}.${search}`, { fix: { summary: `Use one of: ${accepted.join(", ")}.` } });
86
+ }
87
+ function sqlType(dataType, column) {
88
+ if (SAFE_TYPE.test(dataType))
89
+ return dataType;
90
+ assertOperatorFits(column, "contains");
91
+ throw new OkmError2("OKM1124", `Operator contains does not apply to ${column.dataType} column ${column.field}. Accepted operators: ${ACCEPTED[columnFamily(column.dataType)].join(", ")}.`, { fix: { summary: "Use a column type this operator accepts." } });
92
+ }
93
+ function assertNoControl(value, role) {
94
+ for (let index = 0;index < value.length; index += 1) {
95
+ const code = value.charCodeAt(index);
96
+ if (code <= 31 || code === 127) {
97
+ throw new OkmError2("OKM1122", `${role} contains a control character.`, {
98
+ fix: { summary: "Remove NUL and other control characters. The value is not sent." }
99
+ });
100
+ }
101
+ }
102
+ }
103
+ function assertBoundText(value, role) {
104
+ if (value.length === 0) {
105
+ throw new OkmError2("OKM1122", `${role} is empty.`, {
106
+ fix: { summary: "Pass a non-empty key or path segment." }
107
+ });
108
+ }
109
+ assertNoControl(value, role);
110
+ }
111
+ function assertRegconfig(config) {
112
+ if (!REGCONFIG.test(config)) {
113
+ throw new OkmError2("OKM1122", `Text search config ${config} must be a regconfig name such as english or pg_catalog.simple.`, { fix: { summary: "Pass a regconfig name. Quotes and extra clauses are not accepted." } });
114
+ }
115
+ }
116
+ function textArray(values, role) {
117
+ for (const value of values)
118
+ assertBoundText(value, role);
119
+ return writeArray(values, 1, (value) => String(value), false);
120
+ }
121
+ function arrayElementType(dataType, column) {
122
+ if (!dataType.endsWith("[]")) {
123
+ assertOperatorFits(column, "arr.append");
124
+ }
125
+ const element = dataType.slice(0, -2);
126
+ if (!SAFE_TYPE.test(element)) {
127
+ throw new OkmError2("OKM1124", `Operator arr.append does not apply to ${column.dataType} column ${column.field}. Accepted operators: ${ACCEPTED.array.join(", ")}.`, { fix: { summary: "Use arr.append on an array column." } });
128
+ }
129
+ return element;
130
+ }
131
+
132
+ export { assertOperatorFits, sqlType, assertNoControl, assertBoundText, assertRegconfig, textArray, arrayElementType };
@@ -0,0 +1,68 @@
1
+ import {
2
+ open2
3
+ } from "./xw1d69vd.js";
4
+ import"./n442h54c.js";
5
+ import"./t616ynfn.js";
6
+ import {
7
+ assertRoleHealth
8
+ } from "./hcmdtwgh.js";
9
+ import {
10
+ errorDoc,
11
+ selectTarget,
12
+ openProject
13
+ } from "./5nmdenb6.js";
14
+ import {
15
+ omitManagedObjects
16
+ } from "./2ssqrv66.js";
17
+ import {
18
+ OkmError2
19
+ } from "./52szzakm.js";
20
+
21
+ // src/tooling/migrate/doctor.ts
22
+ async function doctorProject(cwd, code, flags) {
23
+ if (code !== undefined) {
24
+ const doc = errorDoc(code);
25
+ if (doc === undefined) {
26
+ throw new OkmError2("invalid", `Unknown code ${code}.`, {
27
+ fix: { summary: "Pass a code from the registry, or run okm doctor with no argument." }
28
+ });
29
+ }
30
+ return `${doc.code}: ${doc.title}
31
+ ${doc.summary}
32
+ ${doc.fix}
33
+ `;
34
+ }
35
+ const opened = await openProject(cwd);
36
+ const objects = omitManagedObjects(opened.built.catalog).objects;
37
+ if (opened.config.roles !== undefined) {
38
+ const target = selectTarget(opened.config, flags?.target);
39
+ const pool = open2({ url: target.url, max: 1 });
40
+ try {
41
+ await assertRoleHealth(pool, opened.config.roles, objects);
42
+ } finally {
43
+ await pool.close();
44
+ }
45
+ }
46
+ return formatTriggers(objects);
47
+ }
48
+ function formatTriggers(objects) {
49
+ const tables = new Map;
50
+ for (const object of objects) {
51
+ if (object.kind !== "trigger")
52
+ continue;
53
+ const table = object.identity.parent.name;
54
+ const names = tables.get(table) ?? [];
55
+ names.push(object.identity.name);
56
+ tables.set(table, names);
57
+ }
58
+ if (tables.size === 0)
59
+ return `no triggers
60
+ `;
61
+ const lines = [...tables.entries()].sort((left, right) => left[0] < right[0] ? -1 : left[0] > right[0] ? 1 : 0).map(([table, names]) => `${table}: ${[...names].sort().join(", ")}`);
62
+ return `${lines.join(`
63
+ `)}
64
+ `;
65
+ }
66
+ export {
67
+ doctorProject
68
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  catalogError2
3
- } from "./ycwz42az.js";
3
+ } from "./52szzakm.js";
4
4
 
5
5
  // src/contracts/utf8.ts
6
6
  function utf8ByteLength2(value) {
@@ -273,109 +273,7 @@ function toHex(bytes) {
273
273
  // src/contracts/catalog/words.ts
274
274
  var words;
275
275
  function reservedWords() {
276
- words ??= new Set([
277
- "all",
278
- "analyse",
279
- "analyze",
280
- "and",
281
- "any",
282
- "array",
283
- "as",
284
- "asc",
285
- "asymmetric",
286
- "authorization",
287
- "binary",
288
- "both",
289
- "case",
290
- "cast",
291
- "check",
292
- "collate",
293
- "collation",
294
- "column",
295
- "concurrently",
296
- "constraint",
297
- "create",
298
- "cross",
299
- "current_catalog",
300
- "current_date",
301
- "current_role",
302
- "current_schema",
303
- "current_time",
304
- "current_timestamp",
305
- "current_user",
306
- "default",
307
- "deferrable",
308
- "desc",
309
- "distinct",
310
- "do",
311
- "else",
312
- "end",
313
- "except",
314
- "false",
315
- "fetch",
316
- "for",
317
- "foreign",
318
- "freeze",
319
- "from",
320
- "full",
321
- "grant",
322
- "group",
323
- "having",
324
- "ilike",
325
- "in",
326
- "initially",
327
- "inner",
328
- "intersect",
329
- "into",
330
- "is",
331
- "isnull",
332
- "join",
333
- "lateral",
334
- "leading",
335
- "left",
336
- "like",
337
- "limit",
338
- "localtime",
339
- "localtimestamp",
340
- "natural",
341
- "not",
342
- "notnull",
343
- "null",
344
- "offset",
345
- "on",
346
- "only",
347
- "or",
348
- "order",
349
- "outer",
350
- "overlaps",
351
- "placing",
352
- "primary",
353
- "references",
354
- "returning",
355
- "right",
356
- "select",
357
- "session_user",
358
- "similar",
359
- "some",
360
- "symmetric",
361
- "system_user",
362
- "table",
363
- "tablesample",
364
- "then",
365
- "to",
366
- "trailing",
367
- "true",
368
- "union",
369
- "unique",
370
- "user",
371
- "using",
372
- "variadic",
373
- "verbose",
374
- "when",
375
- "where",
376
- "window",
377
- "with"
378
- ]);
276
+ words ??= new Set("all analyse analyze and any array as asc asymmetric authorization binary both case cast check collate collation column concurrently constraint create cross current_catalog current_date current_role current_schema current_time current_timestamp current_user default deferrable desc distinct do else end except false fetch for foreign freeze from full grant group having ilike in initially inner intersect into is isnull join lateral leading left like limit localtime localtimestamp natural not notnull null offset on only or order outer overlaps placing primary references returning right select session_user similar some symmetric system_user table tablesample then to trailing true union unique user using variadic verbose when where window with".split(" "));
379
277
  return words;
380
278
  }
381
279
 
@@ -0,0 +1,42 @@
1
+ import {
2
+ OkmError2
3
+ } from "./52szzakm.js";
4
+
5
+ // src/dialects/pg/preset.ts
6
+ var RESERVED_PRESETS = new Set([
7
+ "find",
8
+ "one",
9
+ "page",
10
+ "aggregate",
11
+ "count",
12
+ "exists",
13
+ "insert",
14
+ "update",
15
+ "delete",
16
+ "archive",
17
+ "restore",
18
+ "withArchived",
19
+ "onlyArchived",
20
+ "then",
21
+ "lock",
22
+ "watch",
23
+ "subscribe",
24
+ "stream",
25
+ "inspect",
26
+ "explain",
27
+ "with",
28
+ "for",
29
+ "as"
30
+ ]);
31
+ function checkPresetNames(names, where) {
32
+ for (const name of names) {
33
+ if (!RESERVED_PRESETS.has(name))
34
+ continue;
35
+ throw new OkmError2("OKM1040", `Preset ${name} on ${where} is a client method or a reserved name. Reserved: ${[...RESERVED_PRESETS].join(", ")}.`, { fix: { summary: `Rename the preset ${name}.` } });
36
+ }
37
+ }
38
+ function duplicatePreset(name, table, first, second) {
39
+ throw new OkmError2("OKM1040", `Preset ${name} on ${table} is defined by ${first} and by ${second}.`, { fix: { summary: `Rename the preset in ${first} or in ${second}, or drop one of them.` } });
40
+ }
41
+
42
+ export { checkPresetNames, duplicatePreset };
@@ -0,0 +1,195 @@
1
+ import {
2
+ decodeRows,
3
+ readHandle,
4
+ readCall,
5
+ attachHttp
6
+ } from "./k34e0xf2.js";
7
+ import {
8
+ selectedColumns,
9
+ parseOrder,
10
+ rejectKeys,
11
+ readLimit,
12
+ indexes,
13
+ quote,
14
+ list,
15
+ isRecord,
16
+ registerFailFix,
17
+ fail
18
+ } from "./xrfnq5k8.js";
19
+ import {
20
+ OkmError2,
21
+ throwNamed2
22
+ } from "./52szzakm.js";
23
+
24
+ // src/runtime/page.ts
25
+ registerFailFix("OKM1130", "Request the next page with the same orderBy and the exact next value the previous page returned. The cursor encodes that order.");
26
+ var OPTIONS = [
27
+ "where",
28
+ "select",
29
+ "orderBy",
30
+ "limit",
31
+ "include",
32
+ "after",
33
+ "signal",
34
+ "timeout"
35
+ ];
36
+ function build(session, table, options, mods, view) {
37
+ try {
38
+ return plan(session, table, options, mods, view);
39
+ } catch (error) {
40
+ throw error instanceof OkmError2 ? attachHttp(session.http, error) : error;
41
+ }
42
+ }
43
+ function plan(session, table, options, mods, view) {
44
+ const record = isRecord(options) ? options : {};
45
+ rejectKeys(record, OPTIONS, "page");
46
+ const indexed = indexes(session.schema).get(table);
47
+ if (indexed === undefined)
48
+ fail("OKM1120", `Table ${table} is not in the schema.`);
49
+ if (record.limit === undefined)
50
+ fail("OKM1101", "page() needs a limit.");
51
+ const size = readLimit(record.limit);
52
+ if (size < 1) {
53
+ throw new OkmError2("invalid", "page() limit must be at least 1.", { kind: "invalid" });
54
+ }
55
+ const keys = orderKeys(indexed, record.orderBy);
56
+ const signature = `${table}:${keys.map((key) => `${key.column.field}.${key.dir}.${key.nulls}`).join(",")}`;
57
+ const after = record.after === undefined || record.after === null ? undefined : keyset(keys, signature, record.after);
58
+ const wanted = selectedColumns(indexed, record.select);
59
+ const extra = keys.filter((key) => !wanted.includes(key.column)).map((key) => key.column.field);
60
+ const select = extra.length === 0 ? record.select : [...wanted.map((column) => column.field), ...extra];
61
+ const orderBy = {};
62
+ for (const key of keys)
63
+ orderBy[key.column.field] = { dir: key.dir, nulls: key.nulls };
64
+ const call = {
65
+ ...readCall("find", table, {
66
+ where: record.where,
67
+ select,
68
+ orderBy,
69
+ limit: size + 1,
70
+ include: record.include,
71
+ signal: record.signal,
72
+ timeout: record.timeout
73
+ }, undefined, session.scope, session.schema.model[table], session.schema, view),
74
+ ...after !== undefined ? { after } : {}
75
+ };
76
+ return readHandle(session, table, call, mods, async (compiled, rows) => {
77
+ const items = await decodeRows(compiled, rows, table);
78
+ const more = items.length > size;
79
+ const kept = more ? items.slice(0, size) : items;
80
+ const last = rows[size - 1];
81
+ const next = more && last !== undefined ? makeCursor(compiled, last, keys, signature) : null;
82
+ if (extra.length > 0) {
83
+ for (const item of kept) {
84
+ for (const field of extra)
85
+ delete item[field];
86
+ }
87
+ }
88
+ return { items: kept, next };
89
+ });
90
+ }
91
+ function orderKeys(table, orderBy) {
92
+ if (orderBy !== undefined && !isRecord(orderBy)) {
93
+ fail("OKM1120", "orderBy must be an object of fields.");
94
+ }
95
+ const keys = [];
96
+ for (const field of Object.keys(orderBy ?? {})) {
97
+ const column = table.columns.get(field);
98
+ if (column === undefined) {
99
+ throwNamed2("OKM1120", field, table.names, `Field ${field} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
100
+ }
101
+ keys.push({ column, ...parseOrder(field, orderBy?.[field]) });
102
+ }
103
+ if (table.model.primary.length === 0) {
104
+ fail("OKM1120", `page() needs a primary key on ${table.model.name} to break ties.`);
105
+ }
106
+ for (const field of table.model.primary) {
107
+ const column = table.columns.get(field);
108
+ if (column === undefined || keys.some((key) => key.column === column))
109
+ continue;
110
+ keys.push({ column, dir: "asc", nulls: "last" });
111
+ }
112
+ return keys;
113
+ }
114
+ function keyset(keys, signature, token) {
115
+ const values = readCursor(token, signature, keys.length);
116
+ return (sink, alias) => {
117
+ sink.mark(`k:${signature}:${values.map((value) => value === null ? "n" : "v").join("")}`);
118
+ let wrote = false;
119
+ for (let index = 0;index < keys.length; index += 1) {
120
+ const key = keys[index];
121
+ const value = values[index];
122
+ if (key === undefined || value === undefined)
123
+ continue;
124
+ if (value === null && key.nulls === "last")
125
+ continue;
126
+ sink.text(wrote ? " or (" : "(");
127
+ wrote = true;
128
+ for (let before = 0;before < index; before += 1) {
129
+ const prior = keys[before];
130
+ const held = values[before];
131
+ if (prior === undefined || held === undefined)
132
+ continue;
133
+ const ref = `${alias}.${quote(prior.column.sql)}`;
134
+ if (held === null) {
135
+ sink.text(`${ref} is null and `);
136
+ } else {
137
+ sink.text(`${ref} = `);
138
+ sink.param(held);
139
+ sink.text(" and ");
140
+ }
141
+ }
142
+ const ref = `${alias}.${quote(key.column.sql)}`;
143
+ if (value === null) {
144
+ sink.text(`${ref} is not null`);
145
+ } else {
146
+ sink.text(key.nulls === "last" ? `(${ref} ${compare(key)} ` : `${ref} ${compare(key)} `);
147
+ sink.param(value);
148
+ sink.text(key.nulls === "last" ? ` or ${ref} is null)` : "");
149
+ }
150
+ sink.text(")");
151
+ }
152
+ if (!wrote)
153
+ sink.text("false");
154
+ };
155
+ }
156
+ function compare(key) {
157
+ return key.dir === "asc" ? ">" : "<";
158
+ }
159
+ function makeCursor(plan, row, keys, signature) {
160
+ const values = keys.map((key) => {
161
+ const at = plan.outputs.fields.find((field) => field.key === key.column.field)?.at;
162
+ return at === undefined ? null : row[at] ?? null;
163
+ });
164
+ const bytes = new TextEncoder().encode(JSON.stringify([signature, ...values]));
165
+ let binary = "";
166
+ for (const byte of bytes)
167
+ binary += String.fromCharCode(byte);
168
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
169
+ }
170
+ function readCursor(token, signature, count) {
171
+ let parsed;
172
+ if (typeof token === "string") {
173
+ try {
174
+ const binary = atob(token.replaceAll("-", "+").replaceAll("_", "/"));
175
+ const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
176
+ parsed = JSON.parse(new TextDecoder().decode(bytes));
177
+ } catch {
178
+ parsed = undefined;
179
+ }
180
+ }
181
+ if (!Array.isArray(parsed) || typeof parsed[0] !== "string") {
182
+ fail("OKM1130", "after is not a cursor that page() returned.");
183
+ }
184
+ if (parsed[0] !== signature) {
185
+ fail("OKM1130", `The cursor was made for another order: ${parsed[0]}. This page orders by ${signature}.`);
186
+ }
187
+ const values = parsed.slice(1);
188
+ if (values.length !== count || !values.every((value) => value === null || typeof value === "string")) {
189
+ fail("OKM1130", "after is not a cursor that page() returned.");
190
+ }
191
+ return values;
192
+ }
193
+ export {
194
+ build
195
+ };
@@ -0,0 +1,88 @@
1
+ import {
2
+ assertNamespace2,
3
+ normaliseEdges,
4
+ assertProvenance
5
+ } from "./t4tbsy9h.js";
6
+ import {
7
+ assertIdentifier2,
8
+ assertStoredText
9
+ } from "./nfzc5z0w.js";
10
+ import {
11
+ catalogError2
12
+ } from "./52szzakm.js";
13
+
14
+ // src/contracts/catalog/enum.ts
15
+ function enumType(input) {
16
+ assertNamespace2(input.namespace);
17
+ assertIdentifier2(input.name, "type");
18
+ assertProvenance(input.provenance);
19
+ if (input.labels.length === 0) {
20
+ catalogError2("OKM1020", `Enum ${input.name} must list at least one label.`);
21
+ }
22
+ const labels = [];
23
+ const seen = new Set;
24
+ for (const label of input.labels) {
25
+ assertStoredText(label, "enum label");
26
+ if (label.length === 0) {
27
+ catalogError2("OKM1020", `Enum ${input.name} has an empty label.`);
28
+ }
29
+ if (seen.has(label)) {
30
+ catalogError2("OKM1020", `Enum ${input.name} repeats label ${label}.`);
31
+ }
32
+ seen.add(label);
33
+ labels.push(label);
34
+ }
35
+ const identity = {
36
+ kind: "type",
37
+ namespace: input.namespace,
38
+ name: input.name
39
+ };
40
+ return {
41
+ kind: "type",
42
+ identity,
43
+ owner: input.owner ?? "managed",
44
+ definition: { labels },
45
+ dependencies: normaliseEdges(input.dependencies ?? []),
46
+ provenance: input.provenance
47
+ };
48
+ }
49
+ function domainType(input) {
50
+ assertNamespace2(input.namespace);
51
+ assertIdentifier2(input.name, "type");
52
+ assertProvenance(input.provenance);
53
+ if (input.base.length === 0) {
54
+ catalogError2("OKM1020", `Domain ${input.name} needs a base type.`);
55
+ }
56
+ assertStoredText(input.check, "domain check");
57
+ if (input.check.length === 0) {
58
+ catalogError2("OKM1020", `Domain ${input.name} needs a check.`);
59
+ }
60
+ const identity = {
61
+ kind: "type",
62
+ namespace: input.namespace,
63
+ name: input.name
64
+ };
65
+ const definition = { base: input.base, check: input.check };
66
+ return {
67
+ kind: "type",
68
+ identity,
69
+ owner: input.owner ?? "managed",
70
+ definition,
71
+ dependencies: normaliseEdges(input.dependencies ?? []),
72
+ provenance: input.provenance
73
+ };
74
+ }
75
+ function isDomain(definition) {
76
+ return "base" in definition;
77
+ }
78
+ function sameEnumLabels(left, right) {
79
+ if (left.length !== right.length)
80
+ return false;
81
+ for (let index = 0;index < left.length; index += 1) {
82
+ if (left[index] !== right[index])
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+
88
+ export { enumType, domainType, isDomain, sameEnumLabels };
@@ -6,7 +6,7 @@ import {
6
6
  catalogHash2,
7
7
  loadTrustedCatalog2,
8
8
  parseCatalog2
9
- } from "./y9m15dfv.js";
9
+ } from "./t616ynfn.js";
10
10
  export {
11
11
  catalogHash2 as catalogHash,
12
12
  creationOrder2 as creationOrder,