Skip to content

Commit 7b6c477

Browse files
Merge pull request #267 from shiftcode/#257-get-rid-of-lodash_v2
#257 get rid of lodash v2
2 parents ff4b6e8 + 2cf34d4 commit 7b6c477

25 files changed

+384
-28
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"@commitlint/config-conventional": "^8.1.0",
6060
"@commitlint/prompt-cli": "^8.1.0",
6161
"@types/jest": "^24.0.18",
62-
"@types/lodash": "^4.14.137",
6362
"@types/node": "8.10.40",
6463
"@types/uuid": "^3.4.5",
6564
"aws-sdk": "^2.401.0",
@@ -68,7 +67,6 @@
6867
"husky": "^3.0.4",
6968
"jest": "^24.9.0",
7069
"lint-staged": "^9.2.3",
71-
"lodash": "^4.17.11",
7270
"lodash.camelcase": "^4.3.0",
7371
"prettier": "^1.18.2",
7472
"reflect-metadata": "^0.1.13",
@@ -87,7 +85,6 @@
8785
},
8886
"peerDependencies": {
8987
"aws-sdk": "^2.401.0",
90-
"lodash": "^4.17.11",
9188
"reflect-metadata": "^0.1.12",
9289
"tslib": "^1.10.0",
9390
"uuid": "^3.3.2"

src/decorator/impl/model/model.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @module decorators
33
*/
44
import * as DynamoDB from 'aws-sdk/clients/dynamodb'
5-
import { kebabCase } from 'lodash'
5+
import { kebabCase } from '../../../helper/kebab-case.function'
66
import { ModelMetadata } from '../../metadata/model-metadata.model'
77
import { PropertyMetadata } from '../../metadata/property-metadata.model'
88
import { SecondaryIndex } from '../index/secondary-index'

src/dynamo/expression/condition-expression-builder.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// tslint:disable:max-classes-per-file
2-
import { has } from 'lodash'
32
import { ComplexModel } from '../../../test/models'
43
import { Form, FormId, formIdMapper, FormType } from '../../../test/models/real-world'
54
import { CollectionProperty } from '../../decorator/impl/collection/collection-property.decorator'
@@ -304,9 +303,9 @@ describe('expressions', () => {
304303

305304
expect(condition.attributeValues).toBeDefined()
306305
expect(Object.keys(condition.attributeValues).length).toBe(2)
307-
expect(has(condition.attributeValues, ':counter')).toBeTruthy()
306+
expect(':counter' in condition.attributeValues).toBeTruthy()
308307
expect(condition.attributeValues[':counter']).toEqual({ N: '2' })
309-
expect(has(condition.attributeValues, ':counter_2')).toBeTruthy()
308+
expect(':counter_2' in condition.attributeValues).toBeTruthy()
310309
expect(condition.attributeValues[':counter_2']).toEqual({ N: '5' })
311310
})
312311

@@ -331,9 +330,9 @@ describe('expressions', () => {
331330

332331
expect(condition.attributeValues).toBeDefined()
333332
expect(Object.keys(condition.attributeValues).length).toBe(2)
334-
expect(has(condition.attributeValues, ':creationDate')).toBeTruthy()
333+
expect(':creationDate' in condition.attributeValues).toBeTruthy()
335334
expect(condition.attributeValues[':creationDate']).toEqual({ S: date1.toISOString() })
336-
expect(has(condition.attributeValues, ':creationDate_2')).toBeTruthy()
335+
expect(':creationDate_2' in condition.attributeValues).toBeTruthy()
337336
expect(condition.attributeValues[':creationDate_2']).toEqual({ S: date2.toISOString() })
338337
})
339338
})

src/dynamo/expression/condition-expression-builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/**
22
* @module expression
33
*/
4-
import { curry, isPlainObject } from 'lodash'
54
import { Metadata } from '../../decorator/metadata/metadata'
65
import {
76
alterCollectionPropertyMetadataForSingleItem,
87
PropertyMetadata,
98
} from '../../decorator/metadata/property-metadata.model'
9+
import { curry } from '../../helper/curry.function'
10+
import { isPlainObject } from '../../helper/is-plain-object.function'
1011
import { toDbOne } from '../../mapper/mapper'
1112
import { Attribute, Attributes } from '../../mapper/type/attribute.type'
1213
import { typeOf } from '../../mapper/util'

src/dynamo/expression/param-util.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
* @module expression
33
*/
44
import * as DynamoDB from 'aws-sdk/clients/dynamodb'
5-
import { isEmpty, isString } from 'lodash'
5+
import { isEmpty } from '../../helper/is-empty.function'
6+
import { isString } from '../../helper/is-string.function'
67
import { ConditionalParams } from '../operation-params.type'
78
import { resolveAttributeValueNameConflicts } from './functions/resolve-attribute-value-name-conflicts.function'
89
import { Expression } from './type/expression.type'
910
import { UpdateActionKeyword } from './type/update-action-keyword.type'
11+
1012
/**
1113
* @hidden
1214
*/

src/dynamo/expression/request-expression-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* @module expression
33
*/
4-
import { curry } from 'lodash'
54
import { Metadata } from '../../decorator/metadata/metadata'
5+
import { curry } from '../../helper/curry.function'
66
import { ConditionalParamsHost, UpdateParamsHost } from '../operation-params.type'
77
import { StandardRequest } from '../request/standard.request'
88
import { buildFilterExpression } from './condition-expression-builder'

src/helper/curry.function.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { curry } from './curry.function'
2+
3+
function a(x: number, y: string, z: boolean | null) {
4+
return [x, y, z]
5+
}
6+
7+
describe('curry', () => {
8+
it('should work (w/o arity)', () => {
9+
expect(curry(a)(2)('ok')(true)).toEqual([2, 'ok', true])
10+
expect(curry(a)(4, 'NOK')(false)).toEqual([4, 'NOK', false])
11+
expect(curry(a)(6, 'FOO', null)).toEqual([6, 'FOO', null])
12+
})
13+
14+
it('should work (w/ arity)', () => {
15+
expect(typeof curry(a, 4)(6, 'FOO', null)).toEqual('function')
16+
})
17+
})

