@rljson/db 0.0.11 → 0.0.13

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.
@@ -6,9 +6,58 @@
6
6
 
7
7
  ## Table of contents <!-- omit in toc -->
8
8
 
9
+ - [Tree INSERT operations failing with empty results](#tree-insert-operations-failing-with-empty-results)
9
10
  - [Vscode Windows: Debugging is not working](#vscode-windows-debugging-is-not-working)
10
11
  - [GitHub actions: Cannot find module @rollup/rollup-linux-x64-gnu](#github-actions-cannot-find-module-rolluprollup-linux-x64-gnu)
11
12
 
13
+ ## Tree INSERT operations failing with empty results
14
+
15
+ Date: 2026-01-28
16
+
17
+ ### Symptoms
18
+
19
+ - Tree INSERT operations complete without errors
20
+ - GET queries after INSERT return empty results or only root node
21
+ - Cell length is 1 instead of expected count
22
+ - Navigation stops at root level
23
+
24
+ ### Root Cause
25
+
26
+ The `treeFromObject` function from `@rljson/rljson` v0.0.74+ creates an explicit root node with `id='root'` at the end of the tree array. When inserting an already-isolated subtree (from `isolate()`), this created a double-root structure:
27
+
28
+ ```
29
+ Auto-root (id='root')
30
+ └─ User-root (id='root')
31
+ └─ actual data nodes
32
+ ```
33
+
34
+ When `TreeController` navigates the tree, it stops at the first node with `id='root'` (the auto-root), which has no meaningful data.
35
+
36
+ ### Solution
37
+
38
+ ✅ **Fixed in current version**: The `db.ts` file now calls `treeFromObject` with `skipRootCreation: true` parameter:
39
+
40
+ ```typescript
41
+ const trees = treeFromObject(treeObject, true);
42
+ ```
43
+
44
+ This prevents the automatic root wrapper from being created during INSERT operations.
45
+
46
+ ### Verification
47
+
48
+ Run the tree INSERT tests:
49
+
50
+ ```bash
51
+ pnpm test --run --grep "insert on tree"
52
+ ```
53
+
54
+ All tree INSERT tests should pass:
55
+
56
+ - "insert on tree root node"
57
+ - "insert on tree deeper leaf"
58
+ - "insert on tree simple branch"
59
+ - "insert new child on branch"
60
+
12
61
  ## Vscode Windows: Debugging is not working
13
62
 
14
63
  Date: 2025-03-08
@@ -20,7 +20,7 @@ export type ControllerChildProperty = {
20
20
  * @property {ControllerRunFn<N>} insert - Function to execute a command on the table.
21
21
  * @property {() => Promise<void>} init - Initializes the controller.
22
22
  * @property {() => Promise<T>} table - Retrieves the current state of the table.
23
- * @property {(where: string | { [column: string]: JsonValue }) => Promise<Rljson>} get - Fetches data from the table based on a condition.
23
+ * @property {(where: string | { [column: string]: JsonValue }, filter: Json | undefined, path: string | undefined) => Promise<Rljson>} get - Fetches data from the table based on a condition.
24
24
  * @property {(where: string | Json, filter?: Json) => Promise<Array<{ tableKey: TableKey; ref: Ref }>>} getChildRefs - Retrieves references to child entries in related tables based on a condition.
25
25
  * @param {string | Json }} where - The condition to filter the data.
26
26
  * @returns {Promise<Json[] | null>} A promise that resolves to an array of JSON objects or null if no data is found.
@@ -30,7 +30,7 @@ export interface Controller<T extends TableType, C extends JsonValue, N extends
30
30
  insert: ControllerRunFn<N, C>;
31
31
  init(): Promise<void>;
32
32
  table(): Promise<T>;
33
- get(where: string | Json, filter?: Json): Promise<Rljson>;
33
+ get(where: string | Json, filter?: Json, path?: string): Promise<Rljson>;
34
34
  getChildRefs(where: string | Json, filter?: Json): Promise<ControllerChildProperty[]>;
35
35
  filterRow(row: Json, key: string, value: JsonValue): Promise<boolean>;
36
36
  contentType(): ContentType;
@@ -0,0 +1,18 @@
1
+ import { Json } from '@rljson/json';
2
+ import { InsertCommand, InsertHistoryRow, Ref, Rljson, TableKey, Tree, TreesTable } from '@rljson/rljson';
3
+ import { Core } from '../core.ts';
4
+ import { Cell } from '../db.ts';
5
+ import { BaseController } from './base-controller.ts';
6
+ import { Controller, ControllerChildProperty } from './controller.ts';
7
+ export declare class TreeController<N extends string, C extends Tree> extends BaseController<TreesTable, C> implements Controller<TreesTable, C, N> {
8
+ protected readonly _core: Core;
9
+ protected readonly _tableKey: TableKey;
10
+ constructor(_core: Core, _tableKey: TableKey);
11
+ init(): Promise<void>;
12
+ insert(command: InsertCommand, value: Tree, origin?: Ref): Promise<InsertHistoryRow<any>[]>;
13
+ get(where: string | Json, filter?: Json, path?: string): Promise<Rljson>;
14
+ buildTreeFromTrees(trees: Tree[]): Promise<Json>;
15
+ buildCellsFromTree(trees: Tree[]): Promise<Cell[]>;
16
+ getChildRefs(where: string | Json, filter?: Json): Promise<ControllerChildProperty[]>;
17
+ filterRow(): Promise<boolean>;
18
+ }
package/dist/db.d.ts CHANGED
@@ -131,12 +131,6 @@ export declare class Db {
131
131
  * @throws {Error} If the InsertHistory table does not exist
132
132
  */
133
133
  private _writeInsertHistory;
134
- /**
135
- * Add a head revision for a cake
136
- * @param cakeKey - The cake table key
137
- * @param cakeRef - The cake reference
138
- */
139
- addHeadRevision(cakeKey: string, cakeRef: Ref): Promise<InsertHistoryRow<string>[]>;
140
134
  /**
141
135
  * Add a multiEdit
142
136
  * @param cakeKey - The cake table key