MCPcopy Create free account
hub / github.com/anomalyco/opencode / define

Function define

packages/schema/src/event.ts:42–70  ·  view source on GitHub ↗
(input: {
  readonly type: Type
  readonly durable?: {
    readonly version: number
    readonly aggregate: string
  }
  readonly schema: Fields
})

Source from the content-addressed store, hash-verified

40}
41
42export function define<
43 const Type extends string,
44 const Fields extends Readonly<Record<PropertyKey, Schema.Codec<unknown, unknown>>>,
45>(input: {
46 readonly type: Type
47 readonly durable?: {
48 readonly version: number
49 readonly aggregate: string
50 }
51 readonly schema: Fields
52}) {
53 const data = Schema.Struct(input.schema)
54 return Schema.Struct({
55 id: ID,
56 metadata: optional(Schema.Record(Schema.String, Schema.Unknown)),
57 type: Schema.Literal(input.type),
58 durable: optional(Schema.Struct({ aggregateID: Schema.String, seq: Schema.Int, version: Schema.Int })),
59 location: optional(Location.Ref),
60 data,
61 })
62 .annotate({ identifier: input.type })
63 .pipe(
64 statics(() => ({
65 type: input.type,
66 ...(input.durable === undefined ? {} : { durable: input.durable }),
67 data,
68 })),
69 ) satisfies Definition<Type, typeof data>
70}
71
72export function inventory<const Definitions extends ReadonlyArray<Definition>>(...definitions: Definitions) {
73 return Object.freeze(definitions)

Callers 15

catalog.tsFile · 0.90
permission.tsFile · 0.90
plugin.tsFile · 0.90
session-todo.tsFile · 0.90
filesystem.tsFile · 0.90
models-dev.tsFile · 0.90
integration.tsFile · 0.90
project.tsFile · 0.90
reference.tsFile · 0.90
pty.tsFile · 0.90
question.tsFile · 0.90

Calls 2

optionalFunction · 0.90
staticsFunction · 0.90

Tested by

no test coverage detected