(
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
}
}
)
| 69 | }) |
| 70 | |
| 71 | const 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 | |
| 78 | const 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 | */ |
| 123 | export function makeRepoInternal< |
| 124 | Evt = never |
| 125 | >() { |
| 126 | return < |
| 127 | ItemType extends string, |
| 128 | R, |
no test coverage detected
searching dependent graphs…