convention_builder 1.2.2 → 1.4.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.
@@ -8404,6 +8404,45 @@ var require_schema_utilities = __commonJS({
8404
8404
  }
8405
8405
  }
8406
8406
  __name(dig, "dig");
8407
+ function findCommonPath(targetObject, path) {
8408
+ const chunks = path.split(/\.|\[|\]/).filter((d) => d.length !== 0);
8409
+ let partialPath = "";
8410
+ chunks.forEach((attr) => {
8411
+ let newPartialPath = partialPath.concat(".", attr).replace(/^\./, "");
8412
+ let partialPathExists = dig(targetObject, newPartialPath, false) ? true : false;
8413
+ if (partialPathExists) {
8414
+ partialPath = newPartialPath;
8415
+ }
8416
+ ;
8417
+ });
8418
+ return partialPath;
8419
+ }
8420
+ __name(findCommonPath, "findCommonPath");
8421
+ function bury(targetObject, path, value, merge = false) {
8422
+ let acum = value;
8423
+ let partialPath = findCommonPath(targetObject, path);
8424
+ let sharedPathPattern = new RegExp("^".concat(partialPath));
8425
+ let targetPath = path.replace(sharedPathPattern, "").replace(/\.$/, "");
8426
+ let chunks = targetPath.split(/\.|\[|\]/).filter((d) => d.length !== 0);
8427
+ chunks.reverse().forEach((attr) => {
8428
+ let newLayer = {};
8429
+ newLayer[attr] = acum;
8430
+ acum = newLayer;
8431
+ });
8432
+ if (merge) {
8433
+ let sharedObjectSection = dig(targetObject, partialPath);
8434
+ Object.assign(sharedObjectSection, acum);
8435
+ } else {
8436
+ chunks = partialPath.split(/\.|\[|\]/).filter((d) => d.length !== 0);
8437
+ let lastAttr = chunks[chunks.length - 1];
8438
+ let remainingPath = path.replace(new RegExp(lastAttr.concat("$")), "").replace(/\.$/, "");
8439
+ let sharedObjectSection = dig(targetObject, remainingPath);
8440
+ sharedObjectSection[lastAttr] = value;
8441
+ }
8442
+ ;
8443
+ return targetObject;
8444
+ }
8445
+ __name(bury, "bury");
8407
8446
  function fixRelationshipDataField(schema) {
8408
8447
  if (schema.properties.relationships) {
8409
8448
  Object.keys(schema.properties.relationships.properties).forEach((relKey) => {
@@ -8792,8 +8831,10 @@ var require_schema_utilities = __commonJS({
8792
8831
  return output;
8793
8832
  }
8794
8833
  __name(flattenObjectBranch, "flattenObjectBranch");
8834
+ var nameRegex = /[0-9a-zA-Z_]*$/;
8835
+ var overlayRegex = /[0-9a-zA-Z-_]*/;
8795
8836
  function checkRequiredInSchema(path, schema) {
8796
- let attributeName = path.match(/[a-zA-Z_]*$/)[0];
8837
+ let attributeName = path.match(nameRegex)[0];
8797
8838
  let pathFormat = new RegExp(`properties.${attributeName}`).test(path);
8798
8839
  if (!pathFormat) {
8799
8840
  throw new Error(`Attribute paths have a format in which the second to last property is 'properties' such as 'properties.attributes.properties.date' for a field named 'date'. This one seems to have another format. Provided path is ${path} .`);
@@ -8830,14 +8871,14 @@ var require_schema_utilities = __commonJS({
8830
8871
  let entry = {
8831
8872
  path: attr,
8832
8873
  path_simplified: attr.replace(/\.properties/g, "").replace(/properties\./, ""),
8833
- name: attr.match(/[a-zA-Z_]*$/)[0],
8874
+ name: attr.match(nameRegex)[0],
8834
8875
  required: isRequired
8835
8876
  };
8836
8877
  if (isConvention) {
8837
- entry.overlay = entry.path_simplified.match(/[a-zA-Z-_]*/)[0];
8878
+ entry.overlay = entry.path_simplified.match(overlayRegex)[0];
8838
8879
  }
8839
8880
  ;
8840
- allFlattenedPaths.filter((d) => d.path.includes(`${attr}.`)).forEach((d) => {
8881
+ allFlattenedPaths.filter((d) => d.path.includes(`${attr}.`) && !d.path.includes("items")).forEach((d) => {
8841
8882
  let key = d.path.replace(`${attr}.`, "");
8842
8883
  let value = d.value;
8843
8884
  entry[key] = value;
@@ -8849,10 +8890,10 @@ var require_schema_utilities = __commonJS({
8849
8890
  let entry = {
8850
8891
  path: rel,
8851
8892
  path_simplified: rel.replace(/\.properties/g, "").replace(/properties\./, ""),
8852
- name: rel.match(/[a-zA-Z]*$/)[0]
8893
+ name: rel.match(nameRegex)[0]
8853
8894
  };
8854
8895
  if (isConvention) {
8855
- entry.overlay = entry.path_simplified.match(/[a-zA-Z-_]*/)[0];
8896
+ entry.overlay = entry.path_simplified.match(overlayRegex)[0];
8856
8897
  let relatedDataPaths = dig(
8857
8898
  schema,
8858
8899
  `${rel}.properties.data.contains.anyOf`
@@ -8869,6 +8910,57 @@ var require_schema_utilities = __commonJS({
8869
8910
  return table;
8870
8911
  }
8871
8912
  __name(flattenJSONSchema, "flattenJSONSchema");
8913
+ function listAttributesAndSubAttributes(schema) {
8914
+ let topLevelAttributes = new Set(Object.keys(schema.properties.attributes.properties));
8915
+ let output = topLevelAttributes;
8916
+ let objectTypeAttributes = Array.from(topLevelAttributes).filter((attr) => schema.properties.attributes.properties[attr].type == "object");
8917
+ objectTypeAttributes.flatMap((objAttr) => {
8918
+ let subAttrs = Object.keys(schema.properties.attributes.properties[objAttr].properties);
8919
+ subAttrs.forEach((subAttr) => {
8920
+ output.add(`${objAttr}.properties.${subAttr}`);
8921
+ output.delete(`${objAttr}`);
8922
+ });
8923
+ });
8924
+ return output;
8925
+ }
8926
+ __name(listAttributesAndSubAttributes, "listAttributesAndSubAttributes");
8927
+ function findAllObjectAttributesInTree(schemataTree) {
8928
+ let output = [];
8929
+ Object.keys(schemataTree).forEach((typeKey) => {
8930
+ Object.keys(schemataTree[typeKey]).forEach((bundleKey) => {
8931
+ let schema = schemataTree[typeKey][bundleKey];
8932
+ let topLevelAttributes = new Set(Object.keys(schema.properties.attributes.properties));
8933
+ let objectTypeAttributes = Array.from(topLevelAttributes).filter((attr) => schema.properties.attributes.properties[attr].type == "object");
8934
+ objectTypeAttributes.forEach((attr) => {
8935
+ let entry = output.find((attrDescription) => attrDescription.attribute == attr);
8936
+ if (entry) {
8937
+ entry.instances.push(
8938
+ {
8939
+ type: typeKey,
8940
+ bundle: bundleKey,
8941
+ schema: `${typeKey}--${bundleKey}`
8942
+ }
8943
+ );
8944
+ } else {
8945
+ output.push({
8946
+ attribute: attr,
8947
+ instances: [
8948
+ {
8949
+ type: typeKey,
8950
+ bundle: bundleKey,
8951
+ schema: `${typeKey}--${bundleKey}`
8952
+ }
8953
+ ]
8954
+ });
8955
+ }
8956
+ });
8957
+ });
8958
+ });
8959
+ return output;
8960
+ }
8961
+ __name(findAllObjectAttributesInTree, "findAllObjectAttributesInTree");
8962
+ exports.dig = dig;
8963
+ exports.bury = bury;
8872
8964
  exports.fixRelationshipDataField = fixRelationshipDataField;
8873
8965
  exports.buildValidator = buildValidator;
8874
8966
  exports.buildStaticValidator = buildStaticValidator;
@@ -8885,6 +8977,8 @@ var require_schema_utilities = __commonJS({
8885
8977
  exports.reduceSchemaToRequiredFields = reduceSchemaToRequiredFields;
8886
8978
  exports.flattenObjectBranch = flattenObjectBranch;
8887
8979
  exports.flattenJSONSchema = flattenJSONSchema;
8980
+ exports.listAttributesAndSubAttributes = listAttributesAndSubAttributes;
8981
+ exports.findAllObjectAttributesInTree = findAllObjectAttributesInTree;
8888
8982
  }
8889
8983
  });
8890
8984
 
@@ -8892,7 +8986,7 @@ var require_schema_utilities = __commonJS({
8892
8986
  var require_convention_builder = __commonJS({
8893
8987
  "src/convention_builder.js"(exports) {
8894
8988
  var fs = __require("fs");
8895
- var { buildValidator, urlToStringPair } = require_schema_utilities();
8989
+ var { buildValidator, urlToStringPair, dig, bury, listAttributesAndSubAttributes } = require_schema_utilities();
8896
8990
  function getAttributes(root, convention) {
8897
8991
  let branches = convention.relationships.filter((rel) => rel.containerEntity == root).map((d) => d.mentionedEntity);
8898
8992
  let output = {};
@@ -8947,7 +9041,7 @@ var require_convention_builder = __commonJS({
8947
9041
  }
8948
9042
  ;
8949
9043
  this.baseSchema = baseSchema;
8950
- this.unmodifiedAttributes = new Set(Object.keys(this.baseSchema.properties.attributes.properties));
9044
+ this.unmodifiedAttributes = listAttributesAndSubAttributes(this.baseSchema);
8951
9045
  this.modifiedAttributes = /* @__PURE__ */ new Set([]);
8952
9046
  if (!overlay) {
8953
9047
  this.overlay = {
@@ -8976,10 +9070,11 @@ var require_convention_builder = __commonJS({
8976
9070
  this.schema = {};
8977
9071
  this.schema.$id = `${this.repoURL}/schemata/${this.typeAndBundle.replace("--", "/")}/schema.json`;
8978
9072
  Object.assign(this.schema, this.baseSchema);
8979
- let allModifiedAttributes = new Set(Object.keys(this.overlay.properties.attributes.properties));
9073
+ let allModifiedAttributes = listAttributesAndSubAttributes(this.overlay);
8980
9074
  this.modifiedAttributes = allModifiedAttributes;
8981
9075
  Array.from(this.modifiedAttributes).forEach((attr) => {
8982
- this.schema.properties.attributes.properties[attr] = this.overlay.properties.attributes.properties[attr];
9076
+ let currentValue = dig(this.overlay.properties.attributes.properties, attr);
9077
+ bury(this.schema, `properties.attributes.properties.${attr}`, currentValue, true);
8983
9078
  });
8984
9079
  let originalRequiredFields = this.schema.properties.attributes.required ? this.schema.properties.attributes.required : [];
8985
9080
  let allRequiredSet = Array.from(/* @__PURE__ */ new Set([...originalRequiredFields, ...Array.from(this.requiredFields)]));
@@ -9021,6 +9116,21 @@ var require_convention_builder = __commonJS({
9021
9116
  this.requiredFields.add(attribute);
9022
9117
  this.updateSchema();
9023
9118
  }
9119
+ setGenericSection({ attribute, section, description }) {
9120
+ this.checkAttributeStatus(attribute);
9121
+ bury(this.overlay.properties.attributes.properties, attribute, section, true);
9122
+ if (attribute.match(/\./)) {
9123
+ let firstLevel = attribute.split(/\./)[0];
9124
+ this.overlay.properties.attributes.properties[firstLevel].type = "object";
9125
+ }
9126
+ ;
9127
+ if (description) {
9128
+ bury(this.overlay.properties.attributes.properties, attribute.concat(".description"), description, true);
9129
+ }
9130
+ ;
9131
+ this.updateAttributeStatus(attribute);
9132
+ this.updateSchema();
9133
+ }
9024
9134
  /**
9025
9135
  * Sets an attribute as a constant as indicated by the given value.
9026
9136
  * @param {string} attribute -- Attribute name for the attribute which will be set to a constant.
@@ -9028,14 +9138,8 @@ var require_convention_builder = __commonJS({
9028
9138
  * @param {string} description -- Describes the rationale behind the chosing of the value.
9029
9139
  */
9030
9140
  setConstant({ attribute, value, description }) {
9031
- this.checkAttributeStatus(attribute);
9032
- this.overlay.properties.attributes.properties[attribute] = { const: value };
9033
- if (description) {
9034
- this.overlay.properties.attributes.properties[attribute].description = description;
9035
- }
9036
- ;
9037
- this.updateAttributeStatus(attribute);
9038
- this.updateSchema();
9141
+ let constantSection = { const: value };
9142
+ this.setGenericSection({ attribute, section: constantSection, description });
9039
9143
  }
9040
9144
  /**
9041
9145
  * Sets a regex pattern as a restriction for the value of an attribute. Look into the JSON Schema documentation, as it recomends sticking to a [subset of RegEx](https://website-2v2.pages.dev/understanding-json-schema/reference/regular_expressions).
@@ -9045,17 +9149,11 @@ var require_convention_builder = __commonJS({
9045
9149
  * @param {string} description -- Describes the rationale behind the chosing of the value.
9046
9150
  */
9047
9151
  setPattern({ attribute, pattern, string, description }) {
9048
- this.checkAttributeStatus(attribute);
9049
- this.overlay.properties.attributes.properties[attribute] = {
9152
+ let patternSchemaSection = {
9050
9153
  type: "string",
9051
9154
  pattern: pattern ? pattern : string
9052
9155
  };
9053
- if (description) {
9054
- this.overlay.properties.attributes.properties[attribute].description = description;
9055
- }
9056
- ;
9057
- this.updateAttributeStatus(attribute);
9058
- this.updateSchema();
9156
+ this.setGenericSection({ attribute, section: patternSchemaSection, description });
9059
9157
  }
9060
9158
  /**
9061
9159
  * Sets an attribute as a constrained to a list of possible values.
@@ -9071,13 +9169,8 @@ var require_convention_builder = __commonJS({
9071
9169
  } else {
9072
9170
  subschema = { anyOf: [{ type: "string" }, { enum: valuesArray }] };
9073
9171
  }
9074
- this.overlay.properties.attributes.properties[attribute] = subschema;
9075
- if (description) {
9076
- this.overlay.properties.attributes.properties[attribute].description = description;
9077
- }
9078
9172
  ;
9079
- this.updateAttributeStatus(attribute);
9080
- this.updateSchema();
9173
+ this.setGenericSection({ attribute, section: subschema, description });
9081
9174
  }
9082
9175
  /**
9083
9176
  * 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).
@@ -8397,6 +8397,45 @@ var require_schema_utilities = __commonJS({
8397
8397
  }
8398
8398
  }
8399
8399
  __name(dig, "dig");
8400
+ function findCommonPath(targetObject, path) {
8401
+ const chunks = path.split(/\.|\[|\]/).filter((d) => d.length !== 0);
8402
+ let partialPath = "";
8403
+ chunks.forEach((attr) => {
8404
+ let newPartialPath = partialPath.concat(".", attr).replace(/^\./, "");
8405
+ let partialPathExists = dig(targetObject, newPartialPath, false) ? true : false;
8406
+ if (partialPathExists) {
8407
+ partialPath = newPartialPath;
8408
+ }
8409
+ ;
8410
+ });
8411
+ return partialPath;
8412
+ }
8413
+ __name(findCommonPath, "findCommonPath");
8414
+ function bury(targetObject, path, value, merge = false) {
8415
+ let acum = value;
8416
+ let partialPath = findCommonPath(targetObject, path);
8417
+ let sharedPathPattern = new RegExp("^".concat(partialPath));
8418
+ let targetPath = path.replace(sharedPathPattern, "").replace(/\.$/, "");
8419
+ let chunks = targetPath.split(/\.|\[|\]/).filter((d) => d.length !== 0);
8420
+ chunks.reverse().forEach((attr) => {
8421
+ let newLayer = {};
8422
+ newLayer[attr] = acum;
8423
+ acum = newLayer;
8424
+ });
8425
+ if (merge) {
8426
+ let sharedObjectSection = dig(targetObject, partialPath);
8427
+ Object.assign(sharedObjectSection, acum);
8428
+ } else {
8429
+ chunks = partialPath.split(/\.|\[|\]/).filter((d) => d.length !== 0);
8430
+ let lastAttr = chunks[chunks.length - 1];
8431
+ let remainingPath = path.replace(new RegExp(lastAttr.concat("$")), "").replace(/\.$/, "");
8432
+ let sharedObjectSection = dig(targetObject, remainingPath);
8433
+ sharedObjectSection[lastAttr] = value;
8434
+ }
8435
+ ;
8436
+ return targetObject;
8437
+ }
8438
+ __name(bury, "bury");
8400
8439
  function fixRelationshipDataField(schema) {
8401
8440
  if (schema.properties.relationships) {
8402
8441
  Object.keys(schema.properties.relationships.properties).forEach((relKey) => {
@@ -8785,8 +8824,10 @@ var require_schema_utilities = __commonJS({
8785
8824
  return output;
8786
8825
  }
8787
8826
  __name(flattenObjectBranch, "flattenObjectBranch");
8827
+ var nameRegex = /[0-9a-zA-Z_]*$/;
8828
+ var overlayRegex = /[0-9a-zA-Z-_]*/;
8788
8829
  function checkRequiredInSchema(path, schema) {
8789
- let attributeName = path.match(/[a-zA-Z_]*$/)[0];
8830
+ let attributeName = path.match(nameRegex)[0];
8790
8831
  let pathFormat = new RegExp(`properties.${attributeName}`).test(path);
8791
8832
  if (!pathFormat) {
8792
8833
  throw new Error(`Attribute paths have a format in which the second to last property is 'properties' such as 'properties.attributes.properties.date' for a field named 'date'. This one seems to have another format. Provided path is ${path} .`);
@@ -8823,14 +8864,14 @@ var require_schema_utilities = __commonJS({
8823
8864
  let entry = {
8824
8865
  path: attr,
8825
8866
  path_simplified: attr.replace(/\.properties/g, "").replace(/properties\./, ""),
8826
- name: attr.match(/[a-zA-Z_]*$/)[0],
8867
+ name: attr.match(nameRegex)[0],
8827
8868
  required: isRequired
8828
8869
  };
8829
8870
  if (isConvention) {
8830
- entry.overlay = entry.path_simplified.match(/[a-zA-Z-_]*/)[0];
8871
+ entry.overlay = entry.path_simplified.match(overlayRegex)[0];
8831
8872
  }
8832
8873
  ;
8833
- allFlattenedPaths.filter((d) => d.path.includes(`${attr}.`)).forEach((d) => {
8874
+ allFlattenedPaths.filter((d) => d.path.includes(`${attr}.`) && !d.path.includes("items")).forEach((d) => {
8834
8875
  let key = d.path.replace(`${attr}.`, "");
8835
8876
  let value = d.value;
8836
8877
  entry[key] = value;
@@ -8842,10 +8883,10 @@ var require_schema_utilities = __commonJS({
8842
8883
  let entry = {
8843
8884
  path: rel,
8844
8885
  path_simplified: rel.replace(/\.properties/g, "").replace(/properties\./, ""),
8845
- name: rel.match(/[a-zA-Z]*$/)[0]
8886
+ name: rel.match(nameRegex)[0]
8846
8887
  };
8847
8888
  if (isConvention) {
8848
- entry.overlay = entry.path_simplified.match(/[a-zA-Z-_]*/)[0];
8889
+ entry.overlay = entry.path_simplified.match(overlayRegex)[0];
8849
8890
  let relatedDataPaths = dig(
8850
8891
  schema,
8851
8892
  `${rel}.properties.data.contains.anyOf`
@@ -8862,6 +8903,57 @@ var require_schema_utilities = __commonJS({
8862
8903
  return table;
8863
8904
  }
8864
8905
  __name(flattenJSONSchema, "flattenJSONSchema");
8906
+ function listAttributesAndSubAttributes(schema) {
8907
+ let topLevelAttributes = new Set(Object.keys(schema.properties.attributes.properties));
8908
+ let output = topLevelAttributes;
8909
+ let objectTypeAttributes = Array.from(topLevelAttributes).filter((attr) => schema.properties.attributes.properties[attr].type == "object");
8910
+ objectTypeAttributes.flatMap((objAttr) => {
8911
+ let subAttrs = Object.keys(schema.properties.attributes.properties[objAttr].properties);
8912
+ subAttrs.forEach((subAttr) => {
8913
+ output.add(`${objAttr}.properties.${subAttr}`);
8914
+ output.delete(`${objAttr}`);
8915
+ });
8916
+ });
8917
+ return output;
8918
+ }
8919
+ __name(listAttributesAndSubAttributes, "listAttributesAndSubAttributes");
8920
+ function findAllObjectAttributesInTree(schemataTree) {
8921
+ let output = [];
8922
+ Object.keys(schemataTree).forEach((typeKey) => {
8923
+ Object.keys(schemataTree[typeKey]).forEach((bundleKey) => {
8924
+ let schema = schemataTree[typeKey][bundleKey];
8925
+ let topLevelAttributes = new Set(Object.keys(schema.properties.attributes.properties));
8926
+ let objectTypeAttributes = Array.from(topLevelAttributes).filter((attr) => schema.properties.attributes.properties[attr].type == "object");
8927
+ objectTypeAttributes.forEach((attr) => {
8928
+ let entry = output.find((attrDescription) => attrDescription.attribute == attr);
8929
+ if (entry) {
8930
+ entry.instances.push(
8931
+ {
8932
+ type: typeKey,
8933
+ bundle: bundleKey,
8934
+ schema: `${typeKey}--${bundleKey}`
8935
+ }
8936
+ );
8937
+ } else {
8938
+ output.push({
8939
+ attribute: attr,
8940
+ instances: [
8941
+ {
8942
+ type: typeKey,
8943
+ bundle: bundleKey,
8944
+ schema: `${typeKey}--${bundleKey}`
8945
+ }
8946
+ ]
8947
+ });
8948
+ }
8949
+ });
8950
+ });
8951
+ });
8952
+ return output;
8953
+ }
8954
+ __name(findAllObjectAttributesInTree, "findAllObjectAttributesInTree");
8955
+ exports2.dig = dig;
8956
+ exports2.bury = bury;
8865
8957
  exports2.fixRelationshipDataField = fixRelationshipDataField;
8866
8958
  exports2.buildValidator = buildValidator;
8867
8959
  exports2.buildStaticValidator = buildStaticValidator;
@@ -8878,6 +8970,8 @@ var require_schema_utilities = __commonJS({
8878
8970
  exports2.reduceSchemaToRequiredFields = reduceSchemaToRequiredFields;
8879
8971
  exports2.flattenObjectBranch = flattenObjectBranch;
8880
8972
  exports2.flattenJSONSchema = flattenJSONSchema;
8973
+ exports2.listAttributesAndSubAttributes = listAttributesAndSubAttributes;
8974
+ exports2.findAllObjectAttributesInTree = findAllObjectAttributesInTree;
8881
8975
  }
8882
8976
  });
8883
8977
 
@@ -8885,7 +8979,7 @@ var require_schema_utilities = __commonJS({
8885
8979
  var require_convention_builder = __commonJS({
8886
8980
  "src/convention_builder.js"(exports2) {
8887
8981
  var fs = require("fs");
8888
- var { buildValidator, urlToStringPair } = require_schema_utilities();
8982
+ var { buildValidator, urlToStringPair, dig, bury, listAttributesAndSubAttributes } = require_schema_utilities();
8889
8983
  function getAttributes(root, convention) {
8890
8984
  let branches = convention.relationships.filter((rel) => rel.containerEntity == root).map((d) => d.mentionedEntity);
8891
8985
  let output = {};
@@ -8940,7 +9034,7 @@ var require_convention_builder = __commonJS({
8940
9034
  }
8941
9035
  ;
8942
9036
  this.baseSchema = baseSchema;
8943
- this.unmodifiedAttributes = new Set(Object.keys(this.baseSchema.properties.attributes.properties));
9037
+ this.unmodifiedAttributes = listAttributesAndSubAttributes(this.baseSchema);
8944
9038
  this.modifiedAttributes = /* @__PURE__ */ new Set([]);
8945
9039
  if (!overlay) {
8946
9040
  this.overlay = {
@@ -8969,10 +9063,11 @@ var require_convention_builder = __commonJS({
8969
9063
  this.schema = {};
8970
9064
  this.schema.$id = `${this.repoURL}/schemata/${this.typeAndBundle.replace("--", "/")}/schema.json`;
8971
9065
  Object.assign(this.schema, this.baseSchema);
8972
- let allModifiedAttributes = new Set(Object.keys(this.overlay.properties.attributes.properties));
9066
+ let allModifiedAttributes = listAttributesAndSubAttributes(this.overlay);
8973
9067
  this.modifiedAttributes = allModifiedAttributes;
8974
9068
  Array.from(this.modifiedAttributes).forEach((attr) => {
8975
- this.schema.properties.attributes.properties[attr] = this.overlay.properties.attributes.properties[attr];
9069
+ let currentValue = dig(this.overlay.properties.attributes.properties, attr);
9070
+ bury(this.schema, `properties.attributes.properties.${attr}`, currentValue, true);
8976
9071
  });
8977
9072
  let originalRequiredFields = this.schema.properties.attributes.required ? this.schema.properties.attributes.required : [];
8978
9073
  let allRequiredSet = Array.from(/* @__PURE__ */ new Set([...originalRequiredFields, ...Array.from(this.requiredFields)]));
@@ -9014,6 +9109,21 @@ var require_convention_builder = __commonJS({
9014
9109
  this.requiredFields.add(attribute);
9015
9110
  this.updateSchema();
9016
9111
  }
9112
+ setGenericSection({ attribute, section, description }) {
9113
+ this.checkAttributeStatus(attribute);
9114
+ bury(this.overlay.properties.attributes.properties, attribute, section, true);
9115
+ if (attribute.match(/\./)) {
9116
+ let firstLevel = attribute.split(/\./)[0];
9117
+ this.overlay.properties.attributes.properties[firstLevel].type = "object";
9118
+ }
9119
+ ;
9120
+ if (description) {
9121
+ bury(this.overlay.properties.attributes.properties, attribute.concat(".description"), description, true);
9122
+ }
9123
+ ;
9124
+ this.updateAttributeStatus(attribute);
9125
+ this.updateSchema();
9126
+ }
9017
9127
  /**
9018
9128
  * Sets an attribute as a constant as indicated by the given value.
9019
9129
  * @param {string} attribute -- Attribute name for the attribute which will be set to a constant.
@@ -9021,14 +9131,8 @@ var require_convention_builder = __commonJS({
9021
9131
  * @param {string} description -- Describes the rationale behind the chosing of the value.
9022
9132
  */
9023
9133
  setConstant({ attribute, value, description }) {
9024
- this.checkAttributeStatus(attribute);
9025
- this.overlay.properties.attributes.properties[attribute] = { const: value };
9026
- if (description) {
9027
- this.overlay.properties.attributes.properties[attribute].description = description;
9028
- }
9029
- ;
9030
- this.updateAttributeStatus(attribute);
9031
- this.updateSchema();
9134
+ let constantSection = { const: value };
9135
+ this.setGenericSection({ attribute, section: constantSection, description });
9032
9136
  }
9033
9137
  /**
9034
9138
  * Sets a regex pattern as a restriction for the value of an attribute. Look into the JSON Schema documentation, as it recomends sticking to a [subset of RegEx](https://website-2v2.pages.dev/understanding-json-schema/reference/regular_expressions).
@@ -9038,17 +9142,11 @@ var require_convention_builder = __commonJS({
9038
9142
  * @param {string} description -- Describes the rationale behind the chosing of the value.
9039
9143
  */
9040
9144
  setPattern({ attribute, pattern, string, description }) {
9041
- this.checkAttributeStatus(attribute);
9042
- this.overlay.properties.attributes.properties[attribute] = {
9145
+ let patternSchemaSection = {
9043
9146
  type: "string",
9044
9147
  pattern: pattern ? pattern : string
9045
9148
  };
9046
- if (description) {
9047
- this.overlay.properties.attributes.properties[attribute].description = description;
9048
- }
9049
- ;
9050
- this.updateAttributeStatus(attribute);
9051
- this.updateSchema();
9149
+ this.setGenericSection({ attribute, section: patternSchemaSection, description });
9052
9150
  }
9053
9151
  /**
9054
9152
  * Sets an attribute as a constrained to a list of possible values.
@@ -9064,13 +9162,8 @@ var require_convention_builder = __commonJS({
9064
9162
  } else {
9065
9163
  subschema = { anyOf: [{ type: "string" }, { enum: valuesArray }] };
9066
9164
  }
9067
- this.overlay.properties.attributes.properties[attribute] = subschema;
9068
- if (description) {
9069
- this.overlay.properties.attributes.properties[attribute].description = description;
9070
- }
9071
9165
  ;
9072
- this.updateAttributeStatus(attribute);
9073
- this.updateSchema();
9166
+ this.setGenericSection({ attribute, section: subschema, description });
9074
9167
  }
9075
9168
  /**
9076
9169
  * 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).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convention_builder",
3
- "version": "1.2.2",
3
+ "version": "1.4.0",
4
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",