### Setting Up and Running an ES4X Project Source: https://github.com/reactiverse/es4x/blob/develop/docs/README.md This snippet provides a quick guide to initialize, install dependencies, and run a new ES4X project using npm or yarn. It outlines the essential commands for getting started with ES4X development. ```bash # (1) create npm init @es4x project # (2) install dependencies npm install # OR yarn # (3) run npm start # OR yarn start ``` -------------------------------- ### Install ES4X Project Dependencies Source: https://github.com/reactiverse/es4x/blob/develop/docs/examples/README.md This command demonstrates how to install the required dependencies for an ES4X project using `npm i`. The output shows the `es4x install` postinstall script being executed, which handles the setup of GraalJS components. A `package-lock.json` is also created. ```bash $ npm i > hello-es4x@1.0.0 postinstall .../hello-world > es4x install npm notice created a lockfile as package-lock.json. You should commit this file. added 2 packages from 1 contributor and audited 2 packages in 6.704s found 0 vulnerabilities ``` -------------------------------- ### Display ES4X CLI Help Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/install.md Shows the help documentation for the globally installed `es4x` command-line interface. This command provides a quick reference to all available commands and their respective options. ```bash es4x --help ``` -------------------------------- ### Install ES4X PostgreSQL Access Dependencies Source: https://github.com/reactiverse/es4x/blob/develop/docs/examples/README.md This command installs the dependencies for the ES4X PostgreSQL application, including `@reactiverse/es4x` and `@vertx/pg-client`. The `npm i` process ensures that all necessary GraalJS components are installed via the `es4x install` postinstall script. ```bash $ npm i > hello-es4x@1.0.0 postinstall .../hello-world > es4x install npm notice created a lockfile as package-lock.json. You should commit this file. added 2 packages from 1 contributor and audited 2 packages in 6.704s found 0 vulnerabilities ``` -------------------------------- ### Display ES4X CLI Help via NPX Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/install.md Executes the `@es4x/create` package as a one-shot operation using `npx` to display its help documentation. This method allows users to access the tool's functionality without requiring a global installation. ```bash npx @es4x/create --help ``` -------------------------------- ### Connect to PostgreSQL with ES4X Source: https://github.com/reactiverse/es4x/blob/develop/docs/pl/examples/README.md This snippet shows how to configure an ES4X project to interact with a PostgreSQL database. It provides the `package.json` setup, the JavaScript code for executing a simple query using Vert.x PG Client, and instructions for dependency installation. ```json { "name": "pg-es4x", "version": "1.0.0", "description": "An ES4X PostgreSQL access example.", "main": "index.js", "scripts": { "start": "es4x", "postinstall": "es4x install" }, "dependencies": { "@reactiverse/es4x": "^0.15.0", "@vertx/pg-client": "^4.0.0" } } ``` ```bash $ npm i > hello-es4x@1.0.0 postinstall .../hello-world > es4x install npm notice created a lockfile as package-lock.json. You should commit this file. added 2 packages from 1 contributor and audited 2 packages in 6.704s found 0 vulnerabilities ``` ```javascript import { Client } from '@vertx/pg-client'; import { Vertx } from '@vertx/core'; const vertx = Vertx.vertx(); const client = Client.create(vertx, { host: 'localhost', port: 5432, database: 'mydb', user: 'user', password: 'password' }); client.query('SELECT NOW() AS current_time').execute(ar => { if (ar.succeeded()) { const result = ar.result(); result.forEach(row => { console.log('Current time from Postgres: ' + row.getString('current_time')); }); } else { console.error('Failure: ' + ar.cause().getMessage()); } client.close(); }); ``` -------------------------------- ### Create a Basic ES4X Hello World Project Source: https://github.com/reactiverse/es4x/blob/develop/docs/pl/examples/README.md This snippet demonstrates how to initialize a new ES4X project, define its dependencies in `package.json`, and write a simple 'Hello ES4X' JavaScript application. It also includes commands to install dependencies and run the application. ```json { "name": "hello-es4x", "version": "1.0.0", "description": "A simple ES4X hello world example.", "main": "index.js", "scripts": { "start": "es4x", "postinstall": "es4x install" }, "dependencies": { "@reactiverse/es4x": "^0.15.0" } } ``` ```bash $ npm i > hello-es4x@1.0.0 postinstall .../hello-world > es4x install npm notice created a lockfile as package-lock.json. You should commit this file. added 2 packages from 1 contributor and audited 2 packages in 6.704s found 0 vulnerabilities ``` ```javascript console.log('Hello ES4X'); ``` ```bash $ npm start > hello-es4x@1.0.0 start .../hello-world > es4x Hello ES4X Succeeded in deploying verticle ``` -------------------------------- ### Install ES4X Web Application Dependencies Source: https://github.com/reactiverse/es4x/blob/develop/docs/examples/README.md This command installs the necessary dependencies for the ES4X web application, including `@reactiverse/es4x` and `@vertx/web`. The `npm i` process triggers the `es4x install` postinstall script, ensuring all required GraalJS components are set up for optimal performance. ```bash $ npm i > hello-es4x@1.0.0 postinstall .../hello-world > es4x install npm notice created a lockfile as package-lock.json. You should commit this file. added 2 packages from 1 contributor and audited 2 packages in 6.704s found 0 vulnerabilities ``` -------------------------------- ### Define ES4X Hello World Project Configuration Source: https://github.com/reactiverse/es4x/blob/develop/docs/examples/README.md This `package.json` file sets up a basic ES4X 'Hello World' project. It defines the project's metadata, specifies `index.js` as the main entry point, and includes `@reactiverse/es4x` as a core dependency. The `start` script is configured to execute the ES4X runtime. ```json { "name": "hello-es4x", "version": "1.0.0", "description": "ES4X Hello World example", "main": "index.js", "scripts": { "start": "es4x", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@reactiverse/es4x": "^0.15.0" } } ``` -------------------------------- ### ES4X Command-Line Interface (CLI) Reference Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/install.md Displays the available commands and their descriptions for the `es4x` command-line tool. This serves as a comprehensive reference for managing ES4X projects and applications, detailing functionalities like project creation, Dockerfile generation, dependency installation, and application lifecycle management. ```APIDOC Usage: java -jar /usr/local/bin/es4x-bin.jar [COMMAND] [OPTIONS] [arg...] Commands: bare Creates a bare instance of vert.x. dockerfile Creates a generic Dockerfile for building and deploying the current project. project Initializes the 'package.json' to work with ES4X. install Installs required jars from maven to 'node_modules'. list List vert.x applications run Runs a JS script called in its own instance of vert.x. start Start a vert.x application in background stop Stop a vert.x application version Displays the version. Run 'java -jar /usr/local/bin/es4x-bin.jar COMMAND --help' for more information on a command. ``` -------------------------------- ### Develop a Simple ES4X Web Application Source: https://github.com/reactiverse/es4x/blob/develop/docs/pl/examples/README.md This example illustrates setting up an ES4X project for a basic web application. It includes the `package.json` configuration, the JavaScript code for a simple HTTP server using Vert.x Web, and the necessary commands to install dependencies. ```json { "name": "web-es4x", "version": "1.0.0", "description": "A simple ES4X web application example.", "main": "index.js", "scripts": { "start": "es4x", "postinstall": "es4x install" }, "dependencies": { "@reactiverse/es4x": "^0.15.0", "@vertx/web": "^4.0.0" } } ``` ```bash $ npm i > hello-es4x@1.0.0 postinstall .../hello-world > es4x install npm notice created a lockfile as package-lock.json. You should commit this file. added 2 packages from 1 contributor and audited 2 packages in 6.704s found 0 vulnerabilities ``` ```javascript import { Router } from '@vertx/web'; import { Vertx } from '@vertx/core'; const vertx = Vertx.vertx(); const router = Router.router(vertx); router.get('/').handler(ctx => { ctx.response().end('Hello from ES4X Web App!'); }); vertx.createHttpServer().requestHandler(router).listen(8080, res => { if (res.succeeded()) { console.log('Server listening on port 8080'); } else { console.error('Failed to start server: ' + res.cause()); } }); ``` -------------------------------- ### Install ES4X Project Management Tools Globally Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/install.md Installs the `@es4x/create` package globally using npm or yarn. This provides the `es4x` command-line utility, which is essential for creating new projects and performing various development tasks within the ES4X ecosystem. ```bash npm install -g @es4x/create ``` ```bash yarn global add @es4x/create ``` -------------------------------- ### Run ES4X Hello World Application Source: https://github.com/reactiverse/es4x/blob/develop/docs/examples/README.md This command executes the ES4X 'Hello World' application using the `npm start` script defined in `package.json`. The output confirms that the 'Hello ES4X' message is printed and the verticle is successfully deployed by the ES4X runtime. ```bash $ npm start > hello-es4x@1.0.0 start .../hello-world > es4x Hello ES4X Succeeded in deploying verticle ``` -------------------------------- ### Define ES4X Web Application Project Configuration Source: https://github.com/reactiverse/es4x/blob/develop/docs/examples/README.md This `package.json` configures an ES4X web application project. It includes `@reactiverse/es4x` for the runtime and `@vertx/web` as a dependency for building web functionalities. The `start` script is set to run the main application file. ```json { "name": "web-es4x", "version": "1.0.0", "description": "ES4X Web Application example", "main": "index.js", "scripts": { "start": "es4x", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@reactiverse/es4x": "^0.15.0", "@vertx/web": "^4.0.0" } } ``` -------------------------------- ### Install ES4X Project Manager via Tarball Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/install.md Downloads and extracts the ES4X project manager binary tarball to `/usr/local`. This method is an alternative installation approach, particularly useful for CI environments or systems where traditional package managers like npm are not preferred or available. ```bash ES4X='0.16.0' \ curl -sL \ https://github.com/reactiverse/es4x/releases/download/$ES4X/es4x-pm-$ES4X-bin.tar.gz \ | tar zx --strip-components=1 -C /usr/local ``` -------------------------------- ### Install OpenJDK and GraalVM with Jabba Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/install.md Installs specific versions of OpenJDK and GraalVM using the Jabba version manager. This ensures compatibility and performance for ES4X by providing access to recommended JVM runtimes. ```bash jabba install openjdk@1.11.0 ``` ```bash jabba install graalvm@21.3.0 ``` -------------------------------- ### Default ES4X project package.json structure Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/hello-world.md This JSON snippet illustrates the default `package.json` file generated for a new ES4X project. It includes pre-configured scripts for testing, installation, and starting the application, along with essential ES4X dependencies. ```json { "version" : "1.0.0", "description" : "This is a ES4X empty project.", "name" : "myapp", "main" : "index.js", "scripts" : { "test" : "es4x test index.test.js", "postinstall" : "es4x install", "start" : "es4x" }, "dependencies": { "@es4x/create": "latest", "@vertx/unit": "latest" }, "keywords" : [ ], "author" : "", "license" : "ISC" } ``` -------------------------------- ### Initialize a new ES4X project Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/hello-world.md These bash commands guide the user through creating a new directory, navigating into it, and initializing a new ES4X project using the `es4x project` command. This sets up the basic `package.json` structure. ```bash # create a project dir mkdir myapp # change into the project dir cd myapp # create the project es4x project ``` -------------------------------- ### Initialize ES4X Project and Install Dependencies Source: https://github.com/reactiverse/es4x/blob/develop/README.md This snippet outlines the steps to set up a new ES4X project using `npm init`, followed by installing necessary development and production dependencies like `@vertx/unit` and `@vertx/core`. The final `npm install` command triggers the download of required Java dependencies. ```bash # create a generic project mkdir my-app cd my-app # init the project npm init @es4x project # add other dependencies... npm install @vertx/unit --save-dev npm install @vertx/core --save-prod # will trigger the download # of the java dependencies npm install ``` -------------------------------- ### Verify Java Version Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/install.md Checks the currently installed Java Development Kit (JDK) version. ES4X requires Java 11 or higher for optimal performance, as older versions may not benefit from the high-performance engine ES4X uses. ```bash $ java -version openjdk version "11.0.15" 2022-04-19 OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1) OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1, mixed mode) ``` -------------------------------- ### Install uuid package via npm Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README_js.md Installs the 'uuid' package using npm, making it available for use in Node.js projects. This is the recommended way to get started with the library for CommonJS environments. ```shell npm install uuid ``` -------------------------------- ### Interact with Running ES4X Application using cURL Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/run.md After starting the ES4X application, this command demonstrates how to interact with it using a simple HTTP client like cURL. It sends a GET request to the running server, expecting a 'Hello from Vert.x Web!' response. ```bash curl localhost:8080 ``` -------------------------------- ### Define ES4X PostgreSQL Access Project Configuration Source: https://github.com/reactiverse/es4x/blob/develop/docs/examples/README.md This `package.json` sets up an ES4X project for interacting with a PostgreSQL database. It includes `@reactiverse/es4x` for the runtime and `@vertx/pg-client` as a dependency, enabling database connectivity and query execution. ```json { "name": "pg-es4x", "version": "1.0.0", "description": "ES4X Postgres Access example", "main": "index.js", "scripts": { "start": "es4x", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@reactiverse/es4x": "^0.15.0", "@vertx/pg-client": "^4.0.0" } } ``` -------------------------------- ### Switch JVM Version with Jabba Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/install.md Switches the active Java Virtual Machine (JVM) version using Jabba. This allows developers to easily change between different JDKs or GraalVM installations to match project requirements or performance needs. ```bash jabba use openjdk@1.11 ``` ```bash jabba use graalvm@21.2 ``` -------------------------------- ### Install Typedoc and Deploy Packages with API Documentation Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/contributing.md Installs Typedoc globally for generating API documentation. Subsequently, it uses Maven to deploy es4x generator packages to Verdaccio while simultaneously generating API documentation into the 'docs' folder using the `typedoc` plugin. ```bash # install the API doc generator npm install -g typedoc # deploy to verdaccio and generate docs to the docs folder cd generator mvn -Dnpm-registry="http://localhost:4873" \ clean \ generate-sources \ exec:exec@npm-publish \ exec:exec@typedoc ``` -------------------------------- ### Install ES4X Launcher with npm or Yarn Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/run.md This command installs the necessary ES4X launcher, which is typically created in `node_modules/.bin/es4x-lancher.*`. It's a prerequisite for running ES4X applications. ```bash npm install # OR yarn ``` -------------------------------- ### Launch ES4X REPL with es4x-launcher.jar Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/shell.md This snippet illustrates an alternative method to start the ES4X REPL directly using the `es4x-launcher.jar` executable. This approach is useful for environments where `npm` is not available or for standalone deployments, providing the same interactive JavaScript shell. ```bash java -jar es4x-launcher.jar run "js:>" ``` -------------------------------- ### Install Verdaccio Local NPM Registry Source: https://github.com/reactiverse/es4x/blob/develop/CONTRIBUTING.md Installs Verdaccio globally, a lightweight private NPM registry for local development and testing. ```bash npm install -g verdaccio ``` -------------------------------- ### Install Verdaccio NPM Registry Globally Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/contributing.md Instructions to install Verdaccio, a lightweight private NPM registry, globally using npm. This allows for local package deployment and testing during development. ```bash npm install -g verdaccio ``` -------------------------------- ### Start an ES4X Application Source: https://github.com/reactiverse/es4x/blob/develop/README.md This command shows how to run the ES4X application after it has been set up and configured. It typically executes the main script defined in the project's `package.json`. ```bash npm start ``` -------------------------------- ### Install TypeDoc API Documentation Generator Source: https://github.com/reactiverse/es4x/blob/develop/CONTRIBUTING.md Installs TypeDoc globally, a tool used to generate API documentation for TypeScript projects, required for generating docs for generated packages. ```bash npm install -g typedoc ``` -------------------------------- ### Install Vert.x Unit Development Dependency Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/test.md Instructions to add the Vert.x Unit test framework as a development dependency using npm or yarn, followed by ensuring all project dependencies are fetched. ```bash npm install @vertx/unit --save-dev # OR yarn add -D @vertx/unit # ensure es4x fetches the non npm dependencies npm install # OR yarn ``` -------------------------------- ### Start ES4X REPL Shell with npm Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/shell.md This snippet demonstrates how to launch the ES4X interactive shell (REPL) using the npm script. This provides a JavaScript environment where code can be executed interactively, bootstrapped with components available in your classpath. ```bash $ npm run "js:>" ``` -------------------------------- ### Start ES4X Application with npm or Yarn Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/run.md This command initiates the ES4X application on the JVM runtime, replacing the default npm operation. Upon successful deployment, it typically outputs server listening details and a deployment success message. ```bash npm start # OR yarn start ``` -------------------------------- ### Write a Basic Vert.x Unit Test Suite in JavaScript Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/test.md Example of creating a test suite and a test case using @vertx/unit in JavaScript. It demonstrates importing TestSuite, defining a test, asserting values, and running the suite. ```js import { TestSuite } from '@vertx/unit'; const suite = TestSuite.create("the_test_suite"); suite.test("my_test_case", function (context) { var s = "value"; context.assertEquals("value", s); }); suite.run(); ``` -------------------------------- ### Install JVM Dependencies for ES4X Source: https://github.com/reactiverse/es4x/blob/develop/pm/README.md Processes the `package.json` to identify and download required JVM artifacts from Maven Central, installing them into `node_modules`. ```bash es4x install ``` -------------------------------- ### Implement ES4X Hello World Verticle Source: https://github.com/reactiverse/es4x/blob/develop/docs/examples/README.md This JavaScript code defines a simple ES4X verticle. It uses `console.log` to print 'Hello ES4X' to the standard output, serving as a basic demonstration of code execution within the ES4X environment. ```javascript console.log('Hello ES4X'); ``` -------------------------------- ### Display ES4X Runtime and Dependency Versions Source: https://github.com/reactiverse/es4x/blob/develop/pm/README.md Outputs the versions of the current runtime environment and all installed ES4X dependencies. ```bash es4x versions ``` -------------------------------- ### Add dependencies to an ES4X project Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/hello-world.md These commands demonstrate how to add new JavaScript dependencies to an ES4X project using `npm` (or `yarn`). After adding, `npm install` is run to resolve both npm and Java (Maven) dependencies. ```bash # add other dependencies... npm install @vertx/unit --save-dev # OR yarn add -D @vertx/unit npm install @vertx/web --save-prod # OR yarn add @vertx/web # will trigger the download of the npm + java dependencies npm install ``` -------------------------------- ### Example Output of Vert.x Unit Test Execution Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/test.md Illustrative console output showing the execution flow and results of a Vert.x Unit test suite run, including test case pass/fail status. ```bash Running: java ... Begin test suite the_test_suite Begin test my_test_case Passed my_test_case End test suite the_test_suite , run: 1, Failures: 0, Errors: 0 ``` -------------------------------- ### Implement ES4X Basic Web Server Verticle Source: https://github.com/reactiverse/es4x/blob/develop/docs/examples/README.md This JavaScript code creates a simple web server using ES4X and Vert.x Web. It initializes a Vert.x instance, sets up a router to handle requests to the root path, and responds with 'Hello from ES4X Web!'. The server listens on port 8080. ```javascript import { Vertx } from '@vertx/core'; import { Router } from '@vertx/web'; const vertx = Vertx.vertx(); const server = vertx.createHttpServer(); const router = Router.router(vertx); router.route('/').handler(ctx => { ctx.response().end('Hello from ES4X Web!'); }); server.requestHandler(router).listen(8080, res => { if (res.succeeded()) { console.log('Web server listening on port 8080'); } else { console.error('Failed to start web server: ' + res.cause().getMessage()); } }); ``` -------------------------------- ### Generate v5 UUID Example in JavaScript Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README.md Example demonstrating how to generate a RFC4122 v5 UUID by providing a 'name' string and a 'namespace' UUID. ```javascript uuidv5('hello world', MY_NAMESPACE); // ⇨ '9f282611-e0fd-5650-8953-89c8e342da0b' ``` -------------------------------- ### Generate v3 UUID Example in JavaScript Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README.md Example demonstrating how to generate a RFC4122 v3 UUID by providing a 'name' string and a 'namespace' UUID. ```javascript uuidv3('hello world', MY_NAMESPACE); // ⇨ '042ffd34-d989-321c-ad06-f60826172424' ``` -------------------------------- ### Configure ES4X Security Policy Source: https://github.com/reactiverse/es4x/blob/develop/pm/README.md Installs a security policy file (`security.policy`) for the project, enabling sandboxing and runtime constraints as allowed by the JVM. ```bash es4x security-policy ``` -------------------------------- ### Example: Generating a v5 UUID Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README_js.md Demonstrates how to generate a RFC4122 v5 UUID using a name and a predefined namespace. ```javascript uuidv5('hello world', MY_NAMESPACE); // RESULT ``` -------------------------------- ### Deploy PM Project to Local NPM Registry Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/contributing.md Steps to package and deploy the 'pm' project to a local NPM registry. This process involves building a Maven fat JAR and then using a custom script to convert it into an NPM package and publish it to your local Verdaccio installation. ```bash cd pm mvn package ./publish.sh local ``` -------------------------------- ### Example: Generating a v3 UUID Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README_js.md Demonstrates how to generate a RFC4122 v3 UUID using a name and a predefined namespace. ```javascript uuidv3('hello world', MY_NAMESPACE); // RESULT ``` -------------------------------- ### API Example: Generate v1 UUID with custom options Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README_js.md Provides an example of generating a version 1 UUID using `uuidv1` with a fully specified `options` object, including custom node ID, clock sequence, milliseconds, and nanoseconds. This demonstrates fine-grained control over the generated UUID's components. ```javascript const v1options = { node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], clockseq: 0x1234, msecs: new Date('2011-11-01').getTime(), nsecs: 5678 }; uuidv1(v1options); ``` -------------------------------- ### Install uuid Module via npm Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README.md Installs the uuid package using npm, which is the recommended method for CommonJS usage in Node.js environments. ```shell npm install uuid ``` -------------------------------- ### Docker Multi-Stage Build: JVM Dependencies and JLink Runtime Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/package.md This Dockerfile snippet represents the second stage of a multi-stage build. It uses `openjdk:11` as the base, copies application code, downloads the `es4x` runtime tool, installs Java dependencies (production only), and then creates an optimized Java runtime using `es4x jlink` into `/usr/local`. ```dockerfile # Second stage (build the JVM related code) FROM openjdk:11 AS JVM ARG ES4X_VERSION=${project.version} # Copy the previous build step COPY --from=NPM /usr/src/app /usr/src/app # use the copied workspace WORKDIR /usr/src/app # Download the ES4X runtime tool RUN curl -sL https://github.com/reactiverse/es4x/releases/download/${ES4X_VERSION}/es4x-pm-${ES4X_VERSION}-bin.tar.gz | \ tar zx --strip-components=1 -C /usr/local # Install the Java Dependencies # force es4x maven resolution only to consider production dependencies RUN es4x install --only=prod # Create the optimized runtime RUN es4x jlink -t /usr/local ``` -------------------------------- ### Implement ES4X PostgreSQL Database Query Verticle Source: https://github.com/reactiverse/es4x/blob/develop/docs/examples/README.md This JavaScript code demonstrates how to connect to a PostgreSQL database and execute a simple query using ES4X and Vert.x PG Client. It configures connection options, creates a connection pool, and queries the 'users' table, logging the results to the console. ```javascript import { PgPool } from '@vertx/pg-client'; import { PgConnectOptions } from '@vertx/pg-client'; const connectOptions = new PgConnectOptions() .setPort(5432) .setHost('localhost') .setDatabase('mydatabase') .setUser('myuser') .setPassword('mypassword'); const pool = PgPool.pool(connectOptions); pool.query('SELECT * FROM users').execute(ar => { if (ar.succeeded()) { const result = ar.result(); console.log('Got ' + result.size() + ' rows '); result.forEach(row => { console.log('User: ' + row.getString('name')); }); } else { console.error('Failure: ' + ar.cause().getMessage()); } pool.close(); }); ``` -------------------------------- ### Generate ES4X Dockerfile Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/package.md Generates a default 3-stage Dockerfile for the ES4X application. The stages involve installing NPM dependencies, Maven dependencies, and finally running the application using a GraalVM image. This file can be customized. ```bash es4x dockerfile ``` -------------------------------- ### Scale ES4X Verticles for Performance Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/run.md This command demonstrates how to scale the number of verticles an ES4X application uses, which can improve performance. The example sets the number of instances to 2, but it can be customized based on the number of CPU cores for optimal results. ```bash N=2 \ ./node_modules/.bin/es4x-launcher -instances $N ``` -------------------------------- ### Create Optimized Java Runtime with JLink Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/package.md Uses the `jlink` tool to assemble and optimize a set of Java modules and their dependencies into a custom runtime image. This significantly reduces the runtime size compared to a full JDK installation, making it suitable for smaller deployments. ```bash es4x jlink ``` -------------------------------- ### Display ES4X Run Command Help Documentation Source: https://github.com/reactiverse/es4x/blob/develop/docs/advanced/hot-reload.md This `bash` command retrieves and displays the comprehensive help documentation for the `es4x run` command. It provides detailed information on all available options, flags, and usage examples for configuring application execution. ```bash es4x run --help ``` -------------------------------- ### Example: Generating Multiple v4 UUIDs into a Single Buffer Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README_js.md Shows how to generate two RFC4122 v4 UUIDs sequentially into the same buffer by specifying different offsets, demonstrating efficient memory usage. ```javascript const buffer = new Array(); uuidv4(null, buffer, 0); // RESULT uuidv4(null, buffer, 16); // RESULT ``` -------------------------------- ### Generate UUIDs from the Command Line Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README_js.md Explains how to generate RFC4122 UUIDs directly from the command line using the `uuid` utility. It shows examples for generating a default UUID and a version 1 UUID, and mentions the `--help` option for more details. ```shell $ uuid ddeb27fb-d9a0-4624-be4d-4615062daed4 $ uuid v1 02d37060-d446-11e7-a9fa-7bdae751ebe1 ``` -------------------------------- ### Load JavaScript Module in ES4X Shell Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/shell.md Once the ES4X REPL is active, this example shows how to load an external JavaScript module, such as `index.js`, into the shell environment. This allows for testing and interaction with existing project code directly within the REPL. ```javascript js:> require('./index.js'); ``` -------------------------------- ### Generate v1 UUID with Fully-Specified Options in JavaScript Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README.md Example demonstrating how to generate a RFC4122 v1 UUID by providing all optional parameters like node ID, clock sequence, and precise timestamp (milliseconds and nanoseconds). ```javascript const v1options = { node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], clockseq: 0x1234, msecs: new Date('2011-11-01').getTime(), nsecs: 5678 }; uuidv1(v1options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab' ``` -------------------------------- ### Generate VSCode Debug Configuration for es4x Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/debug.md Before debugging with VSCode, ensure the 'GraalVM Tools for Java' extension is installed. Use the es4x vscode command to automatically generate a launcher.json file, which contains the necessary attach configuration for debugging your es4x application. ```sh es4x vscode ``` -------------------------------- ### VSCode GraalVM Debug Attach Configuration Example Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/debug.md This JSON configuration snippet for launcher.json defines an 'attach' type debugger for GraalVM. It specifies the port (9229) where the debugger agent is listening, allowing VSCode to connect and debug the running es4x application. ```json { "version" : "0.2.0", "configurations" : [ { "name" : "Launch empty-project", "type" : "graalvm", "request" : "attach", "port" : 9229 } ] } ``` -------------------------------- ### Display ES4X Launcher Help Options Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/run.md This command provides access to the ES4X launcher's help documentation, allowing users to discover and customize various startup options and configurations for their application. ```bash ./node_modules/.bin/es4x-launcher -help ``` -------------------------------- ### Write Unit Tests with Vert.x Unit in ES4X Source: https://github.com/reactiverse/es4x/blob/develop/README.md This JavaScript example illustrates how to write a unit test using the `@vertx/unit` framework within an ES4X application. It defines a test suite and a test case that performs a basic assertion, demonstrating the integration of testing capabilities. ```js import { TestSuite } from '@vertx/unit'; const suite = TestSuite.create("the_test_suite"); suite.test("my_test_case", function (context) { var s = "value"; context.assertEquals("value", s); }); suite.run(); ``` -------------------------------- ### ES4X Hot Reload Initial Console Output Source: https://github.com/reactiverse/es4x/blob/develop/docs/advanced/hot-reload.md This `bash` output illustrates the console messages displayed when an ES4X application is initially started in hot-redeploy mode. It confirms the watched paths, the deployment of the Vert.x application, and the successful execution of the initial script. ```bash $ ./node_modules/.bin/es4x --redeploy "m/*" Watched paths: [/home/hello/./m] Starting the vert.x application in redeploy mode Starting vert.x application... ec467de2-ca71-43c6-98d8-9da0cc0d24f8-redeploy Hello from A Hello from B Hello from C Succeeded in deploying verticle ``` -------------------------------- ### Maven POM for ES4X Module Generation Setup Source: https://github.com/reactiverse/es4x/blob/develop/docs/advanced/codegen.md This `pom.xml` snippet demonstrates the basic configuration required to generate an ES4X module. It specifies the `es4x-generator` as the parent, defines the artifact ID and version, and includes dependencies like `vertx-web` and the source module itself. It also sets initial npm properties for the generated module. ```XML 4.0.0 io.reactiverse.es4x es4x-generator 0.16.0 ../../pom.xml hot-reload 0.15.1-SNAPSHOT jar xyz.jetdrone 0.0.5 false { "@vertx/web": "${stack.version}" } io.vertx vertx-web ${stack.version} true ${maven.groupId} ${project.artifactId} ${npm-version} ${maven.groupId} ${project.artifactId} ${npm-version} provided sources ``` -------------------------------- ### Create a Hello World application using Vert.x Web with ES4X Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/hello-world.md This JavaScript code snippet builds upon the basic HTTP server by integrating Vert.x Web for routing. It sets up a router to handle requests to the root path (`/`) and responds with 'Hello from Vert.x Web!', demonstrating a more structured approach to web application development. ```js /// // @ts-check import { Router } from '@vertx/web'; const app = Router.router(vertx); app.route('/').handler(ctx => { ctx.response() .end('Hello from Vert.x Web!'); }); vertx.createHttpServer() .requestHandler(app) .listen(8080); console.log('Server listening at: http://localhost:8080/') ``` -------------------------------- ### Run an ES4X JavaScript application Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/hello-world.md This command line snippet shows how to execute an ES4X JavaScript file directly using the `es4x` command. It's suitable for small scripts without complex dependencies. ```bash $ es4x hello-es4x.js ``` -------------------------------- ### Bootstrap ES4X Project with npm Source: https://github.com/reactiverse/es4x/blob/develop/pm/README.md Initializes a new ES4X project by creating a basic set of files including `package.json`, `index.js`, and `index.test.js`. ```bash npm init @es4x project ``` -------------------------------- ### Main Verticle Interaction with ES4X Worker (JavaScript) Source: https://github.com/reactiverse/es4x/blob/develop/docs/es/advanced/worker.md This example illustrates how a main Verticle creates and interacts with an ES4X worker. It demonstrates using `Worker.create()` to instantiate a worker, handling incoming messages with `worker.onmessage`, managing errors with `worker.onerror` (including worker termination), and sending data to the worker via `worker.postMessage()`. This setup ensures long-running operations are delegated, keeping the event loop responsive. ```JavaScript Worker.create('workers/worker.js', function (create) { if (create.succeeded()) { var worker = create.result(); worker.onmessage = function (msg) { console.log('onmessage: ' + msg); }; worker.onerror = function (err) { console.err(err); // Termina el "worker" worker.terminate(); }; console.log('posting...'); worker.postMessage({data: [2, 3]}); } }); ``` -------------------------------- ### Initialize ES4X Project via CLI Source: https://github.com/reactiverse/es4x/blob/develop/pm/README.md Executes the project initialization command directly using the `es4x` CLI, achieving the same outcome as `npm init @es4x project`. ```bash es4x project ``` -------------------------------- ### ES4X Command Line Interface Reference Source: https://github.com/reactiverse/es4x/blob/develop/pm/README.md Provides an overview of the available `es4x` commands and their primary functions, along with current VM details. Use `es4x COMMAND --help` for more specific information. ```APIDOC Usage: es4x [COMMAND] [OPTIONS] [arg...] Commands: project Initializes the 'package.json' to work with ES4X. install Installs required jars from maven to 'node_modules'. security-policy Initializes a secure by default VM 'security.policy' to work with ES4X. versions Displays the versions. Current VM: Name: Java HotSpot(TM) 64-Bit Server VM - 11.0.7 Vendor: GraalVM CE 20.1.0 Run 'es4x COMMAND --help' for more information on a command. ``` -------------------------------- ### Start es4x Application for Chrome Inspector Debugging Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/debug.md To enable remote debugging via Chrome Inspector, start your es4x application with the -Dinspect flag, specifying the desired port (e.g., 9229). This allows you to attach a Chrome DevTools instance for a remote debug session, setting breakpoints and inspecting runtime behavior. ```sh npm start -- -Dinspect=9229 ``` -------------------------------- ### Create a basic Hello World HTTP server with ES4X Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/hello-world.md This JavaScript snippet demonstrates how to create a simple HTTP server using Vert.x within an ES4X application. It listens on port 8080 and responds with 'Hello ES4X world!' to all incoming requests. ```js vertx.createHttpServer() .requestHandler(req => { req.response() .end('Hello ES4X world!'); }) .listen(8080); ``` -------------------------------- ### Deploy PM Project to Local NPM Registry Source: https://github.com/reactiverse/es4x/blob/develop/CONTRIBUTING.md Builds the 'pm' project using Maven, generating a fat JAR, and then uses a local script to convert it into an NPM package and deploy it to the local Verdaccio registry. ```bash cd pm mvn package ./publish.sh local ``` -------------------------------- ### Example: Generating a v4 UUID with Custom Random Values Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README_js.md Illustrates how to generate a RFC4122 v4 UUID by providing a custom array of 16 numbers for the `random` option, overriding the default random number generation. ```javascript const v4options = { random: [ 0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea, 0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36 ] }; uuidv4(v4options); // RESULT ``` -------------------------------- ### Test ES4X HTTP server with cURL Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/hello-world.md This cURL command is used to test the running ES4X HTTP server by sending a request to `localhost:8080` and displaying the server's response. ```bash $ curl localhost:8080 ``` -------------------------------- ### Run ES4X Application Directly without npm/yarn Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/run.md For production deployments where a package manager might not be bundled, this command allows direct execution of the ES4X application using its launcher. This avoids reliance on `npm` or `yarn` for startup. ```bash ./node_modules/.bin/es4x-launcher ``` -------------------------------- ### Configure package.json for ES4X Test Script Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/test.md Shows how to add a 'test' script to the scripts section of package.json to enable running tests with npm test using the es4x test command. ```json { ... "scripts" : { "test" : "es4x test index.test.js", ... } ``` -------------------------------- ### Generate Multiple v4 UUIDs In-Place in JavaScript Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README.md Example showing how to generate two RFC4122 v4 UUIDs directly into a single array buffer by specifying different offsets, demonstrating efficient memory usage. ```javascript const buffer = new Array(); uuidv4(null, buffer, 0); // ⇨ [ 54, 122, 218, 70, 45, 70, 65, 24, 171, 53, 95, 130, 83, 195, 242, 45 ] uuidv4(null, buffer, 16); // ⇨ [ 54, 122, 218, 70, 45, 70, 65, 24, 171, 53, 95, 130, 83, 195, 242, 45, 108, 204, 255, 103, 171, 86, 76, 94, 178, 225, 188, 236, 150, 20, 151, 87 ] ``` -------------------------------- ### Docker Multi-Stage Build: Final Image with Optimized JLink Runtime Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/package.md This Dockerfile snippet represents the final stage of a multi-stage build. It uses a minimal `debian:slim` base image, copies the optimized Java runtime and application from previous stages, sets Java options for container support, and defines the `es4x-launcher` as the entrypoint. This results in a smaller final image size. ```dockerfile FROM debian:slim # Collect the jars from the previous step COPY --from=JVM /usr/local /usr/local COPY --from=JVM /usr/src/app /usr/src/app # use the copied workspace WORKDIR /usr/src/app # Bundle app source COPY . . # Define custom java options for containers ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:+UseContainerSupport" # define the entrypoint ENTRYPOINT [ "./node_modules/.bin/es4x-launcher" ] ``` -------------------------------- ### Generate v4 UUID with Predefined Random Values in JavaScript Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README.md Example demonstrating how to generate a RFC4122 v4 UUID by providing a predefined array of 16 random byte values, useful for testing or specific scenarios. ```javascript const v4options = { random: [ 0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea, 0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36 ] }; uuidv4(v4options); // ⇨ '109156be-c4fb-41ea-b1b4-efe1671c5836' ``` -------------------------------- ### Generate Multiple v1 UUIDs In-Place in JavaScript Source: https://github.com/reactiverse/es4x/blob/develop/es4x/src/test/resources/alias/node_modules/uuid/README.md Example showing how to generate two RFC4122 v1 UUIDs directly into a single array buffer by specifying different offsets, demonstrating efficient memory usage. ```javascript const arr = new Array(); uuidv1(null, arr, 0); // ⇨ [ 69, 117, 109, 208, 123, 26, 17, 232, 146, 52, 45, 66, 178, 27, 26, 62 ] uuidv1(null, arr, 16); // ⇨ [ 69, 117, 109, 208, 123, 26, 17, 232, 146, 52, 45, 66, 178, 27, 26, 62, 69, 117, 109, 209, 123, 26, 17, 232, 146, 52, 45, 66, 178, 27, 26, 62 ] ``` -------------------------------- ### Deploy Generator NPM Packages and Generate API Docs Source: https://github.com/reactiverse/es4x/blob/develop/CONTRIBUTING.md Deploys the NPM packages from the 'generator' project to the local Verdaccio registry and simultaneously generates API documentation using TypeDoc, saving them to the 'docs' folder. ```bash cd generator mvn -Dnpm-registry="http://localhost:4873" \ clean \ generate-sources \ exec:exec@npm-publish \ exec:exec@typedoc ``` -------------------------------- ### Run Tests Using npm Command Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/test.md The command to execute tests configured in the package.json using npm, which typically triggers the JVM runtime for ES4X projects. ```bash > npm test ``` -------------------------------- ### Vert.x Web APIs Reference Source: https://github.com/reactiverse/es4x/blob/develop/docs/api/README.md A tool-kit for writing sophisticated modern web applications and HTTP microservices. ```APIDOC web: /es4x/@vertx/web web-api-contract: /es4x/@vertx/web-api-contract web-client: /es4x/@vertx/web-client web-common: /es4x/@vertx/web-common ``` -------------------------------- ### Package ES4X Application using NPM Pack Source: https://github.com/reactiverse/es4x/blob/develop/docs/get-started/package.md This command packages the ES4X application into a TGZ archive, following NPM style. The resulting archive can be moved or published to an NPM registry. The target environment requires access to `@es4x/create` for Java dependencies. ```sh npm pack ``` -------------------------------- ### Vert.x Authentication and Authorization APIs Reference Source: https://github.com/reactiverse/es4x/blob/develop/docs/api/README.md Modules to perform authentication and/or authorization. ```APIDOC auth-common: /es4x/@vertx/auth-common auth-digest: /es4x/@vertx/auth-digest auth-jdbc: /es4x/@vertx/auth-jdbc auth-jwt: /es4x/@vertx/auth-jwt auth-mongo: /es4x/@vertx/auth-mongo auth-oauth2: /es4x/@vertx/auth-oauth2 auth-shiro: /es4x/@vertx/auth-shiro auth-webauthn: /es4x/@vertx/auth-webauthn auth-otp: /es4x/@vertx/auth-otp ``` -------------------------------- ### Vert.x Monitoring APIs Reference Source: https://github.com/reactiverse/es4x/blob/develop/docs/api/README.md Modules to work with monitoring tools. ```APIDOC dropwizard-metrics: /es4x/@vertx/dropwizard-metrics micrometer-metrics: /es4x/@vertx/micrometer-metrics ```