okmodel 0.6.0 → 0.7.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 +3 -0
- package/dist/adapters/failure.d.ts +13 -2
- package/dist/adapters/lazy-errors.d.ts +22 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
- package/dist/adapters/pg/bunsql.d.ts +14 -1
- package/dist/adapters/pg/cursor.d.ts +17 -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/dialects/pg/floor.d.ts +68 -0
- package/dist/dialects/pg/index.d.ts +6 -1
- package/dist/dialects/pg/index.js +49 -159
- 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/inc.d.ts +2 -2
- 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/index.js +1 -1
- 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/page.d.ts +4 -1
- package/dist/runtime/pg/bun.js +12 -6
- 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/sync.d.ts +70 -0
- package/dist/runtime/tenancy/index.js +7 -5
- package/dist/runtime/text-search.d.ts +20 -0
- package/dist/runtime/traits/index.d.ts +80 -0
- package/dist/runtime/traits/index.js +175 -11
- package/dist/runtime/tree.d.ts +38 -0
- package/dist/runtime/types.d.ts +218 -22
- package/dist/runtime/validate/index.js +2 -2
- 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/{wkme6tep.js → 14vx95q4.js} +8 -16
- package/dist/shared/1est4ezg.js +313 -0
- package/dist/shared/{4az561fn.js → 1qa0qajz.js} +8 -23
- package/dist/shared/{2cg3wnxc.js → 1w508jbr.js} +593 -130
- package/dist/shared/2c13q96h.js +18 -0
- package/dist/shared/{b4v57v3x.js → 2d3xq4ps.js} +2 -2
- package/dist/shared/{1nw1f3vs.js → 2shdbn8q.js} +7 -7
- package/dist/shared/3v7t1yrv.js +208 -0
- package/dist/shared/{x3jc53kg.js → 5e3tf63j.js} +2 -2
- package/dist/shared/5fe3kbsh.js +10 -0
- package/dist/shared/5v3xf80k.js +37 -0
- package/dist/shared/{c58secgj.js → 63qtkrca.js} +38 -4
- package/dist/shared/{2z7wv5tj.js → 67txcrcw.js} +55 -34
- package/dist/shared/79dt02vc.js +12 -0
- package/dist/shared/{8x72s86k.js → 7k9grvf6.js} +10 -4
- package/dist/shared/7kms6fvj.js +20 -0
- package/dist/shared/7mnme5tn.js +8 -0
- package/dist/shared/7n7ddwt4.js +6 -0
- package/dist/shared/{5j36z8dn.js → 81ebdx9p.js} +39 -70
- package/dist/shared/{knmes2kh.js → 8skf0cam.js} +1 -1
- package/dist/shared/9a4ae4p8.js +31 -0
- package/dist/shared/9y3mmmh1.js +436 -0
- package/dist/shared/ab9gmbwy.js +213 -0
- package/dist/shared/{f0f1n281.js → ax7qv55k.js} +2 -2
- package/dist/shared/{g90m9b0g.js → aytqh5y2.js} +6 -5
- package/dist/shared/{vjpnzwjz.js → b5pftnn2.js} +1 -1
- package/dist/shared/{ag4c7516.js → b76b8d95.js} +2 -2
- package/dist/shared/{vmfkhszw.js → bg3rym3g.js} +33 -26
- package/dist/shared/{mb2ycs1p.js → bm22fvzr.js} +15 -15
- package/dist/shared/{q3j1tq7a.js → bz84tkzm.js} +148 -23
- package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
- package/dist/shared/cn957f8d.js +179 -0
- package/dist/shared/{gwn6v667.js → cnkky55j.js} +25 -14
- package/dist/shared/{ys0xzyaj.js → dkxgzaqd.js} +224 -19
- package/dist/shared/dzj09cye.js +10 -0
- package/dist/shared/exn3sd90.js +359 -0
- package/dist/shared/g6evj1j3.js +66 -0
- package/dist/shared/ga9j92qj.js +25 -0
- package/dist/shared/{t3g0k88x.js → gs74dbj5.js} +16 -12
- package/dist/shared/gzaveazc.js +285 -0
- package/dist/shared/{2jd1sn0e.js → hyh73qk6.js} +1 -1
- package/dist/shared/{r1fdd0f6.js → je4axnm8.js} +5 -2
- package/dist/shared/{1f0xa3cb.js → jvd0mqag.js} +3 -3
- package/dist/shared/jznfax0y.js +155 -0
- package/dist/shared/{cgbamx3e.js → kb2sdhfb.js} +7 -4
- package/dist/shared/{wt5rzv1h.js → kr0jzbw2.js} +5 -5
- package/dist/shared/{p6bjzq9q.js → ktz42yez.js} +12 -4
- package/dist/shared/{p248q79y.js → m6p12kbr.js} +2 -2
- package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
- package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
- package/dist/shared/{929h19xp.js → mtaszv5a.js} +40 -10
- package/dist/shared/{b3awxn7h.js → n816peh1.js} +1 -1
- package/dist/shared/nbw1z4yd.js +18 -0
- package/dist/shared/{nx9hh281.js → p6qc5gcp.js} +12 -11
- package/dist/shared/{pjr6xrm5.js → pbp1ss85.js} +20 -17
- package/dist/shared/pt94kz7f.js +6 -0
- package/dist/shared/q5c6ngn3.js +13 -0
- package/dist/shared/{xq0mvhts.js → rs73fca9.js} +4 -4
- package/dist/shared/{r11n8grd.js → sfz1ksn6.js} +7 -4
- package/dist/shared/{wynzeggs.js → svncdeh5.js} +6 -6
- package/dist/shared/{j60w0dvr.js → tbrvgw6z.js} +57 -38
- package/dist/shared/te5as7z7.js +622 -0
- package/dist/shared/{ttmg09vd.js → tsvww22q.js} +1 -1
- package/dist/shared/{y2t3jktd.js → ttsqgp4p.js} +19 -12
- package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
- package/dist/shared/{sbdme3vy.js → vb6qfyve.js} +60 -10
- package/dist/shared/{5d8t84hg.js → vczs8gd4.js} +14 -14
- package/dist/shared/{5yv4k6a6.js → vqrjpcqn.js} +144 -2
- package/dist/shared/{3fqwmr09.js → w72kgg4q.js} +4 -4
- package/dist/shared/{1z04fa85.js → w79hsckn.js} +12 -57
- package/dist/shared/{09p049xa.js → wa07eas9.js} +42 -14
- package/dist/shared/{32cnm7kn.js → x933k9a3.js} +74 -38
- package/dist/shared/{n076ydsc.js → xhfsfkgk.js} +62 -28
- package/dist/shared/xjk7hnn5.js +272 -0
- package/dist/shared/{hazqqecq.js → xnxsed62.js} +50 -21
- package/dist/shared/y6njgyda.js +249 -0
- package/dist/shared/{8etn7d8w.js → z7s6fpxv.js} +1 -1
- package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
- package/dist/shared/zm0ptry0.js +40 -0
- package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
- package/dist/shared/zp9fmend.js +145 -0
- package/dist/tooling/cli.js +11 -11
- package/dist/tooling/migrate/engine.d.ts +3 -2
- package/dist/tooling/migrate/index.js +7 -7
- package/dist/tooling/testing/index.js +1 -1
- package/package.json +4 -2
- package/dist/shared/3qnhc7w5.js +0 -38
- package/dist/shared/7m88x3e9.js +0 -45
- package/dist/shared/8dqhth8c.js +0 -12
- package/dist/shared/d5azex6s.js +0 -6
- 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/zm0mafk4.js +0 -92
|
@@ -41,6 +41,7 @@ var FIND_OPTIONS = [
|
|
|
41
41
|
"include",
|
|
42
42
|
"limit",
|
|
43
43
|
"orderBy",
|
|
44
|
+
"search",
|
|
44
45
|
"select",
|
|
45
46
|
"route",
|
|
46
47
|
"signal",
|
|
@@ -56,12 +57,15 @@ var ONE_OPTIONS = [
|
|
|
56
57
|
"timeout",
|
|
57
58
|
"where"
|
|
58
59
|
];
|
|
60
|
+
var COUNT_OPTIONS = ["route", "search", "signal", "timeout", "where"];
|
|
59
61
|
var FILTER_OPTIONS = ["route", "signal", "timeout", "where"];
|
|
60
62
|
function readOptionNames(op) {
|
|
61
63
|
if (op === "find")
|
|
62
64
|
return FIND_OPTIONS;
|
|
63
65
|
if (op === "one")
|
|
64
66
|
return ONE_OPTIONS;
|
|
67
|
+
if (op === "count")
|
|
68
|
+
return COUNT_OPTIONS;
|
|
65
69
|
return FILTER_OPTIONS;
|
|
66
70
|
}
|
|
67
71
|
var BASE_RULES = [
|
|
@@ -78,7 +82,19 @@ function readNeedsOperatorSql(schema, call) {
|
|
|
78
82
|
if (operatorEmit !== undefined)
|
|
79
83
|
return false;
|
|
80
84
|
const table = indexes(schema).get(call.table);
|
|
81
|
-
|
|
85
|
+
if (table === undefined)
|
|
86
|
+
return false;
|
|
87
|
+
return needsOperatorSql(table, call.where) || orderHasRelevance(call.orderBy);
|
|
88
|
+
}
|
|
89
|
+
function orderHasRelevance(orderBy) {
|
|
90
|
+
if (!isRecord(orderBy))
|
|
91
|
+
return false;
|
|
92
|
+
for (const key of Object.keys(orderBy)) {
|
|
93
|
+
const value = orderBy[key];
|
|
94
|
+
if (isOperator(value) && operatorName(value) === "relevance")
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
82
98
|
}
|
|
83
99
|
function emitRelationFrom(schema, relation, child, sink, parent, alias, depth) {
|
|
84
100
|
if (relation.through !== undefined) {
|
|
@@ -122,12 +138,12 @@ function needsOperatorSql(table, value, key) {
|
|
|
122
138
|
function isTextColumn(dataType) {
|
|
123
139
|
return dataType === "text" || dataType === "citext" || dataType.startsWith("varchar(") || dataType.startsWith("char(") || dataType.startsWith("character");
|
|
124
140
|
}
|
|
125
|
-
function emitLazy(column, ref, name, value, sink) {
|
|
141
|
+
function emitLazy(column, ref, name, value, sink, order) {
|
|
126
142
|
const emit = operatorEmit;
|
|
127
143
|
if (emit === undefined) {
|
|
128
|
-
|
|
144
|
+
fail2("OKM1121", `Operator ${name} on ${column.field} is not loaded.`);
|
|
129
145
|
}
|
|
130
|
-
emit(column, ref, name, value, sink);
|
|
146
|
+
emit(column, ref, name, value, sink, order);
|
|
131
147
|
}
|
|
132
148
|
function verifyRead(schema, call) {
|
|
133
149
|
if (!safetyInstalled())
|
|
@@ -208,7 +224,7 @@ function logicalIntent(call) {
|
|
|
208
224
|
table: call.table,
|
|
209
225
|
where: plain(call.where),
|
|
210
226
|
select: call.select,
|
|
211
|
-
orderBy: call.orderBy,
|
|
227
|
+
orderBy: plain(call.orderBy),
|
|
212
228
|
limit: call.limit,
|
|
213
229
|
include: plain(call.include),
|
|
214
230
|
all: call.all
|
|
@@ -261,7 +277,7 @@ function emitRead(schema, call, sink, outputs, hooks) {
|
|
|
261
277
|
throwNamed2("OKM1120", call.table, [...indexes(schema).keys()], `Table ${call.table} is not in the schema. Accepted names: ${list([...indexes(schema).keys()])}.`);
|
|
262
278
|
}
|
|
263
279
|
if (call.build !== undefined) {
|
|
264
|
-
call.build(schema, table, sink, outputs, call);
|
|
280
|
+
call.build(schema, table, sink, outputs, call, hooks);
|
|
265
281
|
return;
|
|
266
282
|
}
|
|
267
283
|
rejectOptions(call);
|
|
@@ -296,7 +312,7 @@ function emitRead(schema, call, sink, outputs, hooks) {
|
|
|
296
312
|
column += 1;
|
|
297
313
|
}
|
|
298
314
|
if (call.include !== undefined && hooks === undefined) {
|
|
299
|
-
|
|
315
|
+
fail2("OKM1120", "An include needs the include planner.");
|
|
300
316
|
}
|
|
301
317
|
const includes = hooks === undefined || call.include === undefined ? [] : hooks.read(schema, table, call.include, call.all);
|
|
302
318
|
if (selected.length === 0 && includes.length === 0)
|
|
@@ -375,7 +391,7 @@ function emitWhere(schema, table, where, sink, alias, depth, appended = false, e
|
|
|
375
391
|
continue;
|
|
376
392
|
const joined = isOperator(part);
|
|
377
393
|
if (!joined && !isRecord(part))
|
|
378
|
-
|
|
394
|
+
fail2("OKM1121", WHERE_FIELDS);
|
|
379
395
|
if (!joined && Object.keys(part).length === 0)
|
|
380
396
|
continue;
|
|
381
397
|
sink.text(started ? " and " : " where ");
|
|
@@ -389,7 +405,7 @@ function emitWhere(schema, table, where, sink, alias, depth, appended = false, e
|
|
|
389
405
|
var WHERE_FIELDS = "where must be an object of fields. Wrap an object value with eq.";
|
|
390
406
|
function emitAnd(schema, table, where, sink, alias, depth) {
|
|
391
407
|
if (!isRecord(where)) {
|
|
392
|
-
|
|
408
|
+
fail2("OKM1121", WHERE_FIELDS);
|
|
393
409
|
}
|
|
394
410
|
const keys = Object.keys(where);
|
|
395
411
|
let wrote = false;
|
|
@@ -446,7 +462,7 @@ function emitOperator(schema, table, column, ref, name, value, sink, alias, dept
|
|
|
446
462
|
return;
|
|
447
463
|
}
|
|
448
464
|
if (column === undefined) {
|
|
449
|
-
|
|
465
|
+
fail2("OKM1121", "That operator needs a field.");
|
|
450
466
|
}
|
|
451
467
|
if (name === "not") {
|
|
452
468
|
emitNot(schema, table, column, ref, value, sink, alias, depth);
|
|
@@ -464,7 +480,7 @@ function emitOperator(schema, table, column, ref, name, value, sink, alias, dept
|
|
|
464
480
|
}
|
|
465
481
|
if (name === "between") {
|
|
466
482
|
if (!Array.isArray(value) || value.length !== 2) {
|
|
467
|
-
|
|
483
|
+
fail2("OKM1121", `between on ${column.field} needs two values.`);
|
|
468
484
|
}
|
|
469
485
|
sink.text(ref);
|
|
470
486
|
sink.text(" between ");
|
|
@@ -479,7 +495,7 @@ function emitOperator(schema, table, column, ref, name, value, sink, alias, dept
|
|
|
479
495
|
}
|
|
480
496
|
if (TEXT_OPERATORS.includes(`,${name},`) && isTextColumn(column.dataType)) {
|
|
481
497
|
if (typeof value !== "string") {
|
|
482
|
-
|
|
498
|
+
fail2("OKM1121", `${name} on ${column.field} needs a string.`);
|
|
483
499
|
}
|
|
484
500
|
sink.text(ref);
|
|
485
501
|
if (name === "like" || name === "ilike") {
|
|
@@ -489,7 +505,7 @@ function emitOperator(schema, table, column, ref, name, value, sink, alias, dept
|
|
|
489
505
|
}
|
|
490
506
|
sink.text(" like ");
|
|
491
507
|
if (name !== "startsWith" && name !== "endsWith" && name !== "contains") {
|
|
492
|
-
|
|
508
|
+
fail2("OKM1121", `${name} on ${column.field} needs a string.`);
|
|
493
509
|
}
|
|
494
510
|
sink.param(literalPattern(value, name));
|
|
495
511
|
sink.text(" escape E'\\\\'");
|
|
@@ -517,7 +533,7 @@ function emitNot(schema, table, column, ref, value, sink, alias, depth) {
|
|
|
517
533
|
}
|
|
518
534
|
function emitIn(column, ref, name, value, sink) {
|
|
519
535
|
if (!Array.isArray(value)) {
|
|
520
|
-
|
|
536
|
+
fail2("OKM1121", `${name} on ${column.field} needs a list.`);
|
|
521
537
|
}
|
|
522
538
|
sink.mark(`:${String(value.length)}`);
|
|
523
539
|
if (value.length === 0) {
|
|
@@ -549,7 +565,7 @@ function emitOr(schema, table, value, sink, alias, depth) {
|
|
|
549
565
|
sink.text(" or ");
|
|
550
566
|
sink.text("(");
|
|
551
567
|
if (!isRecord(branch)) {
|
|
552
|
-
|
|
568
|
+
fail2("OKM1121", "or() branches must be where objects.");
|
|
553
569
|
}
|
|
554
570
|
let wrote = false;
|
|
555
571
|
for (const key of Object.keys(branch)) {
|
|
@@ -569,15 +585,15 @@ function emitOr(schema, table, value, sink, alias, depth) {
|
|
|
569
585
|
}
|
|
570
586
|
function emitRelationFilter(schema, relation, value, sink, alias, depth) {
|
|
571
587
|
if (!isOperator(value)) {
|
|
572
|
-
|
|
588
|
+
fail2("OKM1121", `Relation ${relation.name} needs has, none, or every.`);
|
|
573
589
|
}
|
|
574
590
|
const name = operatorName(value);
|
|
575
591
|
if (name !== "has" && name !== "none" && name !== "every") {
|
|
576
|
-
|
|
592
|
+
fail2("OKM1121", `Relation ${relation.name} needs has, none, or every.`);
|
|
577
593
|
}
|
|
578
594
|
const child = indexes(schema).get(relation.table);
|
|
579
595
|
if (child === undefined) {
|
|
580
|
-
|
|
596
|
+
fail2("OKM1120", `Relation ${relation.name} names ${relation.table}, which is not in the schema.`);
|
|
581
597
|
}
|
|
582
598
|
const childAlias = `r${String(depth)}_${relation.name}`;
|
|
583
599
|
sink.mark(`rel:${relation.name}:${name}`);
|
|
@@ -601,7 +617,7 @@ function emitOrder(table, orderBy, sink, alias) {
|
|
|
601
617
|
if (orderBy === undefined)
|
|
602
618
|
return;
|
|
603
619
|
if (!isRecord(orderBy)) {
|
|
604
|
-
|
|
620
|
+
fail2("OKM1120", "orderBy must be an object of fields.");
|
|
605
621
|
}
|
|
606
622
|
const keys = Object.keys(orderBy);
|
|
607
623
|
if (keys.length === 0)
|
|
@@ -616,9 +632,14 @@ function emitOrder(table, orderBy, sink, alias) {
|
|
|
616
632
|
throwNamed2("OKM1120", key, table.names, `Field ${key} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
|
|
617
633
|
}
|
|
618
634
|
refuseHidden(column);
|
|
619
|
-
const
|
|
635
|
+
const value = orderBy[key];
|
|
620
636
|
if (index > 0)
|
|
621
637
|
sink.text(", ");
|
|
638
|
+
if (isOperator(value) && operatorName(value) === "relevance") {
|
|
639
|
+
emitLazy(column, `${alias}.${quote(column.sql)}`, "relevance", operatorValue(value), sink, true);
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
const parsed = parseOrder(key, value);
|
|
622
643
|
sink.text(alias);
|
|
623
644
|
sink.text(".");
|
|
624
645
|
sink.text(quote(column.sql));
|
|
@@ -647,7 +668,7 @@ function emitPrimaryOrder(table, sink, alias) {
|
|
|
647
668
|
function refuseHidden(column) {
|
|
648
669
|
if (column.hidden !== true)
|
|
649
670
|
return;
|
|
650
|
-
|
|
671
|
+
fail2("OKM1120", `Field ${column.field} is hidden.`, "Call hidden({ filterable: true }).");
|
|
651
672
|
}
|
|
652
673
|
function emitLimit(call, sink) {
|
|
653
674
|
if (call.op === "one") {
|
|
@@ -660,7 +681,7 @@ function emitLimit(call, sink) {
|
|
|
660
681
|
return;
|
|
661
682
|
if (call.all !== undefined) {
|
|
662
683
|
if (call.all.length === 0) {
|
|
663
|
-
|
|
684
|
+
fail2("OKM1101", "find() .all needs a reason.");
|
|
664
685
|
}
|
|
665
686
|
sink.mark(`all:${call.all}`);
|
|
666
687
|
if (call.limit !== undefined) {
|
|
@@ -672,7 +693,7 @@ function emitLimit(call, sink) {
|
|
|
672
693
|
return;
|
|
673
694
|
}
|
|
674
695
|
if (call.limit === undefined) {
|
|
675
|
-
|
|
696
|
+
fail2("OKM1101", "find() needs a limit, or .all(reason) when the full set is intentional.");
|
|
676
697
|
}
|
|
677
698
|
const limit = readLimit(call.limit);
|
|
678
699
|
sink.text(" limit ");
|
|
@@ -689,12 +710,12 @@ function selectedColumns(table, select) {
|
|
|
689
710
|
return columns;
|
|
690
711
|
}
|
|
691
712
|
if (!Array.isArray(select)) {
|
|
692
|
-
|
|
713
|
+
fail2("OKM1120", "select must be a list of field names.");
|
|
693
714
|
}
|
|
694
715
|
const columns = [];
|
|
695
716
|
for (const name of select) {
|
|
696
717
|
if (typeof name !== "string") {
|
|
697
|
-
|
|
718
|
+
fail2("OKM1120", "select must be a list of field names.");
|
|
698
719
|
}
|
|
699
720
|
const column = table.columns.get(name);
|
|
700
721
|
if (column === undefined) {
|
|
@@ -712,17 +733,17 @@ function parseOrder(field, value) {
|
|
|
712
733
|
if (isRecord(value)) {
|
|
713
734
|
const dir = value.dir ?? value.direction;
|
|
714
735
|
if (dir !== "asc" && dir !== "desc") {
|
|
715
|
-
|
|
736
|
+
fail2("OKM1120", `orderBy ${field} must be asc or desc.`);
|
|
716
737
|
}
|
|
717
738
|
const nulls = value.nulls;
|
|
718
739
|
if (nulls === undefined)
|
|
719
740
|
return { dir, nulls: dir === "asc" ? "last" : "first" };
|
|
720
741
|
if (nulls !== "first" && nulls !== "last") {
|
|
721
|
-
|
|
742
|
+
fail2("OKM1120", `orderBy ${field} nulls must be first or last.`);
|
|
722
743
|
}
|
|
723
744
|
return { dir, nulls };
|
|
724
745
|
}
|
|
725
|
-
|
|
746
|
+
fail2("OKM1120", `orderBy ${field} must be asc or desc.`);
|
|
726
747
|
}
|
|
727
748
|
function rejectOptions(call) {
|
|
728
749
|
const accepted = readOptionNames(call.op);
|
|
@@ -739,11 +760,11 @@ function rejectOptions(call) {
|
|
|
739
760
|
present.include = call.include;
|
|
740
761
|
rejectKeys(present, accepted, call.op);
|
|
741
762
|
}
|
|
742
|
-
function rejectKeys(value, accepted, where) {
|
|
763
|
+
function rejectKeys(value, accepted, where, search) {
|
|
743
764
|
for (const key of Object.keys(value)) {
|
|
744
765
|
if (accepted.includes(key))
|
|
745
766
|
continue;
|
|
746
|
-
throwNamed2("OKM1120", key, accepted, `Option ${key} is not accepted by ${where}. Accepted options: ${list(accepted)}.`);
|
|
767
|
+
throwNamed2("OKM1120", key, accepted, key === "search" && search === true ? `${where}() does not take search. Pass search to find or count.` : `Option ${key} is not accepted by ${where}. Accepted options: ${list(accepted)}.`);
|
|
747
768
|
}
|
|
748
769
|
}
|
|
749
770
|
function readLimit(value) {
|
|
@@ -754,7 +775,7 @@ function readLimit(value) {
|
|
|
754
775
|
}
|
|
755
776
|
function requireValue(column, value) {
|
|
756
777
|
if (value === undefined || value === null) {
|
|
757
|
-
|
|
778
|
+
fail2("OKM1121", `Field ${column.field} needs a value.`);
|
|
758
779
|
}
|
|
759
780
|
if (typeof value === "object")
|
|
760
781
|
takeObject(column, value);
|
|
@@ -762,7 +783,7 @@ function requireValue(column, value) {
|
|
|
762
783
|
}
|
|
763
784
|
function takeObject(column, value, bare = false) {
|
|
764
785
|
if (bare || !column.accepts?.includes({}.toString.call(value).slice(8, -1))) {
|
|
765
|
-
|
|
786
|
+
fail2("OKM1121", `Field ${column.field} rejects that object.`);
|
|
766
787
|
}
|
|
767
788
|
}
|
|
768
789
|
function projectExpr(sql, dataType) {
|
|
@@ -867,7 +888,7 @@ var FAIL_FIX = {
|
|
|
867
888
|
function registerFailFix(code, summary) {
|
|
868
889
|
FAIL_FIX[code] = summary;
|
|
869
890
|
}
|
|
870
|
-
function
|
|
891
|
+
function fail2(code, message, fix) {
|
|
871
892
|
const summary = fix ?? FAIL_FIX[code];
|
|
872
893
|
throw new OkmError2(code, message, summary === undefined ? undefined : { fix: { summary } });
|
|
873
894
|
}
|
|
@@ -891,4 +912,4 @@ function hasMany(include) {
|
|
|
891
912
|
return Object.keys(include).length > 0;
|
|
892
913
|
}
|
|
893
914
|
|
|
894
|
-
export { withRowFilters, installArchiveInspect, archiveRules, readOptionNames, installOperatorSql, readNeedsOperatorSql, emitRelationFrom, bindCall, compileCall, decodeResult, logicalIntent, appliedRules, emitJoin, emitWhere, emitOrder, emitPrimaryOrder, refuseHidden, selectedColumns, parseOrder, rejectKeys, readLimit, takeObject, projectExpr, jsonExpr, decodeRow, cell, indexes, quote, list, isRecord, orFail, registerFailFix,
|
|
915
|
+
export { withRowFilters, installArchiveInspect, archiveRules, readOptionNames, installOperatorSql, readNeedsOperatorSql, orderHasRelevance, emitRelationFrom, needsOperatorSql, bindCall, compileCall, decodeResult, logicalIntent, appliedRules, emitJoin, emitWhere, emitOrder, emitPrimaryOrder, refuseHidden, emitLimit, selectedColumns, parseOrder, rejectKeys, readLimit, takeObject, projectExpr, jsonExpr, decodeRow, cell, indexes, quote, list, isRecord, orFail, registerFailFix, fail2 };
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
viewGlobalReason,
|
|
6
6
|
viewMentions
|
|
7
|
-
} from "./
|
|
7
|
+
} from "./5e3tf63j.js";
|
|
8
8
|
import {
|
|
9
9
|
createClient
|
|
10
|
-
} from "./
|
|
10
|
+
} from "./tbrvgw6z.js";
|
|
11
11
|
import {
|
|
12
12
|
OkmError2
|
|
13
13
|
} from "./52szzakm.js";
|
|
@@ -641,7 +641,10 @@ async function readTenant(facts, handle, where) {
|
|
|
641
641
|
leak(facts.name, "stream", item);
|
|
642
642
|
}
|
|
643
643
|
} catch (error) {
|
|
644
|
-
if (!(error instanceof OkmError2)
|
|
644
|
+
if (!(error instanceof OkmError2))
|
|
645
|
+
throw error;
|
|
646
|
+
const refused = error.code === "OKM1111" || error.code === "OKM1120" && error.message.includes("primary key");
|
|
647
|
+
if (!refused)
|
|
645
648
|
throw error;
|
|
646
649
|
}
|
|
647
650
|
}
|
|
@@ -988,7 +991,10 @@ async function readFiltered(name, handle, where) {
|
|
|
988
991
|
leak(name, "stream", item);
|
|
989
992
|
}
|
|
990
993
|
} catch (error) {
|
|
991
|
-
if (!(error instanceof OkmError2)
|
|
994
|
+
if (!(error instanceof OkmError2))
|
|
995
|
+
throw error;
|
|
996
|
+
const refused = error.code === "OKM1111" || error.code === "OKM1120" && error.message.includes("primary key");
|
|
997
|
+
if (!refused)
|
|
992
998
|
throw error;
|
|
993
999
|
}
|
|
994
1000
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/adapters/pg/cursor.ts
|
|
2
|
+
async function* cursorStream(run, text, params) {
|
|
3
|
+
const name = "okm_stream";
|
|
4
|
+
await run("BEGIN");
|
|
5
|
+
try {
|
|
6
|
+
await run(`DECLARE ${name} NO SCROLL CURSOR FOR ${text}`, params);
|
|
7
|
+
for (;; ) {
|
|
8
|
+
const chunk = await run(`FETCH 64 FROM ${name}`);
|
|
9
|
+
if (chunk.rows.length === 0)
|
|
10
|
+
break;
|
|
11
|
+
yield chunk.rows;
|
|
12
|
+
}
|
|
13
|
+
} finally {
|
|
14
|
+
await run("ROLLBACK").catch(() => {
|
|
15
|
+
return;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { cursorStream };
|
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./
|
|
2
|
+
noTimeout
|
|
3
|
+
} from "./79dt02vc.js";
|
|
4
4
|
import {
|
|
5
5
|
PGLITE_CAPABILITIES,
|
|
6
6
|
driverErrors,
|
|
7
7
|
rejectClosed,
|
|
8
8
|
rejectCancelled,
|
|
9
9
|
rejectTimedOut,
|
|
10
|
-
mapFailure,
|
|
11
10
|
nextTransactionDepth,
|
|
12
11
|
runCall,
|
|
13
12
|
EMPTY_NOTICES,
|
|
14
13
|
resultFrom
|
|
15
|
-
} from "./
|
|
14
|
+
} from "./kb2sdhfb.js";
|
|
16
15
|
|
|
17
16
|
// src/adapters/pg/pglite.ts
|
|
18
17
|
import { PGlite } from "@electric-sql/pglite";
|
|
19
|
-
var RESET_ALL = "RESET ALL";
|
|
20
|
-
var UNLOCK = "SELECT pg_advisory_unlock_all()";
|
|
21
18
|
async function open3(config = {}) {
|
|
19
|
+
const wire = await import("./g6evj1j3.js");
|
|
22
20
|
const db = new PGlite({
|
|
23
21
|
dataDir: config.dataDir ?? "memory://",
|
|
24
|
-
parsers:
|
|
25
|
-
serializers:
|
|
22
|
+
parsers: wire.parsers,
|
|
23
|
+
serializers: wire.serializers
|
|
26
24
|
});
|
|
27
25
|
await db.waitReady;
|
|
28
26
|
const acquireMs = config.timeouts?.acquire;
|
|
@@ -30,8 +28,8 @@ async function open3(config = {}) {
|
|
|
30
28
|
const notices = noticeBuffer();
|
|
31
29
|
const queryOptions = {
|
|
32
30
|
rowMode: "array",
|
|
33
|
-
parsers:
|
|
34
|
-
serializers:
|
|
31
|
+
parsers: wire.parsers,
|
|
32
|
+
serializers: wire.serializers,
|
|
35
33
|
onNotice(notice) {
|
|
36
34
|
notices.push(notice);
|
|
37
35
|
}
|
|
@@ -42,7 +40,7 @@ async function open3(config = {}) {
|
|
|
42
40
|
inflight += 1;
|
|
43
41
|
}, () => {
|
|
44
42
|
inflight = Math.max(0, inflight - 1);
|
|
45
|
-
});
|
|
43
|
+
}, (error) => wire.fail(error));
|
|
46
44
|
async function lease() {
|
|
47
45
|
if (closed)
|
|
48
46
|
return rejectClosed();
|
|
@@ -50,13 +48,17 @@ async function open3(config = {}) {
|
|
|
50
48
|
let released = false;
|
|
51
49
|
return {
|
|
52
50
|
execute: (text, params, options) => {
|
|
53
|
-
|
|
51
|
+
const refused = noTimeout(options);
|
|
52
|
+
if (refused !== undefined)
|
|
53
|
+
return refused;
|
|
54
54
|
return runCall(closed, options, (watch) => session.query(text, params, watch));
|
|
55
55
|
},
|
|
56
56
|
batch: (statements, options) => {
|
|
57
|
-
|
|
57
|
+
const refused = noTimeout(options);
|
|
58
|
+
if (refused !== undefined)
|
|
59
|
+
return refused;
|
|
58
60
|
return runCall(closed, options, async (watch) => {
|
|
59
|
-
const { runAtomicBatch } = await import("./
|
|
61
|
+
const { runAtomicBatch } = await import("./b76b8d95.js");
|
|
60
62
|
return runAtomicBatch(session, statements, watch);
|
|
61
63
|
});
|
|
62
64
|
},
|
|
@@ -65,7 +67,8 @@ async function open3(config = {}) {
|
|
|
65
67
|
return;
|
|
66
68
|
released = true;
|
|
67
69
|
try {
|
|
68
|
-
await
|
|
70
|
+
const { resetQueried } = await import("./5fe3kbsh.js");
|
|
71
|
+
await resetQueried(session);
|
|
69
72
|
} finally {
|
|
70
73
|
slot.release();
|
|
71
74
|
}
|
|
@@ -75,7 +78,9 @@ async function open3(config = {}) {
|
|
|
75
78
|
return {
|
|
76
79
|
capabilities: PGLITE_CAPABILITIES,
|
|
77
80
|
execute(text, params, options) {
|
|
78
|
-
|
|
81
|
+
const refused = noTimeout(options);
|
|
82
|
+
if (refused !== undefined)
|
|
83
|
+
return refused;
|
|
79
84
|
return runCall(closed, options, async (watch) => {
|
|
80
85
|
await slot.acquire(acquireMs);
|
|
81
86
|
try {
|
|
@@ -86,7 +91,9 @@ async function open3(config = {}) {
|
|
|
86
91
|
});
|
|
87
92
|
},
|
|
88
93
|
async batch(statements, options) {
|
|
89
|
-
|
|
94
|
+
const refused = noTimeout(options);
|
|
95
|
+
if (refused !== undefined)
|
|
96
|
+
return refused;
|
|
90
97
|
const connection = await lease();
|
|
91
98
|
try {
|
|
92
99
|
return await connection.batch(statements, options);
|
|
@@ -122,6 +129,12 @@ async function open3(config = {}) {
|
|
|
122
129
|
}
|
|
123
130
|
};
|
|
124
131
|
}
|
|
132
|
+
function seal2(pool) {
|
|
133
|
+
let closed = 0;
|
|
134
|
+
return new Proxy(pool, {
|
|
135
|
+
get: (inner, key) => key === "close" ? () => Promise.resolve(closed = 1) : (inner = inner[key], closed && inner?.call ? () => rejectClosed() : inner)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
125
138
|
|
|
126
139
|
class PgliteSession {
|
|
127
140
|
canCancel = false;
|
|
@@ -131,12 +144,14 @@ class PgliteSession {
|
|
|
131
144
|
notices;
|
|
132
145
|
enter;
|
|
133
146
|
leave;
|
|
134
|
-
|
|
147
|
+
fail;
|
|
148
|
+
constructor(db, options, notices, enter, leave, fail) {
|
|
135
149
|
this.db = db;
|
|
136
150
|
this.options = options;
|
|
137
151
|
this.notices = notices;
|
|
138
152
|
this.enter = enter;
|
|
139
153
|
this.leave = leave;
|
|
154
|
+
this.fail = fail;
|
|
140
155
|
}
|
|
141
156
|
query(text, params, watch) {
|
|
142
157
|
const why = watch?.reason();
|
|
@@ -153,7 +168,7 @@ class PgliteSession {
|
|
|
153
168
|
}, (error) => {
|
|
154
169
|
this.leave();
|
|
155
170
|
this.notices.take();
|
|
156
|
-
return
|
|
171
|
+
return this.fail(stampQuery(error, text)).then((mapped) => {
|
|
157
172
|
throw mapped;
|
|
158
173
|
});
|
|
159
174
|
});
|
|
@@ -237,56 +252,10 @@ class Slot {
|
|
|
237
252
|
return this.waiters.length;
|
|
238
253
|
}
|
|
239
254
|
}
|
|
240
|
-
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
});
|
|
245
|
-
try {
|
|
246
|
-
await session.query(RESET_ALL, undefined, undefined);
|
|
247
|
-
await session.query(UNLOCK, undefined, undefined);
|
|
248
|
-
} catch {
|
|
249
|
-
await session.rollback().catch(() => {
|
|
250
|
-
return;
|
|
251
|
-
});
|
|
252
|
-
await session.query(RESET_ALL, undefined, undefined);
|
|
253
|
-
await session.query(UNLOCK, undefined, undefined);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
function wireMap(oids) {
|
|
257
|
-
const parsers = {};
|
|
258
|
-
for (const oid of oids)
|
|
259
|
-
parsers[oid] = (value) => value;
|
|
260
|
-
return parsers;
|
|
255
|
+
function stampQuery(error, text) {
|
|
256
|
+
if (typeof error === "object" && error !== null && !("query" in error))
|
|
257
|
+
Reflect.set(error, "query", text);
|
|
258
|
+
return error;
|
|
261
259
|
}
|
|
262
|
-
var WIRE = wireMap([
|
|
263
|
-
16,
|
|
264
|
-
17,
|
|
265
|
-
20,
|
|
266
|
-
21,
|
|
267
|
-
23,
|
|
268
|
-
25,
|
|
269
|
-
114,
|
|
270
|
-
700,
|
|
271
|
-
701,
|
|
272
|
-
1043,
|
|
273
|
-
1082,
|
|
274
|
-
1114,
|
|
275
|
-
1184,
|
|
276
|
-
1700,
|
|
277
|
-
2950,
|
|
278
|
-
3802,
|
|
279
|
-
1000,
|
|
280
|
-
1005,
|
|
281
|
-
1007,
|
|
282
|
-
1009,
|
|
283
|
-
1016,
|
|
284
|
-
1115,
|
|
285
|
-
1182,
|
|
286
|
-
1185,
|
|
287
|
-
1231,
|
|
288
|
-
199,
|
|
289
|
-
3807
|
|
290
|
-
]);
|
|
291
260
|
|
|
292
|
-
export { open3 };
|
|
261
|
+
export { open3, seal2 };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/dialects/pg/ops/window.ts
|
|
2
|
+
var RUNTIME = Symbol.for("okmodel.window");
|
|
3
|
+
function isWindow(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && RUNTIME in value;
|
|
5
|
+
}
|
|
6
|
+
function rowNumber2(options) {
|
|
7
|
+
return frame("rowNumber", "row_number", undefined, options);
|
|
8
|
+
}
|
|
9
|
+
function rank2(options) {
|
|
10
|
+
return frame("rank", "rank", undefined, options);
|
|
11
|
+
}
|
|
12
|
+
function denseRank2(options) {
|
|
13
|
+
return frame("denseRank", "dense_rank", undefined, options);
|
|
14
|
+
}
|
|
15
|
+
function runningTotal2(column, options) {
|
|
16
|
+
return frame("runningTotal", "sum", column, options);
|
|
17
|
+
}
|
|
18
|
+
function frame(label, fn, column, options) {
|
|
19
|
+
const spec = options ?? { orderBy: undefined, as: undefined, partitionBy: undefined };
|
|
20
|
+
return {
|
|
21
|
+
[RUNTIME]: true,
|
|
22
|
+
label,
|
|
23
|
+
fn,
|
|
24
|
+
column,
|
|
25
|
+
partitionBy: spec.partitionBy,
|
|
26
|
+
orderBy: spec.orderBy,
|
|
27
|
+
as: spec.as
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { isWindow, rowNumber2, rank2, denseRank2, runningTotal2 };
|