lawspec 0.13.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API-MIGRATION.md +24 -0
- package/LANGUAGE.md +118 -9
- package/PRIMITIVES.md +1 -1
- package/README.md +30 -14
- package/REFINEMENTS.md +1 -1
- package/RELEASE-0.14.md +52 -0
- package/bin/lawspec.mjs +80 -5
- package/build.json +28 -22
- package/core.wasm +0 -0
- package/examples/packages/orders/lawspec.json +7 -0
- package/examples/packages/orders/orders.lawspec +57 -0
- package/examples/packages/shop-domain/lawspec-package.json +5 -0
- package/examples/packages/shop-domain/src/domain.lawspec +49 -0
- package/index.d.ts +24 -0
- package/package.json +2 -2
package/API-MIGRATION.md
CHANGED
|
@@ -294,3 +294,27 @@ changes. Generated definition code no longer re-checks proved postconditions.
|
|
|
294
294
|
including a `wrapper` constraint, checked whenever a value is constructed or
|
|
295
295
|
decoded. Its `declaration` is the constructor identity and its `status` is
|
|
296
296
|
`runtime-checked`. The TypeScript API names these records `ObligationEvidence`.
|
|
297
|
+
|
|
298
|
+
## Imports and packages (0.14)
|
|
299
|
+
|
|
300
|
+
Requests on schema 3 or 4 may add three optional fields:
|
|
301
|
+
|
|
302
|
+
- `dependencies`: `Record<string, string>`, package names and version ranges the
|
|
303
|
+
request's own sources require;
|
|
304
|
+
- `packages`: `Package[]`, each `{name, version, dependencies?, sources}`, the
|
|
305
|
+
complete set of packages those sources require directly or indirectly;
|
|
306
|
+
- `package`: `{name, version}` when the request's own sources are themselves a
|
|
307
|
+
package, whose units must then be named after it.
|
|
308
|
+
|
|
309
|
+
Package sources are compiled with the request's sources. When any of these fields
|
|
310
|
+
is present, results add `packages: PackageView[]`, each with `name`, `version`,
|
|
311
|
+
`dependencies` and the package's `units`, and `project: {package?,
|
|
312
|
+
dependencies}`. Package errors use the diagnostic code `package`; import errors
|
|
313
|
+
use `import`. Requests without these fields produce the same results as before.
|
|
314
|
+
A compiler older than 0.14 ignores the fields and reports the imports it cannot
|
|
315
|
+
resolve.
|
|
316
|
+
|
|
317
|
+
Imported declarations need no new wire forms. Data declarations keep the ID of
|
|
318
|
+
the unit that declares them. An imported checked definition appears among the
|
|
319
|
+
importing unit's definitions with a name derived from its unit
|
|
320
|
+
(`shop.orders::shopDomainCentsOf`).
|
package/LANGUAGE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# LawSpec language and compiler boundary (0.
|
|
1
|
+
# LawSpec language and compiler boundary (0.14)
|
|
2
2
|
|
|
3
3
|
LawSpec describes portable laws, concrete examples, and adapter contracts. The
|
|
4
4
|
compiler is written in Haskell. Rust is an output backend alongside Java, Python,
|
|
@@ -261,6 +261,107 @@ Because each state is its own type, a `ValidatedOrder` can only hold checked
|
|
|
261
261
|
values, and a step that needs one cannot be given raw input. See the
|
|
262
262
|
[domain modeling example](examples/specs/domain_modeling.lawspec).
|
|
263
263
|
|
|
264
|
+
## Imports and packages
|
|
265
|
+
|
|
266
|
+
### Importing units
|
|
267
|
+
|
|
268
|
+
A unit may import other units after its `unit` line:
|
|
269
|
+
|
|
270
|
+
```lawspec
|
|
271
|
+
unit shop.orders
|
|
272
|
+
import shop.domain as domain (Money, Cents, `commutative`)
|
|
273
|
+
|
|
274
|
+
type Currency is | Usd | Gbp end
|
|
275
|
+
settlement :: Currency -> domain.Currency
|
|
276
|
+
|
|
277
|
+
law `dollars settle in dollars` is
|
|
278
|
+
definition is
|
|
279
|
+
settlement Usd = domain.Usd
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
`import U` makes every declaration of `U` available qualified by an alias, which
|
|
285
|
+
defaults to the unit's last name segment (`import shop.domain` gives `domain`);
|
|
286
|
+
`as` names another alias. A parenthesized list also makes the listed names
|
|
287
|
+
available unqualified. Listing a data type or wrapper brings its constructors and
|
|
288
|
+
its generated functions (`valueOf<Name>`, indexed-family measures) with it; list
|
|
289
|
+
a law by its quoted name. Qualified names are written without spaces around the
|
|
290
|
+
dot (`domain.Usd`); write `f . g` with spaces to compose a function whose name is
|
|
291
|
+
also an alias.
|
|
292
|
+
|
|
293
|
+
What can be imported:
|
|
294
|
+
|
|
295
|
+
- data types, wrappers and indexed families, with their constructors;
|
|
296
|
+
- refinements;
|
|
297
|
+
- checked definitions;
|
|
298
|
+
- generic laws, that is laws with parameters, which the importer applies to its
|
|
299
|
+
own adapters (`` `commutative` total ``).
|
|
300
|
+
|
|
301
|
+
Adapter signatures and laws without parameters belong to their unit: they are the
|
|
302
|
+
unit's own contract with its native code and are tested there. Referring to
|
|
303
|
+
another unit's adapter is an error, as is importing a declaration that uses one.
|
|
304
|
+
|
|
305
|
+
Names are scoped to their unit. Two units may both declare `Currency`, `Usd` or a
|
|
306
|
+
definition `size`; `domain.Usd` and the local `Usd` are different constructors.
|
|
307
|
+
Targets with a single data namespace qualify the colliding native names by unit
|
|
308
|
+
(`ShopDomainCurrency`, `ShopOrdersCurrency`). An unqualified name that is both
|
|
309
|
+
listed in an import and declared locally is an error, as is one listed from two
|
|
310
|
+
units. Imports are not re-exported: a unit uses what it imports itself.
|
|
311
|
+
|
|
312
|
+
Imports are resolved before type checking. A data type stays with the unit that
|
|
313
|
+
declares it, so values of `domain.Money` are the same values in every importing
|
|
314
|
+
unit. Imported refinements, checked definitions and generic laws are copied into
|
|
315
|
+
the importing unit, together with everything they use, under names derived from
|
|
316
|
+
their unit (`domain.centsOf` is emitted as `shopDomainCentsOf`). Core and all
|
|
317
|
+
eight targets therefore need nothing new. Import cycles, unknown units and
|
|
318
|
+
missing names are reported at the import.
|
|
319
|
+
|
|
320
|
+
### Packages
|
|
321
|
+
|
|
322
|
+
A package is a named, versioned directory of units, described by
|
|
323
|
+
`lawspec-package.json`:
|
|
324
|
+
|
|
325
|
+
```json
|
|
326
|
+
{
|
|
327
|
+
"name": "shop.domain",
|
|
328
|
+
"version": "1.2.0",
|
|
329
|
+
"sources": ["src"],
|
|
330
|
+
"dependencies": {}
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Every unit of a package is named after it: `shop.domain` or `shop.domain.<name>`.
|
|
335
|
+
A project, or another package, declares the packages it depends on with version
|
|
336
|
+
ranges, and lists the package directories to load:
|
|
337
|
+
|
|
338
|
+
```json
|
|
339
|
+
{
|
|
340
|
+
"version": 1,
|
|
341
|
+
"sources": ["orders.lawspec"],
|
|
342
|
+
"dependencies": {"shop.domain": "^1.0.0"},
|
|
343
|
+
"packages": ["../shop-domain"],
|
|
344
|
+
"targets": [{"language": "java", "root": "java"}]
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
A unit may import the units of its own package (or project) and of the packages
|
|
349
|
+
it depends on directly. Versions are `MAJOR.MINOR.PATCH` with an optional
|
|
350
|
+
prerelease. Ranges combine `1.2.3` (exactly), `^1.2.3`, `~1.2.3`, `>=`, `>`,
|
|
351
|
+
`<=`, `<` and `*`, with npm's meaning. Resolution is exact: one version of each
|
|
352
|
+
package is supplied, every range must accept it, a package that nothing requires
|
|
353
|
+
is rejected, and package dependency cycles are rejected. Project units may not
|
|
354
|
+
use a dependency's namespace.
|
|
355
|
+
|
|
356
|
+
A package publishes a behavioral contract. Its types, refinements, definitions
|
|
357
|
+
and generic laws are a library, and its adapter signatures and concrete laws are
|
|
358
|
+
obligations: a project that depends on the package implements those adapters in
|
|
359
|
+
its own native code and is tested against the package's laws, with the same
|
|
360
|
+
user-owned adapter files as for its own units. `lawspec package` checks a
|
|
361
|
+
package on its own and summarizes its units, laws and data types. A package
|
|
362
|
+
directory can be distributed any way that delivers the directory, for example
|
|
363
|
+
as an npm package. See the [package example](examples/packages).
|
|
364
|
+
|
|
264
365
|
## Total definitions
|
|
265
366
|
|
|
266
367
|
A unit can supply an implementation as a checked total definition:
|
|
@@ -333,8 +434,8 @@ entry points enforce the same contracts. See [refined definitions](REFINEMENTS.m
|
|
|
333
434
|
|
|
334
435
|
## Source and declarations
|
|
335
436
|
|
|
336
|
-
A source has one named `unit`, function signatures, data
|
|
337
|
-
definitions, reusable refinements, and laws. Qualified unit names determine target module/package paths. Function
|
|
437
|
+
A source has one named `unit`, its imports, function signatures, data
|
|
438
|
+
declarations, checked definitions, reusable refinements, and laws. Qualified unit names determine target module/package paths. Function
|
|
338
439
|
signatures are curried: `a -> b -> c` takes two inputs and returns `c`. Parentheses
|
|
339
440
|
group types and expressions. Comments start with `--` and run to the line end.
|
|
340
441
|
|
|
@@ -342,7 +443,9 @@ The following grammar summarizes the main forms; the parser and executable
|
|
|
342
443
|
compiler tests specify lexical details:
|
|
343
444
|
|
|
344
445
|
```text
|
|
345
|
-
source = "unit" qualified-name declaration*
|
|
446
|
+
source = "unit" qualified-name import* declaration*
|
|
447
|
+
import = "import" qualified-name ["as" name]
|
|
448
|
+
["(" (name | quoted-name) ("," (name | quoted-name))* ")"]
|
|
346
449
|
declaration = name "::" type | law | refinement | data-type | function
|
|
347
450
|
data-type = "type" name ("(" name "::" "Type" ")")*
|
|
348
451
|
"is" constructor* "end"
|
|
@@ -500,12 +603,18 @@ GADTs that refine type arguments.
|
|
|
500
603
|
checked step types and a generated railway composition law.
|
|
501
604
|
- See [domain modeling](#domain-modeling).
|
|
502
605
|
|
|
503
|
-
### 0.14 Cross-unit imports and packages
|
|
606
|
+
### 0.14 Cross-unit imports and packages (released)
|
|
607
|
+
|
|
608
|
+
- Reusable law, type and refinement libraries: `import` brings another unit's
|
|
609
|
+
types, refinements, checked definitions and generic laws into scope.
|
|
610
|
+
- Versioning and namespacing: packages have names, semantic versions and
|
|
611
|
+
dependency ranges, units live in their package's namespace, and constructor
|
|
612
|
+
names are scoped to their unit.
|
|
613
|
+
- Publishable behavioral contracts: a package's adapter signatures and laws are
|
|
614
|
+
implemented and tested by every project that depends on it.
|
|
615
|
+
- See [imports and packages](#imports-and-packages).
|
|
504
616
|
|
|
505
|
-
|
|
506
|
-
- Versioning and namespacing, including constructor names scoped to their unit.
|
|
507
|
-
Today every unit compiled together needs distinct constructor names.
|
|
508
|
-
- Publishable behavioral contracts.
|
|
617
|
+
Still open: re-exports, and several versions of one package in one build.
|
|
509
618
|
|
|
510
619
|
### 0.15 Evidence/discharge model
|
|
511
620
|
|
package/PRIMITIVES.md
CHANGED
package/README.md
CHANGED
|
@@ -79,8 +79,19 @@ railway composition of its steps. See
|
|
|
79
79
|
[example](examples/specs/domain_modeling.lawspec) and the
|
|
80
80
|
[release notes](RELEASE-0.13.md).
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
## Imports and packages in 0.14
|
|
83
|
+
|
|
84
|
+
LawSpec 0.14 lets units import each other and groups units into versioned
|
|
85
|
+
packages. ``import shop.domain as domain (Money, `commutative`)`` brings in
|
|
86
|
+
another unit's types, refinements, checked definitions and generic laws, qualified
|
|
87
|
+
or by name. Names are scoped to their unit, so two units may both declare a
|
|
88
|
+
`Currency`. A package is a directory with a `lawspec-package.json`; a project
|
|
89
|
+
names the packages it depends on with semantic-version ranges, and implements
|
|
90
|
+
and tests the adapters of the contracts they publish. See
|
|
91
|
+
[imports and packages](LANGUAGE.md#imports-and-packages), the
|
|
92
|
+
[package example](examples/packages) and the [release notes](RELEASE-0.14.md).
|
|
93
|
+
|
|
94
|
+
Planned: 0.15 evidence reporting. See the [roadmap](LANGUAGE.md#roadmap).
|
|
84
95
|
|
|
85
96
|
## Install and try it
|
|
86
97
|
|
|
@@ -91,7 +102,7 @@ support to use it; GitHub currently uses the Haskell fallback.
|
|
|
91
102
|
Install [LawSpec from npm](https://www.npmjs.com/package/lawspec):
|
|
92
103
|
|
|
93
104
|
```sh
|
|
94
|
-
npm install --save-dev lawspec@0.
|
|
105
|
+
npm install --save-dev lawspec@0.14.0
|
|
95
106
|
npx lawspec --version
|
|
96
107
|
```
|
|
97
108
|
|
|
@@ -105,8 +116,8 @@ local dependencies so LawSpec can create its `package.json` and test script:
|
|
|
105
116
|
```sh
|
|
106
117
|
mkdir lawspec-example
|
|
107
118
|
cd lawspec-example
|
|
108
|
-
npm exec --package=lawspec@0.
|
|
109
|
-
npm install --save-dev lawspec@0.
|
|
119
|
+
npm exec --package=lawspec@0.14.0 -- lawspec init --target javascript
|
|
120
|
+
npm install --save-dev lawspec@0.14.0
|
|
110
121
|
npx lawspec check
|
|
111
122
|
npx lawspec explain 'example.atoi_codec::itoa and then atoi yields a'
|
|
112
123
|
npx lawspec doctor
|
|
@@ -173,6 +184,9 @@ preserved, and setup instructions describe the changes you need to make yourself
|
|
|
173
184
|
```
|
|
174
185
|
|
|
175
186
|
Source entries are files or directories, relative to the configuration file.
|
|
187
|
+
`dependencies` maps package names to version ranges, and `packages` lists the
|
|
188
|
+
package directories to load (each with a `lawspec-package.json`); see
|
|
189
|
+
[packages](LANGUAGE.md#packages).
|
|
176
190
|
Directories are scanned for `.lawspec` files. Every target has its own project
|
|
177
191
|
root. Use `init --target python --project python` to add a target; `--config`
|
|
178
192
|
selects a different configuration file. Targets can override `sourceDir` and
|
|
@@ -199,6 +213,8 @@ Commands:
|
|
|
199
213
|
- `generate`: check environments, validate every output, then write artifacts.
|
|
200
214
|
- `generate --dry-run`: show proposed file operations without applying them.
|
|
201
215
|
- `generate --check`: fail when generated files need updating, without writing.
|
|
216
|
+
- `package [--project <directory>]`: check a package directory on its own and
|
|
217
|
+
summarize its units, laws and data types.
|
|
202
218
|
|
|
203
219
|
Use `--target <language>` to select a configured language, and `--json` for
|
|
204
220
|
machine-readable check, explanation, doctor and generation output. Generation
|
|
@@ -316,7 +332,7 @@ reusable laws accept these curried functions, their partial applications, and
|
|
|
316
332
|
scalar parameters. Quantified test inputs remain scalar.
|
|
317
333
|
|
|
318
334
|
The prelude defines the following laws. Every row has an executable example in
|
|
319
|
-
[algebra.lawspec](https://github.com/brain-fuel/lawspec/blob/v0.
|
|
335
|
+
[algebra.lawspec](https://github.com/brain-fuel/lawspec/blob/v0.14.0/examples/specs/algebra.lawspec), including both sides of every
|
|
320
336
|
combined law. `f` and `g` are binary operations, `inverse` is unary, and `e` and
|
|
321
337
|
`zero` are scalar parameters. All these laws require equality of the element type.
|
|
322
338
|
|
|
@@ -384,7 +400,7 @@ their entire consequence. Every conjunct is type-checked and emitted. As with
|
|
|
384
400
|
existing assertions, the first failure stops that individual test. `and` is now
|
|
385
401
|
a reserved word.
|
|
386
402
|
|
|
387
|
-
[Currying examples](https://github.com/brain-fuel/lawspec/blob/v0.
|
|
403
|
+
[Currying examples](https://github.com/brain-fuel/lawspec/blob/v0.14.0/examples/specs/currying.lawspec) demonstrate a four-argument
|
|
388
404
|
function partially applied twice, a formatter with four heterogeneous arguments,
|
|
389
405
|
and composition after partial application. Each example states its exact outputs.
|
|
390
406
|
Run `node npm/bin/lawspec.mjs examples` after rebuilding to inspect all nine units
|
|
@@ -436,7 +452,7 @@ law `valid ports round trip` is
|
|
|
436
452
|
end
|
|
437
453
|
```
|
|
438
454
|
|
|
439
|
-
The [complete port example](https://github.com/brain-fuel/lawspec/blob/v0.
|
|
455
|
+
The [complete port example](https://github.com/brain-fuel/lawspec/blob/v0.14.0/examples/specs/parse_port.lawspec)
|
|
440
456
|
defines valid ports as 1–65535, and covers both endpoints, ordinary ports, zero,
|
|
441
457
|
negative values, and 65536. All explicit `expect` assertions run regardless of
|
|
442
458
|
the law's condition. A false condition skips only the consequence: invalid ports
|
|
@@ -454,7 +470,7 @@ The prelude includes `satisfies predicate` (the predicate holds for every input)
|
|
|
454
470
|
and `left inverse when predicate parse render` (the guarded round trip above).
|
|
455
471
|
These reusable laws preserve the condition and its lexical bindings when expanded.
|
|
456
472
|
`equivalent` can also compare two predicates, since `Bool` supports equality.
|
|
457
|
-
The [Boolean flags example](https://github.com/brain-fuel/lawspec/blob/v0.
|
|
473
|
+
The [Boolean flags example](https://github.com/brain-fuel/lawspec/blob/v0.14.0/examples/specs/boolean_flags.lawspec)
|
|
458
474
|
checks that flipping twice restores both `false` and `true`; all targets generate
|
|
459
475
|
Boolean property inputs and explicit tests for both Boolean boundary values. Java caps Boolean-only JetCheck runs at the number of
|
|
460
476
|
possible input combinations (up to 100), avoiding generator exhaustion.
|
|
@@ -533,7 +549,7 @@ This expands to `for all (x :: Int32) . render (x) = referenceRender (x)`.
|
|
|
533
549
|
The example inherits the input name `x` from the prelude. Both functions are
|
|
534
550
|
user-owned adapter functions; either may delegate to your existing code.
|
|
535
551
|
|
|
536
|
-
[The complete example](https://github.com/brain-fuel/lawspec/blob/v0.
|
|
552
|
+
[The complete example](https://github.com/brain-fuel/lawspec/blob/v0.14.0/examples/specs/equivalent.lawspec) compares decimal
|
|
537
553
|
renderers and two implementations that clamp negative integers to zero. For
|
|
538
554
|
JavaScript, their adapters can be:
|
|
539
555
|
|
|
@@ -570,7 +586,7 @@ law `normalizers agree` is
|
|
|
570
586
|
end
|
|
571
587
|
```
|
|
572
588
|
|
|
573
|
-
The [slug example](https://github.com/brain-fuel/lawspec/blob/v0.
|
|
589
|
+
The [slug example](https://github.com/brain-fuel/lawspec/blob/v0.14.0/examples/specs/slug.lawspec)
|
|
574
590
|
compares two implementations of ASCII-space replacement. It includes empty,
|
|
575
591
|
Unicode and escaped text. Each target uses its native string generator:
|
|
576
592
|
JetCheck `Generator.stringsOf(Generator.asciiPrintableChars())`, Hypothesis `st.text()`, fast-check `fc.string()`,
|
|
@@ -597,7 +613,7 @@ law `canonicalization reaches a fixed point` is
|
|
|
597
613
|
end
|
|
598
614
|
```
|
|
599
615
|
|
|
600
|
-
The [canonical URL example](https://github.com/brain-fuel/lawspec/blob/v0.
|
|
616
|
+
The [canonical URL example](https://github.com/brain-fuel/lawspec/blob/v0.14.0/examples/specs/canonical_url.lawspec)
|
|
601
617
|
uses removal of **all trailing slashes** as a small fixed-point demonstration,
|
|
602
618
|
not a complete URL canonicalization algorithm. For JavaScript:
|
|
603
619
|
|
|
@@ -606,7 +622,7 @@ export const canonicalize = value => value.replace(/\/+$/, "");
|
|
|
606
622
|
```
|
|
607
623
|
|
|
608
624
|
Removing just one trailing slash fails the supplied repeated-slash example.
|
|
609
|
-
The [mixed-input example](https://github.com/brain-fuel/lawspec/blob/v0.
|
|
625
|
+
The [mixed-input example](https://github.com/brain-fuel/lawspec/blob/v0.14.0/examples/specs/mixed_inputs.lawspec)
|
|
610
626
|
shows `Text` and `Int32` in the same quantified property and executable example.
|
|
611
627
|
The JavaScript API represents example bindings as typed records whose values use
|
|
612
628
|
`DataValue`: lossless tagged scalar payloads or structural constructors. Expected results are
|
|
@@ -689,7 +705,7 @@ by the JS shim.
|
|
|
689
705
|
## Build and verify
|
|
690
706
|
|
|
691
707
|
For contributors working from a repository checkout, build a local archive with
|
|
692
|
-
`npm pack ./npm` and install it with `npm install --save-dev ./lawspec-0.
|
|
708
|
+
`npm pack ./npm` and install it with `npm install --save-dev ./lawspec-0.14.0.tgz`.
|
|
693
709
|
The package payload lives in `npm/`.
|
|
694
710
|
|
|
695
711
|
```sh
|
package/REFINEMENTS.md
CHANGED
package/RELEASE-0.14.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# LawSpec 0.14
|
|
2
|
+
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Imports
|
|
6
|
+
|
|
7
|
+
```lawspec
|
|
8
|
+
unit shop.orders
|
|
9
|
+
import shop.domain as domain (Money, Cents, `commutative`)
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
A unit imports other units by name. Every declaration of an imported unit is
|
|
13
|
+
available through the alias (`domain.Usd`, `domain.centsOf`), and listed names
|
|
14
|
+
also unqualified. Types, wrappers, indexed families, refinements, checked
|
|
15
|
+
definitions and generic laws can be imported. Adapters and concrete laws stay
|
|
16
|
+
with their unit. Import cycles, unknown units and missing or ambiguous names are
|
|
17
|
+
reported at the import, with the reason: an adapter, a constructor listed
|
|
18
|
+
without its type, or a law without parameters.
|
|
19
|
+
|
|
20
|
+
Names are scoped to their unit, so units compiled together no longer need
|
|
21
|
+
distinct constructor names. Targets with one data namespace (Python,
|
|
22
|
+
JavaScript, TypeScript, Go and Haskell) name colliding types after their unit,
|
|
23
|
+
`ShopDomainCurrency` and `ShopOrdersCurrency`, and their constructors
|
|
24
|
+
`ShopDomainCurrencyUsd`. Java, Kotlin and Rust qualify only the type. Earlier
|
|
25
|
+
versions qualified only the colliding names, for example
|
|
26
|
+
`ShopDomainTypeCurrencyUsd` next to `CurrencyEur`.
|
|
27
|
+
|
|
28
|
+
Imports are resolved before type checking, like indexed families and domain
|
|
29
|
+
models, so Core and the eight backends are unchanged.
|
|
30
|
+
|
|
31
|
+
### Packages
|
|
32
|
+
|
|
33
|
+
A `lawspec-package.json` names a package, its version, its source directories
|
|
34
|
+
and the version ranges of its dependencies. Package units are named after the
|
|
35
|
+
package, a unit imports only from its own package and direct dependencies, and
|
|
36
|
+
every range must accept the supplied version. A project lists `dependencies` and
|
|
37
|
+
the `packages` directories in `lawspec.json`. A package's adapters and laws are a
|
|
38
|
+
published contract: dependent projects implement and test them as their own.
|
|
39
|
+
`lawspec package` checks a package and summarizes it.
|
|
40
|
+
|
|
41
|
+
The compiler API accepts `dependencies`, `packages` and `package`, and reports
|
|
42
|
+
the resolved packages (see [API migration](API-MIGRATION.md#imports-and-packages-014)).
|
|
43
|
+
|
|
44
|
+
### Other changes
|
|
45
|
+
|
|
46
|
+
- Rust: a law without quantified inputs no longer emits an untyped empty case
|
|
47
|
+
vector, which did not compile.
|
|
48
|
+
- The VS Code grammar highlights `import` and `as`.
|
|
49
|
+
- A new acceptance suite, `packages`, runs the
|
|
50
|
+
[package example](examples/packages) on all eight targets in both machine
|
|
51
|
+
profiles and rejects five adapter mutants plus the bare stubs. `lawspec-dev ci`
|
|
52
|
+
includes it.
|
package/bin/lawspec.mjs
CHANGED
|
@@ -67,6 +67,9 @@ function diagnostics(result) {
|
|
|
67
67
|
return result;
|
|
68
68
|
}
|
|
69
69
|
async function sources(config) {
|
|
70
|
+
return lawspecFiles(configRoot, config.sources);
|
|
71
|
+
}
|
|
72
|
+
async function lawspecFiles(root, entries) {
|
|
70
73
|
const files = [];
|
|
71
74
|
async function visit(file) {
|
|
72
75
|
const info = await stat(file);
|
|
@@ -75,8 +78,7 @@ async function sources(config) {
|
|
|
75
78
|
await visit(path.join(file, entry));
|
|
76
79
|
else if (file.endsWith(".lawspec")) files.push(file);
|
|
77
80
|
}
|
|
78
|
-
for (const source of
|
|
79
|
-
await visit(path.resolve(configRoot, source));
|
|
81
|
+
for (const source of entries) await visit(path.resolve(root, source));
|
|
80
82
|
if (!files.length) throw new Error("No .lawspec source files found");
|
|
81
83
|
return Promise.all(
|
|
82
84
|
[...new Set(files)].sort().map(async (file) => ({
|
|
@@ -85,6 +87,73 @@ async function sources(config) {
|
|
|
85
87
|
})),
|
|
86
88
|
);
|
|
87
89
|
}
|
|
90
|
+
// A package directory holds lawspec-package.json: its name, version, source
|
|
91
|
+
// directories and dependency ranges. The compiler checks names, versions,
|
|
92
|
+
// namespaces and which units may import which.
|
|
93
|
+
async function loadPackage(directory) {
|
|
94
|
+
const file = path.join(directory, "lawspec-package.json");
|
|
95
|
+
const manifest = JSON.parse(await readFile(file, "utf8"));
|
|
96
|
+
if (
|
|
97
|
+
typeof manifest.name !== "string" ||
|
|
98
|
+
typeof manifest.version !== "string" ||
|
|
99
|
+
!Array.isArray(manifest.sources)
|
|
100
|
+
)
|
|
101
|
+
throw new Error(`${file}: expected name, version and a sources array`);
|
|
102
|
+
return {
|
|
103
|
+
manifest,
|
|
104
|
+
package: {
|
|
105
|
+
name: manifest.name,
|
|
106
|
+
version: manifest.version,
|
|
107
|
+
dependencies: manifest.dependencies ?? {},
|
|
108
|
+
sources: await lawspecFiles(directory, manifest.sources),
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async function packageInput(owner, root) {
|
|
113
|
+
if (owner.packages !== undefined && !Array.isArray(owner.packages))
|
|
114
|
+
throw new Error("packages must be an array of package directories");
|
|
115
|
+
const packages = await Promise.all(
|
|
116
|
+
(owner.packages ?? []).map(async (p) => (await loadPackage(path.resolve(root, p))).package),
|
|
117
|
+
);
|
|
118
|
+
return {
|
|
119
|
+
...(packages.length ? { packages } : {}),
|
|
120
|
+
...(owner.dependencies !== undefined ? { dependencies: owner.dependencies } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async function packageCommand() {
|
|
124
|
+
const directory = path.resolve(options.project || ".");
|
|
125
|
+
const { manifest, package: own } = await loadPackage(directory);
|
|
126
|
+
const compiler = await createCompiler();
|
|
127
|
+
const result = diagnostics(
|
|
128
|
+
await compiler.check({
|
|
129
|
+
sources: own.sources,
|
|
130
|
+
package: { name: own.name, version: own.version },
|
|
131
|
+
...(await packageInput(manifest, directory)),
|
|
132
|
+
machineBits: options.machineBits ?? 64,
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
const units = result.units.map((u) => u.id).filter((u) => u !== "prelude");
|
|
136
|
+
const laws = result.laws.filter((l) => units.includes(l.owner));
|
|
137
|
+
const summary = {
|
|
138
|
+
name: own.name,
|
|
139
|
+
version: own.version,
|
|
140
|
+
dependencies: own.dependencies,
|
|
141
|
+
units,
|
|
142
|
+
laws: laws.map((l) => `${l.owner}::${l.name}`),
|
|
143
|
+
dataTypes: result.dataTypes
|
|
144
|
+
.filter((d) => units.some((u) => d.id.startsWith(u + "::")))
|
|
145
|
+
.map((d) => d.id),
|
|
146
|
+
};
|
|
147
|
+
output(
|
|
148
|
+
options.json
|
|
149
|
+
? summary
|
|
150
|
+
: `${summary.name} ${summary.version}: ${units.length} unit(s), ${summary.laws.length} law(s), ${summary.dataTypes.length} data type(s).
|
|
151
|
+
` +
|
|
152
|
+
`Units: ${units.join(", ")}
|
|
153
|
+
` +
|
|
154
|
+
`Dependencies: ${Object.entries(summary.dependencies).map(([n, r]) => `${n} ${r}`).join(", ") || "none"}`,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
88
157
|
async function init() {
|
|
89
158
|
const language = options.target;
|
|
90
159
|
if (!targets.includes(language))
|
|
@@ -173,13 +242,13 @@ async function main() {
|
|
|
173
242
|
}
|
|
174
243
|
if (!verb || ["help", "--help", "-h"].includes(verb)) {
|
|
175
244
|
output(
|
|
176
|
-
"LawSpec 0.
|
|
245
|
+
"LawSpec 0.14.0\nUsage: lawspec init --target <language> [--project <directory>] [--minify]\n lawspec check | doctor | explain <unit>::<law> | generate\n lawspec package [--project <package directory>]\n lawspec examples [--example payments] [--target <language>] [--output <directory>]\nOptions: --config <path>, --target <language>, --machine-bits <32|64>, --json\nGeneration: --dry-run, --check, --minify\nTargets: " +
|
|
177
246
|
targets.join(", "),
|
|
178
247
|
);
|
|
179
248
|
return;
|
|
180
249
|
}
|
|
181
250
|
if (verb === "--version") {
|
|
182
|
-
output("0.
|
|
251
|
+
output("0.14.0");
|
|
183
252
|
return;
|
|
184
253
|
}
|
|
185
254
|
if (positional.length > (verb === "explain" ? 1 : 0))
|
|
@@ -218,6 +287,7 @@ async function main() {
|
|
|
218
287
|
if (options.minify && !["init", "generate", "examples"].includes(verb))
|
|
219
288
|
throw new Error("--minify applies to init, generate and examples");
|
|
220
289
|
if (verb === "init") return init();
|
|
290
|
+
if (verb === "package") return packageCommand();
|
|
221
291
|
if (!["check", "doctor", "explain", "generate"].includes(verb))
|
|
222
292
|
throw new Error(`Unknown command: ${verb}`);
|
|
223
293
|
const config = JSON.parse(await readFile(configFile, "utf8"));
|
|
@@ -255,7 +325,12 @@ async function main() {
|
|
|
255
325
|
return;
|
|
256
326
|
}
|
|
257
327
|
if (config.machineBits !== undefined && ![32, 64].includes(config.machineBits)) throw new Error("machineBits must be 32 or 64");
|
|
258
|
-
const input = {
|
|
328
|
+
const input = {
|
|
329
|
+
sources: await sources(config),
|
|
330
|
+
...(await packageInput(config, configRoot)),
|
|
331
|
+
generation: config.generation,
|
|
332
|
+
machineBits: options.machineBits ?? config.machineBits ?? 64,
|
|
333
|
+
};
|
|
259
334
|
const compiler = await createCompiler();
|
|
260
335
|
// Proved obligations need no runtime check; the rest are enforced at runtime.
|
|
261
336
|
const evidenceSummary = (evidence) => {
|
package/build.json
CHANGED
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"src/LawSpec/CoreNativeScalarEmit.hs",
|
|
56
56
|
"src/LawSpec/CoreScalarEmit.hs",
|
|
57
57
|
"src/LawSpec/Data.hs",
|
|
58
|
+
"src/LawSpec/DataNames.hs",
|
|
58
59
|
"src/LawSpec/DefinitionTotality.hs",
|
|
59
60
|
"src/LawSpec/Domain.hs",
|
|
60
61
|
"src/LawSpec/DomainModel.hs",
|
|
@@ -77,6 +78,7 @@
|
|
|
77
78
|
"src/LawSpec/HaskellProperties.hs",
|
|
78
79
|
"src/LawSpec/HaskellTestHelpers.hs",
|
|
79
80
|
"src/LawSpec/HaskellTypeRefs.hs",
|
|
81
|
+
"src/LawSpec/Imports.hs",
|
|
80
82
|
"src/LawSpec/Indexed.hs",
|
|
81
83
|
"src/LawSpec/Inference.hs",
|
|
82
84
|
"src/LawSpec/JavaData.hs",
|
|
@@ -94,6 +96,7 @@
|
|
|
94
96
|
"src/LawSpec/Model.hs",
|
|
95
97
|
"src/LawSpec/NativeBinding.hs",
|
|
96
98
|
"src/LawSpec/NativeRequest.hs",
|
|
99
|
+
"src/LawSpec/Packages.hs",
|
|
97
100
|
"src/LawSpec/Parser.hs",
|
|
98
101
|
"src/LawSpec/PortableGenerator.hs",
|
|
99
102
|
"src/LawSpec/PortableTestHelpers.hs",
|
|
@@ -130,8 +133,8 @@
|
|
|
130
133
|
"wasm/lawspec-wasm.cabal"
|
|
131
134
|
],
|
|
132
135
|
"digests": {
|
|
133
|
-
"lawspec.cabal": "
|
|
134
|
-
"package.yaml": "
|
|
136
|
+
"lawspec.cabal": "1d976756374bc2916c3247e8f16677d711bdfbd9312cb4ba86da468028bc0709",
|
|
137
|
+
"package.yaml": "ea0daa1aadb9271b81868507fdaee32380ccb6cc80f9d8ebe9e5ddff0a0e459d",
|
|
135
138
|
"runtime/LawSpecCodecs.hs": "90cb1ed15d7ab664a17a054580c849408d77cfd2b2adcb4a3228b05132caeaca",
|
|
136
139
|
"runtime/LawSpecDataStrategies.hs": "cbe9f1946228db1076c19cd3158e8798fe32766cfdbea3f66b63d22d3d217508",
|
|
137
140
|
"runtime/LawSpecDataStrategies.java": "e3416efe8a0d7b1276cb4d1a8105fd01b1f5f3f02a803bf55d955d9e3ec39095",
|
|
@@ -155,15 +158,15 @@
|
|
|
155
158
|
"runtime/lawspec_schema.mjs": "60eb4204461eaa2c207fc7c3394014e2a814e4383b7045c065b4dae7c7a202c2",
|
|
156
159
|
"runtime/lawspec_schema.py": "b6967ef1a33fe6a1a180d5573ec37cd8bb2079c06e961ac2eeb05f23cffcdd07",
|
|
157
160
|
"runtime/lawspec_strategies.rs": "cac9ca301d4614fff9acfe61e7cc5678fabc044edadfa89ec11599b6780dc5f3",
|
|
158
|
-
"runtime/rust/Cargo.lock": "
|
|
159
|
-
"runtime/rust/Cargo.toml": "
|
|
160
|
-
"src/LawSpec/Api.hs": "
|
|
161
|
+
"runtime/rust/Cargo.lock": "ce3773a6636b3c40c1ec23dd45a267dc98ac2c68fa605d2b05f4f6abf6996fae",
|
|
162
|
+
"runtime/rust/Cargo.toml": "b52ba13a9b8d428b382c97cdb04659b8da3f83d4c54da4b5286245f547bc9108",
|
|
163
|
+
"src/LawSpec/Api.hs": "b629bbf854f9213629eeda404548075b56657ee1337ad37d67c54751ed1fc5dc",
|
|
161
164
|
"src/LawSpec/Backend.hs": "03c3b0cd62467ca677c88d29d7b12b2ab505cc0076d93d1f48fbddb0e9bcf133",
|
|
162
165
|
"src/LawSpec/Capabilities.hs": "e43d4fc3a4481fbb8aa3ff1c3f41f7e7fca5db01bfe256a30162a45d75a00c1c",
|
|
163
166
|
"src/LawSpec/Code/Doc.hs": "9e3b70f85deb1dcbce385af1d0cd4bea2dfa8a2d806d54745d4bb437406673e5",
|
|
164
167
|
"src/LawSpec/Code/JavaScript.hs": "77bf27dcc210216e4739f68c4709f556f80130ab83b3b9387ac4a2421e790910",
|
|
165
168
|
"src/LawSpec/Common.hs": "107612a8aaa787488413acf9c1a56622004d3bff251db89b99928343e6070883",
|
|
166
|
-
"src/LawSpec/Compile.hs": "
|
|
169
|
+
"src/LawSpec/Compile.hs": "ac7c9d81b7c205b1d56a30f94bd8474c6910db8ecab4802f451ab39a10fe073b",
|
|
167
170
|
"src/LawSpec/Core.hs": "ec081c49e5ccce95f84ded6073f1d8f30298f061dd8b94437d4b00410c57f27c",
|
|
168
171
|
"src/LawSpec/Core/DefinitionContracts.hs": "b7f60f038b231187ecf898e585ae1a8fb1fc113bb55bad6d1bb2660350fd969e",
|
|
169
172
|
"src/LawSpec/Core/Definitions.hs": "52f024fca59661142f70f9aa7dd2cbdb4892e5d3b1ca8079c878c5a1ba667112",
|
|
@@ -184,6 +187,7 @@
|
|
|
184
187
|
"src/LawSpec/CoreNativeScalarEmit.hs": "4082661ba5f8b1b09b4811f62ba767fa1ea401a38dd10011aea442c5a27892af",
|
|
185
188
|
"src/LawSpec/CoreScalarEmit.hs": "d1a51f7fe9b23817eeac7b50dac70ec02219df66d4b0218c5c9ae5237da244fd",
|
|
186
189
|
"src/LawSpec/Data.hs": "9dbeafa120276b114dad790ec69e617f7ad0c632e3c718962f2f7faf8ca327f4",
|
|
190
|
+
"src/LawSpec/DataNames.hs": "f10da6137dade8ac369fabb9231d87bf0d801655eb6756e816369102d147b4c0",
|
|
187
191
|
"src/LawSpec/DefinitionTotality.hs": "7671b7efb0cac5d796b074d48b2c10940e5bd0b5df082b926aee694903285efa",
|
|
188
192
|
"src/LawSpec/Domain.hs": "222d15f0012ae630802238a6d7e1ee78d1e718b599f5ebb5a1ddc4e8d29d68c3",
|
|
189
193
|
"src/LawSpec/DomainModel.hs": "3be67117c44e66a39d42d7ce094c2940c48ea1541017b64027afa6ea4b77092f",
|
|
@@ -191,39 +195,41 @@
|
|
|
191
195
|
"src/LawSpec/Emit.hs": "9f34f5765915a2a12a66a6dca647ddaef9289372956802c6d99cf0cfec447c7a",
|
|
192
196
|
"src/LawSpec/Eval.hs": "b0872ba8a6974463b32776653c2939826a6be87318c15641401f913f6b139de2",
|
|
193
197
|
"src/LawSpec/Frontend.hs": "fbf091b9c96f5b5361dbf4f65819634c0f8526ff98550d97c434c0d47af7839e",
|
|
194
|
-
"src/LawSpec/Gen.hs": "
|
|
195
|
-
"src/LawSpec/GoData.hs": "
|
|
198
|
+
"src/LawSpec/Gen.hs": "dcf5e49fca5671af7e7f878768746e1222e5c91d5eb85f032bc96b49866e368d",
|
|
199
|
+
"src/LawSpec/GoData.hs": "1b1882906ba676cdd37c744b91d271c7d25279b137f0c5ba5863f4423729bc86",
|
|
196
200
|
"src/LawSpec/GoDefinitions.hs": "3cb55c22f28443fff73e73c59780bf1977ab9260b8d66c7f19d1b94b40d1397e",
|
|
197
201
|
"src/LawSpec/GoExpr.hs": "da3a7cc0e3d2906886dc44f6b990e72098bb351558bbb31ee335da7382fac58a",
|
|
198
202
|
"src/LawSpec/GoNativeBinding.hs": "1ad8ea4cec6187c7e6005651c0edeec69e196eb329fb958c833da7751225aa1b",
|
|
199
203
|
"src/LawSpec/GoProperties.hs": "1eee75d852b0a1f8b6fe2cfb1cd3ed7dc57f44ca0ee137697729e8e1583d85fe",
|
|
200
204
|
"src/LawSpec/GoTestHelpers.hs": "dee55ee8505370e932773b8c685f4a1f380129e6f43f8806bf1e82efb99451b1",
|
|
201
205
|
"src/LawSpec/GoTypeRefs.hs": "7f239f5ac3ac8bd21c8f76c328049f7715d8562ee1382befa0a58abd4f15f726",
|
|
202
|
-
"src/LawSpec/HaskellData.hs": "
|
|
206
|
+
"src/LawSpec/HaskellData.hs": "0925cf589c8ff1e821ff1f0fa023deed562e2b71bffb97aef5befad69890e010",
|
|
203
207
|
"src/LawSpec/HaskellDefinitions.hs": "bc3664771247547900fc65f62147048238c3aa477154ac69d7a6e7568b05b2dd",
|
|
204
208
|
"src/LawSpec/HaskellExpr.hs": "f4144cf2022ef0a3bec6d796ebe7d2f42563e9d25758b9f362cd5545b47e802b",
|
|
205
209
|
"src/LawSpec/HaskellNativeBinding.hs": "9f98aa0c8659b572bd6486a0e29c4692bc6432db8639fa74a09bbf1b771bbfa6",
|
|
206
210
|
"src/LawSpec/HaskellProperties.hs": "5d64d5f45b86b5bb148383588d69ad717b0e158926b76938cc5cef54ed3adecc",
|
|
207
211
|
"src/LawSpec/HaskellTestHelpers.hs": "51e59b2abc9e85455e3c8e2c6baadb27e5d319081cb730d2ce56be5dc8053897",
|
|
208
212
|
"src/LawSpec/HaskellTypeRefs.hs": "2225b2a5e2ab3662e7202d23b24f4d6db48353b35ae28df8acd2b92fd2b97574",
|
|
209
|
-
"src/LawSpec/
|
|
213
|
+
"src/LawSpec/Imports.hs": "4e146ae1c2ee54f038b83430f322f8aadaede252a0857345471eb02a91d39ed6",
|
|
214
|
+
"src/LawSpec/Indexed.hs": "77d0198459ac5b8aad51d7043ed9759035ba5b819ae0664d3e9dcd51d36cac03",
|
|
210
215
|
"src/LawSpec/Inference.hs": "78285145897f03c3c4adc37acf0f490ea779bab3975fb2830628dae3a152fe38",
|
|
211
|
-
"src/LawSpec/JavaData.hs": "
|
|
216
|
+
"src/LawSpec/JavaData.hs": "4645edcab4524c6979450a1d92fb88baf39586b2aa56bcc603bd58dabaebe017",
|
|
212
217
|
"src/LawSpec/JavaDefinitions.hs": "fc2666e4f9f68b747aa596c0caf0483b9f0a47ec4957bbcd399234e77909588d",
|
|
213
218
|
"src/LawSpec/JavaExpr.hs": "6f237b0fc1eabe2d53c160f4cb781f8b77b478383f1a77ca4ccc8f08ac0dbcd0",
|
|
214
219
|
"src/LawSpec/JavaNativeBinding.hs": "8abbae78959a5cb61b7c6ae1c9071e43d10e26c2f421766d431fa18031f87173",
|
|
215
220
|
"src/LawSpec/JavaProperties.hs": "d953771df667aa193b110dbc898b0936b9ff5a32f6ebc9d2ff25d44a6cd4dfec",
|
|
216
221
|
"src/LawSpec/JavaTestHelpers.hs": "e6f4b9bbb7e5f07ece6ab1845e12aa661e62e8b926680b11454223fc3ec1523d",
|
|
217
|
-
"src/LawSpec/KotlinData.hs": "
|
|
222
|
+
"src/LawSpec/KotlinData.hs": "99ea660416ccc2156584a767e5cc200c0f5ccbf47c47f7b256c00d374ddc65dc",
|
|
218
223
|
"src/LawSpec/KotlinDefinitions.hs": "97d7d407d4bbdb4ce16035d607dbbcb8e3d6f5db513f2123a2c269e3dc6d2b38",
|
|
219
224
|
"src/LawSpec/KotlinExpr.hs": "20312f0774f1d0832a21a19b93c8103e2791ecd32a827d8e9c4f2b4830a996a0",
|
|
220
225
|
"src/LawSpec/KotlinNativeBinding.hs": "1aec7854758f07a4d2288de13931fbb88ef32220f85d3c84fe8233ad67b6d095",
|
|
221
226
|
"src/LawSpec/KotlinProperties.hs": "ee8c68bc5ee10a601a643356edb1e0a0c50d6e72a4520feaccb716c6f02ac99c",
|
|
222
227
|
"src/LawSpec/KotlinTestHelpers.hs": "74810d65faafc6ed4d64b1fb0596cda4186e586b7144a7441641b798795bc324",
|
|
223
|
-
"src/LawSpec/Model.hs": "
|
|
228
|
+
"src/LawSpec/Model.hs": "8d01d937b9ced2047018fa12dc8b06b0d71389c1dd9bd9f4dc5f71613d778b0f",
|
|
224
229
|
"src/LawSpec/NativeBinding.hs": "33959b0fd432ad4150f3b685f6438e284b801c2a59d9ef3132486a1cc7c8925a",
|
|
225
230
|
"src/LawSpec/NativeRequest.hs": "fb2dc88f42424ca520533700eab68c407a5de83807d1b0d8c976e6c4f3d65212",
|
|
226
|
-
"src/LawSpec/
|
|
231
|
+
"src/LawSpec/Packages.hs": "161fc68a9959a80762ca4ece405240351e3180ea4dbb2bf148eaca6562fb7c30",
|
|
232
|
+
"src/LawSpec/Parser.hs": "b99b122a5505667906e05c61da74f1c00dea830dd6936bc35b1d715f797723a2",
|
|
227
233
|
"src/LawSpec/PortableGenerator.hs": "69d457e39f539c77fc7a4c08205e75352bbecd9dfdff031a283a39bf44b22d49",
|
|
228
234
|
"src/LawSpec/PortableTestHelpers.hs": "8ba4d87183c8c11f6ef1ce21c170127335797154f29fb97ad3429f032a167fd3",
|
|
229
235
|
"src/LawSpec/Prelude.hs": "b1e155c12f58e7c346551a0c65c5d5af76d045b3f1625977ca2a5d1c97cb8c46",
|
|
@@ -232,12 +238,12 @@
|
|
|
232
238
|
"src/LawSpec/PythonDefinitions.hs": "30f3d2d71a378e194d62261e0fd1baade5a49ac8b5eaac97578ca015a48ce8e4",
|
|
233
239
|
"src/LawSpec/PythonExpr.hs": "23d7d24b5fb4efff9cb63d38c02a93d95744ec79b4565daf1412088fc7c4ba59",
|
|
234
240
|
"src/LawSpec/PythonNativeBinding.hs": "4e35ff8781062d0f614e45ea45f98038c8d609ab78bd671cb0a239eaa9db1690",
|
|
235
|
-
"src/LawSpec/PythonTypes.hs": "
|
|
236
|
-
"src/LawSpec/Refinement.hs": "
|
|
241
|
+
"src/LawSpec/PythonTypes.hs": "61c7271279e33b59f5b70cdee6363e0c0efb53a2f58c3256950dbec522ad7f10",
|
|
242
|
+
"src/LawSpec/Refinement.hs": "3bbdc090f9ebce60d99254dbe93dec6e11bd838df8537df828fd9c768c79d126",
|
|
237
243
|
"src/LawSpec/RuntimeSources.hs": "22c9f7e4f977b4f548363f494c9d66edeb4d3247c7a1e7e7cad470b1059019be",
|
|
238
|
-
"src/LawSpec/RustData.hs": "
|
|
244
|
+
"src/LawSpec/RustData.hs": "0d28ff5b35c5085c55604ef1eea366dec737b29d3352ef1576bb82c7421b615c",
|
|
239
245
|
"src/LawSpec/RustDefinitions.hs": "8c289e2779d7ed623f3578f20974dd9e2016c67734ee1447ed7f4b7c22caedf9",
|
|
240
|
-
"src/LawSpec/RustEmit.hs": "
|
|
246
|
+
"src/LawSpec/RustEmit.hs": "d08797ca26180b6ed2884c0576ec7b0265cadc2236a95d8754cfea89bb2940e0",
|
|
241
247
|
"src/LawSpec/RustExpr.hs": "04b2ef81417b811c7b98a98acdadab4e588ca8757964a63ba8dc5936c36479e6",
|
|
242
248
|
"src/LawSpec/RustNativeBinding.hs": "9d08348da571ac335e335e48c1ad4a67108f7bca54119f5960480e97a6d1da84",
|
|
243
249
|
"src/LawSpec/RustNativeGenerators.hs": "a3b1484d9ff0008e4f961aa81d0aa51da57ec0cd7909124e80c98d56aacc8ce9",
|
|
@@ -249,17 +255,17 @@
|
|
|
249
255
|
"src/LawSpec/WebDefinitions.hs": "d654df765e4bafcb1acdd35058f8a510c2cd81920153c0a75ff1e7e1137c96e5",
|
|
250
256
|
"src/LawSpec/WebExpr.hs": "0389dcd5cf7479dd23ef034b1012de6ebd70bf1dc9e3d90981dfb0ba2702596f",
|
|
251
257
|
"src/LawSpec/WebNativeBinding.hs": "465251be1a93d24a775aa57955bb9ec612af7364c53c83017da051f44943eda9",
|
|
252
|
-
"src/LawSpec/WebTypes.hs": "
|
|
258
|
+
"src/LawSpec/WebTypes.hs": "f74c6e346e3e3922223f8738a8f85e2b036e8f0469d9d7f027400e2f60f6957e",
|
|
253
259
|
"stack.yaml": "20ccf4d599e355e60b7aa4f814a7cd4299fe2048616cc2e6dbdc22a7bd8cec73",
|
|
254
260
|
"stack.yaml.lock": "ae222b9c81af920c56e50fa4596fa57786e7fa5a7b461390362b2b2ff63818c7",
|
|
255
261
|
"tools/embed-runtimes.py": "91a05197fc542a65387f3ccf4614a4817c850031eb4b84196c621b8baf344865",
|
|
256
262
|
"wasm/app/Exports.hs": "4ecbdac8faa2449e6fc61b93c82e6278fa14374154f29b4dacf0eef433f06a47",
|
|
257
263
|
"wasm/cabal.project": "021e560afdc5eb4cb7169e7119ecb8f92c9ee170245af909c94b612941bff5cc",
|
|
258
264
|
"wasm/cabal.project.freeze": "733dbed3d2ecccb26e874fd58f136296dad772184deb1658c196b5d54a0814dc",
|
|
259
|
-
"wasm/lawspec-wasm.cabal": "
|
|
260
|
-
"npm/core.wasm": "
|
|
265
|
+
"wasm/lawspec-wasm.cabal": "8121d57d0724e191598f25cfea986a18bc298c2fab38febb38fc721c7a9660f8",
|
|
266
|
+
"npm/core.wasm": "19d1ed55f899cb73a926d5982746c4ffd803f8cfe60ee83fbc86d400896edb2c",
|
|
261
267
|
"npm/core_jsffi.js": "88d136efe92f7cff5758c8fec8d9b6bbc9707fe37741cebeeb415fe34ce3d72b",
|
|
262
268
|
"npm/api.mjs": "e93251db289ff0609abaff78ad67f0a9af82508c1141c6a999604f67c56b6e7d",
|
|
263
|
-
"npm/index.d.ts": "
|
|
269
|
+
"npm/index.d.ts": "4847f99a55b5948b5f5cc1ed22cd404c3df625472148e0d57d2d9c3406ce6afd"
|
|
264
270
|
}
|
|
265
271
|
}
|
package/core.wasm
CHANGED
|
Binary file
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
unit shop.orders
|
|
2
|
+
import shop.domain as domain (Money, Cents, `commutative`, `idempotent`)
|
|
3
|
+
|
|
4
|
+
-- Constructor names are scoped to their unit: this Usd is not domain.Usd.
|
|
5
|
+
type Currency is | Usd | Gbp end
|
|
6
|
+
|
|
7
|
+
type Line is Line price :: Money quantity :: domain.Quantity end
|
|
8
|
+
|
|
9
|
+
settlement :: Currency -> domain.Currency
|
|
10
|
+
lineTotal :: Line -> Money
|
|
11
|
+
-- Generic laws quantify over the argument's base type, so these adapters take
|
|
12
|
+
-- any Int64; the last law restricts its inputs to Cents.
|
|
13
|
+
cheaper :: Int64 -> Int64 -> Int64
|
|
14
|
+
roundDown :: Int64 -> Int64
|
|
15
|
+
|
|
16
|
+
law `dollars settle in dollars` is
|
|
17
|
+
definition is
|
|
18
|
+
settlement Usd = domain.Usd
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
law `pounds settle in euros` is
|
|
23
|
+
definition is
|
|
24
|
+
settlement Gbp = domain.Eur
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
law `a line total keeps the price currency` is
|
|
29
|
+
definition is
|
|
30
|
+
`for all` (l :: Line) .
|
|
31
|
+
domain.currencyOf (lineTotal l) = (match l with
|
|
32
|
+
| Line p q -> domain.currencyOf p
|
|
33
|
+
end)
|
|
34
|
+
end
|
|
35
|
+
example `two items` is
|
|
36
|
+
l = Line (Money domain.Usd 250) (domain.Quantity 2)
|
|
37
|
+
expect domain.centsOf (lineTotal l) = 500
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
law `the cheaper price does not depend on order` is
|
|
42
|
+
definition is
|
|
43
|
+
`commutative` cheaper
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
law `rounding down to whole dollars is stable` is
|
|
48
|
+
definition is
|
|
49
|
+
`idempotent` roundDown
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
law `rounding down never raises a price` is
|
|
54
|
+
definition is
|
|
55
|
+
`for all` (c :: Cents) . roundDown c <= c
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
unit shop.domain
|
|
2
|
+
|
|
3
|
+
-- A package of reusable types, refinements, definitions and laws. Other units
|
|
4
|
+
-- import it by name; its declarations keep their own names, so an importer may
|
|
5
|
+
-- declare a Currency or a Usd of its own.
|
|
6
|
+
type Currency is | Usd | Eur end
|
|
7
|
+
|
|
8
|
+
refinement Cents is (c :: Int64 where c >= 0 && c <= 100000000) end
|
|
9
|
+
|
|
10
|
+
type Money is Money currency :: Currency cents :: Cents end
|
|
11
|
+
|
|
12
|
+
wrapper Quantity is Int32 where value >= 1 && value <= 1000 end
|
|
13
|
+
|
|
14
|
+
definition currencyOf (m :: Money) :: Currency is
|
|
15
|
+
match m with | Money c n -> c end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
definition centsOf (m :: Money) :: Int64 is
|
|
19
|
+
match m with | Money c n -> n end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
-- Generic laws are templates: an importer applies them to its own adapters.
|
|
23
|
+
law `commutative` (f :: a -> a -> a) requires Eq a is
|
|
24
|
+
definition is
|
|
25
|
+
`for all` (x :: a) (y :: a) . f x y = f y x
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
law `idempotent` (f :: a -> a) requires Eq a is
|
|
30
|
+
definition is
|
|
31
|
+
`for all` (x :: a) . f (f x) = f x
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
-- A published contract: every project that depends on this package implements
|
|
36
|
+
-- convert and is tested against these laws.
|
|
37
|
+
convert :: Currency -> Money -> Money
|
|
38
|
+
|
|
39
|
+
law `conversion targets the requested currency` is
|
|
40
|
+
definition is
|
|
41
|
+
`for all` (c :: Currency) (m :: Money) . currencyOf (convert c m) = c
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
law `converting to the same currency changes nothing` is
|
|
46
|
+
definition is
|
|
47
|
+
`for all` (m :: Money) . convert (currencyOf m) m = m
|
|
48
|
+
end
|
|
49
|
+
end
|
package/index.d.ts
CHANGED
|
@@ -212,12 +212,34 @@ export interface NativeBindings {
|
|
|
212
212
|
goImports?: NativeGoImport[];
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
export interface PackageVersion {
|
|
216
|
+
name: string;
|
|
217
|
+
version: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface Package {
|
|
221
|
+
name: string;
|
|
222
|
+
version: string;
|
|
223
|
+
dependencies?: Record<string, string>;
|
|
224
|
+
sources: Source[];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface PackageView {
|
|
228
|
+
name: string;
|
|
229
|
+
version: string;
|
|
230
|
+
dependencies: Record<string, string>;
|
|
231
|
+
units: string[];
|
|
232
|
+
}
|
|
233
|
+
|
|
215
234
|
export interface CheckRequest {
|
|
216
235
|
sources: Source[];
|
|
217
236
|
schemaVersion?: 3 | 4;
|
|
218
237
|
machineBits?: 32 | 64;
|
|
219
238
|
generation?: Partial<Generation>;
|
|
220
239
|
nativeBindings?: NativeBindings;
|
|
240
|
+
package?: PackageVersion;
|
|
241
|
+
dependencies?: Record<string, string>;
|
|
242
|
+
packages?: Package[];
|
|
221
243
|
}
|
|
222
244
|
|
|
223
245
|
export interface GenerationRequest extends CheckRequest {
|
|
@@ -240,6 +262,8 @@ export interface Result {
|
|
|
240
262
|
diagnostics: Diagnostic[];
|
|
241
263
|
expansions?: string[];
|
|
242
264
|
files?: Artifact[];
|
|
265
|
+
packages?: PackageView[];
|
|
266
|
+
project?: {package?: PackageVersion; dependencies: Record<string, string>;};
|
|
243
267
|
}
|
|
244
268
|
|
|
245
269
|
export interface PayloadPredicate {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lawspec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "State the law once. Check it everywhere.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
"bin": { "lawspec": "bin/lawspec.mjs" },
|
|
9
9
|
"exports": { ".": { "types": "./index.d.ts", "import": "./api.mjs" } },
|
|
10
10
|
"types": "index.d.ts",
|
|
11
|
-
"files": ["*.mjs", "*.json", "index.d.ts", "bin", "core.wasm", "core_jsffi.js", "README.md", "NATIVE-BINDINGS.md", "PRIMITIVES.md", "REFINEMENTS.md", "RUST.md", "JAVA.md", "PYTHON.md", "GO.md", "HASKELL.md", "KOTLIN.md", "WEB.md", "LANGUAGE.md", "API-MIGRATION.md", "RELEASE-0.9.md", "RELEASE-0.10.md", "RELEASE-0.11.md", "RELEASE-0.12.md", "RELEASE-0.13.md", "LICENSE", "starter.lawspec", "examples"],
|
|
11
|
+
"files": ["*.mjs", "*.json", "index.d.ts", "bin", "core.wasm", "core_jsffi.js", "README.md", "NATIVE-BINDINGS.md", "PRIMITIVES.md", "REFINEMENTS.md", "RUST.md", "JAVA.md", "PYTHON.md", "GO.md", "HASKELL.md", "KOTLIN.md", "WEB.md", "LANGUAGE.md", "API-MIGRATION.md", "RELEASE-0.9.md", "RELEASE-0.10.md", "RELEASE-0.11.md", "RELEASE-0.12.md", "RELEASE-0.13.md", "RELEASE-0.14.md", "LICENSE", "starter.lawspec", "examples"],
|
|
12
12
|
"scripts": { "test": "node --test test/*.test.mjs" }
|
|
13
13
|
}
|