wirejs-resources 0.1.4-alpha → 0.1.6-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.
- package/lib/adapters/context.js +3 -3
- package/lib/resources/secret.js +7 -4
- package/lib/types.ts +2 -0
- package/package.json +1 -1
package/lib/adapters/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CookieJar } from "./cookie-jar.js";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const __requiresContext = new Symbol('__requiresContext');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {(...args: any) => any} ApiMethod
|
|
@@ -61,7 +61,7 @@ export function withContext(contextWrapper, path = []) {
|
|
|
61
61
|
return withContext(contextWrapper, [...path, prop])
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
|
-
|
|
64
|
+
fnOrNs[__requiresContext] = true;
|
|
65
65
|
return fnOrNs;
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -71,7 +71,7 @@ export function withContext(contextWrapper, path = []) {
|
|
|
71
71
|
* @returns {fnOrNS is (context: Context) => T}
|
|
72
72
|
*/
|
|
73
73
|
export function requiresContext(fnOrNS) {
|
|
74
|
-
return
|
|
74
|
+
return fnOrNS[__requiresContext] === true;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
export class Context {
|
package/lib/resources/secret.js
CHANGED
|
@@ -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
|
-
|
|
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.#
|
|
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.#
|
|
51
|
+
await this.#initialize();
|
|
49
52
|
await this.#fileService.write(FILENAME, JSON.stringify(data));
|
|
50
53
|
}
|
|
51
54
|
}
|
package/lib/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AuthenticationService as AuthenticationServiceBase,
|
|
3
3
|
withContext as withContextBase,
|
|
4
|
+
requiresContext as requiresContextBase,
|
|
4
5
|
FileService as FileServiceBase,
|
|
5
6
|
Context as ContextBase,
|
|
6
7
|
Resource as ResourceBase,
|
|
@@ -11,4 +12,5 @@ export declare class Context extends ContextBase {};
|
|
|
11
12
|
export declare class AuthenticationService extends AuthenticationServiceBase {};
|
|
12
13
|
export declare class FileService extends FileServiceBase {};
|
|
13
14
|
export declare function withContext(): typeof withContextBase;
|
|
15
|
+
export declare function requiresContext(): typeof requiresContextBase;
|
|
14
16
|
export declare const overrides: any;
|