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

@json-layout/vocabulary

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@json-layout/vocabulary - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

2

package.json
{
"name": "@json-layout/vocabulary",
"version": "0.10.0",
"version": "0.11.0",
"description": "Main JSON Layout vocabulary as JSON schemas and Typescript types. Also contains some small utility functions to validate and normalize annotations.",

@@ -5,0 +5,0 @@ "type": "module",

/** @typedef {import("./types.js").SchemaFragment} SchemaFragment */
export * from './layout-keyword/index.js'
export * from './normalized-layout/index.js'
export { normalizeLayoutFragment } from './normalize.js'
export { normalizeLayoutFragment, getSchemaFragmentType } from './normalize.js'

@@ -21,3 +21,3 @@ import { validateLayoutKeyword, isComponentName, isPartialCompObject, isPartialChildren, isPartialSwitch, isPartialGetItemsExpr, isPartialGetItemsObj, isPartialSlotMarkdown, isPartialGetItemsFetch } from './layout-keyword/index.js'

function getDefaultChildren (schemaFragment) {
const { type } = getType(schemaFragment)
const { type } = getSchemaFragmentType(schemaFragment)
/** @type {Children} */

@@ -91,4 +91,4 @@ const children = []

function getDefaultComp (partial, schemaFragment, arrayChild) {
const { type } = getType(schemaFragment)
const hasSimpleType = ['string', 'integer', 'number'].includes(type)
const { type } = getSchemaFragmentType(schemaFragment)
const hasSimpleType = type && ['string', 'integer', 'number'].includes(type)
if (arrayChild === 'oneOf') return 'one-of-select'

@@ -167,4 +167,4 @@ if (hasSimpleType && schemaFragment.enum) return schemaFragment.enum.length > 20 ? 'autocomplete' : 'select'

if (!schemaFragment) return null
const { type } = getType(schemaFragment)
const hasSimpleType = ['string', 'integer', 'number'].includes(type)
const { type } = getSchemaFragmentType(schemaFragment)
const hasSimpleType = type && ['string', 'integer', 'number'].includes(type)
if (schemaFragment.enum && hasSimpleType) {

@@ -200,5 +200,5 @@ return schemaFragment.enum.map((/** @type {string} */ value) => ({ key: value + '', title: value + '', value }))

* @param {SchemaFragment} schemaFragment
* @returns {{type: string, nullable: boolean}}
* @returns {{type: string | undefined, nullable: boolean}}
*/
const getType = (schemaFragment) => {
export const getSchemaFragmentType = (schemaFragment) => {
if (Array.isArray(schemaFragment.type) && schemaFragment.type.length === 2 && schemaFragment.type.includes('null')) {

@@ -208,2 +208,25 @@ const type = schemaFragment.type.find(t => t !== 'null')

}
if (!schemaFragment.type && schemaFragment.properties) {
return { type: 'object', nullable: false }
}
// case where type is not defined but can be deduced from children oneOf/allOf/anyOf
/** @type {any[]} */
if (!schemaFragment.type) {
/** @type {string[]} */
const combinationTypes = []
for (const combinationKey of ['allOf', 'anyOf', 'oneOf']) {
// @ts-ignore
if (schemaFragment[combinationKey]) {
// @ts-ignore
for (const subSchema of schemaFragment[combinationKey]) {
const { type: subType } = getSchemaFragmentType(subSchema)
if (subType && !combinationTypes.includes(subType)) combinationTypes.push(subType)
}
}
}
if (combinationTypes.length === 1) return { type: combinationTypes[0], nullable: false }
}
return { type: schemaFragment.type, nullable: false }

@@ -226,3 +249,3 @@ }

const { type, nullable } = getType(schemaFragment)
const { type, nullable } = getSchemaFragmentType(schemaFragment)

@@ -229,0 +252,0 @@ if ('const' in schemaFragment) return { normalized: { comp: 'none' }, errors }

export * from "./layout-keyword/index.js";
export * from "./normalized-layout/index.js";
export { normalizeLayoutFragment } from "./normalize.js";
export type SchemaFragment = import("./types.js").SchemaFragment;
export { normalizeLayoutFragment, getSchemaFragmentType } from "./normalize.js";
//# sourceMappingURL=index.d.ts.map

@@ -13,2 +13,6 @@ /**

};
export function getSchemaFragmentType(schemaFragment: SchemaFragment): {
type: string | undefined;
nullable: boolean;
};
export type Child = import('./index.js').Child;

@@ -15,0 +19,0 @@ export type Children = import('./index.js').Children;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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