@hamak/ui-remote-fs 0.5.1

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 (94) hide show
  1. package/dist/api/contracts/i-remote-fs-service.d.ts +85 -0
  2. package/dist/api/contracts/i-remote-fs-service.d.ts.map +1 -0
  3. package/dist/api/contracts/i-remote-fs-service.js +6 -0
  4. package/dist/api/contracts/index.d.ts +5 -0
  5. package/dist/api/contracts/index.d.ts.map +1 -0
  6. package/dist/api/contracts/index.js +4 -0
  7. package/dist/api/index.d.ts +8 -0
  8. package/dist/api/index.d.ts.map +1 -0
  9. package/dist/api/index.js +7 -0
  10. package/dist/api/tokens/index.d.ts +5 -0
  11. package/dist/api/tokens/index.d.ts.map +1 -0
  12. package/dist/api/tokens/index.js +4 -0
  13. package/dist/api/tokens/remote-fs.tokens.d.ts +29 -0
  14. package/dist/api/tokens/remote-fs.tokens.d.ts.map +1 -0
  15. package/dist/api/tokens/remote-fs.tokens.js +28 -0
  16. package/dist/api/types/index.d.ts +7 -0
  17. package/dist/api/types/index.d.ts.map +1 -0
  18. package/dist/api/types/index.js +6 -0
  19. package/dist/api/types/remote-fs-action.types.d.ts +34 -0
  20. package/dist/api/types/remote-fs-action.types.d.ts.map +1 -0
  21. package/dist/api/types/remote-fs-action.types.js +42 -0
  22. package/dist/api/types/remote-fs-config.types.d.ts +40 -0
  23. package/dist/api/types/remote-fs-config.types.d.ts.map +1 -0
  24. package/dist/api/types/remote-fs-config.types.js +12 -0
  25. package/dist/api/types/remote-fs-error.types.d.ts +28 -0
  26. package/dist/api/types/remote-fs-error.types.d.ts.map +1 -0
  27. package/dist/api/types/remote-fs-error.types.js +15 -0
  28. package/dist/impl/actions/index.d.ts +5 -0
  29. package/dist/impl/actions/index.d.ts.map +1 -0
  30. package/dist/impl/actions/index.js +4 -0
  31. package/dist/impl/actions/remote-fs-actions.d.ts +196 -0
  32. package/dist/impl/actions/remote-fs-actions.d.ts.map +1 -0
  33. package/dist/impl/actions/remote-fs-actions.js +151 -0
  34. package/dist/impl/autosave/index.d.ts +5 -0
  35. package/dist/impl/autosave/index.d.ts.map +1 -0
  36. package/dist/impl/autosave/index.js +4 -0
  37. package/dist/impl/autosave/remote-fs-autosave-provider.d.ts +46 -0
  38. package/dist/impl/autosave/remote-fs-autosave-provider.d.ts.map +1 -0
  39. package/dist/impl/autosave/remote-fs-autosave-provider.js +80 -0
  40. package/dist/impl/index.d.ts +14 -0
  41. package/dist/impl/index.d.ts.map +1 -0
  42. package/dist/impl/index.js +13 -0
  43. package/dist/impl/middleware/index.d.ts +6 -0
  44. package/dist/impl/middleware/index.d.ts.map +1 -0
  45. package/dist/impl/middleware/index.js +5 -0
  46. package/dist/impl/middleware/remote-fs-middleware.d.ts +38 -0
  47. package/dist/impl/middleware/remote-fs-middleware.d.ts.map +1 -0
  48. package/dist/impl/middleware/remote-fs-middleware.js +192 -0
  49. package/dist/impl/middleware/store-sync-middleware.d.ts +35 -0
  50. package/dist/impl/middleware/store-sync-middleware.d.ts.map +1 -0
  51. package/dist/impl/middleware/store-sync-middleware.js +135 -0
  52. package/dist/impl/plugin/index.d.ts +5 -0
  53. package/dist/impl/plugin/index.d.ts.map +1 -0
  54. package/dist/impl/plugin/index.js +4 -0
  55. package/dist/impl/plugin/remote-fs-plugin-factory.d.ts +84 -0
  56. package/dist/impl/plugin/remote-fs-plugin-factory.d.ts.map +1 -0
  57. package/dist/impl/plugin/remote-fs-plugin-factory.js +150 -0
  58. package/dist/impl/providers/http-workspace-client.d.ts +103 -0
  59. package/dist/impl/providers/http-workspace-client.d.ts.map +1 -0
  60. package/dist/impl/providers/http-workspace-client.js +215 -0
  61. package/dist/impl/providers/index.d.ts +5 -0
  62. package/dist/impl/providers/index.d.ts.map +1 -0
  63. package/dist/impl/providers/index.js +4 -0
  64. package/dist/impl/services/index.d.ts +5 -0
  65. package/dist/impl/services/index.d.ts.map +1 -0
  66. package/dist/impl/services/index.js +4 -0
  67. package/dist/impl/services/remote-fs-service.d.ts +10 -0
  68. package/dist/impl/services/remote-fs-service.d.ts.map +1 -0
  69. package/dist/impl/services/remote-fs-service.js +12 -0
  70. package/dist/index.d.ts +6 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +5 -0
  73. package/dist/spi/index.d.ts +8 -0
  74. package/dist/spi/index.d.ts.map +1 -0
  75. package/dist/spi/index.js +7 -0
  76. package/dist/spi/middleware/index.d.ts +5 -0
  77. package/dist/spi/middleware/index.d.ts.map +1 -0
  78. package/dist/spi/middleware/index.js +4 -0
  79. package/dist/spi/middleware/remote-fs-middleware.types.d.ts +61 -0
  80. package/dist/spi/middleware/remote-fs-middleware.types.d.ts.map +1 -0
  81. package/dist/spi/middleware/remote-fs-middleware.types.js +6 -0
  82. package/dist/spi/providers/i-path-translator.d.ts +74 -0
  83. package/dist/spi/providers/i-path-translator.d.ts.map +1 -0
  84. package/dist/spi/providers/i-path-translator.js +61 -0
  85. package/dist/spi/providers/i-remote-fs-provider.d.ts +78 -0
  86. package/dist/spi/providers/i-remote-fs-provider.d.ts.map +1 -0
  87. package/dist/spi/providers/i-remote-fs-provider.js +6 -0
  88. package/dist/spi/providers/i-workspace-client.d.ts +97 -0
  89. package/dist/spi/providers/i-workspace-client.d.ts.map +1 -0
  90. package/dist/spi/providers/i-workspace-client.js +7 -0
  91. package/dist/spi/providers/index.d.ts +7 -0
  92. package/dist/spi/providers/index.d.ts.map +1 -0
  93. package/dist/spi/providers/index.js +6 -0
  94. package/package.json +69 -0
