lawspec 0.26.0 → 0.28.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 (55) hide show
  1. package/CHANGELOG.md +178 -1
  2. package/NORMALIZATION-LICENSES.txt +296 -0
  3. package/README.md +8 -0
  4. package/bin/lawspec.mjs +126 -33
  5. package/build.json +159 -131
  6. package/builtin-data-names.mjs +4 -4
  7. package/core.wasm +2 -2
  8. package/core_jsffi.js +5 -5
  9. package/doctor.mjs +14 -4
  10. package/examples/native-payments/elixir/lib/payments_domain.ex +1 -1
  11. package/examples/native-payments/erlang/src/payments_domain.erl +1 -1
  12. package/examples/native-payments/prolog/lawspec.json +20 -0
  13. package/examples/native-payments/prolog/src/domain/payments.pl +23 -0
  14. package/examples/native-payments/prolog/tests/domain/payment_generators.pl +17 -0
  15. package/examples/rc1/bit-codec.lawspec +6 -6
  16. package/examples/rc1/native-payments.lawspec +6 -6
  17. package/examples/rc1/nesting/rrr.lawspec +2 -2
  18. package/examples/rc1/nesting/rru.lawspec +4 -4
  19. package/examples/rc1/nesting/rur.lawspec +4 -4
  20. package/examples/rc1/nesting/ruu.lawspec +5 -5
  21. package/examples/rc1/nesting/urr.lawspec +4 -4
  22. package/examples/rc1/nesting/uru.lawspec +5 -5
  23. package/examples/rc1/nesting/uur.lawspec +5 -5
  24. package/examples/rc1/nesting/uuu.lawspec +6 -6
  25. package/examples/rc1/recursive-records.lawspec +5 -5
  26. package/examples/rc1/refund-policy.lawspec +4 -0
  27. package/examples/specs/approvals.lawspec +3 -3
  28. package/examples/specs/builtins.lawspec +2 -2
  29. package/examples/specs/collections.lawspec +8 -8
  30. package/examples/specs/composition.lawspec +10 -10
  31. package/examples/specs/contracts.lawspec +2 -2
  32. package/examples/specs/crypto.lawspec +2 -2
  33. package/examples/specs/domain_modeling.lawspec +20 -0
  34. package/examples/specs/flow_stack.lawspec +4 -4
  35. package/examples/specs/generation.lawspec +2 -2
  36. package/examples/specs/limits.lawspec +1 -1
  37. package/examples/specs/list_contracts.lawspec +3 -3
  38. package/examples/specs/lists.lawspec +6 -6
  39. package/examples/specs/matching.lawspec +8 -8
  40. package/examples/specs/payments.lawspec +5 -5
  41. package/examples/specs/records.lawspec +4 -4
  42. package/examples/specs/refinements.lawspec +4 -0
  43. package/examples/specs/resilience.lawspec +2 -2
  44. package/examples/specs/resources.lawspec +5 -5
  45. package/examples/specs/sequences.lawspec +1 -1
  46. package/examples/specs/sum_refinements.lawspec +11 -11
  47. package/examples-command.mjs +3 -1
  48. package/index.d.ts +160 -4
  49. package/native-evidence.mjs +25 -12
  50. package/native-examples.mjs +1 -1
  51. package/package.json +2 -1
  52. package/proof.d.ts +57 -12
  53. package/proof.mjs +277 -13
  54. package/templates.mjs +84 -3
  55. package/test-command.mjs +40 -4
@@ -40,7 +40,7 @@ ability Reader with Store is
40
40
  size :: Text -> Maybe Int64
41
41
  laws
42
42
  law "|an unknown log has no size| is
43
- definition : for all (t :: Text) => size t = Nothing end for all end definition
43
+ definition : for all (t :: Text) => size t = Absent end for all end definition
44
44
  end law
45
45
  end laws
46
46
  end ability
@@ -52,7 +52,7 @@ ability Writer with Store is
52
52
  laws
53
53
  law "|a write to a new log is read back| is
54
54
  definition :
55
- for all (t :: Text) (r :: Text where r != "") => (create t; write t r; size t) = Just 1 end for all
55
+ for all (t :: Text) (r :: Text where r != "") => (create t; write t r; size t) = Present 1 end for all
56
56
  end definition
57
57
  end law
58
58
  end laws
