adaptive-extender 0.9.1 → 0.9.3
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 +5 -1
- package/README.md +160 -2
- 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/portable.d.ts +5 -7
- package/dist/core/portable.js +10 -11
- package/dist/core/portable.js.map +1 -1
- package/package.json +2 -2
- package/dist/core/archivable.d.ts +0 -19
- package/dist/core/archivable.js +0 -3
- package/dist/core/archivable.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
## 0.9.
|
|
1
|
+
## 0.9.3 (23.01.2026)
|
|
2
|
+
- Ported models no longer automatically receive a discriminator unless they are polymorphic descendants.
|
|
3
|
+
- Improved typing for `Model.export` and its descendants in `Descendant`, ensuring that data is handled as at least an `object` type.
|
|
4
|
+
|
|
5
|
+
## 0.9.2 (20.01.2026)
|
|
2
6
|
- Unified the `ImportableConstructor` and `ExportableConstructor` interfaces into `PortableConstructor`.
|
|
3
7
|
- Improved typing for object porting; decorators now possess better context inference.
|
|
4
8
|
- Moved `Constructor` to [global](./src/core/global.ts).
|
package/README.md
CHANGED
|
@@ -1,7 +1,165 @@
|
|
|
1
|
-
|
|
1
|
+
# Adaptive Extender
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/adaptive-extender)
|
|
4
4
|
|
|
5
|
-
Adaptive library for JS/TS development environments
|
|
5
|
+
Adaptive library for JS/TS development environments.
|
|
6
|
+
|
|
7
|
+
**Adaptive Extender** is a comprehensive TypeScript library designed to bridge the gap between raw JavaScript primitives and high-level application logic. It augments native objects with fluent, intuitive APIs and provides robust systems for data modeling, time management, and asynchronous control flow.
|
|
6
8
|
|
|
7
9
|
[Change log](./CHANGELOG.md)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## ⚡ Key Features & Problems Solved
|
|
14
|
+
|
|
15
|
+
### 1. Type-Safe Data Portability (`Portable`)
|
|
16
|
+
**The Problem:**
|
|
17
|
+
Reading data from external sources (APIs, JSON files) usually results in `any` or untyped objects. Validating them requires verbose boilerplate repetitive mapping code. `JSON.parse` offers zero guarantees about shape or types.
|
|
18
|
+
|
|
19
|
+
**The Solution:**
|
|
20
|
+
The `Portable` system allows you to define strict schemas using decorators directly on your classes. It handles validation, type conversion, and polymorphic resolution automatically.
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { Model, Field, ArrayOf, Nullable } from "adaptive-extender/core";
|
|
24
|
+
|
|
25
|
+
// Define a model
|
|
26
|
+
class User extends Model {
|
|
27
|
+
@Field(String)
|
|
28
|
+
name: string = "";
|
|
29
|
+
|
|
30
|
+
@Field(Nullable(Number))
|
|
31
|
+
age: number | null = null;
|
|
32
|
+
|
|
33
|
+
@Field(ArrayOf(String))
|
|
34
|
+
tags: string[] = [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ❌ The Problem: Unsafe JSON
|
|
38
|
+
const rawData = JSON.parse('{"name": "Alice", "tags": ["admin"]}');
|
|
39
|
+
|
|
40
|
+
// ✅ The Solution: Typed Import
|
|
41
|
+
// Validates structure and types automatically. Throws informative errors if invalid.
|
|
42
|
+
const user = User.import(rawData, "api_response");
|
|
43
|
+
|
|
44
|
+
console.log(user instanceof User); // true
|
|
45
|
+
console.log(user.name); // "Alice"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2. First-Class Time Management (`Timespan`)
|
|
49
|
+
**The Problem:**
|
|
50
|
+
Calculating durations using raw milliseconds (e.g., `86400000` for a day) is prone to "magic number" errors and is hard to read. Converting back and forth between days, minutes, and milliseconds creates messy math in your business logic.
|
|
51
|
+
|
|
52
|
+
**The Solution:**
|
|
53
|
+
The `Timespan` class offers a structured, readable way to handle time intervals, inspired by robust systems like .NET.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { Timespan } from "adaptive-extender/core";
|
|
57
|
+
|
|
58
|
+
// ❌ The Problem: Unreadable Math
|
|
59
|
+
// setTimeout(() => {}, 2 * 60 * 60 * 1000 + 30 * 1000);
|
|
60
|
+
|
|
61
|
+
// ✅ The Solution: Explicit Definition
|
|
62
|
+
const duration = Timespan.fromComponents(0, 2, 30, 0); // 0 days, 2 hours, 30 min
|
|
63
|
+
|
|
64
|
+
console.log(duration.valueOf()); // 9000000 (milliseconds)
|
|
65
|
+
console.log(`Duration: ${duration.hours}h ${duration.minutes}m`);
|
|
66
|
+
|
|
67
|
+
// Parsing support
|
|
68
|
+
const fromString = Timespan.parse("02:30:00.000");
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 3. Extended Native Prototypes
|
|
72
|
+
**The Problem:**
|
|
73
|
+
JavaScript's standard library often lacks convenient utility methods found in other languages. Developers often write repetitive helper functions like `isEmpty(str)` or manual `for` loops to generate number ranges.
|
|
74
|
+
|
|
75
|
+
**The Solution:**
|
|
76
|
+
Adaptive Extender safely adds non-enumerable, standard-compliant extensions to native prototypes (`Array`, `String`, `Math`, etc.), making your code more expressive.
|
|
77
|
+
|
|
78
|
+
#### String Utilities
|
|
79
|
+
```typescript
|
|
80
|
+
// ❌ Original: Checks are verbose
|
|
81
|
+
if (str !== null && str !== undefined && str.trim() !== "") { ... }
|
|
82
|
+
|
|
83
|
+
// ✅ Extended: Clean & Readable
|
|
84
|
+
if (!String.isWhitespace(str)) { ... }
|
|
85
|
+
|
|
86
|
+
// Fallback values
|
|
87
|
+
const displayName = userInput.insteadWhitespace("files/default.png");
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Array Utilities
|
|
91
|
+
```typescript
|
|
92
|
+
// ❌ Original: Manual loops for sequences
|
|
93
|
+
const nums = [];
|
|
94
|
+
for (let i = 0; i < 5; i++) nums.push(i);
|
|
95
|
+
|
|
96
|
+
// ✅ Extended: Python-like Range
|
|
97
|
+
const nums = Array.range(0, 5); // [0, 1, 2, 3, 4]
|
|
98
|
+
|
|
99
|
+
// Zipping arrays
|
|
100
|
+
const names = ["A", "B"];
|
|
101
|
+
const ages = [20, 30];
|
|
102
|
+
for (const [name, age] of Array.zip(names, ages)) {
|
|
103
|
+
console.log(`${name} is ${age}`);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 4. Advanced Promise Control
|
|
108
|
+
**The Problem:**
|
|
109
|
+
Managing complex asynchronous states or checking if a promise has settled without awaiting it can be difficult.
|
|
110
|
+
|
|
111
|
+
**The Solution:**
|
|
112
|
+
Extensions to `Promise` and the `Promisable<T>` type simplify async workflows.
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { type Promisable } from "adaptive-extender/core";
|
|
116
|
+
|
|
117
|
+
// Unified type for Sync or Async values
|
|
118
|
+
function process(input: Promisable<string>) {
|
|
119
|
+
// ...
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Check status (async check)
|
|
123
|
+
if (await mytask.isSettled) {
|
|
124
|
+
console.log("Task finished");
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 📦 Modules
|
|
131
|
+
|
|
132
|
+
The library is split into scopes to keep your bundle size optimal:
|
|
133
|
+
|
|
134
|
+
- **`adaptive-extender/core`**:
|
|
135
|
+
Platform-agnostic utilities (Math, Primitives, Time, Portable System). Works in Node.js, Deno, and Browser.
|
|
136
|
+
|
|
137
|
+
- **`adaptive-extender/node`**:
|
|
138
|
+
Node.js specific extensions (Environment, File System processing).
|
|
139
|
+
|
|
140
|
+
- **`adaptive-extender/web`**:
|
|
141
|
+
Browser specific DOM extensions (Element, ParentNode hooks).
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 🚀 Installation
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
npm install adaptive-extender
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 🛠 Usage
|
|
152
|
+
|
|
153
|
+
Simply import the module to activate the extensions.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
// Import core to register global proto extensions
|
|
157
|
+
import "adaptive-extender/core";
|
|
158
|
+
|
|
159
|
+
// Use features
|
|
160
|
+
const list = Array.range(1, 10);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## 📄 License
|
|
164
|
+
|
|
165
|
+
Apache-2.0
|
|
@@ -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;QACd,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;CACD;AAOD,MAAM,gBAAgB;IACrB,SAAS,CAAsB;IAE/B,YAAY,QAA6B;QACxC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACD;AACD,YAAY;AACZ,8BAA8B;AAC9B,MAAM,mBAAmB;IACxB,MAAM,CAAC,SAAS,GAAqC,IAAI,GAAG,EAAE,CAAC;IAC/D,MAAM,CAAuB;IAC7B,OAAO,GAAsB,EAAE,CAA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@@ export interface PortableConstructor<I = any, S = unknown> extends Constructor<I
|
|
|
29
29
|
export declare abstract class Model {
|
|
30
30
|
/**
|
|
31
31
|
* Creates an instance of the model from a raw source.
|
|
32
|
-
*
|
|
33
|
-
* @param source The raw source object (e.g. from JSON).
|
|
32
|
+
* @param source The raw source object.
|
|
34
33
|
* @param name The context path for error reporting.
|
|
35
34
|
* @throws {TypeError} If validation fails or types do not match.
|
|
36
35
|
*/
|
|
37
36
|
static import<I extends Model>(this: Constructor<I>, source: any, name: string): I;
|
|
38
37
|
/**
|
|
39
38
|
* Serializes the model instance to a raw object.
|
|
40
|
-
* Includes type discrimination for polymorphic models.
|
|
41
39
|
* @param source The model instance to export.
|
|
42
40
|
*/
|
|
43
|
-
static export<I extends Model, S
|
|
41
|
+
static export<I extends Model, S extends object>(this: Constructor<I>, source: I): S;
|
|
44
42
|
}
|
|
45
43
|
/**
|
|
46
44
|
* Decorator to register a class field as part of the portable schema.
|
|
47
45
|
* @param type The portable constructor to use for import/export.
|
|
48
46
|
*/
|
|
49
|
-
export declare function Field<M, S>(type: PortableConstructor<M, S>): (target: void, context: ClassFieldDecoratorContext<Model,
|
|
47
|
+
export declare function Field<M, S>(type: PortableConstructor<M, S>): (target: void, context: ClassFieldDecoratorContext<Model, M>) => void;
|
|
50
48
|
/**
|
|
51
49
|
* Decorator to register a class field as part of the portable schema.
|
|
52
50
|
* @param type The portable constructor to use for import/export.
|
|
53
51
|
* @param name Alias for the field in the external source.
|
|
54
52
|
*/
|
|
55
|
-
export declare function Field<M, S>(type: PortableConstructor<M, S>, name: string): (target: void, context: ClassFieldDecoratorContext<Model,
|
|
53
|
+
export declare function Field<M, S>(type: PortableConstructor<M, S>, name: string): (target: void, context: ClassFieldDecoratorContext<Model, M>) => void;
|
|
56
54
|
/**
|
|
57
55
|
* Creates a portable wrapper for array types.
|
|
58
56
|
* @param type The portable type of the array elements.
|
|
@@ -77,7 +75,7 @@ export declare function Deferred<M, S>(resolver: (_: void) => PortableConstructo
|
|
|
77
75
|
* Decorator to register a descendant class in the base class's polymorphic registry.
|
|
78
76
|
* @param descendant The subclass constructor to register.
|
|
79
77
|
*/
|
|
80
|
-
export declare function Descendant<M extends typeof Model>(descendant: PortableConstructor): (target: M, context: ClassDecoratorContext) => void;
|
|
78
|
+
export declare function Descendant<M extends typeof Model>(descendant: PortableConstructor<Model, object>): (target: M, context: ClassDecoratorContext) => void;
|
|
81
79
|
/**
|
|
82
80
|
* A portable adapter that facilitates the conversion between `Date` instances and millisecond timestamps.
|
|
83
81
|
*/
|
package/dist/core/portable.js
CHANGED
|
@@ -57,7 +57,7 @@ class PortabilityMetadata {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
//#endregion
|
|
60
|
-
//#region
|
|
60
|
+
//#region Model
|
|
61
61
|
/**
|
|
62
62
|
* The abstract base class for all portable data models.
|
|
63
63
|
* Provides mechanism for type-safe import and export of data structures.
|
|
@@ -65,8 +65,7 @@ class PortabilityMetadata {
|
|
|
65
65
|
export class Model {
|
|
66
66
|
/**
|
|
67
67
|
* Creates an instance of the model from a raw source.
|
|
68
|
-
*
|
|
69
|
-
* @param source The raw source object (e.g. from JSON).
|
|
68
|
+
* @param source The raw source object.
|
|
70
69
|
* @param name The context path for error reporting.
|
|
71
70
|
* @throws {TypeError} If validation fails or types do not match.
|
|
72
71
|
*/
|
|
@@ -93,7 +92,6 @@ export class Model {
|
|
|
93
92
|
}
|
|
94
93
|
/**
|
|
95
94
|
* Serializes the model instance to a raw object.
|
|
96
|
-
* Includes type discrimination for polymorphic models.
|
|
97
95
|
* @param source The model instance to export.
|
|
98
96
|
*/
|
|
99
97
|
static export(source) {
|
|
@@ -103,15 +101,16 @@ export class Model {
|
|
|
103
101
|
const descendant = descendants.find(descendant => source instanceof descendant);
|
|
104
102
|
if (descendant === undefined)
|
|
105
103
|
throw new TypeError(`Invalid '${typename(source)}' type for source`);
|
|
106
|
-
|
|
104
|
+
const exported = descendant.export(source);
|
|
105
|
+
Reflect.set(exported, "$type", descendant.name);
|
|
106
|
+
return exported;
|
|
107
107
|
}
|
|
108
|
-
const object = Object();
|
|
109
|
-
Reflect.set(object, "$type", model.name);
|
|
108
|
+
const object = new Object();
|
|
110
109
|
const { fields } = PortabilityMetadata.read(model);
|
|
111
|
-
for (const
|
|
112
|
-
const value = Reflect.get(source,
|
|
113
|
-
const raw =
|
|
114
|
-
Reflect.set(object,
|
|
110
|
+
for (const { key, association, type } of fields.values()) {
|
|
111
|
+
const value = Reflect.get(source, key);
|
|
112
|
+
const raw = type.export(value);
|
|
113
|
+
Reflect.set(object, association, raw);
|
|
115
114
|
}
|
|
116
115
|
return object;
|
|
117
116
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portable.js","sourceRoot":"","sources":["../../src/core/portable.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;AACrB,OAAO,aAAa,CAAC;AACrB,OAAO,cAAc,CAAC;AACtB,OAAO,YAAY,CAAC;AACpB,OAAO,aAAa,CAAC;AACrB,OAAO,cAAc,CAAC;AACtB,OAAO,EAAoB,MAAM,aAAa,CAAC;AAoB/C,YAAY;AACZ,0BAA0B;AAC1B,MAAM,eAAe;IACpB,IAAI,CAAS;IACb,YAAY,CAAS;IACrB,KAAK,CAAsB;IAE3B,YAAY,GAAW,EAAE,WAAmB,EAAE,IAAyB;QACtE,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;QACd,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;CACD;AACD,YAAY;AACZ,8BAA8B;AAC9B,MAA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CAAC,MAAW;QACjB,OAAO,MAAM,CAAC;IACf,CAAC;CAC2C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adaptive-extender",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Adaptive library for JS/TS development environments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/core/index.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"build:web": "tsc -p ./src/web/tsconfig.json",
|
|
52
52
|
"build": "npm run build:core && npm run build:node && npm run build:web",
|
|
53
53
|
|
|
54
|
-
"test": "vitest",
|
|
54
|
+
"test": "vitest run",
|
|
55
55
|
"coverage": "vitest run --coverage"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defines the interface for an archivable object's prototype.
|
|
3
|
-
* @template S The type of the notation returned by the export method.
|
|
4
|
-
*/
|
|
5
|
-
export interface ArchivablePrototype<S = any> {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new instance of the archivable object.
|
|
8
|
-
*/
|
|
9
|
-
new (...args: any): any;
|
|
10
|
-
/**
|
|
11
|
-
* Imports data from a source and returns a new instance.
|
|
12
|
-
* @throws {TypeError} If unable to import the source.
|
|
13
|
-
*/
|
|
14
|
-
import(source: any, name: string): InstanceType<this>;
|
|
15
|
-
/**
|
|
16
|
-
* Exports the state of an instance to a notation.
|
|
17
|
-
*/
|
|
18
|
-
export(source: InstanceType<this>): S;
|
|
19
|
-
}
|
package/dist/core/archivable.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"archivable.js","sourceRoot":"","sources":["../../src/core/archivable.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|