Skip to content

Migration (v3 to v4)

Λlisue (Ali sue・ありすえ) edited this page Aug 2, 2024 · 4 revisions

Details

  • Use alternative functions of deprecated functions
    • is.RecordLike to is.Record
    • is.RecordLikeOf(...) to is.RecordOf(...)
    • is.ReadonlyTupleOf(...) to is.ReadonlyOf(is.TupleOf(...))
    • is.ReadonlyUniformTupleOf(...) to is.ReadonlyOf(is.UniformTupleOf(...))
    • is.ObjectOf(..., { strict: true }) to is.StrictOf(is.ObjectOf(...))
    • is.OneOf(...) to is.UnionOf(...)
    • is.AllOf(...) to is.IntersectionOf(...)
  • Rename is.BigInt(...) to is.Bigint(...)
  • Rename is.OptionalOf(...) to as.Optional(...)
  • Remove obsolete functions/types
    • isReadonly
    • isUnwrapReadonlyOf
    • getMetadata
    • getPredicateFactoryMetadata
    • setPredicateFactoryMetadata
    • GetMetadata
    • WithMetadata
    • PredicateFactoryMetadata

Migration script

  1. Update jsr:@core/unknownutil@^3.0.0 to jsr:@core/unknownutil@^4.0.0 in import map
  2. Execute the following migration script for simple replacements
import { walk } from "jsr:@std/fs/walk";

const version = "^4.0.0";

function migrate(text: string): string {
  text = text.replace(
    /import(\s+){(.*?)}(\s+)from(\s+)"jsr:@core\/unknownutil@3.*?"/sg,
    `import$1{$2}$3from$4"jsr:@core/unknownutil@${version}"`,
  );
  text = text.replace(/is\.RecordLike/g, "is.Record");
  text = text.replace(/is\.RecordLikeOf\((.*?)\)/sg, "is.RecordOf($1)");
  text = text.replace(
    /is\.ReadonlyTupleOf\((.*?)\)/sg,
    "is.ReadonlyOf(is.Tuple($1))",
  );
  text = text.replace(
    /is\.ReadonlyUniformTupleOf\((.*?)\)/sg,
    "is.ReadonlyOf(is.UniformTuple($1))",
  );
  text = text.replace(/is\.OneOf\((.*?)\)/sg, "is.UnionOf($1)");
  text = text.replace(/is\.AllOf\((.*?)\)/sg, "is.IntersectionOf($1)");
  text = text.replace(/is\.BigInt/g, "is.Bigint");
  text = text.replace(/is\.OptionalOf/g, "as.Optional");

  if (text.includes("as.Optional")) {
    text = text.replace(
      /import(\s+){(.*?)\bis\b(.*?)}(\s+)from/sg,
      "import$1{$2as, is$3}$4from",
    );
  }
  return text;
}

for await (const entry of walk(".")) {
  if (entry.path === import.meta.filename) continue;
  if (entry.isFile && entry.name.endsWith(".ts")) {
    let text = await Deno.readTextFile(entry.path);
    text = migrate(text);
    await Deno.writeTextFile(entry.path, text);
  }
}

Clone this wiki locally