@hypequery/protocol 0.27.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/cache-preimages/cache-preimages.d.ts.map +1 -1
  2. package/dist/cache-preimages/cache-preimages.js +22 -0
  3. package/dist/deployments/codec.d.ts +8 -0
  4. package/dist/deployments/codec.d.ts.map +1 -1
  5. package/dist/deployments/codec.js +11 -1
  6. package/dist/deployments/events.d.ts +10 -0
  7. package/dist/deployments/events.d.ts.map +1 -0
  8. package/dist/deployments/events.js +59 -0
  9. package/dist/deployments/index.d.ts +8 -4
  10. package/dist/deployments/index.d.ts.map +1 -1
  11. package/dist/deployments/index.js +5 -2
  12. package/dist/deployments/sql-source-analysis.d.ts +29 -0
  13. package/dist/deployments/sql-source-analysis.d.ts.map +1 -0
  14. package/dist/deployments/sql-source-analysis.js +264 -0
  15. package/dist/deployments/sql-source.d.ts +8 -0
  16. package/dist/deployments/sql-source.d.ts.map +1 -0
  17. package/dist/deployments/sql-source.js +107 -0
  18. package/dist/deployments/types.d.ts +41 -1
  19. package/dist/deployments/types.d.ts.map +1 -1
  20. package/dist/deployments/validate.d.ts +19 -0
  21. package/dist/deployments/validate.d.ts.map +1 -1
  22. package/dist/deployments/validate.js +162 -4
  23. package/dist/event-operations/index.d.ts +6 -0
  24. package/dist/event-operations/index.d.ts.map +1 -0
  25. package/dist/event-operations/index.js +4 -0
  26. package/dist/event-operations/limits.d.ts +17 -0
  27. package/dist/event-operations/limits.d.ts.map +1 -0
  28. package/dist/event-operations/limits.js +21 -0
  29. package/dist/event-operations/predicates.d.ts +4 -0
  30. package/dist/event-operations/predicates.d.ts.map +1 -0
  31. package/dist/event-operations/predicates.js +10 -0
  32. package/dist/event-operations/records.d.ts +9 -0
  33. package/dist/event-operations/records.d.ts.map +1 -0
  34. package/dist/event-operations/records.js +55 -0
  35. package/dist/event-operations/types.d.ts +69 -0
  36. package/dist/event-operations/types.d.ts.map +1 -0
  37. package/dist/event-operations/types.js +1 -0
  38. package/dist/event-operations/validate.d.ts +11 -0
  39. package/dist/event-operations/validate.d.ts.map +1 -0
  40. package/dist/event-operations/validate.js +220 -0
  41. package/dist/event-operations/window.d.ts +8 -0
  42. package/dist/event-operations/window.d.ts.map +1 -0
  43. package/dist/event-operations/window.js +23 -0
  44. package/dist/expressions/calculations.d.ts +103 -0
  45. package/dist/expressions/calculations.d.ts.map +1 -0
  46. package/dist/expressions/calculations.js +9 -0
  47. package/dist/expressions/index.d.ts +3 -0
  48. package/dist/expressions/index.d.ts.map +1 -1
  49. package/dist/expressions/index.js +2 -0
  50. package/dist/expressions/relative-dates.d.ts +31 -0
  51. package/dist/expressions/relative-dates.d.ts.map +1 -0
  52. package/dist/expressions/relative-dates.js +38 -0
  53. package/dist/expressions/types.d.ts +24 -1
  54. package/dist/expressions/types.d.ts.map +1 -1
  55. package/dist/expressions/validate-calculations.d.ts +41 -0
  56. package/dist/expressions/validate-calculations.d.ts.map +1 -0
  57. package/dist/expressions/validate-calculations.js +397 -0
  58. package/dist/expressions/validate.d.ts.map +1 -1
  59. package/dist/expressions/validate.js +80 -4
  60. package/dist/index.d.ts +10 -5
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +6 -2
  63. package/dist/invocations/index.d.ts +1 -1
  64. package/dist/invocations/index.d.ts.map +1 -1
  65. package/dist/invocations/types.d.ts +13 -3
  66. package/dist/invocations/types.d.ts.map +1 -1
  67. package/dist/invocations/validate.d.ts.map +1 -1
  68. package/dist/invocations/validate.js +58 -2
  69. package/dist/visibility/resolve.d.ts +4 -4
  70. package/dist/visibility/resolve.d.ts.map +1 -1
  71. package/dist/visibility/resolve.js +12 -4
  72. package/dist/visibility/types.d.ts +6 -0
  73. package/dist/visibility/types.d.ts.map +1 -1
  74. package/package.json +1 -1
