@chainlink/cre-sdk 1.1.1 → 1.1.3-alpha.1
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 +12 -1
- 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 +3 -0
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/sdk/test/evm-contract-mock.d.ts +68 -0
- package/dist/sdk/test/evm-contract-mock.js +114 -0
- package/dist/sdk/test/index.d.ts +1 -0
- package/dist/sdk/test/index.js +1 -0
- package/dist/sdk/types/global.d.ts +105 -2
- package/dist/sdk/types/restricted-apis.d.ts +18 -23
- package/dist/sdk/types/restricted-node-modules.d.ts +405 -0
- package/dist/sdk/utils/prepare-runtime.d.ts +1 -1
- package/dist/sdk/utils/prepare-runtime.js +9 -2
- package/package.json +1 -1
- package/scripts/run.ts +5 -1
- package/scripts/src/build-types.ts +31 -1
- package/scripts/src/compile-to-js.ts +2 -0
- package/scripts/src/validate-workflow-runtime-compat.test.ts +412 -0
- package/scripts/src/validate-workflow-runtime-compat.ts +573 -0
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ The Chainlink Runtime Environment (CRE) SDK for TypeScript enables developers to
|
|
|
8
8
|
- [Examples](#examples)
|
|
9
9
|
- [Simulate locally with CRE CLI](#simulate-locally-with-cre-cli)
|
|
10
10
|
- [Installation](#installation)
|
|
11
|
+
- [Runtime Compatibility Constraints](#runtime-compatibility-constraints)
|
|
11
12
|
- [Core Concepts](#core-concepts)
|
|
12
13
|
- [Workflows](#workflows)
|
|
13
14
|
- [Runtime Modes](#runtime-modes)
|
|
@@ -47,10 +48,20 @@ This package must be used along with the [CRE CLI tool](https://github.com/smart
|
|
|
47
48
|
|
|
48
49
|
## Prerequisites
|
|
49
50
|
|
|
50
|
-
1. the [bun runtime](https://bun.com/)
|
|
51
|
+
1. the [bun runtime](https://bun.com/) for local tooling and workflow compilation.
|
|
51
52
|
|
|
52
53
|
2. the [CRE CLI tool](https://github.com/smartcontractkit/cre-cli) installed.
|
|
53
54
|
|
|
55
|
+
## Runtime Compatibility Constraints
|
|
56
|
+
|
|
57
|
+
CRE workflows are compiled to WASM and executed through Javy (QuickJS). This is **not** a full Node.js runtime.
|
|
58
|
+
|
|
59
|
+
- Node built-ins like `node:fs`, `node:crypto`, `node:http`, `node:net`, etc. are not supported in workflows.
|
|
60
|
+
- Browser globals like `fetch`, `window`, and `setTimeout` are also not available in workflow runtime.
|
|
61
|
+
- `cre compile:workflow` / `cre-compile` now validates workflow source and fails fast when unsupported APIs are used.
|
|
62
|
+
|
|
63
|
+
Use CRE capabilities (for example, `cre.capabilities.HTTPClient`) instead of direct Node/browser APIs.
|
|
64
|
+
|
|
54
65
|
## Getting Started
|
|
55
66
|
|
|
56
67
|
We recommend you consult the [getting started docs](https://docs.chain.link/cre/getting-started/cli-installation) and install the CRE CLI.
|
|
@@ -10,7 +10,7 @@ import { file_values_v1_values } from '../../../../values/v1/values_pb';
|
|
|
10
10
|
*/
|
|
11
11
|
export const file_capabilities_blockchain_evm_v1alpha_client =
|
|
12
12
|
/*@__PURE__*/
|
|
13
|
-
fileDesc('
|
|
13
|
+
fileDesc('CjBjYXBhYmlsaXRpZXMvYmxvY2tjaGFpbi9ldm0vdjFhbHBoYS9jbGllbnQucHJvdG8SI2NhcGFiaWxpdGllcy5ibG9ja2NoYWluLmV2bS52MWFscGhhIh0KC1RvcGljVmFsdWVzEg4KBnZhbHVlcxgBIAMoDCK4AQoXRmlsdGVyTG9nVHJpZ2dlclJlcXVlc3QSEQoJYWRkcmVzc2VzGAEgAygMEkAKBnRvcGljcxgCIAMoCzIwLmNhcGFiaWxpdGllcy5ibG9ja2NoYWluLmV2bS52MWFscGhhLlRvcGljVmFsdWVzEkgKCmNvbmZpZGVuY2UYAyABKA4yNC5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jpWMWFscGhhYgZwcm90bzM', [file_sdk_v1alpha_sdk, file_tools_generator_v1alpha_cre_metadata, file_values_v1_values]);
|
|
14
14
|
/**
|
|
15
15
|
* Describes the message capabilities.blockchain.evm.v1alpha.TopicValues.
|
|
16
16
|
* Use `create(TopicValuesSchema)` to create a new message.
|
|
@@ -43,6 +43,7 @@ export declare class ClientCapability {
|
|
|
43
43
|
readonly 'ethereum-mainnet-base-1': 15971525489660198786n;
|
|
44
44
|
readonly 'ethereum-mainnet-optimism-1': 3734403246176062136n;
|
|
45
45
|
readonly 'ethereum-mainnet-worldchain-1': 2049429975587534727n;
|
|
46
|
+
readonly 'ethereum-mainnet-xlayer-1': 3016212468291539606n;
|
|
46
47
|
readonly 'ethereum-mainnet-zksync-1': 1562403441176082196n;
|
|
47
48
|
readonly 'ethereum-testnet-sepolia': 16015286601757825753n;
|
|
48
49
|
readonly 'ethereum-testnet-sepolia-arbitrum-1': 3478487238524512106n;
|
|
@@ -53,7 +54,9 @@ export declare class ClientCapability {
|
|
|
53
54
|
readonly 'ethereum-testnet-sepolia-zksync-1': 6898391096552792247n;
|
|
54
55
|
readonly 'hyperliquid-testnet': 4286062357653186312n;
|
|
55
56
|
readonly 'ink-testnet-sepolia': 9763904284804119144n;
|
|
57
|
+
readonly 'jovay-mainnet': 1523760397290643893n;
|
|
56
58
|
readonly 'jovay-testnet': 945045181441419236n;
|
|
59
|
+
readonly 'pharos-mainnet': 7801139999541420232n;
|
|
57
60
|
readonly 'plasma-testnet': 3967220077692964309n;
|
|
58
61
|
readonly 'polygon-mainnet': 4051577828743386545n;
|
|
59
62
|
readonly 'polygon-testnet-amoy': 16281711391670634445n;
|
|
@@ -53,6 +53,7 @@ export class ClientCapability {
|
|
|
53
53
|
'ethereum-mainnet-base-1': 15971525489660198786n,
|
|
54
54
|
'ethereum-mainnet-optimism-1': 3734403246176062136n,
|
|
55
55
|
'ethereum-mainnet-worldchain-1': 2049429975587534727n,
|
|
56
|
+
'ethereum-mainnet-xlayer-1': 3016212468291539606n,
|
|
56
57
|
'ethereum-mainnet-zksync-1': 1562403441176082196n,
|
|
57
58
|
'ethereum-testnet-sepolia': 16015286601757825753n,
|
|
58
59
|
'ethereum-testnet-sepolia-arbitrum-1': 3478487238524512106n,
|
|
@@ -63,7 +64,9 @@ export class ClientCapability {
|
|
|
63
64
|
'ethereum-testnet-sepolia-zksync-1': 6898391096552792247n,
|
|
64
65
|
'hyperliquid-testnet': 4286062357653186312n,
|
|
65
66
|
'ink-testnet-sepolia': 9763904284804119144n,
|
|
67
|
+
'jovay-mainnet': 1523760397290643893n,
|
|
66
68
|
'jovay-testnet': 945045181441419236n,
|
|
69
|
+
'pharos-mainnet': 7801139999541420232n,
|
|
67
70
|
'plasma-testnet': 3967220077692964309n,
|
|
68
71
|
'polygon-mainnet': 4051577828743386545n,
|
|
69
72
|
'polygon-testnet-amoy': 16281711391670634445n,
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { GasConfig, WriteReportReply, WriteReportReplyJson } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
2
|
+
import type { ReportResponse } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
+
import { type Abi, type AbiFunction, type Address } from 'viem';
|
|
4
|
+
import type { EvmMock } from './generated';
|
|
5
|
+
type ViewFunction = AbiFunction & {
|
|
6
|
+
stateMutability: 'view' | 'pure';
|
|
7
|
+
};
|
|
8
|
+
type ExtractViewFunctionNames<TAbi extends Abi> = Extract<TAbi[number], ViewFunction>['name'];
|
|
9
|
+
/**
|
|
10
|
+
* Strict version of {@link WriteReportRequest} where `report` and `gasConfig`
|
|
11
|
+
* are guaranteed to be present. Used by mock handlers so tests don't need
|
|
12
|
+
* to check for undefined.
|
|
13
|
+
*/
|
|
14
|
+
export interface WriteReportMockInput {
|
|
15
|
+
receiver: Uint8Array;
|
|
16
|
+
report: ReportResponse;
|
|
17
|
+
gasConfig: GasConfig;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A contract mock returned by {@link addContractMock}.
|
|
21
|
+
*
|
|
22
|
+
* Each view/pure function in the ABI becomes an optional property whose value
|
|
23
|
+
* is a handler function. When set, calls to that function on the mock EVM
|
|
24
|
+
* client are automatically routed, decoded, and re-encoded.
|
|
25
|
+
*
|
|
26
|
+
* A special `writeReport` property handles write-report calls to this
|
|
27
|
+
* contract's address. Its handler receives a {@link WriteReportMockInput}
|
|
28
|
+
* where `report` and `gasConfig` are guaranteed to be present.
|
|
29
|
+
*/
|
|
30
|
+
export type ContractMock<TAbi extends Abi> = {
|
|
31
|
+
[K in ExtractViewFunctionNames<TAbi>]?: (...args: readonly unknown[]) => unknown;
|
|
32
|
+
} & {
|
|
33
|
+
writeReport?: (input: WriteReportMockInput) => WriteReportReply | WriteReportReplyJson;
|
|
34
|
+
};
|
|
35
|
+
export interface AddContractMockOptions<TAbi extends Abi> {
|
|
36
|
+
address: Address;
|
|
37
|
+
abi: TAbi;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Registers a typed contract mock on an {@link EvmMock} instance.
|
|
41
|
+
*
|
|
42
|
+
* This is the TypeScript equivalent of Go's `evmmock.AddContractMock`.
|
|
43
|
+
* It intercepts `callContract` and `writeReport` on the provided mock,
|
|
44
|
+
* routing calls by contract address and ABI method selector.
|
|
45
|
+
*
|
|
46
|
+
* Multiple contracts can be mocked on the same `EvmMock` — each call to
|
|
47
|
+
* `addContractMock` chains with the previous handler.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const evmMock = EvmMock.testInstance(chainSelector);
|
|
52
|
+
*
|
|
53
|
+
* const balanceMock = addContractMock(evmMock, {
|
|
54
|
+
* address: "0x1234...",
|
|
55
|
+
* abi: BalanceReader,
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* balanceMock.getNativeBalances = (addresses) => {
|
|
59
|
+
* return [500000000000000000n];
|
|
60
|
+
* };
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @param evmMock - The `EvmMock` instance to attach to.
|
|
64
|
+
* @param options - Contract address and viem-compatible ABI.
|
|
65
|
+
* @returns A mock object with settable handler properties for each view/pure function.
|
|
66
|
+
*/
|
|
67
|
+
export declare function addContractMock<const TAbi extends Abi>(evmMock: EvmMock, options: AddContractMockOptions<TAbi>): ContractMock<TAbi>;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { decodeFunctionData, encodeFunctionResult, } from 'viem';
|
|
2
|
+
function bytesToHexAddress(bytes) {
|
|
3
|
+
return `0x${Array.from(bytes)
|
|
4
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
5
|
+
.join('')}`.toLowerCase();
|
|
6
|
+
}
|
|
7
|
+
function bytesToHex(bytes) {
|
|
8
|
+
return `0x${Array.from(bytes)
|
|
9
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
10
|
+
.join('')}`;
|
|
11
|
+
}
|
|
12
|
+
function hexToUint8Array(hex) {
|
|
13
|
+
const clean = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
14
|
+
const bytes = new Uint8Array(clean.length / 2);
|
|
15
|
+
for (let i = 0; i < clean.length; i += 2) {
|
|
16
|
+
bytes[i / 2] = Number.parseInt(clean.slice(i, i + 2), 16);
|
|
17
|
+
}
|
|
18
|
+
return bytes;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Registers a typed contract mock on an {@link EvmMock} instance.
|
|
22
|
+
*
|
|
23
|
+
* This is the TypeScript equivalent of Go's `evmmock.AddContractMock`.
|
|
24
|
+
* It intercepts `callContract` and `writeReport` on the provided mock,
|
|
25
|
+
* routing calls by contract address and ABI method selector.
|
|
26
|
+
*
|
|
27
|
+
* Multiple contracts can be mocked on the same `EvmMock` — each call to
|
|
28
|
+
* `addContractMock` chains with the previous handler.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const evmMock = EvmMock.testInstance(chainSelector);
|
|
33
|
+
*
|
|
34
|
+
* const balanceMock = addContractMock(evmMock, {
|
|
35
|
+
* address: "0x1234...",
|
|
36
|
+
* abi: BalanceReader,
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* balanceMock.getNativeBalances = (addresses) => {
|
|
40
|
+
* return [500000000000000000n];
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param evmMock - The `EvmMock` instance to attach to.
|
|
45
|
+
* @param options - Contract address and viem-compatible ABI.
|
|
46
|
+
* @returns A mock object with settable handler properties for each view/pure function.
|
|
47
|
+
*/
|
|
48
|
+
export function addContractMock(evmMock, options) {
|
|
49
|
+
const mock = {};
|
|
50
|
+
const normalizedAddress = options.address.toLowerCase();
|
|
51
|
+
const previousCallContract = evmMock.callContract;
|
|
52
|
+
evmMock.callContract = (req) => {
|
|
53
|
+
const toBytes = req.call?.to;
|
|
54
|
+
if (!toBytes || bytesToHexAddress(toBytes) !== normalizedAddress) {
|
|
55
|
+
if (previousCallContract)
|
|
56
|
+
return previousCallContract(req);
|
|
57
|
+
throw new Error(`addContractMock: no mock registered for address ${toBytes ? bytesToHexAddress(toBytes) : '(empty)'}`);
|
|
58
|
+
}
|
|
59
|
+
const dataBytes = req.call?.data;
|
|
60
|
+
if (!dataBytes || dataBytes.length < 4) {
|
|
61
|
+
throw new Error('addContractMock: call data too short (need at least 4 bytes for selector)');
|
|
62
|
+
}
|
|
63
|
+
const callDataHex = bytesToHex(dataBytes);
|
|
64
|
+
let decoded;
|
|
65
|
+
try {
|
|
66
|
+
decoded = decodeFunctionData({
|
|
67
|
+
abi: options.abi,
|
|
68
|
+
data: callDataHex,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
if (previousCallContract)
|
|
73
|
+
return previousCallContract(req);
|
|
74
|
+
throw new Error(`addContractMock: failed to decode function data for ${options.address}: ${e instanceof Error ? e.message : e}`);
|
|
75
|
+
}
|
|
76
|
+
const handler = mock[decoded.functionName];
|
|
77
|
+
if (typeof handler !== 'function') {
|
|
78
|
+
throw new Error(`addContractMock: no handler set for ${decoded.functionName} on ${options.address}`);
|
|
79
|
+
}
|
|
80
|
+
const result = handler(...(decoded.args ?? []));
|
|
81
|
+
const encoded = encodeFunctionResult({
|
|
82
|
+
abi: options.abi,
|
|
83
|
+
functionName: decoded.functionName,
|
|
84
|
+
result: result,
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
data: hexToUint8Array(encoded),
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const previousWriteReport = evmMock.writeReport;
|
|
91
|
+
evmMock.writeReport = (req) => {
|
|
92
|
+
const receiverBytes = req.receiver;
|
|
93
|
+
if (!receiverBytes || bytesToHexAddress(receiverBytes) !== normalizedAddress) {
|
|
94
|
+
if (previousWriteReport)
|
|
95
|
+
return previousWriteReport(req);
|
|
96
|
+
throw new Error(`addContractMock: no writeReport mock registered for receiver ${receiverBytes ? bytesToHexAddress(receiverBytes) : '(empty)'}`);
|
|
97
|
+
}
|
|
98
|
+
if (typeof mock.writeReport !== 'function') {
|
|
99
|
+
throw new Error(`addContractMock: no writeReport handler set for ${options.address}`);
|
|
100
|
+
}
|
|
101
|
+
if (!req.report) {
|
|
102
|
+
throw new Error(`addContractMock: writeReport called without report for ${options.address}`);
|
|
103
|
+
}
|
|
104
|
+
if (!req.gasConfig) {
|
|
105
|
+
throw new Error(`addContractMock: writeReport called without gasConfig for ${options.address}`);
|
|
106
|
+
}
|
|
107
|
+
return mock.writeReport({
|
|
108
|
+
receiver: req.receiver,
|
|
109
|
+
report: req.report,
|
|
110
|
+
gasConfig: req.gasConfig,
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
return mock;
|
|
114
|
+
}
|
package/dist/sdk/test/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { type CapabilityHandler, DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, type NewTestRuntimeOptions, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, type Secrets, TestRuntime, type TestRuntimeState, test, } from '../testutils/test-runtime';
|
|
6
6
|
export { TestWriter } from '../testutils/test-writer';
|
|
7
|
+
export { type AddContractMockOptions, addContractMock, type ContractMock, type WriteReportMockInput, } from './evm-contract-mock';
|
|
7
8
|
export * from './generated';
|
package/dist/sdk/test/index.js
CHANGED
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, TestRuntime, test, } from '../testutils/test-runtime';
|
|
6
6
|
export { TestWriter } from '../testutils/test-writer';
|
|
7
|
+
export { addContractMock, } from './evm-contract-mock';
|
|
7
8
|
export * from './generated';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
// Global type declarations for the CRE SDK runtime
|
|
2
|
-
//
|
|
1
|
+
// Global type declarations for the CRE SDK runtime.
|
|
2
|
+
// These are the methods and globals exposed by the Host to the Guest.
|
|
3
|
+
|
|
4
|
+
type ExistingGlobal<K extends PropertyKey, Fallback> =
|
|
5
|
+
typeof globalThis extends Record<K, infer T> ? T : Fallback
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Host functions exposed by the CRE runtime to WASM guests
|
|
@@ -78,6 +81,106 @@ declare global {
|
|
|
78
81
|
* @returns Unix timestamp in milliseconds
|
|
79
82
|
*/
|
|
80
83
|
function now(): number
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Console API available in the QuickJS runtime
|
|
87
|
+
*/
|
|
88
|
+
type CreConsole = {
|
|
89
|
+
log(...args: unknown[]): void
|
|
90
|
+
warn(...args: unknown[]): void
|
|
91
|
+
error(...args: unknown[]): void
|
|
92
|
+
info(...args: unknown[]): void
|
|
93
|
+
debug(...args: unknown[]): void
|
|
94
|
+
}
|
|
95
|
+
var console: ExistingGlobal<'console', CreConsole>
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* TextEncoder/TextDecoder APIs available via Javy's text_encoding support
|
|
99
|
+
*/
|
|
100
|
+
interface CreTextEncoderEncodeIntoResult {
|
|
101
|
+
read: number
|
|
102
|
+
written: number
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface CreTextEncoder {
|
|
106
|
+
readonly encoding: string
|
|
107
|
+
encode(input?: string): Uint8Array
|
|
108
|
+
encodeInto(input: string, dest: Uint8Array): CreTextEncoderEncodeIntoResult
|
|
109
|
+
}
|
|
110
|
+
var TextEncoder: ExistingGlobal<
|
|
111
|
+
'TextEncoder',
|
|
112
|
+
{ prototype: CreTextEncoder; new (): CreTextEncoder }
|
|
113
|
+
>
|
|
114
|
+
|
|
115
|
+
interface CreTextDecoder {
|
|
116
|
+
readonly encoding: string
|
|
117
|
+
readonly fatal: boolean
|
|
118
|
+
readonly ignoreBOM: boolean
|
|
119
|
+
decode(input?: ArrayBuffer | ArrayBufferView, options?: { stream?: boolean }): string
|
|
120
|
+
}
|
|
121
|
+
var TextDecoder: ExistingGlobal<
|
|
122
|
+
'TextDecoder',
|
|
123
|
+
{
|
|
124
|
+
prototype: CreTextDecoder
|
|
125
|
+
new (label?: string, options?: { fatal?: boolean; ignoreBOM?: boolean }): CreTextDecoder
|
|
126
|
+
}
|
|
127
|
+
>
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Base64 encoding/decoding — exposed via prepareRuntime() from node:buffer
|
|
131
|
+
*/
|
|
132
|
+
function atob(encodedData: string): string
|
|
133
|
+
function btoa(stringToEncode: string): string
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* URL and URLSearchParams — exposed via prepareRuntime() from node:url
|
|
137
|
+
*/
|
|
138
|
+
interface CreURLSearchParams {
|
|
139
|
+
append(name: string, value: string): void
|
|
140
|
+
delete(name: string): void
|
|
141
|
+
get(name: string): string | null
|
|
142
|
+
getAll(name: string): string[]
|
|
143
|
+
has(name: string): boolean
|
|
144
|
+
set(name: string, value: string): void
|
|
145
|
+
sort(): void
|
|
146
|
+
toString(): string
|
|
147
|
+
forEach(callback: (value: string, key: string, parent: CreURLSearchParams) => void): void
|
|
148
|
+
entries(): IterableIterator<[string, string]>
|
|
149
|
+
keys(): IterableIterator<string>
|
|
150
|
+
values(): IterableIterator<string>
|
|
151
|
+
[Symbol.iterator](): IterableIterator<[string, string]>
|
|
152
|
+
readonly size: number
|
|
153
|
+
}
|
|
154
|
+
var URLSearchParams: ExistingGlobal<
|
|
155
|
+
'URLSearchParams',
|
|
156
|
+
{
|
|
157
|
+
prototype: CreURLSearchParams
|
|
158
|
+
new (
|
|
159
|
+
init?: string | Record<string, string> | [string, string][] | CreURLSearchParams,
|
|
160
|
+
): CreURLSearchParams
|
|
161
|
+
}
|
|
162
|
+
>
|
|
163
|
+
|
|
164
|
+
interface CreURL {
|
|
165
|
+
hash: string
|
|
166
|
+
host: string
|
|
167
|
+
hostname: string
|
|
168
|
+
href: string
|
|
169
|
+
readonly origin: string
|
|
170
|
+
password: string
|
|
171
|
+
pathname: string
|
|
172
|
+
port: string
|
|
173
|
+
protocol: string
|
|
174
|
+
search: string
|
|
175
|
+
readonly searchParams: CreURLSearchParams
|
|
176
|
+
username: string
|
|
177
|
+
toString(): string
|
|
178
|
+
toJSON(): string
|
|
179
|
+
}
|
|
180
|
+
var URL: ExistingGlobal<
|
|
181
|
+
'URL',
|
|
182
|
+
{ prototype: CreURL; new (url: string, base?: string | CreURL): CreURL }
|
|
183
|
+
>
|
|
81
184
|
}
|
|
82
185
|
|
|
83
186
|
export {}
|
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
declare global {
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/** @deprecated setTimeout is not available in CRE WASM workflows. Use cre.capabilities.CronCapability for scheduling. */
|
|
21
|
-
const setTimeout: never
|
|
22
|
-
|
|
23
|
-
/** @deprecated setInterval is not available in CRE WASM workflows. Use cre.capabilities.CronCapability for scheduling. */
|
|
24
|
-
const setInterval: never
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated fetch is not available in CRE WASM workflows.
|
|
4
|
+
* Use cre.capabilities.HTTPClient instead.
|
|
5
|
+
* @see https://docs.chain.link/cre/concepts/typescript-wasm-runtime
|
|
6
|
+
*/
|
|
7
|
+
function fetch(_notAvailable: never): never
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated setTimeout is not available in CRE WASM workflows. Use cre.capabilities.CronCapability for scheduling.
|
|
11
|
+
* @see https://docs.chain.link/cre/concepts/typescript-wasm-runtime
|
|
12
|
+
*/
|
|
13
|
+
function setTimeout(_notAvailable: never, ..._args: never[]): never
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated setInterval is not available in CRE WASM workflows. Use cre.capabilities.CronCapability for scheduling.
|
|
17
|
+
* @see https://docs.chain.link/cre/concepts/typescript-wasm-runtime
|
|
18
|
+
*/
|
|
19
|
+
function setInterval(_notAvailable: never, ..._args: never[]): never
|
|
25
20
|
}
|
|
26
21
|
|
|
27
22
|
export {}
|