@lunora/d1 1.0.0-alpha.4 → 1.0.0-alpha.40

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.
@@ -1,4 +1,6 @@
1
+ import { LunoraError } from '@lunora/errors';
1
2
  import { runD1GlobalTableMigrations } from './createD1CtxDb-BMR8J0dT.mjs';
3
+ import { quoteIdentifier } from './quoteIdentifier-B-ZeSe1V.mjs';
2
4
  import { decodeGlobalRow } from '@lunora/sql-store';
3
5
 
4
6
  const ensureGlobalTables = (exec, schema) => runD1GlobalTableMigrations(exec, schema);
@@ -6,7 +8,6 @@ const DEFAULT_PAGE_SIZE = 50;
6
8
  const MAX_PAGE_SIZE = 500;
7
9
  const DEFAULT_FACET_LIMIT = 30;
8
10
  const MAX_FACET_LIMIT = 200;
9
- const quoteIdentifier = (name) => `"${name.replaceAll('"', '""')}"`;
10
11
  const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
11
12
  const INTERNAL_TABLE = /^sqlite_|^_cf_|^d1_|^__cdc|__agg_|__rank_|__fts_/u;
12
13
  const isInternalTable = (name) => INTERNAL_TABLE.test(name);
@@ -28,7 +29,10 @@ const buildEqPredicate = (schema, table, displayColumns, filters) => {
28
29
  const params = [];
29
30
  for (const filter of filters) {
30
31
  if (!displayColumns.includes(filter.column)) {
31
- throw Object.assign(new Error(`unknown column: ${filter.column}`), { code: "UNKNOWN_COLUMN", name: "LunoraError", status: 404 });
32
+ throw new LunoraError("UNKNOWN_COLUMN", `unknown column: ${filter.column}`, { status: 404 });
33
+ }
34
+ if (schema.tables[table] === void 0 && SENSITIVE_COLUMN.test(filter.column)) {
35
+ throw new LunoraError("FORBIDDEN", `cannot filter on a redacted column: ${filter.column}`, { status: 403 });
32
36
  }
33
37
  const quoted = quoteIdentifier(physicalColumnName(schema, table, filter.column));
34
38
  if (filter.value === null || filter.value === void 0) {
@@ -89,7 +93,7 @@ const readGlobalTablePage = async (exec, schema, options) => {
89
93
  await ensureGlobalTables(exec, schema);
90
94
  const tableNames = await listTableNames(exec);
91
95
  if (!tableNames.includes(table)) {
92
- throw Object.assign(new Error(`unknown table: ${table}`), { code: "UNKNOWN_TABLE", name: "LunoraError", status: 404 });
96
+ throw new LunoraError("UNKNOWN_TABLE", `unknown table: ${table}`, { status: 404 });
93
97
  }
94
98
  const limit = clamp(Math.trunc(options.limit ?? DEFAULT_PAGE_SIZE), 1, MAX_PAGE_SIZE);
95
99
  const offset = Math.max(0, Math.trunc(options.offset ?? 0));
@@ -109,11 +113,11 @@ const facetGlobalColumn = async (exec, schema, options) => {
109
113
  await ensureGlobalTables(exec, schema);
110
114
  const tableNames = await listTableNames(exec);
111
115
  if (!tableNames.includes(table)) {
112
- throw Object.assign(new Error(`unknown table: ${table}`), { code: "UNKNOWN_TABLE", name: "LunoraError", status: 404 });
116
+ throw new LunoraError("UNKNOWN_TABLE", `unknown table: ${table}`, { status: 404 });
113
117
  }
114
118
  const columns = await resolveColumns(exec, schema, table);
115
119
  if (!columns.includes(column)) {
116
- throw Object.assign(new Error(`unknown column: ${column}`), { code: "UNKNOWN_COLUMN", name: "LunoraError", status: 404 });
120
+ throw new LunoraError("UNKNOWN_COLUMN", `unknown column: ${column}`, { status: 404 });
117
121
  }
118
122
  const quoted = quoteIdentifier(table);
119
123
  const predicate = buildEqPredicate(schema, table, columns, options.filters);
@@ -0,0 +1,3 @@
1
+ const quoteIdentifier = (name) => `"${name.replaceAll('"', '""')}"`;
2
+
3
+ export { quoteIdentifier };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/d1",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.40",
4
4
  "description": "D1 adapter for Lunora .global() tables, wrapping the Sessions API for read-your-writes",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -25,7 +25,7 @@
25
25
  "directory": "packages/d1"
26
26
  },
27
27
  "files": [
28
- "dist",
28
+ "./dist",
29
29
  "README.md",
30
30
  "LICENSE.md",
31
31
  "__assets__"
@@ -50,8 +50,9 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@lunora/do": "1.0.0-alpha.4",
54
- "@lunora/sql-store": "1.0.0-alpha.4",
53
+ "@lunora/do": "1.0.0-alpha.44",
54
+ "@lunora/errors": "1.0.0-alpha.8",
55
+ "@lunora/sql-store": "1.0.0-alpha.41",
55
56
  "drizzle-orm": "^0.45.2"
56
57
  },
57
58
  "engines": {