@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,236 @@
|
|
|
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
|
+
/* eslint-disable @typescript-eslint/no-throw-literal */
|
|
11
|
+
import type { Stream, StreamClient } from "@synnaxlabs/freighter";
|
|
12
|
+
import { decodeError, errorZ } from "@synnaxlabs/freighter";
|
|
13
|
+
import {
|
|
14
|
+
type NativeTypedArray,
|
|
15
|
+
Series,
|
|
16
|
+
TimeStamp,
|
|
17
|
+
type CrudeTimeStamp,
|
|
18
|
+
toArray,
|
|
19
|
+
} from "@synnaxlabs/x";
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
|
|
22
|
+
import { type Key, type KeyOrName, type Params } from "@/channel/payload";
|
|
23
|
+
import { type Retriever } from "@/channel/retriever";
|
|
24
|
+
import { Authority } from "@/control/authority";
|
|
25
|
+
import {
|
|
26
|
+
subjectZ as controlSubjectZ,
|
|
27
|
+
type Subject as ControlSubject,
|
|
28
|
+
} from "@/control/state";
|
|
29
|
+
import { ForwardFrameAdapter } from "@/framer/adapter";
|
|
30
|
+
import { type CrudeFrame, Frame, frameZ } from "@/framer/frame";
|
|
31
|
+
import { StreamProxy } from "@/framer/streamProxy";
|
|
32
|
+
|
|
33
|
+
enum Command {
|
|
34
|
+
Open = 0,
|
|
35
|
+
Write = 1,
|
|
36
|
+
Commit = 2,
|
|
37
|
+
Error = 3,
|
|
38
|
+
SetAuthority = 4,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const netConfigZ = z.object({
|
|
42
|
+
start: TimeStamp.z.optional(),
|
|
43
|
+
controlSubject: controlSubjectZ.optional(),
|
|
44
|
+
keys: z.number().array(),
|
|
45
|
+
authorities: Authority.z.array().optional(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const reqZ = z.object({
|
|
49
|
+
command: z.nativeEnum(Command),
|
|
50
|
+
config: netConfigZ.optional(),
|
|
51
|
+
frame: frameZ.optional(),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
type Request = z.infer<typeof reqZ>;
|
|
55
|
+
|
|
56
|
+
const resZ = z.object({
|
|
57
|
+
ack: z.boolean(),
|
|
58
|
+
command: z.nativeEnum(Command),
|
|
59
|
+
error: errorZ.optional().nullable(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
type Response = z.infer<typeof resZ>;
|
|
63
|
+
|
|
64
|
+
export interface WriterConfig {
|
|
65
|
+
start: CrudeTimeStamp;
|
|
66
|
+
channels: Params;
|
|
67
|
+
controlSubject?: ControlSubject;
|
|
68
|
+
authorities?: Authority | Authority[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Writer is used to write telemetry to a set of channels in time order.
|
|
73
|
+
* It should not be instantiated directly, and should instead be instantited via the
|
|
74
|
+
* FramerClient {@link FrameClient#openWriter}.
|
|
75
|
+
*
|
|
76
|
+
* The writer is a streaming protocol that is heavily optimized for prerformance. This
|
|
77
|
+
* comes at the cost of icnreased complexity, and should only be used directly when
|
|
78
|
+
* writing large volumes of data (such as recording telemetry from a sensor or ingsting
|
|
79
|
+
* data froma file). Simpler methods (such as the frame client's write method) should
|
|
80
|
+
* be used for most use cases.
|
|
81
|
+
*
|
|
82
|
+
* The protocol is as follows:
|
|
83
|
+
*
|
|
84
|
+
* 1. The writer is opened with a starting timestamp and a list of channel keys. The
|
|
85
|
+
* writer will fail to open if the starting timstamp overlaps with any existing telemetry
|
|
86
|
+
* for any channels specified. If the writer opens successfuly, the caller is then
|
|
87
|
+
* free to write frames to the writer.
|
|
88
|
+
*
|
|
89
|
+
* 2. To write a frame, the caller can use the write method and follow the validation
|
|
90
|
+
* rules described in its method's documentation. This process is asynchronous, meaning
|
|
91
|
+
* that write calls may return before teh frame has been written to the cluster. This
|
|
92
|
+
* also means that the writer can accumulate an error after write is called. If the writer
|
|
93
|
+
* accumulates an erorr, all subsequent write and commit calls will return False. The
|
|
94
|
+
* caller can check for errors by calling the error mehtod, which returns the accumulated
|
|
95
|
+
* error and resets the writer for future use. The caller can also check for errors by
|
|
96
|
+
* closing the writer, which will throw any accumulated error.
|
|
97
|
+
*
|
|
98
|
+
* 3. To commit the written frames to the cluster, the caller can call the commit method.
|
|
99
|
+
* Unlike write, commit is synchronous, meaning that it will not return until the frames
|
|
100
|
+
* have been written to the cluster. If the writer has accumulated an erorr, commit will
|
|
101
|
+
* return false. After the caller acknowledges the erorr, they can attempt to commit again.
|
|
102
|
+
* Commit can be called several times throughout a writer's lifetime, and will only
|
|
103
|
+
* commit the frames that have been written since the last commit.
|
|
104
|
+
*
|
|
105
|
+
* 4. A writer MUST be closed after use in order to prevent resource leaks. Close should
|
|
106
|
+
* typically be called in a 'finally' block. If the writer has accumulated an error,
|
|
107
|
+
* close will throw the error.
|
|
108
|
+
*/
|
|
109
|
+
export class Writer {
|
|
110
|
+
private static readonly ENDPOINT = "/frame/write";
|
|
111
|
+
private readonly stream: StreamProxy<typeof reqZ, typeof resZ>;
|
|
112
|
+
private readonly adapter: ForwardFrameAdapter;
|
|
113
|
+
|
|
114
|
+
private constructor(
|
|
115
|
+
stream: Stream<typeof reqZ, typeof resZ>,
|
|
116
|
+
adapter: ForwardFrameAdapter,
|
|
117
|
+
) {
|
|
118
|
+
this.stream = new StreamProxy("Writer", stream);
|
|
119
|
+
this.adapter = adapter;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static async _open(
|
|
123
|
+
retriever: Retriever,
|
|
124
|
+
client: StreamClient,
|
|
125
|
+
{
|
|
126
|
+
channels,
|
|
127
|
+
authorities = Authority.ABSOLUTE,
|
|
128
|
+
controlSubject: subject,
|
|
129
|
+
start,
|
|
130
|
+
}: WriterConfig,
|
|
131
|
+
): Promise<Writer> {
|
|
132
|
+
const adapter = await ForwardFrameAdapter.open(retriever, channels);
|
|
133
|
+
const stream = await client.stream(Writer.ENDPOINT, reqZ, resZ);
|
|
134
|
+
const writer = new Writer(stream, adapter);
|
|
135
|
+
await writer.execute({
|
|
136
|
+
command: Command.Open,
|
|
137
|
+
config: {
|
|
138
|
+
start: new TimeStamp(start),
|
|
139
|
+
keys: adapter.keys,
|
|
140
|
+
controlSubject: subject,
|
|
141
|
+
authorities: toArray(authorities),
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return writer;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async write(channel: KeyOrName, data: NativeTypedArray): Promise<boolean>;
|
|
148
|
+
|
|
149
|
+
async write(frame: CrudeFrame): Promise<boolean>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Writes the given frame to the database.
|
|
153
|
+
*
|
|
154
|
+
* @param frame - The frame to write to the database. The frame must:
|
|
155
|
+
*
|
|
156
|
+
* 1. Have exactly one array for each key in the list of keys provided to the
|
|
157
|
+
* writer's open method.
|
|
158
|
+
* 2. Have equal length arrays for each key.
|
|
159
|
+
* 3. When writing to an index (i.e. TimeStamp) channel, the values must be
|
|
160
|
+
* monotonically increasing.
|
|
161
|
+
*
|
|
162
|
+
* @returns false if the writer has accumulated an error. In this case, the caller
|
|
163
|
+
* should acknowledge the error by calling the error method or closing the writer.
|
|
164
|
+
*/
|
|
165
|
+
async write(
|
|
166
|
+
frame: CrudeFrame | KeyOrName,
|
|
167
|
+
data?: NativeTypedArray,
|
|
168
|
+
): Promise<boolean> {
|
|
169
|
+
const isKeyOrName = ["string", "number"].includes(typeof frame);
|
|
170
|
+
if (isKeyOrName) {
|
|
171
|
+
frame = new Frame(frame, new Series(data as NativeTypedArray));
|
|
172
|
+
}
|
|
173
|
+
frame = this.adapter.adapt(new Frame(frame));
|
|
174
|
+
// @ts-expect-error
|
|
175
|
+
this.stream.send({ command: Command.Write, frame: frame.toPayload() });
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async setAuthority(value: Record<Key, Authority>): Promise<boolean> {
|
|
180
|
+
const res = await this.execute({
|
|
181
|
+
command: Command.SetAuthority,
|
|
182
|
+
config: {
|
|
183
|
+
keys: Object.keys(value).map((k) => Number(k)),
|
|
184
|
+
authorities: Object.values(value),
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
return res.ack;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Commits the written frames to the database. Commit is synchronous, meaning that it
|
|
192
|
+
* will not return until all frames have been commited to the database.
|
|
193
|
+
*
|
|
194
|
+
* @returns false if the commit failed due to an error. In this case, the caller
|
|
195
|
+
* should acknowledge the error by calling the error method or closing the writer.
|
|
196
|
+
* After the caller acknowledges the error, they can attempt to commit again.
|
|
197
|
+
*/
|
|
198
|
+
async commit(): Promise<boolean> {
|
|
199
|
+
if (this.errorAccumulated) return false;
|
|
200
|
+
const res = await this.execute({ command: Command.Commit });
|
|
201
|
+
return res.ack;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @returns The accumulated error, if any. This method will clear the writer's error
|
|
206
|
+
* state, allowing the writer to be used again.
|
|
207
|
+
*/
|
|
208
|
+
async error(): Promise<Error | null> {
|
|
209
|
+
this.stream.send({ command: Command.Error });
|
|
210
|
+
const res = await this.execute({ command: Command.Error });
|
|
211
|
+
return res.error != null ? decodeError(res.error) : null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Closes the writer, raising any accumulated error encountered during operation.
|
|
216
|
+
* A writer MUST be closed after use, and this method should probably be placed
|
|
217
|
+
* in a 'finally' block.
|
|
218
|
+
*/
|
|
219
|
+
async close(): Promise<void> {
|
|
220
|
+
await this.stream.closeAndAck();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async execute(req: Request): Promise<Response> {
|
|
224
|
+
// @ts-expect-error
|
|
225
|
+
this.stream.send(req);
|
|
226
|
+
while (true) {
|
|
227
|
+
const res = await this.stream.receive();
|
|
228
|
+
if (res.command === req.command) return res;
|
|
229
|
+
console.warn("writer received unexpected response", res);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private get errorAccumulated(): boolean {
|
|
234
|
+
return this.stream.received();
|
|
235
|
+
}
|
|
236
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 * from "@/channel";
|
|
11
|
+
export { default as Synnax, synnaxPropsZ } from "@/client";
|
|
12
|
+
export type { SynnaxProps } from "@/client";
|
|
13
|
+
export * from "@/connection";
|
|
14
|
+
export { Channel } from "@/channel/client";
|
|
3
15
|
export {
|
|
4
16
|
AuthError,
|
|
5
17
|
ContiguityError,
|
|
@@ -9,5 +21,32 @@ export {
|
|
|
9
21
|
RouteError,
|
|
10
22
|
UnexpectedError,
|
|
11
23
|
ValidationError,
|
|
12
|
-
} from
|
|
13
|
-
export {
|
|
24
|
+
} from "@/errors";
|
|
25
|
+
export { framer } from "@/framer";
|
|
26
|
+
export { Frame } from "@/framer/frame";
|
|
27
|
+
export { ontology } from "@/ontology";
|
|
28
|
+
export { control } from "@/control";
|
|
29
|
+
export { Authority } from "@/control/authority";
|
|
30
|
+
export {
|
|
31
|
+
DataType,
|
|
32
|
+
Density,
|
|
33
|
+
Rate,
|
|
34
|
+
Series,
|
|
35
|
+
TimeRange,
|
|
36
|
+
TimeSpan,
|
|
37
|
+
TimeStamp,
|
|
38
|
+
} from "@synnaxlabs/x";
|
|
39
|
+
export type {
|
|
40
|
+
NativeTypedArray,
|
|
41
|
+
CrudeDataType,
|
|
42
|
+
CrudeDensity,
|
|
43
|
+
CrudeRate,
|
|
44
|
+
CrudeSize,
|
|
45
|
+
CrudeTimeSpan,
|
|
46
|
+
CrudeTimeStamp,
|
|
47
|
+
SampleValue,
|
|
48
|
+
TimeStampStringFormat,
|
|
49
|
+
TZInfo,
|
|
50
|
+
} from "@synnaxlabs/x";
|
|
51
|
+
export { workspace } from "@/workspace";
|
|
52
|
+
export { ranger } from "@/ranger";
|
|
@@ -0,0 +1,135 @@
|
|
|
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 { observe, type change } from "@synnaxlabs/x";
|
|
11
|
+
|
|
12
|
+
import { QueryError } from "@/errors";
|
|
13
|
+
import { type Client as FrameClient } from "@/framer/client";
|
|
14
|
+
import { type Frame } from "@/framer/frame";
|
|
15
|
+
import { type Streamer as FrameStreamer } from "@/framer/streamer";
|
|
16
|
+
import {
|
|
17
|
+
ID,
|
|
18
|
+
parseRelationship,
|
|
19
|
+
type Relationship,
|
|
20
|
+
type Resource,
|
|
21
|
+
} from "@/ontology/payload";
|
|
22
|
+
import { type Retriever } from "@/ontology/retriever";
|
|
23
|
+
|
|
24
|
+
export type ResourceChange = change.Change<ID, Resource>;
|
|
25
|
+
export type RelationshipChange = change.Change<Relationship, undefined>;
|
|
26
|
+
|
|
27
|
+
const RESOURCE_SET_NAME = "sy_ontology_resource_set";
|
|
28
|
+
const RESOURCE_DELETE_NAME = "sy_ontology_resource_delete";
|
|
29
|
+
const RELATIONSHIP_SET_NAME = "sy_ontology_relationship_set";
|
|
30
|
+
const RELATIONSHIP_DELETE_NAME = "sy_ontology_relationship_delete";
|
|
31
|
+
|
|
32
|
+
export class ChangeTracker {
|
|
33
|
+
private readonly resourceObs: observe.Observer<ResourceChange[]>;
|
|
34
|
+
private readonly relationshipObs: observe.Observer<RelationshipChange[]>;
|
|
35
|
+
|
|
36
|
+
readonly relationships: observe.Observable<RelationshipChange[]>;
|
|
37
|
+
readonly resources: observe.Observable<ResourceChange[]>;
|
|
38
|
+
|
|
39
|
+
private readonly streamer: FrameStreamer;
|
|
40
|
+
private readonly retriever: Retriever;
|
|
41
|
+
private readonly closePromise: Promise<void>;
|
|
42
|
+
|
|
43
|
+
constructor(streamer: FrameStreamer, retriever: Retriever) {
|
|
44
|
+
this.relationshipObs = new observe.Observer<RelationshipChange[]>();
|
|
45
|
+
this.relationships = this.relationshipObs;
|
|
46
|
+
this.resourceObs = new observe.Observer<ResourceChange[]>();
|
|
47
|
+
this.resources = this.resourceObs;
|
|
48
|
+
this.retriever = retriever;
|
|
49
|
+
this.streamer = streamer;
|
|
50
|
+
this.closePromise = this.start();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async close(): Promise<void> {
|
|
54
|
+
this.streamer.close();
|
|
55
|
+
await this.closePromise;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private async start(): Promise<void> {
|
|
59
|
+
for await (const frame of this.streamer) {
|
|
60
|
+
await this.update(frame);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private async update(frame: Frame): Promise<void> {
|
|
65
|
+
const resSets = await this.parseResourceSets(frame);
|
|
66
|
+
const resDeletes = this.parseResourceDeletes(frame);
|
|
67
|
+
const allResources = resSets.concat(resDeletes);
|
|
68
|
+
if (allResources.length > 0) this.resourceObs.notify(resSets.concat(resDeletes));
|
|
69
|
+
const relSets = this.parseRelationshipSets(frame);
|
|
70
|
+
const relDeletes = this.parseRelationshipDeletes(frame);
|
|
71
|
+
const allRels = relSets.concat(relDeletes);
|
|
72
|
+
if (allRels.length > 0) this.relationshipObs.notify(relSets.concat(relDeletes));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private parseRelationshipSets(frame: Frame): RelationshipChange[] {
|
|
76
|
+
const relationships = frame.get(RELATIONSHIP_SET_NAME);
|
|
77
|
+
if (relationships.length === 0) return [];
|
|
78
|
+
// We should only ever get one series of relationships
|
|
79
|
+
return relationships[0].toStrings().map((rel) => ({
|
|
80
|
+
variant: "set",
|
|
81
|
+
key: parseRelationship(rel),
|
|
82
|
+
value: undefined,
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private parseRelationshipDeletes(frame: Frame): RelationshipChange[] {
|
|
87
|
+
const relationships = frame.get(RELATIONSHIP_DELETE_NAME);
|
|
88
|
+
if (relationships.length === 0) return [];
|
|
89
|
+
// We should only ever get one series of relationships
|
|
90
|
+
return relationships[0].toStrings().map((rel) => ({
|
|
91
|
+
variant: "delete",
|
|
92
|
+
key: parseRelationship(rel),
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private async parseResourceSets(frame: Frame): Promise<ResourceChange[]> {
|
|
97
|
+
const sets = frame.get(RESOURCE_SET_NAME);
|
|
98
|
+
if (sets.length === 0) return [];
|
|
99
|
+
// We should only ever get one series of sets
|
|
100
|
+
const ids = sets[0].toStrings().map((id) => new ID(id));
|
|
101
|
+
try {
|
|
102
|
+
const resources = await this.retriever.retrieve(ids);
|
|
103
|
+
return resources.map((resource) => ({
|
|
104
|
+
variant: "set",
|
|
105
|
+
key: resource.id,
|
|
106
|
+
value: resource,
|
|
107
|
+
}));
|
|
108
|
+
} catch (e) {
|
|
109
|
+
if (e instanceof QueryError) {
|
|
110
|
+
console.warn(e);
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
throw e;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private parseResourceDeletes(frame: Frame): ResourceChange[] {
|
|
118
|
+
const deletes = frame.get(RESOURCE_DELETE_NAME);
|
|
119
|
+
if (deletes.length === 0) return [];
|
|
120
|
+
// We should only ever get one series of deletes
|
|
121
|
+
return deletes[0]
|
|
122
|
+
.toStrings()
|
|
123
|
+
.map((str) => ({ variant: "delete", key: new ID(str) }));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static async open(client: FrameClient, retriever: Retriever): Promise<ChangeTracker> {
|
|
127
|
+
const streamer = await client.newStreamer([
|
|
128
|
+
RESOURCE_SET_NAME,
|
|
129
|
+
RESOURCE_DELETE_NAME,
|
|
130
|
+
RELATIONSHIP_SET_NAME,
|
|
131
|
+
RELATIONSHIP_DELETE_NAME,
|
|
132
|
+
]);
|
|
133
|
+
return new ChangeTracker(streamer, retriever);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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 { type AsyncTermSearcher } from "@synnaxlabs/x";
|
|
12
|
+
|
|
13
|
+
import { type Client as FrameClient } from "@/framer/client";
|
|
14
|
+
import { ChangeTracker } from "@/ontology/cdc";
|
|
15
|
+
import { group } from "@/ontology/group";
|
|
16
|
+
import { type ID, type Resource } from "@/ontology/payload";
|
|
17
|
+
import { Retriever } from "@/ontology/retriever";
|
|
18
|
+
import { Writer } from "@/ontology/writer";
|
|
19
|
+
|
|
20
|
+
import { QueryError } from "..";
|
|
21
|
+
|
|
22
|
+
/** The core client class for executing queries against a Synnax cluster ontology */
|
|
23
|
+
export class Client implements AsyncTermSearcher<string, string, Resource> {
|
|
24
|
+
groups: group.Client;
|
|
25
|
+
retriever: Retriever;
|
|
26
|
+
private readonly writer: Writer;
|
|
27
|
+
private readonly framer: FrameClient;
|
|
28
|
+
|
|
29
|
+
constructor(unary: UnaryClient, framer: FrameClient) {
|
|
30
|
+
this.retriever = new Retriever(unary);
|
|
31
|
+
this.writer = new Writer(unary);
|
|
32
|
+
this.groups = new group.Client(unary);
|
|
33
|
+
this.framer = framer;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async search(term: string): Promise<Resource[]> {
|
|
37
|
+
return await this.retriever.search(term);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async retrieve(
|
|
41
|
+
id: ID | string,
|
|
42
|
+
includeSchema?: boolean,
|
|
43
|
+
includeFieldData?: boolean,
|
|
44
|
+
): Promise<Resource>;
|
|
45
|
+
|
|
46
|
+
async retrieve(
|
|
47
|
+
ids: ID[] | string[],
|
|
48
|
+
includeSchema?: boolean,
|
|
49
|
+
includeFieldData?: boolean,
|
|
50
|
+
): Promise<Resource[]>;
|
|
51
|
+
|
|
52
|
+
async retrieve(
|
|
53
|
+
ids: ID | ID[] | string | string[],
|
|
54
|
+
includeSchema?: boolean,
|
|
55
|
+
includeFieldData?: boolean,
|
|
56
|
+
): Promise<Resource | Resource[]> {
|
|
57
|
+
const resources = await this.retriever.retrieve(
|
|
58
|
+
ids,
|
|
59
|
+
includeSchema,
|
|
60
|
+
includeFieldData,
|
|
61
|
+
);
|
|
62
|
+
if (Array.isArray(ids)) return resources;
|
|
63
|
+
if (resources.length === 0)
|
|
64
|
+
throw new QueryError(`No resource found with ID ${ids.toString()}`);
|
|
65
|
+
return resources[0];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async page(offset: number, limit: number): Promise<Resource[]> {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async retrieveChildren(
|
|
73
|
+
IDs: ID | ID[],
|
|
74
|
+
includeSchema?: boolean,
|
|
75
|
+
includeFieldData?: boolean,
|
|
76
|
+
): Promise<Resource[]> {
|
|
77
|
+
return await this.retriever.retrieveChildren(IDs, includeSchema, includeFieldData);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async retrieveParents(
|
|
81
|
+
IDs: ID | ID[],
|
|
82
|
+
includeSchema?: boolean,
|
|
83
|
+
includeFieldData?: boolean,
|
|
84
|
+
): Promise<Resource[]> {
|
|
85
|
+
return await this.retriever.retrieveParents(IDs, includeSchema, includeFieldData);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async addChildren(id: ID, ...children: ID[]): Promise<void> {
|
|
89
|
+
return await this.writer.addChildren(id, ...children);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async removeChildren(id: ID, ...children: ID[]): Promise<void> {
|
|
93
|
+
return await this.writer.removeChildren(id, ...children);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async moveChildren(from: ID, to: ID, ...children: ID[]): Promise<void> {
|
|
97
|
+
return await this.writer.moveChildren(from, to, ...children);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async openChangeTracker(): Promise<ChangeTracker> {
|
|
101
|
+
return await ChangeTracker.open(this.framer, this.retriever);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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 * from "@/ontology/client";
|
|
11
|
+
export * from "@/ontology/payload";
|
|
12
|
+
export * from "@/ontology/cdc";
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
|
|
12
|
+
import { type ID } from "@/ontology/payload";
|
|
13
|
+
|
|
14
|
+
import { Group } from "./group";
|
|
15
|
+
import { type Payload } from "./payload";
|
|
16
|
+
import { Writer } from "./writer";
|
|
17
|
+
|
|
18
|
+
export class Client {
|
|
19
|
+
private readonly creator: Writer;
|
|
20
|
+
|
|
21
|
+
constructor(unary: UnaryClient) {
|
|
22
|
+
this.creator = new Writer(unary);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async create(parent: ID, name: string): Promise<Group> {
|
|
26
|
+
return this.sugar(await this.creator.create(parent, name));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async rename(key: string, name: string): Promise<void> {
|
|
30
|
+
return await this.creator.rename(key, name);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async delete(...keys: string[]): Promise<void> {
|
|
34
|
+
return await this.creator.delete(keys);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private sugar(payload: Payload): Group {
|
|
38
|
+
return new Group(payload.name, payload.key);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 * from "@/ontology/group/group";
|
|
11
|
+
export * from "@/ontology/group/client";
|
|
@@ -0,0 +1,46 @@
|
|
|
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, it, expect } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { QueryError } from "@/errors";
|
|
13
|
+
import { ontology } from "@/ontology";
|
|
14
|
+
import { newClient } from "@/setupspecs";
|
|
15
|
+
|
|
16
|
+
const client = newClient();
|
|
17
|
+
|
|
18
|
+
describe("Group", () => {
|
|
19
|
+
describe("create", () => {
|
|
20
|
+
it("should correctly create a group", async () => {
|
|
21
|
+
const name = `group-${Math.random()}`;
|
|
22
|
+
const g = await client.ontology.groups.create(ontology.Root, name);
|
|
23
|
+
expect(g.name).toEqual(name);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe("rename", () => {
|
|
27
|
+
it("should correctly rename a group", async () => {
|
|
28
|
+
const name = `group-${Math.random()}`;
|
|
29
|
+
const g = await client.ontology.groups.create(ontology.Root, name);
|
|
30
|
+
const newName = `group-${Math.random()}`;
|
|
31
|
+
await client.ontology.groups.rename(g.key, newName);
|
|
32
|
+
const g2 = await client.ontology.retrieve(g.ontologyID);
|
|
33
|
+
expect(g2.name).toEqual(newName);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe("delete", () => {
|
|
37
|
+
it("should correctly delete the group", async () => {
|
|
38
|
+
const name = `group-${Math.random()}`;
|
|
39
|
+
const g = await client.ontology.groups.create(ontology.Root, name);
|
|
40
|
+
await client.ontology.groups.delete(g.key);
|
|
41
|
+
await expect(
|
|
42
|
+
async () => await client.ontology.retrieve(g.ontologyID),
|
|
43
|
+
).rejects.toThrow(QueryError);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { ontology } from "@/ontology";
|
|
11
|
+
|
|
12
|
+
export class Group {
|
|
13
|
+
key: string;
|
|
14
|
+
name: string;
|
|
15
|
+
|
|
16
|
+
constructor(name: string, key: string) {
|
|
17
|
+
this.key = key;
|
|
18
|
+
this.name = name;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get ontologyID(): ontology.ID {
|
|
22
|
+
return new ontology.ID({
|
|
23
|
+
type: "group",
|
|
24
|
+
key: this.key,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -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 group from "@/ontology/group/external";
|