@mondaydotcomorg/atp-server 0.20.7 → 0.21.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.
- package/dist/aggregator/index.d.ts +17 -1
- package/dist/aggregator/index.d.ts.map +1 -1
- package/dist/aggregator/index.js +68 -0
- package/dist/aggregator/index.js.map +1 -1
- package/dist/explorer/index.d.ts +1 -18
- package/dist/explorer/index.d.ts.map +1 -1
- package/dist/explorer/index.js +4 -65
- package/dist/explorer/index.js.map +1 -1
- package/dist/index.cjs +881 -880
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +881 -880
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/aggregator/index.ts +81 -0
- package/src/core/request-scope.ts +3 -0
- package/src/explorer/index.ts +4 -79
package/package.json
CHANGED
package/src/aggregator/index.ts
CHANGED
|
@@ -313,4 +313,85 @@ export class APIAggregator {
|
|
|
313
313
|
getApiGroups(): string[] {
|
|
314
314
|
return this.apiGroups.map((g) => g.name);
|
|
315
315
|
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Generates a compact TypeScript definition for a single function.
|
|
319
|
+
* Includes input types with inline descriptions and compact output type.
|
|
320
|
+
* @param func - Function definition
|
|
321
|
+
* @param groupName - API group name
|
|
322
|
+
* @returns Compact TypeScript definition string
|
|
323
|
+
*/
|
|
324
|
+
generateCompactFunctionDefinition(func: CustomFunctionDef, groupName: string): string {
|
|
325
|
+
const groupPath = groupName.replace(/\//g, '.');
|
|
326
|
+
const inputType = this.generateCompactInputType(func.inputSchema);
|
|
327
|
+
const outputType = func.outputSchema
|
|
328
|
+
? this.generateCompactOutputType(func.outputSchema)
|
|
329
|
+
: 'unknown';
|
|
330
|
+
return `async function api.${groupPath}.${func.name}(${inputType}): Promise<${outputType}>`;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Generates compact input type with inline descriptions
|
|
335
|
+
*/
|
|
336
|
+
private generateCompactInputType(schema?: {
|
|
337
|
+
properties?: Record<string, any>;
|
|
338
|
+
required?: string[];
|
|
339
|
+
}): string {
|
|
340
|
+
if (!schema || !schema.properties) {
|
|
341
|
+
return '{}';
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const props: string[] = [];
|
|
345
|
+
const required = schema.required || [];
|
|
346
|
+
|
|
347
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
348
|
+
const prop = value as { type?: string; description?: string; enum?: any[] };
|
|
349
|
+
const isRequired = required.includes(key);
|
|
350
|
+
const tsType = prop.enum
|
|
351
|
+
? prop.enum.map((v: any) => `"${v}"`).join(' | ')
|
|
352
|
+
: this.jsonSchemaTypeToTS(prop.type ?? 'unknown');
|
|
353
|
+
const optional = isRequired ? '' : '?';
|
|
354
|
+
|
|
355
|
+
if (prop.description) {
|
|
356
|
+
const desc = prop.description.replace(/\n/g, ' ').substring(0, 100);
|
|
357
|
+
props.push(`/* ${desc} */ ${key}${optional}: ${tsType}`);
|
|
358
|
+
} else {
|
|
359
|
+
props.push(`${key}${optional}: ${tsType}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return `{ ${props.join('; ')} }`;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Generates compact output type with inline descriptions (top-level fields only, limited count)
|
|
368
|
+
*/
|
|
369
|
+
private generateCompactOutputType(schema: { properties?: Record<string, any> }): string {
|
|
370
|
+
if (!schema.properties) {
|
|
371
|
+
return 'unknown';
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const keys = Object.keys(schema.properties);
|
|
375
|
+
if (keys.length === 0) {
|
|
376
|
+
return 'unknown';
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const maxFields = 6;
|
|
380
|
+
const displayKeys = keys.slice(0, maxFields);
|
|
381
|
+
const props = displayKeys.map((key) => {
|
|
382
|
+
const prop = schema.properties![key] as { type?: string; description?: string };
|
|
383
|
+
const tsType = this.jsonSchemaTypeToTS(prop.type ?? 'unknown');
|
|
384
|
+
|
|
385
|
+
if (prop.description) {
|
|
386
|
+
const desc = prop.description.replace(/\n/g, ' ').substring(0, 80);
|
|
387
|
+
return `/* ${desc} */ ${key}: ${tsType}`;
|
|
388
|
+
}
|
|
389
|
+
return `${key}: ${tsType}`;
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
if (keys.length > maxFields) {
|
|
393
|
+
return `{ ${props.join('; ')}; /* +${keys.length - maxFields} more */ }`;
|
|
394
|
+
}
|
|
395
|
+
return `{ ${props.join('; ')} }`;
|
|
396
|
+
}
|
|
316
397
|
}
|
package/src/explorer/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
CustomFunctionDef,
|
|
5
5
|
} from '@mondaydotcomorg/atp-protocol';
|
|
6
6
|
import { filterApiGroups } from '../core/request-scope.js';
|
|
7
|
+
import { APIAggregator } from '../aggregator/index.js';
|
|
7
8
|
|
|
8
9
|
interface TreeNode {
|
|
9
10
|
type: 'directory' | 'function';
|
|
@@ -31,8 +32,6 @@ interface ExploreFunctionResult {
|
|
|
31
32
|
description: string;
|
|
32
33
|
definition: string;
|
|
33
34
|
group: string;
|
|
34
|
-
inputSchema?: any;
|
|
35
|
-
outputSchema?: any;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
export type ExploreResult = ExploreDirectoryResult | ExploreFunctionResult;
|
|
@@ -46,10 +45,12 @@ export class ExplorerService {
|
|
|
46
45
|
private root: TreeNode;
|
|
47
46
|
private apiGroups: APIGroupConfig[];
|
|
48
47
|
private apiGroupMap: Map<string, APIGroupConfig>;
|
|
48
|
+
private aggregator: APIAggregator;
|
|
49
49
|
|
|
50
50
|
constructor(apiGroups: APIGroupConfig[]) {
|
|
51
51
|
this.apiGroups = apiGroups;
|
|
52
52
|
this.apiGroupMap = new Map(apiGroups.map((group) => [group.name, group]));
|
|
53
|
+
this.aggregator = new APIAggregator(apiGroups);
|
|
53
54
|
this.root = { type: 'directory', name: '/', children: new Map() };
|
|
54
55
|
this.buildTree(apiGroups);
|
|
55
56
|
}
|
|
@@ -319,7 +320,7 @@ export class ExplorerService {
|
|
|
319
320
|
return null;
|
|
320
321
|
}
|
|
321
322
|
|
|
322
|
-
const definition = this.
|
|
323
|
+
const definition = this.aggregator.generateCompactFunctionDefinition(func, group);
|
|
323
324
|
|
|
324
325
|
return {
|
|
325
326
|
type: 'function',
|
|
@@ -328,8 +329,6 @@ export class ExplorerService {
|
|
|
328
329
|
description: func.description,
|
|
329
330
|
definition,
|
|
330
331
|
group,
|
|
331
|
-
inputSchema: func.inputSchema,
|
|
332
|
-
outputSchema: func.outputSchema,
|
|
333
332
|
};
|
|
334
333
|
}
|
|
335
334
|
}
|
|
@@ -350,78 +349,4 @@ export class ExplorerService {
|
|
|
350
349
|
|
|
351
350
|
return path;
|
|
352
351
|
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Generates TypeScript function signature showing how to call the function.
|
|
356
|
-
*/
|
|
357
|
-
private generateFunctionDefinition(func: CustomFunctionDef, group: string): string {
|
|
358
|
-
const inputType = this.generateInputType(func.inputSchema);
|
|
359
|
-
const groupPath = group.replace(/\//g, '.');
|
|
360
|
-
const outputType = func.outputSchema ? this.generateOutputType(func.outputSchema) : 'unknown';
|
|
361
|
-
return `async function api.${groupPath}.${func.name}(${inputType}): Promise<${outputType}>`;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Generates TypeScript type from JSON schema
|
|
366
|
-
*/
|
|
367
|
-
private generateInputType(schema?: {
|
|
368
|
-
properties?: Record<string, any>;
|
|
369
|
-
required?: string[];
|
|
370
|
-
}): string {
|
|
371
|
-
if (!schema || !schema.properties) {
|
|
372
|
-
return '{}';
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const props: string[] = [];
|
|
376
|
-
const required = schema.required || [];
|
|
377
|
-
|
|
378
|
-
for (const [key, value] of Object.entries(schema.properties)) {
|
|
379
|
-
const isRequired = required.includes(key);
|
|
380
|
-
const prop = value as { type?: string; description?: string };
|
|
381
|
-
const tsType = this.jsonSchemaTypeToTS(prop.type ?? 'any');
|
|
382
|
-
const optional = isRequired ? '' : '?';
|
|
383
|
-
props.push(`${key}${optional}: ${tsType}`);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return `{ ${props.join('; ')} }`;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Generates output type from JSON schema
|
|
391
|
-
*/
|
|
392
|
-
private generateOutputType(schema: { properties?: Record<string, any> }): string {
|
|
393
|
-
if (!schema.properties) {
|
|
394
|
-
return 'unknown';
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const props: string[] = [];
|
|
398
|
-
for (const [key, value] of Object.entries(schema.properties)) {
|
|
399
|
-
const prop = value as { type?: string };
|
|
400
|
-
const tsType = this.jsonSchemaTypeToTS(prop.type ?? 'any');
|
|
401
|
-
props.push(`${key}: ${tsType}`);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
return `{ ${props.join('; ')} }`;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Converts JSON Schema type to TypeScript type
|
|
409
|
-
*/
|
|
410
|
-
private jsonSchemaTypeToTS(type: string): string {
|
|
411
|
-
switch (type) {
|
|
412
|
-
case 'string':
|
|
413
|
-
return 'string';
|
|
414
|
-
case 'number':
|
|
415
|
-
case 'integer':
|
|
416
|
-
return 'number';
|
|
417
|
-
case 'boolean':
|
|
418
|
-
return 'boolean';
|
|
419
|
-
case 'array':
|
|
420
|
-
return 'any[]';
|
|
421
|
-
case 'object':
|
|
422
|
-
return 'Record<string, any>';
|
|
423
|
-
default:
|
|
424
|
-
return 'any';
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
352
|
}
|