Skip to content

Commit c3e2965

Browse files
authored
Merge pull request #48 from jsonjoy-com/random-impr
Rename "field" to "key"
2 parents d4d86aa + 32551f6 commit c3e2965

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+671
-342
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ interface NumberSchema {
206206
format?: 'i' | 'u' | 'f' | 'i8' | 'i16' | 'i32' | 'i64' | 'u8' | 'u16' | 'u32' | 'u64' | 'f32' | 'f64';
207207
gt?: number; // Greater than (exclusive)
208208
gte?: number; // Greater than or equal to
209-
lt?: number; // Less than (exclusive)
209+
lt?: number; // Less than (exclusive)
210210
lte?: number; // Less than or equal to
211211
validator?: string | string[];
212212
}
213213
```
214214

215215
**Format options:**
216216
- `i*` - Signed integers (i8, i16, i32, i64)
217-
- `u*` - Unsigned integers (u8, u16, u32, u64)
217+
- `u*` - Unsigned integers (u8, u16, u32, u64)
218218
- `f*` - Floating point (f32, f64)
219219

220220
**Examples:**
@@ -234,7 +234,7 @@ interface StringSchema {
234234
ascii?: boolean; // @deprecated Use format: 'ascii'
235235
noJsonEscape?: boolean; // Skip JSON escaping for performance
236236
min?: number; // Minimum length
237-
max?: number; // Maximum length
237+
max?: number; // Maximum length
238238
validator?: string | string[];
239239
}
240240
```
@@ -269,7 +269,7 @@ s.Binary(s.Object(), {format: 'cbor'}) // CBOR-encoded object
269269

270270
### Composite Types
271271

272-
#### ArraySchema (`arr`)
272+
#### ArraySchema (`arr`)
273273
Represents a JSON array with elements of a specific type.
274274

275275
```ts
@@ -310,9 +310,9 @@ Represents a JSON object with defined fields.
310310
```ts
311311
interface ObjectSchema {
312312
kind: 'obj';
313-
fields: ObjectFieldSchema[]; // Defined object fields
314-
unknownFields?: boolean; // @deprecated Allow undefined fields
315-
encodeUnknownFields?: boolean; // Include unknown fields in output
313+
keys: ObjectKeydSchema[]; // Defined object keys
314+
decodeUnknownKeys?: boolean;
315+
encodeUnknownKeys?: boolean;
316316
validator?: string | string[];
317317
}
318318
```
@@ -325,12 +325,12 @@ s.Object([
325325
])
326326
```
327327

328-
#### ObjectFieldSchema (`field`)
328+
#### ObjectKeySchema (`key`)
329329
Represents a single field in an object.
330330

331331
```ts
332-
interface ObjectFieldSchema {
333-
kind: 'field';
332+
interface ObjectKeydSchema {
333+
kind: 'key';
334334
key: string; // Field name
335335
type: TType; // Field value type
336336
optional?: boolean; // Whether field is optional
@@ -340,7 +340,7 @@ interface ObjectFieldSchema {
340340
**Examples:**
341341
```ts
342342
s.prop('id', s.String()) // Required field
343-
s.propOpt('description', s.String()) // Optional field
343+
s.propOpt('description', s.String()) // Optional field
344344
```
345345

346346
#### MapSchema (`map`)
@@ -350,7 +350,7 @@ Represents an object treated as a map with string keys and uniform value types.
350350
interface MapSchema {
351351
kind: 'map';
352352
type: TType; // Type of all values
353-
validator?: string | string[];
353+
validator?: string | string[];
354354
}
355355
```
356356

@@ -379,7 +379,7 @@ s.Const(42 as const) // Constant number
379379
s.Const(null) // Null constant
380380
```
381381

382-
#### RefSchema (`ref`)
382+
#### RefSchema (`ref`)
383383
References another type by ID.
384384

385385
```ts
@@ -413,7 +413,7 @@ s.Or(s.String(), s.Number()) // String or number
413413
#### FunctionSchema (`fn`)
414414
Represents a function type with request and response.
415415

