(path: string[], node: Schema<any, any>)
| 102 | |
| 103 | async _actualMigrate(schema: Schema<any>) { |
| 104 | const processNode = async (path: string[], node: Schema<any, any>) => { |
| 105 | for (const item of node.list || []) await processNode(path, item); // eslint-disable-line no-await-in-loop |
| 106 | for (const key in node.dict || {}) await processNode([...path, ...key], node.dict[key]); // eslint-disable-line no-await-in-loop |
| 107 | if (['string', 'number', 'boolean'].includes(node.type)) { |
| 108 | const value = this.initialValues[path.join('.')]; |
| 109 | const migrated = this.initialValues[`${path.join('.')}__migrated`]; |
| 110 | if (migrated || !Object.hasOwn(this.initialValues, path.join('.'))) return; |
| 111 | let parsed; |
| 112 | try { |
| 113 | if (node.type === 'string') parsed = value; |
| 114 | if (node.type === 'number') parsed = +value; |
| 115 | if (node.type === 'boolean') parsed = !!value && !['off', '0', 'false'].includes(value); |
| 116 | } catch (e) { } |
| 117 | if (parsed === undefined) return; |
| 118 | await this.ctx.db.collection('system').updateOne({ _id: `${path.join('.')}__migrated` }, { $set: { value: true } }, { upsert: true }); |
| 119 | this.ctx.logger.info('Migrating %s: %o', path.join('.'), parsed); |
| 120 | await this.saveConfig(this.applyDelta(this.systemConfig, path.join('.'), parsed)); |
| 121 | } |
| 122 | }; |
| 123 | await processNode([], schema); |
| 124 | } |
| 125 |
nothing calls this directly
no test coverage detected