@niscorp/vex 0.3.1 → 0.4.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/DESIGN.md +11 -7
  3. package/DOCS.md +52 -9
  4. package/dist/adapters/express/index.cjs +1 -1
  5. package/dist/adapters/express/index.cjs.map +1 -1
  6. package/dist/adapters/express/index.d.cts +3 -2
  7. package/dist/adapters/express/index.d.ts +3 -2
  8. package/dist/adapters/express/index.js +3 -2
  9. package/dist/adapters/express/index.js.map +1 -1
  10. package/dist/adapters/hono/index.cjs +1 -1
  11. package/dist/adapters/hono/index.cjs.map +1 -1
  12. package/dist/adapters/hono/index.d.cts +3 -2
  13. package/dist/adapters/hono/index.d.ts +3 -2
  14. package/dist/adapters/hono/index.js +3 -2
  15. package/dist/adapters/hono/index.js.map +1 -1
  16. package/dist/agent/index.cjs +144 -21
  17. package/dist/agent/index.cjs.map +1 -1
  18. package/dist/agent/index.d.cts +3 -2
  19. package/dist/agent/index.d.ts +3 -2
  20. package/dist/agent/index.js +146 -22
  21. package/dist/agent/index.js.map +1 -1
  22. package/dist/{chunk-3HORTMZ7.js → chunk-AKR6HU34.js} +9 -5
  23. package/dist/chunk-AKR6HU34.js.map +1 -0
  24. package/dist/chunk-F7RDSWYF.js +7 -0
  25. package/dist/chunk-F7RDSWYF.js.map +1 -0
  26. package/dist/{chunk-J7JYKCUA.js → chunk-UPQMKAAX.js} +3 -18
  27. package/dist/chunk-UPQMKAAX.js.map +1 -0
  28. package/dist/chunk-XTOK7YOR.js +18 -0
  29. package/dist/chunk-XTOK7YOR.js.map +1 -0
  30. package/dist/{handler-B4NAi4k_.d.cts → handler-CoJxInw-.d.ts} +2 -1
  31. package/dist/{handler-BRVhWuNk.d.ts → handler-CsFbanZA.d.cts} +2 -1
  32. package/dist/index.cjs +26 -13
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +6 -4
  35. package/dist/index.d.ts +6 -4
  36. package/dist/index.js +30 -20
  37. package/dist/index.js.map +1 -1
  38. package/dist/migrations/index.cjs +173 -0
  39. package/dist/migrations/index.cjs.map +1 -0
  40. package/dist/migrations/index.d.cts +20 -0
  41. package/dist/migrations/index.d.ts +20 -0
  42. package/dist/migrations/index.js +23 -0
  43. package/dist/migrations/index.js.map +1 -0
  44. package/dist/query.schema-B-LVNfyX.d.cts +461 -0
  45. package/dist/query.schema-B-LVNfyX.d.ts +461 -0
  46. package/dist/{types-DUJp5B3o.d.cts → types-B2HEmyNq.d.cts} +11 -463
  47. package/dist/{types-DUJp5B3o.d.ts → types-DC68ZUuq.d.ts} +11 -463
  48. package/package.json +12 -1
  49. package/dist/chunk-3HORTMZ7.js.map +0 -1
  50. package/dist/chunk-J7JYKCUA.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -1,10 +1,12 @@
