(
toolkitId: string,
input: {
readonly pattern: string;
readonly position?: string;
},
)
| 436 | requireToolkit(toolkitId).pipe(Effect.flatMap(() => listConnectionsForRecord(toolkitId))); |
| 437 | |
| 438 | const createConnection = ( |
| 439 | toolkitId: string, |
| 440 | input: { |
| 441 | readonly pattern: string; |
| 442 | readonly position?: string; |
| 443 | }, |
| 444 | ) => |
| 445 | Effect.gen(function* () { |
| 446 | yield* validatePolicyPattern(input.pattern); |
| 447 | const toolkit = yield* requireToolkit(toolkitId); |
| 448 | const existing = yield* listConnectionsForRecord(toolkitId); |
| 449 | const duplicate = existing.find((connection) => connection.pattern === input.pattern); |
| 450 | if (duplicate) return connectionToResponse(duplicate); |
| 451 | const minPosition = existing |
| 452 | .map((row) => row.position) |
| 453 | .sort() |
| 454 | .at(0); |
| 455 | const now = Date.now(); |
| 456 | const id = newId("tkconn"); |
| 457 | const entry = yield* storage.connections.put({ |
| 458 | owner: toolkit.owner, |
| 459 | key: id, |
| 460 | data: { |
| 461 | id, |
| 462 | toolkitId, |
| 463 | pattern: input.pattern, |
| 464 | position: input.position ?? generateKeyBetween(null, minPosition ?? null), |
| 465 | createdAt: now, |
| 466 | updatedAt: now, |
| 467 | }, |
| 468 | }); |
| 469 | return connectionToResponse(entry.data); |
| 470 | }); |
| 471 | |
| 472 | const removeConnection = (toolkitId: string, connectionId: string) => |
| 473 | Effect.gen(function* () { |
no test coverage detected