generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a87cf6
commit 6c0bd6f
Showing
25 changed files
with
3,974 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class EmptyPipelineError extends Error { | ||
constructor(message?: string) { | ||
super(message || "The executed pipeline has no stages."); | ||
this.name = "EmptyPipelineError"; | ||
Error.captureStackTrace(this, EmptyPipelineError); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { EmptyPipelineError } from "@/errors/EmptyPipelineError"; | ||
import { IPipelineStage } from "@/pipelines/definition/stages/IPipelineStage"; | ||
|
||
export class Pipeline<T> { | ||
private firstStage: IPipelineStage<T> | null = null; | ||
private lastStage: IPipelineStage<T> | null = null; | ||
|
||
addStage(stage: IPipelineStage<T>): Pipeline<T> { | ||
if (!this.firstStage) { | ||
this.firstStage = this.lastStage = stage; | ||
} else { | ||
if (this.lastStage) { | ||
this.lastStage.next(stage); | ||
} | ||
this.lastStage = stage; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
process(request: T): T { | ||
if (!this.firstStage) { | ||
throw new EmptyPipelineError(); | ||
} | ||
|
||
return this.firstStage.process(request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { EmptyPipelineError } from "@/errors/EmptyPipelineError"; | ||
import { IPipelineAsyncStage } from "@/pipelines/definition/stages/IPipelineAsyncStage"; | ||
|
||
export class PipelineAsync<T> { | ||
private firstStage: IPipelineAsyncStage<T> | null = null; | ||
private lastStage: IPipelineAsyncStage<T> | null = null; | ||
|
||
addStage(stage: IPipelineAsyncStage<T>): PipelineAsync<T> { | ||
if (!this.firstStage) { | ||
this.firstStage = this.lastStage = stage; | ||
} else { | ||
if (this.lastStage) { | ||
this.lastStage.next(stage); | ||
} | ||
|
||
this.lastStage = stage; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
async process(request: T): Promise<T> { | ||
if (!this.firstStage) { | ||
throw new EmptyPipelineError(); | ||
} | ||
|
||
return this.firstStage.process(request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { IPipelineAsyncStage } from "@/pipelines/definition/stages/IPipelineAsyncStage"; | ||
|
||
export abstract class BasePipelineAsyncStage<T> | ||
implements IPipelineAsyncStage<T> | ||
{ | ||
private nextStage: IPipelineAsyncStage<T> | null = null; | ||
|
||
next(stage: IPipelineAsyncStage<T>): IPipelineAsyncStage<T> { | ||
this.nextStage = stage; | ||
return stage; | ||
} | ||
|
||
async process(request: T): Promise<T> { | ||
request = await this.execute(request); | ||
return this.nextStage ? this.nextStage.process(request) : request; | ||
} | ||
|
||
// Execute the stages user code. | ||
protected abstract execute(request: T): Promise<T>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { IPipelineStage } from "@/pipelines/definition/stages/IPipelineStage"; | ||
|
||
export abstract class BasePipelineStage<T> implements IPipelineStage<T> { | ||
private nextStage: IPipelineStage<T> | null = null; | ||
|
||
next(stage: IPipelineStage<T>): IPipelineStage<T> { | ||
this.nextStage = stage; | ||
return stage; | ||
} | ||
|
||
process(request: T): T { | ||
request = this.execute(request); | ||
return this.nextStage ? this.nextStage.process(request) : request; | ||
} | ||
|
||
// Execute the stage's user code. | ||
protected abstract execute(request: T): T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface IPipelineAsyncStage<T> { | ||
next(stage: IPipelineAsyncStage<T>): IPipelineAsyncStage<T>; | ||
process(request: T): Promise<T>; | ||
} |
Oops, something went wrong.