@@ -0,0 +1,151 @@
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
+ import { RemoteFsActionTypes } from '../../api';
8
+ /**
9
+ * Action factory class for creating remote filesystem actions
10
+ */
11
+ export class RemoteFsActionFactory {
12
+ constructor() {
13
+ Object.defineProperty(this, "types", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: RemoteFsActionTypes
18
+ });
19
+ }
20
+ // LS (List) operations
21
+ ofLsRequest(path, options) {
22
+ return {
23
+ type: this.types.LS_REQUEST,
24
+ payload: { path, options },
25
+ };
26
+ }
27
+ ofLsCompleted(data, request) {
28
+ return {
29
+ type: this.types.LS_COMPLETED,
30
+ payload: { data, request },
31
+ };
32
+ }
33
+ ofLsFailed(error, request) {
34
+ return {
35
+ type: this.types.LS_FAILED,
36
+ payload: { error, request },
37
+ };
38
+ }
39
+ // MKDIR (Make Directory) operations
40
+ ofMkdirRequest(path, options) {
41
+ return {
42
+ type: this.types.MKDIR_REQUEST,
43
+ payload: { path, options },
44
+ };
45
+ }
46
+ ofMkdirCompleted(data, request) {
47
+ return {
48
+ type: this.types.MKDIR_COMPLETED,
49
+ payload: { data, request },
50
+ };
51
+ }
52
+ ofMkdirFailed(error, request) {
53
+ return {
54
+ type: this.types.MKDIR_FAILED,
55
+ payload: { error, request },
56
+ };
57
+ }
58
+ // GET (Read File) operations
59
+ ofGetRequest(path, options) {
60
+ return {
61
+ type: this.types.GET_REQUEST,
62
+ payload: { path, options },
63
+ };
64
+ }
65
+ ofGetCompleted(data, request) {
66
+ return {
67
+ type: this.types.GET_COMPLETED,
68
+ payload: { data, request },
69
+ };
70
+ }
71
+ ofGetFailed(error, request) {
72
+ return {
73
+ type: this.types.GET_FAILED,
74
+ payload: { error, request },
75
+ };
76
+ }
77
+ // POST (Create File) operations
78
+ ofPostRequest(path, content, options) {
79
+ return {
80
+ type: this.types.POST_REQUEST,
81
+ payload: { path, content, options },
82
+ };
83
+ }
84
+ ofPostCompleted(data, request) {
85
+ return {
86
+ type: this.types.POST_COMPLETED,
87
+ payload: { data, request },
88
+ };
89
+ }
90
+ ofPostFailed(error, request) {
91
+ return {
92
+ type: this.types.POST_FAILED,
93
+ payload: { error, request },
94
+ };
95
+ }
96
+ // PUT (Update File) operations
97
+ ofPutRequest(path, content, options) {
98
+ return {
99
+ type: this.types.PUT_REQUEST,
100
+ payload: { path, content, options },
101
+ };
102
+ }
103
+ ofPutCompleted(data, request) {
104
+ return {
105
+ type: this.types.PUT_COMPLETED,
106
+ payload: { data, request },
107
+ };
108
+ }
109
+ ofPutFailed(error, request) {
110
+ return {
111
+ type: this.types.PUT_FAILED,
112
+ payload: { error, request },
113
+ };
114
+ }
115
+ // DELETE operations
116
+ ofDeleteRequest(path, options) {
117
+ return {
118
+ type: this.types.DELETE_REQUEST,
119
+ payload: { path, options },
120
+ };
121
+ }
122
+ ofDeleteCompleted(data, request) {
123
+ return {
124
+ type: this.types.DELETE_COMPLETED,
125
+ payload: { data, request },
126
+ };
127
+ }
128
+ ofDeleteFailed(error, request) {
129
+ return {
130
+ type: this.types.DELETE_FAILED,
131
+ payload: { error, request },
132
+ };
133
+ }
134
+ /**
135
+ * Type guard to check if an action is a remote FS action
136
+ */
137
+ isRemoteFsAction(action) {
138
+ return (action &&
139
+ typeof action === 'object' &&
140
+ 'type' in action &&
141
+ Object.values(RemoteFsActionTypes).includes(action.type));
142
+ }
143
+ }
144
+ /**
145
+ * Singleton instance of the action factory
146
+ */
147
+ export const rfsActions = new RemoteFsActionFactory();
148
+ /**
149
+ * Re-export the action types enum for convenience
150
+ */
151
+ export { RemoteFsActionTypes };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Remote FS Autosave
3
+ */
4
+ export * from './remote-fs-autosave-provider';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/impl/autosave/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Remote FS Autosave
3
+ */
4
+ export * from './remote-fs-autosave-provider';
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Remote FS Autosave Provider
3
+ *
4
+ * Implements autosave for files managed by the remote filesystem plugin.
5
+ * Uses PUT_REQUEST actions to save files to the remote server.
6
+ */
7
+ import type { Dispatch, AnyAction } from 'redux';
8
+ import type { FileSystemNode } from '@hamak/shared-utils';
9
+ import type { IAutosaveProvider, AutosaveResult } from '@hamak/ui-store-spi';
10
+ import type { IPathTranslator } from '../../spi';
11
+ /**
12
+ * Configuration for RemoteFsAutosaveProvider
13
+ */
14
+ export interface RemoteFsAutosaveProviderConfig {
15
+ /** Path translator to check if path is under remote mount point */
16
+ pathTranslator: IPathTranslator;
17
+ }
18
+ /**
19
+ * Autosave provider for remote filesystem
20
+ *
21
+ * This provider handles autosave for files that are mounted via the
22
+ * remote filesystem plugin. It checks if a file path falls under the
23
+ * configured mount point and uses PUT_REQUEST to save changes.
24
+ */
25
+ export declare class RemoteFsAutosaveProvider implements IAutosaveProvider {
26
+ readonly id = "remote-fs";
27
+ readonly priority = 10;
28
+ private pathTranslator;
29
+ constructor(config: RemoteFsAutosaveProviderConfig);
30
+ /**
31
+ * Check if this provider supports a given path.
32
+ * Returns true if the path is under the remote mount point.
33
+ */
34
+ supports(path: string[], _node: FileSystemNode): boolean;
35
+ /**
36
+ * Save file content to remote server.
37
+ * Dispatches PUT_REQUEST action which will be handled by remote-fs middleware.
38
+ */
39
+ save(path: string[], content: unknown, _node: FileSystemNode, dispatch: Dispatch<AnyAction>): Promise<AutosaveResult>;
40
+ /**
41
+ * Cancel is a no-op for remote-fs since we don't track in-flight requests here.
42
+ * The remote-fs middleware handles the actual HTTP requests.
43
+ */
44
+ cancel(_path: string[]): void;
45
+ }
46
+ //# sourceMappingURL=remote-fs-autosave-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-fs-autosave-provider.d.ts","sourceRoot":"","sources":["../../../src/impl/autosave/remote-fs-autosave-provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAGjD;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,mEAAmE;IACnE,cAAc,EAAE,eAAe,CAAC;CACjC;AAED;;;;;;GAMG;AACH,qBAAa,wBAAyB,YAAW,iBAAiB;IAChE,QAAQ,CAAC,EAAE,eAAe;IAC1B,QAAQ,CAAC,QAAQ,MAAM;IAEvB,OAAO,CAAC,cAAc,CAAkB;gBAE5B,MAAM,EAAE,8BAA8B;IAIlD;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO;IAQxD;;;OAGG;IACG,IAAI,CACR,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,GAC5B,OAAO,CAAC,cAAc,CAAC;IAwB1B;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI;CAG9B"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Remote FS Autosave Provider
3
+ *
4
+ * Implements autosave for files managed by the remote filesystem plugin.
5
+ * Uses PUT_REQUEST actions to save files to the remote server.
6
+ */
7
+ import { rfsActions } from '../actions/remote-fs-actions';
8
+ /**
9
+ * Autosave provider for remote filesystem
10
+ *
11
+ * This provider handles autosave for files that are mounted via the
12
+ * remote filesystem plugin. It checks if a file path falls under the
13
+ * configured mount point and uses PUT_REQUEST to save changes.
14
+ */
15
+ export class RemoteFsAutosaveProvider {
16
+ constructor(config) {
17
+ Object.defineProperty(this, "id", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: 'remote-fs'
22
+ });
23
+ Object.defineProperty(this, "priority", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: 10
28
+ });
29
+ Object.defineProperty(this, "pathTranslator", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+ this.pathTranslator = config.pathTranslator;
36
+ }
37
+ /**
38
+ * Check if this provider supports a given path.
39
+ * Returns true if the path is under the remote mount point.
40
+ */
41
+ supports(path, _node) {
42
+ // Check if path translator can translate this path to a remote path
43
+ const remotePath = this.pathTranslator.toRemotePath({ getSegments: () => path });
44
+ return remotePath !== undefined;
45
+ }
46
+ /**
47
+ * Save file content to remote server.
48
+ * Dispatches PUT_REQUEST action which will be handled by remote-fs middleware.
49
+ */
50
+ async save(path, content, _node, dispatch) {
51
+ try {
52
+ // Dispatch PUT request to save content
53
+ dispatch(rfsActions.ofPutRequest(path, content));
54
+ // Note: The actual HTTP request is async and handled by remote-fs middleware.
55
+ // Success/failure will be tracked by the middleware dispatching
56
+ // PUT_COMPLETED or PUT_FAILED actions.
57
+ // For now, we return optimistic success.
58
+ return {
59
+ success: true,
60
+ timestamp: Date.now(),
61
+ };
62
+ }
63
+ catch (error) {
64
+ return {
65
+ success: false,
66
+ error: {
67
+ code: error.code ?? 'SAVE_ERROR',
68
+ message: error.message ?? 'Failed to dispatch save action',
69
+ },
70
+ };
71
+ }
72
+ }
73
+ /**
74
+ * Cancel is a no-op for remote-fs since we don't track in-flight requests here.
75
+ * The remote-fs middleware handles the actual HTTP requests.
76
+ */
77
+ cancel(_path) {
78
+ // No-op: remote-fs middleware handles request lifecycle
79
+ }
80
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * UI Remote FS Implementation
3
+ * HTTP-based remote filesystem implementation
4
+ */
5
+ export * from '../api';
6
+ export * from '../spi/providers';
7
+ export type { RemoteFsMiddlewareFactory, StoreSyncMiddlewareFactory } from '../spi/middleware';
8
+ export * from './actions';
9
+ export * from './middleware';
10
+ export * from './providers';
11
+ export * from './plugin';
12
+ export * from './services';
13
+ export * from './autosave';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/impl/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AAIjC,YAAY,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAE/F,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * UI Remote FS Implementation
3
+ * HTTP-based remote filesystem implementation
4
+ */
5
+ // Re-export API and SPI for convenience
6
+ export * from '../api';
7
+ export * from '../spi/providers';
8
+ export * from './actions';
9
+ export * from './middleware';
10
+ export * from './providers';
11
+ export * from './plugin';
12
+ export * from './services';
13
+ export * from './autosave';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Remote FS Middleware
3
+ */
4
+ export * from './remote-fs-middleware';
5
+ export * from './store-sync-middleware';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Remote FS Middleware
3
+ */
4
+ export * from './remote-fs-middleware';
5
+ export * from './store-sync-middleware';
@@ -0,0 +1,38 @@
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
+ import { AnyAction, Middleware } from '@reduxjs/toolkit';
8
+ import type { IWorkspaceClient, IPathTranslator } from '../../spi';
9
+ import { type ErrorObject } from '../../api';
10
+ /**
11
+ * Configuration for remote FS middleware
12
+ */
13
+ export interface RemoteFsMiddlewareConfig {
14
+ client: IWorkspaceClient;
15
+ pathTranslator: IPathTranslator;
16
+ onError?: (error: ErrorObject, action: AnyAction) => void;
17
+ onSuccess?: (result: any, action: AnyAction) => void;
18
+ }
19
+ /**
20
+ * Create remote filesystem middleware
21
+ *
22
+ * This middleware intercepts remote FS actions and executes them via the provided
23
+ * workspace client. It handles path translation from local mount point to remote paths.
24
+ *
25
+ * @param config Middleware configuration
26
+ * @returns Redux middleware
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const middleware = createRemoteFsMiddleware({
31
+ * client: new HttpWorkspaceClient({ workspaceId: '0' }),
32
+ * pathTranslator: new PathTranslator(Pathway.ofRoot().resolve('remote'))
33
+ * });
34
+ * ```
35
+ */
36
+ export declare function createRemoteFsMiddleware<S = any>(config: RemoteFsMiddlewareConfig): Middleware<{}, S>;
37
+ export default createRemoteFsMiddleware;
38
+ //# sourceMappingURL=remote-fs-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-fs-middleware.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/remote-fs-middleware.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAWlE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,gBAAgB,CAAC;IACzB,cAAc,EAAE,eAAe,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1D,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;CACtD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,GAAG,GAAG,EAC9C,MAAM,EAAE,wBAAwB,GAC/B,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CA8LnB;AAED,eAAe,wBAAwB,CAAC"}
@@ -0,0 +1,192 @@
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
+ import { Pathway } from '@hamak/shared-utils';
8
+ import { RemoteFsActionTypes } from '../../api';
9
+ import { rfsActions, } from '../actions/remote-fs-actions';
10
+ /**
11
+ * Create remote filesystem middleware
12
+ *
13
+ * This middleware intercepts remote FS actions and executes them via the provided
14
+ * workspace client. It handles path translation from local mount point to remote paths.
15
+ *
16
+ * @param config Middleware configuration
17
+ * @returns Redux middleware
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const middleware = createRemoteFsMiddleware({
22
+ * client: new HttpWorkspaceClient({ workspaceId: '0' }),
23
+ * pathTranslator: new PathTranslator(Pathway.ofRoot().resolve('remote'))
24
+ * });
25
+ * ```
26
+ */
27
+ export function createRemoteFsMiddleware(config) {
28
+ const { client, pathTranslator, onError, onSuccess } = config;
29
+ /**
30
+ * Translate local path to remote path
31
+ */
32
+ const toRemotePath = (path) => {
33
+ const pathway = Array.isArray(path) ? Pathway.of(path) : Pathway.of([path]);
34
+ return pathTranslator.toRemotePath(pathway);
35
+ };
36
+ /**
37
+ * Handle errors and convert to ErrorObject
38
+ */
39
+ const handleError = (error) => {
40
+ if (error && typeof error === 'object' && 'code' in error && 'message' in error) {
41
+ return error;
42
+ }
43
+ return {
44
+ code: error?.code || 'UNKNOWN',
45
+ message: error?.message || 'Unknown error',
46
+ };
47
+ };
48
+ const remoteFsMiddleware = (store) => (next) => (action) => {
49
+ const result = next(action);
50
+ const dispatch = store.dispatch;
51
+ const anyAction = action;
52
+ switch (anyAction.type) {
53
+ case RemoteFsActionTypes.LS_REQUEST: {
54
+ const requestAction = anyAction;
55
+ const remotePath = toRemotePath(requestAction.payload.path);
56
+ if (remotePath === undefined) {
57
+ break;
58
+ }
59
+ void (async () => {
60
+ try {
61
+ const data = await client.listFiles(remotePath.getSegments(), requestAction.payload.options);
62
+ const completedAction = rfsActions.ofLsCompleted(data, requestAction);
63
+ dispatch(completedAction);
64
+ onSuccess?.(data, completedAction);
65
+ }
66
+ catch (error) {
67
+ const errorObject = handleError(error);
68
+ const failedAction = rfsActions.ofLsFailed(errorObject, requestAction);
69
+ dispatch(failedAction);
70
+ onError?.(errorObject, failedAction);
71
+ }
72
+ })();
73
+ break;
74
+ }
75
+ case RemoteFsActionTypes.MKDIR_REQUEST: {
76
+ const requestAction = anyAction;
77
+ const remotePath = toRemotePath(requestAction.payload.path);
78
+ if (remotePath === undefined) {
79
+ break;
80
+ }
81
+ void (async () => {
82
+ try {
83
+ const data = await client.createDirectory(remotePath.getSegments(), requestAction.payload.options);
84
+ const completedAction = rfsActions.ofMkdirCompleted(data, requestAction);
85
+ dispatch(completedAction);
86
+ onSuccess?.(data, completedAction);
87
+ }
88
+ catch (error) {
89
+ const errorObject = handleError(error);
90
+ const failedAction = rfsActions.ofMkdirFailed(errorObject, requestAction);
91
+ dispatch(failedAction);
92
+ onError?.(errorObject, failedAction);
93
+ }
94
+ })();
95
+ break;
96
+ }
97
+ case RemoteFsActionTypes.GET_REQUEST: {
98
+ const requestAction = anyAction;
99
+ const remotePath = toRemotePath(requestAction.payload.path);
100
+ if (remotePath === undefined) {
101
+ break;
102
+ }
103
+ void (async () => {
104
+ try {
105
+ const data = await client.readFile(remotePath.getSegments(), requestAction.payload.options);
106
+ const completedAction = rfsActions.ofGetCompleted(data, requestAction);
107
+ dispatch(completedAction);
108
+ onSuccess?.(data, completedAction);
109
+ }
110
+ catch (error) {
111
+ const errorObject = handleError(error);
112
+ const failedAction = rfsActions.ofGetFailed(errorObject, requestAction);
113
+ dispatch(failedAction);
114
+ onError?.(errorObject, failedAction);
115
+ }
116
+ })();
117
+ break;
118
+ }
119
+ case RemoteFsActionTypes.POST_REQUEST: {
120
+ const requestAction = anyAction;
121
+ const remotePath = toRemotePath(requestAction.payload.path);
122
+ if (remotePath === undefined) {
123
+ break;
124
+ }
125
+ void (async () => {
126
+ try {
127
+ const data = await client.putFile(remotePath.getSegments(), requestAction.payload.content, requestAction.payload.options);
128
+ const completedAction = rfsActions.ofPostCompleted(data, requestAction);
129
+ dispatch(completedAction);
130
+ onSuccess?.(data, completedAction);
131
+ }
132
+ catch (error) {
133
+ const errorObject = handleError(error);
134
+ const failedAction = rfsActions.ofPostFailed(errorObject, requestAction);
135
+ dispatch(failedAction);
136
+ onError?.(errorObject, failedAction);
137
+ }
138
+ })();
139
+ break;
140
+ }
141
+ case RemoteFsActionTypes.PUT_REQUEST: {
142
+ const requestAction = anyAction;
143
+ const remotePath = toRemotePath(requestAction.payload.path);
144
+ if (remotePath === undefined) {
145
+ break;
146
+ }
147
+ void (async () => {
148
+ try {
149
+ const data = await client.putFile(remotePath.getSegments(), requestAction.payload.content, requestAction.payload.options);
150
+ const completedAction = rfsActions.ofPutCompleted(data, requestAction);
151
+ dispatch(completedAction);
152
+ onSuccess?.(data, completedAction);
153
+ }
154
+ catch (error) {
155
+ const errorObject = handleError(error);
156
+ const failedAction = rfsActions.ofPutFailed(errorObject, requestAction);
157
+ dispatch(failedAction);
158
+ onError?.(errorObject, failedAction);
159
+ }
160
+ })();
161
+ break;
162
+ }
163
+ case RemoteFsActionTypes.DELETE_REQUEST: {
164
+ const requestAction = anyAction;
165
+ const remotePath = toRemotePath(requestAction.payload.path);
166
+ if (remotePath === undefined) {
167
+ break;
168
+ }
169
+ void (async () => {
170
+ try {
171
+ const data = await client.deleteFile(remotePath.getSegments(), requestAction.payload.options);
172
+ const completedAction = rfsActions.ofDeleteCompleted(data, requestAction);
173
+ dispatch(completedAction);
174
+ onSuccess?.(data, completedAction);
175
+ }
176
+ catch (error) {
177
+ const errorObject = handleError(error);
178
+ const failedAction = rfsActions.ofDeleteFailed(errorObject, requestAction);
179
+ dispatch(failedAction);
180
+ onError?.(errorObject, failedAction);
181
+ }
182
+ })();
183
+ break;
184
+ }
185
+ default:
186
+ break;
187
+ }
188
+ return result;
189
+ };
190
+ return remoteFsMiddleware;
191
+ }
192
+ export default createRemoteFsMiddleware;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Store Sync Middleware
3
+ *
4
+ * Redux middleware for synchronizing remote filesystem operations to Redux Store FS.
5
+ * This middleware listens to remote FS completion actions and updates the Store FS accordingly.
6
+ * Migrated from amk/libs/ui/core/remote-fs/src/lib/store-fs-adapter-middleware.ts
7
+ */
8
+ import { Middleware } from '@reduxjs/toolkit';
9
+ import { StoreSyncMiddlewareConfig } from '../../spi';
10
+ /**
11
+ * Create store sync middleware
12
+ *
13
+ * This middleware intercepts remote FS completion actions and synchronizes them
14
+ * to the Redux Store FileSystem. It handles:
15
+ * - LS_COMPLETED: Creates directories and file entries in Store FS
16
+ * - MKDIR_COMPLETED: Creates directory in Store FS
17
+ * - GET_COMPLETED: Creates/updates file content in Store FS
18
+ * - POST/PUT_COMPLETED: Reloads file content from remote
19
+ * - DELETE_COMPLETED: Removes node from Store FS
20
+ *
21
+ * @param config Middleware configuration
22
+ * @returns Redux middleware
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const middleware = createStoreSyncMiddleware({
27
+ * fileSystemAdapter: storeFs,
28
+ * pathTranslator: new PathTranslator(Pathway.ofRoot().resolve('remote')),
29
+ * autoReload: true
30
+ * });
31
+ * ```
32
+ */
33
+ export declare function createStoreSyncMiddleware<S = any>(config: StoreSyncMiddlewareConfig): Middleware<{}, S>;
34
+ export default createStoreSyncMiddleware;
35
+ //# sourceMappingURL=store-sync-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-sync-middleware.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/store-sync-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAa,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAWtD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,GAAG,GAAG,EAC/C,MAAM,EAAE,yBAAyB,GAChC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CA8HnB;AAED,eAAe,yBAAyB,CAAC"}