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