lawspec 0.25.0 → 0.26.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 (149) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/README.md +5 -4
  3. package/api.mjs +0 -8
  4. package/bin/lawspec.mjs +14 -52
  5. package/build.json +77 -105
  6. package/core.wasm +2 -2
  7. package/core_jsffi.js +5 -0
  8. package/examples/native-payments/clojure/lawspec.json +1 -1
  9. package/examples/native-payments/csharp/lawspec.json +1 -1
  10. package/examples/native-payments/elixir/lawspec.json +1 -1
  11. package/examples/native-payments/erlang/lawspec.json +1 -1
  12. package/examples/native-payments/fsharp/lawspec.json +1 -1
  13. package/examples/native-payments/gleam/lawspec.json +1 -1
  14. package/examples/native-payments/go/lawspec.json +1 -1
  15. package/examples/native-payments/groovy/lawspec.json +1 -1
  16. package/examples/native-payments/haskell/lawspec.json +1 -1
  17. package/examples/native-payments/java/lawspec.json +1 -1
  18. package/examples/native-payments/javascript/lawspec.json +1 -1
  19. package/examples/native-payments/kotlin/lawspec.json +1 -1
  20. package/examples/native-payments/python/lawspec.json +1 -1
  21. package/examples/native-payments/rust/lawspec.json +1 -1
  22. package/examples/native-payments/scala/lawspec.json +1 -1
  23. package/examples/native-payments/swift/lawspec.json +1 -1
  24. package/examples/native-payments/typescript/lawspec.json +1 -1
  25. package/examples/packages/orders/lawspec.json +1 -1
  26. package/examples/packages/orders/orders.lawspec +27 -25
  27. package/examples/packages/shop-domain/src/domain.lawspec +15 -14
  28. package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
  29. package/examples/packages/shop-tax-1/src/rates.lawspec +1 -0
  30. package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
  31. package/examples/packages/shop-tax-2/src/rates.lawspec +1 -0
  32. package/examples/rc1/authorization-snapshots.lawspec +24 -23
  33. package/examples/rc1/banner-filenames.lawspec +7 -6
  34. package/examples/rc1/bit-codec.lawspec +12 -11
  35. package/examples/rc1/bounded-witness-search.lawspec +52 -45
  36. package/examples/rc1/conflicting-requirements.lawspec +8 -7
  37. package/examples/rc1/constructive-witnesses.lawspec +40 -33
  38. package/examples/rc1/documentary-review.lawspec +9 -8
  39. package/examples/rc1/empty-domains.lawspec +16 -15
  40. package/examples/rc1/finite-integer-domains.lawspec +24 -23
  41. package/examples/rc1/law-metadata.lawspec +6 -5
  42. package/examples/rc1/native-payments.lawspec +17 -16
  43. package/examples/rc1/nesting/rrr.lawspec +4 -3
  44. package/examples/rc1/nesting/rru.lawspec +7 -6
  45. package/examples/rc1/nesting/rur.lawspec +7 -6
  46. package/examples/rc1/nesting/ruu.lawspec +10 -9
  47. package/examples/rc1/nesting/urr.lawspec +7 -6
  48. package/examples/rc1/nesting/uru.lawspec +10 -9
  49. package/examples/rc1/nesting/uur.lawspec +10 -9
  50. package/examples/rc1/nesting/uuu.lawspec +13 -12
  51. package/examples/rc1/order-workflow.lawspec +18 -17
  52. package/examples/rc1/parcel-measurements.lawspec +14 -13
  53. package/examples/rc1/picture-records.lawspec +6 -5
  54. package/examples/rc1/picture-tuples.lawspec +6 -5
  55. package/examples/rc1/record-payloads.lawspec +12 -11
  56. package/examples/rc1/recursive-records.lawspec +11 -10
  57. package/examples/rc1/refund-conformance.lawspec +7 -6
  58. package/examples/rc1/refund-policy.lawspec +15 -14
  59. package/examples/rc1/requirement-composition.lawspec +26 -25
  60. package/examples/rc1/structural-records.lawspec +13 -12
  61. package/examples/rc1-authoring.lawspec +6 -5
  62. package/examples/specs/abilities.lawspec +67 -65
  63. package/examples/specs/ability_imports.lawspec +58 -57
  64. package/examples/specs/actors.lawspec +23 -22
  65. package/examples/specs/algebra.lawspec +142 -141
  66. package/examples/specs/approvals.lawspec +16 -15
  67. package/examples/specs/async_bindings.lawspec +10 -9
  68. package/examples/specs/async_fetch.lawspec +12 -11
  69. package/examples/specs/atoi_codec.lawspec +16 -15
  70. package/examples/specs/boolean_flags.lawspec +10 -9
  71. package/examples/specs/builtins.lawspec +73 -72
  72. package/examples/specs/canonical_url.lawspec +14 -13
  73. package/examples/specs/collections.lawspec +153 -154
  74. package/examples/specs/composition.lawspec +70 -66
  75. package/examples/specs/concurrent_collections.lawspec +8 -7
  76. package/examples/specs/consistency.lawspec +4 -3
  77. package/examples/specs/contracts.lawspec +80 -79
  78. package/examples/specs/crypto.lawspec +26 -25
  79. package/examples/specs/ctc.lawspec +148 -0
  80. package/examples/specs/currying.lawspec +32 -31
  81. package/examples/specs/data_types.lawspec +50 -49
  82. package/examples/specs/distribution.lawspec +57 -56
  83. package/examples/specs/domain_modeling.lawspec +48 -47
  84. package/examples/specs/durations.lawspec +39 -38
  85. package/examples/specs/equivalent.lawspec +25 -24
  86. package/examples/specs/failures.lawspec +64 -63
  87. package/examples/specs/finite_data.lawspec +32 -31
  88. package/examples/specs/flow_stack.lawspec +64 -63
  89. package/examples/specs/gadt_expressions.lawspec +50 -49
  90. package/examples/specs/generation.lawspec +115 -114
  91. package/examples/specs/handler_bindings.lawspec +42 -40
  92. package/examples/specs/handles.lawspec +2 -1
  93. package/examples/specs/harness.lawspec +45 -43
  94. package/examples/specs/harness_testing.lawspec +18 -13
  95. package/examples/specs/indexed_arithmetic.lawspec +401 -126
  96. package/examples/specs/indexed_families.lawspec +182 -66
  97. package/examples/specs/keywords.lawspec +22 -21
  98. package/examples/specs/limits.lawspec +6 -5
  99. package/examples/specs/list_contracts.lawspec +121 -120
  100. package/examples/specs/list_refinements.lawspec +43 -42
  101. package/examples/specs/lists.lawspec +45 -44
  102. package/examples/specs/matchers.lawspec +79 -78
  103. package/examples/specs/matching.lawspec +43 -42
  104. package/examples/specs/mixed_inputs.lawspec +25 -24
  105. package/examples/specs/models.lawspec +44 -43
  106. package/examples/specs/parse_port.lawspec +28 -27
  107. package/examples/specs/payments.lawspec +55 -54
  108. package/examples/specs/railway.lawspec +59 -58
  109. package/examples/specs/records.lawspec +149 -148
  110. package/examples/specs/records_inner.lawspec +5 -4
  111. package/examples/specs/recursive_refinements.lawspec +30 -29
  112. package/examples/specs/refined_definitions.lawspec +24 -23
  113. package/examples/specs/refinements.lawspec +58 -57
  114. package/examples/specs/resilience.lawspec +159 -158
  115. package/examples/specs/resources.lawspec +61 -60
  116. package/examples/specs/scalar_adapters.lawspec +60 -59
  117. package/examples/specs/scalar_catalog.lawspec +165 -164
  118. package/examples/specs/scalars.lawspec +78 -77
  119. package/examples/specs/scheduling_order.lawspec +8 -7
  120. package/examples/specs/scheduling_overlap.lawspec +5 -4
  121. package/examples/specs/sequences.lawspec +66 -65
  122. package/examples/specs/sessions.lawspec +13 -12
  123. package/examples/specs/slug.lawspec +16 -15
  124. package/examples/specs/sum_refinements.lawspec +42 -41
  125. package/examples/specs/tables.lawspec +29 -28
  126. package/examples/specs/total_functions.lawspec +71 -70
  127. package/examples/specs/workflows.lawspec +101 -100
  128. package/examples-command.mjs +4 -6
  129. package/explain.mjs +6 -4
  130. package/expression-presentation.mjs +8 -8
  131. package/files.mjs +1 -1
  132. package/index.d.ts +4 -527
  133. package/launcher.mjs +9 -2
  134. package/lsp.mjs +10 -6
  135. package/native-examples.mjs +2 -2
  136. package/package.json +1 -1
  137. package/starter-rc1.lawspec +6 -5
  138. package/starter.lawspec +16 -15
  139. package/templates.mjs +4 -2
  140. package/migrate.mjs +0 -135
  141. package/migration-bindings.mjs +0 -86
  142. package/migration-cases.mjs +0 -45
  143. package/migration-collections.mjs +0 -54
  144. package/migration-correspondence.mjs +0 -275
  145. package/migration-generation.mjs +0 -99
  146. package/migration-laws.mjs +0 -102
  147. package/migration-records.mjs +0 -166
  148. package/migration-source.mjs +0 -247
  149. package/migration-write.mjs +0 -156
