Skip to content

Commit

Permalink
feat: replace lodash by natives js functions (#99)
Browse files Browse the repository at this point in the history
* feat: replace lodash by natives js functions

* feat: try on testing of utils

* cleaning

* fix: rearrange everything

* fix: build

* fix: tests and lint

* fix: tests and lint

* fix: utils test imports

* fix: typescript to dev dependency

* fix: others to dev dependency

* fix: remove babel ?

* fix: misc

* fix: no merge deep in repository decorator

---------

Co-authored-by: Oscar GUERIN <oscar.guerin@gmail.com>
  • Loading branch information
luzogue970 and oscar-guerin authored Nov 6, 2024
1 parent f9a0a16 commit 0512613
Show file tree
Hide file tree
Showing 85 changed files with 15,915 additions and 10,366 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
],
"parserOptions": {
"project": [
"tsconfig.json",
"e2e/tsconfig.json"
"tsconfig.json"
],
"createDefaultProgram": true
},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ngx-repository-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:

coverall:
name: Coverall
needs: [test, lint, build-ngx-repository, build-ngx-http-repository, build-ngx-firestore-repository]
needs: [ test, lint, build-ngx-repository, build-ngx-http-repository, build-ngx-firestore-repository ]
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
strategy:
Expand Down
2 changes: 2 additions & 0 deletions merge-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const inputFiles = [
path.join(__dirname, 'coverage/ngx-repository/lcov.info'),
path.join(__dirname, 'coverage/ngx-http-repository/lcov.info'),
path.join(__dirname, 'coverage/ngx-firestore-repository/lcov.info'),
path.join(__dirname, 'coverage/utils/lcov.info'),

];

// Path to save the merged LCOV file
Expand Down
25,414 changes: 15,235 additions & 10,179 deletions package-lock.json

Large diffs are not rendered by default.

50 changes: 26 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@
"scripts": {
"ng": "ng",
"start": "ng serve --project ngx-repository-app",
"build:all": "ng build --project ngx-repository && ng build --project ngx-http-repository && ng build --project ngx-firestore-repository",
"build:ngx-repository": "ng build --project ngx-repository --configuration production && cp README.md dist/ngx-repository",
"build:all": "tsc -p projects/utils/tsconfig.lib.json && ng build --project ngx-repository && ng build --project ngx-http-repository && ng build --project ngx-firestore-repository",
"build:utils": "tsc -p projects/utils/tsconfig.lib.json",
"build:ngx-repository": "npm run build:utils && ng build --project ngx-repository --configuration production && cp README.md dist/ngx-repository",
"build:ngx-http-repository": "npm run build:ngx-repository && ng build --project ngx-http-repository --configuration production && cp README.md dist/ngx-http-repository",
"build:ngx-firestore-repository": "npm run build:ngx-repository && ng build --project ngx-firestore-repository --configuration production && cp README.md dist/ngx-firestore-repository",
"test:ngx-repository": "ng test --project ngx-repository --code-coverage",
"test:ngx-http-repository": "ng test --project ngx-http-repository --code-coverage",
"test:ngx-firestore-repository": "ng test --project ngx-firestore-repository --code-coverage",
"test:utils": "ng test --karma-config projects/utils/karma.conf.js --code-coverage",
"doc:all": "typedoc ./projects/ngx-repository ./projects/ngx-http-repository projects/ngx-firestore-repository",
"doc:ngx-repository": "typedoc ./projects/ngx-repository",
"doc:ngx-http-repository": "typedoc ./projects/ngx-http-repository",
"doc:ngx-firestore-repository": "typedoc projects/ngx-firestore-repository",
"test:ci:ngx-repository": "npm run test:ngx-repository -- --no-watch --no-progress --browsers=ChromeHeadlessCI",
"test:ci:ngx-http-repository": "npm run test:ngx-http-repository -- --no-watch --no-progress --browsers=ChromeHeadlessCI",
"test:ci:ngx-firestore-repository": "npm run test:ngx-firestore-repository -- --no-watch --no-progress --browsers=ChromeHeadlessCI",
"test:ci": "npm run test:ci:ngx-repository && npm run test:ci:ngx-http-repository && npm run test:ci:ngx-firestore-repository",
"test:ci:utils": "npm run test:utils -- --no-watch --no-progress --browsers=ChromeHeadlessCI",
"test:ci": "npm run test:ci:ngx-repository && npm run test:ci:ngx-http-repository && npm run test:ci:ngx-firestore-repository && npm run test:ci:utils",
"test:e2e": "npm run test:ci:ngx-repository && npm run test:ci:ngx-http-repository && npm run test:ci:ngx-firestore-repository",
"posttest:ci": "node merge-coverage.js",
"lint:all": "npm run lint:ngx-repository && npm run lint:ngx-http-repository && npm run lint:ngx-firestore-repository && npm run lint:ngx-repository-app",
"lint:ngx-repository": "ng lint --project ngx-repository",
"lint:ngx-http-repository": "ng lint --project ngx-http-repository",
"lint:ngx-firestore-repository": "ng lint --project ngx-firestore-repository",
"lint:ngx-repository-app": "ng lint --project ngx-repository-app",
"lint:utils": "npx eslint projects/utils/src/**/*.ts",
"release": "cd projects/ngx-repository && npm version ${npm_config_release} && cd ../ngx-http-repository && npm version ${npm_config_release} && cd ../ngx-firestore-repository && npm version ${npm_config_release} && git commit -a -m \"release: v${npm_config_release}\"",
"lint": "ng lint"
"lint": "ng lint && npm run lint:utils"
},
"private": true,
"dependencies": {
Expand All @@ -46,20 +50,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 All @@ -77,9 +67,11 @@
"@angular/language-service": "^18.0.1",
"@types/jasmine": "~4.3.1",
"@types/jasminewd2": "~2.0.10",
"@types/node": "^12.11.1",
"@types/node": "^18.19.1",
"@types/webpack-env": "^1.18.5",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"cpx": "^1.5.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "latest",
"eslint-plugin-jsdoc": "latest",
Expand All @@ -90,18 +82,28 @@
"jasmine-marbles": "^0.9.2",
"jasmine-spec-reporter": "~7.0.0",
"karma": "^6.4.3",
"karma-browserify": "^8.1.0",
"karma-chrome-launcher": "~3.2.0",
"karma-cli": "^2.0.0",
"karma-coverage": "~2.2.1",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"karma-nodeunit": "^0.2.0",
"karma-spec-reporter": "^0.0.36",
"karma-typescript": "^5.5.4",
"karma-typescript-es6-transform": "^5.5.4",
"karma-typescript-preprocessor": "^0.4.0",
"karma-webpack": "^5.0.1",
"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",
"ts-loader": "^9.5.1",
"ts-node": "~10.9.1",
"typedoc": "^0.25.13",
"typescript": "^5.4.5"
}
"tsify": "^5.0.4",
"typescript": "^5.5.4",
"webpack": "^5.93.0",
"webpack-cli": "^5.1.4"
},
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
}
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 '@paddls/utils';

export interface FirestoreTestContext {
entity: Type<any>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { FirestoreRepositoryParamConfiguration } from './firestore-repository-param.configuration';
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 { get, isString, isUndefined, omit } from '@paddls/utils';
import { FirestoreRepositoryParamConfiguration } from './firestore-repository-param.configuration';

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,5 +1,5 @@
import { FirestoreRepositoryRequest } from '../request/firestore-repository.request';
import omitBy from 'lodash.omitby';
import { omitBy } from 'lodash';

const IGNORED_KEYS: string[] = ['paths', 'readPath', 'createPath', 'updatePath', 'deletePath', 'pathParams', 'replaceParams'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} 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 '@paddls/utils';

/**
* @ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,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 @@ -102,7 +101,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 @@ -171,7 +170,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
3 changes: 3 additions & 0 deletions projects/ngx-firestore-repository/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"paths": {
"@paddls/ngx-repository": [
"projects/ngx-repository/src/public-api.ts"
],
"@paddls/utils": [
"projects/utils/index.ts"
]
}
},
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('HttpMultipartResource', () => {
expectedRequestBody,
mockedResponseBody: {id: 1, name},
expectedResponse: void 0,

verify: async (params: any) => {
const givenRequestBody: string = await params[2].body.get('data').text();
expect(givenRequestBody).toEqual(JSON.stringify({id: 1, name}));
Expand Down Expand Up @@ -212,6 +213,7 @@ describe('HttpMultipartResource', () => {
expectedRequestBody,
mockedResponseBody: {id: 1, name},
expectedResponse: void 0,

verify: async (params: any) => {
const givenRequestBody: string = await params[2].body.get('data').text();
expect(givenRequestBody).toEqual(JSON.stringify({id: 1, name}));
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-http-repository/src/e2e/http-request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
HttpQueryParam
} from '../public-api';
import { buildHttpParams } from './util/build-http.params.spec';
import forOwn from 'lodash.forown';
import { forOwn } from '@paddls/utils';

describe('HttpRequestDecorator', () => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export async function expectHttpRequest(httpTestContext: HttpRequestTestContext)
});

const response: any = await context.request();

expect(response).withContext('response not match').toEqual(context.expectedResponse);
if (context.verify) {
await context.verify(invokedParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { HttpClient, HttpParams } from '@angular/common/http';
import { HttpRepository } from '../../lib/repository/http.repository';
import { NgxHttpRepositoryModuleConfiguration } from '../../public-api';
import { expectHttpRequest, HttpRequestTestContext } from './expect-http-request.spec';
import forOwn from 'lodash.forown';
import { provideNgxHttpRepositoryModule } from '../../lib/ngx-http-repository.module';
import { forOwn } from '@paddls/utils';

export interface HttpTestContext extends HttpRequestTestContext {
entity: Type<any>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import {
ResponseBuilder,
VoidResponseProcessor
} from '@paddls/ngx-repository';
import merge from 'lodash.merge';
import get from 'lodash.get';
import isString from 'lodash.isstring';
import isUndefined from 'lodash.isundefined';
import omit from 'lodash.omit';
import { get, isString, isUndefined, omit } from '@paddls/utils';


export interface HttpRepositoryContextConfiguration extends HttpRepositoryParamContextConfiguration {
read?: HttpRepositoryParamContextConfiguration | string;
Expand Down Expand Up @@ -47,7 +44,7 @@ function buildOperationParams<T>(params: HttpRepositoryContextConfiguration, pat
.filter((value: any) => !isUndefined(value))
].map((value: any) => isString(value) ? {path: value} : value);

return merge({}, ...configurations);
return Object.assign({}, ...configurations);
}

function buildFindAllParams(params: HttpRepositoryContextConfiguration, path: string[]): HttpRepositoryParamConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { HttpRepositoryDriver } from '../driver/http-repository.driver';
import { HttpRequestBuilder } from '../request/http-request.builder';
import { Observable } from 'rxjs';
import { HttpRequestParamsContext } from '../configuration/context/http-request-params-context.configuration';
import isString from 'lodash.isstring';
import flattenDeep from 'lodash.flattendeep';
import { flattenDeep, isString } from '@paddls/utils';

export function HttpRequestDecorator(params: HttpRequestParamsContext): PropertyDecorator {
return (target: any, propertyKey: string) => {
Expand Down
Loading

0 comments on commit 0512613

Please sign in to comment.