Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/instantiation/Ref.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { omitReadonly } from '../manipulation/omitReadonly';
import { isRefByPrimary } from '../reference/isRefByPrimary';
import { isRefByUnique } from '../reference/isRefByUnique';
import { DomainEntity } from './DomainEntity';
Expand Down Expand Up @@ -268,5 +269,19 @@ describe('Ref', () => {
expect(ref.turtle).not.toHaveProperty('uuid');
});
});

it('should not omit anything when omitReadonly is called, since refs have no metadata', () => {
const ref = new Ref<typeof SeaTurtle>({
seawaterSecurityNumber: '821',
});

const refWithoutReadonly = omitReadonly(ref);

// all properties should be preserved since Ref has metadata = []
if (!isRefByUnique({ of: SeaTurtle })(refWithoutReadonly))
throw new Error('expected ref to be by unique');
expect(refWithoutReadonly.seawaterSecurityNumber).toBe('821');
expect(refWithoutReadonly).toBeInstanceOf(Ref);
});
});
});
2 changes: 2 additions & 0 deletions src/instantiation/Ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export type Ref<

// extend the domain literal into a custom class, so that we can rename it into Ref, without mutating the global DomainLiteral class
class RefBase<T extends DomainObjectShape> extends DomainLiteral<T> {
public static metadata = [] as const;

constructor(props: T) {
// if props itself is a domain entity or domain event, extract its reference (using unique keys as the default)
if (isOfDomainEntity(props) || isOfDomainEvent(props)) {
Expand Down
15 changes: 15 additions & 0 deletions src/instantiation/RefByPrimary.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { HasMetadata, OmitMetadata } from 'type-fns';

import { omitReadonly } from '../manipulation/omitReadonly';
import { DomainEntity } from './DomainEntity';
import { DomainLiteral } from './DomainLiteral';
import { RefByPrimary } from './RefByPrimary';
Expand Down Expand Up @@ -273,5 +274,19 @@ describe('DomainRefByPrimary', () => {
expect(home.turtle).not.toHaveProperty('seawaterSecurityNumber');
});
});

it('should not omit anything when omitReadonly is called, since refs have no metadata', () => {
const ref = new RefByPrimary<typeof SeaTurtle>({
uuid: '123e4567-e89b-12d3-a456-426614174000',
});

const refWithoutReadonly = omitReadonly(ref);

// all properties should be preserved since RefByPrimary has metadata = []
expect(refWithoutReadonly.uuid).toBe(
'123e4567-e89b-12d3-a456-426614174000',
);
expect(refWithoutReadonly).toBeInstanceOf(RefByPrimary);
});
});
});
2 changes: 2 additions & 0 deletions src/instantiation/RefByPrimary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export type RefByPrimary<

// extend the domain literal into a custom class, so that we can rename it into RefByUnique, without mutating the global DomainLiteral class
class RefByPrimaryBase<T extends DomainObjectShape> extends DomainLiteral<T> {
public static metadata = [] as const;

constructor(props: T) {
// if props itself is a domain entity or domain event, extract its reference
if (
Expand Down
13 changes: 13 additions & 0 deletions src/instantiation/RefByUnique.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { omitReadonly } from '../manipulation/omitReadonly';
import { DomainEntity } from './DomainEntity';
import { DomainLiteral } from './DomainLiteral';
import { Ref } from './Ref';
Expand Down Expand Up @@ -229,5 +230,17 @@ describe('DomainRefByUnique', () => {
);
});
});

it('should not omit anything when omitReadonly is called, since refs have no metadata', () => {
const ref = new RefByUnique<typeof SeaTurtle>({
seawaterSecurityNumber: '821',
});

const refWithoutReadonly = omitReadonly(ref);

// all properties should be preserved since RefByUnique has metadata = []
expect(refWithoutReadonly.seawaterSecurityNumber).toBe('821');
expect(refWithoutReadonly).toBeInstanceOf(RefByUnique);
});
});
});
2 changes: 2 additions & 0 deletions src/instantiation/RefByUnique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export type RefByUnique<

// extend the domain literal into a custom class, so that we can rename it into RefByUnique, without mutating the global DomainLiteral class
class RefByUniqueBase<T extends DomainObjectShape> extends DomainLiteral<T> {
public static metadata = [] as const;

constructor(props: T) {
// if props itself is a domain entity or domain event, extract its reference
if (isOfDomainEntity(props) || isOfDomainEvent(props)) {
Expand Down