@prisma/cli 2.20.0 → 3.0.0-alpha.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.
Files changed (183) hide show
  1. package/LICENSE +158 -0
  2. package/README.md +29 -28
  3. package/dist/adapters/config.js +74 -0
  4. package/dist/adapters/local-state.js +98 -0
  5. package/dist/adapters/mock-api.js +57 -0
  6. package/dist/adapters/token-storage.js +43 -0
  7. package/dist/cli.js +9 -0
  8. package/dist/cli2.js +59 -0
  9. package/dist/commands/app/index.js +223 -0
  10. package/dist/commands/auth/index.js +42 -0
  11. package/dist/commands/branch/index.js +51 -0
  12. package/dist/commands/project/index.js +45 -0
  13. package/dist/controllers/app.js +813 -0
  14. package/dist/controllers/auth.js +107 -0
  15. package/dist/controllers/branch.js +73 -0
  16. package/dist/controllers/project.js +214 -0
  17. package/dist/controllers/select-prompt-port.js +12 -0
  18. package/dist/lib/app/bun-project.js +39 -0
  19. package/dist/lib/app/env-vars.js +24 -0
  20. package/dist/lib/app/local-dev.js +149 -0
  21. package/dist/lib/app/preview-build.js +283 -0
  22. package/dist/lib/app/preview-interaction.js +38 -0
  23. package/dist/lib/app/preview-progress.js +139 -0
  24. package/dist/lib/app/preview-provider.js +232 -0
  25. package/dist/lib/auth/auth-ops.js +57 -0
  26. package/dist/lib/auth/client.js +22 -0
  27. package/dist/lib/auth/guard.js +34 -0
  28. package/dist/lib/auth/login.js +117 -0
  29. package/dist/output/patterns.js +93 -0
  30. package/dist/presenters/app.js +405 -0
  31. package/dist/presenters/auth.js +73 -0
  32. package/dist/presenters/branch.js +111 -0
  33. package/dist/presenters/project.js +84 -0
  34. package/dist/shell/command-meta.js +320 -0
  35. package/dist/shell/command-runner.js +33 -0
  36. package/dist/shell/errors.js +66 -0
  37. package/dist/shell/global-flags.js +25 -0
  38. package/dist/shell/help.js +78 -0
  39. package/dist/shell/output.js +54 -0
  40. package/dist/shell/prompt.js +31 -0
  41. package/dist/shell/runtime.js +51 -0
  42. package/dist/shell/ui.js +59 -0
  43. package/dist/use-cases/auth.js +70 -0
  44. package/dist/use-cases/branch.js +95 -0
  45. package/dist/use-cases/create-cli-gateways.js +93 -0
  46. package/dist/use-cases/project.js +75 -0
  47. package/package.json +49 -137
  48. package/build/child.js +0 -4110
  49. package/build/index.js +0 -104447
  50. package/build/public/demo.html +0 -17
  51. package/build/public/demoChunk.js +0 -2
  52. package/build/public/electron-darwin.html +0 -19
  53. package/build/public/electron-linux.html +0 -18
  54. package/build/public/electron-mac.html +0 -18
  55. package/build/public/electron-win.html +0 -17
  56. package/build/public/electron-win32.html +0 -18
  57. package/build/public/electron.html +0 -17
  58. package/build/public/electronBus.js +0 -2
  59. package/build/public/electronChunk.js +0 -2
  60. package/build/public/favicon/apple-touch-icon.png +0 -0
  61. package/build/public/favicon/favicon-16x16.png +0 -0
  62. package/build/public/favicon/favicon-32x32.png +0 -0
  63. package/build/public/favicon/prisma.png +0 -0
  64. package/build/public/fonts/Inter.ttf +0 -0
  65. package/build/public/fonts/RobotoMono.ttf +0 -0
  66. package/build/public/icons/.DS_Store +0 -0
  67. package/build/public/icons/alert.svg +0 -5
  68. package/build/public/icons/array.svg +0 -4
  69. package/build/public/icons/bin.svg +0 -37
  70. package/build/public/icons/boolean.svg +0 -4
  71. package/build/public/icons/check.svg +0 -3
  72. package/build/public/icons/chevron-down.svg +0 -3
  73. package/build/public/icons/code.svg +0 -4
  74. package/build/public/icons/cross.svg +0 -11
  75. package/build/public/icons/data-tool.svg +0 -5
  76. package/build/public/icons/database.svg +0 -4
  77. package/build/public/icons/datetime.svg +0 -4
  78. package/build/public/icons/double-arrow-right.svg +0 -4
  79. package/build/public/icons/download.svg +0 -4
  80. package/build/public/icons/ellipsis.svg +0 -10
  81. package/build/public/icons/enum.svg +0 -6
  82. package/build/public/icons/expand.svg +0 -4
  83. package/build/public/icons/eye.svg +0 -20
  84. package/build/public/icons/filters.svg +0 -5
  85. package/build/public/icons/folder.svg +0 -6
  86. package/build/public/icons/hamburger.svg +0 -4
  87. package/build/public/icons/icon.svg +0 -199
  88. package/build/public/icons/logo.svg +0 -199
  89. package/build/public/icons/logotype.svg +0 -4
  90. package/build/public/icons/number.svg +0 -7
  91. package/build/public/icons/object.svg +0 -5
  92. package/build/public/icons/play.svg +0 -6
  93. package/build/public/icons/plus.svg +0 -4
  94. package/build/public/icons/refresh.svg +0 -4
  95. package/build/public/icons/search.svg +0 -7
  96. package/build/public/icons/settings.svg +0 -8
  97. package/build/public/icons/string.svg +0 -4
  98. package/build/public/icons/tick-indeterminate.svg +0 -3
  99. package/build/public/icons/tick.svg +0 -4
  100. package/build/public/illustrations/.DS_Store +0 -0
  101. package/build/public/illustrations/empty.svg +0 -1
  102. package/build/public/illustrations/read.svg +0 -1
  103. package/build/public/illustrations/searching.svg +0 -1
  104. package/build/public/images/.DS_Store +0 -0
  105. package/build/public/images/icon-1024.png +0 -0
  106. package/build/public/index.html +0 -49
  107. package/build/public/main.31f688a6254e294d9128.css +0 -118
  108. package/build/public/main.31f688a6254e294d9128.css.map +0 -1
  109. package/build/public/main.364c712f32662ff0e43d.css +0 -116
  110. package/build/public/main.364c712f32662ff0e43d.css.map +0 -1
  111. package/build/public/main.42ef3fe7e97347765c91.css +0 -118
  112. package/build/public/main.42ef3fe7e97347765c91.css.map +0 -1
  113. package/build/public/main.503446defafe7aeca2f3.css +0 -116
  114. package/build/public/main.503446defafe7aeca2f3.css.map +0 -1
  115. package/build/public/main.c50a3b5980fe26f78b65.css +0 -118
  116. package/build/public/main.c50a3b5980fe26f78b65.css.map +0 -1
  117. package/build/public/main.cda25e5813776c2af295.css +0 -116
  118. package/build/public/main.cda25e5813776c2af295.css.map +0 -1
  119. package/build/public/main.dbac3b290f78404ff579.css +0 -116
  120. package/build/public/main.dbac3b290f78404ff579.css.map +0 -1
  121. package/build/public/main.f8ce44e122e5e2b8f778.css +0 -118
  122. package/build/public/main.f8ce44e122e5e2b8f778.css.map +0 -1
  123. package/build/public/main.fc9ea7521a4aecce1a77.css +0 -118
  124. package/build/public/main.fc9ea7521a4aecce1a77.css.map +0 -1
  125. package/build/public/main.js +0 -403
  126. package/build/public/main.js.map +0 -1
  127. package/build/public/mainChunk.0a84f3ba4d2ab481e877.css +0 -116
  128. package/build/public/mainChunk.1b327d58afbddc917bce.css +0 -118
  129. package/build/public/mainChunk.2cdf583b2bd51aa67587.css +0 -118
  130. package/build/public/mainChunk.544af00f7e9ffcbe782c.css +0 -118
  131. package/build/public/mainChunk.56f96a13868b2b4a53be.css +0 -118
  132. package/build/public/mainChunk.5cee429bfbf06e7ecb39.css +0 -118
  133. package/build/public/mainChunk.a862474ed4cdb421ffa2.css +0 -118
  134. package/build/public/mainChunk.ada34153c4911b5ac22b.css +0 -118
  135. package/build/public/mainChunk.c16a8d01b2c49b2f2751.css +0 -118
  136. package/build/public/mainChunk.ca4a878d5478b9320be8.css +0 -116
  137. package/build/public/mainChunk.e3adc8758b4395546cef.css +0 -116
  138. package/build/public/mainChunk.f2c59fcbfc455d8b9de5.css +0 -118
  139. package/build/public/mainChunk.js +0 -396
  140. package/build/public/preview.html +0 -16
  141. package/build/public/previewBus.js +0 -2
  142. package/build/public/previewChunk.js +0 -2
  143. package/build/public/projects.html +0 -86
  144. package/build/public/server.html +0 -16
  145. package/build/public/serverBus.js +0 -2
  146. package/build/public/serverChunk.js +0 -2
  147. package/build/public/splash.html +0 -17
  148. package/build/public/studioBundle.828f34b1781061528841.css +0 -118
  149. package/build/public/studioBundle.bfe9138b2e0293fcb7da.css +0 -118
  150. package/build/public/studioBundle.c5b256eede880e502aac.css +0 -118
  151. package/build/public/studioBundle.e43df511c8e2e368900a.css +0 -118
  152. package/build/public/studioBundle.e69382554c2a2942ae32.css +0 -118
  153. package/build/public/studioBundle.ee21aa56a3999a2b380b.css +0 -118
  154. package/build/public/studioBundle.js +0 -396
  155. package/build/public/vercel.html +0 -16
  156. package/build/public/vercelChunk.js +0 -2
  157. package/build/xdg-open +0 -1066
  158. package/install/index.js +0 -5
  159. package/preinstall/index.js +0 -71
  160. package/prisma-client/README.md +0 -27
  161. package/prisma-client/generator-build/.DS_Store +0 -0
  162. package/prisma-client/generator-build/index.js +0 -79697
  163. package/prisma-client/index-browser.js +0 -3
  164. package/prisma-client/index.d.ts +0 -1
  165. package/prisma-client/index.js +0 -11
  166. package/prisma-client/package.json +0 -138
  167. package/prisma-client/runtime/index-browser.d.ts +0 -267
  168. package/prisma-client/runtime/index-browser.js +0 -2273
  169. package/prisma-client/runtime/index.d.ts +0 -1018
  170. package/prisma-client/runtime/index.js +0 -35028
  171. package/prisma-client/scripts/backup-index-browser.js +0 -3
  172. package/prisma-client/scripts/backup-index.d.ts +0 -1
  173. package/prisma-client/scripts/backup-index.js +0 -11
  174. package/prisma-client/scripts/colors.js +0 -180
  175. package/prisma-client/scripts/default-index-browser.js +0 -12
  176. package/prisma-client/scripts/default-index.d.ts +0 -47
  177. package/prisma-client/scripts/default-index.js +0 -12
  178. package/prisma-client/scripts/get-packed-client.js +0 -12
  179. package/prisma-client/scripts/mock-fs.js +0 -14
  180. package/prisma-client/scripts/postinstall.d.ts +0 -5
  181. package/prisma-client/scripts/postinstall.js +0 -398
  182. package/scripts/install-entry.js +0 -8
  183. package/scripts/preinstall-entry.js +0 -9
