componentsjs 5.3.0 → 5.3.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.
@@ -0,0 +1,263 @@
1
+ {
2
+ "@context": {
3
+ "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
4
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
5
+ "type": {
6
+ "@id": "rdf:type"
7
+ },
8
+ "types": {
9
+ "@id": "rdf:type"
10
+ },
11
+
12
+ "oo": "https://linkedsoftwaredependencies.org/vocabularies/object-oriented#",
13
+ "Module": {
14
+ "@id": "oo:Module"
15
+ },
16
+ "Class": {
17
+ "@id": "oo:Class"
18
+ },
19
+ "AbstractClass": {
20
+ "@id": "oo:AbstractClass"
21
+ },
22
+ "Instance": {
23
+ "@id": "oo:ComponentInstance"
24
+ },
25
+ "components": {
26
+ "@id": "oo:component"
27
+ },
28
+ "component": {
29
+ "@id": "oo:component",
30
+ "@type": "@id"
31
+ },
32
+ "parameters": {
33
+ "@id": "oo:parameter"
34
+ },
35
+ "memberFields": {
36
+ "@id": "oo:memberField"
37
+ },
38
+ "memberFieldName": {
39
+ "@id": "oo:memberFieldName"
40
+ },
41
+ "genericTypeParameters": {
42
+ "@id": "oo:genericTypeParameter"
43
+ },
44
+ "constructorArguments": {
45
+ "@id": "oo:constructorArguments",
46
+ "@container": "@list"
47
+ },
48
+ "unique": {
49
+ "@id": "oo:uniqueValue"
50
+ },
51
+ "lazy": {
52
+ "@id": "oo:lazyValue"
53
+ },
54
+ "required": {
55
+ "@id": "oo:required"
56
+ },
57
+ "default": {
58
+ "@id": "oo:defaultValue"
59
+ },
60
+ "defaultScoped": {
61
+ "@id": "oo:defaultScoped"
62
+ },
63
+ "defaultScope": {
64
+ "@id": "oo:defaultScope",
65
+ "@type": "@id"
66
+ },
67
+ "defaultScopedValue": {
68
+ "@id": "oo:defaultScopedValue"
69
+ },
70
+ "fixed": {
71
+ "@id": "oo:hasFixedValue"
72
+ },
73
+ "arguments": {
74
+ "@id": "oo:arguments",
75
+ "@container": "@list"
76
+ },
77
+ "undefined": {
78
+ "@id": "oo:isUndefined"
79
+ },
80
+ "Override": {
81
+ "@id": "oo:Override"
82
+ },
83
+ "overrideInstance": {
84
+ "@id": "oo:overrideInstance"
85
+ },
86
+ "overrideParameters": {
87
+ "@id": "oo:overrideParameters"
88
+ },
89
+ "ParameterRange": {
90
+ "@id": "oo:ParameterRange"
91
+ },
92
+ "ParameterRangeUndefined": {
93
+ "@id": "oo:ParameterRangeUndefined"
94
+ },
95
+ "ParameterRangeWildcard": {
96
+ "@id": "oo:ParameterRangeWildcard"
97
+ },
98
+ "ParameterRangeArray": {
99
+ "@id": "oo:ParameterRangeArray"
100
+ },
101
+ "ParameterRangeRest": {
102
+ "@id": "oo:ParameterRangeRest"
103
+ },
104
+ "ParameterRangeKeyof": {
105
+ "@id": "oo:ParameterRangeKeyof"
106
+ },
107
+ "ParameterRangeLiteral": {
108
+ "@id": "oo:ParameterRangeLiteral"
109
+ },
110
+ "parameterRangeValue": {
111
+ "@id": "oo:parameterRangeValue",
112
+ "@type": "@id"
113
+ },
114
+ "parameterRangeValueLiteral": {
115
+ "@id": "oo:parameterRangeValue"
116
+ },
117
+ "ParameterRangeUnion": {
118
+ "@id": "oo:ParameterRangeUnion"
119
+ },
120
+ "ParameterRangeIntersection": {
121
+ "@id": "oo:ParameterRangeIntersection"
122
+ },
123
+ "ParameterRangeTuple": {
124
+ "@id": "oo:ParameterRangeTuple"
125
+ },
126
+ "parameterRangeElements": {
127
+ "@id": "oo:parameterRangeElement",
128
+ "@type": "@id"
129
+ },
130
+ "ParameterRangeCollectEntries": {
131
+ "@id": "oo:ParameterRangeCollectEntries"
132
+ },
133
+ "parameterRangeCollectEntriesParameters": {
134
+ "@id": "oo:parameterRangeCollectEntriesParameter",
135
+ "@type": "@id"
136
+ },
137
+ "ParameterRangeGenericComponent": {
138
+ "@id": "oo:ParameterRangeGenericComponent"
139
+ },
140
+ "genericTypeInstancesComponentScope": {
141
+ "@id": "oo:genericTypeInstancesComponentScope",
142
+ "@type": "@id"
143
+ },
144
+ "genericTypeInstances": {
145
+ "@id": "oo:genericTypeInstance",
146
+ "@type": "@id"
147
+ },
148
+ "ParameterRangeGenericTypeReference": {
149
+ "@id": "oo:ParameterRangeGenericTypeReference"
150
+ },
151
+ "parameterRangeGenericType": {
152
+ "@id": "oo:parameterRangeGenericType",
153
+ "@type": "@id"
154
+ },
155
+ "parameterRangeGenericBindings": {
156
+ "@id": "oo:parameterRangeGenericBinding",
157
+ "@type": "@id"
158
+ },
159
+ "ParameterRangeIndexed": {
160
+ "@id": "oo:ParameterRangeIndexed"
161
+ },
162
+ "parameterRangeIndexedObject": {
163
+ "@id": "oo:parameterRangeIndexedObject",
164
+ "@type": "@id"
165
+ },
166
+ "parameterRangeIndexedIndex": {
167
+ "@id": "oo:parameterRangeIndexedIndex",
168
+ "@type": "@id"
169
+ },
170
+ "GenericComponentExtension": {
171
+ "@id": "oo:GenericComponentExtension"
172
+ },
173
+
174
+ "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
175
+ "comment": {
176
+ "@id": "rdfs:comment"
177
+ },
178
+ "extends": {
179
+ "@id": "rdfs:subClassOf",
180
+ "@type": "@id"
181
+ },
182
+ "range": {
183
+ "@id": "rdfs:range",
184
+ "@type": "@id"
185
+ },
186
+ "import": {
187
+ "@id": "rdfs:seeAlso",
188
+ "@type": "@id"
189
+ },
190
+
191
+ "owl": "http://www.w3.org/2002/07/owl#",
192
+ "InheritanceValue": {
193
+ "@id": "owl:Restriction"
194
+ },
195
+ "inheritValues": {
196
+ "@id": "rdfs:subClassOf",
197
+ "@type": "@id"
198
+ },
199
+ "onParameter": {
200
+ "@id": "owl:onProperty",
201
+ "@type": "@id"
202
+ },
203
+ "from": {
204
+ "@id": "owl:allValuesFrom",
205
+ "@type": "@id"
206
+ },
207
+
208
+ "doap": "http://usefulinc.com/ns/doap#",
209
+ "requireName": {
210
+ "@id": "doap:name"
211
+ },
212
+ "requireElement": {
213
+ "@id": "oo:componentPath"
214
+ },
215
+ "requireNoConstructor": {
216
+ "@id": "oo:componentNoConstructor"
217
+ },
218
+
219
+ "om": "https://linkedsoftwaredependencies.org/vocabularies/object-mapping#",
220
+ "ObjectMapping": {
221
+ "@id": "om:ObjectMapping"
222
+ },
223
+ "ArrayMapping": {
224
+ "@id": "om:ArrayMapping"
225
+ },
226
+ "fields": {
227
+ "@id": "om:field",
228
+ "@type": "om:ObjectMapEntry",
229
+ "@container": "@list"
230
+ },
231
+ "elements": {
232
+ "@id": "om:elements",
233
+ "@type": "@id",
234
+ "@container": "@list"
235
+ },
236
+ "collectEntries": {
237
+ "@id": "om:collectsEntriesFrom",
238
+ "@type": "@id",
239
+ "@container": "@list"
240
+ },
241
+ "keyRaw": {
242
+ "@id": "om:fieldName"
243
+ },
244
+ "key": {
245
+ "@id": "om:fieldName",
246
+ "@type": "@id"
247
+ },
248
+ "value": {
249
+ "@id": "om:fieldValue",
250
+ "@type": "@id"
251
+ },
252
+ "valueRaw": {
253
+ "@id": "om:fieldValue"
254
+ },
255
+ "valueRawReference": {
256
+ "@id": "om:fieldValueRaw",
257
+ "@type": "@id"
258
+ },
259
+ "Variable": {
260
+ "@id": "om:Variable"
261
+ }
262
+ }
263
+ }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ComponentsManagerBuilder = void 0;
4
- const fs = require("fs");
5
4
  const rdf_object_1 = require("rdf-object");
