@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.
Files changed (40) hide show
  1. package/.turbo/turbo-lint.log +2 -2
  2. package/.turbo/turbo-transpileBrowser.log +1 -1
  3. package/.turbo/turbo-transpileCjs.log +1 -1
  4. package/.turbo/turbo-transpileEsm.log +1 -1
  5. package/.turbo/turbo-transpileTypes.log +1 -1
  6. package/.turbo/turbo-typecheck.log +1 -1
  7. package/CHANGELOG.md +33 -0
  8. package/build/browser/index.js +73 -0
  9. package/build/browser/index.js.map +1 -1
  10. package/build/cjs/index.cjs +73 -0
  11. package/build/cjs/index.cjs.map +1 -1
  12. package/build/cjs/index.d.cts +106 -1
  13. package/build/esm/index.js +73 -0
  14. package/build/esm/index.js.map +1 -1
  15. package/build/types/__tests__/Transaction.test.d.ts +1 -0
  16. package/build/types/__tests__/Transaction.test.d.ts.map +1 -0
  17. package/build/types/__tests__/testUtils.d.ts.map +1 -1
  18. package/build/types/service/BaseYjsDocumentService.d.ts +11 -1
  19. package/build/types/service/BaseYjsDocumentService.d.ts.map +1 -1
  20. package/build/types/service/InMemoryDocumentService.d.ts.map +1 -1
  21. package/build/types/types/DocumentRefImpl.d.ts +20 -0
  22. package/build/types/types/DocumentRefImpl.d.ts.map +1 -1
  23. package/build/types/types/DocumentService.d.ts +18 -1
  24. package/build/types/types/DocumentService.d.ts.map +1 -1
  25. package/build/types/types/RecordCollectionRefImpl.d.ts +23 -0
  26. package/build/types/types/RecordCollectionRefImpl.d.ts.map +1 -1
  27. package/build/types/types/RecordRefImpl.d.ts +25 -0
  28. package/build/types/types/RecordRefImpl.d.ts.map +1 -1
  29. package/build/types/types/StateModule.d.ts +21 -1
  30. package/build/types/types/StateModule.d.ts.map +1 -1
  31. package/package.json +6 -6
  32. package/src/__tests__/Transaction.test.ts +321 -0
  33. package/src/__tests__/testUtils.ts +1 -2
  34. package/src/service/BaseYjsDocumentService.ts +41 -0
  35. package/src/service/InMemoryDocumentService.ts +58 -1
  36. package/src/types/DocumentRefImpl.ts +58 -0
  37. package/src/types/DocumentService.ts +43 -0
  38. package/src/types/RecordCollectionRefImpl.ts +23 -0
  39. package/src/types/RecordRefImpl.ts +25 -0
  40. package/src/types/StateModule.ts +78 -0
@@ -1,5 +1,25 @@
1
1
  import type { PackAppInternal } from "@palantir/pack.core";
2
2
  import type { DocumentId, DocumentRef, DocumentSchema } from "@palantir/pack.document-schema.model-types";
3
3
  export declare const createDocRef: <const D extends DocumentSchema>(app: PackAppInternal, id: DocumentId, schema: D) => DocumentRef<D>;
4
+ /**
5
+ * Get an invalid document reference. This is a stable reference that can be
6
+ * used to represent a non-existent or invalid document.
7
+ *
8
+ * Not to be confused with a valid reference to a non-existent document, an
9
+ * invalid reference is one that is not properly initialized. For example, code
10
+ * that initializes with an undefined or empty documentId might produce an
11
+ * invalid document reference rather than propagate nullish types.
12
+ *
13
+ * Most operations on an invalid reference are no-ops. For the rest, it is
14
+ * recommended to check for validity using {@link isValidDocRef} before
15
+ * performing operations.
16
+ */
4
17
  export declare function invalidDocRef<D extends DocumentSchema = DocumentSchema>(): DocumentRef<D>;
18
+ /**
19
+ * Check if a document reference is an invalid reference.
20
+ * Not to be confused with a valid reference to a non-existent document, an invalid reference is one that is not properly initialized.
21
+ * For example, code that initializes with an undefined or empty documentId might produce an invalid document reference rather than
22
+ * propagate nullish types, as most operations on an invalid reference are no-ops. For the rest, it is recommended to check for
23
+ * validity using this function before performing operations.
24
+ */
5
25
  export declare function isValidDocRef<D extends DocumentSchema = DocumentSchema>(docRef: DocumentRef<D>): docRef is DocumentRef<D>;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,uBAAuB;AACrC,cACE,YAEA,aACA,sBAKK;AAoBP,OAAO,cAAM,qBAAsB,UAAU,gBAC3C,KAAK,iBACL,IAAI,YACJ,QAAQ,MACP,YAAY;AAIf,OAAO,iBAAS,cAAc,UAAU,iBAAiB,mBAAmB,YAAY;AAIxF,OAAO,iBAAS,cAAc,UAAU,iBAAiB,gBACvD,QAAQ,YAAY,KACnB,UAAU,YAAY","names":[],"sources":["../../../src/types/DocumentRefImpl.ts"],"version":3,"file":"DocumentRefImpl.d.ts"}
