convention_builder 1.1.1 → 1.2.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.
@@ -8773,6 +8773,80 @@ var require_schema_utilities = __commonJS({
8773
8773
  return output;
8774
8774
  }
8775
8775
  __name(reduceSchemaToRequiredFields, "reduceSchemaToRequiredFields");
8776
+ function flattenObjectBranch(parentBranch, targetAttribute) {
8777
+ let output = {};
8778
+ if (typeof parentBranch[targetAttribute] == "object" && !Array.isArray(parentBranch[targetAttribute]) && parentBranch[targetAttribute]) {
8779
+ output.situation = "paths";
8780
+ let childAttributes = Object.keys(parentBranch[targetAttribute]);
8781
+ let paths = childAttributes.flatMap((attr) => {
8782
+ let leafs = flattenObjectBranch(parentBranch[targetAttribute], attr);
8783
+ return leafs.paths.map((path) => `${targetAttribute}.${path}`);
8784
+ });
8785
+ output.paths = paths;
8786
+ } else {
8787
+ output.situation = "value";
8788
+ output.paths = [targetAttribute];
8789
+ output.value = parentBranch[targetAttribute];
8790
+ }
8791
+ ;
8792
+ return output;
8793
+ }
8794
+ __name(flattenObjectBranch, "flattenObjectBranch");
8795
+ function checkRequiredInSchema(path, schema) {
8796
+ let attributeName = path.match(/[a-zA-Z_]*$/)[0];
8797
+ let pathFormat = new RegExp(`properties.${attributeName}`).test(path);
8798
+ if (!pathFormat) {
8799
+ 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} .`);
8800
+ }
8801
+ ;
8802
+ let containerPath = path.replace(new RegExp(`.properties.${attributeName}$`), "");
8803
+ let container = dig(schema, containerPath);
8804
+ let requiredFields = container.required ? container.required : [];
8805
+ let output = requiredFields.includes(attributeName);
8806
+ return output;
8807
+ }
8808
+ __name(checkRequiredInSchema, "checkRequiredInSchema");
8809
+ function flattenJSONSchema(schema, isConvention = false) {
8810
+ let mainAttributes = Object.keys(schema);
8811
+ let mainPaths = mainAttributes.flatMap((attr) => {
8812
+ let object = flattenObjectBranch(schema, attr);
8813
+ return object.paths;
8814
+ });
8815
+ let allFlattenedPaths = mainPaths.map((path) => {
8816
+ let pair = {
8817
+ value: dig(schema, path),
8818
+ path
8819
+ };
8820
+ return pair;
8821
+ });
8822
+ let dataAttributes = allFlattenedPaths.filter((d) => /\.type$/.test(d.path) && !/relationships/.test(d.path) && d.value != "object").map((d) => d.path.replace(/\.type$/, "")).filter((d) => !/\.id$/.test(d)).filter((d) => {
8823
+ let attributes = d.split(".");
8824
+ let lastAttr = attributes[attributes.length - 1];
8825
+ let secondToLastAttr = attributes[attributes.length - 2];
8826
+ return secondToLastAttr == "properties";
8827
+ });
8828
+ let table = dataAttributes.map((attr) => {
8829
+ let isRequired = checkRequiredInSchema(attr, schema);
8830
+ let entry = {
8831
+ path: attr,
8832
+ path_simplified: attr.replace(/\.properties/g, "").replace(/properties\./, ""),
8833
+ name: attr.match(/[a-zA-Z]*$/)[0],
8834
+ required: isRequired
8835
+ };
8836
+ if (isConvention) {
8837
+ entry.overlay = entry.path_simplified.match(/[a-zA-Z-]*/)[0];
8838
+ }
8839
+ ;
8840
+ allFlattenedPaths.filter((d) => d.path.includes(`${attr}.`)).forEach((d) => {
8841
+ let key = d.path.replace(`${attr}.`, "");
8842
+ let value = d.value;
8843
+ entry[key] = value;
8844
+ });
8845
+ return entry;
8846
+ });
8847
+ return table;
8848
+ }
8849
+ __name(flattenJSONSchema, "flattenJSONSchema");
8776
8850
  exports.fixRelationshipDataField = fixRelationshipDataField;
8777
8851
  exports.buildValidator = buildValidator;
8778
8852
  exports.buildStaticValidator = buildStaticValidator;
@@ -8787,6 +8861,8 @@ var require_schema_utilities = __commonJS({
8787
8861
  exports.organizeEntitiesArrayByRelationships = organizeEntitiesArrayByRelationships;
8788
8862
  exports.trimNonRequiredFields = trimNonRequiredFields;
8789
8863
  exports.reduceSchemaToRequiredFields = reduceSchemaToRequiredFields;
8864
+ exports.flattenObjectBranch = flattenObjectBranch;
8865
+ exports.flattenJSONSchema = flattenJSONSchema;
8790
8866
  }
8791
8867
  });
8792
8868
 
@@ -9534,6 +9610,7 @@ var require_src = __commonJS({
9534
9610
  exports.organizeEntitiesArrayByRelationships = schemaUtils.organizeEntitiesArrayByRelationships;
9535
9611
  exports.trimNonRequiredFields = schemaUtils.trimNonRequiredFields;
9536
9612
  exports.reduceSchemaToRequiredFields = schemaUtils.reduceSchemaToRequiredFields;
9613
+ exports.flattenJSONSchema = schemaUtils.flattenJSONSchema;
9537
9614
  }
9538
9615
  });
9539
9616
  export default require_src();
@@ -8766,6 +8766,80 @@ var require_schema_utilities = __commonJS({
8766
8766
  return output;
8767
8767
  }
8768
8768
  __name(reduceSchemaToRequiredFields, "reduceSchemaToRequiredFields");
8769
+ function flattenObjectBranch(parentBranch, targetAttribute) {
8770
+ let output = {};
8771
+ if (typeof parentBranch[targetAttribute] == "object" && !Array.isArray(parentBranch[targetAttribute]) && parentBranch[targetAttribute]) {
8772
+ output.situation = "paths";
8773
+ let childAttributes = Object.keys(parentBranch[targetAttribute]);
8774
+ let paths = childAttributes.flatMap((attr) => {
8775
+ let leafs = flattenObjectBranch(parentBranch[targetAttribute], attr);
8776
+ return leafs.paths.map((path) => `${targetAttribute}.${path}`);
8777
+ });
8778
+ output.paths = paths;
8779
+ } else {
8780
+ output.situation = "value";
8781
+ output.paths = [targetAttribute];
8782
+ output.value = parentBranch[targetAttribute];
8783
+ }
8784
+ ;
8785
+ return output;
8786
+ }
8787
+ __name(flattenObjectBranch, "flattenObjectBranch");
8788
+ function checkRequiredInSchema(path, schema) {
8789
+ let attributeName = path.match(/[a-zA-Z_]*$/)[0];
8790
+ let pathFormat = new RegExp(`properties.${attributeName}`).test(path);
8791
+ if (!pathFormat) {
8792
+ 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} .`);
8793
+ }
8794
+ ;
8795
+ let containerPath = path.replace(new RegExp(`.properties.${attributeName}$`), "");
8796
+ let container = dig(schema, containerPath);
8797
+ let requiredFields = container.required ? container.required : [];
8798
+ let output = requiredFields.includes(attributeName);
8799
+ return output;
8800
+ }
8801
+ __name(checkRequiredInSchema, "checkRequiredInSchema");
8802
+ function flattenJSONSchema(schema, isConvention = false) {
8803
+ let mainAttributes = Object.keys(schema);
8804
+ let mainPaths = mainAttributes.flatMap((attr) => {
8805
+ let object = flattenObjectBranch(schema, attr);
8806
+ return object.paths;
8807
+ });
8808
+ let allFlattenedPaths = mainPaths.map((path) => {
8809
+ let pair = {
8810
+ value: dig(schema, path),
8811
+ path
8812
+ };
8813
+ return pair;
8814
+ });
8815
+ let dataAttributes = allFlattenedPaths.filter((d) => /\.type$/.test(d.path) && !/relationships/.test(d.path) && d.value != "object").map((d) => d.path.replace(/\.type$/, "")).filter((d) => !/\.id$/.test(d)).filter((d) => {
8816
+ let attributes = d.split(".");
8817
+ let lastAttr = attributes[attributes.length - 1];
8818
+ let secondToLastAttr = attributes[attributes.length - 2];
8819
+ return secondToLastAttr == "properties";
8820
+ });
8821
+ let table = dataAttributes.map((attr) => {
8822
+ let isRequired = checkRequiredInSchema(attr, schema);
8823
+ let entry = {
8824
+ path: attr,
8825
+ path_simplified: attr.replace(/\.properties/g, "").replace(/properties\./, ""),
8826
+ name: attr.match(/[a-zA-Z]*$/)[0],
8827
+ required: isRequired
8828
+ };
8829
+ if (isConvention) {
8830
+ entry.overlay = entry.path_simplified.match(/[a-zA-Z-]*/)[0];
8831
+ }
8832
+ ;
8833
+ allFlattenedPaths.filter((d) => d.path.includes(`${attr}.`)).forEach((d) => {
8834
+ let key = d.path.replace(`${attr}.`, "");
8835
+ let value = d.value;
8836
+ entry[key] = value;
8837
+ });
8838
+ return entry;
8839
+ });
8840
+ return table;
8841
+ }
8842
+ __name(flattenJSONSchema, "flattenJSONSchema");
8769
8843
  exports2.fixRelationshipDataField = fixRelationshipDataField;
