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 a15d001
Show file tree
Hide file tree
Showing 30 changed files with 1,160 additions and 140 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
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('extractDomainObjectMetadatasFromConfigCriteria', () => {
exclude: null,
});
// console.log(JSON.stringify(metadatas, null, 2));
expect(metadatas.length).toEqual(12);
expect(metadatas.length).toEqual(13);
});
it('should find all of the domain objects findable by all search paths in a directory, with no dupes', async () => {
const metadatas = await extractDomainObjectMetadatasFromConfigCriteria({
Expand All @@ -27,7 +27,7 @@ describe('extractDomainObjectMetadatasFromConfigCriteria', () => {
exclude: null,
});
// console.log(JSON.stringify(metadatas, null, 2));
expect(metadatas.length).toEqual(12);
expect(metadatas.length).toEqual(13);
});
it('should only find the domain objects imported from the files in the search paths', async () => {
const metadatas = await extractDomainObjectMetadatasFromConfigCriteria({
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('extractDomainObjectMetadatasFromConfigCriteria', () => {
exclude: ['TrainLocatedEvent'],
});
// console.log(JSON.stringify(metadatas, null, 2));
expect(metadatas.length).toEqual(11);
expect(metadatas.length).toEqual(12);
});
it('should only keep the one named in the `include` list, if provided', async () => {
const metadatas = await extractDomainObjectMetadatasFromConfigCriteria({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('getAllPathsMatchingGlobs', () => {
expect(files).toContain('src/domain/objects/Train.ts');
expect(files).toContain('src/domain/objects/TrainLocatedEvent.ts');
expect(files).toContain('src/domain/objects/Station.ts');
expect(files.length).toEqual(14);
expect(files.length).toEqual(15);
});
it('should return paths that match each glob', async () => {
const files = await getAllPathsMatchingGlobs({
Expand Down
2 changes: 1 addition & 1 deletion src/logic/config/getConfig/readConfig.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('readConfig', () => {
},
},
});
expect(config.for.objects.length).toEqual(11);
expect(config.for.objects.length).toEqual(12);
expect(config).toMatchSnapshot({ rootDir: expect.anything() }); // to log an example of the output; ignore the rootDir, to make it machine independent
});
});
Loading

0 comments on commit a15d001

Please sign in to comment.