@platformatic/runtime 2.7.1-alpha.2 → 2.8.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 +6 -12
- package/eslint.config.js +1 -1
- package/lib/config.js +1 -1
- package/lib/dependencies.js +15 -13
- package/lib/errors.js +3 -1
- package/lib/logger.js +22 -7
- package/lib/management-api.js +1 -10
- package/lib/runtime.js +318 -245
- package/lib/schema.js +41 -27
- package/lib/start.js +15 -9
- package/lib/worker/app.js +16 -2
- package/lib/worker/itc.js +7 -2
- package/lib/worker/main.js +22 -48
- package/lib/worker/round-robin-map.js +61 -0
- package/lib/worker/symbols.js +6 -1
- package/package.json +23 -18
- package/schema.json +70 -30
- package/lib/shared-http-cache.js +0 -45
- package/lib/worker/http-cache.js +0 -83
package/lib/worker/http-cache.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Readable, Writable } = require('node:stream')
|
|
4
|
-
const { kITC } = require('./symbols')
|
|
5
|
-
|
|
6
|
-
class RemoteCacheStore {
|
|
7
|
-
get isFull () {
|
|
8
|
-
// TODO: make an itc call to the shared cache when interceptor supports
|
|
9
|
-
// an async isFull method
|
|
10
|
-
return false
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async createReadStream (request) {
|
|
14
|
-
const itc = globalThis[kITC]
|
|
15
|
-
if (!itc) return
|
|
16
|
-
|
|
17
|
-
const cachedValue = await itc.send('getHttpCacheValue', {
|
|
18
|
-
request: this.#sanitizeRequest(request)
|
|
19
|
-
})
|
|
20
|
-
if (!cachedValue) return
|
|
21
|
-
|
|
22
|
-
const readable = new Readable({
|
|
23
|
-
read () {}
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
Object.defineProperty(readable, 'value', {
|
|
27
|
-
get () { return cachedValue.response }
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
readable.push(cachedValue.payload)
|
|
31
|
-
readable.push(null)
|
|
32
|
-
|
|
33
|
-
return readable
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
createWriteStream (request, response) {
|
|
37
|
-
const itc = globalThis[kITC]
|
|
38
|
-
if (!itc) throw new Error('Cannot write to cache without an ITC instance')
|
|
39
|
-
|
|
40
|
-
let payload = ''
|
|
41
|
-
|
|
42
|
-
request = this.#sanitizeRequest(request)
|
|
43
|
-
response = this.#sanitizeResponse(response)
|
|
44
|
-
|
|
45
|
-
return new Writable({
|
|
46
|
-
write (chunk, encoding, callback) {
|
|
47
|
-
payload += chunk
|
|
48
|
-
callback()
|
|
49
|
-
},
|
|
50
|
-
final (callback) {
|
|
51
|
-
itc.send('setHttpCacheValue', { request, response, payload })
|
|
52
|
-
.then(() => callback())
|
|
53
|
-
.catch((err) => callback(err))
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
deleteByOrigin (origin) {
|
|
59
|
-
const itc = globalThis[kITC]
|
|
60
|
-
if (!itc) throw new Error('Cannot delete from cache without an ITC instance')
|
|
61
|
-
|
|
62
|
-
itc.send('deleteHttpCacheValue', { origin })
|
|
63
|
-
// TODO: return a Promise
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
#sanitizeRequest (request) {
|
|
67
|
-
return {
|
|
68
|
-
origin: request.origin,
|
|
69
|
-
method: request.method,
|
|
70
|
-
path: request.path,
|
|
71
|
-
headers: request.headers
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
#sanitizeResponse (response) {
|
|
76
|
-
return {
|
|
77
|
-
...response,
|
|
78
|
-
rawHeaders: response.rawHeaders.map(header => header.toString())
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
module.exports = RemoteCacheStore
|