@cratis/fundamentals 7.17.1 → 7.18.0

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.
Files changed (95) hide show
  1. package/Fields.ts +9 -3
  2. package/StandardClassDecoratorContext.ts +14 -0
  3. package/StandardFieldDecoratorContext.ts +13 -0
  4. package/derivedTypeDecorator.ts +21 -4
  5. package/dist/Fields.d.ts.map +1 -1
  6. package/dist/Fields.js +4 -0
  7. package/dist/Fields.js.map +1 -1
  8. package/dist/StandardClassDecoratorContext.d.ts +8 -0
  9. package/dist/StandardClassDecoratorContext.d.ts.map +1 -0
  10. package/dist/StandardClassDecoratorContext.js +2 -0
  11. package/dist/StandardClassDecoratorContext.js.map +1 -0
  12. package/dist/StandardFieldDecoratorContext.d.ts +8 -0
  13. package/dist/StandardFieldDecoratorContext.d.ts.map +1 -0
  14. package/dist/StandardFieldDecoratorContext.js +2 -0
  15. package/dist/StandardFieldDecoratorContext.js.map +1 -0
  16. package/dist/cjs/Fields.d.ts.map +1 -1
  17. package/dist/cjs/Fields.js +4 -0
  18. package/dist/cjs/Fields.js.map +1 -1
  19. package/dist/cjs/StandardClassDecoratorContext.d.ts +8 -0
  20. package/dist/cjs/StandardClassDecoratorContext.d.ts.map +1 -0
  21. package/dist/cjs/StandardFieldDecoratorContext.d.ts +8 -0
  22. package/dist/cjs/StandardFieldDecoratorContext.d.ts.map +1 -0
  23. package/dist/cjs/derivedTypeDecorator.d.ts +5 -1
  24. package/dist/cjs/derivedTypeDecorator.d.ts.map +1 -1
  25. package/dist/cjs/derivedTypeDecorator.js +18 -2
  26. package/dist/cjs/derivedTypeDecorator.js.map +1 -1
  27. package/dist/cjs/fieldDecorator.d.ts +5 -1
  28. package/dist/cjs/fieldDecorator.d.ts.map +1 -1
  29. package/dist/cjs/fieldDecorator.js +33 -2
  30. package/dist/cjs/fieldDecorator.js.map +1 -1
  31. package/dist/cjs/fieldDecoratorMetadata.d.ts +6 -0
  32. package/dist/cjs/fieldDecoratorMetadata.d.ts.map +1 -0
  33. package/dist/cjs/fieldDecoratorMetadata.js +23 -0
  34. package/dist/cjs/fieldDecoratorMetadata.js.map +1 -0
  35. package/dist/cjs/reflection.d.ts.map +1 -1
  36. package/dist/cjs/reflection.js +9 -0
  37. package/dist/cjs/reflection.js.map +1 -1
  38. package/dist/derivedTypeDecorator.d.ts +5 -1
  39. package/dist/derivedTypeDecorator.d.ts.map +1 -1
  40. package/dist/derivedTypeDecorator.js +18 -2
  41. package/dist/derivedTypeDecorator.js.map +1 -1
  42. package/dist/esm/Fields.d.ts.map +1 -1
  43. package/dist/esm/Fields.js +4 -0
  44. package/dist/esm/Fields.js.map +1 -1
  45. package/dist/esm/StandardClassDecoratorContext.d.ts +8 -0
  46. package/dist/esm/StandardClassDecoratorContext.d.ts.map +1 -0
  47. package/dist/esm/StandardFieldDecoratorContext.d.ts +8 -0
  48. package/dist/esm/StandardFieldDecoratorContext.d.ts.map +1 -0
  49. package/dist/esm/derivedTypeDecorator.d.ts +5 -1
  50. package/dist/esm/derivedTypeDecorator.d.ts.map +1 -1
  51. package/dist/esm/derivedTypeDecorator.js +18 -2
  52. package/dist/esm/derivedTypeDecorator.js.map +1 -1
  53. package/dist/esm/fieldDecorator.d.ts +5 -1
  54. package/dist/esm/fieldDecorator.d.ts.map +1 -1
  55. package/dist/esm/fieldDecorator.js +33 -2
  56. package/dist/esm/fieldDecorator.js.map +1 -1
  57. package/dist/esm/fieldDecoratorMetadata.d.ts +6 -0
  58. package/dist/esm/fieldDecoratorMetadata.d.ts.map +1 -0
  59. package/dist/esm/fieldDecoratorMetadata.js +20 -0
  60. package/dist/esm/fieldDecoratorMetadata.js.map +1 -0
  61. package/dist/esm/reflection.d.ts.map +1 -1
  62. package/dist/esm/reflection.js +9 -0
  63. package/dist/esm/reflection.js.map +1 -1
  64. package/dist/fieldDecorator.d.ts +5 -1
  65. package/dist/fieldDecorator.d.ts.map +1 -1
  66. package/dist/fieldDecorator.js +33 -2
  67. package/dist/fieldDecorator.js.map +1 -1
  68. package/dist/fieldDecoratorMetadata.d.ts +6 -0
  69. package/dist/fieldDecoratorMetadata.d.ts.map +1 -0
  70. package/dist/fieldDecoratorMetadata.js +17 -0
  71. package/dist/fieldDecoratorMetadata.js.map +1 -0
  72. package/dist/reflection.d.ts.map +1 -1
  73. package/dist/reflection.js +9 -0
  74. package/dist/reflection.js.map +1 -1
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/fieldDecorator.ts +36 -5
  77. package/fieldDecoratorMetadata.ts +34 -0
  78. package/for_JsonSerializer/when_metadata_is_written_by_another_copy_of_the_package.ts +23 -5
  79. package/for_derivedTypeDecorator/when_an_outer_standard_decorator_replaces_the_class.ts +28 -0
  80. package/for_fieldDecorator/fixtures/standard_decorated_types.ts +76 -0
  81. package/for_fieldDecorator/when_executing_standard_typescript_decorator_emit.ts +109 -0
  82. package/for_fieldDecorator/when_invoked_as_a_legacy_decorator.ts +21 -0
  83. package/for_fieldDecorator/when_invoked_as_a_standard_decorator.ts +43 -0
  84. package/for_fieldDecorator/when_invoked_for_an_unsupported_legacy_field/with_a_static_field.ts +12 -0
  85. package/for_fieldDecorator/when_invoked_for_an_unsupported_legacy_field/with_a_symbol_name.ts +12 -0
  86. package/for_fieldDecorator/when_invoked_for_an_unsupported_standard_field/with_a_private_field.ts +16 -0
  87. package/for_fieldDecorator/when_invoked_for_an_unsupported_standard_field/with_a_static_field.ts +16 -0
  88. package/for_fieldDecorator/when_invoked_for_an_unsupported_standard_field/with_a_symbol_name.ts +16 -0
  89. package/for_fieldDecorator/when_invoked_for_an_unsupported_standard_field/without_decorator_metadata.ts +16 -0
  90. package/for_fieldDecorator/when_legacy_and_standard_metadata_are_mixed_across_inheritance.ts +43 -0
  91. package/for_fieldDecorator/when_standard_metadata_contains_unrelated_fields_metadata.ts +34 -0
  92. package/for_fieldDecorator/when_standard_metadata_is_inherited_and_overridden.ts +37 -0
  93. package/for_reflection/when_loading_with_existing_symbol_metadata.ts +25 -0
  94. package/package.json +1 -1
  95. package/reflection.ts +13 -0
package/Fields.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  import './reflection';
5
5
  import { Constructor } from './Constructor';
6
6
  import { Field } from './Field';
7
+ import { getOwnDecoratorFieldsForType } from './fieldDecoratorMetadata';
7
8
 
