@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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @empiricalrun/playwright-utils
2
2
 
3
+ ## 0.34.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 510c376: fix: get or create behavior in postgres client
8
+
3
9
  ## 0.34.0
4
10
 
5
11
  ### Minor Changes
@@ -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
- delete(name: string): Promise<void>;
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;
@@ -1 +1 @@
1
- {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AA6BA,KAAK,gBAAgB,GAAG;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAIF,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,EAAE,CAAW;;IAYf,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC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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 kvKey = `postgres:${name}`;
22
- const existing = await this.kv.get(kvKey);
23
- if (existing) {
24
- return existing;
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 response = await this.client.request("/api/neon/proxy", {
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: options?.name ?? name,
36
+ name,
32
37
  pg_version: options?.pgVersion,
33
38
  },
34
39
  },
35
40
  });
36
- if (response.error) {
37
- throw new Error(`Postgres create failed: ${response.error}`);
41
+ if (createResponse.error) {
42
+ throw new Error(`Postgres create failed: ${createResponse.error}`);
38
43
  }
39
- const projectId = response.data.project.id;
40
- const connectionUri = response.data.connection_uris?.[0]?.connection_uri;
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
- const db = { projectId, connectionUri };
45
- await this.kv.set(kvKey, db, options?.ttl ?? DEFAULT_TTL);
46
- return db;
49
+ return { projectId, connectionUri };
47
50
  }
48
- async delete(name) {
49
- const kvKey = `postgres:${name}`;
50
- const existing = await this.kv.get(kvKey);
51
- if (!existing) {
52
- return;
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: existing.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.0",
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": {