( params: SelectorRuntimeParams, )
| 63 | | null; |
| 64 | |
| 65 | export async function dispatchFindReadOnlyViaRuntime( |
| 66 | params: SelectorRuntimeParams, |
| 67 | ): Promise<DaemonResponse | null> { |
| 68 | const { req } = params; |
| 69 | if (req.command !== 'find') return null; |
| 70 | const args = req.positionals ?? []; |
| 71 | if (args.length === 0) return errorResponse('INVALID_ARGS', 'find requires a locator or text'); |
| 72 | const parsed = parseFindArgs(args); |
| 73 | if (!parsed.query) return errorResponse('INVALID_ARGS', 'find requires a value'); |
| 74 | if (req.flags?.findFirst && req.flags?.findLast) { |
| 75 | return errorResponse('INVALID_ARGS', 'find accepts only one of --first or --last'); |
| 76 | } |
| 77 | const action = parsed.action; |
| 78 | if (!isReadOnlyFindAction(action)) return null; |
| 79 | |
| 80 | const resolvedRuntime = await createSelectorRuntime(params, { |
| 81 | requireSession: false, |
| 82 | capability: 'find', |
| 83 | }); |
| 84 | if (!resolvedRuntime.ok) return resolvedRuntime.response; |
| 85 | |
| 86 | return await toDaemonResponse(async () => { |
| 87 | const result = await resolvedRuntime.runtime.selectors.find({ |
| 88 | session: params.sessionName, |
| 89 | requestId: req.meta?.requestId, |
| 90 | locator: parsed.locator, |
| 91 | query: parsed.query, |
| 92 | action, |
| 93 | timeoutMs: parsed.timeoutMs, |
| 94 | }); |
| 95 | recordIfSession( |
| 96 | params.sessionStore, |
| 97 | params.sessionName, |
| 98 | req, |
| 99 | buildFindRecordResult(result, action), |
| 100 | ); |
| 101 | return toDaemonFindData(result); |
| 102 | }); |
| 103 | } |
| 104 | |
| 105 | export async function dispatchGetViaRuntime( |
| 106 | params: SelectorRuntimeParams, |
no test coverage detected