1
+ {"mappings":"AAgBA,cAAc,uBAAuB;AACrC,cAEE,YAEA,aACA,sBASK;AA0BP,OAAO,cAAM,qBAAsB,UAAU,gBAC3C,KAAK,iBACL,IAAI,YACJ,QAAQ,MACP,YAAY;;;;;;;;;;;;;;AAiBf,OAAO,iBAAS,cAAc,UAAU,iBAAiB,mBAAmB,YAAY;;;;;;;;AAWxF,OAAO,iBAAS,cAAc,UAAU,iBAAiB,gBACvD,QAAQ,YAAY,KACnB,UAAU,YAAY","names":[],"sources":["../../../src/types/DocumentRefImpl.ts"],"version":3,"file":"DocumentRefImpl.d.ts"}
@@ -1,5 +1,5 @@
1
1
  import type { Unsubscribe } from "@palantir/pack.core";
2
- import type { DocumentId, DocumentMetadata, DocumentRef, DocumentSchema, DocumentState, Model, ModelData, RecordCollectionRef, RecordId, RecordRef } from "@palantir/pack.document-schema.model-types";
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
3
  export declare const DocumentLoadStatus: {
4
4
  readonly UNLOADED: "unloaded";
5
5
  readonly LOADING: "loading";
@@ -31,10 +31,23 @@ export type DocumentStateChangeCallback<T extends DocumentSchema = DocumentSchem
31
31
  export type RecordCollectionChangeCallback<M extends Model = Model> = (items: readonly RecordRef<M>[]) => void;
32
32
  export type RecordChangeCallback<M extends Model = Model> = (snapshot: ModelData<M>, record: RecordRef<M>) => void;
33
33
  export type RecordDeleteCallback<M extends Model = Model> = (record: RecordRef<M>) => void;
34
+ /**
35
+ * Base interface for specific document service implementations.
36
+ * The DocumentService is responsible for persisting document state,
37
+ * metadata, and providing methods to subscribe and interact with documents.
38
+ *
39
+ * The main implementation communicates with the Foundry platform (see @palantir/pack.state.foundry).
40
+ */
34
41
  export interface DocumentService {
35
42
  readonly hasMetadataSubscriptions: boolean;
36
43
  readonly hasStateSubscriptions: boolean;
37
44
  readonly createDocument: <T extends DocumentSchema>(metadata: DocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
45
+ readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
46
+ documentName?: string;
47
+ limit?: number;
48
+ }) => Promise<ReadonlyArray<DocumentMetadata & {
49
+ readonly id: DocumentId;
50
+ }>>;
38
51
  readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
39
52
  readonly getCreateRecordCollectionRef: <const M extends Model>(docRef: DocumentRef, model: M) => RecordCollectionRef<M>;
40
53
  readonly getCreateRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
@@ -42,6 +55,7 @@ export interface DocumentService {
42
55
  readonly getRecordSnapshot: <R extends Model>(record: RecordRef<R>) => Promise<ModelData<R>>;
43
56
  readonly setRecord: <R extends Model>(record: RecordRef<R>, state: ModelData<R>) => Promise<void>;
44
57
  readonly updateRecord: <R extends Model>(record: RecordRef<R>, partialState: Partial<ModelData<R>>) => Promise<void>;
58
+ readonly withTransaction: (docRef: DocumentRef, fn: () => void, description?: EditDescription) => void;
45
59
  readonly getRecord: <M extends Model>(collection: RecordCollectionRef<M>, id: RecordId) => RecordRef<M> | undefined;
46
60
  readonly hasRecord: <M extends Model>(collection: RecordCollectionRef<M>, id: RecordId) => boolean;
47
61
  readonly setCollectionRecord: <M extends Model>(collection: RecordCollectionRef<M>, id: RecordId, state: ModelData<M>) => Promise<void>;
@@ -51,8 +65,11 @@ export interface DocumentService {
51
65
  readonly onCollectionItemsAdded: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
52
66
  readonly onCollectionItemsChanged: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
53
67
  readonly onCollectionItemsDeleted: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
68
+ readonly onActivity: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: ActivityEvent) => void) => Unsubscribe;
54
69
  readonly onMetadataChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: DocumentMetadataChangeCallback<T>) => Unsubscribe;
70
+ readonly onPresence: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: PresenceEvent) => void, options?: PresenceSubscriptionOptions) => Unsubscribe;
55
71
  readonly onStateChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: DocumentStateChangeCallback<T>) => Unsubscribe;
72
+ readonly updateCustomPresence: <M extends Model>(docRef: DocumentRef, model: M, eventData: ModelData<M>) => void;
56
73
  readonly onRecordChanged: <M extends Model>(record: RecordRef<M>, callback: RecordChangeCallback<M>) => Unsubscribe;
57
74
  readonly onRecordDeleted: <M extends Model>(record: RecordRef<M>, callback: RecordDeleteCallback<M>) => Unsubscribe;
58
75
  readonly getDocumentStatus: <T extends DocumentSchema>(docRef: DocumentRef<T>) => DocumentStatus;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,mBAAmB;AACjC,cACE,YACA,kBACA,aACA,gBACA,eACA,OACA,WACA,qBACA,UACA,iBACK;AAEP,OAAO,cAAM;UACX,UAAU;UACV,SAAS;UACT,QAAQ;UACR,OAAO;;AAET,YAAY,4BAA4B,gCAAgC;AAExE,OAAO,cAAM;UACX,cAAc;UACd,YAAY;UACZ,WAAW;UACX,OAAO;;AAET,YAAY,4BAA4B,gCAAgC;AAExE,YAAY,qBAAqB;UACtB;UACA,MAAM;UACN,MAAM;;AAGjB,YAAY,iBAAiB;UAClB,UAAU;UACV,MAAM;UACN;UAC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1C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACtC;UAEI,2BAA2B,UAAU,OAC5C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACtC;UAEI,2BAA2B,UAAU,OAC5C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACtC;UAEI,mBAAmB,UAAU,gBACpC,QAAQ,YAAY,IACpB,UAAU,+BAA+B,OACtC;UAEI,gBAAgB,UAAU,gBACjC,QAAQ,YAAY,IACpB,UAAU,4BAA4B,OACnC;UAEI,kBAAkB,UAAU,OACnC,QAAQ,UAAU,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