@@ -0,0 +1,397 @@
1
+ /**
2
+ * RFC 0026 envelope validation for `calculations`, `limitBy` and `other`.
3
+ *
4
+ * Everything here is decidable from the query alone: shapes, arities, output
5
+ * names, references between entries, and what the query selects. Whether an
6
+ * input is a published measure, visible to the caller, or of the right
7
+ * aggregation is decided against the contract by the data plane and the
8
+ * executor.
9
+ */
10
+ import { expressionError } from './errors.js';
11
+ import { PROTOCOL_CALCULATION_KINDS } from './calculations.js';
12
+ const KINDS = new Set(PROTOCOL_CALCULATION_KINDS);
13
+ const GRAINS = new Set(['minute', 'hour', 'day', 'week', 'month', 'quarter', 'year']);
14
+ const ARITY = Object.freeze({
15
+ add: [2, 2], subtract: [2, 2], multiply: [2, 2], divide: [2, 2],
16
+ nullIfZero: [1, 1], coalesce: [2, 2], round: [1, 2], floor: [1, 1], ceil: [1, 1],
17
+ percentChange: [2, 2],
18
+ });
19
+ const MAX_INTERVAL = 1000;
20
+ const MAX_OTHER = 1000;
21
+ const MAX_LABEL = 64;
22
+ const MAX_ROUND_DECIMALS = 15;
23
+ const COMPARE_SUFFIXES = ['_previous', '_change', '_change_pct'];
24
+ const invalid = (path) => expressionError('HQ_EXPRESSION_INVALID_QUERY', path);
25
+ /** C0 and C1 controls, as the invocation envelope defines them. */
26
+ function hasControlCharacter(text) {
27
+ for (let index = 0; index < text.length; index += 1) {
28
+ const code = text.charCodeAt(index);
29
+ if (code <= 0x1f || (code >= 0x7f && code <= 0x9f))
30
+ return true;
31
+ }
32
+ return false;
33
+ }
34
+ function positiveInteger(value, path, maximum = Number.MAX_SAFE_INTEGER) {
35
+ if (!Number.isSafeInteger(value) || value < 1 || value > maximum)
36
+ invalid(path);
37
+ return value;
38
+ }
39
+ /** The output names an entry produces, before any of its references are checked. */
40
+ function entryOutputs(kit, entry, kind, name, path) {
41
+ if (kind !== 'compare')
42
+ return [name];
43
+ const compare = kit.requireRecord(entry.compare, `${path}.compare`);
44
+ if (compare.measures === undefined)
45
+ return [];
46
+ const measures = kit.arrayValue(compare.measures, `${path}.compare.measures`);
47
+ return measures.flatMap((measure, index) => {
48
+ const measurePath = `${path}.compare.measures[${index}]`;
49
+ const base = kit.identifier(measure, measurePath, false);
50
+ return COMPARE_SUFFIXES.map(suffix => {
51
+ try {
52
+ return kit.identifier(`${base}${suffix}`, measurePath, false);
53
+ }
54
+ catch {
55
+ // The caller wrote a valid measure name; it is the emitted column that
56
+ // cannot exist, which is a query problem rather than a bad identifier.
57
+ return invalid(measurePath);
58
+ }
59
+ });
60
+ });
61
+ }
62
+ class CalculationValidator {
63
+ kit;
64
+ query;
65
+ outputs = new Map();
66
+ selectedMeasures;
67
+ partitionable;
68
+ constructor(kit, query) {
69
+ this.kit = kit;
70
+ this.query = query;
71
+ this.selectedMeasures = new Set(query.measures);
72
+ this.partitionable = new Set([...query.dimensions, ...(query.hasBy ? ['period'] : [])]);
73
+ }
74
+ validate(input) {
75
+ const kit = this.kit;
76
+ const values = kit.arrayValue(input, '$.calculations');
77
+ const taken = new Set([...this.query.dimensions, ...this.query.measures, ...(this.query.hasBy ? ['period'] : [])]);
78
+ // Entry names are unique too, so metadata and errors name one entry.
79
+ const entryNames = new Set();
80
+ const shapes = values.map((item, index) => {
81
+ const path = `$.calculations[${index}]`;
82
+ const entry = kit.requireRecord(item, path);
83
+ for (const key of Object.keys(entry)) {
84
+ if (key !== 'name' && !KINDS.has(key))
85
+ expressionError('HQ_EXPRESSION_UNKNOWN_FIELD', `${path}.${key}`);
86
+ }
87
+ if (!Object.hasOwn(entry, 'name'))
88
+ expressionError('HQ_EXPRESSION_TYPE', `${path}.name`);
89
+ const name = kit.identifier(entry.name, `${path}.name`, false);
90
+ const kinds = Object.keys(entry).filter(key => key !== 'name');
91
+ if (kinds.length !== 1)
92
+ invalid(path);
93
+ const kind = kinds[0];
94
+ if (entryNames.has(name))
95
+ invalid(`${path}.name`);
96
+ entryNames.add(name);
97
+ // Every name is known before any reference is resolved, so a reference
98
+ // to a later entry is recognised as a forward reference rather than
99
+ // mistaken for a published measure.
100
+ for (const output of entryOutputs(kit, entry, kind, name, path)) {
101
+ if (taken.has(output))
102
+ invalid(kind === 'compare' ? `${path}.compare.measures` : `${path}.name`);
103
+ taken.add(output);
104
+ this.outputs.set(output, { entry: index, kind, timed: false });
105
+ }
106
+ return { entry, kind, name, path };
107
+ });
108
+ const entries = shapes.map(({ entry, kind, name, path }, index) => {
109
+ kit.enter(entry, 2, path);
110
+ try {
111
+ return kit.freezeRecord({ name, [kind]: this.kind(kind, entry[kind], index, `${path}.${kind}`) });
112
+ }
113
+ finally {
114
+ kit.leave(entry);
115
+ }
116
+ });
117
+ return { entries: Object.freeze(entries), outputs: Object.freeze([...this.outputs.keys()]) };
118
+ }
119
+ kind(kind, input, index, path) {
120
+ const value = this.kit.requireRecord(input, path);
121
+ this.kit.enter(value, 3, path);
122
+ try {
123
+ switch (kind) {
124
+ case 'filter': return this.filter(value, index, path);
125
+ case 'shift': return this.shift(value, index, path);
126
+ case 'window': return this.window(value, index, path);
127
+ case 'formula': return this.formula(value, index, path, 3);
128
+ case 'compare': return this.compare(value, index, path);
129
+ case 'rank': return this.rank(value, index, path);
130
+ case 'share': return this.share(value, index, path);
131
+ }
132
+ }
133
+ finally {
134
+ this.kit.leave(value);
135
+ }
136
+ }
137
+ /** Marks timed outputs once their entry has validated. */
138
+ settle(index, timed) {
139
+ for (const [name, output] of this.outputs) {
140
+ if (output.entry === index)
141
+ this.outputs.set(name, { ...output, timed });
142
+ }
143
+ }
144
+ /**
145
+ * Resolves an input reference. A name produced by this or a later entry is a
146
+ * forward reference. An earlier output must be of an accepted kind;
147
+ * otherwise the name is a published measure, which `selected` additionally
148
+ * requires the query to select.
149
+ */
150
+ reference(value, path, index, accepts, published) {
151
+ const name = this.kit.identifier(value, path, false);
152
+ const output = this.outputs.get(name);
153
+ if (output !== undefined) {
154
+ if (output.entry >= index || !accepts.includes(output.kind))
155
+ invalid(path);
156
+ return { name, output };
157
+ }
158
+ if (published === 'none' || (published === 'selected' && !this.selectedMeasures.has(name)))
159
+ invalid(path);
160
+ return { name };
161
+ }
162
+ requireBy(path) {
163
+ if (!this.query.hasBy)
164
+ invalid(path);
165
+ }
166
+ interval(value, path, extra) {
167
+ this.kit.exactFields(value, ['amount', 'unit', ...extra], [], path);
168
+ const amount = positiveInteger(value.amount, `${path}.amount`, MAX_INTERVAL);
169
+ const unit = this.kit.stringValue(value.unit, `${path}.unit`);
170
+ if (!GRAINS.has(unit))
171
+ invalid(`${path}.unit`);
172
+ return { amount, unit };
173
+ }
174
+ partition(value, path) {
175
+ const items = this.kit.arrayValue(value, path);
176
+ const seen = new Set();
177
+ return Object.freeze(items.map((item, at) => {
178
+ const itemPath = `${path}[${at}]`;
179
+ const name = this.kit.identifier(item, itemPath);
180
+ if (!this.partitionable.has(name) || seen.has(name))
181
+ invalid(itemPath);
182
+ seen.add(name);
183
+ return name;
184
+ }));
185
+ }
186
+ filter(value, index, path) {
187
+ this.kit.exactFields(value, ['measure', 'where'], [], path);
188
+ const { name } = this.reference(value.measure, `${path}.measure`, index, [], 'any');
189
+ const where = this.kit.arrayValue(value.where, `${path}.where`);
190
+ if (where.length === 0)
191
+ invalid(`${path}.where`);
192
+ return this.kit.freezeRecord({
193
+ measure: name,
194
+ where: Object.freeze(where.map((item, at) => {
195
+ const itemPath = `${path}.where[${at}]`;
196
+ const expression = this.kit.predicate(item, itemPath);
197
+ if (!isPlainComparison(expression))
198
+ invalid(itemPath);
199
+ return expression;
200
+ })),
201
+ });
202
+ }
203
+ shift(value, index, path) {
204
+ this.kit.exactFields(value, ['measure', 'amount', 'unit'], [], path);
205
+ const input = this.reference(value.measure, `${path}.measure`, index, ['filter', 'formula'], 'any');
206
+ if (input.output?.timed)
207
+ invalid(`${path}.measure`);
208
+ const { amount, unit } = this.interval(value, path, ['measure']);
209
+ this.requireBy(path);
210
+ this.settle(index, true);
211
+ return this.kit.freezeRecord({ measure: input.name, amount, unit });
212
+ }
213
+ window(value, index, path) {
214
+ this.kit.exactFields(value, ['measure'], ['trailing', 'toDate', 'cumulative'], path);
215
+ const input = this.reference(value.measure, `${path}.measure`, index, ['filter'], 'any');
216
+ const modes = ['trailing', 'toDate', 'cumulative'].filter(mode => value[mode] !== undefined);
217
+ if (modes.length !== 1)
218
+ invalid(path);
219
+ let mode;
220
+ if (value.trailing !== undefined) {
221
+ const trailingPath = `${path}.trailing`;
222
+ const trailing = this.kit.requireRecord(value.trailing, trailingPath);
223
+ this.kit.enter(trailing, 4, trailingPath);
224
+ try {
225
+ mode = { trailing: this.kit.freezeRecord(this.interval(trailing, trailingPath, [])) };
226
+ }
227
+ finally {
228
+ this.kit.leave(trailing);
229
+ }
230
+ }
231
+ else if (value.toDate !== undefined) {
232
+ const grain = this.kit.stringValue(value.toDate, `${path}.toDate`);
233
+ if (!GRAINS.has(grain) || grain === 'minute')
234
+ invalid(`${path}.toDate`);
235
+ mode = { toDate: grain };
236
+ }
237
+ else {
238
+ if (value.cumulative !== true)
239
+ invalid(`${path}.cumulative`);
240
+ mode = { cumulative: true };
241
+ }
242
+ this.requireBy(path);
243
+ this.settle(index, true);
244
+ return this.kit.freezeRecord({ measure: input.name, ...mode });
245
+ }
246
+ formula(value, index, path, depth) {
247
+ const state = { references: 0, timed: false };
248
+ const node = this.formulaNode(value, index, path, depth, state);
249
+ if (state.references === 0)
250
+ invalid(path);
251
+ this.settle(index, state.timed);
252
+ return node;
253
+ }
254
+ formulaNode(value, index, path, depth, state) {
255
+ this.kit.exactFields(value, ['op', 'args'], [], path);
256
+ const op = this.kit.stringValue(value.op, `${path}.op`);
257
+ const arity = Object.hasOwn(ARITY, op) ? ARITY[op] : undefined;
258
+ if (arity === undefined)
259
+ return invalid(`${path}.op`);
260
+ const args = this.kit.arrayValue(value.args, `${path}.args`);
261
+ if (args.length < arity[0] || args.length > arity[1])
262
+ invalid(`${path}.args`);
263
+ return this.kit.freezeRecord({
264
+ op,
265
+ args: Object.freeze(args.map((arg, at) => {
266
+ const argPath = `${path}.args[${at}]`;
267
+ if (op === 'round' && at === 1) {
268
+ if (!Number.isSafeInteger(arg) || arg < 0 || arg > MAX_ROUND_DECIMALS)
269
+ invalid(argPath);
270
+ return arg;
271
+ }
272
+ if (typeof arg === 'string') {
273
+ const input = this.reference(arg, argPath, index, ['filter', 'shift', 'window', 'formula', 'compare'], 'selected');
274
+ state.references += 1;
275
+ if (input.output?.timed)
276
+ state.timed = true;
277
+ return input.name;
278
+ }
279
+ if (typeof arg === 'number') {
280
+ if (!Number.isFinite(arg))
281
+ invalid(argPath);
282
+ return arg;
283
+ }
284
+ if (typeof arg !== 'object' || arg === null || Array.isArray(arg))
285
+ return invalid(argPath);
286
+ const child = this.kit.requireRecord(arg, argPath);
287
+ this.kit.enter(child, depth + 1, argPath);
288
+ try {
289
+ return this.formulaNode(child, index, argPath, depth + 1, state);
290
+ }
291
+ finally {
292
+ this.kit.leave(child);
293
+ }
294
+ })),
295
+ });
296
+ }
297
+ compare(value, index, path) {
298
+ this.kit.exactFields(value, ['to', 'measures'], [], path);
299
+ const to = this.kit.stringValue(value.to, `${path}.to`);
300
+ if (to !== 'previousPeriod' && to !== 'previousYear')
301
+ invalid(`${path}.to`);
302
+ const items = this.kit.arrayValue(value.measures, `${path}.measures`);
303
+ if (items.length === 0)
304
+ invalid(`${path}.measures`);
305
+ const seen = new Set();
306
+ const measures = items.map((item, at) => {
307
+ const itemPath = `${path}.measures[${at}]`;
308
+ const input = this.reference(item, itemPath, index, ['filter', 'formula'], 'selected');
309
+ if (input.output?.timed || seen.has(input.name))
310
+ invalid(itemPath);
311
+ seen.add(input.name);
312
+ return input.name;
313
+ });
314
+ this.requireBy(path);
315
+ this.settle(index, true);
316
+ return this.kit.freezeRecord({ to, measures: Object.freeze(measures) });
317
+ }
318
+ rank(value, index, path) {
319
+ this.kit.exactFields(value, ['measure'], ['within', 'direction'], path);
320
+ const input = this.reference(value.measure, `${path}.measure`, index, ['filter', 'shift', 'window', 'formula', 'compare'], 'selected');
321
+ const result = { measure: input.name };
322
+ if (value.within !== undefined)
323
+ result.within = this.partition(value.within, `${path}.within`);
324
+ if (value.direction !== undefined) {
325
+ const direction = this.kit.stringValue(value.direction, `${path}.direction`);
326
+ if (direction !== 'asc' && direction !== 'desc')
327
+ invalid(`${path}.direction`);
328
+ result.direction = direction;
329
+ }
330
+ this.settle(index, input.output?.timed ?? false);
331
+ return this.kit.freezeRecord(result);
332
+ }
333
+ share(value, index, path) {
334
+ this.kit.exactFields(value, ['measure'], ['of'], path);
335
+ const input = this.reference(value.measure, `${path}.measure`, index, ['filter', 'shift', 'window', 'formula', 'compare'], 'selected');
336
+ const result = { measure: input.name };
337
+ if (value.of !== undefined)
338
+ result.of = this.partition(value.of, `${path}.of`);
339
+ this.settle(index, input.output?.timed ?? false);
340
+ return this.kit.freezeRecord(result);
341
+ }
342
+ }
343
+ function isPlainComparison(expression) {
344
+ if (expression.kind !== 'comparison' || expression.left.kind !== 'reference')
345
+ return false;
346
+ if (String(expression.left.name).includes('.'))
347
+ return false;
348
+ return !('right' in expression) || expression.right.kind === 'literal';
349
+ }
350
+ /** Validates `calculations`; returns the normalized entries and every output column name. */
351
+ export function validateQueryCalculations(kit, input, query) {
352
+ return new CalculationValidator(kit, query).validate(input);
353
+ }
354
+ /** Validates `limitBy`; `ordered` is whether the query has a non-empty `orderBy`. */
355
+ export function validateLimitBy(kit, input, query, ordered) {
356
+ const value = kit.requireRecord(input, '$.limitBy');
357
+ kit.exactFields(value, ['n', 'by'], [], '$.limitBy');
358
+ const n = positiveInteger(value.n, '$.limitBy.n');
359
+ const items = kit.arrayValue(value.by, '$.limitBy.by');
360
+ if (items.length === 0)
361
+ invalid('$.limitBy.by');
362
+ const partitionable = new Set([...query.dimensions, ...(query.hasBy ? ['period'] : [])]);
363
+ const seen = new Set();
364
+ const by = items.map((item, at) => {
365
+ const path = `$.limitBy.by[${at}]`;
366
+ const name = kit.identifier(item, path);
367
+ if (!partitionable.has(name) || seen.has(name))
368
+ invalid(path);
369
+ seen.add(name);
370
+ return name;
371
+ });
372
+ // Without an order the kept rows would be arbitrary.
373
+ if (!ordered)
374
+ invalid('$.limitBy');
375
+ return kit.freezeRecord({ n, by: Object.freeze(by) });
376
+ }
377
+ /** Validates `other`; `outputs` are calculation output names, which it may not rank by. */
378
+ export function validateOtherBucket(kit, input, query, outputs) {
379
+ const value = kit.requireRecord(input, '$.other');
380
+ kit.exactFields(value, ['dimension', 'n', 'measure'], ['label'], '$.other');
381
+ const dimension = kit.identifier(value.dimension, '$.other.dimension', false);
382
+ if (!query.dimensions.includes(dimension))
383
+ invalid('$.other.dimension');
384
+ const n = positiveInteger(value.n, '$.other.n', MAX_OTHER);
385
+ const measure = kit.identifier(value.measure, '$.other.measure', false);
386
+ if (outputs.includes(measure))
387
+ invalid('$.other.measure');
388
+ const result = { dimension, n, measure };
389
+ if (value.label !== undefined) {
390
+ const label = kit.stringValue(value.label, '$.other.label');
391
+ if (label.length === 0 || [...label].length > MAX_LABEL || hasControlCharacter(label)) {
392
+ invalid('$.other.label');
393
+ }
394
+ result.label = label;
395
+ }
396
+ return kit.freezeRecord(result);
397
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/expressions/validate.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAEV,kBAAkB,EAGlB,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAmRpB,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,kBAAkB,CAEpB;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,qBAAqB,CAmEvB"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/expressions/validate.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAEV,kBAAkB,EAGlB,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAqTpB,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,kBAAkB,CAEpB;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,qBAAqB,CAyGvB"}
@@ -1,12 +1,15 @@
1
+ import { isProtocolRelativeDateRange } from './relative-dates.js';
1
2
  import { ProtocolIdentifierError, parseProtocolIdentifier, parseProtocolQualifiedIdentifier, } from '../identifiers/index.js';
