Skip to content

Commit

Permalink
chore: Standardize files
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeboer committed Jun 14, 2024
1 parent eb3a3ae commit da498d3
Show file tree
Hide file tree
Showing 25 changed files with 487 additions and 342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* JSON Schema for LDWorkbench.
* It helps with the writing of the configuration needed to run LDWorkbench pipelines.
*/
export interface LDWorkbenchConfiguration {
export interface configuration {
/**
* The name of your pipeline, it must be unique over all your configurations.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/cliArgs.ts → src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ program
)
.version(version());
program.parse();
export const cliArgs: {
export const cli: {
config: string;
pipeline?: string;
stage?: string;
silent?: boolean;
init?: boolean;
} = program.opts();

if (cliArgs.init !== undefined) {
if (Object.values(cliArgs).length !== 2) {
if (cli.init !== undefined) {
if (Object.values(cli).length !== 2) {
error(
'The --init flag can not be used in conjunction with other CLI arguments.'
);
Expand Down
158 changes: 158 additions & 0 deletions src/configuration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

/**
* JSON Schema for LDWorkbench.
* It helps with the writing of the configuration needed to run LDWorkbench pipelines.
*/
export interface Configuration {
/**
* The name of your pipeline. It must be unique over all your configurations.
*/
name: string;
/**
* An optional description for your pipeline.
*/
description?: string;
/**
* An optional base directory for files referenced by `file://...` paths. This defaults to the directory that contains the YAML configuration file.
*/
baseDir?: string;
/**
* The file where the final result of your pipeline is saved.
*/
destination?: string;
/**
* A pipeline stage consists of an iterator and one or more generators.
*
* @minItems 1
*/
stages: [
{
/**
* The name of the stage. It must be unique within the pipeline.
*/
name: string;
iterator: {
/**
* SPARQL SELECT query that returns a `$this` binding for each URI that will be passed to the generator(s). Either an inline string (`SELECT $this WHERE {...}`) or a reference to a file (`file://...`) that contains the query.
*/
query: string;
/**
* SPARQL endpoint for the iterator. If it starts with `file://`, a local RDF file is queried. If omitted the result of the previous stage is used.
*/
endpoint?: string;
/**
* Number of `$this` bindings retrieved per query. Defaults to the LIMIT value of your iterator query or 10 if no LIMIT is present.
*/
batchSize?: number;
/**
* Human-readable time delay for requests to the the iterator’s SPARQL endpoint (e.g. `5ms`, `100 milliseconds`, `1s`).
*/
delay?: string;
};
/**
* @minItems 1
*/
generator: [
{
/**
* SPARQL CONSTRUCT query that takes a `$this` binding from the iterator and generates triples for it. Either an inline string (`CONSTRUCT $this schema:name ?name WHERE {$this ...}`) or a reference to a file (`file://...`) that contains the query.
*/
query: string;
/**
* The SPARQL endpoint for the generator. If it starts with `file://`, a local RDF file is queried. If omitted, the endpoint of the iterator is used.
*/
endpoint?: string;
/**
* Overrule the generator's behaviour of fetching results for 10 bindings of `$this` per request.
*/
batchSize?: number;
},
...{
/**
* SPARQL CONSTRUCT query that takes a `$this` binding from the iterator and generates triples for it. Either an inline string (`CONSTRUCT $this schema:name ?name WHERE {$this ...}`) or a reference to a file (`file://...`) that contains the query.
*/
query: string;
/**
* The SPARQL endpoint for the generator. If it starts with `file://`, a local RDF file is queried. If omitted, the endpoint of the iterator is used.
*/
endpoint?: string;
/**
* Overrule the generator's behaviour of fetching results for 10 bindings of `$this` per request.
*/
batchSize?: number;
}[]
];
/**
* The optional path where the results are saved. If omitted, a temporary file will be created.
*/
destination?: string;
},
...{
/**
* The name of the stage. It must be unique within the pipeline.
*/
name: string;
iterator: {
/**
* SPARQL SELECT query that returns a `$this` binding for each URI that will be passed to the generator(s). Either an inline string (`SELECT $this WHERE {...}`) or a reference to a file (`file://...`) that contains the query.
*/
query: string;
/**
* SPARQL endpoint for the iterator. If it starts with `file://`, a local RDF file is queried. If omitted the result of the previous stage is used.
*/
endpoint?: string;
/**
* Number of `$this` bindings retrieved per query. Defaults to the LIMIT value of your iterator query or 10 if no LIMIT is present.
*/
batchSize?: number;
/**
* Human-readable time delay for requests to the the iterator’s SPARQL endpoint (e.g. `5ms`, `100 milliseconds`, `1s`).
*/
delay?: string;
};
/**
* @minItems 1
*/
generator: [
{
/**
* SPARQL CONSTRUCT query that takes a `$this` binding from the iterator and generates triples for it. Either an inline string (`CONSTRUCT $this schema:name ?name WHERE {$this ...}`) or a reference to a file (`file://...`) that contains the query.
*/
query: string;
/**
* The SPARQL endpoint for the generator. If it starts with `file://`, a local RDF file is queried. If omitted, the endpoint of the iterator is used.
*/
endpoint?: string;
/**
* Overrule the generator's behaviour of fetching results for 10 bindings of `$this` per request.
*/
batchSize?: number;
},
...{
/**
* SPARQL CONSTRUCT query that takes a `$this` binding from the iterator and generates triples for it. Either an inline string (`CONSTRUCT $this schema:name ?name WHERE {$this ...}`) or a reference to a file (`file://...`) that contains the query.
*/
query: string;
/**
* The SPARQL endpoint for the generator. If it starts with `file://`, a local RDF file is queried. If omitted, the endpoint of the iterator is used.
*/
endpoint?: string;
/**
* Overrule the generator's behaviour of fetching results for 10 bindings of `$this` per request.
*/
batchSize?: number;
}[]
];
/**
* The optional path where the results are saved. If omitted, a temporary file will be created.
*/
destination?: string;
}[]
];
}
4 changes: 2 additions & 2 deletions src/lib/File.class.ts → src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
mkdirSync,
createReadStream,
} from 'fs';
import {isFile, isFilePathString} from '../utils/guards.js';
import {isFile, isFilePathString} from './utils/guards.js';
import {dirname} from 'path';
import chalk from 'chalk';
import {type Ora} from 'ora';
import type Pipeline from './Pipeline.class.js';
import type Pipeline from './pipeline.js';
import {pipeline as streamPipeline} from 'stream/promises';

export default class File {
Expand Down
12 changes: 6 additions & 6 deletions src/lib/Generator.class.ts → src/generator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type {ConstructQuery} from 'sparqljs';
import type Stage from './Stage.class.js';
import getSPARQLQuery from '../utils/getSPARQLQuery.js';
import type Stage from './stage.js';
import getSPARQLQuery from './utils/getSPARQLQuery.js';
import type {Quad, NamedNode} from '@rdfjs/types';
import getSPARQLQueryString from '../utils/getSPARQLQueryString.js';
import getEndpoint from '../utils/getEndpoint.js';
import getSPARQLQueryString from './utils/getSPARQLQueryString.js';
import getEndpoint from './utils/getEndpoint.js';
import type {Endpoint, QueryEngine, QuerySource} from './types.js';
import getEngine from '../utils/getEngine.js';
import getEngineSource from '../utils/getEngineSource.js';
import getEngine from './utils/getEngine.js';
import getEngineSource from './utils/getEngineSource.js';
import EventEmitter from 'node:events';

const DEFAULT_BATCH_SIZE = 10;
Expand Down
12 changes: 6 additions & 6 deletions src/lib/Iterator.class.ts → src/iterator.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import EventEmitter from 'node:events';
import type {SelectQuery} from 'sparqljs';
import type Stage from './Stage.class.js';
import type Stage from './stage.js';
import type {NamedNode} from '@rdfjs/types';
import getSPARQLQuery from '../utils/getSPARQLQuery.js';
import getSPARQLQuery from './utils/getSPARQLQuery.js';
import {type Bindings} from '@comunica/types';
import getSPARQLQueryString from '../utils/getSPARQLQueryString.js';
import getEndpoint from '../utils/getEndpoint.js';
import getSPARQLQueryString from './utils/getSPARQLQueryString.js';
import getEndpoint from './utils/getEndpoint.js';
import type {Endpoint, QueryEngine, QuerySource} from './types.js';
import getEngine from '../utils/getEngine.js';
import getEngineSource from '../utils/getEngineSource.js';
import getEngine from './utils/getEngine.js';
import getEngineSource from './utils/getEngineSource.js';
import parse from 'parse-duration';

const DEFAULT_LIMIT = 10;
Expand Down
31 changes: 0 additions & 31 deletions src/lib/PreviousStage.class.ts

This file was deleted.

20 changes: 10 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import inquirer from 'inquirer';
import chalk from 'chalk';
import {error} from './utils/error.js';
import version from './utils/version.js';
import type {LDWorkbenchConfiguration} from './lib/LDWorkbenchConfiguration.js';
import type {Configuration} from './configuration.js';
import loadPipelines from './utils/loadPipelines.js';
import Pipeline from './lib/Pipeline.class.js';
import {cliArgs} from './cliArgs.js';
import Pipeline from './pipeline.js';
import {cli} from './cli.js';

console.info(
chalk.bold(`Welcome to LD Workbench version ${chalk.cyan(version())}`)
);

async function main(): Promise<void> {
const pipelines = loadPipelines(cliArgs.config ?? './pipelines/');
const pipelines = loadPipelines(cli.config ?? './pipelines/');
const names = [...pipelines.keys()];
let configuration: LDWorkbenchConfiguration | undefined;
let configuration: Configuration | undefined;

if (cliArgs.pipeline !== undefined) {
configuration = pipelines.get(cliArgs.pipeline);
if (cli.pipeline !== undefined) {
configuration = pipelines.get(cli.pipeline);
if (configuration === undefined) {
error(
`No pipeline named “${cliArgs.pipeline}” was found.`,
`No pipeline named “${cli.pipeline}” was found.`,
2,
`Valid pipeline names are: ${names.map(name => `"${name}"`).join(', ')}`
);
Expand Down Expand Up @@ -57,8 +57,8 @@ async function main(): Promise<void> {

try {
const pipeline = new Pipeline(configuration, {
startFromStageName: cliArgs.stage,
silent: cliArgs.silent,
startFromStageName: cli.stage,
silent: cli.silent,
});
await pipeline.run();
} catch (e) {
Expand Down
18 changes: 9 additions & 9 deletions src/lib/Pipeline.class.ts → src/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import ora, {Ora} from 'ora';
import kebabcase from 'lodash.kebabcase';
import type {LDWorkbenchConfiguration} from './LDWorkbenchConfiguration.js';
import type {Configuration} from './configuration.js';
import chalk from 'chalk';
import Stage from './Stage.class.js';
import formatDuration from '../utils/formatDuration.js';
import Stage from './stage.js';
import formatDuration from './utils/formatDuration.js';
import {millify} from 'millify';
import File from './File.class.js';
import File from './file.js';
import path from 'node:path';
import * as fs from 'node:fs';
import {isFilePathString, isTriplyDBPathString} from '../utils/guards.js';
import TriplyDB from './TriplyDB.class.js';
import {isFilePathString, isTriplyDBPathString} from './utils/guards.js';
import TriplyDB from './triply-db.js';
import prettyMilliseconds from 'pretty-ms';
import {memoryConsumption} from '../utils/memory.js';
import {memoryConsumption} from './utils/memory.js';
interface PipelineOptions {
startFromStageName?: string;
silent?: boolean;
Expand All @@ -28,7 +28,7 @@ class Pipeline {
private readonly opts?: PipelineOptions;

public constructor(
private readonly $configuration: LDWorkbenchConfiguration,
private readonly $configuration: Configuration,
pipelineOptions?: PipelineOptions
) {
// create data folder:
Expand Down Expand Up @@ -111,7 +111,7 @@ class Pipeline {
}
}

public get configuration(): LDWorkbenchConfiguration {
public get configuration(): Configuration {
return this.$configuration;
}

Expand Down
Loading

0 comments on commit da498d3

Please sign in to comment.