@platformatic/runtime 1.6.1 → 1.7.1

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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@myscope/myname",
3
+ "version": "0.0.1",
4
+ "description": "test package.json"
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "version": "0.0.1",
3
+ "description": "test package.json"
4
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.22.0/db",
3
+ "server": {
4
+ "hostname": "127.0.0.1",
5
+ "port": 0
6
+ },
7
+ "migrations": {
8
+ "dir": "migrations",
9
+ "table": "versions"
10
+ },
11
+ "types": {
12
+ "autogenerate": false
13
+ },
14
+ "db": {
15
+ "connectionString": "sqlite://db.sqlite",
16
+ "graphql": true,
17
+ "ignore": {
18
+ "versions": true
19
+ },
20
+ "events": false
21
+ },
22
+ "plugins": {
23
+ "paths": [
24
+ "plugin.js"
25
+ ]
26
+ }
27
+ }
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+
3
+ /** @param {import('fastify').FastifyInstance} app */
4
+ module.exports = async function (app) {
5
+ app.get('/async_crash', async () => {
6
+ setImmediate(() => {
7
+ throw new Error('boom')
8
+ })
9
+
10
+ return 'ok'
11
+ })
12
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.22.0/db",
3
+ "server": {
4
+ "hostname": "127.0.0.1",
5
+ "port": 0
6
+ },
7
+ "migrations": {
8
+ "dir": "migrations",
9
+ "table": "versions"
10
+ },
11
+ "types": {
12
+ "autogenerate": false
13
+ },
14
+ "db": {
15
+ "connectionString": "sqlite://db.sqlite",
16
+ "graphql": true,
17
+ "ignore": {
18
+ "versions": true
19
+ },
20
+ "events": false
21
+ },
22
+ "plugins": {
23
+ "paths": [
24
+ "plugin.js"
25
+ ]
26
+ }
27
+ }
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+
3
+ /** @param {import('fastify').FastifyInstance} app */
4
+ module.exports = async function (app) {
5
+ app.get('/async_crash', async () => {
6
+ setImmediate(() => {
7
+ throw new Error('boom')
8
+ })
9
+
10
+ return 'ok'
11
+ })
12
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "mysimplename",
3
+ "version": "0.0.1",
4
+ "description": "test package.json"
5
+ }
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ module.exports = async function (app) {
4
+ app.get('/hello', async () => {
5
+ return { hello: 'hello123' }
6
+ })
7
+ }
package/help/start.txt CHANGED
@@ -1,5 +1,21 @@
1
1
  Start the Platformatic Runtime with the following command:
2
2
 
3
- ``` bash
3
+ ```bash
4
4
  $ platformatic runtime start
