Oracle Cloud Infrastructure (OCI) Globally Distributed Database Client
This module, `oci-globallydistributeddatabase`, provides the NodeJS client for interacting with the Oracle Cloud Infrastructure (OCI) Globally Distributed Database Service. It is part of the larger `oci-typescript-sdk` and allows programmatic management of sharded databases, enabling operations like creating, updating, and listing globally distributed database resources within OCI. The current package version is 2.124.0, though the overall OCI SDK has seen rapid development with releases up to 2.130.0, indicating a highly active release cadence (often weekly or bi-weekly patches/minor versions). Key differentiators include deep integration with the OCI ecosystem, comprehensive TypeScript type definitions for robust development, and consistent API patterns across all OCI services supported by the SDK.
Common errors
-
NotAuthorizedOrNotFound
cause The configured user or instance principal lacks the necessary IAM permissions to perform the requested operation, or the specified resource (e.g., compartment, sharded database) does not exist or is in a different region.fixVerify IAM policies grant 'manage' or 'read' permissions for `globally-distributed-database` resources in the target compartment. Double-check the OCID of the resource or compartment and ensure the client's configured region matches the resource's region. -
Error: Cannot find module 'oci-globallydistributeddatabase'
cause The package is not installed or the import path is incorrect, especially in projects mixing ESM and CJS modules.fixRun `npm install oci-globallydistributeddatabase` to install the package. If using ESM, ensure your `package.json` has `"type": "module"` or use `.mjs` extension, and ensure your `tsconfig.json` (if applicable) is configured for ESM imports (`"module": "NodeNext"`, `"moduleResolution": "NodeNext"`). -
TypeError: client.listShardedDatabases is not a function
cause The `listShardedDatabases` method or the `GloballyDistributedDatabaseClient` object might be incorrectly instantiated or imported.fixEnsure `GloballyDistributedDatabaseClient` is correctly imported and initialized with an `authenticationDetailsProvider`. Verify the method name `listShardedDatabases` is spelled correctly and matches the SDK's API.
Warnings
- gotcha Authentication details are critical. Incorrect OCI configuration (missing private key, wrong tenancy OCID, user OCID, or fingerprint) or misconfigured IAM policies will result in `NotAuthorizedOrNotFound` errors.
- gotcha OCI SDKs default to a specific region (typically `us-ashburn-1` if not specified). If your resources are in a different region, you must explicitly set the region for the client, otherwise, you may encounter `NotFound` errors or requests routed to the wrong data center.
- gotcha List operations in OCI SDKs are often paginated. If you expect more results than the default `limit` (typically 10-100), you must implement pagination logic to fetch all items by repeatedly calling the list method with the `opcNextPage` token.
Install
-
npm install oci-globallydistributeddatabase -
yarn add oci-globallydistributeddatabase -
pnpm add oci-globallydistributeddatabase
Imports
- GloballyDistributedDatabaseClient
const GloballyDistributedDatabaseClient = require('oci-globallydistributeddatabase');import { GloballyDistributedDatabaseClient } from 'oci-globallydistributeddatabase'; - Auth
import { Auth } from 'oci-globallydistributeddatabase';import * as common from 'oci-common'; const provider = new common.Auth.ConfigFileAuthenticationDetailsProvider();
- ListShardedDatabasesRequest
import { ListShardedDatabasesRequest } from 'oci-globallydistributeddatabase/lib/globallydistributeddatabase_request';import { GloballyDistributedDatabaseRequests } from 'oci-globallydistributeddatabase'; const request: GloballyDistributedDatabaseRequests.ListShardedDatabasesRequest = {};
Quickstart
import { GloballyDistributedDatabaseClient } from 'oci-globallydistributeddatabase';
import * as common from 'oci-common';
import { GloballyDistributedDatabaseRequests } from 'oci-globallydistributeddatabase';
async function listGloballyDistributedDatabases() {
try {
// Configure authentication using a config file (typically ~/.oci/config)
// Ensure your OCI config file is set up with a profile.
const provider = new common.Auth.ConfigFileAuthenticationDetailsProvider();
// Initialize the client
const client = new GloballyDistributedDatabaseClient({ authenticationDetailsProvider: provider });
// Construct a list request. A compartmentId is typically required for listing resources.
// Replace 'ocid1.compartment.oc1..aaaa...' with your actual compartment OCID.
const compartmentId = process.env.OCI_COMPARTMENT_ID ?? 'ocid1.compartment.oc1..examplecompartmentid';
const listRequest: GloballyDistributedDatabaseRequests.ListShardedDatabasesRequest = {
compartmentId: compartmentId,
limit: 10 // Optional: limit the number of results
};
// Make the API call to list sharded databases
console.log(`Listing sharded databases in compartment: ${compartmentId}...`);
const response = await client.listShardedDatabases(listRequest);
// Process the response
if (response.shardedDatabaseCollection?.items && response.shardedDatabaseCollection.items.length > 0) {
console.log('Found Sharded Databases:');
response.shardedDatabaseCollection.items.forEach(db => {
console.log(`- Name: ${db.displayName}, ID: ${db.id}, Lifecycle State: ${db.lifecycleState}`);
});
} else {
console.log('No sharded databases found in the specified compartment.');
}
} catch (error) {
console.error('Error listing sharded databases:', error);
// Log specific OCI errors for better debugging
if (error instanceof common.Error.ServiceError) {
console.error(`OCI Service Error: ${error.statusCode} - ${error.serviceCode} (${error.errorCode}): ${error.message}`);
}
process.exit(1);
}
}
listGloballyDistributedDatabases();