UNPKG

schematic-kafka

Version:

Encode and decode kafka messages with Confluent Schema Registry (pure typescript implementation)

53 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findTypes = exports.up = exports.findPort = void 0; const tslib_1 = require("tslib"); const net_1 = require("net"); const testcontainers_1 = require("testcontainers"); const protobufjs_1 = require("protobufjs"); const TAG = "7.3.0"; const findPort = () => new Promise((resolve) => { const server = (0, net_1.createServer)(); server.listen(0, () => { const { port } = server.address(); server.close(() => { resolve(port); }); }); }); exports.findPort = findPort; const up = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const kafkaPort = yield (0, exports.findPort)(); const testcontainers = yield new testcontainers_1.DockerComposeEnvironment(".", "docker-compose.yml") .withEnvironment({ TAG: TAG, KAFKA_PORT: `${kafkaPort}` }) .withWaitStrategy("zookeeper", testcontainers_1.Wait.forLogMessage("binding to port")) .withWaitStrategy("broker", testcontainers_1.Wait.forLogMessage("Ready to serve as the new controller")) .withStartupTimeout(1000 * 60 * 3) .up(); const schemaRegistryPort = testcontainers.getContainer("schema-registry").getMappedPort(8081); return { testcontainers, schemaRegistryPort, brokerPort: kafkaPort, }; }); exports.up = up; // function to traverse protobuf definition to find all the types (there should only be one) const findTypes = (src) => { const types = []; const dive = (src) => { if (src instanceof protobufjs_1.Type) { types.push(src.name); } else if (src.nested) { dive(src.nested); } else if (typeof src === "object") { Object.values(src).map(dive); } }; dive(src); return types; }; exports.findTypes = findTypes; //# sourceMappingURL=helper.js.map