2
3
  import { CLIENT_TIMEZONE_NAMES } from '../client-contract/timezone-names.js';
3
4
  import { ProtocolValueError, validateCanonicalValue } from '../values/index.js';
4
5
  import { expressionError } from './errors.js';
5
6
  import { resolveExpressionLimits } from './limits.js';
6
7
  import { isProtocolNullCheckOperator } from './null-checks.js';
8
+ import { validateLimitBy, validateOtherBucket, validateQueryCalculations, } from './validate-calculations.js';
7
9
  const BINARY = new Set(['add', 'subtract', 'multiply', 'divide']);
8
10
  const COMPARISONS = new Set([
9
11
  'eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'in', 'notIn', 'between', 'like', 'isNull', 'isNotNull',
12
+ 'inDateRange',
10
13
  ]);
11
14
  const AGGREGATIONS_V1 = new Set([
12
15
  'sum', 'count', 'countDistinct', 'avg', 'min', 'max',
@@ -162,6 +165,10 @@ function validateExpression(input, path, depth, state) {
162
165
  const operator = stringValue(value.operator, `${path}.operator`);
163
166
  if (!COMPARISONS.has(operator))
164
167
  expressionError('HQ_EXPRESSION_INVALID_OPERATOR', `${path}.operator`);
168
+ // RFC 0029: stored definitions must not change meaning with the calendar.
169
+ if (operator === 'inDateRange' && !state.relativeDates) {
170
+ expressionError('HQ_EXPRESSION_INVALID_OPERATOR', `${path}.operator`);
171
+ }
165
172
  if (nullCheck) {
166
173
  return freezeRecord({
167
174
  kind,
@@ -213,6 +220,12 @@ function validateExpression(input, path, depth, state) {
213
220
  }
214
221
  }
215
222
  function validateComparisonOperands(operator, right, path) {
223
+ if (operator === 'inDateRange') {
224
+ if (right.kind !== 'literal' || !isProtocolRelativeDateRange(right.value)) {
225
+ expressionError('HQ_EXPRESSION_INVALID_VALUE', path);
226
+ }
227
+ return;
228
+ }
216
229
  if (operator === 'like') {
217
230
  if (right.kind !== 'literal' || typeof right.value !== 'string') {
218
231
  expressionError('HQ_EXPRESSION_INVALID_VALUE', path);
@@ -253,6 +266,17 @@ function validateAggregate(value, path, depth, state) {
253
266
  expressionError('HQ_EXPRESSION_INVALID_AGGREGATION', `${path}.level`);
254
267
  }
255
268
  const filters = value.filters === undefined ? undefined : arrayValue(value.filters, `${path}.filters`, state);
269
+ // An aggregate's filters are a measure definition, never a relative range (RFC 0029).
270
+ const relativeDates = state.relativeDates;
271
+ state.relativeDates = false;
272
+ try {
273
+ return validatedAggregate(value, path, depth, state, aggregation, isArg, isPercentile, level, filters);
274
+ }
275
+ finally {
276
+ state.relativeDates = relativeDates;
277
+ }
278
+ }
279
+ function validatedAggregate(value, path, depth, state, aggregation, isArg, isPercentile, level, filters) {
256
280
  return freezeRecord({
257
281
  kind: 'aggregate',
258
282
  aggregation,
@@ -269,7 +293,7 @@ function newState(options) {
269
293
  if (extension !== 1 && extension !== 2) {
270
294
  throw new RangeError('extension must be 1 or 2');
271
295
  }
272
- return { limits: resolveExpressionLimits(options), extension, active: new WeakSet(), nodes: 0 };
296
+ return { limits: resolveExpressionLimits(options), extension, active: new WeakSet(), nodes: 0, relativeDates: false };
273
297
  }
274
298
  export function validateProtocolExpression(input, options = {}) {
275
299
  return validateExpression(input, '$', 1, newState(options));
@@ -290,7 +314,11 @@ export function validateProtocolSemanticQuery(input, options = {}) {
290
314
  'filters',
291
315
  ...(v2 ? ['segments'] : []),
292
316
  ...(metric ? [] : ['having']),
293
- 'orderBy', 'limit', 'offset', 'by', 'timezone', 'includeMeta',
317
+ // RFC 0026: query-scoped calculations, extension 2 dataset queries only.
318
+ ...(metric || !v2 ? [] : ['calculations', 'limitBy', 'other']),
319
+ 'orderBy', 'limit', 'offset', 'by', 'timeKey', 'timezone',
320
+ ...(metric ? [] : ['fill']),
321
+ 'includeMeta',
294
322
  ], '$');
295
323
  const result = {
296
324
  kind,
@@ -303,12 +331,30 @@ export function validateProtocolSemanticQuery(input, options = {}) {
303
331
  copyIdentifierArray(value, result, 'measures', v2, state);
304
332
  if (value.filters !== undefined) {
305
333
  const filters = arrayValue(value.filters, '$.filters', state);
306
- result.filters = Object.freeze(filters.map((filter, index) => validatePredicate(filter, `$.filters[${index}]`, 1, state, 'HQ_EXPRESSION_INVALID_QUERY')));
334
+ state.relativeDates = true;
335
+ try {
336
+ result.filters = Object.freeze(filters.map((filter, index) => validatePredicate(filter, `$.filters[${index}]`, 1, state, 'HQ_EXPRESSION_INVALID_QUERY')));
337
+ }
338
+ finally {
339
+ state.relativeDates = false;
340
+ }
307
341
  }
308
342
  if (value.segments !== undefined)
309
343
  result.segments = validateSegments(value.segments, state);
344
+ const calculationShape = {
345
+ dimensions: result.dimensions ?? [],
346
+ measures: result.measures ?? [],
347
+ hasBy: value.by !== undefined,
348
+ };
349
+ const kit = calculationKit(state);
350
+ let outputs = [];
351
+ if (value.calculations !== undefined) {
352
+ const calculations = validateQueryCalculations(kit, value.calculations, calculationShape);
353
+ result.calculations = calculations.entries;
354
+ outputs = calculations.outputs;
355
+ }
310
356
  if (value.having !== undefined) {
311
- result.having = validateHaving(value.having, result.measures, v2, state);
357
+ result.having = validateHaving(value.having, [...(result.measures ?? []), ...outputs], v2, state);
312
358
  }
313
359
  if (value.orderBy !== undefined)
314
360
  result.orderBy = validateOrderBy(value.orderBy, state);
@@ -320,6 +366,9 @@ export function validateProtocolSemanticQuery(input, options = {}) {
320
366
  expressionError('HQ_EXPRESSION_INVALID_QUERY', '$.by');
321
367
  result.by = grain;
322
368
  }
369
+ // RFC 0029: which time axis; the data plane checks it against the contract.
370
+ if (value.timeKey !== undefined)
371
+ result.timeKey = identifier(value.timeKey, '$.timeKey', false);
323
372
  if (value.timezone !== undefined) {
324
373
  const timezone = stringValue(value.timezone, '$.timezone');
325
374
  // RFC 0018's pinned registry, so every implementation accepts the same
@@ -328,6 +377,19 @@ export function validateProtocolSemanticQuery(input, options = {}) {
328
377
  expressionError('HQ_EXPRESSION_INVALID_QUERY', '$.timezone');
329
378
  result.timezone = timezone;
330
379
  }
380
+ if (value.limitBy !== undefined) {
381
+ result.limitBy = validateLimitBy(kit, value.limitBy, calculationShape, (result.orderBy?.length ?? 0) > 0);
382
+ }
383
+ if (value.other !== undefined)
384
+ result.other = validateOtherBucket(kit, value.other, calculationShape, outputs);
385
+ if (value.fill !== undefined) {
386
+ if (typeof value.fill !== 'boolean')
387
+ expressionError('HQ_EXPRESSION_TYPE', '$.fill');
388
+ // RFC 0029: periods to fill exist only under a grain.
389
+ if (value.by === undefined)
390
+ expressionError('HQ_EXPRESSION_INVALID_QUERY', '$.fill');
391
+ result.fill = value.fill;
392
+ }
331
393
  if (value.includeMeta !== undefined) {
332
394
  if (typeof value.includeMeta !== 'boolean')
333
395
  expressionError('HQ_EXPRESSION_INVALID_QUERY', '$.includeMeta');
@@ -339,6 +401,20 @@ export function validateProtocolSemanticQuery(input, options = {}) {
339
401
  state.active.delete(value);
340
402
  }
341
403
  }
404
+ /** The validator primitives RFC 0026's module shares, bound to one state. */
405
+ function calculationKit(state) {
406
+ return {
407
+ requireRecord,
408
+ exactFields,
409
+ stringValue,
410
+ identifier,
411
+ enter: (value, depth, path) => enter(value, depth, state, path),
412
+ leave: value => state.active.delete(value),
413
+ arrayValue: (value, path) => arrayValue(value, path, state),
414
+ freezeRecord,
415
+ predicate: (input, path) => validatePredicate(input, path, 4, state, 'HQ_EXPRESSION_INVALID_QUERY'),
416
+ };
417
+ }
342
418
  function validatePredicate(input, path, depth, state, errorCode) {
343
419
  const expression = validateExpression(input, path, depth, state);
344
420
  if (!isPredicate(expression))
package/dist/index.d.ts CHANGED
@@ -3,10 +3,12 @@ export type { ArrayTaggedValue, BytesTaggedValue, CanonicalValue, CanonicalValue
3
3
  export { PROTOCOL_IDENTIFIER_LIMITS, ProtocolIdentifierError, isProtocolIdentifier, isProtocolQualifiedIdentifier, joinProtocolQualifiedIdentifier, parseProtocolIdentifier, parseProtocolQualifiedIdentifier, splitProtocolQualifiedIdentifier, } from './identifiers/index.js';
4
4
  export { PROTOCOL_CACHE_KEY_LIMITS, ProtocolCacheKeyError, deriveProtocolCacheKey, deriveProtocolCacheNamespaceToken, } from './cache-keys/index.js';
5
5
  export { ProtocolCachePreimageError, buildProtocolCachePreimage, deriveProtocolTenantFingerprint, } from './cache-preimages/index.js';
6
- export { DEFAULT_PROTOCOL_EXPRESSION_LIMITS, PROTOCOL_NULL_CHECK_OPERATORS, ProtocolExpressionError, isProtocolNullCheckOperator, validateProtocolExpression, validateProtocolSemanticQuery, } from './expressions/index.js';
6
+ export { DEFAULT_PROTOCOL_EXPRESSION_LIMITS, PROTOCOL_NULL_CHECK_OPERATORS, PROTOCOL_CALCULATION_KINDS, ProtocolExpressionError, isProtocolNullCheckOperator, isProtocolRelativeDateRange, parseProtocolRelativeDateRange, validateProtocolExpression, validateProtocolSemanticQuery, } from './expressions/index.js';
7
7
  export { DEFAULT_PROTOCOL_SCHEMA_LIMITS, DEFAULT_PROTOCOL_SCHEMA_VALUE_LIMITS, ProtocolSchemaError, ProtocolSchemaValueError, applyProtocolSchemaValue, createProtocolSchemaValueParser, resolveProtocolSchemaValueLimits, validateProtocolSchema, } from './schemas/index.js';
8
8
  export type { ProtocolSchema, ProtocolSchemaErrorCode, ProtocolSchemaLimits, ProtocolSchemaOptions, ProtocolSchemaValueLimits, ProtocolSchemaValueOptions, ProtocolSchemaValueParser, } from './schemas/index.js';
9
- export type { ProtocolAggregation, ProtocolBinaryOperator, ProtocolComparisonOperator, ProtocolDatasetQuery, ProtocolExpression, ProtocolExpressionErrorCode, ProtocolExpressionExtension, ProtocolExpressionLimits, ProtocolExpressionOptions, ProtocolFunctionName, ProtocolMetricQuery, ProtocolNullCheckOperator, ProtocolHavingComparisonOperator, ProtocolHavingCondition, ProtocolOrderBy, ProtocolSemanticQuery, ProtocolQueryTimeGrain, ProtocolTimeGrain, ProtocolValueComparisonOperator, } from './expressions/index.js';
9
+ export type { ProtocolAggregation, ProtocolBinaryOperator, ProtocolComparisonOperator, ProtocolDatasetQuery, ProtocolExpression, ProtocolExpressionErrorCode, ProtocolExpressionExtension, ProtocolExpressionLimits, ProtocolExpressionOptions, ProtocolFunctionName, ProtocolMetricQuery, ProtocolNullCheckOperator, ProtocolHavingComparisonOperator, ProtocolHavingCondition, ProtocolOrderBy, ProtocolSemanticQuery, ProtocolQueryTimeGrain, ProtocolRelativeDateRange, ProtocolRelativeDateUnit, ProtocolTimeGrain, ProtocolValueComparisonOperator, ProtocolCalculationColumn, ProtocolCalculationInterval, ProtocolCalculationKind, ProtocolCompareCalculation, ProtocolFilterCalculation, ProtocolFormulaArgument, ProtocolFormulaNode, ProtocolFormulaOperator, ProtocolLimitBy, ProtocolOtherBucket, ProtocolQueryCalculation, ProtocolRankCalculation, ProtocolShareCalculation, ProtocolShiftCalculation, ProtocolWindowCalculation, } from './expressions/index.js';
10
+ export { PROTOCOL_EVENT_OPERATION_LIMITS, PROTOCOL_FUNNEL_COLUMNS, PROTOCOL_RETENTION_COLUMNS, isProtocolEventOperationKind, isProtocolPredicate, parseProtocolEventWindow, validateProtocolEventOperation, } from './event-operations/index.js';
11
+ export type { ProtocolEventCohortGrain, ProtocolEventOperation, ProtocolEventOperationKind, ProtocolEventWindow, ProtocolEventWindowUnit, ProtocolFunnelOperation, ProtocolFunnelStep, ProtocolRetentionCondition, ProtocolRetentionOperation, } from './event-operations/index.js';
10
12
  export type { DeriveProtocolCacheKeyOptions, ProtocolCacheKeyErrorCode, ProtocolCacheKeyNamespace, } from './cache-keys/index.js';
11
13
  export type { BuildProtocolCachePreimageOptions, ProtocolCachePreimageErrorCode, ProtocolCacheTenantScope, } from './cache-preimages/index.js';
12
14
  export type { ProtocolIdentifier, ProtocolIdentifierErrorCode, ProtocolQualifiedIdentifier, } from './identifiers/index.js';
@@ -14,20 +16,23 @@ export { DEFAULT_PROTOCOL_QUERY_IMPLEMENTATION_LIMITS, ProtocolQueryImplementati
14
16
  export { DEFAULT_PROTOCOL_QUERY_EVENT_LIMITS, ProtocolQueryDiagnosticsError, ProtocolQueryEventError, validateProtocolQueryDiagnostics, validateProtocolQueryEvent, } from './events/index.js';
15
17
  export type { ProtocolQueryDiagnostics, ProtocolQueryDiagnosticsErrorCode, ProtocolQueryErrorCategory, ProtocolQueryEvent, ProtocolQueryEventErrorCode, ProtocolQueryEventLimits, ProtocolQueryEventOptions, ProtocolQueryEventOutcome, ProtocolQueryEventTarget, ProtocolQueryOperation, ProtocolQueryTerminalReason, } from './events/index.js';
16
18
  export { DEFAULT_PROTOCOL_SEMANTIC_INVOCATION_LIMITS, ProtocolSemanticInvocationError, validateProtocolSemanticInvocation, validateProtocolSemanticInvocationFailure, validateProtocolSemanticInvocationResult, validateProtocolSemanticInvocationV2, } from './invocations/index.js';
17
- export type { ProtocolSemanticInvocation, ProtocolSemanticInvocationV2, ProtocolSemanticInvocationBudget, ProtocolSemanticInvocationErrorCode, ProtocolSemanticInvocationFailure, ProtocolSemanticInvocationFailureCategory, ProtocolSemanticInvocationLimits, ProtocolSemanticInvocationMeta, ProtocolSemanticInvocationOptions, ProtocolSemanticInvocationPagination, ProtocolSemanticInvocationResult, ProtocolSemanticInvocationRow, ProtocolSemanticInvocationTarget, ProtocolSemanticInvocationValue, } from './invocations/index.js';
19
+ export type { ProtocolSemanticInvocation, ProtocolSemanticInvocationV2, ProtocolSemanticInvocationBudget, ProtocolSemanticInvocationErrorCode, ProtocolSemanticInvocationFailure, ProtocolSemanticInvocationFailureCategory, ProtocolSemanticInvocationLimits, ProtocolSemanticInvocationMeta, ProtocolSemanticInvocationOperation, ProtocolSemanticInvocationOptions, ProtocolSemanticInvocationPagination, ProtocolSemanticInvocationResult, ProtocolSemanticInvocationRow, ProtocolSemanticInvocationTarget, ProtocolSemanticInvocationValue, } from './invocations/index.js';
18
20
  export { DEFAULT_PROTOCOL_DEPLOYMENT_BUNDLE_LIMITS, PROTOCOL_DEPLOYMENT_BUNDLE_IDENTITY_DOMAIN, ProtocolDeploymentBundleError, encodeProtocolDeploymentBundleManifest, encodeProtocolDeploymentBundleManifestToString, hashProtocolDeploymentBundleManifest, prepareProtocolDeploymentBundleManifest, validateProtocolDeploymentBundleManifest, } from './bundles/index.js';
19
21
  export { DEFAULT_PROTOCOL_BUSINESS_CONTEXT_LIMITS, PROTOCOL_BUSINESS_CONTEXT_IDENTITY_DOMAIN, ProtocolBusinessContextError, encodeProtocolBusinessContext, encodeProtocolBusinessContextToString, hashProtocolBusinessContext, isEmptyProtocolBusinessContext, prepareProtocolBusinessContext, validateProtocolBusinessContext, } from './business-context/index.js';
20
22
  export type { PreparedProtocolBusinessContext, ProtocolBusinessContext, ProtocolBusinessContextErrorCode, ProtocolBusinessContextGlossaryTerm, ProtocolBusinessContextKpi, ProtocolBusinessContextLimits, ProtocolBusinessContextOptions, } from './business-context/index.js';
21
23
  export { DEFAULT_PROTOCOL_DEPLOYMENT_RELEASE_LIMITS, PROTOCOL_DEPLOYMENT_RELEASE_IDENTITY_DOMAIN, ProtocolDeploymentReleaseError, encodeProtocolDeploymentReleaseEnvelope, encodeProtocolDeploymentReleaseEnvelopeToString, hashProtocolDeploymentReleaseEnvelope, prepareProtocolDeploymentReleaseEnvelope, validateProtocolDeploymentReleaseEnvelope, validateProtocolDeploymentReleaseTarget, } from './releases/index.js';
22
24
  export type { PreparedProtocolDeploymentReleaseEnvelope, ProtocolDeploymentReleaseEnvelope, ProtocolDeploymentReleaseErrorCode, ProtocolDeploymentReleaseLimits, ProtocolDeploymentReleaseOptions, ProtocolDeploymentReleaseTarget, } from './releases/index.js';
23
25
  export type { PreparedProtocolDeploymentBundleManifest, ProtocolDeploymentBundleArtifact, ProtocolDeploymentBundleBusinessContext, ProtocolDeploymentBundleDeployment, ProtocolDeploymentBundleErrorCode, ProtocolDeploymentBundleFile, ProtocolDeploymentBundleLimits, ProtocolDeploymentBundleManifest, ProtocolDeploymentBundleOptions, } from './bundles/index.js';
24
- export { DEFAULT_PROTOCOL_DEPLOYMENT_LIMITS, PROTOCOL_DEPLOYMENT_IDENTITY_DOMAIN, PROTOCOL_DEPLOYMENT_V3_IDENTITY_DOMAIN, ProtocolDeploymentError, checkProtocolDatasetContract, checkProtocolDeploymentContract, checkProtocolDeploymentContractV3, encodeProtocolDeploymentContract, encodeProtocolDeploymentContractToString, hashProtocolDeploymentContract, prepareProtocolDeploymentContract, prepareProtocolDeploymentContractV3, validateProtocolDatasetContract, validateProtocolDeploymentContract, validateProtocolDeploymentContractV3, } from './deployments/index.js';
25
- export type { ProtocolDatasetDerivedMeasure, ProtocolDeploymentDataset, ProtocolDeploymentMeasure, PreparedProtocolDeploymentContract, PreparedProtocolDeploymentContractV3, ProtocolAccessPolicy, ProtocolDatasetContract, ProtocolRowResolution, ProtocolDatasetDefaults, ProtocolDatasetDimension, ProtocolDatasetFieldSource, ProtocolDatasetFieldType, ProtocolDatasetFilter, ProtocolDatasetFreshness, ProtocolDatasetLimits, ProtocolDatasetMeasure, ProtocolDatasetMetric, ProtocolDatasetRelationship, ProtocolDatasetTenantPolicy, ProtocolSemanticMetadata, ProtocolSemanticSensitivity, ProtocolDeploymentContract, ProtocolDeploymentContractV3, ProtocolDeploymentDatasetV3, ProtocolDeploymentMeasureV3, ProtocolDatasetDerivedMeasureV3, ProtocolDatasetMeasureV3, ProtocolDatasetSegment, ProtocolDatasetShiftMeasure, ProtocolDatasetWindowMeasure, ProtocolTimeInterval, ProtocolDeploymentCheckResult, ProtocolDeploymentErrorCode, ProtocolDeploymentValidationError, ProtocolDeploymentLimits, ProtocolDeploymentOptions, ProtocolEndpointPolicy, ProtocolEndpointTenantPolicy, ProtocolMetricDerivation, ProtocolMetricInput, } from './deployments/index.js';
26
+ export { DEFAULT_PROTOCOL_DEPLOYMENT_LIMITS, PROTOCOL_DEPLOYMENT_IDENTITY_DOMAIN, PROTOCOL_DEPLOYMENT_V3_IDENTITY_DOMAIN, ProtocolDeploymentError, checkProtocolDatasetContract, checkProtocolDeploymentContract, checkProtocolDeploymentContractV3, encodeProtocolDeploymentContract, encodeProtocolDeploymentContractToString, hashProtocolDeploymentContract, prepareProtocolDeploymentContract, prepareProtocolDeploymentContractAnyVersion, prepareProtocolDeploymentContractV3, validateProtocolDatasetContract, validateProtocolDeploymentContract, validateProtocolDeploymentContractAnyVersion, validateProtocolDeploymentContractAtLowestVersion, validateProtocolDeploymentContractV3, } from './deployments/index.js';
27
+ export type { ProtocolDatasetDerivedMeasure, ProtocolDeploymentDataset, ProtocolDeploymentMeasure, PreparedProtocolDeploymentContract, PreparedProtocolDeploymentContractAnyVersion, PreparedProtocolDeploymentContractV3, ProtocolAccessPolicy, ProtocolDatasetContract, ProtocolRowResolution, ProtocolDatasetEvents, ProtocolDatasetSource, ProtocolSqlSource, ProtocolSqlSourceColumn, ProtocolDatasetDefaults, ProtocolDatasetDimension, ProtocolDatasetFieldSource, ProtocolDatasetFieldType, ProtocolDatasetFilter, ProtocolDatasetFreshness, ProtocolDatasetLimits, ProtocolDatasetMeasure, ProtocolDatasetMetric, ProtocolDatasetRelationship, ProtocolDatasetTenantPolicy, ProtocolSemanticMetadata, ProtocolSemanticSensitivity, ProtocolDeploymentContract, ProtocolDeploymentContractV3, ProtocolDeploymentContractAnyVersion, ProtocolDeploymentDatasetAnyVersion, ProtocolDeploymentDatasetV3, ProtocolDeploymentMeasureV3, ProtocolDatasetDerivedMeasureV3, ProtocolDatasetMeasureV3, ProtocolDatasetSegment, ProtocolDatasetShiftMeasure, ProtocolDatasetWindowMeasure, ProtocolTimeInterval, ProtocolDeploymentCheckResult, ProtocolDeploymentErrorCode, ProtocolDeploymentValidationError, ProtocolDeploymentLimits, ProtocolDeploymentOptions, ProtocolEndpointPolicy, ProtocolEndpointTenantPolicy, ProtocolMetricDerivation, ProtocolMetricInput, } from './deployments/index.js';
26
28
  export type { ProtocolQueryImplementation, ProtocolQueryImplementationErrorCode, ProtocolQueryImplementationLimits, ProtocolQueryImplementationOptions, ProtocolSqlDialect, ProtocolSqlExpression, ProtocolSqlParameter, ProtocolSqlParameterSource, ProtocolSqlTenantPolicy, } from './query-implementations/index.js';
27
29
  export { PROTOCOL_SEMANTIC_FAILURE_MESSAGES } from './invocations/failure-messages.js';
28
30
  export * from './client-contract/index.js';
29
31
  export { PROTOCOL_FIELD_VISIBILITY_LIMITS, ProtocolFieldVisibilityError, resolveProtocolVisibleDatasetFields, validateProtocolFieldVisibility, } from './visibility/index.js';
30
32
  export type { ProtocolDatasetVisibility, ProtocolFieldVisibility, ProtocolFieldVisibilityErrorCode, ProtocolVisibleDatasetFields, ProtocolVisibleFields, } from './visibility/index.js';
31
33
  export { validateProtocolRowResolution } from './deployments/row-resolution.js';
34
+ export { validateProtocolDatasetEvents } from './deployments/events.js';
35
+ export { isProtocolSqlSource, validateProtocolSqlSource } from './deployments/sql-source.js';
36
+ export { PROTOCOL_SQL_SOURCE_MAX_BYTES, PROTOCOL_SQL_SOURCE_MAX_DEPENDENCIES, analyzeProtocolSqlSource, type ProtocolSqlSourceAnalysis, type ProtocolSqlSourceRefusal, } from './deployments/sql-source-analysis.js';
32
37
  export { PROTOCOL_AGGREGATE_STATE_FUNCTIONS, PROTOCOL_APPROXIMATE_STATE_FUNCTIONS, isApproximateStateFunction, isProtocolAggregateStateFunction, type ProtocolAggregateStateFunction, } from './deployments/aggregate-states.js';
33
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,sBAAsB,EACtB,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