@hamak/ui-remote-fs 0.10.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/api/types/remote-fs-error.types.d.ts +28 -0
  2. package/dist/api/types/remote-fs-error.types.d.ts.map +1 -1
  3. package/dist/api/types/remote-fs-error.types.js +18 -0
  4. package/dist/impl/actions/remote-fs-actions.d.ts +22 -2
  5. package/dist/impl/actions/remote-fs-actions.d.ts.map +1 -1
  6. package/dist/impl/actions/remote-fs-actions.js +11 -3
  7. package/dist/impl/middleware/file-content-type.d.ts +4 -52
  8. package/dist/impl/middleware/file-content-type.d.ts.map +1 -1
  9. package/dist/impl/middleware/file-content-type.js +4 -91
  10. package/dist/impl/middleware/remote-fs-middleware.d.ts +22 -0
  11. package/dist/impl/middleware/remote-fs-middleware.d.ts.map +1 -1
  12. package/dist/impl/middleware/remote-fs-middleware.js +293 -22
  13. package/dist/impl/middleware/same-content.d.ts +23 -0
  14. package/dist/impl/middleware/same-content.d.ts.map +1 -0
  15. package/dist/impl/middleware/same-content.js +62 -0
  16. package/dist/impl/middleware/store-sync-middleware.d.ts +5 -4
  17. package/dist/impl/middleware/store-sync-middleware.d.ts.map +1 -1
  18. package/dist/impl/middleware/store-sync-middleware.js +269 -57
  19. package/dist/impl/plugin/remote-fs-plugin-factory.d.ts +5 -4
  20. package/dist/impl/plugin/remote-fs-plugin-factory.d.ts.map +1 -1
  21. package/dist/impl/plugin/remote-fs-plugin-factory.js +1 -2
  22. package/dist/impl/providers/http-workspace-client.d.ts +5 -1
  23. package/dist/impl/providers/http-workspace-client.d.ts.map +1 -1
  24. package/dist/impl/providers/http-workspace-client.js +170 -5
  25. package/dist/spi/middleware/remote-fs-middleware.types.d.ts +21 -2
  26. package/dist/spi/middleware/remote-fs-middleware.types.d.ts.map +1 -1
  27. package/dist/spi/providers/i-workspace-client.d.ts +21 -3
  28. package/dist/spi/providers/i-workspace-client.d.ts.map +1 -1
  29. package/package.json +9 -8
@@ -3,9 +3,31 @@
3
3
  *
4
4
  * Redux middleware for handling remote filesystem operations via HTTP client.
5
5
  * Migrated from amk/libs/ui/core/remote-fs/src/lib/remote-fs-middleware.ts
6
+ *
7
+ * ## Versioned writes (amah/app-framework#70)
8
+ *
9
+ * The middleware remembers, per remote path, the `FileInfo.version` of the
10
+ * last completed operation (list entry, get, post, put; a delete forgets it).
11
+ * A `PUT_REQUEST` whose options carry no `ifMatch` is sent with that version
12
+ * as its precondition, so a write over a file that changed on the server since
13
+ * this client last saw it is refused instead of clobbering the other edit. The
14
+ * refusal arrives as `PUT_FAILED` with `reason: 'version-mismatch'` and
15
+ * `current`, the version now on the server (see `WriteFailureReason`).
16
+ *
17
+ * - `ifMatch: '<version>'` on the request overrides the remembered one;
18
+ * - `ifMatch: false` writes unconditionally (overwrite anyway);
19
+ * - a backend whose `FileInfo` has no `version` never gets a precondition, so
20
+ * it keeps today's unconditional writes.
21
+ *
22
+ * Requests to the same remote path run one after another, in dispatch order.
23
+ * Two quick edits to one file are therefore two writes where the second one
24
+ * carries the version the first one produced, rather than two concurrent
25
+ * writes racing each other (and, with versions, the second one being refused
26
+ * for carrying a version the first one already replaced). Requests to
27
+ * different paths still run concurrently.
6
28
  */
7
29
  import { Pathway } from '@hamak/shared-utils';
8
- import { RemoteFsActionTypes } from '../../api/index.js';
30
+ import { RemoteFsActionTypes, VERSION_MISMATCH } from '../../api/index.js';
9
31
  import { rfsActions, } from '../actions/remote-fs-actions.js';
10
32
  /**
11
33
  * Create remote filesystem middleware
@@ -33,18 +55,233 @@ export function createRemoteFsMiddleware(config) {
33
55
  const pathway = Array.isArray(path) ? Pathway.of(path) : Pathway.of([path]);
34
56
  return pathTranslator.toRemotePath(pathway);
35
57
  };
58
+ /**
59
+ * `code` is only ever taken from the caught value when it is actually a
60
+ * non-empty string — a numeric or otherwise typed `code` must not leak
61
+ * through as an ErrorObject's `code`, which callers expect to be a string
62
+ * (matches the same guard in the HTTP client) (#77 second review, finding D).
63
+ */
64
+ const codeOf = (candidate) => typeof candidate === 'string' && candidate.length > 0 ? candidate : 'UNKNOWN';
65
+ /**
66
+ * First non-blank (after trim) of the candidate messages, else the fixed
67
+ * fallback — one message-resolution rule for every branch of `handleError`
68
+ * (#77 second review).
69
+ */
70
+ const messageOf = (...candidates) => {
71
+ for (const candidate of candidates) {
72
+ if (typeof candidate === 'string' && candidate.trim().length > 0) {
73
+ return candidate;
74
+ }
75
+ }
76
+ return 'Unknown error';
77
+ };
78
+ /** A non-null, non-array, non-Date, plain-prototype object. */
79
+ const isPlainObject = (value) => {
80
+ if (typeof value !== 'object' ||
81
+ value === null ||
82
+ Array.isArray(value) ||
83
+ value instanceof Date) {
84
+ return false;
85
+ }
86
+ const proto = Object.getPrototypeOf(value);
87
+ return proto === Object.prototype || proto === null;
88
+ };
89
+ /**
90
+ * A fresh, JSON-safe deep copy of `candidate`: strings, finite numbers,
91
+ * booleans, `null`, plain objects and arrays are kept; functions, symbols,
92
+ * `undefined` and any other non-plain object (a class instance, a `Map`, a
93
+ * live axios config) are dropped; a `Date` becomes its ISO string. A cycle
94
+ * — the same object reachable from itself along its own path — drops the
95
+ * repeated reference instead of recursing forever.
96
+ *
97
+ * Passing `params` through by reference let a function or a live axios
98
+ * config nested under it reach the Redux store and the `onError` callback
99
+ * unsanitized, and made the result alias the object the caller threw
100
+ * (#77 third review, finding 4). The top-level result is `undefined`
101
+ * unless `candidate` itself is a plain object — `params` on the returned
102
+ * `ErrorObject` is either a (possibly empty) object or absent, never a
103
+ * bare string/array/etc.
104
+ */
105
+ const asParams = (candidate) => {
106
+ if (!isPlainObject(candidate)) {
107
+ return undefined;
108
+ }
109
+ const onPath = new WeakSet();
110
+ const sanitize = (value) => {
111
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') {
112
+ return value;
113
+ }
114
+ if (typeof value === 'number') {
115
+ return Number.isFinite(value) ? value : undefined;
116
+ }
117
+ if (value instanceof Date) {
118
+ // An invalid Date throws from toISOString(), and this runs inside the
119
+ // error handler, so it must not throw.
120
+ return Number.isNaN(value.getTime()) ? undefined : value.toISOString();
121
+ }
122
+ if (Array.isArray(value)) {
123
+ if (onPath.has(value)) {
124
+ return undefined;
125
+ }
126
+ onPath.add(value);
127
+ const out = value.map((item) => {
128
+ const sanitized = sanitize(item);
129
+ return sanitized === undefined ? null : sanitized;
130
+ });
131
+ onPath.delete(value);
132
+ return out;
133
+ }
134
+ if (isPlainObject(value)) {
135
+ if (onPath.has(value)) {
136
+ return undefined;
137
+ }
138
+ onPath.add(value);
139
+ const out = {};
140
+ for (const key of Object.keys(value)) {
141
+ // A key present with an `undefined` value is kept: its presence can
142
+ // be the contract. A version-mismatch error on a deleted file carries
143
+ // `current: undefined`, and `isVersionMismatchError` tests
144
+ // `'current' in params`. Dropping the key turned that refusal into a
145
+ // plain failure, so knownVersions was never refreshed and every later
146
+ // PUT to the path was refused again. Only values with no JSON-safe
147
+ // form (functions, symbols, class instances) are dropped.
148
+ const original = value[key];
149
+ const sanitized = sanitize(original);
150
+ if (sanitized !== undefined || original === undefined) {
151
+ out[key] = sanitized;
152
+ }
153
+ }
154
+ onPath.delete(value);
155
+ return out;
156
+ }
157
+ // Functions, symbols, and non-plain objects (class instances, `Map`,
158
+ // a live axios config, an `Error` instance, …) carry no JSON-safe
159
+ // value of their own — drop them.
160
+ return undefined;
161
+ };
162
+ return sanitize(candidate);
163
+ };
36
164
  /**
37
165
  * Handle errors and convert to ErrorObject
38
166
  */
