2
2
3
3
namespace Appwrite \SDK \Language ;
4
4
5
+ use Twig \TwigFilter ;
6
+
5
7
class KMP extends Kotlin
6
8
{
7
9
/**
@@ -12,12 +14,57 @@ public function getName(): string
12
14
return 'KMP ' ;
13
15
}
14
16
15
- protected function getReturnType (array $ method , array $ spec , string $ namespace , bool $ withGeneric = true , string $ generic = 'T ' ): string
17
+ public function getFilters (): array
18
+ {
19
+ $ filters = parent ::getFilters ();
20
+
21
+ $ filters [] = new TwigFilter ('webAuthServices ' , function (array $ spec ) {
22
+ return $ this ->findWebAuthServices ($ spec );
23
+ });
24
+ return $ filters ;
25
+ }
26
+
27
+ protected function getReturnType (array $ method , array $ spec , string $ namespace , string $ generic = 'T ' , bool $ withGeneric = true ): string
16
28
{
17
29
if ($ method ['type ' ] === 'webAuth ' ) {
18
30
return 'Bool ' ;
19
31
}
20
- return parent ::getReturnType ($ method , $ spec , $ namespace , $ withGeneric , $ generic );
32
+ return parent ::getReturnType ($ method , $ spec , $ namespace , $ generic , $ withGeneric );
33
+ }
34
+
35
+ protected function findWebAuthServices (array $ spec ): array
36
+ {
37
+ $ webAuthServices = [];
38
+ foreach ($ spec ['services ' ] as $ service ) {
39
+ $ webAuthMethods = [];
40
+ $ hasWebAuth = false ;
41
+ foreach ($ service ['methods ' ] as $ method ) {
42
+ if ($ method ['type ' ] === 'webAuth ' ) {
43
+ $ webAuthMethods [] = [
44
+ 'methodName ' => $ method ['name ' ],
45
+ 'parameters ' => $ method ['parameters ' ]
46
+ ];
47
+ $ hasWebAuth = true ;
48
+ }
49
+ }
50
+ if ($ hasWebAuth ) {
51
+ $ webAuthServices [] = [
52
+ 'methods ' => $ webAuthMethods ,
53
+ 'className ' => $ service ['name ' ]
54
+ ];
55
+ }
56
+ }
57
+ return $ webAuthServices ;
58
+ }
59
+
60
+
61
+ protected function getPropertyType (array $ property , array $ spec , string $ generic = 'T ' , bool $ contextual = false ): string
62
+ {
63
+ $ type = parent ::getPropertyType ($ property , $ spec , $ generic );
64
+ if ($ contextual && ($ type === 'List<Any> ' || $ type === 'List<Any>? ' )) {
65
+ $ type = 'List<@Contextual Any> ' ;
66
+ }
67
+ return $ type ;
21
68
}
22
69
23
70
public function getFiles (): array
@@ -65,8 +112,8 @@ public function getFiles(): array
65
112
],
66
113
[
67
114
'scope ' => 'default ' ,
68
- 'destination ' => 'build.gradle ' ,
69
- 'template ' => '/kmp/build.gradle.twig ' ,
115
+ 'destination ' => 'build.gradle.kts ' ,
116
+ 'template ' => '/kmp/build.gradle.kts. twig ' ,
70
117
],
71
118
[
72
119
'scope ' => 'default ' ,
@@ -88,12 +135,27 @@ public function getFiles(): array
88
135
'destination ' => 'LICENSE.md ' ,
89
136
'template ' => '/kmp/LICENSE.md.twig ' ,
90
137
],
138
+ [
139
+ 'scope ' => 'default ' ,
140
+ 'destination ' => 'gradlew ' ,
141
+ 'template ' => '/kmp/gradlew ' ,
142
+ ],
143
+ [
144
+ 'scope ' => 'default ' ,
145
+ 'destination ' => 'gradlew.bat ' ,
146
+ 'template ' => '/kmp/gradlew.bat ' ,
147
+ ],
148
+ [
149
+ 'scope ' => 'default ' ,
150
+ 'destination ' => 'gradle.properties ' ,
151
+ 'template ' => '/kmp/gradle.properties ' ,
152
+ ],
91
153
92
154
// Shared module
93
155
[
94
156
'scope ' => 'default ' ,
95
- 'destination ' => 'shared/build.gradle ' ,
96
- 'template ' => '/kmp/shared/build.gradle.twig ' ,
157
+ 'destination ' => 'shared/build.gradle.kts ' ,
158
+ 'template ' => '/kmp/shared/build.gradle.kts. twig ' ,
97
159
],
98
160
99
161
// Common Main
@@ -195,11 +257,6 @@ public function getFiles(): array
195
257
'destination ' => 'shared/src/commonMain/kotlin/{{ sdk.namespace | caseSlash }}/models/InputFile.kt ' ,
196
258
'template ' => '/kmp/shared/src/commonMain/kotlin/io/package/models/InputFile.kt.twig ' ,
197
259
],
198
- [
199
- 'scope ' => 'definition ' ,
200
- 'destination ' => 'shared/src/commonMain/kotlin/{{ sdk.namespace | caseSlash }}/models//models/{{ definition.name | caseUcfirst }}.kt ' ,
201
- 'template ' => '/kmp/shared/src/commonMain/kotlin/io/package/models/Model.kt.twig ' ,
202
- ],
203
260
[
204
261
'scope ' => 'default ' ,
205
262
'destination ' => 'shared/src/commonMain/kotlin/{{ sdk.namespace | caseSlash }}/models/RealtimeModels.kt ' ,
@@ -311,13 +368,8 @@ public function getFiles(): array
311
368
// Extensions
312
369
[
313
370
'scope ' => 'default ' ,
314
- 'destination ' => 'shared/src/androidMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Session.kt ' ,
315
- 'template ' => '/kmp/shared/src/androidMain/kotlin/io/package/extensions/createOAuth2Session.kt.twig ' ,
316
- ],
317
- [
318
- 'scope ' => 'default ' ,
319
- 'destination ' => 'shared/src/androidMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Token.kt ' ,
320
- 'template ' => '/kmp/shared/src/androidMain/kotlin/io/package/extensions/createOAuth2Token.kt.twig ' ,
371
+ 'destination ' => 'shared/src/androidMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/OAuth2Extensions.kt ' ,
372
+ 'template ' => '/kmp/shared/src/androidMain/kotlin/io/package/extensions/OAuth2Extensions.kt.twig ' ,
321
373
],
322
374
323
375
// File Operations
@@ -381,13 +433,8 @@ public function getFiles(): array
381
433
// Extensions
382
434
[
383
435
'scope ' => 'default ' ,
384
- 'destination ' => 'shared/src/iosMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Session.kt ' ,
385
- 'template ' => '/kmp/shared/src/iosMain/kotlin/io/package/extensions/createOAuth2Session.kt.twig ' ,
386
- ],
387
- [
388
- 'scope ' => 'default ' ,
389
- 'destination ' => 'shared/src/iosMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Token.kt ' ,
390
- 'template ' => '/kmp/shared/src/iosMain/kotlin/io/package/extensions/createOAuth2Token.kt.twig ' ,
436
+ 'destination ' => 'shared/src/iosMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/OAuth2Extensions.kt ' ,
437
+ 'template ' => '/kmp/shared/src/iosMain/kotlin/io/package/extensions/OAuth2Extensions.kt.twig ' ,
391
438
],
392
439
393
440
// File Operations
@@ -443,13 +490,8 @@ public function getFiles(): array
443
490
// Extensions
444
491
[
445
492
'scope ' => 'default ' ,
446
- 'destination ' => 'shared/src/jvmMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Session.kt ' ,
447
- 'template ' => '/kmp/shared/src/jvmMain/kotlin/io/package/extensions/createOAuth2Session.kt.twig ' ,
448
- ],
449
- [
450
- 'scope ' => 'default ' ,
451
- 'destination ' => 'shared/src/jvmMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Token.kt ' ,
452
- 'template ' => '/kmp/shared/src/jvmMain/kotlin/io/package/extensions/createOAuth2Token.kt.twig ' ,
493
+ 'destination ' => 'shared/src/jvmMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/OAuth2Extensions.kt ' ,
494
+ 'template ' => '/kmp/shared/src/jvmMain/kotlin/io/package/extensions/OAuth2Extensions.kt.twig ' ,
453
495
],
454
496
455
497
// File Operations
0 commit comments