@@ -66,8 +66,8 @@ handler store for Logs, Reader with state logs :: KeyVal Text Log start empty un
66
66
  operation create t is ~logs := prelude.put t (Log record{ records = [] , appends = 0}) logs; unitValue end operation
67
67
  operation append t r is
68
68
  first matching case of prelude.lookup t logs :
69
- when Nothing then raise UnknownLog
70
- when Just log then
69
+ when Absent then raise UnknownLog
70
+ when Present log then
71
71
  if r = "" then raise EmptyRecord else
72
72
  (~logs := prelude.put t (log with records = Cons r log.records, appends = prelude.saturating (log.appends + 1)) logs;
73
73
  log.appends) end if
@@ -75,8 +75,8 @@ handler store for Logs, Reader with state logs :: KeyVal Text Log start empty un
75
75
  end operation
76
76
  operation size t is
77
77
  first matching case of prelude.lookup t logs :
78
- when Nothing then Nothing
79
- when Just log then Just log.appends
78
+ when Absent then Absent
79
+ when Present log then Present log.appends
80
80
  end case
81
81
  end operation
82
82
  end handler
@@ -85,13 +85,13 @@ end handler
85
85
  procedure writeTo (t :: Text) (r :: Text) (last :: Maybe Int64) -> Pair Bool (Maybe Int64) uses Logs is
86
86
  first matching case of prelude.attempt (append t r) :
87
87
  when Left problem then Pair false last
88
- when Right offset then Pair true (Just offset)
88
+ when Right offset then Pair true (Present offset)
89
89
  end case
90
90
  end procedure
91
91
 
92
92
  function lastOf (last :: Maybe Int64) -> Pair (Maybe Int64) (Maybe Int64) is Pair last last end function
93
93
 
94
- handler logWriter for Writer with state last :: Maybe Int64 start Nothing is
94
+ handler logWriter for Writer with state last :: Maybe Int64 start Absent is
95
95
  operation write by writeTo end operation
96
96
  operation lastOffset by lastOf end operation
97
97
  end handler
@@ -102,13 +102,13 @@ handlers reference is store, logWriter end handlers
102
102
  law "|sizes count records| is
103
103
  definition :
104
104
  for all (t :: Text) (a :: Text where a != "") (b :: Text where b != "") =>
105
- (create t; append t a; append t b; size t) = Just 2 end for all
105
+ (create t; append t a; append t b; size t) = Present 2 end for all
106
106
  end definition
107
107
  end law
108
108
 
109
109
  law "|a writer remembers where it wrote| is
110
110
  definition :
111
- for all (t :: Text) (r :: Text where r != "") => (create t; write t r; lastOffset) = Just 0 end for all
111
+ for all (t :: Text) (r :: Text where r != "") => (create t; write t r; lastOffset) = Present 0 end for all
112
112
  end definition
113
113
  end law
114
114
  end unit
@@ -109,13 +109,13 @@ type Badge is a record{
109
109
  label :: (v :: Text where validName v)}
110
110
  end type
111
111
 
112
- function withId (body :: Pet) (key :: Int64) -> Pet is body with id = Just key end function
112
+ function withId (body :: Pet) (key :: Int64) -> Pet is body with id = Present key end function
113
113
 
114
114
  function validPet (p :: Pet) -> Bool is p.name matches regex "[a-z]{2,8}" end function
115
115
 
116
116
  law "|an id is set by a record update| is
117
117
  definition :
118
- for all (p :: Pet where validPet p) (key :: Int64) => (withId p key).id = Just key and (withId p key).name = p.name end for all
118
+ for all (p :: Pet where validPet p) (key :: Int64) => (withId p key).id = Present key and (withId p key).name = p.name end for all
119
119
  end definition
120
120
  end law
121
121
 
@@ -22,13 +22,13 @@ procedure handshake (message :: Bytes) (context :: Bytes) -> Maybe Bytes uses Ke
22
22
  let server = deriveAeadKey (decapsulate secret sent) context in
23
23
  unseal server (seal client message context) context end let end let)
24
24
  end case)
25
- else Nothing end if end let)
25
+ else Absent end if end let)
26
26
  end case)
27
27
  end case
28
28
  end procedure
29
29
 
30
30
  law "|a handshake carries the message| is
31
- definition : for all (message :: Bytes) (context :: Bytes) => handshake message context = Just message end for all end definition
31
+ definition : for all (message :: Bytes) (context :: Bytes) => handshake message context = Present message end for all end definition
32
32
  end law
33
33
 
34
34
  -- A native adapter: a short fingerprint of a public key, from its SHA3-256
@@ -39,6 +39,14 @@ law "|placing an order prices it| is
39
39
  input = UnvalidatedOrder record{ id = "A-1" , quantity = 100}
40
40
  expect prelude.isRight (placeOrder input) = true
41
41
  end example
42
+ example "|the last quantity within the price limit| :
43
+ input = UnvalidatedOrder record{ id = "A-2" , quantity = 800}
44
+ expect prelude.isRight (placeOrder input) = true
45
+ end example
46
+ example "|the first quantity over the price limit| :
47
+ input = UnvalidatedOrder record{ id = "A-3" , quantity = 801}
48
+ expect prelude.isRight (placeOrder input) = false
49
+ end example
42
50
  end law
43
51
 
44
52
  law "|validation accepts exactly the valid orders| is
@@ -52,6 +60,18 @@ law "|validation accepts exactly the valid orders| is
52
60
  prelude.length id > 0 && quantity >= 1 && quantity <= 1000
53
61
  end case) end for all
54
62
  end definition
63
+ example "|the largest valid quantity is accepted| :
64
+ input = UnvalidatedOrder record{ id = "A-4" , quantity = 1000}
65
+ expect prelude.isRight (validateOrder input) = true
66
+ end example
67
+ example "|a quantity above the declared range is rejected| :
68
+ input = UnvalidatedOrder record{ id = "A-5" , quantity = 1001}
69
+ expect prelude.isRight (validateOrder input) = false
70
+ end example
71
+ example "|zero is not a unit quantity| :
72
+ input = UnvalidatedOrder record{ id = "A-6" , quantity = 0}
73
+ expect prelude.isRight (validateOrder input) = false
74
+ end example
55
75
  end law
56
76
 
57
77
  law "|quantities are always in range| is
@@ -83,11 +83,11 @@ law "|a push chosen by a match| is
83
83
  definition :
84
84
  for all (m :: Maybe Int8) (s :: Stack n) =>
85
85
  ((first matching case of m :
86
- when Just v then push v ~s
87
- when Nothing then push 0 ~s
86
+ when Present v then push v ~s
87
+ when Absent then push 0 ~s
88
88
  end case); pop ~s) = (first matching case of m :
89
- when Just v then v
90
- when Nothing then prelude.Int8 0
89
+ when Present v then v
90
+ when Absent then prelude.Int8 0
91
91
  end case) end for all
92
92
  end definition
93
93
  end law
@@ -101,8 +101,8 @@ law "|maybe| is
101
101
  end definition
102
102
  example "|seed 5| :
103
103
  seed = 5
104
- expect generated "(maybe (bool))" seed 4 4 = ["Just(false)", "Just(true)", "Just(false)", "Just(true)"]
105
- expect shrunk "(maybe (bool))" seed 4 = ["Nothing"]
104
+ expect generated "(maybe (bool))" seed 4 4 = ["Present(false)", "Present(true)", "Present(false)", "Present(true)"]
105
+ expect shrunk "(maybe (bool))" seed 4 = ["Absent"]
106
106
  end example
107
107
  end law
108
108
 
@@ -33,7 +33,7 @@ workflow quoted :: Ticket -> Either _ Ticket is
33
33
  timeout 200ms
34
34
  end workflow
35
35
 
36
- -- An asynchronous step with a hedge: ticket -2's first quote stalls (600ms),
36
+ -- An asynchronous step with a hedge: ticket -2's first quote stalls,
37
37
  -- so a second starts after 50ms and answers first.
38
38
  async hedgeQuote :: Ticket -> Either Text Ticket
39
39
 
@@ -115,14 +115,14 @@ is value end function
115
115
 
116
116
  function wrapnonzero (value :: Int8 where value != 0)
117
117
  -> Maybe (result :: Int8 where result != 0)
118
- is Just value end function
118
+ is Present value end function
119
119
 
120
120
  function unwrapnonzero (value :: Maybe (element :: Int8 where element != 0))
121
121
  -> Rational
122
122
  is
123
123
  first matching case of value :
124
- when Nothing then 0
125
- when Just element then selectnonzero (Left element)
124
+ when Absent then 0
125
+ when Present element then selectnonzero (Left element)
126
126
  end case
127
127
  end function
128
128
 
@@ -47,22 +47,22 @@ end law
47
47
 
