@recordtimelabel/core 0.1.0 → 0.1.2
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/README.md +75 -43
- package/package.json +20 -20
- package/src/index.js +1627 -569
package/README.md
CHANGED
|
@@ -1,55 +1,87 @@
|
|
|
1
|
-
# @recordtimelabel/core
|
|
2
|
-
|
|
3
|
-
Shared RecordTimeLabel data model, normalization, merge logic, operation reducer, and sync engine.
|
|
4
|
-
|
|
5
|
-
## Scope
|
|
6
|
-
|
|
7
|
-
This package is intentionally platform-neutral. It must not import React, Firebase, Chrome extension APIs, Electron APIs, or app-specific UI code.
|
|
8
|
-
|
|
9
|
-
Current consumers:
|
|
10
|
-
|
|
11
|
-
- `D:\Programming\RecordTimeLabel`
|
|
12
|
-
- `D:\Programming\YouTwitchDownloader`
|
|
13
|
-
|
|
14
|
-
During local development
|
|
1
|
+
# @recordtimelabel/core
|
|
2
|
+
|
|
3
|
+
Shared RecordTimeLabel data model, normalization, merge logic, operation reducer, and sync engine.
|
|
4
|
+
|
|
5
|
+
## Scope
|
|
6
|
+
|
|
7
|
+
This package is intentionally platform-neutral. It must not import React, Firebase, Chrome extension APIs, Electron APIs, or app-specific UI code.
|
|
8
|
+
|
|
9
|
+
Current consumers:
|
|
10
|
+
|
|
11
|
+
- `D:\Programming\RecordTimeLabel`
|
|
12
|
+
- `D:\Programming\YouTwitchDownloader`
|
|
13
|
+
|
|
14
|
+
During local development an app can consume a sibling checkout with:
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
"@recordtimelabel/core": "file:../recordtimelabel-core"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
For release builds, consume a fixed npm package, git tag, or private registry version so builds do not depend on a sibling folder path. The current release candidate is:
|
|
15
21
|
|
|
16
22
|
```json
|
|
17
|
-
"@recordtimelabel/core": "
|
|
23
|
+
"@recordtimelabel/core": "0.1.2"
|
|
18
24
|
```
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- `normalizeState(input)`
|
|
25
|
-
- `normalizeRecords(records, options)`
|
|
25
|
+
|
|
26
|
+
## Public API
|
|
27
|
+
|
|
28
|
+
- `normalizeState(input)`
|
|
29
|
+
- `normalizeRecords(records, options)`
|
|
26
30
|
- `mergeLocalRemote({ localState, remoteState, pendingOps, clientId, now })`
|
|
27
31
|
- `applyOperation(state, operation)`
|
|
32
|
+
- `applyRecordTimeLabelOperation(state, operation)`
|
|
28
33
|
- `createSyncEngine({ storageAdapter, cloudAdapter, clientId, clock, logger })`
|
|
34
|
+
- `createRecordTimeLabelController({ storageAdapter, cloudAdapter, clientId, settingKeys, clock, logger })`
|
|
35
|
+
- `buildRecordTimeLabelSyncPayload({ data, previousCloudData, pendingOps, syncMode, clientId, now })`
|
|
36
|
+
- `buildSyncPayloadWithOperations({ data, previousCloudData, pendingOps, syncMode, clientId, now })`
|
|
37
|
+
- `flushPendingOperations({ operations, storageAdapter, cloudAdapter, clientId, now })`
|
|
38
|
+
- `mergeRemoteStateIntoLocal({ localData, remoteData, pendingOps, settingKeys, clientId, now })`
|
|
39
|
+
- `buildLocalStateFromStorage(data, options)`
|
|
40
|
+
- `buildStoragePatchFromState(state, options)`
|
|
41
|
+
- `buildFirestoreV1UserPatch(state, options)`
|
|
42
|
+
- `buildFirestoreV2LogicalPaths(userId)`
|
|
43
|
+
- `buildFirestoreV2DocumentsFromState(state, options)`
|
|
44
|
+
- `buildStateFromFirestoreV2Documents(documents, options)`
|
|
45
|
+
- `hasMeaningfulRecordTimeLabelCloudState(data, options)`
|
|
46
|
+
- `buildRecordTimeLabelContentFingerprint(data)`
|
|
47
|
+
- `buildMigratedRecordTimeLabelV2State(legacyState, options)`
|
|
48
|
+
- `RECORD_TIMELABEL_CLOUD_SCHEMAS`
|
|
49
|
+
- `RECORD_TIMELABEL_SYNC_MODES`
|
|
29
50
|
- `createOperation(type, payload, options)`
|
|
30
51
|
- `OPERATION_TYPES`
|
|
52
|
+
|
|
53
|
+
## Firestore v1 Compatibility
|
|
54
|
+
|
|
55
|
+
Phase 1 keeps the existing `users/{uid}` document shape:
|
|
56
|
+
|
|
57
|
+
- `folders`
|
|
58
|
+
- `records`
|
|
59
|
+
- `groupOrder`
|
|
60
|
+
- `folderOrder`
|
|
61
|
+
- `expandedGroups`
|
|
62
|
+
- `settings`
|
|
63
|
+
|
|
64
|
+
The core also normalizes and preserves these compatibility metadata fields:
|
|
65
|
+
|
|
66
|
+
- `rtlSyncMeta`
|
|
67
|
+
- `deletedRecordTombstones`
|
|
68
|
+
- `deletedFolderTombstones`
|
|
69
|
+
|
|
70
|
+
Deletion must be represented by tombstones or operations. Do not reintroduce the old heuristic that treats "local exists but cloud missing for more than five minutes" as deletion.
|
|
31
71
|
|
|
32
|
-
## Firestore
|
|
33
|
-
|
|
34
|
-
Phase 1 keeps the existing `users/{uid}` document shape:
|
|
35
|
-
|
|
36
|
-
- `folders`
|
|
37
|
-
- `records`
|
|
38
|
-
- `groupOrder`
|
|
39
|
-
- `folderOrder`
|
|
40
|
-
- `expandedGroups`
|
|
41
|
-
- `settings`
|
|
42
|
-
|
|
43
|
-
The core also normalizes and preserves these compatibility metadata fields:
|
|
44
|
-
|
|
45
|
-
- `rtlSyncMeta`
|
|
46
|
-
- `deletedRecordTombstones`
|
|
47
|
-
- `deletedFolderTombstones`
|
|
72
|
+
## Firestore v2 Preparation
|
|
48
73
|
|
|
49
|
-
|
|
74
|
+
The package exposes platform-neutral v2 document helpers so app adapters can share the same record/folder/settings/ops shape before wiring Firebase SDK or REST calls:
|
|
50
75
|
|
|
51
|
-
|
|
76
|
+
- root document `users/{uid}/recordTimeLabel/main`: settings, order arrays, tombstones, and sync metadata
|
|
77
|
+
- `users/{uid}/recordTimeLabel/main/records/{recordId}`: flattened per-record documents with `folderId`
|
|
78
|
+
- `users/{uid}/recordTimeLabel/main/folders/{folderId}`: per-folder documents
|
|
79
|
+
- `users/{uid}/recordTimeLabel/main/ops/{opId}`: pending operation documents
|
|
52
80
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
81
|
+
These helpers do not import Firebase and do not perform network writes.
|
|
82
|
+
|
|
83
|
+
## Test
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm test
|
|
87
|
+
```
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@recordtimelabel/core",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "Shared RecordTimeLabel data model, merge logic, operations, and sync engine.",
|
|
6
|
-
"main": "./src/index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": "./src/index.js"
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"test": "node --test tests/*.test.mjs"
|
|
12
|
-
},
|
|
13
|
-
"engines": {
|
|
14
|
-
"node": ">=18.0.0"
|
|
15
|
-
},
|
|
16
|
-
"files": [
|
|
17
|
-
"src",
|
|
18
|
-
"README.md"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@recordtimelabel/core",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Shared RecordTimeLabel data model, merge logic, operations, and sync engine.",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "node --test tests/*.test.mjs"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18.0.0"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src",
|
|
18
|
+
"README.md"
|
|
19
|
+
]
|
|
20
|
+
}
|