okmodel 0.5.0 → 0.5.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 +9 -6
- package/dist/dialects/pg/filter-parse.d.ts +8 -2
- package/dist/dialects/pg/fn/index.js +8 -0
- package/dist/dialects/pg/index.js +8 -2
- package/dist/dialects/pg/ops/or.d.ts +1 -1
- package/dist/dialects/pg/temporal.d.ts +5 -76
- package/dist/dialects/pg/view/index.js +1 -1
- package/dist/runtime/client.d.ts +6 -1
- package/dist/runtime/conflict.d.ts +2 -1
- package/dist/runtime/pg/bun.js +5 -5
- package/dist/runtime/pg/pg.js +5 -5
- package/dist/runtime/pg/pglite.js +5 -5
- package/dist/runtime/pg/postgresjs.js +5 -5
- package/dist/runtime/plan.d.ts +13 -0
- package/dist/runtime/tenancy/index.js +1 -1
- package/dist/runtime/traits/index.js +4 -4
- package/dist/runtime/validate/index.js +3 -3
- package/dist/shared/{ckjbyrt9.js → 0t22wwh1.js} +5 -9
- package/dist/shared/{jdgqqx31.js → 2pqx26h8.js} +23 -8
- package/dist/shared/{kyxb62mc.js → 31vm914h.js} +9 -1
- package/dist/shared/{9tgmr1gh.js → 32zqc1dw.js} +18 -7
- package/dist/shared/{47xzb9fc.js → 47x8x9ze.js} +1 -1
- package/dist/shared/{zvbjc949.js → 4az561fn.js} +1 -1
- package/dist/shared/{s6gqfn5j.js → 51mvgj8w.js} +27 -3
- package/dist/shared/{k3ted12y.js → 54tqkxja.js} +20 -2
- package/dist/shared/{3p4b1fg0.js → 5enne4ma.js} +1 -1
- package/dist/shared/{bzsjtd7c.js → 6mnp99hx.js} +7 -6
- package/dist/shared/{ykv7wh5b.js → 6qd27mx0.js} +2 -2
- package/dist/shared/{h4nqvjkp.js → 6rk2gen5.js} +2 -2
- package/dist/shared/{r73pt594.js → 7zwwyh0v.js} +32 -10
- package/dist/shared/{fa9vt245.js → 87jvvhnt.js} +2 -2
- package/dist/shared/{c8aghh05.js → 8rsy3hxz.js} +7 -1
- package/dist/shared/{6p5k20sm.js → 96qcj21c.js} +3 -3
- package/dist/shared/{xsq7v6wp.js → aj2qxyhj.js} +2 -2
- package/dist/shared/{5vdm4sgp.js → caw8b9d8.js} +4 -4
- package/dist/shared/{xhh1srw3.js → cctw17hj.js} +23 -8
- package/dist/shared/{rrstp3kb.js → cgbamx3e.js} +2 -2
- package/dist/shared/{tq9afp8d.js → cr74e96e.js} +1 -1
- package/dist/shared/{b066g80h.js → efmy2gcg.js} +2 -2
- package/dist/shared/{gdh9mrtp.js → f5cw5q5r.js} +2 -2
- package/dist/shared/{ayz64vzj.js → ga3sfy93.js} +357 -3
- package/dist/shared/{qgvt8nx1.js → gbtcc2d7.js} +44 -3
- package/dist/shared/{kdkxh3kb.js → gde73es6.js} +5 -7
- package/dist/shared/{bt9sfq0z.js → hf22e0wt.js} +51 -17
- package/dist/shared/{990a291j.js → janx09m5.js} +6 -5
- package/dist/shared/{4ef7mmqf.js → jwtxdj06.js} +5 -5
- package/dist/shared/{sf8m6tfy.js → k8v5v5wj.js} +3 -3
- package/dist/shared/{r6pj4fq2.js → kfjp0gck.js} +2 -2
- package/dist/shared/{wqem4jed.js → krxx77g0.js} +7 -7
- package/dist/shared/{h8ne16fq.js → nkaxvt9q.js} +1 -1
- package/dist/shared/{jsd07prz.js → ntneex2a.js} +1 -1
- package/dist/shared/{nkc9sfqb.js → nxdp2ze3.js} +40 -4
- package/dist/shared/{tbszx8mz.js → pf0d8f77.js} +1 -1
- package/dist/shared/{qy9rdq0g.js → ps7a6h14.js} +6 -6
- package/dist/shared/{rasvvzgz.js → q58y17hy.js} +5 -5
- package/dist/shared/{p7pfx624.js → qm7cdtvr.js} +22 -9
- package/dist/shared/{xdpj5kkm.js → qv2ydck9.js} +149 -209
- package/dist/shared/{k7cc9nzk.js → r2sp8hrc.js} +6 -3
- package/dist/shared/{fb00y8fp.js → r8x5qhd7.js} +5 -5
- package/dist/shared/{fyqkk1m0.js → sdc7r2ww.js} +6 -5
- package/dist/shared/{wxn4b7pp.js → sycnx8gt.js} +42 -5
- package/dist/shared/{dxjp14rk.js → tm5ab8we.js} +2 -2
- package/dist/shared/{g516zdsb.js → v36c5g6p.js} +78 -19
- package/dist/shared/wq9n6pwr.js +139 -0
- package/dist/shared/{7p2wbz7f.js → x72jb7ad.js} +1 -1
- package/dist/shared/{922qbgnw.js → zqrnhwsq.js} +3 -3
- package/dist/tooling/cli.js +68 -21
- package/dist/tooling/migrate/commands.d.ts +1 -2
- package/dist/tooling/migrate/drift.d.ts +1 -1
- package/dist/tooling/migrate/estimate.d.ts +14 -1
- package/dist/tooling/migrate/index.js +8 -7
- package/dist/tooling/migrate/lint.d.ts +3 -3
- package/dist/tooling/migrate/plan.d.ts +7 -3
- package/dist/tooling/migrate/policy.d.ts +11 -0
- package/dist/tooling/migrate/sql-lex.d.ts +22 -0
- package/dist/tooling/testing/factories.d.ts +10 -0
- package/dist/tooling/testing/index.js +1 -1
- package/dist/tooling/testing/isolation.d.ts +4 -3
- package/package.json +6 -5
- package/dist/shared/0v1g424p.js +0 -26
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
open2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./krxx77g0.js";
|
|
4
4
|
import"./8bwbwy8h.js";
|
|
5
5
|
import"./n442h54c.js";
|
|
6
6
|
import {
|
|
7
|
-
assertTargetPolicy,
|
|
8
|
-
selectTarget,
|
|
9
7
|
openProject
|
|
10
|
-
} from "./
|
|
11
|
-
import
|
|
8
|
+
} from "./qv2ydck9.js";
|
|
9
|
+
import {
|
|
10
|
+
assertTargetPolicy,
|
|
11
|
+
selectTarget
|
|
12
|
+
} from "./ga3sfy93.js";
|
|
12
13
|
import"./8xsbagad.js";
|
|
13
14
|
import {
|
|
14
15
|
isExactVersion,
|
|
@@ -2,17 +2,17 @@ import {
|
|
|
2
2
|
send2,
|
|
3
3
|
reserve,
|
|
4
4
|
park
|
|
5
|
-
} from "./
|
|
5
|
+
} from "./k8v5v5wj.js";
|
|
6
6
|
import {
|
|
7
7
|
isConnectionLost
|
|
8
|
-
} from "./
|
|
8
|
+
} from "./pf0d8f77.js";
|
|
9
9
|
import {
|
|
10
10
|
WireSession
|
|
11
|
-
} from "./
|
|
11
|
+
} from "./4az561fn.js";
|
|
12
12
|
import {
|
|
13
13
|
rejectClosed,
|
|
14
14
|
runCall
|
|
15
|
-
} from "./
|
|
15
|
+
} from "./cgbamx3e.js";
|
|
16
16
|
|
|
17
17
|
// src/adapters/pg/bunsql-extra.ts
|
|
18
18
|
async function checkout(held) {
|
|
@@ -36,7 +36,7 @@ async function checkout(held) {
|
|
|
36
36
|
return {
|
|
37
37
|
execute: (text, params, options) => guard(() => runCall(isClosed(), options, (watch) => session.query(text, params, watch))),
|
|
38
38
|
batch: (statements, options) => guard(() => runCall(isClosed(), options, async (watch) => {
|
|
39
|
-
const { runAtomicBatch } = await import("./
|
|
39
|
+
const { runAtomicBatch } = await import("./efmy2gcg.js");
|
|
40
40
|
return runAtomicBatch(session, statements, watch);
|
|
41
41
|
})),
|
|
42
42
|
async release() {
|
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
noticeBuffer,
|
|
3
3
|
WireSession,
|
|
4
4
|
cursorStream
|
|
5
|
-
} from "./
|
|
5
|
+
} from "./4az561fn.js";
|
|
6
6
|
import {
|
|
7
7
|
BUNSQL_CAPABILITIES,
|
|
8
8
|
driverErrors,
|
|
9
9
|
rejectClosed,
|
|
10
10
|
mapFailure,
|
|
11
11
|
runCall
|
|
12
|
-
} from "./
|
|
12
|
+
} from "./cgbamx3e.js";
|
|
13
13
|
|
|
14
14
|
// src/adapters/pg/bunsql.ts
|
|
15
15
|
import { SQL } from "bun";
|
|
@@ -41,7 +41,7 @@ function open5(config) {
|
|
|
41
41
|
counters.busy = Math.max(0, counters.busy - 1);
|
|
42
42
|
});
|
|
43
43
|
const held = { sql, parked, acquireMs, counters, notices, isClosed };
|
|
44
|
-
const checkout = () => closed ? rejectClosed() : import("./
|
|
44
|
+
const checkout = () => closed ? rejectClosed() : import("./jwtxdj06.js").then((mod) => mod.checkout(held));
|
|
45
45
|
return {
|
|
46
46
|
capabilities: BUNSQL_CAPABILITIES,
|
|
47
47
|
execute(text, params, options) {
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
readHandle,
|
|
3
3
|
readCall,
|
|
4
4
|
attachHttp
|
|
5
|
-
} from "./
|
|
5
|
+
} from "./hf22e0wt.js";
|
|
6
6
|
import {
|
|
7
7
|
emitWhere,
|
|
8
8
|
emitOrder,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
list,
|
|
16
16
|
isRecord,
|
|
17
17
|
fail
|
|
18
|
-
} from "./
|
|
18
|
+
} from "./gbtcc2d7.js";
|
|
19
19
|
import {
|
|
20
20
|
OkmError2,
|
|
21
21
|
throwNamed2
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
runCall,
|
|
7
7
|
EMPTY_NOTICES,
|
|
8
8
|
resultFrom
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./cgbamx3e.js";
|
|
10
10
|
|
|
11
11
|
// src/adapters/pg/postgresjs.ts
|
|
12
12
|
import net from "node:net";
|
|
@@ -117,7 +117,7 @@ function open2(config) {
|
|
|
117
117
|
},
|
|
118
118
|
async batch(statements, options) {
|
|
119
119
|
return sockets.occupy(async () => {
|
|
120
|
-
const { checkout } = await import("./
|
|
120
|
+
const { checkout } = await import("./caw8b9d8.js");
|
|
121
121
|
const connection = await checkout(held);
|
|
122
122
|
try {
|
|
123
123
|
return await connection.batch(statements, options);
|
|
@@ -129,12 +129,12 @@ function open2(config) {
|
|
|
129
129
|
reserve() {
|
|
130
130
|
const gate = sockets.busyGate();
|
|
131
131
|
gate.enter();
|
|
132
|
-
return import("./
|
|
132
|
+
return import("./caw8b9d8.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
|
|
133
133
|
gate.leave();
|
|
134
134
|
throw error;
|
|
135
135
|
});
|
|
136
136
|
},
|
|
137
|
-
describe: (text, params) => sockets.occupy(() => import("./
|
|
137
|
+
describe: (text, params) => sockets.occupy(() => import("./caw8b9d8.js").then((mod) => mod.describe(sql, text, params))),
|
|
138
138
|
stream(text, params) {
|
|
139
139
|
const gate = sockets.busyGate();
|
|
140
140
|
return async function* () {
|
|
@@ -149,7 +149,7 @@ function open2(config) {
|
|
|
149
149
|
listen(channel, onNotify) {
|
|
150
150
|
const gate = sockets.listenerGate();
|
|
151
151
|
gate.enter();
|
|
152
|
-
return import("./
|
|
152
|
+
return import("./caw8b9d8.js").then((mod) => mod.holdListener(gate, async () => {
|
|
153
153
|
const listening = await sql.listen(channel, onNotify);
|
|
154
154
|
return async () => {
|
|
155
155
|
await listening.unlisten();
|
|
@@ -219,7 +219,7 @@ class PgSession {
|
|
|
219
219
|
onAbort();
|
|
220
220
|
else
|
|
221
221
|
watch.signal.addEventListener("abort", onAbort, { once: true });
|
|
222
|
-
return import("./
|
|
222
|
+
return import("./caw8b9d8.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
|
|
223
223
|
start,
|
|
224
224
|
text,
|
|
225
225
|
notices: this.notices,
|
|
@@ -271,7 +271,7 @@ class PgSession {
|
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
async function* loadStream(sql, text, params) {
|
|
274
|
-
const { stream } = await import("./
|
|
274
|
+
const { stream } = await import("./caw8b9d8.js");
|
|
275
275
|
yield* stream(sql, text, params);
|
|
276
276
|
}
|
|
277
277
|
function send(sql, text, params, named) {
|
|
@@ -29,7 +29,7 @@ function openFilters(table, relations, spec, hiddenFields) {
|
|
|
29
29
|
}
|
|
30
30
|
return {
|
|
31
31
|
parse(query) {
|
|
32
|
-
return import("./
|
|
32
|
+
return import("./wq9n6pwr.js").then((mod) => mod.parseQuery(allow, sort, query));
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
isConnectionSqlstate,
|
|
3
|
+
isConnectionErrno
|
|
4
|
+
} from "./pf0d8f77.js";
|
|
4
5
|
import {
|
|
5
6
|
createClient
|
|
6
|
-
} from "./
|
|
7
|
+
} from "./hf22e0wt.js";
|
|
7
8
|
import {
|
|
8
9
|
OkmError2
|
|
9
10
|
} from "./52szzakm.js";
|
|
@@ -674,7 +675,7 @@ async function attempt(handle, choice, run) {
|
|
|
674
675
|
try {
|
|
675
676
|
return await tracked(choice.endpoint, choice.op === "read", () => run(choice.endpoint));
|
|
676
677
|
} catch (error) {
|
|
677
|
-
if (choice.op !== "read" || !
|
|
678
|
+
if (choice.op !== "read" || !isUnreachable(error))
|
|
678
679
|
throw error;
|
|
679
680
|
const next = await retryOf(handle, choice);
|
|
680
681
|
if (next === undefined)
|
|
@@ -683,6 +684,41 @@ async function attempt(handle, choice, run) {
|
|
|
683
684
|
return tracked(next.endpoint, true, () => run(next.endpoint));
|
|
684
685
|
}
|
|
685
686
|
}
|
|
687
|
+
var CHAIN_DEPTH = 8;
|
|
688
|
+
function isUnreachable(error) {
|
|
689
|
+
const seen = new Set;
|
|
690
|
+
const visit = (value, depth) => {
|
|
691
|
+
if (typeof value !== "object" || value === null || depth > CHAIN_DEPTH)
|
|
692
|
+
return false;
|
|
693
|
+
if (seen.has(value))
|
|
694
|
+
return false;
|
|
695
|
+
seen.add(value);
|
|
696
|
+
if (unreachableNode(value))
|
|
697
|
+
return true;
|
|
698
|
+
if (visit(Reflect.get(value, "cause"), depth + 1))
|
|
699
|
+
return true;
|
|
700
|
+
const errors = Reflect.get(value, "errors");
|
|
701
|
+
return Array.isArray(errors) && errors.some((item) => visit(item, depth + 1));
|
|
702
|
+
};
|
|
703
|
+
return visit(error, 0);
|
|
704
|
+
}
|
|
705
|
+
function unreachableNode(node) {
|
|
706
|
+
for (const key of ["sqlstate", "code", "errno"]) {
|
|
707
|
+
const code = Reflect.get(node, key);
|
|
708
|
+
if (typeof code !== "string" || code.length === 0)
|
|
709
|
+
continue;
|
|
710
|
+
if (isConnectionSqlstate(code) || isConnectionErrno(code))
|
|
711
|
+
return true;
|
|
712
|
+
if (code.startsWith("ERR_POSTGRES_CONNECTION_"))
|
|
713
|
+
return true;
|
|
714
|
+
if (code === "ERR_POSTGRES_IDLE_TIMEOUT" || code === "ERR_POSTGRES_LIFETIME_TIMEOUT") {
|
|
715
|
+
return true;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
if (!(node instanceof Error))
|
|
719
|
+
return false;
|
|
720
|
+
return node.message.includes("ECONNREFUSED") || node.message.includes("ECONNRESET") || node.message.includes("CONNECTION_CLOSED") || node.message.includes("terminating connection") || node.message.includes("The pool is closed");
|
|
721
|
+
}
|
|
686
722
|
async function tracked(endpoint, time, run) {
|
|
687
723
|
const replica = endpoint.role === "replica";
|
|
688
724
|
if (replica)
|
|
@@ -51,4 +51,4 @@ function readCode(error, key) {
|
|
|
51
51
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export { isConnectionSqlstate, isConnectionFailure, isConnectionLost };
|
|
54
|
+
export { isConnectionSqlstate, isConnectionErrno, isConnectionFailure, isConnectionLost };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
open2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./krxx77g0.js";
|
|
4
4
|
import"./8bwbwy8h.js";
|
|
5
5
|
import"./n442h54c.js";
|
|
6
6
|
import {
|
|
@@ -9,13 +9,13 @@ import {
|
|
|
9
9
|
import"./fancm5pt.js";
|
|
10
10
|
import {
|
|
11
11
|
errorDoc,
|
|
12
|
-
assertTargetPolicy,
|
|
13
|
-
selectTarget,
|
|
14
12
|
openProject
|
|
15
|
-
} from "./
|
|
13
|
+
} from "./qv2ydck9.js";
|
|
16
14
|
import {
|
|
17
|
-
omitManagedObjects
|
|
18
|
-
|
|
15
|
+
omitManagedObjects,
|
|
16
|
+
assertTargetPolicy,
|
|
17
|
+
selectTarget
|
|
18
|
+
} from "./ga3sfy93.js";
|
|
19
19
|
import"./8xsbagad.js";
|
|
20
20
|
import {
|
|
21
21
|
OkmError2
|
|
@@ -3,16 +3,16 @@ import {
|
|
|
3
3
|
applyProject2,
|
|
4
4
|
pushProject2,
|
|
5
5
|
backfillTiming2
|
|
6
|
-
} from "./
|
|
7
|
-
import"./
|
|
6
|
+
} from "./cctw17hj.js";
|
|
7
|
+
import"./gde73es6.js";
|
|
8
8
|
import"./szm0cksa.js";
|
|
9
9
|
import"./fancm5pt.js";
|
|
10
|
-
import"./
|
|
11
|
-
import"./
|
|
10
|
+
import"./qv2ydck9.js";
|
|
11
|
+
import"./ga3sfy93.js";
|
|
12
12
|
import"./n442h54c.js";
|
|
13
13
|
import"./8xsbagad.js";
|
|
14
14
|
import"./8bwbwy8h.js";
|
|
15
|
-
import"./
|
|
15
|
+
import"./krxx77g0.js";
|
|
16
16
|
export {
|
|
17
17
|
applyProject2 as applyProject,
|
|
18
18
|
applyTarget2 as applyTarget,
|
|
@@ -32,9 +32,10 @@ import {
|
|
|
32
32
|
indexes,
|
|
33
33
|
quote,
|
|
34
34
|
isRecord,
|
|
35
|
+
effectivePredicate,
|
|
35
36
|
registerFailFix,
|
|
36
37
|
fail
|
|
37
|
-
} from "./
|
|
38
|
+
} from "./gbtcc2d7.js";
|
|
38
39
|
import {
|
|
39
40
|
safetyInstalled,
|
|
40
41
|
runSafety
|
|
@@ -45,7 +46,8 @@ import {
|
|
|
45
46
|
operatorValue
|
|
46
47
|
} from "./cn0n68ft.js";
|
|
47
48
|
import {
|
|
48
|
-
OkmError2
|
|
49
|
+
OkmError2,
|
|
50
|
+
throwNamed2
|
|
49
51
|
} from "./52szzakm.js";
|
|
50
52
|
|
|
51
53
|
// src/runtime/write.ts
|
|
@@ -98,6 +100,8 @@ var INSERT_OPTIONS = [
|
|
|
98
100
|
"validate"
|
|
99
101
|
];
|
|
100
102
|
var FILTER_OPTIONS = ["allow", "expect", "returning", "signal", "timeout", "validate"];
|
|
103
|
+
var UPDATE_KEYS = ["set", "where"];
|
|
104
|
+
var UPDATE_ROW_KEYS = ["id", "set", "where"];
|
|
101
105
|
var NO_ALLOW = new Set;
|
|
102
106
|
async function executeWrite(host, op, table, input, options, mods, scope, plan) {
|
|
103
107
|
const prepared = await prepareWrite(host, op, table, input, options, mods, scope);
|
|
@@ -179,8 +183,8 @@ async function planInsert(table, input, options, mods, generators, scope, tenanc
|
|
|
179
183
|
keyFields: undefined
|
|
180
184
|
};
|
|
181
185
|
}
|
|
182
|
-
const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./
|
|
183
|
-
const conflict = conflictMod?.readConflict(table, options.onConflict, allow);
|
|
186
|
+
const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./32zqc1dw.js");
|
|
187
|
+
const conflict = conflictMod?.readConflict(table, options.onConflict, allow, tenancy?.key);
|
|
184
188
|
const chunks = chunkRows(rows.map((row) => cellsFor(columns, row)));
|
|
185
189
|
const statements = [];
|
|
186
190
|
const keys = [];
|
|
@@ -216,6 +220,7 @@ function planUpdate(schema, table, input, options, mods) {
|
|
|
216
220
|
if (Array.isArray(input)) {
|
|
217
221
|
const rows = input.map((item) => {
|
|
218
222
|
const row = updateItem(table, item, allow, schema.tenancy);
|
|
223
|
+
requireFilter(table, row.where, mods, "update");
|
|
219
224
|
return { ...row, where: stack(row.where, mods.presets) };
|
|
220
225
|
});
|
|
221
226
|
return {
|
|
@@ -229,6 +234,7 @@ function planUpdate(schema, table, input, options, mods) {
|
|
|
229
234
|
}
|
|
230
235
|
if (!isRecord(input))
|
|
231
236
|
fail("OKM1121", "update expects { where, set } or a list of rows.");
|
|
237
|
+
rejectUpdateKeys(input, false);
|
|
232
238
|
const set = writeSet(table, input.set, allow, schema.tenancy);
|
|
233
239
|
requireFilter(table, input.where, mods, "update");
|
|
234
240
|
if (Object.keys(set).length === 0)
|
|
@@ -637,6 +643,7 @@ function writeSet(table, value, allow, tenancy) {
|
|
|
637
643
|
function updateItem(table, value, allow, tenancy) {
|
|
638
644
|
if (!isRecord(value))
|
|
639
645
|
fail("OKM1121", "update expects { where, set } or a list of rows.");
|
|
646
|
+
rejectUpdateKeys(value, true);
|
|
640
647
|
const set = writeSet(table, value.set, allow, tenancy);
|
|
641
648
|
if (value.where !== undefined)
|
|
642
649
|
return { where: value.where, set };
|
|
@@ -644,6 +651,14 @@ function updateItem(table, value, allow, tenancy) {
|
|
|
644
651
|
return { where: { id: value.id }, set };
|
|
645
652
|
fail("OKM1102", `update on ${table.model.name} needs id or where for each row.`);
|
|
646
653
|
}
|
|
654
|
+
function rejectUpdateKeys(input, row) {
|
|
655
|
+
const accepted = row ? UPDATE_ROW_KEYS : UPDATE_KEYS;
|
|
656
|
+
for (const key of Object.keys(input)) {
|
|
657
|
+
if (accepted.includes(key))
|
|
658
|
+
continue;
|
|
659
|
+
throwNamed2("OKM1120", key, [...accepted, ...FILTER_OPTIONS], `Option ${key} is not accepted by update. Accepted options: ${accepted.join(", ")}. timeout and signal go in the second argument.`);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
647
662
|
function requireFilter(table, where, mods, op) {
|
|
648
663
|
if (mods.all !== undefined) {
|
|
649
664
|
if (mods.all.trim().length === 0) {
|
|
@@ -651,11 +666,9 @@ function requireFilter(table, where, mods, op) {
|
|
|
651
666
|
}
|
|
652
667
|
return;
|
|
653
668
|
}
|
|
654
|
-
if (
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
return;
|
|
658
|
-
fail("OKM1102", `${op} on ${table.model.name} needs a where. Pass a filter, or .all(reason).`);
|
|
669
|
+
if (!effectivePredicate(where)) {
|
|
670
|
+
fail("OKM1102", `${op} on ${table.model.name} needs a where. Pass a filter, or .all(reason).`);
|
|
671
|
+
}
|
|
659
672
|
}
|
|
660
673
|
function chunkRows(rows) {
|
|
661
674
|
const chunks = [];
|