@hypequery/datasets 0.29.0 → 0.31.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/README.md +18 -0
- package/dist/client-contract/build-from-datasets.d.ts +39 -0
- package/dist/client-contract/build-from-datasets.d.ts.map +1 -0
- package/dist/client-contract/build-from-datasets.js +82 -0
- package/dist/client-contract/build-from-deployment.d.ts +21 -0
- package/dist/client-contract/build-from-deployment.d.ts.map +1 -1
- package/dist/client-contract/build-from-deployment.js +4 -3
- package/dist/client-contract/dataset-annotations.d.ts +14 -0
- package/dist/client-contract/dataset-annotations.d.ts.map +1 -0
- package/dist/client-contract/dataset-annotations.js +27 -0
- package/dist/client-contract/dataset-fields.d.ts +24 -0
- package/dist/client-contract/dataset-fields.d.ts.map +1 -0
- package/dist/client-contract/dataset-fields.js +109 -0
- package/dist/client-contract/deployment-annotations.d.ts +8 -2
- package/dist/client-contract/deployment-annotations.d.ts.map +1 -1
- package/dist/client-contract/deployment-annotations.js +37 -7
- package/dist/client-contract/deployment-fields.d.ts +4 -3
- package/dist/client-contract/deployment-fields.d.ts.map +1 -1
- package/dist/client-contract/deployment-fields.js +15 -12
- package/dist/client-contract/deployment-profile.d.ts +9 -0
- package/dist/client-contract/deployment-profile.d.ts.map +1 -1
- package/dist/client-contract/deployment-profile.js +10 -6
- package/dist/cloud-publishing.d.ts +14 -1
- package/dist/cloud-publishing.d.ts.map +1 -1
- package/dist/cloud-publishing.js +16 -0
- package/dist/codegen/cloud-source.d.ts +8 -0
- package/dist/codegen/cloud-source.d.ts.map +1 -0
- package/dist/codegen/cloud-source.js +90 -0
- package/dist/codegen/dataset-source.d.ts +19 -0
- package/dist/codegen/dataset-source.d.ts.map +1 -0
- package/dist/codegen/dataset-source.js +223 -0
- package/dist/codegen/errors.d.ts +11 -0
- package/dist/codegen/errors.d.ts.map +1 -0
- package/dist/codegen/errors.js +15 -0
- package/dist/codegen/formula-source.d.ts +8 -0
- package/dist/codegen/formula-source.d.ts.map +1 -0
- package/dist/codegen/formula-source.js +83 -0
- package/dist/codegen/index.d.ts +28 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/index.js +67 -0
- package/dist/codegen/utils/declaration-order.d.ts +9 -0
- package/dist/codegen/utils/declaration-order.d.ts.map +1 -0
- package/dist/codegen/utils/declaration-order.js +28 -0
- package/dist/codegen/utils/member-order.d.ts +17 -0
- package/dist/codegen/utils/member-order.d.ts.map +1 -0
- package/dist/codegen/utils/member-order.js +52 -0
- package/dist/codegen/utils/naming.d.ts +7 -0
- package/dist/codegen/utils/naming.d.ts.map +1 -0
- package/dist/codegen/utils/naming.js +22 -0
- package/dist/codegen/utils/source-writer.d.ts +35 -0
- package/dist/codegen/utils/source-writer.d.ts.map +1 -0
- package/dist/codegen/utils/source-writer.js +121 -0
- package/dist/execution-capabilities.json +4 -4
- package/dist/executor.d.ts +33 -1
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +59 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/metric-query-engine.d.ts +9 -0
- package/dist/metric-query-engine.d.ts.map +1 -1
- package/dist/metric-query-engine.js +25 -15
- package/dist/protocol-adapter.d.ts.map +1 -1
- package/dist/protocol-adapter.js +6 -0
- package/dist/query-builder-protocol.d.ts +32 -0
- package/dist/query-builder-protocol.d.ts.map +1 -1
- package/dist/types.d.ts +58 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/compile-dataset-query.d.ts +9 -3
- package/dist/utils/compile-dataset-query.d.ts.map +1 -1
- package/dist/utils/compile-dataset-query.js +11 -9
- package/dist/utils/portable-semantic-query.d.ts.map +1 -1
- package/dist/utils/portable-semantic-query.js +11 -0
- package/dist/utils/relationship-measure-sql.d.ts.map +1 -1
- package/dist/utils/relationship-measure-sql.js +4 -2
- package/dist/utils/semantic-stream.d.ts +6 -0
- package/dist/utils/semantic-stream.d.ts.map +1 -0
- package/dist/utils/semantic-stream.js +17 -0
- package/dist/utils/statement-runner.d.ts +31 -0
- package/dist/utils/statement-runner.d.ts.map +1 -0
- package/dist/utils/statement-runner.js +43 -0
- package/dist/utils/stream-ceiling.d.ts +10 -0
- package/dist/utils/stream-ceiling.d.ts.map +1 -0
- package/dist/utils/stream-ceiling.js +21 -0
- package/dist/utils/time-measure-axis-sql.d.ts.map +1 -1
- package/dist/utils/time-measure-axis-sql.js +4 -1
- package/package.json +14 -6
package/README.md
CHANGED
|
@@ -115,6 +115,24 @@ for module boundaries and verification requirements, and the
|
|
|
115
115
|
|
|
116
116
|
Apache-2.0.
|
|
117
117
|
|
|
118
|
+
## Client contracts from a deployment
|
|
119
|
+
|
|
120
|
+
`buildClientContract(deployment, options)` turns a deployment contract (for
|
|
121
|
+
example `publishToCloud`'s output) into the hashed client contract
|
|
122
|
+
`hypequery generate:client` reads. `having` and a per-request `timezone` are
|
|
123
|
+
off unless the host's route passes them through to the data plane, since a
|
|
124
|
+
route that builds its operation from a fixed list of fields would drop them.
|
|
125
|
+
A host that passes them through opts in:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
buildClientContract(deployment, {
|
|
129
|
+
capabilities: { having: true, timezone: true },
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Capabilities are part of each endpoint's `schemaHash`; changing them means
|
|
134
|
+
regenerating clients.
|
|
135
|
+
|
|
118
136
|
## Public client descriptor schemas
|
|
119
137
|
|
|
120
138
|
`buildClientContractQuerySchemas(contract)` validates an RFC 0018 signed client
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type PreparedProtocolClientContract } from '@hypequery/protocol';
|
|
2
|
+
import type { AnyDatasetInstance, MetricRef } from '../types.js';
|
|
3
|
+
import { type ClientContractProfile } from './deployment-profile.js';
|
|
4
|
+
/** One logical endpoint a host serves: a dataset query, or one metric of a dataset. */
|
|
5
|
+
export interface DatasetClientEndpoint {
|
|
6
|
+
/** The dataset queried, or the dataset the metric reads. */
|
|
7
|
+
readonly dataset: AnyDatasetInstance;
|
|
8
|
+
/** The absolute route the host serves this endpoint at, below `mountPath`. */
|
|
9
|
+
readonly path: string;
|
|
10
|
+
/** For a metric endpoint, the metric it serves. Its rows carry the value under the metric's name. */
|
|
11
|
+
readonly metric?: MetricRef;
|
|
12
|
+
/** A metric endpoint's export ID, such as its route key; the metric's name by default. */
|
|
13
|
+
readonly name?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Ceilings the host enforces for this endpoint; defaults mirror Python's
|
|
16
|
+
* ClientQueryProfile. The export only ever narrows them by the dataset's limits.
|
|
17
|
+
*/
|
|
18
|
+
readonly profile?: ClientContractProfile;
|
|
19
|
+
}
|
|
20
|
+
export interface BuildDatasetClientContractOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Trusted mount prefix, such as `/v1`: absolute, no trailing slash. Never a
|
|
23
|
+
* proxy or request header; the host knows how it is mounted.
|
|
24
|
+
*/
|
|
25
|
+
readonly mountPath?: string;
|
|
26
|
+
/** `authorized` is a caller's view: the host passes only that caller's endpoints. */
|
|
27
|
+
readonly view?: 'build' | 'authorized';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The client contract for endpoints a host serves from dataset definitions:
|
|
31
|
+
* typed fields, routes and schema hashes that `hypequery generate:client`
|
|
32
|
+
* turns into React types and a route manifest. Pure: no network, no execution.
|
|
33
|
+
* Mirrors Python's `export_client_contract`, so an equivalent definition
|
|
34
|
+
* exports the same contract in either language.
|
|
35
|
+
*
|
|
36
|
+
* The host owns the routes and must enforce the advertised profile on them.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildDatasetClientContract(endpoints: readonly DatasetClientEndpoint[], options?: BuildDatasetClientContractOptions): PreparedProtocolClientContract;
|
|
39
|
+
//# sourceMappingURL=build-from-datasets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-from-datasets.d.ts","sourceRoot":"","sources":["../../src/client-contract/build-from-datasets.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIjE,OAAO,EAAyD,KAAK,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAE5H,uFAAuF;AACvF,MAAM,WAAW,qBAAqB;IACpC,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qGAAqG;IACrG,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAC5B,0FAA0F;IAC1F,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;CAC1C;AAED,MAAM,WAAW,iCAAiC;IAChD;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,qFAAqF;IACrF,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;CACxC;AA2DD;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,SAAS,qBAAqB,EAAE,EAC3C,OAAO,GAAE,iCAAsC,GAC9C,8BAA8B,CAWhC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { prepareProtocolClientContract, } from '@hypequery/protocol';
|
|
2
|
+
import { SUPPORTED_TIME_GRAINS } from '../constants.js';
|
|
3
|
+
import { baseMeasureNames } from '../utils/dataset-measures.js';
|
|
4
|
+
import { datasetEndpointAnnotations } from './dataset-annotations.js';
|
|
5
|
+
import { datasetPublicFields } from './dataset-fields.js';
|
|
6
|
+
import { narrowClientQueryLimits, resolveClientContractProfile } from './deployment-profile.js';
|
|
7
|
+
function endpointDescriptor(endpoint, mountPath) {
|
|
8
|
+
const { dataset, metric } = endpoint;
|
|
9
|
+
if (!endpoint.path.startsWith('/')) {
|
|
10
|
+
throw new Error(`Client export: the endpoint for "${dataset.name}" needs an absolute path.`);
|
|
11
|
+
}
|
|
12
|
+
if (metric !== undefined && metric.dataset !== dataset) {
|
|
13
|
+
throw new Error(`Client export: metric "${metric.name}" does not read dataset "${dataset.name}".`);
|
|
14
|
+
}
|
|
15
|
+
const fields = datasetPublicFields(dataset);
|
|
16
|
+
const { dimensions, filters } = fields;
|
|
17
|
+
const id = metric === undefined ? dataset.name : endpoint.name ?? metric.name;
|
|
18
|
+
if (metric !== undefined && id === dataset.name) {
|
|
19
|
+
throw new Error(`Client export: metric "${id}" needs an export ID other than its dataset's name.`);
|
|
20
|
+
}
|
|
21
|
+
// A metric's rows carry its one value under the metric's name.
|
|
22
|
+
const measures = metric === undefined
|
|
23
|
+
? fields.measures
|
|
24
|
+
: { [metric.name]: { wireType: 'string', nullable: true, having: false } };
|
|
25
|
+
// Rows carry the time bucket as `period`, so a field of that name would collide.
|
|
26
|
+
if (dataset.timeKey !== undefined && (Object.hasOwn(dimensions, 'period') || Object.hasOwn(measures, 'period'))) {
|
|
27
|
+
throw new Error(`Client export: dataset "${dataset.name}" has a field named "period", which its time bucket uses. Rename it.`);
|
|
28
|
+
}
|
|
29
|
+
const profile = resolveClientContractProfile(endpoint.profile);
|
|
30
|
+
const limits = narrowClientQueryLimits(dataset.limits, undefined, profile);
|
|
31
|
+
const node = {
|
|
32
|
+
id,
|
|
33
|
+
kind: metric === undefined ? 'dataset' : 'metric',
|
|
34
|
+
dataset: dataset.name,
|
|
35
|
+
path: mountPath + endpoint.path,
|
|
36
|
+
dimensions,
|
|
37
|
+
measures,
|
|
38
|
+
filters,
|
|
39
|
+
metadata: true,
|
|
40
|
+
limits,
|
|
41
|
+
time: dataset.timeKey === undefined ? null : {
|
|
42
|
+
grains: [...(dataset.timeGrains ?? SUPPORTED_TIME_GRAINS)].sort(),
|
|
43
|
+
defaultTimezone: profile.defaultTimezone,
|
|
44
|
+
timezone: true,
|
|
45
|
+
periodFormat: 'calendar-date-or-local-datetime-v1',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
if (metric === undefined) {
|
|
49
|
+
// An endpoint's default selection is the base measures it can serve.
|
|
50
|
+
const defaultMeasures = baseMeasureNames(dataset.measures).filter(name => Object.hasOwn(measures, name));
|
|
51
|
+
if (defaultMeasures.length > limits.maxMeasures) {
|
|
52
|
+
throw new Error(`Client export: dataset "${dataset.name}" selects ${defaultMeasures.length} measures by default, `
|
|
53
|
+
+ `more than its measure budget of ${limits.maxMeasures}. Raise limits.maxMeasures.`);
|
|
54
|
+
}
|
|
55
|
+
node.defaultMeasures = defaultMeasures;
|
|
56
|
+
}
|
|
57
|
+
const annotations = datasetEndpointAnnotations(dataset, Object.keys(dimensions), Object.keys(measures), metric);
|
|
58
|
+
if (annotations)
|
|
59
|
+
node.annotations = annotations;
|
|
60
|
+
return node;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The client contract for endpoints a host serves from dataset definitions:
|
|
64
|
+
* typed fields, routes and schema hashes that `hypequery generate:client`
|
|
65
|
+
* turns into React types and a route manifest. Pure: no network, no execution.
|
|
66
|
+
* Mirrors Python's `export_client_contract`, so an equivalent definition
|
|
67
|
+
* exports the same contract in either language.
|
|
68
|
+
*
|
|
69
|
+
* The host owns the routes and must enforce the advertised profile on them.
|
|
70
|
+
*/
|
|
71
|
+
export function buildDatasetClientContract(endpoints, options = {}) {
|
|
72
|
+
const mountPath = options.mountPath ?? '';
|
|
73
|
+
if (mountPath && (!mountPath.startsWith('/') || mountPath.endsWith('/'))) {
|
|
74
|
+
throw new Error('Client export: mountPath must be empty or an absolute path without a trailing slash.');
|
|
75
|
+
}
|
|
76
|
+
return prepareProtocolClientContract({
|
|
77
|
+
kind: 'hypequery-client-contract',
|
|
78
|
+
version: 1,
|
|
79
|
+
view: options.view ?? 'build',
|
|
80
|
+
endpoints: endpoints.map(endpoint => endpointDescriptor(endpoint, mountPath)),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -14,6 +14,27 @@ export interface BuildClientContractOptions {
|
|
|
14
14
|
readonly view?: 'build' | 'authorized';
|
|
15
15
|
/** Which published datasets to advertise; every one by default. */
|
|
16
16
|
readonly include?: (dataset: ProtocolDeploymentDataset) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Request features the host's route passes through to the data plane. A
|
|
19
|
+
* route may build its operation from a fixed list of fields and drop the
|
|
20
|
+
* rest, so `having` and a per-request `timezone` stay off unless the host
|
|
21
|
+
* turns them on; advertising one the host drops would return the wrong rows.
|
|
22
|
+
*/
|
|
23
|
+
readonly capabilities?: ClientContractCapabilities;
|
|
24
|
+
/**
|
|
25
|
+
* Also advertise each field's synonyms, examples, format, unit and currency
|
|
26
|
+
* in its annotations. Validators released before these members existed reject
|
|
27
|
+
* them, so a live discovery route turns this on only for a request whose
|
|
28
|
+
* `x-hypequery-client-features` header asks for them
|
|
29
|
+
* (`acceptsClientFieldMetadata` from `@hypequery/protocol`). Off by default.
|
|
30
|
+
*/
|
|
31
|
+
readonly fieldMetadata?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface ClientContractCapabilities {
|
|
34
|
+
/** Accepts `having` predicates on measures. */
|
|
35
|
+
readonly having?: boolean;
|
|
36
|
+
/** Accepts a per-request `timezone` for time buckets. */
|
|
37
|
+
readonly timezone?: boolean;
|
|
17
38
|
}
|
|
18
39
|
/**
|
|
19
40
|
* The client contract for a deployment's published datasets: typed fields,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-from-deployment.d.ts","sourceRoot":"","sources":["../../src/client-contract/build-from-deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC/B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAmD,KAAK,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEtH,MAAM,WAAW,0BAA0B;IACzC,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,uGAAuG;IACvG,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IACvC,mEAAmE;IACnE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,yBAAyB,KAAK,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"build-from-deployment.d.ts","sourceRoot":"","sources":["../../src/client-contract/build-from-deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC/B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAmD,KAAK,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEtH,MAAM,WAAW,0BAA0B;IACzC,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,uGAAuG;IACvG,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IACvC,mEAAmE;IACnE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,yBAAyB,KAAK,OAAO,CAAC;IACnE;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,0BAA0B,CAAC;IACnD;;;;;;OAMG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,MAAM,WAAW,0BAA0B;IACzC,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AA8DD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,0BAA0B,EACpC,OAAO,GAAE,0BAA+B,GACvC,8BAA8B,CAchC"}
|
|
@@ -11,7 +11,8 @@ function endpointPath(dataset, options) {
|
|
|
11
11
|
return (options.mountPath ?? '') + path;
|
|
12
12
|
}
|
|
13
13
|
function endpointDescriptor(dataset, options, profile) {
|
|
14
|
-
const
|
|
14
|
+
const capabilities = options.capabilities ?? {};
|
|
15
|
+
const { dimensions, measures, filters } = publicFields(dataset, capabilities);
|
|
15
16
|
// Rows carry the time bucket as `period`, so a field of that name would collide.
|
|
16
17
|
if (dataset.timeField !== undefined && (Object.hasOwn(dimensions, 'period') || Object.hasOwn(measures, 'period'))) {
|
|
17
18
|
throw new Error(`Client export: dataset "${dataset.name}" has a field named "period", which its time bucket uses. Rename it.`);
|
|
@@ -30,7 +31,7 @@ function endpointDescriptor(dataset, options, profile) {
|
|
|
30
31
|
throw new Error(`Client export: dataset "${dataset.name}" selects ${defaultMeasures.length} measures by default, `
|
|
31
32
|
+ `more than the host's measure budget of ${limits.maxMeasures}. Raise the budget, or set the dataset's limits.maxMeasures.`);
|
|
32
33
|
}
|
|
33
|
-
const annotations = endpointAnnotations(dataset, Object.keys(dimensions), Object.keys(measures));
|
|
34
|
+
const annotations = endpointAnnotations(dataset, Object.keys(dimensions), Object.keys(measures), options.fieldMetadata === true);
|
|
34
35
|
return {
|
|
35
36
|
id: dataset.name,
|
|
36
37
|
kind: 'dataset',
|
|
@@ -45,7 +46,7 @@ function endpointDescriptor(dataset, options, profile) {
|
|
|
45
46
|
time: dataset.timeField === undefined ? null : {
|
|
46
47
|
grains: [...PORTABLE_TIME_GRAINS],
|
|
47
48
|
defaultTimezone: profile.defaultTimezone,
|
|
48
|
-
timezone: true,
|
|
49
|
+
timezone: capabilities.timezone === true,
|
|
49
50
|
periodFormat: 'calendar-date-or-local-datetime-v1',
|
|
50
51
|
},
|
|
51
52
|
defaultMeasures,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ClientEndpointAnnotations } from '@hypequery/protocol';
|
|
2
|
+
import type { AnyDatasetInstance } from '../types.js';
|
|
3
|
+
interface Described {
|
|
4
|
+
readonly label?: string;
|
|
5
|
+
readonly description?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Group text from the dataset; field text for each advertised dimension and
|
|
9
|
+
* measure. A metric endpoint's sole measure key is its public alias, so its
|
|
10
|
+
* text comes from `metric`, the handle it serves.
|
|
11
|
+
*/
|
|
12
|
+
export declare function datasetEndpointAnnotations(dataset: AnyDatasetInstance, dimensions: readonly string[], measures: readonly string[], metric?: Described): ClientEndpointAnnotations | undefined;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=dataset-annotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset-annotations.d.ts","sourceRoot":"","sources":["../../src/client-contract/dataset-annotations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAyB,MAAM,qBAAqB,CAAC;AAC5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtD,UAAU,SAAS;IACjB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAUD;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,kBAAkB,EAC3B,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,MAAM,CAAC,EAAE,SAAS,GACjB,yBAAyB,GAAG,SAAS,CAWvC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { annotationText } from './deployment-annotations.js';
|
|
2
|
+
function fieldAnnotation(definition) {
|
|
3
|
+
if (definition === undefined)
|
|
4
|
+
return undefined;
|
|
5
|
+
const label = annotationText(definition.label);
|
|
6
|
+
const description = annotationText(definition.description);
|
|
7
|
+
if (label === undefined && description === undefined)
|
|
8
|
+
return undefined;
|
|
9
|
+
return { ...(label !== undefined ? { label } : {}), ...(description !== undefined ? { description } : {}) };
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Group text from the dataset; field text for each advertised dimension and
|
|
13
|
+
* measure. A metric endpoint's sole measure key is its public alias, so its
|
|
14
|
+
* text comes from `metric`, the handle it serves.
|
|
15
|
+
*/
|
|
16
|
+
export function datasetEndpointAnnotations(dataset, dimensions, measures, metric) {
|
|
17
|
+
const fields = Object.fromEntries([
|
|
18
|
+
...dimensions.map(key => [key, fieldAnnotation(dataset.dimensions[key])]),
|
|
19
|
+
...measures.map(key => [key, fieldAnnotation(metric ?? dataset.measures[key])]),
|
|
20
|
+
].filter((entry) => entry[1] !== undefined));
|
|
21
|
+
const description = annotationText(dataset.description);
|
|
22
|
+
const result = {
|
|
23
|
+
...(description !== undefined ? { description } : {}),
|
|
24
|
+
...(Object.keys(fields).length ? { fields } : {}),
|
|
25
|
+
};
|
|
26
|
+
return Object.keys(result).length ? result : undefined;
|
|
27
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ClientDimension, ClientFilter, ClientMeasure } from '@hypequery/protocol';
|
|
2
|
+
import type { AnyDatasetInstance, DatasetMeasureDefinition, DimensionDefinition, SemanticFilterDefinition } from '../types.js';
|
|
3
|
+
/** Local fields have unknown nullability; the client contract says so rather than guess. */
|
|
4
|
+
export declare function datasetDimensionDescriptor(dimension: DimensionDefinition): ClientDimension;
|
|
5
|
+
/**
|
|
6
|
+
* Base and derived measures are served by a plain query. Window and shift
|
|
7
|
+
* measures need a time axis the client profile does not carry, so they, and
|
|
8
|
+
* formulas over them, are not advertised.
|
|
9
|
+
*/
|
|
10
|
+
export declare function servableMeasure(dataset: AnyDatasetInstance, name: string, path?: Set<string>): boolean;
|
|
11
|
+
/** `having` compares numbers, so ordered aggregations over non-numeric fields can't take it. */
|
|
12
|
+
export declare function datasetMeasureDescriptor(dataset: AnyDatasetInstance, measure: DatasetMeasureDefinition): ClientMeasure;
|
|
13
|
+
export declare function datasetFilterDescriptor(dimension: DimensionDefinition, filter: SemanticFilterDefinition): ClientFilter | null;
|
|
14
|
+
/**
|
|
15
|
+
* The fields one dataset endpoint advertises, resolved from the definition as
|
|
16
|
+
* Python's `public_fields` does with `related=()`. Relationship fields are not
|
|
17
|
+
* exported yet, so a measure whose fixed filters cross a relationship is left out.
|
|
18
|
+
*/
|
|
19
|
+
export declare function datasetPublicFields(dataset: AnyDatasetInstance): {
|
|
20
|
+
dimensions: Record<string, ClientDimension>;
|
|
21
|
+
measures: Record<string, ClientMeasure>;
|
|
22
|
+
filters: Record<string, ClientFilter>;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=dataset-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset-fields.d.ts","sourceRoot":"","sources":["../../src/client-contract/dataset-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAExF,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAUrB,4FAA4F;AAC5F,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,mBAAmB,GAAG,eAAe,CAS1F;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,cAAoB,GAAG,OAAO,CAU5G;AAED,gGAAgG;AAChG,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,wBAAwB,GAAG,aAAa,CAQtH;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,wBAAwB,GAAG,YAAY,GAAG,IAAI,CAO7H;AA2BD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG;IAChE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACvC,CAkBA"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { SEMANTIC_FILTER_OPERATORS } from '../constants.js';
|
|
2
|
+
import { isBaseMeasure, isDerivedMeasure } from '../utils/dataset-measures.js';
|
|
3
|
+
// As Python's builder: booleans compare by equality and membership only.
|
|
4
|
+
// Null checks stay: a boolean column can hold NULL (RFC 0023).
|
|
5
|
+
const BOOLEAN_OPERATORS = new Set(['eq', 'neq', 'in', 'notIn', 'isNull', 'isNotNull']);
|
|
6
|
+
const ORDERED_AGGREGATIONS = new Set(['min', 'max', 'argMin', 'argMax']);
|
|
7
|
+
/** Stored states whose merged value is the stored value itself, which may not be a number. */
|
|
8
|
+
const ORDERED_STATES = new Set(['min', 'max', 'any', 'anyLast']);
|
|
9
|
+
/** Local fields have unknown nullability; the client contract says so rather than guess. */
|
|
10
|
+
export function datasetDimensionDescriptor(dimension) {
|
|
11
|
+
const type = dimension.fieldType;
|
|
12
|
+
return {
|
|
13
|
+
type,
|
|
14
|
+
wireType: type === 'number' ? 'number-or-string' : type === 'boolean' ? 'boolean' : 'string',
|
|
15
|
+
nullable: 'unknown',
|
|
16
|
+
groupable: dimension.groupable !== false,
|
|
17
|
+
orderable: dimension.groupable !== false,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Base and derived measures are served by a plain query. Window and shift
|
|
22
|
+
* measures need a time axis the client profile does not carry, so they, and
|
|
23
|
+
* formulas over them, are not advertised.
|
|
24
|
+
*/
|
|
25
|
+
export function servableMeasure(dataset, name, path = new Set()) {
|
|
26
|
+
// `path` holds only the current chain, so a measure used twice is not a cycle.
|
|
27
|
+
if (!Object.hasOwn(dataset.measures, name) || path.has(name))
|
|
28
|
+
return false;
|
|
29
|
+
const measure = dataset.measures[name];
|
|
30
|
+
if (isBaseMeasure(measure))
|
|
31
|
+
return true;
|
|
32
|
+
if (!isDerivedMeasure(measure))
|
|
33
|
+
return false;
|
|
34
|
+
path.add(name);
|
|
35
|
+
const servable = Object.values(measure.uses).every(use => servableMeasure(dataset, use, path));
|
|
36
|
+
path.delete(name);
|
|
37
|
+
return servable;
|
|
38
|
+
}
|
|
39
|
+
/** `having` compares numbers, so ordered aggregations over non-numeric fields can't take it. */
|
|
40
|
+
export function datasetMeasureDescriptor(dataset, measure) {
|
|
41
|
+
if (!isBaseMeasure(measure))
|
|
42
|
+
return { wireType: 'string', nullable: true, having: true };
|
|
43
|
+
if (measure.aggregation === 'merge') {
|
|
44
|
+
return { wireType: 'string', nullable: true, having: !ORDERED_STATES.has(String(measure.stateFunction)) };
|
|
45
|
+
}
|
|
46
|
+
if (!ORDERED_AGGREGATIONS.has(measure.aggregation))
|
|
47
|
+
return { wireType: 'string', nullable: true, having: true };
|
|
48
|
+
const dimension = Object.hasOwn(dataset.dimensions, measure.field) ? dataset.dimensions[measure.field] : undefined;
|
|
49
|
+
return { wireType: 'string', nullable: true, having: dimension?.fieldType === 'number' };
|
|
50
|
+
}
|
|
51
|
+
export function datasetFilterDescriptor(dimension, filter) {
|
|
52
|
+
const type = dimension.fieldType;
|
|
53
|
+
// An undeclared list allows every value operator; null checks must be named (RFC 0023).
|
|
54
|
+
const operators = [...new Set((filter.operators ?? SEMANTIC_FILTER_OPERATORS).filter(operator => type === 'boolean'
|
|
55
|
+
? BOOLEAN_OPERATORS.has(operator)
|
|
56
|
+
: type !== 'number' || operator !== 'like'))].sort();
|
|
57
|
+
return operators.length ? { type, operators } : null;
|
|
58
|
+
}
|
|
59
|
+
/** Tenant identities come from the caller's credential, never from request predicates. */
|
|
60
|
+
function requestFilter(dataset, field) {
|
|
61
|
+
return dataset.tenantKey === undefined || (dataset.dimensions[field].column ?? field) !== dataset.tenantKey;
|
|
62
|
+
}
|
|
63
|
+
/** The fields a measure's fixed filters read, through any derived dependencies. */
|
|
64
|
+
function measureFilterFields(dataset, name) {
|
|
65
|
+
const pending = [name];
|
|
66
|
+
const seen = new Set();
|
|
67
|
+
const fields = [];
|
|
68
|
+
while (pending.length) {
|
|
69
|
+
const current = pending.pop();
|
|
70
|
+
if (seen.has(current) || !Object.hasOwn(dataset.measures, current))
|
|
71
|
+
continue;
|
|
72
|
+
seen.add(current);
|
|
73
|
+
const measure = dataset.measures[current];
|
|
74
|
+
if (isDerivedMeasure(measure))
|
|
75
|
+
pending.push(...Object.values(measure.uses));
|
|
76
|
+
else if (isBaseMeasure(measure)) {
|
|
77
|
+
for (const filter of measure.filters ?? []) {
|
|
78
|
+
fields.push(Object.hasOwn(dataset.filters, filter.field) ? dataset.filters[filter.field].field : filter.field);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return fields;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The fields one dataset endpoint advertises, resolved from the definition as
|
|
86
|
+
* Python's `public_fields` does with `related=()`. Relationship fields are not
|
|
87
|
+
* exported yet, so a measure whose fixed filters cross a relationship is left out.
|
|
88
|
+
*/
|
|
89
|
+
export function datasetPublicFields(dataset) {
|
|
90
|
+
// Object.fromEntries defines each name as an own key, `__proto__` included.
|
|
91
|
+
const dimensions = Object.fromEntries(Object.entries(dataset.dimensions)
|
|
92
|
+
.map(([name, dimension]) => [name, datasetDimensionDescriptor(dimension)]));
|
|
93
|
+
const measures = Object.fromEntries(Object.entries(dataset.measures)
|
|
94
|
+
.filter(([name]) => servableMeasure(dataset, name)
|
|
95
|
+
&& measureFilterFields(dataset, name).every(field => !field.includes('.')))
|
|
96
|
+
.map(([name, measure]) => [name, datasetMeasureDescriptor(dataset, measure)]));
|
|
97
|
+
const filters = Object.fromEntries(Object.entries(dataset.filters).flatMap(([name, filter]) => {
|
|
98
|
+
if (filter.field.includes('.'))
|
|
99
|
+
return [];
|
|
100
|
+
if (!Object.hasOwn(dataset.dimensions, filter.field)) {
|
|
101
|
+
throw new Error(`Client export: filter "${dataset.name}.${name}" references unknown dimension "${filter.field}".`);
|
|
102
|
+
}
|
|
103
|
+
if (!requestFilter(dataset, filter.field))
|
|
104
|
+
return [];
|
|
105
|
+
const descriptor = datasetFilterDescriptor(dataset.dimensions[filter.field], filter);
|
|
106
|
+
return descriptor ? [[name, descriptor]] : [];
|
|
107
|
+
}));
|
|
108
|
+
return { dimensions, measures, filters };
|
|
109
|
+
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { ClientEndpointAnnotations, ProtocolDeploymentDataset } from '@hypequery/protocol';
|
|
2
2
|
/** Fold whitespace runs so multi-line definitions stay advertisable; omit blank text. */
|
|
3
3
|
export declare function annotationText(value: string | undefined): string | undefined;
|
|
4
|
-
/**
|
|
5
|
-
export declare function
|
|
4
|
+
/** Folded, non-blank, first-occurrence items; omitted when none remain. */
|
|
5
|
+
export declare function annotationList(values: readonly string[] | undefined): string[] | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Group text from the dataset; field text for each advertised dimension and
|
|
8
|
+
* measure. With `fieldMetadata`, fields also carry their synonyms, examples,
|
|
9
|
+
* format, unit and currency.
|
|
10
|
+
*/
|
|
11
|
+
export declare function endpointAnnotations(dataset: ProtocolDeploymentDataset, dimensions: readonly string[], measures: readonly string[], fieldMetadata?: boolean): ClientEndpointAnnotations | undefined;
|
|
6
12
|
//# sourceMappingURL=deployment-annotations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployment-annotations.d.ts","sourceRoot":"","sources":["../../src/client-contract/deployment-annotations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EAEzB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"deployment-annotations.d.ts","sourceRoot":"","sources":["../../src/client-contract/deployment-annotations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EAEzB,yBAAyB,EAE1B,MAAM,qBAAqB,CAAC;AAE7B,yFAAyF;AACzF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAI5E;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,CAI1F;AAwBD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,yBAAyB,EAClC,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,aAAa,UAAQ,GACpB,yBAAyB,GAAG,SAAS,CAgBvC"}
|
|
@@ -5,22 +5,52 @@ export function annotationText(value) {
|
|
|
5
5
|
const folded = value.split(/\s+/).filter(Boolean).join(' ');
|
|
6
6
|
return folded.trim() ? folded : undefined;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
/** Folded, non-blank, first-occurrence items; omitted when none remain. */
|
|
9
|
+
export function annotationList(values) {
|
|
10
|
+
if (values === undefined)
|
|
11
|
+
return undefined;
|
|
12
|
+
const items = [...new Set(values.flatMap(value => annotationText(value) ?? []))];
|
|
13
|
+
return items.length ? items : undefined;
|
|
14
|
+
}
|
|
15
|
+
function fieldAnnotation(definition, fieldMetadata) {
|
|
16
|
+
const node = {};
|
|
9
17
|
const label = annotationText(definition.label);
|
|
10
18
|
const description = annotationText(definition.description);
|
|
11
|
-
if (label
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
if (label !== undefined)
|
|
20
|
+
node.label = label;
|
|
21
|
+
if (description !== undefined)
|
|
22
|
+
node.description = description;
|
|
23
|
+
if (fieldMetadata) {
|
|
24
|
+
const synonyms = annotationList(definition.synonyms);
|
|
25
|
+
const examples = annotationList(definition.examples);
|
|
26
|
+
const format = annotationText(definition.format);
|
|
27
|
+
const unit = annotationText(definition.unit);
|
|
28
|
+
if (synonyms !== undefined)
|
|
29
|
+
node.synonyms = synonyms;
|
|
30
|
+
if (examples !== undefined)
|
|
31
|
+
node.examples = examples;
|
|
32
|
+
if (format !== undefined)
|
|
33
|
+
node.format = format;
|
|
34
|
+
if (unit !== undefined)
|
|
35
|
+
node.unit = unit;
|
|
36
|
+
if (definition.currency !== undefined)
|
|
37
|
+
node.currency = definition.currency;
|
|
38
|
+
}
|
|
39
|
+
return Object.keys(node).length ? node : undefined;
|
|
14
40
|
}
|
|
15
|
-
/**
|
|
16
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Group text from the dataset; field text for each advertised dimension and
|
|
43
|
+
* measure. With `fieldMetadata`, fields also carry their synonyms, examples,
|
|
44
|
+
* format, unit and currency.
|
|
45
|
+
*/
|
|
46
|
+
export function endpointAnnotations(dataset, dimensions, measures, fieldMetadata = false) {
|
|
17
47
|
const advertised = [
|
|
18
48
|
...dataset.dimensions.filter(item => dimensions.includes(item.name)),
|
|
19
49
|
...dataset.measures.filter(item => measures.includes(item.name)),
|
|
20
50
|
];
|
|
21
51
|
// Object.fromEntries defines each name as an own key, `__proto__` included.
|
|
22
52
|
const fields = Object.fromEntries(advertised.flatMap(definition => {
|
|
23
|
-
const node = fieldAnnotation(definition);
|
|
53
|
+
const node = fieldAnnotation(definition, fieldMetadata);
|
|
24
54
|
return node ? [[definition.name, node]] : [];
|
|
25
55
|
}));
|
|
26
56
|
const description = annotationText(dataset.description);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ClientDimension, ClientFilter, ClientMeasure, ProtocolDatasetDimension, ProtocolDatasetFilter, ProtocolDeploymentDataset, ProtocolDeploymentMeasure } from '@hypequery/protocol';
|
|
2
|
+
import type { ClientContractCapabilities } from './build-from-deployment.js';
|
|
2
3
|
/** Local fields have unknown nullability; the client contract says so rather than guess. */
|
|
3
4
|
export declare function dimensionDescriptor(dimension: ProtocolDatasetDimension): ClientDimension;
|
|
4
|
-
/** `having`
|
|
5
|
-
export declare function measureDescriptor(dataset: ProtocolDeploymentDataset, measure: ProtocolDeploymentMeasure): ClientMeasure;
|
|
5
|
+
/** Every measure's value is a decimal string; `having` only where the host executes it and it compares numbers. */
|
|
6
|
+
export declare function measureDescriptor(dataset: ProtocolDeploymentDataset, measure: ProtocolDeploymentMeasure, capabilities: ClientContractCapabilities): ClientMeasure;
|
|
6
7
|
export declare function filterDescriptor(dimension: ProtocolDatasetDimension, filter: ProtocolDatasetFilter): ClientFilter | null;
|
|
7
8
|
/** Tenant identities come from the caller's credential, never from request predicates. */
|
|
8
9
|
export declare function requestFilter(dataset: ProtocolDeploymentDataset, dimension: ProtocolDatasetDimension): boolean;
|
|
@@ -11,7 +12,7 @@ export declare function requestFilter(dataset: ProtocolDeploymentDataset, dimens
|
|
|
11
12
|
* exported yet, matching Python's default (`related=()`), so a measure whose
|
|
12
13
|
* fixed filters cross a relationship is left out rather than advertised.
|
|
13
14
|
*/
|
|
14
|
-
export declare function publicFields(dataset: ProtocolDeploymentDataset): {
|
|
15
|
+
export declare function publicFields(dataset: ProtocolDeploymentDataset, capabilities: ClientContractCapabilities): {
|
|
15
16
|
dimensions: Record<string, ClientDimension>;
|
|
16
17
|
measures: Record<string, ClientMeasure>;
|
|
17
18
|
filters: Record<string, ClientFilter>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployment-fields.d.ts","sourceRoot":"","sources":["../../src/client-contract/deployment-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACb,wBAAwB,EACxB,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EAE1B,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"deployment-fields.d.ts","sourceRoot":"","sources":["../../src/client-contract/deployment-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACb,wBAAwB,EACxB,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EAE1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAS7E,4FAA4F;AAC5F,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,wBAAwB,GAAG,eAAe,CAQxF;AAWD,mHAAmH;AACnH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,yBAAyB,EAClC,YAAY,EAAE,0BAA0B,GACvC,aAAa,CAEf;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,wBAAwB,EAAE,MAAM,EAAE,qBAAqB,GAAG,YAAY,GAAG,IAAI,CAKxH;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,OAAO,EAAE,yBAAyB,EAAE,SAAS,EAAE,wBAAwB,GAAG,OAAO,CAI9G;AAmCD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,yBAAyB,EAAE,YAAY,EAAE,0BAA0B,GAAG;IAC1G,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACvC,CAkBA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// As Python's builder: booleans compare by equality and membership only.
|
|
2
|
-
|
|
2
|
+
// Null checks stay: a boolean column can hold NULL (RFC 0023).
|
|
3
|
+
const BOOLEAN_OPERATORS = new Set(['eq', 'neq', 'in', 'notIn', 'isNull', 'isNotNull']);
|
|
3
4
|
const ORDERED_AGGREGATIONS = new Set(['min', 'max', 'argMin', 'argMax']);
|
|
4
5
|
/** Stored states whose merged value is the stored value itself, which may not be a number. */
|
|
5
6
|
const ORDERED_STATES = new Set(['min', 'max', 'any', 'anyLast']);
|
|
@@ -14,17 +15,19 @@ export function dimensionDescriptor(dimension) {
|
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
/** `having` compares numbers, so ordered aggregations over non-numeric fields can't take it. */
|
|
17
|
-
|
|
18
|
+
function havingAllowed(dataset, measure) {
|
|
18
19
|
if ('kind' in measure)
|
|
19
|
-
return
|
|
20
|
-
if (measure.aggregation === 'merge')
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return { wireType: 'string', nullable: true, having: true };
|
|
25
|
-
}
|
|
20
|
+
return true;
|
|
21
|
+
if (measure.aggregation === 'merge')
|
|
22
|
+
return !ORDERED_STATES.has(String(measure.stateFunction));
|
|
23
|
+
if (!ORDERED_AGGREGATIONS.has(measure.aggregation))
|
|
24
|
+
return true;
|
|
26
25
|
const dimension = dataset.dimensions.find(item => item.name === measure.field);
|
|
27
|
-
return
|
|
26
|
+
return dimension?.type === 'number';
|
|
27
|
+
}
|
|
28
|
+
/** Every measure's value is a decimal string; `having` only where the host executes it and it compares numbers. */
|
|
29
|
+
export function measureDescriptor(dataset, measure, capabilities) {
|
|
30
|
+
return { wireType: 'string', nullable: true, having: capabilities.having === true && havingAllowed(dataset, measure) };
|
|
28
31
|
}
|
|
29
32
|
export function filterDescriptor(dimension, filter) {
|
|
30
33
|
const operators = [...new Set(filter.operators.filter(operator => dimension.type === 'boolean'
|
|
@@ -80,11 +83,11 @@ function measureFilterFields(dataset, name) {
|
|
|
80
83
|
* exported yet, matching Python's default (`related=()`), so a measure whose
|
|
81
84
|
* fixed filters cross a relationship is left out rather than advertised.
|
|
82
85
|
*/
|
|
83
|
-
export function publicFields(dataset) {
|
|
86
|
+
export function publicFields(dataset, capabilities) {
|
|
84
87
|
const dimensions = Object.fromEntries(dataset.dimensions.map(dimension => [dimension.name, dimensionDescriptor(dimension)]));
|
|
85
88
|
const measures = Object.fromEntries(dataset.measures
|
|
86
89
|
.filter(measure => measureFilterFields(dataset, measure.name).every(field => !field.includes('.')))
|
|
87
|
-
.map(measure => [measure.name, measureDescriptor(dataset, measure)]));
|
|
90
|
+
.map(measure => [measure.name, measureDescriptor(dataset, measure, capabilities)]));
|
|
88
91
|
// Built with Object.fromEntries, as above: assigning a key such as
|
|
89
92
|
// `__proto__` would set the prototype instead of adding an entry.
|
|
90
93
|
const filters = Object.fromEntries(dataset.filters.flatMap((filter) => {
|
|
@@ -17,6 +17,15 @@ export interface ClientContractProfile {
|
|
|
17
17
|
readonly defaultTimezone?: string;
|
|
18
18
|
}
|
|
19
19
|
export declare function resolveClientContractProfile(profile?: ClientContractProfile): Required<ClientContractProfile>;
|
|
20
|
+
/** A definition's own query ceilings, as datasets and deployment datasets both carry them. */
|
|
21
|
+
export interface ClientLimitCeilings {
|
|
22
|
+
readonly maxResultSize?: number;
|
|
23
|
+
readonly maxDimensions?: number;
|
|
24
|
+
readonly maxMeasures?: number;
|
|
25
|
+
readonly maxFilters?: number;
|
|
26
|
+
}
|
|
27
|
+
/** Intersect the profile with a definition's ceilings and an endpoint's page cap; never widen them. */
|
|
28
|
+
export declare function narrowClientQueryLimits(ceilings: ClientLimitCeilings | undefined, endpointMaxLimit: number | undefined, profile: Required<ClientContractProfile>): ClientQueryLimits;
|
|
20
29
|
/** Intersect the profile with the dataset's own ceilings; never widen them. */
|
|
21
30
|
export declare function clientQueryLimits(dataset: ProtocolDeploymentDataset, profile: Required<ClientContractProfile>): ClientQueryLimits;
|
|
22
31
|
//# sourceMappingURL=deployment-profile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployment-profile.d.ts","sourceRoot":"","sources":["../../src/client-contract/deployment-profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAExF;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,gDAAgD;IAChD,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAcD,wBAAgB,4BAA4B,CAAC,OAAO,GAAE,qBAA0B,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAEjH;AAID,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,iBAAiB,
|
|
1
|
+
{"version":3,"file":"deployment-profile.d.ts","sourceRoot":"","sources":["../../src/client-contract/deployment-profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAExF;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,gDAAgD;IAChD,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAcD,wBAAgB,4BAA4B,CAAC,OAAO,GAAE,qBAA0B,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAEjH;AAID,8FAA8F;AAC9F,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,uGAAuG;AACvG,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,mBAAmB,GAAG,SAAS,EACzC,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GACvC,iBAAiB,CAYnB;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,iBAAiB,CAEjI"}
|
|
@@ -13,17 +13,21 @@ export function resolveClientContractProfile(profile = {}) {
|
|
|
13
13
|
return { ...DEFAULT_PROFILE, ...Object.fromEntries(Object.entries(profile).filter(([, value]) => value !== undefined)) };
|
|
14
14
|
}
|
|
15
15
|
const narrower = (ceiling, value) => value === undefined ? ceiling : Math.min(ceiling, value);
|
|
16
|
-
/** Intersect the profile with
|
|
17
|
-
export function
|
|
18
|
-
const maxLimit = narrower(narrower(profile.maxLimit,
|
|
16
|
+
/** Intersect the profile with a definition's ceilings and an endpoint's page cap; never widen them. */
|
|
17
|
+
export function narrowClientQueryLimits(ceilings, endpointMaxLimit, profile) {
|
|
18
|
+
const maxLimit = narrower(narrower(profile.maxLimit, ceilings?.maxResultSize), endpointMaxLimit);
|
|
19
19
|
return {
|
|
20
20
|
defaultLimit: Math.min(profile.defaultLimit, maxLimit),
|
|
21
21
|
maxLimit,
|
|
22
22
|
maxOffset: profile.maxOffset,
|
|
23
|
-
maxDimensions: narrower(profile.maxDimensions,
|
|
24
|
-
maxMeasures: narrower(profile.maxMeasures,
|
|
25
|
-
maxPredicates: narrower(profile.maxPredicates,
|
|
23
|
+
maxDimensions: narrower(profile.maxDimensions, ceilings?.maxDimensions),
|
|
24
|
+
maxMeasures: narrower(profile.maxMeasures, ceilings?.maxMeasures),
|
|
25
|
+
maxPredicates: narrower(profile.maxPredicates, ceilings?.maxFilters),
|
|
26
26
|
maxOrderBy: profile.maxOrderBy,
|
|
27
27
|
maxFilterValues: profile.maxFilterValues,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
/** Intersect the profile with the dataset's own ceilings; never widen them. */
|
|
31
|
+
export function clientQueryLimits(dataset, profile) {
|
|
32
|
+
return narrowClientQueryLimits(dataset.limits, dataset.endpoint?.maxLimit, profile);
|
|
33
|
+
}
|