@super-line/collections-cloudflare 0.0.0-stage → 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/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ Generated from conventional commits by [git-cliff](https://git-cliff.org) —
4
+ run `pnpm changelog` rather than editing by hand.
5
+
6
+ ## [collections-cloudflare-v0.1.0] — 2026-10-15
7
+
8
+ ### Features
9
+
10
+ - **collections-cloudflare:** Row collections on Durable Object SQLite ([6b1f3eb])
11
+
12
+ ### Documentation
13
+
14
+ - Teach hosting a node on Cloudflare Durable Objects ([a893f83])
15
+
16
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,45 @@
1
- # Temporary Holding Version
1
+ # @super-line/collections-cloudflare
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [**super-line**](https://super-line.dogar.biz/) [row collections](https://super-line.dogar.biz/collections/row-collections) stored in a Cloudflare **Durable Object's** own SQLite — the object that is the node (see [`@super-line/transport-cloudflare`](https://github.com/mertdogar/super-line/tree/main/packages/transport-cloudflare)). Each collection gets its own typed table, laid out exactly as [`@super-line/collections-sqlite`](https://github.com/mertdogar/super-line/tree/main/packages/collections-sqlite) does, with the same IR→SQL snapshot pushdown, and one `transactionSync` spans every collection, so a cross-collection batch stays atomic.
4
+
5
+ ```bash
6
+ pnpm add @super-line/core @super-line/collections-cloudflare
7
+ ```
8
+
9
+ ```ts
10
+ import { createSuperLineServer } from '@super-line/server'
11
+ import { createDurableNode } from '@super-line/transport-cloudflare'
12
+ import { cloudflareCollections } from '@super-line/collections-cloudflare'
13
+ import { contract } from './contract'
14
+
15
+ export class Node extends createDurableNode((ctx, env, base) =>
16
+ createSuperLineServer(contract, {
17
+ ...base,
18
+ authenticate,
19
+ policies,
20
+ collections: cloudflareCollections(ctx.storage, contract.collections),
21
+ }),
22
+ ) {}
23
+ ```
24
+
25
+ `cloudflareCollections(storage, collections)` is synchronous and opens on the first operation, so building it in the object's constructor costs nothing and never throws. It needs the contract's post-merge `collections` map. `clustering: 'relay'`, `coordination: 'local'` — one node, so nothing is relayed.
26
+
27
+ ## Limits
28
+
29
+ Durable Object SQLite is stricter than a SQLite file:
30
+
31
+ - **98 typed columns per collection** (the platform allows 100; two are row timestamps). A wider collection fails its own operations with an `INTERNAL` error naming it; the rest keep working.
32
+ - **2 MB per row.** A larger write fails, and the client receives `INTERNAL`.
33
+ - **100 bound values per query.** A snapshot filter needing more than 98 values scans the table and filters in JavaScript — same results, slower on a large table.
34
+
35
+ ## Schema changes on a deployed object
36
+
37
+ A new optional field is altered in on the first operation. Any other change — a field that changed type, a removed field, a new required field — makes that collection fail its operations with an `INTERNAL` error naming it and the fix, while the rest of the object works. Either rename the collection (a new table; the old rows stay unread), or migrate `col_<name>` and its `col_meta` row with `ctx.storage.sql.exec` in your factory before you create the server.
38
+
39
+ The backend owns the `col_<name>` and `col_meta` tables in the object's storage.
40
+
41
+ - 📖 Guide: [Host a node on Cloudflare Durable Objects](https://super-line.dogar.biz/how-to/cloudflare-durable-objects)
42
+ - 📚 Reference: [Backends & clustering](https://super-line.dogar.biz/collections/backends)
43
+ - 🧩 Source: <https://github.com/mertdogar/super-line>
44
+
45
+ MIT © Mert
@@ -0,0 +1,19 @@
1
+ import { CollectionDef, RelayCollectionStore } from '@super-line/core';
2
+
3
+ /**
4
+ * The Durable Object SQLite RelayCollectionStore: every LWW collection on the contract gets its own typed table
5
+ * (`col_<name>`) in the object's own storage, exactly as `sqliteCollections` lays it out, and one
6
+ * `transactionSync` spans all of them, so a cross-collection batch stays atomic.
7
+ *
8
+ * Opens lazily, on the first operation, so building it in the object's constructor never throws (a throw there
9
+ * resets the object). A collection that can't open — its schema drifted non-additively, or it plans more than 98
10
+ * columns — fails only its own operations, with an `INTERNAL` error that names it and the fix; the rest keep
11
+ * working. Additive drift (new optional fields) is altered in, as with `sqliteCollections`.
12
+ *
13
+ * ```ts
14
+ * createSuperLineServer(contract, { ...base, collections: cloudflareCollections(ctx.storage, contract.collections) })
15
+ * ```
16
+ */
17
+ declare function cloudflareCollections(storage: DurableObjectStorage, collections: Record<string, CollectionDef>): RelayCollectionStore;
18
+
19
+ export { cloudflareCollections };
package/dist/index.js ADDED
@@ -0,0 +1,358 @@
1
+ // src/index.ts
2
+ import { SuperLineError, applyQuery, isCrdtCollection, matchesFilter } from "@super-line/core";
3
+
4
+ // ../collections-sqlite/src/sql.ts
5
+ import { DEGENERATE_DATA_COLUMN, planColumns } from "@super-line/core";
6
+ var IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/;
7
+ var sqlType = (kind) => kind === "text" ? "TEXT" : kind === "real" ? "REAL" : kind === "integer-bool" ? "INTEGER" : "TEXT";
8
+ var norm = (v) => typeof v === "boolean" ? v ? 1 : 0 : v;
9
+ var kindMatches = (kind, v) => kind === "text" && typeof v === "string" || kind === "real" && typeof v === "number" || kind === "integer-bool" && typeof v === "boolean";
10
+ var META_SQL = {
11
+ create: `CREATE TABLE IF NOT EXISTS col_meta (collection TEXT PRIMARY KEY, fingerprint TEXT NOT NULL)`,
12
+ get: `SELECT fingerprint FROM col_meta WHERE collection = ?`,
13
+ insert: `INSERT INTO col_meta (collection, fingerprint) VALUES (?, ?)`,
14
+ update: `UPDATE col_meta SET fingerprint = ? WHERE collection = ?`
15
+ };
16
+ function defineTable(n, def) {
17
+ if (!IDENT.test(n) || n.length > 60) throw new Error(`invalid collection name '${n}'`);
18
+ const plan = planColumns(def);
19
+ const name = `col_${n}`;
20
+ const indexes = (def.indexes ?? []).map((fields, index) => {
21
+ if (fields.length === 0 || fields.some((field) => !plan.columns.some((column) => column.name === field)))
22
+ throw new Error(`invalid index ${index} on '${n}'`);
23
+ return `CREATE INDEX IF NOT EXISTS "${name}_idx_${index}" ON "${name}" (${fields.map((field) => `"${field}"`).join(", ")})`;
24
+ });
25
+ const colList = plan.columns.map((c) => `"${c.name}"`).join(", ");
26
+ const setList = [...plan.columns.filter((c) => c.name !== plan.key).map((c) => `"${c.name}" = ?`), `"_sl_updated_at" = ?`].join(", ");
27
+ return {
28
+ name,
29
+ plan,
30
+ byName: new Map(plan.columns.map((c) => [c.name, c])),
31
+ create: createTableSql(name, plan),
32
+ indexes,
33
+ sql: {
34
+ get: `SELECT ${colList} FROM "${name}" WHERE "${plan.key}" = ?`,
35
+ has: `SELECT 1 FROM "${name}" WHERE "${plan.key}" = ?`,
36
+ insert: `INSERT INTO "${name}" (${colList}, "_sl_created_at", "_sl_updated_at") VALUES (${plan.columns.map(() => "?").join(", ")}, ?, ?)`,
37
+ update: `UPDATE "${name}" SET ${setList} WHERE "${plan.key}" = ?`,
38
+ delete: `DELETE FROM "${name}" WHERE "${plan.key}" = ?`
39
+ }
40
+ };
41
+ }
42
+ function resolveField(t, field) {
43
+ if (t.plan.degenerate) return { at: "json", col: DEGENERATE_DATA_COLUMN, path: "$." + field };
44
+ const dot = field.indexOf(".");
45
+ const head = dot === -1 ? field : field.slice(0, dot);
46
+ const col = t.byName.get(head);
47
+ if (!col) return { at: "absent" };
48
+ if (col.kind === "json") return { at: "json", col: col.name, path: dot === -1 ? "$" : "$." + field.slice(dot + 1) };
49
+ return dot === -1 ? { at: "scalar", col } : { at: "absent" };
50
+ }
51
+ var TRUE = { sql: "1=1", params: [], exact: true };
52
+ var FALSE = { sql: "1=0", params: [], exact: true };
53
+ function compileExpr(t, expr) {
54
+ switch (expr.op) {
55
+ case "and":
56
+ case "or": {
57
+ if (expr.args.length === 0) return expr.op === "and" ? TRUE : FALSE;
58
+ const parts = [];
59
+ const params = [];
60
+ let exact = true;
61
+ for (const arg of expr.args) {
62
+ const c = compileExpr(t, arg);
63
+ if (!c) {
64
+ if (expr.op === "or") return null;
65
+ exact = false;
66
+ continue;
67
+ }
68
+ exact &&= c.exact;
69
+ parts.push(`(${c.sql})`);
70
+ params.push(...c.params);
71
+ }
72
+ if (parts.length === 0) return null;
73
+ return { sql: parts.join(expr.op === "and" ? " AND " : " OR "), params, exact };
74
+ }
75
+ case "not": {
76
+ const c = compileExpr(t, expr.arg);
77
+ return c?.exact ? { sql: `NOT (${c.sql})`, params: c.params, exact: true } : null;
78
+ }
79
+ case "eq": {
80
+ const ref = resolveField(t, expr.field);
81
+ if (ref.at === "absent") return FALSE;
82
+ if (ref.at === "scalar") {
83
+ if (expr.value === null) return ref.col.nullable ? { sql: `"${ref.col.name}" IS NULL`, params: [], exact: true } : FALSE;
84
+ if (!kindMatches(ref.col.kind, expr.value)) return FALSE;
85
+ return { sql: `"${ref.col.name}" IS ?`, params: [norm(expr.value)], exact: true };
86
+ }
87
+ const je = `json_extract("${ref.col}", ?)`;
88
+ return expr.value === null ? { sql: `${je} IS NULL`, params: [ref.path], exact: false } : { sql: `${je} IS ?`, params: [ref.path, norm(expr.value)], exact: false };
89
+ }
90
+ case "neq": {
91
+ const ref = resolveField(t, expr.field);
92
+ if (ref.at === "absent") return TRUE;
93
+ if (ref.at === "scalar") {
94
+ if (expr.value === null) return ref.col.nullable ? { sql: `"${ref.col.name}" IS NOT NULL`, params: [], exact: true } : TRUE;
95
+ if (!kindMatches(ref.col.kind, expr.value)) return TRUE;
96
+ return { sql: `"${ref.col.name}" IS NOT ?`, params: [norm(expr.value)], exact: true };
97
+ }
98
+ return null;
99
+ }
100
+ case "lt":
101
+ case "lte":
102
+ case "gt":
103
+ case "gte": {
104
+ if (expr.value === null) return FALSE;
105
+ const op = expr.op === "lt" ? "<" : expr.op === "lte" ? "<=" : expr.op === "gt" ? ">" : ">=";
106
+ const ref = resolveField(t, expr.field);
107
+ if (ref.at === "absent") return FALSE;
108
+ if (ref.at === "scalar") {
109
+ if (ref.col.kind === "real" && typeof expr.value === "number") {
110
+ return { sql: `COALESCE("${ref.col.name}" ${op} ?, 0)`, params: [expr.value], exact: true };
111
+ }
112
+ if (ref.col.kind === "text" && typeof expr.value === "string") return null;
113
+ return FALSE;
114
+ }
115
+ if (typeof expr.value !== "number") return null;
116
+ return { sql: `COALESCE(json_extract("${ref.col}", ?) ${op} ?, 0)`, params: [ref.path, expr.value], exact: false };
117
+ }
118
+ case "in": {
119
+ if (expr.values.length === 0) return FALSE;
120
+ const ref = resolveField(t, expr.field);
121
+ if (ref.at === "absent") return FALSE;
122
+ if (ref.at === "scalar") {
123
+ const usable = expr.values.filter((v) => kindMatches(ref.col.kind, v));
124
+ const parts = [];
125
+ const params = [];
126
+ if (usable.length > 0) {
127
+ parts.push(`COALESCE("${ref.col.name}" IN (${usable.map(() => "?").join(",")}), 0)`);
128
+ params.push(...usable.map(norm));
129
+ }
130
+ if (expr.values.includes(null) && ref.col.nullable) parts.push(`"${ref.col.name}" IS NULL`);
131
+ return parts.length === 0 ? FALSE : { sql: parts.join(" OR "), params, exact: true };
132
+ }
133
+ if (expr.values.some((v) => v === null)) return null;
134
+ return {
135
+ sql: `COALESCE(json_extract("${ref.col}", ?) IN (${expr.values.map(() => "?").join(",")}), 0)`,
136
+ params: [ref.path, ...expr.values.map(norm)],
137
+ exact: false
138
+ };
139
+ }
140
+ default:
141
+ return null;
142
+ }
143
+ }
144
+ function compileOrder(t, orderBy) {
145
+ const parts = [];
146
+ for (const { field, dir } of orderBy) {
147
+ const ref = resolveField(t, field);
148
+ if (ref.at !== "scalar" || ref.col.kind !== "real") return null;
149
+ parts.push(dir === "desc" ? `"${ref.col.name}" DESC NULLS FIRST` : `"${ref.col.name}" ASC NULLS LAST`);
150
+ }
151
+ return parts.join(", ");
152
+ }
153
+ function snapshotSql(t, query, maxParams = Infinity) {
154
+ let sql = `SELECT ${t.plan.columns.map((c) => `"${c.name}"`).join(", ")} FROM "${t.name}"`;
155
+ const params = [];
156
+ let where = query.filter ? compileExpr(t, query.filter) : TRUE;
157
+ if (where && where.params.length + 2 > maxParams) where = null;
158
+ if (query.filter && where) {
159
+ sql += ` WHERE ${where.sql}`;
160
+ params.push(...where.params);
161
+ }
162
+ const order = query.orderBy?.length ? compileOrder(t, query.orderBy) : "";
163
+ if (!where?.exact || order === null) return { sql, params, exact: false };
164
+ if (order) sql += ` ORDER BY ${order}`;
165
+ if (query.limit !== void 0 || query.offset !== void 0) {
166
+ sql += ` LIMIT ? OFFSET ?`;
167
+ params.push(query.limit ?? -1, query.offset ?? 0);
168
+ }
169
+ return { sql, params, exact: true };
170
+ }
171
+ var rowMetaSql = (t, count) => `SELECT "${t.plan.key}" AS id, "_sl_created_at" AS c, "_sl_updated_at" AS u FROM "${t.name}" WHERE "${t.plan.key}" IN (${Array.from({ length: count }, () => "?").join(",")})`;
172
+ var encode = (col, v) => {
173
+ if (col.kind === "json") return v === void 0 ? null : JSON.stringify(v);
174
+ if (v === void 0 || v === null) return null;
175
+ return norm(v);
176
+ };
177
+ function rowParams(t, id, row) {
178
+ if (t.plan.degenerate) return [id, JSON.stringify(row)];
179
+ const rec = row;
180
+ return t.plan.columns.map((c) => c.name === t.plan.key ? id : encode(c, rec[c.name]));
181
+ }
182
+ function updateParams(t, id, row, ts) {
183
+ return [...rowParams(t, id, row).filter((_, i) => t.plan.columns[i].name !== t.plan.key), ts, id];
184
+ }
185
+ function fromRow(t, dbRow) {
186
+ if (t.plan.degenerate) return JSON.parse(dbRow[DEGENERATE_DATA_COLUMN]);
187
+ const row = {};
188
+ for (const col of t.plan.columns) {
189
+ const v = dbRow[col.name];
190
+ if (col.kind === "json") {
191
+ if (v !== null) row[col.name] = JSON.parse(v);
192
+ continue;
193
+ }
194
+ if (v === null) {
195
+ if (col.nullable) row[col.name] = null;
196
+ continue;
197
+ }
198
+ row[col.name] = col.kind === "integer-bool" ? v === 1 : v;
199
+ }
200
+ return row;
201
+ }
202
+ function createTableSql(name, plan) {
203
+ const cols = plan.columns.map((c) => {
204
+ const constraint = c.name === plan.key ? " NOT NULL PRIMARY KEY" : c.optional || c.nullable ? "" : " NOT NULL";
205
+ return `"${c.name}" ${sqlType(c.kind)}${constraint}`;
206
+ });
207
+ return `CREATE TABLE IF NOT EXISTS "${name}" (${cols.join(", ")}, "_sl_created_at" INTEGER NOT NULL, "_sl_updated_at" INTEGER NOT NULL)`;
208
+ }
209
+ var parseFingerprint = (fp) => {
210
+ const parts = fp.split(";");
211
+ const cols = /* @__PURE__ */ new Map();
212
+ for (const p of parts.slice(2)) cols.set(p.slice(0, p.indexOf(":")), p);
213
+ return { head: parts[0], key: parts[1], cols };
214
+ };
215
+ function driftOf(t, stored) {
216
+ const old = parseFingerprint(stored);
217
+ const next = parseFingerprint(t.plan.fingerprint);
218
+ if (old.head !== next.head || old.key !== next.key) return { refuse: "changed its key or shape non-additively" };
219
+ for (const [name, entry] of old.cols) {
220
+ if (next.cols.get(name) !== entry) return { refuse: `changed or removed field '${name}'` };
221
+ }
222
+ const alter = [];
223
+ for (const col of t.plan.columns) {
224
+ if (old.cols.has(col.name)) continue;
225
+ if (!col.optional && !col.nullable) return { refuse: `added required field '${col.name}' (existing rows can't be backfilled)` };
226
+ alter.push(`ALTER TABLE "${t.name}" ADD COLUMN "${col.name}" ${sqlType(col.kind)}`);
227
+ }
228
+ return { alter };
229
+ }
230
+
231
+ // src/index.ts
232
+ var MAX_PARAMS = 100;
233
+ var MAX_COLUMNS = 98;
234
+ function cloudflareCollections(storage, collections) {
235
+ const sql = storage.sql;
236
+ const rows = (query, ...params) => Array.from(sql.exec(query, ...params));
237
+ const openTable = (n, def) => {
238
+ const t = defineTable(n, def);
239
+ if (t.plan.columns.length > MAX_COLUMNS)
240
+ throw new Error(`plans ${t.plan.columns.length} columns; a Durable Object table holds ${MAX_COLUMNS} besides the row timestamps`);
241
+ sql.exec(t.create);
242
+ const stored = rows(META_SQL.get, n)[0]?.fingerprint;
243
+ if (stored === void 0) sql.exec(META_SQL.insert, n, t.plan.fingerprint);
244
+ else if (stored !== t.plan.fingerprint) {
245
+ const drift = driftOf(t, stored);
246
+ if ("refuse" in drift)
247
+ throw new Error(`schema ${drift.refuse} \u2014 rename the collection, or migrate table "${t.name}" and its col_meta row in code`);
248
+ for (const alter of drift.alter) sql.exec(alter);
249
+ sql.exec(META_SQL.update, t.plan.fingerprint, n);
250
+ }
251
+ for (const index of t.indexes) sql.exec(index);
252
+ return t;
253
+ };
254
+ let tables;
255
+ const open = () => {
256
+ if (tables) return tables;
257
+ sql.exec(META_SQL.create);
258
+ tables = /* @__PURE__ */ new Map();
259
+ for (const [n, def] of Object.entries(collections)) {
260
+ if (isCrdtCollection(def)) continue;
261
+ try {
262
+ tables.set(n, openTable(n, def));
263
+ } catch (err) {
264
+ tables.set(n, new SuperLineError("INTERNAL", `cloudflareCollections: collection '${n}' is unusable: ${err.message}`));
265
+ }
266
+ }
267
+ return tables;
268
+ };
269
+ const table = (n) => {
270
+ const t = open().get(n);
271
+ if (t instanceof SuperLineError) throw t;
272
+ return t;
273
+ };
274
+ const readRow = (t, id) => {
275
+ const r = rows(t.sql.get, id)[0];
276
+ return r ? fromRow(t, r) : void 0;
277
+ };
278
+ const listeners = /* @__PURE__ */ new Set();
279
+ const emit = (changes) => {
280
+ for (const c of changes) for (const cb of listeners) cb(c);
281
+ };
282
+ const applyOps = (ops, origin) => {
283
+ const changes = [];
284
+ const ts = Date.now();
285
+ for (const op of ops) {
286
+ const t = table(op.n);
287
+ if (!t) throw new SuperLineError("NOT_FOUND", `Unknown collection: ${op.n}`);
288
+ if (op.op === "insert") {
289
+ if (rows(t.sql.has, op.id).length > 0) throw new SuperLineError("CONFLICT", `Row already exists: ${op.n}/${op.id}`);
290
+ sql.exec(t.sql.insert, ...rowParams(t, op.id, op.row), ts, ts);
291
+ changes.push({ n: op.n, k: "insert", id: op.id, next: op.row, origin });
292
+ } else if (op.op === "update") {
293
+ const prev = readRow(t, op.id);
294
+ if (prev === void 0) throw new SuperLineError("NOT_FOUND", `No row: ${op.n}/${op.id}`);
295
+ sql.exec(t.sql.update, ...updateParams(t, op.id, op.row, ts));
296
+ changes.push({ n: op.n, k: "update", id: op.id, prev, next: op.row, origin });
297
+ } else {
298
+ const prev = readRow(t, op.id);
299
+ if (prev === void 0) continue;
300
+ sql.exec(t.sql.delete, op.id);
301
+ changes.push({ n: op.n, k: "delete", id: op.id, prev, origin });
302
+ }
303
+ }
304
+ return changes;
305
+ };
306
+ return {
307
+ clustering: "relay",
308
+ coordination: "local",
309
+ apply(ops, origin) {
310
+ const changes = storage.transactionSync(() => applyOps(ops, origin));
311
+ emit(changes);
312
+ return changes;
313
+ },
314
+ conditionalApply(conditions, ops, origin) {
315
+ const changes = storage.transactionSync(() => {
316
+ for (const condition of conditions) {
317
+ const t = table(condition.n);
318
+ const row = t ? readRow(t, condition.id) : void 0;
319
+ if (row === void 0 || !matchesFilter(condition.filter, row)) return void 0;
320
+ }
321
+ return applyOps(ops, origin);
322
+ });
323
+ if (!changes) return false;
324
+ emit(changes);
325
+ return true;
326
+ },
327
+ snapshot(n, query) {
328
+ const t = table(n);
329
+ if (!t) return [];
330
+ const q = snapshotSql(t, query, MAX_PARAMS);
331
+ const found = rows(q.sql, ...q.params).map((r) => fromRow(t, r));
332
+ return q.exact ? found : applyQuery(found, query);
333
+ },
334
+ read(n, id) {
335
+ const t = table(n);
336
+ return t ? readRow(t, id) : void 0;
337
+ },
338
+ rowMeta(n, ids) {
339
+ const out = {};
340
+ const t = table(n);
341
+ if (!t) return out;
342
+ for (let i = 0; i < ids.length; i += MAX_PARAMS) {
343
+ const chunk = ids.slice(i, i + MAX_PARAMS);
344
+ for (const r of rows(rowMetaSql(t, chunk.length), ...chunk)) {
345
+ out[r.id] = { createdAt: r.c, updatedAt: r.u };
346
+ }
347
+ }
348
+ return out;
349
+ },
350
+ onChange(cb) {
351
+ listeners.add(cb);
352
+ return () => listeners.delete(cb);
353
+ }
354
+ };
355
+ }
356
+ export {
357
+ cloudflareCollections
358
+ };
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@super-line/collections-cloudflare",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Durable Object SQLite CollectionStore backend for super-line — typed row collections stored in the object that is the node, with IR→SQL snapshot pushdown.",
6
+ "license": "MIT",
7
+ "author": "Mert",
8
+ "keywords": [
9
+ "super-line",
10
+ "collections",
11
+ "cloudflare",
12
+ "durable-objects",
13
+ "sqlite",
14
+ "rows"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/mertdogar/super-line.git",
19
+ "directory": "packages/collections-cloudflare"
20
+ },
21
+ "homepage": "https://mertdogar.github.io/super-line/",
22
+ "bugs": "https://github.com/mertdogar/super-line/issues",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "CHANGELOG.md"
34
+ ],
35
+ "sideEffects": false,
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "peerDependencies": {
40
+ "@super-line/core": ">=0.17.0 <1.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@cloudflare/workers-types": "^5.20261013.1",
44
+ "@super-line/core": "^0.21.0"
45
+ },
46
+ "scripts": {
47
+ "build": "tsup"
48
+ }
6
49
  }