@helios-lang/contract-utils 0.3.21 → 0.3.22
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/README.md +46 -0
- package/package.json +9 -4
- package/src/artifacts/ChildArtifactWriter.js +18 -0
- package/src/artifacts/RootArtifact.js +8 -0
- package/src/cli/compile.js +211 -0
- package/src/cli/config.mjs +158 -0
- package/src/cli/login.mjs +117 -0
- package/src/cli/project.mjs +67 -0
- package/src/codegen/LoadedScriptsWriter.js +20 -3
- package/src/context/ContractContextBuilder.js +34 -1
- package/src/context/debugger.js +46 -0
- package/src/helios.mjs +47 -0
- package/src/hl2ts.js +5 -185
- package/src/index.js +10 -1
- package/types/artifacts/ChildArtifactWriter.d.ts.map +1 -1
- package/types/artifacts/RootArtifact.d.ts.map +1 -1
- package/types/cli/compile.d.ts +9 -0
- package/types/cli/compile.d.ts.map +1 -0
- package/types/cli/config.d.mts +4 -0
- package/types/cli/config.d.mts.map +1 -0
- package/types/cli/project.d.mts +11 -0
- package/types/cli/project.d.mts.map +1 -0
- package/types/codegen/LoadedScriptsWriter.d.ts +2 -1
- package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -1
- package/types/context/ContractContextBuilder.d.ts.map +1 -1
- package/types/context/debugger.d.ts +9 -0
- package/types/context/debugger.d.ts.map +1 -0
- package/types/hl2ts.d.ts +1 -6
- package/types/hl2ts.d.ts.map +1 -1
- package/types/index.d.ts +18 -1
- package/types/index.d.ts.map +1 -1
- package/types/cast/PermissiveType.d.ts +0 -4
- package/types/cast/PermissiveType.d.ts.map +0 -1
- package/types/cast/StrictType.d.ts +0 -4
- package/types/cast/StrictType.d.ts.map +0 -1
- package/types/codegen/LoadedModule.d.ts +0 -17
- package/types/codegen/LoadedModule.d.ts.map +0 -1
- package/types/codegen/LoadedValidator.d.ts +0 -38
- package/types/codegen/LoadedValidator.d.ts.map +0 -1
- package/types/codegen/Module.d.ts +0 -24
- package/types/codegen/Module.d.ts.map +0 -1
- package/types/codegen/TypeCheckedModule.d.ts +0 -24
- package/types/codegen/TypeCheckedModule.d.ts.map +0 -1
- package/types/codegen/TypeCheckedValidator.d.ts +0 -9
- package/types/codegen/TypeCheckedValidator.d.ts.map +0 -1
- package/types/codegen/TypescriptWriter.d.ts +0 -50
- package/types/codegen/TypescriptWriter.d.ts.map +0 -1
- package/types/codegen/Validator.d.ts +0 -22
- package/types/codegen/Validator.d.ts.map +0 -1
- package/types/codegen/Writer.d.ts +0 -23
- package/types/codegen/Writer.d.ts.map +0 -1
- package/types/context/ContractContext.d.ts +0 -53
- package/types/context/ContractContext.d.ts.map +0 -1
- package/types/context/writeContractContextArtifacts.d.ts +0 -30
- package/types/context/writeContractContextArtifacts.d.ts.map +0 -1
- package/types/lib/Lib.d.ts +0 -41
- package/types/lib/Lib.d.ts.map +0 -1
- package/types/lib/Libg_v0_16.d.ts +0 -256
- package/types/lib/Libg_v0_16.d.ts.map +0 -1
- package/types/lib/index.d.ts +0 -3
- package/types/lib/index.d.ts.map +0 -1
- package/types/lib/load.d.ts +0 -6
- package/types/lib/load.d.ts.map +0 -1
- package/types/runtime/Cast.d.ts +0 -32
- package/types/runtime/Cast.d.ts.map +0 -1
- package/types/runtime/ContractContext.d.ts +0 -23
- package/types/runtime/ContractContext.d.ts.map +0 -1
- package/types/runtime/ContractContextBuilder.d.ts +0 -53
- package/types/runtime/ContractContextBuilder.d.ts.map +0 -1
- package/types/runtime/DagCompiler.d.ts +0 -64
- package/types/runtime/DagCompiler.d.ts.map +0 -1
- package/types/runtime/PermissiveType.d.ts +0 -3
- package/types/runtime/PermissiveType.d.ts.map +0 -1
- package/types/runtime/StrictType.d.ts +0 -3
- package/types/runtime/StrictType.d.ts.map +0 -1
- package/types/runtime/index.d.ts +0 -2
- package/types/runtime/index.d.ts.map +0 -1
|
@@ -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
|
-
|
|
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
|
-
|
|
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,47 @@
|
|
|
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 === "login") {
|
|
11
|
+
if (args.some((arg) => arg !== "--no-browser"))
|
|
12
|
+
throw new Error("Usage: helios login [--no-browser]")
|
|
13
|
+
const { login } = await import("./cli/login.mjs")
|
|
14
|
+
const abort = new AbortController()
|
|
15
|
+
const cancel = () => abort.abort(new Error("Login cancelled"))
|
|
16
|
+
process.once("SIGINT", cancel)
|
|
17
|
+
process.once("SIGTERM", cancel)
|
|
18
|
+
try {
|
|
19
|
+
await login({
|
|
20
|
+
noBrowser: args.includes("--no-browser"),
|
|
21
|
+
signal: AbortSignal.any([
|
|
22
|
+
abort.signal,
|
|
23
|
+
AbortSignal.timeout(600000)
|
|
24
|
+
])
|
|
25
|
+
})
|
|
26
|
+
} finally {
|
|
27
|
+
process.removeListener("SIGINT", cancel)
|
|
28
|
+
process.removeListener("SIGTERM", cancel)
|
|
29
|
+
}
|
|
30
|
+
} else if (command === "--version" || command === "-v") {
|
|
31
|
+
console.log(
|
|
32
|
+
JSON.parse(
|
|
33
|
+
await readFile(
|
|
34
|
+
new URL("../package.json", import.meta.url),
|
|
35
|
+
"utf8"
|
|
36
|
+
)
|
|
37
|
+
).version
|
|
38
|
+
)
|
|
39
|
+
} else if (!command || ["--help", "-h", "help"].includes(command)) {
|
|
40
|
+
console.log(
|
|
41
|
+
"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 --version"
|
|
42
|
+
)
|
|
43
|
+
} else throw new Error(`Unknown command: ${command}. Run helios --help.`)
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error(error.message)
|
|
46
|
+
process.exitCode = 1
|
|
47
|
+
}
|
package/src/hl2ts.js
CHANGED
|
@@ -1,186 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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,
|
|
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,
|
|
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,4 @@
|
|
|
1
|
+
export function configPath(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv, home?: string): string;
|
|
2
|
+
export function readConfig(path?: string): Promise<any>;
|
|
3
|
+
export function installProjects(wallet: any, projects: any, endpoint: any, path?: string): Promise<string>;
|
|
4
|
+
//# sourceMappingURL=config.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../src/cli/config.mjs"],"names":[],"mappings":"AAiDA,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
|
|
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":"
|
|
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
package/types/hl2ts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hl2ts.d.ts","sourceRoot":"","sources":["../src/hl2ts.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hl2ts.d.ts","sourceRoot":"","sources":["../src/hl2ts.js"],"names":[],"mappings":""}
|
package/types/index.d.ts
CHANGED
|
@@ -144,6 +144,7 @@ export type UserFunc<ArgsT extends {
|
|
|
144
144
|
profile: (namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined) => CekResult;
|
|
145
145
|
};
|
|
146
146
|
export type LoadedModule = {
|
|
147
|
+
$debugger?: DebuggerContext;
|
|
147
148
|
$name: string;
|
|
148
149
|
$purpose: "module";
|
|
149
150
|
$sourceCode: string;
|
|
@@ -159,6 +160,7 @@ export type LoadedModule = {
|
|
|
159
160
|
* * 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
|
|
160
161
|
*/
|
|
161
162
|
export type LoadedValidator = {
|
|
163
|
+
$debugger?: DebuggerContext;
|
|
162
164
|
$name: string;
|
|
163
165
|
$sourceCode: string;
|
|
164
166
|
$dependencies: ReadonlyArray<LoadedModule>;
|
|
@@ -234,7 +236,9 @@ export type ContractContext<Vs extends {
|
|
|
234
236
|
[name: string]: LoadedModule;
|
|
235
237
|
} = {
|
|
236
238
|
[name: string]: LoadedModule;
|
|
237
|
-
}> = { [K in keyof Vs]: ContractValidatorContexts<Vs[K]>; } & { [K in keyof Ms]: ContractModuleContexts<Ms[K]>; }
|
|
239
|
+
}> = { [K in keyof Vs]: ContractValidatorContexts<Vs[K]>; } & { [K in keyof Ms]: ContractModuleContexts<Ms[K]>; } & {
|
|
240
|
+
$debugger?: DebuggerContext;
|
|
241
|
+
};
|
|
238
242
|
/**
|
|
239
243
|
* if `debug` is true, the ir is included where possible
|
|
240
244
|
*/
|
|
@@ -275,6 +279,19 @@ export type WriteContractContextArtifactsOptions = {
|
|
|
275
279
|
outDir: string;
|
|
276
280
|
fs: FileSystem;
|
|
277
281
|
};
|
|
282
|
+
/**
|
|
283
|
+
* Metadata carried outside script CBOR/hashes for automatic failed-transaction capture.
|
|
284
|
+
*/
|
|
285
|
+
export type DebuggerContext = {
|
|
286
|
+
projectId: string;
|
|
287
|
+
name: string;
|
|
288
|
+
apiKey: string;
|
|
289
|
+
endpoint: string;
|
|
290
|
+
sources?: Record<string, string>;
|
|
291
|
+
};
|
|
292
|
+
export type DebuggerUplcProgram = UplcProgram & {
|
|
293
|
+
$debugger?: DebuggerContext;
|
|
294
|
+
};
|
|
278
295
|
import type { TypeSchema } from "@helios-lang/type-utils";
|
|
279
296
|
import type { UplcData } from "@helios-lang/uplc";
|
|
280
297
|
import type { PlutusVersion } from "@helios-lang/uplc";
|