@@ -14,29 +14,30 @@ law "|allowed requests are approved| is
14
14
  owner: Payments.Review
15
15
  description:
16
16
  "An allowed request receives approval."
17
- end
17
+ end description
18
18
  definition:
19
19
  review true must be Approved
20
- end
20
+ end definition
21
21
  references:
22
22
  #S{ref law "|other requests are declined| description,
23
23
  ref function review}
24
24
  ref law "|other requests are declined| references."|Review policy|
25
25
  "|Review policy|: "Allowed requests are approved; all other requests are declined."
26
- end
27
- end
26
+ end references
27
+ end law
28
28
 
29
29
  law "|other requests are declined| is
30
30
  owner: Payments.Review
31
31
  id: "REVIEW-002"
32
32
  description:
33
33
  "A request without permission receives a decline."
34
- end
34
+ end description
35
35
  definition:
36
36
  review false must be Declined
37
- end
37
+ end definition
38
38
  references:
39
39
  ref law "|allowed requests are approved| definition
40
40
  "|Review policy|: "Allowed requests are approved; all other requests are declined."
41
- end
42
- end
41
+ end references
42
+ end law
43
+ end unit
@@ -9,38 +9,39 @@ law "|no issued approval incurs an obligation| is
9
9
  definition:
10
10
  for all (approval of type UnissuedApproval) =>
