Skip to content

Commit 4fa87d5

Browse files
committed
inline docs for android permission and query files
1 parent 264aca0 commit 4fa87d5

File tree

2 files changed

+204
-4
lines changed

2 files changed

+204
-4
lines changed

templates/android/library/src/main/java/io/package/Permission.kt.twig

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,60 @@
11
package {{ sdk.namespace | caseDot }}
22

3+
/**
4+
* Helper class to generate permission strings for resources.
5+
*/
36
class Permission {
47
companion object {
8+
9+
/**
10+
* Generate read permission string for the provided role.
11+
*
12+
* @param role The role for which to generate the permission.
13+
* @returns The read permission string.
14+
*/
515
fun read(role: String): String {
616
return "read(\"${role}\")"
7-
}
17+
}
18+
19+
/**
20+
* Generate write permission string for the provided role.
21+
*
22+
* This is an alias of update, delete, and possibly create.
23+
* Don't use write in combination with update, delete, or create.
24+
*
25+
* @param role The role for which to generate the permission.
26+
* @returns The write permission string.
27+
*/
828
fun write(role: String): String {
929
return "write(\"${role}\")"
1030
}
31+
32+
/**
33+
* Generate create permission string for the provided role.
34+
*
35+
* @param role The role for which to generate the permission.
36+
* @returns The create permission string.
37+
*/
1138
fun create(role: String): String {
1239
return "create(\"${role}\")"
13-
}
40+
}
41+
42+
/**
43+
* Generate update permission string for the provided role.
44+
*
45+
* @param role The role for which to generate the permission.
46+
* @returns The update permission string.
47+
*/
1448
fun update(role: String): String {
1549
return "update(\"${role}\")"
16-
}
50+
}
51+
52+
/**
53+
* Generate delete permission string for the provided role.
54+
*
55+
* @param role The role for which to generate the permission.
56+
* @returns The delete permission string.
57+
*/
1758
fun delete(role: String): String {
1859
return "delete(\"${role}\")"
1960
}

templates/android/library/src/main/java/io/package/Query.kt.twig

Lines changed: 160 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,217 @@ package {{ sdk.namespace | caseDot }}
33
import {{ sdk.namespace | caseDot }}.extensions.toJson
44
import {{ sdk.namespace | caseDot }}.extensions.fromJson
55

