convention_builder 1.8.6 → 2.0.1

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 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
+
@@ -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;
@@ -10652,7 +10679,6 @@ var require_convention_builder = __commonJS({
10652
10679
  let firstLevel = attribute.split(/\./)[0];
10653
10680
  let siblingModifications = Array.from(this.modifiedAttributes).filter((attr) => attr != attribute).filter((attr) => attr.includes(`${firstLevel}.`));
10654
10681
  let isOnlyModification = siblingModifications.length == 0;
10655
- console.log(`${attribute} is only modification? ${isOnlyModification}, there are ${siblingModifications.join(", ")}`);
10656
10682
  if (isOnlyModification) {
10657
10683
  delete this.overlay.properties.attributes.properties[firstLevel];
10658
10684
  }
@@ -10773,14 +10799,14 @@ var require_convention_builder = __commonJS({
10773
10799
  */
10774
10800
  store(test = true) {
10775
10801
  this.updateSchema();
10776
- let targetPath = `${this.storagePath()}/${this.schemaName}`;
10802
+ let targetPath = `${this.storagePath()}/${this.schemaName}/${this.version}/`;
10777
10803
  if (!this.trivial) {
10778
10804
  fs.mkdirSync(targetPath, { recursive: true }, console.error);
10779
10805
  fs.mkdirSync(`${targetPath}/examples/correct`, { recursive: true }, console.error);
10780
10806
  fs.mkdirSync(`${targetPath}/examples/incorrect`, { recursive: true }, console.error);
10781
10807
  }
10782
10808
  let valid = "not tested";
10783
- if (test) {
10809
+ if (test && !this.trivial) {
10784
10810
  let test2 = this.testExamples();
10785
10811
  valid = test2.success;
10786
10812
  if (!valid) {
@@ -11001,16 +11027,21 @@ var require_convention_builder = __commonJS({
11001
11027
  * Adds an attribute which should be an entity represented as a schema overlay object.
11002
11028
  * @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
11029
  * @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.
11030
+ * @param {SemVer} version -- In case of string, you can indicate the version, otherwise the latest one will be used.
11004
11031
  * @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
11032
  */
11006
- addAttribute({ schemaOverlayObject, attributeName, required }) {
11033
+ addAttribute({ schemaOverlayObject, attributeName, version, required }) {
11007
11034
  let overlaysOnly = process.argv.includes("overlaysOnly");
11008
11035
  if (typeof schemaOverlayObject == "string") {
11009
11036
  let schemaOverlayName = schemaOverlayObject;
11010
11037
  let isOverlay = fs.readdirSync(`${this.storagePath()}/overlays`).find((folder) => folder == schemaOverlayObject);
11011
11038
  if (isOverlay) {
11012
11039
  try {
11013
- schemaOverlayObject = new SchemaOverlay(JSON.parse(fs.readFileSync(`${this.storagePath()}/overlays/${schemaOverlayObject}/object.json`)));
11040
+ if (!version) {
11041
+ let versions = fs.readdirSync(`${this.storagePath()}/overlays/${schemaOverlayObject}`, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
11042
+ version = findLatestSemverString(versions);
11043
+ }
11044
+ schemaOverlayObject = new SchemaOverlay(JSON.parse(fs.readFileSync(`${this.storagePath()}/overlays/${schemaOverlayObject}/${version}/object.json`)));
11014
11045
  schemaOverlayObject.global = true;
11015
11046
  } catch (e) {
11016
11047
  if (e.code == "ENOENT" && !overlaysOnly) {
@@ -11047,6 +11078,9 @@ var require_convention_builder = __commonJS({
11047
11078
  schemaOverlayObject.updateSchema();
11048
11079
  }
11049
11080
  ;
11081
+ if (!schemaOverlayObject.version) {
11082
+ schemaOverlayObject.version = this.version;
11083
+ }
11050
11084
  this.overlays[attributeName] = schemaOverlayObject;
11051
11085
  if (required) {
11052
11086
  this.required.push(attributeName);
@@ -11080,6 +11114,14 @@ var require_convention_builder = __commonJS({
11080
11114
  this.relationships.push({ containerEntity, relationName, mentionedEntity, required });
11081
11115
  this.updateSchema();
11082
11116
  }
11117
+ /**
11118
+ * Removes overlay from the convention, as well as all relationships in it or mentioning it.
11119
+ * @param {} attributeName
11120
+ */
11121
+ removeOverlay(attributeName) {
11122
+ this.relatioships = this.relationships.filter((rel) => rel.containerEntitiy != attributeName && rel.mentionedEntity != attributeName);
11123
+ delete this.overlays[attributeName];
11124
+ }
11083
11125
  /**
11084
11126
  * Organizes all attributes of a convention into a hierarchical binary tree, under the assumption the tree is binary.
11085
11127
  * @param {ConventionSchema} -- convention
@@ -11167,8 +11209,8 @@ var require_convention_builder = __commonJS({
11167
11209
  */
11168
11210
  document() {
11169
11211
  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";
11212
+ import Schema from "@site/static/schemas/${this.schemaName}/${this.version}/schema.json";
11213
+ import SchemaReduced from "@site/static/schemas/${this.schemaName}/${this.version}/schema_required_only.json";
11172
11214
  import JSONSchemaViewer from "@theme/JSONSchemaViewer";
11173
11215
  import Tabs from '@theme/Tabs';
11174
11216
  import TabItem from '@theme/TabItem';
@@ -11338,10 +11380,22 @@ import TabItem from '@theme/TabItem';
11338
11380
  getTabularRepresentation() {
11339
11381
  return flattenJSONSchema(this.schema, true);
11340
11382
  }
11383
+ /**
11384
+ * If no examples have been added by hand, will grab examples from the default folders in the definition's subdirectory.
11385
+ */
11386
+ addDefaultFolderExamples() {
11387
+ if (!this.validExamples) {
11388
+ this.addExample({ path: `${__dirname}/examples/correct` });
11389
+ }
11390
+ if (!this.erroredExamples) {
11391
+ this.addExample({ path: `${__dirname}/examples/incorrect` });
11392
+ }
11393
+ }
11341
11394
  /**
11342
11395
  * 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
11396
  */
11344
11397
  testExamples() {
11398
+ this.addDefaultFolderExamples();
11345
11399
  let generalOutput = {};
11346
11400
  if (!this.validExamples || !this.erroredExamples) {
11347
11401
  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 +11474,10 @@ import TabItem from '@theme/TabItem';
11420
11474
  return output2;
11421
11475
  }
11422
11476
  ;
11423
- let targetPath = `${this.storagePath()}/conventions/${this.schemaName}`;
11477
+ let targetPath = `${this.storagePath()}/conventions/${this.schemaName}/${this.version}`;
11424
11478
  let mainEntityType = this.schemaName.split("--")[0];
11425
11479
  let documentationFolder = `${this.storagePath()}/../documentation/Conventions/${mainEntityType}`;
11426
- let documentationPath = `${documentationFolder}/${this.schemaName}.mdx`;
11480
+ let documentationPath = `${documentationFolder}/${this.schemaName}_${this.version}.mdx`;
11427
11481
  fs.mkdirSync(targetPath, { recursive: true }, console.error);
11428
11482
  fs.mkdirSync(`${targetPath}/examples/correct`, { recursive: true }, console.error);
11429
11483
  fs.mkdirSync(`${targetPath}/examples/incorrect`, { recursive: true }, console.error);
@@ -25775,12 +25829,35 @@ var require_array_examples_preparator = __commonJS({
25775
25829
  }
25776
25830
  });
25777
25831
 
25832
+ // src/entity_sorting.js
25833
+ var require_entity_sorting = __commonJS({
25834
+ "src/entity_sorting.js"(exports) {
25835
+ var ENTITY_PREFIXES = {
25836
+ LOG: "log--",
25837
+ ASSET: "asset--"
25838
+ };
25839
+ function categorizeKeysByEntityType(keys, specialKeys = []) {
25840
+ const special = specialKeys.filter((k) => keys.includes(k));
25841
+ const logs = keys.filter((k) => k.startsWith(ENTITY_PREFIXES.LOG));
25842
+ const assets = keys.filter((k) => k.startsWith(ENTITY_PREFIXES.ASSET));
25843
+ const others = keys.filter(
25844
+ (k) => !specialKeys.includes(k) && !k.startsWith(ENTITY_PREFIXES.LOG) && !k.startsWith(ENTITY_PREFIXES.ASSET)
25845
+ );
25846
+ return { special, logs, assets, others };
25847
+ }
25848
+ __name(categorizeKeysByEntityType, "categorizeKeysByEntityType");
25849
+ exports.categorizeKeysByEntityType = categorizeKeysByEntityType;
25850
+ exports.ENTITY_PREFIXES = ENTITY_PREFIXES;
25851
+ }
25852
+ });
25853
+
25778
25854
  // src/index.js
25779
25855
  var require_index = __commonJS({
25780
25856
  "src/index.js"(exports) {
25781
25857
  var { SchemaOverlay, ConventionSchema, InputConventionChanges } = require_convention_builder();
25782
25858
  var schemaUtils = require_schema_utilities();
25783
25859
  var { ArrayDataOrganizer } = require_array_examples_preparator();
25860
+ var { categorizeKeysByEntityType, ENTITY_PREFIXES } = require_entity_sorting();
25784
25861
  exports.SchemaOverlay = SchemaOverlay;
25785
25862
  exports.InputConventionChanges = InputConventionChanges;
25786
25863
  exports.ConventionSchema = ConventionSchema;
@@ -25800,6 +25877,8 @@ var require_index = __commonJS({
25800
25877
  exports.reduceSchemaToRequiredFields = schemaUtils.reduceSchemaToRequiredFields;
25801
25878
  exports.flattenJSONSchema = schemaUtils.flattenJSONSchema;
25802
25879
  exports.ArrayDataOrganizer = ArrayDataOrganizer;
25880
+ exports.categorizeKeysByEntityType = categorizeKeysByEntityType;
25881
+ exports.ENTITY_PREFIXES = ENTITY_PREFIXES;
25803
25882
  }
25804
25883
  });
25805
25884
  export default require_index();
@@ -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;
@@ -10646,7 +10673,6 @@ var require_convention_builder = __commonJS({
10646
10673
  let firstLevel = attribute.split(/\./)[0];
10647
10674
  let siblingModifications = Array.from(this.modifiedAttributes).filter((attr) => attr != attribute).filter((attr) => attr.includes(`${firstLevel}.`));
10648
10675
  let isOnlyModification = siblingModifications.length == 0;
10649
- console.log(`${attribute} is only modification? ${isOnlyModification}, there are ${siblingModifications.join(", ")}`);
10650
10676
  if (isOnlyModification) {
10651
10677
  delete this.overlay.properties.attributes.properties[firstLevel];
10652
10678
  }
@@ -10767,14 +10793,14 @@ var require_convention_builder = __commonJS({
10767
10793
  */
10768
10794
  store(test = true) {
10769
10795
  this.updateSchema();
10770
- let targetPath = `${this.storagePath()}/${this.schemaName}`;
10796
+ let targetPath = `${this.storagePath()}/${this.schemaName}/${this.version}/`;
10771
10797
  if (!this.trivial) {
10772
10798
  fs.mkdirSync(targetPath, { recursive: true }, console.error);
10773
10799
  fs.mkdirSync(`${targetPath}/examples/correct`, { recursive: true }, console.error);
10774
10800
  fs.mkdirSync(`${targetPath}/examples/incorrect`, { recursive: true }, console.error);
10775
10801
  }
10776
10802
  let valid = "not tested";
10777
- if (test) {
10803
+ if (test && !this.trivial) {
10778
10804
  let test2 = this.testExamples();
10779
10805
  valid = test2.success;
10780
10806
  if (!valid) {
@@ -10995,16 +11021,21 @@ var require_convention_builder = __commonJS({
10995
11021
  * Adds an attribute which should be an entity represented as a schema overlay object.
10996
11022
  * @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
11023
  * @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.
11024
+ * @param {SemVer} version -- In case of string, you can indicate the version, otherwise the latest one will be used.
10998
11025
  * @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
11026
  */
11000
- addAttribute({ schemaOverlayObject, attributeName, required }) {
11027
+ addAttribute({ schemaOverlayObject, attributeName, version, required }) {
11001
11028
  let overlaysOnly = process.argv.includes("overlaysOnly");
11002
11029
  if (typeof schemaOverlayObject == "string") {
11003
11030
  let schemaOverlayName = schemaOverlayObject;
11004
11031
  let isOverlay = fs.readdirSync(`${this.storagePath()}/overlays`).find((folder) => folder == schemaOverlayObject);
11005
11032
  if (isOverlay) {
11006
11033
  try {
11007
- schemaOverlayObject = new SchemaOverlay2(JSON.parse(fs.readFileSync(`${this.storagePath()}/overlays/${schemaOverlayObject}/object.json`)));
11034
+ if (!version) {
11035
+ let versions = fs.readdirSync(`${this.storagePath()}/overlays/${schemaOverlayObject}`, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
11036
+ version = findLatestSemverString(versions);
11037
+ }
11038
+ schemaOverlayObject = new SchemaOverlay2(JSON.parse(fs.readFileSync(`${this.storagePath()}/overlays/${schemaOverlayObject}/${version}/object.json`)));
11008
11039
  schemaOverlayObject.global = true;
11009
11040
  } catch (e) {
11010
11041
  if (e.code == "ENOENT" && !overlaysOnly) {
@@ -11041,6 +11072,9 @@ var require_convention_builder = __commonJS({
11041
11072
  schemaOverlayObject.updateSchema();
11042
11073
  }
11043
11074
  ;
11075
+ if (!schemaOverlayObject.version) {
11076
+ schemaOverlayObject.version = this.version;
11077
+ }
11044
11078
  this.overlays[attributeName] = schemaOverlayObject;
11045
11079
  if (required) {
11046
11080
  this.required.push(attributeName);
@@ -11074,6 +11108,14 @@ var require_convention_builder = __commonJS({
11074
11108
  this.relationships.push({ containerEntity, relationName, mentionedEntity, required });
11075
11109
  this.updateSchema();
11076
11110
  }
11111
+ /**
11112
+ * Removes overlay from the convention, as well as all relationships in it or mentioning it.
11113
+ * @param {} attributeName
11114
+ */
11115
+ removeOverlay(attributeName) {
11116
+ this.relatioships = this.relationships.filter((rel) => rel.containerEntitiy != attributeName && rel.mentionedEntity != attributeName);
11117
+ delete this.overlays[attributeName];
11118
+ }
11077
11119
  /**
11078
11120
  * Organizes all attributes of a convention into a hierarchical binary tree, under the assumption the tree is binary.
11079
11121
  * @param {ConventionSchema} -- convention
@@ -11161,8 +11203,8 @@ var require_convention_builder = __commonJS({
11161
11203
  */
11162
11204
  document() {
11163
11205
  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";
11206
+ import Schema from "@site/static/schemas/${this.schemaName}/${this.version}/schema.json";
11207
+ import SchemaReduced from "@site/static/schemas/${this.schemaName}/${this.version}/schema_required_only.json";
11166
11208
  import JSONSchemaViewer from "@theme/JSONSchemaViewer";
11167
11209
  import Tabs from '@theme/Tabs';
11168
11210
  import TabItem from '@theme/TabItem';
@@ -11332,10 +11374,22 @@ import TabItem from '@theme/TabItem';
11332
11374
  getTabularRepresentation() {
11333
11375
  return flattenJSONSchema(this.schema, true);
11334
11376
  }
11377
+ /**
11378
+ * If no examples have been added by hand, will grab examples from the default folders in the definition's subdirectory.
11379
+ */
11380
+ addDefaultFolderExamples() {
11381
+ if (!this.validExamples) {
11382
+ this.addExample({ path: `${__dirname}/examples/correct` });
11383
+ }
11384
+ if (!this.erroredExamples) {
11385
+ this.addExample({ path: `${__dirname}/examples/incorrect` });
11386
+ }
11387
+ }
11335
11388
  /**
11336
11389
  * 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
11390
  */
11338
11391
  testExamples() {
11392
+ this.addDefaultFolderExamples();
11339
11393
  let generalOutput = {};
11340
11394
  if (!this.validExamples || !this.erroredExamples) {
11341
11395
  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 +11468,10 @@ import TabItem from '@theme/TabItem';
11414
11468
  return output2;
11415
11469
  }
11416
11470
  ;
11417
- let targetPath = `${this.storagePath()}/conventions/${this.schemaName}`;
11471
+ let targetPath = `${this.storagePath()}/conventions/${this.schemaName}/${this.version}`;
11418
11472
  let mainEntityType = this.schemaName.split("--")[0];
11419
11473
  let documentationFolder = `${this.storagePath()}/../documentation/Conventions/${mainEntityType}`;
11420
- let documentationPath = `${documentationFolder}/${this.schemaName}.mdx`;
11474
+ let documentationPath = `${documentationFolder}/${this.schemaName}_${this.version}.mdx`;
11421
11475
  fs.mkdirSync(targetPath, { recursive: true }, console.error);
11422
11476
  fs.mkdirSync(`${targetPath}/examples/correct`, { recursive: true }, console.error);
11423
11477
  fs.mkdirSync(`${targetPath}/examples/incorrect`, { recursive: true }, console.error);
@@ -25769,10 +25823,33 @@ var require_array_examples_preparator = __commonJS({
25769
25823
  }
25770
25824
  });
25771
25825
 
25826
+ // src/entity_sorting.js
25827
+ var require_entity_sorting = __commonJS({
25828
+ "src/entity_sorting.js"(exports2) {
25829
+ var ENTITY_PREFIXES2 = {
25830
+ LOG: "log--",
25831
+ ASSET: "asset--"
25832
+ };
25833
+ function categorizeKeysByEntityType2(keys, specialKeys = []) {
25834
+ const special = specialKeys.filter((k) => keys.includes(k));
25835
+ const logs = keys.filter((k) => k.startsWith(ENTITY_PREFIXES2.LOG));
25836
+ const assets = keys.filter((k) => k.startsWith(ENTITY_PREFIXES2.ASSET));
25837
+ const others = keys.filter(
25838
+ (k) => !specialKeys.includes(k) && !k.startsWith(ENTITY_PREFIXES2.LOG) && !k.startsWith(ENTITY_PREFIXES2.ASSET)
25839
+ );
25840
+ return { special, logs, assets, others };
25841
+ }
25842
+ __name(categorizeKeysByEntityType2, "categorizeKeysByEntityType");
25843
+ exports2.categorizeKeysByEntityType = categorizeKeysByEntityType2;
25844
+ exports2.ENTITY_PREFIXES = ENTITY_PREFIXES2;
25845
+ }
25846
+ });
25847
+
25772
25848
  // src/index.js
25773
25849
  var { SchemaOverlay, ConventionSchema, InputConventionChanges } = require_convention_builder();
25774
25850
  var schemaUtils = require_schema_utilities();
25775
25851
  var { ArrayDataOrganizer } = require_array_examples_preparator();
25852
+ var { categorizeKeysByEntityType, ENTITY_PREFIXES } = require_entity_sorting();
25776
25853
  exports.SchemaOverlay = SchemaOverlay;
25777
25854
  exports.InputConventionChanges = InputConventionChanges;
25778
25855
  exports.ConventionSchema = ConventionSchema;
@@ -25792,6 +25869,8 @@ exports.trimNonRequiredFields = schemaUtils.trimNonRequiredFields;
25792
25869
  exports.reduceSchemaToRequiredFields = schemaUtils.reduceSchemaToRequiredFields;
25793
25870
  exports.flattenJSONSchema = schemaUtils.flattenJSONSchema;
25794
25871
  exports.ArrayDataOrganizer = ArrayDataOrganizer;
25872
+ exports.categorizeKeysByEntityType = categorizeKeysByEntityType;
25873
+ exports.ENTITY_PREFIXES = ENTITY_PREFIXES;
25795
25874
  /*! Bundled license information:
25796
25875
 
25797
25876
  uri-js/dist/es5/uri.all.js:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "convention_builder",
3
- "version": "1.8.6",
4
- "description": "Helper tools that offer a high level interface that transforms a convention description into its json schema.",
3
+ "version": "2.0.1",
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",