@niscorp/vex 0.2.0 → 0.2.3
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 +161 -0
- package/DESIGN.md +78 -3
- package/DOCS.md +167 -14
- package/README.md +2 -1
- package/dist/adapters/express/index.cjs +241 -19
- package/dist/adapters/express/index.cjs.map +1 -1
- package/dist/adapters/express/index.d.cts +2 -2
- package/dist/adapters/express/index.d.ts +2 -2
- package/dist/adapters/express/index.js +2 -2
- package/dist/adapters/hono/index.cjs +260 -24
- package/dist/adapters/hono/index.cjs.map +1 -1
- package/dist/adapters/hono/index.d.cts +2 -2
- package/dist/adapters/hono/index.d.ts +2 -2
- package/dist/adapters/hono/index.js +21 -7
- package/dist/adapters/hono/index.js.map +1 -1
- package/dist/agent/index.cjs +2 -0
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/{chunk-HF25Q53I.js → chunk-H4BHW76Q.js} +6 -3
- package/dist/chunk-H4BHW76Q.js.map +1 -0
- package/dist/{chunk-5CBKESBJ.js → chunk-IQM4SQE2.js} +279 -29
- package/dist/chunk-IQM4SQE2.js.map +1 -0
- package/dist/{handler-Cql8SJ3F.d.cts → handler-BGCL6_Si.d.ts} +3 -2
- package/dist/{handler-mICf9ins.d.ts → handler-CMrjTXNx.d.cts} +3 -2
- package/dist/index.cjs +320 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +45 -37
- package/dist/index.js.map +1 -1
- package/dist/{types-BRvMB6IM.d.cts → types-Bi-Lg86b.d.cts} +48 -2
- package/dist/{types-BRvMB6IM.d.ts → types-Bi-Lg86b.d.ts} +48 -2
- package/package.json +9 -8
- package/dist/chunk-5CBKESBJ.js.map +0 -1
- package/dist/chunk-HF25Q53I.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/value.schema.ts","../src/schemas/identifier.schema.ts","../src/schemas/filter.schema.ts","../src/schemas/compute.schema.ts","../src/schemas/aggregate.schema.ts","../src/schemas/query.schema.ts","../src/errors.ts"],"names":["z"],"mappings":";;;AAEO,IAAM,gBAAA,GAAmB,EAC7B,MAAA,CAAO;AAAA,EACN,QAAA,EAAU,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,8CAA8C;AAC9E,CAAC,CAAA,CACA,MAAA,EAAO,CACP,QAAA,CAAS,8CAA8C,CAAA;AAEnD,IAAM,cAAA,GAAiB,EAC3B,MAAA,CAAO;AAAA,EACN,MAAA,EAAQ,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,gDAAgD;AAC9E,CAAC,CAAA,CACA,MAAA,EAAO,CACP,QAAA,CAAS,6DAA6D,CAAA;AAElE,IAAM,kBAAA,GAAqB,EAC/B,KAAA,CAAM;AAAA,EACL,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,CAAS,wDAAwD,CAAA;AAAA,EAC5E,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,CAAS,kBAAkB,CAAA;AAAA,EACtC,CAAA,CAAE,OAAA,EAAQ,CAAE,QAAA,CAAS,mBAAmB,CAAA;AAAA,EACxC,CAAA,CAAE,IAAA,EAAK,CAAE,QAAA,CAAS,gBAAgB,CAAA;AAAA,EAClC,gBAAA;AAAA,EACA;AACF,CAAC,CAAA,CACA,SAAS,mDAAmD,CAAA;ACA/D,IAAM,UAAA,GAAa,0BAAA;AACnB,IAAM,UAAA,GAAa,kDAAA;AAEZ,IAAM,YAAA,GAAe,CAAC,KAAA,KAA2B,UAAA,CAAW,KAAK,KAAK;AAEtE,IAAM,gBAAA,GAAmB,CAAC,KAAA,KAAoC,OAAO,UAAU,QAAA,IAAY,UAAA,CAAW,KAAK,KAAK;AAEhH,IAAM,mBAAmBA,CAAAA,CAC7B,MAAA,EAAO,CACP,KAAA,CAAM,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C;AACpF,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,UAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AACF;AAIA,MAAA,CAAO,eAAe,QAAA,CAAS,SAAA,EAAW,WAAW,EAAE,KAAA,EAAO,MAAM,CAAA;AAE7D,IAAM,UAAA,GAAa,CAAC,GAAA,KACzB,GAAA,YAAe,QAAA,IAAa,GAAA,YAAe,KAAA,IAAS,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,SAAS,CAAA,KAAM","file":"chunk-H4BHW76Q.js","sourcesContent":["import { z } from 'zod';\n\nexport const ContextRefSchema = z\n .object({\n $context: z.string().describe('Key to look up in the request context object'),\n })\n .strict()\n .describe('Reference to a caller-provided context value');\n\nexport const ScopeRefSchema = z\n .object({\n $scope: z.string().describe('Key to look up in the server-side scope values'),\n })\n .strict()\n .describe('Reference to a server-injected scope value (access control)');\n\nexport const FieldOrValueSchema = z\n .union([\n z.string().describe('A field path (entity.field format) or a literal string'),\n z.number().describe('A literal number'),\n z.boolean().describe('A literal boolean'),\n z.null().describe('A literal null'),\n ContextRefSchema,\n ScopeRefSchema,\n ])\n .describe('A field path, literal value, or dynamic reference');\n\nexport type ContextRef = z.infer<typeof ContextRefSchema>;\nexport type ScopeRef = z.infer<typeof ScopeRefSchema>;\nexport type FieldOrValue = z.infer<typeof FieldOrValueSchema>;\n","import { z } from 'zod';\n\n// ═══════════════════════════════════════════════════════════════\n// THE NAMES A QUERY MAY SAY — and the one rule for telling them apart.\n//\n// Every string an author (a person, a seed, a model) puts in a NAME position\n// ends up in SQL text: a column reference, an output alias, a subquery alias.\n// Values never do — they bind as parameters or are quoted as literals. So a\n// name is the only place authored text meets the statement, and it is held to\n// a grammar that cannot carry anything but a name: letters, digits and\n// underscores, not starting with a digit.\n//\n// This is the parse-time half. The resolver checks the same predicates again,\n// because `engine.compile()` and `engine.test()` take a DSL that never went\n// through Zod, and the compiler refuses to emit a field position that did not\n// resolve against the introspected schema. Three layers, one grammar.\n//\n// `isFieldPathShape` is also what decides, in a value position, whether a\n// string is a column or a literal. It used to be \"contains a dot\", which made\n// every email address an unknown entity and every string with a dot a column\n// reference — so a literal like \"u1@x.com\" threw, and a string that merely\n// looked dotted went to SQL as a name. Now a column is exactly `ident.ident`,\n// and everything else is a literal.\n// ═══════════════════════════════════════════════════════════════\n\nconst IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;\nconst FIELD_PATH = /^[A-Za-z_][A-Za-z0-9_]*\\.[A-Za-z_][A-Za-z0-9_]*$/;\n\nexport const isIdentifier = (value: string): boolean => IDENTIFIER.test(value);\n\nexport const isFieldPathShape = (value: unknown): value is string => typeof value === 'string' && FIELD_PATH.test(value);\n\nexport const IdentifierSchema = z\n .string()\n .regex(IDENTIFIER, 'A name is letters, digits and underscores, not starting with a digit');\n\nexport const FieldPathSchema = z\n .string()\n .regex(FIELD_PATH, 'A field path is entity.field — each part letters, digits and underscores, not starting with a digit');\n","import { z } from 'zod';\nimport { ContextRefSchema, ScopeRefSchema, FieldOrValueSchema } from './value.schema.js';\nimport { FieldPathSchema } from './identifier.schema.js';\nimport type { ContextRef, ScopeRef, FieldOrValue } from './value.schema.js';\n\n// EXISTS — \"is there a row over there that points back at this one\".\n//\n// It is the same `{ from, filter }` a query already is, and deliberately no\n// more than that: no fields, no sort, no limit, nothing to select. EXISTS asks\n// whether a row is there, so anything that shapes output would be noise the\n// planner discards, and refusing it is what keeps this an operator rather than\n// an invitation to nest arbitrary SQL.\n//\n// The CORRELATION needs no new vocabulary. A dotted string on either side of a\n// comparison is already a field path, so pointing the inner table at the outer\n// one is an ordinary `eq` between two columns:\n//\n// { exists: { from: ['tasks'], filter: { eq: ['tasks.issue_id', 'issues.id'] } } }\n//\n// and `not` composes for NOT EXISTS. Whoever writes SQL writes this on the\n// first try, which is the entire design goal.\nexport type ExistsQuery = {\n from: string[];\n filter?: Filter;\n};\n\nexport type Filter =\n | { exists: ExistsQuery }\n | { eq: [FieldOrValue, FieldOrValue] }\n | { neq: [FieldOrValue, FieldOrValue] }\n | { gt: [FieldOrValue, FieldOrValue] }\n | { gte: [FieldOrValue, FieldOrValue] }\n | { lt: [FieldOrValue, FieldOrValue] }\n | { lte: [FieldOrValue, FieldOrValue] }\n | { in: [string, FieldOrValue[] | ContextRef | ScopeRef] }\n | { notIn: [string, FieldOrValue[] | ContextRef | ScopeRef] }\n | { like: [string, FieldOrValue] }\n | { ilike: [string, FieldOrValue] }\n | { isNull: string }\n | { isNotNull: string }\n | { and: Filter[] }\n | { or: Filter[] }\n | { not: Filter }\n | { semantic: { field: string; query: ContextRef | ScopeRef; minScore?: number } }\n | { fuzzy: { field: string; query: ContextRef | ScopeRef; maxDistance?: number } }\n | { optional: { key: string | string[]; then: Filter } };\n\nconst comparisonPair = z\n .tuple([FieldOrValueSchema, FieldOrValueSchema])\n .describe('[left, right] — both can be field paths, literals, or references');\n\nconst fieldString = FieldPathSchema.describe('Field path in entity.field format');\n\nconst collectionTarget = z\n .union([\n z.array(FieldOrValueSchema).min(1).describe('Array of literal values or references'),\n ContextRefSchema,\n ScopeRefSchema,\n ])\n .describe('A set of values or a reference that resolves to an array');\n\nconst ExistsSchema: z.ZodType<ExistsQuery> = z.lazy(() =>\n z\n .object({\n from: z.array(z.string()).min(1).describe('Entities the subquery reads. Joined by foreign key like any other from.'),\n filter: FilterSchema.optional().describe('The correlation, and any extra condition. Reference the outer query by its own entity path: { eq: [\"<inner>.<fk>\", \"<outer>.id\"] }.'),\n })\n .strict(),\n);\n\nexport const FilterSchema: z.ZodType<Filter> = z.lazy(() =>\n z.union([\n z.object({ exists: ExistsSchema }).strict().describe('EXISTS: true when the subquery matches at least one row. Wrap in `not` for NOT EXISTS.'),\n z.object({ eq: comparisonPair }).strict().describe('Equals: tests equality between two values'),\n z.object({ neq: comparisonPair }).strict().describe('Not equals'),\n z.object({ gt: comparisonPair }).strict().describe('Greater than'),\n z.object({ gte: comparisonPair }).strict().describe('Greater than or equal'),\n z.object({ lt: comparisonPair }).strict().describe('Less than'),\n z.object({ lte: comparisonPair }).strict().describe('Less than or equal'),\n z.object({ in: z.tuple([fieldString, collectionTarget]) }).strict().describe('Field value is in a set'),\n z.object({ notIn: z.tuple([fieldString, collectionTarget]) }).strict().describe('Field value is not in a set'),\n z.object({ like: z.tuple([fieldString, FieldOrValueSchema]) }).strict().describe('Case-sensitive LIKE pattern match (use % as wildcard)'),\n z.object({ ilike: z.tuple([fieldString, FieldOrValueSchema]) }).strict().describe('Case-insensitive ILIKE pattern match (use % as wildcard)'),\n z.object({ isNull: fieldString }).strict().describe('Field value is NULL'),\n z.object({ isNotNull: fieldString }).strict().describe('Field value is NOT NULL'),\n z.object({ and: z.array(FilterSchema).min(2) }).strict().describe('Logical AND: all conditions must be true'),\n z.object({ or: z.array(FilterSchema).min(2) }).strict().describe('Logical OR: at least one condition must be true'),\n z.object({ not: FilterSchema }).strict().describe('Logical NOT: negates the condition'),\n z.object({\n semantic: z.object({\n field: FieldPathSchema.describe('Vector column field path (entity.field)'),\n query: z.union([ContextRefSchema, ScopeRefSchema]).describe('Text to embed and compare'),\n minScore: z.number().min(0).max(1).optional().describe('Minimum cosine similarity (0–1)'),\n }).strict(),\n }).strict().describe('Semantic vector similarity search'),\n z.object({\n fuzzy: z.object({\n field: FieldPathSchema.describe('String field path'),\n query: z.union([ContextRefSchema, ScopeRefSchema]).describe('Text to fuzzy-match'),\n maxDistance: z.number().int().nonnegative().optional().describe('Maximum Levenshtein edit distance'),\n }).strict(),\n }).strict().describe('Fuzzy string match'),\n z.object({\n optional: z.object({\n key: z.union([z.string().min(1), z.array(z.string().min(1)).min(1)])\n .describe('The context key this condition depends on, or EVERY key it depends on. A condition referencing two keys must name both — gating on one leaves the other conditionally required, which surfaces as an empty result rather than as a condition that did not apply.'),\n // BARE, never `.describe()`d. That call CLONES the schema, and zod\n // detects a recursive reference by instance identity — a clone is a\n // different instance, so `to-json-schema` stops seeing the cycle and\n // expands the filter union into itself until the stack goes. Every\n // other recursive slot here (`not`, `and`, `or`) uses it bare for the\n // same reason; the description belongs on the wrapper below.\n then: FilterSchema,\n }).strict(),\n }).strict().describe(\n 'A condition the caller turns on by supplying context keys. When any named key is absent the condition is REMOVED from the query before it compiles — it does not match everything, it is not there. Absent means missing, undefined or null; \"\" is a value and keeps the condition. Direction follows position: under `and` supplying the key NARROWS, under `or` it WIDENS. Either way an absent key reads exactly as if the condition had never been written, and scope is injected afterwards regardless. Reads only: a mutation may not contain one, and neither may the inside of an `exists` (its correlation must be unconditional).',\n ),\n ]),\n);\n","import { z } from 'zod';\nimport { FieldOrValueSchema } from './value.schema.js';\nimport { FilterSchema } from './filter.schema.js';\n\nconst CaseWhenSchema = z\n .object({\n condition: FilterSchema,\n then: FieldOrValueSchema.describe('Value when condition is true'),\n })\n .strict();\n\nexport const ComputeExpressionSchema = z\n .union([\n z.object({ add: z.tuple([FieldOrValueSchema, FieldOrValueSchema]) }).strict().describe('Addition: a + b'),\n z.object({ subtract: z.tuple([FieldOrValueSchema, FieldOrValueSchema]) }).strict().describe('Subtraction: a - b'),\n z.object({ multiply: z.tuple([FieldOrValueSchema, FieldOrValueSchema]) }).strict().describe('Multiplication: a * b'),\n z.object({ divide: z.tuple([FieldOrValueSchema, FieldOrValueSchema]) }).strict().describe('Division: a / b'),\n z.object({ concat: z.array(FieldOrValueSchema).min(2) }).strict().describe('String concatenation'),\n z.object({ coalesce: z.array(FieldOrValueSchema).min(2) }).strict().describe('Returns first non-null value'),\n z.object({\n case: z\n .object({\n when: z.array(CaseWhenSchema).min(1).describe('Condition/result pairs evaluated in order'),\n else: FieldOrValueSchema.describe('Default value when no condition matches'),\n })\n .strict(),\n }).strict().describe('CASE WHEN conditional expression'),\n ])\n .describe('Computed expression: arithmetic, string, or conditional');\n\nexport type ComputeExpression = z.infer<typeof ComputeExpressionSchema>;\n","import { z } from 'zod';\nimport { ComputeExpressionSchema } from './compute.schema.js';\nimport { FieldPathSchema } from './identifier.schema.js';\n\nconst fieldPath = FieldPathSchema.describe('Field path in entity.field format');\n\n// SUM/AVG/MIN/MAX take either a field path or a compute expression — so the\n// argument can be a derived value (e.g. SUM(value * win_probability / 100)),\n// not just a column. A bare string stays valid (non-breaking).\nconst fieldOrExpr = z.union([fieldPath, ComputeExpressionSchema]).describe('A field path or a compute expression');\n\nexport const AggregateExpressionSchema = z\n .union([\n z.object({ count: z.union([FieldPathSchema, z.literal('*')]).describe('Field path or \"*\" for COUNT(*)') }).strict().describe('COUNT'),\n z.object({ countDistinct: FieldPathSchema.describe('Field path whose distinct non-null values are counted') }).strict().describe('COUNT(DISTINCT field)'),\n z.object({ sum: fieldOrExpr }).strict().describe('SUM'),\n z.object({ avg: fieldOrExpr }).strict().describe('AVG'),\n z.object({ min: fieldOrExpr }).strict().describe('MIN'),\n z.object({ max: fieldOrExpr }).strict().describe('MAX'),\n ])\n .describe('Aggregate function applied to a field or expression');\n\nexport type AggregateExpression = z.infer<typeof AggregateExpressionSchema>;\n","import { z } from 'zod';\nimport { FilterSchema } from './filter.schema.js';\nimport { ComputeExpressionSchema } from './compute.schema.js';\nimport { AggregateExpressionSchema } from './aggregate.schema.js';\nimport { FieldPathSchema, IdentifierSchema } from './identifier.schema.js';\nimport type { Filter } from './filter.schema.js';\nimport type { ComputeExpression } from './compute.schema.js';\nimport type { AggregateExpression } from './aggregate.schema.js';\n\nexport const SortEntrySchema = z\n .object({\n field: z.union([FieldPathSchema, IdentifierSchema]).describe('Field path (entity.field), computed field name, or aggregate alias'),\n dir: z.enum(['asc', 'desc']).default('asc').describe('Sort direction'),\n })\n .strict()\n .describe('Sort specification');\n\nexport type SortEntry = z.infer<typeof SortEntrySchema>;\n\nexport type Source = string | { as: string; query: Query };\n\n// A selected field: a bare `entity.field` path, or an aliased one whose output\n// key is `as` (so joined columns that would collide — three `name`s — get\n// distinct keys without a compute hack).\nexport type FieldRef = string | { field: string; as: string };\n\nexport type Query = {\n from: Source[];\n // Optional: a query may select only aggregates (e.g. a bare `COUNT(*)`); the\n // schema requires at least one of `fields` / `aggregate`.\n fields?: FieldRef[];\n filter?: Filter;\n compute?: Record<string, ComputeExpression>;\n aggregate?: Record<string, AggregateExpression>;\n groupBy?: string[];\n sort?: SortEntry[];\n limit?: number;\n distinct?: boolean;\n};\n\nconst SubquerySourceSchema = z\n .object({\n as: IdentifierSchema.describe('Alias for subquery results — use as prefix in field paths'),\n query: z.lazy((): z.ZodType<Query> => QuerySchema).describe('A nested query'),\n })\n .strict()\n .describe('Subquery data source: a nested query read as a table under `as`, its columns referenced as `<as>.<field>` anywhere in the outer query. Joined by foreign key like an entity when one links them; otherwise every outer row is paired with every subquery row (a cross join), so a one-row subquery puts its values beside each outer row.');\n\nconst SourceSchema = z\n .union([\n z.string().describe('Entity name from the database schema'),\n SubquerySourceSchema,\n ])\n .describe('Data source: entity name or subquery');\n\nconst FieldRefSchema = z\n .union([\n FieldPathSchema.describe('A column in entity.field format'),\n z\n .object({\n field: FieldPathSchema.describe('A column in entity.field format'),\n as: IdentifierSchema.describe('Output key for this column'),\n })\n .strict()\n .describe('An aliased column: output under `as` instead of the column name'),\n ])\n .describe('A selected field — a bare `entity.field`, or `{ field, as }` to alias the output key');\n\nexport const QuerySchema: z.ZodType<Query> = z.lazy(() =>\n z\n .object({\n from: z.array(SourceSchema).min(1).describe('Data sources — entity names or subqueries. Every entity used anywhere in the query must be listed here. Listed entities are JOINED FOR YOU along their foreign keys — a nullable key as a LEFT JOIN, so a row whose key is empty is kept, with the joined columns null. Never restate a join as a filter comparing the two keys: that throws those rows away.'),\n fields: z.array(FieldRefSchema).optional().describe('Raw columns to select — each `entity.field`, or `{ field, as }` to alias the output key (no SELECT *). Optional: omit it for an aggregate-only query (e.g. a bare COUNT). Do not list compute or aggregate aliases here — those are added automatically.'),\n filter: FilterSchema.optional().describe('Filter conditions'),\n compute: z.record(IdentifierSchema, ComputeExpressionSchema).optional().describe('Computed fields — key is output alias, value is the expression'),\n aggregate: z.record(IdentifierSchema, AggregateExpressionSchema).optional().describe('Aggregate functions — key is output alias, value is the function'),\n groupBy: z.array(FieldPathSchema).optional().describe('Fields to group by for aggregation'),\n sort: z.array(SortEntrySchema).optional().describe('Sort order'),\n limit: z.number().int().positive().optional().describe('Maximum rows to return'),\n distinct: z.boolean().optional().describe('Eliminate duplicate rows'),\n })\n .strict()\n .refine(\n (q) => (q.fields?.length ?? 0) > 0 || Object.keys(q.aggregate ?? {}).length > 0,\n { message: 'A query must select at least one of `fields` or `aggregate`.' },\n ),\n);\n\nexport { SubquerySourceSchema, SourceSchema };\n","import type { QueryErrorCode } from './schemas/request.schema.js';\n\n// ONE CLASS, SEVERAL COPIES. The CommonJS build gives each entry point\n// (`@niscorp/vex`, `/hono`, `/express`, `/agent`) its own copy of this class,\n// and an app can load the ESM and CommonJS builds side by side — so an error\n// thrown by an engine from one entry is not an `instanceof` the VexError\n// another entry holds. Every copy puts the same mark on its prototype, under a\n// key the whole process shares, and `isVexError` reads the mark. Wherever vex\n// itself asks \"is this one of ours\", it asks that, never `instanceof`.\nconst VEX_ERROR = Symbol.for('@niscorp/vex:VexError');\n\nexport class VexError extends Error {\n readonly code: QueryErrorCode;\n readonly details?: Record<string, unknown>;\n\n constructor(code: QueryErrorCode, message: string, details?: Record<string, unknown>) {\n super(message);\n this.name = 'VexError';\n this.code = code;\n this.details = details;\n }\n}\n\n// On the prototype, not the instance: a subclass inherits it, and nothing an\n// app prints, serializes or enumerates on an error changes.\nObject.defineProperty(VexError.prototype, VEX_ERROR, { value: true });\n\nexport const isVexError = (err: unknown): err is VexError =>\n err instanceof VexError || (err instanceof Error && Reflect.get(err, VEX_ERROR) === true);\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { FilterSchema, VexError, QuerySchema, isFieldPathShape } from './chunk-
|
|
1
|
+
import { FilterSchema, FieldPathSchema, VexError, QuerySchema, isVexError, isFieldPathShape } from './chunk-H4BHW76Q.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
|
|
@@ -658,13 +806,21 @@ var LookupSchema = z.object({
|
|
|
658
806
|
where: FilterSchema.describe("Bounds the lookup \u2014 should match at most one row")
|
|
659
807
|
}).strict()
|
|
660
808
|
}).strict().describe("Scalar subquery: reads one value from another table at write time; read scope rules apply");
|
|
809
|
+
var ReturnedSchema = z.object({
|
|
810
|
+
$returned: FieldPathSchema.describe(
|
|
811
|
+
"`table.column`: `table` is written by exactly one earlier statement of this batch; `column` is a column of that table, including one the database generated."
|
|
812
|
+
)
|
|
813
|
+
}).strict().describe(
|
|
814
|
+
"A column of the one row an earlier statement of this batch (an insert, update, upsert or delete) returned \u2014 how a later row gets an id the database generated. That statement must return exactly one row; none (its `where` matched no row, or scope kept the row back) or several fails the whole batch and nothing is written. Allowed only as the value of a column a statement sets; never inside a `where`, a `$lookup` or `items`, and never naming an `insertEach` or an `insert` whose `onConflict` has no `set`."
|
|
815
|
+
);
|
|
661
816
|
var ValueSchema = z.union([
|
|
662
817
|
z.string(),
|
|
663
818
|
z.number(),
|
|
664
819
|
z.boolean(),
|
|
665
820
|
z.null(),
|
|
666
821
|
z.object({ $context: z.string() }).strict(),
|
|
667
|
-
LookupSchema
|
|
822
|
+
LookupSchema,
|
|
823
|
+
ReturnedSchema
|
|
668
824
|
]);
|
|
669
825
|
var Columns = z.record(z.string(), ValueSchema).refine((r) => Object.keys(r).length > 0, { message: "a write must set at least one column" });
|
|
670
826
|
var OnConflictSchema = z.object({
|
|
@@ -762,17 +918,23 @@ var walkFilter = (filter, schema, sig) => {
|
|
|
762
918
|
};
|
|
763
919
|
var isLookupRef = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && "$lookup" in v;
|
|
764
920
|
var columnsOf = (m) => m.op === "insert" || m.op === "insertEach" ? { ...m.values, ...m.onConflict?.set ?? {} } : m.op === "update" ? m.set : m.op === "upsert" ? { ...m.columns, ...m.insert ?? {} } : {};
|
|
921
|
+
var positionsSetBy = (m) => {
|
|
922
|
+
const positions = (cols, insertOnly = false) => Object.entries(cols ?? {}).map(([column, value]) => ({ column, value, insertOnly }));
|
|
923
|
+
if (m.op === "insert" || m.op === "insertEach") return [...positions(m.values), ...positions(m.onConflict?.set)];
|
|
924
|
+
if (m.op === "update") return positions(m.set);
|
|
925
|
+
if (m.op === "upsert") return [...positions(m.columns), ...positions(m.insert, true)];
|
|
926
|
+
return [];
|
|
927
|
+
};
|
|
765
928
|
var collectMutationContext = (def, schema) => {
|
|
766
929
|
const sig = {};
|
|
767
930
|
const list = Array.isArray(def) ? def : [def];
|
|
768
931
|
for (const m of list) {
|
|
769
|
-
for (const
|
|
932
|
+
for (const { column: col, value: v, insertOnly } of positionsSetBy(m)) {
|
|
770
933
|
if (isLookupRef(v)) {
|
|
771
934
|
walkFilter(v.$lookup.where, schema, sig);
|
|
772
935
|
continue;
|
|
773
936
|
}
|
|
774
937
|
if (!isContextRef(v)) continue;
|
|
775
|
-
const insertOnly = m.op === "upsert" && m.insert !== void 0 && col in m.insert;
|
|
776
938
|
addField(sig, v.$context, { ...columnInfo(`${m.table}.${col}`, schema), ...insertOnly ? { note: "insert only" } : {} });
|
|
777
939
|
}
|
|
778
940
|
if (m.op === "update" || m.op === "delete") walkFilter(m.where, schema, sig);
|
|
@@ -810,8 +972,7 @@ var mutationEffect = (def) => {
|
|
|
810
972
|
};
|
|
811
973
|
var requiredContextKeys = (m) => {
|
|
812
974
|
const keys = /* @__PURE__ */ new Set();
|
|
813
|
-
const
|
|
814
|
-
for (const v of Object.values(cols)) {
|
|
975
|
+
for (const { value: v } of positionsSetBy(m)) {
|
|
815
976
|
if (isContextRef(v)) keys.add(v.$context);
|
|
816
977
|
else if (isLookupRef(v)) {
|
|
817
978
|
const sub = {};
|
|
@@ -833,9 +994,40 @@ var findOptional = (value) => {
|
|
|
833
994
|
if ("optional" in value) return true;
|
|
834
995
|
return Object.values(value).some(findOptional);
|
|
835
996
|
};
|
|
997
|
+
var isReturnedRef = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && "$returned" in v && typeof v.$returned === "string";
|
|
998
|
+
var returnedIn = (list, at) => {
|
|
999
|
+
const refs = /* @__PURE__ */ new Map();
|
|
1000
|
+
const issues = [];
|
|
1001
|
+
const m = list[at];
|
|
1002
|
+
if (m === void 0) return { refs, issues };
|
|
1003
|
+
const judged = /* @__PURE__ */ new Set();
|
|
1004
|
+
for (const { value: v } of positionsSetBy(m)) {
|
|
1005
|
+
if (!isReturnedRef(v) || judged.has(v.$returned)) continue;
|
|
1006
|
+
judged.add(v.$returned);
|
|
1007
|
+
const dot = v.$returned.indexOf(".");
|
|
1008
|
+
const table = v.$returned.slice(0, dot);
|
|
1009
|
+
const column = v.$returned.slice(dot + 1);
|
|
1010
|
+
const reads = `${m.op} on "${m.table}" reads "${v.$returned}"`;
|
|
1011
|
+
const earlier = list.flatMap((s, i) => i < at && s.table === table ? [{ s, i }] : []);
|
|
1012
|
+
const source = earlier[0];
|
|
1013
|
+
if (source === void 0) {
|
|
1014
|
+
issues.push(`${reads}, and no earlier statement writes "${table}" \u2014 put the statement that writes it before this one, in the same batch`);
|
|
1015
|
+
} else if (earlier.length > 1) {
|
|
1016
|
+
issues.push(`${reads}, and ${earlier.length} earlier statements write "${table}" \u2014 a reference cannot tell them apart`);
|
|
1017
|
+
} else if (source.s.op === "insertEach") {
|
|
1018
|
+
issues.push(`${reads} from an insertEach, which writes a row per element \u2014 there is no one row to read`);
|
|
1019
|
+
} else if (source.s.op === "insert" && source.s.onConflict !== void 0 && source.s.onConflict.set === void 0) {
|
|
1020
|
+
issues.push(`${reads} from an insert that does nothing on conflict, which then returns no row \u2014 give its onConflict a \`set\``);
|
|
1021
|
+
} else {
|
|
1022
|
+
refs.set(v.$returned, { statement: source.i, table, column });
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return { refs, issues };
|
|
1026
|
+
};
|
|
836
1027
|
var lintMutation = (def) => {
|
|
837
1028
|
const issues = [];
|
|
838
1029
|
const list = Array.isArray(def) ? def : [def];
|
|
1030
|
+
list.forEach((_m, at) => issues.push(...returnedIn(list, at).issues));
|
|
839
1031
|
for (const m of list) {
|
|
840
1032
|
if (findOptional(m)) {
|
|
841
1033
|
issues.push(`${m.op} on "${m.table}" contains an optional condition \u2014 a write's bounds cannot depend on what the caller chose to send`);
|
|
@@ -853,6 +1045,7 @@ var lintMutation = (def) => {
|
|
|
853
1045
|
// src/mutations/engine.ts
|
|
854
1046
|
var isLookup = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && "$lookup" in v;
|
|
855
1047
|
var isItemRef = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && "$item" in v;
|
|
1048
|
+
var isReturned = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && "$returned" in v;
|
|
856
1049
|
var collectLookups = (m) => {
|
|
857
1050
|
const out = [];
|
|
858
1051
|
const scan = (cols) => {
|
|
@@ -950,6 +1143,13 @@ var assertWritableColumns = (m, schema) => {
|
|
|
950
1143
|
if (m.onConflict.where !== void 0) assertFilterColumns(m.onConflict.where, m.table, schema, "onConflict");
|
|
951
1144
|
}
|
|
952
1145
|
};
|
|
1146
|
+
var assertReturnedColumns = (refs, schema) => {
|
|
1147
|
+
for (const [ref, source] of refs) {
|
|
1148
|
+
if (findEntity(source.table, schema)?.fields.some((f) => f.name === source.column) !== true) {
|
|
1149
|
+
throw new VexError("invalid_dsl", `Unknown column "${ref}" in $returned.`);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
953
1153
|
var readMatchesFor = (table, policy) => {
|
|
954
1154
|
const rule = policy.entities[table];
|
|
955
1155
|
if (rule === void 0) {
|
|
@@ -1058,7 +1258,8 @@ var newCtx = () => ({
|
|
|
1058
1258
|
resolvedPaths: /* @__PURE__ */ new Map(),
|
|
1059
1259
|
aliasMap: /* @__PURE__ */ new Map(),
|
|
1060
1260
|
paramSlots: [],
|
|
1061
|
-
paramCounter: { value: 0 }
|
|
1261
|
+
paramCounter: { value: 0 },
|
|
1262
|
+
returned: /* @__PURE__ */ new Map()
|
|
1062
1263
|
});
|
|
1063
1264
|
var indexFilterFields = (filter, aliasMap) => {
|
|
1064
1265
|
for (const path of filterColumns(filter)) aliasMap.set(path, path);
|
|
@@ -1069,13 +1270,19 @@ var compileValue = (v, ctx) => {
|
|
|
1069
1270
|
const where = compileFilter(v.$lookup.where, ctx);
|
|
1070
1271
|
return `(SELECT ${v.$lookup.field} FROM ${v.$lookup.from} WHERE ${where})`;
|
|
1071
1272
|
}
|
|
1273
|
+
if (isReturned(v)) {
|
|
1274
|
+
ctx.paramCounter.value += 1;
|
|
1275
|
+
ctx.returned.set(ctx.paramSlots.length, v.$returned);
|
|
1276
|
+
ctx.paramSlots.push({ key: v.$returned, kind: "context", type: "string" });
|
|
1277
|
+
return `$${ctx.paramCounter.value}`;
|
|
1278
|
+
}
|
|
1072
1279
|
return compileFieldOrValue(v, ctx);
|
|
1073
1280
|
};
|
|
1074
1281
|
var compileColumnValue = (table, column, v, ctx, schema) => {
|
|
1075
1282
|
const before = ctx.paramSlots.length;
|
|
1076
1283
|
const sql = compileValue(v, ctx);
|
|
1077
1284
|
const json = findEntity(table, schema)?.fields.find((f) => f.name === column)?.normalizedType === "json";
|
|
1078
|
-
if (json && typeof v === "object" && v !== null && "$context" in v) {
|
|
1285
|
+
if (json && typeof v === "object" && v !== null && ("$context" in v || "$returned" in v)) {
|
|
1079
1286
|
const slot = ctx.paramSlots[before];
|
|
1080
1287
|
if (slot !== void 0) ctx.paramSlots[before] = { ...slot, encode: "json" };
|
|
1081
1288
|
}
|
|
@@ -1106,7 +1313,7 @@ var compileMutation = (m, schema) => {
|
|
|
1106
1313
|
const entries = Object.entries(m.values);
|
|
1107
1314
|
const cols = entries.map(([c]) => c);
|
|
1108
1315
|
const vals = entries.map(([c, v]) => compileColumnValue(m.table, c, v, ctx, schema));
|
|
1109
|
-
return { sql: `INSERT INTO ${m.table} (${cols.join(", ")}) VALUES (${vals.join(", ")})${compileConflict(m, ctx, schema)} RETURNING *`, slots: ctx.paramSlots };
|
|
1316
|
+
return { sql: `INSERT INTO ${m.table} (${cols.join(", ")}) VALUES (${vals.join(", ")})${compileConflict(m, ctx, schema)} RETURNING *`, slots: ctx.paramSlots, returned: ctx.returned };
|
|
1110
1317
|
}
|
|
1111
1318
|
if (m.op === "insertEach") {
|
|
1112
1319
|
const entity = findEntity(m.table, schema);
|
|
@@ -1120,25 +1327,26 @@ var compileMutation = (m, schema) => {
|
|
|
1120
1327
|
const raw = `(item.value->>${quoteLiteral(v.$item)})`;
|
|
1121
1328
|
return cast === void 0 ? raw : `${raw}::${cast}`;
|
|
1122
1329
|
}
|
|
1123
|
-
return compileValue(v, ctx);
|
|
1330
|
+
return isReturned(v) ? compileColumnValue(m.table, col, v, ctx, schema) : compileValue(v, ctx);
|
|
1124
1331
|
});
|
|
1125
1332
|
ctx.paramCounter.value += 1;
|
|
1126
1333
|
ctx.paramSlots.push({ key: m.items.$context, kind: "context", type: "json" });
|
|
1127
1334
|
const source = `jsonb_array_elements($${ctx.paramCounter.value}::jsonb) AS item`;
|
|
1128
1335
|
return {
|
|
1129
1336
|
sql: `INSERT INTO ${m.table} (${cols.join(", ")}) SELECT ${exprs.join(", ")} FROM ${source}${compileConflict(m, ctx, schema)} RETURNING *`,
|
|
1130
|
-
slots: ctx.paramSlots
|
|
1337
|
+
slots: ctx.paramSlots,
|
|
1338
|
+
returned: ctx.returned
|
|
1131
1339
|
};
|
|
1132
1340
|
}
|
|
1133
1341
|
if (m.op === "update") {
|
|
1134
1342
|
const sets = Object.entries(m.set).map(([c, v]) => `${c} = ${compileColumnValue(m.table, c, v, ctx, schema)}`);
|
|
1135
1343
|
indexFilterFields(m.where, ctx.aliasMap);
|
|
1136
1344
|
const where2 = compileFilter(m.where, ctx);
|
|
1137
|
-
return { sql: `UPDATE ${m.table} SET ${sets.join(", ")} WHERE ${where2} RETURNING *`, slots: ctx.paramSlots };
|
|
1345
|
+
return { sql: `UPDATE ${m.table} SET ${sets.join(", ")} WHERE ${where2} RETURNING *`, slots: ctx.paramSlots, returned: ctx.returned };
|
|
1138
1346
|
}
|
|
1139
1347
|
indexFilterFields(m.where, ctx.aliasMap);
|
|
1140
1348
|
const where = compileFilter(m.where, ctx);
|
|
1141
|
-
return { sql: `DELETE FROM ${m.table} WHERE ${where} RETURNING *`, slots: ctx.paramSlots };
|
|
1349
|
+
return { sql: `DELETE FROM ${m.table} WHERE ${where} RETURNING *`, slots: ctx.paramSlots, returned: ctx.returned };
|
|
1142
1350
|
};
|
|
1143
1351
|
var SUGAR = {
|
|
1144
1352
|
upsert: (m, context) => {
|
|
@@ -1150,27 +1358,69 @@ var desugarMutation = (m, context) => {
|
|
|
1150
1358
|
const rewrite = SUGAR[m.op];
|
|
1151
1359
|
return rewrite === void 0 ? m : rewrite(m, context);
|
|
1152
1360
|
};
|
|
1361
|
+
var mutationMisfits = (def, schema) => {
|
|
1362
|
+
const reasons = [];
|
|
1363
|
+
const list = Array.isArray(def) ? def : [def];
|
|
1364
|
+
for (const [at, entry] of list.entries()) {
|
|
1365
|
+
const asked = [
|
|
1366
|
+
// keyed, an upsert is an update; unkeyed, an insert
|
|
1367
|
+
...(entry.op === "upsert" ? [{ [entry.key]: 0 }, {}] : [{}]).map((context) => () => assertWritableColumns(desugarMutation(entry, context), schema)),
|
|
1368
|
+
() => assertReturnedColumns(returnedIn(list, at).refs, schema)
|
|
1369
|
+
];
|
|
1370
|
+
for (const ask of asked) {
|
|
1371
|
+
try {
|
|
1372
|
+
ask();
|
|
1373
|
+
} catch (error) {
|
|
1374
|
+
reasons.push(error instanceof Error ? error.message : String(error));
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
return reasons;
|
|
1379
|
+
};
|
|
1153
1380
|
var executeWrites = async (client, def, mctx) => {
|
|
1154
1381
|
const parsed = MutationDefinitionSchema.parse(def);
|
|
1155
1382
|
const entries = Array.isArray(parsed) ? parsed : [parsed];
|
|
1156
|
-
const
|
|
1157
|
-
|
|
1383
|
+
const cores = entries.map((entry) => desugarMutation(entry, mctx.context));
|
|
1384
|
+
const compiled = cores.map((core, at) => {
|
|
1158
1385
|
const missing = requiredContextKeys(core).filter((k) => mctx.context[k] === void 0);
|
|
1159
1386
|
if (missing.length > 0) {
|
|
1160
1387
|
throw new VexError("missing_context", `Mutation is missing context: ${missing.join(", ")}.`, {
|
|
1161
1388
|
expected: collectMutationContext(parsed, mctx.schema)
|
|
1162
1389
|
});
|
|
1163
1390
|
}
|
|
1391
|
+
const returned = returnedIn(cores, at);
|
|
1392
|
+
if (returned.issues.length > 0) throw new VexError("invalid_dsl", `${returned.issues.join("; ")}.`);
|
|
1164
1393
|
const m = scopeMutation(core, mctx.policy);
|
|
1165
1394
|
assertWritableColumns(m, mctx.schema);
|
|
1395
|
+
assertReturnedColumns(returned.refs, mctx.schema);
|
|
1166
1396
|
const statement = compileMutation(m, mctx.schema);
|
|
1167
1397
|
requireScope({ paramSlots: statement.slots }, mctx.scope);
|
|
1168
|
-
|
|
1398
|
+
const reads = [...statement.returned].map(([slot, ref]) => {
|
|
1399
|
+
const source = returned.refs.get(ref);
|
|
1400
|
+
if (source === void 0) throw new VexError("invalid_dsl", `"${ref}" names no earlier statement of the batch.`);
|
|
1401
|
+
return { slot, ref, source };
|
|
1402
|
+
});
|
|
1403
|
+
return { ...statement, reads, table: m.table, op: m.op === "insertEach" ? "insert" : m.op };
|
|
1169
1404
|
});
|
|
1170
1405
|
const runAll = async (q) => {
|
|
1171
1406
|
const results = [];
|
|
1172
1407
|
for (const c of compiled) {
|
|
1173
1408
|
const params = await resolveParams(c.slots, mctx.context, mctx.scope);
|
|
1409
|
+
for (const read of c.reads) {
|
|
1410
|
+
const rows = results[read.source.statement]?.rows ?? [];
|
|
1411
|
+
const row = rows[0];
|
|
1412
|
+
if (rows.length !== 1 || row === void 0) {
|
|
1413
|
+
throw new VexError(
|
|
1414
|
+
"execution_error",
|
|
1415
|
+
`"${read.ref}" needs exactly one row from statement ${read.source.statement + 1} of the batch, which wrote ${rows.length}. Nothing was written.`,
|
|
1416
|
+
{ returned: read.ref, rows: rows.length }
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
if (!(read.source.column in row)) {
|
|
1420
|
+
throw new VexError("execution_error", `"${read.ref}": the row statement ${read.source.statement + 1} returned has no "${read.source.column}" key. Nothing was written.`, { returned: read.ref });
|
|
1421
|
+
}
|
|
1422
|
+
params[read.slot] = row[read.source.column];
|
|
1423
|
+
}
|
|
1174
1424
|
const bound = params.map((value, i) => {
|
|
1175
1425
|
if (c.slots[i]?.encode === "json") return value !== null && typeof value === "object" ? JSON.stringify(value) : value;
|
|
1176
1426
|
if (c.slots[i]?.type !== "json") return value;
|
|
@@ -1469,11 +1719,11 @@ var runQuery = async (config, body, scope, probe, live) => {
|
|
|
1469
1719
|
}
|
|
1470
1720
|
return { status: 200, body: response };
|
|
1471
1721
|
} catch (err) {
|
|
1472
|
-
if (err
|
|
1722
|
+
if (isVexError(err) && err.code === "missing_scope") {
|
|
1473
1723
|
console.error("[vex] refused a statement the host did not scope:", err.message);
|
|
1474
1724
|
return { status: 500, body: { error: "missing_scope", message: "The server did not supply the scope this request needs." } };
|
|
1475
1725
|
}
|
|
1476
|
-
if (err
|
|
1726
|
+
if (isVexError(err)) {
|
|
1477
1727
|
const status = err.code === "fingerprint_protected" ? 409 : err.code === "cache_miss" ? 404 : 400;
|
|
1478
1728
|
return {
|
|
1479
1729
|
status,
|
|
@@ -1523,6 +1773,6 @@ var handleFingerprintDelete = async (config, fingerprint) => {
|
|
|
1523
1773
|
return { status: 200, body: { fingerprint, deleted: true } };
|
|
1524
1774
|
};
|
|
1525
1775
|
|
|
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-
|
|
1776
|
+
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, mutationMisfits, normalizeShape, optionalKeysOf, presenceOf, presenceSignature, pruneOptional, quoteIdent, refuseOptional, requireScope, requiredContextKeys, resolveParams, scopeResolved, sweepCache, tablesChangedBy };
|
|
1777
|
+
//# sourceMappingURL=chunk-IQM4SQE2.js.map
|
|
1778
|
+
//# sourceMappingURL=chunk-IQM4SQE2.js.map
|