@platformatic/runtime 3.4.1 → 3.5.0

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.
Files changed (49) hide show
  1. package/README.md +1 -1
  2. package/config.d.ts +224 -77
  3. package/eslint.config.js +3 -5
  4. package/index.d.ts +73 -24
  5. package/index.js +173 -29
  6. package/lib/config.js +279 -197
  7. package/lib/errors.js +126 -34
  8. package/lib/generator.js +640 -0
  9. package/lib/logger.js +43 -41
  10. package/lib/management-api.js +109 -118
  11. package/lib/prom-server.js +202 -16
  12. package/lib/runtime.js +1963 -585
  13. package/lib/scheduler.js +119 -0
  14. package/lib/schema.js +22 -234
  15. package/lib/shared-http-cache.js +43 -0
  16. package/lib/upgrade.js +6 -8
  17. package/lib/utils.js +6 -61
  18. package/lib/version.js +7 -0
  19. package/lib/versions/v1.36.0.js +2 -4
  20. package/lib/versions/v1.5.0.js +2 -4
  21. package/lib/versions/v2.0.0.js +3 -5
  22. package/lib/versions/v3.0.0.js +16 -0
  23. package/lib/worker/controller.js +302 -0
  24. package/lib/worker/http-cache.js +171 -0
  25. package/lib/worker/interceptors.js +190 -10
  26. package/lib/worker/itc.js +146 -59
  27. package/lib/worker/main.js +220 -81
  28. package/lib/worker/messaging.js +182 -0
  29. package/lib/worker/round-robin-map.js +62 -0
  30. package/lib/worker/shared-context.js +22 -0
  31. package/lib/worker/symbols.js +14 -5
  32. package/package.json +47 -38
  33. package/schema.json +1383 -55
  34. package/help/compile.txt +0 -8
  35. package/help/help.txt +0 -5
  36. package/help/start.txt +0 -21
  37. package/index.test-d.ts +0 -41
  38. package/lib/build-server.js +0 -69
  39. package/lib/compile.js +0 -98
  40. package/lib/dependencies.js +0 -59
  41. package/lib/generator/README.md +0 -32
  42. package/lib/generator/errors.js +0 -10
  43. package/lib/generator/runtime-generator.d.ts +0 -37
  44. package/lib/generator/runtime-generator.js +0 -498
  45. package/lib/start.js +0 -190
  46. package/lib/worker/app.js +0 -278
  47. package/lib/worker/default-stackable.js +0 -33
  48. package/lib/worker/metrics.js +0 -122
  49. package/runtime.mjs +0 -54
package/lib/errors.js CHANGED
@@ -1,37 +1,129 @@
1
- 'use strict'
1
+ import createError from '@fastify/error'
2
2
 
3
- const createError = require('@fastify/error')
3
+ export const ERROR_PREFIX = 'PLT_RUNTIME'
4
4
 