6
5
  const winston_1 = require("winston");
7
6
  const ComponentsManager_1 = require("../ComponentsManager");
@@ -47,7 +46,7 @@ class ComponentsManagerBuilder {
47
46
  }
48
47
  static createObjectLoader() {
49
48
  return new rdf_object_1.RdfObjectLoader({
50
- context: JSON.parse(fs.readFileSync(`${__dirname}/../../components/context.jsonld`, 'utf8')),
49
+ context: require('../../components/context.json'),
51
50
  });
52
51
  }
53
52
  /**
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigPreprocessorComponent = void 0;
4
4
  const Iris_1 = require("../rdf/Iris");
5
+ const ResourceUtil_1 = require("../rdf/ResourceUtil");
5
6
  const ErrorResourcesContext_1 = require("../util/ErrorResourcesContext");
6
7
  const GenericsContext_1 = require("./GenericsContext");
7
8
  /**
@@ -19,14 +20,7 @@ class ConfigPreprocessorComponent {
19
20
  canHandle(config) {
20
21
  if (!config.property.requireName) {
21
22
  // Collect all component types from the resource
22
- const componentTypesIndex = {};
23
- for (const type of config.properties.types) {
24
- const componentResource = this.componentResources[type.value];
25
- if (componentResource) {
26
- componentTypesIndex[componentResource.value] = componentResource;
27
- }
28
- }
29
- const componentTypes = Object.values(componentTypesIndex);
23
+ const componentTypes = (0, ResourceUtil_1.uniqueTypes)(config, this.componentResources);
30
24
  // Require either exactly one component type, or a requireName
31
25
  if (componentTypes.length > 1) {
32
26
  throw new ErrorResourcesContext_1.ErrorResourcesContext(`Detected more than one component types for config "${config.value}"`, {
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigPreprocessorOverride = void 0;
4
+ const Iris_1 = require("../rdf/Iris");
5
+ const ResourceUtil_1 = require("../rdf/ResourceUtil");
4
6
  const ErrorResourcesContext_1 = require("../util/ErrorResourcesContext");
5
7
  /**
6
8
  * An {@link IConfigPreprocessor} that handles the overriding of parameters.
@@ -67,11 +69,9 @@ class ConfigPreprocessorOverride {
67
69
  * Finds all Override resources in the object loader and links them to their target resource.
68
70
  */
