Skip to content

Commit

Permalink
feat(refs): support direct declarations of Refs
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Dec 2, 2024
1 parent 4cdcb6f commit 9de3ca8
Show file tree
Hide file tree
Showing 36 changed files with 1,487 additions and 218 deletions.
164 changes: 96 additions & 68 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@
"postinstall": "[ -d .git ] && npx husky install || exit 0"
},
"dependencies": {
"@ehmpathy/error-fns": "1.3.1",
"@ehmpathy/error-fns": "1.3.7",
"@oclif/core": "3.26.6",
"@oclif/plugin-help": "6.0.22",
"chalk": "2.4.2",
"change-case": "4.1.1",
"domain-objects": "0.22.1",
"domain-objects-metadata": "0.7.4",
"domain-objects-metadata": "0.7.5",
"fast-glob": "3.2.2",
"joi": "17.4.0",
"lodash.omit": "4.5.0",
Expand Down
12 changes: 12 additions & 0 deletions src/domain/objects/SqlSchemaReferenceMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ import { DomainObjectReferenceMetadata } from 'domain-objects-metadata';
import Joi from 'joi';

export enum SqlSchemaReferenceMethod {
/**
* .what = when a domain literal is directly nested in another domain object
*/
DIRECT_BY_NESTING = 'DIRECT_BY_NESTING',

/**
* .what = when a domain object is explicitly referenced, via Ref<>, in another domain object
*/
DIRECT_BY_DECLARATION = 'DIRECT_BY_DECLARATION',

/**
* .what = when a domain object is implicitly referenced, via uuid, in another domain object
*/
IMPLICIT_BY_UUID = 'IMPLICIT_BY_UUID',
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface Carriage {
capacity: number; // for passenger carriages, number of passengers; for freight, the volume
}
export class Carriage extends DomainEntity<Carriage> implements Carriage {
public static primary = ['uuid'] as const; // there is nothing that naturally identifies a carriage -> it is unique only on the unique identifier tracked in our db
public static unique = ['uuid'] as const; // there is nothing that naturally identifies a carriage -> it is unique only on the unique identifier tracked in our db
public static primary = ['uuid'] as const;
public static unique = ['cin'] as const;
public static updatable = [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { DomainEntity, Ref } from 'domain-objects';
import { Carriage } from './Carriage';

/**
* .what = cargo which has been allocated to a carriage at a given point in time
*/
export interface CarriageCargo {
id?: number;
uuid?: string;

/**
* the itinerary during which it is allocated
*/
itineraryUuid: string; // todo: ref to an itinerary once we declare it

/**
* the carriage it has been allocated to
*/
carriageRef: Ref<typeof Carriage>;

/**
* the slot that it has been allocated to on the carriage
*/
slot: number;

/**
* the cargo that has been allocated
*/
cargoExid: null | string;
}
export class CarriageCargo extends DomainEntity<CarriageCargo> implements CarriageCargo {
public static primary = ['uuid'] as const;
public static unique = ['itineraryUuid', 'carriageRef', 'slot'] as const;
public static updatable = ['cargoExid'];
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './AsyncTaskPredictStationCongestion'
export * from './CarriageCargo';
export * from './Carriage';
export * from './Certificate';
export * from './Engineer';
Expand Down
3 changes: 1 addition & 2 deletions src/logic/commands/generate.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ describe('generate', () => {
describe('carriageDao', () => {
it('it should be able to upsert', async () => {
const carriage = new Carriage({
uuid: uuid(),
cin: 'carriage-to-test',
carries: CarriagePurpose.FREIGHT,
capacity: 821,
Expand Down Expand Up @@ -359,7 +358,7 @@ describe('generate', () => {
);
const foundCarriage = await carriageDao.findByUnique(
{
uuid: carriage.uuid,
cin: carriage.cin,
},
{ dbConnection },
);
Expand Down
Loading

0 comments on commit 9de3ca8

Please sign in to comment.