5
- const ERROR_PREFIX = 'PLT_RUNTIME'
5
+ export const AddressInUseError = createError(
6
+ `${ERROR_PREFIX}_EADDR_IN_USE`,
7
+ 'The current port is in use by another application'
8
+ )
9
+ export const RuntimeExitedError = createError(
10
+ `${ERROR_PREFIX}_RUNTIME_EXIT`,
11
+ 'The runtime exited before the operation completed'
12
+ )
13
+ export const RuntimeAbortedError = createError(`${ERROR_PREFIX}_RUNTIME_ABORT`, 'The runtime aborted the operation')
14
+ // The following two use the same code as we only need to differentiate the label
15
+ export const ApplicationExitedError = createError(
16
+ `${ERROR_PREFIX}_APPLICATION_EXIT`,
17
+ 'The application "%s" exited prematurely with error code %d'
18
+ )
19
+ export const WorkerExitedError = createError(
20
+ `${ERROR_PREFIX}_APPLICATION_WORKER_EXIT`,
21
+ 'The worker %s of the application "%s" exited prematurely with error code %d'
22
+ )
23
+ export const UnknownRuntimeAPICommandError = createError(
24
+ `${ERROR_PREFIX}_UNKNOWN_RUNTIME_API_COMMAND`,
25
+ 'Unknown Runtime API command "%s"'
26
+ )
27
+ export const ApplicationNotFoundError = createError(
28
+ `${ERROR_PREFIX}_APPLICATION_NOT_FOUND`,
29
+ 'Application %s not found. Available applications are: %s'
30
+ )
31
+ export const WorkerNotFoundError = createError(
32
+ `${ERROR_PREFIX}_WORKER_NOT_FOUND`,
33
+ 'Worker %s of application %s not found. Available applications are: %s'
34
+ )
35
+ export const ApplicationNotStartedError = createError(
36
+ `${ERROR_PREFIX}_APPLICATION_NOT_STARTED`,
37
+ "Application with id '%s' is not started"
38
+ )
39
+ export const ApplicationStartTimeoutError = createError(
40
+ `${ERROR_PREFIX}_APPLICATION_START_TIMEOUT`,
41
+ "Application with id '%s' failed to start in %dms."
42
+ )
43
+ export const FailedToRetrieveOpenAPISchemaError = createError(
44
+ `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_OPENAPI_SCHEMA`,
45
+ 'Failed to retrieve OpenAPI schema for application with id "%s": %s'
46
+ )
47
+ export const FailedToRetrieveGraphQLSchemaError = createError(
48
+ `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_GRAPHQL_SCHEMA`,
49
+ 'Failed to retrieve GraphQL schema for application with id "%s": %s'
50
+ )
51
+ export const FailedToRetrieveMetaError = createError(
52
+ `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_META`,
53
+ 'Failed to retrieve metadata for application with id "%s": %s'
54
+ )
55
+ export const FailedToRetrieveMetricsError = createError(
56
+ `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_METRICS`,
57
+ 'Failed to retrieve metrics for application with id "%s": %s'
58
+ )
59
+ export const FailedToRetrieveHealthError = createError(
60
+ `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_HEALTH`,
61
+ 'Failed to retrieve health for application with id "%s": %s'
62
+ )
63
+ export const FailedToPerformCustomHealthCheckError = createError(
64
+ `${ERROR_PREFIX}_FAILED_TO_PERFORM_CUSTOM_HEALTH_CHECK`,
65
+ 'Failed to perform custom healthcheck for application with id "%s": %s'
66
+ )
67
+ export const FailedToPerformCustomReadinessCheckError = createError(
68
+ `${ERROR_PREFIX}_FAILED_TO_PERFORM_CUSTOM_READINESS_CHECK`,
69
+ 'Failed to perform custom readiness check for application with id "%s": %s'
70
+ )
71
+ export const ApplicationAlreadyStartedError = createError(
72
+ `${ERROR_PREFIX}_APPLICATION_ALREADY_STARTED`,
73
+ 'Application is already started'
74
+ )
75
+ export const RuntimeNotStartedError = createError(`${ERROR_PREFIX}_NOT_STARTED`, 'Application has not been started')
76
+ export const ConfigPathMustBeStringError = createError(
77
+ `${ERROR_PREFIX}_CONFIG_PATH_MUST_BE_STRING`,
78
+ 'Config path must be a string'
79
+ )
80
+ export const NoConfigFileFoundError = createError(
81
+ `${ERROR_PREFIX}_NO_CONFIG_FILE_FOUND`,
82
+ "No config file found for application '%s'"
83
+ )
84
+ export const InvalidEntrypointError = createError(
85
+ `${ERROR_PREFIX}_INVALID_ENTRYPOINT`,
86
+ "Invalid entrypoint: '%s' does not exist"
87
+ )
88
+ export const MissingEntrypointError = createError(
89
+ `${ERROR_PREFIX}_MISSING_ENTRYPOINT`,
90
+ 'Missing application entrypoint.'
91
+ )
92
+ export const MissingDependencyError = createError(`${ERROR_PREFIX}_MISSING_DEPENDENCY`, 'Missing dependency: "%s"')
93
+ export const InspectAndInspectBrkError = createError(
94
+ `${ERROR_PREFIX}_INSPECT_AND_INSPECT_BRK`,
95
+ '--inspect and --inspect-brk cannot be used together'
96
+ )
97
+ export const InspectorPortError = createError(
98
+ `${ERROR_PREFIX}_INSPECTOR_PORT`,
99
+ 'Inspector port must be 0 or in range 1024 to 65535'
100
+ )
101
+ export const InspectorHostError = createError(`${ERROR_PREFIX}_INSPECTOR_HOST`, 'Inspector host cannot be empty')
102
+ export const CannotMapSpecifierToAbsolutePathError = createError(
103
+ `${ERROR_PREFIX}_CANNOT_MAP_SPECIFIER_TO_ABSOLUTE_PATH`,
104
+ 'Cannot map "%s" to an absolute path'
105
+ )
106
+ export const NodeInspectorFlagsNotSupportedError = createError(
107
+ `${ERROR_PREFIX}_NODE_INSPECTOR_FLAGS_NOT_SUPPORTED`,
108
+ "The Node.js inspector flags are not supported. Please use 'platformatic start --inspect' instead."
109
+ )
110
+ export const FailedToUnlinkManagementApiSocket = createError(
111
+ `${ERROR_PREFIX}_FAILED_TO_UNLINK_MANAGEMENT_API_SOCKET`,
112
+ 'Failed to unlink management API socket "%s"'
113
+ )
114
+ export const LogFileNotFound = createError(
115
+ `${ERROR_PREFIX}_LOG_FILE_NOT_FOUND`,
116
+ 'Log file with index %s not found',
117
+ 404
118
+ )
119
+ export const WorkerIsRequired = createError(`${ERROR_PREFIX}_REQUIRED_WORKER`, 'The worker parameter is required')
120
+ export const InvalidArgumentError = createError(`${ERROR_PREFIX}_INVALID_ARGUMENT`, 'Invalid argument: "%s"')
121
+ export const MessagingError = createError(
122
+ `${ERROR_PREFIX}_MESSAGING_ERROR`,
123
+ 'Cannot send a message to application "%s": %s'
124
+ )
6
125
 
