lawspec 0.13.0 → 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 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.13)
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 declarations, checked
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
- - Reusable law, type and refinement libraries.
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
 
@@ -1,6 +1,6 @@
1
1
  # Native domain bindings: 0.10 acceptance scope
2
2
 
3
- Status: implementation and local acceptance complete; remote CI remains pending. The payment example now executes with
3
+ Status: implementation and acceptance complete. The payment example now executes with
4
4
  compiler-generated Rust bridges and application-library linkage. Rust supports
5
5
  generic products/sums, regular recursive mappings, nested built-in containers,
6
6
  and native Proptest factories that compose child strategies and retain shrinking.
@@ -17,7 +17,7 @@ emission requests fail explicitly.
17
17
  ## Audit of 0.9
18
18
 
19
19
  The checked-in compiler, generated API, and WASM fingerprints agree
20
- (`node tools/build-integrity.mjs`). The audit inspected the following boundaries:
20
+ (`stack run lawspec-dev -- integrity`). The audit inspected the following boundaries:
21
21
 
22
22
  | Boundary | Existing machinery | Missing for 0.10 |
23
23
  | --- | --- | --- |
@@ -955,7 +955,7 @@ CLI acceptance path: pack and install, export the payment project, prepare nativ
955
955
  dependencies, check and generate, run the normal native build tool, reject an
956
956
  incorrect fee implementation, restore application source, re-export, and check
957
957
  regeneration. Logs for every command are retained under
958
- `.artifacts/native-example-integration/`. CI runs this for every target with the
958
+ `.artifacts/native-example-integration/`. `lawspec-dev ci` runs this for every target with the
959
959
  default profile and with `LAWSPEC_MACHINE_BITS=32 LAWSPEC_MINIFY=1`.
960
960
  `LAWSPEC_PYTHON` selects the Python version for uv; an existing interpreter can be
961
961
  selected with `LAWSPEC_PYTHON_EXECUTABLE`. `LAWSPEC_NODE_MODULES` and
@@ -964,7 +964,7 @@ selected with `LAWSPEC_PYTHON_EXECUTABLE`. `LAWSPEC_NODE_MODULES` and
964
964
  Go proxy access; Stack still requires its normal configured dependency cache.
965
965
  `STACK_ROOT` and `GRADLE_USER_HOME` can select writable copies of existing caches.
966
966
 
967
- The installed CLI/native-tool path has passed for all eight targets in both CI
967
+ The installed CLI/native-tool path has passed for all eight targets in both
968
968
  configurations: 64-bit readable output and 32-bit compact output. TypeScript
969
969
  uses the exact declared dependencies recovered from the existing npm cache;
970
970
  Haskell uses a writable copy of the existing Stack cache. Kotlin's Gradle 9.3.0
@@ -991,16 +991,16 @@ The release audit maps the six shared requirements to these executable checks:
991
991
  | Resolve bindings once | `NativeBindingSpec` checks identities, complete mappings, ordering, arities, reference validation and unchanged defaults. `NativeRequestSpec` checks the public request boundary. `stack test` passes 509 examples. |
992
992
  | Checked native bridges | The target-specific native-payment, native-codec and native-shapes runners compile application models and reject incorrect conversions, precision loss, altered variants and collapsed absence. They compare native/WASM plans across machine profiles, layouts and formatting. |
993
993
  | Native generation and shrinking | The native-generator runtime checks and payment/codec runners verify framework factories, shrinking, invalid samples/shrinks, contracts and exhaustion. The shared empty-domain runners cover ignored and demanded empty parameters on all eight targets. |
994
- | Core semantics and source independence | `tools/check-boundaries.mjs` checks all eight emitter dependency boundaries. The codec/source runners build generated source without test-framework dependencies; native representations are checked against the shared schema. |
994
+ | Core semantics and source independence | `lawspec-dev boundaries` checks all eight emitter dependency boundaries. The codec/source runners build generated source without test-framework dependencies; native representations are checked against the shared schema. |
995
995
  | Application ownership | `npm/test/native-ownership.test.mjs` checks all-target migration, edited files, custom layouts, profile/format changes and adapter updates. `npm/test/native-bindings.test.mjs` covers optional generator scaffolds and signature changes. |
996
- | Coherent public interface | Schema negotiation and declarations are covered by compiler/npm tests; `tools/build-integrity.mjs` checks compiler/WASM/API fingerprints. Bundled projects are exercised by the installed-package runners. The migration guide and release notes document the interface. |
996
+ | Coherent public interface | Schema negotiation and declarations are covered by compiler/npm tests; `lawspec-dev integrity` checks compiler/WASM/API fingerprints. Bundled projects are exercised by the installed-package runners. The migration guide and release notes document the interface. |
997
997
 
998
998
  The full npm regression suite passes 77 tests, and the package smoke test passes
999
999
  installed API generation on all eight targets plus executable Rust scaffold,
