* Create a sharded WAL manager. * * @param opt.dir - Base directory to store shard files (defaults to process.cwd()) * @param opt.format - WAL format configuration * @param opt.groupId - Group ID for sharding (defaults to generated group ID) * @param opt.coordinatorIdEnvVar - Environm
(opt: {
debug?: boolean;
dir?: string;
format: WalFormat<T>;
groupId?: string;
coordinatorIdEnvVar: string;
autoCoordinator?: boolean;
})
| 170 | * @param opt.autoCoordinator - Whether to auto-set the coordinator ID on construction (defaults to true) |
| 171 | */ |
| 172 | constructor(opt: { |
| 173 | debug?: boolean; |
| 174 | dir?: string; |
| 175 | format: WalFormat<T>; |
| 176 | groupId?: string; |
| 177 | coordinatorIdEnvVar: string; |
| 178 | autoCoordinator?: boolean; |
| 179 | }) { |
| 180 | const { |
| 181 | dir, |
| 182 | format, |
| 183 | debug, |
| 184 | groupId, |
| 185 | coordinatorIdEnvVar, |
| 186 | autoCoordinator = true, |
| 187 | } = opt; |
| 188 | |
| 189 | if (debug != null) { |
| 190 | this.#debug = debug; |
| 191 | } |
| 192 | |
| 193 | // Determine groupId: use provided, then env var, or generate |
| 194 | const resolvedGroupId: string = |
| 195 | groupId == null ? getUniqueTimeId() : groupId; |
| 196 | // Validate groupId for path safety before using it |
| 197 | validateGroupId(resolvedGroupId); |
| 198 | |
| 199 | this.groupId = resolvedGroupId; |
| 200 | |
| 201 | if (dir) { |
| 202 | this.#dir = dir; |
| 203 | } |
| 204 | this.#format = format; |
| 205 | this.#coordinatorIdEnvVar = coordinatorIdEnvVar; |
| 206 | |
| 207 | if (autoCoordinator) { |
| 208 | ShardedWal.setCoordinatorProcess(this.#coordinatorIdEnvVar, this.#id); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Gets the unique instance ID for this ShardedWal. |
nothing calls this directly
no test coverage detected