@hypequery/protocol 0.26.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 (100) hide show
  1. package/dist/bundles/index.d.ts +1 -1
  2. package/dist/bundles/index.d.ts.map +1 -1
  3. package/dist/bundles/limits.d.ts.map +1 -1
  4. package/dist/bundles/limits.js +1 -0
  5. package/dist/bundles/types.d.ts +15 -1
  6. package/dist/bundles/types.d.ts.map +1 -1
  7. package/dist/bundles/validate.d.ts.map +1 -1
  8. package/dist/bundles/validate.js +32 -4
  9. package/dist/business-context/codec.d.ts +13 -0
  10. package/dist/business-context/codec.d.ts.map +1 -0
  11. package/dist/business-context/codec.js +30 -0
  12. package/dist/business-context/errors.d.ts +8 -0
  13. package/dist/business-context/errors.d.ts.map +1 -0
  14. package/dist/business-context/errors.js +13 -0
  15. package/dist/business-context/index.d.ts +7 -0
  16. package/dist/business-context/index.d.ts.map +1 -0
  17. package/dist/business-context/index.js +4 -0
  18. package/dist/business-context/limits.d.ts +5 -0
  19. package/dist/business-context/limits.d.ts.map +1 -0
  20. package/dist/business-context/limits.js +21 -0
  21. package/dist/business-context/types.d.ts +51 -0
  22. package/dist/business-context/types.d.ts.map +1 -0
  23. package/dist/business-context/types.js +1 -0
  24. package/dist/business-context/validate.d.ts +11 -0
  25. package/dist/business-context/validate.d.ts.map +1 -0
  26. package/dist/business-context/validate.js +166 -0
  27. package/dist/cache-preimages/cache-preimages.d.ts.map +1 -1
  28. package/dist/cache-preimages/cache-preimages.js +22 -0
  29. package/dist/deployments/codec.d.ts +8 -0
  30. package/dist/deployments/codec.d.ts.map +1 -1
  31. package/dist/deployments/codec.js +11 -1
  32. package/dist/deployments/events.d.ts +10 -0
  33. package/dist/deployments/events.d.ts.map +1 -0
  34. package/dist/deployments/events.js +59 -0
  35. package/dist/deployments/index.d.ts +8 -4
  36. package/dist/deployments/index.d.ts.map +1 -1
  37. package/dist/deployments/index.js +5 -2
  38. package/dist/deployments/sql-source-analysis.d.ts +29 -0
  39. package/dist/deployments/sql-source-analysis.d.ts.map +1 -0
  40. package/dist/deployments/sql-source-analysis.js +264 -0
  41. package/dist/deployments/sql-source.d.ts +8 -0
  42. package/dist/deployments/sql-source.d.ts.map +1 -0
  43. package/dist/deployments/sql-source.js +107 -0
  44. package/dist/deployments/types.d.ts +41 -1
  45. package/dist/deployments/types.d.ts.map +1 -1
  46. package/dist/deployments/validate.d.ts +19 -0
  47. package/dist/deployments/validate.d.ts.map +1 -1
  48. package/dist/deployments/validate.js +162 -4
  49. package/dist/event-operations/index.d.ts +6 -0
  50. package/dist/event-operations/index.d.ts.map +1 -0
  51. package/dist/event-operations/index.js +4 -0
  52. package/dist/event-operations/limits.d.ts +17 -0
  53. package/dist/event-operations/limits.d.ts.map +1 -0
  54. package/dist/event-operations/limits.js +21 -0
  55. package/dist/event-operations/predicates.d.ts +4 -0
  56. package/dist/event-operations/predicates.d.ts.map +1 -0
  57. package/dist/event-operations/predicates.js +10 -0
  58. package/dist/event-operations/records.d.ts +9 -0
  59. package/dist/event-operations/records.d.ts.map +1 -0
  60. package/dist/event-operations/records.js +55 -0
  61. package/dist/event-operations/types.d.ts +69 -0
  62. package/dist/event-operations/types.d.ts.map +1 -0
  63. package/dist/event-operations/types.js +1 -0
  64. package/dist/event-operations/validate.d.ts +11 -0
  65. package/dist/event-operations/validate.d.ts.map +1 -0
  66. package/dist/event-operations/validate.js +220 -0
  67. package/dist/event-operations/window.d.ts +8 -0
  68. package/dist/event-operations/window.d.ts.map +1 -0
  69. package/dist/event-operations/window.js +23 -0
  70. package/dist/expressions/calculations.d.ts +103 -0
  71. package/dist/expressions/calculations.d.ts.map +1 -0
  72. package/dist/expressions/calculations.js +9 -0
  73. package/dist/expressions/index.d.ts +3 -0
  74. package/dist/expressions/index.d.ts.map +1 -1
  75. package/dist/expressions/index.js +2 -0
  76. package/dist/expressions/relative-dates.d.ts +31 -0
  77. package/dist/expressions/relative-dates.d.ts.map +1 -0
  78. package/dist/expressions/relative-dates.js +38 -0
  79. package/dist/expressions/types.d.ts +24 -1
  80. package/dist/expressions/types.d.ts.map +1 -1
  81. package/dist/expressions/validate-calculations.d.ts +41 -0
  82. package/dist/expressions/validate-calculations.d.ts.map +1 -0
  83. package/dist/expressions/validate-calculations.js +397 -0
  84. package/dist/expressions/validate.d.ts.map +1 -1
  85. package/dist/expressions/validate.js +80 -4
  86. package/dist/index.d.ts +13 -6
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +7 -2
  89. package/dist/invocations/index.d.ts +1 -1
  90. package/dist/invocations/index.d.ts.map +1 -1
  91. package/dist/invocations/types.d.ts +13 -3
  92. package/dist/invocations/types.d.ts.map +1 -1
  93. package/dist/invocations/validate.d.ts.map +1 -1
  94. package/dist/invocations/validate.js +58 -2
  95. package/dist/visibility/resolve.d.ts +4 -4
  96. package/dist/visibility/resolve.d.ts.map +1 -1
  97. package/dist/visibility/resolve.js +12 -4
  98. package/dist/visibility/types.d.ts +6 -0
  99. package/dist/visibility/types.d.ts.map +1 -1
  100. package/package.json +1 -1
