@walkeros/cli 1.0.2 → 1.1.0-next-1769691037535

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/CHANGELOG.md CHANGED
@@ -1,5 +1,54 @@
1
1
  # @walkeros/cli
2
2
 
3
+ ## 1.1.0-next-1769691037535
4
+
5
+ ### Minor Changes
6
+
7
+ - 888bbdf: Add inline code syntax for sources, transformers, and destinations
8
+
9
+ Enables defining custom logic directly in flow.json using `code` objects
10
+ instead of requiring external packages. This is ideal for simple one-liner
11
+ transformations.
12
+
13
+ **Example:**
14
+
15
+ ```json
16
+ {
17
+ "transformers": {
18
+ "enrich": {
19
+ "code": {
20
+ "push": "$code:(event) => ({ ...event, data: { ...event.data, enriched: true } })"
21
+ },
22
+ "config": {}
23
+ }
24
+ }
25
+ }
26
+ ```
27
+
28
+ **Code object properties:**
29
+ - `push` - The push function with `$code:` prefix (required)
30
+ - `type` - Optional instance type identifier
31
+ - `init` - Optional init function with `$code:` prefix
32
+
33
+ **Rules:**
34
+ - Use `package` OR `code`, never both (CLI validates this)
35
+ - `config` stays separate from `code`
36
+ - `$code:` prefix outputs raw JavaScript at bundle time
37
+
38
+ ### Patch Changes
39
+
40
+ - fdf6e7b: Add transformer support to CLI bundler
41
+ - Detect and bundle transformer packages from flow.json configuration
42
+ - Support transformer chaining via `next` field
43
+ - Handle `$code:` prefix for inline JavaScript in transformer config
44
+ - Generate proper import statements and config objects for transformers
45
+ - Document transformer configuration in flow.json
46
+
47
+ - Updated dependencies [f39d9fb]
48
+ - Updated dependencies [888bbdf]
49
+ - @walkeros/core@1.2.0-next-1769691037535
50
+ - @walkeros/server-core@1.0.2-next-1769691037535
51
+
3
52
  ## 1.0.2
4
53
 
5
54
  ### Patch Changes
package/dist/index.js CHANGED
@@ -807,6 +807,51 @@ async function getCachedBuild(configContent, tmpDir) {
807
807
  }
808
808
 
809
809
  // src/commands/bundle/bundler.ts
