-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
628 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@kopflos-cms/core": minor | ||
--- | ||
|
||
Changed plugin setup to require classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@kopflos-cms/core": patch | ||
--- | ||
|
||
Added helper to easily access plugin instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@kopflos-cms/hydra": minor | ||
--- | ||
|
||
Created extensible method for collection paging strategies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import type { ParsedUrlQuery } from 'node:querystring' | ||
import { hydra } from '@tpluscode/rdf-ns-builders' | ||
import type { GraphPointer } from 'clownface' | ||
import type { Environment } from '@rdfjs/environment/Environment.js' | ||
import type { DataFactory, NamedNode } from '@rdfjs/types' | ||
import type ClownfaceFactory from 'clownface/Factory.js' | ||
|
||
const literalValueRegex = /^"(?<value>.+)"(@|\^\^)?((?<=@)(?<language>.*))?((?<=\^\^)(?<datatype>.*))?$/ | ||
|
||
function createTermFromVariable(rdf: Environment<DataFactory>, template: GraphPointer, value: string | string[]) { | ||
if (!hydra.ExplicitRepresentation.equals(template.out(hydra.variableRepresentation).term)) { | ||
return value | ||
} | ||
|
||
const parseValue = (value: string) => { | ||
const matches = value.match(literalValueRegex) | ||
if (matches?.groups) { | ||
let datatypeOrLanguage: NamedNode | string | undefined = matches.groups?.language | ||
if (matches.groups?.datatype) { | ||
datatypeOrLanguage = rdf.namedNode(matches.groups.datatype) | ||
} | ||
|
||
return rdf.literal(matches.groups.value, datatypeOrLanguage) | ||
} | ||
|
||
return rdf.namedNode(value) | ||
} | ||
|
||
const values = Array.isArray(value) ? value : [value] | ||
return values.map(parseValue) | ||
} | ||
|
||
export function fromQuery(rdf: Environment<DataFactory | ClownfaceFactory>, query: ParsedUrlQuery, template: GraphPointer) { | ||
const templateParams = rdf.clownface().blankNode() | ||
const variablePropertyMap = new Map() | ||
|
||
template.out(hydra.mapping).forEach(mapping => { | ||
const variable = mapping.out(hydra.variable).value | ||
const property = mapping.out(hydra.property).term | ||
|
||
variablePropertyMap.set(variable, property) | ||
}) | ||
|
||
Object.entries(query).forEach(([key, value]) => { | ||
const property = variablePropertyMap.get(key) | ||
|
||
if (!property || !value) { | ||
return | ||
} | ||
|
||
templateParams.addOut(property, createTermFromVariable(rdf, template, value)) | ||
}) | ||
|
||
return templateParams | ||
} | ||
|
||
export function combineTemplate(collection: GraphPointer, expanded: string) { | ||
let collectionURL = new URL(collection.value) | ||
|
||
if (!expanded.startsWith('?') || expanded.startsWith('$')) { | ||
const searchParams = new URLSearchParams(expanded) | ||
for (const [param, value] of searchParams) { | ||
collectionURL.searchParams.append(param, value) | ||
} | ||
} else { | ||
collectionURL = new URL(expanded, collectionURL) | ||
} | ||
|
||
return collectionURL.toString() | ||
} |
Oops, something went wrong.