@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.
Files changed (83) hide show
  1. package/dist/app-data-storage.d.ts +118 -0
  2. package/dist/app-data-storage.d.ts.map +1 -0
  3. package/dist/app-data-storage.js +117 -0
  4. package/dist/app-data-storage.js.map +1 -0
  5. package/dist/app-data.d.ts +26 -0
  6. package/dist/app-data.d.ts.map +1 -0
  7. package/dist/app-data.js +79 -0
  8. package/dist/app-data.js.map +1 -0
  9. package/dist/browser-app-data-storage.d.ts +26 -0
  10. package/dist/browser-app-data-storage.d.ts.map +1 -0
  11. package/dist/browser-app-data-storage.js +34 -0
  12. package/dist/browser-app-data-storage.js.map +1 -0
  13. package/dist/cache.d.ts +58 -0
  14. package/dist/cache.d.ts.map +1 -0
  15. package/dist/cache.js +12 -0
  16. package/dist/cache.js.map +1 -0
  17. package/dist/file-app-data-storage.d.ts +27 -0
  18. package/dist/file-app-data-storage.d.ts.map +1 -0
  19. package/dist/file-app-data-storage.js +52 -0
  20. package/dist/file-app-data-storage.js.map +1 -0
  21. package/dist/http-fetch.d.ts +45 -0
  22. package/dist/http-fetch.d.ts.map +1 -0
  23. package/dist/http-fetch.js +26 -0
  24. package/dist/http-fetch.js.map +1 -0
  25. package/dist/hyperlink.d.ts +18 -0
  26. package/dist/hyperlink.d.ts.map +1 -0
  27. package/dist/hyperlink.js +2 -0
  28. package/dist/hyperlink.js.map +1 -0
  29. package/dist/index.d.ts +30 -761
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +12 -2
  32. package/dist/index.js.map +1 -0
  33. package/dist/local-app-data-storage.d.ts +8 -0
  34. package/dist/local-app-data-storage.d.ts.map +1 -0
  35. package/dist/local-app-data-storage.js +11 -0
  36. package/dist/local-app-data-storage.js.map +1 -0
  37. package/dist/locale/en/locale-resources.d.ts +10 -0
  38. package/dist/locale/en/locale-resources.d.ts.map +1 -0
  39. package/dist/locale/en/locale-resources.js +9 -0
  40. package/dist/locale/en/locale-resources.js.map +1 -0
  41. package/dist/locale/fr/locale-resources.d.ts +10 -0
  42. package/dist/locale/fr/locale-resources.d.ts.map +1 -0
  43. package/dist/locale/fr/locale-resources.js +9 -0
  44. package/dist/locale/fr/locale-resources.js.map +1 -0
  45. package/dist/locale/i18n.d.ts +83 -0
  46. package/dist/locale/i18n.d.ts.map +1 -0
  47. package/dist/locale/i18n.js +157 -0
  48. package/dist/locale/i18n.js.map +1 -0
  49. package/dist/logger.d.ts +136 -0
  50. package/dist/logger.d.ts.map +1 -0
  51. package/dist/logger.js +256 -0
  52. package/dist/logger.js.map +1 -0
  53. package/dist/parse-version.d.ts +36 -0
  54. package/dist/parse-version.d.ts.map +1 -0
  55. package/dist/parse-version.js +23 -0
  56. package/dist/parse-version.js.map +1 -0
  57. package/dist/remote-app-data-storage.d.ts +23 -0
  58. package/dist/remote-app-data-storage.d.ts.map +1 -0
  59. package/dist/remote-app-data-storage.js +42 -0
  60. package/dist/remote-app-data-storage.js.map +1 -0
  61. package/dist/type-helper.d.ts +115 -0
  62. package/dist/type-helper.d.ts.map +1 -0
  63. package/dist/type-helper.js +163 -0
  64. package/dist/type-helper.js.map +1 -0
  65. package/dist/type.d.ts +111 -0
  66. package/dist/type.d.ts.map +1 -0
  67. package/dist/type.js +2 -0
  68. package/dist/type.js.map +1 -0
  69. package/dist/website-url.d.ts +29 -0
  70. package/dist/website-url.d.ts.map +1 -0
  71. package/dist/website-url.js +60 -0
  72. package/dist/website-url.js.map +1 -0
  73. package/package.json +2 -2
  74. package/src/file-app-data-storage.ts +27 -13
  75. package/src/http-fetch.ts +59 -0
  76. package/src/index.ts +1 -0
  77. package/src/remote-app-data-storage.ts +23 -15
  78. package/tsconfig-src.tsbuildinfo +1 -1
  79. package/dist/browser-app-data-storage-G62WSQ5Z.js +0 -1
  80. package/dist/chunk-FIUBVWNN.js +0 -1
  81. package/dist/file-app-data-storage-Y5AB6YOB.js +0 -1
  82. package/dist/index.cjs +0 -18
  83. package/dist/index.d.cts +0 -761
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-helper.js","sourceRoot":"","sources":["../src/type-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAS,UAAU,CAAgE,QAAkB,EAAE,CAAI,EAAE,GAAG,IAAS;IACrH,yGAAyG;IACzG,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAQ,CAAC,KAAK,QAAQ,CAAC,CAAkD,CAAC;AAC1J,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,IAAI,CAAsC,CAAI,EAAE,GAAG,IAAS;IACxE,OAAO,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,IAAI,CAAsC,CAAI,EAAE,GAAG,IAAS;IACxE,OAAO,UAAU,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,OAAO,CAAyE,IAAW,EAAE,MAAe;IACxH,0FAA0F;IAC1F,OAAO,IAAI,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAQ,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,OAAO,CAAyE,IAAW,EAAE,MAAe;IACxH,0FAA0F;IAC1F,OAAO,IAAI,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAQ,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,UAAU,CAA4D,CAAI,EAAE,GAAM;IAC9F,2GAA2G;IAC3G,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACd;YACI,sFAAsF;YACtF,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAY;SAC3B,CAAC,CAAC;QACH,EAAE,CAC2C,CAAC;AACtD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,QAAiB;IACvC,OAAO,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,SAAS,CAAC;AACvD,CAAC"}
package/dist/type.d.ts ADDED
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Typed function, applicable to any function, stricter than {@linkcode Function}.
3
+ *
4
+ * @template TFunction
5
+ * Function type.
6
+ */
7
+ export type TypedFunction<TFunction extends (...args: Parameters<TFunction>) => ReturnType<TFunction>> = (...args: Parameters<TFunction>) => ReturnType<TFunction>;
8
+ /**
9
+ * Typed synchronous function, applicable to any function that doesn't return a {@linkcode Promise}.
10
+ *
11
+ * @template TFunction
12
+ * Function type.
13
+ */
14
+ export type TypedSyncFunction<TFunction extends TypedFunction<TFunction>> = [ReturnType<TFunction>] extends [PromiseLike<unknown>] ? never : TypedFunction<TFunction>;
15
+ /**
16
+ * Arbitrary constructor. An arbitrary constructor doesn't have to be an exact match to a constructor; the only
17
+ * requirements are that `TConstructorParameters` have compatible types (exact or wider types of the actual constructor
18
+ * parameters) and that `TConstructorInstance` be a compatible type (exact or narrower type of the actual constructor
19
+ * instance).
20
+ *
21
+ * @template TConstructorParameters
22
+ * Constructor parameters types.
23
+ *
24
+ * @template TConstructorInstance
25
+ * Constructor instance type.
26
+ */
27
+ export type Constructor<TConstructorParameters extends unknown[], TConstructorInstance> = new (...args: TConstructorParameters) => TConstructorInstance;
28
+ /**
29
+ * Arbitrary abstract constructor. Abstract version of {@linkcode Constructor}.
30
+ *
31
+ * @template TConstructorParameters
32
+ * Constructor parameters types.
33
+ *
34
+ * @template TConstructorInstance
35
+ * Constructor instance type.
36
+ */
37
+ export type AbstractConstructor<TConstructorParameters extends unknown[], TConstructorInstance> = abstract new (...args: TConstructorParameters) => TConstructorInstance;
38
+ /**
39
+ * Typed constructor, applicable to any constructor.
40
+ *
41
+ * @template TConstructor
42
+ * Constructor type.
43
+ */
44
+ export type TypedConstructor<TConstructor extends abstract new (...args: ConstructorParameters<TConstructor>) => InstanceType<TConstructor>> = Constructor<ConstructorParameters<TConstructor>, InstanceType<TConstructor>>;
45
+ /**
46
+ * Typed abstract constructor, applicable to any constructor.
47
+ *
48
+ * @template TConstructor
49
+ * Constructor type.
50
+ */
51
+ export type TypedAbstractConstructor<TConstructor extends abstract new (...args: ConstructorParameters<TConstructor>) => InstanceType<TConstructor>> = AbstractConstructor<ConstructorParameters<TConstructor>, InstanceType<TConstructor>>;
52
+ /**
53
+ * Promisable type. Extends a type by allowing a {@linkcode Promise} of the same type. Typically used in abstract method
54
+ * declarations where the implementing class may or may not implement the method as asynchronous.
55
+ */
56
+ export type Promisable<T> = T | Promise<T>;
57
+ /**
58
+ * Determine the fundamental promised type. This is stricter than `Awaited<Type>` in that it requires a {@linkcode
59
+ * Promise}.
60
+ *
61
+ * @template T
62
+ * Promised type.
63
+ */
64
+ export type PromisedType<T> = [T] extends [PromiseLike<infer TPromised>] ? TPromised : never;
65
+ /**
66
+ * Typed asynchronous function, applicable to any function that returns a {@linkcode Promise}.
67
+ *
68
+ * @template TFunction
69
+ * Function type.
70
+ */
71
+ export type TypedAsyncFunction<TMethod extends (...args: Parameters<TMethod>) => PromiseLike<PromisedType<ReturnType<TMethod>>>> = (...args: Parameters<TMethod>) => Promise<PromisedType<ReturnType<TMethod>>>;
72
+ /**
73
+ * Nullishable type. Extends a type by allowing `null` and `undefined`.
74
+ *
75
+ * @template T
76
+ * Type.
77
+ */
78
+ export type Nullishable<T> = T | null | undefined;
79
+ /**
80
+ * Non-nullishable type. If T is an object type, it is spread and attributes within it are made non-nullishable.
81
+ * Equivalent to a deep `Required<T>` for an object and `NonNullable<T>` for any other type.
82
+ *
83
+ * @template T
84
+ * Type.
85
+ */
86
+ export type NonNullishable<T> = T extends object ? {
87
+ [P in keyof T]-?: NonNullishable<T[P]>;
88
+ } : NonNullable<T>;
89
+ /**
90
+ * Make some keys within a type optional.
91
+ *
92
+ * @template T
93
+ * Object type.
94
+ *
95
+ * @template K
96
+ * Object key type.
97
+ */
98
+ export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
99
+ /**
100
+ * Type to restrict property keys to those that are strings and that support a specified type.
101
+ *
102
+ * @template T
103
+ * Object type.
104
+ *
105
+ * @template P
106
+ * Object property type.
107
+ */
108
+ export type PropertyKeys<T, P> = {
109
+ [K in keyof T]: K extends string ? T[K] extends P ? K : never : never;
110
+ }[keyof T];
111
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CAAC,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,KAAK,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,KAAK,UAAU,CAAC,SAAS,CAAC,CAAC;AAEnK;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAAC,SAAS,SAAS,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAEtK;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,CACnB,sBAAsB,SAAS,OAAO,EAAE,EACxC,oBAAoB,IACpB,KAAK,GAAG,IAAI,EAAE,sBAAsB,KAAK,oBAAoB,C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WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG;KAC9C,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACzC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAEnB;;;;;;;;GAQG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE9E;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI;KAC5B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,KAAK;CACxE,CAAC,MAAM,CAAC,CAAC,CAAC"}
package/dist/type.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Alpha URL. Reads from local application storage, path "config", key "resources.local", if present, otherwise defaults
3
+ * to Vite development server URL.
4
+ */
5
+ export declare const ALPHA_URL: Promise<string>;
6
+ /**
7
+ * AIDC Toolkit website base URL.
8
+ */
9
+ export declare const WEBSITE_BASE_URL = "https://aidc-toolkit.com";
10
+ /**
11
+ * Determine the website URL based on the package version.
12
+ *
13
+ * @param version
14
+ * Package version.
15
+ *
16
+ * @param includeVersionInProduction
17
+ * If true, the version is included in the URL in production.
18
+ *
19
+ * @param alphaURL
20
+ * URL if pre-release identifier is "alpha".
21
+ *
22
+ * @param nonAlphaRelativeURL
23
+ * Non-alpha URL, relative to website base URL plus pre-release identifier (optional) and version.
24
+ *
25
+ * @returns
26
+ * Fully-formed website URL based on the package version.
27
+ */
28
+ export declare function websiteURL(version: string, includeVersionInProduction: boolean, alphaURL: string, nonAlphaRelativeURL?: string): string;
29
+ //# sourceMappingURL=website-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"website-url.d.ts","sourceRoot":"","sources":["../src/website-url.ts"],"names":[],"mappings":"AAyBA;;;GAGG;AACH,eAAO,MAAM,SAAS,iBAKrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,6BAA6B,CAAC;AAE3D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,0BAA0B,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,MAAM,CAkBvI"}
@@ -0,0 +1,60 @@
1
+ import { LocalAppDataStorage } from "./local-app-data-storage.js";
2
+ import { parseVersion } from "./parse-version.js";
3
+ /**
4
+ * Default alpha URL (Vite development server URL) if no local resources found.
5
+ */
6
+ const DEFAULT_ALPHA_URL = "http://localhost:5173";
7
+ /**
8
+ * Configuration path, expected to be present in development but not necessarily in production.
9
+ */
10
+ const CONFIGURATION_PATH = "config";
11
+ /**
12
+ * Key to local resources, expected to be present in development but not necessarily in production.
13
+ */
14
+ const LOCAL_RESOURCES_KEY = "resources.local";
15
+ /**
16
+ * Alpha URL. Reads from local application storage, path "config", key "resources.local", if present, otherwise defaults
17
+ * to Vite development server URL.
18
+ */
19
+ export const ALPHA_URL = LocalAppDataStorage.then(async (LocalAppDataStorage) => new LocalAppDataStorage(CONFIGURATION_PATH).read(LOCAL_RESOURCES_KEY)).then(resources =>
20
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Fallback works regardless of type.
21
+ resources?.alphaURL ?? DEFAULT_ALPHA_URL);
22
+ /**
23
+ * AIDC Toolkit website base URL.
24
+ */
25
+ export const WEBSITE_BASE_URL = "https://aidc-toolkit.com";
26
+ /**
27
+ * Determine the website URL based on the package version.
28
+ *
29
+ * @param version
30
+ * Package version.
31
+ *
32
+ * @param includeVersionInProduction
33
+ * If true, the version is included in the URL in production.
34
+ *
35
+ * @param alphaURL
36
+ * URL if pre-release identifier is "alpha".
37
+ *
38
+ * @param nonAlphaRelativeURL
39
+ * Non-alpha URL, relative to website base URL plus pre-release identifier (optional) and version.
40
+ *
41
+ * @returns
42
+ * Fully-formed website URL based on the package version.
43
+ */
44
+ export function websiteURL(version, includeVersionInProduction, alphaURL, nonAlphaRelativeURL) {
45
+ const parsedVersion = parseVersion(version);
46
+ const preReleaseIdentifier = parsedVersion.preReleaseIdentifier;
47
+ let url;
48
+ if (preReleaseIdentifier === "alpha") {
49
+ // Alpha base URL is absolute.
50
+ url = alphaURL;
51
+ }
52
+ else {
53
+ const preReleaseIdentifierPath = preReleaseIdentifier !== undefined ? `/${preReleaseIdentifier}` : "";
54
+ const versionPath = preReleaseIdentifier !== undefined || includeVersionInProduction ? `/v${parsedVersion.majorVersion}.${parsedVersion.minorVersion}` : "";
55
+ const relativeURL = nonAlphaRelativeURL !== undefined && nonAlphaRelativeURL !== "" ? `/${nonAlphaRelativeURL}` : "";
56
+ url = `${WEBSITE_BASE_URL}${preReleaseIdentifierPath}${versionPath}${relativeURL}`;
57
+ }
58
+ return url;
59
+ }
60
+ //# sourceMappingURL=website-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"website-url.js","sourceRoot":"","sources":["../src/website-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAElD;;GAEG;AACH,MAAM,kBAAk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,GAAG,gBAAgB,GAAG,wBAAwB,GAAG,WAAW,GAAG,WAAW,EAAE,CAAC;IACvF,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidc-toolkit/core",
3
- "version": "1.0.41",
3
+ "version": "1.0.43-beta",
4
4
  "description": "Core functionality for AIDC Toolkit",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "build:doc": "npm run build:non-prod"
