@nestledjs/api 0.2.0 → 1.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestledjs/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"generators": "./generators.json",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"pg": "^8.13.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@nestledjs/utils": "0.1
|
|
28
|
+
"@nestledjs/utils": "0.2.1"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -3,6 +3,66 @@ import { join } from 'path'
|
|
|
3
3
|
import { execSync } from 'child_process'
|
|
4
4
|
import { getDMMF } from '@prisma/internals'
|
|
5
5
|
|
|
6
|
+
function extractQuotedStrings(input: string): string[] {
|
|
7
|
+
const values: string[] = []
|
|
8
|
+
const regex = /['"`]([^'"`]+)['"`]/g
|
|
9
|
+
let match: RegExpExecArray | null
|
|
10
|
+
while ((match = regex.exec(input)) !== null) {
|
|
11
|
+
values.push(match[1])
|
|
12
|
+
}
|
|
13
|
+
return values
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Helper to extract the argument string of path.join(), handling nested parentheses
|
|
17
|
+
function extractPathJoinArgs(content: string): string | null {
|
|
18
|
+
const needle = 'path.join('
|
|
19
|
+
const pathJoinIndex = content.indexOf(needle)
|
|
20
|
+
if (pathJoinIndex === -1) return null
|
|
21
|
+
let start = content.indexOf('(', pathJoinIndex)
|
|
22
|
+
if (start === -1) return null
|
|
23
|
+
start++ // move past '('
|
|
24
|
+
let depth = 1
|
|
25
|
+
let end = start
|
|
26
|
+
while (end < content.length && depth > 0) {
|
|
27
|
+
const ch = content[end]
|
|
28
|
+
if (ch === '(') depth++
|
|
29
|
+
else if (ch === ')') depth--
|
|
30
|
+
end++
|
|
31
|
+
}
|
|
32
|
+
if (depth === 0) {
|
|
33
|
+
return content.slice(start, end - 1)
|
|
34
|
+
}
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Parse `schema` from prisma.config.ts content
|
|
39
|
+
function parseSchemaPathSettingFromConfigContent(content: string): string | null {
|
|
40
|
+
const joinArgs = extractPathJoinArgs(content)
|
|
41
|
+
if (joinArgs) {
|
|
42
|
+
const parts = extractQuotedStrings(joinArgs)
|
|
43
|
+
if (parts.length) return parts.join('/')
|
|
44
|
+
}
|
|
45
|
+
return content.match(/schema\s*:\s*['"`]([^'"`]+)['"`]/)?.[1] ?? null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Resolve schema setting from prisma.config.ts or package.json
|
|
49
|
+
function getSchemaPathSetting(projectRoot: string): string | null {
|
|
50
|
+
const configPath = join(projectRoot, 'prisma.config.ts')
|
|
51
|
+
if (existsSync(configPath)) {
|
|
52
|
+
const content = readFileSync(configPath, 'utf-8')
|
|
53
|
+
const fromConfig = parseSchemaPathSettingFromConfigContent(content)
|
|
54
|
+
if (fromConfig) return fromConfig
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const packageJsonPath = join(projectRoot, 'package.json')
|
|
59
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
|
|
60
|
+
return packageJson?.prisma?.schema ?? null
|
|
61
|
+
} catch {
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
6
66
|
// Find project root and get schema path from package.json
|
|
7
67
|
function findProjectRoot(startDir: string): string {
|
|
8
68
|
try {
|
|
@@ -20,24 +80,15 @@ function findProjectRoot(startDir: string): string {
|
|
|
20
80
|
}
|
|
21
81
|
}
|
|
22
82
|
|
|
23
|
-
// Determine the correct prisma import path based on
|
|
83
|
+
// Determine the correct prisma import path based on configuration
|
|
24
84
|
function getPrismaImportPath(): string {
|
|
25
85
|
try {
|
|
26
86
|
const projectRoot = findProjectRoot(__dirname)
|
|
27
|
-
const
|
|
28
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
|
|
29
|
-
|
|
30
|
-
const schemaPathSetting = packageJson.prisma?.schema || ''
|
|
87
|
+
const schemaPathSetting = getSchemaPathSetting(projectRoot) ?? ''
|
|
31
88
|
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
schemaPathSetting.includes('libs/api/prisma') ||
|
|
35
|
-
schemaPathSetting.includes('prisma/src/lib')
|
|
36
|
-
) {
|
|
89
|
+
if (schemaPathSetting.includes('libs/api/prisma') || schemaPathSetting.includes('prisma/src/lib')) {
|
|
37
90
|
return '@<%= npmScope %>/api/prisma'
|
|
38
91
|
}
|
|
39
|
-
|
|
40
|
-
// Fallback to the original path if not explicitly the new structure
|
|
41
92
|
return '@<%= npmScope %>/api/core/data-access'
|
|
42
93
|
} catch (error) {
|
|
43
94
|
console.error('Error determining Prisma import path:', error)
|
|
@@ -46,20 +97,14 @@ function getPrismaImportPath(): string {
|
|
|
46
97
|
}
|
|
47
98
|
}
|
|
48
99
|
|
|
49
|
-
// Get schema directory path from
|
|
100
|
+
// Get schema directory path from configuration
|
|
50
101
|
function getPrismaSchemaDir(): string {
|
|
51
102
|
// Renamed
|
|
52
103
|
try {
|
|
53
104
|
const projectRoot = findProjectRoot(__dirname)
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!packageJson.prisma?.schema) {
|
|
58
|
-
throw new Error('prisma.schema path not found in package.json')
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Join the project root with the schema path (which should be a directory)
|
|
62
|
-
return join(projectRoot, packageJson.prisma.schema)
|
|
105
|
+
const setting = getSchemaPathSetting(projectRoot)
|
|
106
|
+
if (setting) return join(projectRoot, setting)
|
|
107
|
+
throw new Error('Prisma schema path not found in config or package.json')
|
|
63
108
|
} catch (error) {
|
|
64
109
|
console.error('Error getting Prisma schema directory path:', error)
|
|
65
110
|
// Fallback to the old directory path for backward compatibility
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'dotenv/config'
|
|
2
|
+
import * as path from 'node:path'
|
|
3
|
+
import { defineConfig } from 'prisma/config'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
schema: path.join('libs', 'api', 'prisma', 'src', 'lib', 'schemas'),
|
|
7
|
+
migrations: {
|
|
8
|
+
seed: 'ts-node --project libs/api/prisma/tsconfig.lib.json libs/api/prisma/src/lib/seed/seed.ts',
|
|
9
|
+
},
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
|
package/src/prisma/generator.js
CHANGED
|
@@ -8,13 +8,26 @@ function generateLibraries(tree_1) {
|
|
|
8
8
|
return tslib_1.__awaiter(this, arguments, void 0, function* (tree, options = {}) {
|
|
9
9
|
const templateRootPath = (0, devkit_1.joinPathFragments)(__dirname, './files');
|
|
10
10
|
const overwrite = options.overwrite === true;
|
|
11
|
-
//
|
|
11
|
+
// Create prisma.config.ts at workspace root via template (idempotent)
|
|
12
|
+
if (!tree.exists('prisma.config.ts')) {
|
|
13
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(templateRootPath, 'config'), '.', { tmpl: '' });
|
|
14
|
+
// Ensure rename from template path to root file name if needed
|
|
15
|
+
if (!tree.exists('prisma.config.ts') && tree.exists('./prisma.config.ts__tmpl__')) {
|
|
16
|
+
tree.rename('./prisma.config.ts__tmpl__', 'prisma.config.ts');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// Update package.json scripts (remove deprecated prisma.schema field if present)
|
|
12
20
|
(0, devkit_1.updateJson)(tree, 'package.json', (json) => {
|
|
13
|
-
|
|
14
|
-
json.prisma
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
var _a;
|
|
22
|
+
if ((_a = json.prisma) === null || _a === void 0 ? void 0 : _a.schema) {
|
|
23
|
+
delete json.prisma.schema;
|
|
24
|
+
}
|
|
25
|
+
if (!json.prisma) {
|
|
26
|
+
json.prisma = {};
|
|
27
|
+
}
|
|
28
|
+
if (!json.prisma.seed) {
|
|
29
|
+
json.prisma.seed = 'ts-node --project libs/api/prisma/tsconfig.lib.json libs/api/prisma/src/lib/seed/seed.ts';
|
|
30
|
+
}
|
|
18
31
|
// Add GraphQL model generation script for the 'core' library
|
|
19
32
|
if (!json.scripts) {
|
|
20
33
|
json.scripts = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../generators/api/src/prisma/generator.ts"],"names":[],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../generators/api/src/prisma/generator.ts"],"names":[],"mappings":";;AAIA,oCA0EC;;AA9ED,uCAAiH;AACjH,4CAAsD;AAGtD,SAA8B,iBAAiB;iEAAC,IAAU,EAAE,UAAoC,EAAE;QAChG,MAAM,gBAAgB,GAAG,IAAA,0BAAiB,EAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAChE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,KAAK,IAAI,CAAA;QAE5C,sEAAsE;QACtE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACrC,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAA,0BAAiB,EAAC,gBAAgB,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAA;YACrF,+DAA+D;YAC/D,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,4BAA4B,CAAC,EAAE,CAAC;gBAClF,IAAI,CAAC,MAAM,CAAC,4BAA4B,EAAE,kBAAkB,CAAC,CAAA;YAC/D,CAAC;QACH,CAAC;QAED,iF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