@credibledata/cred-cli 0.1.4 → 0.1.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.
Files changed (172) hide show
  1. package/.prettierignore +2 -1
  2. package/README.md +0 -2
  3. package/bun.lock +182 -283
  4. package/dist/client/api.js +796 -111
  5. package/dist/client/api.js.map +1 -1
  6. package/dist/clientconfiguration.js +55 -13
  7. package/dist/clientconfiguration.js.map +1 -1
  8. package/dist/clientconfiguration.spec.js +305 -16
  9. package/dist/clientconfiguration.spec.js.map +1 -1
  10. package/dist/commands/add.js +6 -3
  11. package/dist/commands/add.js.map +1 -1
  12. package/dist/commands/connection/createconnections.js +18 -3
  13. package/dist/commands/connection/createconnections.js.map +1 -1
  14. package/dist/commands/connection/createconnections.spec.js +219 -0
  15. package/dist/commands/connection/createconnections.spec.js.map +1 -0
  16. package/dist/commands/connection/deleteconnection.spec.js +130 -0
  17. package/dist/commands/connection/deleteconnection.spec.js.map +1 -0
  18. package/dist/commands/connection/listconnections.js +9 -3
  19. package/dist/commands/connection/listconnections.js.map +1 -1
  20. package/dist/commands/connection/listconnections.spec.js +117 -0
  21. package/dist/commands/connection/listconnections.spec.js.map +1 -0
  22. package/dist/commands/group/addmember.js +2 -0
  23. package/dist/commands/group/addmember.js.map +1 -1
  24. package/dist/commands/group/addmember.spec.js +148 -0
  25. package/dist/commands/group/addmember.spec.js.map +1 -0
  26. package/dist/commands/group/creategroup.spec.js +122 -0
  27. package/dist/commands/group/creategroup.spec.js.map +1 -0
  28. package/dist/commands/group/deletegroup.spec.js +104 -0
  29. package/dist/commands/group/deletegroup.spec.js.map +1 -0
  30. package/dist/commands/group/getgroup.spec.js +111 -0
  31. package/dist/commands/group/getgroup.spec.js.map +1 -0
  32. package/dist/commands/group/listgroups.spec.js +118 -0
  33. package/dist/commands/group/listgroups.spec.js.map +1 -0
  34. package/dist/commands/group/removemember.js +1 -0
  35. package/dist/commands/group/removemember.js.map +1 -1
  36. package/dist/commands/group/removemember.spec.js +138 -0
  37. package/dist/commands/group/removemember.spec.js.map +1 -0
  38. package/dist/commands/groupaccesstoken/createToken.js +6 -2
  39. package/dist/commands/groupaccesstoken/createToken.js.map +1 -1
  40. package/dist/commands/groupaccesstoken/createToken.spec.js +127 -0
  41. package/dist/commands/groupaccesstoken/createToken.spec.js.map +1 -0
  42. package/dist/commands/groupaccesstoken/deleteToken.js.map +1 -1
  43. package/dist/commands/groupaccesstoken/deleteToken.spec.js +103 -0
  44. package/dist/commands/groupaccesstoken/deleteToken.spec.js.map +1 -0
  45. package/dist/commands/groupaccesstoken/groupContainer.js.map +1 -1
  46. package/dist/commands/groupaccesstoken/listTokens.js.map +1 -1
  47. package/dist/commands/groupaccesstoken/listTokens.spec.js +115 -0
  48. package/dist/commands/groupaccesstoken/listTokens.spec.js.map +1 -0
  49. package/dist/commands/list.js +10 -3
  50. package/dist/commands/list.js.map +1 -1
  51. package/dist/commands/misc/login.js +146 -22
  52. package/dist/commands/misc/login.js.map +1 -1
  53. package/dist/commands/misc/login.spec.js +111 -6
  54. package/dist/commands/misc/login.spec.js.map +1 -1
  55. package/dist/commands/misc/logout.spec.js +30 -0
  56. package/dist/commands/misc/logout.spec.js.map +1 -0
  57. package/dist/commands/misc/loopbackOAuth.js +110 -0
  58. package/dist/commands/misc/loopbackOAuth.js.map +1 -0
  59. package/dist/commands/misc/set-access-token.js.map +1 -1
  60. package/dist/commands/misc/set-access-token.spec.js +65 -0
  61. package/dist/commands/misc/set-access-token.spec.js.map +1 -0
  62. package/dist/commands/package/deletepackage.spec.js +136 -0
  63. package/dist/commands/package/deletepackage.spec.js.map +1 -0
  64. package/dist/commands/package/listpackages.js +10 -5
  65. package/dist/commands/package/listpackages.js.map +1 -1
  66. package/dist/commands/package/listpackages.spec.js +129 -0
  67. package/dist/commands/package/listpackages.spec.js.map +1 -0
  68. package/dist/commands/package/publish.js +23 -0
  69. package/dist/commands/package/publish.js.map +1 -1
  70. package/dist/commands/package/publish.spec.js +511 -0
  71. package/dist/commands/package/publish.spec.js.map +1 -0
  72. package/dist/commands/package/updatepackage.spec.js +50 -0
  73. package/dist/commands/package/updatepackage.spec.js.map +1 -1
  74. package/dist/commands/project/createproject.js +11 -1
  75. package/dist/commands/project/createproject.js.map +1 -1
  76. package/dist/commands/project/createproject.spec.js +154 -0
  77. package/dist/commands/project/createproject.spec.js.map +1 -0
  78. package/dist/commands/project/deleteproject.spec.js +106 -0
  79. package/dist/commands/project/deleteproject.spec.js.map +1 -0
  80. package/dist/commands/project/getproject.spec.js +99 -0
  81. package/dist/commands/project/getproject.spec.js.map +1 -0
  82. package/dist/commands/project/listprojects.js +13 -7
  83. package/dist/commands/project/listprojects.js.map +1 -1
  84. package/dist/commands/project/listprojects.spec.js +111 -0
  85. package/dist/commands/project/listprojects.spec.js.map +1 -0
  86. package/dist/commands/project/setproject.spec.js +58 -0
  87. package/dist/commands/project/setproject.spec.js.map +1 -0
  88. package/dist/commands/project/updateproject.js +68 -0
  89. package/dist/commands/project/updateproject.js.map +1 -0
  90. package/dist/commands/project/updateproject.spec.js +129 -0
  91. package/dist/commands/project/updateproject.spec.js.map +1 -0
  92. package/dist/commands/rm.js.map +1 -1
  93. package/dist/commands/update.js +13 -0
  94. package/dist/commands/update.js.map +1 -1
  95. package/dist/commands/version/listversions.spec.js +121 -0
  96. package/dist/commands/version/listversions.spec.js.map +1 -0
  97. package/dist/common/UserGroupId.spec.js +92 -0
  98. package/dist/common/UserGroupId.spec.js.map +1 -0
  99. package/dist/constants.js +49 -13
  100. package/dist/constants.js.map +1 -1
  101. package/dist/index.js +40 -18
  102. package/dist/index.js.map +1 -1
  103. package/dist/logger.spec.js +125 -0
  104. package/dist/logger.spec.js.map +1 -0
  105. package/dist/polyfills/file.polyfill.js.map +1 -1
  106. package/dist/utils.js +59 -0
  107. package/dist/utils.js.map +1 -1
  108. package/dist/utils.spec.js +158 -0
  109. package/dist/utils.spec.js.map +1 -0
  110. package/docker/Dockerfile.ci +11 -3
  111. package/eslint.config.mjs +45 -0
  112. package/generate-client.sh +3 -0
  113. package/package.json +24 -16
  114. package/src/client/.openapi-generator/FILES +1 -0
  115. package/src/client/api.ts +1347 -161
  116. package/src/clientconfiguration.spec.ts +394 -20
  117. package/src/clientconfiguration.ts +74 -15
  118. package/src/commands/add.ts +15 -6
  119. package/src/commands/connection/createconnections.spec.ts +403 -0
  120. package/src/commands/connection/createconnections.ts +30 -5
  121. package/src/commands/connection/deleteconnection.spec.ts +189 -0
  122. package/src/commands/connection/listconnections.spec.ts +132 -0
  123. package/src/commands/connection/listconnections.ts +22 -3
  124. package/src/commands/group/addmember.spec.ts +257 -0
  125. package/src/commands/group/addmember.ts +2 -0
  126. package/src/commands/group/creategroup.spec.ts +146 -0
  127. package/src/commands/group/deletegroup.spec.ts +120 -0
  128. package/src/commands/group/getgroup.spec.ts +129 -0
  129. package/src/commands/group/listgroups.spec.ts +137 -0
  130. package/src/commands/group/removemember.spec.ts +224 -0
  131. package/src/commands/group/removemember.ts +1 -0
  132. package/src/commands/groupaccesstoken/createToken.spec.ts +211 -0
  133. package/src/commands/groupaccesstoken/createToken.ts +55 -51
  134. package/src/commands/groupaccesstoken/deleteToken.spec.ts +147 -0
  135. package/src/commands/groupaccesstoken/deleteToken.ts +16 -11
  136. package/src/commands/groupaccesstoken/groupContainer.ts +51 -51
  137. package/src/commands/groupaccesstoken/listTokens.spec.ts +147 -0
  138. package/src/commands/groupaccesstoken/listTokens.ts +16 -11
  139. package/src/commands/list.ts +50 -9
  140. package/src/commands/misc/login.spec.ts +91 -6
  141. package/src/commands/misc/login.ts +208 -25
  142. package/src/commands/misc/logout.spec.ts +32 -0
  143. package/src/commands/misc/loopbackOAuth.ts +127 -0
  144. package/src/commands/misc/set-access-token.spec.ts +95 -0
  145. package/src/commands/misc/set-access-token.ts +16 -16
  146. package/src/commands/package/deletepackage.spec.ts +164 -0
  147. package/src/commands/package/listpackages.spec.ts +147 -0
  148. package/src/commands/package/listpackages.ts +28 -5
  149. package/src/commands/package/publish.spec.ts +597 -0
  150. package/src/commands/package/publish.ts +32 -0
  151. package/src/commands/package/updatepackage.spec.ts +98 -0
  152. package/src/commands/project/createproject.spec.ts +247 -0
  153. package/src/commands/project/createproject.ts +12 -1
  154. package/src/commands/project/deleteproject.spec.ts +123 -0
  155. package/src/commands/project/getproject.spec.ts +109 -0
  156. package/src/commands/project/listprojects.spec.ts +121 -0
  157. package/src/commands/project/listprojects.ts +33 -7
  158. package/src/commands/project/setproject.spec.ts +63 -0
  159. package/src/commands/project/updateproject.spec.ts +217 -0
  160. package/src/commands/project/updateproject.ts +82 -0
  161. package/src/commands/rm.ts +1 -6
  162. package/src/commands/update.ts +24 -1
  163. package/src/commands/version/listversions.spec.ts +138 -0
  164. package/src/common/UserGroupId.spec.ts +117 -0
  165. package/src/constants.ts +59 -13
  166. package/src/index.ts +46 -20
  167. package/src/logger.spec.ts +158 -0
  168. package/src/polyfills/file.polyfill.ts +1 -0
  169. package/src/utils.spec.ts +135 -0
  170. package/src/utils.ts +81 -0
  171. package/tsconfig.json +15 -18
  172. package/.eslintrc +0 -33
