@synnaxlabs/client 0.32.0 → 0.33.0
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.
- package/.turbo/turbo-build.log +7 -7
- package/dist/access/policy/payload.d.ts +40 -40
- package/dist/access/policy/retriever.d.ts +5 -5
- package/dist/channel/client.d.ts +1 -1
- package/dist/client.cjs +26 -26
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2896 -2499
- package/dist/framer/deleter.d.ts.map +1 -1
- package/dist/framer/frame.d.ts.map +1 -1
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/task/ni/types.d.ts +13 -13
- package/dist/hardware/task/ni/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/label/writer.d.ts +5 -5
- package/dist/ontology/client.d.ts +9 -9
- package/dist/ontology/payload.d.ts +43 -43
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ranger/client.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/ranger/writer.d.ts +5 -5
- package/dist/ranger/writer.d.ts.map +1 -1
- package/dist/workspace/client.d.ts +2 -0
- package/dist/workspace/client.d.ts.map +1 -1
- package/dist/workspace/log/client.d.ts +16 -0
- package/dist/workspace/log/client.d.ts.map +1 -0
- package/dist/workspace/log/external.d.ts +3 -0
- package/dist/workspace/log/external.d.ts.map +1 -0
- package/dist/workspace/log/index.d.ts +2 -0
- package/dist/workspace/log/index.d.ts.map +1 -0
- package/dist/workspace/log/log.spec.d.ts +2 -0
- package/dist/workspace/log/log.spec.d.ts.map +1 -0
- package/dist/workspace/log/payload.d.ts +36 -0
- package/dist/workspace/log/payload.d.ts.map +1 -0
- package/dist/workspace/log/retriever.d.ts +9 -0
- package/dist/workspace/log/retriever.d.ts.map +1 -0
- package/dist/workspace/log/writer.d.ts +35 -0
- package/dist/workspace/log/writer.d.ts.map +1 -0
- package/package.json +12 -13
- package/src/access/policy/policy.spec.ts +6 -6
- package/src/channel/client.ts +1 -1
- package/src/control/state.ts +1 -1
- package/src/errors.spec.ts +19 -0
- package/src/hardware/task/ni/types.ts +13 -13
- package/src/index.ts +2 -2
- package/src/ontology/client.ts +1 -1
- package/src/ontology/payload.ts +1 -0
- package/src/workspace/client.ts +3 -0
- package/src/workspace/log/client.ts +51 -0
- package/src/workspace/log/external.ts +11 -0
- package/src/workspace/log/index.ts +10 -0
- package/src/workspace/log/log.spec.ts +78 -0
- package/src/workspace/log/payload.ts +36 -0
- package/src/workspace/log/retriever.ts +38 -0
- package/src/workspace/log/writer.ts +116 -0
- package/src/workspace/schematic/writer.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synnaxlabs/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"description": "The Synnax Client Library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"synnax",
|
|
@@ -25,24 +25,23 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"async-mutex": "^0.5.0",
|
|
28
|
-
"zod": "3.23.8",
|
|
29
|
-
"@synnaxlabs/freighter": "0.
|
|
30
|
-
"@synnaxlabs/x": "0.
|
|
28
|
+
"zod": "^3.23.8",
|
|
29
|
+
"@synnaxlabs/freighter": "0.33.0",
|
|
30
|
+
"@synnaxlabs/x": "0.33.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^22.5
|
|
34
|
-
"@vitest/coverage-v8": "^2.1.
|
|
35
|
-
"eslint": "^9.
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
33
|
+
"@types/node": "^22.7.5",
|
|
34
|
+
"@vitest/coverage-v8": "^2.1.2",
|
|
35
|
+
"eslint": "^9.12.0",
|
|
36
|
+
"uuid": "^10.0.0",
|
|
37
|
+
"@types/uuid": "^10.0.0",
|
|
38
|
+
"typescript": "^5.6.3",
|
|
39
|
+
"vite": "^5.4.8",
|
|
40
|
+
"vitest": "^2.1.2",
|
|
39
41
|
"@synnaxlabs/tsconfig": "0.0.2",
|
|
40
42
|
"@synnaxlabs/vite-plugin": "0.0.1",
|
|
41
43
|
"eslint-config-synnaxlabs": "0.0.1"
|
|
42
44
|
},
|
|
43
|
-
"peerDependencies": {
|
|
44
|
-
"zod": "3.23.8"
|
|
45
|
-
},
|
|
46
45
|
"type": "module",
|
|
47
46
|
"types": "dist/index.d.ts",
|
|
48
47
|
"module": "dist/client.js",
|
|
@@ -30,7 +30,7 @@ describe("Policy", () => {
|
|
|
30
30
|
objects: [user.ONTOLOGY_TYPE, channel.ONTOLOGY_TYPE],
|
|
31
31
|
actions: "delete",
|
|
32
32
|
});
|
|
33
|
-
expect(policy.key).
|
|
33
|
+
expect(policy.key).toBeDefined();
|
|
34
34
|
expect(policy.subjects.length).toEqual(1);
|
|
35
35
|
expect(policy.subjects[0].key).toEqual("");
|
|
36
36
|
expect(policy.subjects[0].type).toEqual(user.ONTOLOGY_TYPE);
|
|
@@ -48,7 +48,7 @@ describe("Policy", () => {
|
|
|
48
48
|
objects: [],
|
|
49
49
|
actions: [],
|
|
50
50
|
});
|
|
51
|
-
expect(policy.key).
|
|
51
|
+
expect(policy.key).toBeDefined();
|
|
52
52
|
expect(policy.subjects).toHaveLength(0);
|
|
53
53
|
expect(policy.objects).toHaveLength(0);
|
|
54
54
|
expect(policy.actions).toHaveLength(0);
|
|
@@ -61,7 +61,7 @@ describe("Policy", () => {
|
|
|
61
61
|
objects: [],
|
|
62
62
|
actions: [],
|
|
63
63
|
});
|
|
64
|
-
expect(policy.key).
|
|
64
|
+
expect(policy.key).toBeDefined();
|
|
65
65
|
expect(policy.subjects.length).toEqual(1);
|
|
66
66
|
expect(policy.subjects[0].key).toEqual("1");
|
|
67
67
|
expect(policy.subjects[0].type).toEqual(user.ONTOLOGY_TYPE);
|
|
@@ -79,7 +79,7 @@ describe("Policy", () => {
|
|
|
79
79
|
objects: { type: channel.ONTOLOGY_TYPE, key: "3" },
|
|
80
80
|
actions: ["delete", "retrieve"],
|
|
81
81
|
});
|
|
82
|
-
expect(policy.key).
|
|
82
|
+
expect(policy.key).toBeDefined();
|
|
83
83
|
expect(policy.subjects.length).toEqual(2);
|
|
84
84
|
expect(policy.subjects[0].key).toEqual("1");
|
|
85
85
|
expect(policy.subjects[0].type).toEqual(user.ONTOLOGY_TYPE);
|
|
@@ -134,7 +134,7 @@ describe("Policy", () => {
|
|
|
134
134
|
},
|
|
135
135
|
]);
|
|
136
136
|
expect(policies.length).toEqual(2);
|
|
137
|
-
expect(policies[0].key).
|
|
137
|
+
expect(policies[0].key).toBeDefined();
|
|
138
138
|
expect(policies[0].subjects.length).toEqual(1);
|
|
139
139
|
expect(policies[0].subjects[0].key).toEqual("");
|
|
140
140
|
expect(policies[0].subjects[0].type).toEqual(user.ONTOLOGY_TYPE);
|
|
@@ -144,7 +144,7 @@ describe("Policy", () => {
|
|
|
144
144
|
expect(policies[0].objects[0].type).toEqual(user.ONTOLOGY_TYPE);
|
|
145
145
|
expect(policies[0].objects[1].type).toEqual(schematic.ONTOLOGY_TYPE);
|
|
146
146
|
expect(policies[0].actions).toEqual(["retrieve"]);
|
|
147
|
-
expect(policies[1].key).
|
|
147
|
+
expect(policies[1].key).toBeDefined();
|
|
148
148
|
expect(policies[1].subjects.length).toEqual(2);
|
|
149
149
|
expect(policies[1].subjects[0].key).toEqual("");
|
|
150
150
|
expect(policies[1].subjects[1].key).toEqual("");
|
package/src/channel/client.ts
CHANGED
|
@@ -237,7 +237,7 @@ export class Client implements AsyncTermSearcher<string, Key, Channel> {
|
|
|
237
237
|
* channel. If this value is specified, the 'rate' parameter will be ignored.
|
|
238
238
|
* @param isIndex - Set to true if the channel is an index channel, and false
|
|
239
239
|
* otherwise. Index channels must have a data type of `DataType.TIMESTAMP`.
|
|
240
|
-
* @returns the created channel. {@
|
|
240
|
+
* @returns the created channel. {@link Channel}
|
|
241
241
|
* @throws {ValidationError} if any of the parameters for creating the channel are
|
|
242
242
|
* invalid.
|
|
243
243
|
*
|
package/src/control/state.ts
CHANGED
|
@@ -47,7 +47,7 @@ export class StateTracker
|
|
|
47
47
|
|
|
48
48
|
constructor(streamer: FrameStreamer) {
|
|
49
49
|
super(streamer, (frame) => {
|
|
50
|
-
const update: Update = this.codec.decode(frame.series[0].
|
|
50
|
+
const update: Update = this.codec.decode(frame.series[0].data);
|
|
51
51
|
this.merge(update);
|
|
52
52
|
return [update.transfers, true];
|
|
53
53
|
});
|
package/src/errors.spec.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
10
|
import { MatchableErrorType } from "@synnaxlabs/freighter/src/errors";
|
|
11
|
+
import { id } from "@synnaxlabs/x";
|
|
12
|
+
import { v4 as uuid } from "uuid";
|
|
11
13
|
import { describe, expect, test } from "vitest";
|
|
12
14
|
|
|
13
15
|
import {
|
|
@@ -24,6 +26,7 @@ import {
|
|
|
24
26
|
UnexpectedError,
|
|
25
27
|
ValidationError,
|
|
26
28
|
} from "@/errors";
|
|
29
|
+
import { newClient } from "@/setupspecs";
|
|
27
30
|
|
|
28
31
|
describe("error", () => {
|
|
29
32
|
describe("type matching", () => {
|
|
@@ -46,3 +49,19 @@ describe("error", () => {
|
|
|
46
49
|
);
|
|
47
50
|
});
|
|
48
51
|
});
|
|
52
|
+
|
|
53
|
+
const client = newClient();
|
|
54
|
+
|
|
55
|
+
test("client", async () => {
|
|
56
|
+
expect.assertions(2);
|
|
57
|
+
try {
|
|
58
|
+
await client.channels.retrieve(id.id());
|
|
59
|
+
} catch (e) {
|
|
60
|
+
expect(NotFoundError.matches(e)).toBe(true);
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
await client.workspaces.schematic.retrieve(uuid());
|
|
64
|
+
} catch (e) {
|
|
65
|
+
expect(NotFoundError.matches(e)).toBe(true);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
@@ -259,7 +259,7 @@ export const ZERO_AI_ACCEL_CHAN: AIAccelChan = {
|
|
|
259
259
|
};
|
|
260
260
|
|
|
261
261
|
// 2 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaiaccel4wiredcvoltagechan.html
|
|
262
|
-
const aiAccel4WireDCVoltageChanZ = baseAiAccelChanZ.extend({
|
|
262
|
+
export const aiAccel4WireDCVoltageChanZ = baseAiAccelChanZ.extend({
|
|
263
263
|
type: z.literal("ai_accel_4_wire_dc_voltage"),
|
|
264
264
|
units: accelerationUnitsZ,
|
|
265
265
|
voltageExcitSource: excitSourceZ,
|
|
@@ -290,7 +290,7 @@ export const ZERO_AI_ACCEL_4WIRE_DC_VOLTAGE_CHAN: AIAccel4WireDCVoltageChan = {
|
|
|
290
290
|
};
|
|
291
291
|
|
|
292
292
|
// 3 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaiaccelchargechan.html
|
|
293
|
-
const aiAccelChargeChanZ = baseAiAccelChanZ.extend({
|
|
293
|
+
export const aiAccelChargeChanZ = baseAiAccelChanZ.extend({
|
|
294
294
|
type: z.literal("ai_accel_charge"),
|
|
295
295
|
units: accelerationUnitsZ,
|
|
296
296
|
customScale: scaleZ,
|
|
@@ -354,7 +354,7 @@ export const ZERO_AI_BRIDGE_CHAN: AIBridgeChan = {
|
|
|
354
354
|
};
|
|
355
355
|
|
|
356
356
|
// 5 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaichargechan.html
|
|
357
|
-
const aiChargeChan = baseAIChanZ.extend({
|
|
357
|
+
export const aiChargeChan = baseAIChanZ.extend({
|
|
358
358
|
type: z.literal("ai_charge"),
|
|
359
359
|
terminalConfig: terminalConfigZ,
|
|
360
360
|
minVal: z.number(),
|
|
@@ -420,7 +420,7 @@ export const ZERO_AI_CURRENT_CHAN: AICurrentChan = {
|
|
|
420
420
|
};
|
|
421
421
|
|
|
422
422
|
// 7 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaicurrentrmschan.html
|
|
423
|
-
const aiCurrentRMSChanZ = baseAIChanZ.extend({
|
|
423
|
+
export const aiCurrentRMSChanZ = baseAIChanZ.extend({
|
|
424
424
|
type: z.literal("ai_current_rms"),
|
|
425
425
|
terminalConfig: terminalConfigZ,
|
|
426
426
|
minVal: z.number(),
|
|
@@ -450,7 +450,7 @@ export const ZERO_AI_CURRENT_RMS_CHAN: AICurrentRMSChan = {
|
|
|
450
450
|
};
|
|
451
451
|
|
|
452
452
|
// 8 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaiforcebridgepolynomialchan.html
|
|
453
|
-
const aiForceBridgePolynomialChanZ = baseAIChanZ.extend({
|
|
453
|
+
export const aiForceBridgePolynomialChanZ = baseAIChanZ.extend({
|
|
454
454
|
type: z.literal("ai_force_bridge_polynomial"),
|
|
455
455
|
terminalConfig: terminalConfigZ,
|
|
456
456
|
minVal: z.number(),
|
|
@@ -612,7 +612,7 @@ export const ZERO_AI_FORCE_IEPE_CHAN: AIForceEPEChan = {
|
|
|
612
612
|
};
|
|
613
613
|
|
|
614
614
|
// 12 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaifreqvoltagechan.html
|
|
615
|
-
const aiFreqVoltageChanZ = baseAIChanZ.extend({
|
|
615
|
+
export const aiFreqVoltageChanZ = baseAIChanZ.extend({
|
|
616
616
|
type: z.literal("ai_freq_voltage"),
|
|
617
617
|
minVal: z.number(),
|
|
618
618
|
maxVal: z.number(),
|
|
@@ -673,7 +673,7 @@ export const pressureUnitsZ = z.enum(["PoundsPerSquareInch", "Pascals", "Bar"]);
|
|
|
673
673
|
export type PressureUnits = z.infer<typeof pressureUnitsZ>;
|
|
674
674
|
|
|
675
675
|
// 14 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaipressurebridgepolynomialchan.html
|
|
676
|
-
const aiPressureBridgePolynomialChanZ = baseAIChanZ.extend({
|
|
676
|
+
export const aiPressureBridgePolynomialChanZ = baseAIChanZ.extend({
|
|
677
677
|
type: z.literal("ai_pressure_bridge_polynomial"),
|
|
678
678
|
minVal: z.number(),
|
|
679
679
|
maxVal: z.number(),
|
|
@@ -839,7 +839,7 @@ export const ZERO_AI_RESISTANCE_CHAN: AIResistanceChan = {
|
|
|
839
839
|
};
|
|
840
840
|
|
|
841
841
|
// 18 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateairosettestraingagechan.html
|
|
842
|
-
const aiRosetteStrainGageChanZ = baseAIChanZ.extend({
|
|
842
|
+
export const aiRosetteStrainGageChanZ = baseAIChanZ.extend({
|
|
843
843
|
type: z.literal("ai_rosette_strain_gage"),
|
|
844
844
|
terminalConfig: terminalConfigZ,
|
|
845
845
|
minVal: z.number(),
|
|
@@ -1065,7 +1065,7 @@ export const ZERO_AI_THERMOCOUPLE_CHAN: AIThermocoupleChan = {
|
|
|
1065
1065
|
};
|
|
1066
1066
|
|
|
1067
1067
|
// 23 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaithrmstrchaniex.html
|
|
1068
|
-
const aiThermistorChanIex = baseAIChanZ.extend({
|
|
1068
|
+
export const aiThermistorChanIex = baseAIChanZ.extend({
|
|
1069
1069
|
key: z.string(),
|
|
1070
1070
|
type: z.literal("ai_thermistor_iex"),
|
|
1071
1071
|
minVal: z.number(),
|
|
@@ -1100,7 +1100,7 @@ export const ZERO_AI_THERMISTOR_CHAN_IEX: AIThermistorChanIex = {
|
|
|
1100
1100
|
};
|
|
1101
1101
|
|
|
1102
1102
|
// 24 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaitorquebridgepolynomialchan.html
|
|
1103
|
-
const aiThermistorChanVex = baseAIChanZ.extend({
|
|
1103
|
+
export const aiThermistorChanVex = baseAIChanZ.extend({
|
|
1104
1104
|
key: z.string(),
|
|
1105
1105
|
type: z.literal("ai_thermistor_vex"),
|
|
1106
1106
|
minVal: z.number(),
|
|
@@ -1140,7 +1140,7 @@ export const torqueUnitsZ = z.enum(["NewtonMeters", "InchOunces", "FootPounds"])
|
|
|
1140
1140
|
export type TorqueUnits = z.infer<typeof torqueUnitsZ>;
|
|
1141
1141
|
|
|
1142
1142
|
// 25 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaitorquebridgepolynomialchan.html
|
|
1143
|
-
const aiTorqueBridgePolynomialChanZ = baseAIChanZ.extend({
|
|
1143
|
+
export const aiTorqueBridgePolynomialChanZ = baseAIChanZ.extend({
|
|
1144
1144
|
key: z.string(),
|
|
1145
1145
|
type: z.literal("ai_torque_bridge_polynomial"),
|
|
1146
1146
|
minVal: z.number(),
|
|
@@ -1345,7 +1345,7 @@ export const ZERO_AI_VOLTAGE_CHAN: AIVoltageChan = {
|
|
|
1345
1345
|
};
|
|
1346
1346
|
|
|
1347
1347
|
// 30 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaivoltagermschan.html
|
|
1348
|
-
const aiVoltageRMSChanZ = baseAIChanZ.extend({
|
|
1348
|
+
export const aiVoltageRMSChanZ = baseAIChanZ.extend({
|
|
1349
1349
|
key: z.string(),
|
|
1350
1350
|
type: z.literal("ai_voltage_rms"),
|
|
1351
1351
|
terminalConfig: terminalConfigZ,
|
|
@@ -1372,7 +1372,7 @@ export const ZERO_AI_VOLTAGE_RMS_CHAN: AIVoltageRMSChan = {
|
|
|
1372
1372
|
};
|
|
1373
1373
|
|
|
1374
1374
|
// 31 - https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxcreateaivoltagechanwithexcit.html
|
|
1375
|
-
const aiVoltageChanWithExcitZ = baseAIChanZ.extend({
|
|
1375
|
+
export const aiVoltageChanWithExcitZ = baseAIChanZ.extend({
|
|
1376
1376
|
type: z.literal("ai_voltage_with_excit"),
|
|
1377
1377
|
terminalConfig: terminalConfigZ,
|
|
1378
1378
|
minVal: z.number(),
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
export { access } from "@/access";
|
|
11
11
|
export { policy } from "@/access/policy";
|
|
12
|
-
export
|
|
12
|
+
export { channel } from "@/channel";
|
|
13
13
|
export { Channel } from "@/channel/client";
|
|
14
14
|
export { default as Synnax, type SynnaxProps, synnaxPropsZ } from "@/client";
|
|
15
15
|
export * from "@/connection";
|
|
@@ -37,6 +37,7 @@ export { signals } from "@/signals";
|
|
|
37
37
|
export { user } from "@/user";
|
|
38
38
|
export { workspace } from "@/workspace";
|
|
39
39
|
export { linePlot } from "@/workspace/lineplot";
|
|
40
|
+
export { log } from "@/workspace/log";
|
|
40
41
|
export { schematic } from "@/workspace/schematic";
|
|
41
42
|
export {
|
|
42
43
|
type CrudeDataType,
|
|
@@ -48,7 +49,6 @@ export {
|
|
|
48
49
|
DataType,
|
|
49
50
|
Density,
|
|
50
51
|
MultiSeries,
|
|
51
|
-
type NumericTelemValue,
|
|
52
52
|
Rate,
|
|
53
53
|
Series,
|
|
54
54
|
type TelemValue,
|
package/src/ontology/client.ts
CHANGED
|
@@ -214,7 +214,7 @@ export class Client implements AsyncTermSearcher<string, string, Resource> {
|
|
|
214
214
|
/**
|
|
215
215
|
* Opens an observable that can be used to subscribe to changes in both the ontology's
|
|
216
216
|
* resources and relationships.
|
|
217
|
-
* @
|
|
217
|
+
* @link ChangeTracker for more information.
|
|
218
218
|
* @returns An observable that emits changes to the ontology's resources and relationships.
|
|
219
219
|
*/
|
|
220
220
|
async openChangeTracker(): Promise<ChangeTracker> {
|
package/src/ontology/payload.ts
CHANGED
package/src/workspace/client.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { type UnknownRecord } from "@synnaxlabs/x/record";
|
|
|
12
12
|
import { type AsyncTermSearcher } from "@synnaxlabs/x/search";
|
|
13
13
|
|
|
14
14
|
import { linePlot } from "@/workspace/lineplot";
|
|
15
|
+
import { log } from "@/workspace/log";
|
|
15
16
|
import { type Key, type Workspace } from "@/workspace/payload";
|
|
16
17
|
import { Retriever } from "@/workspace/retriever";
|
|
17
18
|
import { schematic } from "@/workspace/schematic";
|
|
@@ -21,6 +22,7 @@ export class Client implements AsyncTermSearcher<string, Key, Workspace> {
|
|
|
21
22
|
readonly type = "workspace";
|
|
22
23
|
readonly schematic: schematic.Client;
|
|
23
24
|
readonly linePlot: linePlot.Client;
|
|
25
|
+
readonly log: log.Client;
|
|
24
26
|
private readonly retriever: Retriever;
|
|
25
27
|
private readonly writer: Writer;
|
|
26
28
|
|
|
@@ -28,6 +30,7 @@ export class Client implements AsyncTermSearcher<string, Key, Workspace> {
|
|
|
28
30
|
this.schematic = new schematic.Client(client);
|
|
29
31
|
this.linePlot = new linePlot.Client(client);
|
|
30
32
|
this.retriever = new Retriever(client);
|
|
33
|
+
this.log = new log.Client(client);
|
|
31
34
|
this.writer = new Writer(client);
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright 2024 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { type UnknownRecord } from "@synnaxlabs/x/record";
|
|
12
|
+
|
|
13
|
+
import { type Key, type Log, type Params } from "@/workspace/log/payload";
|
|
14
|
+
import { Retriever } from "@/workspace/log/retriever";
|
|
15
|
+
import { type NewLog, Writer } from "@/workspace/log/writer";
|
|
16
|
+
|
|
17
|
+
export class Client {
|
|
18
|
+
private readonly writer: Writer;
|
|
19
|
+
private readonly retriever: Retriever;
|
|
20
|
+
|
|
21
|
+
constructor(client: UnaryClient) {
|
|
22
|
+
this.writer = new Writer(client);
|
|
23
|
+
this.retriever = new Retriever(client);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async create(workspace: string, log: NewLog): Promise<Log> {
|
|
27
|
+
return await this.writer.create(workspace, log);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async rename(key: Key, name: string): Promise<void> {
|
|
31
|
+
await this.writer.rename(key, name);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async setData(key: Key, data: UnknownRecord): Promise<void> {
|
|
35
|
+
await this.writer.setData(key, data);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async retrieve(key: Key): Promise<Log>;
|
|
39
|
+
|
|
40
|
+
async retrieve(keys: Key[]): Promise<Log[]>;
|
|
41
|
+
|
|
42
|
+
async retrieve(keys: Params): Promise<Log | Log[]> {
|
|
43
|
+
const isMany = Array.isArray(keys);
|
|
44
|
+
const res = await this.retriever.retrieve(keys);
|
|
45
|
+
return isMany ? res : res[0];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async delete(keys: Params): Promise<void> {
|
|
49
|
+
await this.writer.delete(keys);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright 2024 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
export * from "@/workspace/log/client";
|
|
11
|
+
export * from "@/workspace/log/payload";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2024 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
export * as log from "@/workspace/log/external";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright 2024 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { describe, expect, test } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { newClient } from "@/setupspecs";
|
|
13
|
+
|
|
14
|
+
const client = newClient();
|
|
15
|
+
|
|
16
|
+
const ZERO_UUID = "00000000-0000-0000-0000-000000000000";
|
|
17
|
+
|
|
18
|
+
describe("Log", () => {
|
|
19
|
+
describe("create", () => {
|
|
20
|
+
test("create one", async () => {
|
|
21
|
+
const ws = await client.workspaces.create({
|
|
22
|
+
name: "Log",
|
|
23
|
+
layout: { one: 1 },
|
|
24
|
+
});
|
|
25
|
+
const log = await client.workspaces.log.create(ws.key, {
|
|
26
|
+
name: "Log",
|
|
27
|
+
data: { one: 1 },
|
|
28
|
+
});
|
|
29
|
+
expect(log.name).toEqual("Log");
|
|
30
|
+
expect(log.key).not.toEqual(ZERO_UUID);
|
|
31
|
+
expect(log.data.one).toEqual(1);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe("rename", () => {
|
|
35
|
+
test("rename one", async () => {
|
|
36
|
+
const ws = await client.workspaces.create({
|
|
37
|
+
name: "Log",
|
|
38
|
+
layout: { one: 1 },
|
|
39
|
+
});
|
|
40
|
+
const log = await client.workspaces.log.create(ws.key, {
|
|
41
|
+
name: "Log",
|
|
42
|
+
data: { one: 1 },
|
|
43
|
+
});
|
|
44
|
+
await client.workspaces.log.rename(log.key, "Log2");
|
|
45
|
+
const res = await client.workspaces.log.retrieve(log.key);
|
|
46
|
+
expect(res.name).toEqual("Log2");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe("setData", () => {
|
|
50
|
+
test("set data", async () => {
|
|
51
|
+
const ws = await client.workspaces.create({
|
|
52
|
+
name: "Log",
|
|
53
|
+
layout: { one: 1 },
|
|
54
|
+
});
|
|
55
|
+
const log = await client.workspaces.log.create(ws.key, {
|
|
56
|
+
name: "Log",
|
|
57
|
+
data: { one: 1 },
|
|
58
|
+
});
|
|
59
|
+
await client.workspaces.log.setData(log.key, { two: 2 });
|
|
60
|
+
const res = await client.workspaces.log.retrieve(log.key);
|
|
61
|
+
expect(res.data.two).toEqual(2);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe("delete", () => {
|
|
65
|
+
test("delete one", async () => {
|
|
66
|
+
const ws = await client.workspaces.create({
|
|
67
|
+
name: "Log",
|
|
68
|
+
layout: { one: 1 },
|
|
69
|
+
});
|
|
70
|
+
const log = await client.workspaces.log.create(ws.key, {
|
|
71
|
+
name: "Log",
|
|
72
|
+
data: { one: 1 },
|
|
73
|
+
});
|
|
74
|
+
await client.workspaces.log.delete(log.key);
|
|
75
|
+
await expect(client.workspaces.log.retrieve(log.key)).rejects.toThrow();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Copyright 2024 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { type UnknownRecord, unknownRecordZ } from "@synnaxlabs/x/record";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
import { ontology } from "@/ontology";
|
|
14
|
+
|
|
15
|
+
export const keyZ = z.string().uuid();
|
|
16
|
+
export type Key = z.infer<typeof keyZ>;
|
|
17
|
+
export type Params = Key | Key[];
|
|
18
|
+
|
|
19
|
+
export const logZ = z.object({
|
|
20
|
+
key: z.string(),
|
|
21
|
+
name: z.string(),
|
|
22
|
+
data: unknownRecordZ.or(z.string().transform((s) => JSON.parse(s) as UnknownRecord)),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const logRemoteZ = z.object({
|
|
26
|
+
key: z.string(),
|
|
27
|
+
name: z.string(),
|
|
28
|
+
data: z.string().transform((s) => JSON.parse(s) as UnknownRecord),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type Log = z.infer<typeof logZ>;
|
|
32
|
+
|
|
33
|
+
export const ONTOLOGY_TYPE: ontology.ResourceType = "log";
|
|
34
|
+
|
|
35
|
+
export const ontologyID = (key: Key): ontology.ID =>
|
|
36
|
+
new ontology.ID({ type: ONTOLOGY_TYPE, key: key });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright 2024 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { toArray } from "@synnaxlabs/x/toArray";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
import { type Log, logRemoteZ, type Params } from "@/workspace/log/payload";
|
|
15
|
+
|
|
16
|
+
const reqZ = z.object({ keys: z.string().array() });
|
|
17
|
+
const resZ = z.object({ logs: logRemoteZ.array() });
|
|
18
|
+
|
|
19
|
+
export class Retriever {
|
|
20
|
+
private readonly ENDPOINT = "/workspace/log/retrieve";
|
|
21
|
+
private readonly client: UnaryClient;
|
|
22
|
+
|
|
23
|
+
constructor(client: UnaryClient) {
|
|
24
|
+
this.client = client;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async retrieve(logs: Params): Promise<Log[]> {
|
|
28
|
+
return (
|
|
29
|
+
await sendRequired(
|
|
30
|
+
this.client,
|
|
31
|
+
this.ENDPOINT,
|
|
32
|
+
{ keys: toArray(logs) },
|
|
33
|
+
reqZ,
|
|
34
|
+
resZ,
|
|
35
|
+
)
|
|
36
|
+
).logs;
|
|
37
|
+
}
|
|
38
|
+
}
|