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

This commit is contained in:
Kit Langton
2026-06-25 14:23:01 -04:00
committed by GitHub
parent 44806777ca
commit f44423609b
20 changed files with 1100 additions and 93 deletions
+18 -17
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) {