39
167
  const handleError = (error) => {
168
+ // An Error instance (AxiosError, a Node SystemError) also satisfies the
169
+ // duck-type check below — `'code' in error && 'message' in error` is
170
+ // true for most Errors — so that check used to return the live Error
171
+ // instance itself as the "ErrorObject". That instance carries
172
+ // `config`/`request`/`stack` and fails `instanceof Error` checks
173
+ // downstream once it's expected to be a plain object, and it is not
174
+ // serializable for the Redux store. Extract only `code`/`message`/`params`
175
+ // here, before the duck-type check gets a chance to pass it through
176
+ // untouched (#77 review).
177
+ //
178
+ // `params` is included when the rejection carries one, e.g.
179
+ // `Object.assign(new Error(msg), { code: 'version-mismatch', params:
180
+ // { current: 'v9', status: 412 } })` — dropping it silently degraded a
181
+ // version-mismatch PUT failure to a plain `reason: 'error'` and left
182
+ // `knownVersions` stale (#77 second review, finding E).
183
+ if (error instanceof Error) {
184
+ // A client that rethrows a raw AxiosError (rather than the shaped
185
+ // ErrorObject http-workspace-client.ts produces) still carries the
186
+ // server's `code`/`message`/`hint` under `response.data` — discarding
187
+ // it made a real server error indistinguishable from "the network
188
+ // dropped" (#77 third review, finding 5). Only used when there is an
189
+ // actual plain-object body to read; a response-less Error (or one
190
+ // whose `response.data` isn't a plain object) keeps the behaviour
191
+ // below untouched.
192
+ const response = error.response;
193
+ const data = response && typeof response === 'object' ? response.data : undefined;
194
+ if (isPlainObject(data)) {
195
+ const message = messageOf(data.message, typeof data.error === 'string' ? data.error : undefined, error.message);
196
+ const code = typeof data.code === 'string' && data.code.trim().length > 0
197
+ ? data.code
198
+ : codeOf(error.code);
199
+ const ownParams = asParams(error.params);
200
+ const params = {
201
+ ...ownParams,
202
+ status: response.status,
203
+ body: asParams(data),
204
+ };
205
+ // A raw 412 refusal: lift the server's `current` to where
206
+ // `isVersionMismatchError` looks for it, as the HTTP client's own 412
207
+ // branch does. Left in `body` only, the failure read as
208
+ // `reason: 'error'` beside `code: 'version-mismatch'`, and
209
+ // knownVersions was never refreshed.
210
+ if (code === VERSION_MISMATCH) {
211
+ params.current = typeof data.current === 'string' ? data.current : undefined;
212
+ }
213
+ return { code, message, params };
214
+ }
215
+ const params = asParams(error.params);
216
+ return {
217
+ code: codeOf(error.code),
218
+ message: messageOf(error.message),
219
+ ...(params ? { params } : {}),
220
+ };
221
+ }
40
222
  if (error && typeof error === 'object' && 'code' in error && 'message' in error) {
41
- return error;
223
+ // Project to a plain object rather than passing the caught value
224
+ // through untouched — it may carry non-serializable baggage (a
225
+ // function, a live request handle, …) that must not land in the
226
+ // Redux store (#77 second review, finding G).
227
+ const params = asParams(error.params);
228
+ return {
229
+ code: codeOf(error.code),
230
+ message: messageOf(error.message),
231
+ ...(params ? { params } : {}),
232
+ };
233
+ }
234
+ // A client that rejects with a bare string still has a sentence to show;
235
+ // reading `.message` off it would yield "Unknown error" (#77). A
236
+ // whitespace-only string is not a sentence either (finding F).
237
+ if (typeof error === 'string' && error.trim().length > 0) {
238
+ return { code: 'UNKNOWN', message: error };
42
239
  }
43
240
  return {
44
- code: error?.code || 'UNKNOWN',
45
- message: error?.message || 'Unknown error',
241
+ code: codeOf(error?.code),
242
+ message: messageOf(error?.message),
46
243
  };
47
244
  };
