clockworklabs / clockworklabs/SpacetimeDB
TypeScript SDK - Don't use enums, namespaces
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 25.2k
- Forks
- 1.1k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 46
Description
Some parts of our SDK uses enums and one specific part(UpdateStatus) uses namespaces as a runtime feature. These are non-standard TS-only features which are compiled to JS. The input and output are vastly different. This should be converted to a class like all other modules in client_api folder.
Compiled output:
var UpdateStatus;
((UpdateStatus2) => {
function getAlgebraicType() {
return AlgebraicType.createSumType([
new SumTypeVariant("Committed", DatabaseUpdate.getAlgebraicType()),
new SumTypeVariant(
"Failed",
AlgebraicType.createPrimitiveType(BuiltinType.Type.String)
),
new SumTypeVariant("OutOfEnergy", AlgebraicType.createProductType([]))
]);
}
UpdateStatus2.getAlgebraicType = getAlgebraicType;
function serialize(value) {
switch (value.tag) {
case "Committed":
return { Committed: DatabaseUpdate.serialize(value.value) };
case "Failed":
return { Failed: value.value };
case "OutOfEnergy":
return { OutOfEnergy: [] };
default:
throw "unreachable";
}
}
UpdateStatus2.serialize = serialize;
UpdateStatus2.Committed = (value) => ({
tag: "Committed",
value
});
UpdateStatus2.Failed = (value) => ({ tag: "Failed", value });
UpdateStatus2.OutOfEnergy = { tag: "OutOfEnergy", value: void 0 };
function fromValue(value) {
let sumValue = value.asSumValue();
switch (sumValue.tag) {
case 0:
return {
tag: "Committed",
value: DatabaseUpdate.fromValue(sumValue.value)
};
case 1:
return { tag: "Failed", value: sumValue.value.asString() };
case 2:
return { tag: "OutOfEnergy", value: void 0 };
default:
throw "unreachable";
}
}
UpdateStatus2.fromValue = fromValue;
})(UpdateStatus || (UpdateStatus = {}));
enums deserve similar treatment
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting the TypeScript modules in the client_api folder, especially UpdateStatus, and compare their structure with the other class-based modules. Identify the enum definitions and the namespace-based runtime implementation, then review the compiled output and existing serialization patterns. Done means these modules no longer rely on TypeScript enums or namespaces while preserving their current runtime behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100