@fabrika/db 0.9.0-dev.37 → 0.9.0-dev.38
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 +4 -4
- package/src/orm.ts +24 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/db",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.38",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"./src/testing.ts",
|
|
@@ -96,9 +96,9 @@
|
|
|
96
96
|
"test": "bun test"
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
100
|
-
"@fabrika/platform": "0.9.0-dev.
|
|
101
|
-
"@fabrika/platform-node": "0.9.0-dev.
|
|
99
|
+
"@fabrika/auth-core": "0.9.0-dev.38",
|
|
100
|
+
"@fabrika/platform": "0.9.0-dev.38",
|
|
101
|
+
"@fabrika/platform-node": "0.9.0-dev.38",
|
|
102
102
|
"kysely": "0.29.6",
|
|
103
103
|
"kysely-postgres-js": "5.0.1",
|
|
104
104
|
"zod": "^3.25.76"
|
package/src/orm.ts
CHANGED
|
@@ -896,7 +896,7 @@ async function claimRows(
|
|
|
896
896
|
const limit = limitOf(options['limit'])
|
|
897
897
|
const visible = visibleFor(model, action)
|
|
898
898
|
const conditions = conditionsOf(context, actionShape(model, visible), options['where'])
|
|
899
|
-
if (scope === undefined) {
|
|
899
|
+
if (scope === undefined || conditions === undefined) {
|
|
900
900
|
return []
|
|
901
901
|
}
|
|
902
902
|
const dialect = dialectOf(context)
|
|
@@ -1246,21 +1246,37 @@ function readOptions(options: unknown, allowed: readonly string[], what: string)
|
|
|
1246
1246
|
return read
|
|
1247
1247
|
}
|
|
1248
1248
|
|
|
1249
|
-
/**
|
|
1250
|
-
|
|
1249
|
+
/**
|
|
1250
|
+
* A list's `where`, parsed, with each value as its dialect binds it (`boundTerms`). Undefined when a condition is an
|
|
1251
|
+
* `in` with an empty list: it matches no row, so the read answers nothing and sends no statement, as an empty `Within`.
|
|
1252
|
+
*/
|
|
1253
|
+
function conditionsOf(context: TableContext, shape: TableShape, where: unknown): readonly (Compare | Contains)[] | undefined {
|
|
1251
1254
|
if (where === undefined) {
|
|
1252
1255
|
return []
|
|
1253
1256
|
}
|
|
1254
|
-
const
|
|
1257
|
+
const parsed = parseList(where, (condition): Compare | Contains | undefined => {
|
|
1255
1258
|
const parts = parseList(condition, (part) => part)
|
|
1256
1259
|
if (parts === undefined || parts.length !== 3) {
|
|
1257
1260
|
throw new QueryRefusedError('invalid_argument', 'where takes [column, operator, value] conditions, each a plain array')
|
|
1258
1261
|
}
|
|
1262
|
+
if (parts[1] === 'in' && parseList(parts[2], (item) => item)?.length === 0) {
|
|
1263
|
+
// The column is still held to the capability's columns: an empty list does not make a hidden one nameable.
|
|
1264
|
+
comparableColumnOf(shape, parts[0], 'compares')
|
|
1265
|
+
return undefined
|
|
1266
|
+
}
|
|
1259
1267
|
return parseCondition(shape, parts[0], parts[1], parts[2])
|
|
1260
1268
|
})
|
|
1261
|
-
if (
|
|
1269
|
+
if (parsed === undefined) {
|
|
1262
1270
|
throw new QueryRefusedError('invalid_argument', 'where takes a plain array of [column, operator, value] conditions')
|
|
1263
1271
|
}
|
|
1272
|
+
const conditions: (Compare | Contains)[] = []
|
|
1273
|
+
for (let index = 0; index < parsed.length; index++) {
|
|
1274
|
+
const condition = parsed[index]
|
|
1275
|
+
if (condition === undefined) {
|
|
1276
|
+
return undefined
|
|
1277
|
+
}
|
|
1278
|
+
conditions[index] = condition
|
|
1279
|
+
}
|
|
1264
1280
|
return boundTerms(context, context.model, conditions)
|
|
1265
1281
|
}
|
|
1266
1282
|
|
|
@@ -1397,7 +1413,7 @@ async function listRows(
|
|
|
1397
1413
|
const position = options['after'] === undefined
|
|
1398
1414
|
? undefined
|
|
1399
1415
|
: keysetAfter(table, order, await openCursor(key, cursorList(table, order), options['after'], order.length))
|
|
1400
|
-
if (scope === undefined) {
|
|
1416
|
+
if (scope === undefined || conditions === undefined) {
|
|
1401
1417
|
return { items: [], next: null }
|
|
1402
1418
|
}
|
|
1403
1419
|
const dialect = dialectOf(context)
|
|
@@ -1441,7 +1457,7 @@ async function allRows(
|
|
|
1441
1457
|
const shape = actionShape(context.model, visible)
|
|
1442
1458
|
const conditions = conditionsOf(context, shape, options['where'])
|
|
1443
1459
|
const order = orderOf(shape, options['orderBy'], tiebreak)
|
|
1444
|
-
if (scope === undefined) {
|
|
1460
|
+
if (scope === undefined || conditions === undefined) {
|
|
1445
1461
|
return []
|
|
1446
1462
|
}
|
|
1447
1463
|
const dialect = dialectOf(context)
|
|
@@ -1472,7 +1488,7 @@ async function countRows(
|
|
|
1472
1488
|
const table = context.model.name
|
|
1473
1489
|
const options = readOptions(input, ['where'], 'count')
|
|
1474
1490
|
const conditions = conditionsOf(context, actionShape(context.model, visible), options['where'])
|
|
1475
|
-
if (scope === undefined) {
|
|
1491
|
+
if (scope === undefined || conditions === undefined) {
|
|
1476
1492
|
return 0
|
|
1477
1493
|
}
|
|
1478
1494
|
const node = aggregateNode(table, { groupBy: [], count: true, sum: [], min: [], max: [] }, conditions, scope)
|