MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / processNode

Method processNode

packages/hydrooj/src/settings.ts:104–122  ·  view source on GitHub ↗
(path: string[], node: Schema<any, any>)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

saveConfigMethod · 0.95
applyDeltaMethod · 0.95
processNodeFunction · 0.85
collectionMethod · 0.80
infoMethod · 0.45

Tested by

no test coverage detected