@hamak/ui-remote-fs-impl 0.4.3
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/dist/actions/index.d.ts +5 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +4 -0
- package/dist/actions/remote-fs-actions.d.ts +189 -0
- package/dist/actions/remote-fs-actions.d.ts.map +1 -0
- package/dist/actions/remote-fs-actions.js +146 -0
- package/dist/es2015/actions/index.js +20 -0
- package/dist/es2015/actions/remote-fs-actions.js +147 -0
- package/dist/es2015/index.js +25 -0
- package/dist/es2015/middleware/index.js +21 -0
- package/dist/es2015/middleware/remote-fs-middleware.js +205 -0
- package/dist/es2015/middleware/store-sync-middleware.js +138 -0
- package/dist/es2015/plugin/index.js +20 -0
- package/dist/es2015/plugin/remote-fs-plugin-factory.js +169 -0
- package/dist/es2015/providers/http-workspace-client.js +199 -0
- package/dist/es2015/providers/index.js +20 -0
- package/dist/es2015/services/index.js +20 -0
- package/dist/es2015/services/remote-fs-service.js +16 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/middleware/index.d.ts +6 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +5 -0
- package/dist/middleware/remote-fs-middleware.d.ts +50 -0
- package/dist/middleware/remote-fs-middleware.d.ts.map +1 -0
- package/dist/middleware/remote-fs-middleware.js +192 -0
- package/dist/middleware/store-sync-middleware.d.ts +35 -0
- package/dist/middleware/store-sync-middleware.d.ts.map +1 -0
- package/dist/middleware/store-sync-middleware.js +134 -0
- package/dist/plugin/index.d.ts +5 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +4 -0
- package/dist/plugin/remote-fs-plugin-factory.d.ts +84 -0
- package/dist/plugin/remote-fs-plugin-factory.d.ts.map +1 -0
- package/dist/plugin/remote-fs-plugin-factory.js +150 -0
- package/dist/providers/http-workspace-client.d.ts +99 -0
- package/dist/providers/http-workspace-client.d.ts.map +1 -0
- package/dist/providers/http-workspace-client.js +171 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +4 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +4 -0
- package/dist/services/remote-fs-service.d.ts +10 -0
- package/dist/services/remote-fs-service.d.ts.map +1 -0
- package/dist/services/remote-fs-service.js +12 -0
- package/package.json +56 -0
- package/project.json +24 -0
- package/src/actions/index.ts +5 -0
- package/src/actions/remote-fs-actions.ts +302 -0
- package/src/index.ts +10 -0
- package/src/middleware/index.ts +6 -0
- package/src/middleware/remote-fs-middleware.ts +244 -0
- package/src/middleware/store-sync-middleware.ts +175 -0
- package/src/plugin/index.ts +5 -0
- package/src/plugin/remote-fs-plugin-factory.ts +238 -0
- package/src/providers/http-workspace-client.ts +232 -0
- package/src/providers/index.ts +5 -0
- package/src/services/index.ts +5 -0
- package/src/services/remote-fs-service.ts +13 -0
- package/tsconfig.es2015.json +21 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Remote FS Middleware
|
|
4
|
+
*
|
|
5
|
+
* Redux middleware for handling remote filesystem operations via HTTP client.
|
|
6
|
+
* Migrated from amk/libs/ui/core/remote-fs/src/lib/remote-fs-middleware.ts
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.createRemoteFsMiddleware = void 0;
|
|
19
|
+
const shared_utils_1 = require("@hamak/shared-utils");
|
|
20
|
+
const ui_remote_fs_api_1 = require("@hamak/ui-remote-fs-api");
|
|
21
|
+
const remote_fs_actions_1 = require("../actions/remote-fs-actions");
|
|
22
|
+
/**
|
|
23
|
+
* Create remote filesystem middleware
|
|
24
|
+
*
|
|
25
|
+
* This middleware intercepts remote FS actions and executes them via the provided
|
|
26
|
+
* workspace client. It handles path translation from local mount point to remote paths.
|
|
27
|
+
*
|
|
28
|
+
* @param config Middleware configuration
|
|
29
|
+
* @returns Redux middleware
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const middleware = createRemoteFsMiddleware({
|
|
34
|
+
* client: new HttpWorkspaceClient({ workspaceId: '0' }),
|
|
35
|
+
* pathTranslator: new PathTranslator(Pathway.ofRoot().resolve('remote'))
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function createRemoteFsMiddleware(config) {
|
|
40
|
+
const { client, pathTranslator, onError, onSuccess } = config;
|
|
41
|
+
/**
|
|
42
|
+
* Translate local path to remote path
|
|
43
|
+
*/
|
|
44
|
+
const toRemotePath = (path) => {
|
|
45
|
+
const pathway = Array.isArray(path) ? shared_utils_1.Pathway.of(path) : shared_utils_1.Pathway.of([path]);
|
|
46
|
+
return pathTranslator.toRemotePath(pathway);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Handle errors and convert to ErrorObject
|
|
50
|
+
*/
|
|
51
|
+
const handleError = (error) => {
|
|
52
|
+
if (error && typeof error === 'object' && 'code' in error && 'message' in error) {
|
|
53
|
+
return error;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
code: (error === null || error === void 0 ? void 0 : error.code) || 'UNKNOWN',
|
|
57
|
+
message: (error === null || error === void 0 ? void 0 : error.message) || 'Unknown error',
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const remoteFsMiddleware = (store) => (next) => (action) => {
|
|
61
|
+
const result = next(action);
|
|
62
|
+
const dispatch = store.dispatch;
|
|
63
|
+
const anyAction = action;
|
|
64
|
+
switch (anyAction.type) {
|
|
65
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.LS_REQUEST: {
|
|
66
|
+
const requestAction = anyAction;
|
|
67
|
+
const remotePath = toRemotePath(requestAction.payload.path);
|
|
68
|
+
if (remotePath === undefined) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
void (() => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
try {
|
|
73
|
+
const data = yield client.listFiles(remotePath.getSegments());
|
|
74
|
+
const completedAction = remote_fs_actions_1.rfsActions.ofLsCompleted(data, requestAction);
|
|
75
|
+
dispatch(completedAction);
|
|
76
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data, completedAction);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
const errorObject = handleError(error);
|
|
80
|
+
const failedAction = remote_fs_actions_1.rfsActions.ofLsFailed(errorObject, requestAction);
|
|
81
|
+
dispatch(failedAction);
|
|
82
|
+
onError === null || onError === void 0 ? void 0 : onError(errorObject, failedAction);
|
|
83
|
+
}
|
|
84
|
+
}))();
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.MKDIR_REQUEST: {
|
|
88
|
+
const requestAction = anyAction;
|
|
89
|
+
const remotePath = toRemotePath(requestAction.payload.path);
|
|
90
|
+
if (remotePath === undefined) {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
void (() => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
try {
|
|
95
|
+
const data = yield client.createDirectory(remotePath.getSegments());
|
|
96
|
+
const completedAction = remote_fs_actions_1.rfsActions.ofMkdirCompleted(data, requestAction);
|
|
97
|
+
dispatch(completedAction);
|
|
98
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data, completedAction);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
const errorObject = handleError(error);
|
|
102
|
+
const failedAction = remote_fs_actions_1.rfsActions.ofMkdirFailed(errorObject, requestAction);
|
|
103
|
+
dispatch(failedAction);
|
|
104
|
+
onError === null || onError === void 0 ? void 0 : onError(errorObject, failedAction);
|
|
105
|
+
}
|
|
106
|
+
}))();
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.GET_REQUEST: {
|
|
110
|
+
const requestAction = anyAction;
|
|
111
|
+
const remotePath = toRemotePath(requestAction.payload.path);
|
|
112
|
+
if (remotePath === undefined) {
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
void (() => __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
try {
|
|
117
|
+
const data = yield client.readFile(remotePath.getSegments());
|
|
118
|
+
const completedAction = remote_fs_actions_1.rfsActions.ofGetCompleted(data, requestAction);
|
|
119
|
+
dispatch(completedAction);
|
|
120
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data, completedAction);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
const errorObject = handleError(error);
|
|
124
|
+
const failedAction = remote_fs_actions_1.rfsActions.ofGetFailed(errorObject, requestAction);
|
|
125
|
+
dispatch(failedAction);
|
|
126
|
+
onError === null || onError === void 0 ? void 0 : onError(errorObject, failedAction);
|
|
127
|
+
}
|
|
128
|
+
}))();
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.POST_REQUEST: {
|
|
132
|
+
const requestAction = anyAction;
|
|
133
|
+
const remotePath = toRemotePath(requestAction.payload.path);
|
|
134
|
+
if (remotePath === undefined) {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
void (() => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
try {
|
|
139
|
+
const data = yield client.putFile(remotePath.getSegments(), requestAction.payload.content);
|
|
140
|
+
const completedAction = remote_fs_actions_1.rfsActions.ofPostCompleted(data, requestAction);
|
|
141
|
+
dispatch(completedAction);
|
|
142
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data, completedAction);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
const errorObject = handleError(error);
|
|
146
|
+
const failedAction = remote_fs_actions_1.rfsActions.ofPostFailed(errorObject, requestAction);
|
|
147
|
+
dispatch(failedAction);
|
|
148
|
+
onError === null || onError === void 0 ? void 0 : onError(errorObject, failedAction);
|
|
149
|
+
}
|
|
150
|
+
}))();
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.PUT_REQUEST: {
|
|
154
|
+
const requestAction = anyAction;
|
|
155
|
+
const remotePath = toRemotePath(requestAction.payload.path);
|
|
156
|
+
if (remotePath === undefined) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
void (() => __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
try {
|
|
161
|
+
const data = yield client.putFile(remotePath.getSegments(), requestAction.payload.content);
|
|
162
|
+
const completedAction = remote_fs_actions_1.rfsActions.ofPutCompleted(data, requestAction);
|
|
163
|
+
dispatch(completedAction);
|
|
164
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data, completedAction);
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
const errorObject = handleError(error);
|
|
168
|
+
const failedAction = remote_fs_actions_1.rfsActions.ofPutFailed(errorObject, requestAction);
|
|
169
|
+
dispatch(failedAction);
|
|
170
|
+
onError === null || onError === void 0 ? void 0 : onError(errorObject, failedAction);
|
|
171
|
+
}
|
|
172
|
+
}))();
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.DELETE_REQUEST: {
|
|
176
|
+
const requestAction = anyAction;
|
|
177
|
+
const remotePath = toRemotePath(requestAction.payload.path);
|
|
178
|
+
if (remotePath === undefined) {
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
void (() => __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
try {
|
|
183
|
+
const data = yield client.deleteFile(remotePath.getSegments());
|
|
184
|
+
const completedAction = remote_fs_actions_1.rfsActions.ofDeleteCompleted(data, requestAction);
|
|
185
|
+
dispatch(completedAction);
|
|
186
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data, completedAction);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
const errorObject = handleError(error);
|
|
190
|
+
const failedAction = remote_fs_actions_1.rfsActions.ofDeleteFailed(errorObject, requestAction);
|
|
191
|
+
dispatch(failedAction);
|
|
192
|
+
onError === null || onError === void 0 ? void 0 : onError(errorObject, failedAction);
|
|
193
|
+
}
|
|
194
|
+
}))();
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
default:
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
};
|
|
202
|
+
return remoteFsMiddleware;
|
|
203
|
+
}
|
|
204
|
+
exports.createRemoteFsMiddleware = createRemoteFsMiddleware;
|
|
205
|
+
exports.default = createRemoteFsMiddleware;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Store Sync Middleware
|
|
4
|
+
*
|
|
5
|
+
* Redux middleware for synchronizing remote filesystem operations to Redux Store FS.
|
|
6
|
+
* This middleware listens to remote FS completion actions and updates the Store FS accordingly.
|
|
7
|
+
* Migrated from amk/libs/ui/core/remote-fs/src/lib/store-fs-adapter-middleware.ts
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createStoreSyncMiddleware = void 0;
|
|
11
|
+
const shared_utils_1 = require("@hamak/shared-utils");
|
|
12
|
+
const ui_remote_fs_api_1 = require("@hamak/ui-remote-fs-api");
|
|
13
|
+
const remote_fs_actions_1 = require("../actions/remote-fs-actions");
|
|
14
|
+
/**
|
|
15
|
+
* Create store sync middleware
|
|
16
|
+
*
|
|
17
|
+
* This middleware intercepts remote FS completion actions and synchronizes them
|
|
18
|
+
* to the Redux Store FileSystem. It handles:
|
|
19
|
+
* - LS_COMPLETED: Creates directories and file entries in Store FS
|
|
20
|
+
* - MKDIR_COMPLETED: Creates directory in Store FS
|
|
21
|
+
* - GET_COMPLETED: Creates/updates file content in Store FS
|
|
22
|
+
* - POST/PUT_COMPLETED: Reloads file content from remote
|
|
23
|
+
* - DELETE_COMPLETED: Removes node from Store FS
|
|
24
|
+
*
|
|
25
|
+
* @param config Middleware configuration
|
|
26
|
+
* @returns Redux middleware
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const middleware = createStoreSyncMiddleware({
|
|
31
|
+
* fileSystemAdapter: storeFs,
|
|
32
|
+
* pathTranslator: new PathTranslator(Pathway.ofRoot().resolve('remote')),
|
|
33
|
+
* autoReload: true
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function createStoreSyncMiddleware(config) {
|
|
38
|
+
const { fileSystemAdapter, pathTranslator, autoReload = true, transformContent } = config;
|
|
39
|
+
const storeFsActions = fileSystemAdapter.getActions();
|
|
40
|
+
const storeSyncMiddleware = (store) => (next) => (action) => {
|
|
41
|
+
const result = next(action);
|
|
42
|
+
const anyAction = action;
|
|
43
|
+
// Only process remote FS actions
|
|
44
|
+
if (!remote_fs_actions_1.rfsActions.isRemoteFsAction(anyAction)) {
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
const dispatch = store.dispatch;
|
|
48
|
+
switch (anyAction.type) {
|
|
49
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.LS_COMPLETED: {
|
|
50
|
+
const completedAction = anyAction;
|
|
51
|
+
const { request, data } = completedAction.payload;
|
|
52
|
+
// Iterate through file list and create entries in Store FS
|
|
53
|
+
data === null || data === void 0 ? void 0 : data.forEach((fileInfo) => {
|
|
54
|
+
// Build local path: request path + file name
|
|
55
|
+
const localPath = shared_utils_1.Pathway.of(request.payload.path)
|
|
56
|
+
.resolve(fileInfo.name)
|
|
57
|
+
.getSegments();
|
|
58
|
+
if (fileInfo.isDirectory) {
|
|
59
|
+
// Create directory with parents flag
|
|
60
|
+
dispatch(storeFsActions.mkdir(localPath, true));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Create file entry without content (contentIsPresent: false)
|
|
64
|
+
dispatch(storeFsActions.setFile(localPath, undefined, 'xs:any', {
|
|
65
|
+
override: true,
|
|
66
|
+
contentIsPresent: false,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.MKDIR_COMPLETED: {
|
|
73
|
+
const completedAction = anyAction;
|
|
74
|
+
const { request } = completedAction.payload;
|
|
75
|
+
const localPath = shared_utils_1.Pathway.of(request.payload.path).getSegments();
|
|
76
|
+
// Create directory in Store FS
|
|
77
|
+
dispatch(storeFsActions.mkdir(localPath, true));
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.GET_COMPLETED: {
|
|
81
|
+
const completedAction = anyAction;
|
|
82
|
+
const { request, data } = completedAction.payload;
|
|
83
|
+
const localPath = shared_utils_1.Pathway.of(request.payload.path).getSegments();
|
|
84
|
+
// Parse content
|
|
85
|
+
let content = data.content === undefined || data.content === null
|
|
86
|
+
? undefined
|
|
87
|
+
: data.content === ''
|
|
88
|
+
? undefined
|
|
89
|
+
: JSON.parse(data.content);
|
|
90
|
+
// Apply content transform if provided
|
|
91
|
+
if (content !== undefined && transformContent) {
|
|
92
|
+
content = transformContent(content);
|
|
93
|
+
}
|
|
94
|
+
// Check if file exists in Store FS
|
|
95
|
+
const fileSystemNode = fileSystemAdapter.createSelector((state) => state.fileSystem, localPath)(store.getState());
|
|
96
|
+
if (fileSystemNode === undefined) {
|
|
97
|
+
// File doesn't exist, create it with content
|
|
98
|
+
dispatch(storeFsActions.setFile(localPath, content, 'xs:any', {
|
|
99
|
+
override: true,
|
|
100
|
+
contentIsPresent: true,
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// File exists, update content only if it's a file
|
|
105
|
+
if ((fileSystemNode === null || fileSystemNode === void 0 ? void 0 : fileSystemNode.type) === 'file') {
|
|
106
|
+
dispatch(storeFsActions.setFileContent(localPath, content, true));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.POST_COMPLETED:
|
|
112
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.PUT_COMPLETED: {
|
|
113
|
+
const completedAction = anyAction;
|
|
114
|
+
const { request } = completedAction.payload;
|
|
115
|
+
const localPath = shared_utils_1.Pathway.of(request.payload.path).getSegments();
|
|
116
|
+
// Reload file content from remote if autoReload is enabled
|
|
117
|
+
if (autoReload) {
|
|
118
|
+
dispatch(remote_fs_actions_1.rfsActions.ofGetRequest(localPath));
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case ui_remote_fs_api_1.RemoteFsActionTypes.DELETE_COMPLETED: {
|
|
123
|
+
const completedAction = anyAction;
|
|
124
|
+
const { request } = completedAction.payload;
|
|
125
|
+
const localPath = shared_utils_1.Pathway.of(request.payload.path).getSegments();
|
|
126
|
+
// Remove node from Store FS
|
|
127
|
+
dispatch(storeFsActions.removeNode(localPath));
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
default:
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
};
|
|
135
|
+
return storeSyncMiddleware;
|
|
136
|
+
}
|
|
137
|
+
exports.createStoreSyncMiddleware = createStoreSyncMiddleware;
|
|
138
|
+
exports.default = createStoreSyncMiddleware;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Remote FS Plugin Factory
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./remote-fs-plugin-factory"), exports);
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Remote FS Plugin Factory
|
|
4
|
+
*
|
|
5
|
+
* Creates a microkernel plugin for remote filesystem operations.
|
|
6
|
+
* Integrates HTTP-based remote filesystem with Redux Store FS.
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.createRemoteFsPlugin = void 0;
|
|
19
|
+
const ui_remote_fs_api_1 = require("@hamak/ui-remote-fs-api");
|
|
20
|
+
const ui_remote_fs_spi_1 = require("@hamak/ui-remote-fs-spi");
|
|
21
|
+
const http_workspace_client_1 = require("../providers/http-workspace-client");
|
|
22
|
+
const remote_fs_middleware_1 = require("../middleware/remote-fs-middleware");
|
|
23
|
+
const store_sync_middleware_1 = require("../middleware/store-sync-middleware");
|
|
24
|
+
const ui_store_api_1 = require("@hamak/ui-store-api");
|
|
25
|
+
/**
|
|
26
|
+
* Create Remote FS plugin
|
|
27
|
+
*
|
|
28
|
+
* This plugin provides remote filesystem capabilities through HTTP API.
|
|
29
|
+
* It registers two middleware:
|
|
30
|
+
* - Remote FS Middleware: Handles remote operations via HTTP client
|
|
31
|
+
* - Store Sync Middleware: Synchronizes remote data to Redux Store FS
|
|
32
|
+
*
|
|
33
|
+
* @param config Plugin configuration
|
|
34
|
+
* @returns PluginModule for microkernel integration
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { Pathway } from '@hamak/shared-utils';
|
|
39
|
+
* import { createRemoteFsPlugin } from '@hamak/ui-remote-fs-impl';
|
|
40
|
+
*
|
|
41
|
+
* const plugin = createRemoteFsPlugin({
|
|
42
|
+
* workspaceId: '0',
|
|
43
|
+
* mountPoint: Pathway.ofRoot().resolve('remote'),
|
|
44
|
+
* baseUrl: 'http://localhost:3000/api',
|
|
45
|
+
* autoReload: true
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
function createRemoteFsPlugin(config) {
|
|
50
|
+
let workspaceClient;
|
|
51
|
+
let pathTranslator;
|
|
52
|
+
let storeManager;
|
|
53
|
+
const log = (message, ...args) => {
|
|
54
|
+
if (config.debug) {
|
|
55
|
+
console.log(`[ui-remote-fs] ${message}`, ...args);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
initialize(ctx) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
log('Initializing plugin...');
|
|
62
|
+
// Create or use custom workspace client
|
|
63
|
+
if (config.customClient) {
|
|
64
|
+
workspaceClient = config.customClient;
|
|
65
|
+
log('Using custom workspace client');
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const clientConfig = {
|
|
69
|
+
workspaceId: config.workspaceId,
|
|
70
|
+
baseUrl: config.baseUrl,
|
|
71
|
+
timeout: config.timeout,
|
|
72
|
+
};
|
|
73
|
+
workspaceClient = new http_workspace_client_1.HttpWorkspaceClient(clientConfig);
|
|
74
|
+
log('Created HTTP workspace client', { baseUrl: config.baseUrl, workspaceId: config.workspaceId });
|
|
75
|
+
}
|
|
76
|
+
// Create or use custom path translator
|
|
77
|
+
if (config.customPathTranslator) {
|
|
78
|
+
pathTranslator = config.customPathTranslator;
|
|
79
|
+
log('Using custom path translator');
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
pathTranslator = new ui_remote_fs_spi_1.PathTranslator(config.mountPoint);
|
|
83
|
+
log('Created path translator', { mountPoint: config.mountPoint.getSegments() });
|
|
84
|
+
}
|
|
85
|
+
// Register services via DI
|
|
86
|
+
ctx.provide({ provide: ui_remote_fs_api_1.WORKSPACE_CLIENT_TOKEN, useValue: workspaceClient });
|
|
87
|
+
ctx.provide({ provide: ui_remote_fs_api_1.PATH_TRANSLATOR_TOKEN, useValue: pathTranslator });
|
|
88
|
+
// Note: IRemoteFsService implementation will be added in future phases
|
|
89
|
+
// ctx.provide({ provide: REMOTE_FS_SERVICE_TOKEN, useValue: remoteFsService });
|
|
90
|
+
log('Plugin initialized');
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
activate(ctx) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
log('Activating plugin...');
|
|
96
|
+
// Resolve store manager from DI
|
|
97
|
+
try {
|
|
98
|
+
storeManager = ctx.resolve(ui_store_api_1.STORE_MANAGER_TOKEN);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
throw new Error('[ui-remote-fs] Store manager not found. Ensure @hamak/ui-store plugin is loaded before ui-remote-fs.');
|
|
102
|
+
}
|
|
103
|
+
// Get file system adapter from store
|
|
104
|
+
const fileSystemAdapter = storeManager.getFileSystemAdapter();
|
|
105
|
+
if (!fileSystemAdapter) {
|
|
106
|
+
throw new Error('[ui-remote-fs] File system adapter not found in store manager.');
|
|
107
|
+
}
|
|
108
|
+
// Get store extensions collector
|
|
109
|
+
const extensionsCollector = ctx.resolve(ui_store_api_1.STORE_EXTENSIONS_TOKEN);
|
|
110
|
+
// Create and register remote FS middleware
|
|
111
|
+
const remoteFsMiddleware = (0, remote_fs_middleware_1.createRemoteFsMiddleware)({
|
|
112
|
+
client: workspaceClient,
|
|
113
|
+
pathTranslator,
|
|
114
|
+
onError: (error, action) => {
|
|
115
|
+
log('Remote FS error:', error, action);
|
|
116
|
+
ctx.hooks.emit('ui-remote-fs:error', { error, action });
|
|
117
|
+
},
|
|
118
|
+
onSuccess: (result, action) => {
|
|
119
|
+
log('Remote FS success:', action.type);
|
|
120
|
+
ctx.hooks.emit('ui-remote-fs:success', { result, action });
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
// Create and register store sync middleware
|
|
124
|
+
const storeSyncMiddleware = (0, store_sync_middleware_1.createStoreSyncMiddleware)({
|
|
125
|
+
fileSystemAdapter,
|
|
126
|
+
pathTranslator,
|
|
127
|
+
autoReload: config.autoReload,
|
|
128
|
+
transformContent: config.transformContent,
|
|
129
|
+
});
|
|
130
|
+
// Register middleware with store extensions
|
|
131
|
+
const middlewareExtensions = [
|
|
132
|
+
{
|
|
133
|
+
id: 'remote-fs',
|
|
134
|
+
middleware: remoteFsMiddleware,
|
|
135
|
+
priority: 100,
|
|
136
|
+
plugin: 'ui-remote-fs',
|
|
137
|
+
description: 'Handles remote filesystem operations via HTTP',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: 'store-sync',
|
|
141
|
+
middleware: storeSyncMiddleware,
|
|
142
|
+
priority: 50,
|
|
143
|
+
plugin: 'ui-remote-fs',
|
|
144
|
+
description: 'Synchronizes remote FS to Redux Store FS',
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
extensionsCollector.register('ui-remote-fs:middleware', {
|
|
148
|
+
middleware: middlewareExtensions,
|
|
149
|
+
});
|
|
150
|
+
log('Middleware registered');
|
|
151
|
+
// Emit ready event
|
|
152
|
+
ctx.hooks.emit('ui-remote-fs:ready', {
|
|
153
|
+
workspaceClient,
|
|
154
|
+
pathTranslator,
|
|
155
|
+
mountPoint: config.mountPoint,
|
|
156
|
+
});
|
|
157
|
+
log('Plugin activated');
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
deactivate() {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
log('Plugin deactivated');
|
|
163
|
+
// Cleanup if needed
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
exports.createRemoteFsPlugin = createRemoteFsPlugin;
|
|
169
|
+
exports.default = createRemoteFsPlugin;
|