@palantir/pack.state.core 0.2.2 → 0.3.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/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-transpileBrowser.log +2 -1
- package/.turbo/turbo-transpileCjs.log +2 -1
- package/.turbo/turbo-transpileEsm.log +2 -1
- package/.turbo/turbo-transpileTypes.log +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +26 -0
- package/build/browser/index.js +11 -4
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +11 -4
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +43 -22
- package/build/esm/index.js +11 -4
- package/build/esm/index.js.map +1 -1
- package/build/types/__tests__/testUtils.d.ts.map +1 -1
- package/build/types/index.d.ts +3 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/service/BaseYjsDocumentService.d.ts +13 -9
- package/build/types/service/BaseYjsDocumentService.d.ts.map +1 -1
- package/build/types/service/InMemoryDocumentService.d.ts.map +1 -1
- package/build/types/types/CreateDocumentMetadata.d.ts +6 -0
- package/build/types/types/CreateDocumentMetadata.d.ts.map +1 -0
- package/build/types/types/DocumentService.d.ts +19 -5
- package/build/types/types/DocumentService.d.ts.map +1 -1
- package/build/types/types/StateModule.d.ts +12 -13
- package/build/types/types/StateModule.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/__tests__/testUtils.ts +2 -1
- package/src/index.ts +7 -1
- package/src/service/BaseYjsDocumentService.ts +19 -6
- package/src/service/InMemoryDocumentService.ts +10 -7
- package/src/types/CreateDocumentMetadata.ts +23 -0
- package/src/types/DocumentService.ts +18 -3
- package/src/types/StateModule.ts +13 -13
package/build/cjs/index.d.cts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { Unsubscribe, PackAppInternal, ModuleConfigTuple } from '@palantir/pack.core';
|
|
2
|
-
import {
|
|
1
|
+
import { Unsubscribe, PackAppInternal, ModuleConfigTuple, PackApp } from '@palantir/pack.core';
|
|
2
|
+
import { DocumentSecurity, DocumentSchema, DocumentRef, DocumentMetadata, 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
|
|
|
6
|
+
interface CreateDocumentMetadata {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly documentTypeName: string;
|
|
9
|
+
readonly security?: DocumentSecurity;
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
declare const DocumentLoadStatus: {
|
|
7
13
|
readonly UNLOADED: "unloaded";
|
|
8
14
|
readonly LOADING: "loading";
|
|
@@ -19,6 +25,11 @@ declare const DocumentLiveStatus: {
|
|
|
19
25
|
type DocumentLiveStatus = typeof DocumentLiveStatus[keyof typeof DocumentLiveStatus];
|
|
20
26
|
type DocumentSyncStatus = {
|
|
21
27
|
readonly error?: unknown;
|
|
28
|
+
/**
|
|
29
|
+
* When true, indicates this is a demo/test service not connected to real Foundry.
|
|
30
|
+
* UI can use this to display a badge or indicator that data is local-only.
|
|
31
|
+
*/
|
|
32
|
+
readonly isDemo?: boolean;
|
|
22
33
|
readonly live: DocumentLiveStatus;
|
|
23
34
|
readonly load: DocumentLoadStatus;
|
|
24
35
|
};
|
|
@@ -34,6 +45,15 @@ type DocumentStateChangeCallback<T extends DocumentSchema = DocumentSchema> = (d
|
|
|
34
45
|
type RecordCollectionChangeCallback<M extends Model = Model> = (items: readonly RecordRef<M>[]) => void;
|
|
35
46
|
type RecordChangeCallback<M extends Model = Model> = (snapshot: ModelData<M>, record: RecordRef<M>) => void;
|
|
36
47
|
type RecordDeleteCallback<M extends Model = Model> = (record: RecordRef<M>) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Result of a document search operation, including pagination information.
|
|
50
|
+
*/
|
|
51
|
+
interface SearchDocumentsResult {
|
|
52
|
+
readonly data: ReadonlyArray<DocumentMetadata & {
|
|
53
|
+
readonly id: DocumentId;
|
|
54
|
+
}>;
|
|
55
|
+
readonly nextPageToken?: string;
|
|
56
|
+
}
|
|
37
57
|
/**
|
|
38
58
|
* Base interface for specific document service implementations.
|
|
39
59
|
* The DocumentService is responsible for persisting document state,
|
|
@@ -44,13 +64,12 @@ type RecordDeleteCallback<M extends Model = Model> = (record: RecordRef<M>) => v
|
|
|
44
64
|
interface DocumentService {
|
|
45
65
|
readonly hasMetadataSubscriptions: boolean;
|
|
46
66
|
readonly hasStateSubscriptions: boolean;
|
|
47
|
-
readonly createDocument: <T extends DocumentSchema>(metadata:
|
|
67
|
+
readonly createDocument: <T extends DocumentSchema>(metadata: CreateDocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
|
|
48
68
|
readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
|
|
49
69
|
documentName?: string;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}>>;
|
|
70
|
+
pageSize?: number;
|
|
71
|
+
pageToken?: string;
|
|
72
|
+
}) => Promise<SearchDocumentsResult>;
|
|
54
73
|
readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
|
|
55
74
|
readonly getCreateRecordCollectionRef: <const M extends Model>(docRef: DocumentRef, model: M) => RecordCollectionRef<M>;
|
|
56
75
|
readonly getCreateRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
|
|
@@ -126,6 +145,9 @@ interface InternalYjsDoc {
|
|
|
126
145
|
readonly statusSubscribers: Set<DocumentStatusChangeCallback>;
|
|
127
146
|
readonly yjsCollectionHandlers: Map<string, () => void>;
|
|
128
147
|
}
|
|
148
|
+
interface BaseYjsDocumentServiceOptions {
|
|
149
|
+
readonly isDemo?: boolean;
|
|
150
|
+
}
|
|
129
151
|
/**
|
|
130
152
|
* Base class for document services that use Y.js for local state management.
|
|
131
153
|
* Provides common Y.js operations for both in-memory and backend services.
|
|
@@ -136,20 +158,20 @@ declare abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc = Inte
|
|
|
136
158
|
protected readonly app: PackAppInternal;
|
|
137
159
|
protected readonly logger: Logger;
|
|
138
160
|
protected readonly documents: Map<DocumentId, TDoc>;
|
|
139
|
-
|
|
161
|
+
protected readonly isDemo?: boolean;
|
|
162
|
+
constructor(app: PackAppInternal, logger: Logger, options?: BaseYjsDocumentServiceOptions);
|
|
140
163
|
abstract get hasMetadataSubscriptions(): boolean;
|
|
141
164
|
abstract get hasStateSubscriptions(): boolean;
|
|
142
|
-
abstract readonly createDocument: <T extends DocumentSchema>(metadata:
|
|
165
|
+
abstract readonly createDocument: <T extends DocumentSchema>(metadata: CreateDocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
|
|
143
166
|
abstract readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
|
|
144
167
|
documentName?: string;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}>>;
|
|
168
|
+
pageSize?: number;
|
|
169
|
+
pageToken?: string;
|
|
170
|
+
}) => Promise<SearchDocumentsResult>;
|
|
149
171
|
readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
|
|
150
172
|
readonly getCreateRecordCollectionRef: <const M extends Model>(docRef: DocumentRef, model: M) => RecordCollectionRef<M>;
|
|
151
173
|
readonly getCreateRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
|
|
152
|
-
protected abstract createInternalDoc(ref: DocumentRef, metadata?:
|
|
174
|
+
protected abstract createInternalDoc(ref: DocumentRef, metadata?: CreateDocumentMetadata, yDoc?: Y.Doc): TDoc;
|
|
153
175
|
/**
|
|
154
176
|
* Called when the first metadata subscription is opened for a document.
|
|
155
177
|
* Implementation must:
|
|
@@ -203,7 +225,7 @@ declare abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc = Inte
|
|
|
203
225
|
/**
|
|
204
226
|
* Get existing internal doc or create one with placeholder metadata for lazy initialization
|
|
205
227
|
*/
|
|
206
|
-
protected getCreateInternalDoc<T extends DocumentSchema>(ref: DocumentRef<T>, metadata?:
|
|
228
|
+
protected getCreateInternalDoc<T extends DocumentSchema>(ref: DocumentRef<T>, metadata?: CreateDocumentMetadata, initialYDoc?: Y.Doc): {
|
|
207
229
|
internalDocRef: DocumentRef<T>;
|
|
208
230
|
internalDoc: TDoc;
|
|
209
231
|
wasExisting: boolean;
|
|
@@ -344,13 +366,12 @@ type WithStateModule<T> = T & {
|
|
|
344
366
|
interface StateModule {
|
|
345
367
|
readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
|
|
346
368
|
readonly createRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
|
|
347
|
-
readonly createDocument: <T extends DocumentSchema>(metadata:
|
|
369
|
+
readonly createDocument: <T extends DocumentSchema>(metadata: CreateDocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
|
|
348
370
|
readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
|
|
349
371
|
documentName?: string;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}>>;
|
|
372
|
+
pageSize?: number;
|
|
373
|
+
pageToken?: string;
|
|
374
|
+
}) => Promise<SearchDocumentsResult>;
|
|
354
375
|
readonly getDocumentSnapshot: <T extends DocumentSchema>(docRef: DocumentRef<T>) => Promise<DocumentState<T>>;
|
|
355
376
|
readonly onActivity: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: ActivityEvent) => void) => Unsubscribe;
|
|
356
377
|
readonly onMetadataChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, cb: (docRef: DocumentRef<T>, metadata: DocumentMetadata) => void) => Unsubscribe;
|
|
@@ -372,6 +393,6 @@ interface StateModule {
|
|
|
372
393
|
readonly waitForMetadataLoad: <T extends DocumentSchema>(docRef: DocumentRef<T>) => Promise<void>;
|
|
373
394
|
readonly waitForDataLoad: <T extends DocumentSchema>(docRef: DocumentRef<T>) => Promise<void>;
|
|
374
395
|
}
|
|
375
|
-
declare function getStateModule(app: PackAppInternal): StateModule;
|
|
396
|
+
declare function getStateModule(app: PackApp | PackAppInternal): StateModule;
|
|
376
397
|
|
|
377
|
-
export { BaseYjsDocumentService, DocumentLiveStatus, DocumentLoadStatus, type DocumentMetadataChangeCallback, type DocumentService, type DocumentStateChangeCallback, type DocumentStatus, type DocumentStatusChangeCallback, type DocumentSyncStatus, type InternalYjsDoc, STATE_MODULE_ACCESSOR, type StateModule, type WithDocumentServiceInit, type WithStateModule, createDocRef, createDocumentServiceConfig, createInMemoryDocumentServiceConfig, createRecordCollectionRef, createRecordRef, getDocumentService, getStateModule, invalidDocRef, invalidRecordCollectionRef, invalidRecordRef, isValidDocRef, isValidRecordCollectionRef, isValidRecordRef };
|
|
398
|
+
export { BaseYjsDocumentService, type BaseYjsDocumentServiceOptions, type CreateDocumentMetadata, DocumentLiveStatus, DocumentLoadStatus, type DocumentMetadataChangeCallback, type DocumentService, type DocumentStateChangeCallback, type DocumentStatus, type DocumentStatusChangeCallback, type DocumentSyncStatus, type InternalYjsDoc, STATE_MODULE_ACCESSOR, type SearchDocumentsResult, type StateModule, type WithDocumentServiceInit, type WithStateModule, createDocRef, createDocumentServiceConfig, createInMemoryDocumentServiceConfig, createRecordCollectionRef, createRecordRef, getDocumentService, getStateModule, invalidDocRef, invalidRecordCollectionRef, invalidRecordRef, isValidDocRef, isValidRecordCollectionRef, isValidRecordRef };
|
package/build/esm/index.js
CHANGED
|
@@ -466,9 +466,11 @@ function yMapToState(yMap) {
|
|
|
466
466
|
// src/service/BaseYjsDocumentService.ts
|
|
467
467
|
var BaseYjsDocumentService = class {
|
|
468
468
|
documents = /* @__PURE__ */ new Map();
|
|
469
|
-
|
|
469
|
+
isDemo;
|
|
470
|
+
constructor(app, logger, options) {
|
|
470
471
|
this.app = app;
|
|
471
472
|
this.logger = logger;
|
|
473
|
+
this.isDemo = options?.isDemo;
|
|
472
474
|
}
|
|
473
475
|
createDocRef = (id, schema) => {
|
|
474
476
|
const temporaryRef = createDocRef(this.app, id, schema);
|
|
@@ -588,6 +590,7 @@ var BaseYjsDocumentService = class {
|
|
|
588
590
|
updateMetadataStatus(internalDoc, docRef, update) {
|
|
589
591
|
if (update.load != null || update.live != null) {
|
|
590
592
|
internalDoc.metadataStatus = {
|
|
593
|
+
isDemo: this.isDemo,
|
|
591
594
|
load: update.load ?? internalDoc.metadataStatus.load,
|
|
592
595
|
live: update.live ?? internalDoc.metadataStatus.live
|
|
593
596
|
};
|
|
@@ -602,6 +605,7 @@ var BaseYjsDocumentService = class {
|
|
|
602
605
|
updateDataStatus(internalDoc, docRef, update) {
|
|
603
606
|
if (update.load != null || update.live != null) {
|
|
604
607
|
internalDoc.dataStatus = {
|
|
608
|
+
isDemo: this.isDemo,
|
|
605
609
|
load: update.load ?? internalDoc.dataStatus.load,
|
|
606
610
|
live: update.live ?? internalDoc.dataStatus.live
|
|
607
611
|
};
|
|
@@ -1259,7 +1263,7 @@ var InMemoryDocumentService = class extends BaseYjsDocumentService {
|
|
|
1259
1263
|
const results = [];
|
|
1260
1264
|
const {
|
|
1261
1265
|
documentName,
|
|
1262
|
-
|
|
1266
|
+
pageSize
|
|
1263
1267
|
} = options ?? {};
|
|
1264
1268
|
for (const [docId, internalDoc] of this.documents.entries()) {
|
|
1265
1269
|
if (internalDoc.metadata?.documentTypeName === documentTypeName) {
|
|
@@ -1270,12 +1274,15 @@ var InMemoryDocumentService = class extends BaseYjsDocumentService {
|
|
|
1270
1274
|
...internalDoc.metadata,
|
|
1271
1275
|
id: docId
|
|
1272
1276
|
});
|
|
1273
|
-
if (
|
|
1277
|
+
if (pageSize && results.length >= pageSize) {
|
|
1274
1278
|
break;
|
|
1275
1279
|
}
|
|
1276
1280
|
}
|
|
1277
1281
|
}
|
|
1278
|
-
return Promise.resolve(
|
|
1282
|
+
return Promise.resolve({
|
|
1283
|
+
data: results,
|
|
1284
|
+
nextPageToken: void 0
|
|
1285
|
+
});
|
|
1279
1286
|
};
|
|
1280
1287
|
// Lifecycle method implementations
|
|
1281
1288
|
onMetadataSubscriptionOpened(internalDoc, docRef) {
|