@augment-vir/node 30.0.0 → 30.0.2
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 +7 -10
- package/dist/augments/docker.d.ts +49 -2
- package/dist/augments/docker.js +48 -2
- package/dist/augments/fs/download.d.ts +11 -0
- package/dist/augments/{download.js → fs/download.js} +7 -0
- package/dist/augments/fs/json.d.ts +42 -0
- package/dist/augments/fs/json.js +34 -0
- package/dist/augments/fs/read-dir.d.ts +11 -3
- package/dist/augments/fs/read-dir.js +11 -3
- package/dist/augments/fs/read-file.d.ts +8 -0
- package/dist/augments/fs/read-file.js +8 -0
- package/dist/augments/fs/symlink.d.ts +7 -0
- package/dist/augments/fs/symlink.js +7 -0
- package/dist/augments/fs/write.d.ts +4 -0
- package/dist/augments/fs/write.js +4 -0
- package/dist/augments/npm/query-workspace.d.ts +14 -0
- package/dist/augments/npm/query-workspace.js +8 -1
- package/dist/augments/npm/read-package-json.d.ts +9 -0
- package/dist/augments/npm/read-package-json.js +9 -0
- package/dist/augments/os/operating-system.d.ts +33 -0
- package/dist/augments/os/operating-system.js +35 -0
- package/dist/augments/path/ancestor.d.ts +19 -0
- package/dist/augments/path/ancestor.js +28 -0
- package/dist/augments/path/os-path.d.ts +19 -3
- package/dist/augments/path/os-path.js +19 -3
- package/dist/augments/path/root.d.ts +7 -0
- package/dist/augments/path/root.js +7 -0
- package/dist/augments/prisma.d.ts +137 -1
- package/dist/augments/prisma.js +135 -1
- package/dist/augments/terminal/question.d.ts +50 -0
- package/dist/augments/{console → terminal}/question.js +23 -2
- package/dist/augments/{shell.d.ts → terminal/shell.d.ts} +87 -4
- package/dist/augments/{shell.js → terminal/shell.js} +63 -3
- package/dist/docker/containers/container-info.d.ts +35 -6
- package/dist/docker/containers/container-info.js +1 -7
- package/dist/docker/containers/container-status.d.ts +15 -0
- package/dist/docker/containers/container-status.js +16 -1
- package/dist/docker/containers/copy-to-container.d.ts +7 -0
- package/dist/docker/containers/copy-to-container.js +1 -1
- package/dist/docker/containers/docker-command-inputs.d.ts +54 -0
- package/dist/docker/containers/docker-command-inputs.js +9 -0
- package/dist/docker/containers/kill-container.js +1 -1
- package/dist/docker/containers/run-command.d.ts +8 -2
- package/dist/docker/containers/run-command.js +1 -2
- package/dist/docker/containers/run-container.d.ts +7 -0
- package/dist/docker/containers/run-container.js +1 -1
- package/dist/docker/docker-image.js +4 -2
- package/dist/docker/docker-startup.js +1 -2
- package/dist/docker/run-docker-test.mock.d.ts +2 -0
- package/dist/docker/run-docker-test.mock.js +16 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/prisma/disable-ci-env.mock.d.ts +2 -0
- package/dist/prisma/disable-ci-env.mock.js +81 -0
- package/dist/prisma/model-data.d.ts +73 -0
- package/dist/prisma/model-data.js +70 -0
- package/dist/prisma/prisma-client.d.ts +0 -4
- package/dist/prisma/prisma-client.js +0 -4
- package/dist/prisma/prisma-errors.d.ts +25 -0
- package/dist/prisma/prisma-errors.js +25 -0
- package/dist/prisma/prisma-migrations.d.ts +12 -6
- package/dist/prisma/prisma-migrations.js +1 -7
- package/dist/prisma/run-prisma-command.d.ts +1 -1
- package/dist/prisma/run-prisma-command.js +1 -1
- package/package.json +23 -13
- package/dist/augments/console/question.d.ts +0 -14
- package/dist/augments/download.d.ts +0 -4
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { systemRootPath } from './root.js';
|
|
4
|
+
/**
|
|
5
|
+
* Find an ancestor file path that matches the given `callback`. If no matches are found all the way
|
|
6
|
+
* up until the system root, this returns `undefined`.
|
|
7
|
+
*
|
|
8
|
+
* @category Path : Node
|
|
9
|
+
* @category Package : @augment-vir/node
|
|
10
|
+
* @returns `undefined` if no matches are found.
|
|
11
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
12
|
+
*/
|
|
4
13
|
export function findAncestor(currentPath, callback) {
|
|
5
14
|
if (currentPath === systemRootPath) {
|
|
6
15
|
return undefined;
|
|
@@ -24,6 +33,25 @@ export function findAncestor(currentPath, callback) {
|
|
|
24
33
|
return findAncestor(dirname(currentPath), callback);
|
|
25
34
|
}
|
|
26
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Join a list of paths to the given `parentDirPath`. This is particularly useful for getting full
|
|
38
|
+
* paths from the output of
|
|
39
|
+
* [`readdir`](https://nodejs.org/api/fs.html#fspromisesreaddirpath-options).
|
|
40
|
+
*
|
|
41
|
+
* @category Path : Node
|
|
42
|
+
* @category Package : @augment-vir/node
|
|
43
|
+
* @example
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import {readdir} from 'node:fs/promises';
|
|
47
|
+
* import {join} from 'node:path';
|
|
48
|
+
*
|
|
49
|
+
* const parentDir = join('my', 'path');
|
|
50
|
+
* const dirs = joinFilesToDir(parentDir, await readdir(parentDir));
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
54
|
+
*/
|
|
27
55
|
export function joinFilesToDir(parentDirPath, childNames) {
|
|
28
56
|
return childNames.map((childName) => join(parentDirPath, childName));
|
|
29
57
|
}
|
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Convert a given path to a windows path if the current system doesn't use `/`.
|
|
3
|
+
*
|
|
4
|
+
* @category Path : Node
|
|
5
|
+
* @category Package : @augment-vir/node
|
|
6
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
7
|
+
*/
|
|
2
8
|
export declare function replaceWithWindowsPathIfNeeded(input: string): string;
|
|
3
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Convert a Windows path to a posix path.
|
|
11
|
+
*
|
|
12
|
+
* @category Path : Node
|
|
13
|
+
* @category Package : @augment-vir/node
|
|
14
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
15
|
+
*/
|
|
4
16
|
export declare function toPosixPath(maybeWindowsPath: string): string;
|
|
5
17
|
/**
|
|
6
|
-
* Use this to interpolate paths into bash commands. If the given path is not a
|
|
18
|
+
* Use this to interpolate paths into bash commands. If the given path is not a Windows path, the
|
|
7
19
|
* path structure will not be modified.
|
|
20
|
+
*
|
|
21
|
+
* @category Path : Node
|
|
22
|
+
* @category Package : @augment-vir/node
|
|
23
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
24
|
*/
|
|
9
25
|
export declare function interpolationSafeWindowsPath(input: string): string;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { sep } from 'node:path';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Convert a given path to a windows path if the current system doesn't use `/`.
|
|
4
|
+
*
|
|
5
|
+
* @category Path : Node
|
|
6
|
+
* @category Package : @augment-vir/node
|
|
7
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
|
+
*/
|
|
3
9
|
export function replaceWithWindowsPathIfNeeded(input) {
|
|
4
10
|
if (sep === '/') {
|
|
5
11
|
return input;
|
|
@@ -10,7 +16,13 @@ export function replaceWithWindowsPathIfNeeded(input) {
|
|
|
10
16
|
return input.replace(/\//g, sep);
|
|
11
17
|
}
|
|
12
18
|
}
|
|
13
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Convert a Windows path to a posix path.
|
|
21
|
+
*
|
|
22
|
+
* @category Path : Node
|
|
23
|
+
* @category Package : @augment-vir/node
|
|
24
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
25
|
+
*/
|
|
14
26
|
export function toPosixPath(maybeWindowsPath) {
|
|
15
27
|
return maybeWindowsPath
|
|
16
28
|
.replace(/^(.+?):\\+/, (match, captureGroup) => {
|
|
@@ -19,8 +31,12 @@ export function toPosixPath(maybeWindowsPath) {
|
|
|
19
31
|
.replace(/\\+/g, '/');
|
|
20
32
|
}
|
|
21
33
|
/**
|
|
22
|
-
* Use this to interpolate paths into bash commands. If the given path is not a
|
|
34
|
+
* Use this to interpolate paths into bash commands. If the given path is not a Windows path, the
|
|
23
35
|
* path structure will not be modified.
|
|
36
|
+
*
|
|
37
|
+
* @category Path : Node
|
|
38
|
+
* @category Package : @augment-vir/node
|
|
39
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
24
40
|
*/
|
|
25
41
|
export function interpolationSafeWindowsPath(input) {
|
|
26
42
|
return input.replace(/\\/g, '\\\\\\\\');
|
|
@@ -2,4 +2,11 @@ import { parse } from 'node:path';
|
|
|
2
2
|
function getSystemRootPath() {
|
|
3
3
|
return parse(process.cwd()).root;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* The root path of the system containing the cwd.
|
|
7
|
+
*
|
|
8
|
+
* @category Path : Node
|
|
9
|
+
* @category Package : @augment-vir/node
|
|
10
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
11
|
+
*/
|
|
5
12
|
export const systemRootPath = getSystemRootPath();
|
|
@@ -1,21 +1,157 @@
|
|
|
1
|
+
import { addData, dumpData, getAllPrismaModelNames } from '../prisma/model-data.js';
|
|
1
2
|
import { generatePrismaClient, isGeneratedPrismaClientCurrent } from '../prisma/prisma-client.js';
|
|
2
3
|
import { doesPrismaDiffExist, getPrismaDiff, resetDevPrismaDatabase } from '../prisma/prisma-database.js';
|
|
3
4
|
import { applyPrismaMigrationsToDev, applyPrismaMigrationsToProd, createPrismaMigration, getMigrationStatus } from '../prisma/prisma-migrations.js';
|
|
4
|
-
|
|
5
|
+
export type { PrismaAddDataData as PrismaAddModelData, PrismaDataDumpOptions, } from '../prisma/model-data.js';
|
|
6
|
+
export * from '../prisma/prisma-errors.js';
|
|
7
|
+
export type { PrismaMigrationStatus } from '../prisma/prisma-migrations.js';
|
|
8
|
+
/**
|
|
9
|
+
* Centralized Prisma API from `@augment-vir/node`.
|
|
10
|
+
*
|
|
11
|
+
* ## Prisma flows
|
|
12
|
+
*
|
|
13
|
+
* - Deploy to production
|
|
14
|
+
*
|
|
15
|
+
* - {@link prisma.migration.applyProd}
|
|
16
|
+
* - Update dev environment
|
|
17
|
+
*
|
|
18
|
+
* - Apply migrations: {@link prisma.migration.applyDev}
|
|
19
|
+
*
|
|
20
|
+
* - If throws {@link PrismaMigrationNeededError}, prompt user for a new migration name and pass it to
|
|
21
|
+
* {@link prisma.migration.create}
|
|
22
|
+
* - If throws {@link PrismaResetNeededError}, reset the database with {@link prisma.database.resetDev}
|
|
23
|
+
* - Generate client: `prisma.client.isCurrent`
|
|
24
|
+
*
|
|
25
|
+
* - If `false`, run {@link prisma.client.generate}
|
|
26
|
+
*
|
|
27
|
+
* @category Prisma : Node
|
|
28
|
+
* @category Package : @augment-vir/node
|
|
29
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
30
|
+
*/
|
|
5
31
|
export declare const prisma: {
|
|
6
32
|
migration: {
|
|
33
|
+
/**
|
|
34
|
+
* Get current migration status.
|
|
35
|
+
*
|
|
36
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-status
|
|
37
|
+
*/
|
|
7
38
|
status: typeof getMigrationStatus;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new migration.
|
|
41
|
+
*
|
|
42
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-dev
|
|
43
|
+
*/
|
|
8
44
|
create: typeof createPrismaMigration;
|
|
45
|
+
/**
|
|
46
|
+
* Apply all migrations. Meant for a production environment.
|
|
47
|
+
*
|
|
48
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-deploy
|
|
49
|
+
*/
|
|
9
50
|
applyProd: typeof applyPrismaMigrationsToProd;
|
|
51
|
+
/**
|
|
52
|
+
* Apply all migrations. Meant for a development environment, with less protections than
|
|
53
|
+
* {@link prisma.migration.applyProd}.
|
|
54
|
+
*
|
|
55
|
+
* @throws `PrismaMigrationNeededError` when a new migration is required so the user needs
|
|
56
|
+
* to input a name.
|
|
57
|
+
* @throws `PrismaResetNeededError` when there's a migration mismatch with the database and
|
|
58
|
+
* it needs to be reset.
|
|
59
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-dev
|
|
60
|
+
*/
|
|
10
61
|
applyDev: typeof applyPrismaMigrationsToDev;
|
|
11
62
|
};
|
|
12
63
|
database: {
|
|
64
|
+
/**
|
|
65
|
+
* Force resets a dev database to match the current Prisma schema and migrations.
|
|
66
|
+
*
|
|
67
|
+
* **This will destroy all data. Do not use in production.**
|
|
68
|
+
*
|
|
69
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-reset
|
|
70
|
+
*/
|
|
13
71
|
resetDev: typeof resetDevPrismaDatabase;
|
|
72
|
+
/**
|
|
73
|
+
* Uses {@link prisma.database.diff} to detect if there are any differences between the
|
|
74
|
+
* current database and the Prisma schema that should control it.
|
|
75
|
+
*/
|
|
14
76
|
hasDiff: typeof doesPrismaDiffExist;
|
|
77
|
+
/**
|
|
78
|
+
* Gets a string list of all differences between the current database and the Prisma schema
|
|
79
|
+
* that should control it.
|
|
80
|
+
*
|
|
81
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-diff
|
|
82
|
+
*/
|
|
15
83
|
diff: typeof getPrismaDiff;
|
|
16
84
|
};
|
|
17
85
|
client: {
|
|
86
|
+
/**
|
|
87
|
+
* Runs Prisma generators included in the given Prisma schema (which usually includes the
|
|
88
|
+
* Prisma JS client). This will work even if the database doesn't exist yet.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* import {prisma} from '@augment-vir/node';
|
|
94
|
+
*
|
|
95
|
+
* prisma.client.generate('../../prisma/schema.prisma');
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
18
98
|
generate: typeof generatePrismaClient;
|
|
99
|
+
/**
|
|
100
|
+
* Detects if the current generated Prisma JS Client was generated from the current Prisma
|
|
101
|
+
* schema.
|
|
102
|
+
*/
|
|
19
103
|
isCurrent: typeof isGeneratedPrismaClientCurrent;
|
|
104
|
+
/**
|
|
105
|
+
* Adds a collection of create data to a database through a `PrismaClient` instance. This is
|
|
106
|
+
* particularly useful for setting up mocks in a mock PrismaClient.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
*
|
|
110
|
+
* ```ts
|
|
111
|
+
* import {addPrismaModelData} from '@augment-vir/common';
|
|
112
|
+
* import {PrismaClient} from '@prisma/client';
|
|
113
|
+
*
|
|
114
|
+
* await addPrismaModelData(new PrismaClient(), [
|
|
115
|
+
* {
|
|
116
|
+
* user: {
|
|
117
|
+
* mockUser1: {
|
|
118
|
+
* first_name: 'one',
|
|
119
|
+
* id: 123,
|
|
120
|
+
* // etc.
|
|
121
|
+
* },
|
|
122
|
+
* mockUser2: {
|
|
123
|
+
* first_name: 'two',
|
|
124
|
+
* id: 124,
|
|
125
|
+
* authRole: 'user',
|
|
126
|
+
* // etc.
|
|
127
|
+
* },
|
|
128
|
+
* },
|
|
129
|
+
* },
|
|
130
|
+
* {
|
|
131
|
+
* region: [
|
|
132
|
+
* {
|
|
133
|
+
* id: 1,
|
|
134
|
+
* name: 'North America',
|
|
135
|
+
* // etc.
|
|
136
|
+
* },
|
|
137
|
+
* {
|
|
138
|
+
* id: 2,
|
|
139
|
+
* name: 'Europe',
|
|
140
|
+
* // etc.
|
|
141
|
+
* },
|
|
142
|
+
* ],
|
|
143
|
+
* },
|
|
144
|
+
* ]);
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
addData: typeof addData;
|
|
148
|
+
/**
|
|
149
|
+
* Dump data from the current database through a `PrismaClient` instance.
|
|
150
|
+
*
|
|
151
|
+
* @see {@link PrismaDataDumpOptions}
|
|
152
|
+
*/
|
|
153
|
+
dumpData: typeof dumpData;
|
|
154
|
+
/** List all model names in the given Prisma client. */
|
|
155
|
+
listModelNames: typeof getAllPrismaModelNames;
|
|
20
156
|
};
|
|
21
157
|
};
|
package/dist/augments/prisma.js
CHANGED
|
@@ -1,21 +1,155 @@
|
|
|
1
|
+
import { addData, dumpData, getAllPrismaModelNames } from '../prisma/model-data.js';
|
|
1
2
|
import { generatePrismaClient, isGeneratedPrismaClientCurrent } from '../prisma/prisma-client.js';
|
|
2
3
|
import { doesPrismaDiffExist, getPrismaDiff, resetDevPrismaDatabase, } from '../prisma/prisma-database.js';
|
|
3
4
|
import { applyPrismaMigrationsToDev, applyPrismaMigrationsToProd, createPrismaMigration, getMigrationStatus, } from '../prisma/prisma-migrations.js';
|
|
4
|
-
|
|
5
|
+
export * from '../prisma/prisma-errors.js';
|
|
6
|
+
/**
|
|
7
|
+
* Centralized Prisma API from `@augment-vir/node`.
|
|
8
|
+
*
|
|
9
|
+
* ## Prisma flows
|
|
10
|
+
*
|
|
11
|
+
* - Deploy to production
|
|
12
|
+
*
|
|
13
|
+
* - {@link prisma.migration.applyProd}
|
|
14
|
+
* - Update dev environment
|
|
15
|
+
*
|
|
16
|
+
* - Apply migrations: {@link prisma.migration.applyDev}
|
|
17
|
+
*
|
|
18
|
+
* - If throws {@link PrismaMigrationNeededError}, prompt user for a new migration name and pass it to
|
|
19
|
+
* {@link prisma.migration.create}
|
|
20
|
+
* - If throws {@link PrismaResetNeededError}, reset the database with {@link prisma.database.resetDev}
|
|
21
|
+
* - Generate client: `prisma.client.isCurrent`
|
|
22
|
+
*
|
|
23
|
+
* - If `false`, run {@link prisma.client.generate}
|
|
24
|
+
*
|
|
25
|
+
* @category Prisma : Node
|
|
26
|
+
* @category Package : @augment-vir/node
|
|
27
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
28
|
+
*/
|
|
5
29
|
export const prisma = {
|
|
6
30
|
migration: {
|
|
31
|
+
/**
|
|
32
|
+
* Get current migration status.
|
|
33
|
+
*
|
|
34
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-status
|
|
35
|
+
*/
|
|
7
36
|
status: getMigrationStatus,
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new migration.
|
|
39
|
+
*
|
|
40
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-dev
|
|
41
|
+
*/
|
|
8
42
|
create: createPrismaMigration,
|
|
43
|
+
/**
|
|
44
|
+
* Apply all migrations. Meant for a production environment.
|
|
45
|
+
*
|
|
46
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-deploy
|
|
47
|
+
*/
|
|
9
48
|
applyProd: applyPrismaMigrationsToProd,
|
|
49
|
+
/**
|
|
50
|
+
* Apply all migrations. Meant for a development environment, with less protections than
|
|
51
|
+
* {@link prisma.migration.applyProd}.
|
|
52
|
+
*
|
|
53
|
+
* @throws `PrismaMigrationNeededError` when a new migration is required so the user needs
|
|
54
|
+
* to input a name.
|
|
55
|
+
* @throws `PrismaResetNeededError` when there's a migration mismatch with the database and
|
|
56
|
+
* it needs to be reset.
|
|
57
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-dev
|
|
58
|
+
*/
|
|
10
59
|
applyDev: applyPrismaMigrationsToDev,
|
|
11
60
|
},
|
|
12
61
|
database: {
|
|
62
|
+
/**
|
|
63
|
+
* Force resets a dev database to match the current Prisma schema and migrations.
|
|
64
|
+
*
|
|
65
|
+
* **This will destroy all data. Do not use in production.**
|
|
66
|
+
*
|
|
67
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-reset
|
|
68
|
+
*/
|
|
13
69
|
resetDev: resetDevPrismaDatabase,
|
|
70
|
+
/**
|
|
71
|
+
* Uses {@link prisma.database.diff} to detect if there are any differences between the
|
|
72
|
+
* current database and the Prisma schema that should control it.
|
|
73
|
+
*/
|
|
14
74
|
hasDiff: doesPrismaDiffExist,
|
|
75
|
+
/**
|
|
76
|
+
* Gets a string list of all differences between the current database and the Prisma schema
|
|
77
|
+
* that should control it.
|
|
78
|
+
*
|
|
79
|
+
* @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-diff
|
|
80
|
+
*/
|
|
15
81
|
diff: getPrismaDiff,
|
|
16
82
|
},
|
|
17
83
|
client: {
|
|
84
|
+
/**
|
|
85
|
+
* Runs Prisma generators included in the given Prisma schema (which usually includes the
|
|
86
|
+
* Prisma JS client). This will work even if the database doesn't exist yet.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* import {prisma} from '@augment-vir/node';
|
|
92
|
+
*
|
|
93
|
+
* prisma.client.generate('../../prisma/schema.prisma');
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
18
96
|
generate: generatePrismaClient,
|
|
97
|
+
/**
|
|
98
|
+
* Detects if the current generated Prisma JS Client was generated from the current Prisma
|
|
99
|
+
* schema.
|
|
100
|
+
*/
|
|
19
101
|
isCurrent: isGeneratedPrismaClientCurrent,
|
|
102
|
+
/**
|
|
103
|
+
* Adds a collection of create data to a database through a `PrismaClient` instance. This is
|
|
104
|
+
* particularly useful for setting up mocks in a mock PrismaClient.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* import {addPrismaModelData} from '@augment-vir/common';
|
|
110
|
+
* import {PrismaClient} from '@prisma/client';
|
|
111
|
+
*
|
|
112
|
+
* await addPrismaModelData(new PrismaClient(), [
|
|
113
|
+
* {
|
|
114
|
+
* user: {
|
|
115
|
+
* mockUser1: {
|
|
116
|
+
* first_name: 'one',
|
|
117
|
+
* id: 123,
|
|
118
|
+
* // etc.
|
|
119
|
+
* },
|
|
120
|
+
* mockUser2: {
|
|
121
|
+
* first_name: 'two',
|
|
122
|
+
* id: 124,
|
|
123
|
+
* authRole: 'user',
|
|
124
|
+
* // etc.
|
|
125
|
+
* },
|
|
126
|
+
* },
|
|
127
|
+
* },
|
|
128
|
+
* {
|
|
129
|
+
* region: [
|
|
130
|
+
* {
|
|
131
|
+
* id: 1,
|
|
132
|
+
* name: 'North America',
|
|
133
|
+
* // etc.
|
|
134
|
+
* },
|
|
135
|
+
* {
|
|
136
|
+
* id: 2,
|
|
137
|
+
* name: 'Europe',
|
|
138
|
+
* // etc.
|
|
139
|
+
* },
|
|
140
|
+
* ],
|
|
141
|
+
* },
|
|
142
|
+
* ]);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
addData: addData,
|
|
146
|
+
/**
|
|
147
|
+
* Dump data from the current database through a `PrismaClient` instance.
|
|
148
|
+
*
|
|
149
|
+
* @see {@link PrismaDataDumpOptions}
|
|
150
|
+
*/
|
|
151
|
+
dumpData: dumpData,
|
|
152
|
+
/** List all model names in the given Prisma client. */
|
|
153
|
+
listModelNames: getAllPrismaModelNames,
|
|
20
154
|
},
|
|
21
155
|
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type AnyDuration } from '@date-vir/duration';
|
|
2
|
+
/** Can't test requiring user input. */
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link askQuestion}.
|
|
5
|
+
*
|
|
6
|
+
* @category Node : Terminal : Util
|
|
7
|
+
* @category Package : @augment-vir/node
|
|
8
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
9
|
+
*/
|
|
10
|
+
export type AskQuestionOptions = {
|
|
11
|
+
timeout: AnyDuration;
|
|
12
|
+
hideUserInput: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Asks the user a question in their terminal and then waits for them to type something in response.
|
|
16
|
+
* The response is accepted once the user inputs a new line.
|
|
17
|
+
*
|
|
18
|
+
* @category Node : Terminal
|
|
19
|
+
* @category Package : @augment-vir/node
|
|
20
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
21
|
+
* @see
|
|
22
|
+
* - {@link askQuestionUntilConditionMet}: ask a question on loop until the user provides a valid response.
|
|
23
|
+
*/
|
|
24
|
+
export declare function askQuestion(questionToAsk: string, { hideUserInput, timeout, }?: Partial<AskQuestionOptions>): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Options for {@link askQuestionUntilConditionMet}.
|
|
27
|
+
*
|
|
28
|
+
* @category Node : Terminal : Util
|
|
29
|
+
* @category Package : @augment-vir/node
|
|
30
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
31
|
+
*/
|
|
32
|
+
export type QuestionUntilConditionMetOptions = {
|
|
33
|
+
questionToAsk: string;
|
|
34
|
+
/** Callback to call with the user's response to verify if their response is valid. */
|
|
35
|
+
verifyResponseCallback: (response: string) => boolean | Promise<boolean>;
|
|
36
|
+
invalidInputMessage: string;
|
|
37
|
+
tryCountMax?: number;
|
|
38
|
+
} & Partial<AskQuestionOptions>;
|
|
39
|
+
/**
|
|
40
|
+
* Asks the user a question in their terminal and then waits for them to type something in response.
|
|
41
|
+
* The response is submitted once the user inputs a new line. If the response fails validation, the
|
|
42
|
+
* question is presented again.
|
|
43
|
+
*
|
|
44
|
+
* @category Node : Terminal
|
|
45
|
+
* @category Package : @augment-vir/node
|
|
46
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
47
|
+
* @see
|
|
48
|
+
* - {@link askQuestion}: ask a question and accept any response.
|
|
49
|
+
*/
|
|
50
|
+
export declare function askQuestionUntilConditionMet({ questionToAsk, verifyResponseCallback, invalidInputMessage, tryCountMax, ...options }: QuestionUntilConditionMetOptions): Promise<string>;
|
|
@@ -5,6 +5,16 @@ const defaultAskQuestionOptions = {
|
|
|
5
5
|
timeout: { seconds: 60 },
|
|
6
6
|
hideUserInput: false,
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Asks the user a question in their terminal and then waits for them to type something in response.
|
|
10
|
+
* The response is accepted once the user inputs a new line.
|
|
11
|
+
*
|
|
12
|
+
* @category Node : Terminal
|
|
13
|
+
* @category Package : @augment-vir/node
|
|
14
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
15
|
+
* @see
|
|
16
|
+
* - {@link askQuestionUntilConditionMet}: ask a question on loop until the user provides a valid response.
|
|
17
|
+
*/
|
|
8
18
|
export async function askQuestion(questionToAsk, { hideUserInput = defaultAskQuestionOptions.hideUserInput, timeout = defaultAskQuestionOptions.timeout, } = defaultAskQuestionOptions) {
|
|
9
19
|
const cliInterface = createInterface({
|
|
10
20
|
input: process.stdin,
|
|
@@ -44,13 +54,24 @@ export async function askQuestion(questionToAsk, { hideUserInput = defaultAskQue
|
|
|
44
54
|
});
|
|
45
55
|
});
|
|
46
56
|
}
|
|
47
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Asks the user a question in their terminal and then waits for them to type something in response.
|
|
59
|
+
* The response is submitted once the user inputs a new line. If the response fails validation, the
|
|
60
|
+
* question is presented again.
|
|
61
|
+
*
|
|
62
|
+
* @category Node : Terminal
|
|
63
|
+
* @category Package : @augment-vir/node
|
|
64
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
65
|
+
* @see
|
|
66
|
+
* - {@link askQuestion}: ask a question and accept any response.
|
|
67
|
+
*/
|
|
68
|
+
export async function askQuestionUntilConditionMet({ questionToAsk, verifyResponseCallback, invalidInputMessage, tryCountMax = 5, ...options }) {
|
|
48
69
|
let wasConditionMet = false;
|
|
49
70
|
let retryCount = 0;
|
|
50
71
|
let response = '';
|
|
51
72
|
while (!wasConditionMet && retryCount <= tryCountMax) {
|
|
52
73
|
response = (await askQuestion(questionToAsk, options)).trim();
|
|
53
|
-
wasConditionMet = await
|
|
74
|
+
wasConditionMet = await verifyResponseCallback(response);
|
|
54
75
|
if (!wasConditionMet) {
|
|
55
76
|
log.error(invalidInputMessage);
|
|
56
77
|
}
|