lawspec 0.9.0 → 0.10.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.
Files changed (42) hide show
  1. package/API-MIGRATION.md +78 -2
  2. package/LANGUAGE.md +10 -7
  3. package/NATIVE-BINDINGS.md +1046 -0
  4. package/PRIMITIVES.md +1 -1
  5. package/README.md +73 -23
  6. package/REFINEMENTS.md +1 -1
  7. package/RELEASE-0.10.md +60 -0
  8. package/api.mjs +23 -3
  9. package/bin/lawspec.mjs +17 -4
  10. package/build.json +56 -36
  11. package/core.wasm +0 -0
  12. package/examples/native-payments/go/example/payments/domain.go +38 -0
  13. package/examples/native-payments/go/example/payments/native_generators_test.go +13 -0
  14. package/examples/native-payments/go/lawspec.json +136 -0
  15. package/examples/native-payments/haskell/lawspec.json +149 -0
  16. package/examples/native-payments/haskell/src/PaymentsDomain.hs +21 -0
  17. package/examples/native-payments/haskell/test/PaymentGenerators.hs +12 -0
  18. package/examples/native-payments/java/lawspec.json +165 -0
  19. package/examples/native-payments/java/src/main/java/domain/PaymentsDomain.java +32 -0
  20. package/examples/native-payments/java/src/test/java/domain/PaymentGenerators.java +16 -0
  21. package/examples/native-payments/javascript/lawspec.json +149 -0
  22. package/examples/native-payments/javascript/src/payments_domain.mjs +44 -0
  23. package/examples/native-payments/javascript/test/lawspec_generators.mjs +6 -0
  24. package/examples/native-payments/kotlin/lawspec.json +165 -0
  25. package/examples/native-payments/kotlin/src/main/kotlin/domain/PaymentsDomain.kt +17 -0
  26. package/examples/native-payments/kotlin/src/test/kotlin/domain/PaymentGenerators.kt +12 -0
  27. package/examples/native-payments/python/lawspec.json +149 -0
  28. package/examples/native-payments/python/src/payments_domain.py +60 -0
  29. package/examples/native-payments/python/tests/lawspec_generators.py +15 -0
  30. package/examples/native-payments/rust/lawspec.json +167 -0
  31. package/examples/native-payments/rust/src/domain.rs +37 -0
  32. package/examples/native-payments/rust/src/lib.rs +2 -0
  33. package/examples/native-payments/rust/tests/support/lawspec_generators.rs +11 -0
  34. package/examples/native-payments/typescript/lawspec.json +149 -0
  35. package/examples/native-payments/typescript/src/payments_domain.ts +42 -0
  36. package/examples/native-payments/typescript/test/lawspec_generators.ts +8 -0
  37. package/examples/specs/payments.lawspec +76 -0
  38. package/examples-command.mjs +5 -0
  39. package/files.mjs +6 -6
  40. package/index.d.ts +53 -2
  41. package/native-examples.mjs +81 -0
  42. package/package.json +2 -2
