okmodel 0.8.0 → 0.9.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.
- package/README.md +23 -1
- package/dist/adapters/pg/bunsql-extra.d.ts +5 -5
- package/dist/adapters/pg/bunsql.d.ts +6 -2
- package/dist/adapters/pg/nodepostgres.d.ts +16 -1
- package/dist/adapters/pg/postgres-extra.d.ts +3 -17
- package/dist/adapters/pg/postgresjs.d.ts +2 -1
- package/dist/contracts/driver.d.ts +3 -2
- package/dist/contracts/error.d.ts +1 -1
- package/dist/dialects/pg/errors.d.ts +2 -0
- package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
- package/dist/dialects/pg/ext/btree-gin.js +20 -0
- package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
- package/dist/dialects/pg/ext/btree-gist.js +20 -0
- package/dist/dialects/pg/ext/call.d.ts +53 -0
- package/dist/dialects/pg/ext/citext.js +1 -1
- package/dist/dialects/pg/ext/feature.d.ts +26 -0
- package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
- package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
- package/dist/dialects/pg/ext/hstore.d.ts +41 -0
- package/dist/dialects/pg/ext/hstore.js +29 -0
- package/dist/dialects/pg/ext/index.d.ts +56 -0
- package/dist/dialects/pg/ext/index.js +1 -1
- package/dist/dialects/pg/ext/ltree.d.ts +41 -0
- package/dist/dialects/pg/ext/ltree.js +29 -0
- package/dist/dialects/pg/ext/pg-trgm.js +4 -13
- package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
- package/dist/dialects/pg/ext/pgcrypto.js +33 -0
- package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
- package/dist/dialects/pg/ext/unaccent.js +21 -0
- package/dist/dialects/pg/ext/using.d.ts +23 -0
- package/dist/dialects/pg/ext/versions.d.ts +36 -0
- package/dist/dialects/pg/external.d.ts +19 -0
- package/dist/dialects/pg/filters.d.ts +2 -2
- package/dist/dialects/pg/fn/index.js +5 -5
- package/dist/dialects/pg/index.d.ts +1 -0
- package/dist/dialects/pg/index.js +19 -14
- package/dist/dialects/pg/introspect.d.ts +12 -0
- package/dist/dialects/pg/view/index.js +7 -7
- package/dist/dialects/pg/view/scratch.d.ts +4 -1
- package/dist/runtime/artifact-file.d.ts +22 -0
- package/dist/runtime/client.d.ts +10 -0
- package/dist/runtime/drift-detail.d.ts +2 -1
- package/dist/runtime/drift.d.ts +3 -10
- package/dist/runtime/param-limit.d.ts +20 -0
- package/dist/runtime/pg/bun.js +4 -4
- package/dist/runtime/pg/neon.js +4 -4
- package/dist/runtime/pg/pg.js +4 -4
- package/dist/runtime/pg/pglite.js +4 -4
- package/dist/runtime/pg/postgresjs.js +11 -11
- package/dist/runtime/server-check.d.ts +36 -6
- package/dist/runtime/tenancy/index.js +1 -1
- package/dist/runtime/traits/index.js +6 -6
- package/dist/runtime/validate/index.js +2 -2
- package/dist/runtime/write.d.ts +1 -1
- package/dist/shared/{4m6hskg8.js → 0j6qe91y.js} +4 -4
- package/dist/shared/{6m78c8ss.js → 1h5h1rf5.js} +1 -1
- package/dist/shared/{4vbf83xx.js → 2vcnpf0n.js} +1 -1
- package/dist/shared/{qd9hhd8f.js → 3ap5hxvj.js} +2 -1
- package/dist/shared/{v1wad97q.js → 3d7a80fq.js} +1 -1
- package/dist/shared/{wcrheftc.js → 3dr444ny.js} +58 -79
- package/dist/shared/{hm5f8jby.js → 3vvpcphd.js} +8 -7
- package/dist/shared/{760ppr76.js → 4a3mmhhe.js} +2 -2
- package/dist/shared/{mkrn359n.js → 4pkz5nvw.js} +222 -39
- package/dist/shared/{agsfb86s.js → 4te76xc5.js} +4 -4
- package/dist/shared/{63f4ksbz.js → 60y4ahmw.js} +1 -1
- package/dist/shared/61bmrmhr.js +35 -0
- package/dist/shared/{bxas03mq.js → 63qjmhnp.js} +100 -17
- package/dist/shared/{g5yc06ka.js → 67w3kn71.js} +1 -1
- package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
- package/dist/shared/{njga14v4.js → 6vfvsdkt.js} +10 -8
- package/dist/shared/{kj9d8maq.js → 6xqvesa5.js} +1 -1
- package/dist/shared/8gdbty5v.js +665 -0
- package/dist/shared/{pan0370z.js → 8ma6drzr.js} +211 -30
- package/dist/shared/{mnvjvqyp.js → 8p2bgye0.js} +124 -32
- package/dist/shared/{mfedzr74.js → 8qwqrxed.js} +14 -6
- package/dist/shared/{hfqmpasr.js → 8v7vzpgt.js} +11 -8
- package/dist/shared/{7ghwamrf.js → 99qp9vtg.js} +1 -1
- package/dist/shared/{zgex00fd.js → ak61ye1f.js} +5 -5
- package/dist/shared/{dpc2r7rb.js → bdekbvmt.js} +218 -95
- package/dist/shared/{jebgrkeq.js → bxjq6xqv.js} +2 -2
- package/dist/shared/c7dqd3gk.js +1806 -0
- package/dist/shared/ddh72ym5.js +20 -0
- package/dist/shared/e1c55v04.js +10 -0
- package/dist/shared/{mtw6jz76.js → e275q7sd.js} +1 -1
- package/dist/shared/{k86n8vq3.js → ekhq3ytz.js} +1 -1
- package/dist/shared/esy4dyxe.js +17 -0
- package/dist/shared/{gcefca6p.js → f9t9g54z.js} +22 -9
- package/dist/shared/{sjk86yrx.js → fk9vef30.js} +84 -73
- package/dist/shared/fkjne6gx.js +8 -0
- package/dist/shared/{e8zyaqvj.js → fne90dvz.js} +4 -1
- package/dist/shared/{needfe47.js → g89fmz5s.js} +1 -1
- package/dist/shared/{m4xff2a6.js → ghqzdp94.js} +2 -2
- package/dist/shared/{n0jmpgj1.js → gr9sn4za.js} +1 -1
- package/dist/shared/{5mtf6cj3.js → gzgfsspx.js} +5 -2
- package/dist/shared/h9811jjm.js +17 -0
- package/dist/shared/{z581d7ny.js → hgt69zjf.js} +2 -2
- package/dist/shared/{35q0n9tz.js → jvxcp1qk.js} +71 -87
- package/dist/shared/k73e8n9d.js +136 -0
- package/dist/shared/{195pzzzz.js → kzgrcy8s.js} +12 -8
- package/dist/shared/kzgrnckd.js +29 -0
- package/dist/shared/{p3xbdcvt.js → mz48rs74.js} +68 -8
- package/dist/shared/{zbqbmmrp.js → n6je5b28.js} +13 -26
- package/dist/shared/{b6d6p0zc.js → ns35jqz0.js} +75 -49
- package/dist/shared/{n05z9nwz.js → nstwgzn8.js} +1 -1
- package/dist/{tooling/shared/08kemxjd.js → shared/pgsak1yw.js} +1 -1
- package/dist/shared/py2zrrm6.js +451 -0
- package/dist/shared/{9dr2qnx7.js → qqm3ze6q.js} +1 -1
- package/dist/shared/{wvdjznah.js → rcjm0yn7.js} +31 -38
- package/dist/shared/rged92v6.js +17 -0
- package/dist/shared/{jp36k7dp.js → rw4tpcd0.js} +81 -51
- package/dist/shared/{bsek72fg.js → s5qe47a6.js} +3 -0
- package/dist/shared/{1d9q9cv2.js → smxzjz60.js} +2 -2
- package/dist/shared/{wz2a78mp.js → th5rnaxw.js} +1 -1
- package/dist/{tooling/shared/rs1jb051.js → shared/tr64w5p0.js} +1 -1
- package/dist/shared/{14x60fbf.js → tyqapcgk.js} +73 -10
- package/dist/shared/vsna85qf.js +8 -0
- package/dist/shared/{63qtkrca.js → vy47ryqa.js} +55 -5
- package/dist/shared/{jx2m62cs.js → wbdh9qbg.js} +7 -5
- package/dist/shared/{f4jy1j7x.js → wp7y8q3y.js} +946 -105
- package/dist/shared/{16kvjebh.js → xbd9xs6p.js} +7 -26
- package/dist/shared/{bah9nbg3.js → xbvz446k.js} +18 -23
- package/dist/shared/{p5nh3r8q.js → y6tfjk9q.js} +2 -2
- package/dist/shared/{3bb7wsqt.js → ycnft340.js} +1 -1
- package/dist/shared/{z7s6fpxv.js → ymenf259.js} +1 -1
- package/dist/shared/{0wrea3jq.js → ysdw2fg3.js} +10 -2
- package/dist/shared/zecrwdk9.js +61 -0
- package/dist/shared/{3t6kw83m.js → zm2rzqba.js} +2 -1
- package/dist/tooling/cli.js +200 -50
- package/dist/tooling/driver-run.js +109 -343
- package/dist/tooling/github/comment.d.ts +56 -0
- package/dist/tooling/github/post-comment.d.ts +17 -0
- package/dist/tooling/migrate/apply.d.ts +17 -2
- package/dist/tooling/migrate/commands.d.ts +2 -1
- package/dist/tooling/migrate/config.d.ts +13 -0
- package/dist/tooling/migrate/drift.d.ts +12 -0
- package/dist/tooling/migrate/driver-url.d.ts +17 -0
- package/dist/tooling/migrate/export.d.ts +165 -0
- package/dist/tooling/migrate/ext-surface.d.ts +80 -0
- package/dist/tooling/migrate/ext.d.ts +31 -4
- package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
- package/dist/tooling/migrate/index.d.ts +3 -0
- package/dist/tooling/migrate/index.js +57 -10
- package/dist/tooling/migrate/lint-rules.d.ts +18 -1
- package/dist/tooling/migrate/lint.d.ts +14 -1
- package/dist/tooling/migrate/place.d.ts +18 -0
- package/dist/tooling/migrate/plan-json.d.ts +65 -0
- package/dist/tooling/migrate/policy.d.ts +17 -5
- package/dist/tooling/migrate/pooler-probe.d.ts +23 -0
- package/dist/tooling/migrate/project.d.ts +10 -1
- package/dist/tooling/migrate/pull-emit.d.ts +98 -0
- package/dist/tooling/migrate/pull-routines.d.ts +126 -0
- package/dist/tooling/migrate/pull-verify.d.ts +26 -0
- package/dist/tooling/migrate/pull.d.ts +65 -0
- package/dist/tooling/migrate/reprint.d.ts +32 -0
- package/dist/tooling/migrate/runner.d.ts +24 -1
- package/dist/tooling/migrate/sandbox.d.ts +8 -2
- package/dist/tooling/migrate/schema-api.d.ts +43 -0
- package/dist/tooling/migrate/sql-lex.d.ts +18 -0
- package/dist/tooling/shared/{ppnnnvj8.js → 09a6vsys.js} +1 -1
- package/dist/tooling/shared/{7ae7rjmn.js → 0v9ptnxp.js} +8 -8
- package/dist/tooling/shared/{fb9k2qwd.js → 0wtzps9p.js} +11 -30
- package/dist/tooling/shared/{a6pp9d12.js → 0yhf1db4.js} +6 -6
- package/dist/tooling/shared/{dy672fz6.js → 19msgrsc.js} +2 -2
- package/dist/{shared/q0cqt2sp.js → tooling/shared/1fwfm5m3.js} +1 -1
- package/dist/tooling/shared/{f9mphxej.js → 2jdn09e2.js} +401 -24
- package/dist/tooling/shared/{jne7b93p.js → 2qrte2ct.js} +5 -5
- package/dist/tooling/shared/{5bvw2nev.js → 2v4nwnkb.js} +1 -1
- package/dist/tooling/shared/{spk1jg3r.js → 33z39trp.js} +106 -23
- package/dist/tooling/shared/{z8d7ptht.js → 353vnw9z.js} +5 -5
- package/dist/tooling/shared/{dw08f3m8.js → 390kry9g.js} +2 -2
- package/dist/tooling/shared/{xjs6zqtc.js → 3f6etb9z.js} +18 -31
- package/dist/{shared/bnby0esn.js → tooling/shared/3t2cqmsx.js} +1 -1
- package/dist/tooling/shared/{wwnekq5n.js → 4dzvjtpy.js} +1 -1
- package/dist/tooling/shared/{y5656f0e.js → 4ec0nxvw.js} +10 -10
- package/dist/tooling/shared/{3m1hkg7z.js → 4tg2bn41.js} +59 -78
- package/dist/tooling/shared/{zvnhh1n0.js → 5rah55z0.js} +2 -2
- package/dist/tooling/shared/{pqy21k24.js → 804w1t69.js} +4 -4
- package/dist/tooling/shared/8g0m0rvd.js +134 -0
- package/dist/tooling/shared/8msbtw5s.js +8 -0
- package/dist/tooling/shared/{4d2w25vw.js → 8t22h3h7.js} +2 -2
- package/dist/tooling/shared/{smn6kz1p.js → 91c59b7b.js} +2 -2
- package/dist/tooling/shared/{aftb2mwr.js → adk9k6va.js} +1 -1
- package/dist/tooling/shared/{j9t5s12a.js → ajjd5cwz.js} +2 -2
- package/dist/tooling/shared/{cmptmb4f.js → angjck01.js} +1 -1
- package/dist/tooling/shared/{yw30vnq2.js → asnnc3v5.js} +1 -1
- package/dist/tooling/shared/{ma2340rx.js → bj1kyqc8.js} +2 -2
- package/dist/tooling/shared/{2wtvc7rw.js → bt3tjemb.js} +11 -3
- package/dist/tooling/shared/{ec71zqgt.js → chk2bh4f.js} +2 -2
- package/dist/tooling/shared/{gmcf9cxf.js → ckq4z5ax.js} +5 -2
- package/dist/tooling/shared/{w7qe8sj1.js → d3rhb24q.js} +1 -1
- package/dist/tooling/shared/{y031jct9.js → d8q00vxg.js} +4 -4
- package/dist/tooling/shared/{vs0t6qt8.js → dx188rxs.js} +2 -2
- package/dist/tooling/shared/{g9ad4n80.js → efq6p9df.js} +35 -42
- package/dist/tooling/shared/{ddjtfgnx.js → en6rwzq0.js} +3 -3
- package/dist/tooling/shared/{6nyfyw70.js → f2r5g0fs.js} +2 -2
- package/dist/tooling/shared/{03k6res6.js → f4gep0nk.js} +1 -1
- package/dist/tooling/shared/{gfvtj6d0.js → f8a010fm.js} +13 -11
- package/dist/tooling/shared/{3tq8pnb8.js → fdsek6pa.js} +1 -1
- package/dist/tooling/shared/fvmrxsd1.js +8 -0
- package/dist/tooling/shared/{733a1tq3.js → g3xybeqf.js} +4 -3
- package/dist/tooling/shared/{pwsytxm5.js → gefmpwsa.js} +1 -1
- package/dist/tooling/shared/{mtrqn2hn.js → gjj71hfh.js} +25 -30
- package/dist/tooling/shared/{8sqrsw3s.js → jgzt69pa.js} +5 -5
- package/dist/tooling/shared/{nf7jmhfa.js → jm30k2ca.js} +10 -8
- package/dist/tooling/shared/{vx86qjv8.js → kayqzpbk.js} +6 -3
- package/dist/tooling/shared/{zhwnfyb2.js → kvw1672d.js} +1 -1
- package/dist/tooling/shared/{rq5kk8j6.js → mr1kcgpw.js} +3 -3
- package/dist/tooling/shared/{72fyg4zv.js → mwbdf409.js} +1 -1
- package/dist/tooling/shared/{wt7j7nf6.js → ns9207v3.js} +1 -1
- package/dist/tooling/shared/{9xzm7hjg.js → p6tjv97k.js} +3 -3
- package/dist/tooling/shared/{yfr8hzhm.js → p73evwf0.js} +1 -1
- package/dist/tooling/shared/{dzx85q70.js → phc1nc4g.js} +1 -1
- package/dist/tooling/shared/{417zdsk7.js → ppybjw50.js} +79 -16
- package/dist/tooling/shared/{yk9mp7vb.js → qdrn8ghn.js} +5 -4
- package/dist/tooling/shared/rd8h01ta.js +20 -0
- package/dist/tooling/shared/{bz2dqhab.js → rwg8y90m.js} +3 -3
- package/dist/tooling/shared/{xhrnjch9.js → ry2f3w8p.js} +3 -3
- package/dist/tooling/shared/{a7q7t4n3.js → ryc5sa58.js} +8 -8
- package/dist/tooling/shared/{2revefqt.js → ss87qxwv.js} +2 -2
- package/dist/tooling/shared/{rf83gr2d.js → vg68k11z.js} +7 -3
- package/dist/tooling/shared/{p7f08ktn.js → vms9dta5.js} +73 -89
- package/dist/tooling/shared/{3rrw5w8f.js → xchpnbdv.js} +1 -1
- package/dist/tooling/shared/{djydjpqt.js → xn6p01fh.js} +5 -5
- package/dist/tooling/shared/{9kazs5p6.js → xwr6q618.js} +3 -3
- package/dist/tooling/shared/{ep8zh3bk.js → xx3gmq94.js} +1 -1
- package/dist/tooling/shared/{tn8gay14.js → y2bd7yfx.js} +21 -13
- package/dist/tooling/shared/{vraj6d74.js → y4gq9rbe.js} +11 -11
- package/dist/tooling/shared/y4vwft92.js +9 -0
- package/dist/tooling/shared/{345tbc2k.js → yz68xcmc.js} +1 -1
- package/dist/tooling/testing/factories.d.ts +1 -3
- package/dist/tooling/testing/index.js +2 -2
- package/package.json +39 -9
- package/dist/shared/3449rcae.js +0 -14
- package/dist/shared/fjpnhqan.js +0 -71
- package/dist/shared/n41w4fbz.js +0 -113
- package/dist/tooling/shared/pw8fgahx.js +0 -69
- /package/dist/shared/{ae4j5f42.js → mfvx6kjx.js} +0 -0
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertParamCount2
|
|
3
|
+
} from "./ddh72ym5.js";
|
|
1
4
|
import {
|
|
2
5
|
stack2
|
|
3
6
|
} from "./mss6ctgv.js";
|
|
@@ -29,6 +32,7 @@ import {
|
|
|
29
32
|
decodeRow,
|
|
30
33
|
indexes,
|
|
31
34
|
quote,
|
|
35
|
+
list,
|
|
32
36
|
isRecord,
|
|
33
37
|
registerFailFix,
|
|
34
38
|
fail2
|
|
@@ -163,7 +167,7 @@ async function prepareWrite(host, op, table, input, options, mods, scope) {
|
|
|
163
167
|
return {
|
|
164
168
|
statements: planned.statements,
|
|
165
169
|
options: callOptions(options),
|
|
166
|
-
...planned.parentGuard === true ? { checked: "parent" } : planned.expect !== undefined ? { checked: "expect" } : {},
|
|
170
|
+
...planned.parentGuard === true ? { checked: "parent" } : planned.treeGuard === true ? { checked: "tree" } : planned.expect !== undefined ? { checked: "expect" } : {},
|
|
167
171
|
...planned.recover === undefined ? {} : {
|
|
168
172
|
follow: (results) => planned.recover?.(decodePlanned(withoutQuiet(results, planned.quiet), planned.outputs)) ?? []
|
|
169
173
|
},
|
|
@@ -198,7 +202,7 @@ async function planWrite(schema, generators, op, tableName, input, options, mods
|
|
|
198
202
|
}
|
|
199
203
|
if (op === "update") {
|
|
200
204
|
if (traitNamed(table, "versioned")) {
|
|
201
|
-
const { planVersioned } = await import("./
|
|
205
|
+
const { planVersioned } = await import("./zm2rzqba.js");
|
|
202
206
|
return withRowFilters(scope, mods.archive, () => {
|
|
203
207
|
noteArchive(table, mods.archive);
|
|
204
208
|
const planned = planVersioned(schema, table, input, record, mods);
|
|
@@ -244,7 +248,7 @@ async function planInsert(table, input, options, mods, generators, scope, tenanc
|
|
|
244
248
|
keyColumns: undefined
|
|
245
249
|
};
|
|
246
250
|
}
|
|
247
|
-
const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./
|
|
251
|
+
const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./60y4ahmw.js");
|
|
248
252
|
const conflict = conflictMod?.readConflict(table, options.onConflict, allow, tenantKeyList(tenancy));
|
|
249
253
|
if (conflict?.kind === "update" && traitNamed(table, "versioned")) {
|
|
250
254
|
fail2("OKM1120", `onConflict update on ${table.model.name} does not check the version you read.`, "Read the row and update. ignore and return do not change the existing row.");
|
|
@@ -308,7 +312,7 @@ function planUpdate(schema, table, input, options, mods, scope) {
|
|
|
308
312
|
rejectDuplicateTargets2(table, rows);
|
|
309
313
|
rejectMixedSets2(rows);
|
|
310
314
|
for (const row of rows)
|
|
311
|
-
refuseTreeCycle(table, row.where, row.set, schema.tenancy
|
|
315
|
+
refuseTreeCycle(table, row.where, row.set, tenantKeys(schema.tenancy));
|
|
312
316
|
const moves = rows.some((row) => pathField(schema.tenancy, table.model.name, row.set) !== undefined);
|
|
313
317
|
if (moves) {
|
|
314
318
|
return {
|
|
@@ -338,7 +342,8 @@ function planUpdate(schema, table, input, options, mods, scope) {
|
|
|
338
342
|
requireFilter2(table, input.where, mods, "update");
|
|
339
343
|
if (Object.keys(set).length === 0)
|
|
340
344
|
fail2("OKM1120", "update set is empty.");
|
|
341
|
-
|
|
345
|
+
const keys = tenantKeys(schema.tenancy);
|
|
346
|
+
const cycle = refuseTreeCycle(table, input.where, set, keys);
|
|
342
347
|
const where = stack2(input.where, mods.presets);
|
|
343
348
|
const moved = pathAssignment(schema.tenancy, table.model.name, set, scope);
|
|
344
349
|
if (moved !== undefined && claim !== undefined) {
|
|
@@ -365,6 +370,17 @@ function planUpdate(schema, table, input, options, mods, scope) {
|
|
|
365
370
|
keyColumns: undefined
|
|
366
371
|
};
|
|
367
372
|
}
|
|
373
|
+
if (cycle !== undefined) {
|
|
374
|
+
return {
|
|
375
|
+
statements: [treeSetUpdate(schema, table, where, set, cycle, returning)],
|
|
376
|
+
outputs: parentOutputs(returning),
|
|
377
|
+
shape: returning === undefined ? "count" : "rows",
|
|
378
|
+
expect,
|
|
379
|
+
keys: undefined,
|
|
380
|
+
keyColumns: undefined,
|
|
381
|
+
treeGuard: true
|
|
382
|
+
};
|
|
383
|
+
}
|
|
368
384
|
const sql = new Sql2;
|
|
369
385
|
sql.text("update ");
|
|
370
386
|
sql.text(quote(table.model.sql));
|
|
@@ -411,6 +427,8 @@ function finish(results, planned, table) {
|
|
|
411
427
|
return finishVersioned(results, planned, table);
|
|
412
428
|
if (planned.parentGuard === true)
|
|
413
429
|
return finishParent(results, planned, table);
|
|
430
|
+
if (planned.treeGuard === true)
|
|
431
|
+
return finishTree(results, planned, table);
|
|
414
432
|
if (planned.shape === "count") {
|
|
415
433
|
let count = 0;
|
|
416
434
|
for (const result of results)
|
|
@@ -439,6 +457,18 @@ function finishParent(results, planned, table) {
|
|
|
439
457
|
fix: { summary: "Point the foreign key at a parent in this tenant." }
|
|
440
458
|
});
|
|
441
459
|
}
|
|
460
|
+
return finishGuarded(results, planned, table, updated);
|
|
461
|
+
}
|
|
462
|
+
function finishTree(results, planned, table) {
|
|
463
|
+
const row = results[0]?.rows[0];
|
|
464
|
+
const matched = countCell(row?.[0]);
|
|
465
|
+
const updated = countCell(row?.[1]);
|
|
466
|
+
if (updated < matched) {
|
|
467
|
+
fail2("OKM1120", `update on ${table} cannot point a tree row at itself or its descendant.`, "Set the parent to another row that is not under this one. A filter that is not the primary key is not checked.");
|
|
468
|
+
}
|
|
469
|
+
return finishGuarded(results, planned, table, updated);
|
|
470
|
+
}
|
|
471
|
+
function finishGuarded(results, planned, table, updated) {
|
|
442
472
|
if (planned.shape === "count") {
|
|
443
473
|
checkExpect(updated, planned.expect, table, "write");
|
|
444
474
|
return { count: updated };
|
|
@@ -1074,6 +1104,7 @@ class Sql2 {
|
|
|
1074
1104
|
};
|
|
1075
1105
|
}
|
|
1076
1106
|
statement() {
|
|
1107
|
+
assertParamCount2(this.params.length);
|
|
1077
1108
|
return this.params.length === 0 ? { text: this.parts.join("") } : { text: this.parts.join(""), params: this.params };
|
|
1078
1109
|
}
|
|
1079
1110
|
}
|
|
@@ -1084,7 +1115,7 @@ function insertRow(table, value, allow, tenancy) {
|
|
|
1084
1115
|
for (const key of Object.keys(value)) {
|
|
1085
1116
|
const column = table.columns.get(key);
|
|
1086
1117
|
if (column === undefined)
|
|
1087
|
-
|
|
1118
|
+
refuseUnknownField(table, key);
|
|
1088
1119
|
tenancy?.guard(table.model.name, key, "insert");
|
|
1089
1120
|
if (!writable(table, column, allow, "insert"))
|
|
1090
1121
|
refuse(table, column);
|
|
@@ -1094,6 +1125,9 @@ function insertRow(table, value, allow, tenancy) {
|
|
|
1094
1125
|
refuseHalfMorph(table, row);
|
|
1095
1126
|
return row;
|
|
1096
1127
|
}
|
|
1128
|
+
function refuseUnknownField(table, key) {
|
|
1129
|
+
throwNamed2("OKM1120", key, table.names, `Field ${key} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
|
|
1130
|
+
}
|
|
1097
1131
|
function cellsFor(columns, row) {
|
|
1098
1132
|
return columns.map((column) => {
|
|
1099
1133
|
if (!Object.hasOwn(row, column.field))
|
|
@@ -1200,10 +1234,10 @@ function writeSet2(table, value, allow, tenancy) {
|
|
|
1200
1234
|
}
|
|
1201
1235
|
const set = {};
|
|
1202
1236
|
for (const key of Object.keys(value)) {
|
|
1203
|
-
if (value[key] === undefined)
|
|
1204
|
-
continue;
|
|
1205
1237
|
const column = table.columns.get(key);
|
|
1206
1238
|
if (column === undefined)
|
|
1239
|
+
refuseUnknownField(table, key);
|
|
1240
|
+
if (value[key] === undefined)
|
|
1207
1241
|
continue;
|
|
1208
1242
|
tenancy?.guard(table.model.name, key, "update");
|
|
1209
1243
|
if (column.guardUpdate || !writable(table, column, allow, "update"))
|
|
@@ -1213,10 +1247,11 @@ function writeSet2(table, value, allow, tenancy) {
|
|
|
1213
1247
|
refuseHalfMorph(table, set);
|
|
1214
1248
|
return set;
|
|
1215
1249
|
}
|
|
1216
|
-
function refuseTreeCycle(table, where, set,
|
|
1217
|
-
const
|
|
1218
|
-
if (
|
|
1250
|
+
function refuseTreeCycle(table, where, set, scopeKeys) {
|
|
1251
|
+
const keyed = keyedId(table, where, scopeKeys);
|
|
1252
|
+
if (keyed === undefined)
|
|
1219
1253
|
return;
|
|
1254
|
+
let found;
|
|
1220
1255
|
for (const relation of table.model.relations) {
|
|
1221
1256
|
if (relation.kind !== "many" || relation.through !== undefined || relation.morph !== undefined) {
|
|
1222
1257
|
continue;
|
|
@@ -1231,17 +1266,20 @@ function refuseTreeCycle(table, where, set, scopeKey) {
|
|
|
1231
1266
|
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
|
|
1232
1267
|
continue;
|
|
1233
1268
|
}
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1269
|
+
const parent = typeof value === "string" ? value : value.toString();
|
|
1270
|
+
if (parent === keyed.own) {
|
|
1271
|
+
fail2("OKM1120", `update on ${table.model.name}.${column.field} cannot point a tree row at itself.`, "Set the parent to another row. A filter that is not the primary key is not checked.");
|
|
1272
|
+
}
|
|
1273
|
+
found = { own: keyed.own, parent, column, identity: keyed.identity };
|
|
1237
1274
|
}
|
|
1238
1275
|
}
|
|
1276
|
+
return found;
|
|
1239
1277
|
}
|
|
1240
|
-
function keyedId(table, where,
|
|
1278
|
+
function keyedId(table, where, scopeKeys) {
|
|
1241
1279
|
if (!isRecord(where))
|
|
1242
1280
|
return;
|
|
1243
1281
|
const primary = table.model.primary;
|
|
1244
|
-
const required = primary.filter((field) => field
|
|
1282
|
+
const required = primary.filter((field) => !scopeKeys.includes(field));
|
|
1245
1283
|
const field = required.length === 1 ? required[0] : undefined;
|
|
1246
1284
|
if (field === undefined || !Object.hasOwn(where, field))
|
|
1247
1285
|
return;
|
|
@@ -1253,7 +1291,51 @@ function keyedId(table, where, scopeKey) {
|
|
|
1253
1291
|
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
|
|
1254
1292
|
return;
|
|
1255
1293
|
}
|
|
1256
|
-
|
|
1294
|
+
const identity = table.columns.get(field);
|
|
1295
|
+
if (identity === undefined)
|
|
1296
|
+
return;
|
|
1297
|
+
return { own: String(value), identity };
|
|
1298
|
+
}
|
|
1299
|
+
function tenantKeys(tenancy) {
|
|
1300
|
+
if (tenancy === undefined)
|
|
1301
|
+
return [];
|
|
1302
|
+
if (tenancy.keys !== undefined && tenancy.keys.length > 0)
|
|
1303
|
+
return tenancy.keys;
|
|
1304
|
+
return [tenancy.key];
|
|
1305
|
+
}
|
|
1306
|
+
function treeSetUpdate(schema, table, where, set, cycle, returning) {
|
|
1307
|
+
const sql = new Sql2;
|
|
1308
|
+
sql.text("with matched as (select ");
|
|
1309
|
+
sql.text(rowId("t"));
|
|
1310
|
+
sql.text(" from ");
|
|
1311
|
+
sql.text(quote(table.model.sql));
|
|
1312
|
+
sql.text(" as t");
|
|
1313
|
+
emitFilter(schema, table, where, sql, "t");
|
|
1314
|
+
sql.text("), updated as (update ");
|
|
1315
|
+
sql.text(quote(table.model.sql));
|
|
1316
|
+
sql.text(" as t set ");
|
|
1317
|
+
emitSet2(sql, table, set, "t");
|
|
1318
|
+
sql.text(" where (");
|
|
1319
|
+
sql.text(rowId("t"));
|
|
1320
|
+
sql.text(") in (select tableoid, ctid from matched) and not exists (with recursive d as (select ");
|
|
1321
|
+
sql.text(quote(cycle.identity.sql));
|
|
1322
|
+
sql.text(" as k from ");
|
|
1323
|
+
sql.text(quote(table.model.sql));
|
|
1324
|
+
sql.text(" where ");
|
|
1325
|
+
sql.text(quote(cycle.column.sql));
|
|
1326
|
+
sql.text(" = ");
|
|
1327
|
+
sql.param(cycle.own, cycle.identity.dataType);
|
|
1328
|
+
sql.text(" union all select c.");
|
|
1329
|
+
sql.text(quote(cycle.identity.sql));
|
|
1330
|
+
sql.text(" from ");
|
|
1331
|
+
sql.text(quote(table.model.sql));
|
|
1332
|
+
sql.text(" c join d on c.");
|
|
1333
|
+
sql.text(quote(cycle.column.sql));
|
|
1334
|
+
sql.text(" = d.k) select 1 from d where d.k = ");
|
|
1335
|
+
sql.param(cycle.parent, cycle.identity.dataType);
|
|
1336
|
+
sql.text(")");
|
|
1337
|
+
endParent(sql, returning);
|
|
1338
|
+
return sql.statement();
|
|
1257
1339
|
}
|
|
1258
1340
|
function columnBySql(table, sql) {
|
|
1259
1341
|
for (const column of table.model.columns) {
|
|
@@ -1362,6 +1444,7 @@ function chunkRows(rows) {
|
|
|
1362
1444
|
function withParams(text, params) {
|
|
1363
1445
|
if (params === undefined || params.length === 0)
|
|
1364
1446
|
return { text };
|
|
1447
|
+
assertParamCount2(params.length);
|
|
1365
1448
|
return { text, params };
|
|
1366
1449
|
}
|
|
1367
1450
|
function keyWire(columns, row) {
|
|
@@ -10,6 +10,8 @@ function extension2(name, options = {}) {
|
|
|
10
10
|
const schema = options.schema ?? "public";
|
|
11
11
|
const relocatable = options.relocatable ?? true;
|
|
12
12
|
const version = options.version;
|
|
13
|
+
const requires = options.requires;
|
|
14
|
+
const provides = options.provides;
|
|
13
15
|
const record = extensionObject({
|
|
14
16
|
name,
|
|
15
17
|
schema,
|
|
@@ -22,6 +24,8 @@ function extension2(name, options = {}) {
|
|
|
22
24
|
schema,
|
|
23
25
|
relocatable,
|
|
24
26
|
...version !== undefined ? { version } : {},
|
|
27
|
+
...requires !== undefined ? { requires } : {},
|
|
28
|
+
...provides !== undefined ? { provides } : {},
|
|
25
29
|
contribute(peers, built) {
|
|
26
30
|
const names = peerNames(peers);
|
|
27
31
|
assertDeclared(names, built);
|
|
@@ -4,16 +4,18 @@ import {
|
|
|
4
4
|
applyProject2,
|
|
5
5
|
pushProject2,
|
|
6
6
|
backfillTiming2
|
|
7
|
-
} from "./
|
|
8
|
-
import"./
|
|
9
|
-
import"./
|
|
10
|
-
import"./
|
|
11
|
-
import"./
|
|
12
|
-
import"./
|
|
7
|
+
} from "./8ma6drzr.js";
|
|
8
|
+
import"./8p2bgye0.js";
|
|
9
|
+
import"./6xqvesa5.js";
|
|
10
|
+
import"./4pkz5nvw.js";
|
|
11
|
+
import"./e1c55v04.js";
|
|
12
|
+
import"./mz48rs74.js";
|
|
13
|
+
import"./wp7y8q3y.js";
|
|
14
|
+
import"./bdekbvmt.js";
|
|
13
15
|
import"./n442h54c.js";
|
|
14
|
-
import"./
|
|
16
|
+
import"./fk9vef30.js";
|
|
15
17
|
import"./12z7aznj.js";
|
|
16
|
-
import"./
|
|
18
|
+
import"./jvxcp1qk.js";
|
|
17
19
|
export {
|
|
18
20
|
applyProject2 as applyProject,
|
|
19
21
|
applyTarget2 as applyTarget,
|