@vite-hub/workspace 0.0.3 → 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.
- package/LICENSE +201 -0
- package/README.md +236 -58
- package/dist/{ai-nmHdzjCM.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-Ce3PtWFW.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-CaG9b7tf.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-3I1BnsdO.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-QRV55OCx.js → files-C7Px8uaC.js} +21 -10
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-CfA5vpJ5.js → github-CPxHtFB7.js} +36 -34
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/host-CFnrTXTK.js +1086 -0
- package/dist/{hosted-C1-tTTTf.js → hosted-acMA5XyL.js} +216 -43
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +76 -64
- package/dist/index.js +162 -457
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +10 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/{path-CNI6wKIU.js → path-CNAwN7pw.js} +34 -35
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-Bp-8UUfG.js +129 -0
- package/dist/{registry-BIQVCBWI.d.ts → registry-Cg1TJVVZ.d.ts} +3 -4
- package/dist/{request-execution-u9mgUXKX.js → request-execution-Dk9rY-Yh.js} +24 -20
- package/dist/rolldown-runtime-B4iAMlE-.js +35 -0
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +9 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +1 -2
- package/dist/runtime/state.d.ts +4 -4
- package/dist/runtime/state.js +10 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +84 -15
- package/dist/runtime.js +561 -108
- package/dist/{search-C4REyHj9.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -355
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +7 -1
- package/dist/source-metadata.js +34 -2
- package/dist/{state-TTqa3x3Y.d.ts → state-B8zbLi5t.d.ts} +14 -13
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DiuDmSGk.js → sync-CN6ec-5M.js} +62 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/token-CO62GglH.js +61 -0
- package/dist/{types-60Yn149G.d.ts → types-DeK9GIxy.d.ts} +348 -49
- package/dist/{use-CsV3oIxH.js → use-BQj7nSz6.js} +200 -45
- package/dist/{use-CUFSnFCS.d.ts → use-DhwhbAVV.d.ts} +34 -12
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -50
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/workspace-6pxkOuxr.js +1286 -0
- package/dist/workspace-BWJQBK1u.d.ts +7 -0
- package/package.json +90 -59
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-CDoyls2X.js +0 -30
- package/dist/config-CZLO0m9h.js +0 -7811
- package/dist/file-CHfsZpso.js +0 -23
- package/dist/glob-D0vD_wRY.js +0 -17
- package/dist/host-CAnbugpI.js +0 -370
- package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
- package/dist/lifecycle-BYoa9hVb.js +0 -176
- package/dist/provider-C3_elpEh.js +0 -599
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/registry-CqyDTW9Y.js +0 -74
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/shared-jfogBrd5.js +0 -273
- package/dist/store-Bs1SLh55.js +0 -414
- package/dist/vite-tbfDxtlu.js +0 -2191
- package/dist/workspace-66SKyiec.d.ts +0 -6
- package/dist/workspace-C4k92Ow8.js +0 -1460
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
import { s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
2
|
+
import { a as isExcludedWorkspacePath, f as sha256, i as decodeFile, o as isWorkspaceBytes, r as contentToBytes } from "./path-CNAwN7pw.js";
|
|
3
|
+
import { r as workspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
4
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
|
|
5
|
+
import { n as forkMemoryWorkspaceStore, r as vitehubOwnedPrefix, t as createMemoryWorkspaceStore } from "./memory-BbwOqDXl.js";
|
|
6
|
+
import { n as copyJsonWorkspaceMetadata, t as copyJsonFileMetadata } from "./file-metadata-CxDy-E2H.js";
|
|
7
|
+
import { d as normalizeHistoryRef, l as historyConflict, n as createSnapshotFromEntries, p as validateHistoryMessage, r as diffSnapshots, u as normalizeHistoryPath } from "./utils-Blrh4N2n.js";
|
|
8
|
+
import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
|
|
9
|
+
import { ViteHubError } from "@vite-hub/runtime";
|
|
10
|
+
import { and, desc, eq, inArray, isNotNull, lt, sql } from "drizzle-orm";
|
|
11
|
+
import { index, integer, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
12
|
+
/** Include these tables in a Database Definition and apply its migrations. */
|
|
13
|
+
const workspaceHistorySchema = {
|
|
14
|
+
workspaceHistoryWorkspaces: sqliteTable("workspace_history_workspaces", {
|
|
15
|
+
workspace: text("workspace").primaryKey(),
|
|
16
|
+
deleted: integer("deleted", { mode: "boolean" }).notNull().default(false)
|
|
17
|
+
}),
|
|
18
|
+
workspaceHistoryRefs: sqliteTable("workspace_history_refs", {
|
|
19
|
+
workspace: text("workspace").notNull(),
|
|
20
|
+
ref: text("ref").notNull(),
|
|
21
|
+
head: text("head"),
|
|
22
|
+
sequence: integer("sequence").notNull().default(0)
|
|
23
|
+
}, (table) => [primaryKey({ columns: [table.workspace, table.ref] })]),
|
|
24
|
+
workspaceHistoryRevisions: sqliteTable("workspace_history_revisions", {
|
|
25
|
+
workspace: text("workspace").notNull(),
|
|
26
|
+
id: text("id").notNull(),
|
|
27
|
+
ref: text("ref").notNull(),
|
|
28
|
+
parentId: text("parent_id"),
|
|
29
|
+
sequence: integer("sequence").notNull(),
|
|
30
|
+
createdAt: text("created_at").notNull(),
|
|
31
|
+
message: text("message"),
|
|
32
|
+
metadata: text("metadata", { mode: "json" }).$type(),
|
|
33
|
+
files: integer("files").notNull(),
|
|
34
|
+
bytes: integer("bytes").notNull(),
|
|
35
|
+
entries: text("entries", { mode: "json" }).$type().notNull(),
|
|
36
|
+
committed: integer("committed", { mode: "boolean" }).notNull().default(false)
|
|
37
|
+
}, (table) => [primaryKey({ columns: [table.workspace, table.id] }), index("workspace_history_timeline").on(table.workspace, table.ref, table.committed, table.sequence)]),
|
|
38
|
+
workspaceHistoryObjects: sqliteTable("workspace_history_objects", {
|
|
39
|
+
workspace: text("workspace").notNull(),
|
|
40
|
+
digest: text("digest").notNull(),
|
|
41
|
+
size: integer("size").notNull()
|
|
42
|
+
}, (table) => [primaryKey({ columns: [table.workspace, table.digest] })]),
|
|
43
|
+
workspaceHistoryMetadata: sqliteTable("workspace_history_metadata", {
|
|
44
|
+
workspace: text("workspace").notNull(),
|
|
45
|
+
key: text("key").notNull(),
|
|
46
|
+
value: text("value", { mode: "json" }).$type().notNull()
|
|
47
|
+
}, (table) => [primaryKey({ columns: [table.workspace, table.key] })])
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/storage/blob-database.ts
|
|
51
|
+
const { workspaceHistoryWorkspaces: workspaces, workspaceHistoryRefs: refs, workspaceHistoryRevisions: revisions, workspaceHistoryObjects: objects, workspaceHistoryMetadata: metadata } = workspaceHistorySchema;
|
|
52
|
+
function publicRevision(row) {
|
|
53
|
+
const revision = {
|
|
54
|
+
id: row.id,
|
|
55
|
+
ref: row.ref,
|
|
56
|
+
parentId: row.parentId,
|
|
57
|
+
createdAt: row.createdAt,
|
|
58
|
+
files: row.files,
|
|
59
|
+
bytes: row.bytes
|
|
60
|
+
};
|
|
61
|
+
if (row.message !== null) revision.message = row.message;
|
|
62
|
+
if (row.metadata !== null) revision.metadata = structuredClone(row.metadata);
|
|
63
|
+
return revision;
|
|
64
|
+
}
|
|
65
|
+
var ContentAddressedWorkspaceStore = class {
|
|
66
|
+
options;
|
|
67
|
+
#namespace;
|
|
68
|
+
#ready;
|
|
69
|
+
#draft;
|
|
70
|
+
#dirty = false;
|
|
71
|
+
#baseline;
|
|
72
|
+
#queue = Promise.resolve();
|
|
73
|
+
constructor(options) {
|
|
74
|
+
this.options = options;
|
|
75
|
+
if (!hasRuntimeType(options.workspace, "string") || !options.workspace) throw workspaceError("[vitehub] Blob + Database Store requires a workspace identity.");
|
|
76
|
+
if (options.prefix !== void 0 && !/^[a-zA-Z0-9_-]+(?:\/[a-zA-Z0-9_-]+)*$/.test(options.prefix)) throw workspaceError("[vitehub] History Blob prefix must contain only letters, numbers, underscores, dashes, and single slashes.");
|
|
77
|
+
const root = `${vitehubOwnedPrefix}workspace-history`;
|
|
78
|
+
const prefix = options.prefix === void 0 ? root : `${root}/${options.prefix}`;
|
|
79
|
+
const legacyPrefix = options.prefix === void 0 ? "vitehub/workspace-history" : options.prefix;
|
|
80
|
+
this.#namespace = sha256(options.workspace).then((digest) => {
|
|
81
|
+
const current = `${prefix}/${digest}`;
|
|
82
|
+
const legacy = `${legacyPrefix}/${digest}`;
|
|
83
|
+
return legacy === current ? [current] : [current, legacy];
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
[workspaceStoreTarget]() {
|
|
87
|
+
return {
|
|
88
|
+
provider: "blob-database",
|
|
89
|
+
workspace: this.options.workspace,
|
|
90
|
+
database: this.options.database
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
history = {
|
|
94
|
+
head: async (options) => await this.#head(normalizeHistoryRef(options?.ref)),
|
|
95
|
+
list: async (options) => await this.#listHistory(options),
|
|
96
|
+
refs: async () => await this.#refs(),
|
|
97
|
+
open: async (id) => await this.#open(id),
|
|
98
|
+
usage: async () => {
|
|
99
|
+
const workspace = await this.#key();
|
|
100
|
+
const [result] = await this.options.database.values(sql`
|
|
101
|
+
select coalesce(sum(size), 0) as bytes, count(*) as objects from (
|
|
102
|
+
select distinct json_extract(file.value, '$.digest') as digest,
|
|
103
|
+
json_extract(file.value, '$.size') as size
|
|
104
|
+
from ${revisions}, json_each(${revisions.entries}) as file
|
|
105
|
+
where ${revisions.workspace} = ${workspace} and ${revisions.committed} = 1
|
|
106
|
+
and ${this.#active(workspace)}
|
|
107
|
+
)
|
|
108
|
+
`);
|
|
109
|
+
return {
|
|
110
|
+
bytes: result?.[0] ?? 0,
|
|
111
|
+
objects: result?.[1] ?? 0
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
commit: async (options) => await this.#mutate(async () => {
|
|
115
|
+
const revision = await this.#commit(options);
|
|
116
|
+
if (revision.ref === "main") {
|
|
117
|
+
this.#draft = void 0;
|
|
118
|
+
this.#dirty = false;
|
|
119
|
+
this.#baseline = void 0;
|
|
120
|
+
}
|
|
121
|
+
return revision;
|
|
122
|
+
})
|
|
123
|
+
};
|
|
124
|
+
async #key() {
|
|
125
|
+
const candidates = await this.#namespace;
|
|
126
|
+
this.#ready ??= this.options.database.batch([
|
|
127
|
+
this.options.database.select({ workspace: workspaces.workspace }).from(workspaces).where(eq(workspaces.workspace, candidates[0])),
|
|
128
|
+
this.options.database.select({ workspace: workspaces.workspace }).from(workspaces).where(eq(workspaces.workspace, candidates[1] ?? candidates[0])),
|
|
129
|
+
this.options.database.insert(workspaces).select(sql`
|
|
130
|
+
select ${candidates[0]}, 0
|
|
131
|
+
where not exists (
|
|
132
|
+
select 1 from ${workspaces} where ${workspaces.workspace} = ${candidates[1] ?? candidates[0]}
|
|
133
|
+
)
|
|
134
|
+
`).onConflictDoNothing()
|
|
135
|
+
]).then((results) => {
|
|
136
|
+
const [current, legacy] = results;
|
|
137
|
+
return current[0]?.workspace ?? legacy[0]?.workspace ?? candidates[0];
|
|
138
|
+
}).catch((error) => {
|
|
139
|
+
this.#ready = void 0;
|
|
140
|
+
throw error;
|
|
141
|
+
});
|
|
142
|
+
return await this.#ready;
|
|
143
|
+
}
|
|
144
|
+
#active(workspace) {
|
|
145
|
+
return sql`exists (select 1 from ${workspaces} where ${workspaces.workspace} = ${workspace} and ${workspaces.deleted} = 0)`;
|
|
146
|
+
}
|
|
147
|
+
async #isDeleted() {
|
|
148
|
+
const workspace = await this.#key();
|
|
149
|
+
const [row] = await this.options.database.select({ deleted: workspaces.deleted }).from(workspaces).where(eq(workspaces.workspace, workspace));
|
|
150
|
+
if (!row) throw workspaceError("[vitehub] Workspace history identity is missing.");
|
|
151
|
+
return row.deleted;
|
|
152
|
+
}
|
|
153
|
+
async #ref(workspace, ref) {
|
|
154
|
+
const [row] = await this.options.database.select().from(refs).where(and(eq(refs.workspace, workspace), eq(refs.ref, ref), this.#active(workspace)));
|
|
155
|
+
return row;
|
|
156
|
+
}
|
|
157
|
+
async #head(ref) {
|
|
158
|
+
const workspace = await this.#key();
|
|
159
|
+
const row = await this.#ref(workspace, ref);
|
|
160
|
+
return row?.head ? publicRevision(await this.#revision(row.head)) : null;
|
|
161
|
+
}
|
|
162
|
+
async #refs() {
|
|
163
|
+
const workspace = await this.#key();
|
|
164
|
+
const heads = await this.options.database.select({
|
|
165
|
+
ref: refs.ref,
|
|
166
|
+
head: refs.head
|
|
167
|
+
}).from(refs).where(and(eq(refs.workspace, workspace), isNotNull(refs.head), this.#active(workspace)));
|
|
168
|
+
if (!heads.length) return [];
|
|
169
|
+
const rows = await this.options.database.select().from(revisions).where(and(eq(revisions.workspace, workspace), eq(revisions.committed, true), inArray(revisions.id, heads.map((row) => row.head)), this.#active(workspace)));
|
|
170
|
+
const byId = new Map(rows.map((row) => [row.id, row]));
|
|
171
|
+
return heads.flatMap(({ ref, head }) => {
|
|
172
|
+
const row = byId.get(head);
|
|
173
|
+
return row ? [{
|
|
174
|
+
name: ref,
|
|
175
|
+
head: publicRevision(row)
|
|
176
|
+
}] : [];
|
|
177
|
+
}).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
178
|
+
}
|
|
179
|
+
#deleted() {
|
|
180
|
+
throw new ViteHubError("WORKSPACE_NOT_FOUND", "[vitehub] This Workspace has been deleted. Use a new workspace identity.", { details: { workspace: this.options.workspace } });
|
|
181
|
+
}
|
|
182
|
+
async #assertActive() {
|
|
183
|
+
if (await this.#isDeleted()) this.#deleted();
|
|
184
|
+
}
|
|
185
|
+
async #revision(id) {
|
|
186
|
+
const workspace = await this.#key();
|
|
187
|
+
const [row] = await this.options.database.select().from(revisions).where(and(eq(revisions.workspace, workspace), eq(revisions.id, id), eq(revisions.committed, true), this.#active(workspace)));
|
|
188
|
+
if (!row) throw new ViteHubError("WORKSPACE_NOT_FOUND", `[vitehub] Workspace revision does not exist: ${id}.`);
|
|
189
|
+
return row;
|
|
190
|
+
}
|
|
191
|
+
async #listHistory(options = {}) {
|
|
192
|
+
const limit = options.limit ?? 20;
|
|
193
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw workspaceErrorDiagnostics.WORKSPACE_R0070({ message: "[vitehub] History list limit must be an integer from 1 to 100." });
|
|
194
|
+
const ref = normalizeHistoryRef(options.ref);
|
|
195
|
+
const path = options.path === void 0 ? void 0 : normalizeHistoryPath(options.path);
|
|
196
|
+
const workspace = await this.#key();
|
|
197
|
+
const cursor = options.cursor ? await this.#revision(options.cursor) : void 0;
|
|
198
|
+
if (cursor && cursor.ref !== ref) throw workspaceErrorDiagnostics.WORKSPACE_R0070({ message: `[vitehub] History cursor belongs to ref "${cursor.ref}". Pass it with the ref that returned it.` });
|
|
199
|
+
const previousEntries = sql`
|
|
200
|
+
coalesce((
|
|
201
|
+
select previous.entries
|
|
202
|
+
from ${revisions} as previous
|
|
203
|
+
where previous.workspace = ${revisions.workspace}
|
|
204
|
+
and previous.id = ${revisions.parentId}
|
|
205
|
+
and previous.committed = 1
|
|
206
|
+
), '{}')
|
|
207
|
+
`;
|
|
208
|
+
const pathFilter = path === void 0 ? void 0 : sql`(
|
|
209
|
+
exists (
|
|
210
|
+
select 1
|
|
211
|
+
from json_each(${revisions.entries}) as current_file
|
|
212
|
+
left join json_each(${previousEntries}) as previous_file
|
|
213
|
+
on previous_file.key = current_file.key
|
|
214
|
+
where (current_file.key = ${path} or substr(current_file.key, 1, length(${path}) + 1) = ${path} || '/')
|
|
215
|
+
and (
|
|
216
|
+
previous_file.key is null
|
|
217
|
+
or json_extract(current_file.value, '$.digest') is not json_extract(previous_file.value, '$.digest')
|
|
218
|
+
or json_extract(current_file.value, '$.size') is not json_extract(previous_file.value, '$.size')
|
|
219
|
+
or json_extract(current_file.value, '$.mediaType') is not json_extract(previous_file.value, '$.mediaType')
|
|
220
|
+
or json_extract(current_file.value, '$.metadata') is not json_extract(previous_file.value, '$.metadata')
|
|
221
|
+
)
|
|
222
|
+
)
|
|
223
|
+
or exists (
|
|
224
|
+
select 1
|
|
225
|
+
from json_each(${previousEntries}) as previous_file
|
|
226
|
+
left join json_each(${revisions.entries}) as current_file
|
|
227
|
+
on current_file.key = previous_file.key
|
|
228
|
+
where (previous_file.key = ${path} or substr(previous_file.key, 1, length(${path}) + 1) = ${path} || '/')
|
|
229
|
+
and current_file.key is null
|
|
230
|
+
)
|
|
231
|
+
)`;
|
|
232
|
+
const rows = await this.options.database.select().from(revisions).where(and(eq(revisions.workspace, workspace), eq(revisions.ref, ref), eq(revisions.committed, true), cursor ? lt(revisions.sequence, cursor.sequence) : void 0, pathFilter, this.#active(workspace))).orderBy(desc(revisions.sequence)).limit(limit + 1);
|
|
233
|
+
const result = { revisions: rows.slice(0, limit).map(publicRevision) };
|
|
234
|
+
if (rows.length > limit) result.cursor = rows[limit - 1].id;
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
async #open(id) {
|
|
238
|
+
const row = await this.#revision(id);
|
|
239
|
+
const workspace = await this.#key();
|
|
240
|
+
const entries = /* @__PURE__ */ new Map();
|
|
241
|
+
for (const [path, file] of Object.entries(row.entries)) {
|
|
242
|
+
entries.set(path, {
|
|
243
|
+
path,
|
|
244
|
+
type: "file",
|
|
245
|
+
digest: file.digest,
|
|
246
|
+
size: file.size,
|
|
247
|
+
mediaType: file.mediaType,
|
|
248
|
+
metadata: structuredClone(file.metadata),
|
|
249
|
+
revision: id
|
|
250
|
+
});
|
|
251
|
+
const parts = path.split("/");
|
|
252
|
+
for (let index = 1; index < parts.length; index++) {
|
|
253
|
+
const directory = parts.slice(0, index).join("/");
|
|
254
|
+
entries.set(directory, {
|
|
255
|
+
path: directory,
|
|
256
|
+
type: "directory"
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
entries.set("", {
|
|
261
|
+
path: "",
|
|
262
|
+
type: "directory"
|
|
263
|
+
});
|
|
264
|
+
return Object.freeze({
|
|
265
|
+
revision: publicRevision(row),
|
|
266
|
+
list: async (path = "", options) => {
|
|
267
|
+
await this.#assertActive();
|
|
268
|
+
const normalized = normalizeSafeWorkspacePath(path, { allowEmpty: true }).split("/").filter(Boolean).join("/");
|
|
269
|
+
return [...entries.values()].filter((entry) => entry.path && entry.path !== normalized && (!normalized || entry.path.startsWith(`${normalized}/`)) && !isExcludedWorkspacePath(entry.path, options?.exclude) && (options?.recursive || !entry.path.slice(normalized ? normalized.length + 1 : 0).includes("/"))).sort((left, right) => left.path.localeCompare(right.path)).map((entry) => structuredClone(entry));
|
|
270
|
+
},
|
|
271
|
+
stat: async (path) => {
|
|
272
|
+
await this.#assertActive();
|
|
273
|
+
const normalized = path === "" ? "" : normalizeHistoryPath(path);
|
|
274
|
+
const entry = entries.get(normalized);
|
|
275
|
+
if (!entry) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
276
|
+
return structuredClone(entry);
|
|
277
|
+
},
|
|
278
|
+
readFile: async (path, options) => {
|
|
279
|
+
await this.#assertActive();
|
|
280
|
+
const normalized = normalizeHistoryPath(path);
|
|
281
|
+
const file = Object.hasOwn(row.entries, normalized) ? row.entries[normalized] : void 0;
|
|
282
|
+
if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
283
|
+
const [error, body] = await this.options.blob.get(`${workspace}/sha256/${file.digest}`);
|
|
284
|
+
if (error) throw error;
|
|
285
|
+
if (!body) throw workspaceError(`[vitehub] Retained history object is missing: ${file.digest}.`);
|
|
286
|
+
const bytes = new Uint8Array(await body.arrayBuffer());
|
|
287
|
+
if (bytes.byteLength !== file.size || await sha256(bytes) !== file.digest) throw workspaceError(`[vitehub] Retained history object failed its content hash check: ${file.digest}.`);
|
|
288
|
+
return decodeFile(bytes, options);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
async #commit(options) {
|
|
293
|
+
validateHistoryMessage(options.message);
|
|
294
|
+
const ref = normalizeHistoryRef(options.ref);
|
|
295
|
+
if (options.files === void 0 === (options.changes === void 0)) throw workspaceError("[vitehub] History commit requires exactly one of files or changes.");
|
|
296
|
+
const expectedHeads = Object.entries(options.ifHeads ?? {}).map(([name, head]) => {
|
|
297
|
+
if (head !== null && (!hasRuntimeType(head, "string") || !head)) throw workspaceError("[vitehub] History ifHeads values must be revision ids or null.");
|
|
298
|
+
return [normalizeHistoryRef(name), head];
|
|
299
|
+
});
|
|
300
|
+
const workspace = await this.#key();
|
|
301
|
+
await this.#assertActive();
|
|
302
|
+
const current = await this.#ref(workspace, ref);
|
|
303
|
+
if ((current?.head ?? null) !== options.ifHead) throw this.#conflict(ref, options.ifHead, current?.head ?? null);
|
|
304
|
+
const entries = Object.create(null);
|
|
305
|
+
const removed = /* @__PURE__ */ new Set();
|
|
306
|
+
if (options.changes && current?.head) Object.assign(entries, (await this.#revision(current.head)).entries);
|
|
307
|
+
for (const path of options.changes?.delete ?? []) {
|
|
308
|
+
const normalized = normalizeHistoryPath(path);
|
|
309
|
+
if (!Object.hasOwn(entries, normalized)) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
310
|
+
delete entries[normalized];
|
|
311
|
+
removed.add(normalized);
|
|
312
|
+
}
|
|
313
|
+
const puts = /* @__PURE__ */ new Set();
|
|
314
|
+
const contents = /* @__PURE__ */ new Map();
|
|
315
|
+
for (const [path, file] of Object.entries(options.files ?? options.changes?.put ?? {}).sort(([left], [right]) => left.localeCompare(right))) {
|
|
316
|
+
const normalized = normalizeHistoryPath(path);
|
|
317
|
+
if (puts.has(normalized) || removed.has(normalized)) throw workspaceError(`[vitehub] Duplicate history file path: ${normalized}.`);
|
|
318
|
+
puts.add(normalized);
|
|
319
|
+
if (!hasRuntimeType(file.content, "string") && !isWorkspaceBytes(file.content)) throw workspaceError(`[vitehub] Invalid history file content: ${normalized}.`);
|
|
320
|
+
const bytes = new Uint8Array(contentToBytes(file.content));
|
|
321
|
+
const digest = await sha256(bytes);
|
|
322
|
+
const entry = {
|
|
323
|
+
digest,
|
|
324
|
+
size: bytes.byteLength,
|
|
325
|
+
mediaType: file.mediaType || "application/octet-stream"
|
|
326
|
+
};
|
|
327
|
+
if (file.metadata !== void 0) entry.metadata = copyJsonFileMetadata(normalized, file.metadata);
|
|
328
|
+
entries[normalized] = entry;
|
|
329
|
+
contents.set(digest, bytes);
|
|
330
|
+
}
|
|
331
|
+
for (const path of Object.keys(entries)) {
|
|
332
|
+
const parts = path.split("/");
|
|
333
|
+
for (let index = 1; index < parts.length; index++) if (Object.hasOwn(entries, parts.slice(0, index).join("/"))) throw workspaceError(`[vitehub] History path is both a file and a directory: ${path}.`);
|
|
334
|
+
}
|
|
335
|
+
const sorted = Object.create(null);
|
|
336
|
+
for (const path of Object.keys(entries).sort((left, right) => left.localeCompare(right))) sorted[path] = entries[path];
|
|
337
|
+
const manifest = {
|
|
338
|
+
ref,
|
|
339
|
+
parentId: options.ifHead,
|
|
340
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
341
|
+
message: options.message ?? null,
|
|
342
|
+
metadata: copyJsonWorkspaceMetadata("history revision", options.metadata) ?? null,
|
|
343
|
+
entries: sorted
|
|
344
|
+
};
|
|
345
|
+
const id = await sha256(manifest);
|
|
346
|
+
const registry = [...contents].map(([digest, bytes]) => ({
|
|
347
|
+
digest,
|
|
348
|
+
size: bytes.byteLength
|
|
349
|
+
}));
|
|
350
|
+
await this.options.database.insert(objects).select(sql`
|
|
351
|
+
select ${workspaces.workspace}, json_extract(object.value, '$.digest'), json_extract(object.value, '$.size')
|
|
352
|
+
from ${workspaces}, json_each(${JSON.stringify(registry)}) as object
|
|
353
|
+
where ${workspaces.workspace} = ${workspace} and ${workspaces.deleted} = 0
|
|
354
|
+
`).onConflictDoNothing();
|
|
355
|
+
await this.#assertActive();
|
|
356
|
+
const upload = async ([digest, bytes]) => {
|
|
357
|
+
const key = `${workspace}/sha256/${digest}`;
|
|
358
|
+
const [headError, object] = await this.options.blob.head(key);
|
|
359
|
+
if (headError && headError.code !== "BLOB_NOT_FOUND") throw headError;
|
|
360
|
+
if (!object) {
|
|
361
|
+
const [uploadError] = await this.options.blob.put(key, bytes, {
|
|
362
|
+
addRandomSuffix: false,
|
|
363
|
+
contentType: "application/octet-stream"
|
|
364
|
+
});
|
|
365
|
+
if (uploadError) {
|
|
366
|
+
const [concurrentError, concurrentObject] = await this.options.blob.head(key);
|
|
367
|
+
if (concurrentError || !concurrentObject) throw uploadError;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (await this.#isDeleted()) {
|
|
371
|
+
await this.#removeObject(key);
|
|
372
|
+
this.#deleted();
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
const uploads = [...contents];
|
|
376
|
+
for (let offset = 0; offset < uploads.length; offset += 8) {
|
|
377
|
+
const results = await Promise.allSettled(uploads.slice(offset, offset + 8).map(upload));
|
|
378
|
+
for (const result of results) if (result.status === "rejected") throw result.reason;
|
|
379
|
+
}
|
|
380
|
+
const row = {
|
|
381
|
+
...manifest,
|
|
382
|
+
entries: { ...sorted },
|
|
383
|
+
workspace,
|
|
384
|
+
id,
|
|
385
|
+
sequence: (current?.sequence ?? 0) + 1,
|
|
386
|
+
files: Object.keys(sorted).length,
|
|
387
|
+
bytes: Object.values(sorted).reduce((total, entry) => total + entry.size, 0)
|
|
388
|
+
};
|
|
389
|
+
expectedHeads.map(([name, head]) => sql`(select expected.head from ${refs} as expected where expected.workspace = ${workspace} and expected.ref = ${name}) is ${head}`);
|
|
390
|
+
const [, , changed] = await this.options.database.batch([
|
|
391
|
+
this.options.database.insert(refs).select(sql`
|
|
392
|
+
select ${workspaces.workspace}, ${ref}, null, 0
|
|
393
|
+
from ${workspaces} where ${workspaces.workspace} = ${workspace} and ${workspaces.deleted} = 0
|
|
394
|
+
`).onConflictDoNothing(),
|
|
395
|
+
this.options.database.insert(revisions).select(sql`
|
|
396
|
+
select ${row.workspace}, ${row.id}, ${row.ref}, ${row.parentId}, ${row.sequence}, ${row.createdAt},
|
|
397
|
+
${row.message}, ${row.metadata === null ? null : JSON.stringify(row.metadata)},
|
|
398
|
+
${row.files}, ${row.bytes}, ${JSON.stringify(row.entries)}, 0
|
|
399
|
+
from ${workspaces} where ${workspaces.workspace} = ${workspace} and ${workspaces.deleted} = 0
|
|
400
|
+
`).onConflictDoNothing(),
|
|
401
|
+
this.options.database.update(refs).set({
|
|
402
|
+
head: id,
|
|
403
|
+
sequence: sql`${refs.sequence} + 1`
|
|
404
|
+
}).where(and(eq(refs.workspace, workspace), eq(refs.ref, ref), sql`${refs.head} is ${options.ifHead}`, ...Object.entries(options.ifHeads ?? {}).map(([expectedRef, expectedHead]) => expectedHead === null ? sql`(not exists (select 1 from ${refs} as cross_ref where cross_ref.workspace = ${workspace} and cross_ref.ref = ${expectedRef}) or exists (select 1 from ${refs} as cross_ref where cross_ref.workspace = ${workspace} and cross_ref.ref = ${expectedRef} and cross_ref.head is null))` : sql`exists (select 1 from ${refs} as cross_ref where cross_ref.workspace = ${workspace} and cross_ref.ref = ${expectedRef} and cross_ref.head is ${expectedHead})`), this.#active(workspace))).returning({ head: refs.head }),
|
|
405
|
+
this.options.database.update(revisions).set({ committed: true }).where(and(eq(revisions.workspace, workspace), eq(revisions.id, id), sql`exists (select 1 from ${refs} where ${refs.workspace} = ${workspace} and ${refs.ref} = ${ref} and ${refs.head} = ${id})`, this.#active(workspace)))
|
|
406
|
+
]);
|
|
407
|
+
if (!changed.length) {
|
|
408
|
+
if (await this.#isDeleted()) this.#deleted();
|
|
409
|
+
for (const [name, expected] of expectedHeads) {
|
|
410
|
+
const actual = (await this.#ref(workspace, name))?.head ?? null;
|
|
411
|
+
if (actual !== expected) throw this.#conflict(name, expected, actual);
|
|
412
|
+
}
|
|
413
|
+
throw this.#conflict(ref, options.ifHead, (await this.#ref(workspace, ref))?.head ?? null);
|
|
414
|
+
}
|
|
415
|
+
return publicRevision({
|
|
416
|
+
...row,
|
|
417
|
+
committed: true
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
#conflict(ref, expected, actual) {
|
|
421
|
+
return historyConflict(ref, expected, actual, { workspace: this.options.workspace });
|
|
422
|
+
}
|
|
423
|
+
async #removeObject(key) {
|
|
424
|
+
const [headError, object] = await this.options.blob.head(key);
|
|
425
|
+
if (headError?.code === "BLOB_NOT_FOUND") return;
|
|
426
|
+
if (headError) throw headError;
|
|
427
|
+
if (!object) return;
|
|
428
|
+
const [error] = await this.options.blob.del(key);
|
|
429
|
+
if (error && error.code !== "BLOB_NOT_FOUND") throw error;
|
|
430
|
+
}
|
|
431
|
+
async delete() {
|
|
432
|
+
await this.#mutate(() => this.#delete());
|
|
433
|
+
}
|
|
434
|
+
async #delete() {
|
|
435
|
+
const workspace = await this.#key();
|
|
436
|
+
await this.options.database.batch([this.options.database.update(workspaces).set({ deleted: true }).where(eq(workspaces.workspace, workspace)), this.options.database.delete(refs).where(eq(refs.workspace, workspace))]);
|
|
437
|
+
const catalog = await this.options.database.select().from(objects).where(eq(objects.workspace, workspace));
|
|
438
|
+
for (const object of catalog) await this.#removeObject(`${workspace}/sha256/${object.digest}`);
|
|
439
|
+
let cursor;
|
|
440
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
441
|
+
const remaining = [];
|
|
442
|
+
do {
|
|
443
|
+
const [error, page] = await this.options.blob.list({
|
|
444
|
+
prefix: `${workspace}/sha256/`,
|
|
445
|
+
cursor,
|
|
446
|
+
limit: 1e3
|
|
447
|
+
});
|
|
448
|
+
if (error) throw error;
|
|
449
|
+
remaining.push(...page.blobs.map((object) => object.pathname));
|
|
450
|
+
cursor = page.hasMore ? page.cursor : void 0;
|
|
451
|
+
if (page.hasMore && (!cursor || cursors.has(cursor))) throw workspaceError("[vitehub] History cleanup received an invalid Blob cursor.");
|
|
452
|
+
if (cursor) cursors.add(cursor);
|
|
453
|
+
} while (cursor);
|
|
454
|
+
for (let offset = 0; offset < remaining.length; offset += 1e3) {
|
|
455
|
+
const [error] = await this.options.blob.del(remaining.slice(offset, offset + 1e3));
|
|
456
|
+
if (error) throw error;
|
|
457
|
+
}
|
|
458
|
+
await this.options.database.batch([
|
|
459
|
+
this.options.database.delete(revisions).where(eq(revisions.workspace, workspace)),
|
|
460
|
+
this.options.database.delete(objects).where(eq(objects.workspace, workspace)),
|
|
461
|
+
this.options.database.delete(metadata).where(eq(metadata.workspace, workspace))
|
|
462
|
+
]);
|
|
463
|
+
this.#draft = void 0;
|
|
464
|
+
this.#dirty = false;
|
|
465
|
+
}
|
|
466
|
+
async #loadDraft() {
|
|
467
|
+
await this.#assertActive();
|
|
468
|
+
const head = await this.history.head();
|
|
469
|
+
if (this.#draft && !this.#dirty && (await this.#draft).head?.id !== head?.id) this.#draft = void 0;
|
|
470
|
+
this.#draft ??= (async () => {
|
|
471
|
+
const store = createMemoryWorkspaceStore();
|
|
472
|
+
if (head) {
|
|
473
|
+
const view = await this.history.open(head.id);
|
|
474
|
+
for (const entry of await view.list("", { recursive: true })) if (entry.type === "file") await store.writeFile(entry.path, {
|
|
475
|
+
path: entry.path,
|
|
476
|
+
content: await view.readFile(entry.path, { encoding: "binary" }),
|
|
477
|
+
mediaType: entry.mediaType,
|
|
478
|
+
metadata: entry.metadata
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
await store.snapshot();
|
|
482
|
+
return {
|
|
483
|
+
store,
|
|
484
|
+
head
|
|
485
|
+
};
|
|
486
|
+
})().catch((error) => {
|
|
487
|
+
this.#draft = void 0;
|
|
488
|
+
throw error;
|
|
489
|
+
});
|
|
490
|
+
return await this.#draft;
|
|
491
|
+
}
|
|
492
|
+
#mutate(operation) {
|
|
493
|
+
const pending = this.#queue.then(operation);
|
|
494
|
+
this.#queue = pending.then(() => {}, () => {});
|
|
495
|
+
return pending;
|
|
496
|
+
}
|
|
497
|
+
async #write(operation) {
|
|
498
|
+
await this.#mutate(async () => {
|
|
499
|
+
const draft = await this.#loadDraft();
|
|
500
|
+
const candidate = forkMemoryWorkspaceStore(draft.store);
|
|
501
|
+
const dirty = this.#dirty;
|
|
502
|
+
this.#dirty = true;
|
|
503
|
+
try {
|
|
504
|
+
await operation(candidate);
|
|
505
|
+
await this.#assertActive();
|
|
506
|
+
this.#draft = Promise.resolve({
|
|
507
|
+
store: candidate,
|
|
508
|
+
head: draft.head
|
|
509
|
+
});
|
|
510
|
+
} catch (error) {
|
|
511
|
+
this.#dirty = dirty;
|
|
512
|
+
throw error;
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
async readFile(path) {
|
|
517
|
+
return await (await this.#loadDraft()).store.readFile(normalizeSafeWorkspacePath(path, { allowEmpty: true }));
|
|
518
|
+
}
|
|
519
|
+
async list(path = "", options) {
|
|
520
|
+
return await (await this.#loadDraft()).store.list(path, options);
|
|
521
|
+
}
|
|
522
|
+
async glob(pattern, options) {
|
|
523
|
+
return await (await this.#loadDraft()).store.glob(pattern, options);
|
|
524
|
+
}
|
|
525
|
+
async stat(path) {
|
|
526
|
+
return await (await this.#loadDraft()).store.stat(normalizeSafeWorkspacePath(path, { allowEmpty: true }));
|
|
527
|
+
}
|
|
528
|
+
async writeFile(path, file) {
|
|
529
|
+
await this.#write((store) => store.writeFile(normalizeHistoryPath(path), file));
|
|
530
|
+
}
|
|
531
|
+
async writeFileConditional(path, file, ifDigest) {
|
|
532
|
+
await this.#write((store) => store.writeFileConditional(normalizeHistoryPath(path), file, ifDigest));
|
|
533
|
+
}
|
|
534
|
+
async mkdir(path, options) {
|
|
535
|
+
await this.#write((store) => store.mkdir(normalizeHistoryPath(path), options));
|
|
536
|
+
}
|
|
537
|
+
async rm(path, options) {
|
|
538
|
+
await this.#write((store) => store.rm(normalizeHistoryPath(path), options));
|
|
539
|
+
}
|
|
540
|
+
async removeEmptyDirectory(path) {
|
|
541
|
+
await this.#write((store) => store.removeEmptyDirectory(normalizeHistoryPath(path)));
|
|
542
|
+
}
|
|
543
|
+
async snapshot(options = {}) {
|
|
544
|
+
return await this.#mutate(async () => {
|
|
545
|
+
const draft = await this.#loadDraft();
|
|
546
|
+
const files = Object.create(null);
|
|
547
|
+
for (const entry of await draft.store.list("", { recursive: true })) if (entry.type === "file") files[entry.path] = await draft.store.readFile(entry.path);
|
|
548
|
+
const revision = await this.#commit({
|
|
549
|
+
ifHead: draft.head?.id ?? null,
|
|
550
|
+
files,
|
|
551
|
+
message: options.name
|
|
552
|
+
});
|
|
553
|
+
this.#dirty = false;
|
|
554
|
+
this.#draft = void 0;
|
|
555
|
+
this.#baseline = void 0;
|
|
556
|
+
const view = await this.#open(revision.id);
|
|
557
|
+
const snapshot = await createSnapshotFromEntries(await view.list("", { recursive: true }), options.name);
|
|
558
|
+
this.#baseline = {
|
|
559
|
+
...snapshot,
|
|
560
|
+
id: revision.id,
|
|
561
|
+
createdAt: revision.createdAt
|
|
562
|
+
};
|
|
563
|
+
return this.#baseline;
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
async diff(options = {}) {
|
|
567
|
+
const draft = await this.#loadDraft();
|
|
568
|
+
const baseline = options.from ?? this.#baseline ?? (draft.head ? {
|
|
569
|
+
...await createSnapshotFromEntries(await (await this.#open(draft.head.id)).list("", { recursive: true })),
|
|
570
|
+
id: draft.head.id
|
|
571
|
+
} : void 0);
|
|
572
|
+
return diffSnapshots(baseline, await createSnapshotFromEntries(await draft.store.list("", { recursive: true })));
|
|
573
|
+
}
|
|
574
|
+
async getMeta(key) {
|
|
575
|
+
const workspace = await this.#key();
|
|
576
|
+
const [row] = await this.options.database.select().from(metadata).where(and(eq(metadata.workspace, workspace), eq(metadata.key, key), this.#active(workspace)));
|
|
577
|
+
return row?.value;
|
|
578
|
+
}
|
|
579
|
+
async setMeta(key, value) {
|
|
580
|
+
await this.#assertActive();
|
|
581
|
+
const workspace = await this.#key();
|
|
582
|
+
if (value === void 0) {
|
|
583
|
+
await this.options.database.delete(metadata).where(and(eq(metadata.workspace, workspace), eq(metadata.key, key)));
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
await this.options.database.insert(metadata).select(this.options.database.select({
|
|
587
|
+
workspace: sql`${workspace}`.as("workspace"),
|
|
588
|
+
key: sql`${key}`.as("key"),
|
|
589
|
+
value: sql`${JSON.stringify(value)}`.as("value")
|
|
590
|
+
}).from(workspaces).where(and(eq(workspaces.workspace, workspace), eq(workspaces.deleted, false)))).onConflictDoUpdate({
|
|
591
|
+
target: [metadata.workspace, metadata.key],
|
|
592
|
+
set: { value: sql`${JSON.stringify(value)}` }
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
/** Blob stores bytes; Database atomically publishes immutable folder manifests. */
|
|
597
|
+
function createBlobDatabaseWorkspaceStore(options) {
|
|
598
|
+
return new ContentAddressedWorkspaceStore(options);
|
|
599
|
+
}
|
|
600
|
+
//#endregion
|
|
601
|
+
export { createBlobDatabaseWorkspaceStore, workspaceHistorySchema };
|
package/dist/cloudflare.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bn as WorkspaceStore, s as GitHubWorkspaceStoreOptions, t as CloudflareArtifactsWorkspaceStoreOptions, v as ResolvedWorkspaceModuleOptions } from "./types-DeK9GIxy.js";
|
|
2
2
|
import { configureHostedWorkspaceRuntime } from "./hosted.js";
|
|
3
|
-
|
|
4
3
|
//#region src/providers/cloudflare/artifacts-store.d.ts
|
|
5
|
-
declare function createCloudflareArtifactsWorkspaceStore(options: CloudflareArtifactsWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
|
|
4
|
+
export declare function createCloudflareArtifactsWorkspaceStore(options: CloudflareArtifactsWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
|
|
6
5
|
//#endregion
|
|
7
6
|
//#region src/cloudflare.d.ts
|
|
8
|
-
type CloudflareWorkspaceRuntimeStoreOptions = Partial<CloudflareArtifactsWorkspaceStoreOptions> | (Partial<GitHubWorkspaceStoreOptions> & {
|
|
7
|
+
export type CloudflareWorkspaceRuntimeStoreOptions = Partial<CloudflareArtifactsWorkspaceStoreOptions> | (Partial<GitHubWorkspaceStoreOptions> & {
|
|
9
8
|
provider: "github";
|
|
10
9
|
});
|
|
11
|
-
interface CloudflareWorkspaceRuntimeOptions {
|
|
10
|
+
export interface CloudflareWorkspaceRuntimeOptions {
|
|
12
11
|
assets?: boolean | string[];
|
|
13
12
|
env?: Record<string, string | undefined>;
|
|
14
13
|
root?: string;
|
|
15
14
|
store?: CloudflareWorkspaceRuntimeStoreOptions;
|
|
16
15
|
}
|
|
17
16
|
//#endregion
|
|
18
|
-
export { type CloudflareArtifactsWorkspaceStoreOptions,
|
|
17
|
+
export { type CloudflareArtifactsWorkspaceStoreOptions, type GitHubWorkspaceStoreOptions, type ResolvedWorkspaceModuleOptions, configureHostedWorkspaceRuntime as configureCloudflareWorkspaceRuntime };
|
package/dist/cloudflare.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { r as createCloudflareArtifactsWorkspaceStore, t as configureHostedWorkspaceRuntime } from "./hosted-
|
|
1
|
+
import { r as createCloudflareArtifactsWorkspaceStore, t as configureHostedWorkspaceRuntime } from "./hosted-acMA5XyL.js";
|
|
2
2
|
export { configureHostedWorkspaceRuntime as configureCloudflareWorkspaceRuntime, createCloudflareArtifactsWorkspaceStore };
|