The module loaders implements
predefined loader functions related with JM2MP projection modules.
All loaders must implement the interface (contract):
(name: string) => Promise<object>.
All loaders must be agnostic about query language adapters and just load the corresponding projection module as a JSON value.
Predefined loader functions are:
createStringLoader: it loads a projection module directly from memory; it is usefull for testing.createFileLoader: it loads a projection module from the filesystem; it uses Node.js file system module, so it can be used only in applications and not in web browsers.createUrlLoader: it loads a projection module using the Fetch API; it can be used within both web browsers and Node.js v18+ applications.
Source
Methods
createFileLoader(optionsopt) → {FileLoaderResult}
Loader based on filesystem, so only on Node.js applications can be used, and not as part of client contexts in web browsers.
Every name will be interpreted as a relative path to baseDir, or
as an absolute path.
It dynamically imports node:fs/promises and node:path modules to
avoid breaks web browser's use context.
Parameters
-
options
object<optional>
.
Properties
-
baseDir
string<optional>
It specifies the base directory for relative paths. By default process.cwd() is used.
-
encoding
string<optional>
"utf8"By default, it uses
UTF-8encoding.
-
baseDir
Returns
-
FileLoaderResultThe just created FileLoaderResult.
Throws
-
Whenever 'stringMap' is not an object or is null.
- Type
-
module:jm2mp/modules/LookupAddress.TypeError
Source
createStringLoader(stringMap) → {StringLoaderResult}
Loader based on a simple (in memory) map of names and serialized JSON values.
It is usefull for testing purposes or when the projection modules are actually integrated into the code.
Parameters
-
stringMap
Object.<string, string>The map of names and serialized JSON values.
Returns
-
StringLoaderResultThe just created StringLoaderResult.
Throws
-
Whenever 'stringMap' is not an object or is null.
- Type
-
module:jm2mp/modules/LookupAddress.TypeError
Source
createUrlLoader(optionsopt) → {UrlLoaderResult}
Loader based on the Fetch API feature, available in modern web browser and as part of Node.js v18+ applications.
Every name is interpreted as an absolute URL, or relative to baseUrl
if provided.
Parameters
-
options
object<optional>
.
Properties
-
baseUrl
string<optional>
It specifies the base URL for relative addresses.
-
fetchOptions
RequestInit<optional>
It allows to specify options for
fetch(like headers, credentials, ...).
-
baseUrl
Returns
-
UrlLoaderResultThe just created UrlLoaderResult.
Throws
-
Whenever 'stringMap' is not an object or is null.
- Type
-
module:jm2mp/modules/LookupAddress.TypeError
Source
Type Definitions
FileLoaderResult()
*typedef {Promise<(name: string) => Promise
Source
StringLoaderResult()
*typedef {(name: string) => Promise
Source
UrlLoaderResult()
*typedef {(name: string) => Promise