+ {"mappings":"AAgBA,cAAc,mBAAmB;AACjC,cACE,eACA,YACA,kBACA,aACA,gBACA,eACA,iBACA,OACA,WACA,eACA,6BACA,qBACA,UACA,iBACK;AAEP,OAAO,cAAM;UACX,UAAU;UACV,SAAS;UACT,QAAQ;UACR,OAAO;;AAET,YAAY,4BAA4B,gCAAgC;AAExE,OAAO,cAAM;UACX,cAAc;UACd,YAAY;UACZ,WAAW;UACX,OAAO;;AAET,YAAY,4BAA4B,gCAAgC;AAExE,YAAY,qBAAqB;UACtB;UACA,MAAM;UACN,MAAM;;AAGjB,YAAY,iBAAiB;UAClB,UAAU;UACV,MAAM;UACN;UACA;;AAGX,YAAY,gCACV,QAAQ,aACR,QAAQ;AAGV,YAAY,+BACV,UAAU,iBAAiB,mBACxB,QAAQ,YAAY,IAAI,UAAU;AAEvC,YAAY,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AAU;UAEN,yBAAyB,UAAU,OAC1C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACtC;UAEI,2BAA2B,UAAU,OAC5C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACtC;UAEI,2BAA2B,UAAU,OAC5C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACtC;UAEI,aAAa,UAAU,gBAC9B,QAAQ,YAAY,IACpB,WAAW,QAAQ,YAAY,IAAI,OAAO,2BACvC;UAEI,mBAAmB,UAAU,gBACpC,QAAQ,YAAY,IACpB,UAAU,+BAA+B,OACtC;UAEI,aAAa,UAAU,gBAC9B,QAAQ,YAAY,IACpB,WAAW,QAAQ,YAAY,IAAI,OAAO,wBAC1C,UAAU,gCACP;UAEI,gBAAgB,UAAU,gBACjC,QAAQ,YAAY,IACpB,UAAU,4BAA4B,OACnC;UAEI,uBAAuB,UAAU,OACxC,QAAQ,aACR,OAAO,GACP,WAAW,UAAU;UAGd,kBAAkB,UAAU,OACnC,QAAQ,UAAU,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,5 +1,28 @@
1
1
  import type { DocumentRef, Model, RecordCollectionRef } from "@palantir/pack.document-schema.model-types";
2
2
  import type { DocumentService } from "./DocumentService.js";
3
3
  export declare const createRecordCollectionRef: <const M extends Model>(documentService: DocumentService, docRef: DocumentRef, model: M) => RecordCollectionRef<M>;
4
+ /**
5
+ * Get an invalid record collection reference. This is a stable reference that
6
+ * can be used to represent an invalid record collection.
7
+ *
8
+ * Not to be confused with a valid reference to a non-existent record
9
+ * collection, an invalid reference is one that is not properly initialized. For
10
+ * example, code that initializes with an undefined or empty model might produce
11
+ * an invalid record collection reference rather than propagate nullish types.
12
+ *
13
+ * Most operations on an invalid reference are no-ops. For the rest, it is
14
+ * recommended to check for validity using {@link isValidRecordCollectionRef}
15
+ * before performing operations.
16
+ */
4
17
  export declare function invalidRecordCollectionRef<M extends Model = Model>(): RecordCollectionRef<M>;
18
+ /**
19
+ * Check if a record collection reference is a valid reference.
20
+ *
21
+ * Not to be confused with a valid reference to a non-existent record
22
+ * collection, an invalid reference is one that is not properly initialized.
23
+ *
24
+ * Most operations on an invalid reference are no-ops. For the rest, it is
25
+ * recommended to check for validity using this function before performing
26
+ * operations.
27
+ */
5
28
  export declare function isValidRecordCollectionRef<M extends Model = Model>(collectionRef: RecordCollectionRef<M>): collectionRef is RecordCollectionRef<M>;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cACE,aACA,OAEA,2BAIK;AAGP,cAAc,uBAAuB;AAqBrC,OAAO,cAAM,kCAAmC,UAAU,OACxD,iBAAiB,iBACjB,QAAQ,aACR,OAAO,MACN,oBAAoB;AAIvB,OAAO,iBAAS,2BAA2B,UAAU,QAAQ,UAAU,oBAAoB;AAI3F,OAAO,iBAAS,2BAA2B,UAAU,QAAQ,OAC3D,eAAe,oBAAoB,KAClC,iBAAiB,oBAAoB","names":[],"sources":["../../../src/types/RecordCollectionRefImpl.ts"],"version":3,"file":"RecordCollectionRefImpl.d.ts"}
1
+ {"mappings":"AAgBA,cACE,aACA,OAEA,2BAIK;AAGP,cAAc,uBAAuB;AAqBrC,OAAO,cAAM,kCAAmC,UAAU,OACxD,iBAAiB,iBACjB,QAAQ,aACR,OAAO,MACN,oBAAoB;;;;;;;;;;;;;;AAiBvB,OAAO,iBAAS,2BAA2B,UAAU,QAAQ,UAAU,oBAAoB;;;;;;;;;;;AAc3F,OAAO,iBAAS,2BAA2B,UAAU,QAAQ,OAC3D,eAAe,oBAAoB,KAClC,iBAAiB,oBAAoB","names":[],"sources":["../../../src/types/RecordCollectionRefImpl.ts"],"version":3,"file":"RecordCollectionRefImpl.d.ts"}
@@ -1,5 +1,30 @@
1
1
  import type { DocumentRef, Model, RecordId, RecordRef } from "@palantir/pack.document-schema.model-types";
2
2
  import type { DocumentService } from "./DocumentService.js";
3
3
  export declare const createRecordRef: <const M extends Model>(documentService: DocumentService, docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
4
+ /**
5
+ * Get an invalid record reference. This is a stable reference that can be used
6
+ * to represent an invalid record.
7
+ *
8
+ * Not to be confused with a valid reference to a non-existent record, an
9
+ * invalid reference is one that is not properly initialized. For example, code
10
+ * that initializes with an undefined or empty recordId might produce an
11
+ * invalid record reference rather than propagate nullish types.
12
+ *
13
+ * Most operations on an invalid reference are no-ops. For the rest, it is
14
+ * recommended to check for validity using {@link isValidRecordRef} before
15
+ * performing operations.
16
+ */
4
17
  export declare function invalidRecordRef<M extends Model = Model>(): RecordRef<M>;
18
+ /**
19
+ * Check if a record reference is a valid reference.
20
+ *
21
+ * Not to be confused with a valid reference to a non-existent record, an
22
+ * invalid reference is one that is not properly initialized.
23
+ *
24
+ * For example, code that initializes with an undefined or empty recordId might
25
+ * produce an invalid record reference rather than propagate nullish types, as
26
+ * most operations on an invalid reference are no-ops. For the rest, it is
27
+ * recommended to check for validity using this function before performing
28
+ * operations.
29
+ */
5
30
  export declare function isValidRecordRef<M extends Model = Model>(recordRef: RecordRef<M>): recordRef is RecordRef<M>;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cACE,aACA,OAEA,UACA,iBAEK;AAGP,cAAc,uBAAuB;AAgBrC,OAAO,cAAM,wBAAyB,UAAU,OAC9C,iBAAiB,iBACjB,QAAQ,aACR,IAAI,UACJ,OAAO,MACN,UAAU;AAIb,OAAO,iBAAS,iBAAiB,UAAU,QAAQ,UAAU,UAAU;AAIvE,OAAO,iBAAS,iBAAiB,UAAU,QAAQ,OACjD,WAAW,UAAU,KACpB,aAAa,UAAU","names":[],"sources":["../../../src/types/RecordRefImpl.ts"],"version":3,"file":"RecordRefImpl.d.ts"}
1
+ {"mappings":"AAgBA,cACE,aACA,OAEA,UACA,iBAEK;AAGP,cAAc,uBAAuB;AAgBrC,OAAO,cAAM,wBAAyB,UAAU,OAC9C,iBAAiB,iBACjB,QAAQ,aACR,IAAI,UACJ,OAAO,MACN,UAAU;;;;;;;;;;;;;;AAiBb,OAAO,iBAAS,iBAAiB,UAAU,QAAQ,UAAU,UAAU;;;;;;;;;;;;;AAgBvE,OAAO,iBAAS,iBAAiB,UAAU,QAAQ,OACjD,WAAW,UAAU,KACpB,aAAa,UAAU","names":[],"sources":["../../../src/types/RecordRefImpl.ts"],"version":3,"file":"RecordRefImpl.d.ts"}
@@ -1,5 +1,5 @@
1
1
  import { type ModuleKey, type PackAppInternal, type Unsubscribe } from "@palantir/pack.core";
2
- import type { DocumentId, DocumentMetadata, DocumentRef, DocumentSchema, DocumentState, Model, ModelData, RecordCollectionRef, RecordId, RecordRef } from "@palantir/pack.document-schema.model-types";
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
3
  import type { DocumentService, RecordChangeCallback, RecordCollectionChangeCallback, RecordDeleteCallback } from "./DocumentService.js";
4
4
  export declare const STATE_MODULE_ACCESSOR = "state";
5
5
  export declare const STATE_MODULE_KEY: ModuleKey<StateModuleImpl>;
@@ -10,15 +10,25 @@ export interface StateModule {
10
10
  readonly createDocRef: <const T extends DocumentSchema>(id: DocumentId, schema: T) => DocumentRef<T>;
11
11
  readonly createRecordRef: <const M extends Model>(docRef: DocumentRef, id: RecordId, model: M) => RecordRef<M>;
12
12
  readonly createDocument: <T extends DocumentSchema>(metadata: DocumentMetadata, schema: T) => Promise<DocumentRef<T>>;
13
+ readonly searchDocuments: <T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
14
+ documentName?: string;
15
+ limit?: number;
16
+ }) => Promise<ReadonlyArray<DocumentMetadata & {
17
+ readonly id: DocumentId;
18
+ }>>;
13
19
  readonly getDocumentSnapshot: <T extends DocumentSchema>(docRef: DocumentRef<T>) => Promise<DocumentState<T>>;
20
+ readonly onActivity: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: ActivityEvent) => void) => Unsubscribe;
14
21
  readonly onMetadataChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, cb: (docRef: DocumentRef<T>, metadata: DocumentMetadata) => void) => Unsubscribe;
