@venizia/ignis-connectors 0.4.7-2 → 0.4.7-4
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/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts +9 -1
- package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts.map +1 -1
- package/dist/esm/relational/core/repositories/sqls/recursive-tree.js +18 -3
- package/dist/esm/relational/core/repositories/sqls/recursive-tree.js.map +1 -1
- package/package.json +4 -4
|
@@ -19,6 +19,14 @@ export interface IRecursiveTreeOptions {
|
|
|
19
19
|
* what is meant) and an empty list is refused, because it would silently return nothing.
|
|
20
20
|
*/
|
|
21
21
|
rootId?: string | ReadonlyArray<string>;
|
|
22
|
+
/**
|
|
23
|
+
* `'all'` makes every row a root of the walk, narrowed only by `filter` and `anchorFilter`. Use it when the
|
|
24
|
+
* closure of every row is wanted, not the tree under one root. Cannot be combined with `rootId`. A row shows up
|
|
25
|
+
* once per root that reaches it: in a DOWN walk a node at depth 3 below the top is returned four times (as its own
|
|
26
|
+
* root and under each of its three ancestors), each time with its own `depth`; select `depth = 0` to get
|
|
27
|
+
* each row once. Works for both directions; an UP walk then returns every row with all of its ancestors.
|
|
28
|
+
*/
|
|
29
|
+
start?: 'all';
|
|
22
30
|
direction: TRecursiveTreeDirection;
|
|
23
31
|
/**
|
|
24
32
|
* Counts EDGES, not rows: the root is at depth 0, so `N` returns up to `N+1` rows.
|
|
@@ -68,7 +76,7 @@ export interface IRecursiveTreeOptions {
|
|
|
68
76
|
export declare class RecursiveTreeSql {
|
|
69
77
|
private static assertValidIdentifier;
|
|
70
78
|
static walk(opts: IRecursiveTreeOptions): SQL;
|
|
71
|
-
/** The anchor's root match: one id keeps the SQL it always had; several ids are an IN list; none is every row without a parent. */
|
|
79
|
+
/** The anchor's root match: one id keeps the SQL it always had; several ids are an IN list; none is every row without a parent; `start: 'all'` is every row. */
|
|
72
80
|
private static compileRootCondition;
|
|
73
81
|
/** See {@link RecursiveTreeSql} for why there is no separate `engine` option. */
|
|
74
82
|
private static detectEngine;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursive-tree.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/sqls/recursive-tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,KAAK,EAAQ,GAAG,EAAE,MAAM,aAAa,CAAC;AAK7C,sIAAsI;AACtI,qBAAa,uBAAuB;IAClC,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ;IAC1B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAC9B,MAAM,CAAC,QAAQ,CAAC,UAAU,cAAiC;IAE3D,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;CAG3C;AAED,MAAM,MAAM,uBAAuB,GAAG,WAAW,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAoBlF,MAAM,WAAW,qBAAqB;IACpC,mFAAmF;IACnF,IAAI,EAAE,MAAM,CAAC;IAEb,mIAAmI;IACnI,KAAK,EAAE,OAAO,CAAC;IAEf;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"recursive-tree.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/sqls/recursive-tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,KAAK,EAAQ,GAAG,EAAE,MAAM,aAAa,CAAC;AAK7C,sIAAsI;AACtI,qBAAa,uBAAuB;IAClC,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ;IAC1B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAC9B,MAAM,CAAC,QAAQ,CAAC,UAAU,cAAiC;IAE3D,MAAM,CAAC,OAAO,CAA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eSql {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
static walk(opts) {
|
|
44
|
-
const { name, table, rootId, direction, maxDepth, idColumn = 'id', parentColumn = 'parent_id', columns = [], filter, anchorFilter, recursiveFilter, trackPath = false, startDepth = 0, } = opts;
|
|
44
|
+
const { name, table, rootId, start, direction, maxDepth, idColumn = 'id', parentColumn = 'parent_id', columns = [], filter, anchorFilter, recursiveFilter, trackPath = false, startDepth = 0, } = opts;
|
|
45
45
|
RecursiveTreeSql.assertValidIdentifier({ field: 'name', value: name });
|
|
46
46
|
RecursiveTreeSql.assertValidIdentifier({ field: 'idColumn', value: idColumn });
|
|
47
47
|
RecursiveTreeSql.assertValidIdentifier({ field: 'parentColumn', value: parentColumn });
|
|
@@ -87,6 +87,7 @@ export class RecursiveTreeSql {
|
|
|
87
87
|
: { basePathColumns: sql ``, recursivePathColumns: sql `` };
|
|
88
88
|
const rootCondition = RecursiveTreeSql.compileRootCondition({
|
|
89
89
|
rootId,
|
|
90
|
+
start,
|
|
90
91
|
direction,
|
|
91
92
|
idIdentifier,
|
|
92
93
|
parentIdentifier,
|
|
@@ -107,9 +108,23 @@ export class RecursiveTreeSql {
|
|
|
107
108
|
const recursiveCase = sql `SELECT ${recursiveColumnList}, r.depth + 1${recursivePathColumns} FROM ${tableIdentifier} t JOIN ${cteIdentifier} r ON ${joinCondition} WHERE r.depth + 1 <= ${maxDepth}${cycleGuard}${bothTerms}${extraFilter}`;
|
|
108
109
|
return sql `WITH RECURSIVE ${cteIdentifier} AS (${baseCase} UNION ALL ${recursiveCase})`;
|
|
109
110
|
}
|
|
110
|
-
/** The anchor's root match: one id keeps the SQL it always had; several ids are an IN list; none is every row without a parent. */
|
|
111
|
+
/** The anchor's root match: one id keeps the SQL it always had; several ids are an IN list; none is every row without a parent; `start: 'all'` is every row. */
|
|
111
112
|
static compileRootCondition(opts) {
|
|
112
|
-
const { rootId, direction, idIdentifier, parentIdentifier } = opts;
|
|
113
|
+
const { rootId, start, direction, idIdentifier, parentIdentifier } = opts;
|
|
114
|
+
if (start !== undefined) {
|
|
115
|
+
if (start !== 'all') {
|
|
116
|
+
throw getError({
|
|
117
|
+
message: `[RecursiveTreeSql.walk] Invalid 'start' | Expected 'all' or no value | Got: ${String(start)}`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (rootId !== undefined) {
|
|
121
|
+
throw getError({
|
|
122
|
+
message: "[RecursiveTreeSql.walk] Invalid 'start' | 'all' makes every row a root, so it cannot be combined with 'rootId'",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
// true for every row; `1 = 1` rather than TRUE because it reads the same on Postgres and on every SQLite version
|
|
126
|
+
return sql `1 = 1`;
|
|
127
|
+
}
|
|
113
128
|
if (rootId === undefined) {
|
|
114
129
|
if (direction === RecursiveTreeDirections.UP) {
|
|
115
130
|
throw getError({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursive-tree.js","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/sqls/recursive-tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,sIAAsI;AACtI,MAAM,OAAO,uBAAuB;aAClB,OAAE,GAAG,IAAI,CAAC;aACV,SAAI,GAAG,MAAM,CAAC;aACd,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAE3D,MAAM,CAAC,OAAO,CAAC,SAAiB;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACxC,CAA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,qBAAqB,OAAO,YAAY,OAAO,qBAAqB,yBAAyB;oBACtH,oBAAoB,EAAE,GAAG,CAAA,iBAAiB,YAAY,OAAO,qBAAqB,2BAA2B,qBAAqB,SAAS,YAAY,OAAO,qBAAqB,mBAAmB;iBACvM,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,QAAQ,CAAC;oBACb,OAAO,EAAE,mDAAmD,MAAM,EAAE;iBACrE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { Name, SQL } from 'drizzle-orm';\nimport { getTableName, is, sql, Table } from 'drizzle-orm';\nimport { getTableConfig, PgTable } from 'drizzle-orm/pg-core';\nimport { SQLiteTable } from 'drizzle-orm/sqlite-core';\n\n/** Walk direction relative to `rootId`: DOWN follows `parentColumn -> idColumn` (descendants), UP follows the reverse (ancestors). */\nexport class RecursiveTreeDirections {\n static readonly UP = 'UP';\n static readonly DOWN = 'DOWN';\n static readonly SCHEME_SET = new Set([this.UP, this.DOWN]);\n\n static isValid(direction: string): boolean {\n return this.SCHEME_SET.has(direction);\n }\n}\n\nexport type TRecursiveTreeDirection = TConstValue<typeof RecursiveTreeDirections>;\n\n/** Internal only - not part of {@link IRecursiveTreeOptions}. Derived from `table`, never accepted as an option. */\nclass RecursiveTreeEngines {\n static readonly POSTGRES = 'POSTGRES';\n static readonly SQLITE = 'SQLITE';\n static readonly SCHEME_SET = new Set([this.POSTGRES, this.SQLITE]);\n}\n\ntype TRecursiveTreeEngine = TConstValue<typeof RecursiveTreeEngines>;\n\n/** A SQL identifier is safe to splice only after it matches this allowlist - see {@link RecursiveTreeSql.assertValidIdentifier}. */\nconst IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/**\n * ASCII Unit Separator (0x1F) - chosen because it does not occur in real ids, unlike `/` or `,`.\n * See {@link RecursiveTreeSql} for the exactness limitation this relies on.\n */\nconst SQLITE_PATH_DELIMITER = sql.raw('char(31)');\n\nexport interface IRecursiveTreeOptions {\n /** CTE name the caller references in the SELECT it writes around this fragment. */\n name: string;\n\n /** Runtime-checked with `is(table, Table)`; also the sole dialect selector (Postgres vs SQLite) - see {@link RecursiveTreeSql}. */\n table: unknown;\n\n /**\n * Where the walk starts: one id, several ids (each is a root of the walk), or none. With no root a DOWN walk\n * starts from every row whose parent column is NULL; an UP walk needs a root (the ancestors of every row is never\n * what is meant) and an empty list is refused, because it would silently return nothing.\n */\n rootId?: string | ReadonlyArray<string>;\n direction: TRecursiveTreeDirection;\n\n /**\n * Counts EDGES, not rows: the root is at depth 0, so `N` returns up to `N+1` rows.\n * No default - `0` type-checks but silently produces an empty result, so `walk` throws at\n * runtime for `maxDepth <= 0`.\n */\n maxDepth: number;\n idColumn?: string;\n parentColumn?: string;\n\n /** Extra columns, beyond `idColumn`/`parentColumn`, carried into every row of the walk. */\n columns?: string[];\n\n /**\n * ANDed into BOTH terms (the anchor and the recursive one): a row it rejects is not in the walk and its subtree is\n * cut off. Build it with Drizzle's own `sql` tag and name the table by its alias `t`, which both terms use for it when this option is set:\n * `sql\\`t.deleted_at IS NULL\\``. An unqualified column is ambiguous in the recursive term when the walk carries it too\n * (`id`, `parent_id`, anything in `columns`). It is the same as passing the fragment as {@link anchorFilter} and as\n * {@link recursiveFilter}, written once.\n */\n filter?: SQL;\n\n /**\n * ANDed into the anchor term's WHERE clause, next to the root match - build it with\n * Drizzle's own `sql` tag, columns unqualified. Together with {@link recursiveFilter} it keeps a\n * row out of the walk at both ends, e.g. `sql\\`deleted_at IS NULL\\`` on each term.\n *\n * `walk` takes a table, not a model, so it never applies a model's soft delete or `access` scope by\n * itself: both terms are filtered only by what the caller passes here and in `recursiveFilter`.\n */\n anchorFilter?: SQL;\n\n /** ANDed into the recursive term's WHERE clause - build it with Drizzle's own `sql` tag. */\n recursiveFilter?: SQL;\n\n /**\n * Emits `path`/`is_cycle` and stops expanding once a row re-visits an id in its own path. Row\n * shape differs per engine and nothing in this signature shows it: Postgres returns a real array\n * and boolean; SQLite returns delimited text and `1`/`0` - so `row.path.length` throws on SQLite\n * and `row.is_cycle === true` is always false there.\n */\n trackPath?: boolean;\n startDepth?: number;\n}\n\n/**\n * Returns the CTE definition only - the caller writes its own `SELECT ... FROM <name>` around it.\n * Engine is read off `table`, never asked of the caller, so no option can disagree with the schema.\n * SQLite's `path` is `char(31)`-delimited text, not an array: exact unless an id contains that byte,\n * which this class does not reject. Identifiers cannot be parameterized, so `name`/`idColumn`/\n * `parentColumn`/`columns` are allowlist-checked before reaching a template.\n */\nexport class RecursiveTreeSql {\n private static assertValidIdentifier(opts: { field: string; value: string }): void {\n const { field, value } = opts;\n\n if (!IDENTIFIER_PATTERN.test(value)) {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid '${field}' | Expected letters, digits and underscores only, not starting with a digit | Got: ${value}`,\n });\n }\n }\n\n static walk(opts: IRecursiveTreeOptions): SQL {\n const {\n name,\n table,\n rootId,\n direction,\n maxDepth,\n idColumn = 'id',\n parentColumn = 'parent_id',\n columns = [],\n filter,\n anchorFilter,\n recursiveFilter,\n trackPath = false,\n startDepth = 0,\n } = opts;\n\n RecursiveTreeSql.assertValidIdentifier({ field: 'name', value: name });\n RecursiveTreeSql.assertValidIdentifier({ field: 'idColumn', value: idColumn });\n RecursiveTreeSql.assertValidIdentifier({ field: 'parentColumn', value: parentColumn });\n columns.forEach((column) =>\n RecursiveTreeSql.assertValidIdentifier({ field: 'columns', value: column }),\n );\n\n if (!RecursiveTreeDirections.isValid(direction)) {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'direction' | Expected ${RecursiveTreeDirections.UP} or ${RecursiveTreeDirections.DOWN} | Got: ${direction}`,\n });\n }\n\n if (!Number.isInteger(maxDepth) || maxDepth <= 0) {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'maxDepth' | Expected a positive integer | Got: ${maxDepth}`,\n });\n }\n\n if (!is(table, Table)) {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'table' | Expected a Drizzle table | Got: ${typeof table}`,\n });\n }\n\n const engine = RecursiveTreeSql.detectEngine(table);\n\n const tableName = getTableName(table);\n RecursiveTreeSql.assertValidIdentifier({ field: 'table', value: tableName });\n\n // A Postgres table declared with `pgSchema('commerce').table(...)` lives outside the search path,\n // so the unqualified name would read the wrong relation or none. SQLite has no schemas.\n const schemaName =\n engine === RecursiveTreeEngines.POSTGRES\n ? getTableConfig(table as PgTable).schema\n : undefined;\n\n if (schemaName !== undefined) {\n RecursiveTreeSql.assertValidIdentifier({ field: 'schema', value: schemaName });\n }\n\n const tableIdentifier =\n schemaName === undefined\n ? sql.identifier(tableName)\n : sql`${sql.identifier(schemaName)}.${sql.identifier(tableName)}`;\n const cteIdentifier = sql.identifier(name);\n const idIdentifier = sql.identifier(idColumn);\n const parentIdentifier = sql.identifier(parentColumn);\n const extraIdentifiers = columns.map((column) => sql.identifier(column));\n\n const baseColumnList = sql.join([idIdentifier, parentIdentifier, ...extraIdentifiers], sql`, `);\n const recursiveColumnList = sql.join(\n [idIdentifier, parentIdentifier, ...extraIdentifiers].map(\n (identifier) => sql`t.${identifier}`,\n ),\n sql`, `,\n );\n\n const depthCast = RecursiveTreeSql.compileDepthCast({ engine, depth: startDepth });\n const { basePathColumns, recursivePathColumns } = trackPath\n ? RecursiveTreeSql.compileCycleGuardFragments({ engine, idIdentifier })\n : { basePathColumns: sql``, recursivePathColumns: sql`` };\n\n const rootCondition = RecursiveTreeSql.compileRootCondition({\n rootId,\n direction,\n idIdentifier,\n parentIdentifier,\n });\n const bothTerms = filter ? sql` AND (${filter})` : sql``;\n // The anchor names the table by the alias `t` only when `filter` is given, so a fragment written once with `t.` is valid in both terms; without it the anchor's text is what it always was.\n const anchorTable = filter ? sql`${tableIdentifier} t` : tableIdentifier;\n const anchorExtraFilter = anchorFilter ? sql` AND (${anchorFilter})` : sql``;\n const baseCase = sql`SELECT ${baseColumnList}, ${depthCast} AS depth${basePathColumns} FROM ${anchorTable} WHERE ${rootCondition}${bothTerms}${anchorExtraFilter}`;\n\n // DOWN walks parent -> children (t.parentColumn = r.idColumn); UP walks child -> parent (t.idColumn = r.parentColumn).\n const joinCondition =\n direction === RecursiveTreeDirections.DOWN\n ? sql`t.${parentIdentifier} = r.${idIdentifier}`\n : sql`t.${idIdentifier} = r.${parentIdentifier}`;\n\n // `NOT r.is_cycle` stops expanding a row already flagged cyclic - the row itself stays in the\n // result set with is_cycle = true, only its own children are cut off.\n const cycleGuard = trackPath ? sql` AND NOT r.is_cycle` : sql``;\n const extraFilter = recursiveFilter ? sql` AND (${recursiveFilter})` : sql``;\n\n const recursiveCase = sql`SELECT ${recursiveColumnList}, r.depth + 1${recursivePathColumns} FROM ${tableIdentifier} t JOIN ${cteIdentifier} r ON ${joinCondition} WHERE r.depth + 1 <= ${maxDepth}${cycleGuard}${bothTerms}${extraFilter}`;\n\n return sql`WITH RECURSIVE ${cteIdentifier} AS (${baseCase} UNION ALL ${recursiveCase})`;\n }\n\n /** The anchor's root match: one id keeps the SQL it always had; several ids are an IN list; none is every row without a parent. */\n private static compileRootCondition(opts: {\n rootId?: string | ReadonlyArray<string>;\n direction: TRecursiveTreeDirection;\n idIdentifier: Name;\n parentIdentifier: Name;\n }): SQL {\n const { rootId, direction, idIdentifier, parentIdentifier } = opts;\n\n if (rootId === undefined) {\n if (direction === RecursiveTreeDirections.UP) {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'rootId' | An ${RecursiveTreeDirections.UP} walk needs at least one root | Got: undefined`,\n });\n }\n\n return sql`${parentIdentifier} IS NULL`;\n }\n\n if (typeof rootId === 'string') {\n return sql`${idIdentifier} = ${rootId}`;\n }\n\n if (rootId.length === 0) {\n throw getError({\n message:\n \"[RecursiveTreeSql.walk] Invalid 'rootId' | An empty list of roots would return nothing | Got: []\",\n });\n }\n\n return sql`${idIdentifier} IN (${sql.join(\n rootId.map((id) => sql`${id}`),\n sql`, `,\n )})`;\n }\n\n /** See {@link RecursiveTreeSql} for why there is no separate `engine` option. */\n private static detectEngine(table: Table): TRecursiveTreeEngine {\n if (is(table, PgTable)) {\n return RecursiveTreeEngines.POSTGRES;\n }\n\n if (is(table, SQLiteTable)) {\n return RecursiveTreeEngines.SQLITE;\n }\n\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'table' | Expected a Postgres or SQLite Drizzle table | Got: ${getTableName(table)}`,\n });\n }\n\n /** Postgres needs an explicit cast so the base and recursive terms agree on the `depth` column's type; SQLite's looser typing does not, but casts anyway for parity and to fail loudly on a non-numeric `startDepth`. */\n private static compileDepthCast(opts: { engine: TRecursiveTreeEngine; depth: number }): SQL {\n const { engine, depth } = opts;\n\n switch (engine) {\n case RecursiveTreeEngines.POSTGRES: {\n return sql`${depth}::int`;\n }\n case RecursiveTreeEngines.SQLITE: {\n return sql`CAST(${depth} AS INTEGER)`;\n }\n default: {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'engine' | Got: ${engine}`,\n });\n }\n }\n }\n\n /** See {@link RecursiveTreeSql} for why Postgres and SQLite need different `path`/`is_cycle` shapes. */\n private static compileCycleGuardFragments(opts: {\n engine: TRecursiveTreeEngine;\n idIdentifier: Name;\n }): { basePathColumns: SQL; recursivePathColumns: SQL } {\n const { engine, idIdentifier } = opts;\n\n switch (engine) {\n case RecursiveTreeEngines.POSTGRES: {\n return {\n basePathColumns: sql`, ARRAY[${idIdentifier}] AS path, false AS is_cycle`,\n recursivePathColumns: sql`, r.path || t.${idIdentifier} AS path, t.${idIdentifier} = ANY(r.path) AS is_cycle`,\n };\n }\n case RecursiveTreeEngines.SQLITE: {\n return {\n basePathColumns: sql`, ${SQLITE_PATH_DELIMITER} || ${idIdentifier} || ${SQLITE_PATH_DELIMITER} AS path, 0 AS is_cycle`,\n recursivePathColumns: sql`, r.path || t.${idIdentifier} || ${SQLITE_PATH_DELIMITER} AS path, instr(r.path, ${SQLITE_PATH_DELIMITER} || t.${idIdentifier} || ${SQLITE_PATH_DELIMITER}) > 0 AS is_cycle`,\n };\n }\n default: {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'engine' | Got: ${engine}`,\n });\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recursive-tree.js","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/sqls/recursive-tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,sIAAsI;AACtI,MAAM,OAAO,uBAAuB;aAClB,OAAE,GAAG,IAAI,CAAC;aACV,SAAI,GAAG,MAAM,CAAC;aACd,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAE3D,MAAM,CAAC,OAAO,CAAC,SAAiB;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;;AAKH,oHAAoH;AACpH,MAAM,oBAAoB;aACR,aAAQ,GAAG,UAAU,CAAC;aACtB,WAAM,GAAG,QAAQ,CAAC;aAClB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;;AAKrE,oIAAoI;AACpI,MAAM,kBAAkB,GAAG,0BAA0B,CAAC;AAEtD;;;GAGG;AACH,MAAM,qBAAqB,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAsElD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAC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AAE,GAAG,CAAA,KAAK,qBAAqB,OAAO,YAAY,OAAO,qBAAqB,yBAAyB;oBACtH,oBAAoB,EAAE,GAAG,CAAA,iBAAiB,YAAY,OAAO,qBAAqB,2BAA2B,qBAAqB,SAAS,YAAY,OAAO,qBAAqB,mBAAmB;iBACvM,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,QAAQ,CAAC;oBACb,OAAO,EAAE,mDAAmD,MAAM,EAAE;iBACrE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { Name, SQL } from 'drizzle-orm';\nimport { getTableName, is, sql, Table } from 'drizzle-orm';\nimport { getTableConfig, PgTable } from 'drizzle-orm/pg-core';\nimport { SQLiteTable } from 'drizzle-orm/sqlite-core';\n\n/** Walk direction relative to `rootId`: DOWN follows `parentColumn -> idColumn` (descendants), UP follows the reverse (ancestors). */\nexport class RecursiveTreeDirections {\n static readonly UP = 'UP';\n static readonly DOWN = 'DOWN';\n static readonly SCHEME_SET = new Set([this.UP, this.DOWN]);\n\n static isValid(direction: string): boolean {\n return this.SCHEME_SET.has(direction);\n }\n}\n\nexport type TRecursiveTreeDirection = TConstValue<typeof RecursiveTreeDirections>;\n\n/** Internal only - not part of {@link IRecursiveTreeOptions}. Derived from `table`, never accepted as an option. */\nclass RecursiveTreeEngines {\n static readonly POSTGRES = 'POSTGRES';\n static readonly SQLITE = 'SQLITE';\n static readonly SCHEME_SET = new Set([this.POSTGRES, this.SQLITE]);\n}\n\ntype TRecursiveTreeEngine = TConstValue<typeof RecursiveTreeEngines>;\n\n/** A SQL identifier is safe to splice only after it matches this allowlist - see {@link RecursiveTreeSql.assertValidIdentifier}. */\nconst IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/**\n * ASCII Unit Separator (0x1F) - chosen because it does not occur in real ids, unlike `/` or `,`.\n * See {@link RecursiveTreeSql} for the exactness limitation this relies on.\n */\nconst SQLITE_PATH_DELIMITER = sql.raw('char(31)');\n\nexport interface IRecursiveTreeOptions {\n /** CTE name the caller references in the SELECT it writes around this fragment. */\n name: string;\n\n /** Runtime-checked with `is(table, Table)`; also the sole dialect selector (Postgres vs SQLite) - see {@link RecursiveTreeSql}. */\n table: unknown;\n\n /**\n * Where the walk starts: one id, several ids (each is a root of the walk), or none. With no root a DOWN walk\n * starts from every row whose parent column is NULL; an UP walk needs a root (the ancestors of every row is never\n * what is meant) and an empty list is refused, because it would silently return nothing.\n */\n rootId?: string | ReadonlyArray<string>;\n\n /**\n * `'all'` makes every row a root of the walk, narrowed only by `filter` and `anchorFilter`. Use it when the\n * closure of every row is wanted, not the tree under one root. Cannot be combined with `rootId`. A row shows up\n * once per root that reaches it: in a DOWN walk a node at depth 3 below the top is returned four times (as its own\n * root and under each of its three ancestors), each time with its own `depth`; select `depth = 0` to get\n * each row once. Works for both directions; an UP walk then returns every row with all of its ancestors.\n */\n start?: 'all';\n direction: TRecursiveTreeDirection;\n\n /**\n * Counts EDGES, not rows: the root is at depth 0, so `N` returns up to `N+1` rows.\n * No default - `0` type-checks but silently produces an empty result, so `walk` throws at\n * runtime for `maxDepth <= 0`.\n */\n maxDepth: number;\n idColumn?: string;\n parentColumn?: string;\n\n /** Extra columns, beyond `idColumn`/`parentColumn`, carried into every row of the walk. */\n columns?: string[];\n\n /**\n * ANDed into BOTH terms (the anchor and the recursive one): a row it rejects is not in the walk and its subtree is\n * cut off. Build it with Drizzle's own `sql` tag and name the table by its alias `t`, which both terms use for it when this option is set:\n * `sql\\`t.deleted_at IS NULL\\``. An unqualified column is ambiguous in the recursive term when the walk carries it too\n * (`id`, `parent_id`, anything in `columns`). It is the same as passing the fragment as {@link anchorFilter} and as\n * {@link recursiveFilter}, written once.\n */\n filter?: SQL;\n\n /**\n * ANDed into the anchor term's WHERE clause, next to the root match - build it with\n * Drizzle's own `sql` tag, columns unqualified. Together with {@link recursiveFilter} it keeps a\n * row out of the walk at both ends, e.g. `sql\\`deleted_at IS NULL\\`` on each term.\n *\n * `walk` takes a table, not a model, so it never applies a model's soft delete or `access` scope by\n * itself: both terms are filtered only by what the caller passes here and in `recursiveFilter`.\n */\n anchorFilter?: SQL;\n\n /** ANDed into the recursive term's WHERE clause - build it with Drizzle's own `sql` tag. */\n recursiveFilter?: SQL;\n\n /**\n * Emits `path`/`is_cycle` and stops expanding once a row re-visits an id in its own path. Row\n * shape differs per engine and nothing in this signature shows it: Postgres returns a real array\n * and boolean; SQLite returns delimited text and `1`/`0` - so `row.path.length` throws on SQLite\n * and `row.is_cycle === true` is always false there.\n */\n trackPath?: boolean;\n startDepth?: number;\n}\n\n/**\n * Returns the CTE definition only - the caller writes its own `SELECT ... FROM <name>` around it.\n * Engine is read off `table`, never asked of the caller, so no option can disagree with the schema.\n * SQLite's `path` is `char(31)`-delimited text, not an array: exact unless an id contains that byte,\n * which this class does not reject. Identifiers cannot be parameterized, so `name`/`idColumn`/\n * `parentColumn`/`columns` are allowlist-checked before reaching a template.\n */\nexport class RecursiveTreeSql {\n private static assertValidIdentifier(opts: { field: string; value: string }): void {\n const { field, value } = opts;\n\n if (!IDENTIFIER_PATTERN.test(value)) {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid '${field}' | Expected letters, digits and underscores only, not starting with a digit | Got: ${value}`,\n });\n }\n }\n\n static walk(opts: IRecursiveTreeOptions): SQL {\n const {\n name,\n table,\n rootId,\n start,\n direction,\n maxDepth,\n idColumn = 'id',\n parentColumn = 'parent_id',\n columns = [],\n filter,\n anchorFilter,\n recursiveFilter,\n trackPath = false,\n startDepth = 0,\n } = opts;\n\n RecursiveTreeSql.assertValidIdentifier({ field: 'name', value: name });\n RecursiveTreeSql.assertValidIdentifier({ field: 'idColumn', value: idColumn });\n RecursiveTreeSql.assertValidIdentifier({ field: 'parentColumn', value: parentColumn });\n columns.forEach((column) =>\n RecursiveTreeSql.assertValidIdentifier({ field: 'columns', value: column }),\n );\n\n if (!RecursiveTreeDirections.isValid(direction)) {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'direction' | Expected ${RecursiveTreeDirections.UP} or ${RecursiveTreeDirections.DOWN} | Got: ${direction}`,\n });\n }\n\n if (!Number.isInteger(maxDepth) || maxDepth <= 0) {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'maxDepth' | Expected a positive integer | Got: ${maxDepth}`,\n });\n }\n\n if (!is(table, Table)) {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'table' | Expected a Drizzle table | Got: ${typeof table}`,\n });\n }\n\n const engine = RecursiveTreeSql.detectEngine(table);\n\n const tableName = getTableName(table);\n RecursiveTreeSql.assertValidIdentifier({ field: 'table', value: tableName });\n\n // A Postgres table declared with `pgSchema('commerce').table(...)` lives outside the search path,\n // so the unqualified name would read the wrong relation or none. SQLite has no schemas.\n const schemaName =\n engine === RecursiveTreeEngines.POSTGRES\n ? getTableConfig(table as PgTable).schema\n : undefined;\n\n if (schemaName !== undefined) {\n RecursiveTreeSql.assertValidIdentifier({ field: 'schema', value: schemaName });\n }\n\n const tableIdentifier =\n schemaName === undefined\n ? sql.identifier(tableName)\n : sql`${sql.identifier(schemaName)}.${sql.identifier(tableName)}`;\n const cteIdentifier = sql.identifier(name);\n const idIdentifier = sql.identifier(idColumn);\n const parentIdentifier = sql.identifier(parentColumn);\n const extraIdentifiers = columns.map((column) => sql.identifier(column));\n\n const baseColumnList = sql.join([idIdentifier, parentIdentifier, ...extraIdentifiers], sql`, `);\n const recursiveColumnList = sql.join(\n [idIdentifier, parentIdentifier, ...extraIdentifiers].map(\n (identifier) => sql`t.${identifier}`,\n ),\n sql`, `,\n );\n\n const depthCast = RecursiveTreeSql.compileDepthCast({ engine, depth: startDepth });\n const { basePathColumns, recursivePathColumns } = trackPath\n ? RecursiveTreeSql.compileCycleGuardFragments({ engine, idIdentifier })\n : { basePathColumns: sql``, recursivePathColumns: sql`` };\n\n const rootCondition = RecursiveTreeSql.compileRootCondition({\n rootId,\n start,\n direction,\n idIdentifier,\n parentIdentifier,\n });\n const bothTerms = filter ? sql` AND (${filter})` : sql``;\n // The anchor names the table by the alias `t` only when `filter` is given, so a fragment written once with `t.` is valid in both terms; without it the anchor's text is what it always was.\n const anchorTable = filter ? sql`${tableIdentifier} t` : tableIdentifier;\n const anchorExtraFilter = anchorFilter ? sql` AND (${anchorFilter})` : sql``;\n const baseCase = sql`SELECT ${baseColumnList}, ${depthCast} AS depth${basePathColumns} FROM ${anchorTable} WHERE ${rootCondition}${bothTerms}${anchorExtraFilter}`;\n\n // DOWN walks parent -> children (t.parentColumn = r.idColumn); UP walks child -> parent (t.idColumn = r.parentColumn).\n const joinCondition =\n direction === RecursiveTreeDirections.DOWN\n ? sql`t.${parentIdentifier} = r.${idIdentifier}`\n : sql`t.${idIdentifier} = r.${parentIdentifier}`;\n\n // `NOT r.is_cycle` stops expanding a row already flagged cyclic - the row itself stays in the\n // result set with is_cycle = true, only its own children are cut off.\n const cycleGuard = trackPath ? sql` AND NOT r.is_cycle` : sql``;\n const extraFilter = recursiveFilter ? sql` AND (${recursiveFilter})` : sql``;\n\n const recursiveCase = sql`SELECT ${recursiveColumnList}, r.depth + 1${recursivePathColumns} FROM ${tableIdentifier} t JOIN ${cteIdentifier} r ON ${joinCondition} WHERE r.depth + 1 <= ${maxDepth}${cycleGuard}${bothTerms}${extraFilter}`;\n\n return sql`WITH RECURSIVE ${cteIdentifier} AS (${baseCase} UNION ALL ${recursiveCase})`;\n }\n\n /** The anchor's root match: one id keeps the SQL it always had; several ids are an IN list; none is every row without a parent; `start: 'all'` is every row. */\n private static compileRootCondition(opts: {\n rootId?: string | ReadonlyArray<string>;\n start?: 'all';\n direction: TRecursiveTreeDirection;\n idIdentifier: Name;\n parentIdentifier: Name;\n }): SQL {\n const { rootId, start, direction, idIdentifier, parentIdentifier } = opts;\n\n if (start !== undefined) {\n if (start !== 'all') {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'start' | Expected 'all' or no value | Got: ${String(start)}`,\n });\n }\n\n if (rootId !== undefined) {\n throw getError({\n message:\n \"[RecursiveTreeSql.walk] Invalid 'start' | 'all' makes every row a root, so it cannot be combined with 'rootId'\",\n });\n }\n\n // true for every row; `1 = 1` rather than TRUE because it reads the same on Postgres and on every SQLite version\n return sql`1 = 1`;\n }\n\n if (rootId === undefined) {\n if (direction === RecursiveTreeDirections.UP) {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'rootId' | An ${RecursiveTreeDirections.UP} walk needs at least one root | Got: undefined`,\n });\n }\n\n return sql`${parentIdentifier} IS NULL`;\n }\n\n if (typeof rootId === 'string') {\n return sql`${idIdentifier} = ${rootId}`;\n }\n\n if (rootId.length === 0) {\n throw getError({\n message:\n \"[RecursiveTreeSql.walk] Invalid 'rootId' | An empty list of roots would return nothing | Got: []\",\n });\n }\n\n return sql`${idIdentifier} IN (${sql.join(\n rootId.map((id) => sql`${id}`),\n sql`, `,\n )})`;\n }\n\n /** See {@link RecursiveTreeSql} for why there is no separate `engine` option. */\n private static detectEngine(table: Table): TRecursiveTreeEngine {\n if (is(table, PgTable)) {\n return RecursiveTreeEngines.POSTGRES;\n }\n\n if (is(table, SQLiteTable)) {\n return RecursiveTreeEngines.SQLITE;\n }\n\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'table' | Expected a Postgres or SQLite Drizzle table | Got: ${getTableName(table)}`,\n });\n }\n\n /** Postgres needs an explicit cast so the base and recursive terms agree on the `depth` column's type; SQLite's looser typing does not, but casts anyway for parity and to fail loudly on a non-numeric `startDepth`. */\n private static compileDepthCast(opts: { engine: TRecursiveTreeEngine; depth: number }): SQL {\n const { engine, depth } = opts;\n\n switch (engine) {\n case RecursiveTreeEngines.POSTGRES: {\n return sql`${depth}::int`;\n }\n case RecursiveTreeEngines.SQLITE: {\n return sql`CAST(${depth} AS INTEGER)`;\n }\n default: {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'engine' | Got: ${engine}`,\n });\n }\n }\n }\n\n /** See {@link RecursiveTreeSql} for why Postgres and SQLite need different `path`/`is_cycle` shapes. */\n private static compileCycleGuardFragments(opts: {\n engine: TRecursiveTreeEngine;\n idIdentifier: Name;\n }): { basePathColumns: SQL; recursivePathColumns: SQL } {\n const { engine, idIdentifier } = opts;\n\n switch (engine) {\n case RecursiveTreeEngines.POSTGRES: {\n return {\n basePathColumns: sql`, ARRAY[${idIdentifier}] AS path, false AS is_cycle`,\n recursivePathColumns: sql`, r.path || t.${idIdentifier} AS path, t.${idIdentifier} = ANY(r.path) AS is_cycle`,\n };\n }\n case RecursiveTreeEngines.SQLITE: {\n return {\n basePathColumns: sql`, ${SQLITE_PATH_DELIMITER} || ${idIdentifier} || ${SQLITE_PATH_DELIMITER} AS path, 0 AS is_cycle`,\n recursivePathColumns: sql`, r.path || t.${idIdentifier} || ${SQLITE_PATH_DELIMITER} AS path, instr(r.path, ${SQLITE_PATH_DELIMITER} || t.${idIdentifier} || ${SQLITE_PATH_DELIMITER}) > 0 AS is_cycle`,\n };\n }\n default: {\n throw getError({\n message: `[RecursiveTreeSql.walk] Invalid 'engine' | Got: ${engine}`,\n });\n }\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis-connectors",
|
|
3
|
-
"version": "0.4.7-
|
|
3
|
+
"version": "0.4.7-4",
|
|
4
4
|
"description": "Datasource and repository connectors for the IGNIS framework: the engine-neutral relational and search tiers, plus Postgres, SQLite, PGlite, Typesense and Meilisearch behind sub-paths.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -97,15 +97,15 @@
|
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
99
|
"@venizia/ignis-filter": "0.4.6-1",
|
|
100
|
-
"@venizia/ignis-helpers": "0.4.7-
|
|
100
|
+
"@venizia/ignis-helpers": "0.4.7-4",
|
|
101
101
|
"@venizia/ignis-inversion": "0.4.6-1",
|
|
102
|
-
"@venizia/ignis-kernel": "0.4.7-
|
|
102
|
+
"@venizia/ignis-kernel": "0.4.7-4",
|
|
103
103
|
"zod": "^4.6.7"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
106
|
"@types/bun": "^1.4.3",
|
|
107
107
|
"@types/pg": "^8.23.1",
|
|
108
|
-
"@venizia/dev-configs": "0.4.7-
|
|
108
|
+
"@venizia/dev-configs": "0.4.7-4",
|
|
109
109
|
"eslint": "^10.13.0",
|
|
110
110
|
"oxlint": "1.89.0",
|
|
111
111
|
"oxlint-tsgolint": "7.0.2004",
|