dfx 0.17.8 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cache/driver.d.ts +23 -0
- package/Cache/driver.js +3 -0
- package/Cache/driver.js.map +1 -0
- package/Cache/gateway.d.ts +22 -0
- package/Cache/gateway.js +99 -0
- package/Cache/gateway.js.map +1 -0
- package/Cache/index.d.ts +70 -0
- package/Cache/index.js +54 -0
- package/Cache/index.js.map +1 -0
- package/Cache/memory.d.ts +3 -0
- package/Cache/memory.js +48 -0
- package/Cache/memory.js.map +1 -0
- package/Cache/memoryTTL.d.ts +24 -0
- package/Cache/memoryTTL.js +122 -0
- package/Cache/memoryTTL.js.map +1 -0
- package/Cache/prelude.d.ts +47 -0
- package/Cache/prelude.js +31 -0
- package/Cache/prelude.js.map +1 -0
- package/DiscordGateway/DiscordWS/index.d.ts +2 -3
- package/DiscordGateway/DiscordWS/index.js +1 -3
- package/DiscordGateway/DiscordWS/index.js.map +1 -1
- package/DiscordGateway/Shard/index.d.ts +1 -1
- package/DiscordGateway/Shard/index.js +1 -1
- package/DiscordGateway/Shard/index.js.map +1 -1
- package/DiscordGateway/Sharder/index.d.ts +1 -1
- package/DiscordGateway/Sharder/index.js +1 -1
- package/DiscordGateway/Sharder/index.js.map +1 -1
- package/DiscordGateway/WS/index.d.ts +1 -6
- package/DiscordGateway/WS/index.js +16 -23
- package/DiscordGateway/WS/index.js.map +1 -1
- package/DiscordGateway/index.d.ts +3 -2
- package/DiscordGateway/index.js +2 -0
- package/DiscordGateway/index.js.map +1 -1
- package/DiscordREST/index.d.ts +3 -3
- package/DiscordREST/index.js +4 -4
- package/DiscordREST/index.js.map +1 -1
- package/Http/index.js +1 -2
- package/Http/index.js.map +1 -1
- package/Interactions/context.d.ts +5 -4
- package/Interactions/context.js +7 -6
- package/Interactions/context.js.map +1 -1
- package/Interactions/handlers.js +2 -2
- package/Interactions/handlers.js.map +1 -1
- package/{RateLimitStore → RateLimit}/index.d.ts +1 -0
- package/{RateLimitStore → RateLimit}/index.js +1 -0
- package/RateLimit/index.js.map +1 -0
- package/{RateLimitStore → RateLimit}/memory.d.ts +0 -0
- package/{RateLimitStore → RateLimit}/memory.js +0 -0
- package/RateLimit/memory.js.map +1 -0
- package/{RateLimitStore → RateLimit}/utils.d.ts +0 -0
- package/{RateLimitStore → RateLimit}/utils.js +0 -0
- package/RateLimit/utils.js.map +1 -0
- package/gateway.d.ts +7 -5
- package/gateway.js +2 -0
- package/gateway.js.map +1 -1
- package/global.d.ts +1 -1
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/package.json +6 -6
- package/utils/effect.d.ts +0 -5
- package/utils/effect.js +1 -14
- package/utils/effect.js.map +1 -1
- package/webhooks.d.ts +3 -3
- package/RateLimitStore/index.js.map +0 -1
- package/RateLimitStore/memory.js.map +0 -1
- package/RateLimitStore/utils.js.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Effect } from "@effect/io/Effect";
|
|
2
|
+
import { Maybe } from "dfx";
|
|
3
|
+
export interface ParentCacheStoreDriver<E, T> {
|
|
4
|
+
readonly size: Effect<never, E, number>;
|
|
5
|
+
sizeForParent: (parentId: string) => Effect<never, E, number>;
|
|
6
|
+
get: (parentId: string, resourceId: string) => Effect<never, E, Maybe<T>>;
|
|
7
|
+
getForParent: (parentId: string) => Effect<never, E, Maybe<ReadonlyMap<string, T>>>;
|
|
8
|
+
set: (parentId: string, resourceId: string, resource: T) => Effect<never, E, void>;
|
|
9
|
+
delete: (parentId: string, resourceId: string) => Effect<never, E, void>;
|
|
10
|
+
parentDelete: (parentId: string) => Effect<never, E, void>;
|
|
11
|
+
refreshTTL: (parentId: string, resourceId: string) => Effect<never, E, void>;
|
|
12
|
+
readonly run: Effect<never, E, void>;
|
|
13
|
+
}
|
|
14
|
+
export declare const createParentDriver: <E, T>(driver: ParentCacheStoreDriver<E, T>) => ParentCacheStoreDriver<E, T>;
|
|
15
|
+
export interface CacheStoreDriver<E, T> {
|
|
16
|
+
readonly size: Effect<never, E, number>;
|
|
17
|
+
get: (resourceId: string) => Effect<never, E, Maybe<T>>;
|
|
18
|
+
set: (resourceId: string, resource: T) => Effect<never, E, void>;
|
|
19
|
+
delete: (resourceId: string) => Effect<never, E, void>;
|
|
20
|
+
refreshTTL: (resourceId: string) => Effect<never, E, void>;
|
|
21
|
+
readonly run: Effect<never, E, void>;
|
|
22
|
+
}
|
|
23
|
+
export declare const createDriver: <E, T>(driver: CacheStoreDriver<E, T>) => CacheStoreDriver<E, T>;
|
package/Cache/driver.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../../src/Cache/driver.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAoC,EACpC,EAAE,CAAC,MAAM,CAAA;AAWX,MAAM,CAAC,MAAM,YAAY,GAAG,CAAO,MAA8B,EAAE,EAAE,CAAC,MAAM,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EffectSource } from "callbag-effect-ts/Source";
|
|
2
|
+
import { Discord } from "dfx";
|
|
3
|
+
import { ParentCacheOp, CacheOp } from "./index.js";
|
|
4
|
+
export interface OpsSourceOpts<R, E, A> {
|
|
5
|
+
id: (a: A) => string;
|
|
6
|
+
fromParent: EffectSource<R, E, [parentId: string, resources: A[]]>;
|
|
7
|
+
create: EffectSource<R, E, [parentId: string, resource: A]>;
|
|
8
|
+
update: EffectSource<R, E, [parentId: string, resource: A]>;
|
|
9
|
+
remove: EffectSource<R, E, [parentId: string, id: string]>;
|
|
10
|
+
parentRemove: EffectSource<R, E, string>;
|
|
11
|
+
}
|
|
12
|
+
export declare const source: <R, E, T>({ id, fromParent, create, update, remove, parentRemove, }: OpsSourceOpts<R, E, T>) => import("callbag-effect-ts/Source").EffectSource<R, E, ParentCacheOp<T>>;
|
|
13
|
+
export interface NonParentOpsSourceOpts<R, E, A> {
|
|
14
|
+
id: (a: A) => string;
|
|
15
|
+
create: EffectSource<R, E, A>;
|
|
16
|
+
update: EffectSource<R, E, A>;
|
|
17
|
+
remove: EffectSource<R, E, string>;
|
|
18
|
+
}
|
|
19
|
+
export declare const nonParentSource: <R, E, T>({ id, create, update, remove, }: NonParentOpsSourceOpts<R, E, T>) => import("callbag-effect-ts/Source").EffectSource<R, E, CacheOp<T>>;
|
|
20
|
+
export declare const guilds: import("callbag-effect-ts/Source").EffectSource<import("../DiscordGateway/index.js").DiscordGateway, never, CacheOp<import("../types.js").Guild>>;
|
|
21
|
+
export declare const channels: import("callbag-effect-ts/Source").EffectSource<import("../DiscordGateway/index.js").DiscordGateway, never, ParentCacheOp<import("../types.js").Channel>>;
|
|
22
|
+
export declare const roles: import("callbag-effect-ts/Source").EffectSource<import("../DiscordGateway/index.js").DiscordGateway, never, ParentCacheOp<import("../types.js").Role>>;
|
package/Cache/gateway.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "callbag-effect-ts/Source/fromIterable";
|
|
2
|
+
import * as tsplus_module_2 from "callbag-effect-ts/Source/chain";
|
|
3
|
+
import * as tsplus_module_3 from "callbag-effect-ts/Source/map";
|
|
4
|
+
import * as tsplus_module_4 from "callbag-effect-ts/Source/merge";
|
|
5
|
+
import * as tsplus_module_5 from "dfx/gateway";
|
|
6
|
+
export const source = ({ id, fromParent, create, update, remove, parentRemove, }) => {
|
|
7
|
+
const fromParentOps = tsplus_module_2.chain(([parentId, a]) => tsplus_module_1.fromIterable(a.map((resource) => ({
|
|
8
|
+
op: "create",
|
|
9
|
+
parentId,
|
|
10
|
+
resourceId: id(resource),
|
|
11
|
+
resource,
|
|
12
|
+
}))))(fromParent);
|
|
13
|
+
const createOps = tsplus_module_3.map(([parentId, resource]) => ({
|
|
14
|
+
op: "create",
|
|
15
|
+
parentId,
|
|
16
|
+
resourceId: id(resource),
|
|
17
|
+
resource,
|
|
18
|
+
}))(create);
|
|
19
|
+
const updateOps = tsplus_module_3.map(([parentId, resource]) => ({
|
|
20
|
+
op: "update",
|
|
21
|
+
parentId,
|
|
22
|
+
resourceId: id(resource),
|
|
23
|
+
resource,
|
|
24
|
+
}))(update);
|
|
25
|
+
const removeOps = tsplus_module_3.map(([parentId, resourceId]) => ({
|
|
26
|
+
op: "delete",
|
|
27
|
+
parentId,
|
|
28
|
+
resourceId,
|
|
29
|
+
}))(remove);
|
|
30
|
+
const parentRemoveOps = tsplus_module_3.map((parentId) => ({
|
|
31
|
+
op: "parentDelete",
|
|
32
|
+
parentId,
|
|
33
|
+
}))(parentRemove);
|
|
34
|
+
return tsplus_module_4.merge(parentRemoveOps)(tsplus_module_4.merge(removeOps)(tsplus_module_4.merge(updateOps)(tsplus_module_4.merge(createOps)(fromParentOps))));
|
|
35
|
+
};
|
|
36
|
+
export const nonParentSource = ({ id, create, update, remove, }) => {
|
|
37
|
+
const createOps = tsplus_module_3.map((resource) => ({
|
|
38
|
+
op: "create",
|
|
39
|
+
resourceId: id(resource),
|
|
40
|
+
resource,
|
|
41
|
+
}))(create);
|
|
42
|
+
const updateOps = tsplus_module_3.map((resource) => ({
|
|
43
|
+
op: "update",
|
|
44
|
+
resourceId: id(resource),
|
|
45
|
+
resource,
|
|
46
|
+
}))(update);
|
|
47
|
+
const removeOps = tsplus_module_3.map((resourceId) => ({
|
|
48
|
+
op: "delete",
|
|
49
|
+
resourceId,
|
|
50
|
+
}))(remove);
|
|
51
|
+
return tsplus_module_4.merge(removeOps)(tsplus_module_4.merge(updateOps)(createOps));
|
|
52
|
+
};
|
|
53
|
+
// Guilds
|
|
54
|
+
export const guilds = nonParentSource({
|
|
55
|
+
id: (g) => g.id,
|
|
56
|
+
create: tsplus_module_3.map((g) => ({
|
|
57
|
+
...g,
|
|
58
|
+
channels: [],
|
|
59
|
+
roles: [],
|
|
60
|
+
emojis: [],
|
|
61
|
+
members: [],
|
|
62
|
+
}))(tsplus_module_5.Gateway.fromDispatch("GUILD_CREATE")),
|
|
63
|
+
update: tsplus_module_5.Gateway.fromDispatch("GUILD_UPDATE"),
|
|
64
|
+
remove: tsplus_module_3.map((a) => a.id)(tsplus_module_5.Gateway.fromDispatch("GUILD_DELETE")),
|
|
65
|
+
});
|
|
66
|
+
// Channels
|
|
67
|
+
export const channels = source({
|
|
68
|
+
id: (a) => a.id,
|
|
69
|
+
fromParent: tsplus_module_3.map((g) => [
|
|
70
|
+
g.id,
|
|
71
|
+
g.channels,
|
|
72
|
+
])(tsplus_module_5.Gateway.fromDispatch("GUILD_CREATE")),
|
|
73
|
+
create: tsplus_module_3.map((c) => [c.guild_id, c])(tsplus_module_5.Gateway.fromDispatch("CHANNEL_CREATE")),
|
|
74
|
+
update: tsplus_module_3.map((c) => [c.guild_id, c])(tsplus_module_5.Gateway.fromDispatch("CHANNEL_UPDATE")),
|
|
75
|
+
remove: tsplus_module_3.map((a) => [
|
|
76
|
+
a.guild_id,
|
|
77
|
+
a.id,
|
|
78
|
+
])(tsplus_module_5.Gateway.fromDispatch("CHANNEL_DELETE")),
|
|
79
|
+
parentRemove: tsplus_module_3.map((g) => g.id)(tsplus_module_5.Gateway.fromDispatch("GUILD_DELETE")),
|
|
80
|
+
});
|
|
81
|
+
// Roles
|
|
82
|
+
export const roles = source({
|
|
83
|
+
id: (a) => a.id,
|
|
84
|
+
fromParent: tsplus_module_3.map((g) => [g.id, g.roles])(tsplus_module_5.Gateway.fromDispatch("GUILD_CREATE")),
|
|
85
|
+
create: tsplus_module_3.map((r) => [
|
|
86
|
+
r.guild_id,
|
|
87
|
+
r.role,
|
|
88
|
+
])(tsplus_module_5.Gateway.fromDispatch("GUILD_ROLE_CREATE")),
|
|
89
|
+
update: tsplus_module_3.map((r) => [
|
|
90
|
+
r.guild_id,
|
|
91
|
+
r.role,
|
|
92
|
+
])(tsplus_module_5.Gateway.fromDispatch("GUILD_ROLE_UPDATE")),
|
|
93
|
+
remove: tsplus_module_3.map((a) => [
|
|
94
|
+
a.guild_id,
|
|
95
|
+
a.role_id,
|
|
96
|
+
])(tsplus_module_5.Gateway.fromDispatch("GUILD_ROLE_DELETE")),
|
|
97
|
+
parentRemove: tsplus_module_3.map((g) => g.id)(tsplus_module_5.Gateway.fromDispatch("GUILD_DELETE")),
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/Cache/gateway.ts"],"names":[],"mappings":";;;;;AAWA,MAAM,CAAC,MAAM,MAAM,GAAG,CAAU,EAC9B,EAAE,EACF,UAAU,EACV,MAAM,EACN,MAAM,EACN,MAAM,EACN,YAAY,GACW,EAAE,EAAE;IAC3B,MAAM,aAAa,GAAG,sBAAiB,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CACvD,6BACE,CAAC,CAAC,GAAG,CACH,CAAC,QAAQ,EAAoB,EAAE,CAAC,CAAC;QAC/B,EAAE,EAAE,QAAQ;QACZ,QAAQ;QACR,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC;QACxB,QAAQ;KACT,CAAC,CACH,CACF,EAVmB,UAAU,CAW/B,CAAA;IAED,MAAM,SAAS,GAAG,oBAChB,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAoB,EAAE,CAAC,CAAC;QAC3C,EAAE,EAAE,QAAQ;QACZ,QAAQ;QACR,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC;QACxB,QAAQ;KACT,CAAC,EANc,MAAM,CAOvB,CAAA;IAED,MAAM,SAAS,GAAG,oBAChB,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAoB,EAAE,CAAC,CAAC;QAC3C,EAAE,EAAE,QAAQ;QACZ,QAAQ;QACR,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC;QACxB,QAAQ;KACT,CAAC,EANc,MAAM,CAOvB,CAAA;IAED,MAAM,SAAS,GAAG,oBAChB,CA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2
|
+
import { EffectSource } from "callbag-effect-ts/Source";
|
|
3
|
+
import { ParentCacheStoreDriver, CacheStoreDriver } from "./driver.js";
|
|
4
|
+
export * from "./driver.js";
|
|
5
|
+
export { createWithParent as memoryParentDriver, create as memoryDriver, } from "./memory.js";
|
|
6
|
+
export { createWithParent as memoryTTLParentDriver, create as memoryTTLDriver, } from "./memoryTTL.js";
|
|
7
|
+
export type ParentCacheOp<T> = {
|
|
8
|
+
op: "create";
|
|
9
|
+
parentId: string;
|
|
10
|
+
resourceId: string;
|
|
11
|
+
resource: T;
|
|
12
|
+
} | {
|
|
13
|
+
op: "update";
|
|
14
|
+
parentId: string;
|
|
15
|
+
resourceId: string;
|
|
16
|
+
resource: T;
|
|
17
|
+
} | {
|
|
18
|
+
op: "delete";
|
|
19
|
+
parentId: string;
|
|
20
|
+
resourceId: string;
|
|
21
|
+
} | {
|
|
22
|
+
op: "parentDelete";
|
|
23
|
+
parentId: string;
|
|
24
|
+
};
|
|
25
|
+
export type CacheOp<T> = {
|
|
26
|
+
op: "create";
|
|
27
|
+
resourceId: string;
|
|
28
|
+
resource: T;
|
|
29
|
+
} | {
|
|
30
|
+
op: "update";
|
|
31
|
+
resourceId: string;
|
|
32
|
+
resource: T;
|
|
33
|
+
} | {
|
|
34
|
+
op: "delete";
|
|
35
|
+
resourceId: string;
|
|
36
|
+
};
|
|
37
|
+
export declare const makeParent: <T, R, E, RMD, EMD, ED, RM, EM, RPM, EPM>({ driver: makeDriver, ops, onMiss, onParentMiss, }: {
|
|
38
|
+
driver: import("../global.js").Effect<RMD, EMD, ParentCacheStoreDriver<ED, T>>;
|
|
39
|
+
ops?: import("callbag-effect-ts/Source").EffectSource<R, E, ParentCacheOp<T>> | undefined;
|
|
40
|
+
onMiss: (parentId: string, id: string) => import("../global.js").Effect<RM, EM, T>;
|
|
41
|
+
onParentMiss: (parentId: string) => import("../global.js").Effect<RPM, EPM, [id: string, resource: T][]>;
|
|
42
|
+
}) => import("../global.js").Effect<RMD, EMD, {
|
|
43
|
+
get: (parentId: string, id: string) => import("../global.js").Effect<RM, ED | EM, T>;
|
|
44
|
+
getForParent: (parentId: string) => import("../global.js").Effect<RPM, ED | EPM, ReadonlyMap<string, T>>;
|
|
45
|
+
run: import("../global.js").Effect<R, E | ED, void>;
|
|
46
|
+
size: import("../global.js").Effect<never, ED, number>;
|
|
47
|
+
sizeForParent: (parentId: string) => import("../global.js").Effect<never, ED, number>;
|
|
48
|
+
set: (parentId: string, resourceId: string, resource: T) => import("../global.js").Effect<never, ED, void>;
|
|
49
|
+
delete: (parentId: string, resourceId: string) => import("../global.js").Effect<never, ED, void>;
|
|
50
|
+
parentDelete: (parentId: string) => import("../global.js").Effect<never, ED, void>;
|
|
51
|
+
refreshTTL: (parentId: string, resourceId: string) => import("../global.js").Effect<never, ED, void>;
|
|
52
|
+
}>;
|
|
53
|
+
export declare const make: <T, R, E, RMD, EMD, ED, RM, EM>({ driver: makeDriver, ops, onMiss, }: {
|
|
54
|
+
driver: import("../global.js").Effect<RMD, EMD, CacheStoreDriver<ED, T>>;
|
|
55
|
+
ops?: import("callbag-effect-ts/Source").EffectSource<R, E, CacheOp<T>> | undefined;
|
|
56
|
+
onMiss: (id: string) => import("../global.js").Effect<RM, EM, T>;
|
|
57
|
+
}) => import("../global.js").Effect<RMD, EMD, {
|
|
58
|
+
get: (id: string) => import("../global.js").Effect<RM, ED | EM, T>;
|
|
59
|
+
run: import("../global.js").Effect<R, E | ED, void>;
|
|
60
|
+
size: import("../global.js").Effect<never, ED, number>;
|
|
61
|
+
set: (resourceId: string, resource: T) => import("../global.js").Effect<never, ED, void>;
|
|
62
|
+
delete: (resourceId: string) => import("../global.js").Effect<never, ED, void>;
|
|
63
|
+
refreshTTL: (resourceId: string) => import("../global.js").Effect<never, ED, void>;
|
|
64
|
+
}>;
|
|
65
|
+
export declare class CacheMissError {
|
|
66
|
+
readonly cacheName: string;
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly _tag = "CacheMissError";
|
|
69
|
+
constructor(cacheName: string, id: string);
|
|
70
|
+
}
|
package/Cache/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "callbag-effect-ts/Source/empty";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Effect";
|
|
3
|
+
import * as tsplus_module_3 from "callbag-effect-ts/Source/tap";
|
|
4
|
+
import * as tsplus_module_4 from "callbag-effect-ts/Source/run";
|
|
5
|
+
export * from "./driver.js";
|
|
6
|
+
export { createWithParent as memoryParentDriver, create as memoryDriver, } from "./memory.js";
|
|
7
|
+
export { createWithParent as memoryTTLParentDriver, create as memoryTTLDriver, } from "./memoryTTL.js";
|
|
8
|
+
export const makeParent = ({ driver: makeDriver, ops = tsplus_module_1.empty, onMiss, onParentMiss, }) => tsplus_module_2.map(driver => {
|
|
9
|
+
const sync = tsplus_module_4.runDrain(tsplus_module_3.tap((op) => {
|
|
10
|
+
switch (op.op) {
|
|
11
|
+
case "create":
|
|
12
|
+
case "update":
|
|
13
|
+
return driver.set(op.parentId, op.resourceId, op.resource);
|
|
14
|
+
case "delete":
|
|
15
|
+
return driver.delete(op.parentId, op.resourceId);
|
|
16
|
+
case "parentDelete":
|
|
17
|
+
return driver.parentDelete(op.parentId);
|
|
18
|
+
}
|
|
19
|
+
})(ops));
|
|
20
|
+
return {
|
|
21
|
+
...driver,
|
|
22
|
+
get: (parentId, id) => tsplus_module_2.someOrElseEffect(() => tsplus_module_2.tap((a) => driver.set(parentId, id, a))(onMiss(parentId, id)))(driver
|
|
23
|
+
.get(parentId, id)),
|
|
24
|
+
getForParent: (parentId) => tsplus_module_2.someOrElseEffect(() => tsplus_module_2.map((entries) => new Map(entries))(tsplus_module_2.tap((entries) => tsplus_module_2.collectAllPar(entries.map(([id, a]) => driver.set(parentId, id, a))))(onParentMiss(parentId))))(driver.getForParent(parentId)),
|
|
25
|
+
run: tsplus_module_2.asUnit(tsplus_module_2.zipPar(driver.run)(sync)),
|
|
26
|
+
};
|
|
27
|
+
})(makeDriver);
|
|
28
|
+
export const make = ({ driver: makeDriver, ops = tsplus_module_1.empty, onMiss, }) => tsplus_module_2.map(driver => {
|
|
29
|
+
const sync = tsplus_module_4.runDrain(tsplus_module_3.tap((op) => {
|
|
30
|
+
switch (op.op) {
|
|
31
|
+
case "create":
|
|
32
|
+
case "update":
|
|
33
|
+
return driver.set(op.resourceId, op.resource);
|
|
34
|
+
case "delete":
|
|
35
|
+
return driver.delete(op.resourceId);
|
|
36
|
+
}
|
|
37
|
+
})(ops));
|
|
38
|
+
return {
|
|
39
|
+
...driver,
|
|
40
|
+
get: (id) => tsplus_module_2.someOrElseEffect(() => tsplus_module_2.tap((a) => driver.set(id, a))(onMiss(id)))(driver
|
|
41
|
+
.get(id)),
|
|
42
|
+
run: tsplus_module_2.asUnit(tsplus_module_2.zipPar(driver.run)(sync)),
|
|
43
|
+
};
|
|
44
|
+
})(makeDriver);
|
|
45
|
+
export class CacheMissError {
|
|
46
|
+
cacheName;
|
|
47
|
+
id;
|
|
48
|
+
_tag = "CacheMissError";
|
|
49
|
+
constructor(cacheName, id) {
|
|
50
|
+
this.cacheName = cacheName;
|
|
51
|
+
this.id = id;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Cache/index.ts"],"names":[],"mappings":";;;;AAEA,cAAc,aAAa,CAAA;AAE3B,OAAO,EACL,gBAAgB,IAAI,kBAAkB,EACtC,MAAM,IAAI,YAAY,GACvB,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,gBAAgB,IAAI,qBAAqB,EACzC,MAAM,IAAI,eAAe,GAC1B,MAAM,gBAAgB,CAAA;AAavB,MAAM,CAAC,MAAM,UAAU,GAAG,CAA0C,EAClE,MAAM,EAAE,UAAU,EAClB,GAAG,wBAAqB,EACxB,MAAM,EACN,YAAY,GAQb,EAAE,EAAE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}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Maybe } from "dfx";
|
|
2
|
+
export declare const createWithParent: <T>() => import("../global.js").Effect<never, never, import("./driver.js").ParentCacheStoreDriver<never, T>>;
|
|
3
|
+
export declare const create: <T>() => import("../global.js").Effect<never, never, import("./driver.js").CacheStoreDriver<never, T>>;
|
package/Cache/memory.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "@effect/io/Effect";
|
|
2
|
+
import * as tsplus_module_2 from "@fp-ts/data/Option";
|
|
3
|
+
import { createParentDriver, createDriver } from "./driver.js";
|
|
4
|
+
export const createWithParent = () => tsplus_module_1.sync(() => {
|
|
5
|
+
const map = new Map();
|
|
6
|
+
return createParentDriver({
|
|
7
|
+
size: tsplus_module_1.sync(() => {
|
|
8
|
+
let count = 0;
|
|
9
|
+
for (const a of map.values()) {
|
|
10
|
+
count += a.size;
|
|
11
|
+
}
|
|
12
|
+
return count;
|
|
13
|
+
}),
|
|
14
|
+
sizeForParent: (parentId) => tsplus_module_1.sync(() => map.get(parentId)?.size ?? 0),
|
|
15
|
+
get: (parentId, resourceId) => tsplus_module_1.sync(() => tsplus_module_2.fromNullable(map.get(parentId)?.get(resourceId))),
|
|
16
|
+
getForParent: (parentId) => tsplus_module_1.sync(() => tsplus_module_2.fromNullable(map.get(parentId))),
|
|
17
|
+
set: (parentId, resourceId, resource) => tsplus_module_1.sync(() => {
|
|
18
|
+
if (!map.has(parentId)) {
|
|
19
|
+
map.set(parentId, new Map());
|
|
20
|
+
}
|
|
21
|
+
map.get(parentId).set(resourceId, resource);
|
|
22
|
+
}),
|
|
23
|
+
delete: (parentId, resourceId) => tsplus_module_1.sync(() => {
|
|
24
|
+
map.get(parentId)?.delete(resourceId);
|
|
25
|
+
}),
|
|
26
|
+
parentDelete: (parentId) => tsplus_module_1.sync(() => {
|
|
27
|
+
map.delete(parentId);
|
|
28
|
+
}),
|
|
29
|
+
refreshTTL: () => tsplus_module_1.unit(),
|
|
30
|
+
run: tsplus_module_1.unit(),
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
export const create = () => tsplus_module_1.sync(() => {
|
|
34
|
+
const map = new Map();
|
|
35
|
+
return createDriver({
|
|
36
|
+
size: tsplus_module_1.sync(() => map.size),
|
|
37
|
+
get: (resourceId) => tsplus_module_1.sync(() => tsplus_module_2.fromNullable(map.get(resourceId))),
|
|
38
|
+
set: (resourceId, resource) => tsplus_module_1.sync(() => {
|
|
39
|
+
map.set(resourceId, resource);
|
|
40
|
+
}),
|
|
41
|
+
delete: (resourceId) => tsplus_module_1.sync(() => {
|
|
42
|
+
map.delete(resourceId);
|
|
43
|
+
}),
|
|
44
|
+
refreshTTL: () => tsplus_module_1.unit(),
|
|
45
|
+
run: tsplus_module_1.unit(),
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/Cache/memory.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE9D,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAM,EAAE,CACtC,qBAAY,GAAG,EAAE;IACf,MAAM,GAAG,GAAG,IAAI,GAAG,EAA0B,CAAA;IAE7C,OAAO,kBAAkB,CAAC;QACxB,IAAI,EAAE,qBAAY,GAAG,EAAE;YACrB,IAAI,KAAK,GAAG,CAAC,CAAA;YACb,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,EAAE,EAAE;gBAC5B,KAAK,IAAI,CAAC,CAAC,IAAI,CAAA;aAChB;YACD,OAAO,KAAK,CAAA;QACd,CAAC,CAAC;QAEF,aAAa,EAAE,CAAC,QAAQ,EAAE,EAAE,CAC1B,qBAAY,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,IA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O,YAAY,CAAC;QAClB,IAAI,EAAE,qBAAY,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;QAEjC,GAAG,EAAE,CAAC,UAAU,EAAE,EAAE,CAClB,qBAAY,GAAa,EAAE,CAAC,6BAAmB,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;QAEtE,GAAG,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,CAC5B,qBAAY,GAAG,EAAE;YACf,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QAC/B,CAAC,CAAC;QAEJ,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE,CACrB,qBAAY,GAAG,EAAE;YACf,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QACxB,CAAC,CAAC;QAEJ,UAAU,EAAE,GAAG,EAAE,CAAC,sBAAa;QAE/B,GAAG,EAAE,sBAAa;KACnB,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Duration } from "@fp-ts/data/Duration";
|
|
2
|
+
import { Maybe } from "dfx";
|
|
3
|
+
import { Effect } from "@effect/io/Effect";
|
|
4
|
+
export interface MemoryTTLOpts {
|
|
5
|
+
/** The approx. number of milliseconds to keep items */
|
|
6
|
+
ttl: Duration;
|
|
7
|
+
/**
|
|
8
|
+
* How often items should be cleared.
|
|
9
|
+
*
|
|
10
|
+
* Defaults to 5 minutes
|
|
11
|
+
*/
|
|
12
|
+
resolution?: Duration;
|
|
13
|
+
/**
|
|
14
|
+
* What sweep strategy to use.
|
|
15
|
+
*
|
|
16
|
+
* "activity" means the TTL is reset for every `set` OR `get` operation
|
|
17
|
+
* "usage" means the TTL is only reset for the `get` operation
|
|
18
|
+
*
|
|
19
|
+
* Defaults to "usage"
|
|
20
|
+
*/
|
|
21
|
+
strategy?: "activity" | "usage" | "expiry";
|
|
22
|
+
}
|
|
23
|
+
export declare const create: <T>(opts: MemoryTTLOpts) => import("../global.js").Effect<never, never, import("./driver.js").CacheStoreDriver<never, T>>;
|
|
24
|
+
export declare const createWithParent: <T>(opts: MemoryTTLOpts) => import("../global.js").Effect<never, never, import("./driver.js").ParentCacheStoreDriver<never, T>>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "@fp-ts/data/Duration";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Effect";
|
|
3
|
+
import * as tsplus_module_3 from "@fp-ts/data/Option";
|
|
4
|
+
import * as tsplus_module_4 from "@fp-ts/data/Chunk";
|
|
5
|
+
import { createParentDriver, createDriver } from "./driver.js";
|
|
6
|
+
const make = ({ ttl, resolution = tsplus_module_1.minutes(1), strategy = "usage", }) => {
|
|
7
|
+
const additionalMilliseconds = (Math.floor(ttl.millis / resolution.millis) + 1) * resolution.millis;
|
|
8
|
+
const items = new Map();
|
|
9
|
+
const buckets = [];
|
|
10
|
+
const refreshTTL = (item) => {
|
|
11
|
+
const now = Date.now();
|
|
12
|
+
const remainder = now % resolution.millis;
|
|
13
|
+
const expires = now - remainder + additionalMilliseconds;
|
|
14
|
+
let currentBucket = buckets[buckets.length - 1];
|
|
15
|
+
if ((currentBucket?.expires || 0) < expires) {
|
|
16
|
+
currentBucket = {
|
|
17
|
+
expires,
|
|
18
|
+
items: [],
|
|
19
|
+
};
|
|
20
|
+
buckets.push(currentBucket);
|
|
21
|
+
}
|
|
22
|
+
currentBucket.items.push(item);
|
|
23
|
+
};
|
|
24
|
+
const sweep = () => {
|
|
25
|
+
const now = Date.now();
|
|
26
|
+
const remainder = now % resolution.millis;
|
|
27
|
+
const currentExpires = now - remainder;
|
|
28
|
+
while (buckets.length && buckets[0].expires <= currentExpires) {
|
|
29
|
+
buckets.shift();
|
|
30
|
+
}
|
|
31
|
+
if (global.gc) {
|
|
32
|
+
global.gc();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const getSync = (resourceId) => {
|
|
36
|
+
const ref = items.get(resourceId);
|
|
37
|
+
if (!ref)
|
|
38
|
+
return undefined;
|
|
39
|
+
const item = ref.deref();
|
|
40
|
+
if (!item) {
|
|
41
|
+
items.delete(resourceId);
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
if (strategy !== "expiry") {
|
|
45
|
+
refreshTTL(item);
|
|
46
|
+
}
|
|
47
|
+
return item.resource;
|
|
48
|
+
};
|
|
49
|
+
return createDriver({
|
|
50
|
+
size: tsplus_module_2.sync(() => items.size),
|
|
51
|
+
get: (resourceId) => tsplus_module_2.sync(() => tsplus_module_3.fromNullable(getSync(resourceId))),
|
|
52
|
+
refreshTTL: (id) => tsplus_module_2.sync(() => {
|
|
53
|
+
getSync(id);
|
|
54
|
+
}),
|
|
55
|
+
set: (resourceId, resource) => tsplus_module_2.sync(() => {
|
|
56
|
+
const item = items.get(resourceId)?.deref();
|
|
57
|
+
if (item && strategy !== "activity") {
|
|
58
|
+
item.resource = resource;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const newItem = { resource };
|
|
62
|
+
refreshTTL(newItem);
|
|
63
|
+
items.set(resourceId, new WeakRef(newItem));
|
|
64
|
+
}
|
|
65
|
+
}),
|
|
66
|
+
delete: (resourceId) => tsplus_module_2.sync(() => {
|
|
67
|
+
items.delete(resourceId);
|
|
68
|
+
}),
|
|
69
|
+
run: tsplus_module_2.forever(tsplus_module_2.delay(tsplus_module_1.times(0.5)(resolution))(tsplus_module_2.sync(sweep))),
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
export const create = (opts) => tsplus_module_2.sync(() => make(opts));
|
|
73
|
+
export const createWithParent = (opts) => tsplus_module_2.sync(() => {
|
|
74
|
+
const store = make(opts);
|
|
75
|
+
const parentIds = new Map();
|
|
76
|
+
return createParentDriver({
|
|
77
|
+
size: store.size,
|
|
78
|
+
sizeForParent: (parentId) => tsplus_module_2.sync(() => parentIds.get(parentId)?.size ?? 0),
|
|
79
|
+
refreshTTL: (_, id) => store.refreshTTL(id),
|
|
80
|
+
get: (_, id) => store.get(id),
|
|
81
|
+
getForParent: (parentId) => (() => {
|
|
82
|
+
const ids = parentIds.get(parentId);
|
|
83
|
+
if (!ids)
|
|
84
|
+
return tsplus_module_3.none;
|
|
85
|
+
const toGet = [];
|
|
86
|
+
for (const id in ids) {
|
|
87
|
+
toGet.push(tsplus_module_2.map(item => {
|
|
88
|
+
if (item._tag === "Some") {
|
|
89
|
+
parentIds.delete(id);
|
|
90
|
+
}
|
|
91
|
+
return [id, item];
|
|
92
|
+
})(store.get(id)));
|
|
93
|
+
}
|
|
94
|
+
return tsplus_module_2.map(results => {
|
|
95
|
+
const map = tsplus_module_4.reduce(new Map(), (map, [id, a]) => a._tag === "Some" ? map.set(id, a.value) : map)(results);
|
|
96
|
+
return tsplus_module_3.some(map);
|
|
97
|
+
})(tsplus_module_2.collectAllPar(toGet));
|
|
98
|
+
})(),
|
|
99
|
+
set: (parentId, resourceId, resource) => tsplus_module_2.map(() => {
|
|
100
|
+
if (!parentIds.has(parentId)) {
|
|
101
|
+
parentIds.set(parentId, new Set());
|
|
102
|
+
}
|
|
103
|
+
parentIds.get(parentId).add(resourceId);
|
|
104
|
+
})(store.set(resourceId, resource)),
|
|
105
|
+
delete: (parentId, resourceId) => tsplus_module_2.map(() => {
|
|
106
|
+
parentIds.get(parentId)?.delete(resourceId);
|
|
107
|
+
})(store.delete(resourceId)),
|
|
108
|
+
parentDelete: (parentId) => (() => {
|
|
109
|
+
const ids = parentIds.get(parentId);
|
|
110
|
+
parentIds.delete(parentId);
|
|
111
|
+
const effects = [];
|
|
112
|
+
if (ids) {
|
|
113
|
+
ids.forEach((id) => {
|
|
114
|
+
effects.push(store.delete(id));
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return tsplus_module_2.map(() => void 0)(tsplus_module_2.collectAllParDiscard(effects));
|
|
118
|
+
})(),
|
|
119
|
+
run: store.run,
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+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,CAAC,CAAA;WALtC,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAMjC;QAEJ,MAAM,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE;YAG7B,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;WADzC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAE1B;QAEJ,YAAY,EAAE,CAAC,QAAQ,EAAE,EAAE;YAEvB,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACnC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAE1B,MAAM,OAAO,GAAiC,EAAE,CAAA;YAChD,IAAI,GAAG,EAAE;gBACP,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;oBACjB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;gBAChC,CAAC,CAAC,CAAA;aACH;0FAEC,OAAO;YACT;QAEJ,GAAG,EAAE,KAAK,CAAC,GAAG;KACf,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Discord } from "dfx";
|
|
2
|
+
import { Success } from "dfx/utils/effect";
|
|
3
|
+
import { Cache } from "dfx";
|
|
4
|
+
import { Effect } from "@effect/io/Effect";
|
|
5
|
+
declare const makeGuilds: <RM, EM, E>(driver: Effect<RM, EM, Cache.CacheStoreDriver<E, import("../types.js").Guild>>) => Effect<RM, EM, {
|
|
6
|
+
get: (id: string) => Effect<import("dfx").DiscordREST, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | E, import("../types.js").Guild>;
|
|
7
|
+
run: Effect<import("../DiscordGateway/index.js").DiscordGateway, E, void>;
|
|
8
|
+
size: Effect<never, E, number>;
|
|
9
|
+
set: (resourceId: string, resource: import("../types.js").Guild) => Effect<never, E, void>;
|
|
10
|
+
delete: (resourceId: string) => Effect<never, E, void>;
|
|
11
|
+
refreshTTL: (resourceId: string) => Effect<never, E, void>;
|
|
12
|
+
}>;
|
|
13
|
+
export interface GuildsCache extends Success<ReturnType<typeof makeGuilds>> {
|
|
14
|
+
}
|
|
15
|
+
export declare const GuildsCache: import("../global.js").Tag<GuildsCache>;
|
|
16
|
+
export declare const guilds: <RM, EM, E>(driver: Effect<RM, EM, Cache.CacheStoreDriver<E, import("../types.js").Guild>>) => import("../global.js").Layer<RM, EM, GuildsCache>;
|
|
17
|
+
declare const makeChannels: <RM, EM, E>(driver: Effect<RM, EM, Cache.ParentCacheStoreDriver<E, import("../types.js").Channel>>) => Effect<RM, EM, {
|
|
18
|
+
get: (parentId: string, id: string) => Effect<import("dfx").DiscordREST, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | E, import("../types.js").Channel>;
|
|
19
|
+
getForParent: (parentId: string) => Effect<import("dfx").DiscordREST, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | E, ReadonlyMap<string, import("../types.js").Channel>>;
|
|
20
|
+
run: Effect<import("../DiscordGateway/index.js").DiscordGateway, E, void>;
|
|
21
|
+
size: Effect<never, E, number>;
|
|
22
|
+
sizeForParent: (parentId: string) => Effect<never, E, number>;
|
|
23
|
+
set: (parentId: string, resourceId: string, resource: import("../types.js").Channel) => Effect<never, E, void>;
|
|
24
|
+
delete: (parentId: string, resourceId: string) => Effect<never, E, void>;
|
|
25
|
+
parentDelete: (parentId: string) => Effect<never, E, void>;
|
|
26
|
+
refreshTTL: (parentId: string, resourceId: string) => Effect<never, E, void>;
|
|
27
|
+
}>;
|
|
28
|
+
export interface ChannelsCache extends Success<ReturnType<typeof makeChannels>> {
|
|
29
|
+
}
|
|
30
|
+
export declare const ChannelsCache: import("../global.js").Tag<ChannelsCache>;
|
|
31
|
+
export declare const channels: <RM, EM, E>(driver: Effect<RM, EM, Cache.ParentCacheStoreDriver<E, import("../types.js").Channel>>) => import("../global.js").Layer<RM, EM, ChannelsCache>;
|
|
32
|
+
declare const makeRoles: <RM, EM, E>(driver: Effect<RM, EM, Cache.ParentCacheStoreDriver<E, import("../types.js").Role>>) => Effect<RM, EM, {
|
|
33
|
+
get: (parentId: string, id: string) => Effect<never, Cache.CacheMissError | E, import("../types.js").Role>;
|
|
34
|
+
getForParent: (parentId: string) => Effect<import("dfx").DiscordREST, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | E, ReadonlyMap<string, import("../types.js").Role>>;
|
|
35
|
+
run: Effect<import("../DiscordGateway/index.js").DiscordGateway, E, void>;
|
|
36
|
+
size: Effect<never, E, number>;
|
|
37
|
+
sizeForParent: (parentId: string) => Effect<never, E, number>;
|
|
38
|
+
set: (parentId: string, resourceId: string, resource: import("../types.js").Role) => Effect<never, E, void>;
|
|
39
|
+
delete: (parentId: string, resourceId: string) => Effect<never, E, void>;
|
|
40
|
+
parentDelete: (parentId: string) => Effect<never, E, void>;
|
|
41
|
+
refreshTTL: (parentId: string, resourceId: string) => Effect<never, E, void>;
|
|
42
|
+
}>;
|
|
43
|
+
export interface RolesCache extends Success<ReturnType<typeof makeRoles>> {
|
|
44
|
+
}
|
|
45
|
+
export declare const RolesCache: import("../global.js").Tag<RolesCache>;
|
|
46
|
+
export declare const roles: <RM, EM, E>(driver: Effect<RM, EM, Cache.ParentCacheStoreDriver<E, import("../types.js").Role>>) => import("../global.js").Layer<RM, EM, RolesCache>;
|
|
47
|
+
export {};
|
package/Cache/prelude.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "dfx";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Effect";
|
|
3
|
+
import * as tsplus_module_3 from "@fp-ts/data/Context";
|
|
4
|
+
import * as tsplus_module_4 from "@fp-ts/data/Function";
|
|
5
|
+
import { Cache } from "dfx";
|
|
6
|
+
import { CacheOps } from "dfx/gateway";
|
|
7
|
+
import { toLayer } from "@effect/io/Effect";
|
|
8
|
+
const makeGuilds = (driver) => Cache.make({
|
|
9
|
+
driver,
|
|
10
|
+
ops: CacheOps.guilds,
|
|
11
|
+
onMiss: (id) => tsplus_module_2.flatMap((r) => r.json)(tsplus_module_1.rest.getGuild(id)),
|
|
12
|
+
});
|
|
13
|
+
export const GuildsCache = tsplus_module_3.Tag();
|
|
14
|
+
export const guilds = tsplus_module_4.flow(makeGuilds, toLayer(GuildsCache));
|
|
15
|
+
const makeChannels = (driver) => Cache.makeParent({
|
|
16
|
+
driver,
|
|
17
|
+
ops: CacheOps.channels,
|
|
18
|
+
onMiss: (id) => tsplus_module_2.flatMap((r) => r.json)(tsplus_module_1.rest.getChannel(id)),
|
|
19
|
+
onParentMiss: (guildId) => tsplus_module_2.map((a) => a.map((a) => [a.id, a]))(tsplus_module_2.flatMap((r) => r.json)(tsplus_module_1.rest.getGuildChannels(guildId))),
|
|
20
|
+
});
|
|
21
|
+
export const ChannelsCache = tsplus_module_3.Tag();
|
|
22
|
+
export const channels = tsplus_module_4.flow(makeChannels, toLayer(ChannelsCache));
|
|
23
|
+
const makeRoles = (driver) => Cache.makeParent({
|
|
24
|
+
driver,
|
|
25
|
+
ops: CacheOps.roles,
|
|
26
|
+
onMiss: (id) => tsplus_module_2.fail(new Cache.CacheMissError("RolesCache", id)),
|
|
27
|
+
onParentMiss: (guildId) => tsplus_module_2.map((a) => a.map((a) => [a.id, a]))(tsplus_module_2.flatMap((r) => r.json)(tsplus_module_1.rest.getGuildRoles(guildId))),
|
|
28
|
+
});
|
|
29
|
+
export const RolesCache = tsplus_module_3.Tag();
|
|
30
|
+
export const roles = tsplus_module_4.flow(makeRoles, toLayer(RolesCache));
|
|
31
|
+
//# sourceMappingURL=prelude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../src/Cache/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OAAO,CAAC,CACH,CACa;CACzC,CAAC,CAAA;AAIJ,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAA,GAAG,EAAiB,CAAA;AACjD,MAAM,CAAC,MAAM,QAAQ,GAAG,gBAAA,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAA;AAElE,MAAM,SAAS,GAAG,CAChB,MAAqE,EACrE,EAAE,CACF,KAAK,CAAC,UAAU,CAAC;IACf,MAAM;IACN,GAAG,EAAE,QAAQ,CAAC,KAAK;IACnB,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,qBAAY,IAAI,KAAK,CAAC,cAAc,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IACvE,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CACxB,oBAGO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAHrC,wBAEW,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAFxB,gBAAA,IAAI,CACD,aAAa,CAAC,OAAO,CAAC,CACA,CACa;CACzC,CAAC,CAAA;AAGJ,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAA,GAAG,EAAc,CAAA;AAC3C,MAAM,CAAC,MAAM,KAAK,GAAG,gBAAA,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
/// <reference types="ws" />
|
|
3
2
|
import { Discord } from "dfx";
|
|
4
3
|
import { WS } from "dfx/gateway";
|
|
@@ -14,8 +13,8 @@ export interface OpenOpts {
|
|
|
14
13
|
}
|
|
15
14
|
export interface DiscordWSCodec {
|
|
16
15
|
type: "json" | "etf";
|
|
17
|
-
encode: (p: Discord.GatewayPayload) => string
|
|
18
|
-
decode: (p: WebSocket.
|
|
16
|
+
encode: (p: Discord.GatewayPayload) => string;
|
|
17
|
+
decode: (p: WebSocket.Data) => Discord.GatewayPayload;
|
|
19
18
|
}
|
|
20
19
|
export declare const DiscordWSCodec: import("../../global.js").Tag<DiscordWSCodec>;
|
|
21
20
|
export declare const LiveJsonDiscordWSCodec: import("../../global.js").Layer<never, never, DiscordWSCodec>;
|
|
@@ -21,8 +21,6 @@ export const make = ({ url = "wss://gateway.discord.gg/", version = 10, outbound
|
|
|
21
21
|
return tsplus_module_9.flatMap(ws => tsplus_module_9.map(log => {
|
|
22
22
|
const source = tsplus_module_7.map(encoding.decode)(tsplus_module_6.retry(tsplus_module_4.exponential(tsplus_module_3.seconds(0.5)))(tsplus_module_5.tapError((e) => log.info("DiscordWS", "ERROR", e))(ws)));
|
|
23
23
|
return { source, setUrl };
|
|
24
|
-
})(tsplus_module_9.service(tsplus_module_8.Log.Log)))(tsplus_module_10.WS.make(urlRef, take
|
|
25
|
-
perMessageDeflate: false,
|
|
26
|
-
}));
|
|
24
|
+
})(tsplus_module_9.service(tsplus_module_8.Log.Log)))(tsplus_module_10.WS.make(urlRef, take));
|
|
27
25
|
})(tsplus_module_11.make(`${url}?v=${version}&encoding=${encoding.type}`)))(tsplus_module_9.service(DiscordWSCodec));
|
|
28
26
|
//# sourceMappingURL=index.js.map
|