@platformatic/basic 2.19.0-alpha.3 → 2.19.0-alpha.4

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/lib/base.js CHANGED
@@ -13,9 +13,11 @@ import { NonZeroExitCode } from './errors.js'
13
13
  import { cleanBasePath } from './utils.js'
14
14
  import { ChildManager } from './worker/child-manager.js'
15
15
 
16
+ const kITC = Symbol.for('plt.runtime.itc')
17
+
16
18
  export class BaseStackable {
17
19
  childManager
18
- subprocess
20
+ #subprocess
19
21
  #subprocessStarted
20
22
 
21
23
  constructor (type, version, options, root, configManager) {
@@ -32,6 +34,8 @@ export class BaseStackable {
32
34
  this.serverConfig = deepmerge(options.context.serverConfig ?? {}, configManager.current.server ?? {})
33
35
  this.openapiSchema = null
34
36
  this.graphqlSchema = null
37
+ this.connectionString = null
38
+ this.basePath = null
35
39
  this.isEntrypoint = options.context.isEntrypoint
36
40
  this.isProduction = options.context.isProduction
37
41
  this.metricsRegistry = null
@@ -64,8 +68,10 @@ export class BaseStackable {
64
68
  root: pathToFileURL(this.root).toString(),
65
69
  setOpenapiSchema: this.setOpenapiSchema.bind(this),
66
70
  setGraphqlSchema: this.setGraphqlSchema.bind(this),
71
+ setConnectionString: this.setConnectionString.bind(this),
67
72
  setBasePath: this.setBasePath.bind(this),
68
- runtimeBasePath: this.runtimeConfig?.basePath ?? null
73
+ runtimeBasePath: this.runtimeConfig?.basePath ?? null,
74
+ invalidateHttpCache: this.#invalidateHttpCache.bind(this)
69
75
  })
70
76
  }
71
77
 
@@ -126,6 +132,10 @@ export class BaseStackable {
126
132
  this.graphqlSchema = schema
127
133
  }
128
134
 
135
+ setConnectionString (connectionString) {
136
+ this.connectionString = connectionString
137
+ }
138
+
129
139
  setBasePath (basePath) {
130
140
  this.basePath = basePath
131
141
  }
@@ -212,6 +222,22 @@ export class BaseStackable {
212
222
  this.subprocessConfig = config
213
223
  })
214
224
 
225
+ this.childManager.on('connectionString', connectionString => {
226
+ this.connectionString = connectionString
227
+ })
228
+
229
+ this.childManager.on('openapiSchema', schema => {
230
+ this.openapiSchema = schema
231
+ })
232
+
233
+ this.childManager.on('graphqlSchema', schema => {
234
+ this.graphqlSchema = schema
235
+ })
236
+
237
+ this.childManager.on('basePath', path => {
238
+ this.basePath = path
239
+ })
240
+
215
241
  try {
216
242
  await this.childManager.inject()
217
243
 
@@ -336,6 +362,10 @@ export class BaseStackable {
336
362
  return format === 'json' ? await this.metricsRegistry.getMetricsAsJSON() : await this.metricsRegistry.metrics()
337
363
  }
338
364
 
365
+ async #invalidateHttpCache (opts = {}) {
366
+ await globalThis[kITC].send('invalidateHttpCache', opts)
367
+ }
368
+
339
369
  getMeta () {
340
370
  return {
341
371
  composer: {
@@ -349,7 +379,6 @@ export class BaseStackable {
349
379
 
350
380
  return {
351
381
  id: this.id,
352
- config: this.configManager.current,
353
382
  serviceId: this.serviceId,
354
383
  workerId: this.workerId,
355
384
  // Always use URL to avoid serialization problem in Windows
@@ -3,15 +3,16 @@ import { createDirectory, ensureLoggableError } from '@platformatic/utils'
3
3
  import { once } from 'node:events'
4
4
  import { rm, writeFile } from 'node:fs/promises'
5
5
  import { createServer } from 'node:http'
6
- import { createRequire, register } from 'node:module'
7
- import { platform, tmpdir } from 'node:os'
8
- import { dirname, join, resolve } from 'node:path'
9
6
  import { pathToFileURL } from 'node:url'
7
+ import { register } from 'node:module'
8
+ import { platform, tmpdir } from 'node:os'
9
+ import { dirname, resolve, join } from 'node:path'
10
10
  import { workerData } from 'node:worker_threads'
11
11
  import { request } from 'undici'
12
12
  import { WebSocketServer } from 'ws'
13
13
  import { exitCodes } from '../errors.js'
14
14
  import { ensureFileUrl } from '../utils.js'
15
+ import { createRequire } from 'node:module'
15
16
 
16
17
  export const isWindows = platform() === 'win32'
17
18
 
@@ -170,7 +171,7 @@ export class ChildManager extends ITC {
170
171
  if (this.#context.telemetryConfig) {
171
172
  const require = createRequire(import.meta.url)
172
173
  const telemetryPath = require.resolve('@platformatic/telemetry')
173
- const openTelemetrySetupPath = join(telemetryPath, '..', 'lib', 'node-http-telemetry.js')
174
+ const openTelemetrySetupPath = join(telemetryPath, '..', 'lib', 'node-telemetry.js')
174
175
  telemetryInclude = `--import="${pathToFileURL(openTelemetrySetupPath)}"`
175
176
  }
176
177
 
@@ -11,7 +11,7 @@ import { basename, resolve } from 'node:path'
11
11
  import { fileURLToPath } from 'node:url'
12
12
  import { isMainThread } from 'node:worker_threads'
13
13
  import pino from 'pino'
14
- import { getGlobalDispatcher, setGlobalDispatcher } from 'undici'
14
+ import { Agent, setGlobalDispatcher } from 'undici'
15
15
  import { WebSocket } from 'ws'
16
16
  import { exitCodes } from '../errors.js'
17
17
  import { importFile } from '../utils.js'
@@ -118,6 +118,13 @@ export class ChildProcess extends ITC {
118
118
  process.exit(0)
119
119
  }
120
120
  })
121
+
122
+ this.registerGlobals({
123
+ setOpenapiSchema: this.setOpenapiSchema.bind(this),
124
+ setGraphqlSchema: this.setGraphqlSchema.bind(this),
125
+ setConnectionString: this.setConnectionString.bind(this),
126
+ setBasePath: this.setBasePath.bind(this),
127
+ })
121
128
  }
122
129
 
123
130
  _setupListener (listener) {
@@ -262,7 +269,8 @@ export class ChildProcess extends ITC {
262
269
  }
263
270
 
264
271
  #setupInterceptors () {
265
- setGlobalDispatcher(getGlobalDispatcher().compose(createInterceptor(this)))
272
+ const globalDispatcher = new Agent().compose(createInterceptor(this))
273
+ setGlobalDispatcher(globalDispatcher)
266
274
  }
267
275
 
268
276
  #setupHandlers () {
@@ -281,6 +289,26 @@ export class ChildProcess extends ITC {
281
289
  process.on('uncaughtException', handleUnhandled.bind(this, 'uncaught exception'))
282
290
  process.on('unhandledRejection', handleUnhandled.bind(this, 'unhandled rejection'))
283
291
  }
292
+
293
+ registerGlobals (globals) {
294
+ globalThis.platformatic = Object.assign(globalThis.platformatic ?? {}, globals)
295
+ }
296
+
297
+ setOpenapiSchema (schema) {
298
+ this.notify('openapiSchema', schema)
299
+ }
300
+
301
+ setGraphqlSchema (schema) {
302
+ this.notify('graphqlSchema', schema)
303
+ }
304
+
305
+ setConnectionString (connectionString) {
306
+ this.notify('connectionString', connectionString)
307
+ }
308
+
309
+ setBasePath (basePath) {
310
+ this.notify('basePath', basePath)
311
+ }
284
312
  }
285
313
 
286
314
  function stripBasePath (basePath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/basic",
3
- "version": "2.19.0-alpha.3",
3
+ "version": "2.19.0-alpha.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -21,13 +21,13 @@
21
21
  "pino-abstract-transport": "^2.0.0",
22
22
  "semver": "^7.6.3",
23
23
  "split2": "^4.2.0",
24
- "undici": "^6.19.5",
24
+ "undici": "7.0.0",
25
25
  "ws": "^8.18.0",
26
- "@platformatic/config": "2.19.0-alpha.3",
27
- "@platformatic/itc": "2.19.0-alpha.3",
28
- "@platformatic/utils": "2.19.0-alpha.3",
29
- "@platformatic/telemetry": "2.19.0-alpha.3",
30
- "@platformatic/metrics": "2.19.0-alpha.3"
26
+ "@platformatic/itc": "2.19.0-alpha.4",
27
+ "@platformatic/metrics": "2.19.0-alpha.4",
28
+ "@platformatic/utils": "2.19.0-alpha.4",
29
+ "@platformatic/telemetry": "2.19.0-alpha.4",
30
+ "@platformatic/config": "2.19.0-alpha.4"
31
31
  },
32
32
  "devDependencies": {
33
33
  "borp": "^0.19.0",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.19.0-alpha.3.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.19.0-alpha.4.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Stackable",
5
5
  "type": "object",