( repoRoot: string, workerDirs: string[], envLocal: Map<string, string>, lanIp: string | undefined, dirUsesLanIp: Map<string, boolean> )
| 425 | serviceFilter?: Set<string> |
| 426 | ): SecretsStoreQuery[] { |
| 427 | const queries = new Map<string, SecretsStoreQuery>(); |
| 428 | for (const [name, svc] of services) { |
| 429 | if (svc.type !== 'worker') continue; |
| 430 | if (serviceFilter && !serviceFilter.has(name)) continue; |
| 431 | |
| 432 | const bindings = extractSecretsStoreBindings(repoRoot, svc.dir); |
| 433 | for (const binding of bindings) { |
| 434 | const cacheKey = `${svc.dir}:${binding.store_id}`; |
| 435 | if (queries.has(cacheKey)) continue; |
| 436 | const wranglerDir = path.join(repoRoot, svc.dir, '.wrangler'); |
| 437 | let persistenceDir = wranglerDir; |
| 438 | try { |
| 439 | persistenceDir = fs.realpathSync(wranglerDir); |
| 440 | } catch { |
| 441 | // Wrangler will create this service-local persistence directory on demand. |
| 442 | } |
| 443 | queries.set(cacheKey, { |
| 444 | cacheKey, |
| 445 | persistenceDir, |
| 446 | storeId: binding.store_id, |
| 447 | workerDir: svc.dir, |
| 448 | }); |
| 449 | } |
| 450 | } |
| 451 | return [...queries.values()]; |
| 452 | } |
| 453 | |
| 454 | async function loadLocalStoreSecrets( |
| 455 | repoRoot: string, |
| 456 | serviceFilter?: Set<string>, |
| 457 | options: AsyncPlanOptions = {} |
| 458 | ): Promise<Map<string, string>> { |
| 459 | const groups = new Map<string, SecretsStoreQuery[]>(); |
| 460 | for (const query of getSecretsStoreQueries(repoRoot, serviceFilter)) { |
| 461 | const group = groups.get(query.persistenceDir) ?? []; |
| 462 | group.push(query); |
| 463 | groups.set(query.persistenceDir, group); |
| 464 | } |
| 465 | |
| 466 | const listSecrets = options.listSecrets ?? listLocalStoreSecretsAsync; |
| 467 | const groupedResults = await mapWithConcurrency( |
| 468 | [...groups.values()], |
| 469 | options.concurrency ?? resolveEnvSyncConcurrency(), |
| 470 | async queries => { |
| 471 | const results: [string, string][] = []; |
| 472 | // Store IDs sharing one Wrangler persistence directory use the same local SQLite state. |
| 473 | for (const query of queries) { |
| 474 | results.push([query.cacheKey, await listSecrets(repoRoot, query.workerDir, query.storeId)]); |
| 475 | } |
| 476 | return results; |
| 477 | } |
no test coverage detected