( prefix: string, idKey: IdKey, namespace: string, dir: string, name: string, seed?: Effect.Effect<Iterable<Encoded>, E, R>, defaultValues?: Partial<Encoded> )
| 13 | import { makeMemoryStoreInt } from "./Memory.ts" |
| 14 | |
| 15 | function makeDiskStoreInt<IdKey extends keyof Encoded, Encoded extends FieldValues, R, E>( |
| 16 | prefix: string, |
| 17 | idKey: IdKey, |
| 18 | namespace: string, |
| 19 | dir: string, |
| 20 | name: string, |
| 21 | seed?: Effect.Effect<Iterable<Encoded>, E, R>, |
| 22 | defaultValues?: Partial<Encoded> |
| 23 | ) { |
| 24 | type PM = PersistenceModelType<Encoded> |
| 25 | return Effect.gen(function*() { |
| 26 | if (namespace !== "primary") { |
| 27 | dir = dir + "/" + namespace |
| 28 | if (!fs.existsSync(dir)) { |
| 29 | fs.mkdirSync(dir) |
| 30 | } |
| 31 | } |
| 32 | const file = dir + "/" + prefix + name + ".json" |
| 33 | const fileExtra = { "disk.file.path": file } |
| 34 | const fsStore = { |
| 35 | get: fu |
| 36 | .readTextFile(file) |
| 37 | .pipe( |
| 38 | annotateDb({ |
| 39 | operation: "read.readFile", |
| 40 | system: "disk", |
| 41 | collection: name, |
| 42 | namespace, |
| 43 | entity: name, |
| 44 | extra: fileExtra |
| 45 | }), |
| 46 | Effect.flatMap((x) => |
| 47 | Effect.sync(() => JSON.parse(x) as PM[]).pipe( |
| 48 | annotateDb({ |
| 49 | operation: "read.parse", |
| 50 | system: "disk", |
| 51 | collection: name, |
| 52 | namespace, |
| 53 | entity: name, |
| 54 | extra: fileExtra |
| 55 | }) |
| 56 | ) |
| 57 | ), |
| 58 | Effect.orDie, |
| 59 | annotateDb({ |
| 60 | operation: "read", |
| 61 | system: "disk", |
| 62 | collection: name, |
| 63 | namespace, |
| 64 | entity: name, |
| 65 | extra: fileExtra |
| 66 | }) |
| 67 | ), |
| 68 | setRaw: (v: Iterable<PM>) => |
| 69 | Effect |
| 70 | .sync(() => JSON.stringify([...v], undefined, 2)) |
| 71 | .pipe( |
| 72 | annotateDb({ |
no test coverage detected
searching dependent graphs…