@tinybirdco/sdk 0.0.30 → 0.0.32
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 +29 -4
- package/dist/cli/auth.d.ts.map +1 -1
- package/dist/cli/auth.js +1 -0
- package/dist/cli/auth.js.map +1 -1
- package/dist/cli/commands/branch.js +5 -5
- package/dist/cli/commands/branch.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/build.test.d.ts +2 -0
- package/dist/cli/commands/build.test.d.ts.map +1 -0
- package/dist/cli/commands/build.test.js +266 -0
- package/dist/cli/commands/build.test.js.map +1 -0
- package/dist/cli/commands/clear.d.ts.map +1 -1
- package/dist/cli/commands/clear.js +2 -2
- package/dist/cli/commands/clear.js.map +1 -1
- package/dist/cli/commands/deploy.js +2 -2
- package/dist/cli/commands/deploy.js.map +1 -1
- package/dist/cli/commands/dev.js +12 -12
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/info.js +2 -2
- package/dist/cli/commands/info.js.map +1 -1
- package/dist/cli/commands/info.test.js +11 -13
- package/dist/cli/commands/info.test.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +44 -26
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/init.test.js +44 -25
- package/dist/cli/commands/init.test.js.map +1 -1
- package/dist/cli/commands/login.d.ts.map +1 -1
- package/dist/cli/commands/login.js +7 -6
- package/dist/cli/commands/login.js.map +1 -1
- package/dist/cli/commands/login.test.js +1 -1
- package/dist/cli/commands/login.test.js.map +1 -1
- package/dist/cli/commands/preview.d.ts.map +1 -1
- package/dist/cli/commands/preview.js +2 -2
- package/dist/cli/commands/preview.js.map +1 -1
- package/dist/cli/config-loader.d.ts +18 -0
- package/dist/cli/config-loader.d.ts.map +1 -0
- package/dist/cli/config-loader.js +57 -0
- package/dist/cli/config-loader.js.map +1 -0
- package/dist/cli/config-types.d.ts +28 -0
- package/dist/cli/config-types.d.ts.map +1 -0
- package/dist/cli/config-types.js +8 -0
- package/dist/cli/config-types.js.map +1 -0
- package/dist/cli/config.d.ts +63 -29
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +139 -43
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/config.test.js +73 -9
- package/dist/cli/config.test.js.map +1 -1
- package/dist/cli/index.js +4 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/client/base.d.ts.map +1 -1
- package/dist/client/base.js +21 -9
- package/dist/client/base.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/auth.ts +1 -0
- package/src/cli/commands/branch.ts +5 -5
- package/src/cli/commands/build.test.ts +310 -0
- package/src/cli/commands/build.ts +2 -2
- package/src/cli/commands/clear.ts +2 -2
- package/src/cli/commands/deploy.ts +2 -2
- package/src/cli/commands/dev.ts +12 -12
- package/src/cli/commands/info.test.ts +11 -13
- package/src/cli/commands/info.ts +2 -2
- package/src/cli/commands/init.test.ts +53 -37
- package/src/cli/commands/init.ts +49 -30
- package/src/cli/commands/login.test.ts +1 -1
- package/src/cli/commands/login.ts +7 -6
- package/src/cli/commands/preview.ts +2 -2
- package/src/cli/config-loader.ts +87 -0
- package/src/cli/config-types.ts +29 -0
- package/src/cli/config.test.ts +95 -8
- package/src/cli/config.ts +179 -70
- package/src/cli/index.ts +3 -0
- package/src/client/base.ts +33 -16
- package/src/index.ts +4 -0
package/src/client/base.ts
CHANGED
|
@@ -130,9 +130,11 @@ export class TinybirdClient {
|
|
|
130
130
|
try {
|
|
131
131
|
// Dynamic import to avoid circular dependencies and to keep CLI code
|
|
132
132
|
// out of the client bundle when not using dev mode
|
|
133
|
-
const {
|
|
133
|
+
const { loadConfigAsync } = await import("../cli/config.js");
|
|
134
134
|
const { getOrCreateBranch } = await import("../api/branches.js");
|
|
135
|
-
const { isPreviewEnvironment, getPreviewBranchName } = await import(
|
|
135
|
+
const { isPreviewEnvironment, getPreviewBranchName } = await import(
|
|
136
|
+
"./preview.js"
|
|
137
|
+
);
|
|
136
138
|
|
|
137
139
|
// In preview environments (Vercel preview, CI), the token was already resolved
|
|
138
140
|
// by resolveToken() in project.ts - skip branch creation to avoid conflicts
|
|
@@ -140,9 +142,14 @@ export class TinybirdClient {
|
|
|
140
142
|
const gitBranchName = getPreviewBranchName();
|
|
141
143
|
// Preview branches use the tmp_ci_ prefix (matches what tinybird preview creates)
|
|
142
144
|
const sanitized = gitBranchName
|
|
143
|
-
? gitBranchName
|
|
145
|
+
? gitBranchName
|
|
146
|
+
.replace(/[^a-zA-Z0-9_]/g, "_")
|
|
147
|
+
.replace(/_+/g, "_")
|
|
148
|
+
.replace(/^_|_$/g, "")
|
|
149
|
+
: undefined;
|
|
150
|
+
const tinybirdBranchName = sanitized
|
|
151
|
+
? `tmp_ci_${sanitized}`
|
|
144
152
|
: undefined;
|
|
145
|
-
const tinybirdBranchName = sanitized ? `tmp_ci_${sanitized}` : undefined;
|
|
146
153
|
return this.buildContext({
|
|
147
154
|
token: this.config.token,
|
|
148
155
|
isBranchToken: !!tinybirdBranchName,
|
|
@@ -153,12 +160,16 @@ export class TinybirdClient {
|
|
|
153
160
|
|
|
154
161
|
// Use configDir if provided (important for monorepo setups where process.cwd()
|
|
155
162
|
// may not be in the same directory tree as tinybird.json)
|
|
156
|
-
const config =
|
|
163
|
+
const config = await loadConfigAsync(this.config.configDir);
|
|
157
164
|
const gitBranch = config.gitBranch ?? undefined;
|
|
158
165
|
|
|
159
166
|
// If on main branch, use the workspace token
|
|
160
167
|
if (config.isMainBranch || !config.tinybirdBranch) {
|
|
161
|
-
return this.buildContext({
|
|
168
|
+
return this.buildContext({
|
|
169
|
+
token: this.config.token,
|
|
170
|
+
isBranchToken: false,
|
|
171
|
+
gitBranch,
|
|
172
|
+
});
|
|
162
173
|
}
|
|
163
174
|
|
|
164
175
|
const branchName = config.tinybirdBranch;
|
|
@@ -171,7 +182,11 @@ export class TinybirdClient {
|
|
|
171
182
|
|
|
172
183
|
if (!branch.token) {
|
|
173
184
|
// Fall back to workspace token if no branch token
|
|
174
|
-
return this.buildContext({
|
|
185
|
+
return this.buildContext({
|
|
186
|
+
token: this.config.token,
|
|
187
|
+
isBranchToken: false,
|
|
188
|
+
gitBranch,
|
|
189
|
+
});
|
|
175
190
|
}
|
|
176
191
|
|
|
177
192
|
return this.buildContext({
|
|
@@ -180,9 +195,11 @@ export class TinybirdClient {
|
|
|
180
195
|
branchName,
|
|
181
196
|
gitBranch,
|
|
182
197
|
});
|
|
183
|
-
} catch {
|
|
184
|
-
|
|
185
|
-
|
|
198
|
+
} catch (error) {
|
|
199
|
+
throw new TinybirdError(
|
|
200
|
+
`Failed to resolve branch context: ${(error as Error).message}`,
|
|
201
|
+
500
|
|
202
|
+
);
|
|
186
203
|
}
|
|
187
204
|
}
|
|
188
205
|
|
|
@@ -240,7 +257,11 @@ export class TinybirdClient {
|
|
|
240
257
|
const token = await this.getToken();
|
|
241
258
|
|
|
242
259
|
try {
|
|
243
|
-
return await this.getApi(token).ingestBatch(
|
|
260
|
+
return await this.getApi(token).ingestBatch(
|
|
261
|
+
datasourceName,
|
|
262
|
+
events,
|
|
263
|
+
options
|
|
264
|
+
);
|
|
244
265
|
} catch (error) {
|
|
245
266
|
this.rethrowApiError(error);
|
|
246
267
|
}
|
|
@@ -310,11 +331,7 @@ export class TinybirdClient {
|
|
|
310
331
|
|
|
311
332
|
private rethrowApiError(error: unknown): never {
|
|
312
333
|
if (error instanceof TinybirdApiError) {
|
|
313
|
-
throw new TinybirdError(
|
|
314
|
-
error.message,
|
|
315
|
-
error.statusCode,
|
|
316
|
-
error.response
|
|
317
|
-
);
|
|
334
|
+
throw new TinybirdError(error.message, error.statusCode, error.response);
|
|
318
335
|
}
|
|
319
336
|
|
|
320
337
|
throw error;
|
package/src/index.ts
CHANGED
|
@@ -245,3 +245,7 @@ export {
|
|
|
245
245
|
getLocalDashboardUrl,
|
|
246
246
|
} from "./api/dashboard.js";
|
|
247
247
|
export type { RegionInfo } from "./api/dashboard.js";
|
|
248
|
+
|
|
249
|
+
// ============ Config Types ============
|
|
250
|
+
// Import from config-types.ts to avoid bundling esbuild in client code
|
|
251
|
+
export type { TinybirdConfig, DevMode } from "./cli/config-types.js";
|