@travetto/schema 3.1.0-rc.3 → 3.1.0-rc.5

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 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",
3
+ "version": "3.1.0-rc.5",
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.1"
30
+ "@travetto/registry": "^3.1.0-rc.3"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/transformer": "^3.1.0-rc.2"
33
+ "@travetto/transformer": "^3.1.0-rc.3"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@travetto/transformer": {
@@ -28,12 +28,12 @@ function prop<V>(obj: Partial<FieldConfig>): PropType<V> {
28
28
  * @param config The field configuration
29
29
  * @augments `@travetto/schema:Field`
30
30
  */
31
- export function Field(type: ClassList, config?: Partial<FieldConfig>) {
31
+ export function Field(type: ClassList, ...config: Partial<FieldConfig>[]) {
32
32
  return (f: ClassInstance, k: string, idx?: number): void => {
33
33
  if (idx !== undefined && typeof idx === 'number') {
34
- SchemaRegistry.registerPendingParamConfig(f.constructor, k, idx, type, config);
34
+ SchemaRegistry.registerPendingParamConfig(f.constructor, k, idx, type, Object.assign({}, ...config));
35
35
  } else {
36
- SchemaRegistry.registerPendingFieldConfig(f.constructor, k, type, config);
36
+ SchemaRegistry.registerPendingFieldConfig(f.constructor, k, type, Object.assign({}, ...config));
37
37
  }
38
38
  };
39
39
  }
@@ -83,12 +83,12 @@ export function Enum(values: string[], message?: string): PropType<string | numb
83
83
  * Mark the field as indicating it's storing textual data
84
84
  * @augments `@travetto/schema:Field`
85
85
  */
86
- export function Text(): PropType<string | string[]> { return prop({ specifier: 'text' }); }
86
+ export function Text(): PropType<string | string[]> { return prop({ specifiers: ['text'] }); }
87
87
  /**
88
88
  * Mark the field to indicate it's for long form text
89
89
  * @augments `@travetto/schema:Field`
90
90
  */
91
- export function LongText(): PropType<string | string[]> { return prop({ specifier: 'text-long' }); }
91
+ export function LongText(): PropType<string | string[]> { return prop({ specifiers: ['text', 'long'] }); }
92
92
 
93
93
  /**
94
94
  * Require the field to match a specific RegExp
@@ -197,3 +197,10 @@ export function Currency(): PropType<number> { return Precision(13, 2); }
197
197
  export function Ignore(): PropertyDecorator {
198
198
  return (target: Object, property: string | symbol) => { };
199
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 }); }
@@ -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
 
@@ -115,7 +115,7 @@ export interface FieldConfig extends DescribableConfig {
115
115
  /**
116
116
  * Does the field have a specialization
117
117
  */
118
- specifier?: string;
118
+ specifiers?: string[];
119
119
  /**
120
120
  * The numeric precision
121
121
  */
@@ -140,12 +140,18 @@ export class SchemaTransformUtil {
140
140
  if (!existing) {
141
141
  const resolved = this.toConcreteType(state, typeExpr, node, config.root);
142
142
  params.push(resolved);
143
+ if (attrs.length) {
144
+ params.push(state.factory.createObjectLiteralExpression(attrs));
145
+ }
143
146
  } else {
144
- params.push(...DecoratorUtil.getArguments(existing) ?? []);
145
- }
146
-
147
- if (attrs.length) {
147
+ const args = DecoratorUtil.getArguments(existing) ?? [];
148
+ if (args.length > 0) {
149
+ params.push(args[0]);
150
+ }
148
151
  params.push(state.factory.createObjectLiteralExpression(attrs));
152
+ if (args.length > 1) {
153
+ params.push(...args.slice(1));
154
+ }
149
155
  }
150
156
 
151
157
  const newModifiers = [