@palantir/pack.state.core 0.1.0-beta.2 → 0.1.1
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/.turbo/turbo-lint.log +2 -2
- package/.turbo/turbo-transpileBrowser.log +1 -1
- package/.turbo/turbo-transpileCjs.log +1 -1
- package/.turbo/turbo-transpileEsm.log +1 -1
- package/.turbo/turbo-transpileTypes.log +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +33 -0
- package/build/browser/index.js +73 -0
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +73 -0
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +106 -1
- package/build/esm/index.js +73 -0
- package/build/esm/index.js.map +1 -1
- package/build/types/__tests__/Transaction.test.d.ts +1 -0
- package/build/types/__tests__/Transaction.test.d.ts.map +1 -0
- package/build/types/__tests__/testUtils.d.ts.map +1 -1
- package/build/types/service/BaseYjsDocumentService.d.ts +11 -1
- package/build/types/service/BaseYjsDocumentService.d.ts.map +1 -1
- package/build/types/service/InMemoryDocumentService.d.ts.map +1 -1
- package/build/types/types/DocumentRefImpl.d.ts +20 -0
- package/build/types/types/DocumentRefImpl.d.ts.map +1 -1
- package/build/types/types/DocumentService.d.ts +18 -1
- package/build/types/types/DocumentService.d.ts.map +1 -1
- package/build/types/types/RecordCollectionRefImpl.d.ts +23 -0
- package/build/types/types/RecordCollectionRefImpl.d.ts.map +1 -1
- package/build/types/types/RecordRefImpl.d.ts +25 -0
- package/build/types/types/RecordRefImpl.d.ts.map +1 -1
- package/build/types/types/StateModule.d.ts +21 -1
- package/build/types/types/StateModule.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/Transaction.test.ts +321 -0
- package/src/__tests__/testUtils.ts +1 -2
- package/src/service/BaseYjsDocumentService.ts +41 -0
- package/src/service/InMemoryDocumentService.ts +58 -1
- package/src/types/DocumentRefImpl.ts +58 -0
- package/src/types/DocumentService.ts +43 -0
- package/src/types/RecordCollectionRefImpl.ts +23 -0
- package/src/types/RecordRefImpl.ts +25 -0
- package/src/types/StateModule.ts +78 -0
package/build/cjs/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Unsubscribe, PackAppInternal, ModuleConfigTuple } from '@palantir/pack.core';
|
|
2
|
-
import { DocumentSchema, DocumentMetadata, DocumentRef, DocumentId, Model, RecordCollectionRef, RecordId, RecordRef, DocumentState, ModelData } from '@palantir/pack.document-schema.model-types';
|
|
2
|
+
import { DocumentSchema, DocumentMetadata, DocumentRef, DocumentId, Model, RecordCollectionRef, RecordId, RecordRef, DocumentState, ModelData, EditDescription, ActivityEvent, PresenceEvent, PresenceSubscriptionOptions } from '@palantir/pack.document-schema.model-types';
|
|
3
3
|
import { Logger } from '@osdk/api';
|
|
4
4
|
import * as Y from 'yjs';
|
|
5
5
|
|
|
@@ -34,10 +34,23 @@ type DocumentStateChangeCallback<T extends DocumentSchema = DocumentSchema> = (d
|
|
|
34
34
|
type RecordCollectionChangeCallback<M extends Model = Model> = (items: readonly RecordRef<M>[]) => void;
|
|
35
35
|
type RecordChangeCallback<M extends Model = Model> = (snapshot: ModelData<M>, record: RecordRef<M>) => void;
|
|
36
36
|
type RecordDeleteCallback<M extends Model = Model> = (record: RecordRef<M>) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Base interface for specific document service implementations.
|
|
39
|
+
* The DocumentService is responsible for persisting document state,
|
|
40
|
+
* metadata, and providing methods to subscribe and interact with documents.
|
|
41
|
+
*
|
|
42
|
+
* The main implementation communicates with the Foundry platform (see @palantir/pack.state.foundry).
|
|
43
|
+
*/
|
|
37
44
|
interface DocumentService {
|
|
38
45
|
readonly hasMetadataSubscriptions: boolean;
|
|
39
46
|
readonly hasStateSubscriptions: boolean;
|
|
40
47
|
readonly createDocument: <T extends DocumentSchema>(metadata: DocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
|
|
48
|
+
readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
|
|
49
|
+
documentName?: string;
|
|
50
|
+
limit?: number;
|
|
51
|
+
}) => Promise<ReadonlyArray<DocumentMetadata & {
|
|
52
|
+
readonly id: DocumentId;
|
|
53
|
+
}>>;
|
|
41
54
|
readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
|
|
42
55
|
readonly getCreateRecordCollectionRef: <const M extends Model>(docRef: DocumentRef, model: M) => RecordCollectionRef<M>;
|
|
43
56
|
readonly getCreateRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
|
|
@@ -45,6 +58,7 @@ interface DocumentService {
|
|
|
45
58
|
readonly getRecordSnapshot: <R extends Model>(record: RecordRef<R>) => Promise<ModelData<R>>;
|
|
46
59
|
readonly setRecord: <R extends Model>(record: RecordRef<R>, state: ModelData<R>) => Promise<void>;
|
|
47
60
|
readonly updateRecord: <R extends Model>(record: RecordRef<R>, partialState: Partial<ModelData<R>>) => Promise<void>;
|
|
61
|
+
readonly withTransaction: (docRef: DocumentRef, fn: () => void, description?: EditDescription) => void;
|
|
48
62
|
readonly getRecord: <M extends Model>(collection: RecordCollectionRef<M>, id: RecordId) => RecordRef<M> | undefined;
|
|
49
63
|
readonly hasRecord: <M extends Model>(collection: RecordCollectionRef<M>, id: RecordId) => boolean;
|
|
50
64
|
readonly setCollectionRecord: <M extends Model>(collection: RecordCollectionRef<M>, id: RecordId, state: ModelData<M>) => Promise<void>;
|
|
@@ -54,8 +68,11 @@ interface DocumentService {
|
|
|
54
68
|
readonly onCollectionItemsAdded: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
|
|
55
69
|
readonly onCollectionItemsChanged: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
|
|
56
70
|
readonly onCollectionItemsDeleted: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
|
|
71
|
+
readonly onActivity: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: ActivityEvent) => void) => Unsubscribe;
|
|
57
72
|
readonly onMetadataChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: DocumentMetadataChangeCallback<T>) => Unsubscribe;
|
|
73
|
+
readonly onPresence: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: PresenceEvent) => void, options?: PresenceSubscriptionOptions) => Unsubscribe;
|
|
58
74
|
readonly onStateChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: DocumentStateChangeCallback<T>) => Unsubscribe;
|
|
75
|
+
readonly updateCustomPresence: <M extends Model>(docRef: DocumentRef, model: M, eventData: ModelData<M>) => void;
|
|
59
76
|
readonly onRecordChanged: <M extends Model>(record: RecordRef<M>, callback: RecordChangeCallback<M>) => Unsubscribe;
|
|
60
77
|
readonly onRecordDeleted: <M extends Model>(record: RecordRef<M>, callback: RecordDeleteCallback<M>) => Unsubscribe;
|
|
61
78
|
readonly getDocumentStatus: <T extends DocumentSchema>(docRef: DocumentRef<T>) => DocumentStatus;
|
|
@@ -123,6 +140,12 @@ declare abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc = Inte
|
|
|
123
140
|
abstract get hasMetadataSubscriptions(): boolean;
|
|
124
141
|
abstract get hasStateSubscriptions(): boolean;
|
|
125
142
|
abstract readonly createDocument: <T extends DocumentSchema>(metadata: DocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
|
|
143
|
+
abstract readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
|
|
144
|
+
documentName?: string;
|
|
145
|
+
limit?: number;
|
|
146
|
+
}) => Promise<ReadonlyArray<DocumentMetadata & {
|
|
147
|
+
readonly id: DocumentId;
|
|
148
|
+
}>>;
|
|
126
149
|
readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
|
|
127
150
|
readonly getCreateRecordCollectionRef: <const M extends Model>(docRef: DocumentRef, model: M) => RecordCollectionRef<M>;
|
|
128
151
|
readonly getCreateRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
|
|
@@ -190,7 +213,11 @@ declare abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc = Inte
|
|
|
190
213
|
protected getRecordSnapshotInternal<M extends Model>(internalDoc: TDoc, recordRef: RecordRef<M>): ModelData<M>;
|
|
191
214
|
readonly setRecord: <R extends Model>(recordRef: RecordRef<R>, state: ModelData<R>) => Promise<void>;
|
|
192
215
|
readonly updateRecord: <R extends Model>(recordRef: RecordRef<R>, partialState: Partial<ModelData<R>>) => Promise<void>;
|
|
216
|
+
readonly withTransaction: (docRef: DocumentRef, fn: () => void, description?: EditDescription) => void;
|
|
193
217
|
onMetadataChange<T extends DocumentSchema>(docRef: DocumentRef<T>, callback: DocumentMetadataChangeCallback<T>): Unsubscribe;
|
|
218
|
+
abstract onActivity<T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: ActivityEvent) => void): Unsubscribe;
|
|
219
|
+
abstract onPresence<T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: PresenceEvent) => void): Unsubscribe;
|
|
220
|
+
abstract updateCustomPresence<M extends Model>(docRef: DocumentRef, model: M, eventData: ModelData<M>): void;
|
|
194
221
|
readonly onStateChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: DocumentStateChangeCallback<T>) => Unsubscribe;
|
|
195
222
|
protected getDocumentRef(docId: DocumentId): DocumentRef | null;
|
|
196
223
|
protected notifyMetadataSubscribers(internalDoc: TDoc, docRef: DocumentRef, metadata: DocumentMetadata): void;
|
|
@@ -231,15 +258,83 @@ interface InMemoryDocumentServiceOptions {
|
|
|
231
258
|
declare function createInMemoryDocumentServiceConfig({ autoCreateDocuments }?: InMemoryDocumentServiceOptions): ModuleConfigTuple<DocumentService>;
|
|
232
259
|
|
|
233
260
|
declare const createDocRef: <const D extends DocumentSchema>(app: PackAppInternal, id: DocumentId, schema: D) => DocumentRef<D>;
|
|
261
|
+
/**
|
|
262
|
+
* Get an invalid document reference. This is a stable reference that can be
|
|
263
|
+
* used to represent a non-existent or invalid document.
|
|
264
|
+
*
|
|
265
|
+
* Not to be confused with a valid reference to a non-existent document, an
|
|
266
|
+
* invalid reference is one that is not properly initialized. For example, code
|
|
267
|
+
* that initializes with an undefined or empty documentId might produce an
|
|
268
|
+
* invalid document reference rather than propagate nullish types.
|
|
269
|
+
*
|
|
270
|
+
* Most operations on an invalid reference are no-ops. For the rest, it is
|
|
271
|
+
* recommended to check for validity using {@link isValidDocRef} before
|
|
272
|
+
* performing operations.
|
|
273
|
+
*/
|
|
234
274
|
declare function invalidDocRef<D extends DocumentSchema = DocumentSchema>(): DocumentRef<D>;
|
|
275
|
+
/**
|
|
276
|
+
* Check if a document reference is an invalid reference.
|
|
277
|
+
* Not to be confused with a valid reference to a non-existent document, an invalid reference is one that is not properly initialized.
|
|
278
|
+
* For example, code that initializes with an undefined or empty documentId might produce an invalid document reference rather than
|
|
279
|
+
* propagate nullish types, as most operations on an invalid reference are no-ops. For the rest, it is recommended to check for
|
|
280
|
+
* validity using this function before performing operations.
|
|
281
|
+
*/
|
|
235
282
|
declare function isValidDocRef<D extends DocumentSchema = DocumentSchema>(docRef: DocumentRef<D>): docRef is DocumentRef<D>;
|
|
236
283
|
|
|
237
284
|
declare const createRecordCollectionRef: <const M extends Model>(documentService: DocumentService, docRef: DocumentRef, model: M) => RecordCollectionRef<M>;
|
|
285
|
+
/**
|
|
286
|
+
* Get an invalid record collection reference. This is a stable reference that
|
|
287
|
+
* can be used to represent an invalid record collection.
|
|
288
|
+
*
|
|
289
|
+
* Not to be confused with a valid reference to a non-existent record
|
|
290
|
+
* collection, an invalid reference is one that is not properly initialized. For
|
|
291
|
+
* example, code that initializes with an undefined or empty model might produce
|
|
292
|
+
* an invalid record collection reference rather than propagate nullish types.
|
|
293
|
+
*
|
|
294
|
+
* Most operations on an invalid reference are no-ops. For the rest, it is
|
|
295
|
+
* recommended to check for validity using {@link isValidRecordCollectionRef}
|
|
296
|
+
* before performing operations.
|
|
297
|
+
*/
|
|
238
298
|
declare function invalidRecordCollectionRef<M extends Model = Model>(): RecordCollectionRef<M>;
|
|
299
|
+
/**
|
|
300
|
+
* Check if a record collection reference is a valid reference.
|
|
301
|
+
*
|
|
302
|
+
* Not to be confused with a valid reference to a non-existent record
|
|
303
|
+
* collection, an invalid reference is one that is not properly initialized.
|
|
304
|
+
*
|
|
305
|
+
* Most operations on an invalid reference are no-ops. For the rest, it is
|
|
306
|
+
* recommended to check for validity using this function before performing
|
|
307
|
+
* operations.
|
|
308
|
+
*/
|
|
239
309
|
declare function isValidRecordCollectionRef<M extends Model = Model>(collectionRef: RecordCollectionRef<M>): collectionRef is RecordCollectionRef<M>;
|
|
240
310
|
|
|
241
311
|
declare const createRecordRef: <const M extends Model>(documentService: DocumentService, docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
|
|
312
|
+
/**
|
|
313
|
+
* Get an invalid record reference. This is a stable reference that can be used
|
|
314
|
+
* to represent an invalid record.
|
|
315
|
+
*
|
|
316
|
+
* Not to be confused with a valid reference to a non-existent record, an
|
|
317
|
+
* invalid reference is one that is not properly initialized. For example, code
|
|
318
|
+
* that initializes with an undefined or empty recordId might produce an
|
|
319
|
+
* invalid record reference rather than propagate nullish types.
|
|
320
|
+
*
|
|
321
|
+
* Most operations on an invalid reference are no-ops. For the rest, it is
|
|
322
|
+
* recommended to check for validity using {@link isValidRecordRef} before
|
|
323
|
+
* performing operations.
|
|
324
|
+
*/
|
|
242
325
|
declare function invalidRecordRef<M extends Model = Model>(): RecordRef<M>;
|
|
326
|
+
/**
|
|
327
|
+
* Check if a record reference is a valid reference.
|
|
328
|
+
*
|
|
329
|
+
* Not to be confused with a valid reference to a non-existent record, an
|
|
330
|
+
* invalid reference is one that is not properly initialized.
|
|
331
|
+
*
|
|
332
|
+
* For example, code that initializes with an undefined or empty recordId might
|
|
333
|
+
* produce an invalid record reference rather than propagate nullish types, as
|
|
334
|
+
* most operations on an invalid reference are no-ops. For the rest, it is
|
|
335
|
+
* recommended to check for validity using this function before performing
|
|
336
|
+
* operations.
|
|
337
|
+
*/
|
|
243
338
|
declare function isValidRecordRef<M extends Model = Model>(recordRef: RecordRef<M>): recordRef is RecordRef<M>;
|
|
244
339
|
|
|
245
340
|
declare const STATE_MODULE_ACCESSOR = "state";
|
|
@@ -250,15 +345,25 @@ interface StateModule {
|
|
|
250
345
|
readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
|
|
251
346
|
readonly createRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
|
|
252
347
|
readonly createDocument: <T extends DocumentSchema>(metadata: DocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
|
|
348
|
+
readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
|
|
349
|
+
documentName?: string;
|
|
350
|
+
limit?: number;
|
|
351
|
+
}) => Promise<ReadonlyArray<DocumentMetadata & {
|
|
352
|
+
readonly id: DocumentId;
|
|
353
|
+
}>>;
|
|
253
354
|
readonly getDocumentSnapshot: <T extends DocumentSchema>(docRef: DocumentRef<T>) => Promise<DocumentState<T>>;
|
|
355
|
+
readonly onActivity: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: ActivityEvent) => void) => Unsubscribe;
|
|
254
356
|
readonly onMetadataChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, cb: (docRef: DocumentRef<T>, metadata: DocumentMetadata) => void) => Unsubscribe;
|
|
357
|
+
readonly onPresence: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: PresenceEvent) => void, options?: PresenceSubscriptionOptions) => Unsubscribe;
|
|
255
358
|
readonly onStateChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, cb: (docRef: DocumentRef<T>) => void) => Unsubscribe;
|
|
359
|
+
readonly updateCustomPresence: <M extends Model>(docRef: DocumentRef, model: M, eventData: ModelData<M>) => void;
|
|
256
360
|
readonly getRecordSnapshot: <R extends Model>(recordRef: RecordRef<R>) => Promise<ModelData<R>>;
|
|
257
361
|
readonly onCollectionItemsAdded: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
|
|
258
362
|
readonly onCollectionItemsChanged: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
|
|
259
363
|
readonly onCollectionItemsDeleted: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
|
|
260
364
|
readonly setRecord: <R extends Model>(recordRef: RecordRef<R>, state: ModelData<R>) => Promise<void>;
|
|
261
365
|
readonly updateRecord: <R extends Model>(recordRef: RecordRef<R>, partialState: Partial<ModelData<R>>) => Promise<void>;
|
|
366
|
+
readonly withTransaction: (docRef: DocumentRef, fn: () => void, description?: EditDescription) => void;
|
|
262
367
|
readonly onRecordChanged: <M extends Model>(record: RecordRef<M>, callback: RecordChangeCallback<M>) => Unsubscribe;
|
|
263
368
|
readonly onRecordDeleted: <M extends Model>(record: RecordRef<M>, callback: RecordDeleteCallback<M>) => Unsubscribe;
|
|
264
369
|
readonly deleteRecord: <M extends Model>(record: RecordRef<M>) => Promise<void>;
|
package/build/esm/index.js
CHANGED
|
@@ -46,15 +46,27 @@ var StateModuleImpl = class {
|
|
|
46
46
|
async createDocument(metadata, schema) {
|
|
47
47
|
return this.documentService.createDocument(metadata, schema);
|
|
48
48
|
}
|
|
49
|
+
async searchDocuments(documentTypeName, schema, options) {
|
|
50
|
+
return this.documentService.searchDocuments(documentTypeName, schema, options);
|
|
51
|
+
}
|
|
49
52
|
async getDocumentSnapshot(docRef) {
|
|
50
53
|
return this.documentService.getDocumentSnapshot(docRef);
|
|
51
54
|
}
|
|
55
|
+
onActivity(docRef, callback) {
|
|
56
|
+
return this.documentService.onActivity(docRef, callback);
|
|
57
|
+
}
|
|
52
58
|
onMetadataChange(docRef, cb) {
|
|
53
59
|
return this.documentService.onMetadataChange(docRef, cb);
|
|
54
60
|
}
|
|
61
|
+
onPresence(docRef, callback, options) {
|
|
62
|
+
return this.documentService.onPresence(docRef, callback, options);
|
|
63
|
+
}
|
|
55
64
|
onStateChange(docRef, cb) {
|
|
56
65
|
return this.documentService.onStateChange(docRef, cb);
|
|
57
66
|
}
|
|
67
|
+
updateCustomPresence(docRef, model, eventData) {
|
|
68
|
+
this.documentService.updateCustomPresence(docRef, model, eventData);
|
|
69
|
+
}
|
|
58
70
|
async getRecordSnapshot(recordRef) {
|
|
59
71
|
return this.documentService.getRecordSnapshot(recordRef);
|
|
60
72
|
}
|
|
@@ -64,6 +76,9 @@ var StateModuleImpl = class {
|
|
|
64
76
|
async updateRecord(recordRef, partialState) {
|
|
65
77
|
return this.documentService.updateRecord(recordRef, partialState);
|
|
66
78
|
}
|
|
79
|
+
withTransaction(docRef, fn, description) {
|
|
80
|
+
this.documentService.withTransaction(docRef, fn, description);
|
|
81
|
+
}
|
|
67
82
|
// Collection methods
|
|
68
83
|
getCreateRecordCollectionRef(docRef, model) {
|
|
69
84
|
return this.documentService.getCreateRecordCollectionRef(docRef, model);
|
|
@@ -131,9 +146,18 @@ var INVALID_DOC_REF = Object.freeze({
|
|
|
131
146
|
getRecords: () => {
|
|
132
147
|
throw new Error("Invalid document reference");
|
|
133
148
|
},
|
|
149
|
+
onActivity: () => () => {
|
|
150
|
+
},
|
|
134
151
|
onMetadataChange: () => () => {
|
|
135
152
|
},
|
|
153
|
+
onPresence: () => () => {
|
|
154
|
+
},
|
|
136
155
|
onStateChange: () => () => {
|
|
156
|
+
},
|
|
157
|
+
updateCustomPresence: () => {
|
|
158
|
+
},
|
|
159
|
+
withTransaction: () => {
|
|
160
|
+
throw new Error("Invalid document reference");
|
|
137
161
|
}
|
|
138
162
|
});
|
|
139
163
|
var createDocRef = (app, id, schema) => {
|
|
@@ -160,12 +184,24 @@ var DocumentRefImpl = class {
|
|
|
160
184
|
getRecords(model) {
|
|
161
185
|
return this.#stateModule.getCreateRecordCollectionRef(this, model);
|
|
162
186
|
}
|
|
187
|
+
onActivity(callback) {
|
|
188
|
+
return this.#stateModule.onActivity(this, callback);
|
|
189
|
+
}
|
|
163
190
|
onMetadataChange(cb) {
|
|
164
191
|
return this.#stateModule.onMetadataChange(this, cb);
|
|
165
192
|
}
|
|
193
|
+
onPresence(callback, options) {
|
|
194
|
+
return this.#stateModule.onPresence(this, callback, options);
|
|
195
|
+
}
|
|
166
196
|
onStateChange(callback) {
|
|
167
197
|
return this.#stateModule.onStateChange(this, callback);
|
|
168
198
|
}
|
|
199
|
+
updateCustomPresence(model, eventData) {
|
|
200
|
+
this.#stateModule.updateCustomPresence(this, model, eventData);
|
|
201
|
+
}
|
|
202
|
+
withTransaction(fn, description) {
|
|
203
|
+
this.#stateModule.withTransaction(this, fn, description);
|
|
204
|
+
}
|
|
169
205
|
};
|
|
170
206
|
|
|
171
207
|
// src/types/DocumentService.ts
|
|
@@ -652,6 +688,11 @@ var BaseYjsDocumentService = class {
|
|
|
652
688
|
this.onRecordSet?.(recordRef, partialState);
|
|
653
689
|
return Promise.resolve();
|
|
654
690
|
};
|
|
691
|
+
withTransaction = (docRef, fn, description) => {
|
|
692
|
+
const internalDoc = this.documents.get(docRef.id);
|
|
693
|
+
!(internalDoc != null) ? process.env.NODE_ENV !== "production" ? invariant(false, `Cannot start transaction as document not found: ${docRef.id}`) : invariant(false) : void 0;
|
|
694
|
+
internalDoc.yDoc.transact(fn, description);
|
|
695
|
+
};
|
|
655
696
|
onMetadataChange(docRef, callback) {
|
|
656
697
|
const {
|
|
657
698
|
internalDoc,
|
|
@@ -1212,6 +1253,28 @@ var InMemoryDocumentService = class extends BaseYjsDocumentService {
|
|
|
1212
1253
|
this.getCreateInternalDoc(docRef, metadata, yDoc);
|
|
1213
1254
|
return Promise.resolve(docRef);
|
|
1214
1255
|
};
|
|
1256
|
+
searchDocuments = (documentTypeName, schema, options) => {
|
|
1257
|
+
const results = [];
|
|
1258
|
+
const {
|
|
1259
|
+
documentName,
|
|
1260
|
+
limit
|
|
1261
|
+
} = options ?? {};
|
|
1262
|
+
for (const [docId, internalDoc] of this.documents.entries()) {
|
|
1263
|
+
if (internalDoc.metadata?.documentTypeName === documentTypeName) {
|
|
1264
|
+
if (documentName && !internalDoc.metadata.name.includes(documentName)) {
|
|
1265
|
+
continue;
|
|
1266
|
+
}
|
|
1267
|
+
results.push({
|
|
1268
|
+
...internalDoc.metadata,
|
|
1269
|
+
id: docId
|
|
1270
|
+
});
|
|
1271
|
+
if (limit && results.length >= limit) {
|
|
1272
|
+
break;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
return Promise.resolve(results);
|
|
1277
|
+
};
|
|
1215
1278
|
// Lifecycle method implementations
|
|
1216
1279
|
onMetadataSubscriptionOpened(internalDoc, docRef) {
|
|
1217
1280
|
this.updateMetadataStatus(internalDoc, docRef, {
|
|
@@ -1247,6 +1310,16 @@ var InMemoryDocumentService = class extends BaseYjsDocumentService {
|
|
|
1247
1310
|
}
|
|
1248
1311
|
onDataSubscriptionClosed(_internalDoc, _docRef) {
|
|
1249
1312
|
}
|
|
1313
|
+
onActivity(_docRef, _callback) {
|
|
1314
|
+
return () => {
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
onPresence(_docRef, _callback, _options) {
|
|
1318
|
+
return () => {
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
updateCustomPresence(_docRef, _model, _eventData) {
|
|
1322
|
+
}
|
|
1250
1323
|
};
|
|
1251
1324
|
function generateDocumentId() {
|
|
1252
1325
|
return generateId();
|