Skip to content

Commit c911e54

Browse files
committed
Allow updateProperty() output stats var to be configurable
1 parent a7cd84a commit c911e54

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/core/database/query/properties/update-property.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ export type UpdatePropertyOptions<
3636
id: ID;
3737
},
3838
Key extends keyof DbChanges<TObject> & string,
39+
StatsVar extends string = 'stats',
3940
> = DeactivatePropertyOptions<TResourceStatic, TObject, Key> &
4041
CreatePropertyOptions<TResourceStatic, TObject, Key> & {
4142
/**
4243
* The property is permanent after this given duration.
4344
*/
4445
permanentAfter?: Variable | DurationIn;
46+
outputStatsVar?: StatsVar;
4547
};
4648

4749
export interface PropUpdateStat {
@@ -62,11 +64,16 @@ export const updateProperty =
6264
id: ID;
6365
},
6466
Key extends keyof DbChanges<TObject> & string,
67+
const StatsVar extends string = 'stats',
6568
>(
66-
options: UpdatePropertyOptions<TResourceStatic, TObject, Key>,
69+
options: UpdatePropertyOptions<TResourceStatic, TObject, Key, StatsVar>,
6770
) =>
68-
<R>(query: Query<R>): Query<{ stats: PropUpdateStat }> => {
69-
const { permanentAfter, ...resolved } = {
71+
<R>(query: Query<R>): Query<{ [_ in StatsVar]: PropUpdateStat }> => {
72+
const {
73+
permanentAfter,
74+
outputStatsVar = 'stats',
75+
...resolved
76+
} = {
7077
...options,
7178
nodeName: options.nodeName ?? 'node',
7279
value:
@@ -93,12 +100,12 @@ export const updateProperty =
93100
query
94101
.apply(deactivateProperty<TResourceStatic, TObject, Key>(resolved))
95102
.apply(createProperty<TResourceStatic, TObject, Key>(resolved))
96-
.return<{ stats: PropUpdateStat }>([
103+
.return<{ [_ in StatsVar]: PropUpdateStat }>([
97104
exp({
98105
method: '"new entry"',
99106
deactivated: 'numPropsDeactivated',
100107
created: 'numPropsCreated',
101-
}).as('stats'),
108+
}).as(outputStatsVar),
102109
]);
103110

104111
if (!permanentAfter) {
@@ -111,11 +118,11 @@ export const updateProperty =
111118
'existingProp.value': value.toString(),
112119
'existingProp.modifiedAt': now.toString(),
113120
})
114-
.return<{ stats: PropUpdateStat }>([
121+
.return<{ [_ in StatsVar]: PropUpdateStat }>([
115122
exp({
116123
method: '"inline replace"',
117124
updated: 1,
118-
}).as('stats'),
125+
}).as(outputStatsVar),
119126
]);
120127

121128
return query

0 commit comments

Comments
 (0)