@platformatic/basic 2.8.0 → 2.8.2-alpha.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/lib/base.js +14 -3
- package/lib/worker/child-manager.js +17 -3
- package/lib/worker/child-process.js +0 -9
- package/package.json +6 -6
- package/schema.json +1 -1
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
|
|
@@ -38,7 +40,10 @@ export class BaseStackable {
|
|
|
38
40
|
this.startHttpTimer = null
|
|
39
41
|
this.endHttpTimer = null
|
|
40
42
|
this.clientWs = null
|
|
41
|
-
this.runtimeConfig = deepmerge(
|
|
43
|
+
this.runtimeConfig = deepmerge(
|
|
44
|
+
options.context?.runtimeConfig ?? {},
|
|
45
|
+
workerData?.config ?? {}
|
|
46
|
+
)
|
|
42
47
|
|
|
43
48
|
// Setup the logger
|
|
44
49
|
const pinoOptions = {
|
|
@@ -64,7 +69,9 @@ export class BaseStackable {
|
|
|
64
69
|
root: pathToFileURL(this.root).toString(),
|
|
65
70
|
setOpenapiSchema: this.setOpenapiSchema.bind(this),
|
|
66
71
|
setGraphqlSchema: this.setGraphqlSchema.bind(this),
|
|
67
|
-
setBasePath: this.setBasePath.bind(this)
|
|
72
|
+
setBasePath: this.setBasePath.bind(this),
|
|
73
|
+
runtimeBasePath: this.runtimeConfig?.basePath ?? null,
|
|
74
|
+
invalidateHttpCache: this.#invalidateHttpCache.bind(this)
|
|
68
75
|
})
|
|
69
76
|
}
|
|
70
77
|
|
|
@@ -331,6 +338,10 @@ export class BaseStackable {
|
|
|
331
338
|
return format === 'json' ? await this.metricsRegistry.getMetricsAsJSON() : await this.metricsRegistry.metrics()
|
|
332
339
|
}
|
|
333
340
|
|
|
341
|
+
async #invalidateHttpCache (opts = {}) {
|
|
342
|
+
await globalThis[kITC].send('invalidateHttpCache', opts)
|
|
343
|
+
}
|
|
344
|
+
|
|
334
345
|
getMeta () {
|
|
335
346
|
return {
|
|
336
347
|
composer: {
|
|
@@ -356,7 +367,7 @@ export class BaseStackable {
|
|
|
356
367
|
/* c8 ignore next 2 */
|
|
357
368
|
port: (this.isEntrypoint ? this.serverConfig?.port || 0 : undefined) ?? true,
|
|
358
369
|
host: (this.isEntrypoint ? this.serverConfig?.hostname : undefined) ?? true,
|
|
359
|
-
|
|
370
|
+
telemetryConfig: this.telemetryConfig
|
|
360
371
|
}
|
|
361
372
|
}
|
|
362
373
|
}
|
|
@@ -3,14 +3,17 @@ 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 { pathToFileURL } from 'node:url'
|
|
6
7
|
import { register } from 'node:module'
|
|
7
8
|
import { platform, tmpdir } from 'node:os'
|
|
8
|
-
import { dirname, resolve } from 'node:path'
|
|
9
|
+
import { dirname, resolve, join } from 'node:path'
|
|
9
10
|
import { workerData } from 'node:worker_threads'
|
|
10
11
|
import { request } from 'undici'
|
|
11
12
|
import { WebSocketServer } from 'ws'
|
|
12
13
|
import { exitCodes } from '../errors.js'
|
|
13
14
|
import { ensureFileUrl } from '../utils.js'
|
|
15
|
+
import { createRequire } from 'node:module'
|
|
16
|
+
|
|
14
17
|
export const isWindows = platform() === 'win32'
|
|
15
18
|
|
|
16
19
|
// In theory we could use the context.id to namespace even more, but due to
|
|
@@ -160,8 +163,19 @@ export class ChildManager extends ITC {
|
|
|
160
163
|
)
|
|
161
164
|
|
|
162
165
|
process.env.PLT_MANAGER_ID = this.#id
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
|
|
167
|
+
const nodeOptions = process.env.NODE_OPTIONS ?? ''
|
|
168
|
+
const childProcessInclude = `--import="${new URL('./child-process.js', import.meta.url)}"`
|
|
169
|
+
|
|
170
|
+
let telemetryInclude = ''
|
|
171
|
+
if (this.#context.telemetryConfig) {
|
|
172
|
+
const require = createRequire(import.meta.url)
|
|
173
|
+
const telemetryPath = require.resolve('@platformatic/telemetry')
|
|
174
|
+
const openTelemetrySetupPath = join(telemetryPath, '..', 'lib', 'node-http-telemetry.js')
|
|
175
|
+
telemetryInclude = `--import="${pathToFileURL(openTelemetrySetupPath)}"`
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
process.env.NODE_OPTIONS = `${telemetryInclude} ${childProcessInclude} ${nodeOptions}`.trim()
|
|
165
179
|
}
|
|
166
180
|
|
|
167
181
|
async eject () {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ITC } from '@platformatic/itc'
|
|
2
2
|
import { collectMetrics } from '@platformatic/metrics'
|
|
3
|
-
import { setupNodeHTTPTelemetry } from '@platformatic/telemetry'
|
|
4
3
|
import { createPinoWritable, ensureLoggableError } from '@platformatic/utils'
|
|
5
4
|
import diagnosticChannel, { tracingChannel } from 'node:diagnostics_channel'
|
|
6
5
|
import { EventEmitter, once } from 'node:events'
|
|
@@ -109,7 +108,6 @@ export class ChildProcess extends ITC {
|
|
|
109
108
|
|
|
110
109
|
this.listen()
|
|
111
110
|
this.#setupLogger()
|
|
112
|
-
this.#setupTelemetry()
|
|
113
111
|
this.#setupHandlers()
|
|
114
112
|
this.#setupServer()
|
|
115
113
|
this.#setupInterceptors()
|
|
@@ -215,13 +213,6 @@ export class ChildProcess extends ITC {
|
|
|
215
213
|
}
|
|
216
214
|
}
|
|
217
215
|
|
|
218
|
-
/* c8 ignore next 5 */
|
|
219
|
-
#setupTelemetry () {
|
|
220
|
-
if (globalThis.platformatic.telemetry) {
|
|
221
|
-
setupNodeHTTPTelemetry(globalThis.platformatic.telemetry, this.#logger)
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
216
|
#setupServer () {
|
|
226
217
|
const subscribers = {
|
|
227
218
|
asyncStart ({ options }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/basic",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"split2": "^4.2.0",
|
|
24
24
|
"undici": "^6.19.5",
|
|
25
25
|
"ws": "^8.18.0",
|
|
26
|
-
"@platformatic/
|
|
27
|
-
"@platformatic/
|
|
28
|
-
"@platformatic/
|
|
29
|
-
"@platformatic/metrics": "2.8.
|
|
30
|
-
"@platformatic/
|
|
26
|
+
"@platformatic/itc": "2.8.2-alpha.1",
|
|
27
|
+
"@platformatic/config": "2.8.2-alpha.1",
|
|
28
|
+
"@platformatic/utils": "2.8.2-alpha.1",
|
|
29
|
+
"@platformatic/metrics": "2.8.2-alpha.1",
|
|
30
|
+
"@platformatic/telemetry": "2.8.2-alpha.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"borp": "^0.18.0",
|
package/schema.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://schemas.platformatic.dev/@platformatic/basic/2.8.
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/basic/2.8.2-alpha.1.json",
|
|
3
3
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
4
|
"title": "Platformatic Stackable",
|
|
5
5
|
"type": "object",
|