orange-orm 4.5.0-beta.0 → 4.5.0-beta.2
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 +6 -1
- package/docs/changelog.md +4 -0
- package/package.json +10 -6
- package/src/applyPatch.js +5 -2
- package/src/client/index.js +3 -2
- package/src/client/index.mjs +13552 -6381
- package/src/client/rollup.config.js +24 -4
- package/src/client/stringify.js +2 -9
- package/src/createDomain.js +7 -28
- package/src/d1/newDatabase.js +23 -37
- package/src/d1/newPool.js +6 -6
- package/src/d1/newTransaction.js +1 -0
- package/src/d1/pool/newGenericPool.js +2 -14
- package/src/emitEvent.js +6 -4
- package/src/emptyFilter.js +12 -12
- package/src/format.js +9 -0
- package/src/generic-pool.js +274 -313
- package/src/getManyDto/newQuery.js +5 -5
- package/src/getManyDto/query/newSingleQuery.js +5 -5
- package/src/getManyDto.js +73 -41
- package/src/hostExpress/cycle.ts +211 -0
- package/src/hostExpress/executePath.js +361 -357
- package/src/hostExpress.js +2 -7
- package/src/hostLocal.js +9 -9
- package/src/index.js +13 -17
- package/src/indexBrowser.js +39 -0
- package/src/mssql/newDatabase.js +19 -31
- package/src/mssql/newPool.js +2 -2
- package/src/mssql/newTransaction.js +4 -3
- package/src/mssql/pool/newGenericPool.js +1 -13
- package/src/mySql/deleteFromSql.js +5 -5
- 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 +2 -2
- package/src/mySql/pool/newGenericPool.js +2 -15
- package/src/mySql/quote.js +1 -0
- package/src/newId.js +2 -1
- package/src/newImmutable.js +1 -2
- package/src/oracle/deleteFromSql.js +5 -5
- 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 +5 -5
- package/src/oracle/newPool.js +10 -10
- package/src/oracle/newTransaction.js +2 -1
- package/src/oracle/pool/newGenericPool.js +2 -14
- package/src/oracle/quote.js +1 -0
- package/src/oracle/wrapQuery.js +0 -3
- package/src/package.json +5 -0
- package/src/patchRow.js +2 -2
- package/src/patchTable.js +6 -5
- package/src/pg/deleteFromSql.js +5 -5
- 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 +2 -1
- package/src/pg/pool/newPgPool.js +23 -16
- package/src/pg/pool/parseSearchPathParam.js +10 -0
- 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/promisify.js +24 -0
- package/src/query.js +2 -2
- package/src/sap/deleteFromSql.js +3 -3
- 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 +2 -1
- package/src/sap/quote.js +1 -0
- package/src/sqlite/deleteFromSql.js +5 -5
- 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 +2 -1
- package/src/sqlite/pool/newGenericPool.js +1 -13
- 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/tryParseISO.js +6 -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 +1 -72
- package/src/table/column/newBoolean.js +2 -53
- 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/column/utils.js +113 -0
- package/src/table/column.js +6 -2
- 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 -10
- package/src/table/commands/newGetLastInsertedCommand.js +4 -4
- package/src/table/commands/newGetLastInsertedCommandCore.js +5 -5
- package/src/table/commands/newInsertCommand.js +5 -3
- package/src/table/commands/newInsertCommandCore.js +12 -12
- 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 +2 -14
- 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 +3 -10
- 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/newCascadeDeleteStrategy.js +1 -7
- 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 +6 -12
- 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/newParameterized.js +8 -11
- package/src/table/query/newSingleQuery.js +7 -7
- package/src/table/query/singleQuery/columnSql/joinLegToColumnSql.js +2 -15
- package/src/table/query/singleQuery/columnSql/newJoinedColumnSql.js +2 -25
- package/src/table/query/singleQuery/columnSql/newShallowColumnSql.js +4 -4
- package/src/table/query/singleQuery/columnSql/sharedJoinUtils.js +37 -0
- package/src/table/query/singleQuery/joinSql/joinLegToJoinSql.js +2 -7
- 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 -8
- 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 +7 -7
- package/src/table/query/singleQuery/newWhereSql.js +3 -3
- package/src/table/quote.js +4 -4
- package/src/table/relatedTable/aggregate.js +2 -8
- package/src/table/relatedTable/all.js +6 -12
- package/src/table/relatedTable/any.js +4 -11
- 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 +4 -10
- 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 -9
- 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 +25 -17
- 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 +6 -13
- package/src/table/resultToRows/dbRowsToRows.js +2 -2
- package/src/table/resultToRows/decodeDbRow.js +2 -2
- package/src/table/resultToRows/delete/removeFromCache.js +4 -11
- package/src/table/resultToRows/delete.js +6 -6
- package/src/table/resultToRows/newDecodeDbRow.js +19 -25
- package/src/table/resultToRows/toDto/extractStrategy.js +1 -7
- 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 +3 -13
- 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 +56 -53
- package/src/tedious/deleteFromSql.js +5 -5
- 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 +4 -5
- package/src/tedious/getManyDto/query/newSubQueries/manyLegToQuery.js +4 -5
- package/src/tedious/getManyDto/query/newSubQueries/oneLegToQuery.js +13 -14
- package/src/tedious/getManyDto/query/newSubQueries.js +9 -26
- 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 +3 -4
- package/src/tedious/pool/newGenericPool.js +1 -13
- package/src/tedious/quote.js +1 -0
- package/src/validateDeleteConflict.js +4 -2
- package/src/createDomain/negotiateForwardProperty.js +0 -23
- package/src/d1/pool/defaults.js +0 -45
- 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/table/createJSONReadStream.js +0 -7
- package/src/table/createJSONReadStreamDefault.js +0 -33
- package/src/table/createJSONReadStreamNative.js +0 -31
- package/src/table/createReadStream.js +0 -24
- package/src/table/createReadStreamCoreNative.js +0 -40
- package/src/table/createReadStreamDefault.js +0 -102
- package/src/table/createReadStreamNative.js +0 -17
- package/src/table/readStream/extractLimit.js +0 -7
- package/src/table/readStream/extractOrderBy.js +0 -59
- package/src/table/readStream/mySql/newQuery.js +0 -16
- package/src/table/readStream/mySql/query/newSingleQuery.js +0 -21
- package/src/table/readStream/mySql/query/newSubQueries/joinLegToQuery.js +0 -20
- package/src/table/readStream/mySql/query/newSubQueries/manyLegToQuery.js +0 -22
- package/src/table/readStream/mySql/query/newSubQueries/newQueryCore.js +0 -9
- package/src/table/readStream/mySql/query/newSubQueries/newSingleQueryCore.js +0 -18
- package/src/table/readStream/mySql/query/newSubQueries/oneLegToQuery.js +0 -22
- package/src/table/readStream/mySql/query/newSubQueries.js +0 -47
- package/src/table/readStream/mySql/query/singleQuery/newShallowColumnSql.js +0 -18
- package/src/table/readStream/newQuery.js +0 -32
- package/src/table/readStream/newQueryStream.js +0 -8
- package/src/table/readStream/pg/newQuery.js +0 -8
- package/src/table/readStream/pg/newQueryCore.js +0 -17
- package/src/table/readStream/pg/query/newSingleQuery.js +0 -19
- package/src/table/readStream/pg/query/newSubQueries/joinLegToQuery.js +0 -19
- package/src/table/readStream/pg/query/newSubQueries/manyLegToQuery.js +0 -22
- package/src/table/readStream/pg/query/newSubQueries/oneLegToQuery.js +0 -19
- package/src/table/readStream/pg/query/newSubQueries.js +0 -47
- package/src/table/readStream/pg/query/singleQuery/newShallowColumnSql.js +0 -20
- package/src/table/readStreamDefault/createBatchFilter.js +0 -39
- package/src/tedious/pool/defaults.js +0 -45
- package/src/useHook.js +0 -9
|
@@ -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
|
@@ -3,20 +3,21 @@ const newQuery = require('./getManyDto/newQuery');
|
|
|
3
3
|
const negotiateRawSqlFilter = require('./table/column/negotiateRawSqlFilter');
|
|
4
4
|
const strategyToSpan = require('./table/strategyToSpan');
|
|
5
5
|
const executeQueries = require('./table/executeQueries');
|
|
6
|
+
const getSessionSingleton = require('./table/getSessionSingleton');
|
|
6
7
|
|
|
7
|
-
async function getManyDto(table, filter, strategy, spanFromParent, updateParent) {
|
|
8
|
-
filter = negotiateRawSqlFilter(filter, table);
|
|
8
|
+
async function getManyDto(context, table, filter, strategy, spanFromParent, updateParent) {
|
|
9
|
+
filter = negotiateRawSqlFilter(context, filter, table);
|
|
9
10
|
if (strategy && strategy.where) {
|
|
10
|
-
let arg = typeof strategy.where === 'function' ? strategy.where(table) : strategy.where;
|
|
11
|
-
filter = filter.and(arg);
|
|
11
|
+
let arg = typeof strategy.where === 'function' ? strategy.where(context, table) : strategy.where;
|
|
12
|
+
filter = filter.and(context, arg);
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
let span = spanFromParent || strategyToSpan(table, strategy);
|
|
15
16
|
let alias = table._dbName;
|
|
16
17
|
|
|
17
|
-
const query = newQuery(table, filter, span, alias);
|
|
18
|
-
const res = await executeQueries([query]);
|
|
19
|
-
return decode(strategy, span, await res[0], undefined, updateParent);
|
|
18
|
+
const query = newQuery(context, table, filter, span, alias);
|
|
19
|
+
const res = await executeQueries(context, [query]);
|
|
20
|
+
return decode(context, strategy, span, await res[0], undefined, updateParent);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
function newCreateRow(span) {
|
|
@@ -149,7 +150,7 @@ function hasManyRelations(span) {
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys(rows[0]) : [], updateParent) {
|
|
153
|
+
async function decode(context, strategy, span, rows, keys = rows.length > 0 ? Object.keys(rows[0]) : [], updateParent) {
|
|
153
154
|
const table = span.table;
|
|
154
155
|
let columnsMap = span.columns;
|
|
155
156
|
const columns = table._columns.filter(column => !columnsMap || columnsMap.get(column));
|
|
@@ -179,18 +180,16 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
const column = columns[j];
|
|
182
|
-
outRow[column.alias] = column.decode(row[keys[j]]);
|
|
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;
|
|
192
|
-
// if (parentRows)
|
|
193
|
-
// parentRows[i][parentProp] = outRow;
|
|
194
193
|
if (updateParent)
|
|
195
194
|
updateParent(outRow, i);
|
|
196
195
|
if (shouldCreateMap) {
|
|
@@ -208,13 +207,11 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
208
207
|
const all = [];
|
|
209
208
|
|
|
210
209
|
if (shouldCreateMap) {
|
|
211
|
-
all.push(decodeManyRelations(strategy, span));
|
|
212
|
-
all.push(decodeRelations2(strategy, span, rows, outRows, keys));
|
|
210
|
+
all.push(decodeManyRelations(context, strategy, span));
|
|
211
|
+
all.push(decodeRelations2(context, strategy, span, rows, outRows, keys));
|
|
213
212
|
}
|
|
214
|
-
// decodeRelations2(strategy, span, rows, outRows, keys);
|
|
215
|
-
// }
|
|
216
213
|
else
|
|
217
|
-
all.push(decodeRelations2(strategy, span, rows, outRows, keys));
|
|
214
|
+
all.push(decodeRelations2(context, strategy, span, rows, outRows, keys));
|
|
218
215
|
|
|
219
216
|
await Promise.all(all);
|
|
220
217
|
|
|
@@ -240,70 +237,105 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
|
|
|
240
237
|
|
|
241
238
|
}
|
|
242
239
|
|
|
243
|
-
async function decodeManyRelations(strategy, span) {
|
|
240
|
+
async function decodeManyRelations(context, strategy, span) {
|
|
241
|
+
const maxParameters = getSessionSingleton(context, 'maxParameters');
|
|
242
|
+
const maxRows = maxParameters
|
|
243
|
+
? maxParameters * span.table._primaryColumns.length
|
|
244
|
+
: undefined;
|
|
245
|
+
|
|
244
246
|
const promises = [];
|
|
245
247
|
const c = {};
|
|
246
248
|
c.visitJoin = () => { };
|
|
247
249
|
c.visitOne = c.visitJoin;
|
|
248
250
|
|
|
251
|
+
// Helper function to split an array into chunks
|
|
252
|
+
function chunk(array, size) {
|
|
253
|
+
const results = [];
|
|
254
|
+
for (let i = 0; i < array.length; i += size) {
|
|
255
|
+
results.push(array.slice(i, i + size));
|
|
256
|
+
}
|
|
257
|
+
return results;
|
|
258
|
+
}
|
|
259
|
+
|
|
249
260
|
c.visitMany = function(leg) {
|
|
250
261
|
const name = leg.name;
|
|
251
262
|
const table = span.table;
|
|
252
263
|
const relation = table._relations[name];
|
|
253
264
|
const rowsMap = span._rowsMap;
|
|
254
265
|
|
|
255
|
-
const filter = createOneFilter(relation, span._ids);
|
|
256
266
|
const extractKey = createExtractKey(leg);
|
|
257
267
|
const extractFromMap = createExtractFromMap(rowsMap, table._primaryColumns);
|
|
258
268
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
269
|
+
// If maxRows is defined, chunk the IDs before calling getManyDto
|
|
270
|
+
if (maxRows) {
|
|
271
|
+
const chunkedIds = chunk(span._ids, maxRows);
|
|
272
|
+
for (const idsChunk of chunkedIds) {
|
|
273
|
+
const filter = createOneFilter(context, relation, idsChunk);
|
|
274
|
+
const p = getManyDto(
|
|
275
|
+
context,
|
|
276
|
+
relation.childTable,
|
|
277
|
+
filter,
|
|
278
|
+
strategy[name],
|
|
279
|
+
leg.span,
|
|
280
|
+
updateParent
|
|
281
|
+
);
|
|
282
|
+
promises.push(p);
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
// Otherwise, do the entire set in one go
|
|
286
|
+
const filter = createOneFilter(context, relation, span._ids);
|
|
287
|
+
const p = getManyDto(
|
|
288
|
+
context,
|
|
289
|
+
relation.childTable,
|
|
290
|
+
filter,
|
|
291
|
+
strategy[name],
|
|
292
|
+
leg.span,
|
|
293
|
+
updateParent
|
|
294
|
+
);
|
|
295
|
+
promises.push(p);
|
|
296
|
+
}
|
|
267
297
|
|
|
268
298
|
function updateParent(subRow) {
|
|
269
299
|
const key = extractKey(subRow);
|
|
270
300
|
const parentRow = extractFromMap(key);
|
|
271
301
|
parentRow[name].push(subRow);
|
|
272
302
|
}
|
|
273
|
-
|
|
274
|
-
promises.push(p);
|
|
275
303
|
};
|
|
276
304
|
|
|
277
305
|
function createExtractKey(leg) {
|
|
278
306
|
if (leg.columns.length === 1) {
|
|
279
307
|
const alias = leg.columns[0].alias;
|
|
280
308
|
return (row) => row[alias];
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
309
|
+
} else {
|
|
283
310
|
const aliases = leg.columns.map(column => column.alias);
|
|
284
311
|
return (row) => aliases.map(alias => row[alias]);
|
|
285
312
|
}
|
|
286
313
|
}
|
|
314
|
+
|
|
287
315
|
function createExtractFromMap(map, primaryColumns) {
|
|
288
|
-
if (primaryColumns.length === 1)
|
|
316
|
+
if (primaryColumns.length === 1) {
|
|
289
317
|
return (key) => map.get(key);
|
|
290
|
-
else
|
|
318
|
+
} else {
|
|
291
319
|
return getFromMap.bind(null, map, primaryColumns);
|
|
320
|
+
}
|
|
292
321
|
}
|
|
293
322
|
|
|
323
|
+
// Visit all legs
|
|
294
324
|
span.legs.forEach(onEachLeg);
|
|
295
325
|
|
|
296
326
|
function onEachLeg(leg) {
|
|
297
327
|
leg.accept(c);
|
|
298
328
|
}
|
|
299
329
|
|
|
330
|
+
// Wait until all promises resolve
|
|
300
331
|
await Promise.all(promises);
|
|
301
332
|
}
|
|
302
|
-
|
|
333
|
+
|
|
334
|
+
async function decodeRelations2(context, strategy, span, rawRows, resultRows, keys) {
|
|
303
335
|
const c = {};
|
|
304
336
|
c.visitJoin = function(leg) {
|
|
305
337
|
const name = leg.name;
|
|
306
|
-
return decode(strategy[name], leg.span, rawRows, keys, updateParent);
|
|
338
|
+
return decode(context, strategy[name], leg.span, rawRows, keys, updateParent);
|
|
307
339
|
|
|
308
340
|
function updateParent(subRow, i) {
|
|
309
341
|
resultRows[i][name] = subRow;
|
|
@@ -323,11 +355,11 @@ async function decodeRelations2(strategy, span, rawRows, resultRows, keys) {
|
|
|
323
355
|
await processLegsSequentially(span.legs);
|
|
324
356
|
}
|
|
325
357
|
|
|
326
|
-
function createOneFilter(relation, ids) {
|
|
358
|
+
function createOneFilter(context, relation, ids) {
|
|
327
359
|
const columns = relation.joinRelation.columns;
|
|
328
360
|
|
|
329
361
|
if (columns.length === 1)
|
|
330
|
-
return columns[0].in(ids);
|
|
362
|
+
return columns[0].in(context, ids);
|
|
331
363
|
|
|
332
364
|
else
|
|
333
365
|
return createCompositeFilter();
|
|
@@ -338,11 +370,11 @@ function createOneFilter(relation, ids) {
|
|
|
338
370
|
let nextFilter;
|
|
339
371
|
for (let i = 0; i < columns.length; i++) {
|
|
340
372
|
if (nextFilter)
|
|
341
|
-
nextFilter = nextFilter.and(columns[i].eq(id[i]));
|
|
373
|
+
nextFilter = nextFilter.and(context, columns[i].eq(context, id[i]));
|
|
342
374
|
else
|
|
343
|
-
nextFilter = columns[i].eq(id[i]);
|
|
375
|
+
nextFilter = columns[i].eq(context, id[i]);
|
|
344
376
|
}
|
|
345
|
-
filter = filter.or(nextFilter);
|
|
377
|
+
filter = filter.or(context, nextFilter);
|
|
346
378
|
}
|
|
347
379
|
return filter;
|
|
348
380
|
}
|
|
@@ -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
|
+
|