@travetto/schema 3.1.0-rc.4 → 3.1.0-rc.6
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 +2 -0
- package/package.json +3 -3
- package/src/decorator/field.ts +9 -8
- package/src/service/registry.ts +14 -0
- package/src/service/types.ts +1 -1
- package/support/transform-util.ts +5 -4
package/README.md
CHANGED
|
@@ -81,6 +81,8 @@ This schema provides a powerful base for data binding and validation at runtime.
|
|
|
81
81
|
* [@LongText](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/field.ts#L91) same as text, but expects longer form content
|
|
82
82
|
* [@Readonly](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/field.ts#L58) defines a that field should not be bindable external to the class
|
|
83
83
|
* [@Writeonly](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/field.ts#L52) defines a that field should not be exported in serialization, but that it can be bound to
|
|
84
|
+
* [@Secret](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/field.ts#L64) marks a field as being sensitive. This is used by certain logging activities to ensure sensitive information is not logged out.
|
|
85
|
+
* [@Specifier](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/field.ts#L206) attributes additional specifiers to a field, allowing for more specification beyond just the field's type.
|
|
84
86
|
Additionally, schemas can be nested to form more complex data structures that are able to bound and validated.
|
|
85
87
|
|
|
86
88
|
Just like the class, all fields can be defined with
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/schema",
|
|
3
|
-
"version": "3.1.0-rc.
|
|
3
|
+
"version": "3.1.0-rc.6",
|
|
4
4
|
"description": "Data type registry for runtime validation, reflection and binding.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"schema",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"directory": "module/schema"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/registry": "^3.1.0-rc.
|
|
30
|
+
"@travetto/registry": "^3.1.0-rc.3"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/transformer": "^3.1.0-rc.
|
|
33
|
+
"@travetto/transformer": "^3.1.0-rc.4"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|
|
36
36
|
"@travetto/transformer": {
|
package/src/decorator/field.ts
CHANGED
|
@@ -44,12 +44,6 @@ export function Field(type: ClassList, ...config: Partial<FieldConfig>[]) {
|
|
|
44
44
|
* @augments `@travetto/schema:Field`
|
|
45
45
|
*/
|
|
46
46
|
export function Alias(...aliases: string[]): PropType<unknown> { return prop({ aliases }); }
|
|
47
|
-
/**
|
|
48
|
-
* Specifier for the field
|
|
49
|
-
* @param specifier The specifier for a field
|
|
50
|
-
* @augments `@travetto/schema:Field`
|
|
51
|
-
*/
|
|
52
|
-
export function Specifier(specifier: string): PropType<unknown> { return prop({ specifier }); }
|
|
53
47
|
/**
|
|
54
48
|
* Mark a field as writeonly
|
|
55
49
|
* @param active This determines if this field is readonly or not.
|
|
@@ -89,12 +83,12 @@ export function Enum(values: string[], message?: string): PropType<string | numb
|
|
|
89
83
|
* Mark the field as indicating it's storing textual data
|
|
90
84
|
* @augments `@travetto/schema:Field`
|
|
91
85
|
*/
|
|
92
|
-
export function Text(): PropType<string | string[]> { return prop({
|
|
86
|
+
export function Text(): PropType<string | string[]> { return prop({ specifiers: ['text'] }); }
|
|
93
87
|
/**
|
|
94
88
|
* Mark the field to indicate it's for long form text
|
|
95
89
|
* @augments `@travetto/schema:Field`
|
|
96
90
|
*/
|
|
97
|
-
export function LongText(): PropType<string | string[]> { return prop({
|
|
91
|
+
export function LongText(): PropType<string | string[]> { return prop({ specifiers: ['text', 'long'] }); }
|
|
98
92
|
|
|
99
93
|
/**
|
|
100
94
|
* Require the field to match a specific RegExp
|
|
@@ -203,3 +197,10 @@ export function Currency(): PropType<number> { return Precision(13, 2); }
|
|
|
203
197
|
export function Ignore(): PropertyDecorator {
|
|
204
198
|
return (target: Object, property: string | symbol) => { };
|
|
205
199
|
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Specifier for the field
|
|
203
|
+
* @param specifiers The specifiers for a field
|
|
204
|
+
* @augments `@travetto/schema:Field`
|
|
205
|
+
*/
|
|
206
|
+
export function Specifier(...specifiers: string[]): PropType<unknown> { return prop({ specifiers }); }
|
package/src/service/registry.ts
CHANGED
|
@@ -253,6 +253,14 @@ class $SchemaRegistry extends MetadataRegistry<ClassConfig, FieldConfig> {
|
|
|
253
253
|
registerPendingParamFacet(target: Class, method: string, idx: number, config: Partial<FieldConfig>): Class {
|
|
254
254
|
const methods = this.getOrCreatePending(target)!.methods!;
|
|
255
255
|
const params = (methods[method] ??= []);
|
|
256
|
+
|
|
257
|
+
if (config.aliases) {
|
|
258
|
+
config.aliases = [...params[idx]?.aliases ?? [], ...config.aliases];
|
|
259
|
+
}
|
|
260
|
+
if (config.specifiers) {
|
|
261
|
+
config.specifiers = [...params[idx]?.specifiers ?? [], ...config.specifiers];
|
|
262
|
+
}
|
|
263
|
+
|
|
256
264
|
params[idx] = {
|
|
257
265
|
// @ts-expect-error
|
|
258
266
|
name: `${method}.${idx}`,
|
|
@@ -279,6 +287,12 @@ class $SchemaRegistry extends MetadataRegistry<ClassConfig, FieldConfig> {
|
|
|
279
287
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
280
288
|
allViewConf.schema[prop] = {} as FieldConfig;
|
|
281
289
|
}
|
|
290
|
+
if (config.aliases) {
|
|
291
|
+
config.aliases = [...allViewConf.schema[prop].aliases ?? [], ...config.aliases];
|
|
292
|
+
}
|
|
293
|
+
if (config.specifiers) {
|
|
294
|
+
config.specifiers = [...allViewConf.schema[prop].specifiers ?? [], ...config.specifiers];
|
|
295
|
+
}
|
|
282
296
|
|
|
283
297
|
Object.assign(allViewConf.schema[prop], config);
|
|
284
298
|
|
package/src/service/types.ts
CHANGED
|
@@ -13,7 +13,7 @@ export class SchemaTransformUtil {
|
|
|
13
13
|
static toConcreteType(state: TransformerState, type: AnyType, node: ts.Node, root: ts.Node = node): ts.Expression {
|
|
14
14
|
switch (type.key) {
|
|
15
15
|
case 'pointer': return this.toConcreteType(state, type.target, node, root);
|
|
16
|
-
case '
|
|
16
|
+
case 'managed': return state.getOrImport(type);
|
|
17
17
|
case 'tuple': return state.fromLiteral(type.subTypes.map(x => this.toConcreteType(state, x, node, root)!));
|
|
18
18
|
case 'literal': {
|
|
19
19
|
if ((type.ctor === Array) && type.typeArguments?.length) {
|
|
@@ -60,6 +60,7 @@ export class SchemaTransformUtil {
|
|
|
60
60
|
}
|
|
61
61
|
break;
|
|
62
62
|
}
|
|
63
|
+
case 'foreign':
|
|
63
64
|
case 'unknown':
|
|
64
65
|
default: {
|
|
65
66
|
// Object
|
|
@@ -148,7 +149,7 @@ export class SchemaTransformUtil {
|
|
|
148
149
|
if (args.length > 0) {
|
|
149
150
|
params.push(args[0]);
|
|
150
151
|
}
|
|
151
|
-
params.push(state.
|
|
152
|
+
params.push(state.factory.createObjectLiteralExpression(attrs));
|
|
152
153
|
if (args.length > 1) {
|
|
153
154
|
params.push(...args.slice(1));
|
|
154
155
|
}
|
|
@@ -208,7 +209,7 @@ export class SchemaTransformUtil {
|
|
|
208
209
|
static ensureType(state: TransformerState, anyType: AnyType, target: ts.Node): Record<string, unknown> {
|
|
209
210
|
const { out, type } = this.unwrapType(anyType);
|
|
210
211
|
switch (type?.key) {
|
|
211
|
-
case '
|
|
212
|
+
case 'managed': out.type = state.typeToIdentifier(type); break;
|
|
212
213
|
case 'shape': out.type = SchemaTransformUtil.toConcreteType(state, type, target); break;
|
|
213
214
|
case 'literal': {
|
|
214
215
|
if (type.ctor) {
|
|
@@ -233,7 +234,7 @@ export class SchemaTransformUtil {
|
|
|
233
234
|
const { type } = this.unwrapType(state.resolveReturnType(node));
|
|
234
235
|
let cls;
|
|
235
236
|
switch (type?.key) {
|
|
236
|
-
case '
|
|
237
|
+
case 'managed': {
|
|
237
238
|
const [dec] = DeclarationUtil.getDeclarations(type.original!);
|
|
238
239
|
cls = dec && ts.isClassDeclaration(dec) ? dec : undefined;
|
|
239
240
|
break;
|