@nestledjs/api 1.0.2 → 1.0.4
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.
- package/package.json +1 -1
- package/src/config/files/src/lib/config.service.ts__tmpl__ +8 -0
- package/src/config/files/src/lib/configuration.ts__tmpl__ +6 -0
- package/src/core/files/data-access/src/lib/api-core-data-access.module.ts__tmpl__ +2 -0
- package/src/core/files/data-access/src/lib/api-core-data-access.service.ts__tmpl__ +20 -11
- package/src/core/files/feature/src/lib/config/configuration.ts__tmpl__ +0 -32
- package/src/core/files/feature/src/lib/config/validation.ts__tmpl__ +0 -25
package/package.json
CHANGED
|
@@ -62,4 +62,12 @@ export class ConfigService {
|
|
|
62
62
|
},
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
get prismaOptimizeEnabled(): boolean {
|
|
67
|
+
return this.config.get<boolean>('prisma.optimize.enabled') ?? false
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get prismaOptimizeApiKey(): string | undefined {
|
|
71
|
+
return this.config.get<string>('prisma.optimize.apiKey')
|
|
72
|
+
}
|
|
65
73
|
}
|
|
@@ -30,4 +30,10 @@ export const configuration = () => ({
|
|
|
30
30
|
user: process.env['SMTP_USER'],
|
|
31
31
|
pass: process.env['SMTP_PASS'],
|
|
32
32
|
},
|
|
33
|
+
prisma: {
|
|
34
|
+
optimize: {
|
|
35
|
+
enabled: process.env['OPTIMIZE_ENABLED'] === 'true',
|
|
36
|
+
apiKey: process.env['OPTIMIZE_API_KEY'],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
33
39
|
})
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Module } from '@nestjs/common'
|
|
2
|
+
import { ConfigModule } from '@<%= npmScope %>/api/config'
|
|
2
3
|
|
|
3
4
|
import { ApiCoreDataAccessService } from './api-core-data-access.service'
|
|
4
5
|
|
|
5
6
|
@Module({
|
|
7
|
+
imports: [ConfigModule],
|
|
6
8
|
providers: [ApiCoreDataAccessService],
|
|
7
9
|
exports: [ApiCoreDataAccessService],
|
|
8
10
|
})
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'
|
|
2
2
|
import { Prisma, PrismaClient } from '@<%= npmScope %>/api/prisma'
|
|
3
|
+
import { ConfigService } from '@<%= npmScope %>/api/config'
|
|
3
4
|
import { CorePagingInput } from './dto/core-paging.input'
|
|
4
|
-
import { withOptimize } from '@prisma/extension-optimize'
|
|
5
5
|
|
|
6
6
|
@Injectable()
|
|
7
7
|
export class ApiCoreDataAccessService
|
|
8
8
|
extends PrismaClient
|
|
9
9
|
implements OnModuleInit, OnModuleDestroy
|
|
10
10
|
{
|
|
11
|
-
constructor() {
|
|
11
|
+
constructor(private readonly configService: ConfigService) {
|
|
12
12
|
const config: Prisma.PrismaClientOptions = {
|
|
13
13
|
datasources: {
|
|
14
14
|
db: { url: `${process.env['DATABASE_URL']}?connection_limit=30` },
|
|
@@ -19,18 +19,26 @@ export class ApiCoreDataAccessService
|
|
|
19
19
|
? [{ emit: 'event', level: 'query' }]
|
|
20
20
|
: [{ emit: 'event', level: 'warn' }],
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
// Must call super first before accessing this
|
|
22
24
|
super(config)
|
|
23
25
|
this.queryCount = 0
|
|
24
26
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!apiKey) {
|
|
29
|
-
console.warn('Not Running Prisma Optimize - No API Key Set')
|
|
30
|
-
}
|
|
27
|
+
// Check for Prisma Optimize setup using config service
|
|
28
|
+
const optimizeEnabled = configService.prismaOptimizeEnabled
|
|
29
|
+
const optimizeApiKey = configService.prismaOptimizeApiKey
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
if (optimizeEnabled && optimizeApiKey) {
|
|
32
|
+
console.log('🚀 Prisma Optimize enabled with API key')
|
|
33
|
+
const { withOptimize } = require('@prisma/extension-optimize')
|
|
34
|
+
const extendedClient = new PrismaClient(config).$extends(
|
|
35
|
+
withOptimize({ apiKey: optimizeApiKey })
|
|
36
|
+
)
|
|
33
37
|
Object.assign(this, extendedClient)
|
|
38
|
+
} else {
|
|
39
|
+
if (optimizeEnabled && !optimizeApiKey) {
|
|
40
|
+
console.warn('⚠️ OPTIMIZE_ENABLED is true but OPTIMIZE_API_KEY is not set')
|
|
41
|
+
}
|
|
34
42
|
}
|
|
35
43
|
}
|
|
36
44
|
|
|
@@ -85,8 +93,8 @@ export class ApiCoreDataAccessService
|
|
|
85
93
|
const terms = trimmedSearch.includes(' ')
|
|
86
94
|
? trimmedSearch.split(' ')
|
|
87
95
|
: [trimmedSearch].filter(Boolean)
|
|
88
|
-
const searchFilters = terms.map(
|
|
89
|
-
OR: searchFields.map(
|
|
96
|
+
const searchFilters = terms.map(term => ({
|
|
97
|
+
OR: searchFields.map(field => ({
|
|
90
98
|
[field]: { contains: term, mode: Prisma.QueryMode.insensitive },
|
|
91
99
|
})),
|
|
92
100
|
}))
|
|
@@ -103,3 +111,4 @@ export class ApiCoreDataAccessService
|
|
|
103
111
|
}
|
|
104
112
|
}
|
|
105
113
|
}
|
|
114
|
+
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export const configuration = () => ({
|
|
2
|
-
prefix: 'api',
|
|
3
|
-
environment: process.env['NODE_ENV'],
|
|
4
|
-
host: process.env['HOST'],
|
|
5
|
-
port: parseInt(process.env['PORT'] ?? '3000', 10),
|
|
6
|
-
apiUrl: process.env['API_URL'],
|
|
7
|
-
api: {
|
|
8
|
-
cookie: {
|
|
9
|
-
name: process.env['API_COOKIE_NAME'],
|
|
10
|
-
options: {
|
|
11
|
-
domain: process.env['API_COOKIE_DOMAIN'],
|
|
12
|
-
httpOnly: true,
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
cors: {
|
|
16
|
-
origin: [process.env['WEB_URL']],
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
siteUrl: process.env['SITE_URL'] || process.env['API_URL']?.replace('/api', ''),
|
|
20
|
-
app: {
|
|
21
|
-
email: process.env['APP_EMAIL'],
|
|
22
|
-
supportEmail: process.env['APP_SUPPORT_EMAIL'],
|
|
23
|
-
adminEmails: process.env['APP_ADMIN_EMAILS'],
|
|
24
|
-
name: process.env['APP_NAME'],
|
|
25
|
-
},
|
|
26
|
-
smtp: {
|
|
27
|
-
host: process.env['SMTP_HOST'],
|
|
28
|
-
port: process.env['SMTP_PORT'],
|
|
29
|
-
user: process.env['SMTP_USER'],
|
|
30
|
-
pass: process.env['SMTP_PASS'],
|
|
31
|
-
},
|
|
32
|
-
})
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as Joi from 'joi'
|
|
2
|
-
|
|
3
|
-
export const validationSchema = Joi.object({
|
|
4
|
-
NODE_ENV: Joi.string().valid('development', 'production', 'test'),
|
|
5
|
-
HOST: Joi.string().alphanum().default('localhost'),
|
|
6
|
-
PORT: Joi.number().default(3000),
|
|
7
|
-
WEB_PORT: Joi.number().default(4200),
|
|
8
|
-
WEB_URL: Joi.string().default(
|
|
9
|
-
`http://${process.env['HOST'] || 'localhost'}:${process.env['WEB_PORT']}`
|
|
10
|
-
),
|
|
11
|
-
API_COOKIE_DOMAIN: Joi.string().default('localhost'),
|
|
12
|
-
API_COOKIE_NAME: Joi.string().default('__session'),
|
|
13
|
-
API_URL: Joi.string().default(
|
|
14
|
-
`http://${process.env['HOST'] || 'localhost'}:${process.env['PORT']}/api`
|
|
15
|
-
),
|
|
16
|
-
APP_NAME: Joi.string().required(),
|
|
17
|
-
APP_EMAIL: Joi.string().email().required(),
|
|
18
|
-
APP_SUPPORT_EMAIL: Joi.string().email().required(),
|
|
19
|
-
APP_ADMIN_EMAILS: Joi.string().required(),
|
|
20
|
-
SITE_URL: Joi.string().uri().required(),
|
|
21
|
-
SMTP_HOST: Joi.string().required(),
|
|
22
|
-
SMTP_PORT: Joi.string().required(),
|
|
23
|
-
SMTP_USER: Joi.string().required(),
|
|
24
|
-
SMTP_PASS: Joi.string().required(),
|
|
25
|
-
})
|