Skip to content

Commit

Permalink
derive-typescript: fail on unexpected requests
Browse files Browse the repository at this point in the history
Specifically, this ensures a derivation is failed and restarted if it
sees a second Request.Open, as happens today (we need to handle this
properly).

Also add handling for Request.Reqest, which happens during catalog
tests.
  • Loading branch information
jgraettinger committed Apr 7, 2023
1 parent 48444c1 commit 9e5368d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion crates/derive-typescript/src/codegen/main.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ for await (const line of stdin) {
flush?: Record<string, never>,
startCommit?: {
runtimeCheckpoint: any,
}
},
reset?: {}
};

if (request.read) {
Expand All @@ -83,5 +84,9 @@ for await (const line of stdin) {
} else if (request.startCommit) {
const startedCommit = derivation.startCommit(request.startCommit);
await emit({ startedCommit: startedCommit })
} else if (request.reset) {
await derivation.reset();
} else {
throw new Error(`unexpected request: ${JSON.stringify(request)}`);
}
}
5 changes: 4 additions & 1 deletion crates/derive-typescript/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export abstract class IDerivation {{
return [];
}}
// reset is called only when running catalog tests, and must reset any internal state.
async reset() {{ }}
// startCommit is notified of a runtime commit in progress, and returns an optional
// connector state update to be committed.
startCommit(_startCommit: {{ runtimeCheckpoint: unknown }}): {{ state?: {{ updated: unknown, mergePatch: boolean }} }} {{
Expand All @@ -88,7 +91,7 @@ export abstract class IDerivation {{
write!(
w,
r#"
abstract {method_name}(source: {{ doc: {source_name} }}): Document[];"#,
abstract {method_name}(read: {{ doc: {source_name} }}): Document[];"#,
)
.unwrap();
}
Expand Down

0 comments on commit 9e5368d

Please sign in to comment.