openyida 2026.11.4 → 2026.11.5-beta.0
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 +13 -1
- package/lib/agent/mutation-receipt.js +1 -1
- package/lib/app/create-form.js +48 -39
- package/lib/app/form-data-contract.js +121 -19
- package/lib/app/form-data-response-guard.js +122 -19
- package/lib/app/publish.js +32 -6
- package/lib/app/services/form-compiler.js +1 -1
- package/lib/app/subform-readback.js +60 -0
- package/lib/core/command-manifest.js +30 -7
- package/lib/core/data-seed.js +254 -0
- package/lib/core/locales/en.js +9 -0
- package/lib/core/locales/zh.js +9 -0
- package/lib/core/mock-records.js +202 -0
- package/lib/core/query-data.js +69 -35
- package/lib/core/utils.js +12 -5
- package/lib/samples/openyida-scaffold/canvas-data-source.jsx +120 -0
- package/package.json +1 -1
- package/yida-skills/SKILL.md +1 -1
- package/yida-skills/skills/yida-app/references/common-issues.md +3 -3
- package/yida-skills/skills/yida-app/workflow/fast-build.md +1 -0
- package/yida-skills/skills/yida-app/workflow/step-5-seed-records.md +4 -4
- package/yida-skills/skills/yida-canvas-data-binding/SKILL.md +29 -0
- package/yida-skills/skills/yida-create-form-page/SKILL.md +4 -3
- package/yida-skills/skills/yida-create-form-page/references/association-form-field.md +3 -0
- package/yida-skills/skills/yida-data-management/SKILL.md +109 -111
- package/yida-skills/skills/yida-data-management/references/data-format-guide.md +46 -7
package/README.md
CHANGED
|
@@ -277,11 +277,23 @@ openyida data query form APP_XXX FORM_XXX --page 1 --size 20
|
|
|
277
277
|
openyida data query form APP_XXX FORM_XXX --dynamic-order '{"dateField_xxx":"-"}'
|
|
278
278
|
openyida data query process APP_XXX FORM_XXX --current-approver USER_ID --count
|
|
279
279
|
openyida data create form APP_XXX FORM_XXX --expect-form-name 客户 --expect-form-type receipt --data-file .cache/openyida/data-import/record.json
|
|
280
|
+
openyida data seed form APP_XXX FORM_XXX --expect-form-name 客户 --records-file .cache/openyida/data-import/customers.json --timezone +08:00 --json
|
|
281
|
+
openyida data mock form APP_XXX FORM_XXX --expect-form-name 客户 --records-file .cache/openyida/customers/data-import/records.json --json
|
|
280
282
|
openyida get-permission APP_XXX FORM_XXX
|
|
281
283
|
```
|
|
282
284
|
|
|
283
285
|
`--current-approver` takes an exact userId, not a display name. It scans running instances and their current TODO records, counts each matching instance once, and respects the current login's server-authorized data scope. Omit `--count` to include matching instance data. An incomplete scan or permission failure is reported as an error; the result does not claim application-wide visibility.
|
|
284
286
|
|
|
287
|
+
`data seed form` accepts one JSON array of 1–30 business records using real field IDs (or configured aliases with `--resolve-aliases`). It checks the whole batch against the live schema, then creates and reads back each record, returning `formInstIds`. Use `--check` to preview converted records without writing. `DateField` and date-range endpoints accept millisecond numbers, `YYYY-MM-DD`, or ISO date-times; date-times without an offset use `--timezone` (a fixed UTC offset, default `+08:00`). Subform dates are converted recursively. Invalid dates, reversed ranges and unknown fields/options fail before any write. Business values and real member/department/file/association IDs come from the caller; this command does not invent them or start workflows.
|
|
288
|
+
|
|
289
|
+
Seed supports the 18 writable business components created by default with `create-form`, including associations, subforms, countries, domestic addresses, attachments and images. Serial numbers are server-generated. Addresses support the default domestic `ADDRESS` mode; location/international modes and unknown components follow the CLI's actual diagnostics. Unsupported fields proven optional with no validation are omitted and listed in `skippedFields`, with `requestedFieldsVerified=false`; all-omitted input returns `skipped=true` without creating empty records. Server defaults may still apply. Required or uncertain unsupported fields and invalid supported values fail before writes. Recover pending/unknown writes from the receipt. See [support and recovery](yida-skills/skills/yida-data-management/SKILL.md#组件支持与未适配配置).
|
|
290
|
+
|
|
291
|
+
The input file gets a sibling `.seed-receipt.json`. Rerunning the unchanged command reuses verified records and reads back known pending IDs before continuing. An uncertain write without a trusted ID stops for inspection. Keep the receipt: changing the input, target, identity, schema or omission policy rejects reuse instead of silently creating duplicates. A `.lock` prevents concurrent use of the same receipt; after a process crash, confirm it has stopped and inspect its pending writes before removing the stale lock. Field verification covers submitted values; server-side permissions and business rules still apply.
|
|
292
|
+
|
|
293
|
+
Keep the complete JSON result. After `success=true` and `readbackVerified=true`, match each verified `items[].formInstId` to the input by its zero-based `recordIndex`; `formInstIds` also preserves input order. Create referenced records first, then use those IDs in dependent association values. Avoid `tail/head/grep` on the JSON or list queries whose only purpose is rediscovering returned IDs. Keep the required business spot-check, using `data query form APP_XXX FORM_XXX --inst-id <verified-id> --json`. If output is truncated, read the current command's `receiptFile`; uncertain or cross-session recovery uses the unchanged seed command. Check-only output, pending entries and candidate IDs are not verified association targets. See the [receipt workflow](yida-skills/skills/yida-data-management/SKILL.md#直接消费回执与关联-id).
|
|
294
|
+
|
|
295
|
+
`data mock form` is an explicit beta command for environments with the `/query/aiTool/mockRecords.json` endpoint deployed. It submits 1–3 records for one ordinary form in a single write request, using `[{"clientRecordId":"seed-1","data":{"textField_name":"Customer A"}}]`. The default app-building flow continues to use `data seed form` with its date conversion, readback and resumable receipts. Mock request IDs are for tracing only; every invocation creates a new request, with no automatic retry or fallback to single-record writes. Inspect `COMPLETED/UNKNOWN/REJECTED`, per-row states and counts; `COMPLETED` does not imply every row succeeded. Verify each created instance ID and visible fields separately (`readbackVerified=false`), and inspect existing data before any further write after an uncertain result.
|
|
296
|
+
|
|
285
297
|
Append and forward permissions are configured in the process definition through `nodes[].actions.normalActions/appendActions`. Both `create-process` and `configure-process` compile these settings into matching designer and runtime properties. See [approval action configuration](yida-skills/skills/yida-flow-node-config/references/actions.md) for the JSON example, defaults, and verification limits.
|
|
286
298
|
|
|
287
299
|
`configure-process` 的流程 JSON 中,审批人可配置为发起人、指定成员、指定角色、部门主管或直属主管,例如:
|
|
@@ -549,7 +561,7 @@ When preparing a PR that needs a personal Fork, or when you ask how to support t
|
|
|
549
561
|
|
|
550
562
|
| Command | Description |
|
|
551
563
|
|---------|-------------|
|
|
552
|
-
| `openyida data <query\|get\|create\|update\|transfer> <resource> ... \| delete form <appType> <formUuid> --inst-id <id> --expect-form-name <name> --expect-form-type receipt --confirm [--json]` | Unified data management (form/process/task/subform) |
|
|
564
|
+
| `openyida data <query\|get\|create\|update\|transfer\|seed\|mock> <resource> ... \| delete form <appType> <formUuid> --inst-id <id> --expect-form-name <name> --expect-form-type receipt --confirm [--json]` | Unified data management (form/process/task/subform) |
|
|
553
565
|
| `openyida task-center <todo\|created\|done\|cc\|proxy\|capabilities\|link\|scaffold\|options\|inspect\|count> [--spec <file.json> --output <file.canvas.jsx>] [options]` | Global task center (todo/processed/cc etc.) |
|
|
554
566
|
| `openyida basic-info <overview\|commodity\|grant\|capacity\|quota\|abs-path\|dataflow\|i18n\|domain>` | Query organization basic info, capacity, quotas, and domain settings |
|
|
555
567
|
| `openyida read-dingtalk-doc <docUrl> [--output <file>] [--json]` | Fetch Markdown content from a DingTalk document |
|
|
@@ -49,7 +49,7 @@ function beginManagedMutationCapture({ command, args, env = process.env, console
|
|
|
49
49
|
return {
|
|
50
50
|
commit() {
|
|
51
51
|
restore();
|
|
52
|
-
if (explicitFailure || !latest) {return null;}
|
|
52
|
+
if (explicitFailure || !latest || latest.mutationPerformed === false) {return null;}
|
|
53
53
|
const isReport = command === 'create-report' || command === 'append-chart';
|
|
54
54
|
const formUuid = resourceId(latest?.formUuid, latest?.pageId,
|
|
55
55
|
isReport ? latest?.reportId : undefined, classification.formUuid);
|
package/lib/app/create-form.js
CHANGED
|
@@ -1125,7 +1125,7 @@ function buildFieldComponent(field) {
|
|
|
1125
1125
|
|
|
1126
1126
|
// 关联表单核心配置
|
|
1127
1127
|
props.associationForm = {
|
|
1128
|
-
formType: 'receipt',
|
|
1128
|
+
formType: assocConfig.formType || 'receipt',
|
|
1129
1129
|
formUuid: assocConfig.formUuid || '',
|
|
1130
1130
|
appType: assocConfig.appType || '',
|
|
1131
1131
|
appName: assocConfig.appName || '',
|
|
@@ -4317,27 +4317,25 @@ function applySmartValidations(schema, rawRules) {
|
|
|
4317
4317
|
};
|
|
4318
4318
|
}
|
|
4319
4319
|
|
|
4320
|
-
function collectSmartValidationRulesFromFields(fields,
|
|
4321
|
-
const
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
});
|
|
4340
|
-
}
|
|
4320
|
+
function collectSmartValidationRulesFromFields(fields, schema) {
|
|
4321
|
+
const root = schema.pages[0].componentsTree?.[0];
|
|
4322
|
+
const container = root ? findFormContainer(root) : null;
|
|
4323
|
+
const evidence = collectResumeFieldEvidence(container?.children);
|
|
4324
|
+
const rules = [];
|
|
4325
|
+
collectResumeDesiredFields(fields, { verifyNestedFields: true }).forEach(function ({ field, tablePath }) {
|
|
4326
|
+
const identity = desiredResumeFieldIdentity(field);
|
|
4327
|
+
const key = JSON.stringify([...tablePath, identity.label]);
|
|
4328
|
+
const matches = evidence.filter(item => JSON.stringify([...item.tablePath, item.label]) === key);
|
|
4329
|
+
// Inline rules belong to this definition's field, even when another table
|
|
4330
|
+
// uses the same label. Keep ambiguous definitions on the existing error path.
|
|
4331
|
+
const reference = matches.length === 1 && matches[0].componentName === identity.componentName
|
|
4332
|
+
? matches[0].fieldId : field.label;
|
|
4333
|
+
collectInputValidationRules(field, { includeAdvanced: true }).forEach(function (rule) {
|
|
4334
|
+
if (rule.type === 'required' && !field.required && !field.validation && !field.validations) {
|
|
4335
|
+
return;
|
|
4336
|
+
}
|
|
4337
|
+
rules.push(Object.assign({ field: reference }, rule));
|
|
4338
|
+
});
|
|
4341
4339
|
});
|
|
4342
4340
|
return rules;
|
|
4343
4341
|
}
|
|
@@ -5036,7 +5034,7 @@ async function mainCreate(parsedArgs, authRef) {
|
|
|
5036
5034
|
|
|
5037
5035
|
postCreateStage = 'buildFormSchema';
|
|
5038
5036
|
const schema = buildFormSchema(formTitle, fields, formUuid, corpId, appType, layout, theme, labelAlign);
|
|
5039
|
-
const createValidationRules = collectSmartValidationRulesFromFields(fields).concat(validations || []);
|
|
5037
|
+
const createValidationRules = collectSmartValidationRulesFromFields(fields, schema).concat(validations || []);
|
|
5040
5038
|
if (createValidationRules.length > 0) {
|
|
5041
5039
|
const appliedValidations = applySmartValidations(schema, createValidationRules);
|
|
5042
5040
|
info('已为创建表单写入 ' + appliedValidations.appliedRules.length + ' 条字段校验');
|
|
@@ -5154,7 +5152,7 @@ async function createFormForLegacyProcessQuiet(context, input) {
|
|
|
5154
5152
|
const serverRevision = extractSchemaServerRevision(shellSchemaResult);
|
|
5155
5153
|
const corpId = resolveCorpId(authRef.authData || authRef);
|
|
5156
5154
|
const schema = buildFormSchema(formTitle, fields, formUuid, corpId, appType, layout, theme, labelAlign);
|
|
5157
|
-
const createValidationRules = collectSmartValidationRulesFromFields(fields).concat(validations || []);
|
|
5155
|
+
const createValidationRules = collectSmartValidationRulesFromFields(fields, schema).concat(validations || []);
|
|
5158
5156
|
if (createValidationRules.length > 0) {
|
|
5159
5157
|
applySmartValidations(schema, createValidationRules);
|
|
5160
5158
|
}
|
|
@@ -5984,7 +5982,7 @@ async function mainValidation(parsedArgs, authRef) {
|
|
|
5984
5982
|
|
|
5985
5983
|
// ── update 模式主流程 ─────────────────────────────────
|
|
5986
5984
|
|
|
5987
|
-
function collectResumeFieldEvidence(fields, output) {
|
|
5985
|
+
function collectResumeFieldEvidence(fields, output, tablePath = []) {
|
|
5988
5986
|
const evidence = output || [];
|
|
5989
5987
|
(fields || []).forEach(function (field) {
|
|
5990
5988
|
if (!field || typeof field !== 'object') {
|
|
@@ -5996,10 +5994,12 @@ function collectResumeFieldEvidence(fields, output) {
|
|
|
5996
5994
|
label: labelText,
|
|
5997
5995
|
componentName: field.componentName,
|
|
5998
5996
|
fieldId: field.props && field.props.fieldId ? field.props.fieldId : null,
|
|
5997
|
+
tablePath,
|
|
5999
5998
|
});
|
|
6000
5999
|
}
|
|
6001
6000
|
if (Array.isArray(field.children)) {
|
|
6002
|
-
collectResumeFieldEvidence(field.children.flat(), evidence
|
|
6001
|
+
collectResumeFieldEvidence(field.children.flat(), evidence,
|
|
6002
|
+
field.componentName === 'TableField' ? tablePath.concat(labelText) : tablePath);
|
|
6003
6003
|
}
|
|
6004
6004
|
});
|
|
6005
6005
|
return evidence;
|
|
@@ -6020,9 +6020,9 @@ function collectResumeDesiredFields(fields, options) {
|
|
|
6020
6020
|
const output = [];
|
|
6021
6021
|
const verifyNestedFields = Boolean(options && options.verifyNestedFields);
|
|
6022
6022
|
|
|
6023
|
-
function visit(value) {
|
|
6023
|
+
function visit(value, tablePath) {
|
|
6024
6024
|
if (Array.isArray(value)) {
|
|
6025
|
-
value.forEach(visit);
|
|
6025
|
+
value.forEach(field => visit(field, tablePath));
|
|
6026
6026
|
return;
|
|
6027
6027
|
}
|
|
6028
6028
|
if (!value || typeof value !== 'object') {
|
|
@@ -6030,17 +6030,18 @@ function collectResumeDesiredFields(fields, options) {
|
|
|
6030
6030
|
}
|
|
6031
6031
|
const componentName = normalizeFormDefinitionType(value);
|
|
6032
6032
|
if (isSupportedBusinessFieldType(componentName)) {
|
|
6033
|
-
output.push(value);
|
|
6033
|
+
output.push({ field: value, tablePath });
|
|
6034
6034
|
if (!verifyNestedFields) {
|
|
6035
6035
|
return;
|
|
6036
6036
|
}
|
|
6037
6037
|
}
|
|
6038
6038
|
if (Array.isArray(value.children)) {
|
|
6039
|
-
value.children
|
|
6039
|
+
visit(value.children, componentName === 'TableField'
|
|
6040
|
+
? tablePath.concat(desiredResumeFieldIdentity(value).label) : tablePath);
|
|
6040
6041
|
}
|
|
6041
6042
|
}
|
|
6042
6043
|
|
|
6043
|
-
visit(fields);
|
|
6044
|
+
visit(fields, []);
|
|
6044
6045
|
return output;
|
|
6045
6046
|
}
|
|
6046
6047
|
|
|
@@ -6068,28 +6069,34 @@ function isRecoverableBlankResumeSchema(schema) {
|
|
|
6068
6069
|
}
|
|
6069
6070
|
|
|
6070
6071
|
function buildResumeChanges(existingFields, desiredFields) {
|
|
6071
|
-
|
|
6072
|
+
// Layout containers do not change identity. A table creates a new namespace;
|
|
6073
|
+
// JSON tuples preserve punctuation in labels without path collisions.
|
|
6074
|
+
const scopedKey = (tablePath, label) => JSON.stringify([...tablePath, label]);
|
|
6075
|
+
const existingByScope = new Map();
|
|
6072
6076
|
existingFields.forEach(function (field) {
|
|
6073
|
-
const
|
|
6077
|
+
const key = scopedKey(field.tablePath, field.label);
|
|
6078
|
+
const bucket = existingByScope.get(key) || [];
|
|
6074
6079
|
bucket.push(field);
|
|
6075
|
-
|
|
6080
|
+
existingByScope.set(key, bucket);
|
|
6076
6081
|
});
|
|
6077
6082
|
|
|
6078
6083
|
const desiredLabels = new Set();
|
|
6079
6084
|
const missing = [];
|
|
6080
6085
|
const existing = [];
|
|
6081
6086
|
const conflicts = [];
|
|
6082
|
-
desiredFields.forEach(function (field) {
|
|
6087
|
+
desiredFields.forEach(function ({ field, tablePath }) {
|
|
6083
6088
|
const identity = desiredResumeFieldIdentity(field);
|
|
6084
|
-
|
|
6089
|
+
const key = scopedKey(tablePath, identity.label);
|
|
6090
|
+
if (!identity.label || desiredLabels.has(key)) {
|
|
6085
6091
|
conflicts.push({
|
|
6086
6092
|
code: identity.label ? 'CREATE_FORM_RESUME_DUPLICATE_DESIRED_FIELD' : 'CREATE_FORM_RESUME_FIELD_LABEL_REQUIRED',
|
|
6087
6093
|
label: identity.label || null,
|
|
6094
|
+
tablePath,
|
|
6088
6095
|
});
|
|
6089
6096
|
return;
|
|
6090
6097
|
}
|
|
6091
|
-
desiredLabels.add(
|
|
6092
|
-
const matches =
|
|
6098
|
+
desiredLabels.add(key);
|
|
6099
|
+
const matches = existingByScope.get(key) || [];
|
|
6093
6100
|
if (matches.length === 0) {
|
|
6094
6101
|
missing.push(field);
|
|
6095
6102
|
return;
|
|
@@ -6098,6 +6105,7 @@ function buildResumeChanges(existingFields, desiredFields) {
|
|
|
6098
6105
|
conflicts.push({
|
|
6099
6106
|
code: 'CREATE_FORM_RESUME_FIELD_CONFLICT',
|
|
6100
6107
|
label: identity.label,
|
|
6108
|
+
tablePath,
|
|
6101
6109
|
requestedType: identity.componentName,
|
|
6102
6110
|
observedTypes: matches.map(function (item) { return item.componentName; }),
|
|
6103
6111
|
});
|
|
@@ -6107,6 +6115,7 @@ function buildResumeChanges(existingFields, desiredFields) {
|
|
|
6107
6115
|
label: identity.label,
|
|
6108
6116
|
componentName: identity.componentName,
|
|
6109
6117
|
fieldId: matches[0].fieldId,
|
|
6118
|
+
tablePath,
|
|
6110
6119
|
});
|
|
6111
6120
|
});
|
|
6112
6121
|
return { missing, existing, conflicts };
|
|
@@ -6258,7 +6267,7 @@ async function mainResume(parsedArgs, authRef) {
|
|
|
6258
6267
|
const corpId = resolveCorpId(authRef.authData);
|
|
6259
6268
|
const formTitle = firstRead.schemaResult.formTitle || firstRead.schemaResult.title || formUuid;
|
|
6260
6269
|
firstRead.schema = buildFormSchema(formTitle, fields, formUuid, corpId, appType, 'single', 'default', 'top');
|
|
6261
|
-
const resumeValidationRules = collectSmartValidationRulesFromFields(fields).concat(validations || []);
|
|
6270
|
+
const resumeValidationRules = collectSmartValidationRulesFromFields(fields, firstRead.schema).concat(validations || []);
|
|
6262
6271
|
if (resumeValidationRules.length > 0) {
|
|
6263
6272
|
applySmartValidations(firstRead.schema, resumeValidationRules);
|
|
6264
6273
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const { normalizeSchemaFields, createSchemaHash } = require('./schema-field-resolution');
|
|
4
4
|
const { CliError } = require('../core/cli-error');
|
|
5
5
|
const { t } = require('../core/i18n');
|
|
6
|
+
const { readCanvasSubformRows } = require('./subform-readback');
|
|
6
7
|
|
|
7
8
|
const own = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
8
9
|
const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -12,6 +13,15 @@ const sets = new Set(['CheckboxField', 'MultiSelectField', 'EmployeeField', 'Dep
|
|
|
12
13
|
const files = new Set(['ImageField', 'AttachmentField']);
|
|
13
14
|
const numericText = value => typeof value === 'string' && /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(value.trim());
|
|
14
15
|
|
|
16
|
+
function supportsWriteComponent(type, props = {}) {
|
|
17
|
+
if (type === 'AddressField') {
|
|
18
|
+
return (props.addressType === undefined || props.addressType === 'ADDRESS')
|
|
19
|
+
&& (props.countryMode === undefined || props.countryMode === 'default');
|
|
20
|
+
}
|
|
21
|
+
return strings.has(type) || numbers.has(type) || sets.has(type) || files.has(type)
|
|
22
|
+
|| ['TableField', 'CitySelectField', 'CascadeDateField', 'AssociationFormField', 'CountrySelectField'].includes(type);
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
function buildWriteContract(schema) {
|
|
16
26
|
const fields = normalizeSchemaFields(schema);
|
|
17
27
|
const props = Object.create(null);
|
|
@@ -29,7 +39,7 @@ function buildWriteContract(schema) {
|
|
|
29
39
|
function arrayValue(value, reading) {
|
|
30
40
|
if (reading) {
|
|
31
41
|
// Association projections can contain two JSON string envelopes.
|
|
32
|
-
for (let i = 0; i < 2 && typeof value === 'string'; i++) {
|
|
42
|
+
for (let i = 0; i < 2 && typeof value === 'string' && value !== ''; i++) {
|
|
33
43
|
try {value = JSON.parse(value);} catch {return null;}
|
|
34
44
|
}
|
|
35
45
|
}
|
|
@@ -37,12 +47,41 @@ function arrayValue(value, reading) {
|
|
|
37
47
|
return Array.isArray(value) ? value : null;
|
|
38
48
|
}
|
|
39
49
|
|
|
40
|
-
|
|
50
|
+
// Writes use native arrays; read projections may omit target metadata, but must
|
|
51
|
+
// never contradict it when it is present. Shared by verified and legacy writes.
|
|
52
|
+
function associationValueIssue(value, props = {}, reading = false) {
|
|
53
|
+
if (!Array.isArray(value)) {return { reason: 'value_must_be_array', index: null };}
|
|
54
|
+
if (props.multiple === false && value.length > 1) {return { reason: 'single_selection_required', index: null };}
|
|
55
|
+
const seen = new Set();
|
|
56
|
+
const keys = reading ? ['instanceId'] : ['appType', 'formUuid', 'formType', 'instanceId', 'title'];
|
|
57
|
+
for (let index = 0; index < value.length; index++) {
|
|
58
|
+
const item = value[index];
|
|
59
|
+
if (!object(item)) {return { reason: 'item_must_be_object', index };}
|
|
60
|
+
const missingFields = keys.filter(key => typeof item[key] !== 'string' || !item[key].trim());
|
|
61
|
+
if (missingFields.length) {return { reason: 'required_fields_missing', index, missingFields };}
|
|
62
|
+
for (const key of ['appType', 'formUuid', 'formType']) {
|
|
63
|
+
if (own(item, key) && (typeof item[key] !== 'string' || !item[key].trim())) {
|
|
64
|
+
return { reason: 'invalid_target_metadata', index };
|
|
65
|
+
}
|
|
66
|
+
const target = props.associationForm?.[key];
|
|
67
|
+
if (typeof target === 'string' && target.trim() && own(item, key) && item[key] !== target) {
|
|
68
|
+
return { reason: 'association_target_mismatch', index };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!reading && item.subTitle !== undefined && typeof item.subTitle !== 'string') {
|
|
72
|
+
return { reason: 'subtitle_must_be_string', index };
|
|
73
|
+
}
|
|
74
|
+
if (seen.has(item.instanceId)) {return { reason: 'duplicate_selection', index };}
|
|
75
|
+
seen.add(item.instanceId);
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function canonical(field, value, reading = false, props = {}) {
|
|
41
81
|
const type = field.componentType;
|
|
42
|
-
const supported =
|
|
43
|
-
|| ['CitySelectField', 'CascadeDateField', 'AssociationFormField'].includes(type);
|
|
82
|
+
const supported = supportsWriteComponent(type, props);
|
|
44
83
|
if (!supported) {return { ok: false, reason: 'UNSUPPORTED_COMPONENT' };}
|
|
45
|
-
if (value === null || reading && value === '') {
|
|
84
|
+
if ((value === null && (type !== 'AssociationFormField' || reading)) || reading && value === '') {
|
|
46
85
|
return { ok: true, value: strings.has(type) || numbers.has(type) ? null : [] };
|
|
47
86
|
}
|
|
48
87
|
if (strings.has(type)) {
|
|
@@ -52,8 +91,33 @@ function canonical(field, value, reading = false) {
|
|
|
52
91
|
const number = reading && numericText(value) ? Number(value) : value;
|
|
53
92
|
return typeof number === 'number' && Number.isFinite(number) ? { ok: true, value: number } : { ok: false };
|
|
54
93
|
}
|
|
94
|
+
if (type === 'AddressField') {
|
|
95
|
+
if (reading) {
|
|
96
|
+
for (let depth = 0; depth < 2 && typeof value === 'string'; depth++) {
|
|
97
|
+
try {value = JSON.parse(value);} catch {return { ok: false };}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!object(value) || !Array.isArray(value.regionIds) || value.regionIds.length < 1 || value.regionIds.length > 4
|
|
101
|
+
|| !value.regionIds.every(id => typeof id === 'number' && Number.isSafeInteger(id) && id > 0
|
|
102
|
+
|| typeof id === 'string' && /^[1-9]\d*$/.test(id))
|
|
103
|
+
|| typeof value.address !== 'string' || !Array.isArray(value.regionText)
|
|
104
|
+
|| value.regionText.length !== value.regionIds.length
|
|
105
|
+
|| !value.regionText.every(text => object(text) && Object.entries(text).some(([key, label]) => key !== 'type' && typeof label === 'string' && label.trim()))) {
|
|
106
|
+
return { ok: false };
|
|
107
|
+
}
|
|
108
|
+
return { ok: true, value: { regionIds: value.regionIds.map(String), address: value.address } };
|
|
109
|
+
}
|
|
55
110
|
const list = arrayValue(value, reading);
|
|
56
111
|
if (!list) {return { ok: false };}
|
|
112
|
+
if (type === 'CountrySelectField') {
|
|
113
|
+
if (props.multiple !== true && list.length > 1) {return { ok: false, reason: 'SINGLE_SELECTION_REQUIRED' };}
|
|
114
|
+
const ids = list.map(item => reading && typeof item === 'string' ? item
|
|
115
|
+
: object(item) && (reading || object(item.text) && Object.entries(item.text)
|
|
116
|
+
.some(([key, label]) => key !== 'type' && typeof label === 'string' && label.trim())) ? item.value : null);
|
|
117
|
+
if (!ids.every(id => typeof id === 'string' && /^[A-Z]{2}$/.test(id))) {return { ok: false };}
|
|
118
|
+
if (new Set(ids).size !== ids.length) {return { ok: false, reason: 'DUPLICATE_SELECTION' };}
|
|
119
|
+
return { ok: true, value: ids.slice().sort() };
|
|
120
|
+
}
|
|
57
121
|
if (sets.has(type) || type === 'CitySelectField') {
|
|
58
122
|
if (!list.every(item => typeof item === 'string' && item.length > 0
|
|
59
123
|
|| ['DepartmentSelectField', 'CitySelectField'].includes(type) && typeof item === 'number' && Number.isFinite(item))) {
|
|
@@ -69,9 +133,9 @@ function canonical(field, value, reading = false) {
|
|
|
69
133
|
? { ok: true, value: endpoints } : { ok: false };
|
|
70
134
|
}
|
|
71
135
|
if (type === 'AssociationFormField') {
|
|
72
|
-
const
|
|
73
|
-
return
|
|
74
|
-
|
|
136
|
+
const issue = associationValueIssue(list, props, reading);
|
|
137
|
+
return issue ? { ok: false, reason: issue.reason.toUpperCase() }
|
|
138
|
+
: { ok: true, value: list.map(item => item.instanceId).sort() };
|
|
75
139
|
}
|
|
76
140
|
const identities = list.map(item => object(item)
|
|
77
141
|
? item.fileId || item.id || item.downloadUrl || item.url : null);
|
|
@@ -103,7 +167,7 @@ function prepareWriteData(data, contract, resolveAliases = false) {
|
|
|
103
167
|
output[field.fieldId] = value.map((row, index) => compile(row, field.fieldId, `${location}[${index}]`));
|
|
104
168
|
continue;
|
|
105
169
|
}
|
|
106
|
-
const normalized = canonical(field, value);
|
|
170
|
+
const normalized = canonical(field, value, false, contract.props[field.fieldId]);
|
|
107
171
|
if (!normalized.ok) {
|
|
108
172
|
issues.push({ path: location, fieldId: field.fieldId, componentType: field.componentType,
|
|
109
173
|
code: normalized.reason || 'INVALID_VALUE_TYPE' });
|
|
@@ -133,30 +197,68 @@ function prepareWriteData(data, contract, resolveAliases = false) {
|
|
|
133
197
|
return compiled;
|
|
134
198
|
}
|
|
135
199
|
|
|
136
|
-
function compareWriteData(expected, actual, contract) {
|
|
200
|
+
function compareWriteData(expected, actual, contract, instValue) {
|
|
137
201
|
const issues = [];
|
|
138
|
-
const compare = (wanted, observed, parent = null, prefix = '$') => {
|
|
202
|
+
const compare = (wanted, observed, parent = null, prefix = '$', rawEntries) => {
|
|
139
203
|
if (!object(observed)) {issues.push({ path: prefix, code: 'READBACK_DATA_UNAVAILABLE' }); return;}
|
|
140
204
|
for (const [id, value] of Object.entries(wanted)) {
|
|
141
205
|
const location = `${prefix}[${JSON.stringify(id)}]`;
|
|
142
206
|
const field = contract.fields.find(item => item.fieldId === id && item.parentFieldId === parent);
|
|
143
207
|
if (!field) {issues.push({ path: location, code: 'SCHEMA_FIELD_UNAVAILABLE' }); continue;}
|
|
144
|
-
|
|
145
|
-
|
|
208
|
+
// Member/department base projections contain display names; their _id
|
|
209
|
+
// projections carry identity. Association base values retain priority.
|
|
210
|
+
const identityProjection = ['EmployeeField', 'DepartmentSelectField', 'CountrySelectField'].includes(field.componentType)
|
|
211
|
+
&& own(observed, `${id}_id`);
|
|
212
|
+
const key = identityProjection || !own(observed, id) && field.componentType === 'AssociationFormField' ? `${id}_id` : id;
|
|
213
|
+
let found = own(observed, key), readValue = observed[key];
|
|
214
|
+
const emptyCollection = (sets.has(field.componentType) || files.has(field.componentType) || field.componentType === 'CountrySelectField')
|
|
215
|
+
&& Array.isArray(value) && value.length === 0;
|
|
216
|
+
if (!found && (field.componentType === 'AssociationFormField' || emptyCollection)) {
|
|
217
|
+
let entries = rawEntries;
|
|
218
|
+
if (typeof entries === 'string') {try {entries = JSON.parse(entries);} catch {entries = null;}}
|
|
219
|
+
const matches = Array.isArray(entries) ? entries.filter(entry => object(entry) && entry.fieldId === id) : [];
|
|
220
|
+
if (matches.length === 1 && (matches[0].componentName === undefined || matches[0].componentName === 'AssociationFormField')
|
|
221
|
+
&& field.componentType === 'AssociationFormField' && object(matches[0].fieldData) && own(matches[0].fieldData, 'value')) {
|
|
222
|
+
found = true; readValue = matches[0].fieldData.value;
|
|
223
|
+
}
|
|
224
|
+
const cell = matches.length === 1 ? matches[0] : null;
|
|
225
|
+
if (emptyCollection && cell?.componentName === field.componentType && object(cell.fieldData)
|
|
226
|
+
&& (parent === null ? !cell.rowId : typeof cell.rowId === 'string' && cell.rowId.trim())
|
|
227
|
+
&& !['HIDDEN', 'INVISIBLE'].includes(contract.props[id]?.behavior)
|
|
228
|
+
&& !['HIDDEN', 'INVISIBLE'].includes(contract.props[parent]?.behavior)
|
|
229
|
+
&& !['_id', '_value', '_all'].some(suffix => own(observed, id + suffix))) {
|
|
230
|
+
// This API retains the stored typed cell while null collection values
|
|
231
|
+
// serialize as fieldData={}. Its hidden-field filter removes cells or
|
|
232
|
+
// the whole raw snapshot. Row correspondence was checked above.
|
|
233
|
+
if (own(cell.fieldData, 'value')) { found = true; readValue = cell.fieldData.value; }
|
|
234
|
+
else if (Object.keys(cell.fieldData).length === 0) { found = true; readValue = []; }
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (!found) {issues.push({ path: location, fieldId: id, code: 'READBACK_FIELD_MISSING' }); continue;}
|
|
146
238
|
if (field.componentType === 'TableField') {
|
|
147
|
-
const
|
|
239
|
+
const result = readCanvasSubformRows({ formData: observed, instValue: rawEntries }, id);
|
|
240
|
+
const rows = result.status === 'error' ? null : result.rows;
|
|
148
241
|
if (!rows || rows.length !== value.length) {issues.push({ path: location, fieldId: id, code: 'READBACK_ROW_COUNT_MISMATCH' }); continue;}
|
|
149
|
-
value.forEach((row, index) => compare(row, rows[index], id, `${location}[${index}]
|
|
242
|
+
value.forEach((row, index) => compare(row, rows[index], id, `${location}[${index}]`, rows[index].instValue));
|
|
150
243
|
continue;
|
|
151
244
|
}
|
|
152
|
-
const
|
|
153
|
-
|
|
245
|
+
const props = contract.props[id];
|
|
246
|
+
const before = canonical(field, value, false, props), after = canonical(field, readValue, true, props);
|
|
247
|
+
let targetMismatch = false;
|
|
248
|
+
if (field.componentType === 'AssociationFormField' && before.ok && after.ok) {
|
|
249
|
+
const submitted = new Map(value.map(item => [item.instanceId, item]));
|
|
250
|
+
targetMismatch = (arrayValue(readValue, true) || []).some(item => {
|
|
251
|
+
const expected = submitted.get(item.instanceId);
|
|
252
|
+
return expected && ['appType', 'formUuid', 'formType'].some(k => own(item, k) && item[k] !== expected[k]);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (!before.ok || !after.ok || targetMismatch || JSON.stringify(before.value) !== JSON.stringify(after.value)) {
|
|
154
256
|
issues.push({ path: location, fieldId: id, code: 'READBACK_VALUE_MISMATCH' });
|
|
155
257
|
}
|
|
156
258
|
}
|
|
157
259
|
};
|
|
158
|
-
compare(expected, actual);
|
|
260
|
+
compare(expected, actual, null, '$', instValue);
|
|
159
261
|
return issues;
|
|
160
262
|
}
|
|
161
263
|
|
|
162
|
-
module.exports = { buildWriteContract, prepareWriteData, compareWriteData };
|
|
264
|
+
module.exports = { buildWriteContract, prepareWriteData, compareWriteData, associationValueIssue, supportsWriteComponent };
|
|
@@ -23,35 +23,138 @@ function isYidaBridge(path) {
|
|
|
23
23
|
&& bridgeMember(binding.path.node.init) && !binding.path.scope.getBinding('window'));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// Recognize the local, synchronous association parser by its explicit error
|
|
27
|
+
// contract, not its name alone. Constant aliases work; shadowed parameters and
|
|
28
|
+
// arbitrary adapters remain outside this rule.
|
|
29
|
+
function isAssociationParser(callee, cache, seen = new Set()) {
|
|
30
|
+
if (!callee.isIdentifier()) {return false;}
|
|
31
|
+
const binding = callee.scope.getBinding(callee.node.name);
|
|
32
|
+
if (!binding || !binding.constant || seen.has(binding)) {return false;}
|
|
33
|
+
if (cache.has(binding)) {return cache.get(binding);}
|
|
34
|
+
seen.add(binding);
|
|
35
|
+
let fn = binding.path;
|
|
36
|
+
if (fn.isVariableDeclarator()) {
|
|
37
|
+
const init = fn.get('init');
|
|
38
|
+
if (init.isIdentifier()) {
|
|
39
|
+
const result = isAssociationParser(init, cache, seen);
|
|
40
|
+
cache.set(binding, result);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
fn = init;
|
|
44
|
+
}
|
|
45
|
+
let marker = false, parsesJson = false;
|
|
46
|
+
if (fn.isFunction() && !fn.node.async && !fn.node.generator && fn.get('body').isBlockStatement()
|
|
47
|
+
&& fn.node.body.body.some(node => node.type === 'ReturnStatement' && node.argument?.type === 'Identifier')) {
|
|
48
|
+
fn.traverse({
|
|
49
|
+
Function(path) { path.skip(); },
|
|
50
|
+
StringLiteral(path) { if (path.node.value === 'DATA_ASSOCIATION_INVALID') {marker = true;} },
|
|
51
|
+
CallExpression(path) {
|
|
52
|
+
if (member(path.node.callee, 'parse') && path.node.callee.object?.name === 'JSON'
|
|
53
|
+
&& !path.scope.getBinding('JSON')) {parsesJson = true;}
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const result = marker && parsesJson;
|
|
58
|
+
cache.set(binding, result);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function constantValue(path, seen = new Set()) {
|
|
63
|
+
if (!path.isIdentifier()) {return path;}
|
|
64
|
+
const binding = path.scope.getBinding(path.node.name);
|
|
65
|
+
if (!binding || !binding.constant || !binding.path.isVariableDeclarator() || seen.has(binding)) {return path;}
|
|
66
|
+
seen.add(binding);
|
|
67
|
+
return constantValue(binding.path.get('init'), seen);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Deliberately narrow: a known association ID under formData, its constant
|
|
71
|
+
// alias, or a direct String/template coercion. Do not guess custom renderers.
|
|
72
|
+
function rendersRawAssociation(path) {
|
|
73
|
+
path = constantValue(path);
|
|
74
|
+
if (path.isMemberExpression() || path.isOptionalMemberExpression()) {
|
|
75
|
+
const key = path.node.computed ? path.node.property.value : path.node.property.name;
|
|
76
|
+
return typeof key === 'string' && /^associationFormField_.+/.test(key)
|
|
77
|
+
&& member(constantValue(path.get('object')).node, 'formData');
|
|
78
|
+
}
|
|
79
|
+
if (path.isCallExpression() && path.get('callee').isIdentifier({ name: 'String' })
|
|
80
|
+
&& !path.scope.getBinding('String') && path.node.arguments.length === 1) {
|
|
81
|
+
return rendersRawAssociation(path.get('arguments.0'));
|
|
82
|
+
}
|
|
83
|
+
if (path.isTemplateLiteral()) {return path.get('expressions').some(rendersRawAssociation);}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
26
87
|
function assertFormDataResponse(source, options = {}) {
|
|
27
88
|
let ast;
|
|
28
89
|
try { ast = Babel.packages.parser.parse(source, { sourceType: 'module', plugins: ['jsx', 'typescript'] }); }
|
|
29
90
|
catch { return; } // The compiler owns syntax diagnostics.
|
|
30
91
|
const issues = [];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
92
|
+
const associationIssues = [], parserCache = new WeakMap();
|
|
93
|
+
traverse(ast, {
|
|
94
|
+
TryStatement(path) {
|
|
95
|
+
const handler = path.get('handler');
|
|
96
|
+
if (!handler.node || path.node.finalizer) {return;}
|
|
97
|
+
const statements = handler.node.body.body;
|
|
98
|
+
const last = statements[statements.length - 1];
|
|
99
|
+
// Only the observed unconditional empty-array fallback. Branches, throws,
|
|
100
|
+
// structured error states and nested handlers are not inferred here.
|
|
101
|
+
if (last?.type !== 'ReturnStatement' || last.argument?.type !== 'ArrayExpression'
|
|
102
|
+
|| last.argument.elements.length || statements.slice(0, -1).some(node =>
|
|
103
|
+
!['ExpressionStatement', 'VariableDeclaration'].includes(node.type))) {return;}
|
|
104
|
+
let callsParser = false;
|
|
105
|
+
path.get('block').traverse({
|
|
106
|
+
Function(inner) { inner.skip(); },
|
|
107
|
+
TryStatement(inner) { inner.skip(); },
|
|
108
|
+
CallExpression(call) { if (isAssociationParser(call.get('callee'), parserCache)) {callsParser = true;} },
|
|
109
|
+
});
|
|
110
|
+
if (callsParser) {associationIssues.push({ line: handler.node.loc?.start.line || 1, kind: 'association_error_swallowed' });}
|
|
111
|
+
},
|
|
112
|
+
JSXExpressionContainer(path) {
|
|
113
|
+
if (path.parentPath.isJSXAttribute()) {return;}
|
|
114
|
+
const host = path.findParent(parent => parent.isJSXElement());
|
|
115
|
+
if (host) {
|
|
116
|
+
const name = host.node.openingElement.name;
|
|
117
|
+
if (name.type !== 'JSXIdentifier' || !/^[a-z][a-z0-9]*$/.test(name.name)) {return;}
|
|
118
|
+
}
|
|
119
|
+
if (!rendersRawAssociation(path.get('expression'))) {return;}
|
|
120
|
+
const debug = path.findParent(parent => parent.isJSXElement()
|
|
121
|
+
&& ['pre', 'code'].some(name => parent.get('openingElement.name').isJSXIdentifier({ name })));
|
|
122
|
+
if (!debug) {
|
|
123
|
+
associationIssues.push({ line: path.node.loc?.start.line || 1, kind: 'raw_association_rendered' });
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
VariableDeclarator(path) {
|
|
127
|
+
if (!path.get('id').isIdentifier() || !path.get('init').isAwaitExpression()) {return;}
|
|
128
|
+
const call = path.get('init.argument');
|
|
129
|
+
if (!call.isCallExpression() || !member(call.node.callee, 'searchFormDatas') || !isYidaBridge(call.get('callee.object'))) {return;}
|
|
130
|
+
const binding = path.scope.getBinding(path.node.id.name);
|
|
131
|
+
if (!binding || !binding.constant) {return;}
|
|
132
|
+
let unwrapsArray = false;
|
|
133
|
+
const doubleData = [];
|
|
134
|
+
for (const ref of binding.referencePaths) {
|
|
135
|
+
const first = ref.parentPath;
|
|
136
|
+
if (!member(first.node, 'data') || first.node.object !== ref.node) {continue;}
|
|
137
|
+
const next = first.parentPath;
|
|
138
|
+
if (member(next.node, 'data') && next.node.object === first.node) {doubleData.push(next);}
|
|
139
|
+
if (next.isCallExpression() && member(next.node.callee, 'isArray') && next.node.callee.object?.name === 'Array') {unwrapsArray = true;}
|
|
140
|
+
}
|
|
141
|
+
if (!unwrapsArray && doubleData.length) {
|
|
142
|
+
issues.push({ line: doubleData[0].node.loc?.start.line || 1, variable: path.node.id.name });
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
});
|
|
50
146
|
if (issues.length) {
|
|
51
147
|
throw new CliError(t('publish.lint_searchformdata_bridge_unwrap'), {
|
|
52
148
|
code: 'OPENYIDA_FORM_DATA_RESPONSE_INVALID',
|
|
53
149
|
details: { sourcePath: options.sourcePath || '', issues, nextAction: 'normalize_form_rows' },
|
|
54
150
|
});
|
|
55
151
|
}
|
|
152
|
+
if (associationIssues.length) {
|
|
153
|
+
throw new CliError(t('publish.lint_association_data_contract'), {
|
|
154
|
+
code: 'OPENYIDA_ASSOCIATION_DATA_INVALID',
|
|
155
|
+
details: { sourcePath: options.sourcePath || '', issues: associationIssues,
|
|
156
|
+
nextAction: 'use_read_canvas_association_and_preserve_error_status' },
|
|
157
|
+
});
|
|
158
|
+
}
|
|
56
159
|
}
|
|
57
160
|
module.exports = { assertFormDataResponse };
|