@tinybirdco/sdk 0.0.49 → 0.0.51

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 (82) hide show
  1. package/README.md +19 -2
  2. package/dist/cli/commands/migrate.d.ts.map +1 -1
  3. package/dist/cli/commands/migrate.js +36 -1
  4. package/dist/cli/commands/migrate.js.map +1 -1
  5. package/dist/cli/commands/migrate.test.js +307 -2
  6. package/dist/cli/commands/migrate.test.js.map +1 -1
  7. package/dist/codegen/type-mapper.d.ts.map +1 -1
  8. package/dist/codegen/type-mapper.js +70 -7
  9. package/dist/codegen/type-mapper.js.map +1 -1
  10. package/dist/codegen/type-mapper.test.js +9 -0
  11. package/dist/codegen/type-mapper.test.js.map +1 -1
  12. package/dist/generator/connection.d.ts.map +1 -1
  13. package/dist/generator/connection.js +14 -1
  14. package/dist/generator/connection.js.map +1 -1
  15. package/dist/generator/connection.test.js +20 -4
  16. package/dist/generator/connection.test.js.map +1 -1
  17. package/dist/generator/datasource.d.ts.map +1 -1
  18. package/dist/generator/datasource.js +39 -10
  19. package/dist/generator/datasource.js.map +1 -1
  20. package/dist/generator/datasource.test.js +42 -1
  21. package/dist/generator/datasource.test.js.map +1 -1
  22. package/dist/generator/pipe.d.ts.map +1 -1
  23. package/dist/generator/pipe.js +92 -3
  24. package/dist/generator/pipe.js.map +1 -1
  25. package/dist/generator/pipe.test.js +19 -0
  26. package/dist/generator/pipe.test.js.map +1 -1
  27. package/dist/index.d.ts +3 -3
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/migrate/emit-ts.d.ts.map +1 -1
  32. package/dist/migrate/emit-ts.js +56 -11
  33. package/dist/migrate/emit-ts.js.map +1 -1
  34. package/dist/migrate/parse-connection.d.ts +2 -2
  35. package/dist/migrate/parse-connection.d.ts.map +1 -1
  36. package/dist/migrate/parse-connection.js +34 -4
  37. package/dist/migrate/parse-connection.js.map +1 -1
  38. package/dist/migrate/parse-datasource.d.ts.map +1 -1
  39. package/dist/migrate/parse-datasource.js +39 -2
  40. package/dist/migrate/parse-datasource.js.map +1 -1
  41. package/dist/migrate/parse-pipe.d.ts.map +1 -1
  42. package/dist/migrate/parse-pipe.js +212 -93
  43. package/dist/migrate/parse-pipe.js.map +1 -1
  44. package/dist/migrate/parser-utils.d.ts.map +1 -1
  45. package/dist/migrate/parser-utils.js +3 -1
  46. package/dist/migrate/parser-utils.js.map +1 -1
  47. package/dist/migrate/types.d.ts +22 -1
  48. package/dist/migrate/types.d.ts.map +1 -1
  49. package/dist/schema/connection.d.ts +34 -1
  50. package/dist/schema/connection.d.ts.map +1 -1
  51. package/dist/schema/connection.js +26 -0
  52. package/dist/schema/connection.js.map +1 -1
  53. package/dist/schema/connection.test.js +35 -1
  54. package/dist/schema/connection.test.js.map +1 -1
  55. package/dist/schema/datasource.d.ts +32 -1
  56. package/dist/schema/datasource.d.ts.map +1 -1
  57. package/dist/schema/datasource.js +19 -2
  58. package/dist/schema/datasource.js.map +1 -1
  59. package/dist/schema/datasource.test.js +71 -3
  60. package/dist/schema/datasource.test.js.map +1 -1
  61. package/package.json +1 -1
  62. package/src/cli/commands/migrate.test.ts +448 -2
  63. package/src/cli/commands/migrate.ts +39 -1
  64. package/src/codegen/type-mapper.test.ts +18 -0
  65. package/src/codegen/type-mapper.ts +79 -7
  66. package/src/generator/connection.test.ts +29 -4
  67. package/src/generator/connection.ts +25 -2
  68. package/src/generator/datasource.test.ts +52 -1
  69. package/src/generator/datasource.ts +47 -10
  70. package/src/generator/pipe.test.ts +21 -0
  71. package/src/generator/pipe.ts +119 -3
  72. package/src/index.ts +6 -0
  73. package/src/migrate/emit-ts.ts +67 -14
  74. package/src/migrate/parse-connection.ts +56 -6
  75. package/src/migrate/parse-datasource.ts +74 -3
  76. package/src/migrate/parse-pipe.ts +250 -111
  77. package/src/migrate/parser-utils.ts +5 -1
  78. package/src/migrate/types.ts +26 -1
  79. package/src/schema/connection.test.ts +48 -0
  80. package/src/schema/connection.ts +60 -1
  81. package/src/schema/datasource.test.ts +91 -3
  82. package/src/schema/datasource.ts +62 -3
