@fabrika/app 0.9.0-dev.5 → 0.9.0-dev.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/app",
3
- "version": "0.9.0-dev.5",
3
+ "version": "0.9.0-dev.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -109,14 +109,14 @@
109
109
  "test": "bun test --path-ignore-patterns='src/react/**' && bun test --isolate src/react"
110
110
  },
111
111
  "dependencies": {
112
- "@fabrika/auth": "0.9.0-dev.5",
113
- "@fabrika/auth-core": "0.9.0-dev.5",
114
- "@fabrika/db": "0.9.0-dev.5",
115
- "@fabrika/email": "0.9.0-dev.5",
116
- "@fabrika/jwks": "0.9.0-dev.5",
117
- "@fabrika/platform": "0.9.0-dev.5",
118
- "@fabrika/platform-node": "0.9.0-dev.5",
119
- "@fabrika/proxy-core": "0.9.0-dev.5",
112
+ "@fabrika/auth": "0.9.0-dev.6",
113
+ "@fabrika/auth-core": "0.9.0-dev.6",
114
+ "@fabrika/db": "0.9.0-dev.6",
115
+ "@fabrika/email": "0.9.0-dev.6",
116
+ "@fabrika/jwks": "0.9.0-dev.6",
117
+ "@fabrika/platform": "0.9.0-dev.6",
118
+ "@fabrika/platform-node": "0.9.0-dev.6",
119
+ "@fabrika/proxy-core": "0.9.0-dev.6",
120
120
  "altcha-lib": "2.6.0",
121
121
  "jose": "^5.9.0"
122
122
  },
package/skill/SKILL.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: fabrika-app
3
- version: 0.9.0-dev.5
3
+ version: 0.9.0-dev.6
4
4
  description: >
5
5
  How to write and change a Fabrika application: src/vocabulary.ts, db/migrations/, src/db/tables.ts, the
6
6
  slices' endpoints.ts with their handlers, fabrika.contract.ts, jobs, files, webhooks, share links, connectors
@@ -19,20 +19,20 @@ the SPA is added with it.
19
19
  "test": "bun test --isolate"
20
20
  },
21
21
  "dependencies": {
22
- "@fabrika/app": "0.9.0-dev.5",
23
- "@fabrika/db": "0.9.0-dev.5",
24
- "@fabrika/provider-zerops": "0.9.0-dev.5",
25
- "@fabrika/proxy-core": "0.9.0-dev.5",
26
- "@fabrika/ui": "0.9.0-dev.5",
22
+ "@fabrika/app": "0.9.0-dev.6",
23
+ "@fabrika/db": "0.9.0-dev.6",
24
+ "@fabrika/provider-zerops": "0.9.0-dev.6",
25
+ "@fabrika/proxy-core": "0.9.0-dev.6",
26
+ "@fabrika/ui": "0.9.0-dev.6",
27
27
  "kysely": "0.29.6",
28
28
  "react": "^19.0.0",
29
29
  "react-dom": "^19.0.0",
30
30
  "zod": "^3.25.76"
31
31
  },
32
32
  "devDependencies": {
33
- "@fabrika/check": "0.9.0-dev.5",
34
- "@fabrika/cli": "0.9.0-dev.5",
35
- "@fabrika/platform": "0.9.0-dev.5",
33
+ "@fabrika/check": "0.9.0-dev.6",
34
+ "@fabrika/cli": "0.9.0-dev.6",
35
+ "@fabrika/platform": "0.9.0-dev.6",
36
36
  "@happy-dom/global-registrator": "^20.11.2",
37
37
  "@types/bun": "^1.4.3",
38
38
  "@types/react": "^19.0.0",
@@ -15,12 +15,11 @@ import {
15
15
  OPS_EMPTY_TABLE_HASH,
16
16
  OPS_STALE_STATUS,
17
17
  type OpsDataRefusal,
18
- opsDumpColumnProjection,
19
18
  type OpsDumpCursor,
19
+ type OpsDumpPageRow,
20
20
  type OpsDumpSchemaEntry,
21
21
  type OpsDumpTable,
22
22
  type OpsDumpTablePlan,
23
- type OpsDumpValue,
24
23
  opsDumpValueBinding,
25
24
  type OpsExportBegin,
26
25
  type OpsExportComplete,
@@ -33,7 +32,7 @@ import {
33
32
  parseOpsExportCompleteAck,
34
33
  parseOpsExportPartAck,
35
34
  planOpsDump,
36
- readOpsDumpValue,
35
+ readOpsDumpPage,
37
36
  sha256Hex,
38
37
  } from '@fabrika/auth-core'
39
38
  import type { SqliteValue } from '@fabrika/db/sqlite'
@@ -428,29 +427,10 @@ function rowBounds(storage: Storage, table: OpsDumpTablePlan, after: string | nu
428
427
  })
429
428
  }
