@webqit/webflo 1.0.21 → 1.0.22

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/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "vanila-javascript"
13
13
  ],
14
14
  "homepage": "https://webqit.io/tooling/webflo",
15
- "version": "1.0.21",
15
+ "version": "1.0.22",
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
@@ -49,7 +49,7 @@ export class WebfloServer extends WebfloRuntime {
49
49
  #cx;
50
50
  #servers = new Map;
51
51
  #proxies = new Map;
52
- #sockets = new Map;
52
+ #capabilitiesPromise;
53
53
 
54
54
  // Typically for access by Router
55
55
  get cx() { return this.#cx; }
@@ -102,45 +102,52 @@ export class WebfloServer extends WebfloRuntime {
102
102
  }));
103
103
  }
104
104
  // ---------------
105
- if (this.#cx.server.capabilities?.database) {
106
- if (this.#cx.server.capabilities.database_dialect !== 'postgres') {
107
- throw new Error(`Only postgres supported for now for database dialect`);
105
+ const setupCapabilities = async () => {
106
+ if (this.#cx.server.capabilities?.database) {
107
+ if (this.#cx.server.capabilities.database_dialect !== 'postgres') {
108
+ throw new Error(`Only postgres supported for now for database dialect`);
109
+ }
110
+ if (this.#cx.env.entries[this.#cx.server.capabilities.database_url_variable]) {
111
+ console.log('Database capabilities');
112
+ const { SQLClient } = await import('@linked-db/linked-ql/sql');
113
+ const { default: pg } = await import('pg');
114
+ // Obtain pg client
115
+ const pgClient = new pg.Pool({
116
+ connectionString: this.#cx.env.entries[this.#cx.server.capabilities.database_url_variable],
117
+ database: 'postgres',
118
+ });
119
+ // Connect
120
+ await pgClient.connect();
121
+ this.#sdk.db = new SQLClient(pgClient, { dialect: 'postgres' });
122
+ } else {
123
+ console.log('No database capabilities');
124
+ //const { ODBClient } = await import('@linked-db/linked-ql/odb');
125
+ //this.#sdk.db = new ODBClient({ dialect: 'postgres' });
126
+ }
108
127
  }
109
- if (this.#cx.env.entries[this.#cx.server.capabilities.database_url_variable]) {
110
- const { SQLClient } = await import('@linked-db/linked-ql/sql');
111
- const { default: pg } = await import('pg');
112
- // Obtain pg client
113
- const pgClient = new pg.Pool({
114
- connectionString: this.#cx.env.entries[this.#cx.server.capabilities.database_url_variable],
115
- database: 'postgres',
116
- });
117
- // Connect
118
- await pgClient.connect();
119
- this.#sdk.db = new SQLClient(pgClient, { dialect: 'postgres' });
120
- } else {
121
- //const { ODBClient } = await import('@linked-db/linked-ql/odb');
122
- //this.#sdk.db = new ODBClient({ dialect: 'postgres' });
128
+ if (this.#cx.server.capabilities?.redis && this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable]) {
129
+ const { Redis } = await import('ioredis');
130
+ this.#sdk.redis = !this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable]
131
+ ? new Redis : new Redis(this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable], {
132
+ tls: { rejectUnauthorized: false }, // Required for Upstash
133
+ });
134
+ console.log('Redis capabilities');
123
135
  }
124
- }
125
- if (this.#cx.server.capabilities?.redis && this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable]) {
126
- const { Redis } = await import('ioredis');
127
- this.#sdk.redis = !this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable]
128
- ? new Redis : new Redis(this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable], {
129
- tls: { rejectUnauthorized: false }, // Required for Upstash
130
- });
131
- }
132
- if (this.#cx.server.capabilities?.webpush) {
133
- const { default: webpush } = await import('web-push');
134
- this.#sdk.webpush = webpush;
135
- if (this.#cx.env.entries[this.#cx.server.capabilities.vapid_public_key_variable]
136
- && this.#cx.env.entries[this.#cx.server.capabilities.vapid_private_key_variable]) {
137
- webpush.setVapidDetails(
138
- this.#cx.server.capabilities.vapid_subject,
139
- this.#cx.env.entries[this.#cx.server.capabilities.vapid_public_key_variable],
140
- this.#cx.env.entries[this.#cx.server.capabilities.vapid_private_key_variable]
141
- );
136
+ if (this.#cx.server.capabilities?.webpush) {
137
+ const { default: webpush } = await import('web-push');
138
+ console.log('Webpuah capabilities');
139
+ this.#sdk.webpush = webpush;
140
+ if (this.#cx.env.entries[this.#cx.server.capabilities.vapid_public_key_variable]
141
+ && this.#cx.env.entries[this.#cx.server.capabilities.vapid_private_key_variable]) {
142
+ webpush.setVapidDetails(
143
+ this.#cx.server.capabilities.vapid_subject,
144
+ this.#cx.env.entries[this.#cx.server.capabilities.vapid_public_key_variable],
145
+ this.#cx.env.entries[this.#cx.server.capabilities.vapid_private_key_variable]
146
+ );
147
+ }
142
148
  }
143
- }
149
+ };
150
+ this.#capabilitiesPromise = setupCapabilities();
144
151
  // ---------------
145
152
  this.control();
146
153
  if (this.#cx.logger) {
@@ -221,6 +228,7 @@ export class WebfloServer extends WebfloRuntime {
221
228
 
222
229
  #globalMessagingRegistry = new Map;
223
230
  async handleNodeWsRequest(wss, nodeRequest, socket, head) {
231
+ await this.#capabilitiesPromise;
224
232
  const proto = this.getRequestProto(nodeRequest).replace('http', 'ws');
225
233
  const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest, false);
226
234
  const scope = {};
@@ -281,6 +289,7 @@ export class WebfloServer extends WebfloRuntime {
281
289
  }
282
290
 
283
291
  async handleNodeHttpRequest(nodeRequest, nodeResponse) {
292
+ await this.#capabilitiesPromise;
284
293
  const proto = this.getRequestProto(nodeRequest);
285
294
  const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest);
286
295
  const scope = {};