-
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.
Merge pull request #8 from x0k/workers-refactoring
Workers refactoring
- Loading branch information
Showing
71 changed files
with
602 additions
and
586 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
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 was deleted.
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
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
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
apps/ppp/src/content/design-patterns/factory/go/factory.ts
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 @@ | ||
// Only type imports are allowed | ||
|
||
import type { UniversalFactory } from "testing/actor"; | ||
|
||
import type { GoUniversalFactoryData } from "@/lib/workers/go"; | ||
|
||
import type { Input, Output } from "../tests-data"; | ||
|
||
export const factory: UniversalFactory< | ||
Input, | ||
Output, | ||
GoUniversalFactoryData<Input, Output> | ||
> = ({ makeTestRunnerFactory }) => { | ||
return makeTestRunnerFactory( | ||
({ paymentSystem, amount, base }) => | ||
`factory.Payment(factory.PaymentSystemType("${paymentSystem}"), ${base}, ${amount})` | ||
); | ||
}; |
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,2 @@ | ||
export { default as goCode } from "./code.go?raw"; | ||
export { factory as goFactory } from "./factory"; |
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
apps/ppp/src/content/design-patterns/factory/js/factory.ts
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,21 @@ | ||
// Only type imports are allowed | ||
import type { UniversalFactory } from "testing/actor"; | ||
|
||
import type { UniversalFactoryData } from "@/lib/workers/js"; | ||
|
||
import type { Input, Output } from "../tests-data"; | ||
import type { PaymentSystemType } from "../reference"; | ||
|
||
interface TestingModule { | ||
payment(type: PaymentSystemType, base: number, amount: number): number; | ||
} | ||
|
||
export const factory: UniversalFactory< | ||
Input, | ||
Output, | ||
UniversalFactoryData<TestingModule, Input, Output> | ||
> = ({ makeTestRunnerFactory }) => { | ||
return makeTestRunnerFactory(async (m, input) => | ||
m.payment(input.paymentSystem, input.base, input.amount) | ||
); | ||
}; |
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,2 @@ | ||
export { default as jsCode } from "./code.js?raw"; | ||
export { factory as jsFactory } from "./factory"; |
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
apps/ppp/src/content/design-patterns/factory/php/factory.ts
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,32 @@ | ||
// Only type imports are allowed | ||
import type { UniversalFactory } from "testing/actor"; | ||
|
||
import type { UniversalFactoryData } from "@/lib/workers/php"; | ||
|
||
import type { Input, Output } from "../tests-data"; | ||
|
||
// Const enum import is allowed | ||
import type { PaymentSystemType } from "../reference"; | ||
|
||
export const factory: UniversalFactory< | ||
Input, | ||
Output, | ||
UniversalFactoryData<Input, Output> | ||
> = ({ makeTestRunnerFactory }) => { | ||
const PHP_PAYMENT_SYSTEM_TYPES: Record<PaymentSystemType, string> = { | ||
paypal: "PaymentSystemType::PAYPAL", | ||
webmoney: "PaymentSystemType::WEBMONEY", | ||
"cat-bank": "PaymentSystemType::CAT_BANK", | ||
}; | ||
return makeTestRunnerFactory( | ||
({ paymentSystem, base, amount }: Input) => | ||
`strval(payment(${PHP_PAYMENT_SYSTEM_TYPES[paymentSystem]}, ${base}, ${amount}))`, | ||
(result: string) => { | ||
const r = parseInt(result, 10); | ||
if (isNaN(r)) { | ||
throw new Error(`Invalid result type: ${result}, expected number`); | ||
} | ||
return r; | ||
} | ||
); | ||
}; |
Oops, something went wrong.