1- import { clone , CloneMethod } from "./clone" ;
21import { Collection } from "./collection" ;
3- import { resolveTransformParams } from "./utils " ;
2+ import { clone , CloneMethod } from "./clone " ;
43import { ltHelper , gtHelper , aeqHelper , sortHelper } from "./helper" ;
54import { Doc , Query } from "../../common/types" ;
65
@@ -17,6 +16,45 @@ export type ANY = any;
1716
1817 */
1918
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+
2058function containsCheckFn ( a : ANY ) {
2159 if ( typeof a === "string" || Array . isArray ( a ) ) {
2260 return ( b : ANY ) => ( a as string ) . indexOf ( b ) !== - 1 ;
@@ -1014,10 +1052,10 @@ export class Resultset<E extends object = object> {
10141052 forceCloneMethod = CloneMethod . SHALLOW ;
10151053 }
10161054
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
10181056 if ( ! this . collection . disableDeltaChangesApi ) {
10191057 forceClones = true ;
1020- forceCloneMethod = CloneMethod . PARSE_STRINGIFY ;
1058+ forceCloneMethod = CloneMethod . DEEP ;
10211059 }
10221060
10231061 // if this has no filters applied, just return collection.data
@@ -1140,7 +1178,7 @@ export class Resultset<E extends object = object> {
11401178 */
11411179 //eqJoin<T extends object>(joinData: T[] | Resultset<T>, leftJoinKey: string | ((obj: E) => string), rightJoinKey: string | ((obj: T) => string)): Resultset<{ left: E; right: T; }>;
11421180 // 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 {
11441182// 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> {
11451183 let leftData = [ ] ;
11461184 let leftDataLength ;
@@ -1204,7 +1242,7 @@ export class Resultset<E extends object = object> {
12041242 * @param {boolean } dataOptions.forceClones - forcing the return of cloned objects to your map object
12051243 * @param {string } dataOptions.forceCloneMethod - Allows overriding the default or collection specified cloning method.
12061244 */
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 > {
12081246 let data = this . data ( dataOptions ) . map ( mapFun ) ;
12091247 //return return a new resultset with no filters
12101248 this . collection = new Collection ( "mappedData" ) ;
0 commit comments