Skip to content

Project review #1

Open
Open
@joachimvh

Description

@joachimvh

Here are some comments I had after going through the repository.

package.json

I don't think it's necessary to have the project version be the same as the CSS version it supports, although you can of course. But if you ever want to do a major release of this package while CSS has not changed version there is no way to do it correctly. The supported CSS version can always be deduced from the package.json dependencies.

The repository field is wrong.

Folder structure

I was confused at first that both the config and src folders have the same structure as those in CSS as I thought it implied you were replacing files/configs from CSS. Might be a bit overkil to have such deep folder nesting for 2-3 files.

Documentation

There are some minor grammar issues here and there so would suggest a re-read. Would also advise to not use "obviously" in your text to not make your readers feel stupid 😉.

ShapeValidator.ts

Is missing tsdoc for the class and parameters. The other classes could also use some more documentation.

ShaclValidator.ts

noShapePresent should be a constant outside of the class, or probably just removed since it only occurs once.

canHandle should throw an HttpError (probably NotImplementedHttpError).

let representationData; should have a type

Why does an InternalServerError imply that you are trying to create containers in a constrained container? How does the conversion process trigger this since that shouldn't create anything? Even if this happens, the check should be more specific, e.g. checking the contents of the error.

error instanceof NotImplementedHttpError -> NotImplementedHttpError.isInstance. This gets around certain components.js edge case issues.

Skipping on auxiliary files should happen in the canHandle, not after cloning, since cloning is expensive.

No need to impkement handleSafe yourself in this case as the canHandle call is negligible. The way it is currently done is also wrong, this is how it's supposed to work: https://github.com/CommunitySolidServer/CommunitySolidServer/blob/da99ff30f63b673ea272fc918c69c9ff4a5c0401/src/util/handlers/AsyncHandler.ts#L38-L41

for (const targetClass of targetClasses) {
targetClassesPresent = targetClassesPresent || dataStore.countQuads(null, null, targetClass, null) > 0;
}
if (!targetClassesPresent) {

Can be if (targetClasses.some(targetClass => dataStore.countQuads(null, null, targetClass, null) > 0) {.

throw new BadRequestHttpError(`${'Data not accepted as no nodes in the body conform ' +
'to any of the target classes of '}${shapeURL}`);

Not sure why there is a string in a string there.

ShapeValidationStore.ts

The fact that this class takes so many inputs makes me think that it might be doing too much. Also the fact that the setRepresentation call is 2 completely separate things (which should be separate function calls). It actually feels like the entire metadata part should not be here. We already have a place where we validate metadata that is being changed, this would be a better fit there. Perhaps CSS would need a more generic way to add classes that validate PATCH results.

Ordering of the calls should be changed so no unneccessary actions are done. No need to calculate current representation and shapes if newShapes.length > 1. Similarly, no need to do any work if newShapes.length === 0.

// In case the parent being http://localhost:3123/.internal/setup/ getting the representation would result into a
// NotFoundHttpError

How do you trigger this because this feels like it should be fixed in CSS?

Only the getRepresentation call should be in the try/catch that prevents the NotFoundHttpError. Although preferably we can just prevent this situation from happening as mentioned above.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions