Skip to content

Commit b552f86

Browse files
committed
Add schema record helper
1 parent 64084e5 commit b552f86

15 files changed

Lines changed: 75 additions & 71 deletions

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ type Person = { Id: int; Name: string }
2222
let makePerson id name = { Id = id; Name = name }
2323
2424
let personSchema =
25-
Schema.define<Person>
26-
|> Schema.construct makePerson
25+
Schema.record makePerson
2726
|> Schema.field "id" _.Id
2827
|> Schema.field "name" _.Name
2928
|> Schema.build

docs/CONFIG_CONTRACTS.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ let makeAppConfig mode retryCount labels =
8383
}
8484
8585
let appConfigSchema =
86-
Schema.define<AppConfig>
87-
|> Schema.construct makeAppConfig
86+
Schema.record makeAppConfig
8887
|> Schema.fieldWith "mode" _.Mode (Schema.string |> Schema.missingAsValue "strict")
8988
|> Schema.fieldWith "retry_count" _.RetryCount (Schema.int |> Schema.missingAsValue 3)
9089
|> Schema.fieldWith "labels" _.Labels (Schema.list Schema.string |> Schema.missingAsValue [])
@@ -113,8 +112,7 @@ let makeServiceConfig region labels =
113112
}
114113
115114
let serviceConfigSchema =
116-
Schema.define<ServiceConfig>
117-
|> Schema.construct makeServiceConfig
115+
Schema.record makeServiceConfig
118116
|> Schema.fieldWith "region" _.Region (Schema.string |> Schema.nullAsValue "global")
119117
|> Schema.fieldWith "labels" _.Labels (Schema.list Schema.string |> Schema.emptyCollectionAsValue [ "general" ])
120118
|> Schema.build
@@ -361,8 +359,7 @@ module Schemas =
361359
}
362360
363361
let appConfigV2 =
364-
Schema.define<AppConfigV2>
365-
|> Schema.construct makeAppConfigV2
362+
Schema.record makeAppConfigV2
366363
|> Schema.field "service_url" _.ServiceUrl
367364
|> Schema.field "retry_count" _.RetryCount
368365
|> Schema.field "mode" _.Mode
@@ -377,8 +374,7 @@ module Schemas =
377374
{ Version = version; Config = config }
378375
379376
let versionEnvelope inner =
380-
Schema.define<VersionEnvelope<'T>>
381-
|> Schema.construct makeVersionEnvelope
377+
Schema.record makeVersionEnvelope
382378
|> Schema.field "version" _.Version
383379
|> Schema.fieldWith "config" _.Config inner
384380
|> Schema.build

docs/GETTING_STARTED.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ type Person = { Id: int; Name: string }
1818
let makePerson id name = { Id = id; Name = name }
1919
2020
let personSchema =
21-
Schema.define<Person>
22-
|> Schema.construct makePerson
21+
Schema.record makePerson
2322
|> Schema.field "id" _.Id
2423
|> Schema.field "name" _.Name
2524
|> Schema.build
@@ -41,8 +40,7 @@ That is the normal shape of the library:
4140

4241
Read the builder pipeline from top to bottom:
4342

44-
- `Schema.define<Person>` says which value the schema describes
45-
- `Schema.construct makePerson` says how decode rebuilds the value
43+
- `Schema.record makePerson` says which value the schema describes and how decode rebuilds it
4644
- `Schema.field "id" _.Id` maps the wire field `"id"` to the record field `Id`
4745
- `Schema.build` finishes the schema
4846

@@ -62,8 +60,7 @@ If the schema is only being authored inline at the end of a short example, `Json
6260

6361
```fsharp
6462
let codec =
65-
Schema.define<Person>
66-
|> Schema.construct makePerson
63+
Schema.record makePerson
6764
|> Schema.field "id" _.Id
6865
|> Schema.field "name" _.Name
6966
|> Json.buildAndCompile
@@ -83,15 +80,13 @@ type Person = { Id: int; Name: string; Home: Address }
8380
let makePerson id name home = { Id = id; Name = name; Home = home }
8481
8582
let addressSchema =
86-
Schema.define<Address>
87-
|> Schema.construct makeAddress
83+
Schema.record makeAddress
8884
|> Schema.field "street" _.Street
8985
|> Schema.field "city" _.City
9086
|> Schema.build
9187
9288
let personSchema =
93-
Schema.define<Person>
94-
|> Schema.construct makePerson
89+
Schema.record makePerson
9590
|> Schema.field "id" _.Id
9691
|> Schema.field "name" _.Name
9792
|> Schema.fieldWith "home" _.Home addressSchema

