The code imports necessary modules and data, and defines the kernelInfoInterface
object with various properties that provide information about a kernel. The nativeKernelInfo
function takes a kernel_info
object, extends it with additional information, and returns an object with language, kernel, and meta data.
npm run import -- "kernel info interface"
var importer = require('../Core');
var interface = importer.import("enforcing an interface");
var languageInterface = importer.import("kernel language interface");
var PACKAGE_VERSION = require('../package.json').version;
var kernelInfoInterface = {
// from the docs
protocol_version: [void 0, ''],
implementation: [void 0, ''],
implementation_version: [void 0, ''],
banner: [void 0, ''],
language_info: languageInterface,
help_links: [void 0, []],
// custom, path to it's own script for installing
install_config: [void 0, '']
}
function nativeKernelInfo(kernel_info) {
if(!kernel_info) {
return;
}
var {
language_info,
protocol_version,
implementation,
implementation_version,
banner
} = kernel_info; // for easy reading
//if(typeof language_info === 'function')
// kernel_info.language_info = language_info(language_info);
kernel_info.language_info = interface(language_info, languageInterface);
language_info.name = language_info.name || implementation;
var info = interface(kernel_info, kernelInfoInterface)
var self = extend(meta_info, {
protocol_version: protocol_version || '5.1',
implementation: implementation || language_info.name,
implementation_version: implementation_version || PACKAGE_VERSION,
banner: banner || language_info.language
})
return self;
}
module.exports = {
kernelInfoInterface,
nativeKernelInfo
};
// Import required modules and constants
const { importModules } = require('../Core');
const { getKernelInfoInterface, getLanguageInterface } = importModules(['enforcing-an-interface', 'kernel-language-interface']);
const packageJson = require('../package.json');
const { version: PACKAGE_VERSION } = packageJson;
// Define the kernel info interface
const kernelInfoInterface = {
/**
* The protocol version of the kernel.
* @type {string[]}
*/
protocol_version: [null, ''],
/**
* The implementation of the kernel.
* @type {string[]}
*/
implementation: [null, ''],
/**
* The implementation version of the kernel.
* @type {string[]}
*/
implementation_version: [null, ''],
/**
* The banner of the kernel.
* @type {string[]}
*/
banner: [null, ''],
/**
* The language information of the kernel.
* @type {object}
*/
language_info: getLanguageInterface(),
/**
* The help links of the kernel.
* @type {string[][]}
*/
help_links: [null, []],
/**
* The install configuration of the kernel.
* @type {string}
*/
install_config: [null, '']
};
/**
* Returns the native kernel info by enforcing the kernel info interface.
* @param {object} kernel_info - The kernel info object.
* @returns {object} The native kernel info object.
*/
function nativeKernelInfo(kernel_info) {
if (!kernel_info) {
return;
}
// Destructure the kernel info object for easier reading
const {
language_info,
protocol_version,
implementation,
implementation_version,
banner
} = kernel_info;
// Enforce the language info interface
const enforcedLanguageInfo = getKernelInfoInterface().language_info(language_info, getLanguageInterface());
// Merge the kernel info object with the enforced language info
const mergedKernelInfo = {
...kernel_info,
language_info: enforcedLanguageInfo
};
// Merge the protocol version, implementation, implementation version, and banner
const mergedInfo = {
...mergedKernelInfo,
protocol_version: protocol_version || '5.1',
implementation: implementation || enforcedLanguageInfo.name,
implementation_version: implementation_version || PACKAGE_VERSION,
banner: banner || enforcedLanguageInfo.language
};
return mergedInfo;
}
// Export the kernel info interface and the native kernel info function
module.exports = {
kernelInfoInterface,
nativeKernelInfo
};
The code starts by importing necessary modules and data:
importer
is required from ../Core
and used to import other modules: interface
and languageInterface
.PACKAGE_VERSION
is extracted from ../package.json
.kernelInfoInterface
ObjectThe kernelInfoInterface
object is defined with several properties, including:
protocol_version
, implementation
, implementation_version
, and banner
, which are all initialized with default values.language_info
, which is set to the languageInterface
object.help_links
and install_config
are initialized with default values.nativeKernelInfo
FunctionThe nativeKernelInfo
function takes a kernel_info
object as an argument and returns an extended version of it. Here's what it does:
kernel_info
is truthy and returns immediately if it's not.kernel_info
and assigns them to local variables.interface
function to the language_info
property, using languageInterface
as the interface.name
property of language_info
to either language_info.name
or implementation
.interface
function to the entire kernel_info
object, using kernelInfoInterface
as the interface.self
by extending meta_info
with the extracted properties and returns it.Finally, the code exports the kernelInfoInterface
object and the nativeKernelInfo
function as a module:
module.exports = { kernelInfoInterface, nativeKernelInfo }