@@ -43,31 +43,32 @@ import Data.Array.NonEmpty as NonEmptyArray
43
43
import Data.Codec as Codec
44
44
import Data.Codec.JSON as CJ
45
45
import Data.Codec.JSON.Record as CJ.Record
46
+ import Data.Codec.JSON.Strict as CJS
46
47
import Data.Codec.JSON.Sum as CJ.Sum
47
48
import Data.Either as Either
48
49
import Data.List as List
49
50
import Data.Map as Map
50
51
import Data.Profunctor as Profunctor
51
52
import Partial.Unsafe (unsafeCrashWith )
52
- import Registry.Internal.Codec as Internal.Codec
53
+ import Registry.Internal.Codec as Reg.Internal.Codec
54
+ import Registry.Internal.Parsing as Reg.Internal.Parsing
53
55
import Registry.License as License
54
56
import Registry.Location as Location
55
57
import Registry.PackageName as PackageName
56
58
import Registry.Range as Range
57
59
import Registry.Sha256 as Sha256
58
60
import Registry.Version as Version
59
- import Type.Proxy (Proxy (..))
60
61
61
62
type Config =
62
63
{ package :: Maybe PackageConfig
63
64
, workspace :: Maybe WorkspaceConfig
64
65
}
65
66
66
67
configCodec :: CJ.Codec Config
67
- configCodec = CJ .object
68
- $ CJ .recordPropOptional ( Proxy @" package" ) packageConfigCodec
69
- $ CJ .recordPropOptional ( Proxy @" workspace" ) workspaceConfigCodec
70
- $ CJ .record
68
+ configCodec = CJS .objectStrict
69
+ $ CJS .recordPropOptional @" package" packageConfigCodec
70
+ $ CJS .recordPropOptional @" workspace" workspaceConfigCodec
71
+ $ CJS .record
71
72
72
73
type PackageConfig =
73
74
{ name :: PackageName
@@ -81,16 +82,16 @@ type PackageConfig =
81
82
}
82
83
83
84
packageConfigCodec :: CJ.Codec PackageConfig
84
- packageConfigCodec = CJ .named " PackageConfig" $ CJ .object
85
- $ CJ .recordProp ( Proxy @" name" ) PackageName .codec
86
- $ CJ .recordPropOptional ( Proxy @" description" ) CJ .string
87
- $ CJ .recordProp ( Proxy @" dependencies" ) dependenciesCodec
88
- $ CJ .recordPropOptional ( Proxy @" build" ) packageBuildOptionsCodec
89
- $ CJ .recordPropOptional ( Proxy @" bundle" ) bundleConfigCodec
90
- $ CJ .recordPropOptional ( Proxy @" run" ) runConfigCodec
91
- $ CJ .recordPropOptional ( Proxy @" test" ) testConfigCodec
92
- $ CJ .recordPropOptional ( Proxy @" publish" ) publishConfigCodec
93
- $ CJ .record
85
+ packageConfigCodec = CJ .named " PackageConfig" $ CJS .objectStrict
86
+ $ CJS .recordProp @" name" PackageName .codec
87
+ $ CJS .recordPropOptional @" description" CJ .string
88
+ $ CJS .recordProp @" dependencies" dependenciesCodec
89
+ $ CJS .recordPropOptional @" build" packageBuildOptionsCodec
90
+ $ CJS .recordPropOptional @" bundle" bundleConfigCodec
91
+ $ CJS .recordPropOptional @" run" runConfigCodec
92
+ $ CJS .recordPropOptional @" test" testConfigCodec
93
+ $ CJS .recordPropOptional @" publish" publishConfigCodec
94
+ $ CJS .record
94
95
95
96
type PublishConfig =
96
97
{ version :: Version
@@ -101,24 +102,62 @@ type PublishConfig =
101
102
}
102
103
103
104
publishConfigCodec :: CJ.Codec PublishConfig
104
- publishConfigCodec = CJ .named " PublishConfig" $ CJ .object
105
- $ CJ .recordProp (Proxy @" version" ) Version .codec
106
- $ CJ .recordProp (Proxy @" license" ) License .codec
107
- $ CJ .recordPropOptional (Proxy @" location" ) Location .codec
108
- $ CJ .recordPropOptional (Proxy @" include" ) (CJ .array CJ .string)
109
- $ CJ .recordPropOptional (Proxy @" exclude" ) (CJ .array CJ .string)
110
- $ CJ .record
105
+ publishConfigCodec = CJ .named " PublishConfig" $ CJS .objectStrict
106
+ $ CJS .recordProp @" version" Version .codec
107
+ $ CJS .recordProp @" license" License .codec
108
+ $ CJS .recordPropOptional @" location" publishLocationCodec
109
+ $ CJS .recordPropOptional @" include" (CJ .array CJ .string)
110
+ $ CJS .recordPropOptional @" exclude" (CJ .array CJ .string)
111
+ $ CJS .record
112
+
113
+ -- This codec duplicates `Location.codec` from the Registry library, but with
114
+ -- strict parsing of fields, so that we would error out on unknown fields, thus
115
+ -- catching typos in field names. We do not want to modify the original codec in
116
+ -- the Registry library, because it's used for network communication, not for
117
+ -- reading user input, and therefore it's more important there to ignore unknown
118
+ -- fields for backwards compatibiility.
119
+ publishLocationCodec :: CJ.Codec Location
120
+ publishLocationCodec = CJ .named " Publish Location" $ Codec .codec' decode encode
121
+ where
122
+ decode json =
123
+ (Location.Git <$> Codec .decode gitCodec json)
124
+ <|> (Location.GitHub <$> Codec .decode githubCodec json)
125
+
126
+ encode = case _ of
127
+ Location.Git git -> CJ .encode gitCodec git
128
+ Location.GitHub github -> CJ .encode githubCodec github
129
+
130
+ githubCodec :: CJ.Codec Location.GitHubData
131
+ githubCodec = Profunctor .dimap toJsonRep fromJsonRep $ CJ .named " GitHub" $ CJ.Record .objectStrict
132
+ { githubOwner: CJ .string
133
+ , githubRepo: CJ .string
134
+ , subdir: CJ.Record .optional CJ .string
135
+ }
136
+ where
137
+ toJsonRep { owner, repo, subdir } = { githubOwner: owner, githubRepo: repo, subdir }
138
+ fromJsonRep { githubOwner, githubRepo, subdir } = { owner: githubOwner, repo: githubRepo, subdir }
139
+
140
+ gitCodec :: CJ.Codec Location.GitData
141
+ gitCodec = Profunctor .dimap toJsonRep fromJsonRep $ CJ .named " Git" $ CJ.Record .objectStrict
142
+ { gitUrl: Reg.Internal.Codec .parsedString Reg.Internal.Parsing .gitUrl
143
+ , subdir: CJ.Record .optional CJ .string
144
+ }
145
+ where
146
+ -- The JSON representation of the GitHub type uses 'gitUrl', but in PureScript
147
+ -- we use 'url' for convenience.
148
+ toJsonRep { url, subdir } = { gitUrl: url, subdir }
149
+ fromJsonRep { gitUrl, subdir } = { url: gitUrl, subdir }
111
150
112
151
type RunConfig =
113
152
{ main :: Maybe String
114
153
, execArgs :: Maybe (Array String )
115
154
}
116
155
117
156
runConfigCodec :: CJ.Codec RunConfig
118
- runConfigCodec = CJ .named " RunConfig" $ CJ .object
119
- $ CJ .recordPropOptional ( Proxy @" main" ) CJ .string
120
- $ CJ .recordPropOptional ( Proxy @" execArgs" ) (CJ .array CJ .string)
121
- $ CJ .record
157
+ runConfigCodec = CJ .named " RunConfig" $ CJS .objectStrict
158
+ $ CJS .recordPropOptional @" main" CJ .string
159
+ $ CJS .recordPropOptional @" execArgs" (CJ .array CJ .string)
160
+ $ CJS .record
122
161
123
162
type TestConfig =
124
163
{ main :: String
@@ -130,25 +169,25 @@ type TestConfig =
130
169
}
131
170
132
171
testConfigCodec :: CJ.Codec TestConfig
133
- testConfigCodec = CJ .named " TestConfig" $ CJ .object
134
- $ CJ .recordProp ( Proxy @" main" ) CJ .string
135
- $ CJ .recordPropOptional ( Proxy @" execArgs" ) (CJ .array CJ .string)
136
- $ CJ .recordPropOptional ( Proxy @" censorTestWarnings" ) censorBuildWarningsCodec
137
- $ CJ .recordPropOptional ( Proxy @" strict" ) CJ .boolean
138
- $ CJ .recordPropOptional ( Proxy @" pedanticPackages" ) CJ .boolean
139
- $ CJ .recordProp ( Proxy @" dependencies" ) dependenciesCodec
140
- $ CJ .record
172
+ testConfigCodec = CJ .named " TestConfig" $ CJS .objectStrict
173
+ $ CJS .recordProp @" main" CJ .string
174
+ $ CJS .recordPropOptional @" execArgs" (CJ .array CJ .string)
175
+ $ CJS .recordPropOptional @" censorTestWarnings" censorBuildWarningsCodec
176
+ $ CJS .recordPropOptional @" strict" CJ .boolean
177
+ $ CJS .recordPropOptional @" pedanticPackages" CJ .boolean
178
+ $ CJS .recordProp @" dependencies" dependenciesCodec
179
+ $ CJS .record
141
180
142
181
type BackendConfig =
143
182
{ cmd :: String
144
183
, args :: Maybe (Array String )
145
184
}
146
185
147
186
backendConfigCodec :: CJ.Codec BackendConfig
148
- backendConfigCodec = CJ .named " BackendConfig" $ CJ .object
149
- $ CJ .recordProp ( Proxy @" cmd" ) CJ .string
150
- $ CJ .recordPropOptional ( Proxy @" args" ) (CJ .array CJ .string)
151
- $ CJ .record
187
+ backendConfigCodec = CJ .named " BackendConfig" $ CJS .objectStrict
188
+ $ CJS .recordProp @" cmd" CJ .string
189
+ $ CJS .recordPropOptional @" args" (CJ .array CJ .string)
190
+ $ CJS .record
152
191
153
192
type PackageBuildOptionsInput =
154
193
{ censorProjectWarnings :: Maybe CensorBuildWarnings
@@ -157,11 +196,11 @@ type PackageBuildOptionsInput =
157
196
}
158
197
159
198
packageBuildOptionsCodec :: CJ.Codec PackageBuildOptionsInput
160
- packageBuildOptionsCodec = CJ .named " PackageBuildOptionsInput" $ CJ .object
161
- $ CJ .recordPropOptional ( Proxy @" censorProjectWarnings" ) censorBuildWarningsCodec
162
- $ CJ .recordPropOptional ( Proxy @" strict" ) CJ .boolean
163
- $ CJ .recordPropOptional ( Proxy @" pedanticPackages" ) CJ .boolean
164
- $ CJ .record
199
+ packageBuildOptionsCodec = CJ .named " PackageBuildOptionsInput" $ CJS .objectStrict
200
+ $ CJS .recordPropOptional @" censorProjectWarnings" censorBuildWarningsCodec
201
+ $ CJS .recordPropOptional @" strict" CJ .boolean
202
+ $ CJS .recordPropOptional @" pedanticPackages" CJ .boolean
203
+ $ CJS .record
165
204
166
205
type BundleConfig =
167
206
{ minify :: Maybe Boolean
@@ -173,17 +212,19 @@ type BundleConfig =
173
212
}
174
213
175
214
bundleConfigCodec :: CJ.Codec BundleConfig
176
- bundleConfigCodec = CJ .named " BundleConfig" $ CJ .object
177
- $ CJ .recordPropOptional ( Proxy @" minify" ) CJ .boolean
178
- $ CJ .recordPropOptional ( Proxy @" module" ) CJ .string
179
- $ CJ .recordPropOptional ( Proxy @" outfile" ) CJ .string
180
- $ CJ .recordPropOptional ( Proxy @" platform" ) bundlePlatformCodec
181
- $ CJ .recordPropOptional ( Proxy @" type" ) bundleTypeCodec
182
- $ CJ .recordPropOptional ( Proxy @" extraArgs" ) (CJ .array CJ .string)
183
- $ CJ .record
215
+ bundleConfigCodec = CJ .named " BundleConfig" $ CJS .objectStrict
216
+ $ CJS .recordPropOptional @" minify" CJ .boolean
217
+ $ CJS .recordPropOptional @" module" CJ .string
218
+ $ CJS .recordPropOptional @" outfile" CJ .string
219
+ $ CJS .recordPropOptional @" platform" bundlePlatformCodec
220
+ $ CJS .recordPropOptional @" type" bundleTypeCodec
221
+ $ CJS .recordPropOptional @" extraArgs" (CJ .array CJ .string)
222
+ $ CJS .record
184
223
185
224
data BundlePlatform = BundleNode | BundleBrowser
186
225
226
+ derive instance Eq BundlePlatform
227
+
187
228
instance Show BundlePlatform where
188
229
show = case _ of
189
230
BundleNode -> " node"
@@ -202,6 +243,8 @@ bundlePlatformCodec = CJ.Sum.enumSum show (parsePlatform)
202
243
-- App bundles with a main fn, while Module does not include a main.
203
244
data BundleType = BundleApp | BundleModule
204
245
246
+ derive instance Eq BundleType
247
+
205
248
instance Show BundleType where
206
249
show = case _ of
207
250
BundleApp -> " app"
@@ -238,7 +281,7 @@ instance Monoid Dependencies where
238
281
dependenciesCodec :: CJ.Codec Dependencies
239
282
dependenciesCodec = Profunctor .dimap to from $ CJ .array dependencyCodec
240
283
where
241
- packageSingletonCodec = Internal.Codec .packageMap spagoRangeCodec
284
+ packageSingletonCodec = Reg. Internal.Codec .packageMap spagoRangeCodec
242
285
243
286
to :: Dependencies -> Array (Either PackageName (Map PackageName Range ))
244
287
to (Dependencies deps) =
@@ -291,12 +334,12 @@ type WorkspaceConfig =
291
334
}
292
335
293
336
workspaceConfigCodec :: CJ.Codec WorkspaceConfig
294
- workspaceConfigCodec = CJ .named " WorkspaceConfig" $ CJ .object
295
- $ CJ .recordPropOptional ( Proxy @" packageSet" ) setAddressCodec
296
- $ CJ .recordPropOptional ( Proxy @" backend" ) backendConfigCodec
297
- $ CJ .recordPropOptional ( Proxy @" buildOpts" ) buildOptionsCodec
298
- $ CJ .recordPropOptional ( Proxy @" extraPackages" ) ( Internal.Codec .packageMap extraPackageCodec)
299
- $ CJ .record
337
+ workspaceConfigCodec = CJ .named " WorkspaceConfig" $ CJS .objectStrict
338
+ $ CJS .recordPropOptional @" packageSet" setAddressCodec
339
+ $ CJS .recordPropOptional @" backend" backendConfigCodec
340
+ $ CJS .recordPropOptional @" buildOpts" buildOptionsCodec
341
+ $ CJS .recordPropOptional @" extraPackages" ( Reg. Internal.Codec .packageMap extraPackageCodec)
342
+ $ CJS .record
300
343
301
344
type WorkspaceBuildOptionsInput =
302
345
{ output :: Maybe FilePath
@@ -305,11 +348,11 @@ type WorkspaceBuildOptionsInput =
305
348
}
306
349
307
350
buildOptionsCodec :: CJ.Codec WorkspaceBuildOptionsInput
308
- buildOptionsCodec = CJ .named " WorkspaceBuildOptionsInput" $ CJ .object
309
- $ CJ .recordPropOptional ( Proxy @" output" ) CJ .string
310
- $ CJ .recordPropOptional ( Proxy @" censorLibraryWarnings" ) censorBuildWarningsCodec
311
- $ CJ .recordPropOptional ( Proxy @" statVerbosity" ) statVerbosityCodec
312
- $ CJ .record
351
+ buildOptionsCodec = CJ .named " WorkspaceBuildOptionsInput" $ CJS .objectStrict
352
+ $ CJS .recordPropOptional @" output" CJ .string
353
+ $ CJS .recordPropOptional @" censorLibraryWarnings" censorBuildWarningsCodec
354
+ $ CJS .recordPropOptional @" statVerbosity" statVerbosityCodec
355
+ $ CJS .record
313
356
314
357
data CensorBuildWarnings
315
358
= CensorAllWarnings
@@ -361,13 +404,15 @@ warningCensorTestCodec = Codec.codec' decode encode
361
404
byCode = ByCode <$> Codec .decode CJ .string json
362
405
byPrefix = (ByMessagePrefix <<< _.byPrefix) <$> Codec .decode byMessagePrefixCodec json
363
406
364
- byMessagePrefixCodec = CJ .named " ByMessagePrefix" $ CJ.Record .object { byPrefix: CJ .string }
407
+ byMessagePrefixCodec = CJ .named " ByMessagePrefix" $ CJ.Record .objectStrict { byPrefix: CJ .string }
365
408
366
409
data StatVerbosity
367
410
= NoStats
368
411
| CompactStats
369
412
| VerboseStats
370
413
414
+ derive instance Eq StatVerbosity
415
+
371
416
instance Show StatVerbosity where
372
417
show = case _ of
373
418
NoStats -> " NoStats"
@@ -397,9 +442,9 @@ derive instance Eq SetAddress
397
442
setAddressCodec :: CJ.Codec SetAddress
398
443
setAddressCodec = Codec .codec' decode encode
399
444
where
400
- setFromRegistryCodec = CJ .named " SetFromRegistry" $ CJ.Record .object { registry: Version .codec }
401
- setFromUrlCodec = CJ .named " SetFromUrl" $ CJ.Record .object { url: CJ .string, hash: CJ.Record .optional Sha256 .codec }
402
- setFromPathCodec = CJ .named " SetFromPath" $ CJ.Record .object { path: CJ .string }
445
+ setFromRegistryCodec = CJ .named " SetFromRegistry" $ CJ.Record .objectStrict { registry: Version .codec }
446
+ setFromUrlCodec = CJ .named " SetFromUrl" $ CJ.Record .objectStrict { url: CJ .string, hash: CJ.Record .optional Sha256 .codec }
447
+ setFromPathCodec = CJ .named " SetFromPath" $ CJ.Record .objectStrict { path: CJ .string }
403
448
404
449
encode (SetFromRegistry r) = CJ .encode setFromRegistryCodec r
405
450
encode (SetFromUrl u) = CJ .encode setFromUrlCodec u
@@ -427,7 +472,7 @@ extraPackageCodec = Codec.codec' decode encode
427
472
type LocalPackage = { path :: FilePath }
428
473
429
474
localPackageCodec :: CJ.Codec LocalPackage
430
- localPackageCodec = CJ .named " LocalPackage" $ CJ.Record .object { path: CJ .string }
475
+ localPackageCodec = CJ .named " LocalPackage" $ CJ.Record .objectStrict { path: CJ .string }
431
476
432
477
data RemotePackage
433
478
= RemoteGitPackage GitPackage
@@ -455,12 +500,12 @@ type GitPackage =
455
500
}
456
501
457
502
gitPackageCodec :: CJ.Codec GitPackage
458
- gitPackageCodec = CJ .named " GitPackage" $ CJ .object
459
- $ CJ .recordProp ( Proxy @" git" ) CJ .string
460
- $ CJ .recordProp ( Proxy @" ref" ) CJ .string
461
- $ CJ .recordPropOptional ( Proxy @" subdir" ) CJ .string
462
- $ CJ .recordPropOptional ( Proxy @" dependencies" ) dependenciesCodec
463
- $ CJ .record
503
+ gitPackageCodec = CJ .named " GitPackage" $ CJS .objectStrict
504
+ $ CJS .recordProp @" git" CJ .string
505
+ $ CJS .recordProp @" ref" CJ .string
506
+ $ CJS .recordPropOptional @" subdir" CJ .string
507
+ $ CJS .recordPropOptional @" dependencies" dependenciesCodec
508
+ $ CJS .record
464
509
465
510
-- | The format of a legacy packages.json package set entry for an individual
466
511
-- | package.
@@ -471,8 +516,8 @@ type LegacyPackageSetEntry =
471
516
}
472
517
473
518
legacyPackageSetEntryCodec :: CJ.Codec LegacyPackageSetEntry
474
- legacyPackageSetEntryCodec = CJ .named " LegacyPackageSetEntry" $ CJ .object
475
- $ CJ .recordProp ( Proxy @" repo" ) CJ .string
476
- $ CJ .recordProp ( Proxy @" version" ) CJ .string
477
- $ CJ .recordProp ( Proxy @" dependencies" ) (CJ .array PackageName .codec)
478
- $ CJ .record
519
+ legacyPackageSetEntryCodec = CJ .named " LegacyPackageSetEntry" $ CJS .objectStrict
520
+ $ CJS .recordProp @" repo" CJ .string
521
+ $ CJS .recordProp @" version" CJ .string
522
+ $ CJS .recordProp @" dependencies" (CJ .array PackageName .codec)
523
+ $ CJS .record
0 commit comments