@hamak/ui-store-impl 0.10.1 → 0.12.0
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/package.json +2 -2
- package/dist/autosave/autosave-config-resolver.d.ts +0 -45
- package/dist/autosave/autosave-config-resolver.d.ts.map +0 -1
- package/dist/autosave/autosave-config-resolver.js +0 -107
- package/dist/autosave/autosave-middleware.d.ts +0 -37
- package/dist/autosave/autosave-middleware.d.ts.map +0 -1
- package/dist/autosave/autosave-middleware.js +0 -297
- package/dist/autosave/autosave-registry.d.ts +0 -15
- package/dist/autosave/autosave-registry.d.ts.map +0 -1
- package/dist/autosave/autosave-registry.js +0 -33
- package/dist/autosave/autosave-sync-middleware.d.ts +0 -24
- package/dist/autosave/autosave-sync-middleware.d.ts.map +0 -1
- package/dist/autosave/autosave-sync-middleware.js +0 -98
- package/dist/autosave/index.d.ts +0 -8
- package/dist/autosave/index.d.ts.map +0 -1
- package/dist/autosave/index.js +0 -7
- package/dist/core/index.d.ts +0 -4
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -3
- package/dist/core/middleware-registry.d.ts +0 -21
- package/dist/core/middleware-registry.d.ts.map +0 -1
- package/dist/core/middleware-registry.js +0 -50
- package/dist/core/reducer-registry.d.ts +0 -18
- package/dist/core/reducer-registry.d.ts.map +0 -1
- package/dist/core/reducer-registry.js +0 -54
- package/dist/core/store-manager.d.ts +0 -29
- package/dist/core/store-manager.d.ts.map +0 -1
- package/dist/core/store-manager.js +0 -104
- package/dist/es2015/autosave/autosave-config-resolver.js +0 -110
- package/dist/es2015/autosave/autosave-middleware.js +0 -311
- package/dist/es2015/autosave/autosave-registry.js +0 -33
- package/dist/es2015/autosave/autosave-sync-middleware.js +0 -98
- package/dist/es2015/autosave/index.js +0 -7
- package/dist/es2015/core/index.js +0 -3
- package/dist/es2015/core/middleware-registry.js +0 -47
- package/dist/es2015/core/reducer-registry.js +0 -54
- package/dist/es2015/core/store-manager.js +0 -104
- package/dist/es2015/extensions/store-extensions.js +0 -61
- package/dist/es2015/fs/commands/fs-commands.js +0 -327
- package/dist/es2015/fs/commands/structure-commands.js +0 -21
- package/dist/es2015/fs/core/fs-adapter.js +0 -134
- package/dist/es2015/fs/core/fs-facade.js +0 -78
- package/dist/es2015/fs/index.js +0 -11
- package/dist/es2015/fs/utils/data-updater.js +0 -251
- package/dist/es2015/fs/utils/deep-equal.js +0 -28
- package/dist/es2015/middleware/event-bridge-middleware.js +0 -19
- package/dist/es2015/middleware/index.js +0 -5
- package/dist/es2015/middleware/logger-middleware.js +0 -18
- package/dist/es2015/plugin/index.js +0 -4
- package/dist/es2015/plugin/store-plugin-factory.js +0 -137
- package/dist/extensions/store-extensions.d.ts +0 -23
- package/dist/extensions/store-extensions.d.ts.map +0 -1
- package/dist/extensions/store-extensions.js +0 -61
- package/dist/fs/commands/fs-commands.d.ts +0 -100
- package/dist/fs/commands/fs-commands.d.ts.map +0 -1
- package/dist/fs/commands/fs-commands.js +0 -330
- package/dist/fs/commands/structure-commands.d.ts +0 -76
- package/dist/fs/commands/structure-commands.d.ts.map +0 -1
- package/dist/fs/commands/structure-commands.js +0 -21
- package/dist/fs/core/fs-adapter.d.ts +0 -60
- package/dist/fs/core/fs-adapter.d.ts.map +0 -1
- package/dist/fs/core/fs-adapter.js +0 -134
- package/dist/fs/core/fs-facade.d.ts +0 -37
- package/dist/fs/core/fs-facade.d.ts.map +0 -1
- package/dist/fs/core/fs-facade.js +0 -78
- package/dist/fs/index.d.ts +0 -8
- package/dist/fs/index.d.ts.map +0 -1
- package/dist/fs/index.js +0 -11
- package/dist/fs/utils/data-updater.d.ts +0 -43
- package/dist/fs/utils/data-updater.d.ts.map +0 -1
- package/dist/fs/utils/data-updater.js +0 -255
- package/dist/fs/utils/deep-equal.d.ts +0 -5
- package/dist/fs/utils/deep-equal.d.ts.map +0 -1
- package/dist/fs/utils/deep-equal.js +0 -28
- package/dist/middleware/event-bridge-middleware.d.ts +0 -7
- package/dist/middleware/event-bridge-middleware.d.ts.map +0 -1
- package/dist/middleware/event-bridge-middleware.js +0 -19
- package/dist/middleware/index.d.ts +0 -6
- package/dist/middleware/index.d.ts.map +0 -1
- package/dist/middleware/index.js +0 -5
- package/dist/middleware/logger-middleware.d.ts +0 -7
- package/dist/middleware/logger-middleware.d.ts.map +0 -1
- package/dist/middleware/logger-middleware.js +0 -18
- package/dist/plugin/index.d.ts +0 -5
- package/dist/plugin/index.d.ts.map +0 -1
- package/dist/plugin/index.js +0 -4
- package/dist/plugin/store-plugin-factory.d.ts +0 -15
- package/dist/plugin/store-plugin-factory.d.ts.map +0 -1
- package/dist/plugin/store-plugin-factory.js +0 -121
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Store extensions collector
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Collects middleware and reducer contributions until the store boots
|
|
6
|
-
*/
|
|
7
|
-
export class StoreExtensionsCollector {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.entries = [];
|
|
10
|
-
}
|
|
11
|
-
register(source, extensions) {
|
|
12
|
-
var _a;
|
|
13
|
-
const hasMiddleware = Boolean((_a = extensions.middleware) === null || _a === void 0 ? void 0 : _a.length);
|
|
14
|
-
const hasReducers = Boolean(extensions.reducers && Object.keys(extensions.reducers).length);
|
|
15
|
-
if (!hasMiddleware && !hasReducers) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
this.entries.push({
|
|
19
|
-
source,
|
|
20
|
-
extensions: {
|
|
21
|
-
middleware: extensions.middleware,
|
|
22
|
-
reducers: extensions.reducers,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Drain collected extensions (used internally by the plugin)
|
|
28
|
-
*/
|
|
29
|
-
drain() {
|
|
30
|
-
const snapshot = this.entries;
|
|
31
|
-
this.entries = [];
|
|
32
|
-
return snapshot;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function withSourceMetadata(middleware, source) {
|
|
36
|
-
var _a;
|
|
37
|
-
if (!middleware) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
return Object.assign({ plugin: (_a = middleware.plugin) !== null && _a !== void 0 ? _a : source }, middleware);
|
|
41
|
-
}
|
|
42
|
-
export function applyStoreExtensions(collector, middlewareRegistry, reducerRegistry) {
|
|
43
|
-
const entries = collector.drain();
|
|
44
|
-
entries.forEach(({ source, extensions }) => {
|
|
45
|
-
var _a;
|
|
46
|
-
(_a = extensions.middleware) === null || _a === void 0 ? void 0 : _a.forEach((mw) => {
|
|
47
|
-
const middleware = withSourceMetadata(mw, source);
|
|
48
|
-
if (middleware) {
|
|
49
|
-
middlewareRegistry.register(middleware);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
if (extensions.reducers) {
|
|
53
|
-
Object.entries(extensions.reducers).forEach(([key, reducer]) => {
|
|
54
|
-
reducerRegistry.register(key, reducer);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
export function createStoreExtensionsCollector() {
|
|
60
|
-
return new StoreExtensionsCollector();
|
|
61
|
-
}
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import { fileSystemNodeInitialState } from '@hamak/ui-store-api';
|
|
2
|
-
import { pathSteps } from '@hamak/shared-utils';
|
|
3
|
-
import { DataUpdater } from '../utils/data-updater.js';
|
|
4
|
-
import { produce, current, isDraft, original } from 'immer';
|
|
5
|
-
import { deepEqual } from '../utils/deep-equal.js';
|
|
6
|
-
// Re-export path utilities from shared-utils for internal use
|
|
7
|
-
export { pathSteps, parentPathSteps } from '@hamak/shared-utils';
|
|
8
|
-
/**
|
|
9
|
-
* Get filesystem node at path
|
|
10
|
-
*/
|
|
11
|
-
export function getFileSystemNode(fsNode, path) {
|
|
12
|
-
const steps = pathSteps(path);
|
|
13
|
-
let result = fsNode;
|
|
14
|
-
for (let i = 0; i < steps.length; i++) {
|
|
15
|
-
const step = steps[i];
|
|
16
|
-
if (result === undefined) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
else if (result.type === 'directory') {
|
|
20
|
-
result = result.children[step];
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Create a directory node
|
|
30
|
-
*/
|
|
31
|
-
function createDirectoryNode(step, extensionStates) {
|
|
32
|
-
const state = fileSystemNodeInitialState();
|
|
33
|
-
if (extensionStates) {
|
|
34
|
-
state.extensionStates = Object.assign(Object.assign({}, state.extensionStates), extensionStates);
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
type: 'directory',
|
|
38
|
-
state,
|
|
39
|
-
name: step,
|
|
40
|
-
children: {}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Create a file node
|
|
45
|
-
*/
|
|
46
|
-
function createFileNode(name, content, schema, state, extensionStates) {
|
|
47
|
-
if (extensionStates) {
|
|
48
|
-
state.extensionStates = Object.assign(Object.assign({}, state.extensionStates), extensionStates);
|
|
49
|
-
}
|
|
50
|
-
return { type: 'file', name, content, schema, state };
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* FileSystem command handler - executes filesystem operations
|
|
54
|
-
*/
|
|
55
|
-
export class FileSystemCommandHandler {
|
|
56
|
-
constructor() {
|
|
57
|
-
this.contentCommandHandler = new FileContentCommandHandler();
|
|
58
|
-
}
|
|
59
|
-
execute(state, command) {
|
|
60
|
-
switch (command.name) {
|
|
61
|
-
case 'mkdir': return this.executeMkdir(state, command);
|
|
62
|
-
case 'set-file': return this.executeSetFile(state, command);
|
|
63
|
-
case 'update-file-content': return this.executeContentCommand(state, command);
|
|
64
|
-
case 'set-file-content': return this.executeSetContentCommand(state, command);
|
|
65
|
-
case 'remove': return this.executeRemove(state, command);
|
|
66
|
-
case 'set-extension-state': return this.executeSetExtensionState(state, command);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
executeMkdir(state, command) {
|
|
70
|
-
const { path, parents, extensionStates } = command;
|
|
71
|
-
const steps = pathSteps(path);
|
|
72
|
-
return produce(state, draft => {
|
|
73
|
-
const { root } = draft;
|
|
74
|
-
let dir = root;
|
|
75
|
-
for (let i = 0; i < steps.length; i++) {
|
|
76
|
-
const step = steps[i];
|
|
77
|
-
if (i + 1 === steps.length) {
|
|
78
|
-
// Last step is the element to create
|
|
79
|
-
if (dir.children[step] === undefined) {
|
|
80
|
-
dir.children[step] = createDirectoryNode(step, extensionStates);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
let child = dir.children[step];
|
|
85
|
-
if (child === undefined) {
|
|
86
|
-
if (parents === true) {
|
|
87
|
-
child = createDirectoryNode(step);
|
|
88
|
-
dir.children[step] = child;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else if (child.type === 'directory') {
|
|
95
|
-
dir = child;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
dir = child;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
executeRemove(state, command) {
|
|
106
|
-
const { path, recursive } = command;
|
|
107
|
-
const steps = pathSteps(path);
|
|
108
|
-
return produce(state, draft => {
|
|
109
|
-
const { root } = draft;
|
|
110
|
-
const parentDir = getFileSystemNode(root, steps.slice(0, steps.length - 1));
|
|
111
|
-
if (parentDir === undefined) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (parentDir.type === 'directory') {
|
|
115
|
-
const last = steps[steps.length - 1];
|
|
116
|
-
const child = parentDir.children[last];
|
|
117
|
-
if ((child === null || child === void 0 ? void 0 : child.type) === 'directory'
|
|
118
|
-
&& Object.keys(child.children).length > 0
|
|
119
|
-
&& !(recursive === true)) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
delete parentDir.children[last];
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
executeSetFile(state, command) {
|
|
127
|
-
const { path, content, schema, override, contentIsPresent, extensionStates } = command;
|
|
128
|
-
const steps = pathSteps(path);
|
|
129
|
-
return produce(state, draft => {
|
|
130
|
-
const { root } = draft;
|
|
131
|
-
const parentPath = steps.slice(0, steps.length - 1);
|
|
132
|
-
const parentDir = getFileSystemNode(root, parentPath);
|
|
133
|
-
if (parentDir === undefined) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (parentDir.type === 'directory') {
|
|
137
|
-
const last = steps[steps.length - 1];
|
|
138
|
-
const child = parentDir.children[last];
|
|
139
|
-
if (child === undefined || override === true) {
|
|
140
|
-
parentDir.children[last] = createFileNode(last, content, schema, fileSystemNodeInitialState(contentIsPresent), extensionStates);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
console.warn(`File already exists at location`, path);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
console.warn(`Parent file is not directory`, parentPath);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
executeContentCommand(state, command) {
|
|
152
|
-
const { path, contentCommand } = command;
|
|
153
|
-
return produce(state, draft => {
|
|
154
|
-
const { root } = draft;
|
|
155
|
-
const fileNode = getFileSystemNode(root, path);
|
|
156
|
-
if (fileNode !== undefined) {
|
|
157
|
-
if (fileNode.type === 'file') {
|
|
158
|
-
this.contentCommandHandler.execute(fileNode, contentCommand);
|
|
159
|
-
const previousFile = getFileSystemNode(state.root, path);
|
|
160
|
-
const previousContent = (previousFile === null || previousFile === void 0 ? void 0 : previousFile.type) === "file" ? previousFile.content : undefined;
|
|
161
|
-
this.contentMayChange(fileNode);
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
console.warn(`Not a file at location`, path);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
console.warn(`No file found at location`, path);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
contentMayChange(fileNode) {
|
|
173
|
-
const changed = !deepEqual(this.original(fileNode.content), this.current(fileNode.content));
|
|
174
|
-
if (changed) {
|
|
175
|
-
if (fileNode.state === undefined) {
|
|
176
|
-
fileNode.state = fileSystemNodeInitialState();
|
|
177
|
-
}
|
|
178
|
-
fileNode.state.contentHistory.push(this.original(fileNode.content));
|
|
179
|
-
// check compared to memo modification status
|
|
180
|
-
if (fileNode.state.memo !== undefined) {
|
|
181
|
-
const memo = fileNode.state.memo;
|
|
182
|
-
memo.modified = !deepEqual(this.current(memo.originalContent), this.current(fileNode.content));
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
executeSetContentCommand(state, command) {
|
|
187
|
-
const { path, content, fromRemote } = command;
|
|
188
|
-
return produce(state, draft => {
|
|
189
|
-
const { root } = draft;
|
|
190
|
-
const fileNode = getFileSystemNode(root, path);
|
|
191
|
-
if (fileNode !== undefined) {
|
|
192
|
-
if (fileNode.type === 'file') {
|
|
193
|
-
fileNode.content = content;
|
|
194
|
-
if (fileNode.state === undefined) {
|
|
195
|
-
fileNode.state = fileSystemNodeInitialState(true);
|
|
196
|
-
}
|
|
197
|
-
if (fromRemote) {
|
|
198
|
-
fileNode.state.contentLoaded = true;
|
|
199
|
-
if (fileNode.state.memo === undefined) {
|
|
200
|
-
fileNode.state.memo = { originalContent: { value: content }, modified: false };
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
const memo = fileNode.state.memo;
|
|
204
|
-
memo.originalContent = { value: content };
|
|
205
|
-
memo.modified = false;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
this.contentMayChange(fileNode);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
console.warn(`Not a file at location`, path);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
console.warn(`No file found at location`, path);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
executeSetExtensionState(state, command) {
|
|
222
|
-
const { path, key, state: extensionState } = command;
|
|
223
|
-
return produce(state, draft => {
|
|
224
|
-
const { root } = draft;
|
|
225
|
-
const node = getFileSystemNode(root, path);
|
|
226
|
-
if (node !== undefined) {
|
|
227
|
-
if (node.state === undefined) {
|
|
228
|
-
node.state = fileSystemNodeInitialState();
|
|
229
|
-
}
|
|
230
|
-
if (node.state.extensionStates === undefined) {
|
|
231
|
-
node.state.extensionStates = {};
|
|
232
|
-
}
|
|
233
|
-
// Merge the new state with existing state for this key
|
|
234
|
-
const existing = node.state.extensionStates[key];
|
|
235
|
-
node.state.extensionStates[key] = Object.assign(Object.assign({}, existing), extensionState);
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
console.warn(`No node found at location`, path);
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
current(o) {
|
|
243
|
-
if (o === null || o === undefined) {
|
|
244
|
-
return o;
|
|
245
|
-
}
|
|
246
|
-
return isDraft(o) ? current(o) : o;
|
|
247
|
-
}
|
|
248
|
-
original(o) {
|
|
249
|
-
if (o === null || o === undefined) {
|
|
250
|
-
return o;
|
|
251
|
-
}
|
|
252
|
-
return isDraft(o) ? original(o) : o;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* File content command handler - handles structure commands on file content
|
|
257
|
-
*/
|
|
258
|
-
export class FileContentCommandHandler {
|
|
259
|
-
constructor() {
|
|
260
|
-
this.updater = new DataUpdater();
|
|
261
|
-
}
|
|
262
|
-
execute(file, command) {
|
|
263
|
-
switch (command.name) {
|
|
264
|
-
case 'add-at':
|
|
265
|
-
{
|
|
266
|
-
this.executeAdd(file, command);
|
|
267
|
-
}
|
|
268
|
-
break;
|
|
269
|
-
case 'insert-at':
|
|
270
|
-
{
|
|
271
|
-
this.executeInsert(file, command);
|
|
272
|
-
}
|
|
273
|
-
break;
|
|
274
|
-
case 'set-at':
|
|
275
|
-
{
|
|
276
|
-
this.executeSet(file, command);
|
|
277
|
-
}
|
|
278
|
-
break;
|
|
279
|
-
case 'delete-at':
|
|
280
|
-
{
|
|
281
|
-
this.executeDelete(file, command);
|
|
282
|
-
}
|
|
283
|
-
break;
|
|
284
|
-
case 'batch-update':
|
|
285
|
-
{
|
|
286
|
-
this.executeBatch(file, command);
|
|
287
|
-
}
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
executeDelete(file, command) {
|
|
292
|
-
const { itinerary } = command;
|
|
293
|
-
if (itinerary === undefined) {
|
|
294
|
-
file.content = undefined;
|
|
295
|
-
}
|
|
296
|
-
const { content } = file;
|
|
297
|
-
this.updater.executeDelete(content, itinerary);
|
|
298
|
-
}
|
|
299
|
-
executeSet(file, command) {
|
|
300
|
-
const { itinerary, value } = command;
|
|
301
|
-
if (itinerary === undefined) {
|
|
302
|
-
file.content = value;
|
|
303
|
-
}
|
|
304
|
-
const { content } = file;
|
|
305
|
-
this.updater.executeSet(content, itinerary, value);
|
|
306
|
-
}
|
|
307
|
-
executeAdd(file, command) {
|
|
308
|
-
const { itinerary, value } = command;
|
|
309
|
-
const { content } = file;
|
|
310
|
-
this.updater.executeAdd(content, itinerary, value);
|
|
311
|
-
}
|
|
312
|
-
executeInsert(file, command) {
|
|
313
|
-
const { itinerary, value } = command;
|
|
314
|
-
if (itinerary === undefined) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const { content } = file;
|
|
318
|
-
this.updater.executeInsert(content, itinerary, value);
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Executes a batch of commands, rebasing each on previous mutations.
|
|
322
|
-
*/
|
|
323
|
-
executeBatch(file, command) {
|
|
324
|
-
const { content } = file;
|
|
325
|
-
this.updater.executeBatch(content, command);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper class for creating structure node commands
|
|
3
|
-
*/
|
|
4
|
-
export class StructureNodeCommandHelper {
|
|
5
|
-
addNode(itinerary, value, prototypes) {
|
|
6
|
-
return { name: 'add-at', itinerary, value, prototypes };
|
|
7
|
-
}
|
|
8
|
-
insertNode(itinerary, value, prototypes) {
|
|
9
|
-
return { name: 'insert-at', itinerary, value, prototypes };
|
|
10
|
-
}
|
|
11
|
-
setNode(itinerary, value, prototypes) {
|
|
12
|
-
return { name: 'set-at', itinerary, value, prototypes };
|
|
13
|
-
}
|
|
14
|
-
deleteNode(itinerary) {
|
|
15
|
-
return { name: 'delete-at', itinerary };
|
|
16
|
-
}
|
|
17
|
-
batchUpdate(commands, autoRebase = false) {
|
|
18
|
-
return { name: 'batch-update', commands, autoRebase };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export const structs = new StructureNodeCommandHelper();
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { createSelector } from '@reduxjs/toolkit';
|
|
2
|
-
import { FileSystemCommandHandler, pathSteps } from '../commands/fs-commands.js';
|
|
3
|
-
import { fileSystemNodeInitialState } from '@hamak/ui-store-api';
|
|
4
|
-
/**
|
|
5
|
-
* Factory function to create a FileSystemAdapter
|
|
6
|
-
*/
|
|
7
|
-
export function createFileSystemAdapter(sliceName) {
|
|
8
|
-
return new FileSystemAdapter(sliceName);
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* FileSystemAdapter - Manages Redux state for virtual filesystem
|
|
12
|
-
*/
|
|
13
|
-
export class FileSystemAdapter {
|
|
14
|
-
constructor(sliceName) {
|
|
15
|
-
this.sliceName = sliceName;
|
|
16
|
-
this.actions = new FileSystemNodeActions(sliceName);
|
|
17
|
-
this.commandHandler = new FileSystemCommandHandler();
|
|
18
|
-
this.reducer = (state = this.getInitialState(), action) => {
|
|
19
|
-
if (this.actions.isFileSystemNodeAction(action)) {
|
|
20
|
-
return this.commandHandler.execute(state, action.command);
|
|
21
|
-
}
|
|
22
|
-
return state;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
getInitialState() {
|
|
26
|
-
return { root: { type: 'directory', name: '', children: {}, state: fileSystemNodeInitialState() } };
|
|
27
|
-
}
|
|
28
|
-
getActions() {
|
|
29
|
-
return this.actions;
|
|
30
|
-
}
|
|
31
|
-
getReducer(extraReducers) {
|
|
32
|
-
if (extraReducers === undefined) {
|
|
33
|
-
return this.reducer;
|
|
34
|
-
}
|
|
35
|
-
return (state, action) => this.reducer(extraReducers(state, action), action);
|
|
36
|
-
}
|
|
37
|
-
createSelector(fileSystemSelector, path) {
|
|
38
|
-
const rootSelector = createSelector(fileSystemSelector, fs => fs === null || fs === void 0 ? void 0 : fs.root);
|
|
39
|
-
const steps = pathSteps(path);
|
|
40
|
-
if (steps === undefined || steps.length === 0) {
|
|
41
|
-
return rootSelector;
|
|
42
|
-
}
|
|
43
|
-
return steps.reduce((acc, step) => {
|
|
44
|
-
return createSelector(acc, o => {
|
|
45
|
-
if (o === undefined || o.type === 'file') {
|
|
46
|
-
return o;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
return o.children[step];
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}, rootSelector);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* FileSystemNodeActions - Action creators for filesystem operations
|
|
57
|
-
*/
|
|
58
|
-
export class FileSystemNodeActions {
|
|
59
|
-
constructor(sliceName) {
|
|
60
|
-
this.sliceName = sliceName;
|
|
61
|
-
this._mkdirType = `${this.sliceName}/createDirectoryNode`;
|
|
62
|
-
this._setFileType = `${this.sliceName}/createFileNode`;
|
|
63
|
-
this._removeType = `${this.sliceName}/removeNode`;
|
|
64
|
-
this._updateFileContentType = `${this.sliceName}/updateFileContent`;
|
|
65
|
-
this._setFileContentType = `${this.sliceName}/setFileContent`;
|
|
66
|
-
this._setExtensionStateType = `${this.sliceName}/setExtensionState`;
|
|
67
|
-
this.actionTypeSet = new Set([
|
|
68
|
-
this._mkdirType,
|
|
69
|
-
this._setFileType,
|
|
70
|
-
this._removeType,
|
|
71
|
-
this._updateFileContentType,
|
|
72
|
-
this._setFileContentType,
|
|
73
|
-
this._setExtensionStateType
|
|
74
|
-
]);
|
|
75
|
-
}
|
|
76
|
-
get mkdirType() {
|
|
77
|
-
return this._mkdirType;
|
|
78
|
-
}
|
|
79
|
-
get setFileType() {
|
|
80
|
-
return this._setFileType;
|
|
81
|
-
}
|
|
82
|
-
get removeType() {
|
|
83
|
-
return this._removeType;
|
|
84
|
-
}
|
|
85
|
-
get updateFileContentType() {
|
|
86
|
-
return this._updateFileContentType;
|
|
87
|
-
}
|
|
88
|
-
get setFileContentType() {
|
|
89
|
-
return this._setFileContentType;
|
|
90
|
-
}
|
|
91
|
-
get setExtensionStateType() {
|
|
92
|
-
return this._setExtensionStateType;
|
|
93
|
-
}
|
|
94
|
-
isFileSystemNodeAction(action) {
|
|
95
|
-
return this.actionTypeSet.has(action.type);
|
|
96
|
-
}
|
|
97
|
-
mkdir(path, parents, extensionStates) {
|
|
98
|
-
return {
|
|
99
|
-
type: this.mkdirType,
|
|
100
|
-
command: { name: 'mkdir', path, parents, extensionStates }
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
setFile(path, content, schema, params = { override: true, contentIsPresent: true }) {
|
|
104
|
-
const { override, contentIsPresent, extensionStates } = params;
|
|
105
|
-
return {
|
|
106
|
-
type: this.setFileType,
|
|
107
|
-
command: { name: 'set-file', path, content, schema, override, contentIsPresent, extensionStates }
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
updateFileContent(path, contentCommand) {
|
|
111
|
-
return {
|
|
112
|
-
type: this.updateFileContentType,
|
|
113
|
-
command: { name: 'update-file-content', path, contentCommand }
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
setFileContent(path, content, fromRemote = false) {
|
|
117
|
-
return {
|
|
118
|
-
type: this.setFileContentType,
|
|
119
|
-
command: { name: 'set-file-content', path, content, fromRemote }
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
removeNode(path, recursive) {
|
|
123
|
-
return {
|
|
124
|
-
type: this.removeType,
|
|
125
|
-
command: { name: 'remove', path, recursive }
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
setExtensionState(path, key, state) {
|
|
129
|
-
return {
|
|
130
|
-
type: this.setExtensionStateType,
|
|
131
|
-
command: { name: 'set-extension-state', path, key, state }
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { createSelector } from '@reduxjs/toolkit';
|
|
2
|
-
import { Pathway, RelativePathwayResolver } from '@hamak/shared-utils';
|
|
3
|
-
/**
|
|
4
|
-
* StoreFileSystemFacade - High-level API for filesystem operations
|
|
5
|
-
*/
|
|
6
|
-
export class StoreFileSystemFacade {
|
|
7
|
-
constructor(fileSystemSelector, adapter) {
|
|
8
|
-
this.fileSystemSelector = fileSystemSelector;
|
|
9
|
-
this.adapter = adapter;
|
|
10
|
-
}
|
|
11
|
-
getActions() {
|
|
12
|
-
return this.adapter.getActions();
|
|
13
|
-
}
|
|
14
|
-
createSelector(path) {
|
|
15
|
-
return this.adapter.createSelector(this.fileSystemSelector, path);
|
|
16
|
-
}
|
|
17
|
-
createFileSelector(path) {
|
|
18
|
-
const nodeSelector = this.adapter.createSelector(this.fileSystemSelector, path);
|
|
19
|
-
return createSelector([nodeSelector], (f) => {
|
|
20
|
-
if ((f === null || f === void 0 ? void 0 : f.type) === 'file') {
|
|
21
|
-
return f;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
selectFromRoot(state, path = []) {
|
|
29
|
-
const fileSystemState = this.fileSystemSelector(state);
|
|
30
|
-
if (fileSystemState === undefined || fileSystemState === null) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
const root = fileSystemState.root;
|
|
35
|
-
return (path !== null && path !== void 0 ? path : []).reduce((acc, step) => {
|
|
36
|
-
if (acc === undefined || acc === null) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
switch (acc.type) {
|
|
41
|
-
case "directory": return acc.children[step];
|
|
42
|
-
case "file": return undefined;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}, root);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
selectFileFromRoot(state, path = []) {
|
|
49
|
-
const fsNode = this.selectFromRoot(state, path);
|
|
50
|
-
if (fsNode === undefined) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
if (fsNode.type === "file") {
|
|
55
|
-
return fsNode;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
throw new Error(`Expecting file at path '${Pathway.of(path).toString()}' but got '${fsNode.type}'`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* StoreFileSystemPathwayResolver - Pathway resolver for filesystem state
|
|
65
|
-
*/
|
|
66
|
-
export class StoreFileSystemPathwayResolver {
|
|
67
|
-
constructor(state, fs) {
|
|
68
|
-
this.state = state;
|
|
69
|
-
this.fs = fs;
|
|
70
|
-
}
|
|
71
|
-
resolve(path) {
|
|
72
|
-
const segments = Pathway.of(path).getSegments();
|
|
73
|
-
return this.fs.selectFromRoot(this.state, segments);
|
|
74
|
-
}
|
|
75
|
-
relativeTo(path) {
|
|
76
|
-
return new RelativePathwayResolver(this, path);
|
|
77
|
-
}
|
|
78
|
-
}
|
package/dist/es2015/fs/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Core filesystem functionality
|
|
2
|
-
export * from './core/fs-adapter.js';
|
|
3
|
-
export * from './core/fs-facade.js';
|
|
4
|
-
// Commands
|
|
5
|
-
export * from './commands/fs-commands.js';
|
|
6
|
-
export * from './commands/structure-commands.js';
|
|
7
|
-
// Re-export path utilities from shared-utils for backward compatibility
|
|
8
|
-
export { pathSteps, parentPathSteps } from '@hamak/shared-utils';
|
|
9
|
-
// Utilities
|
|
10
|
-
export * from './utils/data-updater.js';
|
|
11
|
-
export * from './utils/deep-equal.js';
|