Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@platformatic/metaconfig

Package Overview
Dependencies
Maintainers
6
Versions
128
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@platformatic/metaconfig - npm Package Compare versions

Comparing version 0.21.1 to 0.22.0

test/from-eighteen-to-will-see.test.js

33

metaconfig.js

@@ -8,3 +8,10 @@ 'use strict'

const JSON5 = require('json5')
const semver = require('semver')
const FromZeroEighteenToWillSee = require('./versions/from-zero-eighteen-to-will-see.js')
const ranges = [{
range: '>= 0.18.x < 1.0.0',
handler: FromZeroEighteenToWillSee
}]
async function analyze (opts) {

@@ -33,3 +40,5 @@ let data

Handler = require('./versions/0.16.0.js')
} else {
}
if (!Handler) {
const url = new URL(data.$schema)

@@ -48,5 +57,14 @@ const res = url.pathname.match(/^\/schemas\/v(\d+)\.(\d+)\.(\d+)\/(.*)$/)

version = `${major}.${minor}.${patch}`
for (const { range, handler } of ranges) {
if (semver.satisfies(version, range)) {
Handler = handler
break
}
}
try {
// try to load the exact version
Handler = require(`./versions/${major}.${minor}.${patch}.js`)
Handler ||= require(`./versions/${major}.${minor}.${patch}.js`)
} catch {}

@@ -64,4 +82,2 @@

version = `${major}.${minor}.${patch}`
if (!Handler) {

@@ -122,1 +138,10 @@ throw new Error('unable to determine the version')

module.exports.write = write
function upgrade (meta) {
while (typeof meta.up === 'function') {
meta = meta.up()
}
return meta
}
module.exports.upgrade = upgrade

5

package.json
{
"name": "@platformatic/metaconfig",
"version": "0.21.1",
"version": "0.22.0",
"main": "metaconfig.js",

@@ -24,3 +24,4 @@ "description": "Manage mulitple configuration versions at the same time",

"rfdc": "^1.3.0",
"yaml": "^2.2.1"
"semver": "^7.5.0",
"yaml": "^2.2.2"
},

@@ -27,0 +28,0 @@ "scripts": {

@@ -14,3 +14,3 @@ # @platformatic/metaconfig

```javascript
import { analyze, write } from '@platformatic/metaconfig'
import { analyze, write, upgrade } from '@platformatic/metaconfig'

@@ -24,4 +24,4 @@ const meta = await analyze({ file: 'path/to/platformatic.db.json' }))

// Bring it to the next version
const metaNext = meta.up()
// Bring it to the latest version
const metaNext = upgrade(meta)

@@ -28,0 +28,0 @@ console.log(metaNext.version)

'use strict'
const { test } = require('tap')
const { analyze, getParser, getStringifier, write } = require('..')
const { analyze, getParser, getStringifier, write, upgrade } = require('..')
const ZeroSeventeen = require('../versions/0.17.x.js')

@@ -13,2 +13,3 @@ const YAML = require('yaml')

const pkg = require('../package.json')
const semver = require('semver')

@@ -88,1 +89,10 @@ test('throws if no config or file is provided', async (t) => {

})
test('upgrade to latest version', async (t) => {
const file = join(__dirname, 'fixtures', 'v0.16.0', 'array.db.json')
const meta = await analyze({ file })
const upgraded = upgrade(meta)
const version = pkg.version.replace('-dev', '')
t.comment(`upgraded to ${upgraded.version}`)
t.equal(semver.satisfies(version, '^' + upgraded.version), true)
})
{
"$schema": "https://platformatic.dev/schemas/v0.18.0/db",
"$schema": "https://platformatic.dev/schemas/v0.18.0/service",
"server": {

@@ -4,0 +4,0 @@ "hostname": "{PLT_SERVER_HOSTNAME}",

@@ -22,3 +22,2 @@ 'use strict'

const config = rfdc(original)
config.$schema = `https://platformatic.dev/schemas/v0.18.0/${this.kind}`

@@ -30,5 +29,5 @@ if (this.kind === 'db') {

const NewClass = require('./0.18.x.js')
const NewClass = require('./from-zero-eighteen-to-will-see')
return new NewClass({ config, path: this.path, format: this.format })
return new NewClass({ config, path: this.path, format: this.format, version: '0.18.0' })
}

@@ -35,0 +34,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc