* Fetch the number of resources of a given type.
(
key: string,
params?: Optional<OmitIndexSignature<Parameters<TResource["count"]>[0]>, "session">
)
| 219 | * Fetch the number of resources of a given type. |
| 220 | */ |
| 221 | async count( |
| 222 | key: string, |
| 223 | params?: Optional<OmitIndexSignature<Parameters<TResource["count"]>[0]>, "session"> |
| 224 | ): CountReturnType { |
| 225 | return this.runTask( |
| 226 | key, |
| 227 | async (client, task, io) => { |
| 228 | const countResponse = await client.rest[this.resourceType].count( |
| 229 | this.#withSession(params ?? {}) |
| 230 | ); |
| 231 | |
| 232 | const CountResponseSchema = z.object({ |
| 233 | count: z.number(), |
| 234 | }); |
| 235 | |
| 236 | const parsed = CountResponseSchema.safeParse(countResponse); |
| 237 | |
| 238 | if (!parsed.success) { |
| 239 | return JSON.parse(JSON.stringify(countResponse)); |
| 240 | } |
| 241 | |
| 242 | task.outputProperties = [ |
| 243 | { |
| 244 | label: "Total", |
| 245 | text: String(parsed.data.count), |
| 246 | }, |
| 247 | ]; |
| 248 | |
| 249 | return parsed.data; |
| 250 | }, |
| 251 | { |
| 252 | name: `Count ${this.resourceType}s`, |
| 253 | params, |
| 254 | } |
| 255 | ); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Create or update a resource of a given type. The resource will be created if no ID is specified. |
no test coverage detected