@vite-hub/workspace 0.0.1 → 0.0.3

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 (95) hide show
  1. package/README.md +225 -17
  2. package/dist/{ai-Bk3LLnit.js → ai-Ce3PtWFW.js} +160 -29
  3. package/dist/ai-nmHdzjCM.d.ts +162 -0
  4. package/dist/ai.d.ts +2 -85
  5. package/dist/ai.js +1 -1
  6. package/dist/asset-registry-CaG9b7tf.js +19 -0
  7. package/dist/cloudflare.d.ts +18 -0
  8. package/dist/cloudflare.js +2 -0
  9. package/dist/collections/client.d.ts +39 -0
  10. package/dist/collections/client.js +137 -0
  11. package/dist/collections.d.ts +59 -0
  12. package/dist/collections.js +159 -0
  13. package/dist/config-3I1BnsdO.d.ts +28 -0
  14. package/dist/config-CDoyls2X.js +30 -0
  15. package/dist/config-CZLO0m9h.js +7811 -0
  16. package/dist/file-CHfsZpso.js +23 -0
  17. package/dist/{files-DbsIjBya.js → files-QRV55OCx.js} +6 -5
  18. package/dist/github-CfA5vpJ5.js +189 -0
  19. package/dist/glob-D0vD_wRY.js +17 -0
  20. package/dist/host-CAnbugpI.js +370 -0
  21. package/dist/hosted-C1-tTTTf.js +581 -0
  22. package/dist/{providers/vercel/blob-store.js → hosted-vercel-blob-CWBILDVo.js} +100 -19
  23. package/dist/hosted-vercel-blob.d.ts +15 -0
  24. package/dist/hosted-vercel-blob.js +2 -0
  25. package/dist/hosted.d.ts +18 -0
  26. package/dist/hosted.js +2 -0
  27. package/dist/index.d.ts +129 -102
  28. package/dist/index.js +477 -599
  29. package/dist/lifecycle-BYoa9hVb.js +176 -0
  30. package/dist/loader.d.ts +1 -1
  31. package/dist/loader.js +1 -1
  32. package/dist/mountx.d.ts +10 -0
  33. package/dist/mountx.js +143 -0
  34. package/dist/nitro.d.ts +2 -31
  35. package/dist/nitro.js +2 -2
  36. package/dist/nuxt.d.ts +26 -0
  37. package/dist/nuxt.js +36 -0
  38. package/dist/path-CNI6wKIU.js +115 -0
  39. package/dist/{provider-BZuKAV4e.js → provider-C3_elpEh.js} +142 -37
  40. package/dist/providers/github/store.d.ts +6 -0
  41. package/dist/providers/github/store.js +2 -0
  42. package/dist/publish.d.ts +3 -2
  43. package/dist/publish.js +48 -142
  44. package/dist/{registry-D4Qzq26I.d.ts → registry-BIQVCBWI.d.ts} +3 -2
  45. package/dist/registry-CqyDTW9Y.js +74 -0
  46. package/dist/request-execution-u9mgUXKX.js +80 -0
  47. package/dist/runtime/assets.d.ts +2 -1
  48. package/dist/runtime/assets.js +5 -5
  49. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  50. package/dist/runtime/empty-registry.d.ts +1 -1
  51. package/dist/runtime/state.d.ts +4 -21
  52. package/dist/runtime/state.js +7 -4
  53. package/dist/runtime/workspace.d.ts +2 -0
  54. package/dist/runtime/workspace.js +2 -0
  55. package/dist/runtime-options-BsPSv5O7.js +13 -0
  56. package/dist/runtime.d.ts +38 -0
  57. package/dist/runtime.js +626 -0
  58. package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
  59. package/dist/server.d.ts +65 -0
  60. package/dist/server.js +355 -0
  61. package/dist/shared-jfogBrd5.js +273 -0
  62. package/dist/source-metadata.d.ts +2 -0
  63. package/dist/source-metadata.js +2 -0
  64. package/dist/state-TTqa3x3Y.d.ts +25 -0
  65. package/dist/store-Bs1SLh55.js +414 -0
  66. package/dist/sync-DiuDmSGk.js +269 -0
  67. package/dist/target-D4Bqb1eH.js +11 -0
  68. package/dist/test.d.ts +1 -1
  69. package/dist/test.js +1 -1
  70. package/dist/types-60Yn149G.d.ts +612 -0
  71. package/dist/use-CUFSnFCS.d.ts +86 -0
  72. package/dist/use-CsV3oIxH.js +336 -0
  73. package/dist/vite-tbfDxtlu.js +2191 -0
  74. package/dist/vite.d.ts +33 -5
  75. package/dist/vite.js +2 -131
  76. package/dist/workspace-66SKyiec.d.ts +6 -0
  77. package/dist/workspace-C4k92Ow8.js +1460 -0
  78. package/package.json +143 -62
  79. package/dist/asset-registry-CMuQbyvl.js +0 -14
  80. package/dist/cloudflare-env-DL94Uvpz.js +0 -12
  81. package/dist/config-CvS-7sre.js +0 -49
  82. package/dist/errors-BUL8SoFS.js +0 -21
  83. package/dist/lifecycle-uD82JeGh.js +0 -92
  84. package/dist/module-8LZUMEXC.js +0 -922
  85. package/dist/path-BVv9OXhg.js +0 -63
  86. package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
  87. package/dist/providers/cloudflare/artifacts-store.js +0 -384
  88. package/dist/providers/vercel/blob-store.d.ts +0 -6
  89. package/dist/registry-Cnr0NoKv.js +0 -932
  90. package/dist/runtime/nitro-plugin.d.ts +0 -6
  91. package/dist/runtime/nitro-plugin.js +0 -14
  92. package/dist/sandbox-DtGXCWRq.js +0 -198
  93. package/dist/types-CwNcWTdt.d.ts +0 -378
  94. package/dist/utils-BtAm_K5P.js +0 -51
  95. /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
