@helios-lang/contract-utils 0.3.21 → 0.3.23

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 (79) hide show
  1. package/README.md +52 -0
  2. package/package.json +10 -4
  3. package/src/artifacts/ChildArtifactWriter.js +18 -0
  4. package/src/artifacts/RootArtifact.js +8 -0
  5. package/src/cli/compile.js +211 -0
  6. package/src/cli/config.mjs +158 -0
  7. package/src/cli/login.mjs +117 -0
  8. package/src/cli/project.mjs +67 -0
  9. package/src/cli/wallet-file.mjs +14 -0
  10. package/src/cli/wallet.mjs +51 -0
  11. package/src/codegen/LoadedScriptsWriter.js +20 -3
  12. package/src/context/ContractContextBuilder.js +34 -1
  13. package/src/context/debugger.js +46 -0
  14. package/src/helios.mjs +50 -0
  15. package/src/hl2ts.js +5 -185
  16. package/src/index.js +10 -1
  17. package/types/artifacts/ChildArtifactWriter.d.ts.map +1 -1
  18. package/types/artifacts/RootArtifact.d.ts.map +1 -1
  19. package/types/cli/compile.d.ts +9 -0
  20. package/types/cli/compile.d.ts.map +1 -0
  21. package/types/cli/config.d.mts +5 -0
  22. package/types/cli/config.d.mts.map +1 -0
  23. package/types/cli/project.d.mts +11 -0
  24. package/types/cli/project.d.mts.map +1 -0
  25. package/types/codegen/LoadedScriptsWriter.d.ts +2 -1
  26. package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -1
  27. package/types/context/ContractContextBuilder.d.ts.map +1 -1
  28. package/types/context/debugger.d.ts +9 -0
  29. package/types/context/debugger.d.ts.map +1 -0
  30. package/types/hl2ts.d.ts +1 -6
  31. package/types/hl2ts.d.ts.map +1 -1
  32. package/types/index.d.ts +18 -1
  33. package/types/index.d.ts.map +1 -1
  34. package/types/cast/PermissiveType.d.ts +0 -4
  35. package/types/cast/PermissiveType.d.ts.map +0 -1
  36. package/types/cast/StrictType.d.ts +0 -4
  37. package/types/cast/StrictType.d.ts.map +0 -1
  38. package/types/codegen/LoadedModule.d.ts +0 -17
  39. package/types/codegen/LoadedModule.d.ts.map +0 -1
  40. package/types/codegen/LoadedValidator.d.ts +0 -38
  41. package/types/codegen/LoadedValidator.d.ts.map +0 -1
  42. package/types/codegen/Module.d.ts +0 -24
  43. package/types/codegen/Module.d.ts.map +0 -1
  44. package/types/codegen/TypeCheckedModule.d.ts +0 -24
  45. package/types/codegen/TypeCheckedModule.d.ts.map +0 -1
  46. package/types/codegen/TypeCheckedValidator.d.ts +0 -9
  47. package/types/codegen/TypeCheckedValidator.d.ts.map +0 -1
  48. package/types/codegen/TypescriptWriter.d.ts +0 -50
  49. package/types/codegen/TypescriptWriter.d.ts.map +0 -1
  50. package/types/codegen/Validator.d.ts +0 -22
  51. package/types/codegen/Validator.d.ts.map +0 -1
  52. package/types/codegen/Writer.d.ts +0 -23
  53. package/types/codegen/Writer.d.ts.map +0 -1
  54. package/types/context/ContractContext.d.ts +0 -53
  55. package/types/context/ContractContext.d.ts.map +0 -1
  56. package/types/context/writeContractContextArtifacts.d.ts +0 -30
  57. package/types/context/writeContractContextArtifacts.d.ts.map +0 -1
  58. package/types/lib/Lib.d.ts +0 -41
  59. package/types/lib/Lib.d.ts.map +0 -1
  60. package/types/lib/Libg_v0_16.d.ts +0 -256
  61. package/types/lib/Libg_v0_16.d.ts.map +0 -1
  62. package/types/lib/index.d.ts +0 -3
  63. package/types/lib/index.d.ts.map +0 -1
  64. package/types/lib/load.d.ts +0 -6
  65. package/types/lib/load.d.ts.map +0 -1
  66. package/types/runtime/Cast.d.ts +0 -32
  67. package/types/runtime/Cast.d.ts.map +0 -1
  68. package/types/runtime/ContractContext.d.ts +0 -23
  69. package/types/runtime/ContractContext.d.ts.map +0 -1
  70. package/types/runtime/ContractContextBuilder.d.ts +0 -53
  71. package/types/runtime/ContractContextBuilder.d.ts.map +0 -1
  72. package/types/runtime/DagCompiler.d.ts +0 -64
  73. package/types/runtime/DagCompiler.d.ts.map +0 -1
  74. package/types/runtime/PermissiveType.d.ts +0 -3
  75. package/types/runtime/PermissiveType.d.ts.map +0 -1
  76. package/types/runtime/StrictType.d.ts +0 -3
  77. package/types/runtime/StrictType.d.ts.map +0 -1
  78. package/types/runtime/index.d.ts +0 -2
  79. package/types/runtime/index.d.ts.map +0 -1
