/** * @module simple-ibgib is stubbed for now. * * This came from a chat with Gemini regarding hiding some complexity contained * in the primitive transforms: mut8, rel8 and fork. This particular approach * Gemini came up with as an optimistic write-based manager to be used when * dealing with POJOs (or POTOs I suppose in TypeScript). * * I am leaving this here to be picked up at a later time, as this moves towards * a more ORM approach, and our near-term use case is more of a simplification * for consumption in our own blank-gib app. We mainly need to fix diverging * timelines and this was a conflict resolver approach, while I was working * towards a lock-based approach. */ import { clone } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs'; import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs'; import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs'; /** * Result of a save operation on a SimpleIbGib. */ export interface SimpleIbGibSaveResult { conflictDetected: boolean; // Optionally, include information about the new or merged ibgib address // newIbGibAddr?: IbGibAddr; // mergedIbGibAddr?: IbGibAddr; } /** * Represents a simplified view of an ibGib, exposing its data as a mutable POJO. * Internally tracks changes and the associated ibGib timeline state. */ export class Receipt { private manager: SimpleIbGib; private receiptId: string; // Internal ID for tracking by the manager /** * Private constructor. Instances are created via SimpleIbGibManager.track. */ private constructor(manager: SimpleIbGib, receiptId: string) { this.manager = manager; this.receiptId = receiptId; } /** * Get the mutable data as a POJO. Changes to this object are tracked. */ get data(): TData { return this.manager._getPojo(this.receiptId); } /** * Saves the tracked changes back to the ibGib timeline. * Handles optimistic concurrency control and basic merging internally. */ async save(): Promise { return await this.manager._saveReceiptChanges(this.receiptId); } // You could add other helper methods here for more complex operations, // which would internally call manager methods and track changes. // For example: // async addRel8n(name: string, targetAddr: IbGibAddr): Promise { ... } } /** * Manages SimpleIbGib instances, tracking their state and orchestrating * ibGib transforms and concurrency control based on POJO changes. */ export class SimpleIbGib { _getPojo(receiptId: string): TData { throw new Error('Method not implemented.'); } _saveReceiptChanges(receiptId: string): SimpleIbGibSaveResult | PromiseLike { throw new Error('Method not implemented.'); } // Internal map to track SimpleIbGib instances and their associated state private receiptMap = new Map(); private nextReceiptId = 0; // --- Public API for Consumers --- /** * Tracks a POJO, either by creating a new ibGib timeline for it * or by fetching an existing ibGib timeline. Returns a SimpleIbGib receipt. * * @param pojo The POJO to track. * @param initialIbGibAddr Optional. If provided, tracks the timeline starting at this address. * Otherwise, prepares to create a new timeline on save. * @returns A SimpleIbGib receipt representing the tracked POJO. */ async track(pojo: TData, initialIbGibAddr?: IbGibAddr): Promise> { const receiptId = `simple_ibgib_${this.nextReceiptId++}`; let latestAddr: IbGibAddr; let originalAddr: IbGibAddr; let clonedPojo: any; throw new Error(`not implemented (E: 7cf0bf8502037c79d41245d5f6c7c425)`); // if (initialIbGibAddr) { // // Fetch the latest version of the existing ibGib timeline // const ibGib = await this._fetchLatest(initialIbGibAddr); // latestAddr = getIbGibAddr({ // ibGib // }); // originalAddr = latestAddr; // At tracking, the latest is the original for diffing // clonedPojo = clone(ibGib.data); // } else { // // Prepare to create a new ibGib timeline on the first save // // Need a way to generate an initial address or // } } _fetchLatest(initialIbGibAddr: string) { throw new Error('Method not implemented.'); } }