810
+ function isInlineCode(code) {
811
+ return code !== null && typeof code === "object" && "push" in code;
812
+ }
813
+ function validateReference(type, name, ref) {
814
+ const hasPackage = !!ref.package;
815
+ const hasCode = isInlineCode(ref.code);
816
+ if (hasPackage && hasCode) {
817
+ throw new Error(
818
+ `${type} "${name}": Cannot specify both package and code. Use one or the other.`
819
+ );
820
+ }
821
+ if (!hasPackage && !hasCode) {
822
+ throw new Error(`${type} "${name}": Must specify either package or code.`);
823
+ }
824
+ }
825
+ function generateInlineCode(inline, config) {
826
+ const pushFn = inline.push.replace("$code:", "");
827
+ const initFn = inline.init ? inline.init.replace("$code:", "") : void 0;
828
+ const typeLine = inline.type ? `type: '${inline.type}',` : "";
829
+ return `{
830
+ code: async (context) => ({
831
+ ${typeLine}
832
+ config: context.config,
833
+ ${initFn ? `init: ${initFn},` : ""}
834
+ push: ${pushFn}
835
+ }),
836
+ config: ${JSON.stringify(config || {})},
837
+ env: {}
838
+ }`;
839
+ }
840
+ function generateInlineDestinationCode(inline, config) {
841
+ const pushFn = inline.push.replace("$code:", "");
842
+ const initFn = inline.init ? inline.init.replace("$code:", "") : void 0;
843
+ const typeLine = inline.type ? `type: '${inline.type}',` : "";
844
+ return `{
845
+ code: {
846
+ ${typeLine}
847
+ config: ${JSON.stringify(config || {})},
848
+ ${initFn ? `init: ${initFn},` : ""}
849
+ push: ${pushFn}
850
+ },
851
+ config: ${JSON.stringify(config || {})},
852
+ env: {}
853
+ }`;
854
+ }
810
855
  async function copyIncludes(includes, sourceDir, outputDir, logger2) {
811
856
  for (const include of includes) {
812
857
  const sourcePath = path8.resolve(sourceDir, include);
@@ -832,8 +877,48 @@ function generateCacheKeyContent(flowConfig, buildOptions) {
832
877
  };
833
878
  return JSON.stringify(configForCache);
834
879
  }
880
+ function validateFlowConfig(flowConfig, logger2) {
881
+ let hasDeprecatedCodeTrue = false;
882
+ const sources = flowConfig.sources || {};
883
+ for (const [sourceId, source] of Object.entries(sources)) {
884
+ if (source && typeof source === "object" && source.code === true) {
885
+ logger2.warning(
886
+ `DEPRECATED: Source "${sourceId}" uses code: true which is no longer supported. Use $code: prefix in config values or create a source package instead.`
887
+ );
888
+ hasDeprecatedCodeTrue = true;
889
+ }
890
+ }
891
+ const destinations = flowConfig.destinations || {};
892
+ for (const [destId, dest] of Object.entries(destinations)) {
893
+ if (dest && typeof dest === "object" && dest.code === true) {
894
+ logger2.warning(
895
+ `DEPRECATED: Destination "${destId}" uses code: true which is no longer supported. Use $code: prefix in config values or create a destination package instead.`
896
+ );
897
+ hasDeprecatedCodeTrue = true;
898
+ }
899
+ }
900
+ const transformers = flowConfig.transformers || {};
901
+ for (const [transformerId, transformer] of Object.entries(transformers)) {
902
+ if (transformer && typeof transformer === "object" && transformer.code === true) {
903
+ logger2.warning(
904
+ `DEPRECATED: Transformer "${transformerId}" uses code: true which is no longer supported. Use $code: prefix in config values or create a transformer package instead.`
905
+ );
906
+ hasDeprecatedCodeTrue = true;
907
+ }
908
+ }
909
+ if (hasDeprecatedCodeTrue) {
910
+ logger2.warning(
911
+ `See https://www.elbwalker.com/docs/walkeros/getting-started/flow for migration guide.`
912
+ );
913
+ }
914
+ return hasDeprecatedCodeTrue;
915
+ }
835
916
  async function bundleCore(flowConfig, buildOptions, logger2, showStats = false) {
836
917
  const bundleStartTime = Date.now();
918
+ const hasDeprecatedFeatures = validateFlowConfig(flowConfig, logger2);
919
+ if (hasDeprecatedFeatures) {
920
+ logger2.warning("Skipping deprecated code: true entries from bundle.");
921
+ }
837
922
  const TEMP_DIR = buildOptions.tempDir || getTmpPath();
838
923
  if (buildOptions.cache !== false) {
839
924
  const configContent = generateCacheKeyContent(flowConfig, buildOptions);
@@ -1079,6 +1164,9 @@ function detectDestinationPackages(flowConfig) {
1079
1164
  const destinations = flowConfig.destinations;
1080
1165
  if (destinations) {
1081
1166
  for (const [destKey, destConfig] of Object.entries(destinations)) {
1167
+ if (typeof destConfig === "object" && destConfig !== null && "code" in destConfig && destConfig.code === true) {
1168
+ continue;
1169
+ }
1082
1170
  if (typeof destConfig === "object" && destConfig !== null && "package" in destConfig && typeof destConfig.package === "string") {
1083
1171
  destinationPackages.add(destConfig.package);
1084
1172
  }
@@ -1091,6 +1179,9 @@ function detectSourcePackages(flowConfig) {
1091
1179
  const sources = flowConfig.sources;
1092
1180
  if (sources) {
1093
1181
  for (const [sourceKey, sourceConfig] of Object.entries(sources)) {
1182
+ if (typeof sourceConfig === "object" && sourceConfig !== null && "code" in sourceConfig && sourceConfig.code === true) {
1183
+ continue;
1184
+ }
1094
1185
  if (typeof sourceConfig === "object" && sourceConfig !== null && "package" in sourceConfig && typeof sourceConfig.package === "string") {
1095
1186
  sourcePackages.add(sourceConfig.package);
1096
1187
  }
@@ -1098,11 +1189,31 @@ function detectSourcePackages(flowConfig) {
1098
1189
  }
1099
1190
  return sourcePackages;
1100
1191
  }
1192
+ function detectTransformerPackages(flowConfig) {
1193
+ const transformerPackages = /* @__PURE__ */ new Set();
1194
+ const transformers = flowConfig.transformers;
1195
+ if (transformers) {
1196
+ for (const [transformerKey, transformerConfig] of Object.entries(
1197
+ transformers
1198
+ )) {
1199
+ if (typeof transformerConfig === "object" && transformerConfig !== null && "code" in transformerConfig && transformerConfig.code === true) {
1200
+ continue;
1201
+ }
1202
+ if (typeof transformerConfig === "object" && transformerConfig !== null && "package" in transformerConfig && typeof transformerConfig.package === "string") {
1203
+ transformerPackages.add(transformerConfig.package);
1204
+ }
1205
+ }
1206
+ }
1207
+ return transformerPackages;
1208
+ }
1101
1209
  function detectExplicitCodeImports(flowConfig) {
1102
1210
  const explicitCodeImports = /* @__PURE__ */ new Map();
1103
1211
  const destinations = flowConfig.destinations;
1104
1212
  if (destinations) {
1105
1213
  for (const [destKey, destConfig] of Object.entries(destinations)) {
1214
+ if (typeof destConfig === "object" && destConfig !== null && "code" in destConfig && destConfig.code === true) {
1215
+ continue;
1216
+ }
1106
1217
  if (typeof destConfig === "object" && destConfig !== null && "package" in destConfig && typeof destConfig.package === "string" && "code" in destConfig && typeof destConfig.code === "string") {
1107
1218
  const isAutoGenerated = destConfig.code.startsWith("_");
1108
1219
  if (!isAutoGenerated) {
@@ -1117,6 +1228,9 @@ function detectExplicitCodeImports(flowConfig) {
1117
1228
  const sources = flowConfig.sources;
1118
1229
  if (sources) {
1119
1230
  for (const [sourceKey, sourceConfig] of Object.entries(sources)) {
1231
+ if (typeof sourceConfig === "object" && sourceConfig !== null && "code" in sourceConfig && sourceConfig.code === true) {
1232
+ continue;
1233
+ }
1120
1234
  if (typeof sourceConfig === "object" && sourceConfig !== null && "package" in sourceConfig && typeof sourceConfig.package === "string" && "code" in sourceConfig && typeof sourceConfig.code === "string") {
1121
1235
  const isAutoGenerated = sourceConfig.code.startsWith("_");
1122
1236
  if (!isAutoGenerated) {
@@ -1128,12 +1242,35 @@ function detectExplicitCodeImports(flowConfig) {
1128
1242
  }
1129
1243
  }
1130
1244
  }
1245
+ const transformers = flowConfig.transformers;
1246
+ if (transformers) {
1247
+ for (const [transformerKey, transformerConfig] of Object.entries(
1248
+ transformers
1249
+ )) {
1250
+ if (typeof transformerConfig === "object" && transformerConfig !== null && "code" in transformerConfig && transformerConfig.code === true) {
1251
+ continue;
1252
+ }
1253
+ if (typeof transformerConfig === "object" && transformerConfig !== null && "package" in transformerConfig && typeof transformerConfig.package === "string" && "code" in transformerConfig && typeof transformerConfig.code === "string") {
1254
+ const isAutoGenerated = transformerConfig.code.startsWith("_");
1255
+ if (!isAutoGenerated) {
1256
+ if (!explicitCodeImports.has(transformerConfig.package)) {
1257
+ explicitCodeImports.set(transformerConfig.package, /* @__PURE__ */ new Set());
1258
+ }
1259
+ explicitCodeImports.get(transformerConfig.package).add(transformerConfig.code);
1260
+ }
1261
+ }
1262
+ }
1263
+ }
1131
1264
  return explicitCodeImports;
1132
1265
  }
1133
- function generateImportStatements(packages, destinationPackages, sourcePackages, explicitCodeImports) {
1266
+ function generateImportStatements(packages, destinationPackages, sourcePackages, transformerPackages, explicitCodeImports) {
1134
1267
  const importStatements = [];
1135
1268
  const examplesMappings = [];
1136
- const usedPackages = /* @__PURE__ */ new Set([...destinationPackages, ...sourcePackages]);
1269
+ const usedPackages = /* @__PURE__ */ new Set([
1270
+ ...destinationPackages,
1271
+ ...sourcePackages,
1272
+ ...transformerPackages
1273
+ ]);
1137
1274
  for (const [packageName, packageConfig] of Object.entries(packages)) {
1138
1275
  const isUsedByDestOrSource = usedPackages.has(packageName);
1139
1276
  const hasExplicitCode = explicitCodeImports.has(packageName);
@@ -1191,11 +1328,13 @@ function generateImportStatements(packages, destinationPackages, sourcePackages,
1191
1328
  async function createEntryPoint(flowConfig, buildOptions, packagePaths) {
1192
1329
  const destinationPackages = detectDestinationPackages(flowConfig);
1193
1330
  const sourcePackages = detectSourcePackages(flowConfig);
1331
+ const transformerPackages = detectTransformerPackages(flowConfig);
1194
1332
  const explicitCodeImports = detectExplicitCodeImports(flowConfig);
1195
1333
  const { importStatements } = generateImportStatements(
1196
1334
  buildOptions.packages,
1197
1335
  destinationPackages,
1198
1336
  sourcePackages,
1337
+ transformerPackages,
1199
1338
  explicitCodeImports
1200
1339
  );
1201
1340
  const importsCode = importStatements.join("\n");
@@ -1243,9 +1382,34 @@ function buildConfigObject(flowConfig, explicitCodeImports) {
1243
1382
  const flowWithProps = flowConfig;
1244
1383
  const sources = flowWithProps.sources || {};
1245
1384
  const destinations = flowWithProps.destinations || {};
1246
- const sourcesEntries = Object.entries(sources).map(([key, source]) => {
1247
- const hasExplicitCode = source.code && explicitCodeImports.has(source.package);
1248
- const codeVar = hasExplicitCode ? source.code : packageNameToVariable(source.package);
1385
+ const transformers = flowWithProps.transformers || {};
1386
+ Object.entries(sources).forEach(([name, source]) => {
1387
+ if (source.code !== true) {
1388
+ validateReference("Source", name, source);
1389
+ }
1390
+ });
1391
+ Object.entries(destinations).forEach(([name, dest]) => {
1392
+ if (dest.code !== true) {
1393
+ validateReference("Destination", name, dest);
1394
+ }
1395
+ });
1396
+ Object.entries(transformers).forEach(([name, transformer]) => {
1397
+ if (transformer.code !== true) {
1398
+ validateReference("Transformer", name, transformer);
1399
+ }
1400
+ });
1401
+ const sourcesEntries = Object.entries(sources).filter(
1402
+ ([, source]) => source.code !== true && (source.package || isInlineCode(source.code))
1403
+ ).map(([key, source]) => {
1404
+ if (isInlineCode(source.code)) {
1405
+ return ` ${key}: ${generateInlineCode(source.code, source.config || {})}`;
1406
+ }
1407
+ let codeVar;
1408
+ if (source.code && typeof source.code === "string" && explicitCodeImports.has(source.package)) {
1409
+ codeVar = source.code;
1410
+ } else {
1411
+ codeVar = packageNameToVariable(source.package);
1412
+ }
1249
1413
  const configStr = source.config ? processConfigValue(source.config) : "{}";
1250
1414
  const envStr = source.env ? `,
1251
1415
  env: ${processConfigValue(source.env)}` : "";
@@ -1254,28 +1418,64 @@ function buildConfigObject(flowConfig, explicitCodeImports) {
1254
1418
  config: ${configStr}${envStr}
1255
1419
  }`;
1256
1420
  });
1257
- const destinationsEntries = Object.entries(destinations).map(
1258
- ([key, dest]) => {
1259
- const hasExplicitCode = dest.code && explicitCodeImports.has(dest.package);
1260
- const codeVar = hasExplicitCode ? dest.code : packageNameToVariable(dest.package);
1261
- const configStr = dest.config ? processConfigValue(dest.config) : "{}";
1262
- const envStr = dest.env ? `,
1421
+ const destinationsEntries = Object.entries(destinations).filter(
1422
+ ([, dest]) => dest.code !== true && (dest.package || isInlineCode(dest.code))
1423
+ ).map(([key, dest]) => {
1424
+ if (isInlineCode(dest.code)) {
1425
+ return ` ${key}: ${generateInlineDestinationCode(dest.code, dest.config || {})}`;
1426
+ }
1427
+ let codeVar;
1428
+ if (dest.code && typeof dest.code === "string" && explicitCodeImports.has(dest.package)) {
1429
+ codeVar = dest.code;
1430
+ } else {
1431
+ codeVar = packageNameToVariable(dest.package);
1432
+ }
1433
+ const configStr = dest.config ? processConfigValue(dest.config) : "{}";
1434
+ const envStr = dest.env ? `,
1263
1435
  env: ${processConfigValue(dest.env)}` : "";
1264
- return ` ${key}: {
1436
+ return ` ${key}: {
1265
1437
  code: ${codeVar},
1266
1438
  config: ${configStr}${envStr}
1267
1439
  }`;
1440
+ });
1441
+ const transformersEntries = Object.entries(transformers).filter(
1442
+ ([, transformer]) => transformer.code !== true && (transformer.package || isInlineCode(transformer.code))
1443
+ ).map(([key, transformer]) => {
1444
+ if (isInlineCode(transformer.code)) {
1445
+ const configWithNext2 = transformer.next ? {
1446
+ ...transformer.config || {},
1447
+ next: transformer.next
1448
+ } : transformer.config || {};
1449
+ return ` ${key}: ${generateInlineCode(transformer.code, configWithNext2)}`;
1450
+ }
1451
+ let codeVar;
1452
+ if (transformer.code && typeof transformer.code === "string" && explicitCodeImports.has(transformer.package)) {
1453
+ codeVar = transformer.code;
1454
+ } else {
1455
+ codeVar = packageNameToVariable(transformer.package);
1268
1456
  }
1269
- );
1457
+ const configWithNext = transformer.next ? { ...transformer.config || {}, next: transformer.next } : transformer.config;
1458
+ const configStr = configWithNext ? processConfigValue(configWithNext) : "{}";
1459
+ const envStr = transformer.env ? `,
1460
+ env: ${processConfigValue(transformer.env)}` : "";
1461
+ return ` ${key}: {
1462
+ code: ${codeVar},
1463
+ config: ${configStr}${envStr}
1464
+ }`;
1465
+ });
1270
1466
  const collectorStr = flowWithProps.collector ? `,
1271
1467
  ...${processConfigValue(flowWithProps.collector)}` : "";
1468
+ const transformersStr = transformersEntries.length > 0 ? `,
1469
+ transformers: {
1470
+ ${transformersEntries.join(",\n")}
1471
+ }` : "";
1272
1472
  return `{
1273
1473
  sources: {
1274
1474
  ${sourcesEntries.join(",\n")}
1275
1475
  },
1276
1476
  destinations: {
1277
1477
  ${destinationsEntries.join(",\n")}
1278
- }${collectorStr}
1478
+ }${transformersStr}${collectorStr}
1279
1479
  }`;
1280
1480
  }
1281
1481
  function processConfigValue(value) {