parent
09706ef4d7
commit
cc4159e348
@ -1,77 +0,0 @@ |
||||
import { parseRdf, startTransaction, toSparqlUpdate, toTurtle } from "../src"; |
||||
import { FoafProfileShapeType } from "./ldo/foafProfile.shapeTypes"; |
||||
|
||||
async function run() { |
||||
const rawTurtle = ` |
||||
<#me> a <http://xmlns.com/foaf/0.1/Person>; |
||||
<http://xmlns.com/foaf/0.1/name> "Jane Doe". |
||||
`;
|
||||
|
||||
/** |
||||
* Step 1: Convert Raw RDF into a Linked Data Object |
||||
*/ |
||||
const ldoDataset = await parseRdf(rawTurtle, { |
||||
baseIRI: "https://solidweb.me/jane_doe/profile/card", |
||||
}); |
||||
// Create a linked data object by telling the dataset the type and subject of
|
||||
// the object
|
||||
const janeProfile = ldoDataset |
||||
// Tells the LDO dataset that we're looking for a FoafProfile
|
||||
.usingType(FoafProfileShapeType) |
||||
// Says the subject of the FoafProfile
|
||||
.fromSubject("https://solidweb.me/jane_doe/profile/card#me"); |
||||
|
||||
/** |
||||
* Step 2: Manipulate the Linked Data Object |
||||
*/ |
||||
// Logs "Jane Doe"
|
||||
console.log(janeProfile.name); |
||||
// Logs "Person"
|
||||
console.log(janeProfile.type); |
||||
// Logs 0
|
||||
console.log(janeProfile.knows?.length); |
||||
|
||||
// Begins a transaction that tracks your changes
|
||||
startTransaction(janeProfile); |
||||
janeProfile.name = "Jane Smith"; |
||||
janeProfile.knows?.push({ |
||||
"@id": "https://solidweb.me/john_smith/profile/card#me", |
||||
type: { |
||||
"@id": "Person", |
||||
}, |
||||
name: "John Smith", |
||||
knows: [janeProfile], |
||||
}); |
||||
|
||||
// Logs "Jane Smith"
|
||||
console.log(janeProfile.name); |
||||
// Logs "John Smith"
|
||||
console.log(janeProfile.knows?.[0].name); |
||||
// Logs "Jane Smith"
|
||||
console.log(janeProfile.knows?.[0].knows?.[0].name); |
||||
|
||||
/** |
||||
* Step 3: Convert it back to RDF |
||||
*/ |
||||
// Logs:
|
||||
// <https://solidweb.me/jane_doe/profile/card#me> a <http://xmlns.com/foaf/0.1/Person>;
|
||||
// <http://xmlns.com/foaf/0.1/name> "Jane Smith";
|
||||
// <http://xmlns.com/foaf/0.1/knows> <https://solidweb.me/john_smith/profile/card#me>.
|
||||
// <https://solidweb.me/john_smith/profile/card#me> a <http://xmlns.com/foaf/0.1/Person>;
|
||||
// <http://xmlns.com/foaf/0.1/name> "John Smith";
|
||||
// <http://xmlns.com/foaf/0.1/knows> <https://solidweb.me/jane_doe/profile/card#me>.
|
||||
console.log(await toTurtle(janeProfile)); |
||||
// Logs:
|
||||
// DELETE DATA {
|
||||
// <https://solidweb.me/jane_doe/profile/card#me> <http://xmlns.com/foaf/0.1/name> "Jane Doe" .
|
||||
// };
|
||||
// INSERT DATA {
|
||||
// <https://solidweb.me/jane_doe/profile/card#me> <http://xmlns.com/foaf/0.1/name> "Jane Smith" .
|
||||
// <https://solidweb.me/jane_doe/profile/card#me> <http://xmlns.com/foaf/0.1/knows> <https://solidweb.me/john_smith/profile/card#me> .
|
||||
// <https://solidweb.me/john_smith/profile/card#me> <http://xmlns.com/foaf/0.1/name> "John Smith" .
|
||||
// <https://solidweb.me/john_smith/profile/card#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
|
||||
// <https://solidweb.me/john_smith/profile/card#me> <http://xmlns.com/foaf/0.1/knows> <https://solidweb.me/jane_doe/profile/card#me> .
|
||||
// }
|
||||
console.log(await toSparqlUpdate(janeProfile)); |
||||
} |
||||
run(); |
@ -1,26 +0,0 @@ |
||||
import type { ContextDefinition } from "jsonld"; |
||||
|
||||
/** |
||||
* ============================================================================= |
||||
* foafProfileContext: JSONLD Context for foafProfile |
||||
* ============================================================================= |
||||
*/ |
||||
export const foafProfileContext: ContextDefinition = { |
||||
type: { |
||||
"@id": "@type", |
||||
}, |
||||
Person: "http://xmlns.com/foaf/0.1/Person", |
||||
name: { |
||||
"@id": "http://xmlns.com/foaf/0.1/name", |
||||
"@type": "http://www.w3.org/2001/XMLSchema#string", |
||||
}, |
||||
img: { |
||||
"@id": "http://xmlns.com/foaf/0.1/img", |
||||
"@type": "http://www.w3.org/2001/XMLSchema#string", |
||||
}, |
||||
knows: { |
||||
"@id": "http://xmlns.com/foaf/0.1/knows", |
||||
"@type": "@id", |
||||
"@container": "@set", |
||||
}, |
||||
}; |
@ -1,93 +0,0 @@ |
||||
import { Schema } from "shexj"; |
||||
|
||||
/** |
||||
* ============================================================================= |
||||
* foafProfileSchema: ShexJ Schema for foafProfile |
||||
* ============================================================================= |
||||
*/ |
||||
export const foafProfileSchema: Schema = { |
||||
type: "Schema", |
||||
shapes: [ |
||||
{ |
||||
id: "https://example.com/FoafProfile", |
||||
type: "Shape", |
||||
expression: { |
||||
type: "EachOf", |
||||
expressions: [ |
||||
{ |
||||
type: "TripleConstraint", |
||||
predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", |
||||
valueExpr: { |
||||
type: "NodeConstraint", |
||||
values: ["http://xmlns.com/foaf/0.1/Person"], |
||||
}, |
||||
annotations: [ |
||||
{ |
||||
type: "Annotation", |
||||
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||
object: { |
||||
value: "Defines the node as a Person (from foaf)", |
||||
}, |
||||
}, |
||||
], |
||||
}, |
||||
{ |
||||
type: "TripleConstraint", |
||||
predicate: "http://xmlns.com/foaf/0.1/name", |
||||
valueExpr: { |
||||
type: "NodeConstraint", |
||||
datatype: "http://www.w3.org/2001/XMLSchema#string", |
||||
}, |
||||
min: 0, |
||||
max: 1, |
||||
annotations: [ |
||||
{ |
||||
type: "Annotation", |
||||
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||
object: { |
||||
value: "Define a person's name.", |
||||
}, |
||||
}, |
||||
], |
||||
}, |
||||
{ |
||||
type: "TripleConstraint", |
||||
predicate: "http://xmlns.com/foaf/0.1/img", |
||||
valueExpr: { |
||||
type: "NodeConstraint", |
||||
datatype: "http://www.w3.org/2001/XMLSchema#string", |
||||
}, |
||||
min: 0, |
||||
max: 1, |
||||
annotations: [ |
||||
{ |
||||
type: "Annotation", |
||||
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||
object: { |
||||
value: "Photo link but in string form", |
||||
}, |
||||
}, |
||||
], |
||||
}, |
||||
{ |
||||
type: "TripleConstraint", |
||||
predicate: "http://xmlns.com/foaf/0.1/knows", |
||||
valueExpr: "https://example.com/FoafProfile", |
||||
min: 0, |
||||
max: -1, |
||||
annotations: [ |
||||
{ |
||||
type: "Annotation", |
||||
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||
object: { |
||||
value: "A list of WebIds for all the people this user knows.", |
||||
}, |
||||
}, |
||||
], |
||||
}, |
||||
], |
||||
}, |
||||
extra: ["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"], |
||||
}, |
||||
], |
||||
}; |
@ -1,19 +0,0 @@ |
||||
import { ShapeType } from "../../lib"; |
||||
import { foafProfileSchema } from "./foafProfile.schema"; |
||||
import { foafProfileContext } from "./foafProfile.context"; |
||||
import { FoafProfile } from "./foafProfile.typings"; |
||||
|
||||
/** |
||||
* ============================================================================= |
||||
* LDO ShapeTypes foafProfile |
||||
* ============================================================================= |
||||
*/ |
||||
|
||||
/** |
||||
* FoafProfile ShapeType |
||||
*/ |
||||
export const FoafProfileShapeType: ShapeType<FoafProfile> = { |
||||
schema: foafProfileSchema, |
||||
shape: "https://example.com/FoafProfile", |
||||
context: foafProfileContext, |
||||
}; |
@ -1,33 +0,0 @@ |
||||
import { ContextDefinition } from "jsonld"; |
||||
|
||||
/** |
||||
* ============================================================================= |
||||
* Typescript Typings for foafProfile |
||||
* ============================================================================= |
||||
*/ |
||||
|
||||
/** |
||||
* FoafProfile Type |
||||
*/ |
||||
export interface FoafProfile { |
||||
"@id"?: string; |
||||
"@context"?: ContextDefinition; |
||||
/** |
||||
* Defines the node as a Person (from foaf) |
||||
*/ |
||||
type: { |
||||
"@id": "Person"; |
||||
}; |
||||
/** |
||||
* Define a person's name. |
||||
*/ |
||||
name?: string; |
||||
/** |
||||
* Photo link but in string form |
||||
*/ |
||||
img?: string; |
||||
/** |
||||
* A list of WebIds for all the people this user knows. |
||||
*/ |
||||
knows?: FoafProfile[]; |
||||
} |
@ -1,15 +0,0 @@ |
||||
PREFIX ex: <https://example.com/> |
||||
PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
||||
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> |
||||
|
||||
ex:FoafProfile EXTRA a { |
||||
a [ foaf:Person ] |
||||
// rdfs:comment "Defines the node as a Person (from foaf)" ; |
||||
foaf:name xsd:string ? |
||||
// rdfs:comment "Define a person's name." ; |
||||
foaf:img xsd:string ? |
||||
// rdfs:comment "Photo link but in string form" ; |
||||
foaf:knows @ex:FoafProfile * |
||||
// rdfs:comment "A list of WebIds for all the people this user knows." ; |
||||
} |
@ -1,195 +0,0 @@ |
||||
const resourceMethods: Record<string, string[]> = { |
||||
RootContainerResource: [ |
||||
"uri", |
||||
"isLoading", |
||||
"didInitialFetch", |
||||
"ldoDataset", |
||||
"getIsRootContainer", |
||||
"createContainerIn", |
||||
"createDataResourceIn", |
||||
"uploadBinaryIn", |
||||
"createOrOverwrite", |
||||
"read", |
||||
"reload", |
||||
"load", |
||||
"clear", |
||||
"clearIfPresent", |
||||
], |
||||
ContainerResource: [ |
||||
"uri", |
||||
"isLoading", |
||||
"didInitialFetch", |
||||
"parentContainer", |
||||
"getIsRootContainer", |
||||
"getParentContainer", |
||||
"childResources", |
||||
"getRootContainer", |
||||
"createContainerIn", |
||||
"createDataResourceIn", |
||||
"uploadBinaryIn", |
||||
"ldoDataset", |
||||
"createOrOverwrite", |
||||
"read", |
||||
"reload", |
||||
"load", |
||||
"delete", |
||||
"deleteIfPresent", |
||||
"clear", |
||||
"clearIfPresent", |
||||
], |
||||
ChildDataResource: [ |
||||
"uri", |
||||
"isLoading", |
||||
"didInitialFetch", |
||||
"parentContainer", |
||||
"getParentContainer", |
||||
"hasData", |
||||
"ldoDataset", |
||||
"getRootContainer", |
||||
"createOrOverwrite", |
||||
"read", |
||||
"reload", |
||||
"load", |
||||
"delete", |
||||
"deleteIfPresent", |
||||
], |
||||
BinaryResource: [ |
||||
"uri", |
||||
"isLoading", |
||||
"didInitialFetch", |
||||
"mimeType", |
||||
"fileExtension", |
||||
"getRootContainer", |
||||
"getParentContainer", |
||||
"uploadOrOverwrite", |
||||
"read", |
||||
"reload", |
||||
"load", |
||||
"delete", |
||||
"deleteIfPresent", |
||||
], |
||||
AbsentContainerResource: [ |
||||
"uri", |
||||
"isLoading", |
||||
"didInitialFetch", |
||||
"parentContainer", |
||||
"getIsRootContainer", |
||||
"getParentContainer", |
||||
"getRootContainer", |
||||
"createContainerIn", |
||||
"createDataResourceIn", |
||||
"uploadBinaryIn", |
||||
"createOrOverwrite", |
||||
"create", |
||||
"createIfAbsent", |
||||
"read", |
||||
"reload", |
||||
"load", |
||||
"deleteIfPresent", |
||||
"clearIfPresent", |
||||
], |
||||
AbsentChildDataResource: [ |
||||
"uri", |
||||
"isLoading", |
||||
"didInitialFetch", |
||||
"parentContainer", |
||||
"getParentContainer", |
||||
"getRootContainer", |
||||
"createOrOverwrite", |
||||
"create", |
||||
"createIfAbsent", |
||||
"read", |
||||
"reload", |
||||
"load", |
||||
"deleteIfPresent", |
||||
], |
||||
AbsentBinaryResource: [ |
||||
"uri", |
||||
"isLoading", |
||||
"didInitialFetch", |
||||
"parentContainer", |
||||
"getParentContainer", |
||||
"getRootContainer", |
||||
"uploadOrOverwrite", |
||||
"upload", |
||||
"uploadIfAbsent", |
||||
"read", |
||||
"reload", |
||||
"load", |
||||
"deleteIfPresent", |
||||
], |
||||
UnfetchedContainerResource: [ |
||||
"uri", |
||||
"isLoading", |
||||
"didInitialFetch", |
||||
"getIsRootContainer", |
||||
"getParentContainer", |
||||
"getRootContainer", |
||||
"createContainerIn", |
||||
"createDataResourceIn", |
||||
"uploadBinaryIn", |
||||
"createOrOverwrite", |
||||
"createIfAbsent", |
||||
"read", |
||||
"reload", |
||||
"load", |
||||
"clearIfPresent", |
||||
], |
||||
UnfetchedChildDataResource: [ |
||||
"parentContainer", |
||||
"getParentContainer", |
||||
"uri", |
||||
"isLoading", |
||||
"didInitialFetch", |
||||
"getRootContainer", |
||||
"createOrOverwrite", |
||||
"createIfAbsent", |
||||
"read", |
||||
"reload", |
||||
"load", |
||||
"deleteIfPresent", |
||||
], |
||||
UnfetchedBinaryResource: [ |
||||
"uri", |
||||
"isLoading", |
||||
"didInitialFetch", |
||||
"parentContainer", |
||||
"getParentContainer", |
||||
"getRootContainer", |
||||
"uploadOrOverwrite", |
||||
"createOrOverwrite", |
||||
"uploadIfAbsent", |
||||
"read", |
||||
"reload", |
||||
"load", |
||||
"deleteIfPresent", |
||||
], |
||||
}; |
||||
|
||||
function processTypes() { |
||||
const usedKeys = new Set(); |
||||
const interfaces = Object.keys(resourceMethods); |
||||
const groupMap: Record<string, string[]> = {}; |
||||
|
||||
interfaces.forEach((interfaceName) => { |
||||
resourceMethods[interfaceName].forEach((methodKey) => { |
||||
if (!usedKeys.has(methodKey)) { |
||||
usedKeys.add(methodKey); |
||||
|
||||
let groupName = ""; |
||||
interfaces.forEach((interfaceName) => { |
||||
if (resourceMethods[interfaceName].includes(methodKey)) { |
||||
groupName += `${interfaceName}|`; |
||||
} |
||||
}); |
||||
if (!groupMap[groupName]) { |
||||
groupMap[groupName] = []; |
||||
} |
||||
groupMap[groupName].push(methodKey); |
||||
} |
||||
}); |
||||
}); |
||||
|
||||
console.log(groupMap); |
||||
} |
||||
processTypes(); |
@ -1,22 +0,0 @@ |
||||
import { Mixin } from "ts-mixer"; |
||||
|
||||
class Foo { |
||||
protected makeFoo() { |
||||
return "foo"; |
||||
} |
||||
} |
||||
|
||||
class Bar { |
||||
protected makeFoo() { |
||||
return "bar"; |
||||
} |
||||
} |
||||
|
||||
class FooBar extends Mixin(Foo, Bar) { |
||||
public makeFooBar() { |
||||
return this.makeFoo() + this.makeFoo(); |
||||
} |
||||
} |
||||
|
||||
const fooBar = new FooBar(); |
||||
console.log(fooBar.makeFooBar()); |
@ -0,0 +1,5 @@ |
||||
{ |
||||
"entryPoints": ["src/index.ts"], |
||||
"out": "docs", |
||||
"allReflectionsHaveOwnDocument": true |
||||
} |
@ -1,10 +1,10 @@ |
||||
export { |
||||
default as createSubscribableDataset, |
||||
createWrapperSubscribableDataset as createSubscribableDataset, |
||||
createWrapperSubscribableDatasetFactory as createSubscribableDatasetFactory, |
||||
} from "./createWrapperSubscribableDataset"; |
||||
export { default as serializedToSubscribableDataset } from "./createWrapperSubscribableDatasetFromSerializedInput"; |
||||
export { default as ProxyTransactionalDataset } from "./ProxyTransactionalDataset"; |
||||
export { default as WrapperSubscribableDataset } from "./WrapperSubscribableDataset"; |
||||
export { default as WrapperSubscribableDatasetFactory } from "./WrapperSubscribableDatasetFactory"; |
||||
export { createWrapperSubscribableDatasetFromSerializedInput as serializedToSubscribableDataset } from "./createWrapperSubscribableDatasetFromSerializedInput"; |
||||
export * from "./ProxyTransactionalDataset"; |
||||
export * from "./WrapperSubscribableDataset"; |
||||
export * from "./WrapperSubscribableDatasetFactory"; |
||||
export * from "./types"; |
||||
export * from "./mergeDatasetChanges"; |
||||
|
Loading…
Reference in new issue