@@ -8,14 +8,17 @@ import type { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
8
8
import type { UmbDetailStore } from '@umbraco-cms/backoffice/store' ;
9
9
import type { UmbApi } from '@umbraco-cms/backoffice/extension-api' ;
10
10
11
- export abstract class UmbDetailRepositoryBase < DetailModelType extends { unique : string ; entityType : string } >
11
+ export abstract class UmbDetailRepositoryBase <
12
+ DetailModelType extends { unique : string ; entityType : string } ,
13
+ UmbDetailDataSourceType extends UmbDetailDataSource < DetailModelType > = UmbDetailDataSource < DetailModelType > ,
14
+ >
12
15
extends UmbRepositoryBase
13
16
implements UmbDetailRepository < DetailModelType > , UmbApi
14
17
{
15
18
#init: Promise < unknown > ;
16
19
17
20
#detailStore?: UmbDetailStore < DetailModelType > ;
18
- #detailSource: UmbDetailDataSource < DetailModelType > ;
21
+ protected detailDataSource : UmbDetailDataSourceType ;
19
22
#notificationContext?: UmbNotificationContext ;
20
23
21
24
constructor (
@@ -25,7 +28,7 @@ export abstract class UmbDetailRepositoryBase<DetailModelType extends { unique:
25
28
) {
26
29
super ( host ) ;
27
30
28
- this . #detailSource = new detailSource ( host ) ;
31
+ this . detailDataSource = new detailSource ( host ) as UmbDetailDataSourceType ;
29
32
30
33
this . #init = Promise . all ( [
31
34
this . consumeContext ( detailStoreContextAlias , ( instance ) => {
@@ -45,7 +48,7 @@ export abstract class UmbDetailRepositoryBase<DetailModelType extends { unique:
45
48
* @memberof UmbDetailRepositoryBase
46
49
*/
47
50
async createScaffold ( preset ?: Partial < DetailModelType > ) {
48
- return this . #detailSource . createScaffold ( preset ) ;
51
+ return this . detailDataSource . createScaffold ( preset ) ;
49
52
}
50
53
51
54
/**
@@ -58,7 +61,7 @@ export abstract class UmbDetailRepositoryBase<DetailModelType extends { unique:
58
61
if ( ! unique ) throw new Error ( 'Unique is missing' ) ;
59
62
await this . #init;
60
63
61
- const { data, error } = await this . #detailSource . read ( unique ) ;
64
+ const { data, error } = await this . detailDataSource . read ( unique ) ;
62
65
63
66
if ( data ) {
64
67
this . #detailStore! . append ( data ) ;
@@ -78,7 +81,7 @@ export abstract class UmbDetailRepositoryBase<DetailModelType extends { unique:
78
81
if ( ! model ) throw new Error ( 'Data is missing' ) ;
79
82
await this . #init;
80
83
81
- const { data : createdData , error } = await this . #detailSource . create ( model , parentUnique ) ;
84
+ const { data : createdData , error } = await this . detailDataSource . create ( model , parentUnique ) ;
82
85
83
86
if ( createdData ) {
84
87
this . #detailStore?. append ( createdData ) ;
@@ -102,7 +105,7 @@ export abstract class UmbDetailRepositoryBase<DetailModelType extends { unique:
102
105
if ( ! model . unique ) throw new Error ( 'Unique is missing' ) ;
103
106
await this . #init;
104
107
105
- const { data : updatedData , error } = await this . #detailSource . update ( model ) ;
108
+ const { data : updatedData , error } = await this . detailDataSource . update ( model ) ;
106
109
107
110
if ( updatedData ) {
108
111
this . #detailStore! . updateItem ( model . unique , updatedData ) ;
@@ -125,7 +128,7 @@ export abstract class UmbDetailRepositoryBase<DetailModelType extends { unique:
125
128
if ( ! unique ) throw new Error ( 'Unique is missing' ) ;
126
129
await this . #init;
127
130
128
- const { error } = await this . #detailSource . delete ( unique ) ;
131
+ const { error } = await this . detailDataSource . delete ( unique ) ;
129
132
130
133
if ( ! error ) {
131
134
this . #detailStore! . removeItem ( unique ) ;
@@ -152,7 +155,7 @@ export abstract class UmbDetailRepositoryBase<DetailModelType extends { unique:
152
155
153
156
destroy ( ) : void {
154
157
this . #detailStore = undefined ;
155
- ( this . #detailSource as any ) = undefined ;
158
+ ( this . detailDataSource as any ) = undefined ;
156
159
super . destroy ( ) ;
157
160
}
158
161
}
0 commit comments