7
- module.exports = {
8
- AddressInUseError: createError(`${ERROR_PREFIX}_EADDR_IN_USE`, 'The current port is in use by another application'),
9
- RuntimeExitedError: createError(`${ERROR_PREFIX}_RUNTIME_EXIT`, 'The runtime exited before the operation completed'),
10
- ServiceExitedError: createError(`${ERROR_PREFIX}_SERVICE_EXIT`, 'The service %s exited prematurely with error code %d'),
11
- UnknownRuntimeAPICommandError: createError(`${ERROR_PREFIX}_UNKNOWN_RUNTIME_API_COMMAND`, 'Unknown Runtime API command "%s"'),
12
- ServiceNotFoundError: createError(`${ERROR_PREFIX}_SERVICE_NOT_FOUND`, 'Service %s not found. Available services are: %s'),
13
- ServiceNotStartedError: createError(`${ERROR_PREFIX}_SERVICE_NOT_STARTED`, "Service with id '%s' is not started"),
14
- FailedToRetrieveOpenAPISchemaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_OPENAPI_SCHEMA`, 'Failed to retrieve OpenAPI schema for service with id "%s": %s'),
15
- FailedToRetrieveGraphQLSchemaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_GRAPHQL_SCHEMA`, 'Failed to retrieve GraphQL schema for service with id "%s": %s'),
16
- FailedToRetrieveMetaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_META`, 'Failed to retrieve metadata for service with id "%s": %s'),
17
- FailedToRetrieveMetricsError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_METRICS`, 'Failed to retrieve metrics for service with id "%s": %s'),
18
- ApplicationAlreadyStartedError: createError(`${ERROR_PREFIX}_APPLICATION_ALREADY_STARTED`, 'Application is already started'),
19
- ApplicationNotStartedError: createError(`${ERROR_PREFIX}_APPLICATION_NOT_STARTED`, 'Application has not been started'),
20
- ConfigPathMustBeStringError: createError(`${ERROR_PREFIX}_CONFIG_PATH_MUST_BE_STRING`, 'Config path must be a string'),
21
- NoConfigFileFoundError: createError(`${ERROR_PREFIX}_NO_CONFIG_FILE_FOUND`, "No config file found for service '%s'"),
22
- InvalidEntrypointError: createError(`${ERROR_PREFIX}_INVALID_ENTRYPOINT`, "Invalid entrypoint: '%s' does not exist"),
23
- MissingEntrypointError: createError(`${ERROR_PREFIX}_MISSING_ENTRYPOINT`, 'Missing application entrypoint.'),
24
- InvalidServicesWithWebError: createError(`${ERROR_PREFIX}_INVALID_SERVICES_WITH_WEB`, 'The "services" property cannot be used when the "web" property is also defined'),
25
- MissingDependencyError: createError(`${ERROR_PREFIX}_MISSING_DEPENDENCY`, 'Missing dependency: "%s"'),
26
- InspectAndInspectBrkError: createError(`${ERROR_PREFIX}_INSPECT_AND_INSPECT_BRK`, '--inspect and --inspect-brk cannot be used together'),
27
- InspectorPortError: createError(`${ERROR_PREFIX}_INSPECTOR_PORT`, 'Inspector port must be 0 or in range 1024 to 65535'),
28
- InspectorHostError: createError(`${ERROR_PREFIX}_INSPECTOR_HOST`, 'Inspector host cannot be empty'),
29
- CannotMapSpecifierToAbsolutePathError: createError(`${ERROR_PREFIX}_CANNOT_MAP_SPECIFIER_TO_ABSOLUTE_PATH`, 'Cannot map "%s" to an absolute path'),
30
- NodeInspectorFlagsNotSupportedError: createError(`${ERROR_PREFIX}_NODE_INSPECTOR_FLAGS_NOT_SUPPORTED`, 'The Node.js inspector flags are not supported. Please use \'platformatic start --inspect\' instead.'),
31
- FailedToUnlinkManagementApiSocket: createError(`${ERROR_PREFIX}_FAILED_TO_UNLINK_MANAGEMENT_API_SOCKET`, 'Failed to unlink management API socket "%s"'),
32
- LogFileNotFound: createError(`${ERROR_PREFIX}_LOG_FILE_NOT_FOUND`, 'Log file with index %s not found', 404),
33
- WorkerIsRequired: createError(`${ERROR_PREFIX}_REQUIRED_WORKER`, 'The worker parameter is required'),
34
-
35
- // TODO: should remove next one as it's not used anymore
36
- CannotRemoveServiceOnUpdateError: createError(`${ERROR_PREFIX}_CANNOT_REMOVE_SERVICE_ON_UPDATE`, 'Cannot remove service "%s" when updating a Runtime'),
37
- }
126
+ export const MissingPprofCapture = createError(
127
+ `${ERROR_PREFIX}_MISSING_PPROF_CAPTURE`,
128
+ 'Please install @platformatic/wattpm-pprof-capture'
129
+ )