@synnaxlabs/client 0.15.1 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,13 +15,17 @@ import { rackKeyZ, rackZ, type RackPayload } from "@/hardware/rack/payload";
15
15
  const RETRIEVE_ENDPOINT = "/hardware/rack/retrieve";
16
16
 
17
17
  const retrieveRackReqZ = z.object({
18
- keys: rackKeyZ.array(),
18
+ keys: rackKeyZ.array().optional(),
19
+ search: z.string().optional(),
20
+ offset: z.number().optional(),
21
+ limit: z.number().optional(),
19
22
  });
20
23
 
21
24
  const retrieveRackResZ = z.object({
22
25
  racks: rackZ.array(),
23
26
  });
24
27
 
28
+
25
29
  export class Retriever {
26
30
  private readonly client: UnaryClient;
27
31
 
@@ -29,6 +33,26 @@ export class Retriever {
29
33
  this.client = client;
30
34
  }
31
35
 
36
+ async page(offset: number, limit: number): Promise<RackPayload[]> {
37
+ const res = await sendRequired<typeof retrieveRackReqZ, typeof retrieveRackResZ>(
38
+ this.client,
39
+ RETRIEVE_ENDPOINT,
40
+ { offset, limit },
41
+ retrieveRackResZ,
42
+ );
43
+ return res.racks;
44
+ }
45
+
46
+ async search(term: string): Promise<RackPayload[]> {
47
+ const res = await sendRequired<typeof retrieveRackReqZ, typeof retrieveRackResZ>(
48
+ this.client,
49
+ RETRIEVE_ENDPOINT,
50
+ { search: term },
51
+ retrieveRackResZ,
52
+ );
53
+ return res.racks;
54
+ }
55
+
32
56
  async retrieve(keys: number[]): Promise<RackPayload[]> {
33
57
  const res = await sendRequired<typeof retrieveRackReqZ, typeof retrieveRackResZ>(
34
58
  this.client,
@@ -7,13 +7,13 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- import { toArray } from "@synnaxlabs/x";
10
+ import { AsyncTermSearcher, toArray } from "@synnaxlabs/x";
11
11
 
12
- import { type NewTask, type Task } from "@/hardware/task/payload";
12
+ import { TaskKey, type NewTask, type Task } from "@/hardware/task/payload";
13
13
  import { type RetrieveRequest, type Retriever } from "@/hardware/task/retriever";
14
14
  import { type Writer } from "@/hardware/task/writer";
15
15
 
16
- export class Client {
16
+ export class Client implements AsyncTermSearcher<string, TaskKey, Task> {
17
17
  private readonly retriever: Retriever;
18
18
  private readonly writer: Writer;
19
19
 
@@ -22,6 +22,16 @@ export class Client {
22
22
  this.writer = writer;
23
23
  }
24
24
 
25
+ async search(term: string): Promise<Task[]> {
26
+ const res = await this.retriever.search(term);
27
+ return res;
28
+ }
29
+
30
+ async page(offset: number, limit: number): Promise<Task[]> {
31
+ const res = await this.retriever.page(offset, limit);
32
+ return res;
33
+ }
34
+
25
35
  async create(task: NewTask): Promise<Task> {
26
36
  const res = await this.writer.create([task]);
27
37
  return res[0];
@@ -15,6 +15,8 @@ export const taskKeyZ = z
15
15
  .or(z.number())
16
16
  .transform((k) => k.toString());
17
17
 
18
+ export type TaskKey = z.infer<typeof taskKeyZ>;
19
+
18
20
  export const taskZ = z.object({
19
21
  key: taskKeyZ,
20
22
  name: z.string(),
@@ -16,6 +16,8 @@ import { type Task, taskZ } from "@/hardware/task/payload";
16
16
  const retrieveReqZ = z.object({
17
17
  rack: rackKeyZ.optional(),
18
18
  keys: z.string().array().optional(),
19
+ offset: z.number().optional(),
20
+ limit: z.number().optional(),
19
21
  });
20
22
 
21
23
  const rerieveResS = z.object({
@@ -42,4 +44,24 @@ export class Retriever {
42
44
  );
43
45
  return res.tasks;
44
46
  }
47
+
48
+ async search(term: string): Promise<Task[]> {
49
+ const res = await sendRequired<typeof retrieveReqZ, typeof rerieveResS>(
50
+ this.client,
51
+ RETRIEVE_ENDPOINT,
52
+ { keys: [term] },
53
+ rerieveResS,
54
+ );
55
+ return res.tasks;
56
+ }
57
+
58
+ async page(offset: number, limit: number): Promise<Task[]> {
59
+ const res = await sendRequired<typeof retrieveReqZ, typeof rerieveResS>(
60
+ this.client,
61
+ RETRIEVE_ENDPOINT,
62
+ { offset, limit },
63
+ rerieveResS,
64
+ );
65
+ return res.tasks;
66
+ }
45
67
  }
package/src/index.ts CHANGED
@@ -52,3 +52,6 @@ export { workspace } from "@/workspace";
52
52
  export { ranger } from "@/ranger";
53
53
  export { label } from "@/label";
54
54
  export { hardware } from "@/hardware";
55
+ export { rack } from "@/hardware/rack";
56
+ export { task } from "@/hardware/task";
57
+ export { device } from "@/hardware/device";