createOptimisticEventSchema
constcreateOptimisticEventSchema: ({ valueSchema, defaultValue, partialSet, }) =>Schema.transform<typeofSchema.Unknown,Schema.Schema<any,any,never> |Schema.SchemaClass<{[x:string]:any; }, {[x:string]:any; },never>>
Defined in: packages/@livestore/common/dist/schema/state/sqlite/client-document-def.d.ts:56
Creates an optimistic schema that accepts historical event formats and transforms them to the current schema, preserving data and intent.
Decision Matrix for Schema Changes:
| Change Type | Partial Set | Full Set | Strategy |
|---|---|---|---|
| Compatible Changes | |||
| Add optional field | Preserve existing | Preserve existing, new field undefined | Direct decode or merge |
| Add required field | Preserve existing | Preserve existing, new field from default | Merge with defaults |
| Incompatible Changes | |||
| Remove field | Drop removed field | Drop removed field, preserve others | Filter & decode |
| Type change | Use default for field | Use default for changed field | Selective merge |
| Rename field | Use default | Use default (can’t detect rename) | Fall back to default |
| Edge Cases | |||
| Empty event | Return {} | Return full default | Fallback handling |
| Invalid structure | Return {} | Return full default | Fallback handling |
Parameters
Section titled “Parameters”{ valueSchema, defaultValue, partialSet, }
Section titled “{ valueSchema, defaultValue, partialSet, }”defaultValue
Section titled “defaultValue”any
partialSet
Section titled “partialSet”boolean
valueSchema
Section titled “valueSchema”Schema.Schema<any, any>
Returns
Section titled “Returns”Schema.transform<typeof Schema.Unknown, Schema.Schema<any, any, never> | Schema.SchemaClass<{[x: string]: any; }, {[x: string]: any; }, never>>