@@ -0,0 +1,162 @@
1
+ import { D as WorkspaceAssets, T as Workspace, et as WorkspaceMaterializeSourcesResult } from "./types-60Yn149G.js";
2
+ import { Tool, ToolSet } from "ai";
3
+
4
+ //#region src/ai.d.ts
5
+ type ShellObservationEvent = "command_finished" | "command_timed_out" | "policy_denied" | "session_disposed";
6
+ interface ShellRuntimeExecOptions {
7
+ cwd?: string;
8
+ env?: Record<string, string>;
9
+ onStderr?: (chunk: string) => void;
10
+ onStdout?: (chunk: string) => void;
11
+ stdin?: string;
12
+ timeout?: number;
13
+ workspacePaths?: string[];
14
+ }
15
+ interface ShellObservation {
16
+ command?: string;
17
+ cwd?: string;
18
+ durationMs?: number;
19
+ event: ShellObservationEvent;
20
+ exitCode: number | null;
21
+ maxOutputLength?: number;
22
+ outputTruncated?: boolean;
23
+ stderr: string;
24
+ stdout: string;
25
+ timedOut?: boolean;
26
+ workspaceGuardrail?: {
27
+ kind: "broad_search" | "missing_path" | "no_match" | "timeout";
28
+ path?: string;
29
+ };
30
+ }
31
+ interface ShellAnalyzeOptions {
32
+ maxInputBytes?: number;
33
+ timeoutMs?: number;
34
+ }
35
+ interface ShellAnalyzeResult {
36
+ commands?: string[];
37
+ error?: string;
38
+ hasCommandSubstitution?: boolean;
39
+ hasHeredocs?: boolean;
40
+ hasPipelines?: boolean;
41
+ hasRedirects?: boolean;
42
+ ok: boolean;
43
+ parser: "sh-syntax";
44
+ }
45
+ interface ShellProcess {
46
+ id: string;
47
+ command: string;
48
+ cwd?: string;
49
+ stop(): Promise<ShellObservation>;
50
+ }
51
+ interface ShellBoundary {
52
+ cwd: boolean;
53
+ env: boolean;
54
+ filesystem: {
55
+ mountPoint?: string;
56
+ writable: boolean;
57
+ };
58
+ network: boolean | "unknown";
59
+ processes: {
60
+ background: boolean;
61
+ interactive: boolean;
62
+ };
63
+ streaming: boolean;
64
+ timeout: {
65
+ enforcedBy: "provider" | "runtime" | "unsupported";
66
+ supported: boolean;
67
+ };
68
+ }
69
+ interface ShellExecutionProvider {
70
+ analyze?: (command: string, options?: ShellAnalyzeOptions) => Promise<ShellAnalyzeResult>;
71
+ boundary: ShellBoundary;
72
+ exec(command: string, options?: ShellRuntimeExecOptions): Promise<ShellObservation>;
73
+ startProcess?: (command: string, options?: ShellRuntimeExecOptions) => Promise<ShellProcess>;
74
+ }
75
+ interface ShellSessionPolicy {
76
+ maxOutputLength?: number;
77
+ maxShellCalls?: number;
78
+ timeout?: number;
79
+ }
80
+ type WorkspaceShellResult = ShellObservation;
81
+ interface WorkspacePathResult {
82
+ path: string;
83
+ }
84
+ interface WorkspaceMoveResult {
85
+ from: string;
86
+ to: string;
87
+ }
88
+ interface WorkspaceReadOperations {
89
+ list?: boolean;
90
+ materialize?: boolean;
91
+ read?: boolean;
92
+ search?: boolean;
93
+ }
94
+ interface WorkspaceWriteOperations {
95
+ appendFile?: boolean;
96
+ copyPath?: boolean;
97
+ deletePath?: boolean;
98
+ makeDir?: boolean;
99
+ movePath?: boolean;
100
+ writeFile?: boolean;
101
+ }
102
+ type WorkspaceToolOperations = WorkspaceReadOperations & {
103
+ write?: true | WorkspaceWriteOperations;
104
+ };
105
+ interface WorkspaceToolOptions<Operations extends WorkspaceToolOperations | undefined = undefined> extends Pick<ShellSessionPolicy, "maxOutputLength" | "maxShellCalls" | "timeout"> {
106
+ broadSearchPaths?: string[];
107
+ cwd?: string;
108
+ executionProvider?: ShellExecutionProvider | (() => MaybePromise<ShellExecutionProvider | undefined>);
109
+ operations?: Operations;
110
+ }
111
+ type EnabledReadCapability<Operations, Key extends keyof WorkspaceReadOperations> = Operations extends Record<Key, infer Value> ? Value extends false ? false : true : true;
112
+ type ShellEnabled<Operations> = true extends EnabledReadCapability<Operations, "list"> | EnabledReadCapability<Operations, "read"> | EnabledReadCapability<Operations, "search"> ? true : false;
113
+ type ResolvedWriteOperations<Operations> = Operations extends {
114
+ write: infer Write;
115
+ } ? Write : false;
116
+ type WorkspaceWriteToolMap = {
117
+ appendFile: Tool<{
118
+ content: string;
119
+ path: string;
120
+ }, WorkspacePathResult>;
121
+ copyPath: Tool<{
122
+ from: string;
123
+ overwrite?: boolean;
124
+ to: string;
125
+ }, WorkspaceMoveResult>;
126
+ deletePath: Tool<{
127
+ force?: boolean;
128
+ path: string;
129
+ recursive?: boolean;
130
+ }, WorkspacePathResult>;
131
+ makeDir: Tool<{
132
+ path: string;
133
+ recursive?: boolean;
134
+ }, WorkspacePathResult>;
135
+ movePath: Tool<{
136
+ from: string;
137
+ overwrite?: boolean;
138
+ to: string;
139
+ }, WorkspaceMoveResult>;
140
+ writeFile: Tool<{
141
+ content: string;
142
+ mediaType?: string;
143
+ path: string;
144
+ }, WorkspacePathResult>;
145
+ };
146
+ type EnabledWriteTools<Selection> = Selection extends true ? WorkspaceWriteToolMap : Selection extends WorkspaceWriteOperations ? { [Key in keyof WorkspaceWriteToolMap as Key extends keyof Selection ? Selection[Key] extends true ? Key : never : never]: WorkspaceWriteToolMap[Key] } : {};
147
+ type WorkspaceTools<Operations = undefined> = ((ShellEnabled<Operations> extends true ? {
148
+ shell: Tool<{
149
+ command: string;
150
+ }, WorkspaceShellResult>;
151
+ } : {}) & EnabledWriteTools<ResolvedWriteOperations<Operations>> & (Operations extends {
152
+ materialize: true;
153
+ } ? {
154
+ materialize_sources: Tool<{
155
+ path?: string;
156
+ sources?: string[];
157
+ }, WorkspaceMaterializeSourcesResult>;
158
+ } : {})) & ToolSet;
159
+ type MaybePromise<T> = T | Promise<T>;
160
+ declare function createWorkspaceTools<Operations extends WorkspaceToolOperations | undefined = undefined>(input: Workspace | WorkspaceAssets, options?: WorkspaceToolOptions<Operations>): WorkspaceTools<Operations>;
161
+ //#endregion
162
+ export { WorkspaceReadOperations as a, WorkspaceToolOptions as c, WorkspaceWriteToolMap as d, createWorkspaceTools as f, WorkspacePathResult as i, WorkspaceTools as l, ShellEnabled as n, WorkspaceShellResult as o, WorkspaceMoveResult as r, WorkspaceToolOperations as s, EnabledReadCapability as t, WorkspaceWriteOperations as u };
package/dist/ai.d.ts CHANGED
@@ -1,86 +1,3 @@
1
- import { B as WorkspaceMaterializeSourcesResult, C as WorkspaceAssets, x as Workspace } from "./types-CwNcWTdt.js";
2
- import { ShellObservation, ShellSessionPolicy } from "@vite-hub/shell";
3
- import { Tool, ToolSet } from "ai";
4
-
5
- //#region src/ai.d.ts
6
- type WorkspaceShellResult = ShellObservation;
7
- interface WorkspacePathResult {
8
- path: string;
9
- }
10
- interface WorkspaceMoveResult {
11
- from: string;
12
- to: string;
13
- }
14
- interface WorkspaceReadOperations {
15
- list?: boolean;
16
- materialize?: boolean;
17
- read?: boolean;
18
- search?: boolean;
19
- }
20
- interface WorkspaceWriteOperations {
21
- appendFile?: boolean;
22
- copyPath?: boolean;
23
- deletePath?: boolean;
24
- makeDir?: boolean;
25
- movePath?: boolean;
26
- writeFile?: boolean;
27
- }
28
- type WorkspaceToolOperations = WorkspaceReadOperations & {
29
- write?: true | WorkspaceWriteOperations;
30
- };
31
- interface WorkspaceToolOptions<Operations extends WorkspaceToolOperations | undefined = undefined> extends Pick<ShellSessionPolicy, "maxOutputLength" | "maxShellCalls" | "timeout"> {
32
- broadSearchPaths?: string[];
33
- cwd?: string;
34
- operations?: Operations;
35
- }
36
- type EnabledReadCapability<Operations, Key extends keyof WorkspaceReadOperations> = Operations extends Record<Key, infer Value> ? Value extends false ? false : true : true;
37
- type ShellEnabled<Operations> = true extends EnabledReadCapability<Operations, "list"> | EnabledReadCapability<Operations, "read"> | EnabledReadCapability<Operations, "search"> ? true : false;
38
- type ResolvedWriteOperations<Operations> = Operations extends {
39
- write: infer Write;
40
- } ? Write : false;
41
- type WorkspaceWriteToolMap = {
42
- appendFile: Tool<{
43
- content: string;
44
- path: string;
45
- }, WorkspacePathResult>;
46
- copyPath: Tool<{
47
- from: string;
48
- overwrite?: boolean;
49
- to: string;
50
- }, WorkspaceMoveResult>;
51
- deletePath: Tool<{
52
- force?: boolean;
53
- path: string;
54
- recursive?: boolean;
55
- }, WorkspacePathResult>;
56
- makeDir: Tool<{
57
- path: string;
58
- recursive?: boolean;
59
- }, WorkspacePathResult>;
60
- movePath: Tool<{
61
- from: string;
62
- overwrite?: boolean;
63
- to: string;
64
- }, WorkspaceMoveResult>;
65
- writeFile: Tool<{
66
- content: string;
67
- mediaType?: string;
68
- path: string;
69
- }, WorkspacePathResult>;
70
- };
71
- type EnabledWriteTools<Selection> = Selection extends true ? WorkspaceWriteToolMap : Selection extends WorkspaceWriteOperations ? { [Key in keyof WorkspaceWriteToolMap as Key extends keyof Selection ? Selection[Key] extends true ? Key : never : never]: WorkspaceWriteToolMap[Key] } : {};
72
- type WorkspaceTools<Operations = undefined> = ((ShellEnabled<Operations> extends true ? {
73
- shell: Tool<{
74
- command: string;
75
- }, WorkspaceShellResult>;
76
- } : {}) & EnabledWriteTools<ResolvedWriteOperations<Operations>> & (Operations extends {
77
- materialize: true;
78
- } ? {
79
- materialize_sources: Tool<{
80
- path?: string;
81
- sources?: string[];
82
- }, WorkspaceMaterializeSourcesResult>;
83
- } : {})) & ToolSet;
84
- declare function createWorkspaceTools<Operations extends WorkspaceToolOperations | undefined = undefined>(input: Workspace | WorkspaceAssets, options?: WorkspaceToolOptions<Operations>): WorkspaceTools<Operations>;
85
- //#endregion
1
+ import { et as WorkspaceMaterializeSourcesResult } from "./types-60Yn149G.js";
2
+ import { a as WorkspaceReadOperations, c as WorkspaceToolOptions, d as WorkspaceWriteToolMap, f as createWorkspaceTools, i as WorkspacePathResult, l as WorkspaceTools, n as ShellEnabled, o as WorkspaceShellResult, r as WorkspaceMoveResult, s as WorkspaceToolOperations, t as EnabledReadCapability, u as WorkspaceWriteOperations } from "./ai-nmHdzjCM.js";
86
3
  export { EnabledReadCapability, ShellEnabled, type WorkspaceMaterializeSourcesResult, WorkspaceMoveResult, WorkspacePathResult, WorkspaceReadOperations, WorkspaceShellResult, WorkspaceToolOperations, WorkspaceToolOptions, WorkspaceTools, WorkspaceWriteOperations, WorkspaceWriteToolMap, createWorkspaceTools };