@@ -0,0 +1,14 @@
1
+ import { open, unlink } from "node:fs/promises"
2
+ import { windowsAcl } from "./config.mjs"
3
+ export async function writePrivateWallet(path, json) {
4
+ const file = await open(path, "wx", 0o600)
5
+ try {
6
+ if (process.platform === "win32") await windowsAcl(path, false, true)
7
+ await file.writeFile(json, "utf8")
8
+ } catch (error) {
9
+ await file.close()
10
+ await unlink(path)
11
+ throw error
12
+ }
13
+ await file.close()
14
+ }
@@ -0,0 +1,51 @@
1
+ import { randomBytes } from "node:crypto"
2
+ import { parseArgs } from "node:util"
3
+ import { makeRootPrivateKey } from "@helios-lang/tx-utils"
4
+ import { makeShelleyAddress } from "@helios-lang/ledger"
5
+
6
+ export function createWallet(network = "preprod") {
7
+ if (!["preprod", "preview", "mainnet"].includes(network))
8
+ throw new Error("Network must be preprod, preview, or mainnet")
9
+ const key = makeRootPrivateKey([...randomBytes(32)])
10
+ const address = makeShelleyAddress(
11
+ network === "mainnet",
12
+ key.deriveSpendingKey().derivePubKey().hash(),
13
+ key.deriveStakingKey().derivePubKey().hash()
14
+ )
15
+ return {
16
+ network,
17
+ phrase: key.toPhrase().join(" "),
18
+ address: address.toBech32()
19
+ }
20
+ }
21
+ export async function walletCommand(args) {
22
+ const [command, ...rest] = args
23
+ if (["--help", "-h", "help"].includes(command)) {
24
+ console.log(
25
+ "helios wallet create [--network preprod|preview|mainnet] [--out wallet.json]\nGenerates a 24-word recovery phrase and address offline. Without --out, prints the secret phrase as JSON. --out creates a new owner-only file and never overwrites an existing file."
26
+ )
27
+ return
28
+ }
29
+ if (command !== "create")
30
+ throw new Error(
31
+ "Usage: helios wallet create [--network preprod|preview|mainnet] [--out wallet.json]"
32
+ )
33
+ const { values } = parseArgs({
34
+ args: rest,
35
+ options: {
36
+ network: { type: "string", default: "preprod" },
37
+ out: { type: "string" }
38
+ }
39
+ })
40
+ const wallet = createWallet(values.network)
41
+ const json = JSON.stringify(wallet, null, 2) + "\n"
42
+ if (values.out !== undefined) {
43
+ if (!values.out.trim()) throw new Error("--out requires a file path")
44
+ // Reuse credential-file ACL protection on Windows, before storing secrets.
45
+ const { writePrivateWallet } = await import("./wallet-file.mjs")
46
+ await writePrivateWallet(values.out, json)
47
+ console.log(
48
+ `Created ${wallet.network} wallet: ${wallet.address}\nRecovery phrase saved in ${values.out}`
49
+ )
50
+ } else console.log(json)
51
+ }
@@ -9,22 +9,33 @@ import { genTypes } from "./TypeSchema.js"
9
9
 
10
10
  /**
11
11
  * Constructs a LoadedScriptsWriter instance and initializes it be writing the header
12
+ * @param {import("../index.js").DebuggerContext} [debuggerContext]
12
13
  * @returns {LoadedScriptsWriter}
13
14
  */
