@nestledjs/api 1.0.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": "1.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.2.
|
|
28
|
+
"@nestledjs/utils": "0.2.1"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -13,6 +13,56 @@ function extractQuotedStrings(input: string): string[] {
|
|
|
13
13
|
return values
|
|
14
14
|
}
|
|
15
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
|
+
|
|
16
66
|
// Find project root and get schema path from package.json
|
|
17
67
|
function findProjectRoot(startDir: string): string {
|
|
18
68
|
try {
|
|
@@ -34,29 +84,7 @@ function findProjectRoot(startDir: string): string {
|
|
|
34
84
|
function getPrismaImportPath(): string {
|
|
35
85
|
try {
|
|
36
86
|
const projectRoot = findProjectRoot(__dirname)
|
|
37
|
-
const
|
|
38
|
-
let schemaPathSetting = ''
|
|
39
|
-
for (const cfg of cfgCandidates) {
|
|
40
|
-
const configPath = join(projectRoot, cfg)
|
|
41
|
-
if (existsSync(configPath)) {
|
|
42
|
-
const content = readFileSync(configPath, 'utf-8')
|
|
43
|
-
const joinMatch = content.match(/schema\s*:\s*path\.join\(([^)]+)\)/)
|
|
44
|
-
if (joinMatch && joinMatch[1]) {
|
|
45
|
-
const parts = extractQuotedStrings(joinMatch[1])
|
|
46
|
-
if (parts.length) schemaPathSetting = parts.join('/')
|
|
47
|
-
}
|
|
48
|
-
if (!schemaPathSetting) {
|
|
49
|
-
const strMatch = content.match(/schema\s*:\s*['"`]([^'"`]+)['"`]/)
|
|
50
|
-
if (strMatch && strMatch[1]) schemaPathSetting = strMatch[1]
|
|
51
|
-
}
|
|
52
|
-
if (schemaPathSetting) break
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (!schemaPathSetting) {
|
|
56
|
-
const packageJsonPath = join(projectRoot, 'package.json')
|
|
57
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
|
|
58
|
-
schemaPathSetting = packageJson.prisma?.schema || ''
|
|
59
|
-
}
|
|
87
|
+
const schemaPathSetting = getSchemaPathSetting(projectRoot) ?? ''
|
|
60
88
|
|
|
61
89
|
if (schemaPathSetting.includes('libs/api/prisma') || schemaPathSetting.includes('prisma/src/lib')) {
|
|
62
90
|
return '@<%= npmScope %>/api/prisma'
|
|
@@ -74,29 +102,9 @@ function getPrismaSchemaDir(): string {
|
|
|
74
102
|
// Renamed
|
|
75
103
|
try {
|
|
76
104
|
const projectRoot = findProjectRoot(__dirname)
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (existsSync(configPath)) {
|
|
81
|
-
const content = readFileSync(configPath, 'utf-8')
|
|
82
|
-
const joinMatch = content.match(/schema\s*:\s*path\.join\(([^)]+)\)/)
|
|
83
|
-
if (joinMatch && joinMatch[1]) {
|
|
84
|
-
const parts = extractQuotedStrings(joinMatch[1])
|
|
85
|
-
if (parts.length) return join(projectRoot, parts.join('/'))
|
|
86
|
-
}
|
|
87
|
-
const strMatch = content.match(/schema\s*:\s*['"`]([^'"`]+)['"`]/)
|
|
88
|
-
if (strMatch && strMatch[1]) {
|
|
89
|
-
return join(projectRoot, strMatch[1])
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// Fallback to old package.json field if config not found
|
|
94
|
-
const packageJsonPath = join(projectRoot, 'package.json')
|
|
95
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
|
|
96
|
-
if (packageJson.prisma?.schema) {
|
|
97
|
-
return join(projectRoot, packageJson.prisma.schema)
|
|
98
|
-
}
|
|
99
|
-
throw new Error('Prisma schema path not found in config')
|
|
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')
|
|
100
108
|
} catch (error) {
|
|
101
109
|
console.error('Error getting Prisma schema directory path:', error)
|
|
102
110
|
// Fallback to the old directory path for backward compatibility
|