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.
@@ -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