1
- import { clone , CloneMethod } from "./clone" ;
2
1
import { Collection } from "./collection" ;
3
- import { resolveTransformParams } from "./utils " ;
2
+ import { clone , CloneMethod } from "./clone " ;
4
3
import { ltHelper , gtHelper , aeqHelper , sortHelper } from "./helper" ;
5
4
import { Doc , Query } from "../../common/types" ;
6
5
@@ -17,6 +16,45 @@ export type ANY = any;
17
16
18
17
*/
19
18
19
+ // used to recursively scan hierarchical transform step object for param substitution
20
+ function resolveTransformObject ( subObj : object , params : object , depth : number = 0 ) {
21
+ let prop ;
22
+ let pname ;
23
+
24
+ if ( ++ depth >= 10 ) return subObj ;
25
+
26
+ for ( prop in subObj ) {
27
+ if ( typeof subObj [ prop ] === "string" && subObj [ prop ] . indexOf ( "[%lktxp]" ) === 0 ) {
28
+ pname = subObj [ prop ] . substring ( 8 ) ;
29
+ if ( params [ pname ] !== undefined ) {
30
+ subObj [ prop ] = params [ pname ] ;
31
+ }
32
+ } else if ( typeof subObj [ prop ] === "object" ) {
33
+ subObj [ prop ] = resolveTransformObject ( subObj [ prop ] , params , depth ) ;
34
+ }
35
+ }
36
+
37
+ return subObj ;
38
+ }
39
+
40
+ // top level utility to resolve an entire (single) transform (array of steps) for parameter substitution
41
+ function resolveTransformParams ( transform : any , params : object ) {
42
+ let idx ;
43
+ let clonedStep ;
44
+ const resolvedTransform = [ ] ;
45
+
46
+ if ( typeof params === "undefined" ) return transform ;
47
+
48
+ // iterate all steps in the transform array
49
+ for ( idx = 0 ; idx < transform . length ; idx ++ ) {
50
+ // clone transform so our scan/replace can operate directly on cloned transform
51
+ clonedStep = clone ( transform [ idx ] , CloneMethod . SHALLOW_RECURSE_OBJECTS ) ;
52
+ resolvedTransform . push ( resolveTransformObject ( clonedStep , params ) ) ;
53
+ }
54
+
55
+ return resolvedTransform ;
56
+ }
57
+
20
58
function containsCheckFn ( a : ANY ) {
21
59
if ( typeof a === "string" || Array . isArray ( a ) ) {
22
60
return ( b : ANY ) => ( a as string ) . indexOf ( b ) !== - 1 ;
@@ -1014,10 +1052,10 @@ export class Resultset<E extends object = object> {
1014
1052
forceCloneMethod = CloneMethod . SHALLOW ;
1015
1053
}
1016
1054
1017
- // if collection has delta changes active, then force clones and use 'parse-stringify' for effective change tracking of nested objects
1055
+ // if collection has delta changes active, then force clones and use CloneMethod.DEEP for effective change tracking of nested objects
1018
1056
if ( ! this . collection . disableDeltaChangesApi ) {
1019
1057
forceClones = true ;
1020
- forceCloneMethod = CloneMethod . PARSE_STRINGIFY ;
1058
+ forceCloneMethod = CloneMethod . DEEP ;
1021
1059
}
1022
1060
1023
1061
// if this has no filters applied, just return collection.data
@@ -1140,7 +1178,7 @@ export class Resultset<E extends object = object> {
1140
1178
*/
1141
1179
//eqJoin<T extends object>(joinData: T[] | Resultset<T>, leftJoinKey: string | ((obj: E) => string), rightJoinKey: string | ((obj: T) => string)): Resultset<{ left: E; right: T; }>;
1142
1180
// eqJoin<T extends object, U extends object>(joinData: T[] | Resultset<T>, leftJoinKey: string | ((obj: E) => string), rightJoinKey: string | ((obj: T) => string), mapFun?: (a: E, b: T) => U, dataOptions?: Resultset.DataOptions): Resultset<U> {
1143
- eqJoin ( joinData : ANY , leftJoinKey : string | Function , rightJoinKey : string | Function , mapFun ?: Function , dataOptions ?: ANY ) : ANY {
1181
+ eqJoin ( joinData : ANY , leftJoinKey : string | Function , rightJoinKey : string | Function , mapFun ?: Function , dataOptions ?: ANY ) : ANY {
1144
1182
// eqJoin<T extends object, U extends object>(joinData: T[] | Resultset<T>, leftJoinKey: string | ((obj: E) => string), rightJoinKey: string | ((obj: T) => string), mapFun?: (a: E, b: T) => U, dataOptions?: Resultset.DataOptions): Resultset<U> {
1145
1183
let leftData = [ ] ;
1146
1184
let leftDataLength ;
@@ -1204,7 +1242,7 @@ export class Resultset<E extends object = object> {
1204
1242
* @param {boolean } dataOptions.forceClones - forcing the return of cloned objects to your map object
1205
1243
* @param {string } dataOptions.forceCloneMethod - Allows overriding the default or collection specified cloning method.
1206
1244
*/
1207
- map < U extends object > ( mapFun : ( obj : E , index : number , array : E [ ] ) => U , dataOptions ?: Resultset . DataOptions ) : Resultset < U > {
1245
+ map < U extends object > ( mapFun : ( obj : E , index : number , array : E [ ] ) => U , dataOptions ?: Resultset . DataOptions ) : Resultset < U > {
1208
1246
let data = this . data ( dataOptions ) . map ( mapFun ) ;
1209
1247
//return return a new resultset with no filters
1210
1248
this . collection = new Collection ( "mappedData" ) ;
0 commit comments