@synnaxlabs/client 0.17.3 → 0.17.5

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.
@@ -11,23 +11,27 @@
11
11
  import type { Stream, StreamClient } from "@synnaxlabs/freighter";
12
12
  import { decodeError, errorZ } from "@synnaxlabs/freighter";
13
13
  import {
14
- type NativeTypedArray,
15
- Series,
16
14
  TimeStamp,
17
15
  type CrudeTimeStamp,
18
16
  toArray,
17
+ type CrudeSeries,
19
18
  } from "@synnaxlabs/x";
20
19
  import { z } from "zod";
21
20
 
22
- import { type Key, type KeyOrName, type Params } from "@/channel/payload";
21
+ import {
22
+ type KeysOrNames,
23
+ type Key,
24
+ type KeyOrName,
25
+ type Params,
26
+ } from "@/channel/payload";
23
27
  import { type Retriever } from "@/channel/retriever";
24
28
  import { Authority } from "@/control/authority";
25
29
  import {
26
30
  subjectZ as controlSubjectZ,
27
31
  type Subject as ControlSubject,
28
32
  } from "@/control/state";
29
- import { ForwardFrameAdapter } from "@/framer/adapter";
30
- import { type CrudeFrame, Frame, frameZ } from "@/framer/frame";
33
+ import { WriteFrameAdapter } from "@/framer/adapter";
34
+ import { frameZ, type CrudeFrame } from "@/framer/frame";
31
35
  import { StreamProxy } from "@/framer/streamProxy";
32
36
 
33
37
  enum Command {
@@ -118,11 +122,11 @@ export interface WriterConfig {
118
122
  export class Writer {
119
123
  private static readonly ENDPOINT = "/frame/write";
120
124
  private readonly stream: StreamProxy<typeof reqZ, typeof resZ>;
121
- private readonly adapter: ForwardFrameAdapter;
125
+ private readonly adapter: WriteFrameAdapter;
122
126
 
123
127
  private constructor(
124
128
  stream: Stream<typeof reqZ, typeof resZ>,
125
- adapter: ForwardFrameAdapter,
129
+ adapter: WriteFrameAdapter,
126
130
  ) {
127
131
  this.stream = new StreamProxy("Writer", stream);
128
132
  this.adapter = adapter;
@@ -139,7 +143,7 @@ export class Writer {
139
143
  mode,
140
144
  }: WriterConfig,
141
145
  ): Promise<Writer> {
142
- const adapter = await ForwardFrameAdapter.open(retriever, channels);
146
+ const adapter = await WriteFrameAdapter.open(retriever, channels);
143
147
  const stream = await client.stream(Writer.ENDPOINT, reqZ, resZ);
144
148
  const writer = new Writer(stream, adapter);
145
149
  await writer.execute({
@@ -155,7 +159,9 @@ export class Writer {
155
159
  return writer;
156
160
  }
157
161
 
158
- async write(channel: KeyOrName, data: NativeTypedArray): Promise<boolean>;
162
+ async write(channel: KeyOrName, data: CrudeSeries): Promise<boolean>;
163
+
164
+ async write(channel: KeysOrNames, data: CrudeSeries[]): Promise<boolean>;
159
165
 
160
166
  async write(frame: CrudeFrame): Promise<boolean>;
161
167
 
@@ -174,14 +180,11 @@ export class Writer {
174
180
  * should acknowledge the error by calling the error method or closing the writer.
175
181
  */
176
182
  async write(
177
- frame: CrudeFrame | KeyOrName,
178
- data?: NativeTypedArray,
183
+ channelsOrData: Params | Record<KeyOrName, CrudeSeries> | CrudeFrame,
184
+ series?: CrudeSeries | CrudeSeries[],
179
185
  ): Promise<boolean> {
180
- const isKeyOrName = ["string", "number"].includes(typeof frame);
181
- if (isKeyOrName)
182
- frame = new Frame(frame, new Series({ data: data as NativeTypedArray }));
183
- frame = this.adapter.adapt(new Frame(frame));
184
- // @ts-expect-error
186
+ const frame = await this.adapter.adapt(channelsOrData, series);
187
+ // @ts-expect-error - zod issues
185
188
  this.stream.send({ command: Command.Write, frame: frame.toPayload() });
186
189
  return true;
187
190
  }
package/src/index.ts CHANGED
@@ -37,7 +37,7 @@ export {
37
37
  TimeStamp,
38
38
  } from "@synnaxlabs/x";
39
39
  export type {
40
- NativeTypedArray,
40
+ TypedArray,
41
41
  CrudeDataType,
42
42
  CrudeDensity,
43
43
  CrudeRate,
package/src/util/telem.ts CHANGED
@@ -7,9 +7,9 @@
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 { DataType, NativeTypedArray } from "@synnaxlabs/x";
10
+ import { type DataType, type TypedArray } from "@synnaxlabs/x";
11
11
 
12
- export const randomSeries = (length: number, dataType: DataType): NativeTypedArray => {
12
+ export const randomSeries = (length: number, dataType: DataType): TypedArray => {
13
13
  // generate random bytes of the correct length
14
14
  const bytes = new Uint8Array(length * dataType.density.valueOf());
15
15
  for (let i = 0; i < bytes.byteLength; i++) {