@tunasand/sdk 0.7.0 → 0.11.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/CHANGELOG.md +233 -88
- package/README.md +296 -273
- package/dist/analytics.js +657 -10
- package/dist/app.js +323 -96
- package/dist/apps-DIxAWBSZ.js +318 -0
- package/dist/astro-image.d.ts +1 -0
- package/dist/astro-image.js +33 -0
- package/dist/astro-server-Bwau8F6d.js +99 -0
- package/dist/astro-server.d.ts +1 -0
- package/dist/astro-server.js +1 -0
- package/dist/astro.d.ts +1 -0
- package/dist/astro.js +306 -0
- package/dist/bridge-Dv4NxGZ7.js +81 -0
- package/dist/bridge.js +2 -14
- package/dist/build-file-DNi0PHC5.js +31 -0
- package/dist/cli.js +6214 -9
- package/dist/{client-Derrexwr.js → client-C8STAw9T.js} +43 -24
- package/dist/code-N8pBUDbq.js +30 -0
- package/dist/code.d.ts +1 -0
- package/dist/code.js +1 -0
- package/dist/collection-nUz1RetA.js +264 -0
- package/dist/{declared-C_GvPiGF.js → declared-CE4a61qb.js} +124 -36
- package/dist/delivery.js +124 -132
- package/dist/dev-operations-Tutwi1On.js +46 -0
- package/dist/dev.js +9 -16
- package/dist/embeds-B-Dbn64k.js +29 -0
- package/dist/end-users.d.ts +1 -0
- package/dist/end-users.js +185 -0
- package/dist/{customers-C_vJY2_v.js → endUsers-DODfjnv1.js} +31 -38
- package/dist/{errorLabels-CPKiPabZ.js → errorLabels-aT2bnMsO.js} +593 -460
- package/dist/i18n.js +4 -4
- package/dist/ids-DmtIoqBX.js +109 -0
- package/dist/integrations.js +95 -49
- package/dist/{ja-C6lX0CeJ.js → ja-CrY_72Tn.js} +99 -54
- package/dist/{ja-C1HEWWTQ.js → ja-axQPxMJ-.js} +6 -6
- package/dist/operations-CIB99rIY.js +95 -0
- package/dist/operations.d.ts +1 -0
- package/dist/operations.js +1 -0
- package/dist/{page-E_cYgZx-.js → page-yo1cw1kW.js} +5 -5
- package/dist/preview.js +8 -1
- package/dist/{profile-D6t1QMQh.js → profile-DBsXLvvI.js} +52 -52
- package/dist/rich-text.d.ts +1 -0
- package/dist/{body.js → rich-text.js} +20 -21
- package/dist/schema-Dcg1ajnW.js +1267 -0
- package/dist/schema.js +324 -1
- package/dist/types/access/src/handoff.d.ts +22 -17
- package/dist/types/access/src/index.d.ts +2 -2
- package/dist/types/access/src/jws.d.ts +41 -0
- package/dist/types/access/src/jwt.d.ts +1 -1
- package/dist/types/access/src/oidc.d.ts +11 -3
- package/dist/types/access/src/signed.d.ts +0 -2
- package/dist/types/adapter-cloudflare/src/eventLog/viewSchema.d.ts +11 -0
- package/dist/types/contract/src/accountProfile.d.ts +7 -0
- package/dist/types/{cms-contract → contract}/src/apiKeys.d.ts +7 -3
- package/dist/types/contract/src/app.d.ts +38 -0
- package/dist/types/contract/src/appChannels.d.ts +114 -0
- package/dist/types/contract/src/appDefinition.d.ts +133 -0
- package/dist/types/{cms-contract → contract}/src/appDependencies.d.ts +91 -35
- package/dist/types/contract/src/appIdentities.d.ts +21 -0
- package/dist/types/contract/src/appInbound.d.ts +28 -0
- package/dist/types/contract/src/appMail.d.ts +106 -0
- package/dist/types/contract/src/appSecrets.d.ts +45 -0
- package/dist/types/contract/src/appServer.d.ts +501 -0
- package/dist/types/contract/src/approvalLabels.d.ts +26 -0
- package/dist/types/contract/src/approvals.d.ts +63 -0
- package/dist/types/contract/src/apps.d.ts +295 -0
- package/dist/types/contract/src/auditActions.d.ts +18 -0
- package/dist/types/contract/src/auditLabels.d.ts +223 -0
- package/dist/types/contract/src/authorize.d.ts +133 -0
- package/dist/types/{cms-contract → contract}/src/bridge.d.ts +39 -40
- package/dist/types/{cms-contract → contract}/src/consents.d.ts +32 -25
- package/dist/types/contract/src/deletion.d.ts +18 -0
- package/dist/types/contract/src/embeds.d.ts +105 -0
- package/dist/types/{cms-contract/src/customerLabels.d.ts → contract/src/endUserLabels.d.ts} +6 -9
- package/dist/types/contract/src/endUsers.d.ts +241 -0
- package/dist/types/{cms-contract → contract}/src/errorLabels.d.ts +76 -47
- package/dist/types/{cms-contract → contract}/src/errorLabelsEn.d.ts +52 -36
- package/dist/types/contract/src/errors.d.ts +117 -0
- package/dist/types/contract/src/eventSchemas.d.ts +70 -0
- package/dist/types/contract/src/eventTraces.d.ts +43 -0
- package/dist/types/{cms-contract → contract}/src/failureStatus.d.ts +16 -23
- package/dist/types/contract/src/fieldAccess.d.ts +45 -0
- package/dist/types/contract/src/fieldRules.d.ts +41 -0
- package/dist/types/{cms-contract/src/assets.d.ts → contract/src/files.d.ts} +5 -5
- package/dist/types/contract/src/formLabels.d.ts +3 -0
- package/dist/types/contract/src/forms.d.ts +4 -0
- package/dist/types/{cms-contract → contract}/src/functions.d.ts +3 -3
- package/dist/types/contract/src/grants.d.ts +26 -0
- package/dist/types/contract/src/headers.d.ts +5 -0
- package/dist/types/contract/src/hostingRpc.d.ts +149 -0
- package/dist/types/contract/src/hostnames.d.ts +30 -0
- package/dist/types/contract/src/identifiers.d.ts +148 -0
- package/dist/types/contract/src/ids.d.ts +112 -0
- package/dist/types/{cms-contract → contract}/src/import.d.ts +20 -19
- package/dist/types/contract/src/importLabels.d.ts +3 -0
- package/dist/types/contract/src/index.d.ts +92 -0
- package/dist/types/contract/src/integrationGraph.d.ts +83 -0
- package/dist/types/{cms-contract → contract}/src/issueLabels.d.ts +135 -99
- package/dist/types/{cms-contract → contract}/src/issueLabelsEn.d.ts +70 -52
- package/dist/types/contract/src/labels.d.ts +11 -0
- package/dist/types/contract/src/legacyAuditLabels.d.ts +10 -0
- package/dist/types/contract/src/livePeriods.d.ts +18 -0
- package/dist/types/contract/src/manage.d.ts +51 -0
- package/dist/types/contract/src/manageLabels.d.ts +11 -0
- package/dist/types/contract/src/manifestText.d.ts +66 -0
- package/dist/types/contract/src/mcpAuth.d.ts +139 -0
- package/dist/types/contract/src/mcpLabels.d.ts +5 -0
- package/dist/types/contract/src/messagePort.d.ts +208 -0
- package/dist/types/{cms-contract → contract}/src/migration.d.ts +3 -3
- package/dist/types/contract/src/notices.d.ts +38 -0
- package/dist/types/contract/src/operatorOperations.d.ts +640 -0
- package/dist/types/contract/src/operators.d.ts +33 -0
- package/dist/types/contract/src/outbound.d.ts +29 -0
- package/dist/types/contract/src/paths.d.ts +34 -0
- package/dist/types/contract/src/pending.d.ts +6 -0
- package/dist/types/{cms-contract → contract}/src/permissions.d.ts +9 -11
- package/dist/types/contract/src/perspective.d.ts +26 -0
- package/dist/types/contract/src/powers.d.ts +5 -0
- package/dist/types/contract/src/principal.d.ts +181 -0
- package/dist/types/{cms-contract → contract}/src/problems.d.ts +4 -4
- package/dist/types/contract/src/projectRole.d.ts +6 -0
- package/dist/types/contract/src/recordLabels.d.ts +6 -0
- package/dist/types/{cms-contract → contract}/src/roles.d.ts +10 -6
- package/dist/types/contract/src/ruleLabels.d.ts +16 -0
- package/dist/types/contract/src/ruleProblems.d.ts +16 -0
- package/dist/types/contract/src/schemaLabels.d.ts +8 -0
- package/dist/types/{cms-contract → contract}/src/settingProblems.d.ts +3 -3
- package/dist/types/{cms-contract → contract}/src/settings.d.ts +6 -8
- package/dist/types/contract/src/settingsLabels.d.ts +3 -0
- package/dist/types/{cms-contract → contract}/src/siteDeclaration.d.ts +7 -7
- package/dist/types/contract/src/siteIndex.d.ts +76 -0
- package/dist/types/contract/src/slugs.d.ts +6 -0
- package/dist/types/{cms-contract → contract}/src/transfer.d.ts +4 -4
- package/dist/types/contract/src/trial.d.ts +13 -0
- package/dist/types/contract/src/versions.d.ts +7 -0
- package/dist/types/{analytics/src/view.d.ts → contract/src/viewEvent.d.ts} +0 -9
- package/dist/types/contract/src/webhooks.d.ts +135 -0
- package/dist/types/contract/src/workflow.d.ts +43 -0
- package/dist/types/contract/src/workspaceItems.d.ts +87 -0
- package/dist/types/contract/src/workspacePaths.d.ts +4 -0
- package/dist/types/{body → rich-text}/src/declared.d.ts +2 -2
- package/dist/types/{body → rich-text}/src/embed.d.ts +1 -1
- package/dist/types/{body → rich-text}/src/html.d.ts +1 -1
- package/dist/types/{body → rich-text}/src/index.d.ts +8 -7
- package/dist/types/{body → rich-text}/src/labels/en.d.ts +1 -1
- package/dist/types/{body → rich-text}/src/labels/ja.d.ts +4 -4
- package/dist/types/{body → rich-text}/src/library.d.ts +1 -1
- package/dist/types/rich-text/src/media.d.ts +2 -0
- package/dist/types/{body → rich-text}/src/normalize.d.ts +1 -1
- package/dist/types/{body → rich-text}/src/problems.d.ts +5 -5
- package/dist/types/{body → rich-text}/src/profile.d.ts +11 -11
- package/dist/types/{body → rich-text}/src/render.d.ts +1 -1
- package/dist/types/{body → rich-text}/src/schema.d.ts +2 -2
- package/dist/types/{body → rich-text}/src/standard.d.ts +4 -4
- package/dist/types/{body → rich-text}/src/types.d.ts +2 -2
- package/dist/types/schema/src/audience.d.ts +36 -0
- package/dist/types/schema/src/brand.d.ts +5 -0
- package/dist/types/schema/src/capabilities.d.ts +19 -0
- package/dist/types/{model → schema}/src/changes.d.ts +9 -7
- package/dist/types/{model → schema}/src/check.d.ts +2 -2
- package/dist/types/{model/src/model.d.ts → schema/src/collection.d.ts} +150 -121
- package/dist/types/schema/src/defaultSchema.d.ts +15 -0
- package/dist/types/schema/src/fieldIds.d.ts +18 -0
- package/dist/types/{model/src/asset.d.ts → schema/src/file.d.ts} +36 -25
- package/dist/types/schema/src/fileRefs.d.ts +14 -0
- package/dist/types/schema/src/fileSignature.d.ts +20 -0
- package/dist/types/schema/src/filesCollection.d.ts +7 -0
- package/dist/types/schema/src/forms.d.ts +43 -0
- package/dist/types/{model → schema}/src/image.d.ts +3 -3
- package/dist/types/schema/src/imageMetadata.d.ts +9 -0
- package/dist/types/schema/src/index.d.ts +35 -0
- package/dist/types/{model → schema}/src/input.d.ts +3 -3
- package/dist/types/{model → schema}/src/integrity.d.ts +9 -8
- package/dist/types/schema/src/kinds.d.ts +26 -0
- package/dist/types/{model → schema}/src/labels/en.d.ts +93 -51
- package/dist/types/{model → schema}/src/labels/ja.d.ts +97 -52
- package/dist/types/schema/src/mediaUrl.d.ts +60 -0
- package/dist/types/{model → schema}/src/page.d.ts +6 -6
- package/dist/types/{model → schema}/src/problems.d.ts +95 -53
- package/dist/types/{model → schema}/src/refs.d.ts +1 -10
- package/dist/types/{model → schema}/src/rules.d.ts +2 -2
- package/dist/types/{model → schema}/src/schema.d.ts +25 -20
- package/dist/types/schema/src/selfOps.d.ts +31 -0
- package/dist/types/{model/src/capabilities.d.ts → schema/src/traits.d.ts} +6 -6
- package/dist/types/schema/src/typesSource.d.ts +16 -0
- package/dist/types/{model → schema}/src/values.d.ts +7 -4
- package/dist/types/schema/src/widening.d.ts +3 -0
- package/dist/types/sdk/src/analytics.d.ts +3 -2
- package/dist/types/sdk/src/app.d.ts +70 -16
- package/dist/types/sdk/src/astro-image.d.ts +19 -0
- package/dist/types/sdk/src/astro-response.d.ts +6 -0
- package/dist/types/sdk/src/astro-server.d.ts +16 -0
- package/dist/types/sdk/src/astro.d.ts +19 -0
- package/dist/types/sdk/src/bridge.d.ts +13 -15
- package/dist/types/sdk/src/code.d.ts +61 -0
- package/dist/types/sdk/src/delegation.d.ts +49 -0
- package/dist/types/sdk/src/delivery/changes.d.ts +4 -4
- package/dist/types/sdk/src/delivery/client.d.ts +40 -28
- package/dist/types/sdk/src/delivery/fields.d.ts +5 -5
- package/dist/types/sdk/src/delivery/index.d.ts +3 -3
- package/dist/types/sdk/src/delivery/media.d.ts +8 -11
- package/dist/types/sdk/src/delivery/query.d.ts +16 -12
- package/dist/types/sdk/src/delivery/schema.d.ts +5 -5
- package/dist/types/sdk/src/delivery/values.d.ts +16 -20
- package/dist/types/sdk/src/delivery.d.ts +3 -3
- package/dist/types/sdk/src/dev-operations.d.ts +20 -0
- package/dist/types/sdk/src/dev.d.ts +6 -5
- package/dist/types/sdk/src/end-users.d.ts +190 -0
- package/dist/types/sdk/src/i18n.d.ts +11 -11
- package/dist/types/sdk/src/integrations.d.ts +20 -27
- package/dist/types/sdk/src/operations.d.ts +17 -0
- package/dist/types/sdk/src/preview.d.ts +2 -1
- package/dist/types/sdk/src/rich-text.d.ts +2 -0
- package/dist/types/sdk/src/schema.d.ts +5 -21
- package/dist/types/sdk/src/site/artifact.d.ts +64 -0
- package/dist/types/sdk/src/site/build-file.d.ts +30 -0
- package/dist/types/sdk/src/site/check-code.d.ts +14 -0
- package/dist/types/sdk/src/site/check-text.d.ts +19 -0
- package/dist/types/sdk/src/site/cli.d.ts +52 -0
- package/dist/types/sdk/src/site/content-type.d.ts +2 -0
- package/dist/types/sdk/src/site/labels.d.ts +14 -0
- package/dist/types/sdk/src/site.d.ts +1 -1
- package/dist/types/sdk/src/types.d.ts +21 -0
- package/dist/{schema-BPHL7Qr-.js → types-DkO2N7u2.js} +9 -9
- package/dist/types.d.ts +1 -0
- package/dist/types.js +1 -0
- package/dist/typesSource-VJIxtN9b.js +136 -0
- package/dist/workflow-CUpl6hO_.js +148 -0
- package/package.json +42 -16
- package/dist/apps-9u4XMi7E.js +0 -114
- package/dist/body.d.ts +0 -1
- package/dist/bridge-DYAYGV7t.js +0 -74
- package/dist/customers.d.ts +0 -1
- package/dist/customers.js +0 -185
- package/dist/embed-R-OvDYAw.js +0 -90
- package/dist/model-pmXzGX12.js +0 -152
- package/dist/model.d.ts +0 -1
- package/dist/model.js +0 -345
- package/dist/schema-UQJWRyfJ.js +0 -995
- package/dist/src-sazhzYui.js +0 -71
- package/dist/types/analytics/src/index.d.ts +0 -5
- package/dist/types/analytics/src/schedule.d.ts +0 -2
- package/dist/types/analytics/src/shared.d.ts +0 -21
- package/dist/types/analytics/src/source.d.ts +0 -19
- package/dist/types/analytics/src/store.d.ts +0 -24
- package/dist/types/cms-contract/src/app.d.ts +0 -35
- package/dist/types/cms-contract/src/apps.d.ts +0 -195
- package/dist/types/cms-contract/src/authorize.d.ts +0 -146
- package/dist/types/cms-contract/src/customers.d.ts +0 -266
- package/dist/types/cms-contract/src/embeds.d.ts +0 -165
- package/dist/types/cms-contract/src/errors.d.ts +0 -105
- package/dist/types/cms-contract/src/identifiers.d.ts +0 -117
- package/dist/types/cms-contract/src/paths.d.ts +0 -23
- package/dist/types/cms-contract/src/urlLabel.d.ts +0 -13
- package/dist/types/cms-contract/src/webhooks.d.ts +0 -139
- package/dist/types/model/src/audience.d.ts +0 -38
- package/dist/types/model/src/brand.d.ts +0 -25
- package/dist/types/model/src/index.d.ts +0 -26
- package/dist/types/model/src/legacy.d.ts +0 -2
- package/dist/types/model/src/media.d.ts +0 -5
- package/dist/types/model/src/mediaUrl.d.ts +0 -67
- package/dist/types/model/src/selfOps.d.ts +0 -30
- package/dist/types/model/src/typesSource.d.ts +0 -8
- package/dist/types/platform/src/defaultModel.d.ts +0 -8
- package/dist/types/sdk/src/body.d.ts +0 -2
- package/dist/types/sdk/src/customers.d.ts +0 -190
- package/dist/types/sdk/src/model.d.ts +0 -5
- package/dist/typesSource-bO0jFw1I.js +0 -88
- /package/dist/types/{cms-contract → contract}/src/appProblems.d.ts +0 -0
- /package/dist/types/{analytics → contract}/src/day.d.ts +0 -0
- /package/dist/types/{cms-contract → contract}/src/functionLabels.d.ts +0 -0
- /package/dist/types/{cms-contract → contract}/src/permissionLabels.d.ts +0 -0
- /package/dist/types/{cms-contract → contract}/src/siteArtifact.d.ts +0 -0
- /package/dist/types/{cms-contract → contract}/src/views.d.ts +0 -0
- /package/dist/types/{cms-contract → contract}/src/webhookLabels.d.ts +0 -0
- /package/dist/types/{body → rich-text}/src/components.d.ts +0 -0
- /package/dist/types/{body → rich-text}/src/derive.d.ts +0 -0
- /package/dist/types/{body → rich-text}/src/description.d.ts +0 -0
- /package/dist/types/{body → rich-text}/src/href.d.ts +0 -0
- /package/dist/types/{body → rich-text}/src/inline.d.ts +0 -0
- /package/dist/types/{body → rich-text}/src/markdown.d.ts +0 -0
- /package/dist/types/{model → schema}/src/contact.d.ts +0 -0
- /package/dist/types/{model → schema}/src/json.d.ts +0 -0
- /package/dist/types/{model → schema}/src/screens.d.ts +0 -0
- /package/dist/types/{model → schema}/src/time.d.ts +0 -0
package/dist/schema-UQJWRyfJ.js
DELETED
|
@@ -1,995 +0,0 @@
|
|
|
1
|
-
import { i as CORE_COMPONENTS, t as declaredComponentsSchema } from "./declared-C_GvPiGF.js";
|
|
2
|
-
import { f as problemText, l as problemFactory } from "./ja-C1HEWWTQ.js";
|
|
3
|
-
import { n as PRODUCT_FIELD_LABELS, t as MODEL_PROBLEM_MESSAGES } from "./ja-C6lX0CeJ.js";
|
|
4
|
-
import { C as isSurveyShape, S as isSingleton, a as PII_CLASSES, c as acceptsRole, d as cascadeTargetsOf, i as ON_DELETE, l as audienceOf, m as declaredAudienceOf, n as CUSTOMER_FIELD_TYPE, o as SELF_OPS, r as FIELD_ROLES, s as SLUG_MODES, t as AUDIENCES, u as cascadeDepths, v as isListCollection, w as narrower, x as isSequenceField } from "./model-pmXzGX12.js";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
// ../model/src/problems.ts
|
|
7
|
-
/** コンテンツスキーマの検査の問題を作る */
|
|
8
|
-
const modelProblem = problemFactory(MODEL_PROBLEM_MESSAGES);
|
|
9
|
-
/** 問題の英語の既定の文(zod の message と検査の issues の message に入れ、problemOf で戻す) */
|
|
10
|
-
const modelProblemText = (code, ...params) => problemText(modelProblem(code, ...params));
|
|
11
|
-
const PHONE_REGION_IDS = Object.keys({
|
|
12
|
-
JP: "81",
|
|
13
|
-
KR: "82",
|
|
14
|
-
TW: "886",
|
|
15
|
-
CN: "86",
|
|
16
|
-
GB: "44"
|
|
17
|
-
});
|
|
18
|
-
/** URL の項目が受け付ける scheme */
|
|
19
|
-
const URL_SCHEMES = ["https", "http"];
|
|
20
|
-
// ../model/src/check.ts
|
|
21
|
-
/** 配列でないオブジェクトか */
|
|
22
|
-
const isRecord$1 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23
|
-
/** 一意の組に含められる項目か(最上位・単数・入力する項目で、値を文字にできる種類) */
|
|
24
|
-
function acceptsUnique(f) {
|
|
25
|
-
if (f.computed || "multiple" in f && f.multiple) return false;
|
|
26
|
-
return [
|
|
27
|
-
"text",
|
|
28
|
-
"email",
|
|
29
|
-
"phone",
|
|
30
|
-
"url",
|
|
31
|
-
"number",
|
|
32
|
-
"select",
|
|
33
|
-
"reference",
|
|
34
|
-
"date",
|
|
35
|
-
"datetime",
|
|
36
|
-
CUSTOMER_FIELD_TYPE
|
|
37
|
-
].includes(f.type);
|
|
38
|
-
}
|
|
39
|
-
/** コレクションの一意の組(宣言 unique と、unique を付けた顧客フィールドと、連番の項目) */
|
|
40
|
-
const uniqueDefsOf = (collection) => [...collection.unique ?? [], ...collection.fields.flatMap((f) => f.type === "customer" && f.unique || isSequenceField(f) ? [{
|
|
41
|
-
key: f.key,
|
|
42
|
-
fields: [f.key],
|
|
43
|
-
exact: true
|
|
44
|
-
}] : [])];
|
|
45
|
-
/** コレクションの整合の宣言の誤り(スキーマの検査、schema.ts) */
|
|
46
|
-
function integrityProblems(collection) {
|
|
47
|
-
const id = collection.slug;
|
|
48
|
-
const problems = [];
|
|
49
|
-
const defs = uniqueDefsOf(collection);
|
|
50
|
-
if (collection.unique?.length && !isListCollection(collection)) problems.push(modelProblemText("unique_list_only", { collection: id }));
|
|
51
|
-
const names = defs.map((d) => d.key);
|
|
52
|
-
for (const n of new Set(names)) if (names.filter((x) => x === n).length > 1) problems.push(modelProblemText("unique_name_duplicate", {
|
|
53
|
-
collection: id,
|
|
54
|
-
key: n
|
|
55
|
-
}));
|
|
56
|
-
for (const d of collection.unique ?? []) {
|
|
57
|
-
if (!d.fields.length || d.fields.length > 3) problems.push(modelProblemText("unique_field_count", {
|
|
58
|
-
collection: id,
|
|
59
|
-
key: d.key,
|
|
60
|
-
max: 3
|
|
61
|
-
}));
|
|
62
|
-
if (new Set(d.fields).size !== d.fields.length) problems.push(modelProblemText("unique_field_duplicate", {
|
|
63
|
-
collection: id,
|
|
64
|
-
key: d.key
|
|
65
|
-
}));
|
|
66
|
-
for (const key of d.fields) {
|
|
67
|
-
const f = collection.fields.find((x) => x.key === key);
|
|
68
|
-
if (!f) problems.push(modelProblemText("unique_field_not_top", {
|
|
69
|
-
collection: id,
|
|
70
|
-
key: d.key,
|
|
71
|
-
field: key
|
|
72
|
-
}));
|
|
73
|
-
else if (!acceptsUnique(f)) problems.push(modelProblemText("unique_field_unsupported", {
|
|
74
|
-
collection: id,
|
|
75
|
-
key: d.key,
|
|
76
|
-
field: key,
|
|
77
|
-
type: f.type
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const nested = (fields, path) => fields.flatMap((f) => [...isSequenceField(f) ? [modelProblemText("sequence_nested", {
|
|
82
|
-
collection: id,
|
|
83
|
-
field: `${path}${f.key}`
|
|
84
|
-
})] : [], ...f.type === "group" ? nested(f.fields, `${path}${f.key}.`) : []]);
|
|
85
|
-
for (const f of collection.fields) {
|
|
86
|
-
if (f.type === "group") problems.push(...nested(f.fields, `${f.key}.`));
|
|
87
|
-
if (!isSequenceField(f)) continue;
|
|
88
|
-
if (!isListCollection(collection)) problems.push(modelProblemText("sequence_list_only", {
|
|
89
|
-
collection: id,
|
|
90
|
-
field: f.key
|
|
91
|
-
}));
|
|
92
|
-
if (f.required || f.computed || f.when) problems.push(modelProblemText("sequence_plain", {
|
|
93
|
-
collection: id,
|
|
94
|
-
field: f.key
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
return problems;
|
|
98
|
-
}
|
|
99
|
-
/** 遷移の宣言の誤り(スキーマの検査) */
|
|
100
|
-
function transitionProblems(collection) {
|
|
101
|
-
const id = collection.slug;
|
|
102
|
-
const nested = (fields, path) => fields.flatMap((f) => [...f.type === "select" && f.transitions ? [modelProblemText("transition_nested", {
|
|
103
|
-
collection: id,
|
|
104
|
-
field: `${path}${f.key}`
|
|
105
|
-
})] : [], ...f.type === "group" ? nested(f.fields, `${path}${f.key}.`) : []]);
|
|
106
|
-
return collection.fields.flatMap((f) => {
|
|
107
|
-
if (f.type === "group") return nested(f.fields, `${f.key}.`);
|
|
108
|
-
if (f.type !== "select" || !f.transitions) return [];
|
|
109
|
-
const values = new Set(f.options.map((o) => o.value));
|
|
110
|
-
const problems = [];
|
|
111
|
-
if (f.multiple || f.derive || f.fixedBy) problems.push(modelProblemText("transition_field_kind", {
|
|
112
|
-
collection: id,
|
|
113
|
-
field: f.key
|
|
114
|
-
}));
|
|
115
|
-
for (const [i, t] of f.transitions.entries()) {
|
|
116
|
-
const at = {
|
|
117
|
-
collection: id,
|
|
118
|
-
field: f.key,
|
|
119
|
-
index: i + 1
|
|
120
|
-
};
|
|
121
|
-
if (!values.has(t.to)) problems.push(modelProblemText("transition_to_not_option", {
|
|
122
|
-
...at,
|
|
123
|
-
to: t.to
|
|
124
|
-
}));
|
|
125
|
-
if (!t.from.length) problems.push(modelProblemText("transition_from_empty", at));
|
|
126
|
-
for (const v of t.from) if (v !== null && !values.has(v)) problems.push(modelProblemText("transition_from_not_option", {
|
|
127
|
-
...at,
|
|
128
|
-
value: v
|
|
129
|
-
}));
|
|
130
|
-
if (!t.by.roles?.length && !t.by.self && !t.by.apps?.length) problems.push(modelProblemText("transition_no_actor", at));
|
|
131
|
-
}
|
|
132
|
-
return problems;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
// ../model/src/selfOps.ts
|
|
136
|
-
/** 本人の顧客フィールドか(コレクションの最上位の項目) */
|
|
137
|
-
const isSelfField = (f, collection) => f.type === "customer" && (f.self === true || f.self === void 0 && declaredAudienceOf(f) === void 0 && isSurveyShape(collection));
|
|
138
|
-
/** コレクションの本人の顧客フィールド */
|
|
139
|
-
const selfFieldsOf = (collection) => collection.fields.filter((f) => isSelfField(f, collection));
|
|
140
|
-
/** 本人が書ける印を付けられない項目の理由(付けられれば null) */
|
|
141
|
-
function selfWritableBlock(f, collection) {
|
|
142
|
-
if (f.type === "customer") return "customer";
|
|
143
|
-
if (f.type === "group" || f.type === "media" || f.type === "rich_text") return f.type;
|
|
144
|
-
if (audienceOf(f, collection) === "staff") return "staff";
|
|
145
|
-
if (f.adminOnly) return "admin_only";
|
|
146
|
-
if (f.computed) return "computed";
|
|
147
|
-
if (isSequenceField(f)) return "sequence";
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
/** 人の操作の宣言の誤り(配信しない一覧のコレクション、本人の顧客フィールドがちょうど1つで onDelete は cascade か anonymize、一意の組はすべて本人の顧客フィールドを含む) */
|
|
151
|
-
function selfOpsProblems(collection) {
|
|
152
|
-
if (!collection.selfOps?.length) return [];
|
|
153
|
-
const self = selfFieldsOf(collection);
|
|
154
|
-
const at = { collection: collection.slug };
|
|
155
|
-
const problems = [];
|
|
156
|
-
if (collection.private !== true) problems.push(modelProblemText("self_ops_private_only", at));
|
|
157
|
-
if (isSingleton(collection)) problems.push(modelProblemText("self_ops_list_only", at));
|
|
158
|
-
if ((collection.publishing ?? "none") !== "none" || collection.fields.some((f) => f.key === "published" && f.type === "boolean")) problems.push(modelProblemText("self_ops_unpublished", at));
|
|
159
|
-
if (self.length !== 1) problems.push(modelProblemText("self_ops_one_self", at));
|
|
160
|
-
const key = self.length === 1 ? self[0].key : null;
|
|
161
|
-
if (key && self[0].onDelete !== "cascade" && self[0].onDelete !== "anonymize") problems.push(modelProblemText("self_ops_on_delete", {
|
|
162
|
-
...at,
|
|
163
|
-
field: key
|
|
164
|
-
}));
|
|
165
|
-
for (const d of uniqueDefsOf(collection)) if (key && !d.fields.includes(key)) problems.push(modelProblemText("self_ops_unique", {
|
|
166
|
-
...at,
|
|
167
|
-
key: d.key,
|
|
168
|
-
field: key
|
|
169
|
-
}));
|
|
170
|
-
return problems;
|
|
171
|
-
}
|
|
172
|
-
/** 本人が書ける印の誤り(付けられない項目、まとまりの中、create_self か update_self を受けないコレクション) */
|
|
173
|
-
function selfWritableProblems(collection) {
|
|
174
|
-
const nested = (fields, path) => fields.flatMap((f) => [...f.selfWritable !== void 0 ? [modelProblemText("self_writable_nested", {
|
|
175
|
-
collection: collection.slug,
|
|
176
|
-
field: `${path}${f.key}`
|
|
177
|
-
})] : [], ...f.type === "group" ? nested(f.fields, `${path}${f.key}.`) : []]);
|
|
178
|
-
const writes = collection.selfOps?.some((op) => op === "create_self" || op === "update_self") ?? false;
|
|
179
|
-
return collection.fields.flatMap((f) => {
|
|
180
|
-
const inner = f.type === "group" ? nested(f.fields, `${f.key}.`) : [];
|
|
181
|
-
if (!f.selfWritable) return inner;
|
|
182
|
-
const block = selfWritableBlock(f, collection);
|
|
183
|
-
return [
|
|
184
|
-
...block ? [modelProblemText("self_writable_blocked", {
|
|
185
|
-
collection: collection.slug,
|
|
186
|
-
field: f.key,
|
|
187
|
-
block
|
|
188
|
-
})] : [],
|
|
189
|
-
...writes ? [] : [modelProblemText("self_writable_without_ops", {
|
|
190
|
-
collection: collection.slug,
|
|
191
|
-
field: f.key
|
|
192
|
-
})],
|
|
193
|
-
...inner
|
|
194
|
-
];
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
// ../model/src/capabilities.ts
|
|
198
|
-
/** 出典の項目と、内側の項目の key */
|
|
199
|
-
const SOURCES_FIELD = {
|
|
200
|
-
key: "sources",
|
|
201
|
-
source: "source",
|
|
202
|
-
note: "note"
|
|
203
|
-
};
|
|
204
|
-
// ../model/src/legacy.ts
|
|
205
|
-
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
206
|
-
/** 記事の表のコレクションだった目印(古いバージョンの table の値) */
|
|
207
|
-
const ARTICLES = "articles";
|
|
208
|
-
const PUBLISHED_AT = "published_at";
|
|
209
|
-
/** 本文から作成する値の計算の項目(from は本文の項目の key) */
|
|
210
|
-
const computedFields = (from) => [
|
|
211
|
-
{
|
|
212
|
-
key: "excerpt",
|
|
213
|
-
label: PRODUCT_FIELD_LABELS.excerpt,
|
|
214
|
-
type: "long_text",
|
|
215
|
-
computed: {
|
|
216
|
-
kind: "excerpt",
|
|
217
|
-
from
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
key: "read_min",
|
|
222
|
-
label: PRODUCT_FIELD_LABELS.readMin,
|
|
223
|
-
type: "number",
|
|
224
|
-
computed: {
|
|
225
|
-
kind: "read_min",
|
|
226
|
-
from
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
key: "links",
|
|
231
|
-
label: PRODUCT_FIELD_LABELS.links,
|
|
232
|
-
type: "text",
|
|
233
|
-
multiple: true,
|
|
234
|
-
computed: {
|
|
235
|
-
kind: "links",
|
|
236
|
-
from
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
];
|
|
240
|
-
/** 出典の参照の項目を複数のまとまりに */
|
|
241
|
-
const sourcesGroup = (f) => ({
|
|
242
|
-
key: f.key,
|
|
243
|
-
label: f.label,
|
|
244
|
-
...f.private !== void 0 && { private: f.private },
|
|
245
|
-
type: "group",
|
|
246
|
-
multiple: true,
|
|
247
|
-
fields: [{
|
|
248
|
-
key: SOURCES_FIELD.source,
|
|
249
|
-
label: f.label,
|
|
250
|
-
type: "reference",
|
|
251
|
-
to: f.to
|
|
252
|
-
}, {
|
|
253
|
-
key: SOURCES_FIELD.note,
|
|
254
|
-
label: PRODUCT_FIELD_LABELS.sourceNote,
|
|
255
|
-
type: "long_text"
|
|
256
|
-
}]
|
|
257
|
-
});
|
|
258
|
-
/** 古い形のコレクションを今の形に(core・table のないコレクションはそのまま) */
|
|
259
|
-
function normalizeCollection(t) {
|
|
260
|
-
if (!("core" in t) && !("table" in t)) return t;
|
|
261
|
-
const { core, table, ...rest } = t;
|
|
262
|
-
const articles = table === ARTICLES;
|
|
263
|
-
const coreFields = (Array.isArray(core) ? core : []).filter(isRecord).flatMap((f) => {
|
|
264
|
-
if (articles && f.key === PUBLISHED_AT) return [];
|
|
265
|
-
if (articles && f.key === SOURCES_FIELD.key && f.type === "reference") return [sourcesGroup(f)];
|
|
266
|
-
return [f];
|
|
267
|
-
});
|
|
268
|
-
const keys = new Set(coreFields.map((f) => f.key));
|
|
269
|
-
const fields = [...coreFields, ...(Array.isArray(t.fields) ? t.fields : []).filter((f) => !isRecord(f) || !keys.has(f.key))];
|
|
270
|
-
if (!articles) return {
|
|
271
|
-
...rest,
|
|
272
|
-
fields
|
|
273
|
-
};
|
|
274
|
-
const body = fields.find((f) => isRecord(f) && f.type === "rich_text");
|
|
275
|
-
const present = new Set(fields.filter(isRecord).map((f) => f.key));
|
|
276
|
-
const computed = body ? computedFields(String(body.key)).filter((f) => !present.has(f.key)) : [];
|
|
277
|
-
return {
|
|
278
|
-
...rest,
|
|
279
|
-
fields: [...fields, ...computed]
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
/** 古い形のスキーマの JSON を今の形に(形の分からない値はそのまま、検査は parseModel) */
|
|
283
|
-
function normalizeLegacyModel(json) {
|
|
284
|
-
if (!isRecord(json) || !Array.isArray(json.collections)) return json;
|
|
285
|
-
return {
|
|
286
|
-
...json,
|
|
287
|
-
collections: json.collections.map((t) => isRecord(t) ? normalizeCollection(t) : t)
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
// ../model/src/schema.ts
|
|
291
|
-
/** 保持の日数の上限(100年) */
|
|
292
|
-
const RETENTION_DAYS_MAX = 36500;
|
|
293
|
-
const key = z.string().regex(/^[a-z][a-z0-9_]*$/, modelProblemText("invalid_collection_id"));
|
|
294
|
-
const fieldKey = z.string().regex(/^[a-z][a-zA-Z0-9_-]*$/, modelProblemText("invalid_field_key"));
|
|
295
|
-
const condition = z.object({
|
|
296
|
-
key: fieldKey,
|
|
297
|
-
in: z.array(z.string().min(1)).min(1)
|
|
298
|
-
});
|
|
299
|
-
const computed = z.object({
|
|
300
|
-
kind: z.enum([
|
|
301
|
-
"excerpt",
|
|
302
|
-
"read_min",
|
|
303
|
-
"links"
|
|
304
|
-
]),
|
|
305
|
-
from: fieldKey
|
|
306
|
-
});
|
|
307
|
-
const base = {
|
|
308
|
-
key: fieldKey,
|
|
309
|
-
label: z.string().min(1),
|
|
310
|
-
description: z.string().optional(),
|
|
311
|
-
required: z.union([
|
|
312
|
-
z.literal("save"),
|
|
313
|
-
z.literal("submit"),
|
|
314
|
-
z.literal("page"),
|
|
315
|
-
z.literal(false)
|
|
316
|
-
]).optional(),
|
|
317
|
-
when: condition.optional(),
|
|
318
|
-
audience: z.enum(AUDIENCES).optional(),
|
|
319
|
-
adminOnly: z.boolean().optional(),
|
|
320
|
-
selfWritable: z.boolean().optional(),
|
|
321
|
-
pendingUntil: fieldKey.optional(),
|
|
322
|
-
computed: computed.optional(),
|
|
323
|
-
pii: z.enum(PII_CLASSES).optional()
|
|
324
|
-
};
|
|
325
|
-
const frame = z.object({
|
|
326
|
-
when: condition.optional(),
|
|
327
|
-
ratio: z.string().min(1),
|
|
328
|
-
size: z.object({
|
|
329
|
-
width: z.number().int().positive(),
|
|
330
|
-
height: z.number().int().positive()
|
|
331
|
-
}),
|
|
332
|
-
label: z.string().min(1)
|
|
333
|
-
});
|
|
334
|
-
const pageRule = z.union([
|
|
335
|
-
z.object({
|
|
336
|
-
key: z.string().min(1),
|
|
337
|
-
in: z.array(z.string())
|
|
338
|
-
}),
|
|
339
|
-
z.object({
|
|
340
|
-
key: z.string().min(1),
|
|
341
|
-
notIn: z.array(z.string())
|
|
342
|
-
}),
|
|
343
|
-
z.object({
|
|
344
|
-
key: z.string().min(1),
|
|
345
|
-
truthy: z.literal(true)
|
|
346
|
-
}),
|
|
347
|
-
z.object({
|
|
348
|
-
key: z.string().min(1),
|
|
349
|
-
notFuture: z.literal(true)
|
|
350
|
-
})
|
|
351
|
-
]);
|
|
352
|
-
const page = z.object({
|
|
353
|
-
when: condition.optional(),
|
|
354
|
-
path: z.string().startsWith("/", modelProblemText("page_path_slash")),
|
|
355
|
-
public: z.array(pageRule).optional()
|
|
356
|
-
});
|
|
357
|
-
const field = z.lazy(() => fieldUnion);
|
|
358
|
-
/** 項目の宣言の形(アプリのマニフェストのコレクションの項目の検査に使う) */
|
|
359
|
-
const fieldDefSchema = field;
|
|
360
|
-
const transition = z.object({
|
|
361
|
-
from: z.array(z.string().min(1).nullable()),
|
|
362
|
-
to: z.string().min(1),
|
|
363
|
-
by: z.object({
|
|
364
|
-
roles: z.array(z.string().min(1)).optional(),
|
|
365
|
-
self: z.boolean().optional(),
|
|
366
|
-
apps: z.array(z.string().min(1)).optional()
|
|
367
|
-
})
|
|
368
|
-
});
|
|
369
|
-
const counts = {
|
|
370
|
-
minItems: z.number().int().nonnegative().optional(),
|
|
371
|
-
maxItems: z.number().int().positive().optional()
|
|
372
|
-
};
|
|
373
|
-
const regex = z.string().refine((p) => {
|
|
374
|
-
try {
|
|
375
|
-
new RegExp(p, "u");
|
|
376
|
-
return true;
|
|
377
|
-
} catch {
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
}, modelProblemText("invalid_pattern"));
|
|
381
|
-
const anonymize = z.array(fieldKey).min(1).optional();
|
|
382
|
-
const fieldUnion = z.discriminatedUnion("type", [
|
|
383
|
-
z.object({
|
|
384
|
-
...base,
|
|
385
|
-
...counts,
|
|
386
|
-
type: z.enum(["text", "long_text"]),
|
|
387
|
-
externalId: z.boolean().optional(),
|
|
388
|
-
maxLength: z.number().int().positive().optional(),
|
|
389
|
-
minLength: z.number().int().positive().optional(),
|
|
390
|
-
pattern: regex.optional(),
|
|
391
|
-
guideLength: z.number().int().positive().optional(),
|
|
392
|
-
multiple: z.boolean().optional()
|
|
393
|
-
}),
|
|
394
|
-
z.object({
|
|
395
|
-
...base,
|
|
396
|
-
type: z.literal("number"),
|
|
397
|
-
min: z.number().optional(),
|
|
398
|
-
max: z.number().optional(),
|
|
399
|
-
sequence: z.boolean().optional()
|
|
400
|
-
}),
|
|
401
|
-
z.object({
|
|
402
|
-
...base,
|
|
403
|
-
type: z.literal("boolean")
|
|
404
|
-
}),
|
|
405
|
-
z.object({
|
|
406
|
-
...base,
|
|
407
|
-
type: z.literal("email")
|
|
408
|
-
}),
|
|
409
|
-
z.object({
|
|
410
|
-
...base,
|
|
411
|
-
type: z.literal("phone"),
|
|
412
|
-
region: z.enum(PHONE_REGION_IDS).optional()
|
|
413
|
-
}),
|
|
414
|
-
z.object({
|
|
415
|
-
...base,
|
|
416
|
-
type: z.literal("url"),
|
|
417
|
-
schemes: z.array(z.enum(URL_SCHEMES)).min(1).optional()
|
|
418
|
-
}),
|
|
419
|
-
z.object({
|
|
420
|
-
...base,
|
|
421
|
-
type: z.enum(["date", "datetime"])
|
|
422
|
-
}),
|
|
423
|
-
z.object({
|
|
424
|
-
...base,
|
|
425
|
-
...counts,
|
|
426
|
-
type: z.literal("select"),
|
|
427
|
-
options: z.array(z.object({
|
|
428
|
-
value: z.string().min(1),
|
|
429
|
-
label: z.string().min(1),
|
|
430
|
-
tone: z.enum([
|
|
431
|
-
"positive",
|
|
432
|
-
"caution",
|
|
433
|
-
"neutral"
|
|
434
|
-
]).optional(),
|
|
435
|
-
restricted: z.boolean().optional()
|
|
436
|
-
})).min(1),
|
|
437
|
-
initial: z.string().optional(),
|
|
438
|
-
multiple: z.boolean().optional(),
|
|
439
|
-
derive: z.object({
|
|
440
|
-
from: fieldKey,
|
|
441
|
-
map: z.record(z.string(), z.string()),
|
|
442
|
-
otherwise: z.string()
|
|
443
|
-
}).optional(),
|
|
444
|
-
fixedBy: z.object({
|
|
445
|
-
ref: fieldKey,
|
|
446
|
-
key: fieldKey,
|
|
447
|
-
map: z.record(z.string(), z.string())
|
|
448
|
-
}).optional(),
|
|
449
|
-
transitions: z.array(transition).optional()
|
|
450
|
-
}).refine((f) => f.initial === void 0 || f.options.some((o) => o.value === f.initial), {
|
|
451
|
-
message: modelProblemText("initial_not_option"),
|
|
452
|
-
path: ["initial"]
|
|
453
|
-
}).refine((f) => !f.derive || [...Object.values(f.derive.map), f.derive.otherwise].every((v) => f.options.some((o) => o.value === v)), {
|
|
454
|
-
message: modelProblemText("derive_not_option"),
|
|
455
|
-
path: ["derive"]
|
|
456
|
-
}).refine((f) => !f.fixedBy || Object.values(f.fixedBy.map).every((v) => f.options.some((o) => o.value === v)), {
|
|
457
|
-
message: modelProblemText("fixed_not_option"),
|
|
458
|
-
path: ["fixedBy"]
|
|
459
|
-
}),
|
|
460
|
-
z.object({
|
|
461
|
-
...base,
|
|
462
|
-
...counts,
|
|
463
|
-
type: z.literal("reference"),
|
|
464
|
-
to: z.string().min(1),
|
|
465
|
-
multiple: z.boolean().optional(),
|
|
466
|
-
where: z.record(z.string(), z.string()).optional(),
|
|
467
|
-
requests: z.boolean().optional(),
|
|
468
|
-
emptyLabel: z.string().min(1).optional(),
|
|
469
|
-
unique: z.boolean().optional(),
|
|
470
|
-
published: z.boolean().optional(),
|
|
471
|
-
linkedBy: fieldKey.optional(),
|
|
472
|
-
onDelete: z.enum(ON_DELETE).optional(),
|
|
473
|
-
anonymize
|
|
474
|
-
}),
|
|
475
|
-
z.object({
|
|
476
|
-
...base,
|
|
477
|
-
...counts,
|
|
478
|
-
type: z.literal("media"),
|
|
479
|
-
accept: z.array(z.enum(["image", "video"])).optional(),
|
|
480
|
-
multiple: z.boolean().optional(),
|
|
481
|
-
frames: z.array(frame).optional(),
|
|
482
|
-
visibility: z.literal("private").optional()
|
|
483
|
-
}),
|
|
484
|
-
z.object({
|
|
485
|
-
...base,
|
|
486
|
-
type: z.literal("rich_text"),
|
|
487
|
-
visibility: z.literal("private").optional(),
|
|
488
|
-
profile: z.object({
|
|
489
|
-
headings: z.array(z.number()),
|
|
490
|
-
marks: z.array(z.string()),
|
|
491
|
-
components: z.array(z.string())
|
|
492
|
-
}).passthrough()
|
|
493
|
-
}),
|
|
494
|
-
z.object({
|
|
495
|
-
...base,
|
|
496
|
-
...counts,
|
|
497
|
-
type: z.literal("group"),
|
|
498
|
-
fields: z.array(field),
|
|
499
|
-
multiple: z.boolean().optional()
|
|
500
|
-
}),
|
|
501
|
-
z.object({
|
|
502
|
-
...base,
|
|
503
|
-
type: z.literal("customer"),
|
|
504
|
-
unique: z.boolean().optional(),
|
|
505
|
-
self: z.boolean().optional(),
|
|
506
|
-
onDelete: z.enum(ON_DELETE).optional(),
|
|
507
|
-
anonymize
|
|
508
|
-
}).refine((f) => f.onDelete !== "restrict", {
|
|
509
|
-
message: modelProblemText("customer_restrict"),
|
|
510
|
-
path: ["onDelete"]
|
|
511
|
-
})
|
|
512
|
-
]);
|
|
513
|
-
/** 条件が一覧にある選択肢の項目と値を指すか */
|
|
514
|
-
const conditionValid = (when, fields) => {
|
|
515
|
-
const target = when && fields.find((g) => g.key === when.key && g.type === "select");
|
|
516
|
-
return !when || target !== void 0 && when.in.every((v) => target.options.some((o) => o.value === v));
|
|
517
|
-
};
|
|
518
|
-
/** 条件が同じ階層の選択肢の項目と値を指すか(まとまりの中も) */
|
|
519
|
-
const conditionsValid = (fields) => fields.every((f) => conditionValid(f.when, fields) && (!f.derive || fields.some((g) => g.key === f.derive.from && g.type === "select")) && (!f.fixedBy || fields.some((g) => g.key === f.fixedBy.ref && g.type === "reference" && !g.multiple)) && (f.frames ?? []).every((fr) => conditionValid(fr.when, fields)) && conditionsValid(f.fields ?? []));
|
|
520
|
-
/** まとまりの中で決まる値・参照先で固定を持つ項目の key(宣言の適用 rules.ts が最上位の項目だけのため) */
|
|
521
|
-
const nestedRules = (fields) => fields.flatMap((f) => (f.fields ?? []).flatMap((c) => [...c.derive || c.fixedBy ? [`${f.key}.${c.key}`] : [], ...nestedRules([c]).map((k) => `${f.key}.${k}`)]));
|
|
522
|
-
/**
|
|
523
|
-
* システムの値と同じ名前で、項目の key に使用できない名前(API・配信が項目の値を上書きするため)
|
|
524
|
-
* - すべてのコレクション: レコードの ID とスラッグ・作成と更新の日時・作成者、管理画面の一覧で参照する行の数 uses
|
|
525
|
-
* - 公開の管理があるコレクション: 公開の機能の値
|
|
526
|
-
* - 対象外: API・配信の値に出ない列 type、導入先の設定で決まるアカウントの email・account_role
|
|
527
|
-
*/
|
|
528
|
-
const RESERVED = [
|
|
529
|
-
"id",
|
|
530
|
-
"slug",
|
|
531
|
-
"created_at",
|
|
532
|
-
"created_by",
|
|
533
|
-
"updated_at",
|
|
534
|
-
"uses"
|
|
535
|
-
];
|
|
536
|
-
const RESERVED_EDITORIAL = [
|
|
537
|
-
"status",
|
|
538
|
-
"published_at",
|
|
539
|
-
"visibility",
|
|
540
|
-
"version",
|
|
541
|
-
"review_note",
|
|
542
|
-
"assignee"
|
|
543
|
-
];
|
|
544
|
-
/** 配信 API の絞り込みの論理の演算(filter[or][0][key] など) */
|
|
545
|
-
const RESERVED_QUERY = [
|
|
546
|
-
"or",
|
|
547
|
-
"and",
|
|
548
|
-
"not"
|
|
549
|
-
];
|
|
550
|
-
/** 項目の key に使えない名前の全部(公開の管理の有無によらない。アプリのマニフェストの検査) */
|
|
551
|
-
const RESERVED_FIELD_KEYS = [
|
|
552
|
-
...RESERVED,
|
|
553
|
-
...RESERVED_EDITORIAL,
|
|
554
|
-
...RESERVED_QUERY
|
|
555
|
-
];
|
|
556
|
-
/** 予約の名前と同じ最上位の key */
|
|
557
|
-
function reservedKeysOf(t) {
|
|
558
|
-
const reserved = [...RESERVED, ...(t.publishing ?? "none") !== "none" ? RESERVED_EDITORIAL : []];
|
|
559
|
-
return [...t.fields.map((f) => f.key), ...(t.counts ?? []).map((c) => c.key)].filter((k) => reserved.includes(k));
|
|
560
|
-
}
|
|
561
|
-
/** 計算の種類ごとに受け付ける項目の種類 */
|
|
562
|
-
const COMPUTED_TYPES = {
|
|
563
|
-
excerpt: (f) => (f.type === "text" || f.type === "long_text") && !f.multiple,
|
|
564
|
-
read_min: (f) => f.type === "number",
|
|
565
|
-
links: (f) => f.type === "text" && Boolean(f.multiple)
|
|
566
|
-
};
|
|
567
|
-
/** 計算の項目の誤り(最上位の項目と、まとまりの中にある計算の項目) */
|
|
568
|
-
function computedProblems(collection, fields) {
|
|
569
|
-
const nested = (fs, path) => fs.flatMap((f) => [...f.computed ? [modelProblemText("computed_nested", {
|
|
570
|
-
collection,
|
|
571
|
-
field: `${path}${f.key}`
|
|
572
|
-
})] : [], ...nested(f.fields ?? [], `${path}${f.key}.`)]);
|
|
573
|
-
return fields.flatMap((f) => {
|
|
574
|
-
const inner = nested(f.fields ?? [], `${f.key}.`);
|
|
575
|
-
if (!f.computed) return inner;
|
|
576
|
-
return [...[...fields.find((g) => g.key === f.computed.from)?.type === "rich_text" ? [] : [modelProblemText("computed_from_not_body", {
|
|
577
|
-
collection,
|
|
578
|
-
field: f.key,
|
|
579
|
-
from: f.computed.from
|
|
580
|
-
})], ...COMPUTED_TYPES[f.computed.kind]?.(f) ? [] : [modelProblemText("computed_type_mismatch", {
|
|
581
|
-
collection,
|
|
582
|
-
field: f.key,
|
|
583
|
-
kind: f.computed.kind,
|
|
584
|
-
type: f.type
|
|
585
|
-
})]], ...inner];
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
/** 役割の宣言の誤り(最上位にない key・役割が受け付けない項目) */
|
|
589
|
-
const roleProblems = (collection, roles, fields) => Object.entries(roles).flatMap(([role, key]) => {
|
|
590
|
-
const f = fields.find((g) => g.key === key);
|
|
591
|
-
if (!f) return [modelProblemText("role_field_not_top", {
|
|
592
|
-
collection,
|
|
593
|
-
role,
|
|
594
|
-
field: String(key)
|
|
595
|
-
})];
|
|
596
|
-
return acceptsRole(role, f) ? [] : [modelProblemText("role_field_mismatch", {
|
|
597
|
-
collection,
|
|
598
|
-
role,
|
|
599
|
-
field: f.key,
|
|
600
|
-
type: f.type
|
|
601
|
-
})];
|
|
602
|
-
});
|
|
603
|
-
/** 見える範囲の宣言の誤り(顧客フィールドは本人かスタッフ、本人の項目は本人の印を持つコレクション、まとまりの中は外側と同じかスタッフ、要る権利は配信する参照) */
|
|
604
|
-
function audienceProblems(collection, fields, grant) {
|
|
605
|
-
const hasSelf = fields.some((f) => f.type === "customer" && f.self);
|
|
606
|
-
const nested = (fs, path, outer) => fs.flatMap((f) => {
|
|
607
|
-
const own = f.audience ?? outer;
|
|
608
|
-
return [...own !== outer && own !== "staff" ? [modelProblemText("audience_nested_wider", {
|
|
609
|
-
collection,
|
|
610
|
-
field: `${path}${f.key}`
|
|
611
|
-
})] : [], ...nested(f.fields ?? [], `${path}${f.key}.`, own)];
|
|
612
|
-
});
|
|
613
|
-
const own = fields.flatMap((f) => [...f.type === "customer" && f.audience !== "self" && f.audience !== "staff" ? [modelProblemText("audience_customer_field", {
|
|
614
|
-
collection,
|
|
615
|
-
field: f.key
|
|
616
|
-
})] : [], ...nested(f.fields ?? [], `${f.key}.`, f.audience ?? "public")]);
|
|
617
|
-
const anySelf = (fs) => fs.some((f) => f.audience === "self" || anySelf(f.fields ?? []));
|
|
618
|
-
const self = !hasSelf && anySelf(fields) ? [modelProblemText("audience_self_without_marker", { collection })] : [];
|
|
619
|
-
if (grant === void 0) return [...own, ...self];
|
|
620
|
-
const ref = fields.find((f) => f.key === grant);
|
|
621
|
-
return [
|
|
622
|
-
...own,
|
|
623
|
-
...self,
|
|
624
|
-
...ref?.type === "reference" && (ref.audience === "public" || ref.audience === "granted") ? [] : [modelProblemText("grant_not_reference", {
|
|
625
|
-
collection,
|
|
626
|
-
grant
|
|
627
|
-
})]
|
|
628
|
-
];
|
|
629
|
-
}
|
|
630
|
-
/** 元の見える範囲 source が作る値の見える範囲 target より狭いか(読み替えたコレクション、宣言なしは公開) */
|
|
631
|
-
const narrowerThan = (source, target) => {
|
|
632
|
-
const a = source ?? "public";
|
|
633
|
-
const b = target ?? "public";
|
|
634
|
-
return a !== b && narrower(a, b) === a;
|
|
635
|
-
};
|
|
636
|
-
/** 雛形の {key} の key */
|
|
637
|
-
const placeholdersOf = (template) => [...template.matchAll(/\{([A-Za-z0-9_-]+)\}/g)].map((m) => m[1]);
|
|
638
|
-
/**
|
|
639
|
-
* 値から作る値の見える範囲の誤り(読み替えたコレクション、作る値は元より広くできない)
|
|
640
|
-
* - 計算の項目 computed の元、決まる値 derive の元、条件 when の元(条件に合わない値は保存で空になる): 作る項目より狭い元は不可
|
|
641
|
-
* - ページの雛形 pages.path と OG の雛形 og の {key}: 最上位の公開の項目(slug と被参照の件数は可)。{id} は不可(UUID の URL になる)
|
|
642
|
-
*/
|
|
643
|
-
function derivedAudienceProblems(t) {
|
|
644
|
-
const byKey = new Map(t.fields.map((f) => [f.key, f]));
|
|
645
|
-
const narrowerSource = (f, from, source) => narrowerThan(byKey.get(from)?.audience, f.audience) && byKey.has(from) ? [modelProblemText("audience_wider_than_source", {
|
|
646
|
-
collection: t.slug,
|
|
647
|
-
field: f.key,
|
|
648
|
-
source,
|
|
649
|
-
from
|
|
650
|
-
})] : [];
|
|
651
|
-
const own = t.fields.flatMap((f) => [
|
|
652
|
-
...f.computed ? narrowerSource(f, f.computed.from, "computed") : [],
|
|
653
|
-
...f.derive ? narrowerSource(f, f.derive.from, "derive") : [],
|
|
654
|
-
...f.when ? narrowerSource(f, f.when.key, "when") : []
|
|
655
|
-
]);
|
|
656
|
-
const allowed = /* @__PURE__ */ new Set(["slug", ...(t.counts ?? []).map((c) => c.key)]);
|
|
657
|
-
const templates = [...(t.pages ?? []).map((p) => p.path), ...t.og ? [t.og] : []];
|
|
658
|
-
const ids = templates.filter((tpl) => placeholdersOf(tpl).includes("id")).map((tpl) => modelProblemText("template_id_placeholder", {
|
|
659
|
-
collection: t.slug,
|
|
660
|
-
template: tpl
|
|
661
|
-
}));
|
|
662
|
-
const paths = templates.flatMap((tpl) => placeholdersOf(tpl).filter((k) => k !== "id" && !allowed.has(k) && (byKey.get(k)?.audience ?? "public") !== "public").map((k) => modelProblemText("template_private_placeholder", {
|
|
663
|
-
collection: t.slug,
|
|
664
|
-
template: tpl,
|
|
665
|
-
key: k
|
|
666
|
-
})));
|
|
667
|
-
return [
|
|
668
|
-
...own,
|
|
669
|
-
...ids,
|
|
670
|
-
...paths
|
|
671
|
-
];
|
|
672
|
-
}
|
|
673
|
-
/** 参照先で固定 fixedBy と被参照の件数 counts の見える範囲の誤り(固定の元は固定する項目より狭くできない、件数は元のコレクションの公開の参照だけ) */
|
|
674
|
-
function crossCollectionAudienceProblems(collections) {
|
|
675
|
-
const fixed = collections.flatMap((t) => t.fields.flatMap((f) => {
|
|
676
|
-
if (!f.fixedBy) return [];
|
|
677
|
-
const ref = t.fields.find((g) => g.key === f.fixedBy.ref);
|
|
678
|
-
return [ref, ref?.to ? collections.find((x) => x.id === ref.to)?.fields.find((g) => g.key === f.fixedBy.key) : void 0].some((src) => src && narrowerThan(src.audience, f.audience)) ? [modelProblemText("fixed_by_wider", {
|
|
679
|
-
collection: t.slug,
|
|
680
|
-
field: f.key
|
|
681
|
-
})] : [];
|
|
682
|
-
}));
|
|
683
|
-
const counts = collections.flatMap((t) => (t.counts ?? []).flatMap((c) => {
|
|
684
|
-
const ref = collections.find((x) => x.id === c.from)?.fields.find((g) => g.key === c.field);
|
|
685
|
-
return ref && (ref.audience ?? "public") !== "public" ? [modelProblemText("count_reference_private", {
|
|
686
|
-
collection: t.slug,
|
|
687
|
-
key: c.key,
|
|
688
|
-
fromCollection: collections.find((x) => x.id === c.from)?.slug ?? c.from,
|
|
689
|
-
field: c.field
|
|
690
|
-
})] : [];
|
|
691
|
-
}));
|
|
692
|
-
return [...fixed, ...counts];
|
|
693
|
-
}
|
|
694
|
-
/** 顧客フィールドの誤り(まとまりの中に置かない) */
|
|
695
|
-
function customerFieldProblems(collection, fields) {
|
|
696
|
-
const nested = (fs, path) => fs.flatMap((f) => [...f.type === "customer" ? [modelProblemText("customer_field_nested", {
|
|
697
|
-
collection,
|
|
698
|
-
field: `${path}${f.key}`
|
|
699
|
-
})] : [], ...nested(f.fields ?? [], `${path}${f.key}.`)]);
|
|
700
|
-
return fields.flatMap((f) => nested(f.fields ?? [], `${f.key}.`));
|
|
701
|
-
}
|
|
702
|
-
/** anonymize で空にできない項目の種類(本文・まとまり・結び付き) */
|
|
703
|
-
const UNCLEARABLE = /* @__PURE__ */ new Set([
|
|
704
|
-
"rich_text",
|
|
705
|
-
"group",
|
|
706
|
-
"customer",
|
|
707
|
-
"reference"
|
|
708
|
-
]);
|
|
709
|
-
const isRequired = (f) => f.required !== void 0 && f.required !== false;
|
|
710
|
-
/** 指す先が消えたときの扱いのコレクションの中の誤り(必須の項目の clear・anonymize、anonymize の項目、まとまりの中の宣言) */
|
|
711
|
-
function onDeleteProblems(collection, fields) {
|
|
712
|
-
const nested = (fs, path) => fs.flatMap((f) => [...f.onDelete !== void 0 || f.anonymize ? [modelProblemText("on_delete_nested", {
|
|
713
|
-
collection,
|
|
714
|
-
field: `${path}${f.key}`
|
|
715
|
-
})] : [], ...nested(f.fields ?? [], `${path}${f.key}.`)]);
|
|
716
|
-
return fields.flatMap((f) => {
|
|
717
|
-
const inner = nested(f.fields ?? [], `${f.key}.`);
|
|
718
|
-
if (f.type !== "customer" && f.type !== "reference") return inner;
|
|
719
|
-
return [...[
|
|
720
|
-
...isRequired(f) && (f.onDelete === "clear" || f.onDelete === "anonymize") ? [modelProblemText("on_delete_required", {
|
|
721
|
-
collection,
|
|
722
|
-
field: f.key,
|
|
723
|
-
onDelete: f.onDelete
|
|
724
|
-
})] : [],
|
|
725
|
-
...(f.minItems ?? 0) > 0 && (f.onDelete === "clear" || f.onDelete === "anonymize") ? [modelProblemText("on_delete_min_items", {
|
|
726
|
-
collection,
|
|
727
|
-
field: f.key,
|
|
728
|
-
onDelete: f.onDelete
|
|
729
|
-
})] : [],
|
|
730
|
-
...f.anonymize && f.onDelete !== "anonymize" ? [modelProblemText("anonymize_without_on_delete", {
|
|
731
|
-
collection,
|
|
732
|
-
field: f.key
|
|
733
|
-
})] : [],
|
|
734
|
-
...(f.anonymize ?? []).flatMap((k) => {
|
|
735
|
-
const g = fields.find((x) => x.key === k);
|
|
736
|
-
if (!g) return [modelProblemText("anonymize_field_missing", {
|
|
737
|
-
collection,
|
|
738
|
-
field: f.key,
|
|
739
|
-
target: k
|
|
740
|
-
})];
|
|
741
|
-
if (UNCLEARABLE.has(g.type) || g.computed) return [modelProblemText("anonymize_field_unclearable", {
|
|
742
|
-
collection,
|
|
743
|
-
field: f.key,
|
|
744
|
-
target: k,
|
|
745
|
-
type: g.type
|
|
746
|
-
})];
|
|
747
|
-
return isRequired(g) ? [modelProblemText("anonymize_field_required", {
|
|
748
|
-
collection,
|
|
749
|
-
field: f.key,
|
|
750
|
-
target: k
|
|
751
|
-
})] : [];
|
|
752
|
-
})
|
|
753
|
-
], ...inner];
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
/** cascade の循環、人からの深さ、参照の cascade でたどるコレクションの本人の顧客フィールドの誤り */
|
|
757
|
-
function cascadeProblems(collections) {
|
|
758
|
-
const holders = (to) => collections.filter((collection) => cascadeTargetsOf(collection).includes(to));
|
|
759
|
-
const cycleFrom = (start) => {
|
|
760
|
-
const walk = (id, path) => {
|
|
761
|
-
for (const h of holders(id)) {
|
|
762
|
-
if (h.id === start) return [...path, h.id];
|
|
763
|
-
if (path.includes(h.id)) continue;
|
|
764
|
-
const found = walk(h.id, [...path, h.id]);
|
|
765
|
-
if (found) return found;
|
|
766
|
-
}
|
|
767
|
-
return null;
|
|
768
|
-
};
|
|
769
|
-
return walk(start, [start]);
|
|
770
|
-
};
|
|
771
|
-
const cyclic = /* @__PURE__ */ new Set();
|
|
772
|
-
const problems = [];
|
|
773
|
-
for (const collection of collections) {
|
|
774
|
-
const found = cyclic.has(collection.id) ? null : cycleFrom(collection.id);
|
|
775
|
-
if (!found) continue;
|
|
776
|
-
found.forEach((id) => cyclic.add(id));
|
|
777
|
-
problems.push(modelProblemText("cascade_cycle", { cycle: found.map((id) => collections.find((c) => c.id === id)?.slug ?? id).join(" → ") }));
|
|
778
|
-
}
|
|
779
|
-
if (problems.length) return problems;
|
|
780
|
-
const depth = cascadeDepths(collections);
|
|
781
|
-
const tooDeep = [...depth].filter(([, d]) => d > 4).map(([id, d]) => modelProblemText("cascade_too_deep", {
|
|
782
|
-
collection: collections.find((c) => c.id === id)?.slug ?? id,
|
|
783
|
-
depth: d,
|
|
784
|
-
max: 4
|
|
785
|
-
}));
|
|
786
|
-
const self = collections.filter((collection) => cascadeTargetsOf(collection).some((to) => depth.has(to))).flatMap((collection) => collection.fields.filter((f) => f.type === "customer" && f.self).map((f) => modelProblemText("cascade_self_customer", {
|
|
787
|
-
collection: collection.slug,
|
|
788
|
-
field: f.key
|
|
789
|
-
})));
|
|
790
|
-
return [...tooDeep, ...self];
|
|
791
|
-
}
|
|
792
|
-
/** 人から cascade でたどれるコレクションを restrict で指す参照の項目の誤り(undeclared は宣言のない参照も拒む) */
|
|
793
|
-
function restrictProblems(collections, undeclared) {
|
|
794
|
-
const reachable = cascadeDepths(collections);
|
|
795
|
-
const walk = (collectionId, fields, path) => fields.flatMap((f) => {
|
|
796
|
-
if (f.type === "group") return walk(collectionId, f.fields ?? [], `${path}${f.key}.`);
|
|
797
|
-
if (f.type !== "reference" || !f.to || !reachable.has(f.to)) return [];
|
|
798
|
-
if (f.onDelete === "restrict") return [modelProblemText("restrict_reachable", {
|
|
799
|
-
collection: collectionId,
|
|
800
|
-
field: `${path}${f.key}`,
|
|
801
|
-
to: f.to
|
|
802
|
-
})];
|
|
803
|
-
if (undeclared && f.onDelete === void 0) return [modelProblemText("on_delete_undeclared_reference", {
|
|
804
|
-
collection: collectionId,
|
|
805
|
-
field: `${path}${f.key}`,
|
|
806
|
-
to: f.to,
|
|
807
|
-
nested: path ? "yes" : "no"
|
|
808
|
-
})];
|
|
809
|
-
return [];
|
|
810
|
-
});
|
|
811
|
-
return collections.flatMap((t) => walk(t.id, t.fields, ""));
|
|
812
|
-
}
|
|
813
|
-
/** 非公開のコレクションの宣言の誤り(配信に関わる宣言と同時に付けない) */
|
|
814
|
-
function privateProblems(t) {
|
|
815
|
-
const collection = t.slug;
|
|
816
|
-
return [
|
|
817
|
-
...t.format === "object" ? [modelProblemText("private_object", { collection })] : [],
|
|
818
|
-
...(t.publishing ?? "none") !== "none" ? [modelProblemText("private_publishing", { collection })] : [],
|
|
819
|
-
...t.pages?.length ? [modelProblemText("private_pages", { collection })] : [],
|
|
820
|
-
...t.grant !== void 0 ? [modelProblemText("private_grant", { collection })] : []
|
|
821
|
-
];
|
|
822
|
-
}
|
|
823
|
-
/** 本文の項目が使用する部品の名前(まとまりの中も、key は項目の key) */
|
|
824
|
-
const bodyComponents = (fields) => fields.flatMap((f) => f.type === "rich_text" ? f.profile.components.map((name) => ({
|
|
825
|
-
key: f.key,
|
|
826
|
-
name
|
|
827
|
-
})) : bodyComponents(f.fields ?? []));
|
|
828
|
-
/** 参照の項目の参照先(まとまりの中も) */
|
|
829
|
-
const referenceTargets = (fields) => fields.flatMap((f) => f.type === "reference" ? [f.to] : referenceTargets(f.fields ?? []));
|
|
830
|
-
const contentType = z.object({
|
|
831
|
-
id: z.string().min(1),
|
|
832
|
-
slug: key,
|
|
833
|
-
label: z.string().min(1),
|
|
834
|
-
description: z.string().optional(),
|
|
835
|
-
format: z.enum(["list", "object"]).optional(),
|
|
836
|
-
publishing: z.enum([
|
|
837
|
-
"none",
|
|
838
|
-
"draft",
|
|
839
|
-
"review"
|
|
840
|
-
]).optional(),
|
|
841
|
-
fields: z.array(field),
|
|
842
|
-
pages: z.array(page).optional(),
|
|
843
|
-
counts: z.array(z.object({
|
|
844
|
-
key: fieldKey,
|
|
845
|
-
from: z.string().min(1),
|
|
846
|
-
field: fieldKey
|
|
847
|
-
})).optional(),
|
|
848
|
-
og: z.string().startsWith("/", modelProblemText("og_path_slash")).optional(),
|
|
849
|
-
slugMode: z.enum(SLUG_MODES).optional(),
|
|
850
|
-
roles: z.partialRecord(z.enum(FIELD_ROLES), fieldKey).optional(),
|
|
851
|
-
grant: fieldKey.optional(),
|
|
852
|
-
entitlement: z.never({ message: modelProblemText("entitlement_renamed") }).optional(),
|
|
853
|
-
private: z.boolean().optional(),
|
|
854
|
-
unique: z.array(z.object({
|
|
855
|
-
key: fieldKey,
|
|
856
|
-
fields: z.array(fieldKey),
|
|
857
|
-
exact: z.boolean().optional()
|
|
858
|
-
})).optional(),
|
|
859
|
-
selfOps: z.array(z.enum(SELF_OPS)).optional(),
|
|
860
|
-
retentionDays: z.number().int().positive().max(RETENTION_DAYS_MAX).optional()
|
|
861
|
-
}).refine((t) => new Set(t.fields.map((f) => f.key)).size === t.fields.length, { message: modelProblemText("duplicate_field_key") }).refine((t) => conditionsValid(t.fields), { message: modelProblemText("condition_invalid") }).refine((t) => (t.pages ?? []).every((p) => conditionValid(p.when, t.fields)), { message: modelProblemText("page_condition_invalid") }).superRefine((t, ctx) => {
|
|
862
|
-
const fields = t.fields;
|
|
863
|
-
const asCollection = t;
|
|
864
|
-
for (const k of reservedKeysOf(t)) ctx.addIssue({
|
|
865
|
-
code: "custom",
|
|
866
|
-
message: modelProblemText("reserved_key", {
|
|
867
|
-
collection: t.slug,
|
|
868
|
-
key: k
|
|
869
|
-
})
|
|
870
|
-
});
|
|
871
|
-
for (const f of fields) if (RESERVED_QUERY.includes(f.key)) ctx.addIssue({
|
|
872
|
-
code: "custom",
|
|
873
|
-
message: modelProblemText("reserved_query_key", {
|
|
874
|
-
collection: t.slug,
|
|
875
|
-
key: f.key
|
|
876
|
-
})
|
|
877
|
-
});
|
|
878
|
-
for (const k of nestedRules(fields)) ctx.addIssue({
|
|
879
|
-
code: "custom",
|
|
880
|
-
message: modelProblemText("nested_rule", {
|
|
881
|
-
collection: t.slug,
|
|
882
|
-
field: k
|
|
883
|
-
})
|
|
884
|
-
});
|
|
885
|
-
for (const m of roleProblems(t.slug, t.roles ?? {}, t.fields)) ctx.addIssue({
|
|
886
|
-
code: "custom",
|
|
887
|
-
message: m,
|
|
888
|
-
path: ["roles"]
|
|
889
|
-
});
|
|
890
|
-
const problems = [
|
|
891
|
-
...computedProblems(t.slug, fields),
|
|
892
|
-
...audienceProblems(t.slug, fields, t.grant),
|
|
893
|
-
...derivedAudienceProblems({
|
|
894
|
-
...t,
|
|
895
|
-
fields
|
|
896
|
-
}),
|
|
897
|
-
...customerFieldProblems(t.slug, fields),
|
|
898
|
-
...integrityProblems(asCollection),
|
|
899
|
-
...transitionProblems(asCollection),
|
|
900
|
-
...onDeleteProblems(t.slug, fields),
|
|
901
|
-
...selfOpsProblems(asCollection),
|
|
902
|
-
...selfWritableProblems(asCollection)
|
|
903
|
-
];
|
|
904
|
-
for (const m of problems) ctx.addIssue({
|
|
905
|
-
code: "custom",
|
|
906
|
-
message: m
|
|
907
|
-
});
|
|
908
|
-
if (t.private) for (const m of privateProblems(t)) ctx.addIssue({
|
|
909
|
-
code: "custom",
|
|
910
|
-
message: m,
|
|
911
|
-
path: ["private"]
|
|
912
|
-
});
|
|
913
|
-
});
|
|
914
|
-
z.object({
|
|
915
|
-
components: declaredComponentsSchema.optional(),
|
|
916
|
-
collections: z.array(contentType).refine((ts) => new Set(ts.map((t) => t.id)).size === ts.length, { message: modelProblemText("duplicate_collection_id") }).refine((ts) => new Set(ts.map((t) => t.slug)).size === ts.length, { message: modelProblemText("duplicate_collection_slug") }).superRefine((ts, ctx) => {
|
|
917
|
-
const ids = new Set(ts.map((t) => t.id));
|
|
918
|
-
for (const t of ts) for (const to of referenceTargets(t.fields)) if (!ids.has(to)) ctx.addIssue({
|
|
919
|
-
code: "custom",
|
|
920
|
-
message: modelProblemText("reference_target_missing", {
|
|
921
|
-
collection: t.slug,
|
|
922
|
-
to
|
|
923
|
-
})
|
|
924
|
-
});
|
|
925
|
-
for (const t of ts) {
|
|
926
|
-
const keys = new Set(t.fields.map((f) => f.key));
|
|
927
|
-
for (const c of t.counts ?? []) {
|
|
928
|
-
const from = ts.find((x) => x.id === c.from);
|
|
929
|
-
const ref = from && from.fields.find((f) => f.key === c.field);
|
|
930
|
-
if (ref?.type !== "reference" || ref.to !== t.id) ctx.addIssue({
|
|
931
|
-
code: "custom",
|
|
932
|
-
message: modelProblemText("count_reference_mismatch", {
|
|
933
|
-
collection: t.slug,
|
|
934
|
-
key: c.key,
|
|
935
|
-
fromCollection: from?.slug ?? c.from,
|
|
936
|
-
field: c.field
|
|
937
|
-
})
|
|
938
|
-
});
|
|
939
|
-
if (keys.has(c.key)) ctx.addIssue({
|
|
940
|
-
code: "custom",
|
|
941
|
-
message: modelProblemText("count_key_duplicate", {
|
|
942
|
-
collection: t.slug,
|
|
943
|
-
key: c.key
|
|
944
|
-
})
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
const parsed = ts.map((t) => ({
|
|
949
|
-
id: t.id,
|
|
950
|
-
slug: t.slug,
|
|
951
|
-
fields: t.fields
|
|
952
|
-
}));
|
|
953
|
-
for (const m of crossCollectionAudienceProblems(ts.map((t) => ({
|
|
954
|
-
id: t.id,
|
|
955
|
-
slug: t.slug,
|
|
956
|
-
fields: t.fields,
|
|
957
|
-
counts: t.counts
|
|
958
|
-
})))) ctx.addIssue({
|
|
959
|
-
code: "custom",
|
|
960
|
-
message: m
|
|
961
|
-
});
|
|
962
|
-
const cascade = cascadeProblems(parsed);
|
|
963
|
-
for (const m of cascade) ctx.addIssue({
|
|
964
|
-
code: "custom",
|
|
965
|
-
message: m
|
|
966
|
-
});
|
|
967
|
-
if (!cascade.length) for (const m of restrictProblems(parsed, false)) ctx.addIssue({
|
|
968
|
-
code: "custom",
|
|
969
|
-
message: m
|
|
970
|
-
});
|
|
971
|
-
})
|
|
972
|
-
}).superRefine((m, ctx) => {
|
|
973
|
-
const known = /* @__PURE__ */ new Set([...CORE_COMPONENTS.map((c) => c.name), ...(m.components ?? []).map((c) => c.name)]);
|
|
974
|
-
for (const t of m.collections) for (const { key, name } of bodyComponents(t.fields)) if (!known.has(name)) ctx.addIssue({
|
|
975
|
-
code: "custom",
|
|
976
|
-
message: modelProblemText("component_unknown", {
|
|
977
|
-
collection: t.slug,
|
|
978
|
-
field: key,
|
|
979
|
-
name
|
|
980
|
-
})
|
|
981
|
-
});
|
|
982
|
-
});
|
|
983
|
-
/** コレクションの一覧として読めるか(コレクションごとに id・スラッグと項目の配列) */
|
|
984
|
-
const readable = (json) => isRecord$1(json) && Array.isArray(json.collections) && json.collections.every((t) => isRecord$1(t) && typeof t.id === "string" && typeof t.slug === "string" && Array.isArray(t.fields) && t.fields.every(isRecord$1));
|
|
985
|
-
/**
|
|
986
|
-
* 保存した版とファイルの読み込み(寛容: 旧い語を今の名前にした値をそのまま返し、規則で拒まない、既定を書き込まない)
|
|
987
|
-
* - コレクションの一覧として読めない値だけ例外(壊れた版)
|
|
988
|
-
* - 見える範囲などの読み替えは audienceOf と resolvedModel(保存の形には書き戻さない)
|
|
989
|
-
*/
|
|
990
|
-
function parseModel(json) {
|
|
991
|
-
const normalized = normalizeLegacyModel(json);
|
|
992
|
-
if (!readable(normalized)) throw new Error("model_unreadable");
|
|
993
|
-
return normalized;
|
|
994
|
-
}
|
|
995
|
-
export { modelProblemText as i, fieldDefSchema as n, parseModel as r, RESERVED_FIELD_KEYS as t };
|