@tunasand/sdk 0.8.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.
Files changed (215) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/README.md +162 -143
  3. package/dist/analytics.js +76 -65
  4. package/dist/app.js +184 -163
  5. package/dist/apps-DIxAWBSZ.js +318 -0
  6. package/dist/astro-image.d.ts +1 -0
  7. package/dist/astro-image.js +33 -0
  8. package/dist/astro-server-Bwau8F6d.js +99 -0
  9. package/dist/astro-server.d.ts +1 -0
  10. package/dist/astro-server.js +1 -0
  11. package/dist/astro.d.ts +1 -0
  12. package/dist/astro.js +306 -0
  13. package/dist/bridge-Dv4NxGZ7.js +81 -0
  14. package/dist/bridge.js +1 -13
  15. package/dist/build-file-DNi0PHC5.js +31 -0
  16. package/dist/cli.js +6212 -8
  17. package/dist/{client-Derrexwr.js → client-C8STAw9T.js} +43 -24
  18. package/dist/code-N8pBUDbq.js +30 -0
  19. package/dist/code.d.ts +1 -0
  20. package/dist/code.js +1 -0
  21. package/dist/collection-nUz1RetA.js +264 -0
  22. package/dist/{declared-DuNMsdXw.js → declared-CE4a61qb.js} +35 -35
  23. package/dist/delivery.js +121 -114
  24. package/dist/dev-operations-Tutwi1On.js +46 -0
  25. package/dist/dev.js +9 -16
  26. package/dist/embeds-B-Dbn64k.js +29 -0
  27. package/dist/end-users.d.ts +1 -0
  28. package/dist/end-users.js +185 -0
  29. package/dist/endUsers-DODfjnv1.js +77 -0
  30. package/dist/{errorLabels-BgtQ_zUn.js → errorLabels-aT2bnMsO.js} +355 -235
  31. package/dist/i18n.js +4 -4
  32. package/dist/ids-DmtIoqBX.js +109 -0
  33. package/dist/integrations.js +95 -24
  34. package/dist/{ja-Du6ooL6i.js → ja-CrY_72Tn.js} +88 -44
  35. package/dist/{ja-CeHU0EaY.js → ja-axQPxMJ-.js} +3 -3
  36. package/dist/operations-CIB99rIY.js +95 -0
  37. package/dist/operations.d.ts +1 -0
  38. package/dist/operations.js +1 -0
  39. package/dist/{page-Bzrj24sJ.js → page-yo1cw1kW.js} +1 -1
  40. package/dist/preview.js +8 -1
  41. package/dist/{profile-1em_lcxq.js → profile-DBsXLvvI.js} +48 -48
  42. package/dist/rich-text.js +16 -16
  43. package/dist/{schema-WnobuwLg.js → schema-Dcg1ajnW.js} +496 -263
  44. package/dist/schema.js +66 -88
  45. package/dist/types/access/src/handoff.d.ts +19 -14
  46. package/dist/types/access/src/index.d.ts +2 -2
  47. package/dist/types/access/src/jws.d.ts +41 -0
  48. package/dist/types/access/src/oidc.d.ts +10 -2
  49. package/dist/types/access/src/signed.d.ts +0 -2
  50. package/dist/types/adapter-cloudflare/src/eventLog/viewSchema.d.ts +11 -0
  51. package/dist/types/contract/src/accountProfile.d.ts +7 -0
  52. package/dist/types/contract/src/apiKeys.d.ts +6 -2
  53. package/dist/types/contract/src/app.d.ts +15 -5
  54. package/dist/types/contract/src/appChannels.d.ts +114 -0
  55. package/dist/types/contract/src/appDefinition.d.ts +11 -5
  56. package/dist/types/contract/src/appDependencies.d.ts +87 -24
  57. package/dist/types/contract/src/appIdentities.d.ts +21 -0
  58. package/dist/types/contract/src/appInbound.d.ts +28 -0
  59. package/dist/types/contract/src/appMail.d.ts +106 -0
  60. package/dist/types/contract/src/appSecrets.d.ts +45 -0
  61. package/dist/types/contract/src/appServer.d.ts +408 -43
  62. package/dist/types/contract/src/approvals.d.ts +1 -1
  63. package/dist/types/contract/src/apps.d.ts +112 -55
  64. package/dist/types/contract/src/auditActions.d.ts +2 -2
  65. package/dist/types/contract/src/auditLabels.d.ts +111 -15
  66. package/dist/types/contract/src/authorize.d.ts +42 -14
  67. package/dist/types/contract/src/bridge.d.ts +34 -35
  68. package/dist/types/contract/src/consents.d.ts +32 -25
  69. package/dist/types/contract/src/deletion.d.ts +18 -0
  70. package/dist/types/contract/src/embeds.d.ts +16 -82
  71. package/dist/types/contract/src/{customerLabels.d.ts → endUserLabels.d.ts} +6 -9
  72. package/dist/types/contract/src/endUsers.d.ts +241 -0
  73. package/dist/types/contract/src/errorLabels.d.ts +63 -36
  74. package/dist/types/contract/src/errorLabelsEn.d.ts +46 -32
  75. package/dist/types/contract/src/errors.d.ts +28 -16
  76. package/dist/types/contract/src/eventSchemas.d.ts +70 -0
  77. package/dist/types/contract/src/eventTraces.d.ts +43 -0
  78. package/dist/types/contract/src/failureStatus.d.ts +14 -22
  79. package/dist/types/contract/src/fieldAccess.d.ts +8 -8
  80. package/dist/types/contract/src/formLabels.d.ts +3 -0
  81. package/dist/types/contract/src/forms.d.ts +4 -0
  82. package/dist/types/contract/src/grants.d.ts +26 -0
  83. package/dist/types/contract/src/headers.d.ts +5 -0
  84. package/dist/types/contract/src/hostingRpc.d.ts +23 -17
  85. package/dist/types/contract/src/identifiers.d.ts +45 -17
  86. package/dist/types/contract/src/ids.d.ts +18 -10
  87. package/dist/types/contract/src/import.d.ts +17 -16
  88. package/dist/types/contract/src/index.d.ts +52 -27
  89. package/dist/types/contract/src/integrationGraph.d.ts +83 -0
  90. package/dist/types/contract/src/issueLabels.d.ts +113 -81
  91. package/dist/types/contract/src/issueLabelsEn.d.ts +57 -41
  92. package/dist/types/contract/src/manage.d.ts +11 -7
  93. package/dist/types/contract/src/manageLabels.d.ts +2 -0
  94. package/dist/types/contract/src/manifestText.d.ts +66 -0
  95. package/dist/types/contract/src/messagePort.d.ts +208 -0
  96. package/dist/types/contract/src/migration.d.ts +2 -2
  97. package/dist/types/contract/src/notices.d.ts +38 -0
  98. package/dist/types/contract/src/operatorOperations.d.ts +0 -63
  99. package/dist/types/contract/src/outbound.d.ts +29 -0
  100. package/dist/types/contract/src/paths.d.ts +13 -0
  101. package/dist/types/contract/src/pending.d.ts +2 -0
  102. package/dist/types/contract/src/permissions.d.ts +7 -11
  103. package/dist/types/contract/src/perspective.d.ts +26 -0
  104. package/dist/types/contract/src/powers.d.ts +5 -0
  105. package/dist/types/contract/src/principal.d.ts +127 -56
  106. package/dist/types/contract/src/recordLabels.d.ts +6 -0
  107. package/dist/types/contract/src/roles.d.ts +7 -4
  108. package/dist/types/contract/src/ruleLabels.d.ts +16 -0
  109. package/dist/types/contract/src/ruleProblems.d.ts +16 -0
  110. package/dist/types/contract/src/schemaLabels.d.ts +8 -0
  111. package/dist/types/contract/src/settingProblems.d.ts +1 -1
  112. package/dist/types/contract/src/settings.d.ts +5 -7
  113. package/dist/types/contract/src/siteDeclaration.d.ts +7 -7
  114. package/dist/types/contract/src/siteIndex.d.ts +76 -0
  115. package/dist/types/contract/src/transfer.d.ts +1 -1
  116. package/dist/types/contract/src/trial.d.ts +4 -1
  117. package/dist/types/contract/src/versions.d.ts +1 -3
  118. package/dist/types/contract/src/viewEvent.d.ts +0 -9
  119. package/dist/types/contract/src/webhooks.d.ts +24 -3
  120. package/dist/types/contract/src/workflow.d.ts +13 -19
  121. package/dist/types/contract/src/workspaceItems.d.ts +20 -6
  122. package/dist/types/rich-text/src/html.d.ts +1 -1
  123. package/dist/types/rich-text/src/index.d.ts +8 -7
  124. package/dist/types/rich-text/src/labels/en.d.ts +1 -1
  125. package/dist/types/rich-text/src/labels/ja.d.ts +2 -2
  126. package/dist/types/rich-text/src/library.d.ts +1 -1
  127. package/dist/types/rich-text/src/media.d.ts +2 -0
  128. package/dist/types/rich-text/src/normalize.d.ts +1 -1
  129. package/dist/types/rich-text/src/problems.d.ts +5 -5
  130. package/dist/types/rich-text/src/profile.d.ts +10 -10
  131. package/dist/types/rich-text/src/render.d.ts +1 -1
  132. package/dist/types/rich-text/src/schema.d.ts +2 -2
  133. package/dist/types/rich-text/src/standard.d.ts +4 -4
  134. package/dist/types/rich-text/src/types.d.ts +2 -2
  135. package/dist/types/schema/src/audience.d.ts +1 -3
  136. package/dist/types/schema/src/capabilities.d.ts +18 -27
  137. package/dist/types/schema/src/changes.d.ts +3 -1
  138. package/dist/types/schema/src/collection.d.ts +138 -111
  139. package/dist/types/schema/src/defaultSchema.d.ts +8 -2
  140. package/dist/types/schema/src/fieldIds.d.ts +18 -0
  141. package/dist/types/schema/src/file.d.ts +22 -11
  142. package/dist/types/schema/src/fileRefs.d.ts +14 -0
  143. package/dist/types/schema/src/fileSignature.d.ts +20 -0
  144. package/dist/types/schema/src/filesCollection.d.ts +7 -0
  145. package/dist/types/schema/src/forms.d.ts +43 -0
  146. package/dist/types/schema/src/imageMetadata.d.ts +9 -0
  147. package/dist/types/schema/src/index.d.ts +18 -10
  148. package/dist/types/schema/src/input.d.ts +1 -1
  149. package/dist/types/schema/src/integrity.d.ts +8 -7
  150. package/dist/types/schema/src/kinds.d.ts +26 -0
  151. package/dist/types/schema/src/labels/en.d.ts +87 -46
  152. package/dist/types/schema/src/labels/ja.d.ts +89 -45
  153. package/dist/types/schema/src/mediaUrl.d.ts +26 -33
  154. package/dist/types/schema/src/page.d.ts +4 -4
  155. package/dist/types/schema/src/problems.d.ts +82 -41
  156. package/dist/types/schema/src/refs.d.ts +0 -9
  157. package/dist/types/schema/src/schema.d.ts +17 -12
  158. package/dist/types/schema/src/selfOps.d.ts +20 -19
  159. package/dist/types/schema/src/traits.d.ts +28 -0
  160. package/dist/types/schema/src/typesSource.d.ts +1 -1
  161. package/dist/types/schema/src/values.d.ts +5 -2
  162. package/dist/types/schema/src/widening.d.ts +3 -0
  163. package/dist/types/sdk/src/analytics.d.ts +2 -1
  164. package/dist/types/sdk/src/app.d.ts +40 -14
  165. package/dist/types/sdk/src/astro-image.d.ts +19 -0
  166. package/dist/types/sdk/src/astro-response.d.ts +6 -0
  167. package/dist/types/sdk/src/astro-server.d.ts +16 -0
  168. package/dist/types/sdk/src/astro.d.ts +19 -0
  169. package/dist/types/sdk/src/bridge.d.ts +2 -4
  170. package/dist/types/sdk/src/code.d.ts +61 -0
  171. package/dist/types/sdk/src/delegation.d.ts +13 -3
  172. package/dist/types/sdk/src/delivery/changes.d.ts +4 -4
  173. package/dist/types/sdk/src/delivery/client.d.ts +33 -22
  174. package/dist/types/sdk/src/delivery/fields.d.ts +3 -3
  175. package/dist/types/sdk/src/delivery/index.d.ts +3 -3
  176. package/dist/types/sdk/src/delivery/media.d.ts +5 -8
  177. package/dist/types/sdk/src/delivery/query.d.ts +15 -11
  178. package/dist/types/sdk/src/delivery/schema.d.ts +1 -1
  179. package/dist/types/sdk/src/delivery/values.d.ts +10 -14
  180. package/dist/types/sdk/src/delivery.d.ts +2 -2
  181. package/dist/types/sdk/src/dev-operations.d.ts +20 -0
  182. package/dist/types/sdk/src/dev.d.ts +6 -5
  183. package/dist/types/sdk/src/end-users.d.ts +190 -0
  184. package/dist/types/sdk/src/i18n.d.ts +2 -2
  185. package/dist/types/sdk/src/integrations.d.ts +14 -21
  186. package/dist/types/sdk/src/operations.d.ts +17 -0
  187. package/dist/types/sdk/src/preview.d.ts +2 -1
  188. package/dist/types/sdk/src/rich-text.d.ts +2 -2
  189. package/dist/types/sdk/src/schema.d.ts +1 -1
  190. package/dist/types/sdk/src/site/artifact.d.ts +64 -0
  191. package/dist/types/sdk/src/site/build-file.d.ts +30 -0
  192. package/dist/types/sdk/src/site/check-code.d.ts +14 -0
  193. package/dist/types/sdk/src/site/check-text.d.ts +19 -0
  194. package/dist/types/sdk/src/site/cli.d.ts +52 -0
  195. package/dist/types/sdk/src/site/content-type.d.ts +2 -0
  196. package/dist/types/sdk/src/site/labels.d.ts +14 -0
  197. package/dist/types/sdk/src/types.d.ts +1 -1
  198. package/dist/{types-B77qvqPJ.js → types-DkO2N7u2.js} +5 -6
  199. package/dist/types.js +1 -1
  200. package/dist/{typesSource-CWybQYus.js → typesSource-VJIxtN9b.js} +17 -15
  201. package/dist/workflow-CUpl6hO_.js +148 -0
  202. package/package.json +32 -6
  203. package/dist/apps-BxnJ1RlU.js +0 -435
  204. package/dist/bridge-DtHw9hS6.js +0 -74
  205. package/dist/collection-BEOxeISR.js +0 -189
  206. package/dist/customers-DTbL0qn6.js +0 -86
  207. package/dist/customers.d.ts +0 -1
  208. package/dist/customers.js +0 -185
  209. package/dist/embeds-B5V54Zur.js +0 -34
  210. package/dist/ids--RF7hGyC.js +0 -36
  211. package/dist/src-sazhzYui.js +0 -71
  212. package/dist/types/contract/src/customers.d.ts +0 -266
  213. package/dist/types/schema/src/legacy.d.ts +0 -2
  214. package/dist/types/schema/src/media.d.ts +0 -5
  215. package/dist/types/sdk/src/customers.d.ts +0 -184
