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

Function withKeyPath

packages/effect/src/unstable/persistence/KeyValueStore.ts:360–373  ·  view source on GitHub ↗
(
      method: string,
      key: string,
      f: (path: string) => Effect.Effect<A, KeyValueStoreError>
    )

Source from the content-addressed store, hash-verified

358 const fs = yield* FileSystem.FileSystem
359 const path = yield* Path.Path
360 const withKeyPath = <A>(
361 method: string,
362 key: string,
363 f: (path: string) => Effect.Effect<A, KeyValueStoreError>
364 ): Effect.Effect<A, KeyValueStoreError> =>
365 key.length === 0 || key === "." || key === ".."
366 ? Effect.fail(
367 new KeyValueStoreError({
368 method,
369 key,
370 message: `Invalid key ${key}`
371 })
372 )
373 : f(path.join(directory, encodeURIComponent(key)))
374
375 if (!(yield* fs.exists(directory))) {
376 yield* fs.makeDirectory(directory, { recursive: true })

Callers 1

layerFileSystemFunction · 0.85

Calls 3

joinMethod · 0.80
fFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected