Skip to content

Commit

Permalink
feat: replace lodash by natives js functions
Browse files Browse the repository at this point in the history
  • Loading branch information
luzogue970 committed Jul 16, 2024
1 parent fb76085 commit 2368996
Show file tree
Hide file tree
Showing 43 changed files with 487 additions and 521 deletions.
78 changes: 3 additions & 75 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,6 @@
"angular-in-memory-web-api": "^0.18.0",
"chance": "^1.1.4",
"firebase": "^9.9.2",
"lodash.first": "^3.0.0",
"lodash.flatten": "^4.4.0",
"lodash.flattendeep": "^4.4.0",
"lodash.get": "^4.4.2",
"lodash.isfunction": "^3.0.9",
"lodash.isobject": "^3.0.2",
"lodash.isstring": "^4.0.1",
"lodash.isundefined": "^3.0.1",
"lodash.merge": "^4.6.2",
"lodash.omit": "^4.5.0",
"lodash.omitby": "^4.6.0",
"lodash.pick": "^4.4.0",
"lodash.set": "^4.3.2",
"lodash.valuesin": "^4.3.0",
"object-hash": "^2.0.3",
"rxjs": "7.5.3",
"tslib": "^2.6.3",
Expand Down Expand Up @@ -95,8 +81,6 @@
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"lcov-result-merger": "^5.0.1",
"lodash.clone": "^4.5.0",
"lodash.forown": "^4.4.0",
"ng-packagr": "^18.0.0",
"protractor": "~7.0.0",
"reflect-metadata": "^0.2.2",
Expand Down
18 changes: 1 addition & 17 deletions projects/ngx-firestore-repository/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,5 @@
"dest": "../../dist/ngx-firestore-repository",
"lib": {
"entryFile": "src/public-api.ts"
},
"allowedNonPeerDependencies": [
"lodash.first",
"lodash.flatten",
"lodash.flattendeep",
"lodash.get",
"lodash.isfunction",
"lodash.isobject",
"lodash.isstring",
"lodash.isundefined",
"lodash.merge",
"lodash.omit",
"lodash.omitby",
"lodash.pick",
"lodash.set",
"lodash.valuesin"
]
}
}
14 changes: 0 additions & 14 deletions projects/ngx-firestore-repository/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@
"firebase": ">= 9.9.2"
},
"dependencies": {
"lodash.first": "^3.0.0",
"lodash.flatten": "^4.4.0",
"lodash.flattendeep": "^4.4.0",
"lodash.get": "^4.4.2",
"lodash.isfunction": "^3.0.9",
"lodash.isobject": "^3.0.2",
"lodash.isstring": "^4.0.1",
"lodash.isundefined": "^3.0.1",
"lodash.merge": "^4.6.2",
"lodash.omit": "^4.5.0",
"lodash.omitby": "^4.6.0",
"lodash.pick": "^4.4.0",
"lodash.set": "^4.3.2",
"lodash.valuesin": "^4.3.0",
"tslib": "^2.0.0"
},
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { initializeRepository, RepositoryContext } from './repository-intializer
import { addDoc, deleteDoc, query, updateDoc } from '../../lib/firestore-functions';
import { CollectionReference, DocumentReference } from 'firebase/firestore';
import { FirestoreMock } from './firestore-mock.spec';
import forOwn from 'lodash.forown';
import { forOwn } from '../../lib/functions';

export interface FirestoreTestContext {
entity: Type<any>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { FirestoreRepositoryParamConfiguration } from './firestore-repository-pa
import { ResourceConfiguration, ResourceParamConfiguration } from '@paddls/ngx-repository';
import { InjectionToken } from '@angular/core';
import { FIRESTORE_OPERATIONS } from '../request/firestore.operation';
import merge from 'lodash.merge';
import omit from 'lodash.omit';
import get from 'lodash.get';
import isUndefined from 'lodash.isundefined';
import isString from 'lodash.isstring';
import { isString, isUndefined, get, omit } from '../functions';

export const FIRESTORE_REPOSITORY_CONFIGURATION: InjectionToken<FirestoreResourceConfiguration> = new InjectionToken<FirestoreResourceConfiguration>('FIRESTORE_REPOSITORY_CONFIGURATION');

Expand Down Expand Up @@ -46,13 +42,13 @@ export function createFirestoreRepositoryConfiguration(params: ResourceConfigura
};
}

function buildOperationParams<T>(params: ResourceConfiguration, path: string[]): T {
function buildOperationParams<T>(params: ResourceConfiguration, path: string[]) {
const rootConfiguration: any = omit(params, FIRESTORE_OPERATIONS);
const configurations: any[] = [
rootConfiguration,
...path.map((key: string) => get(params, key))
.filter((value: any) => !isUndefined(value))
].map((value: any) => isString(value) ? {path: value} : value);

return merge({}, ...configurations);
return Object.assign({}, ...configurations);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FirestoreRepositoryRequest } from '../request/firestore-repository.request';
import omitBy from 'lodash.omitby';

import { omitBy } from '../functions';
const IGNORED_KEYS: string[] = ['paths', 'readPath', 'createPath', 'updatePath', 'deletePath', 'pathParams', 'replaceParams'];

export class NgxFirestoreRepositoryError extends Error {
Expand Down
52 changes: 52 additions & 0 deletions projects/ngx-firestore-repository/src/lib/functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { FirestoreRepositoryRequest } from '../public-api';

export const get = (obj: unknown, path: string, defValue?: undefined) => {
if (!path) return undefined;
const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g);
const result = pathArray.reduce(
(prevObj, key) => prevObj && prevObj[key],
obj as any
);

return result === undefined ? defValue : result;
};


export const omit = (obj: { [x: string]: any; }, props: (string | number)[]) => {
obj = {...obj};
props.forEach((prop: string | number) => delete obj[prop]);

return obj;
};

export const omitBy = (obj: { [s: string]: unknown; } | ArrayLike<unknown> | FirestoreRepositoryRequest, check: Function) => {
obj = { ...obj };
Object.entries(obj).forEach(([key, value]) => check(value) && delete obj[key]);

return obj;
};

export const set = (obj: unknown, path: string | string[], value: any) => {
const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g);

pathArray.reduce((acc, key, i) => {
if (acc[key] === undefined) acc[key] = {};
if (i === pathArray.length - 1) acc[key] = value;

return acc[key];
}, obj as any);
};

