@hypequery/datasets 0.32.0 → 0.34.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.
- package/dist/agent-catalog.d.ts +3 -3
- package/dist/agent-catalog.d.ts.map +1 -1
- package/dist/cache/protocol-cache-keys.d.ts.map +1 -1
- package/dist/cache/protocol-cache-keys.js +25 -1
- package/dist/cache/query-signature.d.ts.map +1 -1
- package/dist/cache/query-signature.js +16 -5
- package/dist/catalog.d.ts +5 -1
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +9 -0
- package/dist/client-contract/build-from-deployment.d.ts +2 -2
- package/dist/client-contract/build-from-deployment.d.ts.map +1 -1
- package/dist/client-contract/build-from-deployment.js +7 -0
- package/dist/cloud-publication.d.ts +3 -3
- package/dist/cloud-publication.d.ts.map +1 -1
- package/dist/cloud-publishing.d.ts +2 -2
- package/dist/cloud-publishing.d.ts.map +1 -1
- package/dist/codegen/dataset-source.d.ts.map +1 -1
- package/dist/codegen/dataset-source.js +4 -1
- package/dist/contract-3-authoring.fixture.d.ts +103 -0
- package/dist/contract-3-authoring.fixture.d.ts.map +1 -0
- package/dist/contract-3-authoring.fixture.js +40 -0
- package/dist/contract.d.ts +5 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +9 -0
- package/dist/dataset-compilation.d.ts +3 -0
- package/dist/dataset-compilation.d.ts.map +1 -1
- package/dist/dataset-query.d.ts +5 -0
- package/dist/dataset-query.d.ts.map +1 -1
- package/dist/dataset.d.ts.map +1 -1
- package/dist/dataset.js +12 -2
- package/dist/event-operations.d.ts +43 -0
- package/dist/event-operations.d.ts.map +1 -0
- package/dist/event-operations.js +137 -0
- package/dist/execution-capabilities.d.ts +2 -1
- package/dist/execution-capabilities.d.ts.map +1 -1
- package/dist/execution-capabilities.js +1 -1
- package/dist/execution-capabilities.json +6 -6
- package/dist/executor.d.ts +13 -0
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +42 -8
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/portable-execution-errors.d.ts +11 -0
- package/dist/portable-execution-errors.d.ts.map +1 -1
- package/dist/portable-execution-errors.js +14 -0
- package/dist/portable-executor.d.ts +22 -5
- package/dist/portable-executor.d.ts.map +1 -1
- package/dist/portable-executor.js +64 -5
- package/dist/protocol-adapter.d.ts +12 -0
- package/dist/protocol-adapter.d.ts.map +1 -1
- package/dist/protocol-adapter.js +30 -8
- package/dist/protocol-deployment-adapter.d.ts +10 -3
- package/dist/protocol-deployment-adapter.d.ts.map +1 -1
- package/dist/protocol-deployment-adapter.js +60 -26
- package/dist/protocol-rehydrate.d.ts +3 -16
- package/dist/protocol-rehydrate.d.ts.map +1 -1
- package/dist/protocol-rehydrate.js +71 -11
- package/dist/query-builder-protocol.d.ts +10 -0
- package/dist/query-builder-protocol.d.ts.map +1 -1
- package/dist/query-planner.d.ts.map +1 -1
- package/dist/query-planner.js +3 -1
- package/dist/relationship-check.d.ts.map +1 -1
- package/dist/relationship-check.js +2 -0
- package/dist/semantic-planner.d.ts.map +1 -1
- package/dist/semantic-planner.js +16 -3
- package/dist/types.d.ts +109 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/agent-catalog-projection.d.ts +2 -2
- package/dist/utils/agent-catalog-projection.d.ts.map +1 -1
- package/dist/utils/agent-catalog-projection.js +31 -2
- package/dist/utils/build-dataset-query-builder.d.ts.map +1 -1
- package/dist/utils/build-dataset-query-builder.js +4 -8
- package/dist/utils/calculation-stage-sql.d.ts +31 -0
- package/dist/utils/calculation-stage-sql.d.ts.map +1 -0
- package/dist/utils/calculation-stage-sql.js +98 -0
- package/dist/utils/compile-calculated-dataset-query.d.ts +24 -0
- package/dist/utils/compile-calculated-dataset-query.d.ts.map +1 -0
- package/dist/utils/compile-calculated-dataset-query.js +133 -0
- package/dist/utils/compile-dataset-query.d.ts.map +1 -1
- package/dist/utils/compile-dataset-query.js +11 -3
- package/dist/utils/dataset-definition-validation.d.ts.map +1 -1
- package/dist/utils/dataset-definition-validation.js +90 -6
- package/dist/utils/dataset-events.d.ts +19 -0
- package/dist/utils/dataset-events.d.ts.map +1 -0
- package/dist/utils/dataset-events.js +46 -0
- package/dist/utils/dataset-having.d.ts.map +1 -1
- package/dist/utils/dataset-having.js +6 -1
- package/dist/utils/dataset-query-result.d.ts.map +1 -1
- package/dist/utils/dataset-query-result.js +7 -1
- package/dist/utils/dataset-query-validation.d.ts +1 -1
- package/dist/utils/dataset-query-validation.d.ts.map +1 -1
- package/dist/utils/dataset-query-validation.js +25 -47
- package/dist/utils/dataset-source.d.ts +2 -2
- package/dist/utils/dataset-source.d.ts.map +1 -1
- package/dist/utils/dataset-source.js +8 -1
- package/dist/utils/dimension-selection-overrides.d.ts +19 -0
- package/dist/utils/dimension-selection-overrides.d.ts.map +1 -0
- package/dist/utils/dimension-selection-overrides.js +22 -0
- package/dist/utils/event-breakdown-sql.d.ts +15 -0
- package/dist/utils/event-breakdown-sql.d.ts.map +1 -0
- package/dist/utils/event-breakdown-sql.js +17 -0
- package/dist/utils/event-condition-sql.d.ts +18 -0
- package/dist/utils/event-condition-sql.d.ts.map +1 -0
- package/dist/utils/event-condition-sql.js +63 -0
- package/dist/utils/event-operation-shape.d.ts +8 -0
- package/dist/utils/event-operation-shape.d.ts.map +1 -0
- package/dist/utils/event-operation-shape.js +66 -0
- package/dist/utils/event-operation-spec.d.ts +43 -0
- package/dist/utils/event-operation-spec.d.ts.map +1 -0
- package/dist/utils/event-operation-spec.js +68 -0
- package/dist/utils/event-range-span.d.ts +4 -0
- package/dist/utils/event-range-span.d.ts.map +1 -0
- package/dist/utils/event-range-span.js +22 -0
- package/dist/utils/event-result-values.d.ts +8 -0
- package/dist/utils/event-result-values.d.ts.map +1 -0
- package/dist/utils/event-result-values.js +21 -0
- package/dist/utils/event-source-sql.d.ts +38 -0
- package/dist/utils/event-source-sql.d.ts.map +1 -0
- package/dist/utils/event-source-sql.js +71 -0
- package/dist/utils/filter-predicate-tree.d.ts +28 -0
- package/dist/utils/filter-predicate-tree.d.ts.map +1 -0
- package/dist/utils/filter-predicate-tree.js +80 -0
- package/dist/utils/filter-tree.d.ts +42 -0
- package/dist/utils/filter-tree.d.ts.map +1 -0
- package/dist/utils/filter-tree.js +164 -0
- package/dist/utils/filtered-aggregation-sql.d.ts.map +1 -1
- package/dist/utils/filtered-aggregation-sql.js +3 -0
- package/dist/utils/funnel-rows.d.ts +10 -0
- package/dist/utils/funnel-rows.d.ts.map +1 -0
- package/dist/utils/funnel-rows.js +30 -0
- package/dist/utils/funnel-sql.d.ts +18 -0
- package/dist/utils/funnel-sql.d.ts.map +1 -0
- package/dist/utils/funnel-sql.js +104 -0
- package/dist/utils/metric-derived-query.d.ts.map +1 -1
- package/dist/utils/metric-derived-query.js +4 -5
- package/dist/utils/metric-query-builder.d.ts.map +1 -1
- package/dist/utils/metric-query-builder.js +4 -5
- package/dist/utils/metric-query-validation.d.ts.map +1 -1
- package/dist/utils/metric-query-validation.js +18 -7
- package/dist/utils/other-bucket-sql.d.ts +23 -0
- package/dist/utils/other-bucket-sql.d.ts.map +1 -0
- package/dist/utils/other-bucket-sql.js +51 -0
- package/dist/utils/portable-aggregations.d.ts +10 -6
- package/dist/utils/portable-aggregations.d.ts.map +1 -1
- package/dist/utils/portable-aggregations.js +13 -8
- package/dist/utils/portable-grains.d.ts +17 -8
- package/dist/utils/portable-grains.d.ts.map +1 -1
- package/dist/utils/portable-grains.js +26 -11
- package/dist/utils/portable-query-calculations.d.ts +14 -0
- package/dist/utils/portable-query-calculations.d.ts.map +1 -0
- package/dist/utils/portable-query-calculations.js +31 -0
- package/dist/utils/portable-semantic-query.d.ts.map +1 -1
- package/dist/utils/portable-semantic-query.js +27 -1
- package/dist/utils/protocol-contract-3.d.ts +30 -0
- package/dist/utils/protocol-contract-3.d.ts.map +1 -0
- package/dist/utils/protocol-contract-3.js +93 -0
- package/dist/utils/protocol-metric-capabilities.d.ts.map +1 -1
- package/dist/utils/protocol-metric-capabilities.js +2 -1
- package/dist/utils/protocol-metric-expressions.d.ts.map +1 -1
- package/dist/utils/protocol-metric-expressions.js +6 -1
- package/dist/utils/protocol-rehydrate-filters.js +2 -1
- package/dist/utils/protocol-rehydrate-time-keys.d.ts +5 -0
- package/dist/utils/protocol-rehydrate-time-keys.d.ts.map +1 -0
- package/dist/utils/protocol-rehydrate-time-keys.js +5 -0
- package/dist/utils/query-calculation-errors.d.ts +6 -0
- package/dist/utils/query-calculation-errors.d.ts.map +1 -0
- package/dist/utils/query-calculation-errors.js +9 -0
- package/dist/utils/query-calculation-formula.d.ts +19 -0
- package/dist/utils/query-calculation-formula.d.ts.map +1 -0
- package/dist/utils/query-calculation-formula.js +77 -0
- package/dist/utils/query-calculation-outputs.d.ts +24 -0
- package/dist/utils/query-calculation-outputs.d.ts.map +1 -0
- package/dist/utils/query-calculation-outputs.js +72 -0
- package/dist/utils/query-calculation-plan.d.ts +67 -0
- package/dist/utils/query-calculation-plan.d.ts.map +1 -0
- package/dist/utils/query-calculation-plan.js +416 -0
- package/dist/utils/query-calculation-types.d.ts +97 -0
- package/dist/utils/query-calculation-types.d.ts.map +1 -0
- package/dist/utils/query-calculation-types.js +8 -0
- package/dist/utils/query-field-references.d.ts.map +1 -1
- package/dist/utils/query-field-references.js +2 -1
- package/dist/utils/query-filter-errors.d.ts +11 -0
- package/dist/utils/query-filter-errors.d.ts.map +1 -0
- package/dist/utils/query-filter-errors.js +65 -0
- package/dist/utils/query-timezone.d.ts +6 -3
- package/dist/utils/query-timezone.d.ts.map +1 -1
- package/dist/utils/query-timezone.js +5 -1
- package/dist/utils/relationship-builder-plan.d.ts.map +1 -1
- package/dist/utils/relationship-builder-plan.js +2 -1
- package/dist/utils/relationship-fields.d.ts.map +1 -1
- package/dist/utils/relationship-fields.js +5 -0
- package/dist/utils/relationship-measure-sql.d.ts.map +1 -1
- package/dist/utils/relationship-measure-sql.js +2 -0
- package/dist/utils/relationship-validation.d.ts +3 -1
- package/dist/utils/relationship-validation.d.ts.map +1 -1
- package/dist/utils/relationship-validation.js +8 -4
- package/dist/utils/relative-date-filters.d.ts +21 -0
- package/dist/utils/relative-date-filters.d.ts.map +1 -0
- package/dist/utils/relative-date-filters.js +86 -0
- package/dist/utils/relative-date-range.d.ts +20 -0
- package/dist/utils/relative-date-range.d.ts.map +1 -0
- package/dist/utils/relative-date-range.js +75 -0
- package/dist/utils/retention-rows.d.ts +9 -0
- package/dist/utils/retention-rows.d.ts.map +1 -0
- package/dist/utils/retention-rows.js +30 -0
- package/dist/utils/retention-sql.d.ts +16 -0
- package/dist/utils/retention-sql.d.ts.map +1 -0
- package/dist/utils/retention-sql.js +68 -0
- package/dist/utils/scoped-dataset-source.d.ts.map +1 -1
- package/dist/utils/scoped-dataset-source.js +4 -0
- package/dist/utils/segments.d.ts +3 -2
- package/dist/utils/segments.d.ts.map +1 -1
- package/dist/utils/segments.js +5 -4
- package/dist/utils/semantic-query-syntax.d.ts.map +1 -1
- package/dist/utils/semantic-query-syntax.js +8 -2
- package/dist/utils/sql-dataset-source.d.ts +36 -0
- package/dist/utils/sql-dataset-source.d.ts.map +1 -0
- package/dist/utils/sql-dataset-source.js +126 -0
- package/dist/utils/time-axis-bounds.d.ts +11 -4
- package/dist/utils/time-axis-bounds.d.ts.map +1 -1
- package/dist/utils/time-axis-bounds.js +14 -6
- package/dist/utils/time-measure-axis.d.ts +2 -2
- package/dist/utils/time-measure-axis.d.ts.map +1 -1
- package/dist/utils/time-measure-axis.js +13 -3
- package/dist/utils/time-measure-dataset-sql.d.ts +1 -1
- package/dist/utils/time-measure-dataset-sql.d.ts.map +1 -1
- package/dist/utils/time-measure-dataset-sql.js +15 -5
- package/dist/utils/time-measure-source-sql.d.ts +2 -2
- package/dist/utils/time-measure-source-sql.d.ts.map +1 -1
- package/dist/utils/time-measure-source-sql.js +7 -8
- package/dist/utils/time-query-measures.d.ts +5 -0
- package/dist/utils/time-query-measures.d.ts.map +1 -1
- package/dist/utils/time-query-measures.js +7 -0
- package/dist/utils/unsupported-contract-reasons.d.ts +5 -1
- package/dist/utils/unsupported-contract-reasons.d.ts.map +1 -1
- package/dist/utils/unsupported-contract-reasons.js +5 -1
- package/package.json +3 -3
|
@@ -53,3 +53,17 @@ export class PortableExecutionTenantError extends PortableExecutionError {
|
|
|
53
53
|
this.name = 'PortableExecutionTenantError';
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Signalled when a query the protocol validator accepted still cannot be
|
|
58
|
+
* planned against this dataset, such as an RFC 0026 calculation over a measure
|
|
59
|
+
* of the wrong kind or a time measure without a bounded range. The caller can
|
|
60
|
+
* correct it, so it is `input-invalid` rather than an executor failure.
|
|
61
|
+
*/
|
|
62
|
+
export class PortableExecutionInputError extends PortableExecutionError {
|
|
63
|
+
code = 'HQ_SEMANTIC_INPUT_INVALID';
|
|
64
|
+
category = 'input-invalid';
|
|
65
|
+
constructor(message) {
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = 'PortableExecutionInputError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { PortableExecutionUnsupportedError, PortableExecutionBudgetError, PortableExecutionTenantError } from './portable-execution-errors.js';
|
|
1
|
+
export { PortableExecutionInputError, PortableExecutionUnsupportedError, PortableExecutionBudgetError, PortableExecutionTenantError, } from './portable-execution-errors.js';
|
|
2
2
|
/**
|
|
3
3
|
* Portable native execution of a semantic invocation.
|
|
4
4
|
*
|
|
@@ -14,9 +14,9 @@ export { PortableExecutionUnsupportedError, PortableExecutionBudgetError, Portab
|
|
|
14
14
|
* that one. A caller wires the returned function into the data plane's injected
|
|
15
15
|
* `execute` slot.
|
|
16
16
|
*/
|
|
17
|
-
import type {
|
|
17
|
+
import type { ProtocolDeploymentDatasetAnyVersion, ProtocolEventOperation, ProtocolExpression, ProtocolSemanticInvocationResult, ProtocolSemanticQuery } from '@hypequery/protocol';
|
|
18
18
|
import type { DatasetCompilation, DatasetCompilationDescription } from './dataset-compilation.js';
|
|
19
|
-
import type
|
|
19
|
+
import { type QueryBuilderFactoryInput } from './query-builder-protocol.js';
|
|
20
20
|
/** Ceilings the data plane already reduced to the most restrictive value. */
|
|
21
21
|
export interface PortableSemanticBudget {
|
|
22
22
|
readonly maxRows: number;
|
|
@@ -30,9 +30,9 @@ export interface PortableSemanticBudget {
|
|
|
30
30
|
*/
|
|
31
31
|
export interface PortableSemanticExecutionInput {
|
|
32
32
|
readonly deployment: {
|
|
33
|
-
readonly datasets: readonly
|
|
33
|
+
readonly datasets: readonly ProtocolDeploymentDatasetAnyVersion[];
|
|
34
34
|
};
|
|
35
|
-
readonly dataset:
|
|
35
|
+
readonly dataset: ProtocolDeploymentDatasetAnyVersion;
|
|
36
36
|
readonly operation: ProtocolSemanticQuery;
|
|
37
37
|
/** Resolved by the provider callback; never caller-supplied. */
|
|
38
38
|
readonly tenant: unknown;
|
|
@@ -41,6 +41,15 @@ export interface PortableSemanticExecutionInput {
|
|
|
41
41
|
readonly activationRevision: string;
|
|
42
42
|
readonly signal?: AbortSignal;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* The data plane's RFC 0027 execution input: the same fields, with a funnel
|
|
46
|
+
* or retention operation and, apart from it, the provider's enforced constraints.
|
|
47
|
+
*/
|
|
48
|
+
export interface PortableEventExecutionInput extends Omit<PortableSemanticExecutionInput, 'operation'> {
|
|
49
|
+
readonly operation: ProtocolEventOperation;
|
|
50
|
+
/** RFC 0019 enforced constraints, applied to the scan as trusted context. */
|
|
51
|
+
readonly constraints?: readonly ProtocolExpression[];
|
|
52
|
+
}
|
|
44
53
|
export interface PortableSemanticExecutorOptions {
|
|
45
54
|
readonly queryBuilder: QueryBuilderFactoryInput;
|
|
46
55
|
/**
|
|
@@ -50,6 +59,12 @@ export interface PortableSemanticExecutorOptions {
|
|
|
50
59
|
* `CLOUD-09` owns the bounded multi-release cache.
|
|
51
60
|
*/
|
|
52
61
|
readonly cacheRebuiltCatalogs?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Clock that resolves `inDateRange` filters (RFC 0029), read once per call.
|
|
64
|
+
* Defaults to the system clock. The request carries no clock: a caller
|
|
65
|
+
* never decides what "today" is.
|
|
66
|
+
*/
|
|
67
|
+
readonly now?: () => Date;
|
|
53
68
|
}
|
|
54
69
|
export interface PortableDatasetCompilation extends DatasetCompilation {
|
|
55
70
|
readonly activationRevision: string;
|
|
@@ -66,6 +81,8 @@ export interface PortableSemanticRuntime {
|
|
|
66
81
|
*/
|
|
67
82
|
compile(input: PortableSemanticExecutionInput): PortableDatasetCompilation;
|
|
68
83
|
execute(input: PortableSemanticExecutionInput): Promise<ProtocolSemanticInvocationResult>;
|
|
84
|
+
/** RFC 0027 funnels and retention; wire into the data plane's `executeEventOperation`. */
|
|
85
|
+
executeEventOperation(input: PortableEventExecutionInput): Promise<ProtocolSemanticInvocationResult>;
|
|
69
86
|
}
|
|
70
87
|
/** Shared portable runtime for provider-side authoring preview and execution. */
|
|
71
88
|
export declare function createPortableSemanticRuntime(options: PortableSemanticExecutorOptions): PortableSemanticRuntime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portable-executor.d.ts","sourceRoot":"","sources":["../src/portable-executor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"portable-executor.d.ts","sourceRoot":"","sources":["../src/portable-executor.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,2BAA2B,EAC3B,iCAAiC,EACjC,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,gCAAgC,CAAC;AAUxC;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,mCAAmC,EACnC,sBAAsB,EACtB,kBAAkB,EAClB,gCAAgC,EAChC,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAQlG,OAAO,EAAyB,KAAK,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACnG,6EAA6E;AAC7E,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED;;;;GAIG;AACH,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,UAAU,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,mCAAmC,EAAE,CAAA;KAAE,CAAC;IAC3F,QAAQ,CAAC,OAAO,EAAE,mCAAmC,CAAC;IACtD,QAAQ,CAAC,SAAS,EAAE,qBAAqB,CAAC;IAC1C,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC;IACxC,yEAAyE;IACzE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,2BAA4B,SAAQ,IAAI,CAAC,8BAA8B,EAAE,WAAW,CAAC;IACpG,QAAQ,CAAC,SAAS,EAAE,sBAAsB,CAAC;IAC3C,6EAA6E;IAC7E,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;CACtD;AAED,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,YAAY,EAAE,wBAAwB,CAAC;IAChD;;;;;OAKG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IACxC;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAID,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,IAAI,6BAA6B,GAAG;QAAE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC;IACpF,MAAM,IAAI,6BAA6B,GAAG;QAAE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC;CACnF;AAED,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,OAAO,CAAC,KAAK,EAAE,8BAA8B,GAAG,0BAA0B,CAAC;IAC3E,OAAO,CAAC,KAAK,EAAE,8BAA8B,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;IAC1F,0FAA0F;IAC1F,qBAAqB,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;CACtG;AAED,iFAAiF;AACjF,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,+BAA+B,GACvC,uBAAuB,CAwJzB;AAED,2EAA2E;AAC3E,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,CAAC,KAAK,EAAE,8BAA8B,KAAK,OAAO,CAAC,gCAAgC,CAAC,CAEtF"}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import { PortableExecutionUnsupportedError, PortableExecutionTenantError } from './portable-execution-errors.js';
|
|
2
|
-
export { PortableExecutionUnsupportedError, PortableExecutionBudgetError, PortableExecutionTenantError } from './portable-execution-errors.js';
|
|
1
|
+
import { PortableExecutionInputError, PortableExecutionUnsupportedError, PortableExecutionTenantError, } from './portable-execution-errors.js';
|
|
2
|
+
export { PortableExecutionInputError, PortableExecutionUnsupportedError, PortableExecutionBudgetError, PortableExecutionTenantError, } from './portable-execution-errors.js';
|
|
3
|
+
import { hasQueryCalculations } from './utils/query-calculation-outputs.js';
|
|
4
|
+
import { withResolvedRelativeDates } from './utils/relative-date-filters.js';
|
|
5
|
+
import { calculatedDatasetQueryErrors } from './utils/compile-calculated-dataset-query.js';
|
|
6
|
+
import { unsupportedStageMessage } from './utils/other-bucket-sql.js';
|
|
7
|
+
import { resolveDatasetSqlDialect } from './utils/dataset-sql-dialect.js';
|
|
3
8
|
import { tenantRuntime, semanticQuery } from './utils/portable-semantic-query.js';
|
|
4
9
|
import { bounded } from './utils/portable-result-budget.js';
|
|
5
10
|
import { withDeadline } from './utils/portable-execution-deadline.js';
|
|
11
|
+
import { prepareEventOperation } from './event-operations.js';
|
|
12
|
+
import { eventConstraintFilters, eventOperationSpec } from './utils/event-operation-spec.js';
|
|
6
13
|
import { createDatasetClient } from './executor.js';
|
|
7
14
|
import { rehydrateProtocolDatasets, UNSUPPORTED_CONTRACT_REASONS, UnsupportedContractFeatureError, } from './protocol-rehydrate.js';
|
|
15
|
+
import { toQueryBuilderFactory } from './query-builder-protocol.js';
|
|
8
16
|
/** Shared portable runtime for provider-side authoring preview and execution. */
|
|
9
17
|
export function createPortableSemanticRuntime(options) {
|
|
10
|
-
const
|
|
18
|
+
const clock = options.now ?? (() => new Date());
|
|
19
|
+
const client = createDatasetClient({
|
|
20
|
+
queryBuilder: options.queryBuilder,
|
|
21
|
+
...(options.now === undefined ? {} : { now: options.now }),
|
|
22
|
+
});
|
|
11
23
|
let memo;
|
|
12
24
|
function registryFor(input) {
|
|
13
25
|
if (options.cacheRebuiltCatalogs !== false && memo?.revision === input.activationRevision) {
|
|
@@ -31,7 +43,7 @@ export function createPortableSemanticRuntime(options) {
|
|
|
31
43
|
memo = { revision: input.activationRevision, registry };
|
|
32
44
|
return registry;
|
|
33
45
|
}
|
|
34
|
-
function
|
|
46
|
+
function resolveTarget(input) {
|
|
35
47
|
const registry = registryFor(input);
|
|
36
48
|
const rebuilt = registry[String(input.dataset.name)];
|
|
37
49
|
if (rebuilt === undefined) {
|
|
@@ -49,10 +61,54 @@ export function createPortableSemanticRuntime(options) {
|
|
|
49
61
|
throw new PortableExecutionTenantError(`Dataset "${String(input.dataset.name)}" declares no tenant field, so a resolved tenant `
|
|
50
62
|
+ 'cannot be applied to it.');
|
|
51
63
|
}
|
|
52
|
-
const query = semanticQuery(input.operation, input.budget.maxRows);
|
|
53
64
|
const context = tenant === undefined ? {} : { runtime: { tenant } };
|
|
65
|
+
return { target, context };
|
|
66
|
+
}
|
|
67
|
+
function resolve(input) {
|
|
68
|
+
const { target, context } = resolveTarget(input);
|
|
69
|
+
let query = semanticQuery(input.operation, input.budget.maxRows);
|
|
70
|
+
if (hasQueryCalculations(query)) {
|
|
71
|
+
// RFC 0029: resolve relative ranges at one reading of the clock, as the
|
|
72
|
+
// client would, so this check and the run see the same absolute bounds.
|
|
73
|
+
query = withResolvedRelativeDates(target, query, clock());
|
|
74
|
+
// RFC 0026: a calculation the dataset cannot satisfy is the caller's to fix.
|
|
75
|
+
const { errors, plan } = calculatedDatasetQueryErrors(target, query, context);
|
|
76
|
+
if (errors.length > 0 || plan === undefined) {
|
|
77
|
+
throw new PortableExecutionInputError(`Invalid dataset query: ${errors.join('; ')}`);
|
|
78
|
+
}
|
|
79
|
+
// A valid query this engine cannot run is a capability the caller can
|
|
80
|
+
// route elsewhere, not an executor failure.
|
|
81
|
+
const unsupported = unsupportedStageMessage(plan, resolveDatasetSqlDialect(options.queryBuilder));
|
|
82
|
+
if (unsupported !== undefined) {
|
|
83
|
+
throw new PortableExecutionUnsupportedError(unsupported, {
|
|
84
|
+
reason: UNSUPPORTED_CONTRACT_REASONS.queryCalculationDialect,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
54
88
|
return { target, query, context };
|
|
55
89
|
}
|
|
90
|
+
async function executeEventOperation(input) {
|
|
91
|
+
const { target, context } = resolveTarget(input);
|
|
92
|
+
const spec = eventOperationSpec(input.operation, target);
|
|
93
|
+
// Trusted context, like a local client's `runtime.constraints`, so they
|
|
94
|
+
// scope the scan without counting as caller filters.
|
|
95
|
+
const constraints = eventConstraintFilters(input.constraints ?? []);
|
|
96
|
+
const scoped = constraints.length === 0
|
|
97
|
+
? context
|
|
98
|
+
: { ...context, runtime: { ...context.runtime, constraints } };
|
|
99
|
+
const rows = await withDeadline(input.budget, input.signal, async (signal) => (prepareEventOperation(target, spec, {
|
|
100
|
+
builderFactory: toQueryBuilderFactory(options.queryBuilder),
|
|
101
|
+
...(options.now === undefined ? {} : { now: options.now }),
|
|
102
|
+
context: { ...scoped, abortSignal: signal },
|
|
103
|
+
}).execute()));
|
|
104
|
+
return bounded(Object.freeze({
|
|
105
|
+
kind: 'hypequery-semantic-invocation-result',
|
|
106
|
+
version: 1,
|
|
107
|
+
activationRevision: input.activationRevision,
|
|
108
|
+
data: rows,
|
|
109
|
+
meta: { rowCount: rows.length },
|
|
110
|
+
}), input.budget);
|
|
111
|
+
}
|
|
56
112
|
async function execute(input) {
|
|
57
113
|
const { target, query, context } = resolve(input);
|
|
58
114
|
const output = await withDeadline(input.budget, input.signal, async (signal) => (await client.execute(target, query, {
|
|
@@ -69,6 +125,8 @@ export function createPortableSemanticRuntime(options) {
|
|
|
69
125
|
meta: {
|
|
70
126
|
rowCount: rows.length,
|
|
71
127
|
...(pagination === undefined ? {} : { pagination }),
|
|
128
|
+
// RFC 0026: the typed output columns, only when the query had calculations.
|
|
129
|
+
...(output.meta?.calculations === undefined ? {} : { calculations: output.meta.calculations }),
|
|
72
130
|
},
|
|
73
131
|
}), input.budget);
|
|
74
132
|
}
|
|
@@ -87,6 +145,7 @@ export function createPortableSemanticRuntime(options) {
|
|
|
87
145
|
});
|
|
88
146
|
},
|
|
89
147
|
execute,
|
|
148
|
+
executeEventOperation,
|
|
90
149
|
};
|
|
91
150
|
}
|
|
92
151
|
/** Backwards-compatible executor adapter for the deployment data plane. */
|
|
@@ -8,6 +8,18 @@ export interface BuildProtocolDatasetContractOptions {
|
|
|
8
8
|
/**
|
|
9
9
|
* Converts one Dataset instance into a validated local dataset snapshot.
|
|
10
10
|
* Deployment assembly selects the fields supported by the deployment contract.
|
|
11
|
+
*
|
|
12
|
+
* The snapshot is contract 2 shaped, so it refuses every contract 3 feature by
|
|
13
|
+
* name. `buildProtocolDeploymentContract` emits those as contract 3.
|
|
11
14
|
*/
|
|
12
15
|
export declare function buildProtocolDatasetContract(dataset: AnyDatasetInstance, options?: BuildProtocolDatasetContractOptions): ProtocolDatasetContract;
|
|
16
|
+
/**
|
|
17
|
+
* The unvalidated dataset body both contract versions share: dimensions, base
|
|
18
|
+
* measures, the filter allow-list (as `filters`), relationships and limits.
|
|
19
|
+
* At contract 3, base measures may be `approxCountDistinct` and carry the
|
|
20
|
+
* `approximate` marker, and `defaults.timeGrain` may be sub-day. Window,
|
|
21
|
+
* shift and derived measures and segments are added by the deployment
|
|
22
|
+
* adapter, which also renames `filters` for contract 3.
|
|
23
|
+
*/
|
|
24
|
+
export declare function protocolDatasetRecord(dataset: AnyDatasetInstance, options: BuildProtocolDatasetContractOptions, contractVersion: 2 | 3): ProtocolDatasetContract;
|
|
13
25
|
//# sourceMappingURL=protocol-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-adapter.d.ts","sourceRoot":"","sources":["../src/protocol-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protocol-adapter.d.ts","sourceRoot":"","sources":["../src/protocol-adapter.ts"],"names":[],"mappings":"AAIA,OAAO,EAIL,KAAK,uBAAuB,EAE5B,KAAK,sBAAsB,EAI5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EACV,kBAAkB,EAElB,YAAY,EAEb,MAAM,YAAY,CAAC;AAOpB,MAAM,WAAW,mCAAmC;IAClD,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAC1D,QAAQ,CAAC,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAC3C,QAAQ,CAAC,eAAe,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC;CAC7E;AAmFD;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,kBAAkB,EAC3B,OAAO,GAAE,mCAAwC,GAChD,uBAAuB,CAezB;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,mCAAmC,EAC5C,eAAe,EAAE,CAAC,GAAG,CAAC,GACrB,uBAAuB,CA2IzB"}
|
package/dist/protocol-adapter.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sqlSourceToContract } from './utils/sql-dataset-source.js';
|
|
1
2
|
import { byName } from './utils/by-name.js';
|
|
2
3
|
import { splitDatasetMeasures } from './utils/dataset-measures.js';
|
|
3
4
|
import { filterExpression, metricExpression, metricDerivation } from './utils/protocol-metric-expressions.js';
|
|
@@ -6,6 +7,7 @@ import { SEMANTIC_FILTER_OPERATORS } from './constants.js';
|
|
|
6
7
|
import { toProtocolSemanticMetadata } from './utils/protocol-semantic-metadata.js';
|
|
7
8
|
import { assertPublishableTimeGrains, isPortableTimeGrain, requirePortableTimeGrain } from './utils/portable-grains.js';
|
|
8
9
|
import { requirePublishableMeasureAggregation } from './utils/portable-aggregations.js';
|
|
10
|
+
import { isApproximateBaseMeasure } from './utils/approximate-measures.js';
|
|
9
11
|
import { assertNoPublishedSegments } from './utils/segments.js';
|
|
10
12
|
function fieldSchema(type) {
|
|
11
13
|
switch (type) {
|
|
@@ -69,9 +71,12 @@ function requiredSqlDependencies(kind, name, dependencies) {
|
|
|
69
71
|
/**
|
|
70
72
|
* Converts one Dataset instance into a validated local dataset snapshot.
|
|
71
73
|
* Deployment assembly selects the fields supported by the deployment contract.
|
|
74
|
+
*
|
|
75
|
+
* The snapshot is contract 2 shaped, so it refuses every contract 3 feature by
|
|
76
|
+
* name. `buildProtocolDeploymentContract` emits those as contract 3.
|
|
72
77
|
*/
|
|
73
78
|
export function buildProtocolDatasetContract(dataset, options = {}) {
|
|
74
|
-
const {
|
|
79
|
+
const { windows, shifts } = splitDatasetMeasures(dataset.measures);
|
|
75
80
|
const shiftMeasureNames = Object.keys(shifts);
|
|
76
81
|
if (shiftMeasureNames.length)
|
|
77
82
|
throw new Error(`Dataset "${dataset.name}" shift measures (${shiftMeasureNames.join(', ')}) need deployment contract 3 (RFC 0015).`);
|
|
@@ -80,6 +85,21 @@ export function buildProtocolDatasetContract(dataset, options = {}) {
|
|
|
80
85
|
throw new Error(`Dataset "${dataset.name}" window measures (${windowMeasureNames.join(', ')}) need deployment contract 3 (RFC 0015).`);
|
|
81
86
|
}
|
|
82
87
|
assertNoPublishedSegments(dataset);
|
|
88
|
+
// Reuse the protocol validator for strict identifiers, expression limits,
|
|
89
|
+
// and a deeply immutable return value. Cross-dataset references are checked
|
|
90
|
+
// by the containing deployment validator.
|
|
91
|
+
return validateProtocolDatasetContract(protocolDatasetRecord(dataset, options, 2));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The unvalidated dataset body both contract versions share: dimensions, base
|
|
95
|
+
* measures, the filter allow-list (as `filters`), relationships and limits.
|
|
96
|
+
* At contract 3, base measures may be `approxCountDistinct` and carry the
|
|
97
|
+
* `approximate` marker, and `defaults.timeGrain` may be sub-day. Window,
|
|
98
|
+
* shift and derived measures and segments are added by the deployment
|
|
99
|
+
* adapter, which also renames `filters` for contract 3.
|
|
100
|
+
*/
|
|
101
|
+
export function protocolDatasetRecord(dataset, options, contractVersion) {
|
|
102
|
+
const { base: baseMeasures } = splitDatasetMeasures(dataset.measures);
|
|
83
103
|
assertPublishableTimeGrains(dataset);
|
|
84
104
|
if (dataset.limits?.maxStreamRows !== undefined) {
|
|
85
105
|
// The contract's limits cannot carry it, so a deployment would quietly
|
|
@@ -101,7 +121,7 @@ export function buildProtocolDatasetContract(dataset, options = {}) {
|
|
|
101
121
|
name: dataset.name,
|
|
102
122
|
...(dataset.description !== undefined ? { description: dataset.description } : {}),
|
|
103
123
|
...toProtocolSemanticMetadata(dataset),
|
|
104
|
-
source: dataset.source,
|
|
124
|
+
source: dataset.sqlSource ? sqlSourceToContract(dataset.sqlSource) : dataset.source,
|
|
105
125
|
...(dataset.rowResolution === undefined ? {} : { rowResolution: { ...dataset.rowResolution } }),
|
|
106
126
|
...(dataset.freshness !== undefined ? { freshness: { ...dataset.freshness } } : {}),
|
|
107
127
|
...(dataset.owner !== undefined ? { owner: dataset.owner } : {}),
|
|
@@ -113,7 +133,9 @@ export function buildProtocolDatasetContract(dataset, options = {}) {
|
|
|
113
133
|
: {}),
|
|
114
134
|
...(dataset.defaults.timeGrain !== undefined
|
|
115
135
|
? {
|
|
116
|
-
timeGrain:
|
|
136
|
+
timeGrain: contractVersion === 3
|
|
137
|
+
? dataset.defaults.timeGrain
|
|
138
|
+
: requirePortableTimeGrain(dataset.defaults.timeGrain, `Dataset "${dataset.name}" defaults.timeGrain`),
|
|
117
139
|
}
|
|
118
140
|
: {}),
|
|
119
141
|
},
|
|
@@ -123,6 +145,8 @@ export function buildProtocolDatasetContract(dataset, options = {}) {
|
|
|
123
145
|
? { kind: 'required', field: dataset.tenantKey }
|
|
124
146
|
: { kind: 'not-required' },
|
|
125
147
|
...(dataset.timeKey !== undefined ? { timeField: dataset.timeKey } : {}),
|
|
148
|
+
// RFC 0027: published as declared; the contract validator re-checks it.
|
|
149
|
+
...(dataset.events === undefined ? {} : { events: { ...dataset.events } }),
|
|
126
150
|
dimensions: Object.entries(dataset.dimensions).map(([name, dimension]) => ({
|
|
127
151
|
name,
|
|
128
152
|
type: dimension.fieldType,
|
|
@@ -137,7 +161,7 @@ export function buildProtocolDatasetContract(dataset, options = {}) {
|
|
|
137
161
|
})).sort(byName),
|
|
138
162
|
measures: Object.entries(baseMeasures).map(([name, measure]) => ({
|
|
139
163
|
name,
|
|
140
|
-
aggregation: requirePublishableMeasureAggregation(measure.aggregation, `Measure "${dataset.name}.${name}"
|
|
164
|
+
aggregation: requirePublishableMeasureAggregation(measure.aggregation, `Measure "${dataset.name}.${name}"`, contractVersion),
|
|
141
165
|
field: measure.field,
|
|
142
166
|
...(measure.stateFunction !== undefined ? { stateFunction: measure.stateFunction } : {}),
|
|
143
167
|
...(measure.argField !== undefined ? { argField: measure.argField } : {}),
|
|
@@ -148,6 +172,7 @@ export function buildProtocolDatasetContract(dataset, options = {}) {
|
|
|
148
172
|
}
|
|
149
173
|
: {}),
|
|
150
174
|
filters: (measure.filters ?? []).map(filterExpression),
|
|
175
|
+
...(contractVersion === 3 && isApproximateBaseMeasure(measure) ? { approximate: true } : {}),
|
|
151
176
|
...(measure.label !== undefined ? { label: measure.label } : {}),
|
|
152
177
|
...(measure.description !== undefined ? { description: measure.description } : {}),
|
|
153
178
|
...toProtocolSemanticMetadata(measure),
|
|
@@ -190,8 +215,5 @@ export function buildProtocolDatasetContract(dataset, options = {}) {
|
|
|
190
215
|
: {}),
|
|
191
216
|
...(options.endpoint !== undefined ? { endpoint: options.endpoint } : {}),
|
|
192
217
|
};
|
|
193
|
-
|
|
194
|
-
// and a deeply immutable return value. Cross-dataset references are checked
|
|
195
|
-
// by the containing deployment validator.
|
|
196
|
-
return validateProtocolDatasetContract(contract);
|
|
218
|
+
return contract;
|
|
197
219
|
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ProtocolDeploymentContractAnyVersion, type ProtocolEndpointPolicy } from '@hypequery/protocol';
|
|
2
2
|
import type { AnyDatasetInstance } from './types.js';
|
|
3
3
|
export interface BuildProtocolDeploymentContractOptions {
|
|
4
4
|
readonly endpoints?: Readonly<Record<string, ProtocolEndpointPolicy>>;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Build the deployment contract; local metrics are not carried.
|
|
8
|
+
*
|
|
9
|
+
* The version follows RFC 0015's lowest-version rule. A deployment is contract
|
|
10
|
+
* 2 unless a dataset uses segments, window or shift measures, alternate time keys,
|
|
11
|
+
* `approxCountDistinct`, or a sub-day default grain, so a deployment that uses
|
|
12
|
+
* none keeps the bytes and identity it had before contract 3.
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildProtocolDeploymentContract(datasets: readonly AnyDatasetInstance[], options?: BuildProtocolDeploymentContractOptions): ProtocolDeploymentContractAnyVersion;
|
|
8
15
|
//# sourceMappingURL=protocol-deployment-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-deployment-adapter.d.ts","sourceRoot":"","sources":["../src/protocol-deployment-adapter.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"protocol-deployment-adapter.d.ts","sourceRoot":"","sources":["../src/protocol-deployment-adapter.ts"],"names":[],"mappings":"AAGA,OAAO,EAKL,KAAK,oCAAoC,EAGzC,KAAK,sBAAsB,EAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAWrD,MAAM,WAAW,sCAAsC;IACrD,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC;CACvE;AAgDD;;;;;;;GAOG;AACH,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,SAAS,kBAAkB,EAAE,EACvC,OAAO,GAAE,sCAA2C,GACnD,oCAAoC,CAkBtC"}
|
|
@@ -1,38 +1,72 @@
|
|
|
1
1
|
import { byName } from './utils/by-name.js';
|
|
2
2
|
import { splitDatasetMeasures } from './utils/dataset-measures.js';
|
|
3
3
|
import { assertDeployable } from './utils/deployable-formulas.js';
|
|
4
|
-
import { parseProtocolIdentifier, validateProtocolDeploymentContract, } from '@hypequery/protocol';
|
|
5
|
-
import { buildProtocolDatasetContract } from './protocol-adapter.js';
|
|
4
|
+
import { parseProtocolIdentifier, validateProtocolDeploymentContract, validateProtocolDeploymentContractV3, } from '@hypequery/protocol';
|
|
5
|
+
import { buildProtocolDatasetContract, protocolDatasetRecord } from './protocol-adapter.js';
|
|
6
6
|
import { derivedMeasureExpression } from './utils/protocol-metric-expressions.js';
|
|
7
7
|
import { toProtocolSemanticMetadata } from './utils/protocol-semantic-metadata.js';
|
|
8
|
-
|
|
8
|
+
import { derivedApproximateMarker, protocolSegments, protocolTimeMeasures, usesContract3Features, } from './utils/protocol-contract-3.js';
|
|
9
|
+
function derivedMeasures(dataset, contractVersion) {
|
|
10
|
+
return Object.entries(splitDatasetMeasures(dataset.measures).derived).map(([name, definition]) => ({
|
|
11
|
+
kind: 'derived',
|
|
12
|
+
name: parseProtocolIdentifier(name),
|
|
13
|
+
uses: Object.entries(definition.uses).map(([alias, measure]) => ({
|
|
14
|
+
alias: parseProtocolIdentifier(alias),
|
|
15
|
+
measure: parseProtocolIdentifier(measure),
|
|
16
|
+
})),
|
|
17
|
+
expression: derivedMeasureExpression(definition),
|
|
18
|
+
...(contractVersion === 3 ? derivedApproximateMarker(dataset, name) : {}),
|
|
19
|
+
...(definition.label !== undefined ? { label: definition.label } : {}),
|
|
20
|
+
...(definition.description !== undefined ? { description: definition.description } : {}),
|
|
21
|
+
...toProtocolSemanticMetadata(definition),
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
function contract2Dataset(dataset, endpoint) {
|
|
25
|
+
const contract = buildProtocolDatasetContract(dataset, { endpoint });
|
|
26
|
+
const { metrics: _metrics, ...base } = contract;
|
|
27
|
+
return { ...base, measures: [...base.measures, ...derivedMeasures(dataset, 2)] };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A contract 3 dataset: base measures sorted by name, then window and shift
|
|
31
|
+
* measures and then derived measures, each in declaration order. The filter
|
|
32
|
+
* allow-list is `allowedFilters`, and `segments` is present only when declared.
|
|
33
|
+
*/
|
|
34
|
+
function contract3Dataset(dataset, endpoint) {
|
|
35
|
+
const { metrics: _metrics, filters, ...base } = protocolDatasetRecord(dataset, { endpoint }, 3);
|
|
36
|
+
const segments = protocolSegments(dataset);
|
|
37
|
+
return {
|
|
38
|
+
...base,
|
|
39
|
+
measures: [...base.measures, ...protocolTimeMeasures(dataset), ...derivedMeasures(dataset, 3)],
|
|
40
|
+
allowedFilters: filters,
|
|
41
|
+
...(segments.length > 0 ? { segments } : {}),
|
|
42
|
+
// RFC 0029: alternate time axes, in authored order.
|
|
43
|
+
...((dataset.timeKeys?.length ?? 0) > 0 ? { alternateTimeFields: [...dataset.timeKeys] } : {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Build the deployment contract; local metrics are not carried.
|
|
48
|
+
*
|
|
49
|
+
* The version follows RFC 0015's lowest-version rule. A deployment is contract
|
|
50
|
+
* 2 unless a dataset uses segments, window or shift measures, alternate time keys,
|
|
51
|
+
* `approxCountDistinct`, or a sub-day default grain, so a deployment that uses
|
|
52
|
+
* none keeps the bytes and identity it had before contract 3.
|
|
53
|
+
*/
|
|
9
54
|
export function buildProtocolDeploymentContract(datasets, options = {}) {
|
|
10
55
|
// Sorted, as Python's builder does: the contract's identity must not depend
|
|
11
56
|
// on the order the datasets were passed in.
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
57
|
+
const sorted = [...datasets].sort(byName);
|
|
58
|
+
// Name the dataset and measure before the contract grammar can only name a path.
|
|
59
|
+
sorted.forEach(assertDeployable);
|
|
60
|
+
if (!sorted.some(usesContract3Features)) {
|
|
61
|
+
return validateProtocolDeploymentContract({
|
|
62
|
+
kind: 'hypequery-deployment',
|
|
63
|
+
version: 2,
|
|
64
|
+
datasets: sorted.map(dataset => contract2Dataset(dataset, options.endpoints?.[dataset.name])),
|
|
17
65
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
kind: 'derived',
|
|
21
|
-
name: parseProtocolIdentifier(name),
|
|
22
|
-
uses: Object.entries(definition.uses).map(([alias, measure]) => ({
|
|
23
|
-
alias: parseProtocolIdentifier(alias),
|
|
24
|
-
measure: parseProtocolIdentifier(measure),
|
|
25
|
-
})),
|
|
26
|
-
expression: derivedMeasureExpression(definition),
|
|
27
|
-
...(definition.label !== undefined ? { label: definition.label } : {}),
|
|
28
|
-
...(definition.description !== undefined ? { description: definition.description } : {}),
|
|
29
|
-
...toProtocolSemanticMetadata(definition),
|
|
30
|
-
}));
|
|
31
|
-
return { ...base, measures: [...base.measures, ...derived] };
|
|
32
|
-
});
|
|
33
|
-
return validateProtocolDeploymentContract({
|
|
66
|
+
}
|
|
67
|
+
return validateProtocolDeploymentContractV3({
|
|
34
68
|
kind: 'hypequery-deployment',
|
|
35
|
-
version:
|
|
36
|
-
datasets:
|
|
69
|
+
version: 3,
|
|
70
|
+
datasets: sorted.map(dataset => contract3Dataset(dataset, options.endpoints?.[dataset.name])),
|
|
37
71
|
});
|
|
38
72
|
}
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Rebuilds executable datasets from a portable deployment contract.
|
|
3
|
-
*
|
|
4
|
-
* The inverse of `protocol-adapter.ts`. Decision 0005 chose portable native
|
|
5
|
-
* execution, which means a runtime resolves a dataset from the validated active
|
|
6
|
-
* contract and plans the query with the existing semantic planner — no customer
|
|
7
|
-
* module is loaded. This is the function that makes the contract executable.
|
|
8
|
-
*
|
|
9
|
-
* Rehydration deliberately routes through the public `dataset()` factory rather
|
|
10
|
-
* than assembling an instance by hand, so a rebuilt dataset is constructed by
|
|
11
|
-
* exactly the same code path as an authored one. That is what makes the
|
|
12
|
-
* byte-identical SQL claim mitigated by construction rather than by review.
|
|
13
|
-
*/
|
|
14
|
-
import type { ProtocolDatasetContract, ProtocolDeploymentDataset } from '@hypequery/protocol';
|
|
1
|
+
import type { ProtocolDatasetContract, ProtocolDeploymentDatasetAnyVersion } from '@hypequery/protocol';
|
|
15
2
|
import type { AnyDatasetInstance, DatasetCachePolicy, MetricHandle } from './types.js';
|
|
16
3
|
import { type UnsupportedContractReason } from './utils/unsupported-contract-reasons.js';
|
|
17
4
|
export { UNSUPPORTED_CONTRACT_REASONS, type UnsupportedContractReason, } from './utils/unsupported-contract-reasons.js';
|
|
@@ -56,7 +43,7 @@ export declare class UnsupportedContractFeatureError extends Error {
|
|
|
56
43
|
* attached, which is the registry shape `getDatasetCatalog`,
|
|
57
44
|
* `projectAgentSafeCatalog`, and `DatasetClient` already accept.
|
|
58
45
|
*/
|
|
59
|
-
export declare function rehydrateProtocolDatasets(contracts: readonly (ProtocolDatasetContract |
|
|
60
|
-
/** Strict
|
|
46
|
+
export declare function rehydrateProtocolDatasets(contracts: readonly (ProtocolDatasetContract | ProtocolDeploymentDatasetAnyVersion)[], options?: RehydrateProtocolDatasetsOptions): Readonly<Record<string, RehydratedDataset>>;
|
|
47
|
+
/** Strict contract 2 or 3 reader that returns executable datasets without metric handles. */
|
|
61
48
|
export declare function rehydrateProtocolDeploymentContract(input: unknown, options?: RehydrateProtocolDatasetsOptions): Readonly<Record<string, RehydratedDataset>>;
|
|
62
49
|
//# sourceMappingURL=protocol-rehydrate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-rehydrate.d.ts","sourceRoot":"","sources":["../src/protocol-rehydrate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protocol-rehydrate.d.ts","sourceRoot":"","sources":["../src/protocol-rehydrate.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,uBAAuB,EAEvB,mCAAmC,EASpC,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAMlB,YAAY,EAOb,MAAM,YAAY,CAAC;AASpB,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EACL,4BAA4B,EAC5B,KAAK,yBAAyB,GAC/B,MAAM,yCAAyC,CAAC;AAEjD,kFAAkF;AAClF,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG;IACnD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,WAAW,gCAAgC;IAC/C;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,kBAAkB,CAAC;IACpC;;;;;;;;OAQG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACjD;AAED;;;;;GAKG;AACH,qBAAa,+BAAgC,SAAQ,KAAK;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,yBAAyB,GAAG,SAAS,CAAC;gBAGrD,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,yBAAyB;CAQrC;AAuUD;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,SAAS,CAAC,uBAAuB,GAAG,mCAAmC,CAAC,EAAE,EACrF,OAAO,GAAE,gCAAqC,GAC7C,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CA8G7C;AAED,6FAA6F;AAC7F,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,gCAAqC,GAC7C,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAG7C"}
|