LinkedSoftwareDependencies / Components.js

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

Invalid predicate IRI for JSON field #91

Closed adlerfaulkner closed 2 years ago

adlerfaulkner commented 2 years ago

Issue type:


Description:

When I remove --typeScopedContexts from componentsjs-generator in CSS and convert all arguments in the config files to the [Class_name]:_[argument_name] pattern, I get errors about json fields:

Cause: Error while parsing file "/Users/adlerfaulkner/community-server/config/app/variables/cli/cli.json": Invalid predicate IRI: config

For this config:

{
  "@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^3.0.0/components/context.jsonld",
  "@graph": [
    {
      "comment": "Extracts CLI arguments into a key/value object. Config and mainModulePath are only defined here so their description is returned.",
      "@id": "urn:solid-server-app-setup:default:CliExtractor",
      "@type": "YargsCliExtractor",
      "YargsCliExtractor:_parameters": {
        "config": {
          "alias": "c",
          "requiresArg": true,
          "type": "string",
          "describe": "The configuration for the server. The default only stores data in memory; to persist to your filesystem, use @css:config/file.json."
        },
        ...

The jsonld context correctly uses rdf:JSON:

{
  "@context": [
    "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^3.0.0/components/context.jsonld"
  ],
  "@id": "npmd:@solid/community-server",
  "components": [
    {
      "@id": "scs:dist/init/cli/YargsCliExtractor#YargsCliExtractor",
      "@type": "Class",
      "requireElement": "YargsCliExtractor",
      "extends": [
        "scs:dist/init/cli/CliExtractor#CliExtractor"
      ],
      "comment": "Parses CLI args using the yargs library. Specific settings can be enabled through the provided options.",
      "parameters": [
        {
          "@id": "scs:dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters",
          "range": "rdf:JSON",
          "comment": "Parameters that should be parsed from the CLI.",
          "unique": true
        },
        ...

If I change the config file to use the [Class_name]:_[arg_name] syntax for the json fields I get the error below:

{
     "@id": "urn:solid-server-app-setup:default:CliExtractor",
      "@type": "YargsCliExtractor",
      "YargsCliExtractor:_parameters": {
        "YargsCliExtractor:_parameters_config": {
          "YargsCliExtractor:_parameters_config_alias": "c",
          "YargsCliExtractor:_parameters_config_requiresArg": true,
          "YargsCliExtractor:_parameters_config_type": "string",
          "YargsCliExtractor:_parameters_config_describe": "The configuration for the server. The default only stores data in memory; to persist to your filesystem, use @css:config/file.json."
        },
        ...
ErrorResourcesContext: Could not find (valid) component types for config "df_1308_10" among its types, or a requireName
configTypes: 
config: {
  term: BlankNode { termType: 'BlankNode', value: 'df_1308_10' },
  properties: {
    'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters_config': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters_mainModulePath': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters_loggingLevel': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters_baseUrl': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters_port': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters_rootFilePath': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters_showStackTrace': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters_sparqlEndpoint': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters_podConfigJson': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/init/cli/YargsCliExtractor#YargsCliExtractor_parameters_seededPodConfigJson': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#uniqueValue': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#isUndefined': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-mapping#field': [],
    hasFields: [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-mapping#elements': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-mapping#fieldValue': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#lazyValue': [],
    'http://usefulinc.com/ns/doap#name': [],
    'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': []
  }
}
    at ConfigPreprocessorComponentMapped.canHandle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ConfigPreprocessorComponent.js:37:23)
    at ConfigPreprocessorComponentMapped.canHandle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ConfigPreprocessorComponentMapped.js:28:38)
    at ConfigConstructorPool.getRawConfig (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructorPool.js:68:53)
    at ConfigConstructorPool.instantiate (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructorPool.js:46:34)
    at ArgumentConstructorHandlerReference.handle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/argument/ArgumentConstructorHandlerReference.js:22:56)
    at ConfigConstructor.getArgumentValue (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructor.js:55:32)
    at /Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructor.js:73:41
    at Array.map (<anonymous>)
    at ConfigConstructor.createArguments (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructor.js:73:18)
    at ConfigConstructor.createInstance (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructor.js:85:33)
    at ConfigConstructorPool.instantiate (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructorPool.js:54:75)
    at ArgumentConstructorHandlerReference.handle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/argument/ArgumentConstructorHandlerReference.js:22:56)
    at ConfigConstructor.getArgumentValue (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructor.js:55:32)
    at /Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructor.js:73:41
    at Array.map (<anonymous>)
    at ConfigConstructor.createArguments (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructor.js:73:18)

Environment:

componentsjs v4.5.0 componentsjs-generator v2.6.1 node v16.14.0

github-actions[bot] commented 2 years ago

Thanks for reporting!

rubensworks commented 2 years ago

Currently, the CJS generator will only include "@type": "@json" into type-scoped contexts. So removing --typeScopedContexts (in pre-3.x), will indeed make it so that JSON values will not become recognised as direct JSON values indeed.

One solution is to wrap your parameter value in the following:

"ex:_myparam": {
  "@type": "@json",
  "@value": { "somejson": { "somejson": ... } }
}
adlerfaulkner commented 2 years ago

I see, thanks for the explaination.

Wrapping the parameter value as you suggested resulted in:

Error: Invalid term IRI: @json
rubensworks commented 2 years ago

Hmm, might be a bug in the parser then. Can you check if you have jsonld-streaming-parser 2.4.3 installed? If no, could you try updating? If yes, could you open an issue to report this problem at https://github.com/rubensworks/jsonld-streaming-parser.js ?

adlerfaulkner commented 2 years ago

I was on version 2.4.0 but after upgrading to 2.4.3 I'm still getting an error for the first field inside the @value of the json object`:

Cause: Error while parsing file "/Users/adlerfaulkner/community-server/config/app/variables/cli/cli.json": Invalid predicate IRI: config
Error: Error while parsing file "/Users/adlerfaulkner/community-server/config/app/variables/cli/cli.json": Invalid predicate IRI: config
    at Function.addPathToError (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/rdf/RdfParser.js:73:16)
    at PassThrough.<anonymous> (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/rdf/RdfParser.js:46:38)
    at PassThrough.emit (node:events:532:35)
    at JsonLdParser.<anonymous> (/Users/adlerfaulkner/community-server/node_modules/rdf-parse/lib/RdfParser.js:71:47)
    at JsonLdParser.emit (node:events:532:35)
    at ParsingContext.emitError (/Users/adlerfaulkner/community-server/node_modules/jsonld-streaming-parser/lib/ParsingContext.js:232:21)
    at Util.predicateToTerm (/Users/adlerfaulkner/community-server/node_modules/jsonld-streaming-parser/lib/Util.js:437:37)
    at EntryHandlerPredicate.validate (/Users/adlerfaulkner/community-server/node_modules/jsonld-streaming-parser/lib/entryhandler/EntryHandlerPredicate.js:90:71)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async JsonLdParser.validateKey (/Users/adlerfaulkner/community-server/node_modules/jsonld-streaming-parser/lib/JsonLdParser.js:320:17)
    at async JsonLdParser.newOnValueJob (/Users/adlerfaulkner/community-server/node_modules/jsonld-streaming-parser/lib/JsonLdParser.js:174:62)
    at async JsonLdParser.executeBufferedJobs (/Users/adlerfaulkner/community-server/node_modules/jsonld-streaming-parser/lib/JsonLdParser.js:434:13)
adlerfaulkner commented 2 years ago

I think it's a bug with nested json inside the @value predicate. I changed my config to the way that it's tested in https://github.com/rubensworks/jsonld-streaming-parser.js/blob/2c22ac952b67c0a5c5fca61c8c00a7c33c31f52c/test/JsonLdParser-test.ts#L7032-L7046 and it works

{
  "@context": [
    "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^3.0.0/components/context.jsonld",
    { "parameters": { "@id": "YargsCliExtractor:_params", "@type": "@json" } }
  ],
  "@graph": [
    {
      "comment": "Extracts CLI arguments into a key/value object. Config and mainModulePath are only defined here so their description is returned.",
      "@id": "urn:solid-server-app-setup:default:CliExtractor",
      "@type": "YargsCliExtractor",
      "parameters": {
        "config": {
          "alias": "c",
          "requiresArg": true,
          "type": "string",
          "describe": "The configuration for the server. The default only stores data in memory; to persist to your filesystem, use @css:config/file.json."
        },
        ...

I will create a bug in jsonld-streaming-parser.js