@tinybirdco/sdk 0.0.51 → 0.0.53

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.
@@ -0,0 +1,82 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { runDeploy } from "./deploy.js";
3
+
4
+ vi.mock("../config.js", () => ({
5
+ loadConfigAsync: vi.fn(),
6
+ }));
7
+
8
+ vi.mock("../../generator/index.js", () => ({
9
+ buildFromInclude: vi.fn(),
10
+ }));
11
+
12
+ vi.mock("../../api/deploy.js", () => ({
13
+ deployToMain: vi.fn(),
14
+ }));
15
+
16
+ describe("Deploy command", () => {
17
+ beforeEach(() => {
18
+ vi.clearAllMocks();
19
+ });
20
+
21
+ afterEach(() => {
22
+ vi.resetAllMocks();
23
+ });
24
+
25
+ it("passes allowDestructiveOperations to deployToMain", async () => {
26
+ const { loadConfigAsync } = await import("../config.js");
27
+ const { buildFromInclude } = await import("../../generator/index.js");
28
+ const { deployToMain } = await import("../../api/deploy.js");
29
+
30
+ vi.mocked(loadConfigAsync).mockResolvedValue({
31
+ include: ["tinybird/*.ts"],
32
+ token: "p.test-token",
33
+ baseUrl: "https://api.tinybird.co",
34
+ configPath: "/test/tinybird.config.json",
35
+ cwd: "/test",
36
+ gitBranch: "feature-pro-610",
37
+ tinybirdBranch: "feature_pro_610",
38
+ isMainBranch: false,
39
+ devMode: "branch",
40
+ });
41
+
42
+ vi.mocked(buildFromInclude).mockResolvedValue({
43
+ resources: {
44
+ datasources: [],
45
+ pipes: [],
46
+ connections: [],
47
+ },
48
+ entities: {
49
+ datasources: {},
50
+ pipes: {},
51
+ connections: {},
52
+ rawDatasources: [],
53
+ rawPipes: [],
54
+ sourceFiles: [],
55
+ },
56
+ stats: {
57
+ datasourceCount: 0,
58
+ pipeCount: 0,
59
+ connectionCount: 0,
60
+ },
61
+ });
62
+
63
+ vi.mocked(deployToMain).mockResolvedValue({
64
+ success: true,
65
+ result: "success",
66
+ datasourceCount: 0,
67
+ pipeCount: 0,
68
+ connectionCount: 0,
69
+ });
70
+
71
+ const result = await runDeploy({ allowDestructiveOperations: true });
72
+
73
+ expect(result.success).toBe(true);
74
+ expect(deployToMain).toHaveBeenCalledWith(
75
+ expect.anything(),
76
+ expect.anything(),
77
+ expect.objectContaining({
78
+ allowDestructiveOperations: true,
79
+ })
80
+ );
81
+ });
82
+ });
@@ -17,6 +17,8 @@ export interface DeployCommandOptions {
17
17
  dryRun?: boolean;
18
18
  /** Validate deploy with Tinybird API without applying */
19
19
  check?: boolean;
20
+ /** Allow deleting existing resources in main workspace deploys */
21
+ allowDestructiveOperations?: boolean;
20
22
  /** Callbacks for deploy progress */
21
23
  callbacks?: DeployCallbacks;
22
24
  }
@@ -103,6 +105,7 @@ export async function runDeploy(options: DeployCommandOptions = {}): Promise<Dep
103
105
  buildResult.resources,
104
106
  {
105
107
  check: options.check,
108
+ allowDestructiveOperations: options.allowDestructiveOperations,
106
109
  callbacks: options.callbacks,
107
110
  }
108
111
  );
package/src/cli/index.ts CHANGED
@@ -432,6 +432,10 @@ function createCli(): Command {
432
432
  .description("Deploy resources to main Tinybird workspace (production)")
433
433
  .option("--dry-run", "Generate without pushing to API")
434
434
  .option("--check", "Validate deploy with Tinybird API without applying")
435
+ .option(
436
+ "--allow-destructive-operations",
437
+ "Allow deploys that delete existing datasources, pipes, or connections"
438
+ )
435
439
  .option("--debug", "Show debug output including API requests/responses")
436
440
  .action(async (options) => {
437
441
  if (options.debug) {
@@ -443,6 +447,7 @@ function createCli(): Command {
443
447
  const result = await runDeploy({
444
448
  dryRun: options.dryRun,
445
449
  check: options.check,
450
+ allowDestructiveOperations: options.allowDestructiveOperations,
446
451
  callbacks: {
447
452
  onChanges: (deployChanges) => {
448
453
  // Show changes table immediately after deployment is created