@aidc-toolkit/core 1.0.41 → 1.0.43-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
package/dist/logger.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { Logger } from "tslog";
|
|
2
|
+
import { i18nextCore } from "./locale/i18n.js";
|
|
3
|
+
/**
|
|
4
|
+
* Log levels.
|
|
5
|
+
*/
|
|
6
|
+
export const LogLevels = {
|
|
7
|
+
Silly: 0,
|
|
8
|
+
Trace: 1,
|
|
9
|
+
Debug: 2,
|
|
10
|
+
Info: 3,
|
|
11
|
+
Warn: 4,
|
|
12
|
+
Error: 5,
|
|
13
|
+
Fatal: 6
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Get the log level enumeration value corresponding to a string or number.
|
|
17
|
+
*
|
|
18
|
+
* @param untypedLogLevel
|
|
19
|
+
* Untyped log level.
|
|
20
|
+
*
|
|
21
|
+
* @returns
|
|
22
|
+
* Typed log level or default `LogLevels.Info` if untyped log level not provided..
|
|
23
|
+
*/
|
|
24
|
+
export function logLevelOf(untypedLogLevel) {
|
|
25
|
+
let typedLogLevel;
|
|
26
|
+
if (typeof untypedLogLevel === "string") {
|
|
27
|
+
if (untypedLogLevel in LogLevels) {
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- String exists as a key.
|
|
29
|
+
typedLogLevel = LogLevels[untypedLogLevel];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new RangeError(i18nextCore.t("Logger.unknownLogLevel", {
|
|
33
|
+
logLevel: untypedLogLevel
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (untypedLogLevel !== undefined) {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Assume that valid log level has been provided.
|
|
39
|
+
if (Object.values(LogLevels).includes(untypedLogLevel)) {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Valid log level has been provided.
|
|
41
|
+
typedLogLevel = untypedLogLevel;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw new RangeError(i18nextCore.t("Logger.unknownLogLevel", {
|
|
45
|
+
logLevel: untypedLogLevel
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
typedLogLevel = LogLevels.Info;
|
|
51
|
+
}
|
|
52
|
+
return typedLogLevel;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get a logger with an optional log level. The underlying implementation is
|
|
56
|
+
* [`tslog`](https://tslog.js.org/).
|
|
57
|
+
*
|
|
58
|
+
* @param logLevel
|
|
59
|
+
* Log level as enumeration value or string. Mapped to `minLevel` and sets `hideLogPositionForProduction` to true in
|
|
60
|
+
* settings if at {@linkcode LogLevels.Info} or higher. Default is {@linkcode LogLevels.Info}.
|
|
61
|
+
*
|
|
62
|
+
* @param settings
|
|
63
|
+
* Detailed settings. See [`tslog`](https://tslog.js.org/#/?id=settings) documentation for details. The `minLevel` is
|
|
64
|
+
* ignored in favour of `logLevel` but `hideLogPositionForProduction` will override the default logic.
|
|
65
|
+
*
|
|
66
|
+
* @param logObj
|
|
67
|
+
* Default log object. See [`tslog`](https://tslog.js.org/#/?id=defining-and-accessing-logobj) documentation for
|
|
68
|
+
* details.
|
|
69
|
+
*
|
|
70
|
+
* @returns
|
|
71
|
+
* Logger.
|
|
72
|
+
*
|
|
73
|
+
* @template T
|
|
74
|
+
* Log object type.
|
|
75
|
+
*/
|
|
76
|
+
export function getLogger(logLevel, settings, logObj) {
|
|
77
|
+
const minLevel = logLevelOf(logLevel);
|
|
78
|
+
return new Logger({
|
|
79
|
+
// Hiding log position for production can be overridden in settings parameter.
|
|
80
|
+
hideLogPositionForProduction: minLevel >= LogLevels.Info,
|
|
81
|
+
...settings ?? {},
|
|
82
|
+
// Minimum log level overrides settings parameter.
|
|
83
|
+
minLevel
|
|
84
|
+
}, logObj);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get a loggable representation of a value. Values are returned unmodified, except as follows:
|
|
88
|
+
*
|
|
89
|
+
* - Big integers are converted to whole numbers where possible, otherwise as their decimal string representations.
|
|
90
|
+
* - Arrays are limited to a maximum of ten elements. Any array longer than ten elements is replaced with the first four
|
|
91
|
+
* elements, a string of three dots, and the last four elements. This may still create large results for
|
|
92
|
+
* multidimensional arrays.
|
|
93
|
+
* - Errors are converted to objects with `name`, `message`, and `stack` properties.
|
|
94
|
+
* - Symbols are converted to their string representations.
|
|
95
|
+
* - Functions are converted to strings of the form `Function(name)`.
|
|
96
|
+
*
|
|
97
|
+
* @param value
|
|
98
|
+
* Value.
|
|
99
|
+
*
|
|
100
|
+
* @returns
|
|
101
|
+
* Loggable value.
|
|
102
|
+
*/
|
|
103
|
+
export function loggableValue(value) {
|
|
104
|
+
let replacementValue;
|
|
105
|
+
switch (typeof value) {
|
|
106
|
+
case "string":
|
|
107
|
+
case "number":
|
|
108
|
+
case "boolean":
|
|
109
|
+
case "undefined":
|
|
110
|
+
replacementValue = value;
|
|
111
|
+
break;
|
|
112
|
+
case "bigint":
|
|
113
|
+
// Big integers not supported in JSON.
|
|
114
|
+
replacementValue = value >= Number.MIN_SAFE_INTEGER && value <= Number.MAX_SAFE_INTEGER ? Number(value) : value.toString(10);
|
|
115
|
+
break;
|
|
116
|
+
case "object":
|
|
117
|
+
if (value === null) {
|
|
118
|
+
replacementValue = value;
|
|
119
|
+
}
|
|
120
|
+
else if (Array.isArray(value)) {
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Slicing array is necessary to keep log size down.
|
|
122
|
+
replacementValue = (value.length <= 10 ? value : [...value.slice(0, 4), "...", ...value.slice(-4)]).map(entry => loggableValue(entry));
|
|
123
|
+
}
|
|
124
|
+
else if (value instanceof Error) {
|
|
125
|
+
replacementValue = loggableValue({
|
|
126
|
+
name: value.name,
|
|
127
|
+
message: value.message,
|
|
128
|
+
stack: value.stack?.split("\n")
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// Apply recursively to all properties of the object.
|
|
133
|
+
replacementValue = Object.fromEntries(Object.entries(value).map(([k, v]) => [k, loggableValue(v)]));
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case "symbol":
|
|
137
|
+
replacementValue = value.toString();
|
|
138
|
+
break;
|
|
139
|
+
case "function":
|
|
140
|
+
replacementValue = `Function(${value.name})`;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
return replacementValue;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Logger transport that stores messages in memory.
|
|
147
|
+
*/
|
|
148
|
+
export class MemoryTransport {
|
|
149
|
+
/**
|
|
150
|
+
* Notification callbacks map.
|
|
151
|
+
*/
|
|
152
|
+
#notificationCallbacksMap = new Map();
|
|
153
|
+
/**
|
|
154
|
+
* Messages.
|
|
155
|
+
*/
|
|
156
|
+
#messages = [];
|
|
157
|
+
/**
|
|
158
|
+
* Maximum length of messages array.
|
|
159
|
+
*/
|
|
160
|
+
#maximumLength = 0;
|
|
161
|
+
/**
|
|
162
|
+
* Length to which messages array is truncated when maximum is reached.
|
|
163
|
+
*/
|
|
164
|
+
#truncateLength = 0;
|
|
165
|
+
/**
|
|
166
|
+
* Constructor.
|
|
167
|
+
*
|
|
168
|
+
* @param logger
|
|
169
|
+
* Logger.
|
|
170
|
+
*
|
|
171
|
+
* @param maximumLength
|
|
172
|
+
* Maximum length of messages array.
|
|
173
|
+
*
|
|
174
|
+
* @param truncateLength
|
|
175
|
+
* Length to which messages array is truncated when maximum is reached. Default is 50% of `maximumLength`, maximum
|
|
176
|
+
* is 80% of `maximumLength`.
|
|
177
|
+
*/
|
|
178
|
+
constructor(logger, maximumLength, truncateLength) {
|
|
179
|
+
this.resize(maximumLength, truncateLength);
|
|
180
|
+
logger.attachTransport((logObject) => {
|
|
181
|
+
// Truncate logger messages if necessary.
|
|
182
|
+
if (this.#messages.length >= this.#maximumLength) {
|
|
183
|
+
this.#messages.splice(0, this.#maximumLength - this.#truncateLength);
|
|
184
|
+
}
|
|
185
|
+
const message = JSON.stringify(logObject);
|
|
186
|
+
this.#messages.push(message);
|
|
187
|
+
// Notify all registered callbacks.
|
|
188
|
+
for (const notificationCallback of this.#notificationCallbacksMap.values()) {
|
|
189
|
+
notificationCallback(message, this.#messages);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get the messages.
|
|
195
|
+
*/
|
|
196
|
+
get messages() {
|
|
197
|
+
return this.#messages;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get the maximum length of messages array.
|
|
201
|
+
*/
|
|
202
|
+
get maximumLength() {
|
|
203
|
+
return this.#maximumLength;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Get the length to which messages array is truncated when maximum is reached.
|
|
207
|
+
*/
|
|
208
|
+
get truncateLength() {
|
|
209
|
+
return this.#truncateLength;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Add a notification callback. If one already exists under the current name, do nothing.
|
|
213
|
+
*
|
|
214
|
+
* @param name
|
|
215
|
+
* Callback name.
|
|
216
|
+
*
|
|
217
|
+
* @param notificationCallback
|
|
218
|
+
* Callback.
|
|
219
|
+
*
|
|
220
|
+
* @returns
|
|
221
|
+
* True if successfully added.
|
|
222
|
+
*/
|
|
223
|
+
addNotificationCallback(name, notificationCallback) {
|
|
224
|
+
const added = !this.#notificationCallbacksMap.has(name);
|
|
225
|
+
if (added) {
|
|
226
|
+
this.#notificationCallbacksMap.set(name, notificationCallback);
|
|
227
|
+
// Notify with existing messages.
|
|
228
|
+
notificationCallback(undefined, this.#messages);
|
|
229
|
+
}
|
|
230
|
+
return added;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Remove a notification callback.
|
|
234
|
+
*
|
|
235
|
+
* @param name
|
|
236
|
+
* Callback name.
|
|
237
|
+
*/
|
|
238
|
+
removeNotificationCallback(name) {
|
|
239
|
+
this.#notificationCallbacksMap.delete(name);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Resize the messages array.
|
|
243
|
+
*
|
|
244
|
+
* @param maximumLength
|
|
245
|
+
* Maximum length of messages array.
|
|
246
|
+
*
|
|
247
|
+
* @param truncateLength
|
|
248
|
+
* Length to which messages array is truncated when maximum is reached. Default is 50% of `maximumLength`, maximum
|
|
249
|
+
* is 80% of `maximumLength`.
|
|
250
|
+
*/
|
|
251
|
+
resize(maximumLength, truncateLength) {
|
|
252
|
+
this.#maximumLength = maximumLength;
|
|
253
|
+
this.#truncateLength = truncateLength !== undefined ? Math.min(truncateLength, Math.floor(maximumLength * 0.8)) : Math.floor(maximumLength / 2);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,MAAM,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACrB,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;CACF,CAAC;AAYX;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,eAAiC;IACxD,IAAI,aAAuB,CAAC;IAE5B,IAAI,OAAO,eAAe,KAAK,QAAQ,EAAE,CAAC;QACtC,IAAI,eAAe,IAAI,SAAS,EAAE,CAAC;YAC/B,kGAAkG;YAClG,aAAa,GAAG,SAAS,CAAC,eAA8B,CAAC,CAAC;QAC9D,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,wBAAwB,EAAE;gBACzD,QAAQ,EAAE,eAAe;aAC5B,CAAC,CAAC,CAAC;QACR,CAAC;IACL,CAAC;SAAM,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QACvC,yHAAyH;QACzH,IAAI,MAAM,CAAC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;;;OAWG;IACH,uBAAuB,CAAC,IAAY,EAAE,oBAAwF;QAC1H,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAExD,IAAI,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;YAE/D,iCAAiC;YACjC,oBAAoB,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,0BAA0B,CAAC,IAAY;QACnC,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,aAAqB,EAAE,cAAuB;QACjD,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,eAAe,GAAG,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;IACpJ,CAAC;CACJ"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsed version.
|
|
3
|
+
*/
|
|
4
|
+
export interface ParsedVersion {
|
|
5
|
+
/**
|
|
6
|
+
* Major version.
|
|
7
|
+
*/
|
|
8
|
+
readonly majorVersion: number;
|
|
9
|
+
/**
|
|
10
|
+
* Minor version.
|
|
11
|
+
*/
|
|
12
|
+
readonly minorVersion: number;
|
|
13
|
+
/**
|
|
14
|
+
* Patch version.
|
|
15
|
+
*/
|
|
16
|
+
readonly patchVersion: number;
|
|
17
|
+
/**
|
|
18
|
+
* Pre-release identifier.
|
|
19
|
+
*/
|
|
20
|
+
readonly preReleaseIdentifier: string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Date/time included with pre-release identifier.
|
|
23
|
+
*/
|
|
24
|
+
readonly dateTime: string | undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parse version.
|
|
28
|
+
*
|
|
29
|
+
* @param version
|
|
30
|
+
* Version, typically from package.json.
|
|
31
|
+
*
|
|
32
|
+
* @returns
|
|
33
|
+
* Parsed version.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseVersion(version: string): ParsedVersion;
|
|
36
|
+
//# sourceMappingURL=parse-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-version.d.ts","sourceRoot":"","sources":["../src/parse-version.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IAElD;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAc3D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse version.
|
|
3
|
+
*
|
|
4
|
+
* @param version
|
|
5
|
+
* Version, typically from package.json.
|
|
6
|
+
*
|
|
7
|
+
* @returns
|
|
8
|
+
* Parsed version.
|
|
9
|
+
*/
|
|
10
|
+
export function parseVersion(version) {
|
|
11
|
+
const parsedVersionGroups = /^(?<majorVersion>\d+)\.(?<minorVersion>\d+)\.(?<patchVersion>\d+)(?:-(?<preReleaseIdentifier>alpha|beta)(?:\.(?<dateTime>\d{12}))?)?$/u.exec(version)?.groups;
|
|
12
|
+
if (parsedVersionGroups === undefined) {
|
|
13
|
+
throw new Error(`Invalid package version ${version}`);
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
majorVersion: Number(parsedVersionGroups["majorVersion"]),
|
|
17
|
+
minorVersion: Number(parsedVersionGroups["minorVersion"]),
|
|
18
|
+
patchVersion: Number(parsedVersionGroups["patchVersion"]),
|
|
19
|
+
preReleaseIdentifier: parsedVersionGroups["preReleaseIdentifier"],
|
|
20
|
+
dateTime: parsedVersionGroups["dateTime"]
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=parse-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-version.js","sourceRoot":"","sources":["../src/parse-version.ts"],"names":[],"mappings":"AA8BA;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IACxC,MAAM,mBAAmB,GAAG,wIAAwI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAE3L,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO;QACH,YAAY,EAAE,MAAM,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;QACzD,YAAY,EAAE,MAAM,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;QACzD,YAAY,EAAE,MAAM,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;QACzD,oBAAoB,EAAE,mBAAmB,CAAC,sBAAsB,CAAC;QACjE,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC;KAC5C,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReadOnlyAppDataStorage } from "./app-data-storage.js";
|
|
2
|
+
import { type HTTPFetch } from "./http-fetch.js";
|
|
3
|
+
/**
|
|
4
|
+
* Remote application data storage using HTTP.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RemoteAppDataStorage extends ReadOnlyAppDataStorage<true> {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Constructor.
|
|
10
|
+
*
|
|
11
|
+
* @param baseURL
|
|
12
|
+
* Base URL. The URL must not end with a slash.
|
|
13
|
+
*
|
|
14
|
+
* @param httpFetch
|
|
15
|
+
* HTTP fetch function.
|
|
16
|
+
*/
|
|
17
|
+
constructor(baseURL: string, httpFetch?: HTTPFetch);
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
protected doRead(key: string, asBinary: boolean | undefined): Promise<string | Uint8Array | undefined>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=remote-app-data-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-app-data-storage.d.ts","sourceRoot":"","sources":["../src/remote-app-data-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGnF;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,sBAAsB,CAAC,IAAI,CAAC;;IAGlE;;;;;;;;OAQG;gBACS,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,SAA4B;IAMpE;;OAEG;cACsB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;CAiBxH"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ReadOnlyAppDataStorage } from "./app-data-storage.js";
|
|
2
|
+
import { defaultHTTPFetch, HTTP_NOT_FOUND } from "./http-fetch.js";
|
|
3
|
+
import { i18nextCore } from "./locale/i18n.js";
|
|
4
|
+
/**
|
|
5
|
+
* Remote application data storage using HTTP.
|
|
6
|
+
*/
|
|
7
|
+
export class RemoteAppDataStorage extends ReadOnlyAppDataStorage {
|
|
8
|
+
#httpFetch;
|
|
9
|
+
/**
|
|
10
|
+
* Constructor.
|
|
11
|
+
*
|
|
12
|
+
* @param baseURL
|
|
13
|
+
* Base URL. The URL must not end with a slash.
|
|
14
|
+
*
|
|
15
|
+
* @param httpFetch
|
|
16
|
+
* HTTP fetch function.
|
|
17
|
+
*/
|
|
18
|
+
constructor(baseURL, httpFetch = defaultHTTPFetch) {
|
|
19
|
+
super(true, baseURL);
|
|
20
|
+
this.#httpFetch = httpFetch;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
async doRead(key, asBinary) {
|
|
26
|
+
const response = await this.#httpFetch(key);
|
|
27
|
+
let result;
|
|
28
|
+
if (response.ok) {
|
|
29
|
+
result = asBinary === true ? new Uint8Array(await response.arrayBuffer()) : await response.text();
|
|
30
|
+
}
|
|
31
|
+
else if (response.status === HTTP_NOT_FOUND) {
|
|
32
|
+
result = undefined;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new RangeError(i18nextCore.t("RemoteAppDataStorage.httpError", {
|
|
36
|
+
status: response.status
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=remote-app-data-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-app-data-storage.js","sourceRoot":"","sources":["../src/remote-app-data-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAkB,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,sBAA4B;IACzD,UAAU,CAAY;IAE/B;;;;;;;;OAQG;IACH,YAAY,OAAe,EAAE,YAAuB,gBAAgB;QAChE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAErB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;OAEG;IACgB,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,QAA6B;QACtE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAE5C,IAAI,MAAuC,CAAC;QAE5C,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;YACd,MAAM,GAAG,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtG,CAAC;aAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;YAC5C,MAAM,GAAG,SAAS,CAAC;QACvB,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,gCAAgC,EAAE;gBACjE,MAAM,EAAE,QAAQ,CAAC,MAAM;aAC1B,CAAC,CAAC,CAAC;QACR,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create an object with omitted entries.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* Object type.
|
|
6
|
+
*
|
|
7
|
+
* @template K
|
|
8
|
+
* Object key type.
|
|
9
|
+
*
|
|
10
|
+
* @param o
|
|
11
|
+
* Object.
|
|
12
|
+
*
|
|
13
|
+
* @param keys
|
|
14
|
+
* Keys to omit.
|
|
15
|
+
*
|
|
16
|
+
* @returns
|
|
17
|
+
* Edited object.
|
|
18
|
+
*/
|
|
19
|
+
export declare function omit<T extends object, K extends keyof T>(o: T, ...keys: K[]): Omit<T, K>;
|
|
20
|
+
/**
|
|
21
|
+
* Create an object with picked entries.
|
|
22
|
+
*
|
|
23
|
+
* @template T
|
|
24
|
+
* Object type.
|
|
25
|
+
*
|
|
26
|
+
* @template K
|
|
27
|
+
* Object key type.
|
|
28
|
+
*
|
|
29
|
+
* @param o
|
|
30
|
+
* Object.
|
|
31
|
+
*
|
|
32
|
+
* @param keys
|
|
33
|
+
* Keys to pick.
|
|
34
|
+
*
|
|
35
|
+
* @returns
|
|
36
|
+
* Edited object.
|
|
37
|
+
*/
|
|
38
|
+
export declare function pick<T extends object, K extends keyof T>(o: T, ...keys: K[]): Pick<T, K>;
|
|
39
|
+
/**
|
|
40
|
+
* Create an object from a wide object without entries matching those from a narrow object.
|
|
41
|
+
*
|
|
42
|
+
* @template TWide
|
|
43
|
+
* Wide object type.
|
|
44
|
+
*
|
|
45
|
+
* @template TNarrow
|
|
46
|
+
* Narrow object type.
|
|
47
|
+
*
|
|
48
|
+
* @template K
|
|
49
|
+
* Narrow object key type, subset of wide object key type.
|
|
50
|
+
*
|
|
51
|
+
* @param wide
|
|
52
|
+
* Wide object.
|
|
53
|
+
*
|
|
54
|
+
* @param narrow
|
|
55
|
+
* Narrow object.
|
|
56
|
+
*
|
|
57
|
+
* @returns
|
|
58
|
+
* Edited object.
|
|
59
|
+
*/
|
|
60
|
+
export declare function exclude<TWide extends TNarrow, TNarrow extends object, K extends keyof TNarrow>(wide: TWide, narrow: TNarrow): Omit<TWide, K>;
|
|
61
|
+
/**
|
|
62
|
+
* Create an object from a wide object with entries matching those from a narrow object.
|
|
63
|
+
*
|
|
64
|
+
* @template TWide
|
|
65
|
+
* Wide object type.
|
|
66
|
+
*
|
|
67
|
+
* @template TNarrow
|
|
68
|
+
* Narrow object type.
|
|
69
|
+
*
|
|
70
|
+
* @template K
|
|
71
|
+
* Narrow object key type, subset of wide object key type.
|
|
72
|
+
*
|
|
73
|
+
* @param wide
|
|
74
|
+
* Wide object.
|
|
75
|
+
*
|
|
76
|
+
* @param narrow
|
|
77
|
+
* Narrow object.
|
|
78
|
+
*
|
|
79
|
+
* @returns
|
|
80
|
+
* Edited object.
|
|
81
|
+
*/
|
|
82
|
+
export declare function include<TWide extends TNarrow, TNarrow extends object, K extends keyof TNarrow>(wide: TWide, narrow: TNarrow): Pick<TWide, K>;
|
|
83
|
+
/**
|
|
84
|
+
* Cast a property as a more narrow type.
|
|
85
|
+
*
|
|
86
|
+
* @template T
|
|
87
|
+
* Object type.
|
|
88
|
+
*
|
|
89
|
+
* @template K
|
|
90
|
+
* Object key type.
|
|
91
|
+
*
|
|
92
|
+
* @template TAsType
|
|
93
|
+
* Desired type.
|
|
94
|
+
*
|
|
95
|
+
* @param o
|
|
96
|
+
* Object.
|
|
97
|
+
*
|
|
98
|
+
* @param key
|
|
99
|
+
* Key of property to cast.
|
|
100
|
+
*
|
|
101
|
+
* @returns
|
|
102
|
+
* Single-key object with property cast as desired type.
|
|
103
|
+
*/
|
|
104
|
+
export declare function propertyAs<T extends object, K extends keyof T, TAsType extends T[K]>(o: T, key: K): Readonly<Omit<T, K> extends T ? Partial<Record<K, TAsType>> : Record<K, TAsType>>;
|
|
105
|
+
/**
|
|
106
|
+
* Determine if argument is nullish. Application extension may pass `null` or `undefined` to missing parameters.
|
|
107
|
+
*
|
|
108
|
+
* @param argument
|
|
109
|
+
* Argument.
|
|
110
|
+
*
|
|
111
|
+
* @returns
|
|
112
|
+
* True if argument is undefined or null.
|
|
113
|
+
*/
|
|
114
|
+
export declare function isNullish(argument: unknown): argument is null | undefined;
|
|
115
|
+
//# sourceMappingURL=type-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-helper.d.ts","sourceRoot":"","sources":["../src/type-helper.ts"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;;;;;GAiBG;AACH,w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;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,IAAI,GAAG,SAAS,CAEzE"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create an object with omitted or picked entries.
|
|
3
|
+
*
|
|
4
|
+
* @template Omitting
|
|
5
|
+
* Type representation of `omitting` parameter for return type determination.
|
|
6
|
+
*
|
|
7
|
+
* @template T
|
|
8
|
+
* Object type.
|
|
9
|
+
*
|
|
10
|
+
* @template K
|
|
11
|
+
* Object key type.
|
|
12
|
+
*
|
|
13
|
+
* @param omitting
|
|
14
|
+
* True if omitting.
|
|
15
|
+
*
|
|
16
|
+
* @param o
|
|
17
|
+
* Object.
|
|
18
|
+
*
|
|
19
|
+
* @param keys
|
|
20
|
+
* Keys to omit or pick.
|
|
21
|
+
*
|
|
22
|
+
* @returns
|
|
23
|
+
* Edited object.
|
|
24
|
+
*/
|
|
25
|
+
function omitOrPick(omitting, o, ...keys) {
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Key and value types are known.
|
|
27
|
+
return Object.fromEntries(Object.entries(o).filter(([key]) => keys.includes(key) !== omitting));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create an object with omitted entries.
|
|
31
|
+
*
|
|
32
|
+
* @template T
|
|
33
|
+
* Object type.
|
|
34
|
+
*
|
|
35
|
+
* @template K
|
|
36
|
+
* Object key type.
|
|
37
|
+
*
|
|
38
|
+
* @param o
|
|
39
|
+
* Object.
|
|
40
|
+
*
|
|
41
|
+
* @param keys
|
|
42
|
+
* Keys to omit.
|
|
43
|
+
*
|
|
44
|
+
* @returns
|
|
45
|
+
* Edited object.
|
|
46
|
+
*/
|
|
47
|
+
export function omit(o, ...keys) {
|
|
48
|
+
return omitOrPick(true, o, ...keys);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create an object with picked entries.
|
|
52
|
+
*
|
|
53
|
+
* @template T
|
|
54
|
+
* Object type.
|
|
55
|
+
*
|
|
56
|
+
* @template K
|
|
57
|
+
* Object key type.
|
|
58
|
+
*
|
|
59
|
+
* @param o
|
|
60
|
+
* Object.
|
|
61
|
+
*
|
|
62
|
+
* @param keys
|
|
63
|
+
* Keys to pick.
|
|
64
|
+
*
|
|
65
|
+
* @returns
|
|
66
|
+
* Edited object.
|
|
67
|
+
*/
|
|
68
|
+
export function pick(o, ...keys) {
|
|
69
|
+
return omitOrPick(false, o, ...keys);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create an object from a wide object without entries matching those from a narrow object.
|
|
73
|
+
*
|
|
74
|
+
* @template TWide
|
|
75
|
+
* Wide object type.
|
|
76
|
+
*
|
|
77
|
+
* @template TNarrow
|
|
78
|
+
* Narrow object type.
|
|
79
|
+
*
|
|
80
|
+
* @template K
|
|
81
|
+
* Narrow object key type, subset of wide object key type.
|
|
82
|
+
*
|
|
83
|
+
* @param wide
|
|
84
|
+
* Wide object.
|
|
85
|
+
*
|
|
86
|
+
* @param narrow
|
|
87
|
+
* Narrow object.
|
|
88
|
+
*
|
|
89
|
+
* @returns
|
|
90
|
+
* Edited object.
|
|
91
|
+
*/
|
|
92
|
+
export function exclude(wide, narrow) {
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Keys are valid.
|
|
94
|
+
return omit(wide, ...Object.keys(narrow));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Create an object from a wide object with entries matching those from a narrow object.
|
|
98
|
+
*
|
|
99
|
+
* @template TWide
|
|
100
|
+
* Wide object type.
|
|
101
|
+
*
|
|
102
|
+
* @template TNarrow
|
|
103
|
+
* Narrow object type.
|
|
104
|
+
*
|
|
105
|
+
* @template K
|
|
106
|
+
* Narrow object key type, subset of wide object key type.
|
|
107
|
+
*
|
|
108
|
+
* @param wide
|
|
109
|
+
* Wide object.
|
|
110
|
+
*
|
|
111
|
+
* @param narrow
|
|
112
|
+
* Narrow object.
|
|
113
|
+
*
|
|
114
|
+
* @returns
|
|
115
|
+
* Edited object.
|
|
116
|
+
*/
|
|
117
|
+
export function include(wide, narrow) {
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Keys are valid.
|
|
119
|
+
return pick(wide, ...Object.keys(narrow));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Cast a property as a more narrow type.
|
|
123
|
+
*
|
|
124
|
+
* @template T
|
|
125
|
+
* Object type.
|
|
126
|
+
*
|
|
127
|
+
* @template K
|
|
128
|
+
* Object key type.
|
|
129
|
+
*
|
|
130
|
+
* @template TAsType
|
|
131
|
+
* Desired type.
|
|
132
|
+
*
|
|
133
|
+
* @param o
|
|
134
|
+
* Object.
|
|
135
|
+
*
|
|
136
|
+
* @param key
|
|
137
|
+
* Key of property to cast.
|
|
138
|
+
*
|
|
139
|
+
* @returns
|
|
140
|
+
* Single-key object with property cast as desired type.
|
|
141
|
+
*/
|
|
142
|
+
export function propertyAs(o, key) {
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is determined by condition.
|
|
144
|
+
return (key in o ?
|
|
145
|
+
{
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Force cast.
|
|
147
|
+
[key]: o[key]
|
|
148
|
+
} :
|
|
149
|
+
{});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Determine if argument is nullish. Application extension may pass `null` or `undefined` to missing parameters.
|
|
153
|
+
*
|
|
154
|
+
* @param argument
|
|
155
|
+
* Argument.
|
|
156
|
+
*
|
|
157
|
+
* @returns
|
|
158
|
+
* True if argument is undefined or null.
|
|
159
|
+
*/
|
|
160
|
+
export function isNullish(argument) {
|
|
161
|
+
return argument === null || argument === undefined;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=type-helper.js.map
|