@vite-hub/workspace 0.0.4 → 0.1.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 (127) hide show
  1. package/README.md +225 -58
  2. package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
  3. package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
  4. package/dist/ai.d.ts +2 -2
  5. package/dist/ai.js +1 -1
  6. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  7. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
  8. package/dist/blob-database.d.ts +521 -0
  9. package/dist/blob-database.js +601 -0
  10. package/dist/cloudflare.d.ts +5 -6
  11. package/dist/cloudflare.js +1 -1
  12. package/dist/config-B7dmzDX3.js +1112 -0
  13. package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
  14. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  15. package/dist/error-diagnostics-DY5GP47p.js +96 -0
  16. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
  17. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
  18. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
  19. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
  20. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
  21. package/dist/file-C0_aPWSS.js +26 -0
  22. package/dist/file-metadata-CxDy-E2H.js +58 -0
  23. package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
  24. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
  25. package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
  26. package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
  27. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
  28. package/dist/glob--XcLlcml.js +22 -0
  29. package/dist/glob--kNYDbfU.js +30 -0
  30. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
  31. package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
  32. package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
  33. package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
  34. package/dist/hosted-vercel-blob.d.ts +5 -6
  35. package/dist/hosted-vercel-blob.js +1 -1
  36. package/dist/hosted.d.ts +6 -7
  37. package/dist/hosted.js +1 -1
  38. package/dist/index.d.ts +57 -36
  39. package/dist/index.js +56 -56
  40. package/dist/inspect-BoObD2cJ.js +167 -0
  41. package/dist/internal/path.d.ts +2 -0
  42. package/dist/internal/path.js +2 -0
  43. package/dist/lifecycle-BwZ7c9hb.js +596 -0
  44. package/dist/loader.d.ts +5 -6
  45. package/dist/loader.js +3 -2
  46. package/dist/mcp-resources-BREFCmtn.js +39 -0
  47. package/dist/memory-BbwOqDXl.js +248 -0
  48. package/dist/metadata-target-DZEZQGHA.js +1588 -0
  49. package/dist/mountx.d.ts +4 -6
  50. package/dist/mountx.js +10 -8
  51. package/dist/nitro.d.ts +1 -1
  52. package/dist/nitro.js +1 -1
  53. package/dist/nuxt.d.ts +13 -12
  54. package/dist/nuxt.js +4 -8
  55. package/dist/operations-BcpWr41m.js +159 -0
  56. package/dist/operations-CGqY1XeG.js +965 -0
  57. package/dist/operations-DnOwKsJT.d.ts +136 -0
  58. package/dist/operations.d.ts +53 -0
  59. package/dist/operations.js +2 -0
  60. package/dist/path-CNAwN7pw.js +114 -0
  61. package/dist/path-DrSIenjj.js +59 -0
  62. package/dist/path-zHxQUbqa.d.ts +9 -0
  63. package/dist/plugins-DqQ8b4T5.d.ts +10 -0
  64. package/dist/provider-kXjfli9u.js +1457 -0
  65. package/dist/providers/github/store.d.ts +3 -5
  66. package/dist/providers/github/store.js +1 -1
  67. package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
  68. package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
  69. package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
  70. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
  71. package/dist/runtime/assets.d.ts +3 -5
  72. package/dist/runtime/assets.js +7 -6
  73. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  74. package/dist/runtime/empty-registry.d.ts +1 -2
  75. package/dist/runtime/state.d.ts +3 -3
  76. package/dist/runtime/state.js +6 -6
  77. package/dist/runtime/workspace.d.ts +1 -1
  78. package/dist/runtime/workspace.js +1 -1
  79. package/dist/runtime.d.ts +51 -17
  80. package/dist/runtime.js +320 -60
  81. package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
  82. package/dist/server-BNQ-Nbjj.js +290 -0
  83. package/dist/server.d.ts +22 -34
  84. package/dist/server.js +2 -328
  85. package/dist/shared-DalXdP0i.js +2158 -0
  86. package/dist/source-metadata.d.ts +6 -7
  87. package/dist/source-metadata.js +7 -7
  88. package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
  89. package/dist/store-CXgmu-uw.js +1729 -0
  90. package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
  91. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
  92. package/dist/test.d.ts +1 -1
  93. package/dist/test.js +1 -1
  94. package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
  95. package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
  96. package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
  97. package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
  98. package/dist/utils-Blrh4N2n.js +545 -0
  99. package/dist/vite-BEvgU2GY.js +20909 -0
  100. package/dist/vite-CcZmMQ7S.d.ts +476 -0
  101. package/dist/vite.d.ts +2 -2
  102. package/dist/vite.js +2 -2
  103. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
  104. package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
  105. package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
  106. package/package.json +89 -55
  107. package/dist/collections/client.d.ts +0 -39
  108. package/dist/collections/client.js +0 -137
  109. package/dist/collections.d.ts +0 -59
  110. package/dist/collections.js +0 -159
  111. package/dist/config-Bc3c4Su1.js +0 -7904
  112. package/dist/config-CHLLWklZ.js +0 -36
  113. package/dist/file-Bc1X7pco.js +0 -23
  114. package/dist/glob-CEZKeZFC.js +0 -18
  115. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  116. package/dist/lifecycle-LrL3sA4n.js +0 -316
  117. package/dist/metadata-target-B0tOmVW7.js +0 -717
  118. package/dist/path-Cp59koVz.js +0 -139
  119. package/dist/provider-B1yLjCJJ.js +0 -746
  120. package/dist/publish.d.ts +0 -35
  121. package/dist/publish.js +0 -112
  122. package/dist/runtime-options-BsPSv5O7.js +0 -13
  123. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  124. package/dist/shared-DTR1Hhma.js +0 -331
  125. package/dist/store-Dt_Jyys3.js +0 -608
  126. package/dist/vite-BptCrpv2.js +0 -4526
  127. package/dist/vite-CtA9guIM.d.ts +0 -66
