@hamak/ui-store-impl 0.3.0 → 0.4.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/CHANGELOG.md +18 -0
- package/dist/es2015/fs/commands/fs-commands.js +311 -0
- package/dist/es2015/fs/commands/structure-commands.js +21 -0
- package/dist/es2015/fs/core/fs-adapter.js +123 -0
- package/dist/es2015/fs/core/fs-facade.js +78 -0
- package/dist/es2015/fs/index.js +9 -0
- package/dist/es2015/fs/utils/data-updater.js +244 -0
- package/dist/es2015/fs/utils/deep-equal.js +28 -0
- package/dist/es2015/index.js +1 -0
- package/dist/fs/commands/fs-commands.d.ts +96 -0
- package/dist/fs/commands/fs-commands.d.ts.map +1 -0
- package/dist/fs/commands/fs-commands.js +311 -0
- package/dist/fs/commands/structure-commands.d.ts +76 -0
- package/dist/fs/commands/structure-commands.d.ts.map +1 -0
- package/dist/fs/commands/structure-commands.js +21 -0
- package/dist/fs/core/fs-adapter.d.ts +57 -0
- package/dist/fs/core/fs-adapter.d.ts.map +1 -0
- package/dist/fs/core/fs-adapter.js +123 -0
- package/dist/fs/core/fs-facade.d.ts +37 -0
- package/dist/fs/core/fs-facade.d.ts.map +1 -0
- package/dist/fs/core/fs-facade.js +78 -0
- package/dist/fs/index.d.ts +7 -0
- package/dist/fs/index.d.ts.map +1 -0
- package/dist/fs/index.js +9 -0
- package/dist/fs/utils/data-updater.d.ts +36 -0
- package/dist/fs/utils/data-updater.d.ts.map +1 -0
- package/dist/fs/utils/data-updater.js +248 -0
- package/dist/fs/utils/deep-equal.d.ts +5 -0
- package/dist/fs/utils/deep-equal.d.ts.map +1 -0
- package/dist/fs/utils/deep-equal.js +28 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +8 -5
- package/src/fs/commands/fs-commands.ts +406 -0
- package/src/fs/commands/structure-commands.ts +105 -0
- package/src/fs/core/fs-adapter.ts +180 -0
- package/src/fs/core/fs-facade.ts +100 -0
- package/src/fs/index.ts +11 -0
- package/src/fs/utils/data-updater.ts +273 -0
- package/src/fs/utils/deep-equal.ts +35 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Itinerary, StackElement } from '@hamak/navigation-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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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2B,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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Action } from '@reduxjs/toolkit';
|
|
2
|
+
import { FileSystemCommand, FileSystemCommandHandler } from '../commands/fs-commands';
|
|
3
|
+
import { FileSystemNode, FileSystemState, FileContentSchema, FileSystemNodeActionParams, Selector } from '@hamak/ui-store-api';
|
|
4
|
+
import { StructureNodeCommand } from '../commands/structure-commands';
|
|
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 actionTypeSet;
|
|
44
|
+
constructor(sliceName: string);
|
|
45
|
+
get mkdirType(): string;
|
|
46
|
+
get setFileType(): string;
|
|
47
|
+
get removeType(): string;
|
|
48
|
+
get updateFileContentType(): string;
|
|
49
|
+
get setFileContentType(): string;
|
|
50
|
+
isFileSystemNodeAction(action: Action): action is FileSystemNodeAction;
|
|
51
|
+
mkdir(path: string | string[], parents?: boolean): FileSystemNodeAction;
|
|
52
|
+
setFile(path: string | string[], content: any, schema: FileContentSchema, params?: FileSystemNodeActionParams): FileSystemNodeAction;
|
|
53
|
+
updateFileContent(path: string | string[], contentCommand: StructureNodeCommand): FileSystemNodeAction;
|
|
54
|
+
setFileContent(path: string | string[], content: any, fromRemote?: boolean): FileSystemNodeAction;
|
|
55
|
+
removeNode(path: string | string[], recursive?: boolean): FileSystemNodeAction;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=fs-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-adapter.d.ts","sourceRoot":"","sources":["../../../src/fs/core/fs-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EAEzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,cAAc,EAEd,eAAe,EACf,iBAAiB,EACjB,0BAA0B,EAC1B,QAAQ,EACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,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AM,CAElC;IAED,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,oBAAoB;IAI/D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAC,OAAO,GAAG,oBAAoB;IAOtE,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAC,GAAG,EAAE,MAAM,EAAG,iBAAiB,EAAE,MAAM,GAAG,0BAAoE,GAAG,oBAAoB;IAQ9K,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,cAAc,EAAG,oBAAoB,GAAI,oBAAoB;IAOxG,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAG,GAAG,EAAE,UAAU,UAAQ,GAAG,oBAAoB;IAQhG,UAAU,CAAC,IAAI,EAAG,MAAM,GAAG,MAAM,EAAE,EAAE,SAAS,CAAC,EAAG,OAAO,GAAG,oBAAoB;CAOxF"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { createSelector } from '@reduxjs/toolkit';
|
|
2
|
+
import { FileSystemCommandHandler, pathSteps } from '../commands/fs-commands';
|
|
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.actionTypeSet = new Set([
|
|
67
|
+
this._mkdirType,
|
|
68
|
+
this._setFileType,
|
|
69
|
+
this._removeType,
|
|
70
|
+
this._updateFileContentType,
|
|
71
|
+
this._setFileContentType
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
get mkdirType() {
|
|
75
|
+
return this._mkdirType;
|
|
76
|
+
}
|
|
77
|
+
get setFileType() {
|
|
78
|
+
return this._setFileType;
|
|
79
|
+
}
|
|
80
|
+
get removeType() {
|
|
81
|
+
return this._removeType;
|
|
82
|
+
}
|
|
83
|
+
get updateFileContentType() {
|
|
84
|
+
return this._updateFileContentType;
|
|
85
|
+
}
|
|
86
|
+
get setFileContentType() {
|
|
87
|
+
return this._setFileContentType;
|
|
88
|
+
}
|
|
89
|
+
isFileSystemNodeAction(action) {
|
|
90
|
+
return this.actionTypeSet.has(action.type);
|
|
91
|
+
}
|
|
92
|
+
mkdir(path, parents) {
|
|
93
|
+
return {
|
|
94
|
+
type: this.mkdirType,
|
|
95
|
+
command: { name: 'mkdir', path, parents }
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
setFile(path, content, schema, params = { override: true, contentIsPresent: true }) {
|
|
99
|
+
const { override, contentIsPresent } = params;
|
|
100
|
+
return {
|
|
101
|
+
type: this.setFileType,
|
|
102
|
+
command: { name: 'set-file', path, content, schema, override, contentIsPresent }
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
updateFileContent(path, contentCommand) {
|
|
106
|
+
return {
|
|
107
|
+
type: this.updateFileContentType,
|
|
108
|
+
command: { name: 'update-file-content', path, contentCommand }
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
setFileContent(path, content, fromRemote = false) {
|
|
112
|
+
return {
|
|
113
|
+
type: this.setFileContentType,
|
|
114
|
+
command: { name: 'set-file-content', path, content, fromRemote }
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
removeNode(path, recursive) {
|
|
118
|
+
return {
|
|
119
|
+
type: this.removeType,
|
|
120
|
+
command: { name: 'remove', path, recursive }
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { FileNode, FileSystemNode, FileSystemState, Selector } from '@hamak/ui-store-api';
|
|
2
|
+
import { FileSystemAdapter, FileSystemNodeActions } from './fs-adapter';
|
|
3
|
+
import { Path, Pathway, PathwayResolver, RelativePathwayResolver } from '@hamak/navigation-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
|
|
@@ -0,0 +1 @@
|
|
|
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,yBAAyB,CAAC;AAElG;;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"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createSelector } from '@reduxjs/toolkit';
|
|
2
|
+
import { Pathway, RelativePathwayResolver } from '@hamak/navigation-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?.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 ?? []).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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './core/fs-adapter';
|
|
2
|
+
export * from './core/fs-facade';
|
|
3
|
+
export * from './commands/fs-commands';
|
|
4
|
+
export * from './commands/structure-commands';
|
|
5
|
+
export * from './utils/data-updater';
|
|
6
|
+
export * from './utils/deep-equal';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fs/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAG9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
|
package/dist/fs/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Core filesystem functionality
|
|
2
|
+
export * from './core/fs-adapter';
|
|
3
|
+
export * from './core/fs-facade';
|
|
4
|
+
// Commands
|
|
5
|
+
export * from './commands/fs-commands';
|
|
6
|
+
export * from './commands/structure-commands';
|
|
7
|
+
// Utilities
|
|
8
|
+
export * from './utils/data-updater';
|
|
9
|
+
export * from './utils/deep-equal';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Itinerary, StackElement } from '@hamak/navigation-utils';
|
|
2
|
+
import { UnitaryStructureNodeCommand, BatchUpdateStructureNodeCommand } from '../commands/structure-commands';
|
|
3
|
+
/**
|
|
4
|
+
* DataUpdater class handles operations on data structures using itineraries
|
|
5
|
+
*/
|
|
6
|
+
export declare class DataUpdater {
|
|
7
|
+
/**
|
|
8
|
+
* Delete a value at the specified itinerary
|
|
9
|
+
*/
|
|
10
|
+
executeDelete(data: any, itinerary: Itinerary | undefined): void;
|
|
11
|
+
/**
|
|
12
|
+
* Set a value at the specified itinerary
|
|
13
|
+
*/
|
|
14
|
+
executeSet(data: any, itinerary: Itinerary | undefined, value: any, prototypeToParent?: StackElement<any>): void;
|
|
15
|
+
/**
|
|
16
|
+
* Add a value at the specified itinerary
|
|
17
|
+
*/
|
|
18
|
+
executeAdd(data: any, itinerary: Itinerary | undefined, value: any, prototypeToParent?: StackElement<any>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Insert a value at the specified position
|
|
21
|
+
*/
|
|
22
|
+
executeInsert(data: any, itinerary: Itinerary, value: any, prototypeToParent?: StackElement<any>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Rebase a pending command's itinerary on top of an altering command.
|
|
25
|
+
* Returns null if the pending command should be dropped (e.g., targets a deleted element).
|
|
26
|
+
* Enhanced: Handles rebasing for nested itineraries, not just at the first divergence.
|
|
27
|
+
*/
|
|
28
|
+
rebasePendingCommandOn(alteringCmd: UnitaryStructureNodeCommand, pendingCmd: UnitaryStructureNodeCommand): UnitaryStructureNodeCommand | null;
|
|
29
|
+
/**
|
|
30
|
+
* Executes a batch of commands, rebasing each on previous mutations.
|
|
31
|
+
* @param data The data object to mutate
|
|
32
|
+
* @param command The batch update command
|
|
33
|
+
*/
|
|
34
|
+
executeBatch(data: any, command: BatchUpdateStructureNodeCommand): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=data-updater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-updater.d.ts","sourceRoot":"","sources":["../../../src/fs/utils/data-updater.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,YAAY,EAKb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAChC,MAAM,gCAAgC,CAAC;AAyBxC;;GAEG;AACH,qBAAa,WAAW;IAEtB;;OAEG;IACI,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS;IA8BhE;;OAEG;IACI,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,iBAAiB,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC;IA+BhH;;OAEG;IACI,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,iBAAiB,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC;IAahH;;OAEG;IACI,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,iBAAiB,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC;IAkBvG;;;;OAIG;IACI,sBAAsB,CAC3B,WAAW,EAAE,2BAA2B,EACxC,UAAU,EAAE,2BAA2B,GACtC,2BAA2B,GAAG,IAAI;IAqFrC;;;;OAIG;IACI,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,+BAA+B,GAAG,IAAI;CA4B/E"}
|