@@ -1,4 +1,9 @@
1
- import type { KafkaConnectionModel, ResourceFile, S3ConnectionModel } from "./types.js";
1
+ import type {
2
+ GCSConnectionModel,
3
+ KafkaConnectionModel,
4
+ ResourceFile,
5
+ S3ConnectionModel,
6
+ } from "./types.js";
2
7
  import {
3
8
  MigrationParseError,
4
9
  isBlank,
@@ -9,7 +14,7 @@ import {
9
14
 
10
15
  export function parseConnectionFile(
11
16
  resource: ResourceFile
12
- ): KafkaConnectionModel | S3ConnectionModel {
17
+ ): KafkaConnectionModel | S3ConnectionModel | GCSConnectionModel {
13
18
  const lines = splitLines(resource.content);
14
19
  let connectionType: string | undefined;
15
20
 
@@ -34,6 +39,7 @@ export function parseConnectionFile(
34
39
  let arn: string | undefined;
35
40
  let accessKey: string | undefined;
36
41
  let accessSecret: string | undefined;
42
+ let serviceAccountCredentialsJson: string | undefined;
37
43
 
38
44
  for (const rawLine of lines) {
39
45
  const line = rawLine.trim();
@@ -100,6 +106,9 @@ export function parseConnectionFile(
100
106
  case "S3_SECRET":
101
107
  accessSecret = parseQuotedValue(value);
102
108
  break;
109
+ case "GCS_SERVICE_ACCOUNT_CREDENTIALS_JSON":
110
+ serviceAccountCredentialsJson = parseQuotedValue(value);
111
+ break;
103
112
  default:
104
113
  throw new MigrationParseError(
105
114
  resource.filePath,
@@ -120,12 +129,12 @@ export function parseConnectionFile(
120
129
  }
121
130
 
122
131
  if (connectionType === "kafka") {
123
- if (region || arn || accessKey || accessSecret) {
132
+ if (region || arn || accessKey || accessSecret || serviceAccountCredentialsJson) {
124
133
  throw new MigrationParseError(
125
134
  resource.filePath,
126
135
  "connection",
127
136
  resource.name,
128
- "S3 directives are not valid for kafka connections."
137
+ "S3/GCS directives are not valid for kafka connections."
129
138
  );
130
139
  }
131
140
 
@@ -161,13 +170,14 @@ export function parseConnectionFile(
161
170
  key ||
162
171
  secret ||
163
172
  schemaRegistryUrl ||
164
- sslCaPem
173
+ sslCaPem ||
174
+ serviceAccountCredentialsJson
165
175
  ) {
166
176
  throw new MigrationParseError(
167
177
  resource.filePath,
168
178
  "connection",
169
179
  resource.name,
170
- "Kafka directives are not valid for s3 connections."
180
+ "Kafka/GCS directives are not valid for s3 connections."
171
181
  );
172
182
  }
173
183
 
@@ -210,6 +220,46 @@ export function parseConnectionFile(
210
220
  };
211
221
  }
212
222
 
223
+ if (connectionType === "gcs") {
224
+ if (
225
+ bootstrapServers ||
226
+ securityProtocol ||
227
+ saslMechanism ||
228
+ key ||
229
+ secret ||
230
+ schemaRegistryUrl ||
231
+ sslCaPem ||
232
+ region ||
233
+ arn ||
234
+ accessKey ||
235
+ accessSecret
236
+ ) {
237
+ throw new MigrationParseError(
238
+ resource.filePath,
239
+ "connection",
240
+ resource.name,
241
+ "Kafka/S3 directives are not valid for gcs connections."
242
+ );
243
+ }
244
+
245
+ if (!serviceAccountCredentialsJson) {
246
+ throw new MigrationParseError(
247
+ resource.filePath,
248
+ "connection",
249
+ resource.name,
250
+ "GCS_SERVICE_ACCOUNT_CREDENTIALS_JSON is required for gcs connections."
251
+ );
252
+ }
253
+
254
+ return {
255
+ kind: "connection",
256
+ name: resource.name,
257
+ filePath: resource.filePath,
258
+ connectionType: "gcs",
259
+ serviceAccountCredentialsJson,
260
+ };
261
+ }
262
+
213
263
  throw new MigrationParseError(
214
264
  resource.filePath,
215
265
  "connection",
@@ -1,4 +1,9 @@
1
- import type { DatasourceModel, DatasourceTokenModel, ResourceFile } from "./types.js";
1
+ import type {
2
+ DatasourceIndexModel,
3
+ DatasourceModel,
4
+ DatasourceTokenModel,
5
+ ResourceFile,
6
+ } from "./types.js";
2
7
  import {
3
8
  MigrationParseError,
4
9
  isBlank,
@@ -14,6 +19,7 @@ const DATASOURCE_DIRECTIVES = new Set([
14
19
  "DESCRIPTION",
15
20
  "SCHEMA",
16
21
  "FORWARD_QUERY",
22
+ "INDEXES",
17
23
  "SHARED_WITH",
18
24
  "ENGINE",
19
25
  "ENGINE_SORTING_KEY",
@@ -241,9 +247,53 @@ function parseToken(filePath: string, resourceName: string, value: string): Data
241
247
  return { name, scope };
242
248
  }
243
249
 
250
+ function parseIndexLine(
251
+ filePath: string,
252
+ resourceName: string,
253
+ rawLine: string
254
+ ): DatasourceIndexModel {
255
+ const line = rawLine.trim().replace(/,$/, "");
256
+ if (!line) {
257
+ throw new MigrationParseError(
258
+ filePath,
259
+ "datasource",
260
+ resourceName,
261
+ "Empty INDEXES line."
262
+ );
263
+ }
264
+
265
+ const match = line.match(/^(\S+)\s+(.+?)\s+TYPE\s+(.+?)\s+GRANULARITY\s+(\d+)$/i);
266
+ if (!match) {
267
+ throw new MigrationParseError(
268
+ filePath,
269
+ "datasource",
270
+ resourceName,
271
+ `Invalid INDEXES definition: "${rawLine}"`
272
+ );
273
+ }
274
+
275
+ const granularity = Number(match[4]);
276
+ if (!Number.isInteger(granularity) || granularity <= 0) {
277
+ throw new MigrationParseError(
278
+ filePath,
279
+ "datasource",
280
+ resourceName,
281
+ `Invalid INDEXES GRANULARITY value: "${match[4]}"`
282
+ );
283
+ }
284
+
285
+ return {
286
+ name: match[1],
287
+ expr: match[2].trim(),
288
+ type: match[3].trim(),
289
+ granularity,
290
+ };
291
+ }
292
+
244
293
  export function parseDatasourceFile(resource: ResourceFile): DatasourceModel {
245
294
  const lines = splitLines(resource.content);
246
295
  const columns = [];
296
+ const indexes: DatasourceIndexModel[] = [];
247
297
  const tokens: DatasourceTokenModel[] = [];
248
298
  const sharedWith: string[] = [];
249
299
  let description: string | undefined;
@@ -323,6 +373,26 @@ export function parseDatasourceFile(resource: ResourceFile): DatasourceModel {
323
373
  continue;
324
374
  }
325
375
 
376
+ if (line === "INDEXES >") {
377
+ const block = readDirectiveBlock(lines, i + 1, isDatasourceDirectiveLine);
378
+ if (block.lines.length === 0) {
379
+ throw new MigrationParseError(
380
+ resource.filePath,
381
+ "datasource",
382
+ resource.name,
383
+ "INDEXES block is empty."
384
+ );
385
+ }
386
+ for (const indexLine of block.lines) {
387
+ if (isBlank(indexLine) || indexLine.trim().startsWith("#")) {
388
+ continue;
389
+ }
390
+ indexes.push(parseIndexLine(resource.filePath, resource.name, indexLine));
391
+ }
392
+ i = block.nextIndex;
393
+ continue;
394
+ }
395
+
326
396
  if (line === "SHARED_WITH >") {
327
397
  const block = readDirectiveBlock(lines, i + 1, isDatasourceDirectiveLine);
328
398
  for (const sharedLine of block.lines) {
@@ -518,7 +588,7 @@ export function parseDatasourceFile(resource: ResourceFile): DatasourceModel {
518
588
  resource.filePath,
519
589
  "datasource",
520
590
  resource.name,
521
- "IMPORT_CONNECTION_NAME and IMPORT_BUCKET_URI are required when S3 import directives are used."
591
+ "IMPORT_CONNECTION_NAME and IMPORT_BUCKET_URI are required when import directives are used."
522
592
  );
523
593
  }
524
594
 
@@ -527,7 +597,7 @@ export function parseDatasourceFile(resource: ResourceFile): DatasourceModel {
527
597
  resource.filePath,
528
598
  "datasource",
529
599
  resource.name,
530
- "Datasource cannot mix Kafka directives with S3 import directives."
600
+ "Datasource cannot mix Kafka directives with import directives."
531
601
  );
532
602
  }
533
603
 
@@ -552,6 +622,7 @@ export function parseDatasourceFile(resource: ResourceFile): DatasourceModel {
552
622
  settings,
553
623
  }
554
624
  : undefined,
625
+ indexes,
555
626
  kafka,
556
627
  s3,
557
628
  forwardQuery,