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