@platformatic/basic 2.0.0-alpha.3 → 2.0.0-alpha.5

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 (54) hide show
  1. package/NOTICE +13 -0
  2. package/README.md +13 -0
  3. package/config.d.ts +11 -0
  4. package/eslint.config.js +3 -1
  5. package/index.js +63 -77
  6. package/lib/base.js +11 -9
  7. package/lib/errors.js +8 -0
  8. package/lib/schema.js +31 -15
  9. package/lib/utils.js +6 -39
  10. package/lib/worker/child-manager.js +90 -0
  11. package/lib/worker/child-process.js +150 -0
  12. package/lib/worker/server-listener.js +29 -0
  13. package/package.json +18 -11
  14. package/schema.json +12 -0
  15. package/test/helper.js +116 -16
  16. package/lib/server.js +0 -135
  17. package/test/express.test.js +0 -34
  18. package/test/fastify.test.js +0 -34
  19. package/test/fixtures/express/no-build/index.js +0 -16
  20. package/test/fixtures/express/no-build/package.json +0 -7
  21. package/test/fixtures/express/no-build/platformatic.app.json +0 -3
  22. package/test/fixtures/express/no-build/platformatic.as-entrypoint.runtime.json +0 -19
  23. package/test/fixtures/express/no-build/platformatic.no-entrypoint.runtime.json +0 -16
  24. package/test/fixtures/express/with-build/index.js +0 -17
  25. package/test/fixtures/express/with-build/package.json +0 -7
  26. package/test/fixtures/express/with-build/platformatic.app.json +0 -3
  27. package/test/fixtures/express/with-build/platformatic.as-entrypoint.runtime.json +0 -19
  28. package/test/fixtures/express/with-build/platformatic.no-entrypoint.runtime.json +0 -16
  29. package/test/fixtures/fastify/no-build/index.js +0 -14
  30. package/test/fixtures/fastify/no-build/package.json +0 -7
  31. package/test/fixtures/fastify/no-build/platformatic.app.json +0 -3
  32. package/test/fixtures/fastify/no-build/platformatic.as-entrypoint.runtime.json +0 -19
  33. package/test/fixtures/fastify/no-build/platformatic.no-entrypoint.runtime.json +0 -16
  34. package/test/fixtures/fastify/with-build/index.js +0 -15
  35. package/test/fixtures/fastify/with-build/package.json +0 -7
  36. package/test/fixtures/fastify/with-build/platformatic.app.json +0 -3
  37. package/test/fixtures/fastify/with-build/platformatic.as-entrypoint.runtime.json +0 -19
  38. package/test/fixtures/fastify/with-build/platformatic.no-entrypoint.runtime.json +0 -16
  39. package/test/fixtures/nodejs/no-build/index.js +0 -21
  40. package/test/fixtures/nodejs/no-build/package.json +0 -7
  41. package/test/fixtures/nodejs/no-build/platformatic.app.json +0 -3
  42. package/test/fixtures/nodejs/no-build/platformatic.as-entrypoint.runtime.json +0 -19
  43. package/test/fixtures/nodejs/no-build/platformatic.no-entrypoint.runtime.json +0 -16
  44. package/test/fixtures/nodejs/no-configuration/index.js +0 -21
  45. package/test/fixtures/nodejs/no-configuration/platformatic.as-entrypoint.runtime.json +0 -18
  46. package/test/fixtures/nodejs/no-configuration/platformatic.no-entrypoint.runtime.json +0 -16
  47. package/test/fixtures/nodejs/with-build/index.js +0 -20
  48. package/test/fixtures/nodejs/with-build/package.json +0 -7
  49. package/test/fixtures/nodejs/with-build/platformatic.app.json +0 -3
  50. package/test/fixtures/nodejs/with-build/platformatic.as-entrypoint.runtime.json +0 -19
  51. package/test/fixtures/nodejs/with-build/platformatic.no-entrypoint.runtime.json +0 -16
  52. package/test/fixtures/platformatic-service/platformatic.service.json +0 -15
  53. package/test/fixtures/platformatic-service/plugin.js +0 -12
  54. package/test/node.test.js +0 -66