22
+ readonly onPresence: <T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: PresenceEvent) => void, options?: PresenceSubscriptionOptions) => Unsubscribe;
15
23
  readonly onStateChange: <T extends DocumentSchema>(docRef: DocumentRef<T>, cb: (docRef: DocumentRef<T>) => void) => Unsubscribe;
24
+ readonly updateCustomPresence: <M extends Model>(docRef: DocumentRef, model: M, eventData: ModelData<M>) => void;
16
25
  readonly getRecordSnapshot: <R extends Model>(recordRef: RecordRef<R>) => Promise<ModelData<R>>;
17
26
  readonly onCollectionItemsAdded: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
18
27
  readonly onCollectionItemsChanged: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
19
28
  readonly onCollectionItemsDeleted: <M extends Model>(collection: RecordCollectionRef<M>, callback: RecordCollectionChangeCallback<M>) => Unsubscribe;
20
29
  readonly setRecord: <R extends Model>(recordRef: RecordRef<R>, state: ModelData<R>) => Promise<void>;
21
30
  readonly updateRecord: <R extends Model>(recordRef: RecordRef<R>, partialState: Partial<ModelData<R>>) => Promise<void>;
31
+ readonly withTransaction: (docRef: DocumentRef, fn: () => void, description?: EditDescription) => void;
22
32
  readonly onRecordChanged: <M extends Model>(record: RecordRef<M>, callback: RecordChangeCallback<M>) => Unsubscribe;
