@tinybirdco/sdk 0.0.78 → 0.0.79

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 (63) hide show
  1. package/dist/api/branches.d.ts +4 -3
  2. package/dist/api/branches.d.ts.map +1 -1
  3. package/dist/api/branches.js +4 -4
  4. package/dist/api/branches.js.map +1 -1
  5. package/dist/api/branches.test.js +34 -1
  6. package/dist/api/branches.test.js.map +1 -1
  7. package/dist/cli/commands/build.d.ts.map +1 -1
  8. package/dist/cli/commands/build.js +7 -1
  9. package/dist/cli/commands/build.js.map +1 -1
  10. package/dist/cli/commands/build.test.js +159 -0
  11. package/dist/cli/commands/build.test.js.map +1 -1
  12. package/dist/cli/commands/clear.d.ts.map +1 -1
  13. package/dist/cli/commands/clear.js +4 -1
  14. package/dist/cli/commands/clear.js.map +1 -1
  15. package/dist/cli/commands/deploy.test.js +1 -0
  16. package/dist/cli/commands/deploy.test.js.map +1 -1
  17. package/dist/cli/commands/dev.d.ts.map +1 -1
  18. package/dist/cli/commands/dev.js +7 -1
  19. package/dist/cli/commands/dev.js.map +1 -1
  20. package/dist/cli/commands/generate.test.js +3 -0
  21. package/dist/cli/commands/generate.test.js.map +1 -1
  22. package/dist/cli/commands/preview.d.ts.map +1 -1
  23. package/dist/cli/commands/preview.js +4 -1
  24. package/dist/cli/commands/preview.js.map +1 -1
  25. package/dist/cli/commands/preview.test.js +116 -2
  26. package/dist/cli/commands/preview.test.js.map +1 -1
  27. package/dist/cli/config-types.d.ts +4 -0
  28. package/dist/cli/config-types.d.ts.map +1 -1
  29. package/dist/cli/config-types.js +1 -1
  30. package/dist/cli/config-types.js.map +1 -1
  31. package/dist/cli/config.d.ts +4 -2
  32. package/dist/cli/config.d.ts.map +1 -1
  33. package/dist/cli/config.js +27 -0
  34. package/dist/cli/config.js.map +1 -1
  35. package/dist/cli/config.test.js +79 -0
  36. package/dist/cli/config.test.js.map +1 -1
  37. package/dist/cli/index.js +2 -2
  38. package/dist/cli/index.js.map +1 -1
  39. package/dist/client/base.d.ts.map +1 -1
  40. package/dist/client/base.js +4 -1
  41. package/dist/client/base.js.map +1 -1
  42. package/dist/client/base.test.js +2 -1
  43. package/dist/client/base.test.js.map +1 -1
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/package.json +1 -1
  47. package/src/api/branches.test.ts +38 -1
  48. package/src/api/branches.ts +8 -6
  49. package/src/cli/commands/build.test.ts +176 -0
  50. package/src/cli/commands/build.ts +9 -2
  51. package/src/cli/commands/clear.ts +8 -1
  52. package/src/cli/commands/deploy.test.ts +1 -0
  53. package/src/cli/commands/dev.ts +9 -1
  54. package/src/cli/commands/generate.test.ts +3 -0
  55. package/src/cli/commands/preview.test.ts +133 -2
  56. package/src/cli/commands/preview.ts +6 -2
  57. package/src/cli/config-types.ts +4 -0
  58. package/src/cli/config.test.ts +123 -0
  59. package/src/cli/config.ts +41 -3
  60. package/src/cli/index.ts +8 -2
  61. package/src/client/base.test.ts +3 -1
  62. package/src/client/base.ts +7 -1
  63. package/src/index.ts +1 -1
package/src/cli/config.ts CHANGED
@@ -7,9 +7,17 @@ import * as path from "path";
7
7
  import { config as loadDotenv } from "dotenv";