@@ -1,19 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": false,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "error"
10
- }
11
- },
12
- "services": [
13
- {
14
- "id": "main",
15
- "path": ".",
16
- "config": "platformatic.app.json"
17
- }
18
- ]
19
- }
@@ -1,16 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": false,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "error"
10
- }
11
- },
12
- "services": [
13
- { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
- { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
- ]
16
- }
@@ -1,21 +0,0 @@
1
- import { createServer } from 'node:http'
2
-
3
- const server = createServer((req, res) => {
4
- if (req.url === '/direct') {
5
- res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
6
- res.end(JSON.stringify({ ok: true }))
7
- } else if (req.url === '/mesh') {
8
- fetch('http://main.plt.local/direct')
9
- .then(response => response.json())
10
- .then(json => {
11
- res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
12
- res.end(JSON.stringify({ ok: true }))
13
- })
14
- } else {
15
- res.writeHead(404, { 'content-type': 'application/json', connection: 'close' })
16
- res.end(JSON.stringify({ ok: false }))
17
- }
18
- })
19
-
20
- // This would likely fail if our code doesn't work
21
- server.listen(1)
@@ -1,7 +0,0 @@
1
- {
2
- "main": "index.js",
3
- "type": "module",
4
- "dependencies": {
5
- "express": "^4.19.2"
6
- }
7
- }
@@ -1,3 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json"
3
- }
@@ -1,19 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": true,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "warn"
10
- }
11
- },
12
- "services": [
13
- {
14
- "id": "main",
15
- "path": ".",
16
- "config": "platformatic.app.json"
17
- }
18
- ]
19
- }
@@ -1,16 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": true,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "warn"
10
- }
11
- },
12
- "services": [
13
- { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
- { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
- ]
16
- }
@@ -1,21 +0,0 @@
1
- import { createServer } from 'node:http'
2
-
3
- const server = createServer((req, res) => {
4
- if (req.url === '/direct') {
5
- res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
6
- res.end(JSON.stringify({ ok: true }))
7
- } else if (req.url === '/mesh') {
8
- fetch('http://main.plt.local/direct')
9
- .then(response => response.json())
10
- .then(json => {
11
- res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
12
- res.end(JSON.stringify({ ok: true }))
13
- })
14
- } else {
15
- res.writeHead(404, { 'content-type': 'application/json', connection: 'close' })
16
- res.end(JSON.stringify({ ok: false }))
17
- }
18
- })
19
-
20
- // This would likely fail if our code doesn't work
21
- server.listen(1)
@@ -1,18 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": true,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "warn"
10
- }
11
- },
12
- "services": [
13
- {
14
- "id": "main",
15
- "path": "."
16
- }
17
- ]
18
- }
@@ -1,16 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": true,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "warn"
10
- }
11
- },
12
- "services": [
13
- { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
- { "id": "internal", "path": "." }
15
- ]
16
- }
@@ -1,20 +0,0 @@
1
- import { createServer } from 'node:http'
2
-
3
- export function build () {
4
- return createServer((req, res) => {
5
- if (req.url === '/direct') {
6
- res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
7
- res.end(JSON.stringify({ ok: true }))
8
- } else if (req.url === '/mesh') {
9
- fetch('http://main.plt.local/direct')
10
- .then(response => response.json())
11
- .then(json => {
12
- res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
13
- res.end(JSON.stringify({ ok: true }))
14
- })
15
- } else {
16
- res.writeHead(404, { 'content-type': 'application/json', connection: 'close' })
17
- res.end(JSON.stringify({ ok: false }))
18
- }
19
- })
20
- }
@@ -1,7 +0,0 @@
1
- {
2
- "main": "index.js",
3
- "type": "module",
4
- "dependencies": {
5
- "express": "^4.19.2"
6
- }
7
- }
@@ -1,3 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json"
3
- }
@@ -1,19 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": true,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "warn"
10
- }
11
- },
12
- "services": [
13
- {
14
- "id": "main",
15
- "path": ".",
16
- "config": "platformatic.app.json"
17
- }
18
- ]
19
- }
@@ -1,16 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": true,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "warn"
10
- }
11
- },
12
- "services": [
13
- { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
- { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
- ]
16
- }
@@ -1,15 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/service/1.52.0.json",
3
- "server": {
4
- "logger": {
5
- "level": "error"
6
- }
7
- },
8
- "plugins": {
9
- "paths": [
10
- {
11
- "path": "./plugin.js"
12
- }
13
- ]
14
- }
15
- }
@@ -1,12 +0,0 @@
1
- 'use strict'
2
-
3
- export default async function (app) {
4
- app.get('/mesh', async () => {
5
- const response = await fetch('http://internal.plt.local/direct')
6
- return response.json()
7
- })
8
-
9
- app.get('/direct', async () => {
10
- return { ok: true }
11
- })
12
- }
package/test/node.test.js DELETED
@@ -1,66 +0,0 @@
1
- import { deepStrictEqual, ifError } from 'node:assert'
2
- import { test } from 'node:test'
3
- import { createRuntime, getLogs, verifyViaHTTP, verifyViaInject } from './helper.js'
4
-
5
- test('can detect and start a Node.js application with no configuration files', async t => {
6
- const { runtime, url } = await createRuntime(t, 'nodejs/no-configuration/platformatic.as-entrypoint.runtime.json')
7
-
8
- await verifyViaHTTP(url, '/direct', 200, { ok: true })
9
- await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
10
-
11
- const logs = await getLogs(runtime)
12
- deepStrictEqual(
13
- logs.map(m => m.msg),
14
- ['The service main had no valid entrypoint defined in the package.json file. Falling back to the file index.js.']
15
- )
16
- })
17
-
18
- test('can detect and start a Node.js application with no configuration files and when not the entrypoint', async t => {
19
- const { runtime, url } = await createRuntime(t, 'nodejs/no-configuration/platformatic.no-entrypoint.runtime.json')
20
-
21
- await verifyViaHTTP(url, '/mesh', 200, { ok: true })
22
- await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
23
-
24
- const logs = await getLogs(runtime)
25
-
26
- deepStrictEqual(
27
- logs.map(m => m.msg),
28
- [
29
- 'The service internal had no valid entrypoint defined in the package.json file. Falling back to the file index.js.',
30
- ]
31
- )
32
- })
33
-
34
- test('can detect and start a Node.js application with no build function defined', async t => {
35
- const { runtime, url } = await createRuntime(t, 'nodejs/no-build/platformatic.as-entrypoint.runtime.json')
36
-
37
- await verifyViaHTTP(url, '/direct', 200, { ok: true })
38
- await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
39
-
40
- const logs = await getLogs(runtime)
41
- deepStrictEqual(logs, [])
42
- })
43
-
44
- test('can detect and start a Node.js application with no build function and when not the entrypoint', async t => {
45
- const { runtime, url } = await createRuntime(t, 'nodejs/no-build/platformatic.no-entrypoint.runtime.json')
46
-
47
- await verifyViaHTTP(url, '/mesh', 200, { ok: true })
48
- await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
49
- })
50
-
51
- test('can detect and start a Node.js application with build function defined', async t => {
52
- const { runtime, url } = await createRuntime(t, 'nodejs/with-build/platformatic.as-entrypoint.runtime.json')
53
-
54
- await verifyViaHTTP(url, '/direct', 200, { ok: true })
55
- await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
56
- })
57
-
58
- test('can detect and start a Node.js application with build function defined and when not the entrypoint', async t => {
59
- const { runtime, url } = await createRuntime(t, 'nodejs/no-build/platformatic.no-entrypoint.runtime.json')
60
-
61
- await verifyViaHTTP(url, '/mesh', 200, { ok: true })
62
- await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
63
-
64
- const details = await runtime.getServiceDetails('internal')
65
- ifError(details.url)
66
- })