@synnaxlabs/client 0.53.1 → 0.54.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 +14 -8
- package/dist/client.cjs +48 -54
- package/dist/client.js +12360 -15508
- package/dist/src/access/action/index.d.ts +2 -0
- package/dist/src/access/action/index.d.ts.map +1 -0
- package/dist/src/access/{payload.d.ts → action/types.gen.d.ts} +2 -1
- package/dist/src/access/action/types.gen.d.ts.map +1 -0
- package/dist/src/access/enforce.d.ts +2 -2
- package/dist/src/access/enforce.d.ts.map +1 -1
- package/dist/src/access/external.d.ts +1 -1
- package/dist/src/access/external.d.ts.map +1 -1
- package/dist/src/access/policy/client.d.ts +233 -389
- package/dist/src/access/policy/client.d.ts.map +1 -1
- package/dist/src/access/policy/external.d.ts +1 -1
- package/dist/src/access/policy/external.d.ts.map +1 -1
- package/dist/src/access/policy/types.gen.d.ts +120 -0
- package/dist/src/access/policy/types.gen.d.ts.map +1 -0
- package/dist/src/access/role/client.d.ts +1 -1
- package/dist/src/access/role/client.d.ts.map +1 -1
- package/dist/src/access/role/external.d.ts +1 -1
- package/dist/src/access/role/external.d.ts.map +1 -1
- package/dist/src/access/role/types.gen.d.ts +34 -0
- package/dist/src/access/role/types.gen.d.ts.map +1 -0
- package/dist/src/arc/client.d.ts +2 -2
- package/dist/src/arc/client.d.ts.map +1 -1
- package/dist/src/arc/compiler/index.d.ts +2 -0
- package/dist/src/arc/compiler/index.d.ts.map +1 -0
- package/dist/src/arc/compiler/types.gen.d.ts +12 -0
- package/dist/src/arc/compiler/types.gen.d.ts.map +1 -0
- package/dist/src/arc/external.d.ts +6 -1
- package/dist/src/arc/external.d.ts.map +1 -1
- package/dist/src/arc/graph/index.d.ts +2 -0
- package/dist/src/arc/graph/index.d.ts.map +1 -0
- package/dist/src/arc/graph/types.gen.d.ts +644 -0
- package/dist/src/arc/graph/types.gen.d.ts.map +1 -0
- package/dist/src/arc/ir/index.d.ts +2 -0
- package/dist/src/arc/ir/index.d.ts.map +1 -0
- package/dist/src/arc/ir/types.gen.d.ts +2988 -0
- package/dist/src/arc/ir/types.gen.d.ts.map +1 -0
- package/dist/src/arc/module/index.d.ts +2 -0
- package/dist/src/arc/module/index.d.ts.map +1 -0
- package/dist/src/arc/module/types.gen.d.ts +1138 -0
- package/dist/src/arc/module/types.gen.d.ts.map +1 -0
- package/dist/src/arc/program/index.d.ts +2 -0
- package/dist/src/arc/program/index.d.ts.map +1 -0
- package/dist/src/arc/program/types.gen.d.ts +1138 -0
- package/dist/src/arc/program/types.gen.d.ts.map +1 -0
- package/dist/src/arc/text/index.d.ts +2 -0
- package/dist/src/arc/text/index.d.ts.map +1 -0
- package/dist/src/arc/text/types.gen.d.ts +8 -0
- package/dist/src/arc/text/types.gen.d.ts.map +1 -0
- package/dist/src/arc/types/index.d.ts +2 -0
- package/dist/src/arc/types/index.d.ts.map +1 -0
- package/dist/src/arc/types/types.gen.d.ts +237 -0
- package/dist/src/arc/types/types.gen.d.ts.map +1 -0
- package/dist/src/arc/types.gen.d.ts +2394 -0
- package/dist/src/arc/types.gen.d.ts.map +1 -0
- package/dist/src/channel/client.d.ts +5 -4
- package/dist/src/channel/client.d.ts.map +1 -1
- package/dist/src/channel/external.d.ts +1 -0
- package/dist/src/channel/external.d.ts.map +1 -1
- package/dist/src/channel/payload.d.ts +93 -178
- package/dist/src/channel/payload.d.ts.map +1 -1
- package/dist/src/channel/retriever.d.ts +3 -2
- package/dist/src/channel/retriever.d.ts.map +1 -1
- package/dist/src/channel/types.gen.d.ts +151 -0
- package/dist/src/channel/types.gen.d.ts.map +1 -0
- package/dist/src/channel/writer.d.ts +1 -1
- package/dist/src/channel/writer.d.ts.map +1 -1
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/cluster/index.d.ts +2 -0
- package/dist/src/cluster/index.d.ts.map +1 -0
- package/dist/src/cluster/types.gen.d.ts +4 -0
- package/dist/src/cluster/types.gen.d.ts.map +1 -0
- package/dist/src/control/state.d.ts +14 -9
- package/dist/src/control/state.d.ts.map +1 -1
- package/dist/src/device/client.d.ts +7 -12
- package/dist/src/device/client.d.ts.map +1 -1
- package/dist/src/device/external.d.ts +1 -1
- package/dist/src/device/external.d.ts.map +1 -1
- package/dist/src/device/types.gen.d.ts +163 -0
- package/dist/src/device/types.gen.d.ts.map +1 -0
- package/dist/src/framer/adapter.d.ts +2 -2
- package/dist/src/framer/adapter.d.ts.map +1 -1
- package/dist/src/framer/client.d.ts +7 -7
- package/dist/src/framer/client.d.ts.map +1 -1
- package/dist/src/framer/codec.d.ts +5 -5
- package/dist/src/framer/codec.d.ts.map +1 -1
- package/dist/src/framer/external.d.ts +1 -1
- package/dist/src/framer/external.d.ts.map +1 -1
- package/dist/src/framer/frame.d.ts +18 -18
- package/dist/src/framer/frame.d.ts.map +1 -1
- package/dist/src/framer/reader.d.ts +1 -1
- package/dist/src/framer/reader.d.ts.map +1 -1
- package/dist/src/framer/streamer.d.ts +177 -114
- package/dist/src/framer/streamer.d.ts.map +1 -1
- package/dist/src/framer/types.gen.d.ts +9 -0
- package/dist/src/framer/types.gen.d.ts.map +1 -0
- package/dist/src/framer/writer.d.ts +192 -128
- package/dist/src/framer/writer.d.ts.map +1 -1
- package/dist/src/group/client.d.ts +17 -17
- package/dist/src/group/client.d.ts.map +1 -1
- package/dist/src/group/external.d.ts +1 -1
- package/dist/src/group/external.d.ts.map +1 -1
- package/dist/src/group/types.gen.d.ts +23 -0
- package/dist/src/group/types.gen.d.ts.map +1 -0
- package/dist/src/label/client.d.ts +51 -72
- package/dist/src/label/client.d.ts.map +1 -1
- package/dist/src/label/payload.d.ts +30 -8
- package/dist/src/label/payload.d.ts.map +1 -1
- package/dist/src/lineplot/client.d.ts +2 -11
- package/dist/src/lineplot/client.d.ts.map +1 -1
- package/dist/src/lineplot/external.d.ts +1 -1
- package/dist/src/lineplot/external.d.ts.map +1 -1
- package/dist/src/lineplot/types.gen.d.ts +33 -0
- package/dist/src/lineplot/types.gen.d.ts.map +1 -0
- package/dist/src/log/client.d.ts +2 -11
- package/dist/src/log/client.d.ts.map +1 -1
- package/dist/src/log/external.d.ts +1 -1
- package/dist/src/log/external.d.ts.map +1 -1
- package/dist/src/log/types.gen.d.ts +33 -0
- package/dist/src/log/types.gen.d.ts.map +1 -0
- package/dist/src/ontology/client.d.ts +31 -31
- package/dist/src/ontology/payload.d.ts +74 -99
- package/dist/src/ontology/payload.d.ts.map +1 -1
- package/dist/src/ontology/types.gen.d.ts +30 -0
- package/dist/src/ontology/types.gen.d.ts.map +1 -0
- package/dist/src/ontology/writer.d.ts +80 -80
- package/dist/src/rack/client.d.ts +22 -11
- package/dist/src/rack/client.d.ts.map +1 -1
- package/dist/src/rack/external.d.ts +1 -1
- package/dist/src/rack/external.d.ts.map +1 -1
- package/dist/src/rack/types.gen.d.ts +72 -0
- package/dist/src/rack/types.gen.d.ts.map +1 -0
- package/dist/src/range/alias/types.gen.d.ts +14 -0
- package/dist/src/range/alias/types.gen.d.ts.map +1 -0
- package/dist/src/range/kv/types.gen.d.ts +13 -0
- package/dist/src/range/kv/types.gen.d.ts.map +1 -0
- package/dist/src/ranger/alias/client.d.ts +1 -1
- package/dist/src/ranger/alias/client.d.ts.map +1 -1
- package/dist/src/ranger/alias/external.d.ts +3 -1
- package/dist/src/ranger/alias/external.d.ts.map +1 -1
- package/dist/src/ranger/alias/payload.d.ts +5 -9
- package/dist/src/ranger/alias/payload.d.ts.map +1 -1
- package/dist/src/ranger/alias/payload.spec.d.ts +2 -0
- package/dist/src/ranger/alias/payload.spec.d.ts.map +1 -0
- package/dist/src/ranger/alias/types.gen.d.ts +14 -0
- package/dist/src/ranger/alias/types.gen.d.ts.map +1 -0
- package/dist/src/ranger/client.d.ts +10 -15
- package/dist/src/ranger/client.d.ts.map +1 -1
- package/dist/src/ranger/external.d.ts +4 -4
- package/dist/src/ranger/external.d.ts.map +1 -1
- package/dist/src/ranger/kv/client.d.ts +1 -1
- package/dist/src/ranger/kv/client.d.ts.map +1 -1
- package/dist/src/ranger/kv/external.d.ts +3 -1
- package/dist/src/ranger/kv/external.d.ts.map +1 -1
- package/dist/src/ranger/kv/payload.d.ts +6 -13
- package/dist/src/ranger/kv/payload.d.ts.map +1 -1
- package/dist/src/ranger/kv/types.gen.d.ts +13 -0
- package/dist/src/ranger/kv/types.gen.d.ts.map +1 -0
- package/dist/src/ranger/payload.d.ts +2 -97
- package/dist/src/ranger/payload.d.ts.map +1 -1
- package/dist/src/ranger/types.gen.d.ts +219 -0
- package/dist/src/ranger/types.gen.d.ts.map +1 -0
- package/dist/src/ranger/writer.d.ts +25 -25
- package/dist/src/ranger/writer.d.ts.map +1 -1
- package/dist/src/schematic/client.d.ts +2 -11
- package/dist/src/schematic/client.d.ts.map +1 -1
- package/dist/src/schematic/external.d.ts +1 -1
- package/dist/src/schematic/external.d.ts.map +1 -1
- package/dist/src/schematic/symbol/client.d.ts +1 -2
- package/dist/src/schematic/symbol/client.d.ts.map +1 -1
- package/dist/src/schematic/symbol/external.d.ts +1 -1
- package/dist/src/schematic/symbol/external.d.ts.map +1 -1
- package/dist/src/schematic/symbol/types.gen.d.ts +277 -0
- package/dist/src/schematic/symbol/types.gen.d.ts.map +1 -0
- package/dist/src/schematic/types.gen.d.ts +35 -0
- package/dist/src/schematic/types.gen.d.ts.map +1 -0
- package/dist/src/status/client.d.ts +2 -0
- package/dist/src/status/client.d.ts.map +1 -1
- package/dist/src/status/payload.d.ts +25 -54
- package/dist/src/status/payload.d.ts.map +1 -1
- package/dist/src/table/client.d.ts +2 -11
- package/dist/src/table/client.d.ts.map +1 -1
- package/dist/src/table/external.d.ts +1 -1
- package/dist/src/table/external.d.ts.map +1 -1
- package/dist/src/table/types.gen.d.ts +33 -0
- package/dist/src/table/types.gen.d.ts.map +1 -0
- package/dist/src/task/client.d.ts +15 -20
- package/dist/src/task/client.d.ts.map +1 -1
- package/dist/src/task/external.d.ts +1 -1
- package/dist/src/task/external.d.ts.map +1 -1
- package/dist/src/task/types.gen.d.ts +155 -0
- package/dist/src/task/types.gen.d.ts.map +1 -0
- package/dist/src/user/client.d.ts +3 -3
- package/dist/src/user/client.d.ts.map +1 -1
- package/dist/src/user/external.d.ts +1 -1
- package/dist/src/user/external.d.ts.map +1 -1
- package/dist/src/user/types.gen.d.ts +35 -0
- package/dist/src/user/types.gen.d.ts.map +1 -0
- package/dist/src/util/decodeJSONString.d.ts.map +1 -1
- package/dist/src/view/client.d.ts +1 -10
- package/dist/src/view/client.d.ts.map +1 -1
- package/dist/src/view/external.d.ts +1 -1
- package/dist/src/view/external.d.ts.map +1 -1
- package/dist/src/view/types.gen.d.ts +35 -0
- package/dist/src/view/types.gen.d.ts.map +1 -0
- package/dist/src/workspace/client.d.ts +2 -11
- package/dist/src/workspace/client.d.ts.map +1 -1
- package/dist/src/workspace/external.d.ts +1 -1
- package/dist/src/workspace/external.d.ts.map +1 -1
- package/dist/src/workspace/types.gen.d.ts +34 -0
- package/dist/src/workspace/types.gen.d.ts.map +1 -0
- package/package.json +11 -11
- package/src/access/action/index.ts +11 -0
- package/src/access/{payload.ts → action/types.gen.ts} +4 -1
- package/src/access/enforce.spec.ts +1 -2
- package/src/access/enforce.ts +2 -2
- package/src/access/external.ts +1 -1
- package/src/access/policy/client.ts +2 -2
- package/src/access/policy/external.ts +1 -1
- package/src/access/policy/types.gen.ts +44 -0
- package/src/access/role/client.ts +2 -2
- package/src/access/role/external.ts +1 -1
- package/src/access/role/types.gen.ts +46 -0
- package/src/arc/access.spec.ts +18 -6
- package/src/arc/client.ts +3 -3
- package/src/{framer/payload.ts → arc/compiler/index.ts} +1 -6
- package/src/arc/compiler/types.gen.ts +27 -0
- package/src/arc/external.ts +6 -1
- package/src/arc/graph/index.ts +10 -0
- package/src/arc/graph/types.gen.ts +59 -0
- package/src/arc/ir/index.ts +10 -0
- package/src/arc/ir/types.gen.ts +166 -0
- package/src/arc/module/index.ts +10 -0
- package/src/arc/module/types.gen.ts +18 -0
- package/src/arc/program/index.ts +10 -0
- package/src/arc/program/types.gen.ts +18 -0
- package/src/arc/text/index.ts +10 -0
- package/src/arc/text/types.gen.ts +19 -0
- package/src/arc/types/index.ts +10 -0
- package/src/arc/types/types.gen.ts +132 -0
- package/src/arc/types.gen.ts +85 -0
- package/src/channel/client.ts +14 -15
- package/src/channel/external.ts +1 -0
- package/src/channel/payload.spec.ts +19 -16
- package/src/channel/payload.ts +14 -82
- package/src/channel/retriever.ts +9 -18
- package/src/channel/types.gen.ts +137 -0
- package/src/channel/writer.ts +2 -2
- package/src/client.ts +4 -0
- package/src/cluster/index.ts +10 -0
- package/src/cluster/types.gen.ts +16 -0
- package/src/control/state.ts +8 -6
- package/src/device/client.ts +14 -11
- package/src/device/device.spec.ts +95 -1
- package/src/device/external.ts +1 -1
- package/src/device/payload.spec.ts +26 -2
- package/src/device/types.gen.ts +100 -0
- package/src/framer/adapter.ts +7 -4
- package/src/framer/client.ts +15 -9
- package/src/framer/codec.spec.ts +25 -5
- package/src/framer/codec.ts +11 -9
- package/src/framer/deleter.spec.ts +0 -15
- package/src/framer/external.ts +1 -1
- package/src/framer/frame.ts +44 -36
- package/src/framer/reader.spec.ts +2 -2
- package/src/framer/reader.ts +6 -6
- package/src/framer/streamer.spec.ts +98 -0
- package/src/framer/streamer.ts +10 -0
- package/src/framer/types.gen.ts +20 -0
- package/src/framer/writer.ts +14 -8
- package/src/group/client.ts +1 -1
- package/src/group/external.ts +1 -1
- package/src/group/group.spec.ts +1 -1
- package/src/{access/role/payload.ts → group/types.gen.ts} +11 -11
- package/src/label/client.ts +2 -5
- package/src/label/label.spec.ts +12 -3
- package/src/label/payload.ts +3 -1
- package/src/lineplot/client.ts +9 -11
- package/src/lineplot/external.ts +1 -1
- package/src/lineplot/lineplot.spec.ts +40 -0
- package/src/lineplot/types.gen.ts +42 -0
- package/src/log/client.ts +9 -18
- package/src/log/external.ts +1 -1
- package/src/log/log.spec.ts +38 -0
- package/src/log/types.gen.ts +42 -0
- package/src/ontology/payload.ts +5 -29
- package/src/ontology/types.gen.ts +41 -0
- package/src/rack/client.ts +26 -10
- package/src/rack/external.ts +1 -1
- package/src/rack/rack.spec.ts +37 -0
- package/src/rack/types.gen.ts +62 -0
- package/src/range/alias/types.gen.ts +30 -0
- package/src/range/kv/types.gen.ts +28 -0
- package/src/ranger/alias/client.ts +1 -1
- package/src/ranger/alias/external.ts +3 -10
- package/src/ranger/alias/payload.spec.ts +52 -0
- package/src/ranger/alias/payload.ts +11 -10
- package/src/ranger/alias/types.gen.ts +30 -0
- package/src/ranger/client.ts +34 -45
- package/src/ranger/external.ts +3 -3
- package/src/ranger/kv/client.ts +3 -3
- package/src/ranger/kv/external.ts +3 -7
- package/src/ranger/kv/payload.ts +1 -6
- package/src/ranger/kv/types.gen.ts +28 -0
- package/src/ranger/payload.ts +2 -46
- package/src/ranger/ranger.spec.ts +2 -4
- package/src/ranger/types.gen.ts +66 -0
- package/src/ranger/writer.ts +2 -1
- package/src/schematic/client.ts +11 -14
- package/src/schematic/external.ts +1 -1
- package/src/schematic/schematic.spec.ts +54 -2
- package/src/schematic/symbol/client.ts +2 -4
- package/src/schematic/symbol/external.ts +1 -1
- package/src/schematic/symbol/types.gen.ts +124 -0
- package/src/schematic/types.gen.ts +44 -0
- package/src/status/client.ts +4 -3
- package/src/status/payload.ts +5 -4
- package/src/status/status.spec.ts +106 -11
- package/src/table/client.ts +10 -19
- package/src/table/external.ts +1 -1
- package/src/table/table.spec.ts +38 -0
- package/src/table/types.gen.ts +42 -0
- package/src/task/client.ts +29 -24
- package/src/task/external.ts +1 -1
- package/src/task/payload.spec.ts +19 -19
- package/src/task/task.spec.ts +127 -9
- package/src/task/types.gen.ts +169 -0
- package/src/user/client.ts +2 -2
- package/src/user/external.ts +1 -1
- package/src/user/types.gen.ts +49 -0
- package/src/util/decodeJSONString.ts +1 -1
- package/src/util/retrieve.ts +2 -2
- package/src/view/client.ts +2 -7
- package/src/view/external.ts +1 -1
- package/src/view/types.gen.ts +44 -0
- package/src/workspace/client.ts +10 -14
- package/src/workspace/external.ts +1 -1
- package/src/workspace/types.gen.ts +45 -0
- package/src/workspace/workspace.spec.ts +37 -0
- package/tsconfig.json +1 -3
- package/vite.config.ts +9 -2
- package/dist/src/access/payload.d.ts.map +0 -1
- package/dist/src/access/policy/payload.d.ts +0 -156
- package/dist/src/access/policy/payload.d.ts.map +0 -1
- package/dist/src/access/role/payload.d.ts +0 -27
- package/dist/src/access/role/payload.d.ts.map +0 -1
- package/dist/src/arc/payload.d.ts +0 -167
- package/dist/src/arc/payload.d.ts.map +0 -1
- package/dist/src/device/payload.d.ts +0 -281
- package/dist/src/device/payload.d.ts.map +0 -1
- package/dist/src/framer/payload.d.ts +0 -7
- package/dist/src/framer/payload.d.ts.map +0 -1
- package/dist/src/group/payload.d.ts +0 -16
- package/dist/src/group/payload.d.ts.map +0 -1
- package/dist/src/lineplot/payload.d.ts +0 -28
- package/dist/src/lineplot/payload.d.ts.map +0 -1
- package/dist/src/log/payload.d.ts +0 -28
- package/dist/src/log/payload.d.ts.map +0 -1
- package/dist/src/rack/payload.d.ts +0 -243
- package/dist/src/rack/payload.d.ts.map +0 -1
- package/dist/src/schematic/payload.d.ts +0 -38
- package/dist/src/schematic/payload.d.ts.map +0 -1
- package/dist/src/schematic/symbol/payload.d.ts +0 -169
- package/dist/src/schematic/symbol/payload.d.ts.map +0 -1
- package/dist/src/table/payload.d.ts +0 -33
- package/dist/src/table/payload.d.ts.map +0 -1
- package/dist/src/task/payload.d.ts +0 -123
- package/dist/src/task/payload.d.ts.map +0 -1
- package/dist/src/user/payload.d.ts +0 -22
- package/dist/src/user/payload.d.ts.map +0 -1
- package/dist/src/view/payload.d.ts +0 -20
- package/dist/src/view/payload.d.ts.map +0 -1
- package/dist/src/workspace/payload.d.ts +0 -33
- package/dist/src/workspace/payload.d.ts.map +0 -1
- package/src/access/policy/payload.ts +0 -37
- package/src/arc/payload.ts +0 -73
- package/src/device/payload.ts +0 -83
- package/src/group/payload.ts +0 -24
- package/src/lineplot/payload.ts +0 -29
- package/src/log/payload.ts +0 -29
- package/src/rack/payload.ts +0 -30
- package/src/schematic/payload.ts +0 -34
- package/src/schematic/symbol/payload.ts +0 -70
- package/src/table/payload.ts +0 -33
- package/src/task/payload.ts +0 -127
- package/src/user/payload.ts +0 -29
- package/src/view/payload.ts +0 -25
- package/src/workspace/payload.ts +0 -33
package/src/channel/retriever.ts
CHANGED
|
@@ -12,19 +12,10 @@ import { array, DataType, debounce, zod } from "@synnaxlabs/x";
|
|
|
12
12
|
import { Mutex } from "async-mutex";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
type KeyOrName,
|
|
18
|
-
type Keys,
|
|
19
|
-
type KeysOrNames,
|
|
20
|
-
keyZ,
|
|
21
|
-
type Params,
|
|
22
|
-
type Payload,
|
|
23
|
-
payloadZ,
|
|
24
|
-
type PrimitiveParams,
|
|
25
|
-
} from "@/channel/payload";
|
|
15
|
+
import { type Params, type PrimitiveParams } from "@/channel/payload";
|
|
16
|
+
import { type Key, keyZ, type Name, type Payload, payloadZ } from "@/channel/types.gen";
|
|
26
17
|
import { QueryError } from "@/errors";
|
|
27
|
-
import { keyZ as rangeKeyZ } from "@/ranger/
|
|
18
|
+
import { keyZ as rangeKeyZ } from "@/ranger/types.gen";
|
|
28
19
|
import {
|
|
29
20
|
analyzeParams as analyzeParameters,
|
|
30
21
|
type ParamAnalysisResult,
|
|
@@ -53,11 +44,11 @@ export interface RetrieveOptions extends Omit<
|
|
|
53
44
|
> {}
|
|
54
45
|
export interface PageOptions extends Omit<RetrieveOptions, "offset" | "limit"> {}
|
|
55
46
|
|
|
56
|
-
const resZ = z.object({ channels: array.
|
|
47
|
+
const resZ = z.object({ channels: array.nullishToEmpty(payloadZ) });
|
|
57
48
|
|
|
58
49
|
export const analyzeParams = (
|
|
59
50
|
channels: Params,
|
|
60
|
-
): ParamAnalysisResult<
|
|
51
|
+
): ParamAnalysisResult<Key | Name, { number: "keys"; string: "names" }> => {
|
|
61
52
|
if (Array.isArray(channels) && channels.length > 0 && typeof channels[0] === "object")
|
|
62
53
|
channels = (channels as Payload[]).map((c) => c.key);
|
|
63
54
|
else if (typeof channels === "object" && "key" in channels) channels = [channels.key];
|
|
@@ -125,7 +116,7 @@ export class CacheRetriever implements Retriever {
|
|
|
125
116
|
return await this.wrapped.retrieve(channels);
|
|
126
117
|
const { normalized } = analyzeParams(channels);
|
|
127
118
|
const results: Payload[] = [];
|
|
128
|
-
const toFetch:
|
|
119
|
+
const toFetch: Key[] | Name[] = [];
|
|
129
120
|
normalized.forEach((keyOrName) => {
|
|
130
121
|
const c = this.get(keyOrName);
|
|
131
122
|
if (c != null) results.push(...c);
|
|
@@ -183,7 +174,7 @@ export class CacheRetriever implements Retriever {
|
|
|
183
174
|
});
|
|
184
175
|
}
|
|
185
176
|
|
|
186
|
-
private get(channel:
|
|
177
|
+
private get(channel: Key | Name): Payload[] | undefined {
|
|
187
178
|
if (typeof channel === "number") {
|
|
188
179
|
const ch = this.cache.get(channel);
|
|
189
180
|
if (ch == null) return undefined;
|
|
@@ -209,7 +200,7 @@ export interface PromiseFns<T> {
|
|
|
209
200
|
// no interval
|
|
210
201
|
export class DebouncedBatchRetriever implements Retriever {
|
|
211
202
|
private readonly mu = new Mutex();
|
|
212
|
-
private readonly requests = new Map<
|
|
203
|
+
private readonly requests = new Map<Key[], PromiseFns<Payload[]>>();
|
|
213
204
|
private readonly wrapped: Retriever;
|
|
214
205
|
private readonly debouncedRun: () => void;
|
|
215
206
|
|
|
@@ -260,7 +251,7 @@ export const retrieveRequired = async (
|
|
|
260
251
|
): Promise<Payload[]> => {
|
|
261
252
|
const { normalized } = analyzeParams(channels);
|
|
262
253
|
const results = await r.retrieve(normalized);
|
|
263
|
-
const notFound:
|
|
254
|
+
const notFound: (Key | Name)[] = [];
|
|
264
255
|
normalized.forEach((v) => {
|
|
265
256
|
if (results.find((c) => c.name === v || c.key === v) == null) notFound.push(v);
|
|
266
257
|
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Copyright 2026 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
|
+
// Code generated by Oracle. DO NOT EDIT.
|
|
11
|
+
|
|
12
|
+
import { control, status, telem, TimeSpan, zod } from "@synnaxlabs/x";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
15
|
+
import { cluster } from "@/cluster";
|
|
16
|
+
import { ontology } from "@/ontology";
|
|
17
|
+
|
|
18
|
+
export const keyZ = z.uint32().or(
|
|
19
|
+
z
|
|
20
|
+
.string()
|
|
21
|
+
.refine((v) => !isNaN(Number(v)))
|
|
22
|
+
.transform(Number),
|
|
23
|
+
);
|
|
24
|
+
export type Key = z.infer<typeof keyZ>;
|
|
25
|
+
|
|
26
|
+
export const localKeyZ = zod.uint20;
|
|
27
|
+
export type LocalKey = z.infer<typeof localKeyZ>;
|
|
28
|
+
|
|
29
|
+
export const OPERATION_TYPES = ["min", "max", "avg", "none"] as const;
|
|
30
|
+
export const operationTypeZ = z.enum(OPERATION_TYPES);
|
|
31
|
+
export type OperationType = z.infer<typeof operationTypeZ>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Operation defines an aggregation operation applied to channel data. Operations
|
|
35
|
+
* calculate min, max, or average values over a time duration or triggered
|
|
36
|
+
* by a reset channel.
|
|
37
|
+
*/
|
|
38
|
+
export const operationZ = z.object({
|
|
39
|
+
/** type is the aggregation operation type: min, max, avg, or none. */
|
|
40
|
+
type: operationTypeZ,
|
|
41
|
+
/**
|
|
42
|
+
* resetChannel is the channel key that triggers reset of the aggregation. If 0,
|
|
43
|
+
* duration-based reset is used.
|
|
44
|
+
*/
|
|
45
|
+
resetChannel: keyZ.default(0),
|
|
46
|
+
/** duration is the time window for aggregation when reset_channel is 0. */
|
|
47
|
+
duration: telem.timeSpanZ.default(TimeSpan.ZERO),
|
|
48
|
+
});
|
|
49
|
+
export interface Operation extends z.infer<typeof operationZ> {}
|
|
50
|
+
|
|
51
|
+
export const nameZ = z.string().min(1, "Name is required");
|
|
52
|
+
export type Name = z.infer<typeof nameZ>;
|
|
53
|
+
|
|
54
|
+
export const statusZ = status.statusZ();
|
|
55
|
+
export type Status = z.infer<typeof statusZ>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Payload is a logical collection of samples emitted by or representing values
|
|
59
|
+
* from a single source. Channels are the fundamental unit of telemetry
|
|
60
|
+
* storage and streaming in Synnax.
|
|
61
|
+
*/
|
|
62
|
+
export const payloadZ = z.object({
|
|
63
|
+
/**
|
|
64
|
+
* key is the unique identifier for this channel, automatically assigned
|
|
65
|
+
* by Synnax.
|
|
66
|
+
*/
|
|
67
|
+
key: keyZ,
|
|
68
|
+
/** name is the human-readable channel name. */
|
|
69
|
+
name: nameZ,
|
|
70
|
+
/**
|
|
71
|
+
* leaseholder is the cluster node that holds the lease for this channel. Mostly
|
|
72
|
+
* for internal use.
|
|
73
|
+
*/
|
|
74
|
+
leaseholder: cluster.nodeKeyZ,
|
|
75
|
+
/**
|
|
76
|
+
* dataType is the data type of samples stored in this channel (e.g., Float64,
|
|
77
|
+
* Int32, TimeStamp).
|
|
78
|
+
*/
|
|
79
|
+
dataType: telem.dataTypeZ,
|
|
80
|
+
/**
|
|
81
|
+
* isIndex is true if this is an index channel. Index channels must have int64
|
|
82
|
+
* values (TIMESTAMP data type) written in ascending order, and are
|
|
83
|
+
* most commonly unix nanosecond timestamps.
|
|
84
|
+
*/
|
|
85
|
+
isIndex: z.boolean(),
|
|
86
|
+
/**
|
|
87
|
+
* index is the channel used to index this channel's values, associating
|
|
88
|
+
* each value with a timestamp. If zero, the channel's data will be
|
|
89
|
+
* indexed using its rate.
|
|
90
|
+
*/
|
|
91
|
+
index: keyZ,
|
|
92
|
+
/** alias is an optional alternate name for the channel within a specific context. */
|
|
93
|
+
alias: z.string().optional(),
|
|
94
|
+
/**
|
|
95
|
+
* virtual is true if this channel does not store data in the database but can
|
|
96
|
+
* still be used for streaming purposes.
|
|
97
|
+
*/
|
|
98
|
+
virtual: z.boolean().default(false),
|
|
99
|
+
/** internal is true if this is a system channel hidden from normal user queries. */
|
|
100
|
+
internal: z.boolean().default(false),
|
|
101
|
+
/**
|
|
102
|
+
* expression is an Arc expression for calculated channels. If set, the channel
|
|
103
|
+
* is automatically configured as virtual.
|
|
104
|
+
*/
|
|
105
|
+
expression: z.string().default(""),
|
|
106
|
+
/**
|
|
107
|
+
* operations contains optional aggregation operations (min, max, avg) applied to
|
|
108
|
+
* channel data over time or triggered by a reset channel.
|
|
109
|
+
*/
|
|
110
|
+
operations: zod.nullToUndefined(operationZ.array()),
|
|
111
|
+
/**
|
|
112
|
+
* concurrency sets the policy for concurrent writes to the channel's data. Only
|
|
113
|
+
* virtual channels can have a policy of shared concurrency.
|
|
114
|
+
*/
|
|
115
|
+
concurrency: control.concurrencyZ.default(control.Concurrency.exclusive).optional(),
|
|
116
|
+
/** status is the current operational status of the channel. */
|
|
117
|
+
status: statusZ.optional(),
|
|
118
|
+
});
|
|
119
|
+
export interface Payload extends z.infer<typeof payloadZ> {}
|
|
120
|
+
|
|
121
|
+
export const newZ = payloadZ
|
|
122
|
+
.omit({ leaseholder: true })
|
|
123
|
+
.partial({
|
|
124
|
+
key: true,
|
|
125
|
+
index: true,
|
|
126
|
+
isIndex: true,
|
|
127
|
+
internal: true,
|
|
128
|
+
virtual: true,
|
|
129
|
+
expression: true,
|
|
130
|
+
})
|
|
131
|
+
.extend({
|
|
132
|
+
leaseholder: zod.uint12.optional(),
|
|
133
|
+
});
|
|
134
|
+
export interface New extends z.input<typeof newZ> {}
|
|
135
|
+
|
|
136
|
+
export const ontologyID = ontology.createIDFactory<Key>("channel");
|
|
137
|
+
export const TYPE_ONTOLOGY_ID = ontologyID(0);
|
package/src/channel/writer.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
|
11
11
|
import { type DataType } from "@synnaxlabs/x";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
|
|
14
|
+
import { type CacheRetriever } from "@/channel/retriever";
|
|
14
15
|
import {
|
|
15
16
|
type Key,
|
|
16
17
|
keyZ,
|
|
@@ -19,8 +20,7 @@ import {
|
|
|
19
20
|
newZ,
|
|
20
21
|
type Payload,
|
|
21
22
|
payloadZ,
|
|
22
|
-
} from "@/channel/
|
|
23
|
-
import { type CacheRetriever } from "@/channel/retriever";
|
|
23
|
+
} from "@/channel/types.gen";
|
|
24
24
|
|
|
25
25
|
const createReqZ = z.object({ channels: newZ.array() });
|
|
26
26
|
const createResZ = z.object({ channels: payloadZ.array() });
|
package/src/client.ts
CHANGED
|
@@ -26,6 +26,8 @@ import { log } from "@/log";
|
|
|
26
26
|
import { ontology } from "@/ontology";
|
|
27
27
|
import { rack } from "@/rack";
|
|
28
28
|
import { ranger } from "@/ranger";
|
|
29
|
+
import { alias } from "@/ranger/alias";
|
|
30
|
+
import { kv } from "@/ranger/kv";
|
|
29
31
|
import { schematic } from "@/schematic";
|
|
30
32
|
import { status } from "@/status";
|
|
31
33
|
import { table } from "@/table";
|
|
@@ -152,6 +154,8 @@ export default class Synnax extends framer.Client {
|
|
|
152
154
|
chRetriever,
|
|
153
155
|
this.labels,
|
|
154
156
|
this.ontology,
|
|
157
|
+
(key: ranger.Key) => new alias.Client(key, this.transport.unary),
|
|
158
|
+
(key: ranger.Key) => new kv.Client(key, this.transport.unary),
|
|
155
159
|
);
|
|
156
160
|
this.access = new access.Client(this.transport.unary);
|
|
157
161
|
this.users = new user.Client(this.transport.unary);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2026 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 cluster from "@/cluster/types.gen";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2026 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
|
+
// Code generated by Oracle. DO NOT EDIT.
|
|
11
|
+
|
|
12
|
+
import { zod } from "@synnaxlabs/x";
|
|
13
|
+
import { type z } from "zod";
|
|
14
|
+
|
|
15
|
+
export const nodeKeyZ = zod.uint12;
|
|
16
|
+
export type NodeKey = z.infer<typeof nodeKeyZ>;
|
package/src/control/state.ts
CHANGED
|
@@ -11,24 +11,26 @@ import { binary, control, type observe } from "@synnaxlabs/x";
|
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
13
|
import { type channel } from "@/channel";
|
|
14
|
-
import { keyZ } from "@/channel/
|
|
14
|
+
import { keyZ } from "@/channel/types.gen";
|
|
15
15
|
import { framer } from "@/framer";
|
|
16
16
|
|
|
17
17
|
export type Authority = control.Authority;
|
|
18
18
|
export const ABSOLUTE_AUTHORITY = control.ABSOLUTE_AUTHORITY;
|
|
19
19
|
export const ZERO_AUTHORITY = control.ZERO_AUTHORITY;
|
|
20
|
-
export type Transfer = control.Transfer<channel.
|
|
21
|
-
export interface State extends control.State<channel.
|
|
20
|
+
export type Transfer = control.Transfer<typeof channel.keyZ>;
|
|
21
|
+
export interface State extends control.State<typeof channel.keyZ> {}
|
|
22
22
|
export interface Subject extends control.Subject {}
|
|
23
23
|
export const stateZ = control.stateZ(z.number());
|
|
24
24
|
|
|
25
25
|
export const transferString = (t: Transfer): string => {
|
|
26
|
-
|
|
26
|
+
const fromResource = t.from?.resource;
|
|
27
|
+
const toResource = t.to?.resource;
|
|
28
|
+
if (t.to == null) return `${fromResource} - ${t.from?.subject.name} -> released`;
|
|
27
29
|
if (t.from == null)
|
|
28
|
-
return `${
|
|
30
|
+
return `${toResource} - released -> ${
|
|
29
31
|
t.to.subject.name
|
|
30
32
|
} (${t.to.authority.toString()})`;
|
|
31
|
-
return `${
|
|
33
|
+
return `${toResource} - ${t.from.subject.name} -> ${
|
|
32
34
|
t.to.subject.name
|
|
33
35
|
} (${t.to.authority.toString()})`;
|
|
34
36
|
};
|
package/src/device/client.ts
CHANGED
|
@@ -19,16 +19,17 @@ import {
|
|
|
19
19
|
keyZ,
|
|
20
20
|
type New,
|
|
21
21
|
newZ,
|
|
22
|
-
|
|
22
|
+
ontologyID,
|
|
23
|
+
} from "@/device/types.gen";
|
|
23
24
|
import { ontology } from "@/ontology";
|
|
24
|
-
import { keyZ as rackKeyZ } from "@/rack/
|
|
25
|
+
import { keyZ as rackKeyZ } from "@/rack/types.gen";
|
|
25
26
|
import { checkForMultipleOrNoResults } from "@/util/retrieve";
|
|
26
27
|
|
|
27
28
|
export const SET_CHANNEL_NAME = "sy_device_set";
|
|
28
29
|
export const DELETE_CHANNEL_NAME = "sy_device_delete";
|
|
29
30
|
|
|
30
31
|
const createReqZ = <
|
|
31
|
-
Properties extends z.ZodType<record.Unknown> =
|
|
32
|
+
Properties extends z.ZodType<record.Unknown> = z.ZodType<record.Unknown>,
|
|
32
33
|
Make extends z.ZodType<string> = z.ZodString,
|
|
33
34
|
Model extends z.ZodType<string> = z.ZodString,
|
|
34
35
|
>(
|
|
@@ -36,7 +37,7 @@ const createReqZ = <
|
|
|
36
37
|
) => z.object({ devices: zod.toArray(newZ(schemas)) });
|
|
37
38
|
|
|
38
39
|
const createResZ = <
|
|
39
|
-
Properties extends z.ZodType<record.Unknown> =
|
|
40
|
+
Properties extends z.ZodType<record.Unknown> = z.ZodType<record.Unknown>,
|
|
40
41
|
Make extends z.ZodType<string> = z.ZodString,
|
|
41
42
|
Model extends z.ZodType<string> = z.ZodString,
|
|
42
43
|
>(
|
|
@@ -57,15 +58,16 @@ const retrieveRequestZ = z.object({
|
|
|
57
58
|
limit: z.int().optional(),
|
|
58
59
|
offset: z.int().optional(),
|
|
59
60
|
includeStatus: z.boolean().optional(),
|
|
61
|
+
includeParent: z.boolean().optional(),
|
|
60
62
|
});
|
|
61
63
|
|
|
62
64
|
const retrieveResZ = <
|
|
63
|
-
Properties extends z.ZodType<record.Unknown> =
|
|
65
|
+
Properties extends z.ZodType<record.Unknown> = z.ZodType<record.Unknown>,
|
|
64
66
|
Make extends z.ZodType<string> = z.ZodString,
|
|
65
67
|
Model extends z.ZodType<string> = z.ZodString,
|
|
66
68
|
>(
|
|
67
69
|
schemas?: DeviceSchemas<Properties, Make, Model>,
|
|
68
|
-
) => z.object({ devices: array.
|
|
70
|
+
) => z.object({ devices: array.nullishToEmpty(deviceZ(schemas)) });
|
|
69
71
|
|
|
70
72
|
const singleRetrieveArgsZ = z
|
|
71
73
|
.object({
|
|
@@ -133,6 +135,10 @@ export class Client {
|
|
|
133
135
|
return isSingle ? res.devices[0] : res.devices;
|
|
134
136
|
}
|
|
135
137
|
|
|
138
|
+
async create(device: New): Promise<Device>;
|
|
139
|
+
|
|
140
|
+
async create(devices: New[]): Promise<Device[]>;
|
|
141
|
+
|
|
136
142
|
async create<
|
|
137
143
|
Properties extends z.ZodType<record.Unknown>,
|
|
138
144
|
Make extends z.ZodType<string>,
|
|
@@ -142,7 +148,7 @@ export class Client {
|
|
|
142
148
|
schemas: DeviceSchemas<Properties, Make, Model>,
|
|
143
149
|
): Promise<Device<Properties, Make, Model>>;
|
|
144
150
|
|
|
145
|
-
async create(device: New): Promise<Device>;
|
|
151
|
+
async create(device: New, schemas?: DeviceSchemas): Promise<Device>;
|
|
146
152
|
|
|
147
153
|
async create<
|
|
148
154
|
Properties extends z.ZodType<record.Unknown>,
|
|
@@ -153,7 +159,7 @@ export class Client {
|
|
|
153
159
|
schemas: DeviceSchemas<Properties, Make, Model>,
|
|
154
160
|
): Promise<Device<Properties, Make, Model>[]>;
|
|
155
161
|
|
|
156
|
-
async create(devices: New[]): Promise<Device[]>;
|
|
162
|
+
async create(devices: New[], schemas?: DeviceSchemas): Promise<Device[]>;
|
|
157
163
|
|
|
158
164
|
async create(
|
|
159
165
|
devices: New | New[],
|
|
@@ -181,7 +187,4 @@ export class Client {
|
|
|
181
187
|
}
|
|
182
188
|
}
|
|
183
189
|
|
|
184
|
-
export const ontologyID = ontology.createIDFactory<Key>("device");
|
|
185
|
-
export const TYPE_ONTOLOGY_ID = ontologyID("");
|
|
186
|
-
|
|
187
190
|
export const statusKey = (key: Key): string => ontology.idToString(ontologyID(key));
|
|
@@ -7,8 +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 { id, TimeStamp, unique } from "@synnaxlabs/x";
|
|
10
|
+
import { id, record, TimeStamp, unique } from "@synnaxlabs/x";
|
|
11
11
|
import { beforeAll, describe, expect, it } from "vitest";
|
|
12
|
+
import { z } from "zod";
|
|
12
13
|
|
|
13
14
|
import { type device } from "@/device";
|
|
14
15
|
import { createTestClient } from "@/testutil/client";
|
|
@@ -361,5 +362,98 @@ describe("Device", async () => {
|
|
|
361
362
|
.toBe(true);
|
|
362
363
|
});
|
|
363
364
|
});
|
|
365
|
+
|
|
366
|
+
describe("with schemas", () => {
|
|
367
|
+
const schemas = {
|
|
368
|
+
properties: z.object({
|
|
369
|
+
rate: z.number(),
|
|
370
|
+
channels: z.array(z.string()),
|
|
371
|
+
}),
|
|
372
|
+
make: z.string(),
|
|
373
|
+
model: z.string(),
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
it("should create and retrieve with typed properties", async () => {
|
|
377
|
+
const d = await client.devices.create(
|
|
378
|
+
{
|
|
379
|
+
key: id.create(),
|
|
380
|
+
rack: testRack.key,
|
|
381
|
+
location: "Dev1",
|
|
382
|
+
name: "typed-device",
|
|
383
|
+
make: "ni",
|
|
384
|
+
model: "pxi-6281",
|
|
385
|
+
properties: { rate: 1000, channels: ["ai0", "ai1"] },
|
|
386
|
+
},
|
|
387
|
+
schemas,
|
|
388
|
+
);
|
|
389
|
+
expect(d.properties.rate).toBe(1000);
|
|
390
|
+
expect(d.properties.channels).toEqual(["ai0", "ai1"]);
|
|
391
|
+
|
|
392
|
+
const retrieved = await client.devices.retrieve({
|
|
393
|
+
key: d.key,
|
|
394
|
+
schemas,
|
|
395
|
+
});
|
|
396
|
+
expect(retrieved.properties.rate).toBe(1000);
|
|
397
|
+
expect(retrieved.properties.channels).toEqual(["ai0", "ai1"]);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it("should create and retrieve with typed make and model", async () => {
|
|
401
|
+
const makeModelSchemas = {
|
|
402
|
+
properties: record.unknownZ(),
|
|
403
|
+
make: z.literal("labjack"),
|
|
404
|
+
model: z.enum(["t7", "t4", "t8"]),
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const d = await client.devices.create(
|
|
408
|
+
{
|
|
409
|
+
key: id.create(),
|
|
410
|
+
rack: testRack.key,
|
|
411
|
+
location: "Dev1",
|
|
412
|
+
name: "typed-make-model",
|
|
413
|
+
make: "labjack",
|
|
414
|
+
model: "t7",
|
|
415
|
+
properties: {},
|
|
416
|
+
},
|
|
417
|
+
makeModelSchemas,
|
|
418
|
+
);
|
|
419
|
+
expect(d.make).toBe("labjack");
|
|
420
|
+
expect(d.model).toBe("t7");
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it("should retrieve multiple devices with schemas", async () => {
|
|
424
|
+
const d1 = await client.devices.create(
|
|
425
|
+
{
|
|
426
|
+
key: id.create(),
|
|
427
|
+
rack: testRack.key,
|
|
428
|
+
location: "Dev1",
|
|
429
|
+
name: "schema-multi-1",
|
|
430
|
+
make: "ni",
|
|
431
|
+
model: "pxi",
|
|
432
|
+
properties: { rate: 100, channels: ["ch1"] },
|
|
433
|
+
},
|
|
434
|
+
schemas,
|
|
435
|
+
);
|
|
436
|
+
const d2 = await client.devices.create(
|
|
437
|
+
{
|
|
438
|
+
key: id.create(),
|
|
439
|
+
rack: testRack.key,
|
|
440
|
+
location: "Dev2",
|
|
441
|
+
name: "schema-multi-2",
|
|
442
|
+
make: "ni",
|
|
443
|
+
model: "pxi",
|
|
444
|
+
properties: { rate: 200, channels: ["ch2", "ch3"] },
|
|
445
|
+
},
|
|
446
|
+
schemas,
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
const retrieved = await client.devices.retrieve({
|
|
450
|
+
keys: [d1.key, d2.key],
|
|
451
|
+
schemas,
|
|
452
|
+
});
|
|
453
|
+
expect(retrieved).toHaveLength(2);
|
|
454
|
+
expect(retrieved[0].properties.rate).toBe(100);
|
|
455
|
+
expect(retrieved[1].properties.rate).toBe(200);
|
|
456
|
+
});
|
|
457
|
+
});
|
|
364
458
|
});
|
|
365
459
|
});
|
package/src/device/external.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { describe, expect, it } from "vitest";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
|
-
import { deviceZ, newZ } from "@/device/
|
|
13
|
+
import { deviceZ, newZ } from "@/device/types.gen";
|
|
14
14
|
|
|
15
15
|
const VALID_DEVICE = {
|
|
16
16
|
key: "dev-1",
|
|
@@ -20,7 +20,7 @@ const VALID_DEVICE = {
|
|
|
20
20
|
model: "pxi-6281",
|
|
21
21
|
location: "Lab1",
|
|
22
22
|
properties: { rate: 10 },
|
|
23
|
-
status:
|
|
23
|
+
status: undefined,
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
describe("deviceZ", () => {
|
|
@@ -108,6 +108,30 @@ describe("newZ", () => {
|
|
|
108
108
|
expect(result.properties).toEqual(VALID_DEVICE.properties);
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
+
it("should accept a device with an optional parent ontology ID", () => {
|
|
112
|
+
const result = newZ().safeParse({
|
|
113
|
+
...VALID_DEVICE,
|
|
114
|
+
parent: { type: "rack", key: "rack-1" },
|
|
115
|
+
});
|
|
116
|
+
expect(result.success).toBe(true);
|
|
117
|
+
if (result.success)
|
|
118
|
+
expect(result.data.parent).toEqual({ type: "rack", key: "rack-1" });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should accept a device without a parent", () => {
|
|
122
|
+
const result = newZ().safeParse(VALID_DEVICE);
|
|
123
|
+
expect(result.success).toBe(true);
|
|
124
|
+
if (result.success) expect(result.data.parent).toBeUndefined();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should reject a device with an invalid parent type", () => {
|
|
128
|
+
const result = newZ().safeParse({
|
|
129
|
+
...VALID_DEVICE,
|
|
130
|
+
parent: { type: "invalid_type", key: "key-1" },
|
|
131
|
+
});
|
|
132
|
+
expect(result.success).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
|
|
111
135
|
it("should still validate make and model with custom schemas", () => {
|
|
112
136
|
const makeZ = z.literal("ni");
|
|
113
137
|
const result = newZ({ make: makeZ }).safeParse(VALID_DEVICE);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Copyright 2026 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
|
+
// Code generated by Oracle. DO NOT EDIT.
|
|
11
|
+
|
|
12
|
+
import { type optional, record, status } from "@synnaxlabs/x";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
15
|
+
import { ontology } from "@/ontology";
|
|
16
|
+
import { rack } from "@/rack";
|
|
17
|
+
|
|
18
|
+
/** StatusDetails contains device-specific status details identifying the device and its associated rack. */
|
|
19
|
+
export const statusDetailsZ = z.object({
|
|
20
|
+
/** rack is the key of the rack this device belongs to. */
|
|
21
|
+
rack: rack.keyZ,
|
|
22
|
+
/** device is the device identifier. */
|
|
23
|
+
device: z.string(),
|
|
24
|
+
});
|
|
25
|
+
export interface StatusDetails extends z.infer<typeof statusDetailsZ> {}
|
|
26
|
+
|
|
27
|
+
export const keyZ = z.string();
|
|
28
|
+
export type Key = z.infer<typeof keyZ>;
|
|
29
|
+
|
|
30
|
+
export const statusZ = status.statusZ({ details: statusDetailsZ });
|
|
31
|
+
export type Status = z.infer<typeof statusZ>;
|
|
32
|
+
|
|
33
|
+
export interface DeviceSchemas<
|
|
34
|
+
Properties extends z.ZodType<record.Unknown> = z.ZodType<record.Unknown>,
|
|
35
|
+
Make extends z.ZodType<string> = z.ZodType<string>,
|
|
36
|
+
Model extends z.ZodType<string> = z.ZodType<string>,
|
|
37
|
+
> {
|
|
38
|
+
properties: Properties;
|
|
39
|
+
make: Make;
|
|
40
|
+
model: Model;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const deviceZ = <
|
|
44
|
+
Properties extends z.ZodType<record.Unknown> = z.ZodType<record.Unknown>,
|
|
45
|
+
Make extends z.ZodType<string> = z.ZodString,
|
|
46
|
+
Model extends z.ZodType<string> = z.ZodString,
|
|
47
|
+
>({ properties, make, model }: Partial<DeviceSchemas<Properties, Make, Model>> = {}) =>
|
|
48
|
+
z.object({
|
|
49
|
+
key: keyZ,
|
|
50
|
+
rack: rack.keyZ,
|
|
51
|
+
location: z.string().min(1, "Location is required"),
|
|
52
|
+
make: make ?? z.string().min(1, "Make is required"),
|
|
53
|
+
model: model ?? z.string().min(1, "Model is required"),
|
|
54
|
+
name: z.string().min(1, "Name is required"),
|
|
55
|
+
configured: z.boolean().default(false),
|
|
56
|
+
properties: properties ?? record.nullishToEmpty(),
|
|
57
|
+
status: statusZ.optional(),
|
|
58
|
+
parent: ontology.idZ.optional(),
|
|
59
|
+
});
|
|
60
|
+
export interface Device<
|
|
61
|
+
Properties extends z.ZodType<record.Unknown> = z.ZodType<record.Unknown>,
|
|
62
|
+
Make extends z.ZodType<string> = z.ZodString,
|
|
63
|
+
Model extends z.ZodType<string> = z.ZodString,
|
|
64
|
+
> {
|
|
65
|
+
key: Key;
|
|
66
|
+
rack: rack.Key;
|
|
67
|
+
location: string;
|
|
68
|
+
make: z.infer<Make>;
|
|
69
|
+
model: z.infer<Model>;
|
|
70
|
+
name: string;
|
|
71
|
+
configured: boolean;
|
|
72
|
+
properties: z.infer<Properties>;
|
|
73
|
+
status?: Status;
|
|
74
|
+
parent?: ontology.ID;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface NewSchemas<
|
|
78
|
+
Properties extends z.ZodType<record.Unknown> = z.ZodType<record.Unknown>,
|
|
79
|
+
Make extends z.ZodType<string> = z.ZodType<string>,
|
|
80
|
+
Model extends z.ZodType<string> = z.ZodType<string>,
|
|
81
|
+
> {
|
|
82
|
+
properties: Properties;
|
|
83
|
+
make: Make;
|
|
84
|
+
model: Model;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const newZ = <
|
|
88
|
+
Properties extends z.ZodType<record.Unknown> = z.ZodType<record.Unknown>,
|
|
89
|
+
Make extends z.ZodType<string> = z.ZodString,
|
|
90
|
+
Model extends z.ZodType<string> = z.ZodString,
|
|
91
|
+
>({ properties, make, model }: Partial<NewSchemas<Properties, Make, Model>> = {}) =>
|
|
92
|
+
deviceZ({ properties, make, model }).partial({ key: true, configured: true });
|
|
93
|
+
export type New<
|
|
94
|
+
Properties extends z.ZodType<record.Unknown> = z.ZodType<record.Unknown>,
|
|
95
|
+
Make extends z.ZodType<string> = z.ZodString,
|
|
96
|
+
Model extends z.ZodType<string> = z.ZodString,
|
|
97
|
+
> = optional.Optional<Device<Properties, Make, Model>, "key" | "configured">;
|
|
98
|
+
|
|
99
|
+
export const ontologyID = ontology.createIDFactory<Key>("device");
|
|
100
|
+
export const TYPE_ONTOLOGY_ID = ontologyID("");
|