initial commit
This commit is contained in:
commit
b25eb51ff0
280 changed files with 178550 additions and 0 deletions
176
database-service/node_modules/prisma/prisma-client/scripts/colors.js
generated
vendored
Normal file
176
database-service/node_modules/prisma/prisma-client/scripts/colors.js
generated
vendored
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
'use strict'
|
||||
|
||||
const isObject = (val) => val !== null && typeof val === 'object' && !Array.isArray(val)
|
||||
|
||||
// this is a modified version of https://github.com/chalk/ansi-regex (MIT License)
|
||||
const ANSI_REGEX =
|
||||
/* eslint-disable-next-line no-control-regex */
|
||||
/[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g
|
||||
|
||||
const create = () => {
|
||||
const colors = { enabled: true, visible: true, styles: {}, keys: {} }
|
||||
|
||||
if ('FORCE_COLOR' in process.env) {
|
||||
colors.enabled = process.env.FORCE_COLOR !== '0'
|
||||
}
|
||||
|
||||
const ansi = (style) => {
|
||||
let open = (style.open = `\u001b[${style.codes[0]}m`)
|
||||
let close = (style.close = `\u001b[${style.codes[1]}m`)
|
||||
let regex = (style.regex = new RegExp(`\\u001b\\[${style.codes[1]}m`, 'g'))
|
||||
style.wrap = (input, newline) => {
|
||||
if (input.includes(close)) input = input.replace(regex, close + open)
|
||||
let output = open + input + close
|
||||
// see https://github.com/chalk/chalk/pull/92, thanks to the
|
||||
// chalk contributors for this fix. However, we've confirmed that
|
||||
// this issue is also present in Windows terminals
|
||||
return newline ? output.replace(/\r*\n/g, `${close}$&${open}`) : output
|
||||
}
|
||||
return style
|
||||
}
|
||||
|
||||
const wrap = (style, input, newline) => {
|
||||
return typeof style === 'function' ? style(input) : style.wrap(input, newline)
|
||||
}
|
||||
|
||||
const style = (input, stack) => {
|
||||
if (input === '' || input == null) return ''
|
||||
if (colors.enabled === false) return input
|
||||
if (colors.visible === false) return ''
|
||||
let str = '' + input
|
||||
let nl = str.includes('\n')
|
||||
let n = stack.length
|
||||
if (n > 0 && stack.includes('unstyle')) {
|
||||
stack = [...new Set(['unstyle', ...stack])].reverse()
|
||||
}
|
||||
while (n-- > 0) str = wrap(colors.styles[stack[n]], str, nl)
|
||||
return str
|
||||
}
|
||||
|
||||
const define = (name, codes, type) => {
|
||||
colors.styles[name] = ansi({ name, codes })
|
||||
let keys = colors.keys[type] || (colors.keys[type] = [])
|
||||
keys.push(name)
|
||||
|
||||
Reflect.defineProperty(colors, name, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
set(value) {
|
||||
colors.alias(name, value)
|
||||
},
|
||||
get() {
|
||||
let color = (input) => style(input, color.stack)
|
||||
Reflect.setPrototypeOf(color, colors)
|
||||
color.stack = this.stack ? this.stack.concat(name) : [name]
|
||||
return color
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
define('reset', [0, 0], 'modifier')
|
||||
define('bold', [1, 22], 'modifier')
|
||||
define('dim', [2, 22], 'modifier')
|
||||
define('italic', [3, 23], 'modifier')
|
||||
define('underline', [4, 24], 'modifier')
|
||||
define('inverse', [7, 27], 'modifier')
|
||||
define('hidden', [8, 28], 'modifier')
|
||||
define('strikethrough', [9, 29], 'modifier')
|
||||
|
||||
define('black', [30, 39], 'color')
|
||||
define('red', [31, 39], 'color')
|
||||
define('green', [32, 39], 'color')
|
||||
define('yellow', [33, 39], 'color')
|
||||
define('blue', [34, 39], 'color')
|
||||
define('magenta', [35, 39], 'color')
|
||||
define('cyan', [36, 39], 'color')
|
||||
define('white', [37, 39], 'color')
|
||||
define('gray', [90, 39], 'color')
|
||||
define('grey', [90, 39], 'color')
|
||||
|
||||
define('bgBlack', [40, 49], 'bg')
|
||||
define('bgRed', [41, 49], 'bg')
|
||||
define('bgGreen', [42, 49], 'bg')
|
||||
define('bgYellow', [43, 49], 'bg')
|
||||
define('bgBlue', [44, 49], 'bg')
|
||||
define('bgMagenta', [45, 49], 'bg')
|
||||
define('bgCyan', [46, 49], 'bg')
|
||||
define('bgWhite', [47, 49], 'bg')
|
||||
|
||||
define('blackBright', [90, 39], 'bright')
|
||||
define('redBright', [91, 39], 'bright')
|
||||
define('greenBright', [92, 39], 'bright')
|
||||
define('yellowBright', [93, 39], 'bright')
|
||||
define('blueBright', [94, 39], 'bright')
|
||||
define('magentaBright', [95, 39], 'bright')
|
||||
define('cyanBright', [96, 39], 'bright')
|
||||
define('whiteBright', [97, 39], 'bright')
|
||||
|
||||
define('bgBlackBright', [100, 49], 'bgBright')
|
||||
define('bgRedBright', [101, 49], 'bgBright')
|
||||
define('bgGreenBright', [102, 49], 'bgBright')
|
||||
define('bgYellowBright', [103, 49], 'bgBright')
|
||||
define('bgBlueBright', [104, 49], 'bgBright')
|
||||
define('bgMagentaBright', [105, 49], 'bgBright')
|
||||
define('bgCyanBright', [106, 49], 'bgBright')
|
||||
define('bgWhiteBright', [107, 49], 'bgBright')
|
||||
|
||||
colors.ansiRegex = ANSI_REGEX
|
||||
colors.hasColor = colors.hasAnsi = (str) => {
|
||||
colors.ansiRegex.lastIndex = 0
|
||||
return typeof str === 'string' && str !== '' && colors.ansiRegex.test(str)
|
||||
}
|
||||
|
||||
colors.alias = (name, color) => {
|
||||
let fn = typeof color === 'string' ? colors[color] : color
|
||||
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('Expected alias to be the name of an existing color (string) or a function')
|
||||
}
|
||||
|
||||
if (!fn.stack) {
|
||||
Reflect.defineProperty(fn, 'name', { value: name })
|
||||
colors.styles[name] = fn
|
||||
fn.stack = [name]
|
||||
}
|
||||
|
||||
Reflect.defineProperty(colors, name, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
set(value) {
|
||||
colors.alias(name, value)
|
||||
},
|
||||
get() {
|
||||
let color = (input) => style(input, color.stack)
|
||||
Reflect.setPrototypeOf(color, colors)
|
||||
color.stack = this.stack ? this.stack.concat(fn.stack) : fn.stack
|
||||
return color
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
colors.theme = (custom) => {
|
||||
if (!isObject(custom)) throw new TypeError('Expected theme to be an object')
|
||||
for (let name of Object.keys(custom)) {
|
||||
colors.alias(name, custom[name])
|
||||
}
|
||||
return colors
|
||||
}
|
||||
|
||||
colors.alias('unstyle', (str) => {
|
||||
if (typeof str === 'string' && str !== '') {
|
||||
colors.ansiRegex.lastIndex = 0
|
||||
return str.replace(colors.ansiRegex, '')
|
||||
}
|
||||
return ''
|
||||
})
|
||||
|
||||
colors.alias('noop', (str) => str)
|
||||
colors.none = colors.clear = colors.noop
|
||||
|
||||
colors.stripColor = colors.unstyle
|
||||
colors.define = define
|
||||
return colors
|
||||
}
|
||||
|
||||
module.exports = create()
|
||||
module.exports.create = create
|
||||
9
database-service/node_modules/prisma/prisma-client/scripts/default-deno-edge.ts
generated
vendored
Normal file
9
database-service/node_modules/prisma/prisma-client/scripts/default-deno-edge.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class PrismaClient {
|
||||
constructor() {
|
||||
throw new Error(
|
||||
'@prisma/client/deno/edge did not initialize yet. Please run "prisma generate" and try to import it again.',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export { PrismaClient }
|
||||
110
database-service/node_modules/prisma/prisma-client/scripts/default-index.d.ts
generated
vendored
Normal file
110
database-service/node_modules/prisma/prisma-client/scripts/default-index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
|
||||
import * as runtime from '@prisma/client/runtime/library'
|
||||
|
||||
/**
|
||||
* ## Prisma Client ʲˢ
|
||||
*
|
||||
* Type-safe database client for TypeScript & Node.js
|
||||
* @example
|
||||
* ```
|
||||
* const prisma = new Prisma()
|
||||
* // Fetch zero or more Users
|
||||
* const users = await prisma.user.findMany()
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Read more in our [docs](https://www.prisma.io/docs/concepts/components/prisma-client).
|
||||
*/
|
||||
export declare const PrismaClient: any
|
||||
|
||||
/**
|
||||
* ## Prisma Client ʲˢ
|
||||
*
|
||||
* Type-safe database client for TypeScript & Node.js
|
||||
* @example
|
||||
* ```
|
||||
* const prisma = new Prisma()
|
||||
* // Fetch zero or more Users
|
||||
* const users = await prisma.user.findMany()
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Read more in our [docs](https://www.prisma.io/docs/concepts/components/prisma-client).
|
||||
*/
|
||||
export declare type PrismaClient = any
|
||||
|
||||
export declare class PrismaClientExtends<
|
||||
ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs,
|
||||
> {
|
||||
$extends: { extArgs: ExtArgs } & (<
|
||||
R extends runtime.Types.Extensions.UserArgs['result'] = {},
|
||||
M extends runtime.Types.Extensions.UserArgs['model'] = {},
|
||||
Q extends runtime.Types.Extensions.UserArgs['query'] = {},
|
||||
C extends runtime.Types.Extensions.UserArgs['client'] = {},
|
||||
Args extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.InternalArgs<R, M, {}, C>,
|
||||
>(
|
||||
args:
|
||||
| ((client: PrismaClientExtends<ExtArgs>) => { $extends: { extArgs: Args } })
|
||||
| { name?: string }
|
||||
| { result?: R & runtime.Types.Extensions.UserArgs['result'] }
|
||||
| { model?: M & runtime.Types.Extensions.UserArgs['model'] }
|
||||
| { query?: Q & runtime.Types.Extensions.UserArgs['query'] }
|
||||
| { client?: C & runtime.Types.Extensions.UserArgs['client'] },
|
||||
) => PrismaClientExtends<Args & ExtArgs> & Args['client'])
|
||||
|
||||
$transaction<R>(
|
||||
fn: (prisma: Omit<this, runtime.ITXClientDenyList>) => Promise<R>,
|
||||
options?: { maxWait?: number; timeout?: number; isolationLevel?: string },
|
||||
): Promise<R>
|
||||
$transaction<P extends Prisma.PrismaPromise<any>[]>(
|
||||
arg: [...P],
|
||||
options?: { isolationLevel?: string },
|
||||
): Promise<runtime.Types.Utils.UnwrapTuple<P>>
|
||||
}
|
||||
|
||||
export declare const dmmf: any
|
||||
export declare type dmmf = any
|
||||
|
||||
/**
|
||||
* Get the type of the value, that the Promise holds.
|
||||
*/
|
||||
export declare type PromiseType<T extends PromiseLike<any>> = T extends PromiseLike<infer U> ? U : T
|
||||
|
||||
/**
|
||||
* Get the return type of a function which returns a Promise.
|
||||
*/
|
||||
export declare type PromiseReturnType<T extends (...args: any) => Promise<any>> = PromiseType<ReturnType<T>>
|
||||
|
||||
export namespace Prisma {
|
||||
export type TransactionClient = any
|
||||
|
||||
export function defineExtension<
|
||||
R extends runtime.Types.Extensions.UserArgs['result'] = {},
|
||||
M extends runtime.Types.Extensions.UserArgs['model'] = {},
|
||||
Q extends runtime.Types.Extensions.UserArgs['query'] = {},
|
||||
C extends runtime.Types.Extensions.UserArgs['client'] = {},
|
||||
Args extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.InternalArgs<R, M, {}, C>,
|
||||
>(
|
||||
args:
|
||||
| ((client: PrismaClientExtends) => { $extends: { extArgs: Args } })
|
||||
| { name?: string }
|
||||
| { result?: R & runtime.Types.Extensions.UserArgs['result'] }
|
||||
| { model?: M & runtime.Types.Extensions.UserArgs['model'] }
|
||||
| { query?: Q & runtime.Types.Extensions.UserArgs['query'] }
|
||||
| { client?: C & runtime.Types.Extensions.UserArgs['client'] },
|
||||
): (client: any) => PrismaClientExtends<Args>
|
||||
|
||||
export type Extension = runtime.Types.Extensions.UserArgs
|
||||
export import getExtensionContext = runtime.Extensions.getExtensionContext
|
||||
export import Args = runtime.Types.Public.Args
|
||||
export import Payload = runtime.Types.Public.Payload
|
||||
export import Result = runtime.Types.Public.Result
|
||||
export import Exact = runtime.Types.Public.Exact
|
||||
export import PrismaPromise = runtime.Types.Public.PrismaPromise
|
||||
|
||||
export const prismaVersion: {
|
||||
client: string
|
||||
engine: string
|
||||
}
|
||||
}
|
||||
65
database-service/node_modules/prisma/prisma-client/scripts/default-index.js
generated
vendored
Normal file
65
database-service/node_modules/prisma/prisma-client/scripts/default-index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/scripts/default-index.ts
|
||||
var default_index_exports = {};
|
||||
__export(default_index_exports, {
|
||||
Prisma: () => Prisma,
|
||||
PrismaClient: () => PrismaClient,
|
||||
default: () => default_index_default
|
||||
});
|
||||
module.exports = __toCommonJS(default_index_exports);
|
||||
|
||||
// ../../node_modules/.pnpm/@prisma+engines-version@6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959/node_modules/@prisma/engines-version/package.json
|
||||
var prisma = {
|
||||
enginesVersion: "11f085a2012c0f4778414c8db2651556ee0ef959"
|
||||
};
|
||||
|
||||
// package.json
|
||||
var version = "6.1.0";
|
||||
|
||||
// src/runtime/utils/clientVersion.ts
|
||||
var clientVersion = version;
|
||||
|
||||
// src/scripts/default-index.ts
|
||||
var PrismaClient = class {
|
||||
constructor() {
|
||||
throw new Error('@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.');
|
||||
}
|
||||
};
|
||||
function defineExtension(ext) {
|
||||
if (typeof ext === "function") {
|
||||
return ext;
|
||||
}
|
||||
return (client) => client.$extends(ext);
|
||||
}
|
||||
function getExtensionContext(that) {
|
||||
return that;
|
||||
}
|
||||
var Prisma = {
|
||||
defineExtension,
|
||||
getExtensionContext,
|
||||
prismaVersion: { client: clientVersion, engine: prisma.enginesVersion }
|
||||
};
|
||||
var default_index_default = { Prisma };
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
Prisma,
|
||||
PrismaClient
|
||||
});
|
||||
5
database-service/node_modules/prisma/prisma-client/scripts/postinstall.d.ts
generated
vendored
Normal file
5
database-service/node_modules/prisma/prisma-client/scripts/postinstall.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export function getPostInstallTrigger(): string
|
||||
export const UNABLE_TO_FIND_POSTINSTALL_TRIGGER__EMPTY_STRING
|
||||
export const UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING
|
||||
export const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR
|
||||
export const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR
|
||||
410
database-service/node_modules/prisma/prisma-client/scripts/postinstall.js
generated
vendored
Normal file
410
database-service/node_modules/prisma/prisma-client/scripts/postinstall.js
generated
vendored
Normal file
|
|
@ -0,0 +1,410 @@
|
|||
// @ts-check
|
||||
const childProcess = require('child_process')
|
||||
const { promisify } = require('util')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const c = require('./colors')
|
||||
|
||||
const exec = promisify(childProcess.exec)
|
||||
|
||||
function debug(message, ...optionalParams) {
|
||||
if (process.env.DEBUG && process.env.DEBUG === 'prisma:postinstall') {
|
||||
console.log(message, ...optionalParams)
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds `package.json` to the end of a path if it doesn't already exist'
|
||||
* @param {string} pth
|
||||
*/
|
||||
function addPackageJSON(pth) {
|
||||
if (pth.endsWith('package.json')) return pth
|
||||
return path.join(pth, 'package.json')
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up for a `package.json` which is not `@prisma/cli` or `prisma` and returns the directory of the package
|
||||
* @param {string | null} startPath - Path to Start At
|
||||
* @param {number} limit - Find Up limit
|
||||
* @returns {string | null}
|
||||
*/
|
||||
function findPackageRoot(startPath, limit = 10) {
|
||||
if (!startPath || !fs.existsSync(startPath)) return null
|
||||
let currentPath = startPath
|
||||
// Limit traversal
|
||||
for (let i = 0; i < limit; i++) {
|
||||
const pkgPath = addPackageJSON(currentPath)
|
||||
if (fs.existsSync(pkgPath)) {
|
||||
try {
|
||||
const pkg = require(pkgPath)
|
||||
if (pkg.name && !['@prisma/cli', 'prisma'].includes(pkg.name)) {
|
||||
return pkgPath.replace('package.json', '')
|
||||
}
|
||||
} catch {} // eslint-disable-line no-empty
|
||||
}
|
||||
currentPath = path.join(currentPath, '../')
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* The `postinstall` hook of client sets up the ground and env vars for the `prisma generate` command,
|
||||
* and runs it, showing a warning if the schema is not found.
|
||||
* - initializes the ./node_modules/.prisma/client folder with the default index(-browser).js/index.d.ts,
|
||||
* which define a `PrismaClient` class stub that throws an error if instantiated before the `prisma generate`
|
||||
* command is successfully executed.
|
||||
* - sets the path of the root of the project (TODO: to verify) to the `process.env.PRISMA_GENERATE_IN_POSTINSTALL`
|
||||
* variable, or `'true'` if the project root cannot be found.
|
||||
* - runs `prisma generate`, passing through additional information about the command that triggered the generation,
|
||||
* which is useful for debugging/telemetry. It tries to use the local `prisma` package if it is installed, otherwise it
|
||||
* falls back to the global `prisma` package. If neither options are available, it warns the user to install `prisma` first.
|
||||
*/
|
||||
async function main() {
|
||||
if (process.env.INIT_CWD) {
|
||||
process.chdir(process.env.INIT_CWD) // necessary, because npm chooses __dirname as process.cwd()
|
||||
// in the postinstall hook
|
||||
}
|
||||
|
||||
await createDefaultGeneratedThrowFiles()
|
||||
|
||||
// TODO: consider using the `which` package
|
||||
const localPath = getLocalPackagePath()
|
||||
|
||||
// Only execute if !localpath
|
||||
const installedGlobally = localPath ? undefined : await isInstalledGlobally()
|
||||
|
||||
// this is needed, so we can find the correct schemas in yarn workspace projects
|
||||
const root = findPackageRoot(localPath)
|
||||
|
||||
process.env.PRISMA_GENERATE_IN_POSTINSTALL = root ? root : 'true'
|
||||
|
||||
debug({
|
||||
localPath,
|
||||
installedGlobally,
|
||||
init_cwd: process.env.INIT_CWD,
|
||||
PRISMA_GENERATE_IN_POSTINSTALL: process.env.PRISMA_GENERATE_IN_POSTINSTALL,
|
||||
})
|
||||
try {
|
||||
if (localPath) {
|
||||
await run('node', [localPath, 'generate', '--postinstall', doubleQuote(getPostInstallTrigger())])
|
||||
return
|
||||
}
|
||||
if (installedGlobally) {
|
||||
await run('prisma', ['generate', '--postinstall', doubleQuote(getPostInstallTrigger())])
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
// if exit code = 1 do not print
|
||||
if (e && e !== 1) {
|
||||
console.error(e)
|
||||
}
|
||||
debug(e)
|
||||
}
|
||||
|
||||
if (!localPath && !installedGlobally) {
|
||||
console.error(
|
||||
`${c.yellow(
|
||||
'warning',
|
||||
)} In order to use "@prisma/client", please install Prisma CLI. You can install it with "npm add -D prisma".`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function getLocalPackagePath() {
|
||||
try {
|
||||
const packagePath = require.resolve('prisma/package.json')
|
||||
if (packagePath) {
|
||||
return require.resolve('prisma')
|
||||
}
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
// TODO: consider removing this
|
||||
try {
|
||||
const packagePath = require.resolve('@prisma/cli/package.json')
|
||||
if (packagePath) {
|
||||
return require.resolve('@prisma/cli')
|
||||
}
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
async function isInstalledGlobally() {
|
||||
try {
|
||||
const result = await exec('prisma -v')
|
||||
if (result.stdout.includes('@prisma/client')) {
|
||||
return true
|
||||
} else {
|
||||
console.error(`${c.yellow('warning')} You still have the ${c.bold('prisma')} cli (Prisma 1) installed globally.
|
||||
Please uninstall it with either ${c.green('npm remove -g prisma')} or ${c.green('yarn global remove prisma')}.`)
|
||||
}
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (!process.env.PRISMA_SKIP_POSTINSTALL_GENERATE) {
|
||||
main()
|
||||
.catch((e) => {
|
||||
if (e.stderr) {
|
||||
if (e.stderr.includes(`Can't find schema.prisma`)) {
|
||||
console.error(
|
||||
`${c.yellow('warning')} @prisma/client needs a ${c.bold('schema.prisma')} to function, but couldn't find it.
|
||||
Please either create one manually or use ${c.bold('prisma init')}.
|
||||
Once you created it, run ${c.bold('prisma generate')}.
|
||||
To keep Prisma related things separate, we recommend creating it in a subfolder called ${c.underline(
|
||||
'./prisma',
|
||||
)} like so: ${c.underline('./prisma/schema.prisma')}\n`,
|
||||
)
|
||||
} else {
|
||||
console.error(e.stderr)
|
||||
}
|
||||
} else {
|
||||
console.error(e)
|
||||
}
|
||||
process.exit(0)
|
||||
})
|
||||
.finally(() => {
|
||||
debug(`postinstall trigger: ${getPostInstallTrigger()}`)
|
||||
})
|
||||
}
|
||||
|
||||
function run(cmd, params, cwd = process.cwd()) {
|
||||
const child = childProcess.spawn(cmd, params, {
|
||||
stdio: ['pipe', 'inherit', 'inherit'],
|
||||
cwd,
|
||||
})
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
child.on('close', () => {
|
||||
resolve(undefined)
|
||||
})
|
||||
child.on('exit', (code) => {
|
||||
if (code === 0) {
|
||||
resolve(undefined)
|
||||
} else {
|
||||
reject(code)
|
||||
}
|
||||
})
|
||||
child.on('error', () => {
|
||||
reject()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies our default "throw" files into the default generation folder. These
|
||||
* files are dummy and informative because they just throw an error to let the
|
||||
* user know that they have forgotten to run `prisma generate` or that they
|
||||
* don't have a a schema file yet. We only add these files at the default
|
||||
* location `node_modules/.prisma/client`.
|
||||
*/
|
||||
async function createDefaultGeneratedThrowFiles() {
|
||||
try {
|
||||
const dotPrismaClientDir = path.join(__dirname, '../../../.prisma/client')
|
||||
const denoPrismaClientDir = path.join(__dirname, '../../../.prisma/client/deno')
|
||||
|
||||
await makeDir(dotPrismaClientDir)
|
||||
await makeDir(denoPrismaClientDir)
|
||||
|
||||
const defaultFileConfig = {
|
||||
js: path.join(__dirname, 'default-index.js'),
|
||||
ts: path.join(__dirname, 'default-index.d.ts'),
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Record<string, { js?: string; ts?: string } | undefined>}
|
||||
*/
|
||||
const defaultFiles = {
|
||||
index: defaultFileConfig,
|
||||
edge: defaultFileConfig,
|
||||
default: defaultFileConfig,
|
||||
wasm: defaultFileConfig,
|
||||
'index-browser': {
|
||||
js: path.join(__dirname, 'default-index.js'),
|
||||
ts: undefined,
|
||||
},
|
||||
'deno/edge': {
|
||||
js: undefined,
|
||||
ts: path.join(__dirname, 'default-deno-edge.ts'),
|
||||
},
|
||||
}
|
||||
|
||||
for (const file of Object.keys(defaultFiles)) {
|
||||
const { js, ts } = defaultFiles[file] ?? {}
|
||||
const dotPrismaJsFilePath = path.join(dotPrismaClientDir, `${file}.js`)
|
||||
const dotPrismaTsFilePath = path.join(dotPrismaClientDir, `${file}.d.ts`)
|
||||
|
||||
if (js && !fs.existsSync(dotPrismaJsFilePath) && fs.existsSync(js)) {
|
||||
await fs.promises.copyFile(js, dotPrismaJsFilePath)
|
||||
}
|
||||
|
||||
if (ts && !fs.existsSync(dotPrismaTsFilePath) && fs.existsSync(ts)) {
|
||||
await fs.promises.copyFile(ts, dotPrismaTsFilePath)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: can this be replaced some utility eg. mkdir
|
||||
function makeDir(input) {
|
||||
const make = async (pth) => {
|
||||
try {
|
||||
await fs.promises.mkdir(pth)
|
||||
|
||||
return pth
|
||||
} catch (error) {
|
||||
if (error.code === 'EPERM') {
|
||||
throw error
|
||||
}
|
||||
|
||||
if (error.code === 'ENOENT') {
|
||||
if (path.dirname(pth) === pth) {
|
||||
throw new Error(`operation not permitted, mkdir '${pth}'`)
|
||||
}
|
||||
|
||||
if (error.message.includes('null bytes')) {
|
||||
throw error
|
||||
}
|
||||
|
||||
await make(path.dirname(pth))
|
||||
|
||||
return make(pth)
|
||||
}
|
||||
|
||||
try {
|
||||
const stats = await fs.promises.stat(pth)
|
||||
if (!stats.isDirectory()) {
|
||||
throw new Error('The path is not a directory')
|
||||
}
|
||||
} catch (_) {
|
||||
throw error
|
||||
}
|
||||
|
||||
return pth
|
||||
}
|
||||
}
|
||||
|
||||
return make(path.resolve(input))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command that triggered this postinstall script being run. If there is
|
||||
* an error while attempting to get this value then the string constant
|
||||
* 'ERROR_WHILE_FINDING_POSTINSTALL_TRIGGER' is returned.
|
||||
* This information is just necessary for telemetry.
|
||||
* This is passed to `prisma generate` as a string like `--postinstall value`.
|
||||
*/
|
||||
function getPostInstallTrigger() {
|
||||
/*
|
||||
npm_config_argv` is not officially documented so here are our research notes
|
||||
|
||||
`npm_config_argv` is available to the postinstall script when the containing package has been installed by npm into some project.
|
||||
|
||||
An example of its value:
|
||||
|
||||
```
|
||||
npm_config_argv: '{"remain":["../test"],"cooked":["add","../test"],"original":["add","../test"]}',
|
||||
```
|
||||
|
||||
We are interesting in the data contained in the "original" field.
|
||||
|
||||
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)
|
||||
|
||||
Yarn mimics this data and environment variable. Here is an example following `yarn add` for the same package:
|
||||
|
||||
```
|
||||
npm_config_argv: '{"remain":[],"cooked":["add"],"original":["add","../test"]}'
|
||||
```
|
||||
|
||||
Other package managers like `pnpm` have not been tested.
|
||||
*/
|
||||
|
||||
const maybe_npm_config_argv_string = process.env.npm_config_argv
|
||||
|
||||
if (maybe_npm_config_argv_string === undefined) {
|
||||
return UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING
|
||||
}
|
||||
|
||||
let npm_config_argv
|
||||
try {
|
||||
npm_config_argv = JSON.parse(maybe_npm_config_argv_string)
|
||||
} catch (e) {
|
||||
return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR}: ${maybe_npm_config_argv_string}`
|
||||
}
|
||||
|
||||
if (typeof npm_config_argv !== 'object' || npm_config_argv === null) {
|
||||
return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR}: ${maybe_npm_config_argv_string}`
|
||||
}
|
||||
|
||||
const npm_config_argv_original_arr = npm_config_argv.original
|
||||
|
||||
if (!Array.isArray(npm_config_argv_original_arr)) {
|
||||
return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR}: ${maybe_npm_config_argv_string}`
|
||||
}
|
||||
|
||||
const npm_config_argv_original = npm_config_argv_original_arr.filter((arg) => arg !== '').join(' ')
|
||||
|
||||
const command =
|
||||
npm_config_argv_original === ''
|
||||
? getPackageManagerName()
|
||||
: [getPackageManagerName(), npm_config_argv_original].join(' ')
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap double quotes around the given string.
|
||||
*/
|
||||
function doubleQuote(x) {
|
||||
return `"${x}"`
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the package manager name currently being used. If parsing fails, then the following pattern is returned:
|
||||
* UNKNOWN_NPM_CONFIG_USER_AGENT(<string received>).
|
||||
*/
|
||||
function getPackageManagerName() {
|
||||
const userAgent = process.env.npm_config_user_agent
|
||||
if (!userAgent) return 'MISSING_NPM_CONFIG_USER_AGENT'
|
||||
|
||||
const name = parsePackageManagerName(userAgent)
|
||||
if (!name) return `UNKNOWN_NPM_CONFIG_USER_AGENT(${userAgent})`
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse package manager name from useragent. If parsing fails, `null` is returned.
|
||||
*/
|
||||
function parsePackageManagerName(userAgent) {
|
||||
let packageManager = null
|
||||
|
||||
// example: 'yarn/1.22.4 npm/? node/v13.11.0 darwin x64'
|
||||
// References:
|
||||
// - https://pnpm.io/only-allow-pnpm
|
||||
// - https://github.com/cameronhunter/npm-config-user-agent-parser
|
||||
if (userAgent) {
|
||||
const matchResult = userAgent.match(/^([^/]+)\/.+/)
|
||||
if (matchResult) {
|
||||
packageManager = matchResult[1].trim()
|
||||
}
|
||||
}
|
||||
|
||||
return packageManager
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
const UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING'
|
||||
// prettier-ignore
|
||||
const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR'
|
||||
// prettier-ignore
|
||||
const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR'
|
||||
|
||||
// expose for testing
|
||||
|
||||
exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING = UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING
|
||||
exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR = UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR
|
||||
exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR = UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR
|
||||
exports.getPostInstallTrigger = getPostInstallTrigger
|
||||
Loading…
Add table
Add a link
Reference in a new issue