@travetto/schema 8.0.0-alpha.0 → 8.0.0-alpha.10

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.0",
3
+ "version": "8.0.0-alpha.10",
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.0"
31
+ "@travetto/registry": "^8.0.0-alpha.10"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/transformer": "^8.0.0-alpha.0"
34
+ "@travetto/transformer": "^8.0.0-alpha.5"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/transformer": {
@@ -285,6 +285,27 @@ export class SchemaRegistryAdapter implements RegistryAdapter<SchemaClassConfig>
285
285
  for (const method of Object.values(config.methods)) {
286
286
  method.parameters = method.parameters.toSorted((a, b) => (a.index! - b.index!));
287
287
  }
288
+
289
+ // Validate if aliases are duplicated
290
+ const aliasMap: Record<string, SchemaFieldConfig> = {};
291
+ for (const field of Object.values(config.fields)) {
292
+ for (const alias of field.aliases ?? []) {
293
+ if (alias in aliasMap && aliasMap[alias].name !== field.name) {
294
+ throw new RuntimeError(
295
+ `Alias ${alias} has been specified multiple times ${this.#cls.name}#(${field.name},${aliasMap[alias].name})`,
296
+ {
297
+ details: {
298
+ alias,
299
+ class: this.#cls.name,
300
+ field1: field.name,
301
+ field2: aliasMap[alias].name
302
+ }
303
+ }
304
+ );
305
+ }
306
+ aliasMap[alias] = field;
307
+ }
308
+ }
288
309
  }
289
310
 
290
311
  get(): SchemaClassConfig {
@@ -11,8 +11,8 @@ export class SchemaRegistryIndex implements RegistryIndex {
11
11
 
12
12
  static #instance = Registry.registerIndex(SchemaRegistryIndex);
13
13
 
14
- static getForRegister(cls: Class, allowFinalized = false): SchemaRegistryAdapter {
15
- return this.#instance.store.getForRegister(cls, allowFinalized);
14
+ static getForRegister(cls: Class): SchemaRegistryAdapter {
15
+ return this.#instance.store.getForRegister(cls);
16
16
  }
17
17
 
18
18
  static getConfig(cls: Class): SchemaClassConfig {
@@ -199,13 +199,13 @@ export class SchemaValidator {
199
199
  delete error.regex;
200
200
  }
201
201
 
202
- const msg = result.message ?? (
202
+ const message = result.message ?? (
203
203
  Messages.get(error.regex ?? '') ??
204
204
  Messages.get(error.kind) ??
205
205
  Messages.get('default')!
206
206
  );
207
207
 
208
- error.message = msg
208
+ error.message = message
209
209
  .replace(/\{([^}]+)\}/g, (_, key: (keyof ValidationError)) => `${error[key]}`);
210
210
 
211
211
  out.push(error);