Skip to content

Commit

Permalink
Fixed some references to old project name (RDF)
Browse files Browse the repository at this point in the history
  • Loading branch information
cressie176 committed Jan 8, 2024
1 parent 8e0d8b6 commit 627c7d8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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&lt;T&gt;): Promise<T&gt;
Expand Down
8 changes: 4 additions & 4 deletions examples/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import swagger from '@fastify/swagger';
import swaggerUI from '@fastify/swagger-ui';

import changeLogRoute from './routes/changelog-v1';
import Filby, { RdfProjection, RdfEvent } from '../..';
import Filby, { Projection, Event } from '../..';

const fastify = Fastify(config.fastify);

Expand Down Expand Up @@ -57,10 +57,10 @@ const app: AppProcess = process;

await fastify.listen(config.server);

filby.on('park_v1_change', (event: RdfEvent) => {
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();
Expand All @@ -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 });
Expand Down
6 changes: 3 additions & 3 deletions examples/typescript/routes/park-v1.ts
Original file line number Diff line number Diff line change
@@ -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) => {

Expand Down Expand Up @@ -77,15 +77,15 @@ 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());
return Array.from(parkDictionary.values());
});
}

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());
Expand Down
22 changes: 11 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
startNotifications(): Promise<void>;
stopNotifications(): Promise<void>;
stop(): Promise<void>;
withTransaction(callback: (client: PoolClient) => Promise<any>);
getProjections(): Promise<RdfProjection[]>;
getProjection(name: string, version: number): Promise<RdfProjection>;
getChangeLog(projection: RdfProjection): Promise<RdfChangeSet[]>;
getChangeSet(id: number): Promise<RdfChangeSet>;
getProjections(): Promise<Projection[]>;
getProjection(name: string, version: number): Promise<Projection>;
getChangeLog(projection: Projection): Promise<ChangeSet[]>;
getChangeSet(id: number): Promise<ChangeSet>;
};

export type RdfConfig = {
export type Config = {
migrations?: string;
database?: PoolConfig;
notification?: {
Expand All @@ -24,25 +24,25 @@ 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;
lastModified: Date;
entityTag: string;
};

export type RdfEvent = {
export type Event = {
event: string;
} & RdfProjection;
} & Projection;

export type RdfEntity = {
export type Entity = {
name: string;
version: number;
};
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
4 changes: 2 additions & 2 deletions test/TestFilby.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 627c7d8

Please sign in to comment.