1000
1000
  doctor, adapter and regeneration checks. The package contains the binding guide,
1001
1001
  migration notes, release notes and all eight application example configurations.
1002
- The remote CI gate for these checks was reviewed during the 0.11 release, which
1003
- re-ran every target job, including both installed native-binding profiles.
1002
+ These checks, including both installed native-binding profiles, are part of
1003
+ `lawspec-dev ci`, the repository's local check.
1004
1004
 
1005
1005
  The empty-parameter audit must distinguish an empty type from an inhabited type
1006
1006
  that mentions it. A native factory for `Phantom Empty` may ignore its child
package/PRIMITIVES.md CHANGED
@@ -1,4 +1,4 @@
1
- # LawSpec scalar reference (0.13.0)
1
+ # LawSpec scalar reference (0.14.0)
2
2
 
3
3
  A scalar has a declared domain, checked literals, equality, property inputs, and
4
4
  boundary fixtures. General collections, objects, pointers, and type-only constructs
@@ -142,8 +142,8 @@ portable across architectures.
142
142
  The bundled `scalars.lawspec`, `scalar_catalog.lawspec`, and
143
143
  `scalar_adapters.lawspec` contain explicit fixtures for every scalar family.
144
144
  `tools/scalar-reference.py` produces independent Fraction-based conformance
145
- vectors; `tools/scalar-integration.mjs` executes them across the eight targets.
146
- Set `LAWSPEC_MUTANTS=1` to also verify that incorrect adapters are detected.
145
+ vectors; `lawspec-acceptance scalar` executes them across the eight targets and
146
+ verifies that incorrect adapters are detected.
147
147
 
148
148
 
149
149
  Refinements, parameterized domains, abstract native integer results, and executable
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
- Planned: 0.14 cross-unit packages and 0.15 evidence reporting. See the
83
- [roadmap](LANGUAGE.md#roadmap).
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.13.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.13.0 -- lawspec init --target javascript
109
- npm install --save-dev lawspec@0.13.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.13.0/examples/specs/algebra.lawspec), including both sides of every
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.13.0/examples/specs/currying.lawspec) demonstrate a four-argument
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.13.0/examples/specs/parse_port.lawspec)
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.13.0/examples/specs/boolean_flags.lawspec)
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.13.0/examples/specs/equivalent.lawspec) compares decimal
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.13.0/examples/specs/slug.lawspec)
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.13.0/examples/specs/canonical_url.lawspec)
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.13.0/examples/specs/mixed_inputs.lawspec)
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.13.0.tgz`.
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
@@ -698,7 +714,7 @@ stack test
698
714
  tools/wasm.sh
699
715
  node --test npm/test/*.test.mjs
700
716
  node tools/parity.mjs
701
- node tools/build-integrity.mjs
717
+ stack run lawspec-dev -- integrity
702
718
  node tools/package-smoke.mjs
703
719
  ```
704
720
 
