开发者

MAD 是一个嵌入式关系型报表引擎:一份可移植的 .mad 文档、一个第一方 Objective-C 引擎,以及一个在 Linux 和 Windows 上以无头方式运行同一引擎的 mad 命令行工具。这些页面按你想做的事情来组织。

参与贡献? 阅读 CONTRIBUTING.md 了解前置条件、绿色基线和初始任务领域。AI 智能体? 从 AGENTS.md 和两个仓库技能开始: mad-verify 和 mad-headless-port。

嵌入引擎

一个链接了 MAD 框架、某个数据库驱动(MADMySQL、MADPostgres、MADTdsClient 或 MADSqlite3 中的 SQLite 驱动)以及用于本地行缓存的 MADSqlite3 的应用,无需服务器参与即可获得关系型报表能力。打开一份文档,通过共享的操作链刷新它,并通过格式注册表导出它:

#import <MAD/MADHeadlessDocument.h>
#import <MAD/MADDocumentDataProtocol.h>
#import <MAD/MADOperationRefreshInitalizeMainDataTable.h>
#import <MAD/MADOperationRefreshInitialize.h>
#import <MAD/MADOperationRefresh.h>
#import <MAD/MADReportExporterRegistry.h>
#import <MAD/MADReportExporting.h>
#import <MADFoundation/MADOperationQueue.h>

NSError *error = nil;
id <MADDocumentDataProtocol> document =
	[MADHeadlessDocument documentWithContentsOfURL: url error: &error];
if (document == nil) { /* report error */ }

MADOperationQueue *queue = [[MADOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 1;

MADOperationRefreshInitializeMainDataTable *initializeTable =
	[[MADOperationRefreshInitializeMainDataTable alloc] initWithDocument: document];
MADOperationRefreshInitialize *initialize =
	[[MADOperationRefreshInitialize alloc] initWithDocument: document];
MADOperationRefresh *refresh = [[MADOperationRefresh alloc] initWithDocument: document];

[initialize addDependency: initializeTable];
[refresh addDependency: initializeTable];
[refresh addDependency: initialize];

[queue addOperation: initializeTable];
[queue addOperation: initialize];
[queue addOperation: refresh];

// The operations are asynchronous; turn the run loop until they finish, as the CLI does.
while (queue.operationCount > 0) {
	@autoreleasepool {
		[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
								 beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.05]];
	}
}
if (refresh.errors.count > 0) { /* report refresh.errors.firstObject */ }

Class <MADReportExporting> exporterClass =
	[MADReportExporterRegistry exporterClassForFormat: @"html"];
id <MADReportExporting> exporter = [[(Class)exporterClass alloc] init];
[exporter exportDocument: document
				   toURL: outURL
				 options: MADReportExportOptionsNone
				   error: &error];

这就是 CLI 自己的路径: CLI/Source/MADCLIDocument.m 构建了完全相同的链,而 CLI/Source/MADCLIExport.m 按名称查找导出器,而不是指定某个类。源需要凭据的文档会添加一个采用 MADOperationHoldsCredentialsProtocol 的操作,作为刷新操作的依赖, 就像 CLI 的 MADCLICredentialsOperation 那样。组合文档采用 MADOperationRefreshComposed;+[MADOperationRefresh documentUsesComposedRefresh:] 是判断方法。

驱动 CLI

mad 命令行工具是带动词的同一引擎:inspect、 schema、query、refresh、export、write,以及 serve JSON 协议。 CLI 运行于 Linux 和 Windows;已发布的容器镜像是 linux/amd64。在 macOS 上,它是一个通过 iOS 模拟器运行的开发者构建 (CLI/build.sh 和 xcrun simctl spawn booted);它不是原生 macOS 二进制文件。

添加驱动

一个数据库驱动是两个类:一个返回架构和数据行的 MADDatabase 子类, 以及一个遵循 MADDatabaseDriver 并在 +load 中向 MADDatabaseDriverRegistry 注册的 MADDatabaseConnection 子类,因此 引擎无需分叉即可按类型构建它。驱动编写教程 从头到尾走完第一个驱动。实时套件(MADMySQLLiveTests、 MADTdsClientLiveTests、MADPostgresLiveTests)在没有可达服务器时会跳过, 因此框架套件在没有服务器时仍保持绿色。

添加导出格式

一个导出格式遵循 MADReportExporting,并在 +load 中向 MADReportExporterRegistry 注册自身;CLI 通过 --format 名称请求它,其他一切不变。该协议提供格式名称、 描述、文件扩展名、输出路径要求,以及一个面向构建可能不具备的机制的 +isAvailable 闸门。CLI 指南记录了导出接缝 (MADReportExporterRegistry)。

添加元素

一个文档元素是存储在可移植存储中、通过 RptqDocumentElementFactory 生成的 RptqDocumentElement 子类;渲染部分把它绘制为 MADPrintPageElement,而设计器需要为它提供一个视图。添加一个元素会 触及文档模型、设计器和渲染器,因此这是一项高级任务 而不是第一个贡献。阅读 数据对象设计了解布局在契约中的位置, 以及 MADDataTable 架构 了解数据行如何到达那里。

构建与验证

Apple 套件针对一个共享的派生数据路径运行(各框架 通过 BUILT_PRODUCTS_DIR 相互引用);按设备 id 选择模拟器:

xcrun simctl list devices available
xcodebuild test -workspace Reports.xcworkspace -scheme MADFoundation \
	-destination 'platform=iOS Simulator,id=<device-udid>' \
	-derivedDataPath ~/Library/Developer/Xcode/DerivedData/Reports-shared

无头引擎有自己的构建:

理解格式

参与贡献

MAD 由一位维护者和一个开放的开发流程支撑。适合上手的领域是 一处文档更正、一个钉住真实缺陷的测试、一个小型导出器,或对现有驱动的一处有范围 修复;新驱动或新元素是高级任务。阅读 CONTRIBUTING.md 了解前置条件、测试先行规则、DCO 签署,以及无头源文件变更时的 Linux 闸门, 寻找 good first issue 标签,并在 Discussions 中提问。 卫星仓库记录了 mad-action 和容器镜像如何从本仓库发布。

面向智能体

AI 智能体应从 AGENTS.md(仓库地图和批准门槛)开始。它的两个技能是 mad-verify, 把一项改动路由到能够因它而通过或失败的最廉价验证,以及 mad-headless-port, 把源文件移植进无头引擎。第一批任务与人类领域相同: 一处文档更正、一个钉住缺陷的测试,或一个小型导出器。

本页为英文原文的简体中文翻译;如有出入,以英文原文为准。