@nestledjs/api 0.0.1

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.
Files changed (132) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +11 -0
  3. package/eslint.config.cjs +28 -0
  4. package/generators.json +69 -0
  5. package/package.json +21 -0
  6. package/project.json +47 -0
  7. package/src/account/files/data-access/src/index.ts__tmpl__ +5 -0
  8. package/src/account/files/data-access/src/lib/api-account-data-access.module.ts__tmpl__ +10 -0
  9. package/src/account/files/data-access/src/lib/api-account-data-access.service.ts__tmpl__ +152 -0
  10. package/src/account/files/data-access/src/lib/dto/account-create-email.input.ts__tmpl__ +9 -0
  11. package/src/account/files/data-access/src/lib/dto/account-update-password.input.ts__tmpl__ +16 -0
  12. package/src/account/files/data-access/src/lib/dto/account-update-profile.input.ts__tmpl__ +25 -0
  13. package/src/account/files/feature/src/index.ts__tmpl__ +1 -0
  14. package/src/account/files/feature/src/lib/api-account-feature.module.ts__tmpl__ +9 -0
  15. package/src/account/files/feature/src/lib/api-account-feature.resolver.ts__tmpl__ +83 -0
  16. package/src/account/generator.spec.ts +71 -0
  17. package/src/account/generator.ts +20 -0
  18. package/src/account/schema.d.ts +3 -0
  19. package/src/account/schema.json +13 -0
  20. package/src/app/files/src/app.config.ts__tmpl__ +66 -0
  21. package/src/app/files/src/app.module.ts__tmpl__ +43 -0
  22. package/src/app/files/src/applogger.middleware.ts__tmpl__ +21 -0
  23. package/src/app/files/src/main.ts__tmpl__ +33 -0
  24. package/src/app/files/webpack.config.js__tmpl__ +54 -0
  25. package/src/app/generator.spec.ts +112 -0
  26. package/src/app/generator.ts +105 -0
  27. package/src/app/schema.d.ts +1 -0
  28. package/src/app/schema.json +9 -0
  29. package/src/config/files/src/index.ts__tmpl__ +3 -0
  30. package/src/config/files/src/lib/config.service.ts__tmpl__ +51 -0
  31. package/src/config/files/src/lib/configuration.ts__tmpl__ +32 -0
  32. package/src/config/files/src/lib/validation.ts__tmpl__ +21 -0
  33. package/src/config/generator.spec.ts +47 -0
  34. package/src/config/generator.ts +16 -0
  35. package/src/config/schema.d.ts +3 -0
  36. package/src/config/schema.json +13 -0
  37. package/src/core/files/data-access/src/index.ts__tmpl__ +5 -0
  38. package/src/core/files/data-access/src/lib/api-core-data-access.module.ts__tmpl__ +9 -0
  39. package/src/core/files/data-access/src/lib/api-core-data-access.service.ts__tmpl__ +97 -0
  40. package/src/core/files/data-access/src/lib/api-core-pub-sub.ts__tmpl__ +37 -0
  41. package/src/core/files/data-access/src/lib/dto/core-paging.input.ts__tmpl__ +26 -0
  42. package/src/core/files/data-access/src/lib/dto/multi-select-input.ts__tmpl__ +7 -0
  43. package/src/core/files/data-access/src/lib/models/core-paging.ts__tmpl__ +19 -0
  44. package/src/core/files/feature/src/index.ts__tmpl__ +2 -0
  45. package/src/core/files/feature/src/lib/api-core-feature.controller.ts__tmpl__ +12 -0
  46. package/src/core/files/feature/src/lib/api-core-feature.module.ts__tmpl__ +86 -0
  47. package/src/core/files/feature/src/lib/api-core-feature.resolver.ts__tmpl__ +12 -0
  48. package/src/core/files/feature/src/lib/api-core-feature.service.ts__tmpl__ +55 -0
  49. package/src/core/files/feature/src/lib/config/configuration.ts__tmpl__ +32 -0
  50. package/src/core/files/feature/src/lib/config/validation.ts__tmpl__ +25 -0
  51. package/src/core/files/feature/src/lib/plugins/complexity.plugin.ts__tmpl__ +51 -0
  52. package/src/core/files/feature/src/lib/plugins/logging.plugin.ts__tmpl__ +17 -0
  53. package/src/core/files/models/src/index.ts__tmpl__ +1 -0
  54. package/src/core/files/models/src/lib/generate-models.ts__tmpl__ +294 -0
  55. package/src/core/files/models/src/lib/models/core-paging.model.ts__tmpl__ +25 -0
  56. package/src/core/generator.spec.ts +85 -0
  57. package/src/core/generator.ts +35 -0
  58. package/src/core/schema.d.ts +3 -0
  59. package/src/core/schema.json +13 -0
  60. package/src/custom/generator.spec.ts +75 -0
  61. package/src/custom/generator.ts +239 -0
  62. package/src/custom/schema.json +21 -0
  63. package/src/custom/schema.ts +5 -0
  64. package/src/extended/generator.spec.ts +95 -0
  65. package/src/extended/generator.ts +161 -0
  66. package/src/extended/index.ts +1 -0
  67. package/src/extended/schema.json +12 -0
  68. package/src/extended/schema.ts +3 -0
  69. package/src/generate-crud/files/data-access/src/index.ts__tmpl__ +3 -0
  70. package/src/generate-crud/files/data-access/src/lib/api-crud-data-access.module.ts__tmpl__ +11 -0
  71. package/src/generate-crud/files/data-access/src/lib/api-crud-data-access.service.ts__tmpl__ +72 -0
  72. package/src/generate-crud/files/data-access/src/lib/dto/index.ts__tmpl__ +224 -0
  73. package/src/generate-crud/files/feature/.gitkeep +0 -0
  74. package/src/generate-crud/generator.spec.ts +84 -0
  75. package/src/generate-crud/generator.ts +354 -0
  76. package/src/generate-crud/schema.json +32 -0
  77. package/src/generate-crud/schema.ts +8 -0
  78. package/src/index.ts +13 -0
  79. package/src/plugin/generator.spec.ts +18 -0
  80. package/src/plugin/generator.ts +74 -0
  81. package/src/plugin/schema.json +14 -0
  82. package/src/plugin/schema.ts +4 -0
  83. package/src/prisma/files/src/index.ts__tmpl__ +1 -0
  84. package/src/prisma/files/src/lib/.gitkeep +1 -0
  85. package/src/prisma/files/src/lib/schemas/schema.prisma__tmpl__ +402 -0
  86. package/src/prisma/files/src/lib/seed/seed-data/iso-3166-countries.ts__tmpl__ +3239 -0
  87. package/src/prisma/files/src/lib/seed/seed-data/seed-users.ts__tmpl__ +32 -0
  88. package/src/prisma/files/src/lib/seed/seed.ts__tmpl__ +64 -0
  89. package/src/prisma/generator.spec.ts +60 -0
  90. package/src/prisma/generator.ts +61 -0
  91. package/src/prisma/schema.d.ts +3 -0
  92. package/src/prisma/schema.json +13 -0
  93. package/src/setup/generator.md +49 -0
  94. package/src/setup/generator.spec.ts +18 -0
  95. package/src/setup/generator.ts +106 -0
  96. package/src/setup/schema.json +8 -0
  97. package/src/smtp-mailer/files/data-access/src/index.ts__tmpl__ +2 -0
  98. package/src/smtp-mailer/files/data-access/src/lib/api-smtp-mailer-data-access.module.ts__tmpl__ +10 -0
  99. package/src/smtp-mailer/files/data-access/src/lib/api-smtp-mailer-data-access.service.ts__tmpl__ +61 -0
  100. package/src/smtp-mailer/generator.spec.ts +41 -0
  101. package/src/smtp-mailer/generator.ts +14 -0
  102. package/src/smtp-mailer/schema.d.ts +0 -0
  103. package/src/smtp-mailer/schema.json +7 -0
  104. package/src/user/files/data-access/src/index.ts__tmpl__ +5 -0
  105. package/src/user/files/data-access/src/lib/api-user-data-access.module.ts__tmpl__ +10 -0
  106. package/src/user/files/data-access/src/lib/api-user-data-access.service.ts__tmpl__ +119 -0
  107. package/src/user/files/data-access/src/lib/dto/admin-create-user.input.ts__tmpl__ +20 -0
  108. package/src/user/files/data-access/src/lib/dto/admin-update-user.input.ts__tmpl__ +29 -0
  109. package/src/user/files/feature/src/index.ts__tmpl__ +1 -0
  110. package/src/user/files/feature/src/lib/api-user-feature-admin.resolver.ts__tmpl__ +57 -0
  111. package/src/user/files/feature/src/lib/api-user-feature.module.ts__tmpl__ +10 -0
  112. package/src/user/files/feature/src/lib/api-user-feature.resolver.ts__tmpl__ +17 -0
  113. package/src/user/generator.spec.ts +41 -0
  114. package/src/user/generator.ts +15 -0
  115. package/src/user/schema.d.ts +0 -0
  116. package/src/user/schema.json +7 -0
  117. package/src/utils/files/src/index.ts__tmpl__ +3 -0
  118. package/src/utils/files/src/lib/decorators/ctx-user.decorator.ts__tmpl__ +6 -0
  119. package/src/utils/files/src/lib/guards/gql-auth-admin.guard.ts__tmpl__ +39 -0
  120. package/src/utils/files/src/lib/guards/gql-auth.guard.ts__tmpl__ +11 -0
  121. package/src/utils/generator.ts +14 -0
  122. package/src/utils/schema.json +8 -0
  123. package/src/workspace-setup/generator.md +39 -0
  124. package/src/workspace-setup/generator.spec.ts +82 -0
  125. package/src/workspace-setup/generator.ts +49 -0
  126. package/src/workspace-setup/lib/helpers.ts +142 -0
  127. package/src/workspace-setup/schema.d.ts +3 -0
  128. package/src/workspace-setup/schema.json +7 -0
  129. package/tsconfig.json +16 -0
  130. package/tsconfig.lib.json +23 -0
  131. package/tsconfig.spec.json +22 -0
  132. package/vite.config.mts +37 -0