@@ -709,24 +725,48 @@ are frozen in `wasm/cabal.project.freeze`. Install the cross compiler through
709
725
  [ghc-wasm-meta](https://gitlab.haskell.org/haskell-wasm/ghc-wasm-meta).
710
726
 
711
727
  Haskell's export table generates the JS API and `.d.ts` files. The build records
712
- compiler-source and artifact hashes in `npm/build.json`; CI rejects stale WASM
713
- or hand-edited generated wrappers. The npm archive is a self-contained consumer
728
+ compiler-source and artifact hashes in `npm/build.json`; `lawspec-dev integrity`
729
+ rejects stale WASM or hand-edited generated wrappers. The npm archive is a self-contained consumer
714
730
  artifact, with no install-time compilation or download hook.
715
731
 
716
- For all eight native integrations, install their build tools, then:
732
+ The complete check runs locally; there is no hosted CI. Install the eight
733
+ targets' build tools, then:
734
+
735
+ ```sh
736
+ stack run lawspec-dev -- ci # everything
737
+ stack run lawspec-dev -- ci --target rust --target go
738
+ stack run lawspec-dev -- ci --core # compiler, npm and editor only
739
+ ```
740
+
741
+ It runs the compiler, npm, parity, package and editor checks, then for each
742
+ target bootstraps its dependencies, runs every acceptance suite in both machine
743
+ profiles, and runs the installed native-binding example. Each step logs to
744
+ `.artifacts/ci/`, and the command exits non-zero if any step failed.
745
+ `--rust-toolchains 1.85.0,stable` and `--rust-targets i686-unknown-linux-gnu`
746
+ add Rust toolchains and architectures. The steps can also be run on their own:
717
747
 
718
748
  ```sh
719
- # Set LAWSPEC_GRADLE to a Gradle 9.3.0 executable if it is not on PATH.
720
749
  node tools/bootstrap-integration.mjs
721
- node tools/integration.mjs
750
+ stack run lawspec-acceptance -- integration # all eight targets
751
+ stack run lawspec-acceptance -- scalar rust # one suite, one target
752
+ LAWSPEC_MACHINE_BITS=32 LAWSPEC_MINIFY=1 stack run lawspec-acceptance -- indexed go
753
+ stack run lawspec-acceptance -- domain --check # regenerate and compare only
722
754
  ```
723
755
 
724
- These scripts use isolated `.integration/` projects. Bootstrap installs the pinned
725
- test dependencies; integration verifies that correct adapters pass, broken adapters
726
- fail, regeneration preserves implementations, and generation leaves build files
727
- unchanged. Arguments select individual targets. `LAWSPEC_PYTHON=3.14` selects the
728
- additional Python reference environment. CI also exercises Node 22/24/26 and packs
729
- and installs the npm archive. Registry publication is a separate release action.
756
+ Bootstrap installs the pinned test dependencies into isolated `.integration/`
757
+ projects. `lawspec-acceptance` generates each suite's bundled examples in process,
758
+ installs the suite's adapters, runs the target's own test command, and requires
759
+ every mutant to fail its laws at test time; a mutant that only breaks the build
760
+ fails the suite. Suites live in `acceptance/<suite>/`: `suite.json` names the
761
+ specifications, `<target>/files/` holds real adapter sources, `<target>/stubs/`
762
+ records the stub an adapter was written against, and `<target>/mutants/*.mutant`
763
+ holds one search/replace edit per mutant. Suites are `integration`, `algebra`,
764
+ `scalar`, `refinement`, `indexed` and `domain`. Gradle 9.3.0 is used from
765
+ `.tools/gradle-9.3.0` when present, otherwise from `PATH`; `LAWSPEC_OFFLINE=1`
766
+ uses existing dependency caches. `npm/test/build-files.test.mjs` checks that
767
+ generation leaves build files unchanged. `LAWSPEC_PYTHON=3.14` selects the
768
+ additional Python reference environment. Registry publication is a separate
769
+ release action.
730
770
 
731
771
  The native-binding acceptance command uses the installed npm archive, public CLI,
732
772
  and the selected target's normal test command:
package/REFINEMENTS.md CHANGED
@@ -1,4 +1,4 @@
1
- # Refinements and abstract integers (0.13.0)
1
+ # Refinements and abstract integers (0.14.0)
2
2
 
3
3
  A refinement restricts a scalar domain with a pure Boolean expression. LawSpec
4
4
  checks concrete examples, generates satisfying input tuples, and checks adapter
package/RELEASE-0.13.md CHANGED
@@ -1,6 +1,48 @@
1
- # LawSpec 0.13.0
1
+ # LawSpec 0.13
2
2
 
3
- ## Wrappers and constrained primitives
3
+ ## 0.13.2
4
+
5
+ A maintenance release. The language, generated code and API are unchanged.
6
+
7
+ - The repository has no hosted CI. `stack run lawspec-dev -- ci` runs the
8
+ complete check locally: compiler, npm, parity, package and editor checks, then
9
+ for each target the dependency bootstrap, every acceptance suite in both
10
+ machine profiles, and the installed native-binding example. It logs each step to
11
+ `.artifacts/ci/` and exits non-zero on any failure. `--target`, `--core`,
12
+ `--fail-fast`, `--rust-toolchains` and `--rust-targets` select what to run.
13
+ `make ci` is equivalent.
14
+ - The JavaScript acceptance runners and fixture modules replaced by
15
+ `lawspec-acceptance` are removed.
16
+ - The package smoke test's per-command timeout is ten minutes: exporting every
17
+ bundled example had exceeded the former two-minute limit on slower machines.
18
+ - The integration bootstrap restores missing scaffold files in existing projects.
19
+
20
+ ## 0.13.1
21
+
22
+ A maintenance release. The language, generated code and API are unchanged from
23
+ 0.13.0.
24
+
25
+ - Repository checks move from JavaScript to Haskell. `lawspec-dev boundaries` and
26
+ `lawspec-dev integrity` replace `tools/check-boundaries.mjs` and
27
+ `tools/build-integrity.mjs`. The integrity check now also rejects staged npm
28
+ copies of documentation and examples that differ from their sources.
29
+ - `lawspec-acceptance` runs the bundled-example acceptance suites
30
+ (`integration`, `algebra`, `scalar`, `refinement`, `indexed`, `domain`) in
31
+ process. Adapters and mutants are real files under `acceptance/`, and a
32
+ mutant that only breaks the build now fails the suite. This exposed a
33
+ TypeScript scalar mutant that previously counted as rejected because it
34
+ failed type-checking; it now exercises the laws. The JavaScript runners
35
+ continue to run alongside it in CI.
36
+ - Build-file scaffolds are defined once in Haskell (`LawSpec.Scaffold`) and
37
+ checked against the npm templates byte for byte.
38
+ - Compiler API contract tests formerly in `npm/test` run in hspec against the
39
+ same JSON boundary that `core.wasm` exports. A new npm test checks that
40
+ generation never rewrites build files and that regeneration is a no-op on
41
+ every target.
42
+
43
+ ## 0.13.0
44
+
45
+ ### Wrappers and constrained primitives
4
46
 
5
47
  ```lawspec
6
48
  wrapper UnitQuantity is Int32 where value >= 1 && value <= 1000 end
@@ -15,7 +57,7 @@ value. Wrappers may take type parameters. They elaborate to a single-constructor
15
57
  product with a refined field, so all eight targets represent them natively with
16
58
  no new runtime machinery.
17
59
 
18
- ## Workflows and state distinctions
60
+ ### Workflows and state distinctions
19
61
 
20
62
  ```lawspec
21
63
  workflow placeOrder :: UnvalidatedOrder -> Either OrderError PricedOrder is
@@ -32,14 +74,14 @@ native workflow must equal the railway composition of the native steps.
32
74
  Diagnostics name the step and the mismatched types, with the workflow's source
33
75
  location.
34
76
 
35
- ## Evidence
77
+ ### Evidence
36
78
 
37
79
  Constructor field constraints, including wrapper constraints, appear in the
38
80
  evidence as `construction` obligations with status `runtime-checked`, next to
39
81
  the contract obligations introduced in 0.12. The TypeScript API declares these
40
82
  records as `ObligationEvidence`; the 0.12 typing was not published.
41
83
 
42
- ## Examples and acceptance
84
+ ### Examples and acceptance
43
85
 
44
86
  `examples/specs/domain_modeling.lawspec` combines wrappers, a parameterized
45
87
  `NonEmptyList`, order states and the workflow. `tools/domain-integration.mjs`
@@ -48,7 +90,7 @@ mutants that break a wrapper invariant, the railway composition, or a non-empty
48
90
  list operation fail. The example runners now share
49
91
  `tools/example-acceptance.mjs`.
50
92
 
51
- ## Compatibility
93
+ ### Compatibility
52
94
 
53
95
  `wrapper` and `workflow` begin new declarations. Specifications that do not use
54
96
  them compile as in 0.12. API schemas 3 and 4 are unchanged, apart from the
@@ -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 config.sources)
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.13.0\nUsage: lawspec init --target <language> [--project <directory>] [--minify]\n lawspec check | doctor | explain <unit>::<law> | generate\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: " +
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.13.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 = { sources: await sources(config), generation: config.generation, machineBits: options.machineBits ?? config.machineBits ?? 64 };
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",
@@ -112,6 +115,7 @@
112
115
  "src/LawSpec/RustExpr.hs",
