@palantir/pack.state.core 0.0.1-beta.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 (63) hide show
  1. package/.turbo/turbo-lint.log +4 -0
  2. package/.turbo/turbo-transpileBrowser.log +5 -0
  3. package/.turbo/turbo-transpileCjs.log +5 -0
  4. package/.turbo/turbo-transpileEsm.log +5 -0
  5. package/.turbo/turbo-transpileTypes.log +5 -0
  6. package/.turbo/turbo-typecheck.log +4 -0
  7. package/LICENSE.txt +13 -0
  8. package/README.md +55 -0
  9. package/build/browser/index.js +1257 -0
  10. package/build/browser/index.js.map +1 -0
  11. package/build/cjs/index.cjs +1298 -0
  12. package/build/cjs/index.cjs.map +1 -0
  13. package/build/cjs/index.d.cts +272 -0
  14. package/build/esm/index.js +1257 -0
  15. package/build/esm/index.js.map +1 -0
  16. package/build/types/DocumentServiceModule.d.ts +6 -0
  17. package/build/types/DocumentServiceModule.d.ts.map +1 -0
  18. package/build/types/__tests__/DocumentStatusTracking.test.d.ts +1 -0
  19. package/build/types/__tests__/DocumentStatusTracking.test.d.ts.map +1 -0
  20. package/build/types/__tests__/RefStability.test.d.ts +1 -0
  21. package/build/types/__tests__/RefStability.test.d.ts.map +1 -0
  22. package/build/types/__tests__/StateModule.integration.test.d.ts +1 -0
  23. package/build/types/__tests__/StateModule.integration.test.d.ts.map +1 -0
  24. package/build/types/__tests__/testUtils.d.ts +7 -0
  25. package/build/types/__tests__/testUtils.d.ts.map +1 -0
  26. package/build/types/index.d.ts +11 -0
  27. package/build/types/index.d.ts.map +1 -0
  28. package/build/types/service/BaseYjsDocumentService.d.ts +155 -0
  29. package/build/types/service/BaseYjsDocumentService.d.ts.map +1 -0
  30. package/build/types/service/InMemoryDocumentService.d.ts +12 -0
  31. package/build/types/service/InMemoryDocumentService.d.ts.map +1 -0
  32. package/build/types/service/YjsSchemaMapper.d.ts +9 -0
  33. package/build/types/service/YjsSchemaMapper.d.ts.map +1 -0
  34. package/build/types/types/DocumentRefImpl.d.ts +5 -0
  35. package/build/types/types/DocumentRefImpl.d.ts.map +1 -0
  36. package/build/types/types/DocumentService.d.ts +62 -0
  37. package/build/types/types/DocumentService.d.ts.map +1 -0
  38. package/build/types/types/DocumentServiceConfig.d.ts +5 -0
  39. package/build/types/types/DocumentServiceConfig.d.ts.map +1 -0
  40. package/build/types/types/RecordCollectionRefImpl.d.ts +5 -0
  41. package/build/types/types/RecordCollectionRefImpl.d.ts.map +1 -0
  42. package/build/types/types/RecordRefImpl.d.ts +5 -0
  43. package/build/types/types/RecordRefImpl.d.ts.map +1 -0
  44. package/build/types/types/StateModule.d.ts +59 -0
  45. package/build/types/types/StateModule.d.ts.map +1 -0
  46. package/package.json +71 -0
  47. package/src/DocumentServiceModule.ts +53 -0
  48. package/src/__tests__/DocumentStatusTracking.test.ts +229 -0
  49. package/src/__tests__/RefStability.test.ts +441 -0
  50. package/src/__tests__/StateModule.integration.test.ts +1187 -0
  51. package/src/__tests__/testUtils.ts +106 -0
  52. package/src/index.ts +38 -0
  53. package/src/service/BaseYjsDocumentService.ts +1277 -0
  54. package/src/service/InMemoryDocumentService.ts +162 -0
  55. package/src/service/YjsSchemaMapper.ts +194 -0
  56. package/src/types/DocumentRefImpl.ts +98 -0
  57. package/src/types/DocumentService.ts +210 -0
  58. package/src/types/DocumentServiceConfig.ts +22 -0
  59. package/src/types/RecordCollectionRefImpl.ts +124 -0
  60. package/src/types/RecordRefImpl.ts +106 -0
  61. package/src/types/StateModule.ts +329 -0
  62. package/tsconfig.json +21 -0
  63. package/vitest.config.mjs +26 -0
