@tinybirdco/sdk 0.0.39 → 0.0.40

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 (36) hide show
  1. package/README.md +3 -2
  2. package/dist/cli/commands/dev.d.ts.map +1 -1
  3. package/dist/cli/commands/dev.js +4 -9
  4. package/dist/cli/commands/dev.js.map +1 -1
  5. package/dist/cli/commands/init.d.ts +12 -0
  6. package/dist/cli/commands/init.d.ts.map +1 -1
  7. package/dist/cli/commands/init.js +217 -2
  8. package/dist/cli/commands/init.js.map +1 -1
  9. package/dist/cli/commands/init.test.js +15 -0
  10. package/dist/cli/commands/init.test.js.map +1 -1
  11. package/dist/cli/config-types.d.ts +1 -1
  12. package/dist/cli/config-types.d.ts.map +1 -1
  13. package/dist/cli/config.d.ts +1 -1
  14. package/dist/cli/config.d.ts.map +1 -1
  15. package/dist/generator/include-paths.d.ts +7 -0
  16. package/dist/generator/include-paths.d.ts.map +1 -0
  17. package/dist/generator/include-paths.js +164 -0
  18. package/dist/generator/include-paths.js.map +1 -0
  19. package/dist/generator/index.d.ts +1 -1
  20. package/dist/generator/index.d.ts.map +1 -1
  21. package/dist/generator/index.test.js +36 -0
  22. package/dist/generator/index.test.js.map +1 -1
  23. package/dist/generator/loader.d.ts +1 -1
  24. package/dist/generator/loader.d.ts.map +1 -1
  25. package/dist/generator/loader.js +5 -8
  26. package/dist/generator/loader.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/cli/commands/dev.ts +4 -9
  29. package/src/cli/commands/init.test.ts +17 -0
  30. package/src/cli/commands/init.ts +300 -2
  31. package/src/cli/config-types.ts +1 -1
  32. package/src/cli/config.ts +1 -1
  33. package/src/generator/include-paths.ts +234 -0
  34. package/src/generator/index.test.ts +44 -0
  35. package/src/generator/index.ts +1 -1
  36. package/src/generator/loader.ts +6 -10
@@ -325,5 +325,49 @@ TYPE endpoint
325
325
  expect(rawPipe).toBeDefined();
326
326
  expect(rawPipe!.content).toBe(rawPipeContent);
327
327
  });
328
+
329
+ it("supports glob include patterns", async () => {
330
+ const nestedDir = path.join(tempDir, "tinybird", "legacy");
331
+ fs.mkdirSync(nestedDir, { recursive: true });
332
+
333
+ const datasourceContent = `SCHEMA >
334
+ id String
335
+
336
+ ENGINE "MergeTree"
337
+ ENGINE_SORTING_KEY "id"
338
+ `;
339
+ const datasourcePath = path.join(nestedDir, "events.datasource");
340
+ fs.writeFileSync(datasourcePath, datasourceContent);
341
+
342
+ const pipeContent = `NODE endpoint
343
+ SQL >
344
+ SELECT * FROM events
345
+
346
+ TYPE endpoint
347
+ `;
348
+ const pipePath = path.join(nestedDir, "events.pipe");
349
+ fs.writeFileSync(pipePath, pipeContent);
350
+
351
+ const result = await buildFromInclude({
352
+ includePaths: ["tinybird/**/*.datasource", "tinybird/**/*.pipe"],
353
+ cwd: tempDir,
354
+ });
355
+
356
+ expect(result.resources.datasources).toHaveLength(1);
357
+ expect(result.resources.datasources[0].name).toBe("events");
358
+ expect(result.resources.datasources[0].content).toBe(datasourceContent);
359
+ expect(result.resources.pipes).toHaveLength(1);
360
+ expect(result.resources.pipes[0].name).toBe("events");
361
+ expect(result.resources.pipes[0].content).toBe(pipeContent);
362
+ });
363
+
364
+ it("throws when include glob matches no files", async () => {
365
+ await expect(
366
+ buildFromInclude({
367
+ includePaths: ["tinybird/**/*.datasource"],
368
+ cwd: tempDir,
369
+ })
370
+ ).rejects.toThrow("Include pattern matched no files");
371
+ });
328
372
  });
329
373
  });
@@ -122,7 +122,7 @@ export async function build(options: BuildOptions): Promise<BuildResult> {
122
122
  * Build options using include paths
123
123
  */
124
124
  export interface BuildFromIncludeOptions {
125
- /** Array of file paths to scan for datasources and pipes */
125
+ /** Array of file paths or glob patterns to scan for datasources and pipes */
126
126
  includePaths: string[];
127
127
  /** Working directory (defaults to cwd) */
128
128
  cwd?: string;
@@ -11,6 +11,7 @@ import { isProjectDefinition, type ProjectDefinition, type DatasourcesDefinition
11
11
  import { isDatasourceDefinition, type DatasourceDefinition } from "../schema/datasource.js";
12
12
  import { isPipeDefinition, type PipeDefinition } from "../schema/pipe.js";
13
13
  import { isConnectionDefinition, type ConnectionDefinition } from "../schema/connection.js";
14
+ import { resolveIncludeFiles } from "./include-paths.js";
14
15
 
15
16
  /**
16
17
  * Result of loading a schema file
@@ -184,7 +185,7 @@ export interface LoadedEntities {
184
185
  * Options for loading entities
185
186
  */
186
187
  export interface LoadEntitiesOptions {
187
- /** Array of file paths to scan (can be relative or absolute) */
188
+ /** Array of file paths or glob patterns to scan (can be relative or absolute) */
188
189
  includePaths: string[];
189
190
  /** The working directory for resolution (defaults to cwd) */
190
191
  cwd?: string;
@@ -211,6 +212,7 @@ export interface LoadEntitiesOptions {
211
212
  */
212
213
  export async function loadEntities(options: LoadEntitiesOptions): Promise<LoadedEntities> {
213
214
  const cwd = options.cwd ?? process.cwd();
215
+ const includeFiles = resolveIncludeFiles(options.includePaths, cwd);
214
216
  const result: LoadedEntities = {
215
217
  datasources: {},
216
218
  pipes: {},
@@ -220,15 +222,9 @@ export async function loadEntities(options: LoadEntitiesOptions): Promise<Loaded
220
222
  sourceFiles: [],
221
223
  };
222
224
 
223
- for (const includePath of options.includePaths) {
224
- const absolutePath = path.isAbsolute(includePath)
225
- ? includePath
226
- : path.resolve(cwd, includePath);
227
-
228
- // Verify the file exists
229
- if (!fs.existsSync(absolutePath)) {
230
- throw new Error(`Include file not found: ${absolutePath}`);
231
- }
225
+ for (const includeFile of includeFiles) {
226
+ const includePath = includeFile.sourcePath;
227
+ const absolutePath = includeFile.absolutePath;
232
228
 
233
229
  result.sourceFiles.push(includePath);
234
230