Skip to content

Commit 538bdf9

Browse files
committed
refactor: add initial AppModel + Copyable interfaces
1 parent 9ece839 commit 538bdf9

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface Copyable<T, CopyData> {
2+
/**
3+
* Create a copy of this model class, optionally with the specified `data` properties
4+
* merged into the resulting model class.
5+
* @param data Desired data to be merged into the copied model class.
6+
*/
7+
copy(data?: CopyData): T;
8+
}

src/app/data/models/dao/model.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Copyable } from './copyable';
2+
3+
/**
4+
* Generic AppModel type to be used for Firestore collection/document references.
5+
* @template M The `AppModel` type to be used for {@link Copyable}.
6+
* @template Data Data to be returned by {@link AppModel.asRecord}.
7+
* @template DataJson Data to be returned by {@link AppModel.toJSON}.
8+
*/
9+
export interface AppModel<M extends AppModel<M, Data, DataJson>, Data, DataJson>
10+
extends Copyable<M, Partial<Data>> {
11+
/** Converts this model class to its JSON equivalent, suitable for use in stringified data. */
12+
toJSON(): DataJson;
13+
14+
/** Converts this model class to its JS object equivalent. */
15+
asRecord(): Data;
16+
}

0 commit comments

Comments
 (0)