@platformatic/runtime 0.27.0 → 0.29.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 (50) hide show
  1. package/fixtures/configs/invalid-schema-type.config.json +1 -2
  2. package/fixtures/configs/monorepo-client-without-id.json +24 -0
  3. package/fixtures/configs/no-schema.config.json +1 -2
  4. package/fixtures/monorepo/serviceApp/platformatic.service-client-without-id.json +21 -0
  5. package/fixtures/monorepo/serviceApp/platformatic.service.json +1 -1
  6. package/fixtures/monorepo/serviceApp/plugin.js +4 -0
  7. package/fixtures/serviceAppThrowsOnStart/platformatic.service.json +0 -1
  8. package/fixtures/start-command-in-runtime.js +14 -0
  9. package/fixtures/typescript/platformatic.runtime.json +12 -0
  10. package/fixtures/typescript/services/composer/platformatic.composer.json +28 -0
  11. package/fixtures/typescript/services/movies/global.d.ts +24 -0
  12. package/fixtures/typescript/services/movies/migrations/001.do.sql +6 -0
  13. package/fixtures/typescript/services/movies/migrations/001.undo.sql +3 -0
  14. package/fixtures/typescript/services/movies/package.json +17 -0
  15. package/fixtures/typescript/services/movies/platformatic.db.json +33 -0
  16. package/fixtures/typescript/services/movies/plugin.ts +5 -0
  17. package/fixtures/typescript/services/movies/tsconfig.json +21 -0
  18. package/fixtures/typescript/services/movies/types/Movie.d.ts +9 -0
  19. package/fixtures/typescript/services/movies/types/index.d.ts +7 -0
  20. package/fixtures/typescript/services/titles/client/client.d.ts +141 -0
  21. package/fixtures/typescript/services/titles/client/client.openapi.json +630 -0
  22. package/fixtures/typescript/services/titles/client/package.json +4 -0
  23. package/fixtures/typescript/services/titles/platformatic.service.json +31 -0
  24. package/fixtures/typescript/services/titles/plugins/example.ts +6 -0
  25. package/fixtures/typescript/services/titles/routes/root.ts +21 -0
  26. package/fixtures/typescript/services/titles/tsconfig.json +21 -0
  27. package/help/compile.txt +8 -0
  28. package/index.js +7 -7
  29. package/lib/api-client.js +74 -0
  30. package/lib/api.js +206 -0
  31. package/lib/app.js +51 -59
  32. package/lib/compile.js +43 -0
  33. package/lib/config.js +111 -20
  34. package/lib/loader.mjs +21 -13
  35. package/lib/message-port-writable.js +42 -0
  36. package/lib/start.js +42 -35
  37. package/lib/unified-api.js +36 -7
  38. package/lib/worker.js +27 -79
  39. package/package.json +12 -8
  40. package/runtime.mjs +4 -0
  41. package/test/api.test.js +295 -0
  42. package/test/app.test.js +40 -0
  43. package/test/cli/compile.test.mjs +52 -0
  44. package/test/cli/start.test.mjs +56 -0
  45. package/test/cli/validations.test.mjs +2 -1
  46. package/test/cli/watch.test.mjs +12 -12
  47. package/test/config.test.js +146 -1
  48. package/test/start.test.js +44 -0
  49. package/test/unified-api.test.js +33 -0
  50. package/test/worker.test.js +0 -21
@@ -9,8 +9,7 @@
9
9
  }
10
10
  },
11
11
  "plugins": {
12
- "paths": ["./plugin.js"],
13
- "hotReload": false
12
+ "paths": ["./plugin.js"]
14
13
  },
15
14
  "service": {
16
15
  "openapi": true
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.20.0/runtime",
3
+ "entrypoint": "serviceApp",
4
+ "allowCycles": true,
5
+ "hotReload": false,
6
+ "autoload": {
7
+ "path": "../monorepo",
8
+ "exclude": ["docs", "composerApp"],
9
+ "mappings": {
10
+ "serviceApp": {
11
+ "id": "serviceApp",
12
+ "config": "platformatic.service-client-without-id.json"
13
+ },
14
+ "serviceAppWithLogger": {
15
+ "id": "with-logger",
16
+ "config": "platformatic.service.json"
17
+ },
18
+ "serviceAppWithMultiplePlugins": {
19
+ "id": "multi-plugin-service",
20
+ "config": "platformatic.service.json"
21
+ }
22
+ }
23
+ }
24
+ }
@@ -8,8 +8,7 @@
8
8
  }
