Skip to content

Commit

Permalink
build: update webpack loader
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Jan 26, 2024
1 parent 7e87e05 commit e1f2434
Show file tree
Hide file tree
Showing 28 changed files with 117 additions and 139 deletions.
9 changes: 1 addition & 8 deletions apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@
"@rdfine/hydra": "^0.10.2",
"@rdfjs-elements/lit-helpers": "^0.3.4",
"@rdfjs-elements/formats-pretty": "^0.5.1",
"@rdfjs/data-model": "^2.0.1",
"@rdfjs/dataset": "^2.0.1",
"@rdfjs/term-map": "^2.0.0",
"@rdfjs/term-set": "^2.0.0",
"@rdfjs/traverser": "^0.1.0",
"@shoelace-style/shoelace": "^2.0.0-beta.80",
"@tpluscode/rdf-ns-builders": "^4",
"@tpluscode/rdf-string": "^1.0.3",
"@tpluscode/sparql-builder": "^1.1.0",
"content-disposition": "^0.5.4",
Expand All @@ -38,7 +32,6 @@
"@zazuko/prefixes": "^2.0.0",
"@zazuko/vocabulary-extras": "^2.0.1",
"alcaeus": "^2.3.2",
"clownface": "^2",
"clownface-shacl-path": "^2.0.2",
"get-stream": "^6.0.1",
"is-absolute-url": "^4.0.1",
Expand Down Expand Up @@ -69,7 +62,7 @@
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.2",
"webpack-loader-rdf": "^0.1.1",
"webpack-loader-rdf": "^0.2.0",
"webpack-merge": "^5.8.0"
}
}
9 changes: 4 additions & 5 deletions apps/www/src/automation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { rdfs, rdf } from '@tpluscode/rdf-ns-builders'
import TermMap from '@rdfjs/term-map'
import rdf from '@view-builder/core/env.js'
import * as ns from '@view-builder/core/ns.js'
import * as dimensionQueries from './queries/dimensions.js'
import { deleteCbd, newReference } from './clownface.js'
Expand All @@ -26,7 +25,7 @@ async function createKeyDimensions(view, pointer, client, { findKeyDimensions })

map.set(dimension, value)
return map
}, new TermMap())
}, rdf.termMap())

for (const [dimension, { label, sources }] of dimensions) {
view.addOut(ns.view.dimension, (viewDim) => {
Expand All @@ -39,7 +38,7 @@ async function createKeyDimensions(view, pointer, client, { findKeyDimensions })
})

if (label) {
viewDim.addOut(rdfs.label, `Key ${label.value}`)
viewDim.addOut(rdf.ns.rdfs.label, `Key ${label.value}`)
}
})
}
Expand Down Expand Up @@ -68,7 +67,7 @@ async function createMeasureDimensions(view, sources, client, { findMeasureDimen
})

if (label) {
viewDim.addOut(rdfs.label, `Measure ${label.value} (${source.out(rdfs.label).value})`)
viewDim.addOut(rdf.ns.rdfs.label, `Measure ${label.value} (${source.out(rdf.ns.rdfs.label).value})`)
}
})
}
Expand Down
8 changes: 3 additions & 5 deletions apps/www/src/clownface.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import $rdf from '@view-builder/core/env.js'
import Traverser from '@rdfjs/traverser'
import TermSet from '@rdfjs/term-set'

