AML Operation Methods Documentation
1. AML Basic Format
1.1 Standard Format
``xml
`
1.2 Operation Types
| Operation | Description | Example |
|---|---|---|
| get | Query | Get a list of objects or a single object |
| add | Create | Create a new object |
| edit | Edit | Modify an existing object |
| delete | Delete | Delete an object |
2. AML Operation Templates
2.1 Query Operation (get)
File location: /app/lib/aml/queries.ts
`typescript
// Query object list
export const queryTemplates = {
// ECR query
ecrList: (status?: string) =>
${status ? ${status} : ''}
,
// ECR single query
ecrById: (id: string) =>
,
// Part Query
partList: (partNumber?: string) =>
${partNumber ? ${partNumber} : ''}
,
// Vendor query
vendorList: () =>
,
// BOM query
bomList: (partId?: string) =>
${partId ? ${partId} : ''}
,
// Inventory query
inventoryList: () =>
};
`
2.2 Create Operation (add)
`typescript
// File location: /app/lib/aml/creates.ts
export const createTemplates = {
// Create ECR
ecr: (data: { changeNumber: string; title: string; description: string }) =>
${data.changeNumber}
new
,
// Create Part
part: (data: { partNumber: string; name: string; description?: string; unitCost?: number; weight?: number }) =>
${data.partNumber}
${data.description ? : ''}
${data.unitCost ? ${data.unitCost} : ''}
${data.weight ? ${data.weight} : ''}
,
// Create Vendor
vendor: (data: { name: string; contact?: string; phone?: string; email?: string; address?: string }) =>
${data.contact ? : ''}
${data.phone ? ${data.phone} : ''}
${data.email ? ${data.email} : ''}
${data.address ? : ''}
,
// Create BOM
bom: (data: { partId: string; itemId: string; quantity: number; unit?: string }) =>
${data.partId}
${data.itemId}
${data.quantity}
${data.unit ? ${data.unit} : ''}
};
`
2.3 Edit Operations (edit)
`typescript
// File location: /app/lib/aml/edits.ts
export const editTemplates = {
// Update ECR
ecr: (id: string, data: { status?: string; description?: string }) =>
${data.status ? ${data.status} : ''}
${data.description ? : ''}
,
// Update Part
part: (id: string, data: { name?: string; description?: string; unitCost?: number; weight?: number }) =>
${data.name ? : ''}
${data.description ? : ''}
${data.unitCost ? ${data.unitCost} : ''}
${data.weight ? ${data.weight} : ''}
,
// Update Vendor
vendor: (id: string, data: { name?: string; contact?: string; phone?: string; email?: string; address?: string }) =>
${data.name ? : ''}
${data.contact ? : ''}
${data.phone ? ${data.phone} : ''}
${data.email ? ${data.email} : ''}
${data.address ? : ''}
};
`
2.4 Delete Operation (delete)
`typescript
// File location: /app/lib/aml/deletes.ts
export const deleteTemplates = {
// Delete ECR
ecr: (id: string) =>
,
// Delete Part
part: (id: string) =>
,
// Delete Vendor
vendor: (id: string) =>
};
`
3. AML Call Encapsulation
File location: /app/lib/aml/index.ts
`typescript
import { executeAmlWithFallback } from '../SCSAI/fallback';
import { queryTemplates } from './queries';
import { createTemplates } from './creates';
import { editTemplates } from './edits';
import { deleteTemplates } from './deletes';
// Query object list
export async function queryItems(itemType: string, status?: string): Promise {
let aml: string;
switch (itemType) {
case 'ECR':
aml = queryTemplates.ecrList(status);
break;
case 'Part':
aml = queryTemplates.partList();
break;
case 'Vendor':
aml = queryTemplates.vendorList();
break;
case 'BOM':
aml = queryTemplates.bomList();
break;
case 'Inventory':
aml = queryTemplates.inventoryList();
break;
default:
throw new Error(Unsupported item type: ${itemType});
}
return await executeAmlWithFallback(aml, itemType);
}
// Create object
export async function createItem(itemType: string, data: any): Promise {
let aml: string;
switch (itemType) {
case 'ECR':
aml = createTemplates.ecr(data);
break;
case 'Part':
aml = createTemplates.part(data);
break;
case 'Vendor':
aml = createTemplates.vendor(data);
break;
case 'BOM':
aml = createTemplates.bom(data);
break;
default:
throw new Error(Unsupported item type: ${itemType});
}
return await executeAmlWithFallback(aml, itemType);
}
// Update object
export async function updateItem(itemType: string, id: string, data: any): Promise {
let aml: string;
switch (itemType) {
case 'ECR':
aml = editTemplates.ecr(id, data);
break;
case 'Part':
aml = editTemplates.part(id, data);
break;
case 'Vendor':
aml = editTemplates.vendor(id, data);
break;
default:
throw new Error(Unsupported item type: ${itemType});
}
return await executeAmlWithFallback(aml, itemType);
}
// Delete object
export async function deleteItem(itemType: string, id: string): Promise {
let aml: string;
switch (itemType) {
case 'ECR':
aml = deleteTemplates.ecr(id);
break;
case 'Part':
aml = deleteTemplates.part(id);
break;
case 'Vendor':
aml = deleteTemplates.vendor(id);
break;
default:
throw new Error(Unsupported item type: ${itemType});
}
return await executeAmlWithFallback(aml, itemType);
}
`
4. Common Object Types
4.1 Object Type List
| Object Type | Description | Main Fields |
|---|---|---|
| ECR | Engineering Change Request | change_number, title, description, status |
| ECO | Engineering Change Order | change_number, title, affected_items, status |
| Part | Component | part_number, name, description, unit_cost, weight |
| BOM | Bill of Materials | part_id, item_id, quantity, unit |
| Vendor | Supplier | name, contact, phone, email, address |
| Inventory | Stock | part_id, quantity, location, warehouse |
4.2 Status Flow
ECR Status:
- new → pending_approval → approved → in_progress → completed
- new → pending_approval → rejected
ECO Status:
- new → pending_approval → approved → in_progress → completed
- new → pending_approval → rejected
5. Quick Usage Example
`typescript
// File location: /app/api/objects/route.ts
import { queryItems, createItem, updateItem, deleteItem } from '@/app/lib/aml';
// GET /api/objects?type=ECR&status=pending_approval
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const type = searchParams.get('type') || 'ECR';
const status = searchParams.get('status');
const result = await queryItems(type, status);
return Response.json(result);
}
// POST /api/objects
export async function POST(request: Request) {
const { type, data } = await request.json();
const result = await createItem(type, data);
return Response.json(result);
}
// PUT /api/objects
export async function PUT(request: Request) {
const { type, id, data } = await request.json();
const result = await updateItem(type, id, data);
return Response.json(result);
}
// DELETE /api/objects
export async function DELETE(request: Request) {
const { searchParams } = new URL(request.url);
const type = searchParams.get('type');
const id = searchParams.get('id');
if (!type || !id) {
return Response.json({ success: false, error: 'Missing type or id' }, { status: 400 });
}
const result = await deleteItem(type, id);
return Response.json(result);
}
``
6. File Location Summary
| File | Location | Purpose |
|---|---|---|
| queries.ts | /app/lib/aml/queries.ts | Query templates |
| creates.ts | /app/lib/aml/creates.ts | Create templates |
| edits.ts | /app/lib/aml/edits.ts | Edit templates |
| deletes.ts | /app/lib/aml/deletes.ts | Delete templates |
| index.ts | /app/lib/aml/index.ts | Unified export and call encapsulation |
BossAgents