69
71
  *findOverrideTargets() {
70
- const overrideUri = this.objectLoader.contextResolved.expandTerm('oo:Override');
71
- const overrideInstanceUri = this.objectLoader.contextResolved.expandTerm('oo:overrideInstance');
72
72
  for (const [id, resource] of Object.entries(this.objectLoader.resources)) {
73
- if (resource.isA(overrideUri) && resource.value !== overrideUri) {
74
- const targets = resource.properties[overrideInstanceUri];
73
+ if (resource.isA(Iris_1.IRIS_OO.Override) && resource.value !== Iris_1.IRIS_OO.Override) {
74
+ const targets = resource.properties[Iris_1.IRIS_OO.overrideInstance];
75
75
  if (!targets || targets.length === 0) {
76
76
  this.logger.warn(`Missing overrideInstance for ${id}. This Override will be ignored.`);
77
77
  continue;
@@ -163,9 +163,8 @@ class ConfigPreprocessorOverride {
163
163
  * @param chain - The chain to find the target of.
164
164
  */
165
165
  getChainTarget(chain) {
166
- const rdfTypeUri = this.objectLoader.contextResolved.expandTerm('rdf:type');
167
166
  const target = chain[chain.length - 1];
168
- const types = target.properties[rdfTypeUri];
167
+ const types = (0, ResourceUtil_1.uniqueTypes)(target, this.componentResources);
169
168
  if (!types || types.length === 0) {
170
169
  throw new ErrorResourcesContext_1.ErrorResourcesContext(`Missing type for override target ${target.value} of Override ${chain[chain.length - 2].value}`, {
171
170
  target,
@@ -187,8 +186,7 @@ class ConfigPreprocessorOverride {
187
186
  * @param parameters - The parameters that are relevant for the target.
188
187
  */
189
188
  filterOverrideObject(override, target, parameters) {
190
- const overrideParametersUri = this.objectLoader.contextResolved.expandTerm('oo:overrideParameters');
191
- const overrideObjects = override.properties[overrideParametersUri];
189
+ const overrideObjects = override.properties[Iris_1.IRIS_OO.overrideParameters];
192
190
  if (!overrideObjects || overrideObjects.length === 0) {
193
191
  this.logger.warn(`No overrideParameters found for ${override.value}.`);
194
192
  return {};
package/lib/rdf/Iris.d.ts CHANGED
@@ -6,6 +6,9 @@ export declare const IRIS_OO: {
6
6
  ComponentInstance: string;
7
7
  component: string;
8
8
  componentPath: string;
9
+ Override: string;
10
+ overrideInstance: string;
11
+ overrideParameters: string;
9
12
  parameter: string;
10
13
  };
11
14
  export declare const PREFIX_OM: (suffix: string) => string;
package/lib/rdf/Iris.js CHANGED
@@ -10,6 +10,9 @@ exports.IRIS_OO = {
10
10
  ComponentInstance: (0, exports.PREFIX_OO)('ComponentInstance'),
11
11
  component: (0, exports.PREFIX_OO)('component'),
12
12
  componentPath: (0, exports.PREFIX_OO)('componentPath'),
13
+ Override: (0, exports.PREFIX_OO)('Override'),
14
+ overrideInstance: (0, exports.PREFIX_OO)('overrideInstance'),
15
+ overrideParameters: (0, exports.PREFIX_OO)('overrideParameters'),
13
16
  parameter: (0, exports.PREFIX_OO)('parameter'),
14
17
  };
15
18
  exports.PREFIX_OM = definePrefix('https://linkedsoftwaredependencies.org/vocabularies/object-mapping#');
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PrefetchedDocumentLoader = void 0;
4
- const fs = require("fs");
5
4
  const jsonld_context_parser_1 = require("jsonld-context-parser");
6
5
  /**
7
6
  * A document loader that first loads from a precomputed set of contexts,
@@ -34,9 +33,7 @@ class PrefetchedDocumentLoader extends jsonld_context_parser_1.FetchDocumentLoad
34
33
  }
35
34
  exports.PrefetchedDocumentLoader = PrefetchedDocumentLoader;
36
35
  PrefetchedDocumentLoader.CONTEXT_URL = 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld';
37
- // eslint-disable-next-line no-sync
38
- PrefetchedDocumentLoader.DEFAULT_CONTEXT = JSON.parse(fs
39
- .readFileSync(`${__dirname}/../../components/context.jsonld`, 'utf8'));
36
+ PrefetchedDocumentLoader.DEFAULT_CONTEXT = require('../../components/context.json');
40
37
  PrefetchedDocumentLoader.DEFAULT_CONTEXTS = {
41
38
  [PrefetchedDocumentLoader.CONTEXT_URL]: PrefetchedDocumentLoader.DEFAULT_CONTEXT,
42
39
  // TODO: temporarily also set old context versions for backwards-compatible.
@@ -0,0 +1,7 @@
1
+ import type { Resource } from 'rdf-object';
2
+ /**
3
+ * Filters duplicates from the types of the given {@link Resource} and returns all unique entries.
4
+ * @param resource - The {@link Resource} to filter the types of.
5
+ * @param componentResources - All the available component resources.
6
+ */
7
+ export declare function uniqueTypes(resource: Resource, componentResources: Record<string, Resource>): Resource[];
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uniqueTypes = void 0;
4
+ /**
5
+ * Filters duplicates from the types of the given {@link Resource} and returns all unique entries.
6
+ * @param resource - The {@link Resource} to filter the types of.
7
+ * @param componentResources - All the available component resources.
8
+ */
9
+ function uniqueTypes(resource, componentResources) {
10
+ const componentTypesIndex = {};
11
+ for (const type of resource.properties.types) {
12
+ const componentResource = componentResources[type.value];
13
+ if (componentResource) {
14
+ componentTypesIndex[componentResource.value] = componentResource;
15
+ }
16
+ }
17
+ return Object.values(componentTypesIndex);
18
+ }
19
+ exports.uniqueTypes = uniqueTypes;
20
+ //# sourceMappingURL=ResourceUtil.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "componentsjs",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
4
4
  "description": "A semantic dependency injection framework",
5
5
  "lsd:contexts": {
6
6
  "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld": "components/context.jsonld"
@@ -23,9 +23,13 @@
23
23
  "node": ">=8.0"
24
24
  },
25
25
  "scripts": {
26
- "test": "jest ${1}",
26
+ "test": "npm run test:jest && npm run test:webpack",
27
+ "test:jest": "jest ${1}",
28
+ "test:webpack": "npm run test:webpack:node && npm run test:webpack:web",
29
+ "test:webpack:node": "webpack -c test/webpack/webpack.config.js && node test/webpack/build/test.min.js",
30
+ "test:webpack:web": "webpack -c test/webpack/webpack.config-web.js && node test/webpack/build-web/test.min.js",
27
31
  "test-watch": "jest ${1} --watch",
28
- "build": "tsc && chmod +x ./bin/compile-config.js",
32
+ "build": "scopy ./components/context.jsonld ./components/context.json && tsc && chmod +x ./bin/compile-config.js",
29
33
  "build-watch": "tsc --watch",
30
34
  "lint": "eslint . --ext .ts --cache",
31
35
  "validate": "npm ls",
@@ -51,6 +55,8 @@
51
55
  "devDependencies": {
52
56
  "@rubensworks/eslint-config": "^1.0.1",
53
57
  "@types/jest": "^27.0.0",
58
+ "@types/stream-to-array": "^2.3.0",
59
+ "@types/streamify-string": "^1.0.0",
54
60
  "@typescript-eslint/eslint-plugin": "^5.0.0",
55
61
  "@typescript-eslint/parser": "^5.0.0",
56
62
  "eslint": "^7.12.1",
@@ -65,10 +71,16 @@
65
71
  "jshint": "^2.1.10",
66
72
  "manual-git-changelog": "^1.0.1",
67
73
  "n3": "^1.11.1",
74
+ "node-polyfill-webpack-plugin": "^2.0.1",
68
75
  "pre-commit": "^1.2.2",
76
+ "simple-copy": "^2.2.1",
77
+ "stream-to-array": "^2.3.0",
69
78
  "streamify-string": "^1.0.1",
70
79
  "ts-jest": "^27.0.1",
71
- "typescript": "^4.3.5"
80
+ "ts-loader": "^9.4.1",
81
+ "typescript": "^4.3.5",
82
+ "webpack": "^5.75.0",
83
+ "webpack-cli": "^4.10.0"
72
84
  },
73
85
  "files": [
74
86
  "components",