8
8
  import { getCurrentGitBranch, isMainBranch, getTinybirdBranchName } from "./git.js";
9
9
 
10
- // Re-export types from config-types.ts (separate file to avoid bundling esbuild)
11
- export type { DevMode, TinybirdConfig } from "./config-types.js";
12
- import type { DevMode, TinybirdConfig } from "./config-types.js";
10
+ // Re-export config types/constants from config-types.ts (separate file to avoid bundling esbuild)
11
+ export {
12
+ BRANCH_DATA_MODE_VALUES,
13
+ type BranchDataMode,
14
+ type DevMode,
15
+ type TinybirdConfig,
16
+ } from "./config-types.js";
17
+ import { BRANCH_DATA_MODE_VALUES } from "./config-types.js";
18
+ import type { BranchDataMode, DevMode, TinybirdConfig } from "./config-types.js";
19
+
20
+ const DEFAULT_BRANCH_DATA_MODE: BranchDataMode = "last_partition";
13
21
 
14
22
  /**
15
23
  * Resolved configuration with all values expanded
@@ -33,6 +41,8 @@ export interface ResolvedConfig {
33
41
  isMainBranch: boolean;
34
42
  /** Development mode: "branch" or "local" */
35
43
  devMode: DevMode;
44
+ /** Branch data mode configured in tinybird.config.json */
45
+ branchDataMode?: BranchDataMode | null;
36
46
  }
37
47
 
38
48
  /**
@@ -196,6 +206,24 @@ export function findConfigFile(startDir: string): ConfigFileResult | null {
196
206
  // Import the universal config loader
197
207
  import { loadConfigFile } from "./config-loader.js";
198
208
 
209
+ function resolveBranchDataMode(raw: Record<string, unknown>): { mode: BranchDataMode | null; explicit: boolean } {
210
+ if (raw["branch_data_on_create"] !== undefined) {
211
+ throw new Error("`branch_data_on_create` has been renamed to `branch_data_mode`.");
212
+ }
213
+
214
+ const value = raw["branch_data_mode"];
215
+ if (value === undefined || value === null) return { mode: DEFAULT_BRANCH_DATA_MODE, explicit: false };
216
+ if (typeof value !== "string") throw new Error("branch_data_mode must be a string.");
217
+ const mode = value.trim().toLowerCase();
218
+ if (!mode) return { mode: DEFAULT_BRANCH_DATA_MODE, explicit: false };
219
+ if (!BRANCH_DATA_MODE_VALUES.includes(mode as BranchDataMode)) {
220
+ throw new Error(
221
+ `Invalid branch_data_mode '${value}'. Allowed values are: ${BRANCH_DATA_MODE_VALUES.join(", ")}.`
222
+ );
223
+ }
224
+ return { mode: mode as BranchDataMode, explicit: true };
225
+ }
226
+
199
227
  /**
200
228
  * Resolve a TinybirdConfig to a ResolvedConfig
201
229
  */
@@ -255,6 +283,15 @@ function resolveConfig(config: TinybirdConfig, configPath: string): ResolvedConf
255
283
 
256
284
  // Resolve devMode (default to "branch")
257
285
  const devMode: DevMode = config.devMode ?? "branch";
286
+ const { mode: branchDataMode, explicit: branchDataModeExplicit } = resolveBranchDataMode(
287
+ config as unknown as Record<string, unknown>
288
+ );
289
+ if (branchDataModeExplicit && branchDataMode && devMode === "local") {
290
+ console.warn(
291
+ "branch_data_mode is set in tinybird.config.json but dev_mode='local'. " +
292
+ "Branch data settings only apply to cloud branches."
293
+ );
294
+ }
258
295
 
259
296
  return {
260
297
  include,
@@ -266,6 +303,7 @@ function resolveConfig(config: TinybirdConfig, configPath: string): ResolvedConf
266
303
  tinybirdBranch,
267
304
  isMainBranch: isMainBranch(),
268
305
  devMode,
306
+ branchDataMode,
269
307
  };