@@ -0,0 +1,142 @@
1
+ import { execSync } from 'child_process'
2
+ import { existsSync, readFileSync, writeFileSync } from 'fs'
3
+ import { basename } from 'path'
4
+ import { Client } from 'pg'
5
+
6
+ export const MAX_RETRIES = 30
7
+ export const WORKSPACE_NAME = basename(process.cwd())
8
+ export const DATABASE_URL = process.env.DATABASE_URL
9
+ export const DOCKER_COMPOSE_FILE = '.dev/docker-compose.yml'
10
+
11
+ export function log(...msg) {
12
+ console.log(`[${WORKSPACE_NAME}]`, ...msg)
13
+ }
14
+
15
+ export async function connectToPostgres(url: string): Promise<Client> {
16
+ const client = new Client(url)
17
+ await client.connect()
18
+ return client
19
+ }
20
+
21
+ export async function canConnect(url: string): Promise<boolean> {
22
+ try {
23
+ await connectToPostgres(url)
24
+ log('Connected to Postgres')
25
+ return true
26
+ } catch {
27
+ return false
28
+ }
29
+ }
30
+
31
+ export function ensureDockerIsRunning() {
32
+ try {
33
+ execSync('docker ps', { stdio: 'ignore' })
34
+ log('Docker is Up')
35
+ return true
36
+ } catch {
37
+ throw new Error(`Make sure Docker is running, then run this again`)
38
+ }
39
+ }
40
+
41
+ export function isDockerComposeRunning(): boolean {
42
+ try {
43
+ const res = execSync(`docker compose -f ${DOCKER_COMPOSE_FILE} top`, {
44
+ stdio: ['inherit', 'inherit'],
45
+ })
46
+
47
+ if (res) {
48
+ log('Docker Compose is Running')
49
+ return true
50
+ }
51
+ return false
52
+ } catch {
53
+ return false
54
+ }
55
+ }
56
+
57
+ export async function ensureDockerComposeIsRunning() {
58
+ const isRunning = isDockerComposeRunning()
59
+ if (isRunning) {
60
+ return true
61
+ }
62
+
63
+ try {
64
+ execSync(`docker compose -f ${DOCKER_COMPOSE_FILE} up -d`, { stdio: 'ignore' })
65
+ await waitForConnection()
66
+ log('Docker Compose Started')
67
+ } catch {
68
+ throw new Error(`Make sure Docker Compose is running`)
69
+ }
70
+ }
71
+
72
+ export function ensureDotEnv() {
73
+ try {
74
+ if (!existsSync('.env')) {
75
+ writeFileSync('.env', readFileSync('.env.example'))
76
+ log('.env created (copied from .env.example)')
77
+ } else {
78
+ log('.env exists')
79
+ }
80
+ } catch {
81
+ throw new Error(`Error creating or reading.env file`)
82
+ }
83
+ }
84
+
85
+ export function runPrismaSetup() {
86
+ try {
87
+ execSync('pnpm prisma:apply', { stdio: 'ignore' })
88
+ log('Prisma Setup is Done')
89
+ return true
90
+ } catch {
91
+ throw new Error(`There was an issue running 'pnpm prisma:apply'`)
92
+ }
93
+ }
94
+
95
+ export function runPrismaSeed() {
96
+ try {
97
+ execSync('npx prisma db seed -- --confirm --timeout 0', { stdio: 'inherit' })
98
+ log('Prisma Seed is Done')
99
+ return true
100
+ } catch (e) {
101
+ console.error('Prisma Seed Error:', e.message)
102
+ throw new Error(`There was an issue running 'pnpm prisma:seed': ${e.message}`)
103
+ }
104
+ }
105
+
106
+ export function runGraphQLTypeGeneration() {
107
+ try {
108
+ execSync('pnpm generate:models', { stdio: 'inherit' })
109
+ log('GraphQL types generation is done')
110
+ return true
111
+ } catch (e) {
112
+ console.error('GraphQL types generation error:', e.message)
113
+ throw new Error(`There was an issue running 'pnpm generate:models': ${e.message}`)
114
+ }
115
+ }
116
+
117
+ export const sleep = (ms = 1000) => new Promise((resolve) => setTimeout(resolve, ms))
118
+
119
+ function waitForConnection(): Promise<void> {
120
+ log('Waiting for Postgres to connect')
121
+ return new Promise((resolve, reject) => {
122
+ let count = 0
123
+
124
+ function tryConnect() {
125
+ if (count >= MAX_RETRIES) {
126
+ reject()
127
+ return
128
+ }
129
+
130
+ canConnect(DATABASE_URL).then((isConnected) => {
131
+ if (isConnected) {
132
+ resolve()
133
+ } else {
134
+ count++
135
+ sleep().then(tryConnect)
136
+ }
137
+ })
138
+ }
139
+
140
+ tryConnect()
141
+ })
142
+ }
@@ -0,0 +1,3 @@
1
+ export interface WorkspaceSetupGeneratorSchema {
2
+ name: string
3
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "cli": "nx",
3
+ "id": "workspace-setup",
4
+ "type": "object",
5
+ "properties": {},
6
+ "required": []
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "NodeNext"
5
+ },
6
+ "files": [],
7
+ "include": [],
8
+ "references": [
9
+ {
10
+ "path": "./tsconfig.lib.json"
11
+ },
12
+ {
13
+ "path": "./tsconfig.spec.json"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "declaration": true,
6
+ "types": ["node"]
7
+ },
8
+ "include": ["src/**/*.ts"],
9
+ "exclude": [
10
+ "vite.config.mts",
11
+ "vite.config.mts",
12
+ "vitest.config.ts",
13
+ "vitest.config.mts",
14
+ "src/**/*.test.ts",
15
+ "src/**/*.spec.ts",
16
+ "src/**/*.test.tsx",
17
+ "src/**/*.spec.tsx",
18
+ "src/**/*.test.js",
19
+ "src/**/*.spec.js",
20
+ "src/**/*.test.jsx",
21
+ "src/**/*.spec.jsx"
22
+ ]
23
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node", "vitest"]
6
+ },
7
+ "include": [
8
+ "vite.config.mts",
9
+ "vite.config.mts",
10
+ "vitest.config.ts",
11
+ "vitest.config.mts",
12
+ "src/**/*.test.ts",
13
+ "src/**/*.spec.ts",
14
+ "src/**/*.test.tsx",
15
+ "src/**/*.spec.tsx",
16
+ "src/**/*.test.js",
17
+ "src/**/*.spec.js",
18
+ "src/**/*.test.jsx",
19
+ "src/**/*.spec.jsx",
20
+ "src/**/*.d.ts"
21
+ ]
22
+ }
@@ -0,0 +1,37 @@
1
+ /// <reference types="vitest" />
2
+ import { defineConfig } from 'vite'
3
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'
4
+ import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'
5
+ import path from 'path'
6
+
7
+ export default defineConfig(() => ({
8
+ root: __dirname,
9
+ cacheDir: '../../node_modules/.vite/generators/api',
10
+ plugins: [nxCopyAssetsPlugin(['*.md'])],
11
+ resolve: {
12
+ alias: {
13
+ '@nestledjs/utils': path.resolve(__dirname, '../../dist/generators/utils/src/index.js'),
14
+ },
15
+ },
16
+ // Uncomment this if you are using workers.
17
+ // worker: {
18
+ // plugins: [ nxViteTsPaths() ],
19
+ // },
20
+ test: {
21
+ globals: true,
22
+ environment: 'node',
23
+ include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
24
+ pool: 'threads',
25
+ poolOptions: {
26
+ forks: {
27
+ singleFork: true,
28
+ },
29
+ },
30
+ watch: false,
31
+ reporters: ['default'],
32
+ coverage: {
33
+ reportsDirectory: '../../coverage/generators/api',
34
+ provider: 'v8' as const,
35
+ },
36
+ },
37
+ }))