Skip to content

Commit

Permalink
chore: cut v0.6.0 release
Browse files Browse the repository at this point in the history
- several dependency updates
- added more strictness to tsconfig + required changes
- fixed some missing/mis-configured packages
  • Loading branch information
tzellman committed Jan 6, 2022
1 parent 322f7d2 commit 865ed9c
Show file tree
Hide file tree
Showing 11 changed files with 1,399 additions and 1,845 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### [0.6.0](https://github.com/tzellman/nest-jsonapi/compare/v0.5.1...v0.6.0) (2022-01-06)

#### Changes

- Updated nest monorepo devDependency to 8.2+
- Updated several dependencies to latest versions
- Fixed package.json dependency issues (missing/mis-configured)
- Set `noImplicitAny` and `strictNullChecks` to true in tsconfig.json + related changes

### [0.5.1](https://github.com/tzellman/nest-jsonapi/compare/v0.5.0...v0.5.1) (2021-11-01)

#### Changes
Expand Down
3,121 changes: 1,326 additions & 1,795 deletions package-lock.json

Large diffs are not rendered by default.

55 changes: 29 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nest-jsonapi",
"version": "0.5.1",
"version": "0.6.0",
"description": "a NestJS module that provides JSONAPI integration",
"keywords": ["nestjs", "nest", "jsonapi", "json-api"],
"license": "MIT",
Expand Down Expand Up @@ -34,55 +34,58 @@
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:watch": "jest --watch --config jest.config.js"
},
"dependencies": {
"dot-object": "2.1.4",
"transformalizer": "1.1.3"
},
"peerDependencies": {
"@nestjs/common": "^8.2.3",
"@nestjs/core": "^8.2.3",
"class-transformer": "^0.5.1",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.4.0"
"rxjs": "^7.4.0",
"transformalizer": "^1.1.3"
},
"devDependencies": {
"@commitlint/cli": "15.0.0",
"@commitlint/config-conventional": "15.0.0",
"@nestjs/common": "8.2.3",
"@nestjs/core": "8.2.3",
"@nestjs/platform-express": "8.2.3",
"@nestjs/testing": "8.2.3",
"@commitlint/cli": "16.0.1",
"@commitlint/config-conventional": "16.0.0",
"@nestjs/common": "8.2.4",
"@nestjs/core": "8.2.4",
"@nestjs/platform-express": "8.2.4",
"@nestjs/testing": "8.2.4",
"@types/dot-object": "2.1.2",
"@types/express": "4.17.13",
"@types/faker": "5.5.9",
"@types/jest": "27.0.3",
"@types/jest": "27.4.0",
"@types/lodash": "4.14.178",
"@types/node": "14.17.34",
"@types/validator": "13.7.0",
"@typescript-eslint/eslint-plugin": "5.4.0",
"@typescript-eslint/eslint-plugin-tslint": "5.4.0",
"@typescript-eslint/parser": "5.4.0",
"@types/validator": "13.7.1",
"@typescript-eslint/eslint-plugin": "5.9.0",
"@typescript-eslint/eslint-plugin-tslint": "5.9.0",
"@typescript-eslint/parser": "5.9.0",
"class-transformer": "0.5.1",
"conventional-changelog-cli": "2.1.1",
"eslint": "7.32.0",
"conventional-changelog-cli": "2.2.2",
"dot-object": "2.1.4",
"eslint": "8.6.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prefer-arrow": "1.2.3",
"eslint-plugin-prettier": "4.0.0",
"faker": "5.5.3",
"husky": "4.3.8",
"jest": "27.3.1",
"jest": "27.4.7",
"jest-junit": "13.0.0",
"lodash": "4.17.21",
"npm-run-all": "4.1.5",
"prettier": "2.5.0",
"pretty-quick": "3.1.2",
"prettier": "2.5.1",
"pretty-quick": "3.1.3",
"reflect-metadata": "0.1.13",
"rimraf": "3.0.2",
"rxjs": "7.4.0",
"ts-jest": "27.0.7",
"rxjs": "7.5.1",
"transformalizer": "1.1.3",
"ts-jest": "27.1.2",
"ts-node": "10.4.0",
"tsc-watch": "4.5.0",
"tsc-watch": "4.6.0",
"tsconfig-paths": "3.12.0",
"tslint": "6.1.3",
"typedoc": "0.22.10",
"typescript": "4.5.2"
"typescript": "4.5.4"
},
"husky": {
"hooks": {
Expand Down
9 changes: 7 additions & 2 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
"enabledManagers": ["npm"],
"packageRules": [
{
"paths": ["+(package.json)"],
"rangeStrategy": "bump"
"matchPaths": ["+(package.json)"],
"rangeStrategy": "bump",
"ignoreDeps": ["faker"]
},
{
"matchPackageNames": ["husky"],
"allowedVersions": "<5"
},
{
"matchPackageNames": ["@types/node"],
"allowedVersions": "<15"
}
],
"masterIssue": false,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export * from './request-holder';
export * from './schema-builder';
export * from './schema-data-builder';
export * from './service';
export * from './utils';
export { buildLinks } from './utils';
10 changes: 5 additions & 5 deletions src/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export class JsonapiInterceptor implements NestInterceptor {
const start = new Date().getTime();
return next.handle().pipe(
map((data) => {
let jsonapiDocument: JSONAPIDocument;
let jsonapiDocument: JSONAPIDocument | undefined;
if (data) {
assertIsDefined(payloadOptions?.resource);
const params = {
const params: Required<TransformParams> = {
resourceName: payloadOptions.resource,
options: { meta: {} }
} as TransformParams;
params.source = data;
options: { meta: {} },
source: data
};
if (Array.isArray(data)) {
params.options.meta = { count: data.length };
}
Expand Down
3 changes: 1 addition & 2 deletions src/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { REQUEST } from '@nestjs/core';
import { Request } from 'express';
import { JSONAPI_MODULE_SERVICE } from './constants';
import { assertIsDefined } from './utils';
import { JsonapiPayloadOptions } from './payload-decorator';

/**
* This {@link PipeTransform} uses a {@link JsonapiService} to untransform the input payload
Expand All @@ -18,7 +17,7 @@ export class JsonapiPipe implements PipeTransform {
) {}

public transform(value: JSONAPIDocument): ParsedJsonAPIResult | unknown {
const jsonapiRequestHolder: JsonapiPayloadOptions = this.request.jsonapiRequestHolder;
const jsonapiRequestHolder = this.request.jsonapiRequestHolder;

const options = {
untransformIncluded: jsonapiRequestHolder?.untransformIncluded,
Expand Down
9 changes: 5 additions & 4 deletions src/schema-data-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { camelCase, isFunction, kebabCase, merge, omit, pick } from 'lodash';
const FIELD_ID = 'id';

export type ResourceLink = string | { href: string; meta?: Dictionary };

export interface ResourceLinks {
[k: string]: ResourceLink;
}
Expand Down Expand Up @@ -155,7 +156,7 @@ export class SchemaDataBuilder<Resource = unknown> {

public attributes(handler?: SerializeHandler<Dictionary> | AllowDeny<Resource>): SchemaDataBuilder<Resource> {
if (isFunction(handler)) {
this.bindings.attributes = handler as SerializeHandler<Dictionary>;
this.bindings.attributes = handler;
} else {
this.bindings.attributes = this._attributes(handler as AllowDeny<Resource>);
}
Expand All @@ -166,7 +167,7 @@ export class SchemaDataBuilder<Resource = unknown> {
handler?: DeserializeHandler<Dictionary> | AllowDeny<Resource>
): SchemaDataBuilder<Resource> {
if (isFunction(handler)) {
this.bindings.untransformAttributes = handler as DeserializeHandler<Dictionary>;
this.bindings.untransformAttributes = handler;
} else {
this.bindings.untransformAttributes = this._untransformAttributes(handler as AllowDeny<Resource>);
}
Expand Down Expand Up @@ -228,15 +229,15 @@ export class SchemaDataBuilder<Resource = unknown> {
return (params): Dictionary => {
const { attributes } = params;
return Object.keys(attributes ?? {})
.map((k) => [camelCase(k), attributes[k]])
.map((k): [string, unknown] => [camelCase(k), attributes[k]])
.filter(([k]) => !options || !options.allow || options.allow.includes(k as keyof Resource))
.filter(([k]) => !options || !options.deny || !options.deny.includes(k as keyof Resource))
.reduce((obj, [key, val]) => {
if (val !== undefined) {
obj[key] = val;
}
return obj;
}, {});
}, {} as Dictionary);
};
}
}
4 changes: 2 additions & 2 deletions tests/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ describe('jsonapi service', () => {
const result = service.transform({ source: photo, resourceName: RESOURCE_PHOTOS });

const data = result.data as Dictionary;
const included = result.included as Dictionary[];
const included = result.included as Array<{ attributes: Dictionary }>;
expectModel(data, photo, RESOURCE_PHOTOS);
expect((data.attributes as Dictionary).url).toEqual(photo.url);
// make sure the relationship linkage was included
Expand All @@ -339,7 +339,7 @@ describe('jsonapi service', () => {
const album = new Album('faves', [photo]);
const result = service.transform({ source: album, resourceName: RESOURCE_ALBUMS });

const { included } = result;
const included = result.included as Dictionary[];
const data = result.data as Dictionary;
expectModel(data, album, RESOURCE_ALBUMS);
expect(included).toBeDefined();
Expand Down
18 changes: 12 additions & 6 deletions tests/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as url from 'url';
import { URL } from 'url';
import { buildLinks } from '../src';
import { assertIsDefined } from '../src/utils';

describe('utils', () => {
describe('buildLinks', () => {
Expand Down Expand Up @@ -31,11 +32,16 @@ describe('utils', () => {
});

const expectLink = (resultLink: string | undefined, expectedLink: string): void => {
expect(resultLink).toBeDefined();
const resultParts = url.parse(resultLink, true);
const expectedParts = url.parse(expectedLink, true);
expect(resultParts.pathname).toEqual(expectedParts.pathname);
expect(resultParts.query).toEqual(expectedParts.query);
assertIsDefined(resultLink);
const resultUrl = new URL(`http://example.com${resultLink}`);
const expectedUrl = new URL(`http://example.com${expectedLink}`);
expect(resultUrl.pathname).toEqual(expectedUrl.pathname);
for (const [key, value] of resultUrl.searchParams.entries()) {
expect(value).toEqual(expectedUrl.searchParams.get(key));
}
for (const [key, value] of expectedUrl.searchParams.entries()) {
expect(resultUrl.searchParams.get(key)).toEqual(value);
}
};

it('can handle first page', () => {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"incremental": true,
"lib": ["es6", "esnext.asynciterable", "es2019"],
"module": "commonjs",
"noImplicitAny": false,
"noImplicitAny": true,
"noImplicitThis": true,
"noLib": false,
"noUnusedLocals": false,
Expand All @@ -22,7 +22,7 @@
"sourceMap": true,
"strict": true,
"strictFunctionTypes": false,
"strictNullChecks": false,
"strictNullChecks": true,
"target": "es2017",
"tsBuildInfoFile": "./lib/tsconfig.tsbuildinfo",
"typeRoots": ["./node_modules/@types", "./types"]
Expand Down

0 comments on commit 865ed9c

Please sign in to comment.