### Install Dependencies for Node/Express Proxy
Source: https://github.com/oceanum-io/oceanum-js/blob/main/packages/datamesh/proxy/guide.md
Commands to install the necessary Node.js dependencies (express) for the Node/Express Datamesh proxy example.
```sh
cd packages/datamesh/proxy/express
npm init -y
npm install express
```
--------------------------------
### Install Express and Initialize Project
Source: https://github.com/oceanum-io/oceanum-js/blob/main/packages/datamesh/proxy/express/README.md
Installs the Express framework and initializes a new Node.js project using npm. This is a prerequisite for running the proxy server.
```bash
npm init -y
npm install express
```
--------------------------------
### Install @oceanum/datamesh
Source: https://github.com/oceanum-io/oceanum-js/blob/main/packages/datamesh/README.md
Installs the @oceanum/datamesh library using npm. This is the first step to using the library in your Node.js, Deno, or browser projects.
```sh
npm install @oceanum/datamesh
```
--------------------------------
### Install @oceanum/datamesh
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/datamesh/README.md
Installs the @oceanum/datamesh library using npm. This command is used to add the library to your Node.js project.
```sh
npm install @oceanum/datamesh
```
--------------------------------
### Install Express Dependency
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/datamesh/documents/Proxy-Guide.md
Command to install the 'express' package using npm, required for running the Node/Express proxy example.
```sh
npm install express
```
--------------------------------
### Generate and Serve Documentation
Source: https://github.com/oceanum-io/oceanum-js/blob/main/CLAUDE.md
Commands to generate TypeDoc documentation for the project, serve it with live reloading, or generate documentation for a specific package.
```Bash
npm run docs
```
```Bash
npm run docs:serve
```
```Bash
npx nx build-docs datamesh
```
--------------------------------
### Datamesh Proxy Setup with TypeScript
Source: https://github.com/oceanum-io/oceanum-js/blob/main/packages/datamesh/README.md
Provides a TypeScript example for setting up the Datamesh Connector to use a proxy. This is recommended for browser applications to keep the Datamesh token secret and simplify CORS. It requires a PROXY_URL and assumes a deployed Cloudflare Worker.
```typescript
import { Connector } from "@oceanum/datamesh";
const PROXY_URL = "https://your-proxy.workers.dev"; // or your own domain
const datamesh = new Connector("proxy", {
service: PROXY_URL,
gateway: PROXY_URL,
});
```
--------------------------------
### EIDOS Development Commands
Source: https://github.com/oceanum-io/oceanum-js/blob/main/CLAUDE.md
Commands for running the EIDOS development server and generating TypeScript interfaces from schemas using Nx.
```Bash
npx nx dev eidos
```
```Bash
npx nx run eidos:generate-types
```
--------------------------------
### Build Oceanum.js Packages
Source: https://github.com/oceanum-io/oceanum-js/blob/main/CLAUDE.md
Commands to build all packages in the Nx monorepo or specific packages like 'datamesh' or 'eidos'. Uses the 'nx' command-line tool.
```Bash
npx nx run-many -t build
```
```Bash
npx nx build datamesh
```
```Bash
npx nx build eidos
```
--------------------------------
### Install Oceanum EIDOS and Svelte
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/svelte.md
This command installs the necessary Oceanum EIDOS JavaScript bindings and Svelte, preparing your project for integration.
```bash
npm install @oceanum/eidos svelte
```
--------------------------------
### Start Node/Express Proxy
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/datamesh/documents/Proxy-Guide.md
Commands to start the Node/Express proxy. It requires the DATAMESH_TOKEN environment variable to be set and optionally allows configuring the Datamesh URL and port.
```sh
DATAMESH_TOKEN=your_token_here node index.js
# Optional:
# DATAMESH_URL=https://datamesh.oceanum.io PORT=8787 DATAMESH_TOKEN=your_token_here node index.js
```
--------------------------------
### Install EIDOS JavaScript Bindings
Source: https://github.com/oceanum-io/oceanum-js/blob/main/packages/eidos/README.md
Installs the EIDOS JavaScript library using npm. This is the first step to integrating EIDOS visualizations into your web application.
```bash
npm install @oceanum/eidos
```
--------------------------------
### Run Node Express Proxy
Source: https://github.com/oceanum-io/oceanum-js/blob/main/packages/datamesh/proxy/express/README.md
Demonstrates how to run the Node.js Express proxy server. It shows how to set the DATAMESH_TOKEN environment variable and optionally configure DATAMESH_URL and PORT.
```bash
DATAMESH_TOKEN=your_token_here node index.js
# or with a custom upstream and port
DATAMESH_TOKEN=your_token_here DATAMESH_URL=https://datamesh.oceanum.io PORT=8080 node index.js
```
--------------------------------
### Test Oceanum.js Packages
Source: https://github.com/oceanum-io/oceanum-js/blob/main/CLAUDE.md
Commands to run tests for the 'datamesh' package, including an option to generate test coverage reports. Utilizes Vitest as the test runner.
```Bash
npx nx test datamesh
```
```Bash
npx nx test datamesh --coverage
```
--------------------------------
### Install EIDOS JS Package
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/README.md
Installs the EIDOS JavaScript library using npm. This is the first step to integrating EIDOS visualizations into your web application.
```bash
npm install @oceanum/eidos
```
--------------------------------
### Run Node/Express Proxy
Source: https://github.com/oceanum-io/oceanum-js/blob/main/packages/datamesh/proxy/guide.md
Commands to run the Node/Express Datamesh proxy. It shows how to set the DATAMESH_TOKEN and optionally DATAMESH_URL and PORT environment variables.
```sh
DATAMESH_TOKEN=your_token_here node index.js
# Optional:
# DATAMESH_URL=https://datamesh.oceanum.io PORT=8787 DATAMESH_TOKEN=your_token_here node index.js
```
--------------------------------
### Configure @oceanum/datamesh Connector with Proxy
Source: https://github.com/oceanum-io/oceanum-js/blob/main/packages/datamesh/proxy/guide.md
Example TypeScript code demonstrating how to configure the @oceanum/datamesh Connector to use a proxy URL for both service and gateway endpoints. It highlights that the token parameter is ignored when a proxy is used.
```typescript
import { Connector } from "@oceanum/datamesh";
const PROXY_URL = "https://your-proxy.workers.dev"; // or your custom domain
const connector = new Connector("proxy", {
service: PROXY_URL,
gateway: PROXY_URL,
// Optional: tweak caching and session duration as needed
// nocache: true,
// sessionDuration: 1,
});
```
--------------------------------
### Install EIDOS via NPM/Yarn
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/vanilla.md
Installs the EIDOS JavaScript bindings using either npm or yarn package managers. This is the standard method for including the library in a JavaScript project.
```bash
npm install @oceanum/eidos
# or
yarn add @oceanum/eidos
```
--------------------------------
### Install EIDOS and Vue Dependencies
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/vue.md
Installs the necessary EIDOS JavaScript bindings and Vue.js packages using npm. This is the first step to using EIDOS within a Vue project.
```bash
npm install @oceanum/eidos vue
```
--------------------------------
### Interactive EIDOS Visualization Setup
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/vanilla.md
This snippet sets up the HTML structure, CSS styling, and JavaScript logic for an interactive EIDOS visualization. It includes elements for displaying the visualization, controls for user interaction, and a section for event logging. The JavaScript initializes the EIDOS embed function and manages the application state.
```html
Interactive EIDOS Example
Interactive EIDOS Visualization
```
--------------------------------
### Configure @oceanum/datamesh Connector with Proxy
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/datamesh/documents/Proxy-Guide.md
Demonstrates how to initialize the @oceanum/datamesh Connector to use a deployed reverse proxy. Both 'service' and 'gateway' are pointed to the proxy URL, and a placeholder token is used as the proxy handles authentication.
```typescript
import { Connector } from "@oceanum/datamesh";
const PROXY_URL = "http://localhost:8787"; // or your custom domain
const connector = new Connector("proxy", {
service: PROXY_URL,
gateway: PROXY_URL,
// Optional: tweak caching and session duration as needed
// nocache: true,
// sessionDuration: 1,
});
```
--------------------------------
### Get Datamesh Datasource
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/datamesh/index/classes/Connector.md
Fetches a specific datasource from the Datamesh service using its unique ID. This method returns a Promise that resolves with the Datasource object or throws an error if the datasource is not found or access is denied.
```TypeScript
connector.getDatasource("datasourceId")
```
--------------------------------
### Configure Webpack for Eidos Browser Compatibility
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/vanilla.md
A sample `webpack.config.js` file demonstrating how to configure Webpack for Eidos integration. It includes setting the entry point, output, and resolving polyfills for 'path' and 'util' using `path-browserify` and `util/` respectively, along with Babel configuration for JavaScript transpilation.
```javascript
// webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
fallback: {
// EIDOS may need these polyfills for browser compatibility
"path": require.resolve("path-browserify"),
"util": require.resolve("util/")
}
},
module: {
rules: [
{
test: /.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
};
```
--------------------------------
### Get Datamesh Session
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/datamesh/index/classes/Connector.md
Retrieves the current active session or creates a new one if no session exists. This is useful for ensuring an active connection before performing operations. Returns a Promise resolving to the Session object.
```TypeScript
connector.getSession()
```
--------------------------------
### Cloudflare Worker Proxy for Datamesh
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/datamesh/documents/Proxy-Guide.md
An example Cloudflare Worker that acts as a reverse proxy for the Datamesh API. It forwards requests, injects the Datamesh token from environment secrets, and adds permissive CORS headers for browser applications.
```javascript
// Example Cloudflare Worker reverse proxy
// Add your datamesh token as a secret in the Cloudflare worker environment
const DATAMESH = "https://datamesh.oceanum.io";
export default {
async fetch(request, env) {
const url = new URL(request.url);
const DATAMESH_TOKEN = env.DATAMESH_TOKEN;
// Build the upstream request URL
const datameshUrl = new URL(url.pathname + url.search, DATAMESH);
// Clone request and forward body/headers/method
const modifiedRequest = new Request(datameshUrl.toString(), {
method: request.method,
headers: request.headers,
body: request.body,
});
// Inject/overwrite the token
modifiedRequest.headers.set("x-DATAMESH-TOKEN", `${DATAMESH_TOKEN}`);
// Forward
const response = await fetch(modifiedRequest);
// Add CORS headers for the browser
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: {
...response.headers,
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
},
});
},
};
```
--------------------------------
### Create Dataset from Zarr Store
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/datamesh/index/classes/Dataset.md
Creates a Dataset instance by connecting to a Zarr store via HTTP. Requires the store URL, authentication headers, and optional Zarr options.
```typescript
static zarr(url: string, authHeaders: Record, options: ZarrOptions = {}): Promise>
```
--------------------------------
### Cloudflare Worker Proxy for Datamesh
Source: https://github.com/oceanum-io/oceanum-js/blob/main/packages/datamesh/proxy/guide.md
A Cloudflare Worker script that acts as a reverse proxy for the Datamesh API. It forwards requests, injects the Datamesh token from environment secrets, and adds permissive CORS headers for browser applications.
```javascript
// Example Cloudflare Worker reverse proxy
// Add your datamesh token as a secret in the Cloudflare worker environment
const DATAMESH = "https://datamesh.oceanum.io";
export default {
async fetch(request, env) {
const url = new URL(request.url);
const DATAMESH_TOKEN = env.DATAMESH_TOKEN;
// Build the upstream request URL
const datameshUrl = new URL(url.pathname + url.search, DATAMESH);
// Clone request and forward body/headers/method
const modifiedRequest = new Request(datameshUrl.toString(), {
method: request.method,
headers: request.headers,
body: request.body,
});
// Inject/overwrite the token
modifiedRequest.headers.set("x-DATAMESH-TOKEN", `${DATAMESH_TOKEN}`);
// Forward
const response = await fetch(modifiedRequest);
// Add CORS headers for the browser
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: {
...response.headers,
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers":
"Content-Type, Authorization, x-requested-with, x-datamesh-token",
},
});
},
};
```
--------------------------------
### React to Eidos Spec Mutations in JavaScript
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/api.md
Illustrates how to directly mutate Eidos specification properties to update the visualization reactively. Examples include direct property assignment, array operations, nested object updates, and bulk updates using Object.assign.
```javascript
// Direct property assignment
eidos.name = 'New Name';
// Array operations
eidos.root.children.push(newLayer);
eidos.data.splice(0, 1); // Remove first data source
// Nested object updates
eidos.root.children[0].visible = false;
eidos.data[0].url = 'https://new-url.com/data.json';
// Bulk updates
Object.assign(eidos.root, {
backgroundColor: '#fff',
showGrid: true
});
```
--------------------------------
### Basic EIDOS Embedding in Vanilla JavaScript
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/vanilla.md
Demonstrates how to embed EIDOS into a plain HTML page using vanilla JavaScript. It includes setting up a container, defining a specification, and initializing the EIDOS instance with an event listener and a delayed layer addition.
```javascript
import { embed } from '@oceanum/eidos';
const spec = {
id: 'vanilla-demo',
name: 'Vanilla JS Demo',
root: {
id: 'root',
nodeType: 'world',
children: []
},
data: [],
transforms: []
};
async function initEidos() {
const container = document.getElementById('eidos-container');
try {
const eidos = await embed(container, spec, (event) => {
console.log('EIDOS event:', event);
});
console.log('EIDOS instance created:', eidos);
// Example: Add a layer after 2 seconds
setTimeout(() => {
eidos.root.children.push({
id: 'demo-layer',
nodeType: 'worldlayer',
layerType: 'track'
});
console.log('Layer added');
}, 2000);
} catch (error) {
console.error('Failed to create EIDOS:', error);
container.innerHTML = `Error: ${error.message}
`;
}
}
// Initialize when DOM is loaded
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initEidos);
} else {
initEidos();
}
```
--------------------------------
### Handle Eidos Ready State
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/vanilla.md
Updates the UI to reflect that the Eidos component is ready. This includes setting the status text, clearing loading messages, enabling controls, setting the initial title, and updating the layer count.
```javascript
onEidosReady() {
this.status.textContent = 'Ready';
this.container.innerHTML = ''; // Remove loading message
// Enable controls
this.addLayerBtn.disabled = false;
this.addGriddedBtn.disabled = false;
this.updateTitleBtn.disabled = false;
this.titleInput.disabled = false;
this.dataUrlInput.disabled = false;
// Set initial title
this.titleInput.value = this.eidos.name;
this.updateLayerCount();
console.log('EIDOS ready:', this.eidos);
}
```
--------------------------------
### Implement Safe Eidos Embedding with Error Handling
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/vanilla.md
Demonstrates a JavaScript class `EidosErrorHandler` with a static method `safeEmbed` to safely initialize Eidos visualizations. It includes a `handleError` method for logging and displaying user-friendly error messages within the container, and a `getUserFriendlyMessage` helper to map specific error types to clearer messages.
```javascript
// error-handling.js
import { embed } from '@oceanum/eidos';
class EidosErrorHandler {
static async safeEmbed(container, spec, onEvent, renderer) {
try {
return await embed(container, spec, onEvent, renderer);
} catch (error) {
this.handleError(error, container);
throw error;
}
}
static handleError(error, container) {
console.error('EIDOS Error:', error);
// Display user-friendly error message
container.innerHTML = `
Visualization Error
${this.getUserFriendlyMessage(error)}
Technical Details
${error.message}
`;
}
static getUserFriendlyMessage(error) {
if (error.message.includes('validation failed')) {
return 'The visualization specification is invalid. Please check your data format.';
}
if (error.message.includes('network') || error.message.includes('fetch')) {
return 'Unable to connect to the visualization server. Please check your internet connection.';
}
if (error.message.includes('timeout')) {
return 'The visualization is taking too long to load. Please try again.';
}
return 'An unexpected error occurred while loading the visualization.';
}
}
export { EidosErrorHandler };
```
--------------------------------
### Initialize Eidos App and Event Listeners
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/eidos/vanilla.md
Sets up event listeners for UI elements to interact with the Eidos visualization. This includes buttons for adding layers, updating titles, and clearing events, as well as input fields for titles and data URLs.
```javascript
this.addLayerBtn.addEventListener('click', () => this.addTrackLayer());
this.addGriddedBtn.addEventListener('click', () => this.addGriddedLayer());
this.updateTitleBtn.addEventListener('click', () => this.updateTitle());
this.clearEventsBtn.addEventListener('click', () => this.clearEvents());
this.titleInput.addEventListener('input', (e) => {
if (this.eidos) {
this.eidos.name = e.target.value;
}
});
this.titleInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
this.updateTitle();
}
});
```
--------------------------------
### Initialize Datamesh Connector with Proxy (TypeScript)
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/datamesh/README.md
Shows how to initialize the Datamesh Connector in TypeScript when using a proxy. This is recommended for browser applications to keep the Datamesh token secret. It requires specifying the proxy service and gateway URLs.
```typescript
import { Connector } from "@oceanum/datamesh";
const PROXY_URL = "https://your-proxy.workers.dev"; // or your own domain
const datamesh = new Connector("proxy", {
service: PROXY_URL,
gateway: PROXY_URL,
});
```
--------------------------------
### Instantiate Datamesh Connector
Source: https://github.com/oceanum-io/oceanum-js/blob/main/docs/datamesh/index/classes/Connector.md
Initializes a new Connector instance for the Datamesh service. Requires an access token and supports optional configuration for gateway, JWT authentication, caching, service URL, and session duration.
```TypeScript
new Connector(token, {
gateway?: "https://gateway.",
jwtAuth?: "JWT for Oceanum service",
nocache?: boolean,
service?: "https://datamesh.oceanum.io",
sessionDuration?: number
})
```