@a_team/prisma 2.0.8 → 2.0.10

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.
Files changed (41) hide show
  1. package/dist/client/LICENSE +201 -0
  2. package/dist/client/README.md +27 -0
  3. package/dist/client/default.d.ts +1 -0
  4. package/dist/client/default.js +3 -0
  5. package/dist/client/edge.d.ts +1 -0
  6. package/dist/client/edge.js +4 -0
  7. package/dist/client/extension.d.ts +1 -0
  8. package/dist/client/extension.js +4 -0
  9. package/dist/client/generator-build/index.js +9552 -0
  10. package/dist/client/index-browser.js +3 -0
  11. package/dist/client/index.d.ts +1 -0
  12. package/dist/client/index.js +4 -0
  13. package/dist/client/package.json +264 -0
  14. package/dist/client/react-native.d.ts +1 -0
  15. package/dist/client/react-native.js +3 -0
  16. package/dist/client/runtime/binary.d.ts +1 -0
  17. package/dist/client/runtime/binary.js +210 -0
  18. package/dist/client/runtime/edge-esm.js +31 -0
  19. package/dist/client/runtime/edge.js +31 -0
  20. package/dist/client/runtime/index-browser.d.ts +365 -0
  21. package/dist/client/runtime/index-browser.js +13 -0
  22. package/dist/client/runtime/library.d.ts +3273 -0
  23. package/dist/client/runtime/library.js +143 -0
  24. package/dist/client/runtime/query_engine_bg.mysql.js +2 -0
  25. package/dist/client/runtime/query_engine_bg.mysql.wasm +0 -0
  26. package/dist/client/runtime/query_engine_bg.postgresql.js +2 -0
  27. package/dist/client/runtime/query_engine_bg.postgresql.wasm +0 -0
  28. package/dist/client/runtime/query_engine_bg.sqlite.js +2 -0
  29. package/dist/client/runtime/query_engine_bg.sqlite.wasm +0 -0
  30. package/dist/client/runtime/react-native.d.ts +3273 -0
  31. package/dist/client/runtime/react-native.js +80 -0
  32. package/dist/client/runtime/wasm.js +32 -0
  33. package/dist/client/scripts/colors.js +176 -0
  34. package/dist/client/scripts/default-deno-edge.ts +9 -0
  35. package/dist/client/scripts/default-index.d.ts +110 -0
  36. package/dist/client/scripts/default-index.js +65 -0
  37. package/dist/client/scripts/postinstall.d.ts +5 -0
  38. package/dist/client/scripts/postinstall.js +410 -0
  39. package/dist/client/wasm.d.ts +1 -0
  40. package/dist/client/wasm.js +4 -0
  41. package/package.json +3 -4
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/scripts/default-index.ts
21
+ var default_index_exports = {};
22
+ __export(default_index_exports, {
23
+ Prisma: () => Prisma,
24
+ PrismaClient: () => PrismaClient,
25
+ default: () => default_index_default
26
+ });
27
+ module.exports = __toCommonJS(default_index_exports);
28
+
29
+ // ../../node_modules/.pnpm/@prisma+engines-version@5.17.0-31.393aa359c9ad4a4bb28630fb5613f9c281cde053/node_modules/@prisma/engines-version/package.json
30
+ var prisma = {
31
+ enginesVersion: "393aa359c9ad4a4bb28630fb5613f9c281cde053"
32
+ };
33
+
34
+ // package.json
35
+ var version = "5.17.0";
36
+
37
+ // src/runtime/utils/clientVersion.ts
38
+ var clientVersion = version;
39
+
40
+ // src/scripts/default-index.ts
41
+ var PrismaClient = class {
42
+ constructor() {
43
+ throw new Error('@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.');
44
+ }
45
+ };
46
+ function defineExtension(ext) {
47
+ if (typeof ext === "function") {
48
+ return ext;
49
+ }
50
+ return (client) => client.$extends(ext);
51
+ }
52
+ function getExtensionContext(that) {
53
+ return that;
54
+ }
55
+ var Prisma = {
56
+ defineExtension,
57
+ getExtensionContext,
58
+ prismaVersion: { client: clientVersion, engine: prisma.enginesVersion }
59
+ };
60
+ var default_index_default = { Prisma };
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ Prisma,
64
+ PrismaClient
65
+ });
@@ -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,410 @@
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 | null} 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(undefined)
180
+ })
181
+ child.on('exit', (code) => {
182
+ if (code === 0) {
183
+ resolve(undefined)
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 denoPrismaClientDir = path.join(__dirname, '../../../.prisma/client/deno')
205
+
206
+ await makeDir(dotPrismaClientDir)
207
+ await makeDir(denoPrismaClientDir)
208
+
209
+ const defaultFileConfig = {
210
+ js: path.join(__dirname, 'default-index.js'),
211
+ ts: path.join(__dirname, 'default-index.d.ts'),
212
+ }
213
+
214
+ /**
215
+ * @type {Record<string, { js?: string; ts?: string } | undefined>}
216
+ */
217
+ const defaultFiles = {
218
+ index: defaultFileConfig,
219
+ edge: defaultFileConfig,
220
+ default: defaultFileConfig,
221
+ wasm: defaultFileConfig,
222
+ 'index-browser': {
223
+ js: path.join(__dirname, 'default-index.js'),
224
+ ts: undefined,
225
+ },
226
+ 'deno/edge': {
227
+ js: undefined,
228
+ ts: path.join(__dirname, 'default-deno-edge.ts'),
229
+ },
230
+ }
231
+
232
+ for (const file of Object.keys(defaultFiles)) {
233
+ const { js, ts } = defaultFiles[file] ?? {}
234
+ const dotPrismaJsFilePath = path.join(dotPrismaClientDir, `${file}.js`)
235
+ const dotPrismaTsFilePath = path.join(dotPrismaClientDir, `${file}.d.ts`)
236
+
237
+ if (js && !fs.existsSync(dotPrismaJsFilePath) && fs.existsSync(js)) {
238
+ await fs.promises.copyFile(js, dotPrismaJsFilePath)
239
+ }
240
+
241
+ if (ts && !fs.existsSync(dotPrismaTsFilePath) && fs.existsSync(ts)) {
242
+ await fs.promises.copyFile(ts, dotPrismaTsFilePath)
243
+ }
244
+ }
245
+ } catch (e) {
246
+ console.error(e)
247
+ }
248
+ }
249
+
250
+ // TODO: can this be replaced some utility eg. mkdir
251
+ function makeDir(input) {
252
+ const make = async (pth) => {
253
+ try {
254
+ await fs.promises.mkdir(pth)
255
+
256
+ return pth
257
+ } catch (error) {
258
+ if (error.code === 'EPERM') {
259
+ throw error
260
+ }
261
+
262
+ if (error.code === 'ENOENT') {
263
+ if (path.dirname(pth) === pth) {
264
+ throw new Error(`operation not permitted, mkdir '${pth}'`)
265
+ }
266
+
267
+ if (error.message.includes('null bytes')) {
268
+ throw error
269
+ }
270
+
271
+ await make(path.dirname(pth))
272
+
273
+ return make(pth)
274
+ }
275
+
276
+ try {
277
+ const stats = await fs.promises.stat(pth)
278
+ if (!stats.isDirectory()) {
279
+ throw new Error('The path is not a directory')
280
+ }
281
+ } catch (_) {
282
+ throw error
283
+ }
284
+
285
+ return pth
286
+ }
287
+ }
288
+
289
+ return make(path.resolve(input))
290
+ }
291
+
292
+ /**
293
+ * Get the command that triggered this postinstall script being run. If there is
294
+ * an error while attempting to get this value then the string constant
295
+ * 'ERROR_WHILE_FINDING_POSTINSTALL_TRIGGER' is returned.
296
+ * This information is just necessary for telemetry.
297
+ * This is passed to `prisma generate` as a string like `--postinstall value`.
298
+ */
299
+ function getPostInstallTrigger() {
300
+ /*
301
+ npm_config_argv` is not officially documented so here are our research notes
302
+
303
+ `npm_config_argv` is available to the postinstall script when the containing package has been installed by npm into some project.
304
+
305
+ An example of its value:
306
+
307
+ ```
308
+ npm_config_argv: '{"remain":["../test"],"cooked":["add","../test"],"original":["add","../test"]}',
309
+ ```
310
+
311
+ We are interesting in the data contained in the "original" field.
312
+
313
+ 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)
314
+
315
+ Yarn mimics this data and environment variable. Here is an example following `yarn add` for the same package:
316
+
317
+ ```
318
+ npm_config_argv: '{"remain":[],"cooked":["add"],"original":["add","../test"]}'
319
+ ```
320
+
321
+ Other package managers like `pnpm` have not been tested.
322
+ */
323
+
324
+ const maybe_npm_config_argv_string = process.env.npm_config_argv
325
+
326
+ if (maybe_npm_config_argv_string === undefined) {
327
+ return UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING
328
+ }
329
+
330
+ let npm_config_argv
331
+ try {
332
+ npm_config_argv = JSON.parse(maybe_npm_config_argv_string)
333
+ } catch (e) {
334
+ return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR}: ${maybe_npm_config_argv_string}`
335
+ }
336
+
337
+ if (typeof npm_config_argv !== 'object' || npm_config_argv === null) {
338
+ return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR}: ${maybe_npm_config_argv_string}`
339
+ }
340
+
341
+ const npm_config_argv_original_arr = npm_config_argv.original
342
+
343
+ if (!Array.isArray(npm_config_argv_original_arr)) {
344
+ return `${UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR}: ${maybe_npm_config_argv_string}`
345
+ }
346
+
347
+ const npm_config_argv_original = npm_config_argv_original_arr.filter((arg) => arg !== '').join(' ')
348
+
349
+ const command =
350
+ npm_config_argv_original === ''
351
+ ? getPackageManagerName()
352
+ : [getPackageManagerName(), npm_config_argv_original].join(' ')
353
+
354
+ return command
355
+ }
356
+
357
+ /**
358
+ * Wrap double quotes around the given string.
359
+ */
360
+ function doubleQuote(x) {
361
+ return `"${x}"`
362
+ }
363
+
364
+ /**
365
+ * Get the package manager name currently being used. If parsing fails, then the following pattern is returned:
366
+ * UNKNOWN_NPM_CONFIG_USER_AGENT(<string received>).
367
+ */
368
+ function getPackageManagerName() {
369
+ const userAgent = process.env.npm_config_user_agent
370
+ if (!userAgent) return 'MISSING_NPM_CONFIG_USER_AGENT'
371
+
372
+ const name = parsePackageManagerName(userAgent)
373
+ if (!name) return `UNKNOWN_NPM_CONFIG_USER_AGENT(${userAgent})`
374
+
375
+ return name
376
+ }
377
+
378
+ /**
379
+ * Parse package manager name from useragent. If parsing fails, `null` is returned.
380
+ */
381
+ function parsePackageManagerName(userAgent) {
382
+ let packageManager = null
383
+
384
+ // example: 'yarn/1.22.4 npm/? node/v13.11.0 darwin x64'
385
+ // References:
386
+ // - https://pnpm.io/only-allow-pnpm
387
+ // - https://github.com/cameronhunter/npm-config-user-agent-parser
388
+ if (userAgent) {
389
+ const matchResult = userAgent.match(/^([^/]+)\/.+/)
390
+ if (matchResult) {
391
+ packageManager = matchResult[1].trim()
392
+ }
393
+ }
394
+
395
+ return packageManager
396
+ }
397
+
398
+ // prettier-ignore
399
+ const UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING'
400
+ // prettier-ignore
401
+ const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR'
402
+ // prettier-ignore
403
+ const UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR = 'UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR'
404
+
405
+ // expose for testing
406
+
407
+ exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING = UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING
408
+ exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR = UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_PARSE_ERROR
409
+ exports.UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR = UNABLE_TO_FIND_POSTINSTALL_TRIGGER_JSON_SCHEMA_ERROR
410
+ exports.getPostInstallTrigger = getPostInstallTrigger
@@ -0,0 +1 @@
1
+ export * from '.prisma/client/wasm'
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ // https://github.com/prisma/prisma/pull/12907
3
+ ...require('.prisma/client/wasm'),
4
+ }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@a_team/prisma",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "keywords": [],
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist & npm run generate & tsc",
7
+ "postbuild": "cp -R node_modules/@prisma/client ./dist/",
7
8
  "generate": "npx prisma generate",
8
9
  "format": "npx prisma format"
9
10
  },
@@ -16,9 +17,7 @@
16
17
  "main": "dist/index.js",
17
18
  "types": "dist/index.d.ts",
18
19
  "files": [
19
- "dist/index.js",
20
- "dist/index.d.ts",
21
- "dist/models"
20
+ "dist"
22
21
  ],
23
22
  "dependencies": {
24
23
  "@prisma/client": "^5.17.0"