8
9
  /**
9
10
  * Represents a system working with fields on types.
@@ -19,9 +20,10 @@ export class Fields {
19
20
  }
20
21
 
21
22
  static getFieldsForType(target: Constructor): Field[] {
22
- // Fields are stored as own-metadata per type, so a derived type only carries the fields it
23
- // declares itself. Walk the prototype (inheritance) chain and merge every ancestor's fields so
24
- // that deserializing a derived type also populates the fields inherited from its base types.
23
+ // Fields are stored as legacy own metadata on the constructor or as standard own metadata on
24
+ // its Symbol.metadata object, so a derived type only carries the fields it declares itself.
25
+ // Walk the prototype (inheritance) chain and merge every ancestor's fields so that deserializing
26
+ // a derived type also populates the fields inherited from its base types.
25
27
  // Process from the base type down to the target so a derived field overrides a base field of the
26
28
  // same name.
27
29
  const chain: Constructor[] = [];
@@ -40,6 +42,10 @@ export class Fields {
40
42
  fieldsByName.set(name, field);
41
43
  }
42
44
  }
45
+
46
+ for (const field of getOwnDecoratorFieldsForType(type)) {
47
+ fieldsByName.set(field.name, field);
48
+ }
43
49
  }
44
50
 
45
51
  return [...fieldsByName.values()];
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { Constructor } from './Constructor';
5
+
6
+ /**
7
+ * Represents the standard decorator context used for a class.
8
+ */
9
+ export type StandardClassDecoratorContext<Target extends Constructor> = {
10
+ readonly kind: 'class';
11
+ readonly name: string | undefined;
12
+ readonly metadata: Record<PropertyKey, unknown> | undefined;
13
+ addInitializer(initializer: (this: Target) => void): void;
14
+ };
@@ -0,0 +1,13 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ /**
5
+ * Represents the standard decorator context used for a class field.
6
+ */
7
+ export type StandardFieldDecoratorContext = {
8
+ readonly kind: 'field';
9
+ readonly name: string | symbol;
10
+ readonly static: boolean;
11
+ readonly private: boolean;
12
+ readonly metadata: Record<PropertyKey, unknown> | undefined;
13
+ };
@@ -4,12 +4,27 @@
4
4
  import './reflection';
5
5
  import { Constructor } from './Constructor';
6
6
  import { DerivedType } from './DerivedType';
7
+ import { StandardClassDecoratorContext } from './StandardClassDecoratorContext';
7
8
 