5
5
  ```
6
+
7
+ You can also specify a custom routes file, for example:
8
+
9
+ ```bash
10
+ $ platformatic runtime start routes.js
11
+ ```
12
+
13
+ Where `routes.js` is:
14
+
15
+ ```javascript
16
+ module.exports = async function (app) {
17
+ app.get('/hello', async () => {
18
+ return { hello: 'hello123' }
19
+ })
20
+ }
21
+ ```
package/lib/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
  const { readFile, readdir } = require('node:fs/promises')
3
- const { basename, join, resolve: pathResolve } = require('node:path')
3
+ const { join, resolve: pathResolve } = require('node:path')
4
4
  const { closest } = require('fastest-levenshtein')
5
5
  const Topo = require('@hapi/topo')
6
6
  const ConfigManager = require('@platformatic/config')
@@ -253,16 +253,26 @@ platformaticRuntime.configManagerConfig = {
253
253
  }
254
254
 
255
255
  async function wrapConfigInRuntimeConfig ({ configManager, args }) {
256
+ let serviceId = 'main'
257
+ try {
258
+ const packageJson = join(configManager.dirname, 'package.json')
259
+ serviceId = require(packageJson).name || 'main'
260
+ if (serviceId.startsWith('@')) {
261
+ serviceId = serviceId.split('/')[1]
262
+ }
263
+ } catch (err) {
264
+ // on purpose, the package.json might be missing
265
+ }
266
+
256
267
  /* c8 ignore next */
257
- const id = basename(configManager.dirname) || 'main'
258
268
  const wrapperConfig = {
259
269
  $schema: schema.$id,
260
- entrypoint: id,
270
+ entrypoint: serviceId,
261
271
  allowCycles: false,
262
272
  hotReload: true,
263
273
  services: [
264
274
  {
265
- id,
275
+ id: serviceId,
266
276
  path: configManager.dirname,
267
277
  config: configManager.fullPath
268
278
  }
package/lib/start.js CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict'
2
2
  const { once } = require('node:events')
3
3
  const inspector = require('node:inspector')
4
- const { join } = require('node:path')
4
+ const { join, resolve, dirname } = require('node:path')
5
+ const fs = require('node:fs/promises')
5
6
  const { pathToFileURL } = require('node:url')
6
7
  const { Worker } = require('node:worker_threads')
7
8
  const closeWithGrace = require('close-with-grace')
@@ -11,6 +12,7 @@ const { parseInspectorOptions, wrapConfigInRuntimeConfig } = require('./config')
11
12
  const RuntimeApiClient = require('./api-client.js')
12
13
  const { printConfigValidationErrors } = require('@platformatic/config')
13
14
  const errors = require('./errors')
15
+ const pkg = require('../package.json')
14
16
 
15
17
  const kLoaderFile = pathToFileURL(join(__dirname, 'loader.mjs')).href
16
18
  const kWorkerFile = join(__dirname, 'worker.js')
@@ -114,6 +116,29 @@ async function startCommand (args) {
114
116
 
115
117
  return await runtime.start()
116
118
  } catch (err) {
119
+ if (err.code === 'PLT_CONFIG_NO_CONFIG_FILE_FOUND' && args.length === 1) {
120
+ const config = {
121
+ $schema: `https://platformatic.dev/schemas/v${pkg.version}/service`,
122
+ server: {
123
+ hostname: '127.0.0.1',
124
+ port: 3042,
125
+ logger: {
126
+ level: 'info'
127
+ }
128
+ },
129
+ plugins: {
130
+ paths: [args[0]]
131
+ },
132
+ service: {
133
+ openapi: true
134
+ },
135
+ watch: true
136
+ }
137
+ const toWrite = join(dirname(resolve(args[0])), 'platformatic.service.json')
138
+ console.log(`No config file found, creating ${join(dirname(args[0]), 'platformatic.service.json')}`)
139
+ await fs.writeFile(toWrite, JSON.stringify(config, null, 2))
140
+ return startCommand(['--config', toWrite])
141
+ }
117
142
  logErrorAndExit(err)
118
143
  }
119
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "1.6.1",
3
+ "version": "1.7.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -28,8 +28,8 @@
28
28
  "standard": "^17.1.0",
29
29
  "tsd": "^0.29.0",
30
30
  "typescript": "^5.2.2",
31
- "@platformatic/sql-graphql": "1.6.1",
32
- "@platformatic/sql-mapper": "1.6.1"
31
+ "@platformatic/sql-graphql": "1.7.1",
32
+ "@platformatic/sql-mapper": "1.7.1"
33
33
  },
34
34
  "dependencies": {
35
35
  "@fastify/error": "^3.4.0",
@@ -48,12 +48,12 @@
48
48
  "pino": "^8.16.0",
49
49
  "pino-pretty": "^10.2.3",
50
50
  "undici": "^5.26.3",
51
- "@platformatic/config": "1.6.1",
52
- "@platformatic/composer": "1.6.1",
53
- "@platformatic/db": "1.6.1",
54
- "@platformatic/service": "1.6.1",
55
- "@platformatic/telemetry": "1.6.1",
56
- "@platformatic/utils": "1.6.1"
51
+ "@platformatic/composer": "1.7.1",
52
+ "@platformatic/config": "1.7.1",
53
+ "@platformatic/db": "1.7.1",
54
+ "@platformatic/service": "1.7.1",
55
+ "@platformatic/telemetry": "1.7.1",
56
+ "@platformatic/utils": "1.7.1"
57
57
  },
58
58
  "standard": {
59
59
  "ignore": [