-
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
24 changed files
with
1,952 additions
and
1,874 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 @@ | ||
--- | ||
"hydra-box": minor | ||
--- | ||
|
||
Source changes to TypeScript |
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,6 @@ | ||
root = true | ||
|
||
[*] | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
.nyc_output | ||
coverage | ||
node_modules | ||
*.d.ts | ||
*.js | ||
!test/**/*.js | ||
!examples/**/*.js |
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 was deleted.
Oops, something went wrong.
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,63 @@ | ||
import type { NamedNode, Store } from '@rdfjs/types' | ||
import rdf from '@zazuko/env-node' | ||
import { isNamedNode } from 'is-graph-pointer' | ||
import { PropertyResource, Resource, ResourceLoader } from './index.js' | ||
|
||
export default class StoreResourceLoader implements ResourceLoader { | ||
readonly store: Store | ||
|
||
constructor({ store }: { store: Store }) { | ||
this.store = store | ||
} | ||
|
||
async load(term: NamedNode): Promise<Resource | null> { | ||
const dataset = await rdf.dataset().import(this.store.match(null, null, null, term)) | ||
|
||
if (dataset.size === 0) { | ||
return null | ||
} | ||
|
||
const types = rdf.clownface({ dataset, term }) | ||
.out(rdf.ns.rdf.type) | ||
.filter(isNamedNode) | ||
|
||
return { | ||
term, | ||
prefetchDataset: dataset, | ||
async dataset() { | ||
return dataset | ||
}, | ||
quadStream() { | ||
return dataset.toStream() | ||
}, | ||
types: rdf.termSet(types.terms), | ||
} | ||
} | ||
|
||
async forClassOperation(term: NamedNode) { | ||
const resource = await this.load(term) | ||
|
||
return resource ? [resource] : [] | ||
} | ||
|
||
async forPropertyOperation(term: NamedNode): Promise<PropertyResource[]> { | ||
const dataset = await rdf.dataset().import(this.store.match(null, null, term, null)) | ||
const result: PropertyResource[] = [] | ||
|
||
for (const quad of dataset) { | ||
if (quad.subject.termType !== 'NamedNode') continue | ||
if (quad.object.termType !== 'NamedNode') continue | ||
|
||
const loaded = await this.load(quad.subject) | ||
if (!loaded) continue | ||
|
||
result.push({ | ||
property: quad.predicate, | ||
object: quad.object, | ||
...loaded, | ||
}) | ||
} | ||
|
||
return result | ||
} | ||
} |
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,44 @@ | ||
import type { Readable } from 'stream' | ||
import type * as RDF from '@rdfjs/types' | ||
import type { GraphPointer } from 'clownface' | ||
import type { Request } from 'express' | ||
import type { Dataset } from '@zazuko/env/lib/Dataset.js' | ||
import middleware from './middleware.js' | ||
import Api from './Api.js' | ||
|
||
export interface Resource { | ||
term: RDF.NamedNode | ||
prefetchDataset: RDF.DatasetCore | ||
dataset(): Promise<Dataset> | ||
quadStream(): RDF.Stream & Readable | ||
types: Set<RDF.NamedNode> | ||
} | ||
|
||
export interface PropertyResource extends Resource { | ||
property: RDF.Quad_Predicate | ||
object: RDF.NamedNode | ||
} | ||
|
||
export interface PotentialOperation { | ||
resource: Resource | PropertyResource | ||
operation: GraphPointer | ||
} | ||
|
||
export interface HydraBox { | ||
api: Api | ||
term: RDF.NamedNode | ||
store: RDF.Store | ||
resource: Resource & { clownface(): Promise<GraphPointer<RDF.NamedNode, Dataset>> } | ||
operation: GraphPointer | ||
operations: PotentialOperation[] | ||
} | ||
|
||
export interface ResourceLoader { | ||
forClassOperation(term: RDF.NamedNode, req: Request): Promise<Resource[]> | ||
forPropertyOperation(term: RDF.NamedNode, req: Request): Promise<PropertyResource[]> | ||
} | ||
|
||
export default { | ||
middleware, | ||
Api, | ||
} |
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 was deleted.
Oops, something went wrong.
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,20 @@ | ||
import { Router } from 'express' | ||
import Api from '../../Api.js' | ||
|
||
export default function factory(api: Api) { | ||
const router = Router() | ||
|
||
router.use((req, res, next) => { | ||
if (api.term) { | ||
res.setLink(api.term.value, 'http://www.w3.org/ns/hydra/core#apiDocumentation') | ||
} | ||
|
||
next() | ||
}) | ||
|
||
router.get(api.path, (req, res, next) => { | ||
res.dataset(api.dataset).catch(next) | ||
}) | ||
|
||
return router | ||
} |
Oops, something went wrong.