soma-core 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/core/build/blocks/block-compile.ts +31 -2
- package/core/build/blocks/block-container.ts +2 -11
- package/core/build/compiler/page-declaration-compiler.ts +30 -2
- package/core/build/compiler/soma-precompile.js +2053 -23
- package/core/build/component/component-graph.ts +208 -0
- package/core/build/component/package-loader.ts +32 -0
- package/core/build/eject/component-eject.ts +473 -0
- package/core/build/eject/component-upgrade.ts +359 -0
- package/core/build/layout/constraint-solver.ts +235 -0
- package/core/build/layout/css-emitter.ts +116 -0
- package/core/build/layout/page-layout.ts +85 -0
- package/core/build/pack/pack-init.ts +270 -0
- package/core/client/base/SomaHttpClient.ts +34 -1
- package/core/client/base/SomaPageRootBase.ts +61 -0
- package/core/client/component/ai-catalog.ts +121 -4
- package/core/client/component/component-defaults.ts +100 -0
- package/core/client/component/component-definition.types.ts +39 -0
- package/core/client/component/component-manager.ts +79 -4
- package/core/client/component/component-pack.ts +126 -2
- package/core/client/component/keyboard-matrix.ts +144 -0
- package/core/client/component/pack-styles.ts +59 -1
- package/core/client/component/style-features.ts +131 -0
- package/core/client/component/theme-component-tokens.ts +83 -0
- package/core/client/component/verify-pack.ts +120 -1
- package/core/client/container/SomaContainerAdapter.ts +6 -2
- package/core/client/data/data-object-resolver.ts +407 -4
- package/core/client/data/reaction-engine.ts +176 -0
- package/core/client/data/window-engine.ts +477 -0
- package/core/client/engine/event-engine.ts +98 -0
- package/core/client/engine/soma-bootstrap.ts +265 -5
- package/core/client/engine/step-runner.ts +134 -0
- package/core/client/infra/http/SomaHttpService.ts +2 -2
- package/core/client/parser/blocks/page-parser.ts +15 -1
- package/core/client/parser/blocks/use-parser.ts +5 -12
- package/core/client/parser/data-config-parser.ts +316 -8
- package/core/client/parser/duration.ts +16 -0
- package/core/client/parser/layout-parser.ts +157 -0
- package/core/client/parser/page-state-parser.ts +166 -0
- package/core/client/parser/pipeline-parser.ts +76 -1
- package/core/client/parser/reaction-parser.ts +459 -0
- package/core/client/parser/reaction-sugar.ts +47 -0
- package/core/client/parser/step-parser.ts +359 -0
- package/core/client/parser/ui-config-parser.ts +59 -0
- package/core/client/parser/window-parser.ts +294 -0
- package/core/client/theme/theme-engine.ts +102 -2
- package/core/index.ts +184 -0
- package/core/shared/block-errors.ts +11 -0
- package/core/shared/calc/coerce.ts +29 -0
- package/core/shared/calc/errors.ts +43 -0
- package/core/shared/calc/evaluator.ts +101 -0
- package/core/shared/calc/index.ts +12 -0
- package/core/shared/calc/lexer.ts +194 -0
- package/core/shared/calc/parser.ts +204 -0
- package/core/shared/calc/typer.ts +184 -0
- package/core/shared/component/derive-sample.ts +105 -0
- package/core/shared/component/field-lines.ts +473 -0
- package/core/shared/path-algebra.ts +169 -0
- package/core/shared/predicates/index.ts +527 -0
- package/core/shared/types/component-contract.types.ts +151 -9
- package/core/shared/types/data-config.types.ts +120 -1
- package/core/shared/types/domain.types.ts +13 -0
- package/core/shared/types/event.types.ts +22 -2
- package/core/shared/types/layout-constraint.types.ts +73 -0
- package/core/shared/types/page-state.types.ts +60 -0
- package/core/shared/types/reaction.types.ts +144 -0
- package/core/shared/types/step.types.ts +91 -0
- package/core/shared/types/ui-config.types.ts +18 -0
- package/core/shared/types/window.types.ts +177 -0
- package/dist/cli/soma.js +13 -1
- package/dist/core/index.cjs +5529 -631
- package/dist/types/build/blocks/block-container.d.ts +1 -6
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -0
- package/dist/types/build/component/component-graph.d.ts +85 -0
- package/dist/types/build/eject/component-eject.d.ts +121 -0
- package/dist/types/build/eject/component-upgrade.d.ts +43 -0
- package/dist/types/build/layout/constraint-solver.d.ts +36 -0
- package/dist/types/build/layout/css-emitter.d.ts +18 -0
- package/dist/types/build/layout/page-layout.d.ts +24 -0
- package/dist/types/build/pack/pack-init.d.ts +8 -0
- package/dist/types/client/base/SomaHttpClient.d.ts +8 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +28 -0
- package/dist/types/client/component/ai-catalog.d.ts +33 -1
- package/dist/types/client/component/component-defaults.d.ts +15 -0
- package/dist/types/client/component/component-definition.types.d.ts +38 -0
- package/dist/types/client/component/component-manager.d.ts +36 -0
- package/dist/types/client/component/component-pack.d.ts +32 -2
- package/dist/types/client/component/keyboard-matrix.d.ts +24 -0
- package/dist/types/client/component/pack-styles.d.ts +21 -0
- package/dist/types/client/component/style-features.d.ts +26 -0
- package/dist/types/client/component/theme-component-tokens.d.ts +14 -0
- package/dist/types/client/component/verify-pack.d.ts +10 -0
- package/dist/types/client/data/data-object-resolver.d.ts +106 -1
- package/dist/types/client/data/reaction-engine.d.ts +21 -0
- package/dist/types/client/data/window-engine.d.ts +27 -0
- package/dist/types/client/engine/event-engine.d.ts +15 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +70 -0
- package/dist/types/client/engine/step-runner.d.ts +24 -0
- package/dist/types/client/parser/blocks/use-parser.d.ts +2 -2
- package/dist/types/client/parser/duration.d.ts +1 -0
- package/dist/types/client/parser/layout-parser.d.ts +9 -0
- package/dist/types/client/parser/page-state-parser.d.ts +32 -0
- package/dist/types/client/parser/reaction-parser.d.ts +16 -0
- package/dist/types/client/parser/reaction-sugar.d.ts +13 -0
- package/dist/types/client/parser/step-parser.d.ts +23 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +5 -0
- package/dist/types/client/parser/window-parser.d.ts +25 -0
- package/dist/types/client/theme/theme-engine.d.ts +26 -0
- package/dist/types/index.d.ts +35 -2
- package/dist/types/shared/block-errors.d.ts +5 -0
- package/dist/types/shared/calc/coerce.d.ts +4 -0
- package/dist/types/shared/calc/errors.d.ts +14 -0
- package/dist/types/shared/calc/evaluator.d.ts +2 -0
- package/dist/types/shared/calc/index.d.ts +6 -0
- package/dist/types/shared/calc/lexer.d.ts +20 -0
- package/dist/types/shared/calc/parser.d.ts +49 -0
- package/dist/types/shared/calc/typer.d.ts +16 -0
- package/dist/types/shared/component/derive-sample.d.ts +23 -0
- package/dist/types/shared/component/field-lines.d.ts +19 -0
- package/dist/types/shared/path-algebra.d.ts +56 -0
- package/dist/types/shared/predicates/index.d.ts +79 -0
- package/dist/types/shared/types/component-contract.types.d.ts +134 -6
- package/dist/types/shared/types/data-config.types.d.ts +115 -1
- package/dist/types/shared/types/domain.types.d.ts +12 -0
- package/dist/types/shared/types/event.types.d.ts +8 -2
- package/dist/types/shared/types/layout-constraint.types.d.ts +52 -0
- package/dist/types/shared/types/page-state.types.d.ts +49 -0
- package/dist/types/shared/types/reaction.types.d.ts +115 -0
- package/dist/types/shared/types/step.types.d.ts +76 -0
- package/dist/types/shared/types/ui-config.types.d.ts +18 -0
- package/dist/types/shared/types/window.types.d.ts +171 -0
- package/package.json +3 -2
|
@@ -34,7 +34,7 @@ __export(soma_precompile_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(soma_precompile_exports);
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// node_modules/js-yaml/dist/js-yaml.mjs
|
|
38
38
|
function getDefaultExportFromCjs(x) {
|
|
39
39
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
40
40
|
}
|
|
@@ -1312,16 +1312,21 @@ function requireLoader() {
|
|
|
1312
1312
|
state.result += _result;
|
|
1313
1313
|
}
|
|
1314
1314
|
}
|
|
1315
|
+
function chargeMergeWork(state) {
|
|
1316
|
+
state.totalMergeKeys++;
|
|
1317
|
+
if (state.maxTotalMergeKeys !== -1 && state.totalMergeKeys > state.maxTotalMergeKeys) {
|
|
1318
|
+
throwError(state, "merge keys exceeded maxTotalMergeKeys (" + state.maxTotalMergeKeys + ")");
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1315
1321
|
function mergeMappings(state, destination, source, overridableKeys) {
|
|
1316
1322
|
if (!common2.isObject(source)) {
|
|
1317
1323
|
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1318
1324
|
}
|
|
1325
|
+
chargeMergeWork(state);
|
|
1319
1326
|
const sourceKeys = Object.keys(source);
|
|
1320
1327
|
for (let index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
|
|
1321
1328
|
const key = sourceKeys[index];
|
|
1322
|
-
|
|
1323
|
-
throwError(state, "merge keys exceeded maxTotalMergeKeys (" + state.maxTotalMergeKeys + ")");
|
|
1324
|
-
}
|
|
1329
|
+
chargeMergeWork(state);
|
|
1325
1330
|
if (!_hasOwnProperty.call(destination, key)) {
|
|
1326
1331
|
setProperty(destination, key, source[key]);
|
|
1327
1332
|
overridableKeys[key] = true;
|
|
@@ -1349,6 +1354,9 @@ function requireLoader() {
|
|
|
1349
1354
|
}
|
|
1350
1355
|
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
1351
1356
|
if (Array.isArray(valueNode)) {
|
|
1357
|
+
if (valueNode.length > 100) {
|
|
1358
|
+
throwError(state, "abnormal merge sequence size");
|
|
1359
|
+
}
|
|
1352
1360
|
for (let index = 0, quantity = valueNode.length; index < quantity; index += 1) {
|
|
1353
1361
|
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
1354
1362
|
}
|
|
@@ -3246,6 +3254,208 @@ function parseAdaptiveConfig(raw, vocabulary, path = "adaptive", options) {
|
|
|
3246
3254
|
return config;
|
|
3247
3255
|
}
|
|
3248
3256
|
|
|
3257
|
+
// core/client/parser/page-state-parser.ts
|
|
3258
|
+
var CONFIG_KEYS = /* @__PURE__ */ new Set(["version", "window", "columns", "density", "expanded", "initial_state", "url"]);
|
|
3259
|
+
var DENSITIES = /* @__PURE__ */ new Set(["sm", "md", "lg"]);
|
|
3260
|
+
function isPlainObject(value) {
|
|
3261
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3262
|
+
}
|
|
3263
|
+
function parsePageState(input, deps) {
|
|
3264
|
+
const { raw, objectNames, anchorIds, path } = input;
|
|
3265
|
+
const fail = deps.fail;
|
|
3266
|
+
if (!isPlainObject(raw)) fail("state \u5FC5\u987B\u662F\u6620\u5C04", path);
|
|
3267
|
+
for (const key of Object.keys(raw)) {
|
|
3268
|
+
if (!CONFIG_KEYS.has(key)) {
|
|
3269
|
+
fail(`\u672A\u77E5\u7684 state \u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: ${[...CONFIG_KEYS].join(" / ")}\uFF09`, `${path}.${key}`);
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
const version = raw.version;
|
|
3273
|
+
if (!Number.isInteger(version) || version < 1) {
|
|
3274
|
+
fail("state.version \u5FC5\u586B\uFF0C\u4E14\u5FC5\u987B\u662F \u2265 1 \u7684\u6574\u6570\uFF08\u5B83\u51B3\u5B9A\u4E00\u4EFD\u65E7\u72B6\u6001\u8BE5\u4E0D\u8BE5\u88AB\u4E22\u5F03\uFF09", `${path}.version`);
|
|
3275
|
+
}
|
|
3276
|
+
const names = (value, at, allowed, what) => {
|
|
3277
|
+
if (value === void 0) return [];
|
|
3278
|
+
if (!Array.isArray(value)) fail(`${at} \u5FC5\u987B\u662F\u540D\u5B57\u6570\u7EC4`, at);
|
|
3279
|
+
return value.map((entry) => {
|
|
3280
|
+
const name = String(entry);
|
|
3281
|
+
if (!allowed.includes(name)) {
|
|
3282
|
+
fail(`${at} \u91CC\u7684 "${name}" \u4E0D\u662F${what}\uFF08\u53EF\u9009\uFF1A${allowed.join(" / ") || "\u65E0"}\uFF09`, at);
|
|
3283
|
+
}
|
|
3284
|
+
return name;
|
|
3285
|
+
});
|
|
3286
|
+
};
|
|
3287
|
+
const windows = names(raw.window, `${path}.window`, objectNames, "\u672C\u9875\u58F0\u660E\u8FC7\u7684\u6570\u636E\u5BF9\u8C61");
|
|
3288
|
+
const columns = anchorIds === void 0 ? Array.isArray(raw.columns) ? raw.columns.map(String) : [] : names(raw.columns, `${path}.columns`, anchorIds, "\u672C\u9875\u7684\u951A\u70B9");
|
|
3289
|
+
const config = { version };
|
|
3290
|
+
if (windows.length > 0) config.window = windows;
|
|
3291
|
+
if (columns.length > 0) config.columns = columns;
|
|
3292
|
+
if (raw.density !== void 0) config.density = raw.density === true;
|
|
3293
|
+
if (raw.expanded !== void 0) config.expanded = raw.expanded === true;
|
|
3294
|
+
if (raw.url !== void 0) config.url = raw.url === true;
|
|
3295
|
+
if (raw.initial_state !== void 0) {
|
|
3296
|
+
config.initial_state = parseStateValue(raw.initial_state, `${path}.initial_state`, config, fail);
|
|
3297
|
+
}
|
|
3298
|
+
return config;
|
|
3299
|
+
}
|
|
3300
|
+
function parseStateValue(raw, path, config, fail) {
|
|
3301
|
+
if (!isPlainObject(raw)) fail(`${path} \u5FC5\u987B\u662F\u6620\u5C04`, path);
|
|
3302
|
+
const state = { version: config.version };
|
|
3303
|
+
if (raw.version !== void 0 && raw.version !== config.version) {
|
|
3304
|
+
state.version = raw.version;
|
|
3305
|
+
return state;
|
|
3306
|
+
}
|
|
3307
|
+
if (isPlainObject(raw.window)) {
|
|
3308
|
+
const allowed = config.window ?? [];
|
|
3309
|
+
const windows = {};
|
|
3310
|
+
for (const [name, slice] of Object.entries(raw.window)) {
|
|
3311
|
+
if (!allowed.includes(name)) continue;
|
|
3312
|
+
windows[name] = slice;
|
|
3313
|
+
}
|
|
3314
|
+
if (Object.keys(windows).length > 0) {
|
|
3315
|
+
state.window = windows;
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
if (isPlainObject(raw.columns)) {
|
|
3319
|
+
const allowed = config.columns ?? [];
|
|
3320
|
+
const columns = {};
|
|
3321
|
+
for (const [name, slice] of Object.entries(raw.columns)) {
|
|
3322
|
+
if (!allowed.includes(name)) continue;
|
|
3323
|
+
columns[name] = slice;
|
|
3324
|
+
}
|
|
3325
|
+
if (Object.keys(columns).length > 0) {
|
|
3326
|
+
state.columns = columns;
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
if (config.density && typeof raw.density === "string" && DENSITIES.has(raw.density)) {
|
|
3330
|
+
state.density = raw.density;
|
|
3331
|
+
}
|
|
3332
|
+
if (config.expanded && Array.isArray(raw.expanded)) {
|
|
3333
|
+
state.expanded = raw.expanded.map(String);
|
|
3334
|
+
}
|
|
3335
|
+
return state;
|
|
3336
|
+
}
|
|
3337
|
+
|
|
3338
|
+
// core/shared/types/layout-constraint.types.ts
|
|
3339
|
+
var SOMA_LAYOUT_PRIORITIES = [250, 500, 750, 1e3];
|
|
3340
|
+
var SOMA_LAYOUT_ALIGNS = [
|
|
3341
|
+
"start",
|
|
3342
|
+
"center",
|
|
3343
|
+
"end",
|
|
3344
|
+
"baseline",
|
|
3345
|
+
"space_between",
|
|
3346
|
+
"space_evenly",
|
|
3347
|
+
"space_around"
|
|
3348
|
+
];
|
|
3349
|
+
|
|
3350
|
+
// core/client/parser/layout-parser.ts
|
|
3351
|
+
var SIZINGS = /* @__PURE__ */ new Set(["fixed", "hug", "fill"]);
|
|
3352
|
+
var WRAPS = /* @__PURE__ */ new Set(["none", "below", "reel"]);
|
|
3353
|
+
var NODE_KEYS = /* @__PURE__ */ new Set(["sizing", "width", "min", "max", "priority"]);
|
|
3354
|
+
var SECTION_KEYS = /* @__PURE__ */ new Set(["gap", "wrap", "align", "container_name", "nodes"]);
|
|
3355
|
+
var NAME_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
3356
|
+
function isPlainObject2(value) {
|
|
3357
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3358
|
+
}
|
|
3359
|
+
function parseLayoutConstraint(input, deps) {
|
|
3360
|
+
const { raw, path } = input;
|
|
3361
|
+
const fail = deps.fail;
|
|
3362
|
+
if (!isPlainObject2(raw)) fail("layout \u5FC5\u987B\u662F\u6620\u5C04", path);
|
|
3363
|
+
const explicit = isPlainObject2(raw.nodes) ? raw.nodes : null;
|
|
3364
|
+
const source = explicit ?? Object.fromEntries(
|
|
3365
|
+
Object.entries(raw).filter(([key]) => !SECTION_KEYS.has(key))
|
|
3366
|
+
);
|
|
3367
|
+
if (explicit === null) {
|
|
3368
|
+
for (const key of Object.keys(raw)) {
|
|
3369
|
+
if (SECTION_KEYS.has(key)) continue;
|
|
3370
|
+
if (!NAME_PATTERN.test(key)) {
|
|
3371
|
+
fail(
|
|
3372
|
+
`${path}.${key} \u65E2\u4E0D\u662F\u6BB5\u7EA7\u952E\uFF08${[...SECTION_KEYS].join(" / ")}\uFF09\uFF0C\u4E5F\u4E0D\u662F\u5408\u6CD5\u5B50\u9879\u540D\uFF08\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\u3001\u4E0B\u5212\u7EBF\u5206\u9694\uFF09`,
|
|
3373
|
+
`${path}.${key}`
|
|
3374
|
+
);
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
const nodes = {};
|
|
3379
|
+
for (const [name, rawNode] of Object.entries(source)) {
|
|
3380
|
+
const at = `${path}.${name}`;
|
|
3381
|
+
if (!isPlainObject2(rawNode)) fail(`${at} \u5FC5\u987B\u662F\u6620\u5C04`, at);
|
|
3382
|
+
for (const key of Object.keys(rawNode)) {
|
|
3383
|
+
if (!NODE_KEYS.has(key)) {
|
|
3384
|
+
fail(`${at} \u6709\u672A\u77E5\u952E "${key}"\uFF08\u652F\u6301: ${[...NODE_KEYS].join(" / ")}\uFF09`, `${at}.${key}`);
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
const sizing = String(rawNode.sizing ?? "");
|
|
3388
|
+
if (!SIZINGS.has(sizing)) {
|
|
3389
|
+
fail(
|
|
3390
|
+
`${at}.sizing \u53EA\u80FD\u662F ${[...SIZINGS].join(" / ")}\uFF08\u6536\u5230 ${JSON.stringify(rawNode.sizing)}\uFF09\u2014\u2014fixed \u662F"\u5C31\u8FD9\u4E48\u5BBD"\uFF0Chug \u662F"\u5185\u5BB9\u591A\u5BBD\u6211\u591A\u5BBD"\uFF0Cfill \u662F"\u5269\u4E0B\u7684\u7ED9\u6211"`,
|
|
3391
|
+
`${at}.sizing`
|
|
3392
|
+
);
|
|
3393
|
+
}
|
|
3394
|
+
const node = { sizing };
|
|
3395
|
+
for (const key of ["width", "min", "max"]) {
|
|
3396
|
+
if (rawNode[key] === void 0) continue;
|
|
3397
|
+
const literal = String(rawNode[key]);
|
|
3398
|
+
if (!/^\d+(?:\.\d+)?(rem|%|cqi)$/.test(literal)) {
|
|
3399
|
+
fail(
|
|
3400
|
+
`${at}.${key} \u7684\u957F\u5EA6 "${literal}" \u975E\u6CD5\u2014\u2014\u53EA\u8BA4 rem / % / cqi\uFF08\u5355\u4F4D\u5FC5\u586B\uFF0C\u4E0D\u731C\uFF09`,
|
|
3401
|
+
`${at}.${key}`
|
|
3402
|
+
);
|
|
3403
|
+
}
|
|
3404
|
+
node[key] = literal;
|
|
3405
|
+
}
|
|
3406
|
+
if (rawNode.priority !== void 0) {
|
|
3407
|
+
const priority = Number(rawNode.priority);
|
|
3408
|
+
if (!SOMA_LAYOUT_PRIORITIES.includes(priority)) {
|
|
3409
|
+
fail(
|
|
3410
|
+
`${at}.priority \u53EA\u80FD\u662F ${SOMA_LAYOUT_PRIORITIES.join(" / ")}\uFF08\u6536\u5230 ${String(rawNode.priority)}\uFF09\u2014\u2014250 \u662F"\u6211\u613F\u610F\u88AB\u62C9\u5927"\uFF0C750 \u662F"\u6211\u4E0D\u613F\u610F\u88AB\u538B\u5C0F"\uFF0C1000 \u662F\u4E0D\u53EF\u8FDD\u53CD`,
|
|
3411
|
+
`${at}.priority`
|
|
3412
|
+
);
|
|
3413
|
+
}
|
|
3414
|
+
node.priority = priority;
|
|
3415
|
+
}
|
|
3416
|
+
nodes[name] = node;
|
|
3417
|
+
}
|
|
3418
|
+
if (Object.keys(nodes).length === 0) {
|
|
3419
|
+
fail(`${path} \u81F3\u5C11\u8981\u6709\u4E00\u4E2A\u5B50\u9879`, path);
|
|
3420
|
+
}
|
|
3421
|
+
const constraint = { nodes };
|
|
3422
|
+
if (raw.gap !== void 0) {
|
|
3423
|
+
const gap = String(raw.gap);
|
|
3424
|
+
if (!/^\d+(?:\.\d+)?(rem|%|cqi)$/.test(gap)) {
|
|
3425
|
+
fail(`${path}.gap \u7684\u957F\u5EA6 "${gap}" \u975E\u6CD5\u2014\u2014\u53EA\u8BA4 rem / % / cqi`, `${path}.gap`);
|
|
3426
|
+
}
|
|
3427
|
+
constraint.gap = gap;
|
|
3428
|
+
}
|
|
3429
|
+
if (raw.wrap !== void 0) {
|
|
3430
|
+
const wrap = String(raw.wrap);
|
|
3431
|
+
if (!WRAPS.has(wrap)) {
|
|
3432
|
+
fail(`${path}.wrap \u53EA\u80FD\u662F ${[...WRAPS].join(" / ")}\uFF08\u6536\u5230 ${JSON.stringify(raw.wrap)}\uFF09`, `${path}.wrap`);
|
|
3433
|
+
}
|
|
3434
|
+
constraint.wrap = wrap;
|
|
3435
|
+
}
|
|
3436
|
+
if (raw.align !== void 0) {
|
|
3437
|
+
const align = String(raw.align);
|
|
3438
|
+
if (!SOMA_LAYOUT_ALIGNS.includes(align)) {
|
|
3439
|
+
fail(
|
|
3440
|
+
`${path}.align \u53EA\u80FD\u662F ${SOMA_LAYOUT_ALIGNS.join(" / ")}\uFF08\u6536\u5230 ${JSON.stringify(raw.align)}\uFF09`,
|
|
3441
|
+
`${path}.align`
|
|
3442
|
+
);
|
|
3443
|
+
}
|
|
3444
|
+
constraint.align = align;
|
|
3445
|
+
}
|
|
3446
|
+
if (raw.container_name !== void 0) {
|
|
3447
|
+
const containerName = String(raw.container_name);
|
|
3448
|
+
if (!/^[a-z][a-z0-9-]*$/.test(containerName)) {
|
|
3449
|
+
fail(
|
|
3450
|
+
`${path}.container_name "${containerName}" \u4E0D\u662F\u5408\u6CD5\u7684\u5BB9\u5668\u540D\uFF08\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\u3001\u8FDE\u5B57\u7B26\u5206\u9694\uFF1B\u5B83\u8981\u51FA\u73B0\u5728 CSS \u7684 container-name \u4E0A\uFF09`,
|
|
3451
|
+
`${path}.container_name`
|
|
3452
|
+
);
|
|
3453
|
+
}
|
|
3454
|
+
constraint.container_name = containerName;
|
|
3455
|
+
}
|
|
3456
|
+
return constraint;
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3249
3459
|
// core/client/parser/ui-config-parser.ts
|
|
3250
3460
|
var SomaUiConfigError = class extends Error {
|
|
3251
3461
|
constructor(message, path = "") {
|
|
@@ -3474,8 +3684,481 @@ function parseUiConfig(raw, options) {
|
|
|
3474
3684
|
vocabularyRequired: options?.adaptiveVocabularyRequired !== false
|
|
3475
3685
|
});
|
|
3476
3686
|
}
|
|
3687
|
+
if ("state" in raw && raw.state !== void 0) {
|
|
3688
|
+
config.state = parsePageState(
|
|
3689
|
+
{ raw: raw.state, objectNames: options?.dataObjectNames ?? [], path: "state" },
|
|
3690
|
+
{
|
|
3691
|
+
fail(message) {
|
|
3692
|
+
throw new SomaUiConfigError(message);
|
|
3693
|
+
}
|
|
3694
|
+
}
|
|
3695
|
+
);
|
|
3696
|
+
}
|
|
3697
|
+
if ("layout" in raw && raw.layout !== void 0) {
|
|
3698
|
+
config.layout = parseLayoutSection(raw.layout);
|
|
3699
|
+
}
|
|
3700
|
+
if ("layout_css" in raw && raw.layout_css !== void 0) {
|
|
3701
|
+
if (typeof raw.layout_css !== "string") {
|
|
3702
|
+
throw new SomaUiConfigError("layout_css \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF08\u6784\u5EFA\u671F\u6C42\u89E3\u4EA7\u7269\uFF0C\u4E0D\u624B\u5199\uFF09", "layout_css");
|
|
3703
|
+
}
|
|
3704
|
+
config.layoutCss = raw.layout_css;
|
|
3705
|
+
}
|
|
3477
3706
|
return config;
|
|
3478
3707
|
}
|
|
3708
|
+
function parseLayoutSection(raw) {
|
|
3709
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
3710
|
+
throw new SomaUiConfigError("layout \u5FC5\u987B\u662F\u6620\u5C04\uFF1A{ <\u951A\u70B9id>: { gap, wrap, <\u5B50\u9879>: { sizing, \u2026 } } }", "layout");
|
|
3711
|
+
}
|
|
3712
|
+
const out = {};
|
|
3713
|
+
for (const [anchor, spec] of Object.entries(raw)) {
|
|
3714
|
+
if (!/^[A-Za-z_][A-Za-z0-9_-]*$/.test(anchor)) {
|
|
3715
|
+
throw new SomaUiConfigError(`layout \u7684\u952E\u5FC5\u987B\u662F\u951A\u70B9 id\uFF08data-soma-id\uFF09\uFF0C\u6536\u5230 "${anchor}"`, `layout.${anchor}`);
|
|
3716
|
+
}
|
|
3717
|
+
out[anchor] = parseLayoutConstraint(
|
|
3718
|
+
{ raw: spec, path: `layout.${anchor}` },
|
|
3719
|
+
{
|
|
3720
|
+
fail(message, at) {
|
|
3721
|
+
throw new SomaUiConfigError(message, at);
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
);
|
|
3725
|
+
}
|
|
3726
|
+
return out;
|
|
3727
|
+
}
|
|
3728
|
+
|
|
3729
|
+
// core/shared/calc/coerce.ts
|
|
3730
|
+
function textOf(value) {
|
|
3731
|
+
return value === null || value === void 0 ? "" : String(value);
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3734
|
+
// core/shared/predicates/index.ts
|
|
3735
|
+
var SOMA_FIELD_PREDICATE_OPS = [
|
|
3736
|
+
"eq",
|
|
3737
|
+
"ne",
|
|
3738
|
+
"in",
|
|
3739
|
+
"not_in",
|
|
3740
|
+
"empty",
|
|
3741
|
+
"not_empty",
|
|
3742
|
+
"gt",
|
|
3743
|
+
"gte",
|
|
3744
|
+
"lt",
|
|
3745
|
+
"lte",
|
|
3746
|
+
"between",
|
|
3747
|
+
"matches",
|
|
3748
|
+
// 三个文本子串算子(REQ-010 S2)。`matches` 理论上能表达它们(`^华`),但要求写声明的人
|
|
3749
|
+
// 去写正则——而「以华开头」是过滤器里最常见的一条,逼人写 `^华` 只会换来一堆
|
|
3750
|
+
// 没转义的正则元字符(`.` `(` `+` 出现在业务词里是常态)。这三个算子把转义关在引擎里。
|
|
3751
|
+
"starts_with",
|
|
3752
|
+
"ends_with",
|
|
3753
|
+
"contains"
|
|
3754
|
+
];
|
|
3755
|
+
var OPS_BY_KIND = {
|
|
3756
|
+
text: ["eq", "ne", "in", "not_in", "empty", "not_empty", "matches", "starts_with", "ends_with", "contains"],
|
|
3757
|
+
richtext: ["empty", "not_empty"],
|
|
3758
|
+
url: ["eq", "ne", "empty", "not_empty", "matches", "starts_with", "ends_with", "contains"],
|
|
3759
|
+
enum: ["eq", "ne", "in", "not_in", "empty", "not_empty"],
|
|
3760
|
+
bool: ["eq", "ne", "empty", "not_empty"],
|
|
3761
|
+
int: ["eq", "ne", "in", "not_in", "empty", "not_empty", "gt", "gte", "lt", "lte", "between"],
|
|
3762
|
+
float: ["eq", "ne", "in", "not_in", "empty", "not_empty", "gt", "gte", "lt", "lte", "between"],
|
|
3763
|
+
money: ["eq", "ne", "empty", "not_empty", "gt", "gte", "lt", "lte", "between"],
|
|
3764
|
+
percent: ["eq", "ne", "empty", "not_empty", "gt", "gte", "lt", "lte", "between"],
|
|
3765
|
+
progress: ["eq", "ne", "empty", "not_empty", "gt", "gte", "lt", "lte", "between"],
|
|
3766
|
+
date: ["eq", "ne", "empty", "not_empty", "gt", "gte", "lt", "lte", "between"],
|
|
3767
|
+
datetime: ["eq", "ne", "empty", "not_empty", "gt", "gte", "lt", "lte", "between"],
|
|
3768
|
+
image: ["empty", "not_empty"],
|
|
3769
|
+
file: ["empty", "not_empty"],
|
|
3770
|
+
tags: ["in", "not_in", "empty", "not_empty"],
|
|
3771
|
+
tree: ["eq", "ne", "in", "not_in", "empty", "not_empty"],
|
|
3772
|
+
cascade: ["eq", "ne", "in", "not_in", "empty", "not_empty"]
|
|
3773
|
+
};
|
|
3774
|
+
var MAX_DEPTH = 8;
|
|
3775
|
+
var regexCache = /* @__PURE__ */ new Map();
|
|
3776
|
+
function regexOf(source) {
|
|
3777
|
+
const key = textOf(source);
|
|
3778
|
+
if (regexCache.has(key)) return regexCache.get(key) ?? null;
|
|
3779
|
+
let compiled = null;
|
|
3780
|
+
try {
|
|
3781
|
+
compiled = new RegExp(key);
|
|
3782
|
+
} catch {
|
|
3783
|
+
compiled = null;
|
|
3784
|
+
}
|
|
3785
|
+
regexCache.set(key, compiled);
|
|
3786
|
+
return compiled;
|
|
3787
|
+
}
|
|
3788
|
+
var PATH_PATTERN = /^[A-Za-z_][\w]*(?:\[\d+\])*(?:\.[A-Za-z_][\w]*(?:\[\d+\])*)*$/;
|
|
3789
|
+
function checkCondition(raw, fieldKeys, path, options) {
|
|
3790
|
+
const issues = [];
|
|
3791
|
+
const field = typeof raw.field === "string" ? raw.field.trim() : "";
|
|
3792
|
+
if (field === "") {
|
|
3793
|
+
issues.push(`${path}.field \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u540D`);
|
|
3794
|
+
} else if (!fieldKeys.includes(field)) {
|
|
3795
|
+
issues.push(`${path}.field \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5B57\u6BB5 "${field}"`);
|
|
3796
|
+
}
|
|
3797
|
+
const op = String(raw.op ?? "");
|
|
3798
|
+
if (!SOMA_FIELD_PREDICATE_OPS.includes(op)) {
|
|
3799
|
+
issues.push(`${path}.op \u53EA\u80FD\u662F ${SOMA_FIELD_PREDICATE_OPS.join(" / ")}\uFF0C\u6536\u5230 "${op}"`);
|
|
3800
|
+
return issues;
|
|
3801
|
+
}
|
|
3802
|
+
const kind = options.fieldTypes?.[field];
|
|
3803
|
+
if (kind && !raw.path) {
|
|
3804
|
+
const allowed = OPS_BY_KIND[kind];
|
|
3805
|
+
if (allowed && !allowed.includes(op)) {
|
|
3806
|
+
issues.push(
|
|
3807
|
+
`${path}.op="${op}" \u4E0D\u80FD\u7528\u5728 ${kind} \u7C7B\u578B\u7684\u5B57\u6BB5 "${field}" \u4E0A\uFF08\u8BE5\u7C7B\u578B\u5141\u8BB8\uFF1A${allowed.join(" / ")}\uFF09`
|
|
3808
|
+
);
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
if (raw.path !== void 0) {
|
|
3812
|
+
if (typeof raw.path !== "string" || !PATH_PATTERN.test(raw.path)) {
|
|
3813
|
+
issues.push(`${path}.path \u53EA\u5141\u8BB8 a.b.c \u4E0E a[0].b \u4E24\u79CD\u5199\u6CD5\uFF0C\u6536\u5230 ${JSON.stringify(raw.path)}`);
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
const value = raw.value;
|
|
3817
|
+
if ((op === "in" || op === "not_in") && !Array.isArray(value)) {
|
|
3818
|
+
issues.push(`${path}.value \u5728 op=${op} \u65F6\u5FC5\u987B\u662F\u6570\u7EC4`);
|
|
3819
|
+
}
|
|
3820
|
+
if ((op === "eq" || op === "ne" || op === "gt" || op === "gte" || op === "lt" || op === "lte") && value === void 0) {
|
|
3821
|
+
issues.push(`${path}.value \u5728 op=${op} \u65F6\u4E0D\u80FD\u7701\u7565\uFF08\u8981\u5224\u300C\u6709\u6CA1\u6709\u503C\u300D\u8BF7\u7528 empty / not_empty\uFF09`);
|
|
3822
|
+
}
|
|
3823
|
+
if (op === "between" && (!Array.isArray(value) || value.length !== 2)) {
|
|
3824
|
+
issues.push(`${path}.value \u5728 op=between \u65F6\u5FC5\u987B\u662F [\u4F4E, \u9AD8] \u4E24\u5143\u6570\u7EC4`);
|
|
3825
|
+
}
|
|
3826
|
+
if (op === "matches") {
|
|
3827
|
+
if (typeof value !== "string" || value === "") {
|
|
3828
|
+
issues.push(`${path}.value \u5728 op=matches \u65F6\u5FC5\u987B\u662F\u975E\u7A7A\u6B63\u5219\u6E90\u4E32`);
|
|
3829
|
+
} else if (regexOf(value) === null) {
|
|
3830
|
+
issues.push(`${path}.value \u4E0D\u662F\u5408\u6CD5\u6B63\u5219\uFF1A${JSON.stringify(value)}`);
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
if (op === "starts_with" || op === "ends_with" || op === "contains") {
|
|
3834
|
+
if (typeof value !== "string" || value === "") {
|
|
3835
|
+
issues.push(`${path}.value \u5728 op=${op} \u65F6\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u5B83\u6309\u5B57\u9762\u91CF\u6BD4\u5BF9\uFF0C\u4E0D\u662F\u6B63\u5219\uFF09`);
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
return issues;
|
|
3839
|
+
}
|
|
3840
|
+
function validatePredicate(predicate, fieldKeys, path, options = {}) {
|
|
3841
|
+
if (predicate === void 0 || predicate === null) return [];
|
|
3842
|
+
return validateNode(predicate, fieldKeys, path, options, /* @__PURE__ */ new Set(), 0);
|
|
3843
|
+
}
|
|
3844
|
+
function validateNode(predicate, fieldKeys, path, options, visiting, depth) {
|
|
3845
|
+
if (typeof predicate !== "object" || predicate === null || Array.isArray(predicate)) {
|
|
3846
|
+
return [`${path} \u5FC5\u987B\u662F\u8C13\u8BCD\u5BF9\u8C61 { field, op, value? } / { ref } / { all_of | any_of | none_of }`];
|
|
3847
|
+
}
|
|
3848
|
+
if (depth > MAX_DEPTH) {
|
|
3849
|
+
return [`${path} \u5D4C\u5957\u8D85\u8FC7 ${MAX_DEPTH} \u5C42\u2014\u2014\u5E03\u5C14\u4EE3\u6570\u4E0D\u9700\u8981\u8FD9\u4E48\u6DF1\uFF0C\u8FD9\u591A\u534A\u662F\u628A\u4E1A\u52A1\u89C4\u5219\u585E\u8FDB\u4E86\u58F0\u660E`];
|
|
3850
|
+
}
|
|
3851
|
+
const box = predicate;
|
|
3852
|
+
if ("ref" in box) {
|
|
3853
|
+
const name = typeof box.ref === "string" ? box.ref.trim() : "";
|
|
3854
|
+
if (name === "") return [`${path}.ref \u5FC5\u987B\u662F\u975E\u7A7A\u7684\u5177\u540D\u8C13\u8BCD\u540D`];
|
|
3855
|
+
const named = options.named;
|
|
3856
|
+
if (!named) return [`${path} \u7528\u4E86 { ref: "${name}" }\uFF0C\u4F46\u672C\u5C42\u6CA1\u6709\u58F0\u660E predicates \u8868`];
|
|
3857
|
+
if (!(name in named)) {
|
|
3858
|
+
return [`${path}.ref \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5177\u540D\u8C13\u8BCD "${name}"\uFF08\u5DF2\u58F0\u660E\uFF1A${Object.keys(named).join(" / ") || "\u65E0"}\uFF09`];
|
|
3859
|
+
}
|
|
3860
|
+
if (visiting.has(name)) {
|
|
3861
|
+
return [`${path}.ref \u5F62\u6210\u5F15\u7528\u73AF\uFF1A${[...visiting, name].join(" \u2192 ")}`];
|
|
3862
|
+
}
|
|
3863
|
+
visiting.add(name);
|
|
3864
|
+
const issues = validateNode(named[name], fieldKeys, `predicates.${name}`, options, visiting, depth + 1);
|
|
3865
|
+
visiting.delete(name);
|
|
3866
|
+
return issues;
|
|
3867
|
+
}
|
|
3868
|
+
const group = ["all_of", "any_of", "none_of"].find((key) => key in box);
|
|
3869
|
+
if (group) {
|
|
3870
|
+
const members = box[group];
|
|
3871
|
+
if (!Array.isArray(members) || members.length === 0) {
|
|
3872
|
+
return [`${path}.${group} \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4`];
|
|
3873
|
+
}
|
|
3874
|
+
const extra = ["all_of", "any_of", "none_of", "ref", "field"].filter((key) => key !== group && key in box);
|
|
3875
|
+
if (extra.length > 0) {
|
|
3876
|
+
return [`${path} \u540C\u65F6\u5199\u4E86 ${group} \u4E0E ${extra.join(" / ")}\u2014\u2014\u4E00\u4E2A\u8282\u70B9\u53EA\u80FD\u662F\u4E00\u79CD\u5F62\u6001`];
|
|
3877
|
+
}
|
|
3878
|
+
return members.flatMap((member, index) => validateNode(member, fieldKeys, `${path}.${group}[${index}]`, options, visiting, depth + 1));
|
|
3879
|
+
}
|
|
3880
|
+
return checkCondition(box, fieldKeys, path, options);
|
|
3881
|
+
}
|
|
3882
|
+
function validateNamedPredicates(named, fieldKeys, fieldTypes) {
|
|
3883
|
+
if (named === void 0 || named === null) return [];
|
|
3884
|
+
if (typeof named !== "object" || Array.isArray(named)) return ["predicates \u5FC5\u987B\u662F { \u540D\u5B57: \u8C13\u8BCD } \u6620\u5C04"];
|
|
3885
|
+
const table = named;
|
|
3886
|
+
const options = { fieldTypes, named: table };
|
|
3887
|
+
return Object.entries(table).flatMap(([name, predicate]) => {
|
|
3888
|
+
if (!/^[A-Za-z_][\w]*$/.test(name)) return [`predicates \u7684\u952E "${name}" \u5FC5\u987B\u662F\u6807\u8BC6\u7B26`];
|
|
3889
|
+
return validateNode(predicate, fieldKeys, `predicates.${name}`, options, /* @__PURE__ */ new Set([name]), 0);
|
|
3890
|
+
});
|
|
3891
|
+
}
|
|
3892
|
+
function collectPredicateFields(predicate, named) {
|
|
3893
|
+
const out = [];
|
|
3894
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3895
|
+
const visitingRefs = /* @__PURE__ */ new Set();
|
|
3896
|
+
const walk = (node, depth) => {
|
|
3897
|
+
if (!node || typeof node !== "object" || Array.isArray(node) || depth > MAX_DEPTH) return;
|
|
3898
|
+
const box = node;
|
|
3899
|
+
if (typeof box.ref === "string") {
|
|
3900
|
+
if (visitingRefs.has(box.ref)) return;
|
|
3901
|
+
visitingRefs.add(box.ref);
|
|
3902
|
+
walk(named?.[box.ref], depth + 1);
|
|
3903
|
+
visitingRefs.delete(box.ref);
|
|
3904
|
+
return;
|
|
3905
|
+
}
|
|
3906
|
+
for (const group of ["all_of", "any_of", "none_of"]) {
|
|
3907
|
+
if (Array.isArray(box[group])) {
|
|
3908
|
+
for (const member of box[group]) walk(member, depth + 1);
|
|
3909
|
+
return;
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
if (typeof box.field === "string" && box.field !== "" && !seen.has(box.field)) {
|
|
3913
|
+
seen.add(box.field);
|
|
3914
|
+
out.push(box.field);
|
|
3915
|
+
}
|
|
3916
|
+
};
|
|
3917
|
+
walk(predicate, 0);
|
|
3918
|
+
return out;
|
|
3919
|
+
}
|
|
3920
|
+
|
|
3921
|
+
// core/client/parser/step-parser.ts
|
|
3922
|
+
var MAX_FOR_EACH_DEPTH = 2;
|
|
3923
|
+
var STEP_KEYS = /* @__PURE__ */ new Set(["when", "do", "output", "on_error", "switch", "parallel", "for_each"]);
|
|
3924
|
+
var SLOT_NAME_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
3925
|
+
function isPlainObject3(value) {
|
|
3926
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3927
|
+
}
|
|
3928
|
+
function producesArray(pipelineType) {
|
|
3929
|
+
return pipelineType === "UI_REFRESH" || pipelineType === "NAV_ACTION" || pipelineType === "ACTION";
|
|
3930
|
+
}
|
|
3931
|
+
function parseSteps(input, deps) {
|
|
3932
|
+
const { raw, payloadFields, path } = input;
|
|
3933
|
+
const fail = deps.fail;
|
|
3934
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
3935
|
+
fail("steps \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4", path);
|
|
3936
|
+
}
|
|
3937
|
+
const slots = {};
|
|
3938
|
+
const edges = [];
|
|
3939
|
+
let counter = 0;
|
|
3940
|
+
const scopeKeys = () => [...payloadFields, ...Object.keys(slots)];
|
|
3941
|
+
const checkWhen = (when, at) => {
|
|
3942
|
+
if (when === void 0 || when === null) return;
|
|
3943
|
+
for (const field of collectPredicateFields(when)) {
|
|
3944
|
+
const root = field.split(".")[0];
|
|
3945
|
+
if (!payloadFields.includes(root) && slots[root] === void 0) {
|
|
3946
|
+
fail(
|
|
3947
|
+
`${at} \u5F15\u7528\u4E86 "${root}"\uFF0C\u4F46\u5B83\u65E2\u4E0D\u662F\u4E8B\u4EF6\u8F7D\u8377\u5B57\u6BB5\uFF08${payloadFields.join(" / ") || "\u65E0"}\uFF09\uFF0C\u4E5F\u4E0D\u662F\u5148\u4E8E\u672C\u6B65\u58F0\u660E\u7684\u8F93\u51FA\u69FD\uFF08${Object.keys(slots).join(" / ") || "\u65E0"}\uFF09`,
|
|
3948
|
+
at
|
|
3949
|
+
);
|
|
3950
|
+
}
|
|
3951
|
+
}
|
|
3952
|
+
const issues = validatePredicate(when, scopeKeys(), at, {});
|
|
3953
|
+
if (issues.length > 0) fail(issues.join("\uFF1B"), at);
|
|
3954
|
+
};
|
|
3955
|
+
const declareSlot = (name, at, index, pipelineType) => {
|
|
3956
|
+
const slot = String(name ?? "");
|
|
3957
|
+
if (!SLOT_NAME_PATTERN.test(slot)) {
|
|
3958
|
+
fail(`${at}.output "${slot}" \u4E0D\u662F\u5408\u6CD5\u69FD\u540D\uFF08\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\u3001\u4E0B\u5212\u7EBF\u5206\u9694\uFF09`, `${at}.output`);
|
|
3959
|
+
}
|
|
3960
|
+
if (slots[slot] !== void 0) {
|
|
3961
|
+
fail(
|
|
3962
|
+
`${at}.output \u69FD\u540D "${slot}" \u4E0E\u7B2C ${slots[slot].declaredAt + 1} \u6B65\u91CD\u540D\u2014\u2014\u540C\u540D\u69FD\u7684\u540E\u5199\u4F1A\u8986\u76D6\u524D\u5199\uFF0C\u800C\u5F15\u7528\u5B83\u7684\u6761\u4EF6\u8BFB\u5230\u54EA\u4E00\u4E2A\u53D6\u51B3\u4E8E\u6B65\u9AA4\u6B21\u5E8F`,
|
|
3963
|
+
`${at}.output`
|
|
3964
|
+
);
|
|
3965
|
+
}
|
|
3966
|
+
slots[slot] = { declaredAt: index, producedBy: pipelineType, bounded: producesArray(pipelineType) };
|
|
3967
|
+
return slot;
|
|
3968
|
+
};
|
|
3969
|
+
const parsePipe = (expression, at) => {
|
|
3970
|
+
if (typeof expression !== "string" || expression.trim() === "") {
|
|
3971
|
+
fail(`${at}.do \u5FC5\u987B\u662F\u7BA1\u9053\u8868\u8FBE\u5F0F\u5B57\u7B26\u4E32`, `${at}.do`);
|
|
3972
|
+
}
|
|
3973
|
+
try {
|
|
3974
|
+
return deps.parsePipeline(expression);
|
|
3975
|
+
} catch (error) {
|
|
3976
|
+
fail(error instanceof Error ? error.message : String(error), `${at}.do`);
|
|
3977
|
+
}
|
|
3978
|
+
};
|
|
3979
|
+
const parseOnError = (value, at, total, index) => {
|
|
3980
|
+
if (value === void 0) return "stop";
|
|
3981
|
+
const raw2 = String(value);
|
|
3982
|
+
if (raw2 === "stop" || raw2 === "continue") return raw2;
|
|
3983
|
+
const match = /^goto:(\d+)$/.exec(raw2);
|
|
3984
|
+
if (!match) {
|
|
3985
|
+
fail(`${at}.on_error \u53EA\u80FD\u662F stop / continue / goto:<\u6B65\u9AA4\u5E8F\u53F7>\uFF08\u6536\u5230 "${raw2}"\uFF09`, `${at}.on_error`);
|
|
3986
|
+
}
|
|
3987
|
+
const target = Number(match[1]);
|
|
3988
|
+
if (target <= index + 1) {
|
|
3989
|
+
fail(
|
|
3990
|
+
`${at}.on_error \u7684 goto:${target} \u6307\u5411\u7B2C ${target} \u6B65\uFF0C\u4E0D\u5728\u672C\u6B65\uFF08\u7B2C ${index + 1} \u6B65\uFF09\u4E4B\u540E\u2014\u2014\u53EA\u8BB8\u5411\u540E\u8DF3\uFF0C\u5426\u5219\u7F16\u6392\u53EF\u4EE5\u4E0D\u7EC8\u6B62`,
|
|
3991
|
+
`${at}.on_error`
|
|
3992
|
+
);
|
|
3993
|
+
}
|
|
3994
|
+
if (target > total) {
|
|
3995
|
+
fail(`${at}.on_error \u7684 goto:${target} \u8D8A\u8FC7\u4E86\u672B\u6B65\uFF08\u5171 ${total} \u6B65\uFF09`, `${at}.on_error`);
|
|
3996
|
+
}
|
|
3997
|
+
return `goto:${target}`;
|
|
3998
|
+
};
|
|
3999
|
+
const walk = (list, at, depth, inParallel) => {
|
|
4000
|
+
const out = [];
|
|
4001
|
+
const parallelLocalSlots = [];
|
|
4002
|
+
list.forEach((entry, position) => {
|
|
4003
|
+
const stepAt = `${at}[${position}]`;
|
|
4004
|
+
if (!isPlainObject3(entry)) fail(`${stepAt} \u5FC5\u987B\u662F\u6620\u5C04`, stepAt);
|
|
4005
|
+
for (const key of Object.keys(entry)) {
|
|
4006
|
+
if (!STEP_KEYS.has(key)) {
|
|
4007
|
+
fail(`${stepAt} \u6709\u672A\u77E5\u952E "${key}"\uFF08\u652F\u6301: ${[...STEP_KEYS].join(" / ")}\uFF09`, `${stepAt}.${key}`);
|
|
4008
|
+
}
|
|
4009
|
+
}
|
|
4010
|
+
const index = counter;
|
|
4011
|
+
counter += 1;
|
|
4012
|
+
if (out.length > 0) edges.push([out[out.length - 1].index, index]);
|
|
4013
|
+
if (entry.parallel !== void 0) {
|
|
4014
|
+
if (!Array.isArray(entry.parallel) || entry.parallel.length < 2) {
|
|
4015
|
+
fail(`${stepAt}.parallel \u81F3\u5C11\u8981\u4E24\u4E2A\u5206\u652F\uFF08\u4E00\u4E2A\u5206\u652F\u7684\u5E76\u884C\u5C31\u662F\u987A\u5E8F\uFF09`, `${stepAt}.parallel`);
|
|
4016
|
+
}
|
|
4017
|
+
const before = new Set(Object.keys(slots));
|
|
4018
|
+
const children = walk(entry.parallel, `${stepAt}.parallel`, depth, true);
|
|
4019
|
+
const declared = Object.keys(slots).filter((name) => !before.has(name));
|
|
4020
|
+
parallelLocalSlots.push(...declared);
|
|
4021
|
+
out.push({ index, kind: "parallel", onError: "stop", children });
|
|
4022
|
+
return;
|
|
4023
|
+
}
|
|
4024
|
+
if (entry.for_each !== void 0) {
|
|
4025
|
+
if (depth + 1 > MAX_FOR_EACH_DEPTH) {
|
|
4026
|
+
fail(
|
|
4027
|
+
`${stepAt}.for_each \u5D4C\u5957\u8D85\u8FC7 ${MAX_FOR_EACH_DEPTH} \u5C42\u2014\u2014\u4E09\u5C42\u904D\u5386\u5728\u58F0\u660E\u5C42\u51E0\u4E4E\u80AF\u5B9A\u662F\u6570\u636E\u7ED3\u6784\u6CA1\u8BBE\u8BA1\u5BF9`,
|
|
4028
|
+
`${stepAt}.for_each`
|
|
4029
|
+
);
|
|
4030
|
+
}
|
|
4031
|
+
const box = entry.for_each;
|
|
4032
|
+
if (!isPlainObject3(box)) fail(`${stepAt}.for_each \u5FC5\u987B\u662F { over, as, steps }`, `${stepAt}.for_each`);
|
|
4033
|
+
const over = String(box.over ?? "");
|
|
4034
|
+
const as = String(box.as ?? "");
|
|
4035
|
+
const isPayload = payloadFields.includes(over);
|
|
4036
|
+
const slot = slots[over];
|
|
4037
|
+
if (!isPayload && slot === void 0) {
|
|
4038
|
+
fail(
|
|
4039
|
+
`${stepAt}.for_each.over "${over}" \u65E2\u4E0D\u662F\u4E8B\u4EF6\u8F7D\u8377\u5B57\u6BB5\uFF0C\u4E5F\u4E0D\u662F\u5148\u4E8E\u672C\u6B65\u58F0\u660E\u7684\u8F93\u51FA\u69FD`,
|
|
4040
|
+
`${stepAt}.for_each.over`
|
|
4041
|
+
);
|
|
4042
|
+
}
|
|
4043
|
+
if (slot !== void 0 && !slot.bounded) {
|
|
4044
|
+
fail(
|
|
4045
|
+
`${stepAt}.for_each.over "${over}" \u6765\u81EA ${slot.producedBy}\uFF0C\u5B83\u4E0D\u8FD4\u56DE\u6570\u7EC4\u2014\u2014\u904D\u5386\u4E00\u4E2A\u4E0D\u662F\u6570\u7EC4\u7684\u4E1C\u897F\uFF0C\u6B65\u6570\u5C31\u6CA1\u6709\u4E0A\u754C\u4E86`,
|
|
4046
|
+
`${stepAt}.for_each.over`
|
|
4047
|
+
);
|
|
4048
|
+
}
|
|
4049
|
+
if (!SLOT_NAME_PATTERN.test(as)) {
|
|
4050
|
+
fail(`${stepAt}.for_each.as "${as}" \u4E0D\u662F\u5408\u6CD5\u9879\u540D`, `${stepAt}.for_each.as`);
|
|
4051
|
+
}
|
|
4052
|
+
if (!Array.isArray(box.steps) || box.steps.length === 0) {
|
|
4053
|
+
fail(`${stepAt}.for_each.steps \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4`, `${stepAt}.for_each.steps`);
|
|
4054
|
+
}
|
|
4055
|
+
slots[as] = { declaredAt: index, producedBy: "for_each", bounded: false };
|
|
4056
|
+
const children = walk(box.steps, `${stepAt}.for_each.steps`, depth + 1, inParallel);
|
|
4057
|
+
delete slots[as];
|
|
4058
|
+
out.push({ index, kind: "for_each", onError: "stop", over, as, children });
|
|
4059
|
+
return;
|
|
4060
|
+
}
|
|
4061
|
+
if (entry.switch !== void 0) {
|
|
4062
|
+
if (!Array.isArray(entry.switch) || entry.switch.length === 0) {
|
|
4063
|
+
fail(`${stepAt}.switch \u5FC5\u987B\u662F\u975E\u7A7A\u5206\u652F\u6570\u7EC4`, `${stepAt}.switch`);
|
|
4064
|
+
}
|
|
4065
|
+
checkWhen(entry.when, `${stepAt}.when`);
|
|
4066
|
+
const list2 = entry.switch;
|
|
4067
|
+
const branches = [];
|
|
4068
|
+
const otherwiseAt = list2.map((branch, position2) => isPlainObject3(branch) && branch.otherwise === true ? position2 : -1).filter((position2) => position2 !== -1);
|
|
4069
|
+
if (otherwiseAt.length > 1) {
|
|
4070
|
+
fail(
|
|
4071
|
+
`${stepAt}.switch \u6709 ${otherwiseAt.length} \u4E2A otherwise \u5206\u652F\uFF08\u7B2C ${otherwiseAt.map((n) => n + 1).join(" / ")} \u4E2A\uFF09\u2014\u2014\u515C\u5E95\u53EA\u80FD\u6709\u4E00\u4E2A`,
|
|
4072
|
+
`${stepAt}.switch`
|
|
4073
|
+
);
|
|
4074
|
+
}
|
|
4075
|
+
if (otherwiseAt.length === 1 && otherwiseAt[0] !== list2.length - 1) {
|
|
4076
|
+
fail(
|
|
4077
|
+
`${stepAt}.switch[${otherwiseAt[0]}] \u7684 otherwise \u5FC5\u987B\u662F\u6700\u540E\u4E00\u4E2A\u5206\u652F\uFF08\u5B83\u662F\u515C\u5E95\uFF0C\u540E\u9762\u7684\u5206\u652F\u6C38\u8FDC\u8D70\u4E0D\u5230\uFF09`,
|
|
4078
|
+
`${stepAt}.switch[${otherwiseAt[0]}]`
|
|
4079
|
+
);
|
|
4080
|
+
}
|
|
4081
|
+
list2.forEach((branchRaw, branchIndex) => {
|
|
4082
|
+
const branchAt = `${stepAt}.switch[${branchIndex}]`;
|
|
4083
|
+
if (!isPlainObject3(branchRaw)) fail(`${branchAt} \u5FC5\u987B\u662F\u6620\u5C04`, branchAt);
|
|
4084
|
+
const otherwise = branchRaw.otherwise === true;
|
|
4085
|
+
if (!otherwise && branchRaw.when === void 0) {
|
|
4086
|
+
fail(`${branchAt} \u65E2\u6CA1\u6709 when \u4E5F\u4E0D\u662F otherwise\u2014\u2014\u5B83\u4F1A\u65E0\u6761\u4EF6\u547D\u4E2D\u5E76\u5403\u6389\u540E\u9762\u7684\u5206\u652F`, branchAt);
|
|
4087
|
+
}
|
|
4088
|
+
if (!otherwise) checkWhen(branchRaw.when, `${branchAt}.when`);
|
|
4089
|
+
const pipeline2 = parsePipe(branchRaw.do, branchAt);
|
|
4090
|
+
const output2 = branchRaw.output === void 0 ? void 0 : declareSlot(branchRaw.output, branchAt, index, pipeline2.type);
|
|
4091
|
+
branches.push({
|
|
4092
|
+
...otherwise ? {} : { when: branchRaw.when },
|
|
4093
|
+
otherwise,
|
|
4094
|
+
pipeline: pipeline2,
|
|
4095
|
+
...output2 === void 0 ? {} : { output: output2 }
|
|
4096
|
+
});
|
|
4097
|
+
});
|
|
4098
|
+
out.push({ index, kind: "switch", when: entry.when, onError: "stop", branches });
|
|
4099
|
+
return;
|
|
4100
|
+
}
|
|
4101
|
+
checkWhen(entry.when, `${stepAt}.when`);
|
|
4102
|
+
const pipeline = parsePipe(entry.do, stepAt);
|
|
4103
|
+
const onError = parseOnError(entry.on_error, stepAt, list.length, position);
|
|
4104
|
+
if (onError.startsWith("goto:")) {
|
|
4105
|
+
edges.push([index, index + (Number(onError.slice(5)) - position - 1)]);
|
|
4106
|
+
}
|
|
4107
|
+
const output = entry.output === void 0 ? void 0 : declareSlot(entry.output, stepAt, index, pipeline.type);
|
|
4108
|
+
if (inParallel && output !== void 0) parallelLocalSlots.push(output);
|
|
4109
|
+
out.push({
|
|
4110
|
+
index,
|
|
4111
|
+
kind: "do",
|
|
4112
|
+
...entry.when === void 0 ? {} : { when: entry.when },
|
|
4113
|
+
pipeline,
|
|
4114
|
+
onError,
|
|
4115
|
+
...output === void 0 ? {} : { output }
|
|
4116
|
+
});
|
|
4117
|
+
});
|
|
4118
|
+
if (inParallel && parallelLocalSlots.length > 0) {
|
|
4119
|
+
out.forEach((step, position) => {
|
|
4120
|
+
const refs = step.when === void 0 ? [] : collectPredicateFields(step.when);
|
|
4121
|
+
for (const ref of refs) {
|
|
4122
|
+
const root = ref.split(".")[0];
|
|
4123
|
+
if (!parallelLocalSlots.includes(root)) continue;
|
|
4124
|
+
const owner = out.findIndex((other) => other.output === root);
|
|
4125
|
+
if (owner !== -1 && owner !== position) {
|
|
4126
|
+
fail(
|
|
4127
|
+
`${at}[${position}] \u7684 when \u5F15\u7528\u4E86\u540C\u4E00\u4E2A parallel \u91CC\u53E6\u4E00\u4E2A\u5206\u652F\u7684\u8F93\u51FA\u69FD "${root}"\u2014\u2014\u5E76\u884C\u5206\u652F\u4E4B\u95F4\u4E0D\u8BB8\u4E92\u5F15\uFF1A\u4E92\u5F15\u5C31\u610F\u5473\u7740\u6709\u987A\u5E8F\uFF0C\u90A3\u5B83\u5C31\u4E0D\u8BE5\u5199\u6210 parallel`,
|
|
4128
|
+
`${at}[${position}].when`
|
|
4129
|
+
);
|
|
4130
|
+
}
|
|
4131
|
+
}
|
|
4132
|
+
});
|
|
4133
|
+
}
|
|
4134
|
+
return out;
|
|
4135
|
+
};
|
|
4136
|
+
const steps = walk(raw, path, 0, false);
|
|
4137
|
+
if (input.actionNames !== void 0) {
|
|
4138
|
+
const known = new Set(input.actionNames);
|
|
4139
|
+
const visit = (list) => {
|
|
4140
|
+
for (const step of list) {
|
|
4141
|
+
const pipes = [
|
|
4142
|
+
...step.pipeline ? [step.pipeline] : [],
|
|
4143
|
+
...(step.branches ?? []).map((branch) => branch.pipeline)
|
|
4144
|
+
];
|
|
4145
|
+
for (const pipe of pipes) {
|
|
4146
|
+
if (pipe.type !== "ACTION") continue;
|
|
4147
|
+
const name = String(pipe.funcPath ?? "");
|
|
4148
|
+
if (!known.has(name)) {
|
|
4149
|
+
fail(
|
|
4150
|
+
`do: ACTION | ${name} \u2014\u2014 \u672A\u6CE8\u518C\u7684\u5177\u540D\u52A8\u4F5C\uFF08\u5DF2\u6CE8\u518C\uFF1A${[...known].join(" / ") || "\u65E0"}\uFF09\u3002\u5177\u540D\u52A8\u4F5C\u5728 bootstrap \u7684 options.actions \u91CC\u767B\u8BB0\uFF0C\u8FD9\u662F custom(script) \u7684\u66FF\u4EE3\uFF1A\u5B9E\u73B0\u5728 Host \u4EE3\u7801\u91CC\u3001\u6709\u540D\u5B57\u3001\u53EF\u5BA1\u8BA1\u3002`,
|
|
4151
|
+
path
|
|
4152
|
+
);
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
if (step.children) visit(step.children);
|
|
4156
|
+
}
|
|
4157
|
+
};
|
|
4158
|
+
visit(steps);
|
|
4159
|
+
}
|
|
4160
|
+
return { steps, slots, edges };
|
|
4161
|
+
}
|
|
3479
4162
|
|
|
3480
4163
|
// core/shared/types/keyboard.types.ts
|
|
3481
4164
|
var SOMA_KEY_MODIFIERS = {
|
|
@@ -3504,7 +4187,8 @@ var VALID_TYPES = /* @__PURE__ */ new Set([
|
|
|
3504
4187
|
"NAV_STATIC",
|
|
3505
4188
|
"NAV_ACTION",
|
|
3506
4189
|
"UI_REFRESH",
|
|
3507
|
-
"UI_INTERACT"
|
|
4190
|
+
"UI_INTERACT",
|
|
4191
|
+
"ACTION"
|
|
3508
4192
|
]);
|
|
3509
4193
|
var VALID_DOM_EVENTS = /* @__PURE__ */ new Set([
|
|
3510
4194
|
"click",
|
|
@@ -3520,8 +4204,34 @@ var VALID_DOM_EVENTS = /* @__PURE__ */ new Set([
|
|
|
3520
4204
|
"keyup",
|
|
3521
4205
|
"scroll"
|
|
3522
4206
|
]);
|
|
3523
|
-
var VALID_ACTIONS = /* @__PURE__ */ new Set([
|
|
4207
|
+
var VALID_ACTIONS = /* @__PURE__ */ new Set([
|
|
4208
|
+
"open",
|
|
4209
|
+
"close",
|
|
4210
|
+
"toggle",
|
|
4211
|
+
"focus",
|
|
4212
|
+
"scroll_to",
|
|
4213
|
+
"select"
|
|
4214
|
+
]);
|
|
3524
4215
|
var EMIT_NAME_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
4216
|
+
function isStepsDeclaration(value) {
|
|
4217
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.steps);
|
|
4218
|
+
}
|
|
4219
|
+
function collectWhenRoots(steps) {
|
|
4220
|
+
const roots = /* @__PURE__ */ new Set();
|
|
4221
|
+
const walk = (node) => {
|
|
4222
|
+
if (Array.isArray(node)) {
|
|
4223
|
+
for (const item of node) walk(item);
|
|
4224
|
+
return;
|
|
4225
|
+
}
|
|
4226
|
+
if (node === null || typeof node !== "object") return;
|
|
4227
|
+
for (const [key, value] of Object.entries(node)) {
|
|
4228
|
+
if (key === "field" && typeof value === "string") roots.add(value.split(".")[0]);
|
|
4229
|
+
else walk(value);
|
|
4230
|
+
}
|
|
4231
|
+
};
|
|
4232
|
+
walk(steps);
|
|
4233
|
+
return [...roots];
|
|
4234
|
+
}
|
|
3525
4235
|
var CONFIRM_PREFIX = "confirm:";
|
|
3526
4236
|
var PERMISSION_PREFIX = "permission:";
|
|
3527
4237
|
var FORCE_SEGMENT = "force";
|
|
@@ -3645,6 +4355,15 @@ function parsePipelineBody(expression) {
|
|
|
3645
4355
|
}
|
|
3646
4356
|
result.funcPath = parts[1];
|
|
3647
4357
|
break;
|
|
4358
|
+
case "ACTION":
|
|
4359
|
+
if (!parts[1] || !/^[a-z][a-zA-Z0-9_]*$/.test(parts[1])) {
|
|
4360
|
+
throw new SomaEventParseError(
|
|
4361
|
+
`ACTION \u7F3A\u5C11\u5408\u6CD5\u7684\u52A8\u4F5C\u540D\uFF08\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\u7684\u6807\u8BC6\u7B26\uFF09\uFF0C\u6536\u5230 "${parts[1] ?? ""}"`,
|
|
4362
|
+
expression
|
|
4363
|
+
);
|
|
4364
|
+
}
|
|
4365
|
+
result.funcPath = parts[1];
|
|
4366
|
+
break;
|
|
3648
4367
|
case "UI_INTERACT":
|
|
3649
4368
|
result.targetId = parts[1] || void 0;
|
|
3650
4369
|
result.funcPath = parts[2] || null;
|
|
@@ -3690,6 +4409,27 @@ function parseEventConfig(config, parentPath = []) {
|
|
|
3690
4409
|
}
|
|
3691
4410
|
throw error;
|
|
3692
4411
|
}
|
|
4412
|
+
} else if (isStepsDeclaration(value)) {
|
|
4413
|
+
const { somaId, domEvent, keyModifier } = parseSelector(key);
|
|
4414
|
+
const graph = parseSteps(
|
|
4415
|
+
{
|
|
4416
|
+
raw: value.steps,
|
|
4417
|
+
// 事件载荷的字段在编译期不可知(它来自组件契约的 emit payload)。
|
|
4418
|
+
// 给空作用域会把所有 `when` 都判成越界,所以这里放行载荷引用、
|
|
4419
|
+
// 只校验槽的前向引用——载荷字段名的校验归组件契约那一侧。
|
|
4420
|
+
payloadFields: collectWhenRoots(value.steps),
|
|
4421
|
+
path: `${[...parentPath, key].join(" > ")}.steps`
|
|
4422
|
+
},
|
|
4423
|
+
{
|
|
4424
|
+
fail(message) {
|
|
4425
|
+
throw new SomaEventParseError(message, key);
|
|
4426
|
+
},
|
|
4427
|
+
parsePipeline: parsePipelineBody
|
|
4428
|
+
}
|
|
4429
|
+
);
|
|
4430
|
+
const event = { somaId, domEvent, type: "STEPS", steps: graph };
|
|
4431
|
+
if (keyModifier) event.keyModifier = keyModifier;
|
|
4432
|
+
events.push(event);
|
|
3693
4433
|
} else if (typeof value === "object" && value !== null) {
|
|
3694
4434
|
events.push(
|
|
3695
4435
|
...parseEventConfig(value, [...parentPath, key])
|
|
@@ -4271,16 +5011,11 @@ var BUILTIN_PIPES = {
|
|
|
4271
5011
|
};
|
|
4272
5012
|
var defaultPipeRegistry = new SomaPipeRegistry();
|
|
4273
5013
|
|
|
4274
|
-
// core/
|
|
4275
|
-
var
|
|
4276
|
-
|
|
4277
|
-
const prefix = path ? ` (\u8DEF\u5F84: ${path})` : "";
|
|
4278
|
-
super(`[SOMA DataConfigParser] ${message}${prefix}`);
|
|
4279
|
-
this.name = "SomaDataConfigError";
|
|
4280
|
-
this.path = path;
|
|
4281
|
-
}
|
|
5014
|
+
// core/shared/types/data-config.types.ts
|
|
5015
|
+
var SOMA_DATA_FIELD_TYPE_ALIASES = {
|
|
5016
|
+
number: "float"
|
|
4282
5017
|
};
|
|
4283
|
-
var
|
|
5018
|
+
var SOMA_DATA_FIELD_TYPES = [
|
|
4284
5019
|
"text",
|
|
4285
5020
|
"int",
|
|
4286
5021
|
"float",
|
|
@@ -4291,8 +5026,1057 @@ var VALID_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
|
4291
5026
|
"datetime",
|
|
4292
5027
|
"image",
|
|
4293
5028
|
"url",
|
|
4294
|
-
"richtext"
|
|
5029
|
+
"richtext",
|
|
5030
|
+
"percent",
|
|
5031
|
+
"progress",
|
|
5032
|
+
"tags",
|
|
5033
|
+
"file",
|
|
5034
|
+
"tree",
|
|
5035
|
+
"cascade",
|
|
5036
|
+
...Object.keys(SOMA_DATA_FIELD_TYPE_ALIASES)
|
|
5037
|
+
];
|
|
5038
|
+
|
|
5039
|
+
// core/shared/types/reaction.types.ts
|
|
5040
|
+
var SOMA_REACTION_PHASES = [
|
|
5041
|
+
"field_init",
|
|
5042
|
+
"field_mount",
|
|
5043
|
+
"field_unmount",
|
|
5044
|
+
"field_value_change",
|
|
5045
|
+
"field_input_change",
|
|
5046
|
+
"field_validate_start",
|
|
5047
|
+
"field_validate_end",
|
|
5048
|
+
"field_validate_failed",
|
|
5049
|
+
"field_validate_success",
|
|
5050
|
+
"form_submit_start",
|
|
5051
|
+
"form_submit_end"
|
|
5052
|
+
];
|
|
5053
|
+
var SOMA_FIELD_DISPLAYS = ["visible", "hidden", "none"];
|
|
5054
|
+
var SOMA_FIELD_PATTERNS = ["editable", "disabled", "read_only", "read_pretty"];
|
|
5055
|
+
var SOMA_REACTION_FORM_KEY = "submit";
|
|
5056
|
+
|
|
5057
|
+
// core/shared/calc/errors.ts
|
|
5058
|
+
var SomaCalcSyntaxError = class extends Error {
|
|
5059
|
+
constructor(message, source, pos) {
|
|
5060
|
+
super(`[soma-core][calc] ${formatWhere(source, pos)}\uFF1A${message}`);
|
|
5061
|
+
this.name = "SomaCalcSyntaxError";
|
|
5062
|
+
this.pos = pos;
|
|
5063
|
+
this.near = source.slice(pos[0], pos[1]);
|
|
5064
|
+
}
|
|
5065
|
+
};
|
|
5066
|
+
var SomaCalcTypeError = class extends Error {
|
|
5067
|
+
constructor(message, source, pos, expected, actual) {
|
|
5068
|
+
super(`[soma-core][calc] ${formatWhere(source, pos)}\uFF1A${message}`);
|
|
5069
|
+
this.name = "SomaCalcTypeError";
|
|
5070
|
+
this.pos = pos;
|
|
5071
|
+
this.expected = expected;
|
|
5072
|
+
this.actual = actual;
|
|
5073
|
+
}
|
|
5074
|
+
};
|
|
5075
|
+
function formatWhere(source, pos) {
|
|
5076
|
+
return `calc ${JSON.stringify(source)} \u7B2C ${pos[0] + 1} \u5217`;
|
|
5077
|
+
}
|
|
5078
|
+
|
|
5079
|
+
// core/shared/calc/lexer.ts
|
|
5080
|
+
var CALC_FUNCTIONS = ["IF", "MIN", "MAX", "ROUND", "CONCAT", "ABS"];
|
|
5081
|
+
var OPERATORS = [">=", "<=", "==", "!=", "+", "-", "*", "/", ">", "<"];
|
|
5082
|
+
var IDENT_START = /[A-Za-z_]/;
|
|
5083
|
+
var IDENT_PART = /[A-Za-z0-9_]/;
|
|
5084
|
+
var DIGIT = /[0-9]/;
|
|
5085
|
+
function tokenize(source) {
|
|
5086
|
+
const tokens = [];
|
|
5087
|
+
let i = 0;
|
|
5088
|
+
const fail = (message, from, to) => {
|
|
5089
|
+
throw new SomaCalcSyntaxError(message, source, [from, to]);
|
|
5090
|
+
};
|
|
5091
|
+
while (i < source.length) {
|
|
5092
|
+
const char = source[i];
|
|
5093
|
+
if (char === " " || char === " ") {
|
|
5094
|
+
i += 1;
|
|
5095
|
+
continue;
|
|
5096
|
+
}
|
|
5097
|
+
if (char === "\n" || char === "\r") {
|
|
5098
|
+
fail("\u8868\u8FBE\u5F0F\u4E0D\u80FD\u6362\u884C\uFF08\u5B83\u662F\u4E00\u4E2A YAML \u6807\u91CF\uFF0C\u4E0D\u662F\u5757\uFF09", i, i + 1);
|
|
5099
|
+
}
|
|
5100
|
+
const start = i;
|
|
5101
|
+
if (char === "[") {
|
|
5102
|
+
i += 1;
|
|
5103
|
+
const nameStart = i;
|
|
5104
|
+
while (i < source.length && source[i] !== "]") i += 1;
|
|
5105
|
+
if (i >= source.length) fail('\u5B57\u6BB5\u5F15\u7528\u7F3A\u5C11\u95ED\u5408\u7684 "]"', start, source.length);
|
|
5106
|
+
const name = source.slice(nameStart, i);
|
|
5107
|
+
i += 1;
|
|
5108
|
+
if (name === "") fail("\u5B57\u6BB5\u5F15\u7528\u4E0D\u80FD\u4E3A\u7A7A\uFF08\u5199\u6210 [\u5B57\u6BB5\u540D]\uFF09", start, i);
|
|
5109
|
+
if (!IDENT_START.test(name[0]) || ![...name].every((c) => IDENT_PART.test(c))) {
|
|
5110
|
+
fail(`\u5B57\u6BB5\u540D "${name}" \u5FC5\u987B\u662F\u6807\u8BC6\u7B26\uFF08\u5B57\u6BCD\u6216\u4E0B\u5212\u7EBF\u5F00\u5934\uFF09\uFF1B\u6D3E\u751F\u5217\u53EA\u80FD\u5F15\u7528\u540C\u5C42\u5B57\u6BB5\uFF0C\u4E0D\u652F\u6301 . \u6DF1\u53D6`, start, i);
|
|
5111
|
+
}
|
|
5112
|
+
tokens.push({ kind: "ref", value: name, pos: [start, i] });
|
|
5113
|
+
continue;
|
|
5114
|
+
}
|
|
5115
|
+
if (char === "#") {
|
|
5116
|
+
i += 1;
|
|
5117
|
+
const textStart = i;
|
|
5118
|
+
while (i < source.length && source[i] !== "#") i += 1;
|
|
5119
|
+
if (i >= source.length) fail('\u65E5\u671F\u5B57\u9762\u91CF\u7F3A\u5C11\u95ED\u5408\u7684 "#"', start, source.length);
|
|
5120
|
+
const text = source.slice(textStart, i);
|
|
5121
|
+
i += 1;
|
|
5122
|
+
const ms = parseDateLiteral(text);
|
|
5123
|
+
if (ms === null) {
|
|
5124
|
+
fail(`\u65E5\u671F\u5B57\u9762\u91CF "${text}" \u4E0D\u5408\u6CD5\uFF08\u53EA\u8BA4 #YYYY-MM-DD# \u4E0E #YYYY-MM-DDTHH:mm#\uFF09`, start, i);
|
|
5125
|
+
}
|
|
5126
|
+
tokens.push({ kind: "date", value: ms, pos: [start, i] });
|
|
5127
|
+
continue;
|
|
5128
|
+
}
|
|
5129
|
+
if (char === '"') {
|
|
5130
|
+
i += 1;
|
|
5131
|
+
let text = "";
|
|
5132
|
+
while (i < source.length && source[i] !== '"') {
|
|
5133
|
+
if (source[i] === "\n") fail("\u5B57\u7B26\u4E32\u4E0D\u80FD\u8DE8\u884C", start, i);
|
|
5134
|
+
if (source[i] === "\\") {
|
|
5135
|
+
const next = source[i + 1];
|
|
5136
|
+
if (next !== '"' && next !== "\\") {
|
|
5137
|
+
fail(`\u5B57\u7B26\u4E32\u91CC\u53EA\u5141\u8BB8 \\" \u4E0E \\\\ \u4E24\u79CD\u8F6C\u4E49\uFF0C\u6536\u5230 "\\${String(next ?? "")}"`, i, i + 2);
|
|
5138
|
+
}
|
|
5139
|
+
text += next;
|
|
5140
|
+
i += 2;
|
|
5141
|
+
continue;
|
|
5142
|
+
}
|
|
5143
|
+
text += source[i];
|
|
5144
|
+
i += 1;
|
|
5145
|
+
}
|
|
5146
|
+
if (i >= source.length) fail("\u5B57\u7B26\u4E32\u7F3A\u5C11\u95ED\u5408\u7684\u53CC\u5F15\u53F7", start, source.length);
|
|
5147
|
+
i += 1;
|
|
5148
|
+
tokens.push({ kind: "string", value: text, pos: [start, i] });
|
|
5149
|
+
continue;
|
|
5150
|
+
}
|
|
5151
|
+
if (DIGIT.test(char)) {
|
|
5152
|
+
while (i < source.length && DIGIT.test(source[i])) i += 1;
|
|
5153
|
+
if (source[i] === ".") {
|
|
5154
|
+
i += 1;
|
|
5155
|
+
if (!DIGIT.test(source[i] ?? "")) fail("\u5C0F\u6570\u70B9\u540E\u7F3A\u5C11\u6570\u5B57", start, i + 1);
|
|
5156
|
+
while (i < source.length && DIGIT.test(source[i])) i += 1;
|
|
5157
|
+
}
|
|
5158
|
+
if (source[i] === "e" || source[i] === "E") {
|
|
5159
|
+
fail("\u4E0D\u652F\u6301\u79D1\u5B66\u8BA1\u6570\u6CD5\u2014\u2014\u6D3E\u751F\u5217\u7684\u6570\u503C\u5E94\u5F53\u662F\u4EBA\u80FD\u4E00\u773C\u8BFB\u61C2\u7684\u5B57\u9762\u91CF", start, i + 1);
|
|
5160
|
+
}
|
|
5161
|
+
tokens.push({ kind: "number", value: Number(source.slice(start, i)), pos: [start, i] });
|
|
5162
|
+
continue;
|
|
5163
|
+
}
|
|
5164
|
+
if (IDENT_START.test(char)) {
|
|
5165
|
+
while (i < source.length && IDENT_PART.test(source[i])) i += 1;
|
|
5166
|
+
const word = source.slice(start, i);
|
|
5167
|
+
if (word === "true" || word === "false") {
|
|
5168
|
+
tokens.push({ kind: "bool", value: word === "true", pos: [start, i] });
|
|
5169
|
+
continue;
|
|
5170
|
+
}
|
|
5171
|
+
if (CALC_FUNCTIONS.includes(word)) {
|
|
5172
|
+
tokens.push({ kind: "ident", value: word, pos: [start, i] });
|
|
5173
|
+
continue;
|
|
5174
|
+
}
|
|
5175
|
+
fail(
|
|
5176
|
+
`\u672A\u77E5\u7684\u6807\u8BC6\u7B26 "${word}"\u3002\u5B57\u6BB5\u8981\u5199\u6210 [${word}]\uFF1B\u51FD\u6570\u53EA\u6709 ${CALC_FUNCTIONS.join(" / ")}`,
|
|
5177
|
+
start,
|
|
5178
|
+
i
|
|
5179
|
+
);
|
|
5180
|
+
}
|
|
5181
|
+
if (char === "(") {
|
|
5182
|
+
tokens.push({ kind: "lparen", value: "(", pos: [start, i + 1] });
|
|
5183
|
+
i += 1;
|
|
5184
|
+
continue;
|
|
5185
|
+
}
|
|
5186
|
+
if (char === ")") {
|
|
5187
|
+
tokens.push({ kind: "rparen", value: ")", pos: [start, i + 1] });
|
|
5188
|
+
i += 1;
|
|
5189
|
+
continue;
|
|
5190
|
+
}
|
|
5191
|
+
if (char === ",") {
|
|
5192
|
+
tokens.push({ kind: "comma", value: ",", pos: [start, i + 1] });
|
|
5193
|
+
i += 1;
|
|
5194
|
+
continue;
|
|
5195
|
+
}
|
|
5196
|
+
const op = OPERATORS.find((candidate) => source.startsWith(candidate, i));
|
|
5197
|
+
if (op) {
|
|
5198
|
+
i += op.length;
|
|
5199
|
+
tokens.push({ kind: "op", value: op, pos: [start, i] });
|
|
5200
|
+
continue;
|
|
5201
|
+
}
|
|
5202
|
+
const hint = char === "=" ? "\u5224\u65AD\u76F8\u7B49\u8981\u5199 ==" : char === "&" ? "\u5E76\u4E14\u8981\u5199\u6210 IF \u7684\u5D4C\u5957\uFF1Bcalc \u4E0D\u652F\u6301\u903B\u8F91\u8FD0\u7B97\u7B26" : char === "|" ? "\u6216\u8005\u8981\u5199\u6210 IF \u7684\u5D4C\u5957\uFF1Bcalc \u4E0D\u652F\u6301\u903B\u8F91\u8FD0\u7B97\u7B26" : char === "!" ? "\u4E0D\u7B49\u8981\u5199 !=" : char === "'" ? "\u5B57\u7B26\u4E32\u8981\u7528\u53CC\u5F15\u53F7\uFF08\u5355\u5F15\u53F7\u662F YAML \u7684\u5F15\u53F7\uFF09" : "\u5B83\u4E0D\u5728 calc \u7684\u8BCD\u6CD5\u8868\u91CC";
|
|
5203
|
+
fail(`\u65E0\u6CD5\u8BC6\u522B\u7684\u5B57\u7B26 "${char}"\u2014\u2014${hint}`, start, i + 1);
|
|
5204
|
+
}
|
|
5205
|
+
tokens.push({ kind: "eof", value: "", pos: [source.length, source.length] });
|
|
5206
|
+
return tokens;
|
|
5207
|
+
}
|
|
5208
|
+
function parseDateLiteral(text) {
|
|
5209
|
+
const match = text.match(/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}))?$/);
|
|
5210
|
+
if (!match) return null;
|
|
5211
|
+
const [, y, mo, d, h, mi] = match;
|
|
5212
|
+
const year = Number(y);
|
|
5213
|
+
const month = Number(mo);
|
|
5214
|
+
const day = Number(d);
|
|
5215
|
+
const hour = h === void 0 ? 0 : Number(h);
|
|
5216
|
+
const minute = mi === void 0 ? 0 : Number(mi);
|
|
5217
|
+
if (month < 1 || month > 12 || day < 1 || day > 31 || hour > 23 || minute > 59) return null;
|
|
5218
|
+
const ms = Date.UTC(year, month - 1, day, hour, minute);
|
|
5219
|
+
const back = new Date(ms);
|
|
5220
|
+
if (back.getUTCMonth() !== month - 1 || back.getUTCDate() !== day) return null;
|
|
5221
|
+
return ms;
|
|
5222
|
+
}
|
|
5223
|
+
|
|
5224
|
+
// core/shared/calc/parser.ts
|
|
5225
|
+
var CMP_OPS = [">", ">=", "<", "<=", "==", "!="];
|
|
5226
|
+
var ARITY = {
|
|
5227
|
+
IF: [3, 3],
|
|
5228
|
+
MIN: [2, Infinity],
|
|
5229
|
+
MAX: [2, Infinity],
|
|
5230
|
+
ROUND: [1, 2],
|
|
5231
|
+
CONCAT: [2, Infinity],
|
|
5232
|
+
ABS: [1, 1]
|
|
5233
|
+
};
|
|
5234
|
+
function parseCalc(source) {
|
|
5235
|
+
const tokens = tokenize(source);
|
|
5236
|
+
let at = 0;
|
|
5237
|
+
const peek = () => tokens[at];
|
|
5238
|
+
const next = () => tokens[at++];
|
|
5239
|
+
const fail = (message, token) => {
|
|
5240
|
+
throw new SomaCalcSyntaxError(message, source, token.pos);
|
|
5241
|
+
};
|
|
5242
|
+
const expect = (kind, what) => {
|
|
5243
|
+
const token = peek();
|
|
5244
|
+
if (token.kind !== kind) fail(`\u7F3A\u5C11${what}`, token);
|
|
5245
|
+
return next();
|
|
5246
|
+
};
|
|
5247
|
+
const parseCmp = () => {
|
|
5248
|
+
const left = parseSum();
|
|
5249
|
+
const token = peek();
|
|
5250
|
+
if (token.kind === "op" && CMP_OPS.includes(String(token.value))) {
|
|
5251
|
+
next();
|
|
5252
|
+
const right = parseSum();
|
|
5253
|
+
const after = peek();
|
|
5254
|
+
if (after.kind === "op" && CMP_OPS.includes(String(after.value))) {
|
|
5255
|
+
fail("\u6BD4\u8F83\u4E0D\u80FD\u8FDE\u5199\uFF08a < b < c \u51E0\u4E4E\u603B\u662F\u5199\u9519\u4E86\u610F\u601D\uFF09\u2014\u2014\u8BF7\u62C6\u6210\u4E24\u4E2A IF \u6216\u6539\u7528 between \u8C13\u8BCD", after);
|
|
5256
|
+
}
|
|
5257
|
+
return { k: "bin", op: String(token.value), left, right, pos: [left.pos[0], right.pos[1]] };
|
|
5258
|
+
}
|
|
5259
|
+
return left;
|
|
5260
|
+
};
|
|
5261
|
+
const parseSum = () => {
|
|
5262
|
+
let node = parseProduct();
|
|
5263
|
+
for (; ; ) {
|
|
5264
|
+
const token = peek();
|
|
5265
|
+
if (token.kind !== "op" || token.value !== "+" && token.value !== "-") return node;
|
|
5266
|
+
next();
|
|
5267
|
+
const right = parseProduct();
|
|
5268
|
+
node = { k: "bin", op: token.value, left: node, right, pos: [node.pos[0], right.pos[1]] };
|
|
5269
|
+
}
|
|
5270
|
+
};
|
|
5271
|
+
const parseProduct = () => {
|
|
5272
|
+
let node = parseUnary();
|
|
5273
|
+
for (; ; ) {
|
|
5274
|
+
const token = peek();
|
|
5275
|
+
if (token.kind !== "op" || token.value !== "*" && token.value !== "/") return node;
|
|
5276
|
+
next();
|
|
5277
|
+
const right = parseUnary();
|
|
5278
|
+
node = { k: "bin", op: token.value, left: node, right, pos: [node.pos[0], right.pos[1]] };
|
|
5279
|
+
}
|
|
5280
|
+
};
|
|
5281
|
+
const parseUnary = () => {
|
|
5282
|
+
const token = peek();
|
|
5283
|
+
if (token.kind === "op" && token.value === "-") {
|
|
5284
|
+
next();
|
|
5285
|
+
const arg = parseUnary();
|
|
5286
|
+
return { k: "un", op: "-", arg, pos: [token.pos[0], arg.pos[1]] };
|
|
5287
|
+
}
|
|
5288
|
+
return parsePrimary();
|
|
5289
|
+
};
|
|
5290
|
+
const parsePrimary = () => {
|
|
5291
|
+
const token = next();
|
|
5292
|
+
switch (token.kind) {
|
|
5293
|
+
case "number":
|
|
5294
|
+
return { k: "num", v: token.value, pos: token.pos };
|
|
5295
|
+
case "string":
|
|
5296
|
+
return { k: "str", v: token.value, pos: token.pos };
|
|
5297
|
+
case "date":
|
|
5298
|
+
return { k: "date", v: token.value, pos: token.pos };
|
|
5299
|
+
case "bool":
|
|
5300
|
+
return { k: "bool", v: token.value, pos: token.pos };
|
|
5301
|
+
case "ref":
|
|
5302
|
+
return { k: "ref", name: token.value, pos: token.pos };
|
|
5303
|
+
case "lparen": {
|
|
5304
|
+
const inner = parseCmp();
|
|
5305
|
+
expect("rparen", '\u53F3\u62EC\u53F7 ")"');
|
|
5306
|
+
return inner;
|
|
5307
|
+
}
|
|
5308
|
+
case "ident":
|
|
5309
|
+
return parseCall(token);
|
|
5310
|
+
case "op":
|
|
5311
|
+
return fail(`\u8FD0\u7B97\u7B26 "${String(token.value)}" \u524D\u9762\u7F3A\u5C11\u64CD\u4F5C\u6570`, token);
|
|
5312
|
+
case "eof":
|
|
5313
|
+
return fail("\u8868\u8FBE\u5F0F\u4E0D\u5B8C\u6574", token);
|
|
5314
|
+
default:
|
|
5315
|
+
return fail(`\u610F\u5916\u7684 "${String(token.value)}"`, token);
|
|
5316
|
+
}
|
|
5317
|
+
};
|
|
5318
|
+
const parseCall = (name) => {
|
|
5319
|
+
const fn = name.value;
|
|
5320
|
+
expect("lparen", `${fn} \u540E\u7684\u5DE6\u62EC\u53F7 "("`);
|
|
5321
|
+
const args = [];
|
|
5322
|
+
if (peek().kind !== "rparen") {
|
|
5323
|
+
args.push(parseCmp());
|
|
5324
|
+
while (peek().kind === "comma") {
|
|
5325
|
+
next();
|
|
5326
|
+
if (fn === "ROUND" && args.length === 1) {
|
|
5327
|
+
const digits = peek();
|
|
5328
|
+
if (digits.kind !== "number" || !Number.isInteger(digits.value) || digits.value < 0 || digits.value > 6) {
|
|
5329
|
+
fail("ROUND \u7684\u7B2C\u4E8C\u53C2\u5FC5\u987B\u662F 0~6 \u7684\u6574\u6570\u5B57\u9762\u91CF", digits);
|
|
5330
|
+
}
|
|
5331
|
+
next();
|
|
5332
|
+
args.push({ k: "num", v: digits.value, pos: digits.pos });
|
|
5333
|
+
continue;
|
|
5334
|
+
}
|
|
5335
|
+
args.push(parseCmp());
|
|
5336
|
+
}
|
|
5337
|
+
}
|
|
5338
|
+
const close = expect("rparen", `${fn} \u7684\u53F3\u62EC\u53F7 ")"`);
|
|
5339
|
+
const [min, max] = ARITY[fn];
|
|
5340
|
+
if (args.length < min || args.length > max) {
|
|
5341
|
+
const want = max === Infinity ? `\u81F3\u5C11 ${min} \u4E2A` : min === max ? `${min} \u4E2A` : `${min}~${max} \u4E2A`;
|
|
5342
|
+
fail(`${fn} \u9700\u8981${want}\u53C2\u6570\uFF0C\u6536\u5230 ${args.length} \u4E2A`, name);
|
|
5343
|
+
}
|
|
5344
|
+
return { k: "call", fn, args, pos: [name.pos[0], close.pos[1]] };
|
|
5345
|
+
};
|
|
5346
|
+
const ast = parseCmp();
|
|
5347
|
+
const rest = peek();
|
|
5348
|
+
if (rest.kind !== "eof") {
|
|
5349
|
+
fail(`\u8868\u8FBE\u5F0F\u5728\u8FD9\u91CC\u5C31\u7ED3\u675F\u4E86\uFF0C\u540E\u9762\u7684 "${String(rest.value)}" \u662F\u591A\u4F59\u7684`, rest);
|
|
5350
|
+
}
|
|
5351
|
+
return ast;
|
|
5352
|
+
}
|
|
5353
|
+
function collectCalcRefs(ast) {
|
|
5354
|
+
const out = [];
|
|
5355
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5356
|
+
const walk = (node) => {
|
|
5357
|
+
switch (node.k) {
|
|
5358
|
+
case "ref":
|
|
5359
|
+
if (!seen.has(node.name)) {
|
|
5360
|
+
seen.add(node.name);
|
|
5361
|
+
out.push(node.name);
|
|
5362
|
+
}
|
|
5363
|
+
return;
|
|
5364
|
+
case "un":
|
|
5365
|
+
walk(node.arg);
|
|
5366
|
+
return;
|
|
5367
|
+
case "bin":
|
|
5368
|
+
walk(node.left);
|
|
5369
|
+
walk(node.right);
|
|
5370
|
+
return;
|
|
5371
|
+
case "call":
|
|
5372
|
+
node.args.forEach(walk);
|
|
5373
|
+
return;
|
|
5374
|
+
default:
|
|
5375
|
+
return;
|
|
5376
|
+
}
|
|
5377
|
+
};
|
|
5378
|
+
walk(ast);
|
|
5379
|
+
return out;
|
|
5380
|
+
}
|
|
5381
|
+
|
|
5382
|
+
// core/shared/calc/typer.ts
|
|
5383
|
+
var FIELD_TO_CALC = {
|
|
5384
|
+
int: "number",
|
|
5385
|
+
float: "number",
|
|
5386
|
+
money: "number",
|
|
5387
|
+
percent: "number",
|
|
5388
|
+
progress: "number",
|
|
5389
|
+
text: "text",
|
|
5390
|
+
url: "text",
|
|
5391
|
+
enum: "text",
|
|
5392
|
+
bool: "bool",
|
|
5393
|
+
date: "date",
|
|
5394
|
+
datetime: "date"
|
|
5395
|
+
};
|
|
5396
|
+
var CALC_TO_FIELD = {
|
|
5397
|
+
number: ["int", "float", "money", "percent", "progress"],
|
|
5398
|
+
text: ["text", "url", "enum"],
|
|
5399
|
+
bool: ["bool"],
|
|
5400
|
+
date: ["date", "datetime"]
|
|
5401
|
+
};
|
|
5402
|
+
function inferCalcType(ast, ctx) {
|
|
5403
|
+
return infer(ast, ctx);
|
|
5404
|
+
}
|
|
5405
|
+
function infer(node, ctx) {
|
|
5406
|
+
const bad = (message, expected, actual) => {
|
|
5407
|
+
throw new SomaCalcTypeError(message, ctx.source, node.pos, expected, actual);
|
|
5408
|
+
};
|
|
5409
|
+
switch (node.k) {
|
|
5410
|
+
case "num":
|
|
5411
|
+
return "number";
|
|
5412
|
+
case "str":
|
|
5413
|
+
return "text";
|
|
5414
|
+
case "bool":
|
|
5415
|
+
return "bool";
|
|
5416
|
+
case "date":
|
|
5417
|
+
return "date";
|
|
5418
|
+
case "ref": {
|
|
5419
|
+
const declared = ctx.fieldTypes[node.name];
|
|
5420
|
+
if (declared === void 0 && !(node.name in ctx.fieldTypes)) {
|
|
5421
|
+
bad(`\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5B57\u6BB5 "${node.name}"`, "\u5B57\u5178\u91CC\u7684\u5B57\u6BB5", "\u672A\u58F0\u660E");
|
|
5422
|
+
}
|
|
5423
|
+
const kind = FIELD_TO_CALC[declared ?? "text"];
|
|
5424
|
+
if (!kind) {
|
|
5425
|
+
bad(
|
|
5426
|
+
`\u5B57\u6BB5 "${node.name}" \u662F ${declared} \u7C7B\u578B\uFF0C\u4E0D\u80FD\u53C2\u4E0E\u8BA1\u7B97\uFF08\u53EF\u5F15\u7528\u7684\u7C7B\u578B\uFF1A${Object.keys(FIELD_TO_CALC).join(" / ")}\uFF09`,
|
|
5427
|
+
"\u53EF\u8BA1\u7B97\u7684\u5B57\u6BB5\u7C7B\u578B",
|
|
5428
|
+
String(declared)
|
|
5429
|
+
);
|
|
5430
|
+
}
|
|
5431
|
+
return kind;
|
|
5432
|
+
}
|
|
5433
|
+
case "un": {
|
|
5434
|
+
const inner = infer(node.arg, ctx);
|
|
5435
|
+
if (inner !== "number") bad("\u53D6\u8D1F\u53EA\u80FD\u4F5C\u7528\u5728\u6570\u503C\u4E0A", "number", inner);
|
|
5436
|
+
return "number";
|
|
5437
|
+
}
|
|
5438
|
+
case "bin": {
|
|
5439
|
+
const left = infer(node.left, ctx);
|
|
5440
|
+
const right = infer(node.right, ctx);
|
|
5441
|
+
switch (node.op) {
|
|
5442
|
+
case "+":
|
|
5443
|
+
case "-": {
|
|
5444
|
+
if (left === "number" && right === "number") return "number";
|
|
5445
|
+
if (node.op === "-" && left === "date" && right === "date") return "number";
|
|
5446
|
+
if (left === "date" && right === "number") return "date";
|
|
5447
|
+
if (node.op === "+" && left === "number" && right === "date") return "date";
|
|
5448
|
+
if (node.op === "+" && (left === "text" || right === "text")) {
|
|
5449
|
+
bad("\u6587\u672C\u4E0D\u80FD\u7528 + \u62FC\u63A5\u2014\u2014\u8BF7\u7528 CONCAT(a, b)", "number \u6216 date", `${left} \u4E0E ${right}`);
|
|
5450
|
+
}
|
|
5451
|
+
return bad(`${node.op} \u4E0D\u80FD\u4F5C\u7528\u5728 ${left} \u4E0E ${right} \u4E0A`, "number", `${left} \u4E0E ${right}`);
|
|
5452
|
+
}
|
|
5453
|
+
case "*":
|
|
5454
|
+
case "/": {
|
|
5455
|
+
if (left === "number" && right === "number") return "number";
|
|
5456
|
+
return bad(`${node.op} \u53EA\u80FD\u4F5C\u7528\u5728\u6570\u503C\u4E0A`, "number", `${left} \u4E0E ${right}`);
|
|
5457
|
+
}
|
|
5458
|
+
case ">":
|
|
5459
|
+
case ">=":
|
|
5460
|
+
case "<":
|
|
5461
|
+
case "<=": {
|
|
5462
|
+
if (left === right && (left === "number" || left === "date")) return "bool";
|
|
5463
|
+
return bad("\u6BD4\u8F83\u5927\u5C0F\u53EA\u80FD\u5728\u4E24\u4E2A\u6570\u503C\u4E4B\u95F4\u6216\u4E24\u4E2A\u65E5\u671F\u4E4B\u95F4", "\u540C\u4E3A number \u6216\u540C\u4E3A date", `${left} \u4E0E ${right}`);
|
|
5464
|
+
}
|
|
5465
|
+
case "==":
|
|
5466
|
+
case "!=": {
|
|
5467
|
+
if (left === right) return "bool";
|
|
5468
|
+
return bad("\u76F8\u7B49\u6BD4\u8F83\u7684\u4E24\u4FA7\u5FC5\u987B\u540C\u578B", left, right);
|
|
5469
|
+
}
|
|
5470
|
+
}
|
|
5471
|
+
}
|
|
5472
|
+
case "call": {
|
|
5473
|
+
switch (node.fn) {
|
|
5474
|
+
case "IF": {
|
|
5475
|
+
const cond = infer(node.args[0], ctx);
|
|
5476
|
+
if (cond !== "bool") bad("IF \u7684\u7B2C\u4E00\u4E2A\u53C2\u6570\u5FC5\u987B\u662F\u5224\u65AD\uFF08\u6BD4\u8F83\u6216\u5E03\u5C14\u5B57\u6BB5\uFF09", "bool", cond);
|
|
5477
|
+
const a = infer(node.args[1], ctx);
|
|
5478
|
+
const b = infer(node.args[2], ctx);
|
|
5479
|
+
if (a !== b) bad("IF \u7684\u4E24\u4E2A\u5206\u652F\u5FC5\u987B\u540C\u578B", a, b);
|
|
5480
|
+
return a;
|
|
5481
|
+
}
|
|
5482
|
+
case "MIN":
|
|
5483
|
+
case "MAX": {
|
|
5484
|
+
const kinds = node.args.map((arg) => infer(arg, ctx));
|
|
5485
|
+
const first = kinds[0];
|
|
5486
|
+
if (first !== "number" && first !== "date") {
|
|
5487
|
+
bad(`${node.fn} \u53EA\u80FD\u4F5C\u7528\u5728\u6570\u503C\u6216\u65E5\u671F\u4E0A`, "number \u6216 date", first);
|
|
5488
|
+
}
|
|
5489
|
+
const off = kinds.find((kind) => kind !== first);
|
|
5490
|
+
if (off) bad(`${node.fn} \u7684\u53C2\u6570\u5FC5\u987B\u540C\u578B`, first, off);
|
|
5491
|
+
return first;
|
|
5492
|
+
}
|
|
5493
|
+
case "ROUND": {
|
|
5494
|
+
const value = infer(node.args[0], ctx);
|
|
5495
|
+
if (value !== "number") bad("ROUND \u53EA\u80FD\u4F5C\u7528\u5728\u6570\u503C\u4E0A", "number", value);
|
|
5496
|
+
return "number";
|
|
5497
|
+
}
|
|
5498
|
+
case "ABS": {
|
|
5499
|
+
const value = infer(node.args[0], ctx);
|
|
5500
|
+
if (value !== "number") bad("ABS \u53EA\u80FD\u4F5C\u7528\u5728\u6570\u503C\u4E0A", "number", value);
|
|
5501
|
+
return "number";
|
|
5502
|
+
}
|
|
5503
|
+
case "CONCAT": {
|
|
5504
|
+
node.args.forEach((arg) => infer(arg, ctx));
|
|
5505
|
+
return "text";
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
}
|
|
5509
|
+
}
|
|
5510
|
+
}
|
|
5511
|
+
function assertCalcResultType(result, declaredFieldType, ctx, ast) {
|
|
5512
|
+
const declared = declaredFieldType ?? "text";
|
|
5513
|
+
const allowed = CALC_TO_FIELD[result];
|
|
5514
|
+
if (!allowed.includes(declared)) {
|
|
5515
|
+
throw new SomaCalcTypeError(
|
|
5516
|
+
`\u8868\u8FBE\u5F0F\u7B97\u51FA\u6765\u662F ${result}\uFF0C\u4F46\u5B57\u6BB5\u58F0\u660E\u7684\u662F ${declared}\uFF08${result} \u53EF\u4EE5\u58F0\u660E\u4E3A\uFF1A${allowed.join(" / ")}\uFF09`,
|
|
5517
|
+
ctx.source,
|
|
5518
|
+
ast.pos,
|
|
5519
|
+
allowed.join("|"),
|
|
5520
|
+
declared
|
|
5521
|
+
);
|
|
5522
|
+
}
|
|
5523
|
+
if (result === "bool") {
|
|
5524
|
+
throw new SomaCalcTypeError(
|
|
5525
|
+
'\u6D3E\u751F\u5217\u4E0D\u80FD\u662F\u5224\u65AD\u7ED3\u679C\u2014\u2014\u5B57\u6BB5\u7C7B\u578B\u91CC\u6CA1\u6709\u300C\u663E\u793A true\u300D\u8FD9\u79CD\u4E1A\u52A1\u8BED\u4E49\uFF1B\u60F3\u6309\u6761\u4EF6\u51FA\u4E0D\u540C\u6587\u6848\u8BF7\u7528 IF(\u6761\u4EF6, "A", "B")',
|
|
5526
|
+
ctx.source,
|
|
5527
|
+
ast.pos,
|
|
5528
|
+
"number|text|date",
|
|
5529
|
+
"bool"
|
|
5530
|
+
);
|
|
5531
|
+
}
|
|
5532
|
+
}
|
|
5533
|
+
|
|
5534
|
+
// core/client/parser/reaction-parser.ts
|
|
5535
|
+
var PHASES = new Set(SOMA_REACTION_PHASES);
|
|
5536
|
+
var DISPLAYS = new Set(SOMA_FIELD_DISPLAYS);
|
|
5537
|
+
var PATTERNS = new Set(SOMA_FIELD_PATTERNS);
|
|
5538
|
+
var PATCH_KEYS = /* @__PURE__ */ new Set(["visible", "display", "pattern", "required", "value", "options", "message"]);
|
|
5539
|
+
var CONFIG_KEYS2 = /* @__PURE__ */ new Set(["when", "depends", "on", "target", "fulfill", "otherwise"]);
|
|
5540
|
+
var CALC_WRITABLE = /* @__PURE__ */ new Set(["int", "float", "money", "percent", "progress", "text", "url", "enum", "date", "datetime"]);
|
|
5541
|
+
function parseReactions(input, deps) {
|
|
5542
|
+
const { raw, fields, named, path } = input;
|
|
5543
|
+
const { fail } = deps;
|
|
5544
|
+
if (!Array.isArray(raw)) fail("reactions \u5FC5\u987B\u662F\u6570\u7EC4", path);
|
|
5545
|
+
const list = raw;
|
|
5546
|
+
const fieldKeys = Object.keys(fields);
|
|
5547
|
+
const fieldTypes = Object.fromEntries(
|
|
5548
|
+
fieldKeys.map((key) => [key, fields[key].type])
|
|
5549
|
+
);
|
|
5550
|
+
const parsed = [];
|
|
5551
|
+
list.forEach((entry, index) => {
|
|
5552
|
+
const at = `${path}[${index}]`;
|
|
5553
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
5554
|
+
fail("\u6BCF\u6761\u53CD\u5E94\u5FC5\u987B\u662F\u5BF9\u8C61", at);
|
|
5555
|
+
}
|
|
5556
|
+
const box = entry;
|
|
5557
|
+
for (const key of Object.keys(box)) {
|
|
5558
|
+
if (!CONFIG_KEYS2.has(key)) {
|
|
5559
|
+
fail(`\u672A\u77E5\u7684\u53CD\u5E94\u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: ${[...CONFIG_KEYS2].join(" / ")}\uFF09`, `${at}.${key}`);
|
|
5560
|
+
}
|
|
5561
|
+
}
|
|
5562
|
+
const phaseRaw = box.on === void 0 ? "field_value_change" : String(box.on);
|
|
5563
|
+
if (!PHASES.has(phaseRaw)) {
|
|
5564
|
+
fail(`\u672A\u77E5\u7684\u89E6\u53D1\u65F6\u673A "${phaseRaw}"\uFF08\u652F\u6301: ${SOMA_REACTION_PHASES.join(" / ")}\uFF09`, `${at}.on`);
|
|
5565
|
+
}
|
|
5566
|
+
const phase = phaseRaw;
|
|
5567
|
+
const reads = /* @__PURE__ */ new Set();
|
|
5568
|
+
if (box.when !== void 0) {
|
|
5569
|
+
const issues = validatePredicate(box.when, fieldKeys, `${at}.when`, { fieldTypes, named });
|
|
5570
|
+
if (issues.length > 0) fail(issues.join("\uFF1B"), `${at}.when`);
|
|
5571
|
+
for (const field of collectPredicateFields(box.when, named)) reads.add(field);
|
|
5572
|
+
}
|
|
5573
|
+
if (box.depends !== void 0) {
|
|
5574
|
+
if (!Array.isArray(box.depends)) fail("depends \u5FC5\u987B\u662F\u5B57\u6BB5\u540D\u6570\u7EC4", `${at}.depends`);
|
|
5575
|
+
for (const item of box.depends) {
|
|
5576
|
+
const field = String(item ?? "");
|
|
5577
|
+
if (!fieldKeys.includes(field)) {
|
|
5578
|
+
fail(`depends \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5B57\u6BB5 "${field}"`, `${at}.depends`);
|
|
5579
|
+
}
|
|
5580
|
+
reads.add(field);
|
|
5581
|
+
}
|
|
5582
|
+
}
|
|
5583
|
+
if (box.when === void 0 && box.depends === void 0) {
|
|
5584
|
+
fail(
|
|
5585
|
+
"when \u4E0E depends \u81F3\u5C11\u8981\u7ED9\u4E00\u4E2A\u2014\u2014\u4E24\u4E2A\u90FD\u6CA1\u6709\u7684\u53CD\u5E94\u4E0D\u77E5\u9053\u4F55\u65F6\u8BE5\u8DD1\uFF0C\u5B83\u65E2\u4E0D\u4F1A\u751F\u6548\u4E5F\u4E0D\u4F1A\u62A5\u9519\uFF0C\u662F\u6700\u96BE\u53D1\u73B0\u7684\u4E00\u7C7B\u7A7A\u58F0\u660E",
|
|
5586
|
+
at
|
|
5587
|
+
);
|
|
5588
|
+
}
|
|
5589
|
+
if (box.target !== void 0) {
|
|
5590
|
+
const target = String(box.target);
|
|
5591
|
+
if (!fieldKeys.includes(target)) fail(`target \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5B57\u6BB5 "${target}"`, `${at}.target`);
|
|
5592
|
+
if (!phase.startsWith("field_validate")) {
|
|
5593
|
+
fail('target \u53EA\u5728 on: field_validate_* \u65F6\u6709\u610F\u4E49\uFF08\u5176\u4F59\u65F6\u673A\u6CA1\u6709"\u54EA\u4E2A\u5B57\u6BB5"\u8FD9\u4E2A\u6982\u5FF5\uFF09', `${at}.target`);
|
|
5594
|
+
}
|
|
5595
|
+
reads.add(target);
|
|
5596
|
+
} else if (phase.startsWith("field_validate")) {
|
|
5597
|
+
fail(`on: ${phase} \u5FC5\u987B\u7ED9 target\uFF08\u76EF\u7740\u54EA\u4E2A\u5B57\u6BB5\u7684\u6821\u9A8C\u7ED3\u679C\uFF09`, at);
|
|
5598
|
+
}
|
|
5599
|
+
const writes = /* @__PURE__ */ new Set();
|
|
5600
|
+
const calcAsts = {};
|
|
5601
|
+
for (const branch of ["fulfill", "otherwise"]) {
|
|
5602
|
+
const value = box[branch];
|
|
5603
|
+
if (value === void 0) continue;
|
|
5604
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5605
|
+
fail(`${branch} \u5FC5\u987B\u662F { \u5B57\u6BB5\u540D: patch } \u5BF9\u8C61`, `${at}.${branch}`);
|
|
5606
|
+
}
|
|
5607
|
+
for (const [target, patchRaw] of Object.entries(value)) {
|
|
5608
|
+
const patchPath = `${at}.${branch}.${target}`;
|
|
5609
|
+
if (target === SOMA_REACTION_FORM_KEY) {
|
|
5610
|
+
checkFormPatch(patchRaw, patchPath, fail);
|
|
5611
|
+
continue;
|
|
5612
|
+
}
|
|
5613
|
+
if (!fieldKeys.includes(target)) {
|
|
5614
|
+
fail(`${branch} \u7684\u76EE\u6807 "${target}" \u4E0D\u662F\u5B57\u5178\u91CC\u7684\u5B57\u6BB5`, patchPath);
|
|
5615
|
+
}
|
|
5616
|
+
const ast = checkFieldPatch(patchRaw, target, fields[target], fieldKeys, fieldTypes, patchPath, fail);
|
|
5617
|
+
if (ast) {
|
|
5618
|
+
calcAsts[`${branch}:${target}`] = ast.node;
|
|
5619
|
+
for (const ref of ast.refs) reads.add(ref);
|
|
5620
|
+
}
|
|
5621
|
+
writes.add(target);
|
|
5622
|
+
}
|
|
5623
|
+
}
|
|
5624
|
+
if (box.fulfill === void 0 && box.otherwise === void 0) {
|
|
5625
|
+
fail("fulfill \u4E0E otherwise \u81F3\u5C11\u8981\u7ED9\u4E00\u4E2A\uFF08\u4E00\u6761\u4EC0\u4E48\u90FD\u4E0D\u505A\u7684\u53CD\u5E94\u6CA1\u6709\u610F\u4E49\uFF09", at);
|
|
5626
|
+
}
|
|
5627
|
+
parsed.push({
|
|
5628
|
+
config: box,
|
|
5629
|
+
reads: [...reads],
|
|
5630
|
+
writes: [...writes],
|
|
5631
|
+
phase,
|
|
5632
|
+
calcAsts,
|
|
5633
|
+
declaredAt: index
|
|
5634
|
+
});
|
|
5635
|
+
});
|
|
5636
|
+
const order = topoSort(parsed, path, fail);
|
|
5637
|
+
const reactions = order.map((declaredAt, position) => {
|
|
5638
|
+
const item = parsed[declaredAt];
|
|
5639
|
+
return {
|
|
5640
|
+
index: position,
|
|
5641
|
+
declaredAt,
|
|
5642
|
+
reads: item.reads,
|
|
5643
|
+
writes: item.writes,
|
|
5644
|
+
phase: item.phase,
|
|
5645
|
+
config: item.config,
|
|
5646
|
+
calcAsts: item.calcAsts
|
|
5647
|
+
};
|
|
5648
|
+
});
|
|
5649
|
+
const byField = {};
|
|
5650
|
+
reactions.forEach((reaction) => {
|
|
5651
|
+
for (const field of reaction.reads) {
|
|
5652
|
+
(byField[field] ??= []).push(reaction.index);
|
|
5653
|
+
}
|
|
5654
|
+
});
|
|
5655
|
+
return {
|
|
5656
|
+
reactions,
|
|
5657
|
+
byField,
|
|
5658
|
+
provenance: buildProvenance(reactions, fieldKeys, input.sourceApiOf ?? {})
|
|
5659
|
+
};
|
|
5660
|
+
}
|
|
5661
|
+
function checkFormPatch(raw, path, fail) {
|
|
5662
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
5663
|
+
fail("submit \u7684 patch \u5FC5\u987B\u662F\u5BF9\u8C61 { disabled: \u5E03\u5C14 }", path);
|
|
5664
|
+
}
|
|
5665
|
+
const box = raw;
|
|
5666
|
+
for (const key of Object.keys(box)) {
|
|
5667
|
+
if (key !== "disabled") fail(`submit \u53EA\u652F\u6301 disabled\uFF0C\u6536\u5230 "${key}"`, `${path}.${key}`);
|
|
5668
|
+
}
|
|
5669
|
+
if (box.disabled !== void 0 && typeof box.disabled !== "boolean") {
|
|
5670
|
+
fail("submit.disabled \u5FC5\u987B\u662F\u5E03\u5C14", `${path}.disabled`);
|
|
5671
|
+
}
|
|
5672
|
+
}
|
|
5673
|
+
function checkFieldPatch(raw, target, field, fieldKeys, fieldTypes, path, fail) {
|
|
5674
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
5675
|
+
fail("patch \u5FC5\u987B\u662F\u5BF9\u8C61", path);
|
|
5676
|
+
}
|
|
5677
|
+
const patch = raw;
|
|
5678
|
+
for (const key of Object.keys(patch)) {
|
|
5679
|
+
if (!PATCH_KEYS.has(key)) {
|
|
5680
|
+
fail(`\u672A\u77E5\u7684 patch \u952E "${key}"\uFF08\u652F\u6301: ${[...PATCH_KEYS].join(" / ")}\uFF09`, `${path}.${key}`);
|
|
5681
|
+
}
|
|
5682
|
+
}
|
|
5683
|
+
if (patch.visible !== void 0 && typeof patch.visible !== "boolean") {
|
|
5684
|
+
fail("visible \u5FC5\u987B\u662F\u5E03\u5C14\uFF08\u8981\u8FDE\u6570\u636E\u4E00\u8D77\u6458\u9664\u8BF7\u5199 display: none\uFF09", `${path}.visible`);
|
|
5685
|
+
}
|
|
5686
|
+
if (patch.visible !== void 0 && patch.display !== void 0) {
|
|
5687
|
+
fail("visible \u4E0E display \u53EA\u80FD\u7ED9\u4E00\u4E2A\u2014\u2014visible \u672C\u6765\u5C31\u662F display \u7684\u8BED\u6CD5\u7CD6", path);
|
|
5688
|
+
}
|
|
5689
|
+
if (patch.display !== void 0 && !DISPLAYS.has(String(patch.display))) {
|
|
5690
|
+
fail(`display \u53EA\u80FD\u662F ${SOMA_FIELD_DISPLAYS.join(" / ")}`, `${path}.display`);
|
|
5691
|
+
}
|
|
5692
|
+
if (patch.pattern !== void 0 && !PATTERNS.has(String(patch.pattern))) {
|
|
5693
|
+
fail(`pattern \u53EA\u80FD\u662F ${SOMA_FIELD_PATTERNS.join(" / ")}`, `${path}.pattern`);
|
|
5694
|
+
}
|
|
5695
|
+
if (patch.required !== void 0 && typeof patch.required !== "boolean") {
|
|
5696
|
+
fail("required \u5FC5\u987B\u662F\u5E03\u5C14", `${path}.required`);
|
|
5697
|
+
}
|
|
5698
|
+
if (patch.message !== void 0 && typeof patch.message !== "string") {
|
|
5699
|
+
fail("message \u5FC5\u987B\u662F\u5B57\u7B26\u4E32", `${path}.message`);
|
|
5700
|
+
}
|
|
5701
|
+
if (patch.options !== void 0) {
|
|
5702
|
+
const from = patch.options.from;
|
|
5703
|
+
if (typeof from !== "string" || !/^[A-Za-z_]\w*\.[A-Za-z_]\w*$/.test(from)) {
|
|
5704
|
+
fail("options.from \u5FC5\u987B\u662F '<\u5BF9\u8C61>.<\u5B57\u6BB5>' \u5F62\u6001", `${path}.options`);
|
|
5705
|
+
}
|
|
5706
|
+
if (field.type !== "enum") {
|
|
5707
|
+
fail(`options \u53EA\u80FD\u5199\u5728 enum \u5B57\u6BB5\u4E0A\uFF0C"${target}" \u662F ${field.type ?? "text"}`, `${path}.options`);
|
|
5708
|
+
}
|
|
5709
|
+
}
|
|
5710
|
+
if (patch.value !== void 0 && field.permission === "r") {
|
|
5711
|
+
fail(
|
|
5712
|
+
`"${target}" \u662F\u53EA\u8BFB\u5B57\u6BB5\uFF08permission: r\uFF09\uFF0C\u53CD\u5E94\u4E0D\u80FD\u7ED9\u5B83\u5199\u503C\u2014\u2014\u53EA\u8BFB\u662F\u6570\u636E\u5C42\u7684\u88C1\u51B3\uFF0C\u8054\u52A8\u7ED5\u8FC7\u5B83\u5C31\u7B49\u4E8E\u6CA1\u6709\u88C1\u51B3`,
|
|
5713
|
+
`${path}.value`
|
|
5714
|
+
);
|
|
5715
|
+
}
|
|
5716
|
+
if (patch.value === void 0) return null;
|
|
5717
|
+
if (patch.value === "clear") return null;
|
|
5718
|
+
if (typeof patch.value === "object" && patch.value !== null && "from" in patch.value) {
|
|
5719
|
+
const from = String(patch.value.from);
|
|
5720
|
+
if (!fieldKeys.includes(from)) fail(`value.from \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5B57\u6BB5 "${from}"`, `${path}.value`);
|
|
5721
|
+
return { node: null, refs: [from] };
|
|
5722
|
+
}
|
|
5723
|
+
if (typeof patch.value === "object" && patch.value !== null && "calc" in patch.value) {
|
|
5724
|
+
const source = String(patch.value.calc);
|
|
5725
|
+
const declared = field.type ?? "text";
|
|
5726
|
+
if (!CALC_WRITABLE.has(declared)) {
|
|
5727
|
+
fail(`calc \u4E0D\u80FD\u5199\u8FDB ${declared} \u7C7B\u578B\u7684\u5B57\u6BB5 "${target}"`, `${path}.value`);
|
|
5728
|
+
}
|
|
5729
|
+
try {
|
|
5730
|
+
const node = parseCalc(source);
|
|
5731
|
+
const ctx = { fieldTypes, source };
|
|
5732
|
+
const resultType = inferCalcType(node, ctx);
|
|
5733
|
+
assertCalcResultType(resultType, declared, ctx, node);
|
|
5734
|
+
return { node, refs: collectCalcRefs(node) };
|
|
5735
|
+
} catch (error) {
|
|
5736
|
+
if (error instanceof SomaCalcSyntaxError || error instanceof SomaCalcTypeError) {
|
|
5737
|
+
fail(error.message, `${path}.value`);
|
|
5738
|
+
}
|
|
5739
|
+
throw error;
|
|
5740
|
+
}
|
|
5741
|
+
}
|
|
5742
|
+
return fail("value \u53EA\u80FD\u662F 'clear' / { from: \u5B57\u6BB5 } / { calc: \u8868\u8FBE\u5F0F }", `${path}.value`);
|
|
5743
|
+
}
|
|
5744
|
+
function topoSort(parsed, path, fail) {
|
|
5745
|
+
const n = parsed.length;
|
|
5746
|
+
const writerOf = /* @__PURE__ */ new Map();
|
|
5747
|
+
parsed.forEach((item, index) => {
|
|
5748
|
+
for (const field of item.writes) {
|
|
5749
|
+
const list = writerOf.get(field) ?? [];
|
|
5750
|
+
list.push(index);
|
|
5751
|
+
writerOf.set(field, list);
|
|
5752
|
+
}
|
|
5753
|
+
});
|
|
5754
|
+
const edges = Array.from({ length: n }, () => /* @__PURE__ */ new Set());
|
|
5755
|
+
const indegree = new Array(n).fill(0);
|
|
5756
|
+
parsed.forEach((item, index) => {
|
|
5757
|
+
for (const field of item.reads) {
|
|
5758
|
+
for (const writer of writerOf.get(field) ?? []) {
|
|
5759
|
+
if (writer === index) continue;
|
|
5760
|
+
if (edges[writer].has(index)) continue;
|
|
5761
|
+
edges[writer].add(index);
|
|
5762
|
+
indegree[index] += 1;
|
|
5763
|
+
}
|
|
5764
|
+
}
|
|
5765
|
+
});
|
|
5766
|
+
const queue = [];
|
|
5767
|
+
for (let i = 0; i < n; i += 1) if (indegree[i] === 0) queue.push(i);
|
|
5768
|
+
queue.sort((a, b) => a - b);
|
|
5769
|
+
const order = [];
|
|
5770
|
+
while (queue.length > 0) {
|
|
5771
|
+
const current = queue.shift();
|
|
5772
|
+
order.push(current);
|
|
5773
|
+
const next = [];
|
|
5774
|
+
for (const to of edges[current]) {
|
|
5775
|
+
indegree[to] -= 1;
|
|
5776
|
+
if (indegree[to] === 0) next.push(to);
|
|
5777
|
+
}
|
|
5778
|
+
next.sort((a, b) => a - b);
|
|
5779
|
+
queue.push(...next);
|
|
5780
|
+
}
|
|
5781
|
+
if (order.length !== n) {
|
|
5782
|
+
const remaining = /* @__PURE__ */ new Set();
|
|
5783
|
+
for (let i = 0; i < n; i += 1) if (!order.includes(i)) remaining.add(i);
|
|
5784
|
+
const cycle = traceCycle(remaining, edges);
|
|
5785
|
+
fail(
|
|
5786
|
+
`\u53CD\u5E94\u4E4B\u95F4\u6210\u73AF\uFF1A${cycle.map((i) => `#${i + 1}`).join(" \u2192 ")} \u2192 #${cycle[0] + 1}\uFF08\u7F16\u53F7\u662F\u58F0\u660E\u5E8F\uFF09\u3002\u6210\u73AF\u7684\u53CD\u5E94\u4F1A\u5728\u4E00\u6B21\u8F93\u5165\u91CC\u6765\u56DE\u6539\u540C\u4E00\u6279\u5B57\u6BB5\uFF0C\u8868\u73B0\u662F\u8F93\u5165\u6846\u81EA\u5DF1\u8DF3\uFF1B\u8BF7\u628A\u5176\u4E2D\u4E00\u6761\u6539\u6210\u5355\u5411\uFF0C\u6216\u628A\u4E2D\u95F4\u7ED3\u679C\u505A\u6210\u4E00\u4E2A\u771F\u5B9E\u5B57\u6BB5`,
|
|
5787
|
+
path
|
|
5788
|
+
);
|
|
5789
|
+
}
|
|
5790
|
+
return order;
|
|
5791
|
+
}
|
|
5792
|
+
function traceCycle(remaining, edges) {
|
|
5793
|
+
const start = [...remaining][0];
|
|
5794
|
+
const stack = [];
|
|
5795
|
+
const onStack = /* @__PURE__ */ new Set();
|
|
5796
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5797
|
+
let found = null;
|
|
5798
|
+
const walk = (node) => {
|
|
5799
|
+
if (found) return;
|
|
5800
|
+
stack.push(node);
|
|
5801
|
+
onStack.add(node);
|
|
5802
|
+
seen.add(node);
|
|
5803
|
+
for (const to of edges[node]) {
|
|
5804
|
+
if (!remaining.has(to)) continue;
|
|
5805
|
+
if (onStack.has(to)) {
|
|
5806
|
+
found = stack.slice(stack.indexOf(to));
|
|
5807
|
+
return;
|
|
5808
|
+
}
|
|
5809
|
+
if (!seen.has(to)) walk(to);
|
|
5810
|
+
if (found) return;
|
|
5811
|
+
}
|
|
5812
|
+
stack.pop();
|
|
5813
|
+
onStack.delete(node);
|
|
5814
|
+
};
|
|
5815
|
+
walk(start);
|
|
5816
|
+
return found ?? [start];
|
|
5817
|
+
}
|
|
5818
|
+
function buildProvenance(reactions, fieldKeys, sourceApiOf) {
|
|
5819
|
+
const writtenBy = {};
|
|
5820
|
+
const directReads = {};
|
|
5821
|
+
for (const field of fieldKeys) {
|
|
5822
|
+
writtenBy[field] = [];
|
|
5823
|
+
directReads[field] = /* @__PURE__ */ new Set();
|
|
5824
|
+
}
|
|
5825
|
+
for (const reaction of reactions) {
|
|
5826
|
+
for (const target of reaction.writes) {
|
|
5827
|
+
writtenBy[target] ??= [];
|
|
5828
|
+
writtenBy[target].push(reaction.declaredAt);
|
|
5829
|
+
directReads[target] ??= /* @__PURE__ */ new Set();
|
|
5830
|
+
for (const source of reaction.reads) directReads[target].add(source);
|
|
5831
|
+
}
|
|
5832
|
+
}
|
|
5833
|
+
const closure = (field, seen) => {
|
|
5834
|
+
for (const upstream of directReads[field] ?? []) {
|
|
5835
|
+
if (seen.has(upstream)) continue;
|
|
5836
|
+
seen.add(upstream);
|
|
5837
|
+
closure(upstream, seen);
|
|
5838
|
+
}
|
|
5839
|
+
return seen;
|
|
5840
|
+
};
|
|
5841
|
+
const provenance = {};
|
|
5842
|
+
for (const field of Object.keys(directReads)) {
|
|
5843
|
+
provenance[field] = {
|
|
5844
|
+
writtenBy: writtenBy[field] ?? [],
|
|
5845
|
+
readsFrom: [...closure(field, /* @__PURE__ */ new Set())].sort(),
|
|
5846
|
+
...sourceApiOf[field] ? { sourceApi: sourceApiOf[field] } : {}
|
|
5847
|
+
};
|
|
5848
|
+
}
|
|
5849
|
+
return provenance;
|
|
5850
|
+
}
|
|
5851
|
+
|
|
5852
|
+
// core/shared/types/window.types.ts
|
|
5853
|
+
var SOMA_AGGREGATE_FNS = ["sum", "avg", "min", "max", "count"];
|
|
5854
|
+
var SOMA_SELECT_ALL_MODES = ["all", "filtered", "current_page"];
|
|
5855
|
+
|
|
5856
|
+
// core/client/parser/duration.ts
|
|
5857
|
+
function parseDuration(raw, where, fail) {
|
|
5858
|
+
const match = /^(\d+(?:\.\d+)?)(ms|s|m)$/.exec(raw.trim());
|
|
5859
|
+
if (!match) {
|
|
5860
|
+
fail(`${where} \u7684\u65F6\u957F "${raw}" \u975E\u6CD5\u2014\u2014\u5F62\u5982 500ms / 30s / 5m\uFF08\u5355\u4F4D\u5FC5\u586B\uFF0C\u4E0D\u731C\uFF09`);
|
|
5861
|
+
}
|
|
5862
|
+
const value = Number(match[1]);
|
|
5863
|
+
const unit = match[2];
|
|
5864
|
+
return unit === "ms" ? value : unit === "s" ? value * 1e3 : value * 6e4;
|
|
5865
|
+
}
|
|
5866
|
+
|
|
5867
|
+
// core/client/parser/window-parser.ts
|
|
5868
|
+
var MAX_FILTER_DEPTH = 8;
|
|
5869
|
+
var CONFIG_KEYS3 = /* @__PURE__ */ new Set([
|
|
5870
|
+
"mode",
|
|
5871
|
+
"block",
|
|
5872
|
+
"sort",
|
|
5873
|
+
"filter",
|
|
5874
|
+
"group",
|
|
5875
|
+
"aggregate",
|
|
5876
|
+
"selection",
|
|
5877
|
+
"select_all",
|
|
5878
|
+
"cache",
|
|
5879
|
+
"revalidate"
|
|
4295
5880
|
]);
|
|
5881
|
+
var NUMERIC_TYPES = /* @__PURE__ */ new Set(["int", "float", "money", "percent", "progress"]);
|
|
5882
|
+
var DEFAULT_BLOCK = { size: 100, max_blocks: 10, debounce_ms: 120 };
|
|
5883
|
+
function isPlainObject4(value) {
|
|
5884
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5885
|
+
}
|
|
5886
|
+
function parseWindow(input, deps) {
|
|
5887
|
+
const { raw, fields, path } = input;
|
|
5888
|
+
const fail = deps.fail;
|
|
5889
|
+
if (!isPlainObject4(raw)) fail("window \u5FC5\u987B\u662F\u6620\u5C04", path);
|
|
5890
|
+
const section = raw;
|
|
5891
|
+
for (const key of Object.keys(section)) {
|
|
5892
|
+
if (!CONFIG_KEYS3.has(key)) {
|
|
5893
|
+
fail(`\u672A\u77E5\u7684 window \u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: ${[...CONFIG_KEYS3].join(" / ")}\uFF09`, `${path}.${key}`);
|
|
5894
|
+
}
|
|
5895
|
+
}
|
|
5896
|
+
const mode = section.mode === void 0 ? "server" : String(section.mode);
|
|
5897
|
+
if (mode !== "server") {
|
|
5898
|
+
fail(`window.mode \u53EA\u80FD\u662F server\uFF08\u6536\u5230 "${mode}"\uFF09\u2014\u2014\u5BA2\u6237\u7AEF\u7A97\u53E3\u4E0D\u505A\uFF0C\u89C1\u300A\u6570\u636E\u5BF9\u8C61\u5C42\u300B\xA711`, `${path}.mode`);
|
|
5899
|
+
}
|
|
5900
|
+
const fieldKeys = Object.keys(fields);
|
|
5901
|
+
const fieldTypes = Object.fromEntries(
|
|
5902
|
+
fieldKeys.map((key) => [key, fields[key].type])
|
|
5903
|
+
);
|
|
5904
|
+
const requireField = (name, at) => {
|
|
5905
|
+
const key = String(name ?? "");
|
|
5906
|
+
if (!fieldKeys.includes(key)) {
|
|
5907
|
+
fail(`${at} \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5B57\u6BB5 "${key}"\uFF08\u672C\u5BF9\u8C61\u5B57\u5178\uFF1A${fieldKeys.join(" / ") || "\u7A7A"}\uFF09`, at);
|
|
5908
|
+
}
|
|
5909
|
+
return key;
|
|
5910
|
+
};
|
|
5911
|
+
const parseFilter = (node, at, depth) => {
|
|
5912
|
+
if (depth > MAX_FILTER_DEPTH) {
|
|
5913
|
+
fail(`${at} \u7684\u8FC7\u6EE4\u6761\u4EF6\u5D4C\u5957\u8D85\u8FC7 ${MAX_FILTER_DEPTH} \u5C42\u2014\u2014\u518D\u6DF1\u5C31\u6CA1\u4EBA\u8BFB\u5F97\u61C2\u4E86`, at);
|
|
5914
|
+
}
|
|
5915
|
+
if (!isPlainObject4(node)) fail(`${at} \u5FC5\u987B\u662F\u6620\u5C04`, at);
|
|
5916
|
+
if ("join" in node || "conditions" in node) {
|
|
5917
|
+
const branch = node;
|
|
5918
|
+
const join = String(branch.join ?? "");
|
|
5919
|
+
if (join !== "and" && join !== "or") {
|
|
5920
|
+
fail(`${at}.join \u53EA\u80FD\u662F and / or\uFF08\u6536\u5230 ${JSON.stringify(branch.join)}\uFF09`, `${at}.join`);
|
|
5921
|
+
}
|
|
5922
|
+
if (!Array.isArray(branch.conditions) || branch.conditions.length === 0) {
|
|
5923
|
+
fail(`${at}.conditions \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4`, `${at}.conditions`);
|
|
5924
|
+
}
|
|
5925
|
+
return {
|
|
5926
|
+
join,
|
|
5927
|
+
conditions: branch.conditions.map(
|
|
5928
|
+
(child, index) => parseFilter(child, `${at}.conditions[${index}]`, depth + 1)
|
|
5929
|
+
)
|
|
5930
|
+
};
|
|
5931
|
+
}
|
|
5932
|
+
const issues = validatePredicate(node, fieldKeys, at, { fieldTypes });
|
|
5933
|
+
if (issues.length > 0) fail(issues.join("\uFF1B"), at);
|
|
5934
|
+
const leaf = node;
|
|
5935
|
+
return {
|
|
5936
|
+
field: String(leaf.field),
|
|
5937
|
+
op: leaf.op,
|
|
5938
|
+
...leaf.value === void 0 ? {} : { value: leaf.value }
|
|
5939
|
+
};
|
|
5940
|
+
};
|
|
5941
|
+
const filter = section.filter === void 0 || section.filter === null ? null : parseFilter(section.filter, `${path}.filter`, 1);
|
|
5942
|
+
const sort = [];
|
|
5943
|
+
if (section.sort !== void 0) {
|
|
5944
|
+
if (!Array.isArray(section.sort)) fail(`${path}.sort \u5FC5\u987B\u662F\u6570\u7EC4`, `${path}.sort`);
|
|
5945
|
+
section.sort.forEach((entry, index) => {
|
|
5946
|
+
const at = `${path}.sort[${index}]`;
|
|
5947
|
+
if (!isPlainObject4(entry)) fail(`${at} \u5FC5\u987B\u662F { field, order }`, at);
|
|
5948
|
+
const order = String(entry.order ?? "asc");
|
|
5949
|
+
if (order !== "asc" && order !== "desc") {
|
|
5950
|
+
fail(`${at}.order \u53EA\u80FD\u662F asc / desc\uFF08\u6536\u5230 ${JSON.stringify(entry.order)}\uFF09`, `${at}.order`);
|
|
5951
|
+
}
|
|
5952
|
+
sort.push({ field: requireField(entry.field, `${at}.field`), order });
|
|
5953
|
+
});
|
|
5954
|
+
}
|
|
5955
|
+
let group = null;
|
|
5956
|
+
if (section.group !== void 0 && section.group !== null) {
|
|
5957
|
+
const at = `${path}.group`;
|
|
5958
|
+
if (!isPlainObject4(section.group)) fail(`${at} \u5FC5\u987B\u662F { by, keys? }`, at);
|
|
5959
|
+
const by = section.group.by;
|
|
5960
|
+
if (!Array.isArray(by) || by.length === 0) fail(`${at}.by \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4`, `${at}.by`);
|
|
5961
|
+
const keys = section.group.keys ?? [];
|
|
5962
|
+
if (!Array.isArray(keys)) fail(`${at}.keys \u5FC5\u987B\u662F\u6570\u7EC4`, `${at}.keys`);
|
|
5963
|
+
if (keys.length > by.length) {
|
|
5964
|
+
fail(
|
|
5965
|
+
`${at}.keys \u6709 ${keys.length} \u6BB5\uFF0C\u4F46\u53EA\u6309 ${by.length} \u4E2A\u5B57\u6BB5\u5206\u7EC4\u2014\u2014\u5C55\u5F00\u8DEF\u5F84\u4E0D\u53EF\u80FD\u6BD4\u5206\u7EC4\u5C42\u6570\u6DF1`,
|
|
5966
|
+
`${at}.keys`
|
|
5967
|
+
);
|
|
5968
|
+
}
|
|
5969
|
+
group = {
|
|
5970
|
+
by: by.map((name, index) => requireField(name, `${at}.by[${index}]`)),
|
|
5971
|
+
keys: keys.map((key) => String(key))
|
|
5972
|
+
};
|
|
5973
|
+
}
|
|
5974
|
+
const aggregate = [];
|
|
5975
|
+
if (section.aggregate !== void 0) {
|
|
5976
|
+
if (!Array.isArray(section.aggregate)) fail(`${path}.aggregate \u5FC5\u987B\u662F\u6570\u7EC4`, `${path}.aggregate`);
|
|
5977
|
+
section.aggregate.forEach((entry, index) => {
|
|
5978
|
+
const at = `${path}.aggregate[${index}]`;
|
|
5979
|
+
if (!isPlainObject4(entry)) fail(`${at} \u5FC5\u987B\u662F { field, fn }`, at);
|
|
5980
|
+
const fn = String(entry.fn ?? "");
|
|
5981
|
+
if (!SOMA_AGGREGATE_FNS.includes(fn)) {
|
|
5982
|
+
fail(`${at}.fn \u53EA\u80FD\u662F ${SOMA_AGGREGATE_FNS.join(" / ")}\uFF08\u6536\u5230 ${JSON.stringify(entry.fn)}\uFF09`, `${at}.fn`);
|
|
5983
|
+
}
|
|
5984
|
+
const field = requireField(entry.field, `${at}.field`);
|
|
5985
|
+
const type2 = fieldTypes[field] ?? "";
|
|
5986
|
+
if (fn !== "count" && !NUMERIC_TYPES.has(type2)) {
|
|
5987
|
+
fail(
|
|
5988
|
+
`${at}.fn=${fn} \u4E0D\u80FD\u7528\u5728 ${type2 || "\u672A\u58F0\u660E\u7C7B\u578B"} \u7684\u5B57\u6BB5 "${field}" \u4E0A\uFF08\u53EA\u6709 ${[...NUMERIC_TYPES].join(" / ")} \u80FD\u6C42\u548C\u6C42\u5747\uFF1B\u8981\u6570\u884C\u6570\u8BF7\u7528 count\uFF09`,
|
|
5989
|
+
`${at}.fn`
|
|
5990
|
+
);
|
|
5991
|
+
}
|
|
5992
|
+
aggregate.push({ field, fn });
|
|
5993
|
+
});
|
|
5994
|
+
}
|
|
5995
|
+
let selection = { base: "none", toggled: [] };
|
|
5996
|
+
if (section.selection !== void 0) {
|
|
5997
|
+
const at = `${path}.selection`;
|
|
5998
|
+
if (!isPlainObject4(section.selection)) fail(`${at} \u5FC5\u987B\u662F { base, toggled }`, at);
|
|
5999
|
+
const base = String(section.selection.base ?? "none");
|
|
6000
|
+
if (base !== "none" && base !== "all") {
|
|
6001
|
+
fail(`${at}.base \u53EA\u80FD\u662F none / all\uFF08\u6536\u5230 ${JSON.stringify(section.selection.base)}\uFF09`, `${at}.base`);
|
|
6002
|
+
}
|
|
6003
|
+
const toggled = section.selection.toggled ?? [];
|
|
6004
|
+
if (!Array.isArray(toggled)) fail(`${at}.toggled \u5FC5\u987B\u662F\u6570\u7EC4`, `${at}.toggled`);
|
|
6005
|
+
selection = { base, toggled: toggled.map((id) => String(id)) };
|
|
6006
|
+
}
|
|
6007
|
+
const selectAll = String(section.select_all ?? "filtered");
|
|
6008
|
+
if (!SOMA_SELECT_ALL_MODES.includes(selectAll)) {
|
|
6009
|
+
fail(
|
|
6010
|
+
`${path}.select_all \u53EA\u80FD\u662F ${SOMA_SELECT_ALL_MODES.join(" / ")}\uFF08\u6536\u5230 ${JSON.stringify(section.select_all)}\uFF09`,
|
|
6011
|
+
`${path}.select_all`
|
|
6012
|
+
);
|
|
6013
|
+
}
|
|
6014
|
+
if (selectAll === "current_page" && selection.base === "all") {
|
|
6015
|
+
fail(
|
|
6016
|
+
`${path}.select_all=current_page \u4E0E selection.base=all \u51B2\u7A81\u2014\u2014\u53EA\u9009\u5F53\u524D\u9875\u65F6\u57FA\u7EBF\u53EA\u80FD\u662F none\uFF08\u5426\u5219"\u5168\u9009"\u5230\u5E95\u6307\u54EA\u4E9B\u884C\u8BF4\u4E0D\u6E05\uFF09`,
|
|
6017
|
+
`${path}.select_all`
|
|
6018
|
+
);
|
|
6019
|
+
}
|
|
6020
|
+
const block = { ...DEFAULT_BLOCK };
|
|
6021
|
+
if (section.block !== void 0) {
|
|
6022
|
+
const at = `${path}.block`;
|
|
6023
|
+
if (!isPlainObject4(section.block)) fail(`${at} \u5FC5\u987B\u662F\u6620\u5C04`, at);
|
|
6024
|
+
const positive = (raw2, key, fallback) => {
|
|
6025
|
+
if (raw2 === void 0) return fallback;
|
|
6026
|
+
const value = Number(raw2);
|
|
6027
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
6028
|
+
fail(`${at}.${key} \u5FC5\u987B\u662F\u6B63\u6574\u6570\uFF08\u6536\u5230 ${JSON.stringify(raw2)}\uFF09`, `${at}.${key}`);
|
|
6029
|
+
}
|
|
6030
|
+
return value;
|
|
6031
|
+
};
|
|
6032
|
+
block.size = positive(section.block.size, "size", DEFAULT_BLOCK.size);
|
|
6033
|
+
block.max_blocks = positive(section.block.max_blocks, "max_blocks", DEFAULT_BLOCK.max_blocks);
|
|
6034
|
+
block.debounce_ms = section.block.debounce === void 0 ? DEFAULT_BLOCK.debounce_ms : parseDuration(String(section.block.debounce), `${at}.debounce`, (m) => fail(m, `${at}.debounce`));
|
|
6035
|
+
}
|
|
6036
|
+
const cache = { ttl_ms: null, keep_previous: false };
|
|
6037
|
+
if (section.cache !== void 0) {
|
|
6038
|
+
const at = `${path}.cache`;
|
|
6039
|
+
if (!isPlainObject4(section.cache)) fail(`${at} \u5FC5\u987B\u662F { ttl?, keep_previous? }`, at);
|
|
6040
|
+
if (section.cache.ttl !== void 0) {
|
|
6041
|
+
cache.ttl_ms = parseDuration(String(section.cache.ttl), `${at}.ttl`, (m) => fail(m, `${at}.ttl`));
|
|
6042
|
+
}
|
|
6043
|
+
cache.keep_previous = section.cache.keep_previous === true;
|
|
6044
|
+
}
|
|
6045
|
+
const revalidateMs = section.revalidate === void 0 ? null : parseDuration(String(section.revalidate), `${path}.revalidate`, (m) => fail(m, `${path}.revalidate`));
|
|
6046
|
+
return {
|
|
6047
|
+
mode: "server",
|
|
6048
|
+
block,
|
|
6049
|
+
sort,
|
|
6050
|
+
filter,
|
|
6051
|
+
group,
|
|
6052
|
+
aggregate,
|
|
6053
|
+
selection,
|
|
6054
|
+
select_all: selectAll,
|
|
6055
|
+
cache,
|
|
6056
|
+
revalidate_ms: revalidateMs,
|
|
6057
|
+
dict_hash: dictHash(fields)
|
|
6058
|
+
};
|
|
6059
|
+
}
|
|
6060
|
+
function dictHash(fields) {
|
|
6061
|
+
const canonical = Object.keys(fields).sort().map((key) => `${key}:${fields[key].type ?? ""}:${fields[key].permission ?? ""}`).join("|");
|
|
6062
|
+
let hash = 2166136261;
|
|
6063
|
+
for (let index = 0; index < canonical.length; index += 1) {
|
|
6064
|
+
hash ^= canonical.charCodeAt(index);
|
|
6065
|
+
hash = hash + (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24) >>> 0;
|
|
6066
|
+
}
|
|
6067
|
+
return `fnv1a-${hash.toString(16).padStart(8, "0")}`;
|
|
6068
|
+
}
|
|
6069
|
+
|
|
6070
|
+
// core/client/parser/data-config-parser.ts
|
|
6071
|
+
var SomaDataConfigError = class extends Error {
|
|
6072
|
+
constructor(message, path = "") {
|
|
6073
|
+
const prefix = path ? ` (\u8DEF\u5F84: ${path})` : "";
|
|
6074
|
+
super(`[SOMA DataConfigParser] ${message}${prefix}`);
|
|
6075
|
+
this.name = "SomaDataConfigError";
|
|
6076
|
+
this.path = path;
|
|
6077
|
+
}
|
|
6078
|
+
};
|
|
6079
|
+
var VALID_FIELD_TYPES = new Set(SOMA_DATA_FIELD_TYPES);
|
|
4296
6080
|
var VALID_PERMISSIONS = /* @__PURE__ */ new Set(["r", "w"]);
|
|
4297
6081
|
var RULE_VALUE_TYPES = {
|
|
4298
6082
|
required: "boolean",
|
|
@@ -4482,7 +6266,7 @@ function parseField(raw, path) {
|
|
|
4482
6266
|
`${path}.type`
|
|
4483
6267
|
);
|
|
4484
6268
|
}
|
|
4485
|
-
field.type = value;
|
|
6269
|
+
field.type = SOMA_DATA_FIELD_TYPE_ALIASES[value] ?? value;
|
|
4486
6270
|
} else if (key === "permission") {
|
|
4487
6271
|
if (typeof value !== "string" || !VALID_PERMISSIONS.has(value)) {
|
|
4488
6272
|
throw new SomaDataConfigError(
|
|
@@ -4498,15 +6282,202 @@ function parseField(raw, path) {
|
|
|
4498
6282
|
field.rules = value.map((rule, index) => parseRule(rule, `${path}.rules[${index}]`));
|
|
4499
6283
|
} else if (key === "options") {
|
|
4500
6284
|
field.options = parseOptions(value, `${path}.options`);
|
|
6285
|
+
} else if (key === "calc") {
|
|
6286
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
6287
|
+
throw new SomaDataConfigError("calc \u5FC5\u987B\u662F\u975E\u7A7A\u8868\u8FBE\u5F0F\u5B57\u7B26\u4E32", `${path}.calc`);
|
|
6288
|
+
}
|
|
6289
|
+
field.calc = value;
|
|
4501
6290
|
} else {
|
|
4502
6291
|
throw new SomaDataConfigError(
|
|
4503
|
-
`\u672A\u77E5\u7684\u5B57\u5178\u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: name / type / permission / rules / options\uFF09`,
|
|
6292
|
+
`\u672A\u77E5\u7684\u5B57\u5178\u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: name / type / permission / rules / options / calc\uFF09`,
|
|
4504
6293
|
`${path}.${key}`
|
|
4505
6294
|
);
|
|
4506
6295
|
}
|
|
4507
6296
|
}
|
|
4508
6297
|
return field;
|
|
4509
6298
|
}
|
|
6299
|
+
var CALC_WRITABLE_TYPES = /* @__PURE__ */ new Set([
|
|
6300
|
+
"int",
|
|
6301
|
+
"float",
|
|
6302
|
+
"money",
|
|
6303
|
+
"percent",
|
|
6304
|
+
"progress",
|
|
6305
|
+
"text",
|
|
6306
|
+
"url",
|
|
6307
|
+
"enum",
|
|
6308
|
+
"date",
|
|
6309
|
+
"datetime"
|
|
6310
|
+
]);
|
|
6311
|
+
function validateDerivedFields(fields, path) {
|
|
6312
|
+
const derived = Object.keys(fields).filter((key) => fields[key].calc !== void 0);
|
|
6313
|
+
if (derived.length === 0) return;
|
|
6314
|
+
const fieldTypes = Object.fromEntries(
|
|
6315
|
+
Object.keys(fields).map((key) => [key, fields[key].type])
|
|
6316
|
+
);
|
|
6317
|
+
const refsOf = {};
|
|
6318
|
+
for (const key of derived) {
|
|
6319
|
+
const at = `${path}.${key}.calc`;
|
|
6320
|
+
const source = fields[key].calc;
|
|
6321
|
+
const declared = fields[key].type ?? "text";
|
|
6322
|
+
if (!CALC_WRITABLE_TYPES.has(declared)) {
|
|
6323
|
+
throw new SomaDataConfigError(
|
|
6324
|
+
`calc \u7B97\u4E0D\u51FA ${declared} \u7C7B\u578B\u7684\u503C\uFF08\u5B57\u6BB5 "${key}"\uFF09`,
|
|
6325
|
+
at
|
|
6326
|
+
);
|
|
6327
|
+
}
|
|
6328
|
+
try {
|
|
6329
|
+
const node = parseCalc(source);
|
|
6330
|
+
const ctx = { fieldTypes, source };
|
|
6331
|
+
assertCalcResultType(inferCalcType(node, ctx), declared, ctx, node);
|
|
6332
|
+
const refs = collectCalcRefs(node);
|
|
6333
|
+
for (const ref of refs) {
|
|
6334
|
+
if (!(ref in fields)) {
|
|
6335
|
+
throw new SomaDataConfigError(
|
|
6336
|
+
`calc \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5B57\u6BB5 "${ref}"\uFF08\u672C\u5BF9\u8C61\u5B57\u5178\uFF1A${Object.keys(fields).join(" / ")}\uFF09`,
|
|
6337
|
+
at
|
|
6338
|
+
);
|
|
6339
|
+
}
|
|
6340
|
+
if (ref === key) {
|
|
6341
|
+
throw new SomaDataConfigError(`calc \u5F15\u7528\u4E86\u5B83\u81EA\u5DF1\uFF08\u5B57\u6BB5 "${key}"\uFF09`, at);
|
|
6342
|
+
}
|
|
6343
|
+
}
|
|
6344
|
+
refsOf[key] = refs;
|
|
6345
|
+
} catch (error) {
|
|
6346
|
+
if (error instanceof SomaCalcSyntaxError || error instanceof SomaCalcTypeError) {
|
|
6347
|
+
throw new SomaDataConfigError(error.message, at);
|
|
6348
|
+
}
|
|
6349
|
+
throw error;
|
|
6350
|
+
}
|
|
6351
|
+
fields[key].permission = "r";
|
|
6352
|
+
}
|
|
6353
|
+
const state = {};
|
|
6354
|
+
const stack = [];
|
|
6355
|
+
const walk = (key) => {
|
|
6356
|
+
if (state[key] === "done") return;
|
|
6357
|
+
if (state[key] === "visiting") {
|
|
6358
|
+
const from = stack.indexOf(key);
|
|
6359
|
+
throw new SomaDataConfigError(
|
|
6360
|
+
`\u6D3E\u751F\u5217\u6210\u73AF\uFF1A${[...stack.slice(from), key].join(" \u2192 ")}`,
|
|
6361
|
+
`${path}.${key}.calc`
|
|
6362
|
+
);
|
|
6363
|
+
}
|
|
6364
|
+
state[key] = "visiting";
|
|
6365
|
+
stack.push(key);
|
|
6366
|
+
for (const ref of refsOf[key] ?? []) {
|
|
6367
|
+
if (refsOf[ref] !== void 0) walk(ref);
|
|
6368
|
+
}
|
|
6369
|
+
stack.pop();
|
|
6370
|
+
state[key] = "done";
|
|
6371
|
+
};
|
|
6372
|
+
for (const key of derived) walk(key);
|
|
6373
|
+
}
|
|
6374
|
+
var WRITE_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
6375
|
+
function parseWrite(raw, fields, path, objectNames) {
|
|
6376
|
+
assertPlainObject2(raw, "write", path);
|
|
6377
|
+
const write = {};
|
|
6378
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
6379
|
+
if (key === "create" || key === "update") {
|
|
6380
|
+
write[key] = parseWriteEndpoint(value, `${path}.${key}`);
|
|
6381
|
+
} else if (key === "version") {
|
|
6382
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
6383
|
+
throw new SomaDataConfigError("version \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u540D", `${path}.version`);
|
|
6384
|
+
}
|
|
6385
|
+
if (!(value in fields)) {
|
|
6386
|
+
throw new SomaDataConfigError(
|
|
6387
|
+
`version \u6307\u5411\u5B57\u6BB5 "${value}"\uFF0C\u4F46\u5B57\u5178\u91CC\u6CA1\u6709\u5B83\uFF08\u4E50\u89C2\u9501\u4F4D\u5FC5\u987B\u5728\u5B57\u5178\u91CC\u58F0\u660E\uFF0C\u5426\u5219\u5B83\u4E0D\u4F1A\u968F\u8BF7\u6C42\u4F53\u4E0A\u884C\uFF09`,
|
|
6388
|
+
`${path}.version`
|
|
6389
|
+
);
|
|
6390
|
+
}
|
|
6391
|
+
write.version = value;
|
|
6392
|
+
} else if (key === "map") {
|
|
6393
|
+
assertPlainObject2(value, "map", `${path}.map`);
|
|
6394
|
+
const map2 = {};
|
|
6395
|
+
for (const [formKey, bodyKey] of Object.entries(value)) {
|
|
6396
|
+
if (!(formKey in fields)) {
|
|
6397
|
+
throw new SomaDataConfigError(
|
|
6398
|
+
`map \u7684\u952E "${formKey}" \u4E0D\u5728\u5B57\u5178\u91CC\uFF08\u53EA\u80FD\u7ED9\u58F0\u660E\u8FC7\u7684\u5B57\u6BB5\u6539\u540D\uFF09`,
|
|
6399
|
+
`${path}.map.${formKey}`
|
|
6400
|
+
);
|
|
6401
|
+
}
|
|
6402
|
+
if (fields[formKey].permission === "r") {
|
|
6403
|
+
throw new SomaDataConfigError(
|
|
6404
|
+
`map \u7684\u952E "${formKey}" \u662F\u53EA\u8BFB\u5B57\u6BB5\uFF08permission: r\uFF09\u2014\u2014\u53EA\u8BFB\u5B57\u6BB5\u4E0D\u8FDB\u8BF7\u6C42\u4F53\uFF0C\u6539\u540D\u6CA1\u6709\u610F\u4E49`,
|
|
6405
|
+
`${path}.map.${formKey}`
|
|
6406
|
+
);
|
|
6407
|
+
}
|
|
6408
|
+
if (typeof bodyKey !== "string" || !bodyKey.trim()) {
|
|
6409
|
+
throw new SomaDataConfigError(`map \u7684\u503C\u5FC5\u987B\u662F\u975E\u7A7A\u7684\u8BF7\u6C42\u4F53\u952E\u540D`, `${path}.map.${formKey}`);
|
|
6410
|
+
}
|
|
6411
|
+
map2[formKey] = bodyKey;
|
|
6412
|
+
}
|
|
6413
|
+
write.map = map2;
|
|
6414
|
+
} else if (key === "only") {
|
|
6415
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
6416
|
+
throw new SomaDataConfigError("only \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u540D\u6570\u7EC4", `${path}.only`);
|
|
6417
|
+
}
|
|
6418
|
+
for (const fieldKey of value) {
|
|
6419
|
+
if (typeof fieldKey !== "string" || !(fieldKey in fields)) {
|
|
6420
|
+
throw new SomaDataConfigError(
|
|
6421
|
+
`only \u91CC\u7684 "${String(fieldKey)}" \u4E0D\u5728\u5B57\u6BB5\u5B57\u5178\u91CC\uFF08\u672C\u5BF9\u8C61\u5B57\u5178\uFF1A${Object.keys(fields).join(" / ") || "\u7A7A"}\uFF09`,
|
|
6422
|
+
`${path}.only`
|
|
6423
|
+
);
|
|
6424
|
+
}
|
|
6425
|
+
}
|
|
6426
|
+
write.only = value.map(String);
|
|
6427
|
+
} else if (key === "reload") {
|
|
6428
|
+
if (value === "self" || value === "all") {
|
|
6429
|
+
write.reload = value;
|
|
6430
|
+
} else if (Array.isArray(value)) {
|
|
6431
|
+
for (const objectName of value) {
|
|
6432
|
+
if (typeof objectName !== "string" || !objectNames.has(objectName)) {
|
|
6433
|
+
throw new SomaDataConfigError(
|
|
6434
|
+
`reload \u6307\u5411\u6570\u636E\u5BF9\u8C61 "${String(objectName)}"\uFF0C\u4F46\u672C\u9875\u6CA1\u6709\u58F0\u660E\u5B83`,
|
|
6435
|
+
`${path}.reload`
|
|
6436
|
+
);
|
|
6437
|
+
}
|
|
6438
|
+
}
|
|
6439
|
+
write.reload = [...value];
|
|
6440
|
+
} else {
|
|
6441
|
+
throw new SomaDataConfigError(
|
|
6442
|
+
`reload \u5FC5\u987B\u662F 'self' / 'all' / \u6570\u636E\u5BF9\u8C61\u540D\u6570\u7EC4`,
|
|
6443
|
+
`${path}.reload`
|
|
6444
|
+
);
|
|
6445
|
+
}
|
|
6446
|
+
} else {
|
|
6447
|
+
throw new SomaDataConfigError(
|
|
6448
|
+
`\u672A\u77E5\u7684 write \u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: create / update / version / map / only / reload\uFF09`,
|
|
6449
|
+
`${path}.${key}`
|
|
6450
|
+
);
|
|
6451
|
+
}
|
|
6452
|
+
}
|
|
6453
|
+
if (!write.create && !write.update) {
|
|
6454
|
+
throw new SomaDataConfigError(
|
|
6455
|
+
"write \u81F3\u5C11\u8981\u58F0\u660E create \u6216 update \u4E4B\u4E00\uFF08\u4E24\u4E2A\u90FD\u6CA1\u6709\u7684\u5199\u901A\u9053\u4E0D\u5199\u4EFB\u4F55\u4E1C\u897F\uFF09",
|
|
6456
|
+
path
|
|
6457
|
+
);
|
|
6458
|
+
}
|
|
6459
|
+
return write;
|
|
6460
|
+
}
|
|
6461
|
+
function parseWriteEndpoint(raw, path) {
|
|
6462
|
+
assertPlainObject2(raw, "\u5199\u7AEF\u70B9", path);
|
|
6463
|
+
const api = raw.api;
|
|
6464
|
+
const method = raw.method ?? "POST";
|
|
6465
|
+
if (typeof api !== "string" || !api.trim()) {
|
|
6466
|
+
throw new SomaDataConfigError("\u5199\u7AEF\u70B9\u7F3A\u5C11 api\uFF08\u540E\u7AEF\u63A5\u53E3\u662F\u552F\u4E00\u6570\u636E\u8FB9\u754C\uFF09", `${path}.api`);
|
|
6467
|
+
}
|
|
6468
|
+
if (typeof method !== "string" || !WRITE_METHODS.has(method)) {
|
|
6469
|
+
throw new SomaDataConfigError(
|
|
6470
|
+
`method "${String(method)}" \u4E0D\u5728\u767D\u540D\u5355\u5185\uFF08POST / PUT / PATCH\uFF09`,
|
|
6471
|
+
`${path}.method`
|
|
6472
|
+
);
|
|
6473
|
+
}
|
|
6474
|
+
for (const key of Object.keys(raw)) {
|
|
6475
|
+
if (key !== "api" && key !== "method") {
|
|
6476
|
+
throw new SomaDataConfigError(`\u672A\u77E5\u7684\u5199\u7AEF\u70B9\u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: api / method\uFF09`, `${path}.${key}`);
|
|
6477
|
+
}
|
|
6478
|
+
}
|
|
6479
|
+
return { api, method };
|
|
6480
|
+
}
|
|
4510
6481
|
function parseObject(name, raw, path, objectNames) {
|
|
4511
6482
|
if (!IDENTIFIER_PATTERN.test(name)) {
|
|
4512
6483
|
throw new SomaDataConfigError(`\u5BF9\u8C61\u540D "${name}" \u4E0D\u5408\u6CD5\uFF08\u5B57\u6BCD/\u4E0B\u5212\u7EBF\u5F00\u5934\u7684\u6807\u8BC6\u7B26\uFF09`, path);
|
|
@@ -4514,6 +6485,10 @@ function parseObject(name, raw, path, objectNames) {
|
|
|
4514
6485
|
assertPlainObject2(raw, "\u6570\u636E\u5BF9\u8C61\u58F0\u660E", path);
|
|
4515
6486
|
const deps = /* @__PURE__ */ new Set();
|
|
4516
6487
|
const config = { name, from: [], deps: [] };
|
|
6488
|
+
let writeRaw;
|
|
6489
|
+
let predicatesRaw;
|
|
6490
|
+
let reactionsRaw;
|
|
6491
|
+
let windowRaw;
|
|
4517
6492
|
for (const [key, value] of Object.entries(raw)) {
|
|
4518
6493
|
if (key === "from") {
|
|
4519
6494
|
if (!Array.isArray(value) || value.length === 0) {
|
|
@@ -4526,20 +6501,73 @@ function parseObject(name, raw, path, objectNames) {
|
|
|
4526
6501
|
config.transform = parseTransform(value, `${path}.transform`);
|
|
4527
6502
|
} else if (key === "fields") {
|
|
4528
6503
|
assertPlainObject2(value, "fields", `${path}.fields`);
|
|
4529
|
-
const
|
|
6504
|
+
const fields2 = {};
|
|
4530
6505
|
for (const [fieldName, fieldRaw] of Object.entries(value)) {
|
|
4531
|
-
|
|
6506
|
+
fields2[fieldName] = parseField(fieldRaw, `${path}.fields.${fieldName}`);
|
|
4532
6507
|
}
|
|
4533
|
-
|
|
6508
|
+
validateDerivedFields(fields2, `${path}.fields`);
|
|
6509
|
+
config.fields = fields2;
|
|
4534
6510
|
} else if (key === "mock") {
|
|
4535
6511
|
config.mock = value;
|
|
6512
|
+
} else if (key === "write") {
|
|
6513
|
+
writeRaw = value;
|
|
6514
|
+
} else if (key === "predicates") {
|
|
6515
|
+
predicatesRaw = value;
|
|
6516
|
+
} else if (key === "reactions") {
|
|
6517
|
+
reactionsRaw = value;
|
|
6518
|
+
} else if (key === "window") {
|
|
6519
|
+
windowRaw = value;
|
|
4536
6520
|
} else {
|
|
4537
6521
|
throw new SomaDataConfigError(
|
|
4538
|
-
`\u672A\u77E5\u7684\u58F0\u660E\u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: from / transform / fields / mock\uFF09`,
|
|
6522
|
+
`\u672A\u77E5\u7684\u58F0\u660E\u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: from / transform / fields / mock / write / predicates / reactions / window\uFF09`,
|
|
4539
6523
|
`${path}.${key}`
|
|
4540
6524
|
);
|
|
4541
6525
|
}
|
|
4542
6526
|
}
|
|
6527
|
+
if (writeRaw !== void 0) {
|
|
6528
|
+
config.write = parseWrite(writeRaw, config.fields ?? {}, `${path}.write`, objectNames);
|
|
6529
|
+
}
|
|
6530
|
+
const fields = config.fields ?? {};
|
|
6531
|
+
const fieldKeys = Object.keys(fields);
|
|
6532
|
+
const fieldTypes = Object.fromEntries(
|
|
6533
|
+
fieldKeys.map((key) => [key, fields[key].type])
|
|
6534
|
+
);
|
|
6535
|
+
if (predicatesRaw !== void 0) {
|
|
6536
|
+
const issues = validateNamedPredicates(predicatesRaw, fieldKeys, fieldTypes);
|
|
6537
|
+
if (issues.length > 0) {
|
|
6538
|
+
throw new SomaDataConfigError(issues.join("\uFF1B"), `${path}.predicates`);
|
|
6539
|
+
}
|
|
6540
|
+
config.predicates = predicatesRaw;
|
|
6541
|
+
}
|
|
6542
|
+
if (reactionsRaw !== void 0) {
|
|
6543
|
+
config.reactions = parseReactions(
|
|
6544
|
+
{
|
|
6545
|
+
raw: reactionsRaw,
|
|
6546
|
+
fields,
|
|
6547
|
+
named: config.predicates ?? {},
|
|
6548
|
+
// 回溯表要知道每个字段来自哪个接口。字段与接口的对应在声明里是隐式的
|
|
6549
|
+
// (一个 from 拉回来一整个对象),所以退而记「本对象的第一个接口」——
|
|
6550
|
+
// 比不给强:排障时至少知道该去看哪个接口。
|
|
6551
|
+
sourceApiOf: Object.fromEntries(fieldKeys.map((key) => [key, config.from[0]?.api])),
|
|
6552
|
+
path: `${path}.reactions`
|
|
6553
|
+
},
|
|
6554
|
+
{
|
|
6555
|
+
fail(message, at) {
|
|
6556
|
+
throw new SomaDataConfigError(message, at);
|
|
6557
|
+
}
|
|
6558
|
+
}
|
|
6559
|
+
);
|
|
6560
|
+
}
|
|
6561
|
+
if (windowRaw !== void 0) {
|
|
6562
|
+
config.window = parseWindow(
|
|
6563
|
+
{ raw: windowRaw, fields, path: `${path}.window` },
|
|
6564
|
+
{
|
|
6565
|
+
fail(message, at) {
|
|
6566
|
+
throw new SomaDataConfigError(message, at);
|
|
6567
|
+
}
|
|
6568
|
+
}
|
|
6569
|
+
);
|
|
6570
|
+
}
|
|
4543
6571
|
if (config.from.length === 0 && config.mock === void 0) {
|
|
4544
6572
|
throw new SomaDataConfigError(`\u7F3A\u5C11 from \u53D6\u6570\u6765\u6E90\uFF08\u4EC5\u58F0\u660E mock \u6837\u672C\u7684\u9884\u89C8\u5BF9\u8C61\u53EF\u7701\u7565\uFF09`, `${path}.from`);
|
|
4545
6573
|
}
|
|
@@ -4564,7 +6592,7 @@ function parseDataConfig(raw) {
|
|
|
4564
6592
|
return { objects };
|
|
4565
6593
|
}
|
|
4566
6594
|
|
|
4567
|
-
// core/
|
|
6595
|
+
// core/shared/block-errors.ts
|
|
4568
6596
|
var SomaBlockParseError = class extends Error {
|
|
4569
6597
|
constructor(message, blockId, line) {
|
|
4570
6598
|
const where = blockId ? `\uFF08\u5757: ${blockId}${line ? `\uFF0C\u7B2C ${line} \u884C` : ""}\uFF09` : "";
|
|
@@ -4574,6 +6602,8 @@ var SomaBlockParseError = class extends Error {
|
|
|
4574
6602
|
this.name = "SomaBlockParseError";
|
|
4575
6603
|
}
|
|
4576
6604
|
};
|
|
6605
|
+
|
|
6606
|
+
// core/build/blocks/block-container.ts
|
|
4577
6607
|
function stripSwitch(uiYamlRaw) {
|
|
4578
6608
|
const lines = uiYamlRaw.split("\n");
|
|
4579
6609
|
let openIndex = -1;
|