convention_builder 1.8.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/dist/module/index.js +64 -9
- package/dist/node/index.js +64 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,4 +3,16 @@
|
|
|
3
3
|
This library is the main code component in our `farmos_convention_publisher` project.
|
|
4
4
|
It allows a user to create complex Farm data schemata using the FarmOs entities, which are already abstracted into JSON Schema files.
|
|
5
5
|
The objects that abstract this process have many added functionalities, such as the generation of rich react documentation, standalone schema validators and versioning.
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
# Some Characteristics
|
|
8
|
+
|
|
9
|
+
## Versioning
|
|
10
|
+
|
|
11
|
+
Al conventions and overlays are fully versioned.
|
|
12
|
+
|
|
13
|
+
This implies a version attribute in the defining object will ensure they are stored in a subfolder with the version name inside the adequate folder (with the convention/overlay name) in the `outputs` section.
|
|
14
|
+
|
|
15
|
+
The assumed way to store versions is by using git tags.
|
|
16
|
+
|
|
17
|
+
The rebuild scripts will grab each tag for each convention and build all versions using the mentioned subfolders.
|
|
18
|
+
|
package/dist/module/index.js
CHANGED
|
@@ -9089,6 +9089,28 @@ var require_schema_utilities = __commonJS({
|
|
|
9089
9089
|
return `https://gitlab.com/api/v4/projects/${projectID}/jobs/artifacts/main/raw/input/collection/${type}/${bundle}/schema.json?job=copy_schemas`;
|
|
9090
9090
|
}
|
|
9091
9091
|
__name(basicSchemaURLTemplate, "basicSchemaURLTemplate");
|
|
9092
|
+
function compareSemvers(semverA, semverB) {
|
|
9093
|
+
let aFields = semverA.split(".").map((d) => parseInt(d));
|
|
9094
|
+
let bFields = semverB.split(".").map((d) => parseInt(d));
|
|
9095
|
+
let output = 0;
|
|
9096
|
+
[0, 1, 2].forEach((fieldIndex) => {
|
|
9097
|
+
if (output != 0) {
|
|
9098
|
+
return;
|
|
9099
|
+
}
|
|
9100
|
+
;
|
|
9101
|
+
if (aFields[fieldIndex] != bFields[fieldIndex]) {
|
|
9102
|
+
output = aFields[fieldIndex] > bFields[fieldIndex] ? 1 : -1;
|
|
9103
|
+
}
|
|
9104
|
+
;
|
|
9105
|
+
});
|
|
9106
|
+
return output;
|
|
9107
|
+
}
|
|
9108
|
+
__name(compareSemvers, "compareSemvers");
|
|
9109
|
+
function findLatestSemverString(semverStringArray) {
|
|
9110
|
+
let sorted = semverStringArray.sort((a, b) => compareSemvers(b, a));
|
|
9111
|
+
return sorted[0];
|
|
9112
|
+
}
|
|
9113
|
+
__name(findLatestSemverString, "findLatestSemverString");
|
|
9092
9114
|
exports.dig = dig;
|
|
9093
9115
|
exports.bury = bury;
|
|
9094
9116
|
exports.fixRelationshipDataField = fixRelationshipDataField;
|
|
@@ -9114,6 +9136,8 @@ var require_schema_utilities = __commonJS({
|
|
|
9114
9136
|
exports.gitlabConventionURLTemplate = gitlabConventionURLTemplate;
|
|
9115
9137
|
exports.gitlabOverlayURLTemplate = gitlabOverlayURLTemplate;
|
|
9116
9138
|
exports.basicSchemaURLTemplate = basicSchemaURLTemplate;
|
|
9139
|
+
exports.compareSemvers = compareSemvers;
|
|
9140
|
+
exports.findLatestSemverString = findLatestSemverString;
|
|
9117
9141
|
}
|
|
9118
9142
|
});
|
|
9119
9143
|
|
|
@@ -10469,7 +10493,8 @@ var require_convention_builder = __commonJS({
|
|
|
10469
10493
|
gitlabConventionURLTemplate,
|
|
10470
10494
|
basicSchemaURLTemplate,
|
|
10471
10495
|
arrayToStructuredConvention,
|
|
10472
|
-
flattenJSONSchema
|
|
10496
|
+
flattenJSONSchema,
|
|
10497
|
+
findLatestSemverString
|
|
10473
10498
|
} = require_schema_utilities();
|
|
10474
10499
|
var papa = require_papaparse();
|
|
10475
10500
|
function getAttributes(root, convention) {
|
|
@@ -10483,6 +10508,7 @@ var require_convention_builder = __commonJS({
|
|
|
10483
10508
|
constructor({
|
|
10484
10509
|
typeAndBundle,
|
|
10485
10510
|
name,
|
|
10511
|
+
version,
|
|
10486
10512
|
validExamples,
|
|
10487
10513
|
erroredExamples,
|
|
10488
10514
|
repoURLTemplateFunction = gitlabOverlayURLTemplate,
|
|
@@ -10499,6 +10525,7 @@ var require_convention_builder = __commonJS({
|
|
|
10499
10525
|
deletedAttributes = []
|
|
10500
10526
|
}) {
|
|
10501
10527
|
this.name = name;
|
|
10528
|
+
this.version = version;
|
|
10502
10529
|
this.typeAndBundle = typeAndBundle;
|
|
10503
10530
|
this.validExamples = validExamples;
|
|
10504
10531
|
this.erroredExamples = erroredExamples;
|
|
@@ -10773,14 +10800,14 @@ var require_convention_builder = __commonJS({
|
|
|
10773
10800
|
*/
|
|
10774
10801
|
store(test = true) {
|
|
10775
10802
|
this.updateSchema();
|
|
10776
|
-
let targetPath = `${this.storagePath()}/${this.schemaName}
|
|
10803
|
+
let targetPath = `${this.storagePath()}/${this.schemaName}/${this.version}/`;
|
|
10777
10804
|
if (!this.trivial) {
|
|
10778
10805
|
fs.mkdirSync(targetPath, { recursive: true }, console.error);
|
|
10779
10806
|
fs.mkdirSync(`${targetPath}/examples/correct`, { recursive: true }, console.error);
|
|
10780
10807
|
fs.mkdirSync(`${targetPath}/examples/incorrect`, { recursive: true }, console.error);
|
|
10781
10808
|
}
|
|
10782
10809
|
let valid = "not tested";
|
|
10783
|
-
if (test) {
|
|
10810
|
+
if (test && !this.trivial) {
|
|
10784
10811
|
let test2 = this.testExamples();
|
|
10785
10812
|
valid = test2.success;
|
|
10786
10813
|
if (!valid) {
|
|
@@ -11001,16 +11028,21 @@ var require_convention_builder = __commonJS({
|
|
|
11001
11028
|
* Adds an attribute which should be an entity represented as a schema overlay object.
|
|
11002
11029
|
* @param {SchemaOverlay|String} schemaOverlayObject -- An object of the SchemaOverlay class or a string. If it is a string, it should be the "type--bundle" class of the desired base FarmOS schema or a preexisting overlay, using the name it's contained folder has in "collection/overlays".
|
|
11003
11030
|
* @param {string} attributeName -- Name identifying the entity inside the schema. Typically it is not the type--bundle pair but a unique name related to its functionality inside the schema. An example would be the case in which a convention involves many quantities: you can't name each quantity "quantity", instead the logical naming pattern is alluding to what's being measured.
|
|
11031
|
+
* @param {SemVer} version -- In case of string, you can indicate the version, otherwise the latest one will be used.
|
|
11004
11032
|
* @param {boolean} required -- Indicate wether the attribute should be marked as 'required' by the schema, in which case every submission lacking this attribute will be marked as rejected.
|
|
11005
11033
|
*/
|
|
11006
|
-
addAttribute({ schemaOverlayObject, attributeName, required }) {
|
|
11034
|
+
addAttribute({ schemaOverlayObject, attributeName, version, required }) {
|
|
11007
11035
|
let overlaysOnly = process.argv.includes("overlaysOnly");
|
|
11008
11036
|
if (typeof schemaOverlayObject == "string") {
|
|
11009
11037
|
let schemaOverlayName = schemaOverlayObject;
|
|
11010
11038
|
let isOverlay = fs.readdirSync(`${this.storagePath()}/overlays`).find((folder) => folder == schemaOverlayObject);
|
|
11011
11039
|
if (isOverlay) {
|
|
11012
11040
|
try {
|
|
11013
|
-
|
|
11041
|
+
if (!version) {
|
|
11042
|
+
let versions = fs.readdirSync(`${this.storagePath()}/overlays/${schemaOverlayObject}`, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
|
|
11043
|
+
version = findLatestSemverString(versions);
|
|
11044
|
+
}
|
|
11045
|
+
schemaOverlayObject = new SchemaOverlay(JSON.parse(fs.readFileSync(`${this.storagePath()}/overlays/${schemaOverlayObject}/${version}/object.json`)));
|
|
11014
11046
|
schemaOverlayObject.global = true;
|
|
11015
11047
|
} catch (e) {
|
|
11016
11048
|
if (e.code == "ENOENT" && !overlaysOnly) {
|
|
@@ -11047,6 +11079,9 @@ var require_convention_builder = __commonJS({
|
|
|
11047
11079
|
schemaOverlayObject.updateSchema();
|
|
11048
11080
|
}
|
|
11049
11081
|
;
|
|
11082
|
+
if (!schemaOverlayObject.version) {
|
|
11083
|
+
schemaOverlayObject.version = this.version;
|
|
11084
|
+
}
|
|
11050
11085
|
this.overlays[attributeName] = schemaOverlayObject;
|
|
11051
11086
|
if (required) {
|
|
11052
11087
|
this.required.push(attributeName);
|
|
@@ -11080,6 +11115,14 @@ var require_convention_builder = __commonJS({
|
|
|
11080
11115
|
this.relationships.push({ containerEntity, relationName, mentionedEntity, required });
|
|
11081
11116
|
this.updateSchema();
|
|
11082
11117
|
}
|
|
11118
|
+
/**
|
|
11119
|
+
* Removes overlay from the convention, as well as all relationships in it or mentioning it.
|
|
11120
|
+
* @param {} attributeName
|
|
11121
|
+
*/
|
|
11122
|
+
removeOverlay(attributeName) {
|
|
11123
|
+
this.relatioships = this.relationships.filter((rel) => rel.containerEntitiy != attributeName && rel.mentionedEntity != attributeName);
|
|
11124
|
+
delete this.overlays[attributeName];
|
|
11125
|
+
}
|
|
11083
11126
|
/**
|
|
11084
11127
|
* Organizes all attributes of a convention into a hierarchical binary tree, under the assumption the tree is binary.
|
|
11085
11128
|
* @param {ConventionSchema} -- convention
|
|
@@ -11167,8 +11210,8 @@ var require_convention_builder = __commonJS({
|
|
|
11167
11210
|
*/
|
|
11168
11211
|
document() {
|
|
11169
11212
|
let header = `import CodeBlock from '@theme/CodeBlock';
|
|
11170
|
-
import Schema from "@site/static/schemas/${this.schemaName}/schema.json";
|
|
11171
|
-
import SchemaReduced from "@site/static/schemas/${this.schemaName}/schema_required_only.json";
|
|
11213
|
+
import Schema from "@site/static/schemas/${this.schemaName}/${this.version}/schema.json";
|
|
11214
|
+
import SchemaReduced from "@site/static/schemas/${this.schemaName}/${this.version}/schema_required_only.json";
|
|
11172
11215
|
import JSONSchemaViewer from "@theme/JSONSchemaViewer";
|
|
11173
11216
|
import Tabs from '@theme/Tabs';
|
|
11174
11217
|
import TabItem from '@theme/TabItem';
|
|
@@ -11338,10 +11381,22 @@ import TabItem from '@theme/TabItem';
|
|
|
11338
11381
|
getTabularRepresentation() {
|
|
11339
11382
|
return flattenJSONSchema(this.schema, true);
|
|
11340
11383
|
}
|
|
11384
|
+
/**
|
|
11385
|
+
* If no examples have been added by hand, will grab examples from the default folders in the definition's subdirectory.
|
|
11386
|
+
*/
|
|
11387
|
+
addDefaultFolderExamples() {
|
|
11388
|
+
if (!this.validExamples) {
|
|
11389
|
+
this.addExample({ path: `${__dirname}/examples/correct` });
|
|
11390
|
+
}
|
|
11391
|
+
if (!this.erroredExamples) {
|
|
11392
|
+
this.addExample({ path: `${__dirname}/examples/incorrect` });
|
|
11393
|
+
}
|
|
11394
|
+
}
|
|
11341
11395
|
/**
|
|
11342
11396
|
* Build an AJV validator and ensure all valid examples are accepted and all error examples are rejected. Returns an array attribute for each set of examples, plus a general success attribute indicating wether all examples resulted as expected and a failedExamples array only listing entities for which there was no success (meanin unrejected error examples and rejected valid examples).
|
|
11343
11397
|
*/
|
|
11344
11398
|
testExamples() {
|
|
11399
|
+
this.addDefaultFolderExamples();
|
|
11345
11400
|
let generalOutput = {};
|
|
11346
11401
|
if (!this.validExamples || !this.erroredExamples) {
|
|
11347
11402
|
throw new Error(`Testing can't happen because examples are missing either in the valid or errored attribute. Valid examples amount: ${this.validExamples ? this.validExamples.length : "validExamples is not an array"}, errored examples amount: ${this.erroredExamples ? this.erroredExamples.length : "erroredExamples is not an array"}.`);
|
|
@@ -11420,10 +11475,10 @@ import TabItem from '@theme/TabItem';
|
|
|
11420
11475
|
return output2;
|
|
11421
11476
|
}
|
|
11422
11477
|
;
|
|
11423
|
-
let targetPath = `${this.storagePath()}/conventions/${this.schemaName}`;
|
|
11478
|
+
let targetPath = `${this.storagePath()}/conventions/${this.schemaName}/${this.version}`;
|
|
11424
11479
|
let mainEntityType = this.schemaName.split("--")[0];
|
|
11425
11480
|
let documentationFolder = `${this.storagePath()}/../documentation/Conventions/${mainEntityType}`;
|
|
11426
|
-
let documentationPath = `${documentationFolder}/${this.schemaName}.mdx`;
|
|
11481
|
+
let documentationPath = `${documentationFolder}/${this.schemaName}_${this.version}.mdx`;
|
|
11427
11482
|
fs.mkdirSync(targetPath, { recursive: true }, console.error);
|
|
11428
11483
|
fs.mkdirSync(`${targetPath}/examples/correct`, { recursive: true }, console.error);
|
|
11429
11484
|
fs.mkdirSync(`${targetPath}/examples/incorrect`, { recursive: true }, console.error);
|
package/dist/node/index.js
CHANGED
|
@@ -9083,6 +9083,28 @@ var require_schema_utilities = __commonJS({
|
|
|
9083
9083
|
return `https://gitlab.com/api/v4/projects/${projectID}/jobs/artifacts/main/raw/input/collection/${type}/${bundle}/schema.json?job=copy_schemas`;
|
|
9084
9084
|
}
|
|
9085
9085
|
__name(basicSchemaURLTemplate, "basicSchemaURLTemplate");
|
|
9086
|
+
function compareSemvers(semverA, semverB) {
|
|
9087
|
+
let aFields = semverA.split(".").map((d) => parseInt(d));
|
|
9088
|
+
let bFields = semverB.split(".").map((d) => parseInt(d));
|
|
9089
|
+
let output = 0;
|
|
9090
|
+
[0, 1, 2].forEach((fieldIndex) => {
|
|
9091
|
+
if (output != 0) {
|
|
9092
|
+
return;
|
|
9093
|
+
}
|
|
9094
|
+
;
|
|
9095
|
+
if (aFields[fieldIndex] != bFields[fieldIndex]) {
|
|
9096
|
+
output = aFields[fieldIndex] > bFields[fieldIndex] ? 1 : -1;
|
|
9097
|
+
}
|
|
9098
|
+
;
|
|
9099
|
+
});
|
|
9100
|
+
return output;
|
|
9101
|
+
}
|
|
9102
|
+
__name(compareSemvers, "compareSemvers");
|
|
9103
|
+
function findLatestSemverString(semverStringArray) {
|
|
9104
|
+
let sorted = semverStringArray.sort((a, b) => compareSemvers(b, a));
|
|
9105
|
+
return sorted[0];
|
|
9106
|
+
}
|
|
9107
|
+
__name(findLatestSemverString, "findLatestSemverString");
|
|
9086
9108
|
exports2.dig = dig;
|
|
9087
9109
|
exports2.bury = bury;
|
|
9088
9110
|
exports2.fixRelationshipDataField = fixRelationshipDataField;
|
|
@@ -9108,6 +9130,8 @@ var require_schema_utilities = __commonJS({
|
|
|
9108
9130
|
exports2.gitlabConventionURLTemplate = gitlabConventionURLTemplate;
|
|
9109
9131
|
exports2.gitlabOverlayURLTemplate = gitlabOverlayURLTemplate;
|
|
9110
9132
|
exports2.basicSchemaURLTemplate = basicSchemaURLTemplate;
|
|
9133
|
+
exports2.compareSemvers = compareSemvers;
|
|
9134
|
+
exports2.findLatestSemverString = findLatestSemverString;
|
|
9111
9135
|
}
|
|
9112
9136
|
});
|
|
9113
9137
|
|
|
@@ -10463,7 +10487,8 @@ var require_convention_builder = __commonJS({
|
|
|
10463
10487
|
gitlabConventionURLTemplate,
|
|
10464
10488
|
basicSchemaURLTemplate,
|
|
10465
10489
|
arrayToStructuredConvention,
|
|
10466
|
-
flattenJSONSchema
|
|
10490
|
+
flattenJSONSchema,
|
|
10491
|
+
findLatestSemverString
|
|
10467
10492
|
} = require_schema_utilities();
|
|
10468
10493
|
var papa = require_papaparse();
|
|
10469
10494
|
function getAttributes(root, convention) {
|
|
@@ -10477,6 +10502,7 @@ var require_convention_builder = __commonJS({
|
|
|
10477
10502
|
constructor({
|
|
10478
10503
|
typeAndBundle,
|
|
10479
10504
|
name,
|
|
10505
|
+
version,
|
|
10480
10506
|
validExamples,
|
|
10481
10507
|
erroredExamples,
|
|
10482
10508
|
repoURLTemplateFunction = gitlabOverlayURLTemplate,
|
|
@@ -10493,6 +10519,7 @@ var require_convention_builder = __commonJS({
|
|
|
10493
10519
|
deletedAttributes = []
|
|
10494
10520
|
}) {
|
|
10495
10521
|
this.name = name;
|
|
10522
|
+
this.version = version;
|
|
10496
10523
|
this.typeAndBundle = typeAndBundle;
|
|
10497
10524
|
this.validExamples = validExamples;
|
|
10498
10525
|
this.erroredExamples = erroredExamples;
|
|
@@ -10767,14 +10794,14 @@ var require_convention_builder = __commonJS({
|
|
|
10767
10794
|
*/
|
|
10768
10795
|
store(test = true) {
|
|
10769
10796
|
this.updateSchema();
|
|
10770
|
-
let targetPath = `${this.storagePath()}/${this.schemaName}
|
|
10797
|
+
let targetPath = `${this.storagePath()}/${this.schemaName}/${this.version}/`;
|
|
10771
10798
|
if (!this.trivial) {
|
|
10772
10799
|
fs.mkdirSync(targetPath, { recursive: true }, console.error);
|
|
10773
10800
|
fs.mkdirSync(`${targetPath}/examples/correct`, { recursive: true }, console.error);
|
|
10774
10801
|
fs.mkdirSync(`${targetPath}/examples/incorrect`, { recursive: true }, console.error);
|
|
10775
10802
|
}
|
|
10776
10803
|
let valid = "not tested";
|
|
10777
|
-
if (test) {
|
|
10804
|
+
if (test && !this.trivial) {
|
|
10778
10805
|
let test2 = this.testExamples();
|
|
10779
10806
|
valid = test2.success;
|
|
10780
10807
|
if (!valid) {
|
|
@@ -10995,16 +11022,21 @@ var require_convention_builder = __commonJS({
|
|
|
10995
11022
|
* Adds an attribute which should be an entity represented as a schema overlay object.
|
|
10996
11023
|
* @param {SchemaOverlay|String} schemaOverlayObject -- An object of the SchemaOverlay class or a string. If it is a string, it should be the "type--bundle" class of the desired base FarmOS schema or a preexisting overlay, using the name it's contained folder has in "collection/overlays".
|
|
10997
11024
|
* @param {string} attributeName -- Name identifying the entity inside the schema. Typically it is not the type--bundle pair but a unique name related to its functionality inside the schema. An example would be the case in which a convention involves many quantities: you can't name each quantity "quantity", instead the logical naming pattern is alluding to what's being measured.
|
|
11025
|
+
* @param {SemVer} version -- In case of string, you can indicate the version, otherwise the latest one will be used.
|
|
10998
11026
|
* @param {boolean} required -- Indicate wether the attribute should be marked as 'required' by the schema, in which case every submission lacking this attribute will be marked as rejected.
|
|
10999
11027
|
*/
|
|
11000
|
-
addAttribute({ schemaOverlayObject, attributeName, required }) {
|
|
11028
|
+
addAttribute({ schemaOverlayObject, attributeName, version, required }) {
|
|
11001
11029
|
let overlaysOnly = process.argv.includes("overlaysOnly");
|
|
11002
11030
|
if (typeof schemaOverlayObject == "string") {
|
|
11003
11031
|
let schemaOverlayName = schemaOverlayObject;
|
|
11004
11032
|
let isOverlay = fs.readdirSync(`${this.storagePath()}/overlays`).find((folder) => folder == schemaOverlayObject);
|
|
11005
11033
|
if (isOverlay) {
|
|
11006
11034
|
try {
|
|
11007
|
-
|
|
11035
|
+
if (!version) {
|
|
11036
|
+
let versions = fs.readdirSync(`${this.storagePath()}/overlays/${schemaOverlayObject}`, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
|
|
11037
|
+
version = findLatestSemverString(versions);
|
|
11038
|
+
}
|
|
11039
|
+
schemaOverlayObject = new SchemaOverlay2(JSON.parse(fs.readFileSync(`${this.storagePath()}/overlays/${schemaOverlayObject}/${version}/object.json`)));
|
|
11008
11040
|
schemaOverlayObject.global = true;
|
|
11009
11041
|
} catch (e) {
|
|
11010
11042
|
if (e.code == "ENOENT" && !overlaysOnly) {
|
|
@@ -11041,6 +11073,9 @@ var require_convention_builder = __commonJS({
|
|
|
11041
11073
|
schemaOverlayObject.updateSchema();
|
|
11042
11074
|
}
|
|
11043
11075
|
;
|
|
11076
|
+
if (!schemaOverlayObject.version) {
|
|
11077
|
+
schemaOverlayObject.version = this.version;
|
|
11078
|
+
}
|
|
11044
11079
|
this.overlays[attributeName] = schemaOverlayObject;
|
|
11045
11080
|
if (required) {
|
|
11046
11081
|
this.required.push(attributeName);
|
|
@@ -11074,6 +11109,14 @@ var require_convention_builder = __commonJS({
|
|
|
11074
11109
|
this.relationships.push({ containerEntity, relationName, mentionedEntity, required });
|
|
11075
11110
|
this.updateSchema();
|
|
11076
11111
|
}
|
|
11112
|
+
/**
|
|
11113
|
+
* Removes overlay from the convention, as well as all relationships in it or mentioning it.
|
|
11114
|
+
* @param {} attributeName
|
|
11115
|
+
*/
|
|
11116
|
+
removeOverlay(attributeName) {
|
|
11117
|
+
this.relatioships = this.relationships.filter((rel) => rel.containerEntitiy != attributeName && rel.mentionedEntity != attributeName);
|
|
11118
|
+
delete this.overlays[attributeName];
|
|
11119
|
+
}
|
|
11077
11120
|
/**
|
|
11078
11121
|
* Organizes all attributes of a convention into a hierarchical binary tree, under the assumption the tree is binary.
|
|
11079
11122
|
* @param {ConventionSchema} -- convention
|
|
@@ -11161,8 +11204,8 @@ var require_convention_builder = __commonJS({
|
|
|
11161
11204
|
*/
|
|
11162
11205
|
document() {
|
|
11163
11206
|
let header = `import CodeBlock from '@theme/CodeBlock';
|
|
11164
|
-
import Schema from "@site/static/schemas/${this.schemaName}/schema.json";
|
|
11165
|
-
import SchemaReduced from "@site/static/schemas/${this.schemaName}/schema_required_only.json";
|
|
11207
|
+
import Schema from "@site/static/schemas/${this.schemaName}/${this.version}/schema.json";
|
|
11208
|
+
import SchemaReduced from "@site/static/schemas/${this.schemaName}/${this.version}/schema_required_only.json";
|
|
11166
11209
|
import JSONSchemaViewer from "@theme/JSONSchemaViewer";
|
|
11167
11210
|
import Tabs from '@theme/Tabs';
|
|
11168
11211
|
import TabItem from '@theme/TabItem';
|
|
@@ -11332,10 +11375,22 @@ import TabItem from '@theme/TabItem';
|
|
|
11332
11375
|
getTabularRepresentation() {
|
|
11333
11376
|
return flattenJSONSchema(this.schema, true);
|
|
11334
11377
|
}
|
|
11378
|
+
/**
|
|
11379
|
+
* If no examples have been added by hand, will grab examples from the default folders in the definition's subdirectory.
|
|
11380
|
+
*/
|
|
11381
|
+
addDefaultFolderExamples() {
|
|
11382
|
+
if (!this.validExamples) {
|
|
11383
|
+
this.addExample({ path: `${__dirname}/examples/correct` });
|
|
11384
|
+
}
|
|
11385
|
+
if (!this.erroredExamples) {
|
|
11386
|
+
this.addExample({ path: `${__dirname}/examples/incorrect` });
|
|
11387
|
+
}
|
|
11388
|
+
}
|
|
11335
11389
|
/**
|
|
11336
11390
|
* Build an AJV validator and ensure all valid examples are accepted and all error examples are rejected. Returns an array attribute for each set of examples, plus a general success attribute indicating wether all examples resulted as expected and a failedExamples array only listing entities for which there was no success (meanin unrejected error examples and rejected valid examples).
|
|
11337
11391
|
*/
|
|
11338
11392
|
testExamples() {
|
|
11393
|
+
this.addDefaultFolderExamples();
|
|
11339
11394
|
let generalOutput = {};
|
|
11340
11395
|
if (!this.validExamples || !this.erroredExamples) {
|
|
11341
11396
|
throw new Error(`Testing can't happen because examples are missing either in the valid or errored attribute. Valid examples amount: ${this.validExamples ? this.validExamples.length : "validExamples is not an array"}, errored examples amount: ${this.erroredExamples ? this.erroredExamples.length : "erroredExamples is not an array"}.`);
|
|
@@ -11414,10 +11469,10 @@ import TabItem from '@theme/TabItem';
|
|
|
11414
11469
|
return output2;
|
|
11415
11470
|
}
|
|
11416
11471
|
;
|
|
11417
|
-
let targetPath = `${this.storagePath()}/conventions/${this.schemaName}`;
|
|
11472
|
+
let targetPath = `${this.storagePath()}/conventions/${this.schemaName}/${this.version}`;
|
|
11418
11473
|
let mainEntityType = this.schemaName.split("--")[0];
|
|
11419
11474
|
let documentationFolder = `${this.storagePath()}/../documentation/Conventions/${mainEntityType}`;
|
|
11420
|
-
let documentationPath = `${documentationFolder}/${this.schemaName}.mdx`;
|
|
11475
|
+
let documentationPath = `${documentationFolder}/${this.schemaName}_${this.version}.mdx`;
|
|
11421
11476
|
fs.mkdirSync(targetPath, { recursive: true }, console.error);
|
|
11422
11477
|
fs.mkdirSync(`${targetPath}/examples/correct`, { recursive: true }, console.error);
|
|
11423
11478
|
fs.mkdirSync(`${targetPath}/examples/incorrect`, { recursive: true }, console.error);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "convention_builder",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Helper tools that offer a high level interface that transforms a convention description into
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Helper tools that offer a high level interface that transforms a convention description into it's json schema.",
|
|
5
5
|
"main": "./dist/node/index.js",
|
|
6
6
|
"browser": "./dist/browser/index.js",
|
|
7
7
|
"module": "./dist/module/index.js",
|