@cratis/fundamentals 7.17.1 → 7.18.1
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/Fields.ts +9 -3
- package/StandardClassDecoratorContext.ts +14 -0
- package/StandardFieldDecoratorContext.ts +13 -0
- package/derivedTypeDecorator.ts +21 -4
- package/dist/ConceptAs.d.ts.map +1 -1
- package/dist/ConceptAs.js.map +1 -1
- package/dist/DateOnly.d.ts.map +1 -1
- package/dist/DateOnly.js.map +1 -1
- package/dist/DerivedType.d.ts.map +1 -1
- package/dist/Field.d.ts.map +1 -1
- package/dist/Field.js.map +1 -1
- package/dist/Fields.d.ts.map +1 -1
- package/dist/Fields.js +4 -0
- package/dist/Fields.js.map +1 -1
- package/dist/Guid.d.ts.map +1 -1
- package/dist/Guid.js.map +1 -1
- package/dist/JsonSerializer.d.ts.map +1 -1
- package/dist/JsonSerializer.js.map +1 -1
- package/dist/PropertyAccessorDescriptor.d.ts.map +1 -1
- package/dist/PropertyAccessorDescriptor.js.map +1 -1
- package/dist/PropertyPathResolverProxyHandler.d.ts.map +1 -1
- package/dist/PropertyPathResolverProxyHandler.js.map +1 -1
- package/dist/StandardClassDecoratorContext.d.ts +8 -0
- package/dist/StandardClassDecoratorContext.d.ts.map +1 -0
- package/dist/StandardClassDecoratorContext.js +2 -0
- package/dist/StandardClassDecoratorContext.js.map +1 -0
- package/dist/StandardFieldDecoratorContext.d.ts +8 -0
- package/dist/StandardFieldDecoratorContext.d.ts.map +1 -0
- package/dist/StandardFieldDecoratorContext.js +2 -0
- package/dist/StandardFieldDecoratorContext.js.map +1 -0
- package/dist/TimeOnly.d.ts.map +1 -1
- package/dist/TimeOnly.js.map +1 -1
- package/dist/TimeSpan.d.ts.map +1 -1
- package/dist/TimeSpan.js.map +1 -1
- package/dist/ValueMap.d.ts.map +1 -1
- package/dist/ValueMap.js.map +1 -1
- package/dist/cjs/Fields.d.ts.map +1 -1
- package/dist/cjs/Fields.js +4 -0
- package/dist/cjs/Fields.js.map +1 -1
- package/dist/cjs/StandardClassDecoratorContext.d.ts +8 -0
- package/dist/cjs/StandardClassDecoratorContext.d.ts.map +1 -0
- package/dist/cjs/StandardFieldDecoratorContext.d.ts +8 -0
- package/dist/cjs/StandardFieldDecoratorContext.d.ts.map +1 -0
- package/dist/cjs/derivedTypeDecorator.d.ts +5 -1
- package/dist/cjs/derivedTypeDecorator.d.ts.map +1 -1
- package/dist/cjs/derivedTypeDecorator.js +18 -2
- package/dist/cjs/derivedTypeDecorator.js.map +1 -1
- package/dist/cjs/fieldDecorator.d.ts +5 -1
- package/dist/cjs/fieldDecorator.d.ts.map +1 -1
- package/dist/cjs/fieldDecorator.js +33 -2
- package/dist/cjs/fieldDecorator.js.map +1 -1
- package/dist/cjs/fieldDecoratorMetadata.d.ts +6 -0
- package/dist/cjs/fieldDecoratorMetadata.d.ts.map +1 -0
- package/dist/cjs/fieldDecoratorMetadata.js +23 -0
- package/dist/cjs/fieldDecoratorMetadata.js.map +1 -0
- package/dist/cjs/reflection.d.ts.map +1 -1
- package/dist/cjs/reflection.js +9 -0
- package/dist/cjs/reflection.js.map +1 -1
- package/dist/derivedTypeDecorator.d.ts +5 -1
- package/dist/derivedTypeDecorator.d.ts.map +1 -1
- package/dist/derivedTypeDecorator.js +18 -2
- package/dist/derivedTypeDecorator.js.map +1 -1
- package/dist/esm/Fields.d.ts.map +1 -1
- package/dist/esm/Fields.js +4 -0
- package/dist/esm/Fields.js.map +1 -1
- package/dist/esm/StandardClassDecoratorContext.d.ts +8 -0
- package/dist/esm/StandardClassDecoratorContext.d.ts.map +1 -0
- package/dist/esm/StandardFieldDecoratorContext.d.ts +8 -0
- package/dist/esm/StandardFieldDecoratorContext.d.ts.map +1 -0
- package/dist/esm/derivedTypeDecorator.d.ts +5 -1
- package/dist/esm/derivedTypeDecorator.d.ts.map +1 -1
- package/dist/esm/derivedTypeDecorator.js +18 -2
- package/dist/esm/derivedTypeDecorator.js.map +1 -1
- package/dist/esm/fieldDecorator.d.ts +5 -1
- package/dist/esm/fieldDecorator.d.ts.map +1 -1
- package/dist/esm/fieldDecorator.js +33 -2
- package/dist/esm/fieldDecorator.js.map +1 -1
- package/dist/esm/fieldDecoratorMetadata.d.ts +6 -0
- package/dist/esm/fieldDecoratorMetadata.d.ts.map +1 -0
- package/dist/esm/fieldDecoratorMetadata.js +20 -0
- package/dist/esm/fieldDecoratorMetadata.js.map +1 -0
- package/dist/esm/reflection.d.ts.map +1 -1
- package/dist/esm/reflection.js +9 -0
- package/dist/esm/reflection.js.map +1 -1
- package/dist/fieldDecorator.d.ts +5 -1
- package/dist/fieldDecorator.d.ts.map +1 -1
- package/dist/fieldDecorator.js +33 -2
- package/dist/fieldDecorator.js.map +1 -1
- package/dist/fieldDecoratorMetadata.d.ts +6 -0
- package/dist/fieldDecoratorMetadata.d.ts.map +1 -0
- package/dist/fieldDecoratorMetadata.js +17 -0
- package/dist/fieldDecoratorMetadata.js.map +1 -0
- package/dist/geospatial/LineString.d.ts.map +1 -1
- package/dist/geospatial/LineString.js.map +1 -1
- package/dist/geospatial/LinearRing.d.ts.map +1 -1
- package/dist/geospatial/Point.d.ts.map +1 -1
- package/dist/geospatial/Point.js.map +1 -1
- package/dist/geospatial/Polygon.d.ts.map +1 -1
- package/dist/geospatial/Polygon.js.map +1 -1
- package/dist/json/DateJsonConverter.d.ts.map +1 -1
- package/dist/json/DateOnlyJsonConverter.d.ts.map +1 -1
- package/dist/json/GuidJsonConverter.d.ts.map +1 -1
- package/dist/json/JsonConverter.d.ts.map +1 -1
- package/dist/json/LineStringJsonConverter.d.ts.map +1 -1
- package/dist/json/PointJsonConverter.d.ts.map +1 -1
- package/dist/json/PolygonJsonConverter.d.ts.map +1 -1
- package/dist/json/TimeOnlyJsonConverter.d.ts.map +1 -1
- package/dist/json/TimeSpanJsonConverter.d.ts.map +1 -1
- package/dist/json/ValueMapJsonConverter.d.ts.map +1 -1
- package/dist/json/ValueMapJsonConverter.js.map +1 -1
- package/dist/reflection.d.ts.map +1 -1
- package/dist/reflection.js +9 -0
- package/dist/reflection.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/typeKey.d.ts.map +1 -1
- package/dist/vite.config.d.mts.map +1 -1
- package/fieldDecorator.ts +36 -5
- package/fieldDecoratorMetadata.ts +34 -0
- package/for_JsonSerializer/when_metadata_is_written_by_another_copy_of_the_package.ts +23 -5
- package/for_derivedTypeDecorator/when_an_outer_standard_decorator_replaces_the_class.ts +28 -0
- package/for_fieldDecorator/fixtures/standard_decorated_types.ts +76 -0
- package/for_fieldDecorator/when_executing_standard_typescript_decorator_emit.ts +115 -0
- package/for_fieldDecorator/when_invoked_as_a_legacy_decorator.ts +21 -0
- package/for_fieldDecorator/when_invoked_as_a_standard_decorator.ts +43 -0
- package/for_fieldDecorator/when_invoked_for_an_unsupported_legacy_field/with_a_static_field.ts +12 -0
- package/for_fieldDecorator/when_invoked_for_an_unsupported_legacy_field/with_a_symbol_name.ts +12 -0
- package/for_fieldDecorator/when_invoked_for_an_unsupported_standard_field/with_a_private_field.ts +16 -0
- package/for_fieldDecorator/when_invoked_for_an_unsupported_standard_field/with_a_static_field.ts +16 -0
- package/for_fieldDecorator/when_invoked_for_an_unsupported_standard_field/with_a_symbol_name.ts +16 -0
- package/for_fieldDecorator/when_invoked_for_an_unsupported_standard_field/without_decorator_metadata.ts +16 -0
- package/for_fieldDecorator/when_legacy_and_standard_metadata_are_mixed_across_inheritance.ts +43 -0
- package/for_fieldDecorator/when_standard_metadata_contains_unrelated_fields_metadata.ts +34 -0
- package/for_fieldDecorator/when_standard_metadata_is_inherited_and_overridden.ts +37 -0
- package/for_reflection/when_loading_with_existing_symbol_metadata.ts +25 -0
- package/package.json +8 -1
- package/reflection.ts +13 -0
|
@@ -0,0 +1,37 @@
|
|
|
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 { Fields } from '../Fields';
|
|
5
|
+
import { field } from '../fieldDecorator';
|
|
6
|
+
import { StandardFieldDecoratorContext } from '../StandardFieldDecoratorContext';
|
|
7
|
+
|
|
8
|
+
class BaseType { }
|
|
9
|
+
class DerivedType extends BaseType { }
|
|
10
|
+
|
|
11
|
+
describe('when standard metadata is inherited and overridden', () => {
|
|
12
|
+
const baseMetadata: Record<PropertyKey, unknown> = Object.create(null) as Record<PropertyKey, unknown>;
|
|
13
|
+
const derivedMetadata: Record<PropertyKey, unknown> = Object.create(baseMetadata) as Record<PropertyKey, unknown>;
|
|
14
|
+
const contextFor = (name: string, metadata: Record<PropertyKey, unknown>): StandardFieldDecoratorContext => ({
|
|
15
|
+
kind: 'field',
|
|
16
|
+
metadata,
|
|
17
|
+
name,
|
|
18
|
+
private: false,
|
|
19
|
+
static: false
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
field(String)(undefined, contextFor('baseValue', baseMetadata));
|
|
23
|
+
field(String)(undefined, contextFor('value', baseMetadata));
|
|
24
|
+
field(Number)(undefined, contextFor('value', derivedMetadata));
|
|
25
|
+
field(Boolean)(undefined, contextFor('derivedValue', derivedMetadata));
|
|
26
|
+
Object.defineProperty(BaseType, Symbol.metadata, { value: baseMetadata });
|
|
27
|
+
Object.defineProperty(DerivedType, Symbol.metadata, { value: derivedMetadata });
|
|
28
|
+
|
|
29
|
+
const baseFields = Fields.getFieldsForType(BaseType);
|
|
30
|
+
const derivedFields = Fields.getFieldsForType(DerivedType);
|
|
31
|
+
|
|
32
|
+
it('should preserve fields declared by the base type', () => derivedFields.find(_ => _.name === 'baseValue')!.type.should.equal(String));
|
|
33
|
+
it('should preserve fields declared by the derived type', () => derivedFields.find(_ => _.name === 'derivedValue')!.type.should.equal(Boolean));
|
|
34
|
+
it('should keep a single overridden field', () => derivedFields.filter(_ => _.name === 'value').should.have.lengthOf(1));
|
|
35
|
+
it('should use the derived field definition', () => derivedFields.find(_ => _.name === 'value')!.type.should.equal(Number));
|
|
36
|
+
it('should not mutate the base field definition', () => baseFields.find(_ => _.name === 'value')!.type.should.equal(String));
|
|
37
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
describe('when loading with existing Symbol metadata', () => {
|
|
5
|
+
const originalMetadataDescriptor = Object.getOwnPropertyDescriptor(Symbol, 'metadata');
|
|
6
|
+
const existingMetadata = Symbol('existing metadata');
|
|
7
|
+
let actualMetadata: symbol;
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
Object.defineProperty(Symbol, 'metadata', {
|
|
11
|
+
configurable: true,
|
|
12
|
+
value: existingMetadata
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
await import(/* @vite-ignore */ '../reflection?existingSymbolMetadata');
|
|
16
|
+
actualMetadata = Symbol.metadata;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterAll(() => {
|
|
20
|
+
Reflect.deleteProperty(Symbol, 'metadata');
|
|
21
|
+
if (originalMetadataDescriptor) Object.defineProperty(Symbol, 'metadata', originalMetadataDescriptor);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should preserve the existing identity', () => actualMetadata.should.equal(existingMetadata));
|
|
25
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cratis/fundamentals",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.18.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Cratis",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,6 +41,13 @@
|
|
|
41
41
|
"require": "./dist/cjs/reflection.js"
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
+
"installConfig": {
|
|
45
|
+
"hoistingLimits": "workspaces"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"rollup-plugin-typescript2": "0.37.0",
|
|
49
|
+
"typescript-programmatic-api": "npm:typescript@6.0.3"
|
|
50
|
+
},
|
|
44
51
|
"scripts": {
|
|
45
52
|
"prepare": "yarn g:build",
|
|
46
53
|
"clean": "yarn g:clean",
|
package/reflection.ts
CHANGED
|
@@ -29,6 +29,19 @@ declare global {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
// Standard decorators expose their class metadata through Symbol.metadata. Define it before any
|
|
33
|
+
// decorated class is evaluated on runtimes that do not provide it yet. Symbol.for keeps the value
|
|
34
|
+
// stable if more than one copy of this package is loaded in the same realm.
|
|
35
|
+
const symbolConstructor = Symbol as unknown as { metadata?: unknown };
|
|
36
|
+
if (symbolConstructor.metadata === undefined || symbolConstructor.metadata === null) {
|
|
37
|
+
Object.defineProperty(Symbol, 'metadata', {
|
|
38
|
+
configurable: true,
|
|
39
|
+
enumerable: false,
|
|
40
|
+
value: Symbol.for('Symbol.metadata'),
|
|
41
|
+
writable: false
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
// Check if native metadata API is available by testing for multiple methods
|
|
33
46
|
if (typeof Reflect.defineMetadata !== 'function' || typeof Reflect.getOwnMetadata !== 'function') {
|
|
34
47
|
const metadataMap = new WeakMap<any, Map<string | symbol, any>>();
|