| 543 | : false |
| 544 | |
| 545 | const makeTransactionProto = <Source extends IndexedDbVersion.AnyWithProps>({ |
| 546 | IDBKeyRange, |
| 547 | database, |
| 548 | tables, |
| 549 | transaction, |
| 550 | reactivity |
| 551 | }: { |
| 552 | readonly database: MutableRef.MutableRef<globalThis.IDBDatabase> |
| 553 | readonly IDBKeyRange: typeof globalThis.IDBKeyRange |
| 554 | readonly tables: ReadonlyMap<string, IndexedDbVersion.Tables<Source>> |
| 555 | readonly transaction: globalThis.IDBTransaction |
| 556 | readonly reactivity: Reactivity.Reactivity["Service"] |
| 557 | }): Transaction<Source> => { |
| 558 | const migration = IndexedDbQueryBuilder.make({ |
| 559 | database, |
| 560 | IDBKeyRange, |
| 561 | tables, |
| 562 | reactivity |
| 563 | }) as any |
| 564 | |
| 565 | migration.transaction = transaction |
| 566 | |
| 567 | migration.createObjectStore = Effect.fnUntraced(function*(table: string) { |
| 568 | const createTable = yield* Effect.fromNullishOr(tables.get(table)).pipe( |
| 569 | Effect.mapError( |
| 570 | (cause) => |
| 571 | new IndexedDbDatabaseError({ |
| 572 | reason: "MissingTable", |
| 573 | cause |
| 574 | }) |
| 575 | ) |
| 576 | ) |
| 577 | |
| 578 | return yield* Effect.try({ |
| 579 | try: () => |
| 580 | database.current.createObjectStore(createTable.tableName, { |
| 581 | keyPath: createTable.keyPath, |
| 582 | autoIncrement: createTable.autoIncrement |
| 583 | }), |
| 584 | catch: (cause) => |
| 585 | new IndexedDbDatabaseError({ |
| 586 | reason: "TransactionError", |
| 587 | cause |
| 588 | }) |
| 589 | }) |
| 590 | }) |
| 591 | |
| 592 | migration.deleteObjectStore = Effect.fnUntraced(function*(table: string) { |
| 593 | const createTable = yield* Effect.fromNullishOr(tables.get(table)).pipe( |
| 594 | Effect.mapError( |
| 595 | (cause) => |
| 596 | new IndexedDbDatabaseError({ |
| 597 | reason: "MissingTable", |
| 598 | cause |
| 599 | }) |
| 600 | ) |
| 601 | ) |
| 602 | |