@tenetkit/pg 0.41.2 → 0.41.4
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.
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PgClient } from "@effect/sql-pg";
|
|
2
|
+
export interface PostgresClientOptions {
|
|
3
|
+
readonly url: string;
|
|
4
|
+
readonly maxConnections?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const layerClient: (options: PostgresClientOptions) => import("effect/Layer").Layer<PgClient.PgClient | import("effect/unstable/sql/SqlClient").SqlClient, import("effect/unstable/sql/SqlError").SqlError, never>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Redacted } from "effect";
|
|
2
|
+
import { PgClient } from "@effect/sql-pg";
|
|
3
|
+
import { TypeOverrides, types } from "pg";
|
|
4
|
+
const postgresTypes = new TypeOverrides();
|
|
5
|
+
postgresTypes.setTypeParser(types.builtins.INT8, (value) => {
|
|
6
|
+
const parsed = Number(value);
|
|
7
|
+
if (!Number.isSafeInteger(parsed))
|
|
8
|
+
throw new RangeError(`PostgreSQL BIGINT is outside JavaScript's safe integer range: ${value}`);
|
|
9
|
+
return parsed;
|
|
10
|
+
});
|
|
11
|
+
export const layerClient = (options) => PgClient.layer({
|
|
12
|
+
url: Redacted.make(options.url),
|
|
13
|
+
types: postgresTypes,
|
|
14
|
+
...(options.maxConnections === undefined ? undefined : { maxConnections: options.maxConnections }),
|
|
15
|
+
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Effect
|
|
1
|
+
import { Effect } from "effect";
|
|
2
2
|
import { SqlClient } from "effect/unstable/sql";
|
|
3
3
|
import type { SqlError } from "effect/unstable/sql/SqlError";
|
|
4
|
-
import { PgClient } from "@effect/sql-pg";
|
|
5
4
|
import { SchemaChecksumMismatch, SchemaDirty, SchemaMigrationFailed, SchemaUpgradeRequired, SchemaVersionUnsupported } from "tenetkit/runtime/driver/sql/errors";
|
|
6
5
|
export interface SchemaPlan {
|
|
7
6
|
readonly current: number;
|
|
@@ -20,4 +19,7 @@ export declare const RunSchema: {
|
|
|
20
19
|
readonly apply: typeof apply;
|
|
21
20
|
readonly markDirty: typeof markDirty;
|
|
22
21
|
};
|
|
23
|
-
export declare const layerClient: (
|
|
22
|
+
export declare const layerClient: (options: {
|
|
23
|
+
readonly url: string;
|
|
24
|
+
readonly maxConnections?: number;
|
|
25
|
+
}) => import("effect/Layer").Layer<import("@effect/sql-pg/PgClient").PgClient | SqlClient.SqlClient, SqlError, never>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Cause, DateTime, Effect
|
|
1
|
+
import { Cause, DateTime, Effect } from "effect";
|
|
2
2
|
import { Migrator, SqlClient } from "effect/unstable/sql";
|
|
3
|
-
import { PgClient } from "@effect/sql-pg";
|
|
4
3
|
import { SchemaChecksumMismatch, SchemaDirty, SchemaMigrationFailed, SchemaUpgradeRequired, SchemaVersionUnsupported, } from "tenetkit/runtime/driver/sql/errors";
|
|
5
4
|
import { mapSqlError } from "tenetkit/runtime/driver/sql/effect";
|
|
6
5
|
import { MIGRATION_NAME, MIGRATIONS_TABLE, SCHEMA_META_TABLE, SCHEMA_STATEMENTS, SCHEMA_TABLES, SCHEMA_VERSION, schemaChecksum, } from "./schema.js";
|
|
6
|
+
import { layerClient as postgresClient } from "./client.js";
|
|
7
7
|
const migrationFailure = (source, fallback) => (error) => SchemaMigrationFailed.make({
|
|
8
8
|
source,
|
|
9
9
|
message: error.message || fallback,
|
|
@@ -107,4 +107,4 @@ export const markDirty = (source) => mapSqlError(Effect.gen(function* () {
|
|
|
107
107
|
message: "message" in error ? error.message : "failed to mark schema dirty",
|
|
108
108
|
})));
|
|
109
109
|
export const RunSchema = { plan, check, apply, markDirty };
|
|
110
|
-
export const layerClient = (
|
|
110
|
+
export const layerClient = (options) => postgresClient(options);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Context, Effect, Layer
|
|
2
|
-
import { PgClient } from "@effect/sql-pg";
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
3
2
|
import { makeRuntime } from "tenetkit/runtime/driver/memory/layer";
|
|
4
3
|
import { Runtime } from "tenetkit/runtime/driver/service";
|
|
5
4
|
import { RunStore } from "tenetkit/runtime/driver/run/store";
|
|
@@ -9,6 +8,7 @@ import { ExecutionHost, make as makeExecutionHost } from "tenetkit/runtime/drive
|
|
|
9
8
|
import { layer as activeExecutionsLayer } from "tenetkit/runtime/driver/execution/active-executions";
|
|
10
9
|
import { layer as modelPreviewLayer } from "tenetkit/runtime/driver/execution/model-response/preview";
|
|
11
10
|
import { SchemaMigrationFailed, } from "tenetkit/runtime/driver/sql/errors";
|
|
11
|
+
import { layerClient } from "./client.js";
|
|
12
12
|
export const layerPostgres = (options) => {
|
|
13
13
|
const maxConnections = options.maxConnections ?? 10;
|
|
14
14
|
const client = Layer.unwrap(Effect.gen(function* () {
|
|
@@ -18,7 +18,7 @@ export const layerPostgres = (options) => {
|
|
|
18
18
|
message: "PostgreSQL maxConnections must be a positive integer",
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
return
|
|
21
|
+
return layerClient({ url: options.url, maxConnections });
|
|
22
22
|
}));
|
|
23
23
|
const services = Layer.effectContext(postgresServices(options).pipe(Effect.map(({ store, claims }) => Context.make(RunStore, store).pipe(Context.add(RunClaims, claims))))).pipe(Layer.provide(client));
|
|
24
24
|
const dependencies = Layer.mergeAll(services, activeExecutionsLayer, modelPreviewLayer);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "0.41.
|
|
3
|
+
"version": "0.41.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -39,11 +39,13 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@effect/sql-pg": "4.0.0-rc.111",
|
|
42
|
-
"
|
|
42
|
+
"pg": "8.23.0",
|
|
43
|
+
"tenetkit": "0.41.4"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@effect/vitest": "4.0.0-rc.111",
|
|
46
47
|
"@types/bun": "1.4.0",
|
|
48
|
+
"@types/pg": "8.21.0",
|
|
47
49
|
"effect": "4.0.0-rc.111",
|
|
48
50
|
"typescript": "7.0.2",
|
|
49
51
|
"vitest": "4.1.11"
|