@anthonylzq/simba.js 8.0.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,13 +50,11 @@ datasource db {
50
50
  model User {
51
51
  ${
52
52
  isMongo
53
- ? `id String @id @default(auto()) @map("_id") @db.ObjectId
54
- lastName String
55
- name String`
56
- : `id Int @id @default(autoincrement())
57
- lastName String
58
- name String`
53
+ ? 'id String @id @default(auto()) @map("_id") @db.ObjectId'
54
+ : 'id Int @id @default(autoincrement())'
59
55
  }
56
+ lastName String
57
+ name String
60
58
 
61
59
  createdAt DateTime @default(now())
62
60
  updatedAt DateTime @updatedAt
@@ -132,14 +130,14 @@ import { dbConnection } from '../connection'
132
130
  import { Id, User as UserSchema, UserDTO } from 'schemas'
133
131
  import { Logger } from 'utils'
134
132
 
135
- const LOGGER = new Logger(debug('App:Database:Queries:User'))
133
+ const logger = new Logger(debug('App:Database:Queries:User'))
136
134
 
137
- const userDBOtoDTO = (userDBO: User): UserDTO =>
135
+ const userDBOtoDTO = (userDBO: User) =>
138
136
  ({
139
137
  ...userDBO,
140
138
  createdAt: userDBO.createdAt.toISOString(),
141
139
  updatedAt: userDBO.updatedAt.toISOString()
142
- }) as UserDTO
140
+ }) satisfies UserDTO
143
141
 