245
+ /** Version last seen for a remote path (key: segments joined by '/'). */
246
+ const knownVersions = new Map();
247
+ const keyOf = (segments) => segments.join('/');
248
+ const remember = (segments, version) => {
249
+ if (version === undefined) {
250
+ return;
251
+ }
252
+ knownVersions.set(keyOf(segments), version);
253
+ };
254
+ /** Tail of the in-flight requests, per remote path. */
255
+ const queues = new Map();
256
+ /**
257
+ * Run `task` once every earlier request to the same remote path has
258
+ * settled.
259
+ */
260
+ const serialized = (segments, task) => {
261
+ const key = keyOf(segments);
262
+ const previous = queues.get(key) ?? Promise.resolve();
263
+ const settled = previous.then(task, task).catch(() => undefined);
264
+ queues.set(key, settled);
265
+ void settled.then(() => {
266
+ if (queues.get(key) === settled) {
267
+ queues.delete(key);
268
+ }
269
+ });
270
+ };
271
+ /**
272
+ * The options a PUT is sent with: the caller's, with the remembered
273
+ * version as `ifMatch` when the caller left it open.
274
+ */
275
+ const withPrecondition = (segments, options) => {
276
+ if (options?.ifMatch !== undefined) {
277
+ return options;
278
+ }
279
+ const known = knownVersions.get(keyOf(segments));
280
+ if (known === undefined) {
281
+ return options;
282
+ }
283
+ return { ...options, ifMatch: known };
284
+ };
48
285
  const remoteFsMiddleware = (store) => (next) => (action) => {
49
286
  const result = next(action);
50
287
  const dispatch = store.dispatch;
@@ -56,9 +293,22 @@ export function createRemoteFsMiddleware(config) {
56
293
  if (remotePath === undefined) {
57
294
  break;
58
295
  }
59
- void (async () => {
296
+ const segments = remotePath.getSegments();
297
+ serialized(segments, async () => {
60
298
  try {
61
- const data = await client.listFiles(remotePath.getSegments(), requestAction.payload.options);
299
+ const data = await client.listFiles(segments, requestAction.payload.options);
300
+ // A listing fills in versions it does not know yet, but never
301
+ // replaces one learnt from an operation on the file itself: a
302
+ // listing runs on the directory's queue, so it may overlap a write
303
+ // to one of its entries and come back with that entry's older
304
+ // version. A version that is stale anyway costs one refused write,
305
+ // which reports the current one.
306
+ data?.forEach((entry) => {
307
+ const entryPath = [...segments, entry.name];
308
+ if (!entry.isDirectory && !knownVersions.has(keyOf(entryPath))) {
309
+ remember(entryPath, entry.version);
310
+ }
311
+ });
62
312
  const completedAction = rfsActions.ofLsCompleted(data, requestAction);
63
313
  dispatch(completedAction);
64
314
  onSuccess?.(data, completedAction);
@@ -69,7 +319,7 @@ export function createRemoteFsMiddleware(config) {
69
319
  dispatch(failedAction);
70
320
  onError?.(errorObject, failedAction);
71
321
  }
72
- })();
322
+ });
73
323
  break;
74
324
  }
75
325
  case RemoteFsActionTypes.MKDIR_REQUEST: {
@@ -78,9 +328,10 @@ export function createRemoteFsMiddleware(config) {
78
328
  if (remotePath === undefined) {
79
329
  break;
80
330
  }
81
- void (async () => {
331
+ const segments = remotePath.getSegments();
332
+ serialized(segments, async () => {
82
333
  try {
83
- const data = await client.createDirectory(remotePath.getSegments(), requestAction.payload.options);
334
+ const data = await client.createDirectory(segments, requestAction.payload.options);
84
335
  const completedAction = rfsActions.ofMkdirCompleted(data, requestAction);
85
336
  dispatch(completedAction);
86
337
  onSuccess?.(data, completedAction);
@@ -91,7 +342,7 @@ export function createRemoteFsMiddleware(config) {
91
342
  dispatch(failedAction);
92
343
  onError?.(errorObject, failedAction);
93
344
  }
94
- })();
345
+ });
95
346
  break;
96
347
  }
97
348
  case RemoteFsActionTypes.GET_REQUEST: {
@@ -100,9 +351,11 @@ export function createRemoteFsMiddleware(config) {
100
351
  if (remotePath === undefined) {
101
352
  break;
102
353
  }
103
- void (async () => {
354
+ const segments = remotePath.getSegments();
355
+ serialized(segments, async () => {
104
356
  try {
105
- const data = await client.readFile(remotePath.getSegments(), requestAction.payload.options);
357
+ const data = await client.readFile(segments, requestAction.payload.options);
358
+ remember(segments, data?.version);
106
359
  const completedAction = rfsActions.ofGetCompleted(data, requestAction);
107
360
  dispatch(completedAction);
108
361
  onSuccess?.(data, completedAction);
@@ -113,7 +366,7 @@ export function createRemoteFsMiddleware(config) {
113
366
  dispatch(failedAction);
114
367
  onError?.(errorObject, failedAction);
115
368
  }
116
- })();
369
+ });
117
370
  break;
118
371
  }
119
372
  case RemoteFsActionTypes.POST_REQUEST: {
@@ -122,9 +375,13 @@ export function createRemoteFsMiddleware(config) {
122
375
  if (remotePath === undefined) {
123
376
  break;
124
377
  }
125
- void (async () => {
378
+ const segments = remotePath.getSegments();
379
+ serialized(segments, async () => {
126
380
  try {
127
- const data = await client.putFile(remotePath.getSegments(), requestAction.payload.content, requestAction.payload.options);
381
+ // A POST creates: it is sent with exactly the options it was
382
+ // dispatched with, and never gets a remembered version.
383
+ const data = await client.putFile(segments, requestAction.payload.content, requestAction.payload.options);
384
+ remember(segments, data?.version);
128
385
  const completedAction = rfsActions.ofPostCompleted(data, requestAction);
129
386
  dispatch(completedAction);
130
387
  onSuccess?.(data, completedAction);
@@ -135,7 +392,7 @@ export function createRemoteFsMiddleware(config) {
135
392
  dispatch(failedAction);
136
393
  onError?.(errorObject, failedAction);
137
394
  }
138
- })();
395
+ });
139
396
  break;
140
397
  }
141
398
  case RemoteFsActionTypes.PUT_REQUEST: {
@@ -144,9 +401,11 @@ export function createRemoteFsMiddleware(config) {
144
401
  if (remotePath === undefined) {
145
402
  break;
146
403
  }
147
- void (async () => {
404
+ const segments = remotePath.getSegments();
405
+ serialized(segments, async () => {
148
406
  try {
149
- const data = await client.putFile(remotePath.getSegments(), requestAction.payload.content, requestAction.payload.options);
407
+ const data = await client.putFile(segments, requestAction.payload.content, withPrecondition(segments, requestAction.payload.options));
408
+ remember(segments, data?.version);
150
409
  const completedAction = rfsActions.ofPutCompleted(data, requestAction);
151
410
  dispatch(completedAction);
152
411
  onSuccess?.(data, completedAction);
@@ -154,10 +413,20 @@ export function createRemoteFsMiddleware(config) {
154
413
  catch (error) {
155
414
  const errorObject = handleError(error);
156
415
  const failedAction = rfsActions.ofPutFailed(errorObject, requestAction);
416
+ if (failedAction.payload.reason === 'version-mismatch') {
417
+ // The server told us what it holds now; a retry with the
418
+ // remembered version would only be refused again.
419
+ if (failedAction.payload.current === undefined) {
420
+ knownVersions.delete(keyOf(segments));
421
+ }
422
+ else {
423
+ remember(segments, failedAction.payload.current);
424
+ }
425
+ }
157
426
  dispatch(failedAction);
158
427
  onError?.(errorObject, failedAction);
159
428
  }
160
- })();
429
+ });
161
430
  break;
162
431
  }
163
432
  case RemoteFsActionTypes.DELETE_REQUEST: {
@@ -166,9 +435,11 @@ export function createRemoteFsMiddleware(config) {
166
435
  if (remotePath === undefined) {
167
436
  break;
168
437
  }
169
- void (async () => {
438
+ const segments = remotePath.getSegments();
439
+ serialized(segments, async () => {
170
440
  try {
171
- const data = await client.deleteFile(remotePath.getSegments(), requestAction.payload.options);
441
+ const data = await client.deleteFile(segments, requestAction.payload.options);
442
+ knownVersions.delete(keyOf(segments));
172
443
  const completedAction = rfsActions.ofDeleteCompleted(data, requestAction);
173
444
  dispatch(completedAction);
174
445
  onSuccess?.(data, completedAction);
@@ -179,7 +450,7 @@ export function createRemoteFsMiddleware(config) {
179
450
  dispatch(failedAction);
180
451
  onError?.(errorObject, failedAction);
181
452
  }
182
- })();
453
+ });
183
454
  break;
184
455
  }
185
456
  default:
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Structural equality for file content held in store-fs.
3
+ *
4
+ * Store-sync uses it to tell whether a node still holds exactly the content a
5
+ * write sent (#71). Autosave sends the node's own `content` reference, so the
6
+ * common case is decided by the identity check; the recursive walk only runs
7
+ * when something was edited or cloned in between.
8
+ *
9
+ * Content decoded from a file body is JSON-shaped, but a host's
10
+ * `transformContent` or a programmatic write can put anything in the store, so
11
+ * only the shapes whose equality is unambiguous are compared by value:
12
+ * - plain objects and arrays, member by member;
13
+ * - `Date`s, by time.
14
+ * Every other object (`Map`, `Set`, class instances, …) is equal only to
15
+ * itself. Comparing those by own enumerable keys would call any two of them
16
+ * equal — they have none — and in store-sync "equal" means "safe to
17
+ * overwrite".
18
+ *
19
+ * Cyclic structures terminate: a pair already being compared further up is
20
+ * assumed equal, which is the standard coinductive rule.
21
+ */
22
+ export declare function sameContent(a: unknown, b: unknown): boolean;
23
+ //# sourceMappingURL=same-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"same-content.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/same-content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAE3D"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Structural equality for file content held in store-fs.
3
+ *
4
+ * Store-sync uses it to tell whether a node still holds exactly the content a
5
+ * write sent (#71). Autosave sends the node's own `content` reference, so the
6
+ * common case is decided by the identity check; the recursive walk only runs
7
+ * when something was edited or cloned in between.
8
+ *
9
+ * Content decoded from a file body is JSON-shaped, but a host's
10
+ * `transformContent` or a programmatic write can put anything in the store, so
11
+ * only the shapes whose equality is unambiguous are compared by value:
12
+ * - plain objects and arrays, member by member;
13
+ * - `Date`s, by time.
14
+ * Every other object (`Map`, `Set`, class instances, …) is equal only to
15
+ * itself. Comparing those by own enumerable keys would call any two of them
16
+ * equal — they have none — and in store-sync "equal" means "safe to
17
+ * overwrite".
18
+ *
19
+ * Cyclic structures terminate: a pair already being compared further up is
20
+ * assumed equal, which is the standard coinductive rule.
21
+ */
22
+ export function sameContent(a, b) {
23
+ return compare(a, b, []);
24
+ }
25
+ function isPlainObject(value) {
26
+ const proto = Object.getPrototypeOf(value);
27
+ return proto === Object.prototype || proto === null;
28
+ }
29
+ function compare(a, b, path) {
30
+ if (Object.is(a, b)) {
31
+ return true;
32
+ }
33
+ if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {
34
+ return false;
35
+ }
36
+ if (a instanceof Date || b instanceof Date) {
37
+ return a instanceof Date && b instanceof Date && Object.is(a.getTime(), b.getTime());
38
+ }
39
+ const bothArrays = Array.isArray(a) && Array.isArray(b);
40
+ if (!bothArrays && !(isPlainObject(a) && isPlainObject(b))) {
41
+ return false;
42
+ }
43
+ if (path.some(([x, y]) => x === a && y === b)) {
44
+ return true;
45
+ }
46
+ path.push([a, b]);
47
+ try {
48
+ if (bothArrays) {
49
+ const left = a;
50
+ const right = b;
51
+ return left.length === right.length && left.every((item, i) => compare(item, right[i], path));
52
+ }
53
+ const left = a;
54
+ const right = b;
55
+ const keys = Object.keys(left);
56
+ return (keys.length === Object.keys(right).length &&
57
+ keys.every((key) => Object.prototype.hasOwnProperty.call(right, key) && compare(left[key], right[key], path)));
58
+ }
59
+ finally {
60
+ path.pop();
61
+ }
62
+ }
@@ -12,10 +12,12 @@ import { StoreSyncMiddlewareConfig } from '../../spi/index.js';
12
12
  *
13
13
  * This middleware intercepts remote FS completion actions and synchronizes them
14
14
  * to the Redux Store FileSystem. It handles:
15
- * - LS_COMPLETED: Creates directories and file entries in Store FS
15
+ * - LS_COMPLETED: Creates directories and file entries in Store FS, without
16
+ * disturbing the body of an entry that has already been read (#71)
16
17
  * - MKDIR_COMPLETED: Creates directory in Store FS
17
18
  * - GET_COMPLETED: Creates/updates file content in Store FS
18
- * - POST/PUT_COMPLETED: Reloads file content from remote
19
+ * - POST/PUT_COMPLETED: Writes the completion payload's own body into the
20
+ * node, and re-GETs when it carried none (or when `autoReload` says so) (#71)
19
21
  * - DELETE_COMPLETED: Removes node from Store FS
20
22
  *
21
23
  * @param config Middleware configuration
@@ -25,8 +27,7 @@ import { StoreSyncMiddlewareConfig } from '../../spi/index.js';
25
27
  * ```typescript
26
28
  * const middleware = createStoreSyncMiddleware({
27
29
  * fileSystemAdapter: storeFs,
28
- * pathTranslator: new PathTranslator(Pathway.ofRoot().resolve('remote')),
29
- * autoReload: true
30
+ * pathTranslator: new PathTranslator(Pathway.ofRoot().resolve('remote'))
30
31
  * });
31
32
  * ```
32
33
  */
@@ -1 +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;AAYtD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,GAAG,GAAG,EAC/C,MAAM,EAAE,yBAAyB,GAChC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAoLnB;AAED,eAAe,yBAAyB,CAAC"}
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;AActD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,GAAG,GAAG,EAC/C,MAAM,EAAE,yBAAyB,GAChC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CA2anB;AAED,eAAe,yBAAyB,CAAC"}