@moneypot/hub 1.19.13 → 1.19.15

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.
@@ -8,5 +8,6 @@ export interface ServerContext {
8
8
  export declare function createServerContext(overrides?: {
9
9
  superuserDatabaseUrl?: string;
10
10
  postgraphileDatabaseUrl?: string;
11
+ poolMax?: number;
11
12
  }): ServerContext;
12
13
  export declare function closeServerContext(context: ServerContext): Promise<void>;
@@ -8,9 +8,11 @@ export function createServerContext(overrides) {
8
8
  const context = {
9
9
  postgraphilePool: new pg.Pool({
10
10
  connectionString: postgraphileDatabaseUrl,
11
+ max: overrides?.poolMax,
11
12
  }),
12
13
  superuserPool: new pg.Pool({
13
14
  connectionString: superuserDatabaseUrl,
15
+ max: overrides?.poolMax,
14
16
  }),
15
17
  notifier: new DatabaseNotifier(postgraphileDatabaseUrl),
16
18
  };
@@ -1,3 +1,3 @@
1
1
 
2
- ALTER TABLE hub.hash
3
- ADD CONSTRAINT client_seed_length CHECK (length(client_seed) <= 36);
2
+ ALTER TABLE hub.hash DROP CONSTRAINT IF EXISTS client_seed_length;
3
+ ALTER TABLE hub.hash ADD CONSTRAINT client_seed_length CHECK (length(client_seed) <= 36);
@@ -0,0 +1,7 @@
1
+ ALTER TABLE hub.hash DROP CONSTRAINT IF EXISTS hash_iteration_kind_check;
2
+
3
+ ALTER TABLE hub.hash
4
+ ADD CONSTRAINT hash_iteration_kind_check CHECK (
5
+ (iteration = 0 AND kind = 'PREIMAGE') OR
6
+ (iteration > 0 AND kind IN ('INTERMEDIATE', 'TERMINAL'))
7
+ );
@@ -26,7 +26,7 @@ export function HubRiskLimitsPlugin({ outcomeBetConfigs, customGameConfigs, }) {
26
26
  mergedConfigs[kind] = customGameConfigs[kind];
27
27
  }
28
28
  }
29
- return extendSchema((build) => {
29
+ return extendSchema(() => {
30
30
  const typeDefs = gql `
31
31
  enum AnyGameKind {
32
32
  ${anyGameKindEnumValues.join("\n")}
@@ -29,7 +29,7 @@ export declare const requiredPlugins: readonly GraphileConfig.Plugin[];
29
29
  export declare const defaultPlugins: readonly GraphileConfig.Plugin[];
30
30
  import { HubGameConfigPlugin } from "../plugins/hub-game-config-plugin.js";
31
31
  export type HubPlugin = GraphileConfig.Plugin | HubGameConfigPlugin;
32
- export declare function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, context, enableChat, enablePlayground, postgraphileDatabaseUrl, }: {
32
+ export declare function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, context, enableChat, enablePlayground, postgraphileDatabaseUrl, poolMax, }: {
33
33
  plugins: readonly HubPlugin[];
34
34
  exportSchemaSDLPath?: string;
35
35
  extraPgSchemas: string[];
@@ -38,6 +38,7 @@ export declare function createPreset({ plugins, exportSchemaSDLPath, extraPgSche
38
38
  enableChat: boolean;
39
39
  enablePlayground: boolean;
40
40
  postgraphileDatabaseUrl: string;
41
+ poolMax?: number;
41
42
  }): {
42
43
  preset: GraphileConfig.Preset;
43
44
  pgService: GraphileConfig.PgServiceConfiguration<"@dataplan/pg/adaptors/pg">;
@@ -57,7 +57,7 @@ export const defaultPlugins = [
57
57
  ...requiredPlugins,
58
58
  ];
59
59
  import { HubGameConfigPlugin, isHubGameConfigPlugin, expandHubGameConfigPlugin, } from "../plugins/hub-game-config-plugin.js";
60
- export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, context, enableChat, enablePlayground, postgraphileDatabaseUrl, }) {
60
+ export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, context, enableChat, enablePlayground, postgraphileDatabaseUrl, poolMax, }) {
61
61
  if (exportSchemaSDLPath) {
62
62
  if (!exportSchemaSDLPath.startsWith("/")) {
63
63
  throw new Error("exportSchemaSDLPath must be an absolute path");
@@ -95,6 +95,7 @@ export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abo
95
95
  const pgService = makePgService({
96
96
  connectionString: postgraphileDatabaseUrl,
97
97
  schemas: [...extraPgSchemas, "hub"],
98
+ poolConfig: poolMax ? { max: poolMax } : undefined,
98
99
  });
99
100
  const preset = {
100
101
  extends: [PostGraphileAmberPreset],
@@ -22,5 +22,6 @@ export type CreateHubServerOptions = {
22
22
  runProcessors: boolean;
23
23
  superuserDatabaseUrl: string;
24
24
  postgraphileDatabaseUrl: string;
25
+ poolMax?: number;
25
26
  };
26
- export declare function createHubServer({ configureApp, plugins, exportSchemaSDLPath, extraPgSchemas, enableChat, enablePlayground, port, runProcessors, superuserDatabaseUrl, postgraphileDatabaseUrl, }: CreateHubServerOptions): HubServer;
27
+ export declare function createHubServer({ configureApp, plugins, exportSchemaSDLPath, extraPgSchemas, enableChat, enablePlayground, port, runProcessors, superuserDatabaseUrl, postgraphileDatabaseUrl, poolMax, }: CreateHubServerOptions): HubServer;
@@ -46,11 +46,12 @@ function createExpressServer(context) {
46
46
  });
47
47
  return app;
48
48
  }
49
- export function createHubServer({ configureApp, plugins, exportSchemaSDLPath, extraPgSchemas, enableChat, enablePlayground, port, runProcessors, superuserDatabaseUrl, postgraphileDatabaseUrl, }) {
49
+ export function createHubServer({ configureApp, plugins, exportSchemaSDLPath, extraPgSchemas, enableChat, enablePlayground, port, runProcessors, superuserDatabaseUrl, postgraphileDatabaseUrl, poolMax, }) {
50
50
  const abortController = new AbortController();
51
51
  const context = createServerContext({
52
52
  superuserDatabaseUrl,
53
53
  postgraphileDatabaseUrl,
54
+ poolMax,
54
55
  });
55
56
  const expressServer = createExpressServer(context);
56
57
  const { preset, pgService } = createPreset({
@@ -62,6 +63,7 @@ export function createHubServer({ configureApp, plugins, exportSchemaSDLPath, ex
62
63
  context,
63
64
  enableChat,
64
65
  enablePlayground,
66
+ poolMax,
65
67
  });
66
68
  const pgl = postgraphile.default(preset);
67
69
  const serv = pgl.createServ(grafserv);
@@ -5,6 +5,7 @@ import { ServerOptions } from "../index.js";
5
5
  export type HubTestServer = {
6
6
  port: number;
7
7
  stop: () => Promise<void>;
8
+ destroy: () => Promise<void>;
8
9
  dbPool: Pool;
9
10
  playgroundCasinoId: string;
10
11
  authenticate: (userId: DbUser["id"], experienceId: DbExperience["id"]) => Promise<{
@@ -1,20 +1,18 @@
1
1
  import { Client, Pool } from "pg";
2
2
  import { randomBytes, randomUUID } from "node:crypto";
3
- import { execSync } from "node:child_process";
3
+ import { exec } from "node:child_process";
4
+ import { promisify } from "node:util";
5
+ const execAsync = promisify(exec);
4
6
  import { DbHashKind, } from "../db/types.js";
5
- import { exactlyOneRow, maybeOneRow, } from "../db/index.js";
7
+ import { exactlyOneRow, maybeOneRow } from "../db/index.js";
6
8
  import { GraphQLClient } from "graphql-request";
7
9
  import { defaultPlugins, runMigrations } from "../index.js";
8
10
  import { createHubServer } from "../server/index.js";
9
- const createdDatabases = new Set();
10
11
  export async function startTestServer({ plugins = [...defaultPlugins], userDatabaseMigrationsPath, databaseName, extraPgSchemas = [], } = {}) {
11
12
  const dbName = databaseName ?? `hub-test-${randomUUID().slice(0, 8)}`;
12
13
  const connectionString = `postgres://postgres@localhost/${dbName}`;
13
14
  try {
14
- execSync(`psql -U postgres -c "CREATE DATABASE \\"${dbName}\\""`, {
15
- stdio: "pipe",
16
- });
17
- createdDatabases.add(dbName);
15
+ await execAsync(`psql -U postgres -c "CREATE DATABASE \\"${dbName}\\""`);
18
16
  }
19
17
  catch (_e) {
20
18
  const pool = new Pool({ connectionString });
@@ -66,13 +64,23 @@ export async function startTestServer({ plugins = [...defaultPlugins], userDatab
66
64
  if (!playgroundCasinoId) {
67
65
  throw new Error("Playground casino not found - migrations may have failed");
68
66
  }
67
+ const stop = async () => {
68
+ await dbPool.end();
69
+ await hubServer.shutdown();
70
+ };
69
71
  return {
70
72
  port,
71
73
  dbPool,
72
74
  playgroundCasinoId,
73
- stop: async () => {
74
- await dbPool.end();
75
- await hubServer.shutdown();
75
+ stop,
76
+ destroy: async () => {
77
+ await stop();
78
+ try {
79
+ await execAsync(`psql -U postgres -c "DROP DATABASE \\"${dbName}\\""`);
80
+ }
81
+ catch (e) {
82
+ console.warn(`Failed to drop test database ${dbName}:`, e);
83
+ }
76
84
  },
77
85
  authenticate: async (userId, experienceId) => {
78
86
  const user = await dbPool
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneypot/hub",
3
- "version": "1.19.13",
3
+ "version": "1.19.15",
4
4
  "author": "moneypot.com",
5
5
  "homepage": "https://moneypot.com/hub",
6
6
  "keywords": [