src/helper/curry.function.ts

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// copied from just-curry-it
2+
3+
interface CurriedFunction1<T1, R> {
4+
(): CurriedFunction1<T1, R>
5+
6+
(t1: T1): R
7+
}
8+
9+
interface CurriedFunction2<T1, T2, R> {
10+
(): CurriedFunction2<T1, T2, R>
11+
12+
(t1: T1): CurriedFunction1<T2, R>
13+
14+
(t1: T1, t2: T2): R
15+
}
16+
17+
interface CurriedFunction3<T1, T2, T3, R> {
18+
(): CurriedFunction3<T1, T2, T3, R>
19+
20+
(t1: T1): CurriedFunction2<T2, T3, R>
21+
22+
(t1: T1, t2: T2): CurriedFunction1<T3, R>
23+
24+
(t1: T1, t2: T2, t3: T3): R
25+
}
26+
27+
interface CurriedFunction4<T1, T2, T3, T4, R> {
28+
(): CurriedFunction4<T1, T2, T3, T4, R>
29+
30+
(t1: T1): CurriedFunction3<T2, T3, T4, R>
31+
32+
(t1: T1, t2: T2): CurriedFunction2<T3, T4, R>
33+
34+
(t1: T1, t2: T2, t3: T3): CurriedFunction1<T4, R>
35+
36+
(t1: T1, t2: T2, t3: T3, t4: T4): R
37+
}
38+
39+
interface CurriedFunction5<T1, T2, T3, T4, T5, R> {
40+
(): CurriedFunction5<T1, T2, T3, T4, T5, R>
41+
42+
(t1: T1): CurriedFunction4<T2, T3, T4, T5, R>
43+
44+
(t1: T1, t2: T2): CurriedFunction3<T3, T4, T5, R>
45+
46+
(t1: T1, t2: T2, t3: T3): CurriedFunction2<T4, T5, R>
47+
48+
(t1: T1, t2: T2, t3: T3, t4: T4): CurriedFunction1<T5, R>
49+
50+
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): R
51+
}
52+
53+
interface CurriedFunction6<T1, T2, T3, T4, T5, T6, R> {
54+
(): CurriedFunction6<T1, T2, T3, T4, T5, T6, R>
55+
56+
(t1: T1): CurriedFunction5<T2, T3, T4, T5, T6, R>
57+
58+
(t1: T1, t2: T2): CurriedFunction4<T3, T4, T5, T6, R>
59+
60+
(t1: T1, t2: T2, t3: T3): CurriedFunction3<T4, T5, T6, R>
61+
62+
(t1: T1, t2: T2, t3: T3, t4: T4): CurriedFunction2<T5, T6, R>
63+
64+
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): CurriedFunction1<T6, R>
65+
66+
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6): R
67+
}
68+
69+
interface CurriedFunction7<T1, T2, T3, T4, T5, T6, T7, R> {
70+
(): CurriedFunction7<T1, T2, T3, T4, T5, T6, T7, R>
71+
72+
(t1: T1): CurriedFunction6<T2, T3, T4, T5, T6, T7, R>
73+
74+
(t1: T1, t2: T2): CurriedFunction5<T3, T4, T5, T6, T7, R>
75+
76+
(t1: T1, t2: T2, t3: T3): CurriedFunction4<T4, T5, T6, T7, R>
77+
78+
(t1: T1, t2: T2, t3: T3, t4: T4): CurriedFunction3<T5, T6, T7, R>
79+
80+
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): CurriedFunction2<T6, T7, R>
81+
82+
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6): CurriedFunction1<T7, R>
83+
84+
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7): R
85+
}
86+
87+
interface CurriedFunction8<T1, T2, T3, T4, T5, T6, T7, T8, R> {
88+
(): CurriedFunction8<T1, T2, T3, T4, T5, T6, T7, T8, R>
89+
90+
(t1: T1): CurriedFunction7<T2, T3, T4, T5, T6, T7, T8, R>
91+
92+
(t1: T1, t2: T2): CurriedFunction6<T3, T4, T5, T6, T7, T8, R>
93+
94+
(t1: T1, t2: T2, t3: T3): CurriedFunction5<T4, T5, T6, T7, T8, R>
95+
96+
(t1: T1, t2: T2, t3: T3, t4: T4): CurriedFunction4<T5, T6, T7, T8, R>
97+
98+
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): CurriedFunction3<T6, T7, T8, R>
99+
100+
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6): CurriedFunction2<T7, T8, R>
101+
102+
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7): CurriedFunction1<T8, R>
103+
104+
(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8): R
105+
}
106+
107+
/**
108+
* Creates a function that accepts one or more arguments of func that when called either invokes func returning
109+
* its result, if all func arguments have been provided, or returns a function that accepts one or more of the
110+
* remaining func arguments, and so on. The arity of func may be specified if func.length is not sufficient.
111+
* @param func The function to curry.
112+
* @param arity The arity of func.
113+
* @return Returns the new curried function.
114+
*/
115+
export function curry<T1, R>(func: (t1: T1) => R, arity?: number): CurriedFunction1<T1, R>
116+
export function curry<T1, T2, R>(func: (t1: T1, t2: T2) => R, arity?: number): CurriedFunction2<T1, T2, R>
117+
export function curry<T1, T2, T3, R>(
118+
func: (t1: T1, t2: T2, t3: T3) => R,
119+
arity?: number,
120+
): CurriedFunction3<T1, T2, T3, R>
121+
export function curry<T1, T2, T3, T4, R>(
122+
func: (t1: T1, t2: T2, t3: T3, t4: T4) => R,
123+
arity?: number,
124+
): CurriedFunction4<T1, T2, T3, T4, R>
125+
export function curry<T1, T2, T3, T4, T5, R>(
126+
func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R,
127+
arity?: number,
128+
): CurriedFunction5<T1, T2, T3, T4, T5, R>
129+
export function curry<T1, T2, T3, T4, T5, T6, R>(
130+
func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6) => R,
131+
arity?: number,
132+
): CurriedFunction6<T1, T2, T3, T4, T5, T6, R>
133+
export function curry<T1, T2, T3, T4, T5, T6, T7, R>(
134+
func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7) => R,
135+
arity?: number,
136+
): CurriedFunction7<T1, T2, T3, T4, T5, T6, T7, R>
137+
export function curry<T1, T2, T3, T4, T5, T6, T7, T8, R>(
138+
func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8) => R,
139+
arity?: number,
140+
): CurriedFunction8<T1, T2, T3, T4, T5, T6, T7, T8, R>
141+
export function curry(fn: (...args: any[]) => any, arity?: number) {
142+
return function curried() {
143+
if (arity == null) {
144+
arity = fn.length
145+
}
146+
const args = [].slice.call(arguments)
147+
if (args.length >= arity) {
148+
// @ts-ignore
149+
return fn.apply(this, args)
150+
} else {
151+
return function() {
152+
// @ts-ignore
153+
return curried.apply(this, args.concat([].slice.call(arguments)))
154+
}
155+
}
156+
}
157+
}

src/helper/get-tag.function.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Tag } from './tag.enum'
2+
3+
/**
4+
* @return Returns the value (we call it tag) returned by function call `value.toString`,
5+
*/
6+
export function getTag(value: any): Tag | string {
7+
return Object.prototype.toString.call(value)
8+
}

src/helper/is-boolean.function.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { getTag } from './get-tag.function'
2+
import { Tag } from './tag.enum'
3+
4+
/**
5+
* @return Returns true for any value where typeof equals 'string' or an object created with String constructor
6+
*/
7+
export function isBoolean(value: any): boolean {
8+
return typeof value === 'boolean' || getTag(value) === Tag.BOOLEAN
9+
}

0 commit comments

Comments
 (0)