@feltdb/feltkit 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +22 -2
- package/bin/feltkit.js +3 -0
- package/dist/app.d.ts +151 -0
- package/dist/app.js +130 -0
- package/dist/app.js.map +1 -0
- package/dist/cli/deploy.d.ts +8 -0
- package/dist/cli/deploy.js +125 -0
- package/dist/cli/deploy.js.map +1 -0
- package/dist/cli/main.d.ts +9 -0
- package/dist/cli/main.js +365 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/output.d.ts +18 -0
- package/dist/cli/output.js +87 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/client/index.d.ts +125 -0
- package/dist/client/index.js +306 -0
- package/dist/client/index.js.map +1 -0
- package/dist/dashboard/assets/index-BLnBFDJs.css +1 -0
- package/dist/dashboard/assets/index-CxJGCspE.js +15 -0
- package/dist/dashboard/index.html +16 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +54 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +40 -0
- package/dist/react/index.js +85 -0
- package/dist/react/index.js.map +1 -0
- package/dist/runtime/activity.d.ts +97 -0
- package/dist/runtime/activity.js +99 -0
- package/dist/runtime/activity.js.map +1 -0
- package/dist/runtime/authority.d.ts +78 -0
- package/dist/runtime/authority.js +176 -0
- package/dist/runtime/authority.js.map +1 -0
- package/dist/runtime/changes.d.ts +34 -0
- package/dist/runtime/changes.js +85 -0
- package/dist/runtime/changes.js.map +1 -0
- package/dist/runtime/context.d.ts +51 -0
- package/dist/runtime/context.js +2 -0
- package/dist/runtime/context.js.map +1 -0
- package/dist/runtime/data.d.ts +139 -0
- package/dist/runtime/data.js +374 -0
- package/dist/runtime/data.js.map +1 -0
- package/dist/runtime/environment.d.ts +36 -0
- package/dist/runtime/environment.js +62 -0
- package/dist/runtime/environment.js.map +1 -0
- package/dist/runtime/instance.d.ts +77 -0
- package/dist/runtime/instance.js +230 -0
- package/dist/runtime/instance.js.map +1 -0
- package/dist/runtime/loader.d.ts +11 -0
- package/dist/runtime/loader.js +99 -0
- package/dist/runtime/loader.js.map +1 -0
- package/dist/runtime/projects.d.ts +51 -0
- package/dist/runtime/projects.js +139 -0
- package/dist/runtime/projects.js.map +1 -0
- package/dist/runtime/runtime.d.ts +178 -0
- package/dist/runtime/runtime.js +448 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/runtime/services.d.ts +177 -0
- package/dist/runtime/services.js +418 -0
- package/dist/runtime/services.js.map +1 -0
- package/dist/runtime/sessions.d.ts +55 -0
- package/dist/runtime/sessions.js +107 -0
- package/dist/runtime/sessions.js.map +1 -0
- package/dist/schema.d.ts +56 -0
- package/dist/schema.js +44 -0
- package/dist/schema.js.map +1 -0
- package/dist/server/admin.d.ts +115 -0
- package/dist/server/admin.js +326 -0
- package/dist/server/admin.js.map +1 -0
- package/dist/server/http.d.ts +19 -0
- package/dist/server/http.js +99 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/index.d.ts +52 -0
- package/dist/server/index.js +296 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/mcp.d.ts +12 -0
- package/dist/server/mcp.js +77 -0
- package/dist/server/mcp.js.map +1 -0
- package/dist/server/project.d.ts +60 -0
- package/dist/server/project.js +331 -0
- package/dist/server/project.js.map +1 -0
- package/dist/server/public.d.ts +14 -0
- package/dist/server/public.js +15 -0
- package/dist/server/public.js.map +1 -0
- package/dist/testing/index.d.ts +20 -0
- package/dist/testing/index.js +64 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +84 -4
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { FeltKitError } from "../errors.js";
|
|
3
|
+
import { validate } from "../schema.js";
|
|
4
|
+
const MAX_FIND = 10_000;
|
|
5
|
+
/**
|
|
6
|
+
* Per-collection change markers. Every commit through a Writer touches the marker of
|
|
7
|
+
* each collection it writes (unguarded, so concurrent writers never conflict on it).
|
|
8
|
+
* A read with no equality clause fences the marker, because FeltDB fences only
|
|
9
|
+
* predicates that name at least one field.
|
|
10
|
+
*/
|
|
11
|
+
export const COLLECTION_MARKERS = "_feltkit_collections";
|
|
12
|
+
export class CollectionResolver {
|
|
13
|
+
collections;
|
|
14
|
+
constructor(collections) {
|
|
15
|
+
this.collections = collections;
|
|
16
|
+
}
|
|
17
|
+
resolve(ref) {
|
|
18
|
+
const name = typeof ref === "string" ? ref : ref?.name;
|
|
19
|
+
const definition = name ? this.collections.get(name) : undefined;
|
|
20
|
+
if (!definition) {
|
|
21
|
+
throw new FeltKitError("NOT_FOUND", `Collection "${String(name)}" is not declared by this application.`, {
|
|
22
|
+
hint: `Declare it with app.collection("${String(name)}", { ... }). Platform collections are not reachable through ctx.db.`,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return definition;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function newId() {
|
|
29
|
+
return `${Date.now().toString(36)}${randomBytes(6).toString("hex")}`;
|
|
30
|
+
}
|
|
31
|
+
function stripSystem(value) {
|
|
32
|
+
const { id: _id, __version: _v, ...rest } = value;
|
|
33
|
+
return rest;
|
|
34
|
+
}
|
|
35
|
+
function validateRecord(definition, value) {
|
|
36
|
+
const result = validate(definition.schema, value);
|
|
37
|
+
if (!result.ok) {
|
|
38
|
+
throw new FeltKitError("VALIDATION_FAILED", `Invalid "${definition.name}" record: ${result.issues.map((i) => `${i.path}: ${i.message}`).join("; ")}`, {
|
|
39
|
+
details: { collection: definition.name, issues: result.issues },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function compare(a, b) {
|
|
44
|
+
if (a === b)
|
|
45
|
+
return 0;
|
|
46
|
+
if (a === undefined || a === null)
|
|
47
|
+
return -1;
|
|
48
|
+
if (b === undefined || b === null)
|
|
49
|
+
return 1;
|
|
50
|
+
if (typeof a === "number" && typeof b === "number")
|
|
51
|
+
return a - b;
|
|
52
|
+
return String(a) < String(b) ? -1 : 1;
|
|
53
|
+
}
|
|
54
|
+
function matchesWhere(record, where) {
|
|
55
|
+
return where.every((clause) => {
|
|
56
|
+
const value = record[clause.field];
|
|
57
|
+
if ("eq" in clause && clause.eq !== undefined && value !== clause.eq)
|
|
58
|
+
return false;
|
|
59
|
+
if ("neq" in clause && clause.neq !== undefined && value === clause.neq)
|
|
60
|
+
return false;
|
|
61
|
+
if (clause.lt !== undefined && !(compare(value, clause.lt) < 0))
|
|
62
|
+
return false;
|
|
63
|
+
if (clause.lte !== undefined && !(compare(value, clause.lte) <= 0))
|
|
64
|
+
return false;
|
|
65
|
+
if (clause.gt !== undefined && !(compare(value, clause.gt) > 0))
|
|
66
|
+
return false;
|
|
67
|
+
if (clause.gte !== undefined && !(compare(value, clause.gte) >= 0))
|
|
68
|
+
return false;
|
|
69
|
+
return true;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function sortRecords(records, orderBy = []) {
|
|
73
|
+
return [...records].sort((a, b) => {
|
|
74
|
+
for (const order of orderBy) {
|
|
75
|
+
const c = compare(a[order.field], b[order.field]);
|
|
76
|
+
if (c !== 0)
|
|
77
|
+
return order.direction === "desc" ? -c : c;
|
|
78
|
+
}
|
|
79
|
+
return compare(a.id, b.id);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function equalityWhere(filter) {
|
|
83
|
+
return Object.entries(filter ?? {})
|
|
84
|
+
.filter(([, value]) => value !== undefined)
|
|
85
|
+
.map(([field, value]) => ({ field, eq: value }));
|
|
86
|
+
}
|
|
87
|
+
function checkLimit(limit, name) {
|
|
88
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit < 1 || limit > MAX_FIND)) {
|
|
89
|
+
throw new FeltKitError("INVALID_ARGUMENT", `${name} limit must be an integer between 1 and ${MAX_FIND}.`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Read-only access. Every collection read is recorded so subscribers can be invalidated. */
|
|
93
|
+
export class Reader {
|
|
94
|
+
db;
|
|
95
|
+
resolver;
|
|
96
|
+
reads = new Set();
|
|
97
|
+
constructor(db, resolver) {
|
|
98
|
+
this.db = db;
|
|
99
|
+
this.resolver = resolver;
|
|
100
|
+
}
|
|
101
|
+
track(ref) {
|
|
102
|
+
const definition = this.resolver.resolve(ref);
|
|
103
|
+
this.reads.add(definition.name);
|
|
104
|
+
return definition;
|
|
105
|
+
}
|
|
106
|
+
async get(ref, id) {
|
|
107
|
+
const definition = this.track(ref);
|
|
108
|
+
if (typeof id !== "string" || !id)
|
|
109
|
+
throw new FeltKitError("INVALID_ARGUMENT", "get() needs a record id.");
|
|
110
|
+
return (await this.db.collection(definition.name).get(id)) ?? null;
|
|
111
|
+
}
|
|
112
|
+
async find(ref, filter, options = {}) {
|
|
113
|
+
const definition = this.track(ref);
|
|
114
|
+
checkLimit(options.limit, "find()");
|
|
115
|
+
const clean = Object.fromEntries(Object.entries(filter ?? {}).filter(([, v]) => v !== undefined));
|
|
116
|
+
const findOptions = {
|
|
117
|
+
...(options.orderBy ? { orderBy: options.orderBy } : {}),
|
|
118
|
+
...(options.limit ? { limit: options.limit } : {}),
|
|
119
|
+
};
|
|
120
|
+
return this.db.collection(definition.name).find(clean, findOptions);
|
|
121
|
+
}
|
|
122
|
+
async query(ref, request) {
|
|
123
|
+
const definition = this.track(ref);
|
|
124
|
+
checkLimit(request?.limit, "query()");
|
|
125
|
+
if (!request?.limit)
|
|
126
|
+
throw new FeltKitError("INVALID_ARGUMENT", "query() needs a limit; FeltDB queries are bounded.");
|
|
127
|
+
const page = await this.db.query({
|
|
128
|
+
collection: definition.name,
|
|
129
|
+
...(request.where ? { where: request.where } : {}),
|
|
130
|
+
...(request.orderBy ? { orderBy: request.orderBy } : {}),
|
|
131
|
+
limit: request.limit,
|
|
132
|
+
...(request.cursor ? { cursor: request.cursor } : {}),
|
|
133
|
+
});
|
|
134
|
+
return { records: page.records, exhausted: page.exhausted, ...(page.nextCursor ? { nextCursor: page.nextCursor } : {}) };
|
|
135
|
+
}
|
|
136
|
+
async count(ref, filter) {
|
|
137
|
+
return (await this.find(ref, filter)).length;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Mutation access: reads see pending writes; writes commit together. */
|
|
141
|
+
export class Writer extends Reader {
|
|
142
|
+
#pending = new Map();
|
|
143
|
+
/** Committed versions observed by id (null = observed absent). */
|
|
144
|
+
#observed = new Map();
|
|
145
|
+
/** Read bases for predicate reads (find/query/count), keyed by predicate. The first capture wins. */
|
|
146
|
+
#fences = new Map();
|
|
147
|
+
#committed = false;
|
|
148
|
+
/**
|
|
149
|
+
* Fence a predicate read: capture FeltDB's read basis for "records of `collection`
|
|
150
|
+
* whose fields equal `where`" *before* reading, and carry it to commit. The commit
|
|
151
|
+
* re-evaluates the basis inside FeltDB's commit lock, so a record that started or
|
|
152
|
+
* stopped matching, or changed, since this read fails the whole transaction.
|
|
153
|
+
* Range clauses are dropped from the fenced predicate, which fences a superset:
|
|
154
|
+
* more conservative, never weaker.
|
|
155
|
+
*/
|
|
156
|
+
async #fence(collection, where) {
|
|
157
|
+
const equality = where
|
|
158
|
+
.filter((clause) => "eq" in clause && clause.eq !== undefined && [clause.neq, clause.lt, clause.lte, clause.gt, clause.gte].every((v) => v === undefined))
|
|
159
|
+
.map((clause) => ({ field: clause.field, eq: clause.eq }))
|
|
160
|
+
.sort((a, b) => a.field.localeCompare(b.field));
|
|
161
|
+
const key = JSON.stringify([collection, equality]);
|
|
162
|
+
if (this.#fences.has(key))
|
|
163
|
+
return;
|
|
164
|
+
const reads = equality.length
|
|
165
|
+
? { predicates: [{ collection, where: equality }] }
|
|
166
|
+
: { records: [{ collection: COLLECTION_MARKERS, id: collection }] };
|
|
167
|
+
try {
|
|
168
|
+
this.#fences.set(key, await this.db.readBasis(reads));
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
throw new FeltKitError("UNAVAILABLE", `This FeltDB authority cannot fence reads, so the mutation cannot guarantee its reads are current: ${error.message}`, { cause: error });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
#key(collection, id) {
|
|
175
|
+
return `${collection}\u0000${id}`;
|
|
176
|
+
}
|
|
177
|
+
get pendingCount() {
|
|
178
|
+
return this.#pending.size;
|
|
179
|
+
}
|
|
180
|
+
#pendingFor(collection) {
|
|
181
|
+
return [...this.#pending.values()].filter((p) => p.collection === collection);
|
|
182
|
+
}
|
|
183
|
+
async #committedGet(collection, id) {
|
|
184
|
+
const record = (await this.db.collection(collection).get(id)) ?? null;
|
|
185
|
+
const key = this.#key(collection, id);
|
|
186
|
+
if (!this.#observed.has(key))
|
|
187
|
+
this.#observed.set(key, { collection, id, version: record ? record.__version : null });
|
|
188
|
+
return record;
|
|
189
|
+
}
|
|
190
|
+
#overlayOne(pending, committed) {
|
|
191
|
+
if (!pending)
|
|
192
|
+
return committed;
|
|
193
|
+
if (pending.op === "delete")
|
|
194
|
+
return null;
|
|
195
|
+
return { ...pending.value, id: pending.id, __version: committed?.__version ?? 0 };
|
|
196
|
+
}
|
|
197
|
+
async get(ref, id) {
|
|
198
|
+
const definition = this.track(ref);
|
|
199
|
+
if (typeof id !== "string" || !id)
|
|
200
|
+
throw new FeltKitError("INVALID_ARGUMENT", "get() needs a record id.");
|
|
201
|
+
const pending = this.#pending.get(this.#key(definition.name, id));
|
|
202
|
+
if (pending?.op === "insert")
|
|
203
|
+
return this.#overlayOne(pending, null);
|
|
204
|
+
return this.#overlayOne(pending, await this.#committedGet(definition.name, id));
|
|
205
|
+
}
|
|
206
|
+
async #overlayAll(name) {
|
|
207
|
+
const committed = await this.db.collection(name).find({});
|
|
208
|
+
const byId = new Map(committed.map((record) => [record.id, record]));
|
|
209
|
+
for (const pending of this.#pendingFor(name)) {
|
|
210
|
+
const merged = this.#overlayOne(pending, byId.get(pending.id) ?? null);
|
|
211
|
+
if (merged)
|
|
212
|
+
byId.set(pending.id, merged);
|
|
213
|
+
else
|
|
214
|
+
byId.delete(pending.id);
|
|
215
|
+
}
|
|
216
|
+
return [...byId.values()];
|
|
217
|
+
}
|
|
218
|
+
async find(ref, filter, options = {}) {
|
|
219
|
+
const definition = this.resolver.resolve(ref);
|
|
220
|
+
this.#assertOpen();
|
|
221
|
+
await this.#fence(definition.name, equalityWhere(filter));
|
|
222
|
+
if (this.#pendingFor(definition.name).length === 0)
|
|
223
|
+
return super.find(ref, filter, options);
|
|
224
|
+
this.track(ref);
|
|
225
|
+
checkLimit(options.limit, "find()");
|
|
226
|
+
const matched = sortRecords((await this.#overlayAll(definition.name)).filter((r) => matchesWhere(r, equalityWhere(filter))), options.orderBy);
|
|
227
|
+
return options.limit ? matched.slice(0, options.limit) : matched;
|
|
228
|
+
}
|
|
229
|
+
async query(ref, request) {
|
|
230
|
+
const definition = this.resolver.resolve(ref);
|
|
231
|
+
this.#assertOpen();
|
|
232
|
+
await this.#fence(definition.name, request?.where ?? []);
|
|
233
|
+
if (this.#pendingFor(definition.name).length === 0)
|
|
234
|
+
return super.query(ref, request);
|
|
235
|
+
this.track(ref);
|
|
236
|
+
checkLimit(request?.limit, "query()");
|
|
237
|
+
if (request.cursor) {
|
|
238
|
+
throw new FeltKitError("INVALID_ARGUMENT", "query() cursors cannot be combined with this mutation's own pending writes to the same collection.", {
|
|
239
|
+
hint: "Page before writing, or read with find().",
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
const matched = sortRecords((await this.#overlayAll(definition.name)).filter((r) => matchesWhere(r, request.where ?? [])), request.orderBy);
|
|
243
|
+
return { records: matched.slice(0, request.limit), exhausted: matched.length <= request.limit };
|
|
244
|
+
}
|
|
245
|
+
#assertOpen() {
|
|
246
|
+
if (this.#committed)
|
|
247
|
+
throw new FeltKitError("INTERNAL", "This mutation has already committed; ctx.db cannot be used after the handler returns.");
|
|
248
|
+
}
|
|
249
|
+
async insert(ref, value) {
|
|
250
|
+
this.#assertOpen();
|
|
251
|
+
const definition = this.track(ref);
|
|
252
|
+
if (!value || typeof value !== "object")
|
|
253
|
+
throw new FeltKitError("INVALID_ARGUMENT", "insert() needs a record object.");
|
|
254
|
+
const fields = stripSystem(value);
|
|
255
|
+
validateRecord(definition, fields);
|
|
256
|
+
const id = newId();
|
|
257
|
+
this.#pending.set(this.#key(definition.name, id), { collection: definition.name, id, op: "insert", value: fields });
|
|
258
|
+
return id;
|
|
259
|
+
}
|
|
260
|
+
async #existing(definition, id) {
|
|
261
|
+
if (typeof id !== "string" || !id)
|
|
262
|
+
throw new FeltKitError("INVALID_ARGUMENT", "A record id is required.");
|
|
263
|
+
const key = this.#key(definition.name, id);
|
|
264
|
+
const pending = this.#pending.get(key);
|
|
265
|
+
if (pending?.op === "delete")
|
|
266
|
+
throw new FeltKitError("NOT_FOUND", `${definition.name}/${id} was deleted earlier in this mutation.`);
|
|
267
|
+
if (pending)
|
|
268
|
+
return { current: pending.value ?? {}, pending, ...(pending.baseVersion !== undefined ? { base: pending.baseVersion } : {}) };
|
|
269
|
+
const committed = await this.#committedGet(definition.name, id);
|
|
270
|
+
if (!committed)
|
|
271
|
+
throw new FeltKitError("NOT_FOUND", `${definition.name}/${id} does not exist.`, { details: { collection: definition.name, id } });
|
|
272
|
+
return { current: stripSystem(committed), base: committed.__version };
|
|
273
|
+
}
|
|
274
|
+
async patch(ref, id, fields) {
|
|
275
|
+
this.#assertOpen();
|
|
276
|
+
const definition = this.track(ref);
|
|
277
|
+
const { current, pending, base } = await this.#existing(definition, id);
|
|
278
|
+
const merged = { ...current, ...stripSystem(fields ?? {}) };
|
|
279
|
+
for (const [key, value] of Object.entries(fields ?? {}))
|
|
280
|
+
if (value === undefined)
|
|
281
|
+
delete merged[key];
|
|
282
|
+
validateRecord(definition, merged);
|
|
283
|
+
this.#pending.set(this.#key(definition.name, id), {
|
|
284
|
+
collection: definition.name,
|
|
285
|
+
id,
|
|
286
|
+
op: pending?.op === "insert" ? "insert" : "update",
|
|
287
|
+
value: merged,
|
|
288
|
+
...(base !== undefined ? { baseVersion: base } : {}),
|
|
289
|
+
});
|
|
290
|
+
return { ...merged, id, __version: pending?.op === "insert" ? 1 : (base ?? 0) + 1 };
|
|
291
|
+
}
|
|
292
|
+
async replace(ref, id, value) {
|
|
293
|
+
this.#assertOpen();
|
|
294
|
+
const definition = this.track(ref);
|
|
295
|
+
const { pending, base } = await this.#existing(definition, id);
|
|
296
|
+
const fields = stripSystem(value ?? {});
|
|
297
|
+
validateRecord(definition, fields);
|
|
298
|
+
this.#pending.set(this.#key(definition.name, id), {
|
|
299
|
+
collection: definition.name,
|
|
300
|
+
id,
|
|
301
|
+
op: pending?.op === "insert" ? "insert" : "update",
|
|
302
|
+
value: fields,
|
|
303
|
+
...(base !== undefined ? { baseVersion: base } : {}),
|
|
304
|
+
});
|
|
305
|
+
return { ...fields, id, __version: pending?.op === "insert" ? 1 : (base ?? 0) + 1 };
|
|
306
|
+
}
|
|
307
|
+
async delete(ref, id) {
|
|
308
|
+
this.#assertOpen();
|
|
309
|
+
const definition = this.track(ref);
|
|
310
|
+
const { pending, base } = await this.#existing(definition, id);
|
|
311
|
+
const key = this.#key(definition.name, id);
|
|
312
|
+
if (pending?.op === "insert") {
|
|
313
|
+
this.#pending.delete(key);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
this.#pending.set(key, { collection: definition.name, id, op: "delete", ...(base !== undefined ? { baseVersion: base } : {}) });
|
|
317
|
+
}
|
|
318
|
+
/** Commit every pending write in one FeltDB transaction. */
|
|
319
|
+
async commit(transactionId) {
|
|
320
|
+
this.#assertOpen();
|
|
321
|
+
this.#committed = true;
|
|
322
|
+
const writes = [];
|
|
323
|
+
const operations = [];
|
|
324
|
+
for (const pending of this.#pending.values()) {
|
|
325
|
+
if (pending.op === "insert") {
|
|
326
|
+
operations.push({ collection: pending.collection, id: pending.id, requireAbsent: true, value: { ...pending.value, id: pending.id } });
|
|
327
|
+
writes.push({ collection: pending.collection, id: pending.id, op: "insert" });
|
|
328
|
+
}
|
|
329
|
+
else if (pending.op === "update") {
|
|
330
|
+
operations.push({ collection: pending.collection, id: pending.id, ifVersion: pending.baseVersion, value: { ...pending.value, id: pending.id } });
|
|
331
|
+
writes.push({ collection: pending.collection, id: pending.id, op: "update", expectedVersion: pending.baseVersion });
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
operations.push({ collection: pending.collection, id: pending.id, ifVersion: pending.baseVersion });
|
|
335
|
+
writes.push({ collection: pending.collection, id: pending.id, op: "delete", expectedVersion: pending.baseVersion });
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (operations.length === 0)
|
|
339
|
+
return { transactionId, writes: [], operationIds: [] };
|
|
340
|
+
for (const collection of new Set(writes.map((w) => w.collection))) {
|
|
341
|
+
operations.push({ collection: COLLECTION_MARKERS, id: collection, value: { id: collection, transactionId, changedAt: Date.now() } });
|
|
342
|
+
}
|
|
343
|
+
const preconditions = [];
|
|
344
|
+
for (const [key, observed] of this.#observed) {
|
|
345
|
+
if (this.#pending.has(key))
|
|
346
|
+
continue;
|
|
347
|
+
preconditions.push(observed.version === null
|
|
348
|
+
? { collection: observed.collection, id: observed.id, requireAbsent: true }
|
|
349
|
+
: { collection: observed.collection, id: observed.id, ifVersion: observed.version });
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
const fences = [...this.#fences.values()];
|
|
353
|
+
const result = await this.db.transaction({ transactionId, operations, ...(preconditions.length ? { preconditions } : {}), ...(fences.length ? { fences } : {}) });
|
|
354
|
+
return {
|
|
355
|
+
transactionId: result.transactionId,
|
|
356
|
+
writes,
|
|
357
|
+
operationIds: result.operationIds ?? [],
|
|
358
|
+
...(result.commitRevision !== undefined ? { commitRevision: result.commitRevision } : {}),
|
|
359
|
+
...(result.revisionId ? { revisionId: result.revisionId } : {}),
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
const err = error;
|
|
364
|
+
if (err?.name === "ConditionalConflictError" || err?.code === "PRECONDITION_FAILED" || err?.code === "CONFLICT") {
|
|
365
|
+
throw new FeltKitError("CONFLICT", "A record this mutation read changed before it could commit. Nothing was written; it is safe to retry.", {
|
|
366
|
+
details: { transactionId, conflict: err.conflict ?? null },
|
|
367
|
+
cause: error,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
//# sourceMappingURL=data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/runtime/data.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAA6D,MAAM,cAAc,CAAC;AA0EnG,MAAM,QAAQ,GAAG,MAAM,CAAC;AAExB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAEzD,MAAM,OAAO,kBAAkB;IACA;IAA7B,YAA6B,WAAsD;QAAtD,gBAAW,GAAX,WAAW,CAA2C;IAAG,CAAC;IAEvF,OAAO,CAAC,GAAkB;QACxB,MAAM,IAAI,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC;QACvD,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACjE,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,YAAY,CAAC,WAAW,EAAE,eAAe,MAAM,CAAC,IAAI,CAAC,wCAAwC,EAAE;gBACvG,IAAI,EAAE,mCAAmC,MAAM,CAAC,IAAI,CAAC,qEAAqE;aAC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ACzK,OAAO;gBACL,aAAa,EAAE,MAAM,CAAC,aAAa;gBACnC,MAAM;gBACN,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,EAAE;gBACvC,GAAG,CAAC,MAAM,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzF,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChE,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,GAAG,GAAG,KAA+E,CAAC;YAC5F,IAAI,GAAG,EAAE,IAAI,KAAK,0BAA0B,IAAI,GAAG,EAAE,IAAI,KAAK,qBAAqB,IAAI,GAAG,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;gBAChH,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,uGAAuG,EAAE;oBAC1I,OAAO,EAAE,EAAE,aAAa,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,IAAI,EAAE;oBAC1D,KAAK,EAAE,KAAK;iBACb,CAAC,CAAC;YACL,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type EnvironmentName = "development" | "test" | "production" | (string & {});
|
|
2
|
+
export type StorageDescriptor = {
|
|
3
|
+
kind: "local";
|
|
4
|
+
path: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: "remote";
|
|
7
|
+
url: string;
|
|
8
|
+
token?: string;
|
|
9
|
+
applicationId?: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "memory";
|
|
12
|
+
};
|
|
13
|
+
export interface EnvironmentDescriptor {
|
|
14
|
+
name: EnvironmentName;
|
|
15
|
+
namespace: string;
|
|
16
|
+
storage: StorageDescriptor;
|
|
17
|
+
/** Development-only tooling (dev sign-in, dashboard writes) is enabled. */
|
|
18
|
+
development: boolean;
|
|
19
|
+
production: boolean;
|
|
20
|
+
/** Where environment-local runtime files live (admin token, runtime.json). */
|
|
21
|
+
runtimeDir: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ResolveEnvironmentOptions {
|
|
24
|
+
projectDir: string;
|
|
25
|
+
appName: string;
|
|
26
|
+
name?: EnvironmentName;
|
|
27
|
+
env?: NodeJS.ProcessEnv;
|
|
28
|
+
storage?: StorageDescriptor;
|
|
29
|
+
}
|
|
30
|
+
export declare function resolveEnvironment(options: ResolveEnvironmentOptions): EnvironmentDescriptor;
|
|
31
|
+
/** A description safe to print or send to the dashboard. Never includes tokens. */
|
|
32
|
+
export declare function describeStorage(storage: StorageDescriptor): {
|
|
33
|
+
kind: string;
|
|
34
|
+
location: string;
|
|
35
|
+
durable: boolean;
|
|
36
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environments. Each environment gets its own FeltDB instance, and it is always
|
|
3
|
+
* explicit which one is active.
|
|
4
|
+
*
|
|
5
|
+
* development <project>/.feltkit/development/state (local FeltDB, durable)
|
|
6
|
+
* test a fresh temporary directory per runtime (local FeltDB, durable until removed)
|
|
7
|
+
* production FELTDB_URL → a FeltDB server; otherwise FELTKIT_STATE_DIR or
|
|
8
|
+
* <project>/.feltkit/production/state
|
|
9
|
+
*
|
|
10
|
+
* FELTKIT_STATE_DIR overrides the local path for any environment.
|
|
11
|
+
*/
|
|
12
|
+
import { mkdtempSync } from "node:fs";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import { join, resolve } from "node:path";
|
|
15
|
+
import { FeltKitError } from "../errors.js";
|
|
16
|
+
const NAME = /^[a-z][a-z0-9-]{0,31}$/;
|
|
17
|
+
export function resolveEnvironment(options) {
|
|
18
|
+
const env = options.env ?? process.env;
|
|
19
|
+
const name = options.name ?? env.FELTKIT_ENV ?? "development";
|
|
20
|
+
if (!NAME.test(name)) {
|
|
21
|
+
throw new FeltKitError("CONFIGURATION", `Environment name "${name}" is invalid; use lowercase letters, digits, and dashes.`);
|
|
22
|
+
}
|
|
23
|
+
const projectDir = resolve(options.projectDir);
|
|
24
|
+
const runtimeDir = join(projectDir, ".feltkit", name);
|
|
25
|
+
const development = name === "development" || name === "test";
|
|
26
|
+
const production = name === "production";
|
|
27
|
+
let storage = options.storage;
|
|
28
|
+
if (!storage) {
|
|
29
|
+
if (env.FELTDB_URL && name !== "development" && name !== "test") {
|
|
30
|
+
storage = {
|
|
31
|
+
kind: "remote",
|
|
32
|
+
url: env.FELTDB_URL,
|
|
33
|
+
...(env.FELTDB_TOKEN ? { token: env.FELTDB_TOKEN } : {}),
|
|
34
|
+
...(env.FELTDB_APPLICATION_ID ? { applicationId: env.FELTDB_APPLICATION_ID } : {}),
|
|
35
|
+
};
|
|
36
|
+
if (production && !env.FELTDB_TOKEN) {
|
|
37
|
+
throw new FeltKitError("CONFIGURATION", "FELTDB_URL is set for production but FELTDB_TOKEN is not.", {
|
|
38
|
+
hint: "Set FELTDB_TOKEN from your secret manager. It is never written to disk by FeltKit.",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (env.FELTKIT_STATE_DIR) {
|
|
43
|
+
storage = { kind: "local", path: resolve(projectDir, env.FELTKIT_STATE_DIR) };
|
|
44
|
+
}
|
|
45
|
+
else if (name === "test") {
|
|
46
|
+
storage = { kind: "local", path: mkdtempSync(join(tmpdir(), `feltkit-${options.appName}-test-`)) };
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
storage = { kind: "local", path: join(runtimeDir, "state") };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { name, namespace: options.appName, storage, development, production, runtimeDir };
|
|
53
|
+
}
|
|
54
|
+
/** A description safe to print or send to the dashboard. Never includes tokens. */
|
|
55
|
+
export function describeStorage(storage) {
|
|
56
|
+
if (storage.kind === "local")
|
|
57
|
+
return { kind: "local", location: storage.path, durable: true };
|
|
58
|
+
if (storage.kind === "remote")
|
|
59
|
+
return { kind: "remote", location: new URL(storage.url).origin, durable: true };
|
|
60
|
+
return { kind: "memory", location: "memory", durable: false };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/runtime/environment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AA4B5C,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAEtC,MAAM,UAAU,kBAAkB,CAAC,OAAkC;IACnE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAK,GAAG,CAAC,WAA2C,IAAI,aAAa,CAAC;IAC/F,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,YAAY,CAAC,eAAe,EAAE,qBAAqB,IAAI,0DAA0D,CAAC,CAAC;IAC/H,CAAC;IACD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IACtD,MAAM,WAAW,GAAG,IAAI,KAAK,aAAa,IAAI,IAAI,KAAK,MAAM,CAAC;IAC9D,MAAM,UAAU,GAAG,IAAI,KAAK,YAAY,CAAC;IAEzC,IAAI,OAAO,GAAG,O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,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;AAC5F,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,eAAe,CAAC,OAA0B;IACxD,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC9F,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC/G,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The FeltDB instance factory.
|
|
3
|
+
*
|
|
4
|
+
* This module is the only place in FeltKit that calls `createFeltDB`. It opens one
|
|
5
|
+
* authoritative instance per environment and hands out *component handles*: views of
|
|
6
|
+
* that same `StateFirstDB` that record which component touched which collection.
|
|
7
|
+
* Every layer (application functions, AppPort capabilities, AppPort Services, the
|
|
8
|
+
* activity log, sessions) receives a handle through explicit dependency injection.
|
|
9
|
+
*
|
|
10
|
+
* FeltDB itself does not refuse a second instance over the same state in one
|
|
11
|
+
* process, so the factory does: a second open for the same environment, or for
|
|
12
|
+
* another environment pointing at the same state, throws DUPLICATE_INSTANCE.
|
|
13
|
+
*/
|
|
14
|
+
import { type StateFirstDB } from "@feltdb/core";
|
|
15
|
+
import type { EnvironmentDescriptor } from "./environment.js";
|
|
16
|
+
export interface InstanceIdentity {
|
|
17
|
+
/** Environment this instance belongs to. */
|
|
18
|
+
environment: string;
|
|
19
|
+
/** FeltDB deployment mode. */
|
|
20
|
+
mode: "local" | "remote" | "memory";
|
|
21
|
+
/** Where state lives: an absolute path, a server origin, or "memory". Never a credential. */
|
|
22
|
+
location: string;
|
|
23
|
+
namespace: string;
|
|
24
|
+
/** FeltDB's own instance identity (`db.instanceId()`). */
|
|
25
|
+
instanceId: string;
|
|
26
|
+
/** Resolved `@feltdb/core` version backing this instance. */
|
|
27
|
+
feltdbVersion: string;
|
|
28
|
+
durable: boolean;
|
|
29
|
+
openedAt: string;
|
|
30
|
+
pid: number;
|
|
31
|
+
}
|
|
32
|
+
export interface InstanceEvent {
|
|
33
|
+
type: "open" | "close" | "refused";
|
|
34
|
+
key: string;
|
|
35
|
+
environment: string;
|
|
36
|
+
at: string;
|
|
37
|
+
reason?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare class StateInstance {
|
|
40
|
+
#private;
|
|
41
|
+
readonly identity: InstanceIdentity;
|
|
42
|
+
/** component → collections it reached through its handle */
|
|
43
|
+
readonly access: Map<string, Set<string>>;
|
|
44
|
+
constructor(db: StateFirstDB, identity: InstanceIdentity, factory: InstanceFactory, key: string);
|
|
45
|
+
get closed(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* A handle on this instance for one component. The handle *is* this instance's
|
|
48
|
+
* `StateFirstDB` (calls forward to it unchanged); it only records collection access.
|
|
49
|
+
*/
|
|
50
|
+
handle(component: string): StateFirstDB;
|
|
51
|
+
/** True when `db` is this instance or a handle on it. */
|
|
52
|
+
owns(db: unknown): boolean;
|
|
53
|
+
/** The raw instance. Reserved for the runtime and documented escape hatches. */
|
|
54
|
+
unsafeRaw(): StateFirstDB;
|
|
55
|
+
close(): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
/** Identify which handle (if any) a value is. */
|
|
58
|
+
export declare function describeHandle(db: unknown): {
|
|
59
|
+
component: string;
|
|
60
|
+
} | undefined;
|
|
61
|
+
export declare function feltdbVersion(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Opens FeltDB instances. A process normally uses one factory (`defaultInstanceFactory`);
|
|
64
|
+
* tests construct their own to observe every open.
|
|
65
|
+
*/
|
|
66
|
+
export declare class InstanceFactory {
|
|
67
|
+
#private;
|
|
68
|
+
readonly events: InstanceEvent[];
|
|
69
|
+
onEvent(listener: (event: InstanceEvent) => void): void;
|
|
70
|
+
/** Environments currently holding an instance from this factory. */
|
|
71
|
+
get openEnvironments(): string[];
|
|
72
|
+
open(environment: EnvironmentDescriptor): StateInstance;
|
|
73
|
+
/** @internal called by StateInstance.close */
|
|
74
|
+
released(key: string, environment: string): void;
|
|
75
|
+
}
|
|
76
|
+
/** The process's factory. Runtimes use it unless given another. */
|
|
77
|
+
export declare const defaultInstanceFactory: InstanceFactory;
|