| 234 | } |
| 235 | }, |
| 236 | async readOrderedArray<T extends Record<string, unknown>>(documentId: string, name: string): Promise<T[] | null> { |
| 237 | const doc = await loadDoc(documentId) |
| 238 | if (!doc) return null |
| 239 | try { |
| 240 | const dataMap = doc.getMap(`${name}:data`) |
| 241 | const orderArray = doc.getArray<string>(`${name}:order`) |
| 242 | const rows: T[] = [] |
| 243 | for (const id of orderArray.toArray()) { |
| 244 | const row = toPlain(dataMap.get(id)) |
| 245 | if (isRecord(row)) rows.push(row as T) |
| 246 | } |
| 247 | return rows |
| 248 | } finally { |
| 249 | doc.destroy() |
| 250 | } |
| 251 | }, |
| 252 | } |
| 253 | } |