wirejs-resources 0.1.6-alpha → 0.1.8-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/dist/adapters/context.d.ts +21 -0
- package/dist/adapters/context.js +32 -0
- package/dist/adapters/cookie-jar.d.ts +30 -0
- package/dist/adapters/cookie-jar.js +55 -0
- package/dist/index.js +6 -0
- package/dist/overrides.d.ts +11 -0
- package/{lib → dist}/overrides.js +1 -1
- package/dist/resource.d.ts +6 -0
- package/dist/resource.js +20 -0
- package/dist/resources/secret.d.ts +7 -0
- package/dist/resources/secret.js +28 -0
- package/dist/services/authentication.d.ts +67 -0
- package/dist/services/authentication.js +286 -0
- package/dist/services/file.d.ts +16 -0
- package/dist/services/file.js +38 -0
- package/package.json +16 -7
- package/lib/adapters/context.js +0 -98
- package/lib/adapters/cookie-jar.js +0 -94
- package/lib/resource.js +0 -32
- package/lib/resources/secret.js +0 -54
- package/lib/services/authentication.js +0 -439
- package/lib/services/file.js +0 -78
- package/lib/types.ts +0 -16
- /package/{lib/index.js → dist/index.d.ts} +0 -0
package/lib/services/file.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import process from 'process';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
import { Resource } from '../resource.js';
|
|
6
|
-
|
|
7
|
-
const CWD = process.cwd();
|
|
8
|
-
|
|
9
|
-
const ALREADY_EXISTS_CODE = 'EEXIST';
|
|
10
|
-
|
|
11
|
-
export class FileService extends Resource {
|
|
12
|
-
/**
|
|
13
|
-
* @param {Resource | string} scope
|
|
14
|
-
* @param {string} id
|
|
15
|
-
*/
|
|
16
|
-
constructor(scope, id) {
|
|
17
|
-
super(scope, id);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @param {string} filename
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
#fullNameFor(filename) {
|
|
25
|
-
const sanitizedId = this.absoluteId.replace('~', '-').replace(/\.+/g, '.');
|
|
26
|
-
const sanitizedName = filename.replace('~', '-').replace(/\.+/g, '.');
|
|
27
|
-
return path.join(CWD, 'temp', 'wirejs-services', sanitizedId, sanitizedName);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @param {string} filename
|
|
32
|
-
* @param {BufferEncoding} [encoding]
|
|
33
|
-
* @return {Promise<string>} file data as a string
|
|
34
|
-
*/
|
|
35
|
-
async read(filename, encoding = 'utf8') {
|
|
36
|
-
return fs.promises.readFile(this.#fullNameFor(filename), { encoding });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param {string} filename
|
|
42
|
-
* @param {string} data
|
|
43
|
-
* @param {{
|
|
44
|
-
* onlyIfNotExists?: boolean;
|
|
45
|
-
* }} [options]
|
|
46
|
-
*/
|
|
47
|
-
async write(filename, data, { onlyIfNotExists = false } = {}) {
|
|
48
|
-
const fullname = this.#fullNameFor(filename);
|
|
49
|
-
const flag = onlyIfNotExists ? 'wx' : 'w';
|
|
50
|
-
await fs.promises.mkdir(path.dirname(fullname), { recursive: true });
|
|
51
|
-
return fs.promises.writeFile(fullname, data, { flag });
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @param {string} filename
|
|
57
|
-
*/
|
|
58
|
-
async delete(filename) {
|
|
59
|
-
return fs.promises.unlink(this.#fullNameFor(filename));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
* @param {{
|
|
65
|
-
* prefix?: string
|
|
66
|
-
* }} [options]
|
|
67
|
-
*/
|
|
68
|
-
async * list({ prefix = '' } = {}) {
|
|
69
|
-
const all = await fs.promises.readdir(CWD, { recursive: true });
|
|
70
|
-
for (const name of all) {
|
|
71
|
-
if (prefix === undefined || name.startsWith(prefix)) yield name;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
isAlreadyExistsError(error) {
|
|
76
|
-
return error.code === ALREADY_EXISTS_CODE;
|
|
77
|
-
}
|
|
78
|
-
}
|
package/lib/types.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AuthenticationService as AuthenticationServiceBase,
|
|
3
|
-
withContext as withContextBase,
|
|
4
|
-
requiresContext as requiresContextBase,
|
|
5
|
-
FileService as FileServiceBase,
|
|
6
|
-
Context as ContextBase,
|
|
7
|
-
Resource as ResourceBase,
|
|
8
|
-
} from './index.js';
|
|
9
|
-
|
|
10
|
-
export declare class Resource extends ResourceBase {};
|
|
11
|
-
export declare class Context extends ContextBase {};
|
|
12
|
-
export declare class AuthenticationService extends AuthenticationServiceBase {};
|
|
13
|
-
export declare class FileService extends FileServiceBase {};
|
|
14
|
-
export declare function withContext(): typeof withContextBase;
|
|
15
|
-
export declare function requiresContext(): typeof requiresContextBase;
|
|
16
|
-
export declare const overrides: any;
|
|
File without changes
|