Skip to content

Commit 4359ac7

Browse files
committed
feat(json-api-nestjs-shared): Use new structure
set two type package in npm package.json
1 parent 95eac72 commit 4359ac7

File tree

13 files changed

+4582
-7781
lines changed

13 files changed

+4582
-7781
lines changed

.nxignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/*.test-d.ts
2+
**/__test__/**/*

libs/json-api/json-api-nestjs-shared/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
"tslib": "^2.3.0"
66
},
77
"type": "commonjs",
8-
"main": "./src/index.js"
8+
"main": "./cjs/src/index.js",
9+
"types": "./cjs/src/index.d.ts",
10+
"module": "./mjs/src/index.js"
911
}

libs/json-api/json-api-nestjs-shared/project.json

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,71 @@
1313
},
1414
"tags": [],
1515
"targets": {
16-
"build": {
16+
"build-cjs": {
1717
"executor": "@nx/js:tsc",
18-
"outputs": ["{options.outputPath}"],
18+
"outputs": [
19+
"{options.outputPath}"
20+
],
21+
"options": {
22+
"outputPath": "dist/{projectRoot}/cjs",
23+
"tsConfig": "{projectRoot}/tsconfig.lib.json",
24+
"packageJson": "{projectRoot}/package.json",
25+
"main": "{projectRoot}/src/index.ts",
26+
"assets": [
27+
{
28+
"glob": "*.md",
29+
"input": "{projectRoot}",
30+
"output": "../"
31+
}
32+
],
33+
"updateBuildableProjectDepsInPackageJson": true
34+
}
35+
},
36+
"build-mjs": {
37+
"executor": "@nx/js:tsc",
38+
"outputs": [
39+
"{options.outputPath}"
40+
],
41+
"options": {
42+
"outputPath": "dist/{projectRoot}/mjs",
43+
"tsConfig": "{projectRoot}/tsconfig-mjs.lib.json",
44+
"packageJson": "{projectRoot}/package.json",
45+
"main": "{projectRoot}/src/index.ts",
46+
"assets": [
47+
{
48+
"glob": "*.md",
49+
"input": "{projectRoot}",
50+
"output": "../"
51+
}
52+
]
53+
}
54+
},
55+
"build": {
56+
"executor": "nx:run-commands",
57+
"dependsOn": [
58+
"build-cjs",
59+
"build-mjs"
60+
],
1961
"options": {
20-
"outputPath": "dist/libs/json-api/json-api-nestjs-shared",
21-
"tsConfig": "libs/json-api/json-api-nestjs-shared/tsconfig.lib.json",
22-
"packageJson": "libs/json-api/json-api-nestjs-shared/package.json",
23-
"main": "libs/json-api/json-api-nestjs-shared/src/index.ts",
24-
"assets": ["libs/json-api/json-api-nestjs-shared/*.md"]
62+
"commands": [
63+
{
64+
"command": "[ ! -f dist/{projectRoot}/cjs/package.json ] || mv dist/{projectRoot}/cjs/package.json dist/{projectRoot}/package.json",
65+
"forwardAllArgs": false
66+
},
67+
{
68+
"command": "rm -rf dist/{projectRoot}/mjs/package.json",
69+
"forwardAllArgs": false
70+
},
71+
{
72+
"command": "mkdir -p node_modules/@klerick && rm -rf node_modules/@klerick/json-api-nestjs-shared",
73+
"forwardAllArgs": false
74+
},
75+
{
76+
"command": "ln -s $(pwd)/dist/{projectRoot} node_modules/@klerick/json-api-nestjs-shared"
77+
}
78+
],
79+
"cwd": "./",
80+
"parallel": false
2581
}
2682
},
2783
"ts-test": {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './lib/utils';
22
export * from './lib/types';
3+
export * from './lib/constants';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const KEY_MAIN_INPUT_SCHEMA = 'atomic:operations';
2+
export const KEY_MAIN_OUTPUT_SCHEMA = 'atomic:results';

libs/json-api/json-api-nestjs-shared/src/lib/types/entity-type.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Any } from 'ts-toolbelt';
44
import { Users } from '../utils/___test___/test-classes.helper';
55

66
import { RelationKeys, PropertyKeys, IsIterator } from './entity-type';
7-
import { Collection } from '@mikro-orm/core';
7+
import type { Collection } from '@mikro-orm/core';
88

99
type RelationId = 'addresses' | 'manager' | 'roles' | 'comments' | 'userGroup';
1010
type RelationName = 'roles';

libs/json-api/json-api-nestjs-shared/src/lib/types/entity-type.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ export type IsIterator<T> = T extends {
3838
export type TypeOfArray<T> = T extends (infer U)[] ? U : T;
3939

4040
export type ValueOf<T> = T[keyof T];
41+
export type Constructor<T> = new (...args: any[]) => T;
42+
export type AnyEntity<T = object> = T;
43+
export type EntityClass<T extends AnyEntity> = Constructor<T>;

libs/json-api/json-api-nestjs-shared/src/lib/types/query-type.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ export enum FilterOperandOnlySimple {
3434
ne = 'ne',
3535
regexp = 'regexp',
3636
}
37+
38+
export enum Operation {
39+
add = 'add',
40+
update = 'update',
41+
remove = 'remove',
42+
}
Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +0,0 @@
1-
import { Collection } from '@mikro-orm/core';
2-
type IUsers = Users;
3-
export class Users {
4-
public id!: number;
5-
public login!: string;
6-
public firstName!: string;
7-
public testReal: number[] = [];
8-
public testArrayNull!: number[] | null;
9-
public lastName!: string | null;
10-
public isActive!: null;
11-
public testDate!: Date;
12-
public createdAt: Date = new Date();
13-
public updatedAt: Date = new Date();
14-
15-
public addresses!: IAddresses;
16-
public manager!: IUsers;
17-
public roles = new Collection<Roles>(this);
18-
public comments!: Comments[];
19-
public userGroup!: UserGroups | null;
20-
}
21-
type IRoles = Roles;
22-
export class Roles {
23-
public id!: number;
24-
public name!: string;
25-
public key!: string;
26-
public isDefault!: boolean;
27-
createdAt: Date = new Date();
28-
updatedAt: Date = new Date();
29-
}
30-
type IUserGroups = UserGroups;
31-
export class UserGroups {
32-
public id!: number;
33-
public label!: string;
34-
}
35-
type IAddresses = Addresses;
36-
export class Addresses {
37-
public id!: number;
38-
public city!: string;
39-
public state!: string;
40-
public country!: string;
41-
public arrayField!: string[];
42-
createdAt: Date = new Date();
43-
updatedAt: Date = new Date();
44-
}
45-
type IComments = Comments;
46-
export class Comments {
47-
public id!: number;
48-
public kind!: CommentKind;
49-
createdAt: Date = new Date();
50-
updatedAt: Date = new Date();
51-
}
52-
export enum CommentKind {
53-
Comment = 'COMMENT',
54-
Message = 'MESSAGE',
55-
Note = 'NOTE',
56-
}

libs/json-api/json-api-nestjs-shared/src/lib/utils/object-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { kebabCase } from 'change-case-commonjs';
1+
import { pascalCase } from 'change-case-commonjs';
22

33
export const ObjectTyped = {
44
keys: Object.keys as <T extends {}>(yourObject: T) => Array<keyof T>,
@@ -20,7 +20,7 @@ export function isString<T, P extends T>(value: T): value is P {
2020
}
2121

2222
export function createEntityInstance<E>(name: string): E {
23-
const entityName = kebabCase(name);
23+
const entityName = pascalCase(name);
2424
return Function('return new class ' + entityName + '{}')();
2525
}
2626

0 commit comments

Comments
 (0)