Skip to content

Commit

Permalink
feat(terms): domain-value-object to domain-literal, for intuition++
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed May 26, 2024
1 parent 752217d commit 1e8ec9e
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 28 deletions.
35 changes: 30 additions & 5 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 @@ -54,7 +54,7 @@
},
"dependencies": {
"@ehmpathy/error-fns": "1.0.2",
"domain-objects": "^0.13.2",
"domain-objects": "^0.20.0",
"joi": "17.4.0",
"lodash.omit": "^4.5.0",
"type-fns": "^0.9.1",
Expand Down
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ npm install --save domain-objects-metadata

# Usage Examples

### metadata of a value object
### metadata of a literal

say you've defined an `Address` as one of the objects in your domain

```ts
// src/domain/objects/Address.ts

import { DomainValueObject } from 'domain-objects';
import { DomainLiteral } from 'domain-objects';

interface Address {
street: string;
Expand All @@ -33,7 +33,7 @@ interface Address {
state: string;
postal: string;
}
class Address extends DomainValueObject<Address> implements Address {}
class Address extends DomainLiteral<Address> implements Address {}
```

you can introspect the file that its defined in to get its metadata
Expand All @@ -49,7 +49,7 @@ which looks like
```ts
{
name: 'Address',
extends: 'DomainValueObject',
extends: 'DomainLiteral',
properties: {
street: { name: 'street', type: 'string', required: true },
suite: { name: 'suite', type: 'string', nullable: true, required: true },
Expand Down Expand Up @@ -187,7 +187,7 @@ which looks like
destination: {
name: 'destination',
type: 'reference',
of: { name: 'Address', extends: 'DomainValueObject' },
of: { name: 'Address', extends: 'DomainLiteral' },
required: true,
},
contactInfo: {
Expand Down
2 changes: 1 addition & 1 deletion src/domain/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createIsOfEnum } from 'type-fns';

export enum DomainObjectVariant {
DOMAIN_OBJECT = 'DomainObject',
DOMAIN_VALUE_OBJECT = 'DomainValueObject',
DOMAIN_LITERAL = 'DomainLiteral',
DOMAIN_ENTITY = 'DomainEntity',
DOMAIN_EVENT = 'DomainEvent',
}
Expand Down
10 changes: 5 additions & 5 deletions src/logic/__snapshots__/introspect.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`introspect should be possible to introspect all of those files at the s
"unique": null,
"updatable": null,
},
"extends": "DomainValueObject",
"extends": "DomainLiteral",
"name": "Address",
"properties": {
"city": DomainObjectPropertyMetadata {
Expand Down Expand Up @@ -160,7 +160,7 @@ exports[`introspect should be possible to introspect all of those files at the s
"name": "destination",
"nullable": false,
"of": DomainObjectReferenceMetadata {
"extends": "DomainValueObject",
"extends": "DomainLiteral",
"name": "Address",
},
"required": true,
Expand Down Expand Up @@ -228,7 +228,7 @@ exports[`introspect should be possible to introspect the Address file 1`] = `
"unique": null,
"updatable": null,
},
"extends": "DomainValueObject",
"extends": "DomainLiteral",
"name": "Address",
"properties": {
"city": DomainObjectPropertyMetadata {
Expand Down Expand Up @@ -273,7 +273,7 @@ exports[`introspect should be possible to introspect the Delivery file 1`] = `
"unique": null,
"updatable": null,
},
"extends": "DomainValueObject",
"extends": "DomainLiteral",
"name": "Address",
"properties": {
"city": DomainObjectPropertyMetadata {
Expand Down Expand Up @@ -426,7 +426,7 @@ exports[`introspect should be possible to introspect the Delivery file 1`] = `
"name": "destination",
"nullable": false,
"of": DomainObjectReferenceMetadata {
"extends": "DomainValueObject",
"extends": "DomainLiteral",
"name": "Address",
},
"required": true,
Expand Down
4 changes: 2 additions & 2 deletions src/logic/__test_assets__/Address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DomainValueObject } from 'domain-objects';
import { DomainLiteral } from 'domain-objects';

export interface Address {
street: string;
Expand All @@ -7,4 +7,4 @@ export interface Address {
state: string;
postal: string;
}
export class Address extends DomainValueObject<Address> implements Address {}
export class Address extends DomainLiteral<Address> implements Address {}
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ DomainObjectMetadata {
}
`;

exports[`extractDomainObjectMetadataForDeclarationInFile should be able to extract domain object metadata for simple value object 1`] = `
exports[`extractDomainObjectMetadataForDeclarationInFile should be able to extract domain object metadata for simple literal 1`] = `
DomainObjectMetadata {
"decorations": {
"unique": null,
"updatable": null,
},
"extends": "DomainValueObject",
"extends": "DomainLiteral",
"name": "Address",
"properties": {
"city": DomainObjectPropertyMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ts, { isClassDeclaration } from 'typescript';
import { extractDomainObjectMetadataForDeclarationInFile } from './extractDomainObjectMetadataForDeclarationInFile';

describe('extractDomainObjectMetadataForDeclarationInFile', () => {
it('should be able to extract domain object metadata for simple value object', () => {
it('should be able to extract domain object metadata for simple literal', () => {
const program = ts.createProgram(
[`${__dirname}/../__test_assets__/Address.ts`],
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('extractRelevantStaticPropertiesFromClassDeclaration', () => {
updatable: ['status', 'amount', 'currency'],
});
});
it('should be able to get the unique and updatable properties of a DomainValueObject', () => {
it('should be able to get the unique and updatable properties of a DomainLiteral', () => {
const program = ts.createProgram(
[`${__dirname}/../__test_assets__/Address.ts`],
{},
Expand Down
4 changes: 2 additions & 2 deletions src/logic/guard/isDomainObjectReferenceProperty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('isDomainObjectReferenceProperty', () => {
name: 'geocode',
type: DomainObjectPropertyType.REFERENCE,
of: new DomainObjectReferenceMetadata({
extends: DomainObjectVariant.DOMAIN_VALUE_OBJECT,
extends: DomainObjectVariant.DOMAIN_LITERAL,
name: 'Geocode',
}),
});
Expand All @@ -37,7 +37,7 @@ describe('isDomainObjectReferenceProperty', () => {
of: {
type: DomainObjectPropertyType.REFERENCE,
of: new DomainObjectReferenceMetadata({
extends: DomainObjectVariant.DOMAIN_VALUE_OBJECT,
extends: DomainObjectVariant.DOMAIN_LITERAL,
name: 'Geocode',
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`getHydratedDomainObjectMetadatasFromFiles should return metadata from f
"unique": null,
"updatable": null,
},
"extends": "DomainValueObject",
"extends": "DomainLiteral",
"name": "Address",
"properties": {
"city": DomainObjectPropertyMetadata {
Expand Down Expand Up @@ -99,7 +99,7 @@ exports[`getHydratedDomainObjectMetadatasFromFiles should return metadata from f
"name": "destination",
"nullable": false,
"of": DomainObjectReferenceMetadata {
"extends": "DomainValueObject",
"extends": "DomainLiteral",
"name": "Address",
},
"required": true,
Expand Down Expand Up @@ -150,7 +150,7 @@ exports[`getHydratedDomainObjectMetadatasFromFiles should return metadata from f
"unique": null,
"updatable": null,
},
"extends": "DomainValueObject",
"extends": "DomainLiteral",
"name": "Address",
"properties": {
"city": DomainObjectPropertyMetadata {
Expand Down

0 comments on commit 1e8ec9e

Please sign in to comment.