@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.
Files changed (104) hide show
  1. package/dist/api/branches.d.ts.map +1 -1
  2. package/dist/api/branches.js +6 -5
  3. package/dist/api/branches.js.map +1 -1
  4. package/dist/api/branches.test.js +32 -6
  5. package/dist/api/branches.test.js.map +1 -1
  6. package/dist/api/build.d.ts.map +1 -1
  7. package/dist/api/build.js +2 -1
  8. package/dist/api/build.js.map +1 -1
  9. package/dist/api/deploy.d.ts +1 -0
  10. package/dist/api/deploy.d.ts.map +1 -1
  11. package/dist/api/deploy.js +27 -6
  12. package/dist/api/deploy.js.map +1 -1
  13. package/dist/api/deploy.test.js +6 -2
  14. package/dist/api/deploy.test.js.map +1 -1
  15. package/dist/api/fetcher.d.ts +6 -0
  16. package/dist/api/fetcher.d.ts.map +1 -0
  17. package/dist/api/fetcher.js +13 -0
  18. package/dist/api/fetcher.js.map +1 -0
  19. package/dist/api/local.d.ts.map +1 -1
  20. package/dist/api/local.js +5 -4
  21. package/dist/api/local.js.map +1 -1
  22. package/dist/api/local.test.js.map +1 -1
  23. package/dist/api/resources.d.ts +2 -0
  24. package/dist/api/resources.d.ts.map +1 -1
  25. package/dist/api/resources.js +6 -4
  26. package/dist/api/resources.js.map +1 -1
  27. package/dist/api/workspaces.d.ts.map +1 -1
  28. package/dist/api/workspaces.js +2 -1
  29. package/dist/api/workspaces.js.map +1 -1
  30. package/dist/api/workspaces.test.js +9 -1
  31. package/dist/api/workspaces.test.js.map +1 -1
  32. package/dist/cli/auth.d.ts.map +1 -1
  33. package/dist/cli/auth.js +2 -1
  34. package/dist/cli/auth.js.map +1 -1
  35. package/dist/cli/commands/deploy.d.ts +2 -0
  36. package/dist/cli/commands/deploy.d.ts.map +1 -1
  37. package/dist/cli/commands/deploy.js +3 -1
  38. package/dist/cli/commands/deploy.js.map +1 -1
  39. package/dist/cli/commands/init.d.ts +14 -0
  40. package/dist/cli/commands/init.d.ts.map +1 -1
  41. package/dist/cli/commands/init.js +264 -4
  42. package/dist/cli/commands/init.js.map +1 -1
  43. package/dist/cli/index.js +8 -3
  44. package/dist/cli/index.js.map +1 -1
  45. package/dist/client/base.d.ts.map +1 -1
  46. package/dist/client/base.js +2 -1
  47. package/dist/client/base.js.map +1 -1
  48. package/dist/codegen/index.d.ts.map +1 -1
  49. package/dist/codegen/index.js +4 -0
  50. package/dist/codegen/index.js.map +1 -1
  51. package/dist/codegen/index.test.js +10 -0
  52. package/dist/codegen/index.test.js.map +1 -1
  53. package/dist/generator/datasource.d.ts.map +1 -1
  54. package/dist/generator/datasource.js +20 -0
  55. package/dist/generator/datasource.js.map +1 -1
  56. package/dist/generator/datasource.test.js +11 -0
  57. package/dist/generator/datasource.test.js.map +1 -1
  58. package/dist/schema/connection.d.ts.map +1 -1
  59. package/dist/schema/connection.js +3 -2
  60. package/dist/schema/connection.js.map +1 -1
  61. package/dist/schema/datasource.d.ts +5 -0
  62. package/dist/schema/datasource.d.ts.map +1 -1
  63. package/dist/schema/datasource.js +3 -2
  64. package/dist/schema/datasource.js.map +1 -1
  65. package/dist/schema/params.d.ts.map +1 -1
  66. package/dist/schema/params.js +3 -2
  67. package/dist/schema/params.js.map +1 -1
  68. package/dist/schema/pipe.d.ts +2 -2
  69. package/dist/schema/pipe.d.ts.map +1 -1
  70. package/dist/schema/pipe.js +4 -4
  71. package/dist/schema/pipe.js.map +1 -1
  72. package/dist/schema/project.d.ts.map +1 -1
  73. package/dist/schema/project.js +3 -2
  74. package/dist/schema/project.js.map +1 -1
  75. package/dist/schema/types.d.ts.map +1 -1
  76. package/dist/schema/types.js +3 -2
  77. package/dist/schema/types.js.map +1 -1
  78. package/package.json +1 -1
  79. package/src/api/branches.test.ts +65 -57
  80. package/src/api/branches.ts +7 -5
  81. package/src/api/build.ts +2 -1
  82. package/src/api/deploy.test.ts +6 -2
  83. package/src/api/deploy.ts +35 -7
  84. package/src/api/fetcher.ts +17 -0
  85. package/src/api/local.test.ts +43 -31
  86. package/src/api/local.ts +5 -4
  87. package/src/api/resources.ts +9 -4
  88. package/src/api/workspaces.test.ts +15 -9
  89. package/src/api/workspaces.ts +3 -1
  90. package/src/cli/auth.ts +2 -1
  91. package/src/cli/commands/deploy.ts +6 -1
  92. package/src/cli/commands/init.ts +311 -6
  93. package/src/cli/index.ts +35 -11
  94. package/src/client/base.ts +3 -2
  95. package/src/codegen/index.test.ts +12 -0
  96. package/src/codegen/index.ts +5 -0
  97. package/src/generator/datasource.test.ts +13 -0
  98. package/src/generator/datasource.ts +24 -0
  99. package/src/schema/connection.ts +3 -2
  100. package/src/schema/datasource.ts +8 -2
  101. package/src/schema/params.ts +3 -2
  102. package/src/schema/pipe.ts +4 -4
  103. package/src/schema/project.ts +3 -2
  104. 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", () => {
@@ -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"),
@@ -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
- const CONNECTION_BRAND = Symbol("tinybird.connection");
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
@@ -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
- const DATASOURCE_BRAND = Symbol("tinybird.datasource");
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
  }
@@ -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
- const PARAM_BRAND = Symbol("tinybird.param");
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
@@ -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: unique symbol = Symbol("tinybird.pipe");
14
- /** Symbol for brand typing nodes */
15
- export const NODE_BRAND: unique symbol = Symbol("tinybird.node");
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
@@ -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
- const PROJECT_BRAND = Symbol("tinybird.project");
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
@@ -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
- const VALIDATOR_BRAND = Symbol("tinybird.validator");
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