1
- import { Q as QueryEngineConfig, a as QueryEngine, b as Query, D as DatabaseSchema, R as ResolvedQuery, A as AnalysisConfig, c as AnalysisResult, C as CompiledQuery, d as ContextMeta, e as DatabaseAdapter, f as Row, F as FieldSchema, P as ParamSlot, g as ResolvedExists, h as FieldOrValue, i as Filter, j as QueryErrorCode, S as ScopePolicy, k as CacheBackend, l as CacheEntry, m as Refresh, M as MutationDefinition, n as ContextContract } from './types-DUJp5B3o.cjs';
2
- export { o as AdapterCapabilities, p as AggregateExpression, q as AggregateExpressionSchema, B as BoundParams, r as ComputeExpression, s as ComputeExpressionSchema, t as ContextRef, u as CoreMutation, E as EntitySchema, v as ExecuteOptions, w as FilterSchema, G as GenerateDsl, x as GenerationCaller, I as IndexSchema, y as IntrospectOptions, z as ItemRef, L as LiveRowsConfig, H as LiveRowsStats, J as LookupValue, K as MapToShape, N as Mutation, O as MutationCacheEntry, T as MutationDefinitionSchema, U as MutationSchema, V as MutationValue, W as NamedScopeBehaviors, X as NormalizedType, Y as OkCacheEntry, Z as QueryErrorResponse, _ as QueryRequest, $ as QueryRequestSchema, a0 as QueryResponse, a1 as QuerySchema, a2 as REFRESH_MODES, a3 as RelationSchema, a4 as ResolvedField, a5 as ResolvedFilter, a6 as ResolvedJoin, a7 as ResolvedMutation, a8 as ResolvedOnConflict, a9 as ResolvedSemantic, aa as ResolvedSource, ab as ReturnedRef, ac as SCOPE_VERBS, ad as ScopeBehaviors, ae as ScopeBinding, af as ScopeEntityRule, ag as ScopeMatch, ah as ScopeRef, ai as ScopeRule, aj as ScopeRules, ak as ScopeSet, al as ScopeValues, am as SortEntry, an as Source, ao as TestResult, ap as UnsatisfiableCacheEntry, aq as VexEvent, ar as VexEventHandler, as as createScopePolicy, at as isRefresh, au as mergeScopePolicies, av as scopeBindings, aw as scopeGrants, ax as scopeProfiles } from './types-DUJp5B3o.cjs';
1
+ import { Q as QueryEngineConfig, a as QueryEngine, D as DatabaseSchema, R as ResolvedQuery, A as AnalysisConfig, b as AnalysisResult, C as CompiledQuery, c as ContextMeta, d as DatabaseAdapter, e as Row, F as FieldSchema, P as ParamSlot, f as ResolvedExists, g as QueryErrorCode, S as ScopePolicy, h as CacheBackend, i as CacheEntry, j as Refresh, M as MutationDefinition, k as ContextContract } from './types-B2HEmyNq.cjs';
2
+ export { l as AdapterCapabilities, B as BoundParams, m as CoreMutation, E as EntitySchema, n as ExecuteOptions, G as GenerateDsl, o as GenerationCaller, I as IndexSchema, p as IntrospectOptions, q as ItemRef, L as LiveRowsConfig, r as LiveRowsStats, s as LookupValue, t as MapToShape, u as Mutation, v as MutationCacheEntry, w as MutationDefinitionSchema, x as MutationSchema, y as MutationValue, N as NamedScopeBehaviors, z as NormalizedType, O as OkCacheEntry, H as QueryErrorResponse, J as QueryRequest, K as QueryRequestSchema, T as QueryResponse, U as REFRESH_MODES, V as RelationSchema, W as ResolvedField, X as ResolvedFilter, Y as ResolvedJoin, Z as ResolvedMutation, _ as ResolvedOnConflict, $ as ResolvedSemantic, a0 as ResolvedSource, a1 as ReturnedRef, a2 as SCOPE_VERBS, a3 as ScopeBehaviors, a4 as ScopeBinding, a5 as ScopeEntityRule, a6 as ScopeMatch, a7 as ScopeRule, a8 as ScopeRules, a9 as ScopeSet, aa as ScopeValues, ab as TestResult, ac as UnsatisfiableCacheEntry, ad as VexEvent, ae as VexEventHandler, af as createScopePolicy, ag as isRefresh, ah as mergeScopePolicies, ai as scopeBindings, aj as scopeGrants, ak as scopeProfiles } from './types-B2HEmyNq.cjs';
3
+ import { Q as Query, F as FieldOrValue, a as Filter } from './query.schema-B-LVNfyX.cjs';
4
+ export { A as AggregateExpression, b as AggregateExpressionSchema, C as ComputeExpression, c as ComputeExpressionSchema, d as ContextRef, e as FilterSchema, f as QuerySchema, S as ScopeRef, g as SortEntry, h as Source } from './query.schema-B-LVNfyX.cjs';
3
5
  import { P as PgPool } from './introspect-D3OaXHBc.cjs';
