document-drive 1.0.0-alpha.95 → 1.0.0-alpha.97
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/package.json
CHANGED
|
@@ -117,7 +117,7 @@ export class PullResponderTransmitter implements IPullResponderTransmitter {
|
|
|
117
117
|
filter: ListenerFilter
|
|
118
118
|
): Promise<Listener['listenerId']> {
|
|
119
119
|
// graphql request to switchboard
|
|
120
|
-
const
|
|
120
|
+
const result = await requestGraphql<{
|
|
121
121
|
registerPullResponderListener: {
|
|
122
122
|
listenerId: Listener['listenerId'];
|
|
123
123
|
};
|
|
@@ -134,7 +134,17 @@ export class PullResponderTransmitter implements IPullResponderTransmitter {
|
|
|
134
134
|
`,
|
|
135
135
|
{ filter }
|
|
136
136
|
);
|
|
137
|
-
|
|
137
|
+
|
|
138
|
+
const error = result.errors?.at(0);
|
|
139
|
+
if (error) {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!result.registerPullResponderListener) {
|
|
144
|
+
throw new Error('Error registering listener');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return result.registerPullResponderListener.listenerId;
|
|
138
148
|
}
|
|
139
149
|
|
|
140
150
|
static async pullStrands(
|
|
@@ -143,11 +153,7 @@ export class PullResponderTransmitter implements IPullResponderTransmitter {
|
|
|
143
153
|
listenerId: string,
|
|
144
154
|
options?: GetStrandsOptions // TODO add support for since
|
|
145
155
|
): Promise<StrandUpdate[]> {
|
|
146
|
-
const
|
|
147
|
-
system: {
|
|
148
|
-
sync: { strands }
|
|
149
|
-
}
|
|
150
|
-
} = await requestGraphql<PullStrandsGraphQL>(
|
|
156
|
+
const result = await requestGraphql<PullStrandsGraphQL>(
|
|
151
157
|
url,
|
|
152
158
|
gql`
|
|
153
159
|
query strands($listenerId: ID!) {
|
|
@@ -188,7 +194,17 @@ export class PullResponderTransmitter implements IPullResponderTransmitter {
|
|
|
188
194
|
`,
|
|
189
195
|
{ listenerId }
|
|
190
196
|
);
|
|
191
|
-
|
|
197
|
+
|
|
198
|
+
const error = result.errors?.at(0);
|
|
199
|
+
if (error) {
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!result.system) {
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return result.system.sync.strands.map(s => ({
|
|
192
208
|
...s,
|
|
193
209
|
operations: s.operations.map(o => ({
|
|
194
210
|
...o,
|
|
@@ -215,6 +231,14 @@ export class PullResponderTransmitter implements IPullResponderTransmitter {
|
|
|
215
231
|
`,
|
|
216
232
|
{ listenerId, revisions }
|
|
217
233
|
);
|
|
234
|
+
const error = result.errors?.at(0);
|
|
235
|
+
if (error) {
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (result.acknowledge === null) {
|
|
240
|
+
throw new Error('Error acknowledging strands');
|
|
241
|
+
}
|
|
218
242
|
return result.acknowledge;
|
|
219
243
|
}
|
|
220
244
|
|
package/src/storage/browser.ts
CHANGED
package/src/storage/memory.ts
CHANGED
|
@@ -44,7 +44,7 @@ export class MemoryStorage implements IDriveStorage {
|
|
|
44
44
|
|
|
45
45
|
async saveDocument(drive: string, id: string, document: Document) {
|
|
46
46
|
this.documents[drive] = this.documents[drive] ?? {};
|
|
47
|
-
this.documents[drive]
|
|
47
|
+
this.documents[drive][id] = document;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async clearStorage(): Promise<void> {
|
|
@@ -65,7 +65,7 @@ export class MemoryStorage implements IDriveStorage {
|
|
|
65
65
|
clipboard,
|
|
66
66
|
state
|
|
67
67
|
} = document;
|
|
68
|
-
this.documents[drive]
|
|
68
|
+
this.documents[drive][id] = {
|
|
69
69
|
operations,
|
|
70
70
|
initialState,
|
|
71
71
|
name,
|
|
@@ -105,7 +105,7 @@ export class MemoryStorage implements IDriveStorage {
|
|
|
105
105
|
if (!this.documents[drive]) {
|
|
106
106
|
throw new DriveNotFoundError(drive);
|
|
107
107
|
}
|
|
108
|
-
delete this.documents[drive]
|
|
108
|
+
delete this.documents[drive][id];
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
async getDrives() {
|
package/src/utils/graphql.ts
CHANGED
|
@@ -171,6 +171,27 @@ export type DriveState = DriveInfo &
|
|
|
171
171
|
nodes: Array<FolderNode | Omit<FileNode, 'synchronizationUnits'>>;
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
+
export type DocumentGraphQLResult<D extends Document> = Pick<
|
|
175
|
+
D,
|
|
176
|
+
'name' | 'created' | 'documentType' | 'lastModified'
|
|
177
|
+
> & {
|
|
178
|
+
id: string;
|
|
179
|
+
revision: number;
|
|
180
|
+
state: InferDocumentState<D>;
|
|
181
|
+
initialState: InferDocumentState<D>;
|
|
182
|
+
operations: (Pick<
|
|
183
|
+
Operation,
|
|
184
|
+
| 'id'
|
|
185
|
+
| 'hash'
|
|
186
|
+
| 'index'
|
|
187
|
+
| 'skip'
|
|
188
|
+
| 'timestamp'
|
|
189
|
+
| 'type'
|
|
190
|
+
| 'error'
|
|
191
|
+
| 'context'
|
|
192
|
+
> & { inputText: string })[];
|
|
193
|
+
};
|
|
194
|
+
|
|
174
195
|
export async function fetchDocument<D extends Document>(
|
|
175
196
|
url: string,
|
|
176
197
|
documentId: string,
|
|
@@ -192,25 +213,7 @@ export async function fetchDocument<D extends Document>(
|
|
|
192
213
|
const stateFields = generateDocumentStateQueryFields(documentModel);
|
|
193
214
|
const name = pascalCase(documentModel.name);
|
|
194
215
|
const result = await requestGraphql<{
|
|
195
|
-
document:
|
|
196
|
-
D,
|
|
197
|
-
'name' | 'created' | 'documentType' | 'lastModified'
|
|
198
|
-
> & {
|
|
199
|
-
id: string;
|
|
200
|
-
revision: number;
|
|
201
|
-
state: InferDocumentState<D>;
|
|
202
|
-
initialState: InferDocumentState<D>;
|
|
203
|
-
operations: (Pick<
|
|
204
|
-
Operation,
|
|
205
|
-
| 'id'
|
|
206
|
-
| 'hash'
|
|
207
|
-
| 'index'
|
|
208
|
-
| 'skip'
|
|
209
|
-
| 'timestamp'
|
|
210
|
-
| 'type'
|
|
211
|
-
| 'error'
|
|
212
|
-
> & { inputText: string })[];
|
|
213
|
-
};
|
|
216
|
+
document: DocumentGraphQLResult<D>;
|
|
214
217
|
}>(
|
|
215
218
|
url,
|
|
216
219
|
gql`
|