40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
|
|
/* eslint-env node */
|
||
|
|
import fs from 'node:fs'
|
||
|
|
import path from 'node:path'
|
||
|
|
import { fileURLToPath } from 'node:url'
|
||
|
|
|
||
|
|
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
||
|
|
const apiFile = path.join(currentDir, 'index.ts')
|
||
|
|
const interfaceFile = path.join(currentDir, 'interface', 'index.ts')
|
||
|
|
|
||
|
|
const apiSource = fs.readFileSync(apiFile, 'utf8')
|
||
|
|
const interfaceSource = fs.readFileSync(interfaceFile, 'utf8')
|
||
|
|
|
||
|
|
const expectations = [
|
||
|
|
['equipment payload maps devType', /devType:\s*params\.dev_type/],
|
||
|
|
['equipment payload maps devModel', /devModel:\s*params\.dev_model/],
|
||
|
|
['equipment payload maps devAccessMethod', /devAccessMethod:\s*params\.dev_access_method/],
|
||
|
|
['equipment payload maps nodeId', /nodeId:\s*params\.node_id/],
|
||
|
|
['equipment payload maps nodeProcess', /nodeProcess:\s*resolveOptionalNumber\(params\.node_process\)/],
|
||
|
|
['line payload maps lineId', /lineId:\s*resolveOptionalText\(params\.line_id\s*\|\|\s*params\.id\)/],
|
||
|
|
['line payload maps lineNo', /lineNo:\s*params\.line_no/],
|
||
|
|
['line payload maps volGrade', /volGrade:\s*params\.vol_grade/],
|
||
|
|
['line payload maps ctRatio', /ctRatio:\s*params\.ct_ratio/],
|
||
|
|
['line payload maps isGovern', /isGovern:\s*params\.is_govern/],
|
||
|
|
['tree node supports parentId', /parentId\?:\s*string/],
|
||
|
|
['tree node supports parentIds', /parentIds\?:\s*string/],
|
||
|
|
['delete response type is boolean', /requestAddLedger<boolean>\('delete',\s*'\/node'/]
|
||
|
|
]
|
||
|
|
|
||
|
|
const failures = expectations.filter(([, pattern]) => !pattern.test(`${apiSource}\n${interfaceSource}`))
|
||
|
|
|
||
|
|
if (failures.length) {
|
||
|
|
console.error('addLedger API_DEBUG contract check failed:')
|
||
|
|
for (const [name] of failures) {
|
||
|
|
console.error(`- ${name}`)
|
||
|
|
}
|
||
|
|
process.exit(1)
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log('addLedger API_DEBUG contract check passed')
|