@vite-hub/workspace 0.0.0 → 0.0.2

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.
Files changed (84) hide show
  1. package/README.md +262 -1
  2. package/dist/ai-Cztw4eLk.js +472 -0
  3. package/dist/ai-hFdsvDHC.d.ts +162 -0
  4. package/dist/ai.d.ts +3 -0
  5. package/dist/ai.js +2 -0
  6. package/dist/artifacts-store-BAV9jZpd.js +555 -0
  7. package/dist/asset-registry-CaG9b7tf.js +19 -0
  8. package/dist/chunk-8H4AJuhK.js +14 -0
  9. package/dist/cli.d.ts +31 -0
  10. package/dist/cli.js +303 -0
  11. package/dist/cloudflare-env-CKxUs2fa.js +20 -0
  12. package/dist/cloudflare.d.ts +16 -0
  13. package/dist/cloudflare.js +3 -0
  14. package/dist/collections/client.d.ts +39 -0
  15. package/dist/collections/client.js +137 -0
  16. package/dist/collections.d.ts +59 -0
  17. package/dist/collections.js +159 -0
  18. package/dist/config--r5unwPc.js +7811 -0
  19. package/dist/config-Ca5DM8fF.d.ts +28 -0
  20. package/dist/config-DCQ6y30R.js +30 -0
  21. package/dist/file-B2q9NE18.js +24 -0
  22. package/dist/files-xy0le-_U.js +51 -0
  23. package/dist/github-lIO6-2sH.js +194 -0
  24. package/dist/glob-DeH0dzZX.js +23 -0
  25. package/dist/host-I-_vDs05.js +370 -0
  26. package/dist/hosted-vercel-blob.d.ts +15 -0
  27. package/dist/hosted-vercel-blob.js +26 -0
  28. package/dist/hosted.d.ts +18 -0
  29. package/dist/hosted.js +30 -0
  30. package/dist/index.d.ts +185 -0
  31. package/dist/index.js +541 -0
  32. package/dist/lifecycle-Lhk3dAMt.js +176 -0
  33. package/dist/loader.d.ts +17 -0
  34. package/dist/loader.js +22 -0
  35. package/dist/nitro.d.ts +2 -0
  36. package/dist/nitro.js +2 -0
  37. package/dist/nuxt.d.ts +26 -0
  38. package/dist/nuxt.js +36 -0
  39. package/dist/path-CNI6wKIU.js +115 -0
  40. package/dist/provider-CeQciesl.js +599 -0
  41. package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
  42. package/dist/providers/cloudflare/artifacts-store.js +2 -0
  43. package/dist/providers/github/store.d.ts +6 -0
  44. package/dist/providers/github/store.js +362 -0
  45. package/dist/providers/vercel/blob-store.d.ts +6 -0
  46. package/dist/providers/vercel/blob-store.js +235 -0
  47. package/dist/publish.d.ts +35 -0
  48. package/dist/publish.js +112 -0
  49. package/dist/registry-C7DMdBXN.js +74 -0
  50. package/dist/registry-CoC9JxVt.d.ts +11 -0
  51. package/dist/request-execution-C8qRcReq.js +80 -0
  52. package/dist/runtime/assets.d.ts +12 -0
  53. package/dist/runtime/assets.js +138 -0
  54. package/dist/runtime/empty-assets-registry.d.ts +6 -0
  55. package/dist/runtime/empty-assets-registry.js +4 -0
  56. package/dist/runtime/empty-registry.d.ts +6 -0
  57. package/dist/runtime/empty-registry.js +4 -0
  58. package/dist/runtime/state.d.ts +4 -0
  59. package/dist/runtime/state.js +15 -0
  60. package/dist/runtime/workspace.d.ts +2 -0
  61. package/dist/runtime/workspace.js +2 -0
  62. package/dist/runtime.d.ts +38 -0
  63. package/dist/runtime.js +643 -0
  64. package/dist/search-C4REyHj9.js +39 -0
  65. package/dist/server.d.ts +65 -0
  66. package/dist/server.js +355 -0
  67. package/dist/shared-BRycRSbo.js +255 -0
  68. package/dist/source-metadata.d.ts +2 -0
  69. package/dist/source-metadata.js +2 -0
  70. package/dist/state-DSAHEsq6.d.ts +25 -0
  71. package/dist/sync-DO42ypji.js +269 -0
  72. package/dist/target-D4Bqb1eH.js +11 -0
  73. package/dist/test.d.ts +2 -0
  74. package/dist/test.js +2 -0
  75. package/dist/types-DHkae7Cb.d.ts +628 -0
  76. package/dist/use-D16tf8Ph.d.ts +86 -0
  77. package/dist/use-d_PlAdOu.js +353 -0
  78. package/dist/utils-BPdaCyI6.js +55 -0
  79. package/dist/vite-NWC9mFjI.js +1882 -0
  80. package/dist/vite.d.ts +50 -0
  81. package/dist/vite.js +2 -0
  82. package/dist/workspace-f2DBLmPZ.d.ts +6 -0
  83. package/dist/workspace-n4wBmdaM.js +1476 -0
  84. package/package.json +197 -5
