Comments (9)
The thing you see in the Components.js config is actually not a list semantically speaking. In JSON-LD the brackets are used to create multiple triples with the same predicate. To have a list you need the @list keyword. Components.js is just nice enough to interpret all those triples as a list of values instead of separate values (I'm guessing because the @list syntax would make it a lot uglier), even though semantically that's not really a list. The disadvantage of that technique though is indeed that if there are no values (which is identical to writing []
in JSON-LD), it has no idea if this is an empty list or a value that is missing.
from components.js.
Thanks for the suggestion!
from components.js.
Marking a parameter as required actually means that there should be at least one value.
Due to the semantics of JSON-LD and RDF, "ClassName:_listParam": []
will produce no triples, which makes validation of the parameter requirement fail.
I presume that in this case, you probably want to make the parameter optional.
from components.js.
That would mean there is no semantic difference between an empty list and no list at all ...
from components.js.
One solution would be to introduce the following behaviour:
If Components.js sees a field that is non-unique+required (what the generator outputs for array params), and has no passed values, it will consider it an empty array.
Concretely, this would mean that passing "ClassName:_listParam": []
is equivalent to not defining a value for that field at all. In both cases, Components.js would pass an empty array to the constructor.
This is a minor change in semantics for Components.js (that would call for a major update), as non-unique+required fields would require at least one value before. Since this check could be considered a bit arbitrary for arrays, it makes sense to apply this change in semantics.
If the "if the array contains at least one value" check would be necessary, then we could add this via a new minimumElements
property or something like that. But AFAIK, no one really makes use of this functionality, so it probably doesn't hurt if it is removed/modified.
@woutermont @joachimvh Would such a change make sense to you?
from components.js.
The only time unique is false is when the input parameter is an array right? In that case this sounds like a reasonable solution. Only disadvantage is that you lose the error message in case you forget to define the parameter.
I've never had a need yet for empty arrays but since it's currently impossible to define them I think this solution is better than the current situation.
from components.js.
While I think it's semantically a bit strange, it would definitely be more workable than the current situation.
from components.js.
Actually, after thinking about it a bit more, I think the following solution might be cleaner:
For a given config:
{
"@type": "MyClass",
"param1": []
}
The generator would set the JSON-LD container type to @list
inside the type-scoped context entry of param1
.
This would make the values a proper RDF list, which allows us to keep the "empty list" semantics.
(This generator change should be quite trivial)
Next, Components.js would require a small change, as it would now also need to support such RDF lists as input to parameters. I don't foresee major difficulties for this.
The advantage of this approach would be that Components.js will still throw an error if you don't define param1
in your config if it's required. This is because this approach doesn't consider a missing param1
and "param1": []
as the same thing.
@joachimvh @woutermont Any thoughts?
from components.js.
Ah yea, that's definitely better. I just assumed that one wasn't an option :D
from components.js.
Related Issues (20)
- Generics issue when building in different Monrepo HOT 3
- Invalid predicate IRI for JSON field HOT 6
- Accept strings as JSON HOT 5
- Compat URLs during error reporting HOT 1
- Custom components.js serialization HOT 9
- Emit warning on possibly invalid terms HOT 1
- Could not find a valid import path for src/lib/MyActor.jsonld. 'lsd:importPaths' in package.json may be invalid. HOT 12
- Unclear error message when a component is undefined HOT 6
- The basic typescript example in documentation doesn't seem to work HOT 10
- Append to array or collection of a component configuration HOT 2
- Invalid Predicate IRI HOT 9
- Raw value references cannot be used as keys in key/value objects HOT 4
- Some kind of package names are not allowed if it has a substring match with an existing components.js package? HOT 4
- Interfaces exported in a list seem to be ignored when generating component definitions
- Disable remote context lookups by default
- Race condition with raw values HOT 2
- Long version of parameter doesn't work HOT 8
- Allow modifying arrays more specifically HOT 5
- Error from `postinstall` with version 5.5.0 from NPM HOT 2
- Detected remote context lookup on broken softlinks in node_modules
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from components.js.