@empiricalrun/playwright-utils 0.34.0 → 0.34.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/CHANGELOG.md +12 -0
- package/dist/postgres.d.ts +2 -4
- package/dist/postgres.d.ts.map +1 -1
- package/dist/postgres.js +53 -24
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @empiricalrun/playwright-utils
|
|
2
2
|
|
|
3
|
+
## 0.34.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2c88e44: fix: delete behavior in postgres client
|
|
8
|
+
|
|
9
|
+
## 0.34.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 510c376: fix: get or create behavior in postgres client
|
|
14
|
+
|
|
3
15
|
## 0.34.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/postgres.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
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>;
|
|
12
|
+
private getConnectionUri;
|
|
15
13
|
delete(name: string): Promise<void>;
|
|
16
14
|
query<T = Record<string, unknown>>(connectionUri: string, sql: string): Promise<T[]>;
|
|
17
15
|
execute(connectionUri: string, sql: string): Promise<{
|
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,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoCnC,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,51 +12,83 @@ 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
|
-
|
|
46
|
-
|
|
49
|
+
return { projectId, connectionUri };
|
|
50
|
+
}
|
|
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}`);
|
|
66
|
+
}
|
|
67
|
+
return response.data.uri;
|
|
47
68
|
}
|
|
48
69
|
async delete(name) {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
70
|
+
const listResponse = await this.client.request("/api/neon/proxy", {
|
|
71
|
+
method: "POST",
|
|
72
|
+
body: {
|
|
73
|
+
action: "list",
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (listResponse.error) {
|
|
77
|
+
throw new Error(`Postgres list failed: ${listResponse.error}`);
|
|
78
|
+
}
|
|
79
|
+
const project = listResponse.data.projects.find((p) => p.name === name);
|
|
80
|
+
if (!project) {
|
|
52
81
|
return;
|
|
53
82
|
}
|
|
54
|
-
const
|
|
83
|
+
const deleteResponse = await this.client.request("/api/neon/proxy", {
|
|
55
84
|
method: "POST",
|
|
56
85
|
body: {
|
|
57
86
|
action: "delete",
|
|
58
|
-
projectId:
|
|
87
|
+
projectId: project.id,
|
|
59
88
|
},
|
|
60
89
|
});
|
|
61
|
-
if (
|
|
62
|
-
throw new Error(`Postgres delete failed: ${
|
|
90
|
+
if (deleteResponse.error) {
|
|
91
|
+
throw new Error(`Postgres delete failed: ${deleteResponse.error}`);
|
|
63
92
|
}
|
|
64
93
|
}
|
|
65
94
|
async query(connectionUri, sql) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/playwright-utils",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.2",
|
|
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": {
|