@moneypot/hub 1.14.2 → 1.14.6

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.
@@ -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-D5u-RqBs.js"></script>
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>
@@ -1 +1 @@
1
- export { makeExtendSchemaPlugin, gql } from "postgraphile/utils";
1
+ export { makeExtendSchemaPlugin, extendSchema, gql } from "postgraphile/utils";
@@ -1 +1 @@
1
- export { makeExtendSchemaPlugin, gql } from "postgraphile/utils";
1
+ export { makeExtendSchemaPlugin, extendSchema, gql } from "postgraphile/utils";
@@ -1,8 +1,7 @@
1
- import { withPgClient } from "postgraphile/@dataplan/pg";
2
- import { inhibitOnNull, object } from "postgraphile/grafast";
3
- import { gql, makeExtendSchemaPlugin } from "postgraphile/utils";
4
- import { maybeOneRow } from "../../db/util.js";
5
- export const HubPreimageHashFieldPlugin = makeExtendSchemaPlugin((build) => {
1
+ import { loadOneWithPgClient, } from "postgraphile/@dataplan/pg";
2
+ import { inhibitOnNull } from "postgraphile/grafast";
3
+ import { gql, extendSchema } from "postgraphile/utils";
4
+ export const HubPreimageHashFieldPlugin = extendSchema((build) => {
6
5
  const hashTable = build.input.pgRegistry.pgResources.hub_hash;
7
6
  return {
8
7
  typeDefs: gql `
@@ -14,19 +13,20 @@ export const HubPreimageHashFieldPlugin = makeExtendSchemaPlugin((build) => {
14
13
  HubHashChain: {
15
14
  plans: {
16
15
  preimageHash: ($record) => {
17
- const $preimageHashId = withPgClient(hashTable.executor, object({ hashChainId: $record.get("id") }), async (pgClient, { hashChainId }) => {
18
- const hash = await pgClient
19
- .query({
16
+ const $preimageHashId = loadOneWithPgClient(hashTable.executor, $record.get("id"), async (pgClient, hashChainIds) => {
17
+ const { rows } = await pgClient.query({
20
18
  text: `
21
- select id
22
- from hub.hash
23
- where hash_chain_id = $1
24
- and kind = 'PREIMAGE'
25
- `,
26
- values: [hashChainId],
27
- })
28
- .then(maybeOneRow);
29
- return hash?.id ?? null;
19
+ select id, hash_chain_id
20
+ from hub.hash
21
+ where hash_chain_id = ANY($1)
22
+ and kind = 'PREIMAGE'
23
+ `,
24
+ values: [hashChainIds],
25
+ });
26
+ const lookup = new Map(rows.map((row) => [row.hash_chain_id, row.id]));
27
+ return hashChainIds.map((hashChainId) => {
28
+ return lookup.get(hashChainId) ?? null;
29
+ });
30
30
  });
31
31
  return hashTable.get({ id: inhibitOnNull($preimageHashId) });
32
32
  },
@@ -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 { withPgClient } from "postgraphile/@dataplan/pg";
6
- import { object } from "postgraphile/grafast";
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 $hashChainId = withPgClient(hashChainTable.executor, object({ userId: $record.get("id"), identity: $identity }), async (pgClient, { userId, identity }) => {
21
- if (identity?.kind !== "user") {
22
- return null;
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: "DebugPlugin",
4
- description: "A place to artificially slow down the server to test client",
3
+ name: "HubDebugPlugin",
4
+ description: "Logs graphql operations, useful for development",
5
5
  version: "0.0.1",
6
6
  grafserv: {
7
7
  hooks: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneypot/hub",
3
- "version": "1.14.2",
3
+ "version": "1.14.6",
4
4
  "author": "moneypot.com",
5
5
  "homepage": "https://moneypot.com/hub",
6
6
  "keywords": [
@@ -59,7 +59,7 @@
59
59
  "pg": "^8.12.0",
60
60
  "pg-connection-string": "^2.6.4",
61
61
  "pino": "^9.7.0",
62
- "postgraphile": "^5.0.0-beta.42",
62
+ "postgraphile": "^5.0.0-beta.48",
63
63
  "tsafe": "^1.6.6",
64
64
  "yup": "^1.6.1",
65
65
  "zod": "^3.23.5"