forked from nanobus/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiota.ts
91 lines (77 loc) · 2.09 KB
/
iota.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import {
Application,
Authorization,
callProvider,
Flow,
Handler,
Response,
toDataExpr,
} from "https://deno.land/x/[email protected]/mod.ts";
export interface ShortenerShortenArgs {
url: string;
}
export interface ShortenerLookupArgs {
id: string;
}
export interface URL {
/** The dynamically generated URL identifier. */
id: string;
/** The original URL that was shortened. */
url: string;
}
export interface ShortenerOper {
shorten?: Flow<ShortenerShortenArgs>;
lookup?: Flow<ShortenerLookupArgs>;
}
export interface ShortenerAuth {
shorten?: Authorization;
lookup?: Authorization;
}
export const Shortener = {
$interface: "urlshortener.v1.Shortener",
shorten: "urlshortener.v1.Shortener::shorten" as Handler,
lookup: "urlshortener.v1.Shortener::lookup" as Handler,
register(app: Application, iface: ShortenerOper): void {
app.register(
Shortener as unknown as Record<string, Handler>,
iface as Record<string, Flow<unknown>>,
);
},
authorize(app: Application, auths: ShortenerAuth): void {
app.authorize(
Shortener as unknown as Record<string, Handler>,
auths as Record<string, Authorization>,
);
},
};
export interface RepositoryLoadByIdArgs {
id: string;
}
export interface RepositoryLoadByURLArgs {
url: string;
}
export interface RepositoryOper {
loadById?: Flow<RepositoryLoadByIdArgs>;
loadByURL?: Flow<RepositoryLoadByURLArgs>;
storeURL?: Flow<URL>;
}
export const Repository = {
$interface: "urlshortener.v1.Repository",
loadById: "urlshortener.v1.Repository::loadById" as Handler,
loadByURL: "urlshortener.v1.Repository::loadByURL" as Handler,
storeURL: "urlshortener.v1.Repository::storeURL" as Handler,
register(app: Application, iface: RepositoryOper): void {
app.provide(
Repository as unknown as Record<string, Handler>,
iface as Record<string, Flow<unknown>>,
);
},
};
export const repositoryClient = {
loadById(id: string): Response<URL> {
const dataExpr = `{
"id": ${toDataExpr(id)},
}`;
return callProvider(Repository.loadById, dataExpr) as Response<URL>;
},
};