trickle-backend 0.1.0 → 0.1.1

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.
@@ -48,6 +48,8 @@ function collectFunctionTypes(opts) {
48
48
  module: moduleName,
49
49
  env: snapshot.env || environment,
50
50
  observedAt: snapshot.observed_at,
51
+ sampleInput: snapshot.sample_input ? tryParseJson(snapshot.sample_input) : undefined,
52
+ sampleOutput: snapshot.sample_output ? tryParseJson(snapshot.sample_output) : undefined,
51
53
  });
52
54
  }
53
55
  return results;
@@ -30,6 +30,8 @@ export declare function generateFunctionTypes(functionName: string, argsType: Ty
30
30
  module?: string;
31
31
  env?: string;
32
32
  observedAt?: string;
33
+ sampleInput?: unknown;
34
+ sampleOutput?: unknown;
33
35
  }): string;
34
36
  /**
35
37
  * Generate a complete TypeScript declarations file for all functions.
@@ -41,6 +43,8 @@ export declare function generateAllTypes(functions: Array<{
41
43
  module?: string;
42
44
  env?: string;
43
45
  observedAt?: string;
46
+ sampleInput?: unknown;
47
+ sampleOutput?: unknown;
44
48
  }>): string;
45
49
  export declare function generatePythonTypes(functions: Array<{
46
50
  name: string;
@@ -264,13 +264,39 @@ function generateFunctionTypes(functionName, argsType, returnType, meta) {
264
264
  });
265
265
  funcDecl = `export declare function ${funcIdent}(${params.join(", ")}): ${outputName};`;
266
266
  }
267
+ // ── Build @example JSDoc from sample data ──
268
+ const exampleLines = [];
269
+ if (meta?.sampleInput !== undefined || meta?.sampleOutput !== undefined) {
270
+ exampleLines.push(`/**`);
271
+ if (meta?.sampleInput !== undefined) {
272
+ exampleLines.push(` * @example`);
273
+ exampleLines.push(` * // Sample input:`);
274
+ const inputStr = JSON.stringify(meta.sampleInput, null, 2);
275
+ for (const line of inputStr.split('\n')) {
276
+ exampleLines.push(` * ${line}`);
277
+ }
278
+ }
279
+ if (meta?.sampleOutput !== undefined) {
280
+ if (!meta?.sampleInput)
281
+ exampleLines.push(` * @example`);
282
+ exampleLines.push(` * // Sample output:`);
283
+ const outputStr = JSON.stringify(meta.sampleOutput, null, 2);
284
+ for (const line of outputStr.split('\n')) {
285
+ exampleLines.push(` * ${line}`);
286
+ }
287
+ }
288
+ exampleLines.push(` */`);
289
+ }
267
290
  // ── Assemble output ──
268
- // Order: extracted interfaces → input → output → function declaration
291
+ // Order: extracted interfaces → input → output → JSDoc with examples → function declaration
269
292
  const result = [];
270
293
  if (extractedLines.length > 0) {
271
294
  result.push(...extractedLines);
272
295
  }
273
296
  result.push(...lines);
297
+ if (exampleLines.length > 0) {
298
+ result.push(...exampleLines);
299
+ }
274
300
  result.push(funcDecl);
275
301
  return result.join("\n");
276
302
  }
@@ -288,6 +314,8 @@ function generateAllTypes(functions) {
288
314
  module: fn.module,
289
315
  env: fn.env,
290
316
  observedAt: fn.observedAt,
317
+ sampleInput: fn.sampleInput,
318
+ sampleOutput: fn.sampleOutput,
291
319
  }));
292
320
  sections.push("");
293
321
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trickle-backend",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -13,6 +13,8 @@ interface FunctionTypeData {
13
13
  module?: string;
14
14
  env?: string;
15
15
  observedAt?: string;
16
+ sampleInput?: unknown;
17
+ sampleOutput?: unknown;
16
18
  }
17
19
 
18
20
  function tryParseJson(value: string): unknown {
@@ -65,6 +67,8 @@ function collectFunctionTypes(opts: {
65
67
  module: moduleName,
66
68
  env: (snapshot.env as string) || environment,
67
69
  observedAt: snapshot.observed_at as string,
70
+ sampleInput: snapshot.sample_input ? tryParseJson(snapshot.sample_input as string) : undefined,
71
+ sampleOutput: snapshot.sample_output ? tryParseJson(snapshot.sample_output as string) : undefined,
68
72
  });
69
73
  }
70
74
 
@@ -178,7 +178,7 @@ export function generateFunctionTypes(
178
178
  functionName: string,
179
179
  argsType: TypeNode,
180
180
  returnType: TypeNode,
181
- meta?: { module?: string; env?: string; observedAt?: string },
181
+ meta?: { module?: string; env?: string; observedAt?: string; sampleInput?: unknown; sampleOutput?: unknown },
182
182
  ): string {
183
183
  const baseName = toPascalCase(functionName);
184
184
  const extracted: ExtractedInterface[] = [];
@@ -298,14 +298,41 @@ export function generateFunctionTypes(
298
298
  funcDecl = `export declare function ${funcIdent}(${params.join(", ")}): ${outputName};`;
299
299
  }
300
300
 
301
+ // ── Build @example JSDoc from sample data ──
302
+
303
+ const exampleLines: string[] = [];
304
+ if (meta?.sampleInput !== undefined || meta?.sampleOutput !== undefined) {
305
+ exampleLines.push(`/**`);
306
+ if (meta?.sampleInput !== undefined) {
307
+ exampleLines.push(` * @example`);
308
+ exampleLines.push(` * // Sample input:`);
309
+ const inputStr = JSON.stringify(meta.sampleInput, null, 2);
310
+ for (const line of inputStr.split('\n')) {
311
+ exampleLines.push(` * ${line}`);
312
+ }
313
+ }
314
+ if (meta?.sampleOutput !== undefined) {
315
+ if (!meta?.sampleInput) exampleLines.push(` * @example`);
316
+ exampleLines.push(` * // Sample output:`);
317
+ const outputStr = JSON.stringify(meta.sampleOutput, null, 2);
318
+ for (const line of outputStr.split('\n')) {
319
+ exampleLines.push(` * ${line}`);
320
+ }
321
+ }
322
+ exampleLines.push(` */`);
323
+ }
324
+
301
325
  // ── Assemble output ──
302
- // Order: extracted interfaces → input → output → function declaration
326
+ // Order: extracted interfaces → input → output → JSDoc with examples → function declaration
303
327
 
304
328
  const result: string[] = [];
305
329
  if (extractedLines.length > 0) {
306
330
  result.push(...extractedLines);
307
331
  }
308
332
  result.push(...lines);
333
+ if (exampleLines.length > 0) {
334
+ result.push(...exampleLines);
335
+ }
309
336
  result.push(funcDecl);
310
337
 
311
338
  return result.join("\n");
@@ -322,6 +349,8 @@ export function generateAllTypes(
322
349
  module?: string;
323
350
  env?: string;
324
351
  observedAt?: string;
352
+ sampleInput?: unknown;
353
+ sampleOutput?: unknown;
325
354
  }>,
326
355
  ): string {
327
356
  const sections: string[] = [];
@@ -337,6 +366,8 @@ export function generateAllTypes(
337
366
  module: fn.module,
338
367
  env: fn.env,
339
368
  observedAt: fn.observedAt,
369
+ sampleInput: fn.sampleInput,
370
+ sampleOutput: fn.sampleOutput,
340
371
  }),
341
372
  );
342
373
  sections.push("");