export function newReference(ptr) {
return $rdf.clownface({
Expand All @@ -9,7 +7,7 @@ export function newReference(ptr) {
})
}

const subgraph = new Traverser(({ level, quad }) => level === 0 || quad.subject.termType === 'BlankNode', { factory: $rdf })
const subgraph = $rdf.traverser(({ level, quad }) => level === 0 || quad.subject.termType === 'BlankNode')

export function deleteCbd(ptr) {
for (const quad of subgraph.match(ptr)) {
Expand All @@ -18,7 +16,7 @@ export function deleteCbd(ptr) {
}

export function getAllTriplesFromRoot(ptr) {
const visited = new TermSet()
const traverser = new Traverser(({ quad }) => !visited.has(quad.subject), { factory: $rdf })
const visited = $rdf.termSet()
const traverser = $rdf.traverser(({ quad }) => !visited.has(quad.subject))
return traverser.match(ptr)
}
6 changes: 3 additions & 3 deletions apps/www/src/component/decorators.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { dash, rdf } from '@tpluscode/rdf-ns-builders'
import $rdf from '@view-builder/core/env.js'

export const dataGraphInstanceSource = {
applicableTo(component) {
return component.editor.equals(dash.InstancesSelectEditor)
return component.editor.equals($rdf.ns.dash.InstancesSelectEditor)
},
decorate(component) {
return {
Expand All @@ -16,7 +16,7 @@ export const dataGraphInstanceSource = {

return focusNode
.any()
.has(rdf.type, clas.id)
.has($rdf.ns.rdf.type, clas.id)
.toArray()
},
}
Expand Down
4 changes: 2 additions & 2 deletions apps/www/src/element/ssz-notifications.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { css, html, LitElement, render } from 'lit'
import { connect } from '@captaincodeman/rdx'
import $rdf from '@view-builder/core/env.js'
import '@shoelace-style/shoelace/dist/components/dialog/dialog.js'
import '@shoelace-style/shoelace/dist/components/icon/icon.js'
import '@shoelace-style/shoelace/dist/components/progress-bar/progress-bar.js'
import './ssz-shacl-report.js'
import { rdfs } from '@tpluscode/rdf-ns-builders'
import { store } from '../state/store.js'

export class SszNotifications extends connect(store, LitElement) {
Expand Down Expand Up @@ -88,7 +88,7 @@ export class SszNotifications extends connect(store, LitElement) {

renderError() {
return html`<sl-dialog ?open="${!!this.error}"
.label="${this.error?.out(rdfs.comment).value || ''}"
.label="${this.error?.out($rdf.ns.rdfs.comment).value || ''}"
@sl-after-hide="${() => store.dispatch.notifications.hideError()}">
<ssz-shacl-report .report="${this.error}"></ssz-shacl-report>
</sl-dialog>`
Expand Down
17 changes: 8 additions & 9 deletions apps/www/src/element/ssz-shacl-report.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { html, LitElement } from 'lit'
import TermMap from '@rdfjs/term-map'
import { sh } from '@tpluscode/rdf-ns-builders'
import $rdf from '@view-builder/core/env.js'
import '@shoelace-style/shoelace/dist/components/details/details.js'
import { toSparql } from 'clownface-shacl-path'

Expand All @@ -22,15 +21,15 @@ customElements.define('ssz-shacl-report', class extends LitElement {
return []
}

const map = this.report.out(sh.result)
const map = this.report.out($rdf.ns.sh.result)
.toArray()
.reduce((previous, result) => {
const focusNode = result.out(sh.focusNode).term
const focusNode = result.out($rdf.ns.sh.focusNode).term
const results = previous.get(focusNode) || []
results.push(result)
previous.set(focusNode, results)
return previous
}, new TermMap())
}, $rdf.termMap())

return [...map]
}
Expand All @@ -41,7 +40,7 @@ customElements.define('ssz-shacl-report', class extends LitElement {

renderFocusNodeResults([focusNode, results]) {
const grouped = results.reduce(({ warnings, violations }, result) => {
if (result.out(sh.resultSeverity).term?.equals(sh.Warning)) {
if (result.out($rdf.ns.sh.resultSeverity).term?.equals($rdf.ns.sh.Warning)) {
return { violations, warnings: [...warnings, result] }
}

Expand Down Expand Up @@ -78,9 +77,9 @@ customElements.define('ssz-shacl-report', class extends LitElement {

// eslint-disable-next-line class-methods-use-this
renderResult(result) {
const property = result.out(sh.sourceShape).out(sh.name).value ||
toSparql(result.out(sh.resultPath)).toString({ prologue: false })
const property = result.out($rdf.ns.sh.sourceShape).out($rdf.ns.sh.name).value ||
toSparql(result.out($rdf.ns.sh.resultPath)).toString({ prologue: false })

return html`<li>${property}: ${result.out(sh.resultMessage)}</li>`
return html`<li>${property}: ${result.out($rdf.ns.sh.resultMessage)}</li>`
}
})
10 changes: 5 additions & 5 deletions apps/www/src/element/ssz-view-table.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css, html, LitElement } from 'lit'
import { repeat } from 'lit/directives/repeat.js'
import { schema, vcard } from '@tpluscode/rdf-ns-builders'
import $rdf from '@view-builder/core/env.js'
import '@shoelace-style/shoelace/dist/components/icon-button/icon-button.js'
import { ssz } from '@view-builder/core/ns.js'

Expand Down Expand Up @@ -52,10 +52,10 @@ customElements.define('ssz-view-table', class extends LitElement {

return html`
<tr class="view-row" @click="${() => this.dispatchEvent(new CustomEvent('view-select', { detail: { view } }))}">
<td>${view.out(schema.alternateName).value}</td>
<td>${view.out(schema.name).value}</td>
<td>${metadataCreator.out(vcard.hasName).value || metadataCreator.value}</td>
<td>${view.out(schema.author).out(vcard.hasName).value}</td>
<td>${view.out($rdf.ns.schema.alternateName).value}</td>
<td>${view.out($rdf.ns.schema.name).value}</td>
<td>${metadataCreator.out($rdf.ns.vcard.hasName).value || metadataCreator.value}</td>
<td>${view.out($rdf.ns.schema.author).out($rdf.ns.vcard.hasName).value}</td>
<td>
<sl-icon-button name="trash"
label="Delete"
Expand Down
5 changes: 2 additions & 3 deletions apps/www/src/fetch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import str2stream from 'string-to-stream'
import RDF from '@rdfjs/dataset'
import clownface from 'clownface'
import RDF from '@view-builder/core/env.js'
import isAbsoluteUrl from 'is-absolute-url'

export async function fetch(id, what) {
Expand All @@ -15,7 +14,7 @@ export async function fetch(id, what) {
dataset.add(quad)
}

const graph = clownface({ dataset })
const graph = RDF.clownface({ dataset })
return isAbsoluteUrl(id) ? graph.namedNode(id) : graph
}

Expand Down
4 changes: 2 additions & 2 deletions apps/www/src/forms/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import * as templates from '@hydrofoil/shaperone-wc-shoelace/templates.js'
import * as shoelace from '@hydrofoil/shaperone-wc-shoelace/components.js'
import { instancesMultiSelectEditor } from '@hydrofoil/shaperone-wc-shoelace/component-extras.js'
import shaperoneHydra from '@hydrofoil/shaperone-hydra'
import { rdfs, schema } from '@tpluscode/rdf-ns-builders'
import $rdf from '@view-builder/core/env.js'
import * as decorators from '../component/decorators.js'
import * as editors from '../editor/index.js'
import dynamicXone from './dynamicXone.js'
import debugProperties from './debugProperties.js'

shaperoneHydra(configure)

shoelace.autocomplete.labelProperties = [schema.name, rdfs.label]
shoelace.autocomplete.labelProperties = [$rdf.ns.schema.name, $rdf.ns.rdfs.label]

configure.editors.addMatchers(editors)

Expand Down
4 changes: 2 additions & 2 deletions apps/www/src/forms/dynamicXone.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { decorate } from '@hydrofoil/shaperone-wc/templates.js'
import { findNodes } from 'clownface-shacl-path'
import { isGraphPointer } from 'is-graph-pointer'
import { owl } from '@tpluscode/rdf-ns-builders'
import $rdf from '@view-builder/core/env.js'
import sh1 from '@hydrofoil/shaperone-core/ns.js'

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ export default decorate(wrapped => function dynamicXone(context, args) {
return wrapped(context, args)
})

const { differentFrom } = owl
const { differentFrom } = $rdf.ns.owl
function shouldDisplay(shape, value) {
const discriminatorValue = shape.pointer.out(sh1.discriminatorValue)

Expand Down
18 changes: 9 additions & 9 deletions apps/www/src/forms/plugins/autoName.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sh1 from '@hydrofoil/shaperone-core/ns.js'
import { SELECT } from '@tpluscode/sparql-builder'
import { rdfs, rdf, schema } from '@tpluscode/rdf-ns-builders'
import { isGraphPointer, isLiteral } from 'is-graph-pointer'
import { findNodes, toSparql } from 'clownface-shacl-path'
import { view, viewBuilder } from '@view-builder/core/ns.js'
import $rdf from '@view-builder/core/env.js'
import { store } from '../../state/store.js'

export const autoResourceLabel = {
Expand Down Expand Up @@ -31,7 +31,7 @@ export const autoResourceLabel = {
}

const label = await loadResourceLabel(arg.newValue, labelPath)
focusNode.deleteOut(rdfs.label).addOut(rdfs.label, label)
focusNode.deleteOut($rdf.ns.rdfs.label).addOut($rdf.ns.rdfs.label, label)
forms.updateComponentState({ ...arg, newState: { label } })
},
}
Expand All @@ -51,7 +51,7 @@ export const filterLabel = {
*/
'forms/setObjectValue': async (arg) => {
const { focusNode, property } = arg
if (focusNode.has(rdf.type, view.Filter).terms.length === 0) {
if (focusNode.has($rdf.ns.rdf.type, view.Filter).terms.length === 0) {
return
}

Expand All @@ -66,27 +66,27 @@ export const filterLabel = {
const argument = focusNode.out(view.argument)

if (isGraphPointer(filterTermSet)) {
const dimensionLabel = await loadResourceLabel(dimension.term, schema.name)
const termSetLabel = await loadResourceLabel(filterTermSet.term, schema.name)
const dimensionLabel = await loadResourceLabel(dimension.term, $rdf.ns.schema.name)
const termSetLabel = await loadResourceLabel(filterTermSet.term, $rdf.ns.schema.name)

label = `${dimensionLabel} is one of "${termSetLabel}"`
} else if (isGraphPointer(operator) && isGraphPointer(argument)) {
const dimensionLabel = await loadResourceLabel(dimension.term, schema.name)
const operatorLabel = property.pointer.node(operator).out(rdfs.label).value
const dimensionLabel = await loadResourceLabel(dimension.term, $rdf.ns.schema.name)
const operatorLabel = property.pointer.node(operator).out($rdf.ns.rdfs.label).value

label = `${dimensionLabel} ${operatorLabel} "${argument.value}"`
}
}

focusNode.deleteOut(rdfs.label).addOut(rdfs.label, label)
focusNode.deleteOut($rdf.ns.rdfs.label).addOut($rdf.ns.rdfs.label, label)
forms.updateComponentState({ ...arg, newState: { label } })
},
}
},
},
}

async function loadResourceLabel(id, labelPath = rdfs.label) {
async function loadResourceLabel(id, labelPath = $rdf.ns.rdfs.label) {
try {
const propertyPath = isGraphPointer(labelPath)
? toSparql(labelPath)
Expand Down
10 changes: 5 additions & 5 deletions apps/www/src/queries/dimensions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SELECT } from '@tpluscode/sparql-builder'
import { schema, sh } from '@tpluscode/rdf-ns-builders'
import $rdf from '@view-builder/core/env.js'
import { VALUES } from '@tpluscode/sparql-builder/expressions'
import * as ns from '@view-builder/core/ns.js'

Expand All @@ -13,9 +13,9 @@ import * as ns from '@view-builder/core/ns.js'
export function findMeasureDimensions(cube, client) {
return SELECT.DISTINCT`?dimension ?label`
.WHERE`
${cube} ${ns.cube.observationConstraint}/${sh.property}/${sh.path} ?dimension .
${cube} ${ns.cube.observationConstraint}/${$rdf.ns.sh.property}/${$rdf.ns.sh.path} ?dimension .
optional { ?dimension ${schema.name} ?label . }
optional { ?dimension ${$rdf.ns.schema.name} ?label . }
?dimension a ${ns.cube.MeasureDimension}
`.execute(client.query)
Expand All @@ -36,9 +36,9 @@ export function findKeyDimensions(cubes, client) {
.WHERE`
${VALUES(...cubeValues)}
?cube ${ns.cube.observationConstraint}/${sh.property}/${sh.path} ?dimension .
?cube ${ns.cube.observationConstraint}/${$rdf.ns.sh.property}/${$rdf.ns.sh.path} ?dimension .
optional { ?dimension ${schema.name} ?label . }
optional { ?dimension ${$rdf.ns.schema.name} ?label . }
?dimension a ${ns.cube.KeyDimension}
`.execute(client.query)
Expand Down
6 changes: 3 additions & 3 deletions apps/www/src/queries/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { hydra } from '@tpluscode/rdf-ns-builders'
import $rdf from '@view-builder/core/env.js'

export function getSparqlUrl({ query, template, client }) {
const url = new URL(client.query.endpoint.endpointUrl)
url.searchParams.append('query', query)

return template
.out(hydra.mapping)
.out(hydra.variable)
.out($rdf.ns.hydra.mapping)
.out($rdf.ns.hydra.variable)
.toArray()
.reduce((encoded, { value }) => encoded.replace(new RegExp(`%7B${value}%7D`, 'g'), `{${value}}`), url.toString())
}
5 changes: 2 additions & 3 deletions apps/www/src/state/app/effects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { rdf } from '@tpluscode/rdf-ns-builders'
import TermSet from '@rdfjs/term-set'
import $rdf from '@view-builder/core/env.js'
import url from 'url-state'
import * as ns from '@view-builder/core/ns.js'
import { viewBuilder } from '@view-builder/core/ns.js'
Expand Down Expand Up @@ -49,7 +48,7 @@ export default function effects(store) {
dispatch.app.setSparqlEndpoint(endpoint)
const client = store.getState().app.sparqlClient

const types = new TermSet(pointer.out(rdf.type).terms)
const types = $rdf.termSet(pointer.out($rdf.ns.rdf.type).terms)
if (types.has(ns.viewBuilder.ViewCollection)) {
view = await import('../../view/viewCollection.js')
} else if (types.has(ns.view.View)) {
Expand Down
Loading

0 comments on commit e1f2434

Please sign in to comment.