(
input: UpdateToolPolicyInput,
)
| 6017 | ); |
| 6018 | |
| 6019 | const policiesUpdate = ( |
| 6020 | input: UpdateToolPolicyInput, |
| 6021 | ): Effect.Effect<ToolPolicy, OrgWriteDeniedError | StorageFailure> => |
| 6022 | transaction( |
| 6023 | Effect.gen(function* () { |
| 6024 | yield* guardOrgWrite(input.owner); |
| 6025 | if (input.pattern !== undefined && !isValidPattern(input.pattern)) { |
| 6026 | return yield* new StorageError({ |
| 6027 | message: `Invalid tool policy pattern: ${input.pattern}`, |
| 6028 | cause: undefined, |
| 6029 | }); |
| 6030 | } |
| 6031 | const where = (b: AnyCb) => b.and(byOwner(input.owner)(b), b("id", "=", input.id)); |
| 6032 | const existing = yield* core.findFirst("tool_policy", { where }); |
| 6033 | if (!existing) { |
| 6034 | return yield* new StorageError({ |
| 6035 | message: `Tool policy not found: ${input.id}`, |
| 6036 | cause: undefined, |
| 6037 | }); |
| 6038 | } |
| 6039 | const set: Record<string, unknown> = { updated_at: new Date() }; |
| 6040 | if (input.pattern !== undefined) set.pattern = input.pattern; |
| 6041 | if (input.action !== undefined) set.action = input.action; |
| 6042 | if (input.position !== undefined) set.position = input.position; |
| 6043 | yield* core.updateMany("tool_policy", { where, set }); |
| 6044 | const updated = yield* core.findFirst("tool_policy", { where }); |
| 6045 | if (!updated) { |
| 6046 | return yield* new StorageError({ |
| 6047 | message: `Tool policy disappeared while it was being updated: ${input.id}`, |
| 6048 | cause: undefined, |
| 6049 | }); |
| 6050 | } |
| 6051 | return rowToToolPolicy(updated); |
| 6052 | }), |
| 6053 | ); |
| 6054 | |
| 6055 | const policiesRemove = ( |
| 6056 | input: RemoveToolPolicyInput, |
no test coverage detected