29
29
  },
30
30
  "devDependencies": {
31
- "@aidc-toolkit/dev": "^1.0.40"
31
+ "@aidc-toolkit/dev": "1.0.42-beta"
32
32
  },
33
33
  "dependencies": {
34
34
  "base64-js": "^1.5.1",
@@ -6,6 +6,11 @@ import { AppDataStorage } from "./app-data-storage.js";
6
6
  * Application data storage using the file system.
7
7
  */
8
8
  export class FileAppDataStorage extends AppDataStorage<true> {
9
+ /**
10
+ * If true, node:fs has been polyfilled with empty object.
11
+ */
12
+ readonly #isNoOp: boolean;
13
+
9
14
  /**
10
15
  * Constructor.
11
16
  *
@@ -14,36 +19,45 @@ export class FileAppDataStorage extends AppDataStorage<true> {
14
19
  */
15
20
  constructor(path?: string) {
16
21
  super(true, path);
22
+
23
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Condition is true in polyfilled environment.
24
+ this.#isNoOp = fs?.promises?.readFile === undefined;
17
25
  }
18
26
 
19
27
  /**
20
28
  * @inheritDoc
21
29
  */
22
30
  protected override async doRead(key: string, asBinary: boolean | undefined): Promise<string | Uint8Array | undefined> {
23
- return fs.promises.readFile(key).then(buffer =>
24
- asBinary === true ? buffer : buffer.toString()
25
- ).catch(() =>
26
- undefined
27
- );
31
+ return !this.#isNoOp ?
32
+ fs.promises.readFile(key).then(buffer =>
33
+ asBinary === true ? buffer : buffer.toString()
34
+ ).catch(() =>
35
+ undefined
36
+ ) :
37
+ undefined;
28
38
  }
29
39
 
30
40
  /**
31
41
  * @inheritDoc
32
42
  */
33
43
  protected override async doWrite(key: string, data: string | Uint8Array): Promise<void> {
34
- return fs.promises.mkdir(path.dirname(key), {
35
- recursive: true
36
- }).then(async () =>
37
- fs.promises.writeFile(key, data)
38
- );
44
+ return !this.#isNoOp ?
45
+ fs.promises.mkdir(path.dirname(key), {
46
+ recursive: true
47
+ }).then(async () =>
48
+ fs.promises.writeFile(key, data)
49
+ ) :
50
+ undefined;
39
51
  }
40
52
 
41
53
  /**
42
54
  * @inheritDoc
43
55
  */
44
56
  protected override async doDelete(key: string): Promise<void> {
45
- return fs.promises.rm(key, {
46
- force: true
47
- });
57
+ return !this.#isNoOp ?
58
+ fs.promises.rm(key, {
59
+ force: true
60
+ }) :
61
+ undefined;
48
62
  }
49
63
  }
@@ -0,0 +1,59 @@
1
+ import type { Promisable } from "./type.js";
2
+
3
+ /**
4
+ * HTTP status code for OK.
5
+ */
6
+ export const HTTP_OK = 200;
7
+
8
+ /**
9
+ * HTTP status code for not found.
10
+ */
11
+ export const HTTP_NOT_FOUND = 404;
12
+
13
+ /**
14
+ * Generic HTTP response.
15
+ */
16
+ export interface HTTPResponse {
17
+ /**
18
+ * True if OK.
19
+ */
20
+ readonly ok: boolean;
21
+
22
+ /**
23
+ * HTTP status code.
24
+ */
25
+ readonly status: number;
26
+
27
+ /**
28
+ * Body as array buffer.
29
+ */
30
+ readonly arrayBuffer: () => Promisable<ArrayBuffer>;
31
+
32
+ /**
33
+ * Body as text.
34
+ */
35
+ readonly text: () => Promisable<string>;
36
+ }
37
+
38
+ /**
39
+ * HTTP fetch function.
40
+ */
41
+ export type HTTPFetch = (url: string) => Promisable<HTTPResponse>;
42
+
43
+ /**
44
+ * Default HTTP fetch function using global `fetch` function.
45
+ *
46
+ * @param url
47
+ * URL.
48
+ *
49
+ * @returns
50
+ * HTTP response.
51
+ */
52
+ export async function defaultHTTPFetch(url: string): Promise<HTTPResponse> {
53
+ return fetch(url).then(response => ({
54
+ ok: response.ok,
55
+ status: response.status,
56
+ arrayBuffer: async () => response.arrayBuffer(),
57
+ text: async () => response.text()
58
+ }));
59
+ }
package/src/index.ts CHANGED
@@ -26,6 +26,7 @@ export * from "./website-url.js";
26
26
  export * from "./app-data.js";
27
27
  export * from "./app-data-storage.js";
28
28
  export * from "./local-app-data-storage.js";
29
+ export * from "./http-fetch.js";
29
30
  export * from "./remote-app-data-storage.js";
30
31
  export * from "./cache.js";
31
32
 
@@ -1,38 +1,46 @@
1
1
  import { ReadOnlyAppDataStorage } from "./app-data-storage.js";
2
+ import { defaultHTTPFetch, HTTP_NOT_FOUND, type HTTPFetch } from "./http-fetch.js";
2
3
  import { i18nextCore } from "./locale/i18n.js";
3
4
 
4
5
  /**
5
- * Remote application data storage using HTTP. The `store()` and `delete()` methods are not supported.
6
+ * Remote application data storage using HTTP.
6
7
  */
7
8
  export class RemoteAppDataStorage extends ReadOnlyAppDataStorage<true> {
9
+ readonly #httpFetch: HTTPFetch;
10
+
8
11
  /**
9
12
  * Constructor.
10
13
  *
11
14
  * @param baseURL
12
15
  * Base URL. The URL must not end with a slash.
16
+ *
17
+ * @param httpFetch
18
+ * HTTP fetch function.
13
19
  */
14
- constructor(baseURL: string) {
20
+ constructor(baseURL: string, httpFetch: HTTPFetch = defaultHTTPFetch) {
15
21
  super(true, baseURL);
22
+
23
+ this.#httpFetch = httpFetch;
16
24
  }
17
25
 
18
26
  /**
19
27
  * @inheritDoc
20
28
  */
21
29
  protected override async doRead(key: string, asBinary: boolean | undefined): Promise<string | Uint8Array | undefined> {
22
- return fetch(key).then(async (response) => {
23
- let result: string | Uint8Array | undefined;
30
+ const response = await this.#httpFetch(key);
31
+
32
+ let result: string | Uint8Array | undefined;
24
33
 
25
- if (response.ok) {
26
- result = asBinary === true ? new Uint8Array(await response.arrayBuffer()) : await response.text();
27
- } else if (response.status === 404) {
28
- result = undefined;
29
- } else {
30
- throw new RangeError(i18nextCore.t("RemoteAppDataStorage.httpError", {
31
- status: response.status
32
- }));
33
- }
34
+ if (response.ok) {
35
+ result = asBinary === true ? new Uint8Array(await response.arrayBuffer()) : await response.text();
36
+ } else if (response.status === HTTP_NOT_FOUND) {
37
+ result = undefined;
38
+ } else {
39
+ throw new RangeError(i18nextCore.t("RemoteAppDataStorage.httpError", {
40
+ status: response.status
41
+ }));
42
+ }
34
43
 
35
- return result;
36
- });
44
+ return result;
37
45
  }
38
46
  }