Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Move core package to subdir
Browse files Browse the repository at this point in the history
Build with pika
  • Loading branch information
Fletcher91 committed Nov 26, 2019
1 parent 5156457 commit 13d8fb2
Show file tree
Hide file tree
Showing 10 changed files with 5,562 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/*
node_modules/
pkg/
.idea
.rpt2*
coverage/**
Expand Down
56 changes: 56 additions & 0 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@ontologies/core",
"version": "1.5.0",
"@pika/pack": {
"pipeline": [
[
"@pika/plugin-ts-standard-pkg",
{
"exclude": [
"__tests__/**/*"
]
}
],
[
"@pika/plugin-build-node"
],
[
"@pika/plugin-build-web"
]
]
},
"description": "Like definitely typed, but for ontologies",
"main": "dist/cjs/index.js",
"module": "dist/module/index.js",
"sideEffects": true,
"types": "dist/module/index.d.ts",
"scripts": {
"build": "pika build",
"test": "exit 0",
"version": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ontola/ontologies.git"
},
"author": "Fletcher91 <[email protected]>",
"license": "GPL-3.0-or-later",
"bugs": {
"url": "https://github.com/ontola/ontologies/issues"
},
"homepage": "https://github.com/ontola/ontologies#readme",
"dependencies": {
"@ungap/global-this": "^0.3.1"
},
"peerDependencies": {
"@ontologies/core": ">=1.5.0"
},
"devDependencies": {
"@pika/pack": "^0.5.0",
"@pika/plugin-build-node": "^0.8.1",
"@pika/plugin-build-web": "^0.8.1",
"@pika/plugin-ts-standard-pkg": "^0.8.1",
"eslint": "^6.7.1",
"typescript": "^3.7.2"
}
}
File renamed without changes.
61 changes: 31 additions & 30 deletions core/index.ts → core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,69 @@
import "@ungap/global-this"
import { DefaultFactory, PlainFactory } from "./PlainFactory"
import "@ungap/global-this";

import { DefaultFactory, PlainFactory } from "./PlainFactory";
import {
DataFactory,
IdentityFactory,
NamedNode,
Namespace,
} from "./types";

let setup: (factory?: DataFactory, override?: boolean) => void
let globalFactory: DataFactory & any
let globalSymbol: any
let setup: (factory?: DataFactory, override?: boolean) => void;
let globalFactory: DataFactory & any;
let globalSymbol: any;

if (typeof Symbol !== "undefined") {
const rdfFactory: unique symbol = Symbol.for('rdfFactory')
const rdfFactory: unique symbol = Symbol.for('rdfFactory');

setup = function setup(factory = DefaultFactory, override = true) {
if (typeof (globalThis as any)[rdfFactory] === "undefined" || override) {
(globalThis as any)[rdfFactory] = factory
globalFactory = factory
(globalThis as any)[rdfFactory] = factory;
globalFactory = factory;
} else if (typeof globalFactory === "undefined" || override) {
globalFactory = factory
globalFactory = factory;
}
}
};

globalFactory = (globalThis as any)[rdfFactory]
globalFactory = (globalThis as any)[rdfFactory];
globalSymbol = rdfFactory;
} else {
const rdfFactory = 'rdfFactory'
const rdfFactory = 'rdfFactory';

setup = function setup(factory = DefaultFactory, override = true) {
if (typeof (globalThis as any)[rdfFactory] === "undefined" || override) {
(globalThis as any)[rdfFactory] = factory
globalFactory = factory
(globalThis as any)[rdfFactory] = factory;
globalFactory = factory;
} else if (typeof globalFactory === "undefined" || override) {
globalFactory = factory
globalFactory = factory;
}
}
};

globalSymbol = rdfFactory;
globalFactory = (globalThis as any)[rdfFactory]
globalFactory = (globalThis as any)[rdfFactory];
}

export const createNS = (ns: string): Namespace =>
(term: string): NamedNode =>
globalFactory.namedNode(`${ns}${term}`)
globalFactory.namedNode(`${ns}${term}`);

