@moneypot/hub 1.3.0-dev.14 → 1.3.0-dev.16

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.
@@ -37,7 +37,7 @@ declare const InputSchema: z.ZodObject<{
37
37
  weight: number;
38
38
  }[]>;
39
39
  hashChainId: z.ZodString;
40
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
40
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
41
41
  }, "strict", z.ZodTypeAny, {
42
42
  currency: string;
43
43
  hashChainId: string;
@@ -47,7 +47,7 @@ declare const InputSchema: z.ZodObject<{
47
47
  profit: number;
48
48
  weight: number;
49
49
  }[];
50
- metadata?: Record<string, any> | undefined;
50
+ metadata?: Record<string, unknown> | undefined;
51
51
  }, {
52
52
  currency: string;
53
53
  hashChainId: string;
@@ -57,10 +57,11 @@ declare const InputSchema: z.ZodObject<{
57
57
  profit: number;
58
58
  weight: number;
59
59
  }[];
60
- metadata?: Record<string, any> | undefined;
60
+ metadata?: Record<string, unknown> | undefined;
61
61
  }>;
62
62
  type Input = z.infer<typeof InputSchema>;
63
63
  type Outcome = z.infer<typeof OutcomeSchema>;
64
+ type Metadata = NonNullable<Input["metadata"]>;
64
65
  type FinalizeMetadataData = {
65
66
  wager: number;
66
67
  currencyKey: string;
@@ -72,8 +73,8 @@ type FinalizeMetadataData = {
72
73
  export type OutcomeBetConfig = {
73
74
  houseEdge: number;
74
75
  saveOutcomes: boolean;
75
- initializeMetadataFromUntrustedUserInput?: (input: Input) => Result<Record<string, any>, string>;
76
- finalizeMetadata?: (validatedMetadata: Record<string, any>, data: FinalizeMetadataData) => Record<string, any>;
76
+ initializeMetadataFromUntrustedUserInput?: (input: Input) => Result<Metadata, string>;
77
+ finalizeMetadata?: (validatedMetadata: Metadata, data: FinalizeMetadataData) => Metadata;
77
78
  };
78
79
  export type OutcomeBetConfigMap<BetKind extends string> = {
79
80
  [betKind in BetKind]: OutcomeBetConfig;
@@ -39,7 +39,7 @@ const InputSchema = z
39
39
  .refine((data) => data.some((o) => o.profit < 0), "At least one outcome should have profit < 0")
40
40
  .refine((data) => data.some((o) => o.profit > 0), "At least one outcome should have profit > 0"),
41
41
  hashChainId: z.string().uuid("Invalid hash chain ID"),
42
- metadata: z.record(z.string(), z.any()).optional(),
42
+ metadata: z.record(z.string(), z.unknown()).optional(),
43
43
  })
44
44
  .strict();
45
45
  const BetKindSchema = z
@@ -119,9 +119,6 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
119
119
  if (!betConfig) {
120
120
  throw new GraphQLError(`Invalid bet kind`);
121
121
  }
122
- if (!betKinds.includes(rawInput.kind)) {
123
- throw new GraphQLError(`Invalid bet kind`);
124
- }
125
122
  let initializedMetadata;
126
123
  if (betConfig.initializeMetadataFromUntrustedUserInput) {
127
124
  const result = betConfig.initializeMetadataFromUntrustedUserInput(input);
@@ -1,55 +1,30 @@
1
- import { access, context, loadOne, object, } from "postgraphile/grafast";
1
+ import { access, constant, context } from "postgraphile/grafast";
2
2
  import { gql, makeExtendSchemaPlugin } from "postgraphile/utils";
3
- import { superuserPool } from "../db/index.js";
4
- import { pgSelectSingleFromRecord, } from "postgraphile/@dataplan/pg";
3
+ import { TYPES } from "postgraphile/@dataplan/pg";
4
+ import { sql } from "postgraphile/pg-sql2";
5
5
  export const HubUserBalanceByCurrencyPlugin = makeExtendSchemaPlugin((build) => {
6
- const balances = build.input.pgRegistry.pgResources.hub_balance;
6
+ const balanceTable = build.input.pgRegistry.pgResources.hub_balance;
7
7
  return {
8
8
  typeDefs: gql `
9
9
  extend type HubUser {
10
- balanceByCurrency(currency: String!): HubBalance
10
+ hubBalanceByCurrency(currency: String!): HubBalance
11
11
  }
12
12
  `,
13
13
  plans: {
14
14
  HubUser: {
15
- balanceByCurrency: ($record, { $currency }) => {
15
+ hubBalanceByCurrency: ($record, { $currency }) => {
16
16
  const $identity = context().get("identity");
17
- const $params = object({
18
- currency: $currency,
19
- targetUserId: $record.get("id"),
20
- casino_id: access($identity, ["session", "casino_id"]),
21
- experience_id: access($identity, ["session", "experience_id"]),
22
- });
23
- const $balance = loadOne($params, batchGetUserBalanceByCurrency);
24
- return pgSelectSingleFromRecord(balances, $balance);
17
+ const $balances = balanceTable.find();
18
+ $balances.where(sql `
19
+ ${$balances}.currency_key = ${$balances.placeholder($currency, TYPES.text)}
20
+ AND ${$balances}.user_id = ${$balances.placeholder($record.get("id"), TYPES.uuid)}
21
+ AND ${$balances}.casino_id = ${$balances.placeholder(access($identity, ["session", "casino_id"]), TYPES.uuid)}
22
+ AND ${$balances}.experience_id = ${$balances.placeholder(access($identity, ["session", "experience_id"]), TYPES.uuid)}
23
+ `);
24
+ $balances.setFirst(constant(1));
25
+ return $balances.single();
25
26
  },
26
27
  },
27
28
  },
28
29
  };
29
30
  });
30
- async function batchGetUserBalanceByCurrency(paramsArray) {
31
- const values = [];
32
- const valuePlaceholders = [];
33
- paramsArray.forEach((p, index) => {
34
- const baseIndex = index * 4 + 1;
35
- valuePlaceholders.push(`($${baseIndex}, $${baseIndex + 1}::uuid, $${baseIndex + 2}::uuid, $${baseIndex + 3}::uuid)`);
36
- values.push(p.currency, p.targetUserId, p.casino_id, p.experience_id);
37
- });
38
- const sql = `
39
- SELECT b.*
40
- FROM hub.balance b
41
- JOIN (
42
- VALUES
43
- ${valuePlaceholders.join(",\n ")}
44
- ) AS vals(currency_key, user_id, casino_id, experience_id)
45
- ON b.currency_key = vals.currency_key
46
- AND b.user_id = vals.user_id
47
- AND b.casino_id = vals.casino_id
48
- AND b.experience_id = vals.experience_id
49
- `;
50
- const { rows } = await superuserPool.query(sql, values);
51
- return paramsArray.map((p) => rows.find((row) => row.currency_key === p.currency &&
52
- row.user_id === p.targetUserId &&
53
- row.casino_id === p.casino_id &&
54
- row.experience_id === p.experience_id));
55
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneypot/hub",
3
- "version": "1.3.0-dev.14",
3
+ "version": "1.3.0-dev.16",
4
4
  "author": "moneypot.com",
5
5
  "homepage": "https://moneypot.com/hub",
6
6
  "keywords": [