11
11
  false
12
- end
13
- end
12
+ end for all
13
+ end definition
14
14
  description:
15
15
  "No approval can be constructed in this domain. Universal verification evaluates zero cases."
16
- end
17
- end
16
+ end description
17
+ end law
18
18
 
19
19
  law "|excluded inputs require no witnesses| is
20
20
  definition:
21
21
  for all (enabled of type Bool where false) =>
22
22
  there must exist (witness of type Integer) such that
23
23
  false
24
- end
25
- end
26
- end
24
+ end exists
25
+ end for all
26
+ end definition
27
27
  description:
28
28
  "The restriction excludes every input. This establishes no witness for any actual input."
29
- end
30
- end
29
+ end description
30
+ end law
31
31
 
32
32
  law "|absence remains different from existence| is
33
33
  definition:
34
34
  there must not exist (approval of type UnissuedApproval) such that
35
35
  true
36
- end
37
- end
38
- end
36
+ end exists
37
+ end definition
38
+ end law
39
39
 
40
40
  law "|excluded payments incur no obligation| is
41
41
  definition:
42
42
  for all (eligible of type Bool where false) =>
43
43
  false
44
- end
45
- end
46
- end
44
+ end for all
45
+ end definition
46
+ end law
47
+ end unit
@@ -7,61 +7,61 @@ end function
7
7
  law "|each small credit has its exact settlement amount| is
8
8
  description:
9
9
  "Every amount from zero through three receives exactly one extra cent."
10
- end
10
+ end description
11
11
  definition:
12
12
  for all (amount of type Integer where amount >= 0 and amount <= 3) =>
13
13
  there exists (settled of type Integer where
14
14
  settled >= amount + 1 and settled <= amount + 1) such that
15
15
  settled must be credit amount
16
- end
17
- end
18
- end
16
+ end exists
17
+ end for all
18
+ end definition
19
19
  expect credit amount = expected
20
20
  in table (amount, expected):
21
21
  row 0, 1
22
22
  row 1, 2
23
23
  row 2, 3
24
24
  row 3, 4
25
- end
26
- end
25
+ end table
26
+ end law
27
27
 
28
28
  law "|small retry budgets include zero| is