48
48
  law "|Maybe preserves nested absence| is
49
49
  definition : for all (x :: Maybe (Maybe Bool)) => echoMaybe x = x end for all end definition
50
- example "|outer absence| : x = Nothing expect echoMaybe x = Nothing end example
51
- example "|inner absence| : x = Just Nothing expect echoMaybe x = Just Nothing end example
52
- example "|present| : x = Just (Just true) expect echoMaybe x = Just (Just true) end example
50
+ example "|outer absence| : x = Absent expect echoMaybe x = Absent end example
51
+ example "|inner absence| : x = Present Absent expect echoMaybe x = Present Absent end example
52
+ example "|present| : x = Present (Present true) expect echoMaybe x = Present (Present true) end example
53
53
  end law
54
54
 
55
55
  law "|Either preserves branches| is
56
56
  definition : for all (x :: Either (List Int32) (Maybe Bool)) => echoEither x = x end for all end definition
57
57
  example "|left list| : x = Left [3, 1, 3] expect echoEither x = Left [3, 1, 3] end example
58
- example "|right absence| : x = Right Nothing expect echoEither x = Right Nothing end example
58
+ example "|right absence| : x = Right Absent expect echoEither x = Right Absent end example
59
59
  end law
60
60
 
61
61
  law "|nested raw values survive| is
62
62
  definition : for all (xs :: List (Maybe (Either CodeUnit16 Bytes))) => echoNested xs = xs end for all end definition
63
63
  example "|surrogate and octets| :
64
- xs = [Nothing, Just (Left codeUnit16(55296)), Just (Right bytes([0, 255]))]
65
- expect echoNested xs = [Nothing, Just (Left codeUnit16(55296)), Just (Right bytes([0, 255]))]
64
+ xs = [Absent, Present (Left codeUnit16(55296)), Present (Right bytes([0, 255]))]
65
+ expect echoNested xs = [Absent, Present (Left codeUnit16(55296)), Present (Right bytes([0, 255]))]
66
66
  end example
67
67
  end law
68
68
  end unit
@@ -15,10 +15,10 @@ law "|nested Maybe patterns preserve each absence state| is
15
15
  definition :
16
16
  for all (value :: Maybe (Maybe Bool)) =>
