@platformatic/runtime 3.0.0-alpha.5 → 3.0.0-alpha.8
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 +11 -7
- package/eslint.config.js +2 -4
- package/index.d.ts +11 -11
- package/index.js +35 -46
- package/lib/config.js +159 -102
- package/lib/errors.js +65 -99
- package/lib/generator.js +160 -164
- package/lib/logger.js +6 -8
- package/lib/management-api.js +91 -63
- package/lib/prom-server.js +10 -14
- package/lib/runtime.js +815 -747
- package/lib/scheduler.js +13 -15
- package/lib/schema.js +11 -8
- package/lib/shared-http-cache.js +5 -9
- package/lib/upgrade.js +5 -9
- package/lib/utils.js +6 -14
- package/lib/version.js +7 -0
- package/lib/versions/v1.36.0.js +2 -4
- package/lib/versions/v1.5.0.js +2 -4
- package/lib/versions/v2.0.0.js +3 -5
- package/lib/versions/v3.0.0.js +16 -0
- package/lib/worker/{app.js → controller.js} +68 -63
- package/lib/worker/http-cache.js +11 -14
- package/lib/worker/interceptors.js +14 -18
- package/lib/worker/itc.js +85 -79
- package/lib/worker/main.js +49 -55
- package/lib/worker/messaging.js +23 -27
- package/lib/worker/round-robin-map.js +23 -19
- package/lib/worker/shared-context.js +2 -6
- package/lib/worker/symbols.js +12 -29
- package/package.json +24 -23
- package/schema.json +281 -20
- package/lib/dependencies.js +0 -65
package/lib/dependencies.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const Topo = require('@hapi/topo')
|
|
4
|
-
const { closest } = require('fastest-levenshtein')
|
|
5
|
-
|
|
6
|
-
const errors = require('./errors')
|
|
7
|
-
const { RoundRobinMap } = require('./worker/round-robin-map')
|
|
8
|
-
|
|
9
|
-
function missingDependencyErrorMessage (clientName, service, services) {
|
|
10
|
-
const allNames = services.map(s => s.id).filter(id => id !== service.id).sort()
|
|
11
|
-
const closestName = closest(clientName, allNames)
|
|
12
|
-
let errorMsg = `service '${service.id}' has unknown dependency: '${clientName}'.`
|
|
13
|
-
if (closestName) {
|
|
14
|
-
errorMsg += ` Did you mean '${closestName}'?`
|
|
15
|
-
}
|
|
16
|
-
if (allNames.length) {
|
|
17
|
-
errorMsg += ` Known services are: ${allNames.join(', ')}.`
|
|
18
|
-
}
|
|
19
|
-
return errorMsg
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function checkDependencies (services) {
|
|
23
|
-
const allServices = new Set(services.map(s => s.id))
|
|
24
|
-
|
|
25
|
-
for (const service of services) {
|
|
26
|
-
for (const dependency of service.dependencies) {
|
|
27
|
-
if (dependency.local && !allServices.has(dependency.id)) {
|
|
28
|
-
throw new errors.MissingDependencyError(missingDependencyErrorMessage(dependency.id, service, services))
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function topologicalSort (workers, config) {
|
|
35
|
-
const topo = new Topo.Sorter()
|
|
36
|
-
|
|
37
|
-
for (const service of config.services) {
|
|
38
|
-
const localDependencyIds = Array.from(service.dependencies)
|
|
39
|
-
.filter(dep => dep.local)
|
|
40
|
-
.map(dep => dep.id)
|
|
41
|
-
|
|
42
|
-
topo.add(service, {
|
|
43
|
-
group: service.id,
|
|
44
|
-
after: localDependencyIds,
|
|
45
|
-
manual: true
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
config.services = topo.sort()
|
|
50
|
-
|
|
51
|
-
return new RoundRobinMap(
|
|
52
|
-
Array.from(workers.entries()).sort((a, b) => {
|
|
53
|
-
if (a[0] === b[0]) {
|
|
54
|
-
return 0
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const aIndex = config.services.findIndex(s => s.id === a[0])
|
|
58
|
-
const bIndex = config.services.findIndex(s => s.id === b[0])
|
|
59
|
-
return aIndex - bIndex
|
|
60
|
-
}),
|
|
61
|
-
workers.configuration
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports = { checkDependencies, topologicalSort }
|