convention_builder 1.0.0 → 1.1.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.
@@ -8814,7 +8814,8 @@ var require_convention_builder = __commonJS({
8814
8814
  overlay = false,
8815
8815
  originalSrcScript,
8816
8816
  trivial = false,
8817
- baseSchemataFolder = `${__dirname}/../../../../input/collection`
8817
+ baseSchemataFolder = `${__dirname}/../../../../input/collection`,
8818
+ requiredFields = []
8818
8819
  }) {
8819
8820
  this.name = name;
8820
8821
  this.typeAndBundle = typeAndBundle;
@@ -8826,6 +8827,7 @@ var require_convention_builder = __commonJS({
8826
8827
  this.strictEnums = strictEnums;
8827
8828
  this.trivial = trivial;
8828
8829
  this.baseSchemataFolder = baseSchemataFolder;
8830
+ this.requiredFields = Array.isArray(requiredFields) ? new Set(requiredFields) : /* @__PURE__ */ new Set([]);
8829
8831
  let validBaseSchemaPattern = typeAndBundle.match(/^[a-z_]*--[a-z_]*$/) ? typeAndBundle.match(/^[a-z_]*--[a-z_]*$/).index == 0 : false;
8830
8832
  if (!validBaseSchemaPattern) {
8831
8833
  throw new Error(`No schema for ${typeAndBundle} was found, as wanted by ${name}. This parameter should be a type--bundle pair, as farmOS mandates (examples are "log--lab_test" and "asset--land").`);
@@ -8881,6 +8883,9 @@ var require_convention_builder = __commonJS({
8881
8883
  Array.from(this.modifiedAttributes).forEach((attr) => {
8882
8884
  this.schema.properties.attributes.properties[attr] = this.overlay.properties.attributes.properties[attr];
8883
8885
  });
8886
+ let originalRequiredFields = this.schema.properties.attributes.required ? this.schema.properties.attributes.required : [];
8887
+ let allRequiredSet = Array.from(/* @__PURE__ */ new Set([...originalRequiredFields, ...Array.from(this.requiredFields)]));
8888
+ this.schema.properties.attributes.required = allRequiredSet;
8884
8889
  this.schema.description = this.overlay.description;
8885
8890
  let validatorObj = buildValidator();
8886
8891
  this.validate = validatorObj.compile(this.schema);
@@ -8910,6 +8915,14 @@ var require_convention_builder = __commonJS({
8910
8915
  this.overlay.description = description;
8911
8916
  this.updateSchema();
8912
8917
  }
8918
+ /**
8919
+ * Adds an attribute to the set of required attributes.
8920
+ * @param {} attribute
8921
+ */
8922
+ setRequiredAttribute(attribute) {
8923
+ this.requiredFields.add(attribute);
8924
+ this.updateSchema();
8925
+ }
8913
8926
  /**
8914
8927
  * Sets an attribute as a constant as indicated by the given value.
8915
8928
  * @param {string} attribute -- Attribute name for the attribute which will be set to a constant.
@@ -8807,7 +8807,8 @@ var require_convention_builder = __commonJS({
8807
8807
  overlay = false,
8808
8808
  originalSrcScript,
8809
8809
  trivial = false,
8810
- baseSchemataFolder = `${__dirname}/../../../../input/collection`
8810
+ baseSchemataFolder = `${__dirname}/../../../../input/collection`,
8811
+ requiredFields = []
8811
8812
  }) {
8812
8813
  this.name = name;
8813
8814
  this.typeAndBundle = typeAndBundle;
@@ -8819,6 +8820,7 @@ var require_convention_builder = __commonJS({
8819
8820
  this.strictEnums = strictEnums;
8820
8821
  this.trivial = trivial;
8821
8822
  this.baseSchemataFolder = baseSchemataFolder;
8823
+ this.requiredFields = Array.isArray(requiredFields) ? new Set(requiredFields) : /* @__PURE__ */ new Set([]);
8822
8824
  let validBaseSchemaPattern = typeAndBundle.match(/^[a-z_]*--[a-z_]*$/) ? typeAndBundle.match(/^[a-z_]*--[a-z_]*$/).index == 0 : false;
8823
8825
  if (!validBaseSchemaPattern) {
8824
8826
  throw new Error(`No schema for ${typeAndBundle} was found, as wanted by ${name}. This parameter should be a type--bundle pair, as farmOS mandates (examples are "log--lab_test" and "asset--land").`);
@@ -8874,6 +8876,9 @@ var require_convention_builder = __commonJS({
8874
8876
  Array.from(this.modifiedAttributes).forEach((attr) => {
8875
8877
  this.schema.properties.attributes.properties[attr] = this.overlay.properties.attributes.properties[attr];
8876
8878
  });
8879
+ let originalRequiredFields = this.schema.properties.attributes.required ? this.schema.properties.attributes.required : [];
8880
+ let allRequiredSet = Array.from(/* @__PURE__ */ new Set([...originalRequiredFields, ...Array.from(this.requiredFields)]));
8881
+ this.schema.properties.attributes.required = allRequiredSet;
8877
8882
  this.schema.description = this.overlay.description;
8878
8883
  let validatorObj = buildValidator();
8879
8884
  this.validate = validatorObj.compile(this.schema);
@@ -8903,6 +8908,14 @@ var require_convention_builder = __commonJS({
8903
8908
  this.overlay.description = description;
8904
8909
  this.updateSchema();
8905
8910
  }
8911
+ /**
8912
+ * Adds an attribute to the set of required attributes.
8913
+ * @param {} attribute
8914
+ */
8915
+ setRequiredAttribute(attribute) {
8916
+ this.requiredFields.add(attribute);
8917
+ this.updateSchema();
8918
+ }
8906
8919
  /**
8907
8920
  * Sets an attribute as a constant as indicated by the given value.
8908
8921
  * @param {string} attribute -- Attribute name for the attribute which will be set to a constant.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convention_builder",
3
- "version": "1.0.0",
3
+ "version": "1.1.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",