@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.
- package/LICENSE.md +6 -0
- package/__assets__/package-og.svg +1 -1
- package/dist/dialect.d.mts +29 -27
- package/dist/dialect.d.ts +29 -27
- package/dist/dialect.mjs +2 -1
- package/dist/index.d.mts +141 -132
- package/dist/index.d.ts +141 -132
- package/dist/index.mjs +4 -4
- package/dist/packem_shared/{D1Client-DA3flo1o.mjs → D1Client-DSj8p7c4.mjs} +24 -30
- package/dist/packem_shared/{MigrationRunner-BkEwQ-Ya.mjs → MigrationRunner-A-o1LTKj.mjs} +46 -26
- package/dist/packem_shared/{exportGlobalRows-BGCPm_nA.mjs → exportGlobalRows-q0RgCLPM.mjs} +13 -7
- package/dist/packem_shared/{facetGlobalColumn-C6u_WMIY.mjs → facetGlobalColumn-DnglIe4P.mjs} +9 -5
- package/dist/packem_shared/quoteIdentifier-B-ZeSe1V.mjs +3 -0
- package/package.json +5 -4
package/dist/packem_shared/{facetGlobalColumn-C6u_WMIY.mjs → facetGlobalColumn-DnglIe4P.mjs}
RENAMED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/d1",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
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.
|
|
54
|
-
"@lunora/
|
|
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": {
|