Exploration of Temporal.io TypeScript SDK + Star Wars API
temporal server start-dev
to start Temporal Server.npm install
to install dependencies.npm run start.watch
to start the Worker.- In another shell,
npm run workflow
to run the Workflow.
Navigate to localhost:8233
(or wherever you have pointed your temporal server) to see the temporal web UI.
Fetches a list of people from the Star Wars API and filters based on rules. Supports OR
+ AND
filtering and containsNumber
, equals
, greaterThan
, and lessThan
operators. See matchesRule
for the full list of supported operators.
const rules: Rule[] = [
{
propertyName: 'name',
operator: 'containsNumbers',
value: null,
},
{
propertyName: 'eye_color',
operator: 'equals',
value: 'red',
},
];
Fetches a random quote from the star wars films api every minute and prints it to the console. When complete, returns a list of all quotes fetched. Return value looks something like: (truncated)
[
'It is a dark time for the Rebellion. ...etc',
'Turmoil has engulfed the Galactic Republic. ...etc',
'There is unrest in the Galactic Senate. ...etc',
'...etc',
];
npm run jest
will run the workflows and activities tests.
Coverage:
----------------|---------|----------|---------|---------|----------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------------|---------|----------|---------|---------|----------------------
All files | 65.45 | 88.88 | 75 | 64.81 |
src | 64.81 | 88.88 | 75 | 64.15 |
activities.ts | 80.95 | 50 | 100 | 80.95 | 10-11,16-17
workflows.ts | 54.54 | 93.75 | 66.66 | 53.12 | 23,29-32,45-47,52-63
src/test | 100 | 100 | 100 | 100 |
mockPeople.ts | 100 | 100 | 100 | 100 |
----------------|---------|----------|---------|---------|----------------------
Test Suites: 2 passed, 2 total
Tests: 12 passed, 12 total
Snapshots: 0 total
Time: 4.312 s
Configuring a Temporal project with TypeScript and ES Modules.
Fundamental difference from CommonJS:
package.json
has"type": "module"
attribute.tsconfig.json
outputs inesnext
format.- Imports must include the
.js
file extension.