@neat.is/core 0.9.0 → 0.9.1-dev.20260819

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/cli.cjs CHANGED
@@ -10253,6 +10253,11 @@ var import_node_path39 = __toESM(require("path"), 1);
10253
10253
  var import_types28 = require("@neat.is/types");
10254
10254
  var PRODUCER_TOPIC_RE = /(?:producer|kafkaProducer)[\s\S]{0,40}?\.send\s*\(\s*\{[\s\S]{0,200}?topic\s*:\s*['"`]([^'"`]+)['"`]/g;
10255
10255
  var CONSUMER_TOPIC_RE = /(?:consumer|kafkaConsumer)[\s\S]{0,40}?\.(?:subscribe|run)\s*\(\s*\{[\s\S]{0,200}?topic[s]?\s*:\s*(?:\[\s*)?['"`]([^'"`]+)['"`]/g;
10256
+ var SARAMA_IMPORT_RE = /"[^"]*\/sarama"/;
10257
+ var GO_PRODUCER_RE = /ProducerMessage\s*\{[\s\S]{0,300}?\bTopic\s*:\s*(?:"([^"]+)"|`([^`]+)`|([A-Za-z_]\w*))/g;
10258
+ var GO_CONSUMER_RE = /\.Consume\s*\([\s\S]{0,120}?\[\]string\s*\{([^}]*)\}/g;
10259
+ var GO_STRING_LITERAL_RE = /"([^"]+)"|`([^`]+)`/g;
10260
+ var GO_IDENT_RE = /[A-Za-z_]\w*/g;
10256
10261
  function findAll(re, text) {
10257
10262
  re.lastIndex = 0;
10258
10263
  const out = [];
@@ -10262,22 +10267,74 @@ function findAll(re, text) {
10262
10267
  }
10263
10268
  return out;
10264
10269
  }
10270
+ function resolveGoLiteral(ident, text) {
10271
+ const esc = ident.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10272
+ const re = new RegExp(
10273
+ `\\b${esc}(?:\\s+\\w[\\w.\\[\\]*]*)?\\s*(?::=|=)\\s*(?:"([^"]+)"|\`([^\`]+)\`)`
10274
+ );
10275
+ const m = re.exec(text);
10276
+ if (!m) return void 0;
10277
+ return m[1] ?? m[2];
10278
+ }
10279
+ function producerTopicAnchor(match) {
10280
+ const [full] = match;
10281
+ const tokenLen = match[1] ? match[1].length + 2 : match[2] ? match[2].length + 2 : match[3]?.length ?? 0;
10282
+ return match.index + full.length - tokenLen;
10283
+ }
10284
+ function goSaramaEndpoints(text, emit) {
10285
+ if (!SARAMA_IMPORT_RE.test(text)) return;
10286
+ GO_PRODUCER_RE.lastIndex = 0;
10287
+ let m;
10288
+ while ((m = GO_PRODUCER_RE.exec(text)) !== null) {
10289
+ const literal = m[1] ?? m[2];
10290
+ const anchor = producerTopicAnchor(m);
10291
+ if (literal) {
10292
+ emit(literal, "PUBLISHES_TO", anchor);
10293
+ } else if (m[3]) {
10294
+ const resolved = resolveGoLiteral(m[3], text);
10295
+ if (resolved) emit(resolved, "PUBLISHES_TO", anchor);
10296
+ }
10297
+ }
10298
+ GO_CONSUMER_RE.lastIndex = 0;
10299
+ while ((m = GO_CONSUMER_RE.exec(text)) !== null) {
10300
+ const inside = m[1] ?? "";
10301
+ const anchor = m.index + Math.max(0, m[0].indexOf("[]string"));
10302
+ let sawLiteral = false;
10303
+ GO_STRING_LITERAL_RE.lastIndex = 0;
10304
+ let s;
10305
+ while ((s = GO_STRING_LITERAL_RE.exec(inside)) !== null) {
10306
+ const topic = s[1] ?? s[2];
10307
+ if (topic) {
10308
+ emit(topic, "CONSUMES_FROM", anchor);
10309
+ sawLiteral = true;
10310
+ }
10311
+ }
10312
+ if (sawLiteral) continue;
10313
+ GO_IDENT_RE.lastIndex = 0;
10314
+ let id;
10315
+ while ((id = GO_IDENT_RE.exec(inside)) !== null) {
10316
+ const resolved = resolveGoLiteral(id[0], text);
10317
+ if (resolved) emit(resolved, "CONSUMES_FROM", anchor);
10318
+ }
10319
+ }
10320
+ }
10265
10321
  function kafkaEndpointsFromFile(file, serviceDir) {
10266
10322
  const out = [];
10267
10323
  const seen = /* @__PURE__ */ new Set();
10268
- const make = (topic, edgeType) => {
10324
+ const make = (topic, edgeType, anchor) => {
10269
10325
  const key = `${edgeType}|${topic}`;
10270
10326
  if (seen.has(key)) return;
10271
10327
  seen.add(key);
10272
- const line = lineOf(file.content, topic);
10328
+ const line = anchor !== void 0 ? file.content.slice(0, anchor).split("\n").length : lineOf(file.content, topic);
10273
10329
  out.push({
10274
10330
  infraId: (0, import_types28.infraId)("kafka-topic", topic),
10275
10331
  name: topic,
10276
10332
  kind: "kafka-topic",
10277
10333
  edgeType,
10278
- // `producer.send({topic: 'x'})` / `consumer.subscribe({topic: 'x'})`
10279
- // framework-aware (kafkajs / node-rdkafka shape). Verified-call-site
10280
- // tier (ADR-066).
10334
+ // JS: `producer.send({topic: 'x'})` / `consumer.subscribe({topic: 'x'})`
10335
+ // (kafkajs / node-rdkafka). Go: `sarama.ProducerMessage{Topic: 'x'}` /
10336
+ // `consumerGroup.Consume(ctx, []string{'x'}, …)`. Both are framework-aware
10337
+ // call sites — verified-call-site tier (ADR-066).
10281
10338
  confidenceKind: "verified-call-site",
10282
10339
  evidence: {
10283
10340
  file: import_node_path39.default.relative(serviceDir, file.path),
@@ -10286,8 +10343,12 @@ function kafkaEndpointsFromFile(file, serviceDir) {
10286
10343
  }
10287
10344
  });
10288
10345
  };
10289
- for (const { topic } of findAll(PRODUCER_TOPIC_RE, file.content)) make(topic, "PUBLISHES_TO");
10290
- for (const { topic } of findAll(CONSUMER_TOPIC_RE, file.content)) make(topic, "CONSUMES_FROM");
10346
+ if (import_node_path39.default.extname(file.path) === ".go") {
10347
+ goSaramaEndpoints(file.content, make);
10348
+ } else {
10349
+ for (const { topic } of findAll(PRODUCER_TOPIC_RE, file.content)) make(topic, "PUBLISHES_TO");
10350
+ for (const { topic } of findAll(CONSUMER_TOPIC_RE, file.content)) make(topic, "CONSUMES_FROM");
10351
+ }
10291
10352
  return out;
10292
10353
  }
10293
10354