Skip to content

Commit

Permalink
Update Static values to perform checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Dec 4, 2024
1 parent 3593c11 commit 2960758
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 616 deletions.
14 changes: 13 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export async function handler(task: TaskBase, event: Event = {}) {
}

export default class TaskBase {
static name: string = 'default';

etl: TaskBaseSettings;
layer?: Static<typeof TaskLayer>;

Expand All @@ -94,7 +96,11 @@ export default class TaskBase {
* `ETL_LAYER` - The Integer Layer ID to get config information and post results to
* `ETL_TOKEN` - The access token specific to the Layer
*/
constructor() {
constructor(current?: string) {
if (current) {
env(current);
}

this.etl = {
api: process.env.ETL_API || '',
layer: process.env.ETL_LAYER || '',
Expand Down Expand Up @@ -265,6 +271,12 @@ export default class TaskBase {
throw new Error('Failed to get layer from ETL');
} else {
this.layer = await res_layer.typed(TaskLayer);

// Ensure you don't accidently run an ETL against a layer not of the same type - mostly for local dev
if (!this.layer.task.startsWith(this.constructor.name)) {
throw new Error(`Remote layer is not of type: ${this.constructor.name}`);
}

return this.layer;
}
}
Expand Down
Loading

0 comments on commit 2960758

Please sign in to comment.