@tinybirdco/sdk 0.0.4 → 0.0.7
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 +52 -13
- package/dist/api/branches.d.ts.map +1 -1
- package/dist/api/branches.js +6 -5
- package/dist/api/branches.js.map +1 -1
- package/dist/api/branches.test.js +32 -6
- package/dist/api/branches.test.js.map +1 -1
- package/dist/api/build.d.ts.map +1 -1
- package/dist/api/build.js +2 -1
- package/dist/api/build.js.map +1 -1
- package/dist/api/deploy.d.ts +42 -3
- package/dist/api/deploy.d.ts.map +1 -1
- package/dist/api/deploy.js +162 -19
- package/dist/api/deploy.js.map +1 -1
- package/dist/api/deploy.test.js +83 -31
- package/dist/api/deploy.test.js.map +1 -1
- package/dist/api/fetcher.d.ts +6 -0
- package/dist/api/fetcher.d.ts.map +1 -0
- package/dist/api/fetcher.js +13 -0
- package/dist/api/fetcher.js.map +1 -0
- package/dist/api/local.d.ts.map +1 -1
- package/dist/api/local.js +5 -4
- package/dist/api/local.js.map +1 -1
- package/dist/api/local.test.js.map +1 -1
- package/dist/api/resources.d.ts +178 -0
- package/dist/api/resources.d.ts.map +1 -0
- package/dist/api/resources.js +245 -0
- package/dist/api/resources.js.map +1 -0
- package/dist/api/resources.test.d.ts +2 -0
- package/dist/api/resources.test.d.ts.map +1 -0
- package/dist/api/resources.test.js +255 -0
- package/dist/api/resources.test.js.map +1 -0
- package/dist/api/workspaces.d.ts.map +1 -1
- package/dist/api/workspaces.js +2 -1
- package/dist/api/workspaces.js.map +1 -1
- package/dist/api/workspaces.test.js +9 -1
- package/dist/api/workspaces.test.js.map +1 -1
- package/dist/cli/auth.d.ts.map +1 -1
- package/dist/cli/auth.js +2 -1
- package/dist/cli/auth.js.map +1 -1
- package/dist/cli/commands/build.d.ts +3 -4
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +23 -25
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/deploy.d.ts +41 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -0
- package/dist/cli/commands/deploy.js +92 -0
- package/dist/cli/commands/deploy.js.map +1 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +7 -3
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/init.d.ts +38 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +434 -23
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/init.test.js +190 -30
- package/dist/cli/commands/init.test.js.map +1 -1
- package/dist/cli/index.js +80 -15
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/utils/package-manager.d.ts +8 -0
- package/dist/cli/utils/package-manager.d.ts.map +1 -0
- package/dist/cli/utils/package-manager.js +45 -0
- package/dist/cli/utils/package-manager.js.map +1 -0
- package/dist/cli/utils/package-manager.test.d.ts +2 -0
- package/dist/cli/utils/package-manager.test.d.ts.map +1 -0
- package/dist/cli/utils/package-manager.test.js +85 -0
- package/dist/cli/utils/package-manager.test.js.map +1 -0
- package/dist/client/base.d.ts.map +1 -1
- package/dist/client/base.js +2 -1
- package/dist/client/base.js.map +1 -1
- package/dist/codegen/index.d.ts +39 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/index.js +300 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/index.test.d.ts +2 -0
- package/dist/codegen/index.test.d.ts.map +1 -0
- package/dist/codegen/index.test.js +310 -0
- package/dist/codegen/index.test.js.map +1 -0
- package/dist/codegen/type-mapper.d.ts +20 -0
- package/dist/codegen/type-mapper.d.ts.map +1 -0
- package/dist/codegen/type-mapper.js +238 -0
- package/dist/codegen/type-mapper.js.map +1 -0
- package/dist/codegen/type-mapper.test.d.ts +2 -0
- package/dist/codegen/type-mapper.test.d.ts.map +1 -0
- package/dist/codegen/type-mapper.test.js +167 -0
- package/dist/codegen/type-mapper.test.js.map +1 -0
- package/dist/codegen/utils.d.ts +46 -0
- package/dist/codegen/utils.d.ts.map +1 -0
- package/dist/codegen/utils.js +141 -0
- package/dist/codegen/utils.js.map +1 -0
- package/dist/codegen/utils.test.d.ts +2 -0
- package/dist/codegen/utils.test.d.ts.map +1 -0
- package/dist/codegen/utils.test.js +178 -0
- package/dist/codegen/utils.test.js.map +1 -0
- package/dist/generator/index.d.ts +3 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +17 -1
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/index.test.js +104 -1
- package/dist/generator/index.test.js.map +1 -1
- package/dist/generator/loader.d.ts +15 -0
- package/dist/generator/loader.d.ts.map +1 -1
- package/dist/generator/loader.js +24 -0
- package/dist/generator/loader.js.map +1 -1
- package/dist/schema/connection.d.ts.map +1 -1
- package/dist/schema/connection.js +3 -2
- package/dist/schema/connection.js.map +1 -1
- package/dist/schema/datasource.d.ts.map +1 -1
- package/dist/schema/datasource.js +3 -2
- package/dist/schema/datasource.js.map +1 -1
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +3 -2
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/pipe.d.ts +2 -2
- package/dist/schema/pipe.d.ts.map +1 -1
- package/dist/schema/pipe.js +4 -4
- package/dist/schema/pipe.js.map +1 -1
- package/dist/schema/project.d.ts.map +1 -1
- package/dist/schema/project.js +3 -2
- package/dist/schema/project.js.map +1 -1
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +3 -2
- package/dist/schema/types.js.map +1 -1
- package/dist/test/handlers.d.ts +49 -0
- package/dist/test/handlers.d.ts.map +1 -1
- package/dist/test/handlers.js +45 -0
- package/dist/test/handlers.js.map +1 -1
- package/package.json +4 -2
- package/src/api/branches.test.ts +65 -57
- package/src/api/branches.ts +7 -5
- package/src/api/build.ts +2 -1
- package/src/api/deploy.test.ts +141 -36
- package/src/api/deploy.ts +231 -23
- package/src/api/fetcher.ts +17 -0
- package/src/api/local.test.ts +43 -31
- package/src/api/local.ts +5 -4
- package/src/api/resources.test.ts +332 -0
- package/src/api/resources.ts +555 -0
- package/src/api/workspaces.test.ts +15 -9
- package/src/api/workspaces.ts +3 -1
- package/src/cli/auth.ts +2 -1
- package/src/cli/commands/build.ts +29 -33
- package/src/cli/commands/deploy.ts +131 -0
- package/src/cli/commands/dev.ts +10 -3
- package/src/cli/commands/init.test.ts +239 -30
- package/src/cli/commands/init.ts +548 -26
- package/src/cli/index.ts +117 -20
- package/src/cli/utils/package-manager.test.ts +118 -0
- package/src/cli/utils/package-manager.ts +44 -0
- package/src/client/base.ts +3 -2
- package/src/codegen/index.test.ts +367 -0
- package/src/codegen/index.ts +379 -0
- package/src/codegen/type-mapper.test.ts +224 -0
- package/src/codegen/type-mapper.ts +265 -0
- package/src/codegen/utils.test.ts +221 -0
- package/src/codegen/utils.ts +174 -0
- package/src/generator/index.test.ts +121 -1
- package/src/generator/index.ts +19 -1
- package/src/generator/loader.ts +43 -0
- package/src/schema/connection.ts +3 -2
- package/src/schema/datasource.ts +3 -2
- package/src/schema/params.ts +3 -2
- package/src/schema/pipe.ts +4 -4
- package/src/schema/project.ts +3 -2
- package/src/schema/types.ts +3 -2
- package/src/test/handlers.ts +58 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Build command - generates and pushes resources to Tinybird
|
|
2
|
+
* Build command - generates and pushes resources to Tinybird branches
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { loadConfig, LOCAL_BASE_URL, type ResolvedConfig, type DevMode } from "../config.js";
|
|
6
6
|
import { buildFromInclude, type BuildFromIncludeResult } from "../../generator/index.js";
|
|
7
7
|
import { buildToTinybird, type BuildApiResult } from "../../api/build.js";
|
|
8
|
-
import { deployToMain } from "../../api/deploy.js";
|
|
9
8
|
import { getOrCreateBranch } from "../../api/branches.js";
|
|
10
9
|
import {
|
|
11
10
|
getLocalTokens,
|
|
@@ -24,8 +23,6 @@ export interface BuildCommandOptions {
|
|
|
24
23
|
dryRun?: boolean;
|
|
25
24
|
/** Override the token from config (used for branch tokens) */
|
|
26
25
|
tokenOverride?: string;
|
|
27
|
-
/** Use /v1/deploy instead of /v1/build (for main branch) */
|
|
28
|
-
useDeployEndpoint?: boolean;
|
|
29
26
|
/** Override the devMode from config */
|
|
30
27
|
devModeOverride?: DevMode;
|
|
31
28
|
}
|
|
@@ -49,7 +46,8 @@ export interface BuildCommandResult {
|
|
|
49
46
|
/**
|
|
50
47
|
* Run the build command
|
|
51
48
|
*
|
|
52
|
-
*
|
|
49
|
+
* Builds resources and pushes to Tinybird branches (not main).
|
|
50
|
+
* Use runDeploy for deploying to production.
|
|
53
51
|
*
|
|
54
52
|
* @param options - Build options
|
|
55
53
|
* @returns Build command result
|
|
@@ -150,12 +148,19 @@ export async function runBuild(options: BuildCommandOptions = {}): Promise<Build
|
|
|
150
148
|
};
|
|
151
149
|
}
|
|
152
150
|
} else {
|
|
153
|
-
// Branch mode (default)
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
151
|
+
// Branch mode (default)
|
|
152
|
+
// Prevent building to main - must use deploy command
|
|
153
|
+
// Skip this check if tokenOverride is provided (dev command passes branch token)
|
|
154
|
+
const isMainBranch = config.isMainBranch || !config.tinybirdBranch;
|
|
155
|
+
|
|
156
|
+
if (isMainBranch && !options.tokenOverride) {
|
|
157
|
+
return {
|
|
158
|
+
success: false,
|
|
159
|
+
build: buildResult,
|
|
160
|
+
error: `Cannot deploy to main workspace with 'build' command. Use 'tinybird deploy' to deploy to production, or switch to a feature branch.`,
|
|
161
|
+
durationMs: Date.now() - startTime,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
159
164
|
|
|
160
165
|
if (debug) {
|
|
161
166
|
console.log(`[debug] isMainBranch: ${config.isMainBranch}`);
|
|
@@ -163,8 +168,10 @@ export async function runBuild(options: BuildCommandOptions = {}): Promise<Build
|
|
|
163
168
|
console.log(`[debug] tokenOverride: ${!!options.tokenOverride}`);
|
|
164
169
|
}
|
|
165
170
|
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
let effectiveToken = options.tokenOverride ?? config.token;
|
|
172
|
+
|
|
173
|
+
// Get or create the Tinybird branch and use its token
|
|
174
|
+
if (!options.tokenOverride) {
|
|
168
175
|
if (debug) {
|
|
169
176
|
console.log(`[debug] Getting/creating Tinybird branch: ${config.tinybirdBranch}`);
|
|
170
177
|
}
|
|
@@ -174,7 +181,7 @@ export async function runBuild(options: BuildCommandOptions = {}): Promise<Build
|
|
|
174
181
|
baseUrl: config.baseUrl,
|
|
175
182
|
token: config.token,
|
|
176
183
|
},
|
|
177
|
-
config.tinybirdBranch
|
|
184
|
+
config.tinybirdBranch!
|
|
178
185
|
);
|
|
179
186
|
|
|
180
187
|
if (!tinybirdBranch.token) {
|
|
@@ -187,7 +194,6 @@ export async function runBuild(options: BuildCommandOptions = {}): Promise<Build
|
|
|
187
194
|
}
|
|
188
195
|
|
|
189
196
|
effectiveToken = tinybirdBranch.token;
|
|
190
|
-
useDeployEndpoint = false; // Always use /v1/build for branches
|
|
191
197
|
if (debug) {
|
|
192
198
|
console.log(`[debug] Using branch token for branch: ${config.tinybirdBranch}`);
|
|
193
199
|
}
|
|
@@ -202,24 +208,14 @@ export async function runBuild(options: BuildCommandOptions = {}): Promise<Build
|
|
|
202
208
|
}
|
|
203
209
|
|
|
204
210
|
try {
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
);
|
|
214
|
-
} else {
|
|
215
|
-
deployResult = await buildToTinybird(
|
|
216
|
-
{
|
|
217
|
-
baseUrl: config.baseUrl,
|
|
218
|
-
token: effectiveToken,
|
|
219
|
-
},
|
|
220
|
-
buildResult.resources
|
|
221
|
-
);
|
|
222
|
-
}
|
|
211
|
+
// Always use /v1/build for branches
|
|
212
|
+
deployResult = await buildToTinybird(
|
|
213
|
+
{
|
|
214
|
+
baseUrl: config.baseUrl,
|
|
215
|
+
token: effectiveToken,
|
|
216
|
+
},
|
|
217
|
+
buildResult.resources
|
|
218
|
+
);
|
|
223
219
|
} catch (error) {
|
|
224
220
|
return {
|
|
225
221
|
success: false,
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deploy command - deploys resources to main Tinybird workspace
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { loadConfig, type ResolvedConfig } from "../config.js";
|
|
6
|
+
import { buildFromInclude, type BuildFromIncludeResult } from "../../generator/index.js";
|
|
7
|
+
import { deployToMain } from "../../api/deploy.js";
|
|
8
|
+
import type { BuildApiResult } from "../../api/build.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Deploy command options
|
|
12
|
+
*/
|
|
13
|
+
export interface DeployCommandOptions {
|
|
14
|
+
/** Working directory (defaults to cwd) */
|
|
15
|
+
cwd?: string;
|
|
16
|
+
/** Skip pushing to API (just generate) */
|
|
17
|
+
dryRun?: boolean;
|
|
18
|
+
/** Validate deploy with Tinybird API without applying */
|
|
19
|
+
check?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Deploy command result
|
|
24
|
+
*/
|
|
25
|
+
export interface DeployCommandResult {
|
|
26
|
+
/** Whether the deploy was successful */
|
|
27
|
+
success: boolean;
|
|
28
|
+
/** Build result with generated resources */
|
|
29
|
+
build?: BuildFromIncludeResult;
|
|
30
|
+
/** Deploy API result (if not dry run) */
|
|
31
|
+
deploy?: BuildApiResult;
|
|
32
|
+
/** Error message if failed */
|
|
33
|
+
error?: string;
|
|
34
|
+
/** Duration in milliseconds */
|
|
35
|
+
durationMs: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Run the deploy command
|
|
40
|
+
*
|
|
41
|
+
* Builds resources and deploys to main Tinybird workspace (production).
|
|
42
|
+
*
|
|
43
|
+
* @param options - Deploy options
|
|
44
|
+
* @returns Deploy command result
|
|
45
|
+
*/
|
|
46
|
+
export async function runDeploy(options: DeployCommandOptions = {}): Promise<DeployCommandResult> {
|
|
47
|
+
const startTime = Date.now();
|
|
48
|
+
const cwd = options.cwd ?? process.cwd();
|
|
49
|
+
|
|
50
|
+
// Load config
|
|
51
|
+
let config: ResolvedConfig;
|
|
52
|
+
try {
|
|
53
|
+
config = loadConfig(cwd);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
error: (error as Error).message,
|
|
58
|
+
durationMs: Date.now() - startTime,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Build resources from include paths
|
|
63
|
+
let buildResult: BuildFromIncludeResult;
|
|
64
|
+
try {
|
|
65
|
+
buildResult = await buildFromInclude({
|
|
66
|
+
includePaths: config.include,
|
|
67
|
+
cwd: config.cwd,
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
error: `Build failed: ${(error as Error).message}`,
|
|
73
|
+
durationMs: Date.now() - startTime,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// If dry run, return without pushing
|
|
78
|
+
if (options.dryRun) {
|
|
79
|
+
return {
|
|
80
|
+
success: true,
|
|
81
|
+
build: buildResult,
|
|
82
|
+
durationMs: Date.now() - startTime,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const debug = !!process.env.TINYBIRD_DEBUG;
|
|
87
|
+
|
|
88
|
+
if (debug) {
|
|
89
|
+
console.log(`[debug] Deploying to main workspace`);
|
|
90
|
+
console.log(`[debug] baseUrl: ${config.baseUrl}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Deploy to main workspace using /v1/deploy endpoint
|
|
94
|
+
let deployResult: BuildApiResult;
|
|
95
|
+
try {
|
|
96
|
+
deployResult = await deployToMain(
|
|
97
|
+
{
|
|
98
|
+
baseUrl: config.baseUrl,
|
|
99
|
+
token: config.token,
|
|
100
|
+
},
|
|
101
|
+
buildResult.resources,
|
|
102
|
+
{
|
|
103
|
+
check: options.check,
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return {
|
|
108
|
+
success: false,
|
|
109
|
+
build: buildResult,
|
|
110
|
+
error: `Deploy failed: ${(error as Error).message}`,
|
|
111
|
+
durationMs: Date.now() - startTime,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!deployResult.success) {
|
|
116
|
+
return {
|
|
117
|
+
success: false,
|
|
118
|
+
build: buildResult,
|
|
119
|
+
deploy: deployResult,
|
|
120
|
+
error: deployResult.error,
|
|
121
|
+
durationMs: Date.now() - startTime,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
success: true,
|
|
127
|
+
build: buildResult,
|
|
128
|
+
deploy: deployResult,
|
|
129
|
+
durationMs: Date.now() - startTime,
|
|
130
|
+
};
|
|
131
|
+
}
|
package/src/cli/commands/dev.ts
CHANGED
|
@@ -187,9 +187,16 @@ export async function runDev(options: DevCommandOptions = {}): Promise<DevContro
|
|
|
187
187
|
};
|
|
188
188
|
} else {
|
|
189
189
|
// Branch mode: use Tinybird cloud with branches
|
|
190
|
-
//
|
|
190
|
+
// Prevent dev mode on main branch - must use deploy command
|
|
191
|
+
if (config.isMainBranch || !config.tinybirdBranch) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
`Cannot use 'dev' command on main branch. Use 'tinybird deploy' to deploy to production, or switch to a feature branch.`
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Get or create the Tinybird branch
|
|
191
198
|
// Use tinybirdBranch (sanitized name) for Tinybird API, gitBranch for display
|
|
192
|
-
if (
|
|
199
|
+
if (config.tinybirdBranch) {
|
|
193
200
|
const branchName = config.tinybirdBranch; // Sanitized name for Tinybird
|
|
194
201
|
|
|
195
202
|
// Always fetch fresh from API to avoid stale cache issues
|
|
@@ -246,10 +253,10 @@ export async function runDev(options: DevCommandOptions = {}): Promise<DevContro
|
|
|
246
253
|
options.onBuildStart?.();
|
|
247
254
|
|
|
248
255
|
try {
|
|
256
|
+
// Always use runBuild - main branch is blocked at startup
|
|
249
257
|
const result = await runBuild({
|
|
250
258
|
cwd: config.cwd,
|
|
251
259
|
tokenOverride: effectiveToken,
|
|
252
|
-
useDeployEndpoint: devMode !== "local" && config.isMainBranch,
|
|
253
260
|
devModeOverride: devMode,
|
|
254
261
|
});
|
|
255
262
|
options.onBuildComplete?.(result);
|