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

Function makeSeedEffect

packages/infra/src/Store/Cosmos.ts:141–183  ·  view source on GitHub ↗
(ns: string)

Source from the content-addressed store, hash-verified

139 const ctx = yield* Effect.context<R>()
140 const seedCache = new Map<string, Effect.Effect<void>>()
141 const makeSeedEffect = (ns: string) => {
142 const markerId = ns === "primary" ? importedMarkerId : `${importedMarkerId}::${ns}`
143 return Effect
144 .promise(() =>
145 container
146 .item(markerId, markerId)
147 .read<{ id: string }>()
148 .then(({ resource }) => Option.fromNullishOr(resource))
149 )
150 .pipe(
151 Effect.flatMap((marker) => {
152 if (Option.isSome(marker)) return Effect.void
153 return InfraLogger.logInfo(`Creating mock data for ${name} (namespace: ${ns})`).pipe(
154 Effect.andThen(seed!),
155 Effect.flatMap((m) =>
156 Effect.flatMapOption(
157 Effect.succeed(toNonEmptyArray([...m])),
158 (a) => bulkSetInternal(a, ns).pipe(Effect.orDie)
159 )
160 ),
161 Effect.andThen(
162 Effect.promise(() =>
163 container.items.create({
164 _partitionKey: markerId,
165 id: markerId,
166 ttl: -1
167 })
168 )
169 ),
170 Effect.provide(ctx),
171 Effect.orDie
172 )
173 }),
174 Effect.withLogSpan(`Cosmos.seedCheck ${name} in ${ns} [effect-app/infra/Store]`),
175 annotateDb({
176 operation: "seed",
177 system: "cosmosdb",
178 collection: containerId,
179 namespace: ns,
180 entity: name
181 })
182 )
183 }
184 const seedNamespace = Effect.fn("seedNamespace")(function*(ns: string) {
185 if (!seed) return
186 let cached = seedCache.get(ns)

Callers 3

seedNamespaceFunction · 0.85
Cosmos.tsFile · 0.85
seedNamespaceFunction · 0.85

Calls 7

annotateDbFunction · 0.90
readMethod · 0.80
itemMethod · 0.80
bulkSetInternalFunction · 0.70
pipeMethod · 0.65
succeedMethod · 0.45
provideMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…