17
17
  (first matching case of value :
18
- when Nothing then Nothing
19
- when Just inner then Just (first matching case of inner :
20
- when Nothing then Nothing
21
- when Just payload then Just payload
18
+ when Absent then Absent
19
+ when Present inner then Present (first matching case of inner :
20
+ when Absent then Absent
21
+ when Present payload then Present payload
22
22
  end case)
23
23
  end case) = value end for all
24
24
  end definition
@@ -39,11 +39,11 @@ law "|matching can provide a default value| is
39
39
  definition :
40
40
  for all (value :: Maybe Int8) =>
41
41
  ((first matching case of value :
42
- when Nothing then 0
43
- when Just payload then payload
42
+ when Absent then 0
43
+ when Present payload then payload
44
44
  end case) :: Int8) = ((first matching case of value :
45
- when Just payload then payload
46
- when Nothing then 0
45
+ when Present payload then payload
46
+ when Absent then 0
47
47
  end case) :: Int8) end for all
48
48
  end definition
49
49
  end law
@@ -67,11 +67,11 @@ law "|archives preserve order duplicates and absence| is
67
67
  expect archive payments = []
68
68
  end example
69
69
  example "|missing is different from a declined payment| :
70
- payments = [Nothing, Just (Declined ""), Just (Paid (Money record{ amount = 0.1 , currency = USD})),
71
- Just (Paid (Money record{ amount = 0.1 , currency = USD}))]
72
- expect archive payments = [Nothing, Just (Declined ""),
73
- Just (Paid (Money record{ amount = 0.1 , currency = USD})),
74
- Just (Paid (Money record{ amount = 0.1 , currency = USD}))]
70
+ payments = [Absent, Present (Declined ""), Present (Paid (Money record{ amount = 0.1 , currency = USD})),
71
+ Present (Paid (Money record{ amount = 0.1 , currency = USD}))]
72
+ expect archive payments = [Absent, Present (Declined ""),
73
+ Present (Paid (Money record{ amount = 0.1 , currency = USD})),
74
+ Present (Paid (Money record{ amount = 0.1 , currency = USD}))]
75
75
  end example
76
76
  end law
77
77
  end unit
@@ -89,12 +89,12 @@ end law
89
89
 
90
90
  -- A literal takes its type from where it is used: 0 is an Int64 here.
91
91
  function opening (a :: Maybe Account) -> Int64 is
92
- let start = (first matching case of a : when Nothing then 0 when Just account then account.balance end case) in
92
+ let start = (first matching case of a : when Absent then 0 when Present account then account.balance end case) in
93
93
  if start < 0 then 0 else start end if end let
94
94
  end function
95
95
 
96
96
  law "|an absent account opens at zero| is
97
- definition : opening Nothing = 0 end definition
97
+ definition : opening Absent = 0 end definition
98
98
  end law
99
99
 
100
100
  -- Recursion on an integer that moves toward a bound is total.
@@ -164,10 +164,10 @@ law "|a top up stops at the top| is
164
164
  end definition
165
165
  end law
166
166
 
167
- law "|a total that overflows is Nothing| is
167
+ law "|a total that overflows is Absent| is
168
168
  definition :
169
169
  for all (a :: Int32) (b :: Int32) =>
170
- total a b = (if a + b > Int32.max || a + b < Int32.min then Nothing else Just (prelude.Int32 (a + b)) end if) end for all
170
+ total a b = (if a + b > Int32.max || a + b < Int32.min then Absent else Present (prelude.Int32 (a + b)) end if) end for all
171
171
  end definition
172
172
  end law
173
173
 
@@ -42,6 +42,10 @@ law "|bounded input| is
42
42
  example "|middle| : x = 2 expect positive x = 2 end example
43
43
  end law
44
44
 
45
+ laws for positive are
46
+ partial because "the laws check positive only from 1 to 3"
47
+ end laws
48
+
45
49
  law "|large integer| is
46
50
  definition : for all (x :: UInt64) => preserve x = x end for all end definition
47
51
  example "|maximum UInt64| : x = 18446744073709551615 expect preserve x = 18446744073709551615 end example
@@ -230,8 +230,8 @@ law "|a slow quote times out| is
230
230
  end example
231
231
  end law
232
232
 
233
- -- Quotes a ticket under a runtime with the real clock: whether it succeeded
234
- -- quickly (within 400ms), for ticket -2 through a hedged attempt.
233
+ -- Quotes a ticket under a runtime with the real clock: whether it succeeded,
234
+ -- for ticket -2 through a hedge that overtakes the stalled first attempt.
235
235
  async quoteHedged :: Int64 -> Bool
236
236
 
237
237
  law "|a stalled quote is hedged| is
@@ -24,7 +24,7 @@ end resource
24
24
 
25
25
  law "|a stored value can be read back| for store :: Store is
26
26
  definition :
27
- for all (k :: Int32) (v :: Int32) => put store k v = unitValue and get store k = Just v end for all
27
+ for all (k :: Int32) (v :: Int32) => put store k v = unitValue and get store k = Present v end for all
28
28
  end definition
29
29
  example "|the store is open while the case runs| :
30
30
  k = 1
@@ -51,13 +51,13 @@ greeting :: Unit -> Maybe Int32
51
51
  law "|a note reads back| for dir :: TemporaryDirectory is
52
52
  definition :
53
53
  for all (n :: Int32) =>
54
- writeNote (directoryPath dir) n = unitValue and readNote (directoryPath dir) = Just n end for all
54
+ writeNote (directoryPath dir) n = unitValue and readNote (directoryPath dir) = Present n end for all
55
55
  end definition
56
56
  end law
57
57
 
58
58
  law "|a new directory has no note| for dir :: TemporaryDirectory is
59
59
  definition :
60
- readNote (directoryPath dir) = Nothing
60
+ readNote (directoryPath dir) = Absent
61
61
  end definition
62
62
  end law
63
63
 
@@ -69,13 +69,13 @@ end law
69
69
 
70
70
  law "|the greeting is the one set| for saved :: SavedEnvironment is
71
71
  definition :
72
- for all (n :: Int32) => setGreeting n = unitValue and greeting unitValue = Just n end for all
72
+ for all (n :: Int32) => setGreeting n = unitValue and greeting unitValue = Present n end for all
73
73
  end definition
74
74
  end law
75
75
 
76
76
  law "|the environment is restored after each case| for saved :: SavedEnvironment is
77
77
  definition :
78
- greeting unitValue = Nothing
78
+ greeting unitValue = Absent
79
79
  end definition
80
80
  end law
81
81
 
@@ -73,7 +73,7 @@ end law
73
73
 
74
74
  law "|at reads the item an index names| is
75
75
  definition :
76
- for all (x :: Int32) (xs :: List Int32) => prelude.at 0 (Cons x xs) = Just x and prelude.at (prelude.length xs + 1) (Cons x xs) = Nothing end for all
76
+ for all (x :: Int32) (xs :: List Int32) => prelude.at 0 (Cons x xs) = Present x and prelude.at (prelude.length xs + 1) (Cons x xs) = Absent end for all
77
77
  end definition
78
78
  end law
79
79
 
@@ -2,10 +2,10 @@ unit example.sum_refinements
2
2
 
3
3
  law "|positive Maybe payloads| is
4
4
  definition : for all (x :: Maybe (value :: Int8 where value > 0)) =>
5
- (first matching case of x : when Nothing then true when Just payload then payload >= 1 end case) = true end for all
5
+ (first matching case of x : when Absent then true when Present payload then payload >= 1 end case) = true end for all
6
6
  end definition
7
- example "|absent| : x = Nothing expect x = Nothing end example
8
- example "|present| : x = Just 1 expect x = Just 1 end example
7
+ example "|absent| : x = Absent expect x = Absent end example
8
+ example "|present| : x = Present 1 expect x = Present 1 end example
9
9
  end law
10
10
 
11
11
  law "|selected Either payload| is
@@ -19,13 +19,13 @@ end law
19
19
 
20
20
  law "|nested Maybe states| is
21
21
  definition : for all (x :: Maybe (Maybe (value :: Bool where value))) =>
22
- (first matching case of x : when Nothing then true when Just inner then
23
- first matching case of inner : when Nothing then true when Just payload then payload end case
22
+ (first matching case of x : when Absent then true when Present inner then
23
+ first matching case of inner : when Absent then true when Present payload then payload end case
24
24
  end case) = true end for all
25
25
  end definition
26
- example "|outer absent| : x = Nothing expect x = Nothing end example
27
- example "|inner absent| : x = Just Nothing expect x = Just Nothing end example
28
- example "|present| : x = Just (Just true) expect x = Just (Just true) end example
26
+ example "|outer absent| : x = Absent expect x = Absent end example
27
+ example "|inner absent| : x = Present Absent expect x = Present Absent end example
28
+ example "|present| : x = Present (Present true) expect x = Present (Present true) end example
29
29
  end law
30
30
 
31
31
  law "|finite Either variants| is
@@ -38,13 +38,13 @@ end law
38
38
  law "|dependent payload keeps outer binding| is
39
39
  definition : for all (lawspecElement :: Int8)
40
40
  (x :: Maybe (value :: Int8 where value > lawspecElement)) =>
41
- (first matching case of x : when Nothing then true when Just payload then payload - lawspecElement >= 1 end case) = true end for all
41
+ (first matching case of x : when Absent then true when Present payload then payload - lawspecElement >= 1 end case) = true end for all
42
42
  end definition
43
43
  example "|maximum prefix has absent continuation| :
44
- lawspecElement = 127 x = Nothing expect x = Nothing
44
+ lawspecElement = 127 x = Absent expect x = Absent
45
45
  end example
46
46
  example "|present continuation| :
47
- lawspecElement = 0 x = Just 1 expect x = Just 1
47
+ lawspecElement = 0 x = Present 1 expect x = Present 1
48
48
  end example
49
49
  end law
50
50
  end unit
@@ -2,12 +2,14 @@
2
2
  import { readFile, readdir, mkdir } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { createCompiler } from "./api.mjs";
5
- import { targets } from "./templates.mjs";
5
+ import { programTargets as targets, artifactTargets } from "./templates.mjs";
6
6
  import { safePath, planWrites, applyWrites } from "./files.mjs";
7
7
  import { exportNativePayments } from "./native-examples.mjs";
8
8
 
9
9
  export async function generateExamples(options) {
10
10
  const selected = options.target ? [options.target] : targets;
11
+ if (selected.some(t => artifactTargets.includes(t)))
12
+ throw new Error("examples exports program targets; use init and generate for artifact targets");
11
13
  if (selected.some((t) => !targets.includes(t)))
12
14
  throw new Error(`Unknown target: ${options.target}`);
13
15
  if (options.example !== undefined) {