29
29
  definition:
30
30
  for all (budget of type Whole where budget <= 3) =>
31
31
  must budget >= 0
32
- end
33
- end
34
- end
32
+ end for all
33
+ end definition
34
+ end law
35
35
 
36
36
  law "|positive attempt counts exclude zero| is
37
37
  definition:
38
38
  there must not exist (attempts of type Nat where attempts <= 3) such that
39
39
  attempts = 0
40
- end
41
- end
42
- end
40
+ end exists
41
+ end definition
42
+ end law
43
43
 
44
44
  law "|a small credit cannot settle outside the limit| is
45
45
  definition:
46
46
  there must not exist (settled of type Integer where
47
47
  settled >= 0 and settled <= 3) such that
48
48
  settled = 4
49
- end
50
- end
51
- end
49
+ end exists
50
+ end definition
51
+ end law
52
52
 
53
53
  law "|consecutive exact cents have no intermediate amount| is
54
54
  description:
55
55
  "No exact integer amount lies strictly between two consecutive cents."
56
- end
56
+ end description
57
57
  definition:
58
58
  for all (amount of type Integer)
59
59
  (between of type Integer where between > amount and between < amount + 1)
60
60
  =>
61
61
  false
62
- end
63
- end
64
- end
62
+ end for all
63
+ end definition
64
+ end law
65
65
 
66
66
  law "|every exact amount has an adjacent settlement amount| is
67
67
  definition:
@@ -69,7 +69,8 @@ law "|every exact amount has an adjacent settlement amount| is
69
69
  there exists (settled of type Integer where
70
70
  settled > amount and settled <= amount + 2) such that
71
71
  settled must be amount + 1
72
- end
73
- end
74
- end
75
- end
72
+ end exists
73
+ end for all
74
+ end definition
75
+ end law
76
+ end unit
@@ -14,16 +14,17 @@ law "|allowed requests are approved| is
14
14
  owner: Payments.Review
15
15
  description:
16
16
  "An allowed request receives approval."
17
- end
17
+ end description
18
18
  definition:
19
19
  review true must be Approved
20
- end
21
- end
20
+ end definition
21
+ end law
22
22
 
23
23
  law "|other requests are declined| is
24
24
  owner: Payments.Review
25
25
  id: "REVIEW-002"
26
26
  definition:
27
27
  review false must be Declined
28
- end
29
- end
28
+ end definition
29
+ end law
30
+ end unit
@@ -35,13 +35,13 @@ law "|fees preserve currency and exact decimal value| is
35
35
  definition:
36
36
  for all (money of type Money) =>
37
37
  addFee money must be feeModel money
38
- end
39
- end
38
+ end for all
39
+ end definition
40
40
 
41
41
  example "|decimal tenths|:
42
42
  money = Money record{amount = 0.1, currency = USD}
43
43
  expect addFee money = Money record{amount = 0.3, currency = USD}
44
- end
44
+ end example
45
45
 
46
46
  example "|small amount is not rounded away|:
