@travetto/schema 8.0.0-alpha.15 → 8.0.0-alpha.17
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/schema",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Data type registry for runtime validation, reflection and binding.",
|
|
6
6
|
"keywords": [
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"directory": "module/schema"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@travetto/registry": "^8.0.0-alpha.
|
|
31
|
+
"@travetto/registry": "^8.0.0-alpha.16"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@travetto/transformer": "^8.0.0-alpha.
|
|
34
|
+
"@travetto/transformer": "^8.0.0-alpha.11"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@travetto/transformer": {
|
|
@@ -4,7 +4,7 @@ import { RuntimeError, BinaryUtil, castKey, castTo, type Class, describeFunction
|
|
|
4
4
|
import {
|
|
5
5
|
type SchemaClassConfig, type SchemaMethodConfig, type SchemaFieldConfig,
|
|
6
6
|
type SchemaParameterConfig, type SchemaInputConfig, type SchemaFieldMap, type SchemaCoreConfig,
|
|
7
|
-
|
|
7
|
+
CONSTRUCTOR_PROPERTY
|
|
8
8
|
} from './types.ts';
|
|
9
9
|
|
|
10
10
|
export type SchemaDiscriminatedInfo = Required<Pick<SchemaClassConfig, 'discriminatedType' | 'discriminatedField' | 'discriminatedBase'>>;
|
|
@@ -23,19 +23,13 @@ function assignMetadata<T>(key: symbol, base: SchemaCoreConfig, data: Partial<T>
|
|
|
23
23
|
return castTo(out);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function combineCore<T extends SchemaCoreConfig>(base: T, config: Partial<T>): T {
|
|
27
|
-
return
|
|
26
|
+
function combineCore<T extends SchemaCoreConfig>(base: T, config: Partial<T>): Pick<Partial<T>, 'metadata' | 'private' | 'description' | 'examples'> {
|
|
27
|
+
return {
|
|
28
28
|
...config.metadata ? { metadata: { ...base.metadata, ...config.metadata } } : {},
|
|
29
29
|
...config.private ? { private: config.private ?? base.private } : {},
|
|
30
30
|
...config.description ? { description: config.description || base.description } : {},
|
|
31
31
|
...config.examples ? { examples: [...(base.examples ?? []), ...(config.examples ?? [])] } : {},
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function ensureBinary<T extends SchemaBasicType>(config?: T): void {
|
|
36
|
-
if (config?.type) {
|
|
37
|
-
config.binary = BinaryUtil.isBinaryTypeReference(config.type);
|
|
38
|
-
}
|
|
32
|
+
};
|
|
39
33
|
}
|
|
40
34
|
|
|
41
35
|
function combineInputs<T extends SchemaInputConfig>(base: T, configs: Partial<T>[]): T {
|
|
@@ -51,10 +45,9 @@ function combineInputs<T extends SchemaInputConfig>(base: T, configs: Partial<T>
|
|
|
51
45
|
values: (config.enum?.values ?? base.enum?.values ?? []).toSorted()
|
|
52
46
|
}
|
|
53
47
|
} : {},
|
|
48
|
+
...combineCore(base, config)
|
|
54
49
|
});
|
|
55
50
|
}
|
|
56
|
-
combineCore(base, config);
|
|
57
|
-
ensureBinary(base);
|
|
58
51
|
}
|
|
59
52
|
return base;
|
|
60
53
|
}
|
|
@@ -63,16 +56,15 @@ function combineMethods<T extends SchemaMethodConfig>(base: T, configs: Partial<
|
|
|
63
56
|
for (const config of configs) {
|
|
64
57
|
safeAssign(base, {
|
|
65
58
|
...config,
|
|
59
|
+
...combineCore(base, config),
|
|
66
60
|
parameters: config.parameters ?? base.parameters,
|
|
67
61
|
validators: [...base.validators, ...(config.validators ?? [])],
|
|
68
62
|
});
|
|
69
|
-
combineCore(base, config);
|
|
70
63
|
if (config.parameters) {
|
|
71
64
|
for (const param of config.parameters) {
|
|
72
65
|
safeAssign(base.parameters[param.index], param);
|
|
73
66
|
}
|
|
74
67
|
}
|
|
75
|
-
ensureBinary(config.returnType);
|
|
76
68
|
}
|
|
77
69
|
return base;
|
|
78
70
|
}
|
|
@@ -137,11 +129,11 @@ function combineClasses<T extends SchemaClassConfig>(base: T, configs: Partial<T
|
|
|
137
129
|
...config,
|
|
138
130
|
...config.views ? { views: { ...base.views, ...config.views } } : {},
|
|
139
131
|
...config.validators ? { validators: [...base.validators, ...config.validators] } : {},
|
|
132
|
+
...combineCore(base, config),
|
|
140
133
|
interfaces: [...base.interfaces, ...(config.interfaces ?? [])],
|
|
141
134
|
methods: { ...base.methods, ...config.methods },
|
|
142
135
|
fields: { ...base.fields, ...config.fields },
|
|
143
136
|
});
|
|
144
|
-
combineCore(base, config);
|
|
145
137
|
}
|
|
146
138
|
return base;
|
|
147
139
|
}
|
|
@@ -284,11 +276,22 @@ export class SchemaRegistryAdapter implements RegistryAdapter<SchemaClassConfig>
|
|
|
284
276
|
|
|
285
277
|
for (const method of Object.values(config.methods)) {
|
|
286
278
|
method.parameters = method.parameters.toSorted((a, b) => (a.index! - b.index!));
|
|
279
|
+
if (method.returnType?.type) {
|
|
280
|
+
method.returnType.binary = BinaryUtil.isBinaryTypeReference(method.returnType.type);
|
|
281
|
+
}
|
|
282
|
+
for (const input of method.parameters) {
|
|
283
|
+
if (input.type) {
|
|
284
|
+
input.binary = BinaryUtil.isBinaryTypeReference(input.type);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
// Validate if aliases are duplicated
|
|
290
290
|
const aliasMap: Record<string, SchemaFieldConfig> = {};
|
|
291
291
|
for (const field of Object.values(config.fields)) {
|
|
292
|
+
if (field.type) {
|
|
293
|
+
field.binary = BinaryUtil.isBinaryTypeReference(field.type);
|
|
294
|
+
}
|
|
292
295
|
for (const alias of field.aliases ?? []) {
|
|
293
296
|
if (alias in aliasMap && aliasMap[alias].name !== field.name) {
|
|
294
297
|
throw new RuntimeError(
|
|
@@ -40,7 +40,8 @@ export class SchemaTransformUtil {
|
|
|
40
40
|
const cls = state.factory.createClassDeclaration(
|
|
41
41
|
[
|
|
42
42
|
state.createDecorator(this.SCHEMA_IMPORT, 'Schema', state.fromLiteral({
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
description: type.description,
|
|
44
45
|
mappedOperation: type.operation,
|
|
45
46
|
mappedFields: type.fields,
|
|
46
47
|
})),
|
|
@@ -71,7 +72,7 @@ class ${uniqueId} extends ${type.mappedClassName} {
|
|
|
71
72
|
const cls = state.factory.createClassDeclaration(
|
|
72
73
|
[
|
|
73
74
|
state.createDecorator(this.SCHEMA_IMPORT, 'Schema', state.fromLiteral({
|
|
74
|
-
description: type.
|
|
75
|
+
description: type.description
|
|
75
76
|
})),
|
|
76
77
|
],
|
|
77
78
|
id,
|
|
@@ -90,10 +90,11 @@ export class SchemaTransformer {
|
|
|
90
90
|
const existing = state.findDecorator(this, node, 'Schema', SchemaTransformUtil.SCHEMA_IMPORT);
|
|
91
91
|
const cons = node.members.find(member => ts.isConstructorDeclaration(member));
|
|
92
92
|
|
|
93
|
-
const attrs: Record<string, string | boolean | ts.Expression | number | object | unknown[]> = {};
|
|
93
|
+
const attrs: Record<string, string | boolean | ts.Expression | number | object | unknown[] | undefined> = {};
|
|
94
94
|
|
|
95
95
|
if (comments.description) {
|
|
96
96
|
attrs.description = comments.description;
|
|
97
|
+
attrs.examples = comments.examples;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
// Extract all interfaces
|