UNPKG

@storybooker/gcp

Version:

StoryBooker Adapter for interacting with GCP services.

69 lines (67 loc) 2.75 kB
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs'); let __storybooker_core_constants = require("@storybooker/core/constants"); __storybooker_core_constants = require_rolldown_runtime.__toESM(__storybooker_core_constants); //#region src/big-table.ts const COLUMN_FAMILY = "cf1"; var GcpBigtableDatabaseService = class { #instance; constructor(client, instanceName = __storybooker_core_constants.SERVICE_NAME) { this.init = async (_options) => { const [exists] = await this.#instance.exists(); if (!exists) throw new Error(`Bigtable instance '${this.#instance.id}' does not exist.`); }; this.listCollections = async (_options) => { const [tables] = await this.#instance.getTables(); return tables.map((table) => table.id); }; this.createCollection = async (collectionId, _options) => { await this.#instance.createTable(collectionId, { families: [COLUMN_FAMILY] }); }; this.hasCollection = async (collectionId, _options) => { const [exists] = await this.#instance.table(collectionId).exists(); return exists; }; this.deleteCollection = async (collectionId, _options) => { await this.#instance.table(collectionId).delete(); }; this.listDocuments = async (collectionId, _listOptions, _options) => { const [rows] = await this.#instance.table(collectionId).getRows(); const list = []; for (const row of rows) { const document = { ...row.data[COLUMN_FAMILY], id: row.id }; list.push(document); } return list; }; this.getDocument = async (collectionId, documentId, _options) => { const row = this.#instance.table(collectionId).row(documentId); const [exists] = await row.exists(); if (!exists) throw new Error(`Document '${documentId}' not found.`); const [rowData] = await row.get([COLUMN_FAMILY]); return { ...rowData, id: documentId }; }; this.createDocument = async (collectionId, documentData, _options) => { await this.#instance.table(collectionId).row(documentData.id).create({ entry: { [COLUMN_FAMILY]: documentData } }); }; this.hasDocument = async (collectionId, documentId, _options) => { const [exists] = await this.#instance.table(collectionId).row(documentId).exists(); return exists; }; this.deleteDocument = async (collectionId, documentId, _options) => { await this.#instance.table(collectionId).row(documentId).delete(); }; this.updateDocument = async (collectionId, documentId, documentData) => { await this.#instance.table(collectionId).row(documentId).save({ [COLUMN_FAMILY]: documentData }); }; this.#instance = client.instance(instanceName); } }; //#endregion exports.GcpBigtableDatabaseService = GcpBigtableDatabaseService; //# sourceMappingURL=big-table.cjs.map