@@ -0,0 +1,4 @@
1
+
2
+ > @palantir/pack.state.core@0.0.1-beta.1 lint /home/runner/work/pack/pack/packages/state/core
3
+ > eslint ./src ; dprint check --config $(find-up dprint.json) --allow-no-files
4
+
@@ -0,0 +1,5 @@
1
+
2
+ > @palantir/pack.state.core@0.0.1-beta.1 transpileBrowser /home/runner/work/pack/pack/packages/state/core
3
+ > monorepo-transpile -f esm -m bundle -t browser
4
+
5
+ 👍
@@ -0,0 +1,5 @@
1
+
2
+ > @palantir/pack.state.core@0.0.1-beta.1 transpileCjs /home/runner/work/pack/pack/packages/state/core
3
+ > monorepo-transpile -f cjs -m bundle -t node
4
+
5
+ 👍
@@ -0,0 +1,5 @@
1
+
2
+ > @palantir/pack.state.core@0.0.1-beta.1 transpileEsm /home/runner/work/pack/pack/packages/state/core
3
+ > monorepo-transpile -f esm -m bundle -t node
4
+
5
+ 👍
@@ -0,0 +1,5 @@
1
+
2
+ > @palantir/pack.state.core@0.0.1-beta.1 transpileTypes /home/runner/work/pack/pack/packages/state/core
3
+ > monorepo-transpile -f esm -m types -t node
4
+
5
+ 👍
@@ -0,0 +1,4 @@
1
+
2
+ > @palantir/pack.state.core@0.0.1-beta.1 typecheck /home/runner/work/pack/pack/packages/state/core
3
+ > tsc --noEmit --emitDeclarationOnly false
4
+
package/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2025 Palantir Technologies, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # @palantir/pack.state.core
2
+
3
+ Real-time state management system.
4
+
5
+ ## Overview
6
+
7
+ This package provides the core state management infrastructure for PACK, built around the concept of Documents that can be synchronized in real-time across multiple clients.
8
+
9
+ `StateModule` via `app.state` is the main public interface.
10
+
11
+ ## Key Concepts
12
+
13
+ ### Terminology
14
+
15
+ > TODO: These need another pass for consistent naming, there's a confusing interchange of Schema & Model between document & record layer.
16
+
17
+ - `Document` - An instance of a document, as loaded by id. A document is a collection of `Records`.
18
+ - `DocumentType` - The backend-registered metadata describing app-specific archetypes of Documents.
19
+ - `DocumentSchema` - Describes the Record types in a Document Type. Used internally at runtime for type inspection, validation, and read/writes to underlying document implementation.
20
+ - `Model<Data, Schema>` - Effectively a _Record Type_ - A runtime type unifying `ModelData` and `ModelSchema`.
21
+ - via sdk generators:
22
+ - `DocumentModel` - The runtime definition of the document type, ie the `Model`s that make up the document.
23
+ - `ModelData` - The user-friendly type for a record. This is the type that app code uses.
24
+ - `ModelSchema` - The runtime definition of the record. Generally for internal use only at this stage.
25
+ - `Record` - An _instance_ of an object stored in the document. Note this is not a typescript `Record<K,V>`, it is an immutable object corresponding to the defined `Model`. This is the primary concept that apps use for state management.
26
+ - `RecordCollection` - All `Record`s are stored in a document internally in their own (per-`Model`) collection. This means all model types marked as `primary` in the schema are accessible with a map-like interface.
27
+
28
+ ### Reference Types
29
+
30
+ Reference (or _ref_) objects provide the main public api for interacting with documents, providing a clean, async API on top of the DocumentSchema/Models.
31
+
32
+ - `DocumentRef<DocumentSchema>` - References to documents with validation utilities
33
+ - `RecordCollectionRef<ModelSchema>` - References to collections of records
34
+ - `RecordRef<ModelSchema>` - References to individual records within documents
35
+
36
+ > **Note:** Refs are created immediately though the underlying data may not be loaded. DocumentService implementations won't load/subscribe to data unless there are
37
+ > subscriptions on the document or collection/records within the document.
38
+
39
+ > **Note:** All ref objects are stable, deduplicated automatically via weak ref caches. This means they are suitable for use as keys in maps, cache deps in react etc, as long as the application holds a ref it will never receive a duplicate.
40
+
41
+ ## Internal Notes
42
+
43
+ ### Document Services
44
+
45
+ DocumentService is an internal service used to implement connections to a backend.
46
+
47
+ - `DocumentService` - Abstract interface for document state management
48
+ - `BaseYjsDocumentService` - Base implementation using Yjs for real-time collaboration (_TODO:_ This will move out of state-core)
49
+ - `createInMemoryDocumentServiceConfig()` - Configuration for in-memory document service, useful for testing
50
+
51
+ ## Internal Development Notes
52
+
53
+ - Use Symbols for meta fields on objects allows for iteration of keys without meta fields.
54
+ - Records should always be treated as having high cardinality. So prefer iterative approach to working with RecordCollections.
55
+ - Use method type interfaces / classes. Eg we do not want to instantiate bound methods for every record.