LinkedSoftwareDependencies / Components.js

🧩 A semantic dependency injection framework
https://componentsjs.readthedocs.io/
Other
41 stars 6 forks source link

Allow component reference as variable value #27

Open RubenVerborgh opened 3 years ago

RubenVerborgh commented 3 years ago

I'd like to be able to instantiate a variable with a component reference.

For example, I'd like to instantiate

    {
      "@id": "urn:solid-server:default:variable:store",
      "@type": "Variable"
    }

with urn:solid-server:default:RoutingResourceStore defined elsewhere in the configuration file.

We might need a special class for that, such as IriRef, that we pass as a variable value. (Note that NamedNode wouldn't work, because then we would be unable to pass actual named nodes. It has to be a value that would never be used otherwise.)

rubensworks commented 3 years ago

Not sure if I fully understand this issue.

Would the usage of value not be applicable here, as in #23?

RubenVerborgh commented 3 years ago

So the case came up here: https://github.com/solid/community-server/commit/7c1f4e9d6f3701bd949f8ac766f7e1afc2423c7f#diff-d8bc980e9e02b5f4b93773be717b9ac4dc6f50d5accc5ec851de40f18622d476R16-R31

The configuration file has:

    {
      "@id": "urn:solid-server:default:variable:store",
      "@type": "Variable"
    }

with the idea that some store will be injected.

However, the store to be injected is actually one of the stores defined in that same file (in this case either urn:solid-server:default:MemoryResourceStore or urn:solid-server:default:FileResourceStore); it is only known at runtime which one this will be. So currently I am solving this with two successive calls to instantiateFromUrl (wrapped in instantiateFromConfig):

    // Create the internal store
    const variables: Record<string, any> = {
      'urn:solid-server:default:variable:baseUrl': BASE,
    };
    const internalStore = await instantiateFromConfig(
      'urn:solid-server:default:MemoryResourceStore',
      'auth-ldp-handler.json',
      variables,
    ) as ResourceStore;
    variables['urn:solid-server:default:variable:store'] = internalStore;  // <=== note especially this line

    // Create and initialize the HTTP handler and related components
    const instances = await instantiateFromConfig(
      'urn:solid-server:test:Instances',
      'auth-ldp-handler.json',
      variables,
    ) as Record<string, any>;

whereas, with an IriRef, this could be one:

    const variables: Record<string, any> = {
      'urn:solid-server:default:variable:baseUrl': BASE,
      'urn:solid-server:default:variable:store': new IriRef('urn:solid-server:default:MemoryResourceStore'), // <=== this line
    };

    // Create and initialize the HTTP handler and related components
    const instances = await instantiateFromConfig(
      'urn:solid-server:test:Instances',
      'auth-ldp-handler.json',
      variables,
    ) as Record<string, any>;
rubensworks commented 3 years ago

Ah, I understand now. Not at all related to #23 then :-)