adaptive-extender 0.10.5 → 0.11.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/CHANGELOG.md +12 -1
- package/README.md +3 -3
- package/dist/core/array.d.ts +6 -0
- package/dist/core/array.js +18 -0
- package/dist/core/array.js.map +1 -1
- package/dist/core/bigint.js +1 -0
- package/dist/core/boolean.js +1 -0
- package/dist/core/color.js +1 -0
- package/dist/core/controller.js +1 -0
- package/dist/core/date.d.ts +10 -1
- package/dist/core/date.js +34 -0
- package/dist/core/date.js.map +1 -1
- package/dist/core/engine.js +1 -0
- package/dist/core/environment.js +1 -0
- package/dist/core/error.js +1 -0
- package/dist/core/function.js +1 -0
- package/dist/core/global.js +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/map.d.ts +14 -1
- package/dist/core/map.js +48 -1
- package/dist/core/map.js.map +1 -1
- package/dist/core/math.d.ts +5 -0
- package/dist/core/math.js +18 -6
- package/dist/core/math.js.map +1 -1
- package/dist/core/number.js +1 -0
- package/dist/core/object.js +1 -0
- package/dist/core/portable.d.ts +72 -47
- package/dist/core/portable.js +250 -315
- package/dist/core/portable.js.map +1 -1
- package/dist/core/primitives.js +1 -0
- package/dist/core/promise.js +1 -0
- package/dist/core/random.js +1 -0
- package/dist/core/reflect.d.ts +0 -20
- package/dist/core/reflect.js +1 -15
- package/dist/core/reflect.js.map +1 -1
- package/dist/core/set.d.ts +8 -1
- package/dist/core/set.js +18 -1
- package/dist/core/set.js.map +1 -1
- package/dist/core/string.js +1 -0
- package/dist/core/timespan.js +1 -0
- package/dist/core/vector-1.js +1 -0
- package/dist/core/vector-2.js +1 -0
- package/dist/core/vector-3.js +1 -0
- package/dist/core/vector.js +1 -0
- package/dist/core/version.js +1 -0
- package/dist/node/index.js +1 -0
- package/dist/web/archive.d.ts +68 -11
- package/dist/web/archive.js +60 -44
- package/dist/web/archive.js.map +1 -1
- package/dist/web/element.js +1 -0
- package/dist/web/engine.js +1 -0
- package/dist/web/index.d.ts +0 -1
- package/dist/web/index.js +1 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/metadata-injector.js +17 -16
- package/dist/web/metadata-injector.js.map +1 -1
- package/dist/web/parent-node.js +1 -0
- package/dist/web/promise.js +1 -0
- package/dist/worker/engine.js +1 -0
- package/dist/worker/index.js +1 -0
- package/dist/worker/promise.js +1 -0
- package/package.json +2 -1
- package/tsconfig.base.json +4 -0
- package/dist/web/url.d.ts +0 -1
- package/dist/web/url.js +0 -17
- package/dist/web/url.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## 0.11.1 (21.06.2026)
|
|
2
|
+
- Added `Array.Of(type)` portable adapter for typed arrays, alongside the existing `Array.import`/`Array.export`.
|
|
3
|
+
- Added `Set.Of(type)` portable adapter for typed sets.
|
|
4
|
+
- Added `Map.AsRecord(type)` and `Map.AsTuples(typeKey, typeValue)` portable adapters (moved from a separate module into [map](./src/core/map.ts)).
|
|
5
|
+
- Added `Date.AsTimestamp` and `Date.AsUnixSeconds` portable adapters converting `Date` to millisecond and Unix-second numbers respectively.
|
|
6
|
+
- Added `Number.prototype.snap(step)` — snaps a number to the nearest multiple of the given step.
|
|
7
|
+
- **Breaking:** Removed `Reflect.mapNull`, `Reflect.mapUndefined`, and `Reflect.mapNullable`. Use `Nullable.map`, `Optional.map` from the portable module instead.
|
|
8
|
+
- **Breaking:** Renamed `Archive`/`ArchiveManager`/`ArchiveRepository` to `Cell`/`PortableCell`/`BufferedCell`. Construction is now done via `Storage` factory methods (`localStorage.openCell`, `localStorage.openPortableCell`, `localStorage.openBufferedCell`) — the storage backend is no longer hardcoded to `localStorage`.
|
|
9
|
+
- **Breaking:** `@Field` decorator no longer accepts a positional string as the second argument. Use `{ name: "..." }` options object: `@Field(String, { name: "fieldName" })`.
|
|
10
|
+
- `PortableCell.save()` returns `Promise<boolean>` — resolves `true` when persisted, `false` if cancelled (superseded or aborted); rejects only on serialization failure.
|
|
11
|
+
|
|
1
12
|
## 0.10.5 (13.06.2026)
|
|
2
13
|
- Bugfix at [portable](./src/core/portable.ts).
|
|
3
14
|
|
|
@@ -16,7 +27,7 @@
|
|
|
16
27
|
## 0.9.13 (06.04.2026)
|
|
17
28
|
- Added `Version` class for semantic versioning with `parse()`, `tryParse()` support.
|
|
18
29
|
- Added `BigInt` portable support via `BigInt.import()` and `BigInt.export()`.
|
|
19
|
-
- `ArchiveRepository.save()` is now `async` and returns `Promise<
|
|
30
|
+
- `ArchiveRepository.save()` is now `async` and returns `Promise<boolean>`. The promise resolves `true` when the save completes, `false` if cancelled (superseded by a subsequent call or aborted via `abort()`), and rejects only on serialization failure.
|
|
20
31
|
- `Promise.withSignal` now has a default type parameter `T = void`.
|
|
21
32
|
- Renamed `EnumFrom` adapter to `EnumAs`.
|
|
22
33
|
|
package/README.md
CHANGED
|
@@ -412,10 +412,10 @@ const repository = new ArchiveRepository("settings", Settings, new Settings());
|
|
|
412
412
|
const settings = repository.content;
|
|
413
413
|
settings.volume = 0.5;
|
|
414
414
|
|
|
415
|
-
// save()
|
|
416
|
-
await repository.save(); // save immediately
|
|
415
|
+
// save() resolves true when persisted, false if cancelled (superseded or aborted), rejects only on serialization failure
|
|
416
|
+
const saved = await repository.save(); // save immediately
|
|
417
417
|
await repository.save(3000); // debounced — save after 3 seconds
|
|
418
|
-
// A pending save
|
|
418
|
+
// A pending save resolves false when superseded by a new call or cancelled by abort()
|
|
419
419
|
repository.reset(); // abort pending save and revert to initial state
|
|
420
420
|
```
|
|
421
421
|
|
package/dist/core/array.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "./global.js";
|
|
2
|
+
import { type PortableConstructor } from "./portable.js";
|
|
2
3
|
declare global {
|
|
3
4
|
export interface ArrayConstructor {
|
|
4
5
|
/**
|
|
@@ -13,6 +14,11 @@ declare global {
|
|
|
13
14
|
* @param source The array to export.
|
|
14
15
|
*/
|
|
15
16
|
export(source: any[]): any[];
|
|
17
|
+
/**
|
|
18
|
+
* Creates a portable wrapper for array types.
|
|
19
|
+
* @param type The portable type of the array elements.
|
|
20
|
+
*/
|
|
21
|
+
Of<I, S>(type: PortableConstructor<I, S>): PortableConstructor<I[], S[]>;
|
|
16
22
|
/**
|
|
17
23
|
* Creates an array of integers between the specified minimum and maximum values (exclusive).
|
|
18
24
|
* @param min The minimum value of the range (inclusive).
|
package/dist/core/array.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import "./global.js";
|
|
3
3
|
import {} from "./promise.js";
|
|
4
|
+
import {} from "./portable.js";
|
|
4
5
|
const { trunc } = Math;
|
|
5
6
|
Array.import = function (source, name) {
|
|
6
7
|
if (!Array.isArray(source))
|
|
@@ -10,6 +11,22 @@ Array.import = function (source, name) {
|
|
|
10
11
|
Array.export = function (source) {
|
|
11
12
|
return source;
|
|
12
13
|
};
|
|
14
|
+
Array.Of = function (type) {
|
|
15
|
+
return {
|
|
16
|
+
[Symbol.hasInstance](instance) {
|
|
17
|
+
return Array[Symbol.hasInstance](instance);
|
|
18
|
+
},
|
|
19
|
+
get name() {
|
|
20
|
+
return `${type.name}[]`;
|
|
21
|
+
},
|
|
22
|
+
import(source, name) {
|
|
23
|
+
return Array.import(source, name).map((item, index) => type.import(item, `${name}[${index}]`));
|
|
24
|
+
},
|
|
25
|
+
export(source) {
|
|
26
|
+
return source.map(item => type.export(item));
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
13
30
|
Array.range = function (min, max) {
|
|
14
31
|
min = trunc(min);
|
|
15
32
|
max = trunc(max);
|
|
@@ -67,3 +84,4 @@ Array.prototype.remove = function (value) {
|
|
|
67
84
|
this.splice(index, 1);
|
|
68
85
|
return true;
|
|
69
86
|
};
|
|
87
|
+
//# sourceMappingURL=array.js.map
|
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;AACrB,OAAO,EAAmB,MAAM,cAAc,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;AAC/C,OAAO,EAA4B,MAAM,eAAe,CAAC;AAEzD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;AAsEvB,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,EAAE,GAAG,UAAgB,IAA+B;IACzD,OAAO;QACN,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,QAAa;YACjC,OAAO,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,IAAI;YACP,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC;QACzB,CAAC;QAED,MAAM,CAAC,MAAW,EAAE,IAAY;YAC/B,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;QAChG,CAAC;QAED,MAAM,CAAC,MAAW;YACjB,OAAO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KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC;AACb,CAAC,CAAC"}
|
package/dist/core/bigint.js
CHANGED
package/dist/core/boolean.js
CHANGED
package/dist/core/color.js
CHANGED
package/dist/core/controller.js
CHANGED
package/dist/core/date.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import "./global.js";
|
|
2
|
+
import { type PortableConstructor } from "./portable.js";
|
|
2
3
|
declare global {
|
|
3
4
|
export interface DateConstructor {
|
|
4
5
|
/**
|
|
5
|
-
* Validates and imports a date value from a raw source.
|
|
6
|
+
* Validates and imports a date value from a raw ISO string source.
|
|
6
7
|
* @param source The raw value to check.
|
|
7
8
|
* @param name The field name for error context.
|
|
8
9
|
* @throws {TypeError} If the source is not a string.
|
|
@@ -18,6 +19,14 @@ declare global {
|
|
|
18
19
|
* @returns `true` if the value is a `Date` and is invalid; otherwise, `false`.
|
|
19
20
|
*/
|
|
20
21
|
isInvalid(date: unknown): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Portable adapter that converts between `Date` instances and millisecond timestamps.
|
|
24
|
+
*/
|
|
25
|
+
AsTimestamp: PortableConstructor<Date, number>;
|
|
26
|
+
/**
|
|
27
|
+
* Portable adapter that converts between `Date` instances and Unix second timestamps.
|
|
28
|
+
*/
|
|
29
|
+
AsUnixSeconds: PortableConstructor<Date, number>;
|
|
21
30
|
}
|
|
22
31
|
export interface Date {
|
|
23
32
|
/**
|
package/dist/core/date.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import "./global.js";
|
|
3
|
+
import {} from "./portable.js";
|
|
3
4
|
Date.import = function (source, name) {
|
|
4
5
|
if (typeof (source) !== "string")
|
|
5
6
|
throw new TypeError(`Unable to import date from ${name} due its ${typename(source)} type`);
|
|
@@ -13,8 +14,41 @@ Date.isInvalid = function (date) {
|
|
|
13
14
|
return false;
|
|
14
15
|
return Number.isNaN(date.getTime());
|
|
15
16
|
};
|
|
17
|
+
Date.AsTimestamp = {
|
|
18
|
+
[Symbol.hasInstance](instance) {
|
|
19
|
+
return Date[Symbol.hasInstance](instance);
|
|
20
|
+
},
|
|
21
|
+
get name() {
|
|
22
|
+
return "Timestamp";
|
|
23
|
+
},
|
|
24
|
+
import(source, name) {
|
|
25
|
+
if (typeof (source) !== "number")
|
|
26
|
+
throw new TypeError(`Unable to import date from ${name} due its ${typename(source)} type`);
|
|
27
|
+
return new Date(source);
|
|
28
|
+
},
|
|
29
|
+
export(source) {
|
|
30
|
+
return source.getTime();
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
Date.AsUnixSeconds = {
|
|
34
|
+
[Symbol.hasInstance](instance) {
|
|
35
|
+
return Date[Symbol.hasInstance](instance);
|
|
36
|
+
},
|
|
37
|
+
get name() {
|
|
38
|
+
return "UnixSeconds";
|
|
39
|
+
},
|
|
40
|
+
import(source, name) {
|
|
41
|
+
if (typeof (source) !== "number")
|
|
42
|
+
throw new TypeError(`Unable to import date from ${name} due its ${typename(source)} type`);
|
|
43
|
+
return new Date(source * 1000);
|
|
44
|
+
},
|
|
45
|
+
export(source) {
|
|
46
|
+
return Math.trunc(source.getTime() / 1000);
|
|
47
|
+
},
|
|
48
|
+
};
|
|
16
49
|
Date.prototype.insteadInvalid = function (value) {
|
|
17
50
|
if (Date.isInvalid(this))
|
|
18
51
|
return value;
|
|
19
52
|
return this;
|
|
20
53
|
};
|
|
54
|
+
//# sourceMappingURL=date.js.map
|
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
|
+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,CAAC;IACzB,CAAC;CACoC,CAAC;AAEvC,IAAI,CAAC,aAAa,GAAG;IACpB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,QAAa;QACjC,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,IAAI;QACP,OAAO,aAAa,CAAC;IACtB,CAAC;IAED,MAAM,CAAC,MAAW,EAAE,IAAY;QAC/B,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,QAAQ;YAAE,MAAM,IAAI,SAAS,CAAC,8BAA8B,IAAI,YAAY,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7H,OAAO,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,MAAY;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC;CACoC,CAAC;AAEvC,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"}
|
package/dist/core/engine.js
CHANGED
package/dist/core/environment.js
CHANGED
package/dist/core/error.js
CHANGED
package/dist/core/function.js
CHANGED
package/dist/core/global.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Reflect.set(Symbol, "metadata", Reflect.get(Symbol, "metadata") ?? Symbol.for("Symbol.metadata"));
|
|
3
2
|
globalThis.constructor = function (value) {
|
|
4
3
|
return value.constructor;
|
|
5
4
|
};
|
|
@@ -11,3 +10,4 @@ globalThis.typename = function (value) {
|
|
|
11
10
|
}
|
|
12
11
|
};
|
|
13
12
|
export {};
|
|
13
|
+
//# sourceMappingURL=global.js.map
|
package/dist/core/index.js
CHANGED
package/dist/core/map.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
import { type PortableConstructor } from "./portable.js";
|
|
1
2
|
declare global {
|
|
3
|
+
export interface MapConstructor {
|
|
4
|
+
/**
|
|
5
|
+
* Creates a portable wrapper for maps with string keys, converting them to and from plain objects.
|
|
6
|
+
* @param type The portable type of the map values.
|
|
7
|
+
*/
|
|
8
|
+
AsRecord<I, S>(type: PortableConstructor<I, S>): PortableConstructor<Map<string, I>, Record<string, S>>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a portable wrapper for maps with arbitrary key and value types, converting them to and from arrays of `[key, value]` tuples.
|
|
11
|
+
* @param typeKey The portable type of the map keys.
|
|
12
|
+
* @param typeValue The portable type of the map values.
|
|
13
|
+
*/
|
|
14
|
+
AsTuples<IK, SK, IV, SV>(typeKey: PortableConstructor<IK, SK>, typeValue: PortableConstructor<IV, SV>): PortableConstructor<Map<IK, IV>, [SK, SV][]>;
|
|
15
|
+
}
|
|
2
16
|
export interface Map<K, V> {
|
|
3
17
|
/**
|
|
4
18
|
* Adds the key/value pair only if the key is not already present.
|
|
@@ -9,4 +23,3 @@ declare global {
|
|
|
9
23
|
add(key: K, value: V): boolean;
|
|
10
24
|
}
|
|
11
25
|
}
|
|
12
|
-
export {};
|
package/dist/core/map.js
CHANGED
|
@@ -1,8 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
import {} from "./portable.js";
|
|
3
|
+
Map.AsRecord = function (type) {
|
|
4
|
+
return {
|
|
5
|
+
[Symbol.hasInstance](instance) {
|
|
6
|
+
return Map[Symbol.hasInstance](instance);
|
|
7
|
+
},
|
|
8
|
+
get name() {
|
|
9
|
+
return `Map<string, ${type.name}>`;
|
|
10
|
+
},
|
|
11
|
+
import(source, name) {
|
|
12
|
+
const record = Object.import(source, name);
|
|
13
|
+
const map = new Map();
|
|
14
|
+
for (const key of Object.keys(record)) {
|
|
15
|
+
map.set(key, type.import(Reflect.get(record, key), `${name}[${JSON.stringify(key)}]`));
|
|
16
|
+
}
|
|
17
|
+
return map;
|
|
18
|
+
},
|
|
19
|
+
export(source) {
|
|
20
|
+
const record = {};
|
|
21
|
+
for (const [key, value] of source) {
|
|
22
|
+
Reflect.set(record, key, type.export(value));
|
|
23
|
+
}
|
|
24
|
+
return record;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
Map.AsTuples = function (typeKey, typeValue) {
|
|
29
|
+
return {
|
|
30
|
+
[Symbol.hasInstance](instance) {
|
|
31
|
+
return Map[Symbol.hasInstance](instance);
|
|
32
|
+
},
|
|
33
|
+
get name() {
|
|
34
|
+
return `Map<${typeKey.name}, ${typeValue.name}>`;
|
|
35
|
+
},
|
|
36
|
+
import(source, name) {
|
|
37
|
+
return new Map(Array.import(source, name).map((item, index) => {
|
|
38
|
+
const tuple = Array.import(item, `${name}[${index}]`);
|
|
39
|
+
const key = typeKey.import(tuple[0], `${name}[${index}][0]`);
|
|
40
|
+
const value = typeValue.import(tuple[1], `${name}[${index}][1]`);
|
|
41
|
+
return [key, value];
|
|
42
|
+
}));
|
|
43
|
+
},
|
|
44
|
+
export(source) {
|
|
45
|
+
return Array.from(source, ([key, value]) => [typeKey.export(key), typeValue.export(value)]);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
};
|
|
2
49
|
Map.prototype.add = function (key, value) {
|
|
3
50
|
if (this.has(key))
|
|
4
51
|
return false;
|
|
5
52
|
this.set(key, value);
|
|
6
53
|
return true;
|
|
7
54
|
};
|
|
8
|
-
|
|
55
|
+
//# sourceMappingURL=map.js.map
|
package/dist/core/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/core/map.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/core/map.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAE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AAG,EAAE,KAAK,CAAC,CAAC;IACrB,OAAO,IAAI,CAAC;AACb,CAAC,CAAC"}
|
package/dist/core/math.d.ts
CHANGED
|
@@ -36,6 +36,11 @@ declare global {
|
|
|
36
36
|
* @throws {RangeError} When the length is zero.
|
|
37
37
|
*/
|
|
38
38
|
mod(start: number, length: number): number;
|
|
39
|
+
/**
|
|
40
|
+
* Snaps the number to the nearest multiple of the given step.
|
|
41
|
+
* @param step The step size to snap to.
|
|
42
|
+
*/
|
|
43
|
+
snap(step: number): number;
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
declare global {
|
package/dist/core/math.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const { PI, trunc, pow } = Math;
|
|
2
|
+
const { PI, trunc, pow, round } = Math;
|
|
3
3
|
Number.prototype.clamp = function (min, max) {
|
|
4
4
|
let result = this.valueOf();
|
|
5
5
|
if (result < min)
|
|
@@ -8,6 +8,11 @@ Number.prototype.clamp = function (min, max) {
|
|
|
8
8
|
return max;
|
|
9
9
|
return result;
|
|
10
10
|
};
|
|
11
|
+
function normalize(value, min, max) {
|
|
12
|
+
if (min === max)
|
|
13
|
+
throw new Error("Minimum and maximum of the original range cant be equal");
|
|
14
|
+
return (value - min) / (max - min);
|
|
15
|
+
}
|
|
11
16
|
function lerp(value, min1, max1, min2, max2) {
|
|
12
17
|
if (min1 === max1)
|
|
13
18
|
throw new Error("Minimum and maximum of the original range cant be equal");
|
|
@@ -17,18 +22,24 @@ function lerp(value, min1, max1, min2, max2) {
|
|
|
17
22
|
}
|
|
18
23
|
Number.prototype.lerp = function (min1, max1, min2, max2) {
|
|
19
24
|
if (min2 === undefined || max2 === undefined)
|
|
20
|
-
return
|
|
25
|
+
return normalize(this.valueOf(), min1, max1);
|
|
21
26
|
return lerp(this.valueOf(), min1, max1, min2, max2);
|
|
22
27
|
};
|
|
23
|
-
function
|
|
28
|
+
function repeat(value, length) {
|
|
24
29
|
if (length === 0)
|
|
25
30
|
throw new RangeError("Length must not be zero");
|
|
26
|
-
return (
|
|
31
|
+
return (value % length + length) % length;
|
|
32
|
+
}
|
|
33
|
+
function wrap(value, start, length) {
|
|
34
|
+
return repeat(value - start, length) + start;
|
|
27
35
|
}
|
|
28
36
|
Number.prototype.mod = function (arg1, arg2) {
|
|
29
37
|
if (arg2 === undefined)
|
|
30
|
-
return
|
|
31
|
-
return
|
|
38
|
+
return repeat(this.valueOf(), arg1);
|
|
39
|
+
return wrap(this.valueOf(), arg1, arg2);
|
|
40
|
+
};
|
|
41
|
+
Number.prototype.snap = function (step) {
|
|
42
|
+
return round(this.valueOf() / step) * step;
|
|
32
43
|
};
|
|
33
44
|
Math.split = function (x) {
|
|
34
45
|
const integer = trunc(x);
|
|
@@ -70,3 +81,4 @@ Math.meanHarmonic = function (...values) {
|
|
|
70
81
|
return values.length / summary;
|
|
71
82
|
};
|
|
72
83
|
export {};
|
|
84
|
+
//# sourceMappingURL=math.js.map
|
package/dist/core/math.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.js","sourceRoot":"","sources":["../../src/core/math.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"math.js","sourceRoot":"","sources":["../../src/core/math.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;AAiDvC,MAAM,CAAC,SAAS,CAAC,KAAK,GAAG,UAAU,GAAW,EAAE,GAAW;IAC1D,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC5B,IAAI,MAAM,GAAG,GAAG;QAAE,OAAO,GAAG,CAAC;IAC7B,IAAI,MAAM,GAAG,GAAG;QAAE,OAAO,GAAG,CAAC;IAC7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;IAChB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACpD,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;AAChC,CAAC,CAAC;AAEF,IAAI,CAAC,aAAa,GAAG,UAAU,GAAG,MAAgB;IACjD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACpD,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,IAAI,CAAC,YAAY,GAAG,UAAU,GAAG,MAAgB;IAChD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,GAAG,CAAC;QAC5B,OAAO,IAAI,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC;AAChC,CAAC,CAAC"}
|
package/dist/core/number.js
CHANGED
package/dist/core/object.js
CHANGED
package/dist/core/portable.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import "./string.js";
|
|
|
3
3
|
import "./boolean.js";
|
|
4
4
|
import "./array.js";
|
|
5
5
|
import "./object.js";
|
|
6
|
+
import "./map.js";
|
|
6
7
|
import "./reflect.js";
|
|
8
|
+
import "./error.js";
|
|
7
9
|
import { type Constructor } from "./global.js";
|
|
8
10
|
/**
|
|
9
11
|
* Represents a constructor that supports facilitating the safe conversion between anonymous schemes and typed instances.
|
|
@@ -22,6 +24,19 @@ export interface PortableConstructor<I = any, S = unknown> extends Constructor<I
|
|
|
22
24
|
*/
|
|
23
25
|
export(source: I): S;
|
|
24
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for the {@link Field} decorator.
|
|
29
|
+
*/
|
|
30
|
+
export interface FieldOptions<I> {
|
|
31
|
+
/**
|
|
32
|
+
* Alias for the field key in the external source.
|
|
33
|
+
*/
|
|
34
|
+
name: string;
|
|
35
|
+
/**
|
|
36
|
+
* Fallback value used when the source key is absent during import.
|
|
37
|
+
*/
|
|
38
|
+
fallback: I;
|
|
39
|
+
}
|
|
25
40
|
/**
|
|
26
41
|
* The abstract base class for all portable data models.
|
|
27
42
|
* Provides mechanism for type-safe import and export of data structures.
|
|
@@ -48,9 +63,14 @@ export declare function Field<I, S>(type: PortableConstructor<I, S>): (target: v
|
|
|
48
63
|
/**
|
|
49
64
|
* Decorator to register a class field as part of the portable schema.
|
|
50
65
|
* @param type The portable constructor to use for import/export.
|
|
51
|
-
* @param
|
|
66
|
+
* @param options Configuration for aliasing and migration defaults.
|
|
67
|
+
*/
|
|
68
|
+
export declare function Field<I, S>(type: PortableConstructor<I, S>, options: Partial<FieldOptions<I>>): (target: void, context: ClassFieldDecoratorContext<Model, I>) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a wrapper for circular or deferred type references.
|
|
71
|
+
* @param resolver Function that returns the actual type constructor.
|
|
52
72
|
*/
|
|
53
|
-
export declare function
|
|
73
|
+
export declare function Deferred<I, S>(resolver: (_: void) => PortableConstructor<I, S>): PortableConstructor<I, S>;
|
|
54
74
|
/**
|
|
55
75
|
* Decorator to register a descendant class in the base class's polymorphic registry.
|
|
56
76
|
* @param descendant The subclass constructor to register.
|
|
@@ -68,55 +88,60 @@ export declare function Descendant<M extends typeof Model>(descendant: PortableC
|
|
|
68
88
|
*/
|
|
69
89
|
export declare function DiscriminatorKey<M extends typeof Model>(key: string): (target: M, context: ClassDecoratorContext) => void;
|
|
70
90
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*/
|
|
74
|
-
export declare function Deferred<I, S>(resolver: (_: void) => PortableConstructor<I, S>): PortableConstructor<I, S>;
|
|
75
|
-
/**
|
|
76
|
-
* Creates a portable wrapper for optional types.
|
|
77
|
-
* @param type The inner portable type.
|
|
91
|
+
* Portable adapter class for optional (possibly-undefined) types.
|
|
92
|
+
* Use `Optional.Of(type)` to wrap an adapter, and `Optional.map` for conditional mapping.
|
|
78
93
|
*/
|
|
79
|
-
export declare
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
*/
|
|
94
|
-
export declare function SetOf<I, S>(type: PortableConstructor<I, S>): PortableConstructor<Set<I>, S[]>;
|
|
95
|
-
/**
|
|
96
|
-
* Creates a portable wrapper for maps with string keys, converting them to and from plain objects.
|
|
97
|
-
* @param value The portable type of the map values.
|
|
98
|
-
*/
|
|
99
|
-
export declare function RecordOf<I, S>(type: PortableConstructor<I, S>): PortableConstructor<Map<string, I>, Record<string, S>>;
|
|
100
|
-
/**
|
|
101
|
-
* Creates a portable wrapper for maps with arbitrary key and value types, converting them to and from arrays of `[key, value]` tuples.
|
|
102
|
-
* @param key The portable type of the map keys.
|
|
103
|
-
* @param value The portable type of the map values.
|
|
104
|
-
*/
|
|
105
|
-
export declare function MapOf<IK, SK, IV, SV>(typeKey: PortableConstructor<IK, SK>, typeValue: PortableConstructor<IV, SV>): PortableConstructor<Map<IK, IV>, [SK, SV][]>;
|
|
106
|
-
/**
|
|
107
|
-
* Creates a portable wrapper for enum types, strictly operating only on enum values.
|
|
108
|
-
* @param reference The enum object reference.
|
|
109
|
-
*/
|
|
110
|
-
export declare function EnumAs<T extends Readonly<Record<string, unknown>>>(reference: T): PortableConstructor<T[keyof T], T[keyof T]>;
|
|
94
|
+
export declare class Optional {
|
|
95
|
+
constructor();
|
|
96
|
+
/**
|
|
97
|
+
* Creates a portable wrapper for optional types.
|
|
98
|
+
* @param type The inner portable type.
|
|
99
|
+
*/
|
|
100
|
+
static Of<I, S>(type: PortableConstructor<I, S>): PortableConstructor<I | undefined, S | undefined>;
|
|
101
|
+
/**
|
|
102
|
+
* Applies a callback to a non-undefined value, or passes through `undefined` unchanged.
|
|
103
|
+
* @param value The value to map.
|
|
104
|
+
* @param callback The function to apply if the value is not undefined.
|
|
105
|
+
*/
|
|
106
|
+
static map<T, R>(value: T, callback: (value: Defined<T>) => R): R | UndefinedFrom<T>;
|
|
107
|
+
}
|
|
111
108
|
/**
|
|
112
|
-
*
|
|
109
|
+
* Portable adapter class for nullable (possibly-null) types.
|
|
110
|
+
* Use `Nullable.Of(type)` to wrap an adapter, and `Nullable.map` for conditional mapping.
|
|
113
111
|
*/
|
|
114
|
-
export declare
|
|
112
|
+
export declare class Nullable {
|
|
113
|
+
constructor();
|
|
114
|
+
/**
|
|
115
|
+
* Creates a portable wrapper for nullable types.
|
|
116
|
+
* @param type The inner portable type.
|
|
117
|
+
*/
|
|
118
|
+
static Of<I, S>(type: PortableConstructor<I, S>): PortableConstructor<I | null, S | null>;
|
|
119
|
+
/**
|
|
120
|
+
* Applies a callback to a non-null value, or passes through `null` unchanged.
|
|
121
|
+
* @param value The value to map.
|
|
122
|
+
* @param callback The function to apply if the value is not null.
|
|
123
|
+
*/
|
|
124
|
+
static map<T, R>(value: T, callback: (value: NotNull<T>) => R): R | NullFrom<T>;
|
|
125
|
+
}
|
|
115
126
|
/**
|
|
116
|
-
*
|
|
127
|
+
* Portable adapter class for enum types.
|
|
128
|
+
* Use `Enum.Of(reference)` to create an adapter that validates against enum values.
|
|
117
129
|
*/
|
|
118
|
-
export declare
|
|
130
|
+
export declare class Enum {
|
|
131
|
+
constructor();
|
|
132
|
+
/**
|
|
133
|
+
* Creates a portable wrapper for enum types, strictly operating only on enum values.
|
|
134
|
+
* @param reference The enum object reference.
|
|
135
|
+
*/
|
|
136
|
+
static Of<T extends Readonly<Record<string, unknown>>>(reference: T): PortableConstructor<T[keyof T], T[keyof T]>;
|
|
137
|
+
}
|
|
119
138
|
/**
|
|
120
|
-
*
|
|
139
|
+
* Portable adapter class for unknown/any types.
|
|
140
|
+
* Pass `Any` directly to `@Field` to allow any value without validation or transformation.
|
|
121
141
|
*/
|
|
122
|
-
export declare
|
|
142
|
+
export declare class Any {
|
|
143
|
+
constructor();
|
|
144
|
+
static [Symbol.hasInstance](instance: any): boolean;
|
|
145
|
+
static import(source: any, name: string): any;
|
|
146
|
+
static export(source: any): any;
|
|
147
|
+
}
|