@inkandswitch/patchwork-bootloader 0.4.3 → 0.5.0
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/CHANGELOG.md +29 -0
- package/dist/automerge-worker.js +533 -771
- package/dist/externals-list.d.ts +5 -0
- package/dist/externals-list.js +41 -0
- package/dist/externals.d.ts +14 -3
- package/dist/externals.js +50 -38
- package/dist/global.css +30 -0
- package/dist/module-loader.d.ts +0 -5
- package/dist/module-loader.js +0 -6
- package/dist/service-worker.js +178 -205
- package/dist/setup.d.ts +2 -1
- package/dist/setup.js +251 -375
- package/dist/sync-config.d.ts +1 -1
- package/dist/sync-config.js +3 -1
- package/package.json +15 -14
- package/src/automerge-worker.ts +634 -839
- package/src/externals-list.ts +43 -0
- package/src/externals.ts +64 -38
- package/src/global.css +30 -0
- package/src/module-loader.ts +0 -6
- package/src/service-worker.ts +224 -238
- package/src/setup.ts +287 -401
- package/src/sync-config.ts +6 -1
- package/dist/site.d.ts +0 -111
- package/dist/site.js +0 -602
- package/dist/vite/importmap-plugin.d.ts +0 -4
- package/dist/vite/importmap-plugin.js +0 -105
- package/dist/vite/patchwork-plugin.d.ts +0 -14
- package/dist/vite/patchwork-plugin.js +0 -8
- package/dist/vite/service-worker-plugin.d.ts +0 -2
- package/dist/vite/service-worker-plugin.js +0 -42
- package/src/site.ts +0 -859
- package/src/vite/importmap-plugin.ts +0 -133
- package/src/vite/patchwork-plugin.ts +0 -20
- package/src/vite/service-worker-plugin.ts +0 -46
package/src/sync-config.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/** localStorage key: optional override for the classic sync WebSocket URL. */
|
|
2
2
|
export const CLASSIC_SYNC_SERVER_KEY = "patchworkClassicSyncServer";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
declare const __CLASSIC_SYNC_SERVER__: string;
|
|
5
|
+
|
|
6
|
+
export const DEFAULT_CLASSIC_SYNC_SERVER =
|
|
7
|
+
typeof __CLASSIC_SYNC_SERVER__ !== "undefined"
|
|
8
|
+
? __CLASSIC_SYNC_SERVER__
|
|
9
|
+
: "wss://sync3.automerge.org";
|
|
5
10
|
|
|
6
11
|
export function readClassicSyncServer(
|
|
7
12
|
storage: Pick<Storage, "getItem"> = globalThis.localStorage
|
package/dist/site.d.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* High-level browser-app boot sequence for a Patchwork site.
|
|
3
|
-
*
|
|
4
|
-
* Layers on top of {@link setupServiceWorker} (the package default export) to
|
|
5
|
-
* construct the Repo, wire up the automerge-worker port, load plugins via the
|
|
6
|
-
* ModuleWatcher, resolve the user's account document, and hand control to the
|
|
7
|
-
* configured root tool.
|
|
8
|
-
*
|
|
9
|
-
* This entry point pulls in DOM- and plugin-layer dependencies (patchwork
|
|
10
|
-
* elements, plugins, filesystem) and is intended for use only from a browser
|
|
11
|
-
* site's `main.ts`. Non-UI consumers should import the package default (which
|
|
12
|
-
* only does SW registration and the automerge-worker handoff).
|
|
13
|
-
*/
|
|
14
|
-
import { type DocHandle, Repo, type AutomergeUrl } from "@automerge/vanillajs/slim";
|
|
15
|
-
import { type AutomergeRepoKeyhive } from "@automerge/automerge-repo-keyhive";
|
|
16
|
-
import { ModuleWatcher } from "@inkandswitch/patchwork-filesystem";
|
|
17
|
-
import { type AccountDoc } from "@inkandswitch/patchwork-plugins";
|
|
18
|
-
import * as plugins from "@inkandswitch/patchwork-plugins";
|
|
19
|
-
import type { ServiceWorkerRepoChannelListener, SyncStateDocMessage } from "./types.js";
|
|
20
|
-
declare global {
|
|
21
|
-
interface Window {
|
|
22
|
-
accountDocHandle: DocHandle<AccountDoc>;
|
|
23
|
-
Automerge: typeof import("@automerge/automerge");
|
|
24
|
-
AutomergeRepo: typeof import("@automerge/automerge-repo");
|
|
25
|
-
repo: Repo;
|
|
26
|
-
hive?: AutomergeRepoKeyhive;
|
|
27
|
-
getRepoChannel: () => MessagePort;
|
|
28
|
-
patchwork: {
|
|
29
|
-
repo: Repo;
|
|
30
|
-
packages: ModuleWatcher;
|
|
31
|
-
plugins: typeof plugins;
|
|
32
|
-
accountDocHandle: DocHandle<AccountDoc>;
|
|
33
|
-
signer?: {
|
|
34
|
-
peerId: string;
|
|
35
|
-
verifyingKey: string;
|
|
36
|
-
};
|
|
37
|
-
sw: {
|
|
38
|
-
connectClassicSync: (server?: string) => Promise<void>;
|
|
39
|
-
subscribeToRepoChannel: (listener: ServiceWorkerRepoChannelListener) => Promise<() => void>;
|
|
40
|
-
subscribeSyncState: (documentId: string, listener: (update: SyncStateDocMessage) => void) => () => void;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
uncache: (match: string) => Promise<void>;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export interface SiteConfig {
|
|
47
|
-
/**
|
|
48
|
-
* The site's default tool bundle — the tools every user of this site gets
|
|
49
|
-
* out of the box. Must collectively contribute at least a
|
|
50
|
-
* `patchwork:datatype` registration for `"account"` (typically the one
|
|
51
|
-
* supplied by `@inkandswitch/patchwork-frame`).
|
|
52
|
-
*
|
|
53
|
-
* Each entry is a *module-list source* and may be either:
|
|
54
|
-
* - an Automerge module-settings doc URL (`automerge:...`), which is
|
|
55
|
-
* live-reloaded, or
|
|
56
|
-
* - an HTTP(S) URL (absolute or site-relative, e.g. `/modules.json`) to a
|
|
57
|
-
* static JSON manifest of the shape `{ modules: string[], branches? }`,
|
|
58
|
-
* fetched once at boot.
|
|
59
|
-
*
|
|
60
|
-
* The module URLs *inside* either kind of source may themselves be Automerge
|
|
61
|
-
* folder docs or plain HTTP(S) bundles, so deployment targets can be freely
|
|
62
|
-
* mixed.
|
|
63
|
-
*
|
|
64
|
-
* Can be overridden at runtime by setting `localStorage.systemPackageListURL` to
|
|
65
|
-
* another `automerge:` URL or manifest URL — useful for local development
|
|
66
|
-
* against an unpublished tool set.
|
|
67
|
-
*/
|
|
68
|
-
defaultModules?: string | string[];
|
|
69
|
-
/**
|
|
70
|
-
* @deprecated Use {@link SiteConfig.defaultModules}. Retained for backwards
|
|
71
|
-
* compatibility with existing sites.
|
|
72
|
-
*/
|
|
73
|
-
defaultModulesUrl?: AutomergeUrl;
|
|
74
|
-
/**
|
|
75
|
-
* `localStorage` key under which this site remembers which account document
|
|
76
|
-
* belongs to the current user. Sites sharing an origin MUST use distinct
|
|
77
|
-
* keys so they do not clobber each other's accounts.
|
|
78
|
-
*/
|
|
79
|
-
accountStorageKey: string;
|
|
80
|
-
/**
|
|
81
|
-
* Brand word appended to the document title as `"<doc> | <titleSuffix>"`
|
|
82
|
-
* when a document is open. The separator is provided for you.
|
|
83
|
-
*/
|
|
84
|
-
titleSuffix: string;
|
|
85
|
-
/**
|
|
86
|
-
* DOM id of the `<patchwork-view>` element that will host the root tool.
|
|
87
|
-
* Defaults to `"root"`.
|
|
88
|
-
*/
|
|
89
|
-
rootElementId?: string;
|
|
90
|
-
/**
|
|
91
|
-
* When true, initialize keyhive for access control.
|
|
92
|
-
* The Repo will use keyhive's network adapter, peerId, and idFactory
|
|
93
|
-
* instead of a sharePolicy.
|
|
94
|
-
*/
|
|
95
|
-
keyhive?: boolean;
|
|
96
|
-
}
|
|
97
|
-
export interface BootResult {
|
|
98
|
-
repo: Repo;
|
|
99
|
-
moduleWatcher: ModuleWatcher;
|
|
100
|
-
accountDocHandle: DocHandle<AccountDoc>;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Boot a Patchwork browser site.
|
|
104
|
-
*
|
|
105
|
-
* Performs the full application-shell setup: service worker + port, Repo,
|
|
106
|
-
* plugin/module loading, account resolution, URL-hash routing, and dev-console
|
|
107
|
-
* globals (`window.repo`, `window.patchwork`, `window.uncache`). Returns the
|
|
108
|
-
* constructed Repo, ModuleWatcher and account handle for sites that want to
|
|
109
|
-
* do additional wiring after boot.
|
|
110
|
-
*/
|
|
111
|
-
export declare function bootPatchworkSite(config: SiteConfig): Promise<BootResult>;
|