(input: {
readonly type: Type
readonly durable?: {
readonly version: number
readonly aggregate: string
}
readonly schema: Fields
})
| 40 | } |
| 41 | |
| 42 | export 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 | |
| 72 | export function inventory<const Definitions extends ReadonlyArray<Definition>>(...definitions: Definitions) { |
| 73 | return Object.freeze(definitions) |
no test coverage detected