@synnaxlabs/client 0.2.1 → 0.13.6

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.
Files changed (299) hide show
  1. package/.eslintrc.cjs +18 -0
  2. package/.pytest_cache/README.md +8 -0
  3. package/.turbo/turbo-build.log +16 -0
  4. package/LICENSE +4 -21
  5. package/{build/module/lib → dist/auth}/auth.d.ts +16 -19
  6. package/dist/auth/index.d.ts +1 -0
  7. package/dist/cdc/external.d.ts +1 -0
  8. package/dist/cdc/index.d.ts +1 -0
  9. package/dist/cdc/observable.d.ts +17 -0
  10. package/dist/channel/client.d.ts +58 -0
  11. package/dist/channel/creator.d.ts +8 -0
  12. package/dist/channel/external.d.ts +4 -0
  13. package/dist/channel/index.d.ts +1 -0
  14. package/dist/channel/payload.d.ts +63 -0
  15. package/dist/channel/retriever.d.ts +49 -0
  16. package/dist/client.cjs.js +23050 -0
  17. package/dist/client.cjs.js.map +1 -0
  18. package/dist/client.d.ts +73 -0
  19. package/dist/client.es.js +23050 -0
  20. package/dist/client.es.js.map +1 -0
  21. package/dist/connection/checker.d.ts +66 -0
  22. package/dist/connection/index.d.ts +1 -0
  23. package/dist/control/authority.d.ts +6 -0
  24. package/dist/control/external.d.ts +2 -0
  25. package/dist/control/index.d.ts +1 -0
  26. package/dist/control/state.d.ts +81 -0
  27. package/{build/main/lib → dist}/errors.d.ts +6 -3
  28. package/dist/framer/adapter.d.ts +21 -0
  29. package/dist/framer/client.d.ts +44 -0
  30. package/dist/framer/external.d.ts +5 -0
  31. package/dist/framer/frame.d.ts +251 -0
  32. package/dist/framer/index.d.ts +1 -0
  33. package/{build/module/lib/segment → dist/framer}/iterator.d.ts +32 -64
  34. package/dist/framer/streamProxy.d.ts +12 -0
  35. package/dist/framer/streamer.d.ts +17 -0
  36. package/dist/framer/writer.d.ts +257 -0
  37. package/dist/index.d.ts +16 -0
  38. package/dist/label/client.d.ts +25 -0
  39. package/dist/label/external.d.ts +4 -0
  40. package/dist/label/index.d.ts +1 -0
  41. package/dist/label/payload.d.ts +20 -0
  42. package/dist/label/retriever.d.ts +13 -0
  43. package/dist/label/writer.d.ts +26 -0
  44. package/dist/ontology/cdc.d.ts +25 -0
  45. package/dist/ontology/client.d.ts +25 -0
  46. package/dist/ontology/external.d.ts +3 -0
  47. package/dist/ontology/group/client.d.ts +11 -0
  48. package/dist/ontology/group/external.d.ts +2 -0
  49. package/dist/ontology/group/group.d.ts +7 -0
  50. package/dist/ontology/group/index.d.ts +1 -0
  51. package/dist/ontology/group/payload.d.ts +40 -0
  52. package/dist/ontology/group/writer.d.ts +13 -0
  53. package/dist/ontology/index.d.ts +1 -0
  54. package/dist/ontology/ontology.spec.d.ts +1 -0
  55. package/dist/ontology/payload.d.ts +235 -0
  56. package/dist/ontology/retriever.d.ts +12 -0
  57. package/dist/ontology/signals.d.ts +25 -0
  58. package/dist/ontology/writer.d.ts +9 -0
  59. package/dist/ranger/active.d.ts +9 -0
  60. package/dist/ranger/alias.d.ts +32 -0
  61. package/dist/ranger/client.d.ts +31 -0
  62. package/dist/ranger/external.d.ts +6 -0
  63. package/dist/ranger/index.d.ts +1 -0
  64. package/dist/ranger/kv.d.ts +50 -0
  65. package/dist/ranger/payload.d.ts +94 -0
  66. package/dist/ranger/range.d.ts +29 -0
  67. package/dist/ranger/ranger.spec.d.ts +1 -0
  68. package/dist/ranger/retriever.d.ts +10 -0
  69. package/dist/ranger/writer.d.ts +9 -0
  70. package/{build/main → dist}/setupspecs.d.ts +2 -2
  71. package/dist/signals/external.d.ts +1 -0
  72. package/dist/signals/index.d.ts +1 -0
  73. package/dist/signals/observable.d.ts +17 -0
  74. package/dist/transport.d.ts +10 -0
  75. package/dist/user/index.d.ts +1 -0
  76. package/{build/main/lib → dist}/user/payload.d.ts +3 -3
  77. package/dist/util/telem.d.ts +2 -0
  78. package/dist/workspace/client.d.ts +22 -0
  79. package/dist/workspace/external.d.ts +2 -0
  80. package/dist/workspace/index.d.ts +1 -0
  81. package/dist/workspace/lineplot/client.d.ts +15 -0
  82. package/dist/workspace/lineplot/external.d.ts +2 -0
  83. package/dist/workspace/lineplot/index.d.ts +1 -0
  84. package/dist/workspace/lineplot/linePlot.spec.d.ts +1 -0
  85. package/dist/workspace/lineplot/payload.d.ts +31 -0
  86. package/dist/workspace/lineplot/retriever.d.ts +9 -0
  87. package/dist/workspace/lineplot/writer.d.ts +39 -0
  88. package/dist/workspace/payload.d.ts +31 -0
  89. package/dist/workspace/pid/client.d.ts +16 -0
  90. package/dist/workspace/pid/external.d.ts +2 -0
  91. package/dist/workspace/pid/index.d.ts +1 -0
  92. package/dist/workspace/pid/payload.d.ts +37 -0
  93. package/dist/workspace/pid/pid.spec.d.ts +1 -0
  94. package/dist/workspace/pid/retriever.d.ts +9 -0
  95. package/dist/workspace/pid/writer.d.ts +46 -0
  96. package/dist/workspace/retriever.d.ts +12 -0
  97. package/dist/workspace/workspace.spec.d.ts +1 -0
  98. package/dist/workspace/writer.d.ts +55 -0
  99. package/package.json +27 -98
  100. package/src/auth/auth.spec.ts +46 -0
  101. package/src/auth/auth.ts +83 -0
  102. package/src/auth/index.ts +10 -0
  103. package/src/channel/channel.spec.ts +82 -0
  104. package/src/channel/client.ts +209 -0
  105. package/src/channel/creator.ts +43 -0
  106. package/src/channel/external.ts +13 -0
  107. package/src/channel/index.ts +10 -0
  108. package/src/channel/payload.ts +52 -0
  109. package/src/channel/retriever.ts +160 -0
  110. package/src/client.ts +116 -0
  111. package/src/connection/checker.ts +104 -0
  112. package/src/connection/connection.spec.ts +35 -0
  113. package/src/connection/index.ts +10 -0
  114. package/src/control/authority.ts +26 -0
  115. package/src/control/external.ts +11 -0
  116. package/src/control/index.ts +10 -0
  117. package/src/control/state.spec.ts +24 -0
  118. package/src/control/state.ts +133 -0
  119. package/src/errors.ts +163 -0
  120. package/src/framer/adapter.ts +116 -0
  121. package/src/framer/client.ts +116 -0
  122. package/src/framer/external.ts +14 -0
  123. package/src/framer/frame.spec.ts +317 -0
  124. package/src/framer/frame.ts +412 -0
  125. package/src/framer/index.ts +10 -0
  126. package/src/framer/iterator.spec.ts +62 -0
  127. package/src/framer/iterator.ts +240 -0
  128. package/src/framer/streamProxy.ts +59 -0
  129. package/src/framer/streamer.spec.ts +42 -0
  130. package/src/framer/streamer.ts +86 -0
  131. package/src/framer/writer.spec.ts +52 -0
  132. package/src/framer/writer.ts +236 -0
  133. package/src/index.ts +53 -0
  134. package/src/label/client.ts +103 -0
  135. package/src/label/external.ts +13 -0
  136. package/src/label/index.ts +10 -0
  137. package/src/label/label.spec.ts +51 -0
  138. package/src/label/payload.ts +29 -0
  139. package/src/label/retriever.ts +65 -0
  140. package/src/label/writer.ts +90 -0
  141. package/src/ontology/client.ts +104 -0
  142. package/src/ontology/external.ts +12 -0
  143. package/src/ontology/group/client.ts +40 -0
  144. package/src/ontology/group/external.ts +11 -0
  145. package/src/ontology/group/group.spec.ts +46 -0
  146. package/src/ontology/group/group.ts +27 -0
  147. package/src/ontology/group/index.ts +10 -0
  148. package/src/ontology/group/payload.ts +65 -0
  149. package/src/ontology/group/writer.ts +48 -0
  150. package/src/ontology/index.ts +10 -0
  151. package/src/ontology/ontology.spec.ts +114 -0
  152. package/src/ontology/payload.ts +118 -0
  153. package/src/ontology/retriever.ts +91 -0
  154. package/src/ontology/signals.ts +135 -0
  155. package/src/ontology/writer.ts +49 -0
  156. package/src/ranger/active.ts +56 -0
  157. package/src/ranger/alias.ts +183 -0
  158. package/src/ranger/client.ts +129 -0
  159. package/src/ranger/external.ts +15 -0
  160. package/src/ranger/index.ts +10 -0
  161. package/src/ranger/kv.ts +91 -0
  162. package/src/ranger/payload.ts +70 -0
  163. package/src/ranger/range.ts +95 -0
  164. package/src/ranger/ranger.spec.ts +201 -0
  165. package/src/ranger/retriever.ts +50 -0
  166. package/src/ranger/writer.ts +80 -0
  167. package/src/setupspecs.ts +25 -0
  168. package/src/signals/external.ts +10 -0
  169. package/src/signals/index.ts +10 -0
  170. package/src/signals/observable.ts +80 -0
  171. package/src/transport.ts +39 -0
  172. package/src/user/index.ts +10 -0
  173. package/src/user/payload.ts +17 -0
  174. package/src/util/telem.ts +19 -0
  175. package/src/vite-env.d.ts +11 -0
  176. package/src/workspace/client.ts +75 -0
  177. package/src/workspace/external.ts +11 -0
  178. package/src/workspace/index.ts +10 -0
  179. package/src/workspace/lineplot/client.ts +51 -0
  180. package/src/workspace/lineplot/external.ts +11 -0
  181. package/src/workspace/lineplot/index.ts +10 -0
  182. package/src/workspace/lineplot/linePlot.spec.ts +78 -0
  183. package/src/workspace/lineplot/payload.ts +29 -0
  184. package/src/workspace/lineplot/retriever.ts +49 -0
  185. package/src/workspace/lineplot/writer.ts +109 -0
  186. package/src/workspace/payload.ts +29 -0
  187. package/src/workspace/pid/client.ts +55 -0
  188. package/src/workspace/pid/external.ts +11 -0
  189. package/src/workspace/pid/index.ts +10 -0
  190. package/src/workspace/pid/payload.ts +31 -0
  191. package/src/workspace/pid/pid.spec.ts +111 -0
  192. package/src/workspace/pid/retriever.ts +45 -0
  193. package/src/workspace/pid/writer.ts +130 -0
  194. package/src/workspace/retriever.ts +66 -0
  195. package/src/workspace/workspace.spec.ts +62 -0
  196. package/src/workspace/writer.ts +103 -0
  197. package/tsconfig.json +7 -0
  198. package/tsconfig.vite.json +4 -0
  199. package/vite.config.ts +25 -0
  200. package/CHANGELOG.md +0 -5
  201. package/build/main/index.d.ts +0 -4
  202. package/build/main/index.js +0 -35
  203. package/build/main/lib/auth.d.ts +0 -54
  204. package/build/main/lib/auth.js +0 -62
  205. package/build/main/lib/auth.spec.js +0 -39
  206. package/build/main/lib/channel/channel.spec.js +0 -49
  207. package/build/main/lib/channel/client.d.ts +0 -94
  208. package/build/main/lib/channel/client.js +0 -134
  209. package/build/main/lib/channel/creator.d.ts +0 -19
  210. package/build/main/lib/channel/creator.js +0 -44
  211. package/build/main/lib/channel/payload.d.ts +0 -25
  212. package/build/main/lib/channel/payload.js +0 -18
  213. package/build/main/lib/channel/registry.d.ts +0 -9
  214. package/build/main/lib/channel/registry.js +0 -37
  215. package/build/main/lib/channel/retriever.d.ts +0 -11
  216. package/build/main/lib/channel/retriever.js +0 -39
  217. package/build/main/lib/client.d.ts +0 -30
  218. package/build/main/lib/client.js +0 -46
  219. package/build/main/lib/errors.js +0 -122
  220. package/build/main/lib/segment/client.d.ts +0 -62
  221. package/build/main/lib/segment/client.js +0 -95
  222. package/build/main/lib/segment/iterator.d.ts +0 -134
  223. package/build/main/lib/segment/iterator.js +0 -253
  224. package/build/main/lib/segment/iterator.spec.js +0 -73
  225. package/build/main/lib/segment/payload.d.ts +0 -16
  226. package/build/main/lib/segment/payload.js +0 -13
  227. package/build/main/lib/segment/splitter.d.ts +0 -7
  228. package/build/main/lib/segment/splitter.js +0 -25
  229. package/build/main/lib/segment/typed.d.ts +0 -15
  230. package/build/main/lib/segment/typed.js +0 -49
  231. package/build/main/lib/segment/validator.d.ts +0 -22
  232. package/build/main/lib/segment/validator.js +0 -64
  233. package/build/main/lib/segment/writer.d.ts +0 -98
  234. package/build/main/lib/segment/writer.js +0 -183
  235. package/build/main/lib/segment/writer.spec.js +0 -90
  236. package/build/main/lib/telem.d.ts +0 -395
  237. package/build/main/lib/telem.js +0 -553
  238. package/build/main/lib/telem.spec.js +0 -152
  239. package/build/main/lib/transport.d.ts +0 -10
  240. package/build/main/lib/transport.js +0 -22
  241. package/build/main/lib/user/payload.js +0 -9
  242. package/build/main/lib/util/telem.d.ts +0 -2
  243. package/build/main/lib/util/telem.js +0 -13
  244. package/build/main/setupspecs.js +0 -17
  245. package/build/module/index.d.ts +0 -4
  246. package/build/module/index.js +0 -5
  247. package/build/module/lib/auth.js +0 -63
  248. package/build/module/lib/auth.spec.js +0 -34
  249. package/build/module/lib/channel/channel.spec.js +0 -44
  250. package/build/module/lib/channel/client.d.ts +0 -94
  251. package/build/module/lib/channel/client.js +0 -134
  252. package/build/module/lib/channel/creator.d.ts +0 -19
  253. package/build/module/lib/channel/creator.js +0 -42
  254. package/build/module/lib/channel/payload.d.ts +0 -25
  255. package/build/module/lib/channel/payload.js +0 -15
  256. package/build/module/lib/channel/registry.d.ts +0 -9
  257. package/build/module/lib/channel/registry.js +0 -36
  258. package/build/module/lib/channel/retriever.d.ts +0 -11
  259. package/build/module/lib/channel/retriever.js +0 -37
  260. package/build/module/lib/client.d.ts +0 -30
  261. package/build/module/lib/client.js +0 -44
  262. package/build/module/lib/errors.d.ts +0 -53
  263. package/build/module/lib/errors.js +0 -113
  264. package/build/module/lib/segment/client.d.ts +0 -62
  265. package/build/module/lib/segment/client.js +0 -94
  266. package/build/module/lib/segment/iterator.js +0 -248
  267. package/build/module/lib/segment/iterator.spec.js +0 -68
  268. package/build/module/lib/segment/payload.d.ts +0 -16
  269. package/build/module/lib/segment/payload.js +0 -10
  270. package/build/module/lib/segment/splitter.d.ts +0 -7
  271. package/build/module/lib/segment/splitter.js +0 -26
  272. package/build/module/lib/segment/typed.d.ts +0 -15
  273. package/build/module/lib/segment/typed.js +0 -49
  274. package/build/module/lib/segment/validator.d.ts +0 -22
  275. package/build/module/lib/segment/validator.js +0 -60
  276. package/build/module/lib/segment/writer.d.ts +0 -98
  277. package/build/module/lib/segment/writer.js +0 -183
  278. package/build/module/lib/segment/writer.spec.js +0 -85
  279. package/build/module/lib/telem.d.ts +0 -395
  280. package/build/module/lib/telem.js +0 -545
  281. package/build/module/lib/telem.spec.js +0 -147
  282. package/build/module/lib/transport.d.ts +0 -10
  283. package/build/module/lib/transport.js +0 -22
  284. package/build/module/lib/user/payload.d.ts +0 -12
  285. package/build/module/lib/user/payload.js +0 -6
  286. package/build/module/lib/util/telem.d.ts +0 -2
  287. package/build/module/lib/util/telem.js +0 -9
  288. package/build/module/setupspecs.d.ts +0 -4
  289. package/build/module/setupspecs.js +0 -16
  290. /package/{build/main/lib → dist/auth}/auth.spec.d.ts +0 -0
  291. /package/{build/main/lib → dist}/channel/channel.spec.d.ts +0 -0
  292. /package/{build/main/lib/segment/iterator.spec.d.ts → dist/connection/connection.spec.d.ts} +0 -0
  293. /package/{build/main/lib/segment/writer.spec.d.ts → dist/control/state.spec.d.ts} +0 -0
  294. /package/{build/main/lib/telem.spec.d.ts → dist/framer/frame.spec.d.ts} +0 -0
  295. /package/{build/module/lib/segment → dist/framer}/iterator.spec.d.ts +0 -0
  296. /package/{build/module/lib/auth.spec.d.ts → dist/framer/streamer.spec.d.ts} +0 -0
  297. /package/{build/module/lib/segment → dist/framer}/writer.spec.d.ts +0 -0
  298. /package/{build/module/lib/channel/channel.spec.d.ts → dist/label/label.spec.d.ts} +0 -0
  299. /package/{build/module/lib/telem.spec.d.ts → dist/ontology/group/group.spec.d.ts} +0 -0
