diff --git a/README.md b/README.md index f6a9b2a..d145fb1 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ A hook is an event the framework will emit to whenenver a data frame used to bui ## API filby provides a set of lifecycle methods and an API for retrieving change sets and projections, and for executing database queries (although you are free to use your preferred PostgreSQL client too). -#### filby.init(config: RdfConfig): Promise<void> +#### filby.init(config: Config): Promise<void> Connects to the database and runs migrations #### filby.startNotifications(): Promise<void> @@ -201,16 +201,16 @@ Stops polling the database for notifications, and waits for any inflight notific #### filby.stop(): Promise<void> Stops polling for notifications then disconnects from the database -#### filby.getProjections(): Promise<RdfProjection>[] +#### filby.getProjections(): Promise<Projection>[] Returns the list of projections. -#### filby.getProjection(name: string, version: number): Promise<RdfProjection> +#### filby.getProjection(name: string, version: number): Promise<Projection> Returns the specified projection. -#### filby.getChangeLog(projection): Promise<RdfChangeSet[]> +#### filby.getChangeLog(projection): Promise<ChangeSet[]> Returns the change log (an ordered list of change sets) for the given projection. -#### filby.getChangeSet(changeSetId): Promise<RdfChangeSet> +#### filby.getChangeSet(changeSetId): Promise<ChangeSet> Returns the specified change set #### filby.withTransaction(callback: (client: PoolClient) => Promise<T>): Promise { + filby.on('park_v1_change', (event: Event) => { console.log({ event }) }); - filby.on('change', (event: RdfEvent) => { + filby.on('change', (event: Event) => { console.log({ event }) }); await filby.startNotifications(); @@ -81,7 +81,7 @@ async function registerChangelog() { async function registerProjections() { const projections = await filby.getProjections(); - projections.forEach((projection: RdfProjection) => { + projections.forEach((projection: Projection) => { const route = require(path.resolve(`routes/${projection.name}-v${projection.version}`)); const prefix = `/api/projection/v${projection.version}/${projection.name}`; fastify.register(route, { prefix, filby }); diff --git a/examples/typescript/routes/park-v1.ts b/examples/typescript/routes/park-v1.ts index c7f92b6..f96212f 100644 --- a/examples/typescript/routes/park-v1.ts +++ b/examples/typescript/routes/park-v1.ts @@ -1,6 +1,6 @@ import { FastifyInstance, FastifyRequest } from 'fastify'; import createError from 'http-errors'; -import Filby, { RdfChangeSet } from '../../..'; +import Filby, { ChangeSet } from '../../..'; export default (fastify: FastifyInstance, { filby }: { filby: Filby }, done: (err?: Error) => void) => { @@ -77,7 +77,7 @@ export default (fastify: FastifyInstance, { filby }: { filby: Filby }, done: (er return changeSet; } - async function getParks(changeSet: RdfChangeSet) { + async function getParks(changeSet: ChangeSet) { return filby.withTransaction(async (tx) => { const { rows } = await tx.query('SELECT code, name, calendar_event, calendar_occurs FROM get_park_v1($1)', [changeSet.id]); const parkDictionary = rows.reduce(toParkDictionary, new Map()); @@ -85,7 +85,7 @@ export default (fastify: FastifyInstance, { filby }: { filby: Filby }, done: (er }); } - async function getPark(changeSet: RdfChangeSet, code: string) { + async function getPark(changeSet: ChangeSet, code: string) { return filby.withTransaction(async (tx) => { const { rows } = await tx.query('SELECT code, name, calendar_event, calendar_occurs FROM get_park_v1($1) WHERE code = upper($2)', [changeSet.id, code]); const parkDictionary = rows.reduce(toParkDictionary, new Map()); diff --git a/index.d.ts b/index.d.ts index b94ffab..6e6f016 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,19 +2,19 @@ import { EventEmitter2 as EventEmitter } from 'eventemitter2'; import { PoolClient, PoolConfig } from 'pg'; export default class Filby extends EventEmitter { - constructor(config: RdfConfig); + constructor(config: Config); init(): Promise; startNotifications(): Promise; stopNotifications(): Promise; stop(): Promise; withTransaction(callback: (client: PoolClient) => Promise); - getProjections(): Promise; - getProjection(name: string, version: number): Promise; - getChangeLog(projection: RdfProjection): Promise; - getChangeSet(id: number): Promise; + getProjections(): Promise; + getProjection(name: string, version: number): Promise; + getChangeLog(projection: Projection): Promise; + getChangeSet(id: number): Promise; }; -export type RdfConfig = { +export type Config = { migrations?: string; database?: PoolConfig; notification?: { @@ -24,13 +24,13 @@ export type RdfConfig = { } }; -export type RdfProjection = { +export type Projection = { id: number; name: string; version: number; }; -export type RdfChangeSet = { +export type ChangeSet = { id: number; effective: Date; description: string; @@ -38,11 +38,11 @@ export type RdfChangeSet = { entityTag: string; }; -export type RdfEvent = { +export type Event = { event: string; -} & RdfProjection; +} & Projection; -export type RdfEntity = { +export type Entity = { name: string; version: number; }; \ No newline at end of file diff --git a/index.js b/index.js index 240b445..6ebfcad 100644 --- a/index.js +++ b/index.js @@ -23,10 +23,10 @@ module.exports = class Filby extends EventEmitter { } async init() { - const rdfMigrationsDir = path.join(__dirname, 'migrations'); + const filbyMigrationsDir = path.join(__dirname, 'migrations'); const customMigrationsDir = this.#config.migrations || 'migrations'; - await this.#migrate(this.#config.database, rdfMigrationsDir); + await this.#migrate(this.#config.database, filbyMigrationsDir); await this.#migrate(this.#config.database, path.resolve(customMigrationsDir)); } diff --git a/test/TestFilby.js b/test/TestFilby.js index f920365..82326d3 100644 --- a/test/TestFilby.js +++ b/test/TestFilby.js @@ -19,11 +19,11 @@ module.exports = class TestFilby extends Filby { async wipe() { await this.withTransaction(async (tx) => { await this.#nukeCustomObjects(tx); - await this.#wipeRdfData(tx); + await this.#wipeData(tx); }); } - async #wipeRdfData(tx) { + async #wipeData(tx) { await tx.query('DELETE FROM fby_notification'); await tx.query('DELETE FROM fby_hook'); await tx.query('DELETE FROM fby_data_frame');