@platformatic/service 0.43.1 → 0.44.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.
- package/index.d.ts +5 -6
- package/index.test-d.ts +7 -1
- package/lib/gen-types.mjs +40 -0
- package/package.json +6 -7
- package/service.mjs +18 -6
- package/test/cli/compile-1.test.mjs +31 -0
- package/test/cli/gen-types.test.mjs +30 -0
- package/test/cli/validations.test.mjs +2 -1
- package/test/fixtures/hello-ts-with-config/global.d.ts +8 -0
- package/test/fixtures/hello-ts-with-config/platformatic.service.json +16 -0
- package/test/fixtures/hello-ts-with-config/plugin.ts +8 -0
- package/test/fixtures/hello-ts-with-config/tsconfig.json +23 -0
package/index.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/triple-slash-reference */
|
|
2
|
-
/// <reference types="@platformatic/types" />
|
|
3
2
|
/// <reference types="mercurius" />
|
|
4
3
|
/// <reference types="@fastify/swagger" />
|
|
5
4
|
import { FastifyInstance } from 'fastify'
|
|
6
5
|
import ConfigManager from '@platformatic/config'
|
|
7
6
|
import { PlatformaticService } from './config'
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
config: PlatformaticService
|
|
13
|
-
}
|
|
8
|
+
export interface PlatformaticApp<T> {
|
|
9
|
+
configManager: ConfigManager<T>
|
|
10
|
+
config: T
|
|
14
11
|
}
|
|
15
12
|
|
|
13
|
+
export type PlatformaticServiceConfig = PlatformaticService
|
|
14
|
+
|
|
16
15
|
export function buildServer (opts: object, app?: object, ConfigManagerContructor?: object): Promise<FastifyInstance>
|
|
17
16
|
|
|
18
17
|
declare module 'fastify' {
|
package/index.test-d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { expectType } from 'tsd'
|
|
2
2
|
import { FastifyInstance } from 'fastify'
|
|
3
|
-
import { buildServer } from '.'
|
|
3
|
+
import { buildServer, PlatformaticApp } from '.'
|
|
4
4
|
import ConfigManager from '@platformatic/config'
|
|
5
5
|
import { OpenAPI } from 'openapi-types'
|
|
6
6
|
import type { MercuriusPlugin } from 'mercurius'
|
|
7
7
|
import { PlatformaticService } from './config'
|
|
8
8
|
|
|
9
|
+
declare module 'fastify' {
|
|
10
|
+
interface FastifyInstance {
|
|
11
|
+
platformatic: PlatformaticApp<PlatformaticService>
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
const server = await buildServer({
|
|
10
16
|
})
|
|
11
17
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { join, dirname } from 'path'
|
|
2
|
+
import { createRequire } from 'module'
|
|
3
|
+
import { writeFile } from 'fs/promises'
|
|
4
|
+
import pino from 'pino'
|
|
5
|
+
import pretty from 'pino-pretty'
|
|
6
|
+
import { loadConfig } from '@platformatic/config'
|
|
7
|
+
import { platformaticService } from '../index.js'
|
|
8
|
+
import { checkForDependencies } from '@platformatic/utils'
|
|
9
|
+
|
|
10
|
+
const GLOBAL_TYPES_TEMPLATE = `
|
|
11
|
+
import { FastifyInstance } from 'fastify'
|
|
12
|
+
import { PlatformaticApp, PlatformaticServiceConfig } from '@platformatic/service'
|
|
13
|
+
|
|
14
|
+
declare module 'fastify' {
|
|
15
|
+
interface FastifyInstance {
|
|
16
|
+
platformatic: PlatformaticApp<PlatformaticServiceConfig>
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`
|
|
20
|
+
async function execute ({ logger, configManager }) {
|
|
21
|
+
const fileNameOrThen = join(dirname(configManager.fullPath), 'global.d.ts')
|
|
22
|
+
await writeFile(fileNameOrThen, GLOBAL_TYPES_TEMPLATE)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function generateTypes (_args) {
|
|
26
|
+
const logger = pino(pretty({
|
|
27
|
+
translateTime: 'SYS:HH:MM:ss',
|
|
28
|
+
ignore: 'hostname,pid'
|
|
29
|
+
}))
|
|
30
|
+
|
|
31
|
+
const { configManager, args } = await loadConfig({}, _args, platformaticService)
|
|
32
|
+
|
|
33
|
+
await configManager.parseAndValidate()
|
|
34
|
+
const config = configManager.current
|
|
35
|
+
|
|
36
|
+
await execute({ logger, configManager })
|
|
37
|
+
await checkForDependencies(logger, args, createRequire(import.meta.url), config, ['@platformatic/service'])
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { execute, generateTypes }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -65,12 +65,11 @@
|
|
|
65
65
|
"pino-pretty": "^10.0.0",
|
|
66
66
|
"rfdc": "^1.3.0",
|
|
67
67
|
"ua-parser-js": "^1.0.35",
|
|
68
|
-
"@platformatic/client": "0.
|
|
69
|
-
"@platformatic/config": "0.
|
|
70
|
-
"@platformatic/swagger-ui-theme": "0.
|
|
71
|
-
"@platformatic/
|
|
72
|
-
"@platformatic/
|
|
73
|
-
"@platformatic/telemetry": "0.43.1"
|
|
68
|
+
"@platformatic/client": "0.44.0",
|
|
69
|
+
"@platformatic/config": "0.44.0",
|
|
70
|
+
"@platformatic/swagger-ui-theme": "0.44.0",
|
|
71
|
+
"@platformatic/utils": "0.44.0",
|
|
72
|
+
"@platformatic/telemetry": "0.44.0"
|
|
74
73
|
},
|
|
75
74
|
"standard": {
|
|
76
75
|
"ignore": [
|
package/service.mjs
CHANGED
|
@@ -6,7 +6,9 @@ import isMain from 'es-main'
|
|
|
6
6
|
import helpMe from 'help-me'
|
|
7
7
|
import { readFile } from 'fs/promises'
|
|
8
8
|
import { join } from 'desm'
|
|
9
|
+
import { printAndExitLoadConfigError } from '@platformatic/config'
|
|
9
10
|
import { generateJsonSchemaConfig } from './lib/gen-schema.js'
|
|
11
|
+
import { generateTypes } from './lib/gen-types.mjs'
|
|
10
12
|
|
|
11
13
|
import { buildCompileCmd } from './lib/compile.js'
|
|
12
14
|
|
|
@@ -18,20 +20,30 @@ const help = helpMe({
|
|
|
18
20
|
ext: '.txt'
|
|
19
21
|
})
|
|
20
22
|
|
|
23
|
+
function wrapCommand (fn) {
|
|
24
|
+
return async function (...args) {
|
|
25
|
+
try {
|
|
26
|
+
return await fn(...args)
|
|
27
|
+
/* c8 ignore next 3 */
|
|
28
|
+
} catch (err) {
|
|
29
|
+
printAndExitLoadConfigError(err)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
21
34
|
const program = commist({ maxDistance: 2 })
|
|
22
35
|
|
|
23
36
|
program.register('help', help.toStdout)
|
|
24
37
|
program.register('help start', help.toStdout.bind(null, ['start']))
|
|
25
38
|
|
|
26
39
|
program.register('start', (argv) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.error(err)
|
|
30
|
-
process.exit(1)
|
|
31
|
-
})
|
|
40
|
+
/* c8 ignore next 1 */
|
|
41
|
+
start(platformaticService, argv).catch(printAndExitLoadConfigError)
|
|
32
42
|
})
|
|
43
|
+
|
|
33
44
|
program.register('compile', buildCompileCmd(platformaticService))
|
|
34
|
-
program.register('
|
|
45
|
+
program.register('types', wrapCommand(generateTypes))
|
|
46
|
+
program.register('schema config', wrapCommand(generateJsonSchemaConfig))
|
|
35
47
|
program.register('schema', help.toStdout.bind(null, ['schema']))
|
|
36
48
|
|
|
37
49
|
export async function runService (argv) {
|
|
@@ -498,3 +498,34 @@ t.test('should not compile typescript plugin with start without tsconfig', async
|
|
|
498
498
|
t.equal(err.stdout.includes('No typescript configuration file was found, skipping compilation.'), true)
|
|
499
499
|
}
|
|
500
500
|
})
|
|
501
|
+
|
|
502
|
+
t.test('should compile ts app with config', async (t) => {
|
|
503
|
+
const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'hello-ts-with-config')
|
|
504
|
+
const cwd = await getCWD(t)
|
|
505
|
+
|
|
506
|
+
await cp(testDir, cwd, { recursive: true })
|
|
507
|
+
|
|
508
|
+
const child = execa('node', [cliPath, 'compile'], { cwd })
|
|
509
|
+
|
|
510
|
+
t.teardown(exitOnTeardown(child))
|
|
511
|
+
|
|
512
|
+
const splitter = split()
|
|
513
|
+
child.stdout.pipe(splitter)
|
|
514
|
+
|
|
515
|
+
for await (const data of splitter) {
|
|
516
|
+
const sanitized = stripAnsi(data)
|
|
517
|
+
if (sanitized.includes('Typescript compilation completed successfully.')) {
|
|
518
|
+
const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
|
|
519
|
+
try {
|
|
520
|
+
await access(jsPluginPath)
|
|
521
|
+
} catch (err) {
|
|
522
|
+
t.fail(err)
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
t.pass()
|
|
526
|
+
return
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
t.fail('should compile typescript plugin with a compile command')
|
|
531
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cliPath } from './helper.mjs'
|
|
2
|
+
import { test } from 'tap'
|
|
3
|
+
import { join } from 'desm'
|
|
4
|
+
import { execa } from 'execa'
|
|
5
|
+
import { readFile, unlink } from 'fs/promises'
|
|
6
|
+
|
|
7
|
+
const GLOBAL_TYPES_TEMPLATE = `
|
|
8
|
+
import { FastifyInstance } from 'fastify'
|
|
9
|
+
import { PlatformaticApp, PlatformaticServiceConfig } from '@platformatic/service'
|
|
10
|
+
|
|
11
|
+
declare module 'fastify' {
|
|
12
|
+
interface FastifyInstance {
|
|
13
|
+
platformatic: PlatformaticApp<PlatformaticServiceConfig>
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`
|
|
17
|
+
|
|
18
|
+
test('generate global.d.ts', async ({ equal }) => {
|
|
19
|
+
const fileNameOrThen = join(import.meta.url, '..', '..', 'fixtures', 'hello', 'global.d.ts')
|
|
20
|
+
try {
|
|
21
|
+
await unlink(fileNameOrThen)
|
|
22
|
+
} catch {}
|
|
23
|
+
|
|
24
|
+
await execa('node', [cliPath, 'types', '-c', join(import.meta.url, '..', '..', 'fixtures', 'hello', 'platformatic.service.json')])
|
|
25
|
+
|
|
26
|
+
const data = await readFile(fileNameOrThen, 'utf-8')
|
|
27
|
+
await unlink(fileNameOrThen)
|
|
28
|
+
|
|
29
|
+
equal(data, GLOBAL_TYPES_TEMPLATE)
|
|
30
|
+
})
|
|
@@ -3,6 +3,7 @@ import { test } from 'tap'
|
|
|
3
3
|
import { join } from 'desm'
|
|
4
4
|
import { readFile } from 'fs/promises'
|
|
5
5
|
import { execa } from 'execa'
|
|
6
|
+
import stripAnsi from 'strip-ansi'
|
|
6
7
|
|
|
7
8
|
const version = JSON.parse(await readFile(join(import.meta.url, '..', '..', 'package.json'))).version
|
|
8
9
|
|
|
@@ -21,7 +22,7 @@ test('print validation errors', async ({ equal, plan }) => {
|
|
|
21
22
|
await execa('node', [cliPath, 'start', '--config', join(import.meta.url, '..', 'fixtures', 'missing-property.config.json')])
|
|
22
23
|
} catch (err) {
|
|
23
24
|
equal(err.exitCode, 1)
|
|
24
|
-
equal(err.stdout, `
|
|
25
|
+
equal(stripAnsi(err.stdout), `
|
|
25
26
|
┌─────────┬──────┬─────────────────────────────────────────────────────────────────────┐
|
|
26
27
|
│ (index) │ path │ message │
|
|
27
28
|
├─────────┼──────┼─────────────────────────────────────────────────────────────────────┤
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"target": "es2020",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"sourceMap": false,
|
|
8
|
+
"incremental": true,
|
|
9
|
+
"pretty": true,
|
|
10
|
+
"noEmitOnError": true,
|
|
11
|
+
"outDir": "dist"
|
|
12
|
+
},
|
|
13
|
+
"watchOptions": {
|
|
14
|
+
"watchFile": "fixedPollingInterval",
|
|
15
|
+
"watchDirectory": "fixedPollingInterval",
|
|
16
|
+
"fallbackPolling": "dynamicPriority",
|
|
17
|
+
"synchronousWatchDirectory": true,
|
|
18
|
+
"excludeDirectories": [
|
|
19
|
+
"**/node_modules",
|
|
20
|
+
"dist"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|