@synnaxlabs/client 0.2.0 → 0.13.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +18 -0
- package/.pytest_cache/README.md +8 -0
- package/.turbo/turbo-build.log +16 -0
- package/LICENSE +4 -21
- package/{build/main/lib → dist/auth}/auth.d.ts +16 -19
- package/dist/auth/index.d.ts +1 -0
- package/dist/cdc/external.d.ts +1 -0
- package/dist/cdc/index.d.ts +1 -0
- package/dist/cdc/observable.d.ts +17 -0
- package/dist/channel/client.d.ts +58 -0
- package/dist/channel/creator.d.ts +8 -0
- package/dist/channel/external.d.ts +4 -0
- package/dist/channel/index.d.ts +1 -0
- package/dist/channel/payload.d.ts +63 -0
- package/dist/channel/retriever.d.ts +49 -0
- package/dist/client.cjs.js +23050 -0
- package/dist/client.cjs.js.map +1 -0
- package/dist/client.d.ts +73 -0
- package/dist/client.es.js +23050 -0
- package/dist/client.es.js.map +1 -0
- package/dist/connection/checker.d.ts +66 -0
- package/dist/connection/index.d.ts +1 -0
- package/dist/control/authority.d.ts +6 -0
- package/dist/control/external.d.ts +2 -0
- package/dist/control/index.d.ts +1 -0
- package/dist/control/state.d.ts +81 -0
- package/{build/main/lib → dist}/errors.d.ts +6 -3
- package/dist/framer/adapter.d.ts +21 -0
- package/dist/framer/client.d.ts +44 -0
- package/dist/framer/external.d.ts +5 -0
- package/dist/framer/frame.d.ts +251 -0
- package/dist/framer/index.d.ts +1 -0
- package/{build/module/lib/segment → dist/framer}/iterator.d.ts +32 -64
- package/dist/framer/streamProxy.d.ts +12 -0
- package/dist/framer/streamer.d.ts +17 -0
- package/dist/framer/writer.d.ts +257 -0
- package/dist/index.d.ts +16 -0
- package/dist/label/client.d.ts +25 -0
- package/dist/label/external.d.ts +4 -0
- package/dist/label/index.d.ts +1 -0
- package/dist/label/payload.d.ts +20 -0
- package/dist/label/retriever.d.ts +13 -0
- package/dist/label/writer.d.ts +26 -0
- package/dist/ontology/cdc.d.ts +25 -0
- package/dist/ontology/client.d.ts +25 -0
- package/dist/ontology/external.d.ts +3 -0
- package/dist/ontology/group/client.d.ts +11 -0
- package/dist/ontology/group/external.d.ts +2 -0
- package/dist/ontology/group/group.d.ts +7 -0
- package/dist/ontology/group/index.d.ts +1 -0
- package/dist/ontology/group/payload.d.ts +40 -0
- package/dist/ontology/group/writer.d.ts +13 -0
- package/dist/ontology/index.d.ts +1 -0
- package/dist/ontology/ontology.spec.d.ts +1 -0
- package/dist/ontology/payload.d.ts +235 -0
- package/dist/ontology/retriever.d.ts +12 -0
- package/dist/ontology/signals.d.ts +25 -0
- package/dist/ontology/writer.d.ts +9 -0
- package/dist/ranger/active.d.ts +9 -0
- package/dist/ranger/alias.d.ts +32 -0
- package/dist/ranger/client.d.ts +31 -0
- package/dist/ranger/external.d.ts +6 -0
- package/dist/ranger/index.d.ts +1 -0
- package/dist/ranger/kv.d.ts +50 -0
- package/dist/ranger/payload.d.ts +94 -0
- package/dist/ranger/range.d.ts +29 -0
- package/dist/ranger/ranger.spec.d.ts +1 -0
- package/dist/ranger/retriever.d.ts +10 -0
- package/dist/ranger/writer.d.ts +9 -0
- package/{build/main → dist}/setupspecs.d.ts +2 -2
- package/dist/signals/external.d.ts +1 -0
- package/dist/signals/index.d.ts +1 -0
- package/dist/signals/observable.d.ts +17 -0
- package/dist/transport.d.ts +10 -0
- package/dist/user/index.d.ts +1 -0
- package/{build/main/lib → dist}/user/payload.d.ts +3 -3
- package/dist/util/telem.d.ts +2 -0
- package/dist/workspace/client.d.ts +22 -0
- package/dist/workspace/external.d.ts +2 -0
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/lineplot/client.d.ts +15 -0
- package/dist/workspace/lineplot/external.d.ts +2 -0
- package/dist/workspace/lineplot/index.d.ts +1 -0
- package/dist/workspace/lineplot/linePlot.spec.d.ts +1 -0
- package/dist/workspace/lineplot/payload.d.ts +31 -0
- package/dist/workspace/lineplot/retriever.d.ts +9 -0
- package/dist/workspace/lineplot/writer.d.ts +39 -0
- package/dist/workspace/payload.d.ts +31 -0
- package/dist/workspace/pid/client.d.ts +16 -0
- package/dist/workspace/pid/external.d.ts +2 -0
- package/dist/workspace/pid/index.d.ts +1 -0
- package/dist/workspace/pid/payload.d.ts +37 -0
- package/dist/workspace/pid/pid.spec.d.ts +1 -0
- package/dist/workspace/pid/retriever.d.ts +9 -0
- package/dist/workspace/pid/writer.d.ts +46 -0
- package/dist/workspace/retriever.d.ts +12 -0
- package/dist/workspace/workspace.spec.d.ts +1 -0
- package/dist/workspace/writer.d.ts +55 -0
- package/package.json +27 -98
- package/src/auth/auth.spec.ts +46 -0
- package/src/auth/auth.ts +83 -0
- package/src/auth/index.ts +10 -0
- package/src/cdc/external.ts +10 -0
- package/src/cdc/index.ts +10 -0
- package/src/cdc/observable.ts +80 -0
- package/src/channel/channel.spec.ts +82 -0
- package/src/channel/client.ts +209 -0
- package/src/channel/creator.ts +43 -0
- package/src/channel/external.ts +13 -0
- package/src/channel/index.ts +10 -0
- package/src/channel/payload.ts +52 -0
- package/src/channel/retriever.ts +160 -0
- package/src/client.ts +112 -0
- package/src/connection/checker.ts +104 -0
- package/src/connection/connection.spec.ts +35 -0
- package/src/connection/index.ts +10 -0
- package/src/control/authority.ts +25 -0
- package/src/control/external.ts +11 -0
- package/src/control/index.ts +10 -0
- package/src/control/state.spec.ts +24 -0
- package/src/control/state.ts +117 -0
- package/src/errors.ts +153 -0
- package/src/framer/adapter.ts +116 -0
- package/src/framer/client.ts +116 -0
- package/src/framer/external.ts +14 -0
- package/src/framer/frame.spec.ts +317 -0
- package/src/framer/frame.ts +412 -0
- package/src/framer/index.ts +10 -0
- package/src/framer/iterator.spec.ts +62 -0
- package/src/framer/iterator.ts +240 -0
- package/src/framer/streamProxy.ts +59 -0
- package/src/framer/streamer.spec.ts +42 -0
- package/src/framer/streamer.ts +86 -0
- package/src/framer/writer.spec.ts +52 -0
- package/src/framer/writer.ts +236 -0
- package/src/index.ts +43 -4
- package/src/ontology/cdc.ts +135 -0
- package/src/ontology/client.ts +103 -0
- package/src/ontology/external.ts +12 -0
- package/src/ontology/group/client.ts +40 -0
- package/src/ontology/group/external.ts +11 -0
- package/src/ontology/group/group.spec.ts +46 -0
- package/src/ontology/group/group.ts +27 -0
- package/src/ontology/group/index.ts +10 -0
- package/src/ontology/group/payload.ts +65 -0
- package/src/ontology/group/writer.ts +48 -0
- package/src/ontology/index.ts +10 -0
- package/src/ontology/ontology.spec.ts +114 -0
- package/src/ontology/payload.ts +121 -0
- package/src/ontology/retriever.ts +91 -0
- package/src/ontology/writer.ts +49 -0
- package/src/ranger/active.ts +56 -0
- package/src/ranger/alias.ts +183 -0
- package/src/ranger/client.ts +124 -0
- package/src/ranger/external.ts +15 -0
- package/src/ranger/index.ts +10 -0
- package/src/ranger/kv.ts +91 -0
- package/src/ranger/payload.ts +70 -0
- package/src/ranger/range.ts +74 -0
- package/src/ranger/ranger.spec.ts +167 -0
- package/src/ranger/retriever.ts +50 -0
- package/src/ranger/writer.ts +80 -0
- package/src/setupspecs.ts +14 -5
- package/src/transport.ts +39 -0
- package/src/user/index.ts +10 -0
- package/src/user/payload.ts +17 -0
- package/src/util/telem.ts +19 -0
- package/src/vite-env.d.ts +11 -0
- package/src/workspace/client.ts +75 -0
- package/src/workspace/external.ts +11 -0
- package/src/workspace/index.ts +10 -0
- package/src/workspace/lineplot/client.ts +51 -0
- package/src/workspace/lineplot/external.ts +11 -0
- package/src/workspace/lineplot/index.ts +10 -0
- package/src/workspace/lineplot/linePlot.spec.ts +78 -0
- package/src/workspace/lineplot/payload.ts +29 -0
- package/src/workspace/lineplot/retriever.ts +49 -0
- package/src/workspace/lineplot/writer.ts +109 -0
- package/src/workspace/payload.ts +29 -0
- package/src/workspace/pid/client.ts +55 -0
- package/src/workspace/pid/external.ts +11 -0
- package/src/workspace/pid/index.ts +10 -0
- package/src/workspace/pid/payload.ts +31 -0
- package/src/workspace/pid/pid.spec.ts +111 -0
- package/src/workspace/pid/retriever.ts +45 -0
- package/src/workspace/pid/writer.ts +130 -0
- package/src/workspace/retriever.ts +67 -0
- package/src/workspace/workspace.spec.ts +62 -0
- package/src/workspace/writer.ts +103 -0
- package/tsconfig.json +3 -43
- package/tsconfig.vite.json +4 -0
- package/vite.config.ts +25 -0
- package/.DS_Store +0 -0
- package/.editorconfig +0 -15
- package/.eslintrc.json +0 -33
- package/.gitignore +0 -9
- package/.nyc_output/20720f2d-6abe-420f-a3c5-304d52d60827.json +0 -1
- package/.nyc_output/4725921c-6f1b-4ae9-9819-e455f702d31c.json +0 -1
- package/.nyc_output/47478588-5ffd-4332-873c-facaa4a2fc38.json +0 -1
- package/.nyc_output/48180641-e0b2-49ab-a6eb-e7910e9eac2f.json +0 -1
- package/.nyc_output/cb0abf31-740f-47db-b94a-8e3f8f117cb8.json +0 -1
- package/.nyc_output/fc77fce2-dad0-49a8-8d4b-0a9014ecf8c5.json +0 -1
- package/.nyc_output/processinfo/20720f2d-6abe-420f-a3c5-304d52d60827.json +0 -1
- package/.nyc_output/processinfo/4725921c-6f1b-4ae9-9819-e455f702d31c.json +0 -1
- package/.nyc_output/processinfo/47478588-5ffd-4332-873c-facaa4a2fc38.json +0 -1
- package/.nyc_output/processinfo/48180641-e0b2-49ab-a6eb-e7910e9eac2f.json +0 -1
- package/.nyc_output/processinfo/cb0abf31-740f-47db-b94a-8e3f8f117cb8.json +0 -1
- package/.nyc_output/processinfo/fc77fce2-dad0-49a8-8d4b-0a9014ecf8c5.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/.prettierignore +0 -2
- package/CHANGELOG.md +0 -5
- package/build/main/index.d.ts +0 -4
- package/build/main/index.js +0 -35
- package/build/main/lib/auth.js +0 -62
- package/build/main/lib/auth.spec.js +0 -39
- package/build/main/lib/channel/channel.spec.js +0 -49
- package/build/main/lib/channel/client.d.ts +0 -94
- package/build/main/lib/channel/client.js +0 -134
- package/build/main/lib/channel/creator.d.ts +0 -19
- package/build/main/lib/channel/creator.js +0 -44
- package/build/main/lib/channel/payload.d.ts +0 -25
- package/build/main/lib/channel/payload.js +0 -18
- package/build/main/lib/channel/registry.d.ts +0 -9
- package/build/main/lib/channel/registry.js +0 -37
- package/build/main/lib/channel/retriever.d.ts +0 -11
- package/build/main/lib/channel/retriever.js +0 -39
- package/build/main/lib/client.d.ts +0 -30
- package/build/main/lib/client.js +0 -46
- package/build/main/lib/errors.js +0 -122
- package/build/main/lib/segment/client.d.ts +0 -62
- package/build/main/lib/segment/client.js +0 -95
- package/build/main/lib/segment/iterator.d.ts +0 -134
- package/build/main/lib/segment/iterator.js +0 -253
- package/build/main/lib/segment/iterator.spec.js +0 -73
- package/build/main/lib/segment/payload.d.ts +0 -16
- package/build/main/lib/segment/payload.js +0 -13
- package/build/main/lib/segment/splitter.d.ts +0 -7
- package/build/main/lib/segment/splitter.js +0 -25
- package/build/main/lib/segment/typed.d.ts +0 -15
- package/build/main/lib/segment/typed.js +0 -49
- package/build/main/lib/segment/validator.d.ts +0 -22
- package/build/main/lib/segment/validator.js +0 -64
- package/build/main/lib/segment/writer.d.ts +0 -98
- package/build/main/lib/segment/writer.js +0 -183
- package/build/main/lib/segment/writer.spec.js +0 -90
- package/build/main/lib/telem.d.ts +0 -395
- package/build/main/lib/telem.js +0 -553
- package/build/main/lib/telem.spec.js +0 -152
- package/build/main/lib/transport.d.ts +0 -10
- package/build/main/lib/transport.js +0 -22
- package/build/main/lib/user/payload.js +0 -9
- package/build/main/lib/util/telem.d.ts +0 -2
- package/build/main/lib/util/telem.js +0 -13
- package/build/main/setupspecs.js +0 -17
- package/build/module/index.d.ts +0 -4
- package/build/module/index.js +0 -5
- package/build/module/lib/auth.d.ts +0 -54
- package/build/module/lib/auth.js +0 -63
- package/build/module/lib/auth.spec.js +0 -34
- package/build/module/lib/channel/channel.spec.js +0 -44
- package/build/module/lib/channel/client.d.ts +0 -94
- package/build/module/lib/channel/client.js +0 -134
- package/build/module/lib/channel/creator.d.ts +0 -19
- package/build/module/lib/channel/creator.js +0 -42
- package/build/module/lib/channel/payload.d.ts +0 -25
- package/build/module/lib/channel/payload.js +0 -15
- package/build/module/lib/channel/registry.d.ts +0 -9
- package/build/module/lib/channel/registry.js +0 -36
- package/build/module/lib/channel/retriever.d.ts +0 -11
- package/build/module/lib/channel/retriever.js +0 -37
- package/build/module/lib/client.d.ts +0 -30
- package/build/module/lib/client.js +0 -44
- package/build/module/lib/errors.d.ts +0 -53
- package/build/module/lib/errors.js +0 -113
- package/build/module/lib/segment/client.d.ts +0 -62
- package/build/module/lib/segment/client.js +0 -94
- package/build/module/lib/segment/iterator.js +0 -248
- package/build/module/lib/segment/iterator.spec.js +0 -68
- package/build/module/lib/segment/payload.d.ts +0 -16
- package/build/module/lib/segment/payload.js +0 -10
- package/build/module/lib/segment/splitter.d.ts +0 -7
- package/build/module/lib/segment/splitter.js +0 -26
- package/build/module/lib/segment/typed.d.ts +0 -15
- package/build/module/lib/segment/typed.js +0 -49
- package/build/module/lib/segment/validator.d.ts +0 -22
- package/build/module/lib/segment/validator.js +0 -60
- package/build/module/lib/segment/writer.d.ts +0 -98
- package/build/module/lib/segment/writer.js +0 -183
- package/build/module/lib/segment/writer.spec.js +0 -85
- package/build/module/lib/telem.d.ts +0 -395
- package/build/module/lib/telem.js +0 -545
- package/build/module/lib/telem.spec.js +0 -147
- package/build/module/lib/transport.d.ts +0 -10
- package/build/module/lib/transport.js +0 -22
- package/build/module/lib/user/payload.d.ts +0 -12
- package/build/module/lib/user/payload.js +0 -6
- package/build/module/lib/util/telem.d.ts +0 -2
- package/build/module/lib/util/telem.js +0 -9
- package/build/module/setupspecs.d.ts +0 -4
- package/build/module/setupspecs.js +0 -16
- package/build/tsconfig.module.tsbuildinfo +0 -1
- package/build/tsconfig.tsbuildinfo +0 -1
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -191
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -191
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/lib/auth.ts.html +0 -340
- package/coverage/lcov-report/src/lib/channel/client.ts.html +0 -604
- package/coverage/lcov-report/src/lib/channel/creator.ts.html +0 -304
- package/coverage/lcov-report/src/lib/channel/index.html +0 -176
- package/coverage/lcov-report/src/lib/channel/payload.ts.html +0 -139
- package/coverage/lcov-report/src/lib/channel/registry.ts.html +0 -202
- package/coverage/lcov-report/src/lib/channel/retriever.ts.html +0 -244
- package/coverage/lcov-report/src/lib/client.ts.html +0 -244
- package/coverage/lcov-report/src/lib/errors.ts.html +0 -484
- package/coverage/lcov-report/src/lib/index.html +0 -176
- package/coverage/lcov-report/src/lib/segment/client.ts.html +0 -463
- package/coverage/lcov-report/src/lib/segment/index.html +0 -206
- package/coverage/lcov-report/src/lib/segment/iterator.ts.html +0 -928
- package/coverage/lcov-report/src/lib/segment/payload.ts.html +0 -139
- package/coverage/lcov-report/src/lib/segment/splitter.ts.html +0 -181
- package/coverage/lcov-report/src/lib/segment/typed.ts.html +0 -307
- package/coverage/lcov-report/src/lib/segment/validator.ts.html +0 -331
- package/coverage/lcov-report/src/lib/segment/writer.ts.html +0 -727
- package/coverage/lcov-report/src/lib/telem.ts.html +0 -2056
- package/coverage/lcov-report/src/lib/transport.ts.html +0 -196
- package/coverage/lcov-report/src/lib/user/index.html +0 -116
- package/coverage/lcov-report/src/lib/user/payload.ts.html +0 -109
- package/coverage/lcov-report/src/lib/util/index.html +0 -116
- package/coverage/lcov-report/src/lib/util/telem.ts.html +0 -124
- package/coverage/lcov-report/src/setupspecs.ts.html +0 -133
- package/coverage/lcov.info +0 -1230
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/coverage/src/index.html +0 -116
- package/coverage/src/lib/auth.ts.html +0 -340
- package/coverage/src/lib/channel/client.ts.html +0 -604
- package/coverage/src/lib/channel/creator.ts.html +0 -304
- package/coverage/src/lib/channel/index.html +0 -176
- package/coverage/src/lib/channel/payload.ts.html +0 -139
- package/coverage/src/lib/channel/registry.ts.html +0 -202
- package/coverage/src/lib/channel/retriever.ts.html +0 -244
- package/coverage/src/lib/client.ts.html +0 -244
- package/coverage/src/lib/errors.ts.html +0 -484
- package/coverage/src/lib/index.html +0 -176
- package/coverage/src/lib/segment/client.ts.html +0 -463
- package/coverage/src/lib/segment/index.html +0 -206
- package/coverage/src/lib/segment/iterator.ts.html +0 -928
- package/coverage/src/lib/segment/payload.ts.html +0 -139
- package/coverage/src/lib/segment/splitter.ts.html +0 -181
- package/coverage/src/lib/segment/typed.ts.html +0 -307
- package/coverage/src/lib/segment/validator.ts.html +0 -331
- package/coverage/src/lib/segment/writer.ts.html +0 -727
- package/coverage/src/lib/telem.ts.html +0 -2056
- package/coverage/src/lib/transport.ts.html +0 -196
- package/coverage/src/lib/user/index.html +0 -116
- package/coverage/src/lib/user/payload.ts.html +0 -109
- package/coverage/src/lib/util/index.html +0 -116
- package/coverage/src/lib/util/telem.ts.html +0 -124
- package/coverage/src/setupspecs.ts.html +0 -133
- package/src/lib/.DS_Store +0 -0
- package/src/lib/auth.spec.ts +0 -36
- package/src/lib/auth.ts +0 -85
- package/src/lib/channel/channel.spec.ts +0 -49
- package/src/lib/channel/client.ts +0 -173
- package/src/lib/channel/creator.ts +0 -73
- package/src/lib/channel/payload.ts +0 -18
- package/src/lib/channel/registry.ts +0 -39
- package/src/lib/channel/retriever.ts +0 -53
- package/src/lib/client.ts +0 -53
- package/src/lib/errors.ts +0 -133
- package/src/lib/segment/client.ts +0 -126
- package/src/lib/segment/iterator.spec.ts +0 -78
- package/src/lib/segment/iterator.ts +0 -281
- package/src/lib/segment/payload.ts +0 -18
- package/src/lib/segment/splitter.ts +0 -32
- package/src/lib/segment/typed.ts +0 -74
- package/src/lib/segment/validator.ts +0 -82
- package/src/lib/segment/writer.spec.ts +0 -85
- package/src/lib/segment/writer.ts +0 -214
- package/src/lib/telem.spec.ts +0 -200
- package/src/lib/telem.ts +0 -657
- package/src/lib/transport.ts +0 -37
- package/src/lib/user/payload.ts +0 -8
- package/src/lib/util/telem.ts +0 -13
- package/tsconfig.module.json +0 -9
- package/yarn-error.log +0 -5756
- package/yarn.lock +0 -5936
- /package/{build/main/lib → dist/auth}/auth.spec.d.ts +0 -0
- /package/{build/main/lib → dist}/channel/channel.spec.d.ts +0 -0
- /package/{build/main/lib/segment/iterator.spec.d.ts → dist/connection/connection.spec.d.ts} +0 -0
- /package/{build/main/lib/segment/writer.spec.d.ts → dist/control/state.spec.d.ts} +0 -0
- /package/{build/main/lib/telem.spec.d.ts → dist/framer/frame.spec.d.ts} +0 -0
- /package/{build/module/lib/segment → dist/framer}/iterator.spec.d.ts +0 -0
- /package/{build/module/lib/auth.spec.d.ts → dist/framer/streamer.spec.d.ts} +0 -0
- /package/{build/module/lib/segment → dist/framer}/writer.spec.d.ts +0 -0
- /package/{build/module/lib/channel/channel.spec.d.ts → dist/label/label.spec.d.ts} +0 -0
- /package/{build/module/lib/telem.spec.d.ts → dist/ontology/group/group.spec.d.ts} +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { toArray } from "@synnaxlabs/x";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
export const keyZ = z.string().uuid();
|
|
14
|
+
export type Key = z.infer<typeof keyZ>;
|
|
15
|
+
export type Name = string;
|
|
16
|
+
export type Keys = Key[];
|
|
17
|
+
export type Names = Name[];
|
|
18
|
+
export type Params = Key | Name | Keys | Names;
|
|
19
|
+
|
|
20
|
+
export const payloadZ = z.object({
|
|
21
|
+
key: keyZ,
|
|
22
|
+
name: z.string(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type Payload = z.infer<typeof payloadZ>;
|
|
26
|
+
|
|
27
|
+
export type ParamAnalysisResult =
|
|
28
|
+
| {
|
|
29
|
+
single: true;
|
|
30
|
+
variant: "keys";
|
|
31
|
+
normalized: Keys;
|
|
32
|
+
actual: Key;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
single: true;
|
|
36
|
+
variant: "names";
|
|
37
|
+
normalized: Names;
|
|
38
|
+
actual: Name;
|
|
39
|
+
}
|
|
40
|
+
| {
|
|
41
|
+
single: false;
|
|
42
|
+
variant: "keys";
|
|
43
|
+
normalized: Keys;
|
|
44
|
+
actual: Keys;
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
single: false;
|
|
48
|
+
variant: "names";
|
|
49
|
+
normalized: Names;
|
|
50
|
+
actual: Names;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const analyzeParams = (params: Params): ParamAnalysisResult => {
|
|
54
|
+
const normal = toArray(params) as Keys | Names;
|
|
55
|
+
if (normal.length === 0) {
|
|
56
|
+
throw new Error("No groups specified");
|
|
57
|
+
}
|
|
58
|
+
const isKey = keyZ.safeParse(normal[0]).success;
|
|
59
|
+
return {
|
|
60
|
+
single: !Array.isArray(params),
|
|
61
|
+
variant: isKey ? "keys" : "names",
|
|
62
|
+
normalized: normal,
|
|
63
|
+
actual: params,
|
|
64
|
+
} as const as ParamAnalysisResult;
|
|
65
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
import { type Payload, payloadZ } from "@/ontology/group/payload";
|
|
14
|
+
import { type ID } from "@/ontology/payload";
|
|
15
|
+
|
|
16
|
+
const resZ = z.object({
|
|
17
|
+
group: payloadZ,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export class Writer {
|
|
21
|
+
private static readonly ENDPOINT = "/ontology/create-group";
|
|
22
|
+
private static readonly ENDPOINT_RENAME = "/ontology/rename-group";
|
|
23
|
+
private static readonly ENDPOINT_DELETE = "/ontology/delete-group";
|
|
24
|
+
client: UnaryClient;
|
|
25
|
+
|
|
26
|
+
constructor(client: UnaryClient) {
|
|
27
|
+
this.client = client;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async create(parent: ID, name: string): Promise<Payload> {
|
|
31
|
+
const req = { parent, name };
|
|
32
|
+
const [res, err] = await this.client.send(Writer.ENDPOINT, req, resZ);
|
|
33
|
+
if (err != null) throw err;
|
|
34
|
+
return res.group;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async rename(key: string, name: string): Promise<void> {
|
|
38
|
+
const req = { key, name };
|
|
39
|
+
const [, err] = await this.client.send(Writer.ENDPOINT_RENAME, req, z.object({}));
|
|
40
|
+
if (err != null) throw err;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async delete(keys: string[]): Promise<void> {
|
|
44
|
+
const req = { keys };
|
|
45
|
+
const [, err] = await this.client.send(Writer.ENDPOINT_DELETE, req, z.object({}));
|
|
46
|
+
if (err != null) throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
export * as ontology from "@/ontology/external";
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { describe, expect, test, it } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { ontology } from "@/ontology";
|
|
13
|
+
import { newClient } from "@/setupspecs";
|
|
14
|
+
|
|
15
|
+
const client = newClient();
|
|
16
|
+
|
|
17
|
+
const randomName = (): string => `group-${Math.random()}`;
|
|
18
|
+
|
|
19
|
+
describe("Ontology", () => {
|
|
20
|
+
describe("retrieve", () => {
|
|
21
|
+
test("retrieve", async () => {
|
|
22
|
+
const name = randomName();
|
|
23
|
+
const g = await client.ontology.groups.create(ontology.Root, name);
|
|
24
|
+
const g2 = await client.ontology.retrieve(g.ontologyID);
|
|
25
|
+
expect(g2.name).toEqual(name);
|
|
26
|
+
});
|
|
27
|
+
test("retrieve children", async () => {
|
|
28
|
+
const name = randomName();
|
|
29
|
+
const g = await client.ontology.groups.create(ontology.Root, name);
|
|
30
|
+
const name2 = randomName();
|
|
31
|
+
await client.ontology.groups.create(g.ontologyID, name2);
|
|
32
|
+
const children = await client.ontology.retrieveChildren(g.ontologyID);
|
|
33
|
+
expect(children.length).toEqual(1);
|
|
34
|
+
expect(children[0].name).toEqual(name2);
|
|
35
|
+
});
|
|
36
|
+
test("retrieve parents", async () => {
|
|
37
|
+
const name = randomName();
|
|
38
|
+
const g = await client.ontology.groups.create(ontology.Root, name);
|
|
39
|
+
const name2 = randomName();
|
|
40
|
+
const g2 = await client.ontology.groups.create(g.ontologyID, name2);
|
|
41
|
+
const parents = await client.ontology.retrieveParents(g2.ontologyID);
|
|
42
|
+
expect(parents.length).toEqual(1);
|
|
43
|
+
expect(parents[0].name).toEqual(name);
|
|
44
|
+
});
|
|
45
|
+
test("add children", async () => {
|
|
46
|
+
const name = randomName();
|
|
47
|
+
const g = await client.ontology.groups.create(ontology.Root, name);
|
|
48
|
+
const name2 = randomName();
|
|
49
|
+
const g2 = await client.ontology.groups.create(ontology.Root, name2);
|
|
50
|
+
await client.ontology.addChildren(g.ontologyID, g2.ontologyID);
|
|
51
|
+
const children = await client.ontology.retrieveChildren(g.ontologyID);
|
|
52
|
+
expect(children.length).toEqual(1);
|
|
53
|
+
expect(children[0].name).toEqual(name2);
|
|
54
|
+
});
|
|
55
|
+
test("remove children", async () => {
|
|
56
|
+
const name = randomName();
|
|
57
|
+
const g = await client.ontology.groups.create(ontology.Root, name);
|
|
58
|
+
const name2 = randomName();
|
|
59
|
+
const g2 = await client.ontology.groups.create(ontology.Root, name2);
|
|
60
|
+
await client.ontology.addChildren(g.ontologyID, g2.ontologyID);
|
|
61
|
+
await client.ontology.removeChildren(g.ontologyID, g2.ontologyID);
|
|
62
|
+
const children = await client.ontology.retrieveChildren(g.ontologyID);
|
|
63
|
+
expect(children.length).toEqual(0);
|
|
64
|
+
});
|
|
65
|
+
test("move children", async () => {
|
|
66
|
+
const name = randomName();
|
|
67
|
+
const g = await client.ontology.groups.create(ontology.Root, name);
|
|
68
|
+
const name2 = randomName();
|
|
69
|
+
const g2 = await client.ontology.groups.create(ontology.Root, name2);
|
|
70
|
+
const oldRootLength = (await client.ontology.retrieveChildren(ontology.Root))
|
|
71
|
+
.length;
|
|
72
|
+
await client.ontology.moveChildren(ontology.Root, g.ontologyID, g2.ontologyID);
|
|
73
|
+
const children = await client.ontology.retrieveChildren(g.ontologyID);
|
|
74
|
+
expect(children.length).toEqual(1);
|
|
75
|
+
const newRootLength = (await client.ontology.retrieveChildren(ontology.Root))
|
|
76
|
+
.length;
|
|
77
|
+
expect(newRootLength).toEqual(oldRootLength - 1);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe("cdc", async () => {
|
|
81
|
+
it("should correctly decode a set of relationships from a string", () => {
|
|
82
|
+
const rel = ontology.parseRelationship("typeA:keyA->parent->typeB:keyB");
|
|
83
|
+
expect(rel.type).toEqual("parent");
|
|
84
|
+
expect(rel.from.type).toEqual("typeA");
|
|
85
|
+
expect(rel.from.key).toEqual("keyA");
|
|
86
|
+
expect(rel.to.type).toEqual("typeB");
|
|
87
|
+
expect(rel.to.key).toEqual("keyB");
|
|
88
|
+
});
|
|
89
|
+
it("should correctly propagate resource changes to the ontology", async () => {
|
|
90
|
+
const change = await client.ontology.openChangeTracker();
|
|
91
|
+
const p = new Promise<ontology.ResourceChange[]>((resolve) => {
|
|
92
|
+
change.resources.onChange((changes) => {
|
|
93
|
+
resolve(changes);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
await client.ontology.groups.create(ontology.Root, randomName());
|
|
97
|
+
const c = await p;
|
|
98
|
+
expect(c.length).toBeGreaterThan(0);
|
|
99
|
+
await change.close();
|
|
100
|
+
});
|
|
101
|
+
it("should correctly propagate relationship changes to the ontology", async () => {
|
|
102
|
+
const change = await client.ontology.openChangeTracker();
|
|
103
|
+
const p = new Promise<ontology.RelationshipChange[]>((resolve) => {
|
|
104
|
+
change.relationships.onChange((changes) => {
|
|
105
|
+
resolve(changes);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
await client.ontology.groups.create(ontology.Root, randomName());
|
|
109
|
+
const c = await p;
|
|
110
|
+
expect(c.length).toBeGreaterThan(0);
|
|
111
|
+
await change.close();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
|
|
12
|
+
const resourceTypeZ = z.union([
|
|
13
|
+
z.literal("builtin"),
|
|
14
|
+
z.literal("cluster"),
|
|
15
|
+
z.literal("channel"),
|
|
16
|
+
z.literal("node"),
|
|
17
|
+
z.literal("group"),
|
|
18
|
+
z.literal("range"),
|
|
19
|
+
z.literal("range-alias"),
|
|
20
|
+
z.literal("user"),
|
|
21
|
+
z.literal("workspace"),
|
|
22
|
+
z.literal("pid"),
|
|
23
|
+
z.literal("lineplot"),
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
export type ResourceType = z.infer<typeof resourceTypeZ>;
|
|
27
|
+
|
|
28
|
+
export const idZ = z.object({
|
|
29
|
+
type: resourceTypeZ,
|
|
30
|
+
key: z.string(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const stringIDZ = z.string().transform((v) => {
|
|
34
|
+
const [type, key] = v.split(":");
|
|
35
|
+
return {
|
|
36
|
+
type: type as ResourceType,
|
|
37
|
+
key,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const crudeIDZ = z.union([stringIDZ, idZ]);
|
|
42
|
+
|
|
43
|
+
export class ID {
|
|
44
|
+
type: ResourceType;
|
|
45
|
+
key: string;
|
|
46
|
+
|
|
47
|
+
constructor(args: z.input<typeof crudeIDZ> | ID) {
|
|
48
|
+
if (args instanceof ID) {
|
|
49
|
+
this.type = args.type;
|
|
50
|
+
this.key = args.key;
|
|
51
|
+
} else if (typeof args === "string") {
|
|
52
|
+
const [type, key] = args.split(":");
|
|
53
|
+
this.type = type as ResourceType;
|
|
54
|
+
this.key = key;
|
|
55
|
+
} else {
|
|
56
|
+
this.type = args.type;
|
|
57
|
+
this.key = args.key;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
toString(): string {
|
|
62
|
+
return `${this.type}:${this.key}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get payload(): z.infer<typeof idZ> {
|
|
66
|
+
return {
|
|
67
|
+
type: this.type,
|
|
68
|
+
key: this.key,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static readonly z = z.union([crudeIDZ, z.instanceof(ID)]).transform((v) => new ID(v));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const Root = new ID({ type: "builtin", key: "root" });
|
|
76
|
+
|
|
77
|
+
export const schemaFieldZ = z.object({
|
|
78
|
+
type: z.number(),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export type SchemaField = z.infer<typeof schemaFieldZ>;
|
|
82
|
+
|
|
83
|
+
export const schemaZ = z.object({
|
|
84
|
+
type: resourceTypeZ,
|
|
85
|
+
fields: z.record(schemaFieldZ),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export type Schema = z.infer<typeof schemaZ>;
|
|
89
|
+
|
|
90
|
+
export const resourceSchemaZ = z
|
|
91
|
+
.object({
|
|
92
|
+
id: ID.z,
|
|
93
|
+
name: z.string(),
|
|
94
|
+
schema: schemaZ.optional(),
|
|
95
|
+
data: z.record(z.unknown()).optional(),
|
|
96
|
+
})
|
|
97
|
+
.transform((resource) => {
|
|
98
|
+
return {
|
|
99
|
+
key: resource.id.toString(),
|
|
100
|
+
...resource,
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export type Resource = z.infer<typeof resourceSchemaZ>;
|
|
105
|
+
|
|
106
|
+
export const relationshipSchemaZ = z.object({
|
|
107
|
+
from: ID.z,
|
|
108
|
+
type: z.string(),
|
|
109
|
+
to: ID.z,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
export type Relationship = z.infer<typeof relationshipSchemaZ>;
|
|
113
|
+
|
|
114
|
+
export const parseRelationship = (str: string): Relationship => {
|
|
115
|
+
const [from, type, to] = str.split("->");
|
|
116
|
+
return {
|
|
117
|
+
from: new ID(from),
|
|
118
|
+
type,
|
|
119
|
+
to: new ID(to),
|
|
120
|
+
};
|
|
121
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import type { UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { toArray } from "@synnaxlabs/x";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
import { ID, type Resource, idZ, resourceSchemaZ } from "@/ontology/payload";
|
|
15
|
+
|
|
16
|
+
const requestSchema = z.object({
|
|
17
|
+
ids: idZ.array().optional(),
|
|
18
|
+
children: z.boolean().optional(),
|
|
19
|
+
parents: z.boolean().optional(),
|
|
20
|
+
includeSchema: z.boolean().optional(),
|
|
21
|
+
includeFieldData: z.boolean().optional(),
|
|
22
|
+
term: z.string().optional(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
type Request = z.infer<typeof requestSchema>;
|
|
26
|
+
|
|
27
|
+
const responseSchema = z.object({
|
|
28
|
+
resources: resourceSchemaZ.array(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export class Retriever {
|
|
32
|
+
private static readonly ENDPOINT = "/ontology/retrieve";
|
|
33
|
+
private readonly client: UnaryClient;
|
|
34
|
+
|
|
35
|
+
constructor(unary: UnaryClient) {
|
|
36
|
+
this.client = unary;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async search(term: string): Promise<Resource[]> {
|
|
40
|
+
const resources = await this.execute({ term });
|
|
41
|
+
return resources;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async retrieve(
|
|
45
|
+
ids: ID | ID[] | string | string[],
|
|
46
|
+
includeSchema: boolean = true,
|
|
47
|
+
includeFieldData: boolean = true,
|
|
48
|
+
): Promise<Resource[]> {
|
|
49
|
+
return await this.execute({
|
|
50
|
+
ids: toArray(ids).map((id) => new ID(id).payload),
|
|
51
|
+
includeFieldData,
|
|
52
|
+
includeSchema,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async retrieveChildren(
|
|
57
|
+
ids: ID | ID[],
|
|
58
|
+
includeSchema: boolean = true,
|
|
59
|
+
includeFieldData: boolean = true,
|
|
60
|
+
): Promise<Resource[]> {
|
|
61
|
+
return await this.execute({
|
|
62
|
+
ids: toArray(ids).map((id) => new ID(id).payload),
|
|
63
|
+
children: true,
|
|
64
|
+
includeSchema,
|
|
65
|
+
includeFieldData,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async retrieveParents(
|
|
70
|
+
ids: ID | ID[],
|
|
71
|
+
includeSchema: boolean = true,
|
|
72
|
+
includeFieldData: boolean = true,
|
|
73
|
+
): Promise<Resource[]> {
|
|
74
|
+
return await this.execute({
|
|
75
|
+
ids: toArray(ids).map((id) => new ID(id).payload),
|
|
76
|
+
parents: true,
|
|
77
|
+
includeSchema,
|
|
78
|
+
includeFieldData,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private async execute(request: Request): Promise<Resource[]> {
|
|
83
|
+
const [res, err] = await this.client.send(
|
|
84
|
+
Retriever.ENDPOINT,
|
|
85
|
+
request,
|
|
86
|
+
responseSchema,
|
|
87
|
+
);
|
|
88
|
+
if (err != null) throw err;
|
|
89
|
+
return res.resources;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
import { type ID } from "@/ontology/payload";
|
|
14
|
+
|
|
15
|
+
const ENDPOINTS = {
|
|
16
|
+
ADD_CHILDREN: "/ontology/add-children",
|
|
17
|
+
REMOVE_CHILDREN: "/ontology/remove-children",
|
|
18
|
+
MOVE_CHILDREN: "/ontology/move-children",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export class Writer {
|
|
22
|
+
client: UnaryClient;
|
|
23
|
+
|
|
24
|
+
constructor(client: UnaryClient) {
|
|
25
|
+
this.client = client;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async addChildren(id: ID, ...children: ID[]): Promise<void> {
|
|
29
|
+
const req = { id, children };
|
|
30
|
+
const [, err] = await this.client.send(ENDPOINTS.ADD_CHILDREN, req, z.object({}));
|
|
31
|
+
if (err != null) throw err;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async removeChildren(id: ID, ...children: ID[]): Promise<void> {
|
|
35
|
+
const req = { id, children };
|
|
36
|
+
const [, err] = await this.client.send(
|
|
37
|
+
ENDPOINTS.REMOVE_CHILDREN,
|
|
38
|
+
req,
|
|
39
|
+
z.object({}),
|
|
40
|
+
);
|
|
41
|
+
if (err != null) throw err;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async moveChildren(from: ID, to: ID, ...children: ID[]): Promise<void> {
|
|
45
|
+
const req = { from, to, children };
|
|
46
|
+
const [, err] = await this.client.send(ENDPOINTS.MOVE_CHILDREN, req, z.object({}));
|
|
47
|
+
if (err != null) throw err;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
import { QueryError } from "..";
|
|
14
|
+
|
|
15
|
+
import { type Payload, payloadZ, type Key } from "./payload";
|
|
16
|
+
|
|
17
|
+
const setActiveResZ = z.object({});
|
|
18
|
+
|
|
19
|
+
const retrieveActiveResZ = z.object({
|
|
20
|
+
range: payloadZ,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const clearActiveResZ = z.object({});
|
|
24
|
+
|
|
25
|
+
const SET_ENDPOINT = "/range/set-active";
|
|
26
|
+
const RETRIEVE_ENDPOINT = "/range/retrieve-active";
|
|
27
|
+
const CLEAR_ENDPOINT = "/range/clear-active";
|
|
28
|
+
|
|
29
|
+
export class Active {
|
|
30
|
+
private readonly client: UnaryClient;
|
|
31
|
+
|
|
32
|
+
constructor(client: UnaryClient) {
|
|
33
|
+
this.client = client;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async setActive(range: Key): Promise<void> {
|
|
37
|
+
const [, err] = await this.client.send(SET_ENDPOINT, { range }, setActiveResZ);
|
|
38
|
+
if (err != null) throw err;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async retrieveActive(): Promise<Payload | null> {
|
|
42
|
+
const [res, err] = await this.client.send(
|
|
43
|
+
RETRIEVE_ENDPOINT,
|
|
44
|
+
{},
|
|
45
|
+
retrieveActiveResZ,
|
|
46
|
+
);
|
|
47
|
+
if (err instanceof QueryError) return null;
|
|
48
|
+
if (err != null) throw err;
|
|
49
|
+
return res.range;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async clearActive(range: Key): Promise<void> {
|
|
53
|
+
const [, err] = await this.client.send(CLEAR_ENDPOINT, { range }, clearActiveResZ);
|
|
54
|
+
if (err != null) throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|