430
429
 
431
- interface ReadValues {
432
- readonly rowid: string
433
- readonly values: readonly OpsDumpValue[]
434
- }
435
-
436
- /**
437
- * The next `limit` rows: each its rowid as decimal text, then the rowid and every column through the wire's projection.
438
- * The column-name list of the common table expression names every result column, which an expression alone does not.
439
- */
440
- function readRows(storage: Storage, table: OpsDumpTablePlan, after: string | null, limit: number): ReadValues[] {
441
- const keyset = quoted(table.keyset)
442
- const names = ['k', 'r', ...table.columns.flatMap((_, index) => [`t${index}`, `v${index}`])]
443
- const projections = [keyset, `CAST(${keyset} AS TEXT)`, ...table.columns.map(opsDumpColumnProjection)]
430
+ /** The next `limit` rows: each its rowid as decimal text, then the rowid and every column through the wire's projection. */
431
+ function readRows(storage: Storage, table: OpsDumpTablePlan, after: string | null, limit: number): OpsDumpPageRow[] {
444
432
  const condition = keysetCondition(table, after)
445
- const query = `WITH page(${names.join(', ')}) AS (SELECT ${projections.join(', ')} FROM ${source(table)} ${condition.sql}
446
- ORDER BY ${keyset} LIMIT ${limit}) SELECT ${names.slice(1).join(', ')} FROM page ORDER BY k`
447
- return storage.sql.exec(query, ...condition.bindings).toArray().map((row) => {
448
- const rowid = readOpsDumpValue('integer', row['r'])
449
- if (rowid === null || rowid.type !== 'integer') {
450
- throw new Error('a rowid reads as an integer')
451
- }
452
- return { rowid: rowid.value, values: [rowid, ...table.columns.map((_, index) => readOpsDumpValue(row[`t${index}`], row[`v${index}`]))] }
453
- })
433
+ return readOpsDumpPage((query) => storage.sql.exec(query, ...condition.bindings).toArray(), table, condition.sql, limit)
454
434
  }
455
435
 
456
436
  /** The tables a part finished, with their counts and hashes, and the cursor where the next part starts. */
@@ -19,10 +19,10 @@ import {
19
19
  type OpsDataRefusal,
20
20
  type OpsDataRefusalReason,
21
21
  type OpsDumpBinding,
22
- opsDumpColumnProjection,
23
22
  type OpsDumpCursor,
24
23
  type OpsDumpLine,
25
24
  type OpsDumpManifest,
25
+ opsDumpRowidSql,
26
26
  type OpsDumpSchema,
27
27
  type OpsDumpSchemaColumn,
28
28
  type OpsDumpSchemaEntry,
@@ -48,7 +48,7 @@ import {
48
48
  parseOpsImportVerifyAck,
49
49
  planOpsDump,
50
50
  readOpsDumpManifest,
51
- readOpsDumpValue,
51
+ readOpsDumpPage,
52
52
  sha256Hex,
53
53
  } from '@fabrika/auth-core'
54
54
  import type { SqliteStorage, SqliteValue } from '@fabrika/db/sqlite'
@@ -330,9 +330,11 @@ async function loadPart(target: ImportTarget, source: OpsDumpSource, manifest: O
330
330
  /** Writes one row; answers whether it has a deferred key for the link pass to set. */
331
331
  function insertRow(storage: SqliteStorage, table: OpsDumpTablePlan, row: readonly OpsDumpValue[]): boolean {
332
332
  const [rowid, ...values] = row
333
- const key = opsDumpValueBinding(rowid ?? null)
333
+ // Inline, so a row of a table at workerd's column limit binds no more parameters than its columns.
334
+ const key = opsDumpRowidSql(rowid ?? null)
334
335
  const columns: string[] = [table.keyset]
335
- const bindings = [key]
336
+ const keys: string[] = [key]
337
+ const bindings: OpsDumpBinding[] = []
336
338
  let waits = false
337
339
  for (const [index, column] of table.columns.entries()) {
338
340
  const value = values[index] ?? null
@@ -342,16 +344,18 @@ function insertRow(storage: SqliteStorage, table: OpsDumpTablePlan, row: readonl
342
344
  }
343
345
  const deferred = table.deferred.includes(column)
344
346
  waits ||= deferred && value !== null
347
+ const binding = opsDumpValueBinding(deferred ? null : value)
345
348
  columns.push(column)
346
- bindings.push(opsDumpValueBinding(deferred ? null : value))
349
+ keys.push(binding.sql)
350
+ bindings.push(binding)
347
351
  }
348
352
  if (table.name === SQLITE_SEQUENCE) {
349
353
  // Loading an AUTOINCREMENT table writes its own counter row; the source's row replaces it, whichever table loads first.
350
354
  const name = opsDumpValueBinding(values[0] ?? null)
351
- storage.sql.exec(`DELETE FROM ${SQLITE_SEQUENCE} WHERE rowid = ${key.sql} OR name = ${name.sql}`, ...params([key, name]))
355
+ storage.sql.exec(`DELETE FROM ${SQLITE_SEQUENCE} WHERE rowid = ${key} OR name = ${name.sql}`, ...params([name]))
352
356
  }
353
357
  storage.sql.exec(
354
- `INSERT INTO ${quote(table.name)} (${columns.map(quote).join(', ')}) VALUES (${bindings.map((binding) => binding.sql).join(', ')})`,
358
+ `INSERT INTO ${quote(table.name)} (${columns.map(quote).join(', ')}) VALUES (${keys.join(', ')})`,
355
359
  ...params(bindings),
356
360
  )
357
361
  return waits
@@ -396,12 +400,11 @@ async function linkPart(target: ImportTarget, source: OpsDumpSource, manifest: O
396
400
  continue
397
401
  }
398
402
  const sets = deferred.map(({ column, value }) => ({ column, binding: opsDumpValueBinding(value) }))
399
- const key = opsDumpValueBinding(rowid ?? null)
400
403
  storage.sql.exec(
401
404
  `UPDATE ${quote(table.name)} SET ${sets.map(({ column, binding }) => `${quote(column)} = ${binding.sql}`).join(', ')} WHERE ${
402
405
  quote(table.keyset)
403
- } = ${key.sql}`,
404
- ...params([...sets.map(({ binding }) => binding), key]),
406
+ } = ${opsDumpRowidSql(rowid ?? null)}`,
407
+ ...params(sets.map(({ binding }) => binding)),
405
408
  )
406
409
  linked++
407
410
  }
@@ -495,20 +498,9 @@ function cursorKey(cursor: OpsDumpCursor): string {
495
498
 
496
499
  /** One keyset page of `table` after the rowid `after`: each row its rowid, then its columns, as the producer reads them. */
497
500
  function readPage(storage: SqliteStorage, table: OpsDumpTablePlan, after: string | null): (readonly OpsDumpValue[])[] {
498
- const keyset = quote(table.keyset)
499
- // The CTE names each projected column, so no two result columns share a name whatever the table's columns are called.
500
- const names = table.columns.flatMap((_, index) => [`t${index}`, `v${index}`])
501
- const select = [keyset, `CAST(${keyset} AS TEXT)`, ...table.columns.map((column) => opsDumpColumnProjection(column))].join(', ')
502
- const where = after === null ? '' : ` WHERE ${keyset} > CAST(? AS INTEGER)`
503
- // Qualified, so a table named `page` is not the CTE itself.
504
- const query =
505
- `WITH page(r, k, ${names.join(', ')}) AS (SELECT ${select} FROM main.${quote(table.name)}${where} ORDER BY ${keyset} LIMIT ${OPS_DUMP_PAGE_ROWS}) `
506
- + `SELECT k, ${names.join(', ')} FROM page ORDER BY r`
507
- const rows = after === null ? storage.sql.exec(query).toArray() : storage.sql.exec(query, after).toArray()
508
- return rows.map((row) => [
509
- readOpsDumpValue('integer', row['k']),
510
- ...table.columns.map((_, index) => readOpsDumpValue(row[`t${index}`], row[`v${index}`])),
511
- ])
501
+ const condition = after === null ? '' : `WHERE ${quote(table.keyset)} > CAST(? AS INTEGER)`
502
+ const query = (sql: string) => after === null ? storage.sql.exec(sql).toArray() : storage.sql.exec(sql, after).toArray()
503
+ return readOpsDumpPage(query, table, condition, OPS_DUMP_PAGE_ROWS).map((row) => row.values)
512
504
  }
513
505
 
514
506
  /**