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

Function make

packages/effect-app/src/Model/Repository/internal/internal.ts:71–628  ·  view source on GitHub ↗
(
      args: [Evt] extends [never] ? {
          schemaContext?: Context.Context<RCtx>
          makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
          config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
            partitionValue?: (e?: Encoded) => string
          }
        }
        : {
          schemaContext?: Context.Context<RCtx>
          publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, RPublish>
          makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
          config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
            partitionValue?: (e?: Encoded) => string
          }
        }
    )

Source from the content-addressed store, hash-verified

69})
70
71const entityStateFromItems = (items: readonly unknown[]): string | undefined => {
72 const first = items[0]
73 if (first === null || typeof first !== "object" || !("_tag" in first)) return undefined
74 const tag = (first as { readonly _tag: unknown })._tag
75 return typeof tag === "string" ? tag : undefined
76}
77
78const timeSchema = (
79 operation: "decode" | "encode",
80 entity: string,
81 queryMode: "aggregate" | "collect" | "project" | "transform" | undefined,
82 itemCount: number,
83 entityState?: string
84) =>
85<A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
86 Effect.clockWith((clock) => {
87 const startedAt = clock.currentTimeNanosUnsafe()
88 const attributes = {
89 "app.entity": entity,
90 "app.schema.operation": operation,
91 ...(queryMode !== undefined && { "app.query.mode": queryMode }),
92 ...(entityState !== undefined && { "app.entity.state": entityState })
93 }
94 return Effect.onExit(self, () => {
95 const durationMs = Number(clock.currentTimeNanosUnsafe() - startedAt) / 1_000_000
96 const slow = durationMs >= SCHEMA_SLOW_MS
97 return Effect.all([
98 Effect.annotateCurrentSpan({
99 [`app.schema.${operation}.duration_ms`]: durationMs,
100 "app.schema.item_count": itemCount,
101 "app.schema.slow": slow,
102 ...(queryMode !== undefined && { "app.query.mode": queryMode }),
103 ...(entityState !== undefined && { "app.entity.state": entityState })
104 }),
105 Metric.update(
106 Metric.withAttributes(
107 operation === "decode" ? schemaDecodeDuration : schemaEncodeDuration,
108 attributes
109 ),
110 durationMs
111 ),
112 Metric.update(Metric.withAttributes(schemaItemCount, attributes), itemCount),
113 ...(slow
114 ? [Metric.update(Metric.withAttributes(schemaSlow, attributes), 1)] as const
115 : [])
116 ], { discard: true })
117 })
118 })
119
120/**
121 * A base implementation to create a repository.
122 */
123export function makeRepoInternal<
124 Evt = never
125>() {
126 return <
127 ItemType extends string,
128 R,

Callers 1

makeStoreFunction · 0.70

Calls 15

flatMapOptionFunction · 0.90
mapReverseFunction · 0.85
pickIdFromAstFunction · 0.85
saveAllFunction · 0.85
encodeIdOnlyFunction · 0.85
getDecodeManyFunction · 0.85
saveAllEFunction · 0.85
readMethod · 0.80
addFinalizerMethod · 0.80
syncMethod · 0.80
toArrayMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…