convention_builder 1.4.2 → 1.4.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.
@@ -8782,6 +8782,47 @@ var require_schema_utilities = __commonJS({
8782
8782
  };
8783
8783
  }
8784
8784
  __name(organizeEntitiesArrayByRelationships, "organizeEntitiesArrayByRelationships");
8785
+ function arrayToStructuredConvention({ entitiesArray, conventionObject }) {
8786
+ let entities = entitiesArray.map((entity) => {
8787
+ let validations = Object.keys(conventionObject.overlays).map((key) => {
8788
+ var _a;
8789
+ conventionObject.overlays[key].validate(entity);
8790
+ let errors = (_a = conventionObject.overlays[key].validate.errors) == null ? void 0 : _a.filter((d) => !/relationships/.test(d.instancePath));
8791
+ return { overlay: key, errors: errors ? errors : [] };
8792
+ });
8793
+ let passedTests = validations.filter((d) => d.errors.length == 0);
8794
+ let amountPassed = passedTests.length;
8795
+ let output2 = {
8796
+ passedTests,
8797
+ possibleOverlays: passedTests ? passedTests.map((d) => d.overlay) : void 0,
8798
+ allTests: validations,
8799
+ amountPassed,
8800
+ entity
8801
+ };
8802
+ return output2;
8803
+ });
8804
+ let output = {
8805
+ identifiedEntities: entities.filter((d) => d.amountPassed == 1),
8806
+ unrecognizedEntities: entities.filter((d) => d.amountPassed == 0),
8807
+ ambiguousEntities: entities.filter((d) => d.amountPassed > 1)
8808
+ };
8809
+ let assembledEntity = {
8810
+ id: randomUUID(),
8811
+ type: "object"
8812
+ };
8813
+ entities.filter((d) => d.possibleOverlays.length == 1).forEach((entityObj) => {
8814
+ assembledEntity[entityObj.possibleOverlays[0]] = entityObj.entity;
8815
+ });
8816
+ let assembledValidation = conventionObject.validate(assembledEntity);
8817
+ if (conventionObject.validate.errors) {
8818
+ output.errors = conventionObject.validate.errors;
8819
+ }
8820
+ ;
8821
+ output.is_valid = assembledValidation;
8822
+ output.assembled_entity = assembledEntity;
8823
+ return output;
8824
+ }
8825
+ __name(arrayToStructuredConvention, "arrayToStructuredConvention");
8785
8826
  function trimNonRequiredFields(schema, attribute = false) {
8786
8827
  let data;
8787
8828
  if (attribute) {
@@ -9025,6 +9066,7 @@ var require_schema_utilities = __commonJS({
9025
9066
  exports.findMissingEntitiesInExample = findMissingEntitiesInExample;
9026
9067
  exports.organizeEntitiesArrayIntoConvention = organizeEntitiesArrayIntoConvention;
9027
9068
  exports.organizeEntitiesArrayByRelationships = organizeEntitiesArrayByRelationships;
9069
+ exports.arrayToStructuredConvention = arrayToStructuredConvention;
9028
9070
  exports.trimNonRequiredFields = trimNonRequiredFields;
9029
9071
  exports.reduceSchemaToRequiredFields = reduceSchemaToRequiredFields;
9030
9072
  exports.flattenObjectBranch = flattenObjectBranch;
@@ -9405,7 +9447,10 @@ var require_convention_builder = __commonJS({
9405
9447
  if (overlays) {
9406
9448
  let overlayNames = Object.keys(overlays);
9407
9449
  this.overlays = {};
9408
- overlayNames.forEach((ovrl) => this.overlays[ovrl] = new SchemaOverlay(overlays[ovrl]));
9450
+ overlayNames.forEach((ovrl) => {
9451
+ this.overlays[ovrl] = new SchemaOverlay(overlays[ovrl]);
9452
+ this.overlays[ovrl].updateSchema();
9453
+ });
9409
9454
  }
9410
9455
  ;
9411
9456
  if (relationships) {
@@ -9942,7 +9987,7 @@ var require_src = __commonJS({
9942
9987
  exports.exampleImporter = schemaUtils.exampleImporter;
9943
9988
  exports.findMissingEntitiesInExample = schemaUtils.findMissingEntitiesInExample;
9944
9989
  exports.organizeEntitiesArrayIntoConvention = schemaUtils.organizeEntitiesArrayIntoConvention;
9945
- exports.organizeEntitiesArrayByRelationships = schemaUtils.organizeEntitiesArrayByRelationships;
9990
+ exports.arrayToStructuredConvention = schemaUtils.arrayToStructuredConvention;
9946
9991
  exports.trimNonRequiredFields = schemaUtils.trimNonRequiredFields;
9947
9992
  exports.reduceSchemaToRequiredFields = schemaUtils.reduceSchemaToRequiredFields;
9948
9993
  exports.flattenJSONSchema = schemaUtils.flattenJSONSchema;
@@ -8775,6 +8775,47 @@ var require_schema_utilities = __commonJS({
8775
8775
  };
8776
8776
  }
8777
8777
  __name(organizeEntitiesArrayByRelationships, "organizeEntitiesArrayByRelationships");
8778
+ function arrayToStructuredConvention({ entitiesArray, conventionObject }) {
8779
+ let entities = entitiesArray.map((entity) => {
8780
+ let validations = Object.keys(conventionObject.overlays).map((key) => {
8781
+ var _a;
8782
+ conventionObject.overlays[key].validate(entity);
8783
+ let errors = (_a = conventionObject.overlays[key].validate.errors) == null ? void 0 : _a.filter((d) => !/relationships/.test(d.instancePath));
8784
+ return { overlay: key, errors: errors ? errors : [] };
8785
+ });
8786
+ let passedTests = validations.filter((d) => d.errors.length == 0);
8787
+ let amountPassed = passedTests.length;
8788
+ let output2 = {
8789
+ passedTests,
8790
+ possibleOverlays: passedTests ? passedTests.map((d) => d.overlay) : void 0,
8791
+ allTests: validations,
8792
+ amountPassed,
8793
+ entity
8794
+ };
8795
+ return output2;
8796
+ });
8797
+ let output = {
8798
+ identifiedEntities: entities.filter((d) => d.amountPassed == 1),
8799
+ unrecognizedEntities: entities.filter((d) => d.amountPassed == 0),
8800
+ ambiguousEntities: entities.filter((d) => d.amountPassed > 1)
8801
+ };
8802
+ let assembledEntity = {
8803
+ id: randomUUID(),
8804
+ type: "object"
8805
+ };
8806
+ entities.filter((d) => d.possibleOverlays.length == 1).forEach((entityObj) => {
8807
+ assembledEntity[entityObj.possibleOverlays[0]] = entityObj.entity;
8808
+ });
8809
+ let assembledValidation = conventionObject.validate(assembledEntity);
8810
+ if (conventionObject.validate.errors) {
8811
+ output.errors = conventionObject.validate.errors;
8812
+ }
8813
+ ;
8814
+ output.is_valid = assembledValidation;
8815
+ output.assembled_entity = assembledEntity;
8816
+ return output;
8817
+ }
8818
+ __name(arrayToStructuredConvention, "arrayToStructuredConvention");
8778
8819
  function trimNonRequiredFields(schema, attribute = false) {
8779
8820
  let data;
8780
8821
  if (attribute) {
@@ -9018,6 +9059,7 @@ var require_schema_utilities = __commonJS({
9018
9059
  exports2.findMissingEntitiesInExample = findMissingEntitiesInExample;
9019
9060
  exports2.organizeEntitiesArrayIntoConvention = organizeEntitiesArrayIntoConvention;
9020
9061
  exports2.organizeEntitiesArrayByRelationships = organizeEntitiesArrayByRelationships;
9062
+ exports2.arrayToStructuredConvention = arrayToStructuredConvention;
9021
9063
  exports2.trimNonRequiredFields = trimNonRequiredFields;
9022
9064
  exports2.reduceSchemaToRequiredFields = reduceSchemaToRequiredFields;
9023
9065
  exports2.flattenObjectBranch = flattenObjectBranch;
@@ -9398,7 +9440,10 @@ var require_convention_builder = __commonJS({
9398
9440
  if (overlays) {
9399
9441
  let overlayNames = Object.keys(overlays);
9400
9442
  this.overlays = {};
9401
- overlayNames.forEach((ovrl) => this.overlays[ovrl] = new SchemaOverlay2(overlays[ovrl]));
9443
+ overlayNames.forEach((ovrl) => {
9444
+ this.overlays[ovrl] = new SchemaOverlay2(overlays[ovrl]);
9445
+ this.overlays[ovrl].updateSchema();
9446
+ });
9402
9447
  }
9403
9448
  ;
9404
9449
  if (relationships) {
@@ -9933,7 +9978,7 @@ exports.apiComposeTaxonomiesTransformation = schemaUtils.apiComposeTaxonomiesTra
9933
9978
  exports.exampleImporter = schemaUtils.exampleImporter;
9934
9979
  exports.findMissingEntitiesInExample = schemaUtils.findMissingEntitiesInExample;
9935
9980
  exports.organizeEntitiesArrayIntoConvention = schemaUtils.organizeEntitiesArrayIntoConvention;
9936
- exports.organizeEntitiesArrayByRelationships = schemaUtils.organizeEntitiesArrayByRelationships;
9981
+ exports.arrayToStructuredConvention = schemaUtils.arrayToStructuredConvention;
9937
9982
  exports.trimNonRequiredFields = schemaUtils.trimNonRequiredFields;
9938
9983
  exports.reduceSchemaToRequiredFields = schemaUtils.reduceSchemaToRequiredFields;
9939
9984
  exports.flattenJSONSchema = schemaUtils.flattenJSONSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convention_builder",
3
- "version": "1.4.2",
3
+ "version": "1.4.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",