@vite-hub/workspace 0.0.4 → 0.3.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.
Files changed (137) hide show
  1. package/README.md +339 -115
  2. package/dist/abort-BCwpdrN0.js +32 -0
  3. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  4. package/dist/blob-database.d.ts +474 -0
  5. package/dist/blob-database.js +608 -0
  6. package/dist/checkout.d.ts +128 -0
  7. package/dist/checkout.js +849 -0
  8. package/dist/cloudflare.d.ts +6 -7
  9. package/dist/cloudflare.js +1 -1
  10. package/dist/config-B-863EgC.js +15 -0
  11. package/dist/config-BAgL2dtB.js +1076 -0
  12. package/dist/{config-DE9xlaIw.d.ts → config-BQKcPawI.d.ts} +1 -2
  13. package/dist/discard-CNNtCozM.js +8 -0
  14. package/dist/durability.d.ts +22 -0
  15. package/dist/durability.js +70 -0
  16. package/dist/error-diagnostics-CtKjGtGb.js +188 -0
  17. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  18. package/dist/file-2pFYNtsU.js +22 -0
  19. package/dist/{files-Q6xZjDHA.js → files-BOo4SbwE.js} +3 -3
  20. package/dist/files.d.ts +38 -0
  21. package/dist/files.js +6 -0
  22. package/dist/{github-DHnjxQIX.js → github-CrYp4v8k.js} +44 -24
  23. package/dist/glob-B8YGvTrZ.js +21 -0
  24. package/dist/glob-Cjxms1t7.js +30 -0
  25. package/dist/{host-DJH8cuoU.js → host-BFBpXn0N.js} +144 -77
  26. package/dist/{hosted-RPeJOCFz.js → hosted-KcUR_jPv.js} +303 -97
  27. package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
  28. package/dist/hosted-vercel-blob.d.ts +6 -7
  29. package/dist/hosted-vercel-blob.js +1 -1
  30. package/dist/hosted.d.ts +10 -9
  31. package/dist/hosted.js +2 -2
  32. package/dist/index.d.ts +26 -47
  33. package/dist/index.js +30 -100
  34. package/dist/internal/path.d.ts +2 -0
  35. package/dist/internal/path.js +2 -0
  36. package/dist/lifecycle-B-enk_4A.js +596 -0
  37. package/dist/lineage.d.ts +26 -0
  38. package/dist/lineage.js +76 -0
  39. package/dist/loader.d.ts +5 -6
  40. package/dist/loader.js +3 -2
  41. package/dist/mcp-resources-DF0F5rcL.js +39 -0
  42. package/dist/memory-BOexthyW.js +247 -0
  43. package/dist/metadata-target-CWz6KHKq.js +1589 -0
  44. package/dist/object-Da1zyPCR.js +11 -0
  45. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  46. package/dist/operations-C6FpR8Rr.js +389 -0
  47. package/dist/operations-CE2drFih.js +1234 -0
  48. package/dist/operations.d.ts +90 -0
  49. package/dist/operations.js +3 -0
  50. package/dist/path--wrT_Azm.js +113 -0
  51. package/dist/path-AxMho1wo.d.ts +7 -0
  52. package/dist/path-DrSIenjj.js +59 -0
  53. package/dist/path-zHxQUbqa.d.ts +9 -0
  54. package/dist/plugins-C8C0auoW.d.ts +10 -0
  55. package/dist/provider-9s4Ufkm5.js +1479 -0
  56. package/dist/providers/github/store.d.ts +3 -5
  57. package/dist/providers/github/store.js +1 -1
  58. package/dist/registry-B3BBm4Ts.d.ts +19 -0
  59. package/dist/{registry-D3yzt8HQ.js → registry-CNphafBx.js} +60 -23
  60. package/dist/registry-CYNN623b.d.ts +9 -0
  61. package/dist/request-scope-Dw5n8bMC.js +83 -0
  62. package/dist/results-DgkZUmTL.js +8 -0
  63. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-rQ84J-ij.js} +3 -4
  64. package/dist/runtime/assets.d.ts +3 -5
  65. package/dist/runtime/assets.js +7 -6
  66. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  67. package/dist/runtime/empty-registry.d.ts +2 -2
  68. package/dist/runtime/registry.d.ts +2 -0
  69. package/dist/runtime/registry.js +23 -0
  70. package/dist/runtime/request.d.ts +4 -0
  71. package/dist/runtime/request.js +8 -0
  72. package/dist/runtime/state.d.ts +5 -4
  73. package/dist/runtime/state.js +8 -18
  74. package/dist/runtime/workspace.d.ts +1 -1
  75. package/dist/runtime/workspace.js +1 -1
  76. package/dist/runtime.d.ts +52 -17
  77. package/dist/runtime.js +324 -67
  78. package/dist/{search-BpiCF2Tw.js → search-C_RfoM2j.js} +10 -9
  79. package/dist/server-8tGltlGz.js +303 -0
  80. package/dist/server.d.ts +36 -39
  81. package/dist/server.js +2 -328
  82. package/dist/shared-B3_EUk89.js +848 -0
  83. package/dist/source-metadata.d.ts +10 -7
  84. package/dist/source-metadata.js +12 -12
  85. package/dist/state-BISnUf1s.d.ts +35 -0
  86. package/dist/{ai-BqCC8BpY.js → state-DbrW-njQ.js} +237 -114
  87. package/dist/store-ybhyD38Z.js +1873 -0
  88. package/dist/{sync-DnTQwt8r.js → sync-CCD_VYC8.js} +61 -41
  89. package/dist/target-jWhTdIuF.js +89 -0
  90. package/dist/test.d.ts +1 -1
  91. package/dist/test.js +1 -1
  92. package/dist/{types-CYuwjJ4V.d.ts → types-BbtwmBZ5.d.ts} +321 -35
  93. package/dist/use-C6lV3-wC.d.ts +321 -0
  94. package/dist/{use-BTNDR5Rd.js → use-CSpT5W87.js} +141 -107
  95. package/dist/utils-CgMZCHsX.js +616 -0
  96. package/dist/vite.d.ts +585 -2
  97. package/dist/vite.js +21369 -2
  98. package/dist/workspace-CYB2xZ1T.d.ts +7 -0
  99. package/dist/{workspace-Dq08Yn72.js → workspace-sPWn2Jxj.js} +441 -225
  100. package/package.json +97 -72
  101. package/dist/ai-CjxvGqM0.d.ts +0 -162
  102. package/dist/ai.d.ts +0 -3
  103. package/dist/ai.js +0 -2
  104. package/dist/collections/client.d.ts +0 -39
  105. package/dist/collections/client.js +0 -137
  106. package/dist/collections.d.ts +0 -59
  107. package/dist/collections.js +0 -159
  108. package/dist/config-Bc3c4Su1.js +0 -7904
  109. package/dist/config-CHLLWklZ.js +0 -36
  110. package/dist/file-Bc1X7pco.js +0 -23
  111. package/dist/glob-CEZKeZFC.js +0 -18
  112. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  113. package/dist/lifecycle-LrL3sA4n.js +0 -316
  114. package/dist/metadata-target-B0tOmVW7.js +0 -717
  115. package/dist/mountx.d.ts +0 -10
  116. package/dist/mountx.js +0 -143
  117. package/dist/nitro.d.ts +0 -2
  118. package/dist/nitro.js +0 -2
  119. package/dist/nuxt.d.ts +0 -26
  120. package/dist/nuxt.js +0 -42
  121. package/dist/path-Cp59koVz.js +0 -139
  122. package/dist/provider-B1yLjCJJ.js +0 -746
  123. package/dist/publish.d.ts +0 -35
  124. package/dist/publish.js +0 -112
  125. package/dist/registry-Uj6IVxes.d.ts +0 -11
  126. package/dist/request-execution-B-dSFlGB.js +0 -84
  127. package/dist/runtime-options-BsPSv5O7.js +0 -13
  128. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  129. package/dist/shared-DTR1Hhma.js +0 -331
  130. package/dist/state-tYcRWEh2.d.ts +0 -26
  131. package/dist/store-Dt_Jyys3.js +0 -608
  132. package/dist/target-D4Bqb1eH.js +0 -11
  133. package/dist/token-CVzURBxC.js +0 -61
  134. package/dist/use-BiHzt0xA.d.ts +0 -103
  135. package/dist/vite-BptCrpv2.js +0 -4526
  136. package/dist/vite-CtA9guIM.d.ts +0 -66
  137. package/dist/workspace-Xddf4G1B.d.ts +0 -6
@@ -1,159 +0,0 @@
1
- import { t as useWorkspace } from "./use-BTNDR5Rd.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 };