Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/benchmarks/goldens/jsonSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"label": "Check values against a published document",
"note": "the JSON Schema is the input, not the output",
"cells": [
33716,
33717,
64655,
null,
null,
Expand Down
2 changes: 1 addition & 1 deletion packages/benchmarks/goldens/protobuf.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"label": "Decode only",
"note": "what a client that never sends the message gets back from tree-shaking",
"cells": [
39767,
39768,
null,
13566,
15469,
Expand Down
2 changes: 1 addition & 1 deletion packages/benchmarks/goldens/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"label": "Everything the library exports",
"note": "the ceiling, for an app that ends up using all of it",
"cells": [
73883,
73881,
65989,
31148,
15101,
Expand Down
17 changes: 16 additions & 1 deletion packages/sury/scripts/unionFuzz/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ const nestedUnion = (S: Sury, rng: Rng, depth: number): MemberSpec => {
};
};

// Two tagged objects dispatch on a property read, which throws on a value no
// object admits, and a leaf beside them is what brings one in (`S.env` admits
// undefined). A two-member nested union almost never draws all three.
const taggedBesideLeaf = (S: Sury, rng: Rng): MemberSpec => {
const a = taggedRescript(S, "A", leafSchema(S, rng));
const b = taggedRescript(S, "B", leafSchema(S, rng));
const c = leafSchema(S, rng);
return {
id: `union(${a.id},${b.id},${c.id})`,
shape: node("union", a.shape, b.shape, c.shape),
schema: S.union([a.schema, b.schema, c.schema]),
};
};

// A member that reaches itself. Its dispatch resolves the ref to what it
// names, so a list or tree is checked by its runtime type alongside its
// siblings, while one whose definition is itself a union stays opaque. Its keys
Expand Down Expand Up @@ -359,7 +373,8 @@ const memberAt = (S: Sury, rng: Rng, depth: number): MemberSpec => {
const modified = applyModify(S, rng, leafSchema(S, rng));
return modified ?? leafSchema(S, rng);
}
return nestedUnion(S, rng, depth);
if (roll < 0.98) return nestedUnion(S, rng, depth);
return taggedBesideLeaf(S, rng);
};

// One schema from the same grammar the union members come from, for a fuzzer
Expand Down
1 change: 1 addition & 0 deletions packages/sury/scripts/unionFuzz/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export const sample = (schema: unknown, rng: Rng, depth = 0): unknown => {
if (s.format === "int32") return pick ? 7 : 1;
return pick ? 2 : 1;
case "string": {
if (s.format === "env") return pick ? "x" : undefined;
const options = s.format ? FORMAT_STRINGS[s.format] : undefined;
if (options) return options[pick]!;
// An unrecognised format would be a string the refinement rejects, and a
Expand Down
118 changes: 59 additions & 59 deletions packages/sury/specs/bundleSize.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# Minified+gzipped bytes per public export of index.mjs, plus `total` for the whole entry.
# Generated by `pnpm spec check --write` - every row is measured, so never hand-write one.
total: 73883
total: 73881
exports:
$Metadata_Id_make: 6064
$Metadata_get: 6058
$Metadata_set: 6075
$Metadata_set: 6074
$Option_getOr: 14875
$Option_getOrWith: 14876
$encodeAsResult: 6354
$encodeAsResultPromise: 6355
$encodeAsResult: 6358
$encodeAsResultPromise: 6358
$makeAsResult: 6804
$makeAsResultPromise: 6803
$nullAsOption: 17764
$nullAsOption: 17763
$nullAsUnit: 6472
$nullableAsOption: 17768
$option: 17757
$parseAsResult: 6355
$parseAsResultPromise: 6355
$nullableAsOption: 17767
$option: 17756
$parseAsResult: 6358
$parseAsResultPromise: 6358
$schema: 10949
$setExnId: 6059
$to: 8158
$unit: 6445
Error: 6053
Error: 6052
any: 6048
anyOf: 18193
anyOf: 18192
array: 10939
arrayBuffer: 6443
arrayBuffer: 6445
assertInputAsPromiseOrReject: 6759
assertInputOrThrow: 6759
assertOutputAsPromiseOrReject: 6759
Expand All @@ -35,40 +35,40 @@ exports:
bigint: 6408
blob: 8256
boolean: 6351
brand: 6068
brand: 6067
cidrv4: 6629
cidrv6: 6697
cidrv6: 6696
compactColumns: 11815
compareInput: 9032
compareOutput: 9032
compareInput: 9059
compareOutput: 9059
cuid: 6550
cuid2: 6548
date: 6756
decodeAsPromisableResult: 6355
decodeAsPromiseOrReject: 6353
decodeAsResult: 6353
decodeAsPromisableResult: 6358
decodeAsPromiseOrReject: 6355
decodeAsResult: 6356
decodeAsResultPromise: 6357
decodeOrThrow: 6353
deepStrict: 6209
deepStrip: 6208
decodeOrThrow: 6355
deepStrict: 6208
deepStrip: 6207
duration: 6550
e164: 6550
email: 6560
enableStandardJSONSchema: 8370
encodeAsPromisableResult: 6355
encodeAsPromiseOrReject: 6352
encodeAsResult: 6353
encodeAsResultPromise: 6356
encodeOrThrow: 6352
enum: 18195
enableStandardJSONSchema: 8371
encodeAsPromisableResult: 6357
encodeAsPromiseOrReject: 6355
encodeAsResult: 6356
encodeAsResultPromise: 6357
encodeOrThrow: 6355
enum: 18194
env: 7562
extendJSONSchema: 6135
file: 8261
formData: 13119
fromJSONSchemaOrThrow: 33356
fromJSONSchemaOrThrow: 33355
global: 6097
gt: 7330
gte: 7333
gt: 7328
gte: 7329
hex: 6546
hostname: 6552
httpUrl: 6862
Expand All @@ -78,28 +78,28 @@ exports:
int32: 6590
integer: 6572
ipv4: 6580
ipv6: 6676
ipv6: 6675
iri: 6895
iriReference: 6902
isEqualInput: 9179
isEqualOutput: 9178
isEqualInput: 9200
isEqualOutput: 9200
isInput: 6758
isInputAsPromise: 6759
isOutput: 6756
isOutputAsPromise: 6757
isoDate: 6651
isoDate: 6652
isoDateTime: 6848
isoTime: 6723
json: 20270
json: 20271
jsonPointer: 6528
jsonString: 23152
jsonStringWithSpace: 23165
ksuid: 6544
length: 7289
length: 7288
list: 11804
literal: 10930
lt: 7331
lte: 7331
literal: 10929
lt: 7330
lte: 7330
mac: 6594
makeInputAsPromisableResult: 6803
makeInputAsPromiseOrReject: 6804
Expand All @@ -121,32 +121,32 @@ exports:
nan: 6448
nanoid: 6543
never: 6111
noValidation: 6066
noValidation: 6065
nonEmpty: 7304
nullable: 18970
nullable: 18971
nullish: 18969
number: 6561
object: 13235
optional: 18947
parseAsPromisableResult: 6357
parseAsPromiseOrReject: 6355
parseAsResult: 6355
parseAsResultPromise: 6355
parseOrThrow: 6353
optional: 18948
parseAsPromisableResult: 6358
parseAsPromiseOrReject: 6356
parseAsResult: 6358
parseAsResultPromise: 6358
parseOrThrow: 6356
pathToText: 6046
pattern: 6251
port: 6675
protobuf: 29735
protobufAny: 32854
protobufField: 7789
protobufTypeName: 6144
protobuf: 29737
protobufAny: 32853
protobufField: 7790
protobufTypeName: 6143
queryString: 13058
record: 10936
recursive: 7170
refine: 6378
refine: 6379
relativeJsonPointer: 6554
reverse: 6048
schema: 10930
reverse: 6047
schema: 10929
schemaOf: 10937
shape: 12069
size: 7262
Expand All @@ -157,14 +157,14 @@ exports:
to: 7679
toInputExpression: 6047
toInputJSONSchemaOrThrow: 8332
toOutputExpression: 6060
toOutputExpression: 6059
toOutputJSONSchemaOrThrow: 8339
toProtoOrThrow: 19599
trim: 6868
tuple: 12199
uint8Array: 7562
ulid: 6577
union: 18193
union: 18192
unknown: 6048
uri: 6820
uriReference: 6828
Expand All @@ -175,6 +175,6 @@ exports:
uuid: 6529
uuidv4: 6589
uuidv6: 6591
uuidv7: 6592
uuidv7: 6593
void: 6453
xid: 6549
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-boolean-to-optional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jsonSchema:
fromOutputType: boolean
isEqual: strictEqual
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: (a,b)=>a===b?0:(a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0)
vs:
zod:
Expand Down
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-date.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ isEqual:
input: strictEqual
output: (a,b)=>a===b||+a===+b
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: (a,b)=>a===b?0:+a<+b?-1:+a>+b?1:+a===+b?0:1
vs:
zod:
Expand Down
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-email.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jsonSchema:
output: '{ type: "string", format: "email" }'
isEqual: strictEqual
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: strictCompare
vs:
zod:
Expand Down
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-enum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jsonSchema:
output: '{ enum: ["development", "production"] }'
isEqual: strictEqual
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: strictCompare
vs:
zod:
Expand Down
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-jsonstring-or-number.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jsonSchema:
output: '{ anyOf: [{ type: "string" }, { type: "number" }] }'
isEqual: strictEqual
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: "throws: [Sury] Can't compare JSON string | number. Only primitives, Date, URL and tuples of them are orderable. Use isEqual for equality"
vs:
zod:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ isEqual:
input: strictEqual
output: (a,b)=>a===b||(a===void 0?b===void 0:b!==void 0&&a.a===b.a)
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: "throws: [Sury] Can't compare { a: number; }. Only primitives, Date, URL and tuples of them are orderable. Use isEqual for equality"
vs:
zod:
Expand Down
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-string-minlength0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jsonSchema:
output: '{ type: "string", minLength: 0 }'
isEqual: strictEqual
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: strictCompare
vs:
zod:
Expand Down
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-to-bigint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jsonSchema:
output: Expected JSON, received bigint
isEqual: strictEqual
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: strictCompare
vs:
zod:
Expand Down
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-to-boolean.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jsonSchema:
output: '{ type: "boolean" }'
isEqual: strictEqual
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: strictCompare
vs:
zod:
Expand Down
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-to-nullable-blank.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jsonSchema:
output: '{ type: "string", minLength: 0, nullable: true }'
isEqual: strictEqual
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: (a,b)=>a===b?0:(a===null?b===null?0:-1:b===null?1:a<b?-1:a>b?1:0)
vs:
zod:
Expand Down
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-to-number.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jsonSchema:
output: '{ type: "number" }'
isEqual: strictEqual
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: strictCompare
vs:
zod:
Expand Down
2 changes: 1 addition & 1 deletion packages/sury/specs/codec-env-to-object-unsupported.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ isEqual:
input: strictEqual
output: (a,b)=>a===b||a.PORT===b.PORT
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: "throws: [Sury] Can't compare { PORT: port; }. Only primitives, Date, URL and tuples of them are orderable. Use isEqual for equality"
vs:
zod:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jsonSchema:
output: '{ type: "string", minLength: 0 }'
isEqual: strictEqual
compare:
input: (a,b)=>a===b?0:a===void 0?b===void 0?0:-1:b===void 0?1:a<b?-1:a>b?1:0
input: (a,b)=>a===b?0:(b===void 0)-(a===void 0)||(a<b?-1:a>b?1:0)
output: strictCompare
vs:
zod:
Expand Down
Loading
Loading