@hypequery/datasets 0.15.0 → 0.16.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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/protocol-schema-adapter.d.ts +9 -0
- package/dist/protocol-schema-adapter.d.ts.map +1 -0
- package/dist/protocol-schema-adapter.js +249 -0
- package/dist/relationships.d.ts +25 -4
- package/dist/relationships.d.ts.map +1 -1
- package/dist/relationships.js +25 -4
- package/dist/semantic-query-schema.d.ts +19 -0
- package/dist/semantic-query-schema.d.ts.map +1 -1
- package/dist/semantic-query-schema.js +23 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export { compilePortableSqlExpression, DEFAULT_SQL_PORTABILITY_LIMITS, } from '.
|
|
|
25
25
|
export type { SqlPortabilityIssue, SqlPortabilityIssueCode, SqlPortabilityLimits, SqlPortabilityOptions, SqlPortabilityResult, } from './sql-portability.js';
|
|
26
26
|
export type { SemanticContract, SerializeSemanticContractOptions, ContractDataset, ContractDimension, ContractMeasure, ContractMetric, ContractFilter, ContractRelationship, } from './contract.js';
|
|
27
27
|
export { generateDatasetTools, toOpenAITools, toAISDKTools, toMcpTools, } from './tools.js';
|
|
28
|
-
export { buildDatasetInputSchema, buildMetricInputSchema, buildCanonicalSemanticQuerySchemas, toSemanticJsonSchema, DEFAULT_SEMANTIC_QUERY_SCHEMA_LIMITS, } from './semantic-query-schema.js';
|
|
28
|
+
export { buildDatasetInputSchema, buildMetricInputSchema, buildCanonicalSemanticQuerySchemas, toSemanticJsonSchema, DEFAULT_SEMANTIC_QUERY_SCHEMA_LIMITS, buildDatasetInputProtocolSchema, buildMetricInputProtocolSchema, } from './semantic-query-schema.js';
|
|
29
29
|
export type { CanonicalSemanticQuerySchemas, SemanticMetricQueryContract, SemanticQuerySchemaLimits, SemanticQuerySchemaOptions, SemanticQuerySchemaSource, } from './semantic-query-schema.js';
|
|
30
30
|
export type { AISDKToolDefinition, DatasetToolAnalytics, DatasetToolMode, GenerateDatasetToolsOptions, JsonSchema, McpToolDefinition, OpenAIToolDefinition, SemanticToolDefinition, } from './tools.js';
|
|
31
31
|
export { createDatasetClient } from './executor.js';
|
|
@@ -43,4 +43,5 @@ export { toQueryBuilderFactory } from './query-builder-protocol.js';
|
|
|
43
43
|
export { validateSQLIdentifier, isSafeSQLIdentifier, quoteSQLIdentifier } from './sql-utils.js';
|
|
44
44
|
export { GRAIN_FUNCTIONS, SEMANTIC_FILTER_OPERATORS, SUPPORTED_TIME_GRAINS } from './constants.js';
|
|
45
45
|
export type { FieldType, DimensionType, DimensionOptions, DimensionDefinition, MeasureOptions, MeasureDefinition, InferDimensionType, RelationshipKind, RelationshipDefinition, AggregationType, MeasureAggregation, AggregationSpec, FormulaExpr, DerivedMetricSpec, TimeGrain, MetricRef, BaseMetricRef, DerivedMetricRef, GrainedMetricRef, MetricContract, MetricFilter, MetricOrderBy, MetricQuery, DatasetQuery, MetricResultMeta, MetricResult, DatasetQueryResult, MetricHandle, ExecutionContext, SemanticExecutionRuntime, SemanticTenantRuntime, SemanticFilterDefinition, SemanticFiltersDefinition, DatasetConfig, DatasetDefaults, DatasetFreshness, DatasetLimits, DatasetCachePolicy, SemanticMetadata, SemanticSensitivity, DatasetInstance, AnyDatasetInstance, BaseMetricConfig, DerivedMetricConfig, DatasetRegistryInstance, DatasetFieldNames, DatasetDimensionNames, DatasetQueryableDimensions, DatasetMeasureNames, DatasetOrderableNames, DatasetQueryFor, DatasetRow, DatasetRowFor, DatasetQueryResultFor, MetricQueryFor, MetricRow, MetricRowFor, MetricResultFor, KnownStringKeys, } from './types.js';
|
|
46
|
+
export { ProtocolSchemaAdapterError, zodToProtocolSchema } from './protocol-schema-adapter.js';
|
|
46
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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,iBAAiB,EACjB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,SAAS,EACT,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ export { compilePortableSqlExpression, DEFAULT_SQL_PORTABILITY_LIMITS, } from '.
|
|
|
33
33
|
// Agent/tool metadata
|
|
34
34
|
export { generateDatasetTools, toOpenAITools, toAISDKTools, toMcpTools, } from './tools.js';
|
|
35
35
|
// Canonical semantic query schemas shared by Serve, MCP, and agent adapters.
|
|
36
|
-
export { buildDatasetInputSchema, buildMetricInputSchema, buildCanonicalSemanticQuerySchemas, toSemanticJsonSchema, DEFAULT_SEMANTIC_QUERY_SCHEMA_LIMITS, } from './semantic-query-schema.js';
|
|
36
|
+
export { buildDatasetInputSchema, buildMetricInputSchema, buildCanonicalSemanticQuerySchemas, toSemanticJsonSchema, DEFAULT_SEMANTIC_QUERY_SCHEMA_LIMITS, buildDatasetInputProtocolSchema, buildMetricInputProtocolSchema, } from './semantic-query-schema.js';
|
|
37
37
|
// Dataset client
|
|
38
38
|
export { createDatasetClient } from './executor.js';
|
|
39
39
|
// Semantic query result cache
|
|
@@ -49,3 +49,4 @@ export { toQueryBuilderFactory } from './query-builder-protocol.js';
|
|
|
49
49
|
export { validateSQLIdentifier, isSafeSQLIdentifier, quoteSQLIdentifier } from './sql-utils.js';
|
|
50
50
|
// Constants
|
|
51
51
|
export { GRAIN_FUNCTIONS, SEMANTIC_FILTER_OPERATORS, SUPPORTED_TIME_GRAINS } from './constants.js';
|
|
52
|
+
export { ProtocolSchemaAdapterError, zodToProtocolSchema } from './protocol-schema-adapter.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ZodTypeAny } from 'zod';
|
|
2
|
+
import { type ProtocolSchema } from '@hypequery/protocol';
|
|
3
|
+
export declare class ProtocolSchemaAdapterError extends TypeError {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
constructor(message: string, path?: string);
|
|
6
|
+
}
|
|
7
|
+
/** Converts the portable subset of a Zod v3 schema into RFC 0004. */
|
|
8
|
+
export declare function zodToProtocolSchema(schema: ZodTypeAny | undefined, path?: string): ProtocolSchema;
|
|
9
|
+
//# sourceMappingURL=protocol-schema-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-schema-adapter.d.ts","sourceRoot":"","sources":["../src/protocol-schema-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,qBAAqB,CAAC;AAE7B,qBAAa,0BAA2B,SAAQ,SAAS;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,IAAI,SAAM;CAKxC;AAoPD,qEAAqE;AACrE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,UAAU,GAAG,SAAS,EAC9B,IAAI,SAAM,GACT,cAAc,CAGhB"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { validateCanonicalValue, validateProtocolSchema, } from '@hypequery/protocol';
|
|
2
|
+
export class ProtocolSchemaAdapterError extends TypeError {
|
|
3
|
+
path;
|
|
4
|
+
constructor(message, path = '$') {
|
|
5
|
+
super(`${message} at ${path}`);
|
|
6
|
+
this.name = 'ProtocolSchemaAdapterError';
|
|
7
|
+
this.path = path;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function canonicalValue(input, path) {
|
|
11
|
+
try {
|
|
12
|
+
if (Array.isArray(input)) {
|
|
13
|
+
return validateCanonicalValue({
|
|
14
|
+
$hypequery: {
|
|
15
|
+
type: 'array',
|
|
16
|
+
version: 1,
|
|
17
|
+
values: input.map((item, index) => canonicalValue(item, `${path}[${index}]`)),
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (typeof input === 'object' && input !== null) {
|
|
22
|
+
if ('$hypequery' in input)
|
|
23
|
+
return validateCanonicalValue(input);
|
|
24
|
+
const prototype = Object.getPrototypeOf(input);
|
|
25
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
26
|
+
throw new ProtocolSchemaAdapterError('Default is not portable plain data', path);
|
|
27
|
+
}
|
|
28
|
+
return validateCanonicalValue({
|
|
29
|
+
$hypequery: {
|
|
30
|
+
type: 'map',
|
|
31
|
+
version: 1,
|
|
32
|
+
entries: Object.entries(input)
|
|
33
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
34
|
+
.map(([key, value]) => [key, canonicalValue(value, `${path}.${key}`)]),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return validateCanonicalValue(input);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error instanceof ProtocolSchemaAdapterError)
|
|
42
|
+
throw error;
|
|
43
|
+
throw new ProtocolSchemaAdapterError('Default is not a canonical protocol value', path);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function typeName(schema) {
|
|
47
|
+
return String(schema?._def?.typeName ?? 'Unknown');
|
|
48
|
+
}
|
|
49
|
+
function description(schema) {
|
|
50
|
+
return typeof schema.description === 'string'
|
|
51
|
+
? schema.description
|
|
52
|
+
: undefined;
|
|
53
|
+
}
|
|
54
|
+
function annotate(schema, result) {
|
|
55
|
+
const value = description(schema);
|
|
56
|
+
return value === undefined ? result : { ...result, description: value };
|
|
57
|
+
}
|
|
58
|
+
function convertString(schema, path) {
|
|
59
|
+
const result = { kind: 'string' };
|
|
60
|
+
for (const check of schema._def.checks) {
|
|
61
|
+
switch (check.kind) {
|
|
62
|
+
case 'min':
|
|
63
|
+
result.minLength = check.value;
|
|
64
|
+
break;
|
|
65
|
+
case 'max':
|
|
66
|
+
result.maxLength = check.value;
|
|
67
|
+
break;
|
|
68
|
+
case 'length':
|
|
69
|
+
result.minLength = check.value;
|
|
70
|
+
result.maxLength = check.value;
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
throw new ProtocolSchemaAdapterError(`Unsupported Zod string check "${String(check.kind)}"`, path);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return annotate(schema, result);
|
|
77
|
+
}
|
|
78
|
+
function convertNumber(schema, path) {
|
|
79
|
+
const result = { kind: 'number' };
|
|
80
|
+
for (const check of schema._def.checks) {
|
|
81
|
+
switch (check.kind) {
|
|
82
|
+
case 'int':
|
|
83
|
+
result.kind = 'integer';
|
|
84
|
+
break;
|
|
85
|
+
case 'min':
|
|
86
|
+
result[check.inclusive === false ? 'exclusiveMinimum' : 'minimum'] = check.value;
|
|
87
|
+
break;
|
|
88
|
+
case 'max':
|
|
89
|
+
result[check.inclusive === false ? 'exclusiveMaximum' : 'maximum'] = check.value;
|
|
90
|
+
break;
|
|
91
|
+
case 'finite':
|
|
92
|
+
break;
|
|
93
|
+
default:
|
|
94
|
+
throw new ProtocolSchemaAdapterError(`Unsupported Zod number check "${String(check.kind)}"`, path);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return annotate(schema, result);
|
|
98
|
+
}
|
|
99
|
+
function isOptionalProperty(schema) {
|
|
100
|
+
const name = typeName(schema);
|
|
101
|
+
return name === 'ZodOptional' || name === 'ZodDefault';
|
|
102
|
+
}
|
|
103
|
+
function nativeEnumValues(input) {
|
|
104
|
+
const values = Object.keys(input)
|
|
105
|
+
.filter(key => typeof input[String(input[key])] !== 'number')
|
|
106
|
+
.map(key => input[key]);
|
|
107
|
+
return [...new Set(values)];
|
|
108
|
+
}
|
|
109
|
+
function isUnconstrainedRecordKey(schema) {
|
|
110
|
+
if (schema === undefined || typeName(schema) !== 'ZodString')
|
|
111
|
+
return false;
|
|
112
|
+
const definition = schema._def;
|
|
113
|
+
return Array.isArray(definition.checks)
|
|
114
|
+
&& definition.checks.length === 0
|
|
115
|
+
&& definition.coerce !== true;
|
|
116
|
+
}
|
|
117
|
+
function convert(schema, path) {
|
|
118
|
+
const definition = schema._def;
|
|
119
|
+
switch (typeName(schema)) {
|
|
120
|
+
case 'ZodAny':
|
|
121
|
+
case 'ZodUnknown':
|
|
122
|
+
return annotate(schema, { kind: 'any' });
|
|
123
|
+
case 'ZodNever':
|
|
124
|
+
case 'ZodVoid':
|
|
125
|
+
case 'ZodUndefined':
|
|
126
|
+
return annotate(schema, { kind: 'void' });
|
|
127
|
+
case 'ZodNull':
|
|
128
|
+
return annotate(schema, { kind: 'null' });
|
|
129
|
+
case 'ZodBoolean':
|
|
130
|
+
return annotate(schema, { kind: 'boolean' });
|
|
131
|
+
case 'ZodString':
|
|
132
|
+
return convertString(schema, path);
|
|
133
|
+
case 'ZodNumber':
|
|
134
|
+
return convertNumber(schema, path);
|
|
135
|
+
case 'ZodLiteral':
|
|
136
|
+
return annotate(schema, {
|
|
137
|
+
kind: 'literal',
|
|
138
|
+
value: canonicalValue(definition.value, `${path}.value`),
|
|
139
|
+
});
|
|
140
|
+
case 'ZodEnum':
|
|
141
|
+
return annotate(schema, {
|
|
142
|
+
kind: 'enum',
|
|
143
|
+
values: [...definition.values],
|
|
144
|
+
});
|
|
145
|
+
case 'ZodNativeEnum': {
|
|
146
|
+
const values = nativeEnumValues(definition.values);
|
|
147
|
+
return annotate(schema, { kind: 'enum', values });
|
|
148
|
+
}
|
|
149
|
+
case 'ZodArray': {
|
|
150
|
+
const result = {
|
|
151
|
+
kind: 'array',
|
|
152
|
+
items: convert(definition.type, `${path}.items`),
|
|
153
|
+
};
|
|
154
|
+
if (definition.minLength?.value !== undefined)
|
|
155
|
+
result.minItems = definition.minLength.value;
|
|
156
|
+
if (definition.maxLength?.value !== undefined)
|
|
157
|
+
result.maxItems = definition.maxLength.value;
|
|
158
|
+
if (definition.exactLength?.value !== undefined) {
|
|
159
|
+
result.minItems = definition.exactLength.value;
|
|
160
|
+
result.maxItems = definition.exactLength.value;
|
|
161
|
+
}
|
|
162
|
+
return annotate(schema, result);
|
|
163
|
+
}
|
|
164
|
+
case 'ZodObject': {
|
|
165
|
+
if (typeName(definition.catchall) !== 'ZodNever') {
|
|
166
|
+
throw new ProtocolSchemaAdapterError('Unsupported Zod object catchall', path);
|
|
167
|
+
}
|
|
168
|
+
const shape = definition.shape();
|
|
169
|
+
const properties = Object.fromEntries(Object.entries(shape).map(([name, property]) => [
|
|
170
|
+
name,
|
|
171
|
+
convert(property, `${path}.properties.${name}`),
|
|
172
|
+
]));
|
|
173
|
+
const required = Object.entries(shape)
|
|
174
|
+
.filter(([, property]) => !isOptionalProperty(property))
|
|
175
|
+
.map(([name]) => name);
|
|
176
|
+
const unknownProperties = definition.unknownKeys === 'passthrough'
|
|
177
|
+
? 'preserve'
|
|
178
|
+
: definition.unknownKeys === 'strict'
|
|
179
|
+
? 'reject'
|
|
180
|
+
: 'strip';
|
|
181
|
+
return annotate(schema, {
|
|
182
|
+
kind: 'object',
|
|
183
|
+
properties,
|
|
184
|
+
required,
|
|
185
|
+
unknownProperties,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
case 'ZodRecord':
|
|
189
|
+
if (!isUnconstrainedRecordKey(definition.keyType)) {
|
|
190
|
+
throw new ProtocolSchemaAdapterError('Unsupported constrained Zod record key', path);
|
|
191
|
+
}
|
|
192
|
+
return annotate(schema, {
|
|
193
|
+
kind: 'record',
|
|
194
|
+
values: convert(definition.valueType, `${path}.values`),
|
|
195
|
+
});
|
|
196
|
+
case 'ZodUnion':
|
|
197
|
+
return annotate(schema, {
|
|
198
|
+
kind: 'union',
|
|
199
|
+
variants: definition.options.map((option, index) => convert(option, `${path}.variants[${index}]`)),
|
|
200
|
+
});
|
|
201
|
+
case 'ZodDiscriminatedUnion':
|
|
202
|
+
// RFC 0004 has no separate discriminator index. Converting every option
|
|
203
|
+
// drops only Zod's lookup metadata; each object's literal discriminator
|
|
204
|
+
// property remains part of its protocol variant.
|
|
205
|
+
return annotate(schema, {
|
|
206
|
+
kind: 'union',
|
|
207
|
+
variants: [...definition.options.values()].map((option, index) => convert(option, `${path}.variants[${index}]`)),
|
|
208
|
+
});
|
|
209
|
+
case 'ZodNullable':
|
|
210
|
+
return annotate(schema, {
|
|
211
|
+
kind: 'union',
|
|
212
|
+
variants: [convert(definition.innerType, `${path}.variants[0]`), { kind: 'null' }],
|
|
213
|
+
});
|
|
214
|
+
case 'ZodOptional':
|
|
215
|
+
return annotate(schema, convert(definition.innerType, path));
|
|
216
|
+
case 'ZodDefault': {
|
|
217
|
+
const inner = convert(definition.innerType, path);
|
|
218
|
+
if (inner.kind === 'void') {
|
|
219
|
+
throw new ProtocolSchemaAdapterError('Void schemas cannot carry defaults', path);
|
|
220
|
+
}
|
|
221
|
+
return annotate(schema, {
|
|
222
|
+
...inner,
|
|
223
|
+
default: canonicalValue(definition.defaultValue(), `${path}.default`),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
case 'ZodBranded':
|
|
227
|
+
return annotate(schema, convert(definition.type, path));
|
|
228
|
+
case 'ZodReadonly':
|
|
229
|
+
return annotate(schema, convert(definition.innerType, path));
|
|
230
|
+
case 'ZodEffects': {
|
|
231
|
+
const effectType = String(definition.effect?.type ?? 'unknown');
|
|
232
|
+
if (effectType !== 'refinement') {
|
|
233
|
+
throw new ProtocolSchemaAdapterError(`Unsupported Zod effect "${effectType}"`, path);
|
|
234
|
+
}
|
|
235
|
+
// A refinement preserves the wrapped schema's input and output shape.
|
|
236
|
+
// The rule itself remains enforced by Zod, but cannot be advertised by
|
|
237
|
+
// ProtocolSchema (for example, a cross-field selection requirement).
|
|
238
|
+
return annotate(schema, convert(definition.schema, path));
|
|
239
|
+
}
|
|
240
|
+
default:
|
|
241
|
+
throw new ProtocolSchemaAdapterError(`Unsupported Zod type "${typeName(schema)}"`, path);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/** Converts the portable subset of a Zod v3 schema into RFC 0004. */
|
|
245
|
+
export function zodToProtocolSchema(schema, path = '$') {
|
|
246
|
+
if (schema === undefined)
|
|
247
|
+
return validateProtocolSchema({ kind: 'any' });
|
|
248
|
+
return validateProtocolSchema(convert(schema, path));
|
|
249
|
+
}
|
package/dist/relationships.d.ts
CHANGED
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Relationship helpers for dataset definitions.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* To-one relationships (`belongsTo`, `hasOne`) are queryable one hop deep as
|
|
5
|
+
* `<relationship>.<dimension>` and execute as LEFT JOINs. `hasMany` is metadata
|
|
6
|
+
* only: joining it would fan out and corrupt aggregates, so it is refused at
|
|
7
|
+
* query time.
|
|
8
|
+
*
|
|
9
|
+
* Only the target's *dimensions* are reachable. A measure on the target dataset
|
|
10
|
+
* is not addressable through a relationship, so there are no cross-dataset
|
|
11
|
+
* metrics.
|
|
12
|
+
*
|
|
13
|
+
* Note that the `kind` passed here is a declaration, not something checked
|
|
14
|
+
* against the data — there is no uniqueness concept in the model, so nothing
|
|
15
|
+
* verifies that a `belongsTo` target column really is unique. What a
|
|
16
|
+
* mis-declaration costs depends on the builder. One that implements the
|
|
17
|
+
* optional `leftAnyJoin` (ClickHouse `LEFT ANY JOIN`) takes at most one target
|
|
18
|
+
* row per base row, so the aggregate cannot inflate — it just silently picks an
|
|
19
|
+
* arbitrary one of the matches. A builder without it falls back to `leftJoin`,
|
|
20
|
+
* where duplicate target keys fan out and do inflate the aggregate. Either way
|
|
21
|
+
* the declaration has to be right.
|
|
7
22
|
*
|
|
8
23
|
* @example
|
|
9
24
|
* ```ts
|
|
10
25
|
* const Orders = dataset("orders", {
|
|
11
26
|
* source: "orders",
|
|
12
|
-
*
|
|
27
|
+
* dimensions: {
|
|
28
|
+
* id: dimension.string(),
|
|
29
|
+
* customerId: dimension.string({ column: "customer_id" }),
|
|
30
|
+
* },
|
|
13
31
|
* relationships: {
|
|
14
32
|
* customer: belongsTo(() => Customers, { from: "customerId", to: "id" }),
|
|
15
33
|
* },
|
|
16
34
|
* });
|
|
35
|
+
*
|
|
36
|
+
* // Groups by a dimension on Customers, joining through the relationship.
|
|
37
|
+
* await client.execute(Orders, { dimensions: ["customer.country"] });
|
|
17
38
|
* ```
|
|
18
39
|
*/
|
|
19
40
|
import type { RelationshipDefinition } from './types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relationships.d.ts","sourceRoot":"","sources":["../src/relationships.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"relationships.d.ts","sourceRoot":"","sources":["../src/relationships.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAoB,MAAM,YAAY,CAAC;AAmB3E,mDAAmD;AACnD,wBAAgB,SAAS,CAAC,OAAO,SAAS;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAC3E,MAAM,EAAE,MAAM,OAAO,EACrB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACjC,sBAAsB,CAAC,OAAO,EAAE,WAAW,CAAC,CAE9C;AAED,qDAAqD;AACrD,wBAAgB,OAAO,CAAC,OAAO,SAAS;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EACzE,MAAM,EAAE,MAAM,OAAO,EACrB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACjC,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAE5C;AAED,oDAAoD;AACpD,wBAAgB,MAAM,CAAC,OAAO,SAAS;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EACxE,MAAM,EAAE,MAAM,OAAO,EACrB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACjC,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAE3C"}
|
package/dist/relationships.js
CHANGED
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Relationship helpers for dataset definitions.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* To-one relationships (`belongsTo`, `hasOne`) are queryable one hop deep as
|
|
5
|
+
* `<relationship>.<dimension>` and execute as LEFT JOINs. `hasMany` is metadata
|
|
6
|
+
* only: joining it would fan out and corrupt aggregates, so it is refused at
|
|
7
|
+
* query time.
|
|
8
|
+
*
|
|
9
|
+
* Only the target's *dimensions* are reachable. A measure on the target dataset
|
|
10
|
+
* is not addressable through a relationship, so there are no cross-dataset
|
|
11
|
+
* metrics.
|
|
12
|
+
*
|
|
13
|
+
* Note that the `kind` passed here is a declaration, not something checked
|
|
14
|
+
* against the data — there is no uniqueness concept in the model, so nothing
|
|
15
|
+
* verifies that a `belongsTo` target column really is unique. What a
|
|
16
|
+
* mis-declaration costs depends on the builder. One that implements the
|
|
17
|
+
* optional `leftAnyJoin` (ClickHouse `LEFT ANY JOIN`) takes at most one target
|
|
18
|
+
* row per base row, so the aggregate cannot inflate — it just silently picks an
|
|
19
|
+
* arbitrary one of the matches. A builder without it falls back to `leftJoin`,
|
|
20
|
+
* where duplicate target keys fan out and do inflate the aggregate. Either way
|
|
21
|
+
* the declaration has to be right.
|
|
7
22
|
*
|
|
8
23
|
* @example
|
|
9
24
|
* ```ts
|
|
10
25
|
* const Orders = dataset("orders", {
|
|
11
26
|
* source: "orders",
|
|
12
|
-
*
|
|
27
|
+
* dimensions: {
|
|
28
|
+
* id: dimension.string(),
|
|
29
|
+
* customerId: dimension.string({ column: "customer_id" }),
|
|
30
|
+
* },
|
|
13
31
|
* relationships: {
|
|
14
32
|
* customer: belongsTo(() => Customers, { from: "customerId", to: "id" }),
|
|
15
33
|
* },
|
|
16
34
|
* });
|
|
35
|
+
*
|
|
36
|
+
* // Groups by a dimension on Customers, joining through the relationship.
|
|
37
|
+
* await client.execute(Orders, { dimensions: ["customer.country"] });
|
|
17
38
|
* ```
|
|
18
39
|
*/
|
|
19
40
|
function createRelationship(kind, target, join) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ZodTypeAny } from 'zod';
|
|
2
2
|
import { type DatasetCatalog, type DatasetCatalogSource, type MetricCatalogEntry } from './catalog.js';
|
|
3
3
|
import type { JsonSchema } from './tools.js';
|
|
4
|
+
import type { ProtocolSchema } from '@hypequery/protocol';
|
|
4
5
|
export interface SemanticQuerySchemaLimits {
|
|
5
6
|
defaultResultSize?: number;
|
|
6
7
|
maxResultSize?: number;
|
|
@@ -57,4 +58,22 @@ export declare function toSemanticJsonSchema(schema: ZodTypeAny, options?: {
|
|
|
57
58
|
requireSelection?: boolean;
|
|
58
59
|
}): JsonSchema;
|
|
59
60
|
export declare function buildCanonicalSemanticQuerySchemas(datasets: Record<string, SemanticQuerySchemaSource>, options?: SemanticQuerySchemaOptions): CanonicalSemanticQuerySchemas;
|
|
61
|
+
/**
|
|
62
|
+
* The same input schema, as a `ProtocolSchema`.
|
|
63
|
+
*
|
|
64
|
+
* A hosted registry advertises one endpoint per dataset and per metric, and it
|
|
65
|
+
* advertises them in the protocol's own schema format rather than Zod or JSON
|
|
66
|
+
* Schema. Without this it has to rebuild the shape by hand — which is a second
|
|
67
|
+
* generator of the knowledge `CORE-03` exists to keep in one place, and it
|
|
68
|
+
* drifts silently: an advertised field the validator rejects, or a ceiling the
|
|
69
|
+
* data plane does not apply.
|
|
70
|
+
*
|
|
71
|
+
* Derived from `buildDatasetInputSchema`, so there is one source for which
|
|
72
|
+
* dimensions are groupable, which measures exist, what the filter operators
|
|
73
|
+
* are, what the orderable fields are, which grains are supported, and what the
|
|
74
|
+
* row ceiling is.
|
|
75
|
+
*/
|
|
76
|
+
export declare function buildDatasetInputProtocolSchema(dataset: SemanticQuerySchemaSource, options?: SemanticQuerySchemaOptions, path?: string): ProtocolSchema;
|
|
77
|
+
/** The metric form of {@link buildDatasetInputProtocolSchema}. */
|
|
78
|
+
export declare function buildMetricInputProtocolSchema(dataset: SemanticQuerySchemaSource, metricName: string, options?: SemanticQuerySchemaOptions, metricContract?: SemanticMetricQueryContract, path?: string): ProtocolSchema;
|
|
60
79
|
//# sourceMappingURL=semantic-query-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic-query-schema.d.ts","sourceRoot":"","sources":["../src/semantic-query-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAK,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAEzC,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"semantic-query-schema.d.ts","sourceRoot":"","sources":["../src/semantic-query-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAK,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAEzC,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D,MAAM,WAAW,yBAAyB;IACxC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,M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2BAA2B,GAC3C,UAAU,CAaZ;AAsBD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC3C,UAAU,CAMZ;AAyBD,wBAAgB,kCAAkC,CAChD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,EACnD,OAAO,GAAE,0BAA+B,GACvC,6BAA6B,CAgD/B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,yBAAyB,EAClC,OAAO,GAAE,0BAA+B,EACxC,IAAI,SAAkB,GACrB,cAAc,CAEhB;AAED,kEAAkE;AAClE,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,yBAAyB,EAClC,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,0BAA+B,EACxC,cAAc,CAAC,EAAE,2BAA2B,EAC5C,IAAI,SAAiB,GACpB,cAAc,CAKhB"}
|
|
@@ -4,6 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
5
5
|
import { getDatasetCatalog, getGroupableRelationshipFields, getQueryableRelationshipFields, } from './catalog.js';
|
|
6
6
|
import { SEMANTIC_FILTER_OPERATORS } from './constants.js';
|
|
7
|
+
import { zodToProtocolSchema } from './protocol-schema-adapter.js';
|
|
7
8
|
import { compareStrings, stableStringify, uniqueSorted } from './utils/canonical-json.js';
|
|
8
9
|
export const DEFAULT_SEMANTIC_QUERY_SCHEMA_LIMITS = Object.freeze({
|
|
9
10
|
maxResultSize: 10_000,
|
|
@@ -221,3 +222,25 @@ export function buildCanonicalSemanticQuerySchemas(datasets, options = {}) {
|
|
|
221
222
|
manifestHash,
|
|
222
223
|
});
|
|
223
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* The same input schema, as a `ProtocolSchema`.
|
|
227
|
+
*
|
|
228
|
+
* A hosted registry advertises one endpoint per dataset and per metric, and it
|
|
229
|
+
* advertises them in the protocol's own schema format rather than Zod or JSON
|
|
230
|
+
* Schema. Without this it has to rebuild the shape by hand — which is a second
|
|
231
|
+
* generator of the knowledge `CORE-03` exists to keep in one place, and it
|
|
232
|
+
* drifts silently: an advertised field the validator rejects, or a ceiling the
|
|
233
|
+
* data plane does not apply.
|
|
234
|
+
*
|
|
235
|
+
* Derived from `buildDatasetInputSchema`, so there is one source for which
|
|
236
|
+
* dimensions are groupable, which measures exist, what the filter operators
|
|
237
|
+
* are, what the orderable fields are, which grains are supported, and what the
|
|
238
|
+
* row ceiling is.
|
|
239
|
+
*/
|
|
240
|
+
export function buildDatasetInputProtocolSchema(dataset, options = {}, path = 'dataset.input') {
|
|
241
|
+
return zodToProtocolSchema(buildDatasetInputSchema(dataset, options), path);
|
|
242
|
+
}
|
|
243
|
+
/** The metric form of {@link buildDatasetInputProtocolSchema}. */
|
|
244
|
+
export function buildMetricInputProtocolSchema(dataset, metricName, options = {}, metricContract, path = 'metric.input') {
|
|
245
|
+
return zodToProtocolSchema(buildMetricInputSchema(dataset, metricName, options, metricContract), path);
|
|
246
|
+
}
|