Skip to content

Commit

Permalink
bump versions, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ssalbdivad committed Sep 17, 2024
1 parent ed8a086 commit 4bae3c5
Show file tree
Hide file tree
Showing 24 changed files with 83 additions and 69 deletions.
2 changes: 1 addition & 1 deletion ark/attest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ark/attest",
"version": "0.18.1",
"version": "0.18.2",
"author": {
"name": "David Blass",
"email": "[email protected]",
Expand Down
8 changes: 4 additions & 4 deletions ark/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"@astrojs/react": "3.6.2",
"@astrojs/starlight": "0.27.1",
"@astrojs/ts-plugin": "1.10.2",
"@shikijs/transformers": "1.17.6",
"@shikijs/twoslash": "1.17.6",
"@shikijs/transformers": "1.17.7",
"@shikijs/twoslash": "1.17.7",
"arkdark": "workspace:*",
"arktype": "workspace:*",
"astro": "4.15.6",
Expand All @@ -28,11 +28,11 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"sharp": "0.33.5",
"shiki": "1.17.6",
"shiki": "1.17.7",
"twoslash": "0.2.11"
},
"devDependencies": {
"@types/react": "18.3.5",
"@types/react": "18.3.7",
"@types/react-dom": "18.3.0",
"typescript": "catalog:"
}
Expand Down
10 changes: 5 additions & 5 deletions ark/docs/src/content/docs/reference/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const keywords = type({
const keywords = type({
// Primitive keywords are exposed directly on `type`.
string: type.string,
// All builtin keywords and modules are available under `ark`.
date: type.ark.Date,
// All builtin keywords and modules are available under `keywords`.
date: type.keywords.Date,
// Subtype keywords refine or transform their root type.
// `.root` gets the base type of a subtyped module.
dateFormattedString: type.ark.string.date.root,
isoFormattedString: type.ark.string.date.iso.root,
transformStringToDate: type.ark.string.date.parse
dateFormattedString: type.keywords.string.date.root,
isoFormattedString: type.keywords.string.date.iso.root,
transformStringToDate: type.keywords.string.date.parse
})
```

Expand Down
8 changes: 3 additions & 5 deletions ark/docs/src/content/docs/reference/generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ const basicUser = user.pick("name", "age")
### Invoked Definition

```ts
import { ark } from "arktype"
import { type } from "arktype"

const unfalse = ark.Exclude("boolean", "false")
const unfalse = type.keywords.Exclude("boolean", "false")
```

### TS (TODO)
Expand All @@ -120,7 +120,7 @@ console.log(boxType({ box: "foo" }))

### Generic HKTs

Our new generics have been built using a new method for integrating arbitrary external types as native ArkType generics! This opens up tons of possibilities for external integrations that would otherwise not be possible, but we're still finalizing the API. As a preview, here's what the implementation of `Partial` looks like internally:
Our new generics have been built using a new method for integrating arbitrary external types as native ArkType generics! This opens up tons of possibilities for external integrations that would otherwise not be possible. As a preview, here's what the implementation of `Partial` looks like internally:

```ts
import { generic, Hkt } from "arktype"
Expand All @@ -133,8 +133,6 @@ const Partial = generic(["T", "object"])(
)
```

More to come on this as the API is finalized!

Recursive and cyclic generics are also currently unavailable and will be added soon.

For more usage examples, check out the unit tests for generics [here](https://github.com/arktypeio/arktype/blob/main/ark/type/__tests__/generic.test.ts).
Expand Down
2 changes: 1 addition & 1 deletion ark/fs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ark/fs",
"version": "0.10.0",
"version": "0.11.0",
"author": {
"name": "David Blass",
"email": "[email protected]",
Expand Down
25 changes: 19 additions & 6 deletions ark/repo/scratch.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { type, type Type } from "arktype"
import { type } from "arktype"

export const cloudinaryResource = type({
"[string]": "unknown",
"alt?": "string",
"caption?": "string"
const original = type({
bar: "number"
})

const o = cloudinaryResource.optional()
// correctly adds null to bar's value
const variableNullable = original.map(prop => {
// ^?
const nullableValue = prop.value.or("null")
return {
key: prop.key,
value: nullableValue
}
})

// ignores the .or("null") and returns the original value
const inlinedNullable = original.map(prop => ({
// ^?
key: prop.key,
value: prop.value.or("null")
}))
2 changes: 1 addition & 1 deletion ark/schema/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ark/schema",
"version": "0.10.0",
"version": "0.11.0",
"license": "MIT",
"author": {
"name": "David Blass",
Expand Down
14 changes: 7 additions & 7 deletions ark/type/__tests__/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { attest, contextualize } from "@ark/attest"
import { writeInvalidKeysMessage, writeNumberIndexMessage } from "@ark/schema"
import { ark, type } from "arktype"
import { keywords, type } from "arktype"
import type { constrain, string } from "arktype/internal/keywords/inference.ts"
import type { Matching } from "arktype/internal/keywords/string/string.ts"

Expand Down Expand Up @@ -142,20 +142,20 @@ contextualize(() => {
writeInvalidKeysMessage(t.expression, ["5.5"])
)

attest(t.get(ark.Array.index).expression).snap("string | undefined")
attest(t.get(keywords.Array.index).expression).snap("string | undefined")
})

it("number access on non-variadic", () => {
const t = type({ foo: "number" }).array()

// @ts-expect-error
attest(() => t.get(ark.number.root)).throws(
attest(() => t.get(keywords.number.root)).throws(
writeNumberIndexMessage("number", t.expression)
)

// number subtype
// @ts-expect-error
attest(() => t.get(ark.number.integer)).throws(
attest(() => t.get(keywords.number.integer)).throws(
writeNumberIndexMessage("number % 1", t.expression)
)
})
Expand Down Expand Up @@ -204,16 +204,16 @@ contextualize(() => {
}
})

const bar = t.get("foo", ark.symbol, "bar")
const bar = t.get("foo", keywords.symbol, "bar")
attest<1>(bar.t)
attest(bar.expression).snap("undefined | 1")

const baz = t.get("foo", ark.symbol, "baz")
const baz = t.get("foo", keywords.symbol, "baz")
attest<2 | undefined>(baz.t)
attest(baz.expression).snap("undefined | 2")

// @ts-expect-error
attest(() => t.get("foo", ark.symbol, "")).completions({
attest(() => t.get("foo", keywords.symbol, "")).completions({
"": ["bar", "baz"]
})
})
Expand Down
6 changes: 3 additions & 3 deletions ark/type/__tests__/keywords/ip.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { attest, contextualize } from "@ark/attest"
import { ark, type } from "arktype"
import { keywords, type } from "arktype"

const validIPv4 = "192.168.1.1"
const validIPv6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
Expand Down Expand Up @@ -28,13 +28,13 @@ contextualize(() => {
'must be an IPv4 address (was "1234")'
)

attest(ark.string.ip.v6(validIPv6)).equals(validIPv6)
attest(keywords.string.ip.v6(validIPv6)).equals(validIPv6)

attest(uuidv4(validIPv6).toString()).snap(
'must be an IPv4 address (was "2001:0db8:85a3:0000:0000:8a2e:0370:7334")'
)

attest(ark.string.ip.v6(validIPv4).toString()).snap(
attest(keywords.string.ip.v6(validIPv4).toString()).snap(
'must be an IPv6 address (was "192.168.1.1")'
)
})
Expand Down
4 changes: 2 additions & 2 deletions ark/type/__tests__/keywords/merge.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { attest, contextualize } from "@ark/attest"
import { writeNonStructuralOperandMessage } from "@ark/schema"
import { ark, scope, type } from "arktype"
import { keywords, scope, type } from "arktype"

contextualize(() => {
it("parsed", () => {
Expand All @@ -27,7 +27,7 @@ contextualize(() => {

it("invoked", () => {
const s = Symbol()
const t = ark.Merge(
const t = keywords.Merge(
{
"[string]": "number | bigint",
foo: "0",
Expand Down
4 changes: 2 additions & 2 deletions ark/type/__tests__/keywords/object.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { attest, contextualize } from "@ark/attest"
import { ark, type } from "arktype"
import { keywords, type } from "arktype"
import type { To } from "arktype/internal/keywords/inference.ts"

contextualize(() => {
Expand Down Expand Up @@ -30,7 +30,7 @@ contextualize(() => {
})

it("invoked", () => {
const t = ark.Array.liftFrom({ data: "number" })
const t = keywords.Array.liftFrom({ data: "number" })

attest(t.t).type.toString.snap(`(
In: { data: number } | { data: number }[]
Expand Down
8 changes: 4 additions & 4 deletions ark/type/__tests__/keywords/record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
writeIndivisibleMessage,
writeUnsatisfiedParameterConstraintMessage
} from "@ark/schema"
import { ark, type } from "arktype"
import { keywords, type } from "arktype"

contextualize(() => {
it("parsed", () => {
Expand All @@ -18,22 +18,22 @@ contextualize(() => {
it("invoked", () => {
const expected = type({ "[string]": "number" })

const t = ark.Record("string", "number")
const t = keywords.Record("string", "number")

attest(t.json).equals(expected.json)
attest<typeof expected.t>(t.t)
})

it("invoked validation error", () => {
// @ts-expect-error
attest(() => ark.Record("string", "string % 2")).throwsAndHasTypeError(
attest(() => keywords.Record("string", "string % 2")).throwsAndHasTypeError(
writeIndivisibleMessage(intrinsic.string)
)
})

it("invoked constraint error", () => {
// @ts-expect-error
attest(() => ark.Record("boolean", "number"))
attest(() => keywords.Record("boolean", "number"))
.throws(
writeUnsatisfiedParameterConstraintMessage(
"K",
Expand Down
20 changes: 10 additions & 10 deletions ark/type/__tests__/keywords/string.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { attest, contextualize } from "@ark/attest"
import { ark, type } from "arktype"
import { keywords, type } from "arktype"
import type { Out, To, string } from "arktype/internal/keywords/inference.ts"

contextualize(() => {
Expand Down Expand Up @@ -39,20 +39,20 @@ contextualize(() => {

it("credit card", () => {
const validCC = "5489582921773376"
attest(ark.string.creditCard(validCC)).equals(validCC)
attest(keywords.string.creditCard(validCC)).equals(validCC)
// Regex validation
attest(ark.string.creditCard("0".repeat(16)).toString()).snap(
attest(keywords.string.creditCard("0".repeat(16)).toString()).snap(
'must be a credit card number (was "0000000000000000")'
)
// Luhn validation
attest(ark.string.creditCard(validCC.slice(0, -1) + "0").toString()).snap(
'must be a credit card number (was "5489582921773370")'
)
attest(
keywords.string.creditCard(validCC.slice(0, -1) + "0").toString()
).snap('must be a credit card number (was "5489582921773370")')
})

it("semver", () => {
attest(ark.string.semver("1.0.0")).snap("1.0.0")
attest(ark.string.semver("-1.0.0").toString()).snap(
attest(keywords.string.semver("1.0.0")).snap("1.0.0")
attest(keywords.string.semver("-1.0.0").toString()).snap(
'must be a semantic version (see https://semver.org/) (was "-1.0.0")'
)
})
Expand Down Expand Up @@ -84,13 +84,13 @@ contextualize(() => {
'must be an IPv4 address (was "1234")'
)

attest(ark.string.ip.v6(validIPv6)).equals(validIPv6)
attest(keywords.string.ip.v6(validIPv6)).equals(validIPv6)

attest(uuidv4(validIPv6).toString()).snap(
'must be an IPv4 address (was "2001:0db8:85a3:0000:0000:8a2e:0370:7334")'
)

attest(ark.string.ip.v6(validIPv4).toString()).snap(
attest(keywords.string.ip.v6(validIPv4).toString()).snap(
'must be an IPv6 address (was "192.168.1.1")'
)
})
Expand Down
2 changes: 1 addition & 1 deletion ark/type/__tests__/keywords/url.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { attest, contextualize } from "@ark/attest"
import { ark, type } from "arktype"
import { keywords, type } from "arktype"

contextualize(() => {
it("root", () => {
Expand Down
4 changes: 2 additions & 2 deletions ark/type/__tests__/keywords/uuid.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { attest, contextualize } from "@ark/attest"
import { ark, type } from "arktype"
import { keywords, type } from "arktype"

const validUuidV4 = "f70b8242-dd57-4e6b-b0b7-649d997140a0"

Expand All @@ -18,7 +18,7 @@ contextualize(() => {
attest(uuidv4(validUuidV4)).equals(validUuidV4)
attest(uuidv4("1234").toString()).snap('must be a UUIDv4 (was "1234")')

attest(ark.string.uuid.v5(validUuidV5)).equals(validUuidV5)
attest(keywords.string.uuid.v5(validUuidV5)).equals(validUuidV5)

attest(uuidv4(validUuidV5).toString()).equals(
'must be a UUIDv4 (was "f70b8242-dd57-5e6b-b0b7-649d997140a0")'
Expand Down
2 changes: 1 addition & 1 deletion ark/type/__tests__/objects/mapped.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contextualize(() => {
const withNullableBar = original.map(prop => {
if (prop.key === "bar") {
// due to a TS bug, this has to be assigned to a variable,
// otherwise the | null is not inferred
// otherwise the | null is not inferred: https://github.com/arktypeio/arktype/issues/1132
const nullableBar = prop.value.or("null")
return {
key: prop.key,
Expand Down
11 changes: 7 additions & 4 deletions ark/type/__tests__/pipe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
writeMorphIntersectionMessage,
type ArkErrors
} from "@ark/schema"
import { ark, scope, type, type Type } from "arktype"
import { keywords, scope, type, type Type } from "arktype"
import type { Out, To, constrain } from "arktype/internal/keywords/inference.ts"
import type { MoreThan } from "arktype/internal/keywords/number/number.ts"

Expand Down Expand Up @@ -64,10 +64,13 @@ contextualize(() => {
})

it("preserves validated out", () => {
const t = type("string").pipe.try(s => JSON.parse(s), ark.Array.readonly)
const t = type("string").pipe.try(
s => JSON.parse(s),
keywords.Array.readonly
)

const tOut = t.out
const expectedOut = ark.Array.readonly
const expectedOut = keywords.Array.readonly

attest<typeof expectedOut.t>(tOut.t)
attest(tOut.expression).equals(expectedOut.expression)
Expand All @@ -81,7 +84,7 @@ contextualize(() => {
writeInvalidOperandMessage(
"maxLength",
intrinsic.lengthBoundable,
ark.string.numeric.parse.internal
keywords.string.numeric.parse.internal
)
)
.type.errors("Property 'atMostLength' does not exist")
Expand Down
Loading

0 comments on commit 4bae3c5

Please sign in to comment.