@vrtmrz/livesync-commonlib 0.1.0-rc.0 → 0.1.0-rc.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 +98 -16
- package/dist/common/i18n.js +7 -7099
- package/dist/common/messages/combinedMessages.prod.d.ts +3 -0
- package/dist/common/messages/combinedMessages.prod.js +3 -0
- package/dist/common/messages/def.d.ts +1 -0
- package/dist/common/messagesJson/en.json +1 -0
- package/dist/common/models/setting.const.defaults.d.ts +19 -0
- package/dist/common/models/setting.const.defaults.js +20 -2
- package/dist/common/models/setting.lifecycle.d.ts +31 -0
- package/dist/common/models/setting.lifecycle.js +109 -0
- package/dist/common/types.d.ts +4 -2
- package/dist/common/types.js +16 -1
- package/dist/context.d.ts +1 -0
- package/dist/interfaces/Confirm.d.ts +8 -1
- package/dist/interfaces/DatabaseRebuilder.d.ts +12 -2
- package/dist/platform/node/index.d.ts +1 -0
- package/dist/platform/node/index.js +4 -0
- package/dist/platform/node/standardIo.d.ts +24 -0
- package/dist/platform/node/standardIo.js +39 -0
- package/dist/platform/standardIo.d.ts +19 -0
- package/dist/platform/standardIo.js +0 -0
- package/dist/remoteConfigurations.d.ts +9 -0
- package/dist/remoteConfigurations.js +14 -0
- package/dist/replication/trystero/LiveSyncTrysteroReplicator.d.ts +4 -1
- package/dist/replication/trystero/LiveSyncTrysteroReplicator.js +41 -26
- package/dist/replication/trystero/P2PReplicatorCore.d.ts +2 -6
- package/dist/replication/trystero/P2PReplicatorCore.js +16 -86
- package/dist/replication/trystero/TrysteroReplicator.d.ts +2 -1
- package/dist/replication/trystero/TrysteroReplicator.js +10 -4
- package/dist/replication/trystero/TrysteroReplicatorP2PServer.d.ts +4 -5
- package/dist/replication/trystero/TrysteroReplicatorP2PServer.js +22 -30
- package/dist/replication/trystero/UseP2PReplicatorResult.d.ts +10 -2
- package/dist/replication/trystero/addP2PEventHandlers.d.ts +4 -2
- package/dist/replication/trystero/addP2PEventHandlers.js +8 -6
- package/dist/replication/trystero/types.d.ts +2 -0
- package/dist/replication/trystero/useP2PReplicatorCommands.d.ts +1 -1
- package/dist/replication/trystero/useP2PReplicatorCommands.js +3 -1
- package/dist/replication/trystero/useP2PReplicatorFeature.js +1 -1
- package/dist/rpc/RpcRoom.d.ts +1 -1
- package/dist/rpc/RpcRoom.js +22 -16
- package/dist/rpc/transports/TrysteroTransport.d.ts +2 -0
- package/dist/rpc/transports/TrysteroTransport.js +24 -17
- package/dist/rpc/transports/trysteroRoomEvents.d.ts +14 -0
- package/dist/rpc/transports/trysteroRoomEvents.js +34 -0
- package/dist/serviceFeatures/remoteConfig.d.ts +37 -1
- package/dist/serviceFeatures/remoteConfig.js +90 -0
- package/dist/serviceModules/Rebuilder.d.ts +3 -2
- package/dist/serviceModules/Rebuilder.js +21 -9
- package/dist/services/base/IService.d.ts +12 -1
- package/dist/services/base/ReplicationService.d.ts +3 -1
- package/dist/services/base/ReplicationService.js +6 -1
- package/dist/services/base/SettingService.d.ts +14 -1
- package/dist/services/base/SettingService.js +35 -12
- package/dist/services/implements/headless/HeadlessAPIService.d.ts +1 -1
- package/dist/services/implements/headless/HeadlessAPIService.js +1 -1
- package/dist/services/implements/injectable/InjectableTweakValueService.d.ts +3 -3
- package/dist/settings.d.ts +10 -0
- package/dist/settings.js +32 -0
- package/dist/worker/bgWorker.js +1 -1
- package/docs/development.md +77 -2
- package/docs/p2p-transport-lifecycle.md +52 -0
- package/docs/platform-standard-io.md +44 -0
- package/docs/proven-in-use.md +55 -0
- package/docs/releasing.md +9 -5
- package/docs/remote-configurations.md +63 -0
- package/docs/settings-lifecycle.md +60 -0
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -1,48 +1,130 @@
|
|
|
1
1
|
# Self-hosted LiveSync Commonlib
|
|
2
2
|
|
|
3
|
-
Commonlib
|
|
3
|
+
Commonlib is the ESM package which provides shared data, storage, replication, host-context, and RPC primitives for Self-hosted LiveSync, its CLI, Webapp, and WebPeer.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This package is primarily for maintainers of those clients and for integrations which deliberately reuse a reviewed Commonlib contract. It is not yet a general-purpose LiveSync SDK: the package does not provide a stable end-to-end client factory or own host UI, permissions, credentials, process lifecycle, or application persistence.
|
|
6
|
+
|
|
7
|
+
> [!IMPORTANT]
|
|
8
|
+
> **Package migration in progress.** Commonlib is moving from a source-directory and Git-submodule dependency to a compiled npm package as part of Self-hosted LiveSync's Community directory review, reusable package boundary, and 1.0 preparation work.
|
|
9
|
+
>
|
|
10
|
+
> Existing contributions remain welcome and the normal contribution process has not changed. Pull requests which touch packaging, host lifecycle, or compatibility boundaries may need coordination or a rebase while this boundary settles; maintainers will identify affected work rather than asking contributors to adopt a new process pre-emptively.
|
|
11
|
+
|
|
12
|
+
## Status and versioning
|
|
13
|
+
|
|
14
|
+
The package is pre-1.0. Pin an exact reviewed version, and review changes before upgrading. An entry in the package export map means that the import is deliberate and package-tested; it does not make every semantic detail of that entry a final 1.0 guarantee.
|
|
15
|
+
|
|
16
|
+
Treat every `compat/*` subpath as a migration-only interface. A source-directory import, Git submodule, or consumer-defined TypeScript alias is not a supported package boundary.
|
|
17
|
+
|
|
18
|
+
The package is ESM-only and declares Node 20 or later. Browser entry points are built with browser conditions, but the host remains responsible for checking the availability of browser capabilities such as the File System Access API.
|
|
6
19
|
|
|
7
20
|
## Package entry points
|
|
8
21
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
| Entry point | Intended use | Current contract status |
|
|
23
|
+
| -------------------------------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `@vrtmrz/livesync-commonlib` | `DirectFileManipulator` for integrations which access CouchDB directly | Deliberately small, but its high-level lifecycle and file-operation semantics are not final |
|
|
25
|
+
| `@vrtmrz/livesync-commonlib/context` | Instance-owned events, translation injection, and host-neutral standard-I/O types | Focused, package-tested pre-1.0 contract |
|
|
26
|
+
| `@vrtmrz/livesync-commonlib/browser` | Rooted File System Access API storage | Focused, package-tested pre-1.0 contract |
|
|
27
|
+
| `@vrtmrz/livesync-commonlib/node` | Rooted Node storage, Node standard I/O, and selected Node capabilities | Focused platform entry; some convenience exports still require 1.0 classification |
|
|
28
|
+
| `@vrtmrz/livesync-commonlib/rpc` | Transport-neutral RPC rooms, sessions, errors, and the PouchDB RPC bridge | Deliberate export, but its 1.0 stability status is not yet accepted |
|
|
29
|
+
| `@vrtmrz/livesync-commonlib/remote-configurations` | Multiple-remote profile creation, naming, and selection | Focused, package-tested pre-1.0 contract |
|
|
30
|
+
| `@vrtmrz/livesync-commonlib/settings` | New-Vault defaults, stored-setting fallbacks, and settings migration results | Focused, package-tested pre-1.0 contract |
|
|
31
|
+
| `@vrtmrz/livesync-commonlib/compat/*` | Exact legacy imports still required by existing clients | Migration-only; paths may be removed as consumers migrate |
|
|
32
|
+
| `@vrtmrz/livesync-commonlib/package.json` | Package metadata for tooling | Metadata export, not a runtime API |
|
|
15
33
|
|
|
16
34
|
Import only the entry point required by the current runtime. Browser code must not import the Node entry.
|
|
17
35
|
|
|
36
|
+
TODO: decide whether the Node entry's `fs`, `fsPromises`, `path`, `os`, `readline`, URL, and built-in-module convenience exports belong in the 1.0 public contract or should move behind compatibility paths.
|
|
37
|
+
|
|
38
|
+
TODO: decide whether the draft RPC protocol and PouchDB bridge are stable 1.0 contracts, remain explicitly experimental, or move to a separately versioned package. Until that decision, pin the exact package version when consuming the RPC entry.
|
|
39
|
+
|
|
40
|
+
## Host context and initialisation
|
|
41
|
+
|
|
42
|
+
One service context belongs to one independently composed Commonlib client. It owns that client's event hub and translator. Creating a context without options creates a fresh event hub and uses a translator which returns message keys unchanged:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import {
|
|
46
|
+
createLiveSyncEventHub,
|
|
47
|
+
createServiceContext,
|
|
48
|
+
type MessageTranslator,
|
|
49
|
+
} from "@vrtmrz/livesync-commonlib/context";
|
|
50
|
+
|
|
51
|
+
const events = createLiveSyncEventHub();
|
|
52
|
+
declare const hostTranslations: { translate: MessageTranslator };
|
|
53
|
+
const translate: MessageTranslator = (key, parameters) => {
|
|
54
|
+
return hostTranslations.translate(key, parameters);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const context = createServiceContext({ events, translate });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The host may instead extend `ServiceContext` with platform-specific capabilities. Pass the same context instance to every service in one composition so that they share the intended event channel and translator. Create a separate context for a client which must be isolated.
|
|
61
|
+
|
|
62
|
+
Context construction does not select storage, connect to a database, start replication, acquire browser permission, or install process-wide state. The host separately owns platform-resource acquisition, adapter construction, and the lifecycle order of its particular service composition.
|
|
63
|
+
|
|
64
|
+
TODO: define a reviewed high-level composition factory and its initialisation, readiness, error, and disposal contract. Until that exists, service implementations exposed under `compat/*` retain their owning client's lifecycle rather than becoming a general public composition API.
|
|
65
|
+
|
|
18
66
|
## Rooted storage
|
|
19
67
|
|
|
20
68
|
Both platform storage factories receive an existing root from the host. They never select a directory, request browser permission, infer a process directory, or persist a handle.
|
|
21
69
|
|
|
22
70
|
```ts
|
|
23
|
-
import { createFileSystemAccessStorage } from
|
|
71
|
+
import { createFileSystemAccessStorage } from "@vrtmrz/livesync-commonlib/browser";
|
|
24
72
|
|
|
25
73
|
declare const authorisedRoot: FileSystemDirectoryHandle;
|
|
26
74
|
const storage = createFileSystemAccessStorage({ rootHandle: authorisedRoot });
|
|
27
|
-
await storage.write(
|
|
75
|
+
await storage.write("notes/example.md", "# Example");
|
|
28
76
|
```
|
|
29
77
|
|
|
30
78
|
```ts
|
|
31
|
-
import { createNodeStorage } from
|
|
79
|
+
import { createNodeStorage } from "@vrtmrz/livesync-commonlib/node";
|
|
32
80
|
|
|
33
|
-
const storage = createNodeStorage({ rootPath:
|
|
34
|
-
await storage.write(
|
|
81
|
+
const storage = createNodeStorage({ rootPath: "/srv/livesync" });
|
|
82
|
+
await storage.write("notes/example.md", "# Example");
|
|
35
83
|
```
|
|
36
84
|
|
|
37
85
|
See [the platform storage contract](docs/platform-storage.md) for path, ownership, and permission details.
|
|
38
86
|
|
|
39
|
-
##
|
|
87
|
+
## Standard input and output
|
|
88
|
+
|
|
89
|
+
CLI hosts can inject the platform-neutral `StandardIo` contract from the context entry. The Node entry supplies the concrete stream adapter. This keeps command input and protocol output testable without treating logging or process lifecycle as standard I/O.
|
|
40
90
|
|
|
41
|
-
|
|
91
|
+
```ts
|
|
92
|
+
import type { StandardIo } from "@vrtmrz/livesync-commonlib/context";
|
|
93
|
+
import { createNodeStandardIo } from "@vrtmrz/livesync-commonlib/node";
|
|
94
|
+
|
|
95
|
+
const standardIo: StandardIo = createNodeStandardIo();
|
|
96
|
+
standardIo.writeStdout("ready\n");
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
See [the standard-I/O contract](docs/platform-standard-io.md) for host composition and test-double examples.
|
|
100
|
+
|
|
101
|
+
## Settings lifecycle
|
|
102
|
+
|
|
103
|
+
New-Vault recommendations are deliberately separate from the conservative values used to complete older stored settings. The focused settings entry also reports migrations and safety-review requirements without changing a user's synchronisation choices or persisting a device-local acknowledgement.
|
|
104
|
+
|
|
105
|
+
See [the settings lifecycle guide](docs/settings-lifecycle.md) before initialising, importing, resetting, or migrating settings.
|
|
106
|
+
|
|
107
|
+
## Remote connection profiles
|
|
108
|
+
|
|
109
|
+
New profile-management code can create or update a CouchDB, Object Storage, or P2P connection through the focused remote-configurations entry. Profile IDs provide identity, display names remain editable presentation, and the active selection is explicit. Older flat connection fields remain a runtime projection and an import-compatibility boundary rather than the preferred persistence model.
|
|
110
|
+
|
|
111
|
+
See [the remote configuration profile guide](docs/remote-configurations.md) for creation, activation, P2P selection, legacy import, persistence, and verification responsibilities.
|
|
112
|
+
|
|
113
|
+
## Contract scope
|
|
114
|
+
|
|
115
|
+
The package is currently an infrastructure and compatibility boundary. The context, rooted-storage, and standard-I/O result contracts have focused cross-platform or instance-isolation tests. Platform details which cannot be shared, such as file timestamp fidelity and browser permission handling, remain host concerns and are documented separately.
|
|
116
|
+
|
|
117
|
+
`DirectFileManipulator` is useful for existing integrations, but its enumeration, watch ownership, failure, conflict, concurrency, readiness, and disposal semantics are not yet a stable high-level SDK contract.
|
|
42
118
|
|
|
43
119
|
TODO: define and document the first high-level client façade before declaring list, get, put, delete, watch, and close behaviour stable.
|
|
44
120
|
|
|
45
|
-
|
|
121
|
+
Package developers should read [the developer guide](docs/development.md). The focused contracts are described in [the storage guide](docs/platform-storage.md), [the standard-I/O guide](docs/platform-standard-io.md), [the settings lifecycle guide](docs/settings-lifecycle.md), and [the remote configuration profile guide](docs/remote-configurations.md).
|
|
122
|
+
|
|
123
|
+
## Proven in maintained hosts
|
|
124
|
+
|
|
125
|
+
The package boundary is exercised by Self-hosted LiveSync's Obsidian plug-in, CLI, Webapp, and WebPeer compositions. Their validation is not uniform: the Obsidian plug-in and CLI have the strongest real-runtime and cross-host evidence, while the Webapp and WebPeer currently provide focused adapter, type-check, and build evidence.
|
|
126
|
+
|
|
127
|
+
See [Proven in maintained hosts](docs/proven-in-use.md) for the actual composition points, downstream tests, and remaining limits. The examples deliberately separate focused public entries which a new consumer may copy from `compat/*` imports which exist to migrate the current application.
|
|
46
128
|
|
|
47
129
|
## Licence
|
|
48
130
|
|