@moneypot/hub 1.14.3 → 1.14.7
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/dist/dashboard/assets/{index-D5u-RqBs.js → index-BXG4SGJn.js} +56 -56
- package/dist/dashboard/index.html +1 -1
- package/dist/src/graphile.d.ts +1 -1
- package/dist/src/graphile.js +1 -1
- package/dist/src/hash-chain/plugins/hub-user-active-hash-chain.js +34 -25
- package/dist/src/plugins/debug.js +2 -2
- package/dist/src/plugins/hub-current-x.js +10 -27
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Dashboard</title>
|
|
7
|
-
<script type="module" crossorigin src="/dashboard/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/dashboard/assets/index-BXG4SGJn.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/dashboard/assets/index-LZVcTrKv.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
package/dist/src/graphile.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { makeExtendSchemaPlugin, gql } from "postgraphile/utils";
|
|
1
|
+
export { makeExtendSchemaPlugin, extendSchema, gql } from "postgraphile/utils";
|
package/dist/src/graphile.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { makeExtendSchemaPlugin, gql } from "postgraphile/utils";
|
|
1
|
+
export { makeExtendSchemaPlugin, extendSchema, gql } from "postgraphile/utils";
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { maybeOneRow } from "@moneypot/hub/db";
|
|
2
1
|
import { inhibitOnNull } from "@moneypot/hub/grafast";
|
|
3
|
-
import { context } from "@moneypot/hub/grafast";
|
|
4
2
|
import { gql, makeExtendSchemaPlugin } from "@moneypot/hub/graphile";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { loadOneWithPgClient, } from "postgraphile/@dataplan/pg";
|
|
4
|
+
import { context } from "postgraphile/grafast";
|
|
7
5
|
export const HubUserActiveHashChainPlugin = makeExtendSchemaPlugin((build) => {
|
|
8
6
|
const hashChainTable = build.input.pgRegistry.pgResources.hub_hash_chain;
|
|
9
7
|
return {
|
|
@@ -17,27 +15,10 @@ export const HubUserActiveHashChainPlugin = makeExtendSchemaPlugin((build) => {
|
|
|
17
15
|
plans: {
|
|
18
16
|
activeHashChain: ($record) => {
|
|
19
17
|
const $identity = context().get("identity");
|
|
20
|
-
const $
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const { session } = identity;
|
|
25
|
-
const activeHashChain = await pgClient
|
|
26
|
-
.query({
|
|
27
|
-
text: `
|
|
28
|
-
select id
|
|
29
|
-
from hub.hash_chain
|
|
30
|
-
where user_id = $1
|
|
31
|
-
and experience_id = $2
|
|
32
|
-
and casino_id = $3
|
|
33
|
-
and active = TRUE
|
|
34
|
-
order by id desc
|
|
35
|
-
limit 1
|
|
36
|
-
`,
|
|
37
|
-
values: [userId, session.experience_id, session.casino_id],
|
|
38
|
-
})
|
|
39
|
-
.then(maybeOneRow);
|
|
40
|
-
return activeHashChain?.id ?? null;
|
|
18
|
+
const $userId = $record.get("id");
|
|
19
|
+
const $hashChainId = loadOneWithPgClient(hashChainTable.executor, $userId, {
|
|
20
|
+
load: batchGetActiveHashChain,
|
|
21
|
+
shared: { identity: $identity },
|
|
41
22
|
});
|
|
42
23
|
return hashChainTable.get({ id: inhibitOnNull($hashChainId) });
|
|
43
24
|
},
|
|
@@ -46,3 +27,31 @@ export const HubUserActiveHashChainPlugin = makeExtendSchemaPlugin((build) => {
|
|
|
46
27
|
},
|
|
47
28
|
};
|
|
48
29
|
}, "HubActiveHashChainPlugin");
|
|
30
|
+
async function batchGetActiveHashChain(pgClient, userIds, info) {
|
|
31
|
+
const { identity } = info.shared;
|
|
32
|
+
if (identity?.kind !== "user" || !identity.session?.experience_id) {
|
|
33
|
+
return userIds.map(() => null);
|
|
34
|
+
}
|
|
35
|
+
const experienceId = identity.session.experience_id;
|
|
36
|
+
const query = `
|
|
37
|
+
SELECT
|
|
38
|
+
(idx - 1)::int as input_index,
|
|
39
|
+
(
|
|
40
|
+
SELECT id
|
|
41
|
+
FROM hub.hash_chain
|
|
42
|
+
WHERE user_id = user_ids.val
|
|
43
|
+
AND experience_id = $2
|
|
44
|
+
AND active = TRUE
|
|
45
|
+
ORDER BY id DESC
|
|
46
|
+
LIMIT 1
|
|
47
|
+
) as id
|
|
48
|
+
FROM unnest($1::uuid[]) WITH ORDINALITY as user_ids(val, idx)
|
|
49
|
+
ORDER BY idx
|
|
50
|
+
`;
|
|
51
|
+
const { rows } = await pgClient.query({
|
|
52
|
+
text: query,
|
|
53
|
+
values: [userIds, experienceId],
|
|
54
|
+
});
|
|
55
|
+
const resultMap = new Map(rows.map((row) => [row.input_index, row.id]));
|
|
56
|
+
return userIds.map((_, index) => resultMap.get(index) ?? null);
|
|
57
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { logger } from "../logger.js";
|
|
2
2
|
export const DebugPlugin = {
|
|
3
|
-
name: "
|
|
4
|
-
description: "
|
|
3
|
+
name: "HubDebugPlugin",
|
|
4
|
+
description: "Logs graphql operations, useful for development",
|
|
5
5
|
version: "0.0.1",
|
|
6
6
|
grafserv: {
|
|
7
7
|
hooks: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { gql,
|
|
2
|
-
import { context, inhibitOnNull
|
|
3
|
-
export const HubCurrentXPlugin =
|
|
1
|
+
import { gql, extendSchema } from "postgraphile/utils";
|
|
2
|
+
import { access, context, inhibitOnNull } from "postgraphile/grafast";
|
|
3
|
+
export const HubCurrentXPlugin = extendSchema((build) => {
|
|
4
4
|
const userTable = build.input.pgRegistry.pgResources.hub_user;
|
|
5
5
|
const casinoTable = build.input.pgRegistry.pgResources.hub_casino;
|
|
6
6
|
const experienceTable = build.input.pgRegistry.pgResources.hub_experience;
|
|
@@ -19,42 +19,25 @@ export const HubCurrentXPlugin = makeExtendSchemaPlugin((build) => {
|
|
|
19
19
|
plans: {
|
|
20
20
|
hubCurrentUser() {
|
|
21
21
|
const $identity = context().get("identity");
|
|
22
|
-
const $userId =
|
|
23
|
-
if (identity?.kind === "user") {
|
|
24
|
-
return identity.session.user_id;
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
});
|
|
22
|
+
const $userId = access($identity, ["session", "user_id"]);
|
|
28
23
|
return userTable.get({ id: inhibitOnNull($userId) });
|
|
29
24
|
},
|
|
30
25
|
hubCurrentCasino() {
|
|
31
26
|
const $identity = context().get("identity");
|
|
32
|
-
const $casinoId =
|
|
33
|
-
if (identity?.kind === "user") {
|
|
34
|
-
return identity.session.casino_id;
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
});
|
|
27
|
+
const $casinoId = access($identity, ["session", "casino_id"]);
|
|
38
28
|
return casinoTable.get({ id: inhibitOnNull($casinoId) });
|
|
39
29
|
},
|
|
40
30
|
hubCurrentExperience() {
|
|
41
31
|
const $identity = context().get("identity");
|
|
42
|
-
const $experienceId =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return null;
|
|
47
|
-
});
|
|
32
|
+
const $experienceId = access($identity, [
|
|
33
|
+
"session",
|
|
34
|
+
"experience_id",
|
|
35
|
+
]);
|
|
48
36
|
return experienceTable.get({ id: inhibitOnNull($experienceId) });
|
|
49
37
|
},
|
|
50
38
|
hubCurrentSession() {
|
|
51
39
|
const $identity = context().get("identity");
|
|
52
|
-
const $sessionId =
|
|
53
|
-
if (identity?.kind === "user") {
|
|
54
|
-
return identity.session.session_id;
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
});
|
|
40
|
+
const $sessionId = access($identity, ["session", "session_id"]);
|
|
58
41
|
return sessionTable.get({ id: inhibitOnNull($sessionId) });
|
|
59
42
|
},
|
|
60
43
|
},
|