23
33
  readonly onRecordDeleted: <M extends Model>(record: RecordRef<M>, callback: RecordDeleteCallback<M>) => Unsubscribe;
24
34
  readonly deleteRecord: <M extends Model>(record: RecordRef<M>) => Promise<void>;
@@ -33,12 +43,22 @@ export declare class StateModuleImpl implements StateModule {
33
43
  createDocRef<const T extends DocumentSchema>(id: DocumentId, schema: T): DocumentRef<T>;
34
44
  createRecordRef<const M extends Model>(docRef: DocumentRef, id: RecordId, model: M): RecordRef<M>;
35
45
  createDocument<T extends DocumentSchema>(metadata: DocumentMetadata, schema: T): Promise<DocumentRef<T>>;
46
+ searchDocuments<T extends DocumentSchema>(documentTypeName: string, schema: T, options?: {
47
+ documentName?: string;
48
+ limit?: number;
49
+ }): Promise<ReadonlyArray<DocumentMetadata & {
50
+ readonly id: DocumentId;
51
+ }>>;
36
52
  getDocumentSnapshot<T extends DocumentSchema>(docRef: DocumentRef<T>): Promise<DocumentState<T>>;
53
+ onActivity<T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: ActivityEvent) => void): Unsubscribe;
37
54
  onMetadataChange<T extends DocumentSchema>(docRef: DocumentRef<T>, cb: (doc: DocumentRef<T>, metadata: DocumentMetadata) => void): Unsubscribe;
55
+ onPresence<T extends DocumentSchema>(docRef: DocumentRef<T>, callback: (docRef: DocumentRef<T>, event: PresenceEvent) => void, options?: PresenceSubscriptionOptions): Unsubscribe;
38
56
  onStateChange<T extends DocumentSchema>(docRef: DocumentRef<T>, cb: (docRef: DocumentRef<T>) => void): Unsubscribe;
57
+ updateCustomPresence<M extends Model>(docRef: DocumentRef, model: M, eventData: ModelData<M>): void;
39
58
  getRecordSnapshot<R extends Model>(recordRef: RecordRef<R>): Promise<ModelData<R>>;
40
59
  setRecord<R extends Model>(recordRef: RecordRef<R>, state: ModelData<R>): Promise<void>;
41
60
  updateRecord<R extends Model>(recordRef: RecordRef<R>, partialState: Partial<ModelData<R>>): Promise<void>;
61
+ withTransaction(docRef: DocumentRef, fn: () => void, description?: EditDescription): void;
42
62
  getCreateRecordCollectionRef<M extends Model>(docRef: DocumentRef, model: M): RecordCollectionRef<M>;
43
63
  getRecord<M extends Model>(collection: RecordCollectionRef<M>, id: RecordId): RecordRef<M> | undefined;