@@ -0,0 +1,176 @@
1
+ import { t as __exportAll } from "./chunk-8H4AJuhK.js";
2
+ import { c as normalizeWorkspacePath } from "./path-CNI6wKIU.js";
3
+ import { a as normalizeWorkspaceSources, n as createSourceContext } from "./config--r5unwPc.js";
4
+ import { t as createCurrentSnapshotFromStore } from "./utils-BPdaCyI6.js";
5
+ import { n as useWorkspaceAssets } from "./asset-registry-CaG9b7tf.js";
6
+ import { t as files } from "./files-xy0le-_U.js";
7
+ import { getViteHubErrorShape } from "@vite-hub/runtime";
8
+ //#region src/lifecycle.ts
9
+ var lifecycle_exports = /* @__PURE__ */ __exportAll({
10
+ publishWorkspace: () => publishWorkspace,
11
+ publishWorkspaceSnapshot: () => publishWorkspaceSnapshot,
12
+ syncWorkspaceDefinition: () => syncWorkspaceDefinition
13
+ });
14
+ const buildSourcesMetaKey = "workspace:build-sources";
15
+ async function publishWorkspace(definition, store, options = {}) {
16
+ if (!definition.publish?.length) return;
17
+ await publishWorkspaceSnapshot(definition, store, await createCurrentSnapshotFromStore(store, options.name), false);
18
+ }
19
+ async function publishWorkspaceSnapshot(definition, store, snapshot, durable = true) {
20
+ for (const publisher of definition.publish || []) await publisher.publish({
21
+ durable,
22
+ workspace: definition,
23
+ store,
24
+ rootDir: definition.rootDir || process.cwd(),
25
+ snapshot
26
+ });
27
+ }
28
+ async function syncWorkspaceDefinition(definition, store) {
29
+ const loaders = definition.loaders?.length ? definition.loaders : [files()];
30
+ const hasExplicitLoaders = !!definition.loaders?.length;
31
+ const ctxSource = createSourceContext(definition, void 0, store);
32
+ const buildSources = normalizeWorkspaceSources(definition.sources).filter((source) => source.materialize === "build");
33
+ const hasBuildSourceState = await reconcileBuildSourceMounts(store, buildSources);
34
+ const bundledBuildSources = !hasExplicitLoaders ? await syncRuntimeBuildAssets(definition, store, buildSources) : void 0;
35
+ if (bundledBuildSources && buildSources.every((source) => bundledBuildSources.has(source.key))) {
36
+ await publishWorkspaceSnapshot(definition, store, await store.snapshot({ name: "sync" }));
37
+ return;
38
+ }
39
+ if (!hasBuildSourceState && !hasExplicitLoaders) return;
40
+ const normalizedSources = buildSources.filter((source) => !bundledBuildSources?.has(source.key)).map((source) => createMountedBuildSource(source));
41
+ const ctx = {
42
+ workspace: definition.name,
43
+ rootDir: ctxSource.rootDir,
44
+ sourceRootDir: ctxSource.sourceRootDir,
45
+ sources: normalizedSources,
46
+ store,
47
+ parseData: async (input) => input.data,
48
+ generateDigest: (input) => JSON.stringify(input),
49
+ logger: console
50
+ };
51
+ for (const loader of loaders) await loader.load(ctx);
52
+ await publishWorkspaceSnapshot(definition, store, await store.snapshot({ name: "sync" }));
53
+ }
54
+ async function reconcileBuildSourceMounts(store, currentSources) {
55
+ const previousSources = await readSyncedBuildSources(store);
56
+ const hasBuildSourceState = previousSources.length > 0 || currentSources.length > 0;
57
+ const resetPaths = [...new Set([...previousSources.map((source) => source.mountPath), ...currentSources.map((source) => source.mountPath)])];
58
+ for (const mountPath of resetPaths.filter(Boolean).sort((a, b) => b.length - a.length)) await store.rm(mountPath, {
59
+ recursive: true,
60
+ force: true
61
+ });
62
+ for (const source of [...previousSources, ...currentSources].filter((source) => !source.mountPath)) await removeRootBuildSourceFiles(store, source);
63
+ for (const mountPath of [...new Set(currentSources.map((source) => source.mountPath))].filter(Boolean).sort((a, b) => a.length - b.length)) await store.mkdir(mountPath, { recursive: true });
64
+ await store.setMeta?.(buildSourcesMetaKey, currentSources.map(({ key, mountPath }) => ({
65
+ key,
66
+ mountPath
67
+ })));
68
+ return hasBuildSourceState;
69
+ }
70
+ async function syncRuntimeBuildAssets(definition, store, currentSources) {
71
+ if (!currentSources.length) return void 0;
72
+ let assets;
73
+ try {
74
+ assets = useWorkspaceAssets(definition.name);
75
+ } catch (error) {
76
+ if (getViteHubErrorShape(error)?.code === "WORKSPACE_NOT_FOUND") return void 0;
77
+ throw error;
78
+ }
79
+ const files = (await assets.list("", { recursive: true })).filter((entry) => entry.type === "file");
80
+ const bundledPaths = new Set(files.map((entry) => entry.path));
81
+ const bundledSourceByPath = /* @__PURE__ */ new Map();
82
+ const bundledBuildSources = /* @__PURE__ */ new Set();
83
+ for (const source of currentSources) if (await hasCompleteBundledBuildSource(definition, store, source, bundledPaths, files, bundledSourceByPath)) bundledBuildSources.add(source.key);
84
+ for (const entry of files) {
85
+ const sourceKey = typeof entry.metadata?.source === "string" ? entry.metadata.source : bundledSourceByPath.get(entry.path) || findBuildSourceForPath(entry.path, currentSources)?.key;
86
+ await store.writeFile(entry.path, {
87
+ path: entry.path,
88
+ content: await assets.readFile(entry.path, { encoding: "binary" }),
89
+ mediaType: entry.mediaType,
90
+ metadata: sourceKey ? {
91
+ ...entry.metadata,
92
+ source: sourceKey
93
+ } : entry.metadata
94
+ });
95
+ }
96
+ return bundledBuildSources;
97
+ }
98
+ async function hasCompleteBundledBuildSource(definition, store, source, bundledPaths, bundledFiles, bundledSourceByPath) {
99
+ const probeKeys = source.source.probeKeys;
100
+ if (!probeKeys?.length) {
101
+ const paths = bundledFiles?.filter((file) => file.metadata?.source === source.key).map((file) => file.path) ?? [];
102
+ const sourcePaths = await tryListBuildSourcePaths(definition, store, source);
103
+ if (sourcePaths && !sourcePaths.every((path) => paths.includes(path))) return false;
104
+ for (const path of paths) bundledSourceByPath?.set(path, source.key);
105
+ return paths.length > 0;
106
+ }
107
+ const paths = probeKeys.map((key) => normalizeWorkspacePath(`${source.mountPath}/${key}`));
108
+ if (!paths.every((path) => bundledPaths.has(path))) return false;
109
+ for (const path of paths) bundledSourceByPath?.set(path, source.key);
110
+ return true;
111
+ }
112
+ async function tryListBuildSourcePaths(definition, store, source) {
113
+ const ctx = createSourceContext(definition, {
114
+ key: source.key,
115
+ mountPath: source.mountPath
116
+ }, store);
117
+ try {
118
+ await source.source.prepare?.(ctx);
119
+ return (await source.source.getKeys(ctx)).map((key) => normalizeWorkspacePath(`${source.mountPath}/${key}`));
120
+ } catch {
121
+ return;
122
+ }
123
+ }
124
+ function findBuildSourceForPath(path, sources) {
125
+ const matches = sources.filter((source) => !source.mountPath || path === source.mountPath || path.startsWith(`${source.mountPath}/`)).sort((left, right) => right.mountPath.length - left.mountPath.length)[0];
126
+ if (!matches?.mountPath && sources.filter((source) => !source.mountPath).length > 1) return void 0;
127
+ return matches;
128
+ }
129
+ async function readSyncedBuildSources(store) {
130
+ const value = await store.getMeta?.(buildSourcesMetaKey);
131
+ if (!Array.isArray(value)) return [];
132
+ return value.filter(isSyncedBuildSource);
133
+ }
134
+ async function removeRootBuildSourceFiles(store, source) {
135
+ const entries = await store.list("", { recursive: true });
136
+ await Promise.all(entries.map(async (entry) => {
137
+ if (entry.type !== "file") return;
138
+ if ((await store.readFile(entry.path))?.metadata?.source === source.key) await store.rm(entry.path, { force: true });
139
+ }));
140
+ }
141
+ function isSyncedBuildSource(value) {
142
+ return !!value && typeof value === "object" && typeof value.key === "string" && typeof value.mountPath === "string";
143
+ }
144
+ function createMountedBuildSource(source) {
145
+ function getSourceContext(ctx) {
146
+ return {
147
+ ...ctx,
148
+ mountPath: source.mountPath,
149
+ source: source.key
150
+ };
151
+ }
152
+ return {
153
+ ...source.source,
154
+ key: source.key,
155
+ async prepare(ctx) {
156
+ await source.source.prepare?.(getSourceContext(ctx));
157
+ },
158
+ async getKeys(ctx) {
159
+ return await source.source.getKeys(getSourceContext(ctx));
160
+ },
161
+ async getItem(key, ctx) {
162
+ const item = await source.source.getItem(key, getSourceContext(ctx));
163
+ const path = normalizeWorkspacePath(`${source.mountPath}/${item.path || item.key}`);
164
+ return {
165
+ ...item,
166
+ path,
167
+ metadata: {
168
+ ...item.metadata,
169
+ source: source.key
170
+ }
171
+ };
172
+ }
173
+ };
174
+ }
175
+ //#endregion
176
+ export { syncWorkspaceDefinition as n, lifecycle_exports as t };
@@ -0,0 +1,17 @@
1
+ import { Ot as WorkspaceSourceItem, Y as WorkspaceLoader, j as WorkspaceContent } from "./types-DHkae7Cb.js";
2
+
3
+ //#region src/loaders/files.d.ts
4
+ interface FilesLoaderOptions {
5
+ include?: string | string[];
6
+ exclude?: string | string[];
7
+ transform?: (item: WorkspaceSourceItem) => WorkspaceContent | WorkspaceSourceItem | Promise<WorkspaceContent | WorkspaceSourceItem>;
8
+ }
9
+ declare function files(options?: FilesLoaderOptions): WorkspaceLoader;
10
+ //#endregion
11
+ //#region src/loaders/json.d.ts
12
+ declare function json(options?: FilesLoaderOptions): WorkspaceLoader;
13
+ //#endregion
14
+ //#region src/loaders/text.d.ts
15
+ declare function text(options?: FilesLoaderOptions): WorkspaceLoader;
16
+ //#endregion
17
+ export { type FilesLoaderOptions, files, json, text };
package/dist/loader.js ADDED
@@ -0,0 +1,22 @@
1
+ import { t as files } from "./files-xy0le-_U.js";
2
+ //#region src/loaders/json.ts
3
+ function json(options = {}) {
4
+ return files({
5
+ ...options,
6
+ transform: async (item) => {
7
+ const transformed = options.transform ? await options.transform(item) : item;
8
+ if (typeof transformed === "string" || transformed instanceof Uint8Array) return transformed;
9
+ return {
10
+ ...transformed,
11
+ mediaType: transformed.mediaType || "application/json"
12
+ };
13
+ }
14
+ });
15
+ }
16
+ //#endregion
17
+ //#region src/loaders/text.ts
18
+ function text(options = {}) {
19
+ return files(options);
20
+ }
21
+ //#endregion
22
+ export { files, json, text };
@@ -0,0 +1,2 @@
1
+ import { NitroConfig, WorkspaceNitroConfigOptions, createWorkspaceNitroConfig } from "./vite.js";
2
+ export { type NitroConfig, type WorkspaceNitroConfigOptions, createWorkspaceNitroConfig };
package/dist/nitro.js ADDED
@@ -0,0 +1,2 @@
1
+ import { t as createWorkspaceNitroConfig } from "./vite-NWC9mFjI.js";
2
+ export { createWorkspaceNitroConfig };
package/dist/nuxt.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { nt as WorkspaceModuleOptions } from "./types-DHkae7Cb.js";
2
+
3
+ //#region src/nuxt.d.ts
4
+ interface WorkspaceNuxtModuleOptions extends WorkspaceModuleOptions {}
5
+ type NuxtLike = {
6
+ hook?: (name: "nitro:config", handler: (nitroConfig: Record<string, unknown>) => void | Promise<void>) => void;
7
+ options: {
8
+ alias?: Record<string, string>;
9
+ dev?: boolean;
10
+ imports?: {
11
+ imports?: Array<{
12
+ from: string;
13
+ name: string;
14
+ }>;
15
+ };
16
+ rootDir?: string;
17
+ srcDir?: string;
18
+ vite?: {
19
+ plugins?: unknown[];
20
+ workspace?: false | WorkspaceModuleOptions;
21
+ };
22
+ };
23
+ };
24
+ declare function viteHubWorkspaceNuxtModule(options?: WorkspaceNuxtModuleOptions, nuxt?: NuxtLike): void;
25
+ //#endregion
26
+ export { WorkspaceNuxtModuleOptions, viteHubWorkspaceNuxtModule as default };
package/dist/nuxt.js ADDED
@@ -0,0 +1,36 @@
1
+ import { n as hubWorkspace, t as createWorkspaceNitroConfig } from "./vite-NWC9mFjI.js";
2
+ //#region src/nuxt.ts
3
+ function isWorkspaceVitePlugin(value) {
4
+ return Boolean(value && typeof value === "object" && value.name === "@vite-hub/workspace/vite");
5
+ }
6
+ function resolveWorkspaceOptions(options, viteOptions) {
7
+ if (viteOptions !== void 0) return viteOptions;
8
+ return Object.keys(options).length > 0 ? options : void 0;
9
+ }
10
+ function viteHubWorkspaceNuxtModule(options = {}, nuxt) {
11
+ if (!nuxt) return;
12
+ nuxt.options.imports ??= {};
13
+ nuxt.options.imports.imports ??= [];
14
+ for (const name of ["useWorkspaceCollection", "useWorkspaceCollectionItem"]) if (!nuxt.options.imports.imports.some((entry) => entry.name === name)) nuxt.options.imports.imports.push({
15
+ from: "@vite-hub/workspace/collections/client",
16
+ name
17
+ });
18
+ nuxt.options.vite ??= {};
19
+ const workspaceOptions = resolveWorkspaceOptions(options, nuxt.options.vite.workspace);
20
+ const plugins = Array.isArray(nuxt.options.vite.plugins) ? nuxt.options.vite.plugins : [];
21
+ if (!plugins.some(isWorkspaceVitePlugin)) plugins.push(hubWorkspace(workspaceOptions === false ? void 0 : workspaceOptions));
22
+ nuxt.options.vite.plugins = plugins;
23
+ nuxt.hook?.("nitro:config", async (nitroConfig) => {
24
+ const rootDir = nuxt.options.rootDir || process.cwd();
25
+ const nitro = await createWorkspaceNitroConfig({
26
+ aliases: nuxt.options.alias,
27
+ command: nuxt.options.dev ? "serve" : "build",
28
+ nitro: nitroConfig,
29
+ viteRoot: nuxt.options.srcDir || rootDir,
30
+ workspace: workspaceOptions
31
+ });
32
+ if (nitro) Object.assign(nitroConfig, nitro);
33
+ });
34
+ }
35
+ //#endregion
36
+ export { viteHubWorkspaceNuxtModule as default };
@@ -0,0 +1,115 @@
1
+ import { t as __exportAll } from "./chunk-8H4AJuhK.js";
2
+ import { relative, resolve, sep } from "node:path";
3
+ import { createHash } from "node:crypto";
4
+ import { minimatch } from "minimatch";
5
+ import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
6
+ //#region src/core/errors.ts
7
+ function workspaceError(message, options) {
8
+ return new ViteHubError("WORKSPACE_FAILED", message, options);
9
+ }
10
+ function workspaceNotFoundError(name) {
11
+ return new ViteHubError("WORKSPACE_NOT_FOUND", `[vitehub] Workspace "${name}" is not registered.`, { details: { name } });
12
+ }
13
+ function workspacePathError(path) {
14
+ const publicPath = path.slice(0, 4096);
15
+ return new ViteHubError("WORKSPACE_PATH_INVALID", `[vitehub] Workspace path escapes the workspace root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
16
+ }
17
+ function isWorkspaceError(value) {
18
+ const code = getViteHubErrorShape(value)?.code;
19
+ return code === "WORKSPACE_COLLECTION_CURSOR_INVALID" || code === "WORKSPACE_FAILED" || code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID";
20
+ }
21
+ //#endregion
22
+ //#region src/core/path.ts
23
+ var path_exports = /* @__PURE__ */ __exportAll({
24
+ contentStreamChunks: () => contentStreamChunks,
25
+ contentStreamToBytes: () => contentStreamToBytes,
26
+ contentToBytes: () => contentToBytes,
27
+ decodeFile: () => decodeFile,
28
+ matchesAny: () => matchesAny,
29
+ normalizeSafeWorkspacePath: () => normalizeSafeWorkspacePath,
30
+ normalizeSafeWorkspacePattern: () => normalizeSafeWorkspacePattern,
31
+ normalizeWorkspacePath: () => normalizeWorkspacePath,
32
+ resolveInside: () => resolveInside,
33
+ sha256: () => sha256
34
+ });
35
+ function normalizeWorkspacePath(path = "") {
36
+ return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
37
+ }
38
+ function normalizeSafeWorkspacePath(path = "", options = {}) {
39
+ const raw = path.replace(/\\/g, "/");
40
+ const normalized = normalizeWorkspacePath(path);
41
+ const parts = normalized.split("/").filter(Boolean);
42
+ if (!options.allowEmpty && !normalized) throw workspacePathError(path);
43
+ if (raw.startsWith("/") || parts.some((part) => part === "." || part === "..")) throw workspacePathError(path);
44
+ if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw workspacePathError(path);
45
+ return normalized;
46
+ }
47
+ function normalizeSafeWorkspacePattern(pattern) {
48
+ return normalizeSafeWorkspacePath(pattern, {
49
+ allowEmpty: true,
50
+ pattern: true
51
+ });
52
+ }
53
+ function resolveInside(root, path = "") {
54
+ const resolvedRoot = resolve(root);
55
+ const resolved = resolve(resolvedRoot, normalizeWorkspacePath(path));
56
+ const rel = relative(resolvedRoot, resolved);
57
+ if (rel.startsWith("..") || rel === ".." || rel.includes(`..${sep}`) || rel === "") {
58
+ if (rel === "") return resolved;
59
+ throw workspacePathError(path);
60
+ }
61
+ return resolved;
62
+ }
63
+ function matchesAny(path, patterns) {
64
+ if (!patterns) return true;
65
+ const list = Array.isArray(patterns) ? patterns : [patterns];
66
+ const normalizedPath = normalizeWorkspacePath(path);
67
+ return list.some((pattern) => minimatch(normalizedPath, normalizeWorkspacePath(pattern), { dot: true }));
68
+ }
69
+ function contentToBytes(content) {
70
+ return typeof content === "string" ? new TextEncoder().encode(content) : content;
71
+ }
72
+ function isReadableStream(value) {
73
+ return Boolean(value && typeof value.getReader === "function");
74
+ }
75
+ async function* contentStreamChunks(stream) {
76
+ if (isReadableStream(stream)) {
77
+ const reader = stream.getReader();
78
+ try {
79
+ while (true) {
80
+ const chunk = await reader.read();
81
+ if (chunk.done) return;
82
+ yield chunk.value;
83
+ }
84
+ } finally {
85
+ reader.releaseLock();
86
+ }
87
+ return;
88
+ }
89
+ yield* stream;
90
+ }
91
+ async function contentStreamToBytes(stream) {
92
+ const chunks = [];
93
+ let size = 0;
94
+ for await (const chunk of contentStreamChunks(stream)) {
95
+ chunks.push(chunk);
96
+ size += chunk.byteLength;
97
+ }
98
+ const bytes = new Uint8Array(size);
99
+ let offset = 0;
100
+ for (const chunk of chunks) {
101
+ bytes.set(chunk, offset);
102
+ offset += chunk.byteLength;
103
+ }
104
+ return bytes;
105
+ }
106
+ function decodeFile(content, options) {
107
+ if (options?.encoding === "binary") return content;
108
+ return typeof content === "string" ? content : new TextDecoder().decode(content);
109
+ }
110
+ async function sha256(input) {
111
+ const bytes = contentToBytes(typeof input === "string" || input instanceof Uint8Array ? input : JSON.stringify(input));
112
+ return createHash("sha256").update(bytes).digest("hex");
113
+ }
114
+ //#endregion
115
+ export { matchesAny as a, normalizeWorkspacePath as c, sha256 as d, isWorkspaceError as f, decodeFile as i, path_exports as l, workspaceNotFoundError as m, contentStreamToBytes as n, normalizeSafeWorkspacePath as o, workspaceError as p, contentToBytes as r, normalizeSafeWorkspacePattern as s, contentStreamChunks as t, resolveInside as u };