convention_builder 1.1.0 → 1.2.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.
- package/dist/module/index.js +52 -1
- package/dist/node/index.js +52 -1
- package/package.json +1 -1
package/dist/module/index.js
CHANGED
|
@@ -8773,6 +8773,54 @@ 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 flattenJSONSchema(schema) {
|
|
8796
|
+
let mainAttributes = Object.keys(schema);
|
|
8797
|
+
let mainPaths = mainAttributes.flatMap((attr) => {
|
|
8798
|
+
let object = flattenObjectBranch(schema, attr);
|
|
8799
|
+
return object.paths;
|
|
8800
|
+
});
|
|
8801
|
+
let allFlattenedPaths = mainPaths.map((path) => {
|
|
8802
|
+
let pair = {
|
|
8803
|
+
value: dig(schema, path),
|
|
8804
|
+
path
|
|
8805
|
+
};
|
|
8806
|
+
return pair;
|
|
8807
|
+
});
|
|
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) => {
|
|
8810
|
+
let entry = {
|
|
8811
|
+
path: attr,
|
|
8812
|
+
name: attr.match(/[a-zA-Z]*$/)[0]
|
|
8813
|
+
};
|
|
8814
|
+
let relatedPaths = allFlattenedPaths.filter((d) => d.path.includes(attr)).forEach((d) => {
|
|
8815
|
+
let key = d.path.replace(`${attr}.`, "");
|
|
8816
|
+
let value = d.value;
|
|
8817
|
+
entry[key] = value;
|
|
8818
|
+
});
|
|
8819
|
+
return entry;
|
|
8820
|
+
});
|
|
8821
|
+
return table;
|
|
8822
|
+
}
|
|
8823
|
+
__name(flattenJSONSchema, "flattenJSONSchema");
|
|
8776
8824
|
exports.fixRelationshipDataField = fixRelationshipDataField;
|
|
8777
8825
|
exports.buildValidator = buildValidator;
|
|
8778
8826
|
exports.buildStaticValidator = buildStaticValidator;
|
|
@@ -8787,6 +8835,8 @@ var require_schema_utilities = __commonJS({
|
|
|
8787
8835
|
exports.organizeEntitiesArrayByRelationships = organizeEntitiesArrayByRelationships;
|
|
8788
8836
|
exports.trimNonRequiredFields = trimNonRequiredFields;
|
|
8789
8837
|
exports.reduceSchemaToRequiredFields = reduceSchemaToRequiredFields;
|
|
8838
|
+
exports.flattenObjectBranch = flattenObjectBranch;
|
|
8839
|
+
exports.flattenJSONSchema = flattenJSONSchema;
|
|
8790
8840
|
}
|
|
8791
8841
|
});
|
|
8792
8842
|
|
|
@@ -8884,7 +8934,7 @@ var require_convention_builder = __commonJS({
|
|
|
8884
8934
|
this.schema.properties.attributes.properties[attr] = this.overlay.properties.attributes.properties[attr];
|
|
8885
8935
|
});
|
|
8886
8936
|
let originalRequiredFields = this.schema.properties.attributes.required ? this.schema.properties.attributes.required : [];
|
|
8887
|
-
let allRequiredSet = [...originalRequiredFields, ...Array.from(this.requiredFields)];
|
|
8937
|
+
let allRequiredSet = Array.from(/* @__PURE__ */ new Set([...originalRequiredFields, ...Array.from(this.requiredFields)]));
|
|
8888
8938
|
this.schema.properties.attributes.required = allRequiredSet;
|
|
8889
8939
|
this.schema.description = this.overlay.description;
|
|
8890
8940
|
let validatorObj = buildValidator();
|
|
@@ -9534,6 +9584,7 @@ var require_src = __commonJS({
|
|
|
9534
9584
|
exports.organizeEntitiesArrayByRelationships = schemaUtils.organizeEntitiesArrayByRelationships;
|
|
9535
9585
|
exports.trimNonRequiredFields = schemaUtils.trimNonRequiredFields;
|
|
9536
9586
|
exports.reduceSchemaToRequiredFields = schemaUtils.reduceSchemaToRequiredFields;
|
|
9587
|
+
exports.flattenJSONSchema = schemaUtils.flattenJSONSchema;
|
|
9537
9588
|
}
|
|
9538
9589
|
});
|
|
9539
9590
|
export default require_src();
|
package/dist/node/index.js
CHANGED
|
@@ -8766,6 +8766,54 @@ 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 flattenJSONSchema(schema) {
|
|
8789
|
+
let mainAttributes = Object.keys(schema);
|
|
8790
|
+
let mainPaths = mainAttributes.flatMap((attr) => {
|
|
8791
|
+
let object = flattenObjectBranch(schema, attr);
|
|
8792
|
+
return object.paths;
|
|
8793
|
+
});
|
|
8794
|
+
let allFlattenedPaths = mainPaths.map((path) => {
|
|
8795
|
+
let pair = {
|
|
8796
|
+
value: dig(schema, path),
|
|
8797
|
+
path
|
|
8798
|
+
};
|
|
8799
|
+
return pair;
|
|
8800
|
+
});
|
|
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) => {
|
|
8803
|
+
let entry = {
|
|
8804
|
+
path: attr,
|
|
8805
|
+
name: attr.match(/[a-zA-Z]*$/)[0]
|
|
8806
|
+
};
|
|
8807
|
+
let relatedPaths = allFlattenedPaths.filter((d) => d.path.includes(attr)).forEach((d) => {
|
|
8808
|
+
let key = d.path.replace(`${attr}.`, "");
|
|
8809
|
+
let value = d.value;
|
|
8810
|
+
entry[key] = value;
|
|
8811
|
+
});
|
|
8812
|
+
return entry;
|
|
8813
|
+
});
|
|
8814
|
+
return table;
|
|
8815
|
+
}
|
|
8816
|
+
__name(flattenJSONSchema, "flattenJSONSchema");
|
|
8769
8817
|
exports2.fixRelationshipDataField = fixRelationshipDataField;
|
|
8770
8818
|
exports2.buildValidator = buildValidator;
|
|
8771
8819
|
exports2.buildStaticValidator = buildStaticValidator;
|
|
@@ -8780,6 +8828,8 @@ var require_schema_utilities = __commonJS({
|
|
|
8780
8828
|
exports2.organizeEntitiesArrayByRelationships = organizeEntitiesArrayByRelationships;
|
|
8781
8829
|
exports2.trimNonRequiredFields = trimNonRequiredFields;
|
|
8782
8830
|
exports2.reduceSchemaToRequiredFields = reduceSchemaToRequiredFields;
|
|
8831
|
+
exports2.flattenObjectBranch = flattenObjectBranch;
|
|
8832
|
+
exports2.flattenJSONSchema = flattenJSONSchema;
|
|
8783
8833
|
}
|
|
8784
8834
|
});
|
|
8785
8835
|
|
|
@@ -8877,7 +8927,7 @@ var require_convention_builder = __commonJS({
|
|
|
8877
8927
|
this.schema.properties.attributes.properties[attr] = this.overlay.properties.attributes.properties[attr];
|
|
8878
8928
|
});
|
|
8879
8929
|
let originalRequiredFields = this.schema.properties.attributes.required ? this.schema.properties.attributes.required : [];
|
|
8880
|
-
let allRequiredSet = [...originalRequiredFields, ...Array.from(this.requiredFields)];
|
|
8930
|
+
let allRequiredSet = Array.from(/* @__PURE__ */ new Set([...originalRequiredFields, ...Array.from(this.requiredFields)]));
|
|
8881
8931
|
this.schema.properties.attributes.required = allRequiredSet;
|
|
8882
8932
|
this.schema.description = this.overlay.description;
|
|
8883
8933
|
let validatorObj = buildValidator();
|
|
@@ -9525,6 +9575,7 @@ exports.organizeEntitiesArrayIntoConvention = schemaUtils.organizeEntitiesArrayI
|
|
|
9525
9575
|
exports.organizeEntitiesArrayByRelationships = schemaUtils.organizeEntitiesArrayByRelationships;
|
|
9526
9576
|
exports.trimNonRequiredFields = schemaUtils.trimNonRequiredFields;
|
|
9527
9577
|
exports.reduceSchemaToRequiredFields = schemaUtils.reduceSchemaToRequiredFields;
|
|
9578
|
+
exports.flattenJSONSchema = schemaUtils.flattenJSONSchema;
|
|
9528
9579
|
/*! Bundled license information:
|
|
9529
9580
|
|
|
9530
9581
|
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.
|
|
3
|
+
"version": "1.2.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",
|