Skip to content

Commit

Permalink
Merge branch 'collection-paged' into collection-post
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/tests.yml
#	example/docker-compose.yaml
#	package-lock.json
#	packages/core/lib/Kopflos.ts
#	packages/core/lib/handler.ts
#	packages/hydra/handlers/collection.ts
#	packages/hydra/package.json
  • Loading branch information
tpluscode committed Feb 4, 2025
2 parents 5471e2a + e782988 commit 6839abd
Show file tree
Hide file tree
Showing 38 changed files with 1,371 additions and 134 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-baboons-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/vite": patch
---

Add inline `config` to plugin config
5 changes: 5 additions & 0 deletions .changeset/short-lemons-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/core": minor
---

Changed plugin setup to require classes
5 changes: 5 additions & 0 deletions .changeset/shy-bobcats-reply.md
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
5 changes: 5 additions & 0 deletions .changeset/tall-maps-thank.md
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
7 changes: 7 additions & 0 deletions .changeset/tidy-mice-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@kopflos-cms/express": patch
"@kopflos-cms/vite": patch
"kopflos": patch
---

Plugins are now implemented as classes
19 changes: 7 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,19 @@ jobs:
- run: npm ci
- run: npm run -ws --if-present build

smoke-tests:
smoke-test-example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: fabasoad/setup-prolog-action@v1
- uses: lando/setup-lando@v3
with:
lando-version: 3.21.2
- uses: tpluscode/action-lando-start@v0.2.2
with:
healthcheck: https://read-the-plaque.lndo.site/plaque/newton-s-apple-tree-monash-university
timeout: 60000
ignore-errors: true
- uses: actions/setup-node@v4
with:
node-version: lts/*
- run: npm ci
- run: npm test -- --base-iri https://read-the-plaque.lndo.site/
- run: docker compose up -d
working-directory: example
- run: npm run -w example start &
- run: npx wait-on http://localhost:1429/plaque/newton-s-apple-tree-monash-university -t 30000

- run: npm test -- --base-iri http://localhost:1429/
working-directory: example
- run: lando logs
if: failure()
34 changes: 34 additions & 0 deletions .lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: read-the-plaque
services:
oxigraph:
api: 3
type: lando
entrypoint: /usr/local/bin/oxigraph
app_mount: false
scanner: false
ssl: true
services:
image: ghcr.io/oxigraph/oxigraph:0.4.6
user: root
command: serve --location /data --bind 0.0.0.0:7878
ports:
- 7878
volumes:
- ./example/oxigraph:/data
app:
type: node:20
ssl: true
scanner: false
build:
- npm i
command: cd example; kopflos serve --mode development --trust-proxy
overrides:
environment:
API_BASE: https://read-the-plaque.lndo.site
DB_URI: http://db.read-the-plaque.lndo.site

proxy:
oxigraph:
- db.read-the-plaque.lndo.site:7878
app:
- read-the-plaque.lndo.site:1429
20 changes: 14 additions & 6 deletions example/kopflos.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import * as url from 'node:url'
import type { KopflosConfig } from '@kopflos-cms/core'

const baseIri = process.env.API_BASE || 'http://localhost:1429'
const dbUri = process.env.DB_URI || 'http://localhost:7878'

export default <KopflosConfig> {
baseIri: 'http://localhost:1429',
apiGraphs: ['http://localhost:1429/api'],
baseIri,
apiGraphs: [baseIri + '/api'],
sparql: {
default: {
endpointUrl: 'http://localhost:7878/query?union-default-graph',
updateUrl: 'http://localhost:7878/update',
storeUrl: 'http://localhost:7878/store',
endpointUrl: dbUri + '/query?union-default-graph',
updateUrl: dbUri + '/update',
storeUrl: dbUri + '/store',
},
lindas: 'https://lindas.admin.ch/query',
},
Expand All @@ -27,9 +30,14 @@ export default <KopflosConfig> {
'@kopflos-cms/vite': {
root: 'ui',
entrypoints: ['ui/*.html'],
config: {
server: {
allowedHosts: ['read-the-plaque.lndo.site'],
},
},
},
'@kopflos-cms/hydra': {
apis: ['http://localhost:1429/api'],
apis: [baseIri + '/api'],
},
'@kopflos-cms/shacl': {},
},
Expand Down
22 changes: 22 additions & 0 deletions example/resources/countries.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,26 @@ prefix kl-hydra: <https://kopflos.described.at/hydra#>
sh:property [ sh:path schema:name ; sh:languageIn ("en" "de") ] ;
sh:property [ sh:path schema:identifier ] ;
] ;
hydra:limit 10 ;
sh:orderBy
[
sh:nodes [ sh:path schema:name ; ] ;
sh:filterShape
[
sh:languageIn ( "en" ) ;
] ;
] ;
hydra:search
[
hydra:template "{?limit,offset}" ;
hydra:mapping
[
hydra:variable "limit" ;
hydra:property hydra:limit ;
],
[
hydra:variable "offset" ;
hydra:property hydra:offset ;
] ;
] ;
.
57 changes: 57 additions & 0 deletions example/tests/collection-iterate.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
PREFIX lg: <https://purl.org/lg/>
base <http://localhost:1429/>
PREFIX log: <http://www.w3.org/2000/10/swap/log#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX earl: <http://www.w3.org/ns/earl#>
prefix : <https://always-read-the-plaque.tests/plaques/>
prefix tuner: <https://api-tuner.described.at/>
prefix hydra:<http://www.w3.org/ns/hydra/core#>
prefix schema: <http://schema.org/>

:fetchEntireCollection
a earl:TestCase ;
rdfs:label "Check chaining requests to fetch entire collection" ;
:fetch <countries?limit=50> ;
.

{
:fetchEntireCollection :fetch ?page .
} => {
?page a tuner:Request ;
tuner:method "GET" ;
tuner:url ?page ;
.
} .

{
?req tuner:response ?res .

?res tuner:http_code 200 .
?res tuner:body ?body .
?body log:includes {
<countries> hydra:member ?member .
?member schema:name ?name .
} .

(
{
?body log:includes {
<countries>!hydra:view hydra:next ?nextPage .
} .
}
{
?body log:includes {
<countries>!hydra:view hydra:next ?nextPage .
} .
true log:becomes {
:fetchEntireCollection :fetch ?nextPage
}
}
{
true log:becomes { :fetchEntireCollection earl:outcome earl:passed }
}
) log:ifThenElseIn [] .
} => {
<countries> hydra:member ?member .
?member schema:name ?name .
} .
26 changes: 26 additions & 0 deletions example/tests/html-served.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
base <http://localhost:1429/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX earl: <http://www.w3.org/ns/earl#>
PREFIX tuner: <https://api-tuner.described.at/>
prefix : <https://always-read-the-plaque.tests/html/>
prefix string: <http://www.w3.org/2000/10/swap/string#>

:fetchHTML
a earl:TestCase ;
rdfs:label "Check HTML is served" ;
.

:getPage
a tuner:Request ;
tuner:method "GET" ;
tuner:url <plaque/newton-s-apple-tree-monash-university.html> ;
.

{
:getPage tuner:response ?res .

?res tuner:http_code 200 .
?res tuner:header ( "content-type" "text/html.*" string:matches ) .
} => {
:fetchHTML earl:outcome earl:passed .
} .
79 changes: 77 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/lib/command/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default async function (args: BuildArgs) {
const plugins = await loadPlugins(config.plugins)

log.info('Running build actions...')
const buildActions = plugins.map(plugin => plugin.build?.())
const buildActions = plugins.map(Plugin => Plugin.build?.())
if (buildActions.length === 0) {
return log.warn('No plugins with build actions found')
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type { KopflosResponse, KopflosPlugin, PluginConfig, ResultEnvelope } from './lib/Kopflos.js'
export type { KopflosResponse, KopflosPlugin, PluginConfig, ResultEnvelope, KopflosPluginConstructor, Plugins } from './lib/Kopflos.js'
export type { Kopflos, KopflosConfig, Body, Query } from './lib/Kopflos.js'
export { default } from './lib/Kopflos.js'
export { loadHandlers as defaultHandlerLookup } from './lib/handler.js'
Expand Down
Loading

0 comments on commit 6839abd

Please sign in to comment.