@travetto/schema 7.0.4 → 7.0.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 CHANGED
@@ -246,7 +246,7 @@ Within the schema framework, it is possible to add custom validators class level
246
246
 
247
247
  **Code: Password Validator**
248
248
  ```typescript
249
- import { Schema, Validator, ValidationError } from '@travetto/schema';
249
+ import { Schema, Validator, type ValidationError } from '@travetto/schema';
250
250
 
251
251
  const passwordValidator = (user: User): ValidationError | undefined => {
252
252
  const password = user.password;
@@ -368,7 +368,7 @@ What you can see here is that the `Point` type is now backed by a class that sup
368
368
 
369
369
  **Code: Simple Custom Type Usage**
370
370
  ```typescript
371
- import { Schema, Point } from '@travetto/schema';
371
+ import { Schema, type Point } from '@travetto/schema';
372
372
 
373
373
  @Schema()
374
374
  export class LocationAware {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/schema",
3
- "version": "7.0.4",
3
+ "version": "7.0.6",
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": "^7.0.4"
31
+ "@travetto/registry": "^7.0.6"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/transformer": "^7.0.3"
34
+ "@travetto/transformer": "^7.0.5"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/transformer": {
package/src/bind-util.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { castTo, Class, classConstruct, asFull, TypedObject, castKey } from '@travetto/runtime';
1
+ import { castTo, type Class, classConstruct, asFull, TypedObject, castKey } from '@travetto/runtime';
2
2
 
3
3
  import { DataUtil } from './data.ts';
4
- import { SchemaInputConfig, SchemaParameterConfig, SchemaFieldMap } from './service/types.ts';
4
+ import type { SchemaInputConfig, SchemaParameterConfig, SchemaFieldMap } from './service/types.ts';
5
5
  import { SchemaRegistryIndex } from './service/registry-index.ts';
6
6
 
7
7
  type BindConfig = {
package/src/data.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { isNumberObject, isBooleanObject, isStringObject } from 'node:util/types';
2
2
 
3
- import { asConstructable, castTo, Class, asFull, TypedObject } from '@travetto/runtime';
3
+ import { asConstructable, castTo, type Class, asFull, TypedObject } from '@travetto/runtime';
4
4
  import { UnknownType } from './types.ts';
5
5
 
6
- const REGEX_PAT = /[\/](.*)[\/](i|g|m|s)?/;
6
+ const REGEX_PATTERN = /[\/](.*)[\/](i|g|m|s)?/;
7
7
 
8
8
  /**
9
9
  * Utilities for data conversion and binding
@@ -110,9 +110,9 @@ export class DataUtil {
110
110
  static toRegex(input: string | RegExp): RegExp {
111
111
  if (input instanceof RegExp) {
112
112
  return input;
113
- } else if (REGEX_PAT.test(input)) {
114
- const [, pat, mod] = input.match(REGEX_PAT) ?? [];
115
- return new RegExp(pat, mod);
113
+ } else if (REGEX_PATTERN.test(input)) {
114
+ const [, pattern, module] = input.match(REGEX_PATTERN) ?? [];
115
+ return new RegExp(pattern, module);
116
116
  } else {
117
117
  return new RegExp(input);
118
118
  }
@@ -1,6 +1,6 @@
1
- import { Class, ClassInstance, getClass } from '@travetto/runtime';
1
+ import { type Class, type ClassInstance, getClass } from '@travetto/runtime';
2
2
 
3
- import { SchemaCoreConfig } from '../service/types.ts';
3
+ import type { SchemaCoreConfig } from '../service/types.ts';
4
4
  import { SchemaRegistryIndex } from '../service/registry-index.ts';
5
5
 
6
6
  /**
@@ -1,6 +1,6 @@
1
- import { Any, ClassInstance, getClass } from '@travetto/runtime';
1
+ import { type Any, type ClassInstance, getClass } from '@travetto/runtime';
2
2
 
3
- import { SchemaFieldConfig } from '../service/types.ts';
3
+ import type { SchemaFieldConfig } from '../service/types.ts';
4
4
  import { SchemaRegistryIndex } from '../service/registry-index.ts';
5
5
 
6
6
  type PropType<V> = (<T extends Partial<Record<K, V | Function>>, K extends string>(
@@ -1,7 +1,7 @@
1
- import { Any, Class, ClassInstance, getClass } from '@travetto/runtime';
1
+ import { type Any, type Class, type ClassInstance, getClass } from '@travetto/runtime';
2
2
 
3
3
  import { CommonRegex } from '../validate/regex.ts';
4
- import { CONSTRUCTOR_PROPERTY, SchemaInputConfig } from '../service/types.ts';
4
+ import { CONSTRUCTOR_PROPERTY, type SchemaInputConfig } from '../service/types.ts';
5
5
  import { SchemaRegistryIndex } from '../service/registry-index.ts';
6
6
 
7
7
  type PropType<V> = (<T extends Partial<Record<K, V | Function>>, K extends string>(
@@ -1,8 +1,8 @@
1
- import { Any, castTo, ClassInstance, getClass } from '@travetto/runtime';
1
+ import { type Any, castTo, type ClassInstance, getClass } from '@travetto/runtime';
2
2
 
3
- import { SchemaMethodConfig } from '../service/types';
4
- import { SchemaRegistryIndex } from '../service/registry-index';
5
- import { MethodValidatorFn } from '../validate/types';
3
+ import type { SchemaMethodConfig } from '../service/types.ts';
4
+ import { SchemaRegistryIndex } from '../service/registry-index.ts';
5
+ import type { MethodValidatorFn } from '../validate/types.ts';
6
6
 
7
7
  type MethodDecorator = (instance: ClassInstance, property: string, descriptor: PropertyDescriptor) => PropertyDescriptor | void;
8
8
 
@@ -1,8 +1,8 @@
1
- import { castTo, Class, DeepPartial } from '@travetto/runtime';
1
+ import { castTo, type Class, type DeepPartial } from '@travetto/runtime';
2
2
 
3
3
  import { BindUtil } from '../bind-util.ts';
4
- import { SchemaClassConfig, ViewFieldsConfig } from '../service/types.ts';
5
- import { ValidatorFn } from '../validate/types.ts';
4
+ import type { SchemaClassConfig, ViewFieldsConfig } from '../service/types.ts';
5
+ import type { ValidatorFn } from '../validate/types.ts';
6
6
  import { SchemaRegistryIndex } from '../service/registry-index.ts';
7
7
 
8
8
  /**
package/src/name.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SchemaClassConfig } from './service/types.ts';
1
+ import type { SchemaClassConfig } from './service/types.ts';
2
2
 
3
3
  const ID_REGEX = /(\d{1,100})Δ$/;
4
4
 
@@ -1,11 +1,11 @@
1
1
  import type { RegistryAdapter } from '@travetto/registry';
2
- import { AppError, castKey, castTo, Class, describeFunction, safeAssign } from '@travetto/runtime';
2
+ import { AppError, castKey, castTo, type Class, describeFunction, safeAssign } from '@travetto/runtime';
3
3
 
4
4
  import {
5
- SchemaClassConfig, SchemaMethodConfig, SchemaFieldConfig,
6
- SchemaParameterConfig, SchemaInputConfig, SchemaFieldMap, SchemaCoreConfig,
5
+ type SchemaClassConfig, type SchemaMethodConfig, type SchemaFieldConfig,
6
+ type SchemaParameterConfig, type SchemaInputConfig, type SchemaFieldMap, type SchemaCoreConfig,
7
7
  CONSTRUCTOR_PROPERTY
8
- } from './types';
8
+ } from './types.ts';
9
9
 
10
10
  export type SchemaDiscriminatedInfo = Required<Pick<SchemaClassConfig, 'discriminatedType' | 'discriminatedField' | 'discriminatedBase'>>;
11
11
 
@@ -1,8 +1,8 @@
1
- import { RegistrationMethods, RegistryIndex, RegistryIndexStore, Registry } from '@travetto/registry';
2
- import { AppError, castKey, castTo, Class, classConstruct, getParentClass } from '@travetto/runtime';
1
+ import { type RegistrationMethods, type RegistryIndex, RegistryIndexStore, Registry } from '@travetto/registry';
2
+ import { AppError, castKey, castTo, type Class, classConstruct, getParentClass } from '@travetto/runtime';
3
3
 
4
- import { SchemaFieldConfig, SchemaClassConfig } from './types.ts';
5
- import { SchemaDiscriminatedInfo, SchemaRegistryAdapter } from './registry-adapter.ts';
4
+ import type { SchemaFieldConfig, SchemaClassConfig } from './types.ts';
5
+ import { type SchemaDiscriminatedInfo, SchemaRegistryAdapter } from './registry-adapter.ts';
6
6
 
7
7
  /**
8
8
  * Schema registry index for managing schema configurations across classes
@@ -1,6 +1,6 @@
1
- import { Any, Class, Primitive } from '@travetto/runtime';
1
+ import type { Any, Class, Primitive } from '@travetto/runtime';
2
2
 
3
- import { MethodValidatorFn, ValidatorFn } from '../validate/types.ts';
3
+ import type { MethodValidatorFn, ValidatorFn } from '../validate/types.ts';
4
4
 
5
5
  type TemplateLiteralPart = string | NumberConstructor | StringConstructor | BooleanConstructor;
6
6
  export type TemplateLiteral = { operation: 'and' | 'or', values: (TemplateLiteralPart | TemplateLiteral)[] };
@@ -1,5 +1,5 @@
1
- import { Class, AppError } from '@travetto/runtime';
2
- import { ValidationError } from './types.ts';
1
+ import { type Class, AppError } from '@travetto/runtime';
2
+ import type { ValidationError } from './types.ts';
3
3
 
4
4
  /**
5
5
  * Validation results error.
@@ -1,7 +1,7 @@
1
- import { castKey, castTo, Class, ClassInstance, TypedObject } from '@travetto/runtime';
1
+ import { castKey, castTo, type Class, type ClassInstance, TypedObject } from '@travetto/runtime';
2
2
 
3
- import { SchemaInputConfig, SchemaFieldMap } from '../service/types.ts';
4
- import { ValidationError, ValidationKindCore, ValidationResult } from './types.ts';
3
+ import type { SchemaInputConfig, SchemaFieldMap } from '../service/types.ts';
4
+ import type { ValidationError, ValidationKindCore, ValidationResult } from './types.ts';
5
5
  import { Messages } from './messages.ts';
6
6
  import { isValidationError, TypeMismatchError, ValidationResultError } from './error.ts';
7
7
  import { DataUtil } from '../data.ts';
@@ -1,7 +1,7 @@
1
1
  import ts from 'typescript';
2
2
  import {
3
3
  type AnyType, DeclarationUtil, LiteralUtil,
4
- DecoratorUtil, DocUtil, ParamDocumentation, TransformerState, transformCast,
4
+ DecoratorUtil, DocUtil, type ParamDocumentation, type TransformerState, transformCast,
5
5
  } from '@travetto/transformer';
6
6
 
7
7
  export type ComputeConfig = { type?: AnyType, root?: ts.Node, name?: string, index?: number };
@@ -1,10 +1,5 @@
1
1
  import ts from 'typescript';
2
-
3
- import {
4
- TransformerState, OnProperty, OnClass, AfterClass, DocUtil, DeclarationUtil,
5
- OnGetter, OnSetter, OnMethod, DecoratorUtil, OnStaticMethod
6
- } from '@travetto/transformer';
7
-
2
+ import { type TransformerState, DocUtil, DeclarationUtil, DecoratorUtil, TransformerHandler } from '@travetto/transformer';
8
3
  import { SchemaTransformUtil } from './transformer/util.ts';
9
4
 
10
5
  const CONSTRUCTOR_PROPERTY = 'CONSTRUCTOR';
@@ -25,6 +20,16 @@ interface AutoState {
25
20
  */
26
21
  export class SchemaTransformer {
27
22
 
23
+ static {
24
+ TransformerHandler(this, this.startSchema, 'before', 'class', ['Schema']);
25
+ TransformerHandler(this, this.finalizeSchema, 'after', 'class', ['Schema']);
26
+ TransformerHandler(this, this.processSchemaMethod, 'before', 'method');
27
+ TransformerHandler(this, this.processSchemaMethod, 'before', 'static-method');
28
+ TransformerHandler(this, this.processSchemaField, 'before', 'property');
29
+ TransformerHandler(this, this.processSchemaGetter, 'before', 'getter');
30
+ TransformerHandler(this, this.processSchemaSetter, 'before', 'setter');
31
+ }
32
+
28
33
  static isInvisible(state: AutoState & TransformerState, node: ts.Declaration, isStatic?: boolean): boolean {
29
34
  if (!state[InSchema] && !isStatic) {
30
35
  return true;
@@ -57,7 +62,6 @@ export class SchemaTransformer {
57
62
  /**
58
63
  * Track schema on start
59
64
  */
60
- @OnClass('Schema')
61
65
  static startSchema(state: AutoState & TransformerState, node: ts.ClassDeclaration): ts.ClassDeclaration {
62
66
  state[AccessorsSymbol] = new Set();
63
67
  state[AutoEnrollMethods] = new Set();
@@ -80,7 +84,6 @@ export class SchemaTransformer {
80
84
  /**
81
85
  * Mark the end of the schema, document
82
86
  */
83
- @AfterClass('Schema')
84
87
  static finalizeSchema(state: AutoState & TransformerState, node: ts.ClassDeclaration): ts.ClassDeclaration {
85
88
  const comments = DocUtil.describeDocs(node);
86
89
 
@@ -146,8 +149,6 @@ export class SchemaTransformer {
146
149
  /**
147
150
  * Handle explicitly registered methods
148
151
  */
149
- @OnMethod()
150
- @OnStaticMethod()
151
152
  static processSchemaMethod(state: TransformerState & AutoState, node: ts.MethodDeclaration): ts.MethodDeclaration {
152
153
  if (
153
154
  this.isInvisible(state, node, node.modifiers?.some(m => m.kind === ts.SyntaxKind.StaticKeyword)) &&
@@ -185,7 +186,6 @@ export class SchemaTransformer {
185
186
  /**
186
187
  * Handle all properties, while in schema
187
188
  */
188
- @OnProperty()
189
189
  static processSchemaField(state: TransformerState & AutoState, node: ts.PropertyDeclaration): ts.PropertyDeclaration {
190
190
  if (this.isInvisible(state, node)) {
191
191
  return node;
@@ -196,7 +196,6 @@ export class SchemaTransformer {
196
196
  /**
197
197
  * Handle getters
198
198
  */
199
- @OnGetter()
200
199
  static processSchemaGetter(state: TransformerState & AutoState, node: ts.GetAccessorDeclaration): ts.GetAccessorDeclaration {
201
200
  if (this.isInvisible(state, node) || DeclarationUtil.isStatic(node)) {
202
201
  return node;
@@ -212,7 +211,6 @@ export class SchemaTransformer {
212
211
  /**
213
212
  * Handle setters
214
213
  */
215
- @OnSetter()
216
214
  static processSchemaSetter(state: TransformerState & AutoState, node: ts.SetAccessorDeclaration): ts.SetAccessorDeclaration {
217
215
  if (this.isInvisible(state, node) || DeclarationUtil.isStatic(node)) {
218
216
  return node;