wirejs-resources 0.1.4-alpha → 0.1.5-alpha

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.
@@ -23,21 +23,24 @@ export class Secret extends Resource {
23
23
  constructor(scope, id) {
24
24
  super(scope, id);
25
25
  this.#fileService = new (overrides.FileService || FileService)(this, 'files');
26
-
27
- this.#initPromise = this.#fileService.write(
26
+ }
27
+
28
+ #initialize() {
29
+ this.#initPromise = this.#initPromise || this.#fileService.write(
28
30
  FILENAME,
29
31
  JSON.stringify(crypto.randomBytes(64).toString('base64url')),
30
32
  { onlyIfNotExists: true }
31
33
  ).catch(error => {
32
34
  if (!this.#fileService.isAlreadyExistsError(error)) throw error;
33
35
  });
36
+ return this.#initPromise;
34
37
  }
35
38
 
36
39
  /**
37
40
  * @returns {any}
38
41
  */
39
42
  async read() {
40
- await this.#initPromise;
43
+ await this.#initialize();
41
44
  return JSON.parse(await this.#fileService.read(FILENAME));
42
45
  }
43
46
 
@@ -45,7 +48,7 @@ export class Secret extends Resource {
45
48
  * @param {any} data
46
49
  */
47
50
  async write(data) {
48
- await this.#initPromise;
51
+ await this.#initialize();
49
52
  await this.#fileService.write(FILENAME, JSON.stringify(data));
50
53
  }
51
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-resources",
3
- "version": "0.1.4-alpha",
3
+ "version": "0.1.5-alpha",
4
4
  "description": "Basic services and server-side resources for wirejs apps",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",