MCPcopy Create free account
hub / github.com/effect-app/libs / makeDiskStoreInt

Function makeDiskStoreInt

packages/infra/src/Store/Disk.ts:15–160  ·  view source on GitHub ↗
(
  prefix: string,
  idKey: IdKey,
  namespace: string,
  dir: string,
  name: string,
  seed?: Effect.Effect<Iterable<Encoded>, E, R>,
  defaultValues?: Partial<Encoded>
)

Source from the content-addressed store, hash-verified

13import { makeMemoryStoreInt } from "./Memory.ts"
14
15function 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({

Callers 2

makeDiskStoreFunction · 0.85
ensureStoreFunction · 0.85

Calls 6

annotateDbFunction · 0.90
makeMemoryStoreIntFunction · 0.90
syncMethod · 0.80
parseMethod · 0.80
pipeMethod · 0.65
withPermitsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…