package/LICENSE ADDED
@@ -0,0 +1,158 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
34
+ available under the License, as indicated by a copyright notice that is included
35
+ in or attached to the work.
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work by
47
+ the copyright owner or by an individual or Legal Entity authorized to submit on
48
+ behalf of the copyright owner. For the purposes of this definition, "submitted"
49
+ means any form of electronic, verbal, or written communication sent to the
50
+ Licensor or its representatives, including but not limited to communication on
51
+ electronic mailing lists, source code control systems, and issue tracking
52
+ systems that are managed by, or on behalf of, the Licensor for the purpose of
53
+ discussing and improving the Work, but excluding communication that is
54
+ conspicuously marked or otherwise designated in writing by the copyright owner
55
+ as "Not a Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
62
+ License, each Contributor hereby grants to You a perpetual, worldwide,
63
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
64
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
65
+ sublicense, and distribute the Work and such Derivative Works in Source or Object
66
+ form.
67
+
68
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
69
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
70
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
71
+ license to make, have made, use, offer to sell, sell, import, and otherwise
72
+ transfer the Work, where such license applies only to those patent claims
73
+ licensable by such Contributor that are necessarily infringed by their
74
+ Contribution(s) alone or by combination of their Contribution(s) with the Work to
75
+ which such Contribution(s) was submitted. If You institute patent litigation
76
+ against any entity (including a cross-claim or counterclaim in a lawsuit)
77
+ alleging that the Work or a Contribution incorporated within the Work
78
+ constitutes direct or contributory patent infringement, then any patent licenses
79
+ granted to You under this License for that Work shall terminate as of the date
80
+ such litigation is filed.
81
+
82
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
83
+ Derivative Works thereof in any medium, with or without modifications, and in
84
+ Source or Object form, provided that You meet the following conditions:
85
+
86
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
87
+ this License; and
88
+
89
+ (b) You must cause any modified files to carry prominent notices stating that You
90
+ changed the files; and
91
+
92
+ (c) You must retain, in the Source form of any Derivative Works that You
93
+ distribute, all copyright, patent, trademark, and attribution notices from the
94
+ Source form of the Work, excluding those notices that do not pertain to any part
95
+ of the Derivative Works; and
96
+
97
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
98
+ any Derivative Works that You distribute must include a readable copy of the
99
+ attribution notices contained within such NOTICE file, excluding those notices
100
+ that do not pertain to any part of the Derivative Works, in at least one of the
101
+ following places: within a NOTICE text file distributed as part of the Derivative
102
+ Works; within the Source form or documentation, if provided along with the
103
+ Derivative Works; or, within a display generated by the Derivative Works, if and
104
+ wherever such third-party notices normally appear. The contents of the NOTICE
105
+ file are for informational purposes only and do not modify the License. You may
106
+ add Your own attribution notices within Derivative Works that You distribute,
107
+ alongside or as an addendum to the NOTICE text from the Work, provided that such
108
+ additional attribution notices cannot be construed as modifying the License.
109
+
110
+ You may add Your own copyright statement to Your modifications and may provide
111
+ additional or different license terms and conditions for use, reproduction, or
112
+ distribution of Your modifications, or for any such Derivative Works as a whole,
113
+ provided Your use, reproduction, and distribution of the Work otherwise complies
114
+ with the conditions stated in this License.
115
+
116
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
117
+ Contribution intentionally submitted for inclusion in the Work by You to the
118
+ Licensor shall be under the terms and conditions of this License, without any
119
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
120
+ supersede or modify the terms of any separate license agreement you may have
121
+ executed with Licensor regarding such Contributions.
122
+
123
+ 6. Trademarks. This License does not grant permission to use the trade names,
124
+ trademarks, service marks, or product names of the Licensor, except as required
125
+ for reasonable and customary use in describing the origin of the Work and
126
+ reproducing the content of the NOTICE file.
127
+
128
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
129
+ writing, Licensor provides the Work (and each Contributor provides its
130
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
131
+ either express or implied, including, without limitation, any warranties or
132
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
133
+ PARTICULAR PURPOSE. You are solely responsible for determining the
134
+ appropriateness of using or redistributing the Work and assume any risks
135
+ associated with Your exercise of permissions under this License.
136
+
137
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
138
+ tort (including negligence), contract, or otherwise, unless required by
139
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
140
+ writing, shall any Contributor be liable to You for damages, including any
141
+ direct, indirect, special, incidental, or consequential damages of any character
142
+ arising as a result of this License or out of the use or inability to use the
143
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
144
+ computer failure or malfunction, or any and all other commercial damages or
145
+ losses), even if such Contributor has been advised of the possibility of such
146
+ damages.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
149
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
150
+ acceptance of support, warranty, indemnity, or other liability obligations and/or
151
+ rights consistent with this License. However, in accepting such obligations, You
152
+ may act only on Your own behalf and on Your sole responsibility, not on behalf of
153
+ any other Contributor, and only if You agree to indemnify, defend, and hold each
154
+ Contributor harmless for any liability incurred by, or claims asserted against,
155
+ such Contributor by reason of your accepting any such warranty or additional
156
+ liability.
157
+
158
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -1,41 +1,42 @@
1
- # Prisma CLI · [![npm version](https://img.shields.io/npm/v/prisma.svg?style=flat)](https://www.npmjs.com/package/prisma) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/prisma/prisma/blob/master/CONTRIBUTING.md) [![GitHub license](https://img.shields.io/badge/license-Apache%202-blue)](https://github.com/prisma/prisma/blob/master/LICENSE) [![Slack](https://img.shields.io/badge/chat-on%20slack-blue.svg)](https://slack.prisma.io/)
1
+ # Prisma CLI Preview
2
2
 
