@platformatic/sql-json-schema-mapper 0.1.0 → 0.2.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.
@@ -0,0 +1 @@
1
+ {"parent":null,"pid":71976,"argv":["/Users/matteo/.nvm/versions/node/v16.17.0/bin/node","/Users/matteo/Repositories/platformatic/node_modules/.pnpm/tap@16.3.0/node_modules/tap/bin/run.js","test/simple.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper","time":1664620517632,"ppid":71970,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/.nyc_output/9d3ac57a-4999-48ee-aad7-ad4f69be52e8.json","externalId":"","uuid":"9d3ac57a-4999-48ee-aad7-ad4f69be52e8","files":[]}
@@ -1 +1 @@
1
- {"parent":"375cd919-4c7b-485d-b4d1-328984a29f7f","pid":98525,"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":1663832193816,"ppid":98522,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/.nyc_output/0e430260-69b7-4ca8-85f2-59e8074eaab5.json","externalId":"test/simple.test.js","uuid":"0e430260-69b7-4ca8-85f2-59e8074eaab5","files":["/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js"]}
1
+ {"parent":"9d3ac57a-4999-48ee-aad7-ad4f69be52e8","pid":71977,"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":1664620517980,"ppid":71976,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/.nyc_output/d742ed64-3762-424c-b671-a7c0db97cf10.json","externalId":"test/simple.test.js","uuid":"d742ed64-3762-424c-b671-a7c0db97cf10","files":["/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js"]}
@@ -1 +1 @@
1
- {"processes":{"0e430260-69b7-4ca8-85f2-59e8074eaab5":{"parent":"375cd919-4c7b-485d-b4d1-328984a29f7f","externalId":"test/simple.test.js","children":[]},"375cd919-4c7b-485d-b4d1-328984a29f7f":{"parent":null,"children":["0e430260-69b7-4ca8-85f2-59e8074eaab5"]}},"files":{"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js":["0e430260-69b7-4ca8-85f2-59e8074eaab5"]},"externalIds":{"test/simple.test.js":{"root":"0e430260-69b7-4ca8-85f2-59e8074eaab5","children":[]}}}
1
+ {"processes":{"9d3ac57a-4999-48ee-aad7-ad4f69be52e8":{"parent":null,"children":["d742ed64-3762-424c-b671-a7c0db97cf10"]},"d742ed64-3762-424c-b671-a7c0db97cf10":{"parent":"9d3ac57a-4999-48ee-aad7-ad4f69be52e8","externalId":"test/simple.test.js","children":[]}},"files":{"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js":["d742ed64-3762-424c-b671-a7c0db97cf10"]},"externalIds":{"test/simple.test.js":{"root":"d742ed64-3762-424c-b671-a7c0db97cf10","children":[]}}}
package/index.js CHANGED
@@ -60,7 +60,15 @@ function mapSQLEntityToJSONSchema (entity) {
60
60
  for (const name of Object.keys(fields)) {
61
61
  const field = fields[name]
62
62
  const type = mapSQLTypeToOpenAPIType(field.sqlType)
63
- properties[field.camelcase] = { type }
63
+ /* istanbul ignore next */
64
+ if (field.sqlType === 'json') {
65
+ properties[field.camelcase] = {
66
+ type: 'object',
67
+ additionalProperties: true
68
+ }
69
+ } else {
70
+ properties[field.camelcase] = { type }
71
+ }
64
72
  if (field.isNullable) {
65
73
  properties[field.camelcase].nullable = true
66
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/sql-json-schema-mapper",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Map SQL entity to JSON schema",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -14,13 +14,14 @@
14
14
  },
15
15
  "homepage": "https://github.com/plaformatic/platformatic#readme",
16
16
  "devDependencies": {
17
- "@platformatic/sql-mapper": "0.1.0",
17
+ "@platformatic/sql-mapper": "0.2.0",
18
18
  "fastify": "^4.6.0",
19
19
  "snazzy": "^9.0.0",
20
20
  "standard": "^17.0.0",
21
21
  "tap": "^16.0.0"
22
22
  },
23
23
  "scripts": {
24
+ "lint": "standard",
24
25
  "test": "standard | snazzy && npm run test:postgresql && npm run test:mariadb && npm run test:mysql && npm run test:mysql8 && npm run test:sqlite",
25
26
  "test:postgresql": "DB=postgresql tap test/*.test.js",
26
27
  "test:mariadb": "DB=mariadb tap test/*.test.js",
package/test/helper.js CHANGED
@@ -13,6 +13,7 @@ if (!process.env.DB || process.env.DB === 'postgresql') {
13
13
  connInfo.connectionString = 'mysql://root@127.0.0.1:3307/graph'
14
14
  connInfo.poolSize = 10
15
15
  module.exports.isMysql = true
16
+ module.exports.isMariaDB = true
16
17
  } else if (process.env.DB === 'mysql') {
17
18
  connInfo.connectionString = 'mysql://root@127.0.0.1/graph'
18
19
  connInfo.poolSize = 10
@@ -3,7 +3,7 @@
3
3
  const t = require('tap')
4
4
  const sqlMapper = require('@platformatic/sql-mapper')
5
5
  const fastify = require('fastify')
6
- const { clear, connInfo, isSQLite } = require('./helper')
6
+ const { clear, connInfo, isSQLite, isMariaDB } = require('./helper')
7
7
  const { mapSQLEntityToJSONSchema } = require('..')
8
8
  const { test } = t
9
9
 
@@ -12,12 +12,14 @@ async function createBasicPages (db, sql) {
12
12
  await db.query(sql`CREATE TABLE pages (
13
13
  id INTEGER PRIMARY KEY,
14
14
  title VARCHAR(42) NOT NULL,
15
+ metadata JSON,
15
16
  description TEXT
16
17
  );`)
17
18
  } else {
18
19
  await db.query(sql`CREATE TABLE pages (
19
20
  id SERIAL PRIMARY KEY,
20
21
  title VARCHAR(42) NOT NULL,
22
+ metadata JSON,
21
23
  description TEXT
22
24
  );`)
23
25
  }
@@ -51,6 +53,11 @@ test('simple db, simple rest API', async (t) => {
51
53
  t.same(pageJsonSchema.properties.id, { type: 'integer' })
52
54
  t.same(pageJsonSchema.properties.title, { type: 'string' })
53
55
  t.same(pageJsonSchema.properties.description, { type: 'string', nullable: true })
56
+ if (isMariaDB) {
57
+ t.same(pageJsonSchema.properties.metadata, { type: 'string', nullable: true })
58
+ } else {
59
+ t.same(pageJsonSchema.properties.metadata, { type: 'object', additionalProperties: true, nullable: true })
60
+ }
54
61
  t.same(pageJsonSchema.required, ['title'])
55
62
  }
56
63
  })
@@ -1 +0,0 @@
1
- {"parent":null,"pid":98522,"argv":["/Users/matteo/.nvm/versions/node/v16.17.0/bin/node","/Users/matteo/Repositories/platformatic/node_modules/.pnpm/tap@16.3.0/node_modules/tap/bin/run.js","test/simple.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper","time":1663832193483,"ppid":98516,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/.nyc_output/375cd919-4c7b-485d-b4d1-328984a29f7f.json","externalId":"","uuid":"375cd919-4c7b-485d-b4d1-328984a29f7f","files":[]}