@chainlink/cre-sdk 1.5.0-alpha.1 → 1.5.0-alpha.2
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 +1 -12
- package/bin/cre-compile.ts +19 -15
- package/dist/generated/capabilities/blockchain/evm/v1alpha/client_pb.js +1 -1
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +0 -24
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +0 -24
- package/dist/index.d.ts +0 -3
- package/dist/sdk/types/global.d.ts +2 -146
- package/dist/sdk/types/restricted-apis.d.ts +23 -18
- package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.d.ts +3 -40
- package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.js +6 -80
- package/dist/sdk/utils/prepare-runtime.d.ts +1 -1
- package/dist/sdk/utils/prepare-runtime.js +2 -9
- package/dist/sdk/wasm/host-bindings.d.ts +4 -4
- package/package.json +4 -4
- package/scripts/run.ts +1 -7
- package/scripts/src/build-types.ts +1 -31
- package/scripts/src/compile-to-js.ts +6 -5
- package/scripts/src/compile-to-wasm.ts +34 -35
- package/scripts/src/compile-workflow.ts +29 -18
- package/dist/sdk/types/restricted-node-modules.d.ts +0 -462
- package/scripts/src/validate-workflow-runtime-compat.test.ts +0 -433
- package/scripts/src/validate-workflow-runtime-compat.ts +0 -631
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainlink/cre-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "v1.5.0-alpha.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"compile:workflow": "bun scripts/run.ts compile-workflow",
|
|
48
48
|
"fix-imports": "bun scripts/run.ts fix-imports",
|
|
49
49
|
"format": "biome format --write ${BIOME_PATHS:-.}",
|
|
50
|
-
"full-checks": "bun generate:sdk && bun
|
|
50
|
+
"full-checks": "bun generate:sdk && bun build && bun typecheck && bun check && bun test && bun test:standard",
|
|
51
51
|
"generate:chain-selectors": "bun scripts/run.ts generate-chain-selectors && BIOME_PATHS=\"src/generated\" bun check",
|
|
52
52
|
"generate:proto": "bunx @bufbuild/buf generate && BIOME_PATHS=\"src/generated\" bun check",
|
|
53
53
|
"generate:sdk": "bun generate:proto && bun generate:chain-selectors && bun scripts/run generate-sdks && BIOME_PATHS=\"src/generated src/generated-sdk src/sdk/test/generated\" bun check",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@bufbuild/protobuf": "2.6.3",
|
|
62
62
|
"@bufbuild/protoc-gen-es": "2.6.3",
|
|
63
|
-
"@chainlink/cre-sdk-javy-plugin": "
|
|
63
|
+
"@chainlink/cre-sdk-javy-plugin": "v1.5.0-alpha.2",
|
|
64
64
|
"@standard-schema/spec": "1.0.0",
|
|
65
65
|
"viem": "2.34.0",
|
|
66
66
|
"zod": "3.25.76"
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@biomejs/biome": "2.3.14",
|
|
70
70
|
"@bufbuild/buf": "1.56.0",
|
|
71
71
|
"@types/bun": "1.3.8",
|
|
72
|
-
"chain-selectors": "https://github.com/smartcontractkit/chain-selectors.git#
|
|
72
|
+
"chain-selectors": "https://github.com/smartcontractkit/chain-selectors.git#8b963095ae797a3024c8e55822cced7bf618176f",
|
|
73
73
|
"fast-glob": "3.3.3",
|
|
74
74
|
"ts-proto": "2.7.5",
|
|
75
75
|
"typescript": "5.9.3",
|
package/scripts/run.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
|
-
import { WorkflowRuntimeCompatibilityError } from './src/validate-workflow-runtime-compat'
|
|
4
|
-
|
|
5
3
|
const availableScripts = [
|
|
6
4
|
'build-types',
|
|
7
5
|
'compile-to-js',
|
|
@@ -39,11 +37,7 @@ const main = async () => {
|
|
|
39
37
|
process.exit(1)
|
|
40
38
|
}
|
|
41
39
|
} catch (error) {
|
|
42
|
-
|
|
43
|
-
console.error(`\n❌ ${error.message}`)
|
|
44
|
-
} else {
|
|
45
|
-
console.error(`Failed to run script ${scriptName}:`, error)
|
|
46
|
-
}
|
|
40
|
+
console.error(`Failed to load script ${scriptName}:`, error)
|
|
47
41
|
process.exit(1)
|
|
48
42
|
}
|
|
49
43
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { glob } from 'fast-glob'
|
|
2
|
-
import { copyFile, mkdir
|
|
2
|
+
import { copyFile, mkdir } from 'fs/promises'
|
|
3
3
|
import { join } from 'path'
|
|
4
4
|
|
|
5
5
|
const buildTypes = async () => {
|
|
@@ -28,36 +28,6 @@ const buildTypes = async () => {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
console.log(`✅ Copied ${typeFiles.length} type definition file(s) to dist/sdk/types`)
|
|
31
|
-
|
|
32
|
-
// Prepend triple-slash references to dist/index.d.ts so consumers pick up
|
|
33
|
-
// global type augmentations (e.g. restricted-apis.d.ts) automatically.
|
|
34
|
-
// tsc strips these from the emitted .d.ts, so we add them back here.
|
|
35
|
-
const indexDts = join(packageRoot, 'dist/index.d.ts')
|
|
36
|
-
const sourceIndex = join(packageRoot, 'src/index.ts')
|
|
37
|
-
const sourceContent = await readFile(sourceIndex, 'utf-8')
|
|
38
|
-
|
|
39
|
-
const refsFromSource = sourceContent
|
|
40
|
-
.split('\n')
|
|
41
|
-
.filter((line) => line.startsWith('/// <reference types='))
|
|
42
|
-
|
|
43
|
-
// Add references for consumer-only type declarations that cannot be in src/index.ts
|
|
44
|
-
// because they would break the SDK's own scripts/tests (which legitimately use Node.js APIs).
|
|
45
|
-
const consumerOnlyRefs = ['/// <reference types="./sdk/types/restricted-node-modules" />']
|
|
46
|
-
|
|
47
|
-
const tripleSlashRefs = [...refsFromSource, ...consumerOnlyRefs].join('\n')
|
|
48
|
-
|
|
49
|
-
if (tripleSlashRefs) {
|
|
50
|
-
const indexContent = await readFile(indexDts, 'utf-8')
|
|
51
|
-
// Strip any existing triple-slash references from the top of the file
|
|
52
|
-
// so that re-running build-types is idempotent.
|
|
53
|
-
const withoutExistingRefs = indexContent
|
|
54
|
-
.split('\n')
|
|
55
|
-
.filter((line) => !line.trim().startsWith('/// <reference types='))
|
|
56
|
-
.join('\n')
|
|
57
|
-
.replace(/^\n+/, '') // trim leading blank lines left after stripping
|
|
58
|
-
await writeFile(indexDts, `${tripleSlashRefs}\n${withoutExistingRefs}`)
|
|
59
|
-
console.log('✅ Added triple-slash references to dist/index.d.ts')
|
|
60
|
-
}
|
|
61
31
|
}
|
|
62
32
|
|
|
63
33
|
export const main = buildTypes
|
|
@@ -2,7 +2,6 @@ import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
|
2
2
|
import { mkdir } from 'node:fs/promises'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import { $ } from 'bun'
|
|
5
|
-
import { assertWorkflowRuntimeCompatibility } from './validate-workflow-runtime-compat'
|
|
6
5
|
import { wrapWorkflowCode } from './workflow-wrapper'
|
|
7
6
|
|
|
8
7
|
export const main = async (tsFilePath?: string, outputFilePath?: string) => {
|
|
@@ -20,7 +19,6 @@ export const main = async (tsFilePath?: string, outputFilePath?: string) => {
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
const resolvedInput = path.resolve(inputPath)
|
|
23
|
-
assertWorkflowRuntimeCompatibility(resolvedInput)
|
|
24
22
|
console.info(`📁 Using input file: ${resolvedInput}`)
|
|
25
23
|
|
|
26
24
|
// If no explicit output path → same dir, swap extension to .js
|
|
@@ -56,13 +54,16 @@ export const main = async (tsFilePath?: string, outputFilePath?: string) => {
|
|
|
56
54
|
naming: path.basename(resolvedOutput),
|
|
57
55
|
})
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
// The file Bun will emit before bundling
|
|
58
|
+
const builtFile = path.join(path.dirname(resolvedOutput), path.basename(resolvedOutput))
|
|
59
|
+
|
|
60
|
+
if (!existsSync(builtFile)) {
|
|
61
|
+
console.error(`❌ Expected file not found: ${builtFile}`)
|
|
61
62
|
process.exit(1)
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
// Bundle into the final file (overwrite)
|
|
65
|
-
await $`bun build ${
|
|
66
|
+
await $`bun build ${builtFile} --bundle --outfile=${resolvedOutput}`
|
|
66
67
|
|
|
67
68
|
console.info(`✅ Built: ${resolvedOutput}`)
|
|
68
69
|
return resolvedOutput
|
|
@@ -1,38 +1,34 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process'
|
|
2
1
|
import { existsSync } from 'node:fs'
|
|
3
2
|
import { mkdir } from 'node:fs/promises'
|
|
4
3
|
import path from 'node:path'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
const child = spawn('bun', args, {
|
|
9
|
-
stdio: 'inherit',
|
|
10
|
-
env: process.env,
|
|
11
|
-
})
|
|
12
|
-
child.on('error', reject)
|
|
13
|
-
child.on('exit', (code) => {
|
|
14
|
-
if (code === 0) resolve()
|
|
15
|
-
else reject(new Error(`bun exited with code ${code ?? 'unknown'}`))
|
|
16
|
-
})
|
|
17
|
-
})
|
|
18
|
-
}
|
|
4
|
+
import { $ } from 'bun'
|
|
5
|
+
import { parseCompileFlags } from '../../../cre-sdk-javy-plugin/scripts/parse-compile-flags'
|
|
19
6
|
|
|
20
7
|
const isJsFile = (p: string) => ['.js', '.mjs', '.cjs'].includes(path.extname(p).toLowerCase())
|
|
21
8
|
|
|
22
|
-
export const main = async (
|
|
9
|
+
export const main = async (
|
|
10
|
+
inputFile?: string,
|
|
11
|
+
outputFile?: string,
|
|
12
|
+
creExportsPaths?: string[],
|
|
13
|
+
pluginPath?: string | null,
|
|
14
|
+
) => {
|
|
23
15
|
const cliArgs = process.argv.slice(3)
|
|
16
|
+
const { creExports: cliCreExports, plugin: cliPlugin, rest: cliRest } = parseCompileFlags(cliArgs)
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const
|
|
18
|
+
const inputPath = inputFile ?? cliRest[0]
|
|
19
|
+
const outputPathArg = outputFile ?? cliRest[1]
|
|
20
|
+
const creExports = creExportsPaths ?? cliCreExports
|
|
21
|
+
const plugin = pluginPath !== undefined ? pluginPath : cliPlugin
|
|
22
|
+
|
|
23
|
+
if (plugin !== null && plugin !== undefined && creExports.length > 0) {
|
|
24
|
+
console.error('❌ Error: --plugin and --cre-exports are mutually exclusive.')
|
|
25
|
+
process.exit(1)
|
|
26
|
+
}
|
|
28
27
|
|
|
29
28
|
if (!inputPath) {
|
|
30
29
|
console.error(
|
|
31
30
|
'Usage: bun compile:js-to-wasm <path/to/input.(js|mjs|cjs)> [path/to/output.wasm]',
|
|
32
31
|
)
|
|
33
|
-
console.error('Examples:')
|
|
34
|
-
console.error(' bun compile:js-to-wasm ./build/workflows/test.js')
|
|
35
|
-
console.error(' bun compile:js-to-wasm ./build/workflows/test.mjs ./artifacts/test.wasm')
|
|
36
32
|
process.exit(1)
|
|
37
33
|
}
|
|
38
34
|
|
|
@@ -47,31 +43,34 @@ export const main = async (inputFile?: string, outputFile?: string) => {
|
|
|
47
43
|
process.exit(1)
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
// Default output = same dir, same basename, .wasm extension
|
|
51
46
|
const defaultOut = path.join(
|
|
52
47
|
path.dirname(resolvedInput),
|
|
53
48
|
path.basename(resolvedInput).replace(/\.(m|c)?js$/i, '.wasm'),
|
|
54
49
|
)
|
|
55
50
|
const resolvedOutput = outputPathArg ? path.resolve(outputPathArg) : defaultOut
|
|
56
51
|
|
|
57
|
-
// Ensure output directory exists
|
|
58
52
|
await mkdir(path.dirname(resolvedOutput), { recursive: true })
|
|
59
53
|
|
|
60
|
-
console.info(
|
|
54
|
+
console.info('🔨 Compiling to WASM')
|
|
61
55
|
console.info(`📁 Input: ${resolvedInput}`)
|
|
62
56
|
console.info(`🎯 Output: ${resolvedOutput}`)
|
|
63
57
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const compilerPath = path.resolve(
|
|
68
|
-
scriptDir,
|
|
69
|
-
'../../../cre-sdk-javy-plugin/bin/compile-workflow.ts',
|
|
70
|
-
)
|
|
71
|
-
if (existsSync(compilerPath)) {
|
|
72
|
-
await runBun(['--bun', compilerPath, resolvedInput, resolvedOutput])
|
|
58
|
+
const compileArgs: string[] = []
|
|
59
|
+
if (plugin != null && plugin !== '') {
|
|
60
|
+
compileArgs.push('--plugin', path.resolve(plugin))
|
|
73
61
|
} else {
|
|
74
|
-
|
|
62
|
+
compileArgs.push(...creExports.flatMap((p) => ['--cre-exports', path.resolve(p)]))
|
|
63
|
+
}
|
|
64
|
+
compileArgs.push(resolvedInput, resolvedOutput)
|
|
65
|
+
try {
|
|
66
|
+
await $`bun cre-compile-workflow ${compileArgs}`
|
|
67
|
+
} catch {
|
|
68
|
+
const scriptDir = import.meta.dir
|
|
69
|
+
const compilerPath = path.resolve(
|
|
70
|
+
scriptDir,
|
|
71
|
+
'../../../cre-sdk-javy-plugin/bin/compile-workflow.ts',
|
|
72
|
+
)
|
|
73
|
+
await $`bun --bun ${compilerPath} ${compileArgs}`
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
console.info(`✅ Compiled: ${resolvedOutput}`)
|
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
2
|
import { mkdir } from 'node:fs/promises'
|
|
3
3
|
import path from 'node:path'
|
|
4
|
+
import { parseCompileFlags } from '../../../cre-sdk-javy-plugin/scripts/parse-compile-flags'
|
|
4
5
|
import { main as compileToJs } from './compile-to-js'
|
|
5
6
|
import { main as compileToWasm } from './compile-to-wasm'
|
|
6
7
|
|
|
7
|
-
export const main = async (
|
|
8
|
+
export const main = async (
|
|
9
|
+
inputFile?: string,
|
|
10
|
+
outputWasmFile?: string,
|
|
11
|
+
creExportsPaths?: string[],
|
|
12
|
+
pluginPath?: string | null,
|
|
13
|
+
) => {
|
|
8
14
|
const cliArgs = process.argv.slice(3)
|
|
15
|
+
const { creExports: cliCreExports, plugin: cliPlugin, rest: cliRest } = parseCompileFlags(cliArgs)
|
|
9
16
|
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
17
|
+
const inputPath = inputFile ?? cliRest[0]
|
|
18
|
+
const outputPathArg = outputWasmFile ?? cliRest[1]
|
|
19
|
+
const creExports = creExportsPaths ?? cliCreExports
|
|
20
|
+
const plugin = pluginPath !== undefined ? pluginPath : cliPlugin
|
|
21
|
+
|
|
22
|
+
if (plugin != null && plugin !== '' && creExports.length > 0) {
|
|
23
|
+
console.error('❌ Error: --plugin and --cre-exports are mutually exclusive.')
|
|
24
|
+
process.exit(1)
|
|
25
|
+
}
|
|
13
26
|
|
|
14
27
|
if (!inputPath) {
|
|
15
28
|
console.error('Usage: bun compile:workflow <path/to/workflow.ts> [path/to/output.wasm]')
|
|
16
|
-
console.error('Examples:')
|
|
17
|
-
console.error(' bun compile:workflow src/standard_tests/secrets/test.ts')
|
|
18
|
-
console.error(
|
|
19
|
-
' bun compile:workflow src/standard_tests/secrets/test.ts .temp/standard_tests/secrets/test.wasm',
|
|
20
|
-
)
|
|
21
29
|
process.exit(1)
|
|
22
30
|
}
|
|
23
31
|
|
|
@@ -27,30 +35,33 @@ export const main = async (inputFile?: string, outputWasmFile?: string) => {
|
|
|
27
35
|
process.exit(1)
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
// Default final output = same dir, same basename, .wasm
|
|
31
38
|
const defaultWasmOut = path.join(
|
|
32
39
|
path.dirname(resolvedInput),
|
|
33
40
|
path.basename(resolvedInput).replace(/\.[^.]+$/, '.wasm'),
|
|
34
41
|
)
|
|
35
42
|
const resolvedWasmOutput = outputPathArg ? path.resolve(outputPathArg) : defaultWasmOut
|
|
36
|
-
|
|
37
|
-
// Put the intermediate JS next to the final wasm (so custom outputs stay together)
|
|
38
43
|
const resolvedJsOutput = resolvedWasmOutput.replace(/\.wasm$/i, '.js')
|
|
39
44
|
|
|
40
|
-
// Ensure directories exist (handles both intermediate JS dir and wasm dir)
|
|
41
45
|
await mkdir(path.dirname(resolvedJsOutput), { recursive: true })
|
|
42
46
|
|
|
43
|
-
console.info(
|
|
44
|
-
console.info(`📁 Input: ${resolvedInput}
|
|
47
|
+
console.info('🚀 Compiling workflow')
|
|
48
|
+
console.info(`📁 Input: ${resolvedInput}`)
|
|
49
|
+
console.info(`🧪 JS out: ${resolvedJsOutput}`)
|
|
50
|
+
console.info(`🎯 WASM out:${resolvedWasmOutput}\n`)
|
|
45
51
|
|
|
46
|
-
// Step 1: TS/JS → JS (bundled)
|
|
47
52
|
console.info('📦 Step 1: Compiling JS...')
|
|
48
53
|
await compileToJs(resolvedInput, resolvedJsOutput)
|
|
49
54
|
|
|
50
|
-
// Step 2: JS → WASM
|
|
51
55
|
console.info('\n🔨 Step 2: Compiling to WASM...')
|
|
52
|
-
await compileToWasm(resolvedJsOutput, resolvedWasmOutput)
|
|
56
|
+
await compileToWasm(resolvedJsOutput, resolvedWasmOutput, creExports, plugin)
|
|
53
57
|
|
|
54
58
|
console.info(`\n✅ Workflow built: ${resolvedWasmOutput}`)
|
|
55
59
|
return resolvedWasmOutput
|
|
56
60
|
}
|
|
61
|
+
|
|
62
|
+
if (import.meta.main) {
|
|
63
|
+
main().catch((e) => {
|
|
64
|
+
console.error(e)
|
|
65
|
+
process.exit(1)
|
|
66
|
+
})
|
|
67
|
+
}
|