orange-orm 4.4.2 → 4.5.0-beta.1
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/README.md +1 -1
- package/package.json +12 -6
- package/src/client/clientMap.js +2 -0
- package/src/client/createProviders.js +12 -0
- package/src/client/index.js +6 -3
- package/src/client/index.mjs +8 -3
- package/src/client/map.js +1 -0
- package/src/createDomain.js +11 -16
- package/src/d1/newDatabase.js +119 -0
- package/src/d1/newPool.js +19 -0
- package/src/d1/newTransaction.js +82 -0
- package/src/d1/pool/end.js +13 -0
- package/src/d1/pool/newGenericPool.js +53 -0
- package/src/d1/wrapQuery.js +22 -0
- package/src/d1test.js +35 -0
- package/src/emitEvent.js +6 -4
- package/src/emptyFilter.js +12 -12
- package/src/getManyDto/newQuery.js +5 -5
- package/src/getManyDto/query/newSingleQuery.js +5 -5
- package/src/getManyDto.js +25 -24
- package/src/hostExpress/cycle.ts +211 -0
- package/src/hostExpress/executePath.js +360 -357
- package/src/hostLocal.js +8 -8
- package/src/index.d.ts +2 -0
- package/src/index.js +19 -15
- package/src/map.d.ts +3 -0
- package/src/mssql/newDatabase.js +19 -31
- package/src/mssql/newPool.js +2 -2
- package/src/mssql/newTransaction.js +5 -4
- package/src/mssql/pool/newGenericPool.js +1 -1
- package/src/mySql/deleteFromSql.js +1 -1
- package/src/mySql/insert.js +5 -5
- package/src/mySql/insertSql.js +2 -3
- package/src/mySql/lastInsertedSql.js +3 -4
- package/src/mySql/newDatabase.js +20 -34
- package/src/mySql/newPool.js +10 -10
- package/src/mySql/newTransaction.js +3 -3
- package/src/mySql/pool/newGenericPool.js +2 -3
- package/src/mySql/quote.js +1 -0
- package/src/newImmutable.js +1 -2
- package/src/oracle/deleteFromSql.js +1 -1
- package/src/oracle/formatDateOut.js +1 -1
- package/src/oracle/insert.js +6 -6
- package/src/oracle/insertSql.js +6 -14
- package/src/oracle/lastInsertedSql.js +3 -3
- package/src/oracle/mergeSql.js +3 -6
- package/src/oracle/newDatabase.js +18 -33
- package/src/oracle/newInsertCommandCore.js +3 -3
- package/src/oracle/newPool.js +10 -10
- package/src/oracle/newTransaction.js +3 -2
- package/src/oracle/pool/newGenericPool.js +2 -2
- package/src/oracle/quote.js +1 -0
- package/src/oracle/wrapQuery.js +0 -3
- package/src/patchRow.js +2 -2
- package/src/patchTable.js +6 -5
- package/src/pg/deleteFromSql.js +1 -1
- package/src/pg/formatDateOut.js +1 -2
- package/src/pg/insert.js +3 -3
- package/src/pg/insertSql.js +2 -7
- package/src/pg/lastInsertedSql.js +1 -2
- package/src/pg/newDatabase.js +20 -37
- package/src/pg/newPool.js +10 -10
- package/src/pg/newTransaction.js +3 -2
- package/src/pg/pool/newPgPool.js +2 -2
- package/src/pg/quote.js +2 -0
- package/src/pg/schema.js +2 -2
- package/src/{mySql/pool/defaults.js → poolDefaults.js} +0 -2
- package/src/query.js +2 -2
- package/src/sap/deleteFromSql.js +1 -1
- package/src/sap/formatDateOut.js +1 -1
- package/src/sap/insert.js +5 -5
- package/src/sap/insertSql.js +4 -5
- package/src/sap/lastInsertedSql.js +3 -3
- package/src/sap/mergeSql.js +1 -2
- package/src/sap/newDatabase.js +23 -34
- package/src/sap/newPool.js +2 -2
- package/src/sap/newTransaction.js +3 -2
- package/src/sap/quote.js +1 -0
- package/src/sqlite/deleteFromSql.js +1 -1
- package/src/sqlite/insert.js +5 -5
- package/src/sqlite/insertSql.js +2 -2
- package/src/sqlite/lastInsertedSql.js +2 -2
- package/src/sqlite/newDatabase.js +16 -32
- package/src/sqlite/newPool.js +10 -10
- package/src/sqlite/newTransaction.js +3 -2
- package/src/sqlite/pool/newGenericPool.js +2 -1
- package/src/sqlite/quote.js +1 -0
- package/src/table/aggregate.js +1 -1
- package/src/table/begin.js +5 -5
- package/src/table/cascadeDelete.js +2 -2
- package/src/table/column/binary/newDecode.js +2 -2
- package/src/table/column/binary/newEncode.js +3 -4
- package/src/table/column/boolean/newDecode.js +1 -1
- package/src/table/column/boolean/newEncode.js +6 -6
- package/src/table/column/date/formatOut.js +3 -5
- package/src/table/column/date/newDecode.js +2 -2
- package/src/table/column/date/newEncode.js +8 -8
- package/src/table/column/date.js +1 -1
- package/src/table/column/dateWithTimeZone/newEncode.js +3 -4
- package/src/table/column/dateWithTimeZone.js +1 -1
- package/src/table/column/encodeFilterArg.js +3 -3
- package/src/table/column/equal.js +3 -3
- package/src/table/column/extractAlias.js +0 -2
- package/src/table/column/greaterThan.js +3 -3
- package/src/table/column/greaterThanOrEqual.js +3 -3
- package/src/table/column/guid/newDecode.js +1 -1
- package/src/table/column/guid/newEncode.js +3 -3
- package/src/table/column/in.js +3 -3
- package/src/table/column/json/formatOut.js +3 -3
- package/src/table/column/json/newDecode.js +3 -3
- package/src/table/column/json/newEncode.js +6 -6
- package/src/table/column/json.js +2 -1
- package/src/table/column/lessThan.js +3 -3
- package/src/table/column/lessThanOrEqual.js +4 -4
- package/src/table/column/negotiateRawSqlFilter.js +9 -9
- package/src/table/column/newBoolean.js +9 -9
- package/src/table/column/newColumn.js +21 -21
- package/src/table/column/newDecodeCore.js +1 -1
- package/src/table/column/notEqual.js +3 -3
- package/src/table/column/numeric/newDecode.js +2 -2
- package/src/table/column/numeric/newEncode.js +3 -3
- package/src/table/column/string/contains.js +2 -1
- package/src/table/column/string/containsCore.js +5 -5
- package/src/table/column/string/endsWith.js +1 -1
- package/src/table/column/string/endsWithCore.js +4 -4
- package/src/table/column/string/iContains.js +2 -1
- package/src/table/column/string/iEndsWith.js +1 -1
- package/src/table/column/string/iEqual.js +3 -3
- package/src/table/column/string/iStartsWith.js +1 -1
- package/src/table/column/string/newEncode.js +3 -3
- package/src/table/column/string/startsWith.js +1 -1
- package/src/table/column/string/startsWithCore.js +4 -4
- package/src/table/column/string.js +14 -14
- package/src/table/commands/beginCommand.js +2 -2
- package/src/table/commands/compressChanges.js +2 -2
- package/src/table/commands/delete/newSingleCommand.js +5 -5
- package/src/table/commands/delete/singleCommand/joinSql.js +12 -12
- package/src/table/commands/delete/singleCommand/newSingleCommandCore.js +2 -2
- package/src/table/commands/delete/singleCommand/selectSql.js +6 -6
- package/src/table/commands/delete/singleCommand/subFilter.js +11 -11
- package/src/table/commands/delete/singleCommand/whereSql.js +2 -2
- package/src/table/commands/getChangeSet.js +2 -2
- package/src/table/commands/insert/getSqlTemplate.js +16 -16
- package/src/table/commands/lastCommandMatches.js +2 -2
- package/src/table/commands/newDeleteCommand.js +5 -5
- package/src/table/commands/newGetLastInsertedCommand.js +4 -4
- package/src/table/commands/newGetLastInsertedCommandCore.js +5 -5
- package/src/table/commands/newInsertCommand.js +0 -1
- package/src/table/commands/newInsertCommandCore.js +3 -3
- package/src/table/commands/newRow.js +4 -4
- package/src/table/commands/newUpdateCommand.js +4 -4
- package/src/table/commands/newUpdateCommandCore.js +4 -4
- package/src/table/commands/pushCommand.js +2 -2
- package/src/table/commit.js +13 -11
- package/src/table/count.js +8 -8
- package/src/table/delete.js +4 -4
- package/src/table/deleteSessionContext.js +4 -13
- package/src/table/executeQueries/executeChanges.js +3 -3
- package/src/table/executeQueries/executeQueriesCore.js +2 -2
- package/src/table/executeQueries/executeQuery.js +2 -2
- package/src/table/executeQueries/resolveExecuteQuery.js +4 -4
- package/src/table/executeQueries.js +4 -4
- package/src/table/getFromDbById.js +1 -1
- package/src/table/getMany.js +7 -7
- package/src/table/getManyDto.js +3 -4
- package/src/table/getSessionContext.js +4 -4
- package/src/table/getSessionSingleton.js +3 -2
- package/src/table/groupBy/newQuery.js +4 -4
- package/src/table/groupBy.js +9 -9
- package/src/table/insert.js +10 -13
- package/src/table/joinRelation/getRelatives.js +6 -6
- package/src/table/newGetRelated.js +3 -3
- package/src/table/newManyRelation.js +9 -9
- package/src/table/newOneRelation.js +9 -9
- package/src/table/newPrimaryKeyFilter.js +6 -6
- package/src/table/newQuery.js +5 -5
- package/src/table/newRelatedTable.js +2 -2
- package/src/table/newRowCache.js +17 -17
- package/src/table/newThrow.js +2 -2
- package/src/table/oneRelation/getRelatives.js +5 -5
- package/src/table/popChanges.js +3 -3
- package/src/table/promise.js +2 -8
- package/src/table/query/extractLimit.js +2 -2
- package/src/table/query/extractOffset.js +2 -2
- package/src/table/query/extractOrderBy.js +2 -2
- package/src/table/query/newSingleQuery.js +7 -7
- package/src/table/query/singleQuery/columnSql/joinLegToColumnSql.js +5 -5
- package/src/table/query/singleQuery/columnSql/newJoinedColumnSql.js +2 -2
- package/src/table/query/singleQuery/columnSql/newShallowColumnSql.js +4 -4
- package/src/table/query/singleQuery/joinSql/joinLegToJoinSql.js +2 -2
- package/src/table/query/singleQuery/joinSql/joinLegToShallowJoinSql.js +2 -2
- package/src/table/query/singleQuery/joinSql/newDiscriminatorSql.js +2 -2
- package/src/table/query/singleQuery/joinSql/newShallowJoinSql.js +5 -5
- package/src/table/query/singleQuery/joinSql/newShallowJoinSqlCore.js +6 -5
- package/src/table/query/singleQuery/joinSql/oneLegToJoinSql.js +2 -2
- package/src/table/query/singleQuery/joinSql/oneLegToShallowJoinSql.js +2 -2
- package/src/table/query/singleQuery/negotiateExclusive.js +2 -2
- package/src/table/query/singleQuery/newColumnSql.js +3 -3
- package/src/table/query/singleQuery/newDiscriminatorSql.js +2 -2
- package/src/table/query/singleQuery/newJoinSql.js +6 -6
- package/src/table/query/singleQuery/newWhereSql.js +3 -3
- package/src/table/quote.js +4 -4
- package/src/table/relatedTable/aggregate.js +2 -2
- package/src/table/relatedTable/all.js +5 -5
- package/src/table/relatedTable/any.js +3 -3
- package/src/table/relatedTable/childColumn.js +12 -12
- package/src/table/relatedTable/columnAggregate.js +3 -3
- package/src/table/relatedTable/columnAggregateGroup.js +11 -11
- package/src/table/relatedTable/joinSql.js +5 -5
- package/src/table/relatedTable/joinSqlArray.js +3 -3
- package/src/table/relatedTable/none.js +3 -3
- package/src/table/relatedTable/relatedColumn.js +13 -13
- package/src/table/relatedTable/selectSql.js +2 -2
- package/src/table/relatedTable/subFilter.js +4 -4
- package/src/table/relatedTable/where.js +3 -3
- package/src/table/relatedTable/whereSql.js +2 -2
- package/src/table/relation/manyCache/synchronizeAdded.js +2 -2
- package/src/table/relation/manyCache/synchronizeChanged.js +3 -3
- package/src/table/relation/manyCache/synchronizeRemoved.js +2 -2
- package/src/table/relation/newForeignKeyFilter.js +2 -2
- package/src/table/relation/newManyCache.js +16 -16
- package/src/table/relation/newOneCache.js +6 -6
- package/src/table/releaseDbClient.js +4 -4
- package/src/table/resultToPromise.js +1 -3
- package/src/table/resultToRows/dbRowToRow.js +8 -8
- package/src/table/resultToRows/dbRowsToRows.js +2 -2
- package/src/table/resultToRows/decodeDbRow.js +2 -2
- package/src/table/resultToRows/delete/removeFromCache.js +6 -6
- package/src/table/resultToRows/delete.js +6 -6
- package/src/table/resultToRows/newDecodeDbRow.js +19 -18
- package/src/table/resultToRows/toDto.js +3 -3
- package/src/table/resultToRows.js +3 -3
- package/src/table/rollback.js +21 -11
- package/src/table/rowArray/negotiateNextTick.js +1 -2
- package/src/table/setSessionSingleton.js +6 -3
- package/src/table/tryGetFirstFromDb.js +4 -4
- package/src/table/tryGetFromCacheById.js +3 -3
- package/src/table/tryGetFromDbById/extractStrategy.js +2 -2
- package/src/table/tryGetFromDbById.js +8 -6
- package/src/table/tryGetSessionContext.js +5 -10
- package/src/table/tryReleaseDbClient.js +2 -2
- package/src/table/updateField.js +4 -4
- package/src/table/where.js +2 -2
- package/src/table.js +58 -51
- package/src/tedious/deleteFromSql.js +1 -1
- package/src/tedious/formatDateOut.js +1 -1
- package/src/tedious/getManyDto/newQueryCore.js +5 -5
- package/src/tedious/getManyDto/query/newSingleQuery.js +5 -5
- package/src/tedious/getManyDto/query/newSubQueries/joinLegToQuery.js +3 -3
- package/src/tedious/getManyDto/query/newSubQueries/manyLegToQuery.js +3 -3
- package/src/tedious/getManyDto/query/newSubQueries/oneLegToQuery.js +4 -4
- package/src/tedious/getManyDto/query/newSubQueries.js +8 -8
- package/src/tedious/getManyDto/query/singleQuery/newShallowColumnSql.js +5 -6
- package/src/tedious/getManyDto.js +6 -6
- package/src/tedious/insert.js +3 -3
- package/src/tedious/insertSql.js +3 -3
- package/src/tedious/newDatabase.js +17 -30
- package/src/tedious/newPool.js +10 -10
- package/src/tedious/newTransaction.js +4 -5
- package/src/tedious/pool/newGenericPool.js +1 -1
- package/src/tedious/quote.js +1 -0
- package/src/mssql/pool/defaults.js +0 -45
- package/src/oracle/pool/defaults.js +0 -45
- package/src/pg/pool/defaults.js +0 -45
- package/src/sqlite/pool/defaults.js +0 -45
- package/src/tedious/pool/defaults.js +0 -45
|
@@ -5,13 +5,13 @@ var extractLimit = require('../table/query/extractLimit');
|
|
|
5
5
|
var newParameterized = require('../table/query/newParameterized');
|
|
6
6
|
var extractOffset = require('../table/query/extractOffset');
|
|
7
7
|
|
|
8
|
-
function newQuery(table,filter,span,alias) {
|
|
8
|
+
function newQuery(context,table,filter,span,alias) {
|
|
9
9
|
filter = extractFilter(filter);
|
|
10
|
-
var orderBy = extractOrderBy(table,alias,span.orderBy);
|
|
11
|
-
var limit = extractLimit(span);
|
|
12
|
-
var offset = extractOffset(span);
|
|
10
|
+
var orderBy = extractOrderBy(context,table,alias,span.orderBy);
|
|
11
|
+
var limit = extractLimit(context, span);
|
|
12
|
+
var offset = extractOffset(context, span);
|
|
13
13
|
|
|
14
|
-
var query = newSingleQuery(table,filter,span,alias,orderBy,limit,offset);
|
|
14
|
+
var query = newSingleQuery(context,table,filter,span,alias,orderBy,limit,offset);
|
|
15
15
|
return newParameterized(query.sql(), query.parameters);
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -4,12 +4,12 @@ var newJoinSql = require('../../table/query/singleQuery/newJoinSql');
|
|
|
4
4
|
var newParameterized = require('../../table/query/newParameterized');
|
|
5
5
|
var getSessionSingleton = require('../../table/getSessionSingleton');
|
|
6
6
|
|
|
7
|
-
function _new(table,filter,span, alias,orderBy,limit,offset) {
|
|
8
|
-
var quote = getSessionSingleton('quote');
|
|
7
|
+
function _new(context,table,filter,span, alias,orderBy,limit,offset) {
|
|
8
|
+
var quote = getSessionSingleton(context, 'quote');
|
|
9
9
|
var name = quote(table._dbName);
|
|
10
|
-
var columnSql = newColumnSql(table,span,alias,true);
|
|
11
|
-
var joinSql = newJoinSql(span, alias);
|
|
12
|
-
var whereSql = newWhereSql(table,filter,alias);
|
|
10
|
+
var columnSql = newColumnSql(context,table,span,alias,true);
|
|
11
|
+
var joinSql = newJoinSql(context, span, alias);
|
|
12
|
+
var whereSql = newWhereSql(context,table,filter,alias);
|
|
13
13
|
if (limit)
|
|
14
14
|
limit = limit + ' ';
|
|
15
15
|
|
package/src/getManyDto.js
CHANGED
|
@@ -4,19 +4,19 @@ const negotiateRawSqlFilter = require('./table/column/negotiateRawSqlFilter');
|
|
|
4
4
|
const strategyToSpan = require('./table/strategyToSpan');
|
|
5
5
|
const executeQueries = require('./table/executeQueries');
|
|
6
6
|
|
|
7
|
-
async function getManyDto(table, filter, strategy, spanFromParent, updateParent) {
|
|
8
|
-
filter = negotiateRawSqlFilter(filter, table);
|
|
7
|
+
async function getManyDto(context, table, filter, strategy, spanFromParent, updateParent) {
|
|
8
|
+
filter = negotiateRawSqlFilter(context, filter, table);
|
|
9
9
|
if (strategy && strategy.where) {
|
|
10
|
-
let arg = typeof strategy.where === 'function' ? strategy.where(table) : strategy.where
|
|
11
|
-
filter = filter.and(arg);
|
|
10
|
+
let arg = typeof strategy.where === 'function' ? strategy.where(context, table) : strategy.where;//todo
|
|
11
|
+
filter = filter.and(context, arg);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
let span = spanFromParent || strategyToSpan(table, strategy);
|
|
15
15
|
let alias = table._dbName;
|
|
16
16
|
|
|
17
|
-
const query = newQuery(table, filter, span, alias);
|
|
18
|
-
const res = await executeQueries([query]);
|
|
19
|
-
return decode(strategy, span, await res[0], undefined, updateParent);
|
|
17
|
+
const query = newQuery(context, table, filter, span, alias);
|
|
18
|
+
const res = await executeQueries(context, [query]);
|
|
19
|
+
return decode(context, strategy, span, await res[0], undefined, updateParent);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function newCreateRow(span) {
|
|
@@ -149,7 +149,7 @@ function hasManyRelations(span) {
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys(rows[0]) : [], updateParent) {
|
|
152
|
+
async function decode(context, strategy, span, rows, keys = rows.length > 0 ? Object.keys(rows[0]) : [], updateParent) {
|
|
153
153
|
const table = span.table;
|
|
154
154
|
let columnsMap = span.columns;
|
|
155
155
|
const columns = table._columns.filter(column => !columnsMap || columnsMap.get(column));
|
|
@@ -179,13 +179,14 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
const column = columns[j];
|
|
182
|
-
|
|
182
|
+
//todo
|
|
183
|
+
outRow[column.alias] = column.decode(context, row[keys[j]]);
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
for (let j = 0; j < aggregateKeys.length; j++) {
|
|
186
187
|
const key = aggregateKeys[j];
|
|
187
|
-
const parse = span.aggregates[key].column?.decode || Number.parseFloat;
|
|
188
|
-
outRow[key] = parse(row[keys[j + columnsLength]]);
|
|
188
|
+
const parse = span.aggregates[key].column?.decode || ((context, arg) => Number.parseFloat(arg));
|
|
189
|
+
outRow[key] = parse(context, row[keys[j + columnsLength]]);
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
outRows[i] = outRow;
|
|
@@ -208,13 +209,13 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
208
209
|
const all = [];
|
|
209
210
|
|
|
210
211
|
if (shouldCreateMap) {
|
|
211
|
-
all.push(decodeManyRelations(strategy, span));
|
|
212
|
-
all.push(decodeRelations2(strategy, span, rows, outRows, keys));
|
|
212
|
+
all.push(decodeManyRelations(context, strategy, span));
|
|
213
|
+
all.push(decodeRelations2(context, strategy, span, rows, outRows, keys));
|
|
213
214
|
}
|
|
214
215
|
// decodeRelations2(strategy, span, rows, outRows, keys);
|
|
215
216
|
// }
|
|
216
217
|
else
|
|
217
|
-
all.push(decodeRelations2(strategy, span, rows, outRows, keys));
|
|
218
|
+
all.push(decodeRelations2(context, strategy, span, rows, outRows, keys));
|
|
218
219
|
|
|
219
220
|
await Promise.all(all);
|
|
220
221
|
|
|
@@ -240,7 +241,7 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
240
241
|
|
|
241
242
|
}
|
|
242
243
|
|
|
243
|
-
async function decodeManyRelations(strategy, span) {
|
|
244
|
+
async function decodeManyRelations(context, strategy, span) {
|
|
244
245
|
const promises = [];
|
|
245
246
|
const c = {};
|
|
246
247
|
c.visitJoin = () => { };
|
|
@@ -252,11 +253,11 @@ async function decodeManyRelations(strategy, span) {
|
|
|
252
253
|
const relation = table._relations[name];
|
|
253
254
|
const rowsMap = span._rowsMap;
|
|
254
255
|
|
|
255
|
-
const filter = createOneFilter(relation, span._ids);
|
|
256
|
+
const filter = createOneFilter(context, relation, span._ids);
|
|
256
257
|
const extractKey = createExtractKey(leg);
|
|
257
258
|
const extractFromMap = createExtractFromMap(rowsMap, table._primaryColumns);
|
|
258
259
|
|
|
259
|
-
const p = getManyDto(relation.childTable, filter, strategy[name], leg.span, updateParent);
|
|
260
|
+
const p = getManyDto(context, relation.childTable, filter, strategy[name], leg.span, updateParent);
|
|
260
261
|
// .then(subRows => {
|
|
261
262
|
// for (let i = 0; i < subRows.length; i++) {
|
|
262
263
|
// const key = extractKey(subRows[i]);
|
|
@@ -299,11 +300,11 @@ async function decodeManyRelations(strategy, span) {
|
|
|
299
300
|
|
|
300
301
|
await Promise.all(promises);
|
|
301
302
|
}
|
|
302
|
-
async function decodeRelations2(strategy, span, rawRows, resultRows, keys) {
|
|
303
|
+
async function decodeRelations2(context, strategy, span, rawRows, resultRows, keys) {
|
|
303
304
|
const c = {};
|
|
304
305
|
c.visitJoin = function(leg) {
|
|
305
306
|
const name = leg.name;
|
|
306
|
-
return decode(strategy[name], leg.span, rawRows, keys, updateParent);
|
|
307
|
+
return decode(context, strategy[name], leg.span, rawRows, keys, updateParent);
|
|
307
308
|
|
|
308
309
|
function updateParent(subRow, i) {
|
|
309
310
|
resultRows[i][name] = subRow;
|
|
@@ -323,11 +324,11 @@ async function decodeRelations2(strategy, span, rawRows, resultRows, keys) {
|
|
|
323
324
|
await processLegsSequentially(span.legs);
|
|
324
325
|
}
|
|
325
326
|
|
|
326
|
-
function createOneFilter(relation, ids) {
|
|
327
|
+
function createOneFilter(context, relation, ids) {
|
|
327
328
|
const columns = relation.joinRelation.columns;
|
|
328
329
|
|
|
329
330
|
if (columns.length === 1)
|
|
330
|
-
return columns[0].in(ids);
|
|
331
|
+
return columns[0].in(context, ids);
|
|
331
332
|
|
|
332
333
|
else
|
|
333
334
|
return createCompositeFilter();
|
|
@@ -338,11 +339,11 @@ function createOneFilter(relation, ids) {
|
|
|
338
339
|
let nextFilter;
|
|
339
340
|
for (let i = 0; i < columns.length; i++) {
|
|
340
341
|
if (nextFilter)
|
|
341
|
-
nextFilter = nextFilter.and(columns[i].eq(id[i]));
|
|
342
|
+
nextFilter = nextFilter.and(context, columns[i].eq(context, id[i]));
|
|
342
343
|
else
|
|
343
|
-
nextFilter = columns[i].eq(id[i]);
|
|
344
|
+
nextFilter = columns[i].eq(context, id[i]);
|
|
344
345
|
}
|
|
345
|
-
filter = filter.or(nextFilter);
|
|
346
|
+
filter = filter.or(context, nextFilter);
|
|
346
347
|
}
|
|
347
348
|
return filter;
|
|
348
349
|
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Utility to decrement recursion depth
|
|
2
|
+
type DecrementDepth<D extends any[]> = D extends [any, ...infer Rest] ? Rest : never;
|
|
3
|
+
|
|
4
|
+
// Define the structure of each node's definition within NodeTypeMap
|
|
5
|
+
// NodeKey is a string (or a type union of strings) that identifies a node.
|
|
6
|
+
type NodeDefinition = {
|
|
7
|
+
base: {}; // Base type of the node
|
|
8
|
+
children?: Record<string, string>; // childPropName -> childNodeKey
|
|
9
|
+
parent?: { prop: string; node: string }; // parentPropName, parentNodeKey
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// A map of node keys to their definitions
|
|
13
|
+
type NodeTypeMap = {
|
|
14
|
+
[NodeKey: string]: NodeDefinition;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// The RecursiveNode type:
|
|
18
|
+
// D: depth array
|
|
19
|
+
// M: the NodeTypeMap
|
|
20
|
+
// K: the NodeKey for the current node
|
|
21
|
+
//
|
|
22
|
+
// If D is empty, we return just the base type.
|
|
23
|
+
// If not empty, we return the base type plus recursively expanded children and parent.
|
|
24
|
+
type RecursiveNode<
|
|
25
|
+
D extends any[],
|
|
26
|
+
M extends Record<string, NodeDefinition>,
|
|
27
|
+
K extends keyof M
|
|
28
|
+
> = D extends []
|
|
29
|
+
? // At zero depth, just return the base type of this node
|
|
30
|
+
M[K]['base']
|
|
31
|
+
: // Non-zero depth:
|
|
32
|
+
// Start with the base type
|
|
33
|
+
M[K]['base']
|
|
34
|
+
// Add recursively expanded children, if any
|
|
35
|
+
& (M[K]['children'] extends Record<string, string>
|
|
36
|
+
? { [ChildProp in keyof M[K]['children']]:
|
|
37
|
+
RecursiveNode<DecrementDepth<D>, M, M[K]['children'][ChildProp]> }
|
|
38
|
+
: {})
|
|
39
|
+
// Add recursively expanded parent, if defined
|
|
40
|
+
& (M[K]['parent'] extends { prop: string; node: string }
|
|
41
|
+
? { [P in M[K]['parent']['prop']]:
|
|
42
|
+
RecursiveNode<DecrementDepth<D>, M, M[K]['parent']['node']> }
|
|
43
|
+
: {});
|
|
44
|
+
|
|
45
|
+
// ================== EXAMPLE USAGE ==================
|
|
46
|
+
|
|
47
|
+
// Define your base types (clean, no recursion)
|
|
48
|
+
type ABase = { name: string; foo: number };
|
|
49
|
+
type BBase = { title: string; bar: number };
|
|
50
|
+
type CBase = { label: string; baz: boolean };
|
|
51
|
+
type DBase = { tag: string; qux: string };
|
|
52
|
+
|
|
53
|
+
// Now define a NodeTypeMap describing the structure:
|
|
54
|
+
// Let's say we have a graph like before, but arbitrary children.
|
|
55
|
+
// A has three children: bChild -> B, cChild -> C, dChild -> D
|
|
56
|
+
// B, C, D each have a parent going back to A
|
|
57
|
+
// D also has a cLink -> C
|
|
58
|
+
|
|
59
|
+
type MyNodeTypeMap = {
|
|
60
|
+
A: {
|
|
61
|
+
base: ABase;
|
|
62
|
+
children: {
|
|
63
|
+
bChild: 'B';
|
|
64
|
+
cChild: 'C';
|
|
65
|
+
dChild: 'D';
|
|
66
|
+
};
|
|
67
|
+
// No parent defined for A (root)
|
|
68
|
+
};
|
|
69
|
+
B: {
|
|
70
|
+
base: BBase;
|
|
71
|
+
children: {
|
|
72
|
+
fooLink: 'C'; // D links to C as well
|
|
73
|
+
};
|
|
74
|
+
parent: { prop: 'aParent'; node: 'A' };
|
|
75
|
+
};
|
|
76
|
+
C: {
|
|
77
|
+
base: CBase;
|
|
78
|
+
// C has no children defined here
|
|
79
|
+
parent: { prop: 'aParent'; node: 'A' };
|
|
80
|
+
};
|
|
81
|
+
D: {
|
|
82
|
+
base: DBase;
|
|
83
|
+
children: {
|
|
84
|
+
cLink: 'C'; // D links to C as well
|
|
85
|
+
};
|
|
86
|
+
parent: { prop: 'aParent'; node: 'A' };
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Limit recursion to depth 2
|
|
91
|
+
type Depth2 = [unknown, unknown, unknown, unknown];
|
|
92
|
+
|
|
93
|
+
// Now we can create a type for each node expanded to Depth2:
|
|
94
|
+
type MyA = RecursiveNode<Depth2, MyNodeTypeMap, 'A'>;
|
|
95
|
+
type MyB = RecursiveNode<Depth2, MyNodeTypeMap, 'B'>;
|
|
96
|
+
type MyC = RecursiveNode<Depth2, MyNodeTypeMap, 'C'>;
|
|
97
|
+
type MyD = RecursiveNode<Depth2, MyNodeTypeMap, 'D'>;
|
|
98
|
+
|
|
99
|
+
// Create an instance of MyA:
|
|
100
|
+
const aInstance: MyA = {
|
|
101
|
+
name: "Root A",
|
|
102
|
+
foo: 1,
|
|
103
|
+
bChild: {
|
|
104
|
+
title: "B Node",
|
|
105
|
+
bar: 100,
|
|
106
|
+
aParent: {
|
|
107
|
+
name: "A Level 2",
|
|
108
|
+
foo: 2,
|
|
109
|
+
bChild: { title: "B2", bar: 200, aParent: { name: "A Terminal", foo: 3 } },
|
|
110
|
+
cChild: { label: "C2", baz: true, aParent: { name: "A Terminal", foo: 4 } },
|
|
111
|
+
dChild: {
|
|
112
|
+
tag: "D2",
|
|
113
|
+
qux: "XYZ",
|
|
114
|
+
aParent: { name: "A Terminal", foo: 5 },
|
|
115
|
+
cLink: { label: "C-Terminal", baz: false }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
cChild: {
|
|
120
|
+
label: "C Node",
|
|
121
|
+
baz: true,
|
|
122
|
+
aParent: {
|
|
123
|
+
name: "A Level 2C",
|
|
124
|
+
foo: 10,
|
|
125
|
+
bChild: { title: "B3", bar: 300, aParent: { name: "A Terminal", foo: 6 } },
|
|
126
|
+
cChild: { label: "C3", baz: false, aParent: { name: "A Terminal", foo: 7 } },
|
|
127
|
+
dChild: {
|
|
128
|
+
tag: "D3",
|
|
129
|
+
qux: "ABC",
|
|
130
|
+
aParent: { name: "A Terminal", foo: 8 },
|
|
131
|
+
cLink: { label: "C-Terminal2", baz: true }
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
dChild: {
|
|
136
|
+
tag: "D Node",
|
|
137
|
+
qux: "QWE",
|
|
138
|
+
aParent: {
|
|
139
|
+
name: "A Level 2D",
|
|
140
|
+
foo: 20,
|
|
141
|
+
bChild: { title: "B4", bar: 400, aParent: { name: "A Terminal", foo: 9 } },
|
|
142
|
+
cChild: { label: "C4", baz: true, aParent: { name: "A Terminal", foo: 11 } },
|
|
143
|
+
dChild: {
|
|
144
|
+
tag: "D4",
|
|
145
|
+
qux: "DEF",
|
|
146
|
+
aParent: { name: "A Terminal", foo: 12 },
|
|
147
|
+
cLink: { label: "C-Terminal3", baz: false }
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
cLink: {
|
|
151
|
+
label: "C Link Node",
|
|
152
|
+
baz: false
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
console.log(aInstance.name); // "Root A"
|
|
158
|
+
console.log(aInstance.bChild.title); // "B Node"
|
|
159
|
+
console.log(aInstance.bChild.aParent.cChild.label); // "C2"
|
|
160
|
+
console.log(aInstance.dChild.aParent.dChild.cLink.baz); // true
|
|
161
|
+
|
|
162
|
+
// interface HasChild<C> {
|
|
163
|
+
// child: C;
|
|
164
|
+
// }
|
|
165
|
+
|
|
166
|
+
// interface HasParent<P> {
|
|
167
|
+
// parent: P;
|
|
168
|
+
// }
|
|
169
|
+
|
|
170
|
+
// interface AType<C> extends HasChild<C> {
|
|
171
|
+
// name: string;
|
|
172
|
+
// }
|
|
173
|
+
|
|
174
|
+
// interface BType<P> extends HasParent<P> {
|
|
175
|
+
// title: string;
|
|
176
|
+
// }
|
|
177
|
+
|
|
178
|
+
// // Here is the key part: By using a circular type definition, we create a
|
|
179
|
+
// // specific pair (CyclicA, CyclicB) that point to each other generically.
|
|
180
|
+
// // 'CyclicA' extends 'AType' and expects a child of type 'CyclicB'.
|
|
181
|
+
// // 'CyclicB' extends 'BType' and expects a parent of type 'CyclicA'.
|
|
182
|
+
|
|
183
|
+
// // Note: TypeScript allows this pattern as long as the interfaces are defined first.
|
|
184
|
+
// // The cycle is established by the subsequent type definitions.
|
|
185
|
+
|
|
186
|
+
// type CyclicA = AType<CyclicB>;
|
|
187
|
+
// type CyclicB = BType<CyclicA>;
|
|
188
|
+
|
|
189
|
+
// // Now 'CyclicA' and 'CyclicB' are fully defined, with a cyclical reference:
|
|
190
|
+
// // CyclicA -> child: CyclicB
|
|
191
|
+
// // CyclicB -> parent: CyclicA
|
|
192
|
+
|
|
193
|
+
// // Example usage:
|
|
194
|
+
// const aInstance: CyclicA ;
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
// // Establish the cycle at runtime.
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
// // We can now traverse back and forth:
|
|
201
|
+
// console.log(aInstance.name); // "Node A"
|
|
202
|
+
// console.log(aInstance.child.title); // "Node B"
|
|
203
|
+
// console.log(aInstance.child.parent.name); // "Node A" (cycle complete)
|
|
204
|
+
|
|
205
|
+
// // This pattern is generic. If you want another pair of cyclical types,
|
|
206
|
+
// // say X and Y, you can do:
|
|
207
|
+
|
|
208
|
+
// type CyclicX = XType<CyclicY>; // define similarly using HasChild/HasParent
|
|
209
|
+
// type CyclicY = YType<CyclicX>;
|
|
210
|
+
// // ...and so forth, using the same building blocks.
|
|
211
|
+
|