@webiny/api-websockets-sql 0.0.0-unstable.b6d7105cee → 0.0.0-unstable.e1999482d0

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,12 @@
1
+ import { SqlSchemaConfig } from "@webiny/api-core-sql";
2
+ import { TableName as TableNameAbstraction } from "../TableName/abstractions.js";
3
+ /** Table names with the prefix of the SQL storage in the container (`SqlSchemaConfig`). */
4
+ declare class SchemaConfigTableNameImpl implements TableNameAbstraction.Interface {
5
+ private readonly tableName;
6
+ constructor(schemaConfig?: SqlSchemaConfig.Interface);
7
+ resolve(name: string): string;
8
+ }
9
+ export declare const SchemaConfigTableName: typeof SchemaConfigTableNameImpl & {
10
+ __abstraction: import("@webiny/di").Abstraction<import("~/TableName/abstractions.js").ITableName>;
11
+ };
12
+ export {};
@@ -0,0 +1,25 @@
1
+ import { SqlSchemaConfig } from "@webiny/api-core-sql";
2
+ import { TableName } from "./abstractions.js";
3
+ import { TableName as external_TableName_js_TableName } from "./TableName.js";
4
+ class SchemaConfigTableNameImpl {
5
+ constructor(schemaConfig){
6
+ this.tableName = new external_TableName_js_TableName(schemaConfig?.tableNamePrefix);
7
+ }
8
+ resolve(name) {
9
+ return this.tableName.resolve(name);
10
+ }
11
+ }
12
+ const SchemaConfigTableName = TableName.createImplementation({
13
+ implementation: SchemaConfigTableNameImpl,
14
+ dependencies: [
15
+ [
16
+ SqlSchemaConfig,
17
+ {
18
+ optional: true
19
+ }
20
+ ]
21
+ ]
22
+ });
23
+ export { SchemaConfigTableName };
24
+
25
+ //# sourceMappingURL=SchemaConfigTableName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableName/SchemaConfigTableName.js","sources":["../../src/TableName/SchemaConfigTableName.ts"],"sourcesContent":["import { SqlSchemaConfig } from \"@webiny/api-core-sql\";\nimport { TableName as TableNameAbstraction } from \"~/TableName/abstractions.js\";\nimport { TableName } from \"~/TableName/TableName.js\";\n\n/** Table names with the prefix of the SQL storage in the container (`SqlSchemaConfig`). */\nclass SchemaConfigTableNameImpl implements TableNameAbstraction.Interface {\n private readonly tableName: TableName;\n\n public constructor(schemaConfig?: SqlSchemaConfig.Interface) {\n this.tableName = new TableName(schemaConfig?.tableNamePrefix);\n }\n\n public resolve(name: string): string {\n return this.tableName.resolve(name);\n }\n}\n\nexport const SchemaConfigTableName = TableNameAbstraction.createImplementation({\n implementation: SchemaConfigTableNameImpl,\n dependencies: [[SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["SchemaConfigTableNameImpl","schemaConfig","TableName","name","SchemaConfigTableName","TableNameAbstraction","SqlSchemaConfig"],"mappings":";;;AAKA,MAAMA;IAGF,YAAmBC,YAAwC,CAAE;QACzD,IAAI,CAAC,SAAS,GAAG,IAAIC,gCAAUD,cAAc;IACjD;IAEO,QAAQE,IAAY,EAAU;QACjC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACA;IAClC;AACJ;AAEO,MAAMC,wBAAwBC,UAAAA,oBAAyC,CAAC;IAC3E,gBAAgBL;IAChB,cAAc;QAAC;YAACM;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACzD"}
@@ -1,10 +1,11 @@
1
- import { KnexClient } from "@webiny/api-core-sql";
2
- import { ConnectionRegistry } from "@webiny/api-websockets/exports/api.js";
1
+ import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from "@webiny/api-core-sql";
2
+ import { ConnectionRegistry } from "@webiny/api-websockets/features/ConnectionRegistry/abstractions.js";
3
3
  import { TableName } from "./TableName/abstractions.js";
4
4
  declare class WebsocketsConnectionRegistryImpl implements ConnectionRegistry.Interface {
5
+ private readonly schemaConfig?;
5
6
  private readonly knex;
6
7
  private readonly tableName;
7
- constructor(knex: KnexClient.Interface, tableName: TableName.Interface);
8
+ constructor(knex: KnexClient.Interface, tableName: TableName.Interface, schemaConfig?: SqlSchemaConfig.Interface | undefined);
8
9
  register(event: ConnectionRegistry.RegisterParams): Promise<ConnectionRegistry.Data>;
9
10
  unregister(event: ConnectionRegistry.UnregisterParams): Promise<void>;
10
11
  listViaConnections(connections: string[]): Promise<ConnectionRegistry.Data[]>;
@@ -13,12 +14,27 @@ declare class WebsocketsConnectionRegistryImpl implements ConnectionRegistry.Int
13
14
  listAll(): Promise<ConnectionRegistry.Data[]>;
14
15
  updateLastSeen(connectionId: string): Promise<void>;
15
16
  listStale(olderThan: Date): Promise<ConnectionRegistry.Data[]>;
17
+ private prepareTable;
18
+ setupSchema(): Promise<void>;
16
19
  private ensureTable;
20
+ private createTable;
17
21
  private migrateTable;
18
22
  private migrateLastSeen;
23
+ private migrateOwner;
19
24
  private toData;
20
25
  }
21
26
  export declare const WebsocketsConnectionRegistry: typeof WebsocketsConnectionRegistryImpl & {
22
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-websockets/features/ConnectionRegistry/abstractions").IWebsocketsConnectionRegistry>;
27
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-websockets/features/ConnectionRegistry/abstractions.js").IWebsocketsConnectionRegistry>;
28
+ };
29
+ /** The `websockets` schema setup step: the connections table, created and migrated. */
30
+ declare class WebsocketsSchemaSetupImpl implements SqlSchemaSetup.Interface {
31
+ private readonly knex;
32
+ private readonly tableName;
33
+ readonly name = "websockets";
34
+ constructor(knex: KnexClient.Interface, tableName: TableName.Interface);
35
+ setup(): Promise<void>;
36
+ }
37
+ export declare const WebsocketsSchemaSetup: typeof WebsocketsSchemaSetupImpl & {
38
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core-sql/schemaSetup/abstractions").ISqlSchemaSetup>;
23
39
  };
