convention_builder 1.2.1 → 1.2.3

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,8 +8792,10 @@ var require_schema_utilities = __commonJS({
8792
8792
  return output;
8793
8793
  }
8794
8794
  __name(flattenObjectBranch, "flattenObjectBranch");
8795
+ var nameRegex = /[0-9a-zA-Z_]*$/;
8796
+ var overlayRegex = /[0-9a-zA-Z-_]*/;
8795
8797
  function checkRequiredInSchema(path, schema) {
8796
- let attributeName = path.match(/[a-zA-Z_]*$/)[0];
8798
+ let attributeName = path.match(nameRegex)[0];
8797
8799
  let pathFormat = new RegExp(`properties.${attributeName}`).test(path);
8798
8800
  if (!pathFormat) {
8799
8801
  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} .`);
@@ -8825,25 +8827,47 @@ var require_schema_utilities = __commonJS({
8825
8827
  let secondToLastAttr = attributes[attributes.length - 2];
8826
8828
  return secondToLastAttr == "properties";
8827
8829
  });
8828
- let table = dataAttributes.map((attr) => {
8830
+ let attributesTable = dataAttributes.map((attr) => {
8829
8831
  let isRequired = checkRequiredInSchema(attr, schema);
8830
8832
  let entry = {
8831
8833
  path: attr,
8832
8834
  path_simplified: attr.replace(/\.properties/g, "").replace(/properties\./, ""),
8833
- name: attr.match(/[a-zA-Z]*$/)[0],
8835
+ name: attr.match(nameRegex)[0],
8834
8836
  required: isRequired
8835
8837
  };
8836
8838
  if (isConvention) {
8837
- entry.overlay = entry.path_simplified.match(/[a-zA-Z-]*/)[0];
8839
+ entry.overlay = entry.path_simplified.match(overlayRegex)[0];
8838
8840
  }
8839
8841
  ;
8840
- allFlattenedPaths.filter((d) => d.path.includes(`${attr}.`)).forEach((d) => {
8842
+ allFlattenedPaths.filter((d) => d.path.includes(`${attr}.`) && !d.path.includes("items")).forEach((d) => {
8841
8843
  let key = d.path.replace(`${attr}.`, "");
8842
8844
  let value = d.value;
8843
8845
  entry[key] = value;
8844
8846
  });
8845
8847
  return entry;
8846
8848
  });
8849
+ 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$/, ""));
8850
+ let relationshipsTable = relationshipPaths.map((rel) => {
8851
+ let entry = {
8852
+ path: rel,
8853
+ path_simplified: rel.replace(/\.properties/g, "").replace(/properties\./, ""),
8854
+ name: rel.match(nameRegex)[0]
8855
+ };
8856
+ if (isConvention) {
8857
+ entry.overlay = entry.path_simplified.match(overlayRegex)[0];
8858
+ let relatedDataPaths = dig(
8859
+ schema,
8860
+ `${rel}.properties.data.contains.anyOf`
8861
+ );
8862
+ entry.convention_data_targets = relatedDataPaths ? relatedDataPaths.map((d) => d.properties.id.const.$data) : [];
8863
+ }
8864
+ ;
8865
+ return entry;
8866
+ });
8867
+ let table = [
8868
+ ...attributesTable,
8869
+ ...relationshipsTable
8870
+ ];
8847
8871
  return table;
8848
8872
  }
8849
8873
  __name(flattenJSONSchema, "flattenJSONSchema");
@@ -8785,8 +8785,10 @@ var require_schema_utilities = __commonJS({
8785
8785
  return output;
8786
8786
  }
8787
8787
  __name(flattenObjectBranch, "flattenObjectBranch");
8788
+ var nameRegex = /[0-9a-zA-Z_]*$/;
8789
+ var overlayRegex = /[0-9a-zA-Z-_]*/;
8788
8790
  function checkRequiredInSchema(path, schema) {
8789
- let attributeName = path.match(/[a-zA-Z_]*$/)[0];
8791
+ let attributeName = path.match(nameRegex)[0];
8790
8792
  let pathFormat = new RegExp(`properties.${attributeName}`).test(path);
8791
8793
  if (!pathFormat) {
8792
8794
  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} .`);
@@ -8818,25 +8820,47 @@ var require_schema_utilities = __commonJS({
8818
8820
  let secondToLastAttr = attributes[attributes.length - 2];
8819
8821
  return secondToLastAttr == "properties";
8820
8822
  });
8821
- let table = dataAttributes.map((attr) => {
8823
+ let attributesTable = dataAttributes.map((attr) => {
8822
8824
  let isRequired = checkRequiredInSchema(attr, schema);
8823
8825
  let entry = {
8824
8826
  path: attr,
8825
8827
  path_simplified: attr.replace(/\.properties/g, "").replace(/properties\./, ""),
8826
- name: attr.match(/[a-zA-Z]*$/)[0],
8828
+ name: attr.match(nameRegex)[0],
8827
8829
  required: isRequired
8828
8830
  };
8829
8831
  if (isConvention) {
8830
- entry.overlay = entry.path_simplified.match(/[a-zA-Z-]*/)[0];
8832
+ entry.overlay = entry.path_simplified.match(overlayRegex)[0];
8831
8833
  }
8832
8834
  ;
8833
- allFlattenedPaths.filter((d) => d.path.includes(`${attr}.`)).forEach((d) => {
8835
+ allFlattenedPaths.filter((d) => d.path.includes(`${attr}.`) && !d.path.includes("items")).forEach((d) => {
8834
8836
  let key = d.path.replace(`${attr}.`, "");
8835
8837
  let value = d.value;
8836
8838
  entry[key] = value;
8837
8839
  });
8838
8840
  return entry;
8839
8841
  });
8842
+ 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$/, ""));
8843
+ let relationshipsTable = relationshipPaths.map((rel) => {
8844
+ let entry = {
8845
+ path: rel,
8846
+ path_simplified: rel.replace(/\.properties/g, "").replace(/properties\./, ""),
8847
+ name: rel.match(nameRegex)[0]
8848
+ };
8849
+ if (isConvention) {
8850
+ entry.overlay = entry.path_simplified.match(overlayRegex)[0];
8851
+ let relatedDataPaths = dig(
8852
+ schema,
8853
+ `${rel}.properties.data.contains.anyOf`
8854
+ );
8855
+ entry.convention_data_targets = relatedDataPaths ? relatedDataPaths.map((d) => d.properties.id.const.$data) : [];
8856
+ }
8857
+ ;
8858
+ return entry;
8859
+ });
8860
+ let table = [
8861
+ ...attributesTable,
8862
+ ...relationshipsTable
8863
+ ];
8840
8864
  return table;
8841
8865
  }
8842
8866
  __name(flattenJSONSchema, "flattenJSONSchema");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convention_builder",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
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",