@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
|
@@ -0,0 +1,1267 @@
|
|
|
1
|
+
import { i as CORE_COMPONENTS, t as declaredComponentsSchema } from "./declared-CE4a61qb.js";
|
|
2
|
+
import { f as problemText, l as problemFactory } from "./ja-axQPxMJ-.js";
|
|
3
|
+
import { n as SCHEMA_PROBLEM_MESSAGES } from "./ja-CrY_72Tn.js";
|
|
4
|
+
import { A as isUuidShape, C as isListCollection, D as isSingleton, E as isSequenceField, L as isFilesCollection, S as isInputField, a as PII_CLASSES, c as STATUS_CATEGORIES, d as cascadeDepths, f as cascadeTargetsOf, g as endUserFieldsOf, h as declaredAudienceOf, i as ON_DELETE, j as narrower, k as isSurveyShape, l as acceptsRole, n as END_USER_FIELD_TYPE, o as SELF_OPS, r as FIELD_ROLES, s as SLUG_MODES, t as AUDIENCES, u as audienceOf, v as hasPublication, y as initialValueOf } from "./collection-nUz1RetA.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
// ../schema/src/problems.ts
|
|
7
|
+
/** コンテンツスキーマの検査の問題を作る */
|
|
8
|
+
const schemaProblem = problemFactory(SCHEMA_PROBLEM_MESSAGES);
|
|
9
|
+
/** 問題の英語の既定の文(zod の message と検査の issues の message に入れ、problemOf で戻す) */
|
|
10
|
+
const schemaProblemText = (code, ...params) => problemText(schemaProblem(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
|
+
// ../schema/src/check.ts
|
|
21
|
+
/** 配列でないオブジェクトか */
|
|
22
|
+
const isRecord = (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
|
+
"status",
|
|
34
|
+
"reference",
|
|
35
|
+
"date",
|
|
36
|
+
"datetime",
|
|
37
|
+
END_USER_FIELD_TYPE
|
|
38
|
+
].includes(f.type);
|
|
39
|
+
}
|
|
40
|
+
/** コレクションの一意の組(宣言 unique と、unique を付けたエンドユーザーへの参照のフィールドと、連番の項目) */
|
|
41
|
+
const uniqueDefsOf = (collection) => [...collection.unique ?? [], ...collection.fields.flatMap((f) => f.type === "end_user" && f.unique || isSequenceField(f) ? [{
|
|
42
|
+
key: f.key,
|
|
43
|
+
fields: [f.key],
|
|
44
|
+
exact: true
|
|
45
|
+
}] : [])];
|
|
46
|
+
/** コレクションの整合の宣言の誤り(スキーマの検査、schema.ts) */
|
|
47
|
+
function integrityProblems(collection) {
|
|
48
|
+
const id = collection.slug;
|
|
49
|
+
const problems = [];
|
|
50
|
+
const defs = uniqueDefsOf(collection);
|
|
51
|
+
if (collection.unique?.length && !isListCollection(collection)) problems.push(schemaProblemText("unique_list_only", { collection: id }));
|
|
52
|
+
const names = defs.map((d) => d.key);
|
|
53
|
+
for (const n of new Set(names)) if (names.filter((x) => x === n).length > 1) problems.push(schemaProblemText("unique_name_duplicate", {
|
|
54
|
+
collection: id,
|
|
55
|
+
key: n
|
|
56
|
+
}));
|
|
57
|
+
for (const d of collection.unique ?? []) {
|
|
58
|
+
if (!d.fields.length || d.fields.length > 3) problems.push(schemaProblemText("unique_field_count", {
|
|
59
|
+
collection: id,
|
|
60
|
+
key: d.key,
|
|
61
|
+
max: 3
|
|
62
|
+
}));
|
|
63
|
+
if (new Set(d.fields).size !== d.fields.length) problems.push(schemaProblemText("unique_field_duplicate", {
|
|
64
|
+
collection: id,
|
|
65
|
+
key: d.key
|
|
66
|
+
}));
|
|
67
|
+
for (const key of d.fields) {
|
|
68
|
+
const f = collection.fields.find((x) => x.key === key);
|
|
69
|
+
if (!f) problems.push(schemaProblemText("unique_field_not_top", {
|
|
70
|
+
collection: id,
|
|
71
|
+
key: d.key,
|
|
72
|
+
field: key
|
|
73
|
+
}));
|
|
74
|
+
else if (!acceptsUnique(f)) problems.push(schemaProblemText("unique_field_unsupported", {
|
|
75
|
+
collection: id,
|
|
76
|
+
key: d.key,
|
|
77
|
+
field: key,
|
|
78
|
+
type: f.type
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const nested = (fields, path) => fields.flatMap((f) => [...isSequenceField(f) ? [schemaProblemText("sequence_nested", {
|
|
83
|
+
collection: id,
|
|
84
|
+
field: `${path}${f.key}`
|
|
85
|
+
})] : [], ...f.type === "object" ? nested(f.fields, `${path}${f.key}.`) : []]);
|
|
86
|
+
for (const f of collection.fields) {
|
|
87
|
+
if (f.type === "object") problems.push(...nested(f.fields, `${f.key}.`));
|
|
88
|
+
if (!isSequenceField(f)) continue;
|
|
89
|
+
if (!isListCollection(collection)) problems.push(schemaProblemText("sequence_list_only", {
|
|
90
|
+
collection: id,
|
|
91
|
+
field: f.key
|
|
92
|
+
}));
|
|
93
|
+
if (f.required || f.computed || f.when) problems.push(schemaProblemText("sequence_plain", {
|
|
94
|
+
collection: id,
|
|
95
|
+
field: f.key
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
return problems;
|
|
99
|
+
}
|
|
100
|
+
/** 遷移の宣言の誤り(スキーマの検査) */
|
|
101
|
+
function transitionProblems(collection) {
|
|
102
|
+
const id = collection.slug;
|
|
103
|
+
const nested = (fields, path) => fields.flatMap((f) => [...(f.type === "select" || f.type === "status") && f.transitions ? [schemaProblemText("transition_nested", {
|
|
104
|
+
collection: id,
|
|
105
|
+
field: `${path}${f.key}`
|
|
106
|
+
})] : [], ...f.type === "object" ? nested(f.fields, `${path}${f.key}.`) : []]);
|
|
107
|
+
return collection.fields.flatMap((f) => {
|
|
108
|
+
if (f.type === "object") return nested(f.fields, `${f.key}.`);
|
|
109
|
+
if (f.type !== "select" && f.type !== "status" || !f.transitions) return [];
|
|
110
|
+
const values = new Set(f.options.map((o) => o.value));
|
|
111
|
+
const problems = [];
|
|
112
|
+
if (f.type === "select" && (f.multiple || f.derive || f.fixed_by)) problems.push(schemaProblemText("transition_field_kind", {
|
|
113
|
+
collection: id,
|
|
114
|
+
field: f.key
|
|
115
|
+
}));
|
|
116
|
+
for (const [i, t] of f.transitions.entries()) {
|
|
117
|
+
const at = {
|
|
118
|
+
collection: id,
|
|
119
|
+
field: f.key,
|
|
120
|
+
index: i + 1
|
|
121
|
+
};
|
|
122
|
+
if (!values.has(t.to)) problems.push(schemaProblemText("transition_to_not_option", {
|
|
123
|
+
...at,
|
|
124
|
+
to: t.to
|
|
125
|
+
}));
|
|
126
|
+
if (!t.from.length) problems.push(schemaProblemText("transition_from_empty", at));
|
|
127
|
+
for (const v of t.from) if (v !== null && !values.has(v)) problems.push(schemaProblemText("transition_from_not_option", {
|
|
128
|
+
...at,
|
|
129
|
+
value: v
|
|
130
|
+
}));
|
|
131
|
+
if (t.by && !t.by.roles?.length && !t.by.self && !t.by.apps?.length) problems.push(schemaProblemText("transition_no_actor", at));
|
|
132
|
+
}
|
|
133
|
+
return problems;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
// ../schema/src/forms.ts
|
|
137
|
+
const FORM_SUBMITTERS = ["anyone", "end_user"];
|
|
138
|
+
const MANAGED_FIELDS = ["form_version", "form_handled_at"];
|
|
139
|
+
const MANAGED_TYPES = {
|
|
140
|
+
form_version: "text",
|
|
141
|
+
form_handled_at: "datetime"
|
|
142
|
+
};
|
|
143
|
+
const managedFieldOf = (collection, managed) => collection.fields.find((f) => f.managed === managed);
|
|
144
|
+
/** 送信者が書けるフィールドの種類か(1つの値の文字、連絡先、選択肢) */
|
|
145
|
+
function isFormInputField(f) {
|
|
146
|
+
if (!isInputField(f) || f.admin_only || f.when) return false;
|
|
147
|
+
if (f.type === "text" || f.type === "long_text") return !f.multiple;
|
|
148
|
+
if (f.type === "email" || f.type === "phone" || f.type === "url") return true;
|
|
149
|
+
return f.type === "select" && !f.derive && !f.fixed_by;
|
|
150
|
+
}
|
|
151
|
+
/** 送信者が書けるフィールドの key */
|
|
152
|
+
const formFieldKeysOf = (collection) => (collection.form?.fields ?? []).map((f) => f.key);
|
|
153
|
+
/** ID トークンの本人の送信を受けるフォームで、本人を入れるフィールド(ほかは null) */
|
|
154
|
+
const formOwnerOf = (collection) => collection.form?.submitter === "end_user" ? endUserFieldsOf(collection)[0] ?? null : null;
|
|
155
|
+
const HOST = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/;
|
|
156
|
+
/** まとまりの中のフィールド(path は key をドットで連結) */
|
|
157
|
+
const nestedFields = (fields, path = "") => fields.flatMap((f) => f.type === "object" ? f.fields.flatMap((c) => [{
|
|
158
|
+
path: `${path}${f.key}.${c.key}`,
|
|
159
|
+
field: c
|
|
160
|
+
}, ...nestedFields([c], `${path}${f.key}.`)]) : []);
|
|
161
|
+
/** 印 managed の誤り(最上位だけ、印ごとに種類が決まり1つだけ、対応するフォームの宣言が要る) */
|
|
162
|
+
function managedProblems(collection) {
|
|
163
|
+
const { form } = collection;
|
|
164
|
+
const at = collection.slug;
|
|
165
|
+
const nested = nestedFields(collection.fields).flatMap(({ path, field }) => field.managed ? [schemaProblemText("form_managed_nested", {
|
|
166
|
+
collection: at,
|
|
167
|
+
field: path
|
|
168
|
+
})] : []);
|
|
169
|
+
const declared = {
|
|
170
|
+
form_version: form?.submitter === "end_user",
|
|
171
|
+
form_handled_at: form?.handled !== void 0
|
|
172
|
+
};
|
|
173
|
+
const top = collection.fields.flatMap((f) => {
|
|
174
|
+
if (!f.managed) return [];
|
|
175
|
+
return [
|
|
176
|
+
...f.type === MANAGED_TYPES[f.managed] && !("multiple" in f && f.multiple) && !f.required && !f.when && !f.computed && !f.pending_until ? [] : [schemaProblemText("form_managed_shape", {
|
|
177
|
+
collection: at,
|
|
178
|
+
field: f.key,
|
|
179
|
+
managed: f.managed,
|
|
180
|
+
type: MANAGED_TYPES[f.managed]
|
|
181
|
+
})],
|
|
182
|
+
...declared[f.managed] ? [] : [schemaProblemText("form_managed_undeclared", {
|
|
183
|
+
collection: at,
|
|
184
|
+
field: f.key,
|
|
185
|
+
managed: f.managed
|
|
186
|
+
})],
|
|
187
|
+
...managedFieldOf(collection, f.managed) === f ? [] : [schemaProblemText("form_managed_duplicate", {
|
|
188
|
+
collection: at,
|
|
189
|
+
field: f.key,
|
|
190
|
+
managed: f.managed
|
|
191
|
+
})]
|
|
192
|
+
];
|
|
193
|
+
});
|
|
194
|
+
return [...nested, ...top];
|
|
195
|
+
}
|
|
196
|
+
function handledProblems(collection, handled) {
|
|
197
|
+
const at = {
|
|
198
|
+
collection: collection.slug,
|
|
199
|
+
field: handled.field
|
|
200
|
+
};
|
|
201
|
+
const f = collection.fields.find((g) => g.key === handled.field);
|
|
202
|
+
if (f?.type !== "select" || f.multiple || !isInputField(f)) return [schemaProblemText("form_handled_field", at)];
|
|
203
|
+
return [
|
|
204
|
+
...handled.done.every((v) => f.options.some((o) => o.value === v)) && !handled.done.includes(initialValueOf(collection, f.key)) ? [] : [schemaProblemText("form_handled_done", at)],
|
|
205
|
+
...managedFieldOf(collection, "form_handled_at") ? [] : [schemaProblemText("form_handled_at_missing", at)],
|
|
206
|
+
...formFieldKeysOf(collection).includes(f.key) ? [schemaProblemText("form_handled_writable", at)] : []
|
|
207
|
+
];
|
|
208
|
+
}
|
|
209
|
+
function fieldProblems(collection, form) {
|
|
210
|
+
const keys = formFieldKeysOf(collection);
|
|
211
|
+
return form.fields.flatMap((d, i) => {
|
|
212
|
+
const at = {
|
|
213
|
+
collection: collection.slug,
|
|
214
|
+
field: d.key
|
|
215
|
+
};
|
|
216
|
+
const f = collection.fields.find((g) => g.key === d.key);
|
|
217
|
+
if (!f || !isFormInputField(f)) return [schemaProblemText("form_field_unsupported", at)];
|
|
218
|
+
const on = d.required_when && collection.fields.find((g) => g.key === d.required_when.key);
|
|
219
|
+
const conditional = !d.required_when || on?.type === "select" && d.required_when.key !== d.key && keys.includes(d.required_when.key) && d.required_when.in.every((v) => on.options.some((o) => o.value === v));
|
|
220
|
+
const hosts = [...d.hosts?.exact ?? [], ...d.hosts?.subdomains_of ?? []];
|
|
221
|
+
const hosted = !d.hosts || f.type === "url" && (d.hosts.site === true || hosts.length > 0) && hosts.every((h) => HOST.test(h));
|
|
222
|
+
return [
|
|
223
|
+
...keys.indexOf(d.key) === i ? [] : [schemaProblemText("form_field_duplicate", at)],
|
|
224
|
+
...conditional ? [] : [schemaProblemText("form_required_when", at)],
|
|
225
|
+
...hosted ? [] : [schemaProblemText("form_hosts", at)]
|
|
226
|
+
];
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/** フォームの宣言の誤り */
|
|
230
|
+
function formProblems(collection) {
|
|
231
|
+
const { form } = collection;
|
|
232
|
+
if (!form) return managedProblems(collection);
|
|
233
|
+
const at = { collection: collection.slug };
|
|
234
|
+
const keys = formFieldKeysOf(collection);
|
|
235
|
+
const decided = (f) => !isInputField(f) || f.key === form.handled?.field || f.key === formOwnerOf(collection)?.key;
|
|
236
|
+
const delivered = [...collection.fields, ...nestedFields(collection.fields).map((n) => n.field)].filter((f) => f.audience === "public" || f.audience === "entitled");
|
|
237
|
+
return [
|
|
238
|
+
...collection.private === true && isListCollection(collection) ? [] : [schemaProblemText("form_private_list_only", at)],
|
|
239
|
+
...collection.self_ops?.length ? [schemaProblemText("form_with_self_ops", at)] : [],
|
|
240
|
+
...delivered.map((f) => schemaProblemText("form_delivered_field", {
|
|
241
|
+
...at,
|
|
242
|
+
field: f.key
|
|
243
|
+
})),
|
|
244
|
+
...form.submitter === "end_user" && collection.fields.filter((f) => f.type === "end_user").length !== 1 ? [schemaProblemText("form_one_end_user", at)] : [],
|
|
245
|
+
...collection.fields.filter((f) => f.required === "save" && !keys.includes(f.key) && !decided(f)).map((f) => schemaProblemText("form_required_missing", {
|
|
246
|
+
...at,
|
|
247
|
+
field: f.key
|
|
248
|
+
})),
|
|
249
|
+
...fieldProblems(collection, form),
|
|
250
|
+
...form.handled ? handledProblems(collection, form.handled) : [],
|
|
251
|
+
...managedProblems(collection)
|
|
252
|
+
];
|
|
253
|
+
}
|
|
254
|
+
// ../schema/src/selfOps.ts
|
|
255
|
+
/** 本人のエンドユーザーへの参照のフィールドか(コレクションの最上位の項目) */
|
|
256
|
+
const isSelfField = (f, collection) => f.type === "end_user" && (f.self === true || f.self === void 0 && declaredAudienceOf(f) === void 0 && isSurveyShape(collection));
|
|
257
|
+
/** コレクションの本人のエンドユーザーへの参照のフィールド */
|
|
258
|
+
const selfFieldsOf = (collection) => collection.fields.filter((f) => isSelfField(f, collection));
|
|
259
|
+
/** 本人が書ける印を付けられない項目の理由(付けられれば null) */
|
|
260
|
+
function selfWritableBlock(f, collection) {
|
|
261
|
+
if (f.type === "end_user") return "end_user";
|
|
262
|
+
if (f.type === "object" || f.type === "file" || f.type === "rich_text") return f.type;
|
|
263
|
+
if (audienceOf(f, collection) === "none") return "staff";
|
|
264
|
+
if (f.admin_only) return "admin_only";
|
|
265
|
+
if (f.computed) return "computed";
|
|
266
|
+
if (isSequenceField(f)) return "sequence";
|
|
267
|
+
if (f.managed) return "managed";
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* 人の操作の宣言の誤り(配信しない一覧のコレクション、本人のエンドユーザーへの参照のフィールドがちょうど1つで on_delete は cascade か anonymize、
|
|
272
|
+
* 一意の組はすべて本人のエンドユーザーへの参照のフィールドを含む)
|
|
273
|
+
*/
|
|
274
|
+
function selfOpsProblems(collection) {
|
|
275
|
+
if (!collection.self_ops?.length) return [];
|
|
276
|
+
const self = selfFieldsOf(collection);
|
|
277
|
+
const at = { collection: collection.slug };
|
|
278
|
+
const problems = [];
|
|
279
|
+
if (collection.private !== true) problems.push(schemaProblemText("self_ops_private_only", at));
|
|
280
|
+
if (isSingleton(collection)) problems.push(schemaProblemText("self_ops_list_only", at));
|
|
281
|
+
if (collection.publication || collection.fields.some((f) => f.key === "published" && f.type === "boolean")) problems.push(schemaProblemText("self_ops_unpublished", at));
|
|
282
|
+
if (self.length !== 1) problems.push(schemaProblemText("self_ops_one_self", at));
|
|
283
|
+
const key = self.length === 1 ? self[0].key : null;
|
|
284
|
+
if (key && self[0].on_delete !== "cascade" && self[0].on_delete !== "anonymize") problems.push(schemaProblemText("self_ops_on_delete", {
|
|
285
|
+
...at,
|
|
286
|
+
field: key
|
|
287
|
+
}));
|
|
288
|
+
for (const d of uniqueDefsOf(collection)) if (key && !d.fields.includes(key)) problems.push(schemaProblemText("self_ops_unique", {
|
|
289
|
+
...at,
|
|
290
|
+
key: d.key,
|
|
291
|
+
field: key
|
|
292
|
+
}));
|
|
293
|
+
return problems;
|
|
294
|
+
}
|
|
295
|
+
/** 本人が書ける印の誤り(付けられない項目、まとまりの中、create_self か update_self を受けないコレクション) */
|
|
296
|
+
function selfWritableProblems(collection) {
|
|
297
|
+
const nested = (fields, path) => fields.flatMap((f) => [...f.self_writable !== void 0 ? [schemaProblemText("self_writable_nested", {
|
|
298
|
+
collection: collection.slug,
|
|
299
|
+
field: `${path}${f.key}`
|
|
300
|
+
})] : [], ...f.type === "object" ? nested(f.fields, `${path}${f.key}.`) : []]);
|
|
301
|
+
const writes = collection.self_ops?.some((op) => op === "create_self" || op === "update_self") ?? false;
|
|
302
|
+
return collection.fields.flatMap((f) => {
|
|
303
|
+
const inner = f.type === "object" ? nested(f.fields, `${f.key}.`) : [];
|
|
304
|
+
if (!f.self_writable) return inner;
|
|
305
|
+
const block = selfWritableBlock(f, collection);
|
|
306
|
+
return [
|
|
307
|
+
...block ? [schemaProblemText("self_writable_blocked", {
|
|
308
|
+
collection: collection.slug,
|
|
309
|
+
field: f.key,
|
|
310
|
+
block
|
|
311
|
+
})] : [],
|
|
312
|
+
...writes ? [] : [schemaProblemText("self_writable_without_ops", {
|
|
313
|
+
collection: collection.slug,
|
|
314
|
+
field: f.key
|
|
315
|
+
})],
|
|
316
|
+
...inner
|
|
317
|
+
];
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
// ../schema/src/kinds.ts
|
|
321
|
+
/** 宣言できる種類 */
|
|
322
|
+
const DECLARED_COLLECTION_KINDS = [
|
|
323
|
+
"standard",
|
|
324
|
+
"timeseries",
|
|
325
|
+
"aggregate"
|
|
326
|
+
];
|
|
327
|
+
/** 集計の時間の区切り */
|
|
328
|
+
const AGGREGATE_BUCKETS = [
|
|
329
|
+
"hour",
|
|
330
|
+
"day",
|
|
331
|
+
"month"
|
|
332
|
+
];
|
|
333
|
+
/** 集計の値の求め方 */
|
|
334
|
+
const AGGREGATE_OPS = [
|
|
335
|
+
"count",
|
|
336
|
+
"sum",
|
|
337
|
+
"min",
|
|
338
|
+
"max"
|
|
339
|
+
];
|
|
340
|
+
/** 集計の次元の数の上限 */
|
|
341
|
+
const AGGREGATE_LIMITS = { dimensionsMax: 8 };
|
|
342
|
+
/** 種類ごとの宣言の項目(コレクションの key) */
|
|
343
|
+
const KIND_DECLARATIONS = {
|
|
344
|
+
standard: [],
|
|
345
|
+
files: [],
|
|
346
|
+
timeseries: [
|
|
347
|
+
"time",
|
|
348
|
+
"dimensions",
|
|
349
|
+
"subject"
|
|
350
|
+
],
|
|
351
|
+
aggregate: [
|
|
352
|
+
"time",
|
|
353
|
+
"dimensions",
|
|
354
|
+
"source",
|
|
355
|
+
"bucket",
|
|
356
|
+
"measures"
|
|
357
|
+
]
|
|
358
|
+
};
|
|
359
|
+
/** 時系列と集計が持たない能力に頼る宣言 */
|
|
360
|
+
const UNSUPPORTED_DECLARATIONS = [
|
|
361
|
+
"trash",
|
|
362
|
+
"pages",
|
|
363
|
+
"counts",
|
|
364
|
+
"og",
|
|
365
|
+
"entitlement",
|
|
366
|
+
"self_ops",
|
|
367
|
+
"form",
|
|
368
|
+
"publish_checks"
|
|
369
|
+
];
|
|
370
|
+
const kindOf = (collection) => isFilesCollection(collection) ? "files" : collection.kind ?? "standard";
|
|
371
|
+
const isDeclared = (value) => value !== void 0 && value !== false && !(Array.isArray(value) && value.length === 0);
|
|
372
|
+
/**
|
|
373
|
+
* 個人情報を入れるフィールド: 分類の宣言が none 以外、宣言がなければ連絡先と本人への参照
|
|
374
|
+
* 既定の分類(defaultPiiOf)は文字の種類を広く identifier・freetext にするため、宣言のないフィールドは種類で見る
|
|
375
|
+
*/
|
|
376
|
+
const isPiiField = (f) => f.pii !== void 0 ? f.pii !== "none" : f.type === "email" || f.type === "phone" || f.type === "end_user";
|
|
377
|
+
const isTimeField = (f) => f?.type === "date" || f?.type === "datetime";
|
|
378
|
+
/** 種類の宣言の誤り(文) */
|
|
379
|
+
function kindProblems(collection) {
|
|
380
|
+
const kind = kindOf(collection);
|
|
381
|
+
const at = collection.slug;
|
|
382
|
+
const fieldOf = (key) => collection.fields.find((f) => f.key === key);
|
|
383
|
+
const own = KIND_DECLARATIONS[kind];
|
|
384
|
+
const problems = Object.values(KIND_DECLARATIONS).flat().filter((d, i, all) => all.indexOf(d) === i && !own.includes(d) && isDeclared(collection[d])).map((declaration) => schemaProblemText("kind_declaration_invalid", {
|
|
385
|
+
collection: at,
|
|
386
|
+
kind,
|
|
387
|
+
declaration
|
|
388
|
+
}));
|
|
389
|
+
if (kind === "standard" || kind === "files") return problems;
|
|
390
|
+
const unsupported = [
|
|
391
|
+
...hasPublication(collection) ? ["publication"] : [],
|
|
392
|
+
...collection.format === "object" ? ["format"] : [],
|
|
393
|
+
...UNSUPPORTED_DECLARATIONS.filter((d) => isDeclared(collection[d]))
|
|
394
|
+
];
|
|
395
|
+
problems.push(...unsupported.map((declaration) => schemaProblemText("kind_declaration_invalid", {
|
|
396
|
+
collection: at,
|
|
397
|
+
kind,
|
|
398
|
+
declaration
|
|
399
|
+
})));
|
|
400
|
+
const missing = (key) => problems.push(schemaProblemText("kind_field_missing", {
|
|
401
|
+
collection: at,
|
|
402
|
+
declaration: "dimensions",
|
|
403
|
+
field: key
|
|
404
|
+
}));
|
|
405
|
+
for (const key of collection.dimensions ?? []) if (!fieldOf(key)) missing(key);
|
|
406
|
+
if (collection.time !== void 0 && !isTimeField(fieldOf(collection.time))) problems.push(schemaProblemText("kind_time_invalid", {
|
|
407
|
+
collection: at,
|
|
408
|
+
field: collection.time
|
|
409
|
+
}));
|
|
410
|
+
if (kind === "timeseries") {
|
|
411
|
+
if (collection.time === void 0) problems.push(schemaProblemText("kind_declaration_required", {
|
|
412
|
+
collection: at,
|
|
413
|
+
kind,
|
|
414
|
+
declaration: "time"
|
|
415
|
+
}));
|
|
416
|
+
if (collection.retention_days === void 0) problems.push(schemaProblemText("kind_declaration_required", {
|
|
417
|
+
collection: at,
|
|
418
|
+
kind,
|
|
419
|
+
declaration: "retention_days"
|
|
420
|
+
}));
|
|
421
|
+
const subject = collection.subject === void 0 ? void 0 : fieldOf(collection.subject);
|
|
422
|
+
if (collection.subject !== void 0 && subject?.type !== "end_user") problems.push(schemaProblemText("kind_subject_invalid", {
|
|
423
|
+
collection: at,
|
|
424
|
+
field: collection.subject
|
|
425
|
+
}));
|
|
426
|
+
if (collection.subject === void 0 && collection.fields.some(isPiiField)) problems.push(schemaProblemText("kind_declaration_required", {
|
|
427
|
+
collection: at,
|
|
428
|
+
kind,
|
|
429
|
+
declaration: "subject"
|
|
430
|
+
}));
|
|
431
|
+
return problems;
|
|
432
|
+
}
|
|
433
|
+
const dimensions = collection.dimensions ?? [];
|
|
434
|
+
if (dimensions.length > AGGREGATE_LIMITS.dimensionsMax) problems.push(schemaProblemText("aggregate_dimensions_too_many", {
|
|
435
|
+
collection: at,
|
|
436
|
+
max: AGGREGATE_LIMITS.dimensionsMax
|
|
437
|
+
}));
|
|
438
|
+
for (const key of dimensions) if (fieldOf(key)?.type === "end_user") problems.push(schemaProblemText("aggregate_dimension_person", {
|
|
439
|
+
collection: at,
|
|
440
|
+
field: key
|
|
441
|
+
}));
|
|
442
|
+
if (collection.time === void 0 !== (collection.bucket === void 0)) problems.push(schemaProblemText("aggregate_bucket_pair", { collection: at }));
|
|
443
|
+
const measures = collection.measures ?? [];
|
|
444
|
+
if (!measures.length) problems.push(schemaProblemText("kind_declaration_required", {
|
|
445
|
+
collection: at,
|
|
446
|
+
kind,
|
|
447
|
+
declaration: "measures"
|
|
448
|
+
}));
|
|
449
|
+
for (const m of measures) if (fieldOf(m.field)?.type !== "number") problems.push(schemaProblemText("aggregate_measure_invalid", {
|
|
450
|
+
collection: at,
|
|
451
|
+
field: m.field
|
|
452
|
+
}));
|
|
453
|
+
const declared = /* @__PURE__ */ new Set([
|
|
454
|
+
...collection.time === void 0 ? [] : [collection.time],
|
|
455
|
+
...dimensions,
|
|
456
|
+
...measures.map((m) => m.field)
|
|
457
|
+
]);
|
|
458
|
+
for (const f of collection.fields) if (!declared.has(f.key)) problems.push(schemaProblemText("aggregate_field_undeclared", {
|
|
459
|
+
collection: at,
|
|
460
|
+
field: f.key
|
|
461
|
+
}));
|
|
462
|
+
return problems;
|
|
463
|
+
}
|
|
464
|
+
// ../schema/src/capabilities.ts
|
|
465
|
+
/** コレクションが持つ能力 */
|
|
466
|
+
const capabilitiesOf = (collection) => [
|
|
467
|
+
"transactions",
|
|
468
|
+
"history",
|
|
469
|
+
"events",
|
|
470
|
+
...hasPublication(collection) ? ["publication"] : [],
|
|
471
|
+
...collection.trash === true ? ["trash"] : []
|
|
472
|
+
];
|
|
473
|
+
const hasCapability = (collection, capability) => capabilitiesOf(collection).includes(capability);
|
|
474
|
+
/** コレクションの宣言が頼る能力(公開の前の検査 publish_checks は公開) */
|
|
475
|
+
const requiredCapabilities = (collection) => [...collection.publish_checks?.length ? [{
|
|
476
|
+
capability: "publication",
|
|
477
|
+
declaration: "publish_checks"
|
|
478
|
+
}] : []];
|
|
479
|
+
/** 宣言が頼るのにコレクションが持たない能力(なければ空) */
|
|
480
|
+
const missingCapabilities = (schema) => schema.collections.flatMap((collection) => requiredCapabilities(collection).filter((n) => !hasCapability(collection, n.capability)).map((n) => ({
|
|
481
|
+
...n,
|
|
482
|
+
collection
|
|
483
|
+
})));
|
|
484
|
+
// ../schema/src/fieldIds.ts
|
|
485
|
+
/** 内部の id の形(UUID v7 の正規の文字列) */
|
|
486
|
+
const FIELD_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
487
|
+
// ../schema/src/schema.ts
|
|
488
|
+
/** 保持の日数の上限(100年) */
|
|
489
|
+
const RETENTION_DAYS_MAX = 36500;
|
|
490
|
+
/** コレクションのスラッグの形 */
|
|
491
|
+
const COLLECTION_SLUG_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
492
|
+
const key = z.string().regex(COLLECTION_SLUG_PATTERN, schemaProblemText("invalid_collection_id"));
|
|
493
|
+
const fieldKey = z.string().regex(/^[a-z][a-zA-Z0-9_-]*$/, schemaProblemText("invalid_field_key"));
|
|
494
|
+
const condition = z.object({
|
|
495
|
+
key: fieldKey,
|
|
496
|
+
in: z.array(z.string().min(1)).min(1)
|
|
497
|
+
});
|
|
498
|
+
const computed = z.object({
|
|
499
|
+
kind: z.enum([
|
|
500
|
+
"excerpt",
|
|
501
|
+
"read_min",
|
|
502
|
+
"links"
|
|
503
|
+
]),
|
|
504
|
+
from: fieldKey
|
|
505
|
+
});
|
|
506
|
+
const base = {
|
|
507
|
+
id: z.string().regex(FIELD_ID_PATTERN, schemaProblemText("field_id_invalid")).optional(),
|
|
508
|
+
key: fieldKey,
|
|
509
|
+
label: z.string().min(1),
|
|
510
|
+
description: z.string().optional(),
|
|
511
|
+
required: z.union([
|
|
512
|
+
z.literal("save"),
|
|
513
|
+
z.literal("submit"),
|
|
514
|
+
z.literal("page"),
|
|
515
|
+
z.literal(false)
|
|
516
|
+
]).optional(),
|
|
517
|
+
when: condition.optional(),
|
|
518
|
+
audience: z.enum(AUDIENCES).optional(),
|
|
519
|
+
admin_only: z.boolean().optional(),
|
|
520
|
+
self_writable: z.boolean().optional(),
|
|
521
|
+
pending_until: fieldKey.optional(),
|
|
522
|
+
computed: computed.optional(),
|
|
523
|
+
managed: z.enum(MANAGED_FIELDS).optional(),
|
|
524
|
+
pii: z.enum(PII_CLASSES).optional()
|
|
525
|
+
};
|
|
526
|
+
const frame = z.object({
|
|
527
|
+
when: condition.optional(),
|
|
528
|
+
ratio: z.string().min(1),
|
|
529
|
+
size: z.object({
|
|
530
|
+
width: z.number().int().positive(),
|
|
531
|
+
height: z.number().int().positive()
|
|
532
|
+
}),
|
|
533
|
+
label: z.string().min(1)
|
|
534
|
+
});
|
|
535
|
+
const pageRule = z.union([
|
|
536
|
+
z.object({
|
|
537
|
+
key: z.string().min(1),
|
|
538
|
+
in: z.array(z.string())
|
|
539
|
+
}),
|
|
540
|
+
z.object({
|
|
541
|
+
key: z.string().min(1),
|
|
542
|
+
not_in: z.array(z.string())
|
|
543
|
+
}),
|
|
544
|
+
z.object({
|
|
545
|
+
key: z.string().min(1),
|
|
546
|
+
truthy: z.literal(true)
|
|
547
|
+
}),
|
|
548
|
+
z.object({
|
|
549
|
+
key: z.string().min(1),
|
|
550
|
+
not_future: z.literal(true)
|
|
551
|
+
})
|
|
552
|
+
]);
|
|
553
|
+
const page = z.object({
|
|
554
|
+
when: condition.optional(),
|
|
555
|
+
path: z.string().startsWith("/", schemaProblemText("page_path_slash")),
|
|
556
|
+
public: z.array(pageRule).optional()
|
|
557
|
+
});
|
|
558
|
+
const field = z.lazy(() => fieldUnion);
|
|
559
|
+
/** 項目の宣言の形(アプリのマニフェストのコレクションの項目の検査に使う) */
|
|
560
|
+
const fieldDefSchema = field;
|
|
561
|
+
const transition = z.object({
|
|
562
|
+
from: z.array(z.string().min(1).nullable()),
|
|
563
|
+
to: z.string().min(1),
|
|
564
|
+
by: z.object({
|
|
565
|
+
roles: z.array(z.string().min(1)).optional(),
|
|
566
|
+
self: z.boolean().optional(),
|
|
567
|
+
apps: z.array(z.string().min(1)).optional()
|
|
568
|
+
}).optional()
|
|
569
|
+
});
|
|
570
|
+
const counts = {
|
|
571
|
+
min_items: z.number().int().nonnegative().optional(),
|
|
572
|
+
max_items: z.number().int().positive().optional()
|
|
573
|
+
};
|
|
574
|
+
const regex = z.string().refine((p) => {
|
|
575
|
+
try {
|
|
576
|
+
new RegExp(p, "u");
|
|
577
|
+
return true;
|
|
578
|
+
} catch {
|
|
579
|
+
return false;
|
|
580
|
+
}
|
|
581
|
+
}, schemaProblemText("invalid_pattern"));
|
|
582
|
+
const anonymize = z.array(fieldKey).min(1).optional();
|
|
583
|
+
const fieldUnion = z.discriminatedUnion("type", [
|
|
584
|
+
z.object({
|
|
585
|
+
...base,
|
|
586
|
+
...counts,
|
|
587
|
+
type: z.enum(["text", "long_text"]),
|
|
588
|
+
external_id: z.boolean().optional(),
|
|
589
|
+
max_length: z.number().int().positive().optional(),
|
|
590
|
+
min_length: z.number().int().positive().optional(),
|
|
591
|
+
pattern: regex.optional(),
|
|
592
|
+
guide_length: z.number().int().positive().optional(),
|
|
593
|
+
multiple: z.boolean().optional()
|
|
594
|
+
}),
|
|
595
|
+
z.object({
|
|
596
|
+
...base,
|
|
597
|
+
type: z.literal("number"),
|
|
598
|
+
min: z.number().optional(),
|
|
599
|
+
max: z.number().optional(),
|
|
600
|
+
sequence: z.boolean().optional()
|
|
601
|
+
}),
|
|
602
|
+
z.object({
|
|
603
|
+
...base,
|
|
604
|
+
type: z.literal("boolean")
|
|
605
|
+
}),
|
|
606
|
+
z.object({
|
|
607
|
+
...base,
|
|
608
|
+
type: z.literal("email")
|
|
609
|
+
}),
|
|
610
|
+
z.object({
|
|
611
|
+
...base,
|
|
612
|
+
type: z.literal("phone"),
|
|
613
|
+
region: z.enum(PHONE_REGION_IDS).optional()
|
|
614
|
+
}),
|
|
615
|
+
z.object({
|
|
616
|
+
...base,
|
|
617
|
+
type: z.literal("url"),
|
|
618
|
+
schemes: z.array(z.enum(URL_SCHEMES)).min(1).optional()
|
|
619
|
+
}),
|
|
620
|
+
z.object({
|
|
621
|
+
...base,
|
|
622
|
+
type: z.enum(["date", "datetime"])
|
|
623
|
+
}),
|
|
624
|
+
z.object({
|
|
625
|
+
...base,
|
|
626
|
+
...counts,
|
|
627
|
+
type: z.literal("select"),
|
|
628
|
+
options: z.array(z.object({
|
|
629
|
+
value: z.string().min(1),
|
|
630
|
+
label: z.string().min(1),
|
|
631
|
+
tone: z.enum([
|
|
632
|
+
"positive",
|
|
633
|
+
"caution",
|
|
634
|
+
"neutral"
|
|
635
|
+
]).optional(),
|
|
636
|
+
restricted: z.boolean().optional()
|
|
637
|
+
})).min(1),
|
|
638
|
+
initial: z.string().optional(),
|
|
639
|
+
multiple: z.boolean().optional(),
|
|
640
|
+
derive: z.object({
|
|
641
|
+
from: fieldKey,
|
|
642
|
+
map: z.record(z.string(), z.string()),
|
|
643
|
+
otherwise: z.string()
|
|
644
|
+
}).optional(),
|
|
645
|
+
fixed_by: z.object({
|
|
646
|
+
ref: fieldKey,
|
|
647
|
+
key: fieldKey,
|
|
648
|
+
map: z.record(z.string(), z.string())
|
|
649
|
+
}).optional(),
|
|
650
|
+
transitions: z.array(transition).optional()
|
|
651
|
+
}).refine((f) => f.initial === void 0 || f.options.some((o) => o.value === f.initial), {
|
|
652
|
+
message: schemaProblemText("initial_not_option"),
|
|
653
|
+
path: ["initial"]
|
|
654
|
+
}).refine((f) => !f.derive || [...Object.values(f.derive.map), f.derive.otherwise].every((v) => f.options.some((o) => o.value === v)), {
|
|
655
|
+
message: schemaProblemText("derive_not_option"),
|
|
656
|
+
path: ["derive"]
|
|
657
|
+
}).refine((f) => !f.fixed_by || Object.values(f.fixed_by.map).every((v) => f.options.some((o) => o.value === v)), {
|
|
658
|
+
message: schemaProblemText("fixed_not_option"),
|
|
659
|
+
path: ["fixed_by"]
|
|
660
|
+
}),
|
|
661
|
+
z.object({
|
|
662
|
+
...base,
|
|
663
|
+
type: z.literal("status"),
|
|
664
|
+
options: z.array(z.object({
|
|
665
|
+
value: z.string().min(1),
|
|
666
|
+
label: z.string().min(1),
|
|
667
|
+
category: z.enum(STATUS_CATEGORIES),
|
|
668
|
+
tone: z.enum([
|
|
669
|
+
"positive",
|
|
670
|
+
"caution",
|
|
671
|
+
"neutral"
|
|
672
|
+
]).optional()
|
|
673
|
+
})).min(1),
|
|
674
|
+
initial: z.string().optional(),
|
|
675
|
+
transitions: z.array(transition).optional()
|
|
676
|
+
}).refine((f) => f.initial === void 0 || f.options.some((o) => o.value === f.initial), {
|
|
677
|
+
message: schemaProblemText("initial_not_option"),
|
|
678
|
+
path: ["initial"]
|
|
679
|
+
}),
|
|
680
|
+
z.object({
|
|
681
|
+
...base,
|
|
682
|
+
...counts,
|
|
683
|
+
type: z.literal("reference"),
|
|
684
|
+
to: z.string().min(1),
|
|
685
|
+
multiple: z.boolean().optional(),
|
|
686
|
+
where: z.record(z.string(), z.string()).optional(),
|
|
687
|
+
requests: z.boolean().optional(),
|
|
688
|
+
empty_label: z.string().min(1).optional(),
|
|
689
|
+
unique: z.boolean().optional(),
|
|
690
|
+
published: z.boolean().optional(),
|
|
691
|
+
linked_by: fieldKey.optional(),
|
|
692
|
+
on_delete: z.enum(ON_DELETE).optional(),
|
|
693
|
+
anonymize
|
|
694
|
+
}).refine((f) => !f.requests || f.multiple === true, {
|
|
695
|
+
message: schemaProblemText("requests_single"),
|
|
696
|
+
path: ["requests"]
|
|
697
|
+
}),
|
|
698
|
+
z.object({
|
|
699
|
+
...base,
|
|
700
|
+
...counts,
|
|
701
|
+
type: z.literal("file"),
|
|
702
|
+
accept: z.array(z.enum(["image", "video"])).optional(),
|
|
703
|
+
multiple: z.boolean().optional(),
|
|
704
|
+
frames: z.array(frame).optional(),
|
|
705
|
+
restricted_files: z.literal(true).optional()
|
|
706
|
+
}),
|
|
707
|
+
z.object({
|
|
708
|
+
...base,
|
|
709
|
+
type: z.literal("rich_text"),
|
|
710
|
+
restricted_files: z.literal(true).optional(),
|
|
711
|
+
profile: z.object({
|
|
712
|
+
headings: z.array(z.number()),
|
|
713
|
+
marks: z.array(z.string()),
|
|
714
|
+
components: z.array(z.string())
|
|
715
|
+
}).passthrough()
|
|
716
|
+
}),
|
|
717
|
+
z.object({
|
|
718
|
+
...base,
|
|
719
|
+
...counts,
|
|
720
|
+
type: z.literal("object"),
|
|
721
|
+
fields: z.array(field),
|
|
722
|
+
multiple: z.boolean().optional()
|
|
723
|
+
}),
|
|
724
|
+
z.object({
|
|
725
|
+
...base,
|
|
726
|
+
type: z.literal("end_user"),
|
|
727
|
+
unique: z.boolean().optional(),
|
|
728
|
+
self: z.boolean().optional(),
|
|
729
|
+
on_delete: z.enum(ON_DELETE).optional(),
|
|
730
|
+
anonymize
|
|
731
|
+
}).refine((f) => f.on_delete !== "restrict", {
|
|
732
|
+
message: schemaProblemText("end_user_restrict"),
|
|
733
|
+
path: ["on_delete"]
|
|
734
|
+
})
|
|
735
|
+
]);
|
|
736
|
+
/** 条件が一覧にある選択肢の項目と値を指すか */
|
|
737
|
+
const conditionValid = (when, fields) => {
|
|
738
|
+
const target = when && fields.find((g) => g.key === when.key && g.type === "select");
|
|
739
|
+
return !when || target !== void 0 && when.in.every((v) => target.options.some((o) => o.value === v));
|
|
740
|
+
};
|
|
741
|
+
/** 条件が同じ階層の選択肢の項目と値を指すか(まとまりの中も) */
|
|
742
|
+
const conditionsValid = (fields) => fields.every((f) => conditionValid(f.when, fields) && (!f.derive || fields.some((g) => g.key === f.derive.from && g.type === "select")) && (!f.fixed_by || fields.some((g) => g.key === f.fixed_by.ref && g.type === "reference" && !g.multiple)) && (f.frames ?? []).every((fr) => conditionValid(fr.when, fields)) && conditionsValid(f.fields ?? []));
|
|
743
|
+
/** まとまりの中で決まる値・参照先で固定を持つ項目の key(宣言の適用 rules.ts が最上位の項目だけのため) */
|
|
744
|
+
const nestedRules = (fields) => fields.flatMap((f) => (f.fields ?? []).flatMap((c) => [...c.derive || c.fixed_by ? [`${f.key}.${c.key}`] : [], ...nestedRules([c]).map((k) => `${f.key}.${k}`)]));
|
|
745
|
+
/**
|
|
746
|
+
* システムの値と同じ名前で、項目の key に使用できない名前(API・配信が項目の値を上書きするため)
|
|
747
|
+
* - すべてのコレクション: レコードの ID とスラッグ・作成と更新の日時・作成者、ワークスペースの一覧で参照する行の数 uses
|
|
748
|
+
* - 公開の管理があるコレクション: 公開の機能の値
|
|
749
|
+
* - 対象外: API・配信の値に出ない列 type、導入先の設定で決まるアカウントの email・account_role
|
|
750
|
+
*/
|
|
751
|
+
const RESERVED = [
|
|
752
|
+
"id",
|
|
753
|
+
"slug",
|
|
754
|
+
"created_at",
|
|
755
|
+
"created_by",
|
|
756
|
+
"updated_at",
|
|
757
|
+
"uses"
|
|
758
|
+
];
|
|
759
|
+
const RESERVED_EDITORIAL = [
|
|
760
|
+
"status",
|
|
761
|
+
"published_at",
|
|
762
|
+
"visibility",
|
|
763
|
+
"version",
|
|
764
|
+
"review_note",
|
|
765
|
+
"assignee"
|
|
766
|
+
];
|
|
767
|
+
/** 配信 API の絞り込みの論理の演算(filter[or][0][key] など) */
|
|
768
|
+
const RESERVED_QUERY = [
|
|
769
|
+
"or",
|
|
770
|
+
"and",
|
|
771
|
+
"not"
|
|
772
|
+
];
|
|
773
|
+
/** 項目の key に使えない名前の全部(公開の管理の有無によらない。アプリのマニフェストの検査) */
|
|
774
|
+
const RESERVED_FIELD_KEYS = [
|
|
775
|
+
...RESERVED,
|
|
776
|
+
...RESERVED_EDITORIAL,
|
|
777
|
+
...RESERVED_QUERY
|
|
778
|
+
];
|
|
779
|
+
/** 予約の名前と同じ最上位の key */
|
|
780
|
+
function reservedKeysOf(t) {
|
|
781
|
+
const reserved = [...RESERVED, ...t.publication ? RESERVED_EDITORIAL : []];
|
|
782
|
+
return [...t.fields.map((f) => f.key), ...(t.counts ?? []).map((c) => c.key)].filter((k) => reserved.includes(k));
|
|
783
|
+
}
|
|
784
|
+
/** 計算の種類ごとに受け付ける項目の種類 */
|
|
785
|
+
const COMPUTED_TYPES = {
|
|
786
|
+
excerpt: (f) => (f.type === "text" || f.type === "long_text") && !f.multiple,
|
|
787
|
+
read_min: (f) => f.type === "number",
|
|
788
|
+
links: (f) => f.type === "text" && Boolean(f.multiple)
|
|
789
|
+
};
|
|
790
|
+
/** 計算の項目の誤り(最上位の項目と、まとまりの中にある計算の項目) */
|
|
791
|
+
function computedProblems(collection, fields) {
|
|
792
|
+
const nested = (fs, path) => fs.flatMap((f) => [...f.computed ? [schemaProblemText("computed_nested", {
|
|
793
|
+
collection,
|
|
794
|
+
field: `${path}${f.key}`
|
|
795
|
+
})] : [], ...nested(f.fields ?? [], `${path}${f.key}.`)]);
|
|
796
|
+
return fields.flatMap((f) => {
|
|
797
|
+
const inner = nested(f.fields ?? [], `${f.key}.`);
|
|
798
|
+
if (!f.computed) return inner;
|
|
799
|
+
return [...[...fields.find((g) => g.key === f.computed.from)?.type === "rich_text" ? [] : [schemaProblemText("computed_from_not_body", {
|
|
800
|
+
collection,
|
|
801
|
+
field: f.key,
|
|
802
|
+
from: f.computed.from
|
|
803
|
+
})], ...COMPUTED_TYPES[f.computed.kind]?.(f) ? [] : [schemaProblemText("computed_type_mismatch", {
|
|
804
|
+
collection,
|
|
805
|
+
field: f.key,
|
|
806
|
+
kind: f.computed.kind,
|
|
807
|
+
type: f.type
|
|
808
|
+
})]], ...inner];
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
/** 役割の宣言の誤り(最上位にない key・役割が受け付けない項目) */
|
|
812
|
+
const roleProblems = (collection, roles, fields) => Object.entries(roles).flatMap(([role, key]) => {
|
|
813
|
+
const f = fields.find((g) => g.key === key);
|
|
814
|
+
if (!f) return [schemaProblemText("role_field_not_top", {
|
|
815
|
+
collection,
|
|
816
|
+
role,
|
|
817
|
+
field: String(key)
|
|
818
|
+
})];
|
|
819
|
+
return acceptsRole(role, f) ? [] : [schemaProblemText("role_field_mismatch", {
|
|
820
|
+
collection,
|
|
821
|
+
role,
|
|
822
|
+
field: f.key,
|
|
823
|
+
type: f.type
|
|
824
|
+
})];
|
|
825
|
+
});
|
|
826
|
+
/** 見える範囲の宣言の誤り(エンドユーザーへの参照のフィールドは本人かスタッフ、本人の項目は本人の印を持つコレクション、まとまりの中は外側と同じかスタッフ、要る権利は配信する参照) */
|
|
827
|
+
function audienceProblems(collection, fields, entitlement) {
|
|
828
|
+
const hasSelf = fields.some((f) => f.type === "end_user" && f.self);
|
|
829
|
+
const nested = (fs, path, outer) => fs.flatMap((f) => {
|
|
830
|
+
const own = f.audience ?? outer;
|
|
831
|
+
return [...own !== outer && own !== "none" ? [schemaProblemText("audience_nested_wider", {
|
|
832
|
+
collection,
|
|
833
|
+
field: `${path}${f.key}`
|
|
834
|
+
})] : [], ...nested(f.fields ?? [], `${path}${f.key}.`, own)];
|
|
835
|
+
});
|
|
836
|
+
const own = fields.flatMap((f) => [...f.type === "end_user" && f.audience !== "self" && f.audience !== "none" ? [schemaProblemText("audience_end_user_field", {
|
|
837
|
+
collection,
|
|
838
|
+
field: f.key
|
|
839
|
+
})] : [], ...nested(f.fields ?? [], `${f.key}.`, f.audience ?? "public")]);
|
|
840
|
+
const anySelf = (fs) => fs.some((f) => f.audience === "self" || anySelf(f.fields ?? []));
|
|
841
|
+
const self = !hasSelf && anySelf(fields) ? [schemaProblemText("audience_self_without_marker", { collection })] : [];
|
|
842
|
+
if (entitlement === void 0) return [...own, ...self];
|
|
843
|
+
const ref = fields.find((f) => f.key === entitlement);
|
|
844
|
+
return [
|
|
845
|
+
...own,
|
|
846
|
+
...self,
|
|
847
|
+
...ref?.type === "reference" && (ref.audience === "public" || ref.audience === "entitled") ? [] : [schemaProblemText("entitlement_not_reference", {
|
|
848
|
+
collection,
|
|
849
|
+
entitlement
|
|
850
|
+
})]
|
|
851
|
+
];
|
|
852
|
+
}
|
|
853
|
+
/** 元の見える範囲 source が作る値の見える範囲 target より狭いか(読み替えたコレクション、宣言なしは公開) */
|
|
854
|
+
const narrowerThan = (source, target) => {
|
|
855
|
+
const a = source ?? "public";
|
|
856
|
+
const b = target ?? "public";
|
|
857
|
+
return a !== b && narrower(a, b) === a;
|
|
858
|
+
};
|
|
859
|
+
/** 雛形の {key} の key */
|
|
860
|
+
const placeholdersOf = (template) => [...template.matchAll(/\{([A-Za-z0-9_-]+)\}/g)].map((m) => m[1]);
|
|
861
|
+
/**
|
|
862
|
+
* 値から作る値の見える範囲の誤り(読み替えたコレクション、作る値は元より広くできない)
|
|
863
|
+
* - 計算の項目 computed の元、決まる値 derive の元、条件 when の元(条件に合わない値は保存で空になる): 作る項目より狭い元は不可
|
|
864
|
+
* - ページの雛形 pages.path と OG の雛形 og の {key}: 最上位の公開の項目(slug と被参照の件数は可)。{id} は不可(UUID の URL になる)
|
|
865
|
+
*/
|
|
866
|
+
function derivedAudienceProblems(t) {
|
|
867
|
+
const byKey = new Map(t.fields.map((f) => [f.key, f]));
|
|
868
|
+
const narrowerSource = (f, from, source) => narrowerThan(byKey.get(from)?.audience, f.audience) && byKey.has(from) ? [schemaProblemText("audience_wider_than_source", {
|
|
869
|
+
collection: t.slug,
|
|
870
|
+
field: f.key,
|
|
871
|
+
source,
|
|
872
|
+
from
|
|
873
|
+
})] : [];
|
|
874
|
+
const own = t.fields.flatMap((f) => [
|
|
875
|
+
...f.computed ? narrowerSource(f, f.computed.from, "computed") : [],
|
|
876
|
+
...f.derive ? narrowerSource(f, f.derive.from, "derive") : [],
|
|
877
|
+
...f.when ? narrowerSource(f, f.when.key, "when") : []
|
|
878
|
+
]);
|
|
879
|
+
const allowed = /* @__PURE__ */ new Set(["slug", ...(t.counts ?? []).map((c) => c.key)]);
|
|
880
|
+
const templates = [...(t.pages ?? []).map((p) => p.path), ...t.og ? [t.og] : []];
|
|
881
|
+
const ids = templates.filter((tpl) => placeholdersOf(tpl).includes("id")).map((tpl) => schemaProblemText("template_id_placeholder", {
|
|
882
|
+
collection: t.slug,
|
|
883
|
+
template: tpl
|
|
884
|
+
}));
|
|
885
|
+
const paths = templates.flatMap((tpl) => placeholdersOf(tpl).filter((k) => k !== "id" && !allowed.has(k) && (byKey.get(k)?.audience ?? "public") !== "public").map((k) => schemaProblemText("template_private_placeholder", {
|
|
886
|
+
collection: t.slug,
|
|
887
|
+
template: tpl,
|
|
888
|
+
key: k
|
|
889
|
+
})));
|
|
890
|
+
return [
|
|
891
|
+
...own,
|
|
892
|
+
...ids,
|
|
893
|
+
...paths
|
|
894
|
+
];
|
|
895
|
+
}
|
|
896
|
+
/** 参照先で固定 fixed_by と被参照の件数 counts の見える範囲の誤り(固定の元は固定する項目より狭くできない、件数は元のコレクションの公開の参照だけ) */
|
|
897
|
+
function crossCollectionAudienceProblems(collections) {
|
|
898
|
+
const fixed = collections.flatMap((t) => t.fields.flatMap((f) => {
|
|
899
|
+
if (!f.fixed_by) return [];
|
|
900
|
+
const ref = t.fields.find((g) => g.key === f.fixed_by.ref);
|
|
901
|
+
return [ref, ref?.to ? collections.find((x) => x.id === ref.to)?.fields.find((g) => g.key === f.fixed_by.key) : void 0].some((src) => src && narrowerThan(src.audience, f.audience)) ? [schemaProblemText("fixed_by_wider", {
|
|
902
|
+
collection: t.slug,
|
|
903
|
+
field: f.key
|
|
904
|
+
})] : [];
|
|
905
|
+
}));
|
|
906
|
+
const counts = collections.flatMap((t) => (t.counts ?? []).flatMap((c) => {
|
|
907
|
+
const ref = collections.find((x) => x.id === c.from)?.fields.find((g) => g.key === c.field);
|
|
908
|
+
return ref && (ref.audience ?? "public") !== "public" ? [schemaProblemText("count_reference_private", {
|
|
909
|
+
collection: t.slug,
|
|
910
|
+
key: c.key,
|
|
911
|
+
fromCollection: collections.find((x) => x.id === c.from)?.slug ?? c.from,
|
|
912
|
+
field: c.field
|
|
913
|
+
})] : [];
|
|
914
|
+
}));
|
|
915
|
+
return [...fixed, ...counts];
|
|
916
|
+
}
|
|
917
|
+
/** エンドユーザーへの参照のフィールドの誤り(まとまりの中に置かない) */
|
|
918
|
+
function endUserFieldProblems(collection, fields) {
|
|
919
|
+
const nested = (fs, path) => fs.flatMap((f) => [...f.type === "end_user" ? [schemaProblemText("end_user_field_nested", {
|
|
920
|
+
collection,
|
|
921
|
+
field: `${path}${f.key}`
|
|
922
|
+
})] : [], ...nested(f.fields ?? [], `${path}${f.key}.`)]);
|
|
923
|
+
return fields.flatMap((f) => nested(f.fields ?? [], `${f.key}.`));
|
|
924
|
+
}
|
|
925
|
+
/** anonymize で空にできない項目の種類(本文・まとまり・結び付き) */
|
|
926
|
+
const UNCLEARABLE = /* @__PURE__ */ new Set([
|
|
927
|
+
"rich_text",
|
|
928
|
+
"object",
|
|
929
|
+
"end_user",
|
|
930
|
+
"reference"
|
|
931
|
+
]);
|
|
932
|
+
const isRequired = (f) => f.required !== void 0 && f.required !== false;
|
|
933
|
+
/** 指す先が消えたときの扱いのコレクションの中の誤り(必須の項目の clear・anonymize、anonymize の項目。まとまりの中の参照も同じ規則、anonymize の項目は最上位) */
|
|
934
|
+
function onDeleteProblems(collection, fields) {
|
|
935
|
+
const walk = (fs, path) => fs.flatMap((f) => {
|
|
936
|
+
const field = `${path}${f.key}`;
|
|
937
|
+
const inner = walk(f.fields ?? [], `${field}.`);
|
|
938
|
+
if (f.type !== "end_user" && f.type !== "reference") return inner;
|
|
939
|
+
return [...[
|
|
940
|
+
...isRequired(f) && (f.on_delete === "clear" || f.on_delete === "anonymize") ? [schemaProblemText("on_delete_required", {
|
|
941
|
+
collection,
|
|
942
|
+
field,
|
|
943
|
+
on_delete: f.on_delete
|
|
944
|
+
})] : [],
|
|
945
|
+
...(f.min_items ?? 0) > 0 && (f.on_delete === "clear" || f.on_delete === "anonymize") ? [schemaProblemText("on_delete_min_items", {
|
|
946
|
+
collection,
|
|
947
|
+
field,
|
|
948
|
+
on_delete: f.on_delete
|
|
949
|
+
})] : [],
|
|
950
|
+
...f.anonymize && f.on_delete !== "anonymize" ? [schemaProblemText("anonymize_without_on_delete", {
|
|
951
|
+
collection,
|
|
952
|
+
field
|
|
953
|
+
})] : [],
|
|
954
|
+
...(f.anonymize ?? []).flatMap((k) => {
|
|
955
|
+
const g = fields.find((x) => x.key === k);
|
|
956
|
+
if (!g) return [schemaProblemText("anonymize_field_missing", {
|
|
957
|
+
collection,
|
|
958
|
+
field,
|
|
959
|
+
target: k
|
|
960
|
+
})];
|
|
961
|
+
if (UNCLEARABLE.has(g.type) || g.computed) return [schemaProblemText("anonymize_field_unclearable", {
|
|
962
|
+
collection,
|
|
963
|
+
field,
|
|
964
|
+
target: k,
|
|
965
|
+
type: g.type
|
|
966
|
+
})];
|
|
967
|
+
return isRequired(g) ? [schemaProblemText("anonymize_field_required", {
|
|
968
|
+
collection,
|
|
969
|
+
field,
|
|
970
|
+
target: k
|
|
971
|
+
})] : [];
|
|
972
|
+
})
|
|
973
|
+
], ...inner];
|
|
974
|
+
});
|
|
975
|
+
return walk(fields, "");
|
|
976
|
+
}
|
|
977
|
+
/** cascade の循環、人からの深さ、参照の cascade でたどるコレクションの本人のエンドユーザーへの参照のフィールドの誤り */
|
|
978
|
+
function cascadeProblems(collections) {
|
|
979
|
+
const holders = (to) => collections.filter((collection) => cascadeTargetsOf(collection).includes(to));
|
|
980
|
+
const cycleFrom = (start) => {
|
|
981
|
+
const walk = (id, path) => {
|
|
982
|
+
for (const h of holders(id)) {
|
|
983
|
+
if (h.id === start) return [...path, h.id];
|
|
984
|
+
if (path.includes(h.id)) continue;
|
|
985
|
+
const found = walk(h.id, [...path, h.id]);
|
|
986
|
+
if (found) return found;
|
|
987
|
+
}
|
|
988
|
+
return null;
|
|
989
|
+
};
|
|
990
|
+
return walk(start, [start]);
|
|
991
|
+
};
|
|
992
|
+
const cyclic = /* @__PURE__ */ new Set();
|
|
993
|
+
const problems = [];
|
|
994
|
+
for (const collection of collections) {
|
|
995
|
+
const found = cyclic.has(collection.id) ? null : cycleFrom(collection.id);
|
|
996
|
+
if (!found) continue;
|
|
997
|
+
found.forEach((id) => cyclic.add(id));
|
|
998
|
+
problems.push(schemaProblemText("cascade_cycle", { cycle: found.map((id) => collections.find((c) => c.id === id)?.slug ?? id).join(" → ") }));
|
|
999
|
+
}
|
|
1000
|
+
if (problems.length) return problems;
|
|
1001
|
+
const depth = cascadeDepths(collections);
|
|
1002
|
+
const tooDeep = [...depth].filter(([, d]) => d > 4).map(([id, d]) => schemaProblemText("cascade_too_deep", {
|
|
1003
|
+
collection: collections.find((c) => c.id === id)?.slug ?? id,
|
|
1004
|
+
depth: d,
|
|
1005
|
+
max: 4
|
|
1006
|
+
}));
|
|
1007
|
+
const self = collections.filter((collection) => cascadeTargetsOf(collection).some((to) => depth.has(to))).flatMap((collection) => collection.fields.filter((f) => f.type === "end_user" && f.self).map((f) => schemaProblemText("cascade_self_end_user", {
|
|
1008
|
+
collection: collection.slug,
|
|
1009
|
+
field: f.key
|
|
1010
|
+
})));
|
|
1011
|
+
return [...tooDeep, ...self];
|
|
1012
|
+
}
|
|
1013
|
+
/** 人から cascade でたどれるコレクションを restrict で指す参照の項目の誤り(undeclared は宣言のない参照も拒む) */
|
|
1014
|
+
function restrictProblems(collections, undeclared) {
|
|
1015
|
+
const reachable = cascadeDepths(collections);
|
|
1016
|
+
const slugOf = (id) => collections.find((c) => c.id === id)?.slug ?? id;
|
|
1017
|
+
const walk = (slug, fields, path) => fields.flatMap((f) => {
|
|
1018
|
+
if (f.type === "object") return walk(slug, f.fields ?? [], `${path}${f.key}.`);
|
|
1019
|
+
if (f.type !== "reference" || !f.to || !reachable.has(f.to)) return [];
|
|
1020
|
+
if (f.on_delete === "restrict") return [schemaProblemText("restrict_reachable", {
|
|
1021
|
+
collection: slug,
|
|
1022
|
+
field: `${path}${f.key}`,
|
|
1023
|
+
to: slugOf(f.to)
|
|
1024
|
+
})];
|
|
1025
|
+
if (undeclared && f.on_delete === void 0) return [schemaProblemText("on_delete_undeclared_reference", {
|
|
1026
|
+
collection: slug,
|
|
1027
|
+
field: `${path}${f.key}`,
|
|
1028
|
+
to: slugOf(f.to)
|
|
1029
|
+
})];
|
|
1030
|
+
return [];
|
|
1031
|
+
});
|
|
1032
|
+
return collections.flatMap((t) => walk(t.slug, t.fields, ""));
|
|
1033
|
+
}
|
|
1034
|
+
/** 非公開のコレクションの宣言の誤り(配信に関わる宣言と同時に付けない) */
|
|
1035
|
+
function privateProblems(t) {
|
|
1036
|
+
const collection = t.slug;
|
|
1037
|
+
return [
|
|
1038
|
+
...t.format === "object" ? [schemaProblemText("private_object", { collection })] : [],
|
|
1039
|
+
...t.publication ? [schemaProblemText("private_publication", { collection })] : [],
|
|
1040
|
+
...t.pages?.length ? [schemaProblemText("private_pages", { collection })] : [],
|
|
1041
|
+
...t.entitlement !== void 0 ? [schemaProblemText("private_entitlement", { collection })] : []
|
|
1042
|
+
];
|
|
1043
|
+
}
|
|
1044
|
+
/** 本文の項目が使用する部品の名前(まとまりの中も、key は項目の key) */
|
|
1045
|
+
const richTextComponents = (fields) => fields.flatMap((f) => f.type === "rich_text" ? f.profile.components.map((name) => ({
|
|
1046
|
+
key: f.key,
|
|
1047
|
+
name
|
|
1048
|
+
})) : richTextComponents(f.fields ?? []));
|
|
1049
|
+
/** 参照の項目の参照先(まとまりの中も) */
|
|
1050
|
+
const referenceTargets = (fields) => fields.flatMap((f) => f.type === "reference" ? [f.to] : referenceTargets(f.fields ?? []));
|
|
1051
|
+
const formDef = z.strictObject({
|
|
1052
|
+
submitter: z.enum(FORM_SUBMITTERS),
|
|
1053
|
+
fields: z.array(z.strictObject({
|
|
1054
|
+
key: fieldKey,
|
|
1055
|
+
required_when: z.strictObject({
|
|
1056
|
+
key: fieldKey,
|
|
1057
|
+
in: z.array(z.string().min(1)).min(1)
|
|
1058
|
+
}).optional(),
|
|
1059
|
+
hosts: z.strictObject({
|
|
1060
|
+
site: z.boolean().optional(),
|
|
1061
|
+
exact: z.array(z.string()).optional(),
|
|
1062
|
+
subdomains_of: z.array(z.string()).optional()
|
|
1063
|
+
}).optional()
|
|
1064
|
+
})).min(1),
|
|
1065
|
+
handled: z.strictObject({
|
|
1066
|
+
field: fieldKey,
|
|
1067
|
+
done: z.array(z.string().min(1)).min(1),
|
|
1068
|
+
retention_days: z.number().int().positive().max(RETENTION_DAYS_MAX).optional()
|
|
1069
|
+
}).optional()
|
|
1070
|
+
});
|
|
1071
|
+
const contentType = z.object({
|
|
1072
|
+
id: z.string().refine((v) => isUuidShape(v), schemaProblemText("collection_id_invalid")),
|
|
1073
|
+
slug: key,
|
|
1074
|
+
label: z.string().min(1),
|
|
1075
|
+
description: z.string().optional(),
|
|
1076
|
+
format: z.enum(["list", "object"]).optional(),
|
|
1077
|
+
publication: z.boolean().optional(),
|
|
1078
|
+
publishing: z.never({ message: schemaProblemText("publishing_renamed") }).optional(),
|
|
1079
|
+
fields: z.array(field),
|
|
1080
|
+
pages: z.array(page).optional(),
|
|
1081
|
+
counts: z.array(z.object({
|
|
1082
|
+
key: fieldKey,
|
|
1083
|
+
from: z.string().min(1),
|
|
1084
|
+
field: fieldKey
|
|
1085
|
+
})).optional(),
|
|
1086
|
+
og: z.string().startsWith("/", schemaProblemText("og_path_slash")).optional(),
|
|
1087
|
+
slug_mode: z.enum(SLUG_MODES).optional(),
|
|
1088
|
+
roles: z.partialRecord(z.enum(FIELD_ROLES), fieldKey).optional(),
|
|
1089
|
+
entitlement: fieldKey.optional(),
|
|
1090
|
+
grant: z.never({ message: schemaProblemText("grant_renamed") }).optional(),
|
|
1091
|
+
private: z.boolean().optional(),
|
|
1092
|
+
unique: z.array(z.object({
|
|
1093
|
+
key: fieldKey,
|
|
1094
|
+
fields: z.array(fieldKey),
|
|
1095
|
+
exact: z.boolean().optional()
|
|
1096
|
+
})).optional(),
|
|
1097
|
+
self_ops: z.array(z.enum(SELF_OPS)).optional(),
|
|
1098
|
+
form: formDef.optional(),
|
|
1099
|
+
retention_days: z.number().int().positive().max(RETENTION_DAYS_MAX).optional(),
|
|
1100
|
+
publish_checks: z.array(z.string().min(1)).optional(),
|
|
1101
|
+
trash: z.boolean().optional(),
|
|
1102
|
+
kind: z.enum(DECLARED_COLLECTION_KINDS).optional(),
|
|
1103
|
+
time: fieldKey.optional(),
|
|
1104
|
+
dimensions: z.array(fieldKey).optional(),
|
|
1105
|
+
subject: fieldKey.optional(),
|
|
1106
|
+
source: z.string().refine((v) => isUuidShape(v), schemaProblemText("collection_id_invalid")).optional(),
|
|
1107
|
+
bucket: z.enum(AGGREGATE_BUCKETS).optional(),
|
|
1108
|
+
measures: z.array(z.object({
|
|
1109
|
+
field: fieldKey,
|
|
1110
|
+
op: z.enum(AGGREGATE_OPS)
|
|
1111
|
+
})).optional()
|
|
1112
|
+
}).refine((t) => new Set(t.fields.map((f) => f.key)).size === t.fields.length, { message: schemaProblemText("duplicate_field_key") }).refine((t) => conditionsValid(t.fields), { message: schemaProblemText("condition_invalid") }).refine((t) => (t.pages ?? []).every((p) => conditionValid(p.when, t.fields)), { message: schemaProblemText("page_condition_invalid") }).superRefine((t, ctx) => {
|
|
1113
|
+
const fields = t.fields;
|
|
1114
|
+
const asCollection = t;
|
|
1115
|
+
for (const k of reservedKeysOf(t)) ctx.addIssue({
|
|
1116
|
+
code: "custom",
|
|
1117
|
+
message: schemaProblemText("reserved_key", {
|
|
1118
|
+
collection: t.slug,
|
|
1119
|
+
key: k
|
|
1120
|
+
})
|
|
1121
|
+
});
|
|
1122
|
+
for (const f of fields) if (RESERVED_QUERY.includes(f.key)) ctx.addIssue({
|
|
1123
|
+
code: "custom",
|
|
1124
|
+
message: schemaProblemText("reserved_query_key", {
|
|
1125
|
+
collection: t.slug,
|
|
1126
|
+
key: f.key
|
|
1127
|
+
})
|
|
1128
|
+
});
|
|
1129
|
+
for (const k of nestedRules(fields)) ctx.addIssue({
|
|
1130
|
+
code: "custom",
|
|
1131
|
+
message: schemaProblemText("nested_rule", {
|
|
1132
|
+
collection: t.slug,
|
|
1133
|
+
field: k
|
|
1134
|
+
})
|
|
1135
|
+
});
|
|
1136
|
+
for (const m of roleProblems(t.slug, t.roles ?? {}, t.fields)) ctx.addIssue({
|
|
1137
|
+
code: "custom",
|
|
1138
|
+
message: m,
|
|
1139
|
+
path: ["roles"]
|
|
1140
|
+
});
|
|
1141
|
+
const problems = [
|
|
1142
|
+
...computedProblems(t.slug, fields),
|
|
1143
|
+
...audienceProblems(t.slug, fields, t.entitlement),
|
|
1144
|
+
...derivedAudienceProblems({
|
|
1145
|
+
...t,
|
|
1146
|
+
fields
|
|
1147
|
+
}),
|
|
1148
|
+
...endUserFieldProblems(t.slug, fields),
|
|
1149
|
+
...integrityProblems(asCollection),
|
|
1150
|
+
...transitionProblems(asCollection),
|
|
1151
|
+
...onDeleteProblems(t.slug, fields),
|
|
1152
|
+
...selfOpsProblems(asCollection),
|
|
1153
|
+
...selfWritableProblems(asCollection),
|
|
1154
|
+
...formProblems(asCollection),
|
|
1155
|
+
...kindProblems(asCollection)
|
|
1156
|
+
];
|
|
1157
|
+
for (const m of problems) ctx.addIssue({
|
|
1158
|
+
code: "custom",
|
|
1159
|
+
message: m
|
|
1160
|
+
});
|
|
1161
|
+
for (const n of missingCapabilities({ collections: [asCollection] })) ctx.addIssue({
|
|
1162
|
+
code: "custom",
|
|
1163
|
+
message: schemaProblemText("capability_required", {
|
|
1164
|
+
collection: t.slug,
|
|
1165
|
+
declaration: n.declaration,
|
|
1166
|
+
capability: n.capability
|
|
1167
|
+
}),
|
|
1168
|
+
path: [n.declaration]
|
|
1169
|
+
});
|
|
1170
|
+
if (t.private) for (const m of privateProblems(t)) ctx.addIssue({
|
|
1171
|
+
code: "custom",
|
|
1172
|
+
message: m,
|
|
1173
|
+
path: ["private"]
|
|
1174
|
+
});
|
|
1175
|
+
});
|
|
1176
|
+
z.object({
|
|
1177
|
+
components: declaredComponentsSchema.optional(),
|
|
1178
|
+
collections: z.array(contentType).refine((ts) => new Set(ts.map((t) => t.id)).size === ts.length, { message: schemaProblemText("duplicate_collection_id") }).refine((ts) => new Set(ts.map((t) => t.slug)).size === ts.length, { message: schemaProblemText("duplicate_collection_slug") }).superRefine((ts, ctx) => {
|
|
1179
|
+
const ids = new Set(ts.map((t) => t.id));
|
|
1180
|
+
for (const t of ts) for (const to of referenceTargets(t.fields)) if (!ids.has(to)) ctx.addIssue({
|
|
1181
|
+
code: "custom",
|
|
1182
|
+
message: schemaProblemText("reference_target_missing", {
|
|
1183
|
+
collection: t.slug,
|
|
1184
|
+
to
|
|
1185
|
+
})
|
|
1186
|
+
});
|
|
1187
|
+
for (const t of ts) if (t.source !== void 0 && !ids.has(t.source)) ctx.addIssue({
|
|
1188
|
+
code: "custom",
|
|
1189
|
+
message: schemaProblemText("reference_target_missing", {
|
|
1190
|
+
collection: t.slug,
|
|
1191
|
+
to: t.source
|
|
1192
|
+
})
|
|
1193
|
+
});
|
|
1194
|
+
for (const t of ts) for (const to of referenceTargets(t.fields)) if (to === "380c5450-9f5e-5b10-8273-c3e1d86aa266") ctx.addIssue({
|
|
1195
|
+
code: "custom",
|
|
1196
|
+
message: schemaProblemText("reference_to_files", { collection: t.slug })
|
|
1197
|
+
});
|
|
1198
|
+
for (const t of ts) {
|
|
1199
|
+
const keys = new Set(t.fields.map((f) => f.key));
|
|
1200
|
+
for (const c of t.counts ?? []) {
|
|
1201
|
+
const from = ts.find((x) => x.id === c.from);
|
|
1202
|
+
const ref = from && from.fields.find((f) => f.key === c.field);
|
|
1203
|
+
if (ref?.type !== "reference" || ref.to !== t.id) ctx.addIssue({
|
|
1204
|
+
code: "custom",
|
|
1205
|
+
message: schemaProblemText("count_reference_mismatch", {
|
|
1206
|
+
collection: t.slug,
|
|
1207
|
+
key: c.key,
|
|
1208
|
+
fromCollection: from?.slug ?? c.from,
|
|
1209
|
+
field: c.field
|
|
1210
|
+
})
|
|
1211
|
+
});
|
|
1212
|
+
if (keys.has(c.key)) ctx.addIssue({
|
|
1213
|
+
code: "custom",
|
|
1214
|
+
message: schemaProblemText("count_key_duplicate", {
|
|
1215
|
+
collection: t.slug,
|
|
1216
|
+
key: c.key
|
|
1217
|
+
})
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
const parsed = ts.map((t) => ({
|
|
1222
|
+
id: t.id,
|
|
1223
|
+
slug: t.slug,
|
|
1224
|
+
fields: t.fields
|
|
1225
|
+
}));
|
|
1226
|
+
for (const m of crossCollectionAudienceProblems(ts.map((t) => ({
|
|
1227
|
+
id: t.id,
|
|
1228
|
+
slug: t.slug,
|
|
1229
|
+
fields: t.fields,
|
|
1230
|
+
counts: t.counts
|
|
1231
|
+
})))) ctx.addIssue({
|
|
1232
|
+
code: "custom",
|
|
1233
|
+
message: m
|
|
1234
|
+
});
|
|
1235
|
+
const cascade = cascadeProblems(parsed);
|
|
1236
|
+
for (const m of cascade) ctx.addIssue({
|
|
1237
|
+
code: "custom",
|
|
1238
|
+
message: m
|
|
1239
|
+
});
|
|
1240
|
+
if (!cascade.length) for (const m of restrictProblems(parsed, false)) ctx.addIssue({
|
|
1241
|
+
code: "custom",
|
|
1242
|
+
message: m
|
|
1243
|
+
});
|
|
1244
|
+
})
|
|
1245
|
+
}).superRefine((m, ctx) => {
|
|
1246
|
+
const known = /* @__PURE__ */ new Set([...CORE_COMPONENTS.map((c) => c.name), ...(m.components ?? []).map((c) => c.name)]);
|
|
1247
|
+
for (const t of m.collections) for (const { key, name } of richTextComponents(t.fields)) if (!known.has(name)) ctx.addIssue({
|
|
1248
|
+
code: "custom",
|
|
1249
|
+
message: schemaProblemText("component_unknown", {
|
|
1250
|
+
collection: t.slug,
|
|
1251
|
+
field: key,
|
|
1252
|
+
name
|
|
1253
|
+
})
|
|
1254
|
+
});
|
|
1255
|
+
});
|
|
1256
|
+
/** コレクションの一覧として読めるか(コレクションごとに id・スラッグと項目の配列) */
|
|
1257
|
+
const readable = (json) => isRecord(json) && Array.isArray(json.collections) && json.collections.every((t) => isRecord(t) && typeof t.id === "string" && typeof t.slug === "string" && Array.isArray(t.fields) && t.fields.every(isRecord));
|
|
1258
|
+
/**
|
|
1259
|
+
* 保存した版とファイルの読み込み(寛容: 旧い語を今の名前にした値をそのまま返し、規則で拒まない、既定を書き込まない)
|
|
1260
|
+
* - コレクションの一覧として読めない値だけ例外(壊れた版)
|
|
1261
|
+
* - 見える範囲などの読み替えは audienceOf と resolvedSchema(保存の形には書き戻さない)
|
|
1262
|
+
*/
|
|
1263
|
+
function parseSchema(json) {
|
|
1264
|
+
if (!readable(json)) throw new Error("schema_unreadable");
|
|
1265
|
+
return json;
|
|
1266
|
+
}
|
|
1267
|
+
export { AGGREGATE_BUCKETS as a, schemaProblemText as c, parseSchema as i, RESERVED_FIELD_KEYS as n, AGGREGATE_OPS as o, fieldDefSchema as r, DECLARED_COLLECTION_KINDS as s, COLLECTION_SLUG_PATTERN as t };
|