plc-prisma 5.8.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.
- package/README.md +87 -0
- package/build/child.js +82915 -0
- package/build/index.js +2168 -0
- package/build/prisma_schema_build_bg.wasm +0 -0
- package/build/public/assets/alert.60ea9f84.svg +5 -0
- package/build/public/assets/array.1a36c222.svg +4 -0
- package/build/public/assets/boolean.9188b434.svg +4 -0
- package/build/public/assets/chevron-down.24f76e3c.svg +3 -0
- package/build/public/assets/cross.c2610cf5.svg +11 -0
- package/build/public/assets/datetime.a3bf710a.svg +4 -0
- package/build/public/assets/download.8d34b65a.svg +4 -0
- package/build/public/assets/ellipsis.a8c5a34a.svg +10 -0
- package/build/public/assets/enum.7ec0b64c.svg +6 -0
- package/build/public/assets/folder.d77b8eaf.svg +6 -0
- package/build/public/assets/hamburger.5fdadeac.svg +4 -0
- package/build/public/assets/index.js +1 -0
- package/build/public/assets/inter-all-400-normal.4c1f8a0d.woff +0 -0
- package/build/public/assets/inter-all-600-normal.d0a7c8a9.woff +0 -0
- package/build/public/assets/inter-cyrillic-400-normal.ac97a49e.woff2 +0 -0
- package/build/public/assets/inter-cyrillic-600-normal.2c917f10.woff2 +0 -0
- package/build/public/assets/inter-cyrillic-ext-400-normal.f21a6a97.woff2 +0 -0
- package/build/public/assets/inter-cyrillic-ext-600-normal.bb31f197.woff2 +0 -0
- package/build/public/assets/inter-greek-400-normal.e9163df8.woff2 +0 -0
- package/build/public/assets/inter-greek-600-normal.e644d70f.woff2 +0 -0
- package/build/public/assets/inter-greek-ext-400-normal.43addcc8.woff2 +0 -0
- package/build/public/assets/inter-greek-ext-600-normal.7f437016.woff2 +0 -0
- package/build/public/assets/inter-latin-400-normal.27ae72da.woff2 +0 -0
- package/build/public/assets/inter-latin-600-normal.87d718a2.woff2 +0 -0
- package/build/public/assets/inter-latin-ext-400-normal.5b02c69a.woff2 +0 -0
- package/build/public/assets/inter-latin-ext-600-normal.88feb9e4.woff2 +0 -0
- package/build/public/assets/inter-vietnamese-600-normal.8185dacd.woff2 +0 -0
- package/build/public/assets/jetbrains-mono-all-400-normal.f86807b7.woff +0 -0
- package/build/public/assets/jetbrains-mono-cyrillic-400-normal.1ae57fe2.woff2 +0 -0
- package/build/public/assets/jetbrains-mono-latin-400-normal.80a5dc9e.woff2 +0 -0
- package/build/public/assets/jetbrains-mono-latin-ext-400-normal.6315c53c.woff2 +0 -0
- package/build/public/assets/logotype.a960b169.svg +4 -0
- package/build/public/assets/number.85ddf96b.svg +7 -0
- package/build/public/assets/object.0ba944a6.svg +5 -0
- package/build/public/assets/play.8811691e.svg +6 -0
- package/build/public/assets/plus.8fbf7ad3.svg +4 -0
- package/build/public/assets/refresh.d5448ccc.svg +4 -0
- package/build/public/assets/search.2ed766ce.svg +7 -0
- package/build/public/assets/settings.5ad25af2.svg +8 -0
- package/build/public/assets/string.ea615a24.svg +4 -0
- package/build/public/assets/tick-indeterminate.aec8a44d.svg +3 -0
- package/build/public/assets/tick.8cbb6a93.svg +4 -0
- package/build/public/assets/vendor.js +393 -0
- package/build/public/favicon.svg +5 -0
- package/build/public/http/databrowser.js +1 -0
- package/build/public/http/splash.js +1 -0
- package/build/public/icon-1024.png +0 -0
- package/build/public/index.css +1 -0
- package/build/public/pages/http/databrowser.html +21 -0
- package/build/public/pages/http/splash.html +21 -0
- package/build/xdg-open +1066 -0
- package/package.json +131 -0
- package/preinstall/index.js +7 -0
- package/prisma-client/README.md +27 -0
- package/prisma-client/edge.d.ts +1 -0
- package/prisma-client/edge.js +3 -0
- package/prisma-client/extension.d.ts +1 -0
- package/prisma-client/extension.js +3 -0
- package/prisma-client/index-browser.js +3 -0
- package/prisma-client/index.d.ts +1 -0
- package/prisma-client/index.js +3 -0
- package/prisma-client/package.json +180 -0
- package/prisma-client/scripts/colors.js +176 -0
- package/prisma-client/scripts/default-deno-edge.ts +10 -0
- package/prisma-client/scripts/default-edge.js +12 -0
- package/prisma-client/scripts/default-index-browser.js +12 -0
- package/prisma-client/scripts/default-index.d.ts +110 -0
- package/prisma-client/scripts/get-packed-client.js +12 -0
- package/prisma-client/scripts/postinstall.d.ts +5 -0
- package/prisma-client/scripts/postinstall.js +404 -0
- package/scripts/preinstall-entry.js +10 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class PrismaClient {
|
|
2
|
+
constructor() {
|
|
3
|
+
throw new Error(
|
|
4
|
+
`@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
|
|
5
|
+
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues/new`,
|
|
6
|
+
)
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
PrismaClient,
|
|
12
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
|
|
3
|
+
import * as runtime from '@prisma/client/runtime/library'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ## Prisma Client ʲˢ
|
|
7
|
+
*
|
|
8
|
+
* Type-safe database client for TypeScript & Node.js
|
|
9
|
+
* @example
|
|
10
|
+
* ```
|
|
11
|
+
* const prisma = new Prisma()
|
|
12
|
+
* // Fetch zero or more Users
|
|
13
|
+
* const users = await prisma.user.findMany()
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* Read more in our [docs](https://www.prisma.io/docs/concepts/components/prisma-client).
|
|
18
|
+
*/
|
|
19
|
+
export declare const PrismaClient: any
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* ## Prisma Client ʲˢ
|
|
23
|
+
*
|
|
24
|
+
* Type-safe database client for TypeScript & Node.js
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* const prisma = new Prisma()
|
|
28
|
+
* // Fetch zero or more Users
|
|
29
|
+
* const users = await prisma.user.findMany()
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
*
|
|
33
|
+
* Read more in our [docs](https://www.prisma.io/docs/concepts/components/prisma-client).
|
|
34
|
+
*/
|
|
35
|
+
export declare type PrismaClient = any
|
|
36
|
+
|
|
37
|
+
export declare class PrismaClientExtends<
|
|
38
|
+
ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs,
|
|
39
|
+
> {
|
|
40
|
+
$extends: { extArgs: ExtArgs } & (<
|
|
41
|
+
R extends runtime.Types.Extensions.UserArgs['result'] = {},
|
|
42
|
+
M extends runtime.Types.Extensions.UserArgs['model'] = {},
|
|
43
|
+
Q extends runtime.Types.Extensions.UserArgs['query'] = {},
|
|
44
|
+
C extends runtime.Types.Extensions.UserArgs['client'] = {},
|
|
45
|
+
Args extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.InternalArgs<R, M, {}, C>,
|
|
46
|
+
>(
|
|
47
|
+
args:
|
|
48
|
+
| ((client: PrismaClientExtends<ExtArgs>) => { $extends: { extArgs: Args } })
|
|
49
|
+
| { name?: string }
|
|
50
|
+
| { result?: R & runtime.Types.Extensions.UserArgs['result'] }
|
|
51
|
+
| { model?: M & runtime.Types.Extensions.UserArgs['model'] }
|
|
52
|
+
| { query?: Q & runtime.Types.Extensions.UserArgs['query'] }
|
|
53
|
+
| { client?: C & runtime.Types.Extensions.UserArgs['client'] },
|
|
54
|
+
) => PrismaClientExtends<Args & ExtArgs> & Args['client'])
|
|
55
|
+
|
|
56
|
+
$transaction<R>(
|
|
57
|
+
fn: (prisma: Omit<this, runtime.ITXClientDenyList>) => Promise<R>,
|
|
58
|
+
options?: { maxWait?: number; timeout?: number; isolationLevel?: string },
|
|
59
|
+
): Promise<R>
|
|
60
|
+
$transaction<P extends Prisma.PrismaPromise<any>[]>(
|
|
61
|
+
arg: [...P],
|
|
62
|
+
options?: { isolationLevel?: string },
|
|
63
|
+
): Promise<runtime.Types.Utils.UnwrapTuple<P>>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export declare const dmmf: any
|
|
67
|
+
export declare type dmmf = any
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the type of the value, that the Promise holds.
|
|
71
|
+
*/
|
|
72
|
+
export declare type PromiseType<T extends PromiseLike<any>> = T extends PromiseLike<infer U> ? U : T
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get the return type of a function which returns a Promise.
|
|
76
|
+
*/
|
|
77
|
+
export declare type PromiseReturnType<T extends (...args: any) => Promise<any>> = PromiseType<ReturnType<T>>
|
|
78
|
+
|
|
79
|
+
export namespace Prisma {
|
|
80
|
+
export type TransactionClient = any
|
|
81
|
+
|
|
82
|
+
export function defineExtension<
|
|
83
|
+
R extends runtime.Types.Extensions.UserArgs['result'] = {},
|
|
84
|
+
M extends runtime.Types.Extensions.UserArgs['model'] = {},
|
|
85
|
+
Q extends runtime.Types.Extensions.UserArgs['query'] = {},
|
|
86
|
+
C extends runtime.Types.Extensions.UserArgs['client'] = {},
|
|
87
|
+
Args extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.InternalArgs<R, M, {}, C>,
|
|
88
|
+
>(
|
|
89
|
+
args:
|
|
90
|
+
| ((client: PrismaClientExtends) => { $extends: { extArgs: Args } })
|
|
91
|
+
| { name?: string }
|
|
92
|
+
| { result?: R & runtime.Types.Extensions.UserArgs['result'] }
|
|
93
|
+
| { model?: M & runtime.Types.Extensions.UserArgs['model'] }
|
|
94
|
+
| { query?: Q & runtime.Types.Extensions.UserArgs['query'] }
|
|
95
|
+
| { client?: C & runtime.Types.Extensions.UserArgs['client'] },
|
|
96
|
+
): (client: any) => PrismaClientExtends<Args>
|
|
97
|
+
|
|
98
|
+
export type Extension = runtime.Types.Extensions.UserArgs
|
|
99
|
+
export import getExtensionContext = runtime.Extensions.getExtensionContext
|
|
100
|
+
export import Args = runtime.Types.Public.Args
|
|
101
|
+
export import Payload = runtime.Types.Public.Payload
|
|
102
|
+
export import Result = runtime.Types.Public.Result
|
|
103
|
+
export import Exact = runtime.Types.Public.Exact
|
|
104
|
+
export import PrismaPromise = runtime.Types.Public.PrismaPromise
|
|
105
|
+
|
|
106
|
+
export const prismaVersion: {
|
|
107
|
+
client: string
|
|
108
|
+
engine: string
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const { getPackedPackage } = require('@prisma/internals')
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
const target = path.join(process.cwd(), './node_modules/@prisma/client')
|
|
8
|
+
await getPackedPackage('@prisma/client', target, path.join(__dirname, '../'))
|
|
9
|
+
console.log(`Saving packed client to ${target}`)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
void main()
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function getPostInstallTrigger(): string
|
|
2
|
+
export const UNABLE_TO_FIND_POSTINSTALL_TRIGGER__EMPTY_STRING
|
|
3
|
+
export const UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING
|
|
4
|
+
export const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR
|
|
5
|
+
export const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const childProcess = require('child_process')
|
|
3
|
+
const { promisify } = require('util')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const c = require('./colors')
|
|
7
|
+
|
|
8
|
+
const exec = promisify(childProcess.exec)
|
|
9
|
+
|
|
10
|
+
function debug(message, ...optionalParams) {
|
|
11
|
+
if (process.env.DEBUG && process.env.DEBUG === 'prisma:postinstall') {
|
|
12
|
+
console.log(message, ...optionalParams)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Adds `package.json` to the end of a path if it doesn't already exist'
|
|
17
|
+
* @param {string} pth
|
|
18
|
+
*/
|
|
19
|
+
function addPackageJSON(pth) {
|
|
20
|
+
if (pth.endsWith('package.json')) return pth
|
|
21
|
+
return path.join(pth, 'package.json')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Looks up for a `package.json` which is not `@prisma/cli` or `prisma` and returns the directory of the package
|
|
26
|
+
* @param {string} startPath - Path to Start At
|
|
27
|
+
* @param {number} limit - Find Up limit
|
|
28
|
+
* @returns {string | null}
|
|
29
|
+
*/
|
|
30
|
+
function findPackageRoot(startPath, limit = 10) {
|
|
31
|
+
if (!startPath || !fs.existsSync(startPath)) return null
|
|
32
|
+
let currentPath = startPath
|
|
33
|
+
// Limit traversal
|
|
34
|
+
for (let i = 0; i < limit; i++) {
|
|
35
|
+
const pkgPath = addPackageJSON(currentPath)
|
|
36
|
+
if (fs.existsSync(pkgPath)) {
|
|
37
|
+
try {
|
|
38
|
+
const pkg = require(pkgPath)
|
|
39
|
+
if (pkg.name && !['@prisma/cli', 'prisma'].includes(pkg.name)) {
|
|
40
|
+
return pkgPath.replace('package.json', '')
|
|
41
|
+
}
|
|
42
|
+
} catch {} // eslint-disable-line no-empty
|
|
43
|
+
}
|
|
44
|
+
currentPath = path.join(currentPath, '../')
|
|
45
|
+
}
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The `postinstall` hook of client sets up the ground and env vars for the `prisma generate` command,
|
|
51
|
+
* and runs it, showing a warning if the schema is not found.
|
|
52
|
+
* - initializes the ./node_modules/.prisma/client folder with the default index(-browser).js/index.d.ts,
|
|
53
|
+
* which define a `PrismaClient` class stub that throws an error if instantiated before the `prisma generate`
|
|
54
|
+
* command is successfully executed.
|
|
55
|
+
* - sets the path of the root of the project (TODO: to verify) to the `process.env.PRISMA_GENERATE_IN_POSTINSTALL`
|
|
56
|
+
* variable, or `'true'` if the project root cannot be found.
|
|
57
|
+
* - runs `prisma generate`, passing through additional information about the command that triggered the generation,
|
|
58
|
+
* which is useful for debugging/telemetry. It tries to use the local `prisma` package if it is installed, otherwise it
|
|
59
|
+
* falls back to the global `prisma` package. If neither options are available, it warns the user to install `prisma` first.
|
|
60
|
+
*/
|
|
61
|
+
async function main() {
|
|
62
|
+
if (process.env.INIT_CWD) {
|
|
63
|
+
process.chdir(process.env.INIT_CWD) // necessary, because npm chooses __dirname as process.cwd()
|
|
64
|
+
// in the postinstall hook
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
await createDefaultGeneratedThrowFiles()
|
|
68
|
+
|
|
69
|
+
// TODO: consider using the `which` package
|
|
70
|
+
const localPath = getLocalPackagePath()
|
|
71
|
+
|
|
72
|
+
// Only execute if !localpath
|
|
73
|
+
const installedGlobally = localPath ? undefined : await isInstalledGlobally()
|
|
74
|
+
|
|
75
|
+
// this is needed, so we can find the correct schemas in yarn workspace projects
|
|
76
|
+
const root = findPackageRoot(localPath)
|
|
77
|
+
|
|
78
|
+
process.env.PRISMA_GENERATE_IN_POSTINSTALL = root ? root : 'true'
|
|
79
|
+
|
|
80
|
+
debug({
|
|
81
|
+
localPath,
|
|
82
|
+
installedGlobally,
|
|
83
|
+
init_cwd: process.env.INIT_CWD,
|
|
84
|
+
PRISMA_GENERATE_IN_POSTINSTALL: process.env.PRISMA_GENERATE_IN_POSTINSTALL,
|
|
85
|
+
})
|
|
86
|
+
try {
|
|
87
|
+
if (localPath) {
|
|
88
|
+
await run('node', [localPath, 'generate', '--postinstall', doubleQuote(getPostInstallTrigger())])
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
if (installedGlobally) {
|
|
92
|
+
await run('prisma', ['generate', '--postinstall', doubleQuote(getPostInstallTrigger())])
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
} catch (e) {
|
|
96
|
+
// if exit code = 1 do not print
|
|
97
|
+
if (e && e !== 1) {
|
|
98
|
+
console.error(e)
|
|
99
|
+
}
|
|
100
|
+
debug(e)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!localPath && !installedGlobally) {
|
|
104
|
+
console.error(
|
|
105
|
+
`${c.yellow(
|
|
106
|
+
'warning',
|
|
107
|
+
)} In order to use "@prisma/client", please install Prisma CLI. You can install it with "npm add -D prisma".`,
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getLocalPackagePath() {
|
|
113
|
+
try {
|
|
114
|
+
const packagePath = require.resolve('prisma/package.json')
|
|
115
|
+
if (packagePath) {
|
|
116
|
+
return require.resolve('prisma')
|
|
117
|
+
}
|
|
118
|
+
} catch (e) {} // eslint-disable-line no-empty
|
|
119
|
+
|
|
120
|
+
// TODO: consider removing this
|
|
121
|
+
try {
|
|
122
|
+
const packagePath = require.resolve('@prisma/cli/package.json')
|
|
123
|
+
if (packagePath) {
|
|
124
|
+
return require.resolve('@prisma/cli')
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {} // eslint-disable-line no-empty
|
|
127
|
+
|
|
128
|
+
return null
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function isInstalledGlobally() {
|
|
132
|
+
try {
|
|
133
|
+
const result = await exec('prisma -v')
|
|
134
|
+
if (result.stdout.includes('@prisma/client')) {
|
|
135
|
+
return true
|
|
136
|
+
} else {
|
|
137
|
+
console.error(`${c.yellow('warning')} You still have the ${c.bold('prisma')} cli (Prisma 1) installed globally.
|
|
138
|
+
Please uninstall it with either ${c.green('npm remove -g prisma')} or ${c.green('yarn global remove prisma')}.`)
|
|
139
|
+
}
|
|
140
|
+
} catch (e) {
|
|
141
|
+
return false
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (!process.env.PRISMA_SKIP_POSTINSTALL_GENERATE) {
|
|
146
|
+
main()
|
|
147
|
+
.catch((e) => {
|
|
148
|
+
if (e.stderr) {
|
|
149
|
+
if (e.stderr.includes(`Can't find schema.prisma`)) {
|
|
150
|
+
console.error(
|
|
151
|
+
`${c.yellow('warning')} @prisma/client needs a ${c.bold('schema.prisma')} to function, but couldn't find it.
|
|
152
|
+
Please either create one manually or use ${c.bold('prisma init')}.
|
|
153
|
+
Once you created it, run ${c.bold('prisma generate')}.
|
|
154
|
+
To keep Prisma related things separate, we recommend creating it in a subfolder called ${c.underline(
|
|
155
|
+
'./prisma',
|
|
156
|
+
)} like so: ${c.underline('./prisma/schema.prisma')}\n`,
|
|
157
|
+
)
|
|
158
|
+
} else {
|
|
159
|
+
console.error(e.stderr)
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
console.error(e)
|
|
163
|
+
}
|
|
164
|
+
process.exit(0)
|
|
165
|
+
})
|
|
166
|
+
.finally(() => {
|
|
167
|
+
debug(`postinstall trigger: ${getPostInstallTrigger()}`)
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function run(cmd, params, cwd = process.cwd()) {
|
|
172
|
+
const child = childProcess.spawn(cmd, params, {
|
|
173
|
+
stdio: ['pipe', 'inherit', 'inherit'],
|
|
174
|
+
cwd,
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
return new Promise((resolve, reject) => {
|
|
178
|
+
child.on('close', () => {
|
|
179
|
+
resolve()
|
|
180
|
+
})
|
|
181
|
+
child.on('exit', (code) => {
|
|
182
|
+
if (code === 0) {
|
|
183
|
+
resolve()
|
|
184
|
+
} else {
|
|
185
|
+
reject(code)
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
child.on('error', () => {
|
|
189
|
+
reject()
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Copies our default "throw" files into the default generation folder. These
|
|
196
|
+
* files are dummy and informative because they just throw an error to let the
|
|
197
|
+
* user know that they have forgotten to run `prisma generate` or that they
|
|
198
|
+
* don't have a a schema file yet. We only add these files at the default
|
|
199
|
+
* location `node_modules/.prisma/client`.
|
|
200
|
+
*/
|
|
201
|
+
async function createDefaultGeneratedThrowFiles() {
|
|
202
|
+
try {
|
|
203
|
+
const dotPrismaClientDir = path.join(__dirname, '../../../.prisma/client')
|
|
204
|
+
const defaultNodeIndexPath = path.join(dotPrismaClientDir, 'index.js')
|
|
205
|
+
const defaultNodeIndexDtsPath = path.join(dotPrismaClientDir, 'index.d.ts')
|
|
206
|
+
const defaultBrowserIndexPath = path.join(dotPrismaClientDir, 'index-browser.js')
|
|
207
|
+
const defaultEdgeIndexPath = path.join(dotPrismaClientDir, 'edge.js')
|
|
208
|
+
const defaultEdgeIndexDtsPath = path.join(dotPrismaClientDir, 'edge.d.ts')
|
|
209
|
+
const defaultDenoClientDir = path.join(dotPrismaClientDir, 'deno')
|
|
210
|
+
const defaultDenoEdgeIndexPath = path.join(defaultDenoClientDir, 'edge.ts')
|
|
211
|
+
await makeDir(dotPrismaClientDir)
|
|
212
|
+
await makeDir(defaultDenoClientDir)
|
|
213
|
+
|
|
214
|
+
// `default-index.js` may not exist in scripts yet when the postinstall script is running
|
|
215
|
+
// in Prisma repo itself. It will always exist in the published package.
|
|
216
|
+
if (!fs.existsSync(defaultNodeIndexPath) && fs.existsSync(path.join(__dirname, 'default-index.js'))) {
|
|
217
|
+
await fs.promises.copyFile(path.join(__dirname, 'default-index.js'), defaultNodeIndexPath)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (!fs.existsSync(defaultBrowserIndexPath)) {
|
|
221
|
+
await fs.promises.copyFile(path.join(__dirname, 'default-index-browser.js'), defaultBrowserIndexPath)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (!fs.existsSync(defaultNodeIndexDtsPath)) {
|
|
225
|
+
await fs.promises.copyFile(path.join(__dirname, 'default-index.d.ts'), defaultNodeIndexDtsPath)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!fs.existsSync(defaultEdgeIndexPath)) {
|
|
229
|
+
await fs.promises.copyFile(path.join(__dirname, 'default-edge.js'), defaultEdgeIndexPath)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!fs.existsSync(defaultEdgeIndexDtsPath)) {
|
|
233
|
+
await fs.promises.copyFile(path.join(__dirname, 'default-index.d.ts'), defaultEdgeIndexDtsPath)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (!fs.existsSync(defaultDenoEdgeIndexPath)) {
|
|
237
|
+
await fs.promises.copyFile(path.join(__dirname, 'default-deno-edge.ts'), defaultDenoEdgeIndexPath)
|
|
238
|
+
}
|
|
239
|
+
} catch (e) {
|
|
240
|
+
console.error(e)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// TODO: can this be replaced some utility eg. mkdir
|
|
245
|
+
function makeDir(input) {
|
|
246
|
+
const make = async (pth) => {
|
|
247
|
+
try {
|
|
248
|
+
await fs.promises.mkdir(pth)
|
|
249
|
+
|
|
250
|
+
return pth
|
|
251
|
+
} catch (error) {
|
|
252
|
+
if (error.code === 'EPERM') {
|
|
253
|
+
throw error
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (error.code === 'ENOENT') {
|
|
257
|
+
if (path.dirname(pth) === pth) {
|
|
258
|
+
throw new Error(`operation not permitted, mkdir '${pth}'`)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (error.message.includes('null bytes')) {
|
|
262
|
+
throw error
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
await make(path.dirname(pth))
|
|
266
|
+
|
|
267
|
+
return make(pth)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
try {
|
|
271
|
+
const stats = await fs.promises.stat(pth)
|
|
272
|
+
if (!stats.isDirectory()) {
|
|
273
|
+
throw new Error('The path is not a directory')
|
|
274
|
+
}
|
|
275
|
+
} catch (_) {
|
|
276
|
+
throw error
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return pth
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return make(path.resolve(input))
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Get the command that triggered this postinstall script being run. If there is
|
|
288
|
+
* an error while attempting to get this value then the string constant
|
|
289
|
+
* 'ERROR_WHILE_FINDING_POSTINSTALL_TRIGGER' is returned.
|
|
290
|
+
* This information is just necessary for telemetry.
|
|
291
|
+
* This is passed to `prisma generate` as a string like `--postinstall value`.
|
|
292
|
+
*/
|
|
293
|
+
function getPostInstallTrigger() {
|
|
294
|
+
/*
|
|
295
|
+
npm_config_argv` is not officially documented so here are our research notes
|
|
296
|
+
|
|
297
|
+
`npm_config_argv` is available to the postinstall script when the containing package has been installed by npm into some project.
|
|
298
|
+
|
|
299
|
+
An example of its value:
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
npm_config_argv: '{"remain":["../test"],"cooked":["add","../test"],"original":["add","../test"]}',
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
We are interesting in the data contained in the "original" field.
|
|
306
|
+
|
|
307
|
+
Trivia/Note: `npm_config_argv` is not available when running e.g. `npm install` on the containing package itself (e.g. when working on it)
|
|
308
|
+
|
|
309
|
+
Yarn mimics this data and environment variable. Here is an example following `yarn add` for the same package:
|
|
310
|
+
|
|
311
|
+
```
|
|
312
|
+
npm_config_argv: '{"remain":[],"cooked":["add"],"original":["add","../test"]}'
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Other package managers like `pnpm` have not been tested.
|
|
316
|
+
*/
|
|
317
|
+
|
|
318
|
+
const maybe_npm_config_argv_string = process.env.npm_config_argv
|
|
319
|
+
|
|
320
|
+
if (maybe_npm_config_argv_string === undefined) {
|
|
321
|
+
return UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
let npm_config_argv
|
|
325
|
+
try {
|
|
326
|
+
npm_config_argv = JSON.parse(maybe_npm_config_argv_string)
|
|
327
|
+
} catch (e) {
|
|
328
|
+
return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR}: ${maybe_npm_config_argv_string}`
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (typeof npm_config_argv !== 'object' || npm_config_argv === null) {
|
|
332
|
+
return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR}: ${maybe_npm_config_argv_string}`
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const npm_config_argv_original_arr = npm_config_argv.original
|
|
336
|
+
|
|
337
|
+
if (!Array.isArray(npm_config_argv_original_arr)) {
|
|
338
|
+
return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR}: ${maybe_npm_config_argv_string}`
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const npm_config_argv_original = npm_config_argv_original_arr.filter((arg) => arg !== '').join(' ')
|
|
342
|
+
|
|
343
|
+
const command =
|
|
344
|
+
npm_config_argv_original === ''
|
|
345
|
+
? getPackageManagerName()
|
|
346
|
+
: [getPackageManagerName(), npm_config_argv_original].join(' ')
|
|
347
|
+
|
|
348
|
+
return command
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Wrap double quotes around the given string.
|
|
353
|
+
*/
|
|
354
|
+
function doubleQuote(x) {
|
|
355
|
+
return `"${x}"`
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Get the package manager name currently being used. If parsing fails, then the following pattern is returned:
|
|
360
|
+
* UNKNOWN_NPM_CONFIG_USER_AGENT(<string received>).
|
|
361
|
+
*/
|
|
362
|
+
function getPackageManagerName() {
|
|
363
|
+
const userAgent = process.env.npm_config_user_agent
|
|
364
|
+
if (!userAgent) return 'MISSING_NPM_CONFIG_USER_AGENT'
|
|
365
|
+
|
|
366
|
+
const name = parsePackageManagerName(userAgent)
|
|
367
|
+
if (!name) return `UNKNOWN_NPM_CONFIG_USER_AGENT(${userAgent})`
|
|
368
|
+
|
|
369
|
+
return name
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Parse package manager name from useragent. If parsing fails, `null` is returned.
|
|
374
|
+
*/
|
|
375
|
+
function parsePackageManagerName(userAgent) {
|
|
376
|
+
let packageManager = null
|
|
377
|
+
|
|
378
|
+
// example: 'yarn/1.22.4 npm/? node/v13.11.0 darwin x64'
|
|
379
|
+
// References:
|
|
380
|
+
// - https://pnpm.io/only-allow-pnpm
|
|
381
|
+
// - https://github.com/cameronhunter/npm-config-user-agent-parser
|
|
382
|
+
if (userAgent) {
|
|
383
|
+
const matchResult = userAgent.match(/^([^/]+)\/.+/)
|
|
384
|
+
if (matchResult) {
|
|
385
|
+
packageManager = matchResult[1].trim()
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return packageManager
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// prettier-ignore
|
|
393
|
+
const UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING'
|
|
394
|
+
// prettier-ignore
|
|
395
|
+
const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR'
|
|
396
|
+
// prettier-ignore
|
|
397
|
+
const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR'
|
|
398
|
+
|
|
399
|
+
// expose for testing
|
|
400
|
+
|
|
401
|
+
exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING = UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING
|
|
402
|
+
exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR = UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR
|
|
403
|
+
exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR = UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR
|
|
404
|
+
exports.getPostInstallTrigger = getPostInstallTrigger
|