@crombolo/data 0.18.0 → 0.19.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/data",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "SQLite and Postgres storage for crombolo: schema, migrations and repositories.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -28,6 +28,6 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@crombolo/core": "0.18.0"
31
+ "@crombolo/core": "0.19.0"
32
32
  }
33
33
  }
@@ -363,10 +363,16 @@ export class DocumentRepository {
363
363
  return this.#load(node)
364
364
  }
365
365
 
366
- async children(parentKey: string | null, skip: number, take: number): Promise<Page<NodeRow>> {
366
+ /** A page of children, leaving out `excludeKeys` from the page and the total alike. */
367
+ async children(
368
+ parentKey: string | null,
369
+ skip: number,
370
+ take: number,
371
+ excludeKeys: readonly string[] = [],
372
+ ): Promise<Page<NodeRow>> {
367
373
  const parentId = parentKey ? (await this.#nodes.byKey(parentKey))?.id : SystemNodes.Root
368
374
  if (parentId === undefined) return { total: 0, items: [] }
369
- return this.#nodes.children(parentId, this.objectType, skip, take)
375
+ return this.#nodes.children(parentId, this.objectType, skip, take, false, excludeKeys)
370
376
  }
371
377
 
372
378
  /** The recycle bin's tree: trashed documents, top level being what was trashed directly. */
@@ -133,17 +133,29 @@ export class NodeRepository {
133
133
  skip: number,
134
134
  take: number,
135
135
  trashed = false,
136
+ excludeKeys: readonly string[] = [],
136
137
  ): Promise<Page<NodeRow>> {
138
+ const where = `parent_id = ? AND node_object_type = ? AND trashed = ?${
139
+ excludeKeys.length > 0
140
+ ? ` AND unique_id NOT IN (${excludeKeys.map(() => '?').join(', ')})`
141
+ : ''
142
+ }`
143
+ const params = [
144
+ parentId,
145
+ objectType,
146
+ this.#db.dialect.boolValue(trashed),
147
+ ...excludeKeys.map(normaliseUuid),
148
+ ]
137
149
  const totals = await this.#db.query<{ n: number }>(
138
- 'SELECT COUNT(*) AS n FROM node WHERE parent_id = ? AND node_object_type = ? AND trashed = ?',
139
- [parentId, objectType, this.#db.dialect.boolValue(trashed)],
150
+ `SELECT COUNT(*) AS n FROM node WHERE ${where}`,
151
+ params,
140
152
  )
141
153
  const rows = await this.#db.query(
142
154
  `SELECT ${NODE_COLUMNS} FROM node
143
- WHERE parent_id = ? AND node_object_type = ? AND trashed = ?
155
+ WHERE ${where}
144
156
  ORDER BY sort_order, id
145
157
  LIMIT ? OFFSET ?`,
146
- [parentId, objectType, this.#db.dialect.boolValue(trashed), take, skip],
158
+ [...params, take, skip],
147
159
  )
148
160
  return { total: Number(totals[0]?.n ?? 0), items: rows.map(mapNode) }
149
161
  }