@@ -13,10 +13,79 @@ type Status = {
13
13
[ key : string ] : any
14
14
}
15
15
16
+ // XRD Model Registry types
17
+ export interface XrdModelRegistryEntry {
18
+ modelClass : typeof Model
19
+ group : string
20
+ kind : string
21
+ }
22
+
23
+ export interface XrdModelRegistry {
24
+ [ key : string ] : XrdModelRegistryEntry
25
+ }
26
+
27
+ // Global registry for XRD models
28
+ const xrdModelRegistry : XrdModelRegistry = { }
29
+
30
+ /**
31
+ * Register an XRD model class with the global registry
32
+ * @param group - The API group (e.g., "workspace.fabrique.social.gouv.fr")
33
+ * @param kind - The resource kind (e.g., "XRedis")
34
+ * @returns Class decorator function
35
+ */
36
+ export function registerXrdModel ( group : string , kind : string ) {
37
+ return function < T extends new ( ...args : any [ ] ) => Model < any > > ( target : T ) : T {
38
+ const registryKey = `${ group } /${ kind } `
39
+
40
+ xrdModelRegistry [ registryKey ] = {
41
+ modelClass : target as any ,
42
+ group,
43
+ kind,
44
+ }
45
+
46
+ return target
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Get a registered XRD model class by group and kind
52
+ * @param group - The API group
53
+ * @param kind - The resource kind
54
+ * @returns The registered model class or undefined if not found
55
+ */
56
+ export function getRegisteredXrdModel ( group : string , kind : string ) : typeof Model | undefined {
57
+ const registryKey = `${ group } /${ kind } `
58
+ return xrdModelRegistry [ registryKey ] ?. modelClass
59
+ }
60
+
61
+ /**
62
+ * Get a registered XRD model class by apiVersion and kind
63
+ * @param apiVersion - The full API version (e.g., "workspace.fabrique.social.gouv.fr/v1alpha1")
64
+ * @param kind - The resource kind
65
+ * @returns The registered model class or undefined if not found
66
+ */
67
+ export function getRegisteredXrdModelByApiVersion (
68
+ apiVersion : string ,
69
+ kind : string
70
+ ) : typeof Model | undefined {
71
+ // Extract group from apiVersion
72
+ // If no '/' is present, use "core" as convention for core resources
73
+ const group = apiVersion . includes ( "/" ) ? apiVersion . split ( "/" ) [ 0 ] : "core"
74
+ return getRegisteredXrdModel ( group , kind )
75
+ }
76
+
77
+ /**
78
+ * Get all registered XRD models
79
+ * @returns The complete registry
80
+ */
81
+ export function getXrdModelRegistry ( ) : XrdModelRegistry {
82
+ return { ...xrdModelRegistry }
83
+ }
84
+
16
85
export class Model < T > extends BaseModel < T > {
17
86
getMetadata ( ) : IObjectMeta {
18
87
const self = this as any
19
- if ( ! self . metadatata ) {
88
+ if ( ! self . metadata ) {
20
89
throw new Error ( "No metadata found" )
21
90
}
22
91
return self . metadata
0 commit comments