-
Notifications
You must be signed in to change notification settings - Fork 4
remove node types and bun types from workflows #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ernest-nowacki
wants to merge
19
commits into
main
Choose a base branch
from
feat/no-node-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,766
−49
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
85c9cf4
remove node types and bun types from workflows
ernest-nowacki a94277d
Update comment
ernest-nowacki e62a01f
Expose console types through global and add examples that serve as te…
ernest-nowacki 227700f
Add node modules restrictions
ernest-nowacki a776610
Add more restricted node APIs
ernest-nowacki 1e8ca6a
Expose more apis through runtime
ernest-nowacki 87fa5a8
TS fixes
ernest-nowacki afd1270
Fix prepare runtime
ernest-nowacki 8352563
Add links to the docs
ernest-nowacki f55557d
Update versions
ernest-nowacki d809ee7
Add node modules examples
ernest-nowacki 8934ae7
Add documentation around workflow validation
ernest-nowacki 504996a
Add tests and fixed bug caught up by the test
ernest-nowacki c8a8218
Merge branch 'main' of github.com:smartcontractkit/cre-sdk-typescript…
ernest-nowacki 28414a3
Set version for alpha
ernest-nowacki e742d67
Restore 1.1.3 version
ernest-nowacki ccc00e3
Simplify error messages
ernest-nowacki 3a1136d
Alpha release 2
ernest-nowacki f4cf527
Restore correct versions
ernest-nowacki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * This example shows how CRE workflows mark restricted APIs as deprecated in TS. | ||
| * | ||
| * The restricted APIs covered in this example are: | ||
| * - fetch | ||
| * - setTimeout | ||
| * - setInterval | ||
| * | ||
| * Other unsupported globals/modules are enforced by cre-compile runtime checks. | ||
| * There are also NodeJS APIs that do work with the QuickJS runtime, like console.log. | ||
| */ | ||
|
|
||
| export const testFetch = async () => { | ||
| // @ts-expect-error - fetch is not available in the CRE SDK | ||
| fetch('https://api.chain.link/v1/price?symbol=ETH/USD') | ||
| } | ||
|
|
||
| export const testSetTimeout = async () => { | ||
| // @ts-expect-error - setTimeout is not available in the CRE SDK | ||
| setTimeout(() => { | ||
| console.log('Hello, world!') | ||
| }, 1000) | ||
| } | ||
|
|
||
| export const testSetInterval = async () => { | ||
| // @ts-expect-error - setInterval is not available in the CRE SDK | ||
| setInterval(() => { | ||
| console.log('Hello, world!') | ||
| }, 1000) | ||
| } |
132 changes: 132 additions & 0 deletions
132
packages/cre-sdk-examples/src/restricted-node-modules-example.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /** | ||
| * This example shows how CRE workflows mark restricted Node.js modules as `never` in TS. | ||
| * | ||
| * CRE workflows run on QuickJS (via Javy/WASM), not full Node.js. | ||
| * All exports from restricted modules are typed as `never`, so any usage | ||
| * produces a clear TypeScript error at the call site. | ||
| * | ||
| * The restricted modules covered in this example are: | ||
| * - node:crypto | ||
| * - node:fs | ||
| * - node:fs/promises | ||
| * - node:net | ||
| * - node:http | ||
| * - node:https | ||
| * - node:child_process | ||
| * - node:os | ||
| * - node:stream | ||
| * - node:worker_threads | ||
| * - node:dns | ||
| * - node:zlib | ||
| * | ||
| * For HTTP requests, use cre.capabilities.HTTPClient instead of node:http/node:https/node:net. | ||
| * | ||
| * @see https://docs.chain.link/cre/concepts/typescript-wasm-runtime | ||
| */ | ||
|
|
||
| import { exec } from 'node:child_process' | ||
| import { createHash, randomBytes } from 'node:crypto' | ||
| import { lookup } from 'node:dns' | ||
| import { readFileSync } from 'node:fs' | ||
| import { readFile } from 'node:fs/promises' | ||
| import { request as httpRequest } from 'node:http' | ||
| import { request as httpsRequest } from 'node:https' | ||
| import { createConnection } from 'node:net' | ||
| import { cpus, hostname } from 'node:os' | ||
| import { Readable } from 'node:stream' | ||
| import { Worker } from 'node:worker_threads' | ||
| import { createGzip } from 'node:zlib' | ||
|
|
||
| // --- node:crypto --- | ||
|
|
||
| export const testCryptoRandomBytes = () => { | ||
| // @ts-expect-error - node:crypto is not available in CRE WASM workflows | ||
| randomBytes(32) | ||
| } | ||
|
|
||
| export const testCryptoCreateHash = () => { | ||
| // @ts-expect-error - node:crypto is not available in CRE WASM workflows | ||
| createHash('sha256') | ||
| } | ||
|
|
||
| // --- node:fs --- | ||
|
|
||
| export const testFsReadFileSync = () => { | ||
| // @ts-expect-error - node:fs is not available in CRE WASM workflows | ||
| readFileSync('/etc/passwd', 'utf-8') | ||
| } | ||
|
|
||
| // --- node:fs/promises --- | ||
|
|
||
| export const testFsPromisesReadFile = async () => { | ||
| // @ts-expect-error - node:fs/promises is not available in CRE WASM workflows | ||
| await readFile('/etc/passwd', 'utf-8') | ||
| } | ||
|
|
||
| // --- node:net --- | ||
|
|
||
| export const testNetCreateConnection = () => { | ||
| // @ts-expect-error - node:net is not available in CRE WASM workflows | ||
| createConnection({ host: 'localhost', port: 8080 }) | ||
| } | ||
|
|
||
| // --- node:http --- | ||
|
|
||
| export const testHttpRequest = () => { | ||
| // @ts-expect-error - node:http is not available in CRE WASM workflows | ||
| httpRequest('http://example.com') | ||
| } | ||
|
|
||
| // --- node:https --- | ||
|
|
||
| export const testHttpsRequest = () => { | ||
| // @ts-expect-error - node:https is not available in CRE WASM workflows | ||
| httpsRequest('https://example.com') | ||
| } | ||
|
|
||
| // --- node:child_process --- | ||
|
|
||
| export const testChildProcessExec = () => { | ||
| // @ts-expect-error - node:child_process is not available in CRE WASM workflows | ||
| exec('ls -la') | ||
| } | ||
|
|
||
| // --- node:os --- | ||
|
|
||
| export const testOsHostname = () => { | ||
| // @ts-expect-error - node:os is not available in CRE WASM workflows | ||
| hostname() | ||
| } | ||
|
|
||
| export const testOsCpus = () => { | ||
| // @ts-expect-error - node:os is not available in CRE WASM workflows | ||
| cpus() | ||
| } | ||
|
|
||
| // --- node:stream --- | ||
|
|
||
| export const testStreamReadable = () => { | ||
| // @ts-expect-error - node:stream is not available in CRE WASM workflows | ||
| new Readable() | ||
| } | ||
|
|
||
| // --- node:worker_threads --- | ||
|
|
||
| export const testWorkerThreads = () => { | ||
| // @ts-expect-error - node:worker_threads is not available in CRE WASM workflows | ||
| new Worker('./worker.js') | ||
| } | ||
|
|
||
| // --- node:dns --- | ||
|
|
||
| export const testDnsLookup = () => { | ||
| // @ts-expect-error - node:dns is not available in CRE WASM workflows | ||
| lookup('example.com', () => {}) | ||
| } | ||
|
|
||
| // --- node:zlib --- | ||
|
|
||
| export const testZlibCreateGzip = () => { | ||
| // @ts-expect-error - node:zlib is not available in CRE WASM workflows | ||
| createGzip() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's ensure we don't break existing workflows. TextDecoder still needs to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just "extra" cleanup in my example as using
textshall be more convenient for the users.TextDecoderdoes in fact still work and you can still use the previous notation if you prefer.