@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.
- package/dist/api/api.d.ts +17 -1
- package/dist/api/api.d.ts.map +1 -1
- package/dist/api/api.js +91 -0
- package/dist/api/api.js.map +1 -1
- package/dist/api/api.test.js +160 -0
- package/dist/api/api.test.js.map +1 -1
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +2 -3
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/client/base.d.ts +26 -1
- package/dist/client/base.d.ts.map +1 -1
- package/dist/client/base.js +39 -0
- package/dist/client/base.js.map +1 -1
- package/dist/client/base.test.js +25 -0
- package/dist/client/base.test.js.map +1 -1
- package/dist/client/types.d.ts +49 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/schema/project.d.ts +22 -3
- package/dist/schema/project.d.ts.map +1 -1
- package/dist/schema/project.js +12 -0
- package/dist/schema/project.js.map +1 -1
- package/dist/schema/project.test.js +52 -0
- package/dist/schema/project.test.js.map +1 -1
- package/package.json +1 -1
- package/src/api/api.test.ts +222 -0
- package/src/api/api.ts +117 -0
- package/src/cli/commands/init.ts +5 -3
- package/src/client/base.test.ts +32 -0
- package/src/client/base.ts +48 -0
- package/src/client/types.ts +54 -0
- package/src/index.ts +5 -0
- package/src/schema/project.test.ts +64 -0
- package/src/schema/project.ts +42 -3
package/src/schema/project.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
|
|
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 {
|