@augment-vir/node 31.9.1 → 31.9.3

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.
@@ -65,7 +65,7 @@ export async function resetDirContents(rootDir, contents) {
65
65
  * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
66
66
  */
67
67
  export async function writeDirContents(rootDir, contents) {
68
- await Promise.all(getObjectTypedEntries(contents).map(async ([relativePath, content]) => {
68
+ await Promise.all(getObjectTypedEntries(contents).map(async ([relativePath, content,]) => {
69
69
  const fullPath = join(rootDir, relativePath);
70
70
  if (check.isString(content)) {
71
71
  await writeFileAndDir(fullPath, content);
@@ -61,7 +61,7 @@ function mapImportPath(importPath, tsconfig, tsconfigPath) {
61
61
  if (!paths) {
62
62
  return importPath;
63
63
  }
64
- const mappedPaths = filterMap(getObjectTypedEntries(paths), ([alias, paths]) => {
64
+ const mappedPaths = filterMap(getObjectTypedEntries(paths), ([alias, paths,]) => {
65
65
  const aliasRegex = new RegExp('^' + String(alias).replace(/\*/g, '(.*)') + '$');
66
66
  const match = importPath.match(aliasRegex);
67
67
  if (!match) {
@@ -37,7 +37,13 @@ export type RelevantArgsInput = {
37
37
  *
38
38
  * ```ts
39
39
  * extractRelevantArgs({
40
- * rawArgs: ['npx', 'ts-node', './my-script.ts', 'arg1', '--arg2'], // typically will be process.argv
40
+ * rawArgs: [
41
+ * 'npx',
42
+ * 'ts-node',
43
+ * './my-script.ts',
44
+ * 'arg1',
45
+ * '--arg2',
46
+ * ], // typically will be process.argv
41
47
  * binName: 'my-script', // should be your package.json "bin" property name, can be undefined
42
48
  * fileName: 'my-script.ts', // should be __filename from the script that will be executed
43
49
  * });
@@ -9,7 +9,13 @@ import { basename } from 'node:path';
9
9
  *
10
10
  * ```ts
11
11
  * extractRelevantArgs({
12
- * rawArgs: ['npx', 'ts-node', './my-script.ts', 'arg1', '--arg2'], // typically will be process.argv
12
+ * rawArgs: [
13
+ * 'npx',
14
+ * 'ts-node',
15
+ * './my-script.ts',
16
+ * 'arg1',
17
+ * '--arg2',
18
+ * ], // typically will be process.argv
13
19
  * binName: 'my-script', // should be your package.json "bin" property name, can be undefined
14
20
  * fileName: 'my-script.ts', // should be __filename from the script that will be executed
15
21
  * });
@@ -51,7 +51,11 @@ binName) {
51
51
  binName: runner.npx,
52
52
  startPath: dirname(cliScriptFilePath),
53
53
  }) || runner.npx;
54
- const results = await runShellCommand(interpolationSafeWindowsPath([runnerPath, scriptPath, ...args].join(' ')), {
54
+ const results = await runShellCommand(interpolationSafeWindowsPath([
55
+ runnerPath,
56
+ scriptPath,
57
+ ...args,
58
+ ].join(' ')), {
55
59
  hookUpToConsole: true,
56
60
  });
57
61
  process.exit(results.exitCode || 0);
@@ -169,7 +169,10 @@ export async function runShellCommand(command, options = {}) {
169
169
  }
170
170
  /* node:coverage enable */
171
171
  shellTarget.destroy();
172
- const rejectionErrorMessage = combineErrors([new Error(stderr), ...errors]);
172
+ const rejectionErrorMessage = combineErrors([
173
+ new Error(stderr),
174
+ ...errors,
175
+ ]);
173
176
  /** Reject now because the "done" listener won't get fired after killing the process. */
174
177
  reject(rejectionErrorMessage);
175
178
  });
@@ -37,7 +37,7 @@ export function makeEnvFlags(envMapping) {
37
37
  if (!envMapping) {
38
38
  return '';
39
39
  }
40
- const flags = Object.entries(envMapping).map(([key, { value, allowInterpolation }]) => {
40
+ const flags = Object.entries(envMapping).map(([key, { value, allowInterpolation },]) => {
41
41
  const quote = allowInterpolation ? '"' : "'";
42
42
  return `-e ${key}=${wrapString({ value, wrapper: quote })}`;
43
43
  });
@@ -4,7 +4,10 @@ export async function runMockLongLivingContainer(containerName, args = {}) {
4
4
  containerName: containerName,
5
5
  detach: true,
6
6
  imageName: 'alpine:3.20.2',
7
- dockerFlags: ['-i', '-t'],
7
+ dockerFlags: [
8
+ '-i',
9
+ '-t',
10
+ ],
8
11
  command: 'sh',
9
12
  platform: 'amd64',
10
13
  ...args,
@@ -11,7 +11,12 @@ imageName, platform) {
11
11
  const command = [
12
12
  'docker',
13
13
  'pull',
14
- ...(platform ? ['--platform', platform] : []),
14
+ ...(platform
15
+ ? [
16
+ '--platform',
17
+ platform,
18
+ ]
19
+ : []),
15
20
  wrapString({ value: imageName, wrapper: "'" }),
16
21
  ].join(' ');
17
22
  await runShellCommand(command, {
@@ -8,11 +8,11 @@ export async function addData(prismaClient, data) {
8
8
  }
9
9
  async function addModelDataObject(prismaClient, data) {
10
10
  /** Add the mock data to the mock prisma client. */
11
- await awaitedForEach(getObjectTypedEntries(data), async ([modelName, mockData]) => {
11
+ await awaitedForEach(getObjectTypedEntries(data), async ([modelName, mockData,]) => {
12
12
  /**
13
- * This type is dumbed down to just `AnyObject[]` because the union of all possible model
14
- * data is just way too big (and not helpful as the inputs to this function are already type
15
- * guarded).
13
+ * This type is dumbed down to just `AnyObject[]` because the union of all possible
14
+ * model data is just way too big (and not helpful as the inputs to this function are
15
+ * already type guarded).
16
16
  */
17
17
  const mockModelInstances = Array.isArray(mockData)
18
18
  ? mockData
@@ -37,10 +37,16 @@ async function addModelDataObject(prismaClient, data) {
37
37
  }
38
38
  });
39
39
  }
40
- const prismockKeys = ['getData', 'setData'];
40
+ const prismockKeys = [
41
+ 'getData',
42
+ 'setData',
43
+ ];
41
44
  export function getAllPrismaModelNames(prismaClient) {
42
45
  return Object.keys(prismaClient)
43
- .filter((key) => !key.startsWith('$') && !key.startsWith('_') && !prismockKeys.includes(key))
46
+ .filter((key) => !key.startsWith('$') &&
47
+ !key.startsWith('_') &&
48
+ !prismockKeys.includes(key) &&
49
+ key !== 'constructor')
44
50
  .sort();
45
51
  }
46
52
  const defaultPrismaDumpDataOptions = {
@@ -13,7 +13,12 @@ var DbChangeRequired;
13
13
  DbChangeRequired["ResetNeeded"] = "reset-needed";
14
14
  })(DbChangeRequired || (DbChangeRequired = {}));
15
15
  export async function applyPrismaMigrationsToDev(schemaFilePath, env = {}) {
16
- const command = ['prisma', 'migrate', 'dev', `--schema='${schemaFilePath}'`].join(' ');
16
+ const command = [
17
+ 'prisma',
18
+ 'migrate',
19
+ 'dev',
20
+ `--schema='${schemaFilePath}'`,
21
+ ].join(' ');
17
22
  log.faint(`> ${command}`);
18
23
  let dbRequirement = undefined;
19
24
  const result = await runShellCommand(command, {
@@ -71,7 +76,7 @@ export async function getMigrationStatus(schemaFilePath, env = {}) {
71
76
  foundNotAppliedMigrations = true;
72
77
  }
73
78
  else {
74
- const [, countMatch] = safeMatch(line, /^([\d,]+) migrations? found in/);
79
+ const [, countMatch,] = safeMatch(line, /^([\d,]+) migrations? found in/);
75
80
  if (countMatch) {
76
81
  listedMigrations.totalMigrations = toEnsuredNumber(countMatch);
77
82
  }
@@ -8,13 +8,21 @@ export async function runPrismaCommand({ command, ignoreExitCode = false, },
8
8
  /** Set to `undefined` to omit the `--schema` flag. */
9
9
  schemaFilePath, env = {}) {
10
10
  const schemaFileArgs = schemaFilePath
11
- ? ['--schema', wrapString({ value: schemaFilePath, wrapper: "'" })]
11
+ ? [
12
+ '--schema',
13
+ wrapString({ value: schemaFilePath, wrapper: "'" }),
14
+ ]
12
15
  : [];
13
16
  /** Disable Prisma's in-CLI ads. */
14
17
  const noHintsArg = prismaCommandsThatSupportNoHints.some((commandName) => command.startsWith(commandName))
15
18
  ? '--no-hints'
16
19
  : '';
17
- const fullCommand = ['prisma', command, ...schemaFileArgs, noHintsArg].join(' ');
20
+ const fullCommand = [
21
+ 'prisma',
22
+ command,
23
+ ...schemaFileArgs,
24
+ noHintsArg,
25
+ ].join(' ');
18
26
  log.faint(`> ${fullCommand}`);
19
27
  const result = await runShellCommand(interpolationSafeWindowsPath(fullCommand), {
20
28
  env: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/node",
3
- "version": "31.9.1",
3
+ "version": "31.9.3",
4
4
  "description": "A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.",
5
5
  "keywords": [
6
6
  "augment",
@@ -37,29 +37,29 @@
37
37
  "test:update": "npm test"
38
38
  },
39
39
  "dependencies": {
40
- "@augment-vir/assert": "^31.9.1",
41
- "@augment-vir/common": "^31.9.1",
42
- "@date-vir/duration": "^7.1.2",
40
+ "@augment-vir/assert": "^31.9.3",
41
+ "@augment-vir/common": "^31.9.3",
42
+ "@date-vir/duration": "^7.2.1",
43
43
  "ansi-styles": "^6.2.1",
44
44
  "terminate": "^2.8.0",
45
- "tsx": "^4.19.2",
46
- "type-fest": "^4.33.0",
45
+ "tsx": "^4.19.3",
46
+ "type-fest": "^4.37.0",
47
47
  "typed-event-target": "^4.0.2"
48
48
  },
49
49
  "devDependencies": {
50
- "@augment-vir/test": "^31.9.1",
51
- "@prisma/client": "^6.3.0",
52
- "@types/node": "^22.13.0",
53
- "@web/dev-server-esbuild": "^1.0.3",
54
- "@web/test-runner": "^0.19.0",
50
+ "@augment-vir/test": "^31.9.3",
51
+ "@prisma/client": "^6.4.1",
52
+ "@types/node": "^22.13.9",
53
+ "@web/dev-server-esbuild": "^1.0.4",
54
+ "@web/test-runner": "^0.20.0",
55
55
  "@web/test-runner-commands": "^0.9.0",
56
56
  "@web/test-runner-playwright": "^0.11.0",
57
57
  "@web/test-runner-visual-regression": "^0.10.0",
58
58
  "c8": "^10.1.3",
59
59
  "concurrently": "^9.1.2",
60
60
  "istanbul-smart-text-reporter": "^1.1.5",
61
- "prisma": "^6.3.0",
62
- "typescript": "^5.7.2"
61
+ "prisma": "^6.4.1",
62
+ "typescript": "^5.8.2"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "typescript": "*"
@@ -104,13 +104,18 @@ export async function writeDirContents(
104
104
  contents: Readonly<DirContents>,
105
105
  ): Promise<void> {
106
106
  await Promise.all(
107
- getObjectTypedEntries(contents).map(async ([relativePath, content]) => {
108
- const fullPath = join(rootDir, relativePath);
109
- if (check.isString(content)) {
110
- await writeFileAndDir(fullPath, content);
111
- } else {
112
- await writeDirContents(fullPath, content);
113
- }
114
- }),
107
+ getObjectTypedEntries(contents).map(
108
+ async ([
109
+ relativePath,
110
+ content,
111
+ ]) => {
112
+ const fullPath = join(rootDir, relativePath);
113
+ if (check.isString(content)) {
114
+ await writeFileAndDir(fullPath, content);
115
+ } else {
116
+ await writeDirContents(fullPath, content);
117
+ }
118
+ },
119
+ ),
115
120
  );
116
121
  }
@@ -93,7 +93,10 @@ function mapImportPath(
93
93
 
94
94
  const mappedPaths = filterMap(
95
95
  getObjectTypedEntries(paths),
96
- ([alias, paths]) => {
96
+ ([
97
+ alias,
98
+ paths,
99
+ ]) => {
97
100
  const aliasRegex = new RegExp('^' + String(alias).replace(/\*/g, '(.*)') + '$');
98
101
  const match = importPath.match(aliasRegex);
99
102
 
@@ -40,7 +40,13 @@ export type RelevantArgsInput = {
40
40
  *
41
41
  * ```ts
42
42
  * extractRelevantArgs({
43
- * rawArgs: ['npx', 'ts-node', './my-script.ts', 'arg1', '--arg2'], // typically will be process.argv
43
+ * rawArgs: [
44
+ * 'npx',
45
+ * 'ts-node',
46
+ * './my-script.ts',
47
+ * 'arg1',
48
+ * '--arg2',
49
+ * ], // typically will be process.argv
44
50
  * binName: 'my-script', // should be your package.json "bin" property name, can be undefined
45
51
  * fileName: 'my-script.ts', // should be __filename from the script that will be executed
46
52
  * });
@@ -62,7 +62,13 @@ export async function runCliScript(
62
62
  }) || runner.npx;
63
63
 
64
64
  const results = await runShellCommand(
65
- interpolationSafeWindowsPath([runnerPath, scriptPath, ...args].join(' ')),
65
+ interpolationSafeWindowsPath(
66
+ [
67
+ runnerPath,
68
+ scriptPath,
69
+ ...args,
70
+ ].join(' '),
71
+ ),
66
72
  {
67
73
  hookUpToConsole: true,
68
74
  },
@@ -247,7 +247,10 @@ export async function runShellCommand(
247
247
 
248
248
  shellTarget.destroy();
249
249
 
250
- const rejectionErrorMessage: Error = combineErrors([new Error(stderr), ...errors]);
250
+ const rejectionErrorMessage: Error = combineErrors([
251
+ new Error(stderr),
252
+ ...errors,
253
+ ]);
251
254
  /** Reject now because the "done" listener won't get fired after killing the process. */
252
255
  reject(rejectionErrorMessage);
253
256
  });
@@ -109,7 +109,10 @@ export function makeEnvFlags(envMapping?: DockerEnvMap | undefined): string {
109
109
  return '';
110
110
  }
111
111
  const flags: ReadonlyArray<string> = Object.entries(envMapping).map(
112
- ([key, {value, allowInterpolation}]) => {
112
+ ([
113
+ key,
114
+ {value, allowInterpolation},
115
+ ]) => {
113
116
  const quote = allowInterpolation ? '"' : "'";
114
117
  return `-e ${key}=${wrapString({value, wrapper: quote})}`;
115
118
  },
@@ -9,7 +9,10 @@ export async function runMockLongLivingContainer(
9
9
  containerName: containerName,
10
10
  detach: true,
11
11
  imageName: 'alpine:3.20.2',
12
- dockerFlags: ['-i', '-t'],
12
+ dockerFlags: [
13
+ '-i',
14
+ '-t',
15
+ ],
13
16
  command: 'sh',
14
17
  platform: 'amd64',
15
18
  ...args,
@@ -15,7 +15,12 @@ export async function updateImage(
15
15
  const command = [
16
16
  'docker',
17
17
  'pull',
18
- ...(platform ? ['--platform', platform] : []),
18
+ ...(platform
19
+ ? [
20
+ '--platform',
21
+ platform,
22
+ ]
23
+ : []),
19
24
  wrapString({value: imageName, wrapper: "'"}),
20
25
  ].join(' ');
21
26
 
@@ -89,55 +89,68 @@ async function addModelDataObject(
89
89
  data: Record<string, AnyObject>,
90
90
  ) {
91
91
  /** Add the mock data to the mock prisma client. */
92
- await awaitedForEach(getObjectTypedEntries(data), async ([modelName, mockData]) => {
93
- /**
94
- * This type is dumbed down to just `AnyObject[]` because the union of all possible model
95
- * data is just way too big (and not helpful as the inputs to this function are already type
96
- * guarded).
97
- */
98
- const mockModelInstances: AnyObject[] = Array.isArray(mockData)
99
- ? mockData
100
- : getObjectTypedValues(mockData);
101
-
102
- const modelApi: AnyObject | undefined = prismaClient[modelName];
103
-
104
- assert.isDefined(modelApi, `No PrismaClient API found for model '${modelName}'`);
105
-
106
- try {
107
- const allData = filterMap(
108
- mockModelInstances,
109
- (entry) => {
110
- return entry;
111
- },
112
- (mapped, modelEntry) => !modelEntry[prismaModelCreateExclude],
113
- );
114
-
115
- await awaitedForEach(allData, async (modelEntry) => {
116
- if (modelEntry[prismaModelCreateOmitId]) {
117
- modelEntry = omitObjectKeys<AnyObject, PropertyKey>(modelEntry, ['id']);
118
- }
92
+ await awaitedForEach(
93
+ getObjectTypedEntries(data),
94
+ async ([
95
+ modelName,
96
+ mockData,
97
+ ]) => {
98
+ /**
99
+ * This type is dumbed down to just `AnyObject[]` because the union of all possible
100
+ * model data is just way too big (and not helpful as the inputs to this function are
101
+ * already type guarded).
102
+ */
103
+ const mockModelInstances: AnyObject[] = Array.isArray(mockData)
104
+ ? mockData
105
+ : getObjectTypedValues(mockData);
106
+
107
+ const modelApi: AnyObject | undefined = prismaClient[modelName];
108
+
109
+ assert.isDefined(modelApi, `No PrismaClient API found for model '${modelName}'`);
110
+
111
+ try {
112
+ const allData = filterMap(
113
+ mockModelInstances,
114
+ (entry) => {
115
+ return entry;
116
+ },
117
+ (mapped, modelEntry) => !modelEntry[prismaModelCreateExclude],
118
+ );
119
119
 
120
- await modelApi.create({
121
- data: modelEntry,
120
+ await awaitedForEach(allData, async (modelEntry) => {
121
+ if (modelEntry[prismaModelCreateOmitId]) {
122
+ modelEntry = omitObjectKeys<AnyObject, PropertyKey>(modelEntry, ['id']);
123
+ }
124
+
125
+ await modelApi.create({
126
+ data: modelEntry,
127
+ });
122
128
  });
123
- });
124
- } catch (error) {
125
- throw ensureErrorAndPrependMessage(
126
- error,
127
- `Failed to create many '${modelName}' entries.\n\n${JSON.stringify(mockModelInstances, null, 4)}\n\n`,
128
- );
129
- }
130
- });
129
+ } catch (error) {
130
+ throw ensureErrorAndPrependMessage(
131
+ error,
132
+ `Failed to create many '${modelName}' entries.\n\n${JSON.stringify(mockModelInstances, null, 4)}\n\n`,
133
+ );
134
+ }
135
+ },
136
+ );
131
137
  }
132
138
 
133
- const prismockKeys = ['getData', 'setData'];
139
+ const prismockKeys = [
140
+ 'getData',
141
+ 'setData',
142
+ ];
134
143
 
135
144
  export function getAllPrismaModelNames<const PrismaClient extends BasePrismaClient>(
136
145
  prismaClient: PrismaClient,
137
146
  ): PrismaModelName<PrismaClient>[] {
138
147
  return Object.keys(prismaClient)
139
148
  .filter(
140
- (key) => !key.startsWith('$') && !key.startsWith('_') && !prismockKeys.includes(key),
149
+ (key) =>
150
+ !key.startsWith('$') &&
151
+ !key.startsWith('_') &&
152
+ !prismockKeys.includes(key) &&
153
+ key !== 'constructor',
141
154
  )
142
155
  .sort() as PrismaModelName<PrismaClient>[];
143
156
  }
@@ -33,7 +33,12 @@ export async function applyPrismaMigrationsToDev(
33
33
  schemaFilePath: string,
34
34
  env: Record<string, string> = {},
35
35
  ) {
36
- const command = ['prisma', 'migrate', 'dev', `--schema='${schemaFilePath}'`].join(' ');
36
+ const command = [
37
+ 'prisma',
38
+ 'migrate',
39
+ 'dev',
40
+ `--schema='${schemaFilePath}'`,
41
+ ].join(' ');
37
42
 
38
43
  log.faint(`> ${command}`);
39
44
 
@@ -106,7 +111,10 @@ export async function getMigrationStatus(
106
111
  } else if (line.endsWith('not yet been applied:')) {
107
112
  foundNotAppliedMigrations = true;
108
113
  } else {
109
- const [, countMatch] = safeMatch(line, /^([\d,]+) migrations? found in/);
114
+ const [
115
+ ,
116
+ countMatch,
117
+ ] = safeMatch(line, /^([\d,]+) migrations? found in/);
110
118
 
111
119
  if (countMatch) {
112
120
  listedMigrations.totalMigrations = toEnsuredNumber(countMatch);
@@ -19,7 +19,10 @@ export async function runPrismaCommand(
19
19
  env: Record<string, string> | undefined = {},
20
20
  ) {
21
21
  const schemaFileArgs = schemaFilePath
22
- ? ['--schema', wrapString({value: schemaFilePath, wrapper: "'"})]
22
+ ? [
23
+ '--schema',
24
+ wrapString({value: schemaFilePath, wrapper: "'"}),
25
+ ]
23
26
  : [];
24
27
 
25
28
  /** Disable Prisma's in-CLI ads. */
@@ -29,7 +32,12 @@ export async function runPrismaCommand(
29
32
  ? '--no-hints'
30
33
  : '';
31
34
 
32
- const fullCommand = ['prisma', command, ...schemaFileArgs, noHintsArg].join(' ');
35
+ const fullCommand = [
36
+ 'prisma',
37
+ command,
38
+ ...schemaFileArgs,
39
+ noHintsArg,
40
+ ].join(' ');
33
41
 
34
42
  log.faint(`> ${fullCommand}`);
35
43