6+
/**
7+
* Helper class to generate query strings.
8+
*/
69
class Query(
710
val method: String,
811
val attribute: String? = null,
912
val values: List<Any>? = null,
1013
) {
14+
/**
15+
* Convert the query object to a JSON string.
16+
*
17+
* @returns The JSON string representation of the query object.
18+
*/
1119
override fun toString() = this.toJson()
1220

1321
companion object {
22+
23+
/**
24+
* Filter resources where attribute is equal to value.
25+
*
26+
* @param attribute The attribute to filter on.
27+
* @param value The value to compare against.
28+
* @returns The query string.
29+
*/
1430
fun equal(attribute: String, value: Any) = Query("equal", attribute, parseValue(value)).toJson()
1531

32+
/**
33+
* Filter resources where attribute is not equal to value.
34+
*
35+
* @param attribute The attribute to filter on.
36+
* @param value The value to compare against.
37+
* @returns The query string.
38+
*/
1639
fun notEqual(attribute: String, value: Any) = Query("notEqual", attribute, parseValue(value)).toJson()
1740

41+
/**
42+
* Filter resources where attribute is less than value.
43+
*
44+
* @param attribute The attribute to filter on.
45+
* @param value The value to compare against.
46+
* @returns The query string.
47+
*/
1848
fun lessThan(attribute: String, value: Any) = Query("lessThan", attribute, parseValue(value)).toJson()
1949

50+
/**
51+
* Filter resources where attribute is less than or equal to value.
52+
*
53+
* @param attribute The attribute to filter on.
54+
* @param value The value to compare against.
55+
* @returns The query string.
56+
*/
2057
fun lessThanEqual(attribute: String, value: Any) = Query("lessThanEqual", attribute, parseValue(value)).toJson()
2158

59+
/**
60+
* Filter resources where attribute is greater than value.
61+
*
62+
* @param attribute The attribute to filter on.
63+
* @param value The value to compare against.
64+
* @returns The query string.
65+
*/
2266
fun greaterThan(attribute: String, value: Any) = Query("greaterThan", attribute, parseValue(value)).toJson()
2367

68+
/**
69+
* Filter resources where attribute is greater than or equal to value.
70+
*
71+
* @param attribute The attribute to filter on.
72+
* @param value The value to compare against.
73+
* @returns The query string.
74+
*/
2475
fun greaterThanEqual(attribute: String, value: Any) = Query("greaterThanEqual", attribute, parseValue(value)).toJson()
2576

77+
/**
78+
* Filter resources where attribute matches the search value.
79+
*
80+
* @param attribute The attribute to filter on.
81+
* @param value The search value to match against.
82+
* @returns The query string.
83+
*/
2684
fun search(attribute: String, value: String) = Query("search", attribute, listOf(value)).toJson()
2785

86+
/**
87+
* Filter resources where attribute is null.
88+
*
89+
* @param attribute The attribute to filter on.
90+
* @returns The query string.
91+
*/
2892
fun isNull(attribute: String) = Query("isNull", attribute).toJson()
2993

94+
/**
95+
* Filter resources where attribute is not null.
96+
*
97+
* @param attribute The attribute to filter on.
98+
* @returns The query string.
99+
*/
30100
fun isNotNull(attribute: String) = Query("isNotNull", attribute).toJson()
31101

102+
/**
103+
* Filter resources where attribute is between start and end (inclusive).
104+
*
105+
* @param attribute The attribute to filter on.
106+
* @param start The start value of the range.
107+
* @param end The end value of the range.
108+
* @returns The query string.
109+
*/
32110
fun between(attribute: String, start: Any, end: Any) = Query("between", attribute, listOf(start, end)).toJson()
33111

112+
/**
113+
* Filter resources where attribute starts with value.
114+
*
115+
* @param attribute The attribute to filter on.
116+
* @param value The value to compare against.
117+
* @returns The query string.
118+
*/
34119
fun startsWith(attribute: String, value: String) = Query("startsWith", attribute, listOf(value)).toJson()
35120

121+
/**
122+
* Filter resources where attribute ends with value.
123+
*
124+
* @param attribute The attribute to filter on.
125+
* @param value The value to compare against.
126+
* @returns The query string.
127+
*/
36128
fun endsWith(attribute: String, value: String) = Query("endsWith", attribute, listOf(value)).toJson()
37129

130+
/**
131+
* Specify which attributes should be returned by the API call.
132+
*
133+
* @param attributes The list of attributes to select.
134+
* @returns The query string.
135+
*/
38136
fun select(attributes: List<String>) = Query("select", null, attributes).toJson()
39137

138+
/**
139+
* Sort results by attribute ascending.
140+
*
141+
* @param attribute The attribute to sort by.
142+
* @returns The query string.
143+
*/
40144
fun orderAsc(attribute: String) = Query("orderAsc", attribute).toJson()
41145

146+
/**
147+
* Sort results by attribute descending.
148+
*
149+
* @param attribute The attribute to sort by.
150+
* @returns The query string.
151+
*/
42152
fun orderDesc(attribute: String) = Query("orderDesc", attribute).toJson()
43153

154+
/**
155+
* Return results before documentId.
156+
*
157+
* @param documentId The document ID to use as cursor.
158+
* @returns The query string.
159+
*/
44160
fun cursorBefore(documentId: String) = Query("cursorBefore", null, listOf(documentId)).toJson()
45161

162+
/**
163+
* Return results after documentId.
164+
*
165+
* @param documentId The document ID to use as cursor.
166+
* @returns The query string.
167+
*/
46168
fun cursorAfter(documentId: String) = Query("cursorAfter", null, listOf(documentId)).toJson()
47-
169+
170+
/**
171+
* Return only limit results.
172+
*
173+
* @param limit The number of results to return.
174+
* @returns The query string.
175+
*/
48176
fun limit(limit: Int) = Query("limit", null, listOf(limit)).toJson()
49177

178+
/**
179+
* Filter resources by skipping the first offset results.
180+
*
181+
* @param offset The number of results to skip.
182+
* @returns The query string.
183+
*/
50184
fun offset(offset: Int) = Query("offset", null, listOf(offset)).toJson()
51185

186+
/**
187+
* Filter resources where attribute contains the specified value.
188+
*
189+
* @param attribute The attribute to filter on.
190+
* @param value The value to compare against.
191+
* @returns The query string.
192+
*/
52193
fun contains(attribute: String, value: Any) = Query("contains", attribute, parseValue(value)).toJson()
53194

195+
/**
196+
* Combine multiple queries using logical OR operator.
197+
*
198+
* @param queries The list of query strings to combine.
199+
* @returns The query string.
200+
*/
54201
fun or(queries: List<String>) = Query("or", null, queries.map { it.fromJson<Query>() }).toJson()
55202

203+
/**
204+
* Combine multiple queries using logical AND operator.
205+
*
206+
* @param queries The list of query strings to combine.
207+
* @returns The query string.
208+
*/
56209
fun and(queries: List<String>) = Query("and", null, queries.map { it.fromJson<Query>() }).toJson()
57210

211+
/**
212+
* Parse the value to a list of values.
213+
*
214+
* @param value The value to parse.
215+
* @returns The list of parsed values.
216+
*/
58217
private fun parseValue(value: Any): List<Any> {
59218
return when (value) {
60219
is List<*> -> value as List<Any>

0 commit comments

Comments
 (0)