Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

Commit

Permalink
fix(array): 🐛 Resolve issues with circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
xeho91 committed May 6, 2023
1 parent c962129 commit 3e3ba97
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/array/source/schema/empty/empty.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ARRAY_SCHEMA, validateArray } from "../schema.ts";
import { ARRAY_SCHEMA, validateArray } from "../native/native.ts";

export const EMPTY_ARRAY_SCHEMA = ARRAY_SCHEMA.length(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { returns, throws } from "@terminal-nerds/snippets-test/unit";
import { describe, expect, it } from "vitest";
import { ZodError } from "zod";

import { validateArray } from "./schema.ts";
import { validateArray } from "./native.ts";

describe("validateArray(value)", () => {
it(throws(ZodError).on(`non-array values`).samples(SAMPLE_PRIMITIVES), () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/array/source/schema/native/native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { z } from "zod";

export const ARRAY_SCHEMA = z.array(z.any());

export type AnyArray = ReadonlyArray<unknown>;

export function validateArray(value: unknown): asserts value is AnyArray {
ARRAY_SCHEMA.parse(value);
}

export function validateArrays(...arrays: AnyArray[]): void {
for (const currentArray of arrays) {
validateArray(currentArray);
}
}
17 changes: 1 addition & 16 deletions packages/array/source/schema/schema.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
import { z } from "zod";

export const ARRAY_SCHEMA = z.array(z.any());

export type AnyArray = ReadonlyArray<unknown>;

export function validateArray(value: unknown): asserts value is AnyArray {
ARRAY_SCHEMA.parse(value);
}

export function validateArrays(...arrays: AnyArray[]): void {
for (const currentArray of arrays) {
validateArray(currentArray);
}
}

export * from "./bigint/bigint.ts";
export * from "./empty/empty.ts";
export * from "./float/float.ts";
export * from "./integer/integer.ts";
export * from "./native/native.ts";

0 comments on commit 3e3ba97

Please sign in to comment.