144
142
  const store = async (userData: UserSchema) => {
145
143
  try {
@@ -150,7 +148,7 @@ const store = async (userData: UserSchema) => {
150
148
 
151
149
  return userDBOtoDTO(user)
152
150
  } catch (error) {
153
- LOGGER.log({
151
+ logger.log({
154
152
  origin: 'queries/user.ts',
155
153
  method: store.name,
156
154
  value: 'error',
@@ -170,7 +168,7 @@ const removeById = async (id: Id) => {
170
168
 
171
169
  return true
172
170
  } catch (error) {
173
- LOGGER.log({
171
+ logger.log({
174
172
  origin: 'queries/user.ts',
175
173
  method: removeById.name,
176
174
  value: 'error',
@@ -192,7 +190,7 @@ const getById = async (id: Id) => {
192
190
 
193
191
  return userDBOtoDTO(user)
194
192
  } catch (error) {
195
- LOGGER.log({
193
+ logger.log({
196
194
  origin: 'queries/user.ts',
197
195
  method: getById.name,
198
196
  value: 'error',
@@ -215,7 +213,7 @@ const update = async (id: Id, user: UserSchema) => {
215
213
 
216
214
  return userDBOtoDTO(userUpdated)
217
215
  } catch (error) {
218
- LOGGER.log({
216
+ logger.log({
219
217
  origin: 'queries/user.ts',
220
218
  method: update.name,
221
219
  value: 'error',
@@ -15,10 +15,8 @@ const utils = require('./utils')
15
15
  * @param {Boolean} args.dbIsSQL
16
16
  */
17
17
  const types = async ({ projectName, graphQL, dbIsSQL }) => {
18
- const createFoldersCommand = `mkdir ${projectName}/src/@types ${projectName}/src/@types/custom \
19
- ${!dbIsSQL ? ` ${projectName}/src/@types/models` : ''} ${
20
- graphQL ? ` ${projectName}/src/@types/graphQL` : ''
21
- }`
18
+ const createFoldersCommand = `mkdir ${projectName}/src/@types \
19
+ ${!dbIsSQL ? ` ${projectName}/src/@types/models` : ''}`
22
20
 
23
21
  if (platform() === 'win32')
24
22
  await exec(createFoldersCommand.replaceAll('/', '\\'))
@@ -32,36 +30,9 @@ declare global {}
32
30
  export {}
33
31
  `,
34
32
  file: `${projectName}/src/@types/index.d.ts`
35
- },
36
- custom: {
37
- params: {
38
- content: `type Params = {
39
- [key: string]: string
40
- }\n`,
41
- file: `${projectName}/src/@types/custom/params.d.ts`
42
- }
43
- },
44
- ...(graphQL && {
45
- graphQL: {
46
- context: {
47
- content: `type Context = {
48
- log: import('express-pino-logger').HttpLogger['logger']
49
- }
50
- `,
51
- file: `${projectName}/src/@types/graphQL/context.d.ts`
52
- }
53
- }
54
- })
33
+ }
55
34
  }
56
- const processes = [
57
- writeFile(types.index.file, types.index.content),
58
- writeFile(types.custom.params.file, types.custom.params.content)
59
- ]
60
-
61
- if (graphQL)
62
- processes.push(
63
- writeFile(types.graphQL.context.file, types.graphQL.context.content)
64
- )
35
+ const processes = [writeFile(types.index.file, types.index.content)]
65
36
 
66
37
  await Promise.all(processes)
67
38
  }
@@ -406,7 +377,13 @@ const User = Router()
406
377
  User.route('/users').post(
407
378
  validatorCompiler(storeUserDto, 'body'),
408
379
  async (
409
- req: Request<Params, Record<string, unknown>, { args: UserDTO }>,
380
+ req: Request<
381
+ {
382
+ [key: string]: string
383
+ },
384
+ Record<string, unknown>,
385
+ { args: UserDTO }
386
+ >,
410
387
  res: Response,
411
388
  next: NextFunction
412
389
  ): Promise<void> => {
@@ -76,12 +76,12 @@ DELETE http://localhost:1996/api/user/60e7e3b93b01c1a7aa74cd6b
76
76
  : `${database}://${database}:${database}@${database}:${dbDefaultPorts[database]}/${projectName}`
77
77
  }`
78
78
  : database === 'sqlite'
79
- ? ''
80
- : `DATABASE_URL = ${
81
- ENVIRONMENTS_WITH_DB_URI.includes(process.env.NODE_ENV)
82
- ? process.env.MONGO_URI
83
- : `mongodb://mongo:mongo@mongo:27017/${projectName}`
84
- }`,
79
+ ? ''
80
+ : `DATABASE_URL = ${
81
+ ENVIRONMENTS_WITH_DB_URI.includes(process.env.NODE_ENV)
82
+ ? process.env.MONGO_URI
83
+ : `mongodb://mongo:mongo@mongo:27017/${projectName}`
84
+ }`,
85
85
  file: `${projectName}/.env`
86
86
  },
87
87
  index: {
@@ -87,15 +87,11 @@ class BaseHttpService implements Log {
87
87
  value: 'error',
88
88
  content: error
89
89
  })
90
+ const errorMessage = message ?? (error as { message: string }).message
90
91
 
91
- if (code)
92
- throw new httpErrors[code](
93
- message ?? (error as { message: string }).message
94
- )
92
+ if (code) throw new httpErrors[code](errorMessage)
95
93
 
96
- throw new httpErrors.InternalServerError(
97
- message ?? (error as { message: string }).message
98
- )
94
+ throw new httpErrors.InternalServerError(errorMessage)
99
95
  }
100
96
  }
101
97
 
@@ -104,8 +104,7 @@ export { Logger }\n`,
104
104
  "name": "user",
105
105
  "description": "Operations related to the user"
106
106
  }
107
- ]
108
- ${
107
+ ]${
109
108
  !graphQL
110
109
  ? `,
111
110
  "paths": {
@@ -424,7 +423,7 @@ export { Logger }\n`,
424
423
  }
425
424
  }
426
425
  }`
427
- : '}'
426
+ : '\n}'
428
427
  }`,
429
428
  file: `${projectName}/src/utils/docs.json`
430
429
  }
@@ -52,8 +52,8 @@ ${
52
52
  managerName === 'yarn'
53
53
  ? 'yarn install --frozen-lockfile'
54
54
  : managerName
55
- ? 'pnpm i --frozen-lockfile'
56
- : 'npm ci'
55
+ ? 'pnpm i --frozen-lockfile'
56
+ : 'npm ci'
57
57
  }
58
58
 
59
59
  - name: Run linters
@@ -99,8 +99,8 @@ ${
99
99
  managerName === 'yarn'
100
100
  ? 'yarn install --frozen-lockfile'
101
101
  : managerName
102
- ? 'pnpm i --frozen-lockfile'
103
- : 'npm ci'
102
+ ? 'pnpm i --frozen-lockfile'
103
+ : 'npm ci'
104
104
  }
105
105
 
106
106
  - name: Run test
package/lib/src/index.js CHANGED
@@ -97,8 +97,8 @@ module.exports = async ({
97
97
  @typescript-eslint/parser \
98
98
  axios \
99
99
  dotenv \
100
- eslint \
101
- eslint-config-prettier \
100
+ eslint@^8 \
101
+ eslint-config-prettier@^8 \
102
102
  eslint-config-standard \
103
103
  eslint-plugin-import \
104
104
  eslint-plugin-node \
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthonylzq/simba.js",
3
- "version": "8.0.0",
3
+ "version": "8.1.0",
4
4
  "description": "set up a modern backend app by running one command",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -8,25 +8,31 @@
8
8
  "service:q": "node ./bin -q",
9
9
  "help": "node ./bin -h",
10
10
  "lint": "eslint --ext js lib/ --fix",
11
+ "db:create": "node ./scripts/db/sql/create.mjs && node ./scripts/db/mongo/create.mjs",
12
+ "db:create:mongo": "node ./scripts/db/mongo/create.mjs",
13
+ "db:create:sql": "node ./scripts/db/sql/create.mjs",
14
+ "db:restore": "node ./scripts/db/sql/restore.mjs && node ./scripts/db/mongo/restore.mjs",
15
+ "db:restore:mongo": "node ./scripts/db/mongo/restore.mjs",
16
+ "db:restore:sql": "node ./scripts/db/sql/restore.mjs",
11
17
  "example": "node -r dotenv/config ./bin -N local-example -D 'This is a test using fastify' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H --tests --ghat -F",
12
18
  "build": "npm run build:express:all && npm run build:fastify:all",
13
- "build:mongo": "npm run rm:mongo && npm run build:express && npm run build:fastify && npm run build:express:graphql && npm run build:fastify:graphql",
14
- "build:sql": "npm run rm:sql && npm run build:express && npm run build:fastify && npm run build:express:graphql && npm run build:fastify:graphql",
15
- "build:express:all": "npm run build:express && npm run build:express:mongo && npm run build:express:graphql && npm run build:express:mongo:graphql",
16
- "build:fastify:all": "npm run build:fastify && npm run build:fastify:mongo && npm run build:fastify:graphql && npm run build:fastify:mongo:graphql",
17
- "build:express": "npm run rm:express && npm run cd:mv:example && node -r dotenv/config ./bin -N example/express -D 'This is a test using Express with Prisma and PostgreSQL' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H --tests --ghat -d postgres && npm run rm:git:express:mongo",
18
- "build:express:mongo": "npm run rm:express:mongo && npm run cd:mv:example && node -r dotenv/config ./bin -N example/express-mongo -D 'This is a test using Express with Prisma and MongoDB' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H --tests --ghat && npm run rm:git:express",
19
- "build:fastify": "npm run rm:fastify && npm run cd:mv:example && node -r dotenv/config ./bin -N example/fastify -D 'This is a test using Fastify with Prisma and PostgreSQL' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H--tests --ghat -d postgres -F && npm run rm:git:fastify",
20
- "build:fastify:mongo": "npm run rm:fastify:mongo && npm run cd:mv:example && node -r dotenv/config ./bin -N example/fastify-mongo -D 'This is a test using Fastify with Prisma and MongoDB' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H --tests --ghat -F && npm run rm:git:fastify:mongo",
21
- "build:express:graphql": "npm run rm:express:graphql && npm run cd:mv:example && node -r dotenv/config ./bin -N example/express-graphql -D 'This is a test using Express with GraphQL with Prisma and PostgreSQL' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H -g --tests --ghat -d postgres && npm run rm:git:express:graphql",
22
- "build:express:mongo:graphql": "npm run rm:express:mongo:graphql && npm run cd:mv:example && node -r dotenv/config ./bin -N example/express-mongo-graphql -D 'This is a test using Express with GraphQL with Prisma and MongoDB' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H -g --tests --ghat && npm run rm:git:express:mongo:graphql",
23
- "build:fastify:graphql": "npm run rm:fastify:graphql && npm run cd:mv:example && node -r dotenv/config ./bin -N example/fastify-graphql -D 'This is a test using Fastify with GraphQL with Prisma and PostgreSQL' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H -g --tests --ghat -d postgres -F && npm run rm:git:fastify:graphql",
24
- "build:fastify:mongo:graphql": "npm run rm:fastify:mongo:graphql && npm run cd:mv:example && node -r dotenv/config ./bin -N example/fastify-mongo-graphql -D 'This is a test using Fastify with GraphQL with Prisma and MongoDB' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H -g --tests --ghat -F && npm run rm:git:fastify:mongo:graphql",
19
+ "build:mongo": "npm run rm:mongo && npm run db:create:mongo && npm run build:express:mongo && npm run build:fastify:mongo && npm run build:express:mongo:graphql && npm run build:fastify:mongo:graphql",
20
+ "build:sql": "npm run rm:sql && npm run db:create:sql && npm run build:express && npm run build:fastify && npm run build:express:graphql && npm run build:fastify:graphql",
21
+ "build:express:all": "npm run db:create && npm run build:express && npm run build:express:mongo && npm run build:express:graphql && npm run build:express:mongo:graphql",
22
+ "build:fastify:all": "npm run db:create && npm run build:fastify && npm run build:fastify:mongo && npm run build:fastify:graphql && npm run build:fastify:mongo:graphql",
23
+ "build:express": "npm run db:create:sql && npm run rm:express && npm run cd:mv:example && node -r dotenv/config ./bin -N example/express -D 'This is a test using Express with Prisma and PostgreSQL' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H --tests --ghat -d postgres && npm run rm:git:express:mongo",
24
+ "build:express:mongo": "npm run db:create:mongo && npm run rm:express:mongo && npm run cd:mv:example && node -r dotenv/config ./bin -N example/express-mongo -D 'This is a test using Express with Prisma and MongoDB' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H --tests --ghat && npm run rm:git:express",
25
+ "build:fastify": "npm run db:create:sql && npm run rm:fastify && npm run cd:mv:example && node -r dotenv/config ./bin -N example/fastify -D 'This is a test using Fastify with Prisma and PostgreSQL' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H--tests --ghat -d postgres -F && npm run rm:git:fastify",
26
+ "build:fastify:mongo": "npm run db:create:mongo && npm run rm:fastify:mongo && npm run cd:mv:example && node -r dotenv/config ./bin -N example/fastify-mongo -D 'This is a test using Fastify with Prisma and MongoDB' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H --tests --ghat -F && npm run rm:git:fastify:mongo",
27
+ "build:express:graphql": "npm run db:create:sql && npm run rm:express:graphql && npm run cd:mv:example && node -r dotenv/config ./bin -N example/express-graphql -D 'This is a test using Express with GraphQL with Prisma and PostgreSQL' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H -g --tests --ghat -d postgres && npm run rm:git:express:graphql",
28
+ "build:express:mongo:graphql": "npm run db:create:mongo && npm run rm:express:mongo:graphql && npm run cd:mv:example && node -r dotenv/config ./bin -N example/express-mongo-graphql -D 'This is a test using Express with GraphQL with Prisma and MongoDB' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H -g --tests --ghat && npm run rm:git:express:mongo:graphql",
29
+ "build:fastify:graphql": "npm run db:create:sql && npm run rm:fastify:graphql && npm run cd:mv:example && node -r dotenv/config ./bin -N example/fastify-graphql -D 'This is a test using Fastify with GraphQL with Prisma and PostgreSQL' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H -g --tests --ghat -d postgres -F && npm run rm:git:fastify:graphql",
30
+ "build:fastify:mongo:graphql": "npm run db:create:mongo && npm run rm:fastify:mongo:graphql && npm run cd:mv:example && node -r dotenv/config ./bin -N example/fastify-mongo-graphql -D 'This is a test using Fastify with GraphQL with Prisma and MongoDB' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H -g --tests --ghat -F && npm run rm:git:fastify:mongo:graphql",
25
31
  "build:and:test:only": "npm run build && npm run test:only",
26
32
  "test": "npm run test:without:restore && git restore .",
27
- "test:local": "npm run test:without:restore && git restore .",
28
- "test:integration": "jest --testPathPattern=test/integration",
29
- "test:without:restore": "npm run build && npm run test:express:local && npm run test:express:mongo:local && npm run test:express:graphql:local && npm run test:express:mongo:graphql:local && npm run test:fastify:local && npm run test:fastify:mongo:local && npm run test:fastify:graphql:local && npm run test:fastify:mongo:graphql:local",
33
+ "test:local": "npm run test:without:restore",
34
+ "test:integration": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.integration.config.js --testPathPattern=test/integration",
35
+ "test:without:restore": "npm run db:create && npm run build && npm run test:express:local && npm run test:express:mongo:local && npm run test:express:graphql:local && npm run test:express:mongo:graphql:local && npm run test:fastify:local && npm run test:fastify:mongo:local && npm run test:fastify:graphql:local && npm run test:fastify:mongo:graphql:local",
30
36
  "test:mongo:ci": "npm run build:mongo && npm run test:express:mongo:ci && npm run test:fastify:mongo:ci && npm run test:express:mongo:graphql:ci && npm run test:fastify:mongo:graphql:ci",
31
37
  "test:sql:ci": "npm run build:sql && npm run test:express:ci && npm run test:fastify:ci && npm run test:express:graphql:ci && npm run test:fastify:graphql:ci",
32
38
  "test:only": "npm run test:express:only && npm run test:fastify:only",
@@ -78,7 +84,6 @@
78
84
  "rm:git:fastify:mongo:graphql": "if [ -d \"example/fastify-mongo-graphql/.git\" ]; then rm -rf example/fastify-mongo-graphql/.git; fi",
79
85
  "rm:project:structures": "if [ -d \"projectStructureExamples\" ]; then rm -rf projectStructureExamples/*; fi",
80
86
  "cd:mv:example": "if [ ! -d \"example\" ]; then mkdir example && cd example; fi",
81
- "restore:db": "node ./scripts/restoreRelationalDb.js && node ./scripts/restoreMongoDb.js",
82
87
  "release": "standard-version",
83
88
  "version": "npm run release && npm run list:directory:tree:examples && git add ."
84
89
  },
@@ -100,28 +105,28 @@
100
105
  "author": "AnthonyLzq",
101
106
  "license": "MIT",
102
107
  "dependencies": {
103
- "cli-progress": "^3.12.0",
104
- "colors": "^1.4.0",
105
- "prompts": "^2.4.2",
106
- "underscore": "^1.13.6",
107
- "yargs": "^17.7.2"
108
+ "cli-progress": "3.12.0",
109
+ "colors": "1.4.0",
110
+ "prompts": "2.4.2",
111
+ "underscore": "1.13.7",
112
+ "yargs": "17.7.2"
108
113
  },
109
114
  "devDependencies": {
110
- "@types/jest": "^29.5.3",
111
- "dotenv": "^16.3.1",
112
- "eslint": "^8.46.0",
113
- "eslint-config-prettier": "^8.10.0",
114
- "eslint-config-standard": "^17.1.0",
115
- "eslint-plugin-import": "^2.28.0",
116
- "eslint-plugin-node": "^11.1.0",
117
- "eslint-plugin-prettier": "^5.0.0",
118
- "eslint-plugin-promise": "^6.1.1",
119
- "jest": "^29.6.2",
120
- "knex": "^2.5.1",
121
- "mongodb": "^5.7.0",
122
- "pg": "^8.11.2",
123
- "prettier": "^3.0.1",
124
- "standard-version": "^9.5.0"
115
+ "@types/jest": "29.5.12",
116
+ "dotenv": "16.4.5",
117
+ "eslint": "^8",
118
+ "eslint-config-prettier": "^8",
119
+ "eslint-config-standard": "17.1.0",
120
+ "eslint-plugin-import": "2.29.1",
121
+ "eslint-plugin-node": "11.1.0",
122
+ "eslint-plugin-prettier": "5.2.1",
123
+ "eslint-plugin-promise": "^6",
124
+ "jest": "29.7.0",
125
+ "knex": "3.1.0",
126
+ "mongodb": "6.8.0",
127
+ "pg": "8.12.0",
128
+ "prettier": "3.3.3",
129
+ "standard-version": "9.5.0"
125
130
  },
126
131
  "repository": {
127
132
  "type": "git",