convention_builder 1.2.0 → 1.2.2

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.
@@ -8792,7 +8792,21 @@ var require_schema_utilities = __commonJS({
8792
8792
  return output;
8793
8793
  }
8794
8794
  __name(flattenObjectBranch, "flattenObjectBranch");
8795
- function flattenJSONSchema(schema) {
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) {
8796
8810
  let mainAttributes = Object.keys(schema);
8797
8811
  let mainPaths = mainAttributes.flatMap((attr) => {
8798
8812
  let object = flattenObjectBranch(schema, attr);
@@ -8805,19 +8819,53 @@ var require_schema_utilities = __commonJS({
8805
8819
  };
8806
8820
  return pair;
8807
8821
  });
8808
- let dataAttributes = allFlattenedPaths.filter((d) => /\.type$/.test(d.path) && !/relationships/.test(d.path) && d.value != "object").map((d) => d.path.replace(/\.type$/, ""));
8809
- let table = dataAttributes.map((attr) => {
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 attributesTable = dataAttributes.map((attr) => {
8829
+ let isRequired = checkRequiredInSchema(attr, schema);
8810
8830
  let entry = {
8811
8831
  path: attr,
8812
- name: attr.match(/[a-zA-Z]*$/)[0]
8832
+ path_simplified: attr.replace(/\.properties/g, "").replace(/properties\./, ""),
8833
+ name: attr.match(/[a-zA-Z_]*$/)[0],
8834
+ required: isRequired
8813
8835
  };
8814
- let relatedPaths = allFlattenedPaths.filter((d) => d.path.includes(attr)).forEach((d) => {
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) => {
8815
8841
  let key = d.path.replace(`${attr}.`, "");
8816
8842
  let value = d.value;
8817
8843
  entry[key] = value;
8818
8844
  });
8819
8845
  return entry;
8820
8846
  });
8847
+ let relationshipPaths = allFlattenedPaths.filter((d) => d.path.includes(".relationships.")).map((d) => d.path).filter((d) => /\.data.type$/.test(d)).map((d) => d.replace(/\.properties.data.type$/, ""));
8848
+ let relationshipsTable = relationshipPaths.map((rel) => {
8849
+ let entry = {
8850
+ path: rel,
8851
+ path_simplified: rel.replace(/\.properties/g, "").replace(/properties\./, ""),
8852
+ name: rel.match(/[a-zA-Z]*$/)[0]
8853
+ };
8854
+ if (isConvention) {
8855
+ entry.overlay = entry.path_simplified.match(/[a-zA-Z-_]*/)[0];
8856
+ let relatedDataPaths = dig(
8857
+ schema,
8858
+ `${rel}.properties.data.contains.anyOf`
8859
+ );
8860
+ entry.convention_data_targets = relatedDataPaths ? relatedDataPaths.map((d) => d.properties.id.const.$data) : [];
8861
+ }
8862
+ ;
8863
+ return entry;
8864
+ });
8865
+ let table = [
8866
+ ...attributesTable,
8867
+ ...relationshipsTable
8868
+ ];
8821
8869
  return table;
8822
8870
  }
8823
8871
  __name(flattenJSONSchema, "flattenJSONSchema");
@@ -8785,7 +8785,21 @@ var require_schema_utilities = __commonJS({
8785
8785
  return output;
8786
8786
  }
8787
8787
  __name(flattenObjectBranch, "flattenObjectBranch");
8788
- function flattenJSONSchema(schema) {
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) {
8789
8803
  let mainAttributes = Object.keys(schema);
8790
8804
  let mainPaths = mainAttributes.flatMap((attr) => {
8791
8805
  let object = flattenObjectBranch(schema, attr);
@@ -8798,19 +8812,53 @@ var require_schema_utilities = __commonJS({
8798
8812
  };
8799
8813
  return pair;
8800
8814
  });
8801
- let dataAttributes = allFlattenedPaths.filter((d) => /\.type$/.test(d.path) && !/relationships/.test(d.path) && d.value != "object").map((d) => d.path.replace(/\.type$/, ""));
8802
- let table = dataAttributes.map((attr) => {
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 attributesTable = dataAttributes.map((attr) => {
8822
+ let isRequired = checkRequiredInSchema(attr, schema);
8803
8823
  let entry = {
8804
8824
  path: attr,
8805
- name: attr.match(/[a-zA-Z]*$/)[0]
8825
+ path_simplified: attr.replace(/\.properties/g, "").replace(/properties\./, ""),
8826
+ name: attr.match(/[a-zA-Z_]*$/)[0],
8827
+ required: isRequired
8806
8828
  };
8807
- let relatedPaths = allFlattenedPaths.filter((d) => d.path.includes(attr)).forEach((d) => {
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) => {
8808
8834
  let key = d.path.replace(`${attr}.`, "");
8809
8835
  let value = d.value;
8810
8836
  entry[key] = value;
8811
8837
  });
8812
8838
  return entry;
8813
8839
  });
8840
+ let relationshipPaths = allFlattenedPaths.filter((d) => d.path.includes(".relationships.")).map((d) => d.path).filter((d) => /\.data.type$/.test(d)).map((d) => d.replace(/\.properties.data.type$/, ""));
8841
+ let relationshipsTable = relationshipPaths.map((rel) => {
8842
+ let entry = {
8843
+ path: rel,
8844
+ path_simplified: rel.replace(/\.properties/g, "").replace(/properties\./, ""),
8845
+ name: rel.match(/[a-zA-Z]*$/)[0]
8846
+ };
8847
+ if (isConvention) {
8848
+ entry.overlay = entry.path_simplified.match(/[a-zA-Z-_]*/)[0];
8849
+ let relatedDataPaths = dig(
8850
+ schema,
8851
+ `${rel}.properties.data.contains.anyOf`
8852
+ );
8853
+ entry.convention_data_targets = relatedDataPaths ? relatedDataPaths.map((d) => d.properties.id.const.$data) : [];
8854
+ }
8855
+ ;
8856
+ return entry;
8857
+ });
8858
+ let table = [
8859
+ ...attributesTable,
8860
+ ...relationshipsTable
8861
+ ];
8814
8862
  return table;
8815
8863
  }
8816
8864
  __name(flattenJSONSchema, "flattenJSONSchema");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convention_builder",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
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
  }