Skip to content

Commit a28a3d7

Browse files
authored
fix jitless object transformations (#1339)
1 parent cf9dfcf commit a28a3d7

File tree

10 files changed

+73
-69
lines changed

10 files changed

+73
-69
lines changed

ark/attest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ark/attest",
3-
"version": "0.43.2",
3+
"version": "0.43.3",
44
"license": "MIT",
55
"author": {
66
"name": "David Blass",

ark/fs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ark/fs",
3-
"version": "0.43.2",
3+
"version": "0.43.3",
44
"license": "MIT",
55
"author": {
66
"name": "David Blass",

ark/repo/scratch.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
import { type } from "arktype"
22

3-
// Define environment variable requirements
4-
const environmentSchema = type({
5-
DATA_PATH: "string = './data'"
6-
})
7-
8-
const base = {
9-
get foo() {
10-
return "foo"
11-
}
12-
}
13-
14-
// Validate environment variables
15-
console.info("🔧 Parsing environment variables...")
16-
const result = environmentSchema(process.env)
17-
18-
// Exit if validation fails
19-
if (result instanceof type.errors) {
20-
console.error(result.summary)
21-
console.error("process exited with error code 1")
22-
process.exit(1)
23-
}
24-
25-
// Export validated environment
26-
const environment = result
27-
export { environment }
3+
const types = type.module(
4+
{
5+
foo: {
6+
test: "string = 'test'"
7+
}
8+
},
9+
{ jitless: true }
10+
)
11+
12+
types.foo({}) //?

ark/schema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ark/schema",
3-
"version": "0.43.2",
3+
"version": "0.43.3",
44
"license": "MIT",
55
"author": {
66
"name": "David Blass",

ark/schema/structure/structure.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -555,50 +555,50 @@ export class StructureNode extends BaseConstraint<Structure.Declaration> {
555555
}
556556
}
557557

558-
if (!this.index && this.undeclared !== "reject") return true
559-
560-
const keys: Key[] = Object.keys(data)
561-
keys.push(...Object.getOwnPropertySymbols(data))
562-
563-
for (let i = 0; i < keys.length; i++) {
564-
const k = keys[i]
565-
566-
if (this.index) {
567-
for (const node of this.index) {
568-
if (node.signature.traverseAllows(k, ctx)) {
569-
if (traversalKind === "Allows") {
570-
const result = traverseKey(
571-
k,
572-
() => node.value.traverseAllows(data[k as never], ctx),
573-
ctx
574-
)
575-
if (!result) return false
576-
} else {
577-
traverseKey(
578-
k,
579-
() => node.value.traverseApply(data[k as never], ctx),
580-
ctx
581-
)
582-
if (ctx.failFast && ctx.currentErrorCount > errorCount)
583-
return false
558+
if (this.index || this.undeclared === "reject") {
559+
const keys: Key[] = Object.keys(data)
560+
keys.push(...Object.getOwnPropertySymbols(data))
561+
562+
for (let i = 0; i < keys.length; i++) {
563+
const k = keys[i]
564+
565+
if (this.index) {
566+
for (const node of this.index) {
567+
if (node.signature.traverseAllows(k, ctx)) {
568+
if (traversalKind === "Allows") {
569+
const result = traverseKey(
570+
k,
571+
() => node.value.traverseAllows(data[k as never], ctx),
572+
ctx
573+
)
574+
if (!result) return false
575+
} else {
576+
traverseKey(
577+
k,
578+
() => node.value.traverseApply(data[k as never], ctx),
579+
ctx
580+
)
581+
if (ctx.failFast && ctx.currentErrorCount > errorCount)
582+
return false
583+
}
584584
}
585585
}
586586
}
587-
}
588587

589-
if (this.undeclared === "reject" && !this.declaresKey(k)) {
590-
if (traversalKind === "Allows") return false
588+
if (this.undeclared === "reject" && !this.declaresKey(k)) {
589+
if (traversalKind === "Allows") return false
591590

592-
ctx.errorFromNodeContext({
593-
// TODO: this should have its own error code
594-
code: "predicate",
595-
expected: "removed",
596-
actual: "",
597-
relativePath: [k],
598-
meta: this.meta
599-
})
591+
ctx.errorFromNodeContext({
592+
// TODO: this should have its own error code
593+
code: "predicate",
594+
expected: "removed",
595+
actual: "",
596+
relativePath: [k],
597+
meta: this.meta
598+
})
600599

601-
if (ctx.failFast) return false
600+
if (ctx.failFast) return false
601+
}
602602
}
603603
}
604604

ark/type/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# arktype
22

3+
## 2.1.3
4+
5+
Fix a jitless-mode bug causing default + `onUndeclaredKey` transformations to not apply (#1335)
6+
37
## 2.1.2
48

59
Allow non-zero-prefixed decimals in string.numeric ([#1333](https://github.com/arktypeio/arktype/pull/1333))

ark/type/__tests__/defaults.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ contextualize(() => {
5858
)
5959
})
6060

61+
// https://github.com/arktypeio/arktype/issues/1335
62+
it("jitless", () => {
63+
const types = type.module(
64+
{
65+
foo: {
66+
test: "string = 'test'"
67+
}
68+
},
69+
{ jitless: true }
70+
)
71+
72+
attest(types.foo({})).equals({ test: "test" })
73+
attest(types.foo({ test: "provided" })).equals({ test: "provided" })
74+
})
75+
6176
it("unions are defaultable", () => {
6277
const o = type({
6378
boo: "boolean = false"

ark/type/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "arktype",
33
"description": "Optimized runtime validation for TypeScript syntax",
4-
"version": "2.1.2",
4+
"version": "2.1.3",
55
"license": "MIT",
66
"repository": {
77
"type": "git",

ark/util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ark/util",
3-
"version": "0.43.2",
3+
"version": "0.43.3",
44
"license": "MIT",
55
"author": {
66
"name": "David Blass",

ark/util/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { FileConstructor, objectKindOf } from "./objectKinds.ts"
88
// recent node versions (https://nodejs.org/api/esm.html#json-modules).
99

1010
// For now, we assert this matches the package.json version via a unit test.
11-
export const arkUtilVersion = "0.43.2"
11+
export const arkUtilVersion = "0.43.3"
1212

1313
export const initialRegistryContents = {
1414
version: arkUtilVersion,

0 commit comments

Comments
 (0)