@niscorp/vex 0.2.0 → 0.2.2
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/CHANGELOG.md +40 -0
- package/DESIGN.md +12 -0
- package/DOCS.md +11 -2
- package/README.md +2 -1
- package/dist/adapters/express/index.cjs +139 -2
- package/dist/adapters/express/index.cjs.map +1 -1
- package/dist/adapters/express/index.js +1 -1
- package/dist/adapters/hono/index.cjs +139 -2
- package/dist/adapters/hono/index.cjs.map +1 -1
- package/dist/adapters/hono/index.js +1 -1
- package/dist/{chunk-5CBKESBJ.js → chunk-HCEH55PP.js} +159 -11
- package/dist/chunk-HCEH55PP.js.map +1 -0
- package/dist/index.cjs +157 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -17
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
- package/dist/chunk-5CBKESBJ.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { handleDiscovery, handleQuery, handleFingerprintPatch, handleFingerprintDelete } from '../../chunk-
|
|
1
|
+
import { handleDiscovery, handleQuery, handleFingerprintPatch, handleFingerprintDelete } from '../../chunk-HCEH55PP.js';
|
|
2
2
|
import '../../chunk-HF25Q53I.js';
|
|
3
3
|
import { Hono } from 'hono';
|
|
4
4
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FilterSchema, VexError, QuerySchema, isFieldPathShape } from './chunk-HF25Q53I.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { createHash } from 'crypto';
|
|
4
3
|
import { exceedsDepth, depthRefusal } from '@niscorp/strata';
|
|
5
4
|
|
|
6
5
|
var RESERVED_CONTEXT_KEYS = /* @__PURE__ */ new Set(["sortBy", "sortDir"]);
|
|
@@ -280,6 +279,155 @@ var requireScope = (compiled, scope) => {
|
|
|
280
279
|
throw new VexError("missing_scope", `This statement is scoped by ${missing.join(", ")}, which the host did not supply.`, { keys: missing });
|
|
281
280
|
}
|
|
282
281
|
};
|
|
282
|
+
|
|
283
|
+
// src/utils/sha256.ts
|
|
284
|
+
var ROUND_CONSTANTS = new Uint32Array([
|
|
285
|
+
1116352408,
|
|
286
|
+
1899447441,
|
|
287
|
+
3049323471,
|
|
288
|
+
3921009573,
|
|
289
|
+
961987163,
|
|
290
|
+
1508970993,
|
|
291
|
+
2453635748,
|
|
292
|
+
2870763221,
|
|
293
|
+
3624381080,
|
|
294
|
+
310598401,
|
|
295
|
+
607225278,
|
|
296
|
+
1426881987,
|
|
297
|
+
1925078388,
|
|
298
|
+
2162078206,
|
|
299
|
+
2614888103,
|
|
300
|
+
3248222580,
|
|
301
|
+
3835390401,
|
|
302
|
+
4022224774,
|
|
303
|
+
264347078,
|
|
304
|
+
604807628,
|
|
305
|
+
770255983,
|
|
306
|
+
1249150122,
|
|
307
|
+
1555081692,
|
|
308
|
+
1996064986,
|
|
309
|
+
2554220882,
|
|
310
|
+
2821834349,
|
|
311
|
+
2952996808,
|
|
312
|
+
3210313671,
|
|
313
|
+
3336571891,
|
|
314
|
+
3584528711,
|
|
315
|
+
113926993,
|
|
316
|
+
338241895,
|
|
317
|
+
666307205,
|
|
318
|
+
773529912,
|
|
319
|
+
1294757372,
|
|
320
|
+
1396182291,
|
|
321
|
+
1695183700,
|
|
322
|
+
1986661051,
|
|
323
|
+
2177026350,
|
|
324
|
+
2456956037,
|
|
325
|
+
2730485921,
|
|
326
|
+
2820302411,
|
|
327
|
+
3259730800,
|
|
328
|
+
3345764771,
|
|
329
|
+
3516065817,
|
|
330
|
+
3600352804,
|
|
331
|
+
4094571909,
|
|
332
|
+
275423344,
|
|
333
|
+
430227734,
|
|
334
|
+
506948616,
|
|
335
|
+
659060556,
|
|
336
|
+
883997877,
|
|
337
|
+
958139571,
|
|
338
|
+
1322822218,
|
|
339
|
+
1537002063,
|
|
340
|
+
1747873779,
|
|
341
|
+
1955562222,
|
|
342
|
+
2024104815,
|
|
343
|
+
2227730452,
|
|
344
|
+
2361852424,
|
|
345
|
+
2428436474,
|
|
346
|
+
2756734187,
|
|
347
|
+
3204031479,
|
|
348
|
+
3329325298
|
|
349
|
+
]);
|
|
350
|
+
var BLOCK_BYTES = 64;
|
|
351
|
+
var rotateRight = (word, bits) => word >>> bits | word << 32 - bits;
|
|
352
|
+
var wordHex = (word) => (word >>> 0).toString(16).padStart(8, "0");
|
|
353
|
+
var sha256Hex = (text) => {
|
|
354
|
+
const bytes = new TextEncoder().encode(text);
|
|
355
|
+
const padded = new Uint8Array(Math.ceil((bytes.length + 9) / BLOCK_BYTES) * BLOCK_BYTES);
|
|
356
|
+
padded.set(bytes);
|
|
357
|
+
padded[bytes.length] = 128;
|
|
358
|
+
const view = new DataView(padded.buffer);
|
|
359
|
+
const bitLength = bytes.length * 8;
|
|
360
|
+
view.setUint32(padded.length - 8, Math.floor(bitLength / 4294967296));
|
|
361
|
+
view.setUint32(padded.length - 4, bitLength >>> 0);
|
|
362
|
+
let h0 = 1779033703;
|
|
363
|
+
let h1 = 3144134277;
|
|
364
|
+
let h2 = 1013904242;
|
|
365
|
+
let h3 = 2773480762;
|
|
366
|
+
let h4 = 1359893119;
|
|
367
|
+
let h5 = 2600822924;
|
|
368
|
+
let h6 = 528734635;
|
|
369
|
+
let h7 = 1541459225;
|
|
370
|
+
const schedule = new Uint32Array(64);
|
|
371
|
+
for (let offset = 0; offset < padded.length; offset += BLOCK_BYTES) {
|
|
372
|
+
for (let i = 0; i < 16; i += 1) schedule[i] = view.getUint32(offset + i * 4);
|
|
373
|
+
for (let i = 16; i < 64; i += 1) {
|
|
374
|
+
const w15 = schedule[i - 15] ?? 0;
|
|
375
|
+
const w2 = schedule[i - 2] ?? 0;
|
|
376
|
+
const s0 = rotateRight(w15, 7) ^ rotateRight(w15, 18) ^ w15 >>> 3;
|
|
377
|
+
const s1 = rotateRight(w2, 17) ^ rotateRight(w2, 19) ^ w2 >>> 10;
|
|
378
|
+
schedule[i] = (schedule[i - 16] ?? 0) + s0 + (schedule[i - 7] ?? 0) + s1;
|
|
379
|
+
}
|
|
380
|
+
let a = h0;
|
|
381
|
+
let b = h1;
|
|
382
|
+
let c = h2;
|
|
383
|
+
let d = h3;
|
|
384
|
+
let e = h4;
|
|
385
|
+
let f = h5;
|
|
386
|
+
let g = h6;
|
|
387
|
+
let h = h7;
|
|
388
|
+
for (let i = 0; i < 64; i += 1) {
|
|
389
|
+
const sum1 = rotateRight(e, 6) ^ rotateRight(e, 11) ^ rotateRight(e, 25);
|
|
390
|
+
const choice = e & f ^ ~e & g;
|
|
391
|
+
const temp1 = h + sum1 + choice + (ROUND_CONSTANTS[i] ?? 0) + (schedule[i] ?? 0) | 0;
|
|
392
|
+
const sum0 = rotateRight(a, 2) ^ rotateRight(a, 13) ^ rotateRight(a, 22);
|
|
393
|
+
const majority = a & b ^ a & c ^ b & c;
|
|
394
|
+
const temp2 = sum0 + majority | 0;
|
|
395
|
+
h = g;
|
|
396
|
+
g = f;
|
|
397
|
+
f = e;
|
|
398
|
+
e = d + temp1 | 0;
|
|
399
|
+
d = c;
|
|
400
|
+
c = b;
|
|
401
|
+
b = a;
|
|
402
|
+
a = temp1 + temp2 | 0;
|
|
403
|
+
}
|
|
404
|
+
h0 = h0 + a | 0;
|
|
405
|
+
h1 = h1 + b | 0;
|
|
406
|
+
h2 = h2 + c | 0;
|
|
407
|
+
h3 = h3 + d | 0;
|
|
408
|
+
h4 = h4 + e | 0;
|
|
409
|
+
h5 = h5 + f | 0;
|
|
410
|
+
h6 = h6 + g | 0;
|
|
411
|
+
h7 = h7 + h | 0;
|
|
412
|
+
}
|
|
413
|
+
return wordHex(h0) + wordHex(h1) + wordHex(h2) + wordHex(h3) + wordHex(h4) + wordHex(h5) + wordHex(h6) + wordHex(h7);
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
// src/utils/canonical.ts
|
|
417
|
+
var canonical = (value) => {
|
|
418
|
+
if (Array.isArray(value)) return value.map(canonical);
|
|
419
|
+
if (value !== null && typeof value === "object" && !(value instanceof Date)) {
|
|
420
|
+
const sorted = {};
|
|
421
|
+
for (const [key, inner] of Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) sorted[key] = canonical(inner);
|
|
422
|
+
return sorted;
|
|
423
|
+
}
|
|
424
|
+
return value;
|
|
425
|
+
};
|
|
426
|
+
var canonicalText = (value) => JSON.stringify(canonical(value)) ?? "undefined";
|
|
427
|
+
var hashText = (text) => sha256Hex(text);
|
|
428
|
+
var canonicalHash = (value) => hashText(canonicalText(value));
|
|
429
|
+
|
|
430
|
+
// src/cache/hash.ts
|
|
283
431
|
var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
284
432
|
var normalizeShape = (shape) => {
|
|
285
433
|
if (shape === null) return "null";
|
|
@@ -301,25 +449,25 @@ var normalizeShape = (shape) => {
|
|
|
301
449
|
if (typeof shape === "boolean") return "boolean";
|
|
302
450
|
return "unknown";
|
|
303
451
|
};
|
|
304
|
-
var mintFingerprint = () => `fp_${
|
|
452
|
+
var mintFingerprint = () => `fp_${hashText(`${Date.now()}:${Math.random()}`).slice(0, 16)}`;
|
|
305
453
|
var computeRequestHash = (request) => {
|
|
306
454
|
const identity = {
|
|
307
455
|
intent: request.intent ?? null,
|
|
308
456
|
shape: normalizeShape(request.shape),
|
|
309
457
|
contextKeys: Object.keys(request.context ?? {}).sort()
|
|
310
458
|
};
|
|
311
|
-
return
|
|
459
|
+
return hashText(JSON.stringify(identity));
|
|
312
460
|
};
|
|
313
|
-
var
|
|
314
|
-
if (Array.isArray(value)) return value.map(
|
|
461
|
+
var canonical2 = (value) => {
|
|
462
|
+
if (Array.isArray(value)) return value.map(canonical2);
|
|
315
463
|
if (isRecord(value)) {
|
|
316
464
|
const out = {};
|
|
317
|
-
for (const key of Object.keys(value).sort()) out[key] =
|
|
465
|
+
for (const key of Object.keys(value).sort()) out[key] = canonical2(value[key]);
|
|
318
466
|
return out;
|
|
319
467
|
}
|
|
320
468
|
return value;
|
|
321
469
|
};
|
|
322
|
-
var computePolicyKey = (policy) => policy === void 0 ? "none" :
|
|
470
|
+
var computePolicyKey = (policy) => policy === void 0 ? "none" : hashText(JSON.stringify(canonical2(policy))).slice(0, 16);
|
|
323
471
|
var computeSchemaFingerprint = (schema) => {
|
|
324
472
|
const byName = (a, b) => a.name.localeCompare(b.name);
|
|
325
473
|
const stable = {
|
|
@@ -349,7 +497,7 @@ var computeSchemaFingerprint = (schema) => {
|
|
|
349
497
|
}))
|
|
350
498
|
}))
|
|
351
499
|
};
|
|
352
|
-
return
|
|
500
|
+
return hashText(JSON.stringify(stable));
|
|
353
501
|
};
|
|
354
502
|
|
|
355
503
|
// src/cache/util.ts
|
|
@@ -1523,6 +1671,6 @@ var handleFingerprintDelete = async (config, fingerprint) => {
|
|
|
1523
1671
|
return { status: 200, body: { fingerprint, deleted: true } };
|
|
1524
1672
|
};
|
|
1525
1673
|
|
|
1526
|
-
export { MutationDefinitionSchema, MutationSchema, QueryRequestSchema, VexScopeError, applyScope, buildContextContract, buildValidationContext, canReadTable, checkScope, collectMutationContext, collectQueryContext, compileAggregate, compileCompute, compileFieldOrValue, compileFilter, compileJoinPairs, computePolicyKey, computeRequestHash, computeSchemaFingerprint, executeMutation, executeQuery, executeWrites, findMissingContext, fireAndForget, handleDiscovery, handleFingerprintDelete, handleFingerprintPatch, handleQuery, isEntryFresh, isSetMatch, isTouchDue, lintMutation, mintFingerprint, mutationEffect, normalizeShape, optionalKeysOf, presenceOf, presenceSignature, pruneOptional, quoteIdent, refuseOptional, requireScope, requiredContextKeys, resolveParams, scopeResolved, sweepCache, tablesChangedBy };
|
|
1527
|
-
//# sourceMappingURL=chunk-
|
|
1528
|
-
//# sourceMappingURL=chunk-
|
|
1674
|
+
export { MutationDefinitionSchema, MutationSchema, QueryRequestSchema, VexScopeError, applyScope, buildContextContract, buildValidationContext, canReadTable, canonicalHash, canonicalText, checkScope, collectMutationContext, collectQueryContext, compileAggregate, compileCompute, compileFieldOrValue, compileFilter, compileJoinPairs, computePolicyKey, computeRequestHash, computeSchemaFingerprint, executeMutation, executeQuery, executeWrites, findMissingContext, fireAndForget, handleDiscovery, handleFingerprintDelete, handleFingerprintPatch, handleQuery, hashText, isEntryFresh, isSetMatch, isTouchDue, lintMutation, mintFingerprint, mutationEffect, normalizeShape, optionalKeysOf, presenceOf, presenceSignature, pruneOptional, quoteIdent, refuseOptional, requireScope, requiredContextKeys, resolveParams, scopeResolved, sweepCache, tablesChangedBy };
|
|
1675
|
+
//# sourceMappingURL=chunk-HCEH55PP.js.map
|
|
1676
|
+
//# sourceMappingURL=chunk-HCEH55PP.js.map
|