File tree 2 files changed +27
-1
lines changed
packages/api-client-core/src
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -59,3 +59,11 @@ export interface AnyLegacyModelManager {
59
59
* Any model manager, either public or internal
60
60
*/
61
61
export type AnyModelManager = AnyPublicModelManager | AnyPublicSingletonModelManager | AnyLegacyModelManager | InternalModelManager ;
62
+
63
+ export function isPublicModelManager ( manager : AnyModelManager ) : manager is AnyPublicModelManager {
64
+ return "findOne" in manager ;
65
+ }
66
+
67
+ export function isPublicSingletonModelManager ( manager : AnyModelManager ) : manager is AnyPublicSingletonModelManager {
68
+ return "get" in manager ;
69
+ }
Original file line number Diff line number Diff line change 1
1
import { klona as cloneDeep } from "klona" ;
2
2
import type { Jsonify } from "type-fest" ;
3
- import type { AnyModelManager } from "./AnyModelManager.js" ;
3
+ import { isPublicModelManager , isPublicSingletonModelManager , type AnyModelManager } from "./AnyModelManager.js" ;
4
4
import { isEqual , toPrimitiveObject } from "./support.js" ;
5
5
6
6
export enum ChangeTracking {
@@ -212,6 +212,24 @@ export class GadgetRecord_<Shape extends RecordShape> {
212
212
touch ( ) : void {
213
213
this [ kTouched ] = true ;
214
214
}
215
+
216
+ async reload ( ) {
217
+ const modelManager = this [ kModelManager ] ;
218
+
219
+ if ( ! modelManager ) {
220
+ throw new Error ( "Record can not be reloaded" ) ;
221
+ }
222
+
223
+ if ( isPublicModelManager ( modelManager ) ) {
224
+ return await modelManager . findOne ( this . getField ( "id" ) ) ;
225
+ }
226
+
227
+ if ( isPublicSingletonModelManager ( modelManager ) ) {
228
+ return await modelManager . get ( ) ;
229
+ }
230
+
231
+ throw new Error ( "Record can not be reloaded" ) ;
232
+ }
215
233
}
216
234
217
235
/**
You can’t perform that action at this time.
0 commit comments