@prisma-next/driver-postgres 0.1.0-dev.25 → 0.1.0-dev.26
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/exports/control.js
CHANGED
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
import { readFileSync } from "fs";
|
|
7
7
|
import { dirname, join } from "path";
|
|
8
8
|
import { fileURLToPath } from "url";
|
|
9
|
+
import { errorRuntime } from "@prisma-next/core-control-plane/errors";
|
|
10
|
+
import { SqlQueryError } from "@prisma-next/sql-errors";
|
|
11
|
+
import { redactDatabaseUrl } from "@prisma-next/utils/redact-db-url";
|
|
9
12
|
import { type } from "arktype";
|
|
10
13
|
import { Client } from "pg";
|
|
11
14
|
var PostgresControlDriver = class {
|
|
@@ -70,8 +73,28 @@ var postgresDriverDescriptor = {
|
|
|
70
73
|
manifest: loadDriverManifest(),
|
|
71
74
|
async create(url) {
|
|
72
75
|
const client = new Client({ connectionString: url });
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
try {
|
|
77
|
+
await client.connect();
|
|
78
|
+
return new PostgresControlDriver(client);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
const normalized = normalizePgError(error);
|
|
81
|
+
const redacted = redactDatabaseUrl(url);
|
|
82
|
+
try {
|
|
83
|
+
await client.end();
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
const codeFromSqlState = SqlQueryError.is(normalized) ? normalized.sqlState : void 0;
|
|
87
|
+
const causeCode = "cause" in normalized && normalized.cause ? normalized.cause.code : void 0;
|
|
88
|
+
const code = codeFromSqlState ?? causeCode;
|
|
89
|
+
throw errorRuntime("Database connection failed", {
|
|
90
|
+
why: normalized.message,
|
|
91
|
+
fix: "Verify the database URL, ensure the database is reachable, and confirm credentials/permissions",
|
|
92
|
+
meta: {
|
|
93
|
+
...typeof code !== "undefined" ? { code } : {},
|
|
94
|
+
...redacted
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
75
98
|
}
|
|
76
99
|
};
|
|
77
100
|
var control_default = postgresDriverDescriptor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/control.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ExtensionPackManifest } from '@prisma-next/contract/pack-manifest-types';\nimport type {\n ControlDriverDescriptor,\n ControlDriverInstance,\n} from '@prisma-next/core-control-plane/types';\nimport { type } from 'arktype';\nimport { Client } from 'pg';\nimport { normalizePgError } from '../normalize-error';\n\n/**\n * Postgres control driver instance for control-plane operations.\n * Implements ControlDriverInstance<'sql', 'postgres'> for database queries.\n */\nexport class PostgresControlDriver implements ControlDriverInstance<'sql', 'postgres'> {\n readonly familyId = 'sql' as const;\n readonly targetId = 'postgres' as const;\n /**\n * @deprecated Use targetId instead\n */\n readonly target = 'postgres' as const;\n\n constructor(private readonly client: Client) {}\n\n async query<Row = Record<string, unknown>>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ readonly rows: Row[] }> {\n try {\n const result = await this.client.query(sql, params as unknown[] | undefined);\n return { rows: result.rows as Row[] };\n } catch (error) {\n throw normalizePgError(error);\n }\n }\n\n async close(): Promise<void> {\n await this.client.end();\n }\n}\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\nconst TypesImportSpecSchema = type({\n package: 'string',\n named: 'string',\n alias: 'string',\n});\n\nconst ExtensionPackManifestSchema = type({\n id: 'string',\n version: 'string',\n 'targets?': type({ '[string]': type({ 'minVersion?': 'string' }) }),\n 'capabilities?': 'Record<string, unknown>',\n 'types?': type({\n 'codecTypes?': type({\n import: TypesImportSpecSchema,\n }),\n 'operationTypes?': type({\n import: TypesImportSpecSchema,\n }),\n }),\n 'operations?': 'unknown[]',\n});\n\n/**\n * Loads the driver manifest from packs/manifest.json.\n */\nfunction loadDriverManifest(): ExtensionPackManifest {\n const manifestPath = join(__dirname, '../../packs/manifest.json');\n const manifestJson = JSON.parse(readFileSync(manifestPath, 'utf-8'));\n\n const result = ExtensionPackManifestSchema(manifestJson);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Invalid driver manifest structure at ${manifestPath}: ${messages}`);\n }\n\n return result as ExtensionPackManifest;\n}\n\n/**\n * Postgres driver descriptor for CLI config.\n */\nconst postgresDriverDescriptor: ControlDriverDescriptor<'sql', 'postgres', PostgresControlDriver> =\n {\n kind: 'driver',\n id: 'postgres',\n familyId: 'sql',\n targetId: 'postgres',\n manifest: loadDriverManifest(),\n async create(url: string): Promise<PostgresControlDriver> {\n const client = new Client({ connectionString: url });\n await client.connect();\n
|
|
1
|
+
{"version":3,"sources":["../../src/exports/control.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ExtensionPackManifest } from '@prisma-next/contract/pack-manifest-types';\nimport { errorRuntime } from '@prisma-next/core-control-plane/errors';\nimport type {\n ControlDriverDescriptor,\n ControlDriverInstance,\n} from '@prisma-next/core-control-plane/types';\nimport { SqlQueryError } from '@prisma-next/sql-errors';\nimport { redactDatabaseUrl } from '@prisma-next/utils/redact-db-url';\nimport { type } from 'arktype';\nimport { Client } from 'pg';\nimport { normalizePgError } from '../normalize-error';\n\n/**\n * Postgres control driver instance for control-plane operations.\n * Implements ControlDriverInstance<'sql', 'postgres'> for database queries.\n */\nexport class PostgresControlDriver implements ControlDriverInstance<'sql', 'postgres'> {\n readonly familyId = 'sql' as const;\n readonly targetId = 'postgres' as const;\n /**\n * @deprecated Use targetId instead\n */\n readonly target = 'postgres' as const;\n\n constructor(private readonly client: Client) {}\n\n async query<Row = Record<string, unknown>>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ readonly rows: Row[] }> {\n try {\n const result = await this.client.query(sql, params as unknown[] | undefined);\n return { rows: result.rows as Row[] };\n } catch (error) {\n throw normalizePgError(error);\n }\n }\n\n async close(): Promise<void> {\n await this.client.end();\n }\n}\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\nconst TypesImportSpecSchema = type({\n package: 'string',\n named: 'string',\n alias: 'string',\n});\n\nconst ExtensionPackManifestSchema = type({\n id: 'string',\n version: 'string',\n 'targets?': type({ '[string]': type({ 'minVersion?': 'string' }) }),\n 'capabilities?': 'Record<string, unknown>',\n 'types?': type({\n 'codecTypes?': type({\n import: TypesImportSpecSchema,\n }),\n 'operationTypes?': type({\n import: TypesImportSpecSchema,\n }),\n }),\n 'operations?': 'unknown[]',\n});\n\n/**\n * Loads the driver manifest from packs/manifest.json.\n */\nfunction loadDriverManifest(): ExtensionPackManifest {\n const manifestPath = join(__dirname, '../../packs/manifest.json');\n const manifestJson = JSON.parse(readFileSync(manifestPath, 'utf-8'));\n\n const result = ExtensionPackManifestSchema(manifestJson);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Invalid driver manifest structure at ${manifestPath}: ${messages}`);\n }\n\n return result as ExtensionPackManifest;\n}\n\n/**\n * Postgres driver descriptor for CLI config.\n */\nconst postgresDriverDescriptor: ControlDriverDescriptor<'sql', 'postgres', PostgresControlDriver> =\n {\n kind: 'driver',\n id: 'postgres',\n familyId: 'sql',\n targetId: 'postgres',\n manifest: loadDriverManifest(),\n async create(url: string): Promise<PostgresControlDriver> {\n const client = new Client({ connectionString: url });\n try {\n await client.connect();\n return new PostgresControlDriver(client);\n } catch (error) {\n const normalized = normalizePgError(error);\n const redacted = redactDatabaseUrl(url);\n try {\n await client.end();\n } catch {\n // ignore\n }\n\n const codeFromSqlState = SqlQueryError.is(normalized) ? normalized.sqlState : undefined;\n const causeCode =\n 'cause' in normalized && normalized.cause\n ? (normalized.cause as { code?: unknown }).code\n : undefined;\n const code = codeFromSqlState ?? causeCode;\n\n throw errorRuntime('Database connection failed', {\n why: normalized.message,\n fix: 'Verify the database URL, ensure the database is reachable, and confirm credentials/permissions',\n meta: {\n ...(typeof code !== 'undefined' ? { code } : {}),\n ...redacted,\n },\n });\n }\n },\n };\n\nexport default postgresDriverDescriptor;\n"],"mappings":";;;;;AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAE9B,SAAS,oBAAoB;AAK7B,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAClC,SAAS,YAAY;AACrB,SAAS,cAAc;AAOhB,IAAM,wBAAN,MAAgF;AAAA,EAQrF,YAA6B,QAAgB;AAAhB;AAAA,EAAiB;AAAA,EAPrC,WAAW;AAAA,EACX,WAAW;AAAA;AAAA;AAAA;AAAA,EAIX,SAAS;AAAA,EAIlB,MAAM,MACJ,KACA,QACmC;AACnC,QAAI;AACF,YAAM,SAAS,MAAM,KAAK,OAAO,MAAM,KAAK,MAA+B;AAC3E,aAAO,EAAE,MAAM,OAAO,KAAc;AAAA,IACtC,SAAS,OAAO;AACd,YAAM,iBAAiB,KAAK;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,MAAM,QAAuB;AAC3B,UAAM,KAAK,OAAO,IAAI;AAAA,EACxB;AACF;AAEA,IAAM,aAAa,cAAc,YAAY,GAAG;AAChD,IAAM,YAAY,QAAQ,UAAU;AAEpC,IAAM,wBAAwB,KAAK;AAAA,EACjC,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AACT,CAAC;AAED,IAAM,8BAA8B,KAAK;AAAA,EACvC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,YAAY,KAAK,EAAE,YAAY,KAAK,EAAE,eAAe,SAAS,CAAC,EAAE,CAAC;AAAA,EAClE,iBAAiB;AAAA,EACjB,UAAU,KAAK;AAAA,IACb,eAAe,KAAK;AAAA,MAClB,QAAQ;AAAA,IACV,CAAC;AAAA,IACD,mBAAmB,KAAK;AAAA,MACtB,QAAQ;AAAA,IACV,CAAC;AAAA,EACH,CAAC;AAAA,EACD,eAAe;AACjB,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|
"name": "@prisma-next/driver-postgres",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.26",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"arktype": "^2.0.0",
|
|
8
8
|
"pg": "^8.11.5",
|
|
9
9
|
"pg-cursor": "^2.10.5",
|
|
10
|
-
"@prisma-next/contract": "0.1.0-dev.
|
|
11
|
-
"@prisma-next/core-control-plane": "0.1.0-dev.
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/
|
|
14
|
-
"@prisma-next/
|
|
15
|
-
"@prisma-next/sql-
|
|
16
|
-
"@prisma-next/sql-
|
|
10
|
+
"@prisma-next/contract": "0.1.0-dev.26",
|
|
11
|
+
"@prisma-next/core-control-plane": "0.1.0-dev.26",
|
|
12
|
+
"@prisma-next/core-execution-plane": "0.1.0-dev.26",
|
|
13
|
+
"@prisma-next/utils": "0.1.0-dev.26",
|
|
14
|
+
"@prisma-next/sql-contract": "0.1.0-dev.26",
|
|
15
|
+
"@prisma-next/sql-errors": "0.1.0-dev.26",
|
|
16
|
+
"@prisma-next/sql-operations": "0.1.0-dev.26",
|
|
17
|
+
"@prisma-next/sql-relational-core": "0.1.0-dev.26"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
20
|
"@vitest/coverage-v8": "^4.0.0",
|