sasjs-framework
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSASjs Framework — Building SASjs Applications
SASjs框架——构建SASjs应用
A SASjs app = a web frontend (any framework: Angular, React, vanilla) + SAS backend code organised in a standard layout, compiled and deployed by to SAS 9, Viya, or SASjs server. Frontend talks to SAS via ; backend services return JSON via .
@sasjs/cli@sasjs/adapter_weboutSASjs应用 = Web前端(任意框架:Angular、React、原生JS)+ 按标准布局组织的SAS后端代码,通过编译并部署到SAS 9、Viya或SASjs server。前端通过与SAS通信;后端服务通过返回JSON。
@sasjs/cli@sasjs/adapter_weboutStandard project layout
标准项目布局
sasjs/
sasjsconfig.json # project + target configuration
macros/ # project-specific macros (macroFolders)
services/ # web services called from the frontend
jobs/ # jobs (scheduled / flow / long-running)
programs/ # plain programs (initProgram, termProgram, utilities)
db/ # DDL + static data per library (sasjs db)
tests/ # tests run by `sasjs test`
mocks/ # mock responses for offline frontend dev (syncFolder)
doxy/ # extra doxygen content for `sasjs doc`sasjs/
sasjsconfig.json # 项目 + 目标环境配置
macros/ # 项目专属宏(macroFolders)
services/ # 前端调用的Web服务
jobs/ # 任务(可调度/流式/长时间运行)
programs/ # 普通程序(initProgram、termProgram、工具类)
db/ # 每个库对应的DDL + 静态数据(sasjs db)
tests/ # 通过`sasjs test`运行的测试用例
mocks/ # 供前端离线开发使用的模拟响应(syncFolder)
doxy/ # 用于`sasjs doc`的额外doxygen内容sasjsconfig.json
sasjsconfig.json
Root config holds defaults; each entry in can override them. Key sections:
targets[]- ,
macroFolders— where the CLI finds macros/binariesbinaryFolders - — service source folders;
serviceConfig.serviceFoldersruns before every service (set up libnames, options)initProgram - — job source folders
jobConfig.jobFolders - — programs compiled/deployed with the app
programFolders - —
streamConfigstreams the built frontend into SAS so it is served by the platform itself (no separate web server needed);streamWeb: truepoints at the frontend build outputwebSourcePath - — folder synced to the server (e.g. mocks)
syncFolder - — init/term programs for
testConfigsasjs test - — per-environment overrides:
targets[],serverUrl(serverType/SAS9/SASVIYA),SASJS(deploy root, e.g.appLoc), target-specific macroFolders (e.g./Public/app/myappfor platform shims),targets/viya/macros_viya,httpsAgentOptionsdeployConfig
The full JSON schema is bundled at next to this file — validate config changes against it. Reference it with .
sasjsconfig-schema.json"$schema": "https://cli.sasjs.io/sasjsconfig-schema.json"根配置文件保存默认设置;中的每个条目可覆盖默认值。核心配置部分:
targets[]- 、
macroFolders—— CLI查找宏/二进制文件的路径binaryFolders - —— 服务源码文件夹;
serviceConfig.serviceFolders会在每个服务运行前执行(用于设置库名、选项)initProgram - —— 任务源码文件夹
jobConfig.jobFolders - —— 随应用一起编译/部署的程序
programFolders - ——
streamConfig会将构建好的前端流式传输到SAS中,由平台自身提供服务(无需独立Web服务器);streamWeb: true指向前端构建输出目录webSourcePath - —— 同步到服务器的文件夹(例如mocks)
syncFolder - —— 用于
testConfig的初始化/终止程序sasjs test - —— 按环境区分的覆盖配置:
targets[]、serverUrl(serverType/SAS9/SASVIYA)、SASJS(部署根路径,例如appLoc)、目标环境专属的macroFolders(例如用于平台适配的/Public/app/myapp)、targets/viya/macros_viya、httpsAgentOptionsdeployConfig
完整的JSON schema随此文件捆绑在中——配置变更需以此为基准进行验证。可通过引用该schema。
sasjsconfig-schema.json"$schema": "https://cli.sasjs.io/sasjsconfig-schema.json"Service contract (frontend ↔ SAS)
服务契约(前端 ↔ SAS)
- Adapter POSTs to with input tables (arrays of objects) → work datasets named after the JS keys.
services/<folder>/<name> - Service SAS code runs after ; it reads inputs, does work, and writes output JSON to
initProgram._webout - Conventional pattern using @sasjs/core macros:
sas
/**
@file
@brief Example service returning data
<h4> SAS Macros </h4>
@li mp_jsonout.sas
@li mp_abort.sas
**/
/* validation / logic here */
%mp_jsonout(OPEN)
%mp_jsonout(OBJ,results,dslabel=results)
%mp_jsonout(CLOSE)- On error, abort cleanly with (
%mp_abort(...)is deprecated) so the adapter receives a structured error in the JSON, not a half-written response. Do not callmf_abortinside an%mp_abortblock — the macro processor may keep executing beyond the abort. Use the conditional%if/%elseparameter instead, e.g.:iftrue=
sas
%mp_abort(iftrue= (%mf_existds(work.results)=0)
,mac=&_program
,msg=%str(No results found)
)If the abort happens inside a block, SAS cannot exit to cleanly — after the include, call (outside any macro wrapper), which checks for an abort status.
%include_webout%mp_abort(mode=INCLUDE)work.mp_abort_errds- Adapter向发送POST请求,传入输入表(对象数组)→ 生成以JS键命名的工作数据集。
services/<folder>/<name> - 服务SAS代码在之后运行;读取输入数据、执行处理逻辑,并将输出JSON写入
initProgram。_webout - 使用@sasjs/core宏的常规模式:
sas
/**
@file
@brief 返回数据的示例服务
<h4> SAS宏 </h4>
@li mp_jsonout.sas
@li mp_abort.sas
**/
/* 验证/逻辑代码写在这里 */
%mp_jsonout(OPEN)
%mp_jsonout(OBJ,results,dslabel=results)
%mp_jsonout(CLOSE)- 发生错误时,通过(
%mp_abort(...)已废弃)干净地终止程序,确保Adapter能收到JSON格式的结构化错误响应,而非不完整的输出。请勿在mf_abort块内调用%if/%else——宏处理器可能会在终止后继续执行代码。请改用条件参数%mp_abort,例如:iftrue=
sas
%mp_abort(iftrue= (%mf_existds(work.results)=0)
,mac=&_program
,msg=%str(未找到结果)
)如果终止发生在块内,SAS无法干净地退出到——在include之后,调用(在任何宏包装器之外),该宏会检查中的终止状态。
%include_webout%mp_abort(mode=INCLUDE)work.mp_abort_errdsMulti-target discipline
多目标规范
- Keep backend code platform-neutral in shared folders; put platform-specific shims in folders and register them only on that target.
targets/<name>/macros_* - Platform capability macros exist in @sasjs/core (metadata,
mm_*Viya,mv_*server) — don't branch on server type by hand.ms_*
- 在共享文件夹中保持后端代码的平台中立性;将平台专属的适配代码放在文件夹中,并仅在对应目标环境中注册。
targets/<name>/macros_* - @sasjs/core中提供了平台能力宏(元数据、
mm_*Viya、mv_*server)——请勿手动根据服务器类型分支代码。ms_*
Quality gates (follow the conventions of mature apps like Data Controller)
质量管控(遵循Data Controller等成熟应用的规范)
- Run after touching any
sasjs lintfile; fix all warnings in files you touched..sas - The linter enforces 2-space indentation everywhere, including continuation lines inside block comments — never align comment text with 3+ spaces.
/* ... */ - Add tests under and run
sasjs/testsfor backend logic changes.sasjs test - Provide mocks in so the frontend can be developed without a live SAS server.
sasjs/mocks - Never auto-commit or bump versions; releases are pipeline-driven (conventional commits).
- Markdown files: no hard wrapping — one paragraph per line.
- Apps must work offline/on-prem: no external CDN assets in the frontend bundle.
- 修改任何文件后运行
.sas;修复你修改的文件中的所有警告。sasjs lint - 代码检查器强制要求所有地方使用2空格缩进,包括块注释内的换行——切勿用3个及以上空格对齐注释文本。
/* ... */ - 在下添加测试用例,后端逻辑变更时运行
sasjs/tests。sasjs test - 在中提供模拟数据,以便前端无需连接SAS服务器即可开发。
sasjs/mocks - 切勿自动提交或升级版本;版本发布由流水线驱动(遵循约定式提交规范)。
- Markdown文件:禁止硬换行——每段文字占一行。
- 应用必须支持离线/本地部署:前端包中不得包含外部CDN资源。
Reference implementations
参考实现
Look at existing apps for patterns: folder layouts, multi-target setups, service structure, streaming builds, and test/mock conventions (e.g. Data Controller , , ).
sasjsconfig.jsondcdwp_frsplato可参考现有应用的模式:文件夹布局、多目标配置、服务结构、流式构建、测试/模拟规范(例如Data Controller 、、)。
sasjsconfig.jsondcdwp_frsplato