MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeTransactionProto

Function makeTransactionProto

packages/platform/browser/src/IndexedDbDatabase.ts:545–654  ·  view source on GitHub ↗
({
  IDBKeyRange,
  database,
  tables,
  transaction,
  reactivity
}: {
  readonly database: MutableRef.MutableRef<globalThis.IDBDatabase>
  readonly IDBKeyRange: typeof globalThis.IDBKeyRange
  readonly tables: ReadonlyMap<string, IndexedDbVersion.Tables<Source>>
  readonly transaction: globalThis.IDBTransaction
  readonly reactivity: Reactivity.Reactivity["Service"]
})

Source from the content-addressed store, hash-verified

543 : false
544
545const 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

Callers 1

layerFunction · 0.85

Calls 3

makeMethod · 0.65
pipeMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected