@prisma/orm-mongo 8.0.1-dev.43 → 8.0.1-dev.45

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 (28) hide show
  1. package/dist/{mongo-static-D0gxIAFR-D4Ugp6Ri.mjs → mongo-static-DXgxqad2-EexeYfrg.mjs} +3 -3
  2. package/dist/{mongo-static-D0gxIAFR-D4Ugp6Ri.mjs.map → mongo-static-DXgxqad2-EexeYfrg.mjs.map} +1 -1
  3. package/dist/runtime.mjs +1 -1
  4. package/dist/runtime.mjs.map +1 -1
  5. package/dist/static.mjs +1 -1
  6. package/package.json +12 -12
  7. package/skills/prisma-8/SKILL.md +3 -3
  8. package/skills/prisma-8/references/contract.md +1 -1
  9. package/skills/prisma-8/references/scripts/find-detection-hits.ts +57 -0
  10. package/skills/prisma-8/references/upgrade-app.md +29 -10
  11. package/skills/prisma-8/references/upgrade-extension.md +24 -7
  12. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +139 -42
  13. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +164 -12
  14. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +110 -18
  15. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +28 -6
  16. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +70 -13
  17. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +98 -13
  18. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.26-to-8.0.0-rc.27/instructions.md +102 -0
  19. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.27-to-8.0.0-rc.28/instructions.md +5 -0
  20. package/skills/prisma-8/upgrading/extension/upgrades/0.10-to-0.11/instructions.md +2 -1
  21. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +33 -19
  22. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +164 -12
  23. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +110 -18
  24. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +28 -6
  25. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +70 -13
  26. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +98 -13
  27. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.26-to-8.0.0-rc.27/instructions.md +56 -0
  28. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.27-to-8.0.0-rc.28/instructions.md +5 -0
@@ -4,11 +4,12 @@
4
4
  *
5
5
  * Usage: node platform-paths-an-extension-uses.ts [project-root]
6
6
  *
7
- * The script reads each file with the TypeScript compiler of the project, so the project needs its `typescript` package installed. The project root defaults to the working directory. The script walks it, skipping `node_modules`, `dist`, `build` and directories whose name starts with a dot, and rewrites each `.ts`, `.mts`, `.cts`, `.tsx`, `.js`, `.mjs`, `.cjs` and `.jsx` file in place. It prints each file it changed, then, under `Not changed:`, each import it could not rewrite and each place it wants checked. It works out every file's new text before it writes any, so a run that stops before writing changes no file. If a write fails, it stops, names the file it failed on, which may be partly written, and names the files it did not write. A second run changes nothing.
7
+ * The script reads each file with the TypeScript compiler of the project, so the project needs its `typescript` package installed. The project root defaults to the working directory. The script walks it, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot and, in a git repository, the files and folders git ignores, unless git ignores the project root itself, and rewrites each `.ts`, `.mts`, `.cts`, `.tsx`, `.js`, `.mjs`, `.cjs` and `.jsx` file in place. It prints each file it changed, then, under `Not changed:`, each import it could not rewrite and each place it wants checked. It works out every file's new text before it writes any, so a run that stops before writing changes no file. If a write fails, it stops, names the file it failed on, which may be partly written, and names the files it did not write. A second run changes nothing.
8
8
  */
9
+ import { spawnSync } from 'node:child_process';
9
10
  import { readdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
10
11
  import { createRequire } from 'node:module';
11
- import { join, relative, resolve } from 'node:path';
12
+ import { basename, join, relative, resolve, sep } from 'node:path';
12
13
  import { fileURLToPath, pathToFileURL } from 'node:url';
13
14
  import type * as TS from 'typescript';
14
15
 
@@ -1800,7 +1801,7 @@ export function rewriteWith(
1800
1801
  host,
1801
1802
  });
1802
1803
  if (program.getSourceFile(file.fileName) !== file)
