(options?: {
readonly entryTablePrefix?: string
readonly remoteIdTable?: string
readonly compaction?: EventLogServerEncrypted.CompactionOptions | undefined
})
| 80 | * @since 4.0.0 |
| 81 | */ |
| 82 | export const makeStorage = (options?: { |
| 83 | readonly entryTablePrefix?: string |
| 84 | readonly remoteIdTable?: string |
| 85 | readonly compaction?: EventLogServerEncrypted.CompactionOptions | undefined |
| 86 | }): Effect.Effect< |
| 87 | EventLogServerEncrypted.Storage["Service"], |
| 88 | SqlError.SqlError, |
| 89 | SqlClient.SqlClient | Digest.Digest | Scope.Scope |
| 90 | > => |
| 91 | Effect.gen(function*() { |
| 92 | const digest = yield* Digest.Digest |
| 93 | const sql = (yield* SqlClient.SqlClient).withoutTransforms() |
| 94 | const config = yield* EventLogServerEncrypted.makeCompactionConfig(options?.compaction) |
| 95 | const graceMillis = Duration.toMillis(config.grace) |
| 96 | const lagMillis = Duration.toMillis(config.lag) |
| 97 | const stageTtlMillis = Duration.toMillis(config.stageTtl) |
| 98 | const sweepIntervalMillis = Duration.toMillis(config.sweepInterval) |
| 99 | |
| 100 | const tablePrefix = options?.entryTablePrefix ?? "effect_events" |
| 101 | const remoteIdTable = options?.remoteIdTable ?? "effect_remote_id" |
| 102 | const sessionAuthBindingsTable = `${tablePrefix}_session_auth_bindings` |
| 103 | |
| 104 | const remoteIdTableSql = sql(remoteIdTable) |
| 105 | const sessionAuthBindingsTableSql = sql(sessionAuthBindingsTable) |
| 106 | |
| 107 | yield* sql.onDialectOrElse({ |
| 108 | pg: () => |
| 109 | sql` |
| 110 | CREATE TABLE IF NOT EXISTS ${remoteIdTableSql} ( |
| 111 | remote_id BYTEA PRIMARY KEY |
| 112 | )`, |
| 113 | mysql: () => |
| 114 | sql` |
| 115 | CREATE TABLE IF NOT EXISTS ${remoteIdTableSql} ( |
| 116 | remote_id BINARY(16) PRIMARY KEY |
| 117 | )`, |
| 118 | mssql: () => |
| 119 | sql` |
| 120 | IF OBJECT_ID(${remoteIdTable}, N'U') IS NULL |
| 121 | CREATE TABLE ${remoteIdTableSql} ( |
| 122 | remote_id VARBINARY(16) PRIMARY KEY |
| 123 | )`, |
| 124 | orElse: () => |
| 125 | sql` |
| 126 | CREATE TABLE IF NOT EXISTS ${remoteIdTableSql} ( |
| 127 | remote_id BLOB PRIMARY KEY |
| 128 | )` |
| 129 | }) |
| 130 | |
| 131 | yield* sql.onDialectOrElse({ |
| 132 | pg: () => |
| 133 | sql` |
| 134 | CREATE TABLE IF NOT EXISTS ${sessionAuthBindingsTableSql} ( |
| 135 | public_key TEXT PRIMARY KEY, |
| 136 | signing_public_key BYTEA NOT NULL |
| 137 | )`, |
| 138 | mysql: () => |
| 139 | sql` |
no test coverage detected