@platformatic/basic 2.19.0-alpha.1 → 2.19.0-alpha.10

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,6 +13,8 @@ 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
20
  subprocess
@@ -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
  }
@@ -197,7 +207,7 @@ export class BaseStackable {
197
207
  }
198
208
  }
199
209
 
200
- async startWithCommand (command, loader) {
210
+ async startWithCommand (command, loader, scripts) {
201
211
  const config = this.configManager.current
202
212
  const basePath = config.application?.basePath ? cleanBasePath(config.application?.basePath) : ''
203
213
 
@@ -205,13 +215,30 @@ export class BaseStackable {
205
215
  this.childManager = new ChildManager({
206
216
  logger: this.logger,
207
217
  loader,
208
- context
218
+ context,
219
+ scripts
209
220
  })
210
221
 
211
222
  this.childManager.on('config', config => {
212
223
  this.subprocessConfig = config
213
224
  })
214
225
 
226
+ this.childManager.on('connectionString', connectionString => {
227
+ this.connectionString = connectionString
228
+ })
229
+
230
+ this.childManager.on('openapiSchema', schema => {
231
+ this.openapiSchema = schema
232
+ })
233
+
234
+ this.childManager.on('graphqlSchema', schema => {
235
+ this.graphqlSchema = schema
236
+ })
237
+
238
+ this.childManager.on('basePath', path => {
239
+ this.basePath = path
240
+ })
241
+
215
242
  try {
216
243
  await this.childManager.inject()
217
244
 
@@ -336,6 +363,10 @@ export class BaseStackable {
336
363
  return format === 'json' ? await this.metricsRegistry.getMetricsAsJSON() : await this.metricsRegistry.metrics()
337
364
  }
338
365
 
366
+ async #invalidateHttpCache (opts = {}) {
367
+ await globalThis[kITC].send('invalidateHttpCache', opts)
368
+ }
369
+
339
370
  getMeta () {
340
371
  return {
341
372
  composer: {
@@ -170,7 +170,7 @@ export class ChildManager extends ITC {
170
170
  if (this.#context.telemetryConfig) {
171
171
  const require = createRequire(import.meta.url)
172
172
  const telemetryPath = require.resolve('@platformatic/telemetry')
173
- const openTelemetrySetupPath = join(telemetryPath, '..', 'lib', 'node-http-telemetry.js')
173
+ const openTelemetrySetupPath = join(telemetryPath, '..', 'lib', 'node-telemetry.js')
174
174
  telemetryInclude = `--import="${pathToFileURL(openTelemetrySetupPath)}"`
175
175
  }
176
176
 
@@ -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.1",
3
+ "version": "2.19.0-alpha.10",
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.1",
27
- "@platformatic/utils": "2.19.0-alpha.1",
28
- "@platformatic/telemetry": "2.19.0-alpha.1",
29
- "@platformatic/metrics": "2.19.0-alpha.1",
30
- "@platformatic/itc": "2.19.0-alpha.1"
26
+ "@platformatic/config": "2.19.0-alpha.10",
27
+ "@platformatic/itc": "2.19.0-alpha.10",
28
+ "@platformatic/utils": "2.19.0-alpha.10",
29
+ "@platformatic/metrics": "2.19.0-alpha.10",
30
+ "@platformatic/telemetry": "2.19.0-alpha.10"
31
31
  },
32
32
  "devDependencies": {
33
33
  "borp": "^0.19.0",
@@ -36,7 +36,7 @@
36
36
  "fastify": "^5.0.0",
37
37
  "json-schema-to-typescript": "^15.0.0",
38
38
  "neostandard": "^0.11.1",
39
- "next": "^14.2.5",
39
+ "next": "^15.0.0",
40
40
  "react": "^18.3.1",
41
41
  "react-dom": "^18.3.1",
42
42
  "typescript": "^5.5.4",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.19.0-alpha.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.19.0-alpha.10.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Stackable",
5
5
  "type": "object",