@@ -0,0 +1,104 @@
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 { group } from "@/ontology/group";
15
+ import { type ID, type Resource } from "@/ontology/payload";
16
+ import { Retriever } from "@/ontology/retriever";
17
+ import { Writer } from "@/ontology/writer";
18
+
19
+ import { QueryError } from "..";
20
+
21
+ import { ChangeTracker } from "@/ontology/signals";
22
+
23
+ /** The core client class for executing queries against a Synnax cluster ontology */
24
+ export class Client implements AsyncTermSearcher<string, string, Resource> {
25
+ groups: group.Client;
26
+ retriever: Retriever;
27
+ private readonly writer: Writer;
28
+ private readonly framer: FrameClient;
29
+
30
+ constructor(unary: UnaryClient, framer: FrameClient) {
31
+ this.retriever = new Retriever(unary);
32
+ this.writer = new Writer(unary);
33
+ this.groups = new group.Client(unary);
34
+ this.framer = framer;
35
+ }
36
+
37
+ async search(term: string): Promise<Resource[]> {
38
+ return await this.retriever.search(term);
39
+ }
40
+
41
+ async retrieve(
42
+ id: ID | string,
43
+ includeSchema?: boolean,
44
+ includeFieldData?: boolean,
45
+ ): Promise<Resource>;
46
+
47
+ async retrieve(
48
+ ids: ID[] | string[],
49
+ includeSchema?: boolean,
50
+ includeFieldData?: boolean,
51
+ ): Promise<Resource[]>;
52
+
53
+ async retrieve(
54
+ ids: ID | ID[] | string | string[],
55
+ includeSchema?: boolean,
56
+ includeFieldData?: boolean,
57
+ ): Promise<Resource | Resource[]> {
58
+ const resources = await this.retriever.retrieve(
59
+ ids,
60
+ includeSchema,
61
+ includeFieldData,
62
+ );
63
+ if (Array.isArray(ids)) return resources;
64
+ if (resources.length === 0)
65
+ throw new QueryError(`No resource found with ID ${ids.toString()}`);
66
+ return resources[0];
67
+ }
68
+
69
+ async page(offset: number, limit: number): Promise<Resource[]> {
70
+ return [];
71
+ }
72
+
73
+ async retrieveChildren(
74
+ IDs: ID | ID[],
75
+ includeSchema?: boolean,
76
+ includeFieldData?: boolean,
77
+ ): Promise<Resource[]> {
78
+ return await this.retriever.retrieveChildren(IDs, includeSchema, includeFieldData);
79
+ }
80
+
81
+ async retrieveParents(
82
+ IDs: ID | ID[],
83
+ includeSchema?: boolean,
84
+ includeFieldData?: boolean,
85
+ ): Promise<Resource[]> {
86
+ return await this.retriever.retrieveParents(IDs, includeSchema, includeFieldData);
87
+ }
88
+
89
+ async addChildren(id: ID, ...children: ID[]): Promise<void> {
90
+ return await this.writer.addChildren(id, ...children);
91
+ }
92
+
93
+ async removeChildren(id: ID, ...children: ID[]): Promise<void> {
94
+ return await this.writer.removeChildren(id, ...children);
95
+ }
96
+
97
+ async moveChildren(from: ID, to: ID, ...children: ID[]): Promise<void> {
98
+ return await this.writer.moveChildren(from, to, ...children);
99
+ }
100
+
101
+ async openChangeTracker(): Promise<ChangeTracker> {
102
+ return await ChangeTracker.open(this.framer, this.retriever);
103
+ }
104
+ }
@@ -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/signals";
@@ -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";
@@ -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("signals", 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,118 @@
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("label"),
14
+ z.literal("builtin"),
15
+ z.literal("cluster"),
16
+ z.literal("channel"),
17
+ z.literal("node"),
18
+ z.literal("group"),
19
+ z.literal("range"),
20
+ z.literal("range-alias"),
21
+ z.literal("user"),
22
+ z.literal("workspace"),
23
+ z.literal("pid"),
24
+ z.literal("lineplot"),
25
+ ]);
26
+
27
+ export type ResourceType = z.infer<typeof resourceTypeZ>;
28
+
29
+ export const idZ = z.object({
30
+ type: resourceTypeZ,
31
+ key: z.string(),
32
+ });
33
+
34
+ export const stringIDZ = z.string().transform((v) => {
35
+ const [type, key] = v.split(":");
36
+ return {
37
+ type: type as ResourceType,
38
+ key,
39
+ };
40
+ });
41
+
42
+ export const crudeIDZ = z.union([stringIDZ, idZ]);
43
+
44
+ export class ID {
45
+ type: ResourceType;
46
+ key: string;
47
+
48
+ constructor(args: z.input<typeof crudeIDZ> | ID) {
49
+ if (args instanceof ID) {
50
+ this.type = args.type;
51
+ this.key = args.key;
52
+ } else if (typeof args === "string") {
53
+ const [type, key] = args.split(":");
54
+ this.type = type as ResourceType;
55
+ this.key = key;
56
+ } else {
57
+ this.type = args.type;
58
+ this.key = args.key;
59
+ }
60
+ }
61
+
62
+ toString(): string {
63
+ return `${this.type}:${this.key}`;
64
+ }
65
+
66
+ get payload(): z.infer<typeof idZ> {
67
+ return {
68
+ type: this.type,
69
+ key: this.key,
70
+ };
71
+ }
72
+
73
+ static readonly z = z.union([crudeIDZ, z.instanceof(ID)]).transform((v) => new ID(v));
74
+ }
75
+
76
+ export const Root = new ID({ type: "builtin", key: "root" });
77
+
78
+ export const schemaFieldZ = z.object({
79
+ type: z.number(),
80
+ });
81
+
82
+ export type SchemaField = z.infer<typeof schemaFieldZ>;
83
+
84
+ export const schemaZ = z.object({
85
+ type: resourceTypeZ,
86
+ fields: z.record(schemaFieldZ),
87
+ });
88
+
89
+ export type Schema = z.infer<typeof schemaZ>;
90
+
91
+ export const resourceSchemaZ = z
92
+ .object({
93
+ id: ID.z,
94
+ name: z.string(),
95
+ schema: schemaZ.optional(),
96
+ data: z.record(z.unknown()).optional(),
97
+ })
98
+ .transform((resource) => {
99
+ return {
100
+ key: resource.id.toString(),
101
+ ...resource,
102
+ };
103
+ });
104
+
105
+ export type Resource = z.infer<typeof resourceSchemaZ>;
106
+
107
+ export const relationshipSchemaZ = z.object({
108
+ from: ID.z,
109
+ type: z.string(),
110
+ to: ID.z,
111
+ });
112
+
113
+ export type Relationship = z.infer<typeof relationshipSchemaZ>;
114
+
115
+ export const parseRelationship = (str: string): Relationship => {
116
+ const [from, type, to] = str.split("->");
117
+ return { from: new ID(from), type, to: new ID(to) };
118
+ };