@tinybirdco/sdk 0.0.36 → 0.0.37

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.
@@ -8,7 +8,7 @@ import type { PipeDefinition, ParamsDefinition, OutputDefinition } from "./pipe.
8
8
  import type { ConnectionDefinition } from "./connection.js";
9
9
  import { getEndpointConfig } from "./pipe.js";
10
10
  import type { TinybirdClient } from "../client/base.js";
11
- import type { QueryResult } from "../client/types.js";
11
+ import type { AppendOptions, AppendResult, QueryResult } from "../client/types.js";
12
12
  import type { InferRow, InferParams, InferOutputRow } from "../infer/index.js";
13
13
 
14
14
  // Symbol for brand typing - use Symbol.for() for global registry
@@ -72,9 +72,25 @@ type IngestMethods<T extends DatasourcesDefinition> = {
72
72
  };
73
73
 
74
74
  /**
75
- * Typed client interface for a project
75
+ * Type for a datasource accessor with append method
76
+ */
77
+ type DatasourceAccessor = {
78
+ /** Append data from a URL or file */
79
+ append(options: AppendOptions): Promise<AppendResult>;
80
+ };
81
+
82
+ /**
83
+ * Type for datasource accessors object
84
+ * Maps each datasource to an accessor with append method
76
85
  */
77
- export interface ProjectClient<
86
+ type DatasourceAccessors<T extends DatasourcesDefinition> = {
87
+ [K in keyof T]: DatasourceAccessor;
88
+ };
89
+
90
+ /**
91
+ * Base project client interface
92
+ */
93
+ interface ProjectClientBase<
78
94
  TDatasources extends DatasourcesDefinition,
79
95
  TPipes extends PipesDefinition
80
96
  > {
@@ -86,6 +102,15 @@ export interface ProjectClient<
86
102
  readonly client: TinybirdClient;
87
103
  }
88
104
 
105
+ /**
106
+ * Typed client interface for a project
107
+ * Includes datasource accessors as top-level properties
108
+ */
109
+ export type ProjectClient<
110
+ TDatasources extends DatasourcesDefinition,
111
+ TPipes extends PipesDefinition
112
+ > = ProjectClientBase<TDatasources, TPipes> & DatasourceAccessors<TDatasources>;
113
+
89
114
  /**
90
115
  * Configuration for createTinybirdClient
91
116
  */
@@ -294,8 +319,22 @@ function buildProjectClient<
294
319
  };
295
320
  }
296
321
 
322
+ // Build datasource accessors for top-level access
323
+ const datasourceAccessors: Record<string, DatasourceAccessor> = {};
324
+ for (const [name, datasource] of Object.entries(datasources)) {
325
+ const tinybirdName = datasource._name;
326
+
327
+ datasourceAccessors[name] = {
328
+ append: async (options: AppendOptions) => {
329
+ const client = await getClient();
330
+ return client.datasources.append(tinybirdName, options);
331
+ },
332
+ };
333
+ }
334
+
297
335
  // Create the typed client object
298
336
  return {
337
+ ...datasourceAccessors,
299
338
  query: queryMethods,
300
339
  ingest: ingestMethods,
301
340
  get client(): TinybirdClient {