export const isString = (a: any): a is string => typeof a === 'string';

export const isUndefined = (val: any): val is undefined => val === undefined;

export const forOwn = <T extends object>(object: T, iteratee: (value: T[keyof T], key: keyof T, object: T) => void): void => {
if (object && typeof object === 'object') {
for (const key in object) {
if (Object.prototype.hasOwnProperty.call(object, key)) {
iteratee(object[key], key, object);
}
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import {Inject, Injectable} from '@angular/core';
import {FIRESTORE_CREATED_AT_METADATA_KEY} from '../decorator/firestore-created-at.decorator';
import {FIRESTORE_UPDATED_AT_METADATA_KEY} from '../decorator/firestore-updated-at.decorator';
import {NormalizerConfiguration, RepositoryNormalizer} from '@paddls/ngx-repository';
import {FirestoreCreatedAtContextConfiguration} from '../configuration/context/firestore-created-at-context.configuration';
import {FirestoreUpdatedAtContextConfiguration} from '../configuration/context/firestore-updated-at-context.configuration';
import {
FirestoreCreatedAtContextConfiguration
} from '../configuration/context/firestore-created-at-context.configuration';
import {
FirestoreUpdatedAtContextConfiguration
} from '../configuration/context/firestore-updated-at-context.configuration';
import {NORMALIZER_CONFIGURATION_TOKEN} from '@paddls/ngx-serializer';
import {serverTimestamp} from 'firebase/firestore';
import set from 'lodash.set';
import { set } from '../functions';


/**
* @ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ import { BeforeFirestorePatchEvent } from './event/before-firestore-patch.event'
import { AfterFirestorePatchEvent } from './event/after-firestore-patch.event';
import { Inject, Type } from '@angular/core';
import { FIRESTORE_RESOURCE_METADATA_KEY } from '../decorator/firestore-resource.decorator';
import merge from 'lodash.merge';
import first from 'lodash.first';


/**
* @ignore
Expand Down Expand Up @@ -98,7 +97,7 @@ export class FirestoreRepository<T, K = string> extends AbstractRepository<T> im
PublisherService.getInstance().publish(new BeforeFirestoreFindOneEvent({query}));

return this.execute(null, query, ['findOne', 'read']).pipe(
map((result: any) => first(result) || null),
map((result: any) => result[0] || null),
tap((data: R) => PublisherService.getInstance().publish(new AfterFirestoreFindOneEvent({
query,
data
Expand Down Expand Up @@ -167,7 +166,7 @@ export class FirestoreRepository<T, K = string> extends AbstractRepository<T> im
}

protected getResourceConfiguration(resourceType: Type<any>, configuration: ResourceConfiguration): ResourceConfiguration {
const config: ResourceConfiguration = merge({}, configuration, Reflect.getMetadata(FIRESTORE_RESOURCE_METADATA_KEY, resourceType));
const config: ResourceConfiguration = Object.assign({}, configuration, Reflect.getMetadata(FIRESTORE_RESOURCE_METADATA_KEY, resourceType));

return createFirestoreRepositoryConfiguration(config);
}
Expand Down
14 changes: 0 additions & 14 deletions projects/ngx-http-repository/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,5 @@
"entryFile": "src/public-api.ts"
},
"allowedNonPeerDependencies": [
"lodash.first",
"lodash.flatten",
"lodash.flattendeep",
"lodash.get",
"lodash.isfunction",
"lodash.isobject",
"lodash.isstring",
"lodash.isundefined",
"lodash.merge",
"lodash.omit",
"lodash.omitby",
"lodash.pick",
"lodash.set",
"lodash.valuesin"
]
}
14 changes: 0 additions & 14 deletions projects/ngx-http-repository/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@
"@paddls/ngx-repository": "^8.0.0"
},
"dependencies": {
"lodash.first": "^3.0.0",
"lodash.flatten": "^4.4.0",
"lodash.flattendeep": "^4.4.0",
"lodash.get": "^4.4.2",
"lodash.isfunction": "^3.0.9",
"lodash.isobject": "^3.0.2",
"lodash.isstring": "^4.0.1",
"lodash.isundefined": "^3.0.1",
"lodash.merge": "^4.6.2",
"lodash.omit": "^4.5.0",
"lodash.omitby": "^4.6.0",
"lodash.pick": "^4.4.0",
"lodash.set": "^4.3.2",
"lodash.valuesin": "^4.3.0",
"tslib": "^2.0.0"
},
"repository": {
Expand Down
Loading

0 comments on commit 2368996

Please sign in to comment.