]> git.codecow.com Git - libnemo.git/commitdiff
Rename vault request task properties to avoid name collisions.
authorChris Duncan <chris@codecow.com>
Sun, 2 Aug 2026 21:25:24 +0000 (14:25 -0700)
committerChris Duncan <chris@codecow.com>
Sun, 2 Aug 2026 21:25:24 +0000 (14:25 -0700)
src/lib/vault/index.ts
src/lib/vault/vault-worker.ts

index ece62954a23103fe7f640644365e88ff319d7bca..2e5fa05bc9af03cb7315bb17028f92579f21ff4b 100644 (file)
@@ -7,8 +7,8 @@ import { Data } from '../database'
 
 type TaskData = {
        [key: string]: Data | Record<string, Data>
-       url: string
-       id: string
+       taskUrl: string
+       taskId: string
 }
 
 type Task = {
@@ -70,11 +70,11 @@ export class Vault {
                                buffers.push(d)
                        }
                }
-               const id = crypto.randomUUID()
+               const taskId = crypto.randomUUID()
                const data: TaskData = {
                        ...payload,
-                       url: this.#url,
-                       id
+                       taskUrl: this.#url,
+                       taskId
                }
                return new Promise((resolve, reject): void => {
                        const task: Task = {
@@ -82,7 +82,7 @@ export class Vault {
                                resolve,
                                reject
                        }
-                       this.#tasks.set(id, task)
+                       this.#tasks.set(taskId, task)
                        try {
                                console.log('host postMessage(data)', data)
                                BROWSER: this.#worker.postMessage(data, buffers)
@@ -109,19 +109,19 @@ export class Vault {
 
        #report (results: unknown): void {
                if (results == null) return
-               const { url, id, error, isLocked } = results as Record<string, unknown>
-               if (url === this.#url) {
-                       if (typeof id !== 'string') {
+               const { taskUrl, taskId, error, isLocked } = results as Record<string, unknown>
+               if (taskUrl === this.#url) {
+                       if (typeof taskId !== 'string') {
                                throw new Error('Vault worker job invalid ID')
                        }
                        if (typeof isLocked === 'boolean' && this.#isLocked !== isLocked) {
                                this.#isLocked = isLocked
                                this.dispatchEvent(new Event(isLocked ? LOCKED : UNLOCKED))
                        }
-                       if (id === 'autolock') return
-                       const task = this.#tasks.get(id)
+                       if (taskId === 'autolock') return
+                       const task = this.#tasks.get(taskId)
                        if (task == null) {
-                               throw new Error(`Vault worker returned results without an associated job for ID ${id}`)
+                               throw new Error(`Vault worker returned results without an associated task for ID ${taskId}`)
                        }
                        const { resolve, reject } = task
                        if (error != null) {
index 6380e92b923b1fe70be94d850731640b5c86c04a..e4b954f11429f54b8ebd9845e40eced4cd58ac8d 100644 (file)
@@ -27,10 +27,10 @@ const listener = (event: MessageEvent<any>): void => {
                throw new Error('Invalid data')
        }
        const data = event.data as Record<string, unknown>
-       const { url, id } = data
-       if (typeof id !== 'string') return
-       BROWSER: if (url !== location.href) return
-       NODE: if (url !== dec.toString(threadId)) return
+       const { taskUrl, taskId } = data
+       if (typeof taskId !== 'string') return
+       BROWSER: if (taskUrl !== location.href) return
+       NODE: if (taskUrl !== dec.toString(threadId)) return
        NODE: if (parentPort == null) setTimeout(() => listener(event), 0)
        const action = parseAction(data)
        const keySalt = parseKeySalt(action, data)
@@ -86,8 +86,8 @@ const listener = (event: MessageEvent<any>): void => {
                                        }
                                }
                        }
-                       result.url = url
-                       result.id = id
+                       result.taskUrl = taskUrl
+                       result.taskId = taskId
                        console.log('worker postMessage(result)', result)
                        //@ts-expect-error
                        BROWSER: self.postMessage(result, transfer)
@@ -101,8 +101,8 @@ const listener = (event: MessageEvent<any>): void => {
                                data = undefined
                        }
                        console.log('worker postMessage(error)', err)
-                       BROWSER: self.postMessage({ url, id, error: 'Failed to process Vault request', cause: err })
-                       NODE: parentPort?.postMessage({ data: { url, id, error: 'Failed to process Vault request', cause: err } })
+                       BROWSER: self.postMessage({ taskUrl, taskId, error: 'Failed to process Vault request', cause: err })
+                       NODE: parentPort?.postMessage({ data: { taskUrl, taskId, error: 'Failed to process Vault request', cause: err } })
                })
 }
 BROWSER: self.addEventListener('message', listener)