@hypequery/protocol 0.27.0 → 0.30.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 (94) 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/deployment-targets/acceptance.d.ts +41 -0
  4. package/dist/deployment-targets/acceptance.d.ts.map +1 -0
  5. package/dist/deployment-targets/acceptance.js +48 -0
  6. package/dist/deployment-targets/accepts.d.ts +26 -0
  7. package/dist/deployment-targets/accepts.d.ts.map +1 -0
  8. package/dist/deployment-targets/accepts.js +67 -0
  9. package/dist/deployment-targets/index.d.ts +5 -0
  10. package/dist/deployment-targets/index.d.ts.map +1 -0
  11. package/dist/deployment-targets/index.js +2 -0
  12. package/dist/deployments/codec.d.ts +8 -0
  13. package/dist/deployments/codec.d.ts.map +1 -1
  14. package/dist/deployments/codec.js +11 -1
  15. package/dist/deployments/contract-3-features.d.ts +16 -0
  16. package/dist/deployments/contract-3-features.d.ts.map +1 -0
  17. package/dist/deployments/contract-3-features.js +28 -0
  18. package/dist/deployments/events.d.ts +10 -0
  19. package/dist/deployments/events.d.ts.map +1 -0
  20. package/dist/deployments/events.js +59 -0
  21. package/dist/deployments/index.d.ts +12 -4
  22. package/dist/deployments/index.d.ts.map +1 -1
  23. package/dist/deployments/index.js +7 -2
  24. package/dist/deployments/readers.d.ts +39 -0
  25. package/dist/deployments/readers.d.ts.map +1 -0
  26. package/dist/deployments/readers.js +59 -0
  27. package/dist/deployments/sql-source-analysis.d.ts +29 -0
  28. package/dist/deployments/sql-source-analysis.d.ts.map +1 -0
  29. package/dist/deployments/sql-source-analysis.js +264 -0
  30. package/dist/deployments/sql-source.d.ts +8 -0
  31. package/dist/deployments/sql-source.d.ts.map +1 -0
  32. package/dist/deployments/sql-source.js +107 -0
  33. package/dist/deployments/types.d.ts +41 -1
  34. package/dist/deployments/types.d.ts.map +1 -1
  35. package/dist/deployments/validate.d.ts +19 -0
  36. package/dist/deployments/validate.d.ts.map +1 -1
  37. package/dist/deployments/validate.js +163 -9
  38. package/dist/event-operations/index.d.ts +6 -0
  39. package/dist/event-operations/index.d.ts.map +1 -0
  40. package/dist/event-operations/index.js +4 -0
  41. package/dist/event-operations/limits.d.ts +17 -0
  42. package/dist/event-operations/limits.d.ts.map +1 -0
  43. package/dist/event-operations/limits.js +21 -0
  44. package/dist/event-operations/predicates.d.ts +4 -0
  45. package/dist/event-operations/predicates.d.ts.map +1 -0
  46. package/dist/event-operations/predicates.js +10 -0
  47. package/dist/event-operations/records.d.ts +9 -0
  48. package/dist/event-operations/records.d.ts.map +1 -0
  49. package/dist/event-operations/records.js +55 -0
  50. package/dist/event-operations/types.d.ts +69 -0
  51. package/dist/event-operations/types.d.ts.map +1 -0
  52. package/dist/event-operations/types.js +1 -0
  53. package/dist/event-operations/validate.d.ts +11 -0
  54. package/dist/event-operations/validate.d.ts.map +1 -0
  55. package/dist/event-operations/validate.js +220 -0
  56. package/dist/event-operations/window.d.ts +8 -0
  57. package/dist/event-operations/window.d.ts.map +1 -0
  58. package/dist/event-operations/window.js +23 -0
  59. package/dist/expressions/calculations.d.ts +103 -0
  60. package/dist/expressions/calculations.d.ts.map +1 -0
  61. package/dist/expressions/calculations.js +9 -0
  62. package/dist/expressions/index.d.ts +3 -0
  63. package/dist/expressions/index.d.ts.map +1 -1
  64. package/dist/expressions/index.js +2 -0
  65. package/dist/expressions/relative-dates.d.ts +31 -0
  66. package/dist/expressions/relative-dates.d.ts.map +1 -0
  67. package/dist/expressions/relative-dates.js +38 -0
  68. package/dist/expressions/types.d.ts +24 -1
  69. package/dist/expressions/types.d.ts.map +1 -1
  70. package/dist/expressions/validate-calculations.d.ts +41 -0
  71. package/dist/expressions/validate-calculations.d.ts.map +1 -0
  72. package/dist/expressions/validate-calculations.js +397 -0
  73. package/dist/expressions/validate.d.ts.map +1 -1
  74. package/dist/expressions/validate.js +80 -4
  75. package/dist/index.d.ts +13 -6
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +10 -3
  78. package/dist/invocations/index.d.ts +5 -2
  79. package/dist/invocations/index.d.ts.map +1 -1
  80. package/dist/invocations/index.js +2 -1
  81. package/dist/invocations/types.d.ts +13 -3
  82. package/dist/invocations/types.d.ts.map +1 -1
  83. package/dist/invocations/validate.d.ts +14 -1
  84. package/dist/invocations/validate.d.ts.map +1 -1
  85. package/dist/invocations/validate.js +75 -7
  86. package/dist/invocations/version.d.ts +23 -0
  87. package/dist/invocations/version.d.ts.map +1 -0
  88. package/dist/invocations/version.js +37 -0
  89. package/dist/visibility/resolve.d.ts +4 -4
  90. package/dist/visibility/resolve.d.ts.map +1 -1
  91. package/dist/visibility/resolve.js +10 -4
  92. package/dist/visibility/types.d.ts +6 -0
  93. package/dist/visibility/types.d.ts.map +1 -1
  94. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"cache-preimages.d.ts","sourceRoot":"","sources":["../../src/cache-preimages/cache-preimages.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,iCAAiC,EACjC,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAQpB,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,IAAI,EAAE,8BAA8B,CAAC;gBAElC,IAAI,EAAE,8BAA8B;CAOjD;AAwBD;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5F;AA0ED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,iCAAiC,GAAG,MAAM,CAmB7F"}
1
+ {"version":3,"file":"cache-preimages.d.ts","sourceRoot":"","sources":["../../src/cache-preimages/cache-preimages.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iCAAiC,EACjC,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAQpB,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,IAAI,EAAE,8BAA8B,CAAC;gBAElC,IAAI,EAAE,8BAA8B;CAOjD;AAwBD;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5F;AA6FD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,iCAAiC,GAAG,MAAM,CAmB7F"}
@@ -58,6 +58,15 @@ function compareUtf8(left, right) {
58
58
  }
59
59
  return a.byteLength - b.byteLength;
60
60
  }