@@ -1,7 +1,7 @@
1
- import { i as CORE_COMPONENTS, t as declaredComponentsSchema } from "./declared-DuNMsdXw.js";
2
- import { f as problemText, l as problemFactory } from "./ja-CeHU0EaY.js";
3
- import { n as SCHEMA_PROBLEM_MESSAGES, t as PRODUCT_FIELD_LABELS } from "./ja-Du6ooL6i.js";
4
- import { A as publishingOf, C as isSequenceField, D as narrower, E as isSurveyShape, a as PII_CLASSES, c as acceptsRole, d as cascadeTargetsOf, i as ON_DELETE, j as roleFieldOf, 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, w as isSingleton, y as isListCollection } from "./collection-BEOxeISR.js";
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
5
  import { z } from "zod";
6
6
  // ../schema/src/problems.ts
7
7
  /** コンテンツスキーマの検査の問題を作る */
@@ -19,7 +19,7 @@ const PHONE_REGION_IDS = Object.keys({
19
19
  const URL_SCHEMES = ["https", "http"];
20
20
  // ../schema/src/check.ts
21
21
  /** 配列でないオブジェクトか */
22
- const isRecord$1 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
22
+ const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
23
23
  /** 一意の組に含められる項目か(最上位・単数・入力する項目で、値を文字にできる種類) */
24
24
  function acceptsUnique(f) {
25
25
  if (f.computed || "multiple" in f && f.multiple) return false;
@@ -30,14 +30,15 @@ function acceptsUnique(f) {
30
30
  "url",
31
31
  "number",
32
32
  "select",
33
+ "status",
33
34
  "reference",
34
35
  "date",
35
36
  "datetime",
36
- CUSTOMER_FIELD_TYPE
37
+ END_USER_FIELD_TYPE
37
38
  ].includes(f.type);
38
39
  }
39
- /** コレクションの一意の組(宣言 unique と、unique を付けた顧客フィールドと、連番の項目) */
40
- const uniqueDefsOf = (collection) => [...collection.unique ?? [], ...collection.fields.flatMap((f) => f.type === "customer" && f.unique || isSequenceField(f) ? [{
40
+ /** コレクションの一意の組(宣言 unique と、unique を付けたエンドユーザーへの参照のフィールドと、連番の項目) */
41
+ const uniqueDefsOf = (collection) => [...collection.unique ?? [], ...collection.fields.flatMap((f) => f.type === "end_user" && f.unique || isSequenceField(f) ? [{
41
42
  key: f.key,
42
43
  fields: [f.key],
43
44
  exact: true
@@ -81,9 +82,9 @@ function integrityProblems(collection) {
81
82
  const nested = (fields, path) => fields.flatMap((f) => [...isSequenceField(f) ? [schemaProblemText("sequence_nested", {
82
83
  collection: id,
83
84
  field: `${path}${f.key}`
84
- })] : [], ...f.type === "group" ? nested(f.fields, `${path}${f.key}.`) : []]);
85
+ })] : [], ...f.type === "object" ? nested(f.fields, `${path}${f.key}.`) : []]);
85
86
  for (const f of collection.fields) {
86
- if (f.type === "group") problems.push(...nested(f.fields, `${f.key}.`));
87
+ if (f.type === "object") problems.push(...nested(f.fields, `${f.key}.`));
87
88
  if (!isSequenceField(f)) continue;
88
89
  if (!isListCollection(collection)) problems.push(schemaProblemText("sequence_list_only", {
89
90
  collection: id,
@@ -99,16 +100,16 @@ function integrityProblems(collection) {
99
100
  /** 遷移の宣言の誤り(スキーマの検査) */
100
101
  function transitionProblems(collection) {
101
102
  const id = collection.slug;
102
- const nested = (fields, path) => fields.flatMap((f) => [...f.type === "select" && f.transitions ? [schemaProblemText("transition_nested", {
103
+ const nested = (fields, path) => fields.flatMap((f) => [...(f.type === "select" || f.type === "status") && f.transitions ? [schemaProblemText("transition_nested", {
103
104
  collection: id,
104
105
  field: `${path}${f.key}`
105
- })] : [], ...f.type === "group" ? nested(f.fields, `${path}${f.key}.`) : []]);
106
+ })] : [], ...f.type === "object" ? nested(f.fields, `${path}${f.key}.`) : []]);
106
107
  return collection.fields.flatMap((f) => {
107
- if (f.type === "group") return nested(f.fields, `${f.key}.`);
108
- if (f.type !== "select" || !f.transitions) return [];
108
+ if (f.type === "object") return nested(f.fields, `${f.key}.`);
109
+ if (f.type !== "select" && f.type !== "status" || !f.transitions) return [];
109
110
  const values = new Set(f.options.map((o) => o.value));
110
111
  const problems = [];
111
- if (f.multiple || f.derive || f.fixedBy) problems.push(schemaProblemText("transition_field_kind", {
112
+ if (f.type === "select" && (f.multiple || f.derive || f.fixed_by)) problems.push(schemaProblemText("transition_field_kind", {
112
113
  collection: id,
113
114
  field: f.key
114
115
  }));
@@ -127,38 +128,160 @@ function transitionProblems(collection) {
127
128
  ...at,
128
129
  value: v
129
130
  }));
130
- if (!t.by.roles?.length && !t.by.self && !t.by.apps?.length) problems.push(schemaProblemText("transition_no_actor", at));
131
+ if (t.by && !t.by.roles?.length && !t.by.self && !t.by.apps?.length) problems.push(schemaProblemText("transition_no_actor", at));
131
132
  }
132
133
  return problems;
133
134
  });
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
+ }
135
254
  // ../schema/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
- /** コレクションの本人の顧客フィールド */
255
+ /** 本人のエンドユーザーへの参照のフィールドか(コレクションの最上位の項目) */
256
+ const isSelfField = (f, collection) => f.type === "end_user" && (f.self === true || f.self === void 0 && declaredAudienceOf(f) === void 0 && isSurveyShape(collection));
257
+ /** コレクションの本人のエンドユーザーへの参照のフィールド */
139
258
  const selfFieldsOf = (collection) => collection.fields.filter((f) => isSelfField(f, collection));
140
259
  /** 本人が書ける印を付けられない項目の理由(付けられれば null) */
141
260
  function selfWritableBlock(f, collection) {
142
- if (f.type === "customer") return "customer";
143
- if (f.type === "group" || f.type === "file" || f.type === "rich_text") return f.type;
144
- if (audienceOf(f, collection) === "staff") return "staff";
145
- if (f.adminOnly) return "admin_only";
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";
146
265
  if (f.computed) return "computed";
147
266
  if (isSequenceField(f)) return "sequence";
267
+ if (f.managed) return "managed";
148
268
  return null;
149
269
  }
150
- /** 人の操作の宣言の誤り(配信しない一覧のコレクション、本人の顧客フィールドがちょうど1つで onDelete は cascade か anonymize、一意の組はすべて本人の顧客フィールドを含む) */
270
+ /**
271
+ * 人の操作の宣言の誤り(配信しない一覧のコレクション、本人のエンドユーザーへの参照のフィールドがちょうど1つで on_delete は cascade か anonymize、
272
+ * 一意の組はすべて本人のエンドユーザーへの参照のフィールドを含む)
273
+ */
151
274
  function selfOpsProblems(collection) {
152
- if (!collection.selfOps?.length) return [];
275
+ if (!collection.self_ops?.length) return [];
153
276
  const self = selfFieldsOf(collection);
154
277
  const at = { collection: collection.slug };
155
278
  const problems = [];
156
279
  if (collection.private !== true) problems.push(schemaProblemText("self_ops_private_only", at));
157
280
  if (isSingleton(collection)) problems.push(schemaProblemText("self_ops_list_only", at));
158
- if ((collection.publishing ?? "none") !== "none" || collection.fields.some((f) => f.key === "published" && f.type === "boolean")) problems.push(schemaProblemText("self_ops_unpublished", at));
281
+ if (collection.publication || collection.fields.some((f) => f.key === "published" && f.type === "boolean")) problems.push(schemaProblemText("self_ops_unpublished", at));
159
282
  if (self.length !== 1) problems.push(schemaProblemText("self_ops_one_self", at));
160
283
  const key = self.length === 1 ? self[0].key : null;
161
- if (key && self[0].onDelete !== "cascade" && self[0].onDelete !== "anonymize") problems.push(schemaProblemText("self_ops_on_delete", {
284
+ if (key && self[0].on_delete !== "cascade" && self[0].on_delete !== "anonymize") problems.push(schemaProblemText("self_ops_on_delete", {
162
285
  ...at,
163
286
  field: key
164
287
  }));
@@ -171,14 +294,14 @@ function selfOpsProblems(collection) {
171
294
  }
172
295
  /** 本人が書ける印の誤り(付けられない項目、まとまりの中、create_self か update_self を受けないコレクション) */
173
296
  function selfWritableProblems(collection) {
174
- const nested = (fields, path) => fields.flatMap((f) => [...f.selfWritable !== void 0 ? [schemaProblemText("self_writable_nested", {
297
+ const nested = (fields, path) => fields.flatMap((f) => [...f.self_writable !== void 0 ? [schemaProblemText("self_writable_nested", {
175
298
  collection: collection.slug,
176
299
  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;
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;
179
302
  return collection.fields.flatMap((f) => {
180
- const inner = f.type === "group" ? nested(f.fields, `${f.key}.`) : [];
181
- if (!f.selfWritable) return inner;
303
+ const inner = f.type === "object" ? nested(f.fields, `${f.key}.`) : [];
304
+ if (!f.self_writable) return inner;
182
305
  const block = selfWritableBlock(f, collection);
183
306
  return [
184
307
  ...block ? [schemaProblemText("self_writable_blocked", {
@@ -194,141 +317,179 @@ function selfWritableProblems(collection) {
194
317
  ];
195
318
  });
196
319
  }
197
- /** コレクションが本人の確認の方法 proof で受ける人の操作 */
198
- function selfOpsOf(collection, proof) {
199
- if (collection.selfOps?.length) return proof === "site" && !selfOpsProblems(collection).length ? [...new Set(collection.selfOps)] : [];
200
- return proof === "id_token" && isSurveyShape(collection) ? ["submit"] : [];
201
- }
202
- // ../schema/src/capabilities.ts
203
- /** 出典の項目と、内側の項目の key */
204
- const SOURCES_FIELD = {
205
- key: "sources",
206
- source: "source",
207
- note: "note"
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
+ ]
208
358
  };
209
- /** 主のコレクションか(公開の管理と本文の項目を持つ一覧のコレクション) */
210
- const isPrimaryCandidate = (collection) => isListCollection(collection) && publishingOf(collection) !== "none" && roleFieldOf(collection, "body") !== null;
211
- /** 主のコレクション(スキーマの順で先頭、なければ null) */
212
- const primaryCollectionOf = (schema) => schema.collections.find(isPrimaryCandidate) ?? null;
213
- /** 主のコレクション(なければ例外: そのコレクションを前提にする画面・処理だけが使用) */
214
- function requiredPrimaryCollectionOf(collectionSchema) {
215
- const collection = primaryCollectionOf(collectionSchema);
216
- if (!collection) throw new Error("content schema has no collection with publishing and a body field");
217
- return collection;
218
- }
219
- /** 暦の日付(日付の役割の項目を持つ一覧のコレクションと項目の key、スキーマの順、役割は宣言だけで推測なし) */
220
- const dateRoleFieldsOf = (schema) => schema.collections.filter(isListCollection).flatMap((t) => {
221
- const f = roleFieldOf(t, "date");
222
- return f ? [{
223
- collection: t.id,
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,
224
460
  field: f.key
225
- }] : [];
226
- });
227
- /** コレクションの出典の項目(なければ null) */
228
- function sourcesFieldOf(collection) {
229
- const f = collection.fields.find((x) => x.key === SOURCES_FIELD.key);
230
- if (f?.type !== "group" || !f.multiple) return null;
231
- const source = f.fields.find((x) => x.key === SOURCES_FIELD.source);
232
- return source?.type === "reference" && !source.multiple ? {
233
- ...f,
234
- to: source.to
235
- } : null;
461
+ }));
462
+ return problems;
236
463
  }
237
- /** 出典の値にある参照の ID(注の順、空と形の誤りは除外) */
238
- const sourceIdsOf = (value) => (Array.isArray(value) ? value : []).flatMap((item) => {
239
- const id = item && typeof item === "object" ? item[SOURCES_FIELD.source] : void 0;
240
- return typeof id === "string" && id ? [id] : [];
241
- });
242
- // ../schema/src/legacy.ts
243
- const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
244
- /** 記事の表のコレクションだった目印(古いバージョンの table の値) */
245
- const ARTICLES = "articles";
246
- const PUBLISHED_AT = "published_at";
247
- /** 本文から作成する値の計算の項目(from は本文の項目の key) */
248
- const computedFields = (from) => [
249
- {
250
- key: "excerpt",
251
- label: PRODUCT_FIELD_LABELS.excerpt,
252
- type: "long_text",
253
- computed: {
254
- kind: "excerpt",
255
- from
256
- }
257
- },
258
- {
259
- key: "read_min",
260
- label: PRODUCT_FIELD_LABELS.readMin,
261
- type: "number",
262
- computed: {
263
- kind: "read_min",
264
- from
265
- }
266
- },
267
- {
268
- key: "links",
269
- label: PRODUCT_FIELD_LABELS.links,
270
- type: "text",
271
- multiple: true,
272
- computed: {
273
- kind: "links",
274
- from
275
- }
276
- }
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"] : []
277
472
  ];
278
- /** 出典の参照の項目を複数のまとまりに */
279
- const sourcesGroup = (f) => ({
280
- key: f.key,
281
- label: f.label,
282
- ...f.private !== void 0 && { private: f.private },
283
- type: "group",
284
- multiple: true,
285
- fields: [{
286
- key: SOURCES_FIELD.source,
287
- label: f.label,
288
- type: "reference",
289
- to: f.to
290
- }, {
291
- key: SOURCES_FIELD.note,
292
- label: PRODUCT_FIELD_LABELS.sourceNote,
293
- type: "long_text"
294
- }]
295
- });
296
- /** 古い形のコレクションを今の形に(core・table のないコレクションはそのまま) */
297
- function normalizeCollection(t) {
298
- if (!("core" in t) && !("table" in t)) return t;
299
- const { core, table, ...rest } = t;
300
- const articles = table === ARTICLES;
301
- const coreFields = (Array.isArray(core) ? core : []).filter(isRecord).flatMap((f) => {
302
- if (articles && f.key === PUBLISHED_AT) return [];
303
- if (articles && f.key === SOURCES_FIELD.key && f.type === "reference") return [sourcesGroup(f)];
304
- return [f];
305
- });
306
- const keys = new Set(coreFields.map((f) => f.key));
307
- const fields = [...coreFields, ...(Array.isArray(t.fields) ? t.fields : []).filter((f) => !isRecord(f) || !keys.has(f.key))];
308
- if (!articles) return {
309
- ...rest,
310
- fields
311
- };
312
- const body = fields.find((f) => isRecord(f) && f.type === "rich_text");
313
- const present = new Set(fields.filter(isRecord).map((f) => f.key));
314
- const computed = body ? computedFields(String(body.key)).filter((f) => !present.has(f.key)) : [];
315
- return {
316
- ...rest,
317
- fields: [...fields, ...computed]
318
- };
319
- }
320
- /** 古い形のスキーマの JSON を今の形に(形の分からない値はそのまま、検査は parseSchema) */
321
- function normalizeLegacySchema(json) {
322
- if (!isRecord(json) || !Array.isArray(json.collections)) return json;
323
- return {
324
- ...json,
325
- collections: json.collections.map((t) => isRecord(t) ? normalizeCollection(t) : t)
326
- };
327
- }
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}$/;
328
487
  // ../schema/src/schema.ts
329
488
  /** 保持の日数の上限(100年) */
330
489
  const RETENTION_DAYS_MAX = 36500;
331
- const key = z.string().regex(/^[a-z][a-z0-9_]*$/, schemaProblemText("invalid_collection_id"));
490
+ /** コレクションのスラッグの形 */
491
+ const COLLECTION_SLUG_PATTERN = /^[a-z][a-z0-9_]*$/;
492
+ const key = z.string().regex(COLLECTION_SLUG_PATTERN, schemaProblemText("invalid_collection_id"));
332
493
  const fieldKey = z.string().regex(/^[a-z][a-zA-Z0-9_-]*$/, schemaProblemText("invalid_field_key"));
333
494
  const condition = z.object({
334
495
  key: fieldKey,
@@ -343,6 +504,7 @@ const computed = z.object({
343
504
  from: fieldKey
344
505
  });
345
506
  const base = {
507
+ id: z.string().regex(FIELD_ID_PATTERN, schemaProblemText("field_id_invalid")).optional(),
346
508
  key: fieldKey,
347
509
  label: z.string().min(1),
348
510
  description: z.string().optional(),
@@ -354,10 +516,11 @@ const base = {
354
516
  ]).optional(),
355
517
  when: condition.optional(),
356
518
  audience: z.enum(AUDIENCES).optional(),
357
- adminOnly: z.boolean().optional(),
358
- selfWritable: z.boolean().optional(),
359
- pendingUntil: fieldKey.optional(),
519
+ admin_only: z.boolean().optional(),
520
+ self_writable: z.boolean().optional(),
521
+ pending_until: fieldKey.optional(),
360
522
  computed: computed.optional(),
523
+ managed: z.enum(MANAGED_FIELDS).optional(),
361
524
  pii: z.enum(PII_CLASSES).optional()
362
525
  };
363
526
  const frame = z.object({
@@ -376,7 +539,7 @@ const pageRule = z.union([
376
539
  }),
377
540
  z.object({
378
541
  key: z.string().min(1),
379
- notIn: z.array(z.string())
542
+ not_in: z.array(z.string())
380
543
  }),
381
544
  z.object({
382
545
  key: z.string().min(1),
@@ -384,7 +547,7 @@ const pageRule = z.union([
384
547
  }),
385
548
  z.object({
386
549
  key: z.string().min(1),
387
- notFuture: z.literal(true)
550
+ not_future: z.literal(true)
388
551
  })
389
552
  ]);
390
553
  const page = z.object({
@@ -402,11 +565,11 @@ const transition = z.object({
402
565
  roles: z.array(z.string().min(1)).optional(),
403
566
  self: z.boolean().optional(),
404
567
  apps: z.array(z.string().min(1)).optional()
405
- })
568
+ }).optional()
406
569
  });
407
570
  const counts = {
408
- minItems: z.number().int().nonnegative().optional(),
409
- maxItems: z.number().int().positive().optional()
571
+ min_items: z.number().int().nonnegative().optional(),
572
+ max_items: z.number().int().positive().optional()
410
573
  };
411
574
  const regex = z.string().refine((p) => {
412
575
  try {
@@ -422,11 +585,11 @@ const fieldUnion = z.discriminatedUnion("type", [
422
585
  ...base,
423
586
  ...counts,
424
587
  type: z.enum(["text", "long_text"]),
425
- externalId: z.boolean().optional(),
426
- maxLength: z.number().int().positive().optional(),
427
- minLength: z.number().int().positive().optional(),
588
+ external_id: z.boolean().optional(),
589
+ max_length: z.number().int().positive().optional(),
590
+ min_length: z.number().int().positive().optional(),
428
591
  pattern: regex.optional(),
429
- guideLength: z.number().int().positive().optional(),
592
+ guide_length: z.number().int().positive().optional(),
430
593
  multiple: z.boolean().optional()
431
594
  }),
432
595
  z.object({
@@ -479,7 +642,7 @@ const fieldUnion = z.discriminatedUnion("type", [
479
642
  map: z.record(z.string(), z.string()),
480
643
  otherwise: z.string()
481
644
  }).optional(),
482
- fixedBy: z.object({
645
+ fixed_by: z.object({
483
646
  ref: fieldKey,
484
647
  key: fieldKey,
485
648
  map: z.record(z.string(), z.string())
@@ -491,9 +654,28 @@ const fieldUnion = z.discriminatedUnion("type", [
491
654
  }).refine((f) => !f.derive || [...Object.values(f.derive.map), f.derive.otherwise].every((v) => f.options.some((o) => o.value === v)), {
492
655
  message: schemaProblemText("derive_not_option"),
493
656
  path: ["derive"]
494
- }).refine((f) => !f.fixedBy || Object.values(f.fixedBy.map).every((v) => f.options.some((o) => o.value === v)), {
657
+ }).refine((f) => !f.fixed_by || Object.values(f.fixed_by.map).every((v) => f.options.some((o) => o.value === v)), {
495
658
  message: schemaProblemText("fixed_not_option"),
496
- path: ["fixedBy"]
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"]
497
679
  }),
498
680
  z.object({
499
681
  ...base,
@@ -503,12 +685,15 @@ const fieldUnion = z.discriminatedUnion("type", [
503
685
  multiple: z.boolean().optional(),
504
686
  where: z.record(z.string(), z.string()).optional(),
505
687
  requests: z.boolean().optional(),
506
- emptyLabel: z.string().min(1).optional(),
688
+ empty_label: z.string().min(1).optional(),
507
689
  unique: z.boolean().optional(),
508
690
  published: z.boolean().optional(),
509
- linkedBy: fieldKey.optional(),
510
- onDelete: z.enum(ON_DELETE).optional(),
691
+ linked_by: fieldKey.optional(),
692
+ on_delete: z.enum(ON_DELETE).optional(),
511
693
  anonymize
694
+ }).refine((f) => !f.requests || f.multiple === true, {
695
+ message: schemaProblemText("requests_single"),
696
+ path: ["requests"]
512
697
  }),
513
698
  z.object({
514
699
  ...base,
@@ -517,12 +702,12 @@ const fieldUnion = z.discriminatedUnion("type", [
517
702
  accept: z.array(z.enum(["image", "video"])).optional(),
518
703
  multiple: z.boolean().optional(),
519
704
  frames: z.array(frame).optional(),
520
- visibility: z.literal("private").optional()
705
+ restricted_files: z.literal(true).optional()
521
706
  }),
522
707
  z.object({
523
708
  ...base,
524
709
  type: z.literal("rich_text"),
525
- visibility: z.literal("private").optional(),
710
+ restricted_files: z.literal(true).optional(),
526
711
  profile: z.object({
527
712
  headings: z.array(z.number()),
528
713
  marks: z.array(z.string()),
@@ -532,20 +717,20 @@ const fieldUnion = z.discriminatedUnion("type", [
532
717
  z.object({
533
718
  ...base,
534
719
  ...counts,
535
- type: z.literal("group"),
720
+ type: z.literal("object"),
536
721
  fields: z.array(field),
537
722
  multiple: z.boolean().optional()
538
723
  }),
539
724
  z.object({
540
725
  ...base,
541
- type: z.literal("customer"),
726
+ type: z.literal("end_user"),
542
727
  unique: z.boolean().optional(),
543
728
  self: z.boolean().optional(),
544
- onDelete: z.enum(ON_DELETE).optional(),
729
+ on_delete: z.enum(ON_DELETE).optional(),
545
730
  anonymize
546
- }).refine((f) => f.onDelete !== "restrict", {
547
- message: schemaProblemText("customer_restrict"),
548
- path: ["onDelete"]
731
+ }).refine((f) => f.on_delete !== "restrict", {
732
+ message: schemaProblemText("end_user_restrict"),
733
+ path: ["on_delete"]
549
734
  })
550
735
  ]);
551
736
  /** 条件が一覧にある選択肢の項目と値を指すか */
@@ -554,9 +739,9 @@ const conditionValid = (when, fields) => {
554
739
  return !when || target !== void 0 && when.in.every((v) => target.options.some((o) => o.value === v));
555
740
  };
556
741
  /** 条件が同じ階層の選択肢の項目と値を指すか(まとまりの中も) */
557
- 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 ?? []));
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 ?? []));
558
743
  /** まとまりの中で決まる値・参照先で固定を持つ項目の key(宣言の適用 rules.ts が最上位の項目だけのため) */
559
- 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}`)]));
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}`)]));
560
745
  /**
561
746
  * システムの値と同じ名前で、項目の key に使用できない名前(API・配信が項目の値を上書きするため)
562
747
  * - すべてのコレクション: レコードの ID とスラッグ・作成と更新の日時・作成者、ワークスペースの一覧で参照する行の数 uses
@@ -593,7 +778,7 @@ const RESERVED_FIELD_KEYS = [
593
778
  ];
594
779
  /** 予約の名前と同じ最上位の key */
595
780
  function reservedKeysOf(t) {
596
- const reserved = [...RESERVED, ...(t.publishing ?? "none") !== "none" ? RESERVED_EDITORIAL : []];
781
+ const reserved = [...RESERVED, ...t.publication ? RESERVED_EDITORIAL : []];
597
782
  return [...t.fields.map((f) => f.key), ...(t.counts ?? []).map((c) => c.key)].filter((k) => reserved.includes(k));
598
783
  }
599
784
  /** 計算の種類ごとに受け付ける項目の種類 */
@@ -638,30 +823,30 @@ const roleProblems = (collection, roles, fields) => Object.entries(roles).flatMa
638
823
  type: f.type
639
824
  })];
640
825
  });
641
- /** 見える範囲の宣言の誤り(顧客フィールドは本人かスタッフ、本人の項目は本人の印を持つコレクション、まとまりの中は外側と同じかスタッフ、要る権利は配信する参照) */
642
- function audienceProblems(collection, fields, grant) {
643
- const hasSelf = fields.some((f) => f.type === "customer" && f.self);
826
+ /** 見える範囲の宣言の誤り(エンドユーザーへの参照のフィールドは本人かスタッフ、本人の項目は本人の印を持つコレクション、まとまりの中は外側と同じかスタッフ、要る権利は配信する参照) */
827
+ function audienceProblems(collection, fields, entitlement) {
828
+ const hasSelf = fields.some((f) => f.type === "end_user" && f.self);
644
829
  const nested = (fs, path, outer) => fs.flatMap((f) => {
645
830
  const own = f.audience ?? outer;
646
- return [...own !== outer && own !== "staff" ? [schemaProblemText("audience_nested_wider", {
831
+ return [...own !== outer && own !== "none" ? [schemaProblemText("audience_nested_wider", {
647
832
  collection,
648
833
  field: `${path}${f.key}`
649
834
  })] : [], ...nested(f.fields ?? [], `${path}${f.key}.`, own)];
650
835
  });
651
- const own = fields.flatMap((f) => [...f.type === "customer" && f.audience !== "self" && f.audience !== "staff" ? [schemaProblemText("audience_customer_field", {
836
+ const own = fields.flatMap((f) => [...f.type === "end_user" && f.audience !== "self" && f.audience !== "none" ? [schemaProblemText("audience_end_user_field", {
652
837
  collection,
653
838
  field: f.key
654
839
  })] : [], ...nested(f.fields ?? [], `${f.key}.`, f.audience ?? "public")]);
655
840
  const anySelf = (fs) => fs.some((f) => f.audience === "self" || anySelf(f.fields ?? []));
656
841
  const self = !hasSelf && anySelf(fields) ? [schemaProblemText("audience_self_without_marker", { collection })] : [];
657
- if (grant === void 0) return [...own, ...self];
658
- const ref = fields.find((f) => f.key === grant);
842
+ if (entitlement === void 0) return [...own, ...self];
843
+ const ref = fields.find((f) => f.key === entitlement);
659
844
  return [
660
845
  ...own,
661
846
  ...self,
662
- ...ref?.type === "reference" && (ref.audience === "public" || ref.audience === "granted") ? [] : [schemaProblemText("grant_not_reference", {
847
+ ...ref?.type === "reference" && (ref.audience === "public" || ref.audience === "entitled") ? [] : [schemaProblemText("entitlement_not_reference", {
663
848
  collection,
664
- grant
849
+ entitlement
665
850
  })]
666
851
  ];
667
852
  }
@@ -708,12 +893,12 @@ function derivedAudienceProblems(t) {
708
893
  ...paths
709
894
  ];
710
895
  }
711
- /** 参照先で固定 fixedBy と被参照の件数 counts の見える範囲の誤り(固定の元は固定する項目より狭くできない、件数は元のコレクションの公開の参照だけ) */
896
+ /** 参照先で固定 fixed_by と被参照の件数 counts の見える範囲の誤り(固定の元は固定する項目より狭くできない、件数は元のコレクションの公開の参照だけ) */
712
897
  function crossCollectionAudienceProblems(collections) {
713
898
  const fixed = collections.flatMap((t) => t.fields.flatMap((f) => {
714
- if (!f.fixedBy) return [];
715
- const ref = t.fields.find((g) => g.key === f.fixedBy.ref);
716
- 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)) ? [schemaProblemText("fixed_by_wider", {
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", {
717
902
  collection: t.slug,
718
903
  field: f.key
719
904
  })] : [];
@@ -729,9 +914,9 @@ function crossCollectionAudienceProblems(collections) {
729
914
  }));
730
915
  return [...fixed, ...counts];
731
916
  }
732
- /** 顧客フィールドの誤り(まとまりの中に置かない) */
733
- function customerFieldProblems(collection, fields) {
734
- const nested = (fs, path) => fs.flatMap((f) => [...f.type === "customer" ? [schemaProblemText("customer_field_nested", {
917
+ /** エンドユーザーへの参照のフィールドの誤り(まとまりの中に置かない) */
918
+ function endUserFieldProblems(collection, fields) {
919
+ const nested = (fs, path) => fs.flatMap((f) => [...f.type === "end_user" ? [schemaProblemText("end_user_field_nested", {
735
920
  collection,
736
921
  field: `${path}${f.key}`
737
922
  })] : [], ...nested(f.fields ?? [], `${path}${f.key}.`)]);
@@ -740,58 +925,56 @@ function customerFieldProblems(collection, fields) {
740
925
  /** anonymize で空にできない項目の種類(本文・まとまり・結び付き) */
741
926
  const UNCLEARABLE = /* @__PURE__ */ new Set([
742
927
  "rich_text",
743
- "group",
744
- "customer",
928
+ "object",
929
+ "end_user",
745
930
  "reference"
746
931
  ]);
747
932
  const isRequired = (f) => f.required !== void 0 && f.required !== false;
748
- /** 指す先が消えたときの扱いのコレクションの中の誤り(必須の項目の clear・anonymize、anonymize の項目、まとまりの中の宣言) */
933
+ /** 指す先が消えたときの扱いのコレクションの中の誤り(必須の項目の clear・anonymize、anonymize の項目。まとまりの中の参照も同じ規則、anonymize の項目は最上位) */
749
934
  function onDeleteProblems(collection, fields) {
750
- const nested = (fs, path) => fs.flatMap((f) => [...f.onDelete !== void 0 || f.anonymize ? [schemaProblemText("on_delete_nested", {
751
- collection,
752
- field: `${path}${f.key}`
753
- })] : [], ...nested(f.fields ?? [], `${path}${f.key}.`)]);
754
- return fields.flatMap((f) => {
755
- const inner = nested(f.fields ?? [], `${f.key}.`);
756
- if (f.type !== "customer" && f.type !== "reference") return inner;
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;
757
939
  return [...[
758
- ...isRequired(f) && (f.onDelete === "clear" || f.onDelete === "anonymize") ? [schemaProblemText("on_delete_required", {
940
+ ...isRequired(f) && (f.on_delete === "clear" || f.on_delete === "anonymize") ? [schemaProblemText("on_delete_required", {
759
941
  collection,
760
- field: f.key,
761
- onDelete: f.onDelete
942
+ field,
943
+ on_delete: f.on_delete
762
944
  })] : [],
763
- ...(f.minItems ?? 0) > 0 && (f.onDelete === "clear" || f.onDelete === "anonymize") ? [schemaProblemText("on_delete_min_items", {
945
+ ...(f.min_items ?? 0) > 0 && (f.on_delete === "clear" || f.on_delete === "anonymize") ? [schemaProblemText("on_delete_min_items", {
764
946
  collection,
765
- field: f.key,
766
- onDelete: f.onDelete
947
+ field,
948
+ on_delete: f.on_delete
767
949
  })] : [],
768
- ...f.anonymize && f.onDelete !== "anonymize" ? [schemaProblemText("anonymize_without_on_delete", {
950
+ ...f.anonymize && f.on_delete !== "anonymize" ? [schemaProblemText("anonymize_without_on_delete", {
769
951
  collection,
770
- field: f.key
952
+ field
771
953
  })] : [],
772
954
  ...(f.anonymize ?? []).flatMap((k) => {
773
955
  const g = fields.find((x) => x.key === k);
774
956
  if (!g) return [schemaProblemText("anonymize_field_missing", {
775
957
  collection,
776
- field: f.key,
958
+ field,
777
959
  target: k
778
960
  })];
779
961
  if (UNCLEARABLE.has(g.type) || g.computed) return [schemaProblemText("anonymize_field_unclearable", {
780
962
  collection,
781
- field: f.key,
963
+ field,
782
964
  target: k,
783
965
  type: g.type
784
966
  })];
785
967
  return isRequired(g) ? [schemaProblemText("anonymize_field_required", {
786
968
  collection,
787
- field: f.key,
969
+ field,
788
970
  target: k
789
971
  })] : [];
790
972
  })
791
973
  ], ...inner];
792
974
  });
975
+ return walk(fields, "");
793
976
  }
794
- /** cascade の循環、人からの深さ、参照の cascade でたどるコレクションの本人の顧客フィールドの誤り */
977
+ /** cascade の循環、人からの深さ、参照の cascade でたどるコレクションの本人のエンドユーザーへの参照のフィールドの誤り */
795
978
  function cascadeProblems(collections) {
796
979
  const holders = (to) => collections.filter((collection) => cascadeTargetsOf(collection).includes(to));
797
980
  const cycleFrom = (start) => {
@@ -821,7 +1004,7 @@ function cascadeProblems(collections) {
821
1004
  depth: d,
822
1005
  max: 4
823
1006
  }));
824
- 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) => schemaProblemText("cascade_self_customer", {
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", {
825
1008
  collection: collection.slug,
826
1009
  field: f.key
827
1010
  })));
@@ -830,52 +1013,69 @@ function cascadeProblems(collections) {
830
1013
  /** 人から cascade でたどれるコレクションを restrict で指す参照の項目の誤り(undeclared は宣言のない参照も拒む) */
831
1014
  function restrictProblems(collections, undeclared) {
832
1015
  const reachable = cascadeDepths(collections);
833
- const walk = (collectionId, fields, path) => fields.flatMap((f) => {
834
- if (f.type === "group") return walk(collectionId, f.fields ?? [], `${path}${f.key}.`);
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}.`);
835
1019
  if (f.type !== "reference" || !f.to || !reachable.has(f.to)) return [];
836
- if (f.onDelete === "restrict") return [schemaProblemText("restrict_reachable", {
837
- collection: collectionId,
1020
+ if (f.on_delete === "restrict") return [schemaProblemText("restrict_reachable", {
1021
+ collection: slug,
838
1022
  field: `${path}${f.key}`,
839
- to: f.to
1023
+ to: slugOf(f.to)
840
1024
  })];
841
- if (undeclared && f.onDelete === void 0) return [schemaProblemText("on_delete_undeclared_reference", {
842
- collection: collectionId,
1025
+ if (undeclared && f.on_delete === void 0) return [schemaProblemText("on_delete_undeclared_reference", {
1026
+ collection: slug,
843
1027
  field: `${path}${f.key}`,
844
- to: f.to,
845
- nested: path ? "yes" : "no"
1028
+ to: slugOf(f.to)
846
1029
  })];
847
1030
  return [];
848
1031
  });
849
- return collections.flatMap((t) => walk(t.id, t.fields, ""));
1032
+ return collections.flatMap((t) => walk(t.slug, t.fields, ""));
850
1033
  }
851
1034
  /** 非公開のコレクションの宣言の誤り(配信に関わる宣言と同時に付けない) */
852
1035
  function privateProblems(t) {
853
1036
  const collection = t.slug;
854
1037
  return [
855
1038
  ...t.format === "object" ? [schemaProblemText("private_object", { collection })] : [],
856
- ...(t.publishing ?? "none") !== "none" ? [schemaProblemText("private_publishing", { collection })] : [],
1039
+ ...t.publication ? [schemaProblemText("private_publication", { collection })] : [],
857
1040
  ...t.pages?.length ? [schemaProblemText("private_pages", { collection })] : [],
858
- ...t.grant !== void 0 ? [schemaProblemText("private_grant", { collection })] : []
1041
+ ...t.entitlement !== void 0 ? [schemaProblemText("private_entitlement", { collection })] : []
859
1042
  ];
860
1043
  }
861
1044
  /** 本文の項目が使用する部品の名前(まとまりの中も、key は項目の key) */
862
- const bodyComponents = (fields) => fields.flatMap((f) => f.type === "rich_text" ? f.profile.components.map((name) => ({
1045
+ const richTextComponents = (fields) => fields.flatMap((f) => f.type === "rich_text" ? f.profile.components.map((name) => ({
863
1046
  key: f.key,
864
1047
  name
865
- })) : bodyComponents(f.fields ?? []));
1048
+ })) : richTextComponents(f.fields ?? []));
866
1049
  /** 参照の項目の参照先(まとまりの中も) */
867
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
+ });
868
1071
  const contentType = z.object({
869
- id: z.string().min(1),
1072
+ id: z.string().refine((v) => isUuidShape(v), schemaProblemText("collection_id_invalid")),
870
1073
  slug: key,
871
1074
  label: z.string().min(1),
872
1075
  description: z.string().optional(),
873
1076
  format: z.enum(["list", "object"]).optional(),
874
- publishing: z.enum([
875
- "none",
876
- "draft",
877
- "review"
878
- ]).optional(),
1077
+ publication: z.boolean().optional(),
1078
+ publishing: z.never({ message: schemaProblemText("publishing_renamed") }).optional(),
879
1079
  fields: z.array(field),
880
1080
  pages: z.array(page).optional(),
881
1081
  counts: z.array(z.object({
@@ -884,19 +1084,31 @@ const contentType = z.object({
884
1084
  field: fieldKey
885
1085
  })).optional(),
886
1086
  og: z.string().startsWith("/", schemaProblemText("og_path_slash")).optional(),
887
- slugMode: z.enum(SLUG_MODES).optional(),
1087
+ slug_mode: z.enum(SLUG_MODES).optional(),
888
1088
  roles: z.partialRecord(z.enum(FIELD_ROLES), fieldKey).optional(),
889
- grant: fieldKey.optional(),
890
- entitlement: z.never({ message: schemaProblemText("entitlement_renamed") }).optional(),
1089
+ entitlement: fieldKey.optional(),
1090
+ grant: z.never({ message: schemaProblemText("grant_renamed") }).optional(),
891
1091
  private: z.boolean().optional(),
892
1092
  unique: z.array(z.object({
893
1093
  key: fieldKey,
894
1094
  fields: z.array(fieldKey),
895
1095
  exact: z.boolean().optional()
896
1096
  })).optional(),
897
- selfOps: z.array(z.enum(SELF_OPS)).optional(),
898
- retentionDays: z.number().int().positive().max(RETENTION_DAYS_MAX).optional(),
899
- publishChecks: z.array(z.string().min(1)).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()
900
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) => {
901
1113
  const fields = t.fields;
902
1114
  const asCollection = t;
@@ -928,22 +1140,33 @@ const contentType = z.object({
928
1140
  });
929
1141
  const problems = [
930
1142
  ...computedProblems(t.slug, fields),
931
- ...audienceProblems(t.slug, fields, t.grant),
1143
+ ...audienceProblems(t.slug, fields, t.entitlement),
932
1144
  ...derivedAudienceProblems({
933
1145
  ...t,
934
1146
  fields
935
1147
  }),
936
- ...customerFieldProblems(t.slug, fields),
1148
+ ...endUserFieldProblems(t.slug, fields),
937
1149
  ...integrityProblems(asCollection),
938
1150
  ...transitionProblems(asCollection),
939
1151
  ...onDeleteProblems(t.slug, fields),
940
1152
  ...selfOpsProblems(asCollection),
941
- ...selfWritableProblems(asCollection)
1153
+ ...selfWritableProblems(asCollection),
1154
+ ...formProblems(asCollection),
1155
+ ...kindProblems(asCollection)
942
1156
  ];
943
1157
  for (const m of problems) ctx.addIssue({
944
1158
  code: "custom",
945
1159
  message: m
946
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
+ });
947
1170
  if (t.private) for (const m of privateProblems(t)) ctx.addIssue({
948
1171
  code: "custom",
949
1172
  message: m,
@@ -961,6 +1184,17 @@ z.object({
961
1184
  to
962
1185
  })
963
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
+ });
964
1198
  for (const t of ts) {
965
1199
  const keys = new Set(t.fields.map((f) => f.key));
966
1200
  for (const c of t.counts ?? []) {
@@ -1010,7 +1244,7 @@ z.object({
1010
1244
  })
1011
1245
  }).superRefine((m, ctx) => {
1012
1246
  const known = /* @__PURE__ */ new Set([...CORE_COMPONENTS.map((c) => c.name), ...(m.components ?? []).map((c) => c.name)]);
1013
- for (const t of m.collections) for (const { key, name } of bodyComponents(t.fields)) if (!known.has(name)) ctx.addIssue({
1247
+ for (const t of m.collections) for (const { key, name } of richTextComponents(t.fields)) if (!known.has(name)) ctx.addIssue({
1014
1248
  code: "custom",
1015
1249
  message: schemaProblemText("component_unknown", {
1016
1250
  collection: t.slug,
@@ -1020,15 +1254,14 @@ z.object({
1020
1254
  });
1021
1255
  });
1022
1256
  /** コレクションの一覧として読めるか(コレクションごとに id・スラッグと項目の配列) */
1023
- 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));
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));
1024
1258
  /**
1025
1259
  * 保存した版とファイルの読み込み(寛容: 旧い語を今の名前にした値をそのまま返し、規則で拒まない、既定を書き込まない)
1026
1260
  * - コレクションの一覧として読めない値だけ例外(壊れた版)
1027
1261
  * - 見える範囲などの読み替えは audienceOf と resolvedSchema(保存の形には書き戻さない)
1028
1262
  */
1029
1263
  function parseSchema(json) {
1030
- const normalized = normalizeLegacySchema(json);
1031
- if (!readable(normalized)) throw new Error("schema_unreadable");
1032
- return normalized;
1264
+ if (!readable(json)) throw new Error("schema_unreadable");
1265
+ return json;
1033
1266
  }
1034
- export { requiredPrimaryCollectionOf as a, selfOpsOf as c, dateRoleFieldsOf as i, schemaProblemText as l, fieldDefSchema as n, sourceIdsOf as o, parseSchema as r, sourcesFieldOf as s, RESERVED_FIELD_KEYS as t };
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 };