package/API-MIGRATION.md CHANGED
@@ -1,8 +1,15 @@
1
- # Compiler API migration: schema 2 → schema 3
1
+ # Compiler API migration
2
+
3
+ This document covers the published schema-3 interface and the schema-4 native
4
+ binding interface introduced in 0.10. See
5
+ [schema 4 native bindings](#schema-4-native-bindings) when adding
6
+ application types or generators to an existing project.
7
+
8
+ ## Schema 2 → schema 3
2
9
 
3
10
  LawSpec 0.8 introduced API schema version **3**, which 0.9 continues to use.
4
11
  Requests may omit `schemaVersion` or
5
- send `3`. An explicit `2` (or any other version) receives a request diagnostic;
12
+ send `3`. An explicit `2` receives a request diagnostic;
6
13
  it is never silently reinterpreted. LawSpec specification syntax remains compatible.
7
14
  The generated `index.d.ts` describes the public protocol. Internal Haskell
8
15
  constructors and record fields are no longer the wire format.
@@ -202,3 +209,72 @@ definition and constructor contracts support recursive payload proof facts. Cons
202
209
  matches/constructions participate in the constructor dependency-cycle check.
203
210
  The TypeScript declarations now include both
204
211
  `allElements` and `allPayloads`; exhaustive visitors should handle both.
212
+
213
+ ## Schema 4 native bindings
214
+
215
+ Binding requests use `schemaVersion: 4`. Schema-3 requests remain supported for
216
+ existing specifications without bindings. This negotiation is deliberate: an
217
+ older compiler must reject a binding request rather than silently use generated
218
+ types in place of application types.
219
+
220
+ The JavaScript API selects schema 4 when `nativeBindings` is provided, unless an
221
+ explicit `schemaVersion` overrides it. A nonempty binding configuration with
222
+ schema 3 is rejected. Results and diagnostics report the negotiated schema.
223
+
224
+ `nativeBindings` contains optional `types`, `functions`, `generators`,
225
+ `rustCrate` and `goImports` fields. Native symbols use arrays of identifier segments; unknown
226
+ configuration fields are rejected. See [the native-binding scope and current
227
+ implementation status](NATIVE-BINDINGS.md). Rust, Python, JavaScript, TypeScript,
228
+ Java and Kotlin support application type bridges and native generator factories.
229
+ Go supports package-local and imported application types with native Rapid
230
+ factories. Haskell supports application types and native Hedgehog factories.
231
+ Custom codec hooks are available on all eight targets; see the native-binding
232
+ reference for target-specific signatures and current integration limitations.
233
+
234
+ ### Go imports in schema 4 binding requests
235
+
236
+ `nativeBindings.goImports` is an optional array of `{alias, path}` entries.
237
+ References such as `["domain", "Price"]` select exported names from that alias's
238
+ Go import path. One-component references continue to select package-local names.
239
+ Types, constructors, functions and generator factories share the import table;
240
+ only imports used by each generated file are emitted. Other targets reject this
241
+ option. Paths must be module import paths without empty or traversal segments.
242
+
243
+ Go reserves local application symbols before generating canonical data names.
244
+ Colliding generated families receive a fresh `Canonical` prefix (and a numeric
245
+ suffix in that prefix if necessary). Logical type and constructor IDs do not
246
+ change. Hooks that name generated data types should use the emitted canonical
247
+ names; imported application types keep their original names.
248
+
249
+ ### Codec hooks in schema 4 type bindings
250
+
251
+ `NativeTypeBinding` now accepts either `constructors` or
252
+ `codec: {toNative: NativeReference, fromNative: NativeReference}`. Both hook
253
+ references are required and constructor mappings cannot be combined with hooks.
254
+ The canonical side uses generated LawSpec data types, while the native side uses
255
+ `native`; generic hooks receive one directional child converter per type argument.
256
+ All eight targets implement emission. Go hooks return `(value, error)` and the
257
+ verified fixture places them beside the generated canonical types to avoid package
258
+ import cycles. See `NATIVE-BINDINGS.md` for signatures and
259
+ validation behavior.
260
+
261
+ ### Native-binding ownership transitions
262
+
263
+ Existing user adapters are protected when their paths become generated bridges.
264
+ Move application implementations into the configured native modules and save the
265
+ old adapters elsewhere before adopting bindings. Removing bindings preserves the
266
+ old bridge as user-owned content and reports a required adapter update; it does
267
+ not silently replace that content with a stub. Generated layout changes do not
268
+ move application-owned model, hook or factory files. See `NATIVE-BINDINGS.md` for
269
+ the migration sequence and all-target filesystem acceptance checks.
270
+
271
+ ### Optional generator scaffolds in schema 4
272
+
273
+ `NativeGeneratorBinding` accepts `stub?: boolean`, defaulting to false. Python,
274
+ Rust, JavaScript, TypeScript, Java, Kotlin, Go and Haskell support `stub: true` to
275
+ create a user-owned factory in the test directory. Go
276
+ requires a package-local factory and a quantified use to determine placement.
277
+ Existing factory files remain untouched. Factory signature changes
278
+ use the existing `adapterUpdates` reporting channel. See `NATIVE-BINDINGS.md`
279
+ for grouping, module collision checks, and layout
280
+ migration behavior.
package/LANGUAGE.md CHANGED
@@ -1,4 +1,4 @@
1
- # LawSpec language and compiler boundary (0.9)
1
+ # LawSpec language and compiler boundary (0.10)
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,
@@ -332,14 +332,17 @@ API schema v3 uses separately defined wire views, with lossless tagged scalar
332
332
  values. It does not serialize internal AST constructors. See the
333
333
  [API migration guide](API-MIGRATION.md).
334
334
 
335
- ## Beyond 0.9
335
+ ## Beyond 0.10
336
336
 
337
- GADTs, indexed families, and general dependent types are planned after 0.9.
337
+ GADTs, indexed families, and general dependent types are planned after 0.10.
338
338
  The Core type model distinguishes type arguments from index arguments, but that
339
339
  representation is not a claim that arbitrary dependent programs are accepted.
340
- User-defined products and sums have ordinary uniform type parameters. External
341
- type bindings, custom generator bindings, and cross-unit packages are separate
342
- future features.
340
+ User-defined products and sums have ordinary uniform type parameters.
341
+ External type bindings and custom generator bindings are implemented in the
342
+ 0.10 release; see [the binding reference](NATIVE-BINDINGS.md) for their
343
+ interface and acceptance status. They configure native representations alongside
344
+ the typed testing plan and do not change source-language typing or equality.
345
+ Cross-unit packages remain future work.
343
346
 
344
347
  ## Generated project formatting
345
348
 
@@ -357,5 +360,5 @@ code, and 72-column prose. Other targets follow Google language guidance where
357
360
  applicable, with standard Rust formatting. Formatting is deterministic in the
358
361
  native and WASM compilers; generation does not download or invoke a formatter.
359
362
 
360
- See [the release notes](RELEASE-0.9.md) for compatibility and scope, and the target
363
+ See [the release notes](RELEASE-0.10.md) for compatibility and scope, and the target
361
364
  guides for formatting verification and native representation details.