11import * as _ from 'underscore'
22import { ProtectedString } from './protectedString'
33import * as objectPath from 'object-path'
4- // eslint-disable-next-line node /no-extraneous-import
4+ // eslint-disable-next-line n /no-extraneous-import
55import type { Condition , Filter , UpdateFilter } from 'mongodb'
66import { clone } from './lib'
77
@@ -31,8 +31,8 @@ export type MongoFieldSpecifierOnesStrict<T extends Record<string, any>> = {
3131 [ key in keyof T ] ?: T [ key ] extends ProtectedString < any >
3232 ? 1
3333 : T [ key ] extends object | undefined
34- ? MongoFieldSpecifierOnesStrict < T [ key ] > | 1
35- : 1
34+ ? MongoFieldSpecifierOnesStrict < T [ key ] > | 1
35+ : 1
3636}
3737
3838export interface FindOneOptions < TDoc > {
@@ -154,7 +154,7 @@ export function mongoWhere<T>(o: Record<string, any>, selector: MongoQuery<T>):
154154}
155155export function mongoFindOptions < TDoc extends { _id : ProtectedString < any > } > (
156156 docs0 : ReadonlyArray < TDoc > ,
157- options ?: FindOptions < TDoc >
157+ options ?: FindOptions < TDoc > ,
158158) : TDoc [ ] {
159159 let docs = [ ...docs0 ] // Shallow clone it
160160 if ( options ) {
@@ -241,7 +241,7 @@ export function mongoFindOptions<TDoc extends { _id: ProtectedString<any> }>(
241241export function mongoModify < TDoc extends { _id : ProtectedString < any > } > (
242242 selector : MongoQuery < TDoc > ,
243243 doc : TDoc ,
244- modifier : MongoModifier < TDoc >
244+ modifier : MongoModifier < TDoc > ,
245245) : TDoc {
246246 let replace = false
247247 for ( const [ key , value ] of Object . entries < any > ( modifier ) ) {
@@ -293,7 +293,7 @@ export function mutatePath<T>(
293293 obj : Record < string , unknown > ,
294294 path : string ,
295295 substitutions : Record < string , unknown > ,
296- mutator : ( parentObj : Record < string , unknown > , key : string ) => T
296+ mutator : ( parentObj : Record < string , unknown > , key : string ) => T ,
297297) : void {
298298 if ( ! path ) throw new Error ( 'parameter path missing' )
299299
@@ -333,7 +333,7 @@ export function mutatePath<T>(
333333 if ( attr === '$' ) {
334334 if ( ! _ . isArray ( o ) )
335335 throw new Error (
336- 'Object at "' + currentPath + '" is not an array ("' + o + '") (in path "' + path + '")'
336+ 'Object at "' + currentPath + '" is not an array ("' + o + '") (in path "' + path + '")' ,
337337 )
338338
339339 const info = generateWildcardAttrInfo ( )
@@ -352,7 +352,7 @@ export function mutatePath<T>(
352352 } else {
353353 if ( ! _ . isObject ( o [ attr ] ) )
354354 throw new Error (
355- 'Object propery "' + attr + '" is not an object ("' + o [ attr ] + '") (in path "' + path + '")'
355+ 'Object propery "' + attr + '" is not an object ("' + o [ attr ] + '") (in path "' + path + '")' ,
356356 )
357357 }
358358 o = o [ attr ]
@@ -389,7 +389,13 @@ export function pushOntoPath<T>(obj: Record<string, unknown>, path: string, valu
389389 } else {
390390 if ( ! _ . isArray ( o [ lastAttr ] ) )
391391 throw new Error (
392- 'Object propery "' + lastAttr + '" is not an array ("' + o [ lastAttr ] + '") (in path "' + path + '")'
392+ 'Object propery "' +
393+ lastAttr +
394+ '" is not an array ("' +
395+ o [ lastAttr ] +
396+ '") (in path "' +
397+ path +
398+ '")' ,
393399 )
394400 }
395401 const arr : any = o [ lastAttr ]
@@ -410,7 +416,13 @@ export function pullFromPath<T>(obj: Record<string, unknown>, path: string, matc
410416 if ( _ . has ( o , lastAttr ) ) {
411417 if ( ! _ . isArray ( o [ lastAttr ] ) )
412418 throw new Error (
413- 'Object propery "' + lastAttr + '" is not an array ("' + o [ lastAttr ] + '") (in path "' + path + '")'
419+ 'Object propery "' +
420+ lastAttr +
421+ '" is not an array ("' +
422+ o [ lastAttr ] +
423+ '") (in path "' +
424+ path +
425+ '")' ,
414426 )
415427
416428 return ( o [ lastAttr ] = _ . filter ( o [ lastAttr ] as any , ( entry : T ) => ! _ . isMatch ( entry , matchValue ) ) )
@@ -431,13 +443,13 @@ export function setOntoPath<T>(
431443 obj : Record < string , unknown > ,
432444 path : string ,
433445 substitutions : Record < string , unknown > ,
434- valueToSet : T
446+ valueToSet : T ,
435447) : void {
436448 mutatePath (
437449 obj ,
438450 path ,
439451 substitutions ,
440- ( parentObj : Record < string , unknown > , key : string ) => ( parentObj [ key ] = valueToSet )
452+ ( parentObj : Record < string , unknown > , key : string ) => ( parentObj [ key ] = valueToSet ) ,
441453 )
442454}
443455/**
0 commit comments