{ "node": "v24.22.3", "runtime": { "type": "object", "keys": [ "DurableWriteAcknowledger", "IpcSyncRequester", "TemporarilyUnavailableError", "WriteAdmissionGuard" ], "members": { "DurableWriteAcknowledger": { "type": "function", "length": 1, "source": "class DurableWriteAcknowledger {\n /**\n * Constructor.\n *\n * @param {DurableWriteAcknowledgerParams} params - Parameters.\n */\n constructor ({\n litestreamClient,\n timeoutSeconds,\n queueHash,\n writeAdmissionGuard,\n }) {\n this.litestreamClient = litestreamClient\n this.timeoutSeconds = timeoutSeconds\n this.queueHash = queueHash\n this.writeAdmissionGuard = writeAdmissionGuard\n }\n\n /**\n * Factory method.\n *\n * @template {X extends typeof DurableWriteAcknowledger ? X : never} T, X\n * @param {DurableWriteAcknowledgerFactoryParams} params - Parameters for the factory method.\n * @returns {InstanceType} Instance of this class.\n * @this {T}\n */\n static create ({\n litestreamClient,\n timeoutSeconds = 5,\n writeAdmissionGuard = null,\n }) {\n return /** @type {InstanceType} */ (\n new this({\n litestreamClient,\n timeoutSeconds,\n queueHash: new Map(),\n writeAdmissionGuard,\n })\n )\n }\n\n /**\n * Wait until what is committed to the database file so far is in the replica.\n *\n * @param {{\n * databasePath: string\n * }} params - Parameters.\n * @returns {Promise} Resolves once the replica holds the write.\n * @throws {TemporarilyUnavailableError} When the replica cannot be reached, so the write is not durable.\n */\n async waitUntilReplicated ({\n databasePath,\n }) {\n const queue = this.findQueue({\n databasePath,\n })\n\n if (queue.waitingSync) {\n return this.awaitSync({\n sync: queue.waitingSync,\n })\n }\n\n const waitingSync = queue.lastSync.then(() => {\n queue.waitingSync = null\n\n return this.litestreamClient.syncAndWait({\n databasePath,\n timeoutSeconds: this.timeoutSeconds,\n })\n })\n\n queue.waitingSync = waitingSync\n queue.lastSync = waitingSync.catch(() => null)\n\n return this.awaitSync({\n sync: waitingSync,\n })\n }\n\n /**\n * Find the queue of one database file, and start it when there is none.\n *\n * @param {{\n * databasePath: string\n * }} params - Parameters.\n * @returns {SyncQueue} The queue.\n */\n findQueue ({\n databasePath,\n }) {\n const existingQueue = this.queueHash.get(databasePath)\n\n if (existingQueue) {\n return existingQueue\n }\n\n const queue = {\n lastSync: Promise.resolve(),\n waitingSync: null,\n }\n\n this.queueHash.set(databasePath, queue)\n\n return queue\n }\n\n /**\n * Wait for one sync, and turn its failure", "proto": [ "constructor", "waitUntilReplicated", "findQueue", "awaitSync" ] }, "IpcSyncRequester": { "type": "function", "length": 1, "source": "class IpcSyncRequester {\n /**\n * Constructor.\n *\n * @param {IpcSyncRequesterParams} params - Parameters.\n */\n constructor ({\n processClient,\n timeoutMilliseconds,\n requestIdSupplier,\n timerClient,\n requestState,\n }) {\n this.processClient = processClient\n this.timeoutMilliseconds = timeoutMilliseconds\n this.requestIdSupplier = requestIdSupplier\n this.timerClient = timerClient\n this.requestState = requestState\n }\n\n /**\n * Factory method.\n *\n * @template {X extends typeof IpcSyncRequester ? X : never} T, X\n * @param {IpcSyncRequesterFactoryParams} [params] - Parameters for the factory method.\n * @returns {InstanceType} Instance of this class.\n * @this {T}\n */\n static create ({\n processClient = process,\n timeoutMilliseconds = 10000,\n requestIdSupplier = () => crypto.randomUUID(),\n timerClient = {\n startTimer: setTimeout,\n stopTimer: clearTimeout,\n },\n } = {}) {\n return /** @type {InstanceType} */ (\n new this({\n processClient,\n timeoutMilliseconds,\n requestIdSupplier,\n timerClient,\n requestState: {\n isListening: false,\n pendingHash: new Map(),\n },\n })\n )\n }\n\n /**\n * Ask the supervisor to make what is committed so far reach the replica, and wait until it has.\n *\n * @param {{\n * databasePath: string\n * timeoutSeconds: number\n * }} params - Parameters.\n * @returns {Promise} The message of the answer (empty on success).\n * @throws {Error} When the supervisor answers a failure, does not answer in time, or cannot be reached.\n */\n async syncAndWait ({\n databasePath,\n timeoutSeconds,\n }) {\n this.listenForResults()\n\n const requestId = this.requestIdSupplier()\n\n return new Promise((resolve, reject) => {\n const timerHandle = this.timerClient.startTimer(() => {\n this.requestState.pendingHash.delete(requestId)\n\n reject(new Error(`sync request ${requestId} timed out after ${this.timeoutMilliseconds} ms`))\n }, this.timeoutMilliseconds)\n\n this.requestState.pendingHash.set(requestId, {\n resolve,\n reject,\n timerHandle,\n })\n\n this.sendRequest({\n requestId,\n databasePath,\n timeoutSeconds,\n })\n })\n }\n\n /**\n * Start to listen for answers, once.\n *\n * @returns {void}\n */\n listenForResults () {\n if (this.requestState.isListening) {\n return\n }\n\n this.requestState", "proto": [ "constructor", "syncAndWait", "listenForResults", "receiveMessage", "sendRequest", "failRequest" ] }, "TemporarilyUnavailableError": { "type": "function", "length": 1, "source": "class TemporarilyUnavailableError extends Error {\n /**\n * Constructor.\n *\n * @param {TemporarilyUnavailableErrorParams} params - Parameters.\n */\n constructor ({\n reasonName,\n message,\n code,\n status,\n }) {\n super(message)\n\n this.name = 'TemporarilyUnavailable'\n this.reasonName = reasonName\n this.code = code\n this.status = status\n }\n\n /**\n * Factory method.\n *\n * @template {X extends typeof TemporarilyUnavailableError ? X : never} T, X\n * @param {TemporarilyUnavailableErrorFactoryParams} params - Parameters for the factory method.\n * @returns {InstanceType} Instance of this class.\n * @this {T}\n */\n static create ({\n reasonName,\n message = reasonName,\n }) {\n return /** @type {InstanceType} */ (\n new this({\n reasonName,\n message,\n code: ERROR_CODE,\n status: HTTP_STATUS,\n })\n )\n }\n\n /**\n * Build the body a prototype answers with.\n *\n * The message is left out: it carries what Litestream or the bucket said, which names the bucket, paths and the\n * service account. It stays on the error for the log.\n *\n * @returns {{\n * error: {\n * code: string\n * name: string\n * reasonName: string\n * }\n * }} The body.\n */\n buildResponseBody () {\n return {\n error: {\n code: this.code,\n name: this.name,\n reasonName: this.reasonName,\n },\n }\n }\n}", "proto": [ "constructor", "buildResponseBody" ] }, "WriteAdmissionGuard": { "type": "function", "length": 1, "source": "class WriteAdmissionGuard {\n /**\n * Constructor.\n *\n * @param {WriteAdmissionGuardParams} params - Parameters.\n */\n constructor ({\n processClient,\n nowSupplier,\n state,\n }) {\n this.processClient = processClient\n this.nowSupplier = nowSupplier\n this.state = state\n }\n\n /**\n * Factory method.\n *\n * @template {X extends typeof WriteAdmissionGuard ? X : never} T, X\n * @param {WriteAdmissionGuardFactoryParams} [params] - Parameters for the factory method.\n * @returns {InstanceType} Instance of this class.\n * @this {T}\n */\n static create ({\n processClient = process,\n nowSupplier = () => Date.now(),\n } = {}) {\n return /** @type {InstanceType} */ (\n new this({\n processClient,\n nowSupplier,\n state: {\n canWrite: false,\n reasonName: 'NoPermissionYet',\n validUntilEpochMilliseconds: 0,\n },\n })\n )\n }\n\n /**\n * Start to listen for the supervisor's messages.\n *\n * @returns {void}\n */\n listen () {\n this.processClient.on('message', message => this.receiveMessage({\n message,\n }))\n }\n\n /**\n * Take the permission a message carries.\n *\n * @param {{\n * message: any\n * }} params - Parameters.\n * @returns {void}\n */\n receiveMessage ({\n message,\n }) {\n if (message?.type !== MESSAGE_TYPE) {\n return\n }\n\n this.state = {\n canWrite: message.canWrite,\n reasonName: message.reasonName,\n validUntilEpochMilliseconds: message.validUntilEpochMilliseconds,\n }\n }\n\n /**\n * Check whether a write may start now.\n *\n * @returns {boolean} True when the supervisor has permitted it and the permission has not lapsed.\n */\n canWrite () {\n return this.state.canWrite\n && this.nowSupplier() < this.state.validUntilEpochMilliseconds\n }\n\n /**\n * Refuse a write that may not start now.\n *\n * @returns {void}\n * @throws {TemporarilyUnavailableError} When the instance may not write.\n */\n assertWritable () {\n if (this.canWrite()) {\n return\n }\n\n const reasonName = this.state.canWrite\n ? 'LeaseLapsed'\n : this.state.reasonName\n\n throw TemporarilyUnavailableError.create({\n reasonName,\n })\n }\n}", "proto": [ "constructor", "listen", "receiveMessage", "canWrite", "assertWritable" ] } }, "entry": "/node_modules/hora-prototype-runtime/hosted-base-image/application.js", "dir": "/node_modules/hora-prototype-runtime", "files": [ "base-image", "hosted-base-image", "package.json", "persistence" ], "pkg": { "exports": { ".": "./hosted-base-image/application.js" }, "type": "module" } }, "dataDir": [ "app.db", "app.db-shm", "app.db-wal" ] }