8770
8844
  exports2.buildValidator = buildValidator;
8771
8845
  exports2.buildStaticValidator = buildStaticValidator;
@@ -8780,6 +8854,8 @@ var require_schema_utilities = __commonJS({
8780
8854
  exports2.organizeEntitiesArrayByRelationships = organizeEntitiesArrayByRelationships;
8781
8855
  exports2.trimNonRequiredFields = trimNonRequiredFields;
8782
8856
  exports2.reduceSchemaToRequiredFields = reduceSchemaToRequiredFields;
8857
+ exports2.flattenObjectBranch = flattenObjectBranch;
8858
+ exports2.flattenJSONSchema = flattenJSONSchema;
8783
8859
  }
8784
8860
  });
8785
8861
 
@@ -9525,6 +9601,7 @@ exports.organizeEntitiesArrayIntoConvention = schemaUtils.organizeEntitiesArrayI
9525
9601
  exports.organizeEntitiesArrayByRelationships = schemaUtils.organizeEntitiesArrayByRelationships;
9526
9602
  exports.trimNonRequiredFields = schemaUtils.trimNonRequiredFields;
9527
9603
  exports.reduceSchemaToRequiredFields = schemaUtils.reduceSchemaToRequiredFields;
9604
+ exports.flattenJSONSchema = schemaUtils.flattenJSONSchema;
9528
9605
  /*! Bundled license information:
9529
9606
 
9530
9607
  uri-js/dist/es5/uri.all.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convention_builder",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
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",
@@ -44,6 +44,7 @@
44
44
  "devDependencies": {
45
45
  "esbuild": "^0.19.7",
46
46
  "jest": "^29.7.0",
47
- "jest-junit": "^15.0.0"
47
+ "jest-junit": "^15.0.0",
48
+ "papaparse": "^5.4.1"
48
49
  }
49
50
  }