@inkandswitch/patchwork-pkg-base 0.0.4 → 0.0.5
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/modules.json +2 -0
- package/package.json +3 -2
- package/packages/sync-indicator/dist/assets/SyncIndicator-CCDYatIA.js +3 -0
- package/packages/sync-indicator/dist/assets/SyncIndicator-CCDYatIA.js.map +1 -0
- package/packages/sync-indicator/dist/index.js +72 -0
- package/packages/sync-indicator/dist/index.js.map +1 -0
- package/packages/sync-indicator/package.json +43 -0
- package/packages/tasks/dist/assets/datatype-Pq8jM36X.js +10 -0
- package/packages/tasks/dist/assets/datatype-Pq8jM36X.js.map +1 -0
- package/packages/tasks/dist/assets/index-BbuRtBN3.js +7643 -0
- package/packages/tasks/dist/assets/index-BbuRtBN3.js.map +1 -0
- package/packages/tasks/dist/assets/router-BkeENNWb.js +5112 -0
- package/packages/tasks/dist/assets/router-BkeENNWb.js.map +1 -0
- package/packages/tasks/dist/assets/task-queue-tool-BJuLnyjA.js +56 -0
- package/packages/tasks/dist/assets/task-queue-tool-BJuLnyjA.js.map +1 -0
- package/packages/tasks/dist/assets/titlebar-tool-vaV-wxap.js +123 -0
- package/packages/tasks/dist/assets/titlebar-tool-vaV-wxap.js.map +1 -0
- package/packages/tasks/dist/assets/worker-CwK3e_hu.js +5056 -0
- package/packages/tasks/dist/assets/worker-CwK3e_hu.js.map +1 -0
- package/packages/tasks/dist/assets/worker-pool-Bu52iIe3.js +197 -0
- package/packages/tasks/dist/assets/worker-pool-Bu52iIe3.js.map +1 -0
- package/packages/tasks/dist/index.js +91 -0
- package/packages/tasks/dist/index.js.map +1 -0
- package/packages/tasks/package.json +43 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
(async ()=>{
|
|
2
|
+
const M = "https://ga.jspm.io/npm:es-module-shims@1.6.2/dist/es-module-shims.wasm.js";
|
|
3
|
+
let u = null, h = null;
|
|
4
|
+
async function A(t, e) {
|
|
5
|
+
u || (u = (async ()=>{
|
|
6
|
+
try {
|
|
7
|
+
console.log("importing es-module-shims..."), await import(M).then(async (m)=>{
|
|
8
|
+
await m.__tla;
|
|
9
|
+
return m;
|
|
10
|
+
}), console.log("done");
|
|
11
|
+
} catch (o) {
|
|
12
|
+
throw console.error("failed to import es-module-shims:", o), o;
|
|
13
|
+
}
|
|
14
|
+
self.importShim.addImportMap(I(t, e));
|
|
15
|
+
})()), await u;
|
|
16
|
+
}
|
|
17
|
+
function I(t, e) {
|
|
18
|
+
const o = {};
|
|
19
|
+
if (t.imports) {
|
|
20
|
+
o.imports = {};
|
|
21
|
+
for (const [r, n] of Object.entries(t.imports))try {
|
|
22
|
+
o.imports[r] = new URL(n, e).href;
|
|
23
|
+
} catch (a) {
|
|
24
|
+
console.warn(`failed to resolve import map entry ${r}: ${n}`, a), o.imports[r] = n;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (t.scopes) {
|
|
28
|
+
o.scopes = {};
|
|
29
|
+
for (const [r, n] of Object.entries(t.scopes)){
|
|
30
|
+
let a;
|
|
31
|
+
try {
|
|
32
|
+
a = new URL(r, e).href;
|
|
33
|
+
} catch (s) {
|
|
34
|
+
console.warn(`failed to resolve scope key ${r}`, s), a = r;
|
|
35
|
+
}
|
|
36
|
+
o.scopes[a] = {};
|
|
37
|
+
for (const [s, c] of Object.entries(n))try {
|
|
38
|
+
o.scopes[a][s] = new URL(c, e).href;
|
|
39
|
+
} catch (f) {
|
|
40
|
+
console.warn(`failed to resolve scope entry ${r}[${s}]: ${c}`, f), o.scopes[a][s] = c;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return console.log("Import map configured from main thread", o), o;
|
|
45
|
+
}
|
|
46
|
+
async function j(t, e) {
|
|
47
|
+
if (!u) throw new Error("Import map must be configured before creating a worker repo");
|
|
48
|
+
const { Repo: o, MessageChannelNetworkAdapter: r, IndexedDBStorageAdapter: n, initializeWasm: a, initSubductionSync: s } = await S(), [c, f] = await Promise.all([
|
|
49
|
+
fetch("/automerge.wasm").then((w)=>w.arrayBuffer()),
|
|
50
|
+
fetch("/subduction.wasm").then((w)=>w.arrayBuffer())
|
|
51
|
+
]);
|
|
52
|
+
s(new Uint8Array(f)), await a(new Uint8Array(c)), console.log("Automerge & Subduction WASM initialized");
|
|
53
|
+
const g = new o({
|
|
54
|
+
storage: new n,
|
|
55
|
+
peerId: e
|
|
56
|
+
});
|
|
57
|
+
return await b(g, t), globalThis.repo = g, g;
|
|
58
|
+
}
|
|
59
|
+
async function S() {
|
|
60
|
+
return h || (h = (async ()=>{
|
|
61
|
+
await u;
|
|
62
|
+
const [t, e, o, r, n] = await Promise.all([
|
|
63
|
+
self.importShim("@automerge/automerge/slim"),
|
|
64
|
+
self.importShim("@automerge/automerge-repo/slim"),
|
|
65
|
+
self.importShim("@automerge/automerge-repo-network-messagechannel"),
|
|
66
|
+
self.importShim("@automerge/automerge-repo-storage-indexeddb"),
|
|
67
|
+
self.importShim("@automerge/automerge-subduction/slim")
|
|
68
|
+
]);
|
|
69
|
+
return {
|
|
70
|
+
Repo: e.Repo,
|
|
71
|
+
MessageChannelNetworkAdapter: o.MessageChannelNetworkAdapter,
|
|
72
|
+
IndexedDBStorageAdapter: r.IndexedDBStorageAdapter,
|
|
73
|
+
initializeWasm: t.initializeWasm,
|
|
74
|
+
initSubductionSync: n.initSync
|
|
75
|
+
};
|
|
76
|
+
})()), h;
|
|
77
|
+
}
|
|
78
|
+
async function b(t, e) {
|
|
79
|
+
const { MessageChannelNetworkAdapter: o } = await S(), r = new o(e);
|
|
80
|
+
t.networkSubsystem.addNetworkAdapter(r), await r.whenReady();
|
|
81
|
+
}
|
|
82
|
+
const Q = async (t)=>new Promise((e)=>{
|
|
83
|
+
setTimeout(e, t * 1e3);
|
|
84
|
+
});
|
|
85
|
+
let i, d = "not initialized";
|
|
86
|
+
const m = [], y = new Set, k = new Map, l = new Set, p = new Map;
|
|
87
|
+
console.log("hi there, I am the worker pool!");
|
|
88
|
+
self.addEventListener("connect", (t)=>{
|
|
89
|
+
console.log("got a connection!");
|
|
90
|
+
const e = t.ports[0];
|
|
91
|
+
e.onmessage = (o)=>{
|
|
92
|
+
const r = o.data;
|
|
93
|
+
console.log("received message", r);
|
|
94
|
+
try {
|
|
95
|
+
switch(r.type){
|
|
96
|
+
case "init":
|
|
97
|
+
z(r.repoPort, r.importMap, r.baseURI);
|
|
98
|
+
break;
|
|
99
|
+
case "update task queue set":
|
|
100
|
+
v(r.taskQueues);
|
|
101
|
+
break;
|
|
102
|
+
case "register worker":
|
|
103
|
+
R(r.sharedWorkerName, r.workerUrl);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
} catch (n) {
|
|
107
|
+
console.error("uh-oh, error handling message in worker pool", {
|
|
108
|
+
msg: r,
|
|
109
|
+
error: n
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
async function z(t, e, o) {
|
|
115
|
+
if (d !== "not initialized") {
|
|
116
|
+
i && await b(i, t);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
for(console.log("initializing..."), d = "initializing", await A(e, o), i = await j(t, `task-worker-pool-${Math.round(Math.random() * 1e4)}`), U(), console.log("ready"), d = "ready"; m.length > 0;)await m.shift()();
|
|
120
|
+
}
|
|
121
|
+
async function v(t) {
|
|
122
|
+
if (d !== "ready") {
|
|
123
|
+
m.push(()=>v(t));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
for (const e of l)t[e] || (l.delete(e), p.delete(e));
|
|
127
|
+
for (const e of Object.keys(t)){
|
|
128
|
+
if (l.has(e)) continue;
|
|
129
|
+
console.log("joining task queue", e);
|
|
130
|
+
let o;
|
|
131
|
+
try {
|
|
132
|
+
o = await i.find(e);
|
|
133
|
+
} catch (n) {
|
|
134
|
+
console.error("did not join task queue, unable to get its doc handle", {
|
|
135
|
+
taskQueueUrl: e,
|
|
136
|
+
error: n
|
|
137
|
+
});
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
l.add(e), p.set(e, {
|
|
141
|
+
activeRouterHandle: null
|
|
142
|
+
});
|
|
143
|
+
async function r(n) {
|
|
144
|
+
try {
|
|
145
|
+
const a = n.activeRouter ? await i.find(n.activeRouter) : null;
|
|
146
|
+
p.set(e, {
|
|
147
|
+
activeRouterHandle: a
|
|
148
|
+
});
|
|
149
|
+
} catch (a) {
|
|
150
|
+
console.error("error finding doc for active router", {
|
|
151
|
+
taskQueueUrl: e,
|
|
152
|
+
error: a
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
o.on("change", (n)=>r(n.doc)), await r(o.doc()), console.log("done joining task queue", e);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function R(t, e) {
|
|
160
|
+
if (y.has(t)) {
|
|
161
|
+
console.log("registerWorker: already know about", t);
|
|
162
|
+
return;
|
|
163
|
+
} else if (d !== "ready") {
|
|
164
|
+
console.log("registerWorker: will register", t, "after init"), m.push(()=>R(t, e));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
console.log("adding worker", {
|
|
168
|
+
sharedWorkerName: t,
|
|
169
|
+
workerUrl: e
|
|
170
|
+
}), y.add(t);
|
|
171
|
+
try {
|
|
172
|
+
const o = await i.find(e);
|
|
173
|
+
o.on("change", (r)=>k.set(e, r.doc)), k.set(e, o.doc());
|
|
174
|
+
} catch (o) {
|
|
175
|
+
console.error("did not add worker, unable to get its doc handle", {
|
|
176
|
+
workerUrl: e,
|
|
177
|
+
error: o
|
|
178
|
+
}), y.delete(t);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async function U() {
|
|
182
|
+
for(;;){
|
|
183
|
+
await Q(1);
|
|
184
|
+
const t = {};
|
|
185
|
+
for (const e of l)t[e] = !0;
|
|
186
|
+
for (const [e, { activeRouterHandle: o }] of p.entries())if (o) for (const [r, { currentTask: n }] of k.entries())n && n.taskQueueUrl !== e || (console.log("sending worker heartbeat to", o.url, {
|
|
187
|
+
workerUrl: r,
|
|
188
|
+
currentTask: n
|
|
189
|
+
}), o.broadcast({
|
|
190
|
+
type: "worker heartbeat",
|
|
191
|
+
workerUrl: r,
|
|
192
|
+
currentTask: n,
|
|
193
|
+
taskQueues: t
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-pool-Bu52iIe3.js","sources":["../src/webworker-lib.ts","../src/helpers.ts","../src/worker-pool.ts"],"sourcesContent":["import type { Repo } from '@automerge/automerge-repo/slim';\n\nconst shimCodeUrl = 'https://ga.jspm.io/npm:es-module-shims@1.6.2/dist/es-module-shims.wasm.js';\n\nlet importMapReady: Promise<void> | null = null;\nlet repoModulesReady: Promise<any> | null = null;\n\nexport async function setUpImportMap(importMap: any, baseURI: string) {\n if (!importMapReady) {\n importMapReady = (async () => {\n try {\n console.log('importing es-module-shims...');\n await import(shimCodeUrl);\n console.log('done');\n } catch (error) {\n console.error('failed to import es-module-shims:', error);\n throw error;\n }\n\n (self as any).importShim.addImportMap(resolveImportMap(importMap, baseURI));\n })();\n }\n\n await importMapReady;\n}\n\nfunction resolveImportMap(importMap: any, baseURI: string) {\n const resolvedImportMap: any = {};\n\n if (importMap.imports) {\n resolvedImportMap.imports = {};\n for (const [key, value] of Object.entries(importMap.imports)) {\n try {\n resolvedImportMap.imports[key] = new URL(value as any, baseURI).href;\n } catch (e) {\n console.warn(`failed to resolve import map entry ${key}: ${value}`, e);\n resolvedImportMap.imports[key] = value;\n }\n }\n }\n\n if (importMap.scopes) {\n resolvedImportMap.scopes = {};\n for (const [scopeKey, scopeMap] of Object.entries(importMap.scopes)) {\n let resolvedScopeKey;\n try {\n resolvedScopeKey = new URL(scopeKey, baseURI).href;\n } catch (e) {\n console.warn(`failed to resolve scope key ${scopeKey}`, e);\n resolvedScopeKey = scopeKey;\n }\n\n resolvedImportMap.scopes[resolvedScopeKey] = {};\n for (const [key, value] of Object.entries(scopeMap as any)) {\n try {\n resolvedImportMap.scopes[resolvedScopeKey][key] = new URL(value as any, baseURI).href;\n } catch (e) {\n console.warn(`failed to resolve scope entry ${scopeKey}[${key}]: ${value}`, e);\n resolvedImportMap.scopes[resolvedScopeKey][key] = value;\n }\n }\n }\n }\n\n console.log('Import map configured from main thread', resolvedImportMap);\n return resolvedImportMap;\n}\n\nexport async function getRepo(port: MessagePort, peerId: string) {\n if (!importMapReady) {\n throw new Error('Import map must be configured before creating a worker repo');\n }\n\n const {\n Repo,\n MessageChannelNetworkAdapter,\n IndexedDBStorageAdapter,\n initializeWasm,\n initSubductionSync,\n } = await getRepoModules();\n\n const [automergeWasm, subductionWasm] = await Promise.all([\n fetch('/automerge.wasm').then((r) => r.arrayBuffer()),\n fetch('/subduction.wasm').then((r) => r.arrayBuffer()),\n ]);\n\n initSubductionSync(new Uint8Array(subductionWasm));\n await initializeWasm(new Uint8Array(automergeWasm));\n console.log('Automerge & Subduction WASM initialized');\n\n const repo = new Repo({\n storage: new IndexedDBStorageAdapter(),\n peerId: peerId as any,\n });\n\n await connectRepoPort(repo, port);\n\n (globalThis as any).repo = repo;\n\n return repo;\n}\n\nasync function getRepoModules() {\n if (!repoModulesReady) {\n repoModulesReady = (async () => {\n await importMapReady;\n\n const [automerge, repo, network, storage, subduction] = await Promise.all([\n (self as any).importShim('@automerge/automerge/slim'),\n (self as any).importShim('@automerge/automerge-repo/slim'),\n (self as any).importShim('@automerge/automerge-repo-network-messagechannel'),\n (self as any).importShim('@automerge/automerge-repo-storage-indexeddb'),\n (self as any).importShim('@automerge/automerge-subduction/slim'),\n ]);\n\n return {\n Repo: repo.Repo,\n MessageChannelNetworkAdapter: network.MessageChannelNetworkAdapter,\n IndexedDBStorageAdapter: storage.IndexedDBStorageAdapter,\n initializeWasm: automerge.initializeWasm,\n initSubductionSync: subduction.initSync,\n };\n })();\n }\n\n return repoModulesReady;\n}\n\nexport async function connectRepoPort(repo: Repo, port: MessagePort) {\n const { MessageChannelNetworkAdapter } = await getRepoModules();\n const adapter = new MessageChannelNetworkAdapter(port);\n repo.networkSubsystem.addNetworkAdapter(adapter);\n await adapter.whenReady();\n}\n","import { type AutomergeUrl, type DocHandle, type Repo } from '@automerge/automerge-repo/slim';\nimport { TaskQueueSet } from './datatype';\n\nexport const TASK_QUEUE_URLS_FIELD_NAME = '__taskQueues__';\n\n// TODO: where's the type for account??\nexport async function getAccountHandle(repo: Repo): Promise<DocHandle<any>> {\n const accountDocUrl = getAccountDocUrl();\n // avoid importing isValidAutomergeUrl for BS packaging reasons\n if (!accountDocUrl.startsWith('automerge:')) {\n const errorMsg = `account doc url invalid: ${accountDocUrl}`;\n console.error(errorMsg);\n throw new Error(errorMsg);\n }\n const accountHandle = await repo.find<any>(accountDocUrl);\n if (!accountHandle) {\n const errorMsg = `no doc at account doc url: ${accountDocUrl}`;\n console.error(errorMsg);\n throw new Error(errorMsg);\n }\n return accountHandle;\n}\n\n// TODO: what's the right way to get this??\nexport function getAccountDocUrl(): AutomergeUrl {\n return localStorage.getItem('tinyPatchworkAccountUrl') as AutomergeUrl;\n}\n\nexport async function getSelfContactUrl(repo: Repo): Promise<AutomergeUrl> {\n const accountHandle = await getAccountHandle(repo);\n return accountHandle.doc().contactUrl;\n}\n\nexport type TaskQueues = { [taskQueueUrl: AutomergeUrl]: true };\n\nexport function getTaskQueues(account: any): TaskQueues {\n return account[TASK_QUEUE_URLS_FIELD_NAME] ?? { 'automerge:2xrHArq3QwSGHaeUdquP7ECTpnEL': true };\n}\n\nexport function addTaskQueue(account: any, taskQueueUrl: AutomergeUrl) {\n let taskQueues: TaskQueueSet | null = account[TASK_QUEUE_URLS_FIELD_NAME];\n if (!taskQueues) {\n taskQueues = account[TASK_QUEUE_URLS_FIELD_NAME] = {};\n }\n taskQueues![taskQueueUrl] = true;\n}\n\nexport const seconds = async (s: number) =>\n new Promise((resolve) => {\n setTimeout(resolve, s * 1_000);\n });\n\nexport function notNull<T>(value: T | null): value is T {\n return value !== null;\n}\n\nexport function shuffle<T>(array: T[]): T[] {\n for (let i = array.length - 1; i > 0; i--) {\n // Pick a random index from 0 to i\n const j = Math.floor(Math.random() * (i + 1));\n // Swap elements array[i] and array[j]\n [array[i], array[j]] = [array[j], array[i]];\n }\n return array;\n}\n","/* eslint-env worker */\n\nimport type { AutomergeUrl, DocHandle, Repo } from '@automerge/automerge-repo/slim';\nimport type { WorkerDoc, RouterDoc, TaskQueueDoc, TaskQueueSet } from './datatype';\nimport type { MessageToWorkerPool, MessageToRouterChannel } from './protocol';\n\nimport { connectRepoPort, getRepo, setUpImportMap } from './webworker-lib';\nimport { seconds } from './helpers';\n\ninterface TaskQueueState {\n activeRouterHandle: DocHandle<RouterDoc> | null;\n}\n\nlet repo: Repo;\n\nlet status: 'not initialized' | 'initializing' | 'ready' = 'not initialized';\nconst toDoAfterInit: (() => Promise<void>)[] = [];\n\nconst sharedWorkerNames = new Set<string>();\nconst workerByUrl = new Map<AutomergeUrl, WorkerDoc>();\n\nconst taskQueueUrls = new Set<AutomergeUrl>();\nconst taskQueueState = new Map<AutomergeUrl, TaskQueueState>();\n\nconsole.log('hi there, I am the worker pool!');\n\nself.addEventListener('connect', (e: any) => {\n console.log('got a connection!');\n const port = e.ports[0];\n port.onmessage = (e: any) => {\n const msg: MessageToWorkerPool = e.data;\n console.log('received message', msg);\n try {\n switch (msg.type) {\n case 'init':\n init(msg.repoPort, msg.importMap, msg.baseURI);\n break;\n case 'update task queue set':\n updateTaskQueueSet(msg.taskQueues);\n break;\n case 'register worker':\n registerWorker(msg.sharedWorkerName, msg.workerUrl);\n break;\n }\n } catch (error) {\n console.error('uh-oh, error handling message in worker pool', { msg, error });\n }\n };\n});\n\nasync function init(port: MessagePort, importMap: any, baseURI: string) {\n if (status !== 'not initialized') {\n if (repo) {\n await connectRepoPort(repo, port);\n }\n return;\n }\n\n console.log('initializing...');\n status = 'initializing';\n\n await setUpImportMap(importMap, baseURI);\n repo = await getRepo(port, `task-worker-pool-${Math.round(Math.random() * 10_000)}`);\n pSendWorkerStatuses(); // this is a \"process\", meant to be running in the background (hence no `await`)\n\n console.log('ready');\n status = 'ready';\n\n while (toDoAfterInit.length > 0) {\n await toDoAfterInit.shift()!();\n }\n}\n\nasync function updateTaskQueueSet(newTaskQueueUrls: TaskQueueSet) {\n if (status !== 'ready') {\n // haven't initialized yet, so save this for later\n toDoAfterInit.push(() => updateTaskQueueSet(newTaskQueueUrls));\n return;\n }\n\n // remove task queues that are no longer in the set\n for (const taskQueueUrl of taskQueueUrls) {\n if (!newTaskQueueUrls[taskQueueUrl]) {\n taskQueueUrls.delete(taskQueueUrl);\n taskQueueState.delete(taskQueueUrl);\n }\n }\n\n // add the new ones\n for (const taskQueueUrl of Object.keys(newTaskQueueUrls) as AutomergeUrl[]) {\n if (taskQueueUrls.has(taskQueueUrl)) {\n continue;\n }\n\n console.log('joining task queue', taskQueueUrl);\n\n let taskQueueHandle: DocHandle<TaskQueueDoc>;\n try {\n taskQueueHandle = await repo.find<TaskQueueDoc>(taskQueueUrl);\n } catch (error) {\n console.error('did not join task queue, unable to get its doc handle', {\n taskQueueUrl,\n error,\n });\n return;\n }\n\n taskQueueUrls.add(taskQueueUrl);\n taskQueueState.set(taskQueueUrl, { activeRouterHandle: null });\n\n async function setTaskQueueState(taskQueue: TaskQueueDoc) {\n try {\n const activeRouterHandle = taskQueue.activeRouter\n ? await repo.find<RouterDoc>(taskQueue.activeRouter)\n : null;\n taskQueueState.set(taskQueueUrl, { activeRouterHandle });\n } catch (error) {\n console.error('error finding doc for active router', { taskQueueUrl, error });\n }\n }\n\n taskQueueHandle.on('change', (payload) => setTaskQueueState(payload.doc));\n await setTaskQueueState(taskQueueHandle.doc());\n\n console.log('done joining task queue', taskQueueUrl);\n }\n}\n\nasync function registerWorker(sharedWorkerName: string, workerUrl: AutomergeUrl) {\n if (sharedWorkerNames.has(sharedWorkerName)) {\n // already added!\n console.log('registerWorker: already know about', sharedWorkerName);\n return;\n } else if (status !== 'ready') {\n // haven't initialized yet, so save this for later\n console.log('registerWorker: will register', sharedWorkerName, 'after init');\n toDoAfterInit.push(() => registerWorker(sharedWorkerName, workerUrl));\n return;\n }\n\n console.log('adding worker', { sharedWorkerName, workerUrl });\n\n sharedWorkerNames.add(sharedWorkerName);\n\n try {\n const workerHandle = await repo.find<WorkerDoc>(workerUrl);\n workerHandle.on('change', (payload) => workerByUrl.set(workerUrl, payload.doc));\n workerByUrl.set(workerUrl, workerHandle.doc());\n } catch (error) {\n console.error('did not add worker, unable to get its doc handle', { workerUrl, error });\n sharedWorkerNames.delete(sharedWorkerName);\n }\n}\n\nasync function pSendWorkerStatuses() {\n while (true) {\n await seconds(1);\n\n const taskQueues: TaskQueueSet = {};\n for (const taskQueueUrl of taskQueueUrls) {\n taskQueues[taskQueueUrl] = true;\n }\n\n for (const [taskQueueUrl, { activeRouterHandle }] of taskQueueState.entries()) {\n if (!activeRouterHandle) {\n continue;\n }\n\n for (const [workerUrl, { currentTask }] of workerByUrl.entries()) {\n if (currentTask && currentTask.taskQueueUrl !== taskQueueUrl) {\n // don't bother sending the heartbeats of workers that are busy with tasks from other queues\n } else {\n console.log('sending worker heartbeat to', activeRouterHandle.url, { workerUrl, currentTask });\n activeRouterHandle.broadcast({\n type: 'worker heartbeat',\n workerUrl,\n currentTask,\n taskQueues,\n } satisfies MessageToRouterChannel);\n }\n }\n }\n }\n}\n\nexport { }; // to ensure this is a module\n"],"names":["shimCodeUrl","importMapReady","repoModulesReady","setUpImportMap","importMap","baseURI","error","resolveImportMap","resolvedImportMap","key","value","e","scopeKey","scopeMap","resolvedScopeKey","getRepo","port","peerId","Repo","MessageChannelNetworkAdapter","IndexedDBStorageAdapter","initializeWasm","initSubductionSync","getRepoModules","automergeWasm","subductionWasm","r","repo","connectRepoPort","automerge","network","storage","subduction","adapter","seconds","s","resolve","status","toDoAfterInit","sharedWorkerNames","workerByUrl","taskQueueUrls","taskQueueState","msg","init","updateTaskQueueSet","registerWorker","pSendWorkerStatuses","newTaskQueueUrls","taskQueueUrl","taskQueueHandle","setTaskQueueState","taskQueue","activeRouterHandle","payload","sharedWorkerName","workerUrl","workerHandle","taskQueues","currentTask"],"mappings":"AAEA,MAAMA,EAAc,4EAEpB,IAAIC,EAAuC,KACvCC,EAAwC,KAE5C,eAAsBC,EAAeC,EAAgBC,EAAiB,CAC/DJ,IACHA,GAAkB,SAAY,CAC5B,GAAI,CACF,QAAQ,IAAI,8BAA8B,EAC1C,MAAM,OAAOD,GACb,QAAQ,IAAI,MAAM,CACpB,OAASM,EAAO,CACd,cAAQ,MAAM,oCAAqCA,CAAK,EAClDA,CACR,CAEC,KAAa,WAAW,aAAaC,EAAiBH,EAAWC,CAAO,CAAC,CAC5E,GAAA,GAGF,MAAMJ,CACR,CAEA,SAASM,EAAiBH,EAAgBC,EAAiB,CACzD,MAAMG,EAAyB,CAAA,EAE/B,GAAIJ,EAAU,QAAS,CACrBI,EAAkB,QAAU,CAAA,EAC5B,SAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQN,EAAU,OAAO,EACzD,GAAI,CACFI,EAAkB,QAAQC,CAAG,EAAI,IAAI,IAAIC,EAAcL,CAAO,EAAE,IAClE,OAASM,EAAG,CACV,QAAQ,KAAK,sCAAsCF,CAAG,KAAKC,CAAK,GAAIC,CAAC,EACrEH,EAAkB,QAAQC,CAAG,EAAIC,CACnC,CAEJ,CAEA,GAAIN,EAAU,OAAQ,CACpBI,EAAkB,OAAS,CAAA,EAC3B,SAAW,CAACI,EAAUC,CAAQ,IAAK,OAAO,QAAQT,EAAU,MAAM,EAAG,CACnE,IAAIU,EACJ,GAAI,CACFA,EAAmB,IAAI,IAAIF,EAAUP,CAAO,EAAE,IAChD,OAASM,EAAG,CACV,QAAQ,KAAK,+BAA+BC,CAAQ,GAAID,CAAC,EACzDG,EAAmBF,CACrB,CAEAJ,EAAkB,OAAOM,CAAgB,EAAI,CAAA,EAC7C,SAAW,CAACL,EAAK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
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./assets/task-queue-tool-BJuLnyjA.js","./assets/index-BbuRtBN3.js","./assets/titlebar-tool-vaV-wxap.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
let _;
|
|
3
|
+
let __tla = (async () => {
|
|
4
|
+
let k, w, y, u;
|
|
5
|
+
k = "modulepreload";
|
|
6
|
+
w = function(r, l) {
|
|
7
|
+
return new URL(r, l).href;
|
|
8
|
+
};
|
|
9
|
+
y = {};
|
|
10
|
+
u = function(l, c, d) {
|
|
11
|
+
let p = Promise.resolve();
|
|
12
|
+
if (c && c.length > 0) {
|
|
13
|
+
const n = document.getElementsByTagName("link"), e = document.querySelector("meta[property=csp-nonce]"), f = (e == null ? void 0 : e.nonce) || (e == null ? void 0 : e.getAttribute("nonce"));
|
|
14
|
+
p = Promise.allSettled(c.map((t) => {
|
|
15
|
+
if (t = w(t, d), t in y) return;
|
|
16
|
+
y[t] = true;
|
|
17
|
+
const a = t.endsWith(".css"), h = a ? '[rel="stylesheet"]' : "";
|
|
18
|
+
if (!!d) for (let s = n.length - 1; s >= 0; s--) {
|
|
19
|
+
const i = n[s];
|
|
20
|
+
if (i.href === t && (!a || i.rel === "stylesheet")) return;
|
|
21
|
+
}
|
|
22
|
+
else if (document.querySelector(`link[href="${t}"]${h}`)) return;
|
|
23
|
+
const o = document.createElement("link");
|
|
24
|
+
if (o.rel = a ? "stylesheet" : k, a || (o.as = "script"), o.crossOrigin = "", o.href = t, f && o.setAttribute("nonce", f), document.head.appendChild(o), a) return new Promise((s, i) => {
|
|
25
|
+
o.addEventListener("load", s), o.addEventListener("error", () => i(new Error(`Unable to preload CSS for ${t}`)));
|
|
26
|
+
});
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
function m(n) {
|
|
30
|
+
const e = new Event("vite:preloadError", {
|
|
31
|
+
cancelable: true
|
|
32
|
+
});
|
|
33
|
+
if (e.payload = n, window.dispatchEvent(e), !e.defaultPrevented) throw n;
|
|
34
|
+
}
|
|
35
|
+
return p.then((n) => {
|
|
36
|
+
for (const e of n || []) e.status === "rejected" && m(e.reason);
|
|
37
|
+
return l().catch(m);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
_ = [
|
|
41
|
+
{
|
|
42
|
+
type: "patchwork:datatype",
|
|
43
|
+
id: "task-queue",
|
|
44
|
+
name: "Task Queue",
|
|
45
|
+
icon: "CirclePlus",
|
|
46
|
+
unlisted: true,
|
|
47
|
+
load: async () => (await u(async () => {
|
|
48
|
+
const { TaskQueueDatatype: r } = await import("./assets/datatype-Pq8jM36X.js");
|
|
49
|
+
return {
|
|
50
|
+
TaskQueueDatatype: r
|
|
51
|
+
};
|
|
52
|
+
}, [], import.meta.url)).TaskQueueDatatype
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: "patchwork:tool",
|
|
56
|
+
id: "task-queue-browser",
|
|
57
|
+
name: "Task Queue Browser",
|
|
58
|
+
icon: "CirclePlus",
|
|
59
|
+
supportedDatatypes: [
|
|
60
|
+
"task-queue"
|
|
61
|
+
],
|
|
62
|
+
load: async () => (await u(async () => {
|
|
63
|
+
const { TaskQueueTool: r } = await import("./assets/task-queue-tool-BJuLnyjA.js");
|
|
64
|
+
return {
|
|
65
|
+
TaskQueueTool: r
|
|
66
|
+
};
|
|
67
|
+
}, __vite__mapDeps([0,1]), import.meta.url)).TaskQueueTool
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: "patchwork:tool",
|
|
71
|
+
id: "task-titlebar",
|
|
72
|
+
name: "Task Titlebar",
|
|
73
|
+
icon: "Square",
|
|
74
|
+
supportedDatatypes: "*",
|
|
75
|
+
unlisted: true,
|
|
76
|
+
tags: [
|
|
77
|
+
"titlebar-tool"
|
|
78
|
+
],
|
|
79
|
+
load: async () => (await u(async () => {
|
|
80
|
+
const { TitlebarTool: r } = await import("./assets/titlebar-tool-vaV-wxap.js");
|
|
81
|
+
return {
|
|
82
|
+
TitlebarTool: r
|
|
83
|
+
};
|
|
84
|
+
}, __vite__mapDeps([2,1]), import.meta.url)).TitlebarTool
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
})();
|
|
88
|
+
export {
|
|
89
|
+
__tla,
|
|
90
|
+
_ as plugins
|
|
91
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"mappings":"","names":[],"ignoreList":[],"sources":[],"sourcesContent":[],"file":"index.js"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@patchwork/tasks",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Task-Related Datatypes and Tools",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "vite build",
|
|
12
|
+
"push": "pushwork sync",
|
|
13
|
+
"watch": "nodemon --watch src -e js,tsx,ts,tsx,css,json --exec 'pnpm build && pnpm push'",
|
|
14
|
+
"register": "pw-modules add \"$MODULE_SETTINGS_DOC_URL\" \"$(pushwork url)\""
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "Ink & Switch",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@automerge/automerge": "^3.2.6",
|
|
20
|
+
"@automerge/automerge-repo": "2.6.0-subduction.20",
|
|
21
|
+
"@automerge/automerge-repo-react-hooks": "2.6.0-subduction.20",
|
|
22
|
+
"@automerge/vanillajs": "2.6.0-subduction.20",
|
|
23
|
+
"@awarth/tasklib": "^0.0.10",
|
|
24
|
+
"@inkandswitch/patchwork-bootloader": "^0.0.9",
|
|
25
|
+
"@inkandswitch/patchwork-elements": "^0.0.3",
|
|
26
|
+
"@inkandswitch/patchwork-plugins": "^0.0.2",
|
|
27
|
+
"boring-name-generator": "^1.0.3",
|
|
28
|
+
"es-module-shims": "^2.8.1",
|
|
29
|
+
"react": "^18.3.1",
|
|
30
|
+
"react-dom": "^18.3.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/react": "^18.3.28",
|
|
34
|
+
"@types/react-dom": "^19.2.3",
|
|
35
|
+
"@vitejs/plugin-react": "^4.7.0",
|
|
36
|
+
"autoprefixer": "^10.5.0",
|
|
37
|
+
"nodemon": "^3.1.14",
|
|
38
|
+
"vite": "^5.4.21",
|
|
39
|
+
"vite-plugin-css-injected-by-js": "^3.5.2",
|
|
40
|
+
"vite-plugin-top-level-await": "^1.6.0",
|
|
41
|
+
"vite-plugin-wasm": "^3.6.0"
|
|
42
|
+
}
|
|
43
|
+
}
|