@wvb/remote-local-provider 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # Changelog
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @wvb/remote-local-provider
package/dist/index.cjs ADDED
@@ -0,0 +1,110 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ let node_os = require("node:os");
29
+ node_os = __toESM(node_os);
30
+ let node_path = require("node:path");
31
+ node_path = __toESM(node_path);
32
+ let node_stream = require("node:stream");
33
+ let _wvb_remote_local_api = require("@wvb/remote-local/api");
34
+ let hono = require("hono");
35
+ let hono_streaming = require("hono/streaming");
36
+
37
+ //#region src/utils.ts
38
+ function getRemoteBundleDeploymentVersion(deployment, channel, fallback = false) {
39
+ if (channel != null) {
40
+ const channelVersion = deployment.channels?.[channel];
41
+ if (channelVersion != null) return channelVersion;
42
+ if (!fallback) return;
43
+ }
44
+ return deployment.version;
45
+ }
46
+
47
+ //#endregion
48
+ //#region src/remote.ts
49
+ /** biome-ignore-all lint/complexity/noBannedTypes: expected */
50
+ function webviewBundleRemote({ baseDir, allowOtherVersions }) {
51
+ const app = new hono.Hono();
52
+ app.use(async (c, next) => {
53
+ c.set("baseDir", baseDir ?? node_path.default.join(node_os.default.homedir(), ".wvb", "local"));
54
+ await next();
55
+ });
56
+ app.get("/bundles", async (c) => {
57
+ const channel = c.req.query("channel");
58
+ const bundles = (await (0, _wvb_remote_local_api.readAllDeployments)({ baseDir: c.get("baseDir") })).map((x) => {
59
+ const version = getRemoteBundleDeploymentVersion(x, channel);
60
+ if (version == null) return null;
61
+ return {
62
+ name: x.name,
63
+ version
64
+ };
65
+ }).filter((x) => x != null);
66
+ return c.json(bundles);
67
+ });
68
+ async function getBundleResponse(c, bundle, version) {
69
+ const metadata = await (0, _wvb_remote_local_api.readBundleMetadata)({
70
+ baseDir: "",
71
+ bundle,
72
+ version
73
+ });
74
+ c.header("webview-bundle-name", bundle);
75
+ c.header("webview-bundle-version", version);
76
+ if (metadata?.integrity != null) c.header("webview-bundle-integrity", metadata.integrity);
77
+ if (metadata?.signature != null) c.header("webview-bundle-signature", metadata.signature);
78
+ if (c.req.method.toUpperCase() === "HEAD") return c.body(null);
79
+ return (0, hono_streaming.stream)(c, async (s) => {
80
+ const bundleStream = (0, _wvb_remote_local_api.readBundleStream)({
81
+ baseDir: c.get("baseDir"),
82
+ bundle,
83
+ version
84
+ });
85
+ await s.pipe(node_stream.Readable.toWeb(bundleStream));
86
+ });
87
+ }
88
+ app.get("/bundles/:name", async (c) => {
89
+ const bundle = c.req.param("name");
90
+ const channel = c.req.query("channel");
91
+ const deployment = await (0, _wvb_remote_local_api.readDeployment)({
92
+ bundle,
93
+ baseDir: c.get("baseDir")
94
+ });
95
+ if (deployment == null) return c.notFound();
96
+ const version = getRemoteBundleDeploymentVersion(deployment, channel, true);
97
+ if (version == null) return c.notFound();
98
+ return await getBundleResponse(c, bundle, version);
99
+ });
100
+ app.get("/bundles/:name/:version", async (c) => {
101
+ if (allowOtherVersions !== true) return c.body(null, { status: 403 });
102
+ return await getBundleResponse(c, c.req.param("name"), c.req.param("version"));
103
+ });
104
+ return app;
105
+ }
106
+ const wvbRemote = webviewBundleRemote;
107
+
108
+ //#endregion
109
+ exports.webviewBundleRemote = webviewBundleRemote;
110
+ exports.wvbRemote = wvbRemote;
@@ -0,0 +1,34 @@
1
+ import * as hono_types0 from "hono/types";
2
+ import { Hono } from "hono";
3
+
4
+ //#region src/types.d.ts
5
+ interface Variables {
6
+ baseDir: string;
7
+ proxy?: {
8
+ endpoint: string;
9
+ cachePrefix?: string;
10
+ };
11
+ }
12
+ //#endregion
13
+ //#region src/remote.d.ts
14
+ interface Env {
15
+ Bindings: {};
16
+ Variables: Variables;
17
+ }
18
+ type WebviewBundleRemote = Hono<Env>;
19
+ interface WebviewBundleRemoteConfig {
20
+ /**
21
+ * Base directory for bundle storage.
22
+ * @default `~/.wvb/local`
23
+ */
24
+ baseDir?: string;
25
+ /** Option to allow downloading other version instead of deployed version */
26
+ allowOtherVersions?: boolean;
27
+ }
28
+ declare function webviewBundleRemote({
29
+ baseDir,
30
+ allowOtherVersions
31
+ }: WebviewBundleRemoteConfig): Hono<Env, hono_types0.BlankSchema, "/">;
32
+ declare const wvbRemote: typeof webviewBundleRemote;
33
+ //#endregion
34
+ export { type WebviewBundleRemote, type WebviewBundleRemoteConfig, webviewBundleRemote, wvbRemote };
@@ -0,0 +1,34 @@
1
+ import { Hono } from "hono";
2
+ import * as hono_types0 from "hono/types";
3
+
4
+ //#region src/types.d.ts
5
+ interface Variables {
6
+ baseDir: string;
7
+ proxy?: {
8
+ endpoint: string;
9
+ cachePrefix?: string;
10
+ };
11
+ }
12
+ //#endregion
13
+ //#region src/remote.d.ts
14
+ interface Env {
15
+ Bindings: {};
16
+ Variables: Variables;
17
+ }
18
+ type WebviewBundleRemote = Hono<Env>;
19
+ interface WebviewBundleRemoteConfig {
20
+ /**
21
+ * Base directory for bundle storage.
22
+ * @default `~/.wvb/local`
23
+ */
24
+ baseDir?: string;
25
+ /** Option to allow downloading other version instead of deployed version */
26
+ allowOtherVersions?: boolean;
27
+ }
28
+ declare function webviewBundleRemote({
29
+ baseDir,
30
+ allowOtherVersions
31
+ }: WebviewBundleRemoteConfig): Hono<Env, hono_types0.BlankSchema, "/">;
32
+ declare const wvbRemote: typeof webviewBundleRemote;
33
+ //#endregion
34
+ export { type WebviewBundleRemote, type WebviewBundleRemoteConfig, webviewBundleRemote, wvbRemote };
package/dist/index.mjs ADDED
@@ -0,0 +1,80 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ import { Readable } from "node:stream";
4
+ import { readAllDeployments, readBundleMetadata, readBundleStream, readDeployment } from "@wvb/remote-local/api";
5
+ import { Hono } from "hono";
6
+ import { stream } from "hono/streaming";
7
+
8
+ //#region src/utils.ts
9
+ function getRemoteBundleDeploymentVersion(deployment, channel, fallback = false) {
10
+ if (channel != null) {
11
+ const channelVersion = deployment.channels?.[channel];
12
+ if (channelVersion != null) return channelVersion;
13
+ if (!fallback) return;
14
+ }
15
+ return deployment.version;
16
+ }
17
+
18
+ //#endregion
19
+ //#region src/remote.ts
20
+ /** biome-ignore-all lint/complexity/noBannedTypes: expected */
21
+ function webviewBundleRemote({ baseDir, allowOtherVersions }) {
22
+ const app = new Hono();
23
+ app.use(async (c, next) => {
24
+ c.set("baseDir", baseDir ?? path.join(os.homedir(), ".wvb", "local"));
25
+ await next();
26
+ });
27
+ app.get("/bundles", async (c) => {
28
+ const channel = c.req.query("channel");
29
+ const bundles = (await readAllDeployments({ baseDir: c.get("baseDir") })).map((x) => {
30
+ const version = getRemoteBundleDeploymentVersion(x, channel);
31
+ if (version == null) return null;
32
+ return {
33
+ name: x.name,
34
+ version
35
+ };
36
+ }).filter((x) => x != null);
37
+ return c.json(bundles);
38
+ });
39
+ async function getBundleResponse(c, bundle, version) {
40
+ const metadata = await readBundleMetadata({
41
+ baseDir: "",
42
+ bundle,
43
+ version
44
+ });
45
+ c.header("webview-bundle-name", bundle);
46
+ c.header("webview-bundle-version", version);
47
+ if (metadata?.integrity != null) c.header("webview-bundle-integrity", metadata.integrity);
48
+ if (metadata?.signature != null) c.header("webview-bundle-signature", metadata.signature);
49
+ if (c.req.method.toUpperCase() === "HEAD") return c.body(null);
50
+ return stream(c, async (s) => {
51
+ const bundleStream = readBundleStream({
52
+ baseDir: c.get("baseDir"),
53
+ bundle,
54
+ version
55
+ });
56
+ await s.pipe(Readable.toWeb(bundleStream));
57
+ });
58
+ }
59
+ app.get("/bundles/:name", async (c) => {
60
+ const bundle = c.req.param("name");
61
+ const channel = c.req.query("channel");
62
+ const deployment = await readDeployment({
63
+ bundle,
64
+ baseDir: c.get("baseDir")
65
+ });
66
+ if (deployment == null) return c.notFound();
67
+ const version = getRemoteBundleDeploymentVersion(deployment, channel, true);
68
+ if (version == null) return c.notFound();
69
+ return await getBundleResponse(c, bundle, version);
70
+ });
71
+ app.get("/bundles/:name/:version", async (c) => {
72
+ if (allowOtherVersions !== true) return c.body(null, { status: 403 });
73
+ return await getBundleResponse(c, c.req.param("name"), c.req.param("version"));
74
+ });
75
+ return app;
76
+ }
77
+ const wvbRemote = webviewBundleRemote;
78
+
79
+ //#endregion
80
+ export { webviewBundleRemote, wvbRemote };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@wvb/remote-local-provider",
3
+ "version": "0.0.0",
4
+ "description": "Webview Bundle remote provider for local simulation",
5
+ "homepage": "https://github.com/webview-bundle/webview-bundle",
6
+ "bugs": {
7
+ "url": "https://github.com/webview-bundle/webview-bundle/issues"
8
+ },
9
+ "license": "MIT",
10
+ "author": {
11
+ "name": "Seokju Na",
12
+ "email": "seokju.me@gmail.com",
13
+ "url": "https://github.com/seokju-na"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/webview-bundle/webview-bundle",
18
+ "directory": "packages/remote/local-provider"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md",
23
+ "CHANGELOG.md"
24
+ ],
25
+ "type": "module",
26
+ "main": "./dist/index.mjs",
27
+ "types": "./dist/index.d.mts",
28
+ "exports": {
29
+ ".": {
30
+ "import": "./dist/index.mjs",
31
+ "require": "./dist/index.cjs"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "scripts": {
36
+ "prepack": "yarn build",
37
+ "build": "tsdown",
38
+ "typecheck": "tsc --noEmit"
39
+ },
40
+ "dependencies": {
41
+ "@wvb/remote-local": "^0.0.0",
42
+ "hono": "^4.11.10"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "22.19.3",
46
+ "tsdown": "0.20.1",
47
+ "typescript": "5.9.3",
48
+ "vitest": "4.1.5"
49
+ }
50
+ }