(
toolkitId: string,
input: {
readonly pattern: string;
readonly action: ToolPolicyAction;
readonly position?: string;
},
)
| 365 | requireToolkit(toolkitId).pipe(Effect.flatMap(() => listPoliciesForRecord(toolkitId))); |
| 366 | |
| 367 | const createPolicy = ( |
| 368 | toolkitId: string, |
| 369 | input: { |
| 370 | readonly pattern: string; |
| 371 | readonly action: ToolPolicyAction; |
| 372 | readonly position?: string; |
| 373 | }, |
| 374 | ) => |
| 375 | Effect.gen(function* () { |
| 376 | yield* validatePolicyPattern(input.pattern); |
| 377 | const toolkit = yield* requireToolkit(toolkitId); |
| 378 | const existing = yield* listPoliciesForRecord(toolkitId); |
| 379 | const minPosition = existing |
| 380 | .map((row) => row.position) |
| 381 | .sort() |
| 382 | .at(0); |
| 383 | const now = Date.now(); |
| 384 | const id = newId("tkpol"); |
| 385 | const entry = yield* storage.policies.put({ |
| 386 | owner: toolkit.owner, |
| 387 | key: id, |
| 388 | data: { |
| 389 | id, |
| 390 | toolkitId, |
| 391 | pattern: input.pattern, |
| 392 | action: input.action, |
| 393 | position: input.position ?? generateKeyBetween(null, minPosition ?? null), |
| 394 | createdAt: now, |
| 395 | updatedAt: now, |
| 396 | }, |
| 397 | }); |
| 398 | return policyToResponse(entry.data); |
| 399 | }); |
| 400 | |
| 401 | const updatePolicy = ( |
| 402 | toolkitId: string, |
nothing calls this directly
no test coverage detected