adaptive-extender 0.7.0 → 0.7.2

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 CHANGED
@@ -1,5 +1,5 @@
1
- ## 0.7.0 (19.10.2025)
2
- - Added module [archive](), [archive-manager]().
1
+ ## 0.7.2 (20.10.2025)
2
+ - Added module [archive]().
3
3
 
4
4
  ## 0.6.1 (27.09.2025)
5
5
  - Added modules [promise](), [engine](), [parent-node](), [element]().
@@ -9,10 +9,12 @@ interface ArchivablePrototype<N = any> {
9
9
  new (...args: any): any;
10
10
  /**
11
11
  * Imports data from a source and returns a new instance.
12
+ * @throws {TypeError} If unable to import the source.
12
13
  */
13
14
  import(source: any): InstanceType<this>;
14
15
  /**
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.
16
18
  */
17
19
  import(source: any, name: string): InstanceType<this>;
18
20
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"archivable.js","sourceRoot":"","sources":["../../src/core/archivable.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAyBb,OAAO,EAA4B,CAAC"}
1
+ {"version":3,"file":"archivable.js","sourceRoot":"","sources":["../../src/core/archivable.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AA2Bb,OAAO,EAA4B,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import "../core/index.js";
2
+ import { type ArchivablePrototype } from "../core/index.js";
2
3
  /**
3
4
  * Represents a data archive stored in the local storage.
4
5
  */
@@ -25,4 +26,63 @@ declare class Archive {
25
26
  */
26
27
  set data(value: any);
27
28
  }
28
- export { Archive };
29
+ /**
30
+ * Manages the archiving of an object.
31
+ */
32
+ declare class ArchiveManager<T extends ArchivablePrototype> {
33
+ #private;
34
+ /**
35
+ * @param key The key for the archive.
36
+ * @param prototype The prototype of the archivable object.
37
+ * @param args The arguments for the constructor of the archivable object.
38
+ */
39
+ constructor(key: string, prototype: T, ...args: ConstructorParameters<T>);
40
+ /**
41
+ * Key of the archive.
42
+ */
43
+ get key(): string;
44
+ /**
45
+ * Reads content of the archive.
46
+ * @throws {ReferenceError} If the archive is missing from the local storage.
47
+ * @throws {SyntaxError} If the archive is corrupted.
48
+ */
49
+ get content(): InstanceType<T>;
50
+ /**
51
+ * Writes content of the archive.
52
+ * @throws {SyntaxError} If the value could not be processed.
53
+ */
54
+ set content(value: InstanceType<T>);
55
+ /**
56
+ * Resets the content of the archive to a new instance.
57
+ */
58
+ reset(): void;
59
+ }
60
+ /**
61
+ * Provides a repository pattern for managing an archivable object with saving.
62
+ */
63
+ declare class ArchiveRepository<T extends ArchivablePrototype> {
64
+ #private;
65
+ /**
66
+ * @param key The key for the archive.
67
+ * @param prototype The prototype of the archivable object.
68
+ * @param args The arguments for the constructor of the archivable object.
69
+ */
70
+ constructor(key: string, prototype: T, ...args: ConstructorParameters<T>);
71
+ /**
72
+ * Key of the archive.
73
+ */
74
+ get key(): string;
75
+ /**
76
+ * The content of the archive.
77
+ */
78
+ get content(): InstanceType<T>;
79
+ /**
80
+ * Schedules a save of the content to the archive.
81
+ */
82
+ save(): void;
83
+ /**
84
+ * Resets the content of the archive to a new instance and updates the repository's content.
85
+ */
86
+ reset(): void;
87
+ }
88
+ export { Archive, ArchiveManager, ArchiveRepository };
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  import "../core/index.js";
3
+ import {} from "../core/index.js";
3
4
  //#region Archive
4
5
  /**
5
6
  * Represents a data archive stored in the local storage.
@@ -62,5 +63,126 @@ class Archive {
62
63
  }
63
64
  }
64
65
  //#endregion
65
- export { Archive };
66
+ //#region Archive manager
67
+ /**
68
+ * Manages the archiving of an object.
69
+ */
70
+ class ArchiveManager {
71
+ #prototype;
72
+ #args;
73
+ #archive;
74
+ /**
75
+ * @param key The key for the archive.
76
+ * @param prototype The prototype of the archivable object.
77
+ * @param args The arguments for the constructor of the archivable object.
78
+ */
79
+ constructor(key, prototype, ...args) {
80
+ this.#prototype = prototype;
81
+ this.#args = args;
82
+ this.#archive = ArchiveManager.#newArchive(key, prototype, args);
83
+ }
84
+ static #newInstance(prototype, args) {
85
+ return Reflect.construct(prototype, args);
86
+ }
87
+ static #newArchive(key, prototype, args) {
88
+ const instance = ArchiveManager.#newInstance(prototype, args);
89
+ return new Archive(key, prototype.export(instance));
90
+ }
91
+ /**
92
+ * Key of the archive.
93
+ */
94
+ get key() {
95
+ return this.#archive.key;
96
+ }
97
+ /**
98
+ * Reads content of the archive.
99
+ * @throws {ReferenceError} If the archive is missing from the local storage.
100
+ * @throws {SyntaxError} If the archive is corrupted.
101
+ */
102
+ get content() {
103
+ try {
104
+ return this.#prototype.import(this.#archive.data);
105
+ }
106
+ catch (error) {
107
+ if (!(error instanceof TypeError))
108
+ throw error;
109
+ throw new SyntaxError(`Archive at key '${this.#archive.key}' is corrupted`);
110
+ }
111
+ }
112
+ /**
113
+ * Writes content of the archive.
114
+ * @throws {SyntaxError} If the value could not be processed.
115
+ */
116
+ set content(value) {
117
+ this.#archive.data = this.#prototype.export(value);
118
+ }
119
+ /**
120
+ * Resets the content of the archive to a new instance.
121
+ */
122
+ reset() {
123
+ this.content = ArchiveManager.#newInstance(this.#prototype, this.#args);
124
+ }
125
+ }
126
+ //#endregion
127
+ //#region Archive repository
128
+ /**
129
+ * Provides a repository pattern for managing an archivable object with saving.
130
+ */
131
+ class ArchiveRepository {
132
+ #manager;
133
+ #content;
134
+ #idSaveTimeout = NaN;
135
+ /**
136
+ * @param key The key for the archive.
137
+ * @param prototype The prototype of the archivable object.
138
+ * @param args The arguments for the constructor of the archivable object.
139
+ */
140
+ constructor(key, prototype, ...args) {
141
+ this.#manager = new ArchiveManager(key, prototype, ...args);
142
+ this.#content = this.#manager.content;
143
+ window.addEventListener("beforeunload", (event) => {
144
+ if (Number.isNaN(this.#idSaveTimeout))
145
+ return;
146
+ event.returnValue = "Archive saving is in process. Do you want to interrupt?";
147
+ event.preventDefault();
148
+ });
149
+ }
150
+ /**
151
+ * Key of the archive.
152
+ */
153
+ get key() {
154
+ return this.#manager.key;
155
+ }
156
+ /**
157
+ * The content of the archive.
158
+ */
159
+ get content() {
160
+ return this.#content;
161
+ }
162
+ #handler() {
163
+ try {
164
+ this.#manager.content = this.#content;
165
+ }
166
+ finally {
167
+ this.#idSaveTimeout = NaN;
168
+ }
169
+ }
170
+ /**
171
+ * Schedules a save of the content to the archive.
172
+ */
173
+ save() {
174
+ if (!Number.isNaN(this.#idSaveTimeout))
175
+ clearTimeout(this.#idSaveTimeout);
176
+ this.#idSaveTimeout = setTimeout(this.#handler.bind(this));
177
+ }
178
+ /**
179
+ * Resets the content of the archive to a new instance and updates the repository's content.
180
+ */
181
+ reset() {
182
+ this.#manager.reset();
183
+ this.#content = this.#manager.content;
184
+ }
185
+ }
186
+ //#endregion
187
+ export { Archive, ArchiveManager, ArchiveRepository };
66
188
  //# sourceMappingURL=archive.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"archive.js","sourceRoot":"","sources":["../../src/web/archive.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,kBAAkB,CAAC;AAE1B,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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AAI,CAAC,QAAQ,CAAC;QACvC,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC;QAC3B,CAAC;IACF,CAAC;IACD;;OAEG;IACH,IAAI;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC;YAAE,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC1E,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD;;OAEG;IACH,KAAK;QACJ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;IACvC,CAAC;CACD;AACD,YAAY;AAEZ,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC"}
@@ -4,4 +4,3 @@ export * from "./engine.js";
4
4
  export * from "./parent-node.js";
5
5
  export * from "./element.js";
6
6
  export * from "./archive.js";
7
- export * from "./archive-manager.js";
package/dist/web/index.js CHANGED
@@ -5,5 +5,4 @@ export * from "./engine.js";
5
5
  export * from "./parent-node.js";
6
6
  export * from "./element.js";
7
7
  export * from "./archive.js";
8
- export * from "./archive-manager.js";
9
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adaptive-extender",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Adaptive library for JS/TS development environments",
5
5
  "type": "module",
6
6
  "main": "./dist/core/index.js",