@hypequery/serve 0.17.1 → 0.17.2
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 +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/protocol-adapter.js +1 -1
- package/package.json +2 -2
- package/dist/protocol-schema-adapter.d.ts +0 -9
- package/dist/protocol-schema-adapter.d.ts.map +0 -1
- package/dist/protocol-schema-adapter.js +0 -239
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,12 @@ export { buildProtocolDeploymentContract } from './protocol-adapter.js';
|
|
|
22
22
|
export type { BuildProtocolDeploymentOptions } from './protocol-adapter.js';
|
|
23
23
|
export { analyzeCloudCompatibility, formatCloudCompatibilityDiagnostics, } from './cloud-compatibility.js';
|
|
24
24
|
export type { CloudCompatibilityCode, CloudCompatibilityDiagnostic, CloudCompatibilitySeverity, } from './cloud-compatibility.js';
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Re-exported from `@hypequery/datasets`, where it now lives beside the schema
|
|
27
|
+
* builders it converts. Kept here because it is a shipped export of this
|
|
28
|
+
* package and removing it would break importers for no benefit.
|
|
29
|
+
*/
|
|
30
|
+
export { ProtocolSchemaAdapterError, zodToProtocolSchema } from '@hypequery/datasets';
|
|
26
31
|
/** @deprecated Import from `@hypequery/serve/dev` instead. */
|
|
27
32
|
export { serveDev } from "./dev.js";
|
|
28
33
|
export * from "./serve.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,W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oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACtF,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACxF,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACtG,OAAO,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AACxE,YAAY,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EACL,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,sBAAsB,EACtB,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC;AAClC;;;;GAIG;AACH,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACtF,8DAA8D;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AAGpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,12 @@ export { startServer, toNodeHandler, toFetchHandler } from "./adapters/standalon
|
|
|
18
18
|
export { createCacheObservability, detectBuilderCache } from "./cache-observability.js";
|
|
19
19
|
export { buildProtocolDeploymentContract } from './protocol-adapter.js';
|
|
20
20
|
export { analyzeCloudCompatibility, formatCloudCompatibilityDiagnostics, } from './cloud-compatibility.js';
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Re-exported from `@hypequery/datasets`, where it now lives beside the schema
|
|
23
|
+
* builders it converts. Kept here because it is a shipped export of this
|
|
24
|
+
* package and removing it would break importers for no benefit.
|
|
25
|
+
*/
|
|
26
|
+
export { ProtocolSchemaAdapterError, zodToProtocolSchema } from '@hypequery/datasets';
|
|
22
27
|
/** @deprecated Import from `@hypequery/serve/dev` instead. */
|
|
23
28
|
export { serveDev } from "./dev.js";
|
|
24
29
|
export * from "./serve.js";
|
package/dist/protocol-adapter.js
CHANGED
|
@@ -3,7 +3,7 @@ import { buildProtocolDatasetContract, } from '@hypequery/datasets';
|
|
|
3
3
|
import { analyzeCloudCompatibility, formatCloudCompatibilityDiagnostics, } from './cloud-compatibility.js';
|
|
4
4
|
import { resolveDatasetEntry } from './semantic/datasets/utils/dataset-entry.js';
|
|
5
5
|
import { resolveMetricEntry } from './semantic/datasets/metric-endpoint.js';
|
|
6
|
-
import { zodToProtocolSchema } from '
|
|
6
|
+
import { zodToProtocolSchema } from '@hypequery/datasets';
|
|
7
7
|
import { resolveLocalAuthRequirement } from './auth-requirement.js';
|
|
8
8
|
function reportCloudCompatibility(config, options) {
|
|
9
9
|
const diagnostics = analyzeCloudCompatibility(config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypequery/serve",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.2",
|
|
4
4
|
"description": "Code-first TypeScript runtime for validated ClickHouse analytics APIs, OpenAPI, auth, and tenancy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"clickhouse",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"openapi-typescript": "^7.13.0",
|
|
40
40
|
"zod": "^3.23.8",
|
|
41
41
|
"zod-to-json-schema": "^3.23.5",
|
|
42
|
-
"@hypequery/datasets": "^0.
|
|
42
|
+
"@hypequery/datasets": "^0.16.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"tsx": "^4.0.0",
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;AA0OD,qEAAqE;AACrE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,UAAU,GAAG,SAAS,EAC9B,IAAI,SAAM,GACT,cAAc,CAGhB"}
|
|
@@ -1,239 +0,0 @@
|
|
|
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
|
-
default:
|
|
231
|
-
throw new ProtocolSchemaAdapterError(`Unsupported Zod type "${typeName(schema)}"`, path);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
/** Converts the portable subset of a Zod v3 schema into RFC 0004. */
|
|
235
|
-
export function zodToProtocolSchema(schema, path = '$') {
|
|
236
|
-
if (schema === undefined)
|
|
237
|
-
return validateProtocolSchema({ kind: 'any' });
|
|
238
|
-
return validateProtocolSchema(convert(schema, path));
|
|
239
|
-
}
|