feat(sdk): restore session runtime operations (#33777)

This commit is contained in:
Kit Langton 2026-06-25 20:23:01 +02:00 committed by GitHub
commit f44423609b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 1099 additions and 92 deletions

View file

@ -41,7 +41,7 @@ export type Payload<D extends Definition = Definition> = {
export function define<
const Type extends string,
Fields extends Readonly<Record<PropertyKey, Schema.Codec<unknown, unknown>>>,
const Fields extends Readonly<Record<PropertyKey, Schema.Codec<unknown, unknown>>>,
>(input: {
readonly type: Type
readonly durable?: {
@ -49,23 +49,24 @@ export function define<
readonly aggregate: string
}
readonly schema: Fields
}): Schema.Schema<Payload<Definition<Type, Schema.Struct<Fields>>>> & Definition<Type, Schema.Struct<Fields>> {
}) {
const data = Schema.Struct(input.schema)
return Object.assign(
Schema.Struct({
id: ID,
metadata: optional(Schema.Record(Schema.String, Schema.Unknown)),
type: Schema.Literal(input.type),
durable: optional(Schema.Struct({ aggregateID: Schema.String, seq: Schema.Number, version: Schema.Number })),
location: optional(Location.Ref),
data,
}).annotate({ identifier: input.type }),
{
type: input.type,
...(input.durable === undefined ? {} : { durable: input.durable }),
data,
},
) as Schema.Schema<Payload<Definition<Type, Schema.Struct<Fields>>>> & Definition<Type, Schema.Struct<Fields>>
return Schema.Struct({
id: ID,
metadata: optional(Schema.Record(Schema.String, Schema.Unknown)),
type: Schema.Literal(input.type),
durable: optional(Schema.Struct({ aggregateID: Schema.String, seq: Schema.Number, version: Schema.Number })),
location: optional(Location.Ref),
data,
})
.annotate({ identifier: input.type })
.pipe(
statics(() => ({
type: input.type,
...(input.durable === undefined ? {} : { durable: input.durable }),
data,
})),
) satisfies Definition<Type, typeof data>
}
export function inventory<const Definitions extends ReadonlyArray<Definition>>(...definitions: Definitions) {