@gusto/baerly-storage 0.1.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 +97 -0
- package/dist/API.md +850 -0
- package/dist/app-config-Cb5dO2s9.d.ts +480 -0
- package/dist/app-config.d.ts +2 -0
- package/dist/app-config.js +8 -0
- package/dist/app-config.js.map +1 -0
- package/dist/auth.d.ts +237 -0
- package/dist/auth.js +1335 -0
- package/dist/auth.js.map +1 -0
- package/dist/baerly.js +761 -0
- package/dist/baerly.js.map +1 -0
- package/dist/bucket-uri-BrDEYvzy.js +4922 -0
- package/dist/bucket-uri-BrDEYvzy.js.map +1 -0
- package/dist/chunk-EAsCxrDo.js +14 -0
- package/dist/client-BLf3Ae5s.d.ts +233 -0
- package/dist/client-react.d.ts +131 -0
- package/dist/client-react.js +559 -0
- package/dist/client-react.js.map +1 -0
- package/dist/client.d.ts +4 -0
- package/dist/client.js +160 -0
- package/dist/client.js.map +1 -0
- package/dist/cloudflare-CINJPKCW.js +911 -0
- package/dist/cloudflare-CINJPKCW.js.map +1 -0
- package/dist/cloudflare.d.ts +211 -0
- package/dist/cloudflare.js +445 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/config-Bsg8wgwo.js +198 -0
- package/dist/config-Bsg8wgwo.js.map +1 -0
- package/dist/context-Oj7ffwD-.js +187 -0
- package/dist/context-Oj7ffwD-.js.map +1 -0
- package/dist/cost-B1WiZxlf.js +203 -0
- package/dist/cost-B1WiZxlf.js.map +1 -0
- package/dist/current-json-BkatBzF7.js +252 -0
- package/dist/current-json-BkatBzF7.js.map +1 -0
- package/dist/db-D62JguBc.d.ts +336 -0
- package/dist/deploy-BB-wqbhf.js +83 -0
- package/dist/deploy-BB-wqbhf.js.map +1 -0
- package/dist/dev-banner-CWHIk8tH.d.ts +26 -0
- package/dist/dev-vite.d.ts +146 -0
- package/dist/dev-vite.js +223 -0
- package/dist/dev-vite.js.map +1 -0
- package/dist/dev.d.ts +3 -0
- package/dist/dev.js +2 -0
- package/dist/doctor-B8h9GCN9.js +331 -0
- package/dist/doctor-B8h9GCN9.js.map +1 -0
- package/dist/dump-BHo_sIMZ.js +116 -0
- package/dist/dump-BHo_sIMZ.js.map +1 -0
- package/dist/errors-DOdL95kK.js +58 -0
- package/dist/errors-DOdL95kK.js.map +1 -0
- package/dist/export-Dz2PZKSR.js +423 -0
- package/dist/export-Dz2PZKSR.js.map +1 -0
- package/dist/fsck-DEz9lyCy.js +293 -0
- package/dist/fsck-DEz9lyCy.js.map +1 -0
- package/dist/http-CjUO1Bec.js +1756 -0
- package/dist/http-CjUO1Bec.js.map +1 -0
- package/dist/http.d.ts +1619 -0
- package/dist/http.js +2 -0
- package/dist/index-BGC-ENnj.d.ts +1065 -0
- package/dist/index-BYv0hb8M.d.ts +1457 -0
- package/dist/index-BquQkhJi.d.ts +112 -0
- package/dist/index-COsQ-Mlz.d.ts +146 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/indexes-BXn7a06a.js +297 -0
- package/dist/indexes-BXn7a06a.js.map +1 -0
- package/dist/indexes-DwOXkn1Y.d.ts +22 -0
- package/dist/inspect-x02aFWnh.js +149 -0
- package/dist/inspect-x02aFWnh.js.map +1 -0
- package/dist/log-walk-DIru96UT.js +260 -0
- package/dist/log-walk-DIru96UT.js.map +1 -0
- package/dist/maintenance-Bn6ul9aV.js +758 -0
- package/dist/maintenance-Bn6ul9aV.js.map +1 -0
- package/dist/maintenance.d.ts +323 -0
- package/dist/maintenance.js +2 -0
- package/dist/node.d.ts +422 -0
- package/dist/node.js +2 -0
- package/dist/normalize-XWY25_sG.js +133 -0
- package/dist/normalize-XWY25_sG.js.map +1 -0
- package/dist/observability-2IDYRuZK.js +2333 -0
- package/dist/observability-2IDYRuZK.js.map +1 -0
- package/dist/observability.d.ts +3 -0
- package/dist/observability.js +3 -0
- package/dist/plan-Cs17VqjU.js +224 -0
- package/dist/plan-Cs17VqjU.js.map +1 -0
- package/dist/query-DcSbFLJt.js +1880 -0
- package/dist/query-DcSbFLJt.js.map +1 -0
- package/dist/rebuild-index-C5gTXryd.js +119 -0
- package/dist/rebuild-index-C5gTXryd.js.map +1 -0
- package/dist/rebuild-index-DwXM0WfA.js +104 -0
- package/dist/rebuild-index-DwXM0WfA.js.map +1 -0
- package/dist/request-BEF_OvMh.js +72 -0
- package/dist/request-BEF_OvMh.js.map +1 -0
- package/dist/restore-CbKVMMpm.js +847 -0
- package/dist/restore-CbKVMMpm.js.map +1 -0
- package/dist/shared-secret-BJdSwpgw.js +71 -0
- package/dist/shared-secret-BJdSwpgw.js.map +1 -0
- package/dist/snapshot-D7C4_FSl.js +71 -0
- package/dist/snapshot-D7C4_FSl.js.map +1 -0
- package/dist/snapshot-z_N9hpTe.js +917 -0
- package/dist/snapshot-z_N9hpTe.js.map +1 -0
- package/dist/src-Chafbw8r.js +522 -0
- package/dist/src-Chafbw8r.js.map +1 -0
- package/dist/src-DyET_VPP.js +6199 -0
- package/dist/src-DyET_VPP.js.map +1 -0
- package/dist/src-n0Te1r98.js +352 -0
- package/dist/src-n0Te1r98.js.map +1 -0
- package/dist/subcommand-BWs6K7zb.js +110 -0
- package/dist/subcommand-BWs6K7zb.js.map +1 -0
- package/dist/usage-RVUQMLop.js +339 -0
- package/dist/usage-RVUQMLop.js.map +1 -0
- package/dist/validate-DhH1lO8I.js +377 -0
- package/dist/validate-DhH1lO8I.js.map +1 -0
- package/dist/wire-izfGZDvr.js +7 -0
- package/dist/wire-izfGZDvr.js.map +1 -0
- package/package.json +189 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { o as BaerlyError } from "./baerly.js";
|
|
2
|
+
//#region ../protocol/src/query/_internals.ts
|
|
3
|
+
/** @internal Same primitive type for comparison purposes. */
|
|
4
|
+
const sameComparableType = (a, b) => typeof a === "string" && typeof b === "string" || typeof a === "number" && typeof b === "number";
|
|
5
|
+
/**
|
|
6
|
+
* @internal Returns negative / zero / positive for a<b / a==b / a>b.
|
|
7
|
+
*/
|
|
8
|
+
const compareScalar = (a, b) => {
|
|
9
|
+
if (typeof a === "number" && typeof b === "number") return a - b;
|
|
10
|
+
if (typeof a === "string" && typeof b === "string") {
|
|
11
|
+
if (a < b) return -1;
|
|
12
|
+
if (a > b) return 1;
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
return 0;
|
|
16
|
+
};
|
|
17
|
+
/** @internal Render a predicate path for use in error messages. */
|
|
18
|
+
const formatPath = (path) => path.length === 0 ? "<root>" : path.map((p) => JSON.stringify(p)).join(".");
|
|
19
|
+
/**
|
|
20
|
+
* Recursive structural equality for `DocumentValue` values. Lifted to
|
|
21
|
+
* `export` so the filtered-index implication checker (in
|
|
22
|
+
* `@baerly/server`'s query planner) and other callers can reuse the
|
|
23
|
+
* same comparison rule the validator + merger already trust. Two
|
|
24
|
+
* values `a` and `b` are equal iff:
|
|
25
|
+
*
|
|
26
|
+
* - they are reference-equal (covers primitives and object identity);
|
|
27
|
+
* - or they are both non-`null` objects with the same key set, and
|
|
28
|
+
* every value pair is recursively equal.
|
|
29
|
+
*
|
|
30
|
+
* Arrays are out-of-band for `DocumentValue`; this function rejects
|
|
31
|
+
* them implicitly via the same key-set walk (an array reads as an
|
|
32
|
+
* object with numeric-string keys plus a `length` exposure that
|
|
33
|
+
* `Object.keys` happens to skip — defensive callers should still gate
|
|
34
|
+
* with `Array.isArray` first).
|
|
35
|
+
*/
|
|
36
|
+
const deepEqualDocumentValue = (a, b) => {
|
|
37
|
+
if (a === b) return true;
|
|
38
|
+
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
39
|
+
const aKeys = Object.keys(a);
|
|
40
|
+
const bKeys = Object.keys(b);
|
|
41
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
42
|
+
for (const key of aKeys) {
|
|
43
|
+
if (!(key in b)) return false;
|
|
44
|
+
const aSub = a[key];
|
|
45
|
+
const bSub = b[key];
|
|
46
|
+
if (aSub === void 0 || bSub === void 0) return false;
|
|
47
|
+
if (!deepEqualDocumentValue(aSub, bSub)) return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region ../protocol/src/query/matches.ts
|
|
53
|
+
/**
|
|
54
|
+
* Evaluate a validated wire-form predicate against a `JSONObject`
|
|
55
|
+
* document. Returns `true` iff every clause holds.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* matchesWire(
|
|
60
|
+
* { clauses: [{ op: "eq", field: "status", value: "open" }] },
|
|
61
|
+
* { status: "open", priority: "p1" },
|
|
62
|
+
* ); // true
|
|
63
|
+
*
|
|
64
|
+
* matchesWire(
|
|
65
|
+
* { clauses: [{ op: "in", field: "priority", value: ["p1", "p2"] }] },
|
|
66
|
+
* { priority: "p3" },
|
|
67
|
+
* ); // false
|
|
68
|
+
*
|
|
69
|
+
* matchesWire(
|
|
70
|
+
* {
|
|
71
|
+
* clauses: [
|
|
72
|
+
* { op: "gte", field: "count", value: 1 },
|
|
73
|
+
* { op: "lt", field: "count", value: 10 },
|
|
74
|
+
* ],
|
|
75
|
+
* },
|
|
76
|
+
* { count: 5 },
|
|
77
|
+
* ); // true
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
const matchesWire = (wire, doc) => {
|
|
81
|
+
for (const clause of wire.clauses) if (!matchesClause(clause, lookupPath(doc, clause.field))) return false;
|
|
82
|
+
return true;
|
|
83
|
+
};
|
|
84
|
+
const lookupPath = (doc, field) => {
|
|
85
|
+
if (!field.includes(".")) return doc[field];
|
|
86
|
+
const segments = field.split(".");
|
|
87
|
+
let cursor = doc;
|
|
88
|
+
for (const segment of segments) {
|
|
89
|
+
if (cursor === void 0 || cursor === null || typeof cursor !== "object" || Array.isArray(cursor)) return;
|
|
90
|
+
cursor = cursor[segment];
|
|
91
|
+
}
|
|
92
|
+
return cursor;
|
|
93
|
+
};
|
|
94
|
+
const matchesClause = (clause, actual) => {
|
|
95
|
+
switch (clause.op) {
|
|
96
|
+
case "eq": return matchesEq(clause.value, actual);
|
|
97
|
+
case "in": return matchesIn(clause.value, actual);
|
|
98
|
+
case "gt": return compareGT(actual, clause.value, false);
|
|
99
|
+
case "gte": return compareGT(actual, clause.value, true);
|
|
100
|
+
case "lt": return compareLT(actual, clause.value, false);
|
|
101
|
+
case "lte": return compareLT(actual, clause.value, true);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const matchesEq = (expected, actual) => {
|
|
105
|
+
if (typeof expected === "object") {
|
|
106
|
+
if (actual === void 0 || actual === null || typeof actual !== "object" || Array.isArray(actual)) return false;
|
|
107
|
+
for (const subKey of Object.keys(expected)) {
|
|
108
|
+
const subExpected = expected[subKey];
|
|
109
|
+
if (subExpected === void 0) continue;
|
|
110
|
+
const subActual = actual[subKey];
|
|
111
|
+
if (!matchesEq(subExpected, subActual)) return false;
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return expected === actual;
|
|
116
|
+
};
|
|
117
|
+
const matchesIn = (members, actual) => {
|
|
118
|
+
for (const m of members) if (typeof m === "object") {
|
|
119
|
+
if (matchesEq(m, actual)) return true;
|
|
120
|
+
} else if (m === actual) return true;
|
|
121
|
+
return false;
|
|
122
|
+
};
|
|
123
|
+
const compareGT = (actual, bound, inclusive) => {
|
|
124
|
+
if (typeof bound === "string") return typeof actual === "string" && (inclusive ? actual >= bound : actual > bound);
|
|
125
|
+
if (typeof bound === "number") return typeof actual === "number" && (inclusive ? actual >= bound : actual > bound);
|
|
126
|
+
return false;
|
|
127
|
+
};
|
|
128
|
+
const compareLT = (actual, bound, inclusive) => {
|
|
129
|
+
if (typeof bound === "string") return typeof actual === "string" && (inclusive ? actual <= bound : actual < bound);
|
|
130
|
+
if (typeof bound === "number") return typeof actual === "number" && (inclusive ? actual <= bound : actual < bound);
|
|
131
|
+
return false;
|
|
132
|
+
};
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region ../protocol/src/query/satisfiable.ts
|
|
135
|
+
/**
|
|
136
|
+
* Per-field satisfiability check for a {@link PredicateWire}. Groups
|
|
137
|
+
* clauses by field, then runs the same logic the pre-redesign
|
|
138
|
+
* `assertOpObjectSatisfiable` ran on a single op-object — but
|
|
139
|
+
* generalised across N clauses on the same field (the wire merger
|
|
140
|
+
* concatenates lists without coalescing).
|
|
141
|
+
*
|
|
142
|
+
* Triggers:
|
|
143
|
+
* - Two `eq` clauses on the same field with different values →
|
|
144
|
+
* `InvalidConfig` (the same conflict that pre-redesign
|
|
145
|
+
* `mergePredicates` threw on shared primitive keys).
|
|
146
|
+
* - Range bounds with `lo > hi` (or `lo == hi` with strict on
|
|
147
|
+
* either side) → `UnsatisfiablePredicate`.
|
|
148
|
+
* - `eq` value outside the residual range interval or absent from
|
|
149
|
+
* every `in` set on the same field → `UnsatisfiablePredicate`.
|
|
150
|
+
* - `in` sets that intersect to empty across multiple clauses →
|
|
151
|
+
* `UnsatisfiablePredicate`.
|
|
152
|
+
*
|
|
153
|
+
* Used by both `./validate.ts` (wire-arrival check) and
|
|
154
|
+
* `./merge.ts` (post-merge re-check, kept in lockstep).
|
|
155
|
+
*/
|
|
156
|
+
const groupByField = (wire) => {
|
|
157
|
+
const out = /* @__PURE__ */ new Map();
|
|
158
|
+
for (const clause of wire.clauses) {
|
|
159
|
+
let group = out.get(clause.field);
|
|
160
|
+
if (group === void 0) {
|
|
161
|
+
group = {
|
|
162
|
+
eqs: [],
|
|
163
|
+
ins: []
|
|
164
|
+
};
|
|
165
|
+
out.set(clause.field, group);
|
|
166
|
+
}
|
|
167
|
+
applyClause(group, clause.field, clause);
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
};
|
|
171
|
+
const applyClause = (group, field, clause) => {
|
|
172
|
+
switch (clause.op) {
|
|
173
|
+
case "eq":
|
|
174
|
+
group.eqs.push(clause.value);
|
|
175
|
+
return;
|
|
176
|
+
case "in":
|
|
177
|
+
group.ins.push(clause.value);
|
|
178
|
+
return;
|
|
179
|
+
case "gt":
|
|
180
|
+
tightenLower(group, field, clause.value, false);
|
|
181
|
+
return;
|
|
182
|
+
case "gte":
|
|
183
|
+
tightenLower(group, field, clause.value, true);
|
|
184
|
+
return;
|
|
185
|
+
case "lt":
|
|
186
|
+
tightenUpper(group, field, clause.value, false);
|
|
187
|
+
return;
|
|
188
|
+
case "lte":
|
|
189
|
+
tightenUpper(group, field, clause.value, true);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const tightenLower = (group, field, value, inclusive) => {
|
|
194
|
+
if (group.lo === void 0) {
|
|
195
|
+
group.lo = {
|
|
196
|
+
value,
|
|
197
|
+
inclusive
|
|
198
|
+
};
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (!sameComparableType(group.lo.value, value)) throw new BaerlyError("UnsatisfiablePredicate", `Predicate on field ${formatPath([field])} has type-incompatible lower bounds (${JSON.stringify(group.lo.value)} vs ${JSON.stringify(value)}).`);
|
|
202
|
+
const c = compareScalar(group.lo.value, value);
|
|
203
|
+
if (c < 0 || c === 0 && inclusive === false && group.lo.inclusive === true) group.lo = {
|
|
204
|
+
value,
|
|
205
|
+
inclusive
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
const tightenUpper = (group, field, value, inclusive) => {
|
|
209
|
+
if (group.hi === void 0) {
|
|
210
|
+
group.hi = {
|
|
211
|
+
value,
|
|
212
|
+
inclusive
|
|
213
|
+
};
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (!sameComparableType(group.hi.value, value)) throw new BaerlyError("UnsatisfiablePredicate", `Predicate on field ${formatPath([field])} has type-incompatible upper bounds (${JSON.stringify(group.hi.value)} vs ${JSON.stringify(value)}).`);
|
|
217
|
+
const c = compareScalar(group.hi.value, value);
|
|
218
|
+
if (c > 0 || c === 0 && inclusive === false && group.hi.inclusive === true) group.hi = {
|
|
219
|
+
value,
|
|
220
|
+
inclusive
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
const intersectInSets = (sets) => {
|
|
224
|
+
if (sets.length === 0) return [];
|
|
225
|
+
let acc = sets[0];
|
|
226
|
+
for (let i = 1; i < sets.length; i++) {
|
|
227
|
+
const next = [];
|
|
228
|
+
for (const a of acc) for (const b of sets[i]) if (deepEqualDocumentValue(a, b)) {
|
|
229
|
+
next.push(a);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
acc = next;
|
|
233
|
+
}
|
|
234
|
+
return acc;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Check that every per-field clause group on `wire` is jointly
|
|
238
|
+
* satisfiable. Throws `BaerlyError{code:"UnsatisfiablePredicate"}`
|
|
239
|
+
* (or `"InvalidConfig"` for conflicting `eq` clauses) on the
|
|
240
|
+
* first contradiction. Returns `void` on success.
|
|
241
|
+
*/
|
|
242
|
+
const assertWireSatisfiable = (wire) => {
|
|
243
|
+
const groups = groupByField(wire);
|
|
244
|
+
for (const [field, group] of groups) {
|
|
245
|
+
if (group.eqs.length > 1) {
|
|
246
|
+
for (let i = 1; i < group.eqs.length; i++) if (!deepEqualDocumentValue(group.eqs[0], group.eqs[i])) throw new BaerlyError("InvalidConfig", `Conflicting equality clauses on field ${formatPath([field])} (${JSON.stringify(group.eqs[0])} vs ${JSON.stringify(group.eqs[i])}). Predicate chains must agree on shared equality.`);
|
|
247
|
+
}
|
|
248
|
+
const eq = group.eqs[0];
|
|
249
|
+
if (group.lo !== void 0 && group.hi !== void 0 && sameComparableType(group.lo.value, group.hi.value)) {
|
|
250
|
+
const c = compareScalar(group.lo.value, group.hi.value);
|
|
251
|
+
if (c > 0 || c === 0 && (!group.lo.inclusive || !group.hi.inclusive)) throw new BaerlyError("UnsatisfiablePredicate", `Predicate on field ${formatPath([field])} has empty interval (lo=${JSON.stringify(group.lo.value)} ${group.lo.inclusive ? "gte" : "gt"}, hi=${JSON.stringify(group.hi.value)} ${group.hi.inclusive ? "lte" : "lt"}).`);
|
|
252
|
+
}
|
|
253
|
+
if (eq !== void 0) {
|
|
254
|
+
if (group.lo !== void 0) {
|
|
255
|
+
if (!sameComparableType(eq, group.lo.value)) throw new BaerlyError("UnsatisfiablePredicate", `Predicate on field ${formatPath([field])} eq=${JSON.stringify(eq)} (${typeof eq}) is type-incompatible with lower bound ${JSON.stringify(group.lo.value)} (${typeof group.lo.value}); range ops require matching primitive types.`);
|
|
256
|
+
const c = compareScalar(eq, group.lo.value);
|
|
257
|
+
if (c < 0 || c === 0 && !group.lo.inclusive) throw new BaerlyError("UnsatisfiablePredicate", `Predicate on field ${formatPath([field])} eq=${JSON.stringify(eq)} excluded by lower bound ${JSON.stringify(group.lo.value)} (${group.lo.inclusive ? "gte" : "gt"}).`);
|
|
258
|
+
}
|
|
259
|
+
if (group.hi !== void 0) {
|
|
260
|
+
if (!sameComparableType(eq, group.hi.value)) throw new BaerlyError("UnsatisfiablePredicate", `Predicate on field ${formatPath([field])} eq=${JSON.stringify(eq)} (${typeof eq}) is type-incompatible with upper bound ${JSON.stringify(group.hi.value)} (${typeof group.hi.value}); range ops require matching primitive types.`);
|
|
261
|
+
const c = compareScalar(eq, group.hi.value);
|
|
262
|
+
if (c > 0 || c === 0 && !group.hi.inclusive) throw new BaerlyError("UnsatisfiablePredicate", `Predicate on field ${formatPath([field])} eq=${JSON.stringify(eq)} excluded by upper bound ${JSON.stringify(group.hi.value)} (${group.hi.inclusive ? "lte" : "lt"}).`);
|
|
263
|
+
}
|
|
264
|
+
if (group.ins.length > 0) for (const set of group.ins) {
|
|
265
|
+
let found = false;
|
|
266
|
+
for (const m of set) if (deepEqualDocumentValue(eq, m)) {
|
|
267
|
+
found = true;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
if (!found) throw new BaerlyError("UnsatisfiablePredicate", `Predicate on field ${formatPath([field])} eq=${JSON.stringify(eq)} not present in in() set.`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (group.ins.length > 1) {
|
|
274
|
+
if (intersectInSets(group.ins).length === 0) throw new BaerlyError("UnsatisfiablePredicate", `Predicate on field ${formatPath([field])} has empty in() intersection across multiple clauses.`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
//#endregion
|
|
279
|
+
//#region ../protocol/src/query/validate.ts
|
|
280
|
+
/**
|
|
281
|
+
* Wire predicate validator. Walks a {@link PredicateWire} and throws
|
|
282
|
+
* on a structurally bad clause (`BaerlyError{code:"InvalidConfig"}`)
|
|
283
|
+
* or a per-field clause group that contradicts itself
|
|
284
|
+
* (`BaerlyError{code:"UnsatisfiablePredicate"}`).
|
|
285
|
+
*
|
|
286
|
+
* The object-form normaliser at `./normalize.ts` enforces shape on
|
|
287
|
+
* the way in (rejecting `$`-keys / non-scalars / null / undefined);
|
|
288
|
+
* the callback builder at `./builder.ts` enforces shape via the
|
|
289
|
+
* type system. This validator is the wire-arrival check: it runs
|
|
290
|
+
* over already-normalised clauses, defending against raw-`fetch`
|
|
291
|
+
* callers who bypass the typed seam and submit arbitrary JSON.
|
|
292
|
+
*
|
|
293
|
+
* Companion modules: `./matches.ts` (evaluator), `./merge.ts`
|
|
294
|
+
* (AND-merge). Shared helpers live in `./_internals.ts`.
|
|
295
|
+
*/
|
|
296
|
+
const OP_NAMES = [
|
|
297
|
+
"eq",
|
|
298
|
+
"gt",
|
|
299
|
+
"gte",
|
|
300
|
+
"lt",
|
|
301
|
+
"lte",
|
|
302
|
+
"in"
|
|
303
|
+
];
|
|
304
|
+
const RANGE_OPS = [
|
|
305
|
+
"gt",
|
|
306
|
+
"gte",
|
|
307
|
+
"lt",
|
|
308
|
+
"lte"
|
|
309
|
+
];
|
|
310
|
+
/**
|
|
311
|
+
* Validate a normalised predicate wire. Throws
|
|
312
|
+
* `BaerlyError{code:"InvalidConfig"}` on a structurally bad clause,
|
|
313
|
+
* or `BaerlyError{code:"UnsatisfiablePredicate"}` when a clause
|
|
314
|
+
* group on one field contradicts itself.
|
|
315
|
+
*
|
|
316
|
+
* Returns the wire unchanged on success — callers can thread the
|
|
317
|
+
* validated wire forward.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* validateWire({ clauses: [{ op: "eq", field: "status", value: "open" }] }); // ok
|
|
322
|
+
* validateWire({ clauses: [{ op: "in", field: "priority", value: [] }] }); // throws UnsatisfiablePredicate
|
|
323
|
+
* validateWire({ clauses: [{ op: "eq", field: "_id", value: "x" }] }); // throws InvalidConfig (top-level _id)
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
const validateWire = (wire) => {
|
|
327
|
+
if (wire === null || typeof wire !== "object" || !Array.isArray(wire.clauses)) throw new BaerlyError("InvalidConfig", `Predicate wire must be an object with a "clauses" array.`);
|
|
328
|
+
for (let i = 0; i < wire.clauses.length; i++) validateClause(wire.clauses[i], i);
|
|
329
|
+
assertWireSatisfiable(wire);
|
|
330
|
+
return wire;
|
|
331
|
+
};
|
|
332
|
+
const validateClause = (clause, index) => {
|
|
333
|
+
if (clause === null || typeof clause !== "object") throw new BaerlyError("InvalidConfig", `Predicate clause at index ${index} must be an object — got ${JSON.stringify(clause)}.`);
|
|
334
|
+
const { op, field, value } = clause;
|
|
335
|
+
if (typeof op !== "string" || !OP_NAMES.includes(op)) throw new BaerlyError("InvalidConfig", `Predicate clause at index ${index} has unsupported op ${JSON.stringify(op)} — supported: ${OP_NAMES.join(" / ")}.`);
|
|
336
|
+
if (typeof field !== "string" || field.length === 0) throw new BaerlyError("InvalidConfig", `Predicate clause at index ${index} has empty / non-string field.`);
|
|
337
|
+
if (field === "_id") throw new BaerlyError("InvalidConfig", "Predicates may not key on \"_id\"; use .get(id) / .update(id, patch) / .replace(id, doc) / .delete(id) instead.");
|
|
338
|
+
if (op === "in") {
|
|
339
|
+
if (!Array.isArray(value)) throw new BaerlyError("InvalidConfig", `Predicate clause at index ${index} (op="in", field=${JSON.stringify(field)}) must carry an array value.`);
|
|
340
|
+
if (value.length === 0) throw new BaerlyError("UnsatisfiablePredicate", `Predicate clause at index ${index} (op="in", field=${JSON.stringify(field)}) has empty value array — no document can match.`);
|
|
341
|
+
for (let i = 0; i < value.length; i++) validateMemberValue(value[i], field, index, i);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (Array.isArray(value)) throw new BaerlyError("InvalidConfig", `Predicate clause at index ${index} (op=${JSON.stringify(op)}, field=${JSON.stringify(field)}) must carry a primitive value, got an array — only op="in" accepts arrays.`);
|
|
345
|
+
if (RANGE_OPS.includes(op)) {
|
|
346
|
+
validateRangeBound(value, field, index);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
validateScalar(value, field, index);
|
|
350
|
+
};
|
|
351
|
+
const validateMemberValue = (value, field, clauseIndex, memberIndex) => {
|
|
352
|
+
if (value === null || value === void 0) throw new BaerlyError("InvalidConfig", `Predicate clause at index ${clauseIndex} (op="in", field=${JSON.stringify(field)}) member ${memberIndex} is ${value === null ? "null" : "undefined"} — members must be string / number / boolean / nested object.`);
|
|
353
|
+
if (Array.isArray(value)) throw new BaerlyError("InvalidConfig", `Predicate clause at index ${clauseIndex} (op="in", field=${JSON.stringify(field)}) member ${memberIndex} is an array — members must be string / number / boolean / nested object.`);
|
|
354
|
+
const t = typeof value;
|
|
355
|
+
if (t === "object") return;
|
|
356
|
+
if (t !== "string" && t !== "number" && t !== "boolean") throw new BaerlyError("InvalidConfig", `Predicate clause at index ${clauseIndex} (op="in", field=${JSON.stringify(field)}) member ${memberIndex} has unsupported type ${JSON.stringify(t)} — must be string / number / boolean / nested object.`);
|
|
357
|
+
if (t === "number" && !Number.isFinite(value)) throw new BaerlyError("InvalidConfig", `Predicate clause at index ${clauseIndex} (op="in", field=${JSON.stringify(field)}) member ${memberIndex} is ${String(value)} — finite numbers only (NaN / Infinity do not round-trip through JSON).`);
|
|
358
|
+
};
|
|
359
|
+
const validateScalar = (value, field, clauseIndex) => {
|
|
360
|
+
if (value === null || value === void 0) throw new BaerlyError("InvalidConfig", `Predicate clause at index ${clauseIndex} (field=${JSON.stringify(field)}) value is ${value === null ? "null" : "undefined"} — terminal values must be string / number / boolean / nested object.`);
|
|
361
|
+
const t = typeof value;
|
|
362
|
+
if (t === "object") return;
|
|
363
|
+
if (t !== "string" && t !== "number" && t !== "boolean") throw new BaerlyError("InvalidConfig", `Predicate clause at index ${clauseIndex} (field=${JSON.stringify(field)}) value has unsupported type ${JSON.stringify(t)} — must be string / number / boolean / nested object.`);
|
|
364
|
+
if (t === "number" && !Number.isFinite(value)) throw new BaerlyError("InvalidConfig", `Predicate clause at index ${clauseIndex} (field=${JSON.stringify(field)}) value is ${String(value)} — finite numbers only (NaN / Infinity do not round-trip through JSON).`);
|
|
365
|
+
};
|
|
366
|
+
const validateRangeBound = (value, field, clauseIndex) => {
|
|
367
|
+
if (value === null || value === void 0) throw new BaerlyError("InvalidConfig", `Predicate range bound at clause ${clauseIndex} (field=${JSON.stringify(field)}) is ${value === null ? "null" : "undefined"} — range bounds must be string or finite number.`);
|
|
368
|
+
const t = typeof value;
|
|
369
|
+
if (t === "boolean") throw new BaerlyError("InvalidConfig", `Predicate range bound at clause ${clauseIndex} (field=${JSON.stringify(field)}) is a boolean — range bounds must be string or finite number (booleans are not ordered).`);
|
|
370
|
+
if (t === "object") throw new BaerlyError("InvalidConfig", `Predicate range bound at clause ${clauseIndex} (field=${JSON.stringify(field)}) is a nested object — range bounds must be string or finite number.`);
|
|
371
|
+
if (t !== "string" && t !== "number") throw new BaerlyError("InvalidConfig", `Predicate range bound at clause ${clauseIndex} (field=${JSON.stringify(field)}) has unsupported type ${JSON.stringify(t)} — must be string or finite number.`);
|
|
372
|
+
if (t === "number" && !Number.isFinite(value)) throw new BaerlyError("InvalidConfig", `Predicate range bound at clause ${clauseIndex} (field=${JSON.stringify(field)}) is ${String(value)} — finite numbers only (NaN / Infinity do not round-trip through JSON).`);
|
|
373
|
+
};
|
|
374
|
+
//#endregion
|
|
375
|
+
export { matchesWire as n, validateWire as t };
|
|
376
|
+
|
|
377
|
+
//# sourceMappingURL=validate-DhH1lO8I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-DhH1lO8I.js","names":[],"sources":["../packages/protocol/src/query/_internals.ts","../packages/protocol/src/query/matches.ts","../packages/protocol/src/query/satisfiable.ts","../packages/protocol/src/query/validate.ts"],"sourcesContent":["/**\n * Shared helpers for the predicate algebras in `./validate.ts`,\n * `./matches.ts`, and `./merge.ts`. These exist as a single module\n * because more than one of those files uses them and duplicating\n * the implementations would drift over time.\n *\n * Only {@link deepEqualDocumentValue} is part of the public surface;\n * the comparator primitives (`compareScalar`, `sameComparableType`,\n * `formatPath`) are internal to the protocol package and imported\n * by `./validate.ts` / `./merge.ts` / `./normalize.ts` directly.\n */\n\nimport type { DocumentValue } from \"../json.ts\";\n\n/** @internal Same primitive type for comparison purposes. */\nexport const sameComparableType = (a: DocumentValue, b: DocumentValue): boolean =>\n (typeof a === \"string\" && typeof b === \"string\") ||\n (typeof a === \"number\" && typeof b === \"number\");\n\n/**\n * @internal Returns negative / zero / positive for a<b / a==b / a>b.\n */\nexport const compareScalar = (a: DocumentValue, b: DocumentValue): number => {\n if (typeof a === \"number\" && typeof b === \"number\") {\n return a - b;\n }\n if (typeof a === \"string\" && typeof b === \"string\") {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n }\n return 0;\n};\n\n/** @internal Render a predicate path for use in error messages. */\nexport const formatPath = (path: ReadonlyArray<string>): string =>\n path.length === 0 ? \"<root>\" : path.map((p) => JSON.stringify(p)).join(\".\");\n\n/**\n * Recursive structural equality for `DocumentValue` values. Lifted to\n * `export` so the filtered-index implication checker (in\n * `@baerly/server`'s query planner) and other callers can reuse the\n * same comparison rule the validator + merger already trust. Two\n * values `a` and `b` are equal iff:\n *\n * - they are reference-equal (covers primitives and object identity);\n * - or they are both non-`null` objects with the same key set, and\n * every value pair is recursively equal.\n *\n * Arrays are out-of-band for `DocumentValue`; this function rejects\n * them implicitly via the same key-set walk (an array reads as an\n * object with numeric-string keys plus a `length` exposure that\n * `Object.keys` happens to skip — defensive callers should still gate\n * with `Array.isArray` first).\n */\nexport const deepEqualDocumentValue = (a: DocumentValue, b: DocumentValue): boolean => {\n if (a === b) {\n return true;\n } // primitives + object identity\n if (typeof a !== \"object\" || typeof b !== \"object\") {\n return false;\n }\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n for (const key of aKeys) {\n if (!(key in b)) {\n return false;\n }\n const aSub = (a as Record<string, DocumentValue>)[key];\n const bSub = (b as Record<string, DocumentValue>)[key];\n if (aSub === undefined || bSub === undefined) {\n return false;\n }\n if (!deepEqualDocumentValue(aSub, bSub)) {\n return false;\n }\n }\n return true;\n};\n","/**\n * Wire predicate evaluator. Walks a validated {@link PredicateWire}\n * against a `JSONObject` document and returns `true` iff every\n * clause holds. Multiple clauses across all fields AND together.\n *\n * Pre-condition: `wire` must have been returned by\n * {@link validateWire} (see `./validate.ts`). Passing an\n * un-validated wire is a caller bug; behaviour is undefined.\n *\n * Companion modules: `./validate.ts` (construction-time check),\n * `./merge.ts` (AND-merge), `./wire.ts` (types).\n */\n\nimport type { DocumentValue, JSONObject, JSONValue } from \"../json.ts\";\n\nimport type { PredicateClause, PredicateWire } from \"./wire.ts\";\n\n/**\n * Evaluate a validated wire-form predicate against a `JSONObject`\n * document. Returns `true` iff every clause holds.\n *\n * @example\n * ```ts\n * matchesWire(\n * { clauses: [{ op: \"eq\", field: \"status\", value: \"open\" }] },\n * { status: \"open\", priority: \"p1\" },\n * ); // true\n *\n * matchesWire(\n * { clauses: [{ op: \"in\", field: \"priority\", value: [\"p1\", \"p2\"] }] },\n * { priority: \"p3\" },\n * ); // false\n *\n * matchesWire(\n * {\n * clauses: [\n * { op: \"gte\", field: \"count\", value: 1 },\n * { op: \"lt\", field: \"count\", value: 10 },\n * ],\n * },\n * { count: 5 },\n * ); // true\n * ```\n */\nexport const matchesWire = (wire: PredicateWire, doc: JSONObject): boolean => {\n for (const clause of wire.clauses) {\n const actual = lookupPath(doc, clause.field);\n if (!matchesClause(clause, actual)) {\n return false;\n }\n }\n return true;\n};\n\nconst lookupPath = (doc: JSONObject, field: string): JSONValue | undefined => {\n // Fast path: no dot → top-level lookup. Avoids allocating a split\n // array for the common case.\n if (!field.includes(\".\")) {\n return doc[field];\n }\n const segments = field.split(\".\");\n let cursor: JSONValue | undefined = doc;\n for (const segment of segments) {\n if (\n cursor === undefined ||\n cursor === null ||\n typeof cursor !== \"object\" ||\n Array.isArray(cursor)\n ) {\n // Traversal hit a primitive, null, missing key, or array\n // before consuming the path. Predicate cannot match.\n return undefined;\n }\n cursor = (cursor as JSONObject)[segment];\n }\n return cursor;\n};\n\nconst matchesClause = (clause: PredicateClause, actual: JSONValue | undefined): boolean => {\n switch (clause.op) {\n case \"eq\": {\n return matchesEq(clause.value as DocumentValue, actual);\n }\n case \"in\": {\n return matchesIn(clause.value as ReadonlyArray<DocumentValue>, actual);\n }\n case \"gt\": {\n return compareGT(actual, clause.value as DocumentValue, false);\n }\n case \"gte\": {\n return compareGT(actual, clause.value as DocumentValue, true);\n }\n case \"lt\": {\n return compareLT(actual, clause.value as DocumentValue, false);\n }\n case \"lte\": {\n return compareLT(actual, clause.value as DocumentValue, true);\n }\n }\n};\n\nconst matchesEq = (expected: DocumentValue, actual: JSONValue | undefined): boolean => {\n if (typeof expected === \"object\") {\n // Nested object equality is a sub-predicate match — open-world:\n // doc may carry extra keys. The object-form normaliser flattens\n // nested sub-predicates to dotted-path clauses on the way in, so\n // the only callers reaching this branch are callback-form\n // `q.eq(\"nested\", { ... })`.\n if (\n actual === undefined ||\n actual === null ||\n typeof actual !== \"object\" ||\n Array.isArray(actual)\n ) {\n return false;\n }\n for (const subKey of Object.keys(expected)) {\n const subExpected = (expected as Record<string, DocumentValue>)[subKey];\n if (subExpected === undefined) {\n continue;\n }\n const subActual = (actual as JSONObject)[subKey];\n if (!matchesEq(subExpected, subActual)) {\n return false;\n }\n }\n return true;\n }\n return expected === actual;\n};\n\nconst matchesIn = (\n members: ReadonlyArray<DocumentValue>,\n actual: JSONValue | undefined,\n): boolean => {\n for (const m of members) {\n if (typeof m === \"object\") {\n if (matchesEq(m, actual)) {\n return true;\n }\n } else if (m === actual) {\n return true;\n }\n }\n return false;\n};\n\nconst compareGT = (\n actual: JSONValue | undefined,\n bound: DocumentValue,\n inclusive: boolean,\n): boolean => {\n if (typeof bound === \"string\") {\n return typeof actual === \"string\" && (inclusive ? actual >= bound : actual > bound);\n }\n if (typeof bound === \"number\") {\n return typeof actual === \"number\" && (inclusive ? actual >= bound : actual > bound);\n }\n // Validator forbids boolean / null / object range bounds; defensive miss.\n return false;\n};\n\nconst compareLT = (\n actual: JSONValue | undefined,\n bound: DocumentValue,\n inclusive: boolean,\n): boolean => {\n if (typeof bound === \"string\") {\n return typeof actual === \"string\" && (inclusive ? actual <= bound : actual < bound);\n }\n if (typeof bound === \"number\") {\n return typeof actual === \"number\" && (inclusive ? actual <= bound : actual < bound);\n }\n return false;\n};\n","/**\n * Per-field satisfiability check for a {@link PredicateWire}. Groups\n * clauses by field, then runs the same logic the pre-redesign\n * `assertOpObjectSatisfiable` ran on a single op-object — but\n * generalised across N clauses on the same field (the wire merger\n * concatenates lists without coalescing).\n *\n * Triggers:\n * - Two `eq` clauses on the same field with different values →\n * `InvalidConfig` (the same conflict that pre-redesign\n * `mergePredicates` threw on shared primitive keys).\n * - Range bounds with `lo > hi` (or `lo == hi` with strict on\n * either side) → `UnsatisfiablePredicate`.\n * - `eq` value outside the residual range interval or absent from\n * every `in` set on the same field → `UnsatisfiablePredicate`.\n * - `in` sets that intersect to empty across multiple clauses →\n * `UnsatisfiablePredicate`.\n *\n * Used by both `./validate.ts` (wire-arrival check) and\n * `./merge.ts` (post-merge re-check, kept in lockstep).\n */\n\nimport { BaerlyError } from \"../errors.ts\";\nimport type { DocumentValue } from \"../json.ts\";\n\nimport {\n compareScalar,\n deepEqualDocumentValue,\n formatPath,\n sameComparableType,\n} from \"./_internals.ts\";\nimport type { PredicateClause, PredicateWire } from \"./wire.ts\";\n\ninterface FieldGroup {\n readonly eqs: DocumentValue[];\n readonly ins: ReadonlyArray<DocumentValue>[];\n lo?: { value: DocumentValue; inclusive: boolean };\n hi?: { value: DocumentValue; inclusive: boolean };\n}\n\nconst groupByField = (wire: PredicateWire): Map<string, FieldGroup> => {\n const out = new Map<string, FieldGroup>();\n for (const clause of wire.clauses) {\n let group = out.get(clause.field);\n if (group === undefined) {\n group = { eqs: [], ins: [] };\n out.set(clause.field, group);\n }\n applyClause(group, clause.field, clause);\n }\n return out;\n};\n\nconst applyClause = (group: FieldGroup, field: string, clause: PredicateClause): void => {\n switch (clause.op) {\n case \"eq\": {\n group.eqs.push(clause.value as DocumentValue);\n return;\n }\n case \"in\": {\n group.ins.push(clause.value as ReadonlyArray<DocumentValue>);\n return;\n }\n case \"gt\": {\n tightenLower(group, field, clause.value as DocumentValue, false);\n return;\n }\n case \"gte\": {\n tightenLower(group, field, clause.value as DocumentValue, true);\n return;\n }\n case \"lt\": {\n tightenUpper(group, field, clause.value as DocumentValue, false);\n return;\n }\n case \"lte\": {\n tightenUpper(group, field, clause.value as DocumentValue, true);\n return;\n }\n }\n};\n\nconst tightenLower = (\n group: FieldGroup,\n field: string,\n value: DocumentValue,\n inclusive: boolean,\n): void => {\n if (group.lo === undefined) {\n group.lo = { value, inclusive };\n return;\n }\n if (!sameComparableType(group.lo.value, value)) {\n // Type-incompatible bounds on the same field — the user wrote\n // (say) `q.gt(\"x\", 1).gt(\"x\", \"a\")`. Range matching is type-\n // strict at evaluation time so this is always-miss; surface\n // eagerly as `UnsatisfiablePredicate`.\n throw new BaerlyError(\n \"UnsatisfiablePredicate\",\n `Predicate on field ${formatPath([field])} has type-incompatible lower bounds (${JSON.stringify(group.lo.value)} vs ${JSON.stringify(value)}).`,\n );\n }\n const c = compareScalar(group.lo.value, value);\n if (c < 0 || (c === 0 && inclusive === false && group.lo.inclusive === true)) {\n group.lo = { value, inclusive };\n }\n};\n\nconst tightenUpper = (\n group: FieldGroup,\n field: string,\n value: DocumentValue,\n inclusive: boolean,\n): void => {\n if (group.hi === undefined) {\n group.hi = { value, inclusive };\n return;\n }\n if (!sameComparableType(group.hi.value, value)) {\n throw new BaerlyError(\n \"UnsatisfiablePredicate\",\n `Predicate on field ${formatPath([field])} has type-incompatible upper bounds (${JSON.stringify(group.hi.value)} vs ${JSON.stringify(value)}).`,\n );\n }\n const c = compareScalar(group.hi.value, value);\n if (c > 0 || (c === 0 && inclusive === false && group.hi.inclusive === true)) {\n group.hi = { value, inclusive };\n }\n};\n\nconst intersectInSets = (\n sets: ReadonlyArray<ReadonlyArray<DocumentValue>>,\n): ReadonlyArray<DocumentValue> => {\n if (sets.length === 0) {\n return [];\n }\n let acc: ReadonlyArray<DocumentValue> = sets[0]!;\n for (let i = 1; i < sets.length; i++) {\n const next: DocumentValue[] = [];\n for (const a of acc) {\n for (const b of sets[i]!) {\n if (deepEqualDocumentValue(a, b)) {\n next.push(a);\n break;\n }\n }\n }\n acc = next;\n }\n return acc;\n};\n\n/**\n * Check that every per-field clause group on `wire` is jointly\n * satisfiable. Throws `BaerlyError{code:\"UnsatisfiablePredicate\"}`\n * (or `\"InvalidConfig\"` for conflicting `eq` clauses) on the\n * first contradiction. Returns `void` on success.\n */\nexport const assertWireSatisfiable = (wire: PredicateWire): void => {\n const groups = groupByField(wire);\n for (const [field, group] of groups) {\n // Multiple `eq` clauses on the same field must agree.\n if (group.eqs.length > 1) {\n for (let i = 1; i < group.eqs.length; i++) {\n if (!deepEqualDocumentValue(group.eqs[0]!, group.eqs[i]!)) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Conflicting equality clauses on field ${formatPath([field])} (${JSON.stringify(group.eqs[0]!)} vs ${JSON.stringify(group.eqs[i]!)}). Predicate chains must agree on shared equality.`,\n );\n }\n }\n }\n const eq = group.eqs[0];\n // Range interval must be non-empty.\n if (\n group.lo !== undefined &&\n group.hi !== undefined &&\n sameComparableType(group.lo.value, group.hi.value)\n ) {\n const c = compareScalar(group.lo.value, group.hi.value);\n if (c > 0 || (c === 0 && (!group.lo.inclusive || !group.hi.inclusive))) {\n throw new BaerlyError(\n \"UnsatisfiablePredicate\",\n `Predicate on field ${formatPath([field])} has empty interval (lo=${JSON.stringify(group.lo.value)} ${group.lo.inclusive ? \"gte\" : \"gt\"}, hi=${JSON.stringify(group.hi.value)} ${group.hi.inclusive ? \"lte\" : \"lt\"}).`,\n );\n }\n }\n // `eq` outside the residual interval / membership set.\n if (eq !== undefined) {\n if (group.lo !== undefined) {\n if (!sameComparableType(eq, group.lo.value)) {\n throw new BaerlyError(\n \"UnsatisfiablePredicate\",\n `Predicate on field ${formatPath([field])} eq=${JSON.stringify(eq)} (${typeof eq}) is type-incompatible with lower bound ${JSON.stringify(group.lo.value)} (${typeof group.lo.value}); range ops require matching primitive types.`,\n );\n }\n const c = compareScalar(eq, group.lo.value);\n if (c < 0 || (c === 0 && !group.lo.inclusive)) {\n throw new BaerlyError(\n \"UnsatisfiablePredicate\",\n `Predicate on field ${formatPath([field])} eq=${JSON.stringify(eq)} excluded by lower bound ${JSON.stringify(group.lo.value)} (${group.lo.inclusive ? \"gte\" : \"gt\"}).`,\n );\n }\n }\n if (group.hi !== undefined) {\n if (!sameComparableType(eq, group.hi.value)) {\n throw new BaerlyError(\n \"UnsatisfiablePredicate\",\n `Predicate on field ${formatPath([field])} eq=${JSON.stringify(eq)} (${typeof eq}) is type-incompatible with upper bound ${JSON.stringify(group.hi.value)} (${typeof group.hi.value}); range ops require matching primitive types.`,\n );\n }\n const c = compareScalar(eq, group.hi.value);\n if (c > 0 || (c === 0 && !group.hi.inclusive)) {\n throw new BaerlyError(\n \"UnsatisfiablePredicate\",\n `Predicate on field ${formatPath([field])} eq=${JSON.stringify(eq)} excluded by upper bound ${JSON.stringify(group.hi.value)} (${group.hi.inclusive ? \"lte\" : \"lt\"}).`,\n );\n }\n }\n if (group.ins.length > 0) {\n for (const set of group.ins) {\n let found = false;\n for (const m of set) {\n if (deepEqualDocumentValue(eq, m)) {\n found = true;\n break;\n }\n }\n if (!found) {\n throw new BaerlyError(\n \"UnsatisfiablePredicate\",\n `Predicate on field ${formatPath([field])} eq=${JSON.stringify(eq)} not present in in() set.`,\n );\n }\n }\n }\n }\n // Multiple `in` sets must intersect non-empty.\n if (group.ins.length > 1) {\n const isect = intersectInSets(group.ins);\n if (isect.length === 0) {\n throw new BaerlyError(\n \"UnsatisfiablePredicate\",\n `Predicate on field ${formatPath([field])} has empty in() intersection across multiple clauses.`,\n );\n }\n }\n }\n};\n","/**\n * Wire predicate validator. Walks a {@link PredicateWire} and throws\n * on a structurally bad clause (`BaerlyError{code:\"InvalidConfig\"}`)\n * or a per-field clause group that contradicts itself\n * (`BaerlyError{code:\"UnsatisfiablePredicate\"}`).\n *\n * The object-form normaliser at `./normalize.ts` enforces shape on\n * the way in (rejecting `$`-keys / non-scalars / null / undefined);\n * the callback builder at `./builder.ts` enforces shape via the\n * type system. This validator is the wire-arrival check: it runs\n * over already-normalised clauses, defending against raw-`fetch`\n * callers who bypass the typed seam and submit arbitrary JSON.\n *\n * Companion modules: `./matches.ts` (evaluator), `./merge.ts`\n * (AND-merge). Shared helpers live in `./_internals.ts`.\n */\n\nimport { BaerlyError } from \"../errors.ts\";\n\nimport { assertWireSatisfiable } from \"./satisfiable.ts\";\nimport type { PredicateClause, PredicateOpName, PredicateWire } from \"./wire.ts\";\n\nconst OP_NAMES: ReadonlyArray<PredicateOpName> = [\"eq\", \"gt\", \"gte\", \"lt\", \"lte\", \"in\"];\nconst RANGE_OPS: ReadonlyArray<PredicateOpName> = [\"gt\", \"gte\", \"lt\", \"lte\"];\n\n/**\n * Validate a normalised predicate wire. Throws\n * `BaerlyError{code:\"InvalidConfig\"}` on a structurally bad clause,\n * or `BaerlyError{code:\"UnsatisfiablePredicate\"}` when a clause\n * group on one field contradicts itself.\n *\n * Returns the wire unchanged on success — callers can thread the\n * validated wire forward.\n *\n * @example\n * ```ts\n * validateWire({ clauses: [{ op: \"eq\", field: \"status\", value: \"open\" }] }); // ok\n * validateWire({ clauses: [{ op: \"in\", field: \"priority\", value: [] }] }); // throws UnsatisfiablePredicate\n * validateWire({ clauses: [{ op: \"eq\", field: \"_id\", value: \"x\" }] }); // throws InvalidConfig (top-level _id)\n * ```\n */\nexport const validateWire = (wire: PredicateWire): PredicateWire => {\n if (\n wire === null ||\n typeof wire !== \"object\" ||\n !Array.isArray((wire as { clauses?: unknown }).clauses)\n ) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate wire must be an object with a \"clauses\" array.`,\n );\n }\n for (let i = 0; i < wire.clauses.length; i++) {\n validateClause(wire.clauses[i]!, i);\n }\n assertWireSatisfiable(wire);\n return wire;\n};\n\nconst validateClause = (clause: PredicateClause, index: number): void => {\n if (clause === null || typeof clause !== \"object\") {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${index} must be an object — got ${JSON.stringify(clause)}.`,\n );\n }\n const { op, field, value } = clause;\n if (typeof op !== \"string\" || !(OP_NAMES as ReadonlyArray<string>).includes(op)) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${index} has unsupported op ${JSON.stringify(op)} — supported: ${OP_NAMES.join(\" / \")}.`,\n );\n }\n if (typeof field !== \"string\" || field.length === 0) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${index} has empty / non-string field.`,\n );\n }\n if (field === \"_id\") {\n throw new BaerlyError(\n \"InvalidConfig\",\n 'Predicates may not key on \"_id\"; use .get(id) / .update(id, patch) / .replace(id, doc) / .delete(id) instead.',\n );\n }\n if (op === \"in\") {\n if (!Array.isArray(value)) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${index} (op=\"in\", field=${JSON.stringify(field)}) must carry an array value.`,\n );\n }\n if (value.length === 0) {\n throw new BaerlyError(\n \"UnsatisfiablePredicate\",\n `Predicate clause at index ${index} (op=\"in\", field=${JSON.stringify(field)}) has empty value array — no document can match.`,\n );\n }\n for (let i = 0; i < value.length; i++) {\n validateMemberValue(value[i], field, index, i);\n }\n return;\n }\n if (Array.isArray(value)) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${index} (op=${JSON.stringify(op)}, field=${JSON.stringify(field)}) must carry a primitive value, got an array — only op=\"in\" accepts arrays.`,\n );\n }\n if ((RANGE_OPS as ReadonlyArray<string>).includes(op)) {\n validateRangeBound(value, field, index);\n return;\n }\n validateScalar(value, field, index);\n};\n\nconst validateMemberValue = (\n value: unknown,\n field: string,\n clauseIndex: number,\n memberIndex: number,\n): void => {\n if (value === null || value === undefined) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${clauseIndex} (op=\"in\", field=${JSON.stringify(field)}) member ${memberIndex} is ${value === null ? \"null\" : \"undefined\"} — members must be string / number / boolean / nested object.`,\n );\n }\n if (Array.isArray(value)) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${clauseIndex} (op=\"in\", field=${JSON.stringify(field)}) member ${memberIndex} is an array — members must be string / number / boolean / nested object.`,\n );\n }\n const t = typeof value;\n if (t === \"object\") {\n return;\n }\n if (t !== \"string\" && t !== \"number\" && t !== \"boolean\") {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${clauseIndex} (op=\"in\", field=${JSON.stringify(field)}) member ${memberIndex} has unsupported type ${JSON.stringify(t)} — must be string / number / boolean / nested object.`,\n );\n }\n if (t === \"number\" && !Number.isFinite(value as number)) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${clauseIndex} (op=\"in\", field=${JSON.stringify(field)}) member ${memberIndex} is ${String(value)} — finite numbers only (NaN / Infinity do not round-trip through JSON).`,\n );\n }\n};\n\nconst validateScalar = (value: unknown, field: string, clauseIndex: number): void => {\n if (value === null || value === undefined) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${clauseIndex} (field=${JSON.stringify(field)}) value is ${value === null ? \"null\" : \"undefined\"} — terminal values must be string / number / boolean / nested object.`,\n );\n }\n const t = typeof value;\n if (t === \"object\") {\n // Equality clauses against nested objects survive only via callback\n // form (the normaliser flattens object-form sub-predicates to\n // dotted-path eq clauses). Keep the structural recursion light —\n // values are sealed from the typed seam.\n return;\n }\n if (t !== \"string\" && t !== \"number\" && t !== \"boolean\") {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${clauseIndex} (field=${JSON.stringify(field)}) value has unsupported type ${JSON.stringify(t)} — must be string / number / boolean / nested object.`,\n );\n }\n if (t === \"number\" && !Number.isFinite(value as number)) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate clause at index ${clauseIndex} (field=${JSON.stringify(field)}) value is ${String(value)} — finite numbers only (NaN / Infinity do not round-trip through JSON).`,\n );\n }\n};\n\nconst validateRangeBound = (value: unknown, field: string, clauseIndex: number): void => {\n if (value === null || value === undefined) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate range bound at clause ${clauseIndex} (field=${JSON.stringify(field)}) is ${value === null ? \"null\" : \"undefined\"} — range bounds must be string or finite number.`,\n );\n }\n const t = typeof value;\n if (t === \"boolean\") {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate range bound at clause ${clauseIndex} (field=${JSON.stringify(field)}) is a boolean — range bounds must be string or finite number (booleans are not ordered).`,\n );\n }\n if (t === \"object\") {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate range bound at clause ${clauseIndex} (field=${JSON.stringify(field)}) is a nested object — range bounds must be string or finite number.`,\n );\n }\n if (t !== \"string\" && t !== \"number\") {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate range bound at clause ${clauseIndex} (field=${JSON.stringify(field)}) has unsupported type ${JSON.stringify(t)} — must be string or finite number.`,\n );\n }\n if (t === \"number\" && !Number.isFinite(value as number)) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `Predicate range bound at clause ${clauseIndex} (field=${JSON.stringify(field)}) is ${String(value)} — finite numbers only (NaN / Infinity do not round-trip through JSON).`,\n );\n }\n};\n"],"mappings":";;;AAeA,MAAa,sBAAsB,GAAkB,MAClD,OAAO,MAAM,YAAY,OAAO,MAAM,YACtC,OAAO,MAAM,YAAY,OAAO,MAAM;;;;AAKzC,MAAa,iBAAiB,GAAkB,MAA6B;CAC3E,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UACxC,OAAO,IAAI;CAEb,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAClD,IAAI,IAAI,GACN,OAAO;EAET,IAAI,IAAI,GACN,OAAO;EAET,OAAO;CACT;CACA,OAAO;AACT;;AAGA,MAAa,cAAc,SACzB,KAAK,WAAW,IAAI,WAAW,KAAK,KAAK,MAAM,KAAK,UAAU,CAAC,CAAC,EAAE,KAAK,GAAG;;;;;;;;;;;;;;;;;;AAmB5E,MAAa,0BAA0B,GAAkB,MAA8B;CACrF,IAAI,MAAM,GACR,OAAO;CAET,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UACxC,OAAO;CAET,MAAM,QAAQ,OAAO,KAAK,CAAC;CAC3B,MAAM,QAAQ,OAAO,KAAK,CAAC;CAC3B,IAAI,MAAM,WAAW,MAAM,QACzB,OAAO;CAET,KAAK,MAAM,OAAO,OAAO;EACvB,IAAI,EAAE,OAAO,IACX,OAAO;EAET,MAAM,OAAQ,EAAoC;EAClD,MAAM,OAAQ,EAAoC;EAClD,IAAI,SAAS,KAAA,KAAa,SAAS,KAAA,GACjC,OAAO;EAET,IAAI,CAAC,uBAAuB,MAAM,IAAI,GACpC,OAAO;CAEX;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACzCA,MAAa,eAAe,MAAqB,QAA6B;CAC5E,KAAK,MAAM,UAAU,KAAK,SAExB,IAAI,CAAC,cAAc,QADJ,WAAW,KAAK,OAAO,KACN,CAAC,GAC/B,OAAO;CAGX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KAAK,EAAE,wEACtG;AAEJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region packages/protocol/src/query/wire.ts
|
|
2
|
+
/** @internal Empty match-all wire — re-used to avoid re-allocating. */
|
|
3
|
+
const EMPTY_PREDICATE_WIRE = { clauses: [] };
|
|
4
|
+
//#endregion
|
|
5
|
+
export { EMPTY_PREDICATE_WIRE as t };
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=wire-izfGZDvr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire-izfGZDvr.js","names":[],"sources":["../packages/protocol/src/query/wire.ts"],"sourcesContent":["/**\n * Wire-format predicate types. A predicate normalises to a flat list\n * of {@link PredicateClause} records; the server, client, matcher,\n * merger, and validator all consume the wire form. Object-literal\n * (`Predicate<T>`) and callback (`PredicateBuilder<T>`) forms compile\n * to this shape via `./normalize.ts` / `./builder.ts`.\n */\n\nimport type { DocumentValue } from \"../json.ts\";\n\n/**\n * Locked operator vocabulary. Methods on {@link PredicateBuilder}\n * map 1:1 to these names; the validator rejects any other.\n *\n * `eq` — strict equality.\n * `gt` / `gte` / `lt` / `lte` — scalar range. Bounds must be `string`\n * or finite `number`. Type-mismatched actuals are always-miss.\n * `in` — set membership. Empty array → `UnsatisfiablePredicate`.\n */\nexport type PredicateOpName = \"eq\" | \"gt\" | \"gte\" | \"lt\" | \"lte\" | \"in\";\n\n/**\n * One clause in a normalised predicate. `field` is a top-level key\n * or a dotted path. `value` is an array iff `op === \"in\"`.\n *\n * `op: \"eq\"` on a primitive `value` is plain equality. The\n * normaliser flattens nested literal sub-predicates\n * (`{ assignee: { team: \"x\" } }`) to dotted-path `eq` clauses\n * (`{op:\"eq\", field:\"assignee.team\", value:\"x\"}`), so an `eq`\n * value at the wire level is never a nested non-primitive object\n * — only callback-form `q.eq(\"nested\", { ... })` could produce\n * one, and that requires the type system to allow it at the call\n * site.\n */\nexport interface PredicateClause {\n readonly op: PredicateOpName;\n readonly field: string;\n readonly value: DocumentValue | ReadonlyArray<DocumentValue>;\n}\n\n/**\n * Normalised predicate envelope. The wire form is a flat list of\n * clauses; multiple clauses across all fields AND together. The\n * empty wire `{ clauses: [] }` matches every document.\n *\n * Wire mirror on the HTTP surface: `?where=` carries the JSON\n * encoding of this object. See `packages/server/API.md` for the\n * literal example.\n */\nexport interface PredicateWire {\n readonly clauses: ReadonlyArray<PredicateClause>;\n}\n\n/** @internal Empty match-all wire — re-used to avoid re-allocating. */\nexport const EMPTY_PREDICATE_WIRE: PredicateWire = { clauses: [] };\n"],"mappings":";;AAsDA,MAAa,uBAAsC,EAAE,SAAS,CAAC,EAAE"}
|