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.
Files changed (98) hide show
  1. package/CHANGELOG.md +167 -1
  2. package/README.md +29 -22
  3. package/UNICODE-LICENSE.txt +39 -0
  4. package/api.mjs +14 -23
  5. package/bin/lawspec.mjs +200 -67
  6. package/build.json +381 -155
  7. package/builtin-data-names.mjs +73 -0
  8. package/compatibility.json +21 -0
  9. package/core.wasm +2 -2
  10. package/doctor.mjs +98 -1
  11. package/examples/native-payments/clojure/lawspec.json +62 -0
  12. package/examples/native-payments/clojure/src/domain/payments.clj +11 -0
  13. package/examples/native-payments/clojure/test/domain/payment_generators.clj +9 -0
  14. package/examples/native-payments/csharp/lawspec.json +13 -2
  15. package/examples/native-payments/elixir/lawspec.json +14 -3
  16. package/examples/native-payments/erlang/lawspec.json +14 -3
  17. package/examples/native-payments/fsharp/lawspec.json +14 -3
  18. package/examples/native-payments/gleam/lawspec.json +14 -3
  19. package/examples/native-payments/go/lawspec.json +14 -3
  20. package/examples/native-payments/groovy/lawspec.json +176 -0
  21. package/examples/native-payments/groovy/src/main/groovy/domain/PaymentsDomain.groovy +49 -0
  22. package/examples/native-payments/groovy/src/test/groovy/domain/PaymentGenerators.groovy +15 -0
  23. package/examples/native-payments/haskell/lawspec.json +14 -3
  24. package/examples/native-payments/java/lawspec.json +14 -3
  25. package/examples/native-payments/javascript/lawspec.json +14 -3
  26. package/examples/native-payments/kotlin/lawspec.json +14 -3
  27. package/examples/native-payments/python/lawspec.json +14 -3
  28. package/examples/native-payments/rust/lawspec.json +14 -3
  29. package/examples/native-payments/scala/lawspec.json +176 -0
  30. package/examples/native-payments/scala/src/main/scala/domain/PaymentsDomain.scala +18 -0
  31. package/examples/native-payments/scala/src/test/scala/domain/PaymentGenerators.scala +8 -0
  32. package/examples/native-payments/swift/lawspec.json +165 -0
  33. package/examples/native-payments/swift/src/Native/PaymentsDomain.swift +35 -0
  34. package/examples/native-payments/swift/tests/Native/PaymentGenerators.swift +12 -0
  35. package/examples/native-payments/typescript/lawspec.json +14 -3
  36. package/examples/packages/orders/lawspec.json +25 -5
  37. package/examples/packages/orders/orders.lawspec +36 -34
  38. package/examples/packages/shop-domain/src/domain.lawspec +23 -21
  39. package/examples/packages/shop-tax-1/src/rates.lawspec +4 -4
  40. package/examples/packages/shop-tax-2/src/rates.lawspec +5 -4
  41. package/examples/rc1/authorization-snapshots.lawspec +112 -0
  42. package/examples/rc1/banner-filenames.lawspec +63 -0
  43. package/examples/rc1/bit-codec.lawspec +56 -0
  44. package/examples/rc1/bounded-witness-search.lawspec +144 -0
  45. package/examples/rc1/conflicting-requirements.lawspec +30 -0
  46. package/examples/rc1/constructive-witnesses.lawspec +113 -0
  47. package/examples/rc1/documentary-review.lawspec +42 -0
  48. package/examples/rc1/empty-domains.lawspec +46 -0
  49. package/examples/rc1/finite-integer-domains.lawspec +75 -0
  50. package/examples/rc1/law-metadata.lawspec +29 -0
  51. package/examples/rc1/native-payments.lawspec +107 -0
  52. package/examples/rc1/nesting/rrr.lawspec +33 -0
  53. package/examples/rc1/nesting/rru.lawspec +56 -0
  54. package/examples/rc1/nesting/rur.lawspec +57 -0
  55. package/examples/rc1/nesting/ruu.lawspec +77 -0
  56. package/examples/rc1/nesting/urr.lawspec +52 -0
  57. package/examples/rc1/nesting/uru.lawspec +72 -0
  58. package/examples/rc1/nesting/uur.lawspec +73 -0
  59. package/examples/rc1/nesting/uuu.lawspec +95 -0
  60. package/examples/rc1/order-workflow.lawspec +126 -0
  61. package/examples/rc1/parcel-measurements.lawspec +92 -0
  62. package/examples/rc1/picture-records.lawspec +51 -0
  63. package/examples/rc1/picture-tuples.lawspec +47 -0
  64. package/examples/rc1/record-payloads.lawspec +56 -0
  65. package/examples/rc1/recursive-records.lawspec +64 -0
  66. package/examples/rc1/refund-conformance.lawspec +44 -0
  67. package/examples/rc1/refund-policy.lawspec +88 -0
  68. package/examples/rc1/requirement-composition.lawspec +89 -0
  69. package/examples/rc1/structural-records.lawspec +53 -0
  70. package/examples/rc1-authoring.lawspec +56 -0
  71. package/examples-command.mjs +11 -5
  72. package/explain.mjs +112 -0
  73. package/expression-presentation.mjs +333 -0
  74. package/files.mjs +16 -0
  75. package/index.d.ts +934 -12
  76. package/lsp.mjs +231 -0
  77. package/migrate.mjs +135 -0
  78. package/migration-bindings.mjs +86 -0
  79. package/migration-cases.mjs +45 -0
  80. package/migration-collections.mjs +54 -0
  81. package/migration-correspondence.mjs +275 -0
  82. package/migration-generation.mjs +99 -0
  83. package/migration-laws.mjs +102 -0
  84. package/migration-records.mjs +166 -0
  85. package/migration-source.mjs +247 -0
  86. package/migration-write.mjs +156 -0
  87. package/native-evidence.mjs +187 -0
  88. package/native-examples.mjs +8 -1
  89. package/node-events-reporter.mjs +23 -0
  90. package/package.json +8 -1
  91. package/positional-fields.mjs +13 -0
  92. package/proof.d.ts +35 -0
  93. package/proof.mjs +174 -0
  94. package/scala-coverage.mjs +56 -0
  95. package/starter-rc1.lawspec +25 -0
  96. package/templates.mjs +65 -3
  97. package/test-command.mjs +177 -29
  98. package/typed-presentation.mjs +165 -0
