Template
1
0

feat: add payment module

This commit is contained in:
2025-12-05 01:56:42 +01:00
parent a818f3135a
commit be9b8e9e55
160 changed files with 8615 additions and 1158 deletions

View File

@@ -1,12 +1,16 @@
import { AsyncLocalStorage } from "node:async_hooks";
import { serialize } from "node:v8";
import { takeAll, takeOne } from "@platform/parse";
import postgres, { type Options, type Sql, type TransactionSql } from "postgres";
import transit from "transit-js";
import type { ZodType } from "zod";
import { takeAll, takeOne } from "./parser.ts";
const storage = new AsyncLocalStorage<TransactionSql>();
const transitReader = transit.reader("json");
const transitWriter = transit.writer("json");
/*
|--------------------------------------------------------------------------------
| Database
@@ -24,7 +28,16 @@ export class Client {
*
* @param db - Dependency container token to retrieve.
*/
constructor(readonly config: Options<{}>) {}
constructor(
readonly config: Options<{
transit: {
to: 16384;
from: [16384];
serialize: (value: unknown) => string;
parse: (value: unknown) => any;
};
}>,
) {}
/**
* SQL instance to perform queries against.
@@ -51,7 +64,34 @@ export class Client {
*/
#getResolvedInstance(): Sql {
if (this.#db === undefined) {
this.#db = postgres(this.config);
this.#db = postgres({
...this.config,
connection: {
fallback_output_format: "transit",
},
types: {
transit: {
to: 16384,
from: [16384],
serialize: (value: unknown) => {
return transitWriter.write(value);
},
parse: (value: string) => {
return transitReader.read(value);
},
},
int64: {
from: [20],
parse: (value: string) => {
const res = parseInt(value, 10);
if (Number.isSafeInteger(res) === false) {
throw Error(`Could not convert to integer reliably: ${value}`);
}
return res;
},
} as unknown as postgres.PostgresType,
},
});
}
return this.#db;
}
@@ -106,6 +146,30 @@ export class Client {
many: (strings: TemplateStringsArray, ...values: any[]) => this.sql(strings, ...values).then(takeAll(schema)),
};
}
boolean(value: boolean) {
return this.sql.typed(value, 16);
}
int64(value: number) {
return this.sql.typed(value, 20);
}
int32(value: number) {
return this.sql.typed(value, 23);
}
text(value: string) {
return this.sql.typed(value, 25);
}
float64(value: number) {
return this.sql.typed(value, 701);
}
transit(value: object) {
return this.sql.typed(value, 16384);
}
}
/*