4
6
  import { Sequence } from '@niscorp/strata';
5
- export { C as ContextField, a as ContextSignature, D as DiscoveryFingerprint, b as DiscoveryResponse, E as ExecuteRecord, M as MutationClient, c as MutationContext, d as MutationEffect, e as MutationTx, Q as QueryResult, V as VexHandlerConfig, f as VexLive, W as WriteEvent, g as WriteResult, h as collectMutationContext, i as collectQueryContext, j as executeMutation, k as executeWrites, l as handleDiscovery, m as handleFingerprintDelete, n as handleFingerprintPatch, o as handleQuery, p as lintMutation, q as mutationEffect, r as mutationMisfits, s as requiredContextKeys, t as tablesChangedBy } from './handler-B4NAi4k_.cjs';
6
- import 'zod';
7
+ export { C as ContextField, a as ContextSignature, D as DiscoveryFingerprint, b as DiscoveryResponse, E as ExecuteRecord, M as MutationClient, c as MutationContext, d as MutationEffect, e as MutationTx, Q as QueryResult, V as VexHandlerConfig, f as VexLive, W as WriteEvent, g as WriteResult, h as collectMutationContext, i as collectQueryContext, j as executeMutation, k as executeWrites, l as handleDiscovery, m as handleFingerprintDelete, n as handleFingerprintPatch, o as handleQuery, p as lintMutation, q as mutationEffect, r as mutationMisfits, s as requiredContextKeys, t as tablesChangedBy } from './handler-CsFbanZA.cjs';
7
8
  import '@niscorp/prism';
9
+ import 'zod';
8
10
 
9
11
  declare const createQueryEngine: (engineConfig: QueryEngineConfig) => QueryEngine;