package/dist/ai.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createWorkspaceTools } from "./ai-Bk3LLnit.js";
1
+ import { t as createWorkspaceTools } from "./ai-Ce3PtWFW.js";
2
2
  export { createWorkspaceTools };
@@ -0,0 +1,19 @@
1
+ import { m as workspaceNotFoundError } from "./path-CNI6wKIU.js";
2
+ import runtimeAssetsRegistry from "#vitehub-workspace-assets-registry";
3
+ //#region src/asset-registry.ts
4
+ const workspaceAssetsRegistryKey = Symbol.for("vitehub.workspace.assetsRegistry");
5
+ function workspaceAssetsRegistryGlobal() {
6
+ const scope = globalThis;
7
+ scope[workspaceAssetsRegistryKey] ??= runtimeAssetsRegistry;
8
+ return scope;
9
+ }
10
+ function setWorkspaceAssetsRegistry(registry) {
11
+ workspaceAssetsRegistryGlobal()[workspaceAssetsRegistryKey] = registry;
12
+ }
13
+ function useWorkspaceAssets(name) {
14
+ const assets = workspaceAssetsRegistryGlobal()[workspaceAssetsRegistryKey]?.[name];
15
+ if (!assets) throw workspaceNotFoundError(name);
16
+ return assets;
17
+ }
18
+ //#endregion
19
+ export { useWorkspaceAssets as n, setWorkspaceAssetsRegistry as t };
@@ -0,0 +1,18 @@
1
+ import { Jt as WorkspaceStore, o as GitHubWorkspaceStoreOptions, t as CloudflareArtifactsWorkspaceStoreOptions, v as ResolvedWorkspaceModuleOptions } from "./types-60Yn149G.js";
2
+ import { configureHostedWorkspaceRuntime } from "./hosted.js";
3
+
4
+ //#region src/providers/cloudflare/artifacts-store.d.ts
5
+ declare function createCloudflareArtifactsWorkspaceStore(options: CloudflareArtifactsWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
6
+ //#endregion
7
+ //#region src/cloudflare.d.ts
8
+ type CloudflareWorkspaceRuntimeStoreOptions = Partial<CloudflareArtifactsWorkspaceStoreOptions> | (Partial<GitHubWorkspaceStoreOptions> & {
9
+ provider: "github";
10
+ });
11
+ interface CloudflareWorkspaceRuntimeOptions {
12
+ assets?: boolean | string[];
13
+ env?: Record<string, string | undefined>;
14
+ root?: string;
15
+ store?: CloudflareWorkspaceRuntimeStoreOptions;
16
+ }
17
+ //#endregion
18
+ export { type CloudflareArtifactsWorkspaceStoreOptions, CloudflareWorkspaceRuntimeOptions, CloudflareWorkspaceRuntimeStoreOptions, type GitHubWorkspaceStoreOptions, type ResolvedWorkspaceModuleOptions, configureHostedWorkspaceRuntime as configureCloudflareWorkspaceRuntime, createCloudflareArtifactsWorkspaceStore };
@@ -0,0 +1,2 @@
1
+ import { r as createCloudflareArtifactsWorkspaceStore, t as configureHostedWorkspaceRuntime } from "./hosted-C1-tTTTf.js";
2
+ export { configureHostedWorkspaceRuntime as configureCloudflareWorkspaceRuntime, createCloudflareArtifactsWorkspaceStore };
@@ -0,0 +1,39 @@
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 };
@@ -0,0 +1,137 @@
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 };
@@ -0,0 +1,59 @@
1
+ import { rt as WorkspaceName } from "./types-60Yn149G.js";
2
+ import { t as ReadonlyWorkspaceFacade } from "./use-CUFSnFCS.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 };