docs/HOW_TO_EXPORT_JSON_SCHEMA.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ type Person = { Id: int; Name: string }
1818
let makePerson id name = { Id = id; Name = name }
1919
2020
let personSchema =
21-
Schema.define<Person>
22-
|> Schema.construct makePerson
21+
Schema.record makePerson
2322
|> Schema.fieldInfer "id" _.Id
2423
|> Schema.fieldInfer "name" _.Name
2524
|> Schema.build

docs/HOW_TO_MODEL_A_BASIC_RECORD.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ type Person = { Id: int; Name: string }
99
let makePerson id name = { Id = id; Name = name }
1010
1111
let codec =
12-
Schema.define<Person>
13-
|> Schema.construct makePerson
12+
Schema.record makePerson
1413
|> Schema.field "id" _.Id
1514
|> Schema.field "name" _.Name
1615
|> Json.buildAndCompile
1716
```
1817

19-
This is the smallest authored schema shape: define the record target, provide the constructor, then map each field explicitly and finish with `Json.buildAndCompile`.
18+
This is the smallest authored schema shape: start the record with its constructor, then map each field explicitly and finish with `Json.buildAndCompile`.

docs/HOW_TO_MODEL_A_NESTED_RECORD.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ type Person = { Id: int; Name: string; Home: Address }
1212
let makePerson id name home = { Id = id; Name = name; Home = home }
1313
1414
let addressSchema =
15-
Schema.define<Address>
16-
|> Schema.construct makeAddress
15+
Schema.record makeAddress
1716
|> Schema.field "street" _.Street
1817
|> Schema.field "city" _.City
1918
|> Schema.build
2019
2120
let personSchema =
22-
Schema.define<Person>
23-
|> Schema.construct makePerson
21+
Schema.record makePerson
2422
|> Schema.field "id" _.Id
2523
|> Schema.field "name" _.Name
2624
|> Schema.fieldWith "home" _.Home addressSchema

docs/HOW_TO_MODEL_A_VALIDATED_WRAPPER.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ let userIdSchema =
2222
|> Schema.tryMap UserId.create UserId.value
2323
2424
let accountSchema =
25-
Schema.define<Account>
26-
|> Schema.construct makeAccount
25+
Schema.record makeAccount
2726
|> Schema.fieldWith "id" _.Id userIdSchema
2827
|> Schema.field "name" _.Name
2928
|> Schema.build

docs/HOW_TO_MODEL_A_VERSIONED_CONTRACT.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ let makeSettingsV2 version mode region =
1515
{ Version = version; Mode = mode; Region = region }
1616
1717
let settingsV2Schema =
18-
Schema.define<SettingsV2>
19-
|> Schema.construct makeSettingsV2
18+
Schema.record makeSettingsV2
2019
|> Schema.fieldWith "version" _.Version (
2120
Schema.int
2221
|> Schema.tryMap

docs/HOW_TO_MODEL_COMMON_CONTRACT_PATTERNS.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ Use this page as a quick jump list when you know the kind of schema you need and
55
All examples stay on the stable authored DSL:
66

77
```fsharp
8-
Schema.define<'T>
9-
|> Schema.construct ctor
8+
Schema.record ctor
109
|> Schema.field ...
1110
|> Schema.build
1211
```

docs/INTRODUCTION.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ That schema is the important idea in the library:
1616
Most authored schemas follow one stable shape:
1717

1818
```fsharp
19-
Schema.define<'T>
20-
|> Schema.construct ctor
19+
Schema.record ctor
2120
|> Schema.field ...
2221
|> Schema.build
2322
```
2423

2524
Read that pipeline from top to bottom:
2625

27-
- `Schema.define<'T>` says which value the schema describes
28-
- `Schema.construct ctor` says how decode rebuilds the value
29-
- each `Schema.field` or `Schema.fieldWith` maps one wire field to one domain field
26+
- `Schema.record ctor` says which value the schema describes and how decode rebuilds it
27+
- each `Schema.field` maps one wire field to one domain field
3028
- `Schema.build` finishes the authored schema
3129

3230
Then you compile that schema into a codec for the format boundary you need:

0 commit comments

Comments
 (0)