416-
```ts
416+
```ts
417417
interface FunctionSchema {
418418
kind: 'fn';
419419
req: TType; // Request type
@@ -432,7 +432,7 @@ Represents a streaming function type.
432432
```ts
433433
interface FunctionStreamingSchema {
434434
kind: 'fn$';
435-
req: TType; // Request stream type
435+
req: TType; // Request stream type
436436
res: TType; // Response stream type
437437
}
438438
```
@@ -449,17 +449,17 @@ All node types extend the base `TType` interface with these common properties:
449449
```ts
450450
interface TType {
451451
kind: string; // Node type identifier
452-
452+
453453
// Display properties
454454
title?: string; // Human-readable title
455455
intro?: string; // Short description
456456
description?: string; // Long description (may include Markdown)
457-
457+
458458
// Metadata
459459
id?: string; // Unique identifier
460460
meta?: Record<string, unknown>; // Custom metadata
461461
examples?: TExample[]; // Usage examples
462-
462+
463463
// Deprecation
464464
deprecated?: {
465465
description?: string; // Deprecation reason and alternative
@@ -475,7 +475,7 @@ Many types support custom validation through the `validator` property:
475475
// Single validator
476476
{ validator: 'email' }
477477

478-
// Multiple validators
478+
// Multiple validators
479479
{ validator: ['required', 'email'] }
480480
```
481481

SPECIFICATION.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ A simple user type:
3232
{
3333
"kind": "obj",
3434
"title": "User",
35-
"fields": [
35+
"keys": [
3636
{ "kind": "field", "key": "id", "type": { "kind": "str" }, "title": "User ID" },
3737
{ "kind": "field", "key": "name", "type": { "kind": "str" } },
3838
{ "kind": "field", "key": "age", "type": { "kind": "num", "gte": 0 }, "optional": true }
@@ -246,9 +246,9 @@ Represents a fixed-length array, each position with its own type.
246246
Represents a JSON object with a defined set of fields. `obj` fields are ordered and can be required or optional. Optional fields are usually defined at the end of the `fields` array. Even if in many languages objects are unordered, the order of fields in the schema is a useful feature as the field order can be used in documentation, code generation, and serialization to binary formats.
247247

248248
**Properties:**
249-
- `fields` (array): Array of field nodes (see below).
250-
- `unknownFields` (boolean, deprecated): Allow fields not listed.
251-
- `encodeUnknownFields` (boolean): Emit unknown fields during encoding.
249+
- `keys` (array): Array of field nodes (see below).
250+
- `decodeUnknownKeys` (boolean, deprecated): Allow fields not listed.
251+
- `encodeUnknownKeys` (boolean): Emit unknown fields during encoding.
252252
- `validator` (string or array): Custom validation.
253253

254254
**Example:**
@@ -467,7 +467,7 @@ All nodes may contain the following metadata:
467467
- **Type inference:** Types can be mapped to language types using the structure.
468468
- **Optional and required fields:** Fields are required by default; set `optional: true` for optional fields.
469469
- **Type composition:** Types can be nested and composed arbitrarily.
470-
- **Unknown fields:** By default, unknown fields are rejected. Use `unknownFields: true` or `encodeUnknownFields: true` to allow or preserve them.
470+
- **Unknown fields:** By default, unknown fields are rejected. Use `decodeUnknownKeys: true` or `encodeUnknownKeys: true` to allow or preserve them.
471471

472472
---
473473

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"@jsonjoy.com/buffers": "^1.0.0",
6060
"@jsonjoy.com/codegen": "^1.0.0",
6161
"@jsonjoy.com/json-expression": "^1.1.0",
62-
"@jsonjoy.com/json-pack": "^1.9.0",
62+
"@jsonjoy.com/json-pack": "^1.10.0",
6363
"@jsonjoy.com/json-random": "^1.2.0",
6464
"@jsonjoy.com/util": "^1.9.0",
6565
"sonic-forest": "^1.2.1",

src/__demos__/json-type.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ console.log('Can compile a fast validator, which returns booleans as errors:');
119119
console.log();
120120
const validator = user.type.compileValidator({
121121
errors: 'boolean',
122-
skipObjectExtraFieldsCheck: true,
122+
skipObjectExtraKeysCheck: true,
123123
});
124124
console.log(validator.toString());
125125

@@ -128,7 +128,7 @@ console.log('Can compile a fast validator, which returns JSON strings as errors:
128128
console.log();
129129
const validator2 = user.type.compileValidator({
130130
errors: 'string',
131-
skipObjectExtraFieldsCheck: true,
131+
skipObjectExtraKeysCheck: true,
132132
});
133133
console.log(validator2.toString());
134134

@@ -137,6 +137,6 @@ console.log('Can compile a fast validator, which returns objects as errors:');
137137
console.log();
138138
const validator3 = user.type.compileValidator({
139139
errors: 'object',
140-
skipObjectExtraFieldsCheck: true,
140+
skipObjectExtraKeysCheck: true,
141141
});
142142
console.log(validator3.toString());

src/__demos__/samples.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const types = {
4343
s.prop(
4444
'meta',
4545
s.Object([], {
46-
unknownFields: true,
46+
decodeUnknownKeys: true,
4747
}),
4848
),
4949
],

0 commit comments

Comments
 (0)