9
9
  },
10
10
  "plugins": {
11
- "paths": ["./plugin.js"],
12
- "hotReload": false
11
+ "paths": ["./plugin.js"]
13
12
  },
14
13
  "service": {
15
14
  "openapi": true
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.20.0/service",
3
+ "server": {
4
+ "hostname": "127.0.0.1",
5
+ "port": 0
6
+ },
7
+ "service": {
8
+ "openapi": true
9
+ },
10
+ "plugins": {
11
+ "paths": [
12
+ "plugin.js"
13
+ ]
14
+ },
15
+ "clients": [
16
+ {
17
+ "path": "./with-logger",
18
+ "url": "{PLT_WITH_LOGGER_URL}"
19
+ }
20
+ ]
21
+ }
@@ -8,13 +8,13 @@
8
8
  "openapi": true
9
9
  },
10
10
  "plugins": {
11
- "hotReload": true,
12
11
  "paths": [
13
12
  "plugin.js"
14
13
  ]
15
14
  },
16
15
  "clients": [
17
16
  {
17
+ "serviceId": "with-logger",
18
18
  "path": "./with-logger",
19
19
  "url": "{PLT_WITH_LOGGER_URL}"
20
20
  }
@@ -22,4 +22,8 @@ module.exports = async function (app) {
22
22
 
23
23
  return 'ok'
24
24
  })
25
+
26
+ app.get('/env', () => {
27
+ return process.env
28
+ })
25
29
  }
@@ -5,7 +5,6 @@
5
5
  "port": 0
6
6
  },
