massimo-cli 0.0.1 → 0.1.2
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/LICENSE +201 -0
- package/NOTICE +13 -0
- package/README.md +13 -0
- package/eslint.config.js +3 -0
- package/help/help.txt +79 -0
- package/index.d.ts +18 -0
- package/index.js +537 -0
- package/index.test-d.ts +15 -0
- package/lib/errors.js +6 -0
- package/lib/frontend-openapi-generator.js +450 -0
- package/lib/get-type.js +146 -0
- package/lib/graphql-generator.js +136 -0
- package/lib/openapi-common.js +281 -0
- package/lib/openapi-generator.js +153 -0
- package/lib/responses-writer.js +91 -0
- package/lib/utils.js +119 -0
- package/package.json +77 -8
package/lib/utils.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import camelcase from 'camelcase'
|
|
2
|
+
import { readFile, writeFile } from 'fs/promises'
|
|
3
|
+
import { join } from 'path'
|
|
4
|
+
|
|
5
|
+
export function capitalize (str) {
|
|
6
|
+
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function classCase (str) {
|
|
10
|
+
return str
|
|
11
|
+
.split(/[^a-z]+/i)
|
|
12
|
+
.map(s => capitalize(s))
|
|
13
|
+
.join('')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function appendToEnv (file, key, value) {
|
|
17
|
+
try {
|
|
18
|
+
const env = await readFile(file, 'utf8')
|
|
19
|
+
if (env.includes(`${key}=`)) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
// ignore error, file does not exist
|
|
24
|
+
}
|
|
25
|
+
const str = `\n${key}=${value}\n`
|
|
26
|
+
try {
|
|
27
|
+
await writeFile(file, str, { flag: 'a' })
|
|
28
|
+
/* c8 ignore next 1 */
|
|
29
|
+
} catch {}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function appendToBothEnvs (dir, key, value) {
|
|
33
|
+
await Promise.all([appendToEnv(join(dir, '.env'), key, value), appendToEnv(join(dir, '.env.sample'), key, value)])
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function toJavaScriptName (str) {
|
|
37
|
+
return camelcase(str.replace(/[^a-zA-Z0-9]+/gi, ' '))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getResponseContentType (responseObject) {
|
|
41
|
+
if (!responseObject || responseObject.content === undefined) {
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const [firstContentType] = Object.entries(responseObject.content)
|
|
46
|
+
return firstContentType[0]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function is200JsonResponse (responses) {
|
|
50
|
+
const successResponsesCodes = Object.keys(responses).filter(r => r.startsWith('2'))
|
|
51
|
+
for (const code of successResponsesCodes) {
|
|
52
|
+
if (responses[code] && responses[code].content && responses[code].content['application/json']) {
|
|
53
|
+
return true
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getAllResponseCodes (responses) {
|
|
61
|
+
return Object.keys(responses).map(code => {
|
|
62
|
+
return parseInt(code)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getResponseTypes (responses) {
|
|
67
|
+
const output = {
|
|
68
|
+
text: [],
|
|
69
|
+
blob: [],
|
|
70
|
+
json: []
|
|
71
|
+
}
|
|
72
|
+
Object.keys(responses).forEach(code => {
|
|
73
|
+
const resp = responses[code]
|
|
74
|
+
const intCode = parseInt(code)
|
|
75
|
+
if (resp.content) {
|
|
76
|
+
// get all type of contents
|
|
77
|
+
Object.keys(resp.content).forEach(contentType => {
|
|
78
|
+
if (contentType === 'application/json') {
|
|
79
|
+
output.json.push(intCode)
|
|
80
|
+
} else if (contentType.startsWith('text/')) {
|
|
81
|
+
output.text.push(intCode)
|
|
82
|
+
} else {
|
|
83
|
+
const respSchema = resp.content[contentType].schema
|
|
84
|
+
if (respSchema.type && respSchema.type === 'string' && respSchema.format === 'binary') {
|
|
85
|
+
output.blob.push(intCode)
|
|
86
|
+
} else {
|
|
87
|
+
output.text.push(intCode)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
} else {
|
|
92
|
+
output.text.push(intCode)
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
return output
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Returns the type of the request body which can be 'object', 'array', 'plain' or 'empty'
|
|
100
|
+
* @param {object} requestBodyBlock The requestBody OpenAPI spec block
|
|
101
|
+
*/
|
|
102
|
+
export function getBodyType (requestBodyBlock) {
|
|
103
|
+
if (requestBodyBlock === undefined) {
|
|
104
|
+
return 'empty'
|
|
105
|
+
}
|
|
106
|
+
if (requestBodyBlock.content && requestBodyBlock.content['application/json']) {
|
|
107
|
+
const schema = requestBodyBlock.content['application/json'].schema
|
|
108
|
+
if (schema.$ref) {
|
|
109
|
+
return 'object'
|
|
110
|
+
}
|
|
111
|
+
if (schema.type === 'array') {
|
|
112
|
+
return 'array'
|
|
113
|
+
}
|
|
114
|
+
if (schema.type === 'object') {
|
|
115
|
+
return 'object'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return 'plain'
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,81 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "massimo-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "A client for HTTP services.",
|
|
4
5
|
"main": "index.js",
|
|
5
|
-
"
|
|
6
|
-
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"massimo": "index.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/platformatic/massimo.git"
|
|
14
|
+
},
|
|
15
|
+
"author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/platformatic/massimo/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/platformatic/massimo#readme",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@fastify/error": "^4.0.0",
|
|
23
|
+
"camelcase": "~6.3.0",
|
|
24
|
+
"code-block-writer": "^13.0.1",
|
|
25
|
+
"graphql": "^16.8.1",
|
|
26
|
+
"help-me": "^5.0.0",
|
|
27
|
+
"jsonpointer": "^5.0.1",
|
|
28
|
+
"minimist": "^1.2.8",
|
|
29
|
+
"pino": "^9.9.0",
|
|
30
|
+
"pino-pretty": "^13.0.0",
|
|
31
|
+
"undici": "^7.0.0",
|
|
32
|
+
"yaml": "^2.4.1",
|
|
33
|
+
"@platformatic/massimo": "npm:massimo@0.1.2"
|
|
7
34
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@platformatic/composer": "3.0.0-alpha.6",
|
|
37
|
+
"@platformatic/db": "3.0.0-alpha.6",
|
|
38
|
+
"@platformatic/foundation": "3.0.0-alpha.6",
|
|
39
|
+
"@platformatic/runtime": "3.0.0-alpha.6",
|
|
40
|
+
"@platformatic/service": "3.0.0-alpha.6",
|
|
41
|
+
"@platformatic/sql-graphql": "3.0.0-alpha.6",
|
|
42
|
+
"@platformatic/sql-mapper": "3.0.0-alpha.6",
|
|
43
|
+
"@playwright/test": "^1.42.1",
|
|
44
|
+
"@types/react": "^19.1.6",
|
|
45
|
+
"@types/react-dom": "^19.1.5",
|
|
46
|
+
"@vitejs/plugin-react": "^4.5.2",
|
|
47
|
+
"cleaner-spec-reporter": "^0.5.0",
|
|
48
|
+
"dotenv": "^16.4.5",
|
|
49
|
+
"eslint": "9",
|
|
50
|
+
"execa": "^9.0.0",
|
|
51
|
+
"fastify": "^5.0.0",
|
|
52
|
+
"fastify-tsconfig": "^3.0.0",
|
|
53
|
+
"fs-extra": "^11.2.0",
|
|
54
|
+
"neostandard": "^0.12.0",
|
|
55
|
+
"react": "^19.1.0",
|
|
56
|
+
"react-dom": "^19.1.0",
|
|
57
|
+
"scheduler": "^0.26.0",
|
|
58
|
+
"split2": "^4.2.0",
|
|
59
|
+
"tsd": "^0.32.0",
|
|
60
|
+
"typescript": "^5.5.4",
|
|
61
|
+
"vite": "^5.1.6",
|
|
62
|
+
"wattpm": "3.0.0-alpha.5",
|
|
63
|
+
"why-is-node-running": "^2.2.2"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=22.18.0"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"lint": "eslint",
|
|
70
|
+
"test": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/**/*.test.js",
|
|
71
|
+
"posttest": "tsd",
|
|
72
|
+
"pree2e:test": "npm run e2e:prepare",
|
|
73
|
+
"e2e:test": "playwright test -c test/e2e/playwright.config.js && cd test/e2e && tsc --noEmit -p .",
|
|
74
|
+
"e2e:prepare": "node test/e2e/prepare.js",
|
|
75
|
+
"e2e:dev": "vite test/e2e/client",
|
|
76
|
+
"e2e:server": "wattpm start --config platformatic.e2e.db.json test/e2e/server",
|
|
77
|
+
"e2e:build": "npm run e2e:prepare && vite build test/e2e/client",
|
|
78
|
+
"e2e:preview": "vite preview test/e2e/client",
|
|
79
|
+
"e2e:cleanup": "rm -rf test/e2e/client/dist test/e2e/client/src/generated test/e2e/server/db.sqlite playwright-report test-results"
|
|
80
|
+
}
|
|
81
|
+
}
|