trickle-cli 0.1.0

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.
Files changed (125) hide show
  1. package/dist/api-client.d.ts +208 -0
  2. package/dist/api-client.js +237 -0
  3. package/dist/commands/annotate.d.ts +6 -0
  4. package/dist/commands/annotate.js +433 -0
  5. package/dist/commands/audit.d.ts +7 -0
  6. package/dist/commands/audit.js +82 -0
  7. package/dist/commands/auto.d.ts +8 -0
  8. package/dist/commands/auto.js +268 -0
  9. package/dist/commands/capture.d.ts +14 -0
  10. package/dist/commands/capture.js +271 -0
  11. package/dist/commands/check.d.ts +6 -0
  12. package/dist/commands/check.js +408 -0
  13. package/dist/commands/codegen.d.ts +21 -0
  14. package/dist/commands/codegen.js +129 -0
  15. package/dist/commands/coverage.d.ts +13 -0
  16. package/dist/commands/coverage.js +126 -0
  17. package/dist/commands/dashboard.d.ts +1 -0
  18. package/dist/commands/dashboard.js +83 -0
  19. package/dist/commands/dev.d.ts +14 -0
  20. package/dist/commands/dev.js +319 -0
  21. package/dist/commands/diff.d.ts +7 -0
  22. package/dist/commands/diff.js +79 -0
  23. package/dist/commands/docs.d.ts +13 -0
  24. package/dist/commands/docs.js +383 -0
  25. package/dist/commands/errors.d.ts +7 -0
  26. package/dist/commands/errors.js +180 -0
  27. package/dist/commands/export.d.ts +18 -0
  28. package/dist/commands/export.js +238 -0
  29. package/dist/commands/functions.d.ts +6 -0
  30. package/dist/commands/functions.js +71 -0
  31. package/dist/commands/infer.d.ts +14 -0
  32. package/dist/commands/infer.js +275 -0
  33. package/dist/commands/init.d.ts +5 -0
  34. package/dist/commands/init.js +395 -0
  35. package/dist/commands/mock.d.ts +5 -0
  36. package/dist/commands/mock.js +232 -0
  37. package/dist/commands/openapi.d.ts +8 -0
  38. package/dist/commands/openapi.js +82 -0
  39. package/dist/commands/overview.d.ts +11 -0
  40. package/dist/commands/overview.js +266 -0
  41. package/dist/commands/pack.d.ts +11 -0
  42. package/dist/commands/pack.js +133 -0
  43. package/dist/commands/proxy.d.ts +13 -0
  44. package/dist/commands/proxy.js +312 -0
  45. package/dist/commands/replay.d.ts +14 -0
  46. package/dist/commands/replay.js +289 -0
  47. package/dist/commands/run.d.ts +17 -0
  48. package/dist/commands/run.js +997 -0
  49. package/dist/commands/sample.d.ts +13 -0
  50. package/dist/commands/sample.js +260 -0
  51. package/dist/commands/search.d.ts +5 -0
  52. package/dist/commands/search.js +80 -0
  53. package/dist/commands/stubs.d.ts +6 -0
  54. package/dist/commands/stubs.js +187 -0
  55. package/dist/commands/tail.d.ts +4 -0
  56. package/dist/commands/tail.js +76 -0
  57. package/dist/commands/test-gen.d.ts +13 -0
  58. package/dist/commands/test-gen.js +237 -0
  59. package/dist/commands/trace.d.ts +14 -0
  60. package/dist/commands/trace.js +417 -0
  61. package/dist/commands/types.d.ts +7 -0
  62. package/dist/commands/types.js +128 -0
  63. package/dist/commands/unpack.d.ts +11 -0
  64. package/dist/commands/unpack.js +166 -0
  65. package/dist/commands/validate.d.ts +13 -0
  66. package/dist/commands/validate.js +310 -0
  67. package/dist/commands/watch.d.ts +9 -0
  68. package/dist/commands/watch.js +267 -0
  69. package/dist/config.d.ts +1 -0
  70. package/dist/config.js +66 -0
  71. package/dist/formatters/diff-formatter.d.ts +5 -0
  72. package/dist/formatters/diff-formatter.js +43 -0
  73. package/dist/formatters/type-formatter.d.ts +22 -0
  74. package/dist/formatters/type-formatter.js +135 -0
  75. package/dist/index.d.ts +2 -0
  76. package/dist/index.js +419 -0
  77. package/dist/local-codegen.d.ts +22 -0
  78. package/dist/local-codegen.js +762 -0
  79. package/dist/ui/badges.d.ts +16 -0
  80. package/dist/ui/badges.js +71 -0
  81. package/dist/ui/helpers.d.ts +13 -0
  82. package/dist/ui/helpers.js +85 -0
  83. package/package.json +23 -0
  84. package/src/api-client.ts +407 -0
  85. package/src/commands/annotate.ts +450 -0
  86. package/src/commands/audit.ts +103 -0
  87. package/src/commands/auto.ts +268 -0
  88. package/src/commands/capture.ts +257 -0
  89. package/src/commands/check.ts +437 -0
  90. package/src/commands/codegen.ts +128 -0
  91. package/src/commands/coverage.ts +170 -0
  92. package/src/commands/dashboard.ts +46 -0
  93. package/src/commands/dev.ts +323 -0
  94. package/src/commands/diff.ts +99 -0
  95. package/src/commands/docs.ts +392 -0
  96. package/src/commands/errors.ts +205 -0
  97. package/src/commands/export.ts +287 -0
  98. package/src/commands/functions.ts +81 -0
  99. package/src/commands/infer.ts +260 -0
  100. package/src/commands/init.ts +419 -0
  101. package/src/commands/mock.ts +220 -0
  102. package/src/commands/openapi.ts +53 -0
  103. package/src/commands/overview.ts +310 -0
  104. package/src/commands/pack.ts +139 -0
  105. package/src/commands/proxy.ts +314 -0
  106. package/src/commands/replay.ts +356 -0
  107. package/src/commands/run.ts +1190 -0
  108. package/src/commands/sample.ts +259 -0
  109. package/src/commands/search.ts +107 -0
  110. package/src/commands/stubs.ts +211 -0
  111. package/src/commands/tail.ts +94 -0
  112. package/src/commands/test-gen.ts +236 -0
  113. package/src/commands/trace.ts +440 -0
  114. package/src/commands/types.ts +161 -0
  115. package/src/commands/unpack.ts +179 -0
  116. package/src/commands/validate.ts +368 -0
  117. package/src/commands/watch.ts +277 -0
  118. package/src/config.ts +38 -0
  119. package/src/formatters/diff-formatter.ts +51 -0
  120. package/src/formatters/type-formatter.ts +161 -0
  121. package/src/index.ts +454 -0
  122. package/src/local-codegen.ts +859 -0
  123. package/src/ui/badges.ts +66 -0
  124. package/src/ui/helpers.ts +80 -0
  125. package/tsconfig.json +8 -0
