@php-wasm/fs-journal 0.5.1
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/index.cjs +48 -0
- package/index.d.ts +1 -0
- package/index.js +1359 -0
- package/lib/fs-journal.d.ts +127 -0
- package/lib/index.d.ts +2 -0
- package/package.json +44 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { BasePHP, UniversalPHP } from '../../../universal/src/index.ts';
|
|
2
|
+
import type { IsomorphicLocalPHP } from '../../../universal/src/index.ts';
|
|
3
|
+
export type EmscriptenFS = any;
|
|
4
|
+
/**
|
|
5
|
+
* Represents a stream in the Emscripten file system.
|
|
6
|
+
*/
|
|
7
|
+
export type EmscriptenFSStream = {
|
|
8
|
+
/** The path of the node associated with this stream. */
|
|
9
|
+
path: string;
|
|
10
|
+
/** The node associated with the stream. */
|
|
11
|
+
node: EmscriptenFSNode;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents a node in the Emscripten file system.
|
|
15
|
+
*/
|
|
16
|
+
export type EmscriptenFSNode = {
|
|
17
|
+
/**
|
|
18
|
+
* The name of the file or directory.
|
|
19
|
+
*/
|
|
20
|
+
name: string;
|
|
21
|
+
/**
|
|
22
|
+
* A binary flag encoding information about this note,
|
|
23
|
+
* e.g. whether it's file or a directory.
|
|
24
|
+
*/
|
|
25
|
+
mode: number;
|
|
26
|
+
/**
|
|
27
|
+
* A dictionary of functions representing operations
|
|
28
|
+
* that can be performed on the node.
|
|
29
|
+
*/
|
|
30
|
+
node_ops: any;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Represents the type of node in PHP file system.
|
|
34
|
+
*/
|
|
35
|
+
export type FSNodeType = 'file' | 'directory';
|
|
36
|
+
/**
|
|
37
|
+
* Represents an update operation on a file system node.
|
|
38
|
+
*/
|
|
39
|
+
export type UpdateFileOperation = {
|
|
40
|
+
/** The type of operation being performed. */
|
|
41
|
+
operation: 'WRITE';
|
|
42
|
+
/** The path of the node being updated. */
|
|
43
|
+
path: string;
|
|
44
|
+
/** Optional. The new contents of the file. */
|
|
45
|
+
data?: Uint8Array;
|
|
46
|
+
nodeType: 'file';
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Represents a directory operation.
|
|
50
|
+
*/
|
|
51
|
+
export type CreateOperation = {
|
|
52
|
+
/** The type of operation being performed. */
|
|
53
|
+
operation: 'CREATE';
|
|
54
|
+
/** The path of the node being created. */
|
|
55
|
+
path: string;
|
|
56
|
+
/** The type of the node being created. */
|
|
57
|
+
nodeType: FSNodeType;
|
|
58
|
+
};
|
|
59
|
+
export type DeleteOperation = {
|
|
60
|
+
/** The type of operation being performed. */
|
|
61
|
+
operation: 'DELETE';
|
|
62
|
+
/** The path of the node being updated. */
|
|
63
|
+
path: string;
|
|
64
|
+
/** The type of the node being updated. */
|
|
65
|
+
nodeType: FSNodeType;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Represents a rename operation on a file or directory in PHP file system.
|
|
69
|
+
*/
|
|
70
|
+
export type RenameOperation = {
|
|
71
|
+
/** The type of operation being performed. */
|
|
72
|
+
operation: 'RENAME';
|
|
73
|
+
/** The original path of the file or directory being renamed. */
|
|
74
|
+
path: string;
|
|
75
|
+
/** The new path of the file or directory after the rename operation. */
|
|
76
|
+
toPath: string;
|
|
77
|
+
/** The type of node being renamed (file or directory). */
|
|
78
|
+
nodeType: FSNodeType;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Represents a node in the file system.
|
|
82
|
+
*/
|
|
83
|
+
export type FSNode = {
|
|
84
|
+
/** The name of this file or directory. */
|
|
85
|
+
name: string;
|
|
86
|
+
/** The type of this node (file or directory). */
|
|
87
|
+
type: FSNodeType;
|
|
88
|
+
/** The contents of the file, if it is a file and it's stored in memory. */
|
|
89
|
+
contents?: string;
|
|
90
|
+
/** The child nodes of the directory, if it is a directory. */
|
|
91
|
+
children?: FSNode[];
|
|
92
|
+
};
|
|
93
|
+
export type FilesystemOperation = CreateOperation | UpdateFileOperation | DeleteOperation | RenameOperation;
|
|
94
|
+
export declare function journalFSEvents(php: BasePHP, fsRoot: string, onEntry?: (entry: FilesystemOperation) => void): () => void;
|
|
95
|
+
/**
|
|
96
|
+
* Replays a list of filesystem operations on a PHP instance.
|
|
97
|
+
*
|
|
98
|
+
* @param php
|
|
99
|
+
* @param entries
|
|
100
|
+
*/
|
|
101
|
+
export declare function replayFSJournal(php: BasePHP, entries: FilesystemOperation[]): void;
|
|
102
|
+
export declare function recordExistingPath(php: IsomorphicLocalPHP, fromPath: string, toPath: string): Generator<FilesystemOperation>;
|
|
103
|
+
/**
|
|
104
|
+
* Normalizes a list of filesystem operations to remove
|
|
105
|
+
* redundant operations.
|
|
106
|
+
*
|
|
107
|
+
* This is crucial because the journal doesn't store the file contents
|
|
108
|
+
* on write, but only the information that the write happened. We only
|
|
109
|
+
* read the contents of the file on flush. However, at that time the file
|
|
110
|
+
* could have been moved to another location so we need this function to
|
|
111
|
+
* rewrite the journal to reflect the current file location. Only then
|
|
112
|
+
* will the hydrateUpdateFileOps() function be able to do its job.
|
|
113
|
+
*
|
|
114
|
+
* @param journal The original journal.
|
|
115
|
+
* @returns The normalized journal.
|
|
116
|
+
*/
|
|
117
|
+
export declare function normalizeFilesystemOperations(journal: FilesystemOperation[]): FilesystemOperation[];
|
|
118
|
+
/**
|
|
119
|
+
* Populates each WRITE operation with the contents of
|
|
120
|
+
* said file.
|
|
121
|
+
*
|
|
122
|
+
* Mutates the original array.
|
|
123
|
+
*
|
|
124
|
+
* @param php
|
|
125
|
+
* @param entries
|
|
126
|
+
*/
|
|
127
|
+
export declare function hydrateUpdateFileOps(php: UniversalPHP, entries: FilesystemOperation[]): Promise<FilesystemOperation[]>;
|
package/lib/index.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@php-wasm/fs-journal",
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "Bindings to journal the PHP filesystem",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/WordPress/wordpress-playground"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://developer.wordpress.org/playground",
|
|
10
|
+
"author": "The WordPress contributors",
|
|
11
|
+
"contributors": [
|
|
12
|
+
{
|
|
13
|
+
"name": "Adam Zielinski",
|
|
14
|
+
"email": "adam@adamziel.com",
|
|
15
|
+
"url": "https://github.com/adamziel"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"typedoc": {
|
|
19
|
+
"entryPoint": "./src/index.ts",
|
|
20
|
+
"readmeFile": "./README.md",
|
|
21
|
+
"displayName": "@php-wasm/universal",
|
|
22
|
+
"tsconfig": "./tsconfig.lib.json"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": "./index.js",
|
|
27
|
+
"require": "./index.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public",
|
|
33
|
+
"directory": "../../../dist/packages/php-wasm/fs-journal"
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"main": "./index.cjs",
|
|
37
|
+
"module": "./index.js",
|
|
38
|
+
"license": "GPL-2.0-or-later",
|
|
39
|
+
"gitHead": "6c2256a8f3b6bafb2d9a5860f236b00832839769",
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=16.15.1",
|
|
42
|
+
"npm": ">=8.11.0"
|
|
43
|
+
}
|
|
44
|
+
}
|