@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/dist/client.cjs
CHANGED
|
@@ -1,89 +1,83 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod"),Ph=t=>{const e=t.replace(/_[a-z]/g,n=>n[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},La=t=>{const e=(n,r=Dr)=>{if(typeof n=="string")return t(n);if(Array.isArray(n))return n.map(o=>e(o,r));if(!vr(n))return n;r=qh(r);const s={},a=n;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),r):(Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);r.recursive&&(vr(c)?Ii(c)||(c=e(c,r)):r.recursiveInArray&&Ai(c)&&(c=[...c].map(l=>{let h=l;return vr(l)?Ii(h)||(h=e(l,r)):Ai(l)&&(h=e({key:l},r).key),h}))),s[u]=c}),s)};return e},Da=La(Ph),Lh=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,n,r)=>`${n}_${r.toLowerCase()}`),Dh=La(Lh),Bh=[Number,String,Uint8Array],Dr={recursive:!0,recursiveInArray:!0},qh=(t=Dr)=>(t.recursive==null?t=Dr:t.recursiveInArray??=!1,t),Ai=t=>t!=null&&Array.isArray(t),vr=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),Ii=t=>Bh.some(e=>t instanceof e);class Fh{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,n){return this.decodeString(this.decoder.decode(e),n)}decodeString(e,n){const r=JSON.parse(e),s=Da(r);return n!=null?n.parse(s):s}encodeString(e){const n=Dh(e);return JSON.stringify(n,(r,s)=>ArrayBuffer.isView(s)?Array.from(s):typeof s=="bigint"?s.toString():s)}}const Br=new Fh,de=t=>t!=null&&typeof t=="object"&&"value"in t;class It{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}}const Yh=t=>t!=null&&typeof t=="object"&&"toString"in t,Hh=(t,e=!1)=>{const n=Yh(t)?"stringer":typeof t;let r;switch(n){case"string":r=(s,a)=>s.localeCompare(a);break;case"stringer":r=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":r=(s,a)=>Number(s)-Number(a);break;case"bigint":r=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":r=(s,a)=>Number(s)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?Vh(r):r},Vh=t=>(e,n)=>t(n,e);let Ba=(t,e=21)=>(n=e)=>{let r="",s=n|0;for(;s--;)r+=t[Math.random()*t.length|0];return r};const qa="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Gh=`0123456789${qa}`,Wh=11,Jh=Ba(qa,1),Kh=Ba(Gh,Wh-1),Xh=()=>`${Jh()}${Kh()}`,Qh=(t,e)=>n=>n instanceof e||typeof n=="object"&&n!==null&&"discriminator"in n&&n.discriminator===t,ef=2**12-1,qr=2n**63n-1n,tf=2**63-1,Vn=t=>(e,n)=>{if(typeof e=="bigint"){if(nf(n))return t(e,BigInt(n));const r=t(Number(e),Number(n));return typeof r=="number"?BigInt(Math.round(r)):r}return t(Number(e),Number(n))},an=Vn((t,e)=>t-e),at=Vn((t,e)=>t+e),nf=t=>typeof t=="bigint"?!0:Number.isInteger(t),Ne=Vn((t,e)=>t*e),Gn=Vn((t,e)=>t/e),Fa=i.z.tuple([i.z.number(),i.z.number()]),Ya=i.z.object({width:i.z.number(),height:i.z.number()}),rf=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),sf=["start","center","end"],Gt=i.z.object({x:i.z.number(),y:i.z.number()}),af=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),of=["x","y"],Ha=i.z.enum(of),Va=["top","right","bottom","left"];i.z.enum(Va);const cf=["left","right"],Ga=i.z.enum(cf),uf=["top","bottom"],Wa=i.z.enum(uf),Ja=["center"],Zi=i.z.enum(Ja),lf=[...Va,...Ja],Ka=i.z.enum(lf);i.z.enum(sf);const hf=["first","last"];i.z.enum(hf);i.z.object({lower:i.z.number(),upper:i.z.number()});i.z.enum([...Ha.options,...Ka.options]);i.z.union([Ha,Ka,i.z.instanceof(String)]);const ot=(t,e,n)=>{const r={};if(typeof e=="object"&&(n=e,e=void 0),n={makeValid:!0,...n},typeof t=="number"||typeof t=="bigint")e!=null?(r.lower=t,r.upper=e):(r.lower=typeof t=="bigint"?0n:0,r.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[r.lower,r.upper]=t}else r.lower=t.lower,r.upper=t.upper;return n?.makeValid?ff(r):r},ff=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,xi=(t,e)=>{const n=ot(t);return e<n.lower?n.lower:e>=n.upper?n.upper-(typeof n.upper=="number"?1:1n):e};i.z.object({x:Ga.or(Zi),y:Wa.or(Zi)});const Xa=i.z.object({x:Ga,y:Wa}),df=Object.freeze({x:"left",y:"top"}),pf=(t,e)=>t.x===e.x&&t.y===e.y,Ci=i.z.union([i.z.number(),Gt,Fa,Ya,rf,af]),yf=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},_i=Object.freeze({x:0,y:0}),On=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:On,left:On,width:On,height:On});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:Gt,two:Gt,root:Xa});const vs=(t,e,n=0,r=0,s)=>{const a={one:{..._i},two:{..._i},root:s??df};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+n,y:a.one.y+r},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:s??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+n,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+n}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},zr=t=>{const e=vs(t);return{lower:e.one.x,upper:e.two.x}},Tr=t=>{const e=vs(t);return{lower:e.one.y,upper:e.two.y}},mf=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,gf=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([Ya,gf,Gt,Fa]);const wf=(t,e,n)=>e!==void 0&&t<e?e:n!==void 0&&t>n?n:t;i.z.object({offset:Ci,scale:Ci});i.z.object({offset:i.z.number(),scale:i.z.number()});const bf=t=>(e,n,r,s)=>n==="dimension"?[e,r]:[e,s?r-t:r+t],vf=t=>(e,n,r,s)=>[e,s?r/t:r*t],zf=t=>(e,n,r)=>{if(e===null)return[t,r];const{lower:s,upper:a}=e,{lower:o,upper:c}=t,u=a-s,l=c-o;if(n==="dimension")return[t,r*(l/u)];const h=(r-s)*(l/u)+o;return[t,h]},Tf=t=>(e,n,r)=>[t,r],Of=()=>(t,e,n)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,n];const{lower:r,upper:s}=t;return[t,s-(n-r)]},Sf=t=>(e,n,r)=>{const{lower:s,upper:a}=t;return r=wf(r,s,a),[e,r]};class Ve{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new Ve().translate(e)}static magnify(e){return new Ve().magnify(e)}static scale(e,n){return new Ve().scale(e,n)}translate(e){const n=this.new(),r=bf(e);return r.type="translate",n.ops.push(r),n}magnify(e){const n=this.new(),r=vf(e);return r.type="magnify",n.ops.push(r),n}scale(e,n){const r=ot(e,n),s=this.new(),a=zf(r);return a.type="scale",s.ops.push(a),s}clamp(e,n){const r=ot(e,n),s=this.new(),a=Sf(r);return a.type="clamp",s.ops.push(a),s}reBound(e,n){const r=ot(e,n),s=this.new(),a=Tf(r);return a.type="re-bound",s.ops.push(a),s}invert(){const e=Of();e.type="invert";const n=this.new();return n.ops.push(e),n}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new Ve;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,n){return this.currBounds=null,this.ops.reduce(([r,s],a)=>a(r,e,s,this.reversed),[null,n])[1]}reverse(){const e=this.new();e.ops.reverse();const n=[];return e.ops.forEach((r,s)=>{if(r.type==="scale"||n.some(([o,c])=>s>=o&&s<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>s);a!==-1&&n.push([s,a])}),n.forEach(([r,s])=>{const a=e.ops.slice(r,s);a.unshift(e.ops[s]),e.ops.splice(r,s-r+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new Ve}class Se{x;y;currRoot;constructor(e=new Ve,n=new Ve,r=null){this.x=e,this.y=n,this.currRoot=r}static translate(e,n){return new Se().translate(e,n)}static translateX(e){return new Se().translateX(e)}static translateY(e){return new Se().translateY(e)}static clamp(e){return new Se().clamp(e)}static magnify(e){return new Se().magnify(e)}static scale(e){return new Se().scale(e)}static reBound(e){return new Se().reBound(e)}translate(e,n){const r=yf(e,n),s=this.copy();return s.x=this.x.translate(r.x),s.y=this.y.translate(r.y),s}translateX(e){const n=this.copy();return n.x=this.x.translate(e),n}translateY(e){const n=this.copy();return n.y=this.y.translate(e),n}magnify(e){const n=this.copy();return n.x=this.x.magnify(e.x),n.y=this.y.magnify(e.y),n}scale(e){const n=this.copy();if(mf(e)){const r=this.currRoot;return n.currRoot=e.root,r!=null&&!pf(r,e.root)&&(r.x!==e.root.x&&(n.x=n.x.invert()),r.y!==e.root.y&&(n.y=n.y.invert())),n.x=n.x.scale(zr(e)),n.y=n.y.scale(Tr(e)),n}return n.x=n.x.scale(e.width),n.y=n.y.scale(e.height),n}reBound(e){const n=this.copy();return n.x=this.x.reBound(zr(e)),n.y=this.y.reBound(Tr(e)),n}clamp(e){const n=this.copy();return n.x=this.x.clamp(zr(e)),n.y=this.y.clamp(Tr(e)),n}copy(){const e=new Se;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return vs(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new Se}const Ef=Gt.extend({root:Xa,units:i.object({x:i.enum(["px","decimal"]),y:i.enum(["px","decimal"])})});Ef.partial({root:!0,units:!0});const Nf=i.z.enum(["static","dynamic"]),Mi=365,Sn=30,$f=i.z.union([i.z.tuple([i.z.int()]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12)]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12),i.z.int().min(1).max(31)])]),Qa=(t,e)=>{const n=new v(e);if(![z.DAY,z.HOUR,z.MINUTE,z.SECOND,z.MILLISECOND,z.MICROSECOND,z.NANOSECOND].some(s=>s.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof v?new v(r):new z(r)};class v extends It{constructor(e,n="UTC"){if(e==null)super(v.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*v.MILLISECOND.valueOf());else if(typeof e=="string")super(v.parseDateTimeString(e,n).valueOf());else if(Array.isArray(e))super(v.parseDate(e));else{let r=0n;e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=v.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e===tf?e=qr:e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=v.MAX:e=v.MIN)),de(e)&&(e=e.value),super(BigInt(e.valueOf())+r)}}static parseDate([e=1970,n=1,r=1]){const s=new Date(e,n-1,r,0,0,0,0);return new v(BigInt(s.getTime())*v.MILLISECOND.valueOf()).truncate(v.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,n="UTC"){const[r,s,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=v.hours(parseInt(r??"00")).add(v.minutes(parseInt(s??"00"))).add(v.seconds(parseInt(o??"00"))).add(v.milliseconds(parseInt(c??"00")));return n==="local"&&(u=u.add(v.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return v.parseTimeString(e,n);if(e.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?$/)!=null){let s=e,a=0;if(e.includes(".")){const l=e.split(".");s=l[0];const h=l[1]||"0";a=parseInt(h.padEnd(3,"0").slice(0,3))}const o=n==="local"?new Date(s.replace("T"," ")):new Date(`${s}Z`),c=BigInt(o.getTime())*v.MILLISECOND.valueOf(),u=BigInt(a)*v.MILLISECOND.valueOf();return c+u}const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new v(BigInt(r.getTime())*v.MILLISECOND.valueOf(),n).valueOf()}toISOString(e="UTC"){if(e==="UTC")return this.date().toISOString();const n=this.date(),r=new z(BigInt(n.getTimezoneOffset())*v.MINUTE.valueOf());return this.sub(r).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new z(BigInt(new Date().getTimezoneOffset())*v.MINUTE.valueOf())}static since(e){return new v().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new v(e).valueOf()}span(e){return this.range(e).span}range(e){return new re(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new v(e).valueOf()}afterEq(e){return this.valueOf()>=new v(e).valueOf()}before(e){return this.valueOf()<new v(e).valueOf()}beforeEq(e){return this.valueOf()<=new v(e).valueOf()}add(e){return new v(at(this.valueOf(),new z(e).valueOf()))}sub(e){return new v(an(this.valueOf(),new z(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(z.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(z.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(z.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(z.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(v.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(v.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}get localYear(){return this.date().getFullYear()}setYear(e){const n=this.date();return n.setUTCFullYear(e),new v(n)}setLocalYear(e){const n=this.date();return n.setFullYear(e),new v(n)}get month(){return this.date().getUTCMonth()}get localMonth(){return this.date().getMonth()}setMonth(e){const n=this.date();return n.setUTCMonth(e),new v(n)}setLocalMonth(e){const n=this.date();return n.setMonth(e),new v(n)}get day(){return this.date().getUTCDate()}get localDay(){return this.date().getDate()}setDay(e){const n=this.date();return n.setUTCDate(e),new v(n)}setLocalDay(e){const n=this.date();return n.setDate(e),new v(n)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const n=this.date();return n.setHours(e),new v(n)}setHour(e){const n=this.date();return n.setUTCHours(e),new v(n)}get minute(){return this.date().getUTCMinutes()}get localMinute(){return this.date().getMinutes()}setMinute(e){const n=this.date();return n.setUTCMinutes(e),new v(n)}setLocalMinute(e){const n=this.date();return n.setMinutes(e),new v(n)}get second(){return this.date().getUTCSeconds()}get localSecond(){return this.date().getSeconds()}setSecond(e){const n=this.date();return n.setUTCSeconds(e),new v(n)}setLocalSecond(e){const n=this.date();return n.setSeconds(e),new v(n)}get millisecond(){return this.date().getUTCMilliseconds()}get localMillisecond(){return this.date().getMilliseconds()}setMillisecond(e){const n=this.date();return n.setUTCMilliseconds(e),new v(n)}setLocalMillisecond(e){const n=this.date();return n.setMilliseconds(e),new v(n)}toString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}remainder(e){return Qa(this,e)}get isToday(){return this.truncate(z.DAY).equals(v.now().truncate(z.DAY))}truncate(e){return this.sub(this.remainder(e))}formatBySpan(e){return e.greaterThanOrEqual(z.days(30))?"shortDate":e.greaterThanOrEqual(z.DAY)?"dateTime":e.greaterThanOrEqual(z.HOUR)?"time":e.greaterThanOrEqual(z.SECOND)?"preciseTime":"ISOTime"}static now(){return new v(new Date)}static max(...e){let n=v.MIN;for(const r of e){const s=new v(r);s.after(n)&&(n=s)}return n}static min(...e){let n=v.MAX;for(const r of e){const s=new v(r);s.before(n)&&(n=s)}return n}static nanoseconds(e,n="UTC"){return new v(e,n)}static NANOSECOND=v.nanoseconds(1);static microseconds(e,n="UTC"){return v.nanoseconds(e*1e3,n)}static MICROSECOND=v.microseconds(1);static milliseconds(e,n="UTC"){return v.microseconds(e*1e3,n)}static MILLISECOND=v.milliseconds(1);static seconds(e,n="UTC"){return v.milliseconds(e*1e3,n)}static SECOND=v.seconds(1);static minutes(e,n="UTC"){return v.seconds(e*60,n)}static MINUTE=v.minutes(1);static hours(e,n="UTC"){return v.minutes(e*60,n)}static HOUR=v.hours(1);static days(e,n="UTC"){return v.hours(e*24,n)}static DAY=v.days(1);static MAX=new v(qr);static MIN=new v(0);static ZERO=new v(0);static z=i.z.union([i.z.instanceof(v),i.z.object({value:i.z.bigint()}).transform(e=>new v(e.value)),i.z.string().transform(e=>new v(BigInt(e))),i.z.number().transform(e=>new v(e)),i.z.bigint().transform(e=>new v(e)),i.z.date().transform(e=>new v(e)),i.z.custom(e=>e instanceof z).transform(e=>new v(e)),$f.transform(e=>new v(e))]);static sort(e,n){return Number(e.valueOf()-n.valueOf())}}class z extends It{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),de(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof z?e:e instanceof Or?e.period:e instanceof v?new z(e):(de(e)&&(e=e.value),["number","bigint"].includes(typeof e)?z.seconds(e):new z(e))}static fromMilliseconds(e){return e instanceof z?e:e instanceof Or?e.period:e instanceof v?new z(e):(de(e)&&(e=e.value),["number","bigint"].includes(typeof e)?z.milliseconds(e):new z(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new z(e).valueOf()}greaterThan(e){return this.valueOf()>new z(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new z(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new z(e).valueOf()}remainder(e){return Qa(this,e)}truncate(e){return new z(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(e="full"){if(e==="semantic")return this.toSemanticString();const n=this.truncate(z.DAY),r=this.truncate(z.HOUR),s=this.truncate(z.MINUTE),a=this.truncate(z.SECOND),o=this.truncate(z.MILLISECOND),c=this.truncate(z.MICROSECOND),u=this.truncate(z.NANOSECOND),l=n,h=r.sub(n),d=s.sub(r),f=a.sub(s),b=o.sub(a),N=c.sub(o),k=u.sub(c);let O="";return l.isZero||(O+=`${l.days}d `),h.isZero||(O+=`${h.hours}h `),d.isZero||(O+=`${d.minutes}m `),f.isZero||(O+=`${f.seconds}s `),b.isZero||(O+=`${b.milliseconds}ms `),N.isZero||(O+=`${N.microseconds}µs `),k.isZero||(O+=`${k.nanoseconds}ns`),O.trim()}toSemanticString(){const e=this.valueOf()<0n?-this.valueOf():this.valueOf(),n=new z(e),r=this.valueOf()<0n;if(n.valueOf()===0n)return"0s";if(n.lessThan(z.SECOND))return"< 1s";const s=n.days,a=n.hours,o=n.minutes,c=n.seconds,u=Math.floor(s/Mi),l=Math.floor(s/Sn),h=Math.floor(s/7),d=Math.floor(s),f=Math.floor(a),b=Math.floor(o),N=Math.floor(c),k=r?"-":"";if(u>=1){let O=`${u}y`;if(u<2){const S=Math.floor(s%Mi/Sn);S>0&&(O+=` ${S}mo`)}return k+O}if(h>=1&&s<Sn&&s%7===0){let O=`${h}w`;const S=Math.floor(s%7),A=Math.floor(a-h*7*24);return h<2&&(S>0?O+=` ${S}d`:A>0&&A<24&&(O+=` ${A}h`)),k+O}if(l>=1){let O=`${l}mo`;if(l<3){const S=Math.floor(s%Sn);S>0&&(O+=` ${S}d`)}return k+O}if(h>=1){let O=`${h}w`;const S=Math.floor(s%7),A=Math.floor(a-h*7*24);return h<2&&(S>0?O+=` ${S}d`:A>0&&A<24&&(O+=` ${A}h`)),k+O}if(d>=1){let O=`${d}d`;const S=Math.floor(a-d*24);return d<2&&S>0&&(O+=` ${S}h`),k+O}if(f>=1){let O=`${f}h`;if(f<3){const S=Math.floor(o-f*60);S>0&&(O+=` ${S}m`)}return k+O}if(b>=1){let O=`${b}m`;if(b<5){const S=Math.floor(c-b*60);S>0&&(O+=` ${S}s`)}return k+O}return`${k}${N}s`}mult(e){return new z(Ne(this.valueOf(),e))}div(e){return new z(Gn(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(z.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(z.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(z.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(z.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(z.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(z.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new z(e).valueOf()}add(e){return new z(this.valueOf()+new z(e).valueOf())}sub(e){return new z(this.valueOf()-new z(e).valueOf())}static nanoseconds(e=1){return new z(e)}static NANOSECOND=z.nanoseconds(1);static microseconds(e=1){return z.nanoseconds(Ne(e,1e3))}static MICROSECOND=z.microseconds(1);static milliseconds(e=1){return z.microseconds(Ne(e,1e3))}static MILLISECOND=z.milliseconds(1);static seconds(e=1){return z.milliseconds(Ne(e,1e3))}static SECOND=z.seconds(1);static minutes(e=1){return z.seconds(Ne(e,60))}static MINUTE=z.minutes(1);static hours(e){return z.minutes(Ne(e,60))}static HOUR=z.hours(1);static days(e){return z.hours(Ne(e,24))}static DAY=z.days(1);static MAX=new z(qr);static MIN=new z(0);static ZERO=new z(0);static z=i.z.union([i.z.object({value:i.z.bigint()}).transform(e=>new z(e.value)),i.z.string().transform(e=>new z(BigInt(e))),i.z.number().transform(e=>new z(e)),i.z.bigint().transform(e=>new z(e)),i.z.instanceof(z),i.z.instanceof(v).transform(e=>new z(e)),i.z.custom(e=>e instanceof Or).transform(e=>new z(e))])}let Or=class fe extends It{constructor(e){de(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new fe(e).valueOf()}get period(){return z.seconds(1/this.valueOf())}sampleCount(e){return new z(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new R(n).valueOf()}span(e){return z.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/new R(n).valueOf())}add(e){return new fe(at(this.valueOf(),new fe(e).valueOf()))}sub(e){return new fe(an(this.valueOf(),new fe(e).valueOf()))}mult(e){return new fe(Ne(this.valueOf(),e))}div(e){return new fe(Gn(this.valueOf(),e))}static hz(e){return new fe(e)}static khz(e){return fe.hz(e*1e3)}static z=i.z.union([i.z.number().transform(e=>new fe(e)),i.z.instanceof(fe)])};class R extends It{constructor(e){de(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Z(e*this.valueOf())}add(e){return new R(at(this.valueOf(),new R(e).valueOf()))}sub(e){return new R(an(this.valueOf(),new R(e).valueOf()))}mult(e){return new R(Ne(this.valueOf(),e))}div(e){return new R(Gn(this.valueOf(),e))}static UNKNOWN=new R(0);static BIT128=new R(16);static BIT64=new R(8);static BIT32=new R(4);static BIT16=new R(2);static BIT8=new R(1);static z=i.z.union([i.z.number().transform(e=>new R(e)),i.z.instanceof(R)])}class re{start;end;constructor(e,n){typeof e=="object"&&"start"in e?(this.start=new v(e.start),this.end=new v(e.end)):(this.start=new v(e),this.end=new v(n))}get span(){return new z(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new re(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,n=z.ZERO){if(n.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let r=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return r<0&&(r=-r),s<0&&(s=-s),r<=n.valueOf()&&s<=n.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,n=z.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const s=v.max(r.start,e.start),a=v.min(r.end,e.end);return a.before(s)?!1:new z(a.sub(s)).greaterThanOrEqual(n)}contains(e){return e instanceof re?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new re(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}static max(...e){return new re(v.min(...e.map(n=>n.start)),v.max(...e.map(n=>n.end)))}static MAX=new re(v.MIN,v.MAX);static ZERO=new re(v.ZERO,v.ZERO);static z=i.z.union([i.z.object({start:v.z,end:v.z}).transform(e=>new re(e.start,e.end)),i.z.instanceof(re)]);static sort(e,n){return v.sort(e.start,n.start)||v.sort(e.end,n.end)}static merge(...e){return re.max(...e.map(n=>new re(n).makeValid()))}}class y extends It{constructor(e){if(de(e)&&(e=e.value),e instanceof y||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const n=y.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n==null)throw new Error(`unable to find data type for ${e.toString()}`);super(n.valueOf())}}get Array(){const e=y.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(n=>this.equals(n))}toString(e=!1){return e?y.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(y.JSON)||this.equals(y.STRING)||this.equals(y.BYTES)}get isNumeric(){return!this.isVariable&&!this.equals(y.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=y.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(y.UINT8)||this.equals(y.UINT16)||this.equals(y.UINT32)||this.equals(y.UINT64)}get isSignedInteger(){return this.equals(y.INT8)||this.equals(y.INT16)||this.equals(y.INT32)||this.equals(y.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(y.INT32)&&e.equals(y.FLOAT64)||this.equals(y.INT8)&&e.equals(y.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return y.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new y("unknown");static FLOAT64=new y("float64");static FLOAT32=new y("float32");static INT64=new y("int64");static INT32=new y("int32");static INT16=new y("int16");static INT8=new y("int8");static UINT64=new y("uint64");static UINT32=new y("uint32");static UINT16=new y("uint16");static UINT8=new y("uint8");static TIMESTAMP=new y("timestamp");static UUID=new y("uuid");static STRING=new y("string");static JSON=new y("json");static BYTES=new y("bytes");static ARRAY_CONSTRUCTORS=new Map([[y.UINT8.toString(),Uint8Array],[y.UINT16.toString(),Uint16Array],[y.UINT32.toString(),Uint32Array],[y.UINT64.toString(),BigUint64Array],[y.FLOAT32.toString(),Float32Array],[y.FLOAT64.toString(),Float64Array],[y.INT8.toString(),Int8Array],[y.INT16.toString(),Int16Array],[y.INT32.toString(),Int32Array],[y.INT64.toString(),BigInt64Array],[y.TIMESTAMP.toString(),BigInt64Array],[y.STRING.toString(),Uint8Array],[y.JSON.toString(),Uint8Array],[y.UUID.toString(),Uint8Array],[y.BYTES.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,y.UINT8],[Uint16Array.name,y.UINT16],[Uint32Array.name,y.UINT32],[BigUint64Array.name,y.UINT64],[Float32Array.name,y.FLOAT32],[Float64Array.name,y.FLOAT64],[Int8Array.name,y.INT8],[Int16Array.name,y.INT16],[Int32Array.name,y.INT32],[BigInt64Array.name,y.INT64]]);static DENSITIES=new Map([[y.UINT8.toString(),R.BIT8],[y.UINT16.toString(),R.BIT16],[y.UINT32.toString(),R.BIT32],[y.UINT64.toString(),R.BIT64],[y.FLOAT32.toString(),R.BIT32],[y.FLOAT64.toString(),R.BIT64],[y.INT8.toString(),R.BIT8],[y.INT16.toString(),R.BIT16],[y.INT32.toString(),R.BIT32],[y.INT64.toString(),R.BIT64],[y.TIMESTAMP.toString(),R.BIT64],[y.STRING.toString(),R.UNKNOWN],[y.JSON.toString(),R.UNKNOWN],[y.UUID.toString(),R.BIT128],[y.BYTES.toString(),R.UNKNOWN]]);static ALL=[y.UNKNOWN,y.UINT8,y.UINT16,y.UINT32,y.UINT64,y.INT8,y.INT16,y.INT32,y.INT64,y.FLOAT32,y.FLOAT64,y.TIMESTAMP,y.UUID,y.STRING,y.JSON,y.BYTES];static SHORT_STRINGS=new Map([[y.UINT8.toString(),"u8"],[y.UINT16.toString(),"u16"],[y.UINT32.toString(),"u32"],[y.UINT64.toString(),"u64"],[y.INT8.toString(),"i8"],[y.INT16.toString(),"i16"],[y.INT32.toString(),"i32"],[y.INT64.toString(),"i64"],[y.FLOAT32.toString(),"f32"],[y.FLOAT64.toString(),"f64"],[y.TIMESTAMP.toString(),"ts"],[y.UUID.toString(),"uuid"],[y.STRING.toString(),"str"],[y.JSON.toString(),"json"],[y.BYTES.toString(),"bytes"]]);static BIG_INT_TYPES=[y.INT64,y.UINT64,y.TIMESTAMP];static z=i.z.union([i.z.string().transform(e=>new y(e)),i.z.instanceof(y)])}class Z extends It{constructor(e){de(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return de(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return de(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return de(e)&&(e=e.value),new Z(at(this.valueOf(),e.valueOf()))}sub(e){return de(e)&&(e=e.value),new Z(an(this.valueOf(),e.valueOf()))}mult(e){return new Z(Ne(this.valueOf(),e))}div(e){return new Z(Gn(this.valueOf(),e))}truncate(e){return new Z(Math.trunc(this.valueOf()/new Z(e).valueOf())*new Z(e).valueOf())}remainder(e){return Z.bytes(this.valueOf()%new Z(e).valueOf())}get gigabytes(){return this.valueOf()/Z.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/Z.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/Z.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/Z.TERABYTE.valueOf()}toString(){const e=this.truncate(Z.TERABYTE),n=this.truncate(Z.GIGABYTE),r=this.truncate(Z.MEGABYTE),s=this.truncate(Z.KILOBYTE),a=this.truncate(Z.BYTE),o=e,c=n.sub(e),u=r.sub(n),l=s.sub(r),h=a.sub(s);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),l.isZero||(d+=`${l.kilobytes}KB `),(!h.isZero||d==="")&&(d+=`${h.valueOf()}B`),d.trim()}static bytes(e=1){return new Z(e)}static BYTE=new Z(1);static kilobytes(e=1){return Z.bytes(new Z(e).valueOf()*1e3)}static KILOBYTE=Z.kilobytes(1);static megabytes(e=1){return Z.kilobytes(new Z(e).valueOf()*1e3)}static MEGABYTE=Z.megabytes(1);static gigabytes(e=1){return Z.megabytes(new Z(e).valueOf()*1e3)}static GIGABYTE=Z.gigabytes(1);static terabytes(e){return Z.gigabytes(new Z(e).valueOf()*1e3)}static TERABYTE=Z.terabytes(1);static ZERO=new Z(0);static z=i.z.union([i.z.number().transform(e=>new Z(e)),i.z.instanceof(Z)]);get isZero(){return this.valueOf()===0}}i.z.object({start:i.z.number(),end:i.z.number()});i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const eo=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof v||t instanceof z||t instanceof Date},kf=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):an(n,r),Af=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function If(t){return typeof t=="string"&&Af.test(t)}const Q=[];for(let t=0;t<256;++t)Q.push((t+256).toString(16).slice(1));function Zf(t,e=0){return(Q[t[e+0]]+Q[t[e+1]]+Q[t[e+2]]+Q[t[e+3]]+"-"+Q[t[e+4]]+Q[t[e+5]]+"-"+Q[t[e+6]]+Q[t[e+7]]+"-"+Q[t[e+8]]+Q[t[e+9]]+"-"+Q[t[e+10]]+Q[t[e+11]]+Q[t[e+12]]+Q[t[e+13]]+Q[t[e+14]]+Q[t[e+15]]).toLowerCase()}function xf(t,e=0){const n=Zf(t,e);if(!If(n))throw TypeError("Stringified UUID is invalid");return n}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const to=(t,e)=>xf(t,e),Be=-1,Cf=i.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),_f=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),Fr=10,Mf=(t,e)=>{if(t==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(t==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},no="sy_x_telem_series";let ro=class He{key;discriminator=no;dataType;sampleOffset;gl;_data;timeRange=re.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=Be;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=i.z.object({timeRange:re.z.optional(),dataType:y.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([Cf,_f,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:Nf.default("static").optional()});static z=He.crudeZ.transform(e=>new He(e));constructor(e){Rf(e)&&(e={data:e}),e.data??=[];const{dataType:n,timeRange:r,sampleOffset:s=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:u=Xh(),data:l}=e;if(jf(l)){const f=l;this.key=f.key,this.dataType=f.dataType,this.sampleOffset=f.sampleOffset,this.gl=f.gl,this._data=f._data,this.timeRange=f.timeRange,this.alignment=f.alignment,this.alignmentMultiple=f.alignmentMultiple,this.cachedMin=f.cachedMin,this.cachedMax=f.cachedMax,this.writePos=f.writePos,this._refCount=f._refCount,this.cachedLength=f.cachedLength;return}const h=eo(l),d=Array.isArray(l);if(n!=null)this.dataType=new y(n);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(d||h){let f=l;if(!h){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");f=l[0]}if(typeof f=="string")this.dataType=y.STRING;else if(typeof f=="number")this.dataType=y.FLOAT64;else if(typeof f=="bigint")this.dataType=y.INT64;else if(typeof f=="boolean")this.dataType=y.UINT8;else if(f instanceof v||f instanceof Date||f instanceof v)this.dataType=y.TIMESTAMP;else if(typeof f=="object")this.dataType=y.JSON;else throw new Error(`cannot infer data type of ${typeof f} when constructing a Series from a JS array`)}else this.dataType=new y(l)}if(!d&&!h)this._data=l;else if(d&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let f=h?[l]:l;const b=f[0];(b instanceof v||b instanceof Date||b instanceof z)&&(f=f.map(N=>new v(N).valueOf())),this.dataType.equals(y.STRING)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.join(`
|
|
2
|
-
`)}
|
|
3
|
-
`).buffer):this.dataType.equals(y.JSON)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.map(N=>Br.encodeString(N)).join(`
|
|
4
|
-
`)}
|
|
5
|
-
`).buffer):this.dataType.usesBigInt&&typeof
|
|
6
|
-
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(y.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(n=>e.parse(Br.decodeString(n)))}get byteCapacity(){return new Z(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Be?this.byteCapacity:this.dataType.isVariable?new Z(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Be?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const n=[0];return this.data.forEach((r,s)=>{r===Fr&&(e++,n.push(s+1))}),this._cachedIndexes=n,this.cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let s=0;s<this.length;s++)r[s]=kf(this.dataType,e,this.data[s],n);return new He({data:r.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(y.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this.cachedMax=e.reduce((n,r)=>n>r?n:r)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),at(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(y.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this.cachedMin=e.reduce((n,r)=>n<r?n:r)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),at(this.cachedMin,this.sampleOffset))}get bounds(){return ot(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const n=e.cachedMin??e.calcRawMin();n<this.cachedMin&&(this.cachedMin=n)}if(this.cachedMax!=null){const n=e.cachedMax??e.calcRawMax();n>this.cachedMax&&(this.cachedMax=n)}}atAlignment(e,n){const r=Number((e-this.alignment)/this.alignmentMultiple);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n=!1){if(this.dataType.isVariable)return this.atVariable(e,n??!1);if(this.dataType.equals(y.UUID))return this.atUUID(e,n);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return at(r,this.sampleOffset)}atUUID(e,n){e<0&&(e=this.length+e);const r=to(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(r==null){if(n)throw new Error(`[series] - no value at index ${e}`);return}return r}atVariable(e,n){let r=0,s=0;if(this._cachedIndexes!=null)r=this._cachedIndexes[e],s=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===Fr){if(e===0){s=o;break}r=o+1,e--}if(s===0&&(s=this.data.length),r>=s||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,s);return this.dataType.equals(y.STRING)?new TextDecoder().decode(a):Da(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const s=Hh(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=s(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(y.FLOAT32)&&!this.dataType.equals(y.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:s}=this.gl;if(n==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Be){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Be}as(e){return Mf(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:ji(this.alignmentBounds.lower),upper:ji(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return ot(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Uf(this);return this.dataType.equals(y.JSON)?new Pf(e):e}return this.dataType.equals(y.UUID)?new Lf(this):new Df(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new Ri(this,e,n??this.length)}subAlignmentIterator(e,n){const r=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),s=Math.ceil(Number(n-this.alignment)/Number(this.alignmentMultiple));return new Ri(this,r,s)}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new He({data:r,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let s;return e?s=this.data.subarray(n,r):s=this.data.slice(n,r),new He({data:s,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new He({data:this.buffer,dataType:this.dataType,timeRange:re.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(n=>n.toString());else{for(let n=0;n<5;n++)e+=`${this.at(n)?.toString()}`,e+=",";e+="...,";for(let n=-5;n<0;n++)e+=this.at(n)?.toString(),n<-1&&(e+=",")}return e+="])",e}};const Rf=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof ro?!0:eo(t),jf=Qh(no,ro);let Ri=class{series;end;index;constructor(e,n,r){this.series=e;const s=ot(0,e.length+1);this.end=xi(s,r),this.index=xi(s,n)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Uf=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,n=this.series.data;for(;this.index<n.length&&n[this.index]!==Fr;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}},Pf=class so{wrapped;static schema=i.z.record(i.z.string(),i.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Br.decodeString(e.value,so.schema)}}};class Lf{series;index;data;density;constructor(e){if(!e.dataType.equals(y.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=y.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=to(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}class Df{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}const ji=t=>{const e=t>>32n,n=t&0xffffffffn;return{domain:e,sample:n}},Bf=async t=>await new Promise(e=>setTimeout(e,z.fromMilliseconds(t).milliseconds));let qf=class{config;retries;interval;constructor(e){this.config={baseInterval:new z(e?.baseInterval??z.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??Bf},this.retries=0,this.interval=new z(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:n,sleepFn:r}=this.config;return this.retries>=e?!1:(await r(this.interval),this.interval=this.interval.mult(n),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}};const Ff=i.z.object({baseInterval:z.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Yf=Object.freeze(Object.defineProperty({__proto__:null,Breaker:qf,breakerConfigZ:Ff},Symbol.toStringTag,{value:"Module"})),Hf=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,io=i.z.string().regex(Hf),Me=i.z.number().min(0).max(255),zs=i.z.number().min(0).max(1),ao=i.z.tuple([Me,Me,Me,zs]),Vf=i.z.tuple([Me,Me,Me]),Gf=i.z.object({rgba255:ao}),Wf=i.z.object({r:Me,g:Me,b:Me,a:zs}),Jf=i.z.number().min(0).max(360),Kf=i.z.number().min(0).max(100),Xf=i.z.number().min(0).max(100),Qf=i.z.tuple([Jf,Kf,Xf,zs]),Ts=i.z.union([io,Vf,ao,Qf,Gf,Wf]),oo=Ts.transform(t=>Os(t)),Os=(t,e=1)=>{if(t=Ts.parse(t),typeof t=="string")return ed(t,e);if(Array.isArray(t)){if(t.length<3||t.length>4)throw new Error(`Invalid color: [${t.join(", ")}]`);return t.length===3?[...t,e]:t}return"a"in t&&"r"in t?[t.r,t.g,t.b,t.a]:t.rgba255},ed=(t,e=1)=>(t=io.parse(t),t=td(t),[En(t,0),En(t,2),En(t,4),t.length===8?En(t,6)/255:e]),En=(t,e)=>parseInt(t.slice(e,e+2),16),td=t=>t.startsWith("#")?t.slice(1):t;Os("#000000");Os("#ffffff");const nd=i.z.object({key:i.z.string(),color:Ts,position:i.z.number(),switched:i.z.boolean().optional()});i.z.array(nd);const rd=i.z.object({key:i.z.string(),name:i.z.string(),color:oo});i.z.object({key:i.z.string(),name:i.z.string(),swatches:i.z.array(rd)});i.z.int().min(0).max(255);i.z.object({name:i.z.string(),key:i.z.string()});const sd=t=>Object.getOwnPropertySymbols(globalThis).includes(t),id=(t,e)=>{const n=Symbol.for(t);if(!sd(n)){const r=e();Object.defineProperty(globalThis,n,{value:r})}return()=>globalThis[n]},co="sy_x_error",ad=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(t):e instanceof Error?e.message.startsWith(t):typeof e!="string"?!1:e.startsWith(t),on=t=>class Ut extends Error{static discriminator=co;discriminator=Ut.discriminator;static TYPE=t;type=Ut.TYPE;static matches=ad(t);matches=Ut.matches;constructor(n,r){super(n,r),this.name=Ut.TYPE}static sub(n){return on(`${t}.${n}`)}},uo=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!==co)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},zt="unknown",Yr="nil";let od=class{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Yr,data:""};if(uo(e))for(const n of this.providers){const r=n.encode(e);if(r!=null)return r}if(e instanceof Error)return{type:zt,data:e.message};if(typeof e=="string")return{type:zt,data:e};try{return{type:zt,data:JSON.stringify(e)}}catch{return{type:zt,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===Yr)return null;if(e.type===zt)return new Hr(e.data);for(const n of this.providers){const r=n.decode(e);if(r!=null)return r}return new Hr(e.data)}};const Ss=id("synnax-error-registry",()=>new od),cd=({encode:t,decode:e})=>Ss().register({encode:t,decode:e}),ud=t=>Ss().encode(t),ld=t=>t==null?null:Ss().decode(t);let Hr=class extends on("unknown"){};const hd=i.z.object({type:i.z.string(),data:i.z.string()});class fd extends on("canceled"){}let dd=class extends on("not_implemented"){};const We=Object.freeze(Object.defineProperty({__proto__:null,Canceled:fd,NONE:Yr,NotImplemented:dd,UNKNOWN:zt,Unknown:Hr,createTyped:on,decode:ld,encode:ud,isTyped:uo,payloadZ:hd,register:cd},Symbol.toStringTag,{value:"Module"}));i.z.string().regex(/^(?:$|(?:\/(?:[^~/]|~0|~1)*)+)$/,"must be a valid JSON pointer (RFC 6901)");i.z.union([i.z.string(),i.z.number(),i.z.boolean(),i.z.null()]);i.z.enum(["string","number","boolean","null"]);i.z.object({key:i.z.string(),value:i.z.string()});const pd=i.uuid();i.object({key:pd,name:i.string().min(1),color:oo});i.z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/);const yd=["standard","scientific","engineering"];i.z.enum(yd);const md=i.z.union([i.z.string(),i.z.number()]);i.z.record(md,i.z.unknown());const gd=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";gd();const wd=["macOS","Windows","Linux"],bd=["macos","windows","linux"],vd={macos:"macOS",windows:"Windows",linux:"Linux"};i.z.enum(wd).or(i.z.enum(bd).transform(t=>vd[t]));i.z.enum(["success","info","warning","error","loading","disabled"]);i.z.object({stack:i.z.string(),error:i.z.instanceof(Error)});const zd=(...t)=>t.map(lo).join(""),lo=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Td=t=>t.endsWith("/")?t.slice(0,-1):t,Od=(t,e="")=>t===null?"":`?${Object.entries(t).filter(([,n])=>n==null?!1:Array.isArray(n)?n.length>0:!0).map(([n,r])=>`${e}${n}=${r}`).join("&")}`;let Sd=class Cn{protocol;host;port;path;constructor({host:e,port:n,protocol:r="",pathPrefix:s=""}){this.protocol=r,this.host=e,this.port=n,this.path=lo(s)}replace(e){return new Cn({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Cn({...this,pathPrefix:zd(this.path,e)})}toString(){return Td(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Cn({host:"unknown",port:0})};i.z.int().min(0).max(ef);let cn=class extends We.createTyped("freighter"){},ze=class extends cn.sub("eof"){constructor(){super("EOF")}},Nt=class extends cn.sub("stream_closed"){constructor(){super("StreamClosed")}},Je=class extends cn.sub("unreachable"){url;constructor(e={}){const{message:n="Unreachable",url:r=Sd.UNKNOWN}=e;super(n),this.url=r}};const Ed=t=>{if(!t.type.startsWith(cn.TYPE))return null;if(ze.matches(t))return{type:ze.TYPE,data:"EOF"};if(Nt.matches(t))return{type:Nt.TYPE,data:"StreamClosed"};if(Je.matches(t))return{type:Je.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},Nd=t=>{if(!t.type.startsWith(cn.TYPE))return null;switch(t.type){case ze.TYPE:return new ze;case Nt.TYPE:return new Nt;case Je.TYPE:return new Je;default:throw new We.Unknown(`Unknown error type: ${t.data}`)}};We.register({encode:Ed,decode:Nd});let ho=class{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,n){let r=0;const s=async a=>{if(r===this.middleware.length)return await n(a);const o=this.middleware[r];return r++,await o(a,s)};return await s(e)}};const fo="Content-Type",$d=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),kd=t=>{const e=t?.cause?.code??t?.code??t?.errno;if(typeof e=="string"&&$d.has(e))return!0;if(t.name==="TypeError"){const n=String(t.message||"").toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(n))return!0}return t?.name==="AbortError"||t?.code,!1},Ad=400;let Id=class extends ho{endpoint;encoder;constructor(e,n,r=!1){return super(),this.endpoint=e.replace({protocol:r?"https":"http"}),this.encoder=n,new Proxy(this,{get:(s,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(s,a,o)})}get headers(){return{[fo]:this.encoder.contentType}}async send(e,n,r,s){n=r?.parse(n);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(n??{});const[,u]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async l=>{const h={...l,params:{}};c.headers={...this.headers,...l.params};let d;try{d=await fetch(l.target,c)}catch(b){if(!(b instanceof Error))throw b;return[h,kd(b)?new Je({url:o}):b]}const f=await d.arrayBuffer();if(d?.ok)return s!=null&&(a=this.encoder.decode(f,s)),[h,null];try{if(d.status!==Ad)return[h,new Error(d.statusText)];const b=this.encoder.decode(f,We.payloadZ),N=We.decode(b);return[h,N]}catch(b){return[h,new Error(`[freighter] - failed to decode error: ${d.statusText}: ${b.message}`)]}});if(u!=null)return[null,u];if(a==null)throw new Error("Response must be defined");return[a,null]}};const Zd=(t,e)=>{class n{wrapped;constructor(s){this.wrapped=s}use(...s){this.wrapped.use(...s)}async send(s,a,o,c){const u=new Yf.Breaker(e);do{const[l,h]=await this.wrapped.send(s,a,o,c);if(h==null)return[l,null];if(!Je.matches(h))return[null,h];if(console.warn(`[freighter] ${u.retryMessage}`,h),!await u.wait())return[l,h]}while(!0)}}return new n(t)},T=async(t,e,n,r,s)=>{const[a,o]=await t.send(e,n,r,s);if(o!=null)throw o;return a},xd=i.z.object({type:i.z.enum(["data","close","open"]),payload:i.z.unknown(),error:i.z.optional(We.payloadZ)});let Cd=class{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,n,r,s){this.codec=n,this.reqSchema=r,this.resSchema=s,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return We.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new ze;if(this.sendClosed)throw new Nt;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");if(this.serverClosed=We.decode(e.error),this.serverClosed==null)throw new Error("Message error must be defined");return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;const e={type:"close"};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((n,r)=>this.receiveCallbacksQueue.push({resolve:n,reject:r}))}addMessage(e){const n=this.receiveCallbacksQueue.shift();n!=null?n.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,xd))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Md?ze.TYPE:Nt.TYPE,data:""}})}};const _d="freighterctx",Md=1e3;let Rd=class Vr extends ho{baseUrl;encoder;secure;static MESSAGE_TYPE="arraybuffer";constructor(e,n,r=!1){super(),this.secure=r,this.baseUrl=e.replace({protocol:r?"wss":"ws"}),this.encoder=n}withCodec(e){const n=new Vr(this.baseUrl,e,this.secure);return n.use(...this.middleware),n}async stream(e,n,r){let s;const[,a]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async o=>{const c=new WebSocket(this.buildURL(e,o)),u={...o,params:{}};c.binaryType=Vr.MESSAGE_TYPE;const l=await this.wrapSocket(c,n,r);return l instanceof Error?[u,l]:(s=l,[u,null])});if(a!=null)throw a;return s}buildURL(e,n){const r=Od({[fo]:this.encoder.contentType,...n.params},_d);return this.baseUrl.child(e).toString()+r}async wrapSocket(e,n,r){return await new Promise(s=>{e.onopen=()=>{const a=new Cd(e,this.encoder,n,r);a.receiveOpenAck().then(o=>{o!=null?s(o):s(a)}).catch(o=>s(o))},e.onerror=a=>{const o=a;s(new Error(o.message))}})}};const po=t=>i.union([i.union([i.null(),i.undefined()]).transform(()=>[]),t.array()]),jd=t=>Array.isArray(t)?t:t==null?[]:[t],yo=(t,e)=>{if(Array.isArray(e))return e.reduce((s,a)=>yo(s,a),t??[]);if(t==null)return[e];const n=t.findIndex(s=>s==e),r=[...t];return n===-1?r.push(e):r[n]=e,r},Ud=((t,e)=>{if(t!=null)return Array.isArray(e)?t.filter(n=>!e.includes(n)):t.filter(n=>n!=e)}),mo=(t,e)=>{if(Array.isArray(e))return e.reduce((s,a)=>mo(s,a),t??[]);if(t==null)return[e];const n=t.findIndex(s=>s.key===e.key),r=[...t];return n===-1?r.push(e):r[n]=e,r},Pd=((t,e)=>{if(t!=null)return Array.isArray(e)?t.filter(n=>!e.includes(n.key)):t.filter(n=>n.key!==e)}),E=Object.freeze(Object.defineProperty({__proto__:null,nullableZ:po,remove:Ud,removeKeyed:Pd,toArray:jd,upsert:yo,upsertKeyed:mo},Symbol.toStringTag,{value:"Module"})),Ld=t=>{const e=t.replace(/_[a-z]/g,n=>n[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},Wn=t=>{const e=(n,r=Gr)=>{if(typeof n=="string")return t(n);if(Array.isArray(n))return n.map(o=>e(o,r));if(!Sr(n))return n;r=qd(r);const s={},a=n;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),r):(Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);r.recursive&&(Sr(c)?Pi(c)||(c=e(c,r)):r.recursiveInArray&&Ui(c)&&(c=[...c].map(l=>{let h=l;return Sr(l)?Pi(h)||(h=e(l,r)):Ui(l)&&(h=e({key:l},r).key),h}))),s[u]=c}),s)};return e},Es=Wn(Ld),Dd=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,n,r)=>`${n}_${r.toLowerCase()}`),go=Wn(Dd),wo=t=>t.length===0?t:t[0].toUpperCase()+t.slice(1),Bd=[Number,String,Uint8Array],Gr={recursive:!0,recursiveInArray:!0},qd=(t=Gr)=>(t.recursive==null?t=Gr:t.recursiveInArray??=!1,t),Ui=t=>t!=null&&Array.isArray(t),Sr=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),Pi=t=>Bd.some(e=>t instanceof e),Fd=t=>t.replace(/[\s_]+/g,"-").replace(/([a-z0-9])([A-Z])/g,(e,n,r)=>`${n}-${r.toLowerCase()}`).toLowerCase(),Yd=Wn(Fd),Hd=t=>{if(t.length===0)return t;let e=t.replace(/[_-]/g," ");return e=e.replace(/([a-z0-9])([A-Z])/g,(n,r,s)=>`${r} ${s}`),e=e.replace(/([A-Z]+)([A-Z][a-z])/g,(n,r,s)=>`${r} ${s}`),e=e.replace(/\s+/g," ").trim(),e=e.replace(/\b\w/g,n=>n.toUpperCase()),e},Vd=Wn(Hd),Gd=Object.freeze(Object.defineProperty({__proto__:null,camelToSnake:go,capitalize:wo,snakeToCamel:Es,toKebab:Yd,toProperNoun:Vd},Symbol.toStringTag,{value:"Module"})),bo=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);class vo{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,n){return this.decodeString(this.decoder.decode(e),n)}decodeString(e,n){const r=JSON.parse(e),s=Es(r);return n!=null?n.parse(s):s}encodeString(e){const n=go(e);return JSON.stringify(n,(r,s)=>ArrayBuffer.isView(s)?Array.from(s):typeof s=="bigint"?s.toString():s)}}class zo{contentType="text/csv";encode(e){const n=this.encodeString(e);return new TextEncoder().encode(n)}decode(e,n){const r=new TextDecoder().decode(e);return this.decodeString(r,n)}encodeString(e){if(!Array.isArray(e)||e.length===0||!bo(e[0]))throw new Error("Payload must be an array of objects");const n=Object.keys(e[0]),r=[n.join(",")];return e.forEach(s=>{const a=n.map(o=>JSON.stringify(s[o]??""));r.push(a.join(","))}),r.join(`
|
|
7
|
-
`)}decodeString(e,
|
|
8
|
-
`).map(c=>c.trim());if(r.length===0)return n!=null?n.parse({}):{};const a=r.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),s.forEach(c=>{const u=c.split(",").map(l=>l.trim());a.forEach((l,h)=>{const d=this.parseValue(u[h]);d!=null&&o[l].push(d)})}),n!=null?n.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const n=Number(e);return isNaN(n)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:n}}class To{contentType="text/plain";encode(e){if(typeof e!="string")throw new Error("TextCodec.encode payload must be a string");return new TextEncoder().encode(e)}decode(e,n){const r=new TextDecoder().decode(e);return n!=null?n.parse(r):r}}const Wt=new vo,Wd=new zo,Jd=new To,Kd=[Wt],Jn=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:zo,CSV_CODEC:Wd,ENCODERS:Kd,JSONCodec:vo,JSON_CODEC:Wt,TEXT_CODEC:Jd,TextCodec:To},Symbol.toStringTag,{value:"Module"})),he=t=>t!=null&&typeof t=="object"&&"value"in t;class dt{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}}const Ns=t=>t!=null&&typeof t=="object"&&"toString"in t,Oo=t=>{if(Ns(t))return t?.toString().length===0;switch(typeof t){case"string":return t.length===0;case"number":return t===0;case"bigint":return t===0n;case"boolean":return!t;case"undefined":return!0;case"object":return t==null;default:return!1}},Xd=t=>!Oo(t),Qd=Object.freeze(Object.defineProperty({__proto__:null,ValueExtension:dt,isCrudeValueExtension:he,isNonZero:Xd,isStringer:Ns,isZero:Oo},Symbol.toStringTag,{value:"Module"})),Wr=t=>[...new Set(t)],ep=(t,e,n=!0)=>{const r=new Map;return t.forEach(s=>{const a=e(s);if(r.has(a)){if(n)return;r.delete(a)}r.set(a,s)}),Array.from(r.values())},Li=Object.freeze(Object.defineProperty({__proto__:null,by:ep,unique:Wr},Symbol.toStringTag,{value:"Module"})),un=(t,e=!1)=>{const n=Ns(t)?"stringer":typeof t;let r;switch(n){case"string":r=(s,a)=>s.localeCompare(a);break;case"stringer":r=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":r=(s,a)=>Number(s)-Number(a);break;case"bigint":r=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":r=(s,a)=>Number(s)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?Eo(r):r},tp=(t,e,n)=>{const r=un(e[t],n);return(s,a)=>r(s[t],a[t])},np=(t,e)=>t.length!==e.length?t.length-e.length:t.every((n,r)=>n===e[r])?0:-1,So=(t,e)=>{if(t.length!==e.length)return t.length-e.length;if(t.length===0)return 0;const n=un(t[0]),r=[...t].sort(n),s=[...e].sort(n);return r.every((a,o)=>a===s[o])?0:-1},rp=(t,e)=>{const n=Wr(t),r=Wr(e);return So(n,r)},sp=(t,e)=>t===e?0:t==="first"&&e==="last"?1:-1,Eo=t=>(e,n)=>t(n,e),pt=0,Ce=-1,_e=1,No=t=>t<pt,$o=t=>t>pt,ip=t=>t>=pt,ko=t=>t===pt,ap=(t,e)=>{const n=/([a-zA-Z]+)|(\d+)/g,r=t.replace(/[\s_.-]+/g,"").match(n),s=e.replace(/[\s_.-]+/g,"").match(n);if(!r||!s)return 0;for(let a=0;a<Math.min(r.length,s.length);a++){const o=r[a],c=s[a];if(isNaN(Number(o))&&isNaN(Number(c))){const u=o.localeCompare(c);if(u!==0)return u}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const u=Number(o)-Number(c);if(u!==0)return u}else return isNaN(Number(o))?-1:1}return r.length-s.length},Ao=(t,e,n)=>{let r=0,s=t.length;const a=n??un(e);for(;r<s;){const o=Math.floor((r+s)/2),c=a(t[o],e);if(c===0)return o;c<0?r=o+1:s=o}return r},op=(t,e,n)=>{const r=Ao(t,e,n);t.splice(r,0,e)},Di=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:pt,GREATER_THAN:_e,LESS_THAN:Ce,insert:op,isEqualTo:ko,isGreaterThan:$o,isGreaterThanEqual:ip,isLessThan:No,newF:un,newFieldF:tp,order:sp,primitiveArrays:np,reverseF:Eo,search:Ao,stringsWithNumbers:ap,uniqueUnorderedPrimitiveArrays:rp,unorderedPrimitiveArrays:So},Symbol.toStringTag,{value:"Module"}));let Io=(t,e=21)=>(n=e)=>{let r="",s=n|0;for(;s--;)r+=t[Math.random()*t.length|0];return r};const Zo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",cp=`0123456789${Zo}`,xo=11,up=Io(Zo,1),lp=Io(cp,xo-1),$s=()=>`${up()}${lp()}`,Co=Object.freeze(Object.defineProperty({__proto__:null,LENGTH:xo,create:$s},Symbol.toStringTag,{value:"Module"})),hp=(t,e)=>n=>n instanceof e||typeof n=="object"&&n!==null&&"discriminator"in n&&n.discriminator===t,fp=2**8-1,_o=2**12-1,dp=2**16-1,pp=2**32-1,yp=2n**64n-1n,mp=2**64-1,gp=-128,wp=2**7-1,bp=-32768,vp=2**15-1,zp=-2147483648,Tp=2**31-1,Op=-(2n**63n),Rn=2n**63n-1n,Sp=-9223372036854776e3,Mo=2**63-1,Zt=t=>(e,n)=>{if(typeof e=="bigint"){if(jn(n))return t(e,BigInt(n));const r=t(Number(e),Number(n));return typeof r=="number"?BigInt(Math.round(r)):r}return t(Number(e),Number(n))},Re=Zt((t,e)=>t-e),je=Zt((t,e)=>t+e),Ep=(t,e,n=1e-4)=>Math.abs(t-e)<n,Jr=(t,e)=>{const n=typeof t=="bigint",r=typeof e=="bigint";return n&&r?t===e:n&&jn(e)?t===BigInt(e):r&&jn(t)?e===BigInt(t):t===e},Np=t=>{const e=10**Math.floor(Math.log10(t));return Math.round(t/e)*e},Ro=Zt((t,e)=>t<=e?t:e),jn=t=>typeof t=="bigint"?!0:Number.isInteger(t),$p=Zt((t,e)=>t>=e?t:e),jo=t=>typeof t=="bigint"?t<0n?-t:t:t<0?-t:t,we=Zt((t,e)=>t*e),ln=Zt((t,e)=>t/e),Uo=i.z.tuple([i.z.number(),i.z.number()]),Po=i.z.object({width:i.z.number(),height:i.z.number()}),kp=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),Ap=["start","center","end"],$t=i.z.object({x:i.z.number(),y:i.z.number()}),Lo=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),ks=["x","y"],Do=i.z.enum(ks),As=["top","right","bottom","left"],Ip=i.z.enum(As),Bo=["left","right"],Is=i.z.enum(Bo),Zs=["top","bottom"],xs=i.z.enum(Zs),Cs=["center"],Kr=i.z.enum(Cs),Zp=[...As,...Cs],_s=i.z.enum(Zp);i.z.enum(Ap);const xp=["first","last"];i.z.enum(xp);i.z.object({lower:i.z.number(),upper:i.z.number()});i.z.enum([...Do.options,..._s.options]);const Cp=i.z.union([Do,_s,i.z.instanceof(String)]),K=(t,e,n)=>{const r={};if(typeof e=="object"&&(n=e,e=void 0),n={makeValid:!0,...n},typeof t=="number"||typeof t=="bigint")e!=null?(r.lower=t,r.upper=e):(r.lower=typeof t=="bigint"?0n:0,r.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[r.lower,r.upper]=t}else r.lower=t.lower,r.upper=t.upper;return n?.makeValid?_p(r):r},_p=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,Bi=(t,e)=>{const n=K(t);return e<n.lower?n.lower:e>=n.upper?n.upper-(typeof n.upper=="number"?1:1n):e},Nn=(t,e)=>{const n=K(t);if(typeof e=="number"||typeof e=="bigint")return e>=n.lower&&e<n.upper;const r=K(e);return r.lower>=n.lower&&r.upper<=n.upper},Mp=t=>{const e=K(t);return e.upper-e.lower},Rp=t=>({lower:Math.min(...t.map(e=>K(e).lower)),upper:Math.max(...t.map(e=>K(e).upper))}),jp=(t,e,n)=>{const r=t.map(c=>K(c)),s=n>0?1:n<0?-1:0;if(s===0)return e;let a=n,o=e;for(;Jr(a,0)===!1;){const c=r.findIndex(u=>s>0?o>=u.lower&&o<u.upper:o>u.lower&&o<=u.upper);if(c!==-1){const u=r[c];let l;if(s>0?l=Re(u.upper,o):l=Re(o,u.lower),l>0){const h=Ro(jo(a),l);if(o=je(o,s>0?h:-h),a=Re(a,s>0?h:-h),Jr(a,0))return o;continue}}if(s>0){const u=r.filter(l=>l.lower>o);if(u.length>0)o=u[0].lower;else return o}else{const u=r.filter(l=>l.upper<o);if(u.length>0)o=u[u.length-1].upper;else return o}}return o},Up=(t,e,n)=>{const r=t.map(o=>K(o));if(e===n)return typeof e=="bigint"?0n:0;const s=e<n?K([e,n]):K([n,e]);let a=typeof e=="bigint"?0n:0;for(const o of r){const c=o.lower>s.lower?o.lower:s.lower,u=o.upper<s.upper?o.upper:s.upper;if(c<u){const l=u-c;a=a+l}}return a},qi=2,Fi=3,Pp=2,Lp=5,Dp=1e-10,Bp=(t,e)=>{if(Number.isNaN(t)||!Number.isFinite(t))return t;const n=Math.abs(t);if(n===0)return 0;let r=!1,s=0;if(e!=null){s=Mp(e);const c=s/n;r=s>0&&c>Dp}if(r){let c;s>=1e3?c=qi:s>=1?c=Fi:c=Math.ceil(-Math.log10(s))+Pp;const u=10**c;return Math.round(t*u)/u}if(n>=1e3){const c=10**qi;return Math.round(t*c)/c}if(n>=1){const c=10**Fi;return Math.round(t*c)/c}const a=Math.floor(Math.log10(n)),o=10**(Lp-a-1);return Math.round(t*o)/o},Xr=Object.freeze(Object.defineProperty({__proto__:null,MAX_INT16:vp,MAX_INT32:Tp,MAX_INT64:Rn,MAX_INT64_NUMBER:Mo,MAX_INT8:wp,MAX_UINT12:_o,MAX_UINT16:dp,MAX_UINT32:pp,MAX_UINT64:yp,MAX_UINT64_NUMBER:mp,MAX_UINT8:fp,MIN_INT16:bp,MIN_INT32:zp,MIN_INT64:Op,MIN_INT64_NUMBER:Sp,MIN_INT8:gp,abs:jo,add:je,closeTo:Ep,div:ln,equal:Jr,isInteger:jn,max:$p,min:Ro,mult:we,roundToNearestMagnitude:Np,smartRound:Bp,sub:Re},Symbol.toStringTag,{value:"Module"})),qp=t=>ks.includes(t)?t:Zs.includes(t)?"y":"x",Fp=Is,Yp=xs,Hp=Kr,Vp={top:"bottom",right:"left",bottom:"top",left:"right",center:"center"},Gp={top:{clockwise:"left",counterclockwise:"right"},right:{clockwise:"top",counterclockwise:"bottom"},bottom:{clockwise:"right",counterclockwise:"left"},left:{clockwise:"bottom",counterclockwise:"top"}},Wp=Cp,ut=t=>t instanceof String||!ks.includes(t)?t:t==="x"?"left":"top",Jp=t=>Vp[ut(t)],Kp=(t,e)=>Gp[t][e],Jt=t=>{const e=ut(t);return e==="top"||e==="bottom"?"y":"x"},Xp=i.z.object({x:Is.or(Kr),y:xs.or(Kr)}),Ms=i.z.object({x:Is,y:xs}),Rs=Object.freeze({x:"left",y:"top"}),qo=Object.freeze({x:"right",y:"top"}),Fo=Object.freeze({x:"left",y:"bottom"}),Yo=Object.freeze({x:"right",y:"bottom"}),js=Object.freeze({x:"center",y:"center"}),Ho=Object.freeze({x:"center",y:"top"}),Vo=Object.freeze({x:"center",y:"bottom"}),Go=Object.freeze({x:"right",y:"center"}),Wo=Object.freeze({x:"left",y:"center"}),Qp=Object.freeze([Wo,Go,Ho,Vo,Rs,qo,Fo,Yo,js]),Jo=(t,e)=>t.x===e.x&&t.y===e.y,ey=(t,e)=>{if(typeof e=="object"){let n=!0;return"x"in e&&(t.x===e.x||(n=!1)),"y"in e&&(t.y===e.y||(n=!1)),n}return t.x===e||t.y===e},ty=t=>[t.x,t.y],_n=t=>Jt(ut(t))==="x",ny=t=>Jt(ut(t))==="y",ry=t=>`${t.x}${wo(t.y)}`,sy=(t,e)=>{let n,r;if(typeof t=="object"&&"x"in t?(n=t.x,r=t.y):(n=ut(t),r=ut(e??t)),Jt(n)===Jt(r)&&n!=="center"&&r!=="center")throw new Error(`[XYLocation] - encountered two locations with the same direction: ${n.toString()} - ${r.toString()}`);const s={...js};return n==="center"?_n(r)?[s.x,s.y]=[r,n]:[s.x,s.y]=[n,r]:r==="center"?_n(n)?[s.x,s.y]=[n,r]:[s.x,s.y]=[r,n]:_n(n)?[s.x,s.y]=[n,r]:[s.x,s.y]=[r,n],s},iy=Object.freeze(Object.defineProperty({__proto__:null,BOTTOM_CENTER:Vo,BOTTOM_LEFT:Fo,BOTTOM_RIGHT:Yo,CENTER:js,CENTER_LEFT:Wo,CENTER_LOCATIONS:Cs,CENTER_RIGHT:Go,OUTER_LOCATIONS:As,TOP_CENTER:Ho,TOP_LEFT:Rs,TOP_RIGHT:qo,XY_LOCATIONS:Qp,X_LOCATIONS:Bo,Y_LOCATIONS:Zs,center:Hp,construct:ut,constructXY:sy,corner:Ms,crude:Wp,direction:Jt,isX:_n,isY:ny,location:_s,outer:Ip,rotate:Kp,swap:Jp,x:Fp,xy:Xp,xyCouple:ty,xyEquals:Jo,xyMatches:ey,xyToString:ry,y:Yp},Symbol.toStringTag,{value:"Module"})),Qr=i.z.union([i.z.number(),$t,Uo,Po,kp,Lo]),j=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},lt=Object.freeze({x:0,y:0}),ay=Object.freeze({x:1,y:1}),oy=Object.freeze({x:1/0,y:1/0}),cy=Object.freeze({x:NaN,y:NaN}),Ko=(t,e,n=0)=>{const r=j(t),s=j(e);return n===0?r.x===s.x&&r.y===s.y:Math.abs(r.x-s.x)<=n&&Math.abs(r.y-s.y)<=n},uy=t=>Ko(t,lt),Us=(t,e,n)=>{const r=j(t),s=j(e,n);return{x:r.x*s.x,y:r.y*s.y}},Xo=(t,e)=>{const n=j(t);return{x:n.x+e,y:n.y}},Qo=(t,e)=>{const n=j(t);return{x:n.x,y:n.y+e}},ec=(t,e,n,...r)=>{if(typeof e=="string"){if(typeof n!="number")throw new Error("The value must be a number.");return e==="x"?Xo(t,n):Qo(t,n)}if(typeof e=="object"&&"x"in e&&typeof e.x=="string"){const s=j(n),a=j(t);return e.x==="left"?s.x=-s.x:e.x==="center"&&(s.x=0),e.y==="top"?s.y=-s.y:e.y==="center"&&(s.y=0),{x:a.x+s.x,y:a.y+s.y}}return[t,e,n??lt,...r].reduce((s,a)=>{const o=j(a);return{x:s.x+o.x,y:s.y+o.y}},lt)},ly=(t,e,n)=>{const r=j(t);return qp(e)==="x"?{x:n,y:r.y}:{x:r.x,y:n}},hy=(t,e)=>{const n=j(t),r=j(e);return Math.sqrt((n.x-r.x)**2+(n.y-r.y)**2)},fy=(t,e)=>{const n=j(t),r=j(e);return{x:r.x-n.x,y:r.y-n.y}},dy=t=>{const e=j(t);return Number.isNaN(e.x)||Number.isNaN(e.y)},py=t=>{const e=j(t);return Number.isFinite(e.x)&&Number.isFinite(e.y)},yy=t=>{const e=j(t);return[e.x,e.y]},my=t=>{const e=j(t);return{left:e.x,top:e.y}},gy=(t,e=0)=>{const n=j(t);return{x:Number(n.x.toFixed(e)),y:Number(n.y.toFixed(e))}},Pt=(t,e)=>{const n=j(t),r=j(e);return{x:n.x-r.x,y:n.y-r.y}},Lt=t=>{const e=j(t),n=Math.hypot(e.x,e.y);return n===0?{x:0,y:0}:{x:-e.y/n,y:e.x/n}},tc=t=>{const e=j(t),n=Math.hypot(e.x,e.y);return n===0?{x:0,y:0}:{x:e.x/n,y:e.y/n}},nc=(...t)=>{const e=t.reduce((n,r)=>ec(n,r),lt);return Us(e,1/t.length)},wy=(t,e)=>{const n=[];for(let r=0;r<t.length;r++){const s=t[r];let a,o,c,u;if(r===0){const l=t[r+1],h=Pt(l,s);o=Lt(h),c=o,u=e}else if(r===t.length-1){const l=t[r-1],h=Pt(s,l);a=Lt(h),c=a,u=e}else{const l=t[r-1],h=t[r+1],d=Pt(s,l),f=Pt(h,s);a=Lt(d),o=Lt(f);const b=Math.acos((d.x*f.x+d.y*f.y)/(Math.hypot(d.x,d.y)*Math.hypot(f.x,f.y))),N=Math.sin(b/2);N===0?u=e:u=e/N,c=tc(nc(a,o))}n.push(Us(c,u))}return n},by=t=>{const e=j(t);return{x:e.y,y:e.x}},vy=t=>{const e=j(t);return{x:Math.round(e.x),y:Math.round(e.y)}},zy=t=>{const e=j(t);return{x:1/e.x,y:1/e.y}},Ty=(t,e,n)=>{const r=j(t),s=j(e),a=n==="clockwise"?Math.PI/2:-Math.PI/2,o=r.x-s.x,c=r.y-s.y,u=o*Math.cos(a)-c*Math.sin(a),l=o*Math.sin(a)+c*Math.cos(a);return{x:u+s.x,y:l+s.y}},Ps=Object.freeze(Object.defineProperty({__proto__:null,INFINITY:oy,NAN:cy,ONE:ay,ZERO:lt,average:nc,calculateMiters:wy,clientXY:Lo,construct:j,couple:yy,crudeZ:Qr,css:my,distance:hy,equals:Ko,isFinite:py,isNan:dy,isZero:uy,normal:Lt,normalize:tc,reciprocal:zy,rotate:Ty,round:vy,scale:Us,set:ly,sub:Pt,swap:by,translate:ec,translateX:Xo,translateY:Qo,translation:fy,truncate:gy,xy:$t},Symbol.toStringTag,{value:"Module"})),$n=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:$n,left:$n,width:$n,height:$n});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:$t,two:$t,root:Ms});const Ls=(t,e,n=0,r=0,s)=>{const a={one:{...lt},two:{...lt},root:s??Rs};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+n,y:a.one.y+r},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:s??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+n,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+n}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},Er=t=>{const e=Ls(t);return{lower:e.one.x,upper:e.two.x}},Nr=t=>{const e=Ls(t);return{lower:e.one.y,upper:e.two.y}},Oy=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,Sy=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([Po,Sy,$t,Uo]);const Ey=(t,e,n)=>e!==void 0&&t<e?e:n!==void 0&&t>n?n:t;i.z.object({offset:Qr,scale:Qr});i.z.object({offset:i.z.number(),scale:i.z.number()});const Ny=t=>(e,n,r,s)=>n==="dimension"?[e,r]:[e,s?r-t:r+t],$y=t=>(e,n,r,s)=>[e,s?r/t:r*t],ky=t=>(e,n,r)=>{if(e===null)return[t,r];const{lower:s,upper:a}=e,{lower:o,upper:c}=t,u=a-s,l=c-o;if(n==="dimension")return[t,r*(l/u)];const h=(r-s)*(l/u)+o;return[t,h]},Ay=t=>(e,n,r)=>[t,r],Iy=()=>(t,e,n)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,n];const{lower:r,upper:s}=t;return[t,s-(n-r)]},Zy=t=>(e,n,r)=>{const{lower:s,upper:a}=t;return r=Ey(r,s,a),[e,r]};class Ge{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new Ge().translate(e)}static magnify(e){return new Ge().magnify(e)}static scale(e,n){return new Ge().scale(e,n)}translate(e){const n=this.new(),r=Ny(e);return r.type="translate",n.ops.push(r),n}magnify(e){const n=this.new(),r=$y(e);return r.type="magnify",n.ops.push(r),n}scale(e,n){const r=K(e,n),s=this.new(),a=ky(r);return a.type="scale",s.ops.push(a),s}clamp(e,n){const r=K(e,n),s=this.new(),a=Zy(r);return a.type="clamp",s.ops.push(a),s}reBound(e,n){const r=K(e,n),s=this.new(),a=Ay(r);return a.type="re-bound",s.ops.push(a),s}invert(){const e=Iy();e.type="invert";const n=this.new();return n.ops.push(e),n}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new Ge;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,n){return this.currBounds=null,this.ops.reduce(([r,s],a)=>a(r,e,s,this.reversed),[null,n])[1]}reverse(){const e=this.new();e.ops.reverse();const n=[];return e.ops.forEach((r,s)=>{if(r.type==="scale"||n.some(([o,c])=>s>=o&&s<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>s);a!==-1&&n.push([s,a])}),n.forEach(([r,s])=>{const a=e.ops.slice(r,s);a.unshift(e.ops[s]),e.ops.splice(r,s-r+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new Ge}class Ee{x;y;currRoot;constructor(e=new Ge,n=new Ge,r=null){this.x=e,this.y=n,this.currRoot=r}static translate(e,n){return new Ee().translate(e,n)}static translateX(e){return new Ee().translateX(e)}static translateY(e){return new Ee().translateY(e)}static clamp(e){return new Ee().clamp(e)}static magnify(e){return new Ee().magnify(e)}static scale(e){return new Ee().scale(e)}static reBound(e){return new Ee().reBound(e)}translate(e,n){const r=j(e,n),s=this.copy();return s.x=this.x.translate(r.x),s.y=this.y.translate(r.y),s}translateX(e){const n=this.copy();return n.x=this.x.translate(e),n}translateY(e){const n=this.copy();return n.y=this.y.translate(e),n}magnify(e){const n=this.copy();return n.x=this.x.magnify(e.x),n.y=this.y.magnify(e.y),n}scale(e){const n=this.copy();if(Oy(e)){const r=this.currRoot;return n.currRoot=e.root,r!=null&&!Jo(r,e.root)&&(r.x!==e.root.x&&(n.x=n.x.invert()),r.y!==e.root.y&&(n.y=n.y.invert())),n.x=n.x.scale(Er(e)),n.y=n.y.scale(Nr(e)),n}return n.x=n.x.scale(e.width),n.y=n.y.scale(e.height),n}reBound(e){const n=this.copy();return n.x=this.x.reBound(Er(e)),n.y=this.y.reBound(Nr(e)),n}clamp(e){const n=this.copy();return n.x=this.x.clamp(Er(e)),n.y=this.y.clamp(Nr(e)),n}copy(){const e=new Ee;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return Ls(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new Ee}const xy=$t.extend({root:Ms,units:i.object({x:i.enum(["px","decimal"]),y:i.enum(["px","decimal"])})});xy.partial({root:!0,units:!0});const Cy=i.z.enum(["static","dynamic"]),Yi=365,kn=30,_y=i.z.union([i.z.tuple([i.z.int()]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12)]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12),i.z.int().min(1).max(31)])]),rc=(t,e)=>{const n=new m(e);if(![w.DAY,w.HOUR,w.MINUTE,w.SECOND,w.MILLISECOND,w.MICROSECOND,w.NANOSECOND].some(s=>s.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof m?new m(r):new w(r)};class m extends dt{constructor(e,n="UTC"){if(e==null)super(m.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*m.MILLISECOND.valueOf());else if(typeof e=="string")super(m.parseDateTimeString(e,n).valueOf());else if(Array.isArray(e))super(m.parseDate(e));else{let r=0n;e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=m.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e===Mo?e=Rn:e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=m.MAX:e=m.MIN)),he(e)&&(e=e.value),super(BigInt(e.valueOf())+r)}}static parseDate([e=1970,n=1,r=1]){const s=new Date(e,n-1,r,0,0,0,0);return new m(BigInt(s.getTime())*m.MILLISECOND.valueOf()).truncate(m.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,n="UTC"){const[r,s,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=m.hours(parseInt(r??"00")).add(m.minutes(parseInt(s??"00"))).add(m.seconds(parseInt(o??"00"))).add(m.milliseconds(parseInt(c??"00")));return n==="local"&&(u=u.add(m.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return m.parseTimeString(e,n);if(e.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?$/)!=null){let s=e,a=0;if(e.includes(".")){const l=e.split(".");s=l[0];const h=l[1]||"0";a=parseInt(h.padEnd(3,"0").slice(0,3))}const o=n==="local"?new Date(s.replace("T"," ")):new Date(`${s}Z`),c=BigInt(o.getTime())*m.MILLISECOND.valueOf(),u=BigInt(a)*m.MILLISECOND.valueOf();return c+u}const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new m(BigInt(r.getTime())*m.MILLISECOND.valueOf(),n).valueOf()}toISOString(e="UTC"){if(e==="UTC")return this.date().toISOString();const n=this.date(),r=new w(BigInt(n.getTimezoneOffset())*m.MINUTE.valueOf());return this.sub(r).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new w(BigInt(new Date().getTimezoneOffset())*m.MINUTE.valueOf())}static since(e){return new m().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new m(e).valueOf()}span(e){return this.range(e).span}range(e){return new x(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new m(e).valueOf()}afterEq(e){return this.valueOf()>=new m(e).valueOf()}before(e){return this.valueOf()<new m(e).valueOf()}beforeEq(e){return this.valueOf()<=new m(e).valueOf()}add(e){return new m(je(this.valueOf(),new w(e).valueOf()))}sub(e){return new m(Re(this.valueOf(),new w(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(w.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(w.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(w.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(w.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(m.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(m.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}get localYear(){return this.date().getFullYear()}setYear(e){const n=this.date();return n.setUTCFullYear(e),new m(n)}setLocalYear(e){const n=this.date();return n.setFullYear(e),new m(n)}get month(){return this.date().getUTCMonth()}get localMonth(){return this.date().getMonth()}setMonth(e){const n=this.date();return n.setUTCMonth(e),new m(n)}setLocalMonth(e){const n=this.date();return n.setMonth(e),new m(n)}get day(){return this.date().getUTCDate()}get localDay(){return this.date().getDate()}setDay(e){const n=this.date();return n.setUTCDate(e),new m(n)}setLocalDay(e){const n=this.date();return n.setDate(e),new m(n)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const n=this.date();return n.setHours(e),new m(n)}setHour(e){const n=this.date();return n.setUTCHours(e),new m(n)}get minute(){return this.date().getUTCMinutes()}get localMinute(){return this.date().getMinutes()}setMinute(e){const n=this.date();return n.setUTCMinutes(e),new m(n)}setLocalMinute(e){const n=this.date();return n.setMinutes(e),new m(n)}get second(){return this.date().getUTCSeconds()}get localSecond(){return this.date().getSeconds()}setSecond(e){const n=this.date();return n.setUTCSeconds(e),new m(n)}setLocalSecond(e){const n=this.date();return n.setSeconds(e),new m(n)}get millisecond(){return this.date().getUTCMilliseconds()}get localMillisecond(){return this.date().getMilliseconds()}setMillisecond(e){const n=this.date();return n.setUTCMilliseconds(e),new m(n)}setLocalMillisecond(e){const n=this.date();return n.setMilliseconds(e),new m(n)}toString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}remainder(e){return rc(this,e)}get isToday(){return this.truncate(w.DAY).equals(m.now().truncate(w.DAY))}truncate(e){return this.sub(this.remainder(e))}formatBySpan(e){return e.greaterThanOrEqual(w.days(30))?"shortDate":e.greaterThanOrEqual(w.DAY)?"dateTime":e.greaterThanOrEqual(w.HOUR)?"time":e.greaterThanOrEqual(w.SECOND)?"preciseTime":"ISOTime"}static now(){return new m(new Date)}static max(...e){let n=m.MIN;for(const r of e){const s=new m(r);s.after(n)&&(n=s)}return n}static min(...e){let n=m.MAX;for(const r of e){const s=new m(r);s.before(n)&&(n=s)}return n}static nanoseconds(e,n="UTC"){return new m(e,n)}static NANOSECOND=m.nanoseconds(1);static microseconds(e,n="UTC"){return m.nanoseconds(e*1e3,n)}static MICROSECOND=m.microseconds(1);static milliseconds(e,n="UTC"){return m.microseconds(e*1e3,n)}static MILLISECOND=m.milliseconds(1);static seconds(e,n="UTC"){return m.milliseconds(e*1e3,n)}static SECOND=m.seconds(1);static minutes(e,n="UTC"){return m.seconds(e*60,n)}static MINUTE=m.minutes(1);static hours(e,n="UTC"){return m.minutes(e*60,n)}static HOUR=m.hours(1);static days(e,n="UTC"){return m.hours(e*24,n)}static DAY=m.days(1);static MAX=new m(Rn);static MIN=new m(0);static ZERO=new m(0);static z=i.z.union([i.z.instanceof(m),i.z.object({value:i.z.bigint()}).transform(e=>new m(e.value)),i.z.string().transform(e=>new m(BigInt(e))),i.z.number().transform(e=>new m(e)),i.z.bigint().transform(e=>new m(e)),i.z.date().transform(e=>new m(e)),i.z.custom(e=>e instanceof w).transform(e=>new m(e)),_y.transform(e=>new m(e))]);static sort(e,n){return Number(e.valueOf()-n.valueOf())}}class w extends dt{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),he(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof w?e:e instanceof G?e.period:e instanceof m?new w(e):(he(e)&&(e=e.value),["number","bigint"].includes(typeof e)?w.seconds(e):new w(e))}static fromMilliseconds(e){return e instanceof w?e:e instanceof G?e.period:e instanceof m?new w(e):(he(e)&&(e=e.value),["number","bigint"].includes(typeof e)?w.milliseconds(e):new w(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new w(e).valueOf()}greaterThan(e){return this.valueOf()>new w(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new w(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new w(e).valueOf()}remainder(e){return rc(this,e)}truncate(e){return new w(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(e="full"){if(e==="semantic")return this.toSemanticString();const n=this.truncate(w.DAY),r=this.truncate(w.HOUR),s=this.truncate(w.MINUTE),a=this.truncate(w.SECOND),o=this.truncate(w.MILLISECOND),c=this.truncate(w.MICROSECOND),u=this.truncate(w.NANOSECOND),l=n,h=r.sub(n),d=s.sub(r),f=a.sub(s),b=o.sub(a),N=c.sub(o),k=u.sub(c);let O="";return l.isZero||(O+=`${l.days}d `),h.isZero||(O+=`${h.hours}h `),d.isZero||(O+=`${d.minutes}m `),f.isZero||(O+=`${f.seconds}s `),b.isZero||(O+=`${b.milliseconds}ms `),N.isZero||(O+=`${N.microseconds}µs `),k.isZero||(O+=`${k.nanoseconds}ns`),O.trim()}toSemanticString(){const e=this.valueOf()<0n?-this.valueOf():this.valueOf(),n=new w(e),r=this.valueOf()<0n;if(n.valueOf()===0n)return"0s";if(n.lessThan(w.SECOND))return"< 1s";const s=n.days,a=n.hours,o=n.minutes,c=n.seconds,u=Math.floor(s/Yi),l=Math.floor(s/kn),h=Math.floor(s/7),d=Math.floor(s),f=Math.floor(a),b=Math.floor(o),N=Math.floor(c),k=r?"-":"";if(u>=1){let O=`${u}y`;if(u<2){const S=Math.floor(s%Yi/kn);S>0&&(O+=` ${S}mo`)}return k+O}if(h>=1&&s<kn&&s%7===0){let O=`${h}w`;const S=Math.floor(s%7),A=Math.floor(a-h*7*24);return h<2&&(S>0?O+=` ${S}d`:A>0&&A<24&&(O+=` ${A}h`)),k+O}if(l>=1){let O=`${l}mo`;if(l<3){const S=Math.floor(s%kn);S>0&&(O+=` ${S}d`)}return k+O}if(h>=1){let O=`${h}w`;const S=Math.floor(s%7),A=Math.floor(a-h*7*24);return h<2&&(S>0?O+=` ${S}d`:A>0&&A<24&&(O+=` ${A}h`)),k+O}if(d>=1){let O=`${d}d`;const S=Math.floor(a-d*24);return d<2&&S>0&&(O+=` ${S}h`),k+O}if(f>=1){let O=`${f}h`;if(f<3){const S=Math.floor(o-f*60);S>0&&(O+=` ${S}m`)}return k+O}if(b>=1){let O=`${b}m`;if(b<5){const S=Math.floor(c-b*60);S>0&&(O+=` ${S}s`)}return k+O}return`${k}${N}s`}mult(e){return new w(we(this.valueOf(),e))}div(e){return new w(ln(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(w.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(w.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(w.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(w.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(w.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(w.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new w(e).valueOf()}add(e){return new w(this.valueOf()+new w(e).valueOf())}sub(e){return new w(this.valueOf()-new w(e).valueOf())}static nanoseconds(e=1){return new w(e)}static NANOSECOND=w.nanoseconds(1);static microseconds(e=1){return w.nanoseconds(we(e,1e3))}static MICROSECOND=w.microseconds(1);static milliseconds(e=1){return w.microseconds(we(e,1e3))}static MILLISECOND=w.milliseconds(1);static seconds(e=1){return w.milliseconds(we(e,1e3))}static SECOND=w.seconds(1);static minutes(e=1){return w.seconds(we(e,60))}static MINUTE=w.minutes(1);static hours(e){return w.minutes(we(e,60))}static HOUR=w.hours(1);static days(e){return w.hours(we(e,24))}static DAY=w.days(1);static MAX=new w(Rn);static MIN=new w(0);static ZERO=new w(0);static z=i.z.union([i.z.object({value:i.z.bigint()}).transform(e=>new w(e.value)),i.z.string().transform(e=>new w(BigInt(e))),i.z.number().transform(e=>new w(e)),i.z.bigint().transform(e=>new w(e)),i.z.instanceof(w),i.z.instanceof(m).transform(e=>new w(e)),i.z.custom(e=>e instanceof G).transform(e=>new w(e))])}class G extends dt{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new G(e).valueOf()}get period(){return w.seconds(1/this.valueOf())}sampleCount(e){return new w(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new M(n).valueOf()}span(e){return w.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/new M(n).valueOf())}add(e){return new G(je(this.valueOf(),new G(e).valueOf()))}sub(e){return new G(Re(this.valueOf(),new G(e).valueOf()))}mult(e){return new G(we(this.valueOf(),e))}div(e){return new G(ln(this.valueOf(),e))}static hz(e){return new G(e)}static khz(e){return G.hz(e*1e3)}static z=i.z.union([i.z.number().transform(e=>new G(e)),i.z.instanceof(G)])}class M extends dt{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new I(e*this.valueOf())}add(e){return new M(je(this.valueOf(),new M(e).valueOf()))}sub(e){return new M(Re(this.valueOf(),new M(e).valueOf()))}mult(e){return new M(we(this.valueOf(),e))}div(e){return new M(ln(this.valueOf(),e))}static UNKNOWN=new M(0);static BIT128=new M(16);static BIT64=new M(8);static BIT32=new M(4);static BIT16=new M(2);static BIT8=new M(1);static z=i.z.union([i.z.number().transform(e=>new M(e)),i.z.instanceof(M)])}class x{start;end;constructor(e,n){typeof e=="object"&&"start"in e?(this.start=new m(e.start),this.end=new m(e.end)):(this.start=new m(e),this.end=new m(n))}get span(){return new w(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new x(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,n=w.ZERO){if(n.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let r=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return r<0&&(r=-r),s<0&&(s=-s),r<=n.valueOf()&&s<=n.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,n=w.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const s=m.max(r.start,e.start),a=m.min(r.end,e.end);return a.before(s)?!1:new w(a.sub(s)).greaterThanOrEqual(n)}contains(e){return e instanceof x?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new x(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}static max(...e){return new x(m.min(...e.map(n=>n.start)),m.max(...e.map(n=>n.end)))}static MAX=new x(m.MIN,m.MAX);static ZERO=new x(m.ZERO,m.ZERO);static z=i.z.union([i.z.object({start:m.z,end:m.z}).transform(e=>new x(e.start,e.end)),i.z.instanceof(x)]);static sort(e,n){return m.sort(e.start,n.start)||m.sort(e.end,n.end)}static merge(...e){return x.max(...e.map(n=>new x(n).makeValid()))}}class p extends dt{constructor(e){if(he(e)&&(e=e.value),e instanceof p||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const n=p.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n==null)throw new Error(`unable to find data type for ${e.toString()}`);super(n.valueOf())}}get Array(){const e=p.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(n=>this.equals(n))}toString(e=!1){return e?p.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(p.JSON)||this.equals(p.STRING)||this.equals(p.BYTES)}get isNumeric(){return!this.isVariable&&!this.equals(p.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=p.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(p.UINT8)||this.equals(p.UINT16)||this.equals(p.UINT32)||this.equals(p.UINT64)}get isSignedInteger(){return this.equals(p.INT8)||this.equals(p.INT16)||this.equals(p.INT32)||this.equals(p.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(p.INT32)&&e.equals(p.FLOAT64)||this.equals(p.INT8)&&e.equals(p.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return p.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new p("unknown");static FLOAT64=new p("float64");static FLOAT32=new p("float32");static INT64=new p("int64");static INT32=new p("int32");static INT16=new p("int16");static INT8=new p("int8");static UINT64=new p("uint64");static UINT32=new p("uint32");static UINT16=new p("uint16");static UINT8=new p("uint8");static TIMESTAMP=new p("timestamp");static UUID=new p("uuid");static STRING=new p("string");static JSON=new p("json");static BYTES=new p("bytes");static ARRAY_CONSTRUCTORS=new Map([[p.UINT8.toString(),Uint8Array],[p.UINT16.toString(),Uint16Array],[p.UINT32.toString(),Uint32Array],[p.UINT64.toString(),BigUint64Array],[p.FLOAT32.toString(),Float32Array],[p.FLOAT64.toString(),Float64Array],[p.INT8.toString(),Int8Array],[p.INT16.toString(),Int16Array],[p.INT32.toString(),Int32Array],[p.INT64.toString(),BigInt64Array],[p.TIMESTAMP.toString(),BigInt64Array],[p.STRING.toString(),Uint8Array],[p.JSON.toString(),Uint8Array],[p.UUID.toString(),Uint8Array],[p.BYTES.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,p.UINT8],[Uint16Array.name,p.UINT16],[Uint32Array.name,p.UINT32],[BigUint64Array.name,p.UINT64],[Float32Array.name,p.FLOAT32],[Float64Array.name,p.FLOAT64],[Int8Array.name,p.INT8],[Int16Array.name,p.INT16],[Int32Array.name,p.INT32],[BigInt64Array.name,p.INT64]]);static DENSITIES=new Map([[p.UINT8.toString(),M.BIT8],[p.UINT16.toString(),M.BIT16],[p.UINT32.toString(),M.BIT32],[p.UINT64.toString(),M.BIT64],[p.FLOAT32.toString(),M.BIT32],[p.FLOAT64.toString(),M.BIT64],[p.INT8.toString(),M.BIT8],[p.INT16.toString(),M.BIT16],[p.INT32.toString(),M.BIT32],[p.INT64.toString(),M.BIT64],[p.TIMESTAMP.toString(),M.BIT64],[p.STRING.toString(),M.UNKNOWN],[p.JSON.toString(),M.UNKNOWN],[p.UUID.toString(),M.BIT128],[p.BYTES.toString(),M.UNKNOWN]]);static ALL=[p.UNKNOWN,p.UINT8,p.UINT16,p.UINT32,p.UINT64,p.INT8,p.INT16,p.INT32,p.INT64,p.FLOAT32,p.FLOAT64,p.TIMESTAMP,p.UUID,p.STRING,p.JSON,p.BYTES];static SHORT_STRINGS=new Map([[p.UINT8.toString(),"u8"],[p.UINT16.toString(),"u16"],[p.UINT32.toString(),"u32"],[p.UINT64.toString(),"u64"],[p.INT8.toString(),"i8"],[p.INT16.toString(),"i16"],[p.INT32.toString(),"i32"],[p.INT64.toString(),"i64"],[p.FLOAT32.toString(),"f32"],[p.FLOAT64.toString(),"f64"],[p.TIMESTAMP.toString(),"ts"],[p.UUID.toString(),"uuid"],[p.STRING.toString(),"str"],[p.JSON.toString(),"json"],[p.BYTES.toString(),"bytes"]]);static BIG_INT_TYPES=[p.INT64,p.UINT64,p.TIMESTAMP];static z=i.z.union([i.z.string().transform(e=>new p(e)),i.z.instanceof(p)])}class I extends dt{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return he(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return he(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return he(e)&&(e=e.value),new I(je(this.valueOf(),e.valueOf()))}sub(e){return he(e)&&(e=e.value),new I(Re(this.valueOf(),e.valueOf()))}mult(e){return new I(we(this.valueOf(),e))}div(e){return new I(ln(this.valueOf(),e))}truncate(e){return new I(Math.trunc(this.valueOf()/new I(e).valueOf())*new I(e).valueOf())}remainder(e){return I.bytes(this.valueOf()%new I(e).valueOf())}get gigabytes(){return this.valueOf()/I.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/I.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/I.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/I.TERABYTE.valueOf()}toString(){const e=this.truncate(I.TERABYTE),n=this.truncate(I.GIGABYTE),r=this.truncate(I.MEGABYTE),s=this.truncate(I.KILOBYTE),a=this.truncate(I.BYTE),o=e,c=n.sub(e),u=r.sub(n),l=s.sub(r),h=a.sub(s);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),l.isZero||(d+=`${l.kilobytes}KB `),(!h.isZero||d==="")&&(d+=`${h.valueOf()}B`),d.trim()}static bytes(e=1){return new I(e)}static BYTE=new I(1);static kilobytes(e=1){return I.bytes(new I(e).valueOf()*1e3)}static KILOBYTE=I.kilobytes(1);static megabytes(e=1){return I.kilobytes(new I(e).valueOf()*1e3)}static MEGABYTE=I.megabytes(1);static gigabytes(e=1){return I.megabytes(new I(e).valueOf()*1e3)}static GIGABYTE=I.gigabytes(1);static terabytes(e){return I.gigabytes(new I(e).valueOf()*1e3)}static TERABYTE=I.terabytes(1);static ZERO=new I(0);static z=i.z.union([i.z.number().transform(e=>new I(e)),i.z.instanceof(I)]);get isZero(){return this.valueOf()===0}}i.z.object({start:i.z.number(),end:i.z.number()});i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const sc=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof m||t instanceof w||t instanceof Date},My=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):Re(n,r),Ry=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function jy(t){return typeof t=="string"&&Ry.test(t)}const ee=[];for(let t=0;t<256;++t)ee.push((t+256).toString(16).slice(1));function Uy(t,e=0){return(ee[t[e+0]]+ee[t[e+1]]+ee[t[e+2]]+ee[t[e+3]]+"-"+ee[t[e+4]]+ee[t[e+5]]+"-"+ee[t[e+6]]+ee[t[e+7]]+"-"+ee[t[e+8]]+ee[t[e+9]]+"-"+ee[t[e+10]]+ee[t[e+11]]+ee[t[e+12]]+ee[t[e+13]]+ee[t[e+14]]+ee[t[e+15]]).toLowerCase()}function Py(t,e=0){const n=Uy(t,e);if(!jy(n))throw TypeError("Stringified UUID is invalid");return n}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ic=(t,e)=>Py(t,e),qe=-1,es={[Symbol.iterator]:()=>es,next:()=>({done:!0,value:void 0})},Ly=i.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Dy=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),ts=10,ac=(t,e)=>{if(t==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(t==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},oc="sy_x_telem_series";class te{key;discriminator=oc;dataType;sampleOffset;gl;_data;timeRange=x.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=qe;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=i.z.object({timeRange:x.z.optional(),dataType:p.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([Ly,Dy,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:Cy.default("static").optional()});static z=te.crudeZ.transform(e=>new te(e));constructor(e){By(e)&&(e={data:e}),e.data??=[];const{dataType:n,timeRange:r,sampleOffset:s=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:u=$s(),data:l}=e;if(cc(l)){const f=l;this.key=f.key,this.dataType=f.dataType,this.sampleOffset=f.sampleOffset,this.gl=f.gl,this._data=f._data,this.timeRange=f.timeRange,this.alignment=f.alignment,this.alignmentMultiple=f.alignmentMultiple,this.cachedMin=f.cachedMin,this.cachedMax=f.cachedMax,this.writePos=f.writePos,this._refCount=f._refCount,this.cachedLength=f.cachedLength;return}const h=sc(l),d=Array.isArray(l);if(n!=null)this.dataType=new p(n);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(d||h){let f=l;if(!h){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");f=l[0]}if(typeof f=="string")this.dataType=p.STRING;else if(typeof f=="number")this.dataType=p.FLOAT64;else if(typeof f=="bigint")this.dataType=p.INT64;else if(typeof f=="boolean")this.dataType=p.UINT8;else if(f instanceof m||f instanceof Date||f instanceof m)this.dataType=p.TIMESTAMP;else if(typeof f=="object")this.dataType=p.JSON;else throw new Error(`cannot infer data type of ${typeof f} when constructing a Series from a JS array`)}else this.dataType=new p(l)}if(!d&&!h)this._data=l;else if(d&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let f=h?[l]:l;const b=f[0];(b instanceof m||b instanceof Date||b instanceof w)&&(f=f.map(N=>new m(N).valueOf())),this.dataType.equals(p.STRING)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.join(`
|
|
9
|
-
`)}
|
|
10
|
-
`).buffer):this.dataType.equals(
|
|
11
|
-
`)}
|
|
12
|
-
`).buffer):this.dataType.usesBigInt&&typeof b=="number"?this._data=new this.dataType.Array(f.map(N=>BigInt(Math.round(N)))).buffer:!this.dataType.usesBigInt&&typeof b=="bigint"?this._data=new this.dataType.Array(f.map(Number)).buffer:this._data=new this.dataType.Array(f).buffer}this.key=u,this.alignment=o,this.alignmentMultiple=c,this.sampleOffset=s??0,this.timeRange=r??x.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:n,...r}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const s=new new p(n).Array(e),a=new te({data:s.buffer,dataType:n,...r});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===qe)return 0;const n=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,n);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===qe)return 0;const n=this.capacity-this.writePos,r=e.sub(0,n);return this.writeToUnderlyingData(r),this.cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===qe?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
|
|
13
|
-
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(p.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(n=>e.parse(Wt.decodeString(n)))}get byteCapacity(){return new I(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===qe?this.byteCapacity:this.dataType.isVariable?new I(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===qe?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const n=[0];return this.data.forEach((r,s)=>{r===ts&&(e++,n.push(s+1))}),this._cachedIndexes=n,this.cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let s=0;s<this.length;s++)r[s]=My(this.dataType,e,this.data[s],n);return new te({data:r.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(p.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this.cachedMax=e.reduce((n,r)=>n>r?n:r)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),je(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(p.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this.cachedMin=e.reduce((n,r)=>n<r?n:r)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),je(this.cachedMin,this.sampleOffset))}get bounds(){return K(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const n=e.cachedMin??e.calcRawMin();n<this.cachedMin&&(this.cachedMin=n)}if(this.cachedMax!=null){const n=e.cachedMax??e.calcRawMax();n>this.cachedMax&&(this.cachedMax=n)}}atAlignment(e,n){const r=Number((e-this.alignment)/this.alignmentMultiple);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n=!1){if(this.dataType.isVariable)return this.atVariable(e,n??!1);if(this.dataType.equals(p.UUID))return this.atUUID(e,n);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return je(r,this.sampleOffset)}atUUID(e,n){e<0&&(e=this.length+e);const r=ic(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(r==null){if(n)throw new Error(`[series] - no value at index ${e}`);return}return r}atVariable(e,n){let r=0,s=0;if(this._cachedIndexes!=null)r=this._cachedIndexes[e],s=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===ts){if(e===0){s=o;break}r=o+1,e--}if(s===0&&(s=this.data.length),r>=s||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,s);return this.dataType.equals(p.STRING)?new TextDecoder().decode(a):Es(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const s=un(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=s(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(p.FLOAT32)&&!this.dataType.equals(p.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:s}=this.gl;if(n==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==qe){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=qe}as(e){return ac(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Vi(this.alignmentBounds.lower),upper:Vi(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return K(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new qy(this);return this.dataType.equals(p.JSON)?new Ds(e):e}return this.dataType.equals(p.UUID)?new Fy(this):new Yy(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new Hi(this,e,n??this.length)}subAlignmentIterator(e,n){const r=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),s=Math.ceil(Number(n-this.alignment)/Number(this.alignmentMultiple));return new Hi(this,r,s)}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new te({data:r,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let s;return e?s=this.data.subarray(n,r):s=this.data.slice(n,r),new te({data:s,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new te({data:this.buffer,dataType:this.dataType,timeRange:x.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(n=>n.toString());else{for(let n=0;n<5;n++)e+=`${this.at(n)?.toString()}`,e+=",";e+="...,";for(let n=-5;n<0;n++)e+=this.at(n)?.toString(),n<-1&&(e+=",")}return e+="])",e}}const By=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof te?!0:sc(t),cc=hp(oc,te);class Hi{series;end;index;constructor(e,n,r){this.series=e;const s=K(0,e.length+1);this.end=Bi(s,r),this.index=Bi(s,n)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}class qy{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,n=this.series.data;for(;this.index<n.length&&n[this.index]!==ts;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}}class Ds{wrapped;static schema=i.z.record(i.z.string(),i.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Wt.decodeString(e.value,Ds.schema)}}}class Fy{series;index;data;density;constructor(e){if(!e.dataType.equals(p.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=p.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=ic(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}class Yy{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}class uc{series;constructor(e=[]){if(e.length!==0){const n=e[0].dataType;for(let r=1;r<e.length;r++)if(!e[r].dataType.equals(n))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){return ac(e,this.dataType),this}get dataType(){return this.series.length===0?p.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?x.ZERO:new x(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}get alignment(){return this.series.length===0?0n:this.series[0].alignment}get alignmentBounds(){return this.series.length===0?K(0n,0n):K(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){const n=()=>new Error(`cannot push a ${e.dataType.toString()} series to a ${this.dataType.toString()} multi-series`),r=e.dataType.equals(this.dataType);if(cc(e)){if(this.series.length!==0&&!r)throw n();this.series.push(e)}else{if(this.series.length!==0&&e.series.length!==0&&!r)throw n();this.series.push(...e.series)}}get length(){return this.series.reduce((e,n)=>e+n.length,0)}atAlignment(e,n){for(const r of this.series)if(Nn(r.alignmentBounds,e))return r.atAlignment(e,n);if(n)throw new Error(`[series] - no value at alignment ${e}`)}at(e,n=!1){e<0&&(e=this.length+e);for(const r of this.series){if(e<r.length)return r.at(e,n);e-=r.length}if(n)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,n){return new $r(this,e,n??this.length)}subAlignmentIterator(e,n){if(e>=this.alignmentBounds.upper||n<=this.alignmentBounds.lower)return es;let r=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)r+=o.length;else if(Nn(o.alignmentBounds,e)){r+=Math.ceil(Number(e-o.alignment)/Number(o.alignmentMultiple));break}}let s=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(n<o.alignment)break;if(n>=o.alignmentBounds.upper)s+=o.length;else if(Nn(o.alignmentBounds,n)){s+=Math.ceil(Number(n-o.alignment)/Number(o.alignmentMultiple));break}}return new $r(this,r,s)}subAlignmentSpanIterator(e,n){if(e>=this.alignmentBounds.upper)return es;n=Math.min(n,Number(this.distance(e,this.alignmentBounds.upper)));let r=0;for(let s=0;s<this.series.length;s++){const a=this.series[s];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)r+=a.length;else if(Nn(a.alignmentBounds,e)){r+=Number(e-a.alignment);break}}return new $r(this,r,r+n)}updateGLBuffer(e){this.series.forEach(n=>n.updateGLBuffer(e))}get bounds(){return Rp(this.series.map(e=>e.bounds))}get byteLength(){return new I(this.series.reduce((e,n)=>e+n.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let n=0;for(const r of this.series)e.set(r.data,n),n+=r.length;return new this.dataType.Array(e.buffer)}traverseAlignment(e,n){const r=this.series.map(s=>s.alignmentBounds);return jp(r,e,n)}acquire(e){this.series.forEach(n=>n.acquire(e))}release(){this.series.forEach(e=>e.release())}distance(e,n){const r=this.series.map(s=>s.alignmentBounds);return Up(r,e,n)}parseJSON(e){if(!this.dataType.equals(p.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.series.flatMap(n=>n.parseJSON(e))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Hy(this.series)}toStrings(){return this.series.flatMap(e=>e.toStrings())}}class Hy{series;seriesIndex;internal;constructor(e){this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){const e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[Symbol.iterator](){return this}}class $r{series;index;end;constructor(e,n,r){this.series=e,this.end=r,this.index=n}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}const Vi=t=>{const e=t>>32n,n=t&0xffffffffn;return{domain:e,sample:n}},Vy=async t=>await new Promise(e=>setTimeout(e,w.fromMilliseconds(t).milliseconds));class Gy{config;retries;interval;constructor(e){this.config={baseInterval:new w(e?.baseInterval??w.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??Vy},this.retries=0,this.interval=new w(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:n,sleepFn:r}=this.config;return this.retries>=e?!1:(await r(this.interval),this.interval=this.interval.mult(n),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const Wy=i.z.object({baseInterval:w.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Bs=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Gy,breakerConfigZ:Wy},Symbol.toStringTag,{value:"Module"})),Jy=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Un=i.z.string().regex(Jy),Ue=i.z.number().min(0).max(255),qs=i.z.number().min(0).max(1),Kn=i.z.tuple([Ue,Ue,Ue,qs]),Ky=i.z.tuple([Ue,Ue,Ue]),Xy=i.z.object({rgba255:Kn}),Qy=i.z.object({r:Ue,g:Ue,b:Ue,a:qs}),em=i.z.number().min(0).max(360),tm=i.z.number().min(0).max(100),nm=i.z.number().min(0).max(100),lc=i.z.tuple([em,tm,nm,qs]),Xn=i.z.union([Un,Ky,Kn,lc,Xy,Qy]),hn=Xn.transform(t=>P(t)),rm=t=>hn.safeParse(t).success,sm=t=>Kn.safeParse(t).success,im=(t=>{if(t==null)return;const e=hn.safeParse(t);if(e.success)return fc(e.data);if(typeof t=="string")return t;throw e.error}),P=(t,e=1)=>{if(t=Xn.parse(t),typeof t=="string")return Mn(t,e);if(Array.isArray(t)){if(t.length<3||t.length>4)throw new Error(`Invalid color: [${t.join(", ")}]`);return t.length===3?[...t,e]:t}return"a"in t&&"r"in t?[t.r,t.g,t.b,t.a]:t.rgba255},hc=(t,e)=>{if(t==null||e==null)return t==e;const n=P(t),r=P(e);return n.every((s,a)=>s===r[a])},am=(t=>{if(t==null)return;const[e,n,r,s]=P(t),a=Math.round(s*255);return`#${An(e)}${An(n)}${An(r)}${a===255?"":An(a)}`}),fc=t=>{const[e,n,r,s]=P(t);return`rgba(${e}, ${n}, ${r}, ${s})`},om=t=>`rgb(${dc(t)})`,dc=t=>{const[e,n,r]=P(t);return`${e}, ${n}, ${r}`},cm=t=>[...Fs(t),Vt(t)],Fs=t=>[Ft(t)/255,Yt(t)/255,Ht(t)/255],Ft=t=>P(t)[0],Yt=t=>P(t)[1],Ht=t=>P(t)[2],Vt=t=>P(t)[3],um=t=>hc(Ys,t),lm=t=>bm(P(t)),hm=(t,e)=>{const[n,r,s]=P(t);if(e>100)throw new Error(`Color opacity must be between 0 and 100, got ${e}`);return e>1&&(e/=100),[n,r,s,e]},Kt=t=>{const[e,n,r]=Fs(t).map(s=>s<=.03928?s/12.92:((s+.055)/1.055)**2.4);return Number((.2126*e+.7152*n+.0722*r).toFixed(3))},fm=t=>{const[e,n,r]=Fs(t);return 1-(Math.max(e,n,r)-Math.min(e,n,r))},ns=(t,e)=>{const n=P(t),r=P(e),s=Kt(n),a=Kt(r);return(Math.max(s,a)+.5)/(Math.min(s,a)+.5)},dm=(t,...e)=>{if(e.length===0)throw new Error("[Color.pickByContrast] - must provide at least one color");const n=P(t),[r]=e.sort((s,a)=>ns(n,a)-ns(n,s));return P(r)},pm=t=>Kt(t)<.5,ym=t=>Kt(t)>.5,Mn=(t,e=1)=>(t=Un.parse(t),t=mm(t),[In(t,0),In(t,2),In(t,4),t.length===8?In(t,6)/255:e]),Ys=[0,0,0,0],An=t=>Math.floor(t).toString(16).padStart(2,"0"),In=(t,e)=>parseInt(t.slice(e,e+2),16),mm=t=>t.startsWith("#")?t.slice(1):t,Gi={black:"#000000",white:"#ffffff",red:"#ff0000",green:"#008000",blue:"#0000ff",yellow:"#ffff00",cyan:"#00ffff",magenta:"#ff00ff",silver:"#c0c0c0",gray:"#808080",grey:"#808080",maroon:"#800000",olive:"#808000",lime:"#00ff00",aqua:"#00ffff",teal:"#008080",navy:"#000080",fuchsia:"#ff00ff",purple:"#800080",orange:"#ffa500",brown:"#a52a2a",tan:"#d2b48c",gold:"#ffd700",indigo:"#4b0082",violet:"#ee82ee",pink:"#ffc0cb",coral:"#ff7f50",salmon:"#fa8072",khaki:"#f0e68c",crimson:"#dc143c",transparent:"transparent"},gm=t=>{if(!t)return;const e=t.trim().toLowerCase();if(!(e==="transparent"||e==="none")){if(e.startsWith("#")){if(e.length===4){const n=e[1],r=e[2],s=e[3],a=`#${n}${n}${r}${r}${s}${s}`;if(Un.safeParse(a).success)return Mn(a)}return(e.length===7||e.length===9)&&Un.safeParse(e).success?Mn(e):void 0}if(e.startsWith("rgb")){const n=e.match(/rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/);if(n){const[,r,s,a,o]=n;return[parseInt(r),parseInt(s),parseInt(a),o?parseFloat(o):1]}}if(Gi[e])return Mn(Gi[e])}},wm=t=>{t=lc.parse(t);let[e,n,r]=t;const s=t[3];e/=360,n/=100,r/=100;let a,o,c;if(n===0)a=o=c=r;else{const u=r<.5?r*(1+n):r+n-r*n,l=2*r-u;a=kr(l,u,e+1/3),o=kr(l,u,e),c=kr(l,u,e-1/3)}return[Math.round(a*255),Math.round(o*255),Math.round(c*255),s]},kr=(t,e,n)=>(n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+(e-t)*6*n:n<1/2?e:n<2/3?t+(e-t)*(2/3-n)*6:t),bm=t=>{t=Kn.parse(t);let[e,n,r]=t;const s=t[3];e/=255,n/=255,r/=255;const a=Math.max(e,n,r),o=Math.min(e,n,r);let c,u,l=(a+o)/2;if(a===o)c=u=0;else{const h=a-o;u=l>.5?h/(2-a-o):h/(a+o),a===e?c=(n-r)/h+(n<r?6:0):a===n?c=(r-e)/h+2:c=(e-n)/h+4,c/=6}return c*=360,u*=100,l*=100,[Math.round(c),Math.round(u),Math.round(l),s]},vm=P("#000000"),zm=P("#ffffff"),pc=i.z.object({key:i.z.string(),color:Xn,position:i.z.number(),switched:i.z.boolean().optional()}),Tm=i.z.array(pc),Om=(t,e)=>{if(t.length===0)return Ys;if(t=t.slice().sort((n,r)=>n.position-r.position),e<=t[0].position)return P(t[0].color);if(e>=t[t.length-1].position)return P(t[t.length-1].color);for(let n=0;n<t.length-1;n++){const r=t[n],s=t[n+1];if(e<r.position||e>s.position)continue;if(e===r.position)return P(r.color);if(e===s.position)return P(s.color);const a=(e-r.position)/(s.position-r.position),o=P(r.color),c=P(s.color),u=Math.round(Ft(o)+a*(Ft(c)-Ft(o))),l=Math.round(Yt(o)+a*(Yt(c)-Yt(o))),h=Math.round(Ht(o)+a*(Ht(c)-Ht(o))),d=Vt(o)+a*(Vt(c)-Vt(o));return P([u,l,h,d])}return P(t[t.length-1].color)},Sm=i.z.object({key:i.z.string(),name:i.z.string(),color:hn}),Em=i.z.object({key:i.z.string(),name:i.z.string(),swatches:i.z.array(Sm)}),yc=Object.freeze(Object.defineProperty({__proto__:null,BLACK:vm,WHITE:zm,ZERO:Ys,aValue:Vt,bValue:Ht,colorZ:hn,construct:P,contrast:ns,crudeZ:Xn,cssString:im,equals:hc,fromCSS:gm,fromGradient:Om,fromHSLA:wm,gValue:Yt,gradientZ:Tm,grayness:fm,hex:am,hsla:lm,isColor:sm,isCrude:rm,isDark:pm,isLight:ym,isZero:um,luminance:Kt,paletteZ:Em,pickByContrast:dm,rValue:Ft,rgbCSS:om,rgbString:dc,rgba1:cm,rgbaCSS:fc,setAlpha:hm,stopZ:pc},Symbol.toStringTag,{value:"Module"})),mc=i.z.int().min(0).max(255),gc=255,wc=0,Nm={lower:wc,upper:gc+1},bc=i.z.object({name:i.z.string(),key:i.z.string()}),Xt=t=>i.z.object({subject:bc,resource:t,authority:mc}),$m=(...t)=>e=>e.filter(n=>{let r=!1;return n.to!=null&&(r=t.includes(n.to.resource)),n.from!=null&&!r&&(r=t.includes(n.from.resource)),r}),vc=t=>i.z.object({from:Xt(t),to:i.z.null()}),zc=t=>i.z.object({from:i.z.null(),to:Xt(t)}),km=t=>i.z.union([vc(t),zc(t),i.z.object({from:Xt(t),to:Xt(t)})]),pe=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:gc,AUTHORITY_BOUNDS:Nm,ZERO_AUTHORITY:wc,acquireZ:zc,authorityZ:mc,filterTransfersByChannelKey:$m,releaseZ:vc,stateZ:Xt,subjectZ:bc,transferZ:km},Symbol.toStringTag,{value:"Module"})),Am=t=>{switch(typeof t){case"bigint":case"number":return t.toString();case"boolean":return t?"1":"0";case"undefined":return"";case"string":case"symbol":case"function":return Wi(t.toString());case"object":return t==null?"":Wi(JSON.stringify(t))}},Im=/[",\n]/,Wi=t=>Im.test(t)?`"${t.replace(/"/g,'""')}"`:t,Ji=Object.freeze(Object.defineProperty({__proto__:null,formatValue:Am},Symbol.toStringTag,{value:"Module"})),Zm=(t,e)=>{let n=null;return e===0?t:(...r)=>{n!==null&&(clearTimeout(n),n=null),n=setTimeout(()=>t(...r),e)}},rs=".",xm=(t,e,n=rs)=>{const r=t.split(n);return r.map((s,a)=>{const o=e(s,a,r);return o==null?null:typeof o=="string"?o:o.join(n)}).filter(s=>s!=null).join(n)},Cm=(t,e)=>{if(!Array.isArray(t))return t[e];const n=t[e];if(n!=null||t.length==0)return n;const r=t[0];if(typeof r=="object"&&"key"in r)return t.find(s=>s.key===e)},_m=((t,e,n={optional:!1})=>{const{optional:r,getter:s=Cm}=n;if(e==="")return t;const a=e.split(rs);if(a.length===1){const c=s(t,a[0]);if(c===void 0){if(r)return null;throw new Error(`Path ${e} does not exist. ${a[0]} is undefined`)}return c}const o=(c,u)=>{if(u>=a.length)return c;for(let l=a.length-u;l>=1;l--){const h=a.slice(u,u+l).join(rs),d=s(c,h);if(d!==void 0){if(u+l===a.length)return d;if(d===null){if(r)return null;throw new Error(`Path ${e} does not exist. ${h} is null`)}return o(d,u+l)}}if(r)return null;throw new Error(`Path ${e} does not exist. ${a[u]} is undefined`)};return o(t,0)}),Mm=t=>Object.getOwnPropertySymbols(globalThis).includes(t),Rm=(t,e)=>{const n=Symbol.for(t);if(!Mm(n)){const r=e();Object.defineProperty(globalThis,n,{value:r})}return()=>globalThis[n]},Tc="sy_x_error",jm=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(t):e instanceof Error?e.message.startsWith(t):typeof e!="string"?!1:e.startsWith(t),fn=t=>class Dt extends Error{static discriminator=Tc;discriminator=Dt.discriminator;static TYPE=t;type=Dt.TYPE;static matches=jm(t);matches=Dt.matches;constructor(n,r){super(n,r),this.name=Dt.TYPE}static sub(n){return fn(`${t}.${n}`)}},Oc=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!==Tc)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},Tt="unknown",ss="nil";class Um{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:ss,data:""};if(Oc(e))for(const n of this.providers){const r=n.encode(e);if(r!=null)return r}if(e instanceof Error)return{type:Tt,data:e.message};if(typeof e=="string")return{type:Tt,data:e};try{return{type:Tt,data:JSON.stringify(e)}}catch{return{type:Tt,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===ss)return null;if(e.type===Tt)return new is(e.data);for(const n of this.providers){const r=n.decode(e);if(r!=null)return r}return new is(e.data)}}const Hs=Rm("synnax-error-registry",()=>new Um),Pm=({encode:t,decode:e})=>Hs().register({encode:t,decode:e}),Lm=t=>Hs().encode(t),Dm=t=>t==null?null:Hs().decode(t);class is extends fn("unknown"){}const Bm=i.z.object({type:i.z.string(),data:i.z.string()});class qm extends fn("canceled"){}class Fm extends fn("not_implemented"){}const Le=Object.freeze(Object.defineProperty({__proto__:null,Canceled:qm,NONE:ss,NotImplemented:Fm,UNKNOWN:Tt,Unknown:is,createTyped:fn,decode:Dm,encode:Lm,isTyped:Oc,payloadZ:Bm,register:Pm},Symbol.toStringTag,{value:"Module"}));i.z.string().regex(/^(?:$|(?:\/(?:[^~/]|~0|~1)*)+)$/,"must be a valid JSON pointer (RFC 6901)");i.z.union([i.z.string(),i.z.number(),i.z.boolean(),i.z.null()]);i.z.enum(["string","number","boolean","null"]);i.z.object({key:i.z.string(),value:i.z.string()});const Sc=i.uuid(),Ec=i.object({key:Sc,name:i.string().min(1),color:hn}),Nc=Object.freeze(Object.defineProperty({__proto__:null,keyZ:Sc,labelZ:Ec},Symbol.toStringTag,{value:"Module"})),as=i.z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/),Ym=(t,e)=>{const n=t.split("."),r=e.split("."),s=Math.max(n.length,r.length);for(let a=0;a<s;a++){const o=n[a],c=r[a];if(o===void 0)return Ce;if(c===void 0)return _e;const u=/^\d+$/.test(o),l=/^\d+$/.test(c);if(u&&!l)return Ce;if(!u&&l)return _e;if(u&&l){const h=parseInt(o),d=parseInt(c);if(h<d)return Ce;if(h>d)return _e}else{if(o<c)return Ce;if(o>c)return _e}}return pt},dn=((t,e,n={})=>{n.checkMajor??=!0,n.checkMinor??=!0,n.checkPatch??=!0;const r=as.parse(t),s=as.parse(e),[a,o]=r.split("-"),[c,u]=s.split("-"),[l,h,d]=a.split(".").map(Number),[f,b,N]=c.split(".").map(Number);if(n.checkMajor){if(l<f)return Ce;if(l>f)return _e}if(n.checkMinor){if(h<b)return Ce;if(h>b)return _e}if(n.checkPatch){if(d<N)return Ce;if(d>N)return _e}return o===void 0&&u===void 0?pt:o===void 0?_e:u===void 0?Ce:Ym(o,u)}),Hm=(t,e,n={})=>ko(dn(t,e,n)),$c=(t,e,n={})=>$o(dn(t,e,n)),Vm=(t,e,n={})=>No(dn(t,e,n)),Gm=({name:t,migrate:e})=>n=>{try{const r=e(n);return console.log(`${t} migrated: ${n.version} -> ${r.version}`),r}catch(r){throw console.log(`${t} failed to migrate from ${n.version}`),console.error(r),r}},Wm=({name:t,migrations:e,targetSchema:n,defaultVersion:r,def:s})=>{const a=Object.keys(e).sort(dn).pop();if(a==null)return l=>{if(l.version??=r,l.version!==s.version)return console.log(`${t} version ${l.version} is newer than latest version of ${s.version}.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require(`zod`);l=c(l);var u=[`create`,`delete`,`retrieve`,`update`],d=l.z.enum(u),f=Object.defineProperty,p=(e,t)=>{let n={};for(var r in e)f(n,r,{get:e[r],enumerable:!0});return t||f(n,Symbol.toStringTag,{value:`Module`}),n},m=(e,t)=>{if(Array.isArray(t))return t.reduce((e,t)=>m(e,t),e??[]);if(e==null)return[t];let n=e.findIndex(e=>e==t),r=[...e];return n===-1?r.push(t):r[n]=t,r},h=(e,t)=>{if(Array.isArray(t))return t.reduce((e,t)=>h(e,t),e??[]);if(e==null)return[t];let n=e.findIndex(e=>e.key===t.key),r=[...e];return n===-1?r.push(t):r[n]=t,r},g=`synnax.caseconv.preserveCase`,ee=e=>{if(typeof e!=`object`||!e)return!1;if(g in e)return!0;let t=e._zod?.def;return t==null?!1:t.innerType&&ee(t.innerType)?!0:t.type===`union`&&Array.isArray(t.options)?t.options.some(ee):t.type===`pipe`?ee(t.in)||ee(t.out):!1},te=e=>{if(e==null)return;let t=e._zod?.def;if(t?.type===`array`&&t.element!=null)return t.element;if(t?.type===`union`&&Array.isArray(t.options))for(let e of t.options){let t=te(e);if(t!=null)return t}},ne=e=>{if(e==null)return null;let t=e;if(t.shape!=null)return t.shape;if(typeof t.sourceType==`function`){let e=t.sourceType();if(e?.shape!=null)return e.shape}let n=t._zod?.def;if(n==null)return null;if(n.innerType!=null)return ne(n.innerType);if(n.type===`union`&&Array.isArray(n.options))for(let e of n.options){let t=ne(e);if(t!=null)return t}return n.type===`pipe`?ne(n.in)??ne(n.out):null},re=e=>{if(e.length===0)return e;let t=e.indexOf(`_`)===-1?e:e.replace(/_[a-z]/g,e=>e[1].toUpperCase()),n=t.charCodeAt(0);return n<65||n>90||t.length>1&&t.charCodeAt(1)>=65&&t.charCodeAt(1)<=90?t:String.fromCharCode(n+32)+t.slice(1)},ie=e=>{let t=(n,r=se)=>{if(typeof n==`string`)return e(n);if(Array.isArray(n)){let e=te(r.schema),i={recursive:r.recursive,recursiveInArray:r.recursiveInArray,schema:e};return n.map(e=>t(e,i))}if(!ce(n)||r.schema!=null&&ee(r.schema))return n;let i=r.recursive??!0,a=r.recursiveInArray??i,o=r.schema,s={},c=n;if(`toJSON`in c&&typeof c.toJSON==`function`)return t(c.toJSON(),r);let l=ne(o),u={recursive:i,recursiveInArray:a,schema:void 0},d=Object.keys(c);for(let n=0;n<d.length;n++){let r=d[n],o=c[r],f=e(r),p=l==null?void 0:l[r]??l[f]??void 0;i&&(ce(o)?le(o)||(u.schema=p,o=t(o,u)):a&&Array.isArray(o)&&(u.schema=te(p),o=o.map(e=>{if(ce(e)){if(!le(e))return t(e,u)}else if(Array.isArray(e))return t({key:e},u).key;return e}))),s[f]=o}return s};return t},ae=ie(re),oe=ie(e=>e.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`)),se={recursive:!0,recursiveInArray:!0,schema:void 0},ce=e=>typeof e==`object`&&!!e&&!Array.isArray(e),le=e=>e instanceof Uint8Array||e instanceof Number||e instanceof String,ue=e=>typeof e==`object`&&!!e&&!Array.isArray(e),de=class{contentType=`application/json`;decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e,t){return this.encoder.encode(this.encodeString(e,t))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){let n=ae(JSON.parse(e),{schema:t});return t==null?n:t.parse(n)}encodeString(e,t){let n=oe((t==null?e:t.parse(e))??{},{schema:t});return JSON.stringify(n,(e,t)=>ArrayBuffer.isView(t)?Array.from(t):typeof t==`bigint`?t.toString():t)}},fe=class{contentType=`text/csv`;encode(e){let t=this.encodeString(e);return new TextEncoder().encode(t)}decode(e,t){let n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!ue(e[0]))throw Error(`Payload must be an array of objects`);let t=Object.keys(e[0]),n=[t.join(`,`)];return e.forEach(e=>{let r=t.map(t=>JSON.stringify(e[t]??``));n.push(r.join(`,`))}),n.join(`
|
|
2
|
+
`)}decodeString(e,t){let[n,...r]=e.trim().split(`
|
|
3
|
+
`).map(e=>e.trim());if(n.length===0)return t==null?{}:t.parse({});let i=n.split(`,`).map(e=>e.trim()),a={};return i.forEach(e=>{a[e]=[]}),r.forEach(e=>{let t=e.split(`,`).map(e=>e.trim());i.forEach((e,n)=>{let r=this.parseValue(t[n]);r!=null&&a[e].push(r)})}),t==null?a:t.parse(a)}parseValue(e){if(e==null||e.length===0)return null;let t=Number(e);return isNaN(t)?e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e:t}},pe=class{contentType=`text/plain`;encode(e){if(typeof e!=`string`)throw Error(`TextCodec.encode payload must be a string`);return new TextEncoder().encode(e)}decode(e,t){let n=new TextDecoder().decode(e);return t==null?n:t.parse(n)}},me=new de;new fe,new pe;var he=e=>typeof e==`object`&&!!e&&`value`in e,ge=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}},_e=e=>typeof e==`object`&&!!e&&`toString`in e,ve=(e,t=!1)=>{let n=_e(e)?`stringer`:typeof e,r;switch(n){case`string`:r=(e,t)=>e.localeCompare(t);break;case`stringer`:r=(e,t)=>e.toString().localeCompare(t.toString());break;case`number`:r=(e,t)=>Number(e)-Number(t);break;case`bigint`:r=(e,t)=>BigInt(e)-BigInt(t)>0n?1:-1;break;case`boolean`:r=(e,t)=>Number(e)-Number(t);break;case`undefined`:r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return t?ye(r):r},ye=e=>(t,n)=>e(n,t),be=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},xe=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,Se=`0123456789${xe}`,Ce=be(xe,1),we=be(Se,10),Te=()=>`${Ce()}${we()}`,Ee=(e,t)=>n=>n instanceof t||typeof n==`object`&&!!n&&`discriminator`in n&&n.discriminator===e,De=2**12-1,Oe=2**16-1,ke=2**20-1,Ae=-128,je=-(2**15),Me=2**15-1,Ne=-(2n**63n),Pe=2n**63n-1n,Fe=-(2**63),Ie=2**63-1,Le=e=>(t,n)=>{if(typeof t==`bigint`){if(Be(n))return e(t,BigInt(n));let r=e(Number(t),Number(n));return typeof r==`number`?BigInt(Math.round(r)):r}return e(Number(t),Number(n))},Re=Le((e,t)=>e-t),ze=Le((e,t)=>e+t),Be=e=>typeof e==`bigint`?!0:Number.isInteger(e),Ve=Le((e,t)=>e*t),He=Le((e,t)=>e/t),Ue=l.z.tuple([l.z.number(),l.z.number()]),We=l.z.enum([`x`,`y`]),Ge=[`top`,`right`,`bottom`,`left`];l.z.enum(Ge);var Ke=[`left`,`right`],qe=l.z.enum(Ke),Je=l.z.enum([`top`,`bottom`]),Ye=[`center`],Xe=l.z.enum(Ye);l.z.enum([`top`,`right`,`bottom`,`left`,`center`]),l.z.enum([`start`,`center`,`end`]),l.z.enum([`first`,`last`]);var Ze=l.z.object({clientX:l.z.number(),clientY:l.z.number()}),Qe=l.z.object({width:l.z.number(),height:l.z.number()}),$e=l.z.object({signedWidth:l.z.number(),signedHeight:l.z.number()});l.z.object({lower:l.z.number(),upper:l.z.number()}),l.z.enum([`x`,`y`,...Ge,...Ye]),l.z.union([We,l.z.enum([...Ge,...Ye]),l.z.instanceof(String)]);var et=(e,t,n)=>{let r={};if(typeof t==`object`&&(n=t,t=void 0),n={makeValid:!0,...n},typeof e==`number`||typeof e==`bigint`)t==null?(r.lower=typeof e==`bigint`?0n:0,r.upper=e):(r.lower=e,r.upper=t);else if(Array.isArray(e)){if(e.length!==2)throw Error(`bounds: expected array of length 2`);[r.lower,r.upper]=e}else r.lower=e.lower,r.upper=e.upper;return n?.makeValid?tt(r):r};Object.freeze({lower:0,upper:0}),Object.freeze({lower:-1/0,upper:1/0}),Object.freeze({lower:0,upper:1}),Object.freeze({lower:-1,upper:1});var tt=e=>e.lower>e.upper?{lower:e.upper,upper:e.lower}:e,nt=(e,t)=>{let n=et(e);return t<n.lower?n.lower:t>=n.upper?n.upper-(typeof n.upper==`number`?1:1n):t};l.z.object({x:qe.or(Xe),y:Je.or(Xe)});var rt=l.z.object({x:qe,y:Je}),it=Object.freeze({x:`left`,y:`top`}),at=Object.freeze({x:`right`,y:`top`}),ot=Object.freeze({x:`left`,y:`bottom`}),st=Object.freeze({x:`right`,y:`bottom`}),ct=Object.freeze({x:`center`,y:`center`}),lt=Object.freeze({x:`center`,y:`top`}),ut=Object.freeze({x:`center`,y:`bottom`}),dt=Object.freeze({x:`right`,y:`center`}),ft=Object.freeze({x:`left`,y:`center`});Object.freeze([ft,dt,lt,ut,it,at,ot,st,ct]);var pt=(e,t)=>e.x===t.x&&e.y===t.y,mt=e=>[e.x,e.y];l.z.enum([`top`,`right`,`bottom`,`left`]);var ht=l.z.object({x:l.z.number(),y:l.z.number()}),gt=l.z.union([l.z.number(),ht,Ue,Qe,$e,Ze]),_t=(e,t)=>{if(typeof e==`string`){if(t===void 0)throw Error(`The y coordinate must be given.`);return e===`x`?{x:t,y:0}:{x:0,y:t}}return typeof e==`number`?{x:e,y:t??e}:Array.isArray(e)?{x:e[0],y:e[1]}:`signedWidth`in e?{x:e.signedWidth,y:e.signedHeight}:`clientX`in e?{x:e.clientX,y:e.clientY}:`width`in e?{x:e.width,y:e.height}:{x:e.x,y:e.y}},vt=Object.freeze({x:0,y:0});Object.freeze({x:1,y:1}),Object.freeze({x:1/0,y:1/0}),Object.freeze({x:NaN,y:NaN});var yt=(e,t)=>{let n=_t(e);return{x:n.x+t,y:n.y}},bt=(e,t)=>{let n=_t(e);return{x:n.x,y:n.y+t}},xt=(e,t,n,...r)=>{if(typeof t==`string`){if(typeof n!=`number`)throw Error(`The value must be a number.`);return t===`x`?yt(e,n):bt(e,n)}if(typeof t==`object`&&`x`in t&&typeof t.x==`string`){let r=_t(n),i=_t(e);return t.x===`left`?r.x=-r.x:t.x===`center`&&(r.x=0),t.y===`top`?r.y=-r.y:t.y===`center`&&(r.y=0),{x:i.x+r.x,y:i.y+r.y}}return[e,t,n??vt,...r].reduce((e,t)=>{let n=_t(t);return{x:e.x+n.x,y:e.y+n.y}},vt)},St=l.z.union([l.z.number(),l.z.string()]);l.z.object({top:St,left:St,width:St,height:St}),l.z.object({left:l.z.number(),top:l.z.number(),right:l.z.number(),bottom:l.z.number()}),l.z.object({one:ht,two:ht,root:rt});var Ct=(e,t,n=0,r=0,i)=>{let a={one:{...vt},two:{...vt},root:i??it};if(typeof e==`number`){if(typeof t!=`number`)throw Error(`Box constructor called with invalid arguments`);return a.one={x:e,y:t},a.two={x:a.one.x+n,y:a.one.y+r},a}return`one`in e&&`two`in e&&`root`in e?{...e,root:i??e.root}:(`getBoundingClientRect`in e&&(e=e.getBoundingClientRect()),`left`in e?(a.one={x:e.left,y:e.top},a.two={x:e.right,y:e.bottom},a):(a.one=e,t==null?a.two={x:a.one.x+n,y:a.one.y+r}:typeof t==`number`?a.two={x:a.one.x+t,y:a.one.y+n}:`width`in t?a.two={x:a.one.x+t.width,y:a.one.y+t.height}:`signedWidth`in t?a.two={x:a.one.x+t.signedWidth,y:a.one.y+t.signedHeight}:a.two=t,a))},wt=(e,t)=>{let n=Ct(e);return{x:t.x===`center`?kt(n).x:Tt(n,t.x),y:t.y===`center`?kt(n).y:Tt(n,t.y)}},Tt=(e,t)=>{let n=Ct(e),r=mt(n.root).includes(t)?Math.min:Math.max;return Ke.includes(t)?r(n.one.x,n.two.x):r(n.one.y,n.two.y)},Et=e=>{let t=Ct(e);return t.two.x-t.one.x},Dt=e=>{let t=Ct(e);return t.two.y-t.one.y},Ot=e=>wt(e,it),kt=e=>xt(Ot(e),{x:Et(e)/2,y:Dt(e)/2}),At=e=>{let t=Ct(e);return{lower:t.one.x,upper:t.two.x}},jt=e=>{let t=Ct(e);return{lower:t.one.y,upper:t.two.y}},Mt=e=>typeof e!=`object`||!e?!1:`one`in e&&`two`in e&&`root`in e;l.z.union([Qe,$e,ht,Ue]);var Nt=(e,t,n)=>t!==void 0&&e<t?t:n!==void 0&&e>n?n:e;l.z.object({offset:gt,scale:gt}),l.z.object({offset:l.z.number(),scale:l.z.number()});var Pt=e=>(t,n,r,i)=>n===`dimension`?[t,r]:[t,i?r-e:r+e],Ft=e=>(t,n,r,i)=>[t,i?r/e:r*e],It=e=>(t,n,r)=>{if(t===null)return[e,r];let{lower:i,upper:a}=t,{lower:o,upper:s}=e,c=a-i,l=s-o;return n===`dimension`?[e,l/c*r]:[e,(r-i)*(l/c)+o]},Lt=e=>(t,n,r)=>[e,r],Rt=()=>(e,t,n)=>{if(e===null)throw Error(`cannot invert without bounds`);if(t===`dimension`)return[e,n];let{lower:r,upper:i}=e;return[e,i-(n-r)]},zt=e=>(t,n,r)=>{let{lower:i,upper:a}=e;return r=Nt(r,i,a),[t,r]},Bt=class e{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(t){return new e().translate(t)}static magnify(t){return new e().magnify(t)}static scale(t,n){return new e().scale(t,n)}translate(e){let t=this.new(),n=Pt(e);return n.type=`translate`,t.ops.push(n),t}magnify(e){let t=this.new(),n=Ft(e);return n.type=`magnify`,t.ops.push(n),t}scale(e,t){let n=et(e,t),r=this.new(),i=It(n);return i.type=`scale`,r.ops.push(i),r}clamp(e,t){let n=et(e,t),r=this.new(),i=zt(n);return i.type=`clamp`,r.ops.push(i),r}reBound(e,t){let n=et(e,t),r=this.new(),i=Lt(n);return i.type=`re-bound`,r.ops.push(i),r}invert(){let e=Rt();e.type=`invert`;let t=this.new();return t.ops.push(e),t}pos(e){return this.exec(`position`,e)}dim(e){return this.exec(`dimension`,e)}new(){let t=new e;return t.ops=this.ops.slice(),t.reversed=this.reversed,t}exec(e,t){return this.currBounds=null,this.ops.reduce(([t,n],r)=>r(t,e,n,this.reversed),[null,t])[1]}reverse(){let e=this.new();e.ops.reverse();let t=[];return e.ops.forEach((n,r)=>{if(n.type===`scale`||t.some(([e,t])=>r>=e&&r<=t))return;let i=e.ops.findIndex((e,t)=>e.type===`scale`&&t>r);i!==-1&&t.push([r,i])}),t.forEach(([t,n])=>{let r=e.ops.slice(t,n);r.unshift(e.ops[n]),e.ops.splice(t,n-t+1,...r)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new e};(class e{x;y;currRoot;constructor(e=new Bt,t=new Bt,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(t,n){return new e().translate(t,n)}static translateX(t){return new e().translateX(t)}static translateY(t){return new e().translateY(t)}static clamp(t){return new e().clamp(t)}static magnify(t){return new e().magnify(t)}static scale(t){return new e().scale(t)}static reBound(t){return new e().reBound(t)}translate(e,t){let n=_t(e,t),r=this.copy();return r.x=this.x.translate(n.x),r.y=this.y.translate(n.y),r}translateX(e){let t=this.copy();return t.x=this.x.translate(e),t}translateY(e){let t=this.copy();return t.y=this.y.translate(e),t}magnify(e){let t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){let t=this.copy();if(Mt(e)){let n=this.currRoot;return t.currRoot=e.root,n!=null&&!pt(n,e.root)&&(n.x!==e.root.x&&(t.x=t.x.invert()),n.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(At(e)),t.y=t.y.scale(jt(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){let t=this.copy();return t.x=this.x.reBound(At(e)),t.y=this.y.reBound(jt(e)),t}clamp(e){let t=this.copy();return t.x=this.x.clamp(At(e)),t.y=this.y.clamp(jt(e)),t}copy(){let t=new e;return t.currRoot=this.currRoot,t.x=this.x,t.y=this.y,t}reverse(){let e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return Ct(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new e}),ht.extend({root:rt,units:l.default.object({x:l.default.enum([`px`,`decimal`]),y:l.default.enum([`px`,`decimal`])})}).partial({root:!0,units:!0});var Vt=l.z.enum([`static`,`dynamic`]),Ht=365,Ut=30,Wt=l.z.union([l.z.tuple([l.z.int()]),l.z.tuple([l.z.int(),l.z.int().min(1).max(12)]),l.z.tuple([l.z.int(),l.z.int().min(1).max(12),l.z.int().min(1).max(31)])]),Gt=(e,t)=>{let n=new _(t);if(![v.DAY,v.HOUR,v.MINUTE,v.SECOND,v.MILLISECOND,v.MICROSECOND,v.NANOSECOND].some(e=>e.equals(n)))throw Error(`Invalid argument for remainder. Must be an even TimeSpan or Timestamp`);let r=e.valueOf()%n.valueOf();return e instanceof _?new _(r):new v(r)},_=class e extends ge{constructor(t,n=`UTC`){if(t==null)super(e.now().valueOf());else if(t instanceof Date)super(BigInt(t.getTime())*e.MILLISECOND.valueOf());else if(typeof t==`string`)super(e.parseDateTimeString(t,n).valueOf());else if(Array.isArray(t))super(e.parseDate(t));else{let r=0n;t instanceof Number&&(t=t.valueOf()),n===`local`&&(r=e.utcOffset.valueOf()),typeof t==`number`&&(isFinite(t)?t=t===Ie?Pe:Math.trunc(t):(isNaN(t)&&(t=0),t=t===1/0?e.MAX:e.MIN)),he(t)&&(t=t.value),super(BigInt(t.valueOf())+r)}}static parseDate([t=1970,n=1,r=1]){let i=new Date(t,n-1,r,0,0,0,0);return new e(BigInt(i.getTime())*e.MILLISECOND.valueOf()).truncate(e.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(t,n=`UTC`){let[r,i,a]=t.split(`:`),o=`00`,s=`00`;a!=null&&([o,s]=a.split(`.`));let c=e.hours(parseInt(r??`00`,10)).add(e.minutes(parseInt(i??`00`,10))).add(e.seconds(parseInt(o??`00`,10))).add(e.milliseconds(parseInt(s??`00`,10)));return n===`local`&&(c=c.add(e.utcOffset)),c.valueOf()}static parseDateTimeString(t,n=`UTC`){if(!t.includes(`/`)&&!t.includes(`-`))return e.parseTimeString(t,n);if(t.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?$/)!=null){let r=t,i=0;if(t.includes(`.`)){let e=t.split(`.`);r=e[0];let n=e[1]||`0`;i=parseInt(n.padEnd(3,`0`).slice(0,3),10)}let a=n===`local`?new Date(r.replace(`T`,` `)):new Date(`${r}Z`);return BigInt(a.getTime())*e.MILLISECOND.valueOf()+BigInt(i)*e.MILLISECOND.valueOf()}let r=new Date(t);return t.includes(`:`)||r.setUTCHours(0,0,0,0),new e(BigInt(r.getTime())*e.MILLISECOND.valueOf(),n).valueOf()}toISOString(t=`UTC`){if(t===`UTC`)return this.date().toISOString();let n=this.date(),r=new v(BigInt(n.getTimezoneOffset())*e.MINUTE.valueOf());return this.sub(r).date().toISOString()}timeString(e=!1,t=`UTC`){let n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){let e=this.date();return`${e.toLocaleString(`default`,{month:`short`})} ${e.toLocaleString(`default`,{day:`numeric`})}`}static get utcOffset(){return new v(BigInt(new Date().getTimezoneOffset())*e.MINUTE.valueOf())}static since(t){return new e().span(t)}date(){return new Date(this.milliseconds)}equals(t){return this.valueOf()===new e(t).valueOf()}span(e){return this.range(e).span}range(e){return new qt(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(t){return this.valueOf()>new e(t).valueOf()}afterEq(t){return this.valueOf()>=new e(t).valueOf()}before(t){return this.valueOf()<new e(t).valueOf()}beforeEq(t){return this.valueOf()<=new e(t).valueOf()}add(t){return new e(ze(this.valueOf(),new v(t).valueOf()))}sub(t){return new e(Re(this.valueOf(),new v(t).valueOf()))}get hours(){return Number(this.valueOf())/Number(v.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(v.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(v.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(v.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(e.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(e.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}get localYear(){return this.date().getFullYear()}setYear(t){let n=this.date();return n.setUTCFullYear(t),new e(n)}setLocalYear(t){let n=this.date();return n.setFullYear(t),new e(n)}get month(){return this.date().getUTCMonth()}get localMonth(){return this.date().getMonth()}setMonth(t){let n=this.date();return n.setUTCMonth(t),new e(n)}setLocalMonth(t){let n=this.date();return n.setMonth(t),new e(n)}get day(){return this.date().getUTCDate()}get localDay(){return this.date().getDate()}setDay(t){let n=this.date();return n.setUTCDate(t),new e(n)}setLocalDay(t){let n=this.date();return n.setDate(t),new e(n)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(t){let n=this.date();return n.setHours(t),new e(n)}setHour(t){let n=this.date();return n.setUTCHours(t),new e(n)}get minute(){return this.date().getUTCMinutes()}get localMinute(){return this.date().getMinutes()}setMinute(t){let n=this.date();return n.setUTCMinutes(t),new e(n)}setLocalMinute(t){let n=this.date();return n.setMinutes(t),new e(n)}get second(){return this.date().getUTCSeconds()}get localSecond(){return this.date().getSeconds()}setSecond(t){let n=this.date();return n.setUTCSeconds(t),new e(n)}setLocalSecond(t){let n=this.date();return n.setSeconds(t),new e(n)}get millisecond(){return this.date().getUTCMilliseconds()}get localMillisecond(){return this.date().getMilliseconds()}setMillisecond(t){let n=this.date();return n.setUTCMilliseconds(t),new e(n)}setLocalMillisecond(t){let n=this.date();return n.setMilliseconds(t),new e(n)}toString(e=`ISO`,t=`UTC`){switch(e){case`ISODate`:return this.toISOString(t).slice(0,10);case`ISOTime`:return this.toISOString(t).slice(11,23);case`time`:return this.timeString(!1,t);case`preciseTime`:return this.timeString(!0,t);case`date`:return this.dateString();case`preciseDate`:return`${this.dateString()} ${this.timeString(!0,t)}`;case`dateTime`:return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}remainder(e){return Gt(this,e)}get isToday(){return this.truncate(v.DAY).equals(e.now().truncate(v.DAY))}truncate(e){return this.sub(this.remainder(e))}formatBySpan(e){return e.greaterThanOrEqual(v.days(30))?`shortDate`:e.greaterThanOrEqual(v.DAY)?`dateTime`:e.greaterThanOrEqual(v.HOUR)?`time`:e.greaterThanOrEqual(v.SECOND)?`preciseTime`:`ISOTime`}static now(){return new e(new Date)}static max(...t){let n=e.MIN;for(let r of t){let t=new e(r);t.after(n)&&(n=t)}return n}static min(...t){let n=e.MAX;for(let r of t){let t=new e(r);t.before(n)&&(n=t)}return n}static nanoseconds(t,n=`UTC`){return new e(t,n)}static NANOSECOND=e.nanoseconds(1);static microseconds(t,n=`UTC`){return e.nanoseconds(t*1e3,n)}static MICROSECOND=e.microseconds(1);static milliseconds(t,n=`UTC`){return e.microseconds(t*1e3,n)}static MILLISECOND=e.milliseconds(1);static seconds(t,n=`UTC`){return e.milliseconds(t*1e3,n)}static SECOND=e.seconds(1);static minutes(t,n=`UTC`){return e.seconds(t*60,n)}static MINUTE=e.minutes(1);static hours(t,n=`UTC`){return e.minutes(t*60,n)}static HOUR=e.hours(1);static days(t,n=`UTC`){return e.hours(t*24,n)}static DAY=e.days(1);static MAX=new e(Pe);static MIN=new e(0);static ZERO=new e(0);static z=l.z.union([l.z.instanceof(e),l.z.object({value:l.z.bigint()}).transform(t=>new e(t.value)),l.z.string().transform(t=>new e(BigInt(t))),l.z.number().transform(t=>new e(t)),l.z.bigint().transform(t=>new e(t)),l.z.date().transform(t=>new e(t)),l.z.custom(e=>e instanceof v).transform(t=>new e(t)),Wt.transform(t=>new e(t))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},v=class e extends ge{constructor(e){typeof e==`number`&&(e=Math.trunc(e.valueOf())),he(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(t){return t instanceof e?t:t instanceof Kt?t.period:t instanceof _?new e(t):(he(t)&&(t=t.value),[`number`,`bigint`].includes(typeof t)?e.seconds(t):new e(t))}static fromMilliseconds(t){return t instanceof e?t:t instanceof Kt?t.period:t instanceof _?new e(t):(he(t)&&(t=t.value),[`number`,`bigint`].includes(typeof t)?e.milliseconds(t):new e(t))}valueOf(){return this.value}lessThan(t){return this.valueOf()<new e(t).valueOf()}greaterThan(t){return this.valueOf()>new e(t).valueOf()}lessThanOrEqual(t){return this.valueOf()<=new e(t).valueOf()}greaterThanOrEqual(t){return this.valueOf()>=new e(t).valueOf()}remainder(e){return Gt(this,e)}truncate(t){return new e(BigInt(Math.trunc(Number(this.valueOf()/t.valueOf())))*t.valueOf())}toString(t=`full`){if(t===`semantic`)return this.toSemanticString();let n=this.truncate(e.DAY),r=this.truncate(e.HOUR),i=this.truncate(e.MINUTE),a=this.truncate(e.SECOND),o=this.truncate(e.MILLISECOND),s=this.truncate(e.MICROSECOND),c=this.truncate(e.NANOSECOND),l=n,u=r.sub(n),d=i.sub(r),f=a.sub(i),p=o.sub(a),m=s.sub(o),h=c.sub(s),g=``;return l.isZero||(g+=`${l.days}d `),u.isZero||(g+=`${u.hours}h `),d.isZero||(g+=`${d.minutes}m `),f.isZero||(g+=`${f.seconds}s `),p.isZero||(g+=`${p.milliseconds}ms `),m.isZero||(g+=`${m.microseconds}µs `),h.isZero||(g+=`${h.nanoseconds}ns`),g.trim()}toSemanticString(){let t=new e(this.valueOf()<0n?-this.valueOf():this.valueOf()),n=this.valueOf()<0n;if(t.valueOf()===0n)return`0s`;if(t.lessThan(e.SECOND))return`< 1s`;let r=t.days,i=t.hours,a=t.minutes,o=t.seconds,s=Math.floor(r/Ht),c=Math.floor(r/Ut),l=Math.floor(r/7),u=Math.floor(r),d=Math.floor(i),f=Math.floor(a),p=Math.floor(o),m=n?`-`:``;if(s>=1){let e=`${s}y`;if(s<2){let t=Math.floor(r%Ht/Ut);t>0&&(e+=` ${t}mo`)}return m+e}if(l>=1&&r<Ut&&r%7==0){let e=`${l}w`,t=Math.floor(r%7),n=Math.floor(i-l*7*24);return l<2&&(t>0?e+=` ${t}d`:n>0&&n<24&&(e+=` ${n}h`)),m+e}if(c>=1){let e=`${c}mo`;if(c<3){let t=Math.floor(r%Ut);t>0&&(e+=` ${t}d`)}return m+e}if(l>=1){let e=`${l}w`,t=Math.floor(r%7),n=Math.floor(i-l*7*24);return l<2&&(t>0?e+=` ${t}d`:n>0&&n<24&&(e+=` ${n}h`)),m+e}if(u>=1){let e=`${u}d`,t=Math.floor(i-u*24);return u<2&&t>0&&(e+=` ${t}h`),m+e}if(d>=1){let e=`${d}h`;if(d<3){let t=Math.floor(a-d*60);t>0&&(e+=` ${t}m`)}return m+e}if(f>=1){let e=`${f}m`;if(f<5){let t=Math.floor(o-f*60);t>0&&(e+=` ${t}s`)}return m+e}return`${m}${p}s`}mult(t){return new e(Ve(this.valueOf(),t))}div(t){return new e(He(this.valueOf(),t))}get days(){return Number(this.valueOf())/Number(e.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(e.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(e.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(e.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(e.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(e.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(t){return this.valueOf()===new e(t).valueOf()}add(t){return new e(this.valueOf()+new e(t).valueOf())}sub(t){return new e(this.valueOf()-new e(t).valueOf())}static nanoseconds(t=1){return new e(t)}static NANOSECOND=e.nanoseconds(1);static microseconds(t=1){return e.nanoseconds(Ve(t,1e3))}static MICROSECOND=e.microseconds(1);static milliseconds(t=1){return e.microseconds(Ve(t,1e3))}static MILLISECOND=e.milliseconds(1);static seconds(t=1){return e.milliseconds(Ve(t,1e3))}static SECOND=e.seconds(1);static minutes(t=1){return e.seconds(Ve(t,60))}static MINUTE=e.minutes(1);static hours(t){return e.minutes(Ve(t,60))}static HOUR=e.hours(1);static days(t){return e.hours(Ve(t,24))}static DAY=e.days(1);static MAX=new e(Pe);static MIN=new e(0);static ZERO=new e(0);static z=l.z.union([l.z.object({value:l.z.bigint()}).transform(t=>new e(t.value)),l.z.string().transform(t=>new e(BigInt(t))),l.z.number().transform(t=>new e(t)),l.z.bigint().transform(t=>new e(t)),l.z.instanceof(e),l.z.instanceof(_).transform(t=>new e(t)),l.z.custom(e=>e instanceof Kt).transform(t=>new e(t))])},Kt=class e extends ge{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(t){return this.valueOf()===new e(t).valueOf()}get period(){return v.seconds(1/this.valueOf())}sampleCount(e){return new v(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new y(t).valueOf()}span(e){return v.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new y(t).valueOf())}add(t){return new e(ze(this.valueOf(),new e(t).valueOf()))}sub(t){return new e(Re(this.valueOf(),new e(t).valueOf()))}mult(t){return new e(Ve(this.valueOf(),t))}div(t){return new e(He(this.valueOf(),t))}static hz(t){return new e(t)}static khz(t){return e.hz(t*1e3)}static z=l.z.union([l.z.number().transform(t=>new e(t)),l.z.instanceof(e)])},y=class e extends ge{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Jt(e*this.valueOf())}add(t){return new e(ze(this.valueOf(),new e(t).valueOf()))}sub(t){return new e(Re(this.valueOf(),new e(t).valueOf()))}mult(t){return new e(Ve(this.valueOf(),t))}div(t){return new e(He(this.valueOf(),t))}static UNKNOWN=new e(0);static BIT128=new e(16);static BIT64=new e(8);static BIT32=new e(4);static BIT16=new e(2);static BIT8=new e(1);static z=l.z.union([l.z.number().transform(t=>new e(t)),l.z.instanceof(e)])},qt=class e{start;end;constructor(e,t){typeof e==`object`&&`start`in e?(this.start=new _(e.start),this.end=new _(e.end)):(this.start=new _(e),this.end=new _(t))}get span(){return new v(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new e(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=v.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),r=this.end.sub(e.end).valueOf();return n<0&&(n=-n),r<0&&(r=-r),n<=t.valueOf()&&r<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString(`preciseDate`)} - ${this.span.toString()}`}overlapsWith(e,t=v.ZERO){e=e.makeValid();let n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;let r=_.max(n.start,e.start),i=_.min(n.end,e.end);return i.before(r)?!1:new v(i.sub(r)).greaterThanOrEqual(t)}contains(t){return t instanceof e?this.contains(t.start)&&this.contains(t.end):this.start.beforeEq(t)&&this.end.after(t)}boundBy(t){let n=new e(this.start,this.end);return t.start.after(this.start)&&(n.start=t.start),t.start.after(this.end)&&(n.end=t.start),t.end.before(this.end)&&(n.end=t.end),t.end.before(this.start)&&(n.start=t.end),n}static max(...t){return new e(_.min(...t.map(e=>e.start)),_.max(...t.map(e=>e.end)))}static MAX=new e(_.MIN,_.MAX);static ZERO=new e(_.ZERO,_.ZERO);static z=l.z.union([l.z.object({start:_.z,end:_.z}).transform(t=>new e(t.start,t.end)),l.z.instanceof(e)]);static boundedZ=e.z.refine(({isValid:e})=>e,{message:`Time range start time must be before or equal to time range end time`}).refine(({end:e})=>e.valueOf()<=Pe,{message:`Time range end time must be less than or equal to the maximum value of an int64`}).refine(({start:e})=>e.valueOf()>=Ne,{message:`Time range start time must be greater than or equal to the minimum value of an int64`});static sort(e,t){return _.sort(e.start,t.start)||_.sort(e.end,t.end)}static merge(...t){return e.max(...t.map(t=>new e(t).makeValid()))}},b=class e extends ge{constructor(t){if(he(t)&&(t=t.value),t instanceof e||typeof t==`string`||typeof t.valueOf()==`string`)super(t.valueOf());else{let n=e.ARRAY_CONSTRUCTOR_DATA_TYPES.get(t.constructor.name);if(n==null)throw Error(`unable to find data type for ${t.toString()}`);super(n.valueOf())}}get Array(){let t=e.ARRAY_CONSTRUCTORS.get(this.toString());if(t==null)throw Error(`unable to find array constructor for ${this.valueOf()}`);return t}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(e=>this.equals(e))}toString(t=!1){return t?e.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(e.JSON)||this.equals(e.STRING)||this.equals(e.BYTES)}get isNumeric(){return!this.isVariable&&!this.equals(e.UUID)}get isInteger(){let e=this.toString();return e.startsWith(`int`)||e.startsWith(`uint`)}get isFloat(){return this.toString().startsWith(`float`)}get density(){let t=e.DENSITIES.get(this.toString());if(t==null)throw Error(`unable to find density for ${this.valueOf()}`);return t}get isUnsignedInteger(){return this.equals(e.UINT8)||this.equals(e.UINT16)||this.equals(e.UINT32)||this.equals(e.UINT64)}get isSignedInteger(){return this.equals(e.INT8)||this.equals(e.INT16)||this.equals(e.INT32)||this.equals(e.INT64)}canSafelyCastTo(t){return this.equals(t)?!0:!this.isNumeric||!t.isNumeric||this.isVariable||t.isVariable||this.isUnsignedInteger&&t.isSignedInteger?!1:this.isFloat?t.isFloat&&this.density.valueOf()<=t.density.valueOf():this.equals(e.INT32)&&t.equals(e.FLOAT64)||this.equals(e.INT8)&&t.equals(e.FLOAT32)?!0:this.isInteger&&t.isInteger?this.density.valueOf()<=t.density.valueOf()&&this.isUnsignedInteger===t.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return e.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new e(`unknown`);static FLOAT64=new e(`float64`);static FLOAT32=new e(`float32`);static INT64=new e(`int64`);static INT32=new e(`int32`);static INT16=new e(`int16`);static INT8=new e(`int8`);static UINT64=new e(`uint64`);static UINT32=new e(`uint32`);static UINT16=new e(`uint16`);static UINT8=new e(`uint8`);static TIMESTAMP=new e(`timestamp`);static UUID=new e(`uuid`);static STRING=new e(`string`);static JSON=new e(`json`);static BYTES=new e(`bytes`);static ARRAY_CONSTRUCTORS=new Map([[e.UINT8.toString(),Uint8Array],[e.UINT16.toString(),Uint16Array],[e.UINT32.toString(),Uint32Array],[e.UINT64.toString(),BigUint64Array],[e.FLOAT32.toString(),Float32Array],[e.FLOAT64.toString(),Float64Array],[e.INT8.toString(),Int8Array],[e.INT16.toString(),Int16Array],[e.INT32.toString(),Int32Array],[e.INT64.toString(),BigInt64Array],[e.TIMESTAMP.toString(),BigInt64Array],[e.STRING.toString(),Uint8Array],[e.JSON.toString(),Uint8Array],[e.UUID.toString(),Uint8Array],[e.BYTES.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,e.UINT8],[Uint16Array.name,e.UINT16],[Uint32Array.name,e.UINT32],[BigUint64Array.name,e.UINT64],[Float32Array.name,e.FLOAT32],[Float64Array.name,e.FLOAT64],[Int8Array.name,e.INT8],[Int16Array.name,e.INT16],[Int32Array.name,e.INT32],[BigInt64Array.name,e.INT64]]);static DENSITIES=new Map([[e.UINT8.toString(),y.BIT8],[e.UINT16.toString(),y.BIT16],[e.UINT32.toString(),y.BIT32],[e.UINT64.toString(),y.BIT64],[e.FLOAT32.toString(),y.BIT32],[e.FLOAT64.toString(),y.BIT64],[e.INT8.toString(),y.BIT8],[e.INT16.toString(),y.BIT16],[e.INT32.toString(),y.BIT32],[e.INT64.toString(),y.BIT64],[e.TIMESTAMP.toString(),y.BIT64],[e.STRING.toString(),y.UNKNOWN],[e.JSON.toString(),y.UNKNOWN],[e.UUID.toString(),y.BIT128],[e.BYTES.toString(),y.UNKNOWN]]);static ALL=[e.UNKNOWN,e.UINT8,e.UINT16,e.UINT32,e.UINT64,e.INT8,e.INT16,e.INT32,e.INT64,e.FLOAT32,e.FLOAT64,e.TIMESTAMP,e.UUID,e.STRING,e.JSON,e.BYTES];static SHORT_STRINGS=new Map([[e.UINT8.toString(),`u8`],[e.UINT16.toString(),`u16`],[e.UINT32.toString(),`u32`],[e.UINT64.toString(),`u64`],[e.INT8.toString(),`i8`],[e.INT16.toString(),`i16`],[e.INT32.toString(),`i32`],[e.INT64.toString(),`i64`],[e.FLOAT32.toString(),`f32`],[e.FLOAT64.toString(),`f64`],[e.TIMESTAMP.toString(),`ts`],[e.UUID.toString(),`uuid`],[e.STRING.toString(),`str`],[e.JSON.toString(),`json`],[e.BYTES.toString(),`bytes`]]);static BIG_INT_TYPES=[e.INT64,e.UINT64,e.TIMESTAMP];static z=l.z.union([l.z.string().transform(t=>new e(t)),l.z.instanceof(e)])},Jt=class e extends ge{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return he(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return he(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(t){return he(t)&&(t=t.value),new e(ze(this.valueOf(),t.valueOf()))}sub(t){return he(t)&&(t=t.value),new e(Re(this.valueOf(),t.valueOf()))}mult(t){return new e(Ve(this.valueOf(),t))}div(t){return new e(He(this.valueOf(),t))}truncate(t){return new e(Math.trunc(this.valueOf()/new e(t).valueOf())*new e(t).valueOf())}remainder(t){return e.bytes(this.valueOf()%new e(t).valueOf())}get gigabytes(){return this.valueOf()/e.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/e.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/e.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/e.TERABYTE.valueOf()}toString(){let t=this.truncate(e.TERABYTE),n=this.truncate(e.GIGABYTE),r=this.truncate(e.MEGABYTE),i=this.truncate(e.KILOBYTE),a=this.truncate(e.BYTE),o=t,s=n.sub(t),c=r.sub(n),l=i.sub(r),u=a.sub(i),d=``;return o.isZero||(d+=`${o.terabytes}TB `),s.isZero||(d+=`${s.gigabytes}GB `),c.isZero||(d+=`${c.megabytes}MB `),l.isZero||(d+=`${l.kilobytes}KB `),(!u.isZero||d===``)&&(d+=`${u.valueOf()}B`),d.trim()}static bytes(t=1){return new e(t)}static BYTE=new e(1);static kilobytes(t=1){return e.bytes(new e(t).valueOf()*1e3)}static KILOBYTE=e.kilobytes(1);static megabytes(t=1){return e.kilobytes(new e(t).valueOf()*1e3)}static MEGABYTE=e.megabytes(1);static gigabytes(t=1){return e.megabytes(new e(t).valueOf()*1e3)}static GIGABYTE=e.gigabytes(1);static terabytes(t){return e.gigabytes(new e(t).valueOf()*1e3)}static TERABYTE=e.terabytes(1);static ZERO=new e(0);static z=l.z.union([l.z.number().transform(t=>new e(t)),l.z.instanceof(e)]);get isZero(){return this.valueOf()===0}};l.z.object({start:l.z.number(),end:l.z.number()}),l.z.union([l.z.instanceof(Uint8Array),l.z.instanceof(Uint16Array),l.z.instanceof(Uint32Array),l.z.instanceof(BigUint64Array),l.z.instanceof(Float32Array),l.z.instanceof(Float64Array),l.z.instanceof(Int8Array),l.z.instanceof(Int16Array),l.z.instanceof(Int32Array),l.z.instanceof(BigInt64Array)]);var Yt=e=>{let t=typeof e;return t===`string`||t===`number`||t===`boolean`||t===`bigint`||e instanceof _||e instanceof v||e instanceof Date},Xt=(e,t,n,r=0)=>e.usesBigInt&&!t.usesBigInt?Number(n)-Number(r):!e.usesBigInt&&t.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):Re(n,r);qt.z,_.z,v.z,Kt.z,Jt.z,b.z,qt.boundedZ;var Zt=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Qt(e){return typeof e==`string`&&Zt.test(e)}var x=[];for(let e=0;e<256;++e)x.push((e+256).toString(16).slice(1));function $t(e,t=0){return(x[e[t+0]]+x[e[t+1]]+x[e[t+2]]+x[e[t+3]]+`-`+x[e[t+4]]+x[e[t+5]]+`-`+x[e[t+6]]+x[e[t+7]]+`-`+x[e[t+8]]+x[e[t+9]]+`-`+x[e[t+10]]+x[e[t+11]]+x[e[t+12]]+x[e[t+13]]+x[e[t+14]]+x[e[t+15]]).toLowerCase()}function en(e,t=0){let n=$t(e,t);if(!Qt(n))throw TypeError(`Stringified UUID is invalid`);return n}typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);var tn=(e,t)=>en(e,t),nn=-1,rn={[Symbol.iterator]:()=>rn,next:()=>({done:!0,value:void 0})},an=l.z.string().transform(e=>new Uint8Array(atob(e).split(``).map(e=>e.charCodeAt(0))).buffer),on=l.z.union([l.z.null(),l.z.undefined()]).transform(()=>new Uint8Array().buffer),sn=10,cn=(e,t)=>{if(e===`number`&&!t.isNumeric)throw Error(`cannot convert series of type ${t.toString()} to number`);if(e===`bigint`&&!t.usesBigInt)throw Error(`cannot convert series of type ${t.toString()} to bigint`)},ln=`sy_x_telem_series`,un=class e{key;discriminator=ln;dataType;sampleOffset;gl;_data;timeRange=qt.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=nn;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=l.z.object({timeRange:qt.z.optional(),dataType:b.z,alignment:l.z.coerce.bigint().optional(),data:l.z.union([an,on,l.z.instanceof(ArrayBuffer),l.z.instanceof(Uint8Array)]),glBufferUsage:Vt.default(`static`).optional()});static z=e.crudeZ.transform(t=>new e(t));constructor(e){dn(e)&&(e={data:e}),e.data??=[];let{dataType:t,timeRange:n,sampleOffset:r=0,glBufferUsage:i=`static`,alignment:a=0n,alignmentMultiple:o=1n,key:s=Te(),data:c}=e;if(fn(c)){let e=c;this.key=e.key,this.dataType=e.dataType,this.sampleOffset=e.sampleOffset,this.gl=e.gl,this._data=e._data,this.timeRange=e.timeRange,this.alignment=e.alignment,this.alignmentMultiple=e.alignmentMultiple,this.cachedMin=e.cachedMin,this.cachedMax=e.cachedMax,this.writePos=e.writePos,this._refCount=e._refCount,this.cachedLength=e.cachedLength;return}let l=Yt(c),u=Array.isArray(c);if(t!=null)this.dataType=new b(t);else if(c instanceof ArrayBuffer)throw Error(`cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.`);else if(u||l){let e=c;if(!l){if(c.length===0)throw Error(`cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.`);e=c[0]}if(typeof e==`string`)this.dataType=b.STRING;else if(typeof e==`number`)this.dataType=b.FLOAT64;else if(typeof e==`bigint`)this.dataType=b.INT64;else if(typeof e==`boolean`)this.dataType=b.UINT8;else if(e instanceof _||e instanceof Date||e instanceof _)this.dataType=b.TIMESTAMP;else if(typeof e==`object`)this.dataType=b.JSON;else throw Error(`cannot infer data type of ${typeof e} when constructing a Series from a JS array`)}else this.dataType=new b(c);if(!u&&!l)this._data=c;else if(u&&c.length===0)this._data=new this.dataType.Array([]).buffer;else{let e=l?[c]:c,t=e[0];(t instanceof _||t instanceof Date||t instanceof v)&&(e=e.map(e=>new _(e).valueOf())),this.dataType.equals(b.STRING)?(this.cachedLength=e.length,this._data=new TextEncoder().encode(`${e.join(`
|
|
4
|
+
`)}\n`).buffer):this.dataType.equals(b.JSON)?(this.cachedLength=e.length,this._data=new TextEncoder().encode(`${e.map(e=>me.encodeString(e)).join(`
|
|
5
|
+
`)}\n`).buffer):this.dataType.usesBigInt&&typeof t==`number`?this._data=new this.dataType.Array(e.map(e=>BigInt(Math.round(e)))).buffer:!this.dataType.usesBigInt&&typeof t==`bigint`?this._data=new this.dataType.Array(e.map(Number)).buffer:this._data=new this.dataType.Array(e).buffer}this.key=s,this.alignment=a,this.alignmentMultiple=o,this.sampleOffset=r??0,this.timeRange=n??qt.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:i}}static alloc({capacity:t,dataType:n,...r}){if(t===0)throw Error(`[Series] - cannot allocate an array of length 0`);let i=new e({data:new new b(n).Array(t).buffer,dataType:n,...r});return i.writePos=0,i}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn(`cannot release a series with a negative reference count`)}write(e){if(!e.dataType.equals(this.dataType))throw Error(`buffer must be of the same type as this array`);return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===nn)return 0;let t=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,t);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===nn)return 0;let t=this.capacity-this.writePos,n=e.sub(0,t);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data==`object`&&`buffer`in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===nn?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
|
|
6
|
+
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(b.JSON))throw Error(`cannot parse non-JSON series as JSON`);return this.toStrings().map(t=>e.parse(me.decodeString(t)))}get byteCapacity(){return new Jt(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===nn?this.byteCapacity:this.dataType.isVariable?new Jt(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength==null?this.dataType.isVariable?this.calculateCachedLength():this.writePos===nn?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos:this.cachedLength}calculateCachedLength(){if(!this.dataType.isVariable)throw Error(`cannot calculate length of a non-variable length data type`);let e=0,t=[0];return this.data.forEach((n,r)=>{n===sn&&(e++,t.push(r+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(t,n=0){if(this.dataType.equals(t))return this;let r=new t.Array(this.length);for(let e=0;e<this.length;e++)r[e]=Xt(this.dataType,t,this.data[e],n);return new e({data:r.buffer,dataType:t,timeRange:this.timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){return this.length===0?-1/0:(this.dataType.equals(b.TIMESTAMP)?this.cachedMax=this.data[this.data.length-1]:(this.dataType.usesBigInt,this.cachedMax=this.data.reduce((e,t)=>e>t?e:t)),this.cachedMax)}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw Error(`cannot calculate maximum on a variable length data type`);return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),ze(this.cachedMax,this.sampleOffset))}calcRawMin(){return this.length===0?1/0:(this.dataType.equals(b.TIMESTAMP)?this.cachedMin=this.data[0]:(this.dataType.usesBigInt,this.cachedMin=this.data.reduce((e,t)=>e<t?e:t)),this.cachedMin)}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw Error(`cannot calculate minimum on a variable length data type`);return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),ze(this.cachedMin,this.sampleOffset))}get bounds(){return et(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){let t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){let t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){let n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(t===!0)throw Error(`[series] - no value at index ${n}`);return}return this.at(n,t)}at(e,t=!1){if(this.dataType.isVariable)return this.atVariable(e,t??!1);if(this.dataType.equals(b.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);let n=this.data[e];if(n==null){if(t===!0)throw Error(`[series] - no value at index ${e}`);return}return ze(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);let n=tn(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(t)throw Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,t){let n=0,r=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],r=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let t=0;t<this.data.length;t++)if(this.data[t]===sn){if(e===0){r=t;break}n=t+1,e--}if(r===0&&(r=this.data.length),n>=r||e>0){if(t)throw Error(`[series] - no value at index ${e}`);return}}let i=this.data.slice(n,r);return this.dataType.equals(b.STRING)?new TextDecoder().decode(i):ae(JSON.parse(new TextDecoder().decode(i)))}binarySearch(e){let t=0,n=this.length-1,r=ve(e);for(;t<=n;){let i=Math.floor((t+n)/2),a=r(this.at(i,!0),e);if(a===0)return i;a<0?t=i+1:n=i-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(b.FLOAT32)&&!this.dataType.equals(b.UINT8))throw Error(`Only FLOAT32 and UINT8 arrays can be used in WebGL`);let{buffer:t,bufferUsage:n,prevBuffer:r}=this.gl;if(t??(this.gl.buffer=e.createBuffer()),this.writePos!==r)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==nn){r===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);let t=this.dataType.density.size(r).valueOf(),n=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,t,n.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n===`static`?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=nn}as(e){return cn(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:vn(this.alignmentBounds.lower),upper:vn(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return et(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw Error(`gl buffer not initialized`);return this.gl.prevBuffer!==this.writePos&&console.warn(`buffer not updated`),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){let e=new mn(this);return this.dataType.equals(b.JSON)?new hn(e):e}return this.dataType.equals(b.UUID)?new gn(this):new _n(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new pn(this,e,t??this.length)}subAlignmentIterator(e,t){let n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),r=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new pn(this,n,r)}subBytes(t,n){return t>=0&&(n==null||n>=this.byteLength.valueOf())?this:new e({data:this.data.subarray(t,n),dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}sliceSub(t,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return i=t?this.data.subarray(n,r):this.data.slice(n,r),new e({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(t){return new e({data:this.buffer,dataType:this.dataType,timeRange:qt.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:`static`,alignment:t})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(e=>e.toString());else{for(let t=0;t<5;t++)e+=`${this.at(t)?.toString()}`,e+=`,`;e+=`...,`;for(let t=-5;t<0;t++)e+=this.at(t)?.toString(),t<-1&&(e+=`,`)}return e+=`])`,e}},dn=e=>e==null?!1:Array.isArray(e)||e instanceof ArrayBuffer||ArrayBuffer.isView(e)&&!(e instanceof DataView)||e instanceof un?!0:Yt(e),fn=Ee(ln,un),pn=class{series;end;index;constructor(e,t,n){this.series=e;let r=et(0,e.length+1);this.end=nt(r,n),this.index=nt(r,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},mn=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw Error(`cannot create a variable series iterator for a non-variable series`);this.series=e,this.index=0,this.decoder=new TextDecoder}next(){let e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==sn;)this.index++;let n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}},hn=class e{wrapped;static schema=l.z.record(l.z.string(),l.z.unknown());constructor(e){this.wrapped=e}next(){let t=this.wrapped.next();return t.done===!0?{done:!0,value:void 0}:{done:!1,value:me.decodeString(t.value,e.schema)}}},gn=class{series;index;data;density;constructor(e){if(!e.dataType.equals(b.UUID))throw Error(`cannot create a UUID series iterator for a non-UUID series`);this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=b.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};let e=tn(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}},_n=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},vn=e=>({domain:e>>32n,sample:e&4294967295n}),yn=async e=>await new Promise(t=>setTimeout(t,v.fromMilliseconds(e).milliseconds)),bn=p({Breaker:()=>xn,breakerConfigZ:()=>Sn}),xn=class{config;retries;interval;constructor(e){this.config={baseInterval:new v(e?.baseInterval??v.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??yn},this.retries=0,this.interval=new v(this.config.baseInterval)}async wait(){let{maxRetries:e,scale:t,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(t),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}},Sn=l.z.object({baseInterval:v.z.optional(),maxRetries:l.z.number().optional(),scale:l.z.number().optional()});l.z.int().min(Ae).max(127),l.z.int().min(je).max(Me),l.z.int().min(Fe).max(Ie);var Cn=l.z.int().min(0).max(255);l.z.int().min(0).max(De),l.z.int().min(0).max(Oe),l.z.int().min(0).max(ke);var wn=(e,t)=>{let n=Array.isArray(e),r=Array.isArray(t);if(n!==r)return!1;if(n&&r){let n=e,r=t;if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(!wn(n[e],r[e]))return!1;return!0}if(e==null||t==null||typeof e!=`object`||typeof t!=`object`)return e===t;if(`equals`in e)return e.equals(t);let i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return!1;for(let n of i){let r=e[n],i=t[n];if(typeof r==`object`&&typeof i==`object`){if(!wn(r,i))return!1}else if(r!==i)return!1}return!0},Tn=(e,t)=>{if(typeof e!=`object`||!e)return e===t;let n=Object.keys(e),r=Object.keys(t);if(r.length>n.length)return!1;for(let n of r){let r=e[n],i=t[n];if(typeof r==`object`&&typeof i==`object`){if(!Tn(r,i))return!1}else if(r!==i)return!1}return!0},En=(e,...t)=>{if(t.length===0)return e;let n=t.shift();if(ue(e)&&ue(n))for(let t in n)try{ue(n[t])?(t in e||Object.assign(e,{[t]:{}}),En(e[t],n[t])):Object.assign(e,{[t]:n[t]})}catch(e){throw e instanceof TypeError?TypeError(`.${t}: ${e.message}`,{cause:e}):e}return En(e,...t)},Dn=l.z.string().regex(/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i),On=Cn,kn=l.z.number().min(0).max(1),An=l.z.tuple([On,On,On,kn]),jn=l.z.tuple([On,On,On]),Mn=l.z.object({rgba255:An}),Nn=l.z.object({r:On,g:On,b:On,a:kn}),Pn=l.z.number().min(0).max(360),Fn=l.z.number().min(0).max(100),In=l.z.number().min(0).max(100),Ln=l.z.tuple([Pn,Fn,In,kn]),Rn=l.z.union([Dn,jn,An,Ln,Mn,Nn]),zn=Rn.transform(e=>Bn(e)),Bn=(e,t=1)=>{if(e=Rn.parse(e),typeof e==`string`)return Vn(e,t);if(Array.isArray(e)){if(e.length<3||e.length>4)throw Error(`Invalid color: [${e.join(`, `)}]`);return e.length===3?[...e,t]:e}return`a`in e&&`r`in e?[e.r,e.g,e.b,e.a]:e.rgba255},Vn=(e,t=1)=>(e=Dn.parse(e),e=Un(e),[Hn(e,0),Hn(e,2),Hn(e,4),e.length===8?Hn(e,6)/255:t]),Hn=(e,t)=>parseInt(e.slice(t,t+2),16),Un=e=>e.startsWith(`#`)?e.slice(1):e;Bn(`#000000`),Bn(`#ffffff`);var Wn=l.z.object({key:l.z.string(),color:Rn,position:l.z.number(),switched:l.z.boolean().optional()});l.z.array(Wn);var Gn=l.z.object({key:l.z.string(),name:l.z.string(),color:zn});l.z.object({key:l.z.string(),name:l.z.string(),swatches:l.z.array(Gn)});var Kn=function(e){return e[e.exclusive=0]=`exclusive`,e[e.shared=1]=`shared`,e}({});l.z.enum(Kn),l.z.object({key:l.z.string(),name:l.z.string(),group:l.z.uint32().optional()});var qn=e=>Object.getOwnPropertySymbols(globalThis).includes(e),Jn=(e,t)=>{let n=Symbol.for(e);if(!qn(n)){let e=t();Object.defineProperty(globalThis,n,{value:e})}return()=>globalThis[n]},Yn=p({Canceled:()=>cr,NONE:()=>`nil`,NotImplemented:()=>lr,UNKNOWN:()=>er,Unknown:()=>or,createTyped:()=>Qn,decode:()=>ar,encode:()=>ir,isTyped:()=>$n,payloadZ:()=>sr,register:()=>rr}),Xn=`sy_x_error`,Zn=e=>t=>typeof t==`object`&&t&&`type`in t&&typeof t.type==`string`?t.type.startsWith(e):t instanceof Error?t.message.startsWith(e):typeof t==`string`?t.startsWith(e):!1,Qn=e=>class t extends Error{static discriminator=Xn;discriminator=t.discriminator;static TYPE=e;type=t.TYPE;static matches=Zn(e);matches=t.matches;constructor(e,n){super(e,n),this.name=t.TYPE}static sub(t){return Qn(`${e}.${t}`)}},$n=e=>{if(typeof e!=`object`||!e)return!1;let t=e;if(t.discriminator!==Xn)return!1;if(!(`type`in t))throw Error(`X Error is missing its type property: ${JSON.stringify(t)}`);return!0},er=`unknown`,tr=class{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:`nil`,data:``};if($n(e))for(let t of this.providers){let n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:er,data:e.message};if(typeof e==`string`)return{type:er,data:e};try{return{type:er,data:JSON.stringify(e)}}catch{return{type:er,data:`unable to encode error information`}}}decode(e){if(e==null||e.type===`nil`)return null;if(e.type===`unknown`)return new or(e.data);for(let t of this.providers){let n=t.decode(e);if(n!=null)return n}return new or(e.data)}},nr=Jn(`synnax-error-registry`,()=>new tr),rr=({encode:e,decode:t})=>nr().register({encode:e,decode:t}),ir=e=>nr().encode(e),ar=e=>e==null?null:nr().decode(e),or=class extends Qn(`unknown`){},sr=l.z.object({type:l.z.string(),data:l.z.string()}),cr=class extends Qn(`canceled`){},lr=class extends Qn(`not_implemented`){};l.z.string().regex(/^(?:$|(?:\/(?:[^~/]|~0|~1)*)+)$/,`must be a valid JSON pointer (RFC 6901)`),l.z.union([l.z.string(),l.z.number(),l.z.boolean(),l.z.null()]),l.z.enum([`string`,`number`,`boolean`,`null`]),l.z.object({key:l.z.string(),value:l.z.string()});var ur=l.z.uuid();l.z.object({key:ur,name:l.z.string().min(1),color:zn}).partial({key:!0}),l.z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/),l.z.enum([`standard`,`scientific`,`engineering`]),l.z.union([l.z.string(),l.z.number()]),typeof process<`u`&&process.versions!=null&&process.versions.node!=null||typeof window>`u`||window.document;var dr=[`macOS`,`Windows`,`Linux`],fr=[`macos`,`windows`,`linux`],pr={macos:`macOS`,windows:`Windows`,linux:`Linux`};l.z.enum(dr).or(l.z.enum(fr).transform(e=>pr[e])),l.z.object({stack:l.z.string(),error:l.z.instanceof(Error)}),l.z.enum([`success`,`info`,`warning`,`error`,`loading`,`disabled`]),l.z.literal(`success`),l.z.literal(`info`),l.z.literal(`warning`),l.z.literal(`error`),l.z.literal(`loading`),l.z.literal(`disabled`);var mr=(...e)=>e.map(hr).join(``),hr=e=>(e.endsWith(`/`)||(e+=`/`),e.startsWith(`/`)&&(e=e.slice(1)),e),gr=e=>e.endsWith(`/`)?e.slice(0,-1):e,_r=(e,t=``)=>e===null?``:`?${Object.entries(e).filter(([,e])=>e==null?!1:Array.isArray(e)?e.length>0:!0).map(([e,n])=>`${t}${e}=${n}`).join(`&`)}`,vr=class e{protocol;host;port;path;constructor({host:e,port:t,protocol:n=``,pathPrefix:r=``}){this.protocol=n,this.host=e,this.port=t,this.path=hr(r)}replace(t){return new e({host:t.host??this.host,port:t.port??this.port,protocol:t.protocol??this.protocol,pathPrefix:t.pathPrefix??this.path})}child(t){return new e({...this,pathPrefix:mr(this.path,t)})}toString(){return gr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new e({host:`unknown`,port:0})},yr=class extends Yn.createTyped(`freighter`){},br=class extends yr.sub(`eof`){constructor(){super(`EOF`)}},xr=class extends yr.sub(`stream_closed`){constructor(){super(`StreamClosed`)}},Sr=class extends yr.sub(`unreachable`){url;constructor(e={}){let{message:t=`Unreachable`,url:n=vr.UNKNOWN}=e;super(t),this.url=n}};Yn.register({encode:e=>{if(!e.type.startsWith(yr.TYPE))return null;if(br.matches(e))return{type:br.TYPE,data:`EOF`};if(xr.matches(e))return{type:xr.TYPE,data:`StreamClosed`};if(Sr.matches(e))return{type:Sr.TYPE,data:`Unreachable`};throw Error(`Unknown error type: ${e.type}: ${e.message}`)},decode:e=>{if(!e.type.startsWith(yr.TYPE))return null;switch(e.type){case br.TYPE:return new br;case xr.TYPE:return new xr;case Sr.TYPE:return new Sr;default:throw new Yn.Unknown(`Unknown error type: ${e.data}`)}}});var Cr=class{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0,r=async e=>{if(n===this.middleware.length)return await t(e);let i=this.middleware[n];return n++,await i(e,r)};return await r(e)}},wr=`Content-Type`,Tr=new Set([`ECONNREFUSED`,`ECONNRESET`,`ETIMEDOUT`,`EPIPE`,`UND_ERR_CONNECT_TIMEOUT`,`UND_ERR_SOCKET`]),Er=e=>{let t=e?.cause?.code??e?.code??e?.errno;if(typeof t==`string`&&Tr.has(t))return!0;if(e.name===`TypeError`){let t=String(e.message||``).toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(t))return typeof navigator<`u`&&navigator.onLine,!0}return e?.name===`AbortError`||e?.code,!1},Dr=400,Or=class extends Cr{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?`https`:`http`}),this.encoder=t,new Proxy(this,{get:(e,t,n)=>t===`endpoint`?this.endpoint:Reflect.get(e,t,n)})}get headers(){return{[wr]:this.encoder.contentType}}async send(e,t,n,r){let i=null,a=this.endpoint.child(e),o={};o.method=`POST`,o.body=this.encoder.encode(t,n);let[,s]=await this.executeMiddleware({target:a.toString(),protocol:this.endpoint.protocol,params:{},role:`client`},async e=>{let t={...e,params:{}};o.headers={...this.headers,...e.params};let n;try{n=await fetch(e.target,o)}catch(e){if(!(e instanceof Error))throw e;return[t,Er(e)?new Sr({url:a}):e]}let s=await n.arrayBuffer();if(n?.ok)return r!=null&&(i=this.encoder.decode(s,r)),[t,null];try{if(n.status!==Dr)return[t,Error(n.statusText)];let e=this.encoder.decode(s,Yn.payloadZ);return[t,Yn.decode(e)]}catch(e){return[t,Error(`[freighter] - failed to decode error: ${n.statusText}: ${e.message}`)]}});if(s!=null)return[null,s];if(i==null)throw Error(`Response must be defined`);return[i,null]}},kr=(e,t)=>{class n{wrapped;constructor(e){this.wrapped=e}use(...e){this.wrapped.use(...e)}async send(e,n,r,i){let a=new bn.Breaker(t);do{let[t,o]=await this.wrapped.send(e,n,r,i);if(o==null)return[t,null];if(!Sr.matches(o))return[null,o];if(console.warn(`[freighter] ${a.retryMessage}`,o),!await a.wait())return[t,o]}while(!0)}}return new n(e)},S=async(e,t,n,r,i)=>{let[a,o]=await e.send(t,n,r,i);if(o!=null)throw o;return a},Ar=l.z.object({type:l.z.enum([`data`,`close`,`open`]),payload:l.z.unknown(),error:l.z.optional(Yn.payloadZ)}),jr=class{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,n,r){this.codec=t,this.reqSchema=n,this.resSchema=r,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){let e=await this.receiveMsg();if(e.type!==`open`){if(e.error==null)throw Error(`Message error must be defined`);return Yn.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new br;if(this.sendClosed)throw new xr;return this.ws.send(this.codec.encode({type:`data`,payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];let e=await this.receiveMsg();if(e.type===`close`){if(e.error==null||(this.serverClosed=Yn.decode(e.error),this.serverClosed==null))throw Error(`Message error must be defined`);return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;let e={type:`close`};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((e,t)=>this.receiveCallbacksQueue.push({resolve:e,reject:t}))}addMessage(e){let t=this.receiveCallbacksQueue.shift();t==null?this.receiveDataQueue.push(e):t.resolve(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,Ar))}onClose(e){this.addMessage({type:`close`,error:{type:e.code===Nr?br.TYPE:xr.TYPE,data:``}})}},Mr=`freighterctx`,Nr=1e3,Pr=class e extends Cr{baseUrl;encoder;secure;static MESSAGE_TYPE=`arraybuffer`;constructor(e,t,n=!1){super(),this.secure=n,this.baseUrl=e.replace({protocol:n?`wss`:`ws`}),this.encoder=t}withCodec(t){let n=new e(this.baseUrl,t,this.secure);return n.use(...this.middleware),n}async stream(t,n,r){let i,[,a]=await this.executeMiddleware({target:t,protocol:`websocket`,params:{},role:`client`},async a=>{let o=new WebSocket(this.buildURL(t,a)),s={...a,params:{}};o.binaryType=e.MESSAGE_TYPE;let c=await this.wrapSocket(o,n,r);return c instanceof Error?[s,c]:(i=c,[s,null])});if(a!=null)throw a;return i}buildURL(e,t){let n=_r({[wr]:this.encoder.contentType,...t.params},Mr);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(r=>{e.onopen=()=>{let i=new jr(e,this.encoder,t,n);i.receiveOpenAck().then(e=>{r(e??i)}).catch(e=>r(e))},e.onerror=e=>{r(Error(e.message))}})}},Fr=Object.defineProperty,C=(e,t)=>{let n={};for(var r in e)Fr(n,r,{get:e[r],enumerable:!0});return t||Fr(n,Symbol.toStringTag,{value:`Module`}),n},Ir=e=>l.default.union([l.default.union([l.default.null(),l.default.undefined()]).transform(()=>[]),e.array()]),Lr=e=>Array.isArray(e)?e:e==null?[]:[e],Rr=(e,t)=>{if(Array.isArray(t))return t.reduce((e,t)=>Rr(e,t),e??[]);if(e==null)return[t];let n=e.findIndex(e=>e==t),r=[...e];return n===-1?r.push(t):r[n]=t,r},zr=((e,t)=>{if(e!=null)return Array.isArray(t)?e.filter(e=>!t.includes(e)):e.filter(e=>e!=t)}),Br=(e,t)=>{if(Array.isArray(t))return t.reduce((e,t)=>Br(e,t),e??[]);if(e==null)return[t];let n=e.findIndex(e=>e.key===t.key),r=[...e];return n===-1?r.push(t):r[n]=t,r},Vr=((e,t)=>{if(e!=null)return Array.isArray(t)?e.filter(e=>!t.includes(e.key)):e.filter(e=>e.key!==t)}),w=C({nullishToEmpty:()=>Ir,remove:()=>zr,removeKeyed:()=>Vr,toArray:()=>Lr,upsert:()=>Rr,upsertKeyed:()=>Br}),Hr=C({camelToSnake:()=>Zr,capitalize:()=>Qr,preserveCase:()=>Wr,snakeToCamel:()=>Xr,toKebab:()=>ni,toProperNoun:()=>ri}),Ur=`synnax.caseconv.preserveCase`,Wr=e=>(e[Ur]=!0,e),Gr=e=>{if(typeof e!=`object`||!e)return!1;if(Ur in e)return!0;let t=e._zod?.def;return t==null?!1:t.innerType&&Gr(t.innerType)?!0:t.type===`union`&&Array.isArray(t.options)?t.options.some(Gr):t.type===`pipe`?Gr(t.in)||Gr(t.out):!1},Kr=e=>{if(e==null)return;let t=e._zod?.def;if(t?.type===`array`&&t.element!=null)return t.element;if(t?.type===`union`&&Array.isArray(t.options))for(let e of t.options){let t=Kr(e);if(t!=null)return t}},qr=e=>{if(e==null)return null;let t=e;if(t.shape!=null)return t.shape;if(typeof t.sourceType==`function`){let e=t.sourceType();if(e?.shape!=null)return e.shape}let n=t._zod?.def;if(n==null)return null;if(n.innerType!=null)return qr(n.innerType);if(n.type===`union`&&Array.isArray(n.options))for(let e of n.options){let t=qr(e);if(t!=null)return t}return n.type===`pipe`?qr(n.in)??qr(n.out):null},Jr=e=>{if(e.length===0)return e;let t=e.indexOf(`_`)===-1?e:e.replace(/_[a-z]/g,e=>e[1].toUpperCase()),n=t.charCodeAt(0);return n<65||n>90||t.length>1&&t.charCodeAt(1)>=65&&t.charCodeAt(1)<=90?t:String.fromCharCode(n+32)+t.slice(1)},Yr=e=>{let t=(n,r=$r)=>{if(typeof n==`string`)return e(n);if(Array.isArray(n)){let e=Kr(r.schema),i={recursive:r.recursive,recursiveInArray:r.recursiveInArray,schema:e};return n.map(e=>t(e,i))}if(!ei(n)||r.schema!=null&&Gr(r.schema))return n;let i=r.recursive??!0,a=r.recursiveInArray??i,o=r.schema,s={},c=n;if(`toJSON`in c&&typeof c.toJSON==`function`)return t(c.toJSON(),r);let l=qr(o),u={recursive:i,recursiveInArray:a,schema:void 0},d=Object.keys(c);for(let n=0;n<d.length;n++){let r=d[n],o=c[r],f=e(r),p=l==null?void 0:l[r]??l[f]??void 0;i&&(ei(o)?ti(o)||(u.schema=p,o=t(o,u)):a&&Array.isArray(o)&&(u.schema=Kr(p),o=o.map(e=>{if(ei(e)){if(!ti(e))return t(e,u)}else if(Array.isArray(e))return t({key:e},u).key;return e}))),s[f]=o}return s};return t},Xr=Yr(Jr),Zr=Yr(e=>e.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`)),Qr=e=>e.length===0?e:e[0].toUpperCase()+e.slice(1),$r={recursive:!0,recursiveInArray:!0,schema:void 0},ei=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ti=e=>e instanceof Uint8Array||e instanceof Number||e instanceof String,ni=Yr(e=>e.replace(/[\s_]+/g,`-`).replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}-${n.toLowerCase()}`).toLowerCase()),ri=Yr(e=>{if(e.length===0)return e;let t=e.replace(/[_-]/g,` `);return t=t.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t} ${n}`),t=t.replace(/([A-Z]+)([A-Z][a-z])/g,(e,t,n)=>`${t} ${n}`),t=t.replace(/\s+/g,` `).trim(),t=t.replace(/\b\w/g,e=>e.toUpperCase()),t}),ii=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ai=C({CSVCodec:()=>si,CSV_CODEC:()=>ui,ENCODERS:()=>fi,JSONCodec:()=>oi,JSON_CODEC:()=>li,TEXT_CODEC:()=>di,TextCodec:()=>ci}),oi=class{contentType=`application/json`;decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e,t){return this.encoder.encode(this.encodeString(e,t))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){let n=Xr(JSON.parse(e),{schema:t});return t==null?n:t.parse(n)}encodeString(e,t){let n=Zr((t==null?e:t.parse(e))??{},{schema:t});return JSON.stringify(n,(e,t)=>ArrayBuffer.isView(t)?Array.from(t):typeof t==`bigint`?t.toString():t)}},si=class{contentType=`text/csv`;encode(e){let t=this.encodeString(e);return new TextEncoder().encode(t)}decode(e,t){let n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!ii(e[0]))throw Error(`Payload must be an array of objects`);let t=Object.keys(e[0]),n=[t.join(`,`)];return e.forEach(e=>{let r=t.map(t=>JSON.stringify(e[t]??``));n.push(r.join(`,`))}),n.join(`
|
|
7
|
+
`)}decodeString(e,t){let[n,...r]=e.trim().split(`
|
|
8
|
+
`).map(e=>e.trim());if(n.length===0)return t==null?{}:t.parse({});let i=n.split(`,`).map(e=>e.trim()),a={};return i.forEach(e=>{a[e]=[]}),r.forEach(e=>{let t=e.split(`,`).map(e=>e.trim());i.forEach((e,n)=>{let r=this.parseValue(t[n]);r!=null&&a[e].push(r)})}),t==null?a:t.parse(a)}parseValue(e){if(e==null||e.length===0)return null;let t=Number(e);return isNaN(t)?e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e:t}},ci=class{contentType=`text/plain`;encode(e){if(typeof e!=`string`)throw Error(`TextCodec.encode payload must be a string`);return new TextEncoder().encode(e)}decode(e,t){let n=new TextDecoder().decode(e);return t==null?n:t.parse(n)}},li=new oi,ui=new si,di=new ci,fi=[li],pi=C({ValueExtension:()=>mi,isCrudeValueExtension:()=>T,isNonZero:()=>_i,isStringer:()=>hi,isZero:()=>gi}),T=e=>typeof e==`object`&&!!e&&`value`in e,mi=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}},hi=e=>typeof e==`object`&&!!e&&`toString`in e,gi=e=>{if(hi(e))return e?.toString().length===0;switch(typeof e){case`string`:return e.length===0;case`number`:return e===0;case`bigint`:return e===0n;case`boolean`:return!e;case`undefined`:return!0;case`object`:return e==null;default:return!1}},_i=e=>!gi(e),vi=C({by:()=>bi,unique:()=>yi}),yi=e=>[...new Set(e)],bi=(e,t,n=!0)=>{let r=new Map;return e.forEach(e=>{let i=t(e);if(r.has(i)){if(n)return;r.delete(i)}r.set(i,e)}),Array.from(r.values())},xi=(e,t=!1)=>{let n=hi(e)?`stringer`:typeof e,r;switch(n){case`string`:r=(e,t)=>e.localeCompare(t);break;case`stringer`:r=(e,t)=>e.toString().localeCompare(t.toString());break;case`number`:r=(e,t)=>Number(e)-Number(t);break;case`bigint`:r=(e,t)=>BigInt(e)-BigInt(t)>0n?1:-1;break;case`boolean`:r=(e,t)=>Number(e)-Number(t);break;case`undefined`:r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return t?Di(r):r},Si=(e,t,n)=>{let r=xi(t[e],n);return(t,n)=>r(t[e],n[e])},Ci=(e,t)=>e.length===t.length?e.every((e,n)=>e===t[n])?0:-1:e.length-t.length,wi=(e,t)=>{if(e.length!==t.length)return e.length-t.length;if(e.length===0)return 0;let n=xi(e[0]),r=[...e].sort(n),i=[...t].sort(n);return r.every((e,t)=>e===i[t])?0:-1},Ti=(e,t)=>wi(yi(e),yi(t)),Ei=(e,t)=>e===t?0:e===`first`&&t===`last`?1:-1,Di=e=>(t,n)=>e(n,t),Oi=e=>e<0,ki=e=>e>0,Ai=e=>e>=0,ji=e=>e===0,Mi=(e,t)=>{let n=/([a-zA-Z]+)|(\d+)/g,r=e.replace(/[\s_.-]+/g,``).match(n),i=t.replace(/[\s_.-]+/g,``).match(n);if(!r||!i)return 0;for(let e=0;e<Math.min(r.length,i.length);e++){let t=r[e],n=i[e];if(isNaN(Number(t))&&isNaN(Number(n))){let e=t.localeCompare(n);if(e!==0)return e}else if(!isNaN(Number(t))&&!isNaN(Number(n))){let e=Number(t)-Number(n);if(e!==0)return e}else return isNaN(Number(t))?-1:1}return r.length-i.length},Ni=(e,t,n)=>{let r=0,i=e.length,a=n??xi(t);for(;r<i;){let n=Math.floor((r+i)/2),o=a(e[n],t);if(o===0)return n;o<0?r=n+1:i=n}return r},Pi=(e,t,n)=>{let r=Ni(e,t,n);e.splice(r,0,t)},Fi=C({EQUAL:()=>0,GREATER_THAN:()=>1,LESS_THAN:()=>-1,insert:()=>Pi,isEqualTo:()=>ji,isGreaterThan:()=>ki,isGreaterThanEqual:()=>Ai,isLessThan:()=>Oi,newF:()=>xi,newFieldF:()=>Si,order:()=>Ei,primitiveArrays:()=>Ci,reverseF:()=>Di,search:()=>Ni,stringsWithNumbers:()=>Mi,uniqueUnorderedPrimitiveArrays:()=>Ti,unorderedPrimitiveArrays:()=>wi}),Ii=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},Li=C({LENGTH:()=>11,create:()=>Hi}),Ri=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,zi=`0123456789${Ri}`,Bi=Ii(Ri,1),Vi=Ii(zi,10),Hi=()=>`${Bi()}${Vi()}`,Ui=(e,t)=>n=>n instanceof t||typeof n==`object`&&!!n&&`discriminator`in n&&n.discriminator===e,Wi=2**12-1,Gi=2**16-1,Ki=2**20-1,qi=-128,Ji=-(2**15),Yi=2**15-1,Xi=-(2n**63n),Zi=2n**63n-1n,Qi=-(2**63),$i=2**63-1,ea=e=>(t,n)=>{if(typeof t==`bigint`){if(aa(n))return e(t,BigInt(n));let r=e(Number(t),Number(n));return typeof r==`number`?BigInt(Math.round(r)):r}return e(Number(t),Number(n))},ta=ea((e,t)=>e-t),na=ea((e,t)=>e+t),ra=(e,t)=>{let n=typeof e==`bigint`,r=typeof t==`bigint`;return n&&r?e===t:n&&aa(t)?e===BigInt(t):r&&aa(e)?t===BigInt(e):e===t},ia=ea((e,t)=>e<=t?e:t),aa=e=>typeof e==`bigint`?!0:Number.isInteger(e),oa=e=>typeof e==`bigint`?e<0n?-e:e:e<0?-e:e,sa=ea((e,t)=>e*t),ca=ea((e,t)=>e/t),la=l.z.tuple([l.z.number(),l.z.number()]),ua=[`x`,`y`],da=l.z.enum(ua),fa=[`top`,`right`,`bottom`,`left`],pa=l.z.enum(fa),ma=[`left`,`right`],ha=l.z.enum(ma),ga=[`top`,`bottom`],_a=l.z.enum(ga),va=[`center`],ya=l.z.enum(va),ba=[`top`,`right`,`bottom`,`left`,`center`],xa=l.z.enum(ba),Sa=[`start`,`center`,`end`],Ca=l.z.enum(Sa),wa=[`first`,`last`],Ta=l.z.enum(wa),Ea=l.z.object({clientX:l.z.number(),clientY:l.z.number()}),Da=l.z.object({width:l.z.number(),height:l.z.number()}),Oa=l.z.object({signedWidth:l.z.number(),signedHeight:l.z.number()}),ka=l.z.object({lower:l.z.number(),upper:l.z.number()});l.z.enum([`x`,`y`,...fa,...va]),l.z.union([da,l.z.enum([...fa,...va]),l.z.instanceof(String)]);var E=(e,t,n)=>{let r={};if(typeof t==`object`&&(n=t,t=void 0),n={makeValid:!0,...n},typeof e==`number`||typeof e==`bigint`)t==null?(r.lower=typeof e==`bigint`?0n:0,r.upper=e):(r.lower=e,r.upper=t);else if(Array.isArray(e)){if(e.length!==2)throw Error(`bounds: expected array of length 2`);[r.lower,r.upper]=e}else r.lower=e.lower,r.upper=e.upper;return n?.makeValid?Aa(r):r};Object.freeze({lower:0,upper:0}),Object.freeze({lower:-1/0,upper:1/0}),Object.freeze({lower:0,upper:1}),Object.freeze({lower:-1,upper:1});var Aa=e=>e.lower>e.upper?{lower:e.upper,upper:e.lower}:e,ja=(e,t)=>{let n=E(e);return t<n.lower?n.lower:t>=n.upper?n.upper-(typeof n.upper==`number`?1:1n):t},Ma=(e,t)=>{let n=E(e);if(typeof t==`number`||typeof t==`bigint`)return t>=n.lower&&t<n.upper;let r=E(t);return r.lower>=n.lower&&r.upper<=n.upper},Na=e=>({lower:Math.min(...e.map(e=>E(e).lower)),upper:Math.max(...e.map(e=>E(e).upper))}),Pa=(e,t,n)=>{let r=e.map(e=>E(e)),i=n>0?1:n<0?-1:0;if(i===0)return t;let a=n,o=t;for(;ra(a,0)===!1;){let e=r.findIndex(e=>i>0?o>=e.lower&&o<e.upper:o>e.lower&&o<=e.upper);if(e!==-1){let t=r[e],n;if(n=i>0?ta(t.upper,o):ta(o,t.lower),n>0){let e=ia(oa(a),n);if(o=na(o,i>0?e:-e),a=ta(a,i>0?e:-e),ra(a,0))return o;continue}}if(i>0){let e=r.filter(e=>e.lower>o);if(e.length>0)o=e[0].lower;else return o}else{let e=r.filter(e=>e.upper<o);if(e.length>0)o=e[e.length-1].upper;else return o}}return o},Fa=(e,t,n)=>{let r=e.map(e=>E(e));if(t===n)return typeof t==`bigint`?0n:0;let i=E(t<n?[t,n]:[n,t]),a=typeof t==`bigint`?0n:0;for(let e of r){let t=e.lower>i.lower?e.lower:i.lower,n=e.upper<i.upper?e.upper:i.upper;if(t<n){let e=n-t;a+=e}}return a};l.z.object({x:ha.or(ya),y:_a.or(ya)});var Ia=l.z.object({x:ha,y:_a}),La=Object.freeze({x:`left`,y:`top`}),Ra=Object.freeze({x:`right`,y:`top`}),za=Object.freeze({x:`left`,y:`bottom`}),Ba=Object.freeze({x:`right`,y:`bottom`}),Va=Object.freeze({x:`center`,y:`center`}),Ha=Object.freeze({x:`center`,y:`top`}),Ua=Object.freeze({x:`center`,y:`bottom`}),Wa=Object.freeze({x:`right`,y:`center`}),Ga=Object.freeze({x:`left`,y:`center`});Object.freeze([Ga,Wa,Ha,Ua,La,Ra,za,Ba,Va]);var Ka=(e,t)=>e.x===t.x&&e.y===t.y,qa=e=>[e.x,e.y];l.z.enum([`top`,`right`,`bottom`,`left`]);var Ja=l.z.object({x:l.z.number(),y:l.z.number()}),Ya=l.z.union([l.z.number(),Ja,la,Da,Oa,Ea]),Xa=(e,t)=>{if(typeof e==`string`){if(t===void 0)throw Error(`The y coordinate must be given.`);return e===`x`?{x:t,y:0}:{x:0,y:t}}return typeof e==`number`?{x:e,y:t??e}:Array.isArray(e)?{x:e[0],y:e[1]}:`signedWidth`in e?{x:e.signedWidth,y:e.signedHeight}:`clientX`in e?{x:e.clientX,y:e.clientY}:`width`in e?{x:e.width,y:e.height}:{x:e.x,y:e.y}},Za=Object.freeze({x:0,y:0});Object.freeze({x:1,y:1}),Object.freeze({x:1/0,y:1/0}),Object.freeze({x:NaN,y:NaN});var Qa=(e,t)=>{let n=Xa(e);return{x:n.x+t,y:n.y}},$a=(e,t)=>{let n=Xa(e);return{x:n.x,y:n.y+t}},eo=(e,t,n,...r)=>{if(typeof t==`string`){if(typeof n!=`number`)throw Error(`The value must be a number.`);return t===`x`?Qa(e,n):$a(e,n)}if(typeof t==`object`&&`x`in t&&typeof t.x==`string`){let r=Xa(n),i=Xa(e);return t.x===`left`?r.x=-r.x:t.x===`center`&&(r.x=0),t.y===`top`?r.y=-r.y:t.y===`center`&&(r.y=0),{x:i.x+r.x,y:i.y+r.y}}return[e,t,n??Za,...r].reduce((e,t)=>{let n=Xa(t);return{x:e.x+n.x,y:e.y+n.y}},Za)},to=l.z.union([l.z.number(),l.z.string()]);l.z.object({top:to,left:to,width:to,height:to}),l.z.object({left:l.z.number(),top:l.z.number(),right:l.z.number(),bottom:l.z.number()}),l.z.object({one:Ja,two:Ja,root:Ia});var no=(e,t,n=0,r=0,i)=>{let a={one:{...Za},two:{...Za},root:i??La};if(typeof e==`number`){if(typeof t!=`number`)throw Error(`Box constructor called with invalid arguments`);return a.one={x:e,y:t},a.two={x:a.one.x+n,y:a.one.y+r},a}return`one`in e&&`two`in e&&`root`in e?{...e,root:i??e.root}:(`getBoundingClientRect`in e&&(e=e.getBoundingClientRect()),`left`in e?(a.one={x:e.left,y:e.top},a.two={x:e.right,y:e.bottom},a):(a.one=e,t==null?a.two={x:a.one.x+n,y:a.one.y+r}:typeof t==`number`?a.two={x:a.one.x+t,y:a.one.y+n}:`width`in t?a.two={x:a.one.x+t.width,y:a.one.y+t.height}:`signedWidth`in t?a.two={x:a.one.x+t.signedWidth,y:a.one.y+t.signedHeight}:a.two=t,a))},ro=(e,t)=>{let n=no(e);return{x:t.x===`center`?co(n).x:io(n,t.x),y:t.y===`center`?co(n).y:io(n,t.y)}},io=(e,t)=>{let n=no(e),r=qa(n.root).includes(t)?Math.min:Math.max;return ma.includes(t)?r(n.one.x,n.two.x):r(n.one.y,n.two.y)},ao=e=>{let t=no(e);return t.two.x-t.one.x},oo=e=>{let t=no(e);return t.two.y-t.one.y},so=e=>ro(e,La),co=e=>eo(so(e),{x:ao(e)/2,y:oo(e)/2}),lo=e=>{let t=no(e);return{lower:t.one.x,upper:t.two.x}},uo=e=>{let t=no(e);return{lower:t.one.y,upper:t.two.y}},fo=e=>typeof e!=`object`||!e?!1:`one`in e&&`two`in e&&`root`in e;l.z.union([Da,Oa,Ja,la]);var po=(e,t,n)=>t!==void 0&&e<t?t:n!==void 0&&e>n?n:e;l.z.object({offset:Ya,scale:Ya}),l.z.object({offset:l.z.number(),scale:l.z.number()});var mo=e=>(t,n,r,i)=>n===`dimension`?[t,r]:[t,i?r-e:r+e],ho=e=>(t,n,r,i)=>[t,i?r/e:r*e],go=e=>(t,n,r)=>{if(t===null)return[e,r];let{lower:i,upper:a}=t,{lower:o,upper:s}=e,c=a-i,l=s-o;return n===`dimension`?[e,l/c*r]:[e,(r-i)*(l/c)+o]},_o=e=>(t,n,r)=>[e,r],vo=()=>(e,t,n)=>{if(e===null)throw Error(`cannot invert without bounds`);if(t===`dimension`)return[e,n];let{lower:r,upper:i}=e;return[e,i-(n-r)]},yo=e=>(t,n,r)=>{let{lower:i,upper:a}=e;return r=po(r,i,a),[t,r]},bo=class e{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(t){return new e().translate(t)}static magnify(t){return new e().magnify(t)}static scale(t,n){return new e().scale(t,n)}translate(e){let t=this.new(),n=mo(e);return n.type=`translate`,t.ops.push(n),t}magnify(e){let t=this.new(),n=ho(e);return n.type=`magnify`,t.ops.push(n),t}scale(e,t){let n=E(e,t),r=this.new(),i=go(n);return i.type=`scale`,r.ops.push(i),r}clamp(e,t){let n=E(e,t),r=this.new(),i=yo(n);return i.type=`clamp`,r.ops.push(i),r}reBound(e,t){let n=E(e,t),r=this.new(),i=_o(n);return i.type=`re-bound`,r.ops.push(i),r}invert(){let e=vo();e.type=`invert`;let t=this.new();return t.ops.push(e),t}pos(e){return this.exec(`position`,e)}dim(e){return this.exec(`dimension`,e)}new(){let t=new e;return t.ops=this.ops.slice(),t.reversed=this.reversed,t}exec(e,t){return this.currBounds=null,this.ops.reduce(([t,n],r)=>r(t,e,n,this.reversed),[null,t])[1]}reverse(){let e=this.new();e.ops.reverse();let t=[];return e.ops.forEach((n,r)=>{if(n.type===`scale`||t.some(([e,t])=>r>=e&&r<=t))return;let i=e.ops.findIndex((e,t)=>e.type===`scale`&&t>r);i!==-1&&t.push([r,i])}),t.forEach(([t,n])=>{let r=e.ops.slice(t,n);r.unshift(e.ops[n]),e.ops.splice(t,n-t+1,...r)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new e};(class e{x;y;currRoot;constructor(e=new bo,t=new bo,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(t,n){return new e().translate(t,n)}static translateX(t){return new e().translateX(t)}static translateY(t){return new e().translateY(t)}static clamp(t){return new e().clamp(t)}static magnify(t){return new e().magnify(t)}static scale(t){return new e().scale(t)}static reBound(t){return new e().reBound(t)}translate(e,t){let n=Xa(e,t),r=this.copy();return r.x=this.x.translate(n.x),r.y=this.y.translate(n.y),r}translateX(e){let t=this.copy();return t.x=this.x.translate(e),t}translateY(e){let t=this.copy();return t.y=this.y.translate(e),t}magnify(e){let t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){let t=this.copy();if(fo(e)){let n=this.currRoot;return t.currRoot=e.root,n!=null&&!Ka(n,e.root)&&(n.x!==e.root.x&&(t.x=t.x.invert()),n.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(lo(e)),t.y=t.y.scale(uo(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){let t=this.copy();return t.x=this.x.reBound(lo(e)),t.y=this.y.reBound(uo(e)),t}clamp(e){let t=this.copy();return t.x=this.x.clamp(lo(e)),t.y=this.y.clamp(uo(e)),t}copy(){let t=new e;return t.currRoot=this.currRoot,t.x=this.x,t.y=this.y,t}reverse(){let e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return no(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new e});var xo=C({ALIGNMENTS:()=>Sa,CENTER_LOCATIONS:()=>va,DIRECTIONS:()=>ua,LOCATIONS:()=>ba,ORDERS:()=>wa,OUTER_LOCATIONS:()=>fa,X_LOCATIONS:()=>ma,Y_LOCATIONS:()=>ga,alignmentZ:()=>Ca,boundsZ:()=>ka,centerLocationZ:()=>ya,clientXyZ:()=>Ea,dimensionsZ:()=>Da,directionZ:()=>da,locationZ:()=>xa,orderZ:()=>Ta,outerLocationZ:()=>pa,signedDimensionsZ:()=>Oa,xLocationZ:()=>ha,xyZ:()=>Ja,yLocationZ:()=>_a});Ja.extend({root:Ia,units:l.default.object({x:l.default.enum([`px`,`decimal`]),y:l.default.enum([`px`,`decimal`])})}).partial({root:!0,units:!0});var So=l.z.enum([`static`,`dynamic`]),Co=365,wo=30,To=l.z.union([l.z.tuple([l.z.int()]),l.z.tuple([l.z.int(),l.z.int().min(1).max(12)]),l.z.tuple([l.z.int(),l.z.int().min(1).max(12),l.z.int().min(1).max(31)])]),Eo=(e,t)=>{let n=new D(t);if(![O.DAY,O.HOUR,O.MINUTE,O.SECOND,O.MILLISECOND,O.MICROSECOND,O.NANOSECOND].some(e=>e.equals(n)))throw Error(`Invalid argument for remainder. Must be an even TimeSpan or Timestamp`);let r=e.valueOf()%n.valueOf();return e instanceof D?new D(r):new O(r)},D=class e extends mi{constructor(t,n=`UTC`){if(t==null)super(e.now().valueOf());else if(t instanceof Date)super(BigInt(t.getTime())*e.MILLISECOND.valueOf());else if(typeof t==`string`)super(e.parseDateTimeString(t,n).valueOf());else if(Array.isArray(t))super(e.parseDate(t));else{let r=0n;t instanceof Number&&(t=t.valueOf()),n===`local`&&(r=e.utcOffset.valueOf()),typeof t==`number`&&(isFinite(t)?t=t===$i?Zi:Math.trunc(t):(isNaN(t)&&(t=0),t=t===1/0?e.MAX:e.MIN)),T(t)&&(t=t.value),super(BigInt(t.valueOf())+r)}}static parseDate([t=1970,n=1,r=1]){let i=new Date(t,n-1,r,0,0,0,0);return new e(BigInt(i.getTime())*e.MILLISECOND.valueOf()).truncate(e.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(t,n=`UTC`){let[r,i,a]=t.split(`:`),o=`00`,s=`00`;a!=null&&([o,s]=a.split(`.`));let c=e.hours(parseInt(r??`00`,10)).add(e.minutes(parseInt(i??`00`,10))).add(e.seconds(parseInt(o??`00`,10))).add(e.milliseconds(parseInt(s??`00`,10)));return n===`local`&&(c=c.add(e.utcOffset)),c.valueOf()}static parseDateTimeString(t,n=`UTC`){if(!t.includes(`/`)&&!t.includes(`-`))return e.parseTimeString(t,n);if(t.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?$/)!=null){let r=t,i=0;if(t.includes(`.`)){let e=t.split(`.`);r=e[0];let n=e[1]||`0`;i=parseInt(n.padEnd(3,`0`).slice(0,3),10)}let a=n===`local`?new Date(r.replace(`T`,` `)):new Date(`${r}Z`);return BigInt(a.getTime())*e.MILLISECOND.valueOf()+BigInt(i)*e.MILLISECOND.valueOf()}let r=new Date(t);return t.includes(`:`)||r.setUTCHours(0,0,0,0),new e(BigInt(r.getTime())*e.MILLISECOND.valueOf(),n).valueOf()}toISOString(t=`UTC`){if(t===`UTC`)return this.date().toISOString();let n=this.date(),r=new O(BigInt(n.getTimezoneOffset())*e.MINUTE.valueOf());return this.sub(r).date().toISOString()}timeString(e=!1,t=`UTC`){let n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){let e=this.date();return`${e.toLocaleString(`default`,{month:`short`})} ${e.toLocaleString(`default`,{day:`numeric`})}`}static get utcOffset(){return new O(BigInt(new Date().getTimezoneOffset())*e.MINUTE.valueOf())}static since(t){return new e().span(t)}date(){return new Date(this.milliseconds)}equals(t){return this.valueOf()===new e(t).valueOf()}span(e){return this.range(e).span}range(e){return new A(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(t){return this.valueOf()>new e(t).valueOf()}afterEq(t){return this.valueOf()>=new e(t).valueOf()}before(t){return this.valueOf()<new e(t).valueOf()}beforeEq(t){return this.valueOf()<=new e(t).valueOf()}add(t){return new e(na(this.valueOf(),new O(t).valueOf()))}sub(t){return new e(ta(this.valueOf(),new O(t).valueOf()))}get hours(){return Number(this.valueOf())/Number(O.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(O.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(O.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(O.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(e.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(e.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}get localYear(){return this.date().getFullYear()}setYear(t){let n=this.date();return n.setUTCFullYear(t),new e(n)}setLocalYear(t){let n=this.date();return n.setFullYear(t),new e(n)}get month(){return this.date().getUTCMonth()}get localMonth(){return this.date().getMonth()}setMonth(t){let n=this.date();return n.setUTCMonth(t),new e(n)}setLocalMonth(t){let n=this.date();return n.setMonth(t),new e(n)}get day(){return this.date().getUTCDate()}get localDay(){return this.date().getDate()}setDay(t){let n=this.date();return n.setUTCDate(t),new e(n)}setLocalDay(t){let n=this.date();return n.setDate(t),new e(n)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(t){let n=this.date();return n.setHours(t),new e(n)}setHour(t){let n=this.date();return n.setUTCHours(t),new e(n)}get minute(){return this.date().getUTCMinutes()}get localMinute(){return this.date().getMinutes()}setMinute(t){let n=this.date();return n.setUTCMinutes(t),new e(n)}setLocalMinute(t){let n=this.date();return n.setMinutes(t),new e(n)}get second(){return this.date().getUTCSeconds()}get localSecond(){return this.date().getSeconds()}setSecond(t){let n=this.date();return n.setUTCSeconds(t),new e(n)}setLocalSecond(t){let n=this.date();return n.setSeconds(t),new e(n)}get millisecond(){return this.date().getUTCMilliseconds()}get localMillisecond(){return this.date().getMilliseconds()}setMillisecond(t){let n=this.date();return n.setUTCMilliseconds(t),new e(n)}setLocalMillisecond(t){let n=this.date();return n.setMilliseconds(t),new e(n)}toString(e=`ISO`,t=`UTC`){switch(e){case`ISODate`:return this.toISOString(t).slice(0,10);case`ISOTime`:return this.toISOString(t).slice(11,23);case`time`:return this.timeString(!1,t);case`preciseTime`:return this.timeString(!0,t);case`date`:return this.dateString();case`preciseDate`:return`${this.dateString()} ${this.timeString(!0,t)}`;case`dateTime`:return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}remainder(e){return Eo(this,e)}get isToday(){return this.truncate(O.DAY).equals(e.now().truncate(O.DAY))}truncate(e){return this.sub(this.remainder(e))}formatBySpan(e){return e.greaterThanOrEqual(O.days(30))?`shortDate`:e.greaterThanOrEqual(O.DAY)?`dateTime`:e.greaterThanOrEqual(O.HOUR)?`time`:e.greaterThanOrEqual(O.SECOND)?`preciseTime`:`ISOTime`}static now(){return new e(new Date)}static max(...t){let n=e.MIN;for(let r of t){let t=new e(r);t.after(n)&&(n=t)}return n}static min(...t){let n=e.MAX;for(let r of t){let t=new e(r);t.before(n)&&(n=t)}return n}static nanoseconds(t,n=`UTC`){return new e(t,n)}static NANOSECOND=e.nanoseconds(1);static microseconds(t,n=`UTC`){return e.nanoseconds(t*1e3,n)}static MICROSECOND=e.microseconds(1);static milliseconds(t,n=`UTC`){return e.microseconds(t*1e3,n)}static MILLISECOND=e.milliseconds(1);static seconds(t,n=`UTC`){return e.milliseconds(t*1e3,n)}static SECOND=e.seconds(1);static minutes(t,n=`UTC`){return e.seconds(t*60,n)}static MINUTE=e.minutes(1);static hours(t,n=`UTC`){return e.minutes(t*60,n)}static HOUR=e.hours(1);static days(t,n=`UTC`){return e.hours(t*24,n)}static DAY=e.days(1);static MAX=new e(Zi);static MIN=new e(0);static ZERO=new e(0);static z=l.z.union([l.z.instanceof(e),l.z.object({value:l.z.bigint()}).transform(t=>new e(t.value)),l.z.string().transform(t=>new e(BigInt(t))),l.z.number().transform(t=>new e(t)),l.z.bigint().transform(t=>new e(t)),l.z.date().transform(t=>new e(t)),l.z.custom(e=>e instanceof O).transform(t=>new e(t)),To.transform(t=>new e(t))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},O=class e extends mi{constructor(e){typeof e==`number`&&(e=Math.trunc(e.valueOf())),T(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(t){return t instanceof e?t:t instanceof Do?t.period:t instanceof D?new e(t):(T(t)&&(t=t.value),[`number`,`bigint`].includes(typeof t)?e.seconds(t):new e(t))}static fromMilliseconds(t){return t instanceof e?t:t instanceof Do?t.period:t instanceof D?new e(t):(T(t)&&(t=t.value),[`number`,`bigint`].includes(typeof t)?e.milliseconds(t):new e(t))}valueOf(){return this.value}lessThan(t){return this.valueOf()<new e(t).valueOf()}greaterThan(t){return this.valueOf()>new e(t).valueOf()}lessThanOrEqual(t){return this.valueOf()<=new e(t).valueOf()}greaterThanOrEqual(t){return this.valueOf()>=new e(t).valueOf()}remainder(e){return Eo(this,e)}truncate(t){return new e(BigInt(Math.trunc(Number(this.valueOf()/t.valueOf())))*t.valueOf())}toString(t=`full`){if(t===`semantic`)return this.toSemanticString();let n=this.truncate(e.DAY),r=this.truncate(e.HOUR),i=this.truncate(e.MINUTE),a=this.truncate(e.SECOND),o=this.truncate(e.MILLISECOND),s=this.truncate(e.MICROSECOND),c=this.truncate(e.NANOSECOND),l=n,u=r.sub(n),d=i.sub(r),f=a.sub(i),p=o.sub(a),m=s.sub(o),h=c.sub(s),g=``;return l.isZero||(g+=`${l.days}d `),u.isZero||(g+=`${u.hours}h `),d.isZero||(g+=`${d.minutes}m `),f.isZero||(g+=`${f.seconds}s `),p.isZero||(g+=`${p.milliseconds}ms `),m.isZero||(g+=`${m.microseconds}µs `),h.isZero||(g+=`${h.nanoseconds}ns`),g.trim()}toSemanticString(){let t=new e(this.valueOf()<0n?-this.valueOf():this.valueOf()),n=this.valueOf()<0n;if(t.valueOf()===0n)return`0s`;if(t.lessThan(e.SECOND))return`< 1s`;let r=t.days,i=t.hours,a=t.minutes,o=t.seconds,s=Math.floor(r/Co),c=Math.floor(r/wo),l=Math.floor(r/7),u=Math.floor(r),d=Math.floor(i),f=Math.floor(a),p=Math.floor(o),m=n?`-`:``;if(s>=1){let e=`${s}y`;if(s<2){let t=Math.floor(r%Co/wo);t>0&&(e+=` ${t}mo`)}return m+e}if(l>=1&&r<wo&&r%7==0){let e=`${l}w`,t=Math.floor(r%7),n=Math.floor(i-l*7*24);return l<2&&(t>0?e+=` ${t}d`:n>0&&n<24&&(e+=` ${n}h`)),m+e}if(c>=1){let e=`${c}mo`;if(c<3){let t=Math.floor(r%wo);t>0&&(e+=` ${t}d`)}return m+e}if(l>=1){let e=`${l}w`,t=Math.floor(r%7),n=Math.floor(i-l*7*24);return l<2&&(t>0?e+=` ${t}d`:n>0&&n<24&&(e+=` ${n}h`)),m+e}if(u>=1){let e=`${u}d`,t=Math.floor(i-u*24);return u<2&&t>0&&(e+=` ${t}h`),m+e}if(d>=1){let e=`${d}h`;if(d<3){let t=Math.floor(a-d*60);t>0&&(e+=` ${t}m`)}return m+e}if(f>=1){let e=`${f}m`;if(f<5){let t=Math.floor(o-f*60);t>0&&(e+=` ${t}s`)}return m+e}return`${m}${p}s`}mult(t){return new e(sa(this.valueOf(),t))}div(t){return new e(ca(this.valueOf(),t))}get days(){return Number(this.valueOf())/Number(e.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(e.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(e.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(e.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(e.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(e.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(t){return this.valueOf()===new e(t).valueOf()}add(t){return new e(this.valueOf()+new e(t).valueOf())}sub(t){return new e(this.valueOf()-new e(t).valueOf())}static nanoseconds(t=1){return new e(t)}static NANOSECOND=e.nanoseconds(1);static microseconds(t=1){return e.nanoseconds(sa(t,1e3))}static MICROSECOND=e.microseconds(1);static milliseconds(t=1){return e.microseconds(sa(t,1e3))}static MILLISECOND=e.milliseconds(1);static seconds(t=1){return e.milliseconds(sa(t,1e3))}static SECOND=e.seconds(1);static minutes(t=1){return e.seconds(sa(t,60))}static MINUTE=e.minutes(1);static hours(t){return e.minutes(sa(t,60))}static HOUR=e.hours(1);static days(t){return e.hours(sa(t,24))}static DAY=e.days(1);static MAX=new e(Zi);static MIN=new e(0);static ZERO=new e(0);static z=l.z.union([l.z.object({value:l.z.bigint()}).transform(t=>new e(t.value)),l.z.string().transform(t=>new e(BigInt(t))),l.z.number().transform(t=>new e(t)),l.z.bigint().transform(t=>new e(t)),l.z.instanceof(e),l.z.instanceof(D).transform(t=>new e(t)),l.z.custom(e=>e instanceof Do).transform(t=>new e(t))])},Do=class e extends mi{constructor(e){T(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(t){return this.valueOf()===new e(t).valueOf()}get period(){return O.seconds(1/this.valueOf())}sampleCount(e){return new O(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new k(t).valueOf()}span(e){return O.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new k(t).valueOf())}add(t){return new e(na(this.valueOf(),new e(t).valueOf()))}sub(t){return new e(ta(this.valueOf(),new e(t).valueOf()))}mult(t){return new e(sa(this.valueOf(),t))}div(t){return new e(ca(this.valueOf(),t))}static hz(t){return new e(t)}static khz(t){return e.hz(t*1e3)}static z=l.z.union([l.z.number().transform(t=>new e(t)),l.z.instanceof(e)])},k=class e extends mi{constructor(e){T(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Oo(e*this.valueOf())}add(t){return new e(na(this.valueOf(),new e(t).valueOf()))}sub(t){return new e(ta(this.valueOf(),new e(t).valueOf()))}mult(t){return new e(sa(this.valueOf(),t))}div(t){return new e(ca(this.valueOf(),t))}static UNKNOWN=new e(0);static BIT128=new e(16);static BIT64=new e(8);static BIT32=new e(4);static BIT16=new e(2);static BIT8=new e(1);static z=l.z.union([l.z.number().transform(t=>new e(t)),l.z.instanceof(e)])},A=class e{start;end;constructor(e,t){typeof e==`object`&&`start`in e?(this.start=new D(e.start),this.end=new D(e.end)):(this.start=new D(e),this.end=new D(t))}get span(){return new O(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new e(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=O.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),r=this.end.sub(e.end).valueOf();return n<0&&(n=-n),r<0&&(r=-r),n<=t.valueOf()&&r<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString(`preciseDate`)} - ${this.span.toString()}`}overlapsWith(e,t=O.ZERO){e=e.makeValid();let n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;let r=D.max(n.start,e.start),i=D.min(n.end,e.end);return i.before(r)?!1:new O(i.sub(r)).greaterThanOrEqual(t)}contains(t){return t instanceof e?this.contains(t.start)&&this.contains(t.end):this.start.beforeEq(t)&&this.end.after(t)}boundBy(t){let n=new e(this.start,this.end);return t.start.after(this.start)&&(n.start=t.start),t.start.after(this.end)&&(n.end=t.start),t.end.before(this.end)&&(n.end=t.end),t.end.before(this.start)&&(n.start=t.end),n}static max(...t){return new e(D.min(...t.map(e=>e.start)),D.max(...t.map(e=>e.end)))}static MAX=new e(D.MIN,D.MAX);static ZERO=new e(D.ZERO,D.ZERO);static z=l.z.union([l.z.object({start:D.z,end:D.z}).transform(t=>new e(t.start,t.end)),l.z.instanceof(e)]);static boundedZ=e.z.refine(({isValid:e})=>e,{message:`Time range start time must be before or equal to time range end time`}).refine(({end:e})=>e.valueOf()<=Zi,{message:`Time range end time must be less than or equal to the maximum value of an int64`}).refine(({start:e})=>e.valueOf()>=Xi,{message:`Time range start time must be greater than or equal to the minimum value of an int64`});static sort(e,t){return D.sort(e.start,t.start)||D.sort(e.end,t.end)}static merge(...t){return e.max(...t.map(t=>new e(t).makeValid()))}},j=class e extends mi{constructor(t){if(T(t)&&(t=t.value),t instanceof e||typeof t==`string`||typeof t.valueOf()==`string`)super(t.valueOf());else{let n=e.ARRAY_CONSTRUCTOR_DATA_TYPES.get(t.constructor.name);if(n==null)throw Error(`unable to find data type for ${t.toString()}`);super(n.valueOf())}}get Array(){let t=e.ARRAY_CONSTRUCTORS.get(this.toString());if(t==null)throw Error(`unable to find array constructor for ${this.valueOf()}`);return t}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(e=>this.equals(e))}toString(t=!1){return t?e.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(e.JSON)||this.equals(e.STRING)||this.equals(e.BYTES)}get isNumeric(){return!this.isVariable&&!this.equals(e.UUID)}get isInteger(){let e=this.toString();return e.startsWith(`int`)||e.startsWith(`uint`)}get isFloat(){return this.toString().startsWith(`float`)}get density(){let t=e.DENSITIES.get(this.toString());if(t==null)throw Error(`unable to find density for ${this.valueOf()}`);return t}get isUnsignedInteger(){return this.equals(e.UINT8)||this.equals(e.UINT16)||this.equals(e.UINT32)||this.equals(e.UINT64)}get isSignedInteger(){return this.equals(e.INT8)||this.equals(e.INT16)||this.equals(e.INT32)||this.equals(e.INT64)}canSafelyCastTo(t){return this.equals(t)?!0:!this.isNumeric||!t.isNumeric||this.isVariable||t.isVariable||this.isUnsignedInteger&&t.isSignedInteger?!1:this.isFloat?t.isFloat&&this.density.valueOf()<=t.density.valueOf():this.equals(e.INT32)&&t.equals(e.FLOAT64)||this.equals(e.INT8)&&t.equals(e.FLOAT32)?!0:this.isInteger&&t.isInteger?this.density.valueOf()<=t.density.valueOf()&&this.isUnsignedInteger===t.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return e.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new e(`unknown`);static FLOAT64=new e(`float64`);static FLOAT32=new e(`float32`);static INT64=new e(`int64`);static INT32=new e(`int32`);static INT16=new e(`int16`);static INT8=new e(`int8`);static UINT64=new e(`uint64`);static UINT32=new e(`uint32`);static UINT16=new e(`uint16`);static UINT8=new e(`uint8`);static TIMESTAMP=new e(`timestamp`);static UUID=new e(`uuid`);static STRING=new e(`string`);static JSON=new e(`json`);static BYTES=new e(`bytes`);static ARRAY_CONSTRUCTORS=new Map([[e.UINT8.toString(),Uint8Array],[e.UINT16.toString(),Uint16Array],[e.UINT32.toString(),Uint32Array],[e.UINT64.toString(),BigUint64Array],[e.FLOAT32.toString(),Float32Array],[e.FLOAT64.toString(),Float64Array],[e.INT8.toString(),Int8Array],[e.INT16.toString(),Int16Array],[e.INT32.toString(),Int32Array],[e.INT64.toString(),BigInt64Array],[e.TIMESTAMP.toString(),BigInt64Array],[e.STRING.toString(),Uint8Array],[e.JSON.toString(),Uint8Array],[e.UUID.toString(),Uint8Array],[e.BYTES.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,e.UINT8],[Uint16Array.name,e.UINT16],[Uint32Array.name,e.UINT32],[BigUint64Array.name,e.UINT64],[Float32Array.name,e.FLOAT32],[Float64Array.name,e.FLOAT64],[Int8Array.name,e.INT8],[Int16Array.name,e.INT16],[Int32Array.name,e.INT32],[BigInt64Array.name,e.INT64]]);static DENSITIES=new Map([[e.UINT8.toString(),k.BIT8],[e.UINT16.toString(),k.BIT16],[e.UINT32.toString(),k.BIT32],[e.UINT64.toString(),k.BIT64],[e.FLOAT32.toString(),k.BIT32],[e.FLOAT64.toString(),k.BIT64],[e.INT8.toString(),k.BIT8],[e.INT16.toString(),k.BIT16],[e.INT32.toString(),k.BIT32],[e.INT64.toString(),k.BIT64],[e.TIMESTAMP.toString(),k.BIT64],[e.STRING.toString(),k.UNKNOWN],[e.JSON.toString(),k.UNKNOWN],[e.UUID.toString(),k.BIT128],[e.BYTES.toString(),k.UNKNOWN]]);static ALL=[e.UNKNOWN,e.UINT8,e.UINT16,e.UINT32,e.UINT64,e.INT8,e.INT16,e.INT32,e.INT64,e.FLOAT32,e.FLOAT64,e.TIMESTAMP,e.UUID,e.STRING,e.JSON,e.BYTES];static SHORT_STRINGS=new Map([[e.UINT8.toString(),`u8`],[e.UINT16.toString(),`u16`],[e.UINT32.toString(),`u32`],[e.UINT64.toString(),`u64`],[e.INT8.toString(),`i8`],[e.INT16.toString(),`i16`],[e.INT32.toString(),`i32`],[e.INT64.toString(),`i64`],[e.FLOAT32.toString(),`f32`],[e.FLOAT64.toString(),`f64`],[e.TIMESTAMP.toString(),`ts`],[e.UUID.toString(),`uuid`],[e.STRING.toString(),`str`],[e.JSON.toString(),`json`],[e.BYTES.toString(),`bytes`]]);static BIG_INT_TYPES=[e.INT64,e.UINT64,e.TIMESTAMP];static z=l.z.union([l.z.string().transform(t=>new e(t)),l.z.instanceof(e)])},Oo=class e extends mi{constructor(e){T(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return T(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return T(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(t){return T(t)&&(t=t.value),new e(na(this.valueOf(),t.valueOf()))}sub(t){return T(t)&&(t=t.value),new e(ta(this.valueOf(),t.valueOf()))}mult(t){return new e(sa(this.valueOf(),t))}div(t){return new e(ca(this.valueOf(),t))}truncate(t){return new e(Math.trunc(this.valueOf()/new e(t).valueOf())*new e(t).valueOf())}remainder(t){return e.bytes(this.valueOf()%new e(t).valueOf())}get gigabytes(){return this.valueOf()/e.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/e.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/e.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/e.TERABYTE.valueOf()}toString(){let t=this.truncate(e.TERABYTE),n=this.truncate(e.GIGABYTE),r=this.truncate(e.MEGABYTE),i=this.truncate(e.KILOBYTE),a=this.truncate(e.BYTE),o=t,s=n.sub(t),c=r.sub(n),l=i.sub(r),u=a.sub(i),d=``;return o.isZero||(d+=`${o.terabytes}TB `),s.isZero||(d+=`${s.gigabytes}GB `),c.isZero||(d+=`${c.megabytes}MB `),l.isZero||(d+=`${l.kilobytes}KB `),(!u.isZero||d===``)&&(d+=`${u.valueOf()}B`),d.trim()}static bytes(t=1){return new e(t)}static BYTE=new e(1);static kilobytes(t=1){return e.bytes(new e(t).valueOf()*1e3)}static KILOBYTE=e.kilobytes(1);static megabytes(t=1){return e.kilobytes(new e(t).valueOf()*1e3)}static MEGABYTE=e.megabytes(1);static gigabytes(t=1){return e.megabytes(new e(t).valueOf()*1e3)}static GIGABYTE=e.gigabytes(1);static terabytes(t){return e.gigabytes(new e(t).valueOf()*1e3)}static TERABYTE=e.terabytes(1);static ZERO=new e(0);static z=l.z.union([l.z.number().transform(t=>new e(t)),l.z.instanceof(e)]);get isZero(){return this.valueOf()===0}},ko=l.z.object({start:l.z.number(),end:l.z.number()}),Ao=l.z.union([l.z.instanceof(Uint8Array),l.z.instanceof(Uint16Array),l.z.instanceof(Uint32Array),l.z.instanceof(BigUint64Array),l.z.instanceof(Float32Array),l.z.instanceof(Float64Array),l.z.instanceof(Int8Array),l.z.instanceof(Int16Array),l.z.instanceof(Int32Array),l.z.instanceof(BigInt64Array)]),jo=e=>{let t=typeof e;return t===`string`||t===`number`||t===`boolean`||t===`bigint`||e instanceof D||e instanceof O||e instanceof Date},Mo=(e,t,n,r=0)=>e.usesBigInt&&!t.usesBigInt?Number(n)-Number(r):!e.usesBigInt&&t.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):ta(n,r),No=A.z,Po=D.z,Fo=O.z,Io=Do.z,Lo=Oo.z,Ro=j.z,zo=A.boundedZ,Bo=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Vo(e){return typeof e==`string`&&Bo.test(e)}var M=[];for(let e=0;e<256;++e)M.push((e+256).toString(16).slice(1));function Ho(e,t=0){return(M[e[t+0]]+M[e[t+1]]+M[e[t+2]]+M[e[t+3]]+`-`+M[e[t+4]]+M[e[t+5]]+`-`+M[e[t+6]]+M[e[t+7]]+`-`+M[e[t+8]]+M[e[t+9]]+`-`+M[e[t+10]]+M[e[t+11]]+M[e[t+12]]+M[e[t+13]]+M[e[t+14]]+M[e[t+15]]).toLowerCase()}function Uo(e,t=0){let n=Ho(e,t);if(!Vo(n))throw TypeError(`Stringified UUID is invalid`);return n}typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);var Wo=(e,t)=>Uo(e,t),Go=-1,Ko={[Symbol.iterator]:()=>Ko,next:()=>({done:!0,value:void 0})},qo=l.z.string().transform(e=>new Uint8Array(atob(e).split(``).map(e=>e.charCodeAt(0))).buffer),Jo=l.z.union([l.z.null(),l.z.undefined()]).transform(()=>new Uint8Array().buffer),Yo=10,Xo=(e,t)=>{if(e===`number`&&!t.isNumeric)throw Error(`cannot convert series of type ${t.toString()} to number`);if(e===`bigint`&&!t.usesBigInt)throw Error(`cannot convert series of type ${t.toString()} to bigint`)},Zo=`sy_x_telem_series`,Qo=class e{key;discriminator=Zo;dataType;sampleOffset;gl;_data;timeRange=A.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=Go;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=l.z.object({timeRange:A.z.optional(),dataType:j.z,alignment:l.z.coerce.bigint().optional(),data:l.z.union([qo,Jo,l.z.instanceof(ArrayBuffer),l.z.instanceof(Uint8Array)]),glBufferUsage:So.default(`static`).optional()});static z=e.crudeZ.transform(t=>new e(t));constructor(e){$o(e)&&(e={data:e}),e.data??=[];let{dataType:t,timeRange:n,sampleOffset:r=0,glBufferUsage:i=`static`,alignment:a=0n,alignmentMultiple:o=1n,key:s=Hi(),data:c}=e;if(es(c)){let e=c;this.key=e.key,this.dataType=e.dataType,this.sampleOffset=e.sampleOffset,this.gl=e.gl,this._data=e._data,this.timeRange=e.timeRange,this.alignment=e.alignment,this.alignmentMultiple=e.alignmentMultiple,this.cachedMin=e.cachedMin,this.cachedMax=e.cachedMax,this.writePos=e.writePos,this._refCount=e._refCount,this.cachedLength=e.cachedLength;return}let l=jo(c),u=Array.isArray(c);if(t!=null)this.dataType=new j(t);else if(c instanceof ArrayBuffer)throw Error(`cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.`);else if(u||l){let e=c;if(!l){if(c.length===0)throw Error(`cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.`);e=c[0]}if(typeof e==`string`)this.dataType=j.STRING;else if(typeof e==`number`)this.dataType=j.FLOAT64;else if(typeof e==`bigint`)this.dataType=j.INT64;else if(typeof e==`boolean`)this.dataType=j.UINT8;else if(e instanceof D||e instanceof Date||e instanceof D)this.dataType=j.TIMESTAMP;else if(typeof e==`object`)this.dataType=j.JSON;else throw Error(`cannot infer data type of ${typeof e} when constructing a Series from a JS array`)}else this.dataType=new j(c);if(!u&&!l)this._data=c;else if(u&&c.length===0)this._data=new this.dataType.Array([]).buffer;else{let e=l?[c]:c,t=e[0];(t instanceof D||t instanceof Date||t instanceof O)&&(e=e.map(e=>new D(e).valueOf())),this.dataType.equals(j.STRING)?(this.cachedLength=e.length,this._data=new TextEncoder().encode(`${e.join(`
|
|
9
|
+
`)}\n`).buffer):this.dataType.equals(j.JSON)?(this.cachedLength=e.length,this._data=new TextEncoder().encode(`${e.map(e=>li.encodeString(e)).join(`
|
|
10
|
+
`)}\n`).buffer):this.dataType.usesBigInt&&typeof t==`number`?this._data=new this.dataType.Array(e.map(e=>BigInt(Math.round(e)))).buffer:!this.dataType.usesBigInt&&typeof t==`bigint`?this._data=new this.dataType.Array(e.map(Number)).buffer:this._data=new this.dataType.Array(e).buffer}this.key=s,this.alignment=a,this.alignmentMultiple=o,this.sampleOffset=r??0,this.timeRange=n??A.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:i}}static alloc({capacity:t,dataType:n,...r}){if(t===0)throw Error(`[Series] - cannot allocate an array of length 0`);let i=new e({data:new new j(n).Array(t).buffer,dataType:n,...r});return i.writePos=0,i}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn(`cannot release a series with a negative reference count`)}write(e){if(!e.dataType.equals(this.dataType))throw Error(`buffer must be of the same type as this array`);return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===Go)return 0;let t=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,t);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===Go)return 0;let t=this.capacity-this.writePos,n=e.sub(0,t);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data==`object`&&`buffer`in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Go?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
|
|
11
|
+
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(j.JSON))throw Error(`cannot parse non-JSON series as JSON`);return this.toStrings().map(t=>e.parse(li.decodeString(t)))}get byteCapacity(){return new Oo(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Go?this.byteCapacity:this.dataType.isVariable?new Oo(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength==null?this.dataType.isVariable?this.calculateCachedLength():this.writePos===Go?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos:this.cachedLength}calculateCachedLength(){if(!this.dataType.isVariable)throw Error(`cannot calculate length of a non-variable length data type`);let e=0,t=[0];return this.data.forEach((n,r)=>{n===Yo&&(e++,t.push(r+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(t,n=0){if(this.dataType.equals(t))return this;let r=new t.Array(this.length);for(let e=0;e<this.length;e++)r[e]=Mo(this.dataType,t,this.data[e],n);return new e({data:r.buffer,dataType:t,timeRange:this.timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){return this.length===0?-1/0:(this.dataType.equals(j.TIMESTAMP)?this.cachedMax=this.data[this.data.length-1]:(this.dataType.usesBigInt,this.cachedMax=this.data.reduce((e,t)=>e>t?e:t)),this.cachedMax)}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw Error(`cannot calculate maximum on a variable length data type`);return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),na(this.cachedMax,this.sampleOffset))}calcRawMin(){return this.length===0?1/0:(this.dataType.equals(j.TIMESTAMP)?this.cachedMin=this.data[0]:(this.dataType.usesBigInt,this.cachedMin=this.data.reduce((e,t)=>e<t?e:t)),this.cachedMin)}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw Error(`cannot calculate minimum on a variable length data type`);return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),na(this.cachedMin,this.sampleOffset))}get bounds(){return E(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){let t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){let t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){let n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(t===!0)throw Error(`[series] - no value at index ${n}`);return}return this.at(n,t)}at(e,t=!1){if(this.dataType.isVariable)return this.atVariable(e,t??!1);if(this.dataType.equals(j.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);let n=this.data[e];if(n==null){if(t===!0)throw Error(`[series] - no value at index ${e}`);return}return na(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);let n=Wo(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(t)throw Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,t){let n=0,r=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],r=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let t=0;t<this.data.length;t++)if(this.data[t]===Yo){if(e===0){r=t;break}n=t+1,e--}if(r===0&&(r=this.data.length),n>=r||e>0){if(t)throw Error(`[series] - no value at index ${e}`);return}}let i=this.data.slice(n,r);return this.dataType.equals(j.STRING)?new TextDecoder().decode(i):Xr(JSON.parse(new TextDecoder().decode(i)))}binarySearch(e){let t=0,n=this.length-1,r=xi(e);for(;t<=n;){let i=Math.floor((t+n)/2),a=r(this.at(i,!0),e);if(a===0)return i;a<0?t=i+1:n=i-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(j.FLOAT32)&&!this.dataType.equals(j.UINT8))throw Error(`Only FLOAT32 and UINT8 arrays can be used in WebGL`);let{buffer:t,bufferUsage:n,prevBuffer:r}=this.gl;if(t??(this.gl.buffer=e.createBuffer()),this.writePos!==r)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Go){r===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);let t=this.dataType.density.size(r).valueOf(),n=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,t,n.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n===`static`?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Go}as(e){return Xo(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:ls(this.alignmentBounds.lower),upper:ls(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return E(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw Error(`gl buffer not initialized`);return this.gl.prevBuffer!==this.writePos&&console.warn(`buffer not updated`),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){let e=new ns(this);return this.dataType.equals(j.JSON)?new rs(e):e}return this.dataType.equals(j.UUID)?new is(this):new as(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new ts(this,e,t??this.length)}subAlignmentIterator(e,t){let n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),r=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new ts(this,n,r)}subBytes(t,n){return t>=0&&(n==null||n>=this.byteLength.valueOf())?this:new e({data:this.data.subarray(t,n),dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}sliceSub(t,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return i=t?this.data.subarray(n,r):this.data.slice(n,r),new e({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(t){return new e({data:this.buffer,dataType:this.dataType,timeRange:A.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:`static`,alignment:t})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(e=>e.toString());else{for(let t=0;t<5;t++)e+=`${this.at(t)?.toString()}`,e+=`,`;e+=`...,`;for(let t=-5;t<0;t++)e+=this.at(t)?.toString(),t<-1&&(e+=`,`)}return e+=`])`,e}},$o=e=>e==null?!1:Array.isArray(e)||e instanceof ArrayBuffer||ArrayBuffer.isView(e)&&!(e instanceof DataView)||e instanceof Qo?!0:jo(e),es=Ui(Zo,Qo),ts=class{series;end;index;constructor(e,t,n){this.series=e;let r=E(0,e.length+1);this.end=ja(r,n),this.index=ja(r,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},ns=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw Error(`cannot create a variable series iterator for a non-variable series`);this.series=e,this.index=0,this.decoder=new TextDecoder}next(){let e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==Yo;)this.index++;let n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}},rs=class e{wrapped;static schema=l.z.record(l.z.string(),l.z.unknown());constructor(e){this.wrapped=e}next(){let t=this.wrapped.next();return t.done===!0?{done:!0,value:void 0}:{done:!1,value:li.decodeString(t.value,e.schema)}}},is=class{series;index;data;density;constructor(e){if(!e.dataType.equals(j.UUID))throw Error(`cannot create a UUID series iterator for a non-UUID series`);this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=j.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};let e=Wo(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}},as=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},os=class{series;constructor(e=[]){if(e.length!==0){let t=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(t))throw Error(`[multi-series] - series must have the same data type`)}this.series=e}as(e){return Xo(e,this.dataType),this}get dataType(){return this.series.length===0?j.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?A.ZERO:new A(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}get alignment(){return this.series.length===0?0n:this.series[0].alignment}get alignmentBounds(){return this.series.length===0?E(0n,0n):E(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){let t=()=>Error(`cannot push a ${e.dataType.toString()} series to a ${this.dataType.toString()} multi-series`),n=e.dataType.equals(this.dataType);if(es(e)){if(this.series.length!==0&&!n)throw t();this.series.push(e)}else{if(this.series.length!==0&&e.series.length!==0&&!n)throw t();this.series.push(...e.series)}}get length(){return this.series.reduce((e,t)=>e+t.length,0)}atAlignment(e,t){for(let n of this.series)if(Ma(n.alignmentBounds,e))return n.atAlignment(e,t);if(t)throw Error(`[series] - no value at alignment ${e}`)}at(e,t=!1){e<0&&(e=this.length+e);for(let n of this.series){if(e<n.length)return n.at(e,t);e-=n.length}if(t)throw Error(`[series] - no value at index ${e}`)}subIterator(e,t){return new cs(this,e,t??this.length)}subAlignmentIterator(e,t){if(e>=this.alignmentBounds.upper||t<=this.alignmentBounds.lower)return Ko;let n=0;for(let t=0;t<this.series.length;t++){let r=this.series[t];if(e<r.alignment)break;if(e>=r.alignmentBounds.upper)n+=r.length;else if(Ma(r.alignmentBounds,e)){n+=Math.ceil(Number(e-r.alignment)/Number(r.alignmentMultiple));break}}let r=0;for(let e=0;e<this.series.length;e++){let n=this.series[e];if(t<n.alignment)break;if(t>=n.alignmentBounds.upper)r+=n.length;else if(Ma(n.alignmentBounds,t)){r+=Math.ceil(Number(t-n.alignment)/Number(n.alignmentMultiple));break}}return new cs(this,n,r)}subAlignmentSpanIterator(e,t){if(e>=this.alignmentBounds.upper)return Ko;t=Math.min(t,Number(this.distance(e,this.alignmentBounds.upper)));let n=0;for(let t=0;t<this.series.length;t++){let r=this.series[t];if(e<r.alignment)break;if(e>=r.alignmentBounds.upper)n+=r.length;else if(Ma(r.alignmentBounds,e)){n+=Number(e-r.alignment);break}}return new cs(this,n,n+t)}updateGLBuffer(e){this.series.forEach(t=>t.updateGLBuffer(e))}get bounds(){return Na(this.series.map(e=>e.bounds))}get byteLength(){return new Oo(this.series.reduce((e,t)=>e+t.byteLength.valueOf(),0))}get data(){let e=new this.dataType.Array(this.length),t=0;for(let n of this.series)e.set(n.data,t),t+=n.length;return new this.dataType.Array(e.buffer)}traverseAlignment(e,t){return Pa(this.series.map(e=>e.alignmentBounds),e,t)}acquire(e){this.series.forEach(t=>t.acquire(e))}release(){this.series.forEach(e=>e.release())}distance(e,t){return Fa(this.series.map(e=>e.alignmentBounds),e,t)}parseJSON(e){if(!this.dataType.equals(j.JSON))throw Error(`cannot parse non-JSON series as JSON`);return this.series.flatMap(t=>t.parseJSON(e))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new ss(this.series)}toStrings(){return this.series.flatMap(e=>e.toStrings())}},ss=class{series;seriesIndex;internal;constructor(e){this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){let e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[Symbol.iterator](){return this}},cs=class{series;index;end;constructor(e,t,n){this.series=e,this.end=n,this.index=t}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}},ls=e=>({domain:e>>32n,sample:e&4294967295n}),us=C({DataType:()=>j,Density:()=>k,MultiSeries:()=>os,Rate:()=>Do,Series:()=>Qo,Size:()=>Oo,TimeRange:()=>A,TimeSpan:()=>O,TimeStamp:()=>D,convertDataType:()=>Mo,dataTypeZ:()=>Ro,isCrudeSeries:()=>$o,isTelemValue:()=>jo,numericTimeRangeZ:()=>ko,rateZ:()=>Io,sizeZ:()=>Lo,timeRangeBoundedZ:()=>zo,timeRangeZ:()=>No,timeSpanZ:()=>Fo,timeStampZ:()=>Po,typedArrayZ:()=>Ao}),ds=async e=>await new Promise(t=>setTimeout(t,O.fromMilliseconds(e).milliseconds)),fs=C({Breaker:()=>ps,breakerConfigZ:()=>ms}),ps=class{config;retries;interval;constructor(e){this.config={baseInterval:new O(e?.baseInterval??O.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??ds},this.retries=0,this.interval=new O(this.config.baseInterval)}async wait(){let{maxRetries:e,scale:t,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(t),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}},ms=l.z.object({baseInterval:O.z.optional(),maxRetries:l.z.number().optional(),scale:l.z.number().optional()}),hs=e=>e.nullable().transform(e=>e===null?void 0:e).optional(),gs=l.z.int().min(qi).max(127),_s=l.z.int().min(Ji).max(Yi),vs=l.z.int().min(Qi).max($i),ys=l.z.int().min(0).max(255),bs=l.z.int().min(0).max(Wi),xs=l.z.int().min(0).max(Gi),Ss=l.z.int().min(0).max(Ki),Cs=e=>l.default.array(e).or(e.transform(e=>[e])),ws=(e,t)=>{let n=Array.isArray(e),r=Array.isArray(t);if(n!==r)return!1;if(n&&r){let n=e,r=t;if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(!ws(n[e],r[e]))return!1;return!0}if(e==null||t==null||typeof e!=`object`||typeof t!=`object`)return e===t;if(`equals`in e)return e.equals(t);let i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return!1;for(let n of i){let r=e[n],i=t[n];if(typeof r==`object`&&typeof i==`object`){if(!ws(r,i))return!1}else if(r!==i)return!1}return!0},Ts=(e,t)=>{if(typeof e!=`object`||!e)return e===t;let n=Object.keys(e),r=Object.keys(t);if(r.length>n.length)return!1;for(let n of r){let r=e[n],i=t[n];if(typeof r==`object`&&typeof i==`object`){if(!Ts(r,i))return!1}else if(r!==i)return!1}return!0},Es=(e,t,n=`.`)=>{let r=e.split(n);return r.map((e,i)=>{let a=t(e,i,r);return a==null?null:typeof a==`string`?a:a.join(n)}).filter(e=>e!=null).join(n)},Ds=(e,t)=>{if(!Array.isArray(e))return e[t];let n=e[t];if(n!=null||e.length==0)return n;let r=e[0];if(typeof r==`object`&&`key`in r)return e.find(e=>e.key===t)},Os=((e,t,n={optional:!1})=>{let{optional:r,getter:i=Ds}=n;if(t===``)return e;let a=t.split(`.`);if(a.length===1){let n=i(e,a[0]);if(n===void 0){if(r)return null;throw Error(`Path ${t} does not exist. ${a[0]} is undefined`)}return n}let o=(e,n)=>{if(n>=a.length)return e;for(let s=a.length-n;s>=1;s--){let c=a.slice(n,n+s).join(`.`),l=i(e,c);if(l!==void 0){if(n+s===a.length)return l;if(l===null){if(r)return null;throw Error(`Path ${t} does not exist. ${c} is null`)}return o(l,n+s)}}if(r)return null;throw Error(`Path ${t} does not exist. ${a[n]} is undefined`)};return o(e,0)}),ks=(e,...t)=>{if(t.length===0)return e;let n=t.shift();if(ii(e)&&ii(n))for(let t in n)try{ii(n[t])?(t in e||Object.assign(e,{[t]:{}}),ks(e[t],n[t])):Object.assign(e,{[t]:n[t]})}catch(e){throw e instanceof TypeError?TypeError(`.${t}: ${e.message}`,{cause:e}):e}return ks(e,...t)},As=e=>e._zod.def.output,js=e=>Es(e,(e,t,n)=>{let r=t===n.length-1,i=!isNaN(parseInt(e,10)),a=!isNaN(parseInt(n[t+1],10));return i&&(e=`element`),r||a?e:[e,`shape`]}),Ms=(e,t)=>{if(e==null)return null;let n=e[t];return n==null&&typeof e==`object`&&`sourceType`in e?e.sourceType()[t]:n},Ns=((e,t,n)=>t===``?e:Os(Ms(e,`shape`),js(t),{...n,getter:Ms})),N=C({functionOutput:()=>As,getFieldSchema:()=>Ns,getFieldSchemaPath:()=>js,int16:()=>_s,int64:()=>vs,int8:()=>gs,nullToUndefined:()=>hs,toArray:()=>Cs,uint12:()=>bs,uint16:()=>xs,uint20:()=>Ss,uint8:()=>ys}),Ps=l.z.string().regex(/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i),Fs=ys,Is=l.z.number().min(0).max(1),Ls=l.z.tuple([Fs,Fs,Fs,Is]),Rs=l.z.tuple([Fs,Fs,Fs]),zs=l.z.object({rgba255:Ls}),Bs=l.z.object({r:Fs,g:Fs,b:Fs,a:Is}),Vs=l.z.number().min(0).max(360),Hs=l.z.number().min(0).max(100),Us=l.z.number().min(0).max(100),Ws=l.z.tuple([Vs,Hs,Us,Is]),Gs=l.z.union([Ps,Rs,Ls,Ws,zs,Bs]),Ks=Gs.transform(e=>P(e)),qs=e=>Ks.safeParse(e).success,Js=e=>Ls.safeParse(e).success,Ys=(e=>{if(e==null)return;let t=Ks.safeParse(e);if(t.success)return Qs(t.data);if(typeof e==`string`)return e;throw t.error}),P=(e,t=1)=>{if(e=Gs.parse(e),typeof e==`string`)return gc(e,t);if(Array.isArray(e)){if(e.length<3||e.length>4)throw Error(`Invalid color: [${e.join(`, `)}]`);return e.length===3?[...e,t]:e}return`a`in e&&`r`in e?[e.r,e.g,e.b,e.a]:e.rgba255},Xs=(e,t)=>{if(e==null||t==null)return e==t;let n=P(e),r=P(t);return n.every((e,t)=>e===r[t])},Zs=(e=>{if(e==null)return;let[t,n,r,i]=P(e),a=Math.round(i*255);return`#${vc(t)}${vc(n)}${vc(r)}${a===255?``:vc(a)}`}),Qs=e=>{let[t,n,r,i]=P(e);return`rgba(${t}, ${n}, ${r}, ${i})`},$s=e=>`rgb(${ec(e)})`,ec=e=>{let[t,n,r]=P(e);return`${t}, ${n}, ${r}`},tc=e=>[...nc(e),oc(e)],nc=e=>[rc(e)/255,ic(e)/255,ac(e)/255],rc=e=>P(e)[0],ic=e=>P(e)[1],ac=e=>P(e)[2],oc=e=>P(e)[3],sc=e=>Xs(_c,e),cc=e=>Tc(P(e)),lc=(e,t)=>{let[n,r,i]=P(e);if(t>100)throw Error(`Color opacity must be between 0 and 100, got ${t}`);return t>1&&(t/=100),[n,r,i,t]},uc=e=>{let[t,n,r]=nc(e).map(e=>e<=.03928?e/12.92:((e+.055)/1.055)**2.4);return Number((.2126*t+.7152*n+.0722*r).toFixed(3))},dc=e=>{let[t,n,r]=nc(e);return 1-(Math.max(t,n,r)-Math.min(t,n,r))},fc=(e,t)=>{let n=P(e),r=P(t),i=uc(n),a=uc(r);return(Math.max(i,a)+.5)/(Math.min(i,a)+.5)},pc=(e,...t)=>{if(t.length===0)throw Error(`[Color.pickByContrast] - must provide at least one color`);let n=P(e),[r]=t.sort((e,t)=>fc(n,t)-fc(n,e));return P(r)},mc=e=>uc(e)<.5,hc=e=>uc(e)>.5,gc=(e,t=1)=>(e=Ps.parse(e),e=bc(e),[yc(e,0),yc(e,2),yc(e,4),e.length===8?yc(e,6)/255:t]),_c=[0,0,0,0],vc=e=>Math.floor(e).toString(16).padStart(2,`0`),yc=(e,t)=>parseInt(e.slice(t,t+2),16),bc=e=>e.startsWith(`#`)?e.slice(1):e,xc={black:`#000000`,white:`#ffffff`,red:`#ff0000`,green:`#008000`,blue:`#0000ff`,yellow:`#ffff00`,cyan:`#00ffff`,magenta:`#ff00ff`,silver:`#c0c0c0`,gray:`#808080`,grey:`#808080`,maroon:`#800000`,olive:`#808000`,lime:`#00ff00`,aqua:`#00ffff`,teal:`#008080`,navy:`#000080`,fuchsia:`#ff00ff`,purple:`#800080`,orange:`#ffa500`,brown:`#a52a2a`,tan:`#d2b48c`,gold:`#ffd700`,indigo:`#4b0082`,violet:`#ee82ee`,pink:`#ffc0cb`,coral:`#ff7f50`,salmon:`#fa8072`,khaki:`#f0e68c`,crimson:`#dc143c`,transparent:`transparent`},Sc=e=>{if(!e)return;let t=e.trim().toLowerCase();if(!(t===`transparent`||t===`none`)){if(t.startsWith(`#`)){if(t.length===4){let e=t[1],n=t[2],r=t[3],i=`#${e}${e}${n}${n}${r}${r}`;if(Ps.safeParse(i).success)return gc(i)}return(t.length===7||t.length===9)&&Ps.safeParse(t).success?gc(t):void 0}if(t.startsWith(`rgb`)){let e=t.match(/rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/);if(e){let[,t,n,r,i]=e;return[parseInt(t,10),parseInt(n,10),parseInt(r,10),i?parseFloat(i):1]}}if(xc[t])return gc(xc[t])}},Cc=e=>{e=Ws.parse(e);let[t,n,r]=e,i=e[3];t/=360,n/=100,r/=100;let a,o,s;if(n===0)a=o=s=r;else{let e=r<.5?r*(1+n):r+n-r*n,i=2*r-e;a=wc(i,e,t+1/3),o=wc(i,e,t),s=wc(i,e,t-1/3)}return[Math.round(a*255),Math.round(o*255),Math.round(s*255),i]},wc=(e,t,n)=>(n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e),Tc=e=>{e=Ls.parse(e);let[t,n,r]=e,i=e[3];t/=255,n/=255,r/=255;let a=Math.max(t,n,r),o=Math.min(t,n,r),s,c,l=(a+o)/2;if(a===o)s=c=0;else{let e=a-o;c=l>.5?e/(2-a-o):e/(a+o),s=a===t?(n-r)/e+(n<r?6:0):a===n?(r-t)/e+2:(t-n)/e+4,s/=6}return s*=360,c*=100,l*=100,[Math.round(s),Math.round(c),Math.round(l),i]},Ec=P(`#000000`),Dc=P(`#ffffff`),Oc=l.z.object({key:l.z.string(),color:Gs,position:l.z.number(),switched:l.z.boolean().optional()}),kc=l.z.array(Oc),Ac=(e,t)=>{if(e.length===0)return _c;if(e=e.slice().sort((e,t)=>e.position-t.position),t<=e[0].position)return P(e[0].color);if(t>=e[e.length-1].position)return P(e[e.length-1].color);for(let n=0;n<e.length-1;n++){let r=e[n],i=e[n+1];if(t<r.position||t>i.position)continue;if(t===r.position)return P(r.color);if(t===i.position)return P(i.color);let a=(t-r.position)/(i.position-r.position),o=P(r.color),s=P(i.color);return P([Math.round(rc(o)+a*(rc(s)-rc(o))),Math.round(ic(o)+a*(ic(s)-ic(o))),Math.round(ac(o)+a*(ac(s)-ac(o))),oc(o)+a*(oc(s)-oc(o))])}return P(e[e.length-1].color)},jc=l.z.object({key:l.z.string(),name:l.z.string(),color:Ks}),Mc=l.z.object({key:l.z.string(),name:l.z.string(),swatches:l.z.array(jc)}),Nc=C({BLACK:()=>Ec,WHITE:()=>Dc,ZERO:()=>_c,aValue:()=>oc,bValue:()=>ac,colorZ:()=>Ks,construct:()=>P,contrast:()=>fc,crudeZ:()=>Gs,cssString:()=>Ys,equals:()=>Xs,fromCSS:()=>Sc,fromGradient:()=>Ac,fromHSLA:()=>Cc,gValue:()=>ic,gradientZ:()=>kc,grayness:()=>dc,hex:()=>Zs,hsla:()=>cc,isColor:()=>Js,isCrude:()=>qs,isDark:()=>mc,isLight:()=>hc,isZero:()=>sc,luminance:()=>uc,paletteZ:()=>Mc,pickByContrast:()=>pc,rValue:()=>rc,rgbCSS:()=>$s,rgbString:()=>ec,rgba1:()=>tc,rgbaCSS:()=>Qs,setAlpha:()=>lc,stopZ:()=>Oc}),Pc=ys,Fc=function(e){return e[e.exclusive=0]=`exclusive`,e[e.shared=1]=`shared`,e}({}),Ic=l.z.enum(Fc),Lc=l.z.object({key:l.z.string(),name:l.z.string(),group:l.z.uint32().optional()}),Rc=e=>l.z.object({subject:Lc,resource:e,authority:Pc}),zc={lower:0,upper:256},Bc=(...e)=>t=>t.filter(t=>{let n=!1;return t.to!=null&&(n=e.includes(t.to.resource)),t.from!=null&&!n&&(n=e.includes(t.from.resource)),n}),Vc=e=>l.z.object({from:Rc(e),to:l.z.null().optional()}),Hc=e=>l.z.object({from:l.z.null().optional(),to:Rc(e)}),Uc=e=>l.z.union([Vc(e),Hc(e),l.z.object({from:Rc(e),to:Rc(e)})]),F=C({ABSOLUTE_AUTHORITY:()=>255,AUTHORITY_BOUNDS:()=>zc,Concurrency:()=>Fc,ZERO_AUTHORITY:()=>0,acquireZ:()=>Hc,authorityZ:()=>Pc,concurrencyZ:()=>Ic,filterTransfersByChannelKey:()=>Bc,releaseZ:()=>Vc,stateZ:()=>Rc,subjectZ:()=>Lc,transferZ:()=>Uc}),Wc=C({formatValue:()=>Gc}),Gc=e=>{switch(typeof e){case`bigint`:case`number`:return e.toString();case`boolean`:return e?`1`:`0`;case`undefined`:return``;case`string`:case`symbol`:case`function`:return qc(e.toString());case`object`:return e==null?``:qc(JSON.stringify(e))}},Kc=/[",\n]/,qc=e=>Kc.test(e)?`"${e.replace(/"/g,`""`)}"`:e,Jc=(e,t)=>{let n=null;return t===0?e:(...r)=>{n!==null&&(clearTimeout(n),n=null),n=setTimeout(()=>e(...r),t)}},Yc=e=>Object.getOwnPropertySymbols(globalThis).includes(e),Xc=(e,t)=>{let n=Symbol.for(e);if(!Yc(n)){let e=t();Object.defineProperty(globalThis,n,{value:e})}return()=>globalThis[n]},Zc=C({Canceled:()=>ul,NONE:()=>`nil`,NotImplemented:()=>dl,UNKNOWN:()=>nl,Unknown:()=>cl,createTyped:()=>el,decode:()=>sl,encode:()=>ol,isTyped:()=>tl,payloadZ:()=>ll,register:()=>al}),Qc=`sy_x_error`,$c=e=>t=>typeof t==`object`&&t&&`type`in t&&typeof t.type==`string`?t.type.startsWith(e):t instanceof Error?t.message.startsWith(e):typeof t==`string`?t.startsWith(e):!1,el=e=>class t extends Error{static discriminator=Qc;discriminator=t.discriminator;static TYPE=e;type=t.TYPE;static matches=$c(e);matches=t.matches;constructor(e,n){super(e,n),this.name=t.TYPE}static sub(t){return el(`${e}.${t}`)}},tl=e=>{if(typeof e!=`object`||!e)return!1;let t=e;if(t.discriminator!==Qc)return!1;if(!(`type`in t))throw Error(`X Error is missing its type property: ${JSON.stringify(t)}`);return!0},nl=`unknown`,rl=class{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:`nil`,data:``};if(tl(e))for(let t of this.providers){let n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:nl,data:e.message};if(typeof e==`string`)return{type:nl,data:e};try{return{type:nl,data:JSON.stringify(e)}}catch{return{type:nl,data:`unable to encode error information`}}}decode(e){if(e==null||e.type===`nil`)return null;if(e.type===`unknown`)return new cl(e.data);for(let t of this.providers){let n=t.decode(e);if(n!=null)return n}return new cl(e.data)}},il=Xc(`synnax-error-registry`,()=>new rl),al=({encode:e,decode:t})=>il().register({encode:e,decode:t}),ol=e=>il().encode(e),sl=e=>e==null?null:il().decode(e),cl=class extends el(`unknown`){},ll=l.z.object({type:l.z.string(),data:l.z.string()}),ul=class extends el(`canceled`){},dl=class extends el(`not_implemented`){};l.z.string().regex(/^(?:$|(?:\/(?:[^~/]|~0|~1)*)+)$/,`must be a valid JSON pointer (RFC 6901)`),l.z.union([l.z.string(),l.z.number(),l.z.boolean(),l.z.null()]),l.z.enum([`string`,`number`,`boolean`,`null`]),l.z.object({key:l.z.string(),value:l.z.string()});var fl=C({keyZ:()=>pl,labelZ:()=>ml,newZ:()=>hl}),pl=l.z.uuid(),ml=l.z.object({key:pl,name:l.z.string().min(1),color:Ks}),hl=ml.partial({key:!0}),gl=C({compareSemVer:()=>yl,createMigration:()=>Cl,migrator:()=>wl,semVerNewer:()=>xl,semVerOlder:()=>Sl,semVerZ:()=>_l,versionsEqual:()=>bl}),_l=l.z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/),vl=(e,t)=>{let n=e.split(`.`),r=t.split(`.`),i=Math.max(n.length,r.length);for(let e=0;e<i;e++){let t=n[e],i=r[e];if(t===void 0)return-1;if(i===void 0)return 1;let a=/^\d+$/.test(t),o=/^\d+$/.test(i);if(a&&!o)return-1;if(!a&&o)return 1;if(a&&o){let e=parseInt(t,10),n=parseInt(i,10);if(e<n)return-1;if(e>n)return 1}else{if(t<i)return-1;if(t>i)return 1}}return 0},yl=((e,t,n={})=>{n.checkMajor??=!0,n.checkMinor??=!0,n.checkPatch??=!0;let r=_l.parse(e),i=_l.parse(t),[a,o]=r.split(`-`),[s,c]=i.split(`-`),[l,u,d]=a.split(`.`).map(Number),[f,p,m]=s.split(`.`).map(Number);if(n.checkMajor){if(l<f)return-1;if(l>f)return 1}if(n.checkMinor){if(u<p)return-1;if(u>p)return 1}if(n.checkPatch){if(d<m)return-1;if(d>m)return 1}return o===void 0&&c===void 0?0:o===void 0?1:c===void 0?-1:vl(o,c)}),bl=(e,t,n={})=>ji(yl(e,t,n)),xl=(e,t,n={})=>ki(yl(e,t,n)),Sl=(e,t,n={})=>Oi(yl(e,t,n)),Cl=({name:e,migrate:t})=>n=>{try{let r=t(n);return console.log(`${e} migrated: ${n.version} -> ${r.version}`),r}catch(t){throw console.log(`${e} failed to migrate from ${n.version}`),console.error(t),t}},wl=({name:e,migrations:t,targetSchema:n,defaultVersion:r,def:i})=>{let a=Object.keys(t).sort(yl).pop();if(a==null)return t=>{if(t.version??=r,t.version!==i.version)return console.log(`${e} version ${t.version} is newer than latest version of ${i.version}.
|
|
14
12
|
Returning default instead.
|
|
15
|
-
`),
|
|
16
|
-
${JSON.stringify(o,null,2)}`}catch{a=`Description: ${t.description}`}r.push(a)}if("details"in t&&bo(t.details)){const a=t.details;"stack"in a&&r.push(`Stack Trace:
|
|
17
|
-
${String(a.stack)}`);const o=Object.fromEntries(Object.entries(a).filter(([c])=>c!=="stack"&&c!=="error"));Object.keys(o).length>0&&r.push(`Details:
|
|
18
|
-
${JSON.stringify(o,null,2)}`)}return r.join(`
|
|
13
|
+
`),i;try{return n==null?t:n.parse(t)}catch(t){return console.log(`${e} failed to parse default. Exiting with default`),console.error(t),i}};let o=Object.keys(t).length,s=!1,c=n=>{try{if(o===0||xl(n.version,a))return console.log(s?`${e} ${n.version} now up to date`:`${e} version ${n.version} is up to date with target version ${i.version}`),n;let r=t[n.version],l=r(n);return s=!0,c(l)}catch(t){return console.log(`${e} failed to migrate from ${n.version} to ${a}`),console.error(t),i}};return t=>{try{if(t.version==null)if(r!=null)console.log(`${e} version is null. Setting version to default of ${r}`),t.version=r;else return console.log(`${e} version is null and no default version set. Exiting with default`),i;return c(t)}catch(t){return console.log(`${e} failed to parse final result. Exiting with default`),console.error(t),i}}};l.z.enum([`standard`,`scientific`,`engineering`]);var Tl=C({BaseObserver:()=>Dl,Observer:()=>El}),El=class{handlers;transform;closer;constructor(e,t){this.transform=e,this.handlers=t??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let t=e;if(this.transform!=null){let[n,r]=this.transform(e);if(!r)return;t=n}this.handlers.forEach((e,n)=>n(t))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}},Dl=class{handlers;constructor(e){this.handlers=e??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){this.handlers.forEach((t,n)=>n(e))}},I=C({entries:()=>Al,keyZ:()=>Ol,map:()=>jl,nullishToEmpty:()=>Pl,omit:()=>Nl,purgeUndefined:()=>Ml,unknownZ:()=>kl}),Ol=l.z.union([l.z.string(),l.z.number()]),kl=()=>l.z.record(Ol,l.z.unknown()),Al=e=>Object.entries(e),jl=(e,t)=>Object.fromEntries(Al(e).map(([e,n])=>[e,t(n,e)])),Ml=e=>Object.fromEntries(Al(e).filter(([e,t])=>t!==void 0)),Nl=(e,...t)=>{let n={...e};for(let e of t)delete n[e];return n},Pl=()=>l.z.union([l.z.union([l.z.null(),l.z.undefined()]).transform(()=>({})),kl()]),Fl=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null?`node`:typeof window>`u`||window.document===void 0?`webworker`:`browser`,Il=Fl(),Ll=[`macOS`,`Windows`,`Linux`],Rl=[`macos`,`windows`,`linux`],zl={macos:`macOS`,windows:`Windows`,linux:`Linux`},Bl=l.z.enum(Ll).or(l.z.enum(Rl).transform(e=>zl[e])),Vl=()=>{if(typeof window>`u`)return;let e=window.navigator.userAgent.toLowerCase();if(e.includes(`mac`))return`macOS`;if(e.includes(`win`))return`Windows`;if(e.includes(`linux`))return`Linux`},Hl,Ul=((e={})=>{let{force:t,default:n}=e;return t??Hl??(Hl=Vl(),Hl??n)}),Wl=C({OPERATING_SYSTEMS:()=>Ll,RUNTIME:()=>Il,detect:()=>Fl,getOS:()=>Ul,osZ:()=>Bl}),Gl=l.z.object({stack:l.z.string(),error:l.z.instanceof(Error)}),Kl=(e,t)=>{if(!(e instanceof Error))throw e;return ql({variant:`error`,message:t??e.message,description:t==null?void 0:e.message,details:{stack:e.stack??``,error:e}})},ql=e=>({key:Hi(),time:D.now(),name:``,...e}),Jl=(e,t=[])=>{if(e!=null)return Array.isArray(t)?t.includes(e)?e:void 0:t===e?e:void 0},Yl=(e,t=[])=>{if(e!=null)return Array.isArray(t)?t.includes(e)?void 0:e:t===e?void 0:e},Xl={includeTimestamp:!1,includeName:!0},Zl=(e,t={})=>{let n={...Xl,...t},r=[],i=e.variant.toUpperCase();if(n.includeName&&e.name.length>0&&(i+=` [${e.name}]`),i+=`: ${e.message}`,n.includeTimestamp&&(i+=` (${e.time.toString(`dateTime`,`local`)})`),r.push(i),e.description!=null){let t;try{let n=JSON.parse(e.description);t=`Description:\n${JSON.stringify(n,null,2)}`}catch{t=`Description: ${e.description}`}r.push(t)}if(`details`in e&&ii(e.details)){let t=e.details;`stack`in t&&r.push(`Stack Trace:\n${String(t.stack)}`);let n=Object.fromEntries(Object.entries(t).filter(([e])=>e!==`stack`&&e!==`error`));Object.keys(n).length>0&&r.push(`Details:\n${JSON.stringify(n,null,2)}`)}return r.join(`
|
|
19
14
|
|
|
20
|
-
`)},
|
|
15
|
+
`)},Ql=[`success`,`info`,`warning`,`error`,`loading`,`disabled`],$l=l.z.enum(Ql),eu=l.z.literal(`success`),tu=l.z.literal(`info`),nu=l.z.literal(`warning`),ru=l.z.literal(`error`),iu=l.z.literal(`loading`),au=l.z.literal(`disabled`),ou=({details:e,v:t}={})=>l.z.object({key:l.z.string().default(()=>Hi()),name:l.z.string().default(``),variant:t??$l,message:l.z.string(),description:l.z.string().optional(),time:Po.default(()=>D.now()),details:e??l.z.unknown().optional(),labels:hs(ml.array())}),su=({details:e,v:t}={})=>ou({details:e,v:t}).partial({key:!0,name:!0,time:!0}),cu=C({VARIANTS:()=>Ql,create:()=>ql,disabledVariantZ:()=>au,errorVariantZ:()=>ru,exceptionDetailsSchema:()=>Gl,fromException:()=>Kl,infoVariantZ:()=>tu,keepVariants:()=>Jl,loadingVariantZ:()=>iu,newZ:()=>su,removeVariants:()=>Yl,statusZ:()=>ou,successVariantZ:()=>eu,toString:()=>Zl,variantZ:()=>$l,warningVariantZ:()=>nu}),lu=(e,t)=>{if(!t.has(e))return e;let n,r,i=e;for(;t.has(i);){let e=i.match(uu);e?(n=i.slice(0,e.index).trim(),r=parseInt(e[1],10)+1):(n=i,r=1),i=`${n} (${r})`}return i},uu=/\((\d+)\)$/,du=(e,t=``)=>{if(typeof e==`string`)return e;let n=e.length;return n===0?t:n===1?e[0]:n===2?`${e[0]} and ${e[1]}`:`${e.slice(0,-1).join(`, `)}, and ${e[n-1]}`},fu=e=>{let t=e.split(` `),n=new Set,r=t.map(e=>e.charAt(0).toLowerCase()).join(``);n.add(r.replace(/-/g,`_`)),n.add(r.replace(/(.)(.)/g,`$1_$2`).replace(/-/g,`_`));let i=/\d+/g;e.match(i)&&t.forEach((e,r)=>{if(i.test(e)){let e=t.map((e,t)=>t===r?e:e.charAt(0).toLowerCase()).join(``);n.add(e.replace(/-/g,`_`)),n.add(e.replace(/(.)(.)/g,`$1_$2`).replace(/-/g,`_`))}});let a=t.map(e=>(e.length>3?e.substring(0,3):e).toLowerCase());return n.add(a.join(``).replace(/-/g,`_`)),n.add(a.join(`_`).replace(/-/g,`_`)),Array.from(n).filter(e=>e.length>=2&&e.length<=12&&!/^\d/.test(e))},pu=(e,t)=>e.startsWith(t)?e.slice(t.length):e,mu=C({createShortIdentifiers:()=>fu,deduplicateFileName:()=>lu,naturalLanguageJoin:()=>du,trimPrefix:()=>pu}),hu=(...e)=>e.map(gu).join(``),gu=e=>(e.endsWith(`/`)||(e+=`/`),e.startsWith(`/`)&&(e=e.slice(1)),e),_u=e=>e.endsWith(`/`)?e.slice(0,-1):e,vu=class e{protocol;host;port;path;constructor({host:e,port:t,protocol:n=``,pathPrefix:r=``}){this.protocol=n,this.host=e,this.port=t,this.path=gu(r)}replace(t){return new e({host:t.host??this.host,port:t.port??this.port,protocol:t.protocol??this.protocol,pathPrefix:t.pathPrefix??this.path})}child(t){return new e({...this,pathPrefix:hu(this.path,t)})}toString(){return _u(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new e({host:`unknown`,port:0})},yu=class extends Zc.createTyped(`sy`){},L=class extends yu.sub(`validation`){},bu=class e extends L.sub(`path`){path;error;static encodedSchema=l.z.object({path:l.z.string().array(),error:Zc.payloadZ});constructor(e,t){let n=w.toArray(e);super(`${n.join(`.`)}: ${t.message}`),this.path=n.flatMap(e=>e.split(`.`)),this.error=t}static decode(t){let n=e.encodedSchema.parse(JSON.parse(t.data));return new e(n.path,Zc.decode(n.error))}},xu=class extends yu.sub(`auth`){},Su=class extends xu.sub(`invalid_token`){},Cu=class extends xu.sub(`expired_token`){};xu.sub(`access_denied`);var wu=class extends yu.sub(`unexpected`){constructor(e){super(`
|
|
21
16
|
Unexpected error encountered:
|
|
22
17
|
|
|
23
18
|
${e}
|
|
24
19
|
|
|
25
20
|
Please report this to the Synnax team.
|
|
26
|
-
`)}}class Ke extends Ae.sub("query"){}class en extends Ke.sub("not_found"){}class tn extends Ke.sub("multiple_results"){}class ls extends Ae.sub("route"){path;constructor(e,n){super(e),this.path=n}}class hs extends Ae.sub("control"){}class Qi extends hs.sub("unauthorized"){}class Ig extends Ae.sub("disconnected"){constructor(e="Operation failed because no Core is connected."){super(e)}}class Zg extends Ae.sub("contiguity"){}const xg=t=>t.type.startsWith(Ae.TYPE)?t.type.startsWith(W.TYPE)?t.type===Qt.TYPE?Qt.decode(t):new W(t.data):t.type.startsWith(kt.TYPE)?t.type.startsWith(cs.TYPE)?new cs(t.data):t.type.startsWith(us.TYPE)?new us(t.data):new kt(t.data):t.type.startsWith(ct.TYPE)?new ct(t.data):t.type.startsWith(Ke.TYPE)?t.type.startsWith(en.TYPE)?new en(t.data):t.type.startsWith(tn.TYPE)?new tn(t.data):new Ke(t.data):t.type.startsWith(hs.TYPE)?t.type.startsWith(Qi.TYPE)?new Qi(t.data):new hs(t.data):t.type.startsWith(ls.TYPE)?new ls(t.data,t.data):new ct(t.data):null,Cg=()=>{throw new Le.NotImplemented};Le.register({encode:Cg,decode:xg});const _g=async(t,e)=>{const[n,r]=await e(t);return r==null?[n,r]:r instanceof Je?[n,new Je({message:`Cannot reach Core at ${r.url.host}:${r.url.port}`,url:r.url})]:[n,r]},Qn=i.z.enum(["label","log","builtin","cluster","channel","node","group","range","framer","range-alias","user","workspace","schematic","lineplot","rack","device","task","policy","role","table","arc","schematic_symbol","status","view"]),Rc=i.z.string().transform(t=>{const[e,n]=t.split(":");return{type:Qn.parse(e),key:n??""}}),B=i.z.object({type:Qn,key:i.z.string()}).or(Rc),Mg={type:"builtin",key:"root"},J=t=>{const e=n=>({type:t,key:Qd.isZero(n)?"":n.toString()});return(n=>Array.isArray(n)?n.map(e):e(n))},ke=(t=>(typeof t=="string"&&(t=Rc.parse(t)),Array.isArray(t)?t.map(e=>ke(e)):`${t.type}:${t.key}`)),Rg=(t,e)=>t.type===e.type&&t.key===e.key,jc=t=>{const e=E.toArray(t);return e.length===0?[]:typeof e[0]=="object"&&"id"in e[0]?e.map(({id:n})=>n):e.map(n=>B.parse(n))},Uc=i.z.object({id:B,name:i.z.string(),data:oe.unknownZ.optional().nullable()}).transform(t=>({key:ke(t.id),...t})),jg=t=>t==="to"?"from":"to",Ug=i.z.object({from:B,type:i.z.string(),to:B}).or(i.z.string().transform(t=>{const[e,n,r]=t.split("->");return{from:B.parse(e),type:n,to:B.parse(r)}})),Pg=t=>`${ke(t.from)}->${t.type}->${ke(t.to)}`,Lg="parent",Dg=(t,e)=>!(e.type!=null&&e.type!==t.type||e.from?.type!=null&&e.from.type!==t.from.type||e.to?.type!=null&&e.to.type!==t.to.type||e.from?.key!=null&&e.from.key!==t.from.key||e.to?.key!=null&&e.to.key!==t.to.key),ea=i.z.object({id:B,children:B.array()}),Bg=i.z.object({from:B,to:B,children:B.array()}),Ir=i.z.object({});let qg=class{client;constructor(e){this.client=e}async addChildren(e,...n){await T(this.client,"/ontology/add-children",{id:e,children:n},ea,Ir)}async removeChildren(e,...n){await T(this.client,"/ontology/remove-children",{id:e,children:n},ea,Ir)}async moveChildren(e,n,...r){await T(this.client,"/ontology/move-children",{from:e,to:n,children:r},Bg,Ir)}};const Fg=i.z.object({ids:B.array().optional(),children:i.z.boolean().optional(),parents:i.z.boolean().optional(),excludeFieldData:i.z.boolean().optional(),types:Qn.array().optional(),searchTerm:i.z.string().optional(),limit:i.z.int().optional(),offset:i.z.int().optional()}),Yg=i.z.object({resources:Uc.array()});let Pc=class{type="ontology";client;writer;constructor(e){this.client=e,this.writer=new qg(e)}async retrieve(e,n){if(!Array.isArray(e)&&typeof e=="object"&&!("key"in e))return this.execRetrieve(e);const r=jc(e),s=await this.execRetrieve({ids:r,...n});if(Array.isArray(e))return s;if(s.length===0)throw new Ke(`No resource found with ID ${os.naturalLanguageJoin(r.map(a=>ke(a)))}`);return s[0]}async retrieveChildren(e,n){return await this.execRetrieve({ids:E.toArray(e),children:!0,...n})}async retrieveParents(e,n){return await this.execRetrieve({ids:E.toArray(e),parents:!0,...n})}async addChildren(e,...n){return await this.writer.addChildren(e,...n)}async removeChildren(e,...n){return await this.writer.removeChildren(e,...n)}async moveChildren(e,n,...r){return await this.writer.moveChildren(e,n,...r)}async execRetrieve(e){const{resources:n}=await T(this.client,"/ontology/retrieve",e,Fg,Yg);return n}};const Hg="sy_ontology_resource_set",Vg="sy_ontology_resource_delete",Gg="sy_ontology_relationship_set",Wg="sy_ontology_relationship_delete",Jg=Object.freeze(Object.defineProperty({__proto__:null,Client:Pc,PARENT_OF_RELATIONSHIP_TYPE:Lg,RELATIONSHIP_DELETE_CHANNEL_NAME:Wg,RELATIONSHIP_SET_CHANNEL_NAME:Gg,RESOURCE_DELETE_CHANNEL_NAME:Vg,RESOURCE_SET_CHANNEL_NAME:Hg,ROOT_ID:Mg,createIDFactory:J,idToString:ke,idZ:B,idsEqual:Rg,matchRelationship:Dg,oppositeRelationshipDirection:jg,parseIDs:jc,relationshipToString:Pg,relationshipZ:Ug,resourceTypeZ:Qn,resourceZ:Uc},Symbol.toStringTag,{value:"Module"})),xt=i.z.uuid(),Ws=i.z.object({key:xt,name:i.z.string(),objects:E.nullableZ(B),actions:E.nullableZ(Gs),internal:i.z.boolean()}),Js=i.z.object({key:xt.optional(),name:i.z.string(),objects:be.toArray(B),actions:be.toArray(Gs)}),Ks=J("policy"),Kg=Ks(""),Xg="sy_policy_set",Qg="sy_policy_delete",ew=i.z.object({keys:xt.array().optional(),subjects:B.array().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),internal:i.z.boolean().optional()}),tw=i.z.object({key:xt}).transform(({key:t})=>({keys:[t]})),nw=i.z.union([i.z.object({for:B}).transform(({for:t})=>({subjects:[t]})),i.z.object({for:B.array()}).transform(({for:t})=>({subjects:t})),ew]),rw=i.z.union([tw,nw]),sw=i.z.object({policies:E.nullableZ(Ws)}),iw=Js.transform(t=>({policies:[t]})),Lc=Js.array().transform(t=>({policies:t})),Dc=i.z.union([iw,Lc]),aw=i.z.object({policies:Ws.array()}),ow=i.z.object({keys:xt.array()}),cw=i.z.object({});let Bc=class{client;constructor(e){this.client=e}async create(e){const n=Array.isArray(e),r=await T(this.client,"/access/policy/create",e,Dc,aw);return n?r.policies:r.policies[0]}async retrieve(e){const n="key"in e,r=await T(this.client,"/access/policy/retrieve",e,rw,sw);return n?r.policies[0]:r.policies}async delete(e){await T(this.client,"/access/policy/delete",{keys:E.toArray(e)},ow,cw)}};const uw=Object.freeze(Object.defineProperty({__proto__:null,Client:Bc,DELETE_CHANNEL_NAME:Qg,SET_CHANNEL_NAME:Xg,TYPE_ONTOLOGY_ID:Kg,createArgsZ:Dc,keyZ:xt,multipleCreateArgsZ:Lc,newZ:Js,ontologyID:Ks,policyZ:Ws},Symbol.toStringTag,{value:"Module"})),Xe=i.z.uuid(),er=i.z.object({key:Xe,name:i.z.string(),description:i.z.string().optional(),internal:i.z.boolean().optional()}),Xs=er.partial({key:!0}),Qs=J("role"),lw=Qs(""),Ie=i.z.uuid(),pn=i.z.object({key:Ie,username:i.z.string().min(1,"Username is required"),firstName:i.z.string().default(""),lastName:i.z.string().default(""),rootUser:i.z.boolean().default(!1)}),qc=pn.omit({rootUser:!0}).partial({key:!0,firstName:!0,lastName:!0}).extend({password:i.z.string().min(1)}),hw=i.z.object({keys:Ie.array().optional(),usernames:i.z.string().array().optional()}),fw=i.z.object({key:Ie}).transform(({key:t})=>({keys:[t]})),dw=i.z.object({username:i.z.string()}).transform(({username:t})=>({usernames:[t]})),pw=i.z.object({usernames:i.z.string().array()}).transform(({usernames:t})=>({usernames:t})),yw=i.z.union([fw,dw,pw,hw]),mw=i.z.object({users:E.nullableZ(pn)}),gw=i.z.object({users:qc.array()}),ww=i.z.object({users:pn.array()}),bw=i.z.object({key:Ie,username:i.z.string().min(1)}),vw=i.z.object({}),zw=i.z.object({key:Ie,firstName:i.z.string().optional(),lastName:i.z.string().optional()}),Tw=i.z.object({}),Ow=i.z.object({keys:Ie.array()}),Sw=i.z.object({}),Ew="sy_user_set",Nw="sy_user_delete";let Fc=class{client;constructor(e){this.client=e}async create(e){const n=Array.isArray(e),r=await T(this.client,"/user/create",{users:E.toArray(e)},gw,ww);return n?r.users:r.users[0]}async changeUsername(e,n){await T(this.client,"/user/change-username",{key:e,username:n},bw,vw)}async retrieve(e){const n="key"in e||"username"in e,r=await T(this.client,"/user/retrieve",e,yw,mw);if(!n)return r.users;if(r.users.length===0){const s="key"in e?`key ${e.key}`:`username ${e.username}`;throw new en(`No user with ${s} found`)}if(r.users.length>1){const s="key"in e?`key ${e.key}`:`username ${e.username}`;throw new tn(`Multiple users found with ${s}`)}return r.users[0]}async rename(e,n,r){await T(this.client,"/user/rename",{key:e,firstName:n,lastName:r},zw,Tw)}async delete(e){await T(this.client,"/user/delete",{keys:E.toArray(e)},Ow,Sw)}};const Yc=J("user"),$w=Yc(""),kw=Object.freeze(Object.defineProperty({__proto__:null,Client:Fc,DELETE_CHANNEL_NAME:Nw,SET_CHANNEL_NAME:Ew,TYPE_ONTOLOGY_ID:$w,keyZ:Ie,newZ:qc,ontologyID:Yc,userZ:pn},Symbol.toStringTag,{value:"Module"})),Aw=i.z.object({keys:Xe.array().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),internal:i.z.boolean().optional()}),Iw=i.z.object({key:Xe}).transform(({key:t})=>({keys:[t]})),Zw=Xs.transform(t=>({roles:[t]})),Hc=Xs.array().transform(t=>({roles:t})),Vc=i.z.union([Zw,Hc]),xw=i.z.object({roles:er.array()}),Cw=i.z.object({roles:E.nullableZ(er)}),Gc=i.z.union([Iw,Aw]),_w=i.z.object({}),Mw=Xe.transform(t=>({keys:[t]})).or(Xe.array().transform(t=>({keys:t}))),Rw=i.z.object({user:Ie,role:Xe}),jw=i.z.object({}),Uw=i.z.object({user:Ie,role:Xe}),Pw=i.z.object({}),Lw="sy_role_set",Dw="sy_role_delete";let Wc=class{client;constructor(e){this.client=e}async create(e){const n=Array.isArray(e),r=await T(this.client,"/access/role/create",e,Vc,xw);return n?r.roles:r.roles[0]}async retrieve(e){const n="key"in e,r=await T(this.client,"/access/role/retrieve",e,Gc,Cw);return n?r.roles[0]:r.roles}async delete(e){await T(this.client,"/access/role/delete",e,Mw,_w)}async assign(e){await T(this.client,"/access/role/assign",e,Rw,jw)}async unassign(e){await T(this.client,"/access/role/unassign",e,Uw,Pw)}};const Bw=Object.freeze(Object.defineProperty({__proto__:null,Client:Wc,DELETE_CHANNEL_NAME:Dw,SET_CHANNEL_NAME:Lw,TYPE_ONTOLOGY_ID:lw,createArgsZ:Vc,keyZ:Xe,multipleCreateArgsZ:Hc,newZ:Xs,ontologyID:Qs,retrieveArgsZ:Gc,roleZ:er},Symbol.toStringTag,{value:"Module"}));let Jc=class{policies;roles;constructor(e){this.policies=new Bc(e),this.roles=new Wc(e)}};const qw=(t,e)=>{const n=E.toArray(t.objects),{action:r}=t;for(const s of n){let a=!1;for(const o of e)if(o.actions.includes(r)){for(const u of o.objects)if(u.key===""){if(u.type===s.type){a=!0;break}}else if(u.type===s.type&&u.key===s.key){a=!0;break}if(a)break}if(!a)return!1}return!0},Fw=Object.freeze(Object.defineProperty({__proto__:null,Client:Jc,actionZ:Gs,allowRequest:qw,policy:uw,role:Bw},Symbol.toStringTag,{value:"Module"}));function g(t,e,n){function r(c,u){if(c._zod||Object.defineProperty(c,"_zod",{value:{def:u,constr:o,traits:new Set},enumerable:!1}),c._zod.traits.has(t))return;c._zod.traits.add(t),e(c,u);const l=o.prototype,h=Object.keys(l);for(let d=0;d<h.length;d++){const f=h[d];f in c||(c[f]=l[f].bind(c))}}const s=n?.Parent??Object;class a extends s{}Object.defineProperty(a,"name",{value:t});function o(c){var u;const l=n?.Parent?new a:this;r(l,c),(u=l._zod).deferred??(u.deferred=[]);for(const h of l._zod.deferred)h();return l}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:c=>n?.Parent&&c instanceof n.Parent?!0:c?._zod?.traits?.has(t)}),Object.defineProperty(o,"name",{value:t}),o}class Et extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Kc extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Xc={};function ht(t){return Xc}function Qc(t){const e=Object.values(t).filter(r=>typeof r=="number");return Object.entries(t).filter(([r,s])=>e.indexOf(+r)===-1).map(([r,s])=>s)}function fs(t,e){return typeof e=="bigint"?e.toString():e}function ei(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function ti(t){return t==null}function ni(t){const e=t.startsWith("^")?1:0,n=t.endsWith("$")?t.length-1:t.length;return t.slice(e,n)}function Yw(t,e){const n=(t.toString().split(".")[1]||"").length,r=e.toString();let s=(r.split(".")[1]||"").length;if(s===0&&/\d?e-\d?/.test(r)){const u=r.match(/\d?e-(\d?)/);u?.[1]&&(s=Number.parseInt(u[1]))}const a=n>s?n:s,o=Number.parseInt(t.toFixed(a).replace(".","")),c=Number.parseInt(e.toFixed(a).replace(".",""));return o%c/10**a}const ta=Symbol("evaluating");function U(t,e,n){let r;Object.defineProperty(t,e,{get(){if(r!==ta)return r===void 0&&(r=ta,r=n()),r},set(s){Object.defineProperty(t,e,{value:s})},configurable:!0})}function yt(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0})}function et(...t){const e={};for(const n of t){const r=Object.getOwnPropertyDescriptors(n);Object.assign(e,r)}return Object.defineProperties({},e)}function na(t){return JSON.stringify(t)}function Hw(t){return t.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const eu="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function Pn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const Vw=ei(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function nn(t){if(Pn(t)===!1)return!1;const e=t.constructor;if(e===void 0||typeof e!="function")return!0;const n=e.prototype;return!(Pn(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function tu(t){return nn(t)?{...t}:Array.isArray(t)?[...t]:t}const Gw=new Set(["string","number","symbol"]);function At(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function tt(t,e,n){const r=new t._zod.constr(e??t._zod.def);return(!e||n?.parent)&&(r._zod.parent=t),r}function $(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function Ww(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const Jw={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Kw(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const a=et(t._zod.def,{get shape(){const o={};for(const c in e){if(!(c in n.shape))throw new Error(`Unrecognized key: "${c}"`);e[c]&&(o[c]=n.shape[c])}return yt(this,"shape",o),o},checks:[]});return tt(t,a)}function Xw(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const a=et(t._zod.def,{get shape(){const o={...t._zod.def.shape};for(const c in e){if(!(c in n.shape))throw new Error(`Unrecognized key: "${c}"`);e[c]&&delete o[c]}return yt(this,"shape",o),o},checks:[]});return tt(t,a)}function Qw(t,e){if(!nn(e))throw new Error("Invalid input to extend: expected a plain object");const n=t._zod.def.checks;if(n&&n.length>0){const a=t._zod.def.shape;for(const o in e)if(Object.getOwnPropertyDescriptor(a,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const s=et(t._zod.def,{get shape(){const a={...t._zod.def.shape,...e};return yt(this,"shape",a),a}});return tt(t,s)}function eb(t,e){if(!nn(e))throw new Error("Invalid input to safeExtend: expected a plain object");const n=et(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e};return yt(this,"shape",r),r}});return tt(t,n)}function tb(t,e){const n=et(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e._zod.def.shape};return yt(this,"shape",r),r},get catchall(){return e._zod.def.catchall},checks:[]});return tt(t,n)}function nb(t,e,n){const s=e._zod.def.checks;if(s&&s.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=et(e._zod.def,{get shape(){const c=e._zod.def.shape,u={...c};if(n)for(const l in n){if(!(l in c))throw new Error(`Unrecognized key: "${l}"`);n[l]&&(u[l]=t?new t({type:"optional",innerType:c[l]}):c[l])}else for(const l in c)u[l]=t?new t({type:"optional",innerType:c[l]}):c[l];return yt(this,"shape",u),u},checks:[]});return tt(e,o)}function rb(t,e,n){const r=et(e._zod.def,{get shape(){const s=e._zod.def.shape,a={...s};if(n)for(const o in n){if(!(o in a))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(a[o]=new t({type:"nonoptional",innerType:s[o]}))}else for(const o in s)a[o]=new t({type:"nonoptional",innerType:s[o]});return yt(this,"shape",a),a}});return tt(e,r)}function Ot(t,e=0){if(t.aborted===!0)return!0;for(let n=e;n<t.issues.length;n++)if(t.issues[n]?.continue!==!0)return!0;return!1}function nu(t,e){return e.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(t),n})}function Zn(t){return typeof t=="string"?t:t?.message}function ft(t,e,n){const r={...t,path:t.path??[]};if(!t.message){const s=Zn(t.inst?._zod.def?.error?.(t))??Zn(e?.error?.(t))??Zn(n.customError?.(t))??Zn(n.localeError?.(t))??"Invalid input";r.message=s}return delete r.inst,delete r.continue,e?.reportInput||delete r.input,r}function ri(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function rn(...t){const[e,n,r]=t;return typeof e=="string"?{message:e,code:"custom",input:n,inst:r}:{...e}}const ru=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,fs,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},su=g("$ZodError",ru),iu=g("$ZodError",ru,{Parent:Error});function sb(t,e=n=>n.message){const n={},r=[];for(const s of t.issues)s.path.length>0?(n[s.path[0]]=n[s.path[0]]||[],n[s.path[0]].push(e(s))):r.push(e(s));return{formErrors:r,fieldErrors:n}}function ib(t,e=n=>n.message){const n={_errors:[]},r=s=>{for(const a of s.issues)if(a.code==="invalid_union"&&a.errors.length)a.errors.map(o=>r({issues:o}));else if(a.code==="invalid_key")r({issues:a.issues});else if(a.code==="invalid_element")r({issues:a.issues});else if(a.path.length===0)n._errors.push(e(a));else{let o=n,c=0;for(;c<a.path.length;){const u=a.path[c];c===a.path.length-1?(o[u]=o[u]||{_errors:[]},o[u]._errors.push(e(a))):o[u]=o[u]||{_errors:[]},o=o[u],c++}}};return r(t),n}const si=t=>(e,n,r,s)=>{const a=r?Object.assign(r,{async:!1}):{async:!1},o=e._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new Et;if(o.issues.length){const c=new(s?.Err??t)(o.issues.map(u=>ft(u,a,ht())));throw eu(c,s?.callee),c}return o.value},ii=t=>async(e,n,r,s)=>{const a=r?Object.assign(r,{async:!0}):{async:!0};let o=e._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){const c=new(s?.Err??t)(o.issues.map(u=>ft(u,a,ht())));throw eu(c,s?.callee),c}return o.value},tr=t=>(e,n,r)=>{const s=r?{...r,async:!1}:{async:!1},a=e._zod.run({value:n,issues:[]},s);if(a instanceof Promise)throw new Et;return a.issues.length?{success:!1,error:new(t??su)(a.issues.map(o=>ft(o,s,ht())))}:{success:!0,data:a.value}},ab=tr(iu),nr=t=>async(e,n,r)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let a=e._zod.run({value:n,issues:[]},s);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new t(a.issues.map(o=>ft(o,s,ht())))}:{success:!0,data:a.value}},ob=nr(iu),cb=t=>(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return si(t)(e,n,s)},ub=t=>(e,n,r)=>si(t)(e,n,r),lb=t=>async(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ii(t)(e,n,s)},hb=t=>async(e,n,r)=>ii(t)(e,n,r),fb=t=>(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return tr(t)(e,n,s)},db=t=>(e,n,r)=>tr(t)(e,n,r),pb=t=>async(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return nr(t)(e,n,s)},yb=t=>async(e,n,r)=>nr(t)(e,n,r),mb=/^[cC][^\s-]{8,}$/,gb=/^[0-9a-z]+$/,wb=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,bb=/^[0-9a-vA-V]{20}$/,vb=/^[A-Za-z0-9]{27}$/,zb=/^[a-zA-Z0-9_-]{21}$/,Tb=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Ob=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,ra=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Sb=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Eb="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Nb(){return new RegExp(Eb,"u")}const $b=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,kb=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Ab=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Ib=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Zb=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,au=/^[A-Za-z0-9_-]*$/,xb=/^\+[1-9]\d{6,14}$/,ou="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Cb=new RegExp(`^${ou}$`);function cu(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function _b(t){return new RegExp(`^${cu(t)}$`)}function Mb(t){const e=cu({precision:t.precision}),n=["Z"];t.local&&n.push(""),t.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${e}(?:${n.join("|")})`;return new RegExp(`^${ou}T(?:${r})$`)}const Rb=t=>{const e=t?`[\\s\\S]{${t?.minimum??0},${t?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},jb=/^-?\d+$/,Ub=/^-?\d+(?:\.\d+)?$/,Pb=/^(?:true|false)$/i,Lb=/^[^A-Z]*$/,Db=/^[^a-z]*$/,ce=g("$ZodCheck",(t,e)=>{var n;t._zod??(t._zod={}),t._zod.def=e,(n=t._zod).onattach??(n.onattach=[])}),uu={number:"number",bigint:"bigint",object:"date"},lu=g("$ZodCheckLessThan",(t,e)=>{ce.init(t,e);const n=uu[typeof e.value];t._zod.onattach.push(r=>{const s=r._zod.bag,a=(e.inclusive?s.maximum:s.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<a&&(e.inclusive?s.maximum=e.value:s.exclusiveMaximum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),hu=g("$ZodCheckGreaterThan",(t,e)=>{ce.init(t,e);const n=uu[typeof e.value];t._zod.onattach.push(r=>{const s=r._zod.bag,a=(e.inclusive?s.minimum:s.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>a&&(e.inclusive?s.minimum=e.value:s.exclusiveMinimum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Bb=g("$ZodCheckMultipleOf",(t,e)=>{ce.init(t,e),t._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=e.value)}),t._zod.check=n=>{if(typeof n.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%e.value===BigInt(0):Yw(n.value,e.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:e.value,input:n.value,inst:t,continue:!e.abort})}}),qb=g("$ZodCheckNumberFormat",(t,e)=>{ce.init(t,e),e.format=e.format||"float64";const n=e.format?.includes("int"),r=n?"int":"number",[s,a]=Jw[e.format];t._zod.onattach.push(o=>{const c=o._zod.bag;c.format=e.format,c.minimum=s,c.maximum=a,n&&(c.pattern=jb)}),t._zod.check=o=>{const c=o.value;if(n){if(!Number.isInteger(c)){o.issues.push({expected:r,format:e.format,code:"invalid_type",continue:!1,input:c,inst:t});return}if(!Number.isSafeInteger(c)){c>0?o.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort}):o.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort});return}}c<s&&o.issues.push({origin:"number",input:c,code:"too_small",minimum:s,inclusive:!0,inst:t,continue:!e.abort}),c>a&&o.issues.push({origin:"number",input:c,code:"too_big",maximum:a,inclusive:!0,inst:t,continue:!e.abort})}}),Fb=g("$ZodCheckMaxLength",(t,e)=>{var n;ce.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!ti(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<s&&(r._zod.bag.maximum=e.maximum)}),t._zod.check=r=>{const s=r.value;if(s.length<=e.maximum)return;const o=ri(s);r.issues.push({origin:o,code:"too_big",maximum:e.maximum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),Yb=g("$ZodCheckMinLength",(t,e)=>{var n;ce.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!ti(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>s&&(r._zod.bag.minimum=e.minimum)}),t._zod.check=r=>{const s=r.value;if(s.length>=e.minimum)return;const o=ri(s);r.issues.push({origin:o,code:"too_small",minimum:e.minimum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),Hb=g("$ZodCheckLengthEquals",(t,e)=>{var n;ce.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!ti(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag;s.minimum=e.length,s.maximum=e.length,s.length=e.length}),t._zod.check=r=>{const s=r.value,a=s.length;if(a===e.length)return;const o=ri(s),c=a>e.length;r.issues.push({origin:o,...c?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:r.value,inst:t,continue:!e.abort})}}),rr=g("$ZodCheckStringFormat",(t,e)=>{var n,r;ce.init(t,e),t._zod.onattach.push(s=>{const a=s._zod.bag;a.format=e.format,e.pattern&&(a.patterns??(a.patterns=new Set),a.patterns.add(e.pattern))}),e.pattern?(n=t._zod).check??(n.check=s=>{e.pattern.lastIndex=0,!e.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:e.format,input:s.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(r=t._zod).check??(r.check=()=>{})}),Vb=g("$ZodCheckRegex",(t,e)=>{rr.init(t,e),t._zod.check=n=>{e.pattern.lastIndex=0,!e.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),Gb=g("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=Lb),rr.init(t,e)}),Wb=g("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=Db),rr.init(t,e)}),Jb=g("$ZodCheckIncludes",(t,e)=>{ce.init(t,e);const n=At(e.includes),r=new RegExp(typeof e.position=="number"?`^.{${e.position}}${n}`:n);e.pattern=r,t._zod.onattach.push(s=>{const a=s._zod.bag;a.patterns??(a.patterns=new Set),a.patterns.add(r)}),t._zod.check=s=>{s.value.includes(e.includes,e.position)||s.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:s.value,inst:t,continue:!e.abort})}}),Kb=g("$ZodCheckStartsWith",(t,e)=>{ce.init(t,e);const n=new RegExp(`^${At(e.prefix)}.*`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=r=>{r.value.startsWith(e.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:r.value,inst:t,continue:!e.abort})}}),Xb=g("$ZodCheckEndsWith",(t,e)=>{ce.init(t,e);const n=new RegExp(`.*${At(e.suffix)}$`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=r=>{r.value.endsWith(e.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:r.value,inst:t,continue:!e.abort})}}),Qb=g("$ZodCheckOverwrite",(t,e)=>{ce.init(t,e),t._zod.check=n=>{n.value=e.tx(n.value)}});class ev{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const r=e.split(`
|
|
27
|
-
`).filter(
|
|
28
|
-
`))}}
|
|
29
|
-
if (${
|
|
30
|
-
if (${
|
|
31
|
-
payload.issues = payload.issues.concat(${
|
|
21
|
+
`)}},Tu=class extends yu.sub(`query`){},Eu=class extends Tu.sub(`not_found`){},Du=class extends Tu.sub(`multiple_results`){},Ou=class extends yu.sub(`route`){path;constructor(e,t){super(e),this.path=t}},ku=class extends yu.sub(`control`){},Au=class extends ku.sub(`unauthorized`){},ju=class extends yu.sub(`disconnected`){constructor(e=`Operation failed because no Core is connected.`){super(e)}},Mu=class extends yu.sub(`contiguity`){};Zc.register({encode:()=>{throw new Zc.NotImplemented},decode:e=>e.type.startsWith(yu.TYPE)?e.type.startsWith(L.TYPE)?e.type===bu.TYPE?bu.decode(e):new L(e.data):e.type.startsWith(xu.TYPE)?e.type.startsWith(Su.TYPE)?new Su(e.data):e.type.startsWith(Cu.TYPE)?new Cu(e.data):new xu(e.data):e.type.startsWith(wu.TYPE)?new wu(e.data):e.type.startsWith(Tu.TYPE)?e.type.startsWith(Eu.TYPE)?new Eu(e.data):e.type.startsWith(Du.TYPE)?new Du(e.data):new Tu(e.data):e.type.startsWith(ku.TYPE)?e.type.startsWith(Au.TYPE)?new Au(e.data):new ku(e.data):e.type.startsWith(Ou.TYPE)?new Ou(e.data,e.data):new wu(e.data):null});var Nu=async(e,t)=>{let[n,r]=await t(e);return r==null?[n,r]:r instanceof Sr?[n,new Sr({message:`Cannot reach Core at ${r.url.host}:${r.url.port}`,url:r.url})]:[n,r]},Pu=[`arc`,`builtin`,`channel`,`cluster`,`device`,`framer`,`group`,`label`,`lineplot`,`log`,`node`,`policy`,`rack`,`range`,`range-alias`,`role`,`schematic`,`schematic_symbol`,`status`,`table`,`task`,`user`,`view`,`workspace`],Fu=l.z.enum(Pu),Iu=l.z.string().transform(e=>{let[t,n]=e.split(`:`);return{type:Fu.parse(t),key:n??``}}),R=l.z.object({type:Fu,key:l.z.string()}).or(Iu),Lu={type:`builtin`,key:`root`},z=e=>{let t=t=>({type:e,key:pi.isZero(t)?``:t.toString()});return(e=>Array.isArray(e)?e.map(t):t(e))},Ru=(e=>(typeof e==`string`&&(e=Iu.parse(e)),Array.isArray(e)?e.map(e=>Ru(e)):`${e.type}:${e.key}`)),zu=(e,t)=>e.type===t.type&&e.key===t.key,Bu=e=>{let t=w.toArray(e);return t.length===0?[]:typeof t[0]==`object`&&`id`in t[0]?t.map(({id:e})=>e):t.map(e=>R.parse(e))},Vu=l.z.object({id:R,name:l.z.string(),data:I.unknownZ().optional().nullable()}).transform(e=>({key:Ru(e.id),...e})),Hu=e=>e===`to`?`from`:`to`,Uu=l.z.object({from:R,type:l.z.string(),to:R}).or(l.z.string().transform(e=>{let[t,n,r]=e.split(`->`);return{from:R.parse(t),type:n,to:R.parse(r)}})),Wu=e=>`${Ru(e.from)}->${e.type}->${Ru(e.to)}`,Gu=`parent`,Ku=(e,t)=>!(t.type!=null&&t.type!==e.type||t.from?.type!=null&&t.from.type!==e.from.type||t.to?.type!=null&&t.to.type!==e.to.type||t.from?.key!=null&&t.from.key!==e.from.key||t.to?.key!=null&&t.to.key!==e.to.key),qu=l.z.object({id:R,children:R.array()}),Ju=l.z.object({from:R,to:R,children:R.array()}),Yu=l.z.object({}),Xu=class{client;constructor(e){this.client=e}async addChildren(e,...t){await S(this.client,`/ontology/add-children`,{id:e,children:t},qu,Yu)}async removeChildren(e,...t){await S(this.client,`/ontology/remove-children`,{id:e,children:t},qu,Yu)}async moveChildren(e,t,...n){await S(this.client,`/ontology/move-children`,{from:e,to:t,children:n},Ju,Yu)}},Zu=l.z.object({ids:R.array().optional(),children:l.z.boolean().optional(),parents:l.z.boolean().optional(),excludeFieldData:l.z.boolean().optional(),types:Fu.array().optional(),searchTerm:l.z.string().optional(),limit:l.z.int().optional(),offset:l.z.int().optional()}),Qu=l.z.object({resources:Vu.array()}),$u=class{type=`ontology`;client;writer;constructor(e){this.client=e,this.writer=new Xu(e)}async retrieve(e,t){if(!Array.isArray(e)&&typeof e==`object`&&!(`key`in e))return this.execRetrieve(e);let n=Bu(e),r=await this.execRetrieve({ids:n,...t});if(Array.isArray(e))return r;if(r.length===0)throw new Tu(`No resource found with ID ${mu.naturalLanguageJoin(n.map(e=>Ru(e)))}`);return r[0]}async retrieveChildren(e,t){return await this.execRetrieve({ids:w.toArray(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:w.toArray(e),parents:!0,...t})}async addChildren(e,...t){return await this.writer.addChildren(e,...t)}async removeChildren(e,...t){return await this.writer.removeChildren(e,...t)}async moveChildren(e,t,...n){return await this.writer.moveChildren(e,t,...n)}async execRetrieve(e){let{resources:t}=await S(this.client,`/ontology/retrieve`,e,Zu,Qu);return t}},ed=`sy_ontology_resource_set`,td=`sy_ontology_resource_delete`,nd=`sy_ontology_relationship_set`,rd=`sy_ontology_relationship_delete`,id=o({Client:()=>$u,PARENT_OF_RELATIONSHIP_TYPE:()=>Gu,RELATIONSHIP_DELETE_CHANNEL_NAME:()=>rd,RELATIONSHIP_SET_CHANNEL_NAME:()=>nd,RESOURCE_DELETE_CHANNEL_NAME:()=>td,RESOURCE_SET_CHANNEL_NAME:()=>ed,RESOURCE_TYPES:()=>Pu,ROOT_ID:()=>Lu,createIDFactory:()=>z,idToString:()=>Ru,idZ:()=>R,idsEqual:()=>zu,matchRelationship:()=>Ku,oppositeRelationshipDirection:()=>Hu,parseIDs:()=>Bu,relationshipToString:()=>Wu,relationshipZ:()=>Uu,resourceTypeZ:()=>Fu,resourceZ:()=>Vu}),ad=l.z.uuid(),od=l.z.object({key:ad,name:l.z.string(),objects:w.nullishToEmpty(R),actions:w.nullishToEmpty(d),internal:l.z.boolean().default(!1).optional()}),sd=od.partial({key:!0}),cd=z(`policy`),ld=cd(``),ud=`sy_policy_set`,dd=`sy_policy_delete`,fd=l.z.object({keys:ad.array().optional(),subjects:R.array().optional(),limit:l.z.number().optional(),offset:l.z.number().optional(),internal:l.z.boolean().optional()}),pd=l.z.object({key:ad}).transform(({key:e})=>({keys:[e]})),md=l.z.union([l.z.object({for:R}).transform(({for:e})=>({subjects:[e]})),l.z.object({for:R.array()}).transform(({for:e})=>({subjects:e})),fd]),hd=l.z.union([pd,md]),gd=l.z.object({policies:w.nullishToEmpty(od)}),_d=sd.transform(e=>({policies:[e]})),vd=sd.array().transform(e=>({policies:e})),yd=l.z.union([_d,vd]),bd=l.z.object({policies:od.array()}),xd=l.z.object({keys:ad.array()}),Sd=l.z.object({}),Cd=class{client;constructor(e){this.client=e}async create(e){let t=Array.isArray(e),n=await S(this.client,`/access/policy/create`,e,yd,bd);return t?n.policies:n.policies[0]}async retrieve(e){let t=`key`in e,n=await S(this.client,`/access/policy/retrieve`,e,hd,gd);return t?n.policies[0]:n.policies}async delete(e){await S(this.client,`/access/policy/delete`,{keys:w.toArray(e)},xd,Sd)}},wd=o({Client:()=>Cd,DELETE_CHANNEL_NAME:()=>dd,SET_CHANNEL_NAME:()=>ud,TYPE_ONTOLOGY_ID:()=>ld,createArgsZ:()=>yd,keyZ:()=>ad,multipleCreateArgsZ:()=>vd,newZ:()=>sd,ontologyID:()=>cd,policyZ:()=>od}),Td=l.z.uuid(),Ed=l.z.object({key:Td,name:l.z.string(),description:l.z.string().optional(),internal:l.z.boolean().optional()}),Dd=Ed.partial({key:!0}),Od=z(`role`),kd=Od(``),Ad=l.z.uuid(),jd=l.z.object({key:Ad,username:l.z.string().min(1,`Username is required`),firstName:l.z.string(),lastName:l.z.string(),rootUser:l.z.boolean().default(!1)}),Md=jd.omit({rootUser:!0}).partial({key:!0,firstName:!0,lastName:!0}).extend({password:l.z.string().min(1)});z(`user`)(``);var Nd=l.z.object({keys:Ad.array().optional(),usernames:l.z.string().array().optional()}),Pd=l.z.object({key:Ad}).transform(({key:e})=>({keys:[e]})),Fd=l.z.object({username:l.z.string()}).transform(({username:e})=>({usernames:[e]})),Id=l.z.object({usernames:l.z.string().array()}).transform(({usernames:e})=>({usernames:e})),Ld=l.z.union([Pd,Fd,Id,Nd]),Rd=l.z.object({users:w.nullishToEmpty(jd)}),zd=l.z.object({users:Md.array()}),Bd=l.z.object({users:jd.array()}),Vd=l.z.object({key:Ad,username:l.z.string().min(1)}),Hd=l.z.object({}),Ud=l.z.object({key:Ad,firstName:l.z.string().optional(),lastName:l.z.string().optional()}),Wd=l.z.object({}),Gd=l.z.object({keys:Ad.array()}),Kd=l.z.object({}),qd=`sy_user_set`,Jd=`sy_user_delete`,Yd=class{client;constructor(e){this.client=e}async create(e){let t=Array.isArray(e),n=await S(this.client,`/user/create`,{users:w.toArray(e)},zd,Bd);return t?n.users:n.users[0]}async changeUsername(e,t){await S(this.client,`/user/change-username`,{key:e,username:t},Vd,Hd)}async retrieve(e){let t=`key`in e||`username`in e,n=await S(this.client,`/user/retrieve`,e,Ld,Rd);if(!t)return n.users;if(n.users.length===0)throw new Eu(`No user with ${`key`in e?`key ${e.key}`:`username ${e.username}`} found`);if(n.users.length>1)throw new Du(`Multiple users found with ${`key`in e?`key ${e.key}`:`username ${e.username}`}`);return n.users[0]}async rename(e,t,n){await S(this.client,`/user/rename`,{key:e,firstName:t,lastName:n},Ud,Wd)}async delete(e){await S(this.client,`/user/delete`,{keys:w.toArray(e)},Gd,Kd)}},Xd=z(`user`),Zd=Xd(``),Qd=o({Client:()=>Yd,DELETE_CHANNEL_NAME:()=>Jd,SET_CHANNEL_NAME:()=>qd,TYPE_ONTOLOGY_ID:()=>Zd,keyZ:()=>Ad,newZ:()=>Md,ontologyID:()=>Xd,userZ:()=>jd}),$d=l.z.object({keys:Td.array().optional(),limit:l.z.number().optional(),offset:l.z.number().optional(),internal:l.z.boolean().optional()}),ef=l.z.object({key:Td}).transform(({key:e})=>({keys:[e]})),tf=Dd.transform(e=>({roles:[e]})),nf=Dd.array().transform(e=>({roles:e})),rf=l.z.union([tf,nf]),af=l.z.object({roles:Ed.array()}),of=l.z.object({roles:w.nullishToEmpty(Ed)}),sf=l.z.union([ef,$d]),cf=l.z.object({}),lf=Td.transform(e=>({keys:[e]})).or(Td.array().transform(e=>({keys:e}))),uf=l.z.object({user:Ad,role:Td}),df=l.z.object({}),ff=l.z.object({user:Ad,role:Td}),pf=l.z.object({}),mf=`sy_role_set`,hf=`sy_role_delete`,gf=class{client;constructor(e){this.client=e}async create(e){let t=Array.isArray(e),n=await S(this.client,`/access/role/create`,e,rf,af);return t?n.roles:n.roles[0]}async retrieve(e){let t=`key`in e,n=await S(this.client,`/access/role/retrieve`,e,sf,of);return t?n.roles[0]:n.roles}async delete(e){await S(this.client,`/access/role/delete`,e,lf,cf)}async assign(e){await S(this.client,`/access/role/assign`,e,uf,df)}async unassign(e){await S(this.client,`/access/role/unassign`,e,ff,pf)}},_f=o({Client:()=>gf,DELETE_CHANNEL_NAME:()=>hf,SET_CHANNEL_NAME:()=>mf,TYPE_ONTOLOGY_ID:()=>kd,createArgsZ:()=>rf,keyZ:()=>Td,multipleCreateArgsZ:()=>nf,newZ:()=>Dd,ontologyID:()=>Od,retrieveArgsZ:()=>sf,roleZ:()=>Ed}),vf=class{policies;roles;constructor(e){this.policies=new Cd(e),this.roles=new gf(e)}},yf=(e,t)=>{let n=w.toArray(e.objects),{action:r}=e;for(let e of n){let n=!1;for(let i of t)if(i.actions.includes(r)){for(let t of i.objects)if(t.key===``){if(t.type===e.type){n=!0;break}}else if(t.type===e.type&&t.key===e.key){n=!0;break}if(n)break}if(!n)return!1}return!0},bf=o({ACTIONS:()=>u,Client:()=>vf,actionZ:()=>d,allowRequest:()=>yf,policy:()=>wd,role:()=>_f});Object.freeze({status:`aborted`});function B(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,`_zod`,{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,`name`,{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,`init`,{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,`name`,{value:e}),o}var xf=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Sf=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}},Cf={};function wf(e){return e&&Object.assign(Cf,e),Cf}function Tf(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function Ef(e,t){return typeof t==`bigint`?t.toString():t}function Df(e){return{get value(){{let t=e();return Object.defineProperty(this,`value`,{value:t}),t}throw Error(`cached value already set`)}}}function Of(e){return e==null}function kf(e){let t=e.startsWith(`^`)?1:0,n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function Af(e,t){let n=(e.toString().split(`.`)[1]||``).length,r=t.toString(),i=(r.split(`.`)[1]||``).length;if(i===0&&/\d?e-\d?/.test(r)){let e=r.match(/\d?e-(\d?)/);e?.[1]&&(i=Number.parseInt(e[1]))}let a=n>i?n:i;return Number.parseInt(e.toFixed(a).replace(`.`,``))%Number.parseInt(t.toFixed(a).replace(`.`,``))/10**a}var jf=Symbol(`evaluating`);function V(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==jf)return r===void 0&&(r=jf,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function Mf(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Nf(...e){let t={};for(let n of e)Object.assign(t,Object.getOwnPropertyDescriptors(n));return Object.defineProperties({},t)}function Pf(e){return JSON.stringify(e)}function Ff(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}var If=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function Lf(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Rf=Df(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function zf(e){if(Lf(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return!(Lf(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}function Bf(e){return zf(e)?{...e}:Array.isArray(e)?[...e]:e}var Vf=new Set([`string`,`number`,`symbol`]);function Hf(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Uf(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function H(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function Wf(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}var Gf={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Kf(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return Uf(e,Nf(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return Mf(this,`shape`,e),e},checks:[]}))}function qf(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return Uf(e,Nf(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return Mf(this,`shape`,r),r},checks:[]}))}function Jf(e,t){if(!zf(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return Uf(e,Nf(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return Mf(this,`shape`,n),n}}))}function Yf(e,t){if(!zf(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return Uf(e,Nf(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return Mf(this,`shape`,n),n}}))}function Xf(e,t){return Uf(e,Nf(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return Mf(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:[]}))}function Zf(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return Uf(t,Nf(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return Mf(this,`shape`,i),i},checks:[]}))}function Qf(e,t,n){return Uf(t,Nf(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return Mf(this,`shape`,i),i}}))}function $f(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function ep(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function tp(e){return typeof e==`string`?e:e?.message}function np(e,t,n){let r={...e,path:e.path??[]};return e.message||(r.message=tp(e.inst?._zod.def?.error?.(e))??tp(t?.error?.(e))??tp(n.customError?.(e))??tp(n.localeError?.(e))??`Invalid input`),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function rp(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function ip(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}var ap=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,`_zod`,{value:e._zod,enumerable:!1}),Object.defineProperty(e,`issues`,{value:t,enumerable:!1}),e.message=JSON.stringify(t,Ef,2),Object.defineProperty(e,`toString`,{value:()=>e.message,enumerable:!1})},op=B(`$ZodError`,ap),sp=B(`$ZodError`,ap,{Parent:Error});function cp(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function lp(e,t=e=>e.message){let n={_errors:[]},r=e=>{for(let i of e.issues)if(i.code===`invalid_union`&&i.errors.length)i.errors.map(e=>r({issues:e}));else if(i.code===`invalid_key`)r({issues:i.issues});else if(i.code===`invalid_element`)r({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let e=n,r=0;for(;r<i.path.length;){let n=i.path[r];r===i.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(i))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(e),n}var up=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new xf;if(o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>np(e,a,wf())));throw If(t,i?.callee),t}return o.value},dp=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>np(e,a,wf())));throw If(t,i?.callee),t}return o.value},fp=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new xf;return a.issues.length?{success:!1,error:new(e??op)(a.issues.map(e=>np(e,i,wf())))}:{success:!0,data:a.value}},pp=fp(sp),mp=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>np(e,i,wf())))}:{success:!0,data:a.value}},hp=mp(sp),gp=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return up(e)(t,n,i)},_p=e=>(t,n,r)=>up(e)(t,n,r),vp=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return dp(e)(t,n,i)},yp=e=>async(t,n,r)=>dp(e)(t,n,r),bp=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return fp(e)(t,n,i)},xp=e=>(t,n,r)=>fp(e)(t,n,r),Sp=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return mp(e)(t,n,i)},Cp=e=>async(t,n,r)=>mp(e)(t,n,r),wp=/^[cC][^\s-]{8,}$/,Tp=/^[0-9a-z]+$/,Ep=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Dp=/^[0-9a-vA-V]{20}$/,Op=/^[A-Za-z0-9]{27}$/,kp=/^[a-zA-Z0-9_-]{21}$/,Ap=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,jp=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Mp=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Np=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Pp=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function Fp(){return new RegExp(Pp,`u`)}var Ip=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Lp=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Rp=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,zp=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Bp=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Vp=/^[A-Za-z0-9_-]*$/,Hp=/^\+[1-9]\d{6,14}$/,Up=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,Wp=RegExp(`^${Up}$`);function Gp(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Kp(e){return RegExp(`^${Gp(e)}$`)}function qp(e){let t=Gp({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Up}T(?:${r})$`)}var Jp=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Yp=/^-?\d+$/,Xp=/^-?\d+(?:\.\d+)?$/,Zp=/^(?:true|false)$/i,Qp=/^[^A-Z]*$/,$p=/^[^a-z]*$/,U=B(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),em={number:`number`,bigint:`bigint`,object:`date`},tm=B(`$ZodCheckLessThan`,(e,t)=>{U.init(e,t);let n=em[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),nm=B(`$ZodCheckGreaterThan`,(e,t)=>{U.init(e,t);let n=em[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),rm=B(`$ZodCheckMultipleOf`,(e,t)=>{U.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):Af(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),im=B(`$ZodCheckNumberFormat`,(e,t)=>{U.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=Gf[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Yp)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),am=B(`$ZodCheckMaxLength`,(e,t)=>{var n;U.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Of(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=rp(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),om=B(`$ZodCheckMinLength`,(e,t)=>{var n;U.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Of(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=rp(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),sm=B(`$ZodCheckLengthEquals`,(e,t)=>{var n;U.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Of(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=rp(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),cm=B(`$ZodCheckStringFormat`,(e,t)=>{var n,r;U.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),lm=B(`$ZodCheckRegex`,(e,t)=>{cm.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),um=B(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Qp,cm.init(e,t)}),dm=B(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=$p,cm.init(e,t)}),fm=B(`$ZodCheckIncludes`,(e,t)=>{U.init(e,t);let n=Hf(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),pm=B(`$ZodCheckStartsWith`,(e,t)=>{U.init(e,t);let n=RegExp(`^${Hf(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),mm=B(`$ZodCheckEndsWith`,(e,t)=>{U.init(e,t);let n=RegExp(`.*${Hf(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),hm=B(`$ZodCheckOverwrite`,(e,t)=>{U.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}}),gm=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
22
|
+
`).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.args,n=[...(this?.content??[``]).map(e=>` ${e}`)];return new e(...t,n.join(`
|
|
23
|
+
`))}},_m={major:4,minor:3,patch:6},W=B(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=_m;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=$f(e),i;for(let a of t){if(a._zod.def.when){if(!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new xf;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=$f(e,t))});else{if(e.issues.length===t)continue;r||=$f(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if($f(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new xf;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new xf;return o.then(e=>t(e,r,a))}return t(o,r,a)}}V(e,`~standard`,()=>({validate:t=>{try{let n=pp(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return hp(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),vm=B(`$ZodString`,(e,t)=>{W.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Jp(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),G=B(`$ZodStringFormat`,(e,t)=>{cm.init(e,t),vm.init(e,t)}),ym=B(`$ZodGUID`,(e,t)=>{t.pattern??=jp,G.init(e,t)}),bm=B(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=Mp(e)}else t.pattern??=Mp();G.init(e,t)}),xm=B(`$ZodEmail`,(e,t)=>{t.pattern??=Np,G.init(e,t)}),Sm=B(`$ZodURL`,(e,t)=>{G.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),Cm=B(`$ZodEmoji`,(e,t)=>{t.pattern??=Fp(),G.init(e,t)}),wm=B(`$ZodNanoID`,(e,t)=>{t.pattern??=kp,G.init(e,t)}),Tm=B(`$ZodCUID`,(e,t)=>{t.pattern??=wp,G.init(e,t)}),Em=B(`$ZodCUID2`,(e,t)=>{t.pattern??=Tp,G.init(e,t)}),Dm=B(`$ZodULID`,(e,t)=>{t.pattern??=Ep,G.init(e,t)}),Om=B(`$ZodXID`,(e,t)=>{t.pattern??=Dp,G.init(e,t)}),km=B(`$ZodKSUID`,(e,t)=>{t.pattern??=Op,G.init(e,t)}),Am=B(`$ZodISODateTime`,(e,t)=>{t.pattern??=qp(t),G.init(e,t)}),jm=B(`$ZodISODate`,(e,t)=>{t.pattern??=Wp,G.init(e,t)}),Mm=B(`$ZodISOTime`,(e,t)=>{t.pattern??=Kp(t),G.init(e,t)}),Nm=B(`$ZodISODuration`,(e,t)=>{t.pattern??=Ap,G.init(e,t)}),Pm=B(`$ZodIPv4`,(e,t)=>{t.pattern??=Ip,G.init(e,t),e._zod.bag.format=`ipv4`}),Fm=B(`$ZodIPv6`,(e,t)=>{t.pattern??=Lp,G.init(e,t),e._zod.bag.format=`ipv6`,e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),Im=B(`$ZodCIDRv4`,(e,t)=>{t.pattern??=Rp,G.init(e,t)}),Lm=B(`$ZodCIDRv6`,(e,t)=>{t.pattern??=zp,G.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function Rm(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}var zm=B(`$ZodBase64`,(e,t)=>{t.pattern??=Bp,G.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{Rm(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function Bm(e){if(!Vp.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Rm(t.padEnd(Math.ceil(t.length/4)*4,`=`))}var Vm=B(`$ZodBase64URL`,(e,t)=>{t.pattern??=Vp,G.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{Bm(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Hm=B(`$ZodE164`,(e,t)=>{t.pattern??=Hp,G.init(e,t)});function Um(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}var Wm=B(`$ZodJWT`,(e,t)=>{G.init(e,t),e._zod.check=n=>{Um(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Gm=B(`$ZodNumber`,(e,t)=>{W.init(e,t),e._zod.pattern=e._zod.bag.pattern??Xp,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),Km=B(`$ZodNumberFormat`,(e,t)=>{im.init(e,t),Gm.init(e,t)}),qm=B(`$ZodBoolean`,(e,t)=>{W.init(e,t),e._zod.pattern=Zp,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),Jm=B(`$ZodUnknown`,(e,t)=>{W.init(e,t),e._zod.parse=e=>e}),Ym=B(`$ZodNever`,(e,t)=>{W.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Xm(e,t,n){e.issues.length&&t.issues.push(...ep(n,e.issues)),t.value[n]=e.value}var Zm=B(`$ZodArray`,(e,t)=>{W.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>Xm(t,n,e))):Xm(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function Qm(e,t,n,r,i){if(e.issues.length){if(i&&!(n in r))return;t.issues.push(...ep(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function $m(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=Wf(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function eh(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optout===`optional`;for(let i in t){if(s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>Qm(e,n,i,t,u))):Qm(a,n,i,t,u)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}var th=B(`$ZodObject`,(e,t)=>{if(W.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,`shape`,{get:()=>{let n={...e};return Object.defineProperty(t,`shape`,{value:n}),n}})}let n=Df(()=>$m(t));V(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=Lf,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optout===`optional`,i=n._zod.run({value:s[e],issues:[]},o);i instanceof Promise?c.push(i.then(n=>Qm(n,t,e,s,r))):Qm(i,t,e,s,r)}return i?eh(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),nh=B(`$ZodObjectJIT`,(e,t)=>{th.init(e,t);let n=e._zod.parse,r=Df(()=>$m(t)),i=e=>{let t=new gm([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=Pf(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=Pf(r),s=e[r]?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),s?t.write(`
|
|
24
|
+
if (${n}.issues.length) {
|
|
25
|
+
if (${o} in input) {
|
|
26
|
+
payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
32
27
|
...iss,
|
|
33
|
-
path: iss.path ? [${
|
|
28
|
+
path: iss.path ? [${o}, ...iss.path] : [${o}]
|
|
34
29
|
})));
|
|
35
30
|
}
|
|
36
31
|
}
|
|
37
32
|
|
|
38
|
-
if (${
|
|
39
|
-
if (${
|
|
40
|
-
newResult[${
|
|
33
|
+
if (${n}.value === undefined) {
|
|
34
|
+
if (${o} in input) {
|
|
35
|
+
newResult[${o}] = undefined;
|
|
41
36
|
}
|
|
42
37
|
} else {
|
|
43
|
-
newResult[${
|
|
38
|
+
newResult[${o}] = ${n}.value;
|
|
44
39
|
}
|
|
45
40
|
|
|
46
|
-
`):
|
|
47
|
-
if (${
|
|
48
|
-
payload.issues = payload.issues.concat(${
|
|
41
|
+
`):t.write(`
|
|
42
|
+
if (${n}.issues.length) {
|
|
43
|
+
payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
49
44
|
...iss,
|
|
50
|
-
path: iss.path ? [${
|
|
45
|
+
path: iss.path ? [${o}, ...iss.path] : [${o}]
|
|
51
46
|
})));
|
|
52
47
|
}
|
|
53
48
|
|
|
54
|
-
if (${
|
|
55
|
-
if (${
|
|
56
|
-
newResult[${
|
|
49
|
+
if (${n}.value === undefined) {
|
|
50
|
+
if (${o} in input) {
|
|
51
|
+
newResult[${o}] = undefined;
|
|
57
52
|
}
|
|
58
53
|
} else {
|
|
59
|
-
newResult[${
|
|
54
|
+
newResult[${o}] = ${n}.value;
|
|
60
55
|
}
|
|
61
56
|
|
|
62
|
-
`)}b.write("payload.value = newResult;"),b.write("return payload;");const A=b.compile();return(D,C)=>A(f,D,C)};let a;const o=Pn,c=!Xc.jitless,l=c&&Vw.value,h=e.catchall;let d;t._zod.parse=(f,b)=>{d??(d=r.value);const N=f.value;return o(N)?c&&l&&b?.async===!1&&b.jitless!==!0?(a||(a=s(e.shape)),f=a(f,b),h?yu([],N,f,b,d,t):f):n(f,b):(f.issues.push({expected:"object",code:"invalid_type",input:N,inst:t}),f)}});function ia(t,e,n,r){for(const a of t)if(a.issues.length===0)return e.value=a.value,e;const s=t.filter(a=>!Ot(a));return s.length===1?(e.value=s[0].value,s[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:n,errors:t.map(a=>a.issues.map(o=>ft(o,r,ht())))}),e)}const _v=g("$ZodUnion",(t,e)=>{Y.init(t,e),U(t._zod,"optin",()=>e.options.some(s=>s._zod.optin==="optional")?"optional":void 0),U(t._zod,"optout",()=>e.options.some(s=>s._zod.optout==="optional")?"optional":void 0),U(t._zod,"values",()=>{if(e.options.every(s=>s._zod.values))return new Set(e.options.flatMap(s=>Array.from(s._zod.values)))}),U(t._zod,"pattern",()=>{if(e.options.every(s=>s._zod.pattern)){const s=e.options.map(a=>a._zod.pattern);return new RegExp(`^(${s.map(a=>ni(a.source)).join("|")})$`)}});const n=e.options.length===1,r=e.options[0]._zod.run;t._zod.parse=(s,a)=>{if(n)return r(s,a);let o=!1;const c=[];for(const u of e.options){const l=u._zod.run({value:s.value,issues:[]},a);if(l instanceof Promise)c.push(l),o=!0;else{if(l.issues.length===0)return l;c.push(l)}}return o?Promise.all(c).then(u=>ia(u,s,t,a)):ia(c,s,t,a)}}),Mv=g("$ZodIntersection",(t,e)=>{Y.init(t,e),t._zod.parse=(n,r)=>{const s=n.value,a=e.left._zod.run({value:s,issues:[]},r),o=e.right._zod.run({value:s,issues:[]},r);return a instanceof Promise||o instanceof Promise?Promise.all([a,o]).then(([u,l])=>aa(n,u,l)):aa(n,a,o)}});function ds(t,e){if(t===e)return{valid:!0,data:t};if(t instanceof Date&&e instanceof Date&&+t==+e)return{valid:!0,data:t};if(nn(t)&&nn(e)){const n=Object.keys(e),r=Object.keys(t).filter(a=>n.indexOf(a)!==-1),s={...t,...e};for(const a of r){const o=ds(t[a],e[a]);if(!o.valid)return{valid:!1,mergeErrorPath:[a,...o.mergeErrorPath]};s[a]=o.data}return{valid:!0,data:s}}if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<t.length;r++){const s=t[r],a=e[r],o=ds(s,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function aa(t,e,n){const r=new Map;let s;for(const c of e.issues)if(c.code==="unrecognized_keys"){s??(s=c);for(const u of c.keys)r.has(u)||r.set(u,{}),r.get(u).l=!0}else t.issues.push(c);for(const c of n.issues)if(c.code==="unrecognized_keys")for(const u of c.keys)r.has(u)||r.set(u,{}),r.get(u).r=!0;else t.issues.push(c);const a=[...r].filter(([,c])=>c.l&&c.r).map(([c])=>c);if(a.length&&s&&t.issues.push({...s,keys:a}),Ot(t))return t;const o=ds(e.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return t.value=o.data,t}const Rv=g("$ZodEnum",(t,e)=>{Y.init(t,e);const n=Qc(e.entries),r=new Set(n);t._zod.values=r,t._zod.pattern=new RegExp(`^(${n.filter(s=>Gw.has(typeof s)).map(s=>typeof s=="string"?At(s):s.toString()).join("|")})$`),t._zod.parse=(s,a)=>{const o=s.value;return r.has(o)||s.issues.push({code:"invalid_value",values:n,input:o,inst:t}),s}}),jv=g("$ZodLiteral",(t,e)=>{if(Y.init(t,e),e.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(e.values);t._zod.values=n,t._zod.pattern=new RegExp(`^(${e.values.map(r=>typeof r=="string"?At(r):r?At(r.toString()):String(r)).join("|")})$`),t._zod.parse=(r,s)=>{const a=r.value;return n.has(a)||r.issues.push({code:"invalid_value",values:e.values,input:a,inst:t}),r}}),Uv=g("$ZodTransform",(t,e)=>{Y.init(t,e),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Kc(t.constructor.name);const s=e.transform(n.value,n);if(r.async)return(s instanceof Promise?s:Promise.resolve(s)).then(o=>(n.value=o,n));if(s instanceof Promise)throw new Et;return n.value=s,n}});function oa(t,e){return t.issues.length&&e===void 0?{issues:[],value:void 0}:t}const mu=g("$ZodOptional",(t,e)=>{Y.init(t,e),t._zod.optin="optional",t._zod.optout="optional",U(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),U(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${ni(n.source)})?$`):void 0}),t._zod.parse=(n,r)=>{if(e.innerType._zod.optin==="optional"){const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(a=>oa(a,n.value)):oa(s,n.value)}return n.value===void 0?n:e.innerType._zod.run(n,r)}}),Pv=g("$ZodExactOptional",(t,e)=>{mu.init(t,e),U(t._zod,"values",()=>e.innerType._zod.values),U(t._zod,"pattern",()=>e.innerType._zod.pattern),t._zod.parse=(n,r)=>e.innerType._zod.run(n,r)}),Lv=g("$ZodNullable",(t,e)=>{Y.init(t,e),U(t._zod,"optin",()=>e.innerType._zod.optin),U(t._zod,"optout",()=>e.innerType._zod.optout),U(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${ni(n.source)}|null)$`):void 0}),U(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(n,r)=>n.value===null?n:e.innerType._zod.run(n,r)}),Dv=g("$ZodDefault",(t,e)=>{Y.init(t,e),t._zod.optin="optional",U(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);if(n.value===void 0)return n.value=e.defaultValue,n;const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(a=>ca(a,e)):ca(s,e)}});function ca(t,e){return t.value===void 0&&(t.value=e.defaultValue),t}const Bv=g("$ZodPrefault",(t,e)=>{Y.init(t,e),t._zod.optin="optional",U(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=e.defaultValue),e.innerType._zod.run(n,r))}),qv=g("$ZodNonOptional",(t,e)=>{Y.init(t,e),U(t._zod,"values",()=>{const n=e.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),t._zod.parse=(n,r)=>{const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(a=>ua(a,t)):ua(s,t)}});function ua(t,e){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:e}),t}const Fv=g("$ZodCatch",(t,e)=>{Y.init(t,e),U(t._zod,"optin",()=>e.innerType._zod.optin),U(t._zod,"optout",()=>e.innerType._zod.optout),U(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(a=>(n.value=a.value,a.issues.length&&(n.value=e.catchValue({...n,error:{issues:a.issues.map(o=>ft(o,r,ht()))},input:n.value}),n.issues=[]),n)):(n.value=s.value,s.issues.length&&(n.value=e.catchValue({...n,error:{issues:s.issues.map(a=>ft(a,r,ht()))},input:n.value}),n.issues=[]),n)}}),Yv=g("$ZodPipe",(t,e)=>{Y.init(t,e),U(t._zod,"values",()=>e.in._zod.values),U(t._zod,"optin",()=>e.in._zod.optin),U(t._zod,"optout",()=>e.out._zod.optout),U(t._zod,"propValues",()=>e.in._zod.propValues),t._zod.parse=(n,r)=>{if(r.direction==="backward"){const a=e.out._zod.run(n,r);return a instanceof Promise?a.then(o=>xn(o,e.in,r)):xn(a,e.in,r)}const s=e.in._zod.run(n,r);return s instanceof Promise?s.then(a=>xn(a,e.out,r)):xn(s,e.out,r)}});function xn(t,e,n){return t.issues.length?(t.aborted=!0,t):e._zod.run({value:t.value,issues:t.issues},n)}const Hv=g("$ZodReadonly",(t,e)=>{Y.init(t,e),U(t._zod,"propValues",()=>e.innerType._zod.propValues),U(t._zod,"values",()=>e.innerType._zod.values),U(t._zod,"optin",()=>e.innerType?._zod?.optin),U(t._zod,"optout",()=>e.innerType?._zod?.optout),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);const s=e.innerType._zod.run(n,r);return s instanceof Promise?s.then(la):la(s)}});function la(t){return t.value=Object.freeze(t.value),t}const Vv=g("$ZodCustom",(t,e)=>{ce.init(t,e),Y.init(t,e),t._zod.parse=(n,r)=>n,t._zod.check=n=>{const r=n.value,s=e.fn(r);if(s instanceof Promise)return s.then(a=>ha(a,n,r,t));ha(s,n,r,t)}});function ha(t,e,n,r){if(!t){const s={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(s.params=r._zod.def.params),e.issues.push(rn(s))}}var fa;class Gv{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...n){const r=n[0];return this._map.set(e,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const n=this._map.get(e);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(e),this}get(e){const n=e._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const s={...r,...this._map.get(e)};return Object.keys(s).length?s:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function Wv(){return new Gv}(fa=globalThis).__zod_globalRegistry??(fa.__zod_globalRegistry=Wv());const Bt=globalThis.__zod_globalRegistry;function Jv(t,e){return new t({type:"string",...$(e)})}function Kv(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...$(e)})}function da(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...$(e)})}function gu(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...$(e)})}function Xv(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...$(e)})}function Qv(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...$(e)})}function ez(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...$(e)})}function tz(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...$(e)})}function nz(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...$(e)})}function rz(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...$(e)})}function sz(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...$(e)})}function iz(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...$(e)})}function az(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...$(e)})}function oz(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...$(e)})}function cz(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...$(e)})}function uz(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...$(e)})}function lz(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...$(e)})}function hz(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...$(e)})}function fz(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...$(e)})}function dz(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...$(e)})}function pz(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...$(e)})}function yz(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...$(e)})}function mz(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...$(e)})}function gz(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...$(e)})}function wz(t,e){return new t({type:"string",format:"date",check:"string_format",...$(e)})}function bz(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...$(e)})}function vz(t,e){return new t({type:"string",format:"duration",check:"string_format",...$(e)})}function zz(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...$(e)})}function Tz(t,e){return new t({type:"boolean",...$(e)})}function Oz(t){return new t({type:"unknown"})}function Sz(t,e){return new t({type:"never",...$(e)})}function pa(t,e){return new lu({check:"less_than",...$(e),value:t,inclusive:!1})}function Zr(t,e){return new lu({check:"less_than",...$(e),value:t,inclusive:!0})}function ya(t,e){return new hu({check:"greater_than",...$(e),value:t,inclusive:!1})}function xr(t,e){return new hu({check:"greater_than",...$(e),value:t,inclusive:!0})}function ma(t,e){return new Bb({check:"multiple_of",...$(e),value:t})}function wu(t,e){return new Fb({check:"max_length",...$(e),maximum:t})}function Dn(t,e){return new Yb({check:"min_length",...$(e),minimum:t})}function bu(t,e){return new Hb({check:"length_equals",...$(e),length:t})}function Ez(t,e){return new Vb({check:"string_format",format:"regex",...$(e),pattern:t})}function Nz(t){return new Gb({check:"string_format",format:"lowercase",...$(t)})}function $z(t){return new Wb({check:"string_format",format:"uppercase",...$(t)})}function kz(t,e){return new Jb({check:"string_format",format:"includes",...$(e),includes:t})}function Az(t,e){return new Kb({check:"string_format",format:"starts_with",...$(e),prefix:t})}function Iz(t,e){return new Xb({check:"string_format",format:"ends_with",...$(e),suffix:t})}function Ct(t){return new Qb({check:"overwrite",tx:t})}function Zz(t){return Ct(e=>e.normalize(t))}function xz(){return Ct(t=>t.trim())}function Cz(){return Ct(t=>t.toLowerCase())}function _z(){return Ct(t=>t.toUpperCase())}function Mz(){return Ct(t=>Hw(t))}function Rz(t,e,n){return new t({type:"array",element:e,...$(n)})}function jz(t,e,n){return new t({type:"custom",check:"custom",fn:e,...$(n)})}function Uz(t){const e=Pz(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(rn(r,n.value,e._zod.def));else{const s=r;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=n.value),s.inst??(s.inst=e),s.continue??(s.continue=!e._zod.def.abort),n.issues.push(rn(s))}},t(n.value,n)));return e}function Pz(t,e){const n=new ce({check:"custom",...$(e)});return n._zod.check=t,n}function vu(t){let e=t?.target??"draft-2020-12";return e==="draft-4"&&(e="draft-04"),e==="draft-7"&&(e="draft-07"),{processors:t.processors??{},metadataRegistry:t?.metadata??Bt,target:e,unrepresentable:t?.unrepresentable??"throw",override:t?.override??(()=>{}),io:t?.io??"output",counter:0,seen:new Map,cycles:t?.cycles??"ref",reused:t?.reused??"inline",external:t?.external??void 0}}function ne(t,e,n={path:[],schemaPath:[]}){var r;const s=t._zod.def,a=e.seen.get(t);if(a)return a.count++,n.schemaPath.includes(t)&&(a.cycle=n.path),a.schema;const o={schema:{},count:1,cycle:void 0,path:n.path};e.seen.set(t,o);const c=t._zod.toJSONSchema?.();if(c)o.schema=c;else{const h={...n,schemaPath:[...n.schemaPath,t],path:n.path};if(t._zod.processJSONSchema)t._zod.processJSONSchema(e,o.schema,h);else{const f=o.schema,b=e.processors[s.type];if(!b)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${s.type}`);b(t,e,f,h)}const d=t._zod.parent;d&&(o.ref||(o.ref=d),ne(d,e,h),e.seen.get(d).isParent=!0)}const u=e.metadataRegistry.get(t);return u&&Object.assign(o.schema,u),e.io==="input"&&ie(t)&&(delete o.schema.examples,delete o.schema.default),e.io==="input"&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,e.seen.get(t).schema}function zu(t,e){const n=t.seen.get(e);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const o of t.seen.entries()){const c=t.metadataRegistry.get(o[0])?.id;if(c){const u=r.get(c);if(u&&u!==o[0])throw new Error(`Duplicate schema id "${c}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(c,o[0])}}const s=o=>{const c=t.target==="draft-2020-12"?"$defs":"definitions";if(t.external){const d=t.external.registry.get(o[0])?.id,f=t.external.uri??(N=>N);if(d)return{ref:f(d)};const b=o[1].defId??o[1].schema.id??`schema${t.counter++}`;return o[1].defId=b,{defId:b,ref:`${f("__shared")}#/${c}/${b}`}}if(o[1]===n)return{ref:"#"};const l=`#/${c}/`,h=o[1].schema.id??`__schema${t.counter++}`;return{defId:h,ref:l+h}},a=o=>{if(o[1].schema.$ref)return;const c=o[1],{ref:u,defId:l}=s(o);c.def={...c.schema},l&&(c.defId=l);const h=c.schema;for(const d in h)delete h[d];h.$ref=u};if(t.cycles==="throw")for(const o of t.seen.entries()){const c=o[1];if(c.cycle)throw new Error(`Cycle detected: #/${c.cycle?.join("/")}/<root>
|
|
57
|
+
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=Lf,s=!Cf.jitless,c=s&&Rf.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?eh([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function rh(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!$f(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>np(e,r,wf())))}),t)}var ih=B(`$ZodUnion`,(e,t)=>{W.init(e,t),V(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),V(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),V(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),V(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>kf(e.source)).join(`|`)})$`)}});let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);if(t instanceof Promise)s.push(t),o=!0;else{if(t.issues.length===0)return t;s.push(t)}}return o?Promise.all(s).then(t=>rh(t,i,e,a)):rh(s,i,e,a)}}),ah=B(`$ZodIntersection`,(e,t)=>{W.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>sh(e,t,n)):sh(e,i,a)}});function oh(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(zf(e)&&zf(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=oh(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=oh(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function sh(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),$f(e))return e;let o=oh(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}var ch=B(`$ZodEnum`,(e,t)=>{W.init(e,t);let n=Tf(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>Vf.has(typeof e)).map(e=>typeof e==`string`?Hf(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),lh=B(`$ZodTransform`,(e,t)=>{W.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Sf(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new xf;return n.value=i,n}});function uh(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}var dh=B(`$ZodOptional`,(e,t)=>{W.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,V(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),V(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${kf(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>uh(t,e.value)):uh(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),fh=B(`$ZodExactOptional`,(e,t)=>{dh.init(e,t),V(e._zod,`values`,()=>t.innerType._zod.values),V(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),ph=B(`$ZodNullable`,(e,t)=>{W.init(e,t),V(e._zod,`optin`,()=>t.innerType._zod.optin),V(e._zod,`optout`,()=>t.innerType._zod.optout),V(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${kf(e.source)}|null)$`):void 0}),V(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),mh=B(`$ZodDefault`,(e,t)=>{W.init(e,t),e._zod.optin=`optional`,V(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>hh(e,t)):hh(r,t)}});function hh(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var gh=B(`$ZodPrefault`,(e,t)=>{W.init(e,t),e._zod.optin=`optional`,V(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),_h=B(`$ZodNonOptional`,(e,t)=>{W.init(e,t),V(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>vh(t,e)):vh(i,e)}});function vh(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}var yh=B(`$ZodCatch`,(e,t)=>{W.init(e,t),V(e._zod,`optin`,()=>t.innerType._zod.optin),V(e._zod,`optout`,()=>t.innerType._zod.optout),V(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>np(e,n,wf()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>np(e,n,wf()))},input:e.value}),e.issues=[]),e)}}),bh=B(`$ZodPipe`,(e,t)=>{W.init(e,t),V(e._zod,`values`,()=>t.in._zod.values),V(e._zod,`optin`,()=>t.in._zod.optin),V(e._zod,`optout`,()=>t.out._zod.optout),V(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>xh(e,t.in,n)):xh(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>xh(e,t.out,n)):xh(r,t.out,n)}});function xh(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}var Sh=B(`$ZodReadonly`,(e,t)=>{W.init(e,t),V(e._zod,`propValues`,()=>t.innerType._zod.propValues),V(e._zod,`values`,()=>t.innerType._zod.values),V(e._zod,`optin`,()=>t.innerType?._zod?.optin),V(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Ch):Ch(r)}});function Ch(e){return e.value=Object.freeze(e.value),e}var wh=B(`$ZodCustom`,(e,t)=>{U.init(e,t),W.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Th(t,n,r,e));Th(i,n,r,e)}});function Th(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(ip(e))}}var Eh,Dh=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Oh(){return new Dh}(Eh=globalThis).__zod_globalRegistry??(Eh.__zod_globalRegistry=Oh());var kh=globalThis.__zod_globalRegistry;function Ah(e,t){return new e({type:`string`,...H(t)})}function jh(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...H(t)})}function Mh(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...H(t)})}function Nh(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...H(t)})}function Ph(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...H(t)})}function Fh(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...H(t)})}function Ih(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...H(t)})}function Lh(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...H(t)})}function Rh(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...H(t)})}function zh(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...H(t)})}function Bh(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...H(t)})}function Vh(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...H(t)})}function Hh(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...H(t)})}function Uh(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...H(t)})}function Wh(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...H(t)})}function Gh(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...H(t)})}function Kh(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...H(t)})}function qh(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...H(t)})}function Jh(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...H(t)})}function Yh(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...H(t)})}function Xh(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...H(t)})}function Zh(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...H(t)})}function Qh(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...H(t)})}function $h(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...H(t)})}function eg(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...H(t)})}function tg(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...H(t)})}function ng(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...H(t)})}function rg(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...H(t)})}function ig(e,t){return new e({type:`boolean`,...H(t)})}function ag(e){return new e({type:`unknown`})}function og(e,t){return new e({type:`never`,...H(t)})}function sg(e,t){return new tm({check:`less_than`,...H(t),value:e,inclusive:!1})}function cg(e,t){return new tm({check:`less_than`,...H(t),value:e,inclusive:!0})}function lg(e,t){return new nm({check:`greater_than`,...H(t),value:e,inclusive:!1})}function ug(e,t){return new nm({check:`greater_than`,...H(t),value:e,inclusive:!0})}function dg(e,t){return new rm({check:`multiple_of`,...H(t),value:e})}function fg(e,t){return new am({check:`max_length`,...H(t),maximum:e})}function pg(e,t){return new om({check:`min_length`,...H(t),minimum:e})}function mg(e,t){return new sm({check:`length_equals`,...H(t),length:e})}function hg(e,t){return new lm({check:`string_format`,format:`regex`,...H(t),pattern:e})}function gg(e){return new um({check:`string_format`,format:`lowercase`,...H(e)})}function _g(e){return new dm({check:`string_format`,format:`uppercase`,...H(e)})}function vg(e,t){return new fm({check:`string_format`,format:`includes`,...H(t),includes:e})}function yg(e,t){return new pm({check:`string_format`,format:`starts_with`,...H(t),prefix:e})}function bg(e,t){return new mm({check:`string_format`,format:`ends_with`,...H(t),suffix:e})}function xg(e){return new hm({check:`overwrite`,tx:e})}function Sg(e){return xg(t=>t.normalize(e))}function Cg(){return xg(e=>e.trim())}function wg(){return xg(e=>e.toLowerCase())}function Tg(){return xg(e=>e.toUpperCase())}function Eg(){return xg(e=>Ff(e))}function Dg(e,t,n){return new e({type:`array`,element:t,...H(n)})}function Og(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...H(n)})}function kg(e){let t=Ag(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(ip(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(ip(r))}},e(n.value,n)));return t}function Ag(e,t){let n=new U({check:`custom`,...H(t)});return n._zod.check=e,n}function jg(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??kh,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function K(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,K(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&q(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Mg(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
63
58
|
|
|
64
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const o of t.seen.entries()){const c=o[1];if(e===o[0]){a(o);continue}if(t.external){const l=t.external.registry.get(o[0])?.id;if(e!==o[0]&&l){a(o);continue}}if(t.metadataRegistry.get(o[0])?.id){a(o);continue}if(c.cycle){a(o);continue}if(c.count>1&&t.reused==="ref"){a(o);continue}}}function Tu(t,e){const n=t.seen.get(e);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=o=>{const c=t.seen.get(o);if(c.ref===null)return;const u=c.def??c.schema,l={...u},h=c.ref;if(c.ref=null,h){r(h);const f=t.seen.get(h),b=f.schema;if(b.$ref&&(t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0")?(u.allOf=u.allOf??[],u.allOf.push(b)):Object.assign(u,b),Object.assign(u,l),o._zod.parent===h)for(const k in u)k==="$ref"||k==="allOf"||k in l||delete u[k];if(b.$ref&&f.def)for(const k in u)k==="$ref"||k==="allOf"||k in f.def&&JSON.stringify(u[k])===JSON.stringify(f.def[k])&&delete u[k]}const d=o._zod.parent;if(d&&d!==h){r(d);const f=t.seen.get(d);if(f?.schema.$ref&&(u.$ref=f.schema.$ref,f.def))for(const b in u)b==="$ref"||b==="allOf"||b in f.def&&JSON.stringify(u[b])===JSON.stringify(f.def[b])&&delete u[b]}t.override({zodSchema:o,jsonSchema:u,path:c.path??[]})};for(const o of[...t.seen.entries()].reverse())r(o[0]);const s={};if(t.target==="draft-2020-12"?s.$schema="https://json-schema.org/draft/2020-12/schema":t.target==="draft-07"?s.$schema="http://json-schema.org/draft-07/schema#":t.target==="draft-04"?s.$schema="http://json-schema.org/draft-04/schema#":t.target,t.external?.uri){const o=t.external.registry.get(e)?.id;if(!o)throw new Error("Schema is missing an `id` property");s.$id=t.external.uri(o)}Object.assign(s,n.def??n.schema);const a=t.external?.defs??{};for(const o of t.seen.entries()){const c=o[1];c.def&&c.defId&&(a[c.defId]=c.def)}t.external||Object.keys(a).length>0&&(t.target==="draft-2020-12"?s.$defs=a:s.definitions=a);try{const o=JSON.parse(JSON.stringify(s));return Object.defineProperty(o,"~standard",{value:{...e["~standard"],jsonSchema:{input:Bn(e,"input",t.processors),output:Bn(e,"output",t.processors)}},enumerable:!1,writable:!1}),o}catch{throw new Error("Error converting schema to JSON.")}}function ie(t,e){const n=e??{seen:new Set};if(n.seen.has(t))return!1;n.seen.add(t);const r=t._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return ie(r.element,n);if(r.type==="set")return ie(r.valueType,n);if(r.type==="lazy")return ie(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return ie(r.innerType,n);if(r.type==="intersection")return ie(r.left,n)||ie(r.right,n);if(r.type==="record"||r.type==="map")return ie(r.keyType,n)||ie(r.valueType,n);if(r.type==="pipe")return ie(r.in,n)||ie(r.out,n);if(r.type==="object"){for(const s in r.shape)if(ie(r.shape[s],n))return!0;return!1}if(r.type==="union"){for(const s of r.options)if(ie(s,n))return!0;return!1}if(r.type==="tuple"){for(const s of r.items)if(ie(s,n))return!0;return!!(r.rest&&ie(r.rest,n))}return!1}const Lz=(t,e={})=>n=>{const r=vu({...n,processors:e});return ne(t,r),zu(r,t),Tu(r,t)},Bn=(t,e,n={})=>r=>{const{libraryOptions:s,target:a}=r??{},o=vu({...s??{},target:a,io:e,processors:n});return ne(t,o),zu(o,t),Tu(o,t)},Dz={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Bz=(t,e,n,r)=>{const s=n;s.type="string";const{minimum:a,maximum:o,format:c,patterns:u,contentEncoding:l}=t._zod.bag;if(typeof a=="number"&&(s.minLength=a),typeof o=="number"&&(s.maxLength=o),c&&(s.format=Dz[c]??c,s.format===""&&delete s.format,c==="time"&&delete s.format),l&&(s.contentEncoding=l),u&&u.size>0){const h=[...u];h.length===1?s.pattern=h[0].source:h.length>1&&(s.allOf=[...h.map(d=>({...e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"?{type:"string"}:{},pattern:d.source}))])}},qz=(t,e,n,r)=>{const s=n,{minimum:a,maximum:o,format:c,multipleOf:u,exclusiveMaximum:l,exclusiveMinimum:h}=t._zod.bag;typeof c=="string"&&c.includes("int")?s.type="integer":s.type="number",typeof h=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(s.minimum=h,s.exclusiveMinimum=!0):s.exclusiveMinimum=h),typeof a=="number"&&(s.minimum=a,typeof h=="number"&&e.target!=="draft-04"&&(h>=a?delete s.minimum:delete s.exclusiveMinimum)),typeof l=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(s.maximum=l,s.exclusiveMaximum=!0):s.exclusiveMaximum=l),typeof o=="number"&&(s.maximum=o,typeof l=="number"&&e.target!=="draft-04"&&(l<=o?delete s.maximum:delete s.exclusiveMaximum)),typeof u=="number"&&(s.multipleOf=u)},Fz=(t,e,n,r)=>{n.type="boolean"},Yz=(t,e,n,r)=>{n.not={}},Hz=(t,e,n,r)=>{},Vz=(t,e,n,r)=>{const s=t._zod.def,a=Qc(s.entries);a.every(o=>typeof o=="number")&&(n.type="number"),a.every(o=>typeof o=="string")&&(n.type="string"),n.enum=a},Gz=(t,e,n,r)=>{const s=t._zod.def,a=[];for(const o of s.values)if(o===void 0){if(e.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(e.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");a.push(Number(o))}else a.push(o);if(a.length!==0)if(a.length===1){const o=a[0];n.type=o===null?"null":typeof o,e.target==="draft-04"||e.target==="openapi-3.0"?n.enum=[o]:n.const=o}else a.every(o=>typeof o=="number")&&(n.type="number"),a.every(o=>typeof o=="string")&&(n.type="string"),a.every(o=>typeof o=="boolean")&&(n.type="boolean"),a.every(o=>o===null)&&(n.type="null"),n.enum=a},Wz=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},Jz=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},Kz=(t,e,n,r)=>{const s=n,a=t._zod.def,{minimum:o,maximum:c}=t._zod.bag;typeof o=="number"&&(s.minItems=o),typeof c=="number"&&(s.maxItems=c),s.type="array",s.items=ne(a.element,e,{...r,path:[...r.path,"items"]})},Xz=(t,e,n,r)=>{const s=n,a=t._zod.def;s.type="object",s.properties={};const o=a.shape;for(const l in o)s.properties[l]=ne(o[l],e,{...r,path:[...r.path,"properties",l]});const c=new Set(Object.keys(o)),u=new Set([...c].filter(l=>{const h=a.shape[l]._zod;return e.io==="input"?h.optin===void 0:h.optout===void 0}));u.size>0&&(s.required=Array.from(u)),a.catchall?._zod.def.type==="never"?s.additionalProperties=!1:a.catchall?a.catchall&&(s.additionalProperties=ne(a.catchall,e,{...r,path:[...r.path,"additionalProperties"]})):e.io==="output"&&(s.additionalProperties=!1)},Qz=(t,e,n,r)=>{const s=t._zod.def,a=s.inclusive===!1,o=s.options.map((c,u)=>ne(c,e,{...r,path:[...r.path,a?"oneOf":"anyOf",u]}));a?n.oneOf=o:n.anyOf=o},eT=(t,e,n,r)=>{const s=t._zod.def,a=ne(s.left,e,{...r,path:[...r.path,"allOf",0]}),o=ne(s.right,e,{...r,path:[...r.path,"allOf",1]}),c=l=>"allOf"in l&&Object.keys(l).length===1,u=[...c(a)?a.allOf:[a],...c(o)?o.allOf:[o]];n.allOf=u},tT=(t,e,n,r)=>{const s=t._zod.def,a=ne(s.innerType,e,r),o=e.seen.get(t);e.target==="openapi-3.0"?(o.ref=s.innerType,n.nullable=!0):n.anyOf=[a,{type:"null"}]},nT=(t,e,n,r)=>{const s=t._zod.def;ne(s.innerType,e,r);const a=e.seen.get(t);a.ref=s.innerType},rT=(t,e,n,r)=>{const s=t._zod.def;ne(s.innerType,e,r);const a=e.seen.get(t);a.ref=s.innerType,n.default=JSON.parse(JSON.stringify(s.defaultValue))},sT=(t,e,n,r)=>{const s=t._zod.def;ne(s.innerType,e,r);const a=e.seen.get(t);a.ref=s.innerType,e.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(s.defaultValue)))},iT=(t,e,n,r)=>{const s=t._zod.def;ne(s.innerType,e,r);const a=e.seen.get(t);a.ref=s.innerType;let o;try{o=s.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o},aT=(t,e,n,r)=>{const s=t._zod.def,a=e.io==="input"?s.in._zod.def.type==="transform"?s.out:s.in:s.out;ne(a,e,r);const o=e.seen.get(t);o.ref=a},oT=(t,e,n,r)=>{const s=t._zod.def;ne(s.innerType,e,r);const a=e.seen.get(t);a.ref=s.innerType,n.readOnly=!0},Ou=(t,e,n,r)=>{const s=t._zod.def;ne(s.innerType,e,r);const a=e.seen.get(t);a.ref=s.innerType},cT=g("ZodISODateTime",(t,e)=>{dv.init(t,e),F.init(t,e)});function uT(t){return gz(cT,t)}const lT=g("ZodISODate",(t,e)=>{pv.init(t,e),F.init(t,e)});function hT(t){return wz(lT,t)}const fT=g("ZodISOTime",(t,e)=>{yv.init(t,e),F.init(t,e)});function dT(t){return bz(fT,t)}const pT=g("ZodISODuration",(t,e)=>{mv.init(t,e),F.init(t,e)});function yT(t){return vz(pT,t)}const mT=(t,e)=>{su.init(t,e),t.name="ZodError",Object.defineProperties(t,{format:{value:n=>ib(t,n)},flatten:{value:n=>sb(t,n)},addIssue:{value:n=>{t.issues.push(n),t.message=JSON.stringify(t.issues,fs,2)}},addIssues:{value:n=>{t.issues.push(...n),t.message=JSON.stringify(t.issues,fs,2)}},isEmpty:{get(){return t.issues.length===0}}})},me=g("ZodError",mT,{Parent:Error}),gT=si(me),wT=ii(me),bT=tr(me),vT=nr(me),zT=cb(me),TT=ub(me),OT=lb(me),ST=hb(me),ET=fb(me),NT=db(me),$T=pb(me),kT=yb(me),H=g("ZodType",(t,e)=>(Y.init(t,e),Object.assign(t["~standard"],{jsonSchema:{input:Bn(t,"input"),output:Bn(t,"output")}}),t.toJSONSchema=Lz(t,{}),t.def=e,t.type=e.type,Object.defineProperty(t,"_def",{value:e}),t.check=(...n)=>t.clone(et(e,{checks:[...e.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0}),t.with=t.check,t.clone=(n,r)=>tt(t,n,r),t.brand=()=>t,t.register=((n,r)=>(n.add(t,r),t)),t.parse=(n,r)=>gT(t,n,r,{callee:t.parse}),t.safeParse=(n,r)=>bT(t,n,r),t.parseAsync=async(n,r)=>wT(t,n,r,{callee:t.parseAsync}),t.safeParseAsync=async(n,r)=>vT(t,n,r),t.spa=t.safeParseAsync,t.encode=(n,r)=>zT(t,n,r),t.decode=(n,r)=>TT(t,n,r),t.encodeAsync=async(n,r)=>OT(t,n,r),t.decodeAsync=async(n,r)=>ST(t,n,r),t.safeEncode=(n,r)=>ET(t,n,r),t.safeDecode=(n,r)=>NT(t,n,r),t.safeEncodeAsync=async(n,r)=>$T(t,n,r),t.safeDecodeAsync=async(n,r)=>kT(t,n,r),t.refine=(n,r)=>t.check(SO(n,r)),t.superRefine=n=>t.check(EO(n)),t.overwrite=n=>t.check(Ct(n)),t.optional=()=>ba(t),t.exactOptional=()=>hO(t),t.nullable=()=>va(t),t.nullish=()=>ba(va(t)),t.nonoptional=n=>gO(t,n),t.array=()=>tO(t),t.or=n=>ci([t,n]),t.and=n=>iO(t,n),t.transform=n=>za(t,uO(n)),t.default=n=>pO(t,n),t.prefault=n=>mO(t,n),t.catch=n=>bO(t,n),t.pipe=n=>za(t,n),t.readonly=()=>TO(t),t.describe=n=>{const r=t.clone();return Bt.add(r,{description:n}),r},Object.defineProperty(t,"description",{get(){return Bt.get(t)?.description},configurable:!0}),t.meta=(...n)=>{if(n.length===0)return Bt.get(t);const r=t.clone();return Bt.add(r,n[0]),r},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t.apply=n=>n(t),t)),Su=g("_ZodString",(t,e)=>{ai.init(t,e),H.init(t,e),t._zod.processJSONSchema=(r,s,a)=>Bz(t,r,s);const n=t._zod.bag;t.format=n.format??null,t.minLength=n.minimum??null,t.maxLength=n.maximum??null,t.regex=(...r)=>t.check(Ez(...r)),t.includes=(...r)=>t.check(kz(...r)),t.startsWith=(...r)=>t.check(Az(...r)),t.endsWith=(...r)=>t.check(Iz(...r)),t.min=(...r)=>t.check(Dn(...r)),t.max=(...r)=>t.check(wu(...r)),t.length=(...r)=>t.check(bu(...r)),t.nonempty=(...r)=>t.check(Dn(1,...r)),t.lowercase=r=>t.check(Nz(r)),t.uppercase=r=>t.check($z(r)),t.trim=()=>t.check(xz()),t.normalize=(...r)=>t.check(Zz(...r)),t.toLowerCase=()=>t.check(Cz()),t.toUpperCase=()=>t.check(_z()),t.slugify=()=>t.check(Mz())}),AT=g("ZodString",(t,e)=>{ai.init(t,e),Su.init(t,e),t.email=n=>t.check(Kv(IT,n)),t.url=n=>t.check(tz(xT,n)),t.jwt=n=>t.check(mz(VT,n)),t.emoji=n=>t.check(nz(CT,n)),t.guid=n=>t.check(da(ga,n)),t.uuid=n=>t.check(gu(qt,n)),t.uuidv4=n=>t.check(Xv(qt,n)),t.uuidv6=n=>t.check(Qv(qt,n)),t.uuidv7=n=>t.check(ez(qt,n)),t.nanoid=n=>t.check(rz(_T,n)),t.guid=n=>t.check(da(ga,n)),t.cuid=n=>t.check(sz(MT,n)),t.cuid2=n=>t.check(iz(RT,n)),t.ulid=n=>t.check(az(jT,n)),t.base64=n=>t.check(dz(FT,n)),t.base64url=n=>t.check(pz(YT,n)),t.xid=n=>t.check(oz(UT,n)),t.ksuid=n=>t.check(cz(PT,n)),t.ipv4=n=>t.check(uz(LT,n)),t.ipv6=n=>t.check(lz(DT,n)),t.cidrv4=n=>t.check(hz(BT,n)),t.cidrv6=n=>t.check(fz(qT,n)),t.e164=n=>t.check(yz(HT,n)),t.datetime=n=>t.check(uT(n)),t.date=n=>t.check(hT(n)),t.time=n=>t.check(dT(n)),t.duration=n=>t.check(yT(n))});function ye(t){return Jv(AT,t)}const F=g("ZodStringFormat",(t,e)=>{q.init(t,e),Su.init(t,e)}),IT=g("ZodEmail",(t,e)=>{sv.init(t,e),F.init(t,e)}),ga=g("ZodGUID",(t,e)=>{nv.init(t,e),F.init(t,e)}),qt=g("ZodUUID",(t,e)=>{rv.init(t,e),F.init(t,e)});function ZT(t){return gu(qt,t)}const xT=g("ZodURL",(t,e)=>{iv.init(t,e),F.init(t,e)}),CT=g("ZodEmoji",(t,e)=>{av.init(t,e),F.init(t,e)}),_T=g("ZodNanoID",(t,e)=>{ov.init(t,e),F.init(t,e)}),MT=g("ZodCUID",(t,e)=>{cv.init(t,e),F.init(t,e)}),RT=g("ZodCUID2",(t,e)=>{uv.init(t,e),F.init(t,e)}),jT=g("ZodULID",(t,e)=>{lv.init(t,e),F.init(t,e)}),UT=g("ZodXID",(t,e)=>{hv.init(t,e),F.init(t,e)}),PT=g("ZodKSUID",(t,e)=>{fv.init(t,e),F.init(t,e)}),LT=g("ZodIPv4",(t,e)=>{gv.init(t,e),F.init(t,e)}),DT=g("ZodIPv6",(t,e)=>{wv.init(t,e),F.init(t,e)}),BT=g("ZodCIDRv4",(t,e)=>{bv.init(t,e),F.init(t,e)}),qT=g("ZodCIDRv6",(t,e)=>{vv.init(t,e),F.init(t,e)}),FT=g("ZodBase64",(t,e)=>{zv.init(t,e),F.init(t,e)}),YT=g("ZodBase64URL",(t,e)=>{Ov.init(t,e),F.init(t,e)}),HT=g("ZodE164",(t,e)=>{Sv.init(t,e),F.init(t,e)}),VT=g("ZodJWT",(t,e)=>{Nv.init(t,e),F.init(t,e)}),GT=g("ZodNumber",(t,e)=>{du.init(t,e),H.init(t,e),t._zod.processJSONSchema=(r,s,a)=>qz(t,r,s),t.gt=(r,s)=>t.check(ya(r,s)),t.gte=(r,s)=>t.check(xr(r,s)),t.min=(r,s)=>t.check(xr(r,s)),t.lt=(r,s)=>t.check(pa(r,s)),t.lte=(r,s)=>t.check(Zr(r,s)),t.max=(r,s)=>t.check(Zr(r,s)),t.int=r=>t.check(qn(r)),t.safe=r=>t.check(qn(r)),t.positive=r=>t.check(ya(0,r)),t.nonnegative=r=>t.check(xr(0,r)),t.negative=r=>t.check(pa(0,r)),t.nonpositive=r=>t.check(Zr(0,r)),t.multipleOf=(r,s)=>t.check(ma(r,s)),t.step=(r,s)=>t.check(ma(r,s)),t.finite=()=>t;const n=t._zod.bag;t.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),t.isFinite=!0,t.format=n.format??null}),WT=g("ZodNumberFormat",(t,e)=>{$v.init(t,e),GT.init(t,e)});function qn(t){return zz(WT,t)}const JT=g("ZodBoolean",(t,e)=>{kv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Fz(t,n,r)});function oi(t){return Tz(JT,t)}const KT=g("ZodUnknown",(t,e)=>{Av.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Hz()});function wa(){return Oz(KT)}const XT=g("ZodNever",(t,e)=>{Iv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Yz(t,n,r)});function QT(t){return Sz(XT,t)}const eO=g("ZodArray",(t,e)=>{Zv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Kz(t,n,r,s),t.element=e.element,t.min=(n,r)=>t.check(Dn(n,r)),t.nonempty=n=>t.check(Dn(1,n)),t.max=(n,r)=>t.check(wu(n,r)),t.length=(n,r)=>t.check(bu(n,r)),t.unwrap=()=>t.element});function tO(t,e){return Rz(eO,t,e)}const nO=g("ZodObject",(t,e)=>{Cv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Xz(t,n,r,s),U(t,"shape",()=>e.shape),t.keyof=()=>Eu(Object.keys(t._zod.def.shape)),t.catchall=n=>t.clone({...t._zod.def,catchall:n}),t.passthrough=()=>t.clone({...t._zod.def,catchall:wa()}),t.loose=()=>t.clone({...t._zod.def,catchall:wa()}),t.strict=()=>t.clone({...t._zod.def,catchall:QT()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=n=>Qw(t,n),t.safeExtend=n=>eb(t,n),t.merge=n=>tb(t,n),t.pick=n=>Kw(t,n),t.omit=n=>Xw(t,n),t.partial=(...n)=>nb(Nu,t,n[0]),t.required=(...n)=>rb($u,t,n[0])});function se(t,e){const n={type:"object",shape:t??{},...$(e)};return new nO(n)}const rO=g("ZodUnion",(t,e)=>{_v.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Qz(t,n,r,s),t.options=e.options});function ci(t,e){return new rO({type:"union",options:t,...$(e)})}const sO=g("ZodIntersection",(t,e)=>{Mv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>eT(t,n,r,s)});function iO(t,e){return new sO({type:"intersection",left:t,right:e})}const ps=g("ZodEnum",(t,e)=>{Rv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(r,s,a)=>Vz(t,r,s),t.enum=e.entries,t.options=Object.values(e.entries);const n=new Set(Object.keys(e.entries));t.extract=(r,s)=>{const a={};for(const o of r)if(n.has(o))a[o]=e.entries[o];else throw new Error(`Key ${o} not found in enum`);return new ps({...e,checks:[],...$(s),entries:a})},t.exclude=(r,s)=>{const a={...e.entries};for(const o of r)if(n.has(o))delete a[o];else throw new Error(`Key ${o} not found in enum`);return new ps({...e,checks:[],...$(s),entries:a})}});function Eu(t,e){const n=Array.isArray(t)?Object.fromEntries(t.map(r=>[r,r])):t;return new ps({type:"enum",entries:n,...$(e)})}const aO=g("ZodLiteral",(t,e)=>{jv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Gz(t,n,r),t.values=new Set(e.values),Object.defineProperty(t,"value",{get(){if(e.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return e.values[0]}})});function oO(t,e){return new aO({type:"literal",values:Array.isArray(t)?t:[t],...$(e)})}const cO=g("ZodTransform",(t,e)=>{Uv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Jz(t,n),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Kc(t.constructor.name);n.addIssue=a=>{if(typeof a=="string")n.issues.push(rn(a,n.value,e));else{const o=a;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),n.issues.push(rn(o))}};const s=e.transform(n.value,n);return s instanceof Promise?s.then(a=>(n.value=a,n)):(n.value=s,n)}});function uO(t){return new cO({type:"transform",transform:t})}const Nu=g("ZodOptional",(t,e)=>{mu.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Ou(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function ba(t){return new Nu({type:"optional",innerType:t})}const lO=g("ZodExactOptional",(t,e)=>{Pv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Ou(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function hO(t){return new lO({type:"optional",innerType:t})}const fO=g("ZodNullable",(t,e)=>{Lv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>tT(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function va(t){return new fO({type:"nullable",innerType:t})}const dO=g("ZodDefault",(t,e)=>{Dv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>rT(t,n,r,s),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function pO(t,e){return new dO({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():tu(e)}})}const yO=g("ZodPrefault",(t,e)=>{Bv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>sT(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function mO(t,e){return new yO({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():tu(e)}})}const $u=g("ZodNonOptional",(t,e)=>{qv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>nT(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function gO(t,e){return new $u({type:"nonoptional",innerType:t,...$(e)})}const wO=g("ZodCatch",(t,e)=>{Fv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>iT(t,n,r,s),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function bO(t,e){return new wO({type:"catch",innerType:t,catchValue:typeof e=="function"?e:()=>e})}const vO=g("ZodPipe",(t,e)=>{Yv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>aT(t,n,r,s),t.in=e.in,t.out=e.out});function za(t,e){return new vO({type:"pipe",in:t,out:e})}const zO=g("ZodReadonly",(t,e)=>{Hv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>oT(t,n,r,s),t.unwrap=()=>t._zod.def.innerType});function TO(t){return new zO({type:"readonly",innerType:t})}const OO=g("ZodCustom",(t,e)=>{Vv.init(t,e),H.init(t,e),t._zod.processJSONSchema=(n,r,s)=>Wz(t,n)});function SO(t,e={}){return jz(OO,t,e)}function EO(t){return Uz(t)}const Ze=t=>t?JSON.parse(t):{},ui=se({key:ye(),type:ye(),config:oe.unknownZ.or(ye().transform(Ze))}),ku=ui.extend({position:Ps.xy}),ys=se({param:ye(),node:ye()}),li=se({source:ys,target:ys}),NO=se({nodes:ui.array(),edges:li.array()}),Au=se({nodes:ku.array(),edges:li.array()}),Iu=se({raw:ye()}),yn=ZT(),Zu=Eu(["graph","text"]).or(oO("").transform(()=>"graph")),sr=se({key:yn,name:ye(),graph:Au,text:Iu,version:ye(),mode:Zu}),xu=sr.partial({key:!0,mode:!0}),$O="arc",Cu=J("arc"),kO=Cu(""),AO=(t,e,{convertNumericStrings:n=!0}={})=>{const r=!Array.isArray(t);let s=E.toArray(t);const a=s[0],o=typeof a;let c;return o==="string"&&n&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,s=s.map(u=>parseInt(u))):c=e[o],{single:r,variant:c,normalized:s,actual:t}},ue=(t,e,n,r)=>{if(r){if(n.length===0)throw new en(`${t} not found matching ${JSON.stringify(e)}`);if(n.length>1)throw new tn(`Expected one ${t} matching ${JSON.stringify(e)}, but found ${n.length}`)}},IO="sy_arc_set",ZO="sy_arc_delete",xO=se({keys:yn.array().optional(),names:ye().array().optional(),searchTerm:ye().optional(),limit:qn().optional(),offset:qn().optional(),includeStatus:oi().optional()}),CO=se({arcs:xu.array()}),_O=se({keys:yn.array()}),MO=se({arcs:E.nullableZ(sr)}),RO=se({arcs:sr.array()}),jO=se({}),ms=se({content:ye()}),UO=se({key:yn,includeStatus:oi().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),PO=se({name:ye(),includeStatus:oi().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e})),_u=ci([UO,PO]),LO=ci([_u,xO]);let Mu=class{client;streamClient;constructor(e,n){this.client=e,this.streamClient=n}async create(e){const n=Array.isArray(e),r=await T(this.client,"/arc/create",{arcs:E.toArray(e)},CO,RO);return n?r.arcs:r.arcs[0]}async retrieve(e){const n="key"in e||"name"in e,r=await T(this.client,"/arc/retrieve",e,LO,MO);return ue("Arc",e,r.arcs,n),n?r.arcs[0]:r.arcs}async delete(e){await T(this.client,"/arc/delete",{keys:E.toArray(e)},_O,jO)}async openLSP(){return await this.streamClient.stream("/arc/lsp",ms,ms)}};const DO=Object.freeze(Object.defineProperty({__proto__:null,Client:Mu,DELETE_CHANNEL_NAME:ZO,ONTOLOGY_TYPE:$O,SET_CHANNEL_NAME:IO,TYPE_ONTOLOGY_ID:kO,arcZ:sr,edgeZ:li,graphNodeZ:ku,graphZ:Au,handleZ:ys,irNodeZ:ui,irZ:NO,keyZ:yn,lspMessageZ:ms,modeZ:Zu,newZ:xu,ontologyID:Cu,singleRetrieveArgsZ:_u,textZ:Iu},Symbol.toStringTag,{value:"Module"})),Ta="Channel key must be a valid uint32.",L=i.z.uint32().or(i.z.string().refine(t=>!isNaN(Number(t)),{message:Ta}).transform(Number).refine(t=>t<Xr.MAX_UINT32,{message:Ta})),Pe=i.z.string().min(1,"Name must not be empty"),Ru=["min","max","avg","none"],ju=i.z.enum(Ru),hi=i.z.object({type:ju,resetChannel:L.optional(),duration:w.z.optional()}),Uu=Qe.statusZ(),Pu=i.z.object({channel:L}),BO=Qe.statusZ(Pu),qO=t=>ke(ir(t)),_t=i.z.object({name:i.z.string(),key:L,dataType:p.z,leaseholder:be.uint12,index:L,isIndex:i.z.boolean(),internal:i.z.boolean(),virtual:i.z.boolean(),alias:i.z.string().optional(),expression:i.z.string().default(""),status:Uu.optional(),operations:E.nullableZ(hi)}),Lu=_t.extend({key:L.optional(),name:Pe,leaseholder:be.uint12.optional(),index:L.optional(),isIndex:i.z.boolean().optional(),internal:i.z.boolean().default(!1),virtual:i.z.boolean().default(!1),expression:i.z.string().default(""),operations:E.nullableZ(hi).optional()}),mt=i.z.union([be.toArray(L),be.toArray(Pe),be.toArray(_t).transform(t=>t.map(e=>e.key))]),ir=J("channel"),FO=ir(0),YO=/[a-zA-Z0-9_]/,HO=/^[a-zA-Z_][a-zA-Z0-9_]*$/,VO=(t,e=!1)=>{if(t==="")return e?"_":"";if(t.match(HO))return t;let n="";for(const r of t)r.match(YO)?n+=r:n+="_";return n[0].match(/^\d/)&&(n=`_${n}`),n},GO=new Error("request for lock canceled");var WO=function(t,e,n,r){function s(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(h){try{l(r.next(h))}catch(d){o(d)}}function u(h){try{l(r.throw(h))}catch(d){o(d)}}function l(h){h.done?a(h.value):s(h.value).then(c,u)}l((r=r.apply(t,e||[])).next())})};class JO{constructor(e,n=GO){this._value=e,this._cancelError=n,this._queue=[],this._weightedWaiters=[]}acquire(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((r,s)=>{const a={resolve:r,reject:s,weight:e,priority:n},o=Du(this._queue,c=>n<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return WO(this,arguments,void 0,function*(n,r=1,s=0){const[a,o]=yield this.acquire(r,s);try{return yield n(a)}finally{o()}})}waitForUnlock(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,n)?Promise.resolve():new Promise(r=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),KO(this._weightedWaiters[e-1],{resolve:r,priority:n})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const n=this._value;this._value-=e.weight,e.resolve([n,this._newReleaser(e.weight)])}_newReleaser(e){let n=!1;return()=>{n||(n=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const n=this._weightedWaiters[e-1];n&&(n.forEach(r=>r.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let n=this._value;n>0;n--){const r=this._weightedWaiters[n-1];if(!r)continue;const s=r.findIndex(a=>a.priority<=e);(s===-1?r:r.splice(0,s)).forEach((a=>a.resolve()))}}}_couldLockImmediately(e,n){return(this._queue.length===0||this._queue[0].priority<n)&&e<=this._value}}function KO(t,e){const n=Du(t,r=>e.priority<=r.priority);t.splice(n+1,0,e)}function Du(t,e){for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1}var XO=function(t,e,n,r){function s(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(h){try{l(r.next(h))}catch(d){o(d)}}function u(h){try{l(r.throw(h))}catch(d){o(d)}}function l(h){h.done?a(h.value):s(h.value).then(c,u)}l((r=r.apply(t,e||[])).next())})};class QO{constructor(e){this._semaphore=new JO(1,e)}acquire(){return XO(this,arguments,void 0,function*(e=0){const[,n]=yield this._semaphore.acquire(1,e);return n})}runExclusive(e,n=0){return this._semaphore.runExclusive(()=>e(),1,n)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const nt=Nc.keyZ,mn=Nc.labelZ,eS="labeled_by",tS="sy_label_set",nS="sy_label_delete",Bu=mn.extend({key:nt.optional()}),rS=i.object({labels:Bu.array()}),sS=i.object({labels:mn.array()}),iS=i.object({keys:nt.array()}),qu=i.object({id:B,labels:nt.array(),replace:i.boolean().optional()}),aS=qu.omit({replace:!0}),Cr=i.object({}),oS=i.object({keys:nt.array().optional(),names:i.string().array().optional(),for:B.optional(),searchTerm:i.string().optional(),offset:i.int().optional(),limit:i.int().optional()}),cS=i.object({key:nt}).transform(({key:t})=>({keys:[t]})),uS=i.union([cS,oS]),lS=i.object({labels:E.nullableZ(mn)});let Fu=class{type="label";client;constructor(e){this.client=e}async retrieve(e){const n="key"in e,r=await T(this.client,"/label/retrieve",e,uS,lS);return ue("Label",e,r.labels,n),n?r.labels[0]:r.labels}async label(e,n,r={}){await T(this.client,"/label/set",{id:e,labels:n,replace:r.replace},qu,Cr)}async remove(e,n){await T(this.client,"/label/remove",{id:e,labels:n},aS,Cr)}async create(e){const n=Array.isArray(e),r=await T(this.client,"/label/create",{labels:E.toArray(e)},rS,sS);return n?r.labels:r.labels[0]}async delete(e){await T(this.client,"/label/delete",{keys:E.toArray(e)},iS,Cr)}};const Yu=J("label"),hS=Yu(""),fS=Object.freeze(Object.defineProperty({__proto__:null,Client:Fu,DELETE_CHANNEL_NAME:nS,LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE:eS,SET_CHANNEL_NAME:tS,TYPE_ONTOLOGY_ID:hS,keyZ:nt,labelZ:mn,newZ:Bu,ontologyID:Yu},Symbol.toStringTag,{value:"Module"})),X=i.z.uuid(),fi=i.z.string().min(1),gn=i.z.object({key:X,name:fi,timeRange:x.z.refine(({isValid:t})=>t,{error:"Time range start time must be before or equal to time range end time"}).refine(({end:t})=>t.valueOf()<=Xr.MAX_INT64,{error:"Time range end time must be less than or equal to the maximum value of an int64"}).refine(({start:t})=>t.valueOf()>=Xr.MIN_INT64,{error:"Time range start time must be greater than or equal to the minimum value of an int64"}),color:yc.colorZ.optional(),labels:mn.array().or(i.z.null().transform(()=>{})).optional(),get parent(){return gn.optional().nullable().transform(t=>t===void 0?null:t)}}),Hu=gn.omit({parent:!0,labels:!0}).partial({key:!0}),dS=i.z.object({nodeKey:be.uint12.optional(),keys:L.array().optional(),names:i.z.string().array().optional(),searchTerm:i.z.string().optional(),rangeKey:X.optional(),limit:i.z.int().optional(),offset:i.z.int().optional(),dataTypes:p.z.array().optional(),notDataTypes:p.z.array().optional(),virtual:i.z.boolean().optional(),isIndex:i.z.boolean().optional(),internal:i.z.boolean().optional(),legacyCalculated:i.z.boolean().optional()}),pS=i.z.object({channels:E.nullableZ(_t)}),ve=t=>(Array.isArray(t)&&t.length>0&&typeof t[0]=="object"?t=t.map(e=>e.key):typeof t=="object"&&"key"in t&&(t=[t.key]),AO(t,{number:"keys",string:"names"}));class di{client;constructor(e){this.client=e}async retrieve(e,n){if(!Array.isArray(e)&&typeof e=="object")return await this.execute(e);const r=ve(e),{variant:s}=r;let{normalized:a}=r;return s==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[s]:a,...n})}async execute(e){return(await T(this.client,"/channel/retrieve",e,dS,pS)).channels}}class pi{cache;namesToKeys;wrapped;constructor(e){this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async retrieve(e,n){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:r}=ve(e),s=[],a=[];if(r.forEach(c=>{const u=this.get(c);u!=null?s.push(...u):a.push(c)}),a.length===0)return s;const o=await this.wrapped.retrieve(a,n);return this.set(o),s.concat(o)}delete(e){const{variant:n,normalized:r}=ve(e);n==="names"?r.forEach(s=>{const a=this.namesToKeys.get(s);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(s))}):r.forEach(s=>{const a=this.cache.get(s);a!=null&&(this.cache.delete(s),this.namesToKeys.delete(a.name))})}rename(e,n){e.forEach((r,s)=>{const a=n[s],o=this.cache.get(r);if(o==null)return;this.cache.delete(r);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(r),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(r,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([r])):u.add(r)})}set(e){e.forEach(n=>{this.cache.set(n.key,n);const r=this.namesToKeys.get(n.name);r==null?this.namesToKeys.set(n.name,new Set([n.key])):r.add(n.key)})}get(e){if(typeof e=="number"){const s=this.cache.get(e);return s==null?void 0:[s]}const n=this.namesToKeys.get(e);if(n==null)return;const r=[];if(n.forEach(s=>{const a=this.cache.get(s);a!=null&&r.push(a)}),r.length!==0)return r}}class Vu{mu=new QO;requests=new Map;wrapped;debouncedRun;constructor(e,n){this.wrapped=e,this.debouncedRun=Zm(()=>{this.run()},n)}async retrieve(e){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:n,variant:r}=ve(e);return r==="names"?await this.wrapped.retrieve(n):await new Promise((a,o)=>{this.mu.runExclusive(()=>{this.requests.set(n,{resolve:a,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((n,r)=>r.forEach(s=>e.add(s)));try{const n=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((r,s)=>r.resolve(n.filter(a=>s.includes(a.key))))}catch(n){this.requests.forEach(r=>r.reject(n))}finally{this.requests.clear()}})}}const Gu=async(t,e)=>{const{normalized:n}=ve(e),r=await t.retrieve(n),s=[];if(n.forEach(a=>{r.find(o=>o.name===a||o.key===a)==null&&s.push(a)}),s.length>0)throw new Ke(`Could not find channels: ${JSON.stringify(s)}`);return r},wn=i.z.uuid(),Wu=i.z.string(),ar=i.z.object({key:wn,name:Wu}),yS=J("group"),mS="sy_group_set",gS="sy_group_delete",wS=i.object({group:ar}),bS=i.object({parent:B,key:wn.optional(),name:i.string()}),vS=i.object({key:wn,name:i.string()}),zS=i.object({keys:i.array(wn)});let Ju=class{client;constructor(e){this.client=e}async create(e){return(await T(this.client,"/ontology/create-group",e,bS,wS)).group}async rename(e,n){await T(this.client,"/ontology/rename-group",{key:e,name:n},vS,i.object({}))}async delete(e){await T(this.client,"/ontology/delete-group",{keys:E.toArray(e)},zS,i.object({}))}};const TS=Object.freeze(Object.defineProperty({__proto__:null,Client:Ju,DELETE_CHANNEL_NAME:gS,SET_CHANNEL_NAME:mS,groupZ:ar,keyZ:wn,nameZ:Wu,ontologyID:yS},Symbol.toStringTag,{value:"Module"})),OS="sy_channel_set",SS="sy_channel_delete";class Fn{_frameClient;key;name;dataType;leaseholder;index;isIndex;internal;alias;virtual;expression;operations;status;constructor({dataType:e,name:n,leaseholder:r=0,key:s=0,isIndex:a=!1,index:o=0,internal:c=!1,virtual:u=!1,frameClient:l,alias:h,status:d,expression:f="",operations:b=[]}){this.key=L.parse(s),this.name=n,this.dataType=new p(e),this.leaseholder=r,this.index=L.parse(o),this.isIndex=a,this.internal=c,this.alias=h,this.virtual=u,this.expression=f,this.operations=b,d!=null&&(this.status=Qe.create(d)),this._frameClient=l??null}get framer(){if(this._frameClient==null)throw new W("cannot read from a channel that has not been created");return this._frameClient}get payload(){return _t.parse({key:this.key,name:this.name,dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal,virtual:this.virtual,expression:this.expression,status:this.status,operations:this.operations})}get isCalculated(){return yi(this.payload)}get ontologyID(){return ir(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,n){return await this.framer.write(e,this.key,n)}}const ES=i.z.object({}),NS=i.z.object({group:ar});let Ku=class{frameClient;client;retriever;writer;constructor(e,n,r,s){this.frameClient=e,this.retriever=n,this.client=r,this.writer=s}async create(e,n={}){const{retrieveIfNameExists:r=!1}=n,s=!Array.isArray(e);let a=E.toArray(e),o=[];if(r){const c=await this.retriever.retrieve(a.map(l=>l.name)),u=new Set(c.map(l=>l.name));a=a.filter(l=>!u.has(l.name)),o=this.sugar(c)}return o=o.concat(this.sugar(await this.writer.create(a))),s?o[0]:o}async retrieve(e,n){if(typeof e=="object"&&!Array.isArray(e))return this.sugar(await this.retriever.retrieve(e));const r=!Array.isArray(e),s=this.sugar(await this.retriever.retrieve(e,n));return ue("channel",e,s,r),r?s[0]:s}async delete(e){const{normalized:n,variant:r}=ve(e);return r==="keys"?await this.writer.delete({keys:n}):await this.writer.delete({names:n})}async rename(e,n){return await this.writer.rename(E.toArray(e),E.toArray(n))}createDebouncedBatchRetriever(e=10){return new pi(new Vu(new di(this.client),e))}sugar(e){const{frameClient:n}=this;return Array.isArray(e)?e.map(r=>new Fn({...r,frameClient:n})):new Fn({...e,frameClient:n})}async retrieveGroup(){return(await T(this.client,"/channel/retrieve-group",{},ES,NS)).group}};const yi=({virtual:t,expression:e})=>t&&e!=="",$S=i.z.object({channels:Lu.array()}),kS=i.z.object({channels:_t.array()}),AS=i.z.object({keys:L.array().optional(),names:Pe.array().optional()}),IS=i.z.object({}),ZS=i.z.object({keys:L.array(),names:Pe.array()}),xS=i.z.object({});let Xu=class{client;cache;constructor(e,n){this.client=e,this.cache=n}async create(e){const{channels:n}=await T(this.client,"/channel/create",{channels:e.map(r=>({...r,dataType:r.dataType}))},$S,kS);return this.cache.set(n),n}async delete(e){const n=L.array().parse(e.keys??[]);await T(this.client,"/channel/delete",e,AS,IS),n.length>0&&this.cache.delete(n),e.names!=null&&this.cache.delete(e.names)}async rename(e,n){await T(this.client,"/channel/rename",{keys:e,names:n},ZS,xS),this.cache.rename(e,n)}};const CS=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:pi,Channel:Fn,Client:Ku,ClusterRetriever:di,DELETE_CHANNEL_NAME:SS,DebouncedBatchRetriever:Vu,OPERATION_TYPES:Ru,SET_CHANNEL_NAME:OS,TYPE_ONTOLOGY_ID:FO,Writer:Xu,analyzeParams:ve,calculationStatusDetailsZ:Pu,calculationStatusZ:BO,escapeInvalidName:VO,isCalculated:yi,keyZ:L,nameZ:Pe,newZ:Lu,ontologyID:ir,operationType:ju,operationZ:hi,paramsZ:mt,payloadZ:_t,retrieveRequired:Gu,statusKey:qO,statusZ:Uu},Symbol.toStringTag,{value:"Module"})),_S=i.z.object({username:i.z.string(),password:i.z.string()}),MS=i.z.object({token:i.z.string(),user:pn}),Oa="/auth/login",RS=3,jS=i.z.object({username:i.z.string(),password:i.z.string(),newPassword:i.z.string().min(1)}),US=i.z.object({}),PS=[cs,us];let LS=class{client;credentials;authState={authenticated:!1};authenticating;retryCount;constructor(e,n){this.client=e,this.credentials=n,this.retryCount=0}get authenticated(){return this.authState.authenticated}get user(){return this.authState.authenticated?this.authState.user:void 0}get token(){return this.authState.authenticated?this.authState.token:void 0}async retrieveUser(){this.authState.authenticated||await this.authenticating;const{authState:e}=this;if(!e.authenticated)throw new Error("Authentication failed: user not available");return e.user}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await T(this.client,"/auth/change-password",{username:this.credentials.username,password:this.credentials.password,newPassword:e},jS,US),this.credentials.password=e}middleware(){const e=async(n,r)=>{if(!this.authenticated&&!n.target.endsWith(Oa)){this.authenticating??=new Promise((c,u)=>{this.client.send(Oa,this.credentials,_S,MS).then(([l,h])=>{if(h!=null)return c(h);if(l==null)return c(new Error("No response from login"));this.authState={authenticated:!0,user:l.user,token:l.token},c(null)}).catch(u)});const o=await this.authenticating;if(o!=null)return[n,o]}n.params.Authorization=`Bearer ${this.token}`;const[s,a]=await r(n);return PS.some(o=>o.matches(a))&&this.retryCount<RS?(this.authState={authenticated:!1},this.authenticating=void 0,this.retryCount+=1,e(n,r)):(this.retryCount=0,[s,a])};return e}};const Qu=i.z.enum(["disconnected","connecting","connected","failed"]),el=i.z.object({status:Qu,error:i.z.instanceof(Error).optional(),message:i.z.string().optional(),clusterKey:i.z.string(),clientVersion:i.z.string(),clientServerCompatible:i.z.boolean(),nodeVersion:i.z.string().optional()}),DS=i.z.object({clusterKey:i.z.string(),nodeVersion:i.z.string().optional()}),BS=i.z.void(),Sa={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.53.1"},Ea=(t,e,n)=>{const r=n?"Core":"client";return`Synnax Core version ${t!=null?`${t} `:""}is too ${n?"old":"new"} for client version ${e}.
|
|
59
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Ng(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(a[e.defId]=e.def)}e.external||Object.keys(a).length>0&&(e.target===`draft-2020-12`?i.$defs=a:i.definitions=a);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:Fg(t,`input`,e.processors),output:Fg(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function q(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return q(r.element,n);if(r.type===`set`)return q(r.valueType,n);if(r.type===`lazy`)return q(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type===`default`||r.type===`prefault`)return q(r.innerType,n);if(r.type===`intersection`)return q(r.left,n)||q(r.right,n);if(r.type===`record`||r.type===`map`)return q(r.keyType,n)||q(r.valueType,n);if(r.type===`pipe`)return q(r.in,n)||q(r.out,n);if(r.type===`object`){for(let e in r.shape)if(q(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(q(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(q(e,n))return!0;return!!(r.rest&&q(r.rest,n))}return!1}var Pg=(e,t={})=>n=>{let r=jg({...n,processors:t});return K(e,r),Mg(r,e),Ng(r,e)},Fg=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=jg({...i??{},target:a,io:t,processors:n});return K(e,o),Mg(o,e),Ng(o,e)},Ig={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Lg=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Ig[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Rg=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`,typeof u==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u),typeof a==`number`&&(i.minimum=a,typeof u==`number`&&t.target!==`draft-04`&&(u>=a?delete i.minimum:delete i.exclusiveMinimum)),typeof l==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l),typeof o==`number`&&(i.maximum=o,typeof l==`number`&&t.target!==`draft-04`&&(l<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c==`number`&&(i.multipleOf=c)},zg=(e,t,n,r)=>{n.type=`boolean`},Bg=(e,t,n,r)=>{n.not={}},Vg=(e,t,n,r)=>{let i=e._zod.def,a=Tf(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Hg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},Ug=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Wg=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=K(a.element,t,{...r,path:[...r.path,`items`]})},Gg=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=K(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=K(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Kg=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>K(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},qg=(e,t,n,r)=>{let i=e._zod.def,a=K(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=K(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Jg=(e,t,n,r)=>{let i=e._zod.def,a=K(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Yg=(e,t,n,r)=>{let i=e._zod.def;K(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Xg=(e,t,n,r)=>{let i=e._zod.def;K(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Zg=(e,t,n,r)=>{let i=e._zod.def;K(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Qg=(e,t,n,r)=>{let i=e._zod.def;K(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},$g=(e,t,n,r)=>{let i=e._zod.def,a=t.io===`input`?i.in._zod.def.type===`transform`?i.out:i.in:i.out;K(a,t,r);let o=t.seen.get(e);o.ref=a},e_=(e,t,n,r)=>{let i=e._zod.def;K(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},t_=(e,t,n,r)=>{let i=e._zod.def;K(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},n_=B(`ZodISODateTime`,(e,t)=>{Am.init(e,t),Y.init(e,t)});function r_(e){return $h(n_,e)}var i_=B(`ZodISODate`,(e,t)=>{jm.init(e,t),Y.init(e,t)});function a_(e){return eg(i_,e)}var o_=B(`ZodISOTime`,(e,t)=>{Mm.init(e,t),Y.init(e,t)});function s_(e){return tg(o_,e)}var c_=B(`ZodISODuration`,(e,t)=>{Nm.init(e,t),Y.init(e,t)});function l_(e){return ng(c_,e)}var u_=(e,t)=>{op.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>lp(e,t)},flatten:{value:t=>cp(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Ef,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Ef,2)}},isEmpty:{get(){return e.issues.length===0}}})};B(`ZodError`,u_);var d_=B(`ZodError`,u_,{Parent:Error}),f_=up(d_),p_=dp(d_),m_=fp(d_),h_=mp(d_),g_=gp(d_),__=_p(d_),v_=vp(d_),y_=yp(d_),b_=bp(d_),x_=xp(d_),S_=Sp(d_),C_=Cp(d_),J=B(`ZodType`,(e,t)=>(W.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:Fg(e,`input`),output:Fg(e,`output`)}}),e.toJSONSchema=Pg(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone(Nf(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>Uf(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>f_(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>m_(e,t,n),e.parseAsync=async(t,n)=>p_(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>h_(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>g_(e,t,n),e.decode=(t,n)=>__(e,t,n),e.encodeAsync=async(t,n)=>v_(e,t,n),e.decodeAsync=async(t,n)=>y_(e,t,n),e.safeEncode=(t,n)=>b_(e,t,n),e.safeDecode=(t,n)=>x_(e,t,n),e.safeEncodeAsync=async(t,n)=>S_(e,t,n),e.safeDecodeAsync=async(t,n)=>C_(e,t,n),e.refine=(t,n)=>e.check(Mv(t,n)),e.superRefine=t=>e.check(Nv(t)),e.overwrite=t=>e.check(xg(t)),e.optional=()=>mv(e),e.exactOptional=()=>gv(e),e.nullable=()=>vv(e),e.nullish=()=>mv(vv(e)),e.nonoptional=t=>wv(e,t),e.array=()=>nv(e),e.or=t=>ov([e,t]),e.and=t=>cv(e,t),e.transform=t=>Ov(e,fv(t)),e.default=t=>bv(e,t),e.prefault=t=>Sv(e,t),e.catch=t=>Ev(e,t),e.pipe=t=>Ov(e,t),e.readonly=()=>Av(e),e.describe=t=>{let n=e.clone();return kh.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return kh.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return kh.get(e);let n=e.clone();return kh.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),w_=B(`_ZodString`,(e,t)=>{vm.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lg(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(hg(...t)),e.includes=(...t)=>e.check(vg(...t)),e.startsWith=(...t)=>e.check(yg(...t)),e.endsWith=(...t)=>e.check(bg(...t)),e.min=(...t)=>e.check(pg(...t)),e.max=(...t)=>e.check(fg(...t)),e.length=(...t)=>e.check(mg(...t)),e.nonempty=(...t)=>e.check(pg(1,...t)),e.lowercase=t=>e.check(gg(t)),e.uppercase=t=>e.check(_g(t)),e.trim=()=>e.check(Cg()),e.normalize=(...t)=>e.check(Sg(...t)),e.toLowerCase=()=>e.check(wg()),e.toUpperCase=()=>e.check(Tg()),e.slugify=()=>e.check(Eg())}),T_=B(`ZodString`,(e,t)=>{vm.init(e,t),w_.init(e,t),e.email=t=>e.check(jh(D_,t)),e.url=t=>e.check(Lh(A_,t)),e.jwt=t=>e.check(Qh(G_,t)),e.emoji=t=>e.check(Rh(j_,t)),e.guid=t=>e.check(Mh(O_,t)),e.uuid=t=>e.check(Nh(k_,t)),e.uuidv4=t=>e.check(Ph(k_,t)),e.uuidv6=t=>e.check(Fh(k_,t)),e.uuidv7=t=>e.check(Ih(k_,t)),e.nanoid=t=>e.check(zh(M_,t)),e.guid=t=>e.check(Mh(O_,t)),e.cuid=t=>e.check(Bh(N_,t)),e.cuid2=t=>e.check(Vh(P_,t)),e.ulid=t=>e.check(Hh(F_,t)),e.base64=t=>e.check(Yh(H_,t)),e.base64url=t=>e.check(Xh(U_,t)),e.xid=t=>e.check(Uh(I_,t)),e.ksuid=t=>e.check(Wh(L_,t)),e.ipv4=t=>e.check(Gh(R_,t)),e.ipv6=t=>e.check(Kh(z_,t)),e.cidrv4=t=>e.check(qh(B_,t)),e.cidrv6=t=>e.check(Jh(V_,t)),e.e164=t=>e.check(Zh(W_,t)),e.datetime=t=>e.check(r_(t)),e.date=t=>e.check(a_(t)),e.time=t=>e.check(s_(t)),e.duration=t=>e.check(l_(t))});function E_(e){return Ah(T_,e)}var Y=B(`ZodStringFormat`,(e,t)=>{G.init(e,t),w_.init(e,t)}),D_=B(`ZodEmail`,(e,t)=>{xm.init(e,t),Y.init(e,t)}),O_=B(`ZodGUID`,(e,t)=>{ym.init(e,t),Y.init(e,t)}),k_=B(`ZodUUID`,(e,t)=>{bm.init(e,t),Y.init(e,t)}),A_=B(`ZodURL`,(e,t)=>{Sm.init(e,t),Y.init(e,t)}),j_=B(`ZodEmoji`,(e,t)=>{Cm.init(e,t),Y.init(e,t)}),M_=B(`ZodNanoID`,(e,t)=>{wm.init(e,t),Y.init(e,t)}),N_=B(`ZodCUID`,(e,t)=>{Tm.init(e,t),Y.init(e,t)}),P_=B(`ZodCUID2`,(e,t)=>{Em.init(e,t),Y.init(e,t)}),F_=B(`ZodULID`,(e,t)=>{Dm.init(e,t),Y.init(e,t)}),I_=B(`ZodXID`,(e,t)=>{Om.init(e,t),Y.init(e,t)}),L_=B(`ZodKSUID`,(e,t)=>{km.init(e,t),Y.init(e,t)}),R_=B(`ZodIPv4`,(e,t)=>{Pm.init(e,t),Y.init(e,t)}),z_=B(`ZodIPv6`,(e,t)=>{Fm.init(e,t),Y.init(e,t)}),B_=B(`ZodCIDRv4`,(e,t)=>{Im.init(e,t),Y.init(e,t)}),V_=B(`ZodCIDRv6`,(e,t)=>{Lm.init(e,t),Y.init(e,t)}),H_=B(`ZodBase64`,(e,t)=>{zm.init(e,t),Y.init(e,t)}),U_=B(`ZodBase64URL`,(e,t)=>{Vm.init(e,t),Y.init(e,t)}),W_=B(`ZodE164`,(e,t)=>{Hm.init(e,t),Y.init(e,t)}),G_=B(`ZodJWT`,(e,t)=>{Wm.init(e,t),Y.init(e,t)}),K_=B(`ZodNumber`,(e,t)=>{Gm.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Rg(e,t,n,r),e.gt=(t,n)=>e.check(lg(t,n)),e.gte=(t,n)=>e.check(ug(t,n)),e.min=(t,n)=>e.check(ug(t,n)),e.lt=(t,n)=>e.check(sg(t,n)),e.lte=(t,n)=>e.check(cg(t,n)),e.max=(t,n)=>e.check(cg(t,n)),e.int=t=>e.check(J_(t)),e.safe=t=>e.check(J_(t)),e.positive=t=>e.check(lg(0,t)),e.nonnegative=t=>e.check(ug(0,t)),e.negative=t=>e.check(sg(0,t)),e.nonpositive=t=>e.check(cg(0,t)),e.multipleOf=(t,n)=>e.check(dg(t,n)),e.step=(t,n)=>e.check(dg(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null}),q_=B(`ZodNumberFormat`,(e,t)=>{Km.init(e,t),K_.init(e,t)});function J_(e){return rg(q_,e)}var Y_=B(`ZodBoolean`,(e,t)=>{qm.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zg(e,t,n,r)});function X_(e){return ig(Y_,e)}var Z_=B(`ZodUnknown`,(e,t)=>{Jm.init(e,t),J.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Q_(){return ag(Z_)}var $_=B(`ZodNever`,(e,t)=>{Ym.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bg(e,t,n,r)});function ev(e){return og($_,e)}var tv=B(`ZodArray`,(e,t)=>{Zm.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wg(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(pg(t,n)),e.nonempty=t=>e.check(pg(1,t)),e.max=(t,n)=>e.check(fg(t,n)),e.length=(t,n)=>e.check(mg(t,n)),e.unwrap=()=>e.element});function nv(e,t){return Dg(tv,e,t)}var rv=B(`ZodObject`,(e,t)=>{nh.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gg(e,t,n,r),V(e,`shape`,()=>t.shape),e.keyof=()=>uv(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Q_()}),e.loose=()=>e.clone({...e._zod.def,catchall:Q_()}),e.strict=()=>e.clone({...e._zod.def,catchall:ev()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Jf(e,t),e.safeExtend=t=>Yf(e,t),e.merge=t=>Xf(e,t),e.pick=t=>Kf(e,t),e.omit=t=>qf(e,t),e.partial=(...t)=>Zf(pv,e,t[0]),e.required=(...t)=>Qf(Cv,e,t[0])});function iv(e,t){return new rv({type:`object`,shape:e??{},...H(t)})}var av=B(`ZodUnion`,(e,t)=>{ih.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Kg(e,t,n,r),e.options=t.options});function ov(e,t){return new av({type:`union`,options:e,...H(t)})}var sv=B(`ZodIntersection`,(e,t)=>{ah.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qg(e,t,n,r)});function cv(e,t){return new sv({type:`intersection`,left:e,right:t})}var lv=B(`ZodEnum`,(e,t)=>{ch.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vg(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new lv({...t,checks:[],...H(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new lv({...t,checks:[],...H(r),entries:i})}});function uv(e,t){return new lv({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...H(t)})}var dv=B(`ZodTransform`,(e,t)=>{lh.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ug(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Sf(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(ip(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(ip(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function fv(e){return new dv({type:`transform`,transform:e})}var pv=B(`ZodOptional`,(e,t)=>{dh.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>t_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function mv(e){return new pv({type:`optional`,innerType:e})}var hv=B(`ZodExactOptional`,(e,t)=>{fh.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>t_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function gv(e){return new hv({type:`optional`,innerType:e})}var _v=B(`ZodNullable`,(e,t)=>{ph.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function vv(e){return new _v({type:`nullable`,innerType:e})}var yv=B(`ZodDefault`,(e,t)=>{mh.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function bv(e,t){return new yv({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Bf(t)}})}var xv=B(`ZodPrefault`,(e,t)=>{gh.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Sv(e,t){return new xv({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Bf(t)}})}var Cv=B(`ZodNonOptional`,(e,t)=>{_h.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function wv(e,t){return new Cv({type:`nonoptional`,innerType:e,...H(t)})}var Tv=B(`ZodCatch`,(e,t)=>{yh.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Ev(e,t){return new Tv({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}var Dv=B(`ZodPipe`,(e,t)=>{bh.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$g(e,t,n,r),e.in=t.in,e.out=t.out});function Ov(e,t){return new Dv({type:`pipe`,in:e,out:t})}var kv=B(`ZodReadonly`,(e,t)=>{Sh.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>e_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Av(e){return new kv({type:`readonly`,innerType:e})}var jv=B(`ZodCustom`,(e,t)=>{wh.init(e,t),J.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hg(e,t,n,r)});function Mv(e,t={}){return Og(jv,e,t)}function Nv(e){return kg(e)}var Pv=function(e){return e[e.invalid=0]=`invalid`,e[e.u8=1]=`u8`,e[e.u16=2]=`u16`,e[e.u32=3]=`u32`,e[e.u64=4]=`u64`,e[e.i8=5]=`i8`,e[e.i16=6]=`i16`,e[e.i32=7]=`i32`,e[e.i64=8]=`i64`,e[e.f32=9]=`f32`,e[e.f64=10]=`f64`,e[e.string=11]=`string`,e[e.chan=14]=`chan`,e[e.series=15]=`series`,e[e.variable=16]=`variable`,e[e.numeric_constant=17]=`numeric_constant`,e[e.integer_constant=18]=`integer_constant`,e[e.float_constant=19]=`float_constant`,e[e.exact_integer_float_constant=20]=`exact_integer_float_constant`,e[e.function=21]=`function`,e[e.sequence=22]=`sequence`,e[e.stage=23]=`stage`,e}({}),Fv=l.z.enum(Pv),Iv=function(e){return e[e.none=0]=`none`,e[e.read=1]=`read`,e[e.write=2]=`write`,e}({}),Lv=l.z.enum(Iv),Rv=l.z.object({read:l.z.record(l.z.uint32(),l.z.string()),write:l.z.record(l.z.uint32(),l.z.string())}),zv=l.z.object({length:N.int8,mass:N.int8,time:N.int8,current:N.int8,temperature:N.int8,angle:N.int8,count:N.int8,data:N.int8}),Bv=l.z.object({dimensions:zv,scale:l.z.number(),name:l.z.string()}),Vv=l.z.object({get inputs(){return Uv.optional()},get outputs(){return Uv.optional()},get config(){return Uv.optional()}}).extend({kind:Fv,name:l.z.string(),get elem(){return Vv.optional()},unit:Bv.optional(),get constraint(){return Vv.optional()},chanDirection:Lv.optional()}),Hv=l.z.object({name:l.z.string(),type:Vv,value:l.z.unknown().optional()}),Uv=w.nullishToEmpty(Hv),Wv=o({EdgeKind:()=>Gv,authoritiesZ:()=>Xv,bodyZ:()=>Jv,edgeKindZ:()=>Kv,edgeZ:()=>Qv,edgesZ:()=>ny,functionZ:()=>$v,functionsZ:()=>ry,handleZ:()=>qv,irZ:()=>cy,nodeZ:()=>Yv,nodesZ:()=>ey,sequenceZ:()=>ay,sequencesZ:()=>sy,stageZ:()=>iy,stagesZ:()=>oy,strataZ:()=>ty,stratumZ:()=>Zv}),Gv=function(e){return e[e.unspecified=0]=`unspecified`,e[e.continuous=1]=`continuous`,e[e.one_shot=2]=`one_shot`,e}({}),Kv=l.z.enum(Gv),qv=l.z.object({node:l.z.string(),param:l.z.string()}),Jv=l.z.object({raw:l.z.string()}),Yv=l.z.object({key:l.z.string(),type:l.z.string(),config:Uv.optional(),inputs:Uv.optional(),outputs:Uv.optional(),channels:Rv.optional()}),Xv=l.z.object({default:N.uint8.optional(),channels:l.z.record(l.z.uint32(),N.uint8).optional()}),Zv=w.nullishToEmpty(l.z.string()),Qv=l.z.object({source:qv,target:qv,kind:Kv.optional()}),$v=l.z.object({key:l.z.string(),body:Jv.optional(),config:Uv.optional(),inputs:Uv.optional(),outputs:Uv.optional(),channels:Rv.optional()}),ey=w.nullishToEmpty(Yv),ty=w.nullishToEmpty(Zv),ny=w.nullishToEmpty(Qv),ry=w.nullishToEmpty($v),iy=l.z.object({key:l.z.string(),nodes:w.nullishToEmpty(l.z.string()),strata:ty}),ay=l.z.object({key:l.z.string(),stages:w.nullishToEmpty(iy)}),oy=w.nullishToEmpty(iy),sy=w.nullishToEmpty(ay),cy=l.z.object({functions:ry.optional(),nodes:ey.optional(),edges:ny.optional(),strata:ty.optional(),sequences:sy.optional(),authorities:Xv.optional()}),ly=o({graphZ:()=>py,nodeZ:()=>uy,nodesZ:()=>fy,viewportZ:()=>dy}),uy=l.z.object({key:l.z.string(),type:l.z.string(),config:I.nullishToEmpty(),position:xo.xyZ}),dy=l.z.object({position:xo.xyZ,zoom:l.z.number()}),fy=w.nullishToEmpty(uy),py=l.z.object({viewport:dy,functions:ry,edges:ny,nodes:fy}),my=o({outputZ:()=>hy}),hy=l.z.object({wasm:l.z.instanceof(Uint8Array),outputMemoryBases:l.z.record(l.z.string(),l.z.uint32())}),gy=cy.extend(hy.shape),_y=o({textZ:()=>vy}),vy=l.z.object({raw:l.z.string()}),yy=[`text`,`graph`],by=l.z.enum(yy),xy=l.z.object({running:l.z.boolean()}),Sy=l.z.uuid(),Cy=cu.statusZ({details:xy}),wy=l.z.object({key:Sy.optional(),name:l.z.string(),mode:by,graph:py,text:vy}),Ty=l.z.object({key:Sy,name:l.z.string(),mode:by,graph:py,text:vy,program:gy.optional(),status:Cy.optional()}),Ey=z(`arc`),Dy=Ey(``),Oy=(e,t,{convertNumericStrings:n=!0}={})=>{let r=!Array.isArray(e),i=w.toArray(e),a=i[0],o=typeof a,s;return o===`string`&&n&&!isNaN(parseInt(a,10))&&`number`in t?(s=t.number,i=i.map(e=>parseInt(e,10))):s=t[o],{single:r,variant:s,normalized:i,actual:e}},X=(e,t,n,r)=>{if(r){if(n.length===0)throw new Eu(`${e} not found matching ${JSON.stringify(t)}`);if(n.length>1)throw new Du(`Expected one ${e} matching ${JSON.stringify(t)}, but found ${n.length}`)}},ky=`sy_arc_set`,Ay=`sy_arc_delete`,jy=iv({keys:Sy.array().optional(),names:E_().array().optional(),searchTerm:E_().optional(),limit:J_().optional(),offset:J_().optional(),includeStatus:X_().optional()}),My=iv({arcs:wy.array()}),Ny=iv({keys:Sy.array()}),Py=iv({arcs:w.nullishToEmpty(Ty)}),Fy=iv({arcs:Ty.array()}),Iy=iv({}),Ly=iv({content:E_()}),Ry=ov([iv({key:Sy,includeStatus:X_().optional()}).transform(({key:e,includeStatus:t})=>({keys:[e],includeStatus:t})),iv({name:E_(),includeStatus:X_().optional()}).transform(({name:e,includeStatus:t})=>({names:[e],includeStatus:t}))]),zy=ov([Ry,jy]),By=class{client;streamClient;constructor(e,t){this.client=e,this.streamClient=t}async create(e){let t=Array.isArray(e),n=await S(this.client,`/arc/create`,{arcs:w.toArray(e)},My,Fy);return t?n.arcs:n.arcs[0]}async retrieve(e){let t=`key`in e||`name`in e,n=await S(this.client,`/arc/retrieve`,e,zy,Py);return X(`Arc`,e,n.arcs,t),t?n.arcs[0]:n.arcs}async delete(e){await S(this.client,`/arc/delete`,{keys:w.toArray(e)},Ny,Iy)}async openLSP(){return await this.streamClient.stream(`/arc/lsp`,Ly,Ly)}},Vy=o({moduleZ:()=>Hy}),Hy=cy.extend(hy.shape),Uy=o({Client:()=>By,DELETE_CHANNEL_NAME:()=>Ay,MODES:()=>yy,SET_CHANNEL_NAME:()=>ky,TYPE_ONTOLOGY_ID:()=>Dy,arcZ:()=>Ty,compiler:()=>my,graph:()=>ly,ir:()=>Wv,keyZ:()=>Sy,lspMessageZ:()=>Ly,modeZ:()=>by,module:()=>Vy,newZ:()=>wy,ontologyID:()=>Ey,singleRetrieveArgsZ:()=>Ry,statusDetailsZ:()=>xy,statusZ:()=>Cy,text:()=>_y}),Wy=Error(`request for lock canceled`),Gy=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},Ky=class{constructor(e,t=Wy){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw Error(`invalid weight ${e}: must be positive`);return new Promise((n,r)=>{let i={resolve:n,reject:r,weight:e,priority:t},a=Jy(this._queue,e=>t<=e.priority);a===-1&&e<=this._value?this._dispatchItem(i):this._queue.splice(a+1,0,i)})}runExclusive(e){return Gy(this,arguments,void 0,function*(e,t=1,n=0){let[r,i]=yield this.acquire(t,n);try{return yield e(r)}finally{i()}})}waitForUnlock(e=1,t=0){if(e<=0)throw Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),qy(this._weightedWaiters[e-1],{resolve:n,priority:t})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){let t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){let t=this._weightedWaiters[e-1];t&&(t.forEach(e=>e.resolve()),this._weightedWaiters[e-1]=[])}else{let e=this._queue[0].priority;for(let t=this._value;t>0;t--){let n=this._weightedWaiters[t-1];if(!n)continue;let r=n.findIndex(t=>t.priority<=e);(r===-1?n:n.splice(0,r)).forEach((e=>e.resolve()))}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}};function qy(e,t){let n=Jy(e,e=>t.priority<=e.priority);e.splice(n+1,0,t)}function Jy(e,t){for(let n=e.length-1;n>=0;n--)if(t(e[n]))return n;return-1}var Yy=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},Xy=class{constructor(e){this._semaphore=new Ky(1,e)}acquire(){return Yy(this,arguments,void 0,function*(e=0){let[,t]=yield this._semaphore.acquire(1,e);return t})}runExclusive(e,t=0){return this._semaphore.runExclusive(()=>e(),1,t)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}},Zy=N.uint12,Z=l.z.uint32().or(l.z.string().refine(e=>!isNaN(Number(e))).transform(Number)),Qy=N.uint20,$y=[`min`,`max`,`avg`,`none`],eb=l.z.enum($y),tb=l.z.object({type:eb,resetChannel:Z.default(0),duration:us.timeSpanZ.default(O.ZERO)}),nb=l.z.string().min(1,`Name is required`),rb=cu.statusZ(),ib=l.z.object({key:Z,name:nb,leaseholder:Zy,dataType:us.dataTypeZ,isIndex:l.z.boolean(),index:Z,alias:l.z.string().optional(),virtual:l.z.boolean().default(!1),internal:l.z.boolean().default(!1),expression:l.z.string().default(``),operations:N.nullToUndefined(tb.array()),concurrency:F.concurrencyZ.default(F.Concurrency.exclusive).optional(),status:rb.optional()}),ab=ib.omit({leaseholder:!0}).partial({key:!0,index:!0,isIndex:!0,internal:!0,virtual:!0,expression:!0}).extend({leaseholder:N.uint12.optional()}),ob=z(`channel`),sb=ob(0),Q=l.z.uuid(),cb=l.z.object({key:Q,name:l.z.string().min(1),timeRange:us.timeRangeZ,color:Nc.colorZ.optional()}),lb=cb.extend({labels:N.nullToUndefined(fl.labelZ.array()),get parent(){return lb.optional()}}),ub=cb.omit({timeRange:!0}).extend({labels:N.nullToUndefined(fl.labelZ.array()),get parent(){return ub.optional()},timeRange:us.timeRangeBoundedZ}),db=ub.omit({parent:!0,labels:!0}).partial({key:!0}),fb=z(`range`),pb=fb(``),mb=l.z.object({nodeKey:N.uint12.optional(),keys:Z.array().optional(),names:l.z.string().array().optional(),searchTerm:l.z.string().optional(),rangeKey:Q.optional(),limit:l.z.int().optional(),offset:l.z.int().optional(),dataTypes:j.z.array().optional(),notDataTypes:j.z.array().optional(),virtual:l.z.boolean().optional(),isIndex:l.z.boolean().optional(),internal:l.z.boolean().optional(),legacyCalculated:l.z.boolean().optional()}),hb=l.z.object({channels:w.nullishToEmpty(ib)}),gb=e=>(Array.isArray(e)&&e.length>0&&typeof e[0]==`object`?e=e.map(e=>e.key):typeof e==`object`&&`key`in e&&(e=[e.key]),Oy(e,{number:`keys`,string:`names`})),_b=class{client;constructor(e){this.client=e}async retrieve(e,t){if(!Array.isArray(e)&&typeof e==`object`)return await this.execute(e);let n=gb(e),{variant:r}=n,{normalized:i}=n;return r===`keys`&&i.indexOf(0)!==-1&&(i=i.filter(e=>e!==0)),i.length===0?[]:await this.execute({[r]:i,...t})}async execute(e){return(await S(this.client,`/channel/retrieve`,e,mb,hb)).channels}},vb=class{cache;namesToKeys;wrapped;constructor(e){this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async retrieve(e,t){if(!Array.isArray(e)&&typeof e==`object`)return await this.wrapped.retrieve(e);let{normalized:n}=gb(e),r=[],i=[];if(n.forEach(e=>{let t=this.get(e);t==null?i.push(e):r.push(...t)}),i.length===0)return r;let a=await this.wrapped.retrieve(i,t);return this.set(a),r.concat(a)}delete(e){let{variant:t,normalized:n}=gb(e);t===`names`?n.forEach(e=>{let t=this.namesToKeys.get(e);t!=null&&(t.forEach(e=>this.cache.delete(e)),this.namesToKeys.delete(e))}):n.forEach(e=>{let t=this.cache.get(e);t!=null&&(this.cache.delete(e),this.namesToKeys.delete(t.name))})}rename(e,t){e.forEach((e,n)=>{let r=t[n],i=this.cache.get(e);if(i==null)return;this.cache.delete(e);let a=this.namesToKeys.get(i.name);a!=null&&(a.delete(e),a.size===0&&this.namesToKeys.delete(i.name)),i.name=r,this.cache.set(e,i);let o=this.namesToKeys.get(r);o==null?this.namesToKeys.set(r,new Set([e])):o.add(e)})}set(e){e.forEach(e=>{this.cache.set(e.key,e);let t=this.namesToKeys.get(e.name);t==null?this.namesToKeys.set(e.name,new Set([e.key])):t.add(e.key)})}get(e){if(typeof e==`number`){let t=this.cache.get(e);return t==null?void 0:[t]}let t=this.namesToKeys.get(e);if(t==null)return;let n=[];if(t.forEach(e=>{let t=this.cache.get(e);t!=null&&n.push(t)}),n.length!==0)return n}},yb=class{mu=new Xy;requests=new Map;wrapped;debouncedRun;constructor(e,t){this.wrapped=e,this.debouncedRun=Jc(()=>{this.run()},t)}async retrieve(e){if(!Array.isArray(e)&&typeof e==`object`)return await this.wrapped.retrieve(e);let{normalized:t,variant:n}=gb(e);return n===`names`?await this.wrapped.retrieve(t):await new Promise((e,n)=>{this.mu.runExclusive(()=>{this.requests.set(t,{resolve:e,reject:n}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{let e=new Set;this.requests.forEach((t,n)=>n.forEach(t=>e.add(t)));try{let t=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((e,n)=>e.resolve(t.filter(e=>n.includes(e.key))))}catch(e){this.requests.forEach(t=>t.reject(e))}finally{this.requests.clear()}})}},bb=async(e,t)=>{let{normalized:n}=gb(t),r=await e.retrieve(n),i=[];if(n.forEach(e=>{r.find(t=>t.name===e||t.key===e)??i.push(e)}),i.length>0)throw new Tu(`Could not find channels: ${JSON.stringify(i)}`);return r},xb=l.z.uuid(),Sb=l.z.object({key:xb,name:l.z.string()}),Cb=z(`group`),wb=Cb(``),Tb=`sy_group_set`,Eb=`sy_group_delete`,Db=l.default.object({group:Sb}),Ob=l.default.object({parent:R,key:xb.optional(),name:l.default.string()}),kb=l.default.object({key:xb,name:l.default.string()}),Ab=l.default.object({keys:l.default.array(xb)}),jb=class{client;constructor(e){this.client=e}async create(e){return(await S(this.client,`/ontology/create-group`,e,Ob,Db)).group}async rename(e,t){await S(this.client,`/ontology/rename-group`,{key:e,name:t},kb,l.default.object({}))}async delete(e){await S(this.client,`/ontology/delete-group`,{keys:w.toArray(e)},Ab,l.default.object({}))}},Mb=o({Client:()=>jb,DELETE_CHANNEL_NAME:()=>Eb,SET_CHANNEL_NAME:()=>Tb,TYPE_ONTOLOGY_ID:()=>wb,groupZ:()=>Sb,keyZ:()=>xb,ontologyID:()=>Cb}),Nb=`sy_channel_set`,Pb=`sy_channel_delete`,Fb=class{_frameClient;key;name;dataType;leaseholder;index;isIndex;internal;alias;virtual;expression;operations;status;constructor({dataType:e,name:t,leaseholder:n=0,key:r=0,isIndex:i=!1,index:a=0,internal:o=!1,virtual:s=!1,frameClient:c,alias:l,status:u,expression:d=``,operations:f=[]}){this.key=Z.parse(r),this.name=t,this.dataType=new j(e),this.leaseholder=n,this.index=Z.parse(a),this.isIndex=i,this.internal=o,this.alias=l,this.virtual=s,this.expression=d,this.operations=f,u!=null&&(this.status=cu.create(u)),this._frameClient=c??null}get framer(){if(this._frameClient==null)throw new L(`cannot read from a channel that has not been created`);return this._frameClient}get payload(){return ib.parse({key:this.key,name:this.name,dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal,virtual:this.virtual,expression:this.expression,status:this.status,operations:this.operations})}get isCalculated(){return zb(this.payload)}get ontologyID(){return ob(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,t){return await this.framer.write(e,this.key,t)}},Ib=l.z.object({}),Lb=l.z.object({group:Sb}),Rb=class{frameClient;client;retriever;writer;constructor(e,t,n,r){this.frameClient=e,this.retriever=t,this.client=n,this.writer=r}async create(e,t={}){let{retrieveIfNameExists:n=!1}=t,r=!Array.isArray(e),i=w.toArray(e),a=[];if(n){let e=await this.retriever.retrieve(i.map(e=>e.name)),t=new Set(e.map(e=>e.name));i=i.filter(e=>!t.has(e.name)),a=this.sugar(e)}return a=a.concat(this.sugar(await this.writer.create(i))),r?a[0]:a}async retrieve(e,t){if(typeof e==`object`&&!Array.isArray(e))return this.sugar(await this.retriever.retrieve(e));let n=!Array.isArray(e),r=this.sugar(await this.retriever.retrieve(e,t));return X(`channel`,e,r,n),n?r[0]:r}async delete(e){let{normalized:t,variant:n}=gb(e);return n===`keys`?await this.writer.delete({keys:t}):await this.writer.delete({names:t})}async rename(e,t){return await this.writer.rename(w.toArray(e),w.toArray(t))}createDebouncedBatchRetriever(e=10){return new vb(new yb(new _b(this.client),e))}sugar(e){let{frameClient:t}=this;return Array.isArray(e)?e.map(e=>new Fb({...e,frameClient:t})):new Fb({...e,frameClient:t})}async retrieveGroup(){return(await S(this.client,`/channel/retrieve-group`,{},Ib,Lb)).group}},zb=({virtual:e,expression:t})=>e&&t!==``,Bb=l.z.union([N.toArray(Z),N.toArray(nb),N.toArray(ib).transform(e=>e.map(e=>e.key))]),Vb=/[a-zA-Z0-9_]/,Hb=/^[a-zA-Z_][a-zA-Z0-9_]*$/,Ub=(e,t=!1)=>{if(e===``)return t?`_`:``;if(e.match(Hb))return e;let n=``;for(let t of e)t.match(Vb)?n+=t:n+=`_`;return n[0].match(/^\d/)&&(n=`_${n}`),n},Wb=e=>Ru(ob(e)),Gb=l.z.object({channels:ab.array()}),Kb=l.z.object({channels:ib.array()}),qb=l.z.object({keys:Z.array().optional(),names:nb.array().optional()}),Jb=l.z.object({}),Yb=l.z.object({keys:Z.array(),names:nb.array()}),Xb=l.z.object({}),Zb=class{client;cache;constructor(e,t){this.client=e,this.cache=t}async create(e){let{channels:t}=await S(this.client,`/channel/create`,{channels:e.map(e=>({...e,dataType:e.dataType}))},Gb,Kb);return this.cache.set(t),t}async delete(e){let t=Z.array().parse(e.keys??[]);await S(this.client,`/channel/delete`,e,qb,Jb),t.length>0&&this.cache.delete(t),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await S(this.client,`/channel/rename`,{keys:e,names:t},Yb,Xb),this.cache.rename(e,t)}},Qb=o({CacheRetriever:()=>vb,Channel:()=>Fb,Client:()=>Rb,ClusterRetriever:()=>_b,DELETE_CHANNEL_NAME:()=>Pb,DebouncedBatchRetriever:()=>yb,OPERATION_TYPES:()=>$y,SET_CHANNEL_NAME:()=>Nb,TYPE_ONTOLOGY_ID:()=>sb,Writer:()=>Zb,analyzeParams:()=>gb,escapeInvalidName:()=>Ub,isCalculated:()=>zb,keyZ:()=>Z,localKeyZ:()=>Qy,nameZ:()=>nb,newZ:()=>ab,ontologyID:()=>ob,operationTypeZ:()=>eb,operationZ:()=>tb,paramsZ:()=>Bb,payloadZ:()=>ib,retrieveRequired:()=>bb,statusKey:()=>Wb,statusZ:()=>rb}),$b=l.z.object({username:l.z.string(),password:l.z.string()}),ex=l.z.object({token:l.z.string(),user:jd}),tx=`/auth/login`,nx=3,rx=l.z.object({username:l.z.string(),password:l.z.string(),newPassword:l.z.string().min(1)}),ix=l.z.object({}),ax=[Su,Cu],ox=class{client;credentials;authState={authenticated:!1};authenticating;retryCount;constructor(e,t){this.client=e,this.credentials=t,this.retryCount=0}get authenticated(){return this.authState.authenticated}get user(){return this.authState.authenticated?this.authState.user:void 0}get token(){return this.authState.authenticated?this.authState.token:void 0}async retrieveUser(){this.authState.authenticated||await this.authenticating;let{authState:e}=this;if(!e.authenticated)throw Error(`Authentication failed: user not available`);return e.user}async changePassword(e){if(!this.authenticated)throw Error(`Not authenticated`);await S(this.client,`/auth/change-password`,{username:this.credentials.username,password:this.credentials.password,newPassword:e},rx,ix),this.credentials.password=e}middleware(){let e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(tx)){this.authenticating??=new Promise((e,t)=>{this.client.send(tx,this.credentials,$b,ex).then(([t,n])=>{if(n!=null)return e(n);if(t==null)return e(Error(`No response from login`));this.authState={authenticated:!0,user:t.user,token:t.token},e(null)}).catch(t)});let e=await this.authenticating;if(e!=null)return[t,e]}t.params.Authorization=`Bearer ${this.token}`;let[r,i]=await n(t);return ax.some(e=>e.matches(i))&&this.retryCount<nx?(this.authState={authenticated:!1},this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[r,i])};return e}},sx=o({Checker:()=>mx,stateZ:()=>lx,statusZ:()=>cx}),cx=l.z.enum([`disconnected`,`connecting`,`connected`,`failed`]),lx=l.z.object({status:cx,error:l.z.instanceof(Error).optional(),message:l.z.string().optional(),clusterKey:l.z.string(),clientVersion:l.z.string(),clientServerCompatible:l.z.boolean(),nodeVersion:l.z.string().optional()}),ux=l.z.object({clusterKey:l.z.string(),nodeVersion:l.z.string().optional()}),dx=l.z.void(),fx={clusterKey:``,status:`disconnected`,error:void 0,message:`Disconnected`,clientServerCompatible:!1,clientVersion:`0.54.0`},px=(e,t,n)=>{let r=n?`Core`:`client`;return`Synnax Core version ${e==null?``:`${e} `}is too ${n?`old`:`new`} for client version ${t}.
|
|
65
60
|
This may cause compatibility issues. We recommend updating the ${r}. For more information, see
|
|
66
|
-
https://docs.synnaxlabs.com/reference/client/resources/troubleshooting#old-${r}-version`}
|
|
67
|
-
Got ${n.length} ${r}s and ${
|
|
61
|
+
https://docs.synnaxlabs.com/reference/client/resources/troubleshooting#old-${r}-version`},mx=class{static DEFAULT=fx;_state;pollFrequency=O.seconds(30);client;name;interval;clientVersion;onChangeHandlers=[];static connectionStateZ=lx;versionWarned=!1;constructor(e,t=O.seconds(30),n,r){this._state={...fx},this.client=e,this.pollFrequency=t,this.clientVersion=n,this.name=r,this.check(),this.start()}stop(){this.interval!=null&&clearInterval(this.interval)}async check(){let e=this._state.status;try{let e=await S(this.client,`/connectivity/check`,void 0,dx,ux),t=e.nodeVersion,n=this.clientVersion,r=this.versionWarned;t==null?(this._state.clientServerCompatible=!1,r||(console.warn(px(null,n,!0)),this.versionWarned=!0)):gl.versionsEqual(n,t,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,r||(console.warn(px(t,n,gl.semVerNewer(n,t))),this.versionWarned=!0)),this._state.status=`connected`,this._state.message=`Connected to ${this.name??`cluster`}`,this._state.clusterKey=e.clusterKey,this._state.nodeVersion=e.nodeVersion,this._state.clientVersion=this.clientVersion}catch(e){this._state.status=`failed`,this._state.error=e,this._state.message=this.state.error?.message}return this.onChangeHandlers.length>0&&e!==this._state.status&&this.onChangeHandlers.forEach(e=>e(this.state)),this.state}get state(){return{...this._state}}onChange(e){this.onChangeHandlers.push(e)}start(){this.interval=setInterval(()=>{this.check()},this.pollFrequency.milliseconds)}},hx=l.z.object({keys:Z.array().optional(),bounds:A.z,names:nb.array().optional()}),gx=l.z.object({}),_x=class{client;constructor(e){this.client=e}async delete(e){await S(this.client,`/frame/delete`,e,hx,gx)}},vx=e=>{let t=w.toArray(e);return t.length===0?null:typeof t[0]==`number`||!isNaN(parseInt(t[0],10))?`key`:`name`},yx=(e,t)=>{let n=w.toArray(e);if(n.length===t.length)return;let r=vx(e);throw r===null?new L(`[Frame] - channel keys or names must be provided when constructing a frame.`):new L(`[Frame] - ${r}s and series must be the same length.
|
|
62
|
+
Got ${n.length} ${r}s and ${t.length} series.`)},$=class e{columns=[];series=[];constructor(t=[],n=[]){if(t instanceof e){this.columns=t.columns,this.series=t.series;return}if(t instanceof Map){t.forEach((e,t)=>this.push(t,...w.toArray(e)));return}if(typeof t==`object`&&!Array.isArray(t)){if(`keys`in t&&`series`in t){let e=t;e.series??=[],e.keys??=[];let n=e.series.map(e=>xx(e));yx(e.keys,n),e.keys.forEach((e,t)=>this.push(e,n[t]))}else Object.entries(t).forEach(([e,t])=>{let n=parseInt(e,10);if(!isNaN(n))return this.push(n,...w.toArray(t));this.push(e,...w.toArray(t))});return}if(Array.isArray(t)||[`string`,`number`].includes(typeof t)){let e=w.toArray(n),r=w.toArray(t);yx(r,e),e.forEach((e,t)=>this.push(r[t],e));return}throw new L(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
|
|
68
63
|
payload, a list of lazy series, a lazy array, a map, or a record keyed by channel
|
|
69
|
-
name. keys parameter must be a set of channel keys or channel names.`)}get colType(){return this.columns.length===0?null:typeof this.columns[0]
|
|
70
|
-
`;return this.uniqueColumns.forEach(
|
|
71
|
-
`}),e+="}",e}}const or=i.z.object({keys:i.z.union([i.z.null().transform(()=>[]),i.z.number().array().default([])]),series:i.z.union([i.z.null().transform(()=>[]),te.crudeZ.array().default([])])}),tl=t=>{const{dataType:e,data:n,timeRange:r,alignment:s}=t;return new te({data:n,dataType:e,timeRange:r,glBufferUsage:"static",alignment:s})},nl=t=>({timeRange:t.timeRange,dataType:t.dataType,data:new Uint8Array(t.data.buffer),alignment:t.alignment});var $e=(t=>(t[t.Open=0]="Open",t[t.Write=1]="Write",t[t.Commit=2]="Commit",t[t.SetAuthority=3]="SetAuthority",t))($e||{});const ka=t=>t.data.byteLength/t.dataType.density.valueOf(),VS=t=>{const{keys:e,series:n}=t;e.forEach((r,s)=>{n[s].key=r}),n.sort((r,s)=>r.key-s.key),e.sort((r,s)=>r-s),n.forEach(r=>delete r.key)},Aa=5,Ia=4,Za=3,xa=2,Ca=1,_a=0,Oe=p.TIMESTAMP.density.valueOf(),Fe=8,Ye=4,_r=4,Mr=4,GS=1;class rl{contentType="application/sy-framer";states=new Map;currState;seqNum=0;constructor(e=[],n=[]){(e.length>0||n.length>0)&&this.update(e,n)}update(e,n){this.seqNum++;const r={keys:e,keyDataTypes:new Map,hasVariableDataTypes:!1};e.forEach((s,a)=>{const o=n[a];r.keyDataTypes.set(s,o),o.isVariable&&(r.hasVariableDataTypes=!0)}),r.keys.sort(),this.states.set(this.seqNum,r),this.currState=r}throwIfNotUpdated(e){if(this.seqNum<1)throw new W(`
|
|
64
|
+
name. keys parameter must be a set of channel keys or channel names.`)}get colType(){return this.columns.length===0?null:typeof this.columns[0]==`string`?`name`:`key`}get keys(){if(this.colType===`name`)throw new wu(`colType is not key`);return this.columns??[]}get uniqueKeys(){return vi.unique(this.keys)}get names(){if(this.colType===`key`)throw new wu(`colType is not name`);return this.columns??[]}get uniqueNames(){return vi.unique(this.names)}get uniqueColumns(){return this.colType===`key`?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>Sx(e)),keys:[...this.keys]}}get isVertical(){return this.uniqueColumns.length===this.columns.length}get isHorizontal(){return this.uniqueColumns.length===1}get isSquare(){return this.isHorizontal&&this.isVertical}get isWeaklyAligned(){if(this.columns.length<=1)return!0;let e=this.timeRanges;return e.every(t=>t.equals(e[0]))}timeRange(e){if(e==null)return this.columns.length===0?A.ZERO:new A(D.min(...this.series.map(e=>e.timeRange.start)),D.max(...this.series.map(e=>e.timeRange.end)));let t=this.get(e);return t==null?A.ZERO:t.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(t=>e.includes(t)):new os(this.series.filter((t,n)=>this.columns[n]===e))}push(t,...n){if(t instanceof e){if(t.colType!=null&&this.colType!==null&&t.colType!==this.colType)throw new L(`keyVariant must match`);this.series.push(...t.series),this.columns.push(...t.columns)}else{if(this.series.push(...n),typeof t==`string`&&this.colType===`key`||typeof t!=`string`&&this.colType===`name`)throw new L(`keyVariant must match`);this.columns.push(...Array.from({length:n.length},()=>t))}}concat(t){return new e([...this.columns,...t.columns],[...this.series,...t.series])}has(e){return typeof e==`string`&&this.colType===`key`||typeof e==`number`&&this.colType===`name`?!1:this.columns.includes(e)}map(t){let n=new e;return this.forEach((e,r,i)=>n.push(...t(e,r,i))),n}mapFilter(t){let n=new e;return this.forEach((e,r,i)=>{let[a,o,s]=t(e,r,i);s&&n.push(a,o)}),n}forEach(e){this.columns.forEach((t,n)=>{let r=this.series[n];e(t,r,n)})}forEachUnique(e){this.uniqueColumns.forEach((t,n)=>e(t,this.get(t),n))}at(e,t=!1){let n={};return this.uniqueColumns.forEach(r=>{n[r]=this.get(r).at(e,t)}),n}filter(t){let n=new e;return this.columns.forEach((e,r)=>{let i=this.series[r];t(e,i,r)&&n.push(e,i)}),n}get byteLength(){return new Oo(this.series.reduce((e,t)=>e.add(t.byteLength),Oo.ZERO))}get digest(){let e={};return this.keys.forEach((t,n)=>{let r=this.series[n].digest;t in e?e[t].push(r):e[t]=[r]}),e}get length(){return this.series.reduce((e,t)=>e+t.length,0)}toString(){let e=`Frame{
|
|
65
|
+
`;return this.uniqueColumns.forEach(t=>{e+=` ${t}: ${this.get(t).series.map(e=>e.toString()).join(`,`)}\n`}),e+=`}`,e}},bx=l.z.object({keys:l.z.union([l.z.null().transform(()=>[]),l.z.number().array().default([])]),series:l.z.union([l.z.null().transform(()=>[]),Qo.crudeZ.array().default([])])}),xx=e=>{let{dataType:t,data:n,timeRange:r,alignment:i}=e;return new Qo({data:n,dataType:t,timeRange:r,glBufferUsage:`static`,alignment:i})},Sx=e=>({timeRange:e.timeRange,dataType:e.dataType,data:new Uint8Array(e.data.buffer),alignment:e.alignment}),Cx=function(e){return e[e.Open=0]=`Open`,e[e.Write=1]=`Write`,e[e.Commit=2]=`Commit`,e[e.SetAuthority=3]=`SetAuthority`,e}({}),wx=l.z.enum(Cx),Tx=e=>e.data.byteLength/e.dataType.density.valueOf(),Ex=e=>{let{keys:t,series:n}=e;t.forEach((e,t)=>{n[t].key=e}),n.sort((e,t)=>e.key-t.key),t.sort((e,t)=>e-t),n.forEach(e=>delete e.key)},Dx=5,Ox=4,kx=3,Ax=2,jx=1,Mx=0,Nx=j.TIMESTAMP.density.valueOf(),Px=8,Fx=4,Ix=4,Lx=4,Rx=1,zx=class{contentType=`application/sy-framer`;states=new Map;currState;seqNum=0;constructor(e=[],t=[]){(e.length>0||t.length>0)&&this.update(e,t)}update(e,t){this.seqNum++;let n={keys:e,keyDataTypes:new Map,hasVariableDataTypes:!1};e.forEach((e,r)=>{let i=t[r];n.keyDataTypes.set(e,i),i.isVariable&&(n.hasVariableDataTypes=!0)}),n.keys.sort(),this.states.set(this.seqNum,n),this.currState=n}throwIfNotUpdated(e){if(this.seqNum<1)throw new L(`
|
|
72
66
|
The codec has not been updated with a list of channels and data types.
|
|
73
67
|
Please call the update method before calling ${e}.
|
|
74
|
-
`)}encode(e,
|
|
68
|
+
`)}encode(e,t=0){this.throwIfNotUpdated(`encode`);let n=e;typeof e==`object`&&e&&`toPayload`in e&&(n=e.toPayload()),Ex(n);let r=-1,i,a,o,s=t+Rx+Lx,c=!this.currState?.hasVariableDataTypes,l=!0,u=!0,d=!0,f=!0,p=!0;n.keys.length!==this.currState?.keys.length&&(d=!1,s+=n.keys.length*Ix),n.series.forEach((e,t)=>{let u=Tx(e),d=n.keys[t],p=this.currState?.keyDataTypes.get(d);if(p==null)throw new L(`Channel ${d} was not provided in the list of channels when opening the writer`);if(!p.equals(e.dataType))throw new L(`Series data type of ${e.dataType.toString()} does not match the data type of ${p.toString()} for channel ${d}`);if(s+=e.data.byteLength,r===-1){r=u,i=e.timeRange?.start,a=e.timeRange?.end,o=BigInt(e.alignment??0n);return}r!==u&&(c=!1),(i?.valueOf()!==e.timeRange?.start.valueOf()||a?.valueOf()!==e.timeRange?.end.valueOf())&&(l=!1),o!==BigInt(e.alignment??0)&&(f=!1)}),u=l&&i==null&&a==null,p=f&&(o===void 0||o===0n),c?s+=Fx:s+=n.keys.length*Fx,u||(l?s+=Nx*2:s+=n.keys.length*Nx*2),p||(f?s+=Px:s+=n.keys.length*Px);let m=new Uint8Array(s),h=new DataView(m.buffer),g=t;return m[g]=Number(p)<<Dx|Number(f)<<Ox|Number(c)<<kx|Number(l)<<Ax|Number(u)<<jx|Number(d)<<Mx,g++,h.setUint32(g,this.seqNum,!0),g+=Lx,c&&(h.setUint32(g,r,!0),g+=Fx),l&&!u&&(h.setBigUint64(g,i?.valueOf()??0n,!0),g+=Nx,h.setBigUint64(g,a?.valueOf()??0n,!0),g+=Nx),f&&!p&&(h.setBigUint64(g,o??0n,!0),g+=Px),n.series.forEach((e,t)=>{if(d||(h.setUint32(g,n.keys[t],!0),g+=Ix),!c){let t=e.data.byteLength;e.dataType.isVariable||(t=Tx(e)),h.setUint32(g,t,!0),g+=Fx}m.set(new Uint8Array(e.data),g),g+=e.data.byteLength,!l&&!u&&(h.setBigUint64(g,e.timeRange?.start.valueOf()??0n,!0),g+=Nx,h.setBigUint64(g,e.timeRange?.end.valueOf()??0n,!0),g+=Nx),!f&&!p&&(h.setBigUint64(g,e.alignment??0n,!0),g+=Px)}),m}decode(e,t=0){this.throwIfNotUpdated(`decode`);let n=e instanceof Uint8Array?e:new Uint8Array(e),r={keys:[],series:[]},i=t,a=0,o=0,s,c,l,u=new DataView(n.buffer,n.byteOffset,n.byteLength),d=!!(n[i]>>Dx&1),f=!!(n[i]>>Ox&1),p=!!(n[i]>>kx&1),m=!!(n[i]>>Ax&1),h=!!(n[i]>>jx&1),g=!!(n[i]>>Mx&1);i++;let ee=u.getUint32(i,!0);i+=Lx;let te=this.states.get(ee);if(te==null)return r;if(p){if(i+Fx>u.byteLength)return r;a=u.getUint32(i,!0),i+=Fx}if(m&&!h){if(i+Nx>u.byteLength)return r;s=new D(u.getBigUint64(i,!0)),i+=Nx,c=new D(u.getBigUint64(i,!0)),i+=Nx}if(f&&!d){if(i+Px>u.byteLength)return r;l=u.getBigUint64(i,!0),i+=Px}return g&&(r.keys=[...te.keys]),te.keys.forEach((e,t)=>{if(!g){if(i>=u.byteLength||u.getUint32(i,!0)!==e)return;i+=Ix,r.keys.push(e)}let ee=te.keyDataTypes.get(e);if(o=0,p)o=a;else{if(i+Fx>u.byteLength)return;o=u.getUint32(i,!0),i+=Fx}let ne=o;if(ee.isVariable||(ne*=ee.density.valueOf()),i+ne>u.byteLength){r.keys.splice(t,1);return}let re={dataType:ee,data:n.slice(i,i+ne).buffer};if(i+=ne,!m&&!h){if(i+Nx*2>u.byteLength)return;let e=u.getBigUint64(i,!0);i+=Nx;let t=u.getBigUint64(i,!0);i+=Nx,re.timeRange=new A({start:e,end:t})}else h?re.timeRange=new A({start:0n,end:0n}):re.timeRange=new A({start:s?.valueOf()??0n,end:c?.valueOf()??0n});if(!f&&!d){if(i+Px>u.byteLength)return;l=u.getBigUint64(i,!0),i+=Px,re.alignment=l}else d?re.alignment=0n:re.alignment=l;r.series.push(re)}),r}},Bx=new Uint8Array([254]),Vx=new Uint8Array([255]),Hx=`application/sy-framer`,Ux=class{contentType=Hx;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=ai.JSON_CODEC}encode(e){let t=e;if(t.type==`close`||t.payload?.command!=Cx.Write){let e=this.lowPerfCodec.encode(t),n=new Uint8Array({length:e.byteLength+1});return n.set(Bx,0),n.set(new Uint8Array(e),1),n}let n=this.base.encode(t.payload?.frame,1);return n.set(Vx,0),n}decode(e,t){if(new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===254)return this.lowPerfCodec.decode(e.slice(1),t);let n={type:`data`},r=this.base.decode(e,1);return n.payload={command:Cx.Write,frame:r},n}},Wx=class{contentType=Hx;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=ai.JSON_CODEC}encode(e){return this.lowPerfCodec.encode(e)}decode(e,t){return new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===254?this.lowPerfCodec.decode(e.slice(1),t):{type:`data`,payload:{frame:this.base.decode(e,1)}}}},Gx=class e{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=new Set,this.codec=new zx}static async open(t,n){let r=new e(t);return await r.update(n),r}async update(e){let{variant:t,normalized:n}=gb(e),r=await this.retriever.retrieve(n),i=r.map(e=>e.key);if(Fi.uniqueUnorderedPrimitiveArrays(Array.from(this.keys),i)===Fi.EQUAL)return!1;if(this.codec.update(i,r.map(e=>e.dataType)),t===`keys`)return this.adapter=null,this.keys=new Set(n),!0;let a=new Map;return this.adapter=a,n.forEach(e=>{let t=r.find(t=>t.name===e);if(t==null)throw Error(`Channel ${e} not found`);a.set(t.key,t.name)}),this.keys=new Set(this.adapter.keys()),!0}adapt(e){if(this.adapter==null){let t=!1;return e.forEach(e=>{this.keys.has(e)||(t=!0)}),t?e.filter(e=>this.keys.has(e)):e}let t=this.adapter;return e.mapFilter((e,n)=>{if(typeof e==`number`){let r=t.get(e);return r==null?[e,n,!1]:[r,n,!0]}return[e,n,!0]})}},Kx=class e{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new zx}static async open(t,n){let r=new e(t);return await r.update(n),r}async adaptParams(e){let t=Bb.parse(e);return await Promise.all(t.map(async e=>await this.adaptToKey(e)))}async update(e){let t=await bb(this.retriever,e),n=t.map(e=>e.key),r=new Set(this.keys),i=new Set(n),a=!i.isSubsetOf(r),o=!r.isSubsetOf(i);return a||o?(this.adapter=new Map(t.map(e=>[e.name,e.key])),this.keys=n,this.codec.update(this.keys,t.map(e=>e.dataType)),!0):!1}async fetchChannel(e){let t=await this.retriever.retrieve(e);if(t.length===0)throw Error(`Channel ${JSON.stringify(e)} not found`);return t[0]}async adaptToKey(e){return typeof e==`number`?e:(await this.fetchChannel(e)).key}encode(e){return this.codec.encode(e.toPayload())}async adapt(e,t){if(typeof e==`string`||typeof e==`number`){if(t==null)throw new L(`
|
|
75
69
|
Received a single channel name or key but no series.
|
|
76
|
-
`);if(Array.isArray(
|
|
70
|
+
`);if(Array.isArray(t)){if(t.some(e=>e instanceof Qo||Array.isArray(e)))throw new L(`
|
|
77
71
|
Received a single channel name or key but multiple series.
|
|
78
|
-
`);
|
|
72
|
+
`);t=t}let n=await this.fetchChannel(e),r=new Qo({data:t,dataType:n.dataType});return new $(n.key,r)}if(Array.isArray(e)){if(t==null)throw new L(`
|
|
79
73
|
Received an array of channel names or keys but no series.
|
|
80
|
-
`);if(!Array.isArray(
|
|
74
|
+
`);if(!Array.isArray(t))throw new L(`
|
|
81
75
|
Received an array of channel names or keys but no array of series.
|
|
82
|
-
`);
|
|
76
|
+
`);let n=[],r=[];for(let i=0;i<e.length;i++){let a=await this.fetchChannel(e[i]);if(i>=t.length)throw new L(`
|
|
83
77
|
Received an array of channel names or keys but not enough series.
|
|
84
|
-
`);
|
|
85
|
-
Channel ${
|
|
86
|
-
`);return
|
|
87
|
-
Please report this error to the Synnax team.`),
|
|
78
|
+
`);let o=new Qo({data:t[i],dataType:a.dataType});n.push(a.key),r.push(o)}return new $(n,r)}if(e instanceof $||e instanceof Map){let t=new $(e);return this.adapter==null?t:new $(t.columns.map(e=>{let t=typeof e==`string`?this.adapter?.get(e):e;if(t==null)throw new L(`
|
|
79
|
+
Channel ${e} was not provided in the list of channels when opening the writer
|
|
80
|
+
`);return t}),t.series)}let n=[],r=[],i=Object.entries(e);for(let e=0;e<i.length;e++){let[t,a]=i[e],o=await this.fetchChannel(t),s=new Qo({data:a,dataType:o.dataType});n.push(o.key),r.push(s)}return new $(n,r)}},qx=class{name;stream;constructor(e,t){this.stream=t,this.name=e}async receive(){let[e,t]=await this.stream.receive();if(t!=null)throw t;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){let[e,t]=await this.stream.receive();if(e!=null&&console.warn(`${this.name} received unexpected response on ${JSON.stringify(e)} closure.
|
|
81
|
+
Please report this error to the Synnax team.`),t!=null){if(br.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){let t=this.stream.send(e);if(t!=null)throw t}},Jx=new O(-1),Yx=function(e){return e[e.Open=0]=`Open`,e[e.Next=1]=`Next`,e[e.Prev=2]=`Prev`,e[e.SeekFirst=3]=`SeekFirst`,e[e.SeekLast=4]=`SeekLast`,e[e.SeekLE=5]=`SeekLE`,e[e.SeekGE=6]=`SeekGE`,e[e.Valid=7]=`Valid`,e[e.Error=8]=`Error`,e}(Yx||{}),Xx=function(e){return e[e.None=0]=`None`,e[e.Ack=1]=`Ack`,e[e.Data=2]=`Data`,e}(Xx||{}),Zx=l.z.object({command:l.z.enum(Yx),span:O.z.optional(),bounds:A.z.optional(),stamp:D.z.optional(),keys:Z.array().optional(),chunkSize:l.z.number().optional(),downsampleFactor:l.z.int().optional()}),Qx=l.z.object({variant:l.z.enum(Xx),ack:l.z.boolean(),command:l.z.enum(Yx),error:Zc.payloadZ.optional().nullable(),frame:bx.optional()}),$x=class e{stream;adapter;value;constructor(e,t){this.stream=new qx(`Iterator`,e),this.value=new $,this.adapter=t}static async _open(t,n,r,i,a={}){let o=await Gx.open(r,n),s=new e(await i.stream(`/frame/iterate`,Zx,Qx),o);return await s.execute({command:Yx.Open,keys:Array.from(o.keys),bounds:new A(t),chunkSize:a.chunkSize??1e5,downsampleFactor:a.downsampleFactor??1}),s}async next(e=Jx){return await this.execute({command:Yx.Next,span:new O(e)})}async prev(e=Jx){return await this.execute({command:Yx.Prev,span:new O(e)})}async seekFirst(){return await this.execute({command:Yx.SeekFirst})}async seekLast(){return await this.execute({command:Yx.SeekLast})}async seekLE(e){return await this.execute({command:Yx.SeekLE,stamp:new D(e)})}async seekGE(e){return await this.execute({command:Yx.SeekGE,stamp:new D(e)})}async valid(){return await this.execute({command:Yx.Valid})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new eS(this)}async execute(e){for(this.stream.send(e),this.value=new $;;){let e=await this.stream.receive();if(e.variant===Xx.Ack)return e.ack;this.value.push(this.adapter.adapt(new $(e.frame)))}}},eS=class{iter;open=!1;constructor(e){this.iter=e}async next(){try{let e=!0;return this.open||=(await this.iter.seekFirst()||(e=!1),!0),await this.iter.next()||(e=!1),e||await this.iter.close(),{done:!e,value:this.iter.value}}catch(e){throw await this.iter.close(),e}}},tS=class{retriever;streamClient;constructor(e,t){this.retriever=e,this.streamClient=t}async read(e){let{channels:t,timeRange:n,channelNames:r,iteratorConfig:i}=e,a=await this.retriever.retrieve(t),o=new Set;a.forEach(e=>{o.add(e.key),e.index!==0&&o.add(e.index)});let s=Array.from(o).filter(e=>!a.some(t=>t.key===e));if(s.length>0){let e=await this.retriever.retrieve(s);a.push(...e)}return nS({iterator:await $x._open(n,Array.from(o),this.retriever,this.streamClient,i),channelPayloads:a,headers:r})}},nS=({iterator:e,channelPayloads:t,headers:n})=>{let r=Wl.getOS()===`Windows`?`\r
|
|
88
82
|
`:`
|
|
89
|
-
`,s=new TextEncoder;let a=!1,o=!1;const c=sE(e),{columns:u,columnsByIndexKey:l,emptyGroupStrings:h}=iE(e,c,n);let d=[],f=0,b=[];const N=O=>{for(const[S]of c){const A=O.get(S);if(A.length===0)continue;const C=(l.get(S)??[]).map(_=>O.get(_.key));for(let _=0;_<A.length;_++){const le=A.at(_,!0),ae=C.map(ge=>Ji.formatValue(ge.at(_,!0)));b.push({time:le,values:ae,indexKey:S})}}},k=(O,S=!1)=>{b.length>0&&(b.sort((C,_)=>Number(C.time-_.time)),f>0&&(d=d.slice(f),f=0),d=aE(d,b),b=[]);const A=[],D=d.length;for(;f<D&&A.length<O;){const C=d[f].time;if(!S&&d[D-1].time===C)break;const _=new Map;for(;f<D&&d[f].time===C;){const ae=d[f++];_.set(ae.indexKey,ae)}const le=[];for(const[ae]of c){const ge=_.get(ae);le.push(ge?.values.join(",")??h.get(ae)??"")}A.push(le.join(","))}return A};return new ReadableStream({async pull(O){try{if(o||(await t.seekFirst(),o=!0),!a){const C=u.map(_=>Ji.formatValue(_.header)).join(",");O.enqueue(s.encode(`${C}${r}`)),a=!0}d.length-f+b.length<Ma&&await t.next()&&N(t.value);const A=k(Ma);if(A.length>0&&O.enqueue(s.encode(`${A.join(r)}${r}`)),d.length-f===0||b.length===0){if(!await t.next()){const _=k(1/0,!0);_.length>0&&O.enqueue(s.encode(`${_.join(r)}${r}`)),await t.close(),O.close();return}N(t.value)}}catch(S){await t.close(),O.error(S)}},async cancel(){await t.close()}})},sE=t=>{const e=new Map;for(const n of t){if(n.index===0)continue;let r=e.get(n.index);r==null&&(r=[n.index],e.set(n.index,r)),!n.isIndex&&!r.includes(n.key)&&r.push(n.key)}return e},iE=(t,e,n)=>{const r=new Map(t.map(c=>[c.key,c])),s=[],a=new Map,o=new Map;for(const[c,u]of e){const l=[];for(const h of u){const d=r.get(h);if(d==null)throw new ct(`Channel ${h} not found`);const f={key:h,header:n?.[h]??n?.[d.name]??d.name};s.push(f),l.push(f)}a.set(c,l),o.set(c,",".repeat(l.length-1))}return{columns:s,columnsByIndexKey:a,emptyGroupStrings:o}},aE=(t,e)=>{const n=[];let r=0,s=0;for(;r<t.length&&s<e.length;)t[r].time<=e[s].time?n.push(t[r++]):n.push(e[s++]);return n.push(...t.slice(r),...e.slice(s)),n},Ma=1e3,oE=i.z.object({keys:i.z.number().array(),downsampleFactor:i.z.int(),throttleRate:G.z.optional()}),cE=i.z.object({frame:or}),Ra=i.z.object({channels:mt,downsampleFactor:i.z.int().default(1),throttleRate:G.z.default(new G(0)),useHighPerformanceCodec:i.z.boolean().default(!0)}),bi=Ra.or(mt.transform(t=>Ra.parse({channels:t}))),cl=(t,e)=>async n=>{const r=bi.parse(n),s=await cr.open(t,r.channels);r.useHighPerformanceCodec&&(e=e.withCodec(new QS(s.codec)));const a=await e.stream("/frame/stream",oE,cE),o=new uE(a,s,r.downsampleFactor,r.throttleRate);a.send({keys:Array.from(s.keys),downsampleFactor:r.downsampleFactor,throttleRate:r.throttleRate});const[,c]=await a.receive();if(c!=null)throw c;return o},ul=async(t,e,n)=>await cl(t,e)(n);class uE{stream;adapter;downsampleFactor;throttleRate;constructor(e,n,r=1,s=new G(0)){this.stream=new il("Streamer",e),this.adapter=n,this.downsampleFactor=r,this.throttleRate=s}get keys(){return Array.from(this.adapter.keys)}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(ze.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new V((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e)&&this.stream.send({keys:Array.from(this.adapter.keys),downsampleFactor:this.downsampleFactor,throttleRate:this.throttleRate})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class ur{wrapped_=null;breaker;opener;config;constructor(e,n,r={}){this.opener=e,this.config=bi.parse(n);const{maxRetries:s=5e3,baseInterval:a=w.seconds(1),scale:o=1}=r??{};this.breaker=new Bs.Breaker({maxRetries:s,baseInterval:a,scale:o})}static async open(e,n,r){const s=new ur(e,n,r);return await s.runStreamer(),s}async runStreamer(){for(;;)try{this.wrapped_!=null&&this.wrapped_.close(),this.wrapped_=await this.opener(this.config),this.breaker.reset();return}catch(e){if(this.wrapped_=null,!await this.breaker.wait())throw e;console.error("failed to open streamer",e);continue}}get wrapped(){if(this.wrapped_==null)throw new Error("stream closed");return this.wrapped_}async update(e){this.config.channels=mt.parse(e);try{await this.wrapped.update(e)}catch{return await this.runStreamer(),await this.update(e)}}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(ze.matches(e))return{done:!0,value:void 0};throw e}}async read(){try{const e=await this.wrapped.read();return this.breaker.reset(),e}catch(e){if(ze.matches(e))throw e;return await this.runStreamer(),await this.read()}}close(){this.wrapped.close()}get keys(){return this.wrapped.keys}[Symbol.asyncIterator](){return this}}class ll extends Qm.Observer{streamer;closePromise;constructor(e,n){super(n),this.streamer=e,this.closePromise=this.stream()}async update(e){await this.streamer.update(e)}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}var sn=(t=>(t[t.PersistStream=1]="PersistStream",t[t.Persist=2]="Persist",t[t.Stream=3]="Stream",t))(sn||{});const lE=new w(-1);class gs extends Ae.sub("writer_closed"){constructor(){super("WriterClosed")}}const hE=i.z.enum(sn).or(i.z.enum(["persist","stream","persistStream"]).transform(t=>{switch(t){case"persist":return 2;case"stream":return 3;case"persistStream":return 1}})),hl=i.z.object({start:m.z.optional(),controlSubject:pe.subjectZ.optional(),authorities:i.z.union([pe.authorityZ.transform(t=>[t]),pe.authorityZ.array()]).default([pe.ABSOLUTE_AUTHORITY]),mode:hE.default(1),errOnUnauthorized:i.z.boolean().default(!1),enableAutoCommit:i.z.boolean().default(!0),autoIndexPersistInterval:w.z.default(w.SECOND),useHighPerformanceCodec:i.z.boolean().default(!0)}),fE=hl.extend({keys:L.array().optional()}),ja=hl.extend({channels:mt}),fl=ja.or(mt.transform(t=>ja.parse({channels:t,start:m.now()}))),dE=i.z.object({command:i.z.enum($e),config:fE.optional(),frame:or.optional(),buffer:i.z.instanceof(Uint8Array).optional()}),pE=i.z.object({command:i.z.enum($e),end:m.z,err:Le.payloadZ.optional()}),yE=i.z.tuple([i.z.union([i.z.record(L.or(Pe),pe.authorityZ),L.or(Pe),pe.authorityZ]),pe.authorityZ.optional()]).transform(([t,e])=>{if(pe.authorityZ.safeParse(t).success)return{keys:[],authorities:[t]};if(L.or(Pe).safeParse(t).success){if(e==null)throw new Error("authority is required when setting authority for a single channel");return{keys:[t],authorities:[e]}}const n=t;return{keys:Object.keys(n),authorities:Object.values(n)}});let dl=class pl{stream;adapter;closeErr=null;constructor(e,n){this.stream=e,this.adapter=n}static async _open(e,n,r){const s=fl.parse(r),a=await gi.open(e,s.channels);s.useHighPerformanceCodec&&(n=n.withCodec(new XS(a.codec)));const o=await n.stream("/frame/write",dE,pE),c=new pl(o,a);return await c.execute({command:$e.Open,config:{...s,keys:a.keys}}),c}async write(e,n){if(this.closeErr!=null)throw this.closeErr;if(this.stream.received())return await this.close();const r=await this.adapter.adapt(e,n);this.stream.send({command:$e.Write,frame:r.toPayload()})}async setAuthority(e,n){if(this.closeErr!=null)throw this.closeErr;const r=yE.parse([e,n]),s={keys:await this.adapter.adaptParams(r.keys),authorities:r.authorities};await this.execute({command:$e.SetAuthority,config:s})}async commit(){if(this.closeErr!=null)throw this.closeErr;return this.stream.received()?(await this.closeInternal(null),m.ZERO):(await this.execute({command:$e.Commit})).end}async close(){await this.closeInternal(null)}async closeInternal(e){if(this.closeErr!=null)throw this.closeErr;for(this.closeErr=e,this.stream.closeSend();;){if(this.closeErr!=null){if(gs.matches(this.closeErr))return null;throw this.closeErr}const[n,r]=await this.stream.receive();r!=null?this.closeErr=ze.matches(r)?new gs:r:this.closeErr=Le.decode(n?.err)}}async execute(e){const n=this.stream.send(e);for(n!=null&&await this.closeInternal(n);;){const[r,s]=await this.stream.receive();s!=null&&await this.closeInternal(s);const a=Le.decode(r?.err);if(a!=null&&await this.closeInternal(a),r?.command==e.command)return r}}};const yl=J("framer"),mE=yl("");let ml=class{streamClient;retriever;deleter;reader;constructor(e,n,r){this.streamClient=e,this.retriever=r,this.deleter=new HS(n),this.reader=new ol(r,e)}async openIterator(e,n,r){return await bn._open(e,n,this.retriever,this.streamClient,r)}async openWriter(e){return await dl._open(this.retriever,this.streamClient,e)}async openStreamer(e){return await ul(this.retriever,this.streamClient,e)}async write(e,n,r){if(r==null){const a=n,o=await this.openWriter({start:e,channels:Object.keys(a),mode:sn.Persist,errOnUnauthorized:!0,autoIndexPersistInterval:w.MAX});return await o.write(a),await o.close()}const s=await this.openWriter({start:e,channels:n,mode:sn.Persist,errOnUnauthorized:!0,autoIndexPersistInterval:w.MAX});await s.write(n,r),await s.close()}async read(e,n){if(!("start"in e))return this.reader.read(e);const{single:r}=ve(n),s=await this.readFrame(e,n);return r?s.get(n):s}async readFrame(e,n){const r=await this.openIterator(e,n),s=new V;try{for await(const a of r)s.push(a)}finally{await r.close()}return s}async readLatest(e,n=1){const{single:r}=ve(e),s=await this.readLatestNFrame(e,n);return r?s.get(e):s}async readLatestNFrame(e,n){const r=await this.openIterator(x.MAX,e,{chunkSize:n}),s=new V;if(n>0)try{await r.seekLast(),await r.prev(Hn),s.push(r.value)}finally{await r.close()}return s}async delete(e,n){const{normalized:r,variant:s}=ve(e),a=new x(n);return s==="keys"?await this.deleter.delete({keys:r,bounds:a}):await this.deleter.delete({names:r,bounds:a})}};const gE=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:lE,AUTO_SPAN:Hn,Client:ml,Frame:V,HardenedStreamer:ur,Iterator:bn,ObservableStreamer:ll,Reader:ol,TYPE_ONTOLOGY_ID:mE,Writer:dl,WriterClosedError:gs,WriterCommand:$e,WriterMode:sn,createStreamOpener:cl,frameZ:or,ontologyID:yl,openStreamer:ul,seriesFromPayload:tl,seriesToPayload:nl,streamerConfigZ:bi,writerConfigZ:fl},Symbol.toStringTag,{value:"Module"})),wE=pe.ABSOLUTE_AUTHORITY,bE=pe.ZERO_AUTHORITY,vE=pe.stateZ(i.z.number()),zE=t=>t.to==null?`${t.from?.resource} - ${t.from?.subject.name} -> released`:t.from==null?`${t.to.resource} - released -> ${t.to.subject.name} (${t.to.authority.toString()})`:`${t.to.resource} - ${t.from.subject.name} -> ${t.to.subject.name} (${t.to.authority.toString()})`,TE=i.z.object({transfers:i.z.array(pe.transferZ(L))});class gl extends ll{states;codec;constructor(e){super(e,n=>{const r=this.codec.decode(n.series[0].buffer,TE);return this.merge(r),[r.transfers,!0]}),this.states=new Map,this.codec=new Jn.JSONCodec}subjects(){const e=new Map;return this.states.forEach(n=>e.set(n.subject.key,n.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(n=>{n.from==null&&n.to==null&&console.warn("Invalid transfer: ",n),n.to==null?this.states.delete(n.from.resource):this.states.set(n.to.resource,n.to)})}}const wl="sy_node_1_control";let bl=class{framer;constructor(e){this.framer=e}async openStateTracker(){const e=await ur.open(async n=>await this.framer.openStreamer(n),wl);return new gl(e)}};const OE=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:wE,CONTROL_STATE_CHANNEL_NAME:wl,Client:bl,StateTracker:gl,ZERO_AUTHORITY:bE,stateZ:vE,transferString:zE},Symbol.toStringTag,{value:"Module"})),Te=i.z.uint32(),vl=i.z.object({rack:Te}),zl=Qe.statusZ(vl),lr=i.z.object({key:Te,name:i.z.string(),status:be.nullToUndefined(zl)}),Tl=lr.partial({key:!0}),Mt=i.z.string(),Ol=i.z.object({rack:Te,device:Mt}),Sl=Qe.statusZ(Ol),hr=({properties:t,make:e,model:n}={})=>i.z.object({key:Mt,rack:Te.min(1,"Must select a location to connect from"),name:i.z.string().min(1,"Name is required"),make:e??i.z.string().min(1,"Make is required"),model:n??i.z.string().min(1,"Model is required"),location:i.z.string().min(1,"Location is required"),configured:i.z.boolean().optional(),properties:t??oe.nullishToEmpty(),status:be.nullToUndefined(Sl)}),El=(t={})=>hr(t).extend({properties:t?.properties??oe.nullishToEmpty()}),SE="sy_device_set",EE="sy_device_delete",NE=t=>i.z.object({devices:be.toArray(El(t))}),$E=t=>i.z.object({devices:hr(t).array()}),kE=i.z.object({keys:Mt.array()}),AE=i.z.object({}),IE=i.z.object({keys:Mt.array().optional(),names:i.z.string().array().optional(),makes:i.z.string().array().optional(),models:i.z.string().array().optional(),locations:i.z.string().array().optional(),racks:Te.array().optional(),searchTerm:i.z.string().optional(),limit:i.z.int().optional(),offset:i.z.int().optional(),includeStatus:i.z.boolean().optional()}),ZE=t=>i.z.object({devices:E.nullableZ(hr(t))}),xE=i.z.object({key:Mt,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),CE=i.z.union([xE,IE]);let Nl=class{client;constructor(e){this.client=e}async retrieve(e){const{schemas:n,...r}=e,s=typeof r=="object"&&"key"in r,a=await T(this.client,"/device/retrieve",r,CE,ZE(n));return ue("Device",r,a.devices,s),s?a.devices[0]:a.devices}async create(e,n){const r=!Array.isArray(e),s=await T(this.client,"/device/create",{devices:E.toArray(e)},NE(n),$E(n));return r?s.devices[0]:s.devices}async delete(e){await T(this.client,"/device/delete",{keys:E.toArray(e)},kE,AE)}};const vi=J("device"),_E=vi(""),ME=t=>ke(vi(t)),RE=Object.freeze(Object.defineProperty({__proto__:null,Client:Nl,DELETE_CHANNEL_NAME:EE,SET_CHANNEL_NAME:SE,TYPE_ONTOLOGY_ID:_E,deviceZ:hr,keyZ:Mt,newZ:El,ontologyID:vi,statusDetailsZ:Ol,statusKey:ME,statusZ:Sl},Symbol.toStringTag,{value:"Module"})),gt=i.z.uuid(),fr=i.z.object({key:gt,name:i.z.string(),data:oe.unknownZ.or(i.z.string().transform(Ze))}),$l=fr.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),xe=i.z.uuid(),dr=i.z.object({key:xe,name:i.z.string().min(1,"Name is required"),layout:oe.unknownZ.or(i.z.string().transform(Ze))}),kl=dr.partial({key:!0}).transform(t=>({...t,layout:JSON.stringify(t.layout)})),Al=dr.omit({layout:!0}).extend({layout:i.z.string().transform(Ze)}),jE=i.z.object({keys:xe.array().optional(),searchTerm:i.z.string().optional(),author:Ie.optional(),offset:i.z.int().optional(),limit:i.z.int().optional()}),UE=i.z.object({workspaces:kl.array()}),PE=i.z.object({key:xe,name:i.z.string()}),LE=i.z.object({key:xe,layout:oe.unknownZ.transform(t=>JSON.stringify(t))}),DE=i.z.object({keys:xe.array()}),BE=i.z.object({workspaces:E.nullableZ(dr)}),qE=i.z.object({workspaces:Al.array()}),Rr=i.z.object({}),FE="sy_workspace_set",YE="sy_workspace_delete";let Il=class{client;constructor(e){this.client=e}async create(e){const n=Array.isArray(e),r=await T(this.client,"/workspace/create",{workspaces:E.toArray(e)},UE,qE);return n?r.workspaces:r.workspaces[0]}async rename(e,n){await T(this.client,"/workspace/rename",{key:e,name:n},PE,Rr)}async setLayout(e,n){await T(this.client,"/workspace/set-layout",{key:e,layout:n},LE,Rr)}async retrieve(e){let n;const r=typeof e!="string";typeof e=="string"||Array.isArray(e)?n={keys:E.toArray(e)}:n=e;const s=await T(this.client,"/workspace/retrieve",n,jE,BE);return r?s.workspaces:s.workspaces[0]}async delete(e){await T(this.client,"/workspace/delete",{keys:E.toArray(e)},DE,Rr)}};const Zl=J("workspace"),HE=Zl(""),VE=Object.freeze(Object.defineProperty({__proto__:null,Client:Il,DELETE_CHANNEL_NAME:YE,SET_CHANNEL_NAME:FE,TYPE_ONTOLOGY_ID:HE,keyZ:xe,newZ:kl,ontologyID:Zl,remoteZ:Al,workspaceZ:dr},Symbol.toStringTag,{value:"Module"})),GE=i.z.object({key:gt,name:i.z.string()}),WE=i.z.object({key:gt,data:i.z.string()}),JE=i.z.object({keys:gt.array()}),KE=i.z.object({keys:gt.array()}),xl=i.z.object({key:gt}).transform(({key:t})=>({keys:[t]})),Cl=i.z.union([xl,KE]),XE=i.z.object({linePlots:E.nullableZ(fr)}),QE=i.z.object({workspace:xe,linePlots:$l.array()}),e0=i.z.object({linePlots:fr.array()}),jr=i.z.object({});let _l=class{client;constructor(e){this.client=e}async create(e,n){const r=Array.isArray(n),s=await T(this.client,"/lineplot/create",{workspace:e,linePlots:E.toArray(n)},QE,e0);return r?s.linePlots:s.linePlots[0]}async rename(e,n){await T(this.client,"/lineplot/rename",{key:e,name:n},GE,jr)}async setData(e,n){await T(this.client,"/lineplot/set-data",{key:e,data:JSON.stringify(n)},WE,jr)}async retrieve(e){const n=xl.safeParse(e).success,r=await T(this.client,"/lineplot/retrieve",e,Cl,XE);return ue("LinePlot",e,r.linePlots,n),n?r.linePlots[0]:r.linePlots}async delete(e){await T(this.client,"/lineplot/delete",{keys:E.toArray(e)},JE,jr)}};const Ml=J("lineplot"),t0=Ml(""),n0=Object.freeze(Object.defineProperty({__proto__:null,Client:_l,TYPE_ONTOLOGY_ID:t0,keyZ:gt,linePlotZ:fr,newZ:$l,ontologyID:Ml,retrieveArgsZ:Cl},Symbol.toStringTag,{value:"Module"})),wt=i.z.uuid(),pr=i.z.object({key:wt,name:i.z.string(),data:oe.unknownZ.or(i.z.string().transform(Ze))}),Rl=pr.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),r0=i.z.object({key:wt,name:i.z.string()}),s0=i.z.object({key:wt,data:i.z.string()}),i0=i.z.object({keys:wt.array()}),a0=i.z.object({keys:wt.array()}),jl=i.z.object({key:wt}).transform(({key:t})=>({keys:[t]})),Ul=i.z.union([jl,a0]),o0=i.z.object({logs:E.nullableZ(pr)}),c0=i.z.object({workspace:xe,logs:Rl.array()}),u0=i.z.object({logs:pr.array()}),Ur=i.z.object({});let Pl=class{client;constructor(e){this.client=e}async create(e,n){const r=Array.isArray(n),s=await T(this.client,"/log/create",{workspace:e,logs:E.toArray(n)},c0,u0);return r?s.logs:s.logs[0]}async rename(e,n){await T(this.client,"/log/rename",{key:e,name:n},r0,Ur)}async setData(e,n){await T(this.client,"/log/set-data",{key:e,data:JSON.stringify(n)},s0,Ur)}async retrieve(e){const n=jl.safeParse(e).success,r=await T(this.client,"/log/retrieve",e,Ul,o0);return ue("Log",e,r.logs,n),n?r.logs[0]:r.logs}async delete(e){await T(this.client,"/log/delete",{keys:E.toArray(e)},i0,Ur)}};const Ll=J("log"),l0=Ll(""),h0=Object.freeze(Object.defineProperty({__proto__:null,Client:Pl,TYPE_ONTOLOGY_ID:l0,keyZ:wt,logZ:pr,newZ:Rl,ontologyID:Ll,retrieveArgsZ:Ul},Symbol.toStringTag,{value:"Module"})),f0="sy_rack_set",d0="sy_rack_delete",p0=i.z.object({keys:Te.array().optional(),names:i.z.string().array().optional(),searchTerm:i.z.string().optional(),embedded:i.z.boolean().optional(),hostIsNode:i.z.boolean().optional(),limit:i.z.int().optional(),offset:i.z.int().optional(),includeStatus:i.z.boolean().optional()}),y0=i.z.object({racks:E.nullableZ(lr)}),m0=i.z.union([i.z.object({key:Te,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),i.z.object({name:i.z.string(),includeStatus:i.z.boolean().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e}))]),g0=p0,w0=i.z.union([m0,g0]),b0=i.z.object({racks:Tl.array()}),v0=i.z.object({racks:lr.array()}),z0=i.z.object({keys:Te.array()}),T0=i.z.object({});let Dl=class{client;tasks;constructor(e,n){this.client=e,this.tasks=n}async delete(e){await T(this.client,"/rack/delete",{keys:E.toArray(e)},z0,T0)}async create(e){const n=!Array.isArray(e),r=await T(this.client,"/rack/create",{racks:E.toArray(e)},b0,v0),s=this.sugar(r.racks);return n?s[0]:s}async retrieve(e){const n="key"in e||"name"in e,r=await T(this.client,"/rack/retrieve",e,w0,y0),s=this.sugar(r.racks);return ue("Rack",e,s,n),n?s[0]:s}sugar(e){const n=!Array.isArray(e),r=E.toArray(e).map(({key:s,name:a,status:o})=>new Bl(s,a,this.tasks,o));return n?r[0]:r}};class Bl{key;name;status;tasks;constructor(e,n,r,s){this.key=e,this.name=n,this.tasks=r,this.status=s}async listTasks(){return await this.tasks.retrieve({rack:this.key})}async createTask(e,n){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e,n)}async deleteTask(e){await this.tasks.delete([e])}get payload(){return{key:this.key,name:this.name,status:this.status}}}const zi=J("rack"),O0=zi(0),S0=t=>ke(zi(t)),E0=Object.freeze(Object.defineProperty({__proto__:null,Client:Dl,DELETE_CHANNEL_NAME:d0,Rack:Bl,SET_CHANNEL_NAME:f0,TYPE_ONTOLOGY_ID:O0,keyZ:Te,newZ:Tl,ontologyID:zi,rackZ:lr,statusDetailsZ:vl,statusKey:S0,statusZ:zl},Symbol.toStringTag,{value:"Module"})),ql="sy_range_alias_set",Fl="sy_range_alias_delete",N0=i.z.object({alias:i.z.string().optional(),channel:L,range:X}),Yl="---",Hl=t=>`${t.range}${Yl}${t.channel}`,Vl=t=>{const[e,n]=t.split(Yl);return{range:e,channel:Number(n)}},$0=Object.freeze(Object.defineProperty({__proto__:null,DELETE_CHANNEL_NAME:Fl,SET_CHANNEL_NAME:ql,aliasZ:N0,createKey:Hl,decodeDeleteChange:Vl},Symbol.toStringTag,{value:"Module"})),k0=i.z.object({range:X,aliases:i.z.string().array()}),A0=i.z.object({aliases:i.z.record(i.z.string(),L)}),I0=i.z.object({range:X,aliases:i.z.record(L,i.z.string())}),Z0=i.z.unknown(),x0=i.z.object({range:X,channels:L.array()}),C0=i.z.unknown(),_0=i.z.object({range:X}),M0=i.z.object({aliases:i.z.record(i.z.string(),i.z.string())}),R0=i.z.object({range:X,channels:L.array()}),j0=i.z.object({aliases:i.z.record(i.z.string(),i.z.string())});let vt=class{cache=new Map;client;rangeKey;constructor(e,n){this.rangeKey=e,this.cache=new Map,this.client=n}async resolve(e){const n=[],r=typeof e=="string",s={};if(r){const o=this.cache.get(e);if(o!=null)return o;n.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?s[o]=c:n.push(o)});if(n.length===0)return s;const a=await T(this.client,"/range/alias/resolve",{range:this.rangeKey,aliases:n},k0,A0);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),r?a.aliases[n[0]]:{...s,...a.aliases}}async set(e){await T(this.client,"/range/alias/set",{range:this.rangeKey,aliases:e},I0,Z0)}async list(){return(await T(this.client,"/range/alias/list",{range:this.rangeKey},_0,M0)).aliases}async retrieve(e){const n=typeof e=="number",r=await T(this.client,"/range/alias/retrieve",{range:this.rangeKey,channels:E.toArray(e)},R0,j0);return n?r.aliases[e]:r.aliases}async delete(e){await T(this.client,"/range/alias/delete",{range:this.rangeKey,channels:E.toArray(e)},x0,C0)}};const Gl="sy_range_kv_set",Wl="sy_range_kv_delete",yr=i.z.object({range:X,key:i.z.string(),value:i.z.string()}),Jl=({range:t,key:e})=>`${t}<--->${e}`,U0=i.z.object({range:X,keys:i.z.string().array()}),P0=i.z.object({pairs:E.nullableZ(yr)}),L0=i.z.object({range:X,pairs:yr.array()}),D0=i.z.object({range:X,keys:i.z.string().array()});let Ua=class{rangeKey;client;constructor(e,n){this.rangeKey=e,this.client=n}async get(e){const n=await T(this.client,"/range/kv/get",{range:this.rangeKey,keys:E.toArray(e)},U0,P0);return typeof e=="string"?n.pairs[0].value:Object.fromEntries(n.pairs.map(r=>[r.key,r.value]))}async list(){return this.get([])}async set(e,n=""){let r;typeof e=="string"?r=[{range:this.rangeKey,key:e,value:n}]:r=Object.entries(e).map(([s,a])=>({range:this.rangeKey,key:s,value:a})),await T(this.client,"/range/kv/set",{range:this.rangeKey,pairs:r},L0,i.z.unknown())}async delete(e){await T(this.client,"/range/kv/delete",{range:this.rangeKey,keys:E.toArray(e)},D0,i.z.unknown())}};const B0="sy_range_set",q0="sy_range_delete";class Kl{key;name;kv;timeRange;color;parent;labels;channels;aliaser;frameClient;labelClient;ontologyClient;rangeClient;constructor({name:e,timeRange:n=x.ZERO,key:r,color:s,parent:a,labels:o},{frameClient:c,kv:u,aliaser:l,channels:h,labelClient:d,ontologyClient:f,rangeClient:b}){this.key=r,this.name=e,this.timeRange=n,this.parent=a,this.labels=o,this.frameClient=c,this.color=s,this.kv=u,this.aliaser=l,this.channels=h,this.labelClient=d,this.ontologyClient=f,this.rangeClient=b}get ontologyID(){return st(this.key)}get payload(){let e=null;return this.parent!=null&&("payload"in this.parent?e=this.parent.payload:e=this.parent),{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color,labels:this.labels,parent:e}}async setAlias(e,n){const r=await this.channels.retrieve(e);if(r.length===0)throw new Ke(`Channel ${e} does not exist`);await this.aliaser.set({[r[0].key]:n})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(n=>n.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async retrieveLabels(){return await this.labelClient.retrieve({for:st(this.key)})}async addLabel(...e){await this.labelClient.label(st(this.key),e)}async removeLabel(...e){await this.labelClient.remove(st(this.key),e)}static sort(e,n){return x.sort(e.timeRange,n.timeRange)}}const F0=i.z.object({keys:X.array().optional(),names:i.z.string().array().optional(),searchTerm:i.z.string().optional(),overlapsWith:x.z.optional(),hasLabels:nt.array().optional(),limit:i.z.int().optional(),offset:i.z.int().optional(),includeLabels:i.z.boolean().optional(),includeParent:i.z.boolean().optional()}),Y0=F0.or(X.array().transform(t=>({keys:t}))).or(X.transform(t=>({keys:[t]}))).or(i.z.string().transform(t=>({names:[t]}))).or(i.z.string().array().transform(t=>({names:t}))).or(x.z.transform(t=>({overlapsWith:t}))),H0=i.z.object({ranges:E.nullableZ(gn)});let Xl=class{type="range";frameClient;writer;unaryClient;channels;labelClient;ontologyClient;constructor(e,n,r,s,a,o){this.frameClient=e,this.writer=n,this.unaryClient=r,this.channels=s,this.labelClient=a,this.ontologyClient=o}async create(e,n){const r=!Array.isArray(e),s=this.sugarMany(await this.writer.create(E.toArray(e),n));return r?s[0]:s}async rename(e,n){await this.writer.rename(e,n)}async delete(e){await this.writer.delete(E.toArray(e))}async retrieve(e){const n=typeof e=="string",{ranges:r}=await T(this.unaryClient,"/range/retrieve",e,Y0,H0);return ue("Range",e,r,n),n?this.sugarMany(r)[0]:this.sugarMany(r)}getKV(e){return new Ua(e,this.unaryClient)}async retrieveParent(e){const n=await this.ontologyClient.retrieveParents(st(e));if(n.length===0)return null;const r=n[0];return r.id.type!=="range"?null:await this.retrieve(r.id.key)}sugarOntologyResource(e){return this.sugarOne(Ql(e))}async retrieveAlias(e,n){return await new vt(e,this.unaryClient).retrieve(n)}async retrieveAliases(e,n){return await new vt(e,this.unaryClient).retrieve(n)}async listAliases(e){return await new vt(e,this.unaryClient).list()}async setAlias(e,n,r){await new vt(e,this.unaryClient).set({[n]:r})}async deleteAlias(e,n){await new vt(e,this.unaryClient).delete(n)}sugarOne(e){return new Kl(e,{frameClient:this.frameClient,kv:new Ua(e.key,this.unaryClient),aliaser:new vt(e.key,this.unaryClient),channels:this.channels,labelClient:this.labelClient,ontologyClient:this.ontologyClient,rangeClient:this})}sugarMany(e){return e.map(n=>this.sugarOne(n))}resourceToRange(e){return this.sugarOne({key:e.id.key,name:e.data?.name,timeRange:new x(e.data?.timeRange),color:e.data?.color,labels:[],parent:null})}};const st=J("range"),V0=st(""),G0=t=>({type:"range-alias",key:t}),Ql=({data:t,id:{key:e},name:n})=>{const r=x.z.parse(t?.timeRange),s=yc.colorZ.safeParse(t?.color);return{key:e,name:n,timeRange:r,color:s.success?s.data:void 0,labels:[],parent:null}},W0=Object.freeze(Object.defineProperty({__proto__:null,DELETE_CHANNEL:Wl,SET_CHANNEL:Gl,createPairKey:Jl,pairZ:yr},Symbol.toStringTag,{value:"Module"})),J0=i.z.object({ranges:gn.array()}),K0=i.z.object({parent:B.optional(),ranges:Hu.array()}),X0=i.z.object({keys:X.array()}),Q0=i.z.object({}),eN=i.z.object({key:X,name:fi}),tN=i.z.object({});class eh{client;constructor(e){this.client=e}async rename(e,n){await T(this.client,"/range/rename",{key:e,name:n},eN,tN)}async create(e,n){return(await T(this.client,"/range/create",{ranges:e,...n},K0,J0)).ranges}async delete(e){await T(this.client,"/range/delete",{keys:e},X0,Q0)}}const nN=Object.freeze(Object.defineProperty({__proto__:null,Client:Xl,DELETE_ALIAS_CHANNEL_NAME:Fl,DELETE_CHANNEL_NAME:q0,KV_DELETE_CHANNEL:Wl,KV_SET_CHANNEL:Gl,Range:Kl,SET_ALIAS_CHANNEL_NAME:ql,SET_CHANNEL_NAME:B0,TYPE_ONTOLOGY_ID:V0,Writer:eh,alias:$0,aliasKey:Hl,aliasOntologyID:G0,convertOntologyResourceToPayload:Ql,decodeDeleteAliasChange:Vl,keyZ:X,kv:W0,kvPairKey:Jl,kvPairZ:yr,nameZ:fi,newZ:Hu,ontologyID:st,payloadZ:gn},Symbol.toStringTag,{value:"Module"})),rt=i.z.uuid(),mr=i.z.object({key:rt,name:i.z.string(),data:oe.unknownZ.or(i.z.string().transform(Ze)),snapshot:i.z.boolean()}),th=mr.partial({key:!0,snapshot:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),Ti=mr.extend({data:i.z.string().transform(Ze)}),Rt=i.z.uuid(),nh=i.z.object({key:i.z.string(),name:i.z.string(),selectors:i.z.string().array().default([]),strokeColor:i.z.string().optional(),fillColor:i.z.string().optional()}),rh=i.z.object({key:i.z.string(),name:i.z.string(),regions:nh.array()}),sh=i.z.object({key:i.z.string(),position:Ps.xy,orientation:iy.outer}),rN=i.z.object({zoom:i.z.number().positive().default(1),position:Ps.xy}),ih=i.z.object({svg:i.z.string().min(1,"SVG is required"),states:rh.array(),variant:i.z.string().min(1,"Variant is required"),handles:sh.array(),scale:i.z.number().positive().default(1),scaleStroke:i.z.boolean().default(!1),previewViewport:rN.default({zoom:1,position:{x:0,y:0}})}),gr=i.z.object({key:Rt,version:i.z.literal(1).default(1),name:i.z.string().min(1,"Name is required"),data:ih}),ah=gr.partial({key:!0}),sN=i.z.object({symbols:ah.array(),parent:B}),iN=i.z.object({key:Rt,name:i.z.string()}),aN=i.z.object({keys:Rt.array()}),oN=i.z.object({keys:Rt.array().optional(),searchTerm:i.z.string().optional()}),cN=i.z.object({key:Rt}).transform(({key:t})=>({keys:[t]})),uN=i.z.union([cN,oN]),lN=i.z.object({symbols:E.nullableZ(gr)}),hN=i.z.object({symbols:gr.array()}),Pa=i.z.object({}),fN=i.z.object({}),dN=i.z.object({group:ar}),pN="sy_schematic_symbol_set",yN="sy_schematic_symbol_delete";let oh=class{client;constructor(e){this.client=e}async create(e){const n="symbols"in e,r=n?e.symbols:[e],s=await T(this.client,"/schematic/symbol/create",{symbols:r,parent:e.parent},sN,hN);return n?s.symbols:s.symbols[0]}async rename(e,n){await T(this.client,"/schematic/symbol/rename",{key:e,name:n},iN,Pa)}async retrieve(e){const n="key"in e,r=await T(this.client,"/schematic/symbol/retrieve",e,uN,lN);return ue("Schematic Symbol",e,r.symbols,n),n?r.symbols[0]:r.symbols}async delete(e){await T(this.client,"/schematic/symbol/delete",{keys:E.toArray(e)},aN,Pa)}async retrieveGroup(){return(await T(this.client,"/schematic/symbol/retrieve-group",{},fN,dN)).group}};const mN=J("schematic_symbol"),gN=Object.freeze(Object.defineProperty({__proto__:null,Client:oh,DELETE_CHANNEL_NAME:yN,SET_CHANNEL_NAME:pN,handleZ:sh,keyZ:Rt,newZ:ah,ontologyID:mN,regionZ:nh,specZ:ih,stateZ:rh,symbolZ:gr},Symbol.toStringTag,{value:"Module"})),wN=i.z.object({key:rt,name:i.z.string()}),bN=i.z.object({key:rt,data:i.z.string()}),vN=i.z.object({keys:rt.array()}),zN=i.z.object({key:rt,name:i.z.string(),snapshot:i.z.boolean()}),TN=i.z.object({keys:rt.array()}),ch=i.z.object({key:rt}).transform(({key:t})=>({keys:[t]})),uh=i.z.union([ch,TN]),ON=i.z.object({schematics:E.nullableZ(Ti)}),SN=i.z.object({workspace:xe,schematics:th.array()}),EN=i.z.object({schematics:Ti.array()}),NN=i.z.object({schematic:mr}),Pr=i.z.object({});let lh=class{symbols;client;constructor(e){this.client=e,this.symbols=new oh(e)}async create(e,n){const r=Array.isArray(n),s=await T(this.client,"/schematic/create",{workspace:e,schematics:E.toArray(n)},SN,EN);return r?s.schematics:s.schematics[0]}async rename(e,n){await T(this.client,"/schematic/rename",{key:e,name:n},wN,Pr)}async setData(e,n){await T(this.client,"/schematic/set-data",{key:e,data:JSON.stringify(n)},bN,Pr)}async retrieve(e){const n=ch.safeParse(e).success,r=await T(this.client,"/schematic/retrieve",e,uh,ON);return ue("Schematic",e,r.schematics,n),n?r.schematics[0]:r.schematics}async delete(e){await T(this.client,"/schematic/delete",{keys:E.toArray(e)},vN,Pr)}async copy(e){return(await T(this.client,"/schematic/copy",e,zN,NN)).schematic}};const hh=J("schematic"),$N=hh(""),kN=Object.freeze(Object.defineProperty({__proto__:null,Client:lh,TYPE_ONTOLOGY_ID:$N,keyZ:rt,newZ:th,ontologyID:hh,remoteZ:Ti,retrieveArgsZ:uh,schematicZ:mr,symbol:gN},Symbol.toStringTag,{value:"Module"})),vn=i.z.string(),wr=t=>Qe.statusZ(t),fh=t=>wr(t).omit({labels:!0}).extend({key:vn.optional()}),ws="sy_status_set",AN="sy_status_delete",dh=J("status"),IN=dh(""),ZN=t=>i.object({parent:B.optional(),statuses:fh(t).array()}),xN=t=>i.object({statuses:wr(t).array()}),CN=i.object({keys:vn.array()}),_N=i.object({}),MN=i.object({keys:vn.array().optional(),searchTerm:i.string().optional(),offset:i.int().optional(),limit:i.int().optional(),includeLabels:i.boolean().optional(),hasLabels:nt.array().optional()}),RN=i.object({key:vn,includeLabels:i.boolean().optional()}).transform(({key:t,includeLabels:e})=>({keys:[t],includeLabels:e})),jN=i.union([RN,MN]),UN=t=>i.object({statuses:E.nullableZ(wr(t))});let ph=class{type="status";client;constructor(e){this.client=e}async retrieve(e){const n="key"in e,r=await T(this.client,"/status/retrieve",e,jN,UN(e.detailsSchema));ue("Status",e,r.statuses,n);const s=r.statuses;return n?s[0]:s}async set(e,n={}){const r=Array.isArray(e),a=(await T(this.client,"/status/set",{statuses:E.toArray(e),parent:n.parent},ZN(n.detailsSchema),xN(n.detailsSchema))).statuses;return r?a:a[0]}async delete(e){await T(this.client,"/status/delete",{keys:E.toArray(e)},CN,_N)}};const PN=Object.freeze(Object.defineProperty({__proto__:null,Client:ph,DELETE_CHANNEL_NAME:AN,SET_CHANNEL_NAME:ws,TYPE_ONTOLOGY_ID:IN,keyZ:vn,newZ:fh,ontologyID:dh,statusZ:wr},Symbol.toStringTag,{value:"Module"})),bt=i.z.uuid(),Oi=i.z.object({key:bt,name:i.z.string(),data:oe.unknownZ.or(i.z.string().transform(Ze))}),yh=Oi.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),Si=Oi.extend({data:i.z.string().transform(Ze)}),LN=i.z.object({key:bt,name:i.z.string()}),DN=i.z.object({key:bt,data:i.z.string()}),BN=i.z.object({keys:bt.array()}),qN=i.z.object({keys:bt.array()}),mh=i.z.object({key:bt}).transform(({key:t})=>({keys:[t]})),gh=i.z.union([mh,qN]),FN=i.z.object({tables:E.nullableZ(Si)}),YN=i.z.object({workspace:xe,tables:yh.array()}),HN=i.z.object({tables:Si.array()}),Lr=i.z.object({});let wh=class{client;constructor(e){this.client=e}async create(e,n){const r=Array.isArray(n),s=await T(this.client,"/table/create",{workspace:e,tables:E.toArray(n)},YN,HN);return r?s.tables:s.tables[0]}async rename(e,n){await T(this.client,"/table/rename",{key:e,name:n},LN,Lr)}async setData(e,n){await T(this.client,"/table/set-data",{key:e,data:JSON.stringify(n)},DN,Lr)}async retrieve(e){const n=mh.safeParse(e).success,r=await T(this.client,"/table/retrieve",e,gh,FN);return ue("Table",e,r.tables,n),n?r.tables[0]:r.tables}async delete(e){await T(this.client,"/table/delete",{keys:E.toArray(e)},BN,Lr)}};const bh=J("table"),VN=bh(""),GN=Object.freeze(Object.defineProperty({__proto__:null,Client:wh,TYPE_ONTOLOGY_ID:VN,keyZ:bt,newZ:yh,ontologyID:bh,remoteZ:Si,retrieveArgsZ:gh,tableZ:Oi},Symbol.toStringTag,{value:"Module"})),De=i.z.union([i.z.string(),i.z.bigint().transform(t=>t.toString()),i.z.number().transform(t=>t.toString())]),Ei=t=>i.z.object({task:De,running:i.z.boolean(),data:t,cmd:i.z.string().optional()}),Ni=t=>Qe.statusZ(Ei(t)),WN=t=>Ei(t).partial({task:!0}),vh=t=>Qe.statusZ(WN(t)).partial({key:!0,name:!0}),zn=(t={type:i.z.string(),config:oe.nullishToEmpty(),statusData:i.z.unknown()})=>i.z.object({key:De,name:i.z.string(),type:t.type,internal:i.z.boolean().optional(),config:t.config,status:Ni(t.statusData).optional().nullable(),snapshot:i.z.boolean().optional()}),zh=t=>zn(t).omit({key:!0,status:!0}).extend({key:De.transform(e=>e.toString()).optional(),config:t?.config??oe.nullishToEmpty(),status:vh(t?.statusData??i.z.unknown()).optional().nullable()}),JN=i.z.object({task:De,type:i.z.string(),key:i.z.string(),args:oe.unknownZ.or(i.z.string().transform(Ze)).or(i.z.array(i.z.unknown())).or(i.z.null()).optional()}),KN=t=>Number(BigInt(t)>>32n),XN=(t,e=0)=>((BigInt(t)<<32n)+BigInt(e)).toString(),bs="sy_task_cmd",QN="sy_task_set",e$="sy_task_delete",it=new Error("Task not created"),Th=async(t,e)=>{const n=await e.retrieveParents(Tn(t));return n.length===0?null:n[0]};class Oh{key;name;internal;type;snapshot;config;status;schemas;frameClient_;ontologyClient_;rangeClient_;get frameClient(){if(this.frameClient_==null)throw it;return this.frameClient_}get ontologyClient(){if(this.ontologyClient_==null)throw it;return this.ontologyClient_}get rangeClient(){if(this.rangeClient_==null)throw it;return this.rangeClient_}constructor({key:e,type:n,name:r,config:s,internal:a=!1,snapshot:o=!1,status:c},u,l,h,d){this.key=e,this.name=r,this.type=n,this.config=s,this.schemas=u??{type:i.z.string(),config:i.z.unknown(),statusData:i.z.unknown()},this.internal=a,this.snapshot=o,this.status=c,this.frameClient_=l,this.ontologyClient_=h,this.rangeClient_=d}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,status:this.status,internal:this.internal}}get ontologyID(){return Tn(this.key)}async executeCommand(e){return await Nh({...e,frameClient:this.frameClient,task:this.key})}async executeCommandSync(e){return await $h({...e,frameClient:this.frameClient,task:this.key,name:this.name,statusDataZ:this.schemas.statusData})}async start(){await this.executeCommand({type:"start"})}async stop(){await this.executeCommand({type:"stop"})}async run(e){await this.start();try{return await e()}finally{await this.stop()}}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw it;return this.snapshot?await Th(this.key,this.ontologyClient):null}}const t$=i.z.object({rack:Te.optional(),keys:De.array().optional(),names:i.z.string().array().optional(),types:i.z.string().array().optional(),includeStatus:i.z.boolean().optional(),internal:i.z.boolean().optional(),snapshot:i.z.boolean().optional(),searchTerm:i.z.string().optional(),offset:i.z.int().optional(),limit:i.z.int().optional()}),Sh=i.z.union([i.z.object({key:De,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),i.z.object({name:i.z.string(),includeStatus:i.z.boolean().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e})),i.z.object({type:i.z.string(),rack:Te.optional()}).transform(({type:t,rack:e})=>({types:[t],rack:e}))]),n$=t$,r$=i.z.union([Sh,n$]),s$=t=>i.z.object({tasks:E.nullableZ(zn(t))}),i$=t=>i.z.object({tasks:zh(t).array()}),a$=t=>i.z.object({tasks:zn(t).array()}),o$=i.z.object({keys:De.array()}),c$=i.z.object({}),u$=i.z.object({key:De,name:i.z.string(),snapshot:i.z.boolean()}),l$=t=>i.z.object({task:zn(t)});let Eh=class{client;frameClient;ontologyClient;rangeClient;constructor(e,n,r,s){this.client=e,this.frameClient=n,this.ontologyClient=r,this.rangeClient=s}async create(e,n){const r=!Array.isArray(e),s=i$(n),a=a$(n),o=await T(this.client,"/task/create",{tasks:E.toArray(e)},s,a),c=this.sugar(o.tasks,n);return r?c[0]:c}async delete(e){await T(this.client,"/task/delete",{keys:E.toArray(e)},o$,c$)}async retrieve({schemas:e,...n}){const r=Sh.safeParse(n).success,a=(await T(this.client,"/task/retrieve",n,r$,s$(e))).tasks,o=this.sugar(a,e);return ue("Task",n,o,r),r?o[0]:o}async copy(e,n,r){const s=l$(),a=await T(this.client,"/task/copy",{key:e,name:n,snapshot:r},u$,s);return this.sugar(a.task)}async list(e){const n={internal:!1};return e!==void 0&&(n.rack=e),await this.retrieve(n)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw it;return await Th(e,this.ontologyClient)}sugar(e,n){const r=!Array.isArray(e),s=E.toArray(e).map(({key:a,name:o,type:c,config:u,status:l,internal:h,snapshot:d})=>new Oh({key:a,name:o,type:c,config:u,internal:h,snapshot:d,status:l},n,this.frameClient,this.ontologyClient,this.rangeClient));return r?s[0]:s}async executeCommand(e){return"commands"in e?await $i({...e,frameClient:this.frameClient}):await Nh({...e,frameClient:this.frameClient})}async executeCommandSync(e){if("commands"in e){const r=async()=>{const{commands:s}=e;return(await this.retrieve({keys:s.map(o=>o.task)})).map(o=>o.name)};return await kh({...e,frameClient:this.frameClient,name:r})}const n=async()=>{const{task:r}=e;return(await this.retrieve({key:r})).name};return await $h({frameClient:this.frameClient,name:n,...e})}};const Tn=J("task"),h$=Tn(""),f$=t=>ke(Tn(t)),Nh=async({frameClient:t,task:e,type:n,args:r})=>(await $i({frameClient:t,commands:[{args:r,task:e,type:n}]}))[0],$i=async({frameClient:t,commands:e})=>{if(t==null)throw it;const n=await t.openWriter(bs),r=e.map(s=>({...s,key:Co.create()}));return await n.write(bs,r),await n.close(),r.map(s=>s.key)},$h=async({frameClient:t,task:e,type:n,timeout:r,name:s,statusDataZ:a,args:o})=>(await kh({frameClient:t,commands:[{args:o,task:e,type:n}],timeout:r,statusDataZ:a,name:s}))[0],kh=async({frameClient:t,commands:e,timeout:n=w.seconds(10),statusDataZ:r,name:s})=>{if(t==null)throw it;const a=await t.openStreamer(ws),o=await $i({frameClient:t,commands:e}),c=new w(n);let u=[],l;const h=new Promise((d,f)=>{l=setTimeout(()=>{(async()=>{const b=e.map(N=>N.task);f(await d$("command",s,c,b))})()},c.milliseconds)});try{for(;;){const d=await Promise.race([a.read(),h]),f=Ni(r).safeParse(d.at(-1)[ws]);if(!f.success)continue;const b=f.data;if(!(b.details.cmd==null||!o.includes(b.details.cmd))&&(u=[...u.filter(N=>N.key!==b.key),b],u.length===o.length))return u}}finally{clearTimeout(l),a.close()}},d$=async(t,e,n,r)=>{const s=Gd.capitalize(t),a=n.toString();try{let o;typeof e=="string"?o=[e]:Array.isArray(e)?o=e:o=E.toArray(await e());const c=os.naturalLanguageJoin(o);return new Error(`${s} command to ${c} timed out after ${a}`)}catch(o){return console.error("Failed to retrieve task name for timeout error:",o),new Error(`${s} command to task with key ${os.naturalLanguageJoin(r)} timed out after ${a}`)}},p$=Object.freeze(Object.defineProperty({__proto__:null,COMMAND_CHANNEL_NAME:bs,Client:Eh,DELETE_CHANNEL_NAME:e$,SET_CHANNEL_NAME:QN,TYPE_ONTOLOGY_ID:h$,Task:Oh,commandZ:JN,keyZ:De,newKey:XN,newStatusZ:vh,newZ:zh,ontologyID:Tn,rackKey:KN,statusDetailsZ:Ei,statusKey:f$,statusZ:Ni,taskZ:zn},Symbol.toStringTag,{value:"Module"}));class Ah{url;unary;stream;secure;constructor(e,n={},r=!1){this.secure=r,this.url=e.child("/api/v1/");const s=new Jn.JSONCodec;this.unary=Zd(new Id(this.url,s,this.secure),n),this.stream=new Rd(this.url,s,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const jt=i.uuid(),br=i.object({key:jt,name:i.string(),type:i.string(),query:oe.unknownZ}),Ih=br.extend({key:jt.optional()}),y$="sy_view_set",m$="sy_view_delete",g$=i.z.object({views:Ih.array()}),w$=i.z.object({views:br.array()}),b$=i.z.object({keys:jt.array()}),v$=i.z.object({}),z$=i.z.object({keys:jt.array().optional(),types:i.z.string().array().optional(),searchTerm:i.z.string().optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),T$=i.z.object({key:jt}).transform(({key:t})=>({keys:[t]})),O$=i.z.union([T$,z$]),S$=i.z.object({views:E.nullableZ(br)});class Zh{client;constructor(e){this.client=e}async retrieve(e){const n="key"in e,r=await T(this.client,"/view/retrieve",e,O$,S$);return ue("View",e,r.views,n),n?r.views[0]:r.views}async create(e){const n=Array.isArray(e),r=await T(this.client,"/view/create",{views:E.toArray(e)},g$,w$);return n?r.views:r.views[0]}async delete(e){await T(this.client,"/view/delete",{keys:E.toArray(e)},b$,v$)}}const xh=t=>({type:"view",key:t}),E$=xh(""),N$=Object.freeze(Object.defineProperty({__proto__:null,Client:Zh,DELETE_CHANNEL_NAME:m$,SET_CHANNEL_NAME:y$,TYPE_ONTOLOGY_ID:E$,keyZ:jt,newZ:Ih,ontologyID:xh,viewZ:br},Symbol.toStringTag,{value:"Module"})),Ch=i.z.object({host:i.z.string({error:"Host is required"}).min(1,"Host is required"),port:i.z.number({error:"Port is required"}).or(i.z.string({error:"Port is required"})),username:i.z.string().min(1,"Username is required"),password:i.z.string().min(1,"Password is required"),connectivityPollFrequency:w.z.default(w.seconds(30)),secure:i.z.boolean().default(!1),name:i.z.string().optional(),retry:Bs.breakerConfigZ.optional()});class _h extends ml{createdAt;params;ranges;channels;auth;users;access;connectivity;ontology;workspaces;labels;statuses;tasks;racks;devices;control;arcs;views;schematics;lineplots;logs;tables;groups;static connectivity=Yn;transport;clientVersion="0.53.1";constructor(e){const n=Ch.parse(e),{host:r,port:s,username:a,password:o,connectivityPollFrequency:c,secure:u,retry:l}=n,h=new Ah(new St({host:r,port:Number(s)}),l,u);h.use(_g);const d=new pi(new di(h.unary));super(h.stream,h.unary,d),this.auth=new LS(h.unary,{username:a,password:o}),h.use(this.auth.middleware());const f=new Xu(h.unary,d);this.createdAt=m.now(),this.params=n,this.transport=h,this.channels=new Ku(this,d,h.unary,f),this.connectivity=new Yn(h.unary,c,this.clientVersion,n.name),this.control=new bl(this),this.ontology=new Pc(this.transport.unary);const b=new eh(this.transport.unary);this.labels=new Fu(this.transport.unary),this.statuses=new ph(this.transport.unary),this.ranges=new Xl(this,b,this.transport.unary,d,this.labels,this.ontology),this.access=new Jc(this.transport.unary),this.users=new Fc(this.transport.unary),this.workspaces=new Il(this.transport.unary),this.tasks=new Eh(this.transport.unary,this,this.ontology,this.ranges),this.racks=new Dl(this.transport.unary,this.tasks),this.devices=new Nl(this.transport.unary),this.arcs=new Mu(this.transport.unary,this.transport.stream),this.views=new Zh(this.transport.unary),this.schematics=new lh(this.transport.unary),this.lineplots=new _l(this.transport.unary),this.logs=new Pl(this.transport.unary),this.tables=new wh(this.transport.unary),this.groups=new Ju(this.transport.unary)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stop()}}const $$=async t=>await Mh(t).check(),Mh=t=>{const{host:e,port:n,secure:r,name:s,retry:a}=t,o=Bs.breakerConfigZ.optional().parse(a),c=new St({host:e,port:Number(n)}),u=new Ah(c,o,r);return new Yn(u.unary,void 0,"0.53.1",s)},Rh={host:"localhost",port:9090,username:"synnax",password:"seldon",retry:{maxRetries:4,baseInterval:w.seconds(1),scale:1.5}},jh=t=>new _h({...Rh,...t}),k$=async(t,e)=>{const n=Co.create(),r=await t.users.create({username:n,password:"test",firstName:"test",lastName:"test"}),s=await t.access.policies.create(e),a=await t.access.roles.create({name:"test",description:"test"});return await t.ontology.addChildren(Qs(a.key),Ks(s.key)),await t.access.roles.assign({user:r.key,role:a.key}),jh({username:n,password:"test"})};exports.AuthError=kt;exports.Channel=Fn;exports.ContiguityError=Zg;exports.DataType=p;exports.Density=M;exports.DisconnectedError=Ig;exports.Frame=V;exports.MultiSeries=uc;exports.MultipleFoundError=tn;exports.NotFoundError=en;exports.QueryError=Ke;exports.Rate=G;exports.RouteError=ls;exports.Series=te;exports.Synnax=_h;exports.TEST_CLIENT_PARAMS=Rh;exports.TimeRange=x;exports.TimeSpan=w;exports.TimeStamp=m;exports.UnexpectedError=ct;exports.ValidationError=W;exports.access=Fw;exports.arc=DO;exports.channel=CS;exports.checkConnection=$$;exports.connection=qS;exports.control=OE;exports.createTestClient=jh;exports.createTestClientWithPolicy=k$;exports.device=RE;exports.framer=gE;exports.group=TS;exports.isCalculated=yi;exports.label=fS;exports.lineplot=n0;exports.log=h0;exports.newConnectionChecker=Mh;exports.ontology=Jg;exports.rack=E0;exports.ranger=nN;exports.schematic=kN;exports.status=PN;exports.synnaxParamsZ=Ch;exports.table=GN;exports.task=p$;exports.user=kw;exports.view=N$;exports.workspace=VE;
|
|
83
|
+
`,i=new TextEncoder,a=!1,o=!1,s=rS(t),{columns:c,columnsByIndexKey:l,emptyGroupStrings:u}=iS(t,s,n),d=[],f=0,p=[],m=e=>{for(let[t]of s){let n=e.get(t);if(n.length===0)continue;let r=(l.get(t)??[]).map(t=>e.get(t.key));for(let e=0;e<n.length;e++){let i=n.at(e,!0),a=r.map(t=>Wc.formatValue(t.at(e,!0)));p.push({time:i,values:a,indexKey:t})}}},h=(e,t=!1)=>{p.length>0&&(p.sort((e,t)=>Number(e.time-t.time)),f>0&&(d=d.slice(f),f=0),d=aS(d,p),p=[]);let n=[],r=d.length;for(;f<r&&n.length<e;){let e=d[f].time;if(!t&&d[r-1].time===e)break;let i=new Map;for(;f<r&&d[f].time===e;){let e=d[f++];i.set(e.indexKey,e)}let a=[];for(let[e]of s){let t=i.get(e);a.push(t?.values.join(`,`)??u.get(e)??``)}n.push(a.join(`,`))}return n};return new ReadableStream({async pull(t){try{if(o||=(await e.seekFirst(),!0),!a){let e=c.map(e=>Wc.formatValue(e.header)).join(`,`);t.enqueue(i.encode(`${e}${r}`)),a=!0}d.length-f+p.length<oS&&await e.next()&&m(e.value);let n=h(oS);if(n.length>0&&t.enqueue(i.encode(`${n.join(r)}${r}`)),d.length-f===0||p.length===0){if(!await e.next()){let n=h(1/0,!0);n.length>0&&t.enqueue(i.encode(`${n.join(r)}${r}`)),await e.close(),t.close();return}m(e.value)}}catch(n){await e.close(),t.error(n)}},async cancel(){await e.close()}})},rS=e=>{let t=new Map;for(let n of e){if(n.index===0)continue;let e=t.get(n.index);e??(e=[n.index],t.set(n.index,e)),!n.isIndex&&!e.includes(n.key)&&e.push(n.key)}return t},iS=(e,t,n)=>{let r=new Map(e.map(e=>[e.key,e])),i=[],a=new Map,o=new Map;for(let[e,s]of t){let t=[];for(let e of s){let a=r.get(e);if(a==null)throw new wu(`Channel ${e} not found`);let o={key:e,header:n?.[e]??n?.[a.name]??a.name};i.push(o),t.push(o)}a.set(e,t),o.set(e,`,`.repeat(t.length-1))}return{columns:i,columnsByIndexKey:a,emptyGroupStrings:o}},aS=(e,t)=>{let n=[],r=0,i=0;for(;r<e.length&&i<t.length;)e[r].time<=t[i].time?n.push(e[r++]):n.push(t[i++]);return n.push(...e.slice(r),...t.slice(i)),n},oS=1e3,sS=l.z.object({keys:l.z.number().array(),downsampleFactor:l.z.int(),throttleRate:Do.z.optional(),excludeGroups:l.z.uint32().array().optional()}),cS=l.z.object({frame:bx}),lS=l.z.object({channels:Bb,downsampleFactor:l.z.int().default(1),throttleRate:Do.z.default(new Do(0)),useHighPerformanceCodec:l.z.boolean().default(!0),excludeGroups:l.z.uint32().array().default([])}),uS=lS.or(Bb.transform(e=>lS.parse({channels:e}))),dS=(e,t)=>async n=>{let r=uS.parse(n),i=await Gx.open(e,r.channels);r.useHighPerformanceCodec&&(t=t.withCodec(new Wx(i.codec)));let a=await t.stream(`/frame/stream`,sS,cS),o=new pS(a,i,r.downsampleFactor,r.throttleRate,r.excludeGroups);a.send({keys:Array.from(i.keys),downsampleFactor:r.downsampleFactor,throttleRate:r.throttleRate,excludeGroups:r.excludeGroups});let[,s]=await a.receive();if(s!=null)throw s;return o},fS=async(e,t,n)=>await dS(e,t)(n),pS=class{stream;adapter;downsampleFactor;throttleRate;excludeGroups;constructor(e,t,n=1,r=new Do(0),i=[]){this.stream=new qx(`Streamer`,e),this.adapter=t,this.downsampleFactor=n,this.throttleRate=r,this.excludeGroups=i}get keys(){return Array.from(this.adapter.keys)}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(br.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new $((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e)&&this.stream.send({keys:Array.from(this.adapter.keys),downsampleFactor:this.downsampleFactor,throttleRate:this.throttleRate,excludeGroups:this.excludeGroups})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}},mS=class e{wrapped_=null;breaker;opener;config;constructor(e,t,n={}){this.opener=e,this.config=uS.parse(t);let{maxRetries:r=5e3,baseInterval:i=O.seconds(1),scale:a=1}=n??{};this.breaker=new fs.Breaker({maxRetries:r,baseInterval:i,scale:a})}static async open(t,n,r){let i=new e(t,n,r);return await i.runStreamer(),i}async runStreamer(){for(;;)try{this.wrapped_!=null&&this.wrapped_.close(),this.wrapped_=await this.opener(this.config),this.breaker.reset();return}catch(e){if(this.wrapped_=null,!await this.breaker.wait())throw e;console.error(`failed to open streamer`,e);continue}}get wrapped(){if(this.wrapped_==null)throw Error(`stream closed`);return this.wrapped_}async update(e){this.config.channels=Bb.parse(e);try{await this.wrapped.update(e)}catch{return await this.runStreamer(),await this.update(e)}}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(br.matches(e))return{done:!0,value:void 0};throw e}}async read(){try{let e=await this.wrapped.read();return this.breaker.reset(),e}catch(e){if(br.matches(e))throw e;return await this.runStreamer(),await this.read()}}close(){this.wrapped.close()}get keys(){return this.wrapped.keys}[Symbol.asyncIterator](){return this}},hS=class extends Tl.Observer{streamer;closePromise;constructor(e,t){super(t),this.streamer=e,this.closePromise=this.stream()}async update(e){await this.streamer.update(e)}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(let e of this.streamer)this.notify(e)}},gS=function(e){return e[e.PersistStream=1]=`PersistStream`,e[e.Persist=2]=`Persist`,e[e.Stream=3]=`Stream`,e}({}),_S=new O(-1),vS=class extends yu.sub(`writer_closed`){constructor(){super(`WriterClosed`)}},yS=l.z.enum(gS).or(l.z.enum([`persist`,`stream`,`persistStream`]).transform(e=>{switch(e){case`persist`:return gS.Persist;case`stream`:return gS.Stream;case`persistStream`:return gS.PersistStream}})),bS=l.z.object({start:D.z.optional(),controlSubject:F.subjectZ.optional(),authorities:l.z.union([F.authorityZ.transform(e=>[e]),F.authorityZ.array()]).default([F.ABSOLUTE_AUTHORITY]),mode:yS.default(gS.PersistStream),errOnUnauthorized:l.z.boolean().default(!1),enableAutoCommit:l.z.boolean().default(!0),autoIndexPersistInterval:O.z.default(O.SECOND),useHighPerformanceCodec:l.z.boolean().default(!0)}),xS=bS.extend({keys:Z.array().optional()}),SS=bS.extend({channels:Bb}),CS=SS.or(Bb.transform(e=>SS.parse({channels:e,start:D.now()}))),wS=l.z.object({command:l.z.enum(Cx),config:xS.optional(),frame:bx.optional(),buffer:l.z.instanceof(Uint8Array).optional()}),TS=l.z.object({command:l.z.enum(Cx),end:D.z,err:Zc.payloadZ.optional()}),ES=l.z.tuple([l.z.union([l.z.record(Z.or(nb),F.authorityZ),Z.or(nb),F.authorityZ]),F.authorityZ.optional()]).transform(([e,t])=>{if(F.authorityZ.safeParse(e).success)return{keys:[],authorities:[e]};if(Z.or(nb).safeParse(e).success){if(t==null)throw Error(`authority is required when setting authority for a single channel`);return{keys:[e],authorities:[t]}}let n=e;return{keys:Object.keys(n),authorities:Object.values(n)}}),DS=class e{stream;adapter;closeErr=null;constructor(e,t){this.stream=e,this.adapter=t}static async _open(t,n,r){let i=CS.parse(r),a=await Kx.open(t,i.channels);i.useHighPerformanceCodec&&(n=n.withCodec(new Ux(a.codec)));let o=new e(await n.stream(`/frame/write`,wS,TS),a);return await o.execute({command:Cx.Open,config:{...i,keys:a.keys}}),o}async write(e,t){if(this.closeErr!=null)throw this.closeErr;if(this.stream.received())return await this.close();let n=await this.adapter.adapt(e,t);this.stream.send({command:Cx.Write,frame:n.toPayload()})}async setAuthority(e,t){if(this.closeErr!=null)throw this.closeErr;let n=ES.parse([e,t]),r={keys:await this.adapter.adaptParams(n.keys),authorities:n.authorities};await this.execute({command:Cx.SetAuthority,config:r})}async commit(){if(this.closeErr!=null)throw this.closeErr;return this.stream.received()?(await this.closeInternal(null),D.ZERO):(await this.execute({command:Cx.Commit})).end}async close(){await this.closeInternal(null)}async closeInternal(e){if(this.closeErr!=null)throw this.closeErr;for(this.closeErr=e,this.stream.closeSend();;){if(this.closeErr!=null){if(vS.matches(this.closeErr))return null;throw this.closeErr}let[e,t]=await this.stream.receive();t==null?this.closeErr=Zc.decode(e?.err):this.closeErr=br.matches(t)?new vS:t}}async execute(e){let t=this.stream.send(e);for(t!=null&&await this.closeInternal(t);;){let[t,n]=await this.stream.receive();n!=null&&await this.closeInternal(n);let r=Zc.decode(t?.err);if(r!=null&&await this.closeInternal(r),t?.command==e.command)return t}}},OS=z(`framer`),kS=OS(``),AS=class{streamClient;retriever;deleter;reader;constructor(e,t,n){this.streamClient=e,this.retriever=n,this.deleter=new _x(t),this.reader=new tS(n,e)}async openIterator(e,t,n){return await $x._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return await DS._open(this.retriever,this.streamClient,e)}async openStreamer(e){return await fS(this.retriever,this.streamClient,e)}async write(e,t,n){if(n==null){let n=t,r=await this.openWriter({start:e,channels:Object.keys(n),mode:gS.Persist,errOnUnauthorized:!0,autoIndexPersistInterval:O.MAX});return await r.write(n),await r.close()}let r=await this.openWriter({start:e,channels:t,mode:gS.Persist,errOnUnauthorized:!0,autoIndexPersistInterval:O.MAX});await r.write(t,n),await r.close()}async read(e,t){if(!(`start`in e))return this.reader.read(e);let{single:n}=gb(t),r=await this.readFrame(e,t);return n?r.get(t):r}async readFrame(e,t){let n=await this.openIterator(e,t),r=new $;try{for await(let e of n)r.push(e)}finally{await n.close()}return r}async readLatest(e,t=1){let{single:n}=gb(e),r=await this.readLatestNFrame(e,t);return n?r.get(e):r}async readLatestNFrame(e,t){let n=await this.openIterator(A.MAX,e,{chunkSize:t}),r=new $;if(t>0)try{await n.seekLast(),await n.prev(Jx),r.push(n.value)}finally{await n.close()}return r}async delete(e,t){let{normalized:n,variant:r}=gb(e),i=new A(t);return r===`keys`?await this.deleter.delete({keys:n,bounds:i}):await this.deleter.delete({names:n,bounds:i})}},jS=o({ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:()=>_S,AUTO_SPAN:()=>Jx,Client:()=>AS,Frame:()=>$,HardenedStreamer:()=>mS,Iterator:()=>$x,ObservableStreamer:()=>hS,Reader:()=>tS,TYPE_ONTOLOGY_ID:()=>kS,Writer:()=>DS,WriterClosedError:()=>vS,WriterCommand:()=>Cx,WriterMode:()=>gS,createStreamOpener:()=>dS,frameZ:()=>bx,ontologyID:()=>OS,openStreamer:()=>fS,seriesFromPayload:()=>xx,seriesToPayload:()=>Sx,streamerConfigZ:()=>uS,writerCommandZ:()=>wx,writerConfigZ:()=>CS}),MS=F.ABSOLUTE_AUTHORITY,NS=F.ZERO_AUTHORITY,PS=F.stateZ(l.z.number()),FS=e=>{let t=e.from?.resource,n=e.to?.resource;return e.to==null?`${t} - ${e.from?.subject.name} -> released`:e.from==null?`${n} - released -> ${e.to.subject.name} (${e.to.authority.toString()})`:`${n} - ${e.from.subject.name} -> ${e.to.subject.name} (${e.to.authority.toString()})`},IS=l.z.object({transfers:l.z.array(F.transferZ(Z))}),LS=class extends hS{states;codec;constructor(e){super(e,e=>{let t=this.codec.decode(e.series[0].buffer,IS);return this.merge(t),[t.transfers,!0]}),this.states=new Map,this.codec=new ai.JSONCodec}subjects(){let e=new Map;return this.states.forEach(t=>e.set(t.subject.key,t.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(e=>{e.from==null&&e.to==null&&console.warn(`Invalid transfer: `,e),e.to==null?this.states.delete(e.from.resource):this.states.set(e.to.resource,e.to)})}},RS=`sy_node_1_control`,zS=class{framer;constructor(e){this.framer=e}async openStateTracker(){return new LS(await mS.open(async e=>await this.framer.openStreamer(e),RS))}},BS=o({ABSOLUTE_AUTHORITY:()=>MS,CONTROL_STATE_CHANNEL_NAME:()=>RS,Client:()=>zS,StateTracker:()=>LS,ZERO_AUTHORITY:()=>NS,stateZ:()=>PS,transferString:()=>FS}),VS=l.z.uint32(),HS=l.z.object({rack:VS}),US=cu.statusZ({details:HS}),WS=l.z.object({key:VS,name:l.z.string().min(1,`Name is required`),taskCounter:l.z.uint32().optional(),embedded:l.z.boolean().optional(),status:US.optional(),integrations:N.nullToUndefined(l.z.string().array())}),GS=WS.omit({taskCounter:!0,embedded:!0,key:!0}).extend({key:l.z.uint32().default(0)}),KS=z(`rack`),qS=KS(0),JS=`sy_rack_set`,YS=`sy_rack_delete`,XS=l.z.object({keys:VS.array().optional(),names:l.z.string().array().optional(),integration:l.z.string().optional(),searchTerm:l.z.string().optional(),embedded:l.z.boolean().optional(),hostIsNode:l.z.boolean().optional(),limit:l.z.int().optional(),offset:l.z.int().optional(),includeStatus:l.z.boolean().optional()}),ZS=l.z.object({racks:w.nullishToEmpty(WS)}),QS=WS,$S=l.z.union([l.z.object({key:VS,includeStatus:l.z.boolean().optional()}).transform(({key:e,includeStatus:t})=>({keys:[e],includeStatus:t})),l.z.object({name:l.z.string(),includeStatus:l.z.boolean().optional()}).transform(({name:e,includeStatus:t})=>({names:[e],includeStatus:t}))]),eC=XS,tC=l.z.union([$S,eC]),nC=l.z.object({racks:GS.array()}),rC=l.z.object({racks:WS.array()}),iC=l.z.object({keys:VS.array()}),aC=l.z.object({}),oC=class{client;tasks;constructor(e,t){this.client=e,this.tasks=t}async delete(e){await S(this.client,`/rack/delete`,{keys:w.toArray(e)},iC,aC)}async create(e){let t=!Array.isArray(e),n=await S(this.client,`/rack/create`,{racks:w.toArray(e)},nC,rC),r=this.sugar(n.racks);return t?r[0]:r}async retrieve(e){let t=`key`in e||`name`in e,n=await S(this.client,`/rack/retrieve`,e,tC,ZS),r=this.sugar(n.racks);return X(`Rack`,e,r,t),t?r[0]:r}sugar(e){let t=!Array.isArray(e),n=w.toArray(e).map(({key:e,name:t,status:n,integrations:r})=>new sC(e,t,this.tasks,n,r));return t?n[0]:n}},sC=class{key;name;status;integrations;tasks;constructor(e,t,n,r,i){this.key=e,this.name=t,this.tasks=n,this.status=r,this.integrations=i}async listTasks(){return await this.tasks.retrieve({rack:this.key})}async createTask(e,t){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&4294967295n)).toString(),await this.tasks.create(e,t)}async deleteTask(e){await this.tasks.delete([e])}get payload(){return{key:this.key,name:this.name,status:this.status,integrations:this.integrations}}},cC=e=>Ru(KS(e)),lC=o({Client:()=>oC,DELETE_CHANNEL_NAME:()=>YS,Rack:()=>sC,SET_CHANNEL_NAME:()=>JS,TYPE_ONTOLOGY_ID:()=>qS,keyZ:()=>VS,newZ:()=>GS,ontologyID:()=>KS,payloadZ:()=>WS,rackZ:()=>QS,statusDetailsZ:()=>HS,statusKey:()=>cC,statusZ:()=>US}),uC=l.z.object({rack:VS,device:l.z.string()}),dC=l.z.string(),fC=cu.statusZ({details:uC}),pC=({properties:e,make:t,model:n}={})=>l.z.object({key:dC,rack:VS,location:l.z.string().min(1,`Location is required`),make:t??l.z.string().min(1,`Make is required`),model:n??l.z.string().min(1,`Model is required`),name:l.z.string().min(1,`Name is required`),configured:l.z.boolean().default(!1),properties:e??I.nullishToEmpty(),status:fC.optional(),parent:R.optional()}),mC=({properties:e,make:t,model:n}={})=>pC({properties:e,make:t,model:n}).partial({key:!0,configured:!0}),hC=z(`device`),gC=hC(``),_C=`sy_device_set`,vC=`sy_device_delete`,yC=e=>l.z.object({devices:N.toArray(mC(e))}),bC=e=>l.z.object({devices:pC(e).array()}),xC=l.z.object({keys:dC.array()}),SC=l.z.object({}),CC=l.z.object({keys:dC.array().optional(),names:l.z.string().array().optional(),makes:l.z.string().array().optional(),models:l.z.string().array().optional(),locations:l.z.string().array().optional(),racks:VS.array().optional(),searchTerm:l.z.string().optional(),limit:l.z.int().optional(),offset:l.z.int().optional(),includeStatus:l.z.boolean().optional(),includeParent:l.z.boolean().optional()}),wC=e=>l.z.object({devices:w.nullishToEmpty(pC(e))}),TC=l.z.object({key:dC,includeStatus:l.z.boolean().optional()}).transform(({key:e,includeStatus:t})=>({keys:[e],includeStatus:t})),EC=l.z.union([TC,CC]),DC=class{client;constructor(e){this.client=e}async retrieve(e){let{schemas:t,...n}=e,r=typeof n==`object`&&`key`in n,i=await S(this.client,`/device/retrieve`,n,EC,wC(t));return X(`Device`,n,i.devices,r),r?i.devices[0]:i.devices}async create(e,t){let n=!Array.isArray(e),r=await S(this.client,`/device/create`,{devices:w.toArray(e)},yC(t),bC(t));return n?r.devices[0]:r.devices}async delete(e){await S(this.client,`/device/delete`,{keys:w.toArray(e)},xC,SC)}},OC=e=>Ru(hC(e)),kC=o({Client:()=>DC,DELETE_CHANNEL_NAME:()=>vC,SET_CHANNEL_NAME:()=>_C,TYPE_ONTOLOGY_ID:()=>gC,deviceZ:()=>pC,keyZ:()=>dC,newZ:()=>mC,ontologyID:()=>hC,statusDetailsZ:()=>uC,statusKey:()=>OC,statusZ:()=>fC}),AC=fl.keyZ,jC=fl.labelZ,MC=fl.newZ,NC=`labeled_by`,PC=`sy_label_set`,FC=`sy_label_delete`,IC=l.default.object({labels:MC.array()}),LC=l.default.object({labels:jC.array()}),RC=l.default.object({keys:AC.array()}),zC=l.default.object({id:R,labels:AC.array(),replace:l.default.boolean().optional()}),BC=zC.omit({replace:!0}),VC=l.default.object({}),HC=l.default.object({keys:AC.array().optional(),names:l.default.string().array().optional(),for:R.optional(),searchTerm:l.default.string().optional(),offset:l.default.int().optional(),limit:l.default.int().optional()}),UC=l.default.object({key:AC}).transform(({key:e})=>({keys:[e]})),WC=l.default.union([UC,HC]),GC=l.default.object({labels:w.nullishToEmpty(jC)}),KC=class{type=`label`;client;constructor(e){this.client=e}async retrieve(e){let t=`key`in e,n=await S(this.client,`/label/retrieve`,e,WC,GC);return X(`Label`,e,n.labels,t),t?n.labels[0]:n.labels}async label(e,t,n={}){await S(this.client,`/label/set`,{id:e,labels:t,replace:n.replace},zC,VC)}async remove(e,t){await S(this.client,`/label/remove`,{id:e,labels:t},BC,VC)}async create(e){let t=Array.isArray(e),n=await S(this.client,`/label/create`,{labels:w.toArray(e)},IC,LC);return t?n.labels:n.labels[0]}async delete(e){await S(this.client,`/label/delete`,{keys:w.toArray(e)},RC,VC)}},qC=z(`label`),JC=qC(``),YC=o({Client:()=>KC,DELETE_CHANNEL_NAME:()=>FC,LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE:()=>NC,SET_CHANNEL_NAME:()=>PC,TYPE_ONTOLOGY_ID:()=>JC,keyZ:()=>AC,labelZ:()=>jC,newZ:()=>MC,ontologyID:()=>qC}),XC=l.z.uuid(),ZC=l.z.object({key:XC,name:l.z.string(),data:Hr.preserveCase(I.nullishToEmpty())}),QC=ZC.partial({key:!0}),$C=z(`lineplot`),ew=$C(``),tw=l.z.uuid(),nw=l.z.object({key:tw,name:l.z.string().min(1,`Name is required`),author:l.z.uuid().optional(),layout:Hr.preserveCase(I.nullishToEmpty())}),rw=nw.omit({author:!0}).partial({key:!0}),iw=z(`workspace`),aw=iw(``),ow=l.z.object({keys:tw.array().optional(),searchTerm:l.z.string().optional(),author:Ad.optional(),offset:l.z.int().optional(),limit:l.z.int().optional()}),sw=l.z.object({workspaces:rw.array()}),cw=l.z.object({key:tw,name:l.z.string()}),lw=l.z.object({key:tw,layout:Hr.preserveCase(I.unknownZ())}),uw=l.z.object({keys:tw.array()}),dw=l.z.object({workspaces:w.nullishToEmpty(nw)}),fw=l.z.object({workspaces:nw.array()}),pw=l.z.object({}),mw=`sy_workspace_set`,hw=`sy_workspace_delete`,gw=class{client;constructor(e){this.client=e}async create(e){let t=Array.isArray(e),n=await S(this.client,`/workspace/create`,{workspaces:w.toArray(e)},sw,fw);return t?n.workspaces:n.workspaces[0]}async rename(e,t){await S(this.client,`/workspace/rename`,{key:e,name:t},cw,pw)}async setLayout(e,t){await S(this.client,`/workspace/set-layout`,{key:e,layout:t},lw,pw)}async retrieve(e){let t,n=typeof e!=`string`;t=typeof e==`string`||Array.isArray(e)?{keys:w.toArray(e)}:e;let r=await S(this.client,`/workspace/retrieve`,t,ow,dw);return n?r.workspaces:r.workspaces[0]}async delete(e){await S(this.client,`/workspace/delete`,{keys:w.toArray(e)},uw,pw)}},_w=o({Client:()=>gw,DELETE_CHANNEL_NAME:()=>hw,SET_CHANNEL_NAME:()=>mw,TYPE_ONTOLOGY_ID:()=>aw,keyZ:()=>tw,newZ:()=>rw,ontologyID:()=>iw,workspaceZ:()=>nw}),vw=l.z.object({key:XC,name:l.z.string()}),yw=l.z.object({key:XC,data:Hr.preserveCase(I.unknownZ())}),bw=l.z.object({keys:XC.array()}),xw=l.z.object({keys:XC.array()}),Sw=l.z.object({key:XC}).transform(({key:e})=>({keys:[e]})),Cw=l.z.union([Sw,xw]),ww=l.z.object({linePlots:w.nullishToEmpty(ZC)}),Tw=l.z.object({workspace:tw,linePlots:QC.array()}),Ew=l.z.object({linePlots:ZC.array()}),Dw=l.z.object({}),Ow=class{client;constructor(e){this.client=e}async create(e,t){let n=Array.isArray(t),r=await S(this.client,`/lineplot/create`,{workspace:e,linePlots:w.toArray(t)},Tw,Ew);return n?r.linePlots:r.linePlots[0]}async rename(e,t){await S(this.client,`/lineplot/rename`,{key:e,name:t},vw,Dw)}async setData(e,t){await S(this.client,`/lineplot/set-data`,{key:e,data:t},yw,Dw)}async retrieve(e){let t=Sw.safeParse(e).success,n=await S(this.client,`/lineplot/retrieve`,e,Cw,ww);return X(`LinePlot`,e,n.linePlots,t),t?n.linePlots[0]:n.linePlots}async delete(e){await S(this.client,`/lineplot/delete`,{keys:w.toArray(e)},bw,Dw)}},kw=o({Client:()=>Ow,TYPE_ONTOLOGY_ID:()=>ew,keyZ:()=>XC,linePlotZ:()=>ZC,newZ:()=>QC,ontologyID:()=>$C,retrieveArgsZ:()=>Cw}),Aw=l.z.uuid(),jw=l.z.object({key:Aw,name:l.z.string(),data:Hr.preserveCase(I.nullishToEmpty())}),Mw=jw.partial({key:!0}),Nw=z(`log`),Pw=Nw(``),Fw=l.z.object({key:Aw,name:l.z.string()}),Iw=l.z.object({key:Aw,data:Hr.preserveCase(I.unknownZ())}),Lw=l.z.object({keys:Aw.array()}),Rw=l.z.object({keys:Aw.array()}),zw=l.z.object({key:Aw}).transform(({key:e})=>({keys:[e]})),Bw=l.z.union([zw,Rw]),Vw=l.z.object({logs:w.nullishToEmpty(jw)}),Hw=l.z.object({workspace:tw,logs:Mw.array()}),Uw=l.z.object({logs:jw.array()}),Ww=l.z.object({}),Gw=class{client;constructor(e){this.client=e}async create(e,t){let n=Array.isArray(t),r=await S(this.client,`/log/create`,{workspace:e,logs:w.toArray(t)},Hw,Uw);return n?r.logs:r.logs[0]}async rename(e,t){await S(this.client,`/log/rename`,{key:e,name:t},Fw,Ww)}async setData(e,t){await S(this.client,`/log/set-data`,{key:e,data:t},Iw,Ww)}async retrieve(e){let t=zw.safeParse(e).success,n=await S(this.client,`/log/retrieve`,e,Bw,Vw);return X(`Log`,e,n.logs,t),t?n.logs[0]:n.logs}async delete(e){await S(this.client,`/log/delete`,{keys:w.toArray(e)},Lw,Ww)}},Kw=o({Client:()=>Gw,TYPE_ONTOLOGY_ID:()=>Pw,keyZ:()=>Aw,logZ:()=>jw,newZ:()=>Mw,ontologyID:()=>Nw,retrieveArgsZ:()=>Bw}),qw=l.z.object({range:Q,aliases:l.z.string().array()}),Jw=l.z.object({aliases:l.z.record(l.z.string(),Z)}),Yw=l.z.object({range:Q,aliases:l.z.record(Z,l.z.string())}),Xw=l.z.unknown(),Zw=l.z.object({range:Q,channels:Z.array()}),Qw=l.z.unknown(),$w=l.z.object({range:Q}),eT=l.z.object({aliases:l.z.record(l.z.string(),l.z.string())}),tT=l.z.object({range:Q,channels:Z.array()}),nT=l.z.object({aliases:l.z.record(l.z.string(),l.z.string())}),rT=class{cache=new Map;client;rangeKey;constructor(e,t){this.rangeKey=e,this.cache=new Map,this.client=t}async resolve(e){let t=[],n=typeof e==`string`,r={};if(n){let n=this.cache.get(e);if(n!=null)return n;t.push(e)}else e.forEach(e=>{let n=this.cache.get(e);n==null?t.push(e):r[e]=n});if(t.length===0)return r;let i=await S(this.client,`/range/alias/resolve`,{range:this.rangeKey,aliases:t},qw,Jw);return Object.entries(i.aliases).forEach(([e,t])=>this.cache.set(e,t)),n?i.aliases[t[0]]:{...r,...i.aliases}}async set(e){await S(this.client,`/range/alias/set`,{range:this.rangeKey,aliases:e},Yw,Xw)}async list(){return(await S(this.client,`/range/alias/list`,{range:this.rangeKey},$w,eT)).aliases}async retrieve(e){let t=typeof e==`number`,n=await S(this.client,`/range/alias/retrieve`,{range:this.rangeKey,channels:w.toArray(e)},tT,nT);return t?n.aliases[e]:n.aliases}async delete(e){await S(this.client,`/range/alias/delete`,{range:this.rangeKey,channels:w.toArray(e)},Zw,Qw)}},iT=`sy_range_alias_set`,aT=`sy_range_alias_delete`,oT=`---`,sT=e=>`${e.range}${oT}${e.channel}`,cT=(e,t)=>({type:`range-alias`,key:sT({range:e,channel:t})}),lT={type:`range-alias`,key:``},uT=e=>{let[t,n]=e.split(oT);return{range:t,channel:Number(n)}},dT=iT,fT=aT,pT=sT,mT=uT,hT=l.z.object({range:Q,channel:Z,alias:l.z.string()}),gT=o({Client:()=>rT,DELETE_ALIAS_CHANNEL_NAME:()=>fT,DELETE_CHANNEL_NAME:()=>aT,SET_ALIAS_CHANNEL_NAME:()=>dT,SET_CHANNEL_NAME:()=>iT,TYPE_ONTOLOGY_ID:()=>lT,aliasKey:()=>pT,aliasZ:()=>hT,createKey:()=>sT,decodeDeleteAliasChange:()=>mT,decodeDeleteChange:()=>uT,ontologyID:()=>cT}),_T=`sy_range_set`,vT=`sy_range_delete`,yT=class{key;name;kv;timeRange;color;parent;labels;channels;aliaser;frameClient;labelClient;ontologyClient;rangeClient;constructor({name:e,timeRange:t=A.ZERO,key:n,color:r,parent:i,labels:a},{frameClient:o,kv:s,aliaser:c,channels:l,labelClient:u,ontologyClient:d,rangeClient:f}){this.key=n,this.name=e,this.timeRange=t,this.parent=i,this.labels=a,this.frameClient=o,this.color=r,this.kv=s,this.aliaser=c,this.channels=l,this.labelClient=u,this.ontologyClient=d,this.rangeClient=f}get ontologyID(){return fb(this.key)}get payload(){let e={key:this.key,name:this.name,timeRange:this.timeRange,color:this.color,labels:this.labels};return this.parent!=null&&(`payload`in this.parent?e.parent=this.parent.payload:e.parent=this.parent),e}async setAlias(e,t){let n=await this.channels.retrieve(e);if(n.length===0)throw new Tu(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:t})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){let e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:[`range`]})).map(e=>e.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async retrieveLabels(){return await this.labelClient.retrieve({for:fb(this.key)})}async addLabel(...e){await this.labelClient.label(fb(this.key),e)}async removeLabel(...e){await this.labelClient.remove(fb(this.key),e)}static sort(e,t){return A.sort(e.timeRange,t.timeRange)}},bT=l.z.object({keys:Q.array().optional(),names:l.z.string().array().optional(),searchTerm:l.z.string().optional(),overlapsWith:A.z.optional(),hasLabels:AC.array().optional(),limit:l.z.int().optional(),offset:l.z.int().optional(),includeLabels:l.z.boolean().optional(),includeParent:l.z.boolean().optional()}).or(Q.array().transform(e=>({keys:e}))).or(Q.transform(e=>({keys:[e]}))).or(l.z.string().transform(e=>({names:[e]}))).or(l.z.string().array().transform(e=>({names:e}))).or(A.z.transform(e=>({overlapsWith:e}))),xT=l.z.object({ranges:w.nullishToEmpty(ub)}),ST=class{type=`range`;frameClient;writer;unaryClient;channels;labelClient;ontologyClient;createAliasClient;createKVClient;constructor(e,t,n,r,i,a,o,s){this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=r,this.labelClient=i,this.ontologyClient=a,this.createAliasClient=o,this.createKVClient=s}async create(e,t){let n=!Array.isArray(e),r=this.sugarMany(await this.writer.create(w.toArray(e),t));return n?r[0]:r}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(w.toArray(e))}async retrieve(e){let t=typeof e==`string`,{ranges:n}=await S(this.unaryClient,`/range/retrieve`,e,bT,xT);return X(`Range`,e,n,t),t?this.sugarMany(n)[0]:this.sugarMany(n)}getKV(e){return this.createKVClient(e)}async retrieveParent(e){let t=await this.ontologyClient.retrieveParents(fb(e));if(t.length===0)return null;let n=t[0];return n.id.type===`range`?await this.retrieve(n.id.key):null}sugarOntologyResource(e){return this.sugarOne(wT(e))}async retrieveAlias(e,t){return await this.createAliasClient(e).retrieve(t)}async retrieveAliases(e,t){return await this.createAliasClient(e).retrieve(t)}async listAliases(e){return await this.createAliasClient(e).list()}async setAlias(e,t,n){await this.createAliasClient(e).set({[t]:n})}async deleteAlias(e,t){await this.createAliasClient(e).delete(t)}sugarOne(e){return new yT(e,{frameClient:this.frameClient,kv:this.createKVClient(e.key),aliaser:this.createAliasClient(e.key),channels:this.channels,labelClient:this.labelClient,ontologyClient:this.ontologyClient,rangeClient:this})}sugarMany(e){return e.map(e=>this.sugarOne(e))}resourceToRange(e){return this.sugarOne(wT(e))}},CT=e=>({type:`range-alias`,key:e}),wT=({data:e,id:{key:t},name:n})=>{let r=A.z.parse(e?.timeRange),i=Nc.colorZ.safeParse(e?.color);return{key:t,name:n,timeRange:r,color:i.success?i.data:void 0,labels:[],parent:void 0}},TT=l.z.object({range:Q,key:l.z.string(),value:l.z.string()}),ET=l.z.object({range:Q,keys:l.z.string().array()}),DT=l.z.object({pairs:w.nullishToEmpty(TT)}),OT=l.z.object({range:Q,pairs:TT.array()}),kT=l.z.object({range:Q,keys:l.z.string().array()}),AT=class{rangeKey;client;constructor(e,t){this.rangeKey=e,this.client=t}async get(e){let t=await S(this.client,`/range/kv/get`,{range:this.rangeKey,keys:w.toArray(e)},ET,DT);return typeof e==`string`?t.pairs[0].value:Object.fromEntries(t.pairs.map(e=>[e.key,e.value]))}async list(){return this.get([])}async set(e,t=``){let n;n=typeof e==`string`?[{range:this.rangeKey,key:e,value:t}]:Object.entries(e).map(([e,t])=>({range:this.rangeKey,key:e,value:t})),await S(this.client,`/range/kv/set`,{range:this.rangeKey,pairs:n},OT,l.z.unknown())}async delete(e){await S(this.client,`/range/kv/delete`,{range:this.rangeKey,keys:w.toArray(e)},kT,l.z.unknown())}},jT=`sy_range_kv_set`,MT=`sy_range_kv_delete`,NT=({range:e,key:t})=>`${e}<--->${t}`,PT=jT,FT=MT,IT=TT,LT=NT,RT=o({Client:()=>AT,DELETE_CHANNEL_NAME:()=>MT,KV_DELETE_CHANNEL:()=>FT,KV_SET_CHANNEL:()=>PT,SET_CHANNEL_NAME:()=>jT,createPairKey:()=>NT,kvPairKey:()=>LT,kvPairZ:()=>IT,pairZ:()=>TT}),zT=l.z.string().min(1),BT=l.z.object({ranges:ub.array()}),VT=l.z.object({parent:R.optional(),ranges:db.array()}),HT=l.z.object({keys:Q.array()}),UT=l.z.object({}),WT=l.z.object({key:Q,name:zT}),GT=l.z.object({}),KT=class{client;constructor(e){this.client=e}async rename(e,t){await S(this.client,`/range/rename`,{key:e,name:t},WT,GT)}async create(e,t){return(await S(this.client,`/range/create`,{ranges:e,...t},VT,BT)).ranges}async delete(e){await S(this.client,`/range/delete`,{keys:e},HT,UT)}},qT=o({Client:()=>ST,DELETE_ALIAS_CHANNEL_NAME:()=>aT,DELETE_CHANNEL_NAME:()=>vT,KV_DELETE_CHANNEL:()=>MT,KV_SET_CHANNEL:()=>jT,Range:()=>yT,SET_ALIAS_CHANNEL_NAME:()=>iT,SET_CHANNEL_NAME:()=>_T,TYPE_ONTOLOGY_ID:()=>pb,Writer:()=>KT,alias:()=>gT,aliasKey:()=>sT,aliasOntologyID:()=>CT,apiRangeZ:()=>lb,baseZ:()=>cb,convertOntologyResourceToPayload:()=>wT,decodeDeleteAliasChange:()=>uT,keyZ:()=>Q,kv:()=>RT,kvPairKey:()=>NT,nameZ:()=>zT,newZ:()=>db,ontologyID:()=>fb,payloadZ:()=>ub}),JT=l.z.object({key:l.z.string(),name:l.z.string(),selectors:w.nullishToEmpty(l.z.string()),strokeColor:l.z.string().optional(),fillColor:l.z.string().optional()}),YT=l.z.object({key:l.z.string(),position:xo.xyZ,orientation:xo.outerLocationZ}),XT=l.z.object({zoom:l.z.number().default(1),position:xo.xyZ}),ZT=l.z.uuid(),QT=l.z.object({key:l.z.string(),name:l.z.string(),regions:w.nullishToEmpty(JT)}),$T=l.z.object({svg:l.z.string().min(1),states:w.nullishToEmpty(QT),variant:l.z.string().min(1),handles:w.nullishToEmpty(YT),scale:l.z.number().default(1),scaleStroke:l.z.boolean().default(!1),previewViewport:XT.optional()}),eE=l.z.object({key:ZT,version:l.z.uint32().default(1),name:l.z.string().min(1),data:$T}),tE=l.z.object({key:ZT.optional(),version:l.z.uint32().default(1),name:l.z.string().min(1),data:$T}),nE=z(`schematic_symbol`),rE=nE(``),iE=l.z.object({symbols:tE.array(),parent:R}),aE=l.z.object({key:ZT,name:l.z.string()}),oE=l.z.object({keys:ZT.array()}),sE=l.z.object({keys:ZT.array().optional(),searchTerm:l.z.string().optional()}),cE=l.z.object({key:ZT}).transform(({key:e})=>({keys:[e]})),lE=l.z.union([cE,sE]),uE=l.z.object({symbols:w.nullishToEmpty(eE)}),dE=l.z.object({symbols:eE.array()}),fE=l.z.object({}),pE=l.z.object({}),mE=l.z.object({group:Sb}),hE=`sy_schematic_symbol_set`,gE=`sy_schematic_symbol_delete`,_E=class{client;constructor(e){this.client=e}async create(e){let t=`symbols`in e,n=t?e.symbols:[e],r=await S(this.client,`/schematic/symbol/create`,{symbols:n,parent:e.parent},iE,dE);return t?r.symbols:r.symbols[0]}async rename(e,t){await S(this.client,`/schematic/symbol/rename`,{key:e,name:t},aE,fE)}async retrieve(e){let t=`key`in e,n=await S(this.client,`/schematic/symbol/retrieve`,e,lE,uE);return X(`Schematic Symbol`,e,n.symbols,t),t?n.symbols[0]:n.symbols}async delete(e){await S(this.client,`/schematic/symbol/delete`,{keys:w.toArray(e)},oE,fE)}async retrieveGroup(){return(await S(this.client,`/schematic/symbol/retrieve-group`,{},pE,mE)).group}},vE=o({Client:()=>_E,DELETE_CHANNEL_NAME:()=>gE,SET_CHANNEL_NAME:()=>hE,TYPE_ONTOLOGY_ID:()=>rE,handleZ:()=>YT,keyZ:()=>ZT,newZ:()=>tE,ontologyID:()=>nE,regionZ:()=>JT,specZ:()=>$T,stateZ:()=>QT,symbolZ:()=>eE,viewportZ:()=>XT}),yE=l.z.uuid(),bE=l.z.object({key:yE,name:l.z.string(),data:Hr.preserveCase(I.nullishToEmpty()),snapshot:l.z.boolean()}),xE=bE.partial({key:!0,snapshot:!0}),SE=z(`schematic`),CE=SE(``),wE=l.z.object({key:yE,name:l.z.string()}),TE=l.z.object({key:yE,data:Hr.preserveCase(I.unknownZ())}),EE=l.z.object({keys:yE.array()}),DE=l.z.object({key:yE,name:l.z.string(),snapshot:l.z.boolean()}),OE=l.z.object({keys:yE.array()}),kE=l.z.object({key:yE}).transform(({key:e})=>({keys:[e]})),AE=l.z.union([kE,OE]),jE=l.z.object({schematics:bE.array()}),ME=l.z.object({workspace:tw,schematics:xE.array()}),NE=l.z.object({schematics:bE.array()}),PE=l.z.object({schematic:bE}),FE=l.z.object({}),IE=class{symbols;client;constructor(e){this.client=e,this.symbols=new _E(e)}async create(e,t){let n=Array.isArray(t),r=await S(this.client,`/schematic/create`,{workspace:e,schematics:w.toArray(t)},ME,NE);return n?r.schematics:r.schematics[0]}async rename(e,t){await S(this.client,`/schematic/rename`,{key:e,name:t},wE,FE)}async setData(e,t){await S(this.client,`/schematic/set-data`,{key:e,data:t},TE,FE)}async retrieve(e){let t=kE.safeParse(e).success,n=await S(this.client,`/schematic/retrieve`,e,AE,jE);return X(`Schematic`,e,n.schematics,t),t?n.schematics[0]:n.schematics}async delete(e){await S(this.client,`/schematic/delete`,{keys:w.toArray(e)},EE,FE)}async copy(e){return(await S(this.client,`/schematic/copy`,e,DE,PE)).schematic}},LE=o({Client:()=>IE,TYPE_ONTOLOGY_ID:()=>CE,keyZ:()=>yE,newZ:()=>xE,ontologyID:()=>SE,retrieveArgsZ:()=>AE,schematicZ:()=>bE,symbol:()=>vE}),RE=l.z.string(),zE=e=>cu.statusZ({details:e}),BE=e=>cu.newZ({details:e}).omit({labels:!0}),VE=`sy_status_set`,HE=`sy_status_delete`,UE=z(`status`),WE=UE(``),GE=e=>l.default.object({parent:R.optional(),statuses:BE(e).array()}),KE=e=>l.default.object({statuses:zE(e).array()}),qE=l.default.object({keys:RE.array()}),JE=l.default.object({}),YE=l.default.object({keys:RE.array().optional(),searchTerm:l.default.string().optional(),offset:l.default.int().optional(),limit:l.default.int().optional(),includeLabels:l.default.boolean().optional(),hasLabels:AC.array().optional(),variants:l.default.string().array().optional()}),XE=l.default.object({key:RE,includeLabels:l.default.boolean().optional()}).transform(({key:e,includeLabels:t})=>({keys:[e],includeLabels:t})),ZE=l.default.union([XE,YE]),QE=e=>l.default.object({statuses:w.nullishToEmpty(zE(e))}),$E=class{type=`status`;client;constructor(e){this.client=e}async retrieve(e){let t=`key`in e,n=await S(this.client,`/status/retrieve`,e,ZE,QE(e.detailsSchema));X(`Status`,e,n.statuses,t);let r=n.statuses;return t?r[0]:r}async set(e,t={}){let n=Array.isArray(e),r=(await S(this.client,`/status/set`,{statuses:w.toArray(e),parent:t.parent},GE(t.detailsSchema),KE(t.detailsSchema))).statuses;return n?r:r[0]}async delete(e){await S(this.client,`/status/delete`,{keys:w.toArray(e)},qE,JE)}},eD=o({Client:()=>$E,DELETE_CHANNEL_NAME:()=>HE,SET_CHANNEL_NAME:()=>VE,TYPE_ONTOLOGY_ID:()=>WE,keyZ:()=>RE,newZ:()=>BE,ontologyID:()=>UE,statusZ:()=>zE}),tD=l.z.uuid(),nD=l.z.object({key:tD,name:l.z.string(),data:Hr.preserveCase(I.nullishToEmpty())}),rD=nD.partial({key:!0}),iD=z(`table`),aD=iD(``),oD=l.z.object({key:tD,name:l.z.string()}),sD=l.z.object({key:tD,data:Hr.preserveCase(I.unknownZ())}),cD=l.z.object({keys:tD.array()}),lD=l.z.object({keys:tD.array()}),uD=l.z.object({key:tD}).transform(({key:e})=>({keys:[e]})),dD=l.z.union([uD,lD]),fD=l.z.object({tables:w.nullishToEmpty(nD)}),pD=l.z.object({workspace:tw,tables:rD.array()}),mD=l.z.object({tables:nD.array()}),hD=l.z.object({}),gD=class{client;constructor(e){this.client=e}async create(e,t){let n=Array.isArray(t),r=await S(this.client,`/table/create`,{workspace:e,tables:w.toArray(t)},pD,mD);return n?r.tables:r.tables[0]}async rename(e,t){await S(this.client,`/table/rename`,{key:e,name:t},oD,hD)}async setData(e,t){await S(this.client,`/table/set-data`,{key:e,data:t},sD,hD)}async retrieve(e){let t=uD.safeParse(e).success,n=await S(this.client,`/table/retrieve`,e,dD,fD);return X(`Table`,e,n.tables,t),t?n.tables[0]:n.tables}async delete(e){await S(this.client,`/table/delete`,{keys:w.toArray(e)},cD,hD)}},_D=o({Client:()=>gD,TYPE_ONTOLOGY_ID:()=>aD,keyZ:()=>tD,newZ:()=>rD,ontologyID:()=>iD,retrieveArgsZ:()=>dD,tableZ:()=>nD}),vD=l.z.string().or(l.z.number().transform(String).or(l.z.bigint().transform(String))),yD=e=>l.z.object({task:vD,running:l.z.boolean(),cmd:l.z.string().optional(),data:e??l.z.unknown().optional()}),bD=e=>l.z.object({task:vD.optional(),running:l.z.boolean(),cmd:l.z.string().optional(),data:e??l.z.unknown().optional()}),xD=l.z.object({task:vD,type:l.z.string(),key:l.z.string(),args:Hr.preserveCase(N.nullToUndefined(I.unknownZ()))}),SD=e=>cu.statusZ({details:yD(e)}),CD=e=>cu.newZ({details:bD(e)}),wD=({type:e,config:t,statusData:n}={})=>l.z.object({key:vD,name:l.z.string(),type:e??l.z.string(),config:t??I.nullishToEmpty(),internal:l.z.boolean().optional(),snapshot:l.z.boolean().optional(),status:cu.statusZ({details:yD(n)}).optional()}),TD=({type:e,config:t,statusData:n}={})=>wD({type:e,config:t,statusData:n}).omit({internal:!0,snapshot:!0,status:!0}).partial({key:!0}).extend({status:cu.newZ({details:bD(n)}).optional()}),ED=z(`task`),DD=ED(``),OD=`sy_task_cmd`,kD=`sy_task_set`,AD=`sy_task_delete`,jD=Error(`Task not created`),MD=e=>Number(BigInt(e)>>32n),ND=(e,t=0)=>((BigInt(e)<<32n)+BigInt(t)).toString(),PD=async(e,t)=>{let n=await t.retrieveParents(ED(e));return n.length===0?null:n[0]},FD=class{key;name;internal;type;snapshot;config;status;schemas;frameClient_;ontologyClient_;rangeClient_;get frameClient(){if(this.frameClient_==null)throw jD;return this.frameClient_}get ontologyClient(){if(this.ontologyClient_==null)throw jD;return this.ontologyClient_}get rangeClient(){if(this.rangeClient_==null)throw jD;return this.rangeClient_}constructor({key:e,type:t,name:n,config:r,internal:i=!1,snapshot:a=!1,status:o},s,c,u,d){this.key=e,this.name=n,this.type=t,this.config=r,this.schemas=s??{type:l.z.string(),config:l.z.unknown(),statusData:l.z.unknown()},this.internal=i,this.snapshot=a,this.status=o,this.frameClient_=c,this.ontologyClient_=u,this.rangeClient_=d}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,status:this.status,internal:this.internal}}get ontologyID(){return ED(this.key)}async executeCommand(e){return await YD({...e,frameClient:this.frameClient,task:this.key})}async executeCommandSync(e){return await ZD({...e,frameClient:this.frameClient,task:this.key,name:this.name,statusDataZ:this.schemas.statusData})}async start(){await this.executeCommand({type:`start`})}async stop(){await this.executeCommand({type:`stop`})}async run(e){await this.start();try{return await e()}finally{await this.stop()}}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw jD;return this.snapshot?await PD(this.key,this.ontologyClient):null}},ID=l.z.object({rack:VS.optional(),keys:vD.array().optional(),names:l.z.string().array().optional(),types:l.z.string().array().optional(),includeStatus:l.z.boolean().optional(),internal:l.z.boolean().optional(),snapshot:l.z.boolean().optional(),searchTerm:l.z.string().optional(),offset:l.z.int().optional(),limit:l.z.int().optional()}),LD=l.z.union([l.z.object({key:vD,includeStatus:l.z.boolean().optional()}).transform(({key:e,includeStatus:t})=>({keys:[e],includeStatus:t})),l.z.object({name:l.z.string(),includeStatus:l.z.boolean().optional()}).transform(({name:e,includeStatus:t})=>({names:[e],includeStatus:t})),l.z.object({type:l.z.string(),rack:VS.optional()}).transform(({type:e,rack:t})=>({types:[e],rack:t}))]),RD=ID,zD=l.z.union([LD,RD]),BD=e=>l.z.object({tasks:w.nullishToEmpty(wD(e))}),VD=e=>l.z.object({tasks:TD(e).array()}),HD=e=>l.z.object({tasks:wD(e).array()}),UD=l.z.object({keys:vD.array()}),WD=l.z.object({}),GD=l.z.object({key:vD,name:l.z.string(),snapshot:l.z.boolean()}),KD=e=>l.z.object({task:wD(e)}),qD=class{client;frameClient;ontologyClient;rangeClient;constructor(e,t,n,r){this.client=e,this.frameClient=t,this.ontologyClient=n,this.rangeClient=r}async create(e,t){let n=!Array.isArray(e),r=VD(t),i=HD(t),a=await S(this.client,`/task/create`,{tasks:w.toArray(e)},r,i),o=this.sugar(a.tasks,t);return n?o[0]:o}async delete(e){await S(this.client,`/task/delete`,{keys:w.toArray(e)},UD,WD)}async retrieve({schemas:e,...t}){let n=LD.safeParse(t).success,r=(await S(this.client,`/task/retrieve`,t,zD,BD(e))).tasks,i=this.sugar(r,e);return X(`Task`,t,i,n),n?i[0]:i}async copy(e,t,n){let r=KD(),i=await S(this.client,`/task/copy`,{key:e,name:t,snapshot:n},GD,r);return this.sugar(i.task)}async list(e){let t={internal:!1};return e!==void 0&&(t.rack=e),await this.retrieve(t)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw jD;return await PD(e,this.ontologyClient)}sugar(e,t){let n=!Array.isArray(e),r=w.toArray(e).map(({key:e,name:n,type:r,config:i,status:a,internal:o,snapshot:s})=>new FD({key:e,name:n,type:r,config:i,internal:o,snapshot:s,status:a},t,this.frameClient,this.ontologyClient,this.rangeClient));return n?r[0]:r}async executeCommand(e){return`commands`in e?await XD({...e,frameClient:this.frameClient}):await YD({...e,frameClient:this.frameClient})}async executeCommandSync(e){if(`commands`in e){let t=async()=>{let{commands:t}=e;return(await this.retrieve({keys:t.map(e=>e.task)})).map(e=>e.name)};return await QD({...e,frameClient:this.frameClient,name:t})}return await ZD({frameClient:this.frameClient,name:async()=>{let{task:t}=e;return(await this.retrieve({key:t})).name},...e})}},JD=e=>Ru(ED(e)),YD=async({frameClient:e,task:t,type:n,args:r})=>(await XD({frameClient:e,commands:[{args:r,task:t,type:n}]}))[0],XD=async({frameClient:e,commands:t})=>{if(e==null)throw jD;let n=await e.openWriter(OD),r=t.map(e=>({...e,key:Li.create()}));return await n.write(OD,r),await n.close(),r.map(e=>e.key)},ZD=async({frameClient:e,task:t,type:n,timeout:r,name:i,statusDataZ:a,args:o})=>(await QD({frameClient:e,commands:[{args:o,task:t,type:n}],timeout:r,statusDataZ:a,name:i}))[0],QD=async({frameClient:e,commands:t,timeout:n=O.seconds(10),statusDataZ:r,name:i})=>{if(e==null)throw jD;let a=await e.openStreamer(VE),o=await XD({frameClient:e,commands:t}),s=new O(n),c=[],l,u=new Promise((e,n)=>{l=setTimeout(()=>{(async()=>{n(await $D(`command`,i,s,t.map(e=>e.task)))})()},s.milliseconds)});try{for(;;){let e=await Promise.race([a.read(),u]),t=SD(r).safeParse(e.at(-1)[VE]);if(!t.success)continue;let n=t.data;if(!(n.details.cmd==null||!o.includes(n.details.cmd))&&(c=[...c.filter(e=>e.key!==n.key),n],c.length===o.length))return c}}finally{clearTimeout(l),a.close()}},$D=async(e,t,n,r)=>{let i=Hr.capitalize(e),a=n.toString();try{let e;e=typeof t==`string`?[t]:Array.isArray(t)?t:w.toArray(await t());let n=mu.naturalLanguageJoin(e);return Error(`${i} command to ${n} timed out after ${a}`)}catch(e){return console.error(`Failed to retrieve task name for timeout error:`,e),Error(`${i} command to task with key ${mu.naturalLanguageJoin(w.toArray(r).map(e=>e.toString()))} timed out after ${a}`)}},eO=o({COMMAND_CHANNEL_NAME:()=>OD,Client:()=>qD,DELETE_CHANNEL_NAME:()=>AD,SET_CHANNEL_NAME:()=>kD,TYPE_ONTOLOGY_ID:()=>DD,Task:()=>FD,commandZ:()=>xD,keyZ:()=>vD,newKey:()=>ND,newStatusDetailsZ:()=>bD,newStatusZ:()=>CD,newZ:()=>TD,ontologyID:()=>ED,payloadZ:()=>wD,rackKey:()=>MD,statusDetailsZ:()=>yD,statusKey:()=>JD,statusZ:()=>SD}),tO=class{url;unary;stream;secure;constructor(e,t={},n=!1){this.secure=n,this.url=e.child(`/api/v1/`);let r=new ai.JSONCodec;this.unary=kr(new Or(this.url,r,this.secure),t),this.stream=new Pr(this.url,r,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}},nO=l.z.uuid(),rO=l.z.object({key:nO,name:l.z.string(),type:l.z.string(),query:I.nullishToEmpty()}),iO=rO.partial({key:!0}),aO=z(`view`),oO=aO(``),sO=`sy_view_set`,cO=`sy_view_delete`,lO=l.z.object({views:iO.array()}),uO=l.z.object({views:rO.array()}),dO=l.z.object({keys:nO.array()}),fO=l.z.object({}),pO=l.z.object({keys:nO.array().optional(),types:l.z.string().array().optional(),searchTerm:l.z.string().optional(),offset:l.z.number().optional(),limit:l.z.number().optional()}),mO=l.z.object({key:nO}).transform(({key:e})=>({keys:[e]})),hO=l.z.union([mO,pO]),gO=l.z.object({views:w.nullishToEmpty(rO)}),_O=class{client;constructor(e){this.client=e}async retrieve(e){let t=`key`in e,n=await S(this.client,`/view/retrieve`,e,hO,gO);return X(`View`,e,n.views,t),t?n.views[0]:n.views}async create(e){let t=Array.isArray(e),n=await S(this.client,`/view/create`,{views:w.toArray(e)},lO,uO);return t?n.views:n.views[0]}async delete(e){await S(this.client,`/view/delete`,{keys:w.toArray(e)},dO,fO)}},vO=o({Client:()=>_O,DELETE_CHANNEL_NAME:()=>cO,SET_CHANNEL_NAME:()=>sO,TYPE_ONTOLOGY_ID:()=>oO,keyZ:()=>nO,newZ:()=>iO,ontologyID:()=>aO,viewZ:()=>rO}),yO=l.z.object({host:l.z.string({error:`Host is required`}).min(1,`Host is required`),port:l.z.number({error:`Port is required`}).or(l.z.string({error:`Port is required`})),username:l.z.string().min(1,`Username is required`),password:l.z.string().min(1,`Password is required`),connectivityPollFrequency:O.z.default(O.seconds(30)),secure:l.z.boolean().default(!1),name:l.z.string().optional(),retry:fs.breakerConfigZ.optional()}),bO=class extends AS{createdAt;params;ranges;channels;auth;users;access;connectivity;ontology;workspaces;labels;statuses;tasks;racks;devices;control;arcs;views;schematics;lineplots;logs;tables;groups;static connectivity=mx;transport;clientVersion=`0.54.0`;constructor(e){let t=yO.parse(e),{host:n,port:r,username:i,password:a,connectivityPollFrequency:o,secure:s,retry:c}=t,l=new tO(new vu({host:n,port:Number(r)}),c,s);l.use(Nu);let u=new vb(new _b(l.unary));super(l.stream,l.unary,u),this.auth=new ox(l.unary,{username:i,password:a}),l.use(this.auth.middleware());let d=new Zb(l.unary,u);this.createdAt=D.now(),this.params=t,this.transport=l,this.channels=new Rb(this,u,l.unary,d),this.connectivity=new mx(l.unary,o,this.clientVersion,t.name),this.control=new zS(this),this.ontology=new $u(this.transport.unary);let f=new KT(this.transport.unary);this.labels=new KC(this.transport.unary),this.statuses=new $E(this.transport.unary),this.ranges=new ST(this,f,this.transport.unary,u,this.labels,this.ontology,e=>new rT(e,this.transport.unary),e=>new AT(e,this.transport.unary)),this.access=new vf(this.transport.unary),this.users=new Yd(this.transport.unary),this.workspaces=new gw(this.transport.unary),this.tasks=new qD(this.transport.unary,this,this.ontology,this.ranges),this.racks=new oC(this.transport.unary,this.tasks),this.devices=new DC(this.transport.unary),this.arcs=new By(this.transport.unary,this.transport.stream),this.views=new _O(this.transport.unary),this.schematics=new IE(this.transport.unary),this.lineplots=new Ow(this.transport.unary),this.logs=new Gw(this.transport.unary),this.tables=new gD(this.transport.unary),this.groups=new jb(this.transport.unary)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stop()}},xO=async e=>await SO(e).check(),SO=e=>{let{host:t,port:n,secure:r,name:i,retry:a}=e,o=fs.breakerConfigZ.optional().parse(a);return new mx(new tO(new vu({host:t,port:Number(n)}),o,r).unary,void 0,`0.54.0`,i)},CO={host:`localhost`,port:9090,username:`synnax`,password:`seldon`,retry:{maxRetries:4,baseInterval:O.seconds(1),scale:1.5}},wO=e=>new bO({...CO,...e}),TO=async(e,t)=>{let n=Li.create(),r=await e.users.create({username:n,password:`test`,firstName:`test`,lastName:`test`}),i=await e.access.policies.create(t),a=await e.access.roles.create({name:`test`,description:`test`});return await e.ontology.addChildren(Od(a.key),cd(i.key)),await e.access.roles.assign({user:r.key,role:a.key}),wO({username:n,password:`test`})};exports.AuthError=xu,exports.Channel=Fb,exports.ContiguityError=Mu,exports.DataType=j,exports.Density=k,exports.DisconnectedError=ju,exports.Frame=$,exports.MultiSeries=os,exports.MultipleFoundError=Du,exports.NotFoundError=Eu,exports.QueryError=Tu,exports.Rate=Do,exports.RouteError=Ou,exports.Series=Qo,exports.Synnax=bO,exports.TEST_CLIENT_PARAMS=CO,exports.TimeRange=A,exports.TimeSpan=O,exports.TimeStamp=D,exports.UnexpectedError=wu,exports.ValidationError=L,Object.defineProperty(exports,`access`,{enumerable:!0,get:function(){return bf}}),Object.defineProperty(exports,`arc`,{enumerable:!0,get:function(){return Uy}}),Object.defineProperty(exports,`channel`,{enumerable:!0,get:function(){return Qb}}),exports.checkConnection=xO,Object.defineProperty(exports,`connection`,{enumerable:!0,get:function(){return sx}}),Object.defineProperty(exports,`control`,{enumerable:!0,get:function(){return BS}}),exports.createTestClient=wO,exports.createTestClientWithPolicy=TO,Object.defineProperty(exports,`device`,{enumerable:!0,get:function(){return kC}}),Object.defineProperty(exports,`framer`,{enumerable:!0,get:function(){return jS}}),Object.defineProperty(exports,`group`,{enumerable:!0,get:function(){return Mb}}),exports.isCalculated=zb,Object.defineProperty(exports,`label`,{enumerable:!0,get:function(){return YC}}),Object.defineProperty(exports,`lineplot`,{enumerable:!0,get:function(){return kw}}),Object.defineProperty(exports,`log`,{enumerable:!0,get:function(){return Kw}}),exports.newConnectionChecker=SO,Object.defineProperty(exports,`ontology`,{enumerable:!0,get:function(){return id}}),Object.defineProperty(exports,`rack`,{enumerable:!0,get:function(){return lC}}),Object.defineProperty(exports,`ranger`,{enumerable:!0,get:function(){return qT}}),Object.defineProperty(exports,`schematic`,{enumerable:!0,get:function(){return LE}}),Object.defineProperty(exports,`status`,{enumerable:!0,get:function(){return eD}}),exports.synnaxParamsZ=yO,Object.defineProperty(exports,`table`,{enumerable:!0,get:function(){return _D}}),Object.defineProperty(exports,`task`,{enumerable:!0,get:function(){return eO}}),Object.defineProperty(exports,`user`,{enumerable:!0,get:function(){return Qd}}),Object.defineProperty(exports,`view`,{enumerable:!0,get:function(){return vO}}),Object.defineProperty(exports,`workspace`,{enumerable:!0,get:function(){return _w}});
|