@tinybirdco/sdk 0.0.6 → 0.0.8
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/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 +1 -0
- package/dist/api/deploy.d.ts.map +1 -1
- package/dist/api/deploy.js +27 -6
- package/dist/api/deploy.js.map +1 -1
- package/dist/api/deploy.test.js +6 -2
- 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 +2 -0
- package/dist/api/resources.d.ts.map +1 -1
- package/dist/api/resources.js +6 -4
- package/dist/api/resources.js.map +1 -1
- 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/deploy.d.ts +2 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -1
- package/dist/cli/commands/deploy.js +3 -1
- package/dist/cli/commands/deploy.js.map +1 -1
- package/dist/cli/commands/init.d.ts +14 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +264 -4
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/index.js +8 -3
- package/dist/cli/index.js.map +1 -1
- 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.map +1 -1
- package/dist/codegen/index.js +4 -0
- package/dist/codegen/index.js.map +1 -1
- package/dist/codegen/index.test.js +10 -0
- package/dist/codegen/index.test.js.map +1 -1
- package/dist/generator/datasource.d.ts.map +1 -1
- package/dist/generator/datasource.js +20 -0
- package/dist/generator/datasource.js.map +1 -1
- package/dist/generator/datasource.test.js +11 -0
- package/dist/generator/datasource.test.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 +5 -0
- 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/package.json +1 -1
- 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 +6 -2
- package/src/api/deploy.ts +35 -7
- 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.ts +9 -4
- 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/deploy.ts +6 -1
- package/src/cli/commands/init.ts +311 -6
- package/src/cli/index.ts +35 -11
- package/src/client/base.ts +3 -2
- package/src/codegen/index.test.ts +12 -0
- package/src/codegen/index.ts +5 -0
- package/src/generator/datasource.test.ts +13 -0
- package/src/generator/datasource.ts +24 -0
- package/src/schema/connection.ts +3 -2
- package/src/schema/datasource.ts +8 -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
|
@@ -74,6 +74,18 @@ describe("generateDatasourceCode", () => {
|
|
|
74
74
|
expect(code).toContain(" * Event tracking data");
|
|
75
75
|
expect(code).toContain(" */");
|
|
76
76
|
});
|
|
77
|
+
|
|
78
|
+
it("includes forward query when present", () => {
|
|
79
|
+
const ds: DatasourceInfo = {
|
|
80
|
+
name: "events",
|
|
81
|
+
columns: [{ name: "id", type: "String" }],
|
|
82
|
+
engine: { type: "MergeTree", sorting_key: "id" },
|
|
83
|
+
forward_query: "SELECT id",
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const code = generateDatasourceCode(ds);
|
|
87
|
+
expect(code).toContain("forwardQuery: `SELECT id`");
|
|
88
|
+
});
|
|
77
89
|
});
|
|
78
90
|
|
|
79
91
|
describe("generatePipeCode", () => {
|
package/src/codegen/index.ts
CHANGED
|
@@ -45,6 +45,11 @@ export function generateDatasourceCode(ds: DatasourceInfo): string {
|
|
|
45
45
|
const engineCode = generateEngineCode(ds.engine);
|
|
46
46
|
lines.push(` engine: ${engineCode},`);
|
|
47
47
|
|
|
48
|
+
if (ds.forward_query) {
|
|
49
|
+
const formattedQuery = formatSqlForTemplate(ds.forward_query);
|
|
50
|
+
lines.push(` forwardQuery: \`${formattedQuery}\`,`);
|
|
51
|
+
}
|
|
52
|
+
|
|
48
53
|
lines.push("});");
|
|
49
54
|
lines.push("");
|
|
50
55
|
lines.push(`export type ${typeName}Row = InferRow<typeof ${varName}>;`);
|
|
@@ -81,6 +81,19 @@ describe('Datasource Generator', () => {
|
|
|
81
81
|
const result = generateDatasource(ds);
|
|
82
82
|
expect(result.content).toContain('ENGINE_TTL "timestamp + INTERVAL 90 DAY"');
|
|
83
83
|
});
|
|
84
|
+
|
|
85
|
+
it('includes forward query when provided', () => {
|
|
86
|
+
const ds = defineDatasource('test_ds', {
|
|
87
|
+
schema: {
|
|
88
|
+
id: t.string(),
|
|
89
|
+
},
|
|
90
|
+
forwardQuery: 'SELECT id',
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const result = generateDatasource(ds);
|
|
94
|
+
expect(result.content).toContain('FORWARD_QUERY >');
|
|
95
|
+
expect(result.content).toContain(' SELECT id');
|
|
96
|
+
});
|
|
84
97
|
});
|
|
85
98
|
|
|
86
99
|
describe('Column formatting', () => {
|
|
@@ -163,6 +163,23 @@ function generateKafkaConfig(kafka: KafkaConfig): string {
|
|
|
163
163
|
return parts.join("\n");
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Generate forward query section
|
|
168
|
+
*/
|
|
169
|
+
function generateForwardQuery(forwardQuery?: string): string | null {
|
|
170
|
+
if (!forwardQuery) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const trimmed = forwardQuery.trim();
|
|
175
|
+
if (!trimmed) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const lines = trimmed.split(/\r?\n/);
|
|
180
|
+
return ["FORWARD_QUERY >", ...lines.map((line) => ` ${line}`)].join("\n");
|
|
181
|
+
}
|
|
182
|
+
|
|
166
183
|
/**
|
|
167
184
|
* Generate a .datasource file content from a DatasourceDefinition
|
|
168
185
|
*
|
|
@@ -224,6 +241,13 @@ export function generateDatasource(
|
|
|
224
241
|
parts.push(generateKafkaConfig(datasource.options.kafka));
|
|
225
242
|
}
|
|
226
243
|
|
|
244
|
+
// Add forward query if present
|
|
245
|
+
const forwardQuery = generateForwardQuery(datasource.options.forwardQuery);
|
|
246
|
+
if (forwardQuery) {
|
|
247
|
+
parts.push("");
|
|
248
|
+
parts.push(forwardQuery);
|
|
249
|
+
}
|
|
250
|
+
|
|
227
251
|
return {
|
|
228
252
|
name: datasource._name,
|
|
229
253
|
content: parts.join("\n"),
|
package/src/schema/connection.ts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* Define external connections (Kafka, etc.) as TypeScript with full type safety
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
// Symbol for brand typing
|
|
7
|
-
|
|
6
|
+
// Symbol for brand typing - use Symbol.for() for global registry
|
|
7
|
+
// This ensures the same symbol is used across module instances
|
|
8
|
+
const CONNECTION_BRAND = Symbol.for("tinybird.connection");
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Kafka security protocol options
|
package/src/schema/datasource.ts
CHANGED
|
@@ -7,8 +7,9 @@ import type { AnyTypeValidator } from "./types.js";
|
|
|
7
7
|
import type { EngineConfig } from "./engines.js";
|
|
8
8
|
import type { KafkaConnectionDefinition } from "./connection.js";
|
|
9
9
|
|
|
10
|
-
// Symbol for brand typing
|
|
11
|
-
|
|
10
|
+
// Symbol for brand typing - use Symbol.for() for global registry
|
|
11
|
+
// This ensures the same symbol is used across module instances
|
|
12
|
+
const DATASOURCE_BRAND = Symbol.for("tinybird.datasource");
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* A column can be defined as just a type validator,
|
|
@@ -70,6 +71,11 @@ export interface DatasourceOptions<TSchema extends SchemaDefinition> {
|
|
|
70
71
|
* Defaults to true.
|
|
71
72
|
*/
|
|
72
73
|
jsonPaths?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Forward query used to evolve a datasource with incompatible schema changes.
|
|
76
|
+
* This should be the SELECT clause only (no FROM/WHERE).
|
|
77
|
+
*/
|
|
78
|
+
forwardQuery?: string;
|
|
73
79
|
/** Kafka ingestion configuration */
|
|
74
80
|
kafka?: KafkaConfig;
|
|
75
81
|
}
|
package/src/schema/params.ts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* Similar to the column type validators but for query parameters
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
// Symbol for brand typing
|
|
7
|
-
|
|
6
|
+
// Symbol for brand typing - use Symbol.for() for global registry
|
|
7
|
+
// This ensures the same symbol is used across module instances
|
|
8
|
+
const PARAM_BRAND = Symbol.for("tinybird.param");
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Base interface for parameter validators
|
package/src/schema/pipe.ts
CHANGED
|
@@ -9,10 +9,10 @@ import type { DatasourceDefinition, SchemaDefinition, ColumnDefinition } from ".
|
|
|
9
9
|
import { getColumnType } from "./datasource.js";
|
|
10
10
|
import { getTinybirdType } from "./types.js";
|
|
11
11
|
|
|
12
|
-
/** Symbol for brand typing pipes */
|
|
13
|
-
export const PIPE_BRAND
|
|
14
|
-
/** Symbol for brand typing nodes */
|
|
15
|
-
export const NODE_BRAND
|
|
12
|
+
/** Symbol for brand typing pipes - use Symbol.for() for global registry */
|
|
13
|
+
export const PIPE_BRAND = Symbol.for("tinybird.pipe");
|
|
14
|
+
/** Symbol for brand typing nodes - use Symbol.for() for global registry */
|
|
15
|
+
export const NODE_BRAND = Symbol.for("tinybird.node");
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Parameter definition for a pipe
|
package/src/schema/project.ts
CHANGED
|
@@ -11,8 +11,9 @@ import type { TinybirdClient } from "../client/base.js";
|
|
|
11
11
|
import type { QueryResult } from "../client/types.js";
|
|
12
12
|
import type { InferRow, InferParams, InferOutputRow } from "../infer/index.js";
|
|
13
13
|
|
|
14
|
-
// Symbol for brand typing
|
|
15
|
-
|
|
14
|
+
// Symbol for brand typing - use Symbol.for() for global registry
|
|
15
|
+
// This ensures the same symbol is used across module instances
|
|
16
|
+
const PROJECT_BRAND = Symbol.for("tinybird.project");
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Collection of datasource definitions
|
package/src/schema/types.ts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* Similar to Convex's `v.*` pattern, but for ClickHouse types
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
// Symbol for brand typing
|
|
7
|
-
|
|
6
|
+
// Symbol for brand typing - use Symbol.for() for global registry
|
|
7
|
+
// This ensures the same symbol is used across module instances
|
|
8
|
+
const VALIDATOR_BRAND = Symbol.for("tinybird.validator");
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Base interface for all type validators
|