mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #55595 feat: minimal types for barnard59 by @tpluscode
This commit is contained in:
committed by
GitHub
parent
dcf88f4f93
commit
40aaff087f
77
types/barnard59-core/barnard59-core-tests.ts
Normal file
77
types/barnard59-core/barnard59-core-tests.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { createPipeline, defaultLogger, run } from 'barnard59-core';
|
||||
import Pipeline, { VariableMap } from "barnard59-core/lib/Pipeline";
|
||||
import { GraphPointer } from 'clownface';
|
||||
import { Logger } from 'winston';
|
||||
import LoaderRegistry = require('rdf-loaders-registry');
|
||||
|
||||
function testCreatePipeline() {
|
||||
const ptr: GraphPointer = <any> {};
|
||||
const loaderRegistry: LoaderRegistry = <any> {};
|
||||
const logger: Logger = <any> {};
|
||||
|
||||
let pipeline: Pipeline;
|
||||
|
||||
pipeline = createPipeline(ptr);
|
||||
pipeline = createPipeline(ptr, { basePath: '' });
|
||||
pipeline = createPipeline(ptr, {
|
||||
basePath: '',
|
||||
loaderRegistry,
|
||||
context: {},
|
||||
logger,
|
||||
variables: new Map()
|
||||
});
|
||||
}
|
||||
|
||||
function testDefaultLogger() {
|
||||
let logger: Logger;
|
||||
|
||||
logger = defaultLogger();
|
||||
logger = defaultLogger({});
|
||||
|
||||
const level: 'error' | 'info' | 'debug' = 'error';
|
||||
logger = defaultLogger({
|
||||
level
|
||||
});
|
||||
|
||||
logger = defaultLogger({
|
||||
console: true
|
||||
});
|
||||
|
||||
logger = defaultLogger({
|
||||
errorFilename: './err.log'
|
||||
});
|
||||
|
||||
logger = defaultLogger({
|
||||
filename: 'pipeline.log'
|
||||
});
|
||||
}
|
||||
|
||||
async function testRun() {
|
||||
const pipeline: Pipeline = <any> {};
|
||||
|
||||
await run(pipeline);
|
||||
await run(pipeline, {
|
||||
end: true
|
||||
});
|
||||
await run(pipeline, {
|
||||
resume: true
|
||||
});
|
||||
}
|
||||
|
||||
declare module 'barnard59-core' {
|
||||
interface Variables {
|
||||
foo: string;
|
||||
bar: number;
|
||||
}
|
||||
}
|
||||
|
||||
function testAugmentedVariables(variables: VariableMap) {
|
||||
variables.set('foo', 'bar');
|
||||
// $ExpectError
|
||||
variables.set('foo', {});
|
||||
|
||||
const foo: string = variables.get('foo');
|
||||
const bar: number = variables.get('bar');
|
||||
// $ExpectError
|
||||
const notBar: string = variables.get('bar');
|
||||
}
|
||||
26
types/barnard59-core/index.d.ts
vendored
Normal file
26
types/barnard59-core/index.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Type definitions for barnard59-core 1.0
|
||||
// Project: https://github.com/zazuko/barnard59-core
|
||||
// Definitions by: tpluscode <https://github.com/tpluscode>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { Logger } from 'winston';
|
||||
import LoaderRegistry = require('rdf-loaders-registry');
|
||||
export { default as createPipeline } from './lib/factory/pipeline';
|
||||
export { default as run } from './lib/run';
|
||||
export { Variables } from './lib/Pipeline';
|
||||
|
||||
interface DefaultLogger {
|
||||
console?: boolean;
|
||||
errorFilename?: string | null;
|
||||
filename?: string | null;
|
||||
level?: 'error' | 'info' | 'debug';
|
||||
}
|
||||
|
||||
declare function defaultLogger(arg?: DefaultLogger): Logger;
|
||||
|
||||
declare const defaultLoaderRegistry: LoaderRegistry;
|
||||
|
||||
export {
|
||||
defaultLoaderRegistry,
|
||||
defaultLogger,
|
||||
};
|
||||
27
types/barnard59-core/lib/Pipeline.d.ts
vendored
Normal file
27
types/barnard59-core/lib/Pipeline.d.ts
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Stream } from "stream";
|
||||
import { Logger } from 'winston';
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
export interface Variables {}
|
||||
|
||||
type Keys = keyof Variables extends never ? string : keyof Variables;
|
||||
|
||||
interface TypedMap extends Map<Keys, any> {
|
||||
// tslint:disable-next-line:no-unnecessary-generics
|
||||
get<K extends keyof Variables>(key: K): Variables[typeof key];
|
||||
// tslint:disable-next-line:no-unnecessary-generics
|
||||
set<K extends keyof Variables>(key: K, value: Variables[typeof key] | undefined): this;
|
||||
}
|
||||
|
||||
export type VariableMap = keyof Variables extends never ? Map<string, any> : TypedMap;
|
||||
|
||||
export interface Context {
|
||||
logger: Logger;
|
||||
variables: VariableMap;
|
||||
}
|
||||
|
||||
export default class Pipeline extends Stream {
|
||||
context: Context;
|
||||
}
|
||||
|
||||
export {};
|
||||
15
types/barnard59-core/lib/factory/pipeline.d.ts
vendored
Normal file
15
types/barnard59-core/lib/factory/pipeline.d.ts
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Logger } from 'winston';
|
||||
import { GraphPointer } from 'clownface';
|
||||
import LoaderRegistry = require('rdf-loaders-registry');
|
||||
import Pipeline, { VariableMap } from "../Pipeline";
|
||||
|
||||
interface CreatePipeline {
|
||||
basePath: string;
|
||||
context?: unknown;
|
||||
loaderRegistry?: LoaderRegistry;
|
||||
logger?: Logger;
|
||||
variables?: VariableMap;
|
||||
}
|
||||
|
||||
export default function createPipeline(ptr: GraphPointer, arg?: CreatePipeline): Pipeline;
|
||||
export {};
|
||||
9
types/barnard59-core/lib/run.d.ts
vendored
Normal file
9
types/barnard59-core/lib/run.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import Pipeline from './Pipeline';
|
||||
|
||||
interface Run {
|
||||
end?: boolean;
|
||||
resume?: boolean;
|
||||
}
|
||||
|
||||
export default function run(pipeline: Pipeline, opts?: Run): Promise<any>;
|
||||
export {};
|
||||
7
types/barnard59-core/package.json
Normal file
7
types/barnard59-core/package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"rdf-js": "^4.0.2",
|
||||
"winston": "^3.3.3"
|
||||
}
|
||||
}
|
||||
23
types/barnard59-core/tsconfig.json
Normal file
23
types/barnard59-core/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"barnard59-core-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/barnard59-core/tslint.json
Normal file
1
types/barnard59-core/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
36
types/barnard59/barnard59-tests.ts
Normal file
36
types/barnard59/barnard59-tests.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { DatasetCore, NamedNode } from '@rdfjs/types';
|
||||
import { findPipeline, runner } from 'barnard59';
|
||||
import Pipeline from 'barnard59-core/lib/Pipeline';
|
||||
import { GraphPointer } from 'clownface';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
function testCreate() {
|
||||
const dataset: DatasetCore = <any> {};
|
||||
const iri: NamedNode = <any> {};
|
||||
let pipleine: GraphPointer;
|
||||
|
||||
pipleine = findPipeline(dataset);
|
||||
pipleine = findPipeline(dataset, 'http://foo.bar/pipeline');
|
||||
pipleine = findPipeline(dataset, iri);
|
||||
}
|
||||
|
||||
async function testRunner() {
|
||||
let finished: Promise<void>;
|
||||
let pipeline: Pipeline;
|
||||
const logger: Logger = <any> {};
|
||||
const pointer: GraphPointer = <any> {};
|
||||
|
||||
({ finished, pipeline } = await runner(pointer));
|
||||
({ finished, pipeline } = await runner(pointer, {
|
||||
basePath: '',
|
||||
logger,
|
||||
outputStream: process.stdout,
|
||||
}));
|
||||
({ finished, pipeline } = await runner(pointer, {
|
||||
basePath: '',
|
||||
logger,
|
||||
outputStream: process.stdout,
|
||||
level: 'debug',
|
||||
variables: new Map()
|
||||
}));
|
||||
}
|
||||
4
types/barnard59/findPipeline.d.ts
vendored
Normal file
4
types/barnard59/findPipeline.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { GraphPointer } from 'clownface';
|
||||
import { DatasetCore, NamedNode } from '@rdfjs/types';
|
||||
|
||||
export default function findPipeline(dataset: DatasetCore, iri?: NamedNode | string): GraphPointer;
|
||||
7
types/barnard59/index.d.ts
vendored
Normal file
7
types/barnard59/index.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// Type definitions for barnard59 1.0
|
||||
// Project: https://github.com/zazuko/barnard59
|
||||
// Definitions by: tpluscode <https://github.com/tpluscode>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export { default as runner } from './runner';
|
||||
export { default as findPipeline } from './findPipeline';
|
||||
7
types/barnard59/package.json
Normal file
7
types/barnard59/package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"rdf-js": "^4.0.2",
|
||||
"winston": "^3.3.3"
|
||||
}
|
||||
}
|
||||
20
types/barnard59/runner.d.ts
vendored
Normal file
20
types/barnard59/runner.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { GraphPointer } from "clownface";
|
||||
import { Writable } from "stream";
|
||||
import { Logger } from 'winston';
|
||||
import Pipeline, { VariableMap } from 'barnard59-core/lib/Pipeline';
|
||||
|
||||
interface Runner {
|
||||
finished: Promise<any>;
|
||||
pipeline: Pipeline;
|
||||
}
|
||||
|
||||
interface Create {
|
||||
basePath: string;
|
||||
outputStream: Writable;
|
||||
variables?: VariableMap;
|
||||
logger?: Logger;
|
||||
level?: 'error' | 'info' | 'debug';
|
||||
}
|
||||
|
||||
export default function create(ptr: GraphPointer, args?: Create): Promise<Runner>;
|
||||
export {};
|
||||
23
types/barnard59/tsconfig.json
Normal file
23
types/barnard59/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"barnard59-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/barnard59/tslint.json
Normal file
1
types/barnard59/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user