convention_builder 1.7.1 → 1.7.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.
@@ -10546,6 +10546,7 @@ var require_convention_builder = __commonJS({
10546
10546
  this.trivial = trivial;
10547
10547
  this.baseSchemataFolder = baseSchemataFolder;
10548
10548
  this.requiredFields = Array.isArray(requiredFields) ? new Set(requiredFields) : /* @__PURE__ */ new Set([]);
10549
+ this.gitlabProjectId = gitlabProjectId;
10549
10550
  let validBaseSchemaPattern = typeAndBundle.match(/^[a-z_]*--[a-z_]*$/) ? typeAndBundle.match(/^[a-z_]*--[a-z_]*$/).index == 0 : false;
10550
10551
  if (!validBaseSchemaPattern) {
10551
10552
  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").`);
@@ -10708,6 +10709,10 @@ var require_convention_builder = __commonJS({
10708
10709
  setEnum({ attribute, valuesArray, description }) {
10709
10710
  this.checkAttributeStatus(attribute);
10710
10711
  let subschema;
10712
+ if (!valuesArray) {
10713
+ throw new Error(`Attribute 'valuesArray' is empty for ${attribute}, which makes the schema impossible to satisfy.`);
10714
+ }
10715
+ ;
10711
10716
  if (this.strictEnums) {
10712
10717
  subschema = { enum: valuesArray };
10713
10718
  } else {
@@ -11008,6 +11013,7 @@ var require_convention_builder = __commonJS({
11008
11013
  if (isOverlay) {
11009
11014
  try {
11010
11015
  schemaOverlayObject = new SchemaOverlay(JSON.parse(fs.readFileSync(`${this.storagePath()}/overlays/${schemaOverlayObject}/object.json`)));
11016
+ schemaOverlayObject.global = true;
11011
11017
  } catch (e) {
11012
11018
  if (e.code == "ENOENT" && !overlaysOnly) {
11013
11019
  throw new Error(`Couldn't find any file corresponding to the string provided, searched for ${this.storagePath()}/overlays/${schemaOverlayName}/object.json. Might be the case that you are calling.`);
@@ -11069,7 +11075,8 @@ var require_convention_builder = __commonJS({
11069
11075
  let containerSchema = this.overlays[containerEntity].schema;
11070
11076
  let relationshipAttributes = Object.keys(containerSchema.properties.relationships.properties);
11071
11077
  if (!relationshipAttributes.includes(relationName)) {
11072
- throw new Error(`The provided relationship field, '${relationName}', doesn't seem to be a valid field in the schema for '${containerSchema.properties.type.const}'. Available fields are: ${relationshipAttributes.join(", ")}.`);
11078
+ throw new Error(`The provided relationship field, '${relationName}', doesn't seem to be a valid field in the schema for '${containerSchema.properties.type.const}'. Available fields are: ${relationshipAttributes ? relationshipAttributes.join(", ") : "none"}.
11079
+ Schema read from ${this.baseSchemataFolder}`);
11073
11080
  }
11074
11081
  ;
11075
11082
  this.relationships.push({ containerEntity, relationName, mentionedEntity, required });
@@ -11392,7 +11399,11 @@ import TabItem from '@theme/TabItem';
11392
11399
  }
11393
11400
  ;
11394
11401
  Object.keys(this.overlays).forEach((overlayName) => {
11395
- this.overlays[overlayName].store(false);
11402
+ let currentOverlay = this.overlays[overlayName];
11403
+ if (!currentOverlay.trivial && !currentOverlay.global) {
11404
+ currentOverlay.store(false);
11405
+ }
11406
+ ;
11396
11407
  });
11397
11408
  if (overlaysOnly) {
11398
11409
  console.log(`Only storing overlays due to overlaysOnly switch.`);
@@ -11479,9 +11490,9 @@ import TabItem from '@theme/TabItem';
11479
11490
  typeAndBundle: target,
11480
11491
  attributeOverlayName: this.overlayName,
11481
11492
  baseSchemataFolder: this.baseSchemataFolder,
11482
- gitlabProjectId: this.gitlabProjectId
11493
+ gitlabProjectId
11483
11494
  });
11484
- currentOverlay.gitlabProjectId = this.gitlabProjectId;
11495
+ currentOverlay.gitlabProjectId = gitlabProjectId;
11485
11496
  this.overlays.push(currentOverlay);
11486
11497
  });
11487
11498
  }
@@ -25356,9 +25367,17 @@ var require_array_examples_preparator = __commonJS({
25356
25367
  var utils = require_schema_utilities();
25357
25368
  var axios = require_axios();
25358
25369
  var _ArrayDataOrganizer = class _ArrayDataOrganizer {
25359
- constructor({ exampleArray }) {
25370
+ constructor({
25371
+ exampleArray,
25372
+ storageFolder = `${__dirname}/../../../../output/collection/overlays`,
25373
+ baseSchemataFolder = `${__dirname}/../../../../input/collection`,
25374
+ predefinedConventions
25375
+ }) {
25360
25376
  this.exampleArray = exampleArray;
25361
25377
  this.instances = [];
25378
+ this.storageFolder = storageFolder;
25379
+ this.baseSchemataFolder = baseSchemataFolder;
25380
+ this.predefinedConventions = predefinedConventions;
25362
25381
  }
25363
25382
  /**
25364
25383
  * Will retrieve the data needed and structure the example.
@@ -25390,11 +25409,21 @@ var require_array_examples_preparator = __commonJS({
25390
25409
  return entries;
25391
25410
  });
25392
25411
  let allMentionedConventions = Array.from(new Set(this.exampleArray.filter((d) => d.type == "taxonomy_term--convention").map((d) => d.attributes.external_uri)));
25393
- let conventionSchemataPromises = allMentionedConventions.map((url) => __async(this, null, function* () {
25394
- return yield axios.get(url.replace("schema.json", "object.json")).then((res) => res.data);
25395
- }));
25396
- let conventionObjects = yield Promise.all(conventionSchemataPromises);
25397
- let conventions = conventionObjects.map((d) => new builder.ConventionSchema(d));
25412
+ let conventionObjects;
25413
+ if (!this.predefinedConventions) {
25414
+ let conventionSchemataPromises = allMentionedConventions.map((url) => __async(this, null, function* () {
25415
+ return yield axios.get(url.replace("schema.json", "object.json")).then((res) => res.data);
25416
+ }));
25417
+ conventionObjects = yield Promise.all(conventionSchemataPromises);
25418
+ } else {
25419
+ conventionObjects = this.predefinedConventions;
25420
+ }
25421
+ ;
25422
+ let conventions = conventionObjects.map((d) => {
25423
+ d.baseSchemataFolder = this.baseSchemataFolder;
25424
+ d.storageFolder = this.storageFolder;
25425
+ return new builder.ConventionSchema(d);
25426
+ });
25398
25427
  this.detected_conventions = conventionCarrierEntities;
25399
25428
  this.conventions = conventions;
25400
25429
  });
@@ -25406,6 +25435,12 @@ var require_array_examples_preparator = __commonJS({
25406
25435
  return __async(this, null, function* () {
25407
25436
  let structuredInstances = yield this.detected_conventions.forEach((instance) => __async(this, null, function* () {
25408
25437
  let currentConvention = yield this.conventions.find((c) => c.schema.$id == instance.convention_entity.attributes.external_uri);
25438
+ if (!currentConvention) {
25439
+ throw new Error(`Couldn't find a convention matching URI ${instance.convention_entity.attributes.external_uri}
25440
+ available ones are:
25441
+ ${this.conventions.map((d) => d.schema.$id).join("\n")}`);
25442
+ }
25443
+ ;
25409
25444
  this.instances.push(
25410
25445
  utils.arrayToStructuredConvention(
25411
25446
  {
@@ -10539,6 +10539,7 @@ var require_convention_builder = __commonJS({
10539
10539
  this.trivial = trivial;
10540
10540
  this.baseSchemataFolder = baseSchemataFolder;
10541
10541
  this.requiredFields = Array.isArray(requiredFields) ? new Set(requiredFields) : /* @__PURE__ */ new Set([]);
10542
+ this.gitlabProjectId = gitlabProjectId;
10542
10543
  let validBaseSchemaPattern = typeAndBundle.match(/^[a-z_]*--[a-z_]*$/) ? typeAndBundle.match(/^[a-z_]*--[a-z_]*$/).index == 0 : false;
10543
10544
  if (!validBaseSchemaPattern) {
10544
10545
  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").`);
@@ -10701,6 +10702,10 @@ var require_convention_builder = __commonJS({
10701
10702
  setEnum({ attribute, valuesArray, description }) {
10702
10703
  this.checkAttributeStatus(attribute);
10703
10704
  let subschema;
10705
+ if (!valuesArray) {
10706
+ throw new Error(`Attribute 'valuesArray' is empty for ${attribute}, which makes the schema impossible to satisfy.`);
10707
+ }
10708
+ ;
10704
10709
  if (this.strictEnums) {
10705
10710
  subschema = { enum: valuesArray };
10706
10711
  } else {
@@ -11001,6 +11006,7 @@ var require_convention_builder = __commonJS({
11001
11006
  if (isOverlay) {
11002
11007
  try {
11003
11008
  schemaOverlayObject = new SchemaOverlay2(JSON.parse(fs.readFileSync(`${this.storagePath()}/overlays/${schemaOverlayObject}/object.json`)));
11009
+ schemaOverlayObject.global = true;
11004
11010
  } catch (e) {
11005
11011
  if (e.code == "ENOENT" && !overlaysOnly) {
11006
11012
  throw new Error(`Couldn't find any file corresponding to the string provided, searched for ${this.storagePath()}/overlays/${schemaOverlayName}/object.json. Might be the case that you are calling.`);
@@ -11062,7 +11068,8 @@ var require_convention_builder = __commonJS({
11062
11068
  let containerSchema = this.overlays[containerEntity].schema;
11063
11069
  let relationshipAttributes = Object.keys(containerSchema.properties.relationships.properties);
11064
11070
  if (!relationshipAttributes.includes(relationName)) {
11065
- throw new Error(`The provided relationship field, '${relationName}', doesn't seem to be a valid field in the schema for '${containerSchema.properties.type.const}'. Available fields are: ${relationshipAttributes.join(", ")}.`);
11071
+ throw new Error(`The provided relationship field, '${relationName}', doesn't seem to be a valid field in the schema for '${containerSchema.properties.type.const}'. Available fields are: ${relationshipAttributes ? relationshipAttributes.join(", ") : "none"}.
11072
+ Schema read from ${this.baseSchemataFolder}`);
11066
11073
  }
11067
11074
  ;
11068
11075
  this.relationships.push({ containerEntity, relationName, mentionedEntity, required });
@@ -11385,7 +11392,11 @@ import TabItem from '@theme/TabItem';
11385
11392
  }
11386
11393
  ;
11387
11394
  Object.keys(this.overlays).forEach((overlayName) => {
11388
- this.overlays[overlayName].store(false);
11395
+ let currentOverlay = this.overlays[overlayName];
11396
+ if (!currentOverlay.trivial && !currentOverlay.global) {
11397
+ currentOverlay.store(false);
11398
+ }
11399
+ ;
11389
11400
  });
11390
11401
  if (overlaysOnly) {
11391
11402
  console.log(`Only storing overlays due to overlaysOnly switch.`);
@@ -11472,9 +11483,9 @@ import TabItem from '@theme/TabItem';
11472
11483
  typeAndBundle: target,
11473
11484
  attributeOverlayName: this.overlayName,
11474
11485
  baseSchemataFolder: this.baseSchemataFolder,
11475
- gitlabProjectId: this.gitlabProjectId
11486
+ gitlabProjectId
11476
11487
  });
11477
- currentOverlay.gitlabProjectId = this.gitlabProjectId;
11488
+ currentOverlay.gitlabProjectId = gitlabProjectId;
11478
11489
  this.overlays.push(currentOverlay);
11479
11490
  });
11480
11491
  }
@@ -25349,9 +25360,17 @@ var require_array_examples_preparator = __commonJS({
25349
25360
  var utils = require_schema_utilities();
25350
25361
  var axios = require_axios();
25351
25362
  var _ArrayDataOrganizer = class _ArrayDataOrganizer {
25352
- constructor({ exampleArray }) {
25363
+ constructor({
25364
+ exampleArray,
25365
+ storageFolder = `${__dirname}/../../../../output/collection/overlays`,
25366
+ baseSchemataFolder = `${__dirname}/../../../../input/collection`,
25367
+ predefinedConventions
25368
+ }) {
25353
25369
  this.exampleArray = exampleArray;
25354
25370
  this.instances = [];
25371
+ this.storageFolder = storageFolder;
25372
+ this.baseSchemataFolder = baseSchemataFolder;
25373
+ this.predefinedConventions = predefinedConventions;
25355
25374
  }
25356
25375
  /**
25357
25376
  * Will retrieve the data needed and structure the example.
@@ -25383,11 +25402,21 @@ var require_array_examples_preparator = __commonJS({
25383
25402
  return entries;
25384
25403
  });
25385
25404
  let allMentionedConventions = Array.from(new Set(this.exampleArray.filter((d) => d.type == "taxonomy_term--convention").map((d) => d.attributes.external_uri)));
25386
- let conventionSchemataPromises = allMentionedConventions.map((url) => __async(this, null, function* () {
25387
- return yield axios.get(url.replace("schema.json", "object.json")).then((res) => res.data);
25388
- }));
25389
- let conventionObjects = yield Promise.all(conventionSchemataPromises);
25390
- let conventions = conventionObjects.map((d) => new builder.ConventionSchema(d));
25405
+ let conventionObjects;
25406
+ if (!this.predefinedConventions) {
25407
+ let conventionSchemataPromises = allMentionedConventions.map((url) => __async(this, null, function* () {
25408
+ return yield axios.get(url.replace("schema.json", "object.json")).then((res) => res.data);
25409
+ }));
25410
+ conventionObjects = yield Promise.all(conventionSchemataPromises);
25411
+ } else {
25412
+ conventionObjects = this.predefinedConventions;
25413
+ }
25414
+ ;
25415
+ let conventions = conventionObjects.map((d) => {
25416
+ d.baseSchemataFolder = this.baseSchemataFolder;
25417
+ d.storageFolder = this.storageFolder;
25418
+ return new builder.ConventionSchema(d);
25419
+ });
25391
25420
  this.detected_conventions = conventionCarrierEntities;
25392
25421
  this.conventions = conventions;
25393
25422
  });
@@ -25399,6 +25428,12 @@ var require_array_examples_preparator = __commonJS({
25399
25428
  return __async(this, null, function* () {
25400
25429
  let structuredInstances = yield this.detected_conventions.forEach((instance) => __async(this, null, function* () {
25401
25430
  let currentConvention = yield this.conventions.find((c) => c.schema.$id == instance.convention_entity.attributes.external_uri);
25431
+ if (!currentConvention) {
25432
+ throw new Error(`Couldn't find a convention matching URI ${instance.convention_entity.attributes.external_uri}
25433
+ available ones are:
25434
+ ${this.conventions.map((d) => d.schema.$id).join("\n")}`);
25435
+ }
25436
+ ;
25402
25437
  this.instances.push(
25403
25438
  utils.arrayToStructuredConvention(
25404
25439
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convention_builder",
3
- "version": "1.7.1",
3
+ "version": "1.7.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",