@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.
Files changed (89) hide show
  1. package/package.json +2 -2
  2. package/dist/autosave/autosave-config-resolver.d.ts +0 -45
  3. package/dist/autosave/autosave-config-resolver.d.ts.map +0 -1
  4. package/dist/autosave/autosave-config-resolver.js +0 -107
  5. package/dist/autosave/autosave-middleware.d.ts +0 -37
  6. package/dist/autosave/autosave-middleware.d.ts.map +0 -1
  7. package/dist/autosave/autosave-middleware.js +0 -297
  8. package/dist/autosave/autosave-registry.d.ts +0 -15
  9. package/dist/autosave/autosave-registry.d.ts.map +0 -1
  10. package/dist/autosave/autosave-registry.js +0 -33
  11. package/dist/autosave/autosave-sync-middleware.d.ts +0 -24
  12. package/dist/autosave/autosave-sync-middleware.d.ts.map +0 -1
  13. package/dist/autosave/autosave-sync-middleware.js +0 -98
  14. package/dist/autosave/index.d.ts +0 -8
  15. package/dist/autosave/index.d.ts.map +0 -1
  16. package/dist/autosave/index.js +0 -7
  17. package/dist/core/index.d.ts +0 -4
  18. package/dist/core/index.d.ts.map +0 -1
  19. package/dist/core/index.js +0 -3
  20. package/dist/core/middleware-registry.d.ts +0 -21
  21. package/dist/core/middleware-registry.d.ts.map +0 -1
  22. package/dist/core/middleware-registry.js +0 -50
  23. package/dist/core/reducer-registry.d.ts +0 -18
  24. package/dist/core/reducer-registry.d.ts.map +0 -1
  25. package/dist/core/reducer-registry.js +0 -54
  26. package/dist/core/store-manager.d.ts +0 -29
  27. package/dist/core/store-manager.d.ts.map +0 -1
  28. package/dist/core/store-manager.js +0 -104
  29. package/dist/es2015/autosave/autosave-config-resolver.js +0 -110
  30. package/dist/es2015/autosave/autosave-middleware.js +0 -311
  31. package/dist/es2015/autosave/autosave-registry.js +0 -33
  32. package/dist/es2015/autosave/autosave-sync-middleware.js +0 -98
  33. package/dist/es2015/autosave/index.js +0 -7
  34. package/dist/es2015/core/index.js +0 -3
  35. package/dist/es2015/core/middleware-registry.js +0 -47
  36. package/dist/es2015/core/reducer-registry.js +0 -54
  37. package/dist/es2015/core/store-manager.js +0 -104
  38. package/dist/es2015/extensions/store-extensions.js +0 -61
  39. package/dist/es2015/fs/commands/fs-commands.js +0 -327
  40. package/dist/es2015/fs/commands/structure-commands.js +0 -21
  41. package/dist/es2015/fs/core/fs-adapter.js +0 -134
  42. package/dist/es2015/fs/core/fs-facade.js +0 -78
  43. package/dist/es2015/fs/index.js +0 -11
  44. package/dist/es2015/fs/utils/data-updater.js +0 -251
  45. package/dist/es2015/fs/utils/deep-equal.js +0 -28
  46. package/dist/es2015/middleware/event-bridge-middleware.js +0 -19
  47. package/dist/es2015/middleware/index.js +0 -5
  48. package/dist/es2015/middleware/logger-middleware.js +0 -18
  49. package/dist/es2015/plugin/index.js +0 -4
  50. package/dist/es2015/plugin/store-plugin-factory.js +0 -137
  51. package/dist/extensions/store-extensions.d.ts +0 -23
  52. package/dist/extensions/store-extensions.d.ts.map +0 -1
  53. package/dist/extensions/store-extensions.js +0 -61
  54. package/dist/fs/commands/fs-commands.d.ts +0 -100
  55. package/dist/fs/commands/fs-commands.d.ts.map +0 -1
  56. package/dist/fs/commands/fs-commands.js +0 -330
  57. package/dist/fs/commands/structure-commands.d.ts +0 -76
  58. package/dist/fs/commands/structure-commands.d.ts.map +0 -1
  59. package/dist/fs/commands/structure-commands.js +0 -21
  60. package/dist/fs/core/fs-adapter.d.ts +0 -60
  61. package/dist/fs/core/fs-adapter.d.ts.map +0 -1
  62. package/dist/fs/core/fs-adapter.js +0 -134
  63. package/dist/fs/core/fs-facade.d.ts +0 -37
  64. package/dist/fs/core/fs-facade.d.ts.map +0 -1
  65. package/dist/fs/core/fs-facade.js +0 -78
  66. package/dist/fs/index.d.ts +0 -8
  67. package/dist/fs/index.d.ts.map +0 -1
  68. package/dist/fs/index.js +0 -11
  69. package/dist/fs/utils/data-updater.d.ts +0 -43
  70. package/dist/fs/utils/data-updater.d.ts.map +0 -1
  71. package/dist/fs/utils/data-updater.js +0 -255
  72. package/dist/fs/utils/deep-equal.d.ts +0 -5
  73. package/dist/fs/utils/deep-equal.d.ts.map +0 -1
  74. package/dist/fs/utils/deep-equal.js +0 -28
  75. package/dist/middleware/event-bridge-middleware.d.ts +0 -7
  76. package/dist/middleware/event-bridge-middleware.d.ts.map +0 -1
  77. package/dist/middleware/event-bridge-middleware.js +0 -19
  78. package/dist/middleware/index.d.ts +0 -6
  79. package/dist/middleware/index.d.ts.map +0 -1
  80. package/dist/middleware/index.js +0 -5
  81. package/dist/middleware/logger-middleware.d.ts +0 -7
  82. package/dist/middleware/logger-middleware.d.ts.map +0 -1
  83. package/dist/middleware/logger-middleware.js +0 -18
  84. package/dist/plugin/index.d.ts +0 -5
  85. package/dist/plugin/index.d.ts.map +0 -1
  86. package/dist/plugin/index.js +0 -4
  87. package/dist/plugin/store-plugin-factory.d.ts +0 -15
  88. package/dist/plugin/store-plugin-factory.d.ts.map +0 -1
  89. package/dist/plugin/store-plugin-factory.js +0 -121
@@ -1,330 +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 = { ...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 = { ...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?.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?.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] = {
236
- ...existing,
237
- ...extensionState
238
- };
239
- }
240
- else {
241
- console.warn(`No node found at location`, path);
242
- }
243
- });
244
- }
245
- current(o) {
246
- if (o === null || o === undefined) {
247
- return o;
248
- }
249
- return isDraft(o) ? current(o) : o;
250
- }
251
- original(o) {
252
- if (o === null || o === undefined) {
253
- return o;
254
- }
255
- return isDraft(o) ? original(o) : o;
256
- }
257
- }
258
- /**
259
- * File content command handler - handles structure commands on file content
260
- */
261
- export class FileContentCommandHandler {
262
- constructor() {
263
- this.updater = new DataUpdater();
264
- }
265
- execute(file, command) {
266
- switch (command.name) {
267
- case 'add-at':
268
- {
269
- this.executeAdd(file, command);
270
- }
271
- break;
272
- case 'insert-at':
273
- {
274
- this.executeInsert(file, command);
275
- }
276
- break;
277
- case 'set-at':
278
- {
279
- this.executeSet(file, command);
280
- }
281
- break;
282
- case 'delete-at':
283
- {
284
- this.executeDelete(file, command);
285
- }
286
- break;
287
- case 'batch-update':
288
- {
289
- this.executeBatch(file, command);
290
- }
291
- break;
292
- }
293
- }
294
- executeDelete(file, command) {
295
- const { itinerary } = command;
296
- if (itinerary === undefined) {
297
- file.content = undefined;
298
- }
299
- const { content } = file;
300
- this.updater.executeDelete(content, itinerary);
301
- }
302
- executeSet(file, command) {
303
- const { itinerary, value } = command;
304
- if (itinerary === undefined) {
305
- file.content = value;
306
- }
307
- const { content } = file;
308
- this.updater.executeSet(content, itinerary, value);
309
- }
310
- executeAdd(file, command) {
311
- const { itinerary, value } = command;
312
- const { content } = file;
313
- this.updater.executeAdd(content, itinerary, value);
314
- }
315
- executeInsert(file, command) {
316
- const { itinerary, value } = command;
317
- if (itinerary === undefined) {
318
- return;
319
- }
320
- const { content } = file;
321
- this.updater.executeInsert(content, itinerary, value);
322
- }
323
- /**
324
- * Executes a batch of commands, rebasing each on previous mutations.
325
- */
326
- executeBatch(file, command) {
327
- const { content } = file;
328
- this.updater.executeBatch(content, command);
329
- }
330
- }
@@ -1,76 +0,0 @@
1
- import { Itinerary, StackElement } from '@hamak/shared-utils';
2
- /**
3
- * Base interface for structure node commands
4
- */
5
- export interface StructureNodeCommandBase {
6
- name: "add-at" | "set-at" | "delete-at" | 'insert-at' | "batch-update";
7
- }
8
- /**
9
- * Base interface for unitary (single operation) commands
10
- */
11
- export interface UnitaryStructureNodeCommandBase extends StructureNodeCommandBase {
12
- name: "add-at" | "set-at" | "delete-at" | 'insert-at';
13
- itinerary: Itinerary;
14
- }
15
- /**
16
- * Base interface for commands that insert/update values
17
- */
18
- export interface StructureNodeUpsertCommandBase extends UnitaryStructureNodeCommandBase {
19
- name: "add-at" | "set-at" | 'insert-at';
20
- prototypes?: StackElement<any>;
21
- }
22
- /**
23
- * Add a value at the specified itinerary
24
- */
25
- export interface AddStructureNodeCommand extends StructureNodeUpsertCommandBase {
26
- name: "add-at";
27
- value: any;
28
- }
29
- /**
30
- * Insert a value at the specified position
31
- */
32
- export interface InsertStructureNodeCommand extends StructureNodeUpsertCommandBase {
33
- name: "insert-at";
34
- value: any;
35
- }
36
- /**
37
- * Set a value at the specified itinerary
38
- */
39
- export interface SetStructureNodeCommand extends StructureNodeUpsertCommandBase {
40
- name: "set-at";
41
- value: any;
42
- }
43
- /**
44
- * Delete a value at the specified itinerary
45
- */
46
- export interface DeleteStructureNodeCommand extends UnitaryStructureNodeCommandBase {
47
- name: "delete-at";
48
- }
49
- /**
50
- * Batch update multiple operations
51
- */
52
- export interface BatchUpdateStructureNodeCommand extends StructureNodeCommandBase {
53
- name: "batch-update";
54
- autoRebase?: boolean;
55
- commands: UnitaryStructureNodeCommand[];
56
- }
57
- /**
58
- * Union type for unitary structure node commands
59
- */
60
- export type UnitaryStructureNodeCommand = AddStructureNodeCommand | InsertStructureNodeCommand | SetStructureNodeCommand | DeleteStructureNodeCommand;
61
- /**
62
- * Union type for all structure node commands
63
- */
64
- export type StructureNodeCommand = UnitaryStructureNodeCommand | BatchUpdateStructureNodeCommand;
65
- /**
66
- * Helper class for creating structure node commands
67
- */
68
- export declare class StructureNodeCommandHelper {
69
- addNode(itinerary: Itinerary, value: any, prototypes?: StackElement<any>): AddStructureNodeCommand;
70
- insertNode(itinerary: Itinerary, value: any, prototypes?: StackElement<any>): InsertStructureNodeCommand;
71
- setNode(itinerary: Itinerary, value: any, prototypes?: StackElement<any>): SetStructureNodeCommand;
72
- deleteNode(itinerary: Itinerary): DeleteStructureNodeCommand;
73
- batchUpdate(commands: UnitaryStructureNodeCommand[], autoRebase?: boolean): BatchUpdateStructureNodeCommand;
74
- }
75
- export declare const structs: StructureNodeCommandHelper;
76
- //# sourceMappingURL=structure-commands.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"structure-commands.d.ts","sourceRoot":"","sources":["../../../src/fs/commands/structure-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,GAAG,cAAc,CAAA;CACvE;AAED;;GAEG;AACH,MAAM,WAAW,+BAAgC,SAAQ,wBAAwB;IAC/E,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAA;IACrD,SAAS,EAAE,SAAS,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,8BAA+B,SAAQ,+BAA+B;IACrF,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAA;IACvC,UAAU,CAAC,EAAG,YAAY,CAAC,GAAG,CAAC,CAAA;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,8BAA8B;IAC7E,IAAI,EAAE,QAAQ,CAAA;IACd,KAAK,EAAE,GAAG,CAAA;CACX;AAED;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,8BAA8B;IAChF,IAAI,EAAE,WAAW,CAAA;IACjB,KAAK,EAAE,GAAG,CAAA;CACX;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,8BAA8B;IAC7E,IAAI,EAAE,QAAQ,CAAA;IACd,KAAK,EAAE,GAAG,CAAA;CACX;AAED;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,+BAA+B;IACjF,IAAI,EAAE,WAAW,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,+BAAgC,SAAQ,wBAAwB;IAC/E,IAAI,EAAE,cAAc,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,2BAA2B,EAAE,CAAA;CACxC;AAED;;GAEG;AACH,MAAM,MAAM,2BAA2B,GACnC,uBAAuB,GACvB,0BAA0B,GAC1B,uBAAuB,GACvB,0BAA0B,CAAA;AAE9B;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,2BAA2B,GAAG,+BAA+B,CAAA;AAEhG;;GAEG;AACH,qBAAa,0BAA0B;IACrC,OAAO,CAAC,SAAS,EAAG,SAAS,EAAE,KAAK,EAAG,GAAG,EAAE,UAAU,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,GAAI,uBAAuB;IAIrG,UAAU,CAAC,SAAS,EAAG,SAAS,EAAE,KAAK,EAAG,GAAG,EAAE,UAAU,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,GAAI,0BAA0B;IAI3G,OAAO,CAAC,SAAS,EAAG,SAAS,EAAE,KAAK,EAAG,GAAG,EAAE,UAAU,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,GAAI,uBAAuB;IAIrG,UAAU,CAAC,SAAS,EAAG,SAAS,GAAI,0BAA0B;IAI9D,WAAW,CAAC,QAAQ,EAAG,2BAA2B,EAAE,EAAE,UAAU,UAAQ,GAAI,+BAA+B;CAG5G;AAED,eAAO,MAAM,OAAO,4BAAmC,CAAA"}
@@ -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,60 +0,0 @@
1
- import { Action } from '@reduxjs/toolkit';
2
- import { FileSystemCommand, FileSystemCommandHandler } from '../commands/fs-commands.js';
3
- import { FileSystemNode, FileSystemState, FileContentSchema, FileSystemNodeActionParams, Selector } from '@hamak/ui-store-api';
4
- import { StructureNodeCommand } from '../commands/structure-commands.js';
5
- /**
6
- * Action interface for filesystem operations
7
- */
8
- export interface FileSystemNodeAction extends Action {
9
- command: FileSystemCommand;
10
- }
11
- /**
12
- * Factory function to create a FileSystemAdapter
13
- */
14
- export declare function createFileSystemAdapter(sliceName: string): FileSystemAdapter;
15
- /**
16
- * Filesystem reducer function type
17
- */
18
- export type FileSystemNodeReducerFn = (state: FileSystemState, action: Action) => FileSystemState;
19
- /**
20
- * FileSystemAdapter - Manages Redux state for virtual filesystem
21
- */
22
- export declare class FileSystemAdapter {
23
- readonly sliceName: string;
24
- readonly actions: FileSystemNodeActions;
25
- readonly commandHandler: FileSystemCommandHandler;
26
- readonly reducer: FileSystemNodeReducerFn;
27
- constructor(sliceName: string);
28
- getInitialState(): FileSystemState;
29
- getActions(): FileSystemNodeActions;
30
- getReducer(extraReducers?: FileSystemNodeReducerFn): FileSystemNodeReducerFn;
31
- createSelector<S>(fileSystemSelector: Selector<S, FileSystemState | undefined>, path: string | string[]): Selector<S, FileSystemNode | undefined>;
32
- }
33
- /**
34
- * FileSystemNodeActions - Action creators for filesystem operations
35
- */
36
- export declare class FileSystemNodeActions {
37
- sliceName: string;
38
- private readonly _mkdirType;
39
- private readonly _setFileType;
40
- private readonly _removeType;
41
- private readonly _updateFileContentType;
42
- private readonly _setFileContentType;
43
- private readonly _setExtensionStateType;
44
- private actionTypeSet;
45
- constructor(sliceName: string);
46
- get mkdirType(): string;
47
- get setFileType(): string;
48
- get removeType(): string;
49
- get updateFileContentType(): string;
50
- get setFileContentType(): string;
51
- get setExtensionStateType(): string;
52
- isFileSystemNodeAction(action: Action): action is FileSystemNodeAction;
53
- mkdir(path: string | string[], parents?: boolean, extensionStates?: Record<string, unknown>): FileSystemNodeAction;
54
- setFile(path: string | string[], content: any, schema: FileContentSchema, params?: FileSystemNodeActionParams): FileSystemNodeAction;
55
- updateFileContent(path: string | string[], contentCommand: StructureNodeCommand): FileSystemNodeAction;
56
- setFileContent(path: string | string[], content: any, fromRemote?: boolean): FileSystemNodeAction;
57
- removeNode(path: string | string[], recursive?: boolean): FileSystemNodeAction;
58
- setExtensionState(path: string | string[], key: string, state: Record<string, unknown>): FileSystemNodeAction;
59
- }
60
- //# sourceMappingURL=fs-adapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs-adapter.d.ts","sourceRoot":"","sources":["../../../src/fs/core/fs-adapter.ts"],"names":[],"mappings":"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"}
@@ -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?.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,37 +0,0 @@
1
- import { FileNode, FileSystemNode, FileSystemState, Selector } from '@hamak/ui-store-api';
2
- import { FileSystemAdapter, FileSystemNodeActions } from './fs-adapter.js';
3
- import { Path, Pathway, PathwayResolver, RelativePathwayResolver } from '@hamak/shared-utils';
4
- /**
5
- * Selector that returns a FileSystemNode generally the root of the Filesystem Overlay
6
- */
7
- export interface StoreFileSystemOverlaySelector<S> {
8
- /**
9
- * The key of the overlay
10
- */
11
- key: string;
12
- selector: Selector<S, FileSystemNode | undefined>;
13
- }
14
- /**
15
- * StoreFileSystemFacade - High-level API for filesystem operations
16
- */
17
- export declare class StoreFileSystemFacade<S = any> {
18
- private fileSystemSelector;
19
- private adapter;
20
- constructor(fileSystemSelector: Selector<S, FileSystemState | undefined>, adapter: FileSystemAdapter);
21
- getActions(): FileSystemNodeActions;
22
- createSelector(path: string | string[]): Selector<S, FileSystemNode | undefined>;
23
- createFileSelector(path: string | string[]): Selector<S, FileNode | undefined>;
24
- selectFromRoot(state: S, path?: string[]): FileSystemNode | undefined;
25
- selectFileFromRoot(state: S, path?: string[]): FileNode | undefined;
26
- }
27
- /**
28
- * StoreFileSystemPathwayResolver - Pathway resolver for filesystem state
29
- */
30
- export declare class StoreFileSystemPathwayResolver<S = any> implements PathwayResolver<FileSystemNode> {
31
- private state;
32
- private fs;
33
- constructor(state: S, fs: StoreFileSystemFacade<S>);
34
- resolve(path: string | string[] | Pathway): FileSystemNode | undefined;
35
- relativeTo(path: Path): RelativePathwayResolver<FileSystemNode>;
36
- }
37
- //# sourceMappingURL=fs-facade.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs-facade.d.ts","sourceRoot":"","sources":["../../../src/fs/core/fs-facade.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,QAAQ,EACR,cAAc,EACd,eAAe,EACf,QAAQ,EACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9F;;GAEG;AACH,MAAM,WAAW,8BAA8B,CAAC,CAAC;IAC/C;;OAEG;IACH,GAAG,EAAG,MAAM,CAAC;IACb,QAAQ,EAAG,QAAQ,CAAC,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC,CAAA;CACnD;AAED;;GAEG;AACH,qBAAa,qBAAqB,CAAC,CAAC,GAAG,GAAG;IAEtC,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,OAAO;gBADP,kBAAkB,EAAE,QAAQ,CAAC,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,EAC5D,OAAO,EAAG,iBAAiB;IAGrC,UAAU,IAAK,qBAAqB;IAIpC,cAAc,CAAC,IAAI,EAAG,MAAM,GAAG,MAAM,EAAE,GAAI,QAAQ,CAAC,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IAIlF,kBAAkB,CAAC,IAAI,EAAG,MAAM,GAAG,MAAM,EAAE,GAAI,QAAQ,CAAC,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAWhF,cAAc,CAAC,KAAK,EAAG,CAAC,EAAE,IAAI,GAAG,MAAM,EAAO,GAAI,cAAc,GAAG,SAAS;IAmB5E,kBAAkB,CAAC,KAAK,EAAG,CAAC,EAAE,IAAI,GAAG,MAAM,EAAO,GAAI,QAAQ,GAAG,SAAS;CAY3E;AAGD;;GAEG;AACH,qBAAa,8BAA8B,CAAC,CAAC,GAAG,GAAG,CAAE,YAAW,eAAe,CAAC,cAAc,CAAC;IACjF,OAAO,CAAC,KAAK;IAAM,OAAO,CAAC,EAAE;gBAArB,KAAK,EAAG,CAAC,EAAU,EAAE,EAAG,qBAAqB,CAAC,CAAC,CAAC;IAGpE,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,GAAG,cAAc,GAAG,SAAS;IAKtE,UAAU,CAAC,IAAI,EAAG,IAAI,GAAI,uBAAuB,CAAC,cAAc,CAAC;CAGlE"}