24
40
  export {};
@@ -1,18 +1,29 @@
1
1
  import { WebinyError } from "@webiny/error";
2
- import { KnexClient } from "@webiny/api-core-sql";
3
- import { ConnectionRegistry } from "@webiny/api-websockets/exports/api.js";
2
+ import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from "@webiny/api-core-sql";
3
+ import { ConnectionRegistry } from "@webiny/api-websockets/features/ConnectionRegistry/abstractions.js";
4
4
  import { TableName } from "./TableName/abstractions.js";
5
+ import { toIsoString } from "./toIsoString.js";
5
6
  const BASE_TABLE_NAME = "WebsocketsConnections";
7
+ const applyOnce = async (isDone, change)=>{
8
+ const done = await isDone();
9
+ if (done) return;
10
+ try {
11
+ await change();
12
+ } catch (error) {
13
+ const doneByAnotherCall = await isDone();
14
+ if (doneByAnotherCall) return;
15
+ throw error;
16
+ }
17
+ };
6
18
  class WebsocketsConnectionRegistryImpl {
7
- constructor(knex, tableName){
19
+ constructor(knex, tableName, schemaConfig){
20
+ this.schemaConfig = schemaConfig;
8
21
  this.knex = knex;
9
22
  this.tableName = tableName.resolve(BASE_TABLE_NAME);
10
23
  }
11
24
  async register(event) {
12
25
  try {
13
- await this.ensureTable();
14
- await this.migrateTable();
15
- await this.migrateLastSeen();
26
+ await this.prepareTable();
16
27
  const row = {
17
28
  connectionId: event.connectionId,
18
29
  identityId: event.identity.id,
@@ -21,7 +32,8 @@ class WebsocketsConnectionRegistryImpl {
21
32
  tenant: event.tenant,
22
33
  endpoint: event.endpoint,
23
34
  connectedOn: event.connectedOn,
24
- lastSeen: new Date().toISOString()
35
+ lastSeen: new Date().toISOString(),
36
+ owner: event.owner ?? null
25
37
  };
26
38
  await this.knex.client(this.tableName).insert(row);
27
39
  return this.toData(row);
@@ -37,9 +49,7 @@ class WebsocketsConnectionRegistryImpl {
37
49
  }
38
50
  async unregister(event) {
39
51
  try {
40
- await this.ensureTable();
41
- await this.migrateTable();
42
- await this.migrateLastSeen();
52
+ await this.prepareTable();
43
53
  const existing = await this.knex.client(this.tableName).where("connectionId", event.connectionId).first();
44
54
  if (!existing) throw new WebinyError(`Connection "${event.connectionId}" does not exist.`, "CONNECTION_NOT_FOUND", {
45
55
  connectionId: event.connectionId
@@ -57,9 +67,7 @@ class WebsocketsConnectionRegistryImpl {
57
67
  }
58
68
  async listViaConnections(connections) {
59
69
  try {
60
- await this.ensureTable();
61
- await this.migrateTable();
62
- await this.migrateLastSeen();
70
+ await this.prepareTable();
63
71
  const rows = await this.knex.client(this.tableName).whereIn("connectionId", connections);
64
72
  return rows.map((row)=>this.toData(row));
65
73
  } catch (err) {
@@ -74,9 +82,7 @@ class WebsocketsConnectionRegistryImpl {
74
82
  }
75
83
  async listViaIdentity(identity) {
76
84
  try {
77
- await this.ensureTable();
78
- await this.migrateTable();
79
- await this.migrateLastSeen();
85
+ await this.prepareTable();
80
86
  const rows = await this.knex.client(this.tableName).where("identityId", identity);
81
87
  return rows.map((row)=>this.toData(row));
82
88
  } catch (err) {
@@ -91,9 +97,7 @@ class WebsocketsConnectionRegistryImpl {
91
97
  }
92
98
  async listViaTenant(tenant) {
93
99
  try {
94
- await this.ensureTable();
95
- await this.migrateTable();
96
- await this.migrateLastSeen();
100
+ await this.prepareTable();
97
101
  const rows = await this.knex.client(this.tableName).where("tenant", tenant);
98
102
  return rows.map((row)=>this.toData(row));
99
103
  } catch (err) {
@@ -108,9 +112,7 @@ class WebsocketsConnectionRegistryImpl {
108
112
  }
109
113
  async listAll() {
110
114
  try {
111
- await this.ensureTable();
112
- await this.migrateTable();
113
- await this.migrateLastSeen();
115
+ await this.prepareTable();
114
116
  const rows = await this.knex.client(this.tableName).select("*");
115
117
  return rows.map((row)=>this.toData(row));
116
118
  } catch (err) {
@@ -122,9 +124,7 @@ class WebsocketsConnectionRegistryImpl {
122
124
  }
123
125
  async updateLastSeen(connectionId) {
124
126
  try {
125
- await this.ensureTable();
126
- await this.migrateTable();
127
- await this.migrateLastSeen();
127
+ await this.prepareTable();
128
128
  await this.knex.client(this.tableName).where("connectionId", connectionId).update({
129
129
  lastSeen: new Date().toISOString()
130
130
  });
@@ -140,9 +140,7 @@ class WebsocketsConnectionRegistryImpl {
140
140
  }
141
141
  async listStale(olderThan) {
142
142
  try {
143
- await this.ensureTable();
144
- await this.migrateTable();
145
- await this.migrateLastSeen();
143
+ await this.prepareTable();
146
144
  const threshold = olderThan.toISOString();
147
145
  const rows = await this.knex.client(this.tableName).where((qb)=>{
148
146
  qb.where("lastSeen", "<", threshold).orWhereNull("lastSeen");
@@ -158,9 +156,20 @@ class WebsocketsConnectionRegistryImpl {
158
156
  });
159
157
  }
160
158
  }
159
+ async prepareTable() {
160
+ if (this.schemaConfig?.isManaged()) return;
161
+ await this.setupSchema();
162
+ }
163
+ async setupSchema() {
164
+ await this.ensureTable();
165
+ await this.migrateTable();
166
+ await this.migrateLastSeen();
167
+ await this.migrateOwner();
168
+ }
161
169
  async ensureTable() {
162
- const exists = await this.knex.client.schema.hasTable(this.tableName);
163
- if (exists) return;
170
+ await applyOnce(()=>this.knex.client.schema.hasTable(this.tableName), ()=>this.createTable());
171
+ }
172
+ async createTable() {
164
173
  await this.knex.client.schema.createTable(this.tableName, (table)=>{
165
174
  table.text("connectionId").notNullable().primary();
166
175
  table.text("identityId").notNullable();
@@ -170,6 +179,7 @@ class WebsocketsConnectionRegistryImpl {
170
179
  table.text("endpoint").notNullable();
171
180
  table.datetime("connectedOn").notNullable();
172
181
  table.datetime("lastSeen").nullable();
182
+ table.text("owner").nullable();
173
183
  table.index([
174
184
  "identityId"
175
185
  ]);
@@ -194,11 +204,14 @@ class WebsocketsConnectionRegistryImpl {
194
204
  });
195
205
  }
196
206
  async migrateLastSeen() {
197
- const hasLastSeen = await this.knex.client.schema.hasColumn(this.tableName, "lastSeen");
198
- if (hasLastSeen) return;
199
- await this.knex.client.schema.alterTable(this.tableName, (table)=>{
200
- table.datetime("lastSeen").nullable();
201
- });
207
+ await applyOnce(()=>this.knex.client.schema.hasColumn(this.tableName, "lastSeen"), ()=>this.knex.client.schema.alterTable(this.tableName, (table)=>{
208
+ table.datetime("lastSeen").nullable();
209
+ }));
210
+ }
211
+ async migrateOwner() {
212
+ await applyOnce(()=>this.knex.client.schema.hasColumn(this.tableName, "owner"), ()=>this.knex.client.schema.alterTable(this.tableName, (table)=>{
213
+ table.text("owner").nullable();
214
+ }));
202
215
  }
203
216
  toData(row) {
204
217
  return {
@@ -210,17 +223,41 @@ class WebsocketsConnectionRegistryImpl {
210
223
  },
211
224
  tenant: row.tenant,
212
225
  endpoint: row.endpoint,
213
- connectedOn: row.connectedOn
226
+ connectedOn: toIsoString(row.connectedOn),
227
+ owner: row.owner ?? void 0
214
228
  };
215
229
  }
216
230
  }
217
231
  const WebsocketsConnectionRegistry = ConnectionRegistry.createImplementation({
218
232
  implementation: WebsocketsConnectionRegistryImpl,
233
+ dependencies: [
234
+ KnexClient,
235
+ TableName,
236
+ [
237
+ SqlSchemaConfig,
238
+ {
239
+ optional: true
240
+ }
241
+ ]
242
+ ]
243
+ });
244
+ class WebsocketsSchemaSetupImpl {
245
+ constructor(knex, tableName){
246
+ this.knex = knex;
247
+ this.tableName = tableName;
248
+ this.name = "websockets";
249
+ }
250
+ setup() {
251
+ return new WebsocketsConnectionRegistryImpl(this.knex, this.tableName).setupSchema();
252
+ }
253
+ }
254
+ const WebsocketsSchemaSetup = SqlSchemaSetup.createImplementation({
255
+ implementation: WebsocketsSchemaSetupImpl,
219
256
  dependencies: [
220
257
  KnexClient,
221
258
  TableName
222
259
  ]
223
260
  });
224
- export { WebsocketsConnectionRegistry };
261
+ export { WebsocketsConnectionRegistry, WebsocketsSchemaSetup };
225
262
 
226
263
  //# sourceMappingURL=WebsocketsConnectionRegistry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"WebsocketsConnectionRegistry.js","sources":["../src/WebsocketsConnectionRegistry.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { KnexClient } from \"@webiny/api-core-sql\";\nimport { ConnectionRegistry } from \"@webiny/api-websockets/exports/api.js\";\nimport { TableName } from \"~/TableName/abstractions.js\";\n\ninterface ConnectionRow {\n connectionId: string;\n identityId: string;\n identityDisplayName: string;\n identityType: string;\n tenant: string;\n endpoint: string;\n connectedOn: string;\n lastSeen: string | null;\n}\n\nconst BASE_TABLE_NAME = \"WebsocketsConnections\";\n\nclass WebsocketsConnectionRegistryImpl implements ConnectionRegistry.Interface {\n private readonly knex;\n private readonly tableName;\n\n public constructor(knex: KnexClient.Interface, tableName: TableName.Interface) {\n this.knex = knex;\n this.tableName = tableName.resolve(BASE_TABLE_NAME);\n }\n\n public async register(\n event: ConnectionRegistry.RegisterParams\n ): Promise<ConnectionRegistry.Data> {\n try {\n await this.ensureTable();\n await this.migrateTable();\n await this.migrateLastSeen();\n\n const row: ConnectionRow = {\n connectionId: event.connectionId,\n identityId: event.identity.id,\n identityDisplayName: event.identity.displayName,\n identityType: event.identity.type,\n tenant: event.tenant,\n endpoint: event.endpoint,\n connectedOn: event.connectedOn,\n lastSeen: new Date().toISOString()\n };\n\n await this.knex.client<ConnectionRow>(this.tableName).insert(row);\n\n return this.toData(row);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not register websockets connection.\",\n code: \"REGISTER_CONNECTION_ERROR\",\n data: { event }\n });\n }\n }\n\n public async unregister(event: ConnectionRegistry.UnregisterParams): Promise<void> {\n try {\n await this.ensureTable();\n await this.migrateTable();\n await this.migrateLastSeen();\n\n const existing = await this.knex\n .client<ConnectionRow>(this.tableName)\n .where(\"connectionId\", event.connectionId)\n .first();\n\n if (!existing) {\n throw new WebinyError(\n `Connection \"${event.connectionId}\" does not exist.`,\n \"CONNECTION_NOT_FOUND\",\n { connectionId: event.connectionId }\n );\n }\n\n await this.knex\n .client<ConnectionRow>(this.tableName)\n .where(\"connectionId\", event.connectionId)\n .delete();\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not unregister websockets connection.\",\n code: \"UNREGISTER_CONNECTION_ERROR\",\n data: { event }\n });\n }\n }\n\n public async listViaConnections(connections: string[]): Promise<ConnectionRegistry.Data[]> {\n try {\n await this.ensureTable();\n await this.migrateTable();\n await this.migrateLastSeen();\n\n const rows = await this.knex\n .client<ConnectionRow>(this.tableName)\n .whereIn(\"connectionId\", connections);\n\n return rows.map(row => this.toData(row));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list websockets connections by connection IDs.\",\n code: \"LIST_VIA_CONNECTIONS_ERROR\",\n data: { connections }\n });\n }\n }\n\n public async listViaIdentity(identity: string): Promise<ConnectionRegistry.Data[]> {\n try {\n await this.ensureTable();\n await this.migrateTable();\n await this.migrateLastSeen();\n\n const rows = await this.knex\n .client<ConnectionRow>(this.tableName)\n .where(\"identityId\", identity);\n\n return rows.map(row => this.toData(row));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list websockets connections by identity.\",\n code: \"LIST_VIA_IDENTITY_ERROR\",\n data: { identity }\n });\n }\n }\n\n public async listViaTenant(tenant: string): Promise<ConnectionRegistry.Data[]> {\n try {\n await this.ensureTable();\n await this.migrateTable();\n await this.migrateLastSeen();\n\n const rows = await this.knex\n .client<ConnectionRow>(this.tableName)\n .where(\"tenant\", tenant);\n\n return rows.map(row => this.toData(row));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list websockets connections by tenant.\",\n code: \"LIST_VIA_TENANT_ERROR\",\n data: { tenant }\n });\n }\n }\n\n public async listAll(): Promise<ConnectionRegistry.Data[]> {\n try {\n await this.ensureTable();\n await this.migrateTable();\n await this.migrateLastSeen();\n\n const rows = await this.knex.client<ConnectionRow>(this.tableName).select(\"*\");\n\n return rows.map(row => this.toData(row));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list all websockets connections.\",\n code: \"LIST_ALL_CONNECTIONS_ERROR\"\n });\n }\n }\n\n public async updateLastSeen(connectionId: string): Promise<void> {\n try {\n await this.ensureTable();\n await this.migrateTable();\n await this.migrateLastSeen();\n\n await this.knex\n .client<ConnectionRow>(this.tableName)\n .where(\"connectionId\", connectionId)\n .update({ lastSeen: new Date().toISOString() });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update lastSeen for websockets connection.\",\n code: \"UPDATE_LAST_SEEN_ERROR\",\n data: { connectionId }\n });\n }\n }\n\n public async listStale(olderThan: Date): Promise<ConnectionRegistry.Data[]> {\n try {\n await this.ensureTable();\n await this.migrateTable();\n await this.migrateLastSeen();\n\n const threshold = olderThan.toISOString();\n\n const rows = await this.knex.client<ConnectionRow>(this.tableName).where(qb => {\n qb.where(\"lastSeen\", \"<\", threshold).orWhereNull(\"lastSeen\");\n });\n\n return rows.map(row => this.toData(row));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list stale websockets connections.\",\n code: \"LIST_STALE_CONNECTIONS_ERROR\",\n data: { olderThan }\n });\n }\n }\n\n private async ensureTable(): Promise<void> {\n const exists = await this.knex.client.schema.hasTable(this.tableName);\n if (exists) {\n return;\n }\n\n await this.knex.client.schema.createTable(this.tableName, table => {\n table.text(\"connectionId\").notNullable().primary();\n table.text(\"identityId\").notNullable();\n table.text(\"identityDisplayName\").notNullable();\n table.text(\"identityType\").notNullable();\n table.text(\"tenant\").notNullable();\n table.text(\"endpoint\").notNullable();\n table.datetime(\"connectedOn\").notNullable();\n table.datetime(\"lastSeen\").nullable();\n table.index([\"identityId\"]);\n table.index([\"tenant\"]);\n });\n }\n\n private async migrateTable(): Promise<void> {\n const hasEndpoint = await this.knex.client.schema.hasColumn(this.tableName, \"endpoint\");\n if (hasEndpoint) {\n return;\n }\n\n await this.knex.client.schema.alterTable(this.tableName, table => {\n table.text(\"endpoint\").nullable();\n });\n\n await this.knex.client(this.tableName).update({\n endpoint: this.knex.client.raw(\"'https://' || \\\"domainName\\\" || '/' || \\\"stage\\\"\")\n });\n\n await this.knex.client.schema.alterTable(this.tableName, table => {\n table.text(\"endpoint\").notNullable().alter();\n table.dropColumn(\"domainName\");\n table.dropColumn(\"stage\");\n });\n }\n\n private async migrateLastSeen(): Promise<void> {\n const hasLastSeen = await this.knex.client.schema.hasColumn(this.tableName, \"lastSeen\");\n if (hasLastSeen) {\n return;\n }\n\n await this.knex.client.schema.alterTable(this.tableName, table => {\n table.datetime(\"lastSeen\").nullable();\n });\n }\n\n private toData(row: ConnectionRow): ConnectionRegistry.Data {\n return {\n connectionId: row.connectionId,\n identity: {\n id: row.identityId,\n displayName: row.identityDisplayName,\n type: row.identityType\n },\n tenant: row.tenant,\n endpoint: row.endpoint,\n connectedOn: row.connectedOn\n };\n }\n}\n\nexport const WebsocketsConnectionRegistry = ConnectionRegistry.createImplementation({\n implementation: WebsocketsConnectionRegistryImpl,\n dependencies: [KnexClient, TableName]\n});\n"],"names":["BASE_TABLE_NAME","WebsocketsConnectionRegistryImpl","knex","tableName","event","row","Date","err","WebinyError","existing","connections","rows","identity","tenant","connectionId","olderThan","threshold","qb","exists","table","hasEndpoint","hasLastSeen","WebsocketsConnectionRegistry","ConnectionRegistry","KnexClient","TableName"],"mappings":";;;;AAgBA,MAAMA,kBAAkB;AAExB,MAAMC;IAIF,YAAmBC,IAA0B,EAAEC,SAA8B,CAAE;QAC3E,IAAI,CAAC,IAAI,GAAGD;QACZ,IAAI,CAAC,SAAS,GAAGC,UAAU,OAAO,CAACH;IACvC;IAEA,MAAa,SACTI,KAAwC,EACR;QAChC,IAAI;YACA,MAAM,IAAI,CAAC,WAAW;YACtB,MAAM,IAAI,CAAC,YAAY;YACvB,MAAM,IAAI,CAAC,eAAe;YAE1B,MAAMC,MAAqB;gBACvB,cAAcD,MAAM,YAAY;gBAChC,YAAYA,MAAM,QAAQ,CAAC,EAAE;gBAC7B,qBAAqBA,MAAM,QAAQ,CAAC,WAAW;gBAC/C,cAAcA,MAAM,QAAQ,CAAC,IAAI;gBACjC,QAAQA,MAAM,MAAM;gBACpB,UAAUA,MAAM,QAAQ;gBACxB,aAAaA,MAAM,WAAW;gBAC9B,UAAU,IAAIE,OAAO,WAAW;YACpC;YAEA,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,CAACD;YAE7D,OAAO,IAAI,CAAC,MAAM,CAACA;QACvB,EAAE,OAAOE,KAAK;YACV,MAAMC,YAAY,IAAI,CAACD,KAAK;gBACxB,SAAS;gBACT,MAAM;gBACN,MAAM;oBAAEH;gBAAM;YAClB;QACJ;IACJ;IAEA,MAAa,WAAWA,KAA0C,E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CAAC,YAAY,QAAQ;QACvC;IACJ;IAEQ,OAAOd,GAAkB,EAA2B;QACxD,OAAO;YACH,cAAcA,IAAI,YAAY;YAC9B,UAAU;gBACN,IAAIA,IAAI,UAAU;gBAClB,aAAaA,IAAI,mBAAmB;gBACpC,MAAMA,IAAI,YAAY;YAC1B;YACA,QAAQA,IAAI,MAAM;YAClB,UAAUA,IAAI,QAAQ;YACtB,aAAaA,IAAI,WAAW;QAChC;IACJ;AACJ;AAEO,MAAMiB,+BAA+BC,mBAAmB,oBAAoB,CAAC;IAChF,gBAAgBtB;IAChB,cAAc;QAACuB;QAAYC;KAAU;AACzC"}
1
+ {"version":3,"file":"WebsocketsConnectionRegistry.js","sources":["../src/WebsocketsConnectionRegistry.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from \"@webiny/api-core-sql\";\nimport { ConnectionRegistry } from \"@webiny/api-websockets/features/ConnectionRegistry/abstractions.js\";\nimport { TableName } from \"~/TableName/abstractions.js\";\nimport { toIsoString } from \"~/toIsoString.js\";\n\ninterface ConnectionRow {\n connectionId: string;\n identityId: string;\n identityDisplayName: string;\n identityType: string;\n tenant: string;\n endpoint: string;\n connectedOn: string;\n lastSeen: string | null;\n owner: string | null;\n}\n\nconst BASE_TABLE_NAME = \"WebsocketsConnections\";\n\n/*\n * Runs `change` unless `isDone` already holds. After an upgrade every browser reconnects at once, so\n * several calls, in one process or in several, can find the same table or column missing; all but\n * the first then fail because it exists by now. A failure after which `isDone` holds was one of\n * those and is not an error.\n */\nconst applyOnce = async (\n isDone: () => Promise<boolean>,\n change: () => Promise<unknown>\n): Promise<void> => {\n const done = await isDone();\n if (done) {\n return;\n }\n try {\n await change();\n } catch (error) {\n const doneByAnotherCall = await isDone();\n if (doneByAnotherCall) {\n return;\n }\n throw error;\n }\n};\n\nclass WebsocketsConnectionRegistryImpl implements ConnectionRegistry.Interface {\n private readonly knex;\n private readonly tableName;\n\n public constructor(\n knex: KnexClient.Interface,\n tableName: TableName.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {\n this.knex = knex;\n this.tableName = tableName.resolve(BASE_TABLE_NAME);\n }\n\n public async register(\n event: ConnectionRegistry.RegisterParams\n ): Promise<ConnectionRegistry.Data> {\n try {\n await this.prepareTable();\n\n const row: ConnectionRow = {\n connectionId: event.connectionId,\n identityId: event.identity.id,\n identityDisplayName: event.identity.displayName,\n identityType: event.identity.type,\n tenant: event.tenant,\n endpoint: event.endpoint,\n connectedOn: event.connectedOn,\n lastSeen: new Date().toISOString(),\n owner: event.owner ?? null\n };\n\n await this.knex.client<ConnectionRow>(this.tableName).insert(row);\n\n return this.toData(row);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not register websockets connection.\",\n code: \"REGISTER_CONNECTION_ERROR\",\n data: { event }\n });\n }\n }\n\n public async unregister(event: ConnectionRegistry.UnregisterParams): Promise<void> {\n try {\n await this.prepareTable();\n\n const existing = await this.knex\n .client<ConnectionRow>(this.tableName)\n .where(\"connectionId\", event.connectionId)\n .first();\n\n if (!existing) {\n throw new WebinyError(\n `Connection \"${event.connectionId}\" does not exist.`,\n \"CONNECTION_NOT_FOUND\",\n { connectionId: event.connectionId }\n );\n }\n\n await this.knex\n .client<ConnectionRow>(this.tableName)\n .where(\"connectionId\", event.connectionId)\n .delete();\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not unregister websockets connection.\",\n code: \"UNREGISTER_CONNECTION_ERROR\",\n data: { event }\n });\n }\n }\n\n public async listViaConnections(connections: string[]): Promise<ConnectionRegistry.Data[]> {\n try {\n await this.prepareTable();\n\n const rows = await this.knex\n .client<ConnectionRow>(this.tableName)\n .whereIn(\"connectionId\", connections);\n\n return rows.map(row => this.toData(row));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list websockets connections by connection IDs.\",\n code: \"LIST_VIA_CONNECTIONS_ERROR\",\n data: { connections }\n });\n }\n }\n\n public async listViaIdentity(identity: string): Promise<ConnectionRegistry.Data[]> {\n try {\n await this.prepareTable();\n\n const rows = await this.knex\n .client<ConnectionRow>(this.tableName)\n .where(\"identityId\", identity);\n\n return rows.map(row => this.toData(row));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list websockets connections by identity.\",\n code: \"LIST_VIA_IDENTITY_ERROR\",\n data: { identity }\n });\n }\n }\n\n public async listViaTenant(tenant: string): Promise<ConnectionRegistry.Data[]> {\n try {\n await this.prepareTable();\n\n const rows = await this.knex\n .client<ConnectionRow>(this.tableName)\n .where(\"tenant\", tenant);\n\n return rows.map(row => this.toData(row));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list websockets connections by tenant.\",\n code: \"LIST_VIA_TENANT_ERROR\",\n data: { tenant }\n });\n }\n }\n\n public async listAll(): Promise<ConnectionRegistry.Data[]> {\n try {\n await this.prepareTable();\n\n const rows = await this.knex.client<ConnectionRow>(this.tableName).select(\"*\");\n\n return rows.map(row => this.toData(row));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list all websockets connections.\",\n code: \"LIST_ALL_CONNECTIONS_ERROR\"\n });\n }\n }\n\n public async updateLastSeen(connectionId: string): Promise<void> {\n try {\n await this.prepareTable();\n\n await this.knex\n .client<ConnectionRow>(this.tableName)\n .where(\"connectionId\", connectionId)\n .update({ lastSeen: new Date().toISOString() });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update lastSeen for websockets connection.\",\n code: \"UPDATE_LAST_SEEN_ERROR\",\n data: { connectionId }\n });\n }\n }\n\n public async listStale(olderThan: Date): Promise<ConnectionRegistry.Data[]> {\n try {\n await this.prepareTable();\n\n const threshold = olderThan.toISOString();\n\n const rows = await this.knex.client<ConnectionRow>(this.tableName).where(qb => {\n qb.where(\"lastSeen\", \"<\", threshold).orWhereNull(\"lastSeen\");\n });\n\n return rows.map(row => this.toData(row));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list stale websockets connections.\",\n code: \"LIST_STALE_CONNECTIONS_ERROR\",\n data: { olderThan }\n });\n }\n }\n\n /* At runtime: nothing when the schema is managed (`SqlSchemaConfig`). */\n private async prepareTable(): Promise<void> {\n if (this.schemaConfig?.isManaged()) {\n return;\n }\n await this.setupSchema();\n }\n\n /* Creates and migrates the table, whatever the mode (deploy-time schema setup). */\n public async setupSchema(): Promise<void> {\n await this.ensureTable();\n await this.migrateTable();\n await this.migrateLastSeen();\n await this.migrateOwner();\n }\n\n /*\n * `schema` is read fresh in each call below: it is a new builder on every read, and one builder\n * reused would run the statements queued on it before.\n */\n private async ensureTable(): Promise<void> {\n await applyOnce(\n () => this.knex.client.schema.hasTable(this.tableName),\n () => this.createTable()\n );\n }\n\n private async createTable(): Promise<void> {\n await this.knex.client.schema.createTable(this.tableName, table => {\n table.text(\"connectionId\").notNullable().primary();\n table.text(\"identityId\").notNullable();\n table.text(\"identityDisplayName\").notNullable();\n table.text(\"identityType\").notNullable();\n table.text(\"tenant\").notNullable();\n table.text(\"endpoint\").notNullable();\n table.datetime(\"connectedOn\").notNullable();\n table.datetime(\"lastSeen\").nullable();\n table.text(\"owner\").nullable();\n table.index([\"identityId\"]);\n table.index([\"tenant\"]);\n });\n }\n\n private async migrateTable(): Promise<void> {\n const hasEndpoint = await this.knex.client.schema.hasColumn(this.tableName, \"endpoint\");\n if (hasEndpoint) {\n return;\n }\n\n await this.knex.client.schema.alterTable(this.tableName, table => {\n table.text(\"endpoint\").nullable();\n });\n\n await this.knex.client(this.tableName).update({\n endpoint: this.knex.client.raw(\"'https://' || \\\"domainName\\\" || '/' || \\\"stage\\\"\")\n });\n\n await this.knex.client.schema.alterTable(this.tableName, table => {\n table.text(\"endpoint\").notNullable().alter();\n table.dropColumn(\"domainName\");\n table.dropColumn(\"stage\");\n });\n }\n\n private async migrateLastSeen(): Promise<void> {\n await applyOnce(\n () => this.knex.client.schema.hasColumn(this.tableName, \"lastSeen\"),\n () => {\n return this.knex.client.schema.alterTable(this.tableName, table => {\n table.datetime(\"lastSeen\").nullable();\n });\n }\n );\n }\n\n private async migrateOwner(): Promise<void> {\n await applyOnce(\n () => this.knex.client.schema.hasColumn(this.tableName, \"owner\"),\n () => {\n return this.knex.client.schema.alterTable(this.tableName, table => {\n table.text(\"owner\").nullable();\n });\n }\n );\n }\n\n private toData(row: ConnectionRow): ConnectionRegistry.Data {\n return {\n connectionId: row.connectionId,\n identity: {\n id: row.identityId,\n displayName: row.identityDisplayName,\n type: row.identityType\n },\n tenant: row.tenant,\n endpoint: row.endpoint,\n connectedOn: toIsoString(row.connectedOn),\n owner: row.owner ?? undefined\n };\n }\n}\n\nexport const WebsocketsConnectionRegistry = ConnectionRegistry.createImplementation({\n implementation: WebsocketsConnectionRegistryImpl,\n dependencies: [KnexClient, TableName, [SqlSchemaConfig, { optional: true }]]\n});\n\n/** The `websockets` schema setup step: the connections table, created and migrated. */\nclass WebsocketsSchemaSetupImpl implements SqlSchemaSetup.Interface {\n public readonly name = \"websockets\";\n\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly tableName: TableName.Interface\n ) {}\n\n public setup(): Promise<void> {\n return new WebsocketsConnectionRegistryImpl(this.knex, this.tableName).setupSchema();\n }\n}\n\nexport const WebsocketsSchemaSetup = SqlSchemaSetup.createImplementation({\n implementation: WebsocketsSchemaSetupImpl,\n dependencies: [KnexClient, TableName]\n});\n"],"names":["BASE_TABLE_NAME","applyOnce","isDone","change","done","error","doneByAnotherCall","WebsocketsConnectionRegistryImpl","knex","tableName","schemaConfig","event","row","Date","err","WebinyError","existing","connections","rows","identity","tenant","connectionId","olderThan","threshold","qb","table","hasEndpoint","toIsoString","undefined","WebsocketsConnectionRegistry","ConnectionRegistry","KnexClient","TableName","SqlSchemaConfig","WebsocketsSchemaSetupImpl","WebsocketsSchemaSetup","SqlSchemaSetup"],"mappings":";;;;;AAkBA,MAAMA,kBAAkB;AAQxB,MAAMC,YAAY,OACdC,QACAC;IAEA,MAAMC,OAAO,MAAMF;IACnB,IAAIE,MACA;IAEJ,I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I,YAAY;YAC9B,UAAU;gBACN,IAAIA,IAAI,UAAU;gBAClB,aAAaA,IAAI,mBAAmB;gBACpC,MAAMA,IAAI,YAAY;YAC1B;YACA,QAAQA,IAAI,MAAM;YAClB,UAAUA,IAAI,QAAQ;YACtB,aAAae,YAAYf,IAAI,WAAW;YACxC,OAAOA,IAAI,KAAK,IAAIgB;QACxB;IACJ;AACJ;AAEO,MAAMC,+BAA+BC,mBAAmB,oBAAoB,CAAC;IAChF,gBAAgBvB;IAChB,cAAc;QAACwB;QAAYC;QAAW;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAChF;AAGA,MAAMC;IAGF,YACqB1B,IAA0B,EAC1BC,SAA8B,CACjD;aAFmBD,IAAI,GAAJA;aACAC,SAAS,GAATA;aAJL,IAAI,GAAG;IAKpB;IAEI,QAAuB;QAC1B,OAAO,IAAIF,iCAAiC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,WAAW;IACtF;AACJ;AAEO,MAAM4B,wBAAwBC,eAAe,oBAAoB,CAAC;IACrE,gBAAgBF;IAChB,cAAc;QAACH;QAAYC;KAAU;AACzC"}
@@ -0,0 +1,10 @@
1
+ import { type Container } from "@webiny/feature/api";
2
+ /**
3
+ * The websocket connection registry on SQL, and its `websockets` schema setup step. Registered per
4
+ * request, it runs on the connection (`KnexClient`) and the table prefix (`SqlSchemaConfig`) the SQL
5
+ * storage keeps in the root.
6
+ */
7
+ export declare const WebsocketsSqlFeature: {
8
+ name: string;
9
+ register(container: Container): void;
10
+ };
@@ -0,0 +1,14 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { SchemaConfigTableName } from "./TableName/SchemaConfigTableName.js";
3
+ import { WebsocketsConnectionRegistry, WebsocketsSchemaSetup } from "./WebsocketsConnectionRegistry.js";
4
+ const WebsocketsSqlFeature = createFeature({
5
+ name: "WebsocketsSql",
6
+ register (container) {
7
+ container.register(SchemaConfigTableName);
8
+ container.register(WebsocketsConnectionRegistry);
9
+ container.register(WebsocketsSchemaSetup);
10
+ }
11
+ });
12
+ export { WebsocketsSqlFeature };
13
+
14
+ //# sourceMappingURL=WebsocketsSqlFeature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebsocketsSqlFeature.js","sources":["../src/WebsocketsSqlFeature.ts"],"sourcesContent":["import { type Container, createFeature } from \"@webiny/feature/api\";\nimport { SchemaConfigTableName } from \"~/TableName/SchemaConfigTableName.js\";\nimport {\n WebsocketsConnectionRegistry,\n WebsocketsSchemaSetup\n} from \"./WebsocketsConnectionRegistry.js\";\n\n/**\n * The websocket connection registry on SQL, and its `websockets` schema setup step. Registered per\n * request, it runs on the connection (`KnexClient`) and the table prefix (`SqlSchemaConfig`) the SQL\n * storage keeps in the root.\n */\nexport const WebsocketsSqlFeature = createFeature({\n name: \"WebsocketsSql\",\n register(container: Container) {\n container.register(SchemaConfigTableName);\n container.register(WebsocketsConnectionRegistry);\n container.register(WebsocketsSchemaSetup);\n }\n});\n"],"names":["WebsocketsSqlFeature","createFeature","container","SchemaConfigTableName","WebsocketsConnectionRegistry","WebsocketsSchemaSetup"],"mappings":";;;AAYO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAoB;QACzBA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;IACvB;AACJ"}
package/index.d.ts CHANGED
@@ -1,7 +1,2 @@
1
- import type { Knex } from "knex";
2
- interface RegisterWebsocketsSqlStorageOperationsParams {
3
- knex: Knex;
4
- tableNamePrefix?: string;
5
- }
6
- export declare const registerWebsocketsSqlStorageOperations: (params: RegisterWebsocketsSqlStorageOperationsParams) => import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>;
7
- export {};
1
+ export { WebsocketsConnectionRegistry } from "./WebsocketsConnectionRegistry.js";
2
+ export { WebsocketsSqlFeature } from "./WebsocketsSqlFeature.js";
package/index.js CHANGED
@@ -1,11 +1,2 @@
1
- import { createRegisterExtensionPlugin } from "@webiny/handler";
2
- import { WebsocketsConnectionRegistry } from "./WebsocketsConnectionRegistry.js";
3
- import { TableName } from "./TableName/abstractions.js";
4
- import { TableName as TableName_js_TableName } from "./TableName/TableName.js";
5
- const registerWebsocketsSqlStorageOperations = (params)=>createRegisterExtensionPlugin((context)=>{
6
- context.container.registerInstance(TableName, new TableName_js_TableName(params.tableNamePrefix));
7
- context.container.register(WebsocketsConnectionRegistry);
8
- });
9
- export { registerWebsocketsSqlStorageOperations };
10
-
11
- //# sourceMappingURL=index.js.map
1
+ export { WebsocketsConnectionRegistry } from "./WebsocketsConnectionRegistry.js";
2
+ export { WebsocketsSqlFeature } from "./WebsocketsSqlFeature.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-websockets-sql",
3
- "version": "0.0.0-unstable.b6d7105cee",
3
+ "version": "0.0.0-unstable.e1999482d0",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "@webiny/api-websockets",
@@ -20,21 +20,20 @@
20
20
  "./*": "./*"
21
21
  },
22
22
  "dependencies": {
23
- "@webiny/api-core-sql": "0.0.0-unstable.b6d7105cee",
24
- "@webiny/api-websockets": "0.0.0-unstable.b6d7105cee",
25
- "@webiny/error": "0.0.0-unstable.b6d7105cee",
26
- "@webiny/feature": "0.0.0-unstable.b6d7105cee",
27
- "@webiny/handler": "0.0.0-unstable.b6d7105cee",
23
+ "@webiny/api-core-sql": "0.0.0-unstable.e1999482d0",
24
+ "@webiny/api-websockets": "0.0.0-unstable.e1999482d0",
25
+ "@webiny/error": "0.0.0-unstable.e1999482d0",
26
+ "@webiny/feature": "0.0.0-unstable.e1999482d0",
28
27
  "knex": "3.3.0"
29
28
  },
30
29
  "devDependencies": {
31
- "@webiny/build-tools": "0.0.0-unstable.b6d7105cee",
32
- "@webiny/di": "1.0.2",
33
- "@webiny/project-utils": "0.0.0-unstable.b6d7105cee",
34
- "better-sqlite3": "13.0.1",
35
- "rimraf": "6.1.3",
30
+ "@webiny/api-core": "0.0.0-unstable.e1999482d0",
31
+ "@webiny/build-tools": "0.0.0-unstable.e1999482d0",
32
+ "@webiny/di": "2.0.0",
33
+ "better-sqlite3": "13.2.0",
34
+ "rimraf": "6.1.4",
36
35
  "typescript": "7.0.2",
37
- "vitest": "4.1.10"
36
+ "vitest": "5.1.1"
38
37
  },
39
38
  "publishConfig": {
40
39
  "access": "public"
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Normalize a timestamp read out of a `datetime` column to a UTC ISO string.
3
+ *
4
+ * We always write ISO strings, but the column's read shape is the driver's decision: node-postgres
5
+ * and mysql2 parse it into a `Date`, better-sqlite3 hands back the text it was given, and some
6
+ * configurations return "2026-08-04 17:02:06" with no `T` and no zone. That wall-clock is UTC,
7
+ * because that is how it was written, so the space form is read back as UTC.
8
+ *
9
+ * Taking `unknown` keeps the variance out of the row type, so the rest of the registry can treat a
10
+ * timestamp as the `string` it is declared to be. Anything unparseable throws rather than being
11
+ * stringified: these values are compared against a cutoff to decide which connections are still
12
+ * live, and a quietly malformed one drops a user's connections with no error to show for it.
13
+ */
14
+ export declare const toIsoString: (value: unknown) => string;
package/toIsoString.js ADDED
@@ -0,0 +1,15 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ const toIsoString = (value)=>{
3
+ if (value instanceof Date) return value.toISOString();
4
+ if ("string" == typeof value) {
5
+ const normalized = value.includes(" ") && !value.includes("T") ? `${value.replace(" ", "T")}Z` : value;
6
+ const parsed = new Date(normalized);
7
+ if (!Number.isNaN(parsed.getTime())) return parsed.toISOString();
8
+ }
9
+ throw new WebinyError("Could not read a websockets connection timestamp.", "INVALID_CONNECTION_TIMESTAMP", {
10
+ value
11
+ });
12
+ };
13
+ export { toIsoString };
14
+
15
+ //# sourceMappingURL=toIsoString.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toIsoString.js","sources":["../src/toIsoString.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\n\n/**\n * Normalize a timestamp read out of a `datetime` column to a UTC ISO string.\n *\n * We always write ISO strings, but the column's read shape is the driver's decision: node-postgres\n * and mysql2 parse it into a `Date`, better-sqlite3 hands back the text it was given, and some\n * configurations return \"2026-08-04 17:02:06\" with no `T` and no zone. That wall-clock is UTC,\n * because that is how it was written, so the space form is read back as UTC.\n *\n * Taking `unknown` keeps the variance out of the row type, so the rest of the registry can treat a\n * timestamp as the `string` it is declared to be. Anything unparseable throws rather than being\n * stringified: these values are compared against a cutoff to decide which connections are still\n * live, and a quietly malformed one drops a user's connections with no error to show for it.\n */\nexport const toIsoString = (value: unknown): string => {\n if (value instanceof Date) {\n return value.toISOString();\n }\n\n if (typeof value === \"string\") {\n const normalized =\n value.includes(\" \") && !value.includes(\"T\") ? `${value.replace(\" \", \"T\")}Z` : value;\n\n const parsed = new Date(normalized);\n if (!Number.isNaN(parsed.getTime())) {\n return parsed.toISOString();\n }\n }\n\n throw new WebinyError(\n \"Could not read a websockets connection timestamp.\",\n \"INVALID_CONNECTION_TIMESTAMP\",\n { value }\n );\n};\n"],"names":["toIsoString","value","Date","normalized","parsed","Number","WebinyError"],"mappings":";AAeO,MAAMA,cAAc,CAACC;IACxB,IAAIA,iBAAiBC,MACjB,OAAOD,MAAM,WAAW;IAG5B,IAAI,AAAiB,YAAjB,OAAOA,OAAoB;QAC3B,MAAME,aACFF,MAAM,QAAQ,CAAC,QAAQ,CAACA,MAAM,QAAQ,CAAC,OAAO,GAAGA,MAAM,OAAO,CAAC,KAAK,KAAK,CAAC,CAAC,GAAGA;QAElF,MAAMG,SAAS,IAAIF,KAAKC;QACxB,IAAI,CAACE,OAAO,KAAK,CAACD,OAAO,OAAO,KAC5B,OAAOA,OAAO,WAAW;IAEjC;IAEA,MAAM,IAAIE,YACN,qDACA,gCACA;QAAEL;IAAM;AAEhB"}
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { WebsocketsConnectionRegistry } from \"./WebsocketsConnectionRegistry.js\";\nimport { TableName as TableNameAbstraction } from \"~/TableName/abstractions.js\";\nimport { TableName } from \"~/TableName/TableName.js\";\n\ninterface RegisterWebsocketsSqlStorageOperationsParams {\n knex: Knex;\n tableNamePrefix?: string;\n}\n\nexport const registerWebsocketsSqlStorageOperations = (\n params: RegisterWebsocketsSqlStorageOperationsParams\n) => {\n return createRegisterExtensionPlugin(context => {\n context.container.registerInstance(\n TableNameAbstraction,\n new TableName(params.tableNamePrefix)\n );\n context.container.register(WebsocketsConnectionRegistry);\n });\n};\n"],"names":["registerWebsocketsSqlStorageOperations","params","createRegisterExtensionPlugin","context","TableNameAbstraction","TableName","WebsocketsConnectionRegistry"],"mappings":";;;;AAWO,MAAMA,yCAAyC,CAClDC,SAEOC,8BAA8BC,CAAAA;QACjCA,QAAQ,SAAS,CAAC,gBAAgB,CAC9BC,WACA,IAAIC,uBAAUJ,OAAO,eAAe;QAExCE,QAAQ,SAAS,CAAC,QAAQ,CAACG;IAC/B"}