Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tinybirdco/sdk",
"version": "0.0.62",
"version": "0.0.63",
"description": "TypeScript SDK for Tinybird Forward - define datasources and pipes as TypeScript",
"type": "module",
"main": "./dist/index.js",
Expand Down
21 changes: 18 additions & 3 deletions src/api/branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,26 @@ async function pollJob(
* @param name - Branch name to create
* @returns The created branch with token
*/
export interface CreateBranchOptions {
/** Copy the last partition of production data into the branch */
lastPartition?: boolean;
}

export async function createBranch(
config: BranchApiConfig,
name: string
name: string,
options?: CreateBranchOptions
): Promise<TinybirdBranch> {
const url = new URL("/v1/environments", config.baseUrl);
url.searchParams.set("name", name);
if (options?.lastPartition) {
url.searchParams.set("last_partition", "1");
}

const debug = !!process.env.TINYBIRD_DEBUG;
if (debug) {
console.log(`[debug] POST ${url.toString()}`);
}

const response = await tinybirdFetch(url.toString(), {
method: "POST",
Expand Down Expand Up @@ -325,7 +339,8 @@ export async function branchExists(
*/
export async function getOrCreateBranch(
config: BranchApiConfig,
name: string
name: string,
options?: CreateBranchOptions
): Promise<GetOrCreateBranchResult> {
// First try to get the existing branch
try {
Expand All @@ -334,7 +349,7 @@ export async function getOrCreateBranch(
} catch (error) {
// If it's a 404, create the branch
if (error instanceof BranchApiError && error.status === 404) {
const branch = await createBranch(config, name);
const branch = await createBranch(config, name, options);
return { ...branch, wasCreated: true };
}
throw error;
Expand Down
5 changes: 4 additions & 1 deletion src/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface BuildCommandOptions {
tokenOverride?: string;
/** Override the devMode from config */
devModeOverride?: DevMode;
/** Copy the last partition of production data when creating a branch */
lastPartition?: boolean;
}

/**
Expand Down Expand Up @@ -225,7 +227,8 @@ export async function runBuild(options: BuildCommandOptions = {}): Promise<Build
baseUrl: config.baseUrl,
token: config.token,
},
config.tinybirdBranch!
config.tinybirdBranch!,
{ lastPartition: options.lastPartition }
);

if (!tinybirdBranch.token) {
Expand Down
5 changes: 4 additions & 1 deletion src/cli/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export interface DevCommandOptions {
onSchemaValidation?: (result: SchemaValidationResult) => void;
/** Override the devMode from config */
devModeOverride?: DevMode;
/** Copy the last partition of production data when creating a branch */
lastPartition?: boolean;
}

/**
Expand Down Expand Up @@ -241,7 +243,8 @@ export async function runDev(
baseUrl: config.baseUrl,
token: config.token,
},
branchName
branchName,
{ lastPartition: options.lastPartition }
);

if (!tinybirdBranch.token) {
Expand Down
4 changes: 4 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ function createCli(): Command {
.option("--debug", "Show debug output including API requests/responses")
.option("--local", "Use local Tinybird container")
.option("--branch", "Use Tinybird cloud with branches")
.option("--last-partition", "Copy the last partition of production data when creating a branch")
.action(async (options) => {
if (options.debug) {
process.env.TINYBIRD_DEBUG = "1";
Expand All @@ -286,6 +287,7 @@ function createCli(): Command {
const result = await runBuild({
dryRun: options.dryRun,
devModeOverride,
lastPartition: options.lastPartition,
});

const { build, deploy, branchInfo } = result;
Expand Down Expand Up @@ -677,6 +679,7 @@ function createCli(): Command {
.description("Watch for changes and sync with Tinybird")
.option("--local", "Use local Tinybird container")
.option("--branch", "Use Tinybird cloud with branches")
.option("--last-partition", "Copy the last partition of production data when creating a branch")
.action(async (options) => {
// Determine devMode override
let devModeOverride: DevMode | undefined;
Expand All @@ -689,6 +692,7 @@ function createCli(): Command {
try {
const controller = await runDev({
devModeOverride,
lastPartition: options.lastPartition,
onLoginComplete: (info) => {
console.log("\nAuthentication successful!");
if (info.workspaceName) {
Expand Down
Loading