9
+ export function derivedType(identifier: string, targetType?: Constructor) {
10
+ function decorator<Target extends Constructor>(target: Target): void;
11
+ function decorator<Target extends Constructor>(target: Target, context: StandardClassDecoratorContext<Target>): void;
12
+ function decorator(target: Constructor, context?: StandardClassDecoratorContext<Constructor>): void {
13
+ if (typeof target !== 'function') throw new TypeError('@derivedType can only decorate classes');
14
+ if (context && context.kind !== 'class') throw new TypeError('@derivedType can only decorate classes');
15
+ if (context && typeof context.addInitializer !== 'function') throw new TypeError('@derivedType requires a standard class decorator context');
8
16
 
9
- /* eslint-disable @typescript-eslint/no-explicit-any */
17
+ if (context) {
18
+ context.addInitializer(function (this: Constructor): void {
19
+ register(this);
20
+ });
21
+ return;
22
+ }
10
23
 
11
- export function derivedType(identifier: string, targetType?: Constructor) {
12
- return function (target: any) {
24
+ register(target);
25
+ }
26
+
27
+ function register(target: Constructor): void {
13
28
  DerivedType.set(target, identifier, targetType);
14
29
 
15
30
  // Auto-register with every class in the prototype chain so that JsonSerializer
@@ -20,5 +35,7 @@ export function derivedType(identifier: string, targetType?: Constructor) {
20
35
  DerivedType.set(target, identifier, proto.constructor);
21
36
  proto = Object.getPrototypeOf(proto);
22
37
  }
23
- };
38
+ }
39
+
40
+ return decorator;
24
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Fields.d.ts","sourceRoot":"","sources":["../Fields.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC,qBAAa,MAAM;IACf,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE;IASlK,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE;CA0BxD"}
1
+ {"version":3,"file":"Fields.d.ts","sourceRoot":"","sources":["../Fields.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMhC,qBAAa,MAAM;IACf,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE;IASlK,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE;CA+BxD"}
package/dist/Fields.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import './reflection';
2
2
  import { Field } from './Field';
3
+ import { getOwnDecoratorFieldsForType } from './fieldDecoratorMetadata';
3
4
  export class Fields {
4
5
  static addFieldToType(target, field, fieldType, enumerable, derivatives, genericArguments) {
5
6
  let fields = new Map();
@@ -25,6 +26,9 @@ export class Fields {
25
26
  fieldsByName.set(name, field);
26
27
  }
27
28
  }
29
+ for (const field of getOwnDecoratorFieldsForType(type)) {
30
+ fieldsByName.set(field.name, field);
31
+ }
28
32
  }
29
33
  return [...fieldsByName.values()];
30
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Fields.js","sourceRoot":"","s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ChC,IAAI,OAAO,GAA4B,MAAM,CAAC;QAC9C,OAAO,OAAO,IAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;YACrE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACpB,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAA4B,CAAC;QACxE,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,GAAG,EAAiB,CAAC;QAC9C,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;YACrD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC;gBACzC,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAuB,CAAC;gBAC/E,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;oBAC9C,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAClC,CAAC;YACL,CAAC;YAED,KAAK,MAAM,KAAK,IAAI,4BAA4B,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrD,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YACxC,CAAC;QACL,CAAC;QAED,OAAO,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,CAAC;CACJ"}
@@ -0,0 +1,8 @@
1
+ import { Constructor } from './Constructor';
2
+ export type StandardClassDecoratorContext<Target extends Constructor> = {
3
+ readonly kind: 'class';
4
+ readonly name: string | undefined;
5
+ readonly metadata: Record<PropertyKey, unknown> | undefined;
6
+ addInitializer(initializer: (this: Target) => void): void;
7
+ };
8
+ //# sourceMappingURL=StandardClassDecoratorContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardClassDecoratorContext.d.ts","sourceRoot":"","sources":["../StandardClassDecoratorContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5C,MAAM,MAAM,6BAA6B,CAAC,MAAM,SAAS,WAAW,IAAI;IACpE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC5D,cAAc,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;CAC7D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=StandardClassDecoratorContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardClassDecoratorContext.js","sourceRoot":"","sources":["../StandardClassDecoratorContext.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export type StandardFieldDecoratorContext = {
2
+ readonly kind: 'field';
3
+ readonly name: string | symbol;
4
+ readonly static: boolean;
5
+ readonly private: boolean;
6
+ readonly metadata: Record<PropertyKey, unknown> | undefined;
7
+ };
8
+ //# sourceMappingURL=StandardFieldDecoratorContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardFieldDecoratorContext.d.ts","sourceRoot":"","sources":["../StandardFieldDecoratorContext.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,6BAA6B,GAAG;IACxC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC/D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=StandardFieldDecoratorContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardFieldDecoratorContext.js","sourceRoot":"","sources":["../StandardFieldDecoratorContext.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"Fields.d.ts","sourceRoot":"","sources":["../../Fields.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC,qBAAa,MAAM;IACf,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE;IASlK,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE;CA0BxD"}
1
+ {"version":3,"file":"Fields.d.ts","sourceRoot":"","sources":["../../Fields.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMhC,qBAAa,MAAM;IACf,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE;IASlK,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE;CA+BxD"}
@@ -2,6 +2,7 @@
2
2
 
3
3
  require('./reflection.js');
4
4
  var Field = require('./Field.js');
5
+ var fieldDecoratorMetadata = require('./fieldDecoratorMetadata.js');
5
6
 
6
7
  class Fields {
7
8
  static addFieldToType(target, field, fieldType, enumerable, derivatives, genericArguments) {
@@ -28,6 +29,9 @@ class Fields {
28
29
  fieldsByName.set(name, field);
29
30
  }
30
31
  }
32
+ for (const field of fieldDecoratorMetadata.getOwnDecoratorFieldsForType(type)) {
33
+ fieldsByName.set(field.name, field);
34
+ }
31
35
  }
32
36
  return [...fieldsByName.values()];
33
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Fields.js","sources":["../../Fields.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\n\n/**\n * Represents a system working with fields on types.\n */\nexport class Fields {\n static addFieldToType(target: Constructor, field: string, fieldType: Constructor, enumerable: boolean, derivatives: Constructor[], genericArguments: Constructor[]) {\n let fields: Map<string, Field> = new Map<string, Field>();\n if (Reflect.hasOwnMetadata('fields', target)) {\n fields = Reflect.getOwnMetadata('fields', target);\n }\n fields.set(field, new Field(field, fieldType, enumerable, derivatives, genericArguments));\n Reflect.defineMetadata('fields', fields, target);\n }\n\n static getFieldsForType(target: Constructor): Field[] {\n // Fields are stored as own-metadata per type, so a derived type only carries the fields it\n // declares itself. Walk the prototype (inheritance) chain and merge every ancestor's fields so\n // that deserializing a derived type also populates the fields inherited from its base types.\n // Process from the base type down to the target so a derived field overrides a base field of the\n // same name.\n const chain: Constructor[] = [];\n let current: Constructor | undefined = target;\n while (current && current !== Function.prototype && current !== Object) {\n chain.push(current);\n current = Object.getPrototypeOf(current) as Constructor | undefined;\n }\n\n const fieldsByName = new Map<string, Field>();\n for (let index = chain.length - 1; index >= 0; index--) {\n const type = chain[index];\n if (Reflect.hasOwnMetadata('fields', type)) {\n const fieldsMap = Reflect.getOwnMetadata('fields', type) as Map<string, Field>;\n for (const [name, field] of fieldsMap.entries()) {\n fieldsByName.set(name, field);\n }\n }\n }\n\n return [...fieldsByName.values()];\n }\n}\n"],"names":["Field"],"mappings":";;;;;MAUa,MAAM,CAAA;AACf,IAAA,OAAO,cAAc,CAAC,MAAmB,EAAE,KAAa,EAAE,SAAsB,EAAE,UAAmB,EAAE,WAA0B,EAAE,gBAA+B,EAAA;AAC9J,QAAA,IAAI,MAAM,GAAuB,IAAI,GAAG,EAAiB;QACzD,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE;YAC1C,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC;QACrD;AACA,QAAA,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAIA,WAAK,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC;QACzF,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;IACpD;IAEA,OAAO,gBAAgB,CAAC,MAAmB,EAAA;QAMvC,MAAM,KAAK,GAAkB,EAAE;QAC/B,IAAI,OAAO,GAA4B,MAAM;AAC7C,QAAA,OAAO,OAAO,IAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,IAAI,OAAO,KAAK,MAAM,EAAE;AACpE,YAAA,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;AACnB,YAAA,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAA4B;QACvE;AAEA,QAAA,MAAM,YAAY,GAAG,IAAI,GAAG,EAAiB;AAC7C,QAAA,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;AACpD,YAAA,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC;YACzB,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE;gBACxC,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAuB;AAC9E,gBAAA,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE;AAC7C,oBAAA,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC;gBACjC;YACJ;QACJ;AAEA,QAAA,OAAO,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC;IACrC;AACH;;;;"}
1
+ {"version":3,"file":"Fields.js","sources":["../../Fields.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\nimport { getOwnDecoratorFieldsForType } from './fieldDecoratorMetadata';\n\n/**\n * Represents a system working with fields on types.\n */\nexport class Fields {\n static addFieldToType(target: Constructor, field: string, fieldType: Constructor, enumerable: boolean, derivatives: Constructor[], genericArguments: Constructor[]) {\n let fields: Map<string, Field> = new Map<string, Field>();\n if (Reflect.hasOwnMetadata('fields', target)) {\n fields = Reflect.getOwnMetadata('fields', target);\n }\n fields.set(field, new Field(field, fieldType, enumerable, derivatives, genericArguments));\n Reflect.defineMetadata('fields', fields, target);\n }\n\n static getFieldsForType(target: Constructor): Field[] {\n // Fields are stored as legacy own metadata on the constructor or as standard own metadata on\n // its Symbol.metadata object, so a derived type only carries the fields it declares itself.\n // Walk the prototype (inheritance) chain and merge every ancestor's fields so that deserializing\n // a derived type also populates the fields inherited from its base types.\n // Process from the base type down to the target so a derived field overrides a base field of the\n // same name.\n const chain: Constructor[] = [];\n let current: Constructor | undefined = target;\n while (current && current !== Function.prototype && current !== Object) {\n chain.push(current);\n current = Object.getPrototypeOf(current) as Constructor | undefined;\n }\n\n const fieldsByName = new Map<string, Field>();\n for (let index = chain.length - 1; index >= 0; index--) {\n const type = chain[index];\n if (Reflect.hasOwnMetadata('fields', type)) {\n const fieldsMap = Reflect.getOwnMetadata('fields', type) as Map<string, Field>;\n for (const [name, field] of fieldsMap.entries()) {\n fieldsByName.set(name, field);\n }\n }\n\n for (const field of getOwnDecoratorFieldsForType(type)) {\n fieldsByName.set(field.name, field);\n }\n }\n\n return [...fieldsByName.values()];\n }\n}\n"],"names":["Field","getOwnDecoratorFieldsForType"],"mappings":";;;;;;MAWa,MAAM,CAAA;AACf,IAAA,OAAO,cAAc,CAAC,MAAmB,EAAE,KAAa,EAAE,SAAsB,EAAE,UAAmB,EAAE,WAA0B,EAAE,gBAA+B,EAAA;AAC9J,QAAA,IAAI,MAAM,GAAuB,IAAI,GAAG,EAAiB;QACzD,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE;YAC1C,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC;QACrD;AACA,QAAA,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAIA,WAAK,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC;QACzF,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;IACpD;IAEA,OAAO,gBAAgB,CAAC,MAAmB,EAAA;QAOvC,MAAM,KAAK,GAAkB,EAAE;QAC/B,IAAI,OAAO,GAA4B,MAAM;AAC7C,QAAA,OAAO,OAAO,IAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,IAAI,OAAO,KAAK,MAAM,EAAE;AACpE,YAAA,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;AACnB,YAAA,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAA4B;QACvE;AAEA,QAAA,MAAM,YAAY,GAAG,IAAI,GAAG,EAAiB;AAC7C,QAAA,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;AACpD,YAAA,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC;YACzB,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE;gBACxC,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAuB;AAC9E,gBAAA,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE;AAC7C,oBAAA,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC;gBACjC;YACJ;YAEA,KAAK,MAAM,KAAK,IAAIC,mDAA4B,CAAC,IAAI,CAAC,EAAE;gBACpD,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;YACvC;QACJ;AAEA,QAAA,OAAO,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC;IACrC;AACH;;;;"}
@@ -0,0 +1,8 @@
1
+ import { Constructor } from './Constructor';
2
+ export type StandardClassDecoratorContext<Target extends Constructor> = {
3
+ readonly kind: 'class';
4
+ readonly name: string | undefined;
5
+ readonly metadata: Record<PropertyKey, unknown> | undefined;
6
+ addInitializer(initializer: (this: Target) => void): void;
7
+ };
8
+ //# sourceMappingURL=StandardClassDecoratorContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardClassDecoratorContext.d.ts","sourceRoot":"","sources":["../../StandardClassDecoratorContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5C,MAAM,MAAM,6BAA6B,CAAC,MAAM,SAAS,WAAW,IAAI;IACpE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC5D,cAAc,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;CAC7D,CAAC"}
@@ -0,0 +1,8 @@
1
+ export type StandardFieldDecoratorContext = {
2
+ readonly kind: 'field';
3
+ readonly name: string | symbol;
4
+ readonly static: boolean;
5
+ readonly private: boolean;
6
+ readonly metadata: Record<PropertyKey, unknown> | undefined;
7
+ };
8
+ //# sourceMappingURL=StandardFieldDecoratorContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardFieldDecoratorContext.d.ts","sourceRoot":"","sources":["../../StandardFieldDecoratorContext.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,6BAA6B,GAAG;IACxC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC/D,CAAC"}
@@ -1,4 +1,8 @@
1
1
  import './reflection';
2
2
  import { Constructor } from './Constructor';
3
- export declare function derivedType(identifier: string, targetType?: Constructor): (target: any) => void;
3
+ import { StandardClassDecoratorContext } from './StandardClassDecoratorContext';
4
+ export declare function derivedType(identifier: string, targetType?: Constructor): {
5
+ <Target extends Constructor>(target: Target): void;
6
+ <Target extends Constructor>(target: Target, context: StandardClassDecoratorContext<Target>): void;
7
+ };
4
8
  //# sourceMappingURL=derivedTypeDecorator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"derivedTypeDecorator.d.ts","sourceRoot":"","sources":["../../derivedTypeDecorator.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM5C,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,WAAW,IACnD,QAAQ,GAAG,UAY/B"}
1
+ {"version":3,"file":"derivedTypeDecorator.d.ts","sourceRoot":"","sources":["../../derivedTypeDecorator.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,WAAW;KACjD,MAAM,SAAS,WAAW,UAAU,MAAM,GAAG,IAAI;KACjD,MAAM,SAAS,WAAW,UAAU,MAAM,WAAW,6BAA6B,CAAC,MAAM,CAAC,GAAG,IAAI;EA8BvH"}
@@ -4,14 +4,30 @@ require('./reflection.js');
4
4
  var DerivedType = require('./DerivedType.js');
5
5
 
6
6
  function derivedType(identifier, targetType) {
7
- return function (target) {
7
+ function decorator(target, context) {
8
+ if (typeof target !== 'function')
9
+ throw new TypeError('@derivedType can only decorate classes');
10
+ if (context && context.kind !== 'class')
11
+ throw new TypeError('@derivedType can only decorate classes');
12
+ if (context && typeof context.addInitializer !== 'function')
13
+ throw new TypeError('@derivedType requires a standard class decorator context');
14
+ if (context) {
15
+ context.addInitializer(function () {
16
+ register(this);
17
+ });
18
+ return;
19
+ }
20
+ register(target);
21
+ }
22
+ function register(target) {
8
23
  DerivedType.DerivedType.set(target, identifier, targetType);
9
24
  let proto = Object.getPrototypeOf(target.prototype);
10
25
  while (proto && proto.constructor && proto.constructor !== Object) {
11
26
  DerivedType.DerivedType.set(target, identifier, proto.constructor);
12
27
  proto = Object.getPrototypeOf(proto);
13
28
  }
14
- };
29
+ }
30
+ return decorator;
15
31
  }
16
32
 
17
33
  exports.derivedType = derivedType;
@@ -1 +1 @@
1
- {"version":3,"file":"derivedTypeDecorator.js","sources":["../../derivedTypeDecorator.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { DerivedType } from './DerivedType';\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport function derivedType(identifier: string, targetType?: Constructor) {\n return function (target: any) {\n DerivedType.set(target, identifier, targetType);\n\n // Auto-register with every class in the prototype chain so that JsonSerializer\n // can discover all derived types via DerivedType.getDerivedTypesFor() at runtime,\n // without requiring the parent type to import each subtype (which causes circular deps).\n let proto = Object.getPrototypeOf(target.prototype);\n while (proto && proto.constructor && proto.constructor !== Object) {\n DerivedType.set(target, identifier, proto.constructor);\n proto = Object.getPrototypeOf(proto);\n }\n };\n}\n"],"names":["DerivedType"],"mappings":";;;;;AAUM,SAAU,WAAW,CAAC,UAAkB,EAAE,UAAwB,EAAA;AACpE,IAAA,OAAO,UAAU,MAAW,EAAA;QACxBA,uBAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC;QAK/C,IAAI,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC;AACnD,QAAA,OAAO,KAAK,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,KAAK,MAAM,EAAE;YAC/DA,uBAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,WAAW,CAAC;AACtD,YAAA,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC;QACxC;AACJ,IAAA,CAAC;AACL;;;;"}
1
+ {"version":3,"file":"derivedTypeDecorator.js","sources":["../../derivedTypeDecorator.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { DerivedType } from './DerivedType';\nimport { StandardClassDecoratorContext } from './StandardClassDecoratorContext';\n\nexport function derivedType(identifier: string, targetType?: Constructor) {\n function decorator<Target extends Constructor>(target: Target): void;\n function decorator<Target extends Constructor>(target: Target, context: StandardClassDecoratorContext<Target>): void;\n function decorator(target: Constructor, context?: StandardClassDecoratorContext<Constructor>): void {\n if (typeof target !== 'function') throw new TypeError('@derivedType can only decorate classes');\n if (context && context.kind !== 'class') throw new TypeError('@derivedType can only decorate classes');\n if (context && typeof context.addInitializer !== 'function') throw new TypeError('@derivedType requires a standard class decorator context');\n\n if (context) {\n context.addInitializer(function (this: Constructor): void {\n register(this);\n });\n return;\n }\n\n register(target);\n }\n\n function register(target: Constructor): void {\n DerivedType.set(target, identifier, targetType);\n\n // Auto-register with every class in the prototype chain so that JsonSerializer\n // can discover all derived types via DerivedType.getDerivedTypesFor() at runtime,\n // without requiring the parent type to import each subtype (which causes circular deps).\n let proto = Object.getPrototypeOf(target.prototype);\n while (proto && proto.constructor && proto.constructor !== Object) {\n DerivedType.set(target, identifier, proto.constructor);\n proto = Object.getPrototypeOf(proto);\n }\n }\n\n return decorator;\n}\n"],"names":["DerivedType"],"mappings":";;;;;AAQM,SAAU,WAAW,CAAC,UAAkB,EAAE,UAAwB,EAAA;AAGpE,IAAA,SAAS,SAAS,CAAC,MAAmB,EAAE,OAAoD,EAAA;QACxF,IAAI,OAAO,MAAM,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC;AAC/F,QAAA,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC;AACtG,QAAA,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,cAAc,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,SAAS,CAAC,0DAA0D,CAAC;QAE5I,IAAI,OAAO,EAAE;YACT,OAAO,CAAC,cAAc,CAAC,YAAA;gBACnB,QAAQ,CAAC,IAAI,CAAC;AAClB,YAAA,CAAC,CAAC;YACF;QACJ;QAEA,QAAQ,CAAC,MAAM,CAAC;IACpB;IAEA,SAAS,QAAQ,CAAC,MAAmB,EAAA;QACjCA,uBAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC;QAK/C,IAAI,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC;AACnD,QAAA,OAAO,KAAK,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,KAAK,MAAM,EAAE;YAC/DA,uBAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,WAAW,CAAC;AACtD,YAAA,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC;QACxC;IACJ;AAEA,IAAA,OAAO,SAAS;AACpB;;;;"}
@@ -1,9 +1,13 @@
1
1
  import { Constructor } from './Constructor';
2
+ import { StandardFieldDecoratorContext } from './StandardFieldDecoratorContext';
2
3
  type fieldOptions = {
3
4
  enumerable?: boolean;
4
5
  derivatives?: Constructor[];
5
6
  genericArguments?: Constructor[];
6
7
  };
7
- export declare function field(targetType: Constructor, enumerableOrOptions?: boolean | fieldOptions, derivatives?: Constructor[], genericArguments?: Constructor[]): (target: any, propertyKey: string) => void;
8
+ export declare function field(targetType: Constructor, enumerableOrOptions?: boolean | fieldOptions, derivatives?: Constructor[], genericArguments?: Constructor[]): {
9
+ (target: object, propertyKey: string): void;
10
+ (initialValue: undefined, context: StandardFieldDecoratorContext): void;
11
+ };
8
12
  export {};
9
13
  //# sourceMappingURL=fieldDecorator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fieldDecorator.d.ts","sourceRoot":"","sources":["../../fieldDecorator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5C,KAAK,YAAY,GAAG;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;IAC5B,gBAAgB,CAAC,EAAE,WAAW,EAAE,CAAC;CACpC,CAAC;AAMF,wBAAgB,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE,mBAAmB,CAAC,EAAE,OAAO,GAAG,YAAY,EAAE,WAAW,CAAC,EAAE,WAAW,EAAE,EAAE,gBAAgB,CAAC,EAAE,WAAW,EAAE,IAKrI,QAAQ,GAAG,EAAE,aAAa,MAAM,UAGpD"}
1
+ {"version":3,"file":"fieldDecorator.d.ts","sourceRoot":"","sources":["../../fieldDecorator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,KAAK,YAAY,GAAG;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;IAC5B,gBAAgB,CAAC,EAAE,WAAW,EAAE,CAAC;CACpC,CAAC;AAMF,wBAAgB,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE,mBAAmB,CAAC,EAAE,OAAO,GAAG,YAAY,EAAE,WAAW,CAAC,EAAE,WAAW,EAAE,EAAE,gBAAgB,CAAC,EAAE,WAAW,EAAE;aAK3H,MAAM,eAAe,MAAM,GAAG,IAAI;mBAC5B,SAAS,WAAW,6BAA6B,GAAG,IAAI;EAgC5F"}
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ var Field = require('./Field.js');
3
4
  var Fields = require('./Fields.js');
5
+ var fieldDecoratorMetadata = require('./fieldDecoratorMetadata.js');
4
6
 
5
7
  const isFieldOptions = (value) => {
6
8
  return typeof value === 'object' && value !== null;
@@ -9,9 +11,38 @@ function field(targetType, enumerableOrOptions, derivatives, genericArguments) {
9
11
  const enumerable = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.enumerable || false) : (enumerableOrOptions || false);
10
12
  const actualDerivatives = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.derivatives || []) : (derivatives || []);
11
13
  const actualGenericArguments = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.genericArguments || []) : (genericArguments || []);
12
- return function (target, propertyKey) {
14
+ function decorator(targetOrInitialValue, propertyKeyOrContext) {
15
+ if (typeof propertyKeyOrContext === 'object' && propertyKeyOrContext !== null) {
16
+ if (targetOrInitialValue !== undefined)
17
+ throw new TypeError('@field received an invalid standard field value');
18
+ addStandardField(propertyKeyOrContext);
19
+ return;
20
+ }
21
+ addLegacyField(targetOrInitialValue, propertyKeyOrContext);
22
+ }
23
+ function addStandardField(context) {
24
+ if (context.kind !== 'field')
25
+ throw new TypeError('@field can only decorate fields');
26
+ if (context.static)
27
+ throw new TypeError('@field cannot decorate static fields');
28
+ if (context.private)
29
+ throw new TypeError('@field cannot decorate private fields');
30
+ if (typeof context.name !== 'string')
31
+ throw new TypeError('@field cannot decorate symbol-named fields');
32
+ if (!context.metadata)
33
+ throw new TypeError('@field requires standard decorator metadata support');
34
+ fieldDecoratorMetadata.addFieldToDecoratorMetadata(context.metadata, new Field.Field(context.name, targetType, enumerable, actualDerivatives, actualGenericArguments));
35
+ }
36
+ function addLegacyField(target, propertyKey) {
37
+ if (typeof propertyKey === 'symbol')
38
+ throw new TypeError('@field cannot decorate symbol-named fields');
39
+ if (typeof propertyKey !== 'string')
40
+ throw new TypeError('@field received an invalid legacy decorator invocation');
41
+ if (!target || typeof target === 'function')
42
+ throw new TypeError('@field cannot decorate static fields');
13
43
  Fields.Fields.addFieldToType(target.constructor, propertyKey, targetType, enumerable, actualDerivatives, actualGenericArguments);
14
- };
44
+ }
45
+ return decorator;
15
46
  }
16
47
 
17
48
  exports.field = field;
@@ -1 +1 @@
1
- {"version":3,"file":"fieldDecorator.js","sources":["../../fieldDecorator.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\nimport { Fields } from './Fields';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype fieldOptions = {\n enumerable?: boolean;\n derivatives?: Constructor[];\n genericArguments?: Constructor[];\n};\n\nconst isFieldOptions = (value: boolean | fieldOptions | undefined): value is fieldOptions => {\n return typeof value === 'object' && value !== null;\n};\n\nexport function field(targetType: Constructor, enumerableOrOptions?: boolean | fieldOptions, derivatives?: Constructor[], genericArguments?: Constructor[]) {\n const enumerable = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.enumerable || false) : (enumerableOrOptions || false);\n const actualDerivatives = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.derivatives || []) : (derivatives || []);\n const actualGenericArguments = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.genericArguments || []) : (genericArguments || []);\n\n return function (target: any, propertyKey: string) {\n Fields.addFieldToType(target.constructor, propertyKey, targetType, enumerable, actualDerivatives, actualGenericArguments);\n };\n}\n"],"names":["Fields"],"mappings":";;;;AAcA,MAAM,cAAc,GAAG,CAAC,KAAyC,KAA2B;IACxF,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;AACtD,CAAC;AAEK,SAAU,KAAK,CAAC,UAAuB,EAAE,mBAA4C,EAAE,WAA2B,EAAE,gBAAgC,EAAA;IACtJ,MAAM,UAAU,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,UAAU,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,CAAC;IACnI,MAAM,iBAAiB,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,WAAW,IAAI,EAAE,KAAK,WAAW,IAAI,EAAE,CAAC;IAC7H,MAAM,sBAAsB,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,gBAAgB,IAAI,EAAE,KAAK,gBAAgB,IAAI,EAAE,CAAC;IAE5I,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAA;AAC7C,QAAAA,aAAM,CAAC,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,sBAAsB,CAAC;AAC7H,IAAA,CAAC;AACL;;;;"}
1
+ {"version":3,"file":"fieldDecorator.js","sources":["../../fieldDecorator.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\nimport { Fields } from './Fields';\nimport { addFieldToDecoratorMetadata } from './fieldDecoratorMetadata';\nimport { StandardFieldDecoratorContext } from './StandardFieldDecoratorContext';\n\ntype fieldOptions = {\n enumerable?: boolean;\n derivatives?: Constructor[];\n genericArguments?: Constructor[];\n};\n\nconst isFieldOptions = (value: boolean | fieldOptions | undefined): value is fieldOptions => {\n return typeof value === 'object' && value !== null;\n};\n\nexport function field(targetType: Constructor, enumerableOrOptions?: boolean | fieldOptions, derivatives?: Constructor[], genericArguments?: Constructor[]) {\n const enumerable = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.enumerable || false) : (enumerableOrOptions || false);\n const actualDerivatives = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.derivatives || []) : (derivatives || []);\n const actualGenericArguments = isFieldOptions(enumerableOrOptions) ? (enumerableOrOptions.genericArguments || []) : (genericArguments || []);\n\n function decorator(target: object, propertyKey: string): void;\n function decorator(initialValue: undefined, context: StandardFieldDecoratorContext): void;\n function decorator(targetOrInitialValue: object | undefined, propertyKeyOrContext: string | symbol | StandardFieldDecoratorContext): void {\n if (typeof propertyKeyOrContext === 'object' && propertyKeyOrContext !== null) {\n if (targetOrInitialValue !== undefined) throw new TypeError('@field received an invalid standard field value');\n addStandardField(propertyKeyOrContext);\n return;\n }\n\n addLegacyField(targetOrInitialValue, propertyKeyOrContext);\n }\n\n function addStandardField(context: StandardFieldDecoratorContext): void {\n if (context.kind !== 'field') throw new TypeError('@field can only decorate fields');\n if (context.static) throw new TypeError('@field cannot decorate static fields');\n if (context.private) throw new TypeError('@field cannot decorate private fields');\n if (typeof context.name !== 'string') throw new TypeError('@field cannot decorate symbol-named fields');\n if (!context.metadata) throw new TypeError('@field requires standard decorator metadata support');\n\n addFieldToDecoratorMetadata(\n context.metadata,\n new Field(context.name, targetType, enumerable, actualDerivatives, actualGenericArguments));\n }\n\n function addLegacyField(target: object | undefined, propertyKey: string | symbol): void {\n if (typeof propertyKey === 'symbol') throw new TypeError('@field cannot decorate symbol-named fields');\n if (typeof propertyKey !== 'string') throw new TypeError('@field received an invalid legacy decorator invocation');\n if (!target || typeof target === 'function') throw new TypeError('@field cannot decorate static fields');\n\n Fields.addFieldToType(target.constructor as Constructor, propertyKey, targetType, enumerable, actualDerivatives, actualGenericArguments);\n }\n\n return decorator;\n}\n"],"names":["addFieldToDecoratorMetadata","Field","Fields"],"mappings":";;;;;;AAeA,MAAM,cAAc,GAAG,CAAC,KAAyC,KAA2B;IACxF,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;AACtD,CAAC;AAEK,SAAU,KAAK,CAAC,UAAuB,EAAE,mBAA4C,EAAE,WAA2B,EAAE,gBAAgC,EAAA;IACtJ,MAAM,UAAU,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,UAAU,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,CAAC;IACnI,MAAM,iBAAiB,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,WAAW,IAAI,EAAE,KAAK,WAAW,IAAI,EAAE,CAAC;IAC7H,MAAM,sBAAsB,GAAG,cAAc,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,gBAAgB,IAAI,EAAE,KAAK,gBAAgB,IAAI,EAAE,CAAC;AAI5I,IAAA,SAAS,SAAS,CAAC,oBAAwC,EAAE,oBAAqE,EAAA;QAC9H,IAAI,OAAO,oBAAoB,KAA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AAExG,QAAAC,aAAM,CAAC,cAAc,CAAC,MAAM,CAAC,WAA0B,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,sBAAsB,CAAC;IAC5I;AAEA,IAAA,OAAO,SAAS;AACpB;;;;"}
@@ -0,0 +1,6 @@
1
+ import './reflection';
2
+ import { Constructor } from './Constructor';
3
+ import { Field } from './Field';
4
+ export declare function addFieldToDecoratorMetadata(metadata: Record<PropertyKey, unknown>, field: Field): void;
5
+ export declare function getOwnDecoratorFieldsForType(target: Constructor): Field[];
6
+ //# sourceMappingURL=fieldDecoratorMetadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldDecoratorMetadata.d.ts","sourceRoot":"","sources":["../../fieldDecoratorMetadata.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAShC,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAItG;AAOD,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE,CAQzE"}
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ require('./reflection.js');
4
+
5
+ const fieldsMetadataKey = Symbol.for('@cratis/fundamentals.fields');
6
+ function addFieldToDecoratorMetadata(metadata, field) {
7
+ const fields = Reflect.getOwnMetadata(fieldsMetadataKey, metadata) ?? new Map();
8
+ fields.set(field.name, field);
9
+ Reflect.defineMetadata(fieldsMetadataKey, fields, metadata);
10
+ }
11
+ function getOwnDecoratorFieldsForType(target) {
12
+ if (!Object.prototype.hasOwnProperty.call(target, Symbol.metadata))
13
+ return [];
14
+ const metadata = target[Symbol.metadata];
15
+ if (!metadata)
16
+ return [];
17
+ const fields = Reflect.getOwnMetadata(fieldsMetadataKey, metadata);
18
+ return fields ? [...fields.values()] : [];
19
+ }
20
+
21
+ exports.addFieldToDecoratorMetadata = addFieldToDecoratorMetadata;
22
+ exports.getOwnDecoratorFieldsForType = getOwnDecoratorFieldsForType;
23
+ //# sourceMappingURL=fieldDecoratorMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldDecoratorMetadata.js","sources":["../../fieldDecoratorMetadata.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport './reflection';\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\n\nconst fieldsMetadataKey = Symbol.for('@cratis/fundamentals.fields');\n\n/**\n * Adds a field to the metadata object supplied to a standard decorator.\n * @param metadata The class metadata object supplied by the decorator runtime.\n * @param field The field to add.\n */\nexport function addFieldToDecoratorMetadata(metadata: Record<PropertyKey, unknown>, field: Field): void {\n const fields = Reflect.getOwnMetadata(fieldsMetadataKey, metadata) as Map<string, Field> | undefined ?? new Map<string, Field>();\n fields.set(field.name, field);\n Reflect.defineMetadata(fieldsMetadataKey, fields, metadata);\n}\n\n/**\n * Gets the fields stored in the standard decorator metadata owned by a type.\n * @param target The type to read metadata from.\n * @returns The fields declared by the type through standard decorators.\n */\nexport function getOwnDecoratorFieldsForType(target: Constructor): Field[] {\n if (!Object.prototype.hasOwnProperty.call(target, Symbol.metadata)) return [];\n\n const metadata = (target as Constructor & { [Symbol.metadata]?: Record<PropertyKey, unknown> | null })[Symbol.metadata];\n if (!metadata) return [];\n\n const fields = Reflect.getOwnMetadata(fieldsMetadataKey, metadata) as Map<string, Field> | undefined;\n return fields ? [...fields.values()] : [];\n}\n"],"names":[],"mappings":";;;;AAOA,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC;AAO7D,SAAU,2BAA2B,CAAC,QAAsC,EAAE,KAAY,EAAA;AAC5F,IAAA,MAAM,MAAM,GAAG,OAAO,CAA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metadata === undefined || symbolConstructor.metadata === null) {
5
+ Object.defineProperty(Symbol, 'metadata', {
6
+ configurable: true,
7
+ enumerable: false,
8
+ value: Symbol.for('Symbol.metadata'),
9
+ writable: false
10
+ });
11
+ }
3
12
  if (typeof Reflect.defineMetadata !== 'function' || typeof Reflect.getOwnMetadata !== 'function') {
4
13
  const metadataMap = new WeakMap();
5
14
  const propertyMetadataMap = new WeakMap();
@@ -1 +1 @@
1
- {"version":3,"file":"reflection.js","sources":["../../reflection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Reflect metadata polyfill\n * Provides a minimal implementation of the reflect-metadata API using WeakMap.\n * If native Reflect metadata API is already available, this is a no-op.\n *\n * Limitations:\n * - Only supports object targets (not primitives)\n * - Property-level metadata uses a secondary Map structure keyed by property\n * - Does not support all advanced reflect-metadata features\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-namespace */\n\ndeclare global {\n namespace Reflect {\n function defineMetadata(metadataKey: string | symbol, metadataValue: any, target: any, propertyKey?: string | symbol): void;\n function getMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): any;\n function getOwnMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): any;\n function hasMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean;\n function hasOwnMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean;\n function getMetadataKeys(target: any, propertyKey?: string | symbol): (string | symbol)[];\n function getOwnMetadataKeys(target: any, propertyKey?: string | symbol): (string | symbol)[];\n function deleteMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean;\n function metadata(metadataKey: string | symbol, metadataValue: any): (target: any, propertyKey?: string | symbol) => void;\n }\n}\n\n// Check if native metadata API is available by testing for multiple methods\nif (typeof Reflect.defineMetadata !== 'function' || typeof Reflect.getOwnMetadata !== 'function') {\n const metadataMap = new WeakMap<any, Map<string | symbol, any>>();\n const propertyMetadataMap = new WeakMap<any, Map<string | symbol, Map<string | symbol, any>>>();\n\n function getMetadataStore(target: any, propertyKey?: string | symbol): Map<string | symbol, any> {\n if (propertyKey != null) {\n let propMap = propertyMetadataMap.get(target);\n if (!propMap) {\n propMap = new Map();\n propertyMetadataMap.set(target, propMap);\n }\n if (!propMap.has(propertyKey)) {\n propMap.set(propertyKey, new Map());\n }\n return propMap.get(propertyKey)!;\n } else {\n if (!metadataMap.has(target)) {\n metadataMap.set(target, new Map());\n }\n return metadataMap.get(target)!;\n }\n }\n\n function getMetadataStoreIfExists(target: any, propertyKey?: string | symbol): Map<string | symbol, any> | undefined {\n if (propertyKey != null) {\n const propMap = propertyMetadataMap.get(target);\n return propMap?.get(propertyKey);\n } else {\n return metadataMap.get(target);\n }\n }\n\n Reflect.defineMetadata = function (metadataKey: string | symbol, metadataValue: any, target: any, propertyKey?: string | symbol): void {\n const store = getMetadataStore(target, propertyKey);\n store.set(metadataKey, metadataValue);\n };\n\n Reflect.getMetadata = function (metadataKey: string | symbol, target: any, propertyKey?: string | symbol): any {\n let currentTarget = target;\n while (currentTarget !== null && currentTarget !== undefined) {\n const store = getMetadataStoreIfExists(currentTarget, propertyKey);\n if (store && store.has(metadataKey)) {\n return store.get(metadataKey);\n }\n currentTarget = Object.getPrototypeOf(currentTarget);\n }\n return undefined;\n };\n\n Reflect.getOwnMetadata = function (metadataKey: string | symbol, target: any, propertyKey?: string | symbol): any {\n const store = getMetadataStoreIfExists(target, propertyKey);\n return store?.get(metadataKey);\n };\n\n Reflect.hasMetadata = function (metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean {\n let currentTarget = target;\n while (currentTarget !== null && currentTarget !== undefined) {\n const store = getMetadataStoreIfExists(currentTarget, propertyKey);\n if (store && store.has(metadataKey)) {\n return true;\n }\n currentTarget = Object.getPrototypeOf(currentTarget);\n }\n return false;\n };\n\n Reflect.hasOwnMetadata = function (metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean {\n const store = getMetadataStoreIfExists(target, propertyKey);\n return store ? store.has(metadataKey) : false;\n };\n\n Reflect.getMetadataKeys = function (target: any, propertyKey?: string | symbol): (string | symbol)[] {\n const keys = new Set<string | symbol>();\n let currentTarget = target;\n while (currentTarget !== null && currentTarget !== undefined) {\n const store = getMetadataStoreIfExists(currentTarget, propertyKey);\n if (store) {\n for (const key of store.keys()) {\n keys.add(key);\n }\n }\n currentTarget = Object.getPrototypeOf(currentTarget);\n }\n return Array.from(keys);\n };\n\n Reflect.getOwnMetadataKeys = function (target: any, propertyKey?: string | symbol): (string | symbol)[] {\n const store = getMetadataStoreIfExists(target, propertyKey);\n return store ? Array.from(store.keys()) : [];\n };\n\n Reflect.deleteMetadata = function (metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean {\n const store = getMetadataStoreIfExists(target, propertyKey);\n return store ? store.delete(metadataKey) : false;\n };\n\n // Decorator factory used by TypeScript's emitDecoratorMetadata output (the tslib\n // __metadata helper). Without this, 'design:type'/'design:paramtypes'/'design:returntype'\n // metadata is never recorded, which breaks constructor parameter type reflection.\n Reflect.metadata = function (metadataKey: string | symbol, metadataValue: any): (target: any, propertyKey?: string | symbol) => void {\n return function (target: any, propertyKey?: string | symbol): void {\n Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey);\n };\n };\n}\n\nexport {};\n"],"names":[],"mappings":";;AAgCA,IAAI,OAAO,OAAO,CAAC,cAAc,KAAK,UAAU,IAAI,OAAO,OAAO,CAAC,cAAc,KAAK,UAAU,EAAE;AAC9F,IAAA,MAAM,WAAW,GAAG,IAAI,OAAO,EAAkC;AACjE,IAAA,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAwD;AAE/F,IAAA,SAAS,gBAAgB,CAAC,MAAW,EAAE,WAA6B,EAAA;AAChE,QAAA,IAAI,WAAW,IAAI,IAAI,EAAE;YACrB,IAAI,OAAO,GAAG,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC;Y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.js","sources":["../../reflection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Reflect metadata polyfill\n * Provides a minimal implementation of the reflect-metadata API using WeakMap.\n * If native Reflect metadata API is already available, this is a no-op.\n *\n * Limitations:\n * - Only supports object targets (not primitives)\n * - Property-level metadata uses a secondary Map structure keyed by property\n * - Does not support all advanced reflect-metadata features\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-namespace */\n\ndeclare global {\n namespace Reflect {\n function defineMetadata(metadataKey: string | symbol, metadataValue: any, target: any, propertyKey?: string | symbol): void;\n function getMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): any;\n function getOwnMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): any;\n function hasMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean;\n function hasOwnMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean;\n function getMetadataKeys(target: any, propertyKey?: string | symbol): (string | symbol)[];\n function getOwnMetadataKeys(target: any, propertyKey?: string | symbol): (string | symbol)[];\n function deleteMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean;\n function metadata(metadataKey: string | symbol, metadataValue: any): (target: any, propertyKey?: string | symbol) => void;\n }\n}\n\n// Standard decorators expose their class metadata through Symbol.metadata. Define it before any\n// decorated class is evaluated on runtimes that do not provide it yet. Symbol.for keeps the value\n// stable if more than one copy of this package is loaded in the same realm.\nconst symbolConstructor = Symbol as unknown as { metadata?: unknown };\nif (symbolConstructor.metadata === undefined || symbolConstructor.metadata === null) {\n Object.defineProperty(Symbol, 'metadata', {\n configurable: true,\n enumerable: false,\n value: Symbol.for('Symbol.metadata'),\n writable: false\n });\n}\n\n// Check if native metadata API is available by testing for multiple methods\nif (typeof Reflect.defineMetadata !== 'function' || typeof Reflect.getOwnMetadata !== 'function') {\n const metadataMap = new WeakMap<any, Map<string | symbol, any>>();\n const propertyMetadataMap = new WeakMap<any, Map<string | symbol, Map<string | symbol, any>>>();\n\n function getMetadataStore(target: any, propertyKey?: string | symbol): Map<string | symbol, any> {\n if (propertyKey != null) {\n let propMap = propertyMetadataMap.get(target);\n if (!propMap) {\n propMap = new Map();\n propertyMetadataMap.set(target, propMap);\n }\n if (!propMap.has(propertyKey)) {\n propMap.set(propertyKey, new Map());\n }\n return propMap.get(propertyKey)!;\n } else {\n if (!metadataMap.has(target)) {\n metadataMap.set(target, new Map());\n }\n return metadataMap.get(target)!;\n }\n }\n\n function getMetadataStoreIfExists(target: any, propertyKey?: string | symbol): Map<string | symbol, any> | undefined {\n if (propertyKey != null) {\n const propMap = propertyMetadataMap.get(target);\n return propMap?.get(propertyKey);\n } else {\n return metadataMap.get(target);\n }\n }\n\n Reflect.defineMetadata = function (metadataKey: string | symbol, metadataValue: any, target: any, propertyKey?: string | symbol): void {\n const store = getMetadataStore(target, propertyKey);\n store.set(metadataKey, metadataValue);\n };\n\n Reflect.getMetadata = function (metadataKey: string | symbol, target: any, propertyKey?: string | symbol): any {\n let currentTarget = target;\n while (currentTarget !== null && currentTarget !== undefined) {\n const store = getMetadataStoreIfExists(currentTarget, propertyKey);\n if (store && store.has(metadataKey)) {\n return store.get(metadataKey);\n }\n currentTarget = Object.getPrototypeOf(currentTarget);\n }\n return undefined;\n };\n\n Reflect.getOwnMetadata = function (metadataKey: string | symbol, target: any, propertyKey?: string | symbol): any {\n const store = getMetadataStoreIfExists(target, propertyKey);\n return store?.get(metadataKey);\n };\n\n Reflect.hasMetadata = function (metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean {\n let currentTarget = target;\n while (currentTarget !== null && currentTarget !== undefined) {\n const store = getMetadataStoreIfExists(currentTarget, propertyKey);\n if (store && store.has(metadataKey)) {\n return true;\n }\n currentTarget = Object.getPrototypeOf(currentTarget);\n }\n return false;\n };\n\n Reflect.hasOwnMetadata = function (metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean {\n const store = getMetadataStoreIfExists(target, propertyKey);\n return store ? store.has(metadataKey) : false;\n };\n\n Reflect.getMetadataKeys = function (target: any, propertyKey?: string | symbol): (string | symbol)[] {\n const keys = new Set<string | symbol>();\n let currentTarget = target;\n while (currentTarget !== null && currentTarget !== undefined) {\n const store = getMetadataStoreIfExists(currentTarget, propertyKey);\n if (store) {\n for (const key of store.keys()) {\n keys.add(key);\n }\n }\n currentTarget = Object.getPrototypeOf(currentTarget);\n }\n return Array.from(keys);\n };\n\n Reflect.getOwnMetadataKeys = function (target: any, propertyKey?: string | symbol): (string | symbol)[] {\n const store = getMetadataStoreIfExists(target, propertyKey);\n return store ? Array.from(store.keys()) : [];\n };\n\n Reflect.deleteMetadata = function (metadataKey: string | symbol, target: any, propertyKey?: string | symbol): boolean {\n const store = getMetadataStoreIfExists(target, propertyKey);\n return store ? store.delete(metadataKey) : false;\n };\n\n // Decorator factory used by TypeScript's emitDecoratorMetadata output (the tslib\n // __metadata helper). Without this, 'design:type'/'design:paramtypes'/'design:returntype'\n // metadata is never recorded, which breaks constructor parameter type reflection.\n Reflect.metadata = function (metadataKey: string | symbol, metadataValue: any): (target: any, propertyKey?: string | symbol) => void {\n return function (target: any, propertyKey?: string | symbol): void {\n Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey);\n };\n };\n}\n\nexport {};\n"],"names":[],"mappings":";;AAkCA,MAAM,iBAAiB,GAAG,MAA2C;AACrE,IAAI,iBAAiB,CAAC,QAAQ,KAAK,SAAS,IAAI,iBAAiB,CAAC,QAAQ,KAAK,IAAI,EAAE;AACjF,IAAA,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE;AACtC,QAAA,YAAY,EAAE,IAAI;AAClB,QAAA,UAAU,EAAE,KAAK;AACjB,QAAA,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC;AACpC,QAAA,QAAQ,EAAE;AACb,KAAA,CAAC;AACN;AAGA,IAAI,OAAO,O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A,OAAO,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,KAAK;AACpD,IAAA,CAAC;AAKD,IAAA,OAAO,CAAC,QAAQ,GAAG,UAAU,WAA4B,EAAE,aAAkB,EAAA;QACzE,OAAO,UAAU,MAAW,EAAE,WAA6B,EAAA;YACvD,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC;AAC3E,QAAA,CAAC;AACL,IAAA,CAAC;AACL;;"}
@@ -1,4 +1,8 @@
1
1
  import './reflection';
2
2
  import { Constructor } from './Constructor';
3
- export declare function derivedType(identifier: string, targetType?: Constructor): (target: any) => void;
3
+ import { StandardClassDecoratorContext } from './StandardClassDecoratorContext';
4
+ export declare function derivedType(identifier: string, targetType?: Constructor): {
5
+ <Target extends Constructor>(target: Target): void;
6
+ <Target extends Constructor>(target: Target, context: StandardClassDecoratorContext<Target>): void;
7
+ };
4
8
  //# sourceMappingURL=derivedTypeDecorator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"derivedTypeDecorator.d.ts","sourceRoot":"","sources":["../derivedTypeDecorator.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM5C,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,WAAW,IACnD,QAAQ,GAAG,UAY/B"}
1
+ {"version":3,"file":"derivedTypeDecorator.d.ts","sourceRoot":"","sources":["../derivedTypeDecorator.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,WAAW;KACjD,MAAM,SAAS,WAAW,UAAU,MAAM,GAAG,IAAI;KACjD,MAAM,SAAS,WAAW,UAAU,MAAM,WAAW,6BAA6B,CAAC,MAAM,CAAC,GAAG,IAAI;EA8BvH"}
@@ -1,13 +1,29 @@
1
1
  import './reflection';
2
2
  import { DerivedType } from './DerivedType';
3
3
  export function derivedType(identifier, targetType) {
4
- return function (target) {
4
+ function decorator(target, context) {
5
+ if (typeof target !== 'function')
6
+ throw new TypeError('@derivedType can only decorate classes');
7
+ if (context && context.kind !== 'class')
8
+ throw new TypeError('@derivedType can only decorate classes');
9
+ if (context && typeof context.addInitializer !== 'function')
10
+ throw new TypeError('@derivedType requires a standard class decorator context');
11
+ if (context) {
12
+ context.addInitializer(function () {
13
+ register(this);
14
+ });
15
+ return;
16
+ }
17
+ register(target);
18
+ }
19
+ function register(target) {
5
20
  DerivedType.set(target, identifier, targetType);
6
21
  let proto = Object.getPrototypeOf(target.prototype);
7
22
  while (proto && proto.constructor && proto.constructor !== Object) {
8
23
  DerivedType.set(target, identifier, proto.constructor);
9
24
  proto = Object.getPrototypeOf(proto);
10
25
  }
11
- };
26
+ }
27
+ return decorator;
12
28
  }
13
29
  //# sourceMappingURL=derivedTypeDecorator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"derivedTypeDecorator.js","sourceRoot":"","sources":["../derivedTypeDecorator.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5C,MAAM,UAAU,WAAW,CAAC,UAAkB,EAAE,UAAwB;IACpE,OAAO,UAAU,MAAW;QACxB,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QAKhD,IAAI,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACpD,OAAO,KAAK,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,KAAK,MAAM,EAAE,CAAC;YAChE,WAAW,CAAC,GAAG,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AE,KAAK,CAAC,WAAW,CAAC,CAAC;YACvD,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Fields.d.ts","sourceRoot":"","sources":["../../Fields.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC,qBAAa,MAAM;IACf,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE;IASlK,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE;CA0BxD"}
1
+ {"version":3,"file":"Fields.d.ts","sourceRoot":"","sources":["../../Fields.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMhC,qBAAa,MAAM;IACf,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE;IASlK,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE;CA+BxD"}