convention_builder 1.6.1 → 1.7.2
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 +86 -10
- package/dist/node/index.js +86 -10
- package/package.json +1 -1
package/dist/module/index.js
CHANGED
|
@@ -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").`);
|
|
@@ -10971,6 +10972,7 @@ var require_convention_builder = __commonJS({
|
|
|
10971
10972
|
description: this.description,
|
|
10972
10973
|
required: this.required
|
|
10973
10974
|
};
|
|
10975
|
+
this.enforceConventionTaxonomyTerm();
|
|
10974
10976
|
Object.keys(this.overlays).forEach((attributeName) => {
|
|
10975
10977
|
this.overlays[attributeName].updateSchema();
|
|
10976
10978
|
this.schema.properties[attributeName] = this.overlays[attributeName].schema;
|
|
@@ -11068,7 +11070,8 @@ var require_convention_builder = __commonJS({
|
|
|
11068
11070
|
let containerSchema = this.overlays[containerEntity].schema;
|
|
11069
11071
|
let relationshipAttributes = Object.keys(containerSchema.properties.relationships.properties);
|
|
11070
11072
|
if (!relationshipAttributes.includes(relationName)) {
|
|
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.join(", ")}
|
|
11073
|
+
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(", ")}.
|
|
11074
|
+
Schema read from ${this.baseSchemataFolder}`);
|
|
11072
11075
|
}
|
|
11073
11076
|
;
|
|
11074
11077
|
this.relationships.push({ containerEntity, relationName, mentionedEntity, required });
|
|
@@ -11275,6 +11278,56 @@ import TabItem from '@theme/TabItem';
|
|
|
11275
11278
|
;
|
|
11276
11279
|
return output;
|
|
11277
11280
|
}
|
|
11281
|
+
/**
|
|
11282
|
+
* Will create an appropiate convention taxonomy term and add it into the definition, with the appropriate content and relationships.
|
|
11283
|
+
*/
|
|
11284
|
+
addConventionTaxonomyTerm() {
|
|
11285
|
+
let conventionTree = this.getAttributesTree();
|
|
11286
|
+
let entitiesInRoot = Object.keys(conventionTree);
|
|
11287
|
+
let mainEntity = entitiesInRoot.length == 1 ? entitiesInRoot[0] : void 0;
|
|
11288
|
+
if (mainEntity) {
|
|
11289
|
+
const conventionTaxonomyTerm = new SchemaOverlay(
|
|
11290
|
+
{
|
|
11291
|
+
typeAndBundle: "taxonomy_term--convention",
|
|
11292
|
+
name: "convention_taxonomy",
|
|
11293
|
+
baseSchemataFolder: this.baseSchemataFolder,
|
|
11294
|
+
storageFolder: this.storageFolder
|
|
11295
|
+
}
|
|
11296
|
+
);
|
|
11297
|
+
conventionTaxonomyTerm.setConstant({
|
|
11298
|
+
attribute: "external_uri",
|
|
11299
|
+
value: this.repoURLTemplateFunction({ conventionName: this.schemaName, projectID: this.gitlabProjectId }),
|
|
11300
|
+
description: "External URI in which this convention's schema and other artifacts will be hosted as artifacts by GitLab."
|
|
11301
|
+
});
|
|
11302
|
+
conventionTaxonomyTerm.setMainDescription("This entity tags data as organized into the convention we intend to instantiate, allowing to pick the right schemata to test it against.");
|
|
11303
|
+
conventionTaxonomyTerm.setConstant({
|
|
11304
|
+
attribute: "name",
|
|
11305
|
+
value: this.title
|
|
11306
|
+
});
|
|
11307
|
+
this.addAttribute({
|
|
11308
|
+
schemaOverlayObject: conventionTaxonomyTerm,
|
|
11309
|
+
attributeName: "convention_taxonomy",
|
|
11310
|
+
required: true
|
|
11311
|
+
});
|
|
11312
|
+
this.addRelationship({
|
|
11313
|
+
containerEntity: mainEntity,
|
|
11314
|
+
relationName: "convention",
|
|
11315
|
+
mentionedEntity: "convention_taxonomy",
|
|
11316
|
+
required: true
|
|
11317
|
+
});
|
|
11318
|
+
}
|
|
11319
|
+
;
|
|
11320
|
+
}
|
|
11321
|
+
enforceConventionTaxonomyTerm() {
|
|
11322
|
+
let conventionExists = Object.keys(this.overlays).find((d) => this.overlays[d].typeAndBundle == "taxonomy_term--convention");
|
|
11323
|
+
let output = false;
|
|
11324
|
+
if (!conventionExists) {
|
|
11325
|
+
this.addConventionTaxonomyTerm();
|
|
11326
|
+
output = true;
|
|
11327
|
+
}
|
|
11328
|
+
;
|
|
11329
|
+
return output;
|
|
11330
|
+
}
|
|
11278
11331
|
/**
|
|
11279
11332
|
* This method takes this object's schema and returns an array of fixed attributes objects, which is equivalent to a row by row encoded excel spreadsheet and is mostly meant at allowing users to work on said schema via a tabular structure.
|
|
11280
11333
|
* The output will include one row for each data entry path (not all of the paths) and will synthesize all of its properties into columns, such as name, Title, Type, etc.
|
|
@@ -11334,7 +11387,6 @@ import TabItem from '@theme/TabItem';
|
|
|
11334
11387
|
let test = this.testExamples();
|
|
11335
11388
|
let valid = test.success;
|
|
11336
11389
|
if (!valid && !overlaysOnly) {
|
|
11337
|
-
console.log(JSON.stringify(test.failedExamples));
|
|
11338
11390
|
throw new Error(`The 'testExamples' method failed. The schema ${this.schemaName} either lacks examples, or is rejecting a valid example or accepting an invalid example.
|
|
11339
11391
|
* Valid examples provided: ${test.validExamples.length}
|
|
11340
11392
|
* Error examples provided: ${test.erroredExamples.length}
|
|
@@ -11429,9 +11481,9 @@ import TabItem from '@theme/TabItem';
|
|
|
11429
11481
|
typeAndBundle: target,
|
|
11430
11482
|
attributeOverlayName: this.overlayName,
|
|
11431
11483
|
baseSchemataFolder: this.baseSchemataFolder,
|
|
11432
|
-
gitlabProjectId
|
|
11484
|
+
gitlabProjectId
|
|
11433
11485
|
});
|
|
11434
|
-
currentOverlay.gitlabProjectId =
|
|
11486
|
+
currentOverlay.gitlabProjectId = gitlabProjectId;
|
|
11435
11487
|
this.overlays.push(currentOverlay);
|
|
11436
11488
|
});
|
|
11437
11489
|
}
|
|
@@ -25306,9 +25358,17 @@ var require_array_examples_preparator = __commonJS({
|
|
|
25306
25358
|
var utils = require_schema_utilities();
|
|
25307
25359
|
var axios = require_axios();
|
|
25308
25360
|
var _ArrayDataOrganizer = class _ArrayDataOrganizer {
|
|
25309
|
-
constructor({
|
|
25361
|
+
constructor({
|
|
25362
|
+
exampleArray,
|
|
25363
|
+
storageFolder = `${__dirname}/../../../../output/collection/overlays`,
|
|
25364
|
+
baseSchemataFolder = `${__dirname}/../../../../input/collection`,
|
|
25365
|
+
predefinedConventions
|
|
25366
|
+
}) {
|
|
25310
25367
|
this.exampleArray = exampleArray;
|
|
25311
25368
|
this.instances = [];
|
|
25369
|
+
this.storageFolder = storageFolder;
|
|
25370
|
+
this.baseSchemataFolder = baseSchemataFolder;
|
|
25371
|
+
this.predefinedConventions = predefinedConventions;
|
|
25312
25372
|
}
|
|
25313
25373
|
/**
|
|
25314
25374
|
* Will retrieve the data needed and structure the example.
|
|
@@ -25340,11 +25400,21 @@ var require_array_examples_preparator = __commonJS({
|
|
|
25340
25400
|
return entries;
|
|
25341
25401
|
});
|
|
25342
25402
|
let allMentionedConventions = Array.from(new Set(this.exampleArray.filter((d) => d.type == "taxonomy_term--convention").map((d) => d.attributes.external_uri)));
|
|
25343
|
-
let
|
|
25344
|
-
|
|
25345
|
-
|
|
25346
|
-
|
|
25347
|
-
|
|
25403
|
+
let conventionObjects;
|
|
25404
|
+
if (!this.predefinedConventions) {
|
|
25405
|
+
let conventionSchemataPromises = allMentionedConventions.map((url) => __async(this, null, function* () {
|
|
25406
|
+
return yield axios.get(url.replace("schema.json", "object.json")).then((res) => res.data);
|
|
25407
|
+
}));
|
|
25408
|
+
conventionObjects = yield Promise.all(conventionSchemataPromises);
|
|
25409
|
+
} else {
|
|
25410
|
+
conventionObjects = this.predefinedConventions;
|
|
25411
|
+
}
|
|
25412
|
+
;
|
|
25413
|
+
let conventions = conventionObjects.map((d) => {
|
|
25414
|
+
d.baseSchemataFolder = this.baseSchemataFolder;
|
|
25415
|
+
d.storageFolder = this.storageFolder;
|
|
25416
|
+
return new builder.ConventionSchema(d);
|
|
25417
|
+
});
|
|
25348
25418
|
this.detected_conventions = conventionCarrierEntities;
|
|
25349
25419
|
this.conventions = conventions;
|
|
25350
25420
|
});
|
|
@@ -25356,6 +25426,12 @@ var require_array_examples_preparator = __commonJS({
|
|
|
25356
25426
|
return __async(this, null, function* () {
|
|
25357
25427
|
let structuredInstances = yield this.detected_conventions.forEach((instance) => __async(this, null, function* () {
|
|
25358
25428
|
let currentConvention = yield this.conventions.find((c) => c.schema.$id == instance.convention_entity.attributes.external_uri);
|
|
25429
|
+
if (!currentConvention) {
|
|
25430
|
+
throw new Error(`Couldn't find a convention matching URI ${instance.convention_entity.attributes.external_uri}
|
|
25431
|
+
available ones are:
|
|
25432
|
+
${this.conventions.map((d) => d.schema.$id).join("\n")}`);
|
|
25433
|
+
}
|
|
25434
|
+
;
|
|
25359
25435
|
this.instances.push(
|
|
25360
25436
|
utils.arrayToStructuredConvention(
|
|
25361
25437
|
{
|
package/dist/node/index.js
CHANGED
|
@@ -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").`);
|
|
@@ -10964,6 +10965,7 @@ var require_convention_builder = __commonJS({
|
|
|
10964
10965
|
description: this.description,
|
|
10965
10966
|
required: this.required
|
|
10966
10967
|
};
|
|
10968
|
+
this.enforceConventionTaxonomyTerm();
|
|
10967
10969
|
Object.keys(this.overlays).forEach((attributeName) => {
|
|
10968
10970
|
this.overlays[attributeName].updateSchema();
|
|
10969
10971
|
this.schema.properties[attributeName] = this.overlays[attributeName].schema;
|
|
@@ -11061,7 +11063,8 @@ var require_convention_builder = __commonJS({
|
|
|
11061
11063
|
let containerSchema = this.overlays[containerEntity].schema;
|
|
11062
11064
|
let relationshipAttributes = Object.keys(containerSchema.properties.relationships.properties);
|
|
11063
11065
|
if (!relationshipAttributes.includes(relationName)) {
|
|
11064
|
-
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(", ")}
|
|
11066
|
+
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(", ")}.
|
|
11067
|
+
Schema read from ${this.baseSchemataFolder}`);
|
|
11065
11068
|
}
|
|
11066
11069
|
;
|
|
11067
11070
|
this.relationships.push({ containerEntity, relationName, mentionedEntity, required });
|
|
@@ -11268,6 +11271,56 @@ import TabItem from '@theme/TabItem';
|
|
|
11268
11271
|
;
|
|
11269
11272
|
return output;
|
|
11270
11273
|
}
|
|
11274
|
+
/**
|
|
11275
|
+
* Will create an appropiate convention taxonomy term and add it into the definition, with the appropriate content and relationships.
|
|
11276
|
+
*/
|
|
11277
|
+
addConventionTaxonomyTerm() {
|
|
11278
|
+
let conventionTree = this.getAttributesTree();
|
|
11279
|
+
let entitiesInRoot = Object.keys(conventionTree);
|
|
11280
|
+
let mainEntity = entitiesInRoot.length == 1 ? entitiesInRoot[0] : void 0;
|
|
11281
|
+
if (mainEntity) {
|
|
11282
|
+
const conventionTaxonomyTerm = new SchemaOverlay2(
|
|
11283
|
+
{
|
|
11284
|
+
typeAndBundle: "taxonomy_term--convention",
|
|
11285
|
+
name: "convention_taxonomy",
|
|
11286
|
+
baseSchemataFolder: this.baseSchemataFolder,
|
|
11287
|
+
storageFolder: this.storageFolder
|
|
11288
|
+
}
|
|
11289
|
+
);
|
|
11290
|
+
conventionTaxonomyTerm.setConstant({
|
|
11291
|
+
attribute: "external_uri",
|
|
11292
|
+
value: this.repoURLTemplateFunction({ conventionName: this.schemaName, projectID: this.gitlabProjectId }),
|
|
11293
|
+
description: "External URI in which this convention's schema and other artifacts will be hosted as artifacts by GitLab."
|
|
11294
|
+
});
|
|
11295
|
+
conventionTaxonomyTerm.setMainDescription("This entity tags data as organized into the convention we intend to instantiate, allowing to pick the right schemata to test it against.");
|
|
11296
|
+
conventionTaxonomyTerm.setConstant({
|
|
11297
|
+
attribute: "name",
|
|
11298
|
+
value: this.title
|
|
11299
|
+
});
|
|
11300
|
+
this.addAttribute({
|
|
11301
|
+
schemaOverlayObject: conventionTaxonomyTerm,
|
|
11302
|
+
attributeName: "convention_taxonomy",
|
|
11303
|
+
required: true
|
|
11304
|
+
});
|
|
11305
|
+
this.addRelationship({
|
|
11306
|
+
containerEntity: mainEntity,
|
|
11307
|
+
relationName: "convention",
|
|
11308
|
+
mentionedEntity: "convention_taxonomy",
|
|
11309
|
+
required: true
|
|
11310
|
+
});
|
|
11311
|
+
}
|
|
11312
|
+
;
|
|
11313
|
+
}
|
|
11314
|
+
enforceConventionTaxonomyTerm() {
|
|
11315
|
+
let conventionExists = Object.keys(this.overlays).find((d) => this.overlays[d].typeAndBundle == "taxonomy_term--convention");
|
|
11316
|
+
let output = false;
|
|
11317
|
+
if (!conventionExists) {
|
|
11318
|
+
this.addConventionTaxonomyTerm();
|
|
11319
|
+
output = true;
|
|
11320
|
+
}
|
|
11321
|
+
;
|
|
11322
|
+
return output;
|
|
11323
|
+
}
|
|
11271
11324
|
/**
|
|
11272
11325
|
* This method takes this object's schema and returns an array of fixed attributes objects, which is equivalent to a row by row encoded excel spreadsheet and is mostly meant at allowing users to work on said schema via a tabular structure.
|
|
11273
11326
|
* The output will include one row for each data entry path (not all of the paths) and will synthesize all of its properties into columns, such as name, Title, Type, etc.
|
|
@@ -11327,7 +11380,6 @@ import TabItem from '@theme/TabItem';
|
|
|
11327
11380
|
let test = this.testExamples();
|
|
11328
11381
|
let valid = test.success;
|
|
11329
11382
|
if (!valid && !overlaysOnly) {
|
|
11330
|
-
console.log(JSON.stringify(test.failedExamples));
|
|
11331
11383
|
throw new Error(`The 'testExamples' method failed. The schema ${this.schemaName} either lacks examples, or is rejecting a valid example or accepting an invalid example.
|
|
11332
11384
|
* Valid examples provided: ${test.validExamples.length}
|
|
11333
11385
|
* Error examples provided: ${test.erroredExamples.length}
|
|
@@ -11422,9 +11474,9 @@ import TabItem from '@theme/TabItem';
|
|
|
11422
11474
|
typeAndBundle: target,
|
|
11423
11475
|
attributeOverlayName: this.overlayName,
|
|
11424
11476
|
baseSchemataFolder: this.baseSchemataFolder,
|
|
11425
|
-
gitlabProjectId
|
|
11477
|
+
gitlabProjectId
|
|
11426
11478
|
});
|
|
11427
|
-
currentOverlay.gitlabProjectId =
|
|
11479
|
+
currentOverlay.gitlabProjectId = gitlabProjectId;
|
|
11428
11480
|
this.overlays.push(currentOverlay);
|
|
11429
11481
|
});
|
|
11430
11482
|
}
|
|
@@ -25299,9 +25351,17 @@ var require_array_examples_preparator = __commonJS({
|
|
|
25299
25351
|
var utils = require_schema_utilities();
|
|
25300
25352
|
var axios = require_axios();
|
|
25301
25353
|
var _ArrayDataOrganizer = class _ArrayDataOrganizer {
|
|
25302
|
-
constructor({
|
|
25354
|
+
constructor({
|
|
25355
|
+
exampleArray,
|
|
25356
|
+
storageFolder = `${__dirname}/../../../../output/collection/overlays`,
|
|
25357
|
+
baseSchemataFolder = `${__dirname}/../../../../input/collection`,
|
|
25358
|
+
predefinedConventions
|
|
25359
|
+
}) {
|
|
25303
25360
|
this.exampleArray = exampleArray;
|
|
25304
25361
|
this.instances = [];
|
|
25362
|
+
this.storageFolder = storageFolder;
|
|
25363
|
+
this.baseSchemataFolder = baseSchemataFolder;
|
|
25364
|
+
this.predefinedConventions = predefinedConventions;
|
|
25305
25365
|
}
|
|
25306
25366
|
/**
|
|
25307
25367
|
* Will retrieve the data needed and structure the example.
|
|
@@ -25333,11 +25393,21 @@ var require_array_examples_preparator = __commonJS({
|
|
|
25333
25393
|
return entries;
|
|
25334
25394
|
});
|
|
25335
25395
|
let allMentionedConventions = Array.from(new Set(this.exampleArray.filter((d) => d.type == "taxonomy_term--convention").map((d) => d.attributes.external_uri)));
|
|
25336
|
-
let
|
|
25337
|
-
|
|
25338
|
-
|
|
25339
|
-
|
|
25340
|
-
|
|
25396
|
+
let conventionObjects;
|
|
25397
|
+
if (!this.predefinedConventions) {
|
|
25398
|
+
let conventionSchemataPromises = allMentionedConventions.map((url) => __async(this, null, function* () {
|
|
25399
|
+
return yield axios.get(url.replace("schema.json", "object.json")).then((res) => res.data);
|
|
25400
|
+
}));
|
|
25401
|
+
conventionObjects = yield Promise.all(conventionSchemataPromises);
|
|
25402
|
+
} else {
|
|
25403
|
+
conventionObjects = this.predefinedConventions;
|
|
25404
|
+
}
|
|
25405
|
+
;
|
|
25406
|
+
let conventions = conventionObjects.map((d) => {
|
|
25407
|
+
d.baseSchemataFolder = this.baseSchemataFolder;
|
|
25408
|
+
d.storageFolder = this.storageFolder;
|
|
25409
|
+
return new builder.ConventionSchema(d);
|
|
25410
|
+
});
|
|
25341
25411
|
this.detected_conventions = conventionCarrierEntities;
|
|
25342
25412
|
this.conventions = conventions;
|
|
25343
25413
|
});
|
|
@@ -25349,6 +25419,12 @@ var require_array_examples_preparator = __commonJS({
|
|
|
25349
25419
|
return __async(this, null, function* () {
|
|
25350
25420
|
let structuredInstances = yield this.detected_conventions.forEach((instance) => __async(this, null, function* () {
|
|
25351
25421
|
let currentConvention = yield this.conventions.find((c) => c.schema.$id == instance.convention_entity.attributes.external_uri);
|
|
25422
|
+
if (!currentConvention) {
|
|
25423
|
+
throw new Error(`Couldn't find a convention matching URI ${instance.convention_entity.attributes.external_uri}
|
|
25424
|
+
available ones are:
|
|
25425
|
+
${this.conventions.map((d) => d.schema.$id).join("\n")}`);
|
|
25426
|
+
}
|
|
25427
|
+
;
|
|
25352
25428
|
this.instances.push(
|
|
25353
25429
|
utils.arrayToStructuredConvention(
|
|
25354
25430
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "convention_builder",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.2",
|
|
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",
|