270
308
  }
271
309
 
package/src/cli/index.ts CHANGED
@@ -270,7 +270,10 @@ function createCli(): Command {
270
270
  .option("--debug", "Show debug output including API requests/responses")
271
271
  .option("--local", "Use local Tinybird container")
272
272
  .option("--branch", "Use Tinybird cloud with branches")
273
- .option("--last-partition", "Copy the last partition of production data when creating a branch")
273
+ .option(
274
+ "--last-partition",
275
+ '[DEPRECATED] Use `branch_data_mode: "last_partition"` in tinybird.config.json. Copy the last partition of production data when creating a cloud branch.'
276
+ )
274
277
  .action(async (options) => {
275
278
  if (options.debug) {
276
279
  process.env.TINYBIRD_DEBUG = "1";
@@ -679,7 +682,10 @@ function createCli(): Command {
679
682
  .description("Watch for changes and sync with Tinybird")
680
683
  .option("--local", "Use local Tinybird container")
681
684
  .option("--branch", "Use Tinybird cloud with branches")
682
- .option("--last-partition", "Copy the last partition of production data when creating a branch")
685
+ .option(
686
+ "--last-partition",
687
+ '[DEPRECATED] Use `branch_data_mode: "last_partition"` in tinybird.config.json. Copy the last partition of production data when creating a cloud branch.'
688
+ )
683
689
  .action(async (options) => {
684
690
  // Determine devMode override
685
691
  let devModeOverride: DevMode | undefined;
@@ -167,6 +167,7 @@ describe("TinybirdClient", () => {
167
167
  tinybirdBranch: "feature_add_fetch",
168
168
  isMainBranch: false,
169
169
  devMode: "branch",
170
+ branchDataMode: null,
170
171
  });
171
172
  mockedGetOrCreateBranch.mockResolvedValue({
172
173
  id: "branch-123",
@@ -192,7 +193,8 @@ describe("TinybirdClient", () => {
192
193
  token: "workspace-token",
193
194
  fetch: customFetch,
194
195
  },
195
- "feature_add_fetch"
196
+ "feature_add_fetch",
197
+ undefined
196
198
  );
197
199
  expect(context.token).toBe("branch-token");
198
200
  expect(context.isBranchToken).toBe(true);
@@ -19,6 +19,7 @@ import type {
19
19
  } from "./types.js";
20
20
  import { TinybirdError } from "./types.js";
21
21
  import { TinybirdApi, TinybirdApiError } from "../api/api.js";
22
+ import type { CreateBranchOptions } from "../api/branches.js";
22
23
  import { TokensNamespace } from "./tokens.js";
23
24
 
24
25
  /**
@@ -340,6 +341,10 @@ export class TinybirdClient {
340
341
  }
341
342
 
342
343
  const branchName = config.tinybirdBranch;
344
+ const branchOptions: CreateBranchOptions | undefined =
345
+ config.devMode !== "local" && config.branchDataMode === "last_partition"
346
+ ? { branch_data_mode: "last_partition" }
347
+ : undefined;
343
348
 
344
349
  // Get or create branch (always fetch fresh to avoid stale cache issues)
345
350
  const branch = await getOrCreateBranch(
@@ -348,7 +353,8 @@ export class TinybirdClient {
348
353
  token: this.config.token,
349
354
  fetch: this.config.fetch,
350
355
  },
351
- branchName
356
+ branchName,
357
+ branchOptions
352
358
  );
353
359
 
354
360
  if (!branch.token) {
package/src/index.ts CHANGED
@@ -317,4 +317,4 @@ export type {
317
317
 
318
318
  // ============ Config Types ============
319
319
  // Import from config-types.ts to avoid bundling esbuild in client code
320
- export type { TinybirdConfig, DevMode } from "./cli/config-types.js";
320
+ export type { TinybirdConfig, DevMode, BranchDataMode } from "./cli/config-types.js";