@niscorp/vex 0.3.1 → 0.4.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/CHANGELOG.md +12 -0
- package/DESIGN.md +4 -3
- package/DOCS.md +26 -4
- package/dist/adapters/express/index.cjs +1 -1
- package/dist/adapters/express/index.cjs.map +1 -1
- package/dist/adapters/express/index.d.cts +3 -2
- package/dist/adapters/express/index.d.ts +3 -2
- package/dist/adapters/express/index.js +3 -2
- package/dist/adapters/express/index.js.map +1 -1
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.cjs.map +1 -1
- package/dist/adapters/hono/index.d.cts +3 -2
- package/dist/adapters/hono/index.d.ts +3 -2
- package/dist/adapters/hono/index.js +3 -2
- package/dist/adapters/hono/index.js.map +1 -1
- package/dist/agent/index.cjs +4 -3
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +3 -2
- package/dist/agent/index.d.ts +3 -2
- package/dist/agent/index.js +6 -4
- package/dist/agent/index.js.map +1 -1
- package/dist/{chunk-3HORTMZ7.js → chunk-7F2OH4IP.js} +5 -4
- package/dist/chunk-7F2OH4IP.js.map +1 -0
- package/dist/chunk-F7RDSWYF.js +7 -0
- package/dist/chunk-F7RDSWYF.js.map +1 -0
- package/dist/{chunk-J7JYKCUA.js → chunk-UPQMKAAX.js} +3 -18
- package/dist/chunk-UPQMKAAX.js.map +1 -0
- package/dist/chunk-XTOK7YOR.js +18 -0
- package/dist/chunk-XTOK7YOR.js.map +1 -0
- package/dist/{handler-B4NAi4k_.d.cts → handler-Bw7xVmBM.d.ts} +2 -1
- package/dist/{handler-BRVhWuNk.d.ts → handler-Cy0gNM6K.d.cts} +2 -1
- package/dist/index.cjs +21 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +29 -19
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.cjs +173 -0
- package/dist/migrations/index.cjs.map +1 -0
- package/dist/migrations/index.d.cts +20 -0
- package/dist/migrations/index.d.ts +20 -0
- package/dist/migrations/index.js +23 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/query.schema-B-LVNfyX.d.cts +461 -0
- package/dist/query.schema-B-LVNfyX.d.ts +461 -0
- package/dist/{types-DUJp5B3o.d.cts → types-Bs_9VM9p.d.ts} +10 -462
- package/dist/{types-DUJp5B3o.d.ts → types-DO-rYZci.d.cts} +10 -462
- package/package.json +11 -1
- package/dist/chunk-3HORTMZ7.js.map +0 -1
- package/dist/chunk-J7JYKCUA.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { aa as ScopeValues, S as ScopePolicy, D as DatabaseSchema, e as Row, M as MutationDefinition, u as Mutation, m as CoreMutation, a as QueryEngine, T as QueryResponse } from './types-Bs_9VM9p.js';
|
|
2
|
+
import { Q as Query } from './query.schema-B-LVNfyX.js';
|
|
2
3
|
|
|
3
4
|
type MutationTx = {
|
|
4
5
|
query: (sql: string, params?: unknown[]) => Promise<{
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { aa as ScopeValues, S as ScopePolicy, D as DatabaseSchema, e as Row, M as MutationDefinition, u as Mutation, m as CoreMutation, a as QueryEngine, T as QueryResponse } from './types-DO-rYZci.cjs';
|
|
2
|
+
import { Q as Query } from './query.schema-B-LVNfyX.cjs';
|
|
2
3
|
|
|
3
4
|
type MutationTx = {
|
|
4
5
|
query: (sql: string, params?: unknown[]) => Promise<{
|
package/dist/index.cjs
CHANGED
|
@@ -1880,12 +1880,12 @@ var createQueryEngine = (engineConfig) => {
|
|
|
1880
1880
|
const now = Date.now();
|
|
1881
1881
|
if (isTouchDue(entry, now)) fireAndForget(cache.set(key, { ...entry, lastUsedAt: now }));
|
|
1882
1882
|
};
|
|
1883
|
-
const resolveFingerprint = async (validRequest, hasRequest, requestHash) => {
|
|
1883
|
+
const resolveFingerprint = async (validRequest, hasRequest, requestHash, scope) => {
|
|
1884
1884
|
const fp = validRequest.fingerprint;
|
|
1885
1885
|
if (fp === void 0) {
|
|
1886
1886
|
return { fingerprint: mintFingerprint(), hit: false, replaced: false };
|
|
1887
1887
|
}
|
|
1888
|
-
const entry = await cache.get(fp);
|
|
1888
|
+
const entry = await cache.get(fp, scope);
|
|
1889
1889
|
if (entry?.kind === "mutation") {
|
|
1890
1890
|
throw new VexError(
|
|
1891
1891
|
"invalid_request",
|
|
@@ -1989,6 +1989,7 @@ var createQueryEngine = (engineConfig) => {
|
|
|
1989
1989
|
let result = rows;
|
|
1990
1990
|
let mappingMs;
|
|
1991
1991
|
let mappedIr = cachedIr;
|
|
1992
|
+
let mappedConfig;
|
|
1992
1993
|
if (validRequest.shape !== void 0) {
|
|
1993
1994
|
if (cachedIr !== void 0) {
|
|
1994
1995
|
const mapStart = Date.now();
|
|
@@ -2000,10 +2001,11 @@ var createQueryEngine = (engineConfig) => {
|
|
|
2000
2001
|
mappingMs = Date.now() - mapStart;
|
|
2001
2002
|
result = mapped.transformed;
|
|
2002
2003
|
mappedIr = mapped.ir;
|
|
2004
|
+
mappedConfig = mapped.config;
|
|
2003
2005
|
}
|
|
2004
2006
|
if (mappingMs !== void 0) emit({ type: "query.mapped", mappingMs });
|
|
2005
2007
|
}
|
|
2006
|
-
return { result, rowCount: rows.length, executionMs, mappingMs, mappedIr };
|
|
2008
|
+
return { result, rowCount: rows.length, executionMs, mappingMs, mappedIr, ...mappedConfig !== void 0 ? { mappedConfig } : {} };
|
|
2007
2009
|
};
|
|
2008
2010
|
const execute = async (request, options) => {
|
|
2009
2011
|
if (strata.exceedsDepth(request)) throw new VexError("invalid_request", `Invalid request: ${strata.depthRefusal()}`);
|
|
@@ -2029,7 +2031,7 @@ var createQueryEngine = (engineConfig) => {
|
|
|
2029
2031
|
fingerprint: validRequest.fingerprint,
|
|
2030
2032
|
entities: options?.entities
|
|
2031
2033
|
});
|
|
2032
|
-
const cached = await resolveFingerprint(validRequest, hasRequest, requestHash);
|
|
2034
|
+
const cached = await resolveFingerprint(validRequest, hasRequest, requestHash, scope);
|
|
2033
2035
|
emit({ type: "query.cache", hit: cached.hit, fingerprint: cached.fingerprint, replaced: cached.replaced });
|
|
2034
2036
|
let dsl = cached.dsl;
|
|
2035
2037
|
let agentMs;
|
|
@@ -2116,7 +2118,7 @@ var createQueryEngine = (engineConfig) => {
|
|
|
2116
2118
|
emit({ type: "query.done", totalMs: Date.now() - t0 });
|
|
2117
2119
|
return { result: result2, meta: { ...metaOf(rows.length), timing: { executionMs: executionMs2 } } };
|
|
2118
2120
|
}
|
|
2119
|
-
const { result, rowCount, executionMs, mappingMs, mappedIr } = await executeAndMap(
|
|
2121
|
+
const { result, rowCount, executionMs, mappingMs, mappedIr, mappedConfig } = await executeAndMap(
|
|
2120
2122
|
compiled,
|
|
2121
2123
|
effectiveRequest,
|
|
2122
2124
|
cached.cachedIr,
|
|
@@ -2131,6 +2133,7 @@ var createQueryEngine = (engineConfig) => {
|
|
|
2131
2133
|
kind: "ok",
|
|
2132
2134
|
dsl,
|
|
2133
2135
|
...mappedIr !== void 0 ? { prismIr: mappedIr } : {},
|
|
2136
|
+
...mappedConfig !== void 0 ? { mapping: mappedConfig } : {},
|
|
2134
2137
|
createdAt: now,
|
|
2135
2138
|
lastUsedAt: now,
|
|
2136
2139
|
...requestHash !== void 0 ? { requestHash } : {},
|
|
@@ -3017,7 +3020,7 @@ var quoteIdent2 = (name, label) => {
|
|
|
3017
3020
|
}
|
|
3018
3021
|
return `"${name}"`;
|
|
3019
3022
|
};
|
|
3020
|
-
var SELECT_COLS = "key, kind, intent, shape, dsl, prism_ir, reach, reason, created_at, expires_at, schema_fingerprint, protected, last_used_at, request_hash, refresh";
|
|
3023
|
+
var SELECT_COLS = "key, kind, intent, shape, dsl, prism_ir, mapping, reach, reason, created_at, expires_at, schema_fingerprint, protected, last_used_at, request_hash, refresh";
|
|
3021
3024
|
var rowToEntry = (row) => {
|
|
3022
3025
|
const createdAt = row["created_at"].getTime();
|
|
3023
3026
|
const expiresAtRaw = row["expires_at"];
|
|
@@ -3048,6 +3051,7 @@ var rowToEntry = (row) => {
|
|
|
3048
3051
|
kind: "ok",
|
|
3049
3052
|
dsl: row["dsl"],
|
|
3050
3053
|
...row["prism_ir"] != null ? { prismIr: row["prism_ir"] } : {},
|
|
3054
|
+
...row["mapping"] != null ? { mapping: row["mapping"] } : {},
|
|
3051
3055
|
...row["reach"] != null ? { reach: row["reach"] } : {},
|
|
3052
3056
|
...isRefresh(row["refresh"]) ? { refresh: row["refresh"] } : {},
|
|
3053
3057
|
...meta
|
|
@@ -3093,6 +3097,10 @@ var createPostgresCache = (config) => {
|
|
|
3093
3097
|
{ kind: "sql", sql: `ALTER TABLE ${qualified} ADD COLUMN IF NOT EXISTS reach text` },
|
|
3094
3098
|
{ kind: "sql", sql: `ALTER TABLE ${qualified} ADD COLUMN IF NOT EXISTS refresh text` }
|
|
3095
3099
|
]
|
|
3100
|
+
},
|
|
3101
|
+
{
|
|
3102
|
+
description: "The prism config a mapping was compiled from",
|
|
3103
|
+
steps: [{ kind: "sql", sql: `ALTER TABLE ${qualified} ADD COLUMN IF NOT EXISTS mapping jsonb` }]
|
|
3096
3104
|
}
|
|
3097
3105
|
]
|
|
3098
3106
|
};
|
|
@@ -3136,6 +3144,7 @@ var createPostgresCache = (config) => {
|
|
|
3136
3144
|
const isOk = entry.kind === "ok";
|
|
3137
3145
|
const dsl = isOk ? JSON.stringify(entry.dsl) : entry.kind === "mutation" ? JSON.stringify(entry.mutation) : null;
|
|
3138
3146
|
const prismIr = isOk && entry.prismIr !== void 0 ? JSON.stringify(entry.prismIr) : null;
|
|
3147
|
+
const mapping = isOk && entry.mapping !== void 0 ? JSON.stringify(entry.mapping) : null;
|
|
3139
3148
|
const reason = entry.kind === "unsatisfiable" ? entry.reason : null;
|
|
3140
3149
|
const intent = entry.intent ?? null;
|
|
3141
3150
|
const shape = entry.shape !== void 0 ? JSON.stringify(entry.shape) : null;
|
|
@@ -3148,8 +3157,8 @@ var createPostgresCache = (config) => {
|
|
|
3148
3157
|
const reach = entry.kind === "unsatisfiable" ? null : entry.reach ?? null;
|
|
3149
3158
|
const refresh = entry.kind === "ok" ? entry.refresh ?? null : null;
|
|
3150
3159
|
await pool.query(
|
|
3151
|
-
`INSERT INTO ${qualified} (key, kind, intent, shape, dsl, prism_ir, reach, reason, created_at, expires_at, schema_fingerprint, protected, last_used_at, request_hash, refresh)
|
|
3152
|
-
VALUES ($1, $2, $3, $4::jsonb, $5::jsonb, $6::jsonb, $7, $8, $9, $10, $11, $12, $13, $14, $15)
|
|
3160
|
+
`INSERT INTO ${qualified} (key, kind, intent, shape, dsl, prism_ir, reach, reason, created_at, expires_at, schema_fingerprint, protected, last_used_at, request_hash, refresh, mapping)
|
|
3161
|
+
VALUES ($1, $2, $3, $4::jsonb, $5::jsonb, $6::jsonb, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16::jsonb)
|
|
3153
3162
|
ON CONFLICT (key) DO UPDATE SET
|
|
3154
3163
|
kind = EXCLUDED.kind,
|
|
3155
3164
|
intent = EXCLUDED.intent,
|
|
@@ -3164,8 +3173,9 @@ var createPostgresCache = (config) => {
|
|
|
3164
3173
|
protected = EXCLUDED.protected,
|
|
3165
3174
|
last_used_at = EXCLUDED.last_used_at,
|
|
3166
3175
|
request_hash = EXCLUDED.request_hash,
|
|
3167
|
-
refresh = EXCLUDED.refresh
|
|
3168
|
-
|
|
3176
|
+
refresh = EXCLUDED.refresh,
|
|
3177
|
+
mapping = EXCLUDED.mapping`,
|
|
3178
|
+
[key, entry.kind, intent, shape, dsl, prismIr, reach, reason, createdAt, expiresAt, fingerprint, isProtected, lastUsedAt, requestHash, refresh, mapping]
|
|
3169
3179
|
);
|
|
3170
3180
|
};
|
|
3171
3181
|
const del = async (key) => {
|
|
@@ -4076,7 +4086,7 @@ var runQuery = async (config, body, scope, probe, live) => {
|
|
|
4076
4086
|
try {
|
|
4077
4087
|
let entryReach;
|
|
4078
4088
|
if (parsed.data.fingerprint !== void 0) {
|
|
4079
|
-
const entry = await engine.cache.get(parsed.data.fingerprint);
|
|
4089
|
+
const entry = await engine.cache.get(parsed.data.fingerprint, scope);
|
|
4080
4090
|
if (entry !== void 0 && entry.kind === "ok") entryReach = entry.reach;
|
|
4081
4091
|
if (probe !== void 0 && entryReach !== void 0) probe.reach = entryReach;
|
|
4082
4092
|
if (entry !== void 0 && entry.kind === "mutation") {
|