14
- export function makeLoadedScriptsWriter() {
15
- return new LoadedScriptsWriterImpl()
15
+ export function makeLoadedScriptsWriter(debuggerContext) {
16
+ return new LoadedScriptsWriterImpl(debuggerContext)
16
17
  }
17
18
 
18
19
  /**
19
20
  * @implements {LoadedScriptsWriter}
20
21
  */
21
22
  class LoadedScriptsWriterImpl {
22
- constructor() {
23
+ /** @param {import("../index.js").DebuggerContext} [debuggerContext] */
24
+ constructor(debuggerContext) {
25
+ this.debuggerContext = debuggerContext
23
26
  this.definition = makeStringWriter()
24
27
  this.declaration = makeStringWriter()
25
28
  this.combined = makeStringWriter()
26
29
 
27
30
  this.writeHeaders()
31
+ if (debuggerContext) {
32
+ const value = JSON.stringify(debuggerContext)
33
+ this.definition.write(`export const $debugger = ${value}\n`)
34
+ this.combined.write(`export const $debugger = ${value}\n`)
35
+ this.declaration.write(
36
+ `export declare const $debugger: import("@helios-lang/contract-utils").DebuggerContext\n`
37
+ )
38
+ }
28
39
  }
29
40
 
30
41
  /**
@@ -271,6 +282,7 @@ class LoadedScriptsWriterImpl {
271
282
  */
272
283
  writeModule(m) {
273
284
  this.definition.write(`export const ${m.name} = {
285
+ ${this.debuggerContext ? "$debugger," : ""}
274
286
  $name: /** @type {const} */ ("${m.name}"),
275
287
  $purpose: /** @type {const} */ ("${m.purpose}"),
276
288
  $sourceCode: ${JSON.stringify(m.sourceCode)},
@@ -278,6 +290,7 @@ class LoadedScriptsWriterImpl {
278
290
 
279
291
  this.declaration.write(
280
292
  `export const ${m.name}: {
293
+ ${this.debuggerContext ? '$debugger: import("@helios-lang/contract-utils").DebuggerContext' : ""}
281
294
  $name: "${m.name}"
282
295
  $purpose: "${m.purpose}"
283
296
  $sourceCode: string
@@ -286,6 +299,7 @@ class LoadedScriptsWriterImpl {
286
299
 
287
300
  this.combined.write(
288
301
  `export const ${m.name} = {
302
+ ${this.debuggerContext ? "$debugger," : ""}
289
303
  $name: "${m.name}" as const,
290
304
  $purpose: "${m.purpose}" as const,
291
305
  $sourceCode: ${JSON.stringify(m.sourceCode)} as string,
@@ -311,6 +325,7 @@ class LoadedScriptsWriterImpl {
311
325
 
312
326
  this.definition.write(
313
327
  `export const ${v.name} = {
328
+ ${this.debuggerContext ? "$debugger," : ""}
314
329
  $name: /** @type {const} */ ("${v.name}"),
315
330
  $purpose: /** @type {const} */ ("${v.purpose}"),
316
331
  ${isSome(currentScriptIndex) ? ` $currentScriptIndex: /** @type {const} */ (${currentScriptIndex}),` : ""}
@@ -324,6 +339,7 @@ ${datumTypes ? ` $Datum: (config) => /** @type {Cast<${datumTypes[0]}, ${datu
324
339
 
325
340
  this.declaration.write(
326
341
  `export const ${v.name}: {
342
+ ${this.debuggerContext ? '$debugger: import("@helios-lang/contract-utils").DebuggerContext' : ""}
327
343
  $name: "${v.name}"
328
344
  $purpose: "${v.purpose}"
329
345
  ${isSome(currentScriptIndex) ? ` $currentScriptIndex: ${currentScriptIndex}` : ""}
@@ -340,6 +356,7 @@ ${datumTypes ? ` $Datum: ConfigurableCast<${datumTypes[0]}, ${datumTypes[1]}>
340
356
 
341
357
  this.combined.write(
342
358
  `export const ${v.name} = {
359
+ ${this.debuggerContext ? "$debugger," : ""}
343
360
  $name: "${v.name}" as const,
344
361
  $purpose: "${v.purpose}" as const,
345
362
  ${isSome(currentScriptIndex) ? ` $currentScriptIndex: ${currentScriptIndex} as const,` : ""}
@@ -1,3 +1,4 @@
1
+ import { bindDebuggerContexts } from "./debugger.js"
1
2
  import { expectDefined } from "@helios-lang/type-utils"
2
3
  import { configureCast } from "../cast/Cast.js"
3
4
  import { loadCompilerLib } from "../compiler/index.js"
@@ -115,7 +116,7 @@ class ContractContextBuilderImpl {
115
116
 
116
117
  const cached = contractContextCache.get(key)
117
118
 
118
- const compiled =
119
+ let compiled =
119
120
  cached ||
120
121
  dagCompiler.build(
121
122
  Object.values(this.validators),
@@ -125,6 +126,7 @@ class ContractContextBuilderImpl {
125
126
  )
126
127
 
127
128
  contractContextCache.set(key, compiled)
129
+ compiled = bindDebuggerContexts(compiled, this.validators, this.modules)
128
130
 
129
131
  if (props.dumpHashes) {
130
132
  for (let name in compiled.validators) {
@@ -136,11 +138,34 @@ class ContractContextBuilderImpl {
136
138
  * @type {any}
137
139
  */
138
140
  const res = {}
141
+ const contexts = [
142
+ ...Object.values(this.validators),
143
+ ...Object.values(this.modules)
144
+ ]
145
+ .map((v) => v.$debugger)
146
+ .filter(Boolean)
147
+ if (
148
+ contexts.length &&
149
+ contexts.every(
150
+ (c) =>
151
+ c?.apiKey === contexts[0]?.apiKey &&
152
+ c?.endpoint === contexts[0]?.endpoint
153
+ )
154
+ )
155
+ res.$debugger = contexts[0]
139
156
 
140
157
  for (let name in this.modules) {
141
158
  const mod = this.modules[name]
142
159
 
143
160
  res[name] = {
161
+ ...(this.validators[name]?.$debugger ||
162
+ this.modules[name]?.$debugger
163
+ ? {
164
+ $debugger:
165
+ this.validators[name]?.$debugger ??
166
+ this.modules[name]?.$debugger
167
+ }
168
+ : {}),
144
169
  ...Object.fromEntries(
145
170
  Object.entries(mod.$types).map(([typeName, castLike]) => [
146
171
  typeName,
@@ -167,6 +192,14 @@ class ContractContextBuilderImpl {
167
192
  const validator = this.validators[name]
168
193
 
169
194
  res[name] = {
195
+ ...(this.validators[name]?.$debugger ||
196
+ this.modules[name]?.$debugger
197
+ ? {
198
+ $debugger:
199
+ this.validators[name]?.$debugger ??
200
+ this.modules[name]?.$debugger
201
+ }
202
+ : {}),
170
203
  ...Object.fromEntries(
171
204
  Object.entries(validator.$types).map(
172
205
  ([typeName, castLike]) => [
@@ -0,0 +1,46 @@
1
+ import { cacheEntryFromJson, cacheEntryToJsonSafe } from "./CacheEntry.js"
2
+ /**
3
+ * Bind credentials after cache lookup, keeping shared compilation caches credential-free.
4
+ * @param {import('./CacheEntry.js').CacheEntry} compiled
5
+ * @param {Record<string, import('../index.js').LoadedValidator>} validators
6
+ * @param {Record<string, import('../index.js').LoadedModule>} modules
7
+ * @returns {import('./CacheEntry.js').CacheEntry}
8
+ */
9
+ export function bindDebuggerContexts(compiled, validators, modules) {
10
+ if (
11
+ ![...Object.values(validators), ...Object.values(modules)].some(
12
+ (v) => v.$debugger
13
+ )
14
+ )
15
+ return compiled
16
+ const result = cacheEntryFromJson(cacheEntryToJsonSafe(compiled))
17
+ for (const [name, hash] of Object.entries(result.validators)) {
18
+ const context = validators[name]?.$debugger
19
+ if (context) {
20
+ const hashContext = /** @type {any} */ (hash.context)
21
+ attach(hashContext.program, context)
22
+ Object.defineProperty(hashContext, "$debugger", {
23
+ value: context,
24
+ enumerable: false
25
+ })
26
+ }
27
+ }
28
+ for (const [name, program] of Object.entries(result.userFuncs)) {
29
+ const moduleName = name.split("::")[0]
30
+ const context =
31
+ validators[moduleName]?.$debugger ?? modules[moduleName]?.$debugger
32
+ if (context) attach(program, context)
33
+ }
34
+ return result
35
+ }
36
+ /**
37
+ * @param {import('@helios-lang/uplc').UplcProgram} program
38
+ * @param {import('../index.js').DebuggerContext} context
39
+ */
40
+ function attach(program, context) {
41
+ Object.defineProperty(program, "$debugger", {
42
+ value: context,
43
+ enumerable: false
44
+ })
45
+ if (program.alt) attach(program.alt, context)
46
+ }
package/src/helios.mjs ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import { readFile } from "node:fs/promises"
3
+ const [command, ...args] = process.argv.slice(2)
4
+ try {
5
+ if (command === "compile") {
6
+ const { compile } = await import("./cli/compile.js")
7
+ await compile(
8
+ args.map((arg) => (["--help", "-h"].includes(arg) ? "help" : arg))
9
+ )
10
+ } else if (command === "wallet") {
11
+ const { walletCommand } = await import("./cli/wallet.mjs")
12
+ await walletCommand(args)
13
+ } else if (command === "login") {
14
+ if (args.some((arg) => arg !== "--no-browser"))
15
+ throw new Error("Usage: helios login [--no-browser]")
16
+ const { login } = await import("./cli/login.mjs")
17
+ const abort = new AbortController()
18
+ const cancel = () => abort.abort(new Error("Login cancelled"))
19
+ process.once("SIGINT", cancel)
20
+ process.once("SIGTERM", cancel)
21
+ try {
22
+ await login({
23
+ noBrowser: args.includes("--no-browser"),
24
+ signal: AbortSignal.any([
25
+ abort.signal,
26
+ AbortSignal.timeout(600000)
27
+ ])
28
+ })
29
+ } finally {
30
+ process.removeListener("SIGINT", cancel)
31
+ process.removeListener("SIGTERM", cancel)
32
+ }
33
+ } else if (command === "--version" || command === "-v") {
34
+ console.log(
35
+ JSON.parse(
36
+ await readFile(
37
+ new URL("../package.json", import.meta.url),
38
+ "utf8"
39
+ )
40
+ ).version
41
+ )
42
+ } else if (!command || ["--help", "-h", "help"].includes(command)) {
43
+ console.log(
44
+ "Helios CLI\n\n helios compile [options] Compile contracts (same options as hl2ts)\n helios login [--no-browser] Install project API keys through the Console\n helios wallet create [--network preprod] [--out wallet.json] Generate a wallet offline\n helios --version"
45
+ )
46
+ } else throw new Error(`Unknown command: ${command}. Run helios --help.`)
47
+ } catch (error) {
48
+ console.error(error.message)
49
+ process.exitCode = 1
50
+ }
package/src/hl2ts.js CHANGED
@@ -1,186 +1,6 @@
1
1
  #!/usr/bin/env node
2
-
3
- import {
4
- existsSync,
5
- mkdirSync,
6
- promises,
7
- readFileSync,
8
- writeFileSync
9
- } from "node:fs"
10
- import { dirname, join, resolve } from "node:path"
11
- import { Cli, EnumOpt, StringOpt } from "@helios-lang/cli-utils"
12
- import { makeLoadedScriptsWriter } from "./codegen/index.js"
13
- import { loadCompilerLib } from "./compiler/index.js"
14
- import { typeCheckFiles } from "./compiler/ops.js"
15
-
16
- /**
17
- * @typedef {{
18
- * name: string
19
- * purpose: string
20
- * sourceCode: string
21
- * }} SourceDetails
22
- */
23
-
24
- /**
25
- * @typedef {"javascript" | "typescript"} FormatKind
26
- */
27
-
28
- const NAME = "hl2ts"
29
-
30
- async function main() {
31
- const cli = new Cli(NAME, {
32
- minArgs: 0,
33
- maxArgs: 0,
34
- options: {
35
- outDir: new StringOpt({
36
- long: "--out-dir",
37
- short: "-o",
38
- default: () => process.cwd()
39
- }),
40
- format: new EnumOpt({
41
- long: "--format",
42
- short: "-f",
43
- variants: /** @type {FormatKind[]} */ ([
44
- "javascript",
45
- "typescript"
46
- ]),
47
- default: () => {
48
- const path = findPackageJson()
49
-
50
- if (
51
- path &&
52
- existsSync(join(dirname(path), "tsconfig.json"))
53
- ) {
54
- return "typescript"
55
- } else {
56
- return "javascript"
57
- }
58
- }
59
- })
60
- },
61
- action: mainInternal
62
- })
63
-
64
- await cli.run()
65
- }
66
-
67
- /**
68
- * @param {string[]} _args
69
- * @param {{outDir: string, format: FormatKind}} options
70
- * @returns {Promise<void>}
71
- */
72
- async function mainInternal(_args, { outDir, format }) {
73
- const lib = loadCompilerLib()
74
-
75
- const filePaths = await listFiles(process.cwd(), ".hl")
76
- const files = readFiles(filePaths)
77
-
78
- console.log(`${NAME} using Helios compiler v${lib.version}`)
79
- console.log(` Transpiling ${Object.keys(files).length} inputs:`)
80
- filePaths.forEach((p) => console.log(` ${p}`))
81
-
82
- const { modules, validators } = typeCheckFiles(lib, files, (current, rel) =>
83
- resolve(join(dirname(current), rel))
84
- )
85
-
86
- const [js, dts, ts] = makeLoadedScriptsWriter()
87
- .writeModules(modules)
88
- .writeValidators(validators)
89
- .finalize()
90
-
91
- if (format == "typescript") {
92
- const tsPath = join(outDir, "index.ts")
93
-
94
- writeFileSync(tsPath, ts)
95
-
96
- console.log(` Output:`)
97
- console.log(` ${tsPath}`)
98
- } else {
99
- const resolvedOutDir = resolve(outDir)
100
-
101
- mkdirIfNotExists(resolvedOutDir)
102
-
103
- const jsPath = join(resolvedOutDir, "index.js")
104
- const dtsPath = join(resolvedOutDir, "index.d.ts")
105
-
106
- writeFileSync(jsPath, js)
107
- writeFileSync(dtsPath, dts)
108
-
109
- console.log(` Output:`)
110
- console.log(` ${jsPath}`)
111
- console.log(` ${dtsPath}`)
112
- }
113
- }
114
-
115
- main()
116
-
117
- /**
118
- * @param {string} dir
119
- * @param {string} ext
120
- * @returns {Promise<string[]>}
121
- */
122
- async function listFiles(dir, ext) {
123
- const entries = await promises.readdir(dir, { withFileTypes: true })
124
-
125
- const files = await Promise.all(
126
- entries.map((entry) => {
127
- const res = resolve(dir, entry.name)
128
-
129
- if (entry.isDirectory()) {
130
- if (entry.name.endsWith("node_modules")) {
131
- return []
132
- } else {
133
- return listFiles(res, ext)
134
- }
135
- } else {
136
- return res
137
- }
138
- })
139
- )
140
-
141
- return files.flat().filter((name) => name.endsWith(ext))
142
- }
143
-
144
- /**
145
- * @param {string[]} filePaths
146
- * @returns {{[path: string]: string}}
147
- */
148
- function readFiles(filePaths) {
149
- return Object.fromEntries(
150
- filePaths.map((f) => {
151
- return [f, readFileSync(f).toString()]
152
- })
153
- )
154
- }
155
-
156
- /**
157
- * @param {string} fileName
158
- * @returns {string | undefined}
159
- */
160
- function findPackageJson(fileName = "package.json") {
161
- let dir = process.cwd()
162
-
163
- let path = join(dir, fileName)
164
- let found = existsSync(path)
165
-
166
- while (!found) {
167
- dir = dirname(dir)
168
- path = join(dir, fileName)
169
- found = existsSync(path)
170
- }
171
-
172
- if (found) {
173
- return path
174
- } else {
175
- return undefined
176
- }
177
- }
178
-
179
- /**
180
- * @param {string} dir
181
- */
182
- function mkdirIfNotExists(dir) {
183
- if (!existsSync(dir)) {
184
- mkdirSync(dir, { recursive: true })
185
- }
186
- }
2
+ import { compile } from "./cli/compile.js"
3
+ compile(process.argv.slice(2)).catch((error) => {
4
+ console.error(error.message)
5
+ process.exitCode = 1
6
+ })
package/src/index.js CHANGED
@@ -204,6 +204,7 @@ export { genTypes } from "./codegen/TypeSchema.js"
204
204
 
205
205
  /**
206
206
  * @typedef {{
207
+ * $debugger?: DebuggerContext
207
208
  * $name: string
208
209
  * $purpose: "module"
209
210
  * $sourceCode: string
@@ -216,6 +217,7 @@ export { genTypes } from "./codegen/TypeSchema.js"
216
217
  /**
217
218
  * * Note: `$hashDependencies` doesn't contain the indirect dependencies! It must be kept to a minimum in order to inform in which order the validators must be compiled
218
219
  * @typedef {{
220
+ * $debugger?: DebuggerContext
219
221
  * $name: string
220
222
  * $sourceCode: string
221
223
  * $dependencies: ReadonlyArray<LoadedModule>
@@ -341,7 +343,7 @@ export { genTypes } from "./codegen/TypeSchema.js"
341
343
  * [K in keyof Vs]: ContractValidatorContexts<Vs[K]>
342
344
  * } & {
343
345
  * [K in keyof Ms]: ContractModuleContexts<Ms[K]>
344
- * }} ContractContext
346
+ * } & {$debugger?: DebuggerContext}} ContractContext
345
347
  */
346
348
 
347
349
  /**
@@ -386,3 +388,10 @@ export { genTypes } from "./codegen/TypeSchema.js"
386
388
  * fs: FileSystem
387
389
  * }} WriteContractContextArtifactsOptions
388
390
  */
391
+
392
+ /**
393
+ * Metadata carried outside script CBOR/hashes for automatic failed-transaction capture.
394
+ * @typedef {{projectId: string, name: string, apiKey: string, endpoint: string, sources?: Record<string,string>}} DebuggerContext
395
+ */
396
+
397
+ /** @typedef {UplcProgram & {$debugger?: DebuggerContext}} DebuggerUplcProgram */
@@ -1 +1 @@
1
- {"version":3,"file":"ChildArtifactWriter.d.ts","sourceRoot":"","sources":["../../src/artifacts/ChildArtifactWriter.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;IAaI;;;OAGG;IACH,oBAHW,QAAQ,QACR,MAAM,EAOhB;IArBD;;;OAGG;IACH,iBAFU,QAAQ,CAEZ;IAEN;;;OAGG;IACH,eAFU,MAAM,CAEZ;IAaJ;;OAEG;IACH,iBAFU,OAAO,CAIhB;IAED;;;;;OAKG;IACH,mBALW,MAAM,WACN,WAAW,cACX,OAAO,GACL,mBAAmB,CA0D/B;CACJ;+BArG8B,qBAAqB;8BAIvB,eAAe;iCADZ,mBAAmB"}
1
+ {"version":3,"file":"ChildArtifactWriter.d.ts","sourceRoot":"","sources":["../../src/artifacts/ChildArtifactWriter.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;IAaI;;;OAGG;IACH,oBAHW,QAAQ,QACR,MAAM,EAOhB;IArBD;;;OAGG;IACH,iBAFU,QAAQ,CAEZ;IAEN;;;OAGG;IACH,eAFU,MAAM,CAEZ;IAaJ;;OAEG;IACH,iBAFU,OAAO,CAIhB;IAED;;;;;OAKG;IACH,mBALW,MAAM,WACN,WAAW,cACX,OAAO,GACL,mBAAmB,CA4E/B;CACJ;+BAvH8B,qBAAqB;8BAIvB,eAAe;iCADZ,mBAAmB"}
@@ -1 +1 @@
1
- {"version":3,"file":"RootArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/RootArtifact.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;GAGG;AACH,uDAHW,GAAG,WACH,oCAAoC,QAoC9C;0DA1CyJ,aAAa"}
1
+ {"version":3,"file":"RootArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/RootArtifact.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;GAGG;AACH,uDAHW,GAAG,WACH,oCAAoC,QA4C9C;0DAlDyJ,aAAa"}
@@ -0,0 +1,9 @@
1
+ /** @param {string[]} args */
2
+ export function compile(args: string[]): Promise<void>;
3
+ export type SourceDetails = {
4
+ name: string;
5
+ purpose: string;
6
+ sourceCode: string;
7
+ };
8
+ export type FormatKind = "javascript" | "typescript";
9
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cli/compile.js"],"names":[],"mappings":"AA2BA,6BAA6B;AAC7B,8BADY,MAAM,EAAE,iBA8CnB;4BA3DY;IACR,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;CACnB;yBAIS,YAAY,GAAG,YAAY"}
@@ -0,0 +1,5 @@
1
+ export function windowsAcl(path: any, directory: any, set?: boolean): Promise<void>;
2
+ export function configPath(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv, home?: string): string;
3
+ export function readConfig(path?: string): Promise<any>;
4
+ export function installProjects(wallet: any, projects: any, endpoint: any, path?: string): Promise<string>;
5
+ //# sourceMappingURL=config.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../src/cli/config.mjs"],"names":[],"mappings":"AAeA,oFAiCC;AACD,uGAcC;AAqBD,wDAaC;AACD,2GA2DC"}
@@ -0,0 +1,11 @@
1
+ export function resolveProject(name: any, { read, fetchImpl }?: {
2
+ read?: typeof readConfig | undefined;
3
+ fetchImpl?: typeof fetch | undefined;
4
+ }): Promise<{
5
+ projectId: any;
6
+ name: any;
7
+ apiKey: any;
8
+ endpoint: string;
9
+ }>;
10
+ import { readConfig } from "./config.mjs";
11
+ //# sourceMappingURL=project.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.mts","sourceRoot":"","sources":["../../src/cli/project.mjs"],"names":[],"mappings":"AACA;;;;;;;;GAiEC;2BAlE0B,cAAc"}
@@ -4,9 +4,10 @@
4
4
  */
5
5
  /**
6
6
  * Constructs a LoadedScriptsWriter instance and initializes it be writing the header
7
+ * @param {import("../index.js").DebuggerContext} [debuggerContext]
7
8
  * @returns {LoadedScriptsWriter}
8
9
  */
9
- export function makeLoadedScriptsWriter(): LoadedScriptsWriter;
10
+ export function makeLoadedScriptsWriter(debuggerContext?: import("../index.js").DebuggerContext): LoadedScriptsWriter;
10
11
  /**
11
12
  * @param {TypeCheckedUserFunc} props
12
13
  * @param {boolean} unsafe
@@ -1 +1 @@
1
- {"version":3,"file":"LoadedScriptsWriter.d.ts","sourceRoot":"","sources":["../../src/codegen/LoadedScriptsWriter.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;GAGG;AACH,2CAFa,mBAAmB,CAI/B;AAsXD;;;;GAIG;AACH,0CAJW,mBAAmB,WACnB,OAAO,GACL,MAAM,CAUlB;AAED;;;;GAIG;AACH,2CAJW,mBAAmB,WACnB,OAAO,GACL,MAAM,CAyBlB;AAED;;;GAGG;AACH,gCAHW,mBAAmB,GACjB,CAAC,MAAM,EAAE,MAAM,CAAC,CAI5B;yCAlbqG,aAAa;yCAAb,aAAa"}
1
+ {"version":3,"file":"LoadedScriptsWriter.d.ts","sourceRoot":"","sources":["../../src/codegen/LoadedScriptsWriter.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;;GAIG;AACH,0DAHW,OAAO,aAAa,EAAE,eAAe,GACnC,mBAAmB,CAI/B;AAsYD;;;;GAIG;AACH,0CAJW,mBAAmB,WACnB,OAAO,GACL,MAAM,CAUlB;AAED;;;;GAIG;AACH,2CAJW,mBAAmB,WACnB,OAAO,GACL,MAAM,CAyBlB;AAED;;;GAGG;AACH,gCAHW,mBAAmB,GACjB,CAAC,MAAM,EAAE,MAAM,CAAC,CAI5B;yCAncqG,aAAa;yCAAb,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"ContractContextBuilder.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextBuilder.js"],"names":[],"mappings":"AAMA;;;GAGG;AAEH;;GAEG;AACH,8CAFa,uBAAuB,EAAE,EAAE,EAAE,CAAC,CAI1C;4CARqK,aAAa"}
1
+ {"version":3,"file":"ContractContextBuilder.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextBuilder.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;;GAEG;AACH,8CAFa,uBAAuB,EAAE,EAAE,EAAE,CAAC,CAI1C;4CARqK,aAAa"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Bind credentials after cache lookup, keeping shared compilation caches credential-free.
3
+ * @param {import('./CacheEntry.js').CacheEntry} compiled
4
+ * @param {Record<string, import('../index.js').LoadedValidator>} validators
5
+ * @param {Record<string, import('../index.js').LoadedModule>} modules
6
+ * @returns {import('./CacheEntry.js').CacheEntry}
7
+ */
8
+ export function bindDebuggerContexts(compiled: import("./CacheEntry.js").CacheEntry, validators: Record<string, import("../index.js").LoadedValidator>, modules: Record<string, import("../index.js").LoadedModule>): import("./CacheEntry.js").CacheEntry;
9
+ //# sourceMappingURL=debugger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debugger.d.ts","sourceRoot":"","sources":["../../src/context/debugger.js"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,+CALW,OAAO,iBAAiB,EAAE,UAAU,cACpC,MAAM,CAAC,MAAM,EAAE,OAAO,aAAa,EAAE,eAAe,CAAC,WACrD,MAAM,CAAC,MAAM,EAAE,OAAO,aAAa,EAAE,YAAY,CAAC,GAChD,OAAO,iBAAiB,EAAE,UAAU,CA4BhD"}
package/types/hl2ts.d.ts CHANGED
@@ -1,8 +1,3 @@
1
1
  #!/usr/bin/env node
2
- export type SourceDetails = {
3
- name: string;
4
- purpose: string;
5
- sourceCode: string;
6
- };
7
- export type FormatKind = "javascript" | "typescript";
2
+ export {};
8
3
  //# sourceMappingURL=hl2ts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hl2ts.d.ts","sourceRoot":"","sources":["../src/hl2ts.js"],"names":[],"mappings":";4BAgBa;IACR,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;CACnB;yBAIS,YAAY,GAAG,YAAY"}
1
+ {"version":3,"file":"hl2ts.d.ts","sourceRoot":"","sources":["../src/hl2ts.js"],"names":[],"mappings":""}