forked from linkeddata/rdflib.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Datafactory & serializer types, enums linkeddata#355
- Loading branch information
Showing
15 changed files
with
360 additions
and
169 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
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,94 @@ | ||
import { TFNamedNode, TFBlankNode, TFLiteral, TFQuad, TFTerm, TFDataFactory, TFSubject, TFObject } from "./types" | ||
|
||
/** | ||
* Defines a strict subset of the DataFactory as defined in the RDF/JS: Data model specification | ||
* Non RDF-native features have been removed (e.g. no Variable, no Literal as predicate, etc.). | ||
* bnIndex is optional but useful. | ||
*/ | ||
export interface DataFactory< | ||
NamedNode extends TFNamedNode = TFNamedNode, | ||
BlankNode extends TFBlankNode = TFBlankNode, | ||
Literal extends TFLiteral = TFLiteral, | ||
FactoryTypes = NamedNode | TFBlankNode | Literal | TFQuad | ||
> extends TFDataFactory { | ||
bnIndex?: number | ||
|
||
supports: SupportTable | ||
|
||
literal(value: string, languageOrDatatype?: string | NamedNode): TFLiteral | ||
|
||
literal(value: unknown): Literal | ||
|
||
defaultGraph(): NamedNode | BlankNode | ||
|
||
quad( | ||
subject: NamedNode | BlankNode, | ||
predicate: NamedNode, | ||
object: NamedNode | BlankNode | Literal, | ||
graph?: NamedNode | ||
): TFQuad | ||
|
||
isQuad(obj: any): obj is TFQuad | ||
|
||
fromTerm(original: Literal | TFTerm): TFTerm | ||
|
||
fromQuad(original: TFQuad): TFQuad | ||
|
||
equals(a: Comparable, b: Comparable): boolean | ||
|
||
toNQ(term: FactoryTypes): string | ||
} | ||
|
||
export interface IdentityFactory< | ||
IndexType = Indexable, | ||
FactoryTypes = TFNamedNode | TFBlankNode | TFLiteral | TFQuad | ||
> extends DataFactory<FactoryTypes> { | ||
/** | ||
* Generates a unique session-idempotent identifier for the given object. | ||
* | ||
* @example NQ serialization (reversible from value) | ||
* @example MD5 hash of termType + value (irreversible from value, map needed) | ||
* | ||
* @return {Indexable} A unique value which must also be a valid JS object key type. | ||
*/ | ||
id(obj: FactoryTypes): IndexType | unknown | ||
|
||
} | ||
|
||
/** | ||
* Factory type which supports reverse id lookups. | ||
* | ||
* It should be able to resolve the value for any given id which it handed out. Passing an id not | ||
* generated by the same instance might result in a value or an exception depending on the | ||
* implementation. | ||
*/ | ||
export interface ReversibleIdentityFactory< | ||
IndexType = Indexable, | ||
FactoryTypes = TFNamedNode | TFBlankNode | TFLiteral | TFQuad | ||
> extends IdentityFactory<FactoryTypes> { | ||
fromId(id: IndexType): FactoryTypes; | ||
} | ||
|
||
export type Namespace = (term:string) => TFNamedNode | ||
export type NamespaceCreator = (ns: string) => Namespace | ||
|
||
export type SupportTable = Record<Feature, boolean> | ||
|
||
export enum Feature { | ||
/** Whether the factory supports termType:Collection terms */ | ||
collections = "COLLECTIONS", | ||
/** Whether the factory supports termType:DefaultGraph terms */ | ||
defaultGraphType = "DEFAULT_GRAPH_TYPE", | ||
/** Whether the factory supports equals on produced instances */ | ||
equalsMethod = "EQUALS_METHOD", | ||
/** Whether the factory can generate a unique session-idempotent identifier for a given object */ | ||
identity = "IDENTITY", | ||
/** Whether the factory supports mapping ids back to instances */ | ||
reversibleIdentity = "REVERSIBLE_IDENTITY", | ||
/** Whether the factory supports termType:Variable terms */ | ||
variableType = "VARIABLE_TYPE", | ||
} | ||
|
||
export type Comparable = TFNamedNode | TFBlankNode | TFLiteral | TFQuad | undefined | null | ||
|
||
export type Indexable = number | string |
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
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
Oops, something went wrong.