Skip to content

Commit

Permalink
feat(alias): support dobj alias for reference variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Jun 10, 2024
1 parent efd46e8 commit faffacc
Show file tree
Hide file tree
Showing 18 changed files with 369 additions and 34 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"chalk": "2.4.2",
"change-case": "4.1.1",
"domain-objects": "0.20.0",
"domain-objects-metadata": "0.7.1",
"domain-objects-metadata": "0.7.3",
"fast-glob": "3.2.2",
"joi": "17.4.0",
"lodash.omit": "4.5.0",
Expand Down
21 changes: 18 additions & 3 deletions src/logic/__test_assets__/createExampleDomainObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,37 @@ export const createExampleDomainObjectMetadata = ({
name: 'ExampleDomainLiteral',
extends: DomainObjectVariant.DOMAIN_LITERAL,
properties: {},
decorations: { unique: null, updatable: null },
decorations: {
alias: null,
primary: null,
unique: null,
updatable: null,
},
});

if (extend === DomainObjectVariant.DOMAIN_ENTITY)
return new DomainObjectMetadata({
name: 'ExampleDomainEntity',
extends: DomainObjectVariant.DOMAIN_LITERAL,
properties: {},
decorations: { unique: ['uuid'], updatable: [] },
decorations: {
alias: null,
primary: null,
unique: ['uuid'],
updatable: [],
},
});
if (extend === DomainObjectVariant.DOMAIN_EVENT)
return new DomainObjectMetadata({
name: 'ExampleDomainEvent',
extends: extend,
properties: {},
decorations: { unique: ['uuid'], updatable: null },
decorations: {
alias: null,
primary: null,
unique: ['uuid'],
updatable: null,
},
});
throw new Error(
'unsupported domain object variant to create example object for',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
"objects": [
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": [
"stationUuid",
"trainLocatedEventUuid",
Expand Down Expand Up @@ -73,6 +75,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": [
"uuid",
],
Expand Down Expand Up @@ -119,6 +123,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": null,
"updatable": null,
},
Expand Down Expand Up @@ -152,6 +158,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": null,
"updatable": null,
},
Expand Down Expand Up @@ -180,6 +188,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": [
"externalId",
],
Expand Down Expand Up @@ -253,6 +263,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": null,
"updatable": null,
},
Expand Down Expand Up @@ -291,6 +303,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": [
"ein",
],
Expand Down Expand Up @@ -366,6 +380,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": null,
"updatable": null,
},
Expand Down Expand Up @@ -397,6 +413,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": [
"combinationId",
],
Expand Down Expand Up @@ -489,6 +507,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": [
"socialSecurityNumberHash",
],
Expand Down Expand Up @@ -555,6 +575,8 @@ exports[`readConfig should be able to read the example config provisioned in __t
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": null,
"unique": [
"geocode",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,43 @@ export const upsert = async (
};"
`;
exports[`defineDaoUpsertMethodCodeForDomainObject should look correct for a simple domain entity with a custom alias 1`] = `
"import { HasMetadata } from 'type-fns';
import { DatabaseConnection } from '$PATH_TO_DATABASE_CONNECTION';
import { AsyncTaskGrantWish } from '$PATH_TO_DOMAIN_OBJECT';
import { log } from '$PATH_TO_LOG_OBJECT';
import { sqlQueryUpsertAsyncTaskGrantWish } from '$PATH_TO_GENERATED_SQL_QUERY_FUNCTIONS';
export const sql = \`
-- query_name = upsert_async_task_grant_wish
SELECT
dgv.id, dgv.uuid
FROM upsert_async_task_grant_wish(
:exid
) as dgv;
\`;
export const upsert = async (
{
task,
}: {
task: AsyncTaskGrantWish;
},
context: { dbConnection: DatabaseConnection },
): Promise<HasMetadata<AsyncTaskGrantWish>> => {
const results = await sqlQueryUpsertAsyncTaskGrantWish({
dbExecute: context.dbConnection.query,
logDebug: log.debug,
input: {
exid: task.exid,
},
});
const { id, uuid } = results[0]!; // grab the db generated values
return new AsyncTaskGrantWish({ ...task, id, uuid }) as HasMetadata<AsyncTaskGrantWish>;
};"
`;
exports[`defineDaoUpsertMethodCodeForDomainObject should look correct for domain entity with references, array and solo, implicit and direct 1`] = `
"import { HasMetadata } from 'type-fns';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ describe('defineDaoCodeFilesForDomainObject', () => {
longitude: { name: 'longitude', type: DomainObjectPropertyType.NUMBER },
},
decorations: {
alias: null,
primary: null,
unique: null,
updatable: null,
},
Expand Down Expand Up @@ -47,6 +49,8 @@ describe('defineDaoCodeFilesForDomainObject', () => {
longitude: { name: 'longitude', type: DomainObjectPropertyType.NUMBER },
},
decorations: {
alias: null,
primary: null,
unique: null,
updatable: null,
},
Expand Down
Loading

0 comments on commit faffacc

Please sign in to comment.