generated from utily/library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Realm.ts
42 lines (40 loc) · 1.21 KB
/
Realm.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { isoly } from "isoly"
import { isly } from "isly"
import { Supplier as modelSupplier } from "./Supplier"
export type Realm = typeof Realm.realms[number]
export namespace Realm {
export const realms = ["test", "testUK", "uk", "eu", "upcheck"] as const
export const type: isly.Type<Realm> = isly.string(realms)
export const is = type.is
export const flaw = type.flaw
export function toString(): string {
return realms.toString().replaceAll(",", ", ") + "."
}
export const currency: Record<Realm, isoly.Currency> = {
test: "EUR",
upcheck: "EUR",
testUK: "GBP",
uk: "GBP",
eu: "EUR",
}
export const suppliers: Record<Realm, modelSupplier[]> = {
test: ["paxgiro", "paxgiroCredit"],
testUK: ["clearbank"],
uk: ["clearbank"],
eu: [],
upcheck: ["paxgiro"],
}
export interface Suppliers extends Record<Realm, modelSupplier[]> {
test: ["paxgiro", "paxgiroCredit"]
testUK: ["clearbank"]
uk: ["clearbank"]
eu: []
upcheck: ["paxgiro"]
}
export type Supplier<P extends keyof Suppliers> = Pick<Suppliers, P>[P][number]
export namespace Supplier {
export function is(realm: Realm, supplier: modelSupplier | any): supplier is Supplier<Realm> {
return suppliers[realm].includes(supplier)
}
}
}