@@ -0,0 +1,51 @@
1
+ unit pictures.records
2
+
3
+ type Orientation is one of
4
+ | Landscape
5
+ | Portrait
6
+ | Square
7
+ end type
8
+
9
+ type Picture is a record{
10
+ fileName of type Text
11
+ dimensions of type record{
12
+ width of type Nat
13
+ height of type Nat
14
+ }
15
+ }
16
+ end type
17
+
18
+ function orientation
19
+ (record{dimensions = record{width = width, height = height}} of type Picture)
20
+ -> Orientation is
21
+ first matching case of width:
22
+ when it > height then Landscape
23
+ when it < height then Portrait
24
+ otherwise Square
25
+ end case
26
+ end function
27
+
28
+ law "|named dimensions determine orientation| is
29
+ description:
30
+ "Dimension labels preserve their meaning in either field order."
31
+ end
32
+ definition:
33
+ for all (picture of type Picture) =>
34
+ orientation picture must be
35
+ if picture.dimensions.width > picture.dimensions.height then Landscape
36
+ else if picture.dimensions.width < picture.dimensions.height then Portrait
37
+ else Square
38
+ end if
39
+ end if
40
+ end
41
+ end
42
+ expect orientation picture = expected
43
+ in table (picture, expected):
44
+ row Picture record{fileName = "wide.jpg", dimensions = record{width = 12,
45
+ height = 8}}, Landscape
46
+ row Picture record{fileName = "tall.jpg", dimensions = record{height = 12,
47
+ width = 8}}, Portrait
48
+ row Picture record{fileName = "square.jpg", dimensions = record{width = 10,
49
+ height = 10}}, Square
50
+ end
51
+ end
@@ -0,0 +1,47 @@
1
+ unit pictures.tuples
2
+
3
+ type Orientation is one of
4
+ | Landscape
5
+ | Portrait
6
+ | Square
7
+ end type
8
+
9
+ type Picture is a record{
10
+ fileName of type Text
11
+ dimensions of type (Nat, Nat)
12
+ }
13
+ end type
14
+
15
+ function orientation
16
+ (record{dimensions = (width, height)} of type Picture) -> Orientation is
17
+ first matching case of width:
18
+ when it > height then Landscape
19
+ when it < height then Portrait
20
+ otherwise Square
21
+ end case
22
+ end function
23
+
24
+ law "|tuple dimensions determine orientation| is
25
+ description:
26
+ "Width comes first and height second in a picture's dimensions."
27
+ end
28
+ definition:
29
+ for all (picture of type Picture) =>
30
+ orientation picture must be
31
+ first matching case of picture.dimensions:
32
+ when (width, height) then
33
+ if width > height then Landscape
34
+ else if width < height then Portrait
35
+ else Square
36
+ end if
37
+ end if
38
+ end case
39
+ end
40
+ end
41
+ expect orientation picture = expected
42
+ in table (picture, expected):
43
+ row Picture record{fileName = "wide.jpg", dimensions = (12, 8)}, Landscape
44
+ row Picture record{fileName = "tall.jpg", dimensions = (8, 12)}, Portrait
45
+ row Picture record{fileName = "square.jpg", dimensions = (10, 10)}, Square
46
+ end
47
+ end
@@ -0,0 +1,56 @@
1
+ unit example.payloads
2
+ type Picture is a record{
3
+ fileName of type Text
4
+ dimensions of type record{width of type Nat height of type Nat}
5
+ } end type
6
+ type Delivery is one of
7
+ | Download of type record{document of type Text}
8
+ | Unavailable
9
+ end type
10
+ type Envelope (a of type Type) is a record{payload of type record{value of type
11
+ a copy of type a}} end type
12
+ type Box (a of type Type) is one of | Box of type record{value of type a}
13
+ end type
14
+ function width (picture of type Picture) -> Nat is picture.dimensions.width
15
+ end function
16
+ function label (delivery of type Delivery) -> Text is
17
+ first matching case of delivery:
18
+ when Download record{document = name} then name
19
+ when Unavailable then "unavailable"
20
+ end case
21
+ end function
22
+ function extract (envelope of type Envelope a) -> a is envelope.payload.value
23
+ end function
24
+ function unpack (envelope of type Envelope a) -> record{value of type a copy
25
+ of type a} is envelope.payload end function
26
+ function boxedPayload (box of type Box a) -> record{value of type a} is
27
+ first matching case of box: when Box value then value end case end function
28
+ law pictureWidth is definition:
29
+ width (Picture record{fileName = "photo", dimensions = record{height = 3,
30
+ width = 2}}) must be 2
31
+ end end
32
+ law downloadLabel is definition: label (Download record{document = "paper"})
33
+ must be "paper" end end
34
+ law wrappedText is definition: extract (Envelope record{payload = record{value =
35
+ "note", copy = "other"}}) must be "note" end end
36
+ law wrappedBoolean is definition: extract (Envelope record{payload =
37
+ record{value = true, copy = false}}) must be true end end
38
+ law wholeRecord is definition: unpack (Envelope record{payload = record{value =
39
+ true, copy = false}}) = record{copy = false, value = true} end end
40
+ law boxedResult is definition: boxedPayload (Box record{value = true}) =
41
+ record{value = true} end end
42
+ law boxedRows is definition: for all (box of type Box Text) => boxedPayload box
43
+ = boxedPayload box end end
44
+ expect (boxedPayload box).value = expected in table (box, expected):
45
+ row Box record{value = "note"}, "note"
46
+ row Box record{value = "paper"}, "paper"
47
+ end end
48
+ law labels is
49
+ definition: for all (delivery of type Delivery) => label delivery = label
50
+ delivery end end
51
+ expect label delivery = expected
52
+ in table (delivery, expected):
53
+ row Download record{document = "paper"}, "paper"
54
+ row Unavailable, "unavailable"
55
+ end
56
+ end
@@ -0,0 +1,64 @@
1
+ unit example.rc1.recursiveRecords
2
+
3
+ type UnissuedApproval is one of
4
+ | Unissued of type UnissuedApproval
5
+ end type
6
+
7
+ type Box (item of type Type) is a record{
8
+ contents of type item
9
+ }
10
+ end type
11
+
12
+ type FirstSnapshot is a record{
13
+ next of type Box SecondSnapshot
14
+ }
15
+ end type
16
+
17
+ type SecondSnapshot is a record{
18
+ previous of type FirstSnapshot
19
+ }
20
+ end type
21
+
22
+ type ApprovalChain is a record{
23
+ next of type Maybe ApprovalChain
24
+ }
25
+ end type
26
+
27
+ function chainLength (chain of type ApprovalChain) -> Whole is
28
+ first matching case of chain:
29
+ when record{next = Nothing} then 0
30
+ when record{next = Just rest} then 1 + chainLength rest
31
+ end case
32
+ end function
33
+
34
+ law "|an unissued approval has no finite construction| is
35
+ definition:
36
+ for all (approval of type UnissuedApproval) =>
37
+ false
38
+ end
39
+ end
40
+ end
41
+
42
+ law "|mutually dependent snapshots have no first value| is
43
+ definition:
44
+ for all (snapshot of type FirstSnapshot) =>
45
+ false
46
+ end
47
+ end
48
+ end
49
+
50
+ law "|a completed chain has no remaining approval| is
51
+ definition:
52
+ chainLength (ApprovalChain record{next = Nothing}) must be 0
53
+ end
54
+ end
55
+
56
+ law "|a pending chain counts each remaining approval| is
57
+ definition:
58
+ chainLength (ApprovalChain record{
59
+ next = Just (ApprovalChain record{
60
+ next = Just (ApprovalChain record{next = Nothing})
61
+ })
62
+ }) must be 2
63
+ end
64
+ end
@@ -0,0 +1,44 @@
1
+ unit example.refundConformance
2
+
3
+ import example.refunds as policy
4
+
5
+ nativeRefund of type policy.RefundRequest -> policy.RefundDecision
6
+
7
+ law "|native refunds conform to the policy| is
8
+ description:
9
+ "The application's refund decision agrees with the checked policy."
10
+ end
11
+ definition:
12
+ for all (request of type policy.RefundRequest) =>
13
+ nativeRefund request must be policy.refund request
14
+ end
15
+ end
16
+
17
+ references:
18
+ ref function policy.refund
19
+ end
20
+
21
+ expect nativeRefund request = expected
22
+ in table (request, expected):
23
+ row policy.RefundRequest record{capturedAmount = 0, requestedAmount = 0,
24
+ flagged = false}, policy.Approved
25
+ row policy.RefundRequest record{capturedAmount = 0, requestedAmount = 0,
26
+ flagged = true}, policy.Approved
27
+ row policy.RefundRequest record{capturedAmount = 100, requestedAmount = 0,
28
+ flagged = true}, policy.Approved
29
+ row policy.RefundRequest record{capturedAmount = 0, requestedAmount = 1,
30
+ flagged = false}, policy.Rejected
31
+ row policy.RefundRequest record{capturedAmount = 100, requestedAmount = 101,
32
+ flagged = true}, policy.Rejected
33
+ row policy.RefundRequest record{capturedAmount = 100, requestedAmount = 100,
34
+ flagged = true}, policy.ReviewRequired
35
+ row policy.RefundRequest record{capturedAmount = 100, requestedAmount = 1,
36
+ flagged = true}, policy.ReviewRequired
37
+ row policy.RefundRequest record{capturedAmount = 100, requestedAmount = 100,
38
+ flagged = false}, policy.Approved
39
+ row policy.RefundRequest record{capturedAmount = 100, requestedAmount = 99,
40
+ flagged = false}, policy.Approved
41
+ row policy.RefundRequest record{capturedAmount = 9007199254740992,
42
+ requestedAmount = 9007199254740993, flagged = false}, policy.Rejected
43
+ end
44
+ end
@@ -0,0 +1,88 @@
1
+ unit example.refunds
2
+
3
+ type RefundDecision is one of
4
+ | Approved
5
+ | ReviewRequired
6
+ | Rejected
7
+ end type
8
+
9
+ type RefundRequest is a record{
10
+ capturedAmount of type Whole
11
+ requestedAmount of type Whole
12
+ flagged of type Bool
13
+ }
14
+ end type
15
+
16
+ function refund (request of type RefundRequest) -> RefundDecision is
17
+ first matching case of request:
18
+ when record{requestedAmount = 0} then Approved
19
+ when it.requestedAmount > it.capturedAmount then Rejected
20
+ when it.flagged then ReviewRequired
21
+ otherwise Approved
22
+ end case
23
+ end function
24
+
25
+ law "|a zero refund is approved| is
26
+ description:
27
+ "A zero request transfers nothing and needs no review."
28
+ end
29
+ definition:
30
+ for all (capturedAmount of type Whole) (flagged of type Bool) =>
31
+ refund (RefundRequest record{
32
+ capturedAmount = capturedAmount, requestedAmount = 0, flagged = flagged
33
+ }) must be Approved
34
+ end
35
+ end
36
+ end
37
+
38
+ law "|a refund cannot exceed the captured amount| is
39
+ definition:
40
+ for all (request of type RefundRequest) =>
41
+ request.requestedAmount > request.capturedAmount implies
42
+ refund request must be Rejected
43
+ end
44
+ end
45
+ end
46
+
47
+ law "|an eligible flagged refund requires review| is
48
+ definition:
49
+ for all (request of type RefundRequest) =>
50
+ request.requestedAmount > 0 and
51
+ request.requestedAmount <= request.capturedAmount and request.flagged
52
+ implies refund request must be ReviewRequired
53
+ end
54
+ end
55
+ end
56
+
57
+ law "|an eligible unflagged refund is approved| is
58
+ definition:
59
+ for all (request of type RefundRequest) =>
60
+ request.requestedAmount <= request.capturedAmount and not request.flagged
61
+ implies refund request must be Approved
62
+ end
63
+ end
64
+
65
+ expect refund request = expected
66
+ in table (request, expected):
67
+ row RefundRequest record{capturedAmount = 0, requestedAmount = 0, flagged =
68
+ false}, Approved
69
+ row RefundRequest record{capturedAmount = 0, requestedAmount = 0, flagged =
70
+ true}, Approved
71
+ row RefundRequest record{capturedAmount = 100, requestedAmount = 0, flagged
72
+ = true}, Approved
73
+ row RefundRequest record{capturedAmount = 0, requestedAmount = 1, flagged =
74
+ false}, Rejected
75
+ row RefundRequest record{capturedAmount = 100, requestedAmount = 101,
76
+ flagged = true}, Rejected
77
+ row RefundRequest record{capturedAmount = 100, requestedAmount = 100,
78
+ flagged = true}, ReviewRequired
79
+ row RefundRequest record{capturedAmount = 100, requestedAmount = 1, flagged
80
+ = true}, ReviewRequired
81
+ row RefundRequest record{capturedAmount = 100, requestedAmount = 100,
82
+ flagged = false}, Approved
83
+ row RefundRequest record{capturedAmount = 100, requestedAmount = 99, flagged
84
+ = false}, Approved
85
+ row RefundRequest record{capturedAmount = 9007199254740992, requestedAmount
86
+ = 9007199254740993, flagged = false}, Rejected
87
+ end
88
+ end
@@ -0,0 +1,89 @@
1
+ unit example.rc1.requirementComposition
2
+
3
+ import example.rc1.authorizationSnapshots as snapshot
4
+ (Payment, Authorization, AuthorizationState, active, authorizes)
5
+
6
+ law "|each item has a match| (relation of type a -> b -> Bool) is
7
+ definition:
8
+ for all (item of type b) =>
9
+ there exists (witness of type a) such that
10
+ relation witness item
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ function revokedMatch (authorization of type Authorization)
17
+ (payment of type Payment) -> Bool is
18
+ active AllRevoked authorization and authorizes authorization payment
19
+ end function
20
+
21
+ law "|matching and readiness agree| is
22
+ definition:
23
+ (apply law "|each item has a match| authorizes)
24
+ and
25
+ (for all (payment of type Payment) =>
26
+ there exists (authorization of type Authorization
27
+ where active Ready authorization) such that
28
+ authorizes authorization payment
29
+ end
30
+ end)
31
+ end
32
+
33
+ description:
34
+ "Every payment has a matching identity and an active approval when ready."
35
+ end
36
+ end
37
+
38
+ law "|revocation or matching has a complete explanation| is
39
+ definition:
40
+ (must not apply law "|each item has a match| revokedMatch)
41
+ or apply law "|each item has a match| authorizes
42
+ end
43
+
44
+ description:
45
+ "Either revoked approvals cannot cover every payment, or matching succeeds."
46
+ end
47
+ end
48
+
49
+ law "|matching implies ready approval coverage| is
50
+ definition:
51
+ (apply law "|each item has a match| authorizes)
52
+ implies
53
+ (for all (payment of type Payment) =>
54
+ there exists (authorization of type Authorization
55
+ where active Ready authorization) such that
56
+ authorizes authorization payment
57
+ end
58
+ end)
59
+ end
60
+ end
61
+
62
+ law "|payment and approval identities have separate scopes| is
63
+ definition:
64
+ (for all (value of type Payment) =>
65
+ value = FirstPayment or value = SecondPayment
66
+ end)
67
+ and
68
+ (for all (value of type Authorization) =>
69
+ value = FirstApproval or value = SecondApproval
70
+ end)
71
+ end
72
+ end
73
+
74
+ law "|an empty condition does not hide required coverage| is
75
+ definition:
76
+ (for all (authorization of type Authorization where false) =>
77
+ false
78
+ end)
79
+ and
80
+ (there exists (authorization of type Authorization
81
+ where active Ready authorization) such that
82
+ authorizes authorization FirstPayment
83
+ end)
84
+ end
85
+
86
+ rationale:
87
+ "A vacuous first clause leaves the approval requirement in force."
88
+ end
89
+ end
@@ -0,0 +1,53 @@
1
+ unit example.records
2
+
3
+ function double
4
+ (value of type record{
5
+ count of type Integer
6
+ }) -> record{
7
+ count of type Integer
8
+ } is
9
+ record{count = value.count + value.count}
10
+ end function
11
+
12
+ function wrap (value of type a) -> record{wrapped of type a} is
13
+ record{wrapped = value}
14
+ end function
15
+
16
+ law doubles is
17
+ definition:
18
+ for all (value of type record{count of type Integer}) =>
19
+ (double value).count must be value.count + value.count
20
+ end
21
+ end
22
+
23
+ expect double value = expected
24
+ in table (value, expected):
25
+ row record{count = -1}, record{count = -2}
26
+ row record{count = 0}, record{count = 0}
27
+ row record{count = 1}, record{count = 2}
28
+ end
29
+ end
30
+
31
+ law wraps is
32
+ definition:
33
+ (wrap true).wrapped must be true
34
+ end
35
+ end
36
+
37
+ law ordered is
38
+ definition:
39
+ record{a = 1, b = true} must be record{b = true, a = 1}
40
+ end
41
+ end
42
+
43
+ law nested is
44
+ definition:
45
+ record{inner = record{count = 4}}.inner.count must be 4
46
+ end
47
+ end
48
+
49
+ law empty is
50
+ definition:
51
+ record{} must be record{}
52
+ end
53
+ end
@@ -0,0 +1,56 @@
1
+ unit example.rc1
2
+
3
+ function "|adds the values| (a of type Integer) (b of type Integer) -> Integer is
4
+ a + b
5
+ end function
6
+
7
+ law "|addition preserves the inputs| is
8
+ description:
9
+ "Adding two amounts gives their mathematical sum."
10
+ end
11
+
12
+ definition:
13
+ for all (a of type Integer) (b of type Integer) =>
14
+ a `|adds the values| b must be a + b
15
+ end
16
+ end
17
+
18
+ expect "|adds the values| a b = expected
19
+ in table (a, b, expected):
20
+ row -1, 1, 0
21
+ row 0, 0, 0
22
+ row 1, 2, 3
23
+ end
24
+ end
25
+
26
+ type Picture is a record{
27
+ fileName of type Text
28
+ width of type Nat
29
+ }
30
+ end type
31
+
32
+ function picture (width of type Nat) -> Picture is
33
+ Picture record{fileName = "photo.jpg", width = width}
34
+ end function
35
+
36
+ function pictureWidth (picture of type Picture) -> Nat is
37
+ picture.width
38
+ end function
39
+
40
+ type Direction is one of
41
+ | North
42
+ | South
43
+ end type
44
+
45
+ mapping directionText of type Direction -> Text is
46
+ row North, "north"
47
+ row South, "south"
48
+ end mapping
49
+
50
+ function "|picture category| (width of type Nat) -> Text is
51
+ first matching case of width:
52
+ when it < 100 then "small"
53
+ when it < 1000 then "medium"
54
+ otherwise "large"
55
+ end case
56
+ end function
@@ -14,6 +14,9 @@ export async function generateExamples(options) {
14
14
  if (options.example !== "payments") throw new Error(`Unknown example: ${options.example}`);
15
15
  return exportNativePayments(options, selected);
16
16
  }
17
+ const projectRoot = process.cwd();
18
+ const outputDirectory = options.output || "example_artifacts";
19
+ const root = await safePath(projectRoot, outputDirectory);
17
20
  const directory = new URL("./examples/specs/", import.meta.url);
18
21
  const sources = await Promise.all(
19
22
  (await readdir(directory))
@@ -27,7 +30,11 @@ export async function generateExamples(options) {
27
30
  const compiler = await createCompiler();
28
31
  const artifacts = [];
29
32
  for (const target of selected) {
30
- const result = await compiler.planGeneration({
33
+ // The bundled specs catalog is the frozen 0.24 migration corpus.
34
+ // Canonical native projects are exported by exportNativePayments above.
35
+ const result = await compiler.migrationBaseline({
36
+ schemaVersion: 5, from: '0.24', includeGeneration: true,
37
+ languageProfile: '1.0-rc.1', verification: {layers: ['proof','exhaustive','property','examples','runtime','model']},
31
38
  sources,
32
39
  target,
33
40
  machineBits: options.machineBits ?? 64,
@@ -39,10 +46,8 @@ export async function generateExamples(options) {
39
46
  });
40
47
  artifacts.push(result.files);
41
48
  }
42
- const root = await safePath(
43
- process.cwd(),
44
- options.output || "example_artifacts",
45
- );
49
+ // Recheck the destination after compilation, before creating output files.
50
+ await safePath(projectRoot, outputDirectory);
46
51
  await mkdir(root, { recursive: true });
47
52
  const plans = [];
48
53
  for (let i = 0; i < selected.length; i++) {
@@ -53,6 +58,7 @@ export async function generateExamples(options) {
53
58
  await applyWrites(plans);
54
59
  return plans.map((plan, i) => ({
55
60
  target: selected[i],
61
+ sourceLanguageProfile: '0.24',
56
62
  directory: plan.root,
57
63
  files: artifacts[i].map((f) => ({ path: f.path, ownership: f.ownership, placement: f.placement })),
58
64
  changes: plan.changes.length,