@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 45 lines 1.67 KB
Raw
1 import type * as EffectSchema from "effect/Schema";
2 import * as Aggregate from "./Aggregate.ts";
3
4 /** A string Schema that keys instances by value, such as an org id. */
5 export type Schema = EffectSchema.Top & { readonly Type: string; readonly Encoded: string };
6
7 /**
8 * What keys the instances of a view, policy, projection or stream: an
9 * aggregate (one instance per aggregate ref), or a string Schema (one
10 * instance per value, with no aggregate behind it).
11 */
12 export type Any = Aggregate.Any | Schema;
13
14 /**
15 * How one instance of a key is addressed: a ref for an aggregate key, the
16 * value itself for a Schema key.
17 */
18 export type RefOf<K> = K extends Aggregate.Any
19 ? Aggregate.Ref<K>
20 : K extends EffectSchema.Top
21 ? K["Type"]
22 : never;
23
24 /** The id of one instance of a key: the aggregate id, or the Schema key's value. */
25 export type IdOf<K> = K extends Aggregate.Any
26 ? Aggregate.IdOf<K>
27 : K extends EffectSchema.Top
28 ? K["Type"]
29 : never;
30
31 /** Is this key an aggregate (and not a Schema)? @internal */
32 export const isAggregate = (key: Any): key is Aggregate.Any =>
33 (key as { readonly kind?: unknown }).kind === "Aggregate";
34
35 /** Address the instance `id` of a key. @internal */
36 export const refOf = (key: Any, id: string): RefOf<Any> =>
37 isAggregate(key) ? Aggregate.makeRef(key, id) : id;
38
39 /** The Schema of a key's ids: an aggregate's id schema, or the Schema key itself. @internal */
40 export const idSchemaOf = (key: Any): Schema =>
41 isAggregate(key) ? (key.definition.id as Schema) : key;
42
43 /** How a problem names a key: the aggregate's name, or "a key schema". @internal */
44 export const describe = (key: Any): string =>
45 isAggregate(key) ? key.aggregateName : "a key schema";