(
toolkitId: string,
input: {
readonly pattern: string;
readonly action: ToolPolicyAction;
readonly position?: string;
},
)
| 411 | requireToolkit(toolkitId).pipe(Effect.flatMap(() => listPoliciesForRecord(toolkitId))); |
| 412 | |
| 413 | const createPolicy = ( |
| 414 | toolkitId: string, |
| 415 | input: { |
| 416 | readonly pattern: string; |
| 417 | readonly action: ToolPolicyAction; |
| 418 | readonly position?: string; |
| 419 | }, |
| 420 | ) => |
| 421 | Effect.gen(function* () { |
| 422 | yield* validatePolicyPattern(input.pattern); |
| 423 | const toolkit = yield* requireToolkit(toolkitId); |
| 424 | const existing = yield* listPoliciesForRecord(toolkitId); |
| 425 | const minPosition = existing |
| 426 | .map((row) => row.position) |
| 427 | .sort() |
| 428 | .at(0); |
| 429 | const now = Date.now(); |
| 430 | const id = newId("tkpol"); |
| 431 | const entry = yield* storage.policies.put({ |
| 432 | owner: toolkit.owner, |
| 433 | key: id, |
| 434 | data: { |
| 435 | id, |
| 436 | toolkitId, |
| 437 | pattern: input.pattern, |
| 438 | action: input.action, |
| 439 | position: input.position ?? generateKeyBetween(null, minPosition ?? null), |
| 440 | createdAt: now, |
| 441 | updatedAt: now, |
| 442 | }, |
| 443 | }); |
| 444 | return policyToResponse(entry.data); |
| 445 | }); |
| 446 | |
| 447 | const updatePolicy = ( |
| 448 | toolkitId: string, |
nothing calls this directly
no test coverage detected