@tinybirdco/sdk 0.0.81 → 0.0.83
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.
- package/README.md +1 -0
- package/dist/api/api.d.ts.map +1 -1
- package/dist/api/api.js +17 -10
- package/dist/api/api.js.map +1 -1
- package/dist/api/api.test.js +51 -0
- package/dist/api/api.test.js.map +1 -1
- package/dist/api/branches.test.js +28 -0
- package/dist/api/branches.test.js.map +1 -1
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +2 -2
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/clear.js +2 -2
- package/dist/cli/commands/clear.js.map +1 -1
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +2 -2
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/preview.js +2 -2
- package/dist/cli/commands/preview.js.map +1 -1
- package/dist/cli/commands/preview.test.js +39 -0
- package/dist/cli/commands/preview.test.js.map +1 -1
- package/dist/cli/config-types.d.ts +4 -1
- package/dist/cli/config-types.d.ts.map +1 -1
- package/dist/cli/config.d.ts +1 -1
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +2 -3
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/config.test.js +13 -4
- package/dist/cli/config.test.js.map +1 -1
- package/dist/client/base.js +2 -2
- package/dist/client/base.js.map +1 -1
- package/package.json +1 -1
- package/src/api/api.test.ts +63 -0
- package/src/api/api.ts +22 -15
- package/src/api/branches.test.ts +32 -0
- package/src/cli/commands/build.ts +3 -4
- package/src/cli/commands/clear.ts +2 -2
- package/src/cli/commands/dev.ts +3 -4
- package/src/cli/commands/preview.test.ts +46 -0
- package/src/cli/commands/preview.ts +2 -2
- package/src/cli/config-types.ts +4 -1
- package/src/cli/config.test.ts +20 -4
- package/src/cli/config.ts +3 -4
- package/src/client/base.ts +2 -2
package/src/api/branches.test.ts
CHANGED
|
@@ -223,6 +223,38 @@ describe("Branch API client", () => {
|
|
|
223
223
|
expect(createParsed.searchParams.get("data")).toBe("last_partition");
|
|
224
224
|
});
|
|
225
225
|
|
|
226
|
+
it("omits the data param when no branch_data_mode is given", async () => {
|
|
227
|
+
const mockBranch = {
|
|
228
|
+
id: "branch-123",
|
|
229
|
+
name: "my-feature",
|
|
230
|
+
token: "p.branch-token",
|
|
231
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
mockFetch.mockResolvedValueOnce({
|
|
235
|
+
ok: true,
|
|
236
|
+
json: () => Promise.resolve({
|
|
237
|
+
job: { id: "job-123", status: "waiting" },
|
|
238
|
+
workspace: { id: "ws-123" },
|
|
239
|
+
}),
|
|
240
|
+
});
|
|
241
|
+
mockFetch.mockResolvedValueOnce({
|
|
242
|
+
ok: true,
|
|
243
|
+
json: () => Promise.resolve({ id: "job-123", status: "done" }),
|
|
244
|
+
});
|
|
245
|
+
mockFetch.mockResolvedValueOnce({
|
|
246
|
+
ok: true,
|
|
247
|
+
json: () => Promise.resolve(mockBranch),
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
await createBranch(config, "my-feature");
|
|
251
|
+
|
|
252
|
+
const [createUrl] = mockFetch.mock.calls[0];
|
|
253
|
+
const createParsed = expectFromParam(createUrl);
|
|
254
|
+
expect(createParsed.searchParams.get("name")).toBe("my-feature");
|
|
255
|
+
expect(createParsed.searchParams.get("data")).toBeNull();
|
|
256
|
+
});
|
|
257
|
+
|
|
226
258
|
it("uses custom fetch when provided", async () => {
|
|
227
259
|
const customFetch = vi
|
|
228
260
|
.fn()
|
|
@@ -225,10 +225,9 @@ export async function runBuild(options: BuildCommandOptions = {}): Promise<Build
|
|
|
225
225
|
console.log(`[debug] Getting/creating Tinybird branch: ${config.tinybirdBranch}`);
|
|
226
226
|
}
|
|
227
227
|
try {
|
|
228
|
-
const branchDataMode: BranchDataMode | undefined =
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
: undefined;
|
|
228
|
+
const branchDataMode: BranchDataMode | undefined = options.lastPartition
|
|
229
|
+
? "last_partition"
|
|
230
|
+
: config.branchDataMode ?? undefined;
|
|
232
231
|
const branchOptions = branchDataMode
|
|
233
232
|
? { branch_data_mode: branchDataMode }
|
|
234
233
|
: undefined;
|
|
@@ -149,8 +149,8 @@ async function clearCloudBranch(config: ResolvedConfig): Promise<ClearResult> {
|
|
|
149
149
|
|
|
150
150
|
// Clear the branch (delete and recreate)
|
|
151
151
|
const branchOptions: CreateBranchOptions | undefined =
|
|
152
|
-
config.devMode !== "local" && config.branchDataMode
|
|
153
|
-
? { branch_data_mode:
|
|
152
|
+
config.devMode !== "local" && config.branchDataMode
|
|
153
|
+
? { branch_data_mode: config.branchDataMode }
|
|
154
154
|
: undefined;
|
|
155
155
|
|
|
156
156
|
const newBranch = await clearBranch(
|
package/src/cli/commands/dev.ts
CHANGED
|
@@ -240,10 +240,9 @@ export async function runDev(
|
|
|
240
240
|
// Use tinybirdBranch (sanitized name) for Tinybird API, gitBranch for display
|
|
241
241
|
if (config.tinybirdBranch) {
|
|
242
242
|
const branchName = config.tinybirdBranch; // Sanitized name for Tinybird
|
|
243
|
-
const branchDataMode: BranchDataMode | undefined =
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
: undefined;
|
|
243
|
+
const branchDataMode: BranchDataMode | undefined = options.lastPartition
|
|
244
|
+
? "last_partition"
|
|
245
|
+
: config.branchDataMode ?? undefined;
|
|
247
246
|
const branchOptions = branchDataMode
|
|
248
247
|
? { branch_data_mode: branchDataMode }
|
|
249
248
|
: undefined;
|
|
@@ -120,6 +120,52 @@ describe("Preview command", () => {
|
|
|
120
120
|
);
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
+
it("creates cloud preview branch without data when branch_data_mode is not set", async () => {
|
|
124
|
+
const { loadConfigAsync } = await import("../config.js");
|
|
125
|
+
const { buildFromInclude } = await import("../../generator/index.js");
|
|
126
|
+
const { getBranch, createBranch } = await import("../../api/branches.js");
|
|
127
|
+
const { deployToMain } = await import("../../api/deploy.js");
|
|
128
|
+
|
|
129
|
+
vi.mocked(loadConfigAsync).mockResolvedValue({
|
|
130
|
+
include: ["test.ts"],
|
|
131
|
+
token: "p.test-token",
|
|
132
|
+
baseUrl: "https://api.tinybird.co",
|
|
133
|
+
configPath: "/test/tinybird.config.json",
|
|
134
|
+
devMode: "branch",
|
|
135
|
+
cwd: "/test",
|
|
136
|
+
gitBranch: "feature-test",
|
|
137
|
+
tinybirdBranch: "feature_test",
|
|
138
|
+
isMainBranch: false,
|
|
139
|
+
branchDataMode: null,
|
|
140
|
+
});
|
|
141
|
+
vi.mocked(buildFromInclude).mockResolvedValue({
|
|
142
|
+
resources: { datasources: [], pipes: [], connections: [] },
|
|
143
|
+
entities: { datasources: {}, pipes: {}, connections: {}, rawDatasources: [], rawPipes: [], sourceFiles: [] },
|
|
144
|
+
stats: { datasourceCount: 0, pipeCount: 0, connectionCount: 0 },
|
|
145
|
+
});
|
|
146
|
+
vi.mocked(getBranch).mockRejectedValue(new Error("not found"));
|
|
147
|
+
vi.mocked(createBranch).mockResolvedValue({
|
|
148
|
+
id: "b1",
|
|
149
|
+
name: "tmp_ci_feature_test",
|
|
150
|
+
token: "p.branch",
|
|
151
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
152
|
+
});
|
|
153
|
+
vi.mocked(deployToMain).mockResolvedValue({
|
|
154
|
+
success: true,
|
|
155
|
+
result: "success",
|
|
156
|
+
datasourceCount: 0,
|
|
157
|
+
pipeCount: 0,
|
|
158
|
+
connectionCount: 0,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
await runPreview();
|
|
162
|
+
expect(createBranch).toHaveBeenCalledWith(
|
|
163
|
+
expect.any(Object),
|
|
164
|
+
"tmp_ci_feature_test",
|
|
165
|
+
undefined
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
|
|
123
169
|
it("ignores config branch_data_mode in local mode", async () => {
|
|
124
170
|
const { loadConfigAsync } = await import("../config.js");
|
|
125
171
|
const { buildFromInclude } = await import("../../generator/index.js");
|
|
@@ -227,8 +227,8 @@ export async function runPreview(options: PreviewCommandOptions = {}): Promise<P
|
|
|
227
227
|
try {
|
|
228
228
|
const apiConfig = { baseUrl: config.baseUrl, token: config.token };
|
|
229
229
|
const branchOptions: CreateBranchOptions | undefined =
|
|
230
|
-
config.branchDataMode
|
|
231
|
-
? { branch_data_mode:
|
|
230
|
+
config.branchDataMode
|
|
231
|
+
? { branch_data_mode: config.branchDataMode }
|
|
232
232
|
: undefined;
|
|
233
233
|
|
|
234
234
|
// Check if branch already exists and delete it for a fresh start
|
package/src/cli/config-types.ts
CHANGED
|
@@ -28,6 +28,9 @@ export interface TinybirdConfig {
|
|
|
28
28
|
baseUrl?: string;
|
|
29
29
|
/** Development mode: "branch" (default) or "local" */
|
|
30
30
|
devMode?: DevMode;
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Branch data mode applied on cloud branch creation (shared snake_case key,
|
|
33
|
+
* also read by the tb CLI). Omit to create branches without data (default).
|
|
34
|
+
*/
|
|
32
35
|
branch_data_mode?: BranchDataMode;
|
|
33
36
|
}
|
package/src/cli/config.test.ts
CHANGED
|
@@ -343,7 +343,23 @@ describe("Config", () => {
|
|
|
343
343
|
expect(result.branchDataMode).toBe("last_partition");
|
|
344
344
|
});
|
|
345
345
|
|
|
346
|
-
it("
|
|
346
|
+
it("throws when branch_data_mode is none", () => {
|
|
347
|
+
const config = {
|
|
348
|
+
include: ["lib/datasources.ts"],
|
|
349
|
+
token: "test-token",
|
|
350
|
+
branch_data_mode: "none",
|
|
351
|
+
};
|
|
352
|
+
fs.writeFileSync(
|
|
353
|
+
path.join(tempDir, "tinybird.json"),
|
|
354
|
+
JSON.stringify(config)
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
expect(() => loadConfig(tempDir)).toThrow(
|
|
358
|
+
"Invalid branch_data_mode 'none'. Allowed values are: last_partition."
|
|
359
|
+
);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it("defaults branch_data_mode to no data when missing", () => {
|
|
347
363
|
const config = {
|
|
348
364
|
include: ["lib/datasources.ts"],
|
|
349
365
|
token: "test-token",
|
|
@@ -354,10 +370,10 @@ describe("Config", () => {
|
|
|
354
370
|
);
|
|
355
371
|
|
|
356
372
|
const result = loadConfig(tempDir);
|
|
357
|
-
expect(result.branchDataMode).
|
|
373
|
+
expect(result.branchDataMode).toBeNull();
|
|
358
374
|
});
|
|
359
375
|
|
|
360
|
-
it("defaults empty branch_data_mode to
|
|
376
|
+
it("defaults empty branch_data_mode to no data", () => {
|
|
361
377
|
const config = {
|
|
362
378
|
include: ["lib/datasources.ts"],
|
|
363
379
|
token: "test-token",
|
|
@@ -369,7 +385,7 @@ describe("Config", () => {
|
|
|
369
385
|
);
|
|
370
386
|
|
|
371
387
|
const result = loadConfig(tempDir);
|
|
372
|
-
expect(result.branchDataMode).
|
|
388
|
+
expect(result.branchDataMode).toBeNull();
|
|
373
389
|
});
|
|
374
390
|
|
|
375
391
|
it("throws when branch_data_mode is all_partitions", () => {
|
package/src/cli/config.ts
CHANGED
|
@@ -17,7 +17,6 @@ export {
|
|
|
17
17
|
import { BRANCH_DATA_MODE_VALUES } from "./config-types.js";
|
|
18
18
|
import type { BranchDataMode, DevMode, TinybirdConfig } from "./config-types.js";
|
|
19
19
|
|
|
20
|
-
const DEFAULT_BRANCH_DATA_MODE: BranchDataMode = "last_partition";
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* Resolved configuration with all values expanded
|
|
@@ -41,7 +40,7 @@ export interface ResolvedConfig {
|
|
|
41
40
|
isMainBranch: boolean;
|
|
42
41
|
/** Development mode: "branch" or "local" */
|
|
43
42
|
devMode: DevMode;
|
|
44
|
-
/** Branch data mode configured in tinybird.config.json */
|
|
43
|
+
/** Branch data mode configured in tinybird.config.json (null = create branches without data, the default) */
|
|
45
44
|
branchDataMode?: BranchDataMode | null;
|
|
46
45
|
}
|
|
47
46
|
|
|
@@ -212,10 +211,10 @@ function resolveBranchDataMode(raw: Record<string, unknown>): { mode: BranchData
|
|
|
212
211
|
}
|
|
213
212
|
|
|
214
213
|
const value = raw["branch_data_mode"];
|
|
215
|
-
if (value === undefined || value === null) return { mode:
|
|
214
|
+
if (value === undefined || value === null) return { mode: null, explicit: false };
|
|
216
215
|
if (typeof value !== "string") throw new Error("branch_data_mode must be a string.");
|
|
217
216
|
const mode = value.trim().toLowerCase();
|
|
218
|
-
if (!mode) return { mode:
|
|
217
|
+
if (!mode) return { mode: null, explicit: false };
|
|
219
218
|
if (!BRANCH_DATA_MODE_VALUES.includes(mode as BranchDataMode)) {
|
|
220
219
|
throw new Error(
|
|
221
220
|
`Invalid branch_data_mode '${value}'. Allowed values are: ${BRANCH_DATA_MODE_VALUES.join(", ")}.`
|
package/src/client/base.ts
CHANGED
|
@@ -342,8 +342,8 @@ export class TinybirdClient {
|
|
|
342
342
|
|
|
343
343
|
const branchName = config.tinybirdBranch;
|
|
344
344
|
const branchOptions: CreateBranchOptions | undefined =
|
|
345
|
-
config.devMode !== "local" && config.branchDataMode
|
|
346
|
-
? { branch_data_mode:
|
|
345
|
+
config.devMode !== "local" && config.branchDataMode
|
|
346
|
+
? { branch_data_mode: config.branchDataMode }
|
|
347
347
|
: undefined;
|
|
348
348
|
|
|
349
349
|
// Get or create branch (always fetch fresh to avoid stale cache issues)
|