@swipt/cli 0.1.0-nightly.98 → 0.1.0-nightly.99
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/availability.d.ts +3 -1
- package/dist/availability.js +173 -151
- package/dist/availability.js.map +1 -1
- package/dist/cli/cli.js +52 -66
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/command.d.ts +9 -0
- package/dist/cli/command.js.map +1 -1
- package/dist/cli/commands/data/clear.js +2 -2
- package/dist/cli/commands/data/clear.js.map +1 -1
- package/dist/cli/commands/data/data.js +2 -2
- package/dist/cli/commands/data/data.js.map +1 -1
- package/dist/cli/commands/data/list.js +3 -3
- package/dist/cli/commands/data/list.js.map +1 -1
- package/dist/cli/commands/data/operand.js.map +1 -1
- package/dist/cli/commands/data/read.js +4 -7
- package/dist/cli/commands/data/read.js.map +1 -1
- package/dist/cli/commands/data/remove.js +3 -3
- package/dist/cli/commands/data/remove.js.map +1 -1
- package/dist/cli/commands/data/write.js +2 -2
- package/dist/cli/commands/data/write.js.map +1 -1
- package/dist/cli/commands/device/add.js +2 -2
- package/dist/cli/commands/device/add.js.map +1 -1
- package/dist/cli/commands/device/device.js +2 -2
- package/dist/cli/commands/device/device.js.map +1 -1
- package/dist/cli/commands/device/list.js +2 -2
- package/dist/cli/commands/device/list.js.map +1 -1
- package/dist/cli/commands/device/logs.js +44 -46
- package/dist/cli/commands/device/logs.js.map +1 -1
- package/dist/cli/commands/device/remove.js +2 -2
- package/dist/cli/commands/device/remove.js.map +1 -1
- package/dist/cli/commands/device/stop.js +3 -3
- package/dist/cli/commands/device/stop.js.map +1 -1
- package/dist/cli/commands/driver/driver.js +6 -6
- package/dist/cli/commands/driver/driver.js.map +1 -1
- package/dist/cli/commands/flags.js +9 -9
- package/dist/cli/commands/flags.js.map +1 -1
- package/dist/cli/commands/index.js +2 -2
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/project/build.js +2 -2
- package/dist/cli/commands/project/build.js.map +1 -1
- package/dist/cli/commands/project/create.js +3 -3
- package/dist/cli/commands/project/create.js.map +1 -1
- package/dist/cli/commands/project/deploy.js +2 -2
- package/dist/cli/commands/project/deploy.js.map +1 -1
- package/dist/cli/commands/project/develop.js +19 -19
- package/dist/cli/commands/project/develop.js.map +1 -1
- package/dist/cli/commands/project/project.js +2 -2
- package/dist/cli/commands/project/project.js.map +1 -1
- package/dist/cli/commands/project/source.js +62 -37
- package/dist/cli/commands/project/source.js.map +1 -1
- package/dist/cli/commands/repl/api.js +2 -2
- package/dist/cli/commands/repl/api.js.map +1 -1
- package/dist/cli/commands/repl/repl.js +4 -4
- package/dist/cli/commands/repl/repl.js.map +1 -1
- package/dist/cli/commands/repl/reset.js +2 -2
- package/dist/cli/commands/repl/reset.js.map +1 -1
- package/dist/cli/commands/repl/run.js +5 -5
- package/dist/cli/commands/repl/run.js.map +1 -1
- package/dist/cli/commands/sideload/install.js +4 -4
- package/dist/cli/commands/sideload/install.js.map +1 -1
- package/dist/cli/commands/sideload/setup.js +3 -3
- package/dist/cli/commands/sideload/setup.js.map +1 -1
- package/dist/cli/commands/sideload/sideload.js +2 -2
- package/dist/cli/commands/sideload/sideload.js.map +1 -1
- package/dist/cli/commands/sideload/uninstall.js +2 -2
- package/dist/cli/commands/sideload/uninstall.js.map +1 -1
- package/dist/cli/commands/sideload/update.js +3 -3
- package/dist/cli/commands/sideload/update.js.map +1 -1
- package/dist/cli/commands/swiplet/call.js +6 -6
- package/dist/cli/commands/swiplet/call.js.map +1 -1
- package/dist/cli/commands/swiplet/install.js +3 -3
- package/dist/cli/commands/swiplet/install.js.map +1 -1
- package/dist/cli/commands/swiplet/list.js +8 -8
- package/dist/cli/commands/swiplet/list.js.map +1 -1
- package/dist/cli/commands/swiplet/remove.js +3 -3
- package/dist/cli/commands/swiplet/remove.js.map +1 -1
- package/dist/cli/commands/swiplet/service/disable.js +3 -3
- package/dist/cli/commands/swiplet/service/disable.js.map +1 -1
- package/dist/cli/commands/swiplet/service/enable.js +3 -3
- package/dist/cli/commands/swiplet/service/enable.js.map +1 -1
- package/dist/cli/commands/swiplet/service/service.js +2 -2
- package/dist/cli/commands/swiplet/service/service.js.map +1 -1
- package/dist/cli/commands/swiplet/service/services.js +2 -2
- package/dist/cli/commands/swiplet/service/services.js.map +1 -1
- package/dist/cli/commands/swiplet/service/watch.js +2 -2
- package/dist/cli/commands/swiplet/service/watch.js.map +1 -1
- package/dist/cli/commands/swiplet/show.js +6 -6
- package/dist/cli/commands/swiplet/show.js.map +1 -1
- package/dist/cli/commands/swiplet/swiplet.js +4 -4
- package/dist/cli/commands/swiplet/swiplet.js.map +1 -1
- package/dist/cli/commands/version/version.js +2 -2
- package/dist/cli/commands/version/version.js.map +1 -1
- package/dist/cli/deploy.js +9 -7
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/session.js.map +1 -1
- package/dist/client.d.ts +145 -7
- package/dist/client.js +20 -22
- package/dist/client.js.map +1 -1
- package/dist/connection.d.ts +292 -25
- package/dist/connection.js +36 -35
- package/dist/connection.js.map +1 -1
- package/dist/driver.d.ts +62 -23
- package/dist/driver.js +29 -33
- package/dist/driver.js.map +1 -1
- package/dist/i18n.d.ts +2 -5
- package/dist/i18n.js +15 -13
- package/dist/i18n.js.map +1 -1
- package/dist/i18next.d.ts +7 -0
- package/dist/ignore.d.ts +14 -7
- package/dist/ignore.js +13 -14
- package/dist/ignore.js.map +1 -1
- package/dist/mdns.d.ts +2 -2
- package/dist/mdns.js +1 -1
- package/dist/mdns.js.map +1 -1
- package/dist/metro.d.ts +19 -5
- package/dist/metro.js +61 -63
- package/dist/metro.js.map +1 -1
- package/dist/output.d.ts +29 -14
- package/dist/output.js +17 -15
- package/dist/output.js.map +1 -1
- package/dist/passcode.d.ts +12 -8
- package/dist/passcode.js +18 -18
- package/dist/passcode.js.map +1 -1
- package/dist/project.d.ts +20 -10
- package/dist/project.js +72 -49
- package/dist/project.js.map +1 -1
- package/dist/proto/common_pb.d.ts +240 -0
- package/dist/proto/common_pb.js +7 -2
- package/dist/proto/common_pb.js.map +1 -1
- package/dist/proto/logs_pb.d.ts +38 -0
- package/dist/proto/repl_pb.d.ts +96 -0
- package/dist/proto/swiplets_pb.d.ts +361 -0
- package/dist/proto/swiplets_pb.js +7 -2
- package/dist/proto/swiplets_pb.js.map +1 -1
- package/dist/proto/system_pb.d.ts +33 -0
- package/dist/resources.d.ts +400 -0
- package/dist/serve.d.ts +9 -1
- package/dist/serve.js +17 -16
- package/dist/serve.js.map +1 -1
- package/dist/sideload.d.ts +27 -14
- package/dist/sideload.js +102 -89
- package/dist/sideload.js.map +1 -1
- package/dist/swipt-app.d.ts +19 -9
- package/dist/swipt-app.js +1 -1
- package/dist/swipt-app.js.map +1 -1
- package/locales/ar/translation.json +413 -0
- package/locales/bg/translation.json +397 -0
- package/locales/bn/translation.json +397 -0
- package/locales/ca/translation.json +401 -0
- package/locales/cs/translation.json +405 -0
- package/locales/da/translation.json +397 -0
- package/locales/de/translation.json +397 -0
- package/locales/el/translation.json +397 -0
- package/locales/en/translation.json +397 -0
- package/locales/es/translation.json +401 -0
- package/locales/es-419/translation.json +401 -0
- package/locales/fi/translation.json +397 -0
- package/locales/fr/translation.json +401 -0
- package/locales/fr-CA/translation.json +401 -0
- package/locales/gu/translation.json +397 -0
- package/locales/he/translation.json +401 -0
- package/locales/hi/translation.json +397 -0
- package/locales/hr/translation.json +401 -0
- package/locales/hu/translation.json +397 -0
- package/locales/id/translation.json +393 -0
- package/locales/it/translation.json +401 -0
- package/locales/ja/translation.json +393 -0
- package/locales/kk/translation.json +397 -0
- package/locales/kn/translation.json +397 -0
- package/locales/ko/translation.json +393 -0
- package/locales/lt/translation.json +405 -0
- package/locales/ml/translation.json +397 -0
- package/locales/mr/translation.json +397 -0
- package/locales/ms/translation.json +393 -0
- package/locales/nb/translation.json +397 -0
- package/locales/nl/translation.json +397 -0
- package/locales/or/translation.json +397 -0
- package/locales/pa/translation.json +397 -0
- package/locales/pl/translation.json +405 -0
- package/locales/pt-BR/translation.json +401 -0
- package/locales/pt-PT/translation.json +401 -0
- package/locales/ro/translation.json +401 -0
- package/locales/ru/translation.json +405 -0
- package/locales/sk/translation.json +405 -0
- package/locales/sl/translation.json +405 -0
- package/locales/sv/translation.json +397 -0
- package/locales/ta/translation.json +397 -0
- package/locales/te/translation.json +397 -0
- package/locales/th/translation.json +393 -0
- package/locales/tr/translation.json +397 -0
- package/locales/uk/translation.json +405 -0
- package/locales/ur/translation.json +397 -0
- package/locales/vi/translation.json +397 -0
- package/locales/zh-HK/translation.json +393 -0
- package/locales/zh-Hans/translation.json +393 -0
- package/locales/zh-Hant/translation.json +393 -0
- package/package.json +14 -9
- package/locales/ar.json +0 -311
- package/locales/bg.json +0 -295
- package/locales/bn.json +0 -295
- package/locales/ca.json +0 -299
- package/locales/cs.json +0 -303
- package/locales/da.json +0 -295
- package/locales/de.json +0 -295
- package/locales/el.json +0 -295
- package/locales/es-419.json +0 -299
- package/locales/es.json +0 -299
- package/locales/fi.json +0 -295
- package/locales/fr-CA.json +0 -299
- package/locales/fr.json +0 -299
- package/locales/gu.json +0 -295
- package/locales/he.json +0 -299
- package/locales/hi.json +0 -295
- package/locales/hr.json +0 -299
- package/locales/hu.json +0 -295
- package/locales/id.json +0 -283
- package/locales/it.json +0 -299
- package/locales/ja.json +0 -283
- package/locales/kk.json +0 -295
- package/locales/kn.json +0 -295
- package/locales/ko.json +0 -283
- package/locales/lt.json +0 -303
- package/locales/ml.json +0 -295
- package/locales/mr.json +0 -295
- package/locales/ms.json +0 -283
- package/locales/nb.json +0 -295
- package/locales/nl.json +0 -295
- package/locales/or.json +0 -295
- package/locales/pa.json +0 -295
- package/locales/pl.json +0 -303
- package/locales/pt-BR.json +0 -299
- package/locales/pt-PT.json +0 -299
- package/locales/ro.json +0 -299
- package/locales/ru.json +0 -303
- package/locales/sk.json +0 -303
- package/locales/sl.json +0 -303
- package/locales/sv.json +0 -295
- package/locales/ta.json +0 -295
- package/locales/te.json +0 -295
- package/locales/th.json +0 -283
- package/locales/tr.json +0 -295
- package/locales/uk.json +0 -303
- package/locales/ur.json +0 -295
- package/locales/vi.json +0 -295
- package/locales/zh-HK.json +0 -283
- package/locales/zh-Hans.json +0 -283
- package/locales/zh-Hant.json +0 -283
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swiplet.js","names":[],"sources":["../../../../src/cli/commands/swiplet/swiplet.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"swiplet.js","names":[],"sources":["../../../../src/cli/commands/swiplet/swiplet.ts"],"sourcesContent":["import { t } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { data } from \"../data\";\nimport type { DataTarget } from \"../data/operand\";\nimport { deviceOption } from \"../flags\";\nimport { call } from \"./call\";\nimport { install } from \"./install\";\nimport { list } from \"./list\";\nimport { remove } from \"./remove\";\nimport { service } from \"./service\";\nimport { show } from \"./show\";\n\nconst swipletData = ([id, ...args]: string[]): DataTarget => ({\n id,\n wholeDirectory: (name) =>\n t(\"commands.swiplet.dataDirectory\", { path: name, swiplet: id }),\n subdirectory: (name) =>\n t(\"commands.swiplet.directory\", { path: name, swiplet: id }),\n args,\n});\n\nexport const swiplet = defineCommand({\n name: \"swiplet\",\n short: t(\"commands.swiplet.description\"),\n options: deviceOption,\n commands: [\n list,\n show,\n install,\n remove,\n call,\n service,\n data(\"ID \", swipletData),\n ],\n});\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAM,eAAe,CAAC,IAAI,GAAG,WAAiC;CAC5D;CACA,iBAAiB,SACf,EAAE,kCAAkC;EAAE,MAAM;EAAM,SAAS;CAAG,CAAC;CACjE,eAAe,SACb,EAAE,8BAA8B;EAAE,MAAM;EAAM,SAAS;CAAG,CAAC;CAC7D;AACF;AAEA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,OAAO,EAAE,8BAA8B;CACvC,SAAS;CACT,UAAU;EACR;EACA;EACA;EACA;EACA;EACA;EACA,KAAK,OAAO,WAAW;CACzB;AACF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t } from "../../../i18n.js";
|
|
2
2
|
import { defineCommand } from "../../command.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
// src/cli/commands/version/version.ts
|
|
@@ -8,7 +8,7 @@ function printVersion() {
|
|
|
8
8
|
}
|
|
9
9
|
const version = defineCommand({
|
|
10
10
|
name: "version",
|
|
11
|
-
short:
|
|
11
|
+
short: t("commands.version.description"),
|
|
12
12
|
args: [0, 0],
|
|
13
13
|
run: printVersion
|
|
14
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../../../src/cli/commands/version/version.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../../../src/cli/commands/version/version.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { t } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\n\nconst { version: packageVersion }: { version: string } = createRequire(\n import.meta.url,\n)(\"../../../../package.json\");\n\nfunction printVersion() {\n console.log(\n \"swipt\",\n packageVersion,\n `node ${process.versions.node}`,\n `${process.platform}/${process.arch}`,\n );\n}\n\nexport const version = defineCommand({\n name: \"version\",\n short: t(\"commands.version.description\"),\n args: [0, 0],\n run: printVersion,\n});\n"],"mappings":";;;;AAKA,MAAM,EAAE,SAAS,mBAAwC,cACvD,YAAY,GACd,CAAC,CAAC,0BAA0B;AAE5B,SAAS,eAAe;CACtB,QAAQ,IACN,SACA,gBACA,QAAQ,QAAQ,SAAS,QACzB,GAAG,QAAQ,SAAS,GAAG,QAAQ,MACjC;AACF;AAEA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,OAAO,EAAE,8BAA8B;CACvC,MAAM,CAAC,GAAG,CAAC;CACX,KAAK;AACP,CAAC"}
|
package/dist/cli/deploy.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t } from "../i18n.js";
|
|
2
|
+
import { SwipletSchema } from "../proto/swiplets_pb.js";
|
|
2
3
|
import { uploadChunk } from "./io.js";
|
|
3
4
|
import fs from "node:fs";
|
|
5
|
+
import { create } from "@bufbuild/protobuf";
|
|
4
6
|
// src/cli/deploy.ts
|
|
5
7
|
async function deploy(client, archive, signal) {
|
|
6
8
|
const data = fs.readFileSync(archive);
|
|
@@ -8,12 +10,12 @@ async function deploy(client, archive, signal) {
|
|
|
8
10
|
for (let offset = 0; offset < data.length || offset === 0; offset += uploadChunk) yield { chunk: data.subarray(offset, offset + uploadChunk) };
|
|
9
11
|
})(), { signal });
|
|
10
12
|
}
|
|
11
|
-
const printDeployed = (
|
|
12
|
-
id:
|
|
13
|
-
version:
|
|
14
|
-
}) :
|
|
15
|
-
id:
|
|
16
|
-
version:
|
|
13
|
+
const printDeployed = ({ replaced, swiplet = create(SwipletSchema) }, toStdout) => (toStdout ? console.log : console.error)(replaced ? t("deploy.replaced", {
|
|
14
|
+
id: swiplet.id,
|
|
15
|
+
version: swiplet.version
|
|
16
|
+
}) : t("deploy.installed", {
|
|
17
|
+
id: swiplet.id,
|
|
18
|
+
version: swiplet.version
|
|
17
19
|
}));
|
|
18
20
|
export { deploy, printDeployed };
|
|
19
21
|
|
package/dist/cli/deploy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.js","names":[],"sources":["../../src/cli/deploy.ts"],"sourcesContent":["import fs from \"node:fs\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"deploy.js","names":[],"sources":["../../src/cli/deploy.ts"],"sourcesContent":["import fs from \"node:fs\";\n\nimport { create } from \"@bufbuild/protobuf\";\n\nimport type { Client } from \"../client\";\nimport { t } from \"../i18n\";\nimport {\n type DeploySwipletResponse,\n SwipletSchema,\n} from \"../proto/swiplets_pb\";\nimport { uploadChunk } from \"./io\";\n\nexport async function deploy(\n client: Client,\n archive: string,\n signal: AbortSignal,\n) {\n const data = fs.readFileSync(archive);\n return client.swiplets.deploySwiplet(\n (async function* () {\n for (\n let offset = 0;\n offset < data.length || offset === 0;\n offset += uploadChunk\n ) {\n yield { chunk: data.subarray(offset, offset + uploadChunk) };\n }\n })(),\n { signal },\n );\n}\n\nexport const printDeployed = (\n { replaced, swiplet = create(SwipletSchema) }: DeploySwipletResponse,\n toStdout: boolean,\n) =>\n (toStdout ? console.log : console.error)(\n replaced\n ? t(\"deploy.replaced\", { id: swiplet.id, version: swiplet.version })\n : t(\"deploy.installed\", { id: swiplet.id, version: swiplet.version }),\n );\n"],"mappings":";;;;;;AAYA,eAAsB,OACpB,QACA,SACA,QACA;CACA,MAAM,OAAO,GAAG,aAAa,OAAO;CACpC,OAAO,OAAO,SAAS,eACpB,mBAAmB;EAClB,KACE,IAAI,SAAS,GACb,SAAS,KAAK,UAAU,WAAW,GACnC,UAAU,aAEV,MAAM,EAAE,OAAO,KAAK,SAAS,QAAQ,SAAS,WAAW,EAAE;CAE/D,EAAA,CAAG,GACH,EAAE,OAAO,CACX;AACF;AAEA,MAAa,iBACX,EAAE,UAAU,UAAU,OAAO,aAAa,KAC1C,cAEC,WAAW,QAAQ,MAAM,QAAQ,MAAA,CAChC,WACI,EAAE,mBAAmB;CAAE,IAAI,QAAQ;CAAI,SAAS,QAAQ;AAAQ,CAAC,IACjE,EAAE,oBAAoB;CAAE,IAAI,QAAQ;CAAI,SAAS,QAAQ;AAAQ,CAAC,CACxE"}
|
package/dist/cli/session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","names":[],"sources":["../../src/cli/session.ts"],"sourcesContent":["import { attach } from \"../connection\";\n\nexport const session = (context
|
|
1
|
+
{"version":3,"file":"session.js","names":[],"sources":["../../src/cli/session.ts"],"sourcesContent":["import type { Client } from \"../client\";\nimport { attach } from \"../connection\";\n\nexport const session = <Result>(\n context: Parameters<typeof attach>[0],\n run: (client: Client) => Result,\n) => attach(context).then(run);\n"],"mappings":";;AAGA,MAAa,WACX,SACA,QACG,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { GetInfoResponse } from "./proto/system_pb.js";
|
|
2
|
+
import { LogLevel } from "./proto/common_pb.js";
|
|
3
|
+
import { ReadLogsRequest, ReadLogsResponse } from "./proto/logs_pb.js";
|
|
4
|
+
import { CallActionRequest, CallActionResponse, DeploySwipletRequest, DeploySwipletResponse, ListDataFilesRequest, ListDataFilesResponse, ListSwipletsResponse, ReadDataFileRequest, ReadDataFileResponse, RemoveDataFileRequest, RemoveSwipletRequest, SetServiceEnabledRequest, SetServiceEnabledResponse, WatchServicesRequest, WatchServicesResponse, WriteDataFileHeader, WriteDataFileRequest, WriteDataFileResponse } from "./proto/swiplets_pb.js";
|
|
5
|
+
import { ExecuteRequest, ExecuteResponse, GetDeclarationsResponse } from "./proto/repl_pb.js";
|
|
6
|
+
import { Message } from "@bufbuild/protobuf";
|
|
1
7
|
export declare const Code: {
|
|
2
8
|
Canceled: number;
|
|
3
9
|
Unknown: number;
|
|
@@ -13,13 +19,145 @@ export declare class RpcError extends Error {
|
|
|
13
19
|
code: number;
|
|
14
20
|
constructor(code: number, message?: string);
|
|
15
21
|
}
|
|
22
|
+
export interface CallOptions {
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
16
25
|
export declare function open({ url, token }: {
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
url: string;
|
|
27
|
+
token: string;
|
|
19
28
|
}): {
|
|
20
|
-
system:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
system: {
|
|
30
|
+
getInfo: (input: Message<"google.protobuf.Empty"> | {
|
|
31
|
+
readonly $typeName?: undefined;
|
|
32
|
+
}, options?: CallOptions) => Promise<GetInfoResponse>;
|
|
33
|
+
shutdown: (input: Message<"google.protobuf.Empty"> | {
|
|
34
|
+
readonly $typeName?: undefined;
|
|
35
|
+
}, options?: CallOptions) => Promise<Message<"google.protobuf.Empty">>;
|
|
36
|
+
};
|
|
37
|
+
logs: {
|
|
38
|
+
readLogs: (input: {
|
|
39
|
+
readonly $typeName?: undefined;
|
|
40
|
+
level?: LogLevel | undefined;
|
|
41
|
+
swipletId?: string | undefined;
|
|
42
|
+
since?: ({
|
|
43
|
+
readonly $typeName?: undefined;
|
|
44
|
+
seconds?: bigint | undefined;
|
|
45
|
+
nanos?: number | undefined;
|
|
46
|
+
} | import("@bufbuild/protobuf/wkt").Timestamp) | undefined;
|
|
47
|
+
tail?: number | undefined;
|
|
48
|
+
follow?: boolean | undefined;
|
|
49
|
+
} | ReadLogsRequest, options?: CallOptions) => AsyncGenerator<ReadLogsResponse, void, any>;
|
|
50
|
+
};
|
|
51
|
+
swiplets: {
|
|
52
|
+
listSwiplets: (input: Message<"google.protobuf.Empty"> | {
|
|
53
|
+
readonly $typeName?: undefined;
|
|
54
|
+
}, options?: CallOptions) => Promise<ListSwipletsResponse>;
|
|
55
|
+
callAction: (input: {
|
|
56
|
+
readonly $typeName?: undefined;
|
|
57
|
+
swipletId?: string | undefined;
|
|
58
|
+
action?: string | undefined;
|
|
59
|
+
input?: ({
|
|
60
|
+
readonly $typeName?: undefined;
|
|
61
|
+
kind?: {
|
|
62
|
+
case: "listValue";
|
|
63
|
+
value: {
|
|
64
|
+
readonly $typeName?: undefined;
|
|
65
|
+
values?: ( /*elided*/ any | import("@bufbuild/protobuf/wkt").Value)[] | undefined;
|
|
66
|
+
} | import("@bufbuild/protobuf/wkt").ListValue;
|
|
67
|
+
} | {
|
|
68
|
+
case: "structValue";
|
|
69
|
+
value: {
|
|
70
|
+
readonly $typeName?: undefined;
|
|
71
|
+
fields?: {
|
|
72
|
+
[key: string]: /*elided*/ any | import("@bufbuild/protobuf/wkt").Value;
|
|
73
|
+
[key: number]: /*elided*/ any | import("@bufbuild/protobuf/wkt").Value;
|
|
74
|
+
} | undefined;
|
|
75
|
+
} | import("@bufbuild/protobuf/wkt").Struct;
|
|
76
|
+
} | {
|
|
77
|
+
value: import("@bufbuild/protobuf/wkt").NullValue;
|
|
78
|
+
case: "nullValue";
|
|
79
|
+
} | {
|
|
80
|
+
value: number;
|
|
81
|
+
case: "numberValue";
|
|
82
|
+
} | {
|
|
83
|
+
value: string;
|
|
84
|
+
case: "stringValue";
|
|
85
|
+
} | {
|
|
86
|
+
value: boolean;
|
|
87
|
+
case: "boolValue";
|
|
88
|
+
} | {
|
|
89
|
+
case: undefined;
|
|
90
|
+
value?: undefined;
|
|
91
|
+
} | undefined;
|
|
92
|
+
} | import("@bufbuild/protobuf/wkt").Value) | undefined;
|
|
93
|
+
} | CallActionRequest, options?: CallOptions) => AsyncGenerator<CallActionResponse, void, any>;
|
|
94
|
+
setServiceEnabled: (input: {
|
|
95
|
+
readonly $typeName?: undefined;
|
|
96
|
+
swipletId?: string | undefined;
|
|
97
|
+
enabled?: boolean | undefined;
|
|
98
|
+
} | SetServiceEnabledRequest, options?: CallOptions) => Promise<SetServiceEnabledResponse>;
|
|
99
|
+
watchServices: (input: {
|
|
100
|
+
readonly $typeName?: undefined;
|
|
101
|
+
swipletId?: string | undefined;
|
|
102
|
+
} | WatchServicesRequest, options?: CallOptions) => AsyncGenerator<WatchServicesResponse, void, any>;
|
|
103
|
+
deploySwiplet: (input: AsyncIterable<{
|
|
104
|
+
readonly $typeName?: undefined;
|
|
105
|
+
chunk?: Uint8Array<ArrayBufferLike> | undefined;
|
|
106
|
+
} | DeploySwipletRequest>, options?: CallOptions) => Promise<DeploySwipletResponse>;
|
|
107
|
+
removeSwiplet: (input: {
|
|
108
|
+
readonly $typeName?: undefined;
|
|
109
|
+
swipletId?: string | undefined;
|
|
110
|
+
} | RemoveSwipletRequest, options?: CallOptions) => Promise<Message<"google.protobuf.Empty">>;
|
|
111
|
+
listDataFiles: (input: {
|
|
112
|
+
readonly $typeName?: undefined;
|
|
113
|
+
swipletId?: string | undefined;
|
|
114
|
+
path?: string | undefined;
|
|
115
|
+
recursive?: boolean | undefined;
|
|
116
|
+
} | ListDataFilesRequest, options?: CallOptions) => Promise<ListDataFilesResponse>;
|
|
117
|
+
readDataFile: (input: {
|
|
118
|
+
readonly $typeName?: undefined;
|
|
119
|
+
swipletId?: string | undefined;
|
|
120
|
+
path?: string | undefined;
|
|
121
|
+
} | ReadDataFileRequest, options?: CallOptions) => AsyncGenerator<ReadDataFileResponse, void, any>;
|
|
122
|
+
writeDataFile: (input: AsyncIterable<{
|
|
123
|
+
readonly $typeName?: undefined;
|
|
124
|
+
part?: {
|
|
125
|
+
case: "header";
|
|
126
|
+
value: {
|
|
127
|
+
readonly $typeName?: undefined;
|
|
128
|
+
swipletId?: string | undefined;
|
|
129
|
+
path?: string | undefined;
|
|
130
|
+
} | WriteDataFileHeader;
|
|
131
|
+
} | {
|
|
132
|
+
value: Uint8Array;
|
|
133
|
+
case: "data";
|
|
134
|
+
} | {
|
|
135
|
+
case: undefined;
|
|
136
|
+
value?: undefined;
|
|
137
|
+
} | undefined;
|
|
138
|
+
} | WriteDataFileRequest>, options?: CallOptions) => Promise<WriteDataFileResponse>;
|
|
139
|
+
removeDataFile: (input: {
|
|
140
|
+
readonly $typeName?: undefined;
|
|
141
|
+
swipletId?: string | undefined;
|
|
142
|
+
path?: string | undefined;
|
|
143
|
+
recursive?: boolean | undefined;
|
|
144
|
+
} | RemoveDataFileRequest, options?: CallOptions) => Promise<Message<"google.protobuf.Empty">>;
|
|
145
|
+
};
|
|
146
|
+
repl: {
|
|
147
|
+
execute: (input: {
|
|
148
|
+
readonly $typeName?: undefined;
|
|
149
|
+
code?: string | undefined;
|
|
150
|
+
timeoutMs?: number | undefined;
|
|
151
|
+
args?: string[] | undefined;
|
|
152
|
+
program?: boolean | undefined;
|
|
153
|
+
} | ExecuteRequest, options?: CallOptions) => AsyncGenerator<ExecuteResponse, void, any>;
|
|
154
|
+
reset: (input: Message<"google.protobuf.Empty"> | {
|
|
155
|
+
readonly $typeName?: undefined;
|
|
156
|
+
}, options?: CallOptions) => Promise<Message<"google.protobuf.Empty">>;
|
|
157
|
+
getDeclarations: (input: Message<"google.protobuf.Empty"> | {
|
|
158
|
+
readonly $typeName?: undefined;
|
|
159
|
+
}, options?: CallOptions) => Promise<GetDeclarationsResponse>;
|
|
160
|
+
};
|
|
24
161
|
};
|
|
25
|
-
export
|
|
162
|
+
export type Client = ReturnType<typeof open>;
|
|
163
|
+
export declare const unauthenticated: (error: unknown) => boolean;
|
package/dist/client.js
CHANGED
|
@@ -41,18 +41,19 @@ const httpStatusCodes = {
|
|
|
41
41
|
504: Code.Unavailable
|
|
42
42
|
};
|
|
43
43
|
function statusMessage(text) {
|
|
44
|
-
if (text === void 0
|
|
44
|
+
if (text === void 0) return "";
|
|
45
45
|
try {
|
|
46
46
|
return decodeURIComponent(text);
|
|
47
47
|
} catch {
|
|
48
48
|
return text;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
const causeText = (cause) => cause?.errors?.length
|
|
51
|
+
const causeText = (cause) => cause?.errors?.length ? cause.errors.map(causeText).join("; ") : cause?.message || cause?.code;
|
|
52
52
|
const transportError = (error) => {
|
|
53
53
|
if (error instanceof RpcError) return error;
|
|
54
|
-
if (error
|
|
55
|
-
return new RpcError(Code.
|
|
54
|
+
if (!(error instanceof Error)) return new RpcError(Code.Unavailable, String(error));
|
|
55
|
+
if (error.name === "AbortError") return new RpcError(Code.Canceled, "the call was canceled");
|
|
56
|
+
return new RpcError(Code.Unavailable, causeText(error.cause) || error.message || String(error));
|
|
56
57
|
};
|
|
57
58
|
async function locate(connection, signal) {
|
|
58
59
|
const url = new URL(connection.url);
|
|
@@ -109,7 +110,7 @@ var FrameReader = class {
|
|
|
109
110
|
};
|
|
110
111
|
function checkStatus(headers) {
|
|
111
112
|
const status = headers["grpc-status"];
|
|
112
|
-
if (status === void 0
|
|
113
|
+
if (status === void 0) return false;
|
|
113
114
|
const code = Number(status);
|
|
114
115
|
if (code !== 0) throw new RpcError(code, statusMessage(headers["grpc-message"]));
|
|
115
116
|
return true;
|
|
@@ -147,7 +148,7 @@ async function* invokeHTTP(connection, method, input, { signal }) {
|
|
|
147
148
|
const reader = new FrameReader(method.output);
|
|
148
149
|
let ended = false;
|
|
149
150
|
try {
|
|
150
|
-
for await (const chunk of response.body) for (const found of reader.push(chunk)) if (found
|
|
151
|
+
for await (const chunk of response.body ?? []) for (const found of reader.push(chunk)) if ("trailers" in found) {
|
|
151
152
|
checkStatus(found.trailers);
|
|
152
153
|
ended = true;
|
|
153
154
|
} else if (!ended) yield found.message;
|
|
@@ -184,7 +185,7 @@ async function* invokeWebSocket(connection, method, input, { signal }) {
|
|
|
184
185
|
});
|
|
185
186
|
socket.addEventListener("message", (event) => {
|
|
186
187
|
try {
|
|
187
|
-
for (const found of reader.push(new Uint8Array(event.data))) if (found
|
|
188
|
+
for (const found of reader.push(new Uint8Array(event.data))) if ("message" in found) messages.push(found.message);
|
|
188
189
|
else if (headersSeen || "grpc-status" in found.trailers) {
|
|
189
190
|
checkStatus(found.trailers);
|
|
190
191
|
closed = true;
|
|
@@ -210,8 +211,7 @@ async function* invokeWebSocket(connection, method, input, { signal }) {
|
|
|
210
211
|
socket.send(Buffer.from(`${Object.entries(headers).map(([key, value]) => `${key}: ${value}\r\n`).join("")}`));
|
|
211
212
|
(async () => {
|
|
212
213
|
try {
|
|
213
|
-
|
|
214
|
-
for await (const message of body) {
|
|
214
|
+
for await (const message of input) {
|
|
215
215
|
if (closed || failure) return;
|
|
216
216
|
socket.send(Buffer.concat([Buffer.from([0]), frame(method.input, message)]));
|
|
217
217
|
}
|
|
@@ -221,8 +221,9 @@ async function* invokeWebSocket(connection, method, input, { signal }) {
|
|
|
221
221
|
}
|
|
222
222
|
})();
|
|
223
223
|
while (true) {
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
const message = messages.shift();
|
|
225
|
+
if (message !== void 0) {
|
|
226
|
+
yield message;
|
|
226
227
|
continue;
|
|
227
228
|
}
|
|
228
229
|
if (closed || failure) break;
|
|
@@ -243,21 +244,18 @@ async function single(iterable) {
|
|
|
243
244
|
return found;
|
|
244
245
|
}
|
|
245
246
|
function bind(service, connection) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
return client;
|
|
247
|
+
return Object.fromEntries(service.methods.map((method) => [method.localName, (input, options = {}) => {
|
|
248
|
+
switch (method.methodKind) {
|
|
249
|
+
case "unary": return single(invokeHTTP(connection, method, input, options));
|
|
250
|
+
case "server_streaming": return invokeHTTP(connection, method, input, options);
|
|
251
|
+
default: return single(invokeWebSocket(connection, method, input, options));
|
|
252
|
+
}
|
|
253
|
+
}]));
|
|
255
254
|
}
|
|
256
255
|
function open({ url, token }) {
|
|
257
256
|
const connection = {
|
|
258
257
|
url,
|
|
259
|
-
token
|
|
260
|
-
resolved: void 0
|
|
258
|
+
token
|
|
261
259
|
};
|
|
262
260
|
return {
|
|
263
261
|
system: bind(SystemService, connection),
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["import dns from \"node:dns\";\nimport { createRequire } from \"node:module\";\n\nimport { create, fromBinary, toBinary } from \"@bufbuild/protobuf\";\n\nimport { resolveHost } from \"./mdns\";\nimport { LogService } from \"./proto/logs_pb\";\nimport { REPLService } from \"./proto/repl_pb\";\nimport { SwipletService } from \"./proto/swiplets_pb\";\nimport { SystemService } from \"./proto/system_pb\";\n\nconst largestMessage = 128 << 20;\nconst resolveLimit = 5000;\nconst contentType = \"application/grpc-web+proto\";\nconst webSocketSubprotocol = \"grpc-websockets\";\nconst { apiLevel } = createRequire(import.meta.url)(\"@swipt/api/package.json\");\n\ndns.setDefaultResultOrder(\"ipv4first\");\n\nexport const Code = {\n Canceled: 1,\n Unknown: 2,\n DeadlineExceeded: 4,\n NotFound: 5,\n Unimplemented: 12,\n Internal: 13,\n Unavailable: 14,\n Unauthenticated: 16,\n};\n\nexport class UsageError extends Error {}\n\nexport class RpcError extends Error {\n declare code: number;\n\n constructor(code: number, message?: string) {\n super(message);\n this.code = code;\n }\n}\n\nconst httpStatusCodes = {\n 400: Code.Internal,\n 401: Code.Unauthenticated,\n 403: Code.Unauthenticated,\n 404: Code.Unimplemented,\n 429: Code.Unavailable,\n 502: Code.Unavailable,\n 503: Code.Unavailable,\n 504: Code.Unavailable,\n};\n\nfunction statusMessage(text) {\n if (text === undefined || text === null) {\n return \"\";\n }\n try {\n return decodeURIComponent(text);\n } catch {\n return text;\n }\n}\n\nconst causeText = (cause) =>\n cause?.errors?.length > 0\n ? cause.errors.map(causeText).join(\"; \")\n : cause?.message || cause?.code;\n\nconst transportError = (error) => {\n if (error instanceof RpcError) {\n return error;\n }\n if (error?.name === \"AbortError\") {\n return new RpcError(Code.Canceled, \"the call was canceled\");\n }\n return new RpcError(\n Code.Unavailable,\n causeText(error?.cause) || error?.message || String(error),\n );\n};\n\nasync function locate(connection, signal) {\n const url = new URL(connection.url);\n if (!url.hostname.endsWith(\".local\")) {\n return connection.url;\n }\n let address;\n try {\n address = await resolveHost(\n url.hostname,\n AbortSignal.any([\n ...(signal ? [signal] : []),\n AbortSignal.timeout(resolveLimit),\n ]),\n );\n } catch (error) {\n throw transportError(error);\n }\n if (signal?.aborted) {\n throw new RpcError(Code.Canceled, \"the call was canceled\");\n }\n if (address === undefined) {\n throw new RpcError(\n Code.Unavailable,\n `${url.hostname} isn't found on the local network`,\n );\n }\n url.hostname = address.includes(\":\") ? `[${address}]` : address;\n return url.href.replace(/\\/+$/, \"\");\n}\n\nasync function base(connection, signal) {\n connection.resolved ??= await locate(connection, signal);\n return connection.resolved;\n}\n\nfunction frame(schema, init) {\n const body = toBinary(schema, create(schema, init));\n const out = Buffer.allocUnsafe(5 + body.length);\n out[0] = 0;\n out.writeUInt32BE(body.length, 1);\n out.set(body, 5);\n return out;\n}\n\nfunction parseMetadata(body) {\n const headers = {};\n for (const line of Buffer.from(body).toString().split(\"\\r\\n\")) {\n const separator = line.indexOf(\":\");\n if (separator > 0) {\n headers[line.slice(0, separator).trim().toLowerCase()] = line\n .slice(separator + 1)\n .trim();\n }\n }\n return headers;\n}\n\nclass FrameReader {\n declare schema: any;\n pending = Buffer.alloc(0);\n\n constructor(schema) {\n this.schema = schema;\n }\n\n push(chunk) {\n this.pending =\n this.pending.length === 0\n ? Buffer.from(chunk)\n : Buffer.concat([this.pending, Buffer.from(chunk)]);\n const frames = [];\n while (this.pending.length >= 5) {\n const length = this.pending.readUInt32BE(1);\n if (length > largestMessage) {\n throw new RpcError(\n Code.Internal,\n `the server sent a message of ${length} bytes`,\n );\n }\n if (this.pending.length < 5 + length) {\n break;\n }\n const body = this.pending.subarray(5, 5 + length);\n frames.push(\n (this.pending[0] & 0x80) !== 0\n ? { trailers: parseMetadata(body) }\n : { message: fromBinary(this.schema, body) },\n );\n this.pending = this.pending.subarray(5 + length);\n }\n return frames;\n }\n}\n\nfunction checkStatus(headers) {\n const status = headers[\"grpc-status\"];\n if (status === undefined || status === null) {\n return false;\n }\n const code = Number(status);\n if (code !== 0) {\n throw new RpcError(code, statusMessage(headers[\"grpc-message\"]));\n }\n return true;\n}\n\nfunction requestHeaders(connection) {\n const headers: Record<string, string> = {\n \"content-type\": contentType,\n \"x-grpc-web\": \"1\",\n \"swipt-api-level\": String(apiLevel),\n };\n if (connection.token !== \"\") {\n headers.authorization = `Bearer ${connection.token}`;\n }\n return headers;\n}\n\nasync function* invokeHTTP(connection, method, input, { signal }) {\n let response;\n try {\n response = await fetch(\n `${await base(connection, signal)}/${method.parent.typeName}/${method.name}`,\n {\n method: \"POST\",\n headers: requestHeaders(connection),\n body: frame(method.input, input),\n signal,\n },\n );\n } catch (error) {\n throw transportError(error);\n }\n const headers = Object.fromEntries(response.headers);\n if (response.status !== 200) {\n await response.body?.cancel();\n throw new RpcError(\n httpStatusCodes[response.status] ?? Code.Unknown,\n `HTTP ${response.status}`,\n );\n }\n if (checkStatus(headers)) {\n await response.body?.cancel();\n return;\n }\n const reader = new FrameReader(method.output);\n let ended = false;\n try {\n for await (const chunk of response.body) {\n for (const found of reader.push(chunk)) {\n if (found.trailers) {\n checkStatus(found.trailers);\n ended = true;\n } else if (!ended) {\n yield found.message;\n }\n }\n }\n } catch (error) {\n throw transportError(error);\n }\n if (!ended) {\n throw new RpcError(Code.Unavailable, \"the response ended without a status\");\n }\n}\n\nasync function* invokeWebSocket(connection, method, input, { signal }) {\n if (signal?.aborted) {\n throw new RpcError(Code.Canceled, \"the call was canceled\");\n }\n const webSocketBase = (await base(connection, signal)).replace(/^http/, \"ws\");\n const socket = new WebSocket(\n `${webSocketBase}/${method.parent.typeName}/${method.name}`,\n [webSocketSubprotocol],\n );\n socket.binaryType = \"arraybuffer\";\n const reader = new FrameReader(method.output);\n const messages = [];\n let failure;\n let closed = false;\n let headersSeen = false;\n let wake: (value?: unknown) => void = () => {};\n const notify = () => {\n const current = wake;\n wake = () => {};\n current();\n };\n const fail = (error) => {\n failure ??= error;\n socket.close();\n notify();\n };\n const abort = () =>\n fail(new RpcError(Code.Canceled, \"the call was canceled\"));\n const opened = new Promise((resolve, reject) => {\n socket.addEventListener(\"open\", resolve, { once: true });\n socket.addEventListener(\n \"close\",\n () =>\n reject(\n failure ??\n new RpcError(\n Code.Unavailable,\n `cannot connect to ${webSocketBase}`,\n ),\n ),\n { once: true },\n );\n });\n socket.addEventListener(\"message\", (event) => {\n try {\n for (const found of reader.push(new Uint8Array(event.data))) {\n if (found.message) {\n messages.push(found.message);\n } else if (headersSeen || \"grpc-status\" in found.trailers) {\n checkStatus(found.trailers);\n closed = true;\n socket.close();\n } else {\n headersSeen = true;\n }\n }\n } catch (error) {\n fail(error);\n }\n notify();\n });\n socket.addEventListener(\"close\", (event) => {\n if (!closed) {\n failure ??= new RpcError(\n Code.Unavailable,\n event.reason || \"the connection closed before the response\",\n );\n }\n closed = true;\n notify();\n });\n socket.addEventListener(\"error\", () => {\n failure ??= new RpcError(\n Code.Unavailable,\n `cannot connect to ${webSocketBase}`,\n );\n });\n signal?.addEventListener(\"abort\", abort, { once: true });\n try {\n await opened;\n const headers = requestHeaders(connection);\n socket.send(\n Buffer.from(\n `${Object.entries(headers)\n .map(([key, value]) => `${key}: ${value}\\r\\n`)\n .join(\"\")}`,\n ),\n );\n void (async () => {\n try {\n const body = method.methodKind === \"client_streaming\" ? input : [input];\n for await (const message of body) {\n if (closed || failure) {\n return;\n }\n socket.send(\n Buffer.concat([Buffer.from([0]), frame(method.input, message)]),\n );\n }\n if (!closed && !failure) {\n socket.send(Buffer.from([1]));\n }\n } catch (error) {\n fail(transportError(error));\n }\n })();\n while (true) {\n if (messages.length > 0) {\n yield messages.shift();\n continue;\n }\n if (closed || failure) {\n break;\n }\n await new Promise((resolve) => {\n wake = resolve;\n });\n }\n if (failure) {\n throw failure;\n }\n } finally {\n signal?.removeEventListener(\"abort\", abort);\n if (socket.readyState !== WebSocket.CLOSED) {\n socket.close();\n }\n }\n}\n\nasync function single(iterable) {\n let found;\n for await (const message of iterable) {\n found ??= message;\n }\n if (found === undefined) {\n throw new RpcError(Code.Internal, \"the server sent no response\");\n }\n return found;\n}\n\nfunction bind(service, connection): Record<string, any> {\n const client: Record<string, any> = {};\n for (const method of service.methods) {\n const streamsInput =\n method.methodKind === \"client_streaming\" ||\n method.methodKind === \"bidi_streaming\";\n client[method.localName] = (\n input,\n options: { signal?: AbortSignal } = {},\n ) => {\n const call = (streamsInput ? invokeWebSocket : invokeHTTP)(\n connection,\n method,\n input,\n { signal: options.signal },\n );\n return method.methodKind === \"unary\" ||\n method.methodKind === \"client_streaming\"\n ? single(call)\n : call;\n };\n }\n return client;\n}\n\nexport function open({ url, token }) {\n const connection = { url, token, resolved: undefined };\n return {\n system: bind(SystemService, connection),\n logs: bind(LogService, connection),\n swiplets: bind(SwipletService, connection),\n repl: bind(REPLService, connection),\n };\n}\n\nexport const unauthentic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,OAAO;AACT;AAEA,SAAgB,KAAK,EAAE,KAAK,SAAS;CACnC,MAAM,aAAa;EAAE;EAAK;EAAO,UAAU,KAAA;CAAU;CACrD,OAAO;EACL,QAAQ,KAAK,eAAe,UAAU;EACtC,MAAM,KAAK,YAAY,UAAU;EACjC,UAAU,KAAK,gBAAgB,UAAU;EACzC,MAAM,KAAK,aAAa,UAAU;CACpC;AACF;AAEA,MAAa,mBAAmB,UAC9B,iBAAiB,YAAY,MAAM,SAAS,KAAK"}
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["import dns from \"node:dns\";\nimport { createRequire } from \"node:module\";\n\nimport {\n type DescMessage,\n type DescMethod,\n type DescService,\n type Message,\n type MessageInitShape,\n type MessageShape,\n create,\n fromBinary,\n toBinary,\n} from \"@bufbuild/protobuf\";\nimport type { GenService } from \"@bufbuild/protobuf/codegenv2\";\n\nimport { resolveHost } from \"./mdns\";\nimport { LogService } from \"./proto/logs_pb\";\nimport { REPLService } from \"./proto/repl_pb\";\nimport { SwipletService } from \"./proto/swiplets_pb\";\nimport { SystemService } from \"./proto/system_pb\";\n\nconst largestMessage = 128 << 20;\nconst resolveLimit = 5000;\nconst contentType = \"application/grpc-web+proto\";\nconst webSocketSubprotocol = \"grpc-websockets\";\nconst { apiLevel } = createRequire(import.meta.url)(\"@swipt/api/package.json\");\n\ndns.setDefaultResultOrder(\"ipv4first\");\n\nexport const Code = {\n Canceled: 1,\n Unknown: 2,\n DeadlineExceeded: 4,\n NotFound: 5,\n Unimplemented: 12,\n Internal: 13,\n Unavailable: 14,\n Unauthenticated: 16,\n};\n\nexport class UsageError extends Error {}\n\nexport class RpcError extends Error {\n declare code: number;\n\n constructor(code: number, message?: string) {\n super(message);\n this.code = code;\n }\n}\n\nconst httpStatusCodes: Record<number, number> = {\n 400: Code.Internal,\n 401: Code.Unauthenticated,\n 403: Code.Unauthenticated,\n 404: Code.Unimplemented,\n 429: Code.Unavailable,\n 502: Code.Unavailable,\n 503: Code.Unavailable,\n 504: Code.Unavailable,\n};\n\nfunction statusMessage(text: string | undefined) {\n if (text === undefined) {\n return \"\";\n }\n try {\n return decodeURIComponent(text);\n } catch {\n return text;\n }\n}\n\ninterface Cause {\n errors?: Cause[];\n message?: string;\n code?: string;\n}\n\nconst causeText = (cause?: Cause): string | undefined =>\n cause?.errors?.length\n ? cause.errors.map(causeText).join(\"; \")\n : cause?.message || cause?.code;\n\nconst transportError = (error: unknown) => {\n if (error instanceof RpcError) {\n return error;\n }\n if (!(error instanceof Error)) {\n return new RpcError(Code.Unavailable, String(error));\n }\n if (error.name === \"AbortError\") {\n return new RpcError(Code.Canceled, \"the call was canceled\");\n }\n return new RpcError(\n Code.Unavailable,\n causeText(error.cause as Cause) || error.message || String(error),\n );\n};\n\ninterface Connection {\n url: string;\n token: string;\n resolved?: string;\n}\n\nexport interface CallOptions {\n signal?: AbortSignal;\n}\n\nasync function locate(connection: Connection, signal?: AbortSignal) {\n const url = new URL(connection.url);\n if (!url.hostname.endsWith(\".local\")) {\n return connection.url;\n }\n let address;\n try {\n address = await resolveHost(\n url.hostname,\n AbortSignal.any([\n ...(signal ? [signal] : []),\n AbortSignal.timeout(resolveLimit),\n ]),\n );\n } catch (error) {\n throw transportError(error);\n }\n if (signal?.aborted) {\n throw new RpcError(Code.Canceled, \"the call was canceled\");\n }\n if (address === undefined) {\n throw new RpcError(\n Code.Unavailable,\n `${url.hostname} isn't found on the local network`,\n );\n }\n url.hostname = address.includes(\":\") ? `[${address}]` : address;\n return url.href.replace(/\\/+$/, \"\");\n}\n\nasync function base(connection: Connection, signal?: AbortSignal) {\n connection.resolved ??= await locate(connection, signal);\n return connection.resolved;\n}\n\nfunction frame(schema: DescMessage, init: MessageInitShape<DescMessage>) {\n const body = toBinary(schema, create(schema, init));\n const out = Buffer.allocUnsafe(5 + body.length);\n out[0] = 0;\n out.writeUInt32BE(body.length, 1);\n out.set(body, 5);\n return out;\n}\n\nfunction parseMetadata(body: Uint8Array) {\n const headers: Record<string, string> = {};\n for (const line of Buffer.from(body).toString().split(\"\\r\\n\")) {\n const separator = line.indexOf(\":\");\n if (separator > 0) {\n headers[line.slice(0, separator).trim().toLowerCase()] = line\n .slice(separator + 1)\n .trim();\n }\n }\n return headers;\n}\n\ntype Frame = { trailers: Record<string, string> } | { message: Message };\n\nclass FrameReader {\n declare schema: DescMessage;\n pending: Buffer = Buffer.alloc(0);\n\n constructor(schema: DescMessage) {\n this.schema = schema;\n }\n\n push(chunk: Uint8Array) {\n this.pending =\n this.pending.length === 0\n ? Buffer.from(chunk)\n : Buffer.concat([this.pending, Buffer.from(chunk)]);\n const frames: Frame[] = [];\n while (this.pending.length >= 5) {\n const length = this.pending.readUInt32BE(1);\n if (length > largestMessage) {\n throw new RpcError(\n Code.Internal,\n `the server sent a message of ${length} bytes`,\n );\n }\n if (this.pending.length < 5 + length) {\n break;\n }\n const body = this.pending.subarray(5, 5 + length);\n frames.push(\n (this.pending[0] & 0x80) !== 0\n ? { trailers: parseMetadata(body) }\n : { message: fromBinary(this.schema, body) },\n );\n this.pending = this.pending.subarray(5 + length);\n }\n return frames;\n }\n}\n\nfunction checkStatus(headers: Record<string, string>) {\n const status = headers[\"grpc-status\"];\n if (status === undefined) {\n return false;\n }\n const code = Number(status);\n if (code !== 0) {\n throw new RpcError(code, statusMessage(headers[\"grpc-message\"]));\n }\n return true;\n}\n\nfunction requestHeaders(connection: Connection) {\n const headers: Record<string, string> = {\n \"content-type\": contentType,\n \"x-grpc-web\": \"1\",\n \"swipt-api-level\": String(apiLevel),\n };\n if (connection.token !== \"\") {\n headers.authorization = `Bearer ${connection.token}`;\n }\n return headers;\n}\n\nasync function* invokeHTTP(\n connection: Connection,\n method: DescMethod,\n input: MessageInitShape<DescMessage>,\n { signal }: CallOptions,\n) {\n let response;\n try {\n response = await fetch(\n `${await base(connection, signal)}/${method.parent.typeName}/${method.name}`,\n {\n method: \"POST\",\n headers: requestHeaders(connection),\n body: frame(method.input, input),\n signal,\n },\n );\n } catch (error) {\n throw transportError(error);\n }\n const headers = Object.fromEntries(response.headers);\n if (response.status !== 200) {\n await response.body?.cancel();\n throw new RpcError(\n httpStatusCodes[response.status] ?? Code.Unknown,\n `HTTP ${response.status}`,\n );\n }\n if (checkStatus(headers)) {\n await response.body?.cancel();\n return;\n }\n const reader = new FrameReader(method.output);\n let ended = false;\n try {\n for await (const chunk of response.body ?? []) {\n for (const found of reader.push(chunk)) {\n if (\"trailers\" in found) {\n checkStatus(found.trailers);\n ended = true;\n } else if (!ended) {\n yield found.message;\n }\n }\n }\n } catch (error) {\n throw transportError(error);\n }\n if (!ended) {\n throw new RpcError(Code.Unavailable, \"the response ended without a status\");\n }\n}\n\nasync function* invokeWebSocket(\n connection: Connection,\n method: DescMethod,\n input: AsyncIterable<MessageInitShape<DescMessage>>,\n { signal }: CallOptions,\n) {\n if (signal?.aborted) {\n throw new RpcError(Code.Canceled, \"the call was canceled\");\n }\n const webSocketBase = (await base(connection, signal)).replace(/^http/, \"ws\");\n const socket = new WebSocket(\n `${webSocketBase}/${method.parent.typeName}/${method.name}`,\n [webSocketSubprotocol],\n );\n socket.binaryType = \"arraybuffer\";\n const reader = new FrameReader(method.output);\n const messages: Message[] = [];\n let failure: unknown;\n let closed = false;\n let headersSeen = false;\n let wake: (value?: unknown) => void = () => {};\n const notify = () => {\n const current = wake;\n wake = () => {};\n current();\n };\n const fail = (error: unknown) => {\n failure ??= error;\n socket.close();\n notify();\n };\n const abort = () =>\n fail(new RpcError(Code.Canceled, \"the call was canceled\"));\n const opened = new Promise((resolve, reject) => {\n socket.addEventListener(\"open\", resolve, { once: true });\n socket.addEventListener(\n \"close\",\n () =>\n reject(\n failure ??\n new RpcError(\n Code.Unavailable,\n `cannot connect to ${webSocketBase}`,\n ),\n ),\n { once: true },\n );\n });\n socket.addEventListener(\"message\", (event) => {\n try {\n for (const found of reader.push(new Uint8Array(event.data))) {\n if (\"message\" in found) {\n messages.push(found.message);\n } else if (headersSeen || \"grpc-status\" in found.trailers) {\n checkStatus(found.trailers);\n closed = true;\n socket.close();\n } else {\n headersSeen = true;\n }\n }\n } catch (error) {\n fail(error);\n }\n notify();\n });\n socket.addEventListener(\"close\", (event) => {\n if (!closed) {\n failure ??= new RpcError(\n Code.Unavailable,\n event.reason || \"the connection closed before the response\",\n );\n }\n closed = true;\n notify();\n });\n socket.addEventListener(\"error\", () => {\n failure ??= new RpcError(\n Code.Unavailable,\n `cannot connect to ${webSocketBase}`,\n );\n });\n signal?.addEventListener(\"abort\", abort, { once: true });\n try {\n await opened;\n const headers = requestHeaders(connection);\n socket.send(\n Buffer.from(\n `${Object.entries(headers)\n .map(([key, value]) => `${key}: ${value}\\r\\n`)\n .join(\"\")}`,\n ),\n );\n void (async () => {\n try {\n for await (const message of input) {\n if (closed || failure) {\n return;\n }\n socket.send(\n Buffer.concat([Buffer.from([0]), frame(method.input, message)]),\n );\n }\n if (!closed && !failure) {\n socket.send(Buffer.from([1]));\n }\n } catch (error) {\n fail(transportError(error));\n }\n })();\n while (true) {\n const message = messages.shift();\n if (message !== undefined) {\n yield message;\n continue;\n }\n if (closed || failure) {\n break;\n }\n await new Promise((resolve) => {\n wake = resolve;\n });\n }\n if (failure) {\n throw failure;\n }\n } finally {\n signal?.removeEventListener(\"abort\", abort);\n if (socket.readyState !== WebSocket.CLOSED) {\n socket.close();\n }\n }\n}\n\nasync function single(iterable: AsyncIterable<Message>) {\n let found: Message | undefined;\n for await (const message of iterable) {\n found ??= message;\n }\n if (found === undefined) {\n throw new RpcError(Code.Internal, \"the server sent no response\");\n }\n return found;\n}\n\ntype Call<Method extends Pick<DescMethod, \"methodKind\" | \"input\" | \"output\">> =\n Method[\"methodKind\"] extends \"unary\"\n ? (\n input: MessageInitShape<Method[\"input\"]>,\n options?: CallOptions,\n ) => Promise<MessageShape<Method[\"output\"]>>\n : Method[\"methodKind\"] extends \"server_streaming\"\n ? (\n input: MessageInitShape<Method[\"input\"]>,\n options?: CallOptions,\n ) => AsyncGenerator<MessageShape<Method[\"output\"]>, void>\n : (\n input: AsyncIterable<MessageInitShape<Method[\"input\"]>>,\n options?: CallOptions,\n ) => Promise<MessageShape<Method[\"output\"]>>;\n\ntype ServiceClient<Service> =\n Service extends GenService<infer Methods>\n ? { [Name in keyof Methods]: Call<Methods[Name]> }\n : never;\n\nfunction bind<Service extends DescService>(\n service: Service,\n connection: Connection,\n) {\n return Object.fromEntries(\n service.methods.map((method) => [\n method.localName,\n (input: never, options: CallOptions = {}) => {\n switch (method.methodKind) {\n case \"unary\":\n return single(invokeHTTP(connection, method, input, options));\n case \"server_streaming\":\n return invokeHTTP(connection, method, input, options);\n default:\n return single(invokeWebSocket(connection, method, input, options));\n }\n },\n ]),\n ) as ServiceClient<Service>;\n}\n\nexport function open({ url, token }: { url: string; token: string }) {\n const connection = { url, token };\n return {\n system: bind(SystemService, connection),\n logs: bind(LogService, connection),\n swiplets: bind(SwipletService, connection),\n repl: bind(REPLService, connection),\n };\n}\n\nexport type Client = ReturnType<typeof open>;\n\nexport const unauthenticated = (error: unknown) =>\n error instanceof RpcError && error.code === Code.Unauthenticated;\n"],"mappings":";;;;;;;;;AAsBA,MAAM,iBAAiB,OAAO;AAC9B,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,uBAAuB;AAC7B,MAAM,EAAE,aAAa,cAAc,YAAY,GAAG,CAAC,CAAC,yBAAyB;AAE7E,IAAI,sBAAsB,WAAW;AAErC,MAAa,OAAO;CAClB,UAAU;CACV,SAAS;CACT,kBAAkB;CAClB,UAAU;CACV,eAAe;CACf,UAAU;CACV,aAAa;CACb,iBAAiB;AACnB;AAEA,IAAa,aAAb,cAAgC,MAAM,CAAC;AAEvC,IAAa,WAAb,cAA8B,MAAM;CAGlC,YAAY,MAAc,SAAkB;EAC1C,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;AAEA,MAAM,kBAA0C;CAC9C,KAAK,KAAK;CACV,KAAK,KAAK;CACV,KAAK,KAAK;CACV,KAAK,KAAK;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