@polkadot-api/smoldot 0.3.17-canary.d6be873 → 0.4.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/dist/from-node-worker/from-node-worker.js +1 -3
- package/dist/from-node-worker/from-node-worker.js.map +1 -1
- package/dist/from-worker/from-worker.js +3 -5
- package/dist/from-worker/from-worker.js.map +1 -1
- package/dist/index.js +1 -12
- package/dist/index.js.map +1 -1
- package/dist/node-worker/node-worker.js +9 -11
- package/dist/node-worker/node-worker.js.map +1 -1
- package/dist/worker/worker.js +4 -25
- package/dist/worker/worker.js.map +1 -1
- package/from-worker/package.json +4 -4
- package/package.json +20 -45
- package/worker/package.json +3 -3
- package/dist/esm/index.mjs +0 -2
- package/dist/esm/index.mjs.map +0 -1
- package/dist/from-node-worker/esm/from-node-worker.mjs +0 -92
- package/dist/from-node-worker/esm/from-node-worker.mjs.map +0 -1
- package/dist/from-worker/esm/from-worker.mjs +0 -17
- package/dist/from-worker/esm/from-worker.mjs.map +0 -1
- package/dist/node-worker/esm/node-worker.mjs +0 -79
- package/dist/node-worker/esm/node-worker.mjs.map +0 -1
- package/dist/worker/esm/worker.mjs +0 -8
- package/dist/worker/esm/worker.mjs.map +0 -1
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const chainIds = /* @__PURE__ */ new WeakMap();
|
|
4
2
|
const startFromWorker = (worker, options = {}) => {
|
|
5
3
|
worker.setMaxListeners(0);
|
|
@@ -90,5 +88,5 @@ function sendToWorker(worker, msg) {
|
|
|
90
88
|
});
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
|
|
91
|
+
export { startFromWorker };
|
|
94
92
|
//# sourceMappingURL=from-node-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"from-node-worker.js","sources":["../../src/from-node-worker.ts"],"sourcesContent":["import { Worker } from \"node:worker_threads\"\nimport type { Chain, Client } from \"@polkadot-api/smoldot-patch\"\nimport type { RequestMessage, SmoldotOptions } from \"./node-worker\"\n\nconst chainIds = new WeakMap<Chain, number>()\nexport const startFromWorker = (\n worker: Worker,\n options: SmoldotOptions = {},\n): Client => {\n worker.setMaxListeners(0)\n sendToWorker(worker, {\n type: \"start\",\n value: options,\n })\n\n return {\n async addChain(options) {\n const { potentialRelayChains, ...addChainOptions } = options\n const id = await sendToWorker(worker, {\n type: \"add-chain\",\n value: {\n ...addChainOptions,\n potentialRelayChainIds: potentialRelayChains?.map((chain) => {\n const id = chainIds.get(chain)\n if (id == null) {\n throw new Error(\"Only chains created with `addChain` can be used\")\n }\n return id\n }),\n },\n })\n\n const chain: Chain = {\n jsonRpcResponses: {\n next: async () =>\n sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"receiveIterable\",\n },\n }),\n [Symbol.asyncIterator]() {\n return this\n },\n },\n nextJsonRpcResponse() {\n return sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"receive\",\n },\n })\n },\n remove() {\n return sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"remove\",\n },\n })\n },\n sendJsonRpc(value) {\n return sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"send\",\n value,\n },\n })\n },\n }\n chainIds.set(chain, id)\n\n return chain\n },\n async terminate() {\n await sendToWorker(worker, {\n type: \"terminate\",\n })\n },\n }\n}\n\nlet msgId = 0\nfunction sendToWorker(worker: Worker, msg: RequestMessage): Promise<any> {\n const id = msgId++\n worker.postMessage({ ...msg, id })\n return new Promise((resolve) => {\n const msgHandler = (response: any) => {\n if (response.id === id) {\n resolve(response.value)\n worker.off(\"message\", msgHandler)\n }\n }\n worker.on(\"message\", msgHandler)\n })\n}\n"],"names":["options","chain","id"],"mappings":"
|
|
1
|
+
{"version":3,"file":"from-node-worker.js","sources":["../../src/from-node-worker.ts"],"sourcesContent":["import { Worker } from \"node:worker_threads\"\nimport type { Chain, Client } from \"@polkadot-api/smoldot-patch\"\nimport type { RequestMessage, SmoldotOptions } from \"./node-worker\"\n\nconst chainIds = new WeakMap<Chain, number>()\nexport const startFromWorker = (\n worker: Worker,\n options: SmoldotOptions = {},\n): Client => {\n worker.setMaxListeners(0)\n sendToWorker(worker, {\n type: \"start\",\n value: options,\n })\n\n return {\n async addChain(options) {\n const { potentialRelayChains, ...addChainOptions } = options\n const id = await sendToWorker(worker, {\n type: \"add-chain\",\n value: {\n ...addChainOptions,\n potentialRelayChainIds: potentialRelayChains?.map((chain) => {\n const id = chainIds.get(chain)\n if (id == null) {\n throw new Error(\"Only chains created with `addChain` can be used\")\n }\n return id\n }),\n },\n })\n\n const chain: Chain = {\n jsonRpcResponses: {\n next: async () =>\n sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"receiveIterable\",\n },\n }),\n [Symbol.asyncIterator]() {\n return this\n },\n },\n nextJsonRpcResponse() {\n return sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"receive\",\n },\n })\n },\n remove() {\n return sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"remove\",\n },\n })\n },\n sendJsonRpc(value) {\n return sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"send\",\n value,\n },\n })\n },\n }\n chainIds.set(chain, id)\n\n return chain\n },\n async terminate() {\n await sendToWorker(worker, {\n type: \"terminate\",\n })\n },\n }\n}\n\nlet msgId = 0\nfunction sendToWorker(worker: Worker, msg: RequestMessage): Promise<any> {\n const id = msgId++\n worker.postMessage({ ...msg, id })\n return new Promise((resolve) => {\n const msgHandler = (response: any) => {\n if (response.id === id) {\n resolve(response.value)\n worker.off(\"message\", msgHandler)\n }\n }\n worker.on(\"message\", msgHandler)\n })\n}\n"],"names":["options","chain","id"],"mappings":"AAIA,MAAM,QAAA,uBAAe,OAAA,EAAuB;AACrC,MAAM,eAAA,GAAkB,CAC7B,MAAA,EACA,OAAA,GAA0B,EAAC,KAChB;AACX,EAAA,MAAA,CAAO,gBAA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ytecode = require('@polkadot-api/smoldot-patch/no-auto-bytecode');
|
|
1
|
+
import { startWithBytecode } from '@polkadot-api/smoldot-patch/no-auto-bytecode';
|
|
4
2
|
|
|
5
3
|
const startFromWorker = (worker, options = {}) => {
|
|
6
4
|
const bytecode = new Promise((resolve) => {
|
|
@@ -8,12 +6,12 @@ const startFromWorker = (worker, options = {}) => {
|
|
|
8
6
|
});
|
|
9
7
|
const { port1, port2 } = new MessageChannel();
|
|
10
8
|
worker.postMessage(port1, [port1]);
|
|
11
|
-
return
|
|
9
|
+
return startWithBytecode({
|
|
12
10
|
bytecode,
|
|
13
11
|
portToWorker: port2,
|
|
14
12
|
...options
|
|
15
13
|
});
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
export { startFromWorker };
|
|
19
17
|
//# sourceMappingURL=from-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"from-worker.js","sources":["../../src/from-worker.ts"],"sourcesContent":["import type { Client } from \"@polkadot-api/smoldot-patch\"\nimport {\n type SmoldotBytecode,\n type ClientOptionsWithBytecode,\n startWithBytecode,\n} from \"@polkadot-api/smoldot-patch/no-auto-bytecode\"\n\nexport type SmoldotOptions = Omit<\n ClientOptionsWithBytecode,\n \"bytecode\" | \"portToWorker\"\n>\n\nexport const startFromWorker = (\n worker: Worker,\n options: SmoldotOptions = {},\n): Client => {\n const bytecode = new Promise<SmoldotBytecode>((resolve) => {\n worker.onmessage = (event) => resolve(event.data)\n })\n\n const { port1, port2 } = new MessageChannel()\n worker.postMessage(port1, [port1])\n\n return startWithBytecode({\n bytecode,\n portToWorker: port2,\n ...options,\n })\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"from-worker.js","sources":["../../src/from-worker.ts"],"sourcesContent":["import type { Client } from \"@polkadot-api/smoldot-patch\"\nimport {\n type SmoldotBytecode,\n type ClientOptionsWithBytecode,\n startWithBytecode,\n} from \"@polkadot-api/smoldot-patch/no-auto-bytecode\"\n\nexport type SmoldotOptions = Omit<\n ClientOptionsWithBytecode,\n \"bytecode\" | \"portToWorker\"\n>\n\nexport const startFromWorker = (\n worker: Worker,\n options: SmoldotOptions = {},\n): Client => {\n const bytecode = new Promise<SmoldotBytecode>((resolve) => {\n worker.onmessage = (event) => resolve(event.data)\n })\n\n const { port1, port2 } = new MessageChannel()\n worker.postMessage(port1, [port1])\n\n return startWithBytecode({\n bytecode,\n portToWorker: port2,\n ...options,\n })\n}\n"],"names":[],"mappings":";;AAYO,MAAM,eAAA,GAAkB,CAC7B,MAAA,EACA,OAAA,GAA0B,EAAC,KAChB;AACX,EAAA,MAAM,QAAA,GAAW,IAAI,OAAA,CAAyB,CAAC,OAAA,KAAY;AACzD,IAAA,MAAA,CAAO,SAAA,GAAY,CAAC,KAAA,KAAU,OAAA,CAAQ,MAAM,IAAI,CAAA;AAAA,EAClD,CAAC,CAAA;AAED,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAM,GAAI,IAAI,cAAA,EAAe;AAC5C,EAAA,MAAA,CAAO,WAAA,CAAY,KAAA,EAAO,CAAC,KAAK,CAAC,CAAA;AAEjC,EAAA,OAAO,iBAAA,CAAkB;AAAA,IACvB,QAAA;AAAA,IACA,YAAA,EAAc,KAAA;AAAA,IACd,GAAG;AAAA,GACJ,CAAA;AACH;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var smoldotPatch = require('@polkadot-api/smoldot-patch');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.keys(smoldotPatch).forEach(function (k) {
|
|
8
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () { return smoldotPatch[k]; }
|
|
11
|
-
});
|
|
12
|
-
});
|
|
1
|
+
export * from '@polkadot-api/smoldot-patch';
|
|
13
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var node_worker_threads = require('node:worker_threads');
|
|
4
|
-
var smoldotPatch = require('@polkadot-api/smoldot-patch');
|
|
1
|
+
import { parentPort } from 'node:worker_threads';
|
|
2
|
+
import { start } from '@polkadot-api/smoldot-patch';
|
|
5
3
|
|
|
6
4
|
let smoldot = null;
|
|
7
5
|
let chainId = 0;
|
|
8
6
|
const chains = /* @__PURE__ */ new Map();
|
|
9
|
-
|
|
7
|
+
parentPort.on("message", async (msg) => {
|
|
10
8
|
if (msg.type === "start") {
|
|
11
9
|
if (smoldot !== null) {
|
|
12
10
|
throw new Error("Can't call start on a client already started");
|
|
13
11
|
}
|
|
14
|
-
smoldot =
|
|
15
|
-
return
|
|
12
|
+
smoldot = start(msg.value);
|
|
13
|
+
return parentPort?.postMessage({
|
|
16
14
|
id: msg.id
|
|
17
15
|
});
|
|
18
16
|
}
|
|
@@ -34,7 +32,7 @@ node_worker_threads.parentPort.on("message", async (msg) => {
|
|
|
34
32
|
});
|
|
35
33
|
const id = chainId++;
|
|
36
34
|
chains.set(id, chain);
|
|
37
|
-
|
|
35
|
+
parentPort?.postMessage({
|
|
38
36
|
id: msg.id,
|
|
39
37
|
value: id
|
|
40
38
|
});
|
|
@@ -42,7 +40,7 @@ node_worker_threads.parentPort.on("message", async (msg) => {
|
|
|
42
40
|
}
|
|
43
41
|
case "terminate":
|
|
44
42
|
await smoldot.terminate();
|
|
45
|
-
|
|
43
|
+
parentPort?.postMessage({
|
|
46
44
|
id: msg.id
|
|
47
45
|
});
|
|
48
46
|
smoldot = null;
|
|
@@ -58,13 +56,13 @@ async function handleChainMessage(msg, id) {
|
|
|
58
56
|
if (!chain) throw new Error("Can't reference removed chain");
|
|
59
57
|
switch (msg.value.type) {
|
|
60
58
|
case "receive":
|
|
61
|
-
|
|
59
|
+
parentPort?.postMessage({
|
|
62
60
|
id,
|
|
63
61
|
value: await chain.nextJsonRpcResponse()
|
|
64
62
|
});
|
|
65
63
|
break;
|
|
66
64
|
case "receiveIterable":
|
|
67
|
-
|
|
65
|
+
parentPort?.postMessage({
|
|
68
66
|
id,
|
|
69
67
|
value: await chain.jsonRpcResponses.next()
|
|
70
68
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-worker.js","sources":["../../src/node-worker.ts"],"sourcesContent":["import { parentPort } from \"node:worker_threads\"\nimport {\n AddChainOptions,\n Chain,\n Client,\n ClientOptions,\n start,\n} from \"@polkadot-api/smoldot-patch\"\n\nexport type SmoldotOptions = Omit<ClientOptions, \"portToWorker\">\nexport interface StartMsg {\n type: \"start\"\n value: SmoldotOptions\n}\nexport interface AddChainMsg {\n type: \"add-chain\"\n value: Omit<AddChainOptions, \"potentialRelayChains\"> & {\n potentialRelayChainIds?: number[]\n }\n}\nexport interface TerminateMsg {\n type: \"terminate\"\n}\nexport interface ChainMsg {\n type: \"chain\"\n value: {\n id: number\n } & (\n | {\n type: \"remove\" | \"receive\" | \"receiveIterable\"\n }\n | {\n type: \"send\"\n value: string\n }\n )\n}\nexport type RequestMessage = StartMsg | AddChainMsg | TerminateMsg | ChainMsg\nexport type CorrelatedRequestMessage = { id: number } & RequestMessage\n\nlet smoldot: Client | null = null\n\nlet chainId = 0\nconst chains = new Map<number, Chain>()\n\nparentPort!.on(\"message\", async (msg: CorrelatedRequestMessage) => {\n if (msg.type === \"start\") {\n if (smoldot !== null) {\n throw new Error(\"Can't call start on a client already started\")\n }\n smoldot = start(msg.value)\n return parentPort?.postMessage({\n id: msg.id,\n })\n }\n\n if (smoldot === null) {\n throw new Error(\"Smoldot not started\")\n }\n\n switch (msg.type) {\n case \"add-chain\": {\n const potentialRelayChains = msg.value.potentialRelayChainIds?.map(\n (id) => {\n const chain = chains.get(id)\n if (!chain) throw new Error(\"Can't reference removed chain\")\n return chain\n },\n )\n const chain = await smoldot.addChain({\n ...msg.value,\n potentialRelayChains,\n })\n const id = chainId++\n chains.set(id, chain)\n parentPort?.postMessage({\n id: msg.id,\n value: id,\n })\n break\n }\n case \"terminate\":\n await smoldot.terminate()\n parentPort?.postMessage({\n id: msg.id,\n })\n smoldot = null\n chains.clear()\n break\n case \"chain\":\n handleChainMessage(msg, msg.id)\n break\n }\n})\n\nasync function handleChainMessage(msg: ChainMsg, id: number) {\n const chain = chains.get(msg.value.id)\n if (!chain) throw new Error(\"Can't reference removed chain\")\n\n switch (msg.value.type) {\n case \"receive\":\n parentPort?.postMessage({\n id,\n value: await chain.nextJsonRpcResponse(),\n })\n break\n case \"receiveIterable\":\n parentPort?.postMessage({\n id,\n value: await chain.jsonRpcResponses.next(),\n })\n break\n case \"send\":\n chain.sendJsonRpc(msg.value.value)\n break\n case \"remove\":\n chain.remove()\n chains.delete(msg.value.id)\n break\n }\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"node-worker.js","sources":["../../src/node-worker.ts"],"sourcesContent":["import { parentPort } from \"node:worker_threads\"\nimport {\n AddChainOptions,\n Chain,\n Client,\n ClientOptions,\n start,\n} from \"@polkadot-api/smoldot-patch\"\n\nexport type SmoldotOptions = Omit<ClientOptions, \"portToWorker\">\nexport interface StartMsg {\n type: \"start\"\n value: SmoldotOptions\n}\nexport interface AddChainMsg {\n type: \"add-chain\"\n value: Omit<AddChainOptions, \"potentialRelayChains\"> & {\n potentialRelayChainIds?: number[]\n }\n}\nexport interface TerminateMsg {\n type: \"terminate\"\n}\nexport interface ChainMsg {\n type: \"chain\"\n value: {\n id: number\n } & (\n | {\n type: \"remove\" | \"receive\" | \"receiveIterable\"\n }\n | {\n type: \"send\"\n value: string\n }\n )\n}\nexport type RequestMessage = StartMsg | AddChainMsg | TerminateMsg | ChainMsg\nexport type CorrelatedRequestMessage = { id: number } & RequestMessage\n\nlet smoldot: Client | null = null\n\nlet chainId = 0\nconst chains = new Map<number, Chain>()\n\nparentPort!.on(\"message\", async (msg: CorrelatedRequestMessage) => {\n if (msg.type === \"start\") {\n if (smoldot !== null) {\n throw new Error(\"Can't call start on a client already started\")\n }\n smoldot = start(msg.value)\n return parentPort?.postMessage({\n id: msg.id,\n })\n }\n\n if (smoldot === null) {\n throw new Error(\"Smoldot not started\")\n }\n\n switch (msg.type) {\n case \"add-chain\": {\n const potentialRelayChains = msg.value.potentialRelayChainIds?.map(\n (id) => {\n const chain = chains.get(id)\n if (!chain) throw new Error(\"Can't reference removed chain\")\n return chain\n },\n )\n const chain = await smoldot.addChain({\n ...msg.value,\n potentialRelayChains,\n })\n const id = chainId++\n chains.set(id, chain)\n parentPort?.postMessage({\n id: msg.id,\n value: id,\n })\n break\n }\n case \"terminate\":\n await smoldot.terminate()\n parentPort?.postMessage({\n id: msg.id,\n })\n smoldot = null\n chains.clear()\n break\n case \"chain\":\n handleChainMessage(msg, msg.id)\n break\n }\n})\n\nasync function handleChainMessage(msg: ChainMsg, id: number) {\n const chain = chains.get(msg.value.id)\n if (!chain) throw new Error(\"Can't reference removed chain\")\n\n switch (msg.value.type) {\n case \"receive\":\n parentPort?.postMessage({\n id,\n value: await chain.nextJsonRpcResponse(),\n })\n break\n case \"receiveIterable\":\n parentPort?.postMessage({\n id,\n value: await chain.jsonRpcResponses.next(),\n })\n break\n case \"send\":\n chain.sendJsonRpc(msg.value.value)\n break\n case \"remove\":\n chain.remove()\n chains.delete(msg.value.id)\n break\n }\n}\n"],"names":["id","chain"],"mappings":";;;AAwCA,IAAI,OAAA,GAAyB,IAAA;AAE7B,IAAI,OAAA,GAAU,CAAA;AACd,MAAM,MAAA,uBAAa,GAAA,EAAmB;AAEtC,UAAA,CAAY,EAAA,CAAG,SAAA,EAAW,OAAO,GAAA,KAAkC;AACjE,EAAA,IAAI,GAAA,CAAI,SAAS,OAAA,EAAS;AACx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AO,KAAA,EAAM;AACb,MAAA;AAAA,IACF,KAAK,OAAA;AACH,MAAA,kBAAA,CAAmB,GAAA,EAAK,IAAI,EAAE,CAAA;AAC9B,MAAA;AAAA;AAEN,CAAC,CAAA;AAED,eAAe,kBAAA,CAAmB,KAAe,EAAA,EAAY;AAC3D,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,GAAA,CAAI,GAAA,CAAI,MAAM,EAAE,CAAA;AACrC,EAAA,IAAI,CAAC,KAAA,EAAO,MAAM,IAAI,MAAM,+BAA+B,CAAA;AAE3D,EAAA,QAAQ,GAAA,CAAI,MAAM,IAAA;AAAM,IACtB,KAAK,SAAA;AACH,MAAA,UAAA,EAAY,WAAA,CAAY;AAAA,QACtB,EAAA;AAAA,QACA,KAAA,EAAO,MAAM,KAAA,CAAM,mBAAA;AAAoB,OACxC,CAAA;AACD,MAAA;AAAA,IACF,KAAK,iBAAA;AACH,MAAA,UAAA,EAAY,WAAA,CAAY;AAAA,QACtB,EAAA;AAAA,QACA,KAAA,EAAO,MAAM,KAAA,CAAM,gBAAA,CAAiB,IAAA;AAAK,OAC1C,CAAA;AACD,MAAA;AAAA,IACF,KAAK,MAAA;AACH,MAAA,KAAA,CAAM,WAAA,CAAY,GAAA,CAAI,KAAA,CAAM,KAAK,CAAA;AACjC,MAAA;AAAA,IACF,KAAK,QAAA;AACH,MAAA,KAAA,CAAM,MAAA,EAAO;AACb,MAAA,MAAA,CAAO,MAAA,CAAO,GAAA,CAAI,KAAA,CAAM,EAAE,CAAA;AAC1B,MAAA;AAAA;AAEN"}
|
package/dist/worker/worker.js
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import * as smoldot from '@polkadot-api/smoldot-patch/worker';
|
|
2
|
+
import { compileBytecode } from '@polkadot-api/smoldot-patch/bytecode';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
var bytecode = require('@polkadot-api/smoldot-patch/bytecode');
|
|
5
|
-
|
|
6
|
-
function _interopNamespaceDefault(e) {
|
|
7
|
-
var n = Object.create(null);
|
|
8
|
-
if (e) {
|
|
9
|
-
Object.keys(e).forEach(function (k) {
|
|
10
|
-
if (k !== 'default') {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
n.default = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var smoldot__namespace = /*#__PURE__*/_interopNamespaceDefault(smoldot);
|
|
24
|
-
|
|
25
|
-
bytecode.compileBytecode().then((x) => {
|
|
4
|
+
compileBytecode().then((x) => {
|
|
26
5
|
postMessage(x);
|
|
27
6
|
});
|
|
28
|
-
onmessage = (msg) =>
|
|
7
|
+
onmessage = (msg) => smoldot.run(msg.data);
|
|
29
8
|
//# sourceMappingURL=worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sources":["../../src/worker.ts"],"sourcesContent":["import * as smoldot from \"@polkadot-api/smoldot-patch/worker\"\nimport { compileBytecode } from \"@polkadot-api/smoldot-patch/bytecode\"\n\ncompileBytecode().then((x) => {\n postMessage(x)\n})\nonmessage = (msg) => smoldot.run(msg.data)\n"],"names":[
|
|
1
|
+
{"version":3,"file":"worker.js","sources":["../../src/worker.ts"],"sourcesContent":["import * as smoldot from \"@polkadot-api/smoldot-patch/worker\"\nimport { compileBytecode } from \"@polkadot-api/smoldot-patch/bytecode\"\n\ncompileBytecode().then((x) => {\n postMessage(x)\n})\nonmessage = (msg) => smoldot.run(msg.data)\n"],"names":[],"mappings":";;;AAGA,eAAA,EAAgB,CAAE,IAAA,CAAK,CAAC,CAAA,KAAM;AAC5B,EAAA,WAAA,CAAY,CAAC,CAAA;AACf,CAAC,CAAA;AACD,SAAA,GAAY,CAAC,GAAA,KAAQ,OAAA,CAAQ,GAAA,CAAI,IAAI,IAAI,CAAA"}
|
package/from-worker/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polkadot-api/smoldot-from-worker",
|
|
3
|
+
"type": "module",
|
|
3
4
|
"types": "../dist/from-worker/from-worker.d.ts",
|
|
4
|
-
"module": "../dist/from-worker/
|
|
5
|
-
"import": "../dist/from-worker/
|
|
6
|
-
"browser": "../dist/node-worker/
|
|
7
|
-
"require": "../dist/from-worker/from-worker.js",
|
|
5
|
+
"module": "../dist/from-worker/from-worker.js",
|
|
6
|
+
"import": "../dist/from-worker/from-worker.js",
|
|
7
|
+
"browser": "../dist/node-worker/node-worker.js",
|
|
8
8
|
"default": "../dist/from-worker/from-worker.js"
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -1,73 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polkadot-api/smoldot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"author": "Josep M Sobrepere (https://github.com/josepot)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/polkadot-api/polkadot-api.git"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"default": "./dist/index.js"
|
|
16
|
-
},
|
|
17
|
-
"module": "./dist/esm/index.mjs",
|
|
18
|
-
"import": "./dist/esm/index.mjs",
|
|
19
|
-
"require": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"import": "./dist/index.js",
|
|
20
16
|
"default": "./dist/index.js"
|
|
21
17
|
},
|
|
22
18
|
"./from-node-worker": {
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"default": "./dist/from-node-worker/from-node-worker.js"
|
|
27
|
-
},
|
|
28
|
-
"module": "./dist/from-node-worker/esm/from-node-worker.mjs",
|
|
29
|
-
"import": "./dist/from-node-worker/esm/from-node-worker.mjs",
|
|
30
|
-
"require": "./dist/from-node-worker/from-node-worker.js",
|
|
19
|
+
"types": "./dist/from-node-worker/from-node-worker.d.ts",
|
|
20
|
+
"module": "./dist/from-node-worker/from-node-worker.js",
|
|
21
|
+
"import": "./dist/from-node-worker/from-node-worker.js",
|
|
31
22
|
"default": "./dist/from-node-worker/from-node-worker.js"
|
|
32
23
|
},
|
|
33
24
|
"./from-worker": {
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"default": "./dist/from-worker/from-worker.js"
|
|
38
|
-
},
|
|
39
|
-
"module": "./dist/from-worker/esm/from-worker.mjs",
|
|
40
|
-
"import": "./dist/from-worker/esm/from-worker.mjs",
|
|
41
|
-
"require": "./dist/from-worker/from-worker.js",
|
|
25
|
+
"types": "./dist/from-worker/from-worker.d.ts",
|
|
26
|
+
"module": "./dist/from-worker/from-worker.js",
|
|
27
|
+
"import": "./dist/from-worker/from-worker.js",
|
|
42
28
|
"default": "./dist/from-worker/from-worker.js"
|
|
43
29
|
},
|
|
44
30
|
"./node-worker": {
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"default": "./dist/node-worker/node-worker.js"
|
|
49
|
-
},
|
|
50
|
-
"module": "./dist/node-worker/esm/node-worker.mjs",
|
|
51
|
-
"import": "./dist/node-worker/esm/node-worker.mjs",
|
|
52
|
-
"require": "./dist/node-worker/node-worker.js",
|
|
31
|
+
"types": "./dist/node-worker/node-worker.d.ts",
|
|
32
|
+
"module": "./dist/node-worker/node-worker.js",
|
|
33
|
+
"import": "./dist/node-worker/node-worker.js",
|
|
53
34
|
"default": "./dist/node-worker/node-worker.js"
|
|
54
35
|
},
|
|
55
36
|
"./worker": {
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"default": "./dist/worker/worker.js"
|
|
60
|
-
},
|
|
61
|
-
"module": "./dist/worker/esm/worker.mjs",
|
|
62
|
-
"import": "./dist/worker/esm/worker.mjs",
|
|
63
|
-
"require": "./dist/worker/worker.js",
|
|
37
|
+
"types": "./dist/worker/worker.d.ts",
|
|
38
|
+
"module": "./dist/worker/worker.js",
|
|
39
|
+
"import": "./dist/worker/worker.js",
|
|
64
40
|
"default": "./dist/worker/worker.js"
|
|
65
|
-
}
|
|
66
|
-
"./package.json": "./package.json"
|
|
41
|
+
}
|
|
67
42
|
},
|
|
68
43
|
"main": "./dist/index.js",
|
|
69
|
-
"module": "./dist/
|
|
70
|
-
"browser": "./dist/
|
|
44
|
+
"module": "./dist/index.js",
|
|
45
|
+
"browser": "./dist/index.js",
|
|
71
46
|
"types": "./dist/index.d.ts",
|
|
72
47
|
"files": [
|
|
73
48
|
"dist",
|
package/worker/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polkadot-api/smoldot-worker",
|
|
3
|
+
"type": "module",
|
|
3
4
|
"types": "../dist/worker/worker.d.ts",
|
|
4
|
-
"module": "../dist/worker/
|
|
5
|
-
"import": "../dist/worker/
|
|
6
|
-
"require": "../dist/worker/worker.js",
|
|
5
|
+
"module": "../dist/worker/worker.js",
|
|
6
|
+
"import": "../dist/worker/worker.js",
|
|
7
7
|
"default": "../dist/worker/worker.js"
|
|
8
8
|
}
|
package/dist/esm/index.mjs
DELETED
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
const chainIds = /* @__PURE__ */ new WeakMap();
|
|
2
|
-
const startFromWorker = (worker, options = {}) => {
|
|
3
|
-
worker.setMaxListeners(0);
|
|
4
|
-
sendToWorker(worker, {
|
|
5
|
-
type: "start",
|
|
6
|
-
value: options
|
|
7
|
-
});
|
|
8
|
-
return {
|
|
9
|
-
async addChain(options2) {
|
|
10
|
-
const { potentialRelayChains, ...addChainOptions } = options2;
|
|
11
|
-
const id = await sendToWorker(worker, {
|
|
12
|
-
type: "add-chain",
|
|
13
|
-
value: {
|
|
14
|
-
...addChainOptions,
|
|
15
|
-
potentialRelayChainIds: potentialRelayChains?.map((chain2) => {
|
|
16
|
-
const id2 = chainIds.get(chain2);
|
|
17
|
-
if (id2 == null) {
|
|
18
|
-
throw new Error("Only chains created with `addChain` can be used");
|
|
19
|
-
}
|
|
20
|
-
return id2;
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
const chain = {
|
|
25
|
-
jsonRpcResponses: {
|
|
26
|
-
next: async () => sendToWorker(worker, {
|
|
27
|
-
type: "chain",
|
|
28
|
-
value: {
|
|
29
|
-
id,
|
|
30
|
-
type: "receiveIterable"
|
|
31
|
-
}
|
|
32
|
-
}),
|
|
33
|
-
[Symbol.asyncIterator]() {
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
nextJsonRpcResponse() {
|
|
38
|
-
return sendToWorker(worker, {
|
|
39
|
-
type: "chain",
|
|
40
|
-
value: {
|
|
41
|
-
id,
|
|
42
|
-
type: "receive"
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
},
|
|
46
|
-
remove() {
|
|
47
|
-
return sendToWorker(worker, {
|
|
48
|
-
type: "chain",
|
|
49
|
-
value: {
|
|
50
|
-
id,
|
|
51
|
-
type: "remove"
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
sendJsonRpc(value) {
|
|
56
|
-
return sendToWorker(worker, {
|
|
57
|
-
type: "chain",
|
|
58
|
-
value: {
|
|
59
|
-
id,
|
|
60
|
-
type: "send",
|
|
61
|
-
value
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
chainIds.set(chain, id);
|
|
67
|
-
return chain;
|
|
68
|
-
},
|
|
69
|
-
async terminate() {
|
|
70
|
-
await sendToWorker(worker, {
|
|
71
|
-
type: "terminate"
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
let msgId = 0;
|
|
77
|
-
function sendToWorker(worker, msg) {
|
|
78
|
-
const id = msgId++;
|
|
79
|
-
worker.postMessage({ ...msg, id });
|
|
80
|
-
return new Promise((resolve) => {
|
|
81
|
-
const msgHandler = (response) => {
|
|
82
|
-
if (response.id === id) {
|
|
83
|
-
resolve(response.value);
|
|
84
|
-
worker.off("message", msgHandler);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
worker.on("message", msgHandler);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export { startFromWorker };
|
|
92
|
-
//# sourceMappingURL=from-node-worker.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"from-node-worker.mjs","sources":["../../../src/from-node-worker.ts"],"sourcesContent":["import { Worker } from \"node:worker_threads\"\nimport type { Chain, Client } from \"@polkadot-api/smoldot-patch\"\nimport type { RequestMessage, SmoldotOptions } from \"./node-worker\"\n\nconst chainIds = new WeakMap<Chain, number>()\nexport const startFromWorker = (\n worker: Worker,\n options: SmoldotOptions = {},\n): Client => {\n worker.setMaxListeners(0)\n sendToWorker(worker, {\n type: \"start\",\n value: options,\n })\n\n return {\n async addChain(options) {\n const { potentialRelayChains, ...addChainOptions } = options\n const id = await sendToWorker(worker, {\n type: \"add-chain\",\n value: {\n ...addChainOptions,\n potentialRelayChainIds: potentialRelayChains?.map((chain) => {\n const id = chainIds.get(chain)\n if (id == null) {\n throw new Error(\"Only chains created with `addChain` can be used\")\n }\n return id\n }),\n },\n })\n\n const chain: Chain = {\n jsonRpcResponses: {\n next: async () =>\n sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"receiveIterable\",\n },\n }),\n [Symbol.asyncIterator]() {\n return this\n },\n },\n nextJsonRpcResponse() {\n return sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"receive\",\n },\n })\n },\n remove() {\n return sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"remove\",\n },\n })\n },\n sendJsonRpc(value) {\n return sendToWorker(worker, {\n type: \"chain\",\n value: {\n id,\n type: \"send\",\n value,\n },\n })\n },\n }\n chainIds.set(chain, id)\n\n return chain\n },\n async terminate() {\n await sendToWorker(worker, {\n type: \"terminate\",\n })\n },\n }\n}\n\nlet msgId = 0\nfunction sendToWorker(worker: Worker, msg: RequestMessage): Promise<any> {\n const id = msgId++\n worker.postMessage({ ...msg, id })\n return new Promise((resolve) => {\n const msgHandler = (response: any) => {\n if (response.id === id) {\n resolve(response.value)\n worker.off(\"message\", msgHandler)\n }\n }\n worker.on(\"message\", msgHandler)\n })\n}\n"],"names":["options","chain","id"],"mappings":"AAIA,MAAM,QAAA,uBAAe,OAAA,EAAuB;AACrC,MAAM,eAAA,GAAkB,CAC7B,MAAA,EACA,OAAA,GAA0B,EAAC,KAChB;AACX,EAAA,MAAA,CAAO,gBAAgB,CAAC,CAAA;AACxB,EAAA,YAAA,CAAa,MAAA,EAAQ;AAAA,IACnB,IAAA,EAAM,OAAA;AAAA,IACN,KAAA,EAAO;AAAA,GACR,CAAA;AAED,EAAA,OAAO;AAAA,IACL,MAAM,SAASA,QAAAA,EAAS;AACtB,MAAA,MAAM,EAAE,oBAAA,EAAsB,GAAG,eAAA,EAAgB,GAAIA,QAAAA;AACrD,MAAA,MAAM,EAAA,GAAK,MAAM,YAAA,CAAa,MAAA,EAAQ;AAAA,QACpC,IAAA,EAAM,WAAA;AAAA,QACN,KAAA,EAAO;AAAA,UACL,GAAG,eAAA;AAAA,UACH,sBAAA,EAAwB,oBAAA,EAAsB,GAAA,CAAI,CAACC,MAAAA,KAAU;AAC3D,YAAA,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;AAAA,IACA,MAAM,SAAA,GAAY;AAChB,MAAA,MAAM,aAAa,MAAA,EAAQ;AAAA,QACzB,IAAA,EAAM;AAAA,OACP,CAAA;AAAA,IACH;AAAA,GACF;AACF;AAEA,IAAI,KAAA,GAAQ,CAAA;AACZ,SAAS,YAAA,CAAa,QAAgB,GAAA,EAAmC;AACvE,EAAA,MAAM,EAAA,GAAK,KAAA,EAAA;AACX,EAAA,MAAA,CAAO,WAAA,CAAY,EAAE,GAAG,GAAA,EAAK,IAAI,CAAA;AACjC,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,KAAY;AAC9B,IAAA,MAAM,UAAA,GAAa,CAAC,QAAA,KAAkB;AACpC,MAAA,IAAI,QAAA,CAAS,OAAO,EAAA,EAAI;AACtB,QAAA,OAAA,CAAQ,SAAS,KAAK,CAAA;AACtB,QAAA,MAAA,CAAO,GAAA,CAAI,WAAW,UAAU,CAAA;AAAA,MAClC;AAAA,IACF,CAAA;AACA,IAAA,MAAA,CAAO,EAAA,CAAG,WAAW,UAAU,CAAA;AAAA,EACjC,CAAC,CAAA;AACH;;;;"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { startWithBytecode } from '@polkadot-api/smoldot-patch/no-auto-bytecode';
|
|
2
|
-
|
|
3
|
-
const startFromWorker = (worker, options = {}) => {
|
|
4
|
-
const bytecode = new Promise((resolve) => {
|
|
5
|
-
worker.onmessage = (event) => resolve(event.data);
|
|
6
|
-
});
|
|
7
|
-
const { port1, port2 } = new MessageChannel();
|
|
8
|
-
worker.postMessage(port1, [port1]);
|
|
9
|
-
return startWithBytecode({
|
|
10
|
-
bytecode,
|
|
11
|
-
portToWorker: port2,
|
|
12
|
-
...options
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export { startFromWorker };
|
|
17
|
-
//# sourceMappingURL=from-worker.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"from-worker.mjs","sources":["../../../src/from-worker.ts"],"sourcesContent":["import type { Client } from \"@polkadot-api/smoldot-patch\"\nimport {\n type SmoldotBytecode,\n type ClientOptionsWithBytecode,\n startWithBytecode,\n} from \"@polkadot-api/smoldot-patch/no-auto-bytecode\"\n\nexport type SmoldotOptions = Omit<\n ClientOptionsWithBytecode,\n \"bytecode\" | \"portToWorker\"\n>\n\nexport const startFromWorker = (\n worker: Worker,\n options: SmoldotOptions = {},\n): Client => {\n const bytecode = new Promise<SmoldotBytecode>((resolve) => {\n worker.onmessage = (event) => resolve(event.data)\n })\n\n const { port1, port2 } = new MessageChannel()\n worker.postMessage(port1, [port1])\n\n return startWithBytecode({\n bytecode,\n portToWorker: port2,\n ...options,\n })\n}\n"],"names":[],"mappings":";;AAYO,MAAM,eAAA,GAAkB,CAC7B,MAAA,EACA,OAAA,GAA0B,EAAC,KAChB;AACX,EAAA,MAAM,QAAA,GAAW,IAAI,OAAA,CAAyB,CAAC,OAAA,KAAY;AACzD,IAAA,MAAA,CAAO,SAAA,GAAY,CAAC,KAAA,KAAU,OAAA,CAAQ,MAAM,IAAI,CAAA;AAAA,EAClD,CAAC,CAAA;AAED,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAM,GAAI,IAAI,cAAA,EAAe;AAC5C,EAAA,MAAA,CAAO,WAAA,CAAY,KAAA,EAAO,CAAC,KAAK,CAAC,CAAA;AAEjC,EAAA,OAAO,iBAAA,CAAkB;AAAA,IACvB,QAAA;AAAA,IACA,YAAA,EAAc,KAAA;AAAA,IACd,GAAG;AAAA,GACJ,CAAA;AACH;;;;"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { parentPort } from 'node:worker_threads';
|
|
2
|
-
import { start } from '@polkadot-api/smoldot-patch';
|
|
3
|
-
|
|
4
|
-
let smoldot = null;
|
|
5
|
-
let chainId = 0;
|
|
6
|
-
const chains = /* @__PURE__ */ new Map();
|
|
7
|
-
parentPort.on("message", async (msg) => {
|
|
8
|
-
if (msg.type === "start") {
|
|
9
|
-
if (smoldot !== null) {
|
|
10
|
-
throw new Error("Can't call start on a client already started");
|
|
11
|
-
}
|
|
12
|
-
smoldot = start(msg.value);
|
|
13
|
-
return parentPort?.postMessage({
|
|
14
|
-
id: msg.id
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
if (smoldot === null) {
|
|
18
|
-
throw new Error("Smoldot not started");
|
|
19
|
-
}
|
|
20
|
-
switch (msg.type) {
|
|
21
|
-
case "add-chain": {
|
|
22
|
-
const potentialRelayChains = msg.value.potentialRelayChainIds?.map(
|
|
23
|
-
(id2) => {
|
|
24
|
-
const chain2 = chains.get(id2);
|
|
25
|
-
if (!chain2) throw new Error("Can't reference removed chain");
|
|
26
|
-
return chain2;
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
const chain = await smoldot.addChain({
|
|
30
|
-
...msg.value,
|
|
31
|
-
potentialRelayChains
|
|
32
|
-
});
|
|
33
|
-
const id = chainId++;
|
|
34
|
-
chains.set(id, chain);
|
|
35
|
-
parentPort?.postMessage({
|
|
36
|
-
id: msg.id,
|
|
37
|
-
value: id
|
|
38
|
-
});
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
case "terminate":
|
|
42
|
-
await smoldot.terminate();
|
|
43
|
-
parentPort?.postMessage({
|
|
44
|
-
id: msg.id
|
|
45
|
-
});
|
|
46
|
-
smoldot = null;
|
|
47
|
-
chains.clear();
|
|
48
|
-
break;
|
|
49
|
-
case "chain":
|
|
50
|
-
handleChainMessage(msg, msg.id);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
async function handleChainMessage(msg, id) {
|
|
55
|
-
const chain = chains.get(msg.value.id);
|
|
56
|
-
if (!chain) throw new Error("Can't reference removed chain");
|
|
57
|
-
switch (msg.value.type) {
|
|
58
|
-
case "receive":
|
|
59
|
-
parentPort?.postMessage({
|
|
60
|
-
id,
|
|
61
|
-
value: await chain.nextJsonRpcResponse()
|
|
62
|
-
});
|
|
63
|
-
break;
|
|
64
|
-
case "receiveIterable":
|
|
65
|
-
parentPort?.postMessage({
|
|
66
|
-
id,
|
|
67
|
-
value: await chain.jsonRpcResponses.next()
|
|
68
|
-
});
|
|
69
|
-
break;
|
|
70
|
-
case "send":
|
|
71
|
-
chain.sendJsonRpc(msg.value.value);
|
|
72
|
-
break;
|
|
73
|
-
case "remove":
|
|
74
|
-
chain.remove();
|
|
75
|
-
chains.delete(msg.value.id);
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=node-worker.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"node-worker.mjs","sources":["../../../src/node-worker.ts"],"sourcesContent":["import { parentPort } from \"node:worker_threads\"\nimport {\n AddChainOptions,\n Chain,\n Client,\n ClientOptions,\n start,\n} from \"@polkadot-api/smoldot-patch\"\n\nexport type SmoldotOptions = Omit<ClientOptions, \"portToWorker\">\nexport interface StartMsg {\n type: \"start\"\n value: SmoldotOptions\n}\nexport interface AddChainMsg {\n type: \"add-chain\"\n value: Omit<AddChainOptions, \"potentialRelayChains\"> & {\n potentialRelayChainIds?: number[]\n }\n}\nexport interface TerminateMsg {\n type: \"terminate\"\n}\nexport interface ChainMsg {\n type: \"chain\"\n value: {\n id: number\n } & (\n | {\n type: \"remove\" | \"receive\" | \"receiveIterable\"\n }\n | {\n type: \"send\"\n value: string\n }\n )\n}\nexport type RequestMessage = StartMsg | AddChainMsg | TerminateMsg | ChainMsg\nexport type CorrelatedRequestMessage = { id: number } & RequestMessage\n\nlet smoldot: Client | null = null\n\nlet chainId = 0\nconst chains = new Map<number, Chain>()\n\nparentPort!.on(\"message\", async (msg: CorrelatedRequestMessage) => {\n if (msg.type === \"start\") {\n if (smoldot !== null) {\n throw new Error(\"Can't call start on a client already started\")\n }\n smoldot = start(msg.value)\n return parentPort?.postMessage({\n id: msg.id,\n })\n }\n\n if (smoldot === null) {\n throw new Error(\"Smoldot not started\")\n }\n\n switch (msg.type) {\n case \"add-chain\": {\n const potentialRelayChains = msg.value.potentialRelayChainIds?.map(\n (id) => {\n const chain = chains.get(id)\n if (!chain) throw new Error(\"Can't reference removed chain\")\n return chain\n },\n )\n const chain = await smoldot.addChain({\n ...msg.value,\n potentialRelayChains,\n })\n const id = chainId++\n chains.set(id, chain)\n parentPort?.postMessage({\n id: msg.id,\n value: id,\n })\n break\n }\n case \"terminate\":\n await smoldot.terminate()\n parentPort?.postMessage({\n id: msg.id,\n })\n smoldot = null\n chains.clear()\n break\n case \"chain\":\n handleChainMessage(msg, msg.id)\n break\n }\n})\n\nasync function handleChainMessage(msg: ChainMsg, id: number) {\n const chain = chains.get(msg.value.id)\n if (!chain) throw new Error(\"Can't reference removed chain\")\n\n switch (msg.value.type) {\n case \"receive\":\n parentPort?.postMessage({\n id,\n value: await chain.nextJsonRpcResponse(),\n })\n break\n case \"receiveIterable\":\n parentPort?.postMessage({\n id,\n value: await chain.jsonRpcResponses.next(),\n })\n break\n case \"send\":\n chain.sendJsonRpc(msg.value.value)\n break\n case \"remove\":\n chain.remove()\n chains.delete(msg.value.id)\n break\n }\n}\n"],"names":["id","chain"],"mappings":";;;AAwCA,IAAI,OAAA,GAAyB,IAAA;AAE7B,IAAI,OAAA,GAAU,CAAA;AACd,MAAM,MAAA,uBAAa,GAAA,EAAmB;AAEtC,UAAA,CAAY,EAAA,CAAG,SAAA,EAAW,OAAO,GAAA,KAAkC;AACjE,EAAA,IAAI,GAAA,CAAI,SAAS,OAAA,EAAS;AACxB,IAAA,IAAI,YAAY,IAAA,EAAM;AACpB,MAAA,MAAM,IAAI,MAAM,8CAA8C,CAAA;AAAA,IAChE;AACA,IAAA,OAAA,GAAU,KAAA,CAAM,IAAI,KAAK,CAAA;AACzB,IAAA,OAAO,YAAY,WAAA,CAAY;AAAA,MAC7B,IAAI,GAAA,CAAI;AAAA,KACT,CAAA;AAAA,EACH;AAEA,EAAA,IAAI,YAAY,IAAA,EAAM;AACpB,I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AA,IAAI,CAAC,KAAA,EAAO,MAAM,IAAI,MAAM,+BAA+B,CAAA;AAE3D,EAAA,QAAQ,GAAA,CAAI,MAAM,IAAA;AAAM,IACtB,KAAK,SAAA;AACH,MAAA,UAAA,EAAY,WAAA,CAAY;AAAA,QACtB,EAAA;AAAA,QACA,KAAA,EAAO,MAAM,KAAA,CAAM,mBAAA;AAAoB,OACxC,CAAA;AACD,MAAA;AAAA,IACF,KAAK,iBAAA;AACH,MAAA,UAAA,EAAY,WAAA,CAAY;AAAA,QACtB,EAAA;AAAA,QACA,KAAA,EAAO,MAAM,KAAA,CAAM,gBAAA,CAAiB,IAAA;AAAK,OAC1C,CAAA;AACD,MAAA;AAAA,IACF,KAAK,MAAA;AACH,MAAA,KAAA,CAAM,WAAA,CAAY,GAAA,CAAI,KAAA,CAAM,KAAK,CAAA;AACjC,MAAA;AAAA,IACF,KAAK,QAAA;AACH,MAAA,KAAA,CAAM,MAAA,EAAO;AACb,MAAA,MAAA,CAAO,MAAA,CAAO,GAAA,CAAI,KAAA,CAAM,EAAE,CAAA;AAC1B,MAAA;AAAA;AAEN"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as smoldot from '@polkadot-api/smoldot-patch/worker';
|
|
2
|
-
import { compileBytecode } from '@polkadot-api/smoldot-patch/bytecode';
|
|
3
|
-
|
|
4
|
-
compileBytecode().then((x) => {
|
|
5
|
-
postMessage(x);
|
|
6
|
-
});
|
|
7
|
-
onmessage = (msg) => smoldot.run(msg.data);
|
|
8
|
-
//# sourceMappingURL=worker.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.mjs","sources":["../../../src/worker.ts"],"sourcesContent":["import * as smoldot from \"@polkadot-api/smoldot-patch/worker\"\nimport { compileBytecode } from \"@polkadot-api/smoldot-patch/bytecode\"\n\ncompileBytecode().then((x) => {\n postMessage(x)\n})\nonmessage = (msg) => smoldot.run(msg.data)\n"],"names":[],"mappings":";;;AAGA,eAAA,EAAgB,CAAE,IAAA,CAAK,CAAC,CAAA,KAAM;AAC5B,EAAA,WAAA,CAAY,CAAC,CAAA;AACf,CAAC,CAAA;AACD,SAAA,GAAY,CAAC,GAAA,KAAQ,OAAA,CAAQ,GAAA,CAAI,IAAI,IAAI,CAAA"}
|