@@ -0,0 +1,208 @@
1
+ export interface FunctionRow {
2
+ id: number;
3
+ function_name: string;
4
+ module: string;
5
+ language: string;
6
+ environment: string;
7
+ first_seen_at: string;
8
+ last_seen_at: string;
9
+ }
10
+ export interface FunctionDetail {
11
+ function: FunctionRow;
12
+ latestSnapshots: Record<string, TypeSnapshot>;
13
+ }
14
+ export interface TypeSnapshot {
15
+ id: number;
16
+ function_id: number;
17
+ type_hash: string;
18
+ env: string;
19
+ args_type: unknown;
20
+ return_type: unknown;
21
+ observed_at: string;
22
+ sample_input?: unknown;
23
+ sample_output?: unknown;
24
+ }
25
+ export interface ErrorRow {
26
+ id: number;
27
+ function_id: number;
28
+ function_name: string;
29
+ module: string;
30
+ language: string;
31
+ env: string;
32
+ error_type: string;
33
+ error_message: string;
34
+ stack_trace?: string;
35
+ type_hash?: string;
36
+ args_type?: unknown;
37
+ return_type?: unknown;
38
+ variables_type?: unknown;
39
+ args_snapshot?: unknown;
40
+ occurred_at: string;
41
+ }
42
+ export interface ErrorDetail {
43
+ error: ErrorRow;
44
+ snapshot: TypeSnapshot | null;
45
+ }
46
+ export interface TypeDiff {
47
+ kind: "added" | "removed" | "changed";
48
+ path: string;
49
+ from?: unknown;
50
+ to?: unknown;
51
+ type?: unknown;
52
+ }
53
+ export interface DiffResponse {
54
+ from: {
55
+ id: number;
56
+ env: string;
57
+ observed_at: string;
58
+ };
59
+ to: {
60
+ id: number;
61
+ env: string;
62
+ observed_at: string;
63
+ };
64
+ diffs: TypeDiff[];
65
+ }
66
+ export interface TailEvent {
67
+ event: string;
68
+ data: Record<string, unknown>;
69
+ }
70
+ export interface ListFunctionsOpts {
71
+ env?: string;
72
+ language?: string;
73
+ search?: string;
74
+ limit?: number;
75
+ offset?: number;
76
+ }
77
+ export declare function listFunctions(opts?: ListFunctionsOpts): Promise<{
78
+ functions: FunctionRow[];
79
+ total: number;
80
+ }>;
81
+ export declare function getFunction(id: number): Promise<FunctionDetail>;
82
+ export interface ListErrorsOpts {
83
+ env?: string;
84
+ functionName?: string;
85
+ since?: string;
86
+ limit?: number;
87
+ offset?: number;
88
+ }
89
+ export declare function listErrors(opts?: ListErrorsOpts): Promise<{
90
+ errors: ErrorRow[];
91
+ total: number;
92
+ }>;
93
+ export declare function getError(id: number): Promise<ErrorDetail>;
94
+ export interface ListTypesOpts {
95
+ env?: string;
96
+ limit?: number;
97
+ }
98
+ export declare function listTypes(functionId: number, opts?: ListTypesOpts): Promise<{
99
+ snapshots: TypeSnapshot[];
100
+ }>;
101
+ export interface GetTypeDiffOpts {
102
+ from?: number;
103
+ to?: number;
104
+ fromEnv?: string;
105
+ toEnv?: string;
106
+ }
107
+ export declare function getTypeDiff(functionId: number, opts?: GetTypeDiffOpts): Promise<DiffResponse>;
108
+ export interface CodegenOpts {
109
+ functionName?: string;
110
+ env?: string;
111
+ language?: string;
112
+ format?: string;
113
+ }
114
+ export declare function fetchCodegen(opts?: CodegenOpts): Promise<{
115
+ types: string;
116
+ }>;
117
+ export interface AnnotationParam {
118
+ name: string;
119
+ type: string;
120
+ }
121
+ export interface AnnotationEntry {
122
+ params: AnnotationParam[];
123
+ returnType: string;
124
+ }
125
+ export declare function fetchAnnotations(opts?: {
126
+ env?: string;
127
+ language?: string;
128
+ }): Promise<{
129
+ annotations: Record<string, AnnotationEntry>;
130
+ }>;
131
+ export interface StubsResponse {
132
+ stubs: Record<string, {
133
+ ts: string;
134
+ python: string;
135
+ }>;
136
+ }
137
+ export declare function fetchStubs(opts?: {
138
+ env?: string;
139
+ }): Promise<StubsResponse>;
140
+ export interface MockRoute {
141
+ method: string;
142
+ path: string;
143
+ functionName: string;
144
+ module: string;
145
+ sampleInput: unknown;
146
+ sampleOutput: unknown;
147
+ observedAt: string;
148
+ }
149
+ export declare function fetchMockConfig(): Promise<{
150
+ routes: MockRoute[];
151
+ }>;
152
+ export interface SnapshotFunction {
153
+ name: string;
154
+ module: string;
155
+ env?: string;
156
+ argsType: unknown;
157
+ returnType: unknown;
158
+ }
159
+ export interface CheckSnapshot {
160
+ version: number;
161
+ createdAt: string;
162
+ functions: SnapshotFunction[];
163
+ }
164
+ export declare function fetchSnapshot(opts?: {
165
+ env?: string;
166
+ }): Promise<CheckSnapshot>;
167
+ export interface OpenApiOpts {
168
+ env?: string;
169
+ title?: string;
170
+ version?: string;
171
+ serverUrl?: string;
172
+ }
173
+ export declare function fetchOpenApiSpec(opts?: OpenApiOpts): Promise<object>;
174
+ export interface DiffReportEntry {
175
+ functionName: string;
176
+ module: string;
177
+ language: string;
178
+ from: {
179
+ id: number;
180
+ env: string;
181
+ observed_at: string;
182
+ type_hash: string;
183
+ };
184
+ to: {
185
+ id: number;
186
+ env: string;
187
+ observed_at: string;
188
+ type_hash: string;
189
+ };
190
+ diffs: TypeDiff[];
191
+ }
192
+ export interface DiffReportResponse {
193
+ mode: "temporal" | "cross-env";
194
+ entries: DiffReportEntry[];
195
+ total: number;
196
+ since?: string | null;
197
+ env?: string | null;
198
+ env1?: string;
199
+ env2?: string;
200
+ }
201
+ export interface DiffReportOpts {
202
+ since?: string;
203
+ env?: string;
204
+ env1?: string;
205
+ env2?: string;
206
+ }
207
+ export declare function fetchDiffReport(opts?: DiffReportOpts): Promise<DiffReportResponse>;
208
+ export declare function tailEvents(onEvent: (event: TailEvent) => void, filter?: string): () => void;
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.listFunctions = listFunctions;
40
+ exports.getFunction = getFunction;
41
+ exports.listErrors = listErrors;
42
+ exports.getError = getError;
43
+ exports.listTypes = listTypes;
44
+ exports.getTypeDiff = getTypeDiff;
45
+ exports.fetchCodegen = fetchCodegen;
46
+ exports.fetchAnnotations = fetchAnnotations;
47
+ exports.fetchStubs = fetchStubs;
48
+ exports.fetchMockConfig = fetchMockConfig;
49
+ exports.fetchSnapshot = fetchSnapshot;
50
+ exports.fetchOpenApiSpec = fetchOpenApiSpec;
51
+ exports.fetchDiffReport = fetchDiffReport;
52
+ exports.tailEvents = tailEvents;
53
+ const http = __importStar(require("http"));
54
+ const https = __importStar(require("https"));
55
+ const url_1 = require("url");
56
+ const chalk_1 = __importDefault(require("chalk"));
57
+ const config_1 = require("./config");
58
+ // ── Helpers ──
59
+ function backendUrl() {
60
+ return (0, config_1.getBackendUrl)();
61
+ }
62
+ function connectionError() {
63
+ const url = backendUrl();
64
+ console.error(chalk_1.default.red(`\nCannot connect to trickle backend at ${chalk_1.default.bold(url)}.`));
65
+ console.error(chalk_1.default.red("Is the backend running?\n"));
66
+ process.exit(1);
67
+ }
68
+ async function fetchJson(path, query) {
69
+ const base = backendUrl();
70
+ const url = new url_1.URL(path, base);
71
+ if (query) {
72
+ for (const [key, value] of Object.entries(query)) {
73
+ if (value !== undefined && value !== "") {
74
+ url.searchParams.set(key, value);
75
+ }
76
+ }
77
+ }
78
+ try {
79
+ const res = await fetch(url.toString());
80
+ if (!res.ok) {
81
+ const body = await res.text();
82
+ throw new Error(`HTTP ${res.status}: ${body}`);
83
+ }
84
+ return (await res.json());
85
+ }
86
+ catch (err) {
87
+ if (err instanceof Error && err.message.startsWith("HTTP ")) {
88
+ throw err;
89
+ }
90
+ connectionError();
91
+ }
92
+ }
93
+ async function listFunctions(opts) {
94
+ return fetchJson("/api/functions", {
95
+ env: opts?.env,
96
+ language: opts?.language,
97
+ q: opts?.search,
98
+ limit: opts?.limit?.toString(),
99
+ offset: opts?.offset?.toString(),
100
+ });
101
+ }
102
+ async function getFunction(id) {
103
+ return fetchJson(`/api/functions/${id}`);
104
+ }
105
+ async function listErrors(opts) {
106
+ return fetchJson("/api/errors", {
107
+ env: opts?.env,
108
+ functionName: opts?.functionName,
109
+ since: opts?.since,
110
+ limit: opts?.limit?.toString(),
111
+ offset: opts?.offset?.toString(),
112
+ });
113
+ }
114
+ async function getError(id) {
115
+ return fetchJson(`/api/errors/${id}`);
116
+ }
117
+ async function listTypes(functionId, opts) {
118
+ return fetchJson(`/api/types/${functionId}`, {
119
+ env: opts?.env,
120
+ limit: opts?.limit?.toString(),
121
+ });
122
+ }
123
+ async function getTypeDiff(functionId, opts) {
124
+ return fetchJson(`/api/types/${functionId}/diff`, {
125
+ from: opts?.from?.toString(),
126
+ to: opts?.to?.toString(),
127
+ fromEnv: opts?.fromEnv,
128
+ toEnv: opts?.toEnv,
129
+ });
130
+ }
131
+ async function fetchCodegen(opts) {
132
+ const pathStr = opts?.functionName
133
+ ? `/api/codegen/${encodeURIComponent(opts.functionName)}`
134
+ : "/api/codegen";
135
+ return fetchJson(pathStr, {
136
+ env: opts?.env,
137
+ language: opts?.language,
138
+ format: opts?.format,
139
+ });
140
+ }
141
+ async function fetchAnnotations(opts) {
142
+ return fetchJson("/api/codegen", {
143
+ env: opts?.env,
144
+ language: opts?.language,
145
+ format: "annotate",
146
+ });
147
+ }
148
+ async function fetchStubs(opts) {
149
+ return fetchJson("/api/codegen", {
150
+ env: opts?.env,
151
+ format: "stubs",
152
+ });
153
+ }
154
+ async function fetchMockConfig() {
155
+ return fetchJson("/api/mock-config");
156
+ }
157
+ async function fetchSnapshot(opts) {
158
+ return fetchJson("/api/codegen", {
159
+ format: "snapshot",
160
+ env: opts?.env,
161
+ });
162
+ }
163
+ async function fetchOpenApiSpec(opts) {
164
+ return fetchJson("/api/codegen", {
165
+ format: "openapi",
166
+ env: opts?.env,
167
+ title: opts?.title,
168
+ version: opts?.version,
169
+ serverUrl: opts?.serverUrl,
170
+ });
171
+ }
172
+ async function fetchDiffReport(opts) {
173
+ return fetchJson("/api/diff", {
174
+ since: opts?.since,
175
+ env: opts?.env,
176
+ env1: opts?.env1,
177
+ env2: opts?.env2,
178
+ });
179
+ }
180
+ function tailEvents(onEvent, filter) {
181
+ const base = backendUrl();
182
+ const url = new url_1.URL("/api/tail", base);
183
+ if (filter) {
184
+ url.searchParams.set("filter", filter);
185
+ }
186
+ const mod = url.protocol === "https:" ? https : http;
187
+ let destroyed = false;
188
+ let currentReq = null;
189
+ function connect() {
190
+ if (destroyed)
191
+ return;
192
+ const req = mod.get(url.toString(), (res) => {
193
+ let buffer = "";
194
+ res.on("data", (chunk) => {
195
+ buffer += chunk.toString();
196
+ const lines = buffer.split("\n");
197
+ buffer = lines.pop() || "";
198
+ let currentEvent = "";
199
+ for (const line of lines) {
200
+ if (line.startsWith("event: ")) {
201
+ currentEvent = line.slice(7).trim();
202
+ }
203
+ else if (line.startsWith("data: ")) {
204
+ const dataStr = line.slice(6).trim();
205
+ try {
206
+ const data = JSON.parse(dataStr);
207
+ onEvent({ event: currentEvent, data });
208
+ }
209
+ catch {
210
+ // Ignore invalid JSON
211
+ }
212
+ currentEvent = "";
213
+ }
214
+ }
215
+ });
216
+ res.on("end", () => {
217
+ if (!destroyed) {
218
+ // Reconnect after a delay
219
+ setTimeout(connect, 2000);
220
+ }
221
+ });
222
+ });
223
+ req.on("error", () => {
224
+ if (!destroyed) {
225
+ setTimeout(connect, 3000);
226
+ }
227
+ });
228
+ currentReq = req;
229
+ }
230
+ connect();
231
+ return () => {
232
+ destroyed = true;
233
+ if (currentReq) {
234
+ currentReq.destroy();
235
+ }
236
+ };
237
+ }
@@ -0,0 +1,6 @@
1
+ export interface AnnotateOptions {
2
+ env?: string;
3
+ dryRun?: boolean;
4
+ jsdoc?: boolean;
5
+ }
6
+ export declare function annotateCommand(file: string, opts: AnnotateOptions): Promise<void>;