let proxy: (DataFactory & IdentityFactory<any> & any)
let proxy: DataFactory & IdentityFactory<any> & any;
if (typeof Proxy !== "undefined") {
proxy = new Proxy<DataFactory>(globalFactory || ({} as DataFactory & any), {
ownKeys(): (string|number|symbol)[] {
return globalFactory && Object.keys(globalFactory) || []
return globalFactory && Object.keys(globalFactory) || [];
},

getOwnPropertyDescriptor(_, k: string | number | symbol): PropertyDescriptor | undefined {
return Object.getOwnPropertyDescriptor(globalFactory, k as string)
return Object.getOwnPropertyDescriptor(globalFactory, k as string);
},

set(_, property: keyof DataFactory & any, value): boolean {
globalFactory[property] = value
return true
globalFactory[property] = value;
return true;
},

get(_, property: keyof DataFactory & any) {
return globalFactory[property]
return globalFactory[property];
},
})
} else {
Expand All @@ -86,19 +87,19 @@ if (typeof Proxy !== "undefined") {
'quadrupleToNQ',
'quadToNQ',
].reduce((acc, key) => {
acc[key] = (...args: any[]) => globalFactory[key](...args)
acc[key] = (...args: any[]) => globalFactory[key](...args);
return acc;
}, {} as { [k: string]: Function })
}, {} as { [k: string]: Function });
}

export {
setup,
globalFactory,
globalSymbol,
PlainFactory,
}
};

export * from './types'
export * from './utilities'
export * from './types';
export * from './utilities';

export default proxy
export default proxy;
File renamed without changes.
24 changes: 12 additions & 12 deletions core/utilities.ts → core/src/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import { BlankNode, Literal, NamedNode, Node, Quad, SomeTerm, Term, TermType } from "./types";

export function isTerm(obj: any): obj is Term {
return typeof obj === "object" && obj !== null && "termType" in obj
return typeof obj === "object" && obj !== null && "termType" in obj;
}

export function isNamedNode(obj: any): obj is NamedNode {
return isTerm(obj) && obj.termType === TermType.NamedNode
return isTerm(obj) && obj.termType === TermType.NamedNode;
}

export function isBlankNode(obj: any): obj is BlankNode {
return isTerm(obj) && obj.termType === TermType.BlankNode
return isTerm(obj) && obj.termType === TermType.BlankNode;
}

export function isLiteral(obj: any): obj is Literal {
return isTerm(obj) && obj.termType === TermType.Literal
return isTerm(obj) && obj.termType === TermType.Literal;
}

const TermTypes = [
TermType.NamedNode.toString(),
TermType.BlankNode.toString(),
TermType.Literal.toString()
]
];
export function isSomeTerm(obj: any): obj is SomeTerm {
return isTerm(obj) && TermTypes.includes(obj.termType)
return isTerm(obj) && TermTypes.includes(obj.termType) === true
}

const NodeTypes = [TermType.NamedNode.toString(), TermType.BlankNode.toString()]
const NodeTypes = [TermType.NamedNode.toString(), TermType.BlankNode.toString()];

export function isNode(obj: any): obj is Node {
return isTerm(obj) && NodeTypes.includes(obj.termType)
return isTerm(obj) && NodeTypes.includes(obj.termType) === true;
}

export function isQuad (obj: any): obj is Quad {
return typeof obj === "object" && obj !== null && "subject" in obj
export function isQuad(obj: any): obj is Quad {
return typeof obj === "object" && obj !== null && "subject" in obj;
}

export function doc (node: NamedNode) {
if (node.value.indexOf('#') < 0) {
return node.value
return node.value;
} else {
return node.value.split('#')[0]
return node.value.split('#')[0];
}
}
16 changes: 16 additions & 0 deletions core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "es2019",
"module": "esnext",
"lib": [
"es2019"
],

"strict": true,

"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
}
Loading

0 comments on commit 13d8fb2

Please sign in to comment.