componentsjs 5.0.0-beta.7 → 5.1.0

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/CHANGELOG.md CHANGED
@@ -1,6 +1,25 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ <a name="v5.1.0"></a>
5
+ ## [v5.1.0](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0...v5.1.0) - 2022-05-10
6
+
7
+ ### Added
8
+ * [Expose instantiated resources from ComponentsManager](https://github.com/LinkedSoftwareDependencies/Components.js/commit/19c8d669a081dc413091a413d1c42c71b691cfbc)
9
+
10
+ <a name="v5.0.1"></a>
11
+ ## [v5.0.1](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0...v5.0.1) - 2022-03-02
12
+
13
+ ### Changed
14
+ * [Bump to rdf-parse 2](https://github.com/LinkedSoftwareDependencies/Components.js/commit/5957c21d9ea0d8e6086be09d67ee99e64f8b2960)
15
+
16
+ <a name="v5.0.0"></a>
17
+ ## [v5.0.0](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0-beta.7...v5.0.0) - 2022-03-01
18
+
19
+ ### Changed
20
+ * [Bump context URL to 5.0.0](https://github.com/LinkedSoftwareDependencies/Components.js/commit/495654fa70f559aaaa86a0960686fd1ca23f9546)
21
+ * [Add incorrect version number as possible cause for remote lookup failure (#67)](https://github.com/LinkedSoftwareDependencies/Components.js/commit/adf1d7e092b95a2fc47c7d2da3dfe191fdb741aa)
22
+
4
23
  <a name="v5.0.0-beta.7"></a>
5
24
  ## [v5.0.0-beta.7](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0-beta.6...v5.0.0-beta.7) - 2022-02-21
6
25
 
package/README.md CHANGED
@@ -53,7 +53,7 @@ $ npm install -D componentsjs-generator
53
53
  ...
54
54
  "build": "npm run build:ts && npm run build:components",
55
55
  "build:ts": "tsc",
56
- "build:components": "componentsjs-generator --typeScopedContexts",
56
+ "build:components": "componentsjs-generator",
57
57
  "prepare": "npm run build",
58
58
  ...
59
59
  }
@@ -80,7 +80,7 @@ export class MyClass {
80
80
  ```json
81
81
  {
82
82
  "@context": [
83
- "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld",
83
+ "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld",
84
84
  "https://linkedsoftwaredependencies.org/bundles/npm/my-package/^2.0.0/components/context.jsonld"
85
85
  ],
86
86
  "@id": "urn:my-package:myInstance",
@@ -132,7 +132,7 @@ export class MyClass {
132
132
  ```json
133
133
  {
134
134
  "@context": [
135
- "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld",
135
+ "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld",
136
136
  { "ex": "http://example.org/" }
137
137
  ],
138
138
  "@id": "ex:MyPackage",
@@ -164,7 +164,7 @@ The constructor of `MyClass` takes a single `name` argument.
164
164
  ```json
165
165
  {
166
166
  "@context": [
167
- "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld",
167
+ "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld",
168
168
  {
169
169
  "ex": "http://example.org/",
170
170
  "name": "ex:MyPackage/MyClass#name"
package/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -33,6 +33,10 @@ export declare class ComponentsManager<Instance> {
33
33
  * @param settings Optional settings that may influence instantiation.
34
34
  */
35
35
  instantiate<T = Instance>(instanceIri: string, settings?: IConstructionSettings): Promise<T>;
36
+ /**
37
+ * Retrieve a list of all instantiated Resources.
38
+ */
39
+ getInstantiatedResources(): Resource[];
36
40
  /**
37
41
  * Create an `componentsjs-error-state.json` file to represent the application state in the current working directory.
38
42
  * @param error The error that causes this error state to be created.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ComponentsManager = void 0;
4
4
  const fs = require("fs");
5
+ const rdf_string_1 = require("rdf-string");
5
6
  const ComponentsManagerBuilder_1 = require("./loading/ComponentsManagerBuilder");
6
7
  const ErrorResourcesContext_1 = require("./util/ErrorResourcesContext");
7
8
  /**
@@ -46,6 +47,15 @@ class ComponentsManager {
46
47
  throw this.generateErrorLog(error);
47
48
  }
48
49
  }
50
+ /**
51
+ * Retrieve a list of all instantiated Resources.
52
+ */
53
+ getInstantiatedResources() {
54
+ const instances = this.configConstructorPool.getInstanceRegistry();
55
+ return Object.keys(instances)
56
+ .map(key => (0, rdf_string_1.stringToTerm)(key))
57
+ .map(term => this.configRegistry.getInstantiatedResource(term));
58
+ }
49
59
  /**
50
60
  * Create an `componentsjs-error-state.json` file to represent the application state in the current working directory.
51
61
  * @param error The error that causes this error state to be created.
@@ -41,6 +41,10 @@ export declare class ConfigConstructorPool<Instance> implements IConfigConstruct
41
41
  * @param optional If the field is optional.
42
42
  */
43
43
  validateParam(config: Resource, field: string, type: string, optional?: boolean): void;
44
+ /**
45
+ * Returns the instance registry.
46
+ */
47
+ getInstanceRegistry(): Record<string, Promise<any>>;
44
48
  }
45
49
  export interface IInstancePoolOptions<Instance> {
46
50
  /**
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigConstructorPool = void 0;
4
+ const rdf_string_1 = require("rdf-string");
4
5
  const ErrorResourcesContext_1 = require("../util/ErrorResourcesContext");
5
6
  const ConfigConstructor_1 = require("./ConfigConstructor");
6
7
  /**
@@ -27,7 +28,8 @@ class ConfigConstructorPool {
27
28
  // Check if this resource is required as argument in its own chain,
28
29
  // if so, return a dummy value, to avoid infinite recursion.
29
30
  const resourceBlacklist = settings.resourceBlacklist || {};
30
- if (resourceBlacklist[configResource.value]) {
31
+ const configResourceId = (0, rdf_string_1.termToString)(configResource.term);
32
+ if (resourceBlacklist[configResourceId]) {
31
33
  return Promise.reject(new ErrorResourcesContext_1.ErrorResourcesContext(`Circular dependency was detected on ${configResource.value}`, { config: configResource }));
32
34
  }
33
35
  // Before instantiating, first check if the resource is a variable
@@ -36,24 +38,24 @@ class ConfigConstructorPool {
36
38
  .getVariableValue({ settings, variableName: configResource.value }));
37
39
  }
38
40
  // Instantiate only once
39
- if (!(configResource.value in this.instances)) {
41
+ if (!(configResourceId in this.instances)) {
40
42
  // The blacklist avoids infinite recursion for self-referencing configs
41
43
  const subBlackList = Object.assign({}, resourceBlacklist);
42
- subBlackList[configResource.value] = true;
44
+ subBlackList[configResourceId] = true;
43
45
  // Prepare instance parameters
44
46
  let rawConfig;
45
47
  try {
46
48
  rawConfig = this.getRawConfig(configResource);
47
49
  }
48
50
  catch (syncError) {
49
- this.instances[configResource.value] = Promise.reject(syncError);
50
- return this.instances[configResource.value];
51
+ this.instances[configResourceId] = Promise.reject(syncError);
52
+ return this.instances[configResourceId];
51
53
  }
52
54
  const subSettings = Object.assign(Object.assign({}, settings), { resourceBlacklist: subBlackList });
53
55
  // Invoke instance creation
54
- this.instances[configResource.value] = this.configConstructor.createInstance(rawConfig, subSettings);
56
+ this.instances[configResourceId] = this.configConstructor.createInstance(rawConfig, subSettings);
55
57
  }
56
- return this.instances[configResource.value];
58
+ return this.instances[configResourceId];
57
59
  }
58
60
  /**
59
61
  * Determine the raw config of the given config.
@@ -106,6 +108,12 @@ class ConfigConstructorPool {
106
108
  throw new ErrorResourcesContext_1.ErrorResourcesContext(`Invalid config: ${field} "${config.property[field].value}" must be a ${type}, but got ${config.property[field].type}`, { config });
107
109
  }
108
110
  }
111
+ /**
112
+ * Returns the instance registry.
113
+ */
114
+ getInstanceRegistry() {
115
+ return this.instances;
116
+ }
109
117
  }
110
118
  exports.ConfigConstructorPool = ConfigConstructorPool;
111
119
  //# sourceMappingURL=ConfigConstructorPool.js.map
@@ -11,4 +11,9 @@ export interface IConfigConstructorPool<Instance> {
11
11
  * @returns {any} The run instance.
12
12
  */
13
13
  instantiate: (configResource: Resource, settings: IConstructionSettings) => Promise<Instance>;
14
+ /**
15
+ * Return the instance regsitry.
16
+ * This is a hash from registered id to a Promise of the Instance.
17
+ */
18
+ getInstanceRegistry: () => Record<string, Promise<Instance>>;
14
19
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { Readable } from 'stream';
3
3
  import type * as RDF from '@rdfjs/types';
4
- import type { RdfObjectLoader } from 'rdf-object';
4
+ import type { RdfObjectLoader, Resource } from 'rdf-object';
5
5
  import type { Logger } from 'winston';
6
6
  import type { IModuleState } from './ModuleStateBuilder';
7
7
  /**
@@ -30,6 +30,11 @@ export declare class ConfigRegistry {
30
30
  * @param params A dictionary with named parameters.
31
31
  */
32
32
  registerCustom(configId: string, componentTypeIri: string, params: Record<string, string>): Promise<void>;
33
+ /**
34
+ * Get the instantiated Resource that was registered to the given term.
35
+ * @param term The term of the Resource that was instantiated
36
+ */
37
+ getInstantiatedResource(term: RDF.Term): Resource;
33
38
  }
34
39
  export interface IConfigLoaderRegistryOptions {
35
40
  moduleState: IModuleState;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigRegistry = void 0;
4
+ const rdf_string_1 = require("rdf-string");
4
5
  const RdfParser_1 = require("../rdf/RdfParser");
5
6
  /**
6
7
  * Accepts registrations for configurations that contain instantiations of components.
@@ -50,6 +51,13 @@ class ConfigRegistry {
50
51
  configResource.property[key] = this.objectLoader.createCompactedResource(`"${params[key]}"`);
51
52
  }
52
53
  }
54
+ /**
55
+ * Get the instantiated Resource that was registered to the given term.
56
+ * @param term The term of the Resource that was instantiated
57
+ */
58
+ getInstantiatedResource(term) {
59
+ return this.objectLoader.resources[(0, rdf_string_1.termToString)(term)];
60
+ }
53
61
  }
54
62
  exports.ConfigRegistry = ConfigRegistry;
55
63
  //# sourceMappingURL=ConfigRegistry.js.map
@@ -17,8 +17,9 @@ class PrefetchedDocumentLoader extends jsonld_context_parser_1.FetchDocumentLoad
17
17
  async load(url) {
18
18
  // Warn on deprecated context usage
19
19
  if (this.logger &&
20
- url === 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld') {
21
- this.logger.warn(`Detected deprecated context URL '${url}'${this.path ? ` in ${this.path}` : ''}. Prefer using version '^4.0.0' instead.`);
20
+ (url === 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld' ||
21
+ url === 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld')) {
22
+ this.logger.warn(`Detected deprecated context URL '${url}'${this.path ? ` in ${this.path}` : ''}. Prefer using version '^5.0.0' instead.`);
22
23
  }
23
24
  // Load prefetched contexts
24
25
  if (url in this.contexts) {
@@ -26,19 +27,20 @@ class PrefetchedDocumentLoader extends jsonld_context_parser_1.FetchDocumentLoad
26
27
  }
27
28
  // Warn before doing a remote context lookup
28
29
  if (this.logger) {
29
- this.logger.warn(`Detected remote context lookup for '${url}'${this.path ? ` in ${this.path}` : ''}. This may indicate a missing or invalid dependency, or an invalid context URL.`);
30
+ this.logger.warn(`Detected remote context lookup for '${url}'${this.path ? ` in ${this.path}` : ''}. This may indicate a missing or invalid dependency, incorrect version number, or an invalid context URL.`);
30
31
  }
31
32
  return super.load(url);
32
33
  }
33
34
  }
34
35
  exports.PrefetchedDocumentLoader = PrefetchedDocumentLoader;
35
- PrefetchedDocumentLoader.CONTEXT_URL = 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld';
36
+ PrefetchedDocumentLoader.CONTEXT_URL = 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld';
36
37
  // eslint-disable-next-line no-sync
37
38
  PrefetchedDocumentLoader.DEFAULT_CONTEXT = JSON.parse(fs
38
39
  .readFileSync(`${__dirname}/../../components/context.jsonld`, 'utf8'));
39
40
  PrefetchedDocumentLoader.DEFAULT_CONTEXTS = {
40
41
  [PrefetchedDocumentLoader.CONTEXT_URL]: PrefetchedDocumentLoader.DEFAULT_CONTEXT,
41
- // TODO: temporarily also set old context version for backwards-compatible.
42
+ // TODO: temporarily also set old context versions for backwards-compatible.
43
+ 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld': PrefetchedDocumentLoader.DEFAULT_CONTEXT,
42
44
  'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld': PrefetchedDocumentLoader.DEFAULT_CONTEXT,
43
45
  };
44
46
  //# sourceMappingURL=PrefetchedDocumentLoader.js.map
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "componentsjs",
3
- "version": "5.0.0-beta.7",
3
+ "version": "5.1.0",
4
4
  "description": "A semantic dependency injection framework",
5
5
  "lsd:contexts": {
6
- "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld": "components/context.jsonld"
6
+ "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld": "components/context.jsonld"
7
7
  },
8
8
  "main": "index.js",
9
9
  "bin": {
@@ -41,24 +41,25 @@
41
41
  "minimist": "^1.2.0",
42
42
  "rdf-data-factory": "^1.1.0",
43
43
  "rdf-object": "^1.13.1",
44
- "rdf-parse": "^1.9.1",
44
+ "rdf-parse": "^2.0.0",
45
45
  "rdf-quad": "^1.5.0",
46
+ "rdf-string": "^1.6.0",
46
47
  "rdf-terms": "^1.7.0",
47
48
  "semver": "^7.3.2",
48
49
  "winston": "^3.3.3"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@rubensworks/eslint-config": "^1.0.1",
52
- "@typescript-eslint/eslint-plugin": "^4.6.1",
53
- "@typescript-eslint/parser": "^4.6.1",
54
53
  "@types/jest": "^27.0.0",
54
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
55
+ "@typescript-eslint/parser": "^5.0.0",
55
56
  "eslint": "^7.12.1",
56
57
  "eslint-config-es": "3.25.3",
57
58
  "eslint-import-resolver-typescript": "^2.3.0",
58
59
  "eslint-plugin-import": "^2.22.1",
59
- "eslint-plugin-jest": "^24.1.0",
60
+ "eslint-plugin-jest": "^26.0.0",
60
61
  "eslint-plugin-tsdoc": "^0.2.7",
61
- "eslint-plugin-unused-imports": "^1.0.0",
62
+ "eslint-plugin-unused-imports": "^2.0.0",
62
63
  "jest": "^27.0.1",
63
64
  "jest-rdf": "^1.7.0",
64
65
  "jshint": "^2.1.10",