Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…dards into airr-js
  • Loading branch information
schristley committed Sep 25, 2023
2 parents 251aa6f + 7a5a574 commit 25898e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
38 changes: 13 additions & 25 deletions lang/js/airr.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const $RefParser = require("@apidevtools/json-schema-ref-parser");
var airr = {};
module.exports = airr;

// load AIRR standards schema
airr.load_schema = async function() {
// Load AIRR spec
var airrFile = path.resolve(__dirname, './airr-schema-openapi3.yaml');
Expand All @@ -35,29 +36,16 @@ airr.load_schema = async function() {
return Promise.resolve(spec);
};

// schema functions
//const schema = require('./schema')(AIRRSchema);
// i/o functions
//const io = require('./io');

/* TODO? UMD
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node.
module.exports = factory(require('b'));
} else {
// Browser globals (root is window)
root.returnExports = factory(root.b);
}
}(typeof self !== 'undefined' ? self : this, function (b) {
// Use b in some fashion.
// Just return a value to define the module export.
// This example returns an object, but the module
// can return a function as the exported value.
return {};
})); */
// load custom schema
airr.load_custom_schema = async function(obj, filename) {
// Load schema file
//var airrFile = path.resolve(__dirname, filename);
var doc = yaml.safeLoad(fs.readFileSync(filename));
if (!doc) Promise.reject(new Error('Could not load custom schema yaml file.'));

// dereference all $ref objects
var spec = await $RefParser.dereference(doc);
var schema = require('./schema')(obj, spec);

return Promise.resolve(spec);
};
4 changes: 4 additions & 0 deletions lang/js/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ var fs = require('fs');
const zlib = require('zlib');
var csv = require('csv-parser');

function isPromise(promise) {
return !!promise && typeof promise.then === 'function'
}

//
// Interface functions for file operations
//
Expand Down

0 comments on commit 25898e9

Please sign in to comment.