44
64
  hasRecord<M extends Model>(collection: RecordCollectionRef<M>, id: RecordId): boolean;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAEO,gBACA,sBACA,mBACA;AACP,cACE,YACA,kBACA,aACA,gBACA,eACA,OACA,WACA,qBACA,UACA,iBACK;AAEP,cACE,iBACA,sBACA,gCACA,4BACK;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,kBACV,QAAQ,MACL,QAAQ,YAAY;UAEhB,sBAAsB,UAAU,gBACvC,QAAQ,YAAY,OACjB,QAAQ,cAAc;UAElB,mBAAmB,UAAU,gBACpC,QAAQ,YAAY,IACpB,KAAK,QAAQ,YAAY,IAAI,UAAU,8BACpC;UAEI,gBAAgB,UAAU,gBACjC,QAAQ,YAAY,IACpB,KAAK,QAAQ,YAAY,gBACtB;UAEI,oBAAoB,UAAU,OACrC,WAAW,UAAU,OAClB,QAAQ,UAAU;UAEd,yBAAyB,UAAU,OAC1C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACtC;UAEI,2BAA2B,UAAU,OAC5C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACtC;UAEI,2BAA2B,UAAU,OAC5C,YAAY,oBAAoB,IAChC,UAAU,+BAA+B,OACtC;UAEI,YAAY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H,6BAA6B,UAAU,OACrC,QAAQ,aACR,OAAO,IACN,oBAAoB;CAKvB,UAAU,UAAU,OAClB,YAAY,oBAAoB,IAChC,IAAI,WACH,UAAU;CAIb,UAAU,UAAU,OAClB,YAAY,oBAAoB,IAChC,IAAI;CAKN,AAAM,oBAAoB,UAAU,OAClC,YAAY,oBAAoB,IAChC,IAAI,UACJ,OAAO,UAAU,KAChB;CAIH,kBAAkB,UAAU,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,kBAAkB","names":["STATE_MODULE_KEY: ModuleKey<StateModuleImpl>","documentService: DocumentService"],"sources":["../../../src/types/StateModule.ts"],"version":3,"file":"StateModule.d.ts"}
1
+ {"mappings":"AAgBA,cAEO,gBACA,sBACA,mBACA;AACP,cACE,eACA,YACA,kBACA,aACA,gBACA,eACA,iBACA,OACA,WACA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gB,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,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.1.0-beta.2",
3
+ "version": "0.1.1",
4
4
  "description": "PACK State logic and utilities",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -32,8 +32,8 @@
32
32
  "remeda": "^2.32.0",
33
33
  "tiny-invariant": "^1.3.3",
34
34
  "yjs": "^13.6.27",
35
- "@palantir/pack.core": "0.1.0-beta.2",
36
- "@palantir/pack.document-schema.model-types": "0.1.0-beta.3"
35
+ "@palantir/pack.document-schema.model-types": "0.1.1",
36
+ "@palantir/pack.core": "0.1.1"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "zod": "^4.1.0"
@@ -44,7 +44,7 @@
44
44
  "tslib": "^2.8.1",
45
45
  "typescript": "^5.9.2",
46
46
  "vitest-mock-extended": "^3.1.0",
47
- "@palantir/pack.monorepo.tsconfig": "~0.4.0-beta.1"
47
+ "@palantir/pack.monorepo.tsconfig": "~0.4.3"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"
@@ -58,8 +58,8 @@
58
58
  "type": "module",
59
59
  "scripts": {
60
60
  "clean": "rimraf .turbo build dist lib test-output *.tgz tsconfig.tsbuildinfo",
61
- "lint": "eslint ./src ; dprint check --config $(find-up dprint.json) --allow-no-files",
62
- "lint:fix": "eslint ./src --fix ; dprint fmt --config $(find-up dprint.json) --allow-no-files",
61
+ "lint": "eslint ./src && dprint check --config $(find-up dprint.json) --allow-no-files",
62
+ "lint:fix": "eslint ./src --fix && dprint fmt --config $(find-up dprint.json) --allow-no-files",
63
63
  "test": "vitest run --passWithNoTests -u",
64
64
  "test:watch": "vitest --passWithNoTests",
65
65
  "transpileBrowser": "monorepo-transpile -f esm -m bundle -t browser",
@@ -0,0 +1,321 @@
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 { PackAppInternal } from "@palantir/pack.core";
18
+ import type {
19
+ DocumentMetadata,
20
+ DocumentRef,
21
+ DocumentSchema,
22
+ Model,
23
+ RecordId,
24
+ RecordRef,
25
+ } from "@palantir/pack.document-schema.model-types";
26
+ import { Metadata } from "@palantir/pack.document-schema.model-types";
27
+ import { beforeEach, describe, expect, it, vi } from "vitest";
28
+ import type * as Y from "yjs";
29
+ import { z } from "zod";
30
+ import { DOCUMENT_SERVICE_MODULE_KEY } from "../DocumentServiceModule.js";
31
+ import type { BaseYjsDocumentService } from "../service/BaseYjsDocumentService.js";
32
+ import { getStateModule } from "../types/StateModule.js";
33
+ import { createTestApp } from "./testUtils.js";
34
+
35
+ const TEST_SECURITY = {
36
+ discretionary: {
37
+ editors: [],
38
+ owners: [],
39
+ viewers: [],
40
+ },
41
+ mandatory: {
42
+ classification: ["MU"],
43
+ markings: [],
44
+ },
45
+ };
46
+
47
+ interface User {
48
+ email: string;
49
+ id: string;
50
+ name: string;
51
+ }
52
+
53
+ const createSchemaWithRecords = () => {
54
+ const userSchema = z.object({
55
+ email: z.email(),
56
+ id: z.string(),
57
+ name: z.string(),
58
+ });
59
+
60
+ const UserModel: Model<User, typeof userSchema> = {
61
+ __type: {} as User,
62
+ zodSchema: userSchema,
63
+ [Metadata]: {
64
+ name: "User",
65
+ },
66
+ };
67
+
68
+ return {
69
+ User: UserModel,
70
+ [Metadata]: {
71
+ version: 1,
72
+ },
73
+ } as const satisfies DocumentSchema;
74
+ };
75
+
76
+ describe("Transaction Batching", () => {
77
+ let app: PackAppInternal;
78
+ let docRef: DocumentRef<ReturnType<typeof createSchemaWithRecords>>;
79
+ let schema: ReturnType<typeof createSchemaWithRecords>;
80
+
81
+ beforeEach(async () => {
82
+ app = createTestApp();
83
+ const stateModule = getStateModule(app);
84
+
85
+ const metadata: DocumentMetadata = {
86
+ documentTypeName: "TestType",
87
+ name: "Test Document",
88
+ ontologyRid: "test-ontology-rid",
89
+ security: TEST_SECURITY,
90
+ };
91
+
92
+ schema = createSchemaWithRecords();
93
+ docRef = await stateModule.createDocument(metadata, schema);
94
+ });
95
+
96
+ it("should batch multiple setRecord operations into single Y.js transaction", async () => {
97
+ const collection = docRef.getRecords(schema.User);
98
+ const stateModule = getStateModule(app);
99
+
100
+ let stateChangeCount = 0;
101
+ const unsubscribe = stateModule.onStateChange(docRef, () => {
102
+ stateChangeCount++;
103
+ });
104
+
105
+ await new Promise(resolve => setTimeout(resolve, 10));
106
+ const initialCount = stateChangeCount;
107
+
108
+ const userId1 = "user1" as RecordId;
109
+ const userId2 = "user2" as RecordId;
110
+ const userId3 = "user3" as RecordId;
111
+
112
+ docRef.withTransaction(() => {
113
+ void collection.set(userId1, { email: "alice@example.com", id: "user1", name: "Alice" });
114
+ void collection.set(userId2, { email: "bob@example.com", id: "user2", name: "Bob" });
115
+ void collection.set(userId3, { email: "charlie@example.com", id: "user3", name: "Charlie" });
116
+ });
117
+
118
+ await new Promise(resolve => setTimeout(resolve, 10));
119
+ expect(stateChangeCount - initialCount).toBe(1);
120
+
121
+ const record1 = collection.get(userId1)!;
122
+ const record2 = collection.get(userId2)!;
123
+ const record3 = collection.get(userId3)!;
124
+
125
+ const snapshot1 = await record1.getSnapshot();
126
+ const snapshot2 = await record2.getSnapshot();
127
+ const snapshot3 = await record3.getSnapshot();
128
+
129
+ expect(snapshot1).toEqual({ email: "alice@example.com", id: "user1", name: "Alice" });
130
+ expect(snapshot2).toEqual({ email: "bob@example.com", id: "user2", name: "Bob" });
131
+ expect(snapshot3).toEqual({ email: "charlie@example.com", id: "user3", name: "Charlie" });
132
+
133
+ unsubscribe();
134
+ });
135
+
136
+ it("should batch mixed operations (set, update, delete) into single transaction", async () => {
137
+ const collection = docRef.getRecords(schema.User);
138
+ const stateModule = getStateModule(app);
139
+
140
+ const userId1 = "user1" as RecordId;
141
+ const userId2 = "user2" as RecordId;
142
+ const userId3 = "user3" as RecordId;
143
+
144
+ await collection.set(userId1, { email: "alice@example.com", id: "user1", name: "Alice" });
145
+ await collection.set(userId2, { email: "bob@example.com", id: "user2", name: "Bob" });
146
+
147
+ let stateChangeCount = 0;
148
+ const unsubscribe = stateModule.onStateChange(docRef, () => {
149
+ stateChangeCount++;
150
+ });
151
+
152
+ await new Promise(resolve => setTimeout(resolve, 10));
153
+ const initialCount = stateChangeCount;
154
+
155
+ const record1 = collection.get(userId1)!;
156
+
157
+ docRef.withTransaction(() => {
158
+ void stateModule.updateRecord(record1, { name: "Alice Updated" });
159
+ void collection.delete(userId2);
160
+ void collection.set(userId3, { email: "charlie@example.com", id: "user3", name: "Charlie" });
161
+ });
162
+
163
+ await new Promise(resolve => setTimeout(resolve, 10));
164
+ expect(stateChangeCount - initialCount).toBe(1);
165
+
166
+ const snapshot1 = await record1.getSnapshot();
167
+ expect(snapshot1.name).toBe("Alice Updated");
168
+
169
+ const record3 = collection.get(userId3)!;
170
+ const snapshot3 = await record3.getSnapshot();
171
+ expect(snapshot3).toEqual({ email: "charlie@example.com", id: "user3", name: "Charlie" });
172
+
173
+ unsubscribe();
174
+ });
175
+
176
+ it("should trigger collection callbacks once after transaction completes", async () => {
177
+ const collection = docRef.getRecords(schema.User);
178
+ const stateModule = getStateModule(app);
179
+
180
+ const addedCallback = vi.fn();
181
+ const unsubscribe = stateModule.onCollectionItemsAdded(collection, addedCallback);
182
+
183
+ const userId1 = "user1" as RecordId;
184
+ const userId2 = "user2" as RecordId;
185
+ const userId3 = "user3" as RecordId;
186
+
187
+ docRef.withTransaction(() => {
188
+ void collection.set(userId1, { email: "alice@example.com", id: "user1", name: "Alice" });
189
+ void collection.set(userId2, { email: "bob@example.com", id: "user2", name: "Bob" });
190
+ void collection.set(userId3, { email: "charlie@example.com", id: "user3", name: "Charlie" });
191
+ });
192
+
193
+ await new Promise(resolve => setTimeout(resolve, 10));
194
+
195
+ expect(addedCallback).toHaveBeenCalledTimes(1);
196
+ const addedRecords = addedCallback.mock.calls[0]?.[0] as readonly RecordRef[] | undefined;
197
+ expect(addedRecords).toBeDefined();
198
+ expect(addedRecords).toHaveLength(3);
199
+
200
+ unsubscribe();
201
+ });
202
+
203
+ it("should handle nested transactions correctly (Y.js transact is reentrant)", async () => {
204
+ const collection = docRef.getRecords(schema.User);
205
+ const stateModule = getStateModule(app);
206
+
207
+ let stateChangeCount = 0;
208
+ const unsubscribe = stateModule.onStateChange(docRef, () => {
209
+ stateChangeCount++;
210
+ });
211
+
212
+ await new Promise(resolve => setTimeout(resolve, 10));
213
+ const initialCount = stateChangeCount;
214
+
215
+ const userId1 = "user1" as RecordId;
216
+ const userId2 = "user2" as RecordId;
217
+
218
+ docRef.withTransaction(() => {
219
+ void collection.set(userId1, { email: "alice@example.com", id: "user1", name: "Alice" });
220
+
221
+ docRef.withTransaction(() => {
222
+ void collection.set(userId2, { email: "bob@example.com", id: "user2", name: "Bob" });
223
+ });
224
+ });
225
+
226
+ await new Promise(resolve => setTimeout(resolve, 10));
227
+ expect(stateChangeCount - initialCount).toBe(1);
228
+
229
+ const record1 = collection.get(userId1)!;
230
+ const record2 = collection.get(userId2)!;
231
+
232
+ const snapshot1 = await record1.getSnapshot();
233
+ const snapshot2 = await record2.getSnapshot();
234
+
235
+ expect(snapshot1).toEqual({ email: "alice@example.com", id: "user1", name: "Alice" });
236
+ expect(snapshot2).toEqual({ email: "bob@example.com", id: "user2", name: "Bob" });
237
+
238
+ unsubscribe();
239
+ });
240
+
241
+ it("should work correctly when operations are called without transaction", async () => {
242
+ const collection = docRef.getRecords(schema.User);
243
+ const stateModule = getStateModule(app);
244
+
245
+ let stateChangeCount = 0;
246
+ const unsubscribe = stateModule.onStateChange(docRef, () => {
247
+ stateChangeCount++;
248
+ });
249
+
250
+ await new Promise(resolve => setTimeout(resolve, 10));
251
+ const initialCount = stateChangeCount;
252
+
253
+ const userId1 = "user1" as RecordId;
254
+ const userId2 = "user2" as RecordId;
255
+
256
+ await collection.set(userId1, { email: "alice@example.com", id: "user1", name: "Alice" });
257
+ await collection.set(userId2, { email: "bob@example.com", id: "user2", name: "Bob" });
258
+
259
+ await new Promise(resolve => setTimeout(resolve, 10));
260
+ expect(stateChangeCount - initialCount).toBe(2);
261
+
262
+ const record1 = collection.get(userId1)!;
263
+ const record2 = collection.get(userId2)!;
264
+
265
+ const snapshot1 = await record1.getSnapshot();
266
+ const snapshot2 = await record2.getSnapshot();
267
+
268
+ expect(snapshot1).toEqual({ email: "alice@example.com", id: "user1", name: "Alice" });
269
+ expect(snapshot2).toEqual({ email: "bob@example.com", id: "user2", name: "Bob" });
270
+
271
+ unsubscribe();
272
+ });
273
+
274
+ it("should handle empty transaction", () => {
275
+ let transactionRan = false;
276
+
277
+ docRef.withTransaction(() => {
278
+ transactionRan = true;
279
+ });
280
+
281
+ expect(transactionRan).toBe(true);
282
+ });
283
+
284
+ it("should pass description as origin to Y.js transaction", async () => {
285
+ const collection = docRef.getRecords(schema.User);
286
+ const documentService = app.getModule(DOCUMENT_SERVICE_MODULE_KEY);
287
+
288
+ const userId1 = "user1" as RecordId;
289
+ const userData = { email: "alice@example.com", id: "user1", name: "Alice" };
290
+
291
+ const description = {
292
+ data: userData,
293
+ model: schema.User,
294
+ };
295
+
296
+ let capturedOrigin: unknown = undefined;
297
+
298
+ const yDoc = (documentService as BaseYjsDocumentService)
299
+ .getYDocForTesting(docRef.id);
300
+
301
+ if (!yDoc) {
302
+ throw new Error("Document not found");
303
+ }
304
+
305
+ const updateHandler = (_update: Uint8Array, origin: unknown, _doc: Y.Doc) => {
306
+ capturedOrigin = origin;
307
+ };
308
+
309
+ yDoc.on("update", updateHandler);
310
+
311
+ docRef.withTransaction(() => {
312
+ void collection.set(userId1, userData);
313
+ }, description);
314
+
315
+ await new Promise(resolve => setTimeout(resolve, 10));
316
+
317
+ expect(capturedOrigin).toEqual(description);
318
+
319
+ yDoc.off("update", updateHandler);
320
+ });
321
+ });
@@ -46,8 +46,7 @@ export function createTestApp(
46
46
  logger: config.logger ?? consoleLogger({}),
47
47
  osdkClient: mockClient,
48
48
  remote: {
49
- packApiPath: "/pack/api",
50
- packWsPath: "/pack/ws",
49
+ packWsPath: "/api/v2/packSubscriptions",
51
50
  baseUrl: "http://localhost",
52
51
  fetchFn: fetch,
53
52
  ...config.remote,