lawspec 0.23.0 → 0.25.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/CHANGELOG.md +167 -1
- package/README.md +29 -22
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +14 -23
- package/bin/lawspec.mjs +200 -67
- package/build.json +381 -155
- package/builtin-data-names.mjs +73 -0
- package/compatibility.json +21 -0
- package/core.wasm +2 -2
- package/doctor.mjs +98 -1
- package/examples/native-payments/clojure/lawspec.json +62 -0
- package/examples/native-payments/clojure/src/domain/payments.clj +11 -0
- package/examples/native-payments/clojure/test/domain/payment_generators.clj +9 -0
- package/examples/native-payments/csharp/lawspec.json +13 -2
- package/examples/native-payments/elixir/lawspec.json +14 -3
- package/examples/native-payments/erlang/lawspec.json +14 -3
- package/examples/native-payments/fsharp/lawspec.json +14 -3
- package/examples/native-payments/gleam/lawspec.json +14 -3
- package/examples/native-payments/go/lawspec.json +14 -3
- package/examples/native-payments/groovy/lawspec.json +176 -0
- package/examples/native-payments/groovy/src/main/groovy/domain/PaymentsDomain.groovy +49 -0
- package/examples/native-payments/groovy/src/test/groovy/domain/PaymentGenerators.groovy +15 -0
- package/examples/native-payments/haskell/lawspec.json +14 -3
- package/examples/native-payments/java/lawspec.json +14 -3
- package/examples/native-payments/javascript/lawspec.json +14 -3
- package/examples/native-payments/kotlin/lawspec.json +14 -3
- package/examples/native-payments/python/lawspec.json +14 -3
- package/examples/native-payments/rust/lawspec.json +14 -3
- package/examples/native-payments/scala/lawspec.json +176 -0
- package/examples/native-payments/scala/src/main/scala/domain/PaymentsDomain.scala +18 -0
- package/examples/native-payments/scala/src/test/scala/domain/PaymentGenerators.scala +8 -0
- package/examples/native-payments/swift/lawspec.json +165 -0
- package/examples/native-payments/swift/src/Native/PaymentsDomain.swift +35 -0
- package/examples/native-payments/swift/tests/Native/PaymentGenerators.swift +12 -0
- package/examples/native-payments/typescript/lawspec.json +14 -3
- package/examples/packages/orders/lawspec.json +25 -5
- package/examples/packages/orders/orders.lawspec +36 -34
- package/examples/packages/shop-domain/src/domain.lawspec +23 -21
- package/examples/packages/shop-tax-1/src/rates.lawspec +4 -4
- package/examples/packages/shop-tax-2/src/rates.lawspec +5 -4
- package/examples/rc1/authorization-snapshots.lawspec +112 -0
- package/examples/rc1/banner-filenames.lawspec +63 -0
- package/examples/rc1/bit-codec.lawspec +56 -0
- package/examples/rc1/bounded-witness-search.lawspec +144 -0
- package/examples/rc1/conflicting-requirements.lawspec +30 -0
- package/examples/rc1/constructive-witnesses.lawspec +113 -0
- package/examples/rc1/documentary-review.lawspec +42 -0
- package/examples/rc1/empty-domains.lawspec +46 -0
- package/examples/rc1/finite-integer-domains.lawspec +75 -0
- package/examples/rc1/law-metadata.lawspec +29 -0
- package/examples/rc1/native-payments.lawspec +107 -0
- package/examples/rc1/nesting/rrr.lawspec +33 -0
- package/examples/rc1/nesting/rru.lawspec +56 -0
- package/examples/rc1/nesting/rur.lawspec +57 -0
- package/examples/rc1/nesting/ruu.lawspec +77 -0
- package/examples/rc1/nesting/urr.lawspec +52 -0
- package/examples/rc1/nesting/uru.lawspec +72 -0
- package/examples/rc1/nesting/uur.lawspec +73 -0
- package/examples/rc1/nesting/uuu.lawspec +95 -0
- package/examples/rc1/order-workflow.lawspec +126 -0
- package/examples/rc1/parcel-measurements.lawspec +92 -0
- package/examples/rc1/picture-records.lawspec +51 -0
- package/examples/rc1/picture-tuples.lawspec +47 -0
- package/examples/rc1/record-payloads.lawspec +56 -0
- package/examples/rc1/recursive-records.lawspec +64 -0
- package/examples/rc1/refund-conformance.lawspec +44 -0
- package/examples/rc1/refund-policy.lawspec +88 -0
- package/examples/rc1/requirement-composition.lawspec +89 -0
- package/examples/rc1/structural-records.lawspec +53 -0
- package/examples/rc1-authoring.lawspec +56 -0
- package/examples-command.mjs +11 -5
- package/explain.mjs +112 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +934 -12
- package/lsp.mjs +231 -0
- package/migrate.mjs +135 -0
- package/migration-bindings.mjs +86 -0
- package/migration-cases.mjs +45 -0
- package/migration-collections.mjs +54 -0
- package/migration-correspondence.mjs +275 -0
- package/migration-generation.mjs +99 -0
- package/migration-laws.mjs +102 -0
- package/migration-records.mjs +166 -0
- package/migration-source.mjs +247 -0
- package/migration-write.mjs +156 -0
- package/native-evidence.mjs +187 -0
- package/native-examples.mjs +8 -1
- package/node-events-reporter.mjs +23 -0
- package/package.json +8 -1
- package/positional-fields.mjs +13 -0
- package/proof.d.ts +35 -0
- package/proof.mjs +174 -0
- package/scala-coverage.mjs +56 -0
- package/starter-rc1.lawspec +25 -0
- package/templates.mjs +65 -3
- package/test-command.mjs +177 -29
- package/typed-presentation.mjs +165 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
unit example.delivery.rru
|
|
2
|
+
|
|
3
|
+
type File is one of
|
|
4
|
+
| Pdf of type record{fileName of type Text
|
|
5
|
+
byteCount of type Whole}
|
|
6
|
+
| PlainText of type record{fileName of type Text}
|
|
7
|
+
end type
|
|
8
|
+
|
|
9
|
+
type EmailDelivery is a record{
|
|
10
|
+
recipient of type Text
|
|
11
|
+
document of type record{number of type Text
|
|
12
|
+
file of type File}
|
|
13
|
+
}
|
|
14
|
+
end type
|
|
15
|
+
|
|
16
|
+
function "|email invoice PDF file name|
|
|
17
|
+
(delivery of type EmailDelivery) -> Maybe Text is
|
|
18
|
+
first matching case of delivery:
|
|
19
|
+
when record{document = record{file = Pdf record{fileName = name}}}
|
|
20
|
+
then Just name
|
|
21
|
+
otherwise Nothing
|
|
22
|
+
end case
|
|
23
|
+
end function
|
|
24
|
+
|
|
25
|
+
function emailPdfInvoice (name of type Text) -> EmailDelivery is
|
|
26
|
+
EmailDelivery record{recipient = "accounts@example.com", document =
|
|
27
|
+
record{number = "INV-2026-10", file = (Pdf (record{fileName =
|
|
28
|
+
name,
|
|
29
|
+
byteCount = 1200}))}}
|
|
30
|
+
end function
|
|
31
|
+
|
|
32
|
+
law "|emailPdfInvoice result| is
|
|
33
|
+
description:
|
|
34
|
+
"PDF invoices sent by email retain their file names."
|
|
35
|
+
end
|
|
36
|
+
definition:
|
|
37
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
38
|
+
"invoice.pdf"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
function emailPlainTextInvoice (name of type Text) -> EmailDelivery is
|
|
43
|
+
EmailDelivery record{recipient = "accounts@example.com", document =
|
|
44
|
+
record{number = "INV-2026-10", file = (PlainText (record{fileName =
|
|
45
|
+
name}))}}
|
|
46
|
+
end function
|
|
47
|
+
|
|
48
|
+
law "|emailPlainTextInvoice result| is
|
|
49
|
+
description:
|
|
50
|
+
"Plain-text invoices have no PDF file name."
|
|
51
|
+
end
|
|
52
|
+
definition:
|
|
53
|
+
"|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
|
|
54
|
+
Nothing
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
unit example.delivery.rur
|
|
2
|
+
|
|
3
|
+
type Document is one of
|
|
4
|
+
| Invoice of type record{number of type Text
|
|
5
|
+
file of type record{fileName of type Text
|
|
6
|
+
byteCount of type Whole}}
|
|
7
|
+
| Letter of type record{subject of type Text
|
|
8
|
+
file of type record{fileName of type Text
|
|
9
|
+
byteCount of type Whole}}
|
|
10
|
+
end type
|
|
11
|
+
|
|
12
|
+
type EmailDelivery is a record{
|
|
13
|
+
recipient of type Text
|
|
14
|
+
document of type Document
|
|
15
|
+
}
|
|
16
|
+
end type
|
|
17
|
+
|
|
18
|
+
function "|email invoice PDF file name|
|
|
19
|
+
(delivery of type EmailDelivery) -> Maybe Text is
|
|
20
|
+
first matching case of delivery:
|
|
21
|
+
when record{document = Invoice record{file = record{fileName = name}}}
|
|
22
|
+
then Just name
|
|
23
|
+
otherwise Nothing
|
|
24
|
+
end case
|
|
25
|
+
end function
|
|
26
|
+
|
|
27
|
+
function emailPdfInvoice (name of type Text) -> EmailDelivery is
|
|
28
|
+
EmailDelivery record{recipient = "accounts@example.com", document = (Invoice
|
|
29
|
+
(record{number = "INV-2026-10", file = record{fileName
|
|
30
|
+
= name, byteCount = 1200}}))}
|
|
31
|
+
end function
|
|
32
|
+
|
|
33
|
+
law "|emailPdfInvoice result| is
|
|
34
|
+
description:
|
|
35
|
+
"PDF invoices sent by email retain their file names."
|
|
36
|
+
end
|
|
37
|
+
definition:
|
|
38
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
39
|
+
"invoice.pdf"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
function emailPdfLetter (name of type Text) -> EmailDelivery is
|
|
44
|
+
EmailDelivery record{recipient = "accounts@example.com", document = (Letter
|
|
45
|
+
(record{subject = "Receipt", file = record{fileName =
|
|
46
|
+
name, byteCount = 1200}}))}
|
|
47
|
+
end function
|
|
48
|
+
|
|
49
|
+
law "|emailPdfLetter result| is
|
|
50
|
+
description:
|
|
51
|
+
"Letters have no invoice PDF file name."
|
|
52
|
+
end
|
|
53
|
+
definition:
|
|
54
|
+
"|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
|
|
55
|
+
Nothing
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
unit example.delivery.ruu
|
|
2
|
+
|
|
3
|
+
type File is one of
|
|
4
|
+
| Pdf of type record{fileName of type Text
|
|
5
|
+
byteCount of type Whole}
|
|
6
|
+
| PlainText of type record{fileName of type Text}
|
|
7
|
+
end type
|
|
8
|
+
|
|
9
|
+
type Document is one of
|
|
10
|
+
| Invoice of type record{number of type Text
|
|
11
|
+
file of type File}
|
|
12
|
+
| Letter of type record{subject of type Text
|
|
13
|
+
file of type File}
|
|
14
|
+
end type
|
|
15
|
+
|
|
16
|
+
type EmailDelivery is a record{
|
|
17
|
+
recipient of type Text
|
|
18
|
+
document of type Document
|
|
19
|
+
}
|
|
20
|
+
end type
|
|
21
|
+
|
|
22
|
+
function "|email invoice PDF file name|
|
|
23
|
+
(delivery of type EmailDelivery) -> Maybe Text is
|
|
24
|
+
first matching case of delivery:
|
|
25
|
+
when record{document = Invoice record{file = Pdf record{fileName = name}}}
|
|
26
|
+
then Just name
|
|
27
|
+
otherwise Nothing
|
|
28
|
+
end case
|
|
29
|
+
end function
|
|
30
|
+
|
|
31
|
+
function emailPdfInvoice (name of type Text) -> EmailDelivery is
|
|
32
|
+
EmailDelivery record{recipient = "accounts@example.com", document = (Invoice
|
|
33
|
+
(record{number = "INV-2026-10", file = (Pdf (record{fileName = name,
|
|
34
|
+
byteCount = 1200}))}))}
|
|
35
|
+
end function
|
|
36
|
+
|
|
37
|
+
law "|emailPdfInvoice result| is
|
|
38
|
+
description:
|
|
39
|
+
"PDF invoices sent by email retain their file names."
|
|
40
|
+
end
|
|
41
|
+
definition:
|
|
42
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
43
|
+
"invoice.pdf"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
function emailPlainTextInvoice (name of type Text) -> EmailDelivery is
|
|
48
|
+
EmailDelivery record{recipient = "accounts@example.com", document = (Invoice
|
|
49
|
+
(record{number = "INV-2026-10", file = (PlainText
|
|
50
|
+
(record{fileName = name}))}))}
|
|
51
|
+
end function
|
|
52
|
+
|
|
53
|
+
law "|emailPlainTextInvoice result| is
|
|
54
|
+
description:
|
|
55
|
+
"Plain-text invoices have no PDF file name."
|
|
56
|
+
end
|
|
57
|
+
definition:
|
|
58
|
+
"|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
|
|
59
|
+
Nothing
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
function emailPdfLetter (name of type Text) -> EmailDelivery is
|
|
64
|
+
EmailDelivery record{recipient = "accounts@example.com", document = (Letter
|
|
65
|
+
(record{subject = "Receipt", file = (Pdf (record{fileName = name, byteCount
|
|
66
|
+
= 1200}))}))}
|
|
67
|
+
end function
|
|
68
|
+
|
|
69
|
+
law "|emailPdfLetter result| is
|
|
70
|
+
description:
|
|
71
|
+
"Letters have no invoice PDF file name."
|
|
72
|
+
end
|
|
73
|
+
definition:
|
|
74
|
+
"|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
|
|
75
|
+
Nothing
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
unit example.delivery.urr
|
|
2
|
+
|
|
3
|
+
type Delivery is one of
|
|
4
|
+
| Email of type record{recipient of type Text
|
|
5
|
+
document of type record{number of type Text
|
|
6
|
+
file of type record{fileName of type Text
|
|
7
|
+
byteCount of type Whole}}}
|
|
8
|
+
| Download of type record{document of type record{number of type Text
|
|
9
|
+
file of type record{fileName of type Text
|
|
10
|
+
byteCount of type Whole}}}
|
|
11
|
+
end type
|
|
12
|
+
|
|
13
|
+
function "|email invoice PDF file name|
|
|
14
|
+
(delivery of type Delivery) -> Maybe Text is
|
|
15
|
+
first matching case of delivery:
|
|
16
|
+
when Email record{document = record{file = record{fileName = name}}}
|
|
17
|
+
then Just name
|
|
18
|
+
otherwise Nothing
|
|
19
|
+
end case
|
|
20
|
+
end function
|
|
21
|
+
|
|
22
|
+
function emailPdfInvoice (name of type Text) -> Delivery is
|
|
23
|
+
Email (record{recipient = "accounts@example.com", document =
|
|
24
|
+
record{number = "INV-2026-10", file = record{fileName =
|
|
25
|
+
name,
|
|
26
|
+
byteCount = 1200}}})
|
|
27
|
+
end function
|
|
28
|
+
|
|
29
|
+
law "|emailPdfInvoice result| is
|
|
30
|
+
description:
|
|
31
|
+
"PDF invoices sent by email retain their file names."
|
|
32
|
+
end
|
|
33
|
+
definition:
|
|
34
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
35
|
+
"invoice.pdf"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
function downloadPdfInvoice (name of type Text) -> Delivery is
|
|
40
|
+
Download (record{document = record{number =
|
|
41
|
+
"INV-2026-10", file = record{fileName = name, byteCount = 1200}}})
|
|
42
|
+
end function
|
|
43
|
+
|
|
44
|
+
law "|downloadPdfInvoice result| is
|
|
45
|
+
description:
|
|
46
|
+
"Downloads have no email invoice PDF file name."
|
|
47
|
+
end
|
|
48
|
+
definition:
|
|
49
|
+
"|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
|
|
50
|
+
Nothing
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
unit example.delivery.uru
|
|
2
|
+
|
|
3
|
+
type File is one of
|
|
4
|
+
| Pdf of type record{fileName of type Text
|
|
5
|
+
byteCount of type Whole}
|
|
6
|
+
| PlainText of type record{fileName of type Text}
|
|
7
|
+
end type
|
|
8
|
+
|
|
9
|
+
type Delivery is one of
|
|
10
|
+
| Email of type record{recipient of type Text
|
|
11
|
+
document of type record{number of type Text
|
|
12
|
+
file of type File}}
|
|
13
|
+
| Download of type record{document of type record{number of type Text
|
|
14
|
+
file of type File}}
|
|
15
|
+
end type
|
|
16
|
+
|
|
17
|
+
function "|email invoice PDF file name|
|
|
18
|
+
(delivery of type Delivery) -> Maybe Text is
|
|
19
|
+
first matching case of delivery:
|
|
20
|
+
when Email record{document = record{file = Pdf record{fileName = name}}}
|
|
21
|
+
then Just name
|
|
22
|
+
otherwise Nothing
|
|
23
|
+
end case
|
|
24
|
+
end function
|
|
25
|
+
|
|
26
|
+
function emailPdfInvoice (name of type Text) -> Delivery is
|
|
27
|
+
Email (record{recipient = "accounts@example.com", document =
|
|
28
|
+
record{number = "INV-2026-10", file = (Pdf (record{fileName
|
|
29
|
+
= name, byteCount = 1200}))}})
|
|
30
|
+
end function
|
|
31
|
+
|
|
32
|
+
law "|emailPdfInvoice result| is
|
|
33
|
+
description:
|
|
34
|
+
"PDF invoices sent by email retain their file names."
|
|
35
|
+
end
|
|
36
|
+
definition:
|
|
37
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
38
|
+
"invoice.pdf"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
function emailPlainTextInvoice (name of type Text) -> Delivery is
|
|
43
|
+
Email (record{recipient = "accounts@example.com", document =
|
|
44
|
+
record{number = "INV-2026-10", file = (PlainText (record{fileName =
|
|
45
|
+
name}))}})
|
|
46
|
+
end function
|
|
47
|
+
|
|
48
|
+
law "|emailPlainTextInvoice result| is
|
|
49
|
+
description:
|
|
50
|
+
"Plain-text invoices have no PDF file name."
|
|
51
|
+
end
|
|
52
|
+
definition:
|
|
53
|
+
"|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
|
|
54
|
+
Nothing
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
function downloadPdfInvoice (name of type Text) -> Delivery is
|
|
59
|
+
Download (record{document = record{number =
|
|
60
|
+
"INV-2026-10", file = (Pdf (record{fileName = name, byteCount =
|
|
61
|
+
1200}))}})
|
|
62
|
+
end function
|
|
63
|
+
|
|
64
|
+
law "|downloadPdfInvoice result| is
|
|
65
|
+
description:
|
|
66
|
+
"Downloads have no email invoice PDF file name."
|
|
67
|
+
end
|
|
68
|
+
definition:
|
|
69
|
+
"|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
|
|
70
|
+
Nothing
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
unit example.delivery.uur
|
|
2
|
+
|
|
3
|
+
type Document is one of
|
|
4
|
+
| Invoice of type record{number of type Text
|
|
5
|
+
file of type record{fileName of type Text
|
|
6
|
+
byteCount of type Whole}}
|
|
7
|
+
| Letter of type record{subject of type Text
|
|
8
|
+
file of type record{fileName of type Text
|
|
9
|
+
byteCount of type Whole}}
|
|
10
|
+
end type
|
|
11
|
+
|
|
12
|
+
type Delivery is one of
|
|
13
|
+
| Email of type record{recipient of type Text
|
|
14
|
+
document of type Document}
|
|
15
|
+
| Download of type record{document of type Document}
|
|
16
|
+
end type
|
|
17
|
+
|
|
18
|
+
function "|email invoice PDF file name|
|
|
19
|
+
(delivery of type Delivery) -> Maybe Text is
|
|
20
|
+
first matching case of delivery:
|
|
21
|
+
when Email record{document = Invoice record{file = record{fileName = name}}}
|
|
22
|
+
then Just name
|
|
23
|
+
otherwise Nothing
|
|
24
|
+
end case
|
|
25
|
+
end function
|
|
26
|
+
|
|
27
|
+
function emailPdfInvoice (name of type Text) -> Delivery is
|
|
28
|
+
Email (record{recipient = "accounts@example.com", document =
|
|
29
|
+
(Invoice (record{number = "INV-2026-10", file = record{fileName = name,
|
|
30
|
+
byteCount = 1200}}))})
|
|
31
|
+
end function
|
|
32
|
+
|
|
33
|
+
law "|emailPdfInvoice result| is
|
|
34
|
+
description:
|
|
35
|
+
"PDF invoices sent by email retain their file names."
|
|
36
|
+
end
|
|
37
|
+
definition:
|
|
38
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
39
|
+
"invoice.pdf"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
function emailPdfLetter (name of type Text) -> Delivery is
|
|
44
|
+
Email (record{recipient = "accounts@example.com", document =
|
|
45
|
+
(Letter (record{subject = "Receipt", file = record{fileName = name,
|
|
46
|
+
byteCount = 1200}}))})
|
|
47
|
+
end function
|
|
48
|
+
|
|
49
|
+
law "|emailPdfLetter result| is
|
|
50
|
+
description:
|
|
51
|
+
"Letters have no invoice PDF file name."
|
|
52
|
+
end
|
|
53
|
+
definition:
|
|
54
|
+
"|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
|
|
55
|
+
Nothing
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
function downloadPdfInvoice (name of type Text) -> Delivery is
|
|
60
|
+
Download (record{document = (Invoice (record{number = "INV-2026-10", file =
|
|
61
|
+
record{fileName = name,
|
|
62
|
+
byteCount = 1200}}))})
|
|
63
|
+
end function
|
|
64
|
+
|
|
65
|
+
law "|downloadPdfInvoice result| is
|
|
66
|
+
description:
|
|
67
|
+
"Downloads have no email invoice PDF file name."
|
|
68
|
+
end
|
|
69
|
+
definition:
|
|
70
|
+
"|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
|
|
71
|
+
Nothing
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
unit example.delivery.uuu
|
|
2
|
+
|
|
3
|
+
type File is one of
|
|
4
|
+
| Pdf of type record{fileName of type Text
|
|
5
|
+
byteCount of type Whole}
|
|
6
|
+
| PlainText of type record{fileName of type Text}
|
|
7
|
+
end type
|
|
8
|
+
|
|
9
|
+
type Document is one of
|
|
10
|
+
| Invoice of type record{number of type Text
|
|
11
|
+
file of type File}
|
|
12
|
+
| Letter of type record{subject of type Text
|
|
13
|
+
file of type File}
|
|
14
|
+
end type
|
|
15
|
+
|
|
16
|
+
type Delivery is one of
|
|
17
|
+
| Email of type record{recipient of type Text
|
|
18
|
+
document of type Document}
|
|
19
|
+
| Download of type record{document of type Document}
|
|
20
|
+
end type
|
|
21
|
+
|
|
22
|
+
function "|email invoice PDF file name|
|
|
23
|
+
(delivery of type Delivery) -> Maybe Text is
|
|
24
|
+
first matching case of delivery:
|
|
25
|
+
when Email record{document = Invoice record{file = Pdf record{fileName =
|
|
26
|
+
name}}}
|
|
27
|
+
then Just name
|
|
28
|
+
otherwise Nothing
|
|
29
|
+
end case
|
|
30
|
+
end function
|
|
31
|
+
|
|
32
|
+
function emailPdfInvoice (name of type Text) -> Delivery is
|
|
33
|
+
Email (record{recipient = "accounts@example.com", document =
|
|
34
|
+
(Invoice (record{number = "INV-2026-10", file = (Pdf
|
|
35
|
+
(record{fileName = name, byteCount = 1200}))}))})
|
|
36
|
+
end function
|
|
37
|
+
|
|
38
|
+
law "|emailPdfInvoice result| is
|
|
39
|
+
description:
|
|
40
|
+
"PDF invoices sent by email retain their file names."
|
|
41
|
+
end
|
|
42
|
+
definition:
|
|
43
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
44
|
+
"invoice.pdf"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
function emailPlainTextInvoice (name of type Text) -> Delivery is
|
|
49
|
+
Email (record{recipient = "accounts@example.com", document =
|
|
50
|
+
(Invoice (record{number = "INV-2026-10", file = (PlainText
|
|
51
|
+
(record{fileName = name}))}))})
|
|
52
|
+
end function
|
|
53
|
+
|
|
54
|
+
law "|emailPlainTextInvoice result| is
|
|
55
|
+
description:
|
|
56
|
+
"Plain-text invoices have no PDF file name."
|
|
57
|
+
end
|
|
58
|
+
definition:
|
|
59
|
+
"|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
|
|
60
|
+
Nothing
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
function emailPdfLetter (name of type Text) -> Delivery is
|
|
65
|
+
Email (record{recipient = "accounts@example.com", document =
|
|
66
|
+
(Letter (record{subject = "Receipt", file = (Pdf (record{fileName = name,
|
|
67
|
+
byteCount = 1200}))}))})
|
|
68
|
+
end function
|
|
69
|
+
|
|
70
|
+
law "|emailPdfLetter result| is
|
|
71
|
+
description:
|
|
72
|
+
"Letters have no invoice PDF file name."
|
|
73
|
+
end
|
|
74
|
+
definition:
|
|
75
|
+
"|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
|
|
76
|
+
Nothing
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
function downloadPdfInvoice (name of type Text) -> Delivery is
|
|
81
|
+
Download (record{document = (Invoice (record{number = "INV-2026-10", file =
|
|
82
|
+
(Pdf (record{fileName =
|
|
83
|
+
name,
|
|
84
|
+
byteCount = 1200}))}))})
|
|
85
|
+
end function
|
|
86
|
+
|
|
87
|
+
law "|downloadPdfInvoice result| is
|
|
88
|
+
description:
|
|
89
|
+
"Downloads have no email invoice PDF file name."
|
|
90
|
+
end
|
|
91
|
+
definition:
|
|
92
|
+
"|email invoice PDF file name| (downloadPdfInvoice "invoice.pdf") must be
|
|
93
|
+
Nothing
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
unit example.orders
|
|
2
|
+
|
|
3
|
+
type OrderState is one of
|
|
4
|
+
| Pending
|
|
5
|
+
| Authorized
|
|
6
|
+
| Shipped
|
|
7
|
+
| Cancelled
|
|
8
|
+
end type
|
|
9
|
+
|
|
10
|
+
type OrderAction is one of
|
|
11
|
+
| Authorize
|
|
12
|
+
| Dispatch
|
|
13
|
+
| Cancel
|
|
14
|
+
end type
|
|
15
|
+
|
|
16
|
+
function nextState (state of type OrderState)
|
|
17
|
+
(action of type OrderAction) -> OrderState is
|
|
18
|
+
first matching case of action:
|
|
19
|
+
when Authorize then
|
|
20
|
+
if state = Pending then Authorized else state end if
|
|
21
|
+
when Dispatch then
|
|
22
|
+
if state = Authorized then Shipped else state end if
|
|
23
|
+
when Cancel then
|
|
24
|
+
if state = Shipped then Shipped else Cancelled end if
|
|
25
|
+
end case
|
|
26
|
+
end function
|
|
27
|
+
|
|
28
|
+
ability OrderStore is
|
|
29
|
+
current of type OrderState
|
|
30
|
+
change of type OrderState -> ()
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
handler inMemory for OrderStore with state order of type OrderState
|
|
34
|
+
start Pending is
|
|
35
|
+
current is order end
|
|
36
|
+
change updated is ~order := updated; () end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
procedure perform (action of type OrderAction) -> OrderState uses OrderStore is
|
|
40
|
+
let updated = nextState current action in
|
|
41
|
+
change updated; current
|
|
42
|
+
end procedure
|
|
43
|
+
|
|
44
|
+
procedure process (actions of type List OrderAction) -> OrderState
|
|
45
|
+
uses OrderStore is
|
|
46
|
+
first matching case of actions:
|
|
47
|
+
when Nil then current
|
|
48
|
+
when Cons action remaining then
|
|
49
|
+
perform action; process remaining
|
|
50
|
+
end case
|
|
51
|
+
end procedure
|
|
52
|
+
|
|
53
|
+
function runOrder (actions of type List OrderAction) -> OrderState is
|
|
54
|
+
handle process actions with inMemory end
|
|
55
|
+
end function
|
|
56
|
+
|
|
57
|
+
function modelRun (state of type OrderState)
|
|
58
|
+
(actions of type List OrderAction) -> OrderState is
|
|
59
|
+
first matching case of actions:
|
|
60
|
+
when Nil then state
|
|
61
|
+
when Cons action remaining then
|
|
62
|
+
modelRun (nextState state action) remaining
|
|
63
|
+
end case
|
|
64
|
+
end function
|
|
65
|
+
|
|
66
|
+
law "|order transitions follow the business lifecycle| is
|
|
67
|
+
definition:
|
|
68
|
+
for all (state of type OrderState) (action of type OrderAction) =>
|
|
69
|
+
(state = Shipped implies nextState state action must be Shipped)
|
|
70
|
+
and (state = Cancelled implies nextState state action must be Cancelled)
|
|
71
|
+
and (state = Pending and action = Authorize implies
|
|
72
|
+
nextState state action must be Authorized)
|
|
73
|
+
and (state = Pending and action = Dispatch implies
|
|
74
|
+
nextState state action must be Pending)
|
|
75
|
+
and (state = Authorized and action = Authorize implies
|
|
76
|
+
nextState state action must be Authorized)
|
|
77
|
+
and (state = Authorized and action = Dispatch implies
|
|
78
|
+
nextState state action must be Shipped)
|
|
79
|
+
and ((state = Pending or state = Authorized) and action = Cancel implies
|
|
80
|
+
nextState state action must be Cancelled)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
expect nextState state action = expected
|
|
84
|
+
in table (state, action, expected):
|
|
85
|
+
row Pending, Authorize, Authorized
|
|
86
|
+
row Pending, Dispatch, Pending
|
|
87
|
+
row Pending, Cancel, Cancelled
|
|
88
|
+
row Authorized, Authorize, Authorized
|
|
89
|
+
row Authorized, Dispatch, Shipped
|
|
90
|
+
row Authorized, Cancel, Cancelled
|
|
91
|
+
row Shipped, Authorize, Shipped
|
|
92
|
+
row Shipped, Dispatch, Shipped
|
|
93
|
+
row Shipped, Cancel, Shipped
|
|
94
|
+
row Cancelled, Authorize, Cancelled
|
|
95
|
+
row Cancelled, Dispatch, Cancelled
|
|
96
|
+
row Cancelled, Cancel, Cancelled
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
law "|processing retains each completed transition| is
|
|
101
|
+
description:
|
|
102
|
+
"Every action observes the state left by the previous action."
|
|
103
|
+
end
|
|
104
|
+
definition:
|
|
105
|
+
for all (actions of type List OrderAction) =>
|
|
106
|
+
runOrder actions must be modelRun Pending actions
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
expect runOrder actions = expected
|
|
110
|
+
in table (actions, expected):
|
|
111
|
+
row [], Pending
|
|
112
|
+
row [Dispatch], Pending
|
|
113
|
+
row [Authorize], Authorized
|
|
114
|
+
row [Authorize, Dispatch], Shipped
|
|
115
|
+
row [Cancel, Authorize, Dispatch], Cancelled
|
|
116
|
+
row [Authorize, Cancel, Dispatch], Cancelled
|
|
117
|
+
row [Authorize, Dispatch, Cancel], Shipped
|
|
118
|
+
row [Authorize, Dispatch, Authorize], Shipped
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
law "|independent orders start pending| is
|
|
123
|
+
definition:
|
|
124
|
+
runOrder [Authorize] must be Authorized and runOrder [] must be Pending
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
unit example.refinedPayloads
|
|
2
|
+
|
|
3
|
+
type Measurement (a of type Type) is a record{
|
|
4
|
+
reading of type record{value of type a}
|
|
5
|
+
}
|
|
6
|
+
end type
|
|
7
|
+
|
|
8
|
+
type Parcel is a record{
|
|
9
|
+
details of type record{
|
|
10
|
+
weight of type (measurement of type Measurement Integer
|
|
11
|
+
where measurement.reading.value > 0)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
end type
|
|
15
|
+
|
|
16
|
+
type DeliveryLabel is a record{
|
|
17
|
+
code of type UInt8
|
|
18
|
+
recipient of type Text
|
|
19
|
+
}
|
|
20
|
+
end type
|
|
21
|
+
|
|
22
|
+
type Delivery (a of type Type) is a record{
|
|
23
|
+
contents of type record{value of type a}
|
|
24
|
+
}
|
|
25
|
+
end type
|
|
26
|
+
|
|
27
|
+
function sampleParcel (unused of type ()) -> Parcel is
|
|
28
|
+
Parcel record{details = record{
|
|
29
|
+
weight = Measurement record{reading = record{value = 1}}
|
|
30
|
+
}}
|
|
31
|
+
end function
|
|
32
|
+
|
|
33
|
+
function weightOf (parcel of type record{
|
|
34
|
+
weight of type (measurement of type Measurement Integer
|
|
35
|
+
where measurement.reading.value > 0)
|
|
36
|
+
}) -> Integer is
|
|
37
|
+
parcel.weight.reading.value
|
|
38
|
+
end function
|
|
39
|
+
|
|
40
|
+
function recipient (delivery of type Delivery DeliveryLabel) -> Text is
|
|
41
|
+
delivery.contents.value.recipient
|
|
42
|
+
end function
|
|
43
|
+
|
|
44
|
+
law sampleWeight is
|
|
45
|
+
description:
|
|
46
|
+
"A sample parcel weighs one gram."
|
|
47
|
+
end
|
|
48
|
+
definition:
|
|
49
|
+
sampleParcel () must be Parcel record{details = record{
|
|
50
|
+
weight = Measurement record{reading = record{value = 1}}
|
|
51
|
+
}}
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
law positiveWeights is
|
|
56
|
+
description:
|
|
57
|
+
"Every accepted parcel measurement has a positive weight."
|
|
58
|
+
end
|
|
59
|
+
definition:
|
|
60
|
+
for all (parcel of type record{
|
|
61
|
+
weight of type (measurement of type Measurement Integer
|
|
62
|
+
where measurement.reading.value > 0)
|
|
63
|
+
}) =>
|
|
64
|
+
weightOf parcel > 0
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
expect weightOf parcel = expected
|
|
68
|
+
in table (parcel, expected):
|
|
69
|
+
row record{weight = Measurement record{reading = record{value = 1}}}, 1
|
|
70
|
+
row record{weight = Measurement record{reading = record{value = 3}}}, 3
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
law recipientLabels is
|
|
75
|
+
description:
|
|
76
|
+
"Deliveries preserve the recipient written on their label."
|
|
77
|
+
end
|
|
78
|
+
definition:
|
|
79
|
+
for all (delivery of type Delivery DeliveryLabel) =>
|
|
80
|
+
recipient delivery = recipient delivery
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
expect recipient delivery = expected
|
|
84
|
+
in table (delivery, expected):
|
|
85
|
+
row Delivery record{contents = record{value = DeliveryLabel record{
|
|
86
|
+
recipient = "Asha", code = 7
|
|
87
|
+
}}}, "Asha"
|
|
88
|
+
row Delivery record{contents = record{value = DeliveryLabel record{
|
|
89
|
+
code = 8, recipient = "Bo"
|
|
90
|
+
}}}, "Bo"
|
|
91
|
+
end
|
|
92
|
+
end
|