1803
- throw new Error(
1804
+ throw new ScriptStop(
1804
1805
  `TypeScript did not take in ${fileName}, so the script cannot tell a local binding from an import there.`,
1805
1806
  );
1806
1807
  const checker = program.getTypeChecker();
@@ -1917,28 +1918,86 @@ export function rewriteWith(
1917
1918
  return { source: result, left: [...new Set(left)] };
1918
1919
  }
1919
1920
 
1921
+ /** A stop the script expects, such as a missing `typescript`, as against a fault in the script. */
1922
+ class ScriptStop extends Error {}
1923
+
1924
+ function hasCompilerApi(module: unknown): module is TypeScript {
1925
+ return (
1926
+ typeof module === 'object' &&
1927
+ module !== null &&
1928
+ 'createProgram' in module &&
1929
+ typeof module.createProgram === 'function'
1930
+ );
1931
+ }
1932
+
1933
+ function versionOf(module: unknown): string {
1934
+ return typeof module === 'object' &&
1935
+ module !== null &&
1936
+ 'version' in module &&
1937
+ typeof module.version === 'string'
1938
+ ? module.version
1939
+ : 'unknown';
1940
+ }
1941
+
1920
1942
  /** TypeScript's compiler, from the project the script works on, or else from beside the script. */
1921
1943
  export function loadTypeScript(root: string): TypeScript {
1944
+ const withoutCompiler = new Set<string>();
1922
1945
  for (const from of [join(root, 'package.json'), fileURLToPath(import.meta.url)]) {
1946
+ let found: unknown;
1923
1947
  try {
1924
- return createRequire(from)('typescript');
1925
- } catch {}
1948
+ found = createRequire(from)('typescript');
1949
+ } catch {
1950
+ continue;
1951
+ }
1952
+ if (hasCompilerApi(found)) return found;
1953
+ withoutCompiler.add(versionOf(found));
1926
1954
  }
1927
- throw new Error(
1955
+ if (withoutCompiler.size > 0)
1956
+ throw new ScriptStop(
1957
+ `This script reads code with the TypeScript compiler, and the \`typescript\` package it found, version ${[...withoutCompiler].join(' and ')}, has no compiler: the \`typescript\` package of TypeScript 7 exports only its version. The script needs TypeScript 5 or 6. There are two ways to give it one. The first changes nothing in the project: make an empty folder outside the project, write a \`package.json\` in it that holds \`{"type": "module"}\`, run \`pnpm add typescript@5\` in that folder, copy this script into it, and run the copy with the project folder as its argument: \`node <folder>/${basename(fileURLToPath(import.meta.url))} <project folder>\`. Without that \`package.json\`, Node prints a \`MODULE_TYPELESS_PACKAGE_JSON\` warning, which is harmless. The second installs TypeScript 5 in the project for the run: \`pnpm add -D typescript@5\`, with \`-w\` added at the root of a pnpm workspace. It changes \`package.json\` and the lockfile, so after the run put back the \`typescript\` version you had, with \`pnpm add -D typescript@<your version>\` (with \`-w\` again where you used it), or \`pnpm remove typescript\` if the project had none; do not use \`git checkout\` on those files, which would also undo the other uncommitted changes the upgrade made to them.`,
1958
+ );
1959
+ throw new ScriptStop(
1928
1960
  'This script reads code with TypeScript, and found no `typescript` package in the project or beside the script. Prisma lists `typescript` as an optional peer dependency, so the project may not have it: install it in the project, for example as a development dependency, then run the script again.',
1929
1961
  );
1930
1962
  }
1931
1963
 
1964
+ function stopMessage(error: unknown): string {
1965
+ if (error instanceof ScriptStop) return `${error.message}\nThe script changed no file.`;
1966
+ const detail = error instanceof Error ? (error.stack ?? error.message) : String(error);
1967
+ return `The script failed on an unexpected error, before it changed any file. This is a fault in the script; report it to Prisma with this output:\n${detail}`;
1968
+ }
1969
+
1932
1970
  const SKIPPED_DIRECTORIES = new Set(['node_modules', 'dist', 'build']);
1933
1971
  const SOURCE_FILE = /\.(ts|mts|cts|tsx|js|mjs|cjs|jsx)$/;
1934
1972
 
1935
- function* sourceFiles(dir: string): Generator<string> {
1973
+ /** A test of whether git ignores a file or folder under `root`. Outside a git repository it ignores nothing, and so it does when git ignores `root` itself, which the user then named on purpose. */
1974
+ function gitIgnores(root: string): (path: string) => boolean {
1975
+ const listed = spawnSync(
1976
+ 'git',
1977
+ ['ls-files', '--others', '--ignored', '--exclude-standard', '--directory', '-z'],
1978
+ { cwd: root, encoding: 'utf8', maxBuffer: 2 ** 30 },
1979
+ );
1980
+ if (listed.status !== 0) return () => false;
1981
+ const ignored = new Set(
1982
+ listed.stdout
1983
+ .split('\0')
1984
+ .filter((path) => path !== '')
1985
+ .map((path) => path.replace(/\/$/, '')),
1986
+ );
1987
+ if (ignored.has('.')) return () => false;
1988
+ const bases = [root, realpathSync(root)];
1989
+ return (path) => bases.some((base) => ignored.has(relative(base, path).split(sep).join('/')));
1990
+ }
1991
+
1992
+ function* sourceFiles(dir: string, ignored: (path: string) => boolean): Generator<string> {
1936
1993
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
1994
+ const path = join(dir, entry.name);
1995
+ if (ignored(path)) continue;
1937
1996
  if (entry.isDirectory()) {
1938
1997
  if (SKIPPED_DIRECTORIES.has(entry.name) || entry.name.startsWith('.')) continue;
1939
- yield* sourceFiles(join(dir, entry.name));
1998
+ yield* sourceFiles(path, ignored);
1940
1999
  } else if (entry.isFile() && SOURCE_FILE.test(entry.name)) {
1941
- yield join(dir, entry.name);
2000
+ yield path;
1942
2001
  }
1943
2002
  }
1944
2003
  }
@@ -1950,16 +2009,14 @@ function main(): void {
1950
2009
  try {
1951
2010
  const ts = loadTypeScript(root);
1952
2011
  const database = databaseOf(root);
1953
- for (const file of sourceFiles(root)) {
2012
+ for (const file of sourceFiles(root, gitIgnores(root))) {
1954
2013
  const source = readFileSync(file, 'utf8');
1955
2014
  const { source: rewritten, left } = rewriteWith(ts, file, source, database);
1956
2015
  for (const entry of left) leftovers.push(`${relative(root, file)}: ${entry}`);
1957
2016
  if (rewritten !== source) changes.push([file, rewritten]);
1958
2017
  }
1959
2018
  } catch (error) {
1960
- console.error(
1961
- `${error instanceof Error ? error.message : String(error)}\nThe script changed no file.`,
1962
- );
2019
+ console.error(stopMessage(error));
1963
2020
  process.exitCode = 1;
1964
2021
  return;
1965
2022
  }
@@ -4,12 +4,13 @@
4
4
  *
5
5
  * Usage: node stored-files-format-version.ts [project-root]
6
6
  *
7
- * The project root defaults to the working directory. The script walks it, skipping `node_modules`, `dist`, `build` and directories whose name starts with a dot. It recognises a contract by its content (`targetFamily`, `storage` and `schemaVersion` at the top level) in any `*.json` file, a `migration.json` by its fields and by the `ops.json` next to it, and a ref file by where Prisma writes refs or by its content. Every `*.json` file in `<migrations>/<space>/refs/` (in an application) or `<migrations>/refs/` (in an extension's own repository) is a ref, where a migrations directory is one holding the contract snapshot store (`snapshots/<hash>/contract.json`) or a migration package, whatever it is named. A `*.json` file in any other `refs` directory is a ref when its content is one: a `hash` that is `empty` or a storage hash, and an `invariants` list of strings. This finds the refs of a space with no migrations after `snapshots/` was deleted. Any other JSON file in a `refs` directory is not Prisma's and is left alone. It edits each file's text in place, so the rest of the file keeps its bytes: the version goes first, except in a contract whose top-level keys are sorted (a snapshot), where it goes in sorted position, as Prisma writes them. No hash covers the version, so no hash changes.
7
+ * The project root defaults to the working directory. The script walks it, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot and, in a git repository, the files and folders git ignores, unless git ignores the project root itself. It walks a migrations folder (one holding the contract snapshot store, a migration package or a ref file, directly or in a space folder) and what is in it even when git ignores them, since nothing else writes those files again. It recognises a contract by its content (`targetFamily`, `storage` and `schemaVersion` at the top level) in any `*.json` file, a `migration.json` by its fields and by the `ops.json` next to it, and a ref file by where Prisma writes refs or by its content. Every `*.json` file in `<migrations>/<space>/refs/` (in an application) or `<migrations>/refs/` (in an extension's own repository) is a ref, where a migrations directory is one holding the contract snapshot store (`snapshots/<hash>/contract.json`) or a migration package, whatever it is named. A `*.json` file in any other `refs` directory is a ref when its content is one: a `hash` that is `empty` or a storage hash, and an `invariants` list of strings. This finds the refs of a space with no migrations after `snapshots/` was deleted. Any other JSON file in a `refs` directory is not Prisma's and is left alone. It edits each file's text in place, so the rest of the file keeps its bytes: the version goes first, except in a contract whose top-level keys are sorted (a snapshot), where it goes in sorted position, as Prisma writes them. No hash covers the version, so no hash changes.
8
8
  *
9
9
  * A ref file may have fields the format does not have; earlier releases ignored them when they read a ref and dropped them when they wrote one again. The script drops them too, and lists each one it dropped.
10
10
  *
11
- * It prints each file it changed. These are reported, left unchanged, and make it exit 1, while it still changes every other file: a `contract.json`, `migration.json` or ref file it cannot read or parse; a ref file or `migration.json` whose content is not one that a release of Prisma read (a missing or extra field, or a value of the wrong type); a contract with both `formatVersion` and `schemaVersion`, or a `contract.json` holding a contract with neither; a contract whose `schemaVersion` is not `"1"`; a stored file whose `formatVersion` is not `1`; a directory it cannot list; and a symbolic link, to a file or folder outside the project root or inside it where the walk skips, that holds a stored file it would change or report, or a link inside the root to a place the walk reads as another kind of file than at the link, since it does not follow links. A second run changes nothing.
11
+ * It checks every file before it writes any. If it finds any of these, it changes no file, lists them and exits 1: a `contract.json`, `migration.json` or ref file it cannot read or parse; a ref file or `migration.json` whose content is not one that a release of Prisma read (a missing or extra field, or a value of the wrong type); a contract with both `formatVersion` and `schemaVersion`, or a `contract.json` holding a contract with neither; a contract whose `schemaVersion` is not `"1"`; a stored file whose `formatVersion` is not `1`; a directory it cannot list; and a symbolic link, to a file or folder outside the project root or inside it where the walk skips, that holds a stored file it would change or report, or a link inside the root to a place the walk reads as another kind of file than at the link, since it does not follow links. Otherwise it prints each file it changed, and a second run changes nothing.
12
12
  */
13
+ import { spawnSync } from 'node:child_process';
13
14
  import {
14
15
  chmodSync,
15
16
  type Dirent,
@@ -458,6 +459,79 @@ function isWalked(name: string): boolean {
458
459
  return !SKIPPED_DIRECTORIES.has(name) && !name.startsWith('.');
459
460
  }
460
461
 
462
+ let ignoredByGit: (path: string) => boolean = () => false;
463
+
464
+ /** A test of whether git ignores a file or folder under `root`. Outside a git repository it ignores nothing, and so it does when git ignores `root` itself, which the user then named on purpose. */
465
+ function gitIgnores(root: string): (path: string) => boolean {
466
+ const listed = spawnSync(
467
+ 'git',
468
+ ['ls-files', '--others', '--ignored', '--exclude-standard', '--directory', '-z'],
469
+ { cwd: root, encoding: 'utf8', maxBuffer: 2 ** 30 },
470
+ );
471
+ if (listed.status !== 0) return () => false;
472
+ const ignored = new Set(
473
+ listed.stdout
474
+ .split('\0')
475
+ .filter((path) => path !== '')
476
+ .map((path) => path.replace(/\/$/, '')),
477
+ );
478
+ if (ignored.has('.')) return () => false;
479
+ const bases = [root, realpathSync(root)];
480
+ return (path) =>
481
+ bases.some((base) => ignored.has(relative(base, path).split(sep).join('/'))) &&
482
+ !isInMigrationsFolder(bases, path);
483
+ }
484
+
485
+ function readsAsRef(path: string): boolean {
486
+ try {
487
+ const value: unknown = JSON.parse(readFileSync(path, 'utf8').replace(/^\uFEFF/, ''));
488
+ return isRecord(value) && hasRefContent(value);
489
+ } catch {
490
+ return false;
491
+ }
492
+ }
493
+
494
+ /** Whether `dir` holds what Prisma writes to a migrations directory or to one of its spaces: the contract snapshot store, a migration package or a ref file. */
495
+ function holdsMigrationFiles(dir: string): boolean {
496
+ return isMigrationsDirectory(dir) || holdsRef(dir);
497
+ }
498
+
499
+ function holdsRef(dir: string): boolean {
500
+ const refs = join(dir, 'refs');
501
+ const entries = listDirectory(refs);
502
+ return (
503
+ typeof entries !== 'string' &&
504
+ entries.some((entry) => entry.isFile() && readsAsRef(join(refs, entry.name)))
505
+ );
506
+ }
507
+
508
+ /** Whether `dir` holds what Prisma writes to a space of a migrations directory: a migration package or a ref file. The snapshot store sits beside the spaces, never in one. */
509
+ function holdsSpaceFiles(dir: string): boolean {
510
+ return hasSubdirectory(dir, isMigrationPackage) || holdsRef(dir);
511
+ }
512
+
513
+ function isMigrationsFolder(dir: string): boolean {
514
+ return (
515
+ holdsMigrationFiles(dir) ||
516
+ hasSubdirectory(dir, (path, name) => SPACE_ID.test(name) && holdsSpaceFiles(path))
517
+ );
518
+ }
519
+
520
+ /** Whether `path`, or a folder it is in below the project root, is a migrations folder, whose files the script upgrades even when git ignores them: nothing else writes them again. */
521
+ function isInMigrationsFolder(bases: readonly string[], path: string): boolean {
522
+ for (let dir = path; !bases.includes(dir) && dir !== dirname(dir); dir = dirname(dir))
523
+ if (isDirectory(dir) && isMigrationsFolder(dir)) return true;
524
+ return false;
525
+ }
526
+
527
+ /** Whether the walk from `realRoot` reaches `target`. */
528
+ function isReached(realRoot: string, target: string): boolean {
529
+ const names = relative(realRoot, target).split(sep);
530
+ return names.every(
531
+ (name, index) => isWalked(name) && !ignoredByGit(join(realRoot, ...names.slice(0, index + 1))),
532
+ );
533
+ }
534
+
461
535
  function isInside(dir: string, path: string): boolean {
462
536
  return path === dir || path.startsWith(`${dir}${sep}`);
463
537
  }
@@ -476,8 +550,7 @@ function handleLink(root: string, path: string, name: string, outcome: Outcome):
476
550
  if (isInside(target, realRoot)) return;
477
551
  const inside = isInside(realRoot, target);
478
552
  const reached =
479
- relative(realRoot, target).split(sep).every(isWalked) &&
480
- (statSync(target).isDirectory() || target.endsWith('.json'));
553
+ isReached(realRoot, target) && (statSync(target).isDirectory() || target.endsWith('.json'));
481
554
  const shown = relative(root, path);
482
555
  const targetShown = relative(realRoot, target);
483
556
  if (inside && reached) {
@@ -491,7 +564,7 @@ function handleLink(root: string, path: string, name: string, outcome: Outcome):
491
564
  const isDirectory = statSync(target).isDirectory();
492
565
  if (isDirectory) {
493
566
  if (!isWalked(name)) return;
494
- visit(root, path, probe, false);
567
+ visit(root, path, probe, 'probe');
495
568
  } else if (name.endsWith('.json')) {
496
569
  handleFile(root, path, probe, false);
497
570
  }
@@ -517,8 +590,8 @@ function readsAlike(
517
590
  const atTarget = emptyOutcome();
518
591
  if (statSync(target).isDirectory()) {
519
592
  if (!isWalked(name)) return true;
520
- visit(root, path, atLink, false);
521
- visit(realRoot, target, atTarget, false);
593
+ visit(root, path, atLink, 'probe');
594
+ visit(realRoot, target, atTarget, 'probe');
522
595
  } else if (name.endsWith('.json')) {
523
596
  handleFile(root, path, atLink, false);
524
597
  handleFile(realRoot, target, atTarget, false);
@@ -530,8 +603,10 @@ function readsAlike(
530
603
  return JSON.stringify(seen(atLink, linkShown)) === JSON.stringify(seen(atTarget, targetShown));
531
604
  }
532
605
 
533
- /** Walks `dir`, rewriting stored files, or, when `write` is false, only recording what it would do. A walk that only records follows no link. */
534
- function visit(root: string, dir: string, outcome: Outcome, write = true): void {
606
+ /** How a walk handles what it finds: `write` rewrites stored files and reports links; `check` only records what `write` would do; `probe` records it too, but does not look at links, which a walk started from a link would otherwise follow in a loop. */
607
+ type Walk = 'write' | 'check' | 'probe';
608
+
609
+ function visit(root: string, dir: string, outcome: Outcome, walk: Walk): void {
535
610
  const entries = listDirectory(dir);
536
611
  if (typeof entries === 'string') {
537
612
  outcome.problems.push(`${relative(root, dir) || '.'}: directory cannot be read (${entries})`);
@@ -539,11 +614,12 @@ function visit(root: string, dir: string, outcome: Outcome, write = true): void
539
614
  }
540
615
  for (const entry of entries) {
541
616
  const path = join(dir, entry.name);
617
+ if (ignoredByGit(path)) continue;
542
618
  if (entry.isDirectory()) {
543
- if (isWalked(entry.name)) visit(root, path, outcome, write);
619
+ if (isWalked(entry.name)) visit(root, path, outcome, walk);
544
620
  } else if (entry.isFile() && entry.name.endsWith('.json')) {
545
- handleFile(root, path, outcome, write);
546
- } else if (entry.isSymbolicLink() && write) {
621
+ handleFile(root, path, outcome, walk === 'write');
622
+ } else if (entry.isSymbolicLink() && walk !== 'probe') {
547
623
  handleLink(root, path, entry.name, outcome);
548
624
  }
549
625
  }
@@ -559,8 +635,17 @@ function main(args: readonly string[]): number {
559
635
  process.stderr.write(`${root}: not a directory\n`);
560
636
  return 1;
561
637
  }
638
+ ignoredByGit = gitIgnores(root);
639
+ const check = emptyOutcome();
640
+ visit(root, root, check, 'check');
641
+ if (check.problems.length > 0) {
642
+ process.stderr.write(
643
+ `Changed no file, because:\n${check.problems.map((problem) => ` ${problem}\n`).join('')}`,
644
+ );
645
+ return 1;
646
+ }
562
647
  const outcome = emptyOutcome();
563
- visit(root, root, outcome);
648
+ visit(root, root, outcome, 'write');
564
649
  if (outcome.changed.length > 0) {
565
650
  const files = outcome.changed.length === 1 ? 'file' : 'files';
566
651
  process.stdout.write(
@@ -0,0 +1,102 @@
1
+ ---
2
+ from: "8.0.0-rc.26"
3
+ to: "8.0.0-rc.27"
4
+ changes:
5
+ - id: app-snapshot-gets-emitted-profile
6
+ summary: |
7
+ `prisma contract emit` now gives the snapshot of the emitted contract (`migrations/snapshots/<hash>/`, under the emitted storage hash) the emitted contract's required capabilities and profile hash when it holds others, and reports the snapshot it rewrote. In 8.0.0-rc.26 that snapshot kept the capabilities it was planned with, so a database that `prisma db migrate --to <ref>` created from it, as every Composer deploy does, failed `prisma db verify` with `CONTRACT.SIGNATURE_MISMATCH` ("signed for other capabilities"). Run `prisma contract emit` once and commit the snapshot it rewrites; sign each database created since the upgrade to 8.0.0-rc.26 with `prisma db sign --no-advance-ref`.
8
+ - id: boolean-codec-type-takes-codec-types
9
+ summary: |
10
+ `BooleanCodecType` takes the contract's codec types, as `BooleanCodecType<CodecTypes>`; a use without type arguments no longer compiles.
11
+ detection:
12
+ glob: "**/*.{ts,tsx,mts,cts}"
13
+ matches:
14
+ - '(?<!\b(?:import|export)\s+(?:type\s+)?\{[^}]*)\bBooleanCodecType\b(?!\s*<)'
15
+ - id: function-condition-takes-codec-types
16
+ summary: |
17
+ `FunctionCondition` from the ORM client takes the contract's codec types; a use without type arguments no longer compiles.
18
+ detection:
19
+ glob: "**/*.{ts,tsx,mts,cts}"
20
+ matches:
21
+ - '(?<!\b(?:import|export)\s+(?:type\s+)?\{[^}]*)\bFunctionCondition\b(?!\s*<)'
22
+ - id: condition-codec-on-mysql-and-sqlite
23
+ summary: |
24
+ Only for a MySQL, MariaDB or SQLite project: a PostgreSQL project changes nothing here, although the detection matches `pg/bool@1` in many of its files, such as the `contract.d.ts` of a contract with a boolean field, and its snapshots. On MySQL, MariaDB and SQLite a condition from `fns` is an expression of the target's boolean codec, `mysql/boolean@1` or `sqlite/boolean@1`, not `pg/bool@1`.
25
+ detection:
26
+ glob: "**/*.{ts,tsx,mts,cts}"
27
+ matches:
28
+ - 'pg\/bool@1'
29
+ - id: projected-condition-reads-as-boolean
30
+ summary: |
31
+ On MySQL, MariaDB and SQLite a condition selected as a column reads as a boolean, or `null` when its value is NULL, where it read as the text `'1'` or `'0'` on MySQL and MariaDB and as the number `1` or `0` on SQLite; on every target its row type is `boolean` without `null` when no operand is nullable.
32
+ - id: functions-builders-no-longer-published
33
+ summary: |
34
+ `createFunctions` and `createAggregateFunctions` are no longer published; a callback of the query builder receives the functions they built as its `fns` argument, and a callback of the ORM receives the ORM's functions, built from `createFunctions`.
35
+ detection:
36
+ glob: "**/*.{ts,tsx,mts,cts}"
37
+ matches:
38
+ - '\bcreate(?:Aggregate)?Functions\b'
39
+ ---
40
+
41
+ # The snapshot of the emitted contract gets its capabilities
42
+
43
+ ## `app-snapshot-gets-emitted-profile`
44
+
45
+ `db migrate --to <ref>` signs the database with the profile hash of the ref's contract snapshot, in `migrations/snapshots/<hash>/`. The profile hash covers the capabilities the contract requires. 8.0.0-rc.26 added `conn.interactiveTransactions` to the capabilities a PostgreSQL contract requires, which changed the emitted profile hash but not the storage hash, so the snapshot of the current contract kept the old list and the old profile hash. A database that `db migrate --to <ref>` created from that snapshot was signed with the old profile hash, and `db verify` failed with `CONTRACT.SIGNATURE_MISMATCH`: "The database is signed for other capabilities". `db migrate` without `--to`, or with `--to @contract`, was not affected.
46
+
47
+ `contract emit` now updates the `requiredCapabilities` and `profileHash` in that snapshot's `contract.json` when they differ from the emitted contract's, changes nothing else in it, and writes the snapshot's `contract.d.ts` again from it. Its output names the snapshot, and its `--json` output has it under `rewrittenSnapshot`. The Vite plugin's emit does not update the snapshot; run `prisma contract emit`.
48
+
49
+ 1. Run `prisma contract emit` in each Prisma project folder. If the output reports an updated snapshot, commit the files under `migrations/snapshots/` that it changed. If it reports none, it changed no snapshot file, and there is nothing to commit for this step.
50
+ 2. This step is only for an application that was on 8.0.0-rc.26 and created databases on it. List each database that `prisma db migrate --to <ref>` or a Composer deploy created after the upgrade to 8.0.0-rc.26: new environments, preview and pull request databases, and demo databases. Run `prisma db verify --db <url>` against each. A database that fails with `CONTRACT.SIGNATURE_MISMATCH` and "The database is signed for other capabilities" was signed with the old profile hash. Sign it again with the emitted contract:
51
+
52
+ ```bash
53
+ prisma db sign --db <url> --no-advance-ref
54
+ ```
55
+
56
+ `db sign` checks the database's schema against the emitted contract before it signs, so run it only once the database is at the contract you emitted. If it refuses because the database's change policy allows only migrations, add `--force`; the schema is still checked and the policies are kept.
57
+
58
+ # Conditions from `fns` carry the contract's boolean codec
59
+
60
+ ## `boolean-codec-type-takes-codec-types`
61
+
62
+ `BooleanCodecType`, exported by `@prisma/orm-family-sql/builder/types`, now takes the contract's codec types and, optionally, a nullability. Pass the `CodecTypes` of the contract's `contract.d.ts`:
63
+
64
+ ```ts
65
+ import type { CodecTypes } from './prisma/contract';
66
+
67
+ expectTypeOf(condition).toExtend<Expression<BooleanCodecType<CodecTypes>>>();
68
+ ```
69
+
70
+ ## `function-condition-takes-codec-types`
71
+
72
+ `FunctionCondition`, exported by `@prisma/orm-family-sql/orm-client`, takes the contract's codec types the same way: `FunctionCondition<CodecTypes>`. It also takes a nullability as a second argument.
73
+
74
+ ## `condition-codec-on-mysql-and-sqlite`
75
+
76
+ This change is only for a MySQL, MariaDB or SQLite project. On PostgreSQL, leave every `pg/bool@1` as it is, even in the files the detection lists.
77
+
78
+ On MySQL, MariaDB and SQLite, a condition such as `fns.eq(...)` or `fns.and(...)` is typed with the target's boolean codec: `mysql/boolean@1` on MySQL and MariaDB, `sqlite/boolean@1` on SQLite. Where code on these targets names `'pg/bool@1'` for a condition, replace it with the target's boolean codec id, `'mysql/boolean@1'` or `'sqlite/boolean@1'`. This covers a type annotation such as `Expression<{ codecId: 'pg/bool@1'; nullable: boolean }>`, and `fns.raw` with `.returns('pg/bool@1')` used as the result of `where` or as an operand of `fns.and` or `fns.or`. A boolean column is now accepted wherever a condition is, so a `fns.raw` that only wrapped a boolean column can be replaced by the column.
79
+
80
+ ## `projected-condition-reads-as-boolean`
81
+
82
+ On MySQL, MariaDB and SQLite, a condition selected as a column, such as `select('isAdmin', (f, fns) => fns.eq(f.role, 'ADMIN'))`, now reads as `true` or `false`, or as `null` when one of its operands is nullable and its value is NULL. Before, it read as the text `'1'` or `'0'` on MySQL and MariaDB, and as the number `1` or `0` on SQLite. Find the code that reads such a value and use it as a boolean:
83
+
84
+ - On MySQL and MariaDB, look for comparisons with `'1'` or `'0'`, such as `row.isAdmin === '1'`, and conversions such as `Number(row.isAdmin)`. `Boolean(row.isAdmin)` was `true` for `'0'` as well, so code that used it was wrong before and is right now.
85
+ - On SQLite, look for comparisons with `1` or `0`, such as `row.isAdmin === 1`, and conversions such as `Boolean(row.isAdmin)` or `Number(row.isAdmin)`.
86
+
87
+ On Postgres the value does not change.
88
+
89
+ On every target, the row type of a selected condition is `boolean` without `null` when none of its operands is nullable. A type annotation that spells `boolean | null` for such a column still compiles; narrow it to `boolean` where the code no longer needs to handle `null`.
90
+
91
+ ## `functions-builders-no-longer-published`
92
+
93
+ `@prisma/orm-family-sql/builder/runtime` no longer exports `createFunctions` and `createAggregateFunctions`, and no other published path exports them. They built the functions that a callback of the query builder receives as its `fns` argument, and the ORM builds the `fns` of its callbacks from `createFunctions`, so code that called them takes `fns` from such a callback instead:
94
+
95
+ ```ts
96
+ // The query builder: the second argument of an expression callback, such as where, select, a join's on, orderBy, groupBy, having or the set of an update.
97
+ db.sql.public.user.select('id').where((f, fns) => fns.eq(f.id, 1));
98
+ // The ORM: the fns member of the second argument of a where or orderBy callback.
99
+ db.orm.public.User.where((user, { fns }) => fns.eq(user.id, 1));
100
+ ```
101
+
102
+ Code that called them to build a condition outside a query, such as in a test, builds a query with the query builder instead and reads the condition from the plan's syntax tree, such as the `where` of `db.sql.public.user.select('id').where((f, fns) => fns.eq(f.id, 1)).build().ast` after checking that its `kind` is `'select'`. That is a syntax-tree node, not the expression `createFunctions` returned.
@@ -0,0 +1,5 @@
1
+ ---
2
+ from: "8.0.0-rc.27"
3
+ to: "8.0.0-rc.28"
4
+ changes: []
5
+ ---
@@ -3,7 +3,8 @@ from: "0.10"
3
3
  to: "0.11"
4
4
  changes:
5
5
  - id: namespace-kind-required-on-handcrafted-contract-literals
6
- summary: Add the `kind` discriminator (`'sql-namespace'` for SQL namespaces; `'mongo-namespace'` for Mongo namespaces) to every handcrafted `Contract<{ namespaces: { ... } }>` type literal in extension test-d files and inline-typed fixtures. The framework `Namespace` interface tightened `kind` from optional to required; emitted `contract.d.ts` literals carry it automatically, but anything you write by hand will fail typecheck without it.
6
+ summary: |
7
+ Add the `kind` discriminator (`'sql-namespace'` for SQL namespaces; `'mongo-namespace'` for Mongo namespaces) to every handcrafted `Contract<{ namespaces: { ... } }>` type literal in extension test-d files and inline-typed fixtures. The framework `Namespace` interface tightened `kind` from optional to required; emitted `contract.d.ts` literals carry it automatically, but anything you write by hand will fail typecheck without it.
7
8
  detection:
8
9
  glob: "**/*.test-d.ts"
9
10
  contains: