dfx 0.17.9 → 0.18.1
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 +22 -0
- package/Cache/memoryTTL.js +122 -0
- package/Cache/memoryTTL.js.map +1 -0
- package/Cache/prelude.d.ts +33 -0
- package/Cache/prelude.js +22 -0
- package/Cache/prelude.js.map +1 -0
- 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/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 +16 -2
- package/utils/effect.js +16 -11
- 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 ParentCacheDriver<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: ParentCacheDriver<E, T>) => ParentCacheDriver<E, T>;
|
|
15
|
+
export interface CacheDriver<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: CacheDriver<E, T>) => CacheDriver<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,CAAO,MAA+B,EAAE,EAAE,CAC1E,MAAM,CAAA;AAWR,MAAM,CAAC,MAAM,YAAY,GAAG,CAAO,MAAyB,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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CAAC,MAAM,KAAK,GAAG,MAAM,CAAC;IAC1B,EAAE,EAAE,CAAC,CAAe,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE;IAC7B,UAAU,EAAE,oBAAyC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAA/D,gBAAA,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,CAA4B;IAC5E,MAAM,EAAE,oBAA8C,CAAC,CAAC,EAAE,EAAE,CAAC;QAC3D,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,IAAI;KACP,EAHO,gBAAA,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAG/C;IACF,MAAM,EAAE,oBAA8C,CAAC,CAAC,EAAE,EAAE,CAAC;QAC3D,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,IAAI;KACP,EAHO,gBAAA,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAG/C;IACF,MAAM,EAAE,oBAA8C,CAAC,CAAC,EAAE,EAAE,CAAC;QAC3D,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,OAAO;KACV,EAHO,gBAAA,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAG/C;IACF,YAAY,EAAE,oBAAyC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAApD,gBAAA,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,CAAiB;CACpE,CAAC,CAAA"}
|
package/Cache/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Effect } from "@effect/io/Effect";
|
|
2
|
+
import { EffectSource } from "callbag-effect-ts/Source";
|
|
3
|
+
import { CacheDriver, ParentCacheDriver } from "./driver.js";
|
|
4
|
+
export * from "./driver.js";
|
|
5
|
+
export { create as memoryDriver, createWithParent as memoryParentDriver, } from "./memory.js";
|
|
6
|
+
export { create as memoryTTLDriver, createWithParent as memoryTTLParentDriver, } 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: <ROps, RMakeDriver, RMiss, RPMiss, EOps, EMakeDriver, EDriver, EMiss, EPMiss, A>({ driver: makeDriver, ops, onMiss, onParentMiss, }: {
|
|
38
|
+
driver: import("../global.js").Effect<RMakeDriver, EMakeDriver, ParentCacheDriver<EDriver, A>>;
|
|
39
|
+
ops?: import("callbag-effect-ts/Source").EffectSource<ROps, EOps, ParentCacheOp<A>> | undefined;
|
|
40
|
+
onMiss: (parentId: string, id: string) => import("../global.js").Effect<RMiss, EMiss, A>;
|
|
41
|
+
onParentMiss: (parentId: string) => import("../global.js").Effect<RPMiss, EPMiss, [id: string, resource: A][]>;
|
|
42
|
+
}) => import("../global.js").Effect<RMakeDriver, EMakeDriver, {
|
|
43
|
+
get: (parentId: string, id: string) => import("../global.js").Effect<RMiss, EDriver | EMiss, A>;
|
|
44
|
+
getForParent: (parentId: string) => import("../global.js").Effect<RPMiss, EDriver | EPMiss, ReadonlyMap<string, A>>;
|
|
45
|
+
run: import("../global.js").Effect<ROps, EOps | EDriver, void>;
|
|
46
|
+
size: import("../global.js").Effect<never, EDriver, number>;
|
|
47
|
+
sizeForParent: (parentId: string) => import("../global.js").Effect<never, EDriver, number>;
|
|
48
|
+
set: (parentId: string, resourceId: string, resource: A) => import("../global.js").Effect<never, EDriver, void>;
|
|
49
|
+
delete: (parentId: string, resourceId: string) => import("../global.js").Effect<never, EDriver, void>;
|
|
50
|
+
parentDelete: (parentId: string) => import("../global.js").Effect<never, EDriver, void>;
|
|
51
|
+
refreshTTL: (parentId: string, resourceId: string) => import("../global.js").Effect<never, EDriver, void>;
|
|
52
|
+
}>;
|
|
53
|
+
export declare const make: <ROps, RMakeDriver, RMiss, EOps, EMakeDriver, EDriver, EMiss, A>({ driver: makeDriver, ops, onMiss, }: {
|
|
54
|
+
driver: import("../global.js").Effect<RMakeDriver, EMakeDriver, CacheDriver<EDriver, A>>;
|
|
55
|
+
ops?: import("callbag-effect-ts/Source").EffectSource<ROps, EOps, CacheOp<A>> | undefined;
|
|
56
|
+
onMiss: (id: string) => import("../global.js").Effect<RMiss, EMiss, A>;
|
|
57
|
+
}) => import("../global.js").Effect<RMakeDriver, EMakeDriver, {
|
|
58
|
+
get: (id: string) => import("../global.js").Effect<RMiss, EDriver | EMiss, A>;
|
|
59
|
+
run: import("../global.js").Effect<ROps, EOps | EDriver, void>;
|
|
60
|
+
size: import("../global.js").Effect<never, EDriver, number>;
|
|
61
|
+
set: (resourceId: string, resource: A) => import("../global.js").Effect<never, EDriver, void>;
|
|
62
|
+
delete: (resourceId: string) => import("../global.js").Effect<never, EDriver, void>;
|
|
63
|
+
refreshTTL: (resourceId: string) => import("../global.js").Effect<never, EDriver, 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 { create as memoryDriver, createWithParent as memoryParentDriver, } from "./memory.js";
|
|
7
|
+
export { create as memoryTTLDriver, createWithParent as memoryTTLParentDriver, } 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;AAC3B,OAAO,EACL,MAAM,IAAI,YAAY,EACtB,gBAAgB,IAAI,kBAAkB,GACvC,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,MAAM,IAAI,eAAe,EACzB,gBAAgB,IAAI,qBAAqB,GAC1C,MAAM,gBAAgB,CAAA;AAavB,MAAM,CAAC,MAAM,UAAU,GAAG,CAWxB,EACA,MAAM,EAAE,UAAU,EAClB,GAAG,wBAAqB,EACxB,MAAM,EACN,YAAY,GAQb,EAAE,EAAE,qBAEK,MAAM;IAEZ,MAAM,IAAI,4BAAG,oBAAQ,CAAC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
|
|
2
|
+
export declare const createWithParent: <T>() => import("../global.js").Effect<never, never, import("./driver.js").ParentCacheDriver<never, T>>;
|
|
3
|
+
export declare const create: <T>() => import("../global.js").Effect<never, never, import("./driver.js").CacheDriver<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,IAAI,CAAC,CAAC;QAEjD,GAAG,EAAE,CAAC,QAAQ,EAAE,UAAU,EAA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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,22 @@
|
|
|
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
|
+
resolution?: Duration;
|
|
11
|
+
/**
|
|
12
|
+
* What sweep strategy to use.
|
|
13
|
+
*
|
|
14
|
+
* "activity" means the TTL is reset for every `set` OR `get` operation
|
|
15
|
+
* "usage" means the TTL is only reset for the `get` operation
|
|
16
|
+
*
|
|
17
|
+
* Defaults to "usage"
|
|
18
|
+
*/
|
|
19
|
+
strategy?: "activity" | "usage" | "expiry";
|
|
20
|
+
}
|
|
21
|
+
export declare const create: <T>(opts: MemoryTTLOpts) => import("../global.js").Effect<never, never, import("./driver.js").CacheDriver<never, T>>;
|
|
22
|
+
export declare const createWithParent: <T>(opts: MemoryTTLOpts) => import("../global.js").Effect<never, never, import("./driver.js").ParentCacheDriver<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
|
+
ids.forEach((id) => {
|
|
87
|
+
toGet.push(tsplus_module_2.map(item => {
|
|
88
|
+
if (item._tag === "None") {
|
|
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
|
+
//# sourceMappingURL=memoryTTL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoryTTL.js","sourceRoot":"","sources":["../../src/Cache/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,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,33 @@
|
|
|
1
|
+
import { Discord } from "dfx";
|
|
2
|
+
import { Effect } from "@effect/io/Effect";
|
|
3
|
+
import { Cache } from "dfx";
|
|
4
|
+
export declare const guilds: <RM, EM, E>(driver: Effect<RM, EM, Cache.CacheDriver<E, import("../types.js").Guild>>) => Effect<RM, EM, {
|
|
5
|
+
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>;
|
|
6
|
+
run: Effect<import("../DiscordGateway/index.js").DiscordGateway, E, void>;
|
|
7
|
+
size: Effect<never, E, number>;
|
|
8
|
+
set: (resourceId: string, resource: import("../types.js").Guild) => Effect<never, E, void>;
|
|
9
|
+
delete: (resourceId: string) => Effect<never, E, void>;
|
|
10
|
+
refreshTTL: (resourceId: string) => Effect<never, E, void>;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const channels: <RM, EM, E>(driver: Effect<RM, EM, Cache.ParentCacheDriver<E, import("../types.js").Channel>>) => Effect<RM, EM, {
|
|
13
|
+
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>;
|
|
14
|
+
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>>;
|
|
15
|
+
run: Effect<import("../DiscordGateway/index.js").DiscordGateway, E, void>;
|
|
16
|
+
size: Effect<never, E, number>;
|
|
17
|
+
sizeForParent: (parentId: string) => Effect<never, E, number>;
|
|
18
|
+
set: (parentId: string, resourceId: string, resource: import("../types.js").Channel) => Effect<never, E, void>;
|
|
19
|
+
delete: (parentId: string, resourceId: string) => Effect<never, E, void>;
|
|
20
|
+
parentDelete: (parentId: string) => Effect<never, E, void>;
|
|
21
|
+
refreshTTL: (parentId: string, resourceId: string) => Effect<never, E, void>;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const roles: <RM, EM, E>(driver: Effect<RM, EM, Cache.ParentCacheDriver<E, import("../types.js").Role>>) => Effect<RM, EM, {
|
|
24
|
+
get: (parentId: string, id: string) => Effect<never, Cache.CacheMissError | E, import("../types.js").Role>;
|
|
25
|
+
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>>;
|
|
26
|
+
run: Effect<import("../DiscordGateway/index.js").DiscordGateway, E, void>;
|
|
27
|
+
size: Effect<never, E, number>;
|
|
28
|
+
sizeForParent: (parentId: string) => Effect<never, E, number>;
|
|
29
|
+
set: (parentId: string, resourceId: string, resource: import("../types.js").Role) => Effect<never, E, void>;
|
|
30
|
+
delete: (parentId: string, resourceId: string) => Effect<never, E, void>;
|
|
31
|
+
parentDelete: (parentId: string) => Effect<never, E, void>;
|
|
32
|
+
refreshTTL: (parentId: string, resourceId: string) => Effect<never, E, void>;
|
|
33
|
+
}>;
|
package/Cache/prelude.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "dfx";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Effect";
|
|
3
|
+
import { Cache } from "dfx";
|
|
4
|
+
import { CacheOps } from "dfx/gateway";
|
|
5
|
+
export const guilds = (driver) => Cache.make({
|
|
6
|
+
driver,
|
|
7
|
+
ops: CacheOps.guilds,
|
|
8
|
+
onMiss: (id) => tsplus_module_2.flatMap((r) => r.json)(tsplus_module_1.rest.getGuild(id)),
|
|
9
|
+
});
|
|
10
|
+
export const channels = (driver) => Cache.makeParent({
|
|
11
|
+
driver,
|
|
12
|
+
ops: CacheOps.channels,
|
|
13
|
+
onMiss: (id) => tsplus_module_2.flatMap((r) => r.json)(tsplus_module_1.rest.getChannel(id)),
|
|
14
|
+
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))),
|
|
15
|
+
});
|
|
16
|
+
export const roles = (driver) => Cache.makeParent({
|
|
17
|
+
driver,
|
|
18
|
+
ops: CacheOps.roles,
|
|
19
|
+
onMiss: (id) => tsplus_module_2.fail(new Cache.CacheMissError("RolesCache", id)),
|
|
20
|
+
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))),
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=prelude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../src/Cache/prelude.ts"],"names":[],"mappings":";;AACA,OAAO,E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Y,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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DiscordWS } from "dfx/gateway";
|
|
2
2
|
import { Discord } from "dfx";
|
|
3
|
-
export declare const make: (shard: [id: number, count: number]) => import("../../global.js").Effect<import("../../Log/index.js").Log | import("../DiscordWS/index.js").DiscordWSCodec | import("../../
|
|
3
|
+
export declare const make: (shard: [id: number, count: number]) => import("../../global.js").Effect<import("../../Log/index.js").Log | import("../DiscordWS/index.js").DiscordWSCodec | import("../../RateLimit/index.js").RateLimiter | import("../../DiscordConfig/index.js").DiscordConfig, never, {
|
|
4
4
|
run: import("../../global.js").Effect<never, never, void>;
|
|
5
5
|
raw: import("callbag-effect-ts/Source").EffectSource<never, never, import("../../types.js").GatewayPayload<any>>;
|
|
6
6
|
dispatch: import("callbag-effect-ts/Source").EffectSource<never, never, import("../../types.js").GatewayPayload<import("../../types.js").ReceiveEvent>>;
|
|
@@ -14,7 +14,7 @@ import * as Identify from "./identify.js";
|
|
|
14
14
|
import * as InvalidSession from "./invalidSession.js";
|
|
15
15
|
import * as Utils from "./utils.js";
|
|
16
16
|
export const make = (shard) => tsplus_module_1.flatMap(({ token, gateway }) => tsplus_module_1.flatMap(limiter => tsplus_module_1.flatMap(outboundQueue => {
|
|
17
|
-
const outbound = tsplus_module_1.tap(() => limiter.maybeWait("shard.send", tsplus_module_10.minutes(1), 120))(outboundQueue
|
|
17
|
+
const outbound = tsplus_module_1.tap(() => limiter.maybeWait("dfx.shard.send", tsplus_module_10.minutes(1), 120))(outboundQueue
|
|
18
18
|
.take());
|
|
19
19
|
const send = (p) => outboundQueue.offer(p);
|
|
20
20
|
return tsplus_module_1.flatMap(socket => tsplus_module_1.flatMap(raw => tsplus_module_1.flatMap(([latestReady, updateLatestReady]) => tsplus_module_1.map(([latestSequence, updateLatestSequence]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Shard/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAkC,EAAE,EAAE,0BAEjD,EAAE,KAAK,EAAE,OAAO,EAAE,6BAClB,OAAO,4BAEP,aAAa;IACnB,MAAM,QAAQ,GAAG,oBAEV,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Shard/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAkC,EAAE,EAAE,0BAEjD,EAAE,KAAK,EAAE,OAAO,EAAE,6BAClB,OAAO,4BAEP,aAAa;IACnB,MAAM,QAAQ,GAAG,oBAEV,GAAG,EAAE,CAAC,OAAO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
|
import { Maybe, Discord } from "dfx";
|
|
3
3
|
import { EffectSource } from "callbag-effect-ts/Source";
|
|
4
4
|
import { ShardStore } from "../ShardStore/index.js";
|
|
5
|
-
export declare const spawn: import("callbag-effect-ts/Source").EffectSource<import("../../Log/index.js").Log | import("../DiscordWS/index.js").DiscordWSCodec | import("../../
|
|
5
|
+
export declare const spawn: import("callbag-effect-ts/Source").EffectSource<import("../../Log/index.js").Log | import("../DiscordWS/index.js").DiscordWSCodec | import("../../RateLimit/index.js").RateLimiter | import("../../DiscordConfig/index.js").DiscordConfig | ShardStore | import("../../index.js").DiscordREST, never, {
|
|
6
6
|
run: import("../../global.js").Effect<never, never, void>;
|
|
7
7
|
raw: import("callbag-effect-ts/Source").EffectSource<never, never, import("../../types.js").GatewayPayload<any>>;
|
|
8
8
|
dispatch: import("callbag-effect-ts/Source").EffectSource<never, never, import("../../types.js").GatewayPayload<import("../../types.js").ReceiveEvent>>;
|