@platformatic/sql-json-schema-mapper 0.8.0 → 0.9.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/.nyc_output/{e67c9e41-1f24-460e-9d74-6a0d2ffd0c2f.json → 758081ea-bea3-4057-9ffe-d39ca896e75c.json} +0 -0
- package/.nyc_output/92438563-64d7-498c-bcea-54ec448f5406.json +1 -0
- package/.nyc_output/processinfo/758081ea-bea3-4057-9ffe-d39ca896e75c.json +1 -0
- package/.nyc_output/processinfo/{77a51ed1-28eb-4f3a-81ac-882440355c34.json → 92438563-64d7-498c-bcea-54ec448f5406.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/index.js +4 -1
- package/package.json +2 -2
- package/test/simple.test.js +42 -0
- package/.nyc_output/77a51ed1-28eb-4f3a-81ac-882440355c34.json +0 -1
- package/.nyc_output/processinfo/e67c9e41-1f24-460e-9d74-6a0d2ffd0c2f.json +0 -1
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js":{"path":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js","statementMap":{"0":{"start":{"line":57,"column":17},"end":{"line":57,"column":30}},"1":{"start":{"line":58,"column":21},"end":{"line":58,"column":23}},"2":{"start":{"line":59,"column":19},"end":{"line":59,"column":21}},"3":{"start":{"line":60,"column":2},"end":{"line":86,"column":3}},"4":{"start":{"line":61,"column":18},"end":{"line":61,"column":30}},"5":{"start":{"line":62,"column":4},"end":{"line":64,"column":5}},"6":{"start":{"line":63,"column":6},"end":{"line":63,"column":14}},"7":{"start":{"line":65,"column":17},"end":{"line":65,"column":55}},"8":{"start":{"line":75,"column":4},"end":{"line":77,"column":5}},"9":{"start":{"line":76,"column":6},"end":{"line":76,"column":49}},"10":{"start":{"line":78,"column":4},"end":{"line":81,"column":5}},"11":{"start":{"line":80,"column":6},"end":{"line":80,"column":36}},"12":{"start":{"line":87,"column":2},"end":{"line":94,"column":3}},"13":{"start":{"line":97,"column":0},"end":{"line":97,"column":70}}},"fnMap":{"0":{"name":"mapSQLTypeToOpenAPIType","decl":{"start":{"line":3,"column":9},"end":{"line":3,"column":32}},"loc":{"start":{"line":3,"column":43},"end":{"line":54,"column":1}},"line":3},"1":{"name":"mapSQLEntityToJSONSchema","decl":{"start":{"line":56,"column":9},"end":{"line":56,"column":33}},"loc":{"start":{"line":56,"column":56},"end":{"line":95,"column":1}},"line":56}},"branchMap":{"0":{"loc":{"start":{"line":56,"column":43},"end":{"line":56,"column":54}},"type":"default-arg","locations":[{"start":{"line":56,"column":52},"end":{"line":56,"column":54}}],"line":56},"1":{"loc":{"start":{"line":62,"column":4},"end":{"line":64,"column":5}},"type":"if","locations":[{"start":{"line":62,"column":4},"end":{"line":64,"column":5}},{"start":{"line":62,"column":4},"end":{"line":64,"column":5}}],"line":62},"2":{"loc":{"start":{"line":75,"column":4},"end":{"line":77,"column":5}},"type":"if","locations":[{"start":{"line":75,"column":4},"end":{"line":77,"column":5}},{"start":{"line":75,"column":4},"end":{"line":77,"column":5}}],"line":75},"3":{"loc":{"start":{"line":78,"column":4},"end":{"line":81,"column":5}},"type":"if","locations":[{"start":{"line":78,"column":4},"end":{"line":81,"column":5}},{"start":{"line":78,"column":4},"end":{"line":81,"column":5}}],"line":78},"4":{"loc":{"start":{"line":78,"column":8},"end":{"line":78,"column":46}},"type":"binary-expr","locations":[{"start":{"line":78,"column":8},"end":{"line":78,"column":25}},{"start":{"line":78,"column":29},"end":{"line":78,"column":46}}],"line":78}},"s":{"0":2,"1":2,"2":2,"3":2,"4":8,"5":8,"6":1,"7":7,"8":7,"9":4,"10":7,"11":1,"12":2,"13":1},"f":{"0":7,"1":2},"b":{"0":[1],"1":[1,7],"2":[4,3],"3":[1,6],"4":[7,3]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"4430f646fe7dfb608e2b1b25d741d4d1ab027c5e","contentHash":"d836a17cae63d39df8cfea3f234f56537a178db1ef6432b888dd2e9ae6aa2752"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":86244,"argv":["/Users/matteo/.nvm/versions/node/v16.17.0/bin/node","/Users/matteo/Repositories/platformatic/node_modules/.pnpm/tap@16.3.2/node_modules/tap/bin/run.js","test/simple.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper","time":1669802016344,"ppid":86237,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/.nyc_output/758081ea-bea3-4057-9ffe-d39ca896e75c.json","externalId":"","uuid":"758081ea-bea3-4057-9ffe-d39ca896e75c","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"758081ea-bea3-4057-9ffe-d39ca896e75c","pid":86246,"argv":["/Users/matteo/.nvm/versions/node/v16.17.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/test/simple.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper","time":1669802016745,"ppid":86244,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/.nyc_output/92438563-64d7-498c-bcea-54ec448f5406.json","externalId":"test/simple.test.js","uuid":"92438563-64d7-498c-bcea-54ec448f5406","files":["/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"758081ea-bea3-4057-9ffe-d39ca896e75c":{"parent":null,"children":["92438563-64d7-498c-bcea-54ec448f5406"]},"92438563-64d7-498c-bcea-54ec448f5406":{"parent":"758081ea-bea3-4057-9ffe-d39ca896e75c","externalId":"test/simple.test.js","children":[]}},"files":{"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js":["92438563-64d7-498c-bcea-54ec448f5406"]},"externalIds":{"test/simple.test.js":{"root":"92438563-64d7-498c-bcea-54ec448f5406","children":[]}}}
|
package/index.js
CHANGED
|
@@ -53,12 +53,15 @@ function mapSQLTypeToOpenAPIType (sqlType) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
function mapSQLEntityToJSONSchema (entity) {
|
|
56
|
+
function mapSQLEntityToJSONSchema (entity, ignore = {}) {
|
|
57
57
|
const fields = entity.fields
|
|
58
58
|
const properties = {}
|
|
59
59
|
const required = []
|
|
60
60
|
for (const name of Object.keys(fields)) {
|
|
61
61
|
const field = fields[name]
|
|
62
|
+
if (ignore[name] === true) {
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
62
65
|
const type = mapSQLTypeToOpenAPIType(field.sqlType)
|
|
63
66
|
/* istanbul ignore next */
|
|
64
67
|
if (field.sqlType === 'json') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/sql-json-schema-mapper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Map SQL entity to JSON schema",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/platformatic/platformatic#readme",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@platformatic/sql-mapper": "0.
|
|
17
|
+
"@platformatic/sql-mapper": "0.9.0",
|
|
18
18
|
"fastify": "^4.6.0",
|
|
19
19
|
"snazzy": "^9.0.0",
|
|
20
20
|
"standard": "^17.0.0",
|
package/test/simple.test.js
CHANGED
|
@@ -74,3 +74,45 @@ test('simple db, simple rest API', async (t) => {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
})
|
|
77
|
+
|
|
78
|
+
test('ignore one field', async (t) => {
|
|
79
|
+
const { pass, teardown } = t
|
|
80
|
+
|
|
81
|
+
const app = fastify()
|
|
82
|
+
app.register(sqlMapper, {
|
|
83
|
+
...connInfo,
|
|
84
|
+
async onDatabaseLoad (db, sql) {
|
|
85
|
+
pass('onDatabaseLoad called')
|
|
86
|
+
|
|
87
|
+
await clear(db, sql)
|
|
88
|
+
await createBasicPages(db, sql)
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
teardown(app.close.bind(app))
|
|
92
|
+
|
|
93
|
+
await app.ready()
|
|
94
|
+
|
|
95
|
+
{
|
|
96
|
+
const page = app.platformatic.entities.page
|
|
97
|
+
const pageJsonSchema = mapSQLEntityToJSONSchema(page, {
|
|
98
|
+
title: true
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
t.equal(pageJsonSchema.$id, 'Page')
|
|
102
|
+
t.equal(pageJsonSchema.title, 'Page')
|
|
103
|
+
t.equal(pageJsonSchema.description, 'A Page')
|
|
104
|
+
t.equal(pageJsonSchema.type, 'object')
|
|
105
|
+
t.same(pageJsonSchema.properties.id, { type: 'integer' })
|
|
106
|
+
t.equal(pageJsonSchema.properties.title, undefined)
|
|
107
|
+
t.same(pageJsonSchema.properties.description, { type: 'string', nullable: true })
|
|
108
|
+
if (isMariaDB) {
|
|
109
|
+
t.same(pageJsonSchema.properties.metadata, { type: 'string', nullable: true })
|
|
110
|
+
} else {
|
|
111
|
+
t.same(pageJsonSchema.properties.metadata, { type: 'object', additionalProperties: true, nullable: true })
|
|
112
|
+
}
|
|
113
|
+
t.same(pageJsonSchema.required, [])
|
|
114
|
+
if (!isSQLite) {
|
|
115
|
+
t.same(pageJsonSchema.properties.type, { type: 'string', nullable: true, enum: ['blank', 'non-blank'] })
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js":{"path":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js","statementMap":{"0":{"start":{"line":57,"column":17},"end":{"line":57,"column":30}},"1":{"start":{"line":58,"column":21},"end":{"line":58,"column":23}},"2":{"start":{"line":59,"column":19},"end":{"line":59,"column":21}},"3":{"start":{"line":60,"column":2},"end":{"line":83,"column":3}},"4":{"start":{"line":61,"column":18},"end":{"line":61,"column":30}},"5":{"start":{"line":62,"column":17},"end":{"line":62,"column":55}},"6":{"start":{"line":72,"column":4},"end":{"line":74,"column":5}},"7":{"start":{"line":73,"column":6},"end":{"line":73,"column":49}},"8":{"start":{"line":75,"column":4},"end":{"line":78,"column":5}},"9":{"start":{"line":77,"column":6},"end":{"line":77,"column":36}},"10":{"start":{"line":84,"column":2},"end":{"line":91,"column":3}},"11":{"start":{"line":94,"column":0},"end":{"line":94,"column":70}}},"fnMap":{"0":{"name":"mapSQLTypeToOpenAPIType","decl":{"start":{"line":3,"column":9},"end":{"line":3,"column":32}},"loc":{"start":{"line":3,"column":43},"end":{"line":54,"column":1}},"line":3},"1":{"name":"mapSQLEntityToJSONSchema","decl":{"start":{"line":56,"column":9},"end":{"line":56,"column":33}},"loc":{"start":{"line":56,"column":43},"end":{"line":92,"column":1}},"line":56}},"branchMap":{"0":{"loc":{"start":{"line":72,"column":4},"end":{"line":74,"column":5}},"type":"if","locations":[{"start":{"line":72,"column":4},"end":{"line":74,"column":5}},{"start":{"line":72,"column":4},"end":{"line":74,"column":5}}],"line":72},"1":{"loc":{"start":{"line":75,"column":4},"end":{"line":78,"column":5}},"type":"if","locations":[{"start":{"line":75,"column":4},"end":{"line":78,"column":5}},{"start":{"line":75,"column":4},"end":{"line":78,"column":5}}],"line":75},"2":{"loc":{"start":{"line":75,"column":8},"end":{"line":75,"column":46}},"type":"binary-expr","locations":[{"start":{"line":75,"column":8},"end":{"line":75,"column":25}},{"start":{"line":75,"column":29},"end":{"line":75,"column":46}}],"line":75}},"s":{"0":1,"1":1,"2":1,"3":1,"4":4,"5":4,"6":4,"7":2,"8":4,"9":1,"10":1,"11":1},"f":{"0":4,"1":1},"b":{"0":[2,2],"1":[1,3],"2":[4,2]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"fed278c48ca0ed9847356e48af19cb304a81df74","contentHash":"2dc11762e41ce65e7eaf09cad100713a4a81a849ed47a4605d680cd7fbbede02"}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":63725,"argv":["/Users/matteo/.nvm/versions/node/v16.17.0/bin/node","/Users/matteo/Repositories/platformatic/node_modules/.pnpm/tap@16.3.1/node_modules/tap/bin/run.js","test/simple.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper","time":1669240052464,"ppid":63719,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/.nyc_output/e67c9e41-1f24-460e-9d74-6a0d2ffd0c2f.json","externalId":"","uuid":"e67c9e41-1f24-460e-9d74-6a0d2ffd0c2f","files":[]}
|