@hamak/ui-remote-fs 0.10.0 → 0.11.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 +114 -18
- 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 +25 -2
- 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 +1 -1
|
@@ -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"],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YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,gBAAgB;IAO/F,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,GAAG,kBAAkB;IAO7E,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,GAAG,eAAe;IAQ3E,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,mBAAmB;IAOvF,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,mBAAmB,GAAG,qBAAqB;IAOtF,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,mBAAmB,GAAG,kBAAkB;IAOpF;;OAEG;IACH,gBAAgB,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,cAAc;CAQxD;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,uBAA8B,CAAC;AAEtD;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -4,7 +4,15 @@
|
|
|
4
4
|
* Action creators for remote filesystem operations.
|
|
5
5
|
* Migrated from amk/libs/ui/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,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,CAmQnB;AAED,eAAe,wBAAwB,CAAC"}
|
|
@@ -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 { Pathway } from '@hamak/shared-utils';
|
|
8
30
|
import { RemoteFsActionTypes } from '../../api/index.js';
|
|
@@ -45,6 +67,46 @@ export function createRemoteFsMiddleware(config) {
|
|
|
45
67
|
message: error?.message || 'Unknown error',
|
|
46
68
|
};
|
|
47
69
|
};
|
|
70
|
+
/** Version last seen for a remote path (key: segments joined by '/'). */
|
|
71
|
+
const knownVersions = new Map();
|
|
72
|
+
const keyOf = (segments) => segments.join('/');
|
|
73
|
+
const remember = (segments, version) => {
|
|
74
|
+
if (version === undefined) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
knownVersions.set(keyOf(segments), version);
|
|
78
|
+
};
|
|
79
|
+
/** Tail of the in-flight requests, per remote path. */
|
|
80
|
+
const queues = new Map();
|
|
81
|
+
/**
|
|
82
|
+
* Run `task` once every earlier request to the same remote path has
|
|
83
|
+
* settled.
|
|
84
|
+
*/
|
|
85
|
+
const serialized = (segments, task) => {
|
|
86
|
+
const key = keyOf(segments);
|
|
87
|
+
const previous = queues.get(key) ?? Promise.resolve();
|
|
88
|
+
const settled = previous.then(task, task).catch(() => undefined);
|
|
89
|
+
queues.set(key, settled);
|
|
90
|
+
void settled.then(() => {
|
|
91
|
+
if (queues.get(key) === settled) {
|
|
92
|
+
queues.delete(key);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The options a PUT is sent with: the caller's, with the remembered
|
|
98
|
+
* version as `ifMatch` when the caller left it open.
|
|
99
|
+
*/
|
|
100
|
+
const withPrecondition = (segments, options) => {
|
|
101
|
+
if (options?.ifMatch !== undefined) {
|
|
102
|
+
return options;
|
|
103
|
+
}
|
|
104
|
+
const known = knownVersions.get(keyOf(segments));
|
|
105
|
+
if (known === undefined) {
|
|
106
|
+
return options;
|
|
107
|
+
}
|
|
108
|
+
return { ...options, ifMatch: known };
|
|
109
|
+
};
|
|
48
110
|
const remoteFsMiddleware = (store) => (next) => (action) => {
|
|
49
111
|
const result = next(action);
|
|
50
112
|
const dispatch = store.dispatch;
|
|
@@ -56,9 +118,22 @@ export function createRemoteFsMiddleware(config) {
|
|
|
56
118
|
if (remotePath === undefined) {
|
|
57
119
|
break;
|
|
58
120
|
}
|
|
59
|
-
|
|
121
|
+
const segments = remotePath.getSegments();
|
|
122
|
+
serialized(segments, async () => {
|
|
60
123
|
try {
|
|
61
|
-
const data = await client.listFiles(
|
|
124
|
+
const data = await client.listFiles(segments, requestAction.payload.options);
|
|
125
|
+
// A listing fills in versions it does not know yet, but never
|
|
126
|
+
// replaces one learnt from an operation on the file itself: a
|
|
127
|
+
// listing runs on the directory's queue, so it may overlap a write
|
|
128
|
+
// to one of its entries and come back with that entry's older
|
|
129
|
+
// version. A version that is stale anyway costs one refused write,
|
|
130
|
+
// which reports the current one.
|
|
131
|
+
data?.forEach((entry) => {
|
|
132
|
+
const entryPath = [...segments, entry.name];
|
|
133
|
+
if (!entry.isDirectory && !knownVersions.has(keyOf(entryPath))) {
|
|
134
|
+
remember(entryPath, entry.version);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
62
137
|
const completedAction = rfsActions.ofLsCompleted(data, requestAction);
|
|
63
138
|
dispatch(completedAction);
|
|
64
139
|
onSuccess?.(data, completedAction);
|
|
@@ -69,7 +144,7 @@ export function createRemoteFsMiddleware(config) {
|
|
|
69
144
|
dispatch(failedAction);
|
|
70
145
|
onError?.(errorObject, failedAction);
|
|
71
146
|
}
|
|
72
|
-
})
|
|
147
|
+
});
|
|
73
148
|
break;
|
|
74
149
|
}
|
|
75
150
|
case RemoteFsActionTypes.MKDIR_REQUEST: {
|
|
@@ -78,9 +153,10 @@ export function createRemoteFsMiddleware(config) {
|
|
|
78
153
|
if (remotePath === undefined) {
|
|
79
154
|
break;
|
|
80
155
|
}
|
|
81
|
-
|
|
156
|
+
const segments = remotePath.getSegments();
|
|
157
|
+
serialized(segments, async () => {
|
|
82
158
|
try {
|
|
83
|
-
const data = await client.createDirectory(
|
|
159
|
+
const data = await client.createDirectory(segments, requestAction.payload.options);
|
|
84
160
|
const completedAction = rfsActions.ofMkdirCompleted(data, requestAction);
|
|
85
161
|
dispatch(completedAction);
|
|
86
162
|
onSuccess?.(data, completedAction);
|
|
@@ -91,7 +167,7 @@ export function createRemoteFsMiddleware(config) {
|
|
|
91
167
|
dispatch(failedAction);
|
|
92
168
|
onError?.(errorObject, failedAction);
|
|
93
169
|
}
|
|
94
|
-
})
|
|
170
|
+
});
|
|
95
171
|
break;
|
|
96
172
|
}
|
|
97
173
|
case RemoteFsActionTypes.GET_REQUEST: {
|
|
@@ -100,9 +176,11 @@ export function createRemoteFsMiddleware(config) {
|
|
|
100
176
|
if (remotePath === undefined) {
|
|
101
177
|
break;
|
|
102
178
|
}
|
|
103
|
-
|
|
179
|
+
const segments = remotePath.getSegments();
|
|
180
|
+
serialized(segments, async () => {
|
|
104
181
|
try {
|
|
105
|
-
const data = await client.readFile(
|
|
182
|
+
const data = await client.readFile(segments, requestAction.payload.options);
|
|
183
|
+
remember(segments, data?.version);
|
|
106
184
|
const completedAction = rfsActions.ofGetCompleted(data, requestAction);
|
|
107
185
|
dispatch(completedAction);
|
|
108
186
|
onSuccess?.(data, completedAction);
|
|
@@ -113,7 +191,7 @@ export function createRemoteFsMiddleware(config) {
|
|
|
113
191
|
dispatch(failedAction);
|
|
114
192
|
onError?.(errorObject, failedAction);
|
|
115
193
|
}
|
|
116
|
-
})
|
|
194
|
+
});
|
|
117
195
|
break;
|
|
118
196
|
}
|
|
119
197
|
case RemoteFsActionTypes.POST_REQUEST: {
|
|
@@ -122,9 +200,13 @@ export function createRemoteFsMiddleware(config) {
|
|
|
122
200
|
if (remotePath === undefined) {
|
|
123
201
|
break;
|
|
124
202
|
}
|
|
125
|
-
|
|
203
|
+
const segments = remotePath.getSegments();
|
|
204
|
+
serialized(segments, async () => {
|
|
126
205
|
try {
|
|
127
|
-
|
|
206
|
+
// A POST creates: it is sent with exactly the options it was
|
|
207
|
+
// dispatched with, and never gets a remembered version.
|
|
208
|
+
const data = await client.putFile(segments, requestAction.payload.content, requestAction.payload.options);
|
|
209
|
+
remember(segments, data?.version);
|
|
128
210
|
const completedAction = rfsActions.ofPostCompleted(data, requestAction);
|
|
129
211
|
dispatch(completedAction);
|
|
130
212
|
onSuccess?.(data, completedAction);
|
|
@@ -135,7 +217,7 @@ export function createRemoteFsMiddleware(config) {
|
|
|
135
217
|
dispatch(failedAction);
|
|
136
218
|
onError?.(errorObject, failedAction);
|
|
137
219
|
}
|
|
138
|
-
})
|
|
220
|
+
});
|
|
139
221
|
break;
|
|
140
222
|
}
|
|
141
223
|
case RemoteFsActionTypes.PUT_REQUEST: {
|
|
@@ -144,9 +226,11 @@ export function createRemoteFsMiddleware(config) {
|
|
|
144
226
|
if (remotePath === undefined) {
|
|
145
227
|
break;
|
|
146
228
|
}
|
|
147
|
-
|
|
229
|
+
const segments = remotePath.getSegments();
|
|
230
|
+
serialized(segments, async () => {
|
|
148
231
|
try {
|
|
149
|
-
const data = await client.putFile(
|
|
232
|
+
const data = await client.putFile(segments, requestAction.payload.content, withPrecondition(segments, requestAction.payload.options));
|
|
233
|
+
remember(segments, data?.version);
|
|
150
234
|
const completedAction = rfsActions.ofPutCompleted(data, requestAction);
|
|
151
235
|
dispatch(completedAction);
|
|
152
236
|
onSuccess?.(data, completedAction);
|
|
@@ -154,10 +238,20 @@ export function createRemoteFsMiddleware(config) {
|
|
|
154
238
|
catch (error) {
|
|
155
239
|
const errorObject = handleError(error);
|
|
156
240
|
const failedAction = rfsActions.ofPutFailed(errorObject, requestAction);
|
|
241
|
+
if (failedAction.payload.reason === 'version-mismatch') {
|
|
242
|
+
// The server told us what it holds now; a retry with the
|
|
243
|
+
// remembered version would only be refused again.
|
|
244
|
+
if (failedAction.payload.current === undefined) {
|
|
245
|
+
knownVersions.delete(keyOf(segments));
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
remember(segments, failedAction.payload.current);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
157
251
|
dispatch(failedAction);
|
|
158
252
|
onError?.(errorObject, failedAction);
|
|
159
253
|
}
|
|
160
|
-
})
|
|
254
|
+
});
|
|
161
255
|
break;
|
|
162
256
|
}
|
|
163
257
|
case RemoteFsActionTypes.DELETE_REQUEST: {
|
|
@@ -166,9 +260,11 @@ export function createRemoteFsMiddleware(config) {
|
|
|
166
260
|
if (remotePath === undefined) {
|
|
167
261
|
break;
|
|
168
262
|
}
|
|
169
|
-
|
|
263
|
+
const segments = remotePath.getSegments();
|
|
264
|
+
serialized(segments, async () => {
|
|
170
265
|
try {
|
|
171
|
-
const data = await client.deleteFile(
|
|
266
|
+
const data = await client.deleteFile(segments, requestAction.payload.options);
|
|
267
|
+
knownVersions.delete(keyOf(segments));
|
|
172
268
|
const completedAction = rfsActions.ofDeleteCompleted(data, requestAction);
|
|
173
269
|
dispatch(completedAction);
|
|
174
270
|
onSuccess?.(data, completedAction);
|
|
@@ -179,7 +275,7 @@ export function createRemoteFsMiddleware(config) {
|
|
|
179
275
|
dispatch(failedAction);
|
|
180
276
|
onError?.(errorObject, failedAction);
|
|
181
277
|
}
|
|
182
|
-
})
|
|
278
|
+
});
|
|
183
279
|
break;
|
|
184
280
|
}
|
|
185
281
|
default:
|
|
@@ -98,7 +98,11 @@ export declare class HttpWorkspaceClient implements IWorkspaceClient {
|
|
|
98
98
|
*/
|
|
99
99
|
readFile(path: string[], options?: RequestOptions): Promise<FileInfo>;
|
|
100
100
|
/**
|
|
101
|
-
* Write or update a file's content (uses PUT method)
|
|
101
|
+
* Write or update a file's content (uses PUT method).
|
|
102
|
+
*
|
|
103
|
+
* With `options.ifMatch` set to a version, the request carries
|
|
104
|
+
* `If-Match: "<version>"` and the server only writes when the file still has
|
|
105
|
+
* that version; otherwise it rejects with a `VersionMismatchError` (#70).
|
|
102
106
|
*/
|
|
103
107
|
putFile(path: string[], content: any, options?: RequestOptions): Promise<FileInfo>;
|
|
104
108
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-workspace-client.d.ts","sourceRoot":"","sources":["../../../src/impl/providers/http-workspace-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAAE,aAAa,EAAc,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,mBAAoB,YAAW,gBAAgB;IAC1D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,MAAM,EAAE,yBAAyB;IAoB7C;;OAEG;IACH,OAAO,CAAC,UAAU;IAIlB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAmBhB;;OAEG;IACH,OAAO,CAAC,WAAW;
|
|
1
|
+
{"version":3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EG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC;IAc3E;;;;;;OAMG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC;IAoBxF;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC;IAc7E;;OAEG;IACH,cAAc,IAAI,MAAM;IAIxB;;OAEG;IACH,UAAU,IAAI,MAAM;CAGrB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,IAAI,CAAC,yBAAyB,EAAE,aAAa,GAAG,SAAS,CAAC,GACnE,mBAAmB,CAMrB"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Migrated from amk/libs/server/ws/ws-client/src/lib/server-ws-ws-client.ts
|
|
6
6
|
*/
|
|
7
7
|
import axios from 'axios';
|
|
8
|
+
import { VERSION_MISMATCH } from '../../api/index.js';
|
|
8
9
|
/**
|
|
9
10
|
* HTTP-based implementation of IWorkspaceClient
|
|
10
11
|
*
|
|
@@ -96,6 +97,20 @@ export class HttpWorkspaceClient {
|
|
|
96
97
|
handleError(error) {
|
|
97
98
|
if (axios.isAxiosError(error)) {
|
|
98
99
|
const axiosError = error;
|
|
100
|
+
// A refused conditional write (#70): 412 with the server's own body,
|
|
101
|
+
// surfaced as a typed error so the caller can tell "the file moved"
|
|
102
|
+
// from "the request failed".
|
|
103
|
+
if (axiosError.response?.status === 412 && axiosError.response.data?.code === VERSION_MISMATCH) {
|
|
104
|
+
const mismatch = {
|
|
105
|
+
code: VERSION_MISMATCH,
|
|
106
|
+
message: 'The file changed on the server since it was read; nothing was written',
|
|
107
|
+
params: {
|
|
108
|
+
current: axiosError.response.data.current ?? undefined,
|
|
109
|
+
status: 412,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
throw mismatch;
|
|
113
|
+
}
|
|
99
114
|
// Try to extract error from response
|
|
100
115
|
if (axiosError.response?.data?.error) {
|
|
101
116
|
throw axiosError.response.data.error;
|
|
@@ -181,14 +196,22 @@ export class HttpWorkspaceClient {
|
|
|
181
196
|
}
|
|
182
197
|
}
|
|
183
198
|
/**
|
|
184
|
-
* Write or update a file's content (uses PUT method)
|
|
199
|
+
* Write or update a file's content (uses PUT method).
|
|
200
|
+
*
|
|
201
|
+
* With `options.ifMatch` set to a version, the request carries
|
|
202
|
+
* `If-Match: "<version>"` and the server only writes when the file still has
|
|
203
|
+
* that version; otherwise it rejects with a `VersionMismatchError` (#70).
|
|
185
204
|
*/
|
|
186
205
|
async putFile(path, content, options) {
|
|
187
206
|
try {
|
|
188
207
|
const formattedPath = this.formatPath(path);
|
|
189
208
|
const serializedContent = this.serializeContent(content);
|
|
190
209
|
const url = this.buildUrl(`/${this.workspaceId}/put/${formattedPath}`, options);
|
|
191
|
-
const
|
|
210
|
+
const ifMatch = options?.ifMatch;
|
|
211
|
+
const config = typeof ifMatch === 'string' && ifMatch.length > 0
|
|
212
|
+
? { headers: { 'If-Match': `"${ifMatch}"` } }
|
|
213
|
+
: undefined;
|
|
214
|
+
const response = await this.axios.put(url, { content: serializedContent }, config);
|
|
192
215
|
return response.data;
|
|
193
216
|
}
|
|
194
217
|
catch (error) {
|
|
@@ -20,6 +20,20 @@ export interface RequestOptions {
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
queryParams?: Record<string, string | string[] | boolean | number | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Write precondition (amah/app-framework#70): the `FileInfo.version` the
|
|
25
|
+
* caller last read for this file. `putFile` sends it as `If-Match`; the
|
|
26
|
+
* server refuses the write with a `version-mismatch` error when the file has
|
|
27
|
+
* changed since, and nothing is written.
|
|
28
|
+
*
|
|
29
|
+
* - `undefined`: no precondition from the caller. The remote-fs middleware
|
|
30
|
+
* then fills in the version it last saw for that path, if any.
|
|
31
|
+
* - `false`: write unconditionally, even if a version is known (the "overwrite
|
|
32
|
+
* anyway" gesture after a refused write).
|
|
33
|
+
*
|
|
34
|
+
* Only `putFile` reads it. A client whose backend has no versions ignores it.
|
|
35
|
+
*/
|
|
36
|
+
ifMatch?: string | false;
|
|
23
37
|
}
|
|
24
38
|
/**
|
|
25
39
|
* Interface for workspace client implementations
|
|
@@ -77,9 +91,13 @@ export interface IWorkspaceClient {
|
|
|
77
91
|
* @param content - Content to write. Strings are sent verbatim; anything else
|
|
78
92
|
* is serialized to pretty-printed JSON, since the result is written to disk
|
|
79
93
|
* as-is and read by humans.
|
|
80
|
-
* @param options - Optional request options
|
|
81
|
-
*
|
|
82
|
-
* @
|
|
94
|
+
* @param options - Optional request options. `ifMatch` makes the write
|
|
95
|
+
* conditional on the file's version (see {@link RequestOptions.ifMatch}).
|
|
96
|
+
* @returns Promise resolving to FileInfo of the written file, carrying its
|
|
97
|
+
* new `version` when the backend has versions
|
|
98
|
+
* @throws Error if the operation fails; a refused conditional write throws a
|
|
99
|
+
* `VersionMismatchError` (`code: 'version-mismatch'`, `params.current` the
|
|
100
|
+
* version now on the server) and has written nothing
|
|
83
101
|
*/
|
|
84
102
|
putFile(path: string[], content: any, options?: RequestOptions): Promise<FileInfo>;
|
|
85
103
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i-workspace-client.d.ts","sourceRoot":"","sources":["../../../src/spi/providers/i-workspace-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE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