@@ -0,0 +1,403 @@
1
+ import { expect } from "chai";
2
+ import fs from "fs";
3
+ import sinon from "sinon";
4
+ import { ConnectionsApi } from "../../client/api";
5
+ import { ClientConfiguration } from "../../clientconfiguration";
6
+ import { logger } from "../../logger";
7
+ import { getConfirmation } from "../../utils";
8
+ import { createConnections } from "./createconnections";
9
+
10
+ describe("create-connections", () => {
11
+ let sandbox: sinon.SinonSandbox;
12
+ let createConnectionStub: sinon.SinonStub;
13
+ let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
14
+ let getConfirmationStub: sinon.SinonStub;
15
+ let readFileSyncStub: sinon.SinonStub;
16
+
17
+ beforeEach(() => {
18
+ sandbox = sinon.createSandbox();
19
+ createConnectionStub = sandbox.stub();
20
+ loggerStub = sandbox.stub(logger);
21
+ getConfirmationStub = sandbox.stub();
22
+ readFileSyncStub = sandbox.stub(fs, "readFileSync");
23
+
24
+ sandbox
25
+ .stub(ClientConfiguration.prototype, "getOrganization")
26
+ .returns("test-org");
27
+ sandbox
28
+ .stub(ClientConfiguration.prototype, "getProject")
29
+ .returns("test-project");
30
+ sandbox
31
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
32
+ .returns(true);
33
+ sandbox
34
+ .stub(ClientConfiguration.prototype, "getHeaders")
35
+ .returns({ Authorization: "Bearer test-token" });
36
+
37
+ sandbox
38
+ .stub(ConnectionsApi.prototype, "createConnection")
39
+ .callsFake(createConnectionStub);
40
+ sandbox
41
+ .stub(require("../../utils"), "getConfirmation")
42
+ .callsFake(getConfirmationStub);
43
+ });
44
+
45
+ afterEach(() => {
46
+ sandbox.restore();
47
+ });
48
+
49
+ it("should create connection successfully", async () => {
50
+ const mockConnections = [
51
+ {
52
+ name: "test_connection",
53
+ type: "postgres",
54
+ host: "localhost",
55
+ port: 5432,
56
+ },
57
+ ];
58
+ readFileSyncStub.returns(JSON.stringify(mockConnections));
59
+ getConfirmationStub.resolves(true);
60
+ createConnectionStub.resolves({ data: {} });
61
+
62
+ await createConnections(
63
+ "http://test-server",
64
+ "/path/to/connections.json",
65
+ null,
66
+ null,
67
+ false,
68
+ false,
69
+ true,
70
+ );
71
+
72
+ expect(readFileSyncStub.calledWith("/path/to/connections.json", "utf8"))
73
+ .to.be.true;
74
+ expect(createConnectionStub.calledOnce).to.be.true;
75
+ expect(createConnectionStub.firstCall.args[0]).to.equal("test-org");
76
+ expect(createConnectionStub.firstCall.args[1]).to.equal("test-project");
77
+ expect(createConnectionStub.firstCall.args[2]).to.deep.include({
78
+ name: "test_connection",
79
+ });
80
+ expect(
81
+ loggerStub.info.calledWith(
82
+ sinon.match("Connection test_connection created successfully"),
83
+ ),
84
+ ).to.be.true;
85
+ });
86
+
87
+ it("should create multiple connections", async () => {
88
+ const mockConnections = [
89
+ { name: "conn1", type: "postgres" },
90
+ { name: "conn2", type: "mysql" },
91
+ ];
92
+ readFileSyncStub.returns(JSON.stringify(mockConnections));
93
+ getConfirmationStub.resolves(true);
94
+ createConnectionStub.resolves({ data: {} });
95
+
96
+ await createConnections(
97
+ "http://test-server",
98
+ "/path/to/connections.json",
99
+ null,
100
+ null,
101
+ false,
102
+ false,
103
+ true,
104
+ );
105
+
106
+ expect(createConnectionStub.calledTwice).to.be.true;
107
+ });
108
+
109
+ it("should handle includeTables", async () => {
110
+ const mockConnections = [{ name: "test_conn", type: "postgres" }];
111
+ readFileSyncStub.returns(JSON.stringify(mockConnections));
112
+ getConfirmationStub.resolves(true);
113
+ createConnectionStub.resolves({ data: {} });
114
+
115
+ await createConnections(
116
+ "http://test-server",
117
+ "/path/to/connections.json",
118
+ "table1, table2",
119
+ null,
120
+ false,
121
+ false,
122
+ true,
123
+ );
124
+
125
+ expect(createConnectionStub.firstCall.args[2]).to.deep.include({
126
+ includeTables: ["table1", "table2"],
127
+ });
128
+ });
129
+
130
+ it("should handle excludeTables", async () => {
131
+ const mockConnections = [{ name: "test_conn", type: "postgres" }];
132
+ readFileSyncStub.returns(JSON.stringify(mockConnections));
133
+ getConfirmationStub.resolves(true);
134
+ createConnectionStub.resolves({ data: {} });
135
+
136
+ await createConnections(
137
+ "http://test-server",
138
+ "/path/to/connections.json",
139
+ null,
140
+ "table1, table2",
141
+ false,
142
+ false,
143
+ true,
144
+ );
145
+
146
+ expect(createConnectionStub.firstCall.args[2]).to.deep.include({
147
+ excludeTables: ["table1", "table2"],
148
+ });
149
+ });
150
+
151
+ it("should handle skipIndexing", async () => {
152
+ const mockConnections = [{ name: "test_conn", type: "postgres" }];
153
+ readFileSyncStub.returns(JSON.stringify(mockConnections));
154
+ getConfirmationStub.resolves(true);
155
+ createConnectionStub.resolves({ data: {} });
156
+
157
+ await createConnections(
158
+ "http://test-server",
159
+ "/path/to/connections.json",
160
+ null,
161
+ null,
162
+ true,
163
+ false,
164
+ true,
165
+ );
166
+
167
+ expect(createConnectionStub.firstCall.args[2]).to.deep.include({
168
+ excludeAllTables: true,
169
+ });
170
+ });
171
+
172
+ it("should reject includeTables and excludeTables together", async () => {
173
+ await createConnections(
174
+ "http://test-server",
175
+ "/path/to/connections.json",
176
+ "table1",
177
+ "table2",
178
+ false,
179
+ false,
180
+ true,
181
+ );
182
+
183
+ expect(createConnectionStub.called).to.be.false;
184
+ expect(
185
+ loggerStub.error.calledWith(
186
+ sinon.match(
187
+ "includeTables and excludeTables cannot be set at the same time",
188
+ ),
189
+ ),
190
+ ).to.be.true;
191
+ });
192
+
193
+ it("should reject skipIndexing with includeTables", async () => {
194
+ await createConnections(
195
+ "http://test-server",
196
+ "/path/to/connections.json",
197
+ "table1",
198
+ null,
199
+ true,
200
+ false,
201
+ true,
202
+ );
203
+
204
+ expect(createConnectionStub.called).to.be.false;
205
+ expect(
206
+ loggerStub.error.calledWith(
207
+ sinon.match(
208
+ "skipIndexing and includeTables cannot be set at the same time",
209
+ ),
210
+ ),
211
+ ).to.be.true;
212
+ });
213
+
214
+ it("should reject skipIndexing with excludeTables", async () => {
215
+ await createConnections(
216
+ "http://test-server",
217
+ "/path/to/connections.json",
218
+ null,
219
+ "table1",
220
+ true,
221
+ false,
222
+ true,
223
+ );
224
+
225
+ expect(createConnectionStub.called).to.be.false;
226
+ expect(
227
+ loggerStub.error.calledWith(
228
+ sinon.match(
229
+ "skipIndexing and excludeTables cannot be set at the same time",
230
+ ),
231
+ ),
232
+ ).to.be.true;
233
+ });
234
+
235
+ it("should reject invalid connection name", async () => {
236
+ const mockConnections = [
237
+ { name: "123invalid", type: "postgres" },
238
+ { name: "valid_connection", type: "postgres" },
239
+ ];
240
+ readFileSyncStub.returns(JSON.stringify(mockConnections));
241
+ getConfirmationStub.resolves(true);
242
+ createConnectionStub.resolves({ data: {} });
243
+
244
+ await createConnections(
245
+ "http://test-server",
246
+ "/path/to/connections.json",
247
+ null,
248
+ null,
249
+ false,
250
+ false,
251
+ true,
252
+ );
253
+
254
+ expect(
255
+ loggerStub.error.calledWith(
256
+ sinon.match(/Connection name can only contain letters/),
257
+ ),
258
+ ).to.be.true;
259
+ expect(createConnectionStub.calledOnce).to.be.true;
260
+ expect(createConnectionStub.firstCall.args[2].name).to.equal(
261
+ "valid_connection",
262
+ );
263
+ });
264
+
265
+ it("should handle missing config", async () => {
266
+ sandbox.restore();
267
+ sandbox = sinon.createSandbox();
268
+ createConnectionStub = sandbox.stub();
269
+ loggerStub = sandbox.stub(logger);
270
+ getConfirmationStub = sandbox.stub();
271
+ readFileSyncStub = sandbox.stub(fs, "readFileSync");
272
+
273
+ sandbox
274
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
275
+ .returns(false);
276
+ sandbox
277
+ .stub(ConnectionsApi.prototype, "createConnection")
278
+ .callsFake(createConnectionStub);
279
+ sandbox
280
+ .stub(require("../../utils"), "getConfirmation")
281
+ .callsFake(getConfirmationStub);
282
+
283
+ await createConnections(
284
+ "http://test-server",
285
+ "/path/to/connections.json",
286
+ null,
287
+ null,
288
+ false,
289
+ false,
290
+ true,
291
+ );
292
+
293
+ expect(createConnectionStub.called).to.be.false;
294
+ expect(
295
+ loggerStub.error.calledWith(
296
+ sinon.match("Please, make sure that you are logged in"),
297
+ ),
298
+ ).to.be.true;
299
+ });
300
+
301
+ it("should handle missing project", async () => {
302
+ sandbox.restore();
303
+ sandbox = sinon.createSandbox();
304
+ createConnectionStub = sandbox.stub();
305
+ loggerStub = sandbox.stub(logger);
306
+ getConfirmationStub = sandbox.stub();
307
+ readFileSyncStub = sandbox.stub(fs, "readFileSync");
308
+
309
+ sandbox
310
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
311
+ .returns(true);
312
+ sandbox.stub(ClientConfiguration.prototype, "getProject").returns("");
313
+ sandbox
314
+ .stub(ConnectionsApi.prototype, "createConnection")
315
+ .callsFake(createConnectionStub);
316
+ sandbox
317
+ .stub(require("../../utils"), "getConfirmation")
318
+ .callsFake(getConfirmationStub);
319
+
320
+ await createConnections(
321
+ "http://test-server",
322
+ "/path/to/connections.json",
323
+ null,
324
+ null,
325
+ false,
326
+ false,
327
+ true,
328
+ );
329
+
330
+ expect(createConnectionStub.called).to.be.false;
331
+ expect(
332
+ loggerStub.error.calledWith(
333
+ sinon.match("Please, make sure to set a project"),
334
+ ),
335
+ ).to.be.true;
336
+ });
337
+
338
+ it("should request confirmation when autoConfirm is false", async () => {
339
+ const mockConnections = [{ name: "test_conn", type: "postgres" }];
340
+ readFileSyncStub.returns(JSON.stringify(mockConnections));
341
+ getConfirmationStub.resolves(true);
342
+ createConnectionStub.resolves({ data: {} });
343
+
344
+ await createConnections(
345
+ "http://test-server",
346
+ "/path/to/connections.json",
347
+ null,
348
+ null,
349
+ false,
350
+ false,
351
+ false,
352
+ );
353
+
354
+ expect(getConfirmationStub.calledOnce).to.be.true;
355
+ expect(createConnectionStub.calledOnce).to.be.true;
356
+ });
357
+
358
+ it("should cancel when confirmation is denied", async () => {
359
+ const mockConnections = [{ name: "test_conn", type: "postgres" }];
360
+ readFileSyncStub.returns(JSON.stringify(mockConnections));
361
+ getConfirmationStub.resolves(false);
362
+
363
+ await createConnections(
364
+ "http://test-server",
365
+ "/path/to/connections.json",
366
+ null,
367
+ null,
368
+ false,
369
+ false,
370
+ false,
371
+ );
372
+
373
+ expect(getConfirmationStub.calledOnce).to.be.true;
374
+ expect(createConnectionStub.called).to.be.false;
375
+ expect(loggerStub.info.calledWith(sinon.match("Operation cancelled."))).to
376
+ .be.true;
377
+ });
378
+
379
+ it("should handle API errors", async () => {
380
+ const mockConnections = [{ name: "test_conn", type: "postgres" }];
381
+ readFileSyncStub.returns(JSON.stringify(mockConnections));
382
+ getConfirmationStub.resolves(true);
383
+ const mockError = new Error("API Error");
384
+ createConnectionStub.rejects(mockError);
385
+
386
+ await createConnections(
387
+ "http://test-server",
388
+ "/path/to/connections.json",
389
+ null,
390
+ null,
391
+ false,
392
+ true,
393
+ true,
394
+ );
395
+
396
+ expect(createConnectionStub.calledOnce).to.be.true;
397
+ expect(
398
+ loggerStub.error.calledWith(
399
+ sinon.match("Failed to create connection test_conn"),
400
+ ),
401
+ ).to.be.true;
402
+ });
403
+ });
@@ -12,6 +12,7 @@ export const createConnections = async (
12
12
  connectionFileName: string,
13
13
  includeTables: string | null,
14
14
  excludeTables: string | null,
15
+ skipIndexing: boolean,
15
16
  debug: boolean,
16
17
  autoConfirm: boolean,
17
18
  ) => {
@@ -30,7 +31,23 @@ export const createConnections = async (
30
31
  }
31
32
 
32
33
  if (includeTables && excludeTables) {
33
- logger.error("includeTables and excludeTables cannot be set at the same time");
34
+ logger.error(
35
+ "includeTables and excludeTables cannot be set at the same time",
36
+ );
37
+ return;
38
+ }
39
+
40
+ if (skipIndexing && includeTables) {
41
+ logger.error(
42
+ "skipIndexing and includeTables cannot be set at the same time",
43
+ );
44
+ return;
45
+ }
46
+
47
+ if (skipIndexing && excludeTables) {
48
+ logger.error(
49
+ "skipIndexing and excludeTables cannot be set at the same time",
50
+ );
34
51
  return;
35
52
  }
36
53
 
@@ -39,9 +56,10 @@ export const createConnections = async (
39
56
  ) as Connection[];
40
57
 
41
58
  for (const connection of connections) {
42
-
43
59
  if (!/^[a-zA-Z_][a-zA-Z0-9_]+$/.test(connection.name)) {
44
- logger.error(`Connection name can only contain letters, numbers, and underscores for connection and should start with a letter or underscore: ${connection.name}`);
60
+ logger.error(
61
+ `Connection name can only contain letters, numbers, and underscores for connection and should start with a letter or underscore: ${connection.name}`,
62
+ );
45
63
  continue;
46
64
  }
47
65
 
@@ -55,8 +73,12 @@ export const createConnections = async (
55
73
  }
56
74
  }
57
75
  try {
58
- const parsedIncludeTables = includeTables ? includeTables.split(',').map(s => s.trim()) : undefined;
59
- const parsedExcludeTables = excludeTables ? excludeTables.split(',').map(s => s.trim()) : undefined;
76
+ const parsedIncludeTables = includeTables
77
+ ? includeTables.split(",").map((s) => s.trim())
78
+ : undefined;
79
+ const parsedExcludeTables = excludeTables
80
+ ? excludeTables.split(",").map((s) => s.trim())
81
+ : undefined;
60
82
 
61
83
  if (parsedIncludeTables) {
62
84
  connection.includeTables = parsedIncludeTables;
@@ -64,6 +86,9 @@ export const createConnections = async (
64
86
  if (parsedExcludeTables) {
65
87
  connection.excludeTables = parsedExcludeTables;
66
88
  }
89
+ if (skipIndexing) {
90
+ connection.excludeAllTables = true;
91
+ }
67
92
 
68
93
  await connectionsApi.createConnection(
69
94
  organizationName,
@@ -0,0 +1,189 @@
1
+ import { expect } from "chai";
2
+ import sinon from "sinon";
3
+ import { ConnectionsApi } from "../../client/api";
4
+ import { ClientConfiguration } from "../../clientconfiguration";
5
+ import { logger } from "../../logger";
6
+ import { getConfirmation } from "../../utils";
7
+ import { deleteConnection } from "./deleteconnection";
8
+
9
+ describe("delete-connection", () => {
10
+ let sandbox: sinon.SinonSandbox;
11
+ let deleteConnectionStub: sinon.SinonStub;
12
+ let loggerStub: sinon.SinonStubbedInstance<typeof logger>;
13
+ let getConfirmationStub: sinon.SinonStub;
14
+
15
+ beforeEach(() => {
16
+ sandbox = sinon.createSandbox();
17
+ deleteConnectionStub = sandbox.stub();
18
+ loggerStub = sandbox.stub(logger);
19
+ getConfirmationStub = sandbox.stub();
20
+
21
+ sandbox
22
+ .stub(ClientConfiguration.prototype, "getOrganization")
23
+ .returns("test-org");
24
+ sandbox
25
+ .stub(ClientConfiguration.prototype, "getProject")
26
+ .returns("test-project");
27
+ sandbox
28
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
29
+ .returns(true);
30
+ sandbox
31
+ .stub(ClientConfiguration.prototype, "getHeaders")
32
+ .returns({ Authorization: "Bearer test-token" });
33
+
34
+ sandbox
35
+ .stub(ConnectionsApi.prototype, "deleteConnection")
36
+ .callsFake(deleteConnectionStub);
37
+ sandbox
38
+ .stub(require("../../utils"), "getConfirmation")
39
+ .callsFake(getConfirmationStub);
40
+ });
41
+
42
+ afterEach(() => {
43
+ sandbox.restore();
44
+ });
45
+
46
+ it("should delete connection successfully", async () => {
47
+ deleteConnectionStub.resolves({ status: 200 });
48
+ getConfirmationStub.resolves(true);
49
+
50
+ await deleteConnection(
51
+ "http://test-server",
52
+ "test-connection",
53
+ false,
54
+ true,
55
+ );
56
+
57
+ expect(deleteConnectionStub.calledOnce).to.be.true;
58
+ expect(deleteConnectionStub.firstCall.args[0]).to.equal("test-org");
59
+ expect(deleteConnectionStub.firstCall.args[1]).to.equal("test-project");
60
+ expect(deleteConnectionStub.firstCall.args[2]).to.equal(
61
+ "test-connection",
62
+ );
63
+ expect(deleteConnectionStub.firstCall.args[3]).to.deep.include({
64
+ baseURL: "http://test-server",
65
+ headers: { Authorization: "Bearer test-token" },
66
+ });
67
+ expect(
68
+ loggerStub.info.calledWith(
69
+ sinon.match("Connection deleted successfully"),
70
+ ),
71
+ ).to.be.true;
72
+ });
73
+
74
+ it("should handle missing config", async () => {
75
+ sandbox.restore();
76
+ sandbox = sinon.createSandbox();
77
+ deleteConnectionStub = sandbox.stub();
78
+ loggerStub = sandbox.stub(logger);
79
+ getConfirmationStub = sandbox.stub();
80
+
81
+ sandbox
82
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
83
+ .returns(false);
84
+ sandbox
85
+ .stub(ConnectionsApi.prototype, "deleteConnection")
86
+ .callsFake(deleteConnectionStub);
87
+ sandbox
88
+ .stub(require("../../utils"), "getConfirmation")
89
+ .callsFake(getConfirmationStub);
90
+
91
+ await deleteConnection(
92
+ "http://test-server",
93
+ "test-connection",
94
+ false,
95
+ true,
96
+ );
97
+
98
+ expect(deleteConnectionStub.called).to.be.false;
99
+ expect(
100
+ loggerStub.error.calledWith(
101
+ sinon.match("Please, make sure that you are logged in"),
102
+ ),
103
+ ).to.be.true;
104
+ });
105
+
106
+ it("should handle missing project", async () => {
107
+ sandbox.restore();
108
+ sandbox = sinon.createSandbox();
109
+ deleteConnectionStub = sandbox.stub();
110
+ loggerStub = sandbox.stub(logger);
111
+ getConfirmationStub = sandbox.stub();
112
+
113
+ sandbox
114
+ .stub(ClientConfiguration.prototype, "doesConfigExists")
115
+ .returns(true);
116
+ sandbox.stub(ClientConfiguration.prototype, "getProject").returns("");
117
+ sandbox
118
+ .stub(ConnectionsApi.prototype, "deleteConnection")
119
+ .callsFake(deleteConnectionStub);
120
+ sandbox
121
+ .stub(require("../../utils"), "getConfirmation")
122
+ .callsFake(getConfirmationStub);
123
+
124
+ await deleteConnection(
125
+ "http://test-server",
126
+ "test-connection",
127
+ false,
128
+ true,
129
+ );
130
+
131
+ expect(deleteConnectionStub.called).to.be.false;
132
+ expect(
133
+ loggerStub.error.calledWith(
134
+ sinon.match("Please, make sure to set a project"),
135
+ ),
136
+ ).to.be.true;
137
+ });
138
+
139
+ it("should request confirmation when autoConfirm is false", async () => {
140
+ deleteConnectionStub.resolves({ status: 200 });
141
+ getConfirmationStub.resolves(true);
142
+
143
+ await deleteConnection(
144
+ "http://test-server",
145
+ "test-connection",
146
+ false,
147
+ false,
148
+ );
149
+
150
+ expect(getConfirmationStub.calledOnce).to.be.true;
151
+ expect(deleteConnectionStub.calledOnce).to.be.true;
152
+ });
153
+
154
+ it("should cancel when confirmation is denied", async () => {
155
+ getConfirmationStub.resolves(false);
156
+
157
+ await deleteConnection(
158
+ "http://test-server",
159
+ "test-connection",
160
+ false,
161
+ false,
162
+ );
163
+
164
+ expect(getConfirmationStub.calledOnce).to.be.true;
165
+ expect(deleteConnectionStub.called).to.be.false;
166
+ expect(loggerStub.info.calledWith(sinon.match("Operation cancelled."))).to
167
+ .be.true;
168
+ });
169
+
170
+ it("should handle API errors", async () => {
171
+ const mockError = new Error("API Error");
172
+ deleteConnectionStub.rejects(mockError);
173
+ getConfirmationStub.resolves(true);
174
+
175
+ await deleteConnection(
176
+ "http://test-server",
177
+ "test-connection",
178
+ true,
179
+ true,
180
+ );
181
+
182
+ expect(deleteConnectionStub.calledOnce).to.be.true;
183
+ expect(
184
+ loggerStub.error.calledWith(
185
+ sinon.match("Failed to delete connection"),
186
+ ),
187
+ ).to.be.true;
188
+ });
189
+ });