@hydranium/protocol 1.0.0-next.117 → 1.0.0-next.123
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/lib/client/data-connection.d.ts +28 -66
- package/lib/client/data-connection.d.ts.map +1 -1
- package/lib/client/data-connection.js +41 -112
- package/lib/client/data-connection.js.map +1 -1
- package/lib/client/data-session.d.ts +168 -93
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +291 -147
- package/lib/client/data-session.js.map +1 -1
- package/lib/data/data-protocol-methods.d.ts +2 -2
- package/lib/data/data-protocol-methods.d.ts.map +1 -1
- package/lib/data/data-protocol-methods.js +4 -0
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +66 -30
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/requests.d.ts +67 -11
- package/lib/data/requests.d.ts.map +1 -1
- package/lib/errors.d.ts +66 -4
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +96 -5
- package/lib/errors.js.map +1 -1
- package/lib/messages/index.d.ts +1 -0
- package/lib/messages/index.d.ts.map +1 -1
- package/lib/messages/index.js +4 -1
- package/lib/messages/index.js.map +1 -1
- package/lib/model-server.d.ts +13 -1
- package/lib/model-server.d.ts.map +1 -1
- package/lib/model-server.js.map +1 -1
- package/lib/model-service/based-on.d.ts +2 -0
- package/lib/model-service/based-on.d.ts.map +1 -1
- package/lib/model-service/based-on.js +3 -0
- package/lib/model-service/based-on.js.map +1 -1
- package/lib/model-service/index.d.ts +0 -1
- package/lib/model-service/index.d.ts.map +1 -1
- package/lib/model-service/index.js +3 -5
- package/lib/model-service/index.js.map +1 -1
- package/lib/patch-merge.d.ts +28 -27
- package/lib/patch-merge.d.ts.map +1 -1
- package/lib/patch-merge.js +66 -22
- package/lib/patch-merge.js.map +1 -1
- package/lib/transfer-document.d.ts +2 -3
- package/lib/transfer-document.d.ts.map +1 -1
- package/lib/transfer-document.js.map +1 -1
- package/package.json +1 -1
- package/src/client/data-connection.ts +69 -119
- package/src/client/data-session.ts +348 -177
- package/src/data/data-protocol-methods.ts +4 -0
- package/src/data/data-server-protocol.ts +74 -30
- package/src/data/requests.ts +71 -11
- package/src/errors.ts +101 -4
- package/src/messages/index.ts +1 -0
- package/src/model-server.ts +13 -5
- package/src/model-service/based-on.ts +3 -0
- package/src/model-service/index.ts +3 -5
- package/src/patch-merge.ts +90 -37
- package/src/transfer-document.ts +2 -3
- package/lib/model-service/args.d.ts +0 -65
- package/lib/model-service/args.d.ts.map +0 -1
- package/lib/model-service/args.js +0 -11
- package/lib/model-service/args.js.map +0 -1
- package/src/model-service/args.ts +0 -69
|
@@ -20,6 +20,10 @@ import type {
|
|
|
20
20
|
|
|
21
21
|
/** Request-method names on {@link DocumentServerProtocol}. */
|
|
22
22
|
export const DOCUMENT_SERVER_PROTOCOL_METHODS = [
|
|
23
|
+
'createSession',
|
|
24
|
+
'closeSession',
|
|
25
|
+
'createModelDocument',
|
|
26
|
+
'updateModelDocuments',
|
|
23
27
|
'openModelDocument',
|
|
24
28
|
'closeModelDocument',
|
|
25
29
|
'getModelDocument',
|
|
@@ -21,11 +21,15 @@ import type {
|
|
|
21
21
|
TransferDocumentUpdatedEvent
|
|
22
22
|
} from './events';
|
|
23
23
|
import type {
|
|
24
|
+
CloseSessionArgs,
|
|
25
|
+
CreateModelDocumentArgs,
|
|
26
|
+
CreateSessionArgs,
|
|
24
27
|
GetModelDocumentArgs,
|
|
25
28
|
GetProjectForUriArgs,
|
|
26
29
|
TransferSaveDocumentArgs,
|
|
27
30
|
WatchModelDocumentArgs,
|
|
28
|
-
TransferUpdateDocumentArgs
|
|
31
|
+
TransferUpdateDocumentArgs,
|
|
32
|
+
TransferUpdateDocumentsArgs
|
|
29
33
|
} from './requests';
|
|
30
34
|
|
|
31
35
|
/**
|
|
@@ -46,35 +50,74 @@ import type {
|
|
|
46
50
|
*/
|
|
47
51
|
export interface DocumentServerProtocol<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic> {
|
|
48
52
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* document at the server's configured target phase — the same shape
|
|
53
|
-
* {@link getModelDocument} returns, except that `version` is taken from
|
|
54
|
-
* the text-document store so the caller's first `basedOn` write
|
|
55
|
-
* cannot self-conflict. Idempotent in registration terms: opening an
|
|
56
|
-
* already-open document refreshes the client registration. Note it does
|
|
57
|
-
* NOT avoid a rebuild — a second client attaching triggers
|
|
58
|
-
* `refreshContent`, which fires a change event, so mounting a form on a
|
|
59
|
-
* document already open in a text editor rebuilds it.
|
|
53
|
+
* Register `args.clientId` as a client session owned by this connection.
|
|
54
|
+
* Rejects with a `DuplicateClientIdError` code when the id is live anywhere
|
|
55
|
+
* in the server process or reserved by the framework.
|
|
60
56
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
57
|
+
* A request carrying a registered id acts as that session: it writes only
|
|
58
|
+
* what the session has open, failing with a `DocumentNotOpenError` code
|
|
59
|
+
* otherwise, and opens nothing implicitly; its open reads the file and takes
|
|
60
|
+
* no `languageId`, `version` or `text` seed. The session ends with
|
|
61
|
+
* {@link closeSession} or when the connection closes, and either closes
|
|
62
|
+
* every document it has open.
|
|
63
|
+
*
|
|
64
|
+
* A registration carrying the `resumeToken` an earlier registration of the
|
|
65
|
+
* same id carried ends that session first, from any connection, so a client
|
|
66
|
+
* whose connection dropped can register again before the server notices.
|
|
67
|
+
*/
|
|
68
|
+
createSession(args: CreateSessionArgs): Promise<void>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* End a session this connection registered: close every document it has
|
|
72
|
+
* open, drop its watches, and free its id. A no-op for an id this
|
|
73
|
+
* connection did not register.
|
|
74
|
+
*/
|
|
75
|
+
closeSession(args: CloseSessionArgs): Promise<void>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Create a document with `args.text`, open for the session, and return it
|
|
79
|
+
* as {@link openModelDocument} does. It reaches disk with the first save.
|
|
80
|
+
* Fails when the file exists or any client has the URI open, and with a
|
|
81
|
+
* `SessionClosedError` code when `args.clientId` is not a session
|
|
82
|
+
* registered on this connection.
|
|
83
|
+
*/
|
|
84
|
+
createModelDocument(args: CreateModelDocumentArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Write several documents the session has open, all or none: a conflict or
|
|
88
|
+
* a document not open fails the whole set before any text applies.
|
|
89
|
+
* Resolves to the documents in the order given. Only for a session
|
|
90
|
+
* registered on this connection.
|
|
91
|
+
*/
|
|
92
|
+
updateModelDocuments(args: TransferUpdateDocumentsArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>[]>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Open a document for the client session `clientId` and return its current
|
|
96
|
+
* state. `clientId` must be a session this connection registered with
|
|
97
|
+
* {@link createSession}; any other id fails with the closed-session code,
|
|
98
|
+
* as every document request here does. The document is read from disk
|
|
99
|
+
* unless a client has it open already, so the request carries no
|
|
100
|
+
* `languageId`, `version` or `text` seed. Returns the document at
|
|
101
|
+
* the server's configured target phase — the same shape
|
|
102
|
+
* {@link getModelDocument} returns, except that `version` is taken from the
|
|
103
|
+
* text-document store so the caller's first `basedOn` write cannot
|
|
104
|
+
* self-conflict. A repeat open changes nothing.
|
|
105
|
+
*
|
|
106
|
+
* Pair with {@link watchModelDocument} to receive subsequent build-phase
|
|
107
|
+
* events (open returns a one-shot snapshot; later validation diagnostics
|
|
108
|
+
* arrive on the watch channel).
|
|
65
109
|
*/
|
|
66
|
-
openModelDocument(args: OpenModelArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
110
|
+
openModelDocument(args: Pick<OpenModelArgs, 'uri' | 'clientId' | 'options'>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
67
111
|
|
|
68
112
|
/**
|
|
69
|
-
* Close
|
|
70
|
-
* {@link openModelDocument}; the
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* the
|
|
76
|
-
*
|
|
77
|
-
* reader can open without streaming.
|
|
113
|
+
* Close the session's open of `uri`. Counterpart to
|
|
114
|
+
* {@link openModelDocument}; the document stays open until every client
|
|
115
|
+
* has closed it, and the last close reverts it to disk. The default
|
|
116
|
+
* `DataServer` impl ALSO releases any watch for the same
|
|
117
|
+
* `(uri, clientId)` (a forgotten {@link unwatchModelDocument} would
|
|
118
|
+
* otherwise leak dispatch; the implicit unwatch is idempotent).
|
|
119
|
+
* `watchModelDocument` is NOT coupled the other way: opening does not force
|
|
120
|
+
* a watch, so a snapshot reader can open without streaming.
|
|
78
121
|
*/
|
|
79
122
|
closeModelDocument(args: CloseModelArgs): Promise<void>;
|
|
80
123
|
|
|
@@ -87,14 +130,15 @@ export interface DocumentServerProtocol<TTransfer extends TransferElement, TDiag
|
|
|
87
130
|
getModelDocument(args: GetModelDocumentArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
88
131
|
|
|
89
132
|
/**
|
|
90
|
-
* Update a document's content
|
|
91
|
-
*
|
|
92
|
-
* response.
|
|
133
|
+
* Update a document's content as the session `clientId`, which must have
|
|
134
|
+
* it open. The response carries the latest built state including
|
|
135
|
+
* diagnostics; callers observe convergence via that response.
|
|
93
136
|
*/
|
|
94
137
|
updateModelDocument(args: TransferUpdateDocumentArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
95
138
|
|
|
96
139
|
/**
|
|
97
|
-
*
|
|
140
|
+
* Write a document as the session `clientId`, which must have it open, and
|
|
141
|
+
* persist it to disk. The response is the post-save document
|
|
98
142
|
* state (matches the file on disk). Save semantics depend on the
|
|
99
143
|
* filesystem-provider wiring; rejection paths surface as awaited
|
|
100
144
|
* promise rejections.
|
package/src/data/requests.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import type {
|
|
10
|
+
import type { BasedOn } from '../model-service/based-on';
|
|
11
11
|
|
|
12
12
|
/** Get the current state of a single document. The server returns the latest built version. */
|
|
13
13
|
export interface GetModelDocumentArgs {
|
|
@@ -41,24 +41,84 @@ export interface GetProjectForUriArgs {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* Update a document
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* without an args mapping.
|
|
44
|
+
* Update a document the session `clientId` has open. Generic over `TTransfer`
|
|
45
|
+
* so adopters parameterise the structured shape against their grammar's
|
|
46
|
+
* transfer-model overlay; passing a string is always allowed.
|
|
48
47
|
*/
|
|
49
|
-
export
|
|
48
|
+
export interface TransferUpdateDocumentArgs<TTransfer> {
|
|
49
|
+
/** Document URI. */
|
|
50
|
+
uri: string;
|
|
51
|
+
/** The id of a live session registered on this connection. */
|
|
52
|
+
clientId: string;
|
|
53
|
+
/** The whole structured model root, or its serialised textual form. */
|
|
54
|
+
model: TTransfer | string;
|
|
55
|
+
/**
|
|
56
|
+
* What this write was authored against. A `SnapshotVersion` is compared
|
|
57
|
+
* against the server's current text-document version for `uri` and throws
|
|
58
|
+
* `ConflictError` on mismatch; `'anything'` writes unconditionally.
|
|
59
|
+
*
|
|
60
|
+
* **Required so that an ungated write is a decision rather than an
|
|
61
|
+
* omission.** An optional gate is indistinguishable from a forgotten one at
|
|
62
|
+
* the call site, and a file of twenty writes hides the one that lost the
|
|
63
|
+
* field. Nothing else here can see that, since the defect is an absence.
|
|
64
|
+
*/
|
|
65
|
+
basedOn: BasedOn;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Update a document the session `clientId` has open, then persist it to disk. */
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
70
|
+
export interface TransferSaveDocumentArgs<TTransfer> extends TransferUpdateDocumentArgs<TTransfer> {}
|
|
71
|
+
|
|
72
|
+
/** Register a client session on the connection. */
|
|
73
|
+
export interface CreateSessionArgs {
|
|
74
|
+
/** The session's id, minted by the client; unique in the server process while the session is live. */
|
|
75
|
+
clientId: string;
|
|
76
|
+
/** What the participant is; kept as the server session's `label`. */
|
|
77
|
+
label?: string;
|
|
78
|
+
/**
|
|
79
|
+
* A token the client keeps for the session's lifetime. It is no secret: the
|
|
80
|
+
* wire carries no authentication. A later `createSession` for the same id
|
|
81
|
+
* carrying the same token, from any connection, ends the session it names
|
|
82
|
+
* and registers the id afresh, so a client whose connection dropped before
|
|
83
|
+
* the server noticed can register again. Without it the id stays refused
|
|
84
|
+
* until the server notices.
|
|
85
|
+
*/
|
|
86
|
+
resumeToken?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** End a client session registered on the connection. */
|
|
90
|
+
export interface CloseSessionArgs {
|
|
91
|
+
clientId: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Create a document that exists nowhere yet, open for the session creating it. */
|
|
95
|
+
export interface CreateModelDocumentArgs {
|
|
96
|
+
uri: string;
|
|
97
|
+
/** The id of a live session registered on this connection. */
|
|
98
|
+
clientId: string;
|
|
99
|
+
/** The document's initial content; it reaches disk with the first save. */
|
|
100
|
+
text: string;
|
|
101
|
+
}
|
|
50
102
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Write several documents a session has open, all or none. `clientId` is on
|
|
105
|
+
* the set rather than on each update: an id per update would allow a set
|
|
106
|
+
* mixing clients, which the server would have to refuse.
|
|
107
|
+
*/
|
|
108
|
+
export interface TransferUpdateDocumentsArgs<TTransfer> {
|
|
109
|
+
/** The id of a live session registered on this connection. */
|
|
110
|
+
clientId: string;
|
|
111
|
+
updates: Omit<TransferUpdateDocumentArgs<TTransfer>, 'clientId'>[];
|
|
112
|
+
}
|
|
53
113
|
|
|
54
114
|
/**
|
|
55
115
|
* Identifies a per-document watch on the data server. Shared by both
|
|
56
116
|
* `watchModelDocument` and `unwatchModelDocument` — the `(uri, clientId)`
|
|
57
117
|
* pair is the watch key, so unwatching names the same watch that was
|
|
58
118
|
* started. The `clientId` identifies the originator the same way it does
|
|
59
|
-
* on
|
|
60
|
-
* `
|
|
61
|
-
* bucket so multiple watchers on the same wire stay distinct, AND it lets
|
|
119
|
+
* on the document writes (`TransferUpdateDocumentArgs.clientId`,
|
|
120
|
+
* `TransferSaveDocumentArgs.clientId`): it keys the per-`(uri, clientId)`
|
|
121
|
+
* watch bucket so multiple watchers on the same wire stay distinct, AND it lets
|
|
62
122
|
* each watcher recognise its own echo on inbound `onDocumentUpdated` events
|
|
63
123
|
* (the wire shape's `sourceClientId` carries the originating mutation's
|
|
64
124
|
* `clientId`).
|
package/src/errors.ts
CHANGED
|
@@ -47,7 +47,7 @@ export interface ConflictErrorData extends HydraniumMessageData {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* Thrown by `
|
|
50
|
+
* Thrown by a client session's `update` / `save` when the caller-
|
|
51
51
|
* supplied based-on version no longer matches the server's current text-
|
|
52
52
|
* document version for the same URI — i.e. the snapshot the caller
|
|
53
53
|
* authored against has been superseded by an intervening edit.
|
|
@@ -60,9 +60,9 @@ export interface ConflictErrorData extends HydraniumMessageData {
|
|
|
60
60
|
* `err.data` (the instance is reconstructed as a generic
|
|
61
61
|
* `ResponseError`, so subclass getters / fields do not survive).
|
|
62
62
|
*
|
|
63
|
-
* Detection is driven by the required `basedOn` field
|
|
64
|
-
*
|
|
65
|
-
*
|
|
63
|
+
* Detection is driven by the required `basedOn` field of every write
|
|
64
|
+
* request; a caller with no meaningful based-on version passes
|
|
65
|
+
* `'anything'` and gets no gating.
|
|
66
66
|
*
|
|
67
67
|
* Three reasonable adopter recovery strategies:
|
|
68
68
|
*
|
|
@@ -114,6 +114,103 @@ export class ConflictError extends ResponseError<ConflictErrorData> {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* JSON-RPC code for {@link SessionClosedError}, beside {@link CONFLICT_ERROR_CODE}
|
|
119
|
+
* and for the same reason: the code survives reconstruction, the class does not.
|
|
120
|
+
*/
|
|
121
|
+
export const SESSION_CLOSED_ERROR_CODE = 1004;
|
|
122
|
+
/** JSON-RPC code for {@link DocumentNotOpenError}. */
|
|
123
|
+
export const DOCUMENT_NOT_OPEN_ERROR_CODE = 1005;
|
|
124
|
+
/** JSON-RPC code for {@link DuplicateClientIdError}. */
|
|
125
|
+
export const DUPLICATE_CLIENT_ID_ERROR_CODE = 1006;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Thrown by every call on a client session after it ended, and by an open that
|
|
129
|
+
* was still in flight when its session ended.
|
|
130
|
+
*
|
|
131
|
+
* The message names the client id, so it is addressed to whoever composes the
|
|
132
|
+
* system rather than to an end user, and carries no message identity. A client
|
|
133
|
+
* recognises it after an RPC with {@link isSessionClosedError}.
|
|
134
|
+
*/
|
|
135
|
+
export class SessionClosedError extends ResponseError<{ readonly clientId: string }> {
|
|
136
|
+
/** `message` replaces the default sentence, for a caller that knows more than that the session is gone. */
|
|
137
|
+
constructor(clientId: string, message = `Client session ${clientId} is closed`) {
|
|
138
|
+
super(SESSION_CLOSED_ERROR_CODE, message, { clientId });
|
|
139
|
+
this.name = 'SessionClosedError';
|
|
140
|
+
// `ResponseError` resets the prototype to its own; see `ConflictError`.
|
|
141
|
+
Object.setPrototypeOf(this, SessionClosedError.prototype);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
get clientId(): string {
|
|
145
|
+
return this.data!.clientId;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Thrown when a client session writes a document it does not have open.
|
|
151
|
+
*
|
|
152
|
+
* A session writes only what it has open, so this is the answer both to a write
|
|
153
|
+
* that never opened and to one whose open was closed underneath it — by the
|
|
154
|
+
* session itself, or by the document being deleted.
|
|
155
|
+
*/
|
|
156
|
+
export class DocumentNotOpenError extends ResponseError<{ readonly uri: string; readonly clientId: string }> {
|
|
157
|
+
constructor(uri: string, clientId: string) {
|
|
158
|
+
super(DOCUMENT_NOT_OPEN_ERROR_CODE, `Document ${uri} is not open in client session ${clientId}`, { uri, clientId });
|
|
159
|
+
this.name = 'DocumentNotOpenError';
|
|
160
|
+
Object.setPrototypeOf(this, DocumentNotOpenError.prototype);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
get uri(): string {
|
|
164
|
+
return this.data!.uri;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
get clientId(): string {
|
|
168
|
+
return this.data!.clientId;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Thrown when a client session is started under an id that is already live in
|
|
174
|
+
* the process, or that the framework reserves for itself.
|
|
175
|
+
*
|
|
176
|
+
* Ids are unique process-wide because the id is also the author label on every
|
|
177
|
+
* version and the key a client recognises its own echoes by; two participants
|
|
178
|
+
* sharing one would each take the other's writes for their own.
|
|
179
|
+
*/
|
|
180
|
+
export class DuplicateClientIdError extends ResponseError<{ readonly clientId: string }> {
|
|
181
|
+
constructor(clientId: string) {
|
|
182
|
+
super(DUPLICATE_CLIENT_ID_ERROR_CODE, `Client id ${clientId} is already in use`, { clientId });
|
|
183
|
+
this.name = 'DuplicateClientIdError';
|
|
184
|
+
Object.setPrototypeOf(this, DuplicateClientIdError.prototype);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
get clientId(): string {
|
|
188
|
+
return this.data!.clientId;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Whether `error` is a {@link SessionClosedError}: by name in-process, by code
|
|
194
|
+
* after an RPC, where it arrives as a plain `ResponseError`.
|
|
195
|
+
*/
|
|
196
|
+
export function isSessionClosedError(error: unknown): error is SessionClosedError {
|
|
197
|
+
return hasErrorIdentity(error, 'SessionClosedError', SESSION_CLOSED_ERROR_CODE);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Whether `error` is a {@link DocumentNotOpenError}; see {@link isSessionClosedError}. */
|
|
201
|
+
export function isDocumentNotOpenError(error: unknown): error is DocumentNotOpenError {
|
|
202
|
+
return hasErrorIdentity(error, 'DocumentNotOpenError', DOCUMENT_NOT_OPEN_ERROR_CODE);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Whether `error` is a {@link DuplicateClientIdError}; see {@link isSessionClosedError}. */
|
|
206
|
+
export function isDuplicateClientIdError(error: unknown): error is DuplicateClientIdError {
|
|
207
|
+
return hasErrorIdentity(error, 'DuplicateClientIdError', DUPLICATE_CLIENT_ID_ERROR_CODE);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function hasErrorIdentity(error: unknown, name: string, code: number): boolean {
|
|
211
|
+
return error instanceof Error && (error.name === name || (error as Partial<ResponseError<unknown>>).code === code);
|
|
212
|
+
}
|
|
213
|
+
|
|
117
214
|
/** Marker substring present in every {@link ConflictError} message, used by
|
|
118
215
|
* {@link isConflictError} as a fallback when a transport re-wraps the error
|
|
119
216
|
* and drops the JSON-RPC code. */
|
package/src/messages/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ export * from './primitives';
|
|
|
27
27
|
|
|
28
28
|
export { STALE_BASED_UPDATE } from '../errors';
|
|
29
29
|
export { DATA_SERVER_CONNECT_FAILED, DATA_SERVER_NOT_READY } from '../client/rpc-connection';
|
|
30
|
+
export { DATA_SESSION_RESTORE_FAILED, DATA_SESSION_UNSAVED_LOST } from '../client/data-session';
|
|
30
31
|
export {
|
|
31
32
|
RELAY_REPLAY_FAILED,
|
|
32
33
|
RELAY_TRANSPORT_OPEN_FAILED,
|
package/src/model-server.ts
CHANGED
|
@@ -14,17 +14,19 @@
|
|
|
14
14
|
* over `TRoot`.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import type { TransferClientArgs } from './model-service/args';
|
|
18
17
|
import type { ReferenceCandidate } from './model-service/reference-candidate';
|
|
19
18
|
|
|
20
19
|
// ---------------------------------------------------------------------------
|
|
21
20
|
// Client / server arguments
|
|
22
21
|
// ---------------------------------------------------------------------------
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/** Identifies a client-document binding. */
|
|
24
|
+
export interface TransferClientArgs {
|
|
25
|
+
/** Document URI. */
|
|
26
|
+
uri: string;
|
|
27
|
+
/** Stable identifier for the client invoking the operation. */
|
|
28
|
+
clientId: string;
|
|
29
|
+
}
|
|
28
30
|
|
|
29
31
|
/** Open a document on behalf of a client. */
|
|
30
32
|
export interface OpenModelArgs extends TransferClientArgs {
|
|
@@ -53,6 +55,12 @@ export interface OpenModelArgs extends TransferClientArgs {
|
|
|
53
55
|
* `didOpen` attach may separately refresh the build.
|
|
54
56
|
*/
|
|
55
57
|
text?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Kept on the server for this client's open until it closes, for the
|
|
60
|
+
* server's own open path to read. Only a client session's open keeps them,
|
|
61
|
+
* and a repeat open keeps the first open's.
|
|
62
|
+
*/
|
|
63
|
+
options?: object;
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
/** Close a previously-opened document for the client. */
|
|
@@ -58,3 +58,6 @@ export function isSnapshotVersion(basedOn: BasedOn): basedOn is SnapshotVersion
|
|
|
58
58
|
export function asSnapshotVersion(version: number): SnapshotVersion {
|
|
59
59
|
return version as SnapshotVersion;
|
|
60
60
|
}
|
|
61
|
+
|
|
62
|
+
/** A snapshot version no write can match, so a write based on it conflicts. */
|
|
63
|
+
export const NO_MATCHING_VERSION: SnapshotVersion = asSnapshotVersion(-1);
|
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// protocol can structurally agree on the lifecycle shape.
|
|
10
|
+
// Generic payload types the data protocol shares with core: the based-on
|
|
11
|
+
// version, which the server's model service checks writes against, and the
|
|
12
|
+
// reference candidates, which core's scope and completion code produce.
|
|
14
13
|
|
|
15
|
-
export * from './args';
|
|
16
14
|
export * from './based-on';
|
|
17
15
|
export * from './reference-candidate';
|