adaptive-extender 0.8.6 → 0.9.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.
- package/CHANGELOG.md +6 -1
- package/dist/core/array.d.ts +8 -4
- package/dist/core/array.js +4 -0
- package/dist/core/array.js.map +1 -1
- package/dist/core/boolean.d.ts +8 -4
- package/dist/core/boolean.js +3 -0
- package/dist/core/boolean.js.map +1 -1
- package/dist/core/controller.d.ts +1 -2
- package/dist/core/controller.js +0 -1
- package/dist/core/controller.js.map +1 -1
- package/dist/core/date.d.ts +0 -8
- package/dist/core/date.js +0 -5
- package/dist/core/date.js.map +1 -1
- package/dist/core/decorators.d.ts +17 -0
- package/dist/core/decorators.js +174 -0
- package/dist/core/decorators.js.map +1 -0
- package/dist/core/global.d.ts +0 -8
- package/dist/core/global.js.map +1 -1
- package/dist/core/number.d.ts +8 -4
- package/dist/core/number.js +3 -0
- package/dist/core/number.js.map +1 -1
- package/dist/core/object.d.ts +9 -5
- package/dist/core/object.js +3 -0
- package/dist/core/object.js.map +1 -1
- package/dist/core/portable.d.ts +68 -8
- package/dist/core/portable.js +201 -1
- package/dist/core/portable.js.map +1 -1
- package/dist/core/reflect.d.ts +23 -6
- package/dist/core/reflect.js.map +1 -1
- package/dist/core/string.d.ts +8 -4
- package/dist/core/string.js +3 -0
- package/dist/core/string.js.map +1 -1
- package/dist/core/vector.d.ts +1 -2
- package/dist/core/vector.js +0 -1
- package/dist/core/vector.js.map +1 -1
- package/dist/web/archive.d.ts +33 -28
- package/dist/web/archive.js +65 -50
- package/dist/web/archive.js.map +1 -1
- package/dist/web/engine.d.ts +1 -2
- package/dist/web/engine.js +0 -1
- package/dist/web/engine.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
## 0.
|
|
1
|
+
## 0.9.0 (18.01.2026)
|
|
2
|
+
- Added automatic model porting using decorators in [portable](./src/core/portable.ts).
|
|
3
|
+
- Built-in types now implement the `PortableConstructor` interface.
|
|
4
|
+
- Improved `ArchiveManager` and `ArchiveRepository` classes for working with archives.
|
|
5
|
+
|
|
6
|
+
## 0.8.7 (09.12.2025)
|
|
2
7
|
- Added `Array.fromAsync` function.
|
|
3
8
|
|
|
4
9
|
## 0.8.5 (04.12.2025)
|
package/dist/core/array.d.ts
CHANGED
|
@@ -2,13 +2,17 @@ import "./global.js";
|
|
|
2
2
|
declare global {
|
|
3
3
|
export interface ArrayConstructor {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param source The
|
|
7
|
-
* @param name The name
|
|
8
|
-
* @returns The imported array.
|
|
5
|
+
* Validates that the source is an array and returns it.
|
|
6
|
+
* @param source The raw data to check.
|
|
7
|
+
* @param name The field name for error context.
|
|
9
8
|
* @throws {TypeError} If the source is not an array.
|
|
10
9
|
*/
|
|
11
10
|
import(source: any, name: string): any[];
|
|
11
|
+
/**
|
|
12
|
+
* Returns the array as-is for export purposes.
|
|
13
|
+
* @param source The array to export.
|
|
14
|
+
*/
|
|
15
|
+
export(source: any[]): any[];
|
|
12
16
|
/**
|
|
13
17
|
* Creates an array of integers between the specified minimum and maximum values (exclusive).
|
|
14
18
|
* @param min The minimum value of the range (inclusive).
|
package/dist/core/array.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import "./global.js";
|
|
3
|
+
import {} from "./promise.js";
|
|
3
4
|
const { trunc } = Math;
|
|
4
5
|
Array.import = function (source, name) {
|
|
5
6
|
if (!Array.isArray(source))
|
|
6
7
|
throw new TypeError(`Unable to import array from ${name} due its ${typename(source)} type`);
|
|
7
8
|
return source;
|
|
8
9
|
};
|
|
10
|
+
Array.export = function (source) {
|
|
11
|
+
return source;
|
|
12
|
+
};
|
|
9
13
|
Array.range = function (min, max) {
|
|
10
14
|
min = trunc(min);
|
|
11
15
|
max = trunc(max);
|
package/dist/core/array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/core/array.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/core/array.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;AACrB,OAAO,EAAmB,MAAM,cAAc,CAAC;AAE/C,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;AA2DvB,KAAK,CAAC,MAAM,GAAG,UAAU,MAAW,EAAE,IAAY;IACjD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,+BAA+B,IAAI,YAAY,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxH,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,KAAK,CAAC,MAAM,GAAG,UAAU,MAAa;IACrC,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,KAAK,CAAC,KAAK,GAAG,UAAU,GAAW,EAAE,GAAW;IAC/C,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACjB,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACjB,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,GAAG,GAAG,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC;QAChD,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAEF,KAAK,CAAC,GAAG,GAAG,QAAQ,CAAC,EAAsB,GAAG,SAA6C;IAC1F,MAAM,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EAA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CAAC;IACvB,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AAC1B,CAAC,CAAC;AAEF,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,UAAwB,MAAc,EAAE,QAAW;IAC3E,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM;QAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACrB,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AACF,YAAY;AAEZ,KAAK,CAAC,IAAI,CAAC"}
|
package/dist/core/boolean.d.ts
CHANGED
|
@@ -2,12 +2,16 @@ import "./global.js";
|
|
|
2
2
|
declare global {
|
|
3
3
|
export interface BooleanConstructor {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param source The
|
|
7
|
-
* @param name The name
|
|
8
|
-
* @returns The imported boolean value.
|
|
5
|
+
* Validates and imports a boolean value from a raw source.
|
|
6
|
+
* @param source The raw value to check.
|
|
7
|
+
* @param name The field name for error context.
|
|
9
8
|
* @throws {TypeError} If the source is not a boolean.
|
|
10
9
|
*/
|
|
11
10
|
import(source: any, name: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the primitive boolean value for export.
|
|
13
|
+
* @param source The boolean to export.
|
|
14
|
+
*/
|
|
15
|
+
export(source: boolean): boolean;
|
|
12
16
|
}
|
|
13
17
|
}
|
package/dist/core/boolean.js
CHANGED
|
@@ -5,4 +5,7 @@ Boolean.import = function (source, name) {
|
|
|
5
5
|
throw new TypeError(`Unable to import boolean from ${name} due its ${typename(source)} type`);
|
|
6
6
|
return source.valueOf();
|
|
7
7
|
};
|
|
8
|
+
Boolean.export = function (source) {
|
|
9
|
+
return source.valueOf();
|
|
10
|
+
};
|
|
8
11
|
//# sourceMappingURL=boolean.js.map
|
package/dist/core/boolean.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/core/boolean.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/core/boolean.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;AAoBrB,OAAO,CAAC,MAAM,GAAG,UAAU,MAAW,EAAE,IAAY;IACnD,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,SAAS,CAAC,iCAAiC,IAAI,YAAY,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjI,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,OAAO,CAAC,MAAM,GAAG,UAAU,MAAe;IACzC,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;AACzB,CAAC,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import "./error.js";
|
|
2
2
|
/**
|
|
3
3
|
* Represents a controller that can be launched and handle errors.
|
|
4
|
-
* @abstract
|
|
5
4
|
*/
|
|
6
|
-
export declare class Controller {
|
|
5
|
+
export declare abstract class Controller {
|
|
7
6
|
/**
|
|
8
7
|
* @throws {TypeError} If the constructor is called on ectly.
|
|
9
8
|
*/
|
package/dist/core/controller.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/core/controller.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,YAAY,CAAC;AAEpB,oBAAoB;AACpB
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/core/controller.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,YAAY,CAAC;AAEpB,oBAAoB;AACpB;;GAEG;AACH,MAAM,OAAgB,UAAU;IAC/B;;OAEG;IACH;QACC,IAAI,GAAG,CAAC,MAAM,KAAK,UAAU;YAAE,MAAM,IAAI,SAAS,CAAC,mDAAmD,CAAC,CAAC;IACzG,CAAC;IACD;;OAEG;IACH,KAAK,CAAC,GAAG;IACT,CAAC;IACD;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,KAAY;IACxB,CAAC;IACD;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM;QAClB,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC;YACJ,MAAM,UAAU,CAAC,GAAG,EAAE,CAAC;QACxB,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YACjB,MAAM,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5C,CAAC;IACF,CAAC;CACD"}
|
package/dist/core/date.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import "./global.js";
|
|
2
2
|
declare global {
|
|
3
3
|
export interface DateConstructor {
|
|
4
|
-
/**
|
|
5
|
-
* Imports a date from a source.
|
|
6
|
-
* @param source The source value to import.
|
|
7
|
-
* @param name The name of the source value.
|
|
8
|
-
* @returns The imported date value.
|
|
9
|
-
* @throws {TypeError} If the source is not a date.
|
|
10
|
-
*/
|
|
11
|
-
import(source: any, name: string): Date;
|
|
12
4
|
/**
|
|
13
5
|
* Checks whether a given date is invalid.
|
|
14
6
|
* @returns `true` if the value is a `Date` and is invalid; otherwise, `false`.
|
package/dist/core/date.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import "./global.js";
|
|
3
|
-
Date.import = function (source, name) {
|
|
4
|
-
if (!(source instanceof Date))
|
|
5
|
-
throw new TypeError(`Unable to import date from ${name} due its ${typename(source)} type`);
|
|
6
|
-
return source;
|
|
7
|
-
};
|
|
8
3
|
Date.isInvalid = function (date) {
|
|
9
4
|
if (!(date instanceof Date))
|
|
10
5
|
return false;
|
package/dist/core/date.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/core/date.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/core/date.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;AAsBrB,IAAI,CAAC,SAAS,GAAG,UAAU,IAAa;IACvC,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1C,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,IAAI,CAAC,SAAS,CAAC,cAAc,GAAG,UAAa,KAAQ;IACpD,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,IAAI,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Constructor, type PortableConstructor } from "./portable.js";
|
|
2
|
+
export interface PortableField<T> extends Constructor {
|
|
3
|
+
import(source: unknown, name: string): T;
|
|
4
|
+
export(source: T): unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface DeferredCallback<T> {
|
|
7
|
+
(): T;
|
|
8
|
+
}
|
|
9
|
+
export declare function Scheme<T>(type: PortableField<T>, name?: string): (target: void, context: ClassFieldDecoratorContext<PortableModel, unknown>) => void;
|
|
10
|
+
export declare function PolymorphicBase<T extends typeof PortableModel>(resolver: DeferredCallback<PortableConstructor[]>): (target: T, context: ClassDecoratorContext) => T;
|
|
11
|
+
export declare function ArrayOf<T>(type: PortableField<T>): PortableField<T[]>;
|
|
12
|
+
export declare function Nullable<T>(type: PortableField<T>): PortableField<T | null>;
|
|
13
|
+
export declare function Optional<T>(type: PortableField<T>): PortableField<T | undefined>;
|
|
14
|
+
export declare abstract class PortableModel {
|
|
15
|
+
static import<T extends typeof PortableModel>(this: T, source: unknown, name: string): InstanceType<T>;
|
|
16
|
+
static export<T extends typeof PortableModel>(this: T, source: InstanceType<T>): unknown;
|
|
17
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import {} from "./portable.js";
|
|
3
|
+
//#region Field descriptor
|
|
4
|
+
class FieldDescriptor {
|
|
5
|
+
#key;
|
|
6
|
+
#association;
|
|
7
|
+
#type;
|
|
8
|
+
constructor(key, association, type) {
|
|
9
|
+
this.#key = key;
|
|
10
|
+
this.#association = association;
|
|
11
|
+
this.#type = type;
|
|
12
|
+
}
|
|
13
|
+
get key() {
|
|
14
|
+
return this.#key;
|
|
15
|
+
}
|
|
16
|
+
get association() {
|
|
17
|
+
return this.#association;
|
|
18
|
+
}
|
|
19
|
+
get type() {
|
|
20
|
+
return this.#type;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class DeferredResolver {
|
|
24
|
+
#resolver;
|
|
25
|
+
constructor(resolver) {
|
|
26
|
+
this.#resolver = resolver;
|
|
27
|
+
}
|
|
28
|
+
get value() {
|
|
29
|
+
return this.#resolver.call(this);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region Portability metadata
|
|
34
|
+
class PortabilityMetadata {
|
|
35
|
+
static #registry = new Map();
|
|
36
|
+
#model;
|
|
37
|
+
#fields = [];
|
|
38
|
+
#callback = null;
|
|
39
|
+
constructor(model) {
|
|
40
|
+
this.#model = model;
|
|
41
|
+
}
|
|
42
|
+
static register(model) {
|
|
43
|
+
const registry = PortabilityMetadata.#registry;
|
|
44
|
+
if (registry.has(model.name))
|
|
45
|
+
return; /** @todo Throw error */
|
|
46
|
+
const metadata = new PortabilityMetadata(model);
|
|
47
|
+
registry.set(model.name, metadata);
|
|
48
|
+
}
|
|
49
|
+
static read(model) {
|
|
50
|
+
const registry = PortabilityMetadata.#registry;
|
|
51
|
+
const record = registry.get(model.name);
|
|
52
|
+
const metadata = ReferenceError.suppress(record, "asdasdadsa"); /** @todo Write error */
|
|
53
|
+
return metadata;
|
|
54
|
+
}
|
|
55
|
+
get model() {
|
|
56
|
+
return this.#model;
|
|
57
|
+
}
|
|
58
|
+
get fields() {
|
|
59
|
+
return this.#fields;
|
|
60
|
+
}
|
|
61
|
+
get callback() {
|
|
62
|
+
return this.#callback;
|
|
63
|
+
}
|
|
64
|
+
set callback(value) {
|
|
65
|
+
this.#callback = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export function Scheme(type, name) {
|
|
70
|
+
return function (target, context) {
|
|
71
|
+
const key = context.name;
|
|
72
|
+
if (typeof key === "symbol")
|
|
73
|
+
throw new TypeError(""); /** @todo Write error */
|
|
74
|
+
const association = name ?? key;
|
|
75
|
+
context.addInitializer(function () {
|
|
76
|
+
const Type = constructor(this); /** @todo Fix constructor */
|
|
77
|
+
const { fields } = PortabilityMetadata.read(Type);
|
|
78
|
+
fields.push(new FieldDescriptor(key, association, type));
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function PolymorphicBase(resolver) {
|
|
83
|
+
return function (target) {
|
|
84
|
+
const metadata = PortabilityMetadata.read(target);
|
|
85
|
+
metadata.callback = resolver;
|
|
86
|
+
return target;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function ArrayOf(type) {
|
|
90
|
+
return class {
|
|
91
|
+
static import(source, name) {
|
|
92
|
+
return Array.import(source, name).map((item, index) => type.import(item, `${name}[${index}]`));
|
|
93
|
+
}
|
|
94
|
+
static export(source) {
|
|
95
|
+
return source.map(item => type.export(item));
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export function Nullable(type) {
|
|
100
|
+
return class {
|
|
101
|
+
static import(source, name) {
|
|
102
|
+
return Reflect.mapNull(source, source => type.import(source, name));
|
|
103
|
+
}
|
|
104
|
+
static export(source) {
|
|
105
|
+
return Reflect.mapNull(source, source => type.export(source));
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function Optional(type) {
|
|
110
|
+
return class {
|
|
111
|
+
static import(source, name) {
|
|
112
|
+
return Reflect.mapUndefined(source, source => type.import(source, name));
|
|
113
|
+
}
|
|
114
|
+
static export(source) {
|
|
115
|
+
return Reflect.mapUndefined(source, source => type.export(source));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export class PortableModel {
|
|
120
|
+
static {
|
|
121
|
+
PortabilityMetadata.register(this);
|
|
122
|
+
}
|
|
123
|
+
static import(source, name) {
|
|
124
|
+
const { callback, fields } = PortabilityMetadata.read(this);
|
|
125
|
+
if (callback !== null) {
|
|
126
|
+
const descendants = callback();
|
|
127
|
+
if (descendants.length > 1) {
|
|
128
|
+
const object = Object.import(source, name);
|
|
129
|
+
const typename = String.import(Reflect.get(object, "$type"), `${name}.$type`);
|
|
130
|
+
const subtype = descendants.find(subtype => subtype.name === typename);
|
|
131
|
+
if (subtype === undefined)
|
|
132
|
+
throw new TypeError(`Unknown polymorphic type '${typename}' for '${this.name}'`);
|
|
133
|
+
return subtype.import(source, name);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const object = Object.import(source, name);
|
|
137
|
+
const instance = Reflect.construct(this, []);
|
|
138
|
+
let current = this;
|
|
139
|
+
while (current && current !== PortableModel) {
|
|
140
|
+
for (const { key, association, type } of fields) {
|
|
141
|
+
const rawValue = Reflect.get(object, association);
|
|
142
|
+
const importedValue = type.import(rawValue, `${name}.${association}`);
|
|
143
|
+
Reflect.set(instance, key, importedValue);
|
|
144
|
+
}
|
|
145
|
+
current = Object.getPrototypeOf(current);
|
|
146
|
+
}
|
|
147
|
+
return instance;
|
|
148
|
+
}
|
|
149
|
+
static export(source) {
|
|
150
|
+
const { callback, fields } = PortabilityMetadata.read(this);
|
|
151
|
+
if (callback !== null) {
|
|
152
|
+
const descendants = callback();
|
|
153
|
+
if (descendants.length > 1) {
|
|
154
|
+
const subtype = descendants.find(subtype => source instanceof subtype);
|
|
155
|
+
if (subtype === undefined)
|
|
156
|
+
throw new TypeError(`Unknown polymorphic type '${typename}' for '${this.name}'`);
|
|
157
|
+
return subtype.export(source);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const result = Object();
|
|
161
|
+
Reflect.set(result, "$type", this.name);
|
|
162
|
+
let current = this;
|
|
163
|
+
while (current && current !== PortableModel) {
|
|
164
|
+
for (const { key, association, type } of fields) {
|
|
165
|
+
const value = Reflect.get(source, key);
|
|
166
|
+
const exportedValue = type.export(value);
|
|
167
|
+
Reflect.set(result, association, exportedValue);
|
|
168
|
+
}
|
|
169
|
+
current = Object.getPrototypeOf(current);
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/core/decorators.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAA8C,MAAM,eAAe,CAAC;AAO3E,0BAA0B;AAC1B,MAAM,eAAe;IACpB,IAAI,CAAS;IACb,YAAY,CAAS;IACrB,KAAK,CAAqB;IAE1B,YAAY,GAAW,EAAE,WAAmB,EAAE,IAAwB;QACrE,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,GAAG;QACN,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,IAAI,WAAW;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E,CAAC;YAC7C,KAAK,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,MAAM,EAAE,CAAC;gBACjD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBACvC,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACzC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;YACjD,CAAC;YACD,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;CACD"}
|
package/dist/core/global.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
declare global {
|
|
2
|
-
/**
|
|
3
|
-
* Exclude null from T
|
|
4
|
-
*/
|
|
5
|
-
export type NonNull<T> = T & ({} | undefined);
|
|
6
|
-
/**
|
|
7
|
-
* Exclude undefined from T
|
|
8
|
-
*/
|
|
9
|
-
export type NonUndefined<T> = T & ({} | null);
|
|
10
2
|
/**
|
|
11
3
|
* Returns the constructor of the given non-nullable value.
|
|
12
4
|
*/
|
package/dist/core/global.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/core/global.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/core/global.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAeb,UAAU,CAAC,WAAW,GAAG,UAAa,KAAqB;IAC1D,OAAO,KAAK,CAAC,WAAW,CAAC;AAC1B,CAAC,CAAC;AAEF,UAAU,CAAC,QAAQ,GAAG,UAAU,KAAU;IACzC,QAAQ,KAAK,EAAE,CAAC;QAChB,KAAK,SAAS,CAAC,CAAC,OAAO,WAAW,CAAC;QACnC,KAAK,IAAI,CAAC,CAAC,OAAO,MAAM,CAAC;QACzB,OAAO,CAAC,CAAC,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;IACxC,CAAC;AACF,CAAC,CAAC"}
|
package/dist/core/number.d.ts
CHANGED
|
@@ -2,13 +2,17 @@ import "./global.js";
|
|
|
2
2
|
declare global {
|
|
3
3
|
export interface NumberConstructor {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param source The
|
|
7
|
-
* @param name The name
|
|
8
|
-
* @returns The imported number value.
|
|
5
|
+
* Validates and imports a number value from a raw source.
|
|
6
|
+
* @param source The raw value to check.
|
|
7
|
+
* @param name The field name for error context.
|
|
9
8
|
* @throws {TypeError} If the source is not a number.
|
|
10
9
|
*/
|
|
11
10
|
import(source: any, name: string): number;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the primitive number value for export.
|
|
13
|
+
* @param source The number to export.
|
|
14
|
+
*/
|
|
15
|
+
export(source: number): number;
|
|
12
16
|
}
|
|
13
17
|
export interface Number {
|
|
14
18
|
/**
|
package/dist/core/number.js
CHANGED
|
@@ -5,6 +5,9 @@ Number.import = function (source, name) {
|
|
|
5
5
|
throw new TypeError(`Unable to import number from ${name} due its ${typename(source)} type`);
|
|
6
6
|
return source.valueOf();
|
|
7
7
|
};
|
|
8
|
+
Number.export = function (source) {
|
|
9
|
+
return source.valueOf();
|
|
10
|
+
};
|
|
8
11
|
Number.prototype.insteadNaN = function (value) {
|
|
9
12
|
const current = this.valueOf();
|
|
10
13
|
if (Number.isNaN(current))
|
package/dist/core/number.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../src/core/number.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../src/core/number.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;AAyCrB,MAAM,CAAC,MAAM,GAAG,UAAU,MAAW,EAAE,IAAY;IAClD,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,QAAQ;QAAE,MAAM,IAAI,SAAS,CAAC,gCAAgC,IAAI,YAAY,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/H,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,UAAU,MAAc;IACvC,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,SAAS,CAAC,UAAU,GAAG,UAAa,KAAQ;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC/B,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IACxC,OAAO,OAAO,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,SAAS,CAAC,eAAe,GAAG,UAAa,KAAQ;IACvD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC/B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,OAAO,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,SAAS,CAAC,WAAW,GAAG,UAAa,KAAQ;IACnD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC/B,IAAI,OAAO,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAChC,OAAO,OAAO,CAAC;AAChB,CAAC,CAAC"}
|
package/dist/core/object.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
export interface ObjectConstructor {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param source The
|
|
6
|
-
* @param name The name
|
|
7
|
-
* @
|
|
8
|
-
* @throws {TypeError} If the source is not an object or null.
|
|
4
|
+
* Validates that the source is a non-null object.
|
|
5
|
+
* @param source The raw data to check.
|
|
6
|
+
* @param name The field name for error context.
|
|
7
|
+
* @throws {TypeError} If the source is not an object or is null.
|
|
9
8
|
*/
|
|
10
9
|
import(source: any, name: string): object;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the object as-is for export purposes.
|
|
12
|
+
* @param source The object to export.
|
|
13
|
+
*/
|
|
14
|
+
export(source: object): object;
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
export {};
|
package/dist/core/object.js
CHANGED
|
@@ -4,5 +4,8 @@ Object.import = function (source, name) {
|
|
|
4
4
|
throw new TypeError(`Unable to import object from ${name} due its ${typename(source)} type`);
|
|
5
5
|
return source;
|
|
6
6
|
};
|
|
7
|
+
Object.export = function (source) {
|
|
8
|
+
return source;
|
|
9
|
+
};
|
|
7
10
|
export {};
|
|
8
11
|
//# sourceMappingURL=object.js.map
|
package/dist/core/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/core/object.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/core/object.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAoBb,MAAM,CAAC,MAAM,GAAG,UAAU,MAAW,EAAE,IAAY;IAClD,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAAE,MAAM,IAAI,SAAS,CAAC,gCAAgC,IAAI,YAAY,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClJ,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,UAAU,MAAc;IACvC,OAAO,MAAM,CAAC;AACf,CAAC,CAAC"}
|
package/dist/core/portable.d.ts
CHANGED
|
@@ -1,35 +1,95 @@
|
|
|
1
|
+
import "./number.js";
|
|
2
|
+
import "./string.js";
|
|
3
|
+
import "./boolean.js";
|
|
4
|
+
import "./array.js";
|
|
5
|
+
import "./object.js";
|
|
6
|
+
import "./reflect.js";
|
|
1
7
|
/**
|
|
2
8
|
* Represents a generic class constructor.
|
|
3
9
|
*/
|
|
4
|
-
export
|
|
5
|
-
new (...args: any): any;
|
|
6
|
-
}
|
|
10
|
+
export type Constructor<T = any, P extends readonly any[] = []> = abstract new (...args: P) => T;
|
|
7
11
|
/**
|
|
8
12
|
* Represents a constructor that supports importing instances from a source.
|
|
9
13
|
*/
|
|
10
|
-
export interface ImportableConstructor extends Constructor {
|
|
14
|
+
export interface ImportableConstructor<M = any> extends Constructor<M> {
|
|
11
15
|
/**
|
|
12
16
|
* Imports an instance from a source.
|
|
13
17
|
* @param source The source value to import.
|
|
14
18
|
* @param name The name of the source value.
|
|
15
19
|
* @throws {TypeError} If the source is not of the expected type.
|
|
16
20
|
*/
|
|
17
|
-
import(source: any, name: string):
|
|
21
|
+
import(source: any, name: string): M;
|
|
18
22
|
}
|
|
19
23
|
/**
|
|
20
24
|
* Represents a constructor that supports exporting instances to a scheme.
|
|
21
25
|
* @template S The type of scheme.
|
|
22
26
|
*/
|
|
23
|
-
export interface ExportableConstructor<S =
|
|
27
|
+
export interface ExportableConstructor<M = any, S = unknown> extends Constructor<M> {
|
|
24
28
|
/**
|
|
25
29
|
* Exports an instance to a source.
|
|
26
30
|
* @param source The instance to export.
|
|
27
31
|
*/
|
|
28
|
-
export(source:
|
|
32
|
+
export(source: M): S;
|
|
29
33
|
}
|
|
30
34
|
/**
|
|
31
35
|
* Represents a constructor that supports facilitating the safe conversion between anonymous schemes and typed instances.
|
|
32
36
|
* @template S The type of scheme.
|
|
33
37
|
*/
|
|
34
|
-
export interface PortableConstructor<S =
|
|
38
|
+
export interface PortableConstructor<M = any, S = unknown> extends ImportableConstructor<M>, ExportableConstructor<M, S> {
|
|
35
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* The abstract base class for all portable data models.
|
|
42
|
+
* Provides mechanism for type-safe import and export of data structures.
|
|
43
|
+
*/
|
|
44
|
+
export declare abstract class PortableModel {
|
|
45
|
+
/**
|
|
46
|
+
* Creates an instance of the model from a raw source.
|
|
47
|
+
* Handles polymorphic resolution and recursive field mapping.
|
|
48
|
+
* @param source The raw source object (e.g. from JSON).
|
|
49
|
+
* @param name The context path for error reporting.
|
|
50
|
+
* @throws {TypeError} If validation fails or types do not match.
|
|
51
|
+
*/
|
|
52
|
+
static import<T extends typeof PortableModel, S = any>(this: T, source: any, name: string): InstanceType<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Serializes the model instance to a raw object.
|
|
55
|
+
* Includes type discrimination for polymorphic models.
|
|
56
|
+
* @param source The model instance to export.
|
|
57
|
+
*/
|
|
58
|
+
static export<T extends typeof PortableModel, S = any>(this: T, source: InstanceType<T>): S;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Decorator to register a class field as part of the portable schema.
|
|
62
|
+
* @param type The portable constructor to use for import/export.
|
|
63
|
+
*/
|
|
64
|
+
export declare function Field<M, S>(type: PortableConstructor<M, S>): (target: void, context: ClassFieldDecoratorContext<PortableModel, S>) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Decorator to register a class field as part of the portable schema.
|
|
67
|
+
* @param type The portable constructor to use for import/export.
|
|
68
|
+
* @param name Alias for the field in the external source.
|
|
69
|
+
*/
|
|
70
|
+
export declare function Field<M, S>(type: PortableConstructor<M, S>, name: string): (target: void, context: ClassFieldDecoratorContext<PortableModel, S>) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a portable wrapper for array types.
|
|
73
|
+
* @param type The portable type of the array elements.
|
|
74
|
+
*/
|
|
75
|
+
export declare function ArrayOf<M, S>(type: PortableConstructor<M, S>): PortableConstructor<M[], S[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a portable wrapper for nullable types.
|
|
78
|
+
* @param type The inner portable type.
|
|
79
|
+
*/
|
|
80
|
+
export declare function Nullable<M, S>(type: PortableConstructor<M, S>): PortableConstructor<M | null, S | null>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a portable wrapper for optional types.
|
|
83
|
+
* @param type The inner portable type.
|
|
84
|
+
*/
|
|
85
|
+
export declare function Optional<M, S>(type: PortableConstructor<M, S>): PortableConstructor<M | undefined, S | undefined>;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a wrapper for circular or deferred type references.
|
|
88
|
+
* @param resolver Function that returns the actual type constructor.
|
|
89
|
+
*/
|
|
90
|
+
export declare function Deferred<M, S>(resolver: (_: void) => PortableConstructor<M, S>): PortableConstructor<M, S>;
|
|
91
|
+
/**
|
|
92
|
+
* Decorator to register a descendant class in the base class's polymorphic registry.
|
|
93
|
+
* @param descendant The subclass constructor to register.
|
|
94
|
+
*/
|
|
95
|
+
export declare function Descendant<M extends typeof PortableModel>(descendant: PortableConstructor): (target: M, context: ClassDecoratorContext) => void;
|