@synnaxlabs/client 0.52.3 → 0.53.1

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.
@@ -76,20 +76,16 @@ export interface ExecuteCommandSyncParams<StatusData extends z.ZodType> extends
76
76
  "frameClient" | "name"
77
77
  > {}
78
78
 
79
- export class Task<
80
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
81
- Config extends z.ZodType = z.ZodType,
82
- StatusData extends z.ZodType = z.ZodType,
83
- > {
79
+ export class Task<S extends Schemas = Schemas> {
84
80
  readonly key: Key;
85
81
  name: string;
86
82
  internal: boolean;
87
- type: z.infer<Type>;
83
+ type: z.infer<S["type"]>;
88
84
  snapshot: boolean;
89
- config: z.infer<Config>;
90
- status?: Status<StatusData>;
85
+ config: z.infer<S["config"]>;
86
+ status?: Status<S["statusData"]>;
91
87
 
92
- readonly schemas: Schemas<Type, Config, StatusData>;
88
+ readonly schemas: S;
93
89
  private readonly frameClient_?: framer.Client;
94
90
  private readonly ontologyClient_?: ontology.Client;
95
91
  private readonly rangeClient_?: ranger.Client;
@@ -110,16 +106,8 @@ export class Task<
110
106
  }
111
107
 
112
108
  constructor(
113
- {
114
- key,
115
- type,
116
- name,
117
- config,
118
- internal = false,
119
- snapshot = false,
120
- status,
121
- }: Payload<Type, Config, StatusData>,
122
- schemas?: Schemas<Type, Config, StatusData>,
109
+ { key, type, name, config, internal = false, snapshot = false, status }: Payload<S>,
110
+ schemas?: S,
123
111
  frameClient?: framer.Client,
124
112
  ontologyClient?: ontology.Client,
125
113
  rangeClient?: ranger.Client,
@@ -128,11 +116,13 @@ export class Task<
128
116
  this.name = name;
129
117
  this.type = type;
130
118
  this.config = config;
131
- this.schemas = schemas ?? {
132
- typeSchema: z.string() as unknown as Type,
133
- configSchema: z.unknown() as unknown as Config,
134
- statusDataSchema: z.unknown() as unknown as StatusData,
135
- };
119
+ this.schemas =
120
+ schemas ??
121
+ ({
122
+ type: z.string() as unknown as S["type"],
123
+ config: z.unknown() as S["config"],
124
+ statusData: z.unknown() as S["statusData"],
125
+ } as S);
136
126
  this.internal = internal;
137
127
  this.snapshot = snapshot;
138
128
  this.status = status;
@@ -141,7 +131,7 @@ export class Task<
141
131
  this.rangeClient_ = rangeClient;
142
132
  }
143
133
 
144
- get payload(): Payload<Type, Config, StatusData> {
134
+ get payload(): Payload<S> {
145
135
  return {
146
136
  key: this.key,
147
137
  name: this.name,
@@ -166,13 +156,13 @@ export class Task<
166
156
 
167
157
  async executeCommandSync(
168
158
  params: TaskExecuteCommandSyncParams,
169
- ): Promise<Status<StatusData>> {
170
- return await executeCommandSync<StatusData>({
159
+ ): Promise<Status<S["statusData"]>> {
160
+ return await executeCommandSync<S["statusData"]>({
171
161
  ...params,
172
162
  frameClient: this.frameClient,
173
163
  task: this.key,
174
164
  name: this.name,
175
- statusDataZ: this.schemas?.statusDataSchema,
165
+ statusDataZ: this.schemas.statusData,
176
166
  });
177
167
  }
178
168
 
@@ -222,10 +212,7 @@ const singleRetrieveArgsZ = z.union([
222
212
  .object({ name: z.string(), includeStatus: z.boolean().optional() })
223
213
  .transform(({ name, includeStatus }) => ({ names: [name], includeStatus })),
224
214
  z
225
- .object({
226
- type: z.string(),
227
- rack: rackKeyZ.optional(),
228
- })
215
+ .object({ type: z.string(), rack: rackKeyZ.optional() })
229
216
  .transform(({ type, rack }) => ({ types: [type], rack })),
230
217
  ]);
231
218
  export type RetrieveSingleParams = z.input<typeof singleRetrieveArgsZ>;
@@ -236,54 +223,26 @@ export type RetrieveMultipleParams = z.input<typeof multiRetrieveArgsZ>;
236
223
  const retrieveArgsZ = z.union([singleRetrieveArgsZ, multiRetrieveArgsZ]);
237
224
  export type RetrieveArgs = z.input<typeof retrieveArgsZ>;
238
225
 
239
- type RetrieveSchemas<
240
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
241
- Config extends z.ZodType = z.ZodType,
242
- StatusData extends z.ZodType = z.ZodType,
243
- > = {
244
- schemas?: Schemas<Type, Config, StatusData>;
245
- };
226
+ interface RetrieveSchemas<S extends Schemas = Schemas> {
227
+ schemas?: S;
228
+ }
246
229
 
247
- const retrieveResZ = <
248
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
249
- Config extends z.ZodType = z.ZodType,
250
- StatusData extends z.ZodType = z.ZodType,
251
- >(
252
- schemas?: Schemas<Type, Config, StatusData>,
253
- ) =>
254
- z.object({
255
- tasks: array.nullableZ(taskZ(schemas)),
256
- });
230
+ const retrieveResZ = <S extends Schemas = Schemas>(schemas?: S) =>
231
+ z.object({ tasks: array.nullableZ(taskZ(schemas)) });
257
232
 
258
233
  export interface RetrieveRequest extends z.infer<typeof retrieveReqZ> {}
259
234
 
260
- const createReqZ = <
261
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
262
- Config extends z.ZodType = z.ZodType,
263
- StatusData extends z.ZodType = z.ZodType,
264
- >(
265
- schemas?: Schemas<Type, Config, StatusData>,
266
- ) => z.object({ tasks: newZ(schemas).array() });
267
- const createResZ = <
268
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
269
- Config extends z.ZodType = z.ZodType,
270
- StatusData extends z.ZodType = z.ZodType,
271
- >(
272
- schemas?: Schemas<Type, Config, StatusData>,
273
- ) => z.object({ tasks: taskZ(schemas).array() });
235
+ const createReqZ = <S extends Schemas = Schemas>(schemas?: S) =>
236
+ z.object({ tasks: newZ(schemas).array() });
237
+ const createResZ = <S extends Schemas = Schemas>(schemas?: S) =>
238
+ z.object({ tasks: taskZ(schemas).array() });
274
239
  const deleteReqZ = z.object({ keys: keyZ.array() });
275
240
  const deleteResZ = z.object({});
276
241
  const copyReqZ = z.object({ key: keyZ, name: z.string(), snapshot: z.boolean() });
277
- const copyResZ = <
278
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
279
- Config extends z.ZodType = z.ZodType,
280
- StatusData extends z.ZodType = z.ZodType,
281
- >(
282
- schemas?: Schemas<Type, Config, StatusData>,
283
- ) => z.object({ task: taskZ(schemas) });
242
+ const copyResZ = <S extends Schemas = Schemas>(schemas?: S) =>
243
+ z.object({ task: taskZ(schemas) });
284
244
 
285
245
  export class Client {
286
- readonly type: string = "task";
287
246
  private readonly client: UnaryClient;
288
247
  private readonly frameClient: framer.Client;
289
248
  private readonly ontologyClient: ontology.Client;
@@ -303,33 +262,14 @@ export class Client {
303
262
 
304
263
  async create(task: New): Promise<Task>;
305
264
  async create(tasks: New[]): Promise<Task[]>;
306
- async create(task: New | New[]): Promise<Task | Task[]>;
307
-
308
- async create<
309
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
310
- Config extends z.ZodType = z.ZodType,
311
- StatusData extends z.ZodType = z.ZodType,
312
- >(
313
- task: New<Type, Config, StatusData>,
314
- schemas: Schemas<Type, Config, StatusData>,
315
- ): Promise<Task<Type, Config, StatusData>>;
316
- async create<
317
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
318
- Config extends z.ZodType = z.ZodType,
319
- StatusData extends z.ZodType = z.ZodType,
320
- >(
321
- tasks: New<Type, Config, StatusData>[],
322
- schemas: Schemas<Type, Config, StatusData>,
323
- ): Promise<Task<Type, Config, StatusData>[]>;
324
-
325
- async create<
326
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
327
- Config extends z.ZodType = z.ZodType,
328
- StatusData extends z.ZodType = z.ZodType,
329
- >(
330
- task: New<Type, Config, StatusData> | Array<New<Type, Config, StatusData>>,
331
- schemas?: Schemas<Type, Config, StatusData>,
332
- ): Promise<Task<Type, Config, StatusData> | Array<Task<Type, Config, StatusData>>> {
265
+
266
+ async create<S extends Schemas>(task: New<S>, schemas: S): Promise<Task<S>>;
267
+ async create<S extends Schemas>(tasks: New<S>[], schemas: S): Promise<Task<S>[]>;
268
+
269
+ async create<S extends Schemas>(
270
+ task: New<S> | New<S>[],
271
+ schemas?: S,
272
+ ): Promise<Task<S> | Task<S>[]> {
333
273
  const isSingle = !Array.isArray(task);
334
274
  const createReq = createReqZ(schemas);
335
275
  const createRes = createResZ(schemas);
@@ -340,10 +280,7 @@ export class Client {
340
280
  createReq,
341
281
  createRes,
342
282
  );
343
- const sugared = this.sugar<Type, Config, StatusData>(
344
- res.tasks as Payload<Type, Config, StatusData>[],
345
- schemas,
346
- );
283
+ const sugared = this.sugar<S>(res.tasks as Payload<S>[], schemas);
347
284
  return isSingle ? sugared[0] : sugared;
348
285
  }
349
286
 
@@ -357,32 +294,18 @@ export class Client {
357
294
  );
358
295
  }
359
296
 
360
- async retrieve<
361
- Type extends z.ZodLiteral<string>,
362
- Config extends z.ZodType,
363
- StatusData extends z.ZodType,
364
- >(
365
- args: RetrieveSingleParams & RetrieveSchemas<Type, Config, StatusData>,
366
- ): Promise<Task<Type, Config, StatusData>>;
297
+ async retrieve<S extends Schemas = Schemas>(
298
+ args: RetrieveSingleParams & RetrieveSchemas<S>,
299
+ ): Promise<Task<S>>;
367
300
  async retrieve(args: RetrieveSingleParams): Promise<Task>;
368
- async retrieve<
369
- Type extends z.ZodLiteral<string>,
370
- Config extends z.ZodType,
371
- StatusData extends z.ZodType,
372
- >(
373
- args: RetrieveMultipleParams & RetrieveSchemas<Type, Config, StatusData>,
374
- ): Promise<Task<Type, Config, StatusData>[]>;
301
+ async retrieve<S extends Schemas = Schemas>(
302
+ args: RetrieveMultipleParams & RetrieveSchemas<S>,
303
+ ): Promise<Task<S>[]>;
375
304
  async retrieve(args: RetrieveMultipleParams): Promise<Task[]>;
376
- async retrieve<
377
- Type extends z.ZodLiteral<string>,
378
- Config extends z.ZodType,
379
- StatusData extends z.ZodType,
380
- >({
305
+ async retrieve<S extends Schemas = Schemas>({
381
306
  schemas,
382
307
  ...args
383
- }: RetrieveArgs & RetrieveSchemas<Type, Config, StatusData>): Promise<
384
- Task<Type, Config, StatusData> | Task<Type, Config, StatusData>[]
385
- > {
308
+ }: RetrieveArgs & RetrieveSchemas<S>): Promise<Task<S> | Task<S>[]> {
386
309
  const isSingle = singleRetrieveArgsZ.safeParse(args).success;
387
310
  const res = await sendRequired(
388
311
  this.client,
@@ -391,8 +314,8 @@ export class Client {
391
314
  retrieveArgsZ,
392
315
  retrieveResZ(schemas),
393
316
  );
394
- const tasks = res.tasks as Payload<Type, Config, StatusData>[];
395
- const sugared = this.sugar<Type, Config, StatusData>(tasks, schemas);
317
+ const tasks = res.tasks as Payload<S>[];
318
+ const sugared = this.sugar(tasks, schemas);
396
319
  checkForMultipleOrNoResults("Task", args, sugared, isSingle);
397
320
  return isSingle ? sugared[0] : sugared;
398
321
  }
@@ -420,32 +343,14 @@ export class Client {
420
343
  return await retrieveSnapshottedTo(taskKey, this.ontologyClient);
421
344
  }
422
345
 
423
- sugar<
424
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
425
- Config extends z.ZodType = z.ZodType,
426
- StatusData extends z.ZodType = z.ZodType,
427
- >(
428
- payloads: Payload<Type, Config, StatusData>[],
429
- schemas?: Schemas<Type, Config, StatusData>,
430
- ): Task<Type, Config, StatusData>[];
431
-
432
- sugar<
433
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
434
- Config extends z.ZodType = z.ZodType,
435
- StatusData extends z.ZodType = z.ZodType,
436
- >(
437
- payload: Payload<Type, Config, StatusData>,
438
- schemas?: Schemas<Type, Config, StatusData>,
439
- ): Task<Type, Config, StatusData>;
440
-
441
- sugar<
442
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
443
- Config extends z.ZodType = z.ZodType,
444
- StatusData extends z.ZodType = z.ZodType,
445
- >(
446
- payloads: Payload<Type, Config, StatusData> | Payload<Type, Config, StatusData>[],
447
- schemas?: Schemas<Type, Config, StatusData>,
448
- ): Task<Type, Config, StatusData>[] | Task<Type, Config, StatusData> {
346
+ sugar<S extends Schemas = Schemas>(payloads: Payload<S>[], schemas?: S): Task<S>[];
347
+
348
+ sugar<S extends Schemas = Schemas>(payload: Payload<S>, schemas?: S): Task<S>;
349
+
350
+ sugar<S extends Schemas = Schemas>(
351
+ payloads: Payload<S> | Payload<S>[],
352
+ schemas?: S,
353
+ ): Task<S>[] | Task<S> {
449
354
  const isSingle = !Array.isArray(payloads);
450
355
  const res = array.toArray(payloads).map(
451
356
  ({ key, name, type, config, status, internal, snapshot }) =>
@@ -21,12 +21,7 @@ export const keyZ = z.union([
21
21
  export type Key = z.infer<typeof keyZ>;
22
22
 
23
23
  export const statusDetailsZ = <DataSchema extends z.ZodType>(data: DataSchema) =>
24
- z.object({
25
- task: keyZ,
26
- running: z.boolean(),
27
- data,
28
- cmd: z.string().optional(),
29
- });
24
+ z.object({ task: keyZ, running: z.boolean(), data, cmd: z.string().optional() });
30
25
 
31
26
  export type StatusDetails<DataSchema extends z.ZodType> = z.infer<
32
27
  ReturnType<typeof statusDetailsZ<DataSchema>>
@@ -35,9 +30,9 @@ export type StatusDetails<DataSchema extends z.ZodType> = z.infer<
35
30
  export const statusZ = <DataSchema extends z.ZodType>(data: DataSchema) =>
36
31
  status.statusZ(statusDetailsZ(data));
37
32
 
38
- export type Status<StatusData extends z.ZodType = z.ZodUnknown> = z.infer<
33
+ export interface Status<StatusData extends z.ZodType = z.ZodUnknown> extends z.infer<
39
34
  ReturnType<typeof statusZ<StatusData>>
40
- >;
35
+ > {}
41
36
 
42
37
  const newStatusDetailsZ = <DataSchema extends z.ZodType>(data: DataSchema) =>
43
38
  statusDetailsZ(data).partial({ task: true });
@@ -45,83 +40,65 @@ const newStatusDetailsZ = <DataSchema extends z.ZodType>(data: DataSchema) =>
45
40
  export const newStatusZ = <DataSchema extends z.ZodType>(data: DataSchema) =>
46
41
  status.statusZ(newStatusDetailsZ(data)).partial({ key: true, name: true });
47
42
 
48
- export interface NewStatus<DataSchema extends z.ZodType = z.ZodUnknown> extends z.infer<
43
+ export interface NewStatus<DataSchema extends z.ZodType = z.ZodType> extends z.infer<
49
44
  ReturnType<typeof newStatusZ<DataSchema>>
50
45
  > {}
51
46
 
52
- export const taskZ = <
47
+ export interface Schemas<
53
48
  Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
54
49
  Config extends z.ZodType = z.ZodType,
55
- StatusData extends z.ZodType = z.ZodUnknown,
56
- >(
57
- schemas: Schemas<Type, Config, StatusData> = {
58
- typeSchema: z.string() as unknown as Type,
59
- configSchema: record.nullishToEmpty() as unknown as Config,
60
- statusDataSchema: z.unknown() as unknown as StatusData,
50
+ StatusData extends z.ZodType = z.ZodType,
51
+ > {
52
+ type: Type;
53
+ config: Config;
54
+ statusData: StatusData;
55
+ }
56
+
57
+ export const taskZ = <S extends Schemas = Schemas>(
58
+ schemas = {
59
+ type: z.string() as unknown as S["type"],
60
+ config: record.nullishToEmpty() as S["config"],
61
+ statusData: z.unknown() as S["statusData"],
61
62
  },
62
63
  ) =>
63
64
  z.object({
64
65
  key: keyZ,
65
66
  name: z.string(),
66
- type: schemas.typeSchema,
67
+ type: schemas.type,
67
68
  internal: z.boolean().optional(),
68
- config: schemas.configSchema,
69
- status: statusZ(schemas.statusDataSchema).optional().nullable(),
69
+ config: schemas.config,
70
+ status: statusZ(schemas.statusData).optional().nullable(),
70
71
  snapshot: z.boolean().optional(),
71
72
  });
72
73
 
73
- export interface Schemas<
74
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
75
- Config extends z.ZodType = z.ZodType,
76
- StatusData extends z.ZodType = z.ZodType,
77
- > {
78
- typeSchema: Type;
79
- configSchema: Config;
80
- statusDataSchema: StatusData;
81
- }
82
-
83
- export type Payload<
84
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
85
- Config extends z.ZodType = z.ZodType,
86
- StatusData extends z.ZodType = z.ZodType,
87
- > = {
74
+ export interface Payload<S extends Schemas = Schemas> {
88
75
  key: Key;
89
76
  name: string;
90
- type: z.infer<Type>;
91
- config: z.infer<Config>;
92
- status?: Status<StatusData>;
77
+ type: z.infer<S["type"]>;
78
+ config: z.infer<S["config"]>;
79
+ status?: Status<S["statusData"]>;
93
80
  snapshot?: boolean;
94
81
  internal?: boolean;
95
- };
82
+ }
96
83
 
97
- export const newZ = <
98
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
99
- Config extends z.ZodType = z.ZodType,
100
- StatusData extends z.ZodType = z.ZodUnknown,
101
- >(
102
- schemas?: Schemas<Type, Config, StatusData>,
103
- ) =>
84
+ export const newZ = <S extends Schemas = Schemas>(schemas?: S) =>
104
85
  taskZ(schemas)
105
86
  .omit({ key: true, status: true })
106
87
  .extend({
107
88
  key: keyZ.transform((k) => k.toString()).optional(),
108
- config: schemas?.configSchema ?? record.nullishToEmpty(),
109
- status: newStatusZ(schemas?.statusDataSchema ?? z.unknown())
89
+ config: schemas?.config ?? record.nullishToEmpty(),
90
+ status: newStatusZ(schemas?.statusData ?? z.unknown())
110
91
  .optional()
111
92
  .nullable(),
112
93
  });
113
94
 
114
- export type New<
115
- Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
116
- Config extends z.ZodType = z.ZodType,
117
- StatusData extends z.ZodType = z.ZodUnknown,
118
- > = {
95
+ export interface New<S extends Schemas = Schemas> {
119
96
  key?: Key;
120
97
  name: string;
121
- type: z.infer<Type>;
122
- config: z.infer<Config>;
123
- status?: NewStatus<StatusData>;
124
- };
98
+ type: z.infer<S["type"]>;
99
+ config: z.infer<S["config"]>;
100
+ status?: NewStatus<S["statusData"]>;
101
+ }
125
102
 
126
103
  export const commandZ = z.object({
127
104
  task: keyZ,