@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
|
@@ -2,7 +2,8 @@ import type { Logger } from "@osdk/api";
|
|
|
2
2
|
import type { PackAppInternal, Unsubscribe } from "@palantir/pack.core";
|
|
3
3
|
import { type ActivityEvent, type DocumentId, type DocumentMetadata, type DocumentRef, type DocumentSchema, type DocumentState, type EditDescription, type Model, type ModelData, type PresenceEvent, type RecordCollectionRef, type RecordId, type RecordRef } from "@palantir/pack.document-schema.model-types";
|
|
4
4
|
import * as Y from "yjs";
|
|
5
|
-
import type {
|
|
5
|
+
import type { CreateDocumentMetadata } from "../types/CreateDocumentMetadata.js";
|
|
6
|
+
import type { DocumentMetadataChangeCallback, DocumentService, DocumentStateChangeCallback, DocumentStatus, DocumentStatusChangeCallback, DocumentSyncStatus, RecordChangeCallback, RecordCollectionChangeCallback, RecordDeleteCallback, SearchDocumentsResult } from "../types/DocumentService.js";
|
|
6
7
|
import { DocumentLiveStatus, DocumentLoadStatus } from "../types/DocumentService.js";
|
|
7
8
|
export interface RecordCollectionSubscriptions<M extends Model = Model> {
|
|
8
9
|
added?: Set<RecordCollectionChangeCallback<M>>;
|
|
@@ -42,6 +43,9 @@ export interface InternalYjsDoc {
|
|
|
42
43
|
readonly statusSubscribers: Set<DocumentStatusChangeCallback>;
|
|
43
44
|
readonly yjsCollectionHandlers: Map<string, () => void>;
|
|
44
45
|
}
|
|
46
|
+
export interface BaseYjsDocumentServiceOptions {
|
|
47
|
+
readonly isDemo?: boolean;
|
|
48
|
+
}
|
|
45
49
|
/**
|
|
46
50
|
* Base class for document services that use Y.js for local state management.
|
|
47
51
|
* Provides common Y.js operations for both in-memory and backend services.
|
|
@@ -52,20 +56,20 @@ export declare abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc
|
|
|
52
56
|
protected readonly app: PackAppInternal;
|
|
53
57
|
protected readonly logger: Logger;
|
|
54
58
|
protected readonly documents: Map<DocumentId, TDoc>;
|
|
55
|
-
|
|
59
|
+
protected readonly isDemo?: boolean;
|
|
60
|
+
constructor(app: PackAppInternal, logger: Logger, options?: BaseYjsDocumentServiceOptions);
|
|
56
61
|
abstract get hasMetadataSubscriptions(): boolean;
|
|
57
62
|
abstract get hasStateSubscriptions(): boolean;
|
|
58
|
-
abstract readonly createDocument: <T extends DocumentSchema>(metadata:
|
|
63
|
+
abstract readonly createDocument: <T extends DocumentSchema>(metadata: CreateDocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
|
|
59
64
|
abstract readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
|
|
60
65
|
documentName?: string;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}>>;
|
|
66
|
+
pageSize?: number;
|
|
67
|
+
pageToken?: string;
|
|
68
|
+
}) => Promise<SearchDocumentsResult>;
|
|
65
69
|
readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
|
|
66
70
|
readonly getCreateRecordCollectionRef: <const M extends Model>(docRef: DocumentRef, model: M) => RecordCollectionRef<M>;
|
|
67
71
|
readonly getCreateRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
|
|
68
|
-
protected abstract createInternalDoc(ref: DocumentRef, metadata?:
|
|
72
|
+
protected abstract createInternalDoc(ref: DocumentRef, metadata?: CreateDocumentMetadata, yDoc?: Y.Doc): TDoc;
|
|
69
73
|
/**
|
|
70
74
|
* Called when the first metadata subscription is opened for a document.
|
|
71
75
|
* Implementation must:
|
|
@@ -119,7 +123,7 @@ export declare abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc
|
|
|
119
123
|
/**
|
|
120
124
|
* Get existing internal doc or create one with placeholder metadata for lazy initialization
|
|
121
125
|
*/
|
|
122
|
-
protected getCreateInternalDoc<T extends DocumentSchema>(ref: DocumentRef<T>, metadata?:
|
|
126
|
+
protected getCreateInternalDoc<T extends DocumentSchema>(ref: DocumentRef<T>, metadata?: CreateDocumentMetadata, initialYDoc?: Y.Doc): {
|
|
123
127
|
internalDocRef: DocumentRef<T>;
|
|
124
128
|
internalDoc: TDoc;
|
|
125
129
|
wasExisting: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAkBA,cAAc,cAAc;AAC5B,cAAc,iBAAiB,mBAAmB;A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S,eAAgB,UAAU,OACjC,QAAQ,UAAU,OACjB;CAkBH,SAAS,oBAAqB,UAAU,OACtC,YAAY,oBAAoB;CASlC,SAAS,uBAAwB,UAAU,OACzC,YAAY,oBAAoB,OAC/B,UAAU;CAUb,SAAS,yBAA0B,UAAU,OAC3C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACxC;CAWH,SAAS,2BAA4B,UAAU,OAC7C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACxC;CAWH,SAAS,2BAA4B,UAAU,OAC7C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACxC;CAYH,SAAS,kBAAmB,UAAU,OACpC,QAAQ,UAAU,IAClB,UAAU,qBAAqB,OAC9B;CAsDH,SAAS,kBAAmB,UAAU,OACpC,QAAQ,UAAU,IAClB,UAAU,qBAAqB,OAC9B;CA4CH,QAAQ;CAaR,QAAQ;CAwBR,QAAQ;CA+CR,QAAQ;CAsHR,QAAQ;CAaR,QAAQ;CAyBR,SAAS,oBAAqB,UAAU,gBACtC,QAAQ,YAAY,OACnB;CAUH,SAAS,iBAAkB,UAAU,gBACnC,QAAQ,YAAY,IACpB,UAAU,iCACT;CAqBH,SAAS,sBAA6B,UAAU,gBAC9C,QAAQ,YAAY,OACnB;CAyBH,SAAS,kBAAyB,UAAU,gBAC1C,QAAQ,YAAY,OACnB","names":["app: PackAppInternal","logger: Logger"],"sources":["../../../src/service/BaseYjsDocumentService.ts"],"version":3,"file":"BaseYjsDocumentService.d.ts"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,mBAAmB,uBAAoC;
|
|
1
|
+
{"mappings":"AAgBA,cAAc,mBAAmB,uBAAoC;AAgBrE,cAAc,uBAA8C;AAG5D,SAAS,8BAA8B;AAEvC,iBAAiB,+BAA+B;;;;;UAKrC;;AAGX,OAAO,iBAAS,oCACd,EAAE,wBAA8B,iCAC/B,kBAAkB;AAQrB,OAAO,iBAAS,sCACd,KAAK,iBACL,SAAS,iCACR","names":[],"sources":["../../../src/service/InMemoryDocumentService.ts"],"version":3,"file":"InMemoryDocumentService.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,wBAAwB;AAEtC,iBAAiB,uBAAuB;UAC7B;UACA;UACA,WAAW","names":[],"sources":["../../../src/types/CreateDocumentMetadata.ts"],"version":3,"file":"CreateDocumentMetadata.d.ts"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Unsubscribe } from "@palantir/pack.core";
|
|
2
2
|
import type { ActivityEvent, DocumentId, DocumentMetadata, DocumentRef, DocumentSchema, DocumentState, EditDescription, Model, ModelData, PresenceEvent, PresenceSubscriptionOptions, RecordCollectionRef, RecordId, RecordRef } from "@palantir/pack.document-schema.model-types";
|
|
3
|
+
import type { CreateDocumentMetadata } from "./CreateDocumentMetadata.js";
|
|
3
4
|
export declare const DocumentLoadStatus: {
|
|
4
5
|
readonly UNLOADED: "unloaded";
|
|
5
6
|
readonly LOADING: "loading";
|
|
@@ -16,6 +17,11 @@ export declare const DocumentLiveStatus: {
|
|
|
16
17
|
export type DocumentLiveStatus = typeof DocumentLiveStatus[keyof typeof DocumentLiveStatus];
|
|
17
18
|
export type DocumentSyncStatus = {
|
|
18
19
|
readonly error?: unknown;
|
|
20
|
+
/**
|
|
21
|
+
* When true, indicates this is a demo/test service not connected to real Foundry.
|
|
22
|
+
* UI can use this to display a badge or indicator that data is local-only.
|
|
23
|
+
*/
|
|
24
|
+
readonly isDemo?: boolean;
|
|
19
25
|
readonly live: DocumentLiveStatus;
|
|
20
26
|
readonly load: DocumentLoadStatus;
|
|
21
27
|
};
|
|
@@ -32,6 +38,15 @@ export type RecordCollectionChangeCallback<M extends Model = Model> = (items: re
|
|
|
32
38
|
export type RecordChangeCallback<M extends Model = Model> = (snapshot: ModelData<M>, record: RecordRef<M>) => void;
|
|
33
39
|
export type RecordDeleteCallback<M extends Model = Model> = (record: RecordRef<M>) => void;
|
|
34
40
|
/**
|
|
41
|
+
* Result of a document search operation, including pagination information.
|
|
42
|
+
*/
|
|
43
|
+
export interface SearchDocumentsResult {
|
|
44
|
+
readonly data: ReadonlyArray<DocumentMetadata & {
|
|
45
|
+
readonly id: DocumentId;
|
|
46
|
+
}>;
|
|
47
|
+
readonly nextPageToken?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
35
50
|
* Base interface for specific document service implementations.
|
|
36
51
|
* The DocumentService is responsible for persisting document state,
|
|
37
52
|
* metadata, and providing methods to subscribe and interact with documents.
|
|
@@ -41,13 +56,12 @@ export type RecordDeleteCallback<M extends Model = Model> = (record: RecordRef<M
|
|
|
41
56
|
export interface DocumentService {
|
|
42
57
|
readonly hasMetadataSubscriptions: boolean;
|
|
43
58
|
readonly hasStateSubscriptions: boolean;
|
|
44
|
-
readonly createDocument: <T extends DocumentSchema>(metadata:
|
|
59
|
+
readonly createDocument: <T extends DocumentSchema>(metadata: CreateDocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
|
|
45
60
|
readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
|
|
46
61
|
documentName?: string;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}>>;
|
|
62
|
+
pageSize?: number;
|
|
63
|
+
pageToken?: string;
|
|
64
|
+
}) => Promise<SearchDocumentsResult>;
|
|
51
65
|
readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
|
|
52
66
|
readonly getCreateRecordCollectionRef: <const M extends Model>(docRef: DocumentRef, model: M) => RecordCollectionRef<M>;
|
|
53
67
|
readonly getCreateRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,mBAAmB;AACjC,cACE,eACA,YACA,kBACA,aACA,gBACA,eACA,iBACA,OACA,WACA,eACA,6BACA,qBACA,UACA,iBACK;
|
|
1
|
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IAClB,UAAU,qBAAqB,OAC5B;UAEI,kBAAkB,UAAU,OACnC,QAAQ,UAAU,IAClB,UAAU,qBAAqB,OAC5B;UAGI,oBAAoB,UAAU,gBACrC,QAAQ,YAAY,OACjB;UAEI,iBAAiB,UAAU,gBAClC,QAAQ,YAAY,IACpB,UAAU,iCACP;UAEI,sBAAsB,UAAU,gBACvC,QAAQ,YAAY,OACjB;UAEI,kBAAkB,UAAU,gBACnC,QAAQ,YAAY,OACjB","names":[],"sources":["../../../src/types/DocumentService.ts"],"version":3,"file":"DocumentService.d.ts"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ModuleKey, PackApp, PackAppInternal, Unsubscribe } from "@palantir/pack.core";
|
|
2
2
|
import type { ActivityEvent, DocumentId, DocumentMetadata, DocumentRef, DocumentSchema, DocumentState, EditDescription, Model, ModelData, PresenceEvent, PresenceSubscriptionOptions, RecordCollectionRef, RecordId, RecordRef } from "@palantir/pack.document-schema.model-types";
|
|
3
|
-
import type {
|
|
3
|
+
import type { CreateDocumentMetadata } from "./CreateDocumentMetadata.js";
|
|
4
|
+
import type { DocumentService, RecordChangeCallback, RecordCollectionChangeCallback, RecordDeleteCallback, SearchDocumentsResult } from "./DocumentService.js";
|
|
4
5
|
export declare const STATE_MODULE_ACCESSOR = "state";
|
|
5
6
|
export declare const STATE_MODULE_KEY: ModuleKey<StateModuleImpl>;
|
|
6
7
|
export type WithStateModule<T> = T & {
|
|
@@ -9,13 +10,12 @@ export type WithStateModule<T> = T & {
|
|
|
9
10
|
export interface StateModule {
|
|
10
11
|
readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
|
|
11
12
|
readonly createRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
|
|
12
|
-
readonly createDocument: <T extends DocumentSchema>(metadata:
|
|
13
|
+
readonly createDocument: <T extends DocumentSchema>(metadata: CreateDocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
|
|
13
14
|
readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
|
|
14
15
|
documentName?: string;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}>>;
|
|
16
|
+
pageSize?: number;
|
|
17
|
+
pageToken?: string;
|
|
18
|
+
}) => Promise<SearchDocumentsResult>;
|
|
19
19
|
readonly getDocumentSnapshot: <T extends DocumentSchema>(docRef: DocumentRef<T>) => Promise<DocumentState<T>>;
|
|
20
20
|
readonly onActivity: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: ActivityEvent) => void) => Unsubscribe;
|
|
21
21
|
readonly onMetadataChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, cb: (docRef: DocumentRef<T>, metadata: DocumentMetadata) => void) => Unsubscribe;
|
|
@@ -42,13 +42,12 @@ export declare class StateModuleImpl implements StateModule {
|
|
|
42
42
|
constructor(documentService: DocumentService);
|
|
43
43
|
createDocRef<const T extends DocumentSchema>(id: DocumentId, schema: T): DocumentRef<T>;
|
|
44
44
|
createRecordRef<const M extends Model>(docRef: DocumentRef, id: RecordId, model: M): RecordRef<M>;
|
|
45
|
-
createDocument<T extends DocumentSchema>(metadata:
|
|
45
|
+
createDocument<T extends DocumentSchema>(metadata: CreateDocumentMetadata, schema: T): Promise<DocumentRef<T>>;
|
|
46
46
|
searchDocuments<T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
|
|
47
47
|
documentName?: string;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}>>;
|
|
48
|
+
pageSize?: number;
|
|
49
|
+
pageToken?: string;
|
|
50
|
+
}): Promise<SearchDocumentsResult>;
|
|
52
51
|
getDocumentSnapshot<T extends DocumentSchema>(docRef: DocumentRef<T>): Promise<DocumentState<T>>;
|
|
53
52
|
onActivity<T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: ActivityEvent) => void): Unsubscribe;
|
|
54
53
|
onMetadataChange<T extends DocumentSchema>(docRef: DocumentRef<T>, cb: (doc: DocumentRef<T>, metadata: DocumentMetadata) => void): Unsubscribe;
|
|
@@ -76,4 +75,4 @@ export declare class StateModuleImpl implements StateModule {
|
|
|
76
75
|
waitForDataLoad<T extends DocumentSchema>(docRef: DocumentRef<T>): Promise<void>;
|
|
77
76
|
deleteRecord<M extends Model>(record: RecordRef<M>): Promise<void>;
|
|
78
77
|
}
|
|
79
|
-
export declare function getStateModule(app: PackAppInternal): StateModule;
|
|
78
|
+
export declare function getStateModule(app: PackApp | PackAppInternal): StateModule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,
|
|
1
|
+
{"mappings":"AAgBA,cAAc,WAAW,SAAS,iBAAiB,mBAAmB;AAEtE,cACE,eACA,YACA,kBACA,aACA,gBACA,eACA,iBACA,OACA,WACA,eACA,6BACA,qBACA,UACA,iBACK;AAEP,cAAc,8BAA8B;AAC5C,cACE,iBACA,sBACA,gCACA,sBACA,6BACK;AAGP,OAAO,cAAM,wBAAwB;AACrC,OAAO,cAAMA,kBAAkB,UAAU;AAQzC,YAAY,gBAAgB,KAAK,IAAI;WAAY,wBAAwB;;AAEzE,iBAAiB,YAAY;UAClB,qBAAqB,UAAU,gBACtC,IAAI,YACJ,QAAQ,MACL,YAAY;UAER,wBAAwB,UAAU,OACzC,QAAQ,aACR,IAAI,UACJ,OAAO,MACJ,UAAU;UAEN,iBAAiB,UAAU,gBAClC,UAAU,wBACV,QAAQ,MACL,QAAQ,YAAY;UAEhB,kBAAkB,UAAU,gBACnC,0BACA,QAAQ,GACR,UAAU;EACR;EACA;EACA;OAEC,QAAQ;UAEJ,sBAAsB,UAAU,gBACvC,QAAQ,YAAY,OACjB,QAAQ,cAAc;UAElB,aAAa,UAAU,gBAC9B,QAAQ,YAAY,IACpB,WAAW,QAAQ,YAAY,IAAI,OAAO,2BACvC;UAEI,mBAAmB,UAAU,gBACpC,QAA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,OAC1B,YAAY,oBAAoB;CAKlC,qBAAqB,UAAU,OAC7B,YAAY,oBAAoB,KAC/B,UAAU;CAIb,gBAAgB,UAAU,OACxB,QAAQ,UAAU,IAClB,UAAU,qBAAqB,KAC9B;CAIH,gBAAgB,UAAU,OACxB,QAAQ,UAAU,IAClB,UAAU,qBAAqB,KAC9B;CAIH,uBAAuB,UAAU,OAC/B,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,KACxC;CAIH,yBAAyB,UAAU,OACjC,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,KACxC;CAIH,yBAAyB,UAAU,OACjC,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,KACxC;CAKH,kBAAkB,UAAU,gBAC1B,QAAQ,YAAY,KACnB,WAAW,gBAAgB;CAI9B,eAAe,UAAU,gBACvB,QAAQ,YAAY,IACpB,UAAU,WAAW,gBAAgB,mBAAmB,KACvD;CAIH,AAAM,oBAAoB,UAAU,gBAClC,QAAQ,YAAY,KACnB;CAIH,AAAM,gBAAgB,UAAU,gBAC9B,QAAQ,YAAY,KACnB;CAIH,AAAM,aAAa,UAAU,OAC3B,QAAQ,UAAU,KACjB;;AAKL,OAAO,iBAAS,eAAe,KAAK,UAAU,kBAAkB","names":["STATE_MODULE_KEY: ModuleKey<StateModuleImpl>","documentService: DocumentService"],"sources":["../../../src/types/StateModule.ts"],"version":3,"file":"StateModule.d.ts"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@palantir/pack.state.core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "PACK State logic and utilities",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -28,21 +28,21 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@osdk/api": "~2.
|
|
31
|
+
"@osdk/api": "~2.5.2",
|
|
32
32
|
"remeda": "^2.32.0",
|
|
33
33
|
"tiny-invariant": "^1.3.3",
|
|
34
34
|
"yjs": "^13.6.27",
|
|
35
|
-
"@palantir/pack.
|
|
36
|
-
"@palantir/pack.
|
|
35
|
+
"@palantir/pack.document-schema.model-types": "0.3.0",
|
|
36
|
+
"@palantir/pack.core": "0.2.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"zod": "^4.1.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@osdk/client": "~2.
|
|
43
|
-
"rimraf": "^6.
|
|
42
|
+
"@osdk/client": "~2.5.2",
|
|
43
|
+
"rimraf": "^6.1.2",
|
|
44
44
|
"tslib": "^2.8.1",
|
|
45
|
-
"typescript": "^5.9.
|
|
45
|
+
"typescript": "^5.9.3",
|
|
46
46
|
"vitest-mock-extended": "^3.1.0",
|
|
47
47
|
"@palantir/pack.monorepo.tsconfig": "~0.4.3"
|
|
48
48
|
},
|
|
@@ -42,8 +42,9 @@ export function createTestApp(
|
|
|
42
42
|
appId: "test-app-id",
|
|
43
43
|
...config.app,
|
|
44
44
|
},
|
|
45
|
-
|
|
45
|
+
isDemoMode: config.isDemoMode ?? true,
|
|
46
46
|
logger: config.logger ?? consoleLogger({}),
|
|
47
|
+
ontologyRid: config.ontologyRid ?? Promise.resolve("ri.ontology...test"),
|
|
47
48
|
osdkClient: mockClient,
|
|
48
49
|
remote: {
|
|
49
50
|
packWsPath: "/api/v2/packSubscriptions",
|
package/src/index.ts
CHANGED
|
@@ -15,8 +15,13 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
export { createDocumentServiceConfig, getDocumentService } from "./DocumentServiceModule.js";
|
|
18
|
-
export {
|
|
18
|
+
export {
|
|
19
|
+
BaseYjsDocumentService,
|
|
20
|
+
type BaseYjsDocumentServiceOptions,
|
|
21
|
+
type InternalYjsDoc,
|
|
22
|
+
} from "./service/BaseYjsDocumentService.js";
|
|
19
23
|
export { createInMemoryDocumentServiceConfig } from "./service/InMemoryDocumentService.js";
|
|
24
|
+
export type { CreateDocumentMetadata } from "./types/CreateDocumentMetadata.js";
|
|
20
25
|
export { createDocRef, invalidDocRef, isValidDocRef } from "./types/DocumentRefImpl.js";
|
|
21
26
|
export { DocumentLiveStatus, DocumentLoadStatus } from "./types/DocumentService.js";
|
|
22
27
|
export type {
|
|
@@ -26,6 +31,7 @@ export type {
|
|
|
26
31
|
DocumentStatus,
|
|
27
32
|
DocumentStatusChangeCallback,
|
|
28
33
|
DocumentSyncStatus,
|
|
34
|
+
SearchDocumentsResult,
|
|
29
35
|
} from "./types/DocumentService.js";
|
|
30
36
|
export type { WithDocumentServiceInit } from "./types/DocumentServiceConfig.js";
|
|
31
37
|
export {
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
import { isDeepEqual } from "remeda";
|
|
38
38
|
import invariant from "tiny-invariant";
|
|
39
39
|
import * as Y from "yjs";
|
|
40
|
+
import type { CreateDocumentMetadata } from "../types/CreateDocumentMetadata.js";
|
|
40
41
|
import { createDocRef } from "../types/DocumentRefImpl.js";
|
|
41
42
|
import type {
|
|
42
43
|
DocumentMetadataChangeCallback,
|
|
@@ -48,6 +49,7 @@ import type {
|
|
|
48
49
|
RecordChangeCallback,
|
|
49
50
|
RecordCollectionChangeCallback,
|
|
50
51
|
RecordDeleteCallback,
|
|
52
|
+
SearchDocumentsResult,
|
|
51
53
|
} from "../types/DocumentService.js";
|
|
52
54
|
import { DocumentLiveStatus, DocumentLoadStatus } from "../types/DocumentService.js";
|
|
53
55
|
import { createRecordCollectionRef } from "../types/RecordCollectionRefImpl.js";
|
|
@@ -105,6 +107,10 @@ export interface InternalYjsDoc {
|
|
|
105
107
|
readonly yjsCollectionHandlers: Map<string, () => void>;
|
|
106
108
|
}
|
|
107
109
|
|
|
110
|
+
export interface BaseYjsDocumentServiceOptions {
|
|
111
|
+
readonly isDemo?: boolean;
|
|
112
|
+
}
|
|
113
|
+
|
|
108
114
|
/**
|
|
109
115
|
* Base class for document services that use Y.js for local state management.
|
|
110
116
|
* Provides common Y.js operations for both in-memory and backend services.
|
|
@@ -115,16 +121,20 @@ export abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc = Inter
|
|
|
115
121
|
implements DocumentService
|
|
116
122
|
{
|
|
117
123
|
protected readonly documents: Map<DocumentId, TDoc> = new Map();
|
|
124
|
+
protected readonly isDemo?: boolean;
|
|
118
125
|
|
|
119
126
|
constructor(
|
|
120
127
|
protected readonly app: PackAppInternal,
|
|
121
128
|
protected readonly logger: Logger,
|
|
122
|
-
|
|
129
|
+
options?: BaseYjsDocumentServiceOptions,
|
|
130
|
+
) {
|
|
131
|
+
this.isDemo = options?.isDemo;
|
|
132
|
+
}
|
|
123
133
|
|
|
124
134
|
abstract get hasMetadataSubscriptions(): boolean;
|
|
125
135
|
abstract get hasStateSubscriptions(): boolean;
|
|
126
136
|
abstract readonly createDocument: <T extends DocumentSchema>(
|
|
127
|
-
metadata:
|
|
137
|
+
metadata: CreateDocumentMetadata,
|
|
128
138
|
schema: T,
|
|
129
139
|
) => Promise<DocumentRef<T>>;
|
|
130
140
|
abstract readonly searchDocuments: <T extends DocumentSchema>(
|
|
@@ -132,9 +142,10 @@ export abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc = Inter
|
|
|
132
142
|
schema: T,
|
|
133
143
|
options?: {
|
|
134
144
|
documentName?: string;
|
|
135
|
-
|
|
145
|
+
pageSize?: number;
|
|
146
|
+
pageToken?: string;
|
|
136
147
|
},
|
|
137
|
-
) => Promise<
|
|
148
|
+
) => Promise<SearchDocumentsResult>;
|
|
138
149
|
|
|
139
150
|
readonly createDocRef = <const T extends DocumentSchema>(
|
|
140
151
|
id: DocumentId,
|
|
@@ -190,7 +201,7 @@ export abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc = Inter
|
|
|
190
201
|
|
|
191
202
|
protected abstract createInternalDoc(
|
|
192
203
|
ref: DocumentRef,
|
|
193
|
-
metadata?:
|
|
204
|
+
metadata?: CreateDocumentMetadata,
|
|
194
205
|
yDoc?: Y.Doc,
|
|
195
206
|
): TDoc;
|
|
196
207
|
|
|
@@ -314,6 +325,7 @@ export abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc = Inter
|
|
|
314
325
|
): void {
|
|
315
326
|
if (update.load != null || update.live != null) {
|
|
316
327
|
internalDoc.metadataStatus = {
|
|
328
|
+
isDemo: this.isDemo,
|
|
317
329
|
load: update.load ?? internalDoc.metadataStatus.load,
|
|
318
330
|
live: update.live ?? internalDoc.metadataStatus.live,
|
|
319
331
|
};
|
|
@@ -338,6 +350,7 @@ export abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc = Inter
|
|
|
338
350
|
): void {
|
|
339
351
|
if (update.load != null || update.live != null) {
|
|
340
352
|
internalDoc.dataStatus = {
|
|
353
|
+
isDemo: this.isDemo,
|
|
341
354
|
load: update.load ?? internalDoc.dataStatus.load,
|
|
342
355
|
live: update.live ?? internalDoc.dataStatus.live,
|
|
343
356
|
};
|
|
@@ -374,7 +387,7 @@ export abstract class BaseYjsDocumentService<TDoc extends InternalYjsDoc = Inter
|
|
|
374
387
|
*/
|
|
375
388
|
protected getCreateInternalDoc<T extends DocumentSchema>(
|
|
376
389
|
ref: DocumentRef<T>,
|
|
377
|
-
metadata?:
|
|
390
|
+
metadata?: CreateDocumentMetadata,
|
|
378
391
|
initialYDoc?: Y.Doc,
|
|
379
392
|
): { internalDocRef: DocumentRef<T>; internalDoc: TDoc; wasExisting: boolean } {
|
|
380
393
|
const { id, schema } = ref;
|
|
@@ -28,8 +28,9 @@ import type {
|
|
|
28
28
|
PresenceSubscriptionOptions,
|
|
29
29
|
} from "@palantir/pack.document-schema.model-types";
|
|
30
30
|
import { createDocumentServiceConfig } from "../DocumentServiceModule.js";
|
|
31
|
+
import type { CreateDocumentMetadata } from "../types/CreateDocumentMetadata.js";
|
|
31
32
|
import { createDocRef } from "../types/DocumentRefImpl.js";
|
|
32
|
-
import type { DocumentService } from "../types/DocumentService.js";
|
|
33
|
+
import type { DocumentService, SearchDocumentsResult } from "../types/DocumentService.js";
|
|
33
34
|
import { DocumentLoadStatus } from "../types/DocumentService.js";
|
|
34
35
|
import type { InternalYjsDoc } from "./BaseYjsDocumentService.js";
|
|
35
36
|
import { BaseYjsDocumentService } from "./BaseYjsDocumentService.js";
|
|
@@ -90,7 +91,7 @@ class InMemoryDocumentService extends BaseYjsDocumentService {
|
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
readonly createDocument = <T extends DocumentSchema>(
|
|
93
|
-
metadata:
|
|
94
|
+
metadata: CreateDocumentMetadata,
|
|
94
95
|
schema: T,
|
|
95
96
|
): Promise<DocumentRef<T>> => {
|
|
96
97
|
const id = generateDocumentId();
|
|
@@ -107,11 +108,12 @@ class InMemoryDocumentService extends BaseYjsDocumentService {
|
|
|
107
108
|
schema: T,
|
|
108
109
|
options?: {
|
|
109
110
|
documentName?: string;
|
|
110
|
-
|
|
111
|
+
pageSize?: number;
|
|
112
|
+
pageToken?: string;
|
|
111
113
|
},
|
|
112
|
-
): Promise<
|
|
114
|
+
): Promise<SearchDocumentsResult> => {
|
|
113
115
|
const results: Array<DocumentMetadata & { readonly id: DocumentId }> = [];
|
|
114
|
-
const { documentName,
|
|
116
|
+
const { documentName, pageSize } = options ?? {};
|
|
115
117
|
|
|
116
118
|
for (const [docId, internalDoc] of this.documents.entries()) {
|
|
117
119
|
if (internalDoc.metadata?.documentTypeName === documentTypeName) {
|
|
@@ -123,13 +125,14 @@ class InMemoryDocumentService extends BaseYjsDocumentService {
|
|
|
123
125
|
id: docId as DocumentId,
|
|
124
126
|
});
|
|
125
127
|
|
|
126
|
-
if (
|
|
128
|
+
if (pageSize && results.length >= pageSize) {
|
|
127
129
|
break;
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
// In-memory service doesn't support pagination
|
|
135
|
+
return Promise.resolve({ data: results, nextPageToken: undefined });
|
|
133
136
|
};
|
|
134
137
|
|
|
135
138
|
// Lifecycle method implementations
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { DocumentSecurity } from "@palantir/pack.document-schema.model-types";
|
|
18
|
+
|
|
19
|
+
export interface CreateDocumentMetadata {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly documentTypeName: string;
|
|
22
|
+
readonly security?: DocumentSecurity;
|
|
23
|
+
}
|
|
@@ -31,6 +31,7 @@ import type {
|
|
|
31
31
|
RecordId,
|
|
32
32
|
RecordRef,
|
|
33
33
|
} from "@palantir/pack.document-schema.model-types";
|
|
34
|
+
import type { CreateDocumentMetadata } from "./CreateDocumentMetadata.js";
|
|
34
35
|
|
|
35
36
|
export const DocumentLoadStatus = {
|
|
36
37
|
UNLOADED: "unloaded", // Not yet loaded
|
|
@@ -50,6 +51,11 @@ export type DocumentLiveStatus = typeof DocumentLiveStatus[keyof typeof Document
|
|
|
50
51
|
|
|
51
52
|
export type DocumentSyncStatus = {
|
|
52
53
|
readonly error?: unknown;
|
|
54
|
+
/**
|
|
55
|
+
* When true, indicates this is a demo/test service not connected to real Foundry.
|
|
56
|
+
* UI can use this to display a badge or indicator that data is local-only.
|
|
57
|
+
*/
|
|
58
|
+
readonly isDemo?: boolean;
|
|
53
59
|
readonly live: DocumentLiveStatus;
|
|
54
60
|
readonly load: DocumentLoadStatus;
|
|
55
61
|
};
|
|
@@ -87,6 +93,14 @@ export type RecordDeleteCallback<M extends Model = Model> = (
|
|
|
87
93
|
record: RecordRef<M>,
|
|
88
94
|
) => void;
|
|
89
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Result of a document search operation, including pagination information.
|
|
98
|
+
*/
|
|
99
|
+
export interface SearchDocumentsResult {
|
|
100
|
+
readonly data: ReadonlyArray<DocumentMetadata & { readonly id: DocumentId }>;
|
|
101
|
+
readonly nextPageToken?: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
90
104
|
/**
|
|
91
105
|
* Base interface for specific document service implementations.
|
|
92
106
|
* The DocumentService is responsible for persisting document state,
|
|
@@ -99,7 +113,7 @@ export interface DocumentService {
|
|
|
99
113
|
readonly hasStateSubscriptions: boolean;
|
|
100
114
|
|
|
101
115
|
readonly createDocument: <T extends DocumentSchema>(
|
|
102
|
-
metadata:
|
|
116
|
+
metadata: CreateDocumentMetadata,
|
|
103
117
|
schema: T,
|
|
104
118
|
) => Promise<DocumentRef<T>>;
|
|
105
119
|
|
|
@@ -108,9 +122,10 @@ export interface DocumentService {
|
|
|
108
122
|
schema: T,
|
|
109
123
|
options?: {
|
|
110
124
|
documentName?: string;
|
|
111
|
-
|
|
125
|
+
pageSize?: number;
|
|
126
|
+
pageToken?: string;
|
|
112
127
|
},
|
|
113
|
-
) => Promise<
|
|
128
|
+
) => Promise<SearchDocumentsResult>;
|
|
114
129
|
|
|
115
130
|
readonly createDocRef: <const T extends DocumentSchema>(
|
|
116
131
|
id: DocumentId,
|
package/src/types/StateModule.ts
CHANGED
|
@@ -14,12 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
type ModuleKey,
|
|
20
|
-
type PackAppInternal,
|
|
21
|
-
type Unsubscribe,
|
|
22
|
-
} from "@palantir/pack.core";
|
|
17
|
+
import type { ModuleKey, PackApp, PackAppInternal, Unsubscribe } from "@palantir/pack.core";
|
|
18
|
+
import { assertIsAppInternal } from "@palantir/pack.core";
|
|
23
19
|
import type {
|
|
24
20
|
ActivityEvent,
|
|
25
21
|
DocumentId,
|
|
@@ -37,11 +33,13 @@ import type {
|
|
|
37
33
|
RecordRef,
|
|
38
34
|
} from "@palantir/pack.document-schema.model-types";
|
|
39
35
|
import { DOCUMENT_SERVICE_MODULE_KEY } from "../DocumentServiceModule.js";
|
|
36
|
+
import type { CreateDocumentMetadata } from "./CreateDocumentMetadata.js";
|
|
40
37
|
import type {
|
|
41
38
|
DocumentService,
|
|
42
39
|
RecordChangeCallback,
|
|
43
40
|
RecordCollectionChangeCallback,
|
|
44
41
|
RecordDeleteCallback,
|
|
42
|
+
SearchDocumentsResult,
|
|
45
43
|
} from "./DocumentService.js";
|
|
46
44
|
|
|
47
45
|
// Ensure state module is accessible on PackApp instances.
|
|
@@ -69,7 +67,7 @@ export interface StateModule {
|
|
|
69
67
|
) => RecordRef<M>;
|
|
70
68
|
|
|
71
69
|
readonly createDocument: <T extends DocumentSchema>(
|
|
72
|
-
metadata:
|
|
70
|
+
metadata: CreateDocumentMetadata,
|
|
73
71
|
schema: T,
|
|
74
72
|
) => Promise<DocumentRef<T>>;
|
|
75
73
|
|
|
@@ -78,9 +76,10 @@ export interface StateModule {
|
|
|
78
76
|
schema: T,
|
|
79
77
|
options?: {
|
|
80
78
|
documentName?: string;
|
|
81
|
-
|
|
79
|
+
pageSize?: number;
|
|
80
|
+
pageToken?: string;
|
|
82
81
|
},
|
|
83
|
-
) => Promise<
|
|
82
|
+
) => Promise<SearchDocumentsResult>;
|
|
84
83
|
|
|
85
84
|
readonly getDocumentSnapshot: <T extends DocumentSchema>(
|
|
86
85
|
docRef: DocumentRef<T>,
|
|
@@ -202,7 +201,7 @@ export class StateModuleImpl implements StateModule {
|
|
|
202
201
|
}
|
|
203
202
|
|
|
204
203
|
async createDocument<T extends DocumentSchema>(
|
|
205
|
-
metadata:
|
|
204
|
+
metadata: CreateDocumentMetadata,
|
|
206
205
|
schema: T,
|
|
207
206
|
): Promise<DocumentRef<T>> {
|
|
208
207
|
return this.documentService.createDocument(metadata, schema);
|
|
@@ -213,9 +212,10 @@ export class StateModuleImpl implements StateModule {
|
|
|
213
212
|
schema: T,
|
|
214
213
|
options?: {
|
|
215
214
|
documentName?: string;
|
|
216
|
-
|
|
215
|
+
pageSize?: number;
|
|
216
|
+
pageToken?: string;
|
|
217
217
|
},
|
|
218
|
-
): Promise<
|
|
218
|
+
): Promise<SearchDocumentsResult> {
|
|
219
219
|
return this.documentService.searchDocuments(documentTypeName, schema, options);
|
|
220
220
|
}
|
|
221
221
|
|
|
@@ -401,7 +401,7 @@ export class StateModuleImpl implements StateModule {
|
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
export function getStateModule(app: PackAppInternal): StateModule {
|
|
404
|
+
export function getStateModule(app: PackApp | PackAppInternal): StateModule {
|
|
405
405
|
assertIsAppInternal(app);
|
|
406
406
|
return app.getModule(STATE_MODULE_KEY);
|
|
407
407
|
}
|