@@ -1,6 +1,7 @@
1
- import { F as WorkspaceDefinition, T as Workspace } from "./types-CYuwjJ4V.js";
2
-
1
+ import { F as WorkspaceDefinition, T as Workspace } from "./types-DeK9GIxy.js";
3
2
  //#region src/core/workspace.d.ts
4
- declare function createWorkspace(definition: WorkspaceDefinition): Workspace;
3
+ declare function createWorkspace(definition: WorkspaceDefinition, options?: {
4
+ reuseStartupSnapshots?: boolean;
5
+ }): Workspace;
5
6
  //#endregion
6
7
  export { createWorkspace as t };
package/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "@vite-hub/workspace",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "Agent-oriented filesystem state and Vite integration for ViteHub.",
5
5
  "keywords": [
6
+ "ai-agents",
6
7
  "cloudflare",
8
+ "filesystem",
9
+ "nuxt",
10
+ "nuxt-module",
11
+ "typescript",
7
12
  "vercel",
8
13
  "vite",
9
14
  "vitehub",
10
15
  "workspace"
11
16
  ],
12
- "homepage": "https://github.com/vite-hub/vitehub#readme",
17
+ "homepage": "https://vitehub.dev",
13
18
  "bugs": "https://github.com/vite-hub/vitehub/issues",
14
19
  "license": "Apache-2.0",
15
20
  "author": "onmax <maximogarciamtnez@gmail.com>",