61
+ function usesRelativeDateRange(expression) {
62
+ if (expression.kind === 'comparison')
63
+ return expression.operator === 'inDateRange';
64
+ if (expression.kind !== 'logical')
65
+ return false;
66
+ return expression.operator === 'not'
67
+ ? usesRelativeDateRange(expression.operand)
68
+ : expression.operands.some(usesRelativeDateRange);
69
+ }
61
70
  function normalizeQuery(source) {
62
71
  let query;
63
72
  try {
@@ -75,6 +84,19 @@ function normalizeQuery(source) {
75
84
  fail('HQ_CACHE_PREIMAGE_INVALID_QUERY');
76
85
  if (query.timezone !== undefined && query.timezone !== 'UTC')
77
86
  fail('HQ_CACHE_PREIMAGE_INVALID_QUERY');
87
+ // RFC 0026: calculations, limitBy and other have no portable key either.
88
+ if (query.kind === 'dataset' && ((query.calculations?.length ?? 0) > 0 || query.limitBy !== undefined || query.other !== undefined))
89
+ fail('HQ_CACHE_PREIMAGE_INVALID_QUERY');
90
+ // RFC 0029: a relative range means a different query every day, and a
91
+ // filled series has rows the preimage can't describe. Neither has a
92
+ // portable key; `fill: false` is the default and is dropped below.
93
+ if ((query.filters ?? []).some(usesRelativeDateRange))
94
+ fail('HQ_CACHE_PREIMAGE_INVALID_QUERY');
95
+ if (query.kind === 'dataset' && query.fill === true)
96
+ fail('HQ_CACHE_PREIMAGE_INVALID_QUERY');
97
+ // Without the contract a key equal to `timeField` can't be told from another.
98
+ if (query.timeKey !== undefined)
99
+ fail('HQ_CACHE_PREIMAGE_INVALID_QUERY');
78
100
  // AND-combined, so order cannot change rows; identical filters collapse.
79
101
  const filters = new Map();
80
102
  for (const filter of query.filters ?? [])
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Whether a deployment target accepts a built deployment (RFC 0030).
3
+ *
4
+ * Producers select versions from content and never lower them to fit a
5
+ * target. This check only reports a mismatch, with what forced the version,
6
+ * so the producer can refuse before upload and say why.
7
+ */
8
+ import { type ProtocolContract3Feature } from '../deployments/contract-3-features.js';
9
+ import type { ProtocolDeploymentContractAnyVersion } from '../deployments/types.js';
10
+ import type { ProtocolDeploymentTargetAccepts } from './accepts.js';
11
+ /** How RFC 0030 words each contract 3 feature in a refusal. */
12
+ export declare const PROTOCOL_CONTRACT_3_FEATURE_LABELS: Readonly<Record<ProtocolContract3Feature, string>>;
13
+ export interface ProtocolDatasetContract3Features {
14
+ readonly dataset: string;
15
+ readonly features: readonly ProtocolContract3Feature[];
16
+ }
17
+ /** The datasets of `contract` that force contract 3, each with its features, in contract order. */
18
+ export declare function deploymentContract3Features(contract: ProtocolDeploymentContractAnyVersion): readonly ProtocolDatasetContract3Features[];
19
+ export type ProtocolDeploymentTargetRefusal = {
20
+ readonly kind: 'deploymentContract';
21
+ readonly version: number;
22
+ readonly accepted: readonly number[];
23
+ /** The datasets whose features forced `version`; empty for contract 2. */
24
+ readonly forcedBy: readonly ProtocolDatasetContract3Features[];
25
+ } | {
26
+ readonly kind: 'bundle';
27
+ readonly version: number;
28
+ readonly accepted: readonly number[];
29
+ };
30
+ export interface ProtocolDeploymentTargetAcceptanceInput {
31
+ readonly contract: ProtocolDeploymentContractAnyVersion;
32
+ /** The bundle manifest version; omit to check the contract only. */
33
+ readonly bundleVersion?: number;
34
+ readonly accepts: ProtocolDeploymentTargetAccepts;
35
+ }
36
+ /**
37
+ * Everything about a built deployment that `accepts` refuses: its contract
38
+ * version, then its bundle manifest version. Empty when the target accepts it.
39
+ */
40
+ export declare function checkProtocolDeploymentTargetAcceptance(input: ProtocolDeploymentTargetAcceptanceInput): readonly ProtocolDeploymentTargetRefusal[];
41
+ //# sourceMappingURL=acceptance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acceptance.d.ts","sourceRoot":"","sources":["../../src/deployment-targets/acceptance.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAA4B,KAAK,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AAChH,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAEpE,+DAA+D;AAC/D,eAAO,MAAM,kCAAkC,EAAE,QAAQ,CAAC,MAAM,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAOhG,CAAC;AAEH,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,wBAAwB,EAAE,CAAC;CACxD;AAED,mGAAmG;AACnG,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,oCAAoC,GAC7C,SAAS,gCAAgC,EAAE,CAK7C;AAED,MAAM,MAAM,+BAA+B,GACvC;IACA,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,EAAE,SAAS,gCAAgC,EAAE,CAAC;CAChE,GACC;IACA,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC,CAAC;AAEJ,MAAM,WAAW,uCAAuC;IACtD,QAAQ,CAAC,QAAQ,EAAE,oCAAoC,CAAC;IACxD,oEAAoE;IACpE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,+BAA+B,CAAC;CACnD;AAED;;;GAGG;AACH,wBAAgB,uCAAuC,CACrD,KAAK,EAAE,uCAAuC,GAC7C,SAAS,+BAA+B,EAAE,CAmB5C"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Whether a deployment target accepts a built deployment (RFC 0030).
3
+ *
4
+ * Producers select versions from content and never lower them to fit a
5
+ * target. This check only reports a mismatch, with what forced the version,
6
+ * so the producer can refuse before upload and say why.
7
+ */
8
+ import { datasetContract3Features } from '../deployments/contract-3-features.js';
9
+ /** How RFC 0030 words each contract 3 feature in a refusal. */
10
+ export const PROTOCOL_CONTRACT_3_FEATURE_LABELS = Object.freeze({
11
+ segments: 'segments',
12
+ windowMeasures: 'window measures',
13
+ shiftMeasures: 'shift measures',
14
+ approxCountDistinct: 'approxCountDistinct',
15
+ subDayDefaultGrain: 'a sub-day default grain',
16
+ alternateTimeFields: 'alternate time keys',
17
+ });
18
+ /** The datasets of `contract` that force contract 3, each with its features, in contract order. */
19
+ export function deploymentContract3Features(contract) {
20
+ return Object.freeze(contract.datasets.flatMap(dataset => {
21
+ const features = datasetContract3Features(dataset);
22
+ return features.length > 0 ? [Object.freeze({ dataset: String(dataset.name), features })] : [];
23
+ }));
24
+ }
25
+ /**
26
+ * Everything about a built deployment that `accepts` refuses: its contract
27
+ * version, then its bundle manifest version. Empty when the target accepts it.
28
+ */
29
+ export function checkProtocolDeploymentTargetAcceptance(input) {
30
+ const refusals = [];
31
+ const contractVersion = input.contract.version;
32
+ if (!input.accepts.deploymentContract.includes(contractVersion)) {
33
+ refusals.push(Object.freeze({
34
+ kind: 'deploymentContract',
35
+ version: contractVersion,
36
+ accepted: input.accepts.deploymentContract,
37
+ forcedBy: deploymentContract3Features(input.contract),
38
+ }));
39
+ }
40
+ if (input.bundleVersion !== undefined && !input.accepts.bundle.includes(input.bundleVersion)) {
41
+ refusals.push(Object.freeze({
42
+ kind: 'bundle',
43
+ version: input.bundleVersion,
44
+ accepted: input.accepts.bundle,
45
+ }));
46
+ }
47
+ return Object.freeze(refusals);
48
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A deployment target's capability advertisement (RFC 0030): the deployment
3
+ * contract, semantic invocation and bundle manifest versions it accepts.
4
+ */
5
+ export interface ProtocolDeploymentTargetAccepts {
6
+ /** Deployment contract versions the target stores, activates and serves. */
7
+ readonly deploymentContract: readonly number[];
8
+ /** Semantic invocation versions its data plane runs, against every accepted contract. */
9
+ readonly semanticInvocation: readonly number[];
10
+ /** Deployment bundle manifest versions its intake accepts. */
11
+ readonly bundle: readonly number[];
12
+ }
13
+ /**
14
+ * What a target that advertises nothing accepts: the versions every hypequery
15
+ * Cloud release has served. Each absent member takes its default on its own.
16
+ */
17
+ export declare const DEFAULT_PROTOCOL_DEPLOYMENT_TARGET_ACCEPTS: ProtocolDeploymentTargetAccepts;
18
+ /**
19
+ * Validate a target's `accepts` advertisement and fill each absent member with
20
+ * its default. `undefined` (no advertisement) is the default advertisement.
21
+ * Unknown members are ignored, so a later RFC can add one. Every present
22
+ * member must be a non-empty, ascending list of distinct positive safe
23
+ * integers; anything else throws `ProtocolDeploymentError` at its path.
24
+ */
25
+ export declare function validateProtocolDeploymentTargetAccepts(input: unknown): ProtocolDeploymentTargetAccepts;
26
+ //# sourceMappingURL=accepts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accepts.d.ts","sourceRoot":"","sources":["../../src/deployment-targets/accepts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,+BAA+B;IAC9C,4EAA4E;IAC5E,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C,yFAAyF;IACzF,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED;;;GAGG;AACH,eAAO,MAAM,0CAA0C,EAAE,+BAIvD,CAAC;AAuBH;;;;;;GAMG;AACH,wBAAgB,uCAAuC,CAAC,KAAK,EAAE,OAAO,GAAG,+BAA+B,CAgBvG"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * A deployment target's capability advertisement (RFC 0030): the deployment
3
+ * contract, semantic invocation and bundle manifest versions it accepts.
4
+ */
5
+ import { deploymentError } from '../deployments/errors.js';
6
+ /**
7
+ * What a target that advertises nothing accepts: the versions every hypequery
8
+ * Cloud release has served. Each absent member takes its default on its own.
9
+ */
10
+ export const DEFAULT_PROTOCOL_DEPLOYMENT_TARGET_ACCEPTS = Object.freeze({
11
+ deploymentContract: Object.freeze([2]),
12
+ semanticInvocation: Object.freeze([1]),
13
+ bundle: Object.freeze([1, 2]),
14
+ });
15
+ const MEMBERS = ['deploymentContract', 'semanticInvocation', 'bundle'];
16
+ /** Far above any version this protocol will define; bounds hostile input. */
17
+ const MAX_VERSIONS = 64;
18
+ function versions(input, path) {
19
+ if (!Array.isArray(input))
20
+ deploymentError('HQ_DEPLOYMENT_TYPE', path);
21
+ if (input.length === 0 || input.length > MAX_VERSIONS)
22
+ deploymentError('HQ_DEPLOYMENT_INVALID_VALUE', path);
23
+ const result = [];
24
+ for (let index = 0; index < input.length; index += 1) {
25
+ const descriptor = Object.getOwnPropertyDescriptor(input, index);
26
+ if (descriptor === undefined || !('value' in descriptor))
27
+ deploymentError('HQ_DEPLOYMENT_UNSAFE_OBJECT', `${path}[${index}]`);
28
+ const value = descriptor.value;
29
+ if (typeof value !== 'number')
30
+ deploymentError('HQ_DEPLOYMENT_TYPE', `${path}[${index}]`);
31
+ if (!Number.isSafeInteger(value) || value < 1)
32
+ deploymentError('HQ_DEPLOYMENT_INVALID_VALUE', `${path}[${index}]`);
33
+ // Ascending and distinct, so one advertisement has one encoding.
34
+ if (index > 0 && value <= result[index - 1])
35
+ deploymentError('HQ_DEPLOYMENT_INVALID_VALUE', `${path}[${index}]`);
36
+ result.push(value);
37
+ }
38
+ return Object.freeze(result);
39
+ }
40
+ /**
41
+ * Validate a target's `accepts` advertisement and fill each absent member with
42
+ * its default. `undefined` (no advertisement) is the default advertisement.
43
+ * Unknown members are ignored, so a later RFC can add one. Every present
44
+ * member must be a non-empty, ascending list of distinct positive safe
45
+ * integers; anything else throws `ProtocolDeploymentError` at its path.
46
+ */
47
+ export function validateProtocolDeploymentTargetAccepts(input) {
48
+ if (input === undefined)
49
+ return DEFAULT_PROTOCOL_DEPLOYMENT_TARGET_ACCEPTS;
50
+ if (typeof input !== 'object' || input === null || Array.isArray(input))
51
+ deploymentError('HQ_DEPLOYMENT_TYPE', '$');
52
+ const prototype = Object.getPrototypeOf(input);
53
+ if (prototype !== Object.prototype && prototype !== null)
54
+ deploymentError('HQ_DEPLOYMENT_UNSAFE_OBJECT', '$');
55
+ const result = {};
56
+ for (const member of MEMBERS) {
57
+ const descriptor = Object.getOwnPropertyDescriptor(input, member);
58
+ if (descriptor === undefined) {
59
+ result[member] = DEFAULT_PROTOCOL_DEPLOYMENT_TARGET_ACCEPTS[member];
60
+ continue;
61
+ }
62
+ if (!('value' in descriptor))
63
+ deploymentError('HQ_DEPLOYMENT_UNSAFE_OBJECT', `$.${member}`);
64
+ result[member] = versions(descriptor.value, `$.${member}`);
65
+ }
66
+ return Object.freeze(result);
67
+ }
@@ -0,0 +1,5 @@
1
+ export { DEFAULT_PROTOCOL_DEPLOYMENT_TARGET_ACCEPTS, validateProtocolDeploymentTargetAccepts, } from './accepts.js';
2
+ export type { ProtocolDeploymentTargetAccepts } from './accepts.js';
3
+ export { PROTOCOL_CONTRACT_3_FEATURE_LABELS, checkProtocolDeploymentTargetAcceptance, deploymentContract3Features, } from './acceptance.js';
4
+ export type { ProtocolDatasetContract3Features, ProtocolDeploymentTargetAcceptanceInput, ProtocolDeploymentTargetRefusal, } from './acceptance.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/deployment-targets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0CAA0C,EAC1C,uCAAuC,GACxC,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,kCAAkC,EAClC,uCAAuC,EACvC,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,gCAAgC,EAChC,uCAAuC,EACvC,+BAA+B,GAChC,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { DEFAULT_PROTOCOL_DEPLOYMENT_TARGET_ACCEPTS, validateProtocolDeploymentTargetAccepts, } from './accepts.js';
2
+ export { PROTOCOL_CONTRACT_3_FEATURE_LABELS, checkProtocolDeploymentTargetAcceptance, deploymentContract3Features, } from './acceptance.js';
@@ -14,6 +14,14 @@ export interface PreparedProtocolDeploymentContractV3 extends Omit<PreparedProto
14
14
  export declare function prepareProtocolDeploymentContract(input: unknown, options?: ProtocolDeploymentOptions): PreparedProtocolDeploymentContract;
15
15
  /** Validates, canonically encodes, and identifies a deployment contract 3. */
16
16
  export declare function prepareProtocolDeploymentContractV3(input: unknown, options?: ProtocolDeploymentOptions): PreparedProtocolDeploymentContractV3;
17
+ /** A prepared deployment contract of any version this package reads. */
18
+ export type PreparedProtocolDeploymentContractAnyVersion = PreparedProtocolDeploymentContract | PreparedProtocolDeploymentContractV3;
19
+ /**
20
+ * Validates, canonically encodes, and identifies a deployment contract 2 or 3,
21
+ * selected by its `version`. Each version keeps its own identity domain, so a
22
+ * contract 2 artifact keeps the identity it had before contract 3 existed.
23
+ */
24
+ export declare function prepareProtocolDeploymentContractAnyVersion(input: unknown, options?: ProtocolDeploymentOptions): PreparedProtocolDeploymentContractAnyVersion;
17
25
  export declare function encodeProtocolDeploymentContract(input: unknown, options?: ProtocolDeploymentOptions): Uint8Array;
18
26
  export declare function hashProtocolDeploymentContract(input: unknown, options?: ProtocolDeploymentOptions): string;
19
27
  export declare function encodeProtocolDeploymentContractToString(input: unknown, options?: ProtocolDeploymentOptions): string;
@@ -1 +1 @@
1
- {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/deployments/codec.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAKpB,eAAO,MAAM,mCAAmC,8BAA8B,CAAC;AAC/E,4DAA4D;AAC5D,eAAO,MAAM,sCAAsC,8BAA8B,CAAC;AAElF,MAAM,WAAW,kCAAkC;IACjD,QAAQ,CAAC,QAAQ,EAAE,0BAA0B,CAAC;IAC9C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,oCACf,SAAQ,IAAI,CAAC,kCAAkC,EAAE,UAAU,CAAC;IAC5D,QAAQ,CAAC,QAAQ,EAAE,4BAA4B,CAAC;CACjD;AAYD,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,kCAAkC,CAEpC;AAED,8EAA8E;AAC9E,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,oCAAoC,CAEtC;AAED,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,UAAU,CAEZ;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAER;AAED,wBAAgB,wCAAwC,CACtD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAER"}
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/deployments/codec.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAKpB,eAAO,MAAM,mCAAmC,8BAA8B,CAAC;AAC/E,4DAA4D;AAC5D,eAAO,MAAM,sCAAsC,8BAA8B,CAAC;AAElF,MAAM,WAAW,kCAAkC;IACjD,QAAQ,CAAC,QAAQ,EAAE,0BAA0B,CAAC;IAC9C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,oCACf,SAAQ,IAAI,CAAC,kCAAkC,EAAE,UAAU,CAAC;IAC5D,QAAQ,CAAC,QAAQ,EAAE,4BAA4B,CAAC;CACjD;AAYD,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,kCAAkC,CAEpC;AAED,8EAA8E;AAC9E,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,oCAAoC,CAEtC;AAED,wEAAwE;AACxE,MAAM,MAAM,4CAA4C,GACpD,kCAAkC,GAClC,oCAAoC,CAAC;AAEzC;;;;GAIG;AACH,wBAAgB,2CAA2C,CACzD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,4CAA4C,CAI9C;AAED,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,UAAU,CAEZ;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAER;AAED,wBAAgB,wCAAwC,CACtD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAER"}
@@ -1,7 +1,7 @@
1
1
  import { sha256 } from '@noble/hashes/sha2.js';
2
2
  import { bytesToHex } from '@noble/hashes/utils.js';
3
3
  import { serializeJcs } from '../values/jcs.js';
4
- import { validateProtocolDeploymentContract, validateProtocolDeploymentContractV3 } from './validate.js';
4
+ import { isContract3Envelope, validateProtocolDeploymentContract, validateProtocolDeploymentContractV3 } from './validate.js';
5
5
  const textEncoder = new TextEncoder();
6
6
  export const PROTOCOL_DEPLOYMENT_IDENTITY_DOMAIN = 'hypequery:deployment:v2\0';
7
7
  /** Identity domain for deployment contract 3 (RFC 0015). */
@@ -22,6 +22,16 @@ export function prepareProtocolDeploymentContract(input, options = {}) {
22
22
  export function prepareProtocolDeploymentContractV3(input, options = {}) {
23
23
  return identify(validateProtocolDeploymentContractV3(input, options), PROTOCOL_DEPLOYMENT_V3_IDENTITY_DOMAIN);
24
24
  }
25
+ /**
26
+ * Validates, canonically encodes, and identifies a deployment contract 2 or 3,
27
+ * selected by its `version`. Each version keeps its own identity domain, so a
28
+ * contract 2 artifact keeps the identity it had before contract 3 existed.
29
+ */
30
+ export function prepareProtocolDeploymentContractAnyVersion(input, options = {}) {
31
+ return isContract3Envelope(input)
32
+ ? prepareProtocolDeploymentContractV3(input, options)
33
+ : prepareProtocolDeploymentContract(input, options);
34
+ }
25
35
  export function encodeProtocolDeploymentContract(input, options = {}) {
26
36
  return prepareProtocolDeploymentContract(input, options).bytes;
27
37
  }
@@ -0,0 +1,16 @@
1
+ import type { ProtocolDeploymentDatasetAnyVersion } from './types.js';
2
+ /**
3
+ * What forces a dataset's deployment to contract 3 (RFC 0015, RFC 0029), in
4
+ * the registry order RFC 0030 fixes. The `allowedFilters` rename is not one:
5
+ * on its own it never raises the version.
6
+ */
7
+ export type ProtocolContract3Feature = 'segments' | 'windowMeasures' | 'shiftMeasures' | 'approxCountDistinct' | 'subDayDefaultGrain' | 'alternateTimeFields';
8
+ /** Registry order, which every message and fixture follows. */
9
+ export declare const PROTOCOL_CONTRACT_3_FEATURES: readonly ProtocolContract3Feature[];
10
+ /**
11
+ * The contract 3 features a contract dataset uses, in registry order. Derived
12
+ * from the contract alone, so a deployment target and the CLI that built the
13
+ * bundle name the same features. A contract 2 dataset uses none.
14
+ */
15
+ export declare function datasetContract3Features(dataset: ProtocolDeploymentDatasetAnyVersion): readonly ProtocolContract3Feature[];
16
+ //# sourceMappingURL=contract-3-features.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-3-features.d.ts","sourceRoot":"","sources":["../../src/deployments/contract-3-features.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAA+B,MAAM,YAAY,CAAC;AAEnG;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAChC,UAAU,GACV,gBAAgB,GAChB,eAAe,GACf,qBAAqB,GACrB,oBAAoB,GACpB,qBAAqB,CAAC;AAE1B,+DAA+D;AAC/D,eAAO,MAAM,4BAA4B,EAAE,SAAS,wBAAwB,EAO1E,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,mCAAmC,GAC3C,SAAS,wBAAwB,EAAE,CAarC"}
@@ -0,0 +1,28 @@
1
+ /** Registry order, which every message and fixture follows. */
2
+ export const PROTOCOL_CONTRACT_3_FEATURES = Object.freeze([
3
+ 'segments',
4
+ 'windowMeasures',
5
+ 'shiftMeasures',
6
+ 'approxCountDistinct',
7
+ 'subDayDefaultGrain',
8
+ 'alternateTimeFields',
9
+ ]);
10
+ /**
11
+ * The contract 3 features a contract dataset uses, in registry order. Derived
12
+ * from the contract alone, so a deployment target and the CLI that built the
13
+ * bundle name the same features. A contract 2 dataset uses none.
14
+ */
15
+ export function datasetContract3Features(dataset) {
16
+ const v3 = dataset;
17
+ const measures = dataset.measures;
18
+ const grain = dataset.defaults?.timeGrain;
19
+ const used = {
20
+ segments: (v3.segments?.length ?? 0) > 0,
21
+ windowMeasures: measures.some(measure => measure.kind === 'window'),
22
+ shiftMeasures: measures.some(measure => measure.kind === 'shift'),
23
+ approxCountDistinct: measures.some(measure => measure.aggregation === 'approxCountDistinct'),
24
+ subDayDefaultGrain: grain === 'minute' || grain === 'hour',
25
+ alternateTimeFields: (v3.alternateTimeFields?.length ?? 0) > 0,
26
+ };
27
+ return Object.freeze(PROTOCOL_CONTRACT_3_FEATURES.filter(feature => used[feature]));
28
+ }
@@ -0,0 +1,10 @@
1
+ import type { ProtocolQualifiedIdentifier } from '../identifiers/index.js';
2
+ import type { ProtocolDatasetDimension, ProtocolDatasetEvents } from './types.js';
3
+ /**
4
+ * RFC 0027: an event dataset names the dimension that identifies who acted
5
+ * (`entity`) and, optionally, the one naming what happened (`event`). The
6
+ * event timestamp is always the dataset's `timeField`, so the declaration is
7
+ * checked against the dataset's own dimensions and time field.
8
+ */
9
+ export declare function validateProtocolDatasetEvents(input: unknown, path: string, dimensions: readonly ProtocolDatasetDimension[], timeField: ProtocolQualifiedIdentifier | undefined): ProtocolDatasetEvents;
10
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/deployments/events.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAsB,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAC/F,OAAO,KAAK,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAUlF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,SAAS,wBAAwB,EAAE,EAC/C,SAAS,EAAE,2BAA2B,GAAG,SAAS,GACjD,qBAAqB,CAoCvB"}
@@ -0,0 +1,59 @@
1
+ import { parseProtocolIdentifier } from '../identifiers/index.js';
2
+ import { deploymentError } from './errors.js';
3
+ function simpleIdentifier(value, path) {
4
+ try {
5
+ return parseProtocolIdentifier(value);
6
+ }
7
+ catch {
8
+ return deploymentError('HQ_DEPLOYMENT_INVALID_IDENTIFIER', path);
9
+ }
10
+ }
11
+ /**
12
+ * RFC 0027: an event dataset names the dimension that identifies who acted
13
+ * (`entity`) and, optionally, the one naming what happened (`event`). The
14
+ * event timestamp is always the dataset's `timeField`, so the declaration is
15
+ * checked against the dataset's own dimensions and time field.
16
+ */
17
+ export function validateProtocolDatasetEvents(input, path, dimensions, timeField) {
18
+ if (input === null || typeof input !== 'object' || Array.isArray(input))
19
+ deploymentError('HQ_DEPLOYMENT_TYPE', path);
20
+ const prototype = Object.getPrototypeOf(input);
21
+ if (prototype !== null && prototype !== Object.prototype)
22
+ deploymentError('HQ_DEPLOYMENT_UNSAFE_OBJECT', path);
23
+ const value = input;
24
+ for (const key of Reflect.ownKeys(value)) {
25
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
26
+ if (typeof key !== 'string' || !descriptor || !descriptor.enumerable || !('value' in descriptor)) {
27
+ deploymentError('HQ_DEPLOYMENT_UNSAFE_OBJECT', path);
28
+ }
29
+ if (key !== 'entity' && key !== 'event')
30
+ deploymentError('HQ_DEPLOYMENT_UNKNOWN_FIELD', `${path}.${key}`);
31
+ }
32
+ if (!Object.hasOwn(value, 'entity'))
33
+ deploymentError('HQ_DEPLOYMENT_TYPE', `${path}.entity`);
34
+ const entity = simpleIdentifier(value.entity, `${path}.entity`);
35
+ const event = value.event === undefined ? undefined : simpleIdentifier(value.event, `${path}.event`);
36
+ const byName = new Map(dimensions.map(dimension => [String(dimension.name), dimension]));
37
+ const entityDimension = byName.get(entity);
38
+ if (!entityDimension)
39
+ deploymentError('HQ_DEPLOYMENT_INVALID_REFERENCE', `${path}.entity`);
40
+ // Distinct entities are counted per group, so the entity must be a value a
41
+ // caller could group by, and not a point in time.
42
+ if (!entityDimension.groupable || (entityDimension.type !== 'string' && entityDimension.type !== 'number')) {
43
+ deploymentError('HQ_DEPLOYMENT_INVALID_VALUE', `${path}.entity`);
44
+ }
45
+ if (event !== undefined) {
46
+ const eventDimension = byName.get(event);
47
+ if (!eventDimension)
48
+ deploymentError('HQ_DEPLOYMENT_INVALID_REFERENCE', `${path}.event`);
49
+ if (!eventDimension.filterable || eventDimension.type !== 'string') {
50
+ deploymentError('HQ_DEPLOYMENT_INVALID_VALUE', `${path}.event`);
51
+ }
52
+ }
53
+ // The time field is the event timestamp: it must be one of this dataset's
54
+ // own timestamp dimensions.
55
+ const time = timeField === undefined ? undefined : byName.get(String(timeField));
56
+ if (time === undefined || time.type !== 'timestamp')
57
+ deploymentError('HQ_DEPLOYMENT_INVALID_REFERENCE', path);
58
+ return Object.freeze({ entity, ...(event === undefined ? {} : { event }) });
59
+ }
@@ -1,8 +1,16 @@
1
1
  export { ProtocolDeploymentError } from './errors.js';
2
- export { PROTOCOL_DEPLOYMENT_IDENTITY_DOMAIN, PROTOCOL_DEPLOYMENT_V3_IDENTITY_DOMAIN, encodeProtocolDeploymentContract, encodeProtocolDeploymentContractToString, hashProtocolDeploymentContract, prepareProtocolDeploymentContract, prepareProtocolDeploymentContractV3, } from './codec.js';
3
- export type { PreparedProtocolDeploymentContract, PreparedProtocolDeploymentContractV3, } from './codec.js';
2
+ export { PROTOCOL_DEPLOYMENT_IDENTITY_DOMAIN, PROTOCOL_DEPLOYMENT_V3_IDENTITY_DOMAIN, encodeProtocolDeploymentContract, encodeProtocolDeploymentContractToString, hashProtocolDeploymentContract, prepareProtocolDeploymentContract, prepareProtocolDeploymentContractAnyVersion, prepareProtocolDeploymentContractV3, } from './codec.js';
3
+ export type { PreparedProtocolDeploymentContract, PreparedProtocolDeploymentContractAnyVersion, PreparedProtocolDeploymentContractV3, } from './codec.js';
4
4
  export { DEFAULT_PROTOCOL_DEPLOYMENT_LIMITS } from './limits.js';
5
- export { checkProtocolDatasetContract, checkProtocolDeploymentContract, checkProtocolDeploymentContractV3, validateProtocolDatasetContract, validateProtocolDeploymentContract, validateProtocolDeploymentContractV3, } from './validate.js';
6
- export type { ProtocolDatasetDerivedMeasure, ProtocolDeploymentDataset, ProtocolDeploymentMeasure, 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 './types.js';
5
+ export { checkProtocolDatasetContract, checkProtocolDeploymentContract, checkProtocolDeploymentContractV3, validateProtocolDatasetContract, validateProtocolDeploymentContract, validateProtocolDeploymentContractAnyVersion, validateProtocolDeploymentContractAtLowestVersion, validateProtocolDeploymentContractV3, } from './validate.js';
6
+ export type { ProtocolDatasetDerivedMeasure, ProtocolDeploymentDataset, ProtocolDeploymentMeasure, 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 './types.js';
7
+ export { PROTOCOL_CONTRACT_3_FEATURES, datasetContract3Features } from './contract-3-features.js';
8
+ export type { ProtocolContract3Feature } from './contract-3-features.js';
9
+ export { datasetAllowedFilters, datasetGrains, datasetSegments, datasetTimeAxes, withDatasetAllowedFilters, } from './readers.js';
10
+ export type { ProtocolAnyVersionDataset } from './readers.js';
7
11
  export { validateProtocolRowResolution } from './row-resolution.js';
12
+ export { validateProtocolDatasetEvents } from './events.js';
13
+ export { isProtocolSqlSource, validateProtocolSqlSource } from './sql-source.js';
14
+ export { PROTOCOL_SQL_SOURCE_MAX_BYTES, PROTOCOL_SQL_SOURCE_MAX_DEPENDENCIES, analyzeProtocolSqlSource, } from './sql-source-analysis.js';
15
+ export type { ProtocolSqlSourceAnalysis, ProtocolSqlSourceRefusal } from './sql-source-analysis.js';
8
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/deployments/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,mCAAmC,EACnC,sCAAsC,EACtC,gCAAgC,EAChC,wCAAwC,EACxC,8BAA8B,EAC9B,iCAAiC,EACjC,mCAAmC,GACpC,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,kCAAkC,EAClC,oCAAoC,GACrC,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kCAAkC,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EACL,4BAA4B,EAC5B,+BAA+B,EAC/B,iCAAiC,EACjC,+BAA+B,EAC/B,kCAAkC,EAClC,oCAAoC,GACrC,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,2BAA2B,EAC3B,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,EAC3B,2BAA2B,EAC3B,+BAA+B,EAC/B,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,EAC3B,4BAA4B,EAC5B,oBAAoB,EACpB,6BAA6B,EAC7B,2BAA2B,EAC3B,iCAAiC,EACjC,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/deployments/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,mCAAmC,EACnC,sCAAsC,EACtC,gCAAgC,EAChC,wCAAwC,EACxC,8BAA8B,EAC9B,iCAAiC,EACjC,2CAA2C,EAC3C,mCAAmC,GACpC,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,kCAAkC,EAClC,4CAA4C,EAC5C,oCAAoC,GACrC,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kCAAkC,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EACL,4BAA4B,EAC5B,+BAA+B,EAC/B,iCAAiC,EACjC,+BAA+B,EAC/B,kCAAkC,EAClC,4CAA4C,EAC5C,iDAAiD,EACjD,oCAAoC,GACrC,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,2BAA2B,EAC3B,0BAA0B,EAC1B,4BAA4B,EAC5B,oCAAoC,EACpC,mCAAmC,EACnC,2BAA2B,EAC3B,2BAA2B,EAC3B,+BAA+B,EAC/B,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,EAC3B,4BAA4B,EAC5B,oBAAoB,EACpB,6BAA6B,EAC7B,2BAA2B,EAC3B,iCAAiC,EACjC,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAClG,YAAY,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,eAAe,EACf,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,EACL,6BAA6B,EAC7B,oCAAoC,EACpC,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -1,5 +1,10 @@
1
1
  export { ProtocolDeploymentError } from './errors.js';
2
- export { PROTOCOL_DEPLOYMENT_IDENTITY_DOMAIN, PROTOCOL_DEPLOYMENT_V3_IDENTITY_DOMAIN, encodeProtocolDeploymentContract, encodeProtocolDeploymentContractToString, hashProtocolDeploymentContract, prepareProtocolDeploymentContract, prepareProtocolDeploymentContractV3, } from './codec.js';
2
+ export { PROTOCOL_DEPLOYMENT_IDENTITY_DOMAIN, PROTOCOL_DEPLOYMENT_V3_IDENTITY_DOMAIN, encodeProtocolDeploymentContract, encodeProtocolDeploymentContractToString, hashProtocolDeploymentContract, prepareProtocolDeploymentContract, prepareProtocolDeploymentContractAnyVersion, prepareProtocolDeploymentContractV3, } from './codec.js';
3
3
  export { DEFAULT_PROTOCOL_DEPLOYMENT_LIMITS } from './limits.js';
4
- export { checkProtocolDatasetContract, checkProtocolDeploymentContract, checkProtocolDeploymentContractV3, validateProtocolDatasetContract, validateProtocolDeploymentContract, validateProtocolDeploymentContractV3, } from './validate.js';
4
+ export { checkProtocolDatasetContract, checkProtocolDeploymentContract, checkProtocolDeploymentContractV3, validateProtocolDatasetContract, validateProtocolDeploymentContract, validateProtocolDeploymentContractAnyVersion, validateProtocolDeploymentContractAtLowestVersion, validateProtocolDeploymentContractV3, } from './validate.js';
5
+ export { PROTOCOL_CONTRACT_3_FEATURES, datasetContract3Features } from './contract-3-features.js';
6
+ export { datasetAllowedFilters, datasetGrains, datasetSegments, datasetTimeAxes, withDatasetAllowedFilters, } from './readers.js';
5
7
  export { validateProtocolRowResolution } from './row-resolution.js';
8
+ export { validateProtocolDatasetEvents } from './events.js';
9
+ export { isProtocolSqlSource, validateProtocolSqlSource } from './sql-source.js';
10
+ export { PROTOCOL_SQL_SOURCE_MAX_BYTES, PROTOCOL_SQL_SOURCE_MAX_DEPENDENCIES, analyzeProtocolSqlSource, } from './sql-source-analysis.js';
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Version-neutral readers for contract datasets (RFC 0030).
3
+ *
4
+ * Each takes a dataset of any deployment contract version a consumer accepts,
5
+ * so a consumer never branches on `version` or probes for a field name. When
6
+ * a new contract version renames, moves or adds a field, its reader ships in
7
+ * the same release.
8
+ */
9
+ import type { ProtocolIdentifier, ProtocolQualifiedIdentifier } from '../identifiers/index.js';
10
+ import type { ProtocolQueryTimeGrain } from '../expressions/index.js';
11
+ import type { ProtocolDatasetContract, ProtocolDatasetFilter, ProtocolDatasetSegment, ProtocolDeploymentDatasetAnyVersion } from './types.js';
12
+ /** A contract dataset of any version, or an RFC 0006 dataset contract. */
13
+ export type ProtocolAnyVersionDataset = ProtocolDeploymentDatasetAnyVersion | ProtocolDatasetContract;
14
+ /**
15
+ * The dataset's filter allow-list: `filters` in contract 2 and in RFC 0006
16
+ * dataset contracts, `allowedFilters` in contract 3 (RFC 0015).
17
+ */
18
+ export declare function datasetAllowedFilters(dataset: ProtocolAnyVersionDataset): readonly ProtocolDatasetFilter[];
19
+ /**
20
+ * A copy of `dataset` whose allow-list is `filters`, stored under the field
21
+ * name the dataset's own contract version uses.
22
+ */
23
+ export declare function withDatasetAllowedFilters<TDataset extends ProtocolAnyVersionDataset>(dataset: TDataset, filters: readonly ProtocolDatasetFilter[]): TDataset;
24
+ /** The dataset's named segments; contract 2 cannot declare any. */
25
+ export declare function datasetSegments(dataset: ProtocolAnyVersionDataset): readonly ProtocolDatasetSegment[];
26
+ /**
27
+ * The time axes a query may select with `timeKey` (RFC 0029): the default
28
+ * `timeField` first, then contract 3 `alternateTimeFields` in authored order.
29
+ * Empty when the dataset has no time field.
30
+ */
31
+ export declare function datasetTimeAxes(dataset: ProtocolAnyVersionDataset): readonly (ProtocolQualifiedIdentifier | ProtocolIdentifier)[];
32
+ /**
33
+ * The grains a query may bucket the dataset `by`: every grain from `minute`
34
+ * to `year` when it has a time field, none otherwise. The contract version
35
+ * does not narrow this (RFC 0030); `minute` and `hour` need semantic
36
+ * invocation 2, which `semanticInvocationVersion` selects.
37
+ */
38
+ export declare function datasetGrains(dataset: ProtocolAnyVersionDataset): readonly ProtocolQueryTimeGrain[];
39
+ //# sourceMappingURL=readers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readers.d.ts","sourceRoot":"","sources":["../../src/deployments/readers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAC/F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EACV,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,mCAAmC,EACpC,MAAM,YAAY,CAAC;AAEpB,0EAA0E;AAC1E,MAAM,MAAM,yBAAyB,GAAG,mCAAmC,GAAG,uBAAuB,CAAC;AActG;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yBAAyB,GAAG,SAAS,qBAAqB,EAAE,CAG1G;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,SAAS,yBAAyB,EAClF,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,SAAS,qBAAqB,EAAE,GACxC,QAAQ,CAIV;AAED,mEAAmE;AACnE,wBAAgB,eAAe,CAAC,OAAO,EAAE,yBAAyB,GAAG,SAAS,sBAAsB,EAAE,CAErG;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,yBAAyB,GACjC,SAAS,CAAC,2BAA2B,GAAG,kBAAkB,CAAC,EAAE,CAI/D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,yBAAyB,GAAG,SAAS,sBAAsB,EAAE,CAEnG"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Version-neutral readers for contract datasets (RFC 0030).
3
+ *
4
+ * Each takes a dataset of any deployment contract version a consumer accepts,
5
+ * so a consumer never branches on `version` or probes for a field name. When
6
+ * a new contract version renames, moves or adds a field, its reader ships in
7
+ * the same release.
8
+ */
9
+ const EMPTY = Object.freeze([]);
10
+ /** Every grain a query may bucket by, coarsest last. */
11
+ const QUERY_GRAINS = Object.freeze([
12
+ 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year',
13
+ ]);
14
+ /** Contract 3 calls the allow-list `allowedFilters`; contract 2 calls it `filters`. */
15
+ function isAllowedFiltersDataset(dataset) {
16
+ return 'allowedFilters' in dataset && dataset.allowedFilters !== undefined;
17
+ }
18
+ /**
19
+ * The dataset's filter allow-list: `filters` in contract 2 and in RFC 0006
20
+ * dataset contracts, `allowedFilters` in contract 3 (RFC 0015).
21
+ */
22
+ export function datasetAllowedFilters(dataset) {
23
+ if (isAllowedFiltersDataset(dataset))
24
+ return dataset.allowedFilters;
25
+ return dataset.filters ?? EMPTY;
26
+ }
27
+ /**
28
+ * A copy of `dataset` whose allow-list is `filters`, stored under the field
29
+ * name the dataset's own contract version uses.
30
+ */
31
+ export function withDatasetAllowedFilters(dataset, filters) {
32
+ return (isAllowedFiltersDataset(dataset)
33
+ ? { ...dataset, allowedFilters: filters }
34
+ : { ...dataset, filters });
35
+ }
36
+ /** The dataset's named segments; contract 2 cannot declare any. */
37
+ export function datasetSegments(dataset) {
38
+ return dataset.segments ?? EMPTY;
39
+ }
40
+ /**
41
+ * The time axes a query may select with `timeKey` (RFC 0029): the default
42
+ * `timeField` first, then contract 3 `alternateTimeFields` in authored order.
43
+ * Empty when the dataset has no time field.
44
+ */
45
+ export function datasetTimeAxes(dataset) {
46
+ if (dataset.timeField === undefined)
47
+ return EMPTY;
48
+ const alternates = dataset.alternateTimeFields ?? [];
49
+ return Object.freeze([dataset.timeField, ...alternates]);
50
+ }
51
+ /**
52
+ * The grains a query may bucket the dataset `by`: every grain from `minute`
53
+ * to `year` when it has a time field, none otherwise. The contract version
54
+ * does not narrow this (RFC 0030); `minute` and `hour` need semantic
55
+ * invocation 2, which `semanticInvocationVersion` selects.
56
+ */
57
+ export function datasetGrains(dataset) {
58
+ return dataset.timeField === undefined ? EMPTY : QUERY_GRAINS;
59
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The RFC 0028 checker for a SQL-sourced dataset: a lexical pass with
3
+ * ClickHouse's literal rules, not a parser. Each rule refuses a construct the
4
+ * lexer can see, so nothing is ever accepted on a judgement that it looks
5
+ * harmless. Code-first datasets and contract validation share it.
6
+ */
7
+ /** Why a SQL source was refused. Stable: datasets maps each to a message. */
8
+ export type ProtocolSqlSourceRefusal = 'empty' | 'too-large' | 'invalid-character' | 'unterminated-literal' | 'multiple-statements' | 'comment' | 'placeholder' | 'not-select' | 'forbidden-clause' | 'table-function' | 'forbidden-function' | 'system-table' | 'unbalanced-parentheses' | 'unsupported-from' | 'undeclared-dependency' | 'unused-dependency';
9
+ export type ProtocolSqlSourceAnalysis = {
10
+ readonly ok: true;
11
+ /** Tables the SQL reads, unquoted and as written, in first-reference order. */
12
+ readonly tables: readonly string[];
13
+ /** The SQL reads at least one table with FINAL (RFC 0021 pinning applies). */
14
+ readonly readsFinal: boolean;
15
+ } | {
16
+ readonly ok: false;
17
+ readonly reason: ProtocolSqlSourceRefusal;
18
+ /** The word, function or table the refusal is about, when there is one. */
19
+ readonly detail?: string;
20
+ };
21
+ /** 16 KiB of UTF-8. */
22
+ export declare const PROTOCOL_SQL_SOURCE_MAX_BYTES = 16384;
23
+ export declare const PROTOCOL_SQL_SOURCE_MAX_DEPENDENCIES = 64;
24
+ /**
25
+ * Check one SQL source against RFC 0028's rules and its declared
26
+ * dependencies. Never throws.
27
+ */
28
+ export declare function analyzeProtocolSqlSource(sql: string, dependencies: readonly string[]): ProtocolSqlSourceAnalysis;
29
+ //# sourceMappingURL=sql-source-analysis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-source-analysis.d.ts","sourceRoot":"","sources":["../../src/deployments/sql-source-analysis.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,6EAA6E;AAC7E,MAAM,MAAM,wBAAwB,GAChC,OAAO,GACP,WAAW,GACX,mBAAmB,GACnB,sBAAsB,GACtB,qBAAqB,GACrB,SAAS,GACT,aAAa,GACb,YAAY,GACZ,kBAAkB,GAClB,gBAAgB,GAChB,oBAAoB,GACpB,cAAc,GACd,wBAAwB,GACxB,kBAAkB,GAClB,uBAAuB,GACvB,mBAAmB,CAAC;AAExB,MAAM,MAAM,yBAAyB,GACjC;IACA,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B,GACC;IACA,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEJ,uBAAuB;AACvB,eAAO,MAAM,6BAA6B,QAAS,CAAC;AACpD,eAAO,MAAM,oCAAoC,KAAK,CAAC;AAiIvD;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,SAAS,MAAM,EAAE,GAC9B,yBAAyB,CA8H3B"}