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
@@ -0,0 +1,81 @@
1
+ import {readFile, readdir, mkdir} from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import {templates, commands, setup} from './templates.mjs';
4
+ import {safePath, planWrites, applyWrites} from './files.mjs';
5
+
6
+ async function projectFiles(directory, prefix = '') {
7
+ const files = {};
8
+ for (const entry of await readdir(directory, {withFileTypes: true})) {
9
+ const name = prefix + entry.name;
10
+ const location = new URL(entry.name + (entry.isDirectory() ? '/' : ''), directory);
11
+ if (entry.isDirectory()) Object.assign(files, await projectFiles(location, name + '/'));
12
+ else if (entry.isFile()) files[name] = await readFile(location, 'utf8');
13
+ else throw new Error(`Unsupported bundled example entry: ${name}`);
14
+ }
15
+ return files;
16
+ }
17
+
18
+ export async function exportNativePayments(options, selected) {
19
+ const root = await safePath(process.cwd(), options.output || 'native_payments');
20
+ await mkdir(root, {recursive: true});
21
+ const law = await readFile(new URL('./examples/specs/payments.lawspec', import.meta.url), 'utf8');
22
+ const plans = [];
23
+ const results = [];
24
+ for (const target of selected) {
25
+ const directory = await safePath(root, target);
26
+ await mkdir(directory, {recursive: true});
27
+ const files = {
28
+ ...templates(target, {minify: options.minify === true}),
29
+ ...await projectFiles(new URL(`./examples/native-payments/${target}/`, import.meta.url)),
30
+ 'laws/payments.lawspec': law,
31
+ };
32
+ const config = JSON.parse(files['lawspec.json']);
33
+ config.machineBits = options.machineBits ?? 64;
34
+ files['lawspec.json'] = JSON.stringify(config, null, options.minify ? undefined : 2) + '\n';
35
+ files['README.md'] = `# Native payments: ${target}
36
+
37
+ This project checks application-owned payment types against the shared LawSpec
38
+ model. Money maps to Price, currency variants have application names, and the
39
+ archive preserves distinct present and absent payments.
40
+
41
+ ## Run
42
+
43
+ Install LawSpec and the native dependencies described below, then run:
44
+
45
+ \`\`\`sh
46
+ lawspec check
47
+ lawspec generate
48
+ ${commands[target]}
49
+ \`\`\`
50
+
51
+ ${setup[target]}
52
+
53
+ JavaScript and TypeScript projects require \`npm install\` before testing.
54
+ The specification includes exact decimal arithmetic and explicit USD/GBP examples.
55
+ The native price generator deliberately samples only EUR values between 1.00 and
56
+ 2.00; examples and deterministic boundaries still check the other cases. Its
57
+ framework's mapping operation preserves the native shrinker.
58
+
59
+ The application types use native exact decimals where available and LawSpec's
60
+ framework-independent numeric runtime otherwise. Run generation before compiling
61
+ the application so that runtime support is present.
62
+
63
+ ## Change the application
64
+
65
+ Edit the domain implementation or generator, then run the native tests again.
66
+ For example, change the fee from 0.2 to 0.3: the exact-decimal law must fail.
67
+ Edit \`lawspec.json\` to change native bindings and rerun \`lawspec generate\`.
68
+
69
+ All exported project files are user-owned. Re-exporting preserves your edits;
70
+ it reports changed bundled versions for review. Compiler-generated files use a
71
+ separate ownership manifest and remain protected against accidental overwrites.
72
+ `;
73
+ const artifacts = Object.entries(files).map(([path, content]) => ({path, content, ownership: 'user'}));
74
+ const plan = await planWrites(directory, artifacts, {manifest: '.lawspec/example.json'});
75
+ plans.push(plan);
76
+ results.push({target, directory, example: 'payments', files: artifacts.map(({path, ownership}) => ({path, ownership})),
77
+ changes: plan.changes.length, preservedAdapters: plan.preserved, adapterUpdates: plan.adapterUpdates});
78
+ }
79
+ await applyWrites(plans);
80
+ return results;
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lawspec",
3
- "version": "0.9.0",
3
+ "version": "0.10.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", "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", "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", "LICENSE", "starter.lawspec", "examples"],
12
12
  "scripts": { "test": "node --test test/*.test.mjs" }
13
13
  }