Skip to content

Commit ee615f6

Browse files
committed
chore: update @WorkGlow packages to version 0.2.0
- Bumped versions for @workglow/cli and workglow to 0.2.0. - Updated package.json and bun.lock to reflect the new versions. - Refactored task instantiation to use defaults for improved consistency across the codebase. - Removed deprecated options and streamlined task execution methods in various CLI groups.
1 parent 26edd25 commit ee615f6

13 files changed

Lines changed: 125 additions & 90 deletions

bun.lock

Lines changed: 51 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.8",
55
"description": "Workglow SEC is an example of using the Workglow AI library to build a tool for retrieving SEC data.",
66
"scripts": {
7-
"bunset": "bunset && git push",
7+
"bunset": "bunset --patch --push",
88
"publish": "bun run build && bun run test && bun run bunset",
99
"dev": "concurrently -c 'auto' -n 'sec:' 'bun:dev-*'",
1010
"dev-js": "bun build --watch --target=bun --sourcemap=external --packages=external --outdir ./dist ./src/sec.ts",
@@ -23,8 +23,8 @@
2323
"@modelcontextprotocol/sdk": "^1.27.1",
2424
"@sroussey/parse-address": "^2.4.2",
2525
"@sroussey/parse-full-name": "^2.0.0",
26-
"workglow": "0.0.126",
27-
"@workglow/cli": "0.0.126",
26+
"workglow": "0.2.0",
27+
"@workglow/cli": "0.2.0",
2828
"awesome-phonenumber": "^7.8.0",
2929
"cheerio": "^1.2.0",
3030
"cheerio-json-mapper": "^1.0.4",

src/cli/groups/bootstrap.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,26 @@ export function addBootstrapCommands(program: Command): void {
4343
const tasks: ITask[] = [];
4444
if (!options.skipDownload) {
4545
tasks.push(
46-
...Object.values(BULK_DOWNLOADS).map((config) => new BootstrapDownloadTask(config))
46+
...Object.values(BULK_DOWNLOADS).map(
47+
(c) =>
48+
new BootstrapDownloadTask({
49+
defaults: { url: c.url, targetFolder: c.targetFolder },
50+
})
51+
)
4752
);
4853
}
4954

5055
if (!options.skipIngest) {
5156
tasks.push(
5257
new FetchAllCikNamesTask(),
5358
new StoreCikNamesTask(),
54-
new BootstrapSubmissionsTask({ force }),
55-
new BootstrapCompanyFactsTask({ force })
59+
new BootstrapSubmissionsTask({ defaults: { force } }),
60+
new BootstrapCompanyFactsTask({ defaults: { force } })
5661
);
5762
}
5863

5964
if (!options.skipForms) {
60-
tasks.push(new UpdateAllFormsTask({ form: ["D", "C"], force }));
65+
tasks.push(new UpdateAllFormsTask({ defaults: { form: ["D", "C"], force } }));
6166
}
6267

6368
if (tasks.length > 0) {
@@ -89,7 +94,9 @@ export function addBootstrapCommands(program: Command): void {
8994

9095
for (const t of types) {
9196
const config = BULK_DOWNLOADS[t];
92-
const task = new BootstrapDownloadTask(config);
97+
const task = new BootstrapDownloadTask({
98+
defaults: { url: config.url, targetFolder: config.targetFolder },
99+
});
93100
await withCli(task).run();
94101
}
95102
});
@@ -110,11 +117,15 @@ export function addBootstrapCommands(program: Command): void {
110117
}
111118

112119
if (target === "submissions" || target === "all") {
113-
await withCli(new BootstrapSubmissionsTask({ force: options.force })).run();
120+
await withCli(
121+
new BootstrapSubmissionsTask({ defaults: { force: options.force } })
122+
).run();
114123
}
115124

116125
if (target === "facts" || target === "all") {
117-
await withCli(new BootstrapCompanyFactsTask({ force: options.force })).run();
126+
await withCli(
127+
new BootstrapCompanyFactsTask({ defaults: { force: options.force } })
128+
).run();
118129
}
119130

120131
if (

src/cli/groups/fetch.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ export function addFetchCommands(program: Command): void {
2222
const wf = new Workflow();
2323
wf.pipe(
2424
new FetchSubmissionsTask({
25-
cik: parseInt(cik),
26-
date: options.date ? secDate(options.date) : undefined,
25+
defaults: {
26+
cik: parseInt(cik),
27+
date: options.date ? secDate(options.date) : undefined,
28+
},
2729
}),
2830
new StoreSubmissionsTask()
2931
);
@@ -40,8 +42,10 @@ export function addFetchCommands(program: Command): void {
4042
const wf = new Workflow();
4143
wf.pipe(
4244
new FetchCompanyFactsTask({
43-
cik: parseInt(cik),
44-
date: options.date ? secDate(options.date) : undefined,
45+
defaults: {
46+
cik: parseInt(cik),
47+
date: options.date ? secDate(options.date) : undefined,
48+
},
4549
}),
4650
new StoreCompanyFactsTask()
4751
);
@@ -54,12 +58,11 @@ export function addFetchCommands(program: Command): void {
5458
.description("Fetch and store a specific form for a company")
5559
.action(async (cik: string, form: string, accession?: string) => {
5660
await runCommand(async () => {
57-
const task = new FetchAndStoreFormsTask({
61+
await withCli(new FetchAndStoreFormsTask()).run({
5862
cik: parseInt(cik),
5963
form,
6064
docid: accession,
6165
});
62-
await withCli(task).run();
6366
});
6467
});
6568

@@ -68,11 +71,10 @@ export function addFetchCommands(program: Command): void {
6871
.description("Process a specific accession document")
6972
.action(async (accession: string, filename?: string) => {
7073
await runCommand(async () => {
71-
const task = new ProcessAccessionDocFormTask({
74+
await withCli(new ProcessAccessionDocFormTask()).run({
7275
accessionNumber: accession,
7376
fileName: filename,
7477
});
75-
await withCli(task).run();
7678
});
7779
});
7880
}

src/cli/groups/sync.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ export function addSyncCommand(program: Command): void {
1717
.action(async (options) => {
1818
await runCommand(
1919
async () => {
20-
const indexFlow = pipe([new FetchDailyIndexTask({}), new StoreCikLastUpdatedTask()]);
20+
const indexFlow = pipe([new FetchDailyIndexTask(), new StoreCikLastUpdatedTask()]);
2121
await withCli(indexFlow).run();
2222

23-
await withCli(new UpdateAllSubmissionsTask({ force: options.force })).run();
24-
await withCli(new UpdateAllCompanyFactsTask({ force: options.force })).run();
23+
await withCli(new UpdateAllSubmissionsTask()).run({ force: options.force });
24+
await withCli(new UpdateAllCompanyFactsTask()).run({
25+
force: options.force,
26+
});
2527

2628
const formTypes = (options.forms as string).split(",");
27-
await withCli(new UpdateAllFormsTask({ form: formTypes, force: options.force })).run();
29+
await withCli(new UpdateAllFormsTask()).run({ form: formTypes, force: options.force });
2830
},
2931
{ force: options.force }
3032
);

src/cli/groups/update.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function addUpdateCommands(program: Command): void {
1515
.action(async (options) => {
1616
await runCommand(
1717
async () => {
18-
await withCli(new UpdateAllSubmissionsTask({ force: options.force })).run();
18+
await withCli(new UpdateAllSubmissionsTask()).run({ force: options.force });
1919
},
2020
{ force: options.force }
2121
);
@@ -28,7 +28,7 @@ export function addUpdateCommands(program: Command): void {
2828
.action(async (options) => {
2929
await runCommand(
3030
async () => {
31-
await withCli(new UpdateAllCompanyFactsTask({ force: options.force })).run();
31+
await withCli(new UpdateAllCompanyFactsTask()).run({ force: options.force });
3232
},
3333
{ force: options.force }
3434
);
@@ -42,7 +42,7 @@ export function addUpdateCommands(program: Command): void {
4242
await runCommand(
4343
async () => {
4444
const formTypes = types.split(",");
45-
await withCli(new UpdateAllFormsTask({ form: formTypes, force: options.force })).run();
45+
await withCli(new UpdateAllFormsTask()).run({ form: formTypes, force: options.force });
4646
},
4747
{ force: options.force }
4848
);

src/fetch/SecCachedFetchTask.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ export abstract class SecCachedFetchTask<
8989

9090
constructor(input: I, config: Partial<TaskConfig> = {}) {
9191
super(input as I & FetchUrlTaskInput, config);
92-
if (!(input as FetchUrlTaskInput).response_type) {
93-
const response_type = guessResponseType(this.inputToUrl(input), input as FetchUrlTaskInput);
94-
(input as FetchUrlTaskInput).response_type = response_type;
92+
const fetchInput = this.defaults as FetchUrlTaskInput & I;
93+
if (!fetchInput.response_type) {
94+
const response_type = guessResponseType(this.inputToUrl(fetchInput as I), fetchInput);
95+
fetchInput.response_type = response_type;
9596
(this.defaults as FetchUrlTaskInput).response_type = response_type;
9697
(this.runInputData as FetchUrlTaskInput).response_type = response_type;
9798
}
@@ -111,7 +112,7 @@ export abstract class SecCachedFetchTask<
111112
}
112113
}
113114

114-
execute(input: I & FetchUrlTaskInput, executeConfig: IExecuteContext): Promise<O | undefined> {
115+
async execute(input: I & FetchUrlTaskInput, executeConfig: IExecuteContext): Promise<O> {
115116
const url = this.inputToUrl(input);
116117
const response_type = guessResponseType(url, input);
117118

@@ -121,6 +122,6 @@ export abstract class SecCachedFetchTask<
121122
response_type: response_type,
122123
};
123124

124-
return super.execute(fetchInput as I & FetchUrlTaskInput, executeConfig);
125+
return (await super.execute(fetchInput as I & FetchUrlTaskInput, executeConfig)) as O;
125126
}
126127
}

src/fetch/SecFetchJob.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { FetchUrlJob, FetchUrlTaskInput, FetchUrlTaskOutput, JobQueueTaskConfig } from "workglow";
7+
import { FetchUrlJob, FetchUrlTaskInput, FetchUrlTaskOutput, JobConstructorParam } from "workglow";
88
import { SecUserAgent } from "../config/Constants";
99

1010
export class SecFetchJob<
1111
Input extends FetchUrlTaskInput = FetchUrlTaskInput,
1212
Output = FetchUrlTaskOutput,
1313
> extends FetchUrlJob<Input, Output> {
14-
constructor(config: JobQueueTaskConfig & { input: Input }) {
15-
// Set SEC-specific headers
16-
config.input.headers = {
14+
constructor(config: JobConstructorParam<Input, Output>) {
15+
const input = { ...config.input };
16+
input.headers = {
1717
"User-Agent": SecUserAgent,
18-
...config.input.headers,
18+
...input.headers,
1919
};
20-
super(config);
20+
super({ ...config, input });
2121
}
2222
}

src/fetch/SecFetchTask.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,33 @@
66

77
import {
88
FetchUrlTask,
9+
FetchUrlTaskConfig,
910
FetchUrlTaskInput,
1011
FetchUrlTaskOutput,
11-
Job,
12-
JobConstructorParam,
13-
JobQueueTaskConfig,
1412
TaskOutput,
1513
} from "workglow";
1614
import { SecJobQueueName, SecUserAgent } from "../config/Constants";
17-
import { SecFetchJob } from "./SecFetchJob";
1815

1916
/**
2017
* SEC-specific fetch task
2118
*/
2219
export class SecFetchTask<
2320
Input extends FetchUrlTaskInput = FetchUrlTaskInput,
2421
Output extends TaskOutput = FetchUrlTaskOutput,
25-
Config extends JobQueueTaskConfig = JobQueueTaskConfig,
22+
Config extends FetchUrlTaskConfig = FetchUrlTaskConfig,
2623
> extends FetchUrlTask<Input, Output, Config> {
2724
constructor(input: FetchUrlTaskInput = {} as FetchUrlTaskInput, config: Config = {} as Config) {
28-
config.queue = SecJobQueueName;
29-
input.queue = SecJobQueueName;
30-
31-
if (input.headers) {
32-
input.headers["User-Agent"] = SecUserAgent;
25+
const defaults: FetchUrlTaskInput = { ...input };
26+
if (defaults.headers) {
27+
defaults.headers = { ...defaults.headers, "User-Agent": SecUserAgent };
3328
} else {
34-
input.headers = { "User-Agent": SecUserAgent };
29+
defaults.headers = { "User-Agent": SecUserAgent };
3530
}
3631

37-
super(input as Input, config);
38-
this.jobClass = SecFetchJob as new (
39-
config: JobConstructorParam<Input, Output>
40-
) => Job<Input, Output>;
32+
super({
33+
...config,
34+
queue: SecJobQueueName,
35+
defaults: defaults as Partial<Input>,
36+
});
4137
}
4238
}

src/task/index/FetchDailyIndexTask.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ describe("FetchDailyIndexTask", () => {
132132
if (isErrorFile) {
133133
it(`should fail to get the daily index for ${date}`, async () => {
134134
try {
135-
const task = new FetchDailyIndexTask({ date });
136-
await task.run();
135+
const task = new FetchDailyIndexTask();
136+
await task.run({ date });
137137
expect.unreachable("This should not be reached");
138138
} catch (error: any) {
139139
expect(error).toBeInstanceOf(TaskFailedError);
140140
}
141141
});
142142
} else {
143143
it(`should get the daily index for ${date}`, async () => {
144-
const results = await new FetchDailyIndexTask({ date }).run();
144+
const results = await new FetchDailyIndexTask().run({ date });
145145
expect(results.updateList.length).toBeGreaterThan(100);
146146
expect(results.updateList[0][1]).toEqual(date);
147147
});

0 commit comments

Comments
 (0)