From e297bdae0d646d596557c1cd45a5bbcd92671184 Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Fri, 20 Jun 2025 17:45:42 -0500 Subject: [PATCH 1/2] fix(json): removes `Arbitrary` from API so users don't have to download fast-check --- packages/json/src/arbitrary.ts | 110 +++++++++++++++---------------- packages/json/src/exports.ts | 1 - packages/json/src/json.ts | 2 - packages/json/test/arbitrary.ts | 61 +++++++++++++++++ packages/json/test/cache.test.ts | 4 +- packages/json/test/json.test.ts | 11 ++-- 6 files changed, 126 insertions(+), 63 deletions(-) create mode 100644 packages/json/test/arbitrary.ts diff --git a/packages/json/src/arbitrary.ts b/packages/json/src/arbitrary.ts index 311a45f6..c61d1ebc 100644 --- a/packages/json/src/arbitrary.ts +++ b/packages/json/src/arbitrary.ts @@ -1,61 +1,61 @@ -import type { Json } from './exports.js' -import * as fc from 'fast-check' +// import type { Json } from './exports.js' +// import * as fc from 'fast-check' -/** @internal */ -const depthIdentifier = fc.createDepthIdentifier() +// /** @internal */ +// const depthIdentifier = fc.createDepthIdentifier() -/** @internal */ -const identifier = fc.stringMatching(/[_$a-zA-Z][_$a-zA-Z0-9]+/g) +// /** @internal */ +// const identifier = fc.stringMatching(/[_$a-zA-Z][_$a-zA-Z0-9]+/g) -/** @internal */ -const scalars = [ - fc.constant(null), - fc.constant(undefined), - fc.boolean(), - fc.integer(), - fc.float(), - fc.string(), -] +// /** @internal */ +// const scalars = [ +// fc.constant(null), +// fc.constant(undefined), +// fc.boolean(), +// fc.integer(), +// fc.float(), +// fc.string(), +// ] -/** @internal */ -const seed: fc.LetrecTypedBuilder = (LOOP) => { - return { - scalar: fc.oneof(...scalars), - array: fc.array(LOOP('any')), - object: fc.dictionary(identifier, LOOP('any')), - any: fc.oneof( - { depthIdentifier, maxDepth: 2, depthSize: 'xsmall', withCrossShrink: true }, - ...scalars, - LOOP('scalar'), - LOOP('array'), - LOOP('object'), - ) - } -} +// /** @internal */ +// const seed: fc.LetrecTypedBuilder = (LOOP) => { +// return { +// scalar: fc.oneof(...scalars), +// array: fc.array(LOOP('any')), +// object: fc.dictionary(identifier, LOOP('any')), +// any: fc.oneof( +// { depthIdentifier, maxDepth: 2, depthSize: 'xsmall', withCrossShrink: true }, +// ...scalars, +// LOOP('scalar'), +// LOOP('array'), +// LOOP('object'), +// ) +// } +// } -/** - * ## {@link Seed `Json.Seed`} - * - * This type describes an object whose values are [fast-check](https://github.com/dubzzz/fast-check) - * arbitraries that are capable of generating arbitrary, valid JSON values. - * - * See also: - * - {@link Arbitrary `Json.Arbitrary`} - */ -export interface Seed { - any: Json - scalar: Json.Scalar - array: readonly this['any'][] - object: Record -} +// /** +// * ## {@link Seed `Json.Seed`} +// * +// * This type describes an object whose values are [fast-check](https://github.com/dubzzz/fast-check) +// * arbitraries that are capable of generating arbitrary, valid JSON values. +// * +// * See also: +// * - {@link Arbitrary `Json.Arbitrary`} +// */ +// export interface Seed { +// any: Json +// scalar: Json.Scalar +// array: readonly this['any'][] +// object: Record +// } -/** - * ## {@link Arbitrary `Json.Arbitrary`} - * - * An object whose values are [fast-check](https://github.com/dubzzz/fast-check) - * arbitraries that are capable of generating arbitrary, valid JSON values. - * - * See also: - * - {@link Seed `Json.Seed`} - */ -export const Arbitrary = fc.letrec(seed) +// /** +// * ## {@link Arbitrary `Json.Arbitrary`} +// * +// * An object whose values are [fast-check](https://github.com/dubzzz/fast-check) +// * arbitraries that are capable of generating arbitrary, valid JSON values. +// * +// * See also: +// * - {@link Seed `Json.Seed`} +// */ +// export const Arbitrary = fc.letrec(seed) diff --git a/packages/json/src/exports.ts b/packages/json/src/exports.ts index ce1042d9..27dc1275 100644 --- a/packages/json/src/exports.ts +++ b/packages/json/src/exports.ts @@ -1,5 +1,4 @@ import * as _ from './functor.js' -import { Arbitrary as _Arbitrary } from './arbitrary.js' export { VERSION } from './version.js' export { Cache } from './cache.js' diff --git a/packages/json/src/json.ts b/packages/json/src/json.ts index 7d402b80..2d926d38 100644 --- a/packages/json/src/json.ts +++ b/packages/json/src/json.ts @@ -1,5 +1,3 @@ -export { Arbitrary } from './arbitrary.js' - export type { Fixpoint, Free, diff --git a/packages/json/test/arbitrary.ts b/packages/json/test/arbitrary.ts new file mode 100644 index 00000000..e043bcc3 --- /dev/null +++ b/packages/json/test/arbitrary.ts @@ -0,0 +1,61 @@ +import { Json } from '@traversable/json' +import * as fc from 'fast-check' + +/** @internal */ +const depthIdentifier = fc.createDepthIdentifier() + +/** @internal */ +const identifier = fc.stringMatching(/[_$a-zA-Z][_$a-zA-Z0-9]+/g) + +/** @internal */ +const scalars = [ + fc.constant(null), + fc.constant(undefined), + fc.boolean(), + fc.integer(), + fc.float(), + fc.string(), +] + +/** @internal */ +const seed: fc.LetrecTypedBuilder = (LOOP) => { + return { + scalar: fc.oneof(...scalars), + array: fc.array(LOOP('any')), + object: fc.dictionary(identifier, LOOP('any')), + any: fc.oneof( + { depthIdentifier, maxDepth: 2, depthSize: 'xsmall', withCrossShrink: true }, + ...scalars, + LOOP('scalar'), + LOOP('array'), + LOOP('object'), + ) + } +} + +/** + * ## {@link Seed `Json.Seed`} + * + * This type describes an object whose values are [fast-check](https://github.com/dubzzz/fast-check) + * arbitraries that are capable of generating arbitrary, valid JSON values. + * + * See also: + * - {@link Arbitrary `Json.Arbitrary`} + */ +export interface Seed { + any: Json + scalar: Json.Scalar + array: readonly this['any'][] + object: Record +} + +/** + * ## {@link Arbitrary `Json.Arbitrary`} + * + * An object whose values are [fast-check](https://github.com/dubzzz/fast-check) + * arbitraries that are capable of generating arbitrary, valid JSON values. + * + * See also: + * - {@link Seed `Json.Seed`} + */ +export const Arbitrary = fc.letrec(seed) diff --git a/packages/json/test/cache.test.ts b/packages/json/test/cache.test.ts index e601b7dd..b9b9bc82 100644 --- a/packages/json/test/cache.test.ts +++ b/packages/json/test/cache.test.ts @@ -4,6 +4,8 @@ import { fc, test } from '@fast-check/vitest' import { Cache, Json } from '@traversable/json' import { symbol } from '@traversable/registry' +import { Arbitrary } from './arbitrary.js' + vi.describe('〖⛳️〗‹‹‹ ❲@traversable/json❳', () => { const createBadCache = Cache.new as any const index = { depth: 0, path: [] } @@ -20,7 +22,7 @@ vi.describe('〖⛳️〗‹‹‹ ❲@traversable/json❳', () => { }) test.prop( - [fc.dictionary(fc.string(), Json.Arbitrary.object)], { + [fc.dictionary(fc.string(), Arbitrary.object)], { // numRuns: 10_000, examples: [ [{ "toString": {} }] diff --git a/packages/json/test/json.test.ts b/packages/json/test/json.test.ts index 38b9679e..ea3238d6 100644 --- a/packages/json/test/json.test.ts +++ b/packages/json/test/json.test.ts @@ -1,6 +1,9 @@ import { Json } from '@traversable/json' import * as vi from 'vitest' import { test } from '@fast-check/vitest' +import * as fc from 'fast-check' +import { Arbitrary } from './arbitrary.js' + const addMetadata = (data: Json) => !Json.isObject(data) ? data @@ -16,17 +19,17 @@ const rmMetadata = (data: Json) => { vi.describe('〖⛳️〗‹‹‹ ❲@traversable/json❳', () => { test.prop( - [Json.Arbitrary.any], { + [Arbitrary.any], { // numRuns: 50_000 })( '〖⛳️〗› ❲Json#Functor❳: Functor.map preserves structure', (json) => { vi.assert.deepEqual(Json.Functor.map((x) => x)(json), json) } - ); + ) test.prop( - [Json.Arbitrary.object], { + [Arbitrary.object], { // numRuns: 50_000, })( '〖⛳️〗› ❲Json#fold + Json#unfold❳', @@ -38,5 +41,5 @@ vi.describe('〖⛳️〗‹‹‹ ❲@traversable/json❳', () => { vi.assert.notDeepEqual(withoutMetadata, withMetadata) vi.assert.deepEqual(json, withoutMetadata) } - ); + ) }) From 0a0d544161b71a6e4d292c34aaca4806449058d6 Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Fri, 20 Jun 2025 17:46:43 -0500 Subject: [PATCH 2/2] chore: commits changeset --- .changeset/short-nails-travel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/short-nails-travel.md diff --git a/.changeset/short-nails-travel.md b/.changeset/short-nails-travel.md new file mode 100644 index 00000000..e3ecc347 --- /dev/null +++ b/.changeset/short-nails-travel.md @@ -0,0 +1,5 @@ +--- +"@traversable/json": patch +--- + +fix(json): removes `Arbitrary` module so users don't have to download fast-check as a dep