10
12
 
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- import { Q as QueryEngineConfig, a as QueryEngine, b as Query, D as DatabaseSchema, R as ResolvedQuery, A as AnalysisConfig, c as AnalysisResult, C as CompiledQuery, d as ContextMeta, e as DatabaseAdapter, f as Row, F as FieldSchema, P as ParamSlot, g as ResolvedExists, h as FieldOrValue, i as Filter, j as QueryErrorCode, S as ScopePolicy, k as CacheBackend, l as CacheEntry, m as Refresh, M as MutationDefinition, n as ContextContract } from './types-DUJp5B3o.js';
2
- export { o as AdapterCapabilities, p as AggregateExpression, q as AggregateExpressionSchema, B as BoundParams, r as ComputeExpression, s as ComputeExpressionSchema, t as ContextRef, u as CoreMutation, E as EntitySchema, v as ExecuteOptions, w as FilterSchema, G as GenerateDsl, x as GenerationCaller, I as IndexSchema, y as IntrospectOptions, z as ItemRef, L as LiveRowsConfig, H as LiveRowsStats, J as LookupValue, K as MapToShape, N as Mutation, O as MutationCacheEntry, T as MutationDefinitionSchema, U as MutationSchema, V as MutationValue, W as NamedScopeBehaviors, X as NormalizedType, Y as OkCacheEntry, Z as QueryErrorResponse, _ as QueryRequest, $ as QueryRequestSchema, a0 as QueryResponse, a1 as QuerySchema, a2 as REFRESH_MODES, a3 as RelationSchema, a4 as ResolvedField, a5 as ResolvedFilter, a6 as ResolvedJoin, a7 as ResolvedMutation, a8 as ResolvedOnConflict, a9 as ResolvedSemantic, aa as ResolvedSource, ab as ReturnedRef, ac as SCOPE_VERBS, ad as ScopeBehaviors, ae as ScopeBinding, af as ScopeEntityRule, ag as ScopeMatch, ah as ScopeRef, ai as ScopeRule, aj as ScopeRules, ak as ScopeSet, al as ScopeValues, am as SortEntry, an as Source, ao as TestResult, ap as UnsatisfiableCacheEntry, aq as VexEvent, ar as VexEventHandler, as as createScopePolicy, at as isRefresh, au as mergeScopePolicies, av as scopeBindings, aw as scopeGrants, ax as scopeProfiles } from './types-DUJp5B3o.js';
1
+ import { Q as QueryEngineConfig, a as QueryEngine, D as DatabaseSchema, R as ResolvedQuery, A as AnalysisConfig, b as AnalysisResult, C as CompiledQuery, c as ContextMeta, d as DatabaseAdapter, e as Row, F as FieldSchema, P as ParamSlot, f as ResolvedExists, g as QueryErrorCode, S as ScopePolicy, h as CacheBackend, i as CacheEntry, j as Refresh, M as MutationDefinition, k as ContextContract } from './types-DC68ZUuq.js';
2
+ export { l as AdapterCapabilities, B as BoundParams, m as CoreMutation, E as EntitySchema, n as ExecuteOptions, G as GenerateDsl, o as GenerationCaller, I as IndexSchema, p as IntrospectOptions, q as ItemRef, L as LiveRowsConfig, r as LiveRowsStats, s as LookupValue, t as MapToShape, u as Mutation, v as MutationCacheEntry, w as MutationDefinitionSchema, x as MutationSchema, y as MutationValue, N as NamedScopeBehaviors, z as NormalizedType, O as OkCacheEntry, H as QueryErrorResponse, J as QueryRequest, K as QueryRequestSchema, T as QueryResponse, U as REFRESH_MODES, V as RelationSchema, W as ResolvedField, X as ResolvedFilter, Y as ResolvedJoin, Z as ResolvedMutation, _ as ResolvedOnConflict, $ as ResolvedSemantic, a0 as ResolvedSource, a1 as ReturnedRef, a2 as SCOPE_VERBS, a3 as ScopeBehaviors, a4 as ScopeBinding, a5 as ScopeEntityRule, a6 as ScopeMatch, a7 as ScopeRule, a8 as ScopeRules, a9 as ScopeSet, aa as ScopeValues, ab as TestResult, ac as UnsatisfiableCacheEntry, ad as VexEvent, ae as VexEventHandler, af as createScopePolicy, ag as isRefresh, ah as mergeScopePolicies, ai as scopeBindings, aj as scopeGrants, ak as scopeProfiles } from './types-DC68ZUuq.js';
3
+ import { Q as Query, F as FieldOrValue, a as Filter } from './query.schema-B-LVNfyX.js';
4
+ export { A as AggregateExpression, b as AggregateExpressionSchema, C as ComputeExpression, c as ComputeExpressionSchema, d as ContextRef, e as FilterSchema, f as QuerySchema, S as ScopeRef, g as SortEntry, h as Source } from './query.schema-B-LVNfyX.js';
3
5
  import { P as PgPool } from './introspect-D3OaXHBc.js';
4
6
  import { Sequence } from '@niscorp/strata';
5
- export { C as ContextField, a as ContextSignature, D as DiscoveryFingerprint, b as DiscoveryResponse, E as ExecuteRecord, M as MutationClient, c as MutationContext, d as MutationEffect, e as MutationTx, Q as QueryResult, V as VexHandlerConfig, f as VexLive, W as WriteEvent, g as WriteResult, h as collectMutationContext, i as collectQueryContext, j as executeMutation, k as executeWrites, l as handleDiscovery, m as handleFingerprintDelete, n as handleFingerprintPatch, o as handleQuery, p as lintMutation, q as mutationEffect, r as mutationMisfits, s as requiredContextKeys, t as tablesChangedBy } from './handler-BRVhWuNk.js';
6
- import 'zod';
7
+ export { C as ContextField, a as ContextSignature, D as DiscoveryFingerprint, b as DiscoveryResponse, E as ExecuteRecord, M as MutationClient, c as MutationContext, d as MutationEffect, e as MutationTx, Q as QueryResult, V as VexHandlerConfig, f as VexLive, W as WriteEvent, g as WriteResult, h as collectMutationContext, i as collectQueryContext, j as executeMutation, k as executeWrites, l as handleDiscovery, m as handleFingerprintDelete, n as handleFingerprintPatch, o as handleQuery, p as lintMutation, q as mutationEffect, r as mutationMisfits, s as requiredContextKeys, t as tablesChangedBy } from './handler-CoJxInw-.js';
7
8
  import '@niscorp/prism';
9
+ import 'zod';
8
10
 
9
11
  declare const createQueryEngine: (engineConfig: QueryEngineConfig) => QueryEngine;
10
12
 
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
- import { MutationDefinitionSchema, lintMutation, computeSchemaFingerprint, pruneOptional, buildValidationContext, requireScope, executeQuery, QueryRequestSchema, computeRequestHash, computePolicyKey, presenceOf, presenceSignature, findMissingContext, buildContextContract, optionalKeysOf, resolveParams, canonicalHash, fireAndForget, isSetMatch, refuseOptional, canonicalText, checkScope, scopeResolved, mintFingerprint, isEntryFresh, canReadTable, hashText, quoteIdent, compileCompute, compileAggregate, compileJoinPairs, compileFilter, isTouchDue } from './chunk-3HORTMZ7.js';
2
- export { MutationDefinitionSchema, MutationSchema, QueryRequestSchema, VexScopeError, applyScope, buildContextContract, buildValidationContext, checkScope, collectMutationContext, collectQueryContext, compileFieldOrValue, compileFilter, computeRequestHash, computeSchemaFingerprint, executeMutation, executeQuery, executeWrites, findMissingContext, handleDiscovery, handleFingerprintDelete, handleFingerprintPatch, handleQuery, lintMutation, mintFingerprint, mutationEffect, mutationMisfits, normalizeShape, optionalKeysOf, presenceOf, pruneOptional, requiredContextKeys, resolveParams, scopeResolved, sweepCache, tablesChangedBy } from './chunk-3HORTMZ7.js';
3
- import { VexError, QuerySchema, isIdentifier, isFieldPathShape, isVexError } from './chunk-J7JYKCUA.js';
4
- export { AggregateExpressionSchema, ComputeExpressionSchema, FilterSchema, QuerySchema, VexError } from './chunk-J7JYKCUA.js';
1
+ import { isRefresh } from './chunk-F7RDSWYF.js';
2
+ export { REFRESH_MODES, isRefresh } from './chunk-F7RDSWYF.js';
3
+ import { MutationDefinitionSchema, lintMutation, computeSchemaFingerprint, pruneOptional, buildValidationContext, requireScope, executeQuery, QueryRequestSchema, computeRequestHash, computePolicyKey, presenceOf, presenceSignature, findMissingContext, buildContextContract, optionalKeysOf, resolveParams, canonicalHash, fireAndForget, isSetMatch, refuseOptional, canonicalText, checkScope, scopeResolved, mintFingerprint, isEntryFresh, canReadTable, hashText, quoteIdent, compileCompute, compileAggregate, compileJoinPairs, compileFilter, isTouchDue } from './chunk-AKR6HU34.js';
4
+ export { MutationDefinitionSchema, MutationSchema, QueryRequestSchema, VexScopeError, applyScope, buildContextContract, buildValidationContext, checkScope, collectMutationContext, collectQueryContext, compileFieldOrValue, compileFilter, computeRequestHash, computeSchemaFingerprint, executeMutation, executeQuery, executeWrites, findMissingContext, handleDiscovery, handleFingerprintDelete, handleFingerprintPatch, handleQuery, lintMutation, mintFingerprint, mutationEffect, mutationMisfits, normalizeShape, optionalKeysOf, presenceOf, pruneOptional, requiredContextKeys, resolveParams, scopeResolved, sweepCache, tablesChangedBy } from './chunk-AKR6HU34.js';
5
+ import { VexError, isVexError } from './chunk-XTOK7YOR.js';
6
+ export { VexError } from './chunk-XTOK7YOR.js';
7
+ import { QuerySchema, isIdentifier, isFieldPathShape } from './chunk-UPQMKAAX.js';
8
+ export { AggregateExpressionSchema, ComputeExpressionSchema, FilterSchema, QuerySchema } from './chunk-UPQMKAAX.js';
5
9
  import { z } from 'zod';
