(
toolkitId: string,
input: {
readonly pattern: string;
readonly position?: string;
},
)
| 482 | requireToolkit(toolkitId).pipe(Effect.flatMap(() => listConnectionsForRecord(toolkitId))); |
| 483 | |
| 484 | const createConnection = ( |
| 485 | toolkitId: string, |
| 486 | input: { |
| 487 | readonly pattern: string; |
| 488 | readonly position?: string; |
| 489 | }, |
| 490 | ) => |
| 491 | Effect.gen(function* () { |
| 492 | yield* validatePolicyPattern(input.pattern); |
| 493 | const toolkit = yield* requireToolkit(toolkitId); |
| 494 | const existing = yield* listConnectionsForRecord(toolkitId); |
| 495 | const duplicate = existing.find((connection) => connection.pattern === input.pattern); |
| 496 | if (duplicate) return connectionToResponse(duplicate); |
| 497 | const minPosition = existing |
| 498 | .map((row) => row.position) |
| 499 | .sort() |
| 500 | .at(0); |
| 501 | const now = Date.now(); |
| 502 | const id = newId("tkconn"); |
| 503 | const entry = yield* storage.connections.put({ |
| 504 | owner: toolkit.owner, |
| 505 | key: id, |
| 506 | data: { |
| 507 | id, |
| 508 | toolkitId, |
| 509 | pattern: input.pattern, |
| 510 | position: input.position ?? generateKeyBetween(null, minPosition ?? null), |
| 511 | createdAt: now, |
| 512 | updatedAt: now, |
| 513 | }, |
| 514 | }); |
| 515 | return connectionToResponse(entry.data); |
| 516 | }); |
| 517 | |
| 518 | const removeConnection = (toolkitId: string, connectionId: string) => |
| 519 | Effect.gen(function* () { |
no test coverage detected