@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.
- package/dist/api/types/remote-fs-error.types.d.ts +28 -0
- package/dist/api/types/remote-fs-error.types.d.ts.map +1 -1
- package/dist/api/types/remote-fs-error.types.js +18 -0
- package/dist/impl/actions/remote-fs-actions.d.ts +22 -2
- package/dist/impl/actions/remote-fs-actions.d.ts.map +1 -1
- package/dist/impl/actions/remote-fs-actions.js +11 -3
- package/dist/impl/middleware/file-content-type.d.ts +4 -52
- package/dist/impl/middleware/file-content-type.d.ts.map +1 -1
- package/dist/impl/middleware/file-content-type.js +4 -91
- package/dist/impl/middleware/remote-fs-middleware.d.ts +22 -0
- package/dist/impl/middleware/remote-fs-middleware.d.ts.map +1 -1
- package/dist/impl/middleware/remote-fs-middleware.js +293 -22
- package/dist/impl/middleware/same-content.d.ts +23 -0
- package/dist/impl/middleware/same-content.d.ts.map +1 -0
- package/dist/impl/middleware/same-content.js +62 -0
- package/dist/impl/middleware/store-sync-middleware.d.ts +5 -4
- package/dist/impl/middleware/store-sync-middleware.d.ts.map +1 -1
- package/dist/impl/middleware/store-sync-middleware.js +269 -57
- package/dist/impl/plugin/remote-fs-plugin-factory.d.ts +5 -4
- package/dist/impl/plugin/remote-fs-plugin-factory.d.ts.map +1 -1
- package/dist/impl/plugin/remote-fs-plugin-factory.js +1 -2
- package/dist/impl/providers/http-workspace-client.d.ts +5 -1
- package/dist/impl/providers/http-workspace-client.d.ts.map +1 -1
- package/dist/impl/providers/http-workspace-client.js +170 -5
- package/dist/spi/middleware/remote-fs-middleware.types.d.ts +21 -2
- package/dist/spi/middleware/remote-fs-middleware.types.d.ts.map +1 -1
- package/dist/spi/providers/i-workspace-client.d.ts +21 -3
- package/dist/spi/providers/i-workspace-client.d.ts.map +1 -1
- package/package.json +9 -8
|
@@ -25,4 +25,32 @@ export interface ErrorObject {
|
|
|
25
25
|
* Type guard to check if an object is an ErrorObject
|
|
26
26
|
*/
|
|
27
27
|
export declare function isErrorObject(obj: any): obj is ErrorObject;
|
|
28
|
+
/**
|
|
29
|
+
* Error code of a refused conditional write (amah/app-framework#70).
|
|
30
|
+
*
|
|
31
|
+
* The filesystem server answers a `PUT` whose `If-Match` does not equal the
|
|
32
|
+
* file's current version with `412 { code: 'version-mismatch', current }` and
|
|
33
|
+
* writes nothing. The HTTP client turns that into a {@link VersionMismatchError}.
|
|
34
|
+
*/
|
|
35
|
+
export declare const VERSION_MISMATCH = "version-mismatch";
|
|
36
|
+
/**
|
|
37
|
+
* The error a `putFile` rejects with when the server refused the write because
|
|
38
|
+
* the file changed since the caller read it.
|
|
39
|
+
*/
|
|
40
|
+
export interface VersionMismatchError extends ErrorObject {
|
|
41
|
+
code: typeof VERSION_MISMATCH;
|
|
42
|
+
params: {
|
|
43
|
+
/**
|
|
44
|
+
* The version the server holds now; `undefined` when the file no longer
|
|
45
|
+
* exists (the caller's copy was deleted underneath it).
|
|
46
|
+
*/
|
|
47
|
+
current: string | undefined;
|
|
48
|
+
/** HTTP status the server answered with (412). */
|
|
49
|
+
status?: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Type guard for {@link VersionMismatchError}.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isVersionMismatchError(obj: any): obj is VersionMismatchError;
|
|
28
56
|
//# sourceMappingURL=remote-fs-error.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-fs-error.types.d.ts","sourceRoot":"","sources":["../../../src/api/types/remote-fs-error.types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,WAAW,CAO1D"}
|
|
1
|
+
{"version":3,"file":"remote-fs-error.types.d.ts","sourceRoot":"","sources":["../../../src/api/types/remote-fs-error.types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,WAAW,CAO1D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,WAAW;IACvD,IAAI,EAAE,OAAO,gBAAgB,CAAC;IAC9B,MAAM,EAAE;QACN;;;WAGG;QACH,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,kDAAkD;QAClD,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,oBAAoB,CAQ5E"}
|
|
@@ -13,3 +13,21 @@ export function isErrorObject(obj) {
|
|
|
13
13
|
typeof obj.code === 'string' &&
|
|
14
14
|
typeof obj.message === 'string');
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Error code of a refused conditional write (amah/app-framework#70).
|
|
18
|
+
*
|
|
19
|
+
* The filesystem server answers a `PUT` whose `If-Match` does not equal the
|
|
20
|
+
* file's current version with `412 { code: 'version-mismatch', current }` and
|
|
21
|
+
* writes nothing. The HTTP client turns that into a {@link VersionMismatchError}.
|
|
22
|
+
*/
|
|
23
|
+
export const VERSION_MISMATCH = 'version-mismatch';
|
|
24
|
+
/**
|
|
25
|
+
* Type guard for {@link VersionMismatchError}.
|
|
26
|
+
*/
|
|
27
|
+
export function isVersionMismatchError(obj) {
|
|
28
|
+
return (isErrorObject(obj) &&
|
|
29
|
+
obj.code === VERSION_MISMATCH &&
|
|
30
|
+
typeof obj.params === 'object' &&
|
|
31
|
+
obj.params !== null &&
|
|
32
|
+
'current' in obj.params);
|
|
33
|
+
}
|
|
@@ -7,6 +7,26 @@
|
|
|
7
7
|
import { RemoteFsActionTypes, ErrorObject } from '../../api/index.js';
|
|
8
8
|
import { FileInfo } from '@hamak/shared-utils';
|
|
9
9
|
import { RequestOptions } from '../../spi/index.js';
|
|
10
|
+
/**
|
|
11
|
+
* Why a write (POST / PUT) failed (amah/app-framework#70).
|
|
12
|
+
*
|
|
13
|
+
* - `version-mismatch`: the server refused the write because the file changed
|
|
14
|
+
* since the client read it; `current` is the version the server holds now
|
|
15
|
+
* (`undefined` when the file was deleted). Nothing was written. The client
|
|
16
|
+
* should re-read, merge or ask, and write again with the new version — or
|
|
17
|
+
* resend with `ifMatch: false` to overwrite anyway.
|
|
18
|
+
* - `error`: any other failure; `error` has the details.
|
|
19
|
+
*/
|
|
20
|
+
export type WriteFailureReason = {
|
|
21
|
+
reason: 'version-mismatch';
|
|
22
|
+
current: string | undefined;
|
|
23
|
+
} | {
|
|
24
|
+
reason: 'error';
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Derive the {@link WriteFailureReason} of a write error.
|
|
28
|
+
*/
|
|
29
|
+
export declare function writeFailureReason(error: ErrorObject): WriteFailureReason;
|
|
10
30
|
export interface LsRequestAction {
|
|
11
31
|
type: RemoteFsActionTypes.LS_REQUEST;
|
|
12
32
|
payload: {
|
|
@@ -101,7 +121,7 @@ export interface PostFailedAction {
|
|
|
101
121
|
payload: {
|
|
102
122
|
error: ErrorObject;
|
|
103
123
|
request: PostRequestAction;
|
|
104
|
-
};
|
|
124
|
+
} & WriteFailureReason;
|
|
105
125
|
[key: string]: any;
|
|
106
126
|
}
|
|
107
127
|
export interface PutRequestAction {
|
|
@@ -126,7 +146,7 @@ export interface PutFailedAction {
|
|
|
126
146
|
payload: {
|
|
127
147
|
error: ErrorObject;
|
|
128
148
|
request: PutRequestAction;
|
|
129
|
-
};
|
|
149
|
+
} & WriteFailureReason;
|
|
130
150
|
[key: string]: any;
|
|
131
151
|
}
|
|
132
152
|
export interface DeleteRequestAction {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-fs-actions.d.ts","sourceRoot":"","sources":["../../../src/impl/actions/remote-fs-actions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"remote-fs-actions.d.ts","sourceRoot":"","sources":["../../../src/impl/actions/remote-fs-actions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAA0B,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,MAAM,EAAE,kBAAkB,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC3D;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAExB;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,kBAAkB,CAIzE;AAGD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAC,UAAU,CAAC;IACrC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,OAAO,CAAC,EAAE,cAAc,CAAA;KAAE,CAAC;IAC/D,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/core/remote-fs/src/lib/remote-fs-actions.ts
|
|
6
6
|
*/
|
|
7
|
-
import { RemoteFsActionTypes } from '../../api/index.js';
|
|
7
|
+
import { RemoteFsActionTypes, isVersionMismatchError } from '../../api/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Derive the {@link WriteFailureReason} of a write error.
|
|
10
|
+
*/
|
|
11
|
+
export function writeFailureReason(error) {
|
|
12
|
+
return isVersionMismatchError(error)
|
|
13
|
+
? { reason: 'version-mismatch', current: error.params.current }
|
|
14
|
+
: { reason: 'error' };
|
|
15
|
+
}
|
|
8
16
|
/**
|
|
9
17
|
* Action factory class for creating remote filesystem actions
|
|
10
18
|
*/
|
|
@@ -90,7 +98,7 @@ export class RemoteFsActionFactory {
|
|
|
90
98
|
ofPostFailed(error, request) {
|
|
91
99
|
return {
|
|
92
100
|
type: this.types.POST_FAILED,
|
|
93
|
-
payload: { error, request },
|
|
101
|
+
payload: { error, request, ...writeFailureReason(error) },
|
|
94
102
|
};
|
|
95
103
|
}
|
|
96
104
|
// PUT (Update File) operations
|
|
@@ -109,7 +117,7 @@ export class RemoteFsActionFactory {
|
|
|
109
117
|
ofPutFailed(error, request) {
|
|
110
118
|
return {
|
|
111
119
|
type: this.types.PUT_FAILED,
|
|
112
|
-
payload: { error, request },
|
|
120
|
+
payload: { error, request, ...writeFailureReason(error) },
|
|
113
121
|
};
|
|
114
122
|
}
|
|
115
123
|
// DELETE operations
|
|
@@ -1,55 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* (amah/app-framework#44).
|
|
6
|
-
*
|
|
7
|
-
* `store-sync-middleware.ts`'s `GET_COMPLETED` handler used to `JSON.parse`
|
|
8
|
-
* every file body unconditionally, with no `try`/`catch` anywhere in the
|
|
9
|
-
* middleware. Any non-JSON body (`.md`, `.sql`, `.txt`, `.css`, `.xqm`) threw
|
|
10
|
-
* a `SyntaxError` synchronously inside the redux dispatch chain, so the
|
|
11
|
-
* content never reached the store and a successful HTTP fetch turned into a
|
|
12
|
-
* spurious `GET_FAILED`. Classify the body by suffix *before* parsing, and
|
|
13
|
-
* never let a parse failure propagate.
|
|
2
|
+
* The suffix → media type table moved to `@hamak/shared-utils` (#68) so the
|
|
3
|
+
* shell's view resolvers and this read path share one table. Re-exported here
|
|
4
|
+
* so existing imports keep working.
|
|
14
5
|
*/
|
|
15
|
-
|
|
16
|
-
export declare const DEFAULT_CONTENT_TYPE = "text/plain";
|
|
17
|
-
/** The JSON media type — the only one whose bodies get parsed. */
|
|
18
|
-
export declare const JSON_CONTENT_TYPE = "application/json";
|
|
19
|
-
/** Media type for a file name, by suffix. Never throws; defaults to text/plain. */
|
|
20
|
-
export declare function contentTypeOf(name: string): string;
|
|
21
|
-
/**
|
|
22
|
-
* Is this file's body JSON? The single predicate both read paths ask.
|
|
23
|
-
* Derived from {@link contentTypeOf} so there is exactly one table.
|
|
24
|
-
*/
|
|
25
|
-
export declare function isJsonFileName(name: string): boolean;
|
|
26
|
-
/** Outcome of turning a raw file body into the value a filesystem stores. */
|
|
27
|
-
export interface DecodedFileContent {
|
|
28
|
-
/**
|
|
29
|
-
* The value to store. `undefined` for an absent body (and for an empty JSON
|
|
30
|
-
* body, which has no JSON value); the raw string for any non-JSON file; the
|
|
31
|
-
* parsed value for a JSON file.
|
|
32
|
-
*/
|
|
33
|
-
content: unknown;
|
|
34
|
-
/** The media type the decision was taken from. */
|
|
35
|
-
contentType: string;
|
|
36
|
-
/**
|
|
37
|
-
* Set when the file claimed to be JSON but its body did not parse. The error
|
|
38
|
-
* is *reported*, never thrown: `content` then falls back to the raw text so a
|
|
39
|
-
* single malformed file cannot wedge the load of any other.
|
|
40
|
-
*/
|
|
41
|
-
error?: Error;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Decode a raw file body for storage, classified by the file's name.
|
|
45
|
-
*
|
|
46
|
-
* Contract:
|
|
47
|
-
* - `undefined` / `null` body → `content: undefined` (nothing was sent).
|
|
48
|
-
* - JSON file, empty body → `content: undefined` (an empty string is not a JSON
|
|
49
|
-
* value; this preserves the historical store-fs behaviour).
|
|
50
|
-
* - JSON file, valid body → parsed value.
|
|
51
|
-
* - JSON file, invalid body → raw text plus `error` (contained, never thrown).
|
|
52
|
-
* - anything else → the raw string, verbatim (`''` stays `''`).
|
|
53
|
-
*/
|
|
54
|
-
export declare function decodeFileContent(name: string, raw: string | null | undefined): DecodedFileContent;
|
|
6
|
+
export { DEFAULT_CONTENT_TYPE, JSON_CONTENT_TYPE, contentTypeOf, isJsonFileName, decodeFileContent, type DecodedFileContent, } from '@hamak/shared-utils';
|
|
55
7
|
//# sourceMappingURL=file-content-type.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-content-type.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/file-content-type.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"file-content-type.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/file-content-type.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,93 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* (amah/app-framework#44).
|
|
6
|
-
*
|
|
7
|
-
* `store-sync-middleware.ts`'s `GET_COMPLETED` handler used to `JSON.parse`
|
|
8
|
-
* every file body unconditionally, with no `try`/`catch` anywhere in the
|
|
9
|
-
* middleware. Any non-JSON body (`.md`, `.sql`, `.txt`, `.css`, `.xqm`) threw
|
|
10
|
-
* a `SyntaxError` synchronously inside the redux dispatch chain, so the
|
|
11
|
-
* content never reached the store and a successful HTTP fetch turned into a
|
|
12
|
-
* spurious `GET_FAILED`. Classify the body by suffix *before* parsing, and
|
|
13
|
-
* never let a parse failure propagate.
|
|
2
|
+
* The suffix → media type table moved to `@hamak/shared-utils` (#68) so the
|
|
3
|
+
* shell's view resolvers and this read path share one table. Re-exported here
|
|
4
|
+
* so existing imports keep working.
|
|
14
5
|
*/
|
|
15
|
-
|
|
16
|
-
* Suffix → media type, first match wins.
|
|
17
|
-
*
|
|
18
|
-
* The JSON rows are not just `.json`: a few Designer file types carry a JSON
|
|
19
|
-
* body under another suffix and are opened by viewers that expect a parsed
|
|
20
|
-
* value — `.jm` (declared alongside `.jm.json` by the json-mapper plugin
|
|
21
|
-
* manifest) and `.prismapp` (an app manifest, JSON by construction). If a new
|
|
22
|
-
* file type is declared with a JSON body and a non-`.json` suffix, it belongs
|
|
23
|
-
* on this list; that is the whole point of the list being here and nowhere else.
|
|
24
|
-
*/
|
|
25
|
-
const SUFFIX_CONTENT_TYPES = [
|
|
26
|
-
[/\.json$/i, 'application/json'],
|
|
27
|
-
[/\.jm$/i, 'application/json'],
|
|
28
|
-
[/\.prismapp$/i, 'application/json'],
|
|
29
|
-
[/\.css$/i, 'text/css'],
|
|
30
|
-
[/\.xqm$/i, 'application/xquery'],
|
|
31
|
-
[/\.xq$/i, 'application/xquery'],
|
|
32
|
-
[/\.xquery$/i, 'application/xquery'],
|
|
33
|
-
[/\.md$/i, 'text/markdown'],
|
|
34
|
-
[/\.sql$/i, 'application/sql'],
|
|
35
|
-
[/\.ya?ml$/i, 'application/yaml'],
|
|
36
|
-
[/\.html?$/i, 'text/html'],
|
|
37
|
-
[/\.svg$/i, 'image/svg+xml'],
|
|
38
|
-
[/\.xml$/i, 'application/xml'],
|
|
39
|
-
[/\.jsx?$/i, 'text/javascript'],
|
|
40
|
-
[/\.tsx?$/i, 'text/typescript'],
|
|
41
|
-
];
|
|
42
|
-
/** What a file with no recognised suffix is assumed to be: opaque text. */
|
|
43
|
-
export const DEFAULT_CONTENT_TYPE = 'text/plain';
|
|
44
|
-
/** The JSON media type — the only one whose bodies get parsed. */
|
|
45
|
-
export const JSON_CONTENT_TYPE = 'application/json';
|
|
46
|
-
/** Media type for a file name, by suffix. Never throws; defaults to text/plain. */
|
|
47
|
-
export function contentTypeOf(name) {
|
|
48
|
-
for (const [pattern, type] of SUFFIX_CONTENT_TYPES) {
|
|
49
|
-
if (pattern.test(name))
|
|
50
|
-
return type;
|
|
51
|
-
}
|
|
52
|
-
return DEFAULT_CONTENT_TYPE;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Is this file's body JSON? The single predicate both read paths ask.
|
|
56
|
-
* Derived from {@link contentTypeOf} so there is exactly one table.
|
|
57
|
-
*/
|
|
58
|
-
export function isJsonFileName(name) {
|
|
59
|
-
return contentTypeOf(name) === JSON_CONTENT_TYPE;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Decode a raw file body for storage, classified by the file's name.
|
|
63
|
-
*
|
|
64
|
-
* Contract:
|
|
65
|
-
* - `undefined` / `null` body → `content: undefined` (nothing was sent).
|
|
66
|
-
* - JSON file, empty body → `content: undefined` (an empty string is not a JSON
|
|
67
|
-
* value; this preserves the historical store-fs behaviour).
|
|
68
|
-
* - JSON file, valid body → parsed value.
|
|
69
|
-
* - JSON file, invalid body → raw text plus `error` (contained, never thrown).
|
|
70
|
-
* - anything else → the raw string, verbatim (`''` stays `''`).
|
|
71
|
-
*/
|
|
72
|
-
export function decodeFileContent(name, raw) {
|
|
73
|
-
const contentType = contentTypeOf(name);
|
|
74
|
-
if (raw === undefined || raw === null) {
|
|
75
|
-
return { content: undefined, contentType };
|
|
76
|
-
}
|
|
77
|
-
if (contentType !== JSON_CONTENT_TYPE) {
|
|
78
|
-
return { content: raw, contentType };
|
|
79
|
-
}
|
|
80
|
-
if (raw === '') {
|
|
81
|
-
return { content: undefined, contentType };
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
return { content: JSON.parse(raw), contentType };
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
return {
|
|
88
|
-
content: raw,
|
|
89
|
-
contentType,
|
|
90
|
-
error: e instanceof Error ? e : new Error(String(e)),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
6
|
+
export { DEFAULT_CONTENT_TYPE, JSON_CONTENT_TYPE, contentTypeOf, isJsonFileName, decodeFileContent, } from '@hamak/shared-utils';
|
|
@@ -3,6 +3,28 @@
|
|
|
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 { AnyAction, Middleware } from '@reduxjs/toolkit';
|
|
8
30
|
import type { IWorkspaceClient, IPathTranslator } from '../../spi/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-fs-middleware.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/remote-fs-middleware.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"remote-fs-middleware.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/remote-fs-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAkB,MAAM,WAAW,CAAC;AACnF,OAAO,EAAyC,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAWpF;;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,CA8bnB;AAED,eAAe,wBAAwB,CAAC"}
|