Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function reifyDefault(
schema: ISettingRegistry.IProperty,
root?: string
): JSONValue | undefined {
// If the property is at the root level, traverse its schema.
schema = (root ? schema.properties?.[root] : schema) || {};
// If the property has no default or is a primitive, return.
if (!('default' in schema) || schema.type !== 'object') {
return schema.default;
}
// Make a copy of the default value to populate.
const result = JSONExt.deepCopy(schema.default);
// Iterate through and populate each child property.
const props = schema.properties || {};
for (let property in props) {
result[property] = reifyDefault(props[property]);
}
return result;
}
}
it('should update list of kernel specs', async () => {
const manager = new TestManager({ standby: 'never' });
const specs = JSONExt.deepCopy(KERNELSPECS) as KernelSpec.ISpecModels;
await manager.ready;
specs.default = 'shell';
manager.intercept = specs;
expect(manager.specs!.default).not.to.equal('shell');
await manager.refreshSpecs();
expect(manager.specs!.default).to.equal('shell');
});
});
it('should update list of kernel specs', async () => {
const manager = new TestManager({ standby: 'never' });
const specs = JSONExt.deepCopy(KERNELSPECS) as Kernel.ISpecModels;
await manager.ready;
specs.default = 'shell';
manager.intercept = specs;
expect(manager.specs.default).not.to.equal('shell');
await manager.refreshSpecs();
expect(manager.specs.default).to.equal('shell');
});
});
let trusted = this.modelDB.createValue('trusted');
trusted.changed.connect(this.onTrustedChanged, this);
if (!cell) {
trusted.set(false);
return;
}
trusted.set(!!cell.metadata['trusted']);
delete cell.metadata['trusted'];
if (Array.isArray(cell.source)) {
this.value.text = (cell.source as string[]).join('');
} else {
this.value.text = cell.source as string;
}
let metadata = JSONExt.deepCopy(cell.metadata);
if (this.type !== 'raw') {
delete metadata['format'];
}
if (this.type !== 'code') {
delete metadata['collapsed'];
delete metadata['scrolled'];
}
for (let key in metadata) {
observableMetadata.set(key, metadata[key]);
}
}
toJSON(): PartialJSONObject {
const out: PartialJSONObject = Object.create(null);
const keys = this.keys();
for (let key of keys) {
const value = this.get(key);
if (value !== undefined) {
out[key] = JSONExt.deepCopy(value) as PartialJSONObject;
}
}
return out;
}
}