// Exercise actual UTS adapters and detail-page bindings with frozen responses; no network or storage. const fs = require('node:fs'); const path = require('node:path'); const vm = require('node:vm'); const assert = require('node:assert/strict'); const ts = require('D:/Develop/HBuilderX/plugins/uniapp-uts-v1/node_modules/@dcloudio/uni-uts-v1/lib/typescript/lib/typescript.js'); const root = path.resolve(__dirname, '..'); class Json { constructor(value = {}) { for (const [key, item] of Object.entries(value)) this[key] = wrap(item); } getString(key) { return typeof this[key] === 'string' ? this[key] : null; } getNumber(key) { return typeof this[key] === 'number' ? this[key] : null; } getBoolean(key) { return typeof this[key] === 'boolean' ? this[key] : null; } } function wrap(value) { return Array.isArray(value) ? value.map(wrap) : value && typeof value === 'object' ? new Json(value) : value; } let response; const modules = {}; function compile(source, filename, extras = {}) { const exports = {}; const compiled = ts.transpileModule(source, { reportDiagnostics: true, compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 } }); assert.equal((compiled.diagnostics || []).filter(item => item.category === ts.DiagnosticCategory.Error).length, 0, filename + ' transpiles'); vm.runInNewContext(compiled.outputText, { exports, UTSJSONObject: Json, Number, Math, Error, setTimeout, clearTimeout, require: name => name.endsWith('api.uts') ? { requestJson: async () => new Json(response), getSession: () => null } : name.endsWith('config.uts') ? { API_BASE_URL: 'https://synthetic.invalid/api/v1' } : name.endsWith('records.uts') ? { revisionParams: value => ({ revisionId: value }) } : name.endsWith('layout.uts') ? { usePageLayout: () => ({}) } : name.endsWith('.uvue') || name.endsWith('assistant.uts') ? {} : load(name.startsWith('@/') ? name.slice(2) : path.posix.normalize(path.posix.dirname(filename) + '/' + name)), ...extras }, { filename }); return exports; } function load(filename) { if (modules[filename]) return modules[filename]; const source = fs.readFileSync(path.join(root, filename), 'utf8').replace(/const (fieldNames|labels): UTSJSONObject = (.*)/g, 'const $1: UTSJSONObject = new UTSJSONObject($2)'); return modules[filename] = compile(source, filename); } function page(kind, exposure) { const filename = `packages/finance/${kind}/${kind}.uvue`; const source = fs.readFileSync(path.join(root, filename), 'utf8').match(/