(
input: UpdateToolPolicyInput,
)
| 5898 | ); |
| 5899 | |
| 5900 | const policiesUpdate = ( |
| 5901 | input: UpdateToolPolicyInput, |
| 5902 | ): Effect.Effect<ToolPolicy, OrgWriteDeniedError | StorageFailure> => |
| 5903 | transaction( |
| 5904 | Effect.gen(function* () { |
| 5905 | yield* guardOrgWrite(input.owner); |
| 5906 | if (input.pattern !== undefined && !isValidPattern(input.pattern)) { |
| 5907 | return yield* new StorageError({ |
| 5908 | message: `Invalid tool policy pattern: ${input.pattern}`, |
| 5909 | cause: undefined, |
| 5910 | }); |
| 5911 | } |
| 5912 | const where = (b: AnyCb) => b.and(byOwner(input.owner)(b), b("id", "=", input.id)); |
| 5913 | const existing = yield* core.findFirst("tool_policy", { where }); |
| 5914 | if (!existing) { |
| 5915 | return yield* new StorageError({ |
| 5916 | message: `Tool policy not found: ${input.id}`, |
| 5917 | cause: undefined, |
| 5918 | }); |
| 5919 | } |
| 5920 | const set: Record<string, unknown> = { updated_at: new Date() }; |
| 5921 | if (input.pattern !== undefined) set.pattern = input.pattern; |
| 5922 | if (input.action !== undefined) set.action = input.action; |
| 5923 | if (input.position !== undefined) set.position = input.position; |
| 5924 | yield* core.updateMany("tool_policy", { where, set }); |
| 5925 | const updated = yield* core.findFirst("tool_policy", { where }); |
| 5926 | if (!updated) { |
| 5927 | return yield* new StorageError({ |
| 5928 | message: `Tool policy disappeared while it was being updated: ${input.id}`, |
| 5929 | cause: undefined, |
| 5930 | }); |
| 5931 | } |
| 5932 | return rowToToolPolicy(updated); |
| 5933 | }), |
| 5934 | ); |
| 5935 | |
| 5936 | const policiesRemove = ( |
| 5937 | input: RemoveToolPolicyInput, |
no test coverage detected