Skip to content

Commit

Permalink
query models
Browse files Browse the repository at this point in the history
  • Loading branch information
rbrightline committed Nov 22, 2024
1 parent 17ce6e2 commit 6dc9be3
Show file tree
Hide file tree
Showing 32 changed files with 373 additions and 44 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# RbrightlineGithubIo

## Material

<a href="https://ng.ant.design/docs/introduce/en"> Material </a>
29 changes: 29 additions & 0 deletions libs/core/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"jsc": {
"target": "es2017",
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true
},
"keepClassNames": true,
"externalHelpers": true,
"loose": true
},
"module": {
"type": "commonjs"
},
"sourceMaps": true,
"exclude": [
"jest.config.ts",
".*\\.spec.tsx?$",
".*\\.test.tsx?$",
"./src/jest-setup.ts$",
"./**/jest-setup.ts$",
".*.js$"
]
}
11 changes: 11 additions & 0 deletions libs/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# core

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build core` to build the library.

## Running unit tests

Run `nx test core` to execute the unit tests via [Vitest](https://vitest.dev/).
22 changes: 22 additions & 0 deletions libs/core/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const baseConfig = require('../../eslint.config.js');

module.exports = [
...baseConfig,
{
files: ['**/*.json'],
rules: {
'@nx/dependency-checks': [
'error',
{
ignoredFiles: [
'{projectRoot}/eslint.config.{js,cjs,mjs}',
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
],
},
],
},
languageOptions: {
parser: require('jsonc-eslint-parser'),
},
},
];
10 changes: 10 additions & 0 deletions libs/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@rline/core",
"version": "0.0.1",
"dependencies": {
"@swc/helpers": "~0.5.11"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts"
}
39 changes: 39 additions & 0 deletions libs/core/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "core",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/core/src",
"projectType": "library",
"release": {
"version": {
"generatorOptions": {
"packageRoot": "dist/{projectRoot}",
"currentVersionResolver": "git-tag"
}
}
},
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:swc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/core",
"main": "libs/core/src/index.ts",
"tsConfig": "libs/core/tsconfig.lib.json",
"assets": ["libs/core/*.md"]
}
},
"nx-release-publish": {
"options": {
"packageRoot": "dist/{projectRoot}"
}
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["{options.reportsDirectory}"],
"options": {
"reportsDirectory": "../../coverage/libs/core"
}
}
}
}
6 changes: 6 additions & 0 deletions libs/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @index(['./**/*.ts','!./**/*.{test,spec}.ts'], f => `export * from '${f.path}'`)
export * from './lib/base/base.entity';
export * from './lib/query/query';
export * from './lib/transformers/query-operator';
export * from './lib/transformers/query';
export * from './lib/transformers/to-find-operator';
23 changes: 23 additions & 0 deletions libs/core/src/lib/base/base.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
Column,
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn,
DeleteDateColumn,
} from 'typeorm';

export class BaseEntity {
@PrimaryGeneratedColumn()
id: number;
}

export class BaseEntityWithTimestamp extends BaseEntity {
@CreateDateColumn() createdAt: Date;
@UpdateDateColumn() updatedAt: Date;
@DeleteDateColumn() deletedAt: Date;
}

export class BaseEntityWithActive extends BaseEntityWithTimestamp {
@Column({ type: 'boolean', default: false })
active: boolean;
}
22 changes: 22 additions & 0 deletions libs/core/src/lib/query/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ApiProperty } from '@nestjs/swagger';

export class QueryModel {
@ApiProperty({ type: 'integer' })
id: number;
}

export class QueryModelWithTimestamp {
@ApiProperty({ type: 'number' })
createdAt: Date;

@ApiProperty({ type: 'number' })
updatedAt: Date;

@ApiProperty({ type: 'number' })
deletedAt: Date;
}

export class QueryModelWithActive {
@ApiProperty({ type: 'boolean' })
active: boolean;
}
11 changes: 11 additions & 0 deletions libs/core/src/lib/transformers/query-operator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum QueryOperator {
EQUAL = 'eq',
CONTAINS = 'cn',
MORE_THAN = 'mt',
LESS_THAN = 'lt',

NOT_EQUAL = 'neq',
NOT_CONTAINS = 'ncn',
NOT_MORE_THAN = 'nmt',
NOT_LESS_THAN = 'nlt',
}
6 changes: 6 additions & 0 deletions libs/core/src/lib/transformers/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Transform } from 'class-transformer';

export type QueryPropertyOptions = {
type: PropertyType;
};
export function QueryProperty(options: QueryPropertyOptions) {}
32 changes: 32 additions & 0 deletions libs/core/src/lib/transformers/to-find-operator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Equal, FindOperator, ILike, LessThan, MoreThan, Not } from 'typeorm';
import { QueryOperator } from './query-operator';

/**
*
* @param value query string delimeted by ":"
*/
export function toFindOperator<T>(
operator: QueryOperator,
value: T
): FindOperator<any> | undefined {
switch (operator as QueryOperator) {
case QueryOperator.CONTAINS:
return ILike(`%${value}%`);
case QueryOperator.EQUAL:
return Equal(value);
case QueryOperator.LESS_THAN:
return LessThan(value);
case QueryOperator.MORE_THAN:
return MoreThan(value);
case QueryOperator.NOT_CONTAINS:
return Not(ILike(`%${value}%`));
case QueryOperator.NOT_EQUAL:
return Not(ILike(`${value}`));
case QueryOperator.NOT_LESS_THAN:
return Not(LessThan(value));
case QueryOperator.NOT_MORE_THAN:
return Not(MoreThan(value));
default:
return undefined;
}
}
22 changes: 22 additions & 0 deletions libs/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
23 changes: 23 additions & 0 deletions libs/core/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": [
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx"
]
}
28 changes: 28 additions & 0 deletions libs/core/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
]
},
"include": [
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
21 changes: 21 additions & 0 deletions libs/core/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig } from 'vite';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';

export default defineConfig({
root: __dirname,
cacheDir: '../../node_modules/.vite/libs/core',
plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },
test: {
watch: false,
globals: true,
environment: 'node',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
coverage: { reportsDirectory: '../../coverage/libs/core', provider: 'v8' },
},
});
2 changes: 1 addition & 1 deletion libs/entity/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/entity';
// @index(['./**/*.ts', '!./**/*.{spec,test,story,stories}.ts'], f => `export * from '${f.path}'`)
12 changes: 12 additions & 0 deletions libs/entity/src/lib/category/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CategoryModel } from '@rline/model';
import { Exclude } from 'class-transformer';
import { MaxLength, MinLength } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

@Exclude()
export class CreateCategoryDto implements CategoryModel {
@ApiProperty({ type: 'string', minLength: 3, maxLength: 50, required: true })
@MinLength(3)
@MaxLength(50)
name: string;
}
9 changes: 9 additions & 0 deletions libs/entity/src/lib/category/entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BaseEntity } from '@rline/core';
import { CategoryEntity } from '@rline/model';
import { Column, Entity } from 'typeorm';

@Entity()
export class Category extends BaseEntity implements CategoryEntity {
@Column({ type: 'varchar', unique: true })
name: string;
}
7 changes: 0 additions & 7 deletions libs/entity/src/lib/entity.spec.ts

This file was deleted.

3 changes: 0 additions & 3 deletions libs/entity/src/lib/entity.ts

This file was deleted.

3 changes: 2 additions & 1 deletion libs/model/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './lib/model';
// @index(['./**/*.ts', '!./**/*.{test,spec}.ts'], f => `export * from '${f.path}'`)
export * from './lib/category/category';
7 changes: 7 additions & 0 deletions libs/model/src/lib/category/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Model } from '@rline/type';

export type CategoryModel = {
name: string;
};

export type CategoryEntity = Model<CategoryModel>;
7 changes: 0 additions & 7 deletions libs/model/src/lib/model.spec.ts

This file was deleted.

3 changes: 0 additions & 3 deletions libs/model/src/lib/model.ts

This file was deleted.

10 changes: 0 additions & 10 deletions libs/type/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
# type

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build type` to build the library.

## Running unit tests

Run `nx test type` to execute the unit tests via [Vitest](https://vitest.dev/).
Loading

0 comments on commit 6dc9be3

Please sign in to comment.