7
7
  "plugins": {
8
- "hotReload": true,
9
8
  "paths": [
10
9
  "plugin.js"
11
10
  ]
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+ const assert = require('node:assert')
3
+ const { request } = require('undici')
4
+ const { startCommandInRuntime } = require('../lib/unified-api')
5
+
6
+ async function main () {
7
+ const entrypoint = await startCommandInRuntime(['-c', process.argv[2]])
8
+ const res = await request(entrypoint)
9
+
10
+ assert.strictEqual(res.statusCode, 200)
11
+ process.exit(42)
12
+ }
13
+
14
+ main()
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.28.1/runtime",
3
+ "entrypoint": "composer",
4
+ "allowCycles": false,
5
+ "hotReload": true,
6
+ "autoload": {
7
+ "path": "services",
8
+ "exclude": [
9
+ "docs"
10
+ ]
11
+ }
12
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.28.1/composer",
3
+ "server": {
4
+ "hostname": "{PLT_SERVER_HOSTNAME}",
5
+ "port": "{PORT}",
6
+ "logger": {
7
+ "level": "{PLT_SERVER_LOGGER_LEVEL}"
8
+ }
9
+ },
10
+ "composer": {
11
+ "services": [
12
+ {
13
+ "id": "movies",
14
+ "openapi": {
15
+ "url": "/documentation/json"
16
+ }
17
+ },
18
+ {
19
+ "id": "titles",
20
+ "openapi": {
21
+ "url": "/documentation/json"
22
+ }
23
+ }
24
+ ],
25
+ "refreshTimeout": 1000
26
+ },
27
+ "watch": true
28
+ }
@@ -0,0 +1,24 @@
1
+ import { Entity } from '@platformatic/sql-mapper';
2
+ import graphqlPlugin from '@platformatic/sql-graphql'
3
+ import { EntityTypes, Movie } from './types'
4
+
5
+ declare module 'fastify' {
6
+ interface FastifyInstance {
7
+ getSchema<T extends 'Movie'>(schemaId: T): {
8
+ '$id': string,
9
+ title: string,
10
+ description: string,
11
+ type: string,
12
+ properties: {
13
+ [x in keyof EntityTypes[T]]: { type: string, nullable?: boolean }
14
+ },
15
+ required: string[]
16
+ };
17
+ }
18
+ }
19
+
20
+ declare module '@platformatic/sql-mapper' {
21
+ interface Entities {
22
+ movie: Entity<Movie>,
23
+ }
24
+ }
@@ -0,0 +1,6 @@
1
+
2
+ -- Add SQL in this file to create the database tables for your API
3
+ CREATE TABLE IF NOT EXISTS movies (
4
+ id INTEGER PRIMARY KEY,
5
+ title TEXT NOT NULL
6
+ );
@@ -0,0 +1,3 @@
1
+
2
+ -- Add SQL in this file to drop the database tables
3
+ DROP TABLE movies;
@@ -0,0 +1,17 @@
1
+ {
2
+ "scripts": {
3
+ "start": "npm run clean && platformatic start",
4
+ "clean": "rm -fr ./dist",
5
+ "build": "npx tsc",
6
+ "migrate": "platformatic db migrations apply"
7
+ },
8
+ "devDependencies": {
9
+ "fastify": "^4.18.0"
10
+ },
11
+ "dependencies": {
12
+ "platformatic": "^0.28.1"
13
+ },
14
+ "engines": {
15
+ "node": "^18.8.0 || >=19"
16
+ }
17
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.28.1/db",
3
+ "server": {
4
+ "hostname": "{PLT_SERVER_HOSTNAME}",
5
+ "port": "{PORT}",
6
+ "logger": {
7
+ "level": "{PLT_SERVER_LOGGER_LEVEL}"
8
+ }
9
+ },
10
+ "db": {
11
+ "connectionString": "{DATABASE_URL}",
12
+ "graphql": true,
13
+ "openapi": true
14
+ },
15
+ "watch": {
16
+ "ignore": [
17
+ "*.sqlite",
18
+ "*.sqlite-journal"
19
+ ]
20
+ },
21
+ "migrations": {
22
+ "dir": "migrations"
23
+ },
24
+ "plugins": {
25
+ "paths": [
26
+ "plugin.ts"
27
+ ],
28
+ "typescript": true
29
+ },
30
+ "types": {
31
+ "autogenerate": true
32
+ }
33
+ }
@@ -0,0 +1,5 @@
1
+ /// <reference path="./global.d.ts" />
2
+ import { FastifyInstance } from 'fastify'
3
+
4
+ export default async function (app: FastifyInstance) {
5
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "esModuleInterop": true,
5
+ "target": "es2019",
6
+ "sourceMap": true,
7
+ "pretty": true,
8
+ "noEmitOnError": true,
9
+ "outDir": "dist"
10
+ },
11
+ "watchOptions": {
12
+ "watchFile": "fixedPollingInterval",
13
+ "watchDirectory": "fixedPollingInterval",
14
+ "fallbackPolling": "dynamicPriority",
15
+ "synchronousWatchDirectory": true,
16
+ "excludeDirectories": [
17
+ "**/node_modules",
18
+ "dist"
19
+ ]
20
+ }
21
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Movie
3
+ * A Movie
4
+ */
5
+ declare interface Movie {
6
+ id?: number;
7
+ title: string;
8
+ }
9
+ export { Movie };
@@ -0,0 +1,7 @@
1
+ import { Movie } from './Movie'
2
+
3
+ interface EntityTypes {
4
+ Movie:Movie
5
+ }
6
+
7
+ export { EntityTypes ,Movie }
@@ -0,0 +1,141 @@
1
+ import { FastifyPluginAsync } from 'fastify'
2
+
3
+ interface GetMoviesRequest {
4
+ 'limit'?: number;
5
+ 'offset'?: number;
6
+ 'totalCount'?: boolean;
7
+ 'fields'?: Array<string>;
8
+ 'where.id.eq'?: number;
9
+ 'where.id.neq'?: number;
10
+ 'where.id.gt'?: number;
11
+ 'where.id.gte'?: number;
12
+ 'where.id.lt'?: number;
13
+ 'where.id.lte'?: number;
14
+ 'where.id.like'?: number;
15
+ 'where.id.in'?: string;
16
+ 'where.id.nin'?: string;
17
+ 'where.title.eq'?: string;
18
+ 'where.title.neq'?: string;
19
+ 'where.title.gt'?: string;
20
+ 'where.title.gte'?: string;
21
+ 'where.title.lt'?: string;
22
+ 'where.title.lte'?: string;
23
+ 'where.title.like'?: string;
24
+ 'where.title.in'?: string;
25
+ 'where.title.nin'?: string;
26
+ 'where.or'?: Array<string>;
27
+ 'orderby.id'?: string;
28
+ 'orderby.title'?: string;
29
+ }
30
+
31
+ interface GetMoviesResponseOK {
32
+ 'id'?: number;
33
+ 'title': string;
34
+ }
35
+
36
+ interface CreateMovieRequest {
37
+ 'id'?: number;
38
+ 'title': string;
39
+ }
40
+
41
+ interface CreateMovieResponseOK {
42
+ 'id'?: number;
43
+ 'title': string;
44
+ }
45
+
46
+ interface UpdateMoviesRequest {
47
+ 'fields'?: Array<string>;
48
+ 'where.id.eq'?: number;
49
+ 'where.id.neq'?: number;
50
+ 'where.id.gt'?: number;
51
+ 'where.id.gte'?: number;
52
+ 'where.id.lt'?: number;
53
+ 'where.id.lte'?: number;
54
+ 'where.id.like'?: number;
55
+ 'where.id.in'?: string;
56
+ 'where.id.nin'?: string;
57
+ 'where.title.eq'?: string;
58
+ 'where.title.neq'?: string;
59
+ 'where.title.gt'?: string;
60
+ 'where.title.gte'?: string;
61
+ 'where.title.lt'?: string;
62
+ 'where.title.lte'?: string;
63
+ 'where.title.like'?: string;
64
+ 'where.title.in'?: string;
65
+ 'where.title.nin'?: string;
66
+ 'where.or'?: Array<string>;
67
+ 'id'?: number;
68
+ 'title': string;
69
+ }
70
+
71
+ interface UpdateMoviesResponseOK {
72
+ 'id'?: number;
73
+ 'title': string;
74
+ }
75
+
76
+ interface GetMovieByIdRequest {
77
+ 'fields'?: Array<string>;
78
+ 'id': number;
79
+ }
80
+
81
+ interface GetMovieByIdResponseOK {
82
+ 'id'?: number;
83
+ 'title': string;
84
+ }
85
+
86
+ interface UpdateMovieRequest {
87
+ 'fields'?: Array<string>;
88
+ 'id': number;
89
+ 'title': string;
90
+ }
91
+
92
+ interface UpdateMovieResponseOK {
93
+ 'id'?: number;
94
+ 'title': string;
95
+ }
96
+
97
+ interface DeleteMoviesRequest {
98
+ 'fields'?: Array<string>;
99
+ 'id': number;
100
+ }
101
+
102
+ interface DeleteMoviesResponseOK {
103
+ 'id'?: number;
104
+ 'title': string;
105
+ }
106
+
107
+ interface Client {
108
+ getMovies(req: GetMoviesRequest): Promise<Array<GetMoviesResponseOK>>;
109
+ createMovie(req: CreateMovieRequest): Promise<CreateMovieResponseOK>;
110
+ updateMovies(req: UpdateMoviesRequest): Promise<Array<UpdateMoviesResponseOK>>;
111
+ getMovieById(req: GetMovieByIdRequest): Promise<GetMovieByIdResponseOK>;
112
+ updateMovie(req: UpdateMovieRequest): Promise<UpdateMovieResponseOK>;
113
+ deleteMovies(req: DeleteMoviesRequest): Promise<DeleteMoviesResponseOK>;
114
+ }
115
+
116
+ type ClientPlugin = FastifyPluginAsync<NonNullable<client.ClientOptions>>
117
+
118
+ declare module 'fastify' {
119
+ interface ConfigureClient {
120
+ getHeaders(req: FastifyRequest, reply: FastifyReply): Promise<Record<string,string>>;
121
+ }
122
+ interface FastifyInstance {
123
+ 'client': Client;
124
+ configureClient(opts: ConfigureClient): unknown
125
+ }
126
+
127
+ interface FastifyRequest {
128
+ 'client': Client;
129
+ }
130
+ }
131
+
132
+ declare namespace client {
133
+ export interface ClientOptions {
134
+ url: string
135
+ }
136
+ export const client: ClientPlugin;
137
+ export { client as default };
138
+ }
139
+
140
+ declare function client(...params: Parameters<ClientPlugin>): ReturnType<ClientPlugin>;
141
+ export = client;