From acd9e85bb87f286b7819e0d6dbe3d5b88f9382ae Mon Sep 17 00:00:00 2001 From: Jesse Kelly Date: Tue, 3 Oct 2023 13:11:33 +0100 Subject: [PATCH] chore: updated effect --- .changeset/lucky-readers-call.md | 5 ++ package.json | 7 ++- pnpm-lock.yaml | 66 ++++++++++---------------- src/common.ts | 22 ++------- src/empty.ts | 4 +- src/equivalence.ts | 8 ++-- src/faker.ts | 9 ++-- src/jsonSchema.ts | 6 +-- src/semigroup.ts | 4 +- tests/empty.test.ts | 11 ++--- tests/equivalence.test.ts | 4 +- tests/faker.test.ts | 11 +++-- tests/jsonSchema.test.ts | 2 +- tests/printer.test.ts | 80 -------------------------------- tests/semigroup.test.ts | 4 +- 15 files changed, 66 insertions(+), 177 deletions(-) create mode 100644 .changeset/lucky-readers-call.md delete mode 100644 tests/printer.test.ts diff --git a/.changeset/lucky-readers-call.md b/.changeset/lucky-readers-call.md new file mode 100644 index 0000000..2b40cb9 --- /dev/null +++ b/.changeset/lucky-readers-call.md @@ -0,0 +1,5 @@ +--- +"effect-schema-compilers": patch +--- + +updated effect packages diff --git a/package.json b/package.json index 84a7303..cacb7be 100644 --- a/package.json +++ b/package.json @@ -40,12 +40,11 @@ "vitest": "^0.29.3" }, "dependencies": { - "@effect/data": "^0.17.5", - "@effect/io": "^0.38.2", "@effect/printer": "^0.13.0", - "@effect/schema": "^0.33.1", + "@effect/schema": "^0.39.2", "@effect/typeclass": "^0.3.0", - "fast-check": "^3.11.0", + "effect": "2.0.0-next.42", + "fast-check": "^3.13.1", "typescript": "^5.0.4" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6c50199..9611ad1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,28 +1,21 @@ lockfileVersion: '6.0' -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false - dependencies: - '@effect/data': - specifier: ^0.17.5 - version: 0.17.5 - '@effect/io': - specifier: ^0.38.2 - version: 0.38.2(@effect/data@0.17.5) '@effect/printer': specifier: ^0.13.0 - version: 0.13.0(@effect/data@0.17.5)(@effect/io@0.38.2)(@effect/typeclass@0.3.0) + version: 0.13.0(@effect/typeclass@0.3.0) '@effect/schema': - specifier: ^0.33.1 - version: 0.33.1(@effect/data@0.17.5)(@effect/io@0.38.2) + specifier: ^0.39.2 + version: 0.39.2(effect@2.0.0-next.42) '@effect/typeclass': specifier: ^0.3.0 version: 0.3.0 + effect: + specifier: 2.0.0-next.42 + version: 2.0.0-next.42 fast-check: - specifier: ^3.11.0 - version: 3.11.0 + specifier: ^3.13.1 + version: 3.13.1 typescript: specifier: ^5.0.4 version: 5.0.4 @@ -276,35 +269,23 @@ packages: resolution: {integrity: sha512-D6hYM+IReoM6YR8okIS5dygcUDdXR+De3O2b8SHwenE0PRQrGnZ9O6kJFeqkkX6pIZwEWBnb1l9SKOrw7auI4A==} dev: false - /@effect/io@0.38.2(@effect/data@0.17.5): - resolution: {integrity: sha512-rnAXFo9BDLbY7DgQE1e8uP/sEniyVCsB7gNs+yXPu0XK9s4kaGinH6XgwYRDBuu7Fu1tQ1yd7JoAdEb7yutNRg==} - peerDependencies: - '@effect/data': ^0.17.1 - dependencies: - '@effect/data': 0.17.5 - dev: false - - /@effect/printer@0.13.0(@effect/data@0.17.5)(@effect/io@0.38.2)(@effect/typeclass@0.3.0): + /@effect/printer@0.13.0(@effect/typeclass@0.3.0): resolution: {integrity: sha512-vqKilbg36AEHZJNj9fiV6qUALojR2kVePKbuJJAkaGQao9Duc6rL3QSbaGEaEzar6v68j6TGTOndg/inI2bQFA==} peerDependencies: '@effect/data': ~0.17.1 '@effect/io': ~0.38.0 '@effect/typeclass': ~0.3.0 dependencies: - '@effect/data': 0.17.5 - '@effect/io': 0.38.2(@effect/data@0.17.5) '@effect/typeclass': 0.3.0 dev: false - /@effect/schema@0.33.1(@effect/data@0.17.5)(@effect/io@0.38.2): - resolution: {integrity: sha512-h+fQInui4q3we8fegAygL0Cs5B2DD/+oC3JWthOh8eLcbKkbYM9smCD/PsHuyQ+BaeWiSP5JdvREGlP4Sg+Ysw==} + /@effect/schema@0.39.2(effect@2.0.0-next.42): + resolution: {integrity: sha512-UolykyRtrg+JHflZBfHK2p+w8IgP8u6kSkTq9VIggure12/2CFvlib9vphw4fJCN8cRd3gZo4LevU4FfS+ZLxw==} peerDependencies: - '@effect/data': ^0.17.1 - '@effect/io': ^0.38.0 + effect: ^2.0.0-next.39 dependencies: - '@effect/data': 0.17.5 - '@effect/io': 0.38.2(@effect/data@0.17.5) - fast-check: 3.12.0 + effect: 2.0.0-next.42 + fast-check: 3.13.1 dev: false /@effect/typeclass@0.3.0: @@ -1618,6 +1599,10 @@ packages: safer-buffer: 2.1.2 dev: true + /effect@2.0.0-next.42: + resolution: {integrity: sha512-ydeSVYDmX70CPyUmZ12SNEQZrzynBmzmxm8An4kl3Bpw8GPbZhkpjb0z41+6vBKiuIAhko3icspLy71qIAytEA==} + dev: false + /emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} dev: true @@ -1959,15 +1944,8 @@ packages: engines: {'0': node >=0.6.0} dev: true - /fast-check@3.11.0: - resolution: {integrity: sha512-H2tctb7AGfFQfz+DEr3UWhJ3s47LXsGp5g3jeJr5tHjnf4xUvpArIqiwcDmL2EXiv+auLHIpF5MqaIpIKvpxiA==} - engines: {node: '>=8.0.0'} - dependencies: - pure-rand: 6.0.2 - dev: false - - /fast-check@3.12.0: - resolution: {integrity: sha512-SqahE9mlL3+lhjJ39joMLwcj6F+24hfZdf/tchlNO8sHcTdrUUdA5P/ZbSFZM9Xpzs36XaneGwE0FWepm/zyOA==} + /fast-check@3.13.1: + resolution: {integrity: sha512-Xp00tFuWd83i8rbG/4wU54qU+yINjQha7bXH2N4ARNTkyOimzHtUBJ5+htpdXk7RMaCOD/j2jxSjEt9u9ZPNeQ==} engines: {node: '>=8.0.0'} dependencies: pure-rand: 6.0.2 @@ -4676,3 +4654,7 @@ packages: dev: true publishDirectory: dist + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false diff --git a/src/common.ts b/src/common.ts index 20f66c0..6d1bac9 100644 --- a/src/common.ts +++ b/src/common.ts @@ -1,8 +1,8 @@ import * as AST from "@effect/schema/AST" import * as S from "@effect/schema/Schema" -import { isNumber } from "@effect/data/Predicate" +import { isNumber } from "effect/Predicate" -export const createHookId = (id: I) => `effect-schema-compilers/${id}` as const +export const createHookId = (id: string) => Symbol(`effect-schema-compilers/${id}`) /** * TODO: Replace with import from "@effect/schema/internal/common" when working @@ -87,14 +87,6 @@ export const getConstraints = (ast: AST.Refinement): Constraints | undefined => }); case S.LessThanOrEqualToTypeId: return new NumberConstraints({ max: jsonSchema.maximum }); - case S.PositiveTypeId: - return new NumberConstraints({ exclusiveMin: 0 }); - case S.NonNegativeTypeId: - return new NumberConstraints({ min: 0 }); - case S.NegativeTypeId: - return new NumberConstraints({ exclusiveMax: 0 }); - case S.NonPositiveTypeId: - return new NumberConstraints({ max: 0 }); case S.IntTypeId: return new NumberConstraints({ isInt: true }); case S.BetweenTypeId: @@ -116,14 +108,6 @@ export const getConstraints = (ast: AST.Refinement): Constraints | undefined => }); case S.LessThanOrEqualToBigintTypeId: return new BigintConstraints({ max: jsonSchema.maximum }); - case S.PositiveBigintTypeId: - return new BigintConstraints({ exclusiveMin: 0n }); - case S.NonNegativeBigintTypeId: - return new BigintConstraints({ min: 0n }); - case S.NegativeBigintTypeId: - return new BigintConstraints({ exclusiveMax: 0n }); - case S.NonPositiveBigintTypeId: - return new BigintConstraints({ max: 0n }); case S.BetweenBigintTypeId: return new BigintConstraints({ min: jsonSchema.minimum, @@ -131,6 +115,8 @@ export const getConstraints = (ast: AST.Refinement): Constraints | undefined => }); // String + case S.LengthTypeId: + return new StringConstraints({ minLength: jsonSchema.minLength, maxLength: jsonSchema.maxLength }); case S.MinLengthTypeId: return new StringConstraints({ minLength: jsonSchema.minLength }); case S.MaxLengthTypeId: diff --git a/src/empty.ts b/src/empty.ts index 90676ff..1b4a857 100644 --- a/src/empty.ts +++ b/src/empty.ts @@ -1,7 +1,7 @@ import * as S from "@effect/schema/Schema" import * as AST from "@effect/schema/AST" -import * as RA from "@effect/data/ReadonlyArray" -import * as O from "@effect/data/Option" +import * as RA from "effect/ReadonlyArray" +import * as O from "effect/Option" import { Constraints, combineConstraints, getConstraints, createHookId } from "./common" diff --git a/src/equivalence.ts b/src/equivalence.ts index 633ff35..5deb89b 100644 --- a/src/equivalence.ts +++ b/src/equivalence.ts @@ -1,11 +1,9 @@ import * as S from "@effect/schema/Schema" import * as AST from "@effect/schema/AST" -import * as Eq from "@effect/data/Equivalence"; -import { pipe } from "@effect/data/Function" -import * as O from "@effect/data/Option" -import * as RA from "@effect/data/ReadonlyArray" +import * as Eq from "effect/Equivalence"; +import * as O from "effect/Option" +import * as RA from "effect/ReadonlyArray" import { createHookId, memoizeThunk } from "./common" -import * as Equal from "@effect/data/Equal"; export const EquivalenceHookId = createHookId("EquivalenceHookId") diff --git a/src/faker.ts b/src/faker.ts index 07cf0f8..e85cb5e 100644 --- a/src/faker.ts +++ b/src/faker.ts @@ -1,11 +1,10 @@ import * as S from "@effect/schema/Schema" import * as AST from "@effect/schema/AST" import type * as F from '@faker-js/faker'; -import * as O from "@effect/data/Option" -import { pipe } from "@effect/data/Function"; -import * as RA from "@effect/data/ReadonlyArray" +import * as O from "effect/Option" +import * as RA from "effect/ReadonlyArray" import { Constraints, combineConstraints, createHookId, getConstraints, memoizeThunk } from "./common" -import { isBigint, isNumber } from "@effect/data/Predicate"; +import { isBigint, isNumber } from "effect/Predicate"; export const FakerHookId = createHookId("FakerHookId") @@ -92,7 +91,7 @@ const go = (ast: AST.AST, depthLimit = 10, constraints?: Constraints): Faker(schema: S.Schema, from: I, to: A) => { @@ -21,7 +18,7 @@ describe("empty", () => { it("any", () => expectEmptyValues(S.any, undefined, undefined)) it("unknown", () => expectEmptyValues(S.unknown, undefined, undefined)) it("number", () => expectEmptyValues(S.number, 0, 0)) - it("bigint", () => expectEmptyValues(S.bigint, 0n, 0n)) + it("bigint", () => expectEmptyValues(S.bigint, "", 0n)) it("string", () => expectEmptyValues(S.string, "", "")); it("boolean", () => expectEmptyValues(S.boolean, false, false)); it("enum", () => expectEmptyValues(S.enums(Fruits), Fruits.Apple, Fruits.Apple)) @@ -40,8 +37,8 @@ describe("empty", () => { it("number/ greaterThan", () => expectEmptyValues(pipe(S.number, S.greaterThan(4)), 0, 4)) it("number/ greaterThanOrEqualTo", () => expectEmptyValues(pipe(S.number, S.greaterThanOrEqualTo(4)), 0, 4)) it("number/ int, greaterThan", () => expectEmptyValues(pipe(S.number, S.int(), S.greaterThan(4)), 0, 5)) - it("bigint/ greaterThan", () => expectEmptyValues(pipe(S.bigint, S.greaterThanBigint(4n)), 0n, 5n)) - it("bigint/ greaterThanOrEqualTo", () => expectEmptyValues(pipe(S.bigint, S.greaterThanOrEqualToBigint(4n)), 0n, 4n)) + it("bigint/ greaterThan", () => expectEmptyValues(pipe(S.bigint, S.greaterThanBigint(4n)), "", 5n)) + it("bigint/ greaterThanOrEqualTo", () => expectEmptyValues(pipe(S.bigint, S.greaterThanOrEqualToBigint(4n)), "", 4n)) it("string/ minLength", () => expectEmptyValues(pipe(S.string, S.minLength(2)), "", " ")) it("array/ minItems", () => expectEmptyValues(pipe(S.array(S.string), S.minItems(2)), [], ["", ""])) diff --git a/tests/equivalence.test.ts b/tests/equivalence.test.ts index fb13938..c3194e0 100644 --- a/tests/equivalence.test.ts +++ b/tests/equivalence.test.ts @@ -1,8 +1,8 @@ import { describe, it, expect } from "vitest"; import * as S from "@effect/schema/Schema" -import { pipe } from "@effect/data/Function" +import { pipe } from "effect/Function" import * as _ from "../src/equivalence" -import * as Eq from "@effect/data/Equivalence"; +import * as Eq from "effect/Equivalence"; import * as fc from 'fast-check' import * as A from "@effect/schema/Arbitrary"; import { Category, Fruits } from "./common"; diff --git a/tests/faker.test.ts b/tests/faker.test.ts index ae7a511..01ce488 100644 --- a/tests/faker.test.ts +++ b/tests/faker.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest"; import * as S from "@effect/schema/Schema" import * as _ from "../src/faker"; import * as F from '@faker-js/faker'; -import { pipe } from "@effect/data/Function"; +import { pipe } from "effect/Function"; import { Category, Fruits } from "./common"; @@ -11,7 +11,10 @@ import { Category, Fruits } from "./common"; */ const generatesValidValue = (schema: S.Schema) => { const fake = _.to(schema)(F.faker) - expect(S.is(schema)(fake)).to.be.true + const isValid = S.is(schema)(fake) + if(!isValid) console.log(fake) + + expect(isValid).to.be.true } describe("faker", () => { @@ -48,7 +51,7 @@ describe("faker", () => { it("number/ int (0, 5)", () => generatesValidValue(pipe(S.number, S.int(), S.greaterThan(0), S.lessThan(5)))) it("number/ int [0, 5]", () => generatesValidValue(pipe(S.number, S.int(), S.greaterThanOrEqualTo(0), S.lessThanOrEqualTo(5)))) it("bigint/ (0, 5)", () => generatesValidValue(pipe(S.bigint, S.greaterThanBigint(0n), S.lessThanBigint(5n)))) - it("string/ length", () => generatesValidValue(pipe(S.string, S.length(30)))) + it("string/ length", () => generatesValidValue(pipe(S.string, S.length(10)))) it("string/ minLength, maxLength", () => generatesValidValue(pipe(S.string, S.minLength(30), S.maxLength(50)))) it("string/ pattern", () => generatesValidValue(pipe(S.string, S.pattern(/hello-[1-5]/)))) it("array/ itemsCount", () => generatesValidValue(pipe(S.array(S.string), S.itemsCount(10)))) @@ -97,7 +100,7 @@ describe("faker", () => { }) it("struct - extra props", () => { - const schema = pipe(S.struct({ a: S.string, b: S.number }), S.extend(S.record(S.symbol, S.string))) + const schema = pipe(S.struct({ a: S.symbol, b: S.number }), S.extend(S.record(S.string, S.string))) generatesValidValue(schema) }) diff --git a/tests/jsonSchema.test.ts b/tests/jsonSchema.test.ts index c9a1c6b..cb46c67 100644 --- a/tests/jsonSchema.test.ts +++ b/tests/jsonSchema.test.ts @@ -3,7 +3,7 @@ import * as A from "@effect/schema/Arbitrary"; import * as S from "@effect/schema/Schema"; import * as fc from "fast-check"; import * as _ from "../src/jsonSchema"; -import { isRecord } from "@effect/data/Predicate"; +import { isRecord } from "effect/Predicate"; import Ajv from "ajv"; const isJsonArray = (u: unknown): u is _.JsonArray => Array.isArray(u) && u.every(isJson) diff --git a/tests/printer.test.ts b/tests/printer.test.ts deleted file mode 100644 index 7bcb9f7..0000000 --- a/tests/printer.test.ts +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Experimental. Converts a schema to a string of itself as best it can. - * @example - * expect(render(S.union(S.string, S.boolean))).toBe(`S.union(S.string, S.boolean)`) - */ - -import * as AST from "@effect/schema/AST"; -import * as Doc from "@effect/printer/Doc" -import * as Render from "@effect/printer/Render" -import * as S from "@effect/schema/Schema"; -import { describe, it, expect } from "vitest"; -import * as RA from "@effect/data/ReadonlyArray"; - -const scope = (scope: string, doc: Doc.Doc): Doc.Doc => - Doc.hcat([Doc.text(scope), Doc.text("."), doc]) - - -const fnCall = (fn: Doc.Doc, args: Doc.Doc[]): Doc.Doc => - Doc.hcat([fn, Doc.text("("), ...RA.intersperse(Doc.text(", "))(args), Doc.text(")")]) - - -interface Config { - scope: string; // e.g. "S" -> S.number - quote: "single" | "double"; -} - -const defaultConfig: Config = { scope: "S", quote: "double" } - -const getIdentifier = AST.getAnnotation( - AST.IdentifierAnnotationId -) - -const to = (schema: S.Schema, config: Config = defaultConfig): Doc.Doc => - go(AST.to(schema.ast), config) - -const go = (ast: AST.AST, config: Config = defaultConfig) => { - const quote = config.quote === "double" ? Doc.doubleQuoted : Doc.singleQuoted - - const annotations = getIdentifier(ast) - if(annotations._tag === "Some") { - return scope(config.scope, Doc.text(annotations.value)) - } - - switch(ast._tag) { - case "NumberKeyword": return scope(config.scope, Doc.text("number")) - case "BigIntKeyword": return scope(config.scope, Doc.text("bigint")) - case "StringKeyword": return scope(config.scope, Doc.text("string")) - case "BooleanKeyword": return scope(config.scope, Doc.text("boolean")) - case "SymbolKeyword": return scope(config.scope, Doc.text("symbol")) - case "Literal": return fnCall(scope(config.scope, Doc.text("literal")), [quote(Doc.text(ast.literal?.toString() || ""))]) - - case "NeverKeyword": return scope(config.scope, Doc.text("never")) - case "AnyKeyword": return scope(config.scope, Doc.text("any")) - - case "Union": { - const u = ast.types.map(t => go(t, config)) - return fnCall(scope(config.scope, Doc.text("union")), u) - } - - default: return Doc.text(""); - } -} - -const render = (schema: S.Schema) => Render.pretty(to(schema), { lineWidth: 14 }); - -describe.concurrent("Printer", () => { - it("string", () => { expect(render(S.string)).toBe(`S.string`) }) - it("number", () => { expect(render(S.number)).toBe(`S.number`) }) - it("bigint", () => { expect(render(S.bigint)).toBe(`S.bigint`) }) - it("boolean", () => { expect(render(S.boolean)).toBe(`S.boolean`) }) - it("symbol", () => { expect(render(S.symbol)).toBe(`S.symbol`) }) - it("literal", () => { expect(render(S.literal("a"))).toBe(`S.literal("a")`) }) - - it("never", () => { expect(render(S.never)).toBe(`S.never`) }) - it("any", () => { expect(render(S.any)).toBe(`S.any`) }) - - it("union", () => { - expect(render(S.union(S.string, S.boolean))).toBe(`S.union(S.string, S.boolean)`) - }) -}) \ No newline at end of file diff --git a/tests/semigroup.test.ts b/tests/semigroup.test.ts index 188cf31..c01add7 100644 --- a/tests/semigroup.test.ts +++ b/tests/semigroup.test.ts @@ -1,12 +1,12 @@ import { describe, it, expect } from "vitest"; import * as S from "@effect/schema/Schema" -import { pipe } from "@effect/data/Function" +import { pipe } from "effect/Function" import * as _ from "../src/semigroup" import * as Semi from "@effect/typeclass/Semigroup" import * as Boolean from "@effect/typeclass/data/Boolean"; import * as Number from "@effect/typeclass/data/Number"; import * as String from "@effect/typeclass/data/String"; -import * as n from "@effect/data/Number" +import * as n from "effect/Number" import * as fc from 'fast-check' import * as A from "@effect/schema/Arbitrary"; import { to } from "../src/equivalence"