@hypequery/deployment 0.13.0 → 0.15.1

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 (47) hide show
  1. package/dist/authorized-contract.d.ts +5 -4
  2. package/dist/authorized-contract.d.ts.map +1 -1
  3. package/dist/authorized-contract.js +10 -8
  4. package/dist/bundle.d.ts +2 -2
  5. package/dist/bundle.d.ts.map +1 -1
  6. package/dist/bundle.js +2 -2
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/semantic-calculation-validation.d.ts +28 -0
  10. package/dist/semantic-calculation-validation.d.ts.map +1 -0
  11. package/dist/semantic-calculation-validation.js +110 -0
  12. package/dist/semantic-data-plane.d.ts +25 -8
  13. package/dist/semantic-data-plane.d.ts.map +1 -1
  14. package/dist/semantic-data-plane.js +44 -18
  15. package/dist/semantic-event-operation-validation.d.ts +25 -0
  16. package/dist/semantic-event-operation-validation.d.ts.map +1 -0
  17. package/dist/semantic-event-operation-validation.js +203 -0
  18. package/dist/semantic-filter-capabilities.d.ts +22 -0
  19. package/dist/semantic-filter-capabilities.d.ts.map +1 -0
  20. package/dist/semantic-filter-capabilities.js +38 -0
  21. package/dist/semantic-invocation-errors.d.ts +4 -3
  22. package/dist/semantic-invocation-errors.d.ts.map +1 -1
  23. package/dist/semantic-invocation-errors.js +5 -3
  24. package/dist/semantic-operation-validation.d.ts +19 -3
  25. package/dist/semantic-operation-validation.d.ts.map +1 -1
  26. package/dist/semantic-operation-validation.js +145 -34
  27. package/dist/utils/event-time-range.d.ts +36 -0
  28. package/dist/utils/event-time-range.d.ts.map +1 -0
  29. package/dist/utils/event-time-range.js +116 -0
  30. package/dist/utils/field-backing-column.d.ts +17 -0
  31. package/dist/utils/field-backing-column.d.ts.map +1 -0
  32. package/dist/utils/field-backing-column.js +24 -0
  33. package/dist/utils/filter-leaves.d.ts +22 -0
  34. package/dist/utils/filter-leaves.d.ts.map +1 -0
  35. package/dist/utils/filter-leaves.js +43 -0
  36. package/dist/utils/semantic-comparison-field.d.ts +17 -0
  37. package/dist/utils/semantic-comparison-field.d.ts.map +1 -0
  38. package/dist/utils/semantic-comparison-field.js +19 -0
  39. package/dist/utils/time-series-range.d.ts +17 -0
  40. package/dist/utils/time-series-range.d.ts.map +1 -0
  41. package/dist/utils/time-series-range.js +32 -0
  42. package/dist/utils/visibility-projection.d.ts +2 -2
  43. package/dist/utils/visibility-projection.d.ts.map +1 -1
  44. package/dist/utils/visibility-projection.js +29 -6
  45. package/dist/utils/visible-measure-selection.d.ts +2 -2
  46. package/dist/utils/visible-measure-selection.d.ts.map +1 -1
  47. package/package.json +3 -3
@@ -12,7 +12,7 @@
12
12
  * catalog projection or schema compilation therefore cannot advertise something
13
13
  * execution would refuse.
14
14
  */
15
- import type { ProtocolAccessPolicy, ProtocolDeploymentContract, ProtocolEndpointPolicy } from '@hypequery/protocol';
15
+ import type { ProtocolAccessPolicy, ProtocolDeploymentContractAnyVersion, ProtocolEndpointPolicy } from '@hypequery/protocol';
16
16
  import type { DeploymentDataPlanePrincipal } from './principal.js';
17
17
  /**
18
18
  * Whether a principal satisfies an access policy.
@@ -27,9 +27,10 @@ export declare function isDeploymentEndpointAuthorized(endpoint: ProtocolEndpoin
27
27
  export interface AuthorizedDeploymentProjection {
28
28
  /**
29
29
  * A valid contract narrowed to what the principal may see, including any
30
- * dataset retained only to support a join.
30
+ * dataset retained only to support a join. A contract 3 whose narrowing
31
+ * leaves no contract 3 feature is returned as contract 2 (RFC 0015).
31
32
  */
32
- readonly contract: ProtocolDeploymentContract;
33
+ readonly contract: ProtocolDeploymentContractAnyVersion;
33
34
  /**
34
35
  * Datasets addressable as a `query_dataset` target, in contract order.
35
36
  *
@@ -76,5 +77,5 @@ export interface AuthorizedDeploymentProjectionOptions {
76
77
  * projection that could emit an invalid one would move that failure to whatever
77
78
  * read it next.
78
79
  */
79
- export declare function projectAuthorizedDeploymentContract(contract: ProtocolDeploymentContract, principal: DeploymentDataPlanePrincipal | null, options?: AuthorizedDeploymentProjectionOptions): AuthorizedDeploymentProjection;
80
+ export declare function projectAuthorizedDeploymentContract(contract: ProtocolDeploymentContractAnyVersion, principal: DeploymentDataPlanePrincipal | null, options?: AuthorizedDeploymentProjectionOptions): AuthorizedDeploymentProjection;
80
81
  //# sourceMappingURL=authorized-contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authorized-contract.d.ts","sourceRoot":"","sources":["../src/authorized-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAE1B,sBAAsB,EAEvB,MAAM,qBAAqB,CAAC;AAM7B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAInE;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,oBAAoB,EAC5B,SAAS,EAAE,4BAA4B,GAAG,IAAI,GAC7C,OAAO,CAIT;AAED,mFAAmF;AACnF,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,sBAAsB,GAAG,SAAS,EAC5C,SAAS,EAAE,4BAA4B,GAAG,IAAI,GAC7C,OAAO,CAKT;AAwCD,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,0BAA0B,CAAC;IAC9C;;;;;;;;;OASG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,qCAAqC;IACpD;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,0BAA0B,EACpC,SAAS,EAAE,4BAA4B,GAAG,IAAI,EAC9C,OAAO,GAAE,qCAA0C,GAClD,8BAA8B,CA0EhC"}
1
+ {"version":3,"file":"authorized-contract.d.ts","sourceRoot":"","sources":["../src/authorized-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,oCAAoC,EAEpC,sBAAsB,EAEvB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAInE;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,oBAAoB,EAC5B,SAAS,EAAE,4BAA4B,GAAG,IAAI,GAC7C,OAAO,CAIT;AAED,mFAAmF;AACnF,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,sBAAsB,GAAG,SAAS,EAC5C,SAAS,EAAE,4BAA4B,GAAG,IAAI,GAC7C,OAAO,CAKT;AA6CD,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,oCAAoC,CAAC;IACxD;;;;;;;;;OASG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,qCAAqC;IACpD;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,oCAAoC,EAC9C,SAAS,EAAE,4BAA4B,GAAG,IAAI,EAC9C,OAAO,GAAE,qCAA0C,GAClD,8BAA8B,CA4EhC"}
@@ -12,7 +12,7 @@
12
12
  * catalog projection or schema compilation therefore cannot advertise something
13
13
  * execution would refuse.
14
14
  */
15
- import { resolveProtocolVisibleDatasetFields, validateProtocolDeploymentContract, validateProtocolFieldVisibility, } from '@hypequery/protocol';
15
+ import { resolveProtocolVisibleDatasetFields, validateProtocolDeploymentContractAtLowestVersion, validateProtocolFieldVisibility, withDatasetAllowedFilters, } from '@hypequery/protocol';
16
16
  import { missing } from './utils/required-access.js';
17
17
  import { concealDimension, narrowDatasetToVisible } from './utils/visibility-projection.js';
18
18
  /**
@@ -53,19 +53,21 @@ export function isDeploymentEndpointAuthorized(endpoint, principal) {
53
53
  */
54
54
  function narrowToJoin(dataset, reachable, joinable) {
55
55
  // `defaults` describes how to query the dataset directly, which is exactly
56
- // what this principal may not do.
57
- const { defaults: _defaults, endpoint: _endpoint, ...rest } = dataset;
56
+ // what this principal may not do. Segments select rows of a direct query too.
57
+ // Event operations (RFC 0027) are direct queries too.
58
+ const { defaults: _defaults, endpoint: _endpoint, events: _events, ...rest } = dataset;
59
+ // Alternate time axes, like segments, only shape a direct query.
60
+ const { segments: _segments, alternateTimeFields: _alternates, ...withoutSegments } = rest;
58
61
  const timeField = dataset.timeField === undefined ? undefined : String(dataset.timeField);
59
- return {
60
- ...rest,
62
+ return withDatasetAllowedFilters({
63
+ ...withoutSegments,
61
64
  dimensions: reachable
62
65
  ? dataset.dimensions.map(dimension => (joinable === undefined || joinable.has(String(dimension.name))
63
66
  ? dimension
64
67
  : concealDimension(dimension)))
65
68
  : dataset.dimensions.filter(dimension => String(dimension.name) === timeField),
66
69
  measures: [],
67
- filters: [],
68
- };
70
+ }, []);
69
71
  }
70
72
  /**
71
73
  * Projects the contract down to what `principal` may see.
@@ -157,7 +159,7 @@ export function projectAuthorizedDeploymentContract(contract, principal, options
157
159
  .map(dataset => (projected.get(String(dataset.name))
158
160
  ?? narrowToJoin(dataset, reachable.has(String(dataset.name)), joinable(dataset))));
159
161
  return Object.freeze({
160
- contract: validateProtocolDeploymentContract({ ...contract, datasets }),
162
+ contract: validateProtocolDeploymentContractAtLowestVersion({ ...contract, datasets }),
161
163
  queryable: Object.freeze(datasets
162
164
  .filter(dataset => published.has(String(dataset.name)))
163
165
  .map(dataset => String(dataset.name))),
package/dist/bundle.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ProtocolBusinessContext, type ProtocolDeploymentBundleManifest, type ProtocolDeploymentContract } from '@hypequery/protocol';
1
+ import { type ProtocolBusinessContext, type ProtocolDeploymentBundleManifest, type ProtocolDeploymentContractAnyVersion } from '@hypequery/protocol';
2
2
  export declare const DEPLOYMENT_BUNDLE_MANIFEST = "bundle.json";
3
3
  export declare const DEPLOYMENT_BUNDLE_CONTRACT = "deployment.json";
4
4
  export declare const DEPLOYMENT_BUNDLE_BUSINESS_CONTEXT = "business-context.json";
@@ -6,7 +6,7 @@ export interface VerifiedDeploymentBundle {
6
6
  readonly directory: string;
7
7
  readonly manifest: ProtocolDeploymentBundleManifest;
8
8
  readonly identity: string;
9
- readonly contract: ProtocolDeploymentContract;
9
+ readonly contract: ProtocolDeploymentContractAnyVersion;
10
10
  /** Reviewed business context; present only for version 2 bundles. */
11
11
  readonly businessContext?: ProtocolBusinessContext;
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAQA,OAAO,EAKL,KAAK,uBAAuB,EAC5B,KAAK,gCAAgC,EACrC,KAAK,0BAA0B,EAChC,MAAM,qBAAqB,CAAC;AAI7B,eAAO,MAAM,0BAA0B,gBAAgB,CAAC;AACxD,eAAO,MAAM,0BAA0B,oBAAoB,CAAC;AAC5D,eAAO,MAAM,kCAAkC,0BAA0B,CAAC;AAE1E,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,gCAAgC,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,0BAA0B,CAAC;IAC9C,qEAAqE;IACrE,QAAQ,CAAC,eAAe,CAAC,EAAE,uBAAuB,CAAC;CACpD;AAgID,wBAAsB,sBAAsB,CAC1C,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,wBAAwB,CAAC,CAwEnC"}
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAQA,OAAO,EAKL,KAAK,uBAAuB,EAC5B,KAAK,gCAAgC,EACrC,KAAK,oCAAoC,EAC1C,MAAM,qBAAqB,CAAC;AAI7B,eAAO,MAAM,0BAA0B,gBAAgB,CAAC;AACxD,eAAO,MAAM,0BAA0B,oBAAoB,CAAC;AAC5D,eAAO,MAAM,kCAAkC,0BAA0B,CAAC;AAE1E,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,gCAAgC,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,oCAAoC,CAAC;IACxD,qEAAqE;IACrE,QAAQ,CAAC,eAAe,CAAC,EAAE,uBAAuB,CAAC;CACpD;AAgID,wBAAsB,sBAAsB,CAC1C,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,wBAAwB,CAAC,CAwEnC"}
package/dist/bundle.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { constants, lstat, open, readdir, } from 'node:fs/promises';
3
3
  import path from 'node:path';
4
- import { DEFAULT_PROTOCOL_DEPLOYMENT_BUNDLE_LIMITS, prepareProtocolBusinessContext, prepareProtocolDeploymentBundleManifest, prepareProtocolDeploymentContract, } from '@hypequery/protocol';
4
+ import { DEFAULT_PROTOCOL_DEPLOYMENT_BUNDLE_LIMITS, prepareProtocolBusinessContext, prepareProtocolDeploymentBundleManifest, prepareProtocolDeploymentContractAnyVersion, } from '@hypequery/protocol';
5
5
  import { deploymentBundleFiles } from './utils/bundle-files.js';
6
6
  import { readBoundedFile } from './utils/read-bounded-file.js';
7
7
  export const DEPLOYMENT_BUNDLE_MANIFEST = 'bundle.json';
@@ -152,7 +152,7 @@ export async function verifyDeploymentBundle(bundleDirectory) {
152
152
  throw new Error(`Invalid deployment JSON in bundle: ${deployment.path}\n\n`
153
153
  + (error instanceof Error ? error.message : String(error)));
154
154
  }
155
- const preparedContract = prepareProtocolDeploymentContract(contractInput);
155
+ const preparedContract = prepareProtocolDeploymentContractAnyVersion(contractInput);
156
156
  if (!Buffer.from(deploymentBytes).equals(Buffer.from(`${preparedContract.canonical}\n`))) {
157
157
  throw new Error('Deployment JSON must contain canonical JSON followed by one newline.');
158
158
  }
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export type { DeploymentIntakeLimits } from './limits.js';
20
20
  export type { DeploymentAuthenticationInput, DeploymentAuthenticator, DeploymentAuthorizationInput, DeploymentAuthorizer, DeploymentIntake, DeploymentIntakeOptions, DeploymentIntakeRequest, DeploymentIntakeResponse, DeploymentSubmissionResponse, DeploymentSubmissionStore, VerifiedDeploymentSubmission, } from './types.js';
21
21
  export type { DeploymentDataPlanePrincipal } from './principal.js';
22
22
  export { createDeploymentSemanticDataPlane, DeploymentSemanticInvocationError, toProtocolSemanticInvocationFailure, } from './semantic-data-plane.js';
23
- export type { DeploymentSemanticAuthenticationInput, DeploymentSemanticBudget, DeploymentSemanticDataPlane, DeploymentSemanticDataPlaneOptions, DeploymentSemanticExecutionInput, DeploymentSemanticInvocationRequest, DeploymentSemanticContextInput, DeploymentSemanticTenantInput, } from './semantic-data-plane.js';
23
+ export type { DeploymentSemanticAuthenticationInput, DeploymentSemanticBudget, DeploymentSemanticDataPlane, DeploymentSemanticDataPlaneOptions, DeploymentSemanticEventExecutionInput, DeploymentSemanticExecutionInput, DeploymentSemanticInvocationRequest, DeploymentSemanticContextInput, DeploymentSemanticTenantInput, } from './semantic-data-plane.js';
24
24
  export { validateSemanticConstraints, validateSemanticOperation, } from './semantic-operation-validation.js';
25
25
  export type { SemanticOperationLimits, SemanticOperationViolation, } from './semantic-operation-validation.js';
26
26
  export { isDeploymentEndpointAuthorized, projectAuthorizedDeploymentContract, satisfiesDeploymentAccess, } from './authorized-contract.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mapp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sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,YAAY,EACV,6BAA6B,EAC7B,uBAAuB,EACvB,4BAA4B,EAC5B,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,EACL,iCAAiC,EACjC,iCAAiC,EACjC,mCAAmC,GACpC,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,qCAAqC,EACrC,wBAAwB,EACxB,2BAA2B,EAC3B,kCAAkC,EAClC,qCAAqC,EACrC,gCAAgC,EAChC,mCAAmC,EACnC,8BAA8B,EAC9B,6BAA6B,GAC9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,oCAAoC,CAAC;AAC5C,YAAY,EACV,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,oCAAoC,CAAC;AAI5C,OAAO,EACL,8BAA8B,EAC9B,mCAAmC,EACnC,yBAAyB,GAC1B,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,8BAA8B,EAC9B,qCAAqC,GACtC,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Contract-driven checks for RFC 0026 query-scoped calculations.
3
+ *
4
+ * The protocol validator has already proven the envelope: shapes, output
5
+ * names, references between entries, and that partitions name selected
6
+ * dimensions. What remains needs the contract and the caller's visibility:
7
+ * every published input is a measure the caller may see and of a kind the
8
+ * calculation accepts, filter conditions use filters the caller may apply,
9
+ * and the counts stay within the dataset's ceilings.
10
+ */
11
+ import type { ProtocolDatasetQuery, ProtocolDeploymentDatasetAnyVersion } from '@hypequery/protocol';
12
+ interface CalculationViolation {
13
+ readonly message: string;
14
+ readonly path: string;
15
+ }
16
+ /** What the caller may use, already narrowed to its visibility. */
17
+ export interface CalculationSurface {
18
+ readonly measures: ReadonlySet<string>;
19
+ readonly filters: ReadonlyMap<string, ReadonlySet<string>>;
20
+ readonly hasTimeField: boolean;
21
+ }
22
+ /** Every output column a query's calculations add, in output order. */
23
+ export declare function calculationOutputNames(operation: ProtocolDatasetQuery): string[];
24
+ /** How many filter-calculation conditions the query adds to the predicate budget. */
25
+ export declare function calculationConditionCount(operation: ProtocolDatasetQuery): number;
26
+ export declare function validateSemanticCalculations(operation: ProtocolDatasetQuery, dataset: ProtocolDeploymentDatasetAnyVersion, surface: CalculationSurface): readonly CalculationViolation[];
27
+ export {};
28
+ //# sourceMappingURL=semantic-calculation-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic-calculation-validation.d.ts","sourceRoot":"","sources":["../src/semantic-calculation-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,mCAAmC,EAEpC,MAAM,qBAAqB,CAAC;AAG7B,UAAU,oBAAoB;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,mEAAmE;AACnE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC;AAQD,uEAAuE;AACvE,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAMhF;AAED,qFAAqF;AACrF,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,CAEjF;AAED,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,oBAAoB,EAC/B,OAAO,EAAE,mCAAmC,EAC5C,OAAO,EAAE,kBAAkB,GAC1B,SAAS,oBAAoB,EAAE,CAiFjC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Contract-driven checks for RFC 0026 query-scoped calculations.
3
+ *
4
+ * The protocol validator has already proven the envelope: shapes, output
5
+ * names, references between entries, and that partitions name selected
6
+ * dimensions. What remains needs the contract and the caller's visibility:
7
+ * every published input is a measure the caller may see and of a kind the
8
+ * calculation accepts, filter conditions use filters the caller may apply,
9
+ * and the counts stay within the dataset's ceilings.
10
+ */
11
+ import { comparisonField } from './utils/semantic-comparison-field.js';
12
+ const UNFILTERABLE = new Set(['argMax', 'argMin', 'merge']);
13
+ const CUMULATIVE = new Set(['sum', 'count', 'min', 'max']);
14
+ const COMPARE_SUFFIXES = ['_previous', '_change', '_change_pct'];
15
+ /** Every output column a query's calculations add, in output order. */
16
+ export function calculationOutputNames(operation) {
17
+ return (operation.calculations ?? []).flatMap(entry => ('compare' in entry
18
+ ? entry.compare.measures.flatMap(measure => COMPARE_SUFFIXES.map(suffix => `${String(measure)}${suffix}`))
19
+ : [String(entry.name)]));
20
+ }
21
+ /** How many filter-calculation conditions the query adds to the predicate budget. */
22
+ export function calculationConditionCount(operation) {
23
+ return (operation.calculations ?? []).reduce((count, entry) => count + ('filter' in entry ? entry.filter.where.length : 0), 0);
24
+ }
25
+ export function validateSemanticCalculations(operation, dataset, surface) {
26
+ const violations = [];
27
+ const fail = (message, path) => violations.push({ message, path });
28
+ const measures = new Map(dataset.measures.map(measure => [String(measure.name), measure]));
29
+ const dimensions = new Map(dataset.dimensions.map(dimension => [String(dimension.name), dimension]));
30
+ const outputs = new Set();
31
+ /** A published input, or undefined when it reads an earlier output or failed. */
32
+ const published = (name, path) => {
33
+ if (outputs.has(name))
34
+ return undefined;
35
+ const measure = measures.get(name);
36
+ // A hidden measure reads exactly like an unknown one (RFC 0019).
37
+ if (measure === undefined || !surface.measures.has(name)) {
38
+ fail(`Unknown measure "${name}".`, path);
39
+ return undefined;
40
+ }
41
+ return measure;
42
+ };
43
+ const timed = (measure) => measure?.kind === 'shift' || measure?.kind === 'window';
44
+ (operation.calculations ?? []).forEach((entry, index) => {
45
+ const path = `$.operation.calculations[${index}]`;
46
+ if ('filter' in entry) {
47
+ const measure = published(String(entry.filter.measure), `${path}.filter.measure`);
48
+ if (measure !== undefined && measure.kind !== undefined) {
49
+ fail(`A filter calculation must filter a base measure; "${measure.name}" is not one.`, `${path}.filter.measure`);
50
+ }
51
+ else if (measure !== undefined && UNFILTERABLE.has(String(measure.aggregation))) {
52
+ fail(`"${measure.name}" is a ${measure.aggregation} measure, which does not accept filters.`, `${path}.filter.measure`);
53
+ }
54
+ entry.filter.where.forEach((expression, at) => {
55
+ const wherePath = `${path}.filter.where[${at}]`;
56
+ const comparison = comparisonField(expression);
57
+ const operators = comparison === null ? undefined : surface.filters.get(comparison.field);
58
+ if (comparison === null || operators === undefined) {
59
+ fail(`Unknown or unfilterable field "${comparison?.field ?? ''}".`, wherePath);
60
+ return;
61
+ }
62
+ if (!operators.has(comparison.operator)) {
63
+ fail(`Operator "${comparison.operator}" is not allowed on "${comparison.field}".`, `${wherePath}.operator`);
64
+ }
65
+ if (dimensions.get(comparison.field)?.type === 'timestamp' || String(dataset.timeField) === comparison.field) {
66
+ fail(`A filter calculation cannot compare time field "${comparison.field}"; bound time with filters.`, wherePath);
67
+ }
68
+ });
69
+ }
70
+ else if ('shift' in entry) {
71
+ const measure = published(String(entry.shift.measure), `${path}.shift.measure`);
72
+ if (timed(measure))
73
+ fail(`"${measure.name}" is already a ${measure.kind} measure.`, `${path}.shift.measure`);
74
+ }
75
+ else if ('window' in entry) {
76
+ const measure = published(String(entry.window.measure), `${path}.window.measure`);
77
+ if (measure !== undefined && measure.kind !== undefined) {
78
+ fail(`A window calculation must window a base measure; "${measure.name}" is not one.`, `${path}.window.measure`);
79
+ }
80
+ else if (measure !== undefined && 'cumulative' in entry.window && !CUMULATIVE.has(String(measure.aggregation))) {
81
+ fail(`Cannot accumulate ${measure.aggregation}; use sum, count, min, or max.`, `${path}.window.cumulative`);
82
+ }
83
+ }
84
+ else if ('compare' in entry) {
85
+ entry.compare.measures.forEach((name, at) => {
86
+ const measure = outputs.has(String(name)) ? undefined : measures.get(String(name));
87
+ if (timed(measure))
88
+ fail(`"${String(name)}" is already a ${measure.kind} measure.`, `${path}.compare.measures[${at}]`);
89
+ });
90
+ }
91
+ if (('shift' in entry || 'window' in entry || 'compare' in entry) && !surface.hasTimeField) {
92
+ fail('This dataset has no time field, so time calculations do not apply.', path);
93
+ }
94
+ for (const output of 'compare' in entry
95
+ ? entry.compare.measures.flatMap(measure => COMPARE_SUFFIXES.map(suffix => `${String(measure)}${suffix}`))
96
+ : [String(entry.name)]) {
97
+ outputs.add(output);
98
+ }
99
+ });
100
+ if (operation.other !== undefined) {
101
+ const { dimension, measure } = operation.other;
102
+ if (dimensions.get(String(dimension))?.type !== 'string') {
103
+ fail(`"other" groups a string dimension; "${String(dimension)}" is not one.`, '$.operation.other.dimension');
104
+ }
105
+ const ranked = published(String(measure), '$.operation.other.measure');
106
+ if (timed(ranked))
107
+ fail(`"other" cannot rank by ${ranked.kind} measure "${ranked.name}".`, '$.operation.other.measure');
108
+ }
109
+ return violations;
110
+ }
@@ -10,7 +10,7 @@
10
10
  * Execution itself is injected. This module decides whether a call is allowed
11
11
  * and what it is allowed to ask for.
12
12
  */
13
- import type { ProtocolDeploymentContract, ProtocolDeploymentDataset, ProtocolSemanticInvocation, ProtocolSemanticInvocationResult, ProtocolSemanticQuery } from '@hypequery/protocol';
13
+ import type { ProtocolDeploymentContractAnyVersion, ProtocolDeploymentDatasetAnyVersion, ProtocolEventOperation, ProtocolExpression, ProtocolSemanticInvocation, ProtocolSemanticInvocationV2, ProtocolSemanticInvocationResult, ProtocolSemanticQuery } from '@hypequery/protocol';
14
14
  import type { DeploymentDataPlanePrincipal } from './principal.js';
15
15
  import { type SemanticOperationLimits } from './semantic-operation-validation.js';
16
16
  export { DeploymentSemanticInvocationError, toProtocolSemanticInvocationFailure } from './semantic-invocation-errors.js';
@@ -22,20 +22,20 @@ export interface DeploymentSemanticBudget {
22
22
  }
23
23
  export interface DeploymentSemanticAuthenticationInput {
24
24
  readonly credentials: unknown;
25
- readonly invocation: ProtocolSemanticInvocation;
26
- readonly dataset: ProtocolDeploymentDataset;
25
+ readonly invocation: ProtocolSemanticInvocation | ProtocolSemanticInvocationV2;
26
+ readonly dataset: ProtocolDeploymentDatasetAnyVersion;
27
27
  }
28
28
  /** What a provider callback knows about the call it resolves context for. */
29
29
  export interface DeploymentSemanticContextInput {
30
30
  readonly principal: DeploymentDataPlanePrincipal | null;
31
- readonly invocation: ProtocolSemanticInvocation;
32
- readonly dataset: ProtocolDeploymentDataset;
31
+ readonly invocation: ProtocolSemanticInvocation | ProtocolSemanticInvocationV2;
32
+ readonly dataset: ProtocolDeploymentDatasetAnyVersion;
33
33
  }
34
34
  /** The input `resolveTenant` receives; the same as every context resolver's. */
35
35
  export type DeploymentSemanticTenantInput = DeploymentSemanticContextInput;
36
36
  export interface DeploymentSemanticExecutionInput {
37
- readonly deployment: ProtocolDeploymentContract;
38
- readonly dataset: ProtocolDeploymentDataset;
37
+ readonly deployment: ProtocolDeploymentContractAnyVersion;
38
+ readonly dataset: ProtocolDeploymentDatasetAnyVersion;
39
39
  readonly operation: ProtocolSemanticQuery;
40
40
  readonly principal: DeploymentDataPlanePrincipal | null;
41
41
  /**
@@ -47,6 +47,17 @@ export interface DeploymentSemanticExecutionInput {
47
47
  readonly activationRevision: string;
48
48
  readonly signal?: AbortSignal;
49
49
  }
50
+ /** What an RFC 0027 executor receives: the execution input, with a funnel or retention operation. */
51
+ export interface DeploymentSemanticEventExecutionInput extends Omit<DeploymentSemanticExecutionInput, 'operation'> {
52
+ /** The caller's operation, exactly as validated: its `filters` hold only caller filters. */
53
+ readonly operation: ProtocolEventOperation;
54
+ /**
55
+ * The provider's enforced constraints (RFC 0019), kept apart from the
56
+ * operation so a trusted time cutoff never reads as a second caller time
57
+ * range. The executor applies them to the event scan, ANDed with filters.
58
+ */
59
+ readonly constraints: readonly ProtocolExpression[];
60
+ }
50
61
  export interface DeploymentSemanticInvocationRequest {
51
62
  /** An unvalidated invocation record; validated before anything else runs. */
52
63
  readonly invocation: unknown;
@@ -54,7 +65,7 @@ export interface DeploymentSemanticInvocationRequest {
54
65
  readonly signal?: AbortSignal;
55
66
  }
56
67
  export interface DeploymentSemanticDataPlaneOptions {
57
- readonly deployment: ProtocolDeploymentContract;
68
+ readonly deployment: ProtocolDeploymentContractAnyVersion;
58
69
  /** The immutable generation this data plane serves. */
59
70
  readonly activationRevision: string;
60
71
  readonly authenticate?: (input: DeploymentSemanticAuthenticationInput) => Promise<DeploymentDataPlanePrincipal | null>;
@@ -76,6 +87,12 @@ export interface DeploymentSemanticDataPlaneOptions {
76
87
  */
77
88
  readonly resolveConstraints?: (input: DeploymentSemanticContextInput) => Promise<unknown>;
78
89
  readonly execute: (input: DeploymentSemanticExecutionInput) => Promise<unknown>;
90
+ /**
91
+ * Runs RFC 0027 funnel and retention operations. Kept apart from `execute`
92
+ * so an executor written for dataset queries never receives one. Without
93
+ * it, those operations are refused with `unsupported-capability`.
94
+ */
95
+ readonly executeEventOperation?: (input: DeploymentSemanticEventExecutionInput) => Promise<unknown>;
79
96
  /** Server-side ceilings, applied on top of contract and caller limits. */
80
97
  readonly limits?: Partial<SemanticOperationLimits> & {
81
98
  readonly deadlineMs?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"semantic-data-plane.d.ts","sourceRoot":"","sources":["../src/semantic-data-plane.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,0BAA0B,EAC1B,yBAAyB,EAGzB,0BAA0B,EAC1B,gCAAgC,EAChC,qBAAqB,EAEtB,MAAM,qBAAqB,CAAC;AAU7B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MA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C,OAAO,CAAC,CAAC;IAC1F,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,gCAAgC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAChF;;;;OAIG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE,qCAAqC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACpG,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG;QACnD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;KACpC,CAAC;CACH;AAED,MAAM,WAAW,2BAA2B;IAC1C,MAAM,CAAC,OAAO,EAAE,mCAAmC,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;CACjG;AAmBD,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,kCAAkC,GAC1C,2BAA2B,CA+U7B"}
@@ -10,8 +10,9 @@
10
10
  * Execution itself is injected. This module decides whether a call is allowed
11
11
  * and what it is allowed to ask for.
12
12
  */
13
- import { ProtocolSemanticInvocationError, resolveProtocolVisibleDatasetFields, validateProtocolDeploymentContract, validateProtocolExpression, validateProtocolFieldVisibility, validateProtocolSemanticInvocation, validateProtocolSemanticInvocationResult, } from '@hypequery/protocol';
13
+ import { ProtocolSemanticInvocationError, isProtocolEventOperationKind, resolveProtocolVisibleDatasetFields, validateProtocolDeploymentContractAnyVersion, validateProtocolExpression, validateProtocolFieldVisibility, validateProtocolSemanticInvocation, validateProtocolSemanticInvocationV2, validateProtocolSemanticInvocationResult, } from '@hypequery/protocol';
14
14
  import { validateSemanticConstraints, validateSemanticOperation, } from './semantic-operation-validation.js';
15
+ import { validateSemanticEventOperation } from './semantic-event-operation-validation.js';
15
16
  import { DeploymentSemanticInvocationError, fail, throwIfAborted } from './semantic-invocation-errors.js';
16
17
  import { missing } from './utils/required-access.js';
17
18
  import { definedLimits, lowest, tighten } from './utils/semantic-budget-limits.js';
@@ -28,10 +29,14 @@ const DEFAULT_LIMITS = Object.freeze({
28
29
  const REVISION_PATTERN = /^[0-9a-f]{64}$/;
29
30
  /** Provider constraints are policy, not queries; a handful per call is plenty. */
30
31
  const MAX_CONSTRAINTS = 32;
32
+ function isInvocation2(input) {
33
+ return typeof input === 'object' && input !== null && input.version === 2;
34
+ }
31
35
  export function createDeploymentSemanticDataPlane(options) {
32
36
  let deployment;
33
37
  try {
34
- deployment = validateProtocolDeploymentContract(options.deployment);
38
+ // A contract 3 consumer keeps accepting contract 2 (RFC 0015).
39
+ deployment = validateProtocolDeploymentContractAnyVersion(options.deployment);
35
40
  }
36
41
  catch (error) {
37
42
  throw new DeploymentSemanticInvocationError('configuration-invalid', 'HQ_SEMANTIC_CONFIGURATION', 'The semantic data plane requires a valid deployment contract.', { cause: error });
@@ -75,7 +80,11 @@ export function createDeploymentSemanticDataPlane(options) {
75
80
  throwIfAborted(request.signal);
76
81
  let invocation;
77
82
  try {
78
- invocation = validateProtocolSemanticInvocation(request.invocation);
83
+ // Invocation 2 (RFC 0015) carries segments and sub-day grains; a request
84
+ // that uses neither is invocation 1, and each validator enforces that.
85
+ invocation = isInvocation2(request.invocation)
86
+ ? validateProtocolSemanticInvocationV2(request.invocation)
87
+ : validateProtocolSemanticInvocation(request.invocation);
79
88
  }
80
89
  catch (error) {
81
90
  fail('input-invalid', 'HQ_SEMANTIC_INVOCATION_INVALID', 'The invocation record is invalid.', {
@@ -213,39 +222,56 @@ export function createDeploymentSemanticDataPlane(options) {
213
222
  // are published in the contract precisely so a gateway can apply them
214
223
  // without loading the authoring package, and a set of ceilings where only
215
224
  // one of the four binds is not a set of ceilings.
216
- const violations = validateSemanticOperation(operation, dataset, datasets, {
217
- maxRows: budget.maxRows,
218
- maxOffset: configured.maxOffset,
219
- maxDimensions: tighten(dataset.limits?.maxDimensions, configured.maxDimensions),
220
- maxMeasures: tighten(dataset.limits?.maxMeasures, configured.maxMeasures),
221
- maxFilters: tighten(dataset.limits?.maxFilters, configured.maxFilters) - constraints.length,
222
- }, visible);
225
+ const maxFilters = tighten(dataset.limits?.maxFilters, configured.maxFilters) - constraints.length;
226
+ const eventOperation = isProtocolEventOperationKind(operation.kind) ? operation : undefined;
227
+ const violations = eventOperation !== undefined
228
+ ? validateSemanticEventOperation(eventOperation, dataset, datasets, {
229
+ maxRows: budget.maxRows,
230
+ maxFilters,
231
+ maxDimensions: tighten(dataset.limits?.maxDimensions, configured.maxDimensions),
232
+ }, visible)
233
+ : validateSemanticOperation(operation, dataset, datasets, {
234
+ maxRows: budget.maxRows,
235
+ maxOffset: configured.maxOffset,
236
+ maxDimensions: tighten(dataset.limits?.maxDimensions, configured.maxDimensions),
237
+ maxMeasures: tighten(dataset.limits?.maxMeasures, configured.maxMeasures),
238
+ maxFilters,
239
+ }, visible);
223
240
  if (violations.length > 0) {
224
241
  const [first] = violations;
225
242
  fail('input-invalid', 'HQ_SEMANTIC_INPUT_INVALID', first.message, { path: first.path });
226
243
  }
227
244
  throwIfAborted(request.signal);
228
- const selected = withVisibleDefaultMeasures(operation, dataset, visible);
245
+ if (eventOperation !== undefined && !options.executeEventOperation) {
246
+ fail('unsupported-capability', 'HQ_SEMANTIC_UNSUPPORTED_OPERATION', `This deployment cannot run ${eventOperation.kind} operations.`, { path: '$.operation.kind' });
247
+ }
248
+ const query = operation;
249
+ const selected = eventOperation !== undefined ? query : withVisibleDefaultMeasures(query, dataset, visible);
229
250
  const maxMeasures = tighten(dataset.limits?.maxMeasures, configured.maxMeasures);
230
- if (selected !== operation && selected.kind === 'dataset' && (selected.measures?.length ?? 0) > maxMeasures) {
251
+ if (selected !== query && selected.kind === 'dataset' && (selected.measures?.length ?? 0) > maxMeasures) {
231
252
  // The caller asked for the default selection; it narrowed to more
232
253
  // measures than one query may select, so the caller has to choose.
233
254
  fail('input-invalid', 'HQ_SEMANTIC_INPUT_INVALID', `Select at most ${maxMeasures} measures explicitly.`, { path: '$.operation.measures' });
234
255
  }
235
256
  let output;
236
257
  try {
237
- output = await options.execute({
258
+ const shared = {
238
259
  deployment,
239
260
  dataset,
240
- operation: constraints.length === 0
241
- ? selected
242
- : Object.freeze({ ...selected, filters: [...(selected.filters ?? []), ...constraints] }),
243
261
  principal,
244
262
  tenant,
245
263
  budget,
246
264
  activationRevision: options.activationRevision,
247
265
  ...(request.signal === undefined ? {} : { signal: request.signal }),
248
- });
266
+ };
267
+ output = eventOperation !== undefined
268
+ ? await options.executeEventOperation({ ...shared, operation: eventOperation, constraints })
269
+ : await options.execute({
270
+ ...shared,
271
+ operation: constraints.length === 0
272
+ ? selected
273
+ : Object.freeze({ ...selected, filters: [...(selected.filters ?? []), ...constraints] }),
274
+ });
249
275
  }
250
276
  catch (error) {
251
277
  if (error instanceof DeploymentSemanticInvocationError)
@@ -289,7 +315,7 @@ export function createDeploymentSemanticDataPlane(options) {
289
315
  // validation already proved it is no larger than the budget. An executor
290
316
  // that returns more rows than were requested widened the request just as
291
317
  // surely as one that exceeded the budget.
292
- const maxRows = Math.min(budget.maxRows, operation.limit ?? budget.maxRows);
318
+ const maxRows = Math.min(budget.maxRows, (eventOperation === undefined ? query.limit : undefined) ?? budget.maxRows);
293
319
  if (result.data.length > maxRows) {
294
320
  fail('budget-exceeded', 'HQ_SEMANTIC_BUDGET_EXCEEDED', `The result has ${result.data.length} rows; the effective limit is ${maxRows}.`);
295
321
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Contract-driven validation of RFC 0027 event operations (funnel, retention).
3
+ *
4
+ * The protocol validator already checked syntax, closed records and
5
+ * structural limits. What remains depends on the contract and the caller:
6
+ * whether the dataset declares events, whether every field exists and may be
7
+ * used by this principal, the bounded time range, and the row budget.
8
+ */
9
+ import { type ProtocolDeploymentDatasetAnyVersion, type ProtocolEventOperation, type ProtocolVisibleDatasetFields } from '@hypequery/protocol';
10
+ import { type SemanticOperationViolation } from './semantic-operation-validation.js';
11
+ export interface SemanticEventOperationLimits {
12
+ /** Largest row count the result may have after every ceiling is applied. */
13
+ readonly maxRows: number;
14
+ /** Filters plus every condition, after enforced constraints are counted. */
15
+ readonly maxFilters: number;
16
+ /** Grouping fields: the entity plus each breakdown dimension. */
17
+ readonly maxDimensions: number;
18
+ }
19
+ /**
20
+ * Validates one RFC 0027 operation against the contract that will serve it.
21
+ * Returns every violation, so an agent correcting a call sees the whole
22
+ * problem in one round trip. Hidden fields fail exactly like unknown ones.
23
+ */
24
+ export declare function validateSemanticEventOperation(operation: ProtocolEventOperation, dataset: ProtocolDeploymentDatasetAnyVersion, datasets: ReadonlyMap<string, ProtocolDeploymentDatasetAnyVersion>, limits: SemanticEventOperationLimits, visible?: ProtocolVisibleDatasetFields): readonly SemanticOperationViolation[];
25
+ //# sourceMappingURL=semantic-event-operation-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic-event-operation-validation.d.ts","sourceRoot":"","sources":["../src/semantic-event-operation-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAGL,KAAK,mCAAmC,EACxC,KAAK,sBAAsB,EAE3B,KAAK,4BAA4B,EAClC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,KAAK,0BAA0B,EAChC,MAAM,oCAAoC,CAAC;AAW5C,MAAM,WAAW,4BAA4B;IAC3C,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,iEAAiE;IACjE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AA4FD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,sBAAsB,EACjC,OAAO,EAAE,mCAAmC,EAC5C,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,mCAAmC,CAAC,EAClE,MAAM,EAAE,4BAA4B,EACpC,OAAO,CAAC,EAAE,4BAA4B,GACrC,SAAS,0BAA0B,EAAE,CA0HvC"}