@platformatic/runtime 2.67.0-alpha.0 → 2.67.0-alpha.2
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/config.d.ts +1 -1
- package/lib/runtime.js +2 -4
- package/lib/worker/interceptors.js +106 -39
- package/lib/worker/itc.js +3 -4
- package/package.json +14 -14
- package/schema.json +1 -1
package/config.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* and run json-schema-to-typescript to regenerate this file.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type HttpsSchemasPlatformaticDevPlatformaticRuntime2670Alpha2Json = {
|
|
9
9
|
[k: string]: unknown;
|
|
10
10
|
} & {
|
|
11
11
|
$schema?: string;
|
package/lib/runtime.js
CHANGED
|
@@ -467,14 +467,12 @@ class Runtime extends EventEmitter {
|
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
-
async
|
|
470
|
+
async updateUndiciInterceptors (undiciConfig) {
|
|
471
471
|
this.#configManager.current.undici = undiciConfig
|
|
472
472
|
|
|
473
|
-
await this.#setDispatcher(undiciConfig)
|
|
474
|
-
|
|
475
473
|
const promises = []
|
|
476
474
|
for (const worker of this.#workers.values()) {
|
|
477
|
-
promises.push(sendViaITC(worker, '
|
|
475
|
+
promises.push(sendViaITC(worker, 'updateUndiciInterceptors', undiciConfig))
|
|
478
476
|
}
|
|
479
477
|
|
|
480
478
|
const results = await Promise.allSettled(promises)
|
|
@@ -11,25 +11,12 @@ const { RemoteCacheStore, httpCacheInterceptor } = require('./http-cache')
|
|
|
11
11
|
const { kInterceptors } = require('./symbols')
|
|
12
12
|
|
|
13
13
|
async function setDispatcher (runtimeConfig) {
|
|
14
|
-
const
|
|
14
|
+
const threadDispatcher = createThreadInterceptor(runtimeConfig)
|
|
15
|
+
const threadInterceptor = threadDispatcher.interceptor
|
|
15
16
|
|
|
16
|
-
let
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
const threadInterceptor = threadDispatcher.interceptor
|
|
20
|
-
|
|
21
|
-
let cacheInterceptor = null
|
|
22
|
-
if (runtimeConfig.httpCache) {
|
|
23
|
-
cacheInterceptor = createHttpCacheInterceptor(runtimeConfig)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interceptors = {
|
|
27
|
-
threadDispatcher,
|
|
28
|
-
threadInterceptor,
|
|
29
|
-
cacheInterceptor
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
globalThis[kInterceptors] = interceptors
|
|
17
|
+
let cacheInterceptor = null
|
|
18
|
+
if (runtimeConfig.httpCache) {
|
|
19
|
+
cacheInterceptor = createHttpCacheInterceptor(runtimeConfig)
|
|
33
20
|
}
|
|
34
21
|
|
|
35
22
|
let userInterceptors = []
|
|
@@ -38,20 +25,114 @@ async function setDispatcher (runtimeConfig) {
|
|
|
38
25
|
userInterceptors = await loadInterceptors(_require, runtimeConfig.undici.interceptors)
|
|
39
26
|
}
|
|
40
27
|
|
|
28
|
+
const dispatcherOpts = await getDispatcherOpts(runtimeConfig.undici)
|
|
29
|
+
|
|
41
30
|
setGlobalDispatcher(
|
|
42
31
|
new Agent(dispatcherOpts).compose(
|
|
43
32
|
[
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
threadInterceptor,
|
|
34
|
+
...userInterceptors,
|
|
35
|
+
cacheInterceptor
|
|
47
36
|
].filter(Boolean)
|
|
48
37
|
)
|
|
49
38
|
)
|
|
50
39
|
|
|
51
|
-
return
|
|
40
|
+
return { threadDispatcher }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function updateUndiciInterceptors (undiciConfig) {
|
|
44
|
+
const updatableInterceptors = globalThis[kInterceptors]
|
|
45
|
+
if (!updatableInterceptors) return
|
|
46
|
+
|
|
47
|
+
if (Array.isArray(undiciConfig?.interceptors)) {
|
|
48
|
+
for (const interceptorConfig of undiciConfig.interceptors) {
|
|
49
|
+
const { module, options } = interceptorConfig
|
|
50
|
+
|
|
51
|
+
const interceptorCtx = updatableInterceptors[module]
|
|
52
|
+
if (!interceptorCtx) continue
|
|
53
|
+
|
|
54
|
+
const { createInterceptor, updateInterceptor } = interceptorCtx
|
|
55
|
+
updateInterceptor(createInterceptor(options))
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
for (const key of ['Agent', 'Pool', 'Client']) {
|
|
59
|
+
const interceptorConfigs = undiciConfig.interceptors[key]
|
|
60
|
+
if (!interceptorConfigs) continue
|
|
61
|
+
|
|
62
|
+
for (const interceptorConfig of interceptorConfigs) {
|
|
63
|
+
const { module, options } = interceptorConfig
|
|
64
|
+
|
|
65
|
+
const interceptorCtx = updatableInterceptors[key][module]
|
|
66
|
+
if (!interceptorCtx) continue
|
|
67
|
+
|
|
68
|
+
const { createInterceptor, updateInterceptor } = interceptorCtx
|
|
69
|
+
updateInterceptor(createInterceptor(options))
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function createUpdatableInterceptor (originInterceptor) {
|
|
76
|
+
let originalDispatcher = null
|
|
77
|
+
let originalDispatch = null
|
|
78
|
+
|
|
79
|
+
function updatableInterceptor (dispatch) {
|
|
80
|
+
originalDispatch = dispatch
|
|
81
|
+
originalDispatcher = originInterceptor(dispatch)
|
|
82
|
+
|
|
83
|
+
return function dispatcher (opts, handler) {
|
|
84
|
+
return originalDispatcher(opts, handler)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function updateInterceptor (newInterceptor) {
|
|
89
|
+
originalDispatcher = newInterceptor(originalDispatch)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return { updatableInterceptor, updateInterceptor }
|
|
52
93
|
}
|
|
53
94
|
|
|
54
|
-
async function
|
|
95
|
+
async function loadInterceptors (_require, interceptorsConfigs, key) {
|
|
96
|
+
return Promise.all(
|
|
97
|
+
interceptorsConfigs.map(async (interceptorConfig) => {
|
|
98
|
+
return loadInterceptor(_require, interceptorConfig, key)
|
|
99
|
+
})
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function loadInterceptor (_require, interceptorConfig, key) {
|
|
104
|
+
let updatableInterceptors = globalThis[kInterceptors]
|
|
105
|
+
if (!updatableInterceptors) {
|
|
106
|
+
updatableInterceptors = {}
|
|
107
|
+
globalThis[kInterceptors] = updatableInterceptors
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const { module, options } = interceptorConfig
|
|
111
|
+
|
|
112
|
+
const url = pathToFileURL(_require.resolve(module))
|
|
113
|
+
const createInterceptor = (await import(url)).default
|
|
114
|
+
const interceptor = createInterceptor(options)
|
|
115
|
+
|
|
116
|
+
const {
|
|
117
|
+
updatableInterceptor,
|
|
118
|
+
updateInterceptor
|
|
119
|
+
} = createUpdatableInterceptor(interceptor)
|
|
120
|
+
|
|
121
|
+
const interceptorCtx = { createInterceptor, updateInterceptor }
|
|
122
|
+
|
|
123
|
+
if (key !== undefined) {
|
|
124
|
+
if (!updatableInterceptors[key]) {
|
|
125
|
+
updatableInterceptors[key] = {}
|
|
126
|
+
}
|
|
127
|
+
updatableInterceptors[key][module] = interceptorCtx
|
|
128
|
+
} else {
|
|
129
|
+
updatableInterceptors[module] = interceptorCtx
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return updatableInterceptor
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function getDispatcherOpts (undiciConfig) {
|
|
55
136
|
const dispatcherOpts = { ...undiciConfig }
|
|
56
137
|
|
|
57
138
|
const interceptorsConfigs = undiciConfig?.interceptors
|
|
@@ -68,7 +149,7 @@ async function getDespatcherOpts (undiciConfig) {
|
|
|
68
149
|
const interceptorConfig = undiciConfig.interceptors[key]
|
|
69
150
|
if (!interceptorConfig) continue
|
|
70
151
|
|
|
71
|
-
const interceptors = await loadInterceptors(_require, interceptorConfig)
|
|
152
|
+
const interceptors = await loadInterceptors(_require, interceptorConfig, key)
|
|
72
153
|
if (key === 'Agent') {
|
|
73
154
|
clientInterceptors.push(...interceptors)
|
|
74
155
|
poolInterceptors.push(...interceptors)
|
|
@@ -124,18 +205,4 @@ function createHttpCacheInterceptor (runtimeConfig) {
|
|
|
124
205
|
return cacheInterceptor
|
|
125
206
|
}
|
|
126
207
|
|
|
127
|
-
|
|
128
|
-
const url = pathToFileURL(_require.resolve(module))
|
|
129
|
-
const interceptor = (await import(url)).default
|
|
130
|
-
return interceptor(options)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function loadInterceptors (_require, interceptors) {
|
|
134
|
-
return Promise.all(
|
|
135
|
-
interceptors.map(async ({ module, options }) => {
|
|
136
|
-
return loadInterceptor(_require, module, options)
|
|
137
|
-
})
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
module.exports = { setDispatcher }
|
|
208
|
+
module.exports = { setDispatcher, updateUndiciInterceptors }
|
package/lib/worker/itc.js
CHANGED
|
@@ -7,7 +7,7 @@ const { ITC } = require('@platformatic/itc')
|
|
|
7
7
|
const { Unpromise } = require('@watchable/unpromise')
|
|
8
8
|
|
|
9
9
|
const errors = require('../errors')
|
|
10
|
-
const {
|
|
10
|
+
const { updateUndiciInterceptors } = require('./interceptors')
|
|
11
11
|
const { kITC, kId, kServiceId, kWorkerId } = require('./symbols')
|
|
12
12
|
|
|
13
13
|
async function safeHandleInITC (worker, fn) {
|
|
@@ -110,9 +110,8 @@ function setupITC (app, service, dispatcher) {
|
|
|
110
110
|
return app.stackable.inject(injectParams)
|
|
111
111
|
},
|
|
112
112
|
|
|
113
|
-
async
|
|
114
|
-
|
|
115
|
-
await setDispatcher({ ...config, undici: undiciConfig })
|
|
113
|
+
async updateUndiciInterceptors (undiciConfig) {
|
|
114
|
+
await updateUndiciInterceptors(undiciConfig)
|
|
116
115
|
},
|
|
117
116
|
|
|
118
117
|
getStatus () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/runtime",
|
|
3
|
-
"version": "2.67.0-alpha.
|
|
3
|
+
"version": "2.67.0-alpha.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"typescript": "^5.5.4",
|
|
38
38
|
"undici-oidc-interceptor": "^0.5.0",
|
|
39
39
|
"why-is-node-running": "^2.2.2",
|
|
40
|
-
"@platformatic/
|
|
41
|
-
"@platformatic/
|
|
42
|
-
"@platformatic/
|
|
43
|
-
"@platformatic/
|
|
44
|
-
"@platformatic/
|
|
45
|
-
"@platformatic/sql-mapper": "2.67.0-alpha.
|
|
40
|
+
"@platformatic/db": "2.67.0-alpha.2",
|
|
41
|
+
"@platformatic/node": "2.67.0-alpha.2",
|
|
42
|
+
"@platformatic/service": "2.67.0-alpha.2",
|
|
43
|
+
"@platformatic/sql-graphql": "2.67.0-alpha.2",
|
|
44
|
+
"@platformatic/composer": "2.67.0-alpha.2",
|
|
45
|
+
"@platformatic/sql-mapper": "2.67.0-alpha.2"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@fastify/accepts": "^5.0.0",
|
|
@@ -77,13 +77,13 @@
|
|
|
77
77
|
"undici": "^7.0.0",
|
|
78
78
|
"undici-thread-interceptor": "^0.13.1",
|
|
79
79
|
"ws": "^8.16.0",
|
|
80
|
-
"@platformatic/basic": "2.67.0-alpha.
|
|
81
|
-
"@platformatic/config": "2.67.0-alpha.
|
|
82
|
-
"@platformatic/generators": "2.67.0-alpha.
|
|
83
|
-
"@platformatic/itc": "2.67.0-alpha.
|
|
84
|
-
"@platformatic/telemetry": "2.67.0-alpha.
|
|
85
|
-
"@platformatic/
|
|
86
|
-
"@platformatic/
|
|
80
|
+
"@platformatic/basic": "2.67.0-alpha.2",
|
|
81
|
+
"@platformatic/config": "2.67.0-alpha.2",
|
|
82
|
+
"@platformatic/generators": "2.67.0-alpha.2",
|
|
83
|
+
"@platformatic/itc": "2.67.0-alpha.2",
|
|
84
|
+
"@platformatic/telemetry": "2.67.0-alpha.2",
|
|
85
|
+
"@platformatic/ts-compiler": "2.67.0-alpha.2",
|
|
86
|
+
"@platformatic/utils": "2.67.0-alpha.2"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
89
89
|
"test": "pnpm run lint && borp --concurrency=1 --timeout=300000 && tsd",
|
package/schema.json
CHANGED