113
116
  "src/LawSpec/RustNativeBinding.hs",
114
117
  "src/LawSpec/RustNativeGenerators.hs",
118
+ "src/LawSpec/Scaffold.hs",
115
119
  "src/LawSpec/Scalar.hs",
116
120
  "src/LawSpec/SpecializeDefinitions.hs",
117
121
  "src/LawSpec/Testing.hs",
@@ -129,8 +133,8 @@
129
133
  "wasm/lawspec-wasm.cabal"
130
134
  ],
131
135
  "digests": {
132
- "lawspec.cabal": "2aab726a6d4e9c64e218c0563d52fab738b0753f9597683b9d650dde1baa948c",
133
- "package.yaml": "95807129285b33f8ac2bf7452aae1ee049f8f7711f0dc9f962fdf9586b58fcc8",
136
+ "lawspec.cabal": "1d976756374bc2916c3247e8f16677d711bdfbd9312cb4ba86da468028bc0709",
137
+ "package.yaml": "ea0daa1aadb9271b81868507fdaee32380ccb6cc80f9d8ebe9e5ddff0a0e459d",
134
138
  "runtime/LawSpecCodecs.hs": "90cb1ed15d7ab664a17a054580c849408d77cfd2b2adcb4a3228b05132caeaca",
135
139
  "runtime/LawSpecDataStrategies.hs": "cbe9f1946228db1076c19cd3158e8798fe32766cfdbea3f66b63d22d3d217508",
136
140
  "runtime/LawSpecDataStrategies.java": "e3416efe8a0d7b1276cb4d1a8105fd01b1f5f3f02a803bf55d955d9e3ec39095",
@@ -154,15 +158,15 @@
154
158
  "runtime/lawspec_schema.mjs": "60eb4204461eaa2c207fc7c3394014e2a814e4383b7045c065b4dae7c7a202c2",
155
159
  "runtime/lawspec_schema.py": "b6967ef1a33fe6a1a180d5573ec37cd8bb2079c06e961ac2eeb05f23cffcdd07",
156
160
  "runtime/lawspec_strategies.rs": "cac9ca301d4614fff9acfe61e7cc5678fabc044edadfa89ec11599b6780dc5f3",
157
- "runtime/rust/Cargo.lock": "deb6b268124278aa237f64c8e821caf2388ccda3df92c2e814a5863331ae8c92",
158
- "runtime/rust/Cargo.toml": "ed36668f25943b9c8a3ea9eb5a805f2953540aabb763919029947d342cc23978",
159
- "src/LawSpec/Api.hs": "392f6e8c1a9ae81a95e219ac071e5b4bea03ee330d63b829036f8f54b2eda8a7",
161
+ "runtime/rust/Cargo.lock": "ce3773a6636b3c40c1ec23dd45a267dc98ac2c68fa605d2b05f4f6abf6996fae",
162
+ "runtime/rust/Cargo.toml": "b52ba13a9b8d428b382c97cdb04659b8da3f83d4c54da4b5286245f547bc9108",
163
+ "src/LawSpec/Api.hs": "b629bbf854f9213629eeda404548075b56657ee1337ad37d67c54751ed1fc5dc",
160
164
  "src/LawSpec/Backend.hs": "03c3b0cd62467ca677c88d29d7b12b2ab505cc0076d93d1f48fbddb0e9bcf133",
161
165
  "src/LawSpec/Capabilities.hs": "e43d4fc3a4481fbb8aa3ff1c3f41f7e7fca5db01bfe256a30162a45d75a00c1c",
162
166
  "src/LawSpec/Code/Doc.hs": "9e3b70f85deb1dcbce385af1d0cd4bea2dfa8a2d806d54745d4bb437406673e5",
163
167
  "src/LawSpec/Code/JavaScript.hs": "77bf27dcc210216e4739f68c4709f556f80130ab83b3b9387ac4a2421e790910",
164
168
  "src/LawSpec/Common.hs": "107612a8aaa787488413acf9c1a56622004d3bff251db89b99928343e6070883",
165
- "src/LawSpec/Compile.hs": "0260f0f1dc3d18d2f2e172ab47d603b6e3029ce2948cc0a237ad8277fc64707f",
169
+ "src/LawSpec/Compile.hs": "ac7c9d81b7c205b1d56a30f94bd8474c6910db8ecab4802f451ab39a10fe073b",
166
170
  "src/LawSpec/Core.hs": "ec081c49e5ccce95f84ded6073f1d8f30298f061dd8b94437d4b00410c57f27c",
167
171
  "src/LawSpec/Core/DefinitionContracts.hs": "b7f60f038b231187ecf898e585ae1a8fb1fc113bb55bad6d1bb2660350fd969e",
168
172
  "src/LawSpec/Core/Definitions.hs": "52f024fca59661142f70f9aa7dd2cbdb4892e5d3b1ca8079c878c5a1ba667112",
@@ -183,6 +187,7 @@
183
187
  "src/LawSpec/CoreNativeScalarEmit.hs": "4082661ba5f8b1b09b4811f62ba767fa1ea401a38dd10011aea442c5a27892af",
184
188
  "src/LawSpec/CoreScalarEmit.hs": "d1a51f7fe9b23817eeac7b50dac70ec02219df66d4b0218c5c9ae5237da244fd",
185
189
  "src/LawSpec/Data.hs": "9dbeafa120276b114dad790ec69e617f7ad0c632e3c718962f2f7faf8ca327f4",
190
+ "src/LawSpec/DataNames.hs": "f10da6137dade8ac369fabb9231d87bf0d801655eb6756e816369102d147b4c0",
186
191
  "src/LawSpec/DefinitionTotality.hs": "7671b7efb0cac5d796b074d48b2c10940e5bd0b5df082b926aee694903285efa",
187
192
  "src/LawSpec/Domain.hs": "222d15f0012ae630802238a6d7e1ee78d1e718b599f5ebb5a1ddc4e8d29d68c3",
188
193
  "src/LawSpec/DomainModel.hs": "3be67117c44e66a39d42d7ce094c2940c48ea1541017b64027afa6ea4b77092f",
@@ -190,39 +195,41 @@
190
195
  "src/LawSpec/Emit.hs": "9f34f5765915a2a12a66a6dca647ddaef9289372956802c6d99cf0cfec447c7a",
191
196
  "src/LawSpec/Eval.hs": "b0872ba8a6974463b32776653c2939826a6be87318c15641401f913f6b139de2",
192
197
  "src/LawSpec/Frontend.hs": "fbf091b9c96f5b5361dbf4f65819634c0f8526ff98550d97c434c0d47af7839e",
193
- "src/LawSpec/Gen.hs": "c76d00fb1f7e9ed2eed7d387f1cd86cf4d12cc57f007abb0e479043b0ed377e6",
194
- "src/LawSpec/GoData.hs": "35efbfdc1079e777d4760069fa2405a9700bbabab7dc7e3c2c5e0757312ea201",
198
+ "src/LawSpec/Gen.hs": "dcf5e49fca5671af7e7f878768746e1222e5c91d5eb85f032bc96b49866e368d",
199
+ "src/LawSpec/GoData.hs": "1b1882906ba676cdd37c744b91d271c7d25279b137f0c5ba5863f4423729bc86",
195
200
  "src/LawSpec/GoDefinitions.hs": "3cb55c22f28443fff73e73c59780bf1977ab9260b8d66c7f19d1b94b40d1397e",
196
201
  "src/LawSpec/GoExpr.hs": "da3a7cc0e3d2906886dc44f6b990e72098bb351558bbb31ee335da7382fac58a",
197
202
  "src/LawSpec/GoNativeBinding.hs": "1ad8ea4cec6187c7e6005651c0edeec69e196eb329fb958c833da7751225aa1b",
198
203
  "src/LawSpec/GoProperties.hs": "1eee75d852b0a1f8b6fe2cfb1cd3ed7dc57f44ca0ee137697729e8e1583d85fe",
199
204
  "src/LawSpec/GoTestHelpers.hs": "dee55ee8505370e932773b8c685f4a1f380129e6f43f8806bf1e82efb99451b1",
200
205
  "src/LawSpec/GoTypeRefs.hs": "7f239f5ac3ac8bd21c8f76c328049f7715d8562ee1382befa0a58abd4f15f726",
201
- "src/LawSpec/HaskellData.hs": "51374f35de2b1d6c78d15597e41e6f0695fe5fdb040cbb35a7d03d23fa3a3179",
206
+ "src/LawSpec/HaskellData.hs": "0925cf589c8ff1e821ff1f0fa023deed562e2b71bffb97aef5befad69890e010",
202
207
  "src/LawSpec/HaskellDefinitions.hs": "bc3664771247547900fc65f62147048238c3aa477154ac69d7a6e7568b05b2dd",
203
208
  "src/LawSpec/HaskellExpr.hs": "f4144cf2022ef0a3bec6d796ebe7d2f42563e9d25758b9f362cd5545b47e802b",
204
209
  "src/LawSpec/HaskellNativeBinding.hs": "9f98aa0c8659b572bd6486a0e29c4692bc6432db8639fa74a09bbf1b771bbfa6",
205
210
  "src/LawSpec/HaskellProperties.hs": "5d64d5f45b86b5bb148383588d69ad717b0e158926b76938cc5cef54ed3adecc",
206
211
  "src/LawSpec/HaskellTestHelpers.hs": "51e59b2abc9e85455e3c8e2c6baadb27e5d319081cb730d2ce56be5dc8053897",
207
212
  "src/LawSpec/HaskellTypeRefs.hs": "2225b2a5e2ab3662e7202d23b24f4d6db48353b35ae28df8acd2b92fd2b97574",
208
- "src/LawSpec/Indexed.hs": "bfb24a4023517acf9f34e6f3327c5623f0e18b1576e5453a43d7a6cd9e691e00",
213
+ "src/LawSpec/Imports.hs": "4e146ae1c2ee54f038b83430f322f8aadaede252a0857345471eb02a91d39ed6",
214
+ "src/LawSpec/Indexed.hs": "77d0198459ac5b8aad51d7043ed9759035ba5b819ae0664d3e9dcd51d36cac03",
209
215
  "src/LawSpec/Inference.hs": "78285145897f03c3c4adc37acf0f490ea779bab3975fb2830628dae3a152fe38",
210
- "src/LawSpec/JavaData.hs": "177713377f7a38d69fbfd7891899357fc55782cf1d361f2e9dd5baf8725d4067",
216
+ "src/LawSpec/JavaData.hs": "4645edcab4524c6979450a1d92fb88baf39586b2aa56bcc603bd58dabaebe017",
211
217
  "src/LawSpec/JavaDefinitions.hs": "fc2666e4f9f68b747aa596c0caf0483b9f0a47ec4957bbcd399234e77909588d",
212
218
  "src/LawSpec/JavaExpr.hs": "6f237b0fc1eabe2d53c160f4cb781f8b77b478383f1a77ca4ccc8f08ac0dbcd0",
213
219
  "src/LawSpec/JavaNativeBinding.hs": "8abbae78959a5cb61b7c6ae1c9071e43d10e26c2f421766d431fa18031f87173",
214
220
  "src/LawSpec/JavaProperties.hs": "d953771df667aa193b110dbc898b0936b9ff5a32f6ebc9d2ff25d44a6cd4dfec",
215
221
  "src/LawSpec/JavaTestHelpers.hs": "e6f4b9bbb7e5f07ece6ab1845e12aa661e62e8b926680b11454223fc3ec1523d",
216
- "src/LawSpec/KotlinData.hs": "7785fc0c091e50010bce3002355f01c1d237fce05bca6a7ce6de6d207737e228",
222
+ "src/LawSpec/KotlinData.hs": "99ea660416ccc2156584a767e5cc200c0f5ccbf47c47f7b256c00d374ddc65dc",
217
223
  "src/LawSpec/KotlinDefinitions.hs": "97d7d407d4bbdb4ce16035d607dbbcb8e3d6f5db513f2123a2c269e3dc6d2b38",
218
224
  "src/LawSpec/KotlinExpr.hs": "20312f0774f1d0832a21a19b93c8103e2791ecd32a827d8e9c4f2b4830a996a0",
219
225
  "src/LawSpec/KotlinNativeBinding.hs": "1aec7854758f07a4d2288de13931fbb88ef32220f85d3c84fe8233ad67b6d095",
220
226
  "src/LawSpec/KotlinProperties.hs": "ee8c68bc5ee10a601a643356edb1e0a0c50d6e72a4520feaccb716c6f02ac99c",
221
227
  "src/LawSpec/KotlinTestHelpers.hs": "74810d65faafc6ed4d64b1fb0596cda4186e586b7144a7441641b798795bc324",
222
- "src/LawSpec/Model.hs": "1d7ceb7bd66e3d496eef89eaa86403e6896472317ca9a4be86e0c933a7cce403",
228
+ "src/LawSpec/Model.hs": "8d01d937b9ced2047018fa12dc8b06b0d71389c1dd9bd9f4dc5f71613d778b0f",
223
229
  "src/LawSpec/NativeBinding.hs": "33959b0fd432ad4150f3b685f6438e284b801c2a59d9ef3132486a1cc7c8925a",
224
230
  "src/LawSpec/NativeRequest.hs": "fb2dc88f42424ca520533700eab68c407a5de83807d1b0d8c976e6c4f3d65212",
225
- "src/LawSpec/Parser.hs": "94a5603f6831d1dad5634a766bbc02cc58d884d23b5d6606ed4a1537cfe4c813",
231
+ "src/LawSpec/Packages.hs": "161fc68a9959a80762ca4ece405240351e3180ea4dbb2bf148eaca6562fb7c30",
232
+ "src/LawSpec/Parser.hs": "b99b122a5505667906e05c61da74f1c00dea830dd6936bc35b1d715f797723a2",
226
233
  "src/LawSpec/PortableGenerator.hs": "69d457e39f539c77fc7a4c08205e75352bbecd9dfdff031a283a39bf44b22d49",
227
234
  "src/LawSpec/PortableTestHelpers.hs": "8ba4d87183c8c11f6ef1ce21c170127335797154f29fb97ad3429f032a167fd3",
228
235
  "src/LawSpec/Prelude.hs": "b1e155c12f58e7c346551a0c65c5d5af76d045b3f1625977ca2a5d1c97cb8c46",
@@ -231,15 +238,16 @@
231
238
  "src/LawSpec/PythonDefinitions.hs": "30f3d2d71a378e194d62261e0fd1baade5a49ac8b5eaac97578ca015a48ce8e4",
232
239
  "src/LawSpec/PythonExpr.hs": "23d7d24b5fb4efff9cb63d38c02a93d95744ec79b4565daf1412088fc7c4ba59",
233
240
  "src/LawSpec/PythonNativeBinding.hs": "4e35ff8781062d0f614e45ea45f98038c8d609ab78bd671cb0a239eaa9db1690",
234
- "src/LawSpec/PythonTypes.hs": "ef928bfeb4324eb6e53c99cae247cc2fa84816075d81de4589d14abaa326656a",
235
- "src/LawSpec/Refinement.hs": "8058a9f7e433b4b00ef0966a9ea2be3c91ae93b591ed58a1ffcb792d316193d3",
241
+ "src/LawSpec/PythonTypes.hs": "61c7271279e33b59f5b70cdee6363e0c0efb53a2f58c3256950dbec522ad7f10",
242
+ "src/LawSpec/Refinement.hs": "3bbdc090f9ebce60d99254dbe93dec6e11bd838df8537df828fd9c768c79d126",
236
243
  "src/LawSpec/RuntimeSources.hs": "22c9f7e4f977b4f548363f494c9d66edeb4d3247c7a1e7e7cad470b1059019be",
237
- "src/LawSpec/RustData.hs": "8fda864335ccb5478c39f56cb714d5275edf36fcbdc2d152bbe94960b644ad98",
244
+ "src/LawSpec/RustData.hs": "0d28ff5b35c5085c55604ef1eea366dec737b29d3352ef1576bb82c7421b615c",
238
245
  "src/LawSpec/RustDefinitions.hs": "8c289e2779d7ed623f3578f20974dd9e2016c67734ee1447ed7f4b7c22caedf9",
239
- "src/LawSpec/RustEmit.hs": "0687d8589940e7b39daa953c439009d1416eba7da54e9936d2f5595316744d21",
246
+ "src/LawSpec/RustEmit.hs": "d08797ca26180b6ed2884c0576ec7b0265cadc2236a95d8754cfea89bb2940e0",
240
247
  "src/LawSpec/RustExpr.hs": "04b2ef81417b811c7b98a98acdadab4e588ca8757964a63ba8dc5936c36479e6",
241
248
  "src/LawSpec/RustNativeBinding.hs": "9d08348da571ac335e335e48c1ad4a67108f7bca54119f5960480e97a6d1da84",
242
249
  "src/LawSpec/RustNativeGenerators.hs": "a3b1484d9ff0008e4f961aa81d0aa51da57ec0cd7909124e80c98d56aacc8ce9",
250
+ "src/LawSpec/Scaffold.hs": "2cdaeaa0708803e6abf3b8e9062dfc2fe31e2d3a6df3b252a17b1ad91eb5d8f2",
243
251
  "src/LawSpec/Scalar.hs": "52e61fec81a337bb5b35e9e6f501446cf0b18bffa6c6af2ddc5aeac2d6e07131",
244
252
  "src/LawSpec/SpecializeDefinitions.hs": "08f2fe674a5e00d1be396d9edab0dd2c948b7beb12fa99f2a6aba00cbdf01e33",
245
253
  "src/LawSpec/Testing.hs": "7b0a2e58bcef24365883b479b6a5af720cc2ac4c217ae23bb771c2621d82aec3",
@@ -247,17 +255,17 @@
247
255
  "src/LawSpec/WebDefinitions.hs": "d654df765e4bafcb1acdd35058f8a510c2cd81920153c0a75ff1e7e1137c96e5",
248
256
  "src/LawSpec/WebExpr.hs": "0389dcd5cf7479dd23ef034b1012de6ebd70bf1dc9e3d90981dfb0ba2702596f",
249
257
  "src/LawSpec/WebNativeBinding.hs": "465251be1a93d24a775aa57955bb9ec612af7364c53c83017da051f44943eda9",
250
- "src/LawSpec/WebTypes.hs": "f77ffee1e0c7929964a889fb252c1c5d0977afed94664ffcb0f8770c37b98c70",
258
+ "src/LawSpec/WebTypes.hs": "f74c6e346e3e3922223f8738a8f85e2b036e8f0469d9d7f027400e2f60f6957e",
251
259
  "stack.yaml": "20ccf4d599e355e60b7aa4f814a7cd4299fe2048616cc2e6dbdc22a7bd8cec73",
252
260
  "stack.yaml.lock": "ae222b9c81af920c56e50fa4596fa57786e7fa5a7b461390362b2b2ff63818c7",
253
261
  "tools/embed-runtimes.py": "91a05197fc542a65387f3ccf4614a4817c850031eb4b84196c621b8baf344865",
254
262
  "wasm/app/Exports.hs": "4ecbdac8faa2449e6fc61b93c82e6278fa14374154f29b4dacf0eef433f06a47",
255
263
  "wasm/cabal.project": "021e560afdc5eb4cb7169e7119ecb8f92c9ee170245af909c94b612941bff5cc",
256
264
  "wasm/cabal.project.freeze": "733dbed3d2ecccb26e874fd58f136296dad772184deb1658c196b5d54a0814dc",
257
- "wasm/lawspec-wasm.cabal": "ee8235aa57e891fe5b1f0d798694f5db5bc6e83b4d013fd1a96e9b2d28aae613",
258
- "npm/core.wasm": "f67a99e2de93750f0d4930cc086688a74ee1d309c3818bfe3125490e01b08660",
265
+ "wasm/lawspec-wasm.cabal": "8121d57d0724e191598f25cfea986a18bc298c2fab38febb38fc721c7a9660f8",
266
+ "npm/core.wasm": "19d1ed55f899cb73a926d5982746c4ffd803f8cfe60ee83fbc86d400896edb2c",
259
267
  "npm/core_jsffi.js": "88d136efe92f7cff5758c8fec8d9b6bbc9707fe37741cebeeb415fe34ce3d72b",
260
268
  "npm/api.mjs": "e93251db289ff0609abaff78ad67f0a9af82508c1141c6a999604f67c56b6e7d",
261
- "npm/index.d.ts": "2674f8830bd20a2b9ef7dfa99e183598125b6bcc17e8d454e8f7cca1bbd2c9fe"
269
+ "npm/index.d.ts": "4847f99a55b5948b5f5cc1ed22cd404c3df625472148e0d57d2d9c3406ce6afd"
262
270
  }
263
271
  }
package/core.wasm CHANGED
Binary file
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 1,
3
+ "sources": ["orders.lawspec"],
4
+ "dependencies": { "shop.domain": "^1.0.0" },
5
+ "packages": ["../shop-domain"],
6
+ "targets": []
7
+ }
@@ -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,5 @@
1
+ {
2
+ "name": "shop.domain",
3
+ "version": "1.2.0",
4
+ "sources": ["src"]
5
+ }
@@ -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.13.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
  }