Skip to content

Resource store router - #283

Merged
jvherweg merged 4 commits into
masterfrom
smessie-routing-resource-store
Nov 2, 2020
Merged

jvherweg merged 4 commits into
masterfrom
smessie-routing-resource-store

Conversation

@jvherweg

@jvherweg jvherweg commented Oct 26, 2020 •

Copy link
Copy Markdown
Member

Replaces #79 due to new branch.

Resolves #195 and #59 (together with #279) .

Both routers are quite generic. Since there are many ways you would want to check the contents of a path I just made it accept regexes as input for that router. For the converting router, in practice it's probably mostly going to be converting to Quads, but any type is supported.

Travis build is going to fail because LinkedSoftwareDependencies/Components-Generator.js#43 . Depending on how urgent this component is needed and the timing of this PR acceptance, I might leave out the path router until that issue is fixed.

@jvherweg jvherweg added the ☀️ enhancement New feature or request label Oct 26, 2020
@jvherweg jvherweg changed the title Smessie routing resource store Resource store router Oct 26, 2020
@rubensworks

Copy link
Copy Markdown
Contributor

LinkedSoftwareDependencies/Components-Generator.js#43 was a lot more work than I anticipated, but it's done now.
You can now write this in the config file:

  {
      "@id": "urn:solid-server:default:RegexRouterRule",
      "@type": "RegexRouterRule",
      "RegexRouterRule:_base": {
        "@id": "urn:solid-server:default:variable:base"
      },
      "RegexRouterRule:_storeMap": [
        {
          "RegexRouterRule:_storeMap_key": "abc",
          "RegexRouterRule:_storeMap_value": { "@id": "urn:solid-server:default:ResourceStore1" }
        },
        {
          "RegexRouterRule:_storeMap_key": "def",
          "RegexRouterRule:_storeMap_value": { "@id": "urn:solid-server:default:ResourceStore2" }
        }
      ]
    }

I've included a commit to bump the generator version.

(FYI, JSON-LD 1.1 may have some features that could simplify this storeMap structure. The Components.js rewrite is a blocker for this though, so I'll look into that once that's done)

@jvherweg

Copy link
Copy Markdown
Member Author

Thanks!

@RubenVerborgh RubenVerborgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff, I just find ConvertingRouterRule weirdly scoped, but not a showstopper.

Comment thread src/storage/routing/RegexRouterRule.ts Resolved
Comment thread src/storage/routing/RegexRouterRule.ts Resolved
Comment thread src/storage/routing/RegexRouterRule.ts Outdated
super();
this.base = trimTrailingSlashes(base);
this.regexes = Object.keys(storeMap).map((regex): RegexEntry =>
({ regex: new RegExp(regex, 'u'), store: storeMap[regex] }));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we don't know the right regex options, so definitely want an actual map.

I do see the appeal of it being JSON-configurable, but that should IMHO be the fallback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is that we then won't be able to configure this class in Components.js, which is needed for this one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that; so I'd still have the JSON-configurable version as a fallback, but also make sure that we can properly construct if we want to.

So:

public constructor(base: string, storeMap: Map<RegExp, String> | { [regex: string]: ResourceStore }) {
...
if (!isMap(storeMap)))
  storeMap = toRegexMap(storeMap);

@jvherweg jvherweg Oct 30, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Components.js generator doesn't like this though, since it can't convert the first part (or because it's a union).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, but that should be filed as a Components.js issue then, and marked as a todo the code (or as an issue on this repo).

We can't have Components.js influence our design; and if it does, we should annotate.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might get quite ugly though. The union type is already quite verbose, and I don't think there's a way for components.js to directly support this so it might need special annotations not helping the situation. But I'll leave that comment up to @rubensworks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks; just document this as an issue/todo somewhere and we can move on for now.

Comment thread src/storage/routing/RegexRouterRule.ts Resolved
@jvherweg
jvherweg force-pushed the smessie-routing-resource-store branch from 75974be to ab6da6c Compare November 2, 2020 12:29
@jvherweg
jvherweg force-pushed the smessie-routing-resource-store branch from ab6da6c to 988ddbc Compare November 2, 2020 14:26
@jvherweg
jvherweg merged commit 50dfea1 into master Nov 2, 2020
@jvherweg
jvherweg deleted the smessie-routing-resource-store branch November 2, 2020 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☀️ enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let different media types be handled by different stores

4 participants