okmodel 0.6.0 → 0.8.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.
- package/README.md +100 -1131
- package/dist/adapters/capabilities.d.ts +35 -0
- package/dist/adapters/failure.d.ts +13 -2
- package/dist/adapters/lazy-errors.d.ts +22 -0
- package/dist/adapters/pg/bun-sql.d.ts +53 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
- package/dist/adapters/pg/bunsql.d.ts +15 -2
- package/dist/adapters/pg/cursor.d.ts +17 -0
- package/dist/adapters/pg/neon-extra.d.ts +18 -0
- package/dist/adapters/pg/neon.d.ts +104 -0
- package/dist/adapters/pg/no-inflight-timeout.d.ts +11 -8
- package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
- package/dist/adapters/pg/nodepostgres.d.ts +12 -0
- package/dist/adapters/pg/pglite-wire.d.ts +24 -0
- package/dist/adapters/pg/pglite.d.ts +10 -0
- package/dist/adapters/pg/postgres-extra.d.ts +27 -11
- package/dist/adapters/pg/reserved.d.ts +42 -0
- package/dist/adapters/pg/session.d.ts +0 -18
- package/dist/contracts/connection.d.ts +7 -6
- package/dist/contracts/error.d.ts +1 -1
- package/dist/dialects/pg/floor.d.ts +68 -0
- package/dist/dialects/pg/fn/index.d.ts +39 -1
- package/dist/dialects/pg/fn/index.js +118 -26
- package/dist/dialects/pg/index.d.ts +8 -1
- package/dist/dialects/pg/index.js +435 -170
- package/dist/dialects/pg/introspect.d.ts +11 -0
- package/dist/dialects/pg/keys.d.ts +11 -8
- package/dist/dialects/pg/model.d.ts +40 -0
- package/dist/dialects/pg/morph.d.ts +43 -0
- package/dist/dialects/pg/operator-fit.d.ts +2 -2
- package/dist/dialects/pg/operators.d.ts +14 -7
- package/dist/dialects/pg/ops/bucket.d.ts +65 -0
- package/dist/dialects/pg/ops/fragment.d.ts +119 -0
- package/dist/dialects/pg/ops/inc.d.ts +2 -2
- package/dist/dialects/pg/ops/lane.d.ts +49 -0
- package/dist/dialects/pg/ops/matches.d.ts +9 -12
- package/dist/dialects/pg/ops/relevance.d.ts +13 -0
- package/dist/dialects/pg/ops/search-query.d.ts +22 -0
- package/dist/dialects/pg/ops/window.d.ts +103 -0
- package/dist/dialects/pg/preset.d.ts +1 -1
- package/dist/dialects/pg/relations.d.ts +100 -3
- package/dist/dialects/pg/schema.d.ts +31 -3
- package/dist/dialects/pg/view/client.d.ts +14 -6
- package/dist/dialects/pg/view/index.d.ts +73 -1
- package/dist/dialects/pg/view/index.js +156 -5
- package/dist/dialects/pg/view/scratch.d.ts +8 -5
- package/dist/runtime/aggregate.d.ts +8 -2
- package/dist/runtime/bucket-group.d.ts +70 -0
- package/dist/runtime/conflict.d.ts +22 -4
- package/dist/runtime/include.d.ts +0 -8
- package/dist/runtime/inflight.d.ts +1 -1
- package/dist/runtime/otel.d.ts +105 -0
- package/dist/runtime/otel.js +97 -0
- package/dist/runtime/page.d.ts +4 -1
- package/dist/runtime/pg/bun.js +12 -6
- package/dist/runtime/pg/neon.d.ts +38 -0
- package/dist/runtime/pg/neon.js +64 -0
- package/dist/runtime/pg/pg.js +5 -5
- package/dist/runtime/pg/pglite.d.ts +1 -0
- package/dist/runtime/pg/pglite.js +9 -9
- package/dist/runtime/pg/postgresjs.js +5 -5
- package/dist/runtime/plan.d.ts +95 -5
- package/dist/runtime/read-stream.d.ts +13 -16
- package/dist/runtime/result-name.d.ts +17 -0
- package/dist/runtime/server-check.d.ts +3 -3
- package/dist/runtime/sort-bind.d.ts +21 -0
- package/dist/runtime/sort.d.ts +56 -0
- package/dist/runtime/sql-fragment.d.ts +43 -0
- package/dist/runtime/sync.d.ts +70 -0
- package/dist/runtime/tenancy/index.js +15 -13
- package/dist/runtime/text-search.d.ts +20 -0
- package/dist/runtime/topology.d.ts +1 -1
- package/dist/runtime/traits/index.d.ts +80 -0
- package/dist/runtime/traits/index.js +184 -21
- package/dist/runtime/tree.d.ts +38 -0
- package/dist/runtime/types.d.ts +232 -22
- package/dist/runtime/validate/index.js +4 -4
- package/dist/runtime/version.d.ts +39 -0
- package/dist/runtime/window.d.ts +21 -0
- package/dist/runtime/write.d.ts +54 -2
- package/dist/shared/{929h19xp.js → 0wrea3jq.js} +141 -13
- package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
- package/dist/shared/{1z04fa85.js → 14x60fbf.js} +12 -57
- package/dist/shared/{ek2wt2dz.js → 16kvjebh.js} +4 -4
- package/dist/shared/{wynzeggs.js → 195pzzzz.js} +8 -8
- package/dist/shared/1d9q9cv2.js +312 -0
- package/dist/shared/2c13q96h.js +18 -0
- package/dist/shared/{b4v57v3x.js → 2d3xq4ps.js} +2 -2
- package/dist/shared/{1f0xa3cb.js → 3449rcae.js} +5 -5
- package/dist/shared/{wkme6tep.js → 35q0n9tz.js} +8 -16
- package/dist/shared/3bb7wsqt.js +99 -0
- package/dist/shared/3t6kw83m.js +249 -0
- package/dist/shared/{5j36z8dn.js → 4m6hskg8.js} +39 -70
- package/dist/shared/{n076ydsc.js → 4vbf83xx.js} +69 -28
- package/dist/shared/{vmfkhszw.js → 63f4ksbz.js} +33 -26
- package/dist/shared/{c58secgj.js → 63qtkrca.js} +38 -4
- package/dist/shared/6m78c8ss.js +6 -0
- package/dist/shared/{x3jc53kg.js → 760ppr76.js} +15 -7
- package/dist/shared/7ghwamrf.js +40 -0
- package/dist/shared/7kms6fvj.js +20 -0
- package/dist/shared/7n7ddwt4.js +6 -0
- package/dist/shared/9a4ae4p8.js +31 -0
- package/dist/shared/{hazqqecq.js → 9dr2qnx7.js} +63 -34
- package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
- package/dist/shared/a62rb2da.js +13 -0
- package/dist/shared/{cgbamx3e.js → ae4j5f42.js} +23 -4
- package/dist/shared/agsfb86s.js +233 -0
- package/dist/shared/{8x72s86k.js → b6d6p0zc.js} +13 -7
- package/dist/shared/{ag4c7516.js → b76b8d95.js} +2 -2
- package/dist/shared/{j60w0dvr.js → bah9nbg3.js} +58 -38
- package/dist/shared/bnby0esn.js +10 -0
- package/dist/shared/bsek72fg.js +225 -0
- package/dist/shared/{2cg3wnxc.js → bxas03mq.js} +608 -141
- package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
- package/dist/shared/{gwn6v667.js → cnkky55j.js} +25 -14
- package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
- package/dist/shared/{ttmg09vd.js → dpc2r7rb.js} +8 -8
- package/dist/shared/dzj09cye.js +10 -0
- package/dist/shared/{sbdme3vy.js → e8zyaqvj.js} +60 -10
- package/dist/shared/{2jd1sn0e.js → ecn8mfdq.js} +6 -6
- package/dist/shared/exn3sd90.js +359 -0
- package/dist/shared/{t3g0k88x.js → f4jy1j7x.js} +39 -22
- package/dist/shared/{y2t3jktd.js → fjpnhqan.js} +20 -13
- package/dist/shared/g5yc06ka.js +272 -0
- package/dist/shared/ga9j92qj.js +25 -0
- package/dist/shared/{3fqwmr09.js → hfqmpasr.js} +6 -6
- package/dist/shared/{wt5rzv1h.js → hm5f8jby.js} +7 -7
- package/dist/shared/{ys0xzyaj.js → hqpxf4a4.js} +224 -19
- package/dist/shared/jebgrkeq.js +179 -0
- package/dist/shared/{09p049xa.js → jp36k7dp.js} +44 -16
- package/dist/shared/jx2m62cs.js +96 -0
- package/dist/shared/{r11n8grd.js → k86n8vq3.js} +7 -4
- package/dist/shared/{2z7wv5tj.js → kgwp4jdd.js} +56 -35
- package/dist/shared/{knmes2kh.js → kj9d8maq.js} +1 -1
- package/dist/shared/{g90m9b0g.js → m4xff2a6.js} +6 -5
- package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
- package/dist/shared/mfedzr74.js +145 -0
- package/dist/shared/{f0f1n281.js → mkrn359n.js} +60 -11
- package/dist/shared/{p248q79y.js → mnvjvqyp.js} +10 -10
- package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
- package/dist/shared/{4az561fn.js → mtw6jz76.js} +8 -23
- package/dist/shared/n05z9nwz.js +313 -0
- package/dist/shared/{pjr6xrm5.js → n0jmpgj1.js} +20 -17
- package/dist/shared/{p6bjzq9q.js → n41w4fbz.js} +14 -6
- package/dist/shared/{b3awxn7h.js → n454kcnw.js} +1 -1
- package/dist/shared/n7kg8mmx.js +61 -0
- package/dist/shared/nbw1z4yd.js +18 -0
- package/dist/shared/needfe47.js +66 -0
- package/dist/shared/{1nw1f3vs.js → njga14v4.js} +9 -9
- package/dist/shared/{5yv4k6a6.js → nmnsgj7x.js} +145 -3
- package/dist/shared/{vjpnzwjz.js → p3xbdcvt.js} +14 -18
- package/dist/shared/p5nh3r8q.js +622 -0
- package/dist/shared/{nx9hh281.js → pan0370z.js} +13 -12
- package/dist/shared/q0cqt2sp.js +12 -0
- package/dist/shared/qd9hhd8f.js +37 -0
- package/dist/shared/{mb2ycs1p.js → qfw14tna.js} +15 -15
- package/dist/shared/{9s0ypp87.js → sjk86yrx.js} +1 -1
- package/dist/shared/th3be82n.js +208 -0
- package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
- package/dist/shared/{5d8t84hg.js → v1wad97q.js} +14 -14
- package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
- package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
- package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
- package/dist/shared/{q3j1tq7a.js → wcrheftc.js} +148 -23
- package/dist/shared/wvdjznah.js +213 -0
- package/dist/shared/wz2a78mp.js +8 -0
- package/dist/shared/xfhe73sb.js +436 -0
- package/dist/shared/{r1fdd0f6.js → z581d7ny.js} +5 -2
- package/dist/shared/{8etn7d8w.js → z7s6fpxv.js} +1 -1
- package/dist/shared/{32cnm7kn.js → zbqbmmrp.js} +76 -40
- package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
- package/dist/shared/{xq0mvhts.js → zgex00fd.js} +6 -6
- package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
- package/dist/shared/zq1he88x.js +155 -0
- package/dist/tooling/cli.js +26 -13
- package/dist/tooling/driver-run.js +4971 -0
- package/dist/tooling/driver-test.d.ts +36 -0
- package/dist/tooling/migrate/commands.d.ts +2 -2
- package/dist/tooling/migrate/engine.d.ts +3 -2
- package/dist/tooling/migrate/index.js +9 -9
- package/dist/tooling/migrate/project.d.ts +3 -0
- package/dist/tooling/shared/03k6res6.js +210 -0
- package/dist/tooling/shared/08kemxjd.js +10 -0
- package/dist/tooling/shared/2revefqt.js +209 -0
- package/dist/tooling/shared/2wtvc7rw.js +1425 -0
- package/dist/tooling/shared/345tbc2k.js +16 -0
- package/dist/tooling/shared/3m1hkg7z.js +344 -0
- package/dist/tooling/shared/3rrw5w8f.js +81 -0
- package/dist/tooling/shared/3tq8pnb8.js +131 -0
- package/dist/tooling/shared/417zdsk7.js +194 -0
- package/dist/tooling/shared/4d2w25vw.js +40 -0
- package/dist/tooling/shared/54tqkxja.js +51 -0
- package/dist/tooling/shared/5bvw2nev.js +12 -0
- package/dist/tooling/shared/6nyfyw70.js +231 -0
- package/dist/tooling/shared/72fyg4zv.js +160 -0
- package/dist/tooling/shared/733a1tq3.js +38 -0
- package/dist/tooling/shared/7ae7rjmn.js +20 -0
- package/dist/tooling/shared/7kms6fvj.js +20 -0
- package/dist/tooling/shared/8sqrsw3s.js +49 -0
- package/dist/tooling/shared/96ps4g1z.js +32 -0
- package/dist/tooling/shared/9kazs5p6.js +195 -0
- package/dist/tooling/shared/9xzm7hjg.js +38 -0
- package/dist/tooling/shared/a6pp9d12.js +49 -0
- package/dist/tooling/shared/a7q7t4n3.js +22 -0
- package/dist/tooling/shared/aftb2mwr.js +18 -0
- package/dist/tooling/shared/bz2dqhab.js +311 -0
- package/dist/tooling/shared/cmptmb4f.js +12 -0
- package/dist/tooling/shared/ddjtfgnx.js +177 -0
- package/dist/tooling/shared/djydjpqt.js +261 -0
- package/dist/tooling/shared/dw08f3m8.js +9 -0
- package/dist/tooling/shared/dy672fz6.js +16 -0
- package/dist/tooling/shared/dzx85q70.js +66 -0
- package/dist/tooling/shared/ec71zqgt.js +270 -0
- package/dist/{shared/d5azex6s.js → tooling/shared/ep8zh3bk.js} +1 -1
- package/dist/tooling/shared/f9mphxej.js +3789 -0
- package/dist/tooling/shared/fb9k2qwd.js +89 -0
- package/dist/tooling/shared/g9ad4n80.js +211 -0
- package/dist/tooling/shared/gfvtj6d0.js +94 -0
- package/dist/tooling/shared/gmcf9cxf.js +294 -0
- package/dist/tooling/shared/htnaj77v.js +17 -0
- package/dist/tooling/shared/j9t5s12a.js +7 -0
- package/dist/tooling/shared/jne7b93p.js +42 -0
- package/dist/tooling/shared/ma2340rx.js +118 -0
- package/dist/tooling/shared/mtrqn2hn.js +505 -0
- package/dist/tooling/shared/n4jqhpqz.js +27 -0
- package/dist/tooling/shared/nf7jmhfa.js +20 -0
- package/dist/tooling/shared/p7f08ktn.js +332 -0
- package/dist/tooling/shared/ppnnnvj8.js +13 -0
- package/dist/tooling/shared/pqy21k24.js +312 -0
- package/dist/tooling/shared/pw8fgahx.js +69 -0
- package/dist/tooling/shared/pwsytxm5.js +17 -0
- package/dist/tooling/shared/rf83gr2d.js +94 -0
- package/dist/tooling/shared/rq5kk8j6.js +401 -0
- package/dist/tooling/shared/rs1jb051.js +12 -0
- package/dist/tooling/shared/smn6kz1p.js +157 -0
- package/dist/tooling/shared/spk1jg3r.js +1696 -0
- package/dist/tooling/shared/tn8gay14.js +143 -0
- package/dist/tooling/shared/vraj6d74.js +42 -0
- package/dist/tooling/shared/vs0t6qt8.js +64 -0
- package/dist/tooling/shared/vx86qjv8.js +150 -0
- package/dist/tooling/shared/w7qe8sj1.js +140 -0
- package/dist/tooling/shared/wt7j7nf6.js +15 -0
- package/dist/tooling/shared/wwnekq5n.js +6 -0
- package/dist/tooling/shared/xhrnjch9.js +185 -0
- package/dist/tooling/shared/xjs6zqtc.js +190 -0
- package/dist/tooling/shared/y031jct9.js +16 -0
- package/dist/tooling/shared/y5656f0e.js +233 -0
- package/dist/tooling/shared/yfr8hzhm.js +604 -0
- package/dist/tooling/shared/yk9mp7vb.js +250 -0
- package/dist/tooling/shared/yw30vnq2.js +139 -0
- package/dist/tooling/shared/z8d7ptht.js +618 -0
- package/dist/tooling/shared/zhwnfyb2.js +9 -0
- package/dist/tooling/shared/zvnhh1n0.js +198 -0
- package/dist/tooling/testing/index.js +3 -3
- package/package.json +17 -3
- package/dist/shared/3qnhc7w5.js +0 -38
- package/dist/shared/7m88x3e9.js +0 -45
- package/dist/shared/8dqhth8c.js +0 -12
- package/dist/shared/j3rkk835.js +0 -99
- package/dist/shared/k68eedmy.js +0 -85
- package/dist/shared/venqrjna.js +0 -216
- package/dist/shared/wxr8cwns.js +0 -6
- package/dist/shared/y34a8714.js +0 -150
- package/dist/shared/zm0mafk4.js +0 -92
- package/dist/shared/zy8r7qvz.js +0 -116
- package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
- package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
functionObject,
|
|
3
|
+
triggerObject
|
|
4
|
+
} from "../../shared/12z7aznj.js";
|
|
2
5
|
import {
|
|
3
6
|
checkPresetNames,
|
|
4
7
|
duplicatePreset
|
|
5
|
-
} from "../../shared/
|
|
8
|
+
} from "../../shared/znm0bpp5.js";
|
|
6
9
|
import {
|
|
7
10
|
checkTrait
|
|
8
11
|
} from "../../shared/n0dgs0pb.js";
|
|
9
|
-
import {
|
|
10
|
-
quoteIdent
|
|
11
|
-
} from "../../shared/9s0ypp87.js";
|
|
12
12
|
import {
|
|
13
13
|
pathEndpoint
|
|
14
14
|
} from "../../shared/rhs3xe4k.js";
|
|
15
15
|
import {
|
|
16
|
-
|
|
17
|
-
triggerObject
|
|
18
|
-
} from "../../shared/y34a8714.js";
|
|
19
|
-
import {
|
|
16
|
+
integer2,
|
|
20
17
|
timestamptz2
|
|
21
|
-
} from "../../shared/
|
|
18
|
+
} from "../../shared/nmnsgj7x.js";
|
|
22
19
|
import {
|
|
23
20
|
uuid2
|
|
24
|
-
} from "../../shared/
|
|
21
|
+
} from "../../shared/ecn8mfdq.js";
|
|
25
22
|
import {
|
|
26
23
|
snakeCase
|
|
27
|
-
} from "../../shared/
|
|
24
|
+
} from "../../shared/gcefca6p.js";
|
|
28
25
|
import {
|
|
29
26
|
ColumnBuilder2,
|
|
30
27
|
retarget
|
|
31
|
-
} from "../../shared/
|
|
28
|
+
} from "../../shared/606g0nbf.js";
|
|
29
|
+
import {
|
|
30
|
+
quoteIdent
|
|
31
|
+
} from "../../shared/sjk86yrx.js";
|
|
32
32
|
import {
|
|
33
33
|
definition,
|
|
34
34
|
unavailable
|
|
@@ -41,10 +41,12 @@ import {
|
|
|
41
41
|
queryHandle,
|
|
42
42
|
attachHttp,
|
|
43
43
|
settleCall
|
|
44
|
-
} from "../../shared/
|
|
44
|
+
} from "../../shared/bah9nbg3.js";
|
|
45
45
|
import {
|
|
46
|
-
installArchiveInspect
|
|
47
|
-
|
|
46
|
+
installArchiveInspect,
|
|
47
|
+
indexes,
|
|
48
|
+
isRecord
|
|
49
|
+
} from "../../shared/kgwp4jdd.js";
|
|
48
50
|
import {
|
|
49
51
|
fitIdentifier2
|
|
50
52
|
} from "../../shared/nfzc5z0w.js";
|
|
@@ -465,13 +467,13 @@ function refuse(host, table) {
|
|
|
465
467
|
}
|
|
466
468
|
var archiveMod;
|
|
467
469
|
function loadArchive() {
|
|
468
|
-
archiveMod ??= import("../../shared/
|
|
470
|
+
archiveMod ??= import("../../shared/qfw14tna.js");
|
|
469
471
|
return archiveMod;
|
|
470
472
|
}
|
|
471
473
|
async function settle(host, table, mods) {
|
|
472
474
|
if (mods.uses === undefined)
|
|
473
475
|
return mods;
|
|
474
|
-
const { resolve } = await import("../../shared/
|
|
476
|
+
const { resolve } = await import("../../shared/m7n9h2a5.js");
|
|
475
477
|
return { ...mods, presets: resolve(host.schema, table, mods.uses).wheres };
|
|
476
478
|
}
|
|
477
479
|
async function run(host, op, table, input, options, mods) {
|
|
@@ -484,6 +486,93 @@ async function run(host, op, table, input, options, mods) {
|
|
|
484
486
|
}
|
|
485
487
|
}
|
|
486
488
|
|
|
489
|
+
// src/runtime/sort-bind.ts
|
|
490
|
+
function rewriteSortable(self, tables, casing, schemaTraits, group) {
|
|
491
|
+
return tables.map((item) => {
|
|
492
|
+
if (!applies2(self, item, schemaTraits))
|
|
493
|
+
return item;
|
|
494
|
+
refusePath(item);
|
|
495
|
+
return withIndex(item, casing, schemaTraits, group);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
function applies2(self, item, schemaTraits) {
|
|
499
|
+
const options = item.options;
|
|
500
|
+
const own = Array.isArray(options?.traits) ? options.traits : [];
|
|
501
|
+
if (own.includes(self))
|
|
502
|
+
return true;
|
|
503
|
+
if (options?.omitDefaults !== undefined)
|
|
504
|
+
return false;
|
|
505
|
+
return schemaTraits?.includes(self) ?? false;
|
|
506
|
+
}
|
|
507
|
+
function refusePath(item) {
|
|
508
|
+
const tenancy = item.options?.tenancy;
|
|
509
|
+
if (typeof tenancy === "object" && tenancy !== null && "via" in tenancy) {
|
|
510
|
+
definition(`sortable() on ${item.name} does not combine with via(). Position needs the tenant columns on the row.`);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function withIndex(item, casing, schemaTraits, group) {
|
|
514
|
+
const options = item.options;
|
|
515
|
+
const prior = options?.indexes;
|
|
516
|
+
const tenantKeys = options?.tenantKeys ?? [];
|
|
517
|
+
const fields = [];
|
|
518
|
+
for (const field of tenantKeys)
|
|
519
|
+
if (!fields.includes(field))
|
|
520
|
+
fields.push(field);
|
|
521
|
+
if (group !== undefined && !fields.includes(group))
|
|
522
|
+
fields.push(group);
|
|
523
|
+
fields.push("position");
|
|
524
|
+
const predicate = archivedPredicate(item, casing, schemaTraits);
|
|
525
|
+
const indexes = (handles) => {
|
|
526
|
+
const calls = prior === undefined ? [] : prior(handles);
|
|
527
|
+
const columns = fields.map((field) => {
|
|
528
|
+
const handle = handles[field];
|
|
529
|
+
if (handle === undefined) {
|
|
530
|
+
definition(`sortable() on ${item.name} needs a column named ${field}.`);
|
|
531
|
+
}
|
|
532
|
+
return handle.name;
|
|
533
|
+
});
|
|
534
|
+
return [...Array.isArray(calls) ? calls : [], uniqueIndex(columns, predicate)];
|
|
535
|
+
};
|
|
536
|
+
return {
|
|
537
|
+
...item,
|
|
538
|
+
options: { ...options, indexes }
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function archivedPredicate(item, casing, schemaTraits) {
|
|
542
|
+
if (!archivable(item, schemaTraits))
|
|
543
|
+
return;
|
|
544
|
+
return casing === "snake" ? "(archived_at IS NULL)" : '("archivedAt" IS NULL)';
|
|
545
|
+
}
|
|
546
|
+
function archivable(item, schemaTraits) {
|
|
547
|
+
const options = item.options;
|
|
548
|
+
const own = Array.isArray(options?.traits) ? options.traits : [];
|
|
549
|
+
for (const trait of own)
|
|
550
|
+
if (marked2(trait))
|
|
551
|
+
return true;
|
|
552
|
+
if (options?.omitDefaults !== undefined)
|
|
553
|
+
return false;
|
|
554
|
+
if (schemaTraits === undefined)
|
|
555
|
+
return false;
|
|
556
|
+
for (const trait of schemaTraits)
|
|
557
|
+
if (marked2(trait))
|
|
558
|
+
return true;
|
|
559
|
+
return false;
|
|
560
|
+
}
|
|
561
|
+
function marked2(value) {
|
|
562
|
+
return value["~archive"] === true;
|
|
563
|
+
}
|
|
564
|
+
function uniqueIndex(columns, predicate) {
|
|
565
|
+
const call = {
|
|
566
|
+
columns,
|
|
567
|
+
isUnique: true,
|
|
568
|
+
...predicate !== undefined ? { predicate } : {},
|
|
569
|
+
unique() {
|
|
570
|
+
return call;
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
return call;
|
|
574
|
+
}
|
|
575
|
+
|
|
487
576
|
// src/runtime/traits/index.ts
|
|
488
577
|
function trait(name, input) {
|
|
489
578
|
if (input.presets !== undefined)
|
|
@@ -561,7 +650,7 @@ function timestamps(options) {
|
|
|
561
650
|
function stamped() {
|
|
562
651
|
return timestamptz2().defaultSql("now()").guarded();
|
|
563
652
|
}
|
|
564
|
-
function
|
|
653
|
+
function archivable2(options) {
|
|
565
654
|
installArchiveContributions();
|
|
566
655
|
const cascade = readCascade(options);
|
|
567
656
|
const base = trait("archivable", {
|
|
@@ -585,6 +674,78 @@ function archivable(options) {
|
|
|
585
674
|
};
|
|
586
675
|
return self;
|
|
587
676
|
}
|
|
677
|
+
function versioned() {
|
|
678
|
+
return trait("versioned", {
|
|
679
|
+
fields: {
|
|
680
|
+
version: integer2().defaultSql("1").guarded()
|
|
681
|
+
},
|
|
682
|
+
sealed: ["version"]
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
function sortable(groupBy) {
|
|
686
|
+
if (groupBy !== undefined && groupBy.length === 0) {
|
|
687
|
+
definition("sortable() groupBy must be a column name.");
|
|
688
|
+
}
|
|
689
|
+
if (groupBy === "position")
|
|
690
|
+
definition("sortable() cannot group by position.");
|
|
691
|
+
const base = trait("sortable", {
|
|
692
|
+
fields: {
|
|
693
|
+
position: integer2().guarded()
|
|
694
|
+
},
|
|
695
|
+
sealed: ["position"]
|
|
696
|
+
});
|
|
697
|
+
const self = {
|
|
698
|
+
...base,
|
|
699
|
+
...groupBy !== undefined ? { group: groupBy } : {},
|
|
700
|
+
"~sort": true,
|
|
701
|
+
apply(model, ctx) {
|
|
702
|
+
if (groupBy !== undefined && !Object.hasOwn(model.columns, groupBy)) {
|
|
703
|
+
definition(`sortable() on ${ctx.table} needs a column named ${groupBy}.`);
|
|
704
|
+
}
|
|
705
|
+
base.apply(model, ctx);
|
|
706
|
+
},
|
|
707
|
+
rewrite(tables, casing, schemaTraits) {
|
|
708
|
+
return rewriteSortable(self, tables, casing, schemaTraits, groupBy);
|
|
709
|
+
},
|
|
710
|
+
hook: attachSort
|
|
711
|
+
};
|
|
712
|
+
return self;
|
|
713
|
+
}
|
|
714
|
+
function attachSort(target, ctx) {
|
|
715
|
+
const tableName = ctx.table;
|
|
716
|
+
const session = ctx.session;
|
|
717
|
+
if (tableName === undefined || session === undefined)
|
|
718
|
+
return;
|
|
719
|
+
const host = session;
|
|
720
|
+
const table = indexes(host.schema).get(tableName);
|
|
721
|
+
if (table === undefined)
|
|
722
|
+
return;
|
|
723
|
+
let sortableTable = false;
|
|
724
|
+
for (const item of table.model.traits ?? []) {
|
|
725
|
+
if (item.name === "sortable")
|
|
726
|
+
sortableTable = true;
|
|
727
|
+
}
|
|
728
|
+
if (!sortableTable)
|
|
729
|
+
return;
|
|
730
|
+
const order = { position: "asc" };
|
|
731
|
+
for (const field of table.model.primary) {
|
|
732
|
+
if (field !== "position")
|
|
733
|
+
order[field] = "asc";
|
|
734
|
+
}
|
|
735
|
+
wrapOrder(target, "find", order);
|
|
736
|
+
wrapOrder(target, "page", order);
|
|
737
|
+
const view = ctx.view;
|
|
738
|
+
target.move = (id, place) => import("../../shared/xfhe73sb.js").then((mod) => mod.move(host, tableName, id, place, view));
|
|
739
|
+
}
|
|
740
|
+
function wrapOrder(target, key, order) {
|
|
741
|
+
const previous = target[key];
|
|
742
|
+
if (typeof previous !== "function")
|
|
743
|
+
return;
|
|
744
|
+
target[key] = (options = {}) => {
|
|
745
|
+
const next = isRecord(options) && options.orderBy !== undefined ? options : { ...options, orderBy: order };
|
|
746
|
+
return previous.call(target, next);
|
|
747
|
+
};
|
|
748
|
+
}
|
|
588
749
|
function readCascade(options) {
|
|
589
750
|
if (options === undefined)
|
|
590
751
|
return [];
|
|
@@ -647,7 +808,9 @@ function addFields(name, fields, model, ctx) {
|
|
|
647
808
|
}
|
|
648
809
|
}
|
|
649
810
|
export {
|
|
650
|
-
archivable,
|
|
811
|
+
archivable2 as archivable,
|
|
812
|
+
sortable,
|
|
651
813
|
timestamps,
|
|
652
|
-
trait
|
|
814
|
+
trait,
|
|
815
|
+
versioned
|
|
653
816
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `descendants` and `ancestors` (spec §13 tool 11).
|
|
3
|
+
*
|
|
4
|
+
* One recursive statement walks a self-relation's parent column. A row already
|
|
5
|
+
* on the path is not entered again, so a cycle in the data returns. `depth`
|
|
6
|
+
* stops the walk earlier. `ltree` is not read: the extension is a later index,
|
|
7
|
+
* and this statement does not require it.
|
|
8
|
+
*
|
|
9
|
+
* Tenancy and the active set apply on the start row, on every step, and on
|
|
10
|
+
* the rows that come back. `where` and presets filter those rows and do not
|
|
11
|
+
* cut the walk short. A missing id returns no rows, including with `self`.
|
|
12
|
+
* The root has no ancestors. Loaded on the first call.
|
|
13
|
+
*/
|
|
14
|
+
import type { ColumnModel } from "../dialects/pg/model.js";
|
|
15
|
+
import { type Mods, type Session } from "./client.js";
|
|
16
|
+
import { type ArchiveView, type Indexed } from "./plan.js";
|
|
17
|
+
/**
|
|
18
|
+
* Builds the handle for one `descendants` or `ancestors` call.
|
|
19
|
+
*
|
|
20
|
+
* @param session - Client session
|
|
21
|
+
* @param table - Table name
|
|
22
|
+
* @param options - The packed call: the id, the direction, and the caller's options
|
|
23
|
+
* @param mods - Presets, signal, and timeout
|
|
24
|
+
* @param view - Archive visibility
|
|
25
|
+
* @returns A handle that resolves to the walked rows
|
|
26
|
+
*/
|
|
27
|
+
export declare function build(session: Session, table: string, options: object, mods: Mods, view: ArchiveView | undefined): Promise<unknown> & Record<string, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* The primary key the caller passes, without the tenant key.
|
|
30
|
+
*
|
|
31
|
+
* A tree walk and `sync` both address one column. A composite key beside the
|
|
32
|
+
* tenant key is refused.
|
|
33
|
+
*
|
|
34
|
+
* @param session - Client session, for the tenant key
|
|
35
|
+
* @param table - The table
|
|
36
|
+
* @returns That column
|
|
37
|
+
*/
|
|
38
|
+
export declare function identityColumn(session: Session, table: Indexed): ColumnModel;
|