adaptive-extender 0.6.3 → 0.7.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 +2 -2
- package/dist/core/archivable.d.ts +25 -0
- package/dist/core/archivable.js +3 -0
- package/dist/core/archivable.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/web/archive-manager.d.ts +27 -0
- package/dist/web/archive-manager.js +51 -0
- package/dist/web/archive-manager.js.map +1 -0
- package/dist/web/archive.d.ts +20 -10
- package/dist/web/archive.js +68 -1
- package/dist/web/archive.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the interface for an archivable object's prototype.
|
|
3
|
+
* @template N The type of the notation returned by the export method.
|
|
4
|
+
*/
|
|
5
|
+
interface ArchivablePrototype<N = 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): InstanceType<this>;
|
|
15
|
+
/**
|
|
16
|
+
* Imports data from a source with a given name and returns a new instance.
|
|
17
|
+
* @throws {TypeError} If unable to import the source.
|
|
18
|
+
*/
|
|
19
|
+
import(source: any, name: string): InstanceType<this>;
|
|
20
|
+
/**
|
|
21
|
+
* Exports the state of an instance to a notation.
|
|
22
|
+
*/
|
|
23
|
+
export(source: InstanceType<this>): N;
|
|
24
|
+
}
|
|
25
|
+
export { type ArchivablePrototype };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archivable.js","sourceRoot":"","sources":["../../src/core/archivable.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AA2Bb,OAAO,EAA4B,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "../core/index.js";
|
|
2
|
+
import { type ArchivablePrototype } from "../core/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Manages the archiving of an object.
|
|
5
|
+
*/
|
|
6
|
+
declare class ArchiveManager<T extends ArchivablePrototype> {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param key The key for the archive.
|
|
10
|
+
* @param prototype The prototype of the archivable object.
|
|
11
|
+
* @param args The arguments for the constructor of the archivable object.
|
|
12
|
+
*/
|
|
13
|
+
constructor(key: string, prototype: T, args: ConstructorParameters<T>);
|
|
14
|
+
/**
|
|
15
|
+
* Reads content of the archive.
|
|
16
|
+
*/
|
|
17
|
+
get content(): InstanceType<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Writes content of the archive.
|
|
20
|
+
*/
|
|
21
|
+
set content(value: InstanceType<T>);
|
|
22
|
+
/**
|
|
23
|
+
* Resets the content of the archive to a new instance.
|
|
24
|
+
*/
|
|
25
|
+
reset(): void;
|
|
26
|
+
}
|
|
27
|
+
export { ArchiveManager };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import "../core/index.js";
|
|
3
|
+
import {} from "../core/index.js";
|
|
4
|
+
import { Archive } from "./archive.js";
|
|
5
|
+
//#region Archive manager
|
|
6
|
+
/**
|
|
7
|
+
* Manages the archiving of an object.
|
|
8
|
+
*/
|
|
9
|
+
class ArchiveManager {
|
|
10
|
+
#prototype;
|
|
11
|
+
#args;
|
|
12
|
+
#archive;
|
|
13
|
+
/**
|
|
14
|
+
* @param key The key for the archive.
|
|
15
|
+
* @param prototype The prototype of the archivable object.
|
|
16
|
+
* @param args The arguments for the constructor of the archivable object.
|
|
17
|
+
*/
|
|
18
|
+
constructor(key, prototype, args) {
|
|
19
|
+
this.#prototype = prototype;
|
|
20
|
+
this.#args = args;
|
|
21
|
+
this.#archive = ArchiveManager.#newArchive(key, prototype, args);
|
|
22
|
+
}
|
|
23
|
+
static #newInstance(prototype, args) {
|
|
24
|
+
return Reflect.construct(prototype, args);
|
|
25
|
+
}
|
|
26
|
+
static #newArchive(key, prototype, args) {
|
|
27
|
+
const instance = ArchiveManager.#newInstance(prototype, args);
|
|
28
|
+
return new Archive(key, prototype.export(instance));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reads content of the archive.
|
|
32
|
+
*/
|
|
33
|
+
get content() {
|
|
34
|
+
return this.#prototype.import(this.#archive.data);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Writes content of the archive.
|
|
38
|
+
*/
|
|
39
|
+
set content(value) {
|
|
40
|
+
this.#archive.data = this.#prototype.export(value);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resets the content of the archive to a new instance.
|
|
44
|
+
*/
|
|
45
|
+
reset() {
|
|
46
|
+
this.content = ArchiveManager.#newInstance(this.#prototype, this.#args);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { ArchiveManager };
|
|
51
|
+
//# sourceMappingURL=archive-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive-manager.js","sourceRoot":"","sources":["../../src/web/archive-manager.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAA4B,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,yBAAyB;AACzB;;GAEG;AACH,MAAM,cAAc;IACnB,UAAU,CAAI;IACd,KAAK,CAA2B;IAChC,QAAQ,CAAU;IAClB;;;;OAIG;IACH,YAAY,GAAW,EAAE,SAAY,EAAE,IAA8B;QACpE,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;IACD,MAAM,CAAC,YAAY,CAAgC,SAAY,EAAE,IAA8B;QAC9F,OAAO,OAAO,CAAC,SAAS,CAA4C,SAAS,EAAE,IAAI,CAAC,CAAC;IACtF,CAAC;IACD,MAAM,CAAC,WAAW,CAAgC,GAAW,EAAE,SAAY,EAAE,IAA8B;QAC1G,MAAM,QAAQ,GAAG,cAAc,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC9D,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrD,CAAC;IACD;;OAEG;IACH,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IACD;;OAEG;IACH,IAAI,OAAO,CAAC,KAAsB;QACjC,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IACD;;OAEG;IACH,KAAK;QACJ,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACzE,CAAC;CACD;AACD,YAAY;AAEZ,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/web/archive.d.ts
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
import "../core/index.js";
|
|
2
|
+
import type { ArchivablePrototype } from "../core/index.js";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
+
* Manages the archiving of an object.
|
|
4
5
|
*/
|
|
5
|
-
declare class
|
|
6
|
+
declare class ArchiveManager<T extends ArchivablePrototype> {
|
|
6
7
|
#private;
|
|
7
8
|
/**
|
|
8
|
-
* @param key The key
|
|
9
|
-
* @param
|
|
9
|
+
* @param key The key for the archive.
|
|
10
|
+
* @param prototype The prototype of the archivable object.
|
|
11
|
+
* @param args The arguments for the constructor of the archivable object.
|
|
10
12
|
*/
|
|
11
|
-
constructor(key: string,
|
|
13
|
+
constructor(key: string, prototype: T, ...args: ConstructorParameters<T>);
|
|
12
14
|
/**
|
|
13
|
-
*
|
|
15
|
+
* Key of the archive.
|
|
16
|
+
*/
|
|
17
|
+
get key(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Reads content of the archive.
|
|
14
20
|
* @throws {ReferenceError} If the archive is missing from the local storage.
|
|
15
21
|
* @throws {SyntaxError} If the archive is corrupted.
|
|
16
22
|
*/
|
|
17
|
-
get
|
|
23
|
+
get content(): InstanceType<T>;
|
|
18
24
|
/**
|
|
19
|
-
*
|
|
25
|
+
* Writes content of the archive.
|
|
20
26
|
* @throws {SyntaxError} If the value could not be processed.
|
|
21
27
|
*/
|
|
22
|
-
set
|
|
28
|
+
set content(value: InstanceType<T>);
|
|
29
|
+
/**
|
|
30
|
+
* Resets the content of the archive to a new instance.
|
|
31
|
+
*/
|
|
32
|
+
reset(): void;
|
|
23
33
|
}
|
|
24
|
-
export {
|
|
34
|
+
export { ArchiveManager };
|
package/dist/web/archive.js
CHANGED
|
@@ -35,6 +35,12 @@ class Archive {
|
|
|
35
35
|
throw new SyntaxError(`Archive at key '${key}' is corrupted`);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The key used in the local storage.
|
|
40
|
+
*/
|
|
41
|
+
get key() {
|
|
42
|
+
return this.#key;
|
|
43
|
+
}
|
|
38
44
|
/**
|
|
39
45
|
* The data stored in the archive.
|
|
40
46
|
* @throws {ReferenceError} If the archive is missing from the local storage.
|
|
@@ -56,5 +62,66 @@ class Archive {
|
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
//#endregion
|
|
59
|
-
|
|
65
|
+
//#region Archive manager
|
|
66
|
+
/**
|
|
67
|
+
* Manages the archiving of an object.
|
|
68
|
+
*/
|
|
69
|
+
class ArchiveManager {
|
|
70
|
+
#prototype;
|
|
71
|
+
#args;
|
|
72
|
+
#archive;
|
|
73
|
+
/**
|
|
74
|
+
* @param key The key for the archive.
|
|
75
|
+
* @param prototype The prototype of the archivable object.
|
|
76
|
+
* @param args The arguments for the constructor of the archivable object.
|
|
77
|
+
*/
|
|
78
|
+
constructor(key, prototype, ...args) {
|
|
79
|
+
this.#prototype = prototype;
|
|
80
|
+
this.#args = args;
|
|
81
|
+
this.#archive = ArchiveManager.#newArchive(key, prototype, args);
|
|
82
|
+
}
|
|
83
|
+
static #newInstance(prototype, args) {
|
|
84
|
+
return Reflect.construct(prototype, args);
|
|
85
|
+
}
|
|
86
|
+
static #newArchive(key, prototype, args) {
|
|
87
|
+
const instance = ArchiveManager.#newInstance(prototype, args);
|
|
88
|
+
return new Archive(key, prototype.export(instance));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Key of the archive.
|
|
92
|
+
*/
|
|
93
|
+
get key() {
|
|
94
|
+
return this.#archive.key;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Reads content of the archive.
|
|
98
|
+
* @throws {ReferenceError} If the archive is missing from the local storage.
|
|
99
|
+
* @throws {SyntaxError} If the archive is corrupted.
|
|
100
|
+
*/
|
|
101
|
+
get content() {
|
|
102
|
+
try {
|
|
103
|
+
return this.#prototype.import(this.#archive.data);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (!(error instanceof TypeError))
|
|
107
|
+
throw error;
|
|
108
|
+
throw new SyntaxError(`Archive at key '${this.#archive.key}' is corrupted`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Writes content of the archive.
|
|
113
|
+
* @throws {SyntaxError} If the value could not be processed.
|
|
114
|
+
*/
|
|
115
|
+
set content(value) {
|
|
116
|
+
this.#archive.data = this.#prototype.export(value);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Resets the content of the archive to a new instance.
|
|
120
|
+
*/
|
|
121
|
+
reset() {
|
|
122
|
+
this.content = ArchiveManager.#newInstance(this.#prototype, this.#args);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { ArchiveManager };
|
|
60
127
|
//# sourceMappingURL=archive.js.map
|
package/dist/web/archive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"archive.js","sourceRoot":"","sources":["../../src/web/archive.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"archive.js","sourceRoot":"","sources":["../../src/web/archive.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,kBAAkB,CAAC;AAG1B,iBAAiB;AACjB;;GAEG;AACH,MAAM,OAAO;IACZ,IAAI,CAAS;IACb;;;OAGG;IACH,YAAY,GAAW,EAAE,OAAY;QACpC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IACD,WAAW,CAAC,KAAU;QACrB,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI;YAAE,OAAO;QACrD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,MAAM,CAAC,SAAS,CAAC,GAAW,EAAE,KAAU;QACvC,IAAI,CAAC;YACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACR,MAAM,IAAI,WAAW,CAAC,mBAAmB,GAAG,+BAA+B,CAAC,CAAC;QAC9E,CAAC;IACF,CAAC;IACD,MAAM,CAAC,WAAW,CAAC,GAAW,EAAE,IAAY;QAC3C,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