47
47
  money = Money record{
@@ -50,47 +50,47 @@ law "|fees preserve currency and exact decimal value| is
50
50
  expect addFee money = Money record{
51
51
  amount = 0.200000000000000000000000000001, currency = EUR
52
52
  }
53
- end
53
+ end example
54
54
 
55
55
  example "|beyond binary floating precision|:
56
56
  money = Money record{amount = 9007199254740993.1, currency = GBP}
57
57
  expect addFee money = Money record{
58
58
  amount = 9007199254740993.3, currency = GBP
59
59
  }
60
- end
61
- end
60
+ end example
61
+ end law
62
62
 
63
63
  law "|payment variants and payloads survive native conversion| is
64
64
  definition:
65
65
  for all (payment of type Payment) =>
66
66
  roundTrip payment must be payment
67
- end
68
- end
67
+ end for all
68
+ end definition
69
69
 
70
70
  example "|successful payment|:
71
71
  payment = Paid (Money record{amount = 12.34, currency = EUR})
72
72
  expect roundTrip payment = Paid (Money record{
73
73
  amount = 12.34, currency = EUR
74
74
  })
75
- end
75
+ end example
76
76
 
77
77
  example "|declined payment|:
78
78
  payment = Declined "card declined"
79
79
  expect roundTrip payment = Declined "card declined"
80
- end
81
- end
80
+ end example
81
+ end law
82
82
 
83
83
  law "|archives preserve order duplicates and absence| is
84
84
  definition:
85
85
  for all (payments of type List (Maybe Payment)) =>
86
86
  archive payments must be payments
87
- end
88
- end
87
+ end for all
88
+ end definition
89
89
 
90
90
  example "|empty archive|:
91
91
  payments = []
92
92
  expect archive payments = []
93
- end
93
+ end example
94
94
 
95
95
  example "|missing is different from a declined payment|:
96
96
  payments = [
@@ -103,5 +103,6 @@ law "|archives preserve order duplicates and absence| is
103
103
  Just (Paid (Money record{amount = 0.1, currency = USD})),
104
104
  Just (Paid (Money record{amount = 0.1, currency = USD}))
105
105
  ]
106
- end
107
- end
106
+ end example
107
+ end law
108
+ end unit
@@ -25,9 +25,10 @@ end function
25
25
  law "|emailPdfInvoice result| is
26
26
  description:
27
27
  "PDF invoices sent by email retain their file names."
28
- end
28
+ end description
29
29
  definition:
30
30
  "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
31
31
  "invoice.pdf"
32
- end
33
- end
32
+ end definition
33
+ end law
34
+ end unit
@@ -32,12 +32,12 @@ end function
32
32
  law "|emailPdfInvoice result| is
33
33
  description:
34
34
  "PDF invoices sent by email retain their file names."
35
- end
35
+ end description
36
36
  definition:
37
37
  "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
38
38
  "invoice.pdf"
39
- end
40
- end
39
+ end definition
40
+ end law
41
41
 
42
42
  function emailPlainTextInvoice (name of type Text) -> EmailDelivery is
43
43
  EmailDelivery record{recipient = "accounts@example.com", document =
@@ -48,9 +48,10 @@ end function
48
48
  law "|emailPlainTextInvoice result| is
49
49
  description:
50
50
  "Plain-text invoices have no PDF file name."
51
- end
51
+ end description
52
52
  definition:
53
53
  "|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
54
54
  Nothing
55
- end
56
- end
55
+ end definition
56
+ end law
57
+ end unit
@@ -33,12 +33,12 @@ end function
33
33
  law "|emailPdfInvoice result| is
34
34
  description:
35
35
  "PDF invoices sent by email retain their file names."
36
- end
36
+ end description
37
37
  definition:
38
38
  "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
39
39
  "invoice.pdf"
40
- end
41
- end
40
+ end definition
41
+ end law
42
42
 
43
43
  function emailPdfLetter (name of type Text) -> EmailDelivery is
44
44
  EmailDelivery record{recipient = "accounts@example.com", document = (Letter
@@ -49,9 +49,10 @@ end function
49
49
  law "|emailPdfLetter result| is
50
50
  description:
51
51
  "Letters have no invoice PDF file name."
52
- end
52
+ end description
53
53
  definition:
54
54
  "|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
55
55
  Nothing
56
- end
57
- end
56
+ end definition
57
+ end law
58
+ end unit
@@ -37,12 +37,12 @@ end function
37
37
  law "|emailPdfInvoice result| is
38
38
  description:
39
39
  "PDF invoices sent by email retain their file names."
40
- end
40
+ end description
41
41
  definition:
42
42
  "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
43
43
  "invoice.pdf"
44
- end
45
- end
44
+ end definition
45
+ end law
46
46
 
47
47
  function emailPlainTextInvoice (name of type Text) -> EmailDelivery is
48
48
  EmailDelivery record{recipient = "accounts@example.com", document = (Invoice
@@ -53,12 +53,12 @@ end function
53
53
  law "|emailPlainTextInvoice result| is
54
54
  description:
55
55
  "Plain-text invoices have no PDF file name."
56
- end
56
+ end description
57
57
  definition:
58
58
  "|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
59
59
  Nothing
60
- end
61
- end
60
+ end definition
61
+ end law
62
62
 
63
63
  function emailPdfLetter (name of type Text) -> EmailDelivery is
64
64
  EmailDelivery record{recipient = "accounts@example.com", document = (Letter
@@ -69,9 +69,10 @@ end function
69
69
  law "|emailPdfLetter result| is
70
70
  description:
71
71
  "Letters have no invoice PDF file name."
72
- end
72
+ end description
73
73
  definition:
74
74
  "|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
75
75
  Nothing
76
- end
77
- end
76
+ end definition
77
+ end law
78
+ end unit
@@ -29,12 +29,12 @@ end function
29
29
  law "|emailPdfInvoice result| is
30
30
  description:
31
31
  "PDF invoices sent by email retain their file names."
32
- end
32
+ end description
33
33
  definition:
34
34
  "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
35
35
  "invoice.pdf"
36
- end
37
- end
36
+ end definition
37
+ end law
38
38
 
39
39
  function downloadPdfInvoice (name of type Text) -> Delivery is
40
40
  Download (record{document = record{number =
@@ -44,9 +44,10 @@ end function
44
44
  law "|downloadPdfInvoice result| is
45
45
  description:
46
46
  "Downloads have no email invoice PDF file name."
47
- end
47
+ end description
48
48
  definition:
49
49
  "|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
50
50
  Nothing
51
- end
52
- end
51
+ end definition
52
+ end law
53
+ end unit
@@ -32,12 +32,12 @@ end function
32
32
  law "|emailPdfInvoice result| is
33
33
  description:
34
34
  "PDF invoices sent by email retain their file names."
35
- end
35
+ end description
36
36
  definition:
37
37
  "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
38
38
  "invoice.pdf"
39
- end
40
- end
39
+ end definition
40
+ end law
41
41
 
42
42
  function emailPlainTextInvoice (name of type Text) -> Delivery is
43
43
  Email (record{recipient = "accounts@example.com", document =
@@ -48,12 +48,12 @@ end function
48
48
  law "|emailPlainTextInvoice result| is
49
49
  description:
50
50
  "Plain-text invoices have no PDF file name."
51
- end
51
+ end description
52
52
  definition:
53
53
  "|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
54
54
  Nothing
55
- end
56
- end
55
+ end definition
56
+ end law
57
57
 
58
58
  function downloadPdfInvoice (name of type Text) -> Delivery is
59
59
  Download (record{document = record{number =
@@ -64,9 +64,10 @@ end function
64
64
  law "|downloadPdfInvoice result| is
65
65
  description:
66
66
  "Downloads have no email invoice PDF file name."
67
- end
67
+ end description
68
68
  definition:
69
69
  "|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
70
70
  Nothing
71
- end
72
- end
71
+ end definition
72
+ end law
73
+ end unit
@@ -33,12 +33,12 @@ end function
33
33
  law "|emailPdfInvoice result| is
34
34
  description:
35
35
  "PDF invoices sent by email retain their file names."
36
- end
36
+ end description
37
37
  definition:
38
38
  "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
39
39
  "invoice.pdf"
40
- end
41
- end
40
+ end definition
41
+ end law
42
42
 
43
43
  function emailPdfLetter (name of type Text) -> Delivery is
44
44
  Email (record{recipient = "accounts@example.com", document =
@@ -49,12 +49,12 @@ end function
49
49
  law "|emailPdfLetter result| is
50
50
  description:
51
51
  "Letters have no invoice PDF file name."
52
- end
52
+ end description
53
53
  definition:
54
54
  "|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
55
55
  Nothing
56
- end
57
- end
56
+ end definition
57
+ end law
58
58
 
59
59
  function downloadPdfInvoice (name of type Text) -> Delivery is
60
60
  Download (record{document = (Invoice (record{number = "INV-2026-10", file =
@@ -65,9 +65,10 @@ end function
65
65
  law "|downloadPdfInvoice result| is
66
66
  description:
67
67
  "Downloads have no email invoice PDF file name."
68
- end
68
+ end description
69
69
  definition:
70
70
  "|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
71
71
  Nothing
72
- end
73
- end
72
+ end definition
73
+ end law
74
+ end unit
@@ -38,12 +38,12 @@ end function
38
38
  law "|emailPdfInvoice result| is
39
39
  description:
40
40
  "PDF invoices sent by email retain their file names."
41
- end
41
+ end description
42
42
  definition:
43
43
  "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
44
44
  "invoice.pdf"
45
- end
46
- end
45
+ end definition
46
+ end law
47
47
 
48
48
  function emailPlainTextInvoice (name of type Text) -> Delivery is
49
49
  Email (record{recipient = "accounts@example.com", document =
@@ -54,12 +54,12 @@ end function
54
54
  law "|emailPlainTextInvoice result| is
55
55
  description:
56
56
  "Plain-text invoices have no PDF file name."
57
- end
57
+ end description
58
58
  definition:
59
59
  "|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
60
60
  Nothing
61
- end
62
- end
61
+ end definition
62
+ end law
63
63
 
64
64
  function emailPdfLetter (name of type Text) -> Delivery is
65
65
  Email (record{recipient = "accounts@example.com", document =
@@ -70,12 +70,12 @@ end function
70
70
  law "|emailPdfLetter result| is
71
71
  description:
72
72
  "Letters have no invoice PDF file name."
73
- end
73
+ end description
74
74
  definition:
75
75
  "|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
76
76
  Nothing
77
- end
78
- end
77
+ end definition
78
+ end law
79
79
 
80
80
  function downloadPdfInvoice (name of type Text) -> Delivery is
81
81
  Download (record{document = (Invoice (record{number = "INV-2026-10", file =
@@ -87,9 +87,10 @@ end function
87
87
  law "|downloadPdfInvoice result| is
88
88
  description:
89
89
  "Downloads have no email invoice PDF file name."
90
- end
90
+ end description
91
91
  definition:
92
92
  "|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
93
93
  Nothing
94
- end
95
- end
94
+ end definition
95
+ end law
96
+ end unit
@@ -28,17 +28,17 @@ end function
28
28
  ability OrderStore is
29
29
  current of type OrderState
30
30
  change of type OrderState -> ()
31
- end
31
+ end ability
32
32
 
33
33
  handler inMemory for OrderStore with state order of type OrderState
34
34
  start Pending is
35
- current is order end
36
- change updated is ~order := updated; () end
37
- end
35
+ operation current is order end operation
36
+ operation change updated is ~order := updated; () end operation
37
+ end handler
38
38
 
39
39
  procedure perform (action of type OrderAction) -> OrderState uses OrderStore is
40
40
  let updated = nextState current action in
41
- change updated; current
41
+ change updated; current end let
42
42
  end procedure
43
43
 
44
44
  procedure process (actions of type List OrderAction) -> OrderState
@@ -51,7 +51,7 @@ procedure process (actions of type List OrderAction) -> OrderState
51
51
  end procedure
52
52
 
53
53
  function runOrder (actions of type List OrderAction) -> OrderState is
54
- handle process actions with inMemory end
54
+ handle process actions with inMemory end handle
55
55
  end function
56
56
 
57
57
  function modelRun (state of type OrderState)
@@ -78,8 +78,8 @@ law "|order transitions follow the business lifecycle| is
78
78
  nextState state action must be Shipped)
79
79
  and ((state = Pending or state = Authorized) and action = Cancel implies
80
80
  nextState state action must be Cancelled)
81
- end
82
- end
81
+ end for all
82
+ end definition
83
83
  expect nextState state action = expected
84
84
  in table (state, action, expected):
85
85
  row Pending, Authorize, Authorized
@@ -94,18 +94,18 @@ law "|order transitions follow the business lifecycle| is
94
94
  row Cancelled, Authorize, Cancelled
95
95
  row Cancelled, Dispatch, Cancelled
96
96
  row Cancelled, Cancel, Cancelled
97
- end
98
- end
97
+ end table
98
+ end law
99
99
 
100
100
  law "|processing retains each completed transition| is
101
101
  description:
102
102
  "Every action observes the state left by the previous action."
103
- end
103
+ end description
104
104
  definition:
105
105
  for all (actions of type List OrderAction) =>
106
106
  runOrder actions must be modelRun Pending actions
107
- end
108
- end
107
+ end for all
108
+ end definition
109
109
  expect runOrder actions = expected
110
110
  in table (actions, expected):
111
111
  row [], Pending
@@ -116,11 +116,12 @@ law "|processing retains each completed transition| is
116
116
  row [Authorize, Cancel, Dispatch], Cancelled
117
117
  row [Authorize, Dispatch, Cancel], Shipped
118
118
  row [Authorize, Dispatch, Authorize], Shipped
119
- end
120
- end
119
+ end table
120
+ end law
121
121
 
122
122
  law "|independent orders start pending| is
123
123
  definition:
124
124
  runOrder [Authorize] must be Authorized and runOrder [] must be Pending
125
- end
126
- end
125
+ end definition
126
+ end law
127
+ end unit