@@ -38,127 +43,156 @@
38
43
  "exports": {
39
44
  ".": {
40
45
  "types": "./dist/index.d.ts",
41
- "import": "./dist/index.js"
46
+ "import": "./dist/index.js",
47
+ "default": "./dist/index.js"
42
48
  },
43
49
  "./ai": {
44
50
  "types": "./dist/ai.d.ts",
45
- "import": "./dist/ai.js"
51
+ "import": "./dist/ai.js",
52
+ "default": "./dist/ai.js"
53
+ },
54
+ "./blob-database": {
55
+ "types": "./dist/blob-database.d.ts",
56
+ "import": "./dist/blob-database.js",
57
+ "default": "./dist/blob-database.js"
46
58
  },
47
59
  "./cloudflare": {
48
60
  "types": "./dist/cloudflare.d.ts",
49
- "import": "./dist/cloudflare.js"
50
- },
51
- "./collections": {
52
- "types": "./dist/collections.d.ts",
53
- "import": "./dist/collections.js"
61
+ "import": "./dist/cloudflare.js",
62
+ "default": "./dist/cloudflare.js"
54
63
  },
55
- "./collections/client": {
56
- "types": "./dist/collections/client.d.ts",
57
- "import": "./dist/collections/client.js"
64
+ "./internal/path": {
65
+ "types": "./dist/internal/path.d.ts",
66
+ "import": "./dist/internal/path.js",
67
+ "default": "./dist/internal/path.js"
58
68
  },
59
69
  "./loader": {
60
70
  "types": "./dist/loader.d.ts",
61
- "import": "./dist/loader.js"
71
+ "import": "./dist/loader.js",
72
+ "default": "./dist/loader.js"
62
73
  },
63
74
  "./mountx": {
64
75
  "types": "./dist/mountx.d.ts",
65
- "import": "./dist/mountx.js"
76
+ "import": "./dist/mountx.js",
77
+ "default": "./dist/mountx.js"
66
78
  },
67
79
  "./nitro": {
68
80
  "types": "./dist/nitro.d.ts",
69
- "import": "./dist/nitro.js"
81
+ "import": "./dist/nitro.js",
82
+ "default": "./dist/nitro.js"
70
83
  },
71
84
  "./nuxt": {
72
85
  "types": "./dist/nuxt.d.ts",
73
- "import": "./dist/nuxt.js"
86
+ "import": "./dist/nuxt.js",
87
+ "default": "./dist/nuxt.js"
74
88
  },
75
- "./publish": {
76
- "types": "./dist/publish.d.ts",
77
- "import": "./dist/publish.js"
89
+ "./operations": {
90
+ "types": "./dist/operations.d.ts",
91
+ "import": "./dist/operations.js",
92
+ "default": "./dist/operations.js"
78
93
  },
79
94
  "./runtime": {
80
95
  "types": "./dist/runtime.d.ts",
81
- "import": "./dist/runtime.js"
96
+ "import": "./dist/runtime.js",
97
+ "default": "./dist/runtime.js"
82
98
  },
83
99
  "./server": {
84
100
  "types": "./dist/server.d.ts",
85
- "import": "./dist/server.js"
101
+ "import": "./dist/server.js",
102
+ "default": "./dist/server.js"
86
103
  },
87
104
  "./source-metadata": {
88
105
  "types": "./dist/source-metadata.d.ts",
89
- "import": "./dist/source-metadata.js"
106
+ "import": "./dist/source-metadata.js",
107
+ "default": "./dist/source-metadata.js"
90
108
  },
91
109
  "./test": {
92
110
  "types": "./dist/test.d.ts",
93
- "import": "./dist/test.js"
111
+ "import": "./dist/test.js",
112
+ "default": "./dist/test.js"
94
113
  },
95
114
  "./vite": {
96
115
  "types": "./dist/vite.d.ts",
97
- "import": "./dist/vite.js"
116
+ "import": "./dist/vite.js",
117
+ "default": "./dist/vite.js"
98
118
  },
99
119
  "./package.json": "./package.json",
100
120
  "./internal/runtime/assets": {
101
121
  "types": "./dist/runtime/assets.d.ts",
102
- "import": "./dist/runtime/assets.js"
122
+ "import": "./dist/runtime/assets.js",
123
+ "default": "./dist/runtime/assets.js"
103
124
  },
104
125
  "./internal/runtime/hosted": {
105
126
  "types": "./dist/hosted.d.ts",
106
- "import": "./dist/hosted.js"
127
+ "import": "./dist/hosted.js",
128
+ "default": "./dist/hosted.js"
107
129
  },
108
130
  "./internal/runtime/hosted-vercel-blob": {
109
131
  "types": "./dist/hosted-vercel-blob.d.ts",
110
- "import": "./dist/hosted-vercel-blob.js"
132
+ "import": "./dist/hosted-vercel-blob.js",
133
+ "default": "./dist/hosted-vercel-blob.js"
111
134
  },
112
135
  "./internal/runtime/state": {
113
136
  "types": "./dist/runtime/state.d.ts",
114
- "import": "./dist/runtime/state.js"
137
+ "import": "./dist/runtime/state.js",
138
+ "default": "./dist/runtime/state.js"
115
139
  },
116
140
  "./internal/runtime/workspace": {
117
141
  "types": "./dist/runtime/workspace.d.ts",
118
- "import": "./dist/runtime/workspace.js"
142
+ "import": "./dist/runtime/workspace.js",
143
+ "default": "./dist/runtime/workspace.js"
119
144
  },
120
145
  "./internal/stores/github": {
121
146
  "types": "./dist/providers/github/store.d.ts",
122
- "import": "./dist/providers/github/store.js"
147
+ "import": "./dist/providers/github/store.js",
148
+ "default": "./dist/providers/github/store.js"
123
149
  }
124
150
  },
125
151
  "dependencies": {
126
- "@vite-hub/box": "0.0.4",
127
- "@vercel/nft": "^1.10.2",
128
- "@vite-hub/markdown-template": "0.0.4",
129
- "@vite-hub/runtime": "0.0.4",
130
- "@vite-hub/source": "0.0.4",
152
+ "@standard-schema/spec": "^1.1.0",
153
+ "@vercel/nft": "^1.11.0",
154
+ "@vite-hub/forge": "0.1.0",
155
+ "@vite-hub/runtime": "0.1.0",
156
+ "@vite-hub/source": "0.1.0",
131
157
  "defu": "^6.1.7",
132
- "esbuild": "^0.27.7",
133
- "exsolve": "^1.1.0",
134
- "h3": "2.0.1-rc.25",
135
- "isomorphic-git": "^1.38.7",
158
+ "esbuild": "^0.28.2",
159
+ "exsolve": "^1.1.3",
160
+ "h3": "2.0.1-rc.33",
161
+ "isomorphic-git": "^1.42.6",
136
162
  "jiti": "^2.7.0",
137
- "mountx": "0.0.2",
138
163
  "minimatch": "^10.2.6",
164
+ "mountx": "0.0.2",
139
165
  "mrmime": "^2.0.1",
140
- "ofetch": "^1.5.1"
166
+ "nostics": "1.3.0",
167
+ "ofetch": "^1.5.1",
168
+ "valibot": "^1.5.0",
169
+ "@vite-hub/markdown-template": "0.1.0",
170
+ "@vite-hub/blob": "0.1.0",
171
+ "@vite-hub/database": "0.1.0",
172
+ "@vite-hub/sandbox": "0.1.0"
141
173
  },
142
174
  "devDependencies": {
143
- "@types/node": "^24.13.3",
175
+ "@types/node": "^24.19.1",
144
176
  "@vercel/blob": "^2.8.0",
145
- "@vite-hub/env": "0.0.4",
146
- "@vite-hub/shell": "0.0.4",
147
- "ai": "7.0.58",
148
- "ocache": "^0.1.5",
149
- "publint": "^0.3.21",
177
+ "@vite-hub/env": "0.1.0",
178
+ "@vite-hub/shell": "0.1.0",
179
+ "ai": "7.0.130",
180
+ "ocache": "^0.3.0",
181
+ "publint": "^0.3.25",
150
182
  "typescript": "^6.0.3",
151
- "vite": "^8.0.8",
152
- "vite-plus": "^0.1.24",
153
- "vitest": "^4.1.4",
154
- "vue": "^3.5.0",
183
+ "vite": "^8.2.2",
184
+ "vite-plus": "^0.3.3",
185
+ "vitest": "^4.1.11",
186
+ "drizzle-orm": "^0.45.3",
187
+ "miniflare": "4.20260730.0",
188
+ "@libsql/client": "^0.18.0",
155
189
  "@vite-hub/internal": "0.0.1"
156
190
  },
157
191
  "peerDependencies": {
158
- "@vite-hub/shell": "0.0.4",
192
+ "@vite-hub/shell": "0.1.0",
159
193
  "ai": "^6.0.0 || ^7.0.0-0",
160
194
  "vite": ">=8.0.0",
161
- "vue": "^3.5.0"
195
+ "drizzle-orm": "^0.45.3"
162
196
  },
163
197
  "peerDependenciesMeta": {
164
198
  "@vite-hub/shell": {
@@ -167,7 +201,7 @@
167
201
  "vite": {
168
202
  "optional": true
169
203
  },
170
- "vue": {
204
+ "drizzle-orm": {
171
205
  "optional": true
172
206
  }
173
207
  },
@@ -177,7 +211,7 @@
177
211
  "scripts": {
178
212
  "build": "vp pack",
179
213
  "dev": "vp pack --watch",
180
- "typecheck": "tsc --noEmit -p ./tsconfig.json",
214
+ "typecheck": "vp run --cache -t @vite-hub/workspace#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
181
215
  "test": "vp run -t @vite-hub/workspace#build && vp test"
182
216
  }
183
217
  }
@@ -1,39 +0,0 @@
1
- import { WorkspaceCollectionItem, WorkspaceCollectionPage } from "../collections.js";
2
- import { ComputedRef, MaybeRefOrGetter, Ref } from "vue";
3
-
4
- //#region src/collections/client.d.ts
5
- interface WorkspaceCollectionRequestOptions {
6
- query?: Record<string, unknown>;
7
- signal: AbortSignal;
8
- }
9
- type WorkspaceCollectionRequester = <T>(endpoint: string, options: WorkspaceCollectionRequestOptions) => Promise<T>;
10
- interface UseWorkspaceCollectionOptions {
11
- immediate?: boolean;
12
- limit?: number;
13
- query?: MaybeRefOrGetter<Record<string, unknown>>;
14
- request?: WorkspaceCollectionRequester;
15
- }
16
- interface UseWorkspaceCollectionReturn<T> {
17
- error: Ref<unknown>;
18
- facets: Ref<WorkspaceCollectionPage<T>["facets"]>;
19
- hasMore: ComputedRef<boolean>;
20
- items: Ref<T[]>;
21
- loadMore: () => Promise<WorkspaceCollectionPage<T> | undefined>;
22
- pending: Ref<boolean>;
23
- refresh: () => Promise<WorkspaceCollectionPage<T> | undefined>;
24
- total: Ref<number>;
25
- }
26
- interface UseWorkspaceCollectionItemOptions {
27
- immediate?: boolean;
28
- request?: WorkspaceCollectionRequester;
29
- }
30
- interface UseWorkspaceCollectionItemReturn<T> {
31
- data: Ref<T | null>;
32
- error: Ref<unknown>;
33
- pending: Ref<boolean>;
34
- refresh: () => Promise<WorkspaceCollectionItem<T> | undefined>;
35
- }
36
- declare function useWorkspaceCollection<T = Record<string, unknown>>(endpoint: string, options?: UseWorkspaceCollectionOptions): UseWorkspaceCollectionReturn<T>;
37
- declare function useWorkspaceCollectionItem<T = Record<string, unknown>>(endpoint: string, value: MaybeRefOrGetter<string | undefined>, options?: UseWorkspaceCollectionItemOptions): UseWorkspaceCollectionItemReturn<T>;
38
- //#endregion
39
- export { UseWorkspaceCollectionItemOptions, UseWorkspaceCollectionItemReturn, UseWorkspaceCollectionOptions, UseWorkspaceCollectionReturn, WorkspaceCollectionRequestOptions, WorkspaceCollectionRequester, useWorkspaceCollection, useWorkspaceCollectionItem };
@@ -1,137 +0,0 @@
1
- import { $fetch } from "ofetch";
2
- import { computed, onScopeDispose, ref, toValue, watch } from "vue";
3
- //#region src/collections/client.ts
4
- const defaultRequester = async (endpoint, options) => {
5
- return await $fetch(endpoint, options);
6
- };
7
- function isAbortError(error) {
8
- return Boolean(error && typeof error === "object" && "name" in error && error.name === "AbortError");
9
- }
10
- function isStaleCursorError(error) {
11
- if (!error || typeof error !== "object") return false;
12
- return ("statusCode" in error ? error.statusCode : "status" in error ? error.status : void 0) === 409;
13
- }
14
- function useWorkspaceCollection(endpoint, options = {}) {
15
- const items = ref([]);
16
- const facets = ref({});
17
- const total = ref(0);
18
- const nextCursor = ref(null);
19
- const pending = ref(false);
20
- const error = ref(null);
21
- const request = options.request || defaultRequester;
22
- let active;
23
- let loaded = false;
24
- async function load(reset) {
25
- if (!reset && (pending.value || loaded && !nextCursor.value)) return;
26
- active?.abort();
27
- const controller = new AbortController();
28
- active = controller;
29
- pending.value = true;
30
- error.value = null;
31
- try {
32
- const response = await request(endpoint, {
33
- query: {
34
- ...options.query ? toValue(options.query) : {},
35
- cursor: reset ? void 0 : nextCursor.value || void 0,
36
- limit: options.limit
37
- },
38
- signal: controller.signal
39
- });
40
- if (active !== controller) return;
41
- items.value = reset ? response.items : [...items.value, ...response.items];
42
- facets.value = response.facets;
43
- total.value = response.total;
44
- nextCursor.value = response.nextCursor;
45
- loaded = true;
46
- return response;
47
- } catch (cause) {
48
- if (active !== controller || isAbortError(cause)) return;
49
- if (!reset && isStaleCursorError(cause)) return await load(true);
50
- error.value = cause;
51
- } finally {
52
- if (active === controller) {
53
- active = void 0;
54
- pending.value = false;
55
- }
56
- }
57
- }
58
- const stop = watch(() => options.query ? toValue(options.query) : void 0, () => {
59
- load(true);
60
- }, {
61
- deep: true,
62
- immediate: options.immediate !== false && (options.request !== void 0 || "window" in globalThis)
63
- });
64
- onScopeDispose(() => {
65
- stop();
66
- active?.abort();
67
- active = void 0;
68
- pending.value = false;
69
- });
70
- return {
71
- error,
72
- facets,
73
- hasMore: computed(() => Boolean(nextCursor.value)),
74
- items,
75
- loadMore: () => load(false),
76
- pending,
77
- refresh: () => load(true),
78
- total
79
- };
80
- }
81
- function useWorkspaceCollectionItem(endpoint, value, options = {}) {
82
- const data = ref(null);
83
- const pending = ref(false);
84
- const error = ref(null);
85
- const request = options.request || defaultRequester;
86
- let active;
87
- async function refresh() {
88
- const resolvedValue = toValue(value);
89
- if (resolvedValue === void 0) {
90
- active?.abort();
91
- active = void 0;
92
- data.value = null;
93
- error.value = null;
94
- pending.value = false;
95
- return;
96
- }
97
- active?.abort();
98
- const controller = new AbortController();
99
- active = controller;
100
- pending.value = true;
101
- error.value = null;
102
- try {
103
- const response = await request(endpoint, {
104
- query: { value: resolvedValue },
105
- signal: controller.signal
106
- });
107
- if (active !== controller) return;
108
- data.value = response.item;
109
- return response;
110
- } catch (cause) {
111
- if (active !== controller || isAbortError(cause)) return;
112
- error.value = cause;
113
- } finally {
114
- if (active === controller) {
115
- active = void 0;
116
- pending.value = false;
117
- }
118
- }
119
- }
120
- const stop = watch(() => toValue(value), () => {
121
- refresh();
122
- }, { immediate: options.immediate !== false && (options.request !== void 0 || "window" in globalThis) });
123
- onScopeDispose(() => {
124
- stop();
125
- active?.abort();
126
- active = void 0;
127
- pending.value = false;
128
- });
129
- return {
130
- data,
131
- error,
132
- pending,
133
- refresh
134
- };
135
- }
136
- //#endregion
137
- export { useWorkspaceCollection, useWorkspaceCollectionItem };
@@ -1,59 +0,0 @@
1
- import { it as WorkspaceName } from "./types-CYuwjJ4V.js";
2
- import { i as ReadonlyWorkspaceFacade } from "./use-BiHzt0xA.js";
3
-
4
- //#region src/collections.d.ts
5
- interface WorkspaceCollectionEmptyFilter {
6
- empty: true;
7
- }
8
- declare const workspaceCollectionEmpty: WorkspaceCollectionEmptyFilter;
9
- type WorkspaceCollectionFilter = string | string[] | WorkspaceCollectionEmptyFilter;
10
- interface WorkspaceCollectionSort {
11
- direction?: "asc" | "desc";
12
- field: string;
13
- }
14
- interface WorkspaceCollectionQuery {
15
- cursor?: string;
16
- facets?: string[];
17
- filters?: Record<string, WorkspaceCollectionFilter | undefined>;
18
- limit?: number;
19
- search?: string;
20
- searchFields?: string[];
21
- select?: string[];
22
- sort?: WorkspaceCollectionSort;
23
- }
24
- interface WorkspaceCollectionItemQuery {
25
- key: string;
26
- select?: string[];
27
- value: string | number;
28
- }
29
- interface WorkspaceCollectionOptions<Name extends WorkspaceName = WorkspaceName> {
30
- defaultLimit?: number;
31
- maxLimit?: number;
32
- path: string;
33
- workspace: Name | ReadonlyWorkspaceFacade<Name> | Promise<ReadonlyWorkspaceFacade<Name>>;
34
- }
35
- interface WorkspaceCollectionPageOptions<Name extends WorkspaceName = WorkspaceName> extends WorkspaceCollectionOptions<Name> {
36
- query?: WorkspaceCollectionQuery;
37
- }
38
- interface WorkspaceCollectionItemOptions<Name extends WorkspaceName = WorkspaceName> extends WorkspaceCollectionOptions<Name> {
39
- query: WorkspaceCollectionItemQuery;
40
- }
41
- interface WorkspaceCollectionFacetValue {
42
- count: number;
43
- value: string;
44
- }
45
- interface WorkspaceCollectionPage<T = Record<string, unknown>> {
46
- digest: string;
47
- facets: Record<string, WorkspaceCollectionFacetValue[]>;
48
- items: T[];
49
- nextCursor: string | null;
50
- total: number;
51
- }
52
- interface WorkspaceCollectionItem<T = Record<string, unknown>> {
53
- digest: string;
54
- item: T | null;
55
- }
56
- declare function queryWorkspaceCollection<T = Record<string, unknown>, Name extends WorkspaceName = WorkspaceName>(options: WorkspaceCollectionPageOptions<Name>): Promise<WorkspaceCollectionPage<T>>;
57
- declare function getWorkspaceCollectionItem<T = Record<string, unknown>, Name extends WorkspaceName = WorkspaceName>(options: WorkspaceCollectionItemOptions<Name>): Promise<WorkspaceCollectionItem<T>>;
58
- //#endregion
59
- export { WorkspaceCollectionEmptyFilter, WorkspaceCollectionFacetValue, WorkspaceCollectionFilter, WorkspaceCollectionItem, WorkspaceCollectionItemOptions, WorkspaceCollectionItemQuery, WorkspaceCollectionOptions, WorkspaceCollectionPage, WorkspaceCollectionPageOptions, WorkspaceCollectionQuery, WorkspaceCollectionSort, getWorkspaceCollectionItem, queryWorkspaceCollection, workspaceCollectionEmpty };
@@ -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 };