@moneypot/hub 1.20.0-dev.0 → 1.20.0-dev.2
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/src/db/util.d.ts +2 -1
- package/dist/src/liability/internal/db.d.ts +1 -4
- package/dist/src/liability/internal/db.js +1 -16
- package/dist/src/liability/internal/index.d.ts +1 -1
- package/dist/src/liability/internal/index.js +1 -1
- package/dist/src/liability/internal/processor.d.ts +4 -0
- package/dist/src/liability/internal/processor.js +2 -3
- package/dist/src/liability/public/config.d.ts +13 -7
- package/dist/src/liability/public/config.js +4 -1
- package/dist/src/util.d.ts +3 -0
- package/package.json +1 -1
package/dist/src/db/util.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { QueryResult, QueryResultRow } from "pg";
|
|
2
2
|
import { PgClientResult } from "postgraphile/@dataplan/pg";
|
|
3
3
|
import * as pg from "pg";
|
|
4
|
-
|
|
4
|
+
import { Prettify } from "../util.js";
|
|
5
|
+
export type QueryExecutor = Prettify<Pick<pg.Pool, "query"> | Pick<pg.ClientBase, "query">>;
|
|
5
6
|
type ResultType<T> = PgClientResult<T> | QueryResult<T extends QueryResultRow ? T : never>;
|
|
6
7
|
export declare function maybeOneRow<T>(result: ResultType<T>): T | undefined;
|
|
7
8
|
export declare function exactlyOneRow<T>(result: ResultType<T>): T;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { PgClientInTransaction } from "../../db/transaction.js";
|
|
2
2
|
import { DbLiability } from "../types.js";
|
|
3
|
-
export declare function
|
|
4
|
-
limit?: number;
|
|
5
|
-
}): Promise<DbLiability[]>;
|
|
6
|
-
export declare function dbGetAndLockLiability(pool: PgClientInTransaction, { id }: {
|
|
3
|
+
export declare function dbLockLiability(pool: PgClientInTransaction, { id }: {
|
|
7
4
|
id: string;
|
|
8
5
|
}): Promise<DbLiability | null>;
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
export async function
|
|
2
|
-
const result = await pgClient.query({
|
|
3
|
-
text: `
|
|
4
|
-
SELECT *
|
|
5
|
-
FROM hub.liability
|
|
6
|
-
WHERE resolved_at IS NULL
|
|
7
|
-
AND deadline < now()
|
|
8
|
-
ORDER BY deadline ASC
|
|
9
|
-
LIMIT $1
|
|
10
|
-
FOR UPDATE SKIP LOCKED
|
|
11
|
-
`,
|
|
12
|
-
values: [limit],
|
|
13
|
-
});
|
|
14
|
-
return result.rows;
|
|
15
|
-
}
|
|
16
|
-
export async function dbGetAndLockLiability(pool, { id }) {
|
|
1
|
+
export async function dbLockLiability(pool, { id }) {
|
|
17
2
|
const result = await pool.query({
|
|
18
3
|
text: `
|
|
19
4
|
SELECT *
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { dbLockLiability } from "./db.js";
|
|
2
2
|
export { startLiabilityExpirationProcessor, processExpiredLiabilities, } from "./processor.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { dbLockLiability } from "./db.js";
|
|
2
2
|
export { startLiabilityExpirationProcessor, processExpiredLiabilities, } from "./processor.js";
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as pg from "pg";
|
|
2
2
|
import { LiabilityConfigInternal } from "../public/config.js";
|
|
3
|
+
import { QueryExecutor } from "../../db/util.js";
|
|
4
|
+
export declare function dbGetLiabilityIdsPastDeadline(pgClient: QueryExecutor, { limit }?: {
|
|
5
|
+
limit?: number;
|
|
6
|
+
}): Promise<string[]>;
|
|
3
7
|
export declare function startLiabilityExpirationProcessor<RefType extends string>({ signal, pool, liabilityConfig, }: {
|
|
4
8
|
signal: AbortSignal;
|
|
5
9
|
pool: pg.Pool;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { logger } from "../../logger.js";
|
|
2
2
|
import { withPgPoolTransaction, } from "../../db/transaction.js";
|
|
3
3
|
import { dbLockHouseBankroll, dbLockPlayerBalance } from "../../db/public.js";
|
|
4
|
-
const POLL_INTERVAL = 30_000;
|
|
5
4
|
const BATCH_SIZE = 100;
|
|
6
|
-
async function dbGetLiabilityIdsPastDeadline(pgClient, { limit = 100 } = {}) {
|
|
5
|
+
export async function dbGetLiabilityIdsPastDeadline(pgClient, { limit = 100 } = {}) {
|
|
7
6
|
const result = await pgClient.query({
|
|
8
7
|
text: `
|
|
9
8
|
SELECT id
|
|
@@ -49,7 +48,7 @@ export function startLiabilityExpirationProcessor({ signal, pool, liabilityConfi
|
|
|
49
48
|
logger.error(e, `Error processing expired liabilities`);
|
|
50
49
|
}
|
|
51
50
|
if (!shouldStop && !signal.aborted) {
|
|
52
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
51
|
+
await new Promise((resolve) => setTimeout(resolve, liabilityConfig._options.pollIntervalMs));
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
logger.info(`Liability expiration processor stopped`);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DbLockedHouseBankrollWithAvailable, DbLockedPlayerBalance, PgClientInTransaction } from "../../db/index.js";
|
|
2
2
|
import { Branded } from "../../util.js";
|
|
3
|
-
import type { DbLiability } from "../types.js";
|
|
4
|
-
import { dbCreateLiability, dbResolveLiabilityByRef } from "./db.js";
|
|
3
|
+
import type { DbLiability, NewLiability } from "../types.js";
|
|
5
4
|
export type DbLockedLiability<RefType extends string = string> = DbLiability & {
|
|
6
5
|
ref_type: RefType;
|
|
7
6
|
};
|
|
@@ -21,16 +20,23 @@ export type LiabilityRefTypeConfig<RefType extends string> = {
|
|
|
21
20
|
};
|
|
22
21
|
export declare function createLiabilityConfig<RefType extends string>(refTypes: {
|
|
23
22
|
[K in RefType]: LiabilityRefTypeConfig<K>;
|
|
24
|
-
}, options?: LiabilityConfigOptions): LiabilityConfig<RefType>;
|
|
23
|
+
}, options?: Partial<LiabilityConfigOptions>): LiabilityConfig<RefType>;
|
|
25
24
|
export type LiabilityConfig<RefType extends string> = {
|
|
26
|
-
dbCreateLiability:
|
|
27
|
-
|
|
25
|
+
dbCreateLiability: <T extends RefType>(pgClient: PgClientInTransaction, args: NewLiability<T>) => Promise<DbLiability & {
|
|
26
|
+
ref_type: T;
|
|
27
|
+
}>;
|
|
28
|
+
dbResolveLiabilityByRef: <T extends RefType>(pgClient: PgClientInTransaction, args: {
|
|
29
|
+
refType: T;
|
|
30
|
+
refId: string;
|
|
31
|
+
lockedBankrollId: string;
|
|
32
|
+
}) => Promise<boolean>;
|
|
33
|
+
};
|
|
34
|
+
export type LiabilityConfigOptions = {
|
|
35
|
+
pollIntervalMs: number;
|
|
28
36
|
};
|
|
29
|
-
type LiabilityConfigOptions = never;
|
|
30
37
|
export type LiabilityConfigInternal<RefType extends string> = LiabilityConfig<RefType> & {
|
|
31
38
|
_refTypes: {
|
|
32
39
|
[K in RefType]: LiabilityRefTypeConfig<K>;
|
|
33
40
|
};
|
|
34
41
|
_options: LiabilityConfigOptions;
|
|
35
42
|
};
|
|
36
|
-
export {};
|
|
@@ -2,10 +2,13 @@ import { dbCreateLiability, dbResolveLiabilityByRef } from "./db.js";
|
|
|
2
2
|
export const LIABILITY_RESOLVED = {
|
|
3
3
|
resolved: true,
|
|
4
4
|
};
|
|
5
|
+
const DEFAULT_OPTIONS = {
|
|
6
|
+
pollIntervalMs: 30_000,
|
|
7
|
+
};
|
|
5
8
|
export function createLiabilityConfig(refTypes, options) {
|
|
6
9
|
return {
|
|
7
10
|
_refTypes: refTypes,
|
|
8
|
-
_options: options,
|
|
11
|
+
_options: { ...DEFAULT_OPTIONS, ...options },
|
|
9
12
|
dbCreateLiability,
|
|
10
13
|
dbResolveLiabilityByRef,
|
|
11
14
|
};
|
package/dist/src/util.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ declare const BRAND: unique symbol;
|
|
|
3
3
|
export type Branded<Brand, T> = T & {
|
|
4
4
|
readonly [BRAND]: Brand;
|
|
5
5
|
};
|
|
6
|
+
export type Prettify<T> = {
|
|
7
|
+
[K in keyof T]: T[K];
|
|
8
|
+
} & {};
|
|
6
9
|
export declare function isUuid(input: any): boolean;
|
|
7
10
|
export type Result<V, E> = {
|
|
8
11
|
ok: true;
|