6
10
  import { exceedsDepth, depthRefusal } from '@niscorp/strata';
7
11
  import { compile, execute } from '@niscorp/prism';
@@ -1202,12 +1206,12 @@ var createQueryEngine = (engineConfig) => {
1202
1206
  const now = Date.now();
1203
1207
  if (isTouchDue(entry, now)) fireAndForget(cache.set(key, { ...entry, lastUsedAt: now }));
1204
1208
  };
1205
- const resolveFingerprint = async (validRequest, hasRequest, requestHash) => {
1209
+ const resolveFingerprint = async (validRequest, hasRequest, requestHash, scope) => {
1206
1210
  const fp = validRequest.fingerprint;
1207
1211
  if (fp === void 0) {
1208
1212
  return { fingerprint: mintFingerprint(), hit: false, replaced: false };
1209
1213
  }
1210
- const entry = await cache.get(fp);
1214
+ const entry = await cache.get(fp, scope);
1211
1215
  if (entry?.kind === "mutation") {
1212
1216
  throw new VexError(
1213
1217
  "invalid_request",
@@ -1311,6 +1315,7 @@ var createQueryEngine = (engineConfig) => {
1311
1315
  let result = rows;
1312
1316
  let mappingMs;
1313
1317
  let mappedIr = cachedIr;
1318
+ let mappedConfig;
1314
1319
  if (validRequest.shape !== void 0) {
1315
1320
  if (cachedIr !== void 0) {
1316
1321
  const mapStart = Date.now();
@@ -1318,14 +1323,15 @@ var createQueryEngine = (engineConfig) => {
1318
1323
  mappingMs = Date.now() - mapStart;
1319
1324
  } else if (mapToShape !== void 0) {
1320
1325
  const mapStart = Date.now();
1321
- const mapped = await mapToShape(rows, validRequest.shape);
1326
+ const mapped = await mapToShape(rows, validRequest.shape, validRequest.intent);
1322
1327
  mappingMs = Date.now() - mapStart;
1323
1328
  result = mapped.transformed;
1324
1329
  mappedIr = mapped.ir;
1330
+ mappedConfig = mapped.config;
1325
1331
  }
1326
1332
  if (mappingMs !== void 0) emit({ type: "query.mapped", mappingMs });
1327
1333
  }
1328
- return { result, rowCount: rows.length, executionMs, mappingMs, mappedIr };
1334
+ return { result, rowCount: rows.length, executionMs, mappingMs, mappedIr, ...mappedConfig !== void 0 ? { mappedConfig } : {} };
1329
1335
  };
1330
1336
  const execute$1 = async (request, options) => {
1331
1337
  if (exceedsDepth(request)) throw new VexError("invalid_request", `Invalid request: ${depthRefusal()}`);
@@ -1351,7 +1357,7 @@ var createQueryEngine = (engineConfig) => {
1351
1357
  fingerprint: validRequest.fingerprint,
1352
1358
  entities: options?.entities
1353
1359
  });
1354
- const cached = await resolveFingerprint(validRequest, hasRequest, requestHash);
1360
+ const cached = await resolveFingerprint(validRequest, hasRequest, requestHash, scope);
1355
1361
  emit({ type: "query.cache", hit: cached.hit, fingerprint: cached.fingerprint, replaced: cached.replaced });
1356
1362
  let dsl = cached.dsl;
1357
1363
  let agentMs;
@@ -1438,7 +1444,7 @@ var createQueryEngine = (engineConfig) => {
1438
1444
  emit({ type: "query.done", totalMs: Date.now() - t0 });
1439
1445
  return { result: result2, meta: { ...metaOf(rows.length), timing: { executionMs: executionMs2 } } };
1440
1446
  }
1441
- const { result, rowCount, executionMs, mappingMs, mappedIr } = await executeAndMap(
1447
+ const { result, rowCount, executionMs, mappingMs, mappedIr, mappedConfig } = await executeAndMap(
1442
1448
  compiled,
1443
1449
  effectiveRequest,
1444
1450
  cached.cachedIr,
@@ -1453,6 +1459,7 @@ var createQueryEngine = (engineConfig) => {
1453
1459
  kind: "ok",
1454
1460
  dsl,
1455
1461
  ...mappedIr !== void 0 ? { prismIr: mappedIr } : {},
1462
+ ...mappedConfig !== void 0 ? { mapping: mappedConfig } : {},
1456
1463
  createdAt: now,
1457
1464
  lastUsedAt: now,
1458
1465
  ...requestHash !== void 0 ? { requestHash } : {},
@@ -1973,10 +1980,6 @@ var vexGuide = () => [
1973
1980
  "",
1974
1981
  "GET on the same URL returns the endpoint's self-description: its entities, the query body contract, and every existing named fingerprint with its intent \u2014 check it before generating a query that may already exist."
1975
1982
  ].join("\n");
1976
-
1977
- // src/cache/cache.types.ts
1978
- var REFRESH_MODES = ["snapshot", "reactive"];
1979
- var isRefresh = (value) => REFRESH_MODES.some((mode) => mode === value);
1980
1983
  var isCompiledIr = (value) => {
1981
1984
  if (value === null || typeof value !== "object") return false;
1982
1985
  const ir = value;
@@ -2021,7 +2024,7 @@ var quoteIdent2 = (name, label) => {
2021
2024
  }
2022
2025
  return `"${name}"`;
2023
2026
  };
2024
- 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";
2027
+ 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";
2025
2028
  var rowToEntry = (row) => {
2026
2029
  const createdAt = row["created_at"].getTime();
2027
2030
  const expiresAtRaw = row["expires_at"];
@@ -2052,6 +2055,7 @@ var rowToEntry = (row) => {
2052
2055
  kind: "ok",
2053
2056
  dsl: row["dsl"],
2054
2057
  ...row["prism_ir"] != null ? { prismIr: row["prism_ir"] } : {},
2058
+ ...row["mapping"] != null ? { mapping: row["mapping"] } : {},
2055
2059
  ...row["reach"] != null ? { reach: row["reach"] } : {},
2056
2060
  ...isRefresh(row["refresh"]) ? { refresh: row["refresh"] } : {},
2057
2061
  ...meta
@@ -2097,6 +2101,10 @@ var createPostgresCache = (config) => {
2097
2101
  { kind: "sql", sql: `ALTER TABLE ${qualified} ADD COLUMN IF NOT EXISTS reach text` },
2098
2102
  { kind: "sql", sql: `ALTER TABLE ${qualified} ADD COLUMN IF NOT EXISTS refresh text` }
2099
2103
  ]
2104
+ },
2105
+ {
2106
+ description: "The prism config a mapping was compiled from",
2107
+ steps: [{ kind: "sql", sql: `ALTER TABLE ${qualified} ADD COLUMN IF NOT EXISTS mapping jsonb` }]
2100
2108
  }
2101
2109
  ]
2102
2110
  };
@@ -2140,6 +2148,7 @@ var createPostgresCache = (config) => {
2140
2148
  const isOk = entry.kind === "ok";
2141
2149
  const dsl = isOk ? JSON.stringify(entry.dsl) : entry.kind === "mutation" ? JSON.stringify(entry.mutation) : null;
2142
2150
  const prismIr = isOk && entry.prismIr !== void 0 ? JSON.stringify(entry.prismIr) : null;
2151
+ const mapping = isOk && entry.mapping !== void 0 ? JSON.stringify(entry.mapping) : null;
2143
2152
  const reason = entry.kind === "unsatisfiable" ? entry.reason : null;
2144
2153
  const intent = entry.intent ?? null;
2145
2154
  const shape = entry.shape !== void 0 ? JSON.stringify(entry.shape) : null;
@@ -2152,8 +2161,8 @@ var createPostgresCache = (config) => {
2152
2161
  const reach = entry.kind === "unsatisfiable" ? null : entry.reach ?? null;
2153
2162
  const refresh = entry.kind === "ok" ? entry.refresh ?? null : null;
2154
2163
  await pool.query(
2155
- `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)
2156
- VALUES ($1, $2, $3, $4::jsonb, $5::jsonb, $6::jsonb, $7, $8, $9, $10, $11, $12, $13, $14, $15)
2164
+ `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)
2165
+ VALUES ($1, $2, $3, $4::jsonb, $5::jsonb, $6::jsonb, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16::jsonb)
2157
2166
  ON CONFLICT (key) DO UPDATE SET
2158
2167
  kind = EXCLUDED.kind,
2159
2168
  intent = EXCLUDED.intent,
@@ -2168,8 +2177,9 @@ var createPostgresCache = (config) => {
2168
2177
  protected = EXCLUDED.protected,
2169
2178
  last_used_at = EXCLUDED.last_used_at,
2170
2179
  request_hash = EXCLUDED.request_hash,
2171
- refresh = EXCLUDED.refresh`,
2172
- [key, entry.kind, intent, shape, dsl, prismIr, reach, reason, createdAt, expiresAt, fingerprint, isProtected, lastUsedAt, requestHash, refresh]
2180
+ refresh = EXCLUDED.refresh,
2181
+ mapping = EXCLUDED.mapping`,
2182
+ [key, entry.kind, intent, shape, dsl, prismIr, reach, reason, createdAt, expiresAt, fingerprint, isProtected, lastUsedAt, requestHash, refresh, mapping]
2173
2183
  );
2174
2184
  };
2175
2185
  const del = async (key) => {
@@ -2305,6 +2315,6 @@ var seedCache = async (cache, entries) => {
2305
2315
  }
2306
2316
  };
2307
2317
 
2308
- export { REFRESH_MODES, SCOPE_VERBS, analyze, createMemoryCache, createPostgresAdapter, createPostgresCache, createQueryEngine, createScopePolicy, createTieredCache, discoverEntities, isRefresh, mergeScopePolicies, resolve, scopeBindings, scopeGrants, scopeProfiles, seedCache, validateEntry, vexGuide };
2318
+ export { SCOPE_VERBS, analyze, createMemoryCache, createPostgresAdapter, createPostgresCache, createQueryEngine, createScopePolicy, createTieredCache, discoverEntities, mergeScopePolicies, resolve, scopeBindings, scopeGrants, scopeProfiles, seedCache, validateEntry, vexGuide };
2309
2319
  //# sourceMappingURL=index.js.map
2310
2320
  //# sourceMappingURL=index.js.map