Implement main-thread Camino sessions and synchronous CRDT editing
This commit is contained in:
@@ -110,6 +110,7 @@ export class GenericSourceTypes {
|
||||
}
|
||||
if (type.kind === "list" || type.kind === "optional") return storable(type.value, depth + 1);
|
||||
if (type.kind === "record") return Object.values(type.fields).every((field) => storable(field, depth + 1));
|
||||
if (type.kind === "variant") return Object.values(type.cases).every((entry) => storable(entry.value, depth + 1));
|
||||
if (type.kind === "alias") {
|
||||
const alias = aliases.get(type.definitionId);
|
||||
if (!alias || alias.parameters.length !== type.arguments.length) return false;
|
||||
@@ -301,6 +302,24 @@ export class GenericSourceTypes {
|
||||
}
|
||||
|
||||
expression(context: ValueTypeContext): ValueTypeExpression {
|
||||
if (context.VARIANT()) {
|
||||
const entries = context.variantCase().map(
|
||||
(entry) =>
|
||||
[
|
||||
entry.identifier().getText(),
|
||||
{
|
||||
id: literal(entry.stringLiteral()),
|
||||
value: this.expression(entry.valueType()),
|
||||
},
|
||||
] as const,
|
||||
);
|
||||
if (
|
||||
new Set(entries.map(([label]) => label)).size !== entries.length ||
|
||||
new Set(entries.map(([, entry]) => entry.id)).size !== entries.length
|
||||
)
|
||||
throw new GenericTypeError("duplicate-variant-case", "variant", "Variant labels and case IDs must be unique");
|
||||
return { kind: "variant", id: literal(context.stringLiteral()!), cases: Object.fromEntries(entries) };
|
||||
}
|
||||
if (context.scalarType())
|
||||
return {
|
||||
kind: "scalar",
|
||||
|
||||
Reference in New Issue
Block a user