@aidc-toolkit/core 1.0.41 → 1.0.42-beta
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/dist/app-data-storage.d.ts +118 -0
- package/dist/app-data-storage.d.ts.map +1 -0
- package/dist/app-data-storage.js +117 -0
- package/dist/app-data-storage.js.map +1 -0
- package/dist/app-data.d.ts +26 -0
- package/dist/app-data.d.ts.map +1 -0
- package/dist/app-data.js +79 -0
- package/dist/app-data.js.map +1 -0
- package/dist/browser-app-data-storage.d.ts +26 -0
- package/dist/browser-app-data-storage.d.ts.map +1 -0
- package/dist/browser-app-data-storage.js +34 -0
- package/dist/browser-app-data-storage.js.map +1 -0
- package/dist/cache.d.ts +58 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +12 -0
- package/dist/cache.js.map +1 -0
- package/dist/file-app-data-storage.d.ts +27 -0
- package/dist/file-app-data-storage.d.ts.map +1 -0
- package/dist/file-app-data-storage.js +52 -0
- package/dist/file-app-data-storage.js.map +1 -0
- package/dist/http-fetch.d.ts +45 -0
- package/dist/http-fetch.d.ts.map +1 -0
- package/dist/http-fetch.js +26 -0
- package/dist/http-fetch.js.map +1 -0
- package/dist/hyperlink.d.ts +18 -0
- package/dist/hyperlink.d.ts.map +1 -0
- package/dist/hyperlink.js +2 -0
- package/dist/hyperlink.js.map +1 -0
- package/dist/index.d.ts +30 -761
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -0
- package/dist/local-app-data-storage.d.ts +8 -0
- package/dist/local-app-data-storage.d.ts.map +1 -0
- package/dist/local-app-data-storage.js +11 -0
- package/dist/local-app-data-storage.js.map +1 -0
- package/dist/locale/en/locale-resources.d.ts +10 -0
- package/dist/locale/en/locale-resources.d.ts.map +1 -0
- package/dist/locale/en/locale-resources.js +9 -0
- package/dist/locale/en/locale-resources.js.map +1 -0
- package/dist/locale/fr/locale-resources.d.ts +10 -0
- package/dist/locale/fr/locale-resources.d.ts.map +1 -0
- package/dist/locale/fr/locale-resources.js +9 -0
- package/dist/locale/fr/locale-resources.js.map +1 -0
- package/dist/locale/i18n.d.ts +83 -0
- package/dist/locale/i18n.d.ts.map +1 -0
- package/dist/locale/i18n.js +157 -0
- package/dist/locale/i18n.js.map +1 -0
- package/dist/logger.d.ts +136 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +256 -0
- package/dist/logger.js.map +1 -0
- package/dist/parse-version.d.ts +36 -0
- package/dist/parse-version.d.ts.map +1 -0
- package/dist/parse-version.js +23 -0
- package/dist/parse-version.js.map +1 -0
- package/dist/remote-app-data-storage.d.ts +23 -0
- package/dist/remote-app-data-storage.d.ts.map +1 -0
- package/dist/remote-app-data-storage.js +42 -0
- package/dist/remote-app-data-storage.js.map +1 -0
- package/dist/type-helper.d.ts +115 -0
- package/dist/type-helper.d.ts.map +1 -0
- package/dist/type-helper.js +163 -0
- package/dist/type-helper.js.map +1 -0
- package/dist/type.d.ts +111 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +2 -0
- package/dist/type.js.map +1 -0
- package/dist/website-url.d.ts +29 -0
- package/dist/website-url.d.ts.map +1 -0
- package/dist/website-url.js +60 -0
- package/dist/website-url.js.map +1 -0
- package/package.json +2 -2
- package/src/file-app-data-storage.ts +27 -13
- package/src/http-fetch.ts +59 -0
- package/src/index.ts +1 -0
- package/src/remote-app-data-storage.ts +23 -15
- package/tsconfig-src.tsbuildinfo +1 -1
- package/dist/browser-app-data-storage-G62WSQ5Z.js +0 -1
- package/dist/chunk-FIUBVWNN.js +0 -1
- package/dist/file-app-data-storage-Y5AB6YOB.js +0 -1
- package/dist/index.cjs +0 -18
- package/dist/index.d.cts +0 -761
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type AppData } from "./app-data.js";
|
|
2
|
+
import type { Promisable } from "./type.js";
|
|
3
|
+
/**
|
|
4
|
+
* Generic read-only application data storage.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class ReadOnlyAppDataStorage<SupportsBinary extends boolean> {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Extension to identify binary data.
|
|
10
|
+
*/
|
|
11
|
+
protected static readonly BINARY_EXTENSION = ".bin";
|
|
12
|
+
/**
|
|
13
|
+
* Extension to identify JSON data.
|
|
14
|
+
*/
|
|
15
|
+
protected static readonly JSON_EXTENSION = ".json";
|
|
16
|
+
/**
|
|
17
|
+
* Constructor.
|
|
18
|
+
*
|
|
19
|
+
* @param supportsBinary
|
|
20
|
+
* True if binary data is supported.
|
|
21
|
+
*
|
|
22
|
+
* @param path
|
|
23
|
+
* Storage path prepended to each key along with '/' if defined, empty string if not.
|
|
24
|
+
*/
|
|
25
|
+
protected constructor(supportsBinary: SupportsBinary, path?: string);
|
|
26
|
+
/**
|
|
27
|
+
* Determine if binary data is supported.
|
|
28
|
+
*/
|
|
29
|
+
get supportsBinary(): SupportsBinary;
|
|
30
|
+
/**
|
|
31
|
+
* Get the storage path, prepended to each key.
|
|
32
|
+
*/
|
|
33
|
+
get path(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Build the full storage key.
|
|
36
|
+
*
|
|
37
|
+
* @param pathKey
|
|
38
|
+
* Key relative to path.
|
|
39
|
+
*
|
|
40
|
+
* @param isBinary
|
|
41
|
+
* True if key is to binary data, false or undefined if to string data. Ignored if binary data is not supported.
|
|
42
|
+
*
|
|
43
|
+
* @returns
|
|
44
|
+
* Full storage key.
|
|
45
|
+
*/
|
|
46
|
+
protected fullKey(pathKey: string, isBinary: boolean): string;
|
|
47
|
+
/**
|
|
48
|
+
* Read a string or binary data from persistent storage.
|
|
49
|
+
*
|
|
50
|
+
* @param key
|
|
51
|
+
* Storage key (file path in Node.js, key in localStorage).
|
|
52
|
+
*
|
|
53
|
+
* @param asBinary
|
|
54
|
+
* True if binary data is requested, false or undefined if string data is requested. Ignored if binary data is not
|
|
55
|
+
* supported.
|
|
56
|
+
*
|
|
57
|
+
* @returns
|
|
58
|
+
* String or binary data or undefined if not found.
|
|
59
|
+
*/
|
|
60
|
+
protected abstract doRead(key: string, asBinary: boolean | undefined): Promisable<(SupportsBinary extends true ? string | Uint8Array : string) | undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* Read application data from storage.
|
|
63
|
+
*
|
|
64
|
+
* @param pathKey
|
|
65
|
+
* Key relative to path.
|
|
66
|
+
*
|
|
67
|
+
* @param asBinary
|
|
68
|
+
* True if binary data is requested, false or undefined if string data is requested. Ignored if binary data is not
|
|
69
|
+
* supported.
|
|
70
|
+
*
|
|
71
|
+
* @returns
|
|
72
|
+
* Application data or undefined if not found.
|
|
73
|
+
*/
|
|
74
|
+
read(pathKey: string, asBinary?: boolean): Promise<AppData | undefined>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Generic read/write application data storage.
|
|
78
|
+
*/
|
|
79
|
+
export declare abstract class AppDataStorage<SupportsBinary extends boolean> extends ReadOnlyAppDataStorage<SupportsBinary> {
|
|
80
|
+
/**
|
|
81
|
+
* Write a string or binary data in persistent storage.
|
|
82
|
+
*
|
|
83
|
+
* @param key
|
|
84
|
+
* Storage key (file path in Node.js, key in localStorage).
|
|
85
|
+
*
|
|
86
|
+
* @param data
|
|
87
|
+
* String or binary data.
|
|
88
|
+
*/
|
|
89
|
+
protected abstract doWrite(key: string, data: SupportsBinary extends true ? string | Uint8Array : string): Promisable<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Write application data to storage.
|
|
92
|
+
*
|
|
93
|
+
* @param pathKey
|
|
94
|
+
* Key relative to path.
|
|
95
|
+
*
|
|
96
|
+
* @param appData
|
|
97
|
+
* Application data to write.
|
|
98
|
+
*/
|
|
99
|
+
write(pathKey: string, appData: AppData): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Delete from persistent storage.
|
|
102
|
+
*
|
|
103
|
+
* @param key
|
|
104
|
+
* Storage key (file path in Node.js, key in localStorage).
|
|
105
|
+
*/
|
|
106
|
+
protected abstract doDelete(key: string): Promisable<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Delete application data from persistent storage.
|
|
109
|
+
*
|
|
110
|
+
* @param pathKey
|
|
111
|
+
* Key relative to path.
|
|
112
|
+
*
|
|
113
|
+
* @param asBinary
|
|
114
|
+
* True if key is to binary data, false or undefined if to string data. Ignored if binary data is not supported.
|
|
115
|
+
*/
|
|
116
|
+
delete(pathKey: string, asBinary?: boolean): Promise<void>;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=app-data-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-data-storage.d.ts","sourceRoot":"","sources":["../src/app-data-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAgC,MAAM,eAAe,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;GAEG;AACH,8BAAsB,sBAAsB,CAAC,cAAc,SAAS,OAAO;;IACvE;;OAEG;IACH,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,UAAU;IAEpD;;OAEG;IACH,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,WAAW;IAYnD;;;;;;;;OAQG;IACH,SAAS,aAAa,cAAc,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,MAAM;IAKnE;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,CAEnC;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM;IAS7D;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC,CAAC,cAAc,SAAS,IAAI,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC,GAAG,SAAS,CAAC;IAE3J;;;;;;;;;;;;OAYG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;CAKhF;AAED;;GAEG;AACH,8BAAsB,cAAc,CAAC,cAAc,SAAS,OAAO,CAAE,SAAQ,sBAAsB,CAAC,cAAc,CAAC;IAC/G;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,SAAS,IAAI,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC;IAE3H;;;;;;;;OAQG;IACG,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAU7D;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC;IAE1D;;;;;;;;OAQG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAGnE"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { decodeAppData, encodeAppData } from "./app-data.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generic read-only application data storage.
|
|
4
|
+
*/
|
|
5
|
+
export class ReadOnlyAppDataStorage {
|
|
6
|
+
/**
|
|
7
|
+
* Extension to identify binary data.
|
|
8
|
+
*/
|
|
9
|
+
static BINARY_EXTENSION = ".bin";
|
|
10
|
+
/**
|
|
11
|
+
* Extension to identify JSON data.
|
|
12
|
+
*/
|
|
13
|
+
static JSON_EXTENSION = ".json";
|
|
14
|
+
/**
|
|
15
|
+
* True if binary data is supported natively.
|
|
16
|
+
*/
|
|
17
|
+
#supportsBinary;
|
|
18
|
+
/**
|
|
19
|
+
* Storage path prepended to each key.
|
|
20
|
+
*/
|
|
21
|
+
#path;
|
|
22
|
+
/**
|
|
23
|
+
* Constructor.
|
|
24
|
+
*
|
|
25
|
+
* @param supportsBinary
|
|
26
|
+
* True if binary data is supported.
|
|
27
|
+
*
|
|
28
|
+
* @param path
|
|
29
|
+
* Storage path prepended to each key along with '/' if defined, empty string if not.
|
|
30
|
+
*/
|
|
31
|
+
constructor(supportsBinary, path) {
|
|
32
|
+
this.#supportsBinary = supportsBinary;
|
|
33
|
+
this.#path = path !== undefined ? `${path}/` : "";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Determine if binary data is supported.
|
|
37
|
+
*/
|
|
38
|
+
get supportsBinary() {
|
|
39
|
+
return this.#supportsBinary;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the storage path, prepended to each key.
|
|
43
|
+
*/
|
|
44
|
+
get path() {
|
|
45
|
+
return this.#path;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build the full storage key.
|
|
49
|
+
*
|
|
50
|
+
* @param pathKey
|
|
51
|
+
* Key relative to path.
|
|
52
|
+
*
|
|
53
|
+
* @param isBinary
|
|
54
|
+
* True if key is to binary data, false or undefined if to string data. Ignored if binary data is not supported.
|
|
55
|
+
*
|
|
56
|
+
* @returns
|
|
57
|
+
* Full storage key.
|
|
58
|
+
*/
|
|
59
|
+
fullKey(pathKey, isBinary) {
|
|
60
|
+
const keyNoExtension = `${this.path}${pathKey}`;
|
|
61
|
+
// Add extension to key if binary data is supported.
|
|
62
|
+
return this.supportsBinary ?
|
|
63
|
+
`${keyNoExtension}${isBinary ? ReadOnlyAppDataStorage.BINARY_EXTENSION : ReadOnlyAppDataStorage.JSON_EXTENSION}` :
|
|
64
|
+
keyNoExtension;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Read application data from storage.
|
|
68
|
+
*
|
|
69
|
+
* @param pathKey
|
|
70
|
+
* Key relative to path.
|
|
71
|
+
*
|
|
72
|
+
* @param asBinary
|
|
73
|
+
* True if binary data is requested, false or undefined if string data is requested. Ignored if binary data is not
|
|
74
|
+
* supported.
|
|
75
|
+
*
|
|
76
|
+
* @returns
|
|
77
|
+
* Application data or undefined if not found.
|
|
78
|
+
*/
|
|
79
|
+
async read(pathKey, asBinary) {
|
|
80
|
+
const data = await this.doRead(this.fullKey(pathKey, asBinary === true), asBinary);
|
|
81
|
+
return typeof data === "string" ? decodeAppData(data) : data;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Generic read/write application data storage.
|
|
86
|
+
*/
|
|
87
|
+
export class AppDataStorage extends ReadOnlyAppDataStorage {
|
|
88
|
+
/**
|
|
89
|
+
* Write application data to storage.
|
|
90
|
+
*
|
|
91
|
+
* @param pathKey
|
|
92
|
+
* Key relative to path.
|
|
93
|
+
*
|
|
94
|
+
* @param appData
|
|
95
|
+
* Application data to write.
|
|
96
|
+
*/
|
|
97
|
+
async write(pathKey, appData) {
|
|
98
|
+
const isBinary = appData instanceof Uint8Array;
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is determined by supports binary flag.
|
|
100
|
+
await this.doWrite(this.fullKey(pathKey, isBinary), (this.supportsBinary && isBinary ?
|
|
101
|
+
appData :
|
|
102
|
+
encodeAppData(appData)));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Delete application data from persistent storage.
|
|
106
|
+
*
|
|
107
|
+
* @param pathKey
|
|
108
|
+
* Key relative to path.
|
|
109
|
+
*
|
|
110
|
+
* @param asBinary
|
|
111
|
+
* True if key is to binary data, false or undefined if to string data. Ignored if binary data is not supported.
|
|
112
|
+
*/
|
|
113
|
+
async delete(pathKey, asBinary) {
|
|
114
|
+
await this.doDelete(this.fullKey(pathKey, asBinary === true));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=app-data-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-data-storage.js","sourceRoot":"","sources":["../src/app-data-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG3E;;GAEG;AACH,MAAM,OAAgB,sBAAsB;IACxC;;OAEG;IACO,MAAM,CAAU,gBAAgB,GAAG,MAAM,CAAC;IAEpD;;OAEG;IACO,MAAM,CAAU,cAAc,GAAG,OAAO,CAAC;IAEnD;;OAEG;IACM,eAAe,CAAiB;IAEzC;;OAEG;IACM,KAAK,CAAS;IAEvB;;;;;;;;OAQG;IACH,YAAsB,cAA8B,EAAE,IAAa;QAC/D,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED;;;;;;;;;;;OAWG;IACO,OAAO,CAAC,OAAe,EAAE,QAAiB;QAChD,MAAM,cAAc,GAAG,GAAG,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,CAAC;QAEhD,oDAAoD;QACpD,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC;YACxB,GAAG,cAAc,GAAG,QAAQ,CAAC,CAAC,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC,CAAC,sBAAsB,CAAC,cAAc,EAAE,CAAC,CAAC;YAClH,cAAc,CAAC;IACvB,CAAC;IAiBD;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,IAAI,CAAC,OAAe,EAAE,QAAkB;QAC1C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;QAEnF,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,CAAC;;AAGL;;GAEG;AACH,MAAM,OAAgB,cAA+C,SAAQ,sBAAsC;IAY/G;;;;;;;;OAQG;IACH,KAAK,CAAC,KAAK,CAAC,OAAe,EAAE,OAAgB;QACzC,MAAM,QAAQ,GAAG,OAAO,YAAY,UAAU,CAAC;QAE/C,sHAAsH;QACtH,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,IAAI,QAAQ,CAAC,CAAC;YAClF,OAAO,CAAC,CAAC;YACT,aAAa,CAAC,OAAO,CAAC,CACa,CAAC,CAAC;IAC7C,CAAC;IAUD;;;;;;;;OAQG;IACH,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,QAAkB;QAC5C,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC;IAClE,CAAC;CACJ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application data.
|
|
3
|
+
*/
|
|
4
|
+
export type AppData = string | number | boolean | object;
|
|
5
|
+
/**
|
|
6
|
+
* Decode application data from an encoded string.
|
|
7
|
+
*
|
|
8
|
+
* @param stringData
|
|
9
|
+
* String data.
|
|
10
|
+
*
|
|
11
|
+
* @returns
|
|
12
|
+
* Decoded application data.
|
|
13
|
+
*/
|
|
14
|
+
export declare function decodeAppData(stringData: string): AppData | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Encode application data as a string for storage. Encoded string is in JSON format with date/time and binary data
|
|
17
|
+
* converted to identifiable strings for decoding.
|
|
18
|
+
*
|
|
19
|
+
* @param appData
|
|
20
|
+
* Application data.
|
|
21
|
+
*
|
|
22
|
+
* @returns
|
|
23
|
+
* Encoded application data.
|
|
24
|
+
*/
|
|
25
|
+
export declare function encodeAppData(appData: AppData): string;
|
|
26
|
+
//# sourceMappingURL=app-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-data.d.ts","sourceRoot":"","sources":["../src/app-data.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAEzD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAqCrE;AA4BD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAEtD"}
|
package/dist/app-data.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { fromByteArray, toByteArray } from "base64-js";
|
|
2
|
+
/**
|
|
3
|
+
* Decode application data from an encoded string.
|
|
4
|
+
*
|
|
5
|
+
* @param stringData
|
|
6
|
+
* String data.
|
|
7
|
+
*
|
|
8
|
+
* @returns
|
|
9
|
+
* Decoded application data.
|
|
10
|
+
*/
|
|
11
|
+
export function decodeAppData(stringData) {
|
|
12
|
+
let decodedAppData;
|
|
13
|
+
try {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Mapping is expected to be correct.
|
|
15
|
+
decodedAppData = JSON.parse(stringData, (_key, value) => {
|
|
16
|
+
let replacementValue = value;
|
|
17
|
+
// Decode string representing date/time and binary array and pass through other values unmodified.
|
|
18
|
+
if (typeof value === "string") {
|
|
19
|
+
// First capture group is type, second is data; simple split at ':' character.
|
|
20
|
+
const stringDataGroups = /^(?<type>\w+):(?<data>.*)$/u.exec(value)?.groups;
|
|
21
|
+
if (stringDataGroups !== undefined) {
|
|
22
|
+
const type = stringDataGroups["type"];
|
|
23
|
+
const data = stringDataGroups["data"];
|
|
24
|
+
switch (type) {
|
|
25
|
+
case "dateTime":
|
|
26
|
+
replacementValue = new Date(data);
|
|
27
|
+
break;
|
|
28
|
+
case "binary":
|
|
29
|
+
replacementValue = toByteArray(data);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return replacementValue;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// String data is not valid JSON; discard it.
|
|
39
|
+
decodedAppData = undefined;
|
|
40
|
+
}
|
|
41
|
+
return decodedAppData;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Encode an object to a format suitable for storage.
|
|
45
|
+
*
|
|
46
|
+
* @param o
|
|
47
|
+
* Object.
|
|
48
|
+
*
|
|
49
|
+
* @returns
|
|
50
|
+
* Object suitable for storage with date/time and binary types encoded as strings.
|
|
51
|
+
*/
|
|
52
|
+
function encodeObject(o) {
|
|
53
|
+
let mappedData;
|
|
54
|
+
// Encode date/time and binary array as string and pass through other values unmodified.
|
|
55
|
+
if (o instanceof Date) {
|
|
56
|
+
mappedData = `dateTime:${o.toISOString()}`;
|
|
57
|
+
}
|
|
58
|
+
else if (o instanceof Uint8Array) {
|
|
59
|
+
mappedData = `binary:${fromByteArray(o)}`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
mappedData = Object.fromEntries(Object.entries(o).map(([key, value]) => [key, typeof value === "object" && value !== null ? encodeObject(value) : value]));
|
|
63
|
+
}
|
|
64
|
+
return mappedData;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Encode application data as a string for storage. Encoded string is in JSON format with date/time and binary data
|
|
68
|
+
* converted to identifiable strings for decoding.
|
|
69
|
+
*
|
|
70
|
+
* @param appData
|
|
71
|
+
* Application data.
|
|
72
|
+
*
|
|
73
|
+
* @returns
|
|
74
|
+
* Encoded application data.
|
|
75
|
+
*/
|
|
76
|
+
export function encodeAppData(appData) {
|
|
77
|
+
return JSON.stringify(typeof appData !== "object" ? appData : encodeObject(appData));
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=app-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-data.js","sourceRoot":"","sources":["../src/app-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAOvD;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB;IAC5C,IAAI,cAAmC,CAAC;IAExC,IAAI,CAAC;QACD,6GAA6G;QAC7G,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,KAAc,EAAE,EAAE;YAC7D,IAAI,gBAAgB,GAAG,KAAK,CAAC;YAE7B,kGAAkG;YAClG,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC5B,8EAA8E;gBAC9E,MAAM,gBAAgB,GAAG,6BAA6B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;gBAE3E,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;oBACjC,MAAM,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;oBACtC,MAAM,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;oBAEtC,QAAQ,IAAI,EAAE,CAAC;wBACX,KAAK,UAAU;4BACX,gBAAgB,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;4BAClC,MAAM;wBAEV,KAAK,QAAQ;4BACT,gBAAgB,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;4BACrC,MAAM;oBACd,CAAC;gBACL,CAAC;YACL,CAAC;YAED,OAAO,gBAAgB,CAAC;QAC5B,CAAC,CAAY,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACL,6CAA6C;QAC7C,cAAc,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,OAAO,cAAc,CAAC;AAC1B,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,YAAY,CAAC,CAAS;IAC3B,IAAI,UAA2B,CAAC;IAEhC,wFAAwF;IACxF,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC;QACpB,UAAU,GAAG,YAAY,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;IAC/C,CAAC;SAAM,IAAI,CAAC,YAAY,UAAU,EAAE,CAAC;QACjC,UAAU,GAAG,UAAU,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,CAAC;SAAM,CAAC;QACJ,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAoB,EAAE,EAAE,CACtF,CAAC,GAAG,EAAE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CACnF,CAAC,CAAC;IACP,CAAC;IAED,OAAO,UAAU,CAAC;AACtB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AppDataStorage } from "./app-data-storage.js";
|
|
2
|
+
/**
|
|
3
|
+
* Application data storage using the browser local storage.
|
|
4
|
+
*/
|
|
5
|
+
export declare class BrowserAppDataStorage extends AppDataStorage<false> {
|
|
6
|
+
/**
|
|
7
|
+
* Constructor.
|
|
8
|
+
*
|
|
9
|
+
* @param path
|
|
10
|
+
* Storage path prepended to each key along with '/' if defined, empty string if not.
|
|
11
|
+
*/
|
|
12
|
+
constructor(path?: string);
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
protected doRead(key: string): string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
protected doWrite(key: string, s: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
protected doDelete(key: string): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=browser-app-data-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-app-data-storage.d.ts","sourceRoot":"","sources":["../src/browser-app-data-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,cAAc,CAAC,KAAK,CAAC;IAC5D;;;;;OAKG;gBACS,IAAI,CAAC,EAAE,MAAM;IAIzB;;OAEG;cACgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI1D;;OAEG;cACgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAIxD;;OAEG;cACgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAGjD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AppDataStorage } from "./app-data-storage.js";
|
|
2
|
+
/**
|
|
3
|
+
* Application data storage using the browser local storage.
|
|
4
|
+
*/
|
|
5
|
+
export class BrowserAppDataStorage extends AppDataStorage {
|
|
6
|
+
/**
|
|
7
|
+
* Constructor.
|
|
8
|
+
*
|
|
9
|
+
* @param path
|
|
10
|
+
* Storage path prepended to each key along with '/' if defined, empty string if not.
|
|
11
|
+
*/
|
|
12
|
+
constructor(path) {
|
|
13
|
+
super(false, path);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
doRead(key) {
|
|
19
|
+
return localStorage.getItem(key) ?? undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
doWrite(key, s) {
|
|
25
|
+
localStorage.setItem(key, s);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
doDelete(key) {
|
|
31
|
+
localStorage.removeItem(key);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=browser-app-data-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-app-data-storage.js","sourceRoot":"","sources":["../src/browser-app-data-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,cAAqB;IAC5D;;;;;OAKG;IACH,YAAY,IAAa;QACrB,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED;;OAEG;IACgB,MAAM,CAAC,GAAW;QACjC,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;IAClD,CAAC;IAED;;OAEG;IACgB,OAAO,CAAC,GAAW,EAAE,CAAS;QAC7C,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACgB,QAAQ,CAAC,GAAW;QACnC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACJ"}
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Promisable } from "./type.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generic cache. Typically used to manage a local copy of remote data that is not refreshed regularly.
|
|
4
|
+
*
|
|
5
|
+
* @template TCache
|
|
6
|
+
* Type of cached data.
|
|
7
|
+
*
|
|
8
|
+
* @template TSource
|
|
9
|
+
* Type of source data. The type may be different from the cached data type if a transformation is required.
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class Cache<TCache, TSource = TCache> {
|
|
12
|
+
/**
|
|
13
|
+
* Get the date/time at or after which the source should be checked for updates. If the value is undefined, this is
|
|
14
|
+
* the first usage.
|
|
15
|
+
*/
|
|
16
|
+
abstract get nextCheckDateTime(): Promisable<Date | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Get the date/time at which the cache was last updated. This may more accurately reflect the date/time at which
|
|
19
|
+
* the last source retrieved was updated. If the value is undefined, there is no data in the cache.
|
|
20
|
+
*/
|
|
21
|
+
abstract get cacheDateTime(): Promisable<Date | undefined>;
|
|
22
|
+
/**
|
|
23
|
+
* Get the cache data. This should only ever be called if the cache date/time is defined.
|
|
24
|
+
*/
|
|
25
|
+
abstract get cacheData(): Promisable<TCache>;
|
|
26
|
+
/**
|
|
27
|
+
* Get the date/time at which the source was last updated. This should not be called unless the next check date/time
|
|
28
|
+
* has passed, as it may trigger an expensive remote retrieval.
|
|
29
|
+
*/
|
|
30
|
+
abstract get sourceDateTime(): Promisable<Date>;
|
|
31
|
+
/**
|
|
32
|
+
* Get the source data. This should not be called unless the next check date/time has passed, as it may trigger an
|
|
33
|
+
* expensive remote retrieval.
|
|
34
|
+
*/
|
|
35
|
+
abstract get sourceData(): Promisable<TSource>;
|
|
36
|
+
/**
|
|
37
|
+
* Update the cache with only the next check date/time. The cache date/time and cache data must not be modified.
|
|
38
|
+
* This is typically called when the cache is up to date with the source or source retrieval has failed.
|
|
39
|
+
*
|
|
40
|
+
* @param nextCheckDateTime
|
|
41
|
+
* Next check date/time.
|
|
42
|
+
*/
|
|
43
|
+
abstract update(nextCheckDateTime: Date): Promisable<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Update all cache parameters. This is typically called when the cache is updated from the source.
|
|
46
|
+
*
|
|
47
|
+
* @param nextCheckDateTime
|
|
48
|
+
* Next check date/time.
|
|
49
|
+
*
|
|
50
|
+
* @param cacheDateTime
|
|
51
|
+
* Cache date/time.
|
|
52
|
+
*
|
|
53
|
+
* @param cacheData
|
|
54
|
+
* Cache data.
|
|
55
|
+
*/
|
|
56
|
+
abstract update(nextCheckDateTime: Date, cacheDateTime: Date, cacheData: TCache): Promisable<void>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;;;;;;;GAQG;AACH,8BAAsB,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM;IAChD;;;OAGG;IACH,QAAQ,KAAK,iBAAiB,IAAI,UAAU,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IAE/D;;;OAGG;IACH,QAAQ,KAAK,aAAa,IAAI,UAAU,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IAE3D;;OAEG;IACH,QAAQ,KAAK,SAAS,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAE7C;;;OAGG;IACH,QAAQ,KAAK,cAAc,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAEhD;;;OAGG;IACH,QAAQ,KAAK,UAAU,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IAE/C;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAE1D;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC;CACrG"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic cache. Typically used to manage a local copy of remote data that is not refreshed regularly.
|
|
3
|
+
*
|
|
4
|
+
* @template TCache
|
|
5
|
+
* Type of cached data.
|
|
6
|
+
*
|
|
7
|
+
* @template TSource
|
|
8
|
+
* Type of source data. The type may be different from the cached data type if a transformation is required.
|
|
9
|
+
*/
|
|
10
|
+
export class Cache {
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,OAAgB,KAAK;CAoD1B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AppDataStorage } from "./app-data-storage.js";
|
|
2
|
+
/**
|
|
3
|
+
* Application data storage using the file system.
|
|
4
|
+
*/
|
|
5
|
+
export declare class FileAppDataStorage extends AppDataStorage<true> {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Constructor.
|
|
9
|
+
*
|
|
10
|
+
* @param path
|
|
11
|
+
* Storage path prepended to each key along with '/' if defined, empty string if not.
|
|
12
|
+
*/
|
|
13
|
+
constructor(path?: string);
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
protected doRead(key: string, asBinary: boolean | undefined): Promise<string | Uint8Array | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
protected doWrite(key: string, data: string | Uint8Array): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
protected doDelete(key: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=file-app-data-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-app-data-storage.d.ts","sourceRoot":"","sources":["../src/file-app-data-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,cAAc,CAAC,IAAI,CAAC;;IAMxD;;;;;OAKG;gBACS,IAAI,CAAC,EAAE,MAAM;IAOzB;;OAEG;cACsB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;IAUrH;;OAEG;cACsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvF;;OAEG;cACsB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOhE"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { AppDataStorage } from "./app-data-storage.js";
|
|
4
|
+
/**
|
|
5
|
+
* Application data storage using the file system.
|
|
6
|
+
*/
|
|
7
|
+
export class FileAppDataStorage extends AppDataStorage {
|
|
8
|
+
/**
|
|
9
|
+
* If true, node:fs has been polyfilled with empty object.
|
|
10
|
+
*/
|
|
11
|
+
#isNoOp;
|
|
12
|
+
/**
|
|
13
|
+
* Constructor.
|
|
14
|
+
*
|
|
15
|
+
* @param path
|
|
16
|
+
* Storage path prepended to each key along with '/' if defined, empty string if not.
|
|
17
|
+
*/
|
|
18
|
+
constructor(path) {
|
|
19
|
+
super(true, path);
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Condition is true in polyfilled environment.
|
|
21
|
+
this.#isNoOp = fs?.promises?.readFile === undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
async doRead(key, asBinary) {
|
|
27
|
+
return !this.#isNoOp ?
|
|
28
|
+
fs.promises.readFile(key).then(buffer => asBinary === true ? buffer : buffer.toString()).catch(() => undefined) :
|
|
29
|
+
undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
async doWrite(key, data) {
|
|
35
|
+
return !this.#isNoOp ?
|
|
36
|
+
fs.promises.mkdir(path.dirname(key), {
|
|
37
|
+
recursive: true
|
|
38
|
+
}).then(async () => fs.promises.writeFile(key, data)) :
|
|
39
|
+
undefined;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @inheritDoc
|
|
43
|
+
*/
|
|
44
|
+
async doDelete(key) {
|
|
45
|
+
return !this.#isNoOp ?
|
|
46
|
+
fs.promises.rm(key, {
|
|
47
|
+
force: true
|
|
48
|
+
}) :
|
|
49
|
+
undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=file-app-data-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-app-data-storage.js","sourceRoot":"","sources":["../src/file-app-data-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,cAAoB;IACxD;;OAEG;IACM,OAAO,CAAU;IAE1B;;;;;OAKG;IACH,YAAY,IAAa;QACrB,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAElB,uHAAuH;QACvH,IAAI,CAAC,OAAO,GAAG,EAAE,EAAE,QAAQ,EAAE,QAAQ,KAAK,SAAS,CAAC;IACxD,CAAC;IAED;;OAEG;IACgB,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,QAA6B;QACtE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAClB,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CACpC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CACjD,CAAC,KAAK,CAAC,GAAG,EAAE,CACT,SAAS,CACZ,CAAC,CAAC;YACH,SAAS,CAAC;IAClB,CAAC;IAED;;OAEG;IACgB,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,IAAyB;QACnE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAClB,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBACjC,SAAS,EAAE,IAAI;aAClB,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CACf,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CACnC,CAAC,CAAC;YACH,SAAS,CAAC;IAClB,CAAC;IAED;;OAEG;IACgB,KAAK,CAAC,QAAQ,CAAC,GAAW;QACzC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAClB,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE;gBAChB,KAAK,EAAE,IAAI;aACd,CAAC,CAAC,CAAC;YACJ,SAAS,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Promisable } from "./type.js";
|
|
2
|
+
/**
|
|
3
|
+
* HTTP status code for OK.
|
|
4
|
+
*/
|
|
5
|
+
export declare const HTTP_OK = 200;
|
|
6
|
+
/**
|
|
7
|
+
* HTTP status code for not found.
|
|
8
|
+
*/
|
|
9
|
+
export declare const HTTP_NOT_FOUND = 404;
|
|
10
|
+
/**
|
|
11
|
+
* Generic HTTP response.
|
|
12
|
+
*/
|
|
13
|
+
export interface HTTPResponse {
|
|
14
|
+
/**
|
|
15
|
+
* True if OK.
|
|
16
|
+
*/
|
|
17
|
+
readonly ok: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* HTTP status code.
|
|
20
|
+
*/
|
|
21
|
+
readonly status: number;
|
|
22
|
+
/**
|
|
23
|
+
* Body as array buffer.
|
|
24
|
+
*/
|
|
25
|
+
readonly arrayBuffer: () => Promisable<ArrayBuffer>;
|
|
26
|
+
/**
|
|
27
|
+
* Body as text.
|
|
28
|
+
*/
|
|
29
|
+
readonly text: () => Promisable<string>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* HTTP fetch function.
|
|
33
|
+
*/
|
|
34
|
+
export type HTTPFetch = (url: string) => Promisable<HTTPResponse>;
|
|
35
|
+
/**
|
|
36
|
+
* Default HTTP fetch function using global `fetch` function.
|
|
37
|
+
*
|
|
38
|
+
* @param url
|
|
39
|
+
* URL.
|
|
40
|
+
*
|
|
41
|
+
* @returns
|
|
42
|
+
* HTTP response.
|
|
43
|
+
*/
|
|
44
|
+
export declare function defaultHTTPFetch(url: string): Promise<HTTPResponse>;
|
|
45
|
+
//# sourceMappingURL=http-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-fetch.d.ts","sourceRoot":"","sources":["../src/http-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,OAAO,MAAM,CAAC;AAE3B;;GAEG;AACH,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,UAAU,CAAC,WAAW,CAAC,CAAC;IAEpD;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,CAAC,YAAY,CAAC,CAAC;AAElE;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAOzE"}
|