@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.cjs
CHANGED
|
@@ -71,15 +71,27 @@ var StateModuleImpl = class {
|
|
|
71
71
|
async createDocument(metadata, schema) {
|
|
72
72
|
return this.documentService.createDocument(metadata, schema);
|
|
73
73
|
}
|
|
74
|
+
async searchDocuments(documentTypeName, schema, options) {
|
|
75
|
+
return this.documentService.searchDocuments(documentTypeName, schema, options);
|
|
76
|
+
}
|
|
74
77
|
async getDocumentSnapshot(docRef) {
|
|
75
78
|
return this.documentService.getDocumentSnapshot(docRef);
|
|
76
79
|
}
|
|
80
|
+
onActivity(docRef, callback) {
|
|
81
|
+
return this.documentService.onActivity(docRef, callback);
|
|
82
|
+
}
|
|
77
83
|
onMetadataChange(docRef, cb) {
|
|
78
84
|
return this.documentService.onMetadataChange(docRef, cb);
|
|
79
85
|
}
|
|
86
|
+
onPresence(docRef, callback, options) {
|
|
87
|
+
return this.documentService.onPresence(docRef, callback, options);
|
|
88
|
+
}
|
|
80
89
|
onStateChange(docRef, cb) {
|
|
81
90
|
return this.documentService.onStateChange(docRef, cb);
|
|
82
91
|
}
|
|
92
|
+
updateCustomPresence(docRef, model, eventData) {
|
|
93
|
+
this.documentService.updateCustomPresence(docRef, model, eventData);
|
|
94
|
+
}
|
|
83
95
|
async getRecordSnapshot(recordRef) {
|
|
84
96
|
return this.documentService.getRecordSnapshot(recordRef);
|
|
85
97
|
}
|
|
@@ -89,6 +101,9 @@ var StateModuleImpl = class {
|
|
|
89
101
|
async updateRecord(recordRef, partialState) {
|
|
90
102
|
return this.documentService.updateRecord(recordRef, partialState);
|
|
91
103
|
}
|
|
104
|
+
withTransaction(docRef, fn, description) {
|
|
105
|
+
this.documentService.withTransaction(docRef, fn, description);
|
|
106
|
+
}
|
|
92
107
|
// Collection methods
|
|
93
108
|
getCreateRecordCollectionRef(docRef, model) {
|
|
94
109
|
return this.documentService.getCreateRecordCollectionRef(docRef, model);
|
|
@@ -156,9 +171,18 @@ var INVALID_DOC_REF = Object.freeze({
|
|
|
156
171
|
getRecords: () => {
|
|
157
172
|
throw new Error("Invalid document reference");
|
|
158
173
|
},
|
|
174
|
+
onActivity: () => () => {
|
|
175
|
+
},
|
|
159
176
|
onMetadataChange: () => () => {
|
|
160
177
|
},
|
|
178
|
+
onPresence: () => () => {
|
|
179
|
+
},
|
|
161
180
|
onStateChange: () => () => {
|
|
181
|
+
},
|
|
182
|
+
updateCustomPresence: () => {
|
|
183
|
+
},
|
|
184
|
+
withTransaction: () => {
|
|
185
|
+
throw new Error("Invalid document reference");
|
|
162
186
|
}
|
|
163
187
|
});
|
|
164
188
|
var createDocRef = (app, id, schema) => {
|
|
@@ -185,12 +209,24 @@ var DocumentRefImpl = class {
|
|
|
185
209
|
getRecords(model) {
|
|
186
210
|
return this.#stateModule.getCreateRecordCollectionRef(this, model);
|
|
187
211
|
}
|
|
212
|
+
onActivity(callback) {
|
|
213
|
+
return this.#stateModule.onActivity(this, callback);
|
|
214
|
+
}
|
|
188
215
|
onMetadataChange(cb) {
|
|
189
216
|
return this.#stateModule.onMetadataChange(this, cb);
|
|
190
217
|
}
|
|
218
|
+
onPresence(callback, options) {
|
|
219
|
+
return this.#stateModule.onPresence(this, callback, options);
|
|
220
|
+
}
|
|
191
221
|
onStateChange(callback) {
|
|
192
222
|
return this.#stateModule.onStateChange(this, callback);
|
|
193
223
|
}
|
|
224
|
+
updateCustomPresence(model, eventData) {
|
|
225
|
+
this.#stateModule.updateCustomPresence(this, model, eventData);
|
|
226
|
+
}
|
|
227
|
+
withTransaction(fn, description) {
|
|
228
|
+
this.#stateModule.withTransaction(this, fn, description);
|
|
229
|
+
}
|
|
194
230
|
};
|
|
195
231
|
|
|
196
232
|
// src/types/DocumentService.ts
|
|
@@ -677,6 +713,11 @@ var BaseYjsDocumentService = class {
|
|
|
677
713
|
this.onRecordSet?.(recordRef, partialState);
|
|
678
714
|
return Promise.resolve();
|
|
679
715
|
};
|
|
716
|
+
withTransaction = (docRef, fn, description) => {
|
|
717
|
+
const internalDoc = this.documents.get(docRef.id);
|
|
718
|
+
!(internalDoc != null) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Cannot start transaction as document not found: ${docRef.id}`) : invariant__default.default(false) : void 0;
|
|
719
|
+
internalDoc.yDoc.transact(fn, description);
|
|
720
|
+
};
|
|
680
721
|
onMetadataChange(docRef, callback) {
|
|
681
722
|
const {
|
|
682
723
|
internalDoc,
|
|
@@ -1237,6 +1278,28 @@ var InMemoryDocumentService = class extends BaseYjsDocumentService {
|
|
|
1237
1278
|
this.getCreateInternalDoc(docRef, metadata, yDoc);
|
|
1238
1279
|
return Promise.resolve(docRef);
|
|
1239
1280
|
};
|
|
1281
|
+
searchDocuments = (documentTypeName, schema, options) => {
|
|
1282
|
+
const results = [];
|
|
1283
|
+
const {
|
|
1284
|
+
documentName,
|
|
1285
|
+
limit
|
|
1286
|
+
} = options ?? {};
|
|
1287
|
+
for (const [docId, internalDoc] of this.documents.entries()) {
|
|
1288
|
+
if (internalDoc.metadata?.documentTypeName === documentTypeName) {
|
|
1289
|
+
if (documentName && !internalDoc.metadata.name.includes(documentName)) {
|
|
1290
|
+
continue;
|
|
1291
|
+
}
|
|
1292
|
+
results.push({
|
|
1293
|
+
...internalDoc.metadata,
|
|
1294
|
+
id: docId
|
|
1295
|
+
});
|
|
1296
|
+
if (limit && results.length >= limit) {
|
|
1297
|
+
break;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
return Promise.resolve(results);
|
|
1302
|
+
};
|
|
1240
1303
|
// Lifecycle method implementations
|
|
1241
1304
|
onMetadataSubscriptionOpened(internalDoc, docRef) {
|
|
1242
1305
|
this.updateMetadataStatus(internalDoc, docRef, {
|
|
@@ -1272,6 +1335,16 @@ var InMemoryDocumentService = class extends BaseYjsDocumentService {
|
|
|
1272
1335
|
}
|
|
1273
1336
|
onDataSubscriptionClosed(_internalDoc, _docRef) {
|
|
1274
1337
|
}
|
|
1338
|
+
onActivity(_docRef, _callback) {
|
|
1339
|
+
return () => {
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
onPresence(_docRef, _callback, _options) {
|
|
1343
|
+
return () => {
|
|
1344
|
+
};
|
|
1345
|
+
}
|
|
1346
|
+
updateCustomPresence(_docRef, _model, _eventData) {
|
|
1347
|
+
}
|
|
1275
1348
|
};
|
|
1276
1349
|
function generateDocumentId() {
|
|
1277
1350
|
return pack_core.generateId();
|