3
- Learn more about Prisma in the [docs](https://www.prisma.io/docs/).
3
+ Preview npm package for the unified Prisma CLI.
4
4
 
5
- ## Getting started
5
+ Install:
6
6
 
7
- Check out the [**Getting Started Quickstart**](https://www.prisma.io/docs/getting-started/quickstart).
8
-
9
- ## Installation
10
-
11
- The Prisma CLI currently requires Node.js 10.4 (or higher).
12
- We recommend using [the latest Node.js LTS ("long-term support") release.](https://nodejs.org/en/about/releases/)
13
-
14
- ### npm
15
-
16
- ```
17
- npm install prisma --save-dev
7
+ ```bash
8
+ pnpm add -D @prisma/cli@preview
18
9
  ```
19
10
 
20
- ### Yarn
11
+ Run:
21
12
 
13
+ ```bash
14
+ pnpm prisma-cli --help
15
+ pnpm prisma-cli auth login
16
+ pnpm prisma-cli app deploy --env DATABASE_URL=postgresql://example
17
+ pnpm prisma-cli app list-env
22
18
  ```
23
- yarn add prisma --dev
24
- ```
25
-
26
- [Check out the docs for more information.](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-cli/installation)
27
19
 
28
- ## CLI Reference
20
+ The package exposes `prisma-cli` so it can coexist with the existing `prisma`
21
+ executable. If you want local project scripts that use the future command shape,
22
+ add:
29
23
 
30
- [Check out the docs for Prisma CLI commands, arguments, and options.](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-cli/command-reference)
24
+ ```json
25
+ {
26
+ "scripts": {
27
+ "prisma": "prisma-cli"
28
+ }
29
+ }
30
+ ```
31
31
 
32
- ## Contributing
32
+ Then run:
33
33
 
34
- Refer to our [contribution guidelines](https://github.com/prisma/prisma/blob/master/CONTRIBUTING.md) and [Code of Conduct for contributors](https://github.com/prisma/prisma/blob/master/CODE_OF_CONDUCT.md).
34
+ ```bash
35
+ pnpm prisma app deploy
36
+ ```
35
37
 
36
- ## Build Status
38
+ Notes:
37
39
 
38
- - Prisma Tests Status:
39
- [![Build status](https://badge.buildkite.com/590e1981074b70961362481ad8319a831b44a38c5d468d6408.svg?branch=master)](https://buildkite.com/prisma/prisma2-test)
40
- - E2E Tests Status:
41
- [![Actions Status](https://github.com/prisma/prisma2-e2e-tests/workflows/test/badge.svg)](https://github.com/prisma/prisma2-e2e-tests/actions)
40
+ - This is a preview package and may change quickly.
41
+ - `prisma.config.ts` stores linked project context for this CLI.
42
+ - Environment variable values passed with `--env` are not printed back to the terminal.
@@ -0,0 +1,74 @@
1
+ import path from "node:path";
2
+ import { copyFile, mkdir, mkdtemp, readFile, rm } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import { updateConfig } from "c12/update";
5
+ //#region src/adapters/config.ts
6
+ const PROJECT_FIELD_PATTERN = /project\s*:\s*["']([^"']+)["']/;
7
+ async function readLinkedProjectId(cwd) {
8
+ const configPath = path.join(cwd, "prisma.config.ts");
9
+ try {
10
+ return (await readFile(configPath, "utf8")).match(PROJECT_FIELD_PATTERN)?.[1] ?? null;
11
+ } catch (error) {
12
+ if (error.code === "ENOENT") return null;
13
+ throw error;
14
+ }
15
+ }
16
+ var UnsafeConfigWriteError = class extends Error {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = "UnsafeConfigWriteError";
20
+ }
21
+ };
22
+ async function assertLinkedProjectIdWritable(cwd) {
23
+ const tempDir = await mkdtemp(path.join(os.tmpdir(), "prisma-cli-config-"));
24
+ const sourceConfigPath = path.join(cwd, "prisma.config.ts");
25
+ const tempConfigPath = path.join(tempDir, "prisma.config.ts");
26
+ try {
27
+ try {
28
+ await copyFile(sourceConfigPath, tempConfigPath);
29
+ } catch (error) {
30
+ if (error.code !== "ENOENT") throw error;
31
+ }
32
+ await applyLinkedProjectIdUpdate(tempDir, "proj_preflight");
33
+ } catch (error) {
34
+ throw toUnsafeConfigWriteError(error);
35
+ } finally {
36
+ await rm(tempDir, {
37
+ recursive: true,
38
+ force: true
39
+ });
40
+ }
41
+ }
42
+ async function writeLinkedProjectId(cwd, projectId) {
43
+ try {
44
+ await applyLinkedProjectIdUpdate(cwd, projectId);
45
+ } catch (error) {
46
+ if (error.code === "ENOENT") {
47
+ await mkdir(cwd, { recursive: true });
48
+ await applyLinkedProjectIdUpdate(cwd, projectId);
49
+ return;
50
+ }
51
+ throw toUnsafeConfigWriteError(error);
52
+ }
53
+ }
54
+ async function applyLinkedProjectIdUpdate(cwd, projectId) {
55
+ await updateConfig({
56
+ cwd,
57
+ configFile: "prisma.config",
58
+ onUpdate(config) {
59
+ config.project = projectId;
60
+ },
61
+ onCreate() {
62
+ return renderProjectConfig(projectId);
63
+ }
64
+ });
65
+ }
66
+ function renderProjectConfig(projectId) {
67
+ return `export default {\n project: "${projectId}",\n};\n`;
68
+ }
69
+ function toUnsafeConfigWriteError(error) {
70
+ if (error instanceof UnsafeConfigWriteError) return error;
71
+ return new UnsafeConfigWriteError("The existing prisma.config.ts file could not be updated safely.");
72
+ }
73
+ //#endregion
74
+ export { UnsafeConfigWriteError, assertLinkedProjectIdWritable, readLinkedProjectId, writeLinkedProjectId };
@@ -0,0 +1,98 @@
1
+ import path from "node:path";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ //#region src/adapters/local-state.ts
4
+ const DEFAULT_STATE = {
5
+ auth: null,
6
+ branch: { active: "preview" },
7
+ app: {
8
+ selectedByProject: {},
9
+ knownLiveDeploymentByProject: {}
10
+ }
11
+ };
12
+ const DEFAULT_STATE_FILE_NAME = "state.json";
13
+ function resolveLocalStateFilePath(stateDir) {
14
+ return path.join(stateDir, DEFAULT_STATE_FILE_NAME);
15
+ }
16
+ var LocalStateStore = class {
17
+ stateFilePath;
18
+ constructor(stateDir) {
19
+ this.stateFilePath = resolveLocalStateFilePath(stateDir);
20
+ }
21
+ async read() {
22
+ try {
23
+ const raw = await readFile(this.stateFilePath, "utf8");
24
+ const parsed = JSON.parse(raw);
25
+ return {
26
+ auth: parsed.auth ?? structuredClone(DEFAULT_STATE.auth),
27
+ branch: { active: parsed.branch?.active ?? DEFAULT_STATE.branch.active },
28
+ app: {
29
+ selectedByProject: parsed.app?.selectedByProject ?? {},
30
+ knownLiveDeploymentByProject: parsed.app?.knownLiveDeploymentByProject ?? {}
31
+ }
32
+ };
33
+ } catch (error) {
34
+ if (error.code === "ENOENT") return structuredClone(DEFAULT_STATE);
35
+ throw error;
36
+ }
37
+ }
38
+ async write(state) {
39
+ await mkdir(path.dirname(this.stateFilePath), { recursive: true });
40
+ await writeFile(this.stateFilePath, `${JSON.stringify(state, null, 2)}\n`, "utf8");
41
+ }
42
+ async setAuthSession(session) {
43
+ const state = await this.read();
44
+ state.auth = session;
45
+ await this.write(state);
46
+ return state;
47
+ }
48
+ async clearAuthSession() {
49
+ const state = await this.read();
50
+ state.auth = null;
51
+ await this.write(state);
52
+ return state;
53
+ }
54
+ async setActiveBranch(active) {
55
+ const state = await this.read();
56
+ state.branch.active = active;
57
+ await this.write(state);
58
+ return state;
59
+ }
60
+ async readSelectedApp(projectId) {
61
+ return (await this.read()).app.selectedByProject[projectId] ?? null;
62
+ }
63
+ async setSelectedApp(projectId, app) {
64
+ const state = await this.read();
65
+ state.app.selectedByProject[projectId] = app;
66
+ await this.write(state);
67
+ return state;
68
+ }
69
+ async clearSelectedApp(projectId, appId) {
70
+ const state = await this.read();
71
+ const selectedApp = state.app.selectedByProject[projectId];
72
+ if (!selectedApp || selectedApp.id !== appId) return state;
73
+ delete state.app.selectedByProject[projectId];
74
+ await this.write(state);
75
+ return state;
76
+ }
77
+ async readKnownLiveDeployment(projectId, appId) {
78
+ return (await this.read()).app.knownLiveDeploymentByProject[projectId]?.[appId] ?? null;
79
+ }
80
+ async setKnownLiveDeployment(projectId, appId, deploymentId) {
81
+ const state = await this.read();
82
+ state.app.knownLiveDeploymentByProject[projectId] ??= {};
83
+ state.app.knownLiveDeploymentByProject[projectId][appId] = deploymentId;
84
+ await this.write(state);
85
+ return state;
86
+ }
87
+ async clearKnownLiveDeployment(projectId, appId) {
88
+ const state = await this.read();
89
+ const projectDeployments = state.app.knownLiveDeploymentByProject[projectId];
90
+ if (!projectDeployments || !(appId in projectDeployments)) return state;
91
+ delete projectDeployments[appId];
92
+ if (Object.keys(projectDeployments).length === 0) delete state.app.knownLiveDeploymentByProject[projectId];
93
+ await this.write(state);
94
+ return state;
95
+ }
96
+ };
97
+ //#endregion
98
+ export { LocalStateStore };
@@ -0,0 +1,57 @@
1
+ import { readFile } from "node:fs/promises";
2
+ //#region src/adapters/mock-api.ts
3
+ var MockApi = class MockApi {
4
+ data;
5
+ constructor(data) {
6
+ this.data = data;
7
+ }
8
+ static async load(fixturePath) {
9
+ const raw = await readFile(fixturePath, "utf8");
10
+ return new MockApi(JSON.parse(raw));
11
+ }
12
+ listProviders() {
13
+ return this.data.providers;
14
+ }
15
+ getProvider(providerId) {
16
+ return this.data.providers.find((provider) => provider.id === providerId);
17
+ }
18
+ listUsersForProvider(providerId) {
19
+ return this.data.users.filter((user) => user.providerIds.includes(providerId));
20
+ }
21
+ getUser(userId) {
22
+ return this.data.users.find((user) => user.id === userId);
23
+ }
24
+ getUserForProvider(providerId, userId) {
25
+ return this.listUsersForProvider(providerId).find((user) => user.id === userId);
26
+ }
27
+ listUserWorkspaces(userId) {
28
+ const workspaceIds = this.data.memberships.filter((membership) => membership.userId === userId).map((membership) => membership.workspaceId);
29
+ return this.data.workspaces.filter((workspace) => workspaceIds.includes(workspace.id));
30
+ }
31
+ getWorkspace(workspaceId) {
32
+ return this.data.workspaces.find((workspace) => workspace.id === workspaceId);
33
+ }
34
+ getUserWorkspace(userId, workspaceId) {
35
+ return this.listUserWorkspaces(userId).find((workspace) => workspace.id === workspaceId);
36
+ }
37
+ listProjectsForWorkspace(workspaceId) {
38
+ return this.data.projects.filter((project) => project.workspaceId === workspaceId);
39
+ }
40
+ getProject(projectId) {
41
+ return this.data.projects.find((project) => project.id === projectId);
42
+ }
43
+ getProjectForWorkspace(workspaceId, projectId) {
44
+ return this.listProjectsForWorkspace(workspaceId).find((project) => project.id === projectId);
45
+ }
46
+ listBranchesForProject(projectId) {
47
+ return this.data.branches.filter((branch) => branch.projectId === projectId);
48
+ }
49
+ getBranchForProject(projectId, name) {
50
+ return this.listBranchesForProject(projectId).find((branch) => branch.name === name);
51
+ }
52
+ getDeployment(deploymentId) {
53
+ return this.data.deployments.find((deployment) => deployment.id === deploymentId);
54
+ }
55
+ };
56
+ //#endregion
57
+ export { MockApi };
@@ -0,0 +1,43 @@
1
+ import { getAuthFilePath } from "../lib/auth/client.js";
2
+ import { CredentialsStore } from "@prisma/credentials-store";
3
+ //#region src/adapters/token-storage.ts
4
+ function findLatestValidTokens(allCredentials) {
5
+ for (let i = allCredentials.length - 1; i >= 0; i -= 1) {
6
+ const credential = allCredentials[i];
7
+ if (!credential) continue;
8
+ if (typeof credential.workspaceId !== "string" || credential.workspaceId.length === 0 || typeof credential.token !== "string" || credential.token.length === 0 || typeof credential.refreshToken !== "string" || credential.refreshToken.length === 0) continue;
9
+ return {
10
+ workspaceId: credential.workspaceId,
11
+ accessToken: credential.token,
12
+ refreshToken: credential.refreshToken
13
+ };
14
+ }
15
+ return null;
16
+ }
17
+ var FileTokenStorage = class {
18
+ credentialsStore;
19
+ constructor(env = process.env) {
20
+ this.credentialsStore = new CredentialsStore(getAuthFilePath(env));
21
+ }
22
+ async getTokens() {
23
+ try {
24
+ return findLatestValidTokens(await this.credentialsStore.getCredentials());
25
+ } catch {
26
+ return null;
27
+ }
28
+ }
29
+ async setTokens(tokens) {
30
+ await this.credentialsStore.storeCredentials({
31
+ workspaceId: tokens.workspaceId,
32
+ token: tokens.accessToken,
33
+ refreshToken: tokens.refreshToken
34
+ });
35
+ }
36
+ async clearTokens() {
37
+ const tokens = findLatestValidTokens(await this.credentialsStore.getCredentials());
38
+ if (!tokens) return;
39
+ await this.credentialsStore.deleteCredentials(tokens.workspaceId);
40
+ }
41
+ };
42
+ //#endregion
43
+ export { FileTokenStorage };
package/dist/cli.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from "./cli2.js";
3
+ import process from "node:process";
4
+ //#region src/bin.ts
5
+ runCli().then((exitCode) => {
6
+ process.exitCode = exitCode;
7
+ });
8
+ //#endregion
9
+ export {};
package/dist/cli2.js ADDED
@@ -0,0 +1,59 @@
1
+ import { attachCommandDescriptor } from "./shell/command-meta.js";
2
+ import { configureRuntimeCommand } from "./shell/runtime.js";
3
+ import "./shell/prompt.js";
4
+ import { createAppCommand } from "./commands/app/index.js";
5
+ import { createAuthCommand } from "./commands/auth/index.js";
6
+ import { createBranchCommand } from "./commands/branch/index.js";
7
+ import { createProjectCommand } from "./commands/project/index.js";
8
+ import process from "node:process";
9
+ import { Command, CommanderError } from "commander";
10
+ //#region src/cli.ts
11
+ async function runCli(options = {}) {
12
+ const runtime = resolveRuntime(options);
13
+ const program = createProgram(runtime);
14
+ process.exitCode = 0;
15
+ try {
16
+ const bareHelpCommand = resolveBareHelpCommand(program, runtime.argv);
17
+ if (bareHelpCommand) {
18
+ runtime.stderr.write(bareHelpCommand.helpInformation());
19
+ return 0;
20
+ }
21
+ await program.parseAsync(runtime.argv, { from: "user" });
22
+ return process.exitCode ?? 0;
23
+ } catch (error) {
24
+ if (error instanceof CommanderError) return error.code === "commander.helpDisplayed" ? 0 : 2;
25
+ const message = error instanceof Error ? error.stack ?? error.message : String(error);
26
+ runtime.stderr.write(`${message}\n`);
27
+ return 1;
28
+ } finally {
29
+ runtime.stdin;
30
+ }
31
+ }
32
+ function createProgram(runtime) {
33
+ const program = attachCommandDescriptor(configureRuntimeCommand(new Command(), runtime), "root");
34
+ program.name("prisma").showSuggestionAfterError();
35
+ program.addCommand(createAuthCommand(runtime));
36
+ program.addCommand(createBranchCommand(runtime));
37
+ program.addCommand(createProjectCommand(runtime));
38
+ program.addCommand(createAppCommand(runtime));
39
+ return program;
40
+ }
41
+ function resolveBareHelpCommand(program, argv) {
42
+ if (argv.length === 0) return program;
43
+ if (argv.length !== 1) return null;
44
+ return program.commands.find((command) => command.name() === argv[0]) ?? null;
45
+ }
46
+ function resolveRuntime(options) {
47
+ return {
48
+ argv: options.argv ?? process.argv.slice(2),
49
+ cwd: options.cwd ?? process.env.INIT_CWD ?? process.cwd(),
50
+ env: options.env ?? process.env,
51
+ stdin: options.stdin ?? process.stdin,
52
+ stdout: options.stdout ?? process.stdout,
53
+ stderr: options.stderr ?? process.stderr,
54
+ fixturePath: options.fixturePath,
55
+ stateDir: options.stateDir
56
+ };
57
+ }
58
+ //#endregion
59
+ export { runCli };