@travetto/schema 3.0.0-rc.10 → 3.0.0-rc.12

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
@@ -140,14 +140,13 @@ and the output would be a `Person` instance with the following structure
140
140
 
141
141
  **Terminal: Sample data output after binding**
142
142
  ```bash
143
- $ trv main support/main.person-output.ts
143
+ $ trv main doc/person-output.ts
144
144
 
145
145
  Person {
146
146
  name: 'Test',
147
147
  age: 19,
148
148
  address: Address { street1: '1234 Fun', street2: 'Unit 20' }
149
149
  }
150
- 
151
150
  ```
152
151
 
153
152
  **Note**: Binding will attempt to convert/coerce types as much as possible to honor the pattern of Javascript and it's dynamic nature.
@@ -201,9 +200,27 @@ would produce an exception similar to following structure
201
200
 
202
201
  **Terminal: Sample error output**
203
202
  ```bash
204
- $ trv main support/main.person-invalid-output.ts
205
-
206
- 
203
+ $ trv main doc/person-invalid-output.ts
204
+
205
+ Validation Failed {
206
+ "message": "Validation errors have occurred",
207
+ "category": "data",
208
+ "type": "ValidationResultError",
209
+ "at": "2029-03-14T04:00:00.618Z",
210
+ "errors": [
211
+ {
212
+ "kind": "type",
213
+ "message": "age is not a valid number",
214
+ "path": "age",
215
+ "type": "number"
216
+ },
217
+ {
218
+ "kind": "required",
219
+ "message": "address.street2 is required",
220
+ "path": "address.street2"
221
+ }
222
+ ]
223
+ }
207
224
  ```
208
225
 
209
226
  ### Custom Validators
@@ -324,7 +341,20 @@ All that happens now, is the type is exported, and the class above is able to pr
324
341
 
325
342
  **Terminal: Custom Type Validation**
326
343
  ```bash
327
- $ trv main support/main.custom-type-output.ts
328
-
329
- 
344
+ $ trv main doc/custom-type-output.ts
345
+
346
+ Validation Failed {
347
+ "message": "Validation errors have occurred",
348
+ "category": "data",
349
+ "type": "ValidationResultError",
350
+ "at": "2029-03-14T04:00:00.837Z",
351
+ "errors": [
352
+ {
353
+ "kind": "type",
354
+ "message": "point is not a valid PointImpl",
355
+ "path": "point",
356
+ "type": "PointImpl"
357
+ }
358
+ ]
359
+ }
330
360
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/schema",
3
- "version": "3.0.0-rc.10",
3
+ "version": "3.0.0-rc.12",
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.0.0-rc.10"
30
+ "@travetto/registry": "^3.0.0-rc.12"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/transformer": "^3.0.0-rc.9"
33
+ "@travetto/transformer": "^3.0.0-rc.11"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@travetto/transformer": {
package/src/bind-util.ts CHANGED
@@ -306,4 +306,15 @@ export class BindUtil {
306
306
  }
307
307
  return params;
308
308
  }
309
+
310
+ /**
311
+ * Coerce method parameters when possible
312
+ * @param cls
313
+ * @param method
314
+ * @param params
315
+ * @returns
316
+ */
317
+ static coerceMethodParams<T>(cls: Class<T>, method: string, params: unknown[], applyDefaults = false): unknown[] {
318
+ return this.coerceFields(SchemaRegistry.getMethodSchema(cls, method), params, applyDefaults);
319
+ }
309
320
  }
@@ -3,7 +3,6 @@ import { MetadataRegistry, RootRegistry, ChangeEvent } from '@travetto/registry'
3
3
 
4
4
  import { ClassList, FieldConfig, ClassConfig, SchemaConfig, ViewFieldsConfig, ViewConfig } from './types';
5
5
  import { SchemaChangeListener } from './changes';
6
- import { BindUtil } from '../bind-util';
7
6
  import { AllViewⲐ } from '../internal/types';
8
7
 
9
8
  function hasType<T>(o: unknown): o is { type: Class<T> | string } {
@@ -244,17 +243,6 @@ class $SchemaRegistry extends MetadataRegistry<ClassConfig, FieldConfig> {
244
243
  return cache.get(method)! ?? [];
245
244
  }
246
245
 
247
- /**
248
- * Coerce method parameters when possible
249
- * @param cls
250
- * @param method
251
- * @param params
252
- * @returns
253
- */
254
- coerceMethodParams<T>(cls: Class<T>, method: string, params: unknown[], applyDefaults = false): unknown[] {
255
- return BindUtil.coerceFields(this.getMethodSchema(cls, method), params, applyDefaults);
256
- }
257
-
258
246
  /**
259
247
  * Register a view
260
248
  * @param target The target class