@empiricalrun/playwright-utils 0.34.0 → 0.34.1
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/CHANGELOG.md +6 -0
- package/dist/postgres.d.ts +3 -5
- package/dist/postgres.d.ts.map +1 -1
- package/dist/postgres.js +39 -23
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/postgres.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
type PostgresDatabase = {
|
|
1
|
+
export type PostgresDatabase = {
|
|
2
2
|
projectId: string;
|
|
3
3
|
connectionUri: string;
|
|
4
4
|
};
|
|
5
5
|
type GetOptions = {
|
|
6
|
-
name?: string;
|
|
7
6
|
pgVersion?: number;
|
|
8
|
-
ttl?: number;
|
|
9
7
|
};
|
|
10
8
|
export declare class PostgresClient {
|
|
11
9
|
private client;
|
|
12
|
-
private kv;
|
|
13
10
|
constructor();
|
|
14
11
|
get(name: string, options?: GetOptions): Promise<PostgresDatabase>;
|
|
15
|
-
|
|
12
|
+
private getConnectionUri;
|
|
13
|
+
delete(projectId: string): Promise<void>;
|
|
16
14
|
query<T = Record<string, unknown>>(connectionUri: string, sql: string): Promise<T[]>;
|
|
17
15
|
execute(connectionUri: string, sql: string): Promise<{
|
|
18
16
|
statement: string;
|
package/dist/postgres.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAgDA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAqB;;IAW7B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAqD1D,gBAAgB;IAwBxB,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBxC,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,CAAC,EAAE,CAAC;IAWT,OAAO,CACX,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAsBrD,OAAO,CAAC,eAAe;CAsBxB"}
|
package/dist/postgres.js
CHANGED
|
@@ -3,11 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PostgresClient = void 0;
|
|
4
4
|
const dashboard_1 = require("@empiricalrun/test-gen/dashboard");
|
|
5
5
|
const pg_1 = require("pg");
|
|
6
|
-
const kv_1 = require("./kv");
|
|
7
|
-
const DEFAULT_TTL = 3600;
|
|
8
6
|
class PostgresClient {
|
|
9
7
|
client;
|
|
10
|
-
kv;
|
|
11
8
|
constructor() {
|
|
12
9
|
if (!process.env.EMPIRICALRUN_API_KEY) {
|
|
13
10
|
throw new Error("EMPIRICALRUN_API_KEY environment variable is required");
|
|
@@ -15,47 +12,66 @@ class PostgresClient {
|
|
|
15
12
|
this.client = new dashboard_1.DashboardAPIClient({
|
|
16
13
|
authType: "project-api-key",
|
|
17
14
|
});
|
|
18
|
-
this.kv = new kv_1.KVClient();
|
|
19
15
|
}
|
|
20
16
|
async get(name, options) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const listResponse = await this.client.request("/api/neon/proxy", {
|
|
18
|
+
method: "POST",
|
|
19
|
+
body: {
|
|
20
|
+
action: "list",
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
if (listResponse.error) {
|
|
24
|
+
throw new Error(`Postgres list failed: ${listResponse.error}`);
|
|
25
25
|
}
|
|
26
|
-
const
|
|
26
|
+
const existingProject = listResponse.data.projects.find((p) => p.name === name);
|
|
27
|
+
if (existingProject) {
|
|
28
|
+
const connectionUri = await this.getConnectionUri(existingProject.id);
|
|
29
|
+
return { projectId: existingProject.id, connectionUri };
|
|
30
|
+
}
|
|
31
|
+
const createResponse = await this.client.request("/api/neon/proxy", {
|
|
27
32
|
method: "POST",
|
|
28
33
|
body: {
|
|
29
34
|
action: "create",
|
|
30
35
|
payload: {
|
|
31
|
-
name
|
|
36
|
+
name,
|
|
32
37
|
pg_version: options?.pgVersion,
|
|
33
38
|
},
|
|
34
39
|
},
|
|
35
40
|
});
|
|
36
|
-
if (
|
|
37
|
-
throw new Error(`Postgres create failed: ${
|
|
41
|
+
if (createResponse.error) {
|
|
42
|
+
throw new Error(`Postgres create failed: ${createResponse.error}`);
|
|
38
43
|
}
|
|
39
|
-
const projectId =
|
|
40
|
-
const connectionUri =
|
|
44
|
+
const projectId = createResponse.data.project.id;
|
|
45
|
+
const connectionUri = createResponse.data.connection_uris?.[0]?.connection_uri;
|
|
41
46
|
if (!connectionUri) {
|
|
42
47
|
throw new Error("No connection URI returned from Neon API");
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
await this.kv.set(kvKey, db, options?.ttl ?? DEFAULT_TTL);
|
|
46
|
-
return db;
|
|
49
|
+
return { projectId, connectionUri };
|
|
47
50
|
}
|
|
48
|
-
async
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
async getConnectionUri(projectId) {
|
|
52
|
+
const response = await this.client.request("/api/neon/proxy", {
|
|
53
|
+
method: "POST",
|
|
54
|
+
body: {
|
|
55
|
+
action: "getConnectionUri",
|
|
56
|
+
projectId,
|
|
57
|
+
payload: {
|
|
58
|
+
databaseName: "neondb",
|
|
59
|
+
roleName: "neondb_owner",
|
|
60
|
+
pooled: false,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
if (response.error) {
|
|
65
|
+
throw new Error(`Postgres getConnectionUri failed: ${response.error}`);
|
|
53
66
|
}
|
|
67
|
+
return response.data.uri;
|
|
68
|
+
}
|
|
69
|
+
async delete(projectId) {
|
|
54
70
|
const response = await this.client.request("/api/neon/proxy", {
|
|
55
71
|
method: "POST",
|
|
56
72
|
body: {
|
|
57
73
|
action: "delete",
|
|
58
|
-
projectId
|
|
74
|
+
projectId,
|
|
59
75
|
},
|
|
60
76
|
});
|
|
61
77
|
if (response.error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/playwright-utils",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"console-log-level": "^1.4.1",
|
|
45
45
|
"puppeteer-extra-plugin-recaptcha": "^3.6.8",
|
|
46
46
|
"rimraf": "^6.0.1",
|
|
47
|
-
"@empiricalrun/r2-uploader": "^0.5.0",
|
|
48
47
|
"@empiricalrun/llm": "^0.25.1",
|
|
48
|
+
"@empiricalrun/r2-uploader": "^0.5.0",
|
|
49
49
|
"@empiricalrun/test-gen": "^0.78.3"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|