I want to save a object[]
using electron-store
with JSON Schema
, after reading the doc of JSON Schema
i get the code can be exec successfully but with warning:
strict mode: "items" is 1-tuple, but minItems or maxItems/additionalItems are not specified or different at path "#/properties/todo"
And my code is :
const Store = require('electron-store')
/** @type import('json-schema-typed').JSONSchema */
const schema = {
todo: {
type: 'array',
items: [true],
minItems: 0,
maxItems: 999,
additionalItems: {
type: 'object',
properties: {
id: {
type: 'number'
},
name: {
type: 'string'
}
}
}
}
}
const todoStore = new Store({ schema })
const todoItem = [{ id: 1, name: '11111' }]
todoStore.set('todo', todoItem)
console.log(todoStore.get('todo'))
const newTodo = [...todoStore.get('todo')]
newTodo.push({ id: 2, name: '22222' })
todoStore.set('todo', prev)
console.log(todoStore.get('todo'))
module.exports = todoStore
i add minItems
and maxItems
, but the warning is still appear. I checkout it out for a few hours but can't work. Can anyone help me?
By the way, i want to ask if i use JSON Schema
in right way?
You could install electron-store
and exec it directly with node ./xxx.js
Thx for helping me.