@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.
- package/README.md +262 -1
- package/dist/ai-Cztw4eLk.js +472 -0
- package/dist/ai-hFdsvDHC.d.ts +162 -0
- package/dist/ai.d.ts +3 -0
- package/dist/ai.js +2 -0
- package/dist/artifacts-store-BAV9jZpd.js +555 -0
- package/dist/asset-registry-CaG9b7tf.js +19 -0
- package/dist/chunk-8H4AJuhK.js +14 -0
- package/dist/cli.d.ts +31 -0
- package/dist/cli.js +303 -0
- package/dist/cloudflare-env-CKxUs2fa.js +20 -0
- package/dist/cloudflare.d.ts +16 -0
- package/dist/cloudflare.js +3 -0
- package/dist/collections/client.d.ts +39 -0
- package/dist/collections/client.js +137 -0
- package/dist/collections.d.ts +59 -0
- package/dist/collections.js +159 -0
- package/dist/config--r5unwPc.js +7811 -0
- package/dist/config-Ca5DM8fF.d.ts +28 -0
- package/dist/config-DCQ6y30R.js +30 -0
- package/dist/file-B2q9NE18.js +24 -0
- package/dist/files-xy0le-_U.js +51 -0
- package/dist/github-lIO6-2sH.js +194 -0
- package/dist/glob-DeH0dzZX.js +23 -0
- package/dist/host-I-_vDs05.js +370 -0
- package/dist/hosted-vercel-blob.d.ts +15 -0
- package/dist/hosted-vercel-blob.js +26 -0
- package/dist/hosted.d.ts +18 -0
- package/dist/hosted.js +30 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +541 -0
- package/dist/lifecycle-Lhk3dAMt.js +176 -0
- package/dist/loader.d.ts +17 -0
- package/dist/loader.js +22 -0
- package/dist/nitro.d.ts +2 -0
- package/dist/nitro.js +2 -0
- package/dist/nuxt.d.ts +26 -0
- package/dist/nuxt.js +36 -0
- package/dist/path-CNI6wKIU.js +115 -0
- package/dist/provider-CeQciesl.js +599 -0
- package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
- package/dist/providers/cloudflare/artifacts-store.js +2 -0
- package/dist/providers/github/store.d.ts +6 -0
- package/dist/providers/github/store.js +362 -0
- package/dist/providers/vercel/blob-store.d.ts +6 -0
- package/dist/providers/vercel/blob-store.js +235 -0
- package/dist/publish.d.ts +35 -0
- package/dist/publish.js +112 -0
- package/dist/registry-C7DMdBXN.js +74 -0
- package/dist/registry-CoC9JxVt.d.ts +11 -0
- package/dist/request-execution-C8qRcReq.js +80 -0
- package/dist/runtime/assets.d.ts +12 -0
- package/dist/runtime/assets.js +138 -0
- package/dist/runtime/empty-assets-registry.d.ts +6 -0
- package/dist/runtime/empty-assets-registry.js +4 -0
- package/dist/runtime/empty-registry.d.ts +6 -0
- package/dist/runtime/empty-registry.js +4 -0
- package/dist/runtime/state.d.ts +4 -0
- package/dist/runtime/state.js +15 -0
- package/dist/runtime/workspace.d.ts +2 -0
- package/dist/runtime/workspace.js +2 -0
- package/dist/runtime.d.ts +38 -0
- package/dist/runtime.js +643 -0
- package/dist/search-C4REyHj9.js +39 -0
- package/dist/server.d.ts +65 -0
- package/dist/server.js +355 -0
- package/dist/shared-BRycRSbo.js +255 -0
- package/dist/source-metadata.d.ts +2 -0
- package/dist/source-metadata.js +2 -0
- package/dist/state-DSAHEsq6.d.ts +25 -0
- package/dist/sync-DO42ypji.js +269 -0
- package/dist/target-D4Bqb1eH.js +11 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.js +2 -0
- package/dist/types-DHkae7Cb.d.ts +628 -0
- package/dist/use-D16tf8Ph.d.ts +86 -0
- package/dist/use-d_PlAdOu.js +353 -0
- package/dist/utils-BPdaCyI6.js +55 -0
- package/dist/vite-NWC9mFjI.js +1882 -0
- package/dist/vite.d.ts +50 -0
- package/dist/vite.js +2 -0
- package/dist/workspace-f2DBLmPZ.d.ts +6 -0
- package/dist/workspace-n4wBmdaM.js +1476 -0
- package/package.json +197 -5
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { t as useWorkspace } from "./use-d_PlAdOu.js";
|
|
2
|
+
import { ViteHubError } from "@vite-hub/runtime";
|
|
3
|
+
//#region src/collections.ts
|
|
4
|
+
const workspaceCollectionEmpty = Object.freeze({ empty: true });
|
|
5
|
+
function workspaceCollectionCursorError(reason) {
|
|
6
|
+
return new ViteHubError("WORKSPACE_COLLECTION_CURSOR_INVALID", reason === "stale" ? "Workspace collection cursor is stale." : "Workspace collection cursor is malformed.", { details: { reason } });
|
|
7
|
+
}
|
|
8
|
+
const defaultPageLimit = 50;
|
|
9
|
+
const defaultMaxLimit = 100;
|
|
10
|
+
function isRecord(value) {
|
|
11
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
12
|
+
}
|
|
13
|
+
function valueAt(value, path) {
|
|
14
|
+
const segments = path.split(".").filter(Boolean);
|
|
15
|
+
function visit(current, remaining) {
|
|
16
|
+
if (!remaining.length) return current;
|
|
17
|
+
if (Array.isArray(current)) return current.map((item) => visit(item, remaining)).filter((item) => item !== void 0);
|
|
18
|
+
if (!isRecord(current)) return;
|
|
19
|
+
return visit(current[remaining[0]], remaining.slice(1));
|
|
20
|
+
}
|
|
21
|
+
return visit(value, segments);
|
|
22
|
+
}
|
|
23
|
+
function scalarValues(value) {
|
|
24
|
+
if (Array.isArray(value)) return value.flatMap(scalarValues);
|
|
25
|
+
if (value === null || value === void 0 || typeof value === "object") return [];
|
|
26
|
+
return [String(value)];
|
|
27
|
+
}
|
|
28
|
+
function matchesFilter(value, expected) {
|
|
29
|
+
const values = scalarValues(value).map((item) => item.toLocaleLowerCase());
|
|
30
|
+
if (typeof expected === "object" && !Array.isArray(expected)) return expected.empty && values.length === 0;
|
|
31
|
+
const candidates = (Array.isArray(expected) ? expected : [expected]).filter((item) => item !== void 0).map((item) => item.toLocaleLowerCase());
|
|
32
|
+
if (!candidates.length) return true;
|
|
33
|
+
return candidates.some((candidate) => values.includes(candidate));
|
|
34
|
+
}
|
|
35
|
+
function project(item, select) {
|
|
36
|
+
if (!select?.length) return item;
|
|
37
|
+
return Object.fromEntries(select.map((field) => [field, valueAt(item, field)]));
|
|
38
|
+
}
|
|
39
|
+
async function digest(value) {
|
|
40
|
+
const bytes = new TextEncoder().encode(value);
|
|
41
|
+
const hash = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
42
|
+
return [...new Uint8Array(hash)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
43
|
+
}
|
|
44
|
+
async function readCollection(options) {
|
|
45
|
+
const workspace = typeof options.workspace === "string" ? useWorkspace(options.workspace) : await options.workspace;
|
|
46
|
+
const stat = await workspace.fs.stat(options.path);
|
|
47
|
+
if (stat.type !== "file") throw new TypeError(`Workspace collection ${options.path} must be a file.`);
|
|
48
|
+
const raw = await workspace.fs.readFile(options.path, { encoding: "utf8" });
|
|
49
|
+
const parsed = JSON.parse(raw);
|
|
50
|
+
if (!Array.isArray(parsed)) throw new TypeError(`Workspace collection ${options.path} must contain a JSON array.`);
|
|
51
|
+
return {
|
|
52
|
+
digest: stat.digest || await digest(raw),
|
|
53
|
+
items: parsed
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function normalizedFilters(filters) {
|
|
57
|
+
return Object.fromEntries(Object.entries(filters || {}).filter((entry) => entry[1] !== void 0).sort(([left], [right]) => left.localeCompare(right)).map(([field, value]) => [field, typeof value === "object" && !Array.isArray(value) ? ["operator:empty"] : (Array.isArray(value) ? value : [value]).map((item) => `value:${item.toLocaleLowerCase()}`).sort()]));
|
|
58
|
+
}
|
|
59
|
+
async function queryDigest(query, limit) {
|
|
60
|
+
return await digest(JSON.stringify({
|
|
61
|
+
facets: [...query.facets || []].sort(),
|
|
62
|
+
filters: normalizedFilters(query.filters),
|
|
63
|
+
limit,
|
|
64
|
+
search: String(query.search || "").trim().toLocaleLowerCase(),
|
|
65
|
+
searchFields: [...query.searchFields || []].sort(),
|
|
66
|
+
select: query.select || [],
|
|
67
|
+
sort: query.sort ? {
|
|
68
|
+
direction: query.sort.direction || "asc",
|
|
69
|
+
field: query.sort.field
|
|
70
|
+
} : null
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
function encodeCursor(cursor) {
|
|
74
|
+
return btoa(JSON.stringify(cursor)).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
75
|
+
}
|
|
76
|
+
function decodeCursor(cursor, expected) {
|
|
77
|
+
if (!cursor) return 0;
|
|
78
|
+
let parsed;
|
|
79
|
+
try {
|
|
80
|
+
const normalized = cursor.replaceAll("-", "+").replaceAll("_", "/");
|
|
81
|
+
parsed = JSON.parse(atob(normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=")));
|
|
82
|
+
} catch {
|
|
83
|
+
throw workspaceCollectionCursorError("malformed");
|
|
84
|
+
}
|
|
85
|
+
if (!isRecord(parsed) || !Number.isSafeInteger(parsed.offset) || Number(parsed.offset) < 0 || typeof parsed.digest !== "string" || typeof parsed.query !== "string") throw workspaceCollectionCursorError("malformed");
|
|
86
|
+
if (parsed.digest !== expected.digest || parsed.query !== expected.query) throw workspaceCollectionCursorError("stale");
|
|
87
|
+
return Number(parsed.offset);
|
|
88
|
+
}
|
|
89
|
+
function resolveLimit(query, options) {
|
|
90
|
+
const maxLimit = options.maxLimit ?? defaultMaxLimit;
|
|
91
|
+
const fallback = options.defaultLimit ?? defaultPageLimit;
|
|
92
|
+
if (!Number.isSafeInteger(maxLimit) || maxLimit < 1) throw new TypeError("Workspace collection maxLimit must be a positive integer.");
|
|
93
|
+
if (!Number.isSafeInteger(fallback) || fallback < 1) throw new TypeError("Workspace collection defaultLimit must be a positive integer.");
|
|
94
|
+
if (query.limit !== void 0 && (!Number.isSafeInteger(query.limit) || query.limit < 1)) throw new TypeError("Workspace collection limit must be a positive integer.");
|
|
95
|
+
return Math.min(query.limit ?? fallback, maxLimit);
|
|
96
|
+
}
|
|
97
|
+
function filterItems(items, query) {
|
|
98
|
+
const search = String(query.search || "").trim().toLocaleLowerCase();
|
|
99
|
+
let filtered = items.filter((item) => Object.entries(query.filters || {}).every(([field, expected]) => matchesFilter(valueAt(item, field), expected)));
|
|
100
|
+
if (search) filtered = filtered.filter((item) => (query.searchFields || []).some((field) => scalarValues(valueAt(item, field)).some((value) => value.toLocaleLowerCase().includes(search))));
|
|
101
|
+
if (query.sort?.field) {
|
|
102
|
+
const direction = query.sort.direction === "desc" ? -1 : 1;
|
|
103
|
+
filtered = [...filtered].sort((left, right) => {
|
|
104
|
+
const leftValue = valueAt(left, query.sort.field);
|
|
105
|
+
const rightValue = valueAt(right, query.sort.field);
|
|
106
|
+
const leftScalar = Array.isArray(leftValue) ? leftValue.flat(Infinity).find((value) => value !== null && value !== void 0 && typeof value !== "object") : leftValue;
|
|
107
|
+
const rightScalar = Array.isArray(rightValue) ? rightValue.flat(Infinity).find((value) => value !== null && value !== void 0 && typeof value !== "object") : rightValue;
|
|
108
|
+
if (typeof leftScalar === "number" && typeof rightScalar === "number") return (leftScalar - rightScalar) * direction;
|
|
109
|
+
return String(leftScalar ?? "").localeCompare(String(rightScalar ?? "")) * direction;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return filtered;
|
|
113
|
+
}
|
|
114
|
+
function buildFacets(items, fields, maxValues) {
|
|
115
|
+
return Object.fromEntries((fields || []).map((field) => {
|
|
116
|
+
const counts = /* @__PURE__ */ new Map();
|
|
117
|
+
for (const item of items) for (const value of new Set(scalarValues(valueAt(item, field)))) counts.set(value, (counts.get(value) || 0) + 1);
|
|
118
|
+
return [field, [...counts].map(([value, count]) => ({
|
|
119
|
+
count,
|
|
120
|
+
value
|
|
121
|
+
})).sort((left, right) => right.count - left.count || left.value.localeCompare(right.value)).slice(0, maxValues)];
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
async function queryWorkspaceCollection(options) {
|
|
125
|
+
const collection = await readCollection(options);
|
|
126
|
+
const query = options.query || {};
|
|
127
|
+
const filtered = filterItems(collection.items, query);
|
|
128
|
+
const limit = resolveLimit(query, options);
|
|
129
|
+
const signature = await queryDigest(query, limit);
|
|
130
|
+
const offset = decodeCursor(query.cursor, {
|
|
131
|
+
digest: collection.digest,
|
|
132
|
+
query: signature
|
|
133
|
+
});
|
|
134
|
+
if (offset > filtered.length) throw workspaceCollectionCursorError("malformed");
|
|
135
|
+
const items = filtered.slice(offset, offset + limit).map((item) => project(item, query.select));
|
|
136
|
+
const nextOffset = offset + items.length;
|
|
137
|
+
return {
|
|
138
|
+
digest: collection.digest,
|
|
139
|
+
facets: buildFacets(filtered, query.facets, options.maxLimit ?? defaultMaxLimit),
|
|
140
|
+
items,
|
|
141
|
+
nextCursor: nextOffset < filtered.length ? encodeCursor({
|
|
142
|
+
digest: collection.digest,
|
|
143
|
+
offset: nextOffset,
|
|
144
|
+
query: signature
|
|
145
|
+
}) : null,
|
|
146
|
+
total: filtered.length
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async function getWorkspaceCollectionItem(options) {
|
|
150
|
+
const collection = await readCollection(options);
|
|
151
|
+
const expected = String(options.query.value);
|
|
152
|
+
const item = collection.items.find((item) => scalarValues(valueAt(item, options.query.key)).some((value) => value === expected));
|
|
153
|
+
return {
|
|
154
|
+
digest: collection.digest,
|
|
155
|
+
item: item === void 0 ? null : project(item, options.query.select)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
export { getWorkspaceCollectionItem, queryWorkspaceCollection, workspaceCollectionEmpty };
|