@tinybirdco/sdk 0.0.2 → 0.0.3
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/build.d.ts +2 -0
- package/dist/api/build.d.ts.map +1 -1
- package/dist/api/build.js +13 -0
- package/dist/api/build.js.map +1 -1
- package/dist/api/build.test.js +1 -0
- package/dist/api/build.test.js.map +1 -1
- package/dist/api/deploy.d.ts.map +1 -1
- package/dist/api/deploy.js +3 -0
- package/dist/api/deploy.js.map +1 -1
- package/dist/api/deploy.test.js +1 -0
- package/dist/api/deploy.test.js.map +1 -1
- package/dist/generator/connection.d.ts +49 -0
- package/dist/generator/connection.d.ts.map +1 -0
- package/dist/generator/connection.js +78 -0
- package/dist/generator/connection.js.map +1 -0
- package/dist/generator/connection.test.d.ts +2 -0
- package/dist/generator/connection.test.d.ts.map +1 -0
- package/dist/generator/connection.test.js +106 -0
- package/dist/generator/connection.test.js.map +1 -0
- package/dist/generator/datasource.d.ts.map +1 -1
- package/dist/generator/datasource.js +20 -0
- package/dist/generator/datasource.js.map +1 -1
- package/dist/generator/datasource.test.js +92 -0
- package/dist/generator/datasource.test.js.map +1 -1
- package/dist/generator/index.d.ts +8 -2
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +10 -3
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/loader.d.ts +8 -1
- package/dist/generator/loader.d.ts.map +1 -1
- package/dist/generator/loader.js +17 -2
- package/dist/generator/loader.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/schema/connection.d.ts +83 -0
- package/dist/schema/connection.d.ts.map +1 -0
- package/dist/schema/connection.js +61 -0
- package/dist/schema/connection.js.map +1 -0
- package/dist/schema/connection.test.d.ts +2 -0
- package/dist/schema/connection.test.d.ts.map +1 -0
- package/dist/schema/connection.test.js +117 -0
- package/dist/schema/connection.test.js.map +1 -0
- package/dist/schema/datasource.d.ts +16 -0
- package/dist/schema/datasource.d.ts.map +1 -1
- package/dist/schema/datasource.js.map +1 -1
- package/dist/schema/project.d.ts +12 -3
- package/dist/schema/project.d.ts.map +1 -1
- package/dist/schema/project.js +2 -0
- package/dist/schema/project.js.map +1 -1
- package/package.json +1 -1
- package/src/api/build.test.ts +1 -0
- package/src/api/build.ts +20 -0
- package/src/api/deploy.test.ts +1 -0
- package/src/api/deploy.ts +3 -0
- package/src/generator/connection.test.ts +135 -0
- package/src/generator/connection.ts +104 -0
- package/src/generator/datasource.test.ts +108 -0
- package/src/generator/datasource.ts +27 -1
- package/src/generator/index.ts +16 -4
- package/src/generator/loader.ts +21 -3
- package/src/index.ts +12 -0
- package/src/schema/connection.test.ts +149 -0
- package/src/schema/connection.ts +123 -0
- package/src/schema/datasource.ts +17 -0
- package/src/schema/project.ts +20 -5
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection definition for Tinybird
|
|
3
|
+
* Define external connections (Kafka, etc.) as TypeScript with full type safety
|
|
4
|
+
*/
|
|
5
|
+
// Symbol for brand typing
|
|
6
|
+
const CONNECTION_BRAND = Symbol("tinybird.connection");
|
|
7
|
+
/**
|
|
8
|
+
* Create a Kafka connection
|
|
9
|
+
*
|
|
10
|
+
* @param name - The connection name (must be valid identifier)
|
|
11
|
+
* @param options - Kafka connection configuration
|
|
12
|
+
* @returns A connection definition that can be used in a project
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { createKafkaConnection } from '@tinybirdco/sdk';
|
|
17
|
+
*
|
|
18
|
+
* export const myKafka = createKafkaConnection('my_kafka', {
|
|
19
|
+
* bootstrapServers: 'kafka.example.com:9092',
|
|
20
|
+
* securityProtocol: 'SASL_SSL',
|
|
21
|
+
* saslMechanism: 'PLAIN',
|
|
22
|
+
* key: '{{ tb_secret("KAFKA_KEY") }}',
|
|
23
|
+
* secret: '{{ tb_secret("KAFKA_SECRET") }}',
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function createKafkaConnection(name, options) {
|
|
28
|
+
// Validate name is a valid identifier
|
|
29
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
|
|
30
|
+
throw new Error(`Invalid connection name: "${name}". Must start with a letter or underscore and contain only alphanumeric characters and underscores.`);
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
[CONNECTION_BRAND]: true,
|
|
34
|
+
_name: name,
|
|
35
|
+
_type: "connection",
|
|
36
|
+
_connectionType: "kafka",
|
|
37
|
+
options,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if a value is a connection definition
|
|
42
|
+
*/
|
|
43
|
+
export function isConnectionDefinition(value) {
|
|
44
|
+
return (typeof value === "object" &&
|
|
45
|
+
value !== null &&
|
|
46
|
+
CONNECTION_BRAND in value &&
|
|
47
|
+
value[CONNECTION_BRAND] === true);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if a value is a Kafka connection definition
|
|
51
|
+
*/
|
|
52
|
+
export function isKafkaConnectionDefinition(value) {
|
|
53
|
+
return isConnectionDefinition(value) && value._connectionType === "kafka";
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get the connection type from a connection definition
|
|
57
|
+
*/
|
|
58
|
+
export function getConnectionType(connection) {
|
|
59
|
+
return connection._connectionType;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/schema/connection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0BAA0B;AAC1B,MAAM,gBAAgB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAkDvD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,qBAAqB,CACnC,IAAY,EACZ,OAA+B;IAE/B,sCAAsC;IACtC,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CACb,6BAA6B,IAAI,qGAAqG,CACvI,CAAC;IACJ,CAAC;IAED,OAAO;QACL,CAAC,gBAAgB,CAAC,EAAE,IAAI;QACxB,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,YAAY;QACnB,eAAe,EAAE,OAAO;QACxB,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,gBAAgB,IAAI,KAAK;QACxB,KAAiC,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAC9D,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,KAAc;IACxD,OAAO,sBAAsB,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,eAAe,KAAK,OAAO,CAAC;AAC5E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAa;IAEb,OAAO,UAAU,CAAC,eAAe,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.test.d.ts","sourceRoot":"","sources":["../../src/schema/connection.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { createKafkaConnection, isConnectionDefinition, isKafkaConnectionDefinition, getConnectionType, } from "./connection.js";
|
|
3
|
+
describe("Connection Schema", () => {
|
|
4
|
+
describe("createKafkaConnection", () => {
|
|
5
|
+
it("creates a Kafka connection with required fields", () => {
|
|
6
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
7
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
8
|
+
});
|
|
9
|
+
expect(conn._name).toBe("my_kafka");
|
|
10
|
+
expect(conn._type).toBe("connection");
|
|
11
|
+
expect(conn._connectionType).toBe("kafka");
|
|
12
|
+
expect(conn.options.bootstrapServers).toBe("kafka.example.com:9092");
|
|
13
|
+
});
|
|
14
|
+
it("creates a Kafka connection with all options", () => {
|
|
15
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
16
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
17
|
+
securityProtocol: "SASL_SSL",
|
|
18
|
+
saslMechanism: "PLAIN",
|
|
19
|
+
key: '{{ tb_secret("KAFKA_KEY") }}',
|
|
20
|
+
secret: '{{ tb_secret("KAFKA_SECRET") }}',
|
|
21
|
+
sslCaPem: '{{ tb_secret("KAFKA_CA_CERT") }}',
|
|
22
|
+
});
|
|
23
|
+
expect(conn.options.securityProtocol).toBe("SASL_SSL");
|
|
24
|
+
expect(conn.options.saslMechanism).toBe("PLAIN");
|
|
25
|
+
expect(conn.options.key).toBe('{{ tb_secret("KAFKA_KEY") }}');
|
|
26
|
+
expect(conn.options.secret).toBe('{{ tb_secret("KAFKA_SECRET") }}');
|
|
27
|
+
expect(conn.options.sslCaPem).toBe('{{ tb_secret("KAFKA_CA_CERT") }}');
|
|
28
|
+
});
|
|
29
|
+
it("supports different SASL mechanisms", () => {
|
|
30
|
+
const scramConn = createKafkaConnection("scram_kafka", {
|
|
31
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
32
|
+
saslMechanism: "SCRAM-SHA-256",
|
|
33
|
+
});
|
|
34
|
+
expect(scramConn.options.saslMechanism).toBe("SCRAM-SHA-256");
|
|
35
|
+
const scram512Conn = createKafkaConnection("scram512_kafka", {
|
|
36
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
37
|
+
saslMechanism: "SCRAM-SHA-512",
|
|
38
|
+
});
|
|
39
|
+
expect(scram512Conn.options.saslMechanism).toBe("SCRAM-SHA-512");
|
|
40
|
+
const oauthConn = createKafkaConnection("oauth_kafka", {
|
|
41
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
42
|
+
saslMechanism: "OAUTHBEARER",
|
|
43
|
+
});
|
|
44
|
+
expect(oauthConn.options.saslMechanism).toBe("OAUTHBEARER");
|
|
45
|
+
});
|
|
46
|
+
it("supports different security protocols", () => {
|
|
47
|
+
const plaintext = createKafkaConnection("plaintext_kafka", {
|
|
48
|
+
bootstrapServers: "localhost:9092",
|
|
49
|
+
securityProtocol: "PLAINTEXT",
|
|
50
|
+
});
|
|
51
|
+
expect(plaintext.options.securityProtocol).toBe("PLAINTEXT");
|
|
52
|
+
const saslPlaintext = createKafkaConnection("sasl_plaintext_kafka", {
|
|
53
|
+
bootstrapServers: "localhost:9092",
|
|
54
|
+
securityProtocol: "SASL_PLAINTEXT",
|
|
55
|
+
});
|
|
56
|
+
expect(saslPlaintext.options.securityProtocol).toBe("SASL_PLAINTEXT");
|
|
57
|
+
});
|
|
58
|
+
it("throws error for invalid connection name", () => {
|
|
59
|
+
expect(() => createKafkaConnection("123invalid", {
|
|
60
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
61
|
+
})).toThrow("Invalid connection name");
|
|
62
|
+
expect(() => createKafkaConnection("my-connection", {
|
|
63
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
64
|
+
})).toThrow("Invalid connection name");
|
|
65
|
+
expect(() => createKafkaConnection("", {
|
|
66
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
67
|
+
})).toThrow("Invalid connection name");
|
|
68
|
+
});
|
|
69
|
+
it("allows valid naming patterns", () => {
|
|
70
|
+
const conn1 = createKafkaConnection("_private_kafka", {
|
|
71
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
72
|
+
});
|
|
73
|
+
expect(conn1._name).toBe("_private_kafka");
|
|
74
|
+
const conn2 = createKafkaConnection("kafka_v2", {
|
|
75
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
76
|
+
});
|
|
77
|
+
expect(conn2._name).toBe("kafka_v2");
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe("isConnectionDefinition", () => {
|
|
81
|
+
it("returns true for valid connection", () => {
|
|
82
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
83
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
84
|
+
});
|
|
85
|
+
expect(isConnectionDefinition(conn)).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
it("returns false for non-connection objects", () => {
|
|
88
|
+
expect(isConnectionDefinition({})).toBe(false);
|
|
89
|
+
expect(isConnectionDefinition(null)).toBe(false);
|
|
90
|
+
expect(isConnectionDefinition(undefined)).toBe(false);
|
|
91
|
+
expect(isConnectionDefinition("string")).toBe(false);
|
|
92
|
+
expect(isConnectionDefinition(123)).toBe(false);
|
|
93
|
+
expect(isConnectionDefinition({ _name: "test" })).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe("isKafkaConnectionDefinition", () => {
|
|
97
|
+
it("returns true for Kafka connection", () => {
|
|
98
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
99
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
100
|
+
});
|
|
101
|
+
expect(isKafkaConnectionDefinition(conn)).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
it("returns false for non-Kafka objects", () => {
|
|
104
|
+
expect(isKafkaConnectionDefinition({})).toBe(false);
|
|
105
|
+
expect(isKafkaConnectionDefinition(null)).toBe(false);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
describe("getConnectionType", () => {
|
|
109
|
+
it("returns the connection type", () => {
|
|
110
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
111
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
112
|
+
});
|
|
113
|
+
expect(getConnectionType(conn)).toBe("kafka");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=connection.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.test.js","sourceRoot":"","sources":["../../src/schema/connection.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C,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;YAC7C,MAAM,CAAC,2BAA2B,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpD,MAAM,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACjC,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;YACrC,MAAM,IAAI,GAAG,qBAAqB,CAAC,UAAU,EAAE;gBAC7C,gBAAgB,EAAE,wBAAwB;aAC3C,CAAC,CAAC;YAEH,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { AnyTypeValidator } from "./types.js";
|
|
6
6
|
import type { EngineConfig } from "./engines.js";
|
|
7
|
+
import type { KafkaConnectionDefinition } from "./connection.js";
|
|
7
8
|
declare const DATASOURCE_BRAND: unique symbol;
|
|
8
9
|
/**
|
|
9
10
|
* A column can be defined as just a type validator,
|
|
@@ -28,6 +29,19 @@ export interface TokenConfig {
|
|
|
28
29
|
/** Permissions granted to this token */
|
|
29
30
|
permissions: readonly ("READ" | "APPEND")[];
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Kafka ingestion configuration for a datasource
|
|
34
|
+
*/
|
|
35
|
+
export interface KafkaConfig {
|
|
36
|
+
/** Kafka connection to use */
|
|
37
|
+
connection: KafkaConnectionDefinition;
|
|
38
|
+
/** Kafka topic to consume from */
|
|
39
|
+
topic: string;
|
|
40
|
+
/** Consumer group ID (optional) */
|
|
41
|
+
groupId?: string;
|
|
42
|
+
/** Where to start reading: 'earliest' or 'latest' (default: 'latest') */
|
|
43
|
+
autoOffsetReset?: "earliest" | "latest";
|
|
44
|
+
}
|
|
31
45
|
/**
|
|
32
46
|
* Options for defining a datasource
|
|
33
47
|
*/
|
|
@@ -48,6 +62,8 @@ export interface DatasourceOptions<TSchema extends SchemaDefinition> {
|
|
|
48
62
|
* Defaults to true.
|
|
49
63
|
*/
|
|
50
64
|
jsonPaths?: boolean;
|
|
65
|
+
/** Kafka ingestion configuration */
|
|
66
|
+
kafka?: KafkaConfig;
|
|
51
67
|
}
|
|
52
68
|
/**
|
|
53
69
|
* A datasource definition with full type information
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/schema/datasource.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/schema/datasource.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAGjE,QAAA,MAAM,gBAAgB,eAAgC,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,gBAAgB,GAAG,gBAAgB;IAC7E,sBAAsB;IACtB,IAAI,EAAE,CAAC,CAAC;IACR,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,gBAA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AAO,CAAC;IAC1B,mBAAmB;IACnB,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,gBAAgB,EAC/D,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAClC,oBAAoB,CAAC,OAAO,CAAC,CAe/B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oBAAoB,CAOpF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,GAAG,gBAAgB,CAK3F;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAKjG;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,gBAAgB,EAC7D,MAAM,EAAE,OAAO,GACd,CAAC,MAAM,OAAO,CAAC,EAAE,CAEnB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,oBAAoB,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEnF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,gBAAgB,EAC/C,IAAI,EAAE,CAAC,EACP,OAAO,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAC1C,gBAAgB,CAAC,CAAC,CAAC,CAKrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource.js","sourceRoot":"","sources":["../../src/schema/datasource.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"datasource.js","sourceRoot":"","sources":["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,CAAC,MAAM,CAAsB,CAAC;AAClD,CAAC;AAOD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CACpB,IAAO,EACP,OAA2C;IAE3C,OAAO;QACL,IAAI;QACJ,GAAG,OAAO;KACX,CAAC;AACJ,CAAC"}
|
package/dist/schema/project.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { DatasourceDefinition, SchemaDefinition } from "./datasource.js";
|
|
6
6
|
import type { PipeDefinition, ParamsDefinition, OutputDefinition } from "./pipe.js";
|
|
7
|
+
import type { ConnectionDefinition } from "./connection.js";
|
|
7
8
|
import type { TinybirdClient } from "../client/base.js";
|
|
8
9
|
import type { QueryResult } from "../client/types.js";
|
|
9
10
|
import type { InferRow, InferParams, InferOutputRow } from "../infer/index.js";
|
|
@@ -16,6 +17,10 @@ export type DatasourcesDefinition = Record<string, DatasourceDefinition<SchemaDe
|
|
|
16
17
|
* Collection of pipe definitions
|
|
17
18
|
*/
|
|
18
19
|
export type PipesDefinition = Record<string, PipeDefinition<ParamsDefinition, OutputDefinition>>;
|
|
20
|
+
/**
|
|
21
|
+
* Collection of connection definitions
|
|
22
|
+
*/
|
|
23
|
+
export type ConnectionsDefinition = Record<string, ConnectionDefinition>;
|
|
19
24
|
/**
|
|
20
25
|
* Type for a single query method
|
|
21
26
|
*/
|
|
@@ -70,16 +75,18 @@ export interface TinybirdClientConfig<TDatasources extends DatasourcesDefinition
|
|
|
70
75
|
/**
|
|
71
76
|
* Project configuration
|
|
72
77
|
*/
|
|
73
|
-
export interface ProjectConfig<TDatasources extends DatasourcesDefinition = DatasourcesDefinition, TPipes extends PipesDefinition = PipesDefinition> {
|
|
78
|
+
export interface ProjectConfig<TDatasources extends DatasourcesDefinition = DatasourcesDefinition, TPipes extends PipesDefinition = PipesDefinition, TConnections extends ConnectionsDefinition = ConnectionsDefinition> {
|
|
74
79
|
/** All datasources in this project */
|
|
75
80
|
datasources?: TDatasources;
|
|
76
81
|
/** All pipes in this project */
|
|
77
82
|
pipes?: TPipes;
|
|
83
|
+
/** All connections in this project */
|
|
84
|
+
connections?: TConnections;
|
|
78
85
|
}
|
|
79
86
|
/**
|
|
80
87
|
* A project definition with full type information
|
|
81
88
|
*/
|
|
82
|
-
export interface ProjectDefinition<TDatasources extends DatasourcesDefinition = DatasourcesDefinition, TPipes extends PipesDefinition = PipesDefinition> {
|
|
89
|
+
export interface ProjectDefinition<TDatasources extends DatasourcesDefinition = DatasourcesDefinition, TPipes extends PipesDefinition = PipesDefinition, TConnections extends ConnectionsDefinition = ConnectionsDefinition> {
|
|
83
90
|
readonly [PROJECT_BRAND]: true;
|
|
84
91
|
/** Type marker for inference */
|
|
85
92
|
readonly _type: "project";
|
|
@@ -87,6 +94,8 @@ export interface ProjectDefinition<TDatasources extends DatasourcesDefinition =
|
|
|
87
94
|
readonly datasources: TDatasources;
|
|
88
95
|
/** All pipes */
|
|
89
96
|
readonly pipes: TPipes;
|
|
97
|
+
/** All connections */
|
|
98
|
+
readonly connections: TConnections;
|
|
90
99
|
/** Typed Tinybird client */
|
|
91
100
|
readonly tinybird: ProjectClient<TDatasources, TPipes>;
|
|
92
101
|
}
|
|
@@ -118,7 +127,7 @@ export interface ProjectDefinition<TDatasources extends DatasourcesDefinition =
|
|
|
118
127
|
* });
|
|
119
128
|
* ```
|
|
120
129
|
*/
|
|
121
|
-
export declare function defineProject<TDatasources extends DatasourcesDefinition, TPipes extends PipesDefinition>(config: ProjectConfig<TDatasources, TPipes>): ProjectDefinition<TDatasources, TPipes>;
|
|
130
|
+
export declare function defineProject<TDatasources extends DatasourcesDefinition, TPipes extends PipesDefinition, TConnections extends ConnectionsDefinition>(config: ProjectConfig<TDatasources, TPipes, TConnections>): ProjectDefinition<TDatasources, TPipes, TConnections>;
|
|
122
131
|
/**
|
|
123
132
|
* Check if a value is a project definition
|
|
124
133
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/schema/project.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/schema/project.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACpF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAG/E,QAAA,MAAM,aAAa,eAA6B,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAE3F;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEjG;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEzE;;GAEG;AACH,KAAK,WAAW,CAAC,CAAC,SAAS,cAAc,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,IAC3E,CAAC,SAAS,cAAc,CAAC,MAAM,CAAC,EAAE,gBAAgB,C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M,EACtB,OAAO,EAAE,iBAAiB,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAEtE;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,SAAS,iBAAiB,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,GACrF,CAAC,GACD,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,iBAAiB,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC,GACrF,CAAC,GACD,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,iBAAiB,IAAI;IACnD,WAAW,EAAE;SACV,CAAC,IAAI,MAAM,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,oBAAoB,CAAC,MAAM,CAAC,CAAC,GACpF,CAAC,GACD,KAAK;KACV,CAAC;IACF,KAAK,EAAE;SACJ,CAAC,IAAI,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAC3E;YAAE,MAAM,EAAE,CAAC,CAAC;YAAC,MAAM,EAAE,CAAC,CAAA;SAAE,GACxB,KAAK;KACV,CAAC;CACH,CAAC"}
|
package/dist/schema/project.js
CHANGED
|
@@ -36,6 +36,7 @@ const PROJECT_BRAND = Symbol("tinybird.project");
|
|
|
36
36
|
export function defineProject(config) {
|
|
37
37
|
const datasources = (config.datasources ?? {});
|
|
38
38
|
const pipes = (config.pipes ?? {});
|
|
39
|
+
const connections = (config.connections ?? {});
|
|
39
40
|
// Use the shared client builder
|
|
40
41
|
const tinybird = buildProjectClient(datasources, pipes);
|
|
41
42
|
return {
|
|
@@ -43,6 +44,7 @@ export function defineProject(config) {
|
|
|
43
44
|
_type: "project",
|
|
44
45
|
datasources,
|
|
45
46
|
pipes,
|
|
47
|
+
connections,
|
|
46
48
|
tinybird,
|
|
47
49
|
};
|
|
48
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/schema/project.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/schema/project.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAK9C,0BAA0B;AAC1B,MAAM,aAAa,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AA+HjD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,aAAa,CAK3B,MAAyD;IAEzD,MAAM,WAAW,GAAG,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAiB,CAAC;IAC/D,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAW,CAAC;IAC7C,MAAM,WAAW,GAAG,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAiB,CAAC;IAE/D,gCAAgC;IAChC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAExD,OAAO;QACL,CAAC,aAAa,CAAC,EAAE,IAAI;QACrB,KAAK,EAAE,SAAS;QAChB,WAAW;QACX,KAAK;QACL,WAAW;QACX,QAAQ;KACT,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,aAAa,IAAI,KAAK;QACrB,KAAiC,CAAC,aAAa,CAAC,KAAK,IAAI,CAC3D,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,kBA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,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CACjD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAU;IAEV,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAA+B,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAA8B,OAAU;IAClE,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAyB,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAI3B,OAAgD,EAAE,IAAO;IACzD,OAAO,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAIrB,OAAgD,EAAE,IAAO;IACzD,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
|
package/package.json
CHANGED
package/src/api/build.test.ts
CHANGED
package/src/api/build.ts
CHANGED
|
@@ -88,6 +88,8 @@ export interface BuildApiResult {
|
|
|
88
88
|
datasourceCount: number;
|
|
89
89
|
/** Number of pipes deployed */
|
|
90
90
|
pipeCount: number;
|
|
91
|
+
/** Number of connections deployed */
|
|
92
|
+
connectionCount: number;
|
|
91
93
|
/** Build ID if successful */
|
|
92
94
|
buildId?: string;
|
|
93
95
|
/** Pipe changes in this build */
|
|
@@ -166,6 +168,21 @@ export async function buildToTinybird(
|
|
|
166
168
|
);
|
|
167
169
|
}
|
|
168
170
|
|
|
171
|
+
// Add connections
|
|
172
|
+
for (const conn of resources.connections ?? []) {
|
|
173
|
+
const fieldName = `data_project://`;
|
|
174
|
+
const fileName = `${conn.name}.connection`;
|
|
175
|
+
if (debug) {
|
|
176
|
+
console.log(`[debug] Adding connection: ${fieldName} (filename: ${fileName})`);
|
|
177
|
+
console.log(`[debug] Content:\n${conn.content}\n`);
|
|
178
|
+
}
|
|
179
|
+
formData.append(
|
|
180
|
+
fieldName,
|
|
181
|
+
new Blob([conn.content], { type: "text/plain" }),
|
|
182
|
+
fileName
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
169
186
|
// Make the request
|
|
170
187
|
const url = `${config.baseUrl.replace(/\/$/, "")}/v1/build`;
|
|
171
188
|
|
|
@@ -217,6 +234,7 @@ export async function buildToTinybird(
|
|
|
217
234
|
error: formatErrors(),
|
|
218
235
|
datasourceCount: resources.datasources.length,
|
|
219
236
|
pipeCount: resources.pipes.length,
|
|
237
|
+
connectionCount: resources.connections?.length ?? 0,
|
|
220
238
|
};
|
|
221
239
|
}
|
|
222
240
|
|
|
@@ -228,6 +246,7 @@ export async function buildToTinybird(
|
|
|
228
246
|
error: formatErrors(),
|
|
229
247
|
datasourceCount: resources.datasources.length,
|
|
230
248
|
pipeCount: resources.pipes.length,
|
|
249
|
+
connectionCount: resources.connections?.length ?? 0,
|
|
231
250
|
};
|
|
232
251
|
}
|
|
233
252
|
|
|
@@ -236,6 +255,7 @@ export async function buildToTinybird(
|
|
|
236
255
|
result: body.result,
|
|
237
256
|
datasourceCount: resources.datasources.length,
|
|
238
257
|
pipeCount: resources.pipes.length,
|
|
258
|
+
connectionCount: resources.connections?.length ?? 0,
|
|
239
259
|
buildId: body.build?.id,
|
|
240
260
|
pipes: {
|
|
241
261
|
changed: body.build?.changed_pipe_names ?? [],
|
package/src/api/deploy.test.ts
CHANGED
package/src/api/deploy.ts
CHANGED
|
@@ -126,6 +126,7 @@ export async function deployToMain(
|
|
|
126
126
|
error: formatErrors(),
|
|
127
127
|
datasourceCount: resources.datasources.length,
|
|
128
128
|
pipeCount: resources.pipes.length,
|
|
129
|
+
connectionCount: resources.connections?.length ?? 0,
|
|
129
130
|
};
|
|
130
131
|
}
|
|
131
132
|
|
|
@@ -137,6 +138,7 @@ export async function deployToMain(
|
|
|
137
138
|
error: formatErrors(),
|
|
138
139
|
datasourceCount: resources.datasources.length,
|
|
139
140
|
pipeCount: resources.pipes.length,
|
|
141
|
+
connectionCount: resources.connections?.length ?? 0,
|
|
140
142
|
};
|
|
141
143
|
}
|
|
142
144
|
|
|
@@ -145,6 +147,7 @@ export async function deployToMain(
|
|
|
145
147
|
result: body.result,
|
|
146
148
|
datasourceCount: resources.datasources.length,
|
|
147
149
|
pipeCount: resources.pipes.length,
|
|
150
|
+
connectionCount: resources.connections?.length ?? 0,
|
|
148
151
|
buildId: body.build?.id,
|
|
149
152
|
pipes: {
|
|
150
153
|
changed: body.build?.changed_pipe_names ?? [],
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { generateConnection, generateAllConnections } from "./connection.js";
|
|
3
|
+
import { createKafkaConnection } from "../schema/connection.js";
|
|
4
|
+
|
|
5
|
+
describe("Connection Generator", () => {
|
|
6
|
+
describe("generateConnection", () => {
|
|
7
|
+
it("generates basic Kafka connection with required fields", () => {
|
|
8
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
9
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const result = generateConnection(conn);
|
|
13
|
+
|
|
14
|
+
expect(result.name).toBe("my_kafka");
|
|
15
|
+
expect(result.content).toContain("TYPE kafka");
|
|
16
|
+
expect(result.content).toContain("KAFKA_BOOTSTRAP_SERVERS kafka.example.com:9092");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("includes security protocol when provided", () => {
|
|
20
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
21
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
22
|
+
securityProtocol: "SASL_SSL",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const result = generateConnection(conn);
|
|
26
|
+
|
|
27
|
+
expect(result.content).toContain("KAFKA_SECURITY_PROTOCOL SASL_SSL");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("includes SASL mechanism when provided", () => {
|
|
31
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
32
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
33
|
+
saslMechanism: "PLAIN",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const result = generateConnection(conn);
|
|
37
|
+
|
|
38
|
+
expect(result.content).toContain("KAFKA_SASL_MECHANISM PLAIN");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("includes key and secret when provided", () => {
|
|
42
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
43
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
44
|
+
key: '{{ tb_secret("KAFKA_KEY") }}',
|
|
45
|
+
secret: '{{ tb_secret("KAFKA_SECRET") }}',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const result = generateConnection(conn);
|
|
49
|
+
|
|
50
|
+
expect(result.content).toContain('KAFKA_KEY {{ tb_secret("KAFKA_KEY") }}');
|
|
51
|
+
expect(result.content).toContain('KAFKA_SECRET {{ tb_secret("KAFKA_SECRET") }}');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("includes SSL CA PEM when provided", () => {
|
|
55
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
56
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
57
|
+
sslCaPem: '{{ tb_secret("KAFKA_CA_CERT") }}',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const result = generateConnection(conn);
|
|
61
|
+
|
|
62
|
+
expect(result.content).toContain('KAFKA_SSL_CA_PEM {{ tb_secret("KAFKA_CA_CERT") }}');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("generates full Kafka connection with all options", () => {
|
|
66
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
67
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
68
|
+
securityProtocol: "SASL_SSL",
|
|
69
|
+
saslMechanism: "SCRAM-SHA-256",
|
|
70
|
+
key: '{{ tb_secret("KAFKA_KEY") }}',
|
|
71
|
+
secret: '{{ tb_secret("KAFKA_SECRET") }}',
|
|
72
|
+
sslCaPem: '{{ tb_secret("KAFKA_CA_CERT") }}',
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const result = generateConnection(conn);
|
|
76
|
+
|
|
77
|
+
expect(result.name).toBe("my_kafka");
|
|
78
|
+
expect(result.content).toContain("TYPE kafka");
|
|
79
|
+
expect(result.content).toContain("KAFKA_BOOTSTRAP_SERVERS kafka.example.com:9092");
|
|
80
|
+
expect(result.content).toContain("KAFKA_SECURITY_PROTOCOL SASL_SSL");
|
|
81
|
+
expect(result.content).toContain("KAFKA_SASL_MECHANISM SCRAM-SHA-256");
|
|
82
|
+
expect(result.content).toContain('KAFKA_KEY {{ tb_secret("KAFKA_KEY") }}');
|
|
83
|
+
expect(result.content).toContain('KAFKA_SECRET {{ tb_secret("KAFKA_SECRET") }}');
|
|
84
|
+
expect(result.content).toContain('KAFKA_SSL_CA_PEM {{ tb_secret("KAFKA_CA_CERT") }}');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("supports PLAINTEXT security protocol", () => {
|
|
88
|
+
const conn = createKafkaConnection("local_kafka", {
|
|
89
|
+
bootstrapServers: "localhost:9092",
|
|
90
|
+
securityProtocol: "PLAINTEXT",
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const result = generateConnection(conn);
|
|
94
|
+
|
|
95
|
+
expect(result.content).toContain("KAFKA_SECURITY_PROTOCOL PLAINTEXT");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("supports different SASL mechanisms", () => {
|
|
99
|
+
const mechanisms = ["PLAIN", "SCRAM-SHA-256", "SCRAM-SHA-512", "OAUTHBEARER"] as const;
|
|
100
|
+
|
|
101
|
+
mechanisms.forEach((mechanism) => {
|
|
102
|
+
const conn = createKafkaConnection("my_kafka", {
|
|
103
|
+
bootstrapServers: "kafka.example.com:9092",
|
|
104
|
+
saslMechanism: mechanism,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const result = generateConnection(conn);
|
|
108
|
+
|
|
109
|
+
expect(result.content).toContain(`KAFKA_SASL_MECHANISM ${mechanism}`);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("generateAllConnections", () => {
|
|
115
|
+
it("generates all connections", () => {
|
|
116
|
+
const conn1 = createKafkaConnection("kafka1", {
|
|
117
|
+
bootstrapServers: "kafka1.example.com:9092",
|
|
118
|
+
});
|
|
119
|
+
const conn2 = createKafkaConnection("kafka2", {
|
|
120
|
+
bootstrapServers: "kafka2.example.com:9092",
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const results = generateAllConnections({ kafka1: conn1, kafka2: conn2 });
|
|
124
|
+
|
|
125
|
+
expect(results).toHaveLength(2);
|
|
126
|
+
expect(results.map((r) => r.name).sort()).toEqual(["kafka1", "kafka2"]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("returns empty array for empty connections", () => {
|
|
130
|
+
const results = generateAllConnections({});
|
|
131
|
+
|
|
132
|
+
expect(results).toHaveLength(0);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|