Skip to content

Commit

Permalink
ACMS-000: release fix for schema loading function
Browse files Browse the repository at this point in the history
ACMS-000: release fix for schema loading function
  • Loading branch information
mehdiguarana authored Nov 28, 2024
2 parents baec855 + 167c07b commit 4e83ce4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# ANS Release Notes

### 1.12.3

* Prevent the callback function from being called twice during the loading of schemas
* Prevent the load schema function from returning before the full schema is read

### 1.12.2

* [PPA-825](https://arcpublishing.atlassian.net/browse/PPA-825) - fix a minor issue in previous 1.12.1
Expand Down
16 changes: 9 additions & 7 deletions lib/schemas.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const schemaVersionsLoaded = {};
var schemas = {};
var schemasByVersion = {};
var dir = require('node-dir');
Expand All @@ -8,7 +9,6 @@ var _ = require('lodash');

var baseDir = path.join(path.dirname(module.filename), '../src/main/resources/schema/ans');

var callback = undefined;
var loaded = false;


Expand All @@ -19,21 +19,23 @@ var loadSchema = function loadSchema(version, done) {
return;
}

if (_.isObject(schemasByVersion[version])) {
if (schemasByVersion[version] && schemaVersionsLoaded[version]) {
done(null, schemasByVersion[version]);
return;
}

var schemaDir = baseDir + '/' + version;

schemasByVersion[version] = {};
var schemaDir = baseDir + '/' + version;

dir.readFiles(
schemaDir, {
match: /.json$/
},
function(err, content, filename, next) {
if (err) throw err;

if (!schemasByVersion[version]) {
schemasByVersion[version] = {};
schemaVersionsLoaded[version] = false;
}
var name = path.relative(schemaDir, filename);
try {
var content = JSON.parse(content);
Expand All @@ -51,7 +53,7 @@ var loadSchema = function loadSchema(version, done) {
return;
}
}
loaded = true;
schemaVersionsLoaded[version] = true;
if (typeof done == 'function') {
done(null, schemasByVersion[version]);
return;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@washingtonpost/ans-schema",
"description": "The Washington Post's Arc Native Specification",
"version": "1.12.2",
"version": "1.12.3",
"homepage": "https://github.com/washingtonpost/ans-schema",
"repository": {
"type": "git",
Expand Down

0 comments on commit 4e83ce4

Please sign in to comment.