@palantir/pack.state.demo 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-transpileBrowser.log +6 -0
- package/.turbo/turbo-transpileCjs.log +6 -0
- package/.turbo/turbo-transpileEsm.log +6 -0
- package/.turbo/turbo-transpileTypes.log +5 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CHANGELOG.md +39 -0
- package/LICENSE.txt +13 -0
- package/README.md +110 -0
- package/build/browser/index.js +545 -0
- package/build/browser/index.js.map +1 -0
- package/build/cjs/index.cjs +570 -0
- package/build/cjs/index.cjs.map +1 -0
- package/build/cjs/index.d.cts +88 -0
- package/build/esm/index.js +545 -0
- package/build/esm/index.js.map +1 -0
- package/build/types/DemoDocumentService.d.ts +40 -0
- package/build/types/DemoDocumentService.d.ts.map +1 -0
- package/build/types/MetadataStore.d.ts +20 -0
- package/build/types/MetadataStore.d.ts.map +1 -0
- package/build/types/PresenceManager.d.ts +27 -0
- package/build/types/PresenceManager.d.ts.map +1 -0
- package/build/types/__tests__/DemoDocumentService.test.d.ts +1 -0
- package/build/types/__tests__/DemoDocumentService.test.d.ts.map +1 -0
- package/build/types/index.d.ts +7 -0
- package/build/types/index.d.ts.map +1 -0
- package/package.json +74 -0
- package/src/DemoDocumentService.ts +414 -0
- package/src/MetadataStore.ts +100 -0
- package/src/PresenceManager.ts +323 -0
- package/src/__tests__/DemoDocumentService.test.ts +414 -0
- package/src/index.ts +33 -0
- package/tsconfig.json +21 -0
- package/vitest.config.mjs +28 -0
- package/vitest.setup.ts +1 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
> @palantir/pack.state.demo@0.1.1 transpileBrowser /home/runner/work/pack/pack/packages/state/demo
|
|
3
|
+
> monorepo-transpile -f esm -m bundle -t browser
|
|
4
|
+
|
|
5
|
+
[baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
|
|
6
|
+
👍
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
> @palantir/pack.state.demo@0.1.1 transpileCjs /home/runner/work/pack/pack/packages/state/demo
|
|
3
|
+
> monorepo-transpile -f cjs -m bundle -t node
|
|
4
|
+
|
|
5
|
+
[baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
|
|
6
|
+
👍
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
> @palantir/pack.state.demo@0.1.1 transpileEsm /home/runner/work/pack/pack/packages/state/demo
|
|
3
|
+
> monorepo-transpile -f esm -m bundle -t node
|
|
4
|
+
|
|
5
|
+
[baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
|
|
6
|
+
👍
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @palantir/pack.state.demo
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5120719: Update dependency ranges
|
|
8
|
+
- Updated dependencies [5120719]
|
|
9
|
+
- @palantir/pack.document-schema.model-types@0.3.1
|
|
10
|
+
- @palantir/pack.state.core@0.3.1
|
|
11
|
+
- @palantir/pack.core@0.2.2
|
|
12
|
+
|
|
13
|
+
## 0.1.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- 15f7f90: fix search api to match required types and add search pagination
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 319660b: Fix demo client id new generation on page reloads
|
|
22
|
+
- 9f45b8e: Improve document creation API to separate create request from raw API types
|
|
23
|
+
- 887cab4: Fix demo service activity and presence implementation
|
|
24
|
+
- 87f1e63: Support for demo mode (offline) document services
|
|
25
|
+
- e6e40f7: Improve demo mode services and add offline demo oauth implementation
|
|
26
|
+
- 4a44875: Remove bun-specific scripts and dependency
|
|
27
|
+
- Updated dependencies [9f45b8e]
|
|
28
|
+
- Updated dependencies [571578c]
|
|
29
|
+
- Updated dependencies [862daf6]
|
|
30
|
+
- Updated dependencies [87f1e63]
|
|
31
|
+
- Updated dependencies [e6e40f7]
|
|
32
|
+
- Updated dependencies [15f7f90]
|
|
33
|
+
- Updated dependencies [7ee55de]
|
|
34
|
+
- Updated dependencies [4a44875]
|
|
35
|
+
- Updated dependencies [8057223]
|
|
36
|
+
- Updated dependencies [19b8f5b]
|
|
37
|
+
- @palantir/pack.document-schema.model-types@0.3.0
|
|
38
|
+
- @palantir/pack.state.core@0.3.0
|
|
39
|
+
- @palantir/pack.core@0.2.1
|
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,110 @@
|
|
|
1
|
+
# @palantir/pack.state.demo
|
|
2
|
+
|
|
3
|
+
Offline demo implementation of `DocumentService` for local development and testing.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
This package provides a browser-based, offline-capable document service implementation that:
|
|
8
|
+
|
|
9
|
+
- Persists documents locally using IndexedDB (via y-indexeddb)
|
|
10
|
+
- Synchronizes document changes across browser tabs using BroadcastChannel API
|
|
11
|
+
- Implements presence and activity tracking across tabs
|
|
12
|
+
- Requires no backend server or network connectivity
|
|
13
|
+
|
|
14
|
+
This is intended for:
|
|
15
|
+
|
|
16
|
+
- Local development without Foundry backend
|
|
17
|
+
- Testing React components and pack layers in isolation
|
|
18
|
+
- Demos and prototypes
|
|
19
|
+
- Unit and integration testing
|
|
20
|
+
|
|
21
|
+
## Architecture
|
|
22
|
+
|
|
23
|
+
### Two-tier Persistence
|
|
24
|
+
|
|
25
|
+
1. **Metadata Store**: Single Y.Doc containing metadata for all documents
|
|
26
|
+
2. **Document Store**: Individual Y.Docs per document, each with its own IndexedDB persistence
|
|
27
|
+
|
|
28
|
+
### Cross-Tab Synchronization
|
|
29
|
+
|
|
30
|
+
- **Data Channels**: Y.js updates broadcast via BroadcastChannel for real-time sync
|
|
31
|
+
- **Presence Channels**: Heartbeat mechanism tracks active clients across tabs
|
|
32
|
+
- **Activity Broadcasting**: Custom presence data shared across all document subscribers
|
|
33
|
+
|
|
34
|
+
### Status Management
|
|
35
|
+
|
|
36
|
+
Documents transition through standard load and live states:
|
|
37
|
+
|
|
38
|
+
- Load: `UNLOADED` → `LOADING` → `LOADED`
|
|
39
|
+
- Live: `DISCONNECTED` → `CONNECTING` → `CONNECTED`
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { createPackApp } from "@palantir/pack.core";
|
|
45
|
+
import { createDemoDocumentServiceConfig } from "@palantir/pack.state.demo";
|
|
46
|
+
|
|
47
|
+
const app = createPackApp({
|
|
48
|
+
modules: [
|
|
49
|
+
createDemoDocumentServiceConfig({
|
|
50
|
+
dbPrefix: "my-app", // Optional, defaults to "pack-demo"
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Implementation Details
|
|
57
|
+
|
|
58
|
+
### BaseYjsDocumentService Extension
|
|
59
|
+
|
|
60
|
+
Extends `BaseYjsDocumentService` which handles:
|
|
61
|
+
|
|
62
|
+
- Y.Doc lifecycle and initialization
|
|
63
|
+
- Record CRUD operations
|
|
64
|
+
- Subscription management
|
|
65
|
+
- Change notifications
|
|
66
|
+
|
|
67
|
+
Demo implementation adds:
|
|
68
|
+
|
|
69
|
+
- IndexedDB persistence layer
|
|
70
|
+
- BroadcastChannel synchronization
|
|
71
|
+
- Presence heartbeat management
|
|
72
|
+
|
|
73
|
+
### Presence Heartbeat Protocol
|
|
74
|
+
|
|
75
|
+
Clients broadcast heartbeats every 5 seconds. The PresenceManager:
|
|
76
|
+
|
|
77
|
+
- Tracks all active clients by clientId
|
|
78
|
+
- Emits "arrive" events when new heartbeats appear
|
|
79
|
+
- Emits "depart" events when heartbeats go stale (>15s)
|
|
80
|
+
|
|
81
|
+
This provides automatic presence detection without explicit arrive/depart messages.
|
|
82
|
+
|
|
83
|
+
## Testing
|
|
84
|
+
|
|
85
|
+
Run tests with:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pnpm test
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Tests cover:
|
|
92
|
+
|
|
93
|
+
- Document creation and persistence across service instances
|
|
94
|
+
- Cross-tab synchronization (simulated with multiple service instances)
|
|
95
|
+
- Presence arrive/depart events
|
|
96
|
+
- Activity event broadcasting
|
|
97
|
+
- Status transition lifecycle
|
|
98
|
+
- Search functionality
|
|
99
|
+
|
|
100
|
+
## Limitations
|
|
101
|
+
|
|
102
|
+
- **Browser-only**: Requires IndexedDB and BroadcastChannel APIs
|
|
103
|
+
- **No conflict resolution**: Relies on Y.js CRDT for concurrent edits
|
|
104
|
+
- **No server sync**: Changes persist only in browser storage
|
|
105
|
+
- **No auth/security**: All documents accessible locally
|
|
106
|
+
- **Storage limits**: Subject to browser IndexedDB quotas
|
|
107
|
+
|
|
108
|
+
## Private Package
|
|
109
|
+
|
|
110
|
+
This package is marked as private and not published to npm. It's intended for internal development and testing workflows only.
|