@@ -3,5 +3,5 @@ export { PROTOCOL_DEPLOYMENT_BUNDLE_IDENTITY_DOMAIN, encodeProtocolDeploymentBun
3
3
  export type { PreparedProtocolDeploymentBundleManifest } from './codec.js';
4
4
  export { DEFAULT_PROTOCOL_DEPLOYMENT_BUNDLE_LIMITS } from './limits.js';
5
5
  export { validateProtocolDeploymentBundleManifest } from './validate.js';
6
- export type { ProtocolDeploymentBundleArtifact, ProtocolDeploymentBundleDeployment, ProtocolDeploymentBundleErrorCode, ProtocolDeploymentBundleFile, ProtocolDeploymentBundleLimits, ProtocolDeploymentBundleManifest, ProtocolDeploymentBundleOptions, ProtocolDeploymentBundleSource, ProtocolDeploymentBundleSourceRevision, } from './types.js';
6
+ export type { ProtocolDeploymentBundleArtifact, ProtocolDeploymentBundleBusinessContext, ProtocolDeploymentBundleDeployment, ProtocolDeploymentBundleErrorCode, ProtocolDeploymentBundleFile, ProtocolDeploymentBundleLimits, ProtocolDeploymentBundleManifest, ProtocolDeploymentBundleOptions, ProtocolDeploymentBundleSource, ProtocolDeploymentBundleSourceRevision, } from './types.js';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundles/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,0CAA0C,EAC1C,sCAAsC,EACtC,8CAA8C,EAC9C,oCAAoC,EACpC,uCAAuC,GACxC,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,wCAAwC,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,wCAAwC,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EACV,gCAAgC,EAChC,kCAAkC,EAClC,iCAAiC,EACjC,4BAA4B,EAC5B,8BAA8B,EAC9B,gCAAgC,EAChC,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,GACvC,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundles/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,0CAA0C,EAC1C,sCAAsC,EACtC,8CAA8C,EAC9C,oCAAoC,EACpC,uCAAuC,GACxC,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,wCAAwC,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,wCAAwC,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EACV,gCAAgC,EAChC,uCAAuC,EACvC,kCAAkC,EAClC,iCAAiC,EACjC,4BAA4B,EAC5B,8BAA8B,EAC9B,gCAAgC,EAChC,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,GACvC,MAAM,YAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/bundles/limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,+BAA+B,EAChC,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,yCAAyC,EACtD,QAAQ,CAAC,8BAA8B,CASrC,CAAC;AAEH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,+BAAoC,GAC5C,QAAQ,CAAC,8BAA8B,CAAC,CAe1C"}
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/bundles/limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,+BAA+B,EAChC,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,yCAAyC,EACtD,QAAQ,CAAC,8BAA8B,CAUrC,CAAC;AAEH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,+BAAoC,GAC5C,QAAQ,CAAC,8BAA8B,CAAC,CAe1C"}
@@ -3,6 +3,7 @@ export const DEFAULT_PROTOCOL_DEPLOYMENT_BUNDLE_LIMITS = Object.freeze({
3
3
  maxSourceFiles: 1_000,
4
4
  maxPathBytes: 1_024,
5
5
  maxDeploymentBytes: 16 * 1_024 * 1_024,
6
+ maxBusinessContextBytes: 1_024 * 1_024,
6
7
  maxArtifactBytes: 128 * 1_024 * 1_024,
7
8
  maxSourceFileBytes: 2 * 1_024 * 1_024,
8
9
  maxSourceBytes: 32 * 1_024 * 1_024,
@@ -6,6 +6,10 @@ export interface ProtocolDeploymentBundleFile {
6
6
  export interface ProtocolDeploymentBundleDeployment extends ProtocolDeploymentBundleFile {
7
7
  readonly identity: string;
8
8
  }
9
+ /** Reviewed business context file (bundle v2). Its identity is the document identity. */
10
+ export interface ProtocolDeploymentBundleBusinessContext extends ProtocolDeploymentBundleFile {
11
+ readonly identity: string;
12
+ }
9
13
  export interface ProtocolDeploymentBundleArtifact extends ProtocolDeploymentBundleFile {
10
14
  readonly runtime: 'node' | 'python';
11
15
  }
@@ -24,10 +28,19 @@ export interface ProtocolDeploymentBundleSource {
24
28
  readonly files: readonly ProtocolDeploymentBundleFile[];
25
29
  readonly revision?: ProtocolDeploymentBundleSourceRevision;
26
30
  }
31
+ /**
32
+ * Deployment bundle manifest.
33
+ *
34
+ * Version 1 carries only the executable contract. Version 2 additionally
35
+ * requires `businessContext`; a bundle without business context is always
36
+ * encoded as version 1 so each bundle has exactly one canonical identity.
37
+ */
27
38
  export interface ProtocolDeploymentBundleManifest {
28
39
  readonly kind: 'hypequery-deployment-bundle';
29
- readonly version: 1;
40
+ readonly version: 1 | 2;
30
41
  readonly deployment: ProtocolDeploymentBundleDeployment;
42
+ /** Present exactly when `version` is 2. */
43
+ readonly businessContext?: ProtocolDeploymentBundleBusinessContext;
31
44
  readonly artifacts: readonly ProtocolDeploymentBundleArtifact[];
32
45
  readonly source?: ProtocolDeploymentBundleSource;
33
46
  }
@@ -36,6 +49,7 @@ export interface ProtocolDeploymentBundleLimits {
36
49
  readonly maxSourceFiles: number;
37
50
  readonly maxPathBytes: number;
38
51
  readonly maxDeploymentBytes: number;
52
+ readonly maxBusinessContextBytes: number;
39
53
  readonly maxArtifactBytes: number;
40
54
  readonly maxSourceFileBytes: number;
41
55
  readonly maxSourceBytes: number;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/bundles/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,kCAAmC,SAAQ,4BAA4B;IACtF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gCAAiC,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../../src/bundles/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAIV,gCAAgC,EAChC,+BAA+B,EAGhC,MAAM,YAAY,CAAC;AAmPpB,wBAAgB,wCAAwC,CACtD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,+BAAoC,GAC5C,gCAAgC,CA+ClC"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/bundles/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAKV,gCAAgC,EAChC,+BAA+B,EAGhC,MAAM,YAAY,CAAC;AAkQpB,wBAAgB,wCAAwC,CACtD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,+BAAoC,GAC5C,gCAAgC,CAsElC"}
@@ -98,6 +98,16 @@ function validateDeployment(input, path, limits) {
98
98
  byteLength: byteLength(value.byteLength, `${path}.byteLength`, limits.maxDeploymentBytes),
99
99
  });
100
100
  }
101
+ function validateBusinessContext(input, path, limits) {
102
+ const value = requireRecord(input, path);
103
+ exactFields(value, ['path', 'identity', 'sha256', 'byteLength'], path);
104
+ return freezeRecord({
105
+ path: relativePath(value.path, `${path}.path`, limits.maxPathBytes),
106
+ identity: digest(value.identity, `${path}.identity`),
107
+ sha256: digest(value.sha256, `${path}.sha256`),
108
+ byteLength: byteLength(value.byteLength, `${path}.byteLength`, limits.maxBusinessContextBytes),
109
+ });
110
+ }
101
111
  function validateArtifact(input, path, limits) {
102
112
  const value = requireRecord(input, path);
103
113
  exactFields(value, ['runtime', 'path', 'sha256', 'byteLength'], path);
@@ -208,25 +218,41 @@ function hasTreeCollision(paths) {
208
218
  export function validateProtocolDeploymentBundleManifest(input, options = {}) {
209
219
  const limits = resolveDeploymentBundleLimits(options);
210
220
  const value = requireRecord(input, '$');
211
- exactFields(value, ['kind', 'version', 'deployment', 'artifacts'], '$', ['source']);
221
+ exactFields(value, ['kind', 'version', 'deployment', 'artifacts'], '$', ['businessContext', 'source']);
212
222
  if (value.kind !== 'hypequery-deployment-bundle') {
213
223
  if (typeof value.kind !== 'string')
214
224
  bundleError('HQ_BUNDLE_TYPE', '$.kind');
215
225
  bundleError('HQ_BUNDLE_INVALID_VALUE', '$.kind');
216
226
  }
217
- if (value.version !== 1) {
227
+ if (value.version !== 1 && value.version !== 2) {
218
228
  if (typeof value.version !== 'number')
219
229
  bundleError('HQ_BUNDLE_TYPE', '$.version');
220
230
  bundleError('HQ_BUNDLE_INVALID_VERSION', '$.version');
221
231
  }
232
+ const version = value.version;
233
+ // v1 cannot carry business context; v2 exists only to carry it.
234
+ if (version === 1 && value.businessContext !== undefined) {
235
+ bundleError('HQ_BUNDLE_UNKNOWN_FIELD', '$.businessContext');
236
+ }
237
+ if (version === 2 && value.businessContext === undefined) {
238
+ bundleError('HQ_BUNDLE_TYPE', '$.businessContext');
239
+ }
222
240
  const deployment = validateDeployment(value.deployment, '$.deployment', limits);
241
+ const businessContext = value.businessContext === undefined
242
+ ? undefined
243
+ : validateBusinessContext(value.businessContext, '$.businessContext', limits);
223
244
  const artifacts = Object.freeze(requireArray(value.artifacts, '$.artifacts', limits.maxArtifacts)
224
245
  .map((artifact, index) => validateArtifact(artifact, `$.artifacts[${index}]`, limits)));
225
246
  const source = value.source === undefined
226
247
  ? undefined
227
248
  : validateSource(value.source, '$.source', limits);
228
249
  const sourcePaths = source?.files.map(file => `${source.root}/${file.path}`) ?? [];
229
- const paths = [deployment.path, ...artifacts.map(artifact => artifact.path), ...sourcePaths];
250
+ const paths = [
251
+ deployment.path,
252
+ ...(businessContext ? [businessContext.path] : []),
253
+ ...artifacts.map(artifact => artifact.path),
254
+ ...sourcePaths,
255
+ ];
230
256
  if (new Set(paths).size !== paths.length
231
257
  || new Set(paths.map(bundlePath => bundlePath.toLowerCase())).size !== paths.length
232
258
  || hasTreeCollision(paths)) {
@@ -240,6 +266,7 @@ export function validateProtocolDeploymentBundleManifest(input, options = {}) {
240
266
  bundleError('HQ_BUNDLE_INVALID_VALUE', '$.artifacts');
241
267
  }
242
268
  const totalBytes = deployment.byteLength
269
+ + (businessContext?.byteLength ?? 0)
243
270
  + artifacts.reduce((total, artifact) => total + artifact.byteLength, 0)
244
271
  + (source?.files.reduce((total, file) => total + file.byteLength, 0) ?? 0);
245
272
  if (!Number.isSafeInteger(totalBytes) || totalBytes > limits.maxTotalBytes) {
@@ -247,8 +274,9 @@ export function validateProtocolDeploymentBundleManifest(input, options = {}) {
247
274
  }
248
275
  return freezeRecord({
249
276
  kind: 'hypequery-deployment-bundle',
250
- version: 1,
277
+ version,
251
278
  deployment,
279
+ ...(businessContext ? { businessContext } : {}),
252
280
  artifacts,
253
281
  ...(source ? { source } : {}),
254
282
  });
@@ -0,0 +1,13 @@
1
+ import type { ProtocolBusinessContext, ProtocolBusinessContextOptions } from './types.js';
2
+ export declare const PROTOCOL_BUSINESS_CONTEXT_IDENTITY_DOMAIN = "hypequery:business-context:v1\0";
3
+ export interface PreparedProtocolBusinessContext {
4
+ readonly context: ProtocolBusinessContext;
5
+ readonly canonical: string;
6
+ readonly bytes: Uint8Array;
7
+ readonly identity: string;
8
+ }
9
+ export declare function prepareProtocolBusinessContext(input: unknown, options?: ProtocolBusinessContextOptions): PreparedProtocolBusinessContext;
10
+ export declare function encodeProtocolBusinessContext(input: unknown, options?: ProtocolBusinessContextOptions): Uint8Array;
11
+ export declare function encodeProtocolBusinessContextToString(input: unknown, options?: ProtocolBusinessContextOptions): string;
12
+ export declare function hashProtocolBusinessContext(input: unknown, options?: ProtocolBusinessContextOptions): string;
13
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/business-context/codec.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAKpB,eAAO,MAAM,yCAAyC,oCAAoC,CAAC;AAE3F,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,8BAAmC,GAC3C,+BAA+B,CAWjC;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,8BAAmC,GAC3C,UAAU,CAEZ;AAED,wBAAgB,qCAAqC,CACnD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,8BAAmC,GAC3C,MAAM,CAER;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,8BAAmC,GAC3C,MAAM,CAER"}
@@ -0,0 +1,30 @@
1
+ import { sha256 } from '@noble/hashes/sha2.js';
2
+ import { bytesToHex } from '@noble/hashes/utils.js';
3
+ import { serializeJcs } from '../values/jcs.js';
4
+ import { businessContextError } from './errors.js';
5
+ import { resolveBusinessContextLimits } from './limits.js';
6
+ import { validateProtocolBusinessContext } from './validate.js';
7
+ const textEncoder = new TextEncoder();
8
+ export const PROTOCOL_BUSINESS_CONTEXT_IDENTITY_DOMAIN = 'hypequery:business-context:v1\0';
9
+ export function prepareProtocolBusinessContext(input, options = {}) {
10
+ const limits = resolveBusinessContextLimits(options);
11
+ const context = validateProtocolBusinessContext(input, options);
12
+ const canonical = serializeJcs(context);
13
+ const bytes = textEncoder.encode(canonical);
14
+ if (bytes.byteLength > limits.maxBytes)
15
+ businessContextError('HQ_BUSINESS_CONTEXT_TOO_LARGE');
16
+ const identity = bytesToHex(sha256.create()
17
+ .update(textEncoder.encode(PROTOCOL_BUSINESS_CONTEXT_IDENTITY_DOMAIN))
18
+ .update(bytes)
19
+ .digest());
20
+ return Object.freeze({ context, canonical, bytes, identity });
21
+ }
22
+ export function encodeProtocolBusinessContext(input, options = {}) {
23
+ return prepareProtocolBusinessContext(input, options).bytes;
24
+ }
25
+ export function encodeProtocolBusinessContextToString(input, options = {}) {
26
+ return prepareProtocolBusinessContext(input, options).canonical;
27
+ }
28
+ export function hashProtocolBusinessContext(input, options = {}) {
29
+ return prepareProtocolBusinessContext(input, options).identity;
30
+ }
@@ -0,0 +1,8 @@
1
+ import type { ProtocolBusinessContextErrorCode } from './types.js';
2
+ export declare class ProtocolBusinessContextError extends TypeError {
3
+ readonly code: ProtocolBusinessContextErrorCode;
4
+ readonly path: string;
5
+ constructor(code: ProtocolBusinessContextErrorCode, path?: string);
6
+ }
7
+ export declare function businessContextError(code: ProtocolBusinessContextErrorCode, path?: string): never;
8
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/business-context/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAC;AAEnE,qBAAa,4BAA6B,SAAQ,SAAS;IACzD,QAAQ,CAAC,IAAI,EAAE,gCAAgC,CAAC;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,gCAAgC,EAAE,IAAI,SAAM;CAM/D;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,gCAAgC,EACtC,IAAI,SAAM,GACT,KAAK,CAEP"}
@@ -0,0 +1,13 @@
1
+ export class ProtocolBusinessContextError extends TypeError {
2
+ code;
3
+ path;
4
+ constructor(code, path = '$') {
5
+ super(`${code} at ${path}`);
6
+ this.name = 'ProtocolBusinessContextError';
7
+ this.code = code;
8
+ this.path = path;
9
+ }
10
+ }
11
+ export function businessContextError(code, path = '$') {
12
+ throw new ProtocolBusinessContextError(code, path);
13
+ }
@@ -0,0 +1,7 @@
1
+ export { ProtocolBusinessContextError } from './errors.js';
2
+ export { PROTOCOL_BUSINESS_CONTEXT_IDENTITY_DOMAIN, encodeProtocolBusinessContext, encodeProtocolBusinessContextToString, hashProtocolBusinessContext, prepareProtocolBusinessContext, } from './codec.js';
3
+ export type { PreparedProtocolBusinessContext } from './codec.js';
4
+ export { DEFAULT_PROTOCOL_BUSINESS_CONTEXT_LIMITS } from './limits.js';
5
+ export { isEmptyProtocolBusinessContext, validateProtocolBusinessContext, } from './validate.js';
6
+ export type { ProtocolBusinessContext, ProtocolBusinessContextErrorCode, ProtocolBusinessContextGlossaryTerm, ProtocolBusinessContextKpi, ProtocolBusinessContextLimits, ProtocolBusinessContextOptions, } from './types.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/business-context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,yCAAyC,EACzC,6BAA6B,EAC7B,qCAAqC,EACrC,2BAA2B,EAC3B,8BAA8B,GAC/B,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,+BAA+B,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,wCAAwC,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,8BAA8B,EAC9B,+BAA+B,GAChC,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,uBAAuB,EACvB,gCAAgC,EAChC,mCAAmC,EACnC,0BAA0B,EAC1B,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { ProtocolBusinessContextError } from './errors.js';
2
+ export { PROTOCOL_BUSINESS_CONTEXT_IDENTITY_DOMAIN, encodeProtocolBusinessContext, encodeProtocolBusinessContextToString, hashProtocolBusinessContext, prepareProtocolBusinessContext, } from './codec.js';
3
+ export { DEFAULT_PROTOCOL_BUSINESS_CONTEXT_LIMITS } from './limits.js';
4
+ export { isEmptyProtocolBusinessContext, validateProtocolBusinessContext, } from './validate.js';
@@ -0,0 +1,5 @@
1
+ import type { ProtocolBusinessContextLimits, ProtocolBusinessContextOptions } from './types.js';
2
+ /** Matches the limits Cloud onboarding already enforces on business profiles. */
3
+ export declare const DEFAULT_PROTOCOL_BUSINESS_CONTEXT_LIMITS: Readonly<ProtocolBusinessContextLimits>;
4
+ export declare function resolveBusinessContextLimits(options?: ProtocolBusinessContextOptions): Readonly<ProtocolBusinessContextLimits>;
5
+ //# sourceMappingURL=limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/business-context/limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAEpB,iFAAiF;AACjF,eAAO,MAAM,wCAAwC,EACrD,QAAQ,CAAC,6BAA6B,CAIpC,CAAC;AAEH,wBAAgB,4BAA4B,CAC1C,OAAO,GAAE,8BAAmC,GAC3C,QAAQ,CAAC,6BAA6B,CAAC,CAezC"}
@@ -0,0 +1,21 @@
1
+ /** Matches the limits Cloud onboarding already enforces on business profiles. */
2
+ export const DEFAULT_PROTOCOL_BUSINESS_CONTEXT_LIMITS = Object.freeze({
3
+ maxTextLength: 4_096,
4
+ maxItems: 100,
5
+ maxBytes: 1_024 * 1_024,
6
+ });
7
+ export function resolveBusinessContextLimits(options = {}) {
8
+ const result = { ...DEFAULT_PROTOCOL_BUSINESS_CONTEXT_LIMITS };
9
+ for (const key of Object.keys(result)) {
10
+ const value = options.limits?.[key];
11
+ if (value === undefined)
12
+ continue;
13
+ const maximum = DEFAULT_PROTOCOL_BUSINESS_CONTEXT_LIMITS[key];
14
+ if (!Number.isSafeInteger(value) || value < 1 || value > maximum) {
15
+ throw new RangeError(`${key} must be a positive safe integer no greater than ${maximum} `
16
+ + '(the business context v1 maximum)');
17
+ }
18
+ result[key] = value;
19
+ }
20
+ return Object.freeze(result);
21
+ }
@@ -0,0 +1,51 @@
1
+ export interface ProtocolBusinessContextKpi {
2
+ readonly name: string;
3
+ readonly definition: string;
4
+ }
5
+ export interface ProtocolBusinessContextGlossaryTerm {
6
+ readonly term: string;
7
+ readonly meaning: string;
8
+ }
9
+ /**
10
+ * Reviewed business context published alongside a deployment contract.
11
+ *
12
+ * This is descriptive guidance for analysts and assistants. It is deliberately
13
+ * separate from the executable deployment contract: the data plane never reads
14
+ * it, and changing it never changes query semantics.
15
+ */
16
+ export interface ProtocolBusinessContext {
17
+ readonly kind: 'hypequery-business-context';
18
+ readonly version: 1;
19
+ /** What the business does, in a few sentences. */
20
+ readonly summary?: string;
21
+ readonly industry?: string;
22
+ /** How the business makes money. */
23
+ readonly businessModel?: string;
24
+ /** Who it sells to, and its main segments. */
25
+ readonly customers?: string;
26
+ /** Who asks the questions: roles and teams. */
27
+ readonly audience?: string;
28
+ /** Decisions and recurring questions the data should help with. */
29
+ readonly goals?: readonly string[];
30
+ /** The numbers the business watches, with their business definition. */
31
+ readonly kpis?: readonly ProtocolBusinessContextKpi[];
32
+ /** Business terms and what they mean in this organisation. */
33
+ readonly glossary?: readonly ProtocolBusinessContextGlossaryTerm[];
34
+ /** Reporting conventions: currency, time zone, fiscal year, week start. */
35
+ readonly conventions?: string;
36
+ /** Known data quirks, e.g. test orders or refunds stored elsewhere. */
37
+ readonly caveats?: readonly string[];
38
+ }
39
+ export interface ProtocolBusinessContextLimits {
40
+ /** Maximum characters in any single text value. */
41
+ readonly maxTextLength: number;
42
+ /** Maximum items in any list (goals, kpis, glossary, caveats). */
43
+ readonly maxItems: number;
44
+ /** Maximum UTF-8 bytes of the canonical encoding. */
45
+ readonly maxBytes: number;
46
+ }
47
+ export interface ProtocolBusinessContextOptions {
48
+ readonly limits?: Partial<ProtocolBusinessContextLimits>;
49
+ }
50
+ export type ProtocolBusinessContextErrorCode = 'HQ_BUSINESS_CONTEXT_TYPE' | 'HQ_BUSINESS_CONTEXT_UNKNOWN_FIELD' | 'HQ_BUSINESS_CONTEXT_INVALID_VERSION' | 'HQ_BUSINESS_CONTEXT_INVALID_VALUE' | 'HQ_BUSINESS_CON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CAAC;IAC9B,uEAAuE;IACvE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,6BAA6B;IAC5C,mDAAmD;IACnD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,6BAA6B,CAAC,CAAC;CAC1D;AAED,MAAM,MAAM,gCAAgC,GACxC,0BAA0B,GAC1B,mCAAmC,GACnC,qCAAqC,GACrC,mCAAmC,GACnC,+BAA+B,GAC/B,oCAAoC,GACpC,+BAA+B,GAC/B,mCAAmC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { ProtocolBusinessContext, ProtocolBusinessContextOptions } from './types.js';
2
+ /**
3
+ * Validates and canonicalises a business context document.
4
+ *
5
+ * Canonical form trims text, omits empty lists and keeps author order. Two
6
+ * inputs that differ only in those respects therefore share one identity.
7
+ */
8
+ export declare function validateProtocolBusinessContext(input: unknown, options?: ProtocolBusinessContextOptions): ProtocolBusinessContext;
9
+ /** True when the document carries no authored content beyond its header. */
10
+ export declare function isEmptyProtocolBusinessContext(context: ProtocolBusinessContext): boolean;
11
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/business-context/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,uBAAuB,EAIvB,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAwIpB;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,8BAAmC,GAC3C,uBAAuB,CAoCzB;AAED,4EAA4E;AAC5E,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAExF"}
@@ -0,0 +1,166 @@
1
+ import { businessContextError } from './errors.js';
2
+ import { resolveBusinessContextLimits } from './limits.js';
3
+ const TEXT_FIELDS = [
4
+ 'summary',
5
+ 'industry',
6
+ 'businessModel',
7
+ 'customers',
8
+ 'audience',
9
+ 'conventions',
10
+ ];
11
+ const TEXT_LIST_FIELDS = ['goals', 'caveats'];
12
+ const FIELD_ORDER = [
13
+ 'summary',
14
+ 'industry',
15
+ 'businessModel',
16
+ 'customers',
17
+ 'audience',
18
+ 'goals',
19
+ 'kpis',
20
+ 'glossary',
21
+ 'conventions',
22
+ 'caveats',
23
+ ];
24
+ const ALLOWED_FIELDS = new Set(['kind', 'version', ...FIELD_ORDER]);
25
+ /** C0/C1 controls other than tab and newline, which have no meaning in prose. */
26
+ const CONTROL_CHARACTER = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/;
27
+ const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
28
+ function requireRecord(input, path) {
29
+ if (typeof input !== 'object' || input === null || Array.isArray(input)) {
30
+ businessContextError('HQ_BUSINESS_CONTEXT_TYPE', path);
31
+ }
32
+ const prototype = Object.getPrototypeOf(input);
33
+ if (prototype !== Object.prototype && prototype !== null) {
34
+ businessContextError('HQ_BUSINESS_CONTEXT_UNSAFE_OBJECT', path);
35
+ }
36
+ if (Object.getOwnPropertySymbols(input).length > 0) {
37
+ businessContextError('HQ_BUSINESS_CONTEXT_UNSAFE_OBJECT', path);
38
+ }
39
+ for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(input))) {
40
+ if (!descriptor.enumerable || !('value' in descriptor)) {
41
+ businessContextError('HQ_BUSINESS_CONTEXT_UNSAFE_OBJECT', path);
42
+ }
43
+ }
44
+ return input;
45
+ }
46
+ function requireArray(input, path, maxItems) {
47
+ if (!Array.isArray(input))
48
+ businessContextError('HQ_BUSINESS_CONTEXT_TYPE', path);
49
+ if (Object.getPrototypeOf(input) !== Array.prototype
50
+ || Object.getOwnPropertySymbols(input).length > 0) {
51
+ businessContextError('HQ_BUSINESS_CONTEXT_UNSAFE_OBJECT', path);
52
+ }
53
+ if (input.length > maxItems)
54
+ businessContextError('HQ_BUSINESS_CONTEXT_TOO_MANY_ITEMS', path);
55
+ const descriptors = Object.getOwnPropertyDescriptors(input);
56
+ for (let index = 0; index < input.length; index += 1) {
57
+ const descriptor = descriptors[String(index)];
58
+ if (!descriptor || !descriptor.enumerable || !('value' in descriptor)) {
59
+ businessContextError('HQ_BUSINESS_CONTEXT_UNSAFE_OBJECT', `${path}[${index}]`);
60
+ }
61
+ }
62
+ if (Object.keys(input).length !== input.length
63
+ || Object.getOwnPropertyNames(input).length !== input.length + 1) {
64
+ businessContextError('HQ_BUSINESS_CONTEXT_UNSAFE_OBJECT', path);
65
+ }
66
+ return input;
67
+ }
68
+ function exactFields(value, allowed, path) {
69
+ for (const key of Object.keys(value)) {
70
+ if (!allowed.has(key))
71
+ businessContextError('HQ_BUSINESS_CONTEXT_UNKNOWN_FIELD', `${path}.${key}`);
72
+ }
73
+ }
74
+ /** Trimmed, non-empty prose without control characters or broken UTF-16. */
75
+ function text(value, path, limits) {
76
+ if (typeof value !== 'string')
77
+ businessContextError('HQ_BUSINESS_CONTEXT_TYPE', path);
78
+ const trimmed = value.trim();
79
+ if (trimmed.length === 0 || CONTROL_CHARACTER.test(trimmed) || LONE_SURROGATE.test(trimmed)) {
80
+ businessContextError('HQ_BUSINESS_CONTEXT_INVALID_VALUE', path);
81
+ }
82
+ if (trimmed.length > limits.maxTextLength) {
83
+ businessContextError('HQ_BUSINESS_CONTEXT_TOO_LARGE', path);
84
+ }
85
+ return trimmed;
86
+ }
87
+ /** Case- and whitespace-insensitive key used to reject ambiguous duplicate terms. */
88
+ function termKey(value) {
89
+ return value.normalize('NFKC').toLowerCase().replace(/\s+/g, ' ');
90
+ }
91
+ function textList(value, path, limits) {
92
+ const items = requireArray(value, path, limits.maxItems);
93
+ return Object.freeze(items.map((item, index) => text(item, `${path}[${index}]`, limits)));
94
+ }
95
+ function pairs(value, path, keyField, valueField, limits) {
96
+ const items = requireArray(value, path, limits.maxItems);
97
+ const allowed = new Set([keyField, valueField]);
98
+ const seen = new Set();
99
+ return Object.freeze(items.map((item, index) => {
100
+ const itemPath = `${path}[${index}]`;
101
+ const record = requireRecord(item, itemPath);
102
+ exactFields(record, allowed, itemPath);
103
+ if (!Object.hasOwn(record, keyField))
104
+ businessContextError('HQ_BUSINESS_CONTEXT_TYPE', `${itemPath}.${keyField}`);
105
+ if (!Object.hasOwn(record, valueField))
106
+ businessContextError('HQ_BUSINESS_CONTEXT_TYPE', `${itemPath}.${valueField}`);
107
+ const key = text(record[keyField], `${itemPath}.${keyField}`, limits);
108
+ const normalized = termKey(key);
109
+ if (seen.has(normalized)) {
110
+ businessContextError('HQ_BUSINESS_CONTEXT_DUPLICATE', `${itemPath}.${keyField}`);
111
+ }
112
+ seen.add(normalized);
113
+ return Object.freeze({
114
+ [keyField]: key,
115
+ [valueField]: text(record[valueField], `${itemPath}.${valueField}`, limits),
116
+ });
117
+ }));
118
+ }
119
+ /**
120
+ * Validates and canonicalises a business context document.
121
+ *
122
+ * Canonical form trims text, omits empty lists and keeps author order. Two
123
+ * inputs that differ only in those respects therefore share one identity.
124
+ */
125
+ export function validateProtocolBusinessContext(input, options = {}) {
126
+ const limits = resolveBusinessContextLimits(options);
127
+ const value = requireRecord(input, '$');
128
+ exactFields(value, ALLOWED_FIELDS, '$');
129
+ if (value.kind !== 'hypequery-business-context') {
130
+ businessContextError('HQ_BUSINESS_CONTEXT_TYPE', '$.kind');
131
+ }
132
+ if (value.version !== 1)
133
+ businessContextError('HQ_BUSINESS_CONTEXT_INVALID_VERSION', '$.version');
134
+ const fields = {};
135
+ for (const key of TEXT_FIELDS) {
136
+ if (value[key] !== undefined)
137
+ fields[key] = text(value[key], `$.${key}`, limits);
138
+ }
139
+ for (const key of TEXT_LIST_FIELDS) {
140
+ if (value[key] === undefined)
141
+ continue;
142
+ const list = textList(value[key], `$.${key}`, limits);
143
+ if (list.length > 0)
144
+ fields[key] = list;
145
+ }
146
+ if (value.kpis !== undefined) {
147
+ const kpis = pairs(value.kpis, '$.kpis', 'name', 'definition', limits);
148
+ if (kpis.length > 0)
149
+ fields.kpis = kpis;
150
+ }
151
+ if (value.glossary !== undefined) {
152
+ const glossary = pairs(value.glossary, '$.glossary', 'term', 'meaning', limits);
153
+ if (glossary.length > 0)
154
+ fields.glossary = glossary;
155
+ }
156
+ const ordered = { kind: 'hypequery-business-context', version: 1 };
157
+ for (const key of FIELD_ORDER) {
158
+ if (fields[key] !== undefined)
159
+ ordered[key] = fields[key];
160
+ }
161
+ return Object.freeze(ordered);
162
+ }
163
+ /** True when the document carries no authored content beyond its header. */
164
+ export function isEmptyProtocolBusinessContext(context) {
165
+ return FIELD_ORDER.every(key => context[key] === undefined);
166
+ }
@@ -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 ?? [])
@@ -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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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
  }