@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.
Files changed (64) hide show
  1. package/dist/actions/index.d.ts +5 -0
  2. package/dist/actions/index.d.ts.map +1 -0
  3. package/dist/actions/index.js +4 -0
  4. package/dist/actions/remote-fs-actions.d.ts +189 -0
  5. package/dist/actions/remote-fs-actions.d.ts.map +1 -0
  6. package/dist/actions/remote-fs-actions.js +146 -0
  7. package/dist/es2015/actions/index.js +20 -0
  8. package/dist/es2015/actions/remote-fs-actions.js +147 -0
  9. package/dist/es2015/index.js +25 -0
  10. package/dist/es2015/middleware/index.js +21 -0
  11. package/dist/es2015/middleware/remote-fs-middleware.js +205 -0
  12. package/dist/es2015/middleware/store-sync-middleware.js +138 -0
  13. package/dist/es2015/plugin/index.js +20 -0
  14. package/dist/es2015/plugin/remote-fs-plugin-factory.js +169 -0
  15. package/dist/es2015/providers/http-workspace-client.js +199 -0
  16. package/dist/es2015/providers/index.js +20 -0
  17. package/dist/es2015/services/index.js +20 -0
  18. package/dist/es2015/services/remote-fs-service.js +16 -0
  19. package/dist/index.d.ts +10 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +9 -0
  22. package/dist/middleware/index.d.ts +6 -0
  23. package/dist/middleware/index.d.ts.map +1 -0
  24. package/dist/middleware/index.js +5 -0
  25. package/dist/middleware/remote-fs-middleware.d.ts +50 -0
  26. package/dist/middleware/remote-fs-middleware.d.ts.map +1 -0
  27. package/dist/middleware/remote-fs-middleware.js +192 -0
  28. package/dist/middleware/store-sync-middleware.d.ts +35 -0
  29. package/dist/middleware/store-sync-middleware.d.ts.map +1 -0
  30. package/dist/middleware/store-sync-middleware.js +134 -0
  31. package/dist/plugin/index.d.ts +5 -0
  32. package/dist/plugin/index.d.ts.map +1 -0
  33. package/dist/plugin/index.js +4 -0
  34. package/dist/plugin/remote-fs-plugin-factory.d.ts +84 -0
  35. package/dist/plugin/remote-fs-plugin-factory.d.ts.map +1 -0
  36. package/dist/plugin/remote-fs-plugin-factory.js +150 -0
  37. package/dist/providers/http-workspace-client.d.ts +99 -0
  38. package/dist/providers/http-workspace-client.d.ts.map +1 -0
  39. package/dist/providers/http-workspace-client.js +171 -0
  40. package/dist/providers/index.d.ts +5 -0
  41. package/dist/providers/index.d.ts.map +1 -0
  42. package/dist/providers/index.js +4 -0
  43. package/dist/services/index.d.ts +5 -0
  44. package/dist/services/index.d.ts.map +1 -0
  45. package/dist/services/index.js +4 -0
  46. package/dist/services/remote-fs-service.d.ts +10 -0
  47. package/dist/services/remote-fs-service.d.ts.map +1 -0
  48. package/dist/services/remote-fs-service.js +12 -0
  49. package/package.json +56 -0
  50. package/project.json +24 -0
  51. package/src/actions/index.ts +5 -0
  52. package/src/actions/remote-fs-actions.ts +302 -0
  53. package/src/index.ts +10 -0
  54. package/src/middleware/index.ts +6 -0
  55. package/src/middleware/remote-fs-middleware.ts +244 -0
  56. package/src/middleware/store-sync-middleware.ts +175 -0
  57. package/src/plugin/index.ts +5 -0
  58. package/src/plugin/remote-fs-plugin-factory.ts +238 -0
  59. package/src/providers/http-workspace-client.ts +232 -0
  60. package/src/providers/index.ts +5 -0
  61. package/src/services/index.ts +5 -0
  62. package/src/services/remote-fs-service.ts +13 -0
  63. package/tsconfig.es2015.json +21 -0
  64. package/tsconfig.json +19 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Remote FS Services
3
+ */
4
+ export * from './remote-fs-service';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Remote FS Service
3
+ *
4
+ * Service implementation for remote filesystem operations.
5
+ * Will be implemented in future phases.
6
+ */
7
+ export declare class RemoteFsService {
8
+ constructor();
9
+ }
10
+ //# sourceMappingURL=remote-fs-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-fs-service.d.ts","sourceRoot":"","sources":["../../src/services/remote-fs-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,qBAAa,eAAe;;CAI3B"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Remote FS Service
3
+ *
4
+ * Service implementation for remote filesystem operations.
5
+ * Will be implemented in future phases.
6
+ */
7
+ // Placeholder - will be implemented in future phases
8
+ export class RemoteFsService {
9
+ constructor() {
10
+ throw new Error('Not yet implemented');
11
+ }
12
+ }
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@hamak/ui-remote-fs-impl",
3
+ "version": "0.4.3",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "Remote FS Implementation - HTTP-based remote filesystem",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "sideEffects": false,
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/amah/app-framework.git",
13
+ "directory": "packages/ui-remote-fs/ui-remote-fs-impl"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.es2015.json",
20
+ "clean": "rm -rf dist",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "default": "./dist/index.js",
29
+ "legacy": "./dist/es2015/index.js"
30
+ },
31
+ "./es2015": {
32
+ "import": "./dist/es2015/index.js",
33
+ "default": "./dist/es2015/index.js"
34
+ }
35
+ },
36
+ "dependencies": {
37
+ "@hamak/ui-remote-fs-api": "0.4.3",
38
+ "@hamak/ui-remote-fs-spi": "0.4.3",
39
+ "@hamak/ui-store-api": "0.4.1",
40
+ "@hamak/ui-store-impl": "0.4.1",
41
+ "@hamak/microkernel-api": "0.4.1",
42
+ "@hamak/microkernel-spi": "0.4.1",
43
+ "@reduxjs/toolkit": "^2.0.0",
44
+ "axios": "^1.6.0",
45
+ "redux": "^5.0.1"
46
+ },
47
+ "peerDependencies": {
48
+ "@hamak/shared-utils": "^0.4.2"
49
+ },
50
+ "devDependencies": {
51
+ "@hamak/shared-utils": "0.4.3",
52
+ "typescript": "~5.4.0",
53
+ "vitest": "^2.0.0",
54
+ "@types/node": "^20.0.0"
55
+ }
56
+ }
package/project.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@hamak/ui-remote-fs-impl",
3
+ "$schema": "../../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "packages/ui-remote-fs/ui-remote-fs-impl/src",
5
+ "projectType": "library",
6
+ "targets": {
7
+ "build": {
8
+ "executor": "nx:run-commands",
9
+ "outputs": ["{projectRoot}/dist"],
10
+ "options": {
11
+ "command": "tsc -p tsconfig.json && tsc -p tsconfig.es2015.json",
12
+ "cwd": "{projectRoot}"
13
+ }
14
+ },
15
+ "clean": {
16
+ "executor": "nx:run-commands",
17
+ "options": {
18
+ "command": "rm -rf dist",
19
+ "cwd": "{projectRoot}"
20
+ }
21
+ }
22
+ },
23
+ "tags": ["type:library", "scope:ui-remote-fs"]
24
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Remote FS Actions
3
+ */
4
+
5
+ export * from './remote-fs-actions';
@@ -0,0 +1,302 @@
1
+ /**
2
+ * Remote FS Actions
3
+ *
4
+ * Action creators for remote filesystem operations.
5
+ * Migrated from amk/libs/ui/core/remote-fs/src/lib/remote-fs-actions.ts
6
+ */
7
+
8
+ import { RemoteFsActionTypes, ErrorObject } from '@hamak/ui-remote-fs-api';
9
+ import { FileInfo } from '@hamak/shared-utils';
10
+
11
+ // Interfaces for action payloads
12
+ export interface LsRequestAction {
13
+ type: RemoteFsActionTypes.LS_REQUEST;
14
+ payload: { path: string | string[] };
15
+ [key: string]: any;
16
+ }
17
+
18
+ export interface LsCompletedAction {
19
+ type: RemoteFsActionTypes.LS_COMPLETED;
20
+ payload: { data: FileInfo[]; request: LsRequestAction };
21
+ [key: string]: any;
22
+ }
23
+
24
+ export interface LsFailedAction {
25
+ type: RemoteFsActionTypes.LS_FAILED;
26
+ payload: { error: ErrorObject; request: LsRequestAction };
27
+ [key: string]: any;
28
+ }
29
+
30
+ export interface MkdirRequestAction {
31
+ type: RemoteFsActionTypes.MKDIR_REQUEST;
32
+ payload: { path: string | string[] };
33
+ [key: string]: any;
34
+ }
35
+
36
+ export interface MkdirCompletedAction {
37
+ type: RemoteFsActionTypes.MKDIR_COMPLETED;
38
+ payload: { data: FileInfo; request: MkdirRequestAction };
39
+ [key: string]: any;
40
+ }
41
+
42
+ export interface MkdirFailedAction {
43
+ type: RemoteFsActionTypes.MKDIR_FAILED;
44
+ payload: { error: ErrorObject; request: MkdirRequestAction };
45
+ [key: string]: any;
46
+ }
47
+
48
+ export interface GetRequestAction {
49
+ type: RemoteFsActionTypes.GET_REQUEST;
50
+ payload: { path: string | string[] };
51
+ [key: string]: any;
52
+ }
53
+
54
+ export interface GetCompletedAction {
55
+ type: RemoteFsActionTypes.GET_COMPLETED;
56
+ payload: { data: FileInfo; request: GetRequestAction };
57
+ [key: string]: any;
58
+ }
59
+
60
+ export interface GetFailedAction {
61
+ type: RemoteFsActionTypes.GET_FAILED;
62
+ payload: { error: ErrorObject; request: GetRequestAction };
63
+ [key: string]: any;
64
+ }
65
+
66
+ export interface PostRequestAction {
67
+ type: RemoteFsActionTypes.POST_REQUEST;
68
+ payload: { path: string | string[]; content: any };
69
+ [key: string]: any;
70
+ }
71
+
72
+ export interface PostCompletedAction {
73
+ type: RemoteFsActionTypes.POST_COMPLETED;
74
+ payload: { data: FileInfo; request: PostRequestAction };
75
+ [key: string]: any;
76
+ }
77
+
78
+ export interface PostFailedAction {
79
+ type: RemoteFsActionTypes.POST_FAILED;
80
+ payload: { error: ErrorObject; request: PostRequestAction };
81
+ [key: string]: any;
82
+ }
83
+
84
+ export interface PutRequestAction {
85
+ type: RemoteFsActionTypes.PUT_REQUEST;
86
+ payload: { path: string | string[]; content: any };
87
+ [key: string]: any;
88
+ }
89
+
90
+ export interface PutCompletedAction {
91
+ type: RemoteFsActionTypes.PUT_COMPLETED;
92
+ payload: { data: FileInfo; request: PutRequestAction };
93
+ [key: string]: any;
94
+ }
95
+
96
+ export interface PutFailedAction {
97
+ type: RemoteFsActionTypes.PUT_FAILED;
98
+ payload: { error: ErrorObject; request: PutRequestAction };
99
+ [key: string]: any;
100
+ }
101
+
102
+ export interface DeleteRequestAction {
103
+ type: RemoteFsActionTypes.DELETE_REQUEST;
104
+ payload: { path: string | string[] };
105
+ [key: string]: any;
106
+ }
107
+
108
+ export interface DeleteCompletedAction {
109
+ type: RemoteFsActionTypes.DELETE_COMPLETED;
110
+ payload: { data: FileInfo; request: DeleteRequestAction };
111
+ [key: string]: any;
112
+ }
113
+
114
+ export interface DeleteFailedAction {
115
+ type: RemoteFsActionTypes.DELETE_FAILED;
116
+ payload: { error: ErrorObject; request: DeleteRequestAction };
117
+ [key: string]: any;
118
+ }
119
+
120
+ /**
121
+ * Union type for all remote FS actions
122
+ */
123
+ export type RemoteFsAction =
124
+ | LsRequestAction
125
+ | LsCompletedAction
126
+ | LsFailedAction
127
+ | MkdirRequestAction
128
+ | MkdirCompletedAction
129
+ | MkdirFailedAction
130
+ | GetRequestAction
131
+ | GetCompletedAction
132
+ | GetFailedAction
133
+ | PostRequestAction
134
+ | PostCompletedAction
135
+ | PostFailedAction
136
+ | PutRequestAction
137
+ | PutCompletedAction
138
+ | PutFailedAction
139
+ | DeleteRequestAction
140
+ | DeleteCompletedAction
141
+ | DeleteFailedAction;
142
+
143
+ /**
144
+ * Action factory class for creating remote filesystem actions
145
+ */
146
+ export class RemoteFsActionFactory {
147
+ public types = RemoteFsActionTypes;
148
+
149
+ // LS (List) operations
150
+ ofLsRequest(path: string | string[]): LsRequestAction {
151
+ return {
152
+ type: this.types.LS_REQUEST,
153
+ payload: { path },
154
+ };
155
+ }
156
+
157
+ ofLsCompleted(data: FileInfo[], request: LsRequestAction): LsCompletedAction {
158
+ return {
159
+ type: this.types.LS_COMPLETED,
160
+ payload: { data, request },
161
+ };
162
+ }
163
+
164
+ ofLsFailed(error: ErrorObject, request: LsRequestAction): LsFailedAction {
165
+ return {
166
+ type: this.types.LS_FAILED,
167
+ payload: { error, request },
168
+ };
169
+ }
170
+
171
+ // MKDIR (Make Directory) operations
172
+ ofMkdirRequest(path: string | string[]): MkdirRequestAction {
173
+ return {
174
+ type: this.types.MKDIR_REQUEST,
175
+ payload: { path },
176
+ };
177
+ }
178
+
179
+ ofMkdirCompleted(data: FileInfo, request: MkdirRequestAction): MkdirCompletedAction {
180
+ return {
181
+ type: this.types.MKDIR_COMPLETED,
182
+ payload: { data, request },
183
+ };
184
+ }
185
+
186
+ ofMkdirFailed(error: ErrorObject, request: MkdirRequestAction): MkdirFailedAction {
187
+ return {
188
+ type: this.types.MKDIR_FAILED,
189
+ payload: { error, request },
190
+ };
191
+ }
192
+
193
+ // GET (Read File) operations
194
+ ofGetRequest(path: string | string[]): GetRequestAction {
195
+ return {
196
+ type: this.types.GET_REQUEST,
197
+ payload: { path },
198
+ };
199
+ }
200
+
201
+ ofGetCompleted(data: FileInfo, request: GetRequestAction): GetCompletedAction {
202
+ return {
203
+ type: this.types.GET_COMPLETED,
204
+ payload: { data, request },
205
+ };
206
+ }
207
+
208
+ ofGetFailed(error: ErrorObject, request: GetRequestAction): GetFailedAction {
209
+ return {
210
+ type: this.types.GET_FAILED,
211
+ payload: { error, request },
212
+ };
213
+ }
214
+
215
+ // POST (Create File) operations
216
+ ofPostRequest(path: string | string[], content: any): PostRequestAction {
217
+ return {
218
+ type: this.types.POST_REQUEST,
219
+ payload: { path, content },
220
+ };
221
+ }
222
+
223
+ ofPostCompleted(data: FileInfo, request: PostRequestAction): PostCompletedAction {
224
+ return {
225
+ type: this.types.POST_COMPLETED,
226
+ payload: { data, request },
227
+ };
228
+ }
229
+
230
+ ofPostFailed(error: ErrorObject, request: PostRequestAction): PostFailedAction {
231
+ return {
232
+ type: this.types.POST_FAILED,
233
+ payload: { error, request },
234
+ };
235
+ }
236
+
237
+ // PUT (Update File) operations
238
+ ofPutRequest(path: string | string[], content: any): PutRequestAction {
239
+ return {
240
+ type: this.types.PUT_REQUEST,
241
+ payload: { path, content },
242
+ };
243
+ }
244
+
245
+ ofPutCompleted(data: FileInfo, request: PutRequestAction): PutCompletedAction {
246
+ return {
247
+ type: this.types.PUT_COMPLETED,
248
+ payload: { data, request },
249
+ };
250
+ }
251
+
252
+ ofPutFailed(error: ErrorObject, request: PutRequestAction): PutFailedAction {
253
+ return {
254
+ type: this.types.PUT_FAILED,
255
+ payload: { error, request },
256
+ };
257
+ }
258
+
259
+ // DELETE operations
260
+ ofDeleteRequest(path: string | string[]): DeleteRequestAction {
261
+ return {
262
+ type: this.types.DELETE_REQUEST,
263
+ payload: { path },
264
+ };
265
+ }
266
+
267
+ ofDeleteCompleted(data: FileInfo, request: DeleteRequestAction): DeleteCompletedAction {
268
+ return {
269
+ type: this.types.DELETE_COMPLETED,
270
+ payload: { data, request },
271
+ };
272
+ }
273
+
274
+ ofDeleteFailed(error: ErrorObject, request: DeleteRequestAction): DeleteFailedAction {
275
+ return {
276
+ type: this.types.DELETE_FAILED,
277
+ payload: { error, request },
278
+ };
279
+ }
280
+
281
+ /**
282
+ * Type guard to check if an action is a remote FS action
283
+ */
284
+ isRemoteFsAction(action: any): action is RemoteFsAction {
285
+ return (
286
+ action &&
287
+ typeof action === 'object' &&
288
+ 'type' in action &&
289
+ Object.values(RemoteFsActionTypes).includes(action.type)
290
+ );
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Singleton instance of the action factory
296
+ */
297
+ export const rfsActions = new RemoteFsActionFactory();
298
+
299
+ /**
300
+ * Re-export the action types enum for convenience
301
+ */
302
+ export { RemoteFsActionTypes };
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * UI Remote FS Implementation
3
+ * HTTP-based remote filesystem implementation
4
+ */
5
+
6
+ export * from './actions';
7
+ export * from './middleware';
8
+ export * from './providers';
9
+ export * from './plugin';
10
+ export * from './services';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Remote FS Middleware
3
+ */
4
+
5
+ export * from './remote-fs-middleware';
6
+ export * from './store-sync-middleware';
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Remote FS Middleware
3
+ *
4
+ * Redux middleware for handling remote filesystem operations via HTTP client.
5
+ * Migrated from amk/libs/ui/core/remote-fs/src/lib/remote-fs-middleware.ts
6
+ */
7
+
8
+ import { AnyAction, Middleware } from '@reduxjs/toolkit';
9
+ import { Pathway } from '@hamak/shared-utils';
10
+ import { IWorkspaceClient, IPathTranslator } from '@hamak/ui-remote-fs-spi';
11
+ import { RemoteFsActionTypes, ErrorObject } from '@hamak/ui-remote-fs-api';
12
+ import {
13
+ rfsActions,
14
+ LsRequestAction,
15
+ MkdirRequestAction,
16
+ GetRequestAction,
17
+ PostRequestAction,
18
+ PutRequestAction,
19
+ DeleteRequestAction,
20
+ } from '../actions/remote-fs-actions';
21
+
22
+ /**
23
+ * Configuration for remote FS middleware
24
+ */
25
+ export interface RemoteFsMiddlewareConfig {
26
+ /**
27
+ * Workspace client for remote operations
28
+ */
29
+ client: IWorkspaceClient;
30
+
31
+ /**
32
+ * Path translator for mount point translation
33
+ */
34
+ pathTranslator: IPathTranslator;
35
+
36
+ /**
37
+ * Optional error handler
38
+ */
39
+ onError?: (error: ErrorObject, action: AnyAction) => void;
40
+
41
+ /**
42
+ * Optional success handler
43
+ */
44
+ onSuccess?: (result: any, action: AnyAction) => void;
45
+ }
46
+
47
+ /**
48
+ * Create remote filesystem middleware
49
+ *
50
+ * This middleware intercepts remote FS actions and executes them via the provided
51
+ * workspace client. It handles path translation from local mount point to remote paths.
52
+ *
53
+ * @param config Middleware configuration
54
+ * @returns Redux middleware
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const middleware = createRemoteFsMiddleware({
59
+ * client: new HttpWorkspaceClient({ workspaceId: '0' }),
60
+ * pathTranslator: new PathTranslator(Pathway.ofRoot().resolve('remote'))
61
+ * });
62
+ * ```
63
+ */
64
+ export function createRemoteFsMiddleware<S = any>(
65
+ config: RemoteFsMiddlewareConfig
66
+ ): Middleware<{}, S> {
67
+ const { client, pathTranslator, onError, onSuccess } = config;
68
+
69
+ /**
70
+ * Translate local path to remote path
71
+ */
72
+ const toRemotePath = (path: string | string[]): Pathway | undefined => {
73
+ const pathway = Array.isArray(path) ? Pathway.of(path) : Pathway.of([path]);
74
+ return pathTranslator.toRemotePath(pathway);
75
+ };
76
+
77
+ /**
78
+ * Handle errors and convert to ErrorObject
79
+ */
80
+ const handleError = (error: any): ErrorObject => {
81
+ if (error && typeof error === 'object' && 'code' in error && 'message' in error) {
82
+ return error as ErrorObject;
83
+ }
84
+ return {
85
+ code: error?.code || 'UNKNOWN',
86
+ message: error?.message || 'Unknown error',
87
+ };
88
+ };
89
+
90
+ const remoteFsMiddleware: Middleware<{}, S> = (store) => (next) => (action) => {
91
+ const result = next(action);
92
+ const dispatch = store.dispatch;
93
+ const anyAction = action as AnyAction;
94
+
95
+ switch (anyAction.type) {
96
+ case RemoteFsActionTypes.LS_REQUEST: {
97
+ const requestAction = anyAction as LsRequestAction;
98
+ const remotePath = toRemotePath(requestAction.payload.path);
99
+ if (remotePath === undefined) {
100
+ break;
101
+ }
102
+ void (async () => {
103
+ try {
104
+ const data = await client.listFiles(remotePath.getSegments());
105
+ const completedAction = rfsActions.ofLsCompleted(data, requestAction);
106
+ dispatch(completedAction);
107
+ onSuccess?.(data, completedAction);
108
+ } catch (error) {
109
+ const errorObject = handleError(error);
110
+ const failedAction = rfsActions.ofLsFailed(errorObject, requestAction);
111
+ dispatch(failedAction);
112
+ onError?.(errorObject, failedAction);
113
+ }
114
+ })();
115
+ break;
116
+ }
117
+
118
+ case RemoteFsActionTypes.MKDIR_REQUEST: {
119
+ const requestAction = anyAction as MkdirRequestAction;
120
+ const remotePath = toRemotePath(requestAction.payload.path);
121
+ if (remotePath === undefined) {
122
+ break;
123
+ }
124
+ void (async () => {
125
+ try {
126
+ const data = await client.createDirectory(remotePath.getSegments());
127
+ const completedAction = rfsActions.ofMkdirCompleted(data, requestAction);
128
+ dispatch(completedAction);
129
+ onSuccess?.(data, completedAction);
130
+ } catch (error) {
131
+ const errorObject = handleError(error);
132
+ const failedAction = rfsActions.ofMkdirFailed(errorObject, requestAction);
133
+ dispatch(failedAction);
134
+ onError?.(errorObject, failedAction);
135
+ }
136
+ })();
137
+ break;
138
+ }
139
+
140
+ case RemoteFsActionTypes.GET_REQUEST: {
141
+ const requestAction = anyAction as GetRequestAction;
142
+ const remotePath = toRemotePath(requestAction.payload.path);
143
+ if (remotePath === undefined) {
144
+ break;
145
+ }
146
+ void (async () => {
147
+ try {
148
+ const data = await client.readFile(remotePath.getSegments());
149
+ const completedAction = rfsActions.ofGetCompleted(data, requestAction);
150
+ dispatch(completedAction);
151
+ onSuccess?.(data, completedAction);
152
+ } catch (error) {
153
+ const errorObject = handleError(error);
154
+ const failedAction = rfsActions.ofGetFailed(errorObject, requestAction);
155
+ dispatch(failedAction);
156
+ onError?.(errorObject, failedAction);
157
+ }
158
+ })();
159
+ break;
160
+ }
161
+
162
+ case RemoteFsActionTypes.POST_REQUEST: {
163
+ const requestAction = anyAction as PostRequestAction;
164
+ const remotePath = toRemotePath(requestAction.payload.path);
165
+ if (remotePath === undefined) {
166
+ break;
167
+ }
168
+ void (async () => {
169
+ try {
170
+ const data = await client.putFile(
171
+ remotePath.getSegments(),
172
+ requestAction.payload.content
173
+ );
174
+ const completedAction = rfsActions.ofPostCompleted(data, requestAction);
175
+ dispatch(completedAction);
176
+ onSuccess?.(data, completedAction);
177
+ } catch (error) {
178
+ const errorObject = handleError(error);
179
+ const failedAction = rfsActions.ofPostFailed(errorObject, requestAction);
180
+ dispatch(failedAction);
181
+ onError?.(errorObject, failedAction);
182
+ }
183
+ })();
184
+ break;
185
+ }
186
+
187
+ case RemoteFsActionTypes.PUT_REQUEST: {
188
+ const requestAction = anyAction as PutRequestAction;
189
+ const remotePath = toRemotePath(requestAction.payload.path);
190
+ if (remotePath === undefined) {
191
+ break;
192
+ }
193
+ void (async () => {
194
+ try {
195
+ const data = await client.putFile(
196
+ remotePath.getSegments(),
197
+ requestAction.payload.content
198
+ );
199
+ const completedAction = rfsActions.ofPutCompleted(data, requestAction);
200
+ dispatch(completedAction);
201
+ onSuccess?.(data, completedAction);
202
+ } catch (error) {
203
+ const errorObject = handleError(error);
204
+ const failedAction = rfsActions.ofPutFailed(errorObject, requestAction);
205
+ dispatch(failedAction);
206
+ onError?.(errorObject, failedAction);
207
+ }
208
+ })();
209
+ break;
210
+ }
211
+
212
+ case RemoteFsActionTypes.DELETE_REQUEST: {
213
+ const requestAction = anyAction as DeleteRequestAction;
214
+ const remotePath = toRemotePath(requestAction.payload.path);
215
+ if (remotePath === undefined) {
216
+ break;
217
+ }
218
+ void (async () => {
219
+ try {
220
+ const data = await client.deleteFile(remotePath.getSegments());
221
+ const completedAction = rfsActions.ofDeleteCompleted(data, requestAction);
222
+ dispatch(completedAction);
223
+ onSuccess?.(data, completedAction);
224
+ } catch (error) {
225
+ const errorObject = handleError(error);
226
+ const failedAction = rfsActions.ofDeleteFailed(errorObject, requestAction);
227
+ dispatch(failedAction);
228
+ onError?.(errorObject, failedAction);
229
+ }
230
+ })();
231
+ break;
232
+ }
233
+
234
+ default:
235
+ break;
236
+ }
237
+
238
+ return result;
239
+ };
240
+
241
+ return remoteFsMiddleware;
242
+ }
243
+
244
+ export default createRemoteFsMiddleware;