@rawsql-ts/sql-contract 0.3.1 → 0.3.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.
@@ -0,0 +1,443 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CatalogExecutionError = exports.ContractViolationError = exports.BinderError = exports.RewriterError = exports.SQLLoaderError = exports.CatalogError = void 0;
4
+ exports.createCatalogExecutor = createCatalogExecutor;
5
+ const mapper_1 = require("../mapper");
6
+ const normalizeExecutionResult_1 = require("../normalizeExecutionResult");
7
+ const mutation_1 = require("./mutation");
8
+ const metadataIdentifierPattern = /^[A-Za-z_][A-Za-z0-9_]*$/;
9
+ const metadataIdentifierControlPattern = /[\u0000-\u001F\u007F]/;
10
+ function cloneMetadataIdentifierList(specId, kind, identifiers) {
11
+ if (!identifiers) {
12
+ return undefined;
13
+ }
14
+ return identifiers.map((identifier) => {
15
+ if (identifier.length === 0) {
16
+ throw new ContractViolationError(`Spec "${specId}" declares an empty metadata.${kind} identifier.`, specId);
17
+ }
18
+ if (metadataIdentifierControlPattern.test(identifier)) {
19
+ throw new ContractViolationError(`Spec "${specId}" declares unsafe metadata.${kind} identifier "${identifier}" containing control characters.`, specId);
20
+ }
21
+ if (!metadataIdentifierPattern.test(identifier)) {
22
+ throw new ContractViolationError(`Spec "${specId}" declares unsafe metadata.${kind} identifier "${identifier}"; expected ${metadataIdentifierPattern}.`, specId);
23
+ }
24
+ return identifier;
25
+ });
26
+ }
27
+ const expectedScaleValues = new Set([
28
+ 'tiny',
29
+ 'small',
30
+ 'medium',
31
+ 'large',
32
+ 'batch',
33
+ ]);
34
+ function cloneQuerySpecPerfNumber(specId, key, value) {
35
+ if (value === undefined) {
36
+ return undefined;
37
+ }
38
+ if (!Number.isFinite(value) || value < 0) {
39
+ throw new ContractViolationError(`Spec "${specId}" declares invalid metadata.perf.${key}; expected a non-negative finite number.`, specId);
40
+ }
41
+ return value;
42
+ }
43
+ function cloneQuerySpecPerfMetadata(specId, perf) {
44
+ if (!perf) {
45
+ return undefined;
46
+ }
47
+ const expectedScale = perf.expectedScale;
48
+ if (expectedScale !== undefined && !expectedScaleValues.has(expectedScale)) {
49
+ throw new ContractViolationError(`Spec "${specId}" declares invalid metadata.perf.expectedScale "${expectedScale}".`, specId);
50
+ }
51
+ return {
52
+ expectedScale,
53
+ expectedInputRows: cloneQuerySpecPerfNumber(specId, 'expectedInputRows', perf.expectedInputRows),
54
+ expectedOutputRows: cloneQuerySpecPerfNumber(specId, 'expectedOutputRows', perf.expectedOutputRows),
55
+ };
56
+ }
57
+ function cloneQuerySpecMetadata(specId, metadata) {
58
+ if (!metadata) {
59
+ return undefined;
60
+ }
61
+ return {
62
+ material: cloneMetadataIdentifierList(specId, 'material', metadata.material),
63
+ scalarMaterial: cloneMetadataIdentifierList(specId, 'scalarMaterial', metadata.scalarMaterial),
64
+ perf: cloneQuerySpecPerfMetadata(specId, metadata.perf),
65
+ };
66
+ }
67
+ let execIdCounter = 0;
68
+ function createExecId() {
69
+ execIdCounter += 1;
70
+ return `catalog-exec-${Date.now()}-${execIdCounter}`;
71
+ }
72
+ /**
73
+ * Root error class for catalog execution failures.
74
+ */
75
+ class CatalogError extends Error {
76
+ constructor(message, specId, cause) {
77
+ super(message);
78
+ this.name = this.constructor.name;
79
+ this.specId = specId;
80
+ this.cause = cause;
81
+ Object.setPrototypeOf(this, new.target.prototype);
82
+ }
83
+ }
84
+ exports.CatalogError = CatalogError;
85
+ /** Wraps failures encountered while loading catalog SQL assets. */
86
+ class SQLLoaderError extends CatalogError {
87
+ }
88
+ exports.SQLLoaderError = SQLLoaderError;
89
+ /** Wraps failures thrown by catalog rewriters. */
90
+ class RewriterError extends CatalogError {
91
+ }
92
+ exports.RewriterError = RewriterError;
93
+ /** Wraps binder failures or invalid binder output. */
94
+ class BinderError extends CatalogError {
95
+ }
96
+ exports.BinderError = BinderError;
97
+ /** Captures violations of the declared query/catalog contract before hitting the executor. */
98
+ class ContractViolationError extends CatalogError {
99
+ }
100
+ exports.ContractViolationError = ContractViolationError;
101
+ /** Wraps failures from the query executor or result shaping.
102
+ * Contract violations must throw `ContractViolationError` instead so observability
103
+ * can consistently classify them as `contract`.
104
+ */
105
+ class CatalogExecutionError extends CatalogError {
106
+ }
107
+ exports.CatalogExecutionError = CatalogExecutionError;
108
+ function assertPositionalParams(specId, params) {
109
+ if (!Array.isArray(params)) {
110
+ throw new ContractViolationError(`Spec "${specId}" expects positional parameters.`, specId);
111
+ }
112
+ return params;
113
+ }
114
+ function isPlainObject(value) {
115
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
116
+ return false;
117
+ }
118
+ const proto = Object.getPrototypeOf(value);
119
+ // Accept `{}`-like objects and those created via Object.create(null).
120
+ return proto === Object.prototype || proto === null;
121
+ }
122
+ function assertNamedParams(specId, params) {
123
+ if (!isPlainObject(params)) {
124
+ throw new ContractViolationError(`Spec "${specId}" expects named parameters.`, specId);
125
+ }
126
+ return params;
127
+ }
128
+ function assertParamsShape(specId, expectedShape, params) {
129
+ if (expectedShape === 'positional') {
130
+ return assertPositionalParams(specId, params);
131
+ }
132
+ return assertNamedParams(specId, params);
133
+ }
134
+ /**
135
+ * Creates a CatalogExecutor that enforces the QuerySpec contract and applies
136
+ * optional rewriters and binders before delegating to the target query executor.
137
+ */
138
+ function createCatalogExecutor(options) {
139
+ var _a, _b, _c, _d, _e;
140
+ const cache = (_a = options.sqlCache) !== null && _a !== void 0 ? _a : new Map();
141
+ const rewriters = (_b = options.rewriters) !== null && _b !== void 0 ? _b : [];
142
+ const binders = (_c = options.binders) !== null && _c !== void 0 ? _c : [];
143
+ const allowNamedWithoutBinder = (_d = options.allowNamedParamsWithoutBinder) !== null && _d !== void 0 ? _d : false;
144
+ const extensions = (_e = options.extensions) !== null && _e !== void 0 ? _e : [];
145
+ const sink = options.observabilitySink;
146
+ async function loadSql(spec) {
147
+ const cached = cache.get(spec.sqlFile);
148
+ if (cached !== undefined) {
149
+ return cached;
150
+ }
151
+ try {
152
+ const sql = await options.loader.load(spec.sqlFile);
153
+ cache.set(spec.sqlFile, sql);
154
+ return sql;
155
+ }
156
+ catch (cause) {
157
+ throw new SQLLoaderError(`Failed to load SQL file "${spec.sqlFile}".`, spec.id, cause);
158
+ }
159
+ }
160
+ function normalizeToQueryParams(value, specId) {
161
+ if (Array.isArray(value)) {
162
+ return value;
163
+ }
164
+ if (isPlainObject(value)) {
165
+ return value;
166
+ }
167
+ throw new ContractViolationError(`Parameters must be positional or named (array or record).`, specId);
168
+ }
169
+ function applyRewriters(spec, sql, params, options) {
170
+ let currentSql = sql;
171
+ let currentParams = params;
172
+ for (const rewriter of rewriters) {
173
+ try {
174
+ const rewritten = rewriter.rewrite({
175
+ specId: spec.id,
176
+ spec,
177
+ sql: currentSql,
178
+ params: currentParams,
179
+ options,
180
+ });
181
+ currentSql = rewritten.sql;
182
+ currentParams = rewritten.params;
183
+ }
184
+ catch (cause) {
185
+ throw new RewriterError(`Rewriter "${rewriter.name}" failed for spec "${spec.id}".`, spec.id, cause);
186
+ }
187
+ }
188
+ return {
189
+ sql: currentSql,
190
+ params: currentParams,
191
+ };
192
+ }
193
+ function applyBinders(spec, sql, params) {
194
+ if (binders.length === 0) {
195
+ return { binderUsed: false, sql, params };
196
+ }
197
+ let currentSql = sql;
198
+ let currentParams = params;
199
+ for (const binder of binders) {
200
+ try {
201
+ const bound = binder.bind({
202
+ specId: spec.id,
203
+ sql: currentSql,
204
+ params: normalizeToQueryParams(currentParams, spec.id),
205
+ });
206
+ if (!Array.isArray(bound.params)) {
207
+ throw new BinderError(`Binder "${binder.name}" returned invalid params for spec "${spec.id}".`, spec.id);
208
+ }
209
+ currentSql = bound.sql;
210
+ currentParams = bound.params;
211
+ }
212
+ catch (cause) {
213
+ if (cause instanceof CatalogError) {
214
+ throw cause;
215
+ }
216
+ throw new BinderError(`Binder "${binder.name}" failed for spec "${spec.id}".`, spec.id, cause);
217
+ }
218
+ }
219
+ if (!Array.isArray(currentParams)) {
220
+ throw new BinderError(`Binder chain did not produce positional params for spec "${spec.id}".`, spec.id);
221
+ }
222
+ return {
223
+ binderUsed: true,
224
+ sql: currentSql,
225
+ params: currentParams,
226
+ };
227
+ }
228
+ function describeParamsShape(params) {
229
+ if (Array.isArray(params)) {
230
+ return 'positional';
231
+ }
232
+ if (isPlainObject(params)) {
233
+ return 'named';
234
+ }
235
+ return 'unknown';
236
+ }
237
+ function createSqlPreview(sql) {
238
+ const maxLength = 2048;
239
+ return sql.length <= maxLength ? sql : sql.slice(0, maxLength);
240
+ }
241
+ function getErrorKind(error) {
242
+ if (error instanceof CatalogExecutionError) {
243
+ return 'db';
244
+ }
245
+ if (error instanceof CatalogError) {
246
+ return 'contract';
247
+ }
248
+ return 'unknown';
249
+ }
250
+ function emitQueryStartEvent(spec, execId, attempt, snapshot) {
251
+ if (!sink) {
252
+ return;
253
+ }
254
+ sink.emit({
255
+ kind: 'query_start',
256
+ specId: spec.id,
257
+ sqlFile: spec.sqlFile,
258
+ execId,
259
+ attempt,
260
+ timeMs: snapshot.startTime,
261
+ attributes: spec.tags,
262
+ sqlPreview: createSqlPreview(snapshot.sql),
263
+ paramsShape: snapshot.paramsShape,
264
+ });
265
+ }
266
+ function emitQueryEndEvent(spec, execId, attempt, baseStartTime, rowCount) {
267
+ if (!sink) {
268
+ return;
269
+ }
270
+ const now = Date.now();
271
+ sink.emit({
272
+ kind: 'query_end',
273
+ specId: spec.id,
274
+ sqlFile: spec.sqlFile,
275
+ execId,
276
+ attempt,
277
+ timeMs: now,
278
+ attributes: spec.tags,
279
+ durationMs: Math.max(now - baseStartTime, 0),
280
+ rowCount,
281
+ });
282
+ }
283
+ function emitQueryErrorEvent(spec, execId, attempt, baseStartTime, error) {
284
+ if (!sink) {
285
+ return;
286
+ }
287
+ const now = Date.now();
288
+ sink.emit({
289
+ kind: 'query_error',
290
+ specId: spec.id,
291
+ sqlFile: spec.sqlFile,
292
+ execId,
293
+ attempt,
294
+ timeMs: now,
295
+ attributes: spec.tags,
296
+ durationMs: Math.max(now - baseStartTime, 0),
297
+ errorKind: getErrorKind(error),
298
+ errorMessage: error instanceof Error ? error.message : String(error !== null && error !== void 0 ? error : 'unknown'),
299
+ });
300
+ }
301
+ async function executeRows(spec, params, executionOptions, execId, attempt) {
302
+ const validatedParams = assertParamsShape(spec.id, spec.params.shape, params);
303
+ const sql = await loadSql(spec);
304
+ if (spec.mutation) {
305
+ (0, mutation_1.assertMutationSafeRewriters)(ContractViolationError, spec, rewriters);
306
+ }
307
+ const preprocessed = spec.mutation
308
+ ? (0, mutation_1.preprocessMutationSpec)(ContractViolationError, spec, sql, validatedParams)
309
+ : { sql, params: validatedParams, mutation: undefined };
310
+ const rewritten = applyRewriters(spec, preprocessed.sql, preprocessed.params, executionOptions);
311
+ const rewrittenParams = assertParamsShape(spec.id, spec.params.shape, rewritten.params);
312
+ assertNamedAllowed(spec, binders, allowNamedWithoutBinder);
313
+ const bound = applyBinders(spec, rewritten.sql, rewrittenParams);
314
+ const paramsShape = describeParamsShape(bound.params);
315
+ const snapshot = {
316
+ sql: bound.sql,
317
+ params: bound.params,
318
+ paramsShape,
319
+ startTime: Date.now(),
320
+ };
321
+ emitQueryStartEvent(spec, execId, attempt, snapshot);
322
+ try {
323
+ const execution = (0, normalizeExecutionResult_1.normalizeExecutionResult)(await options.executor(bound.sql, bound.params));
324
+ return {
325
+ rows: execution.rows,
326
+ rowCount: execution.rowCount,
327
+ snapshot,
328
+ mutation: preprocessed.mutation,
329
+ };
330
+ }
331
+ catch (cause) {
332
+ throw new CatalogExecutionError(`Query executor failed while processing catalog spec "${spec.id}".`, spec.id, cause);
333
+ }
334
+ }
335
+ function createPipelineExec(spec, finalize) {
336
+ return async (input) => {
337
+ var _a, _b;
338
+ const invocationStart = Date.now();
339
+ let snapshot;
340
+ try {
341
+ const { rows, rowCount, snapshot: rowSnapshot, mutation, } = await executeRows(spec, input.params, input.options, input.execId, input.attempt);
342
+ snapshot = rowSnapshot;
343
+ (0, mutation_1.assertDeleteGuard)(ContractViolationError, spec, mutation, rowCount);
344
+ const value = finalize(rows);
345
+ const durationBase = (_a = snapshot === null || snapshot === void 0 ? void 0 : snapshot.startTime) !== null && _a !== void 0 ? _a : invocationStart;
346
+ // durationMs reflects the executor round-trip after loading/rewriting/binding SQL.
347
+ emitQueryEndEvent(spec, input.execId, input.attempt, durationBase, rowCount !== null && rowCount !== void 0 ? rowCount : rows.length);
348
+ return { value, rowCount: rowCount !== null && rowCount !== void 0 ? rowCount : rows.length };
349
+ }
350
+ catch (error) {
351
+ const durationBase = (_b = snapshot === null || snapshot === void 0 ? void 0 : snapshot.startTime) !== null && _b !== void 0 ? _b : invocationStart;
352
+ emitQueryErrorEvent(spec, input.execId, input.attempt, durationBase, error);
353
+ throw error;
354
+ }
355
+ };
356
+ }
357
+ function wrapWithExtensions(core) {
358
+ return extensions.reduceRight((next, extension) => extension.wrap(next), core);
359
+ }
360
+ function applyOutputTransformation(spec, rows) {
361
+ const mappedRows = spec.output.mapping
362
+ ? (0, mapper_1.mapRows)(rows, spec.output.mapping)
363
+ : rows;
364
+ const decode = spec.output.validate;
365
+ if (!decode) {
366
+ return mappedRows;
367
+ }
368
+ // The decoder/validator runs after mapping so it receives the DTO shape
369
+ // declared by the catalog contract instead of the raw SQL row.
370
+ return mappedRows.map((value) => decode(value));
371
+ }
372
+ function expectExactlyOneRow(rows, specId) {
373
+ if (rows.length === 0) {
374
+ throw new ContractViolationError('Expected exactly one row but received none.', specId);
375
+ }
376
+ if (rows.length > 1) {
377
+ throw new ContractViolationError(`Expected exactly one row but received ${rows.length}.`, specId);
378
+ }
379
+ return rows[0];
380
+ }
381
+ function extractScalar(rows, specId) {
382
+ const row = expectExactlyOneRow(rows, specId);
383
+ const columns = Object.keys(row);
384
+ if (columns.length !== 1) {
385
+ throw new ContractViolationError(`Expected exactly one column but received ${columns.length}.`, specId);
386
+ }
387
+ return row[columns[0]];
388
+ }
389
+ function applyScalarResult(spec, value) {
390
+ const decode = spec.output.validate;
391
+ if (decode) {
392
+ // Scalar contracts validate the extracted single-column value directly.
393
+ return decode(value);
394
+ }
395
+ return value;
396
+ }
397
+ function createExecInput(spec, params, options, execId, attempt) {
398
+ // Extensions must never observe a shared QuerySpec metadata reference.
399
+ const metadata = cloneQuerySpecMetadata(spec.id, spec.metadata);
400
+ return {
401
+ specId: spec.id,
402
+ sqlFile: spec.sqlFile,
403
+ metadata,
404
+ params,
405
+ options,
406
+ execId,
407
+ attempt,
408
+ };
409
+ }
410
+ return {
411
+ async list(spec, params, options) {
412
+ const exec = wrapWithExtensions(createPipelineExec(spec, (rows) => applyOutputTransformation(spec, rows)));
413
+ const execId = createExecId();
414
+ const attempt = 1;
415
+ const result = await exec(createExecInput(spec, params, options, execId, attempt));
416
+ return result.value;
417
+ },
418
+ async one(spec, params, options) {
419
+ const exec = wrapWithExtensions(createPipelineExec(spec, (rows) => expectExactlyOneRow(applyOutputTransformation(spec, rows), spec.id)));
420
+ const execId = createExecId();
421
+ const attempt = 1;
422
+ const result = await exec(createExecInput(spec, params, options, execId, attempt));
423
+ return result.value;
424
+ },
425
+ async scalar(spec, params, options) {
426
+ const exec = wrapWithExtensions(createPipelineExec(spec, (rows) => {
427
+ const value = extractScalar(rows, spec.id);
428
+ return applyScalarResult(spec, value);
429
+ }));
430
+ const execId = createExecId();
431
+ const attempt = 1;
432
+ const result = await exec(createExecInput(spec, params, options, execId, attempt));
433
+ return result.value;
434
+ },
435
+ };
436
+ }
437
+ /** Named parameters are forbidden unless a binder is configured or explicit allowance is granted. */
438
+ function assertNamedAllowed(spec, binders, allow) {
439
+ if (spec.params.shape === 'named' && binders.length === 0 && !allow) {
440
+ throw new ContractViolationError(`Spec "${spec.id}" declares named parameters without a binder; enable allowNamedParamsWithoutBinder or add a binder.`, spec.id);
441
+ }
442
+ }
443
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/catalog/index.ts"],"names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
+ requireAllNamedParams: boolean;
5
+ };
6
+ type UpdateMutationConfig = {
7
+ subtractUndefinedAssignments: boolean;
8
+ failOnEmptySet: boolean;
9
+ where: WherePolicy;
10
+ };
11
+ type InsertMutationConfig = {
12
+ subtractUndefinedColumns: boolean;
13
+ failOnEmptyColumns: boolean;
14
+ };
15
+ type DeleteMutationConfig = {
16
+ where: WherePolicy;
17
+ affectedRowsGuard: {
18
+ mode: 'exactly';
19
+ count: number;
20
+ } | {
21
+ mode: 'none';
22
+ };
23
+ };
24
+ export type MutationSafety = 'safe' | 'unsafe' | 'unknown';
25
+ export type MutationAwareRewriter = {
26
+ mutationSafety: 'safe';
27
+ };
28
+ export type NormalizedMutationSpec = {
29
+ kind: 'insert';
30
+ insert: InsertMutationConfig;
31
+ } | {
32
+ kind: 'update';
33
+ update: UpdateMutationConfig;
34
+ } | {
35
+ kind: 'delete';
36
+ delete: DeleteMutationConfig;
37
+ };
38
+ export type MutationCatalogSpec = {
39
+ id: string;
40
+ params: {
41
+ shape: 'positional' | 'named';
42
+ };
43
+ mutation?: {
44
+ kind: 'insert';
45
+ insert?: {
46
+ subtractUndefinedColumns?: boolean;
47
+ failOnEmptyColumns?: boolean;
48
+ };
49
+ } | {
50
+ kind: 'update';
51
+ update?: {
52
+ subtractUndefinedAssignments?: boolean;
53
+ failOnEmptySet?: boolean;
54
+ };
55
+ where?: {
56
+ requireWhereClause?: boolean;
57
+ requireAllNamedParams?: boolean;
58
+ };
59
+ } | {
60
+ kind: 'delete';
61
+ where?: {
62
+ requireWhereClause?: boolean;
63
+ requireAllNamedParams?: boolean;
64
+ };
65
+ delete?: {
66
+ affectedRowsGuard?: {
67
+ mode: 'exactly';
68
+ count: number;
69
+ } | {
70
+ mode: 'none';
71
+ };
72
+ };
73
+ };
74
+ };
75
+ export type MutationPreprocessResult = {
76
+ sql: string;
77
+ params: QueryParams;
78
+ mutation: NormalizedMutationSpec | undefined;
79
+ };
80
+ type ContractViolationLike = new (message: string, specId?: string, cause?: unknown) => Error;
81
+ export declare function preprocessMutationSpec(ContractViolationError: ContractViolationLike, spec: MutationCatalogSpec, sql: string, params: QueryParams): MutationPreprocessResult;
82
+ export declare function isMutationSafeRewriter(rewriter: unknown): rewriter is MutationAwareRewriter;
83
+ export declare function assertMutationSafeRewriters(ContractViolationError: ContractViolationLike, spec: MutationCatalogSpec, rewriters: readonly unknown[]): void;
84
+ export declare function assertDeleteGuard(ContractViolationError: ContractViolationLike, spec: MutationCatalogSpec, mutation: NormalizedMutationSpec | undefined, rowCount: number | undefined): void;
85
+ export {};