@tunasand/sdk 0.8.0 → 0.12.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 (221) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/README.md +165 -144
  3. package/dist/analytics.js +183 -109
  4. package/dist/app.js +276 -166
  5. package/dist/apps-BysPfMuR.js +408 -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-C2Bl-OAF.js +80 -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-26aglrg6.js +282 -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-DY6O5TrJ.js +29 -0
  27. package/dist/end-users.d.ts +1 -0
  28. package/dist/end-users.js +189 -0
  29. package/dist/endUsers-DODfjnv1.js +77 -0
  30. package/dist/{errorLabels-BgtQ_zUn.js → errorLabels-BK1NJ6Wz.js} +374 -238
  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-B3lAaOhZ.js} +91 -45
  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/paymentPort-p1jV44Zz.js +203 -0
  41. package/dist/preview.js +8 -1
  42. package/dist/{profile-1em_lcxq.js → profile-DBsXLvvI.js} +48 -48
  43. package/dist/rich-text.js +16 -16
  44. package/dist/{schema-WnobuwLg.js → schema-Bs_BUUNv.js} +526 -265
  45. package/dist/schema.js +66 -88
  46. package/dist/types/access/src/handoff.d.ts +19 -14
  47. package/dist/types/access/src/index.d.ts +2 -2
  48. package/dist/types/access/src/jws.d.ts +41 -0
  49. package/dist/types/access/src/oidc.d.ts +12 -2
  50. package/dist/types/access/src/signed.d.ts +0 -2
  51. package/dist/types/adapter-cloudflare/src/eventLog/viewSchema.d.ts +11 -0
  52. package/dist/types/contract/src/accountProfile.d.ts +7 -0
  53. package/dist/types/contract/src/api/define.d.ts +165 -0
  54. package/dist/types/contract/src/apiKeys.d.ts +6 -2
  55. package/dist/types/contract/src/app.d.ts +32 -7
  56. package/dist/types/contract/src/appChannels.d.ts +152 -0
  57. package/dist/types/contract/src/appDefinition.d.ts +11 -5
  58. package/dist/types/contract/src/appDependencies.d.ts +107 -24
  59. package/dist/types/contract/src/appIdentities.d.ts +21 -0
  60. package/dist/types/contract/src/appInbound.d.ts +53 -0
  61. package/dist/types/contract/src/appMail.d.ts +106 -0
  62. package/dist/types/contract/src/appSecrets.d.ts +63 -0
  63. package/dist/types/contract/src/appServer.d.ts +460 -45
  64. package/dist/types/contract/src/approvals.d.ts +1 -1
  65. package/dist/types/contract/src/apps.d.ts +126 -60
  66. package/dist/types/contract/src/auditActions.d.ts +2 -2
  67. package/dist/types/contract/src/auditLabels.d.ts +120 -15
  68. package/dist/types/contract/src/authorize.d.ts +42 -14
  69. package/dist/types/contract/src/bridge.d.ts +35 -36
  70. package/dist/types/contract/src/consents.d.ts +29 -27
  71. package/dist/types/contract/src/deletion.d.ts +18 -0
  72. package/dist/types/contract/src/embeds.d.ts +26 -90
  73. package/dist/types/contract/src/{customerLabels.d.ts → endUserLabels.d.ts} +6 -9
  74. package/dist/types/contract/src/endUsers.d.ts +244 -0
  75. package/dist/types/contract/src/errorLabels.d.ts +67 -37
  76. package/dist/types/contract/src/errorLabelsEn.d.ts +50 -33
  77. package/dist/types/contract/src/errors.d.ts +28 -16
  78. package/dist/types/contract/src/eventSchemas.d.ts +70 -0
  79. package/dist/types/contract/src/eventTraces.d.ts +41 -0
  80. package/dist/types/contract/src/failureStatus.d.ts +14 -22
  81. package/dist/types/contract/src/fieldAccess.d.ts +8 -8
  82. package/dist/types/contract/src/formLabels.d.ts +3 -0
  83. package/dist/types/contract/src/forms.d.ts +4 -0
  84. package/dist/types/contract/src/grants.d.ts +26 -0
  85. package/dist/types/contract/src/headers.d.ts +5 -0
  86. package/dist/types/contract/src/hostingRpc.d.ts +44 -19
  87. package/dist/types/contract/src/identifiers.d.ts +45 -17
  88. package/dist/types/contract/src/ids.d.ts +18 -10
  89. package/dist/types/contract/src/import.d.ts +17 -16
  90. package/dist/types/contract/src/index.d.ts +57 -29
  91. package/dist/types/contract/src/integrationGraph.d.ts +83 -0
  92. package/dist/types/contract/src/issueLabels.d.ts +121 -81
  93. package/dist/types/contract/src/issueLabelsEn.d.ts +61 -41
  94. package/dist/types/contract/src/manage.d.ts +16 -7
  95. package/dist/types/contract/src/manageLabels.d.ts +2 -0
  96. package/dist/types/contract/src/manifestText.d.ts +66 -0
  97. package/dist/types/contract/src/messagePort.d.ts +208 -0
  98. package/dist/types/contract/src/migration.d.ts +2 -2
  99. package/dist/types/contract/src/notices.d.ts +37 -0
  100. package/dist/types/contract/src/operationEffects.d.ts +39 -0
  101. package/dist/types/contract/src/operatorOperations.d.ts +104 -110
  102. package/dist/types/contract/src/outbound.d.ts +29 -0
  103. package/dist/types/contract/src/paths.d.ts +13 -0
  104. package/dist/types/contract/src/paymentPort.d.ts +129 -0
  105. package/dist/types/contract/src/pending.d.ts +2 -0
  106. package/dist/types/contract/src/permissions.d.ts +7 -11
  107. package/dist/types/contract/src/perspective.d.ts +26 -0
  108. package/dist/types/contract/src/powers.d.ts +5 -0
  109. package/dist/types/contract/src/principal.d.ts +127 -56
  110. package/dist/types/contract/src/readPages.d.ts +92 -0
  111. package/dist/types/contract/src/recordLabels.d.ts +6 -0
  112. package/dist/types/contract/src/roles.d.ts +7 -4
  113. package/dist/types/contract/src/ruleLabels.d.ts +16 -0
  114. package/dist/types/contract/src/ruleProblems.d.ts +16 -0
  115. package/dist/types/contract/src/schemaLabels.d.ts +8 -0
  116. package/dist/types/contract/src/settingProblems.d.ts +18 -1
  117. package/dist/types/contract/src/settings.d.ts +5 -7
  118. package/dist/types/contract/src/siteDeclaration.d.ts +7 -7
  119. package/dist/types/contract/src/siteIndex.d.ts +76 -0
  120. package/dist/types/contract/src/transfer.d.ts +1 -1
  121. package/dist/types/contract/src/trial.d.ts +4 -1
  122. package/dist/types/contract/src/versions.d.ts +1 -3
  123. package/dist/types/contract/src/viewEvent.d.ts +0 -9
  124. package/dist/types/contract/src/webhooks.d.ts +24 -3
  125. package/dist/types/contract/src/workflow.d.ts +16 -19
  126. package/dist/types/contract/src/workspaceItems.d.ts +23 -7
  127. package/dist/types/contract/src/workspacePaths.d.ts +1 -1
  128. package/dist/types/rich-text/src/html.d.ts +1 -1
  129. package/dist/types/rich-text/src/index.d.ts +8 -7
  130. package/dist/types/rich-text/src/labels/en.d.ts +1 -1
  131. package/dist/types/rich-text/src/labels/ja.d.ts +2 -2
  132. package/dist/types/rich-text/src/library.d.ts +1 -1
  133. package/dist/types/rich-text/src/media.d.ts +2 -0
  134. package/dist/types/rich-text/src/normalize.d.ts +1 -1
  135. package/dist/types/rich-text/src/problems.d.ts +5 -5
  136. package/dist/types/rich-text/src/profile.d.ts +10 -10
  137. package/dist/types/rich-text/src/render.d.ts +1 -1
  138. package/dist/types/rich-text/src/schema.d.ts +2 -2
  139. package/dist/types/rich-text/src/standard.d.ts +4 -4
  140. package/dist/types/rich-text/src/types.d.ts +2 -2
  141. package/dist/types/schema/src/audience.d.ts +1 -3
  142. package/dist/types/schema/src/capabilities.d.ts +18 -27
  143. package/dist/types/schema/src/changes.d.ts +3 -1
  144. package/dist/types/schema/src/collection.d.ts +142 -111
  145. package/dist/types/schema/src/defaultSchema.d.ts +8 -2
  146. package/dist/types/schema/src/fieldIds.d.ts +18 -0
  147. package/dist/types/schema/src/file.d.ts +24 -11
  148. package/dist/types/schema/src/fileRefs.d.ts +14 -0
  149. package/dist/types/schema/src/fileSignature.d.ts +20 -0
  150. package/dist/types/schema/src/filesCollection.d.ts +7 -0
  151. package/dist/types/schema/src/forms.d.ts +43 -0
  152. package/dist/types/schema/src/imageMetadata.d.ts +9 -0
  153. package/dist/types/schema/src/index.d.ts +19 -10
  154. package/dist/types/schema/src/indexes.d.ts +11 -0
  155. package/dist/types/schema/src/input.d.ts +1 -1
  156. package/dist/types/schema/src/integrity.d.ts +8 -7
  157. package/dist/types/schema/src/kinds.d.ts +26 -0
  158. package/dist/types/schema/src/labels/en.d.ts +89 -46
  159. package/dist/types/schema/src/labels/ja.d.ts +92 -46
  160. package/dist/types/schema/src/mediaUrl.d.ts +26 -33
  161. package/dist/types/schema/src/page.d.ts +4 -4
  162. package/dist/types/schema/src/problems.d.ts +85 -42
  163. package/dist/types/schema/src/refs.d.ts +0 -9
  164. package/dist/types/schema/src/schema.d.ts +17 -12
  165. package/dist/types/schema/src/selfOps.d.ts +20 -19
  166. package/dist/types/schema/src/traits.d.ts +28 -0
  167. package/dist/types/schema/src/typesSource.d.ts +1 -1
  168. package/dist/types/schema/src/values.d.ts +5 -2
  169. package/dist/types/schema/src/widening.d.ts +3 -0
  170. package/dist/types/sdk/src/analytics.d.ts +2 -1
  171. package/dist/types/sdk/src/app.d.ts +43 -14
  172. package/dist/types/sdk/src/astro-image.d.ts +19 -0
  173. package/dist/types/sdk/src/astro-response.d.ts +6 -0
  174. package/dist/types/sdk/src/astro-server.d.ts +16 -0
  175. package/dist/types/sdk/src/astro.d.ts +19 -0
  176. package/dist/types/sdk/src/bridge.d.ts +2 -4
  177. package/dist/types/sdk/src/code.d.ts +61 -0
  178. package/dist/types/sdk/src/delegation.d.ts +13 -3
  179. package/dist/types/sdk/src/delivery/changes.d.ts +4 -4
  180. package/dist/types/sdk/src/delivery/client.d.ts +33 -22
  181. package/dist/types/sdk/src/delivery/fields.d.ts +3 -3
  182. package/dist/types/sdk/src/delivery/index.d.ts +3 -3
  183. package/dist/types/sdk/src/delivery/media.d.ts +5 -8
  184. package/dist/types/sdk/src/delivery/query.d.ts +15 -11
  185. package/dist/types/sdk/src/delivery/schema.d.ts +1 -1
  186. package/dist/types/sdk/src/delivery/values.d.ts +10 -14
  187. package/dist/types/sdk/src/delivery.d.ts +2 -2
  188. package/dist/types/sdk/src/dev-operations.d.ts +20 -0
  189. package/dist/types/sdk/src/dev.d.ts +6 -5
  190. package/dist/types/sdk/src/end-users.d.ts +187 -0
  191. package/dist/types/sdk/src/i18n.d.ts +2 -2
  192. package/dist/types/sdk/src/integrations.d.ts +14 -21
  193. package/dist/types/sdk/src/operations.d.ts +17 -0
  194. package/dist/types/sdk/src/preview.d.ts +2 -1
  195. package/dist/types/sdk/src/rich-text.d.ts +2 -2
  196. package/dist/types/sdk/src/schema.d.ts +1 -1
  197. package/dist/types/sdk/src/site/artifact.d.ts +64 -0
  198. package/dist/types/sdk/src/site/build-file.d.ts +30 -0
  199. package/dist/types/sdk/src/site/check-code.d.ts +14 -0
  200. package/dist/types/sdk/src/site/check-text.d.ts +19 -0
  201. package/dist/types/sdk/src/site/cli.d.ts +52 -0
  202. package/dist/types/sdk/src/site/content-type.d.ts +2 -0
  203. package/dist/types/sdk/src/site/labels.d.ts +14 -0
  204. package/dist/types/sdk/src/types.d.ts +1 -1
  205. package/dist/{types-B77qvqPJ.js → types-CYnY-63C.js} +5 -6
  206. package/dist/types.js +1 -1
  207. package/dist/{typesSource-CWybQYus.js → typesSource-BTA9-rcB.js} +17 -15
  208. package/package.json +32 -6
  209. package/dist/apps-BxnJ1RlU.js +0 -435
  210. package/dist/bridge-DtHw9hS6.js +0 -74
  211. package/dist/collection-BEOxeISR.js +0 -189
  212. package/dist/customers-DTbL0qn6.js +0 -86
  213. package/dist/customers.d.ts +0 -1
  214. package/dist/customers.js +0 -185
  215. package/dist/embeds-B5V54Zur.js +0 -34
  216. package/dist/ids--RF7hGyC.js +0 -36
  217. package/dist/src-sazhzYui.js +0 -71
  218. package/dist/types/contract/src/customers.d.ts +0 -266
  219. package/dist/types/schema/src/legacy.d.ts +0 -2
  220. package/dist/types/schema/src/media.d.ts +0 -5
  221. 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-B3lAaOhZ.js";
4
+ import { A as isSurveyShape, C as isInputField, D as isSequenceField, M as narrower, O as isSingleton, R as isFilesCollection, a as PII_CLASSES, b as initialValueOf, c as STATUS_CATEGORIES, d as cascadeDepths, f as cascadeTargetsOf, g as endUserFieldsOf, h as declaredAudienceOf, i as ON_DELETE, j as isUuidShape, 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 fieldPiiOf, w as isListCollection, y as hasPublication } from "./collection-26aglrg6.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,204 @@ 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
- };
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/indexes.ts
485
+ /** 1つのコレクションの索引の上限(仕組みの列と外部キーの列を除く。docs/specs/limits.md の「一覧と索引の上限」) */
486
+ const COLLECTION_INDEX_LIMITS = { indexesMax: 8 };
487
+ const INDEXABLE_TYPES = /* @__PURE__ */ new Set([
488
+ "text",
489
+ "select",
490
+ "status",
491
+ "boolean",
492
+ "number",
493
+ "date",
494
+ "datetime"
495
+ ]);
496
+ /** 索引を宣言できるフィールドか */
497
+ const isIndexableField = (collection, f) => isListCollection(collection) && INDEXABLE_TYPES.has(f.type) && !("multiple" in f && f.multiple) && fieldPiiOf(collection, f) !== "sensitive";
498
+ /** 索引の宣言の誤り(宣言できないフィールドの true と、宣言の true の上限の超過。スキーマの保存で拒む) */
499
+ function indexProblems(collection) {
500
+ const declared = collection.fields.filter((f) => f.index === true);
501
+ return [...declared.filter((f) => !isIndexableField(collection, f)).map((f) => schemaProblemText("index_field_invalid", {
502
+ collection: collection.slug,
503
+ field: f.key
504
+ })), ...declared.length > COLLECTION_INDEX_LIMITS.indexesMax ? [schemaProblemText("indexes_too_many", {
505
+ collection: collection.slug,
506
+ max: COLLECTION_INDEX_LIMITS.indexesMax
507
+ })] : []];
327
508
  }
509
+ // ../schema/src/fieldIds.ts
510
+ /** 内部の id の形(UUID v7 の正規の文字列) */
511
+ 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
512
  // ../schema/src/schema.ts
329
513
  /** 保持の日数の上限(100年) */
330
514
  const RETENTION_DAYS_MAX = 36500;
331
- const key = z.string().regex(/^[a-z][a-z0-9_]*$/, schemaProblemText("invalid_collection_id"));
515
+ /** コレクションのスラッグの形 */
516
+ const COLLECTION_SLUG_PATTERN = /^[a-z][a-z0-9_]*$/;
517
+ const key = z.string().regex(COLLECTION_SLUG_PATTERN, schemaProblemText("invalid_collection_id"));
332
518
  const fieldKey = z.string().regex(/^[a-z][a-zA-Z0-9_-]*$/, schemaProblemText("invalid_field_key"));
333
519
  const condition = z.object({
334
520
  key: fieldKey,
@@ -343,6 +529,7 @@ const computed = z.object({
343
529
  from: fieldKey
344
530
  });
345
531
  const base = {
532
+ id: z.string().regex(FIELD_ID_PATTERN, schemaProblemText("field_id_invalid")).optional(),
346
533
  key: fieldKey,
347
534
  label: z.string().min(1),
348
535
  description: z.string().optional(),
@@ -354,11 +541,13 @@ const base = {
354
541
  ]).optional(),
355
542
  when: condition.optional(),
356
543
  audience: z.enum(AUDIENCES).optional(),
357
- adminOnly: z.boolean().optional(),
358
- selfWritable: z.boolean().optional(),
359
- pendingUntil: fieldKey.optional(),
544
+ admin_only: z.boolean().optional(),
545
+ self_writable: z.boolean().optional(),
546
+ pending_until: fieldKey.optional(),
360
547
  computed: computed.optional(),
361
- pii: z.enum(PII_CLASSES).optional()
548
+ managed: z.enum(MANAGED_FIELDS).optional(),
549
+ pii: z.enum(PII_CLASSES).optional(),
550
+ index: z.boolean().optional()
362
551
  };
363
552
  const frame = z.object({
364
553
  when: condition.optional(),
@@ -376,7 +565,7 @@ const pageRule = z.union([
376
565
  }),
377
566
  z.object({
378
567
  key: z.string().min(1),
379
- notIn: z.array(z.string())
568
+ not_in: z.array(z.string())
380
569
  }),
381
570
  z.object({
382
571
  key: z.string().min(1),
@@ -384,7 +573,7 @@ const pageRule = z.union([
384
573
  }),
385
574
  z.object({
386
575
  key: z.string().min(1),
387
- notFuture: z.literal(true)
576
+ not_future: z.literal(true)
388
577
  })
389
578
  ]);
390
579
  const page = z.object({
@@ -402,11 +591,11 @@ const transition = z.object({
402
591
  roles: z.array(z.string().min(1)).optional(),
403
592
  self: z.boolean().optional(),
404
593
  apps: z.array(z.string().min(1)).optional()
405
- })
594
+ }).optional()
406
595
  });
407
596
  const counts = {
408
- minItems: z.number().int().nonnegative().optional(),
409
- maxItems: z.number().int().positive().optional()
597
+ min_items: z.number().int().nonnegative().optional(),
598
+ max_items: z.number().int().positive().optional()
410
599
  };
411
600
  const regex = z.string().refine((p) => {
412
601
  try {
@@ -422,11 +611,11 @@ const fieldUnion = z.discriminatedUnion("type", [
422
611
  ...base,
423
612
  ...counts,
424
613
  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(),
614
+ external_id: z.boolean().optional(),
615
+ max_length: z.number().int().positive().optional(),
616
+ min_length: z.number().int().positive().optional(),
428
617
  pattern: regex.optional(),
429
- guideLength: z.number().int().positive().optional(),
618
+ guide_length: z.number().int().positive().optional(),
430
619
  multiple: z.boolean().optional()
431
620
  }),
432
621
  z.object({
@@ -479,7 +668,7 @@ const fieldUnion = z.discriminatedUnion("type", [
479
668
  map: z.record(z.string(), z.string()),
480
669
  otherwise: z.string()
481
670
  }).optional(),
482
- fixedBy: z.object({
671
+ fixed_by: z.object({
483
672
  ref: fieldKey,
484
673
  key: fieldKey,
485
674
  map: z.record(z.string(), z.string())
@@ -491,9 +680,28 @@ const fieldUnion = z.discriminatedUnion("type", [
491
680
  }).refine((f) => !f.derive || [...Object.values(f.derive.map), f.derive.otherwise].every((v) => f.options.some((o) => o.value === v)), {
492
681
  message: schemaProblemText("derive_not_option"),
493
682
  path: ["derive"]
494
- }).refine((f) => !f.fixedBy || Object.values(f.fixedBy.map).every((v) => f.options.some((o) => o.value === v)), {
683
+ }).refine((f) => !f.fixed_by || Object.values(f.fixed_by.map).every((v) => f.options.some((o) => o.value === v)), {
495
684
  message: schemaProblemText("fixed_not_option"),
496
- path: ["fixedBy"]
685
+ path: ["fixed_by"]
686
+ }),
687
+ z.object({
688
+ ...base,
689
+ type: z.literal("status"),
690
+ options: z.array(z.object({
691
+ value: z.string().min(1),
692
+ label: z.string().min(1),
693
+ category: z.enum(STATUS_CATEGORIES),
694
+ tone: z.enum([
695
+ "positive",
696
+ "caution",
697
+ "neutral"
698
+ ]).optional()
699
+ })).min(1),
700
+ initial: z.string().optional(),
701
+ transitions: z.array(transition).optional()
702
+ }).refine((f) => f.initial === void 0 || f.options.some((o) => o.value === f.initial), {
703
+ message: schemaProblemText("initial_not_option"),
704
+ path: ["initial"]
497
705
  }),
498
706
  z.object({
499
707
  ...base,
@@ -503,12 +711,15 @@ const fieldUnion = z.discriminatedUnion("type", [
503
711
  multiple: z.boolean().optional(),
504
712
  where: z.record(z.string(), z.string()).optional(),
505
713
  requests: z.boolean().optional(),
506
- emptyLabel: z.string().min(1).optional(),
714
+ empty_label: z.string().min(1).optional(),
507
715
  unique: z.boolean().optional(),
508
716
  published: z.boolean().optional(),
509
- linkedBy: fieldKey.optional(),
510
- onDelete: z.enum(ON_DELETE).optional(),
717
+ linked_by: fieldKey.optional(),
718
+ on_delete: z.enum(ON_DELETE).optional(),
511
719
  anonymize
720
+ }).refine((f) => !f.requests || f.multiple === true, {
721
+ message: schemaProblemText("requests_single"),
722
+ path: ["requests"]
512
723
  }),
513
724
  z.object({
514
725
  ...base,
@@ -517,12 +728,12 @@ const fieldUnion = z.discriminatedUnion("type", [
517
728
  accept: z.array(z.enum(["image", "video"])).optional(),
518
729
  multiple: z.boolean().optional(),
519
730
  frames: z.array(frame).optional(),
520
- visibility: z.literal("private").optional()
731
+ restricted_files: z.literal(true).optional()
521
732
  }),
522
733
  z.object({
523
734
  ...base,
524
735
  type: z.literal("rich_text"),
525
- visibility: z.literal("private").optional(),
736
+ restricted_files: z.literal(true).optional(),
526
737
  profile: z.object({
527
738
  headings: z.array(z.number()),
528
739
  marks: z.array(z.string()),
@@ -532,20 +743,20 @@ const fieldUnion = z.discriminatedUnion("type", [
532
743
  z.object({
533
744
  ...base,
534
745
  ...counts,
535
- type: z.literal("group"),
746
+ type: z.literal("object"),
536
747
  fields: z.array(field),
537
748
  multiple: z.boolean().optional()
538
749
  }),
539
750
  z.object({
540
751
  ...base,
541
- type: z.literal("customer"),
752
+ type: z.literal("end_user"),
542
753
  unique: z.boolean().optional(),
543
754
  self: z.boolean().optional(),
544
- onDelete: z.enum(ON_DELETE).optional(),
755
+ on_delete: z.enum(ON_DELETE).optional(),
545
756
  anonymize
546
- }).refine((f) => f.onDelete !== "restrict", {
547
- message: schemaProblemText("customer_restrict"),
548
- path: ["onDelete"]
757
+ }).refine((f) => f.on_delete !== "restrict", {
758
+ message: schemaProblemText("end_user_restrict"),
759
+ path: ["on_delete"]
549
760
  })
550
761
  ]);
551
762
  /** 条件が一覧にある選択肢の項目と値を指すか */
@@ -554,12 +765,12 @@ const conditionValid = (when, fields) => {
554
765
  return !when || target !== void 0 && when.in.every((v) => target.options.some((o) => o.value === v));
555
766
  };
556
767
  /** 条件が同じ階層の選択肢の項目と値を指すか(まとまりの中も) */
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 ?? []));
768
+ 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
769
  /** まとまりの中で決まる値・参照先で固定を持つ項目の 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}`)]));
770
+ 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
771
  /**
561
772
  * システムの値と同じ名前で、項目の key に使用できない名前(API・配信が項目の値を上書きするため)
562
- * - すべてのコレクション: レコードの ID とスラッグ・作成と更新の日時・作成者、ワークスペースの一覧で参照する行の数 uses
773
+ * - すべてのコレクション: レコードの ID とスラッグ・作成と更新の日時・作成者、ワークスペースの一覧で参照する行の数 uses、一覧の持ち主の絞り込み owned
563
774
  * - 公開の管理があるコレクション: 公開の機能の値
564
775
  * - 対象外: API・配信の値に出ない列 type、導入先の設定で決まるアカウントの email・account_role
565
776
  */
@@ -569,7 +780,8 @@ const RESERVED = [
569
780
  "created_at",
570
781
  "created_by",
571
782
  "updated_at",
572
- "uses"
783
+ "uses",
784
+ "owned"
573
785
  ];
574
786
  const RESERVED_EDITORIAL = [
575
787
  "status",
@@ -593,7 +805,7 @@ const RESERVED_FIELD_KEYS = [
593
805
  ];
594
806
  /** 予約の名前と同じ最上位の key */
595
807
  function reservedKeysOf(t) {
596
- const reserved = [...RESERVED, ...(t.publishing ?? "none") !== "none" ? RESERVED_EDITORIAL : []];
808
+ const reserved = [...RESERVED, ...t.publication ? RESERVED_EDITORIAL : []];
597
809
  return [...t.fields.map((f) => f.key), ...(t.counts ?? []).map((c) => c.key)].filter((k) => reserved.includes(k));
598
810
  }
599
811
  /** 計算の種類ごとに受け付ける項目の種類 */
@@ -638,30 +850,30 @@ const roleProblems = (collection, roles, fields) => Object.entries(roles).flatMa
638
850
  type: f.type
639
851
  })];
640
852
  });
641
- /** 見える範囲の宣言の誤り(顧客フィールドは本人かスタッフ、本人の項目は本人の印を持つコレクション、まとまりの中は外側と同じかスタッフ、要る権利は配信する参照) */
642
- function audienceProblems(collection, fields, grant) {
643
- const hasSelf = fields.some((f) => f.type === "customer" && f.self);
853
+ /** 見える範囲の宣言の誤り(エンドユーザーへの参照のフィールドは本人かスタッフ、本人の項目は本人の印を持つコレクション、まとまりの中は外側と同じかスタッフ、要る権利は配信する参照) */
854
+ function audienceProblems(collection, fields, entitlement) {
855
+ const hasSelf = fields.some((f) => f.type === "end_user" && f.self);
644
856
  const nested = (fs, path, outer) => fs.flatMap((f) => {
645
857
  const own = f.audience ?? outer;
646
- return [...own !== outer && own !== "staff" ? [schemaProblemText("audience_nested_wider", {
858
+ return [...own !== outer && own !== "none" ? [schemaProblemText("audience_nested_wider", {
647
859
  collection,
648
860
  field: `${path}${f.key}`
649
861
  })] : [], ...nested(f.fields ?? [], `${path}${f.key}.`, own)];
650
862
  });
651
- const own = fields.flatMap((f) => [...f.type === "customer" && f.audience !== "self" && f.audience !== "staff" ? [schemaProblemText("audience_customer_field", {
863
+ const own = fields.flatMap((f) => [...f.type === "end_user" && f.audience !== "self" && f.audience !== "none" ? [schemaProblemText("audience_end_user_field", {
652
864
  collection,
653
865
  field: f.key
654
866
  })] : [], ...nested(f.fields ?? [], `${f.key}.`, f.audience ?? "public")]);
655
867
  const anySelf = (fs) => fs.some((f) => f.audience === "self" || anySelf(f.fields ?? []));
656
868
  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);
869
+ if (entitlement === void 0) return [...own, ...self];
870
+ const ref = fields.find((f) => f.key === entitlement);
659
871
  return [
660
872
  ...own,
661
873
  ...self,
662
- ...ref?.type === "reference" && (ref.audience === "public" || ref.audience === "granted") ? [] : [schemaProblemText("grant_not_reference", {
874
+ ...ref?.type === "reference" && (ref.audience === "public" || ref.audience === "entitled") ? [] : [schemaProblemText("entitlement_not_reference", {
663
875
  collection,
664
- grant
876
+ entitlement
665
877
  })]
666
878
  ];
667
879
  }
@@ -708,12 +920,12 @@ function derivedAudienceProblems(t) {
708
920
  ...paths
709
921
  ];
710
922
  }
711
- /** 参照先で固定 fixedBy と被参照の件数 counts の見える範囲の誤り(固定の元は固定する項目より狭くできない、件数は元のコレクションの公開の参照だけ) */
923
+ /** 参照先で固定 fixed_by と被参照の件数 counts の見える範囲の誤り(固定の元は固定する項目より狭くできない、件数は元のコレクションの公開の参照だけ) */
712
924
  function crossCollectionAudienceProblems(collections) {
713
925
  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", {
926
+ if (!f.fixed_by) return [];
927
+ const ref = t.fields.find((g) => g.key === f.fixed_by.ref);
928
+ 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
929
  collection: t.slug,
718
930
  field: f.key
719
931
  })] : [];
@@ -729,9 +941,9 @@ function crossCollectionAudienceProblems(collections) {
729
941
  }));
730
942
  return [...fixed, ...counts];
731
943
  }
732
- /** 顧客フィールドの誤り(まとまりの中に置かない) */
733
- function customerFieldProblems(collection, fields) {
734
- const nested = (fs, path) => fs.flatMap((f) => [...f.type === "customer" ? [schemaProblemText("customer_field_nested", {
944
+ /** エンドユーザーへの参照のフィールドの誤り(まとまりの中に置かない) */
945
+ function endUserFieldProblems(collection, fields) {
946
+ const nested = (fs, path) => fs.flatMap((f) => [...f.type === "end_user" ? [schemaProblemText("end_user_field_nested", {
735
947
  collection,
736
948
  field: `${path}${f.key}`
737
949
  })] : [], ...nested(f.fields ?? [], `${path}${f.key}.`)]);
@@ -740,58 +952,56 @@ function customerFieldProblems(collection, fields) {
740
952
  /** anonymize で空にできない項目の種類(本文・まとまり・結び付き) */
741
953
  const UNCLEARABLE = /* @__PURE__ */ new Set([
742
954
  "rich_text",
743
- "group",
744
- "customer",
955
+ "object",
956
+ "end_user",
745
957
  "reference"
746
958
  ]);
747
959
  const isRequired = (f) => f.required !== void 0 && f.required !== false;
748
- /** 指す先が消えたときの扱いのコレクションの中の誤り(必須の項目の clear・anonymize、anonymize の項目、まとまりの中の宣言) */
960
+ /** 指す先が消えたときの扱いのコレクションの中の誤り(必須の項目の clear・anonymize、anonymize の項目。まとまりの中の参照も同じ規則、anonymize の項目は最上位) */
749
961
  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;
962
+ const walk = (fs, path) => fs.flatMap((f) => {
963
+ const field = `${path}${f.key}`;
964
+ const inner = walk(f.fields ?? [], `${field}.`);
965
+ if (f.type !== "end_user" && f.type !== "reference") return inner;
757
966
  return [...[
758
- ...isRequired(f) && (f.onDelete === "clear" || f.onDelete === "anonymize") ? [schemaProblemText("on_delete_required", {
967
+ ...isRequired(f) && (f.on_delete === "clear" || f.on_delete === "anonymize") ? [schemaProblemText("on_delete_required", {
759
968
  collection,
760
- field: f.key,
761
- onDelete: f.onDelete
969
+ field,
970
+ on_delete: f.on_delete
762
971
  })] : [],
763
- ...(f.minItems ?? 0) > 0 && (f.onDelete === "clear" || f.onDelete === "anonymize") ? [schemaProblemText("on_delete_min_items", {
972
+ ...(f.min_items ?? 0) > 0 && (f.on_delete === "clear" || f.on_delete === "anonymize") ? [schemaProblemText("on_delete_min_items", {
764
973
  collection,
765
- field: f.key,
766
- onDelete: f.onDelete
974
+ field,
975
+ on_delete: f.on_delete
767
976
  })] : [],
768
- ...f.anonymize && f.onDelete !== "anonymize" ? [schemaProblemText("anonymize_without_on_delete", {
977
+ ...f.anonymize && f.on_delete !== "anonymize" ? [schemaProblemText("anonymize_without_on_delete", {
769
978
  collection,
770
- field: f.key
979
+ field
771
980
  })] : [],
772
981
  ...(f.anonymize ?? []).flatMap((k) => {
773
982
  const g = fields.find((x) => x.key === k);
774
983
  if (!g) return [schemaProblemText("anonymize_field_missing", {
775
984
  collection,
776
- field: f.key,
985
+ field,
777
986
  target: k
778
987
  })];
779
988
  if (UNCLEARABLE.has(g.type) || g.computed) return [schemaProblemText("anonymize_field_unclearable", {
780
989
  collection,
781
- field: f.key,
990
+ field,
782
991
  target: k,
783
992
  type: g.type
784
993
  })];
785
994
  return isRequired(g) ? [schemaProblemText("anonymize_field_required", {
786
995
  collection,
787
- field: f.key,
996
+ field,
788
997
  target: k
789
998
  })] : [];
790
999
  })
791
1000
  ], ...inner];
792
1001
  });
1002
+ return walk(fields, "");
793
1003
  }
794
- /** cascade の循環、人からの深さ、参照の cascade でたどるコレクションの本人の顧客フィールドの誤り */
1004
+ /** cascade の循環、人からの深さ、参照の cascade でたどるコレクションの本人のエンドユーザーへの参照のフィールドの誤り */
795
1005
  function cascadeProblems(collections) {
796
1006
  const holders = (to) => collections.filter((collection) => cascadeTargetsOf(collection).includes(to));
797
1007
  const cycleFrom = (start) => {
@@ -821,7 +1031,7 @@ function cascadeProblems(collections) {
821
1031
  depth: d,
822
1032
  max: 4
823
1033
  }));
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", {
1034
+ 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
1035
  collection: collection.slug,
826
1036
  field: f.key
827
1037
  })));
@@ -830,52 +1040,69 @@ function cascadeProblems(collections) {
830
1040
  /** 人から cascade でたどれるコレクションを restrict で指す参照の項目の誤り(undeclared は宣言のない参照も拒む) */
831
1041
  function restrictProblems(collections, undeclared) {
832
1042
  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}.`);
1043
+ const slugOf = (id) => collections.find((c) => c.id === id)?.slug ?? id;
1044
+ const walk = (slug, fields, path) => fields.flatMap((f) => {
1045
+ if (f.type === "object") return walk(slug, f.fields ?? [], `${path}${f.key}.`);
835
1046
  if (f.type !== "reference" || !f.to || !reachable.has(f.to)) return [];
836
- if (f.onDelete === "restrict") return [schemaProblemText("restrict_reachable", {
837
- collection: collectionId,
1047
+ if (f.on_delete === "restrict") return [schemaProblemText("restrict_reachable", {
1048
+ collection: slug,
838
1049
  field: `${path}${f.key}`,
839
- to: f.to
1050
+ to: slugOf(f.to)
840
1051
  })];
841
- if (undeclared && f.onDelete === void 0) return [schemaProblemText("on_delete_undeclared_reference", {
842
- collection: collectionId,
1052
+ if (undeclared && f.on_delete === void 0) return [schemaProblemText("on_delete_undeclared_reference", {
1053
+ collection: slug,
843
1054
  field: `${path}${f.key}`,
844
- to: f.to,
845
- nested: path ? "yes" : "no"
1055
+ to: slugOf(f.to)
846
1056
  })];
847
1057
  return [];
848
1058
  });
849
- return collections.flatMap((t) => walk(t.id, t.fields, ""));
1059
+ return collections.flatMap((t) => walk(t.slug, t.fields, ""));
850
1060
  }
851
1061
  /** 非公開のコレクションの宣言の誤り(配信に関わる宣言と同時に付けない) */
852
1062
  function privateProblems(t) {
853
1063
  const collection = t.slug;
854
1064
  return [
855
1065
  ...t.format === "object" ? [schemaProblemText("private_object", { collection })] : [],
856
- ...(t.publishing ?? "none") !== "none" ? [schemaProblemText("private_publishing", { collection })] : [],
1066
+ ...t.publication ? [schemaProblemText("private_publication", { collection })] : [],
857
1067
  ...t.pages?.length ? [schemaProblemText("private_pages", { collection })] : [],
858
- ...t.grant !== void 0 ? [schemaProblemText("private_grant", { collection })] : []
1068
+ ...t.entitlement !== void 0 ? [schemaProblemText("private_entitlement", { collection })] : []
859
1069
  ];
860
1070
  }
861
1071
  /** 本文の項目が使用する部品の名前(まとまりの中も、key は項目の key) */
862
- const bodyComponents = (fields) => fields.flatMap((f) => f.type === "rich_text" ? f.profile.components.map((name) => ({
1072
+ const richTextComponents = (fields) => fields.flatMap((f) => f.type === "rich_text" ? f.profile.components.map((name) => ({
863
1073
  key: f.key,
864
1074
  name
865
- })) : bodyComponents(f.fields ?? []));
1075
+ })) : richTextComponents(f.fields ?? []));
866
1076
  /** 参照の項目の参照先(まとまりの中も) */
867
1077
  const referenceTargets = (fields) => fields.flatMap((f) => f.type === "reference" ? [f.to] : referenceTargets(f.fields ?? []));
1078
+ const formDef = z.strictObject({
1079
+ submitter: z.enum(FORM_SUBMITTERS),
1080
+ fields: z.array(z.strictObject({
1081
+ key: fieldKey,
1082
+ required_when: z.strictObject({
1083
+ key: fieldKey,
1084
+ in: z.array(z.string().min(1)).min(1)
1085
+ }).optional(),
1086
+ hosts: z.strictObject({
1087
+ site: z.boolean().optional(),
1088
+ exact: z.array(z.string()).optional(),
1089
+ subdomains_of: z.array(z.string()).optional()
1090
+ }).optional()
1091
+ })).min(1),
1092
+ handled: z.strictObject({
1093
+ field: fieldKey,
1094
+ done: z.array(z.string().min(1)).min(1),
1095
+ retention_days: z.number().int().positive().max(RETENTION_DAYS_MAX).optional()
1096
+ }).optional()
1097
+ });
868
1098
  const contentType = z.object({
869
- id: z.string().min(1),
1099
+ id: z.string().refine((v) => isUuidShape(v), schemaProblemText("collection_id_invalid")),
870
1100
  slug: key,
871
1101
  label: z.string().min(1),
872
1102
  description: z.string().optional(),
873
1103
  format: z.enum(["list", "object"]).optional(),
874
- publishing: z.enum([
875
- "none",
876
- "draft",
877
- "review"
878
- ]).optional(),
1104
+ publication: z.boolean().optional(),
1105
+ publishing: z.never({ message: schemaProblemText("publishing_renamed") }).optional(),
879
1106
  fields: z.array(field),
880
1107
  pages: z.array(page).optional(),
881
1108
  counts: z.array(z.object({
@@ -884,19 +1111,31 @@ const contentType = z.object({
884
1111
  field: fieldKey
885
1112
  })).optional(),
886
1113
  og: z.string().startsWith("/", schemaProblemText("og_path_slash")).optional(),
887
- slugMode: z.enum(SLUG_MODES).optional(),
1114
+ slug_mode: z.enum(SLUG_MODES).optional(),
888
1115
  roles: z.partialRecord(z.enum(FIELD_ROLES), fieldKey).optional(),
889
- grant: fieldKey.optional(),
890
- entitlement: z.never({ message: schemaProblemText("entitlement_renamed") }).optional(),
1116
+ entitlement: fieldKey.optional(),
1117
+ grant: z.never({ message: schemaProblemText("grant_renamed") }).optional(),
891
1118
  private: z.boolean().optional(),
892
1119
  unique: z.array(z.object({
893
1120
  key: fieldKey,
894
1121
  fields: z.array(fieldKey),
895
1122
  exact: z.boolean().optional()
896
1123
  })).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()
1124
+ self_ops: z.array(z.enum(SELF_OPS)).optional(),
1125
+ form: formDef.optional(),
1126
+ retention_days: z.number().int().positive().max(RETENTION_DAYS_MAX).optional(),
1127
+ publish_checks: z.array(z.string().min(1)).optional(),
1128
+ trash: z.boolean().optional(),
1129
+ kind: z.enum(DECLARED_COLLECTION_KINDS).optional(),
1130
+ time: fieldKey.optional(),
1131
+ dimensions: z.array(fieldKey).optional(),
1132
+ subject: fieldKey.optional(),
1133
+ source: z.string().refine((v) => isUuidShape(v), schemaProblemText("collection_id_invalid")).optional(),
1134
+ bucket: z.enum(AGGREGATE_BUCKETS).optional(),
1135
+ measures: z.array(z.object({
1136
+ field: fieldKey,
1137
+ op: z.enum(AGGREGATE_OPS)
1138
+ })).optional()
900
1139
  }).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
1140
  const fields = t.fields;
902
1141
  const asCollection = t;
@@ -928,22 +1167,34 @@ const contentType = z.object({
928
1167
  });
929
1168
  const problems = [
930
1169
  ...computedProblems(t.slug, fields),
931
- ...audienceProblems(t.slug, fields, t.grant),
1170
+ ...audienceProblems(t.slug, fields, t.entitlement),
932
1171
  ...derivedAudienceProblems({
933
1172
  ...t,
934
1173
  fields
935
1174
  }),
936
- ...customerFieldProblems(t.slug, fields),
1175
+ ...endUserFieldProblems(t.slug, fields),
937
1176
  ...integrityProblems(asCollection),
938
1177
  ...transitionProblems(asCollection),
939
1178
  ...onDeleteProblems(t.slug, fields),
940
1179
  ...selfOpsProblems(asCollection),
941
- ...selfWritableProblems(asCollection)
1180
+ ...selfWritableProblems(asCollection),
1181
+ ...formProblems(asCollection),
1182
+ ...kindProblems(asCollection),
1183
+ ...indexProblems(asCollection)
942
1184
  ];
943
1185
  for (const m of problems) ctx.addIssue({
944
1186
  code: "custom",
945
1187
  message: m
946
1188
  });
1189
+ for (const n of missingCapabilities({ collections: [asCollection] })) ctx.addIssue({
1190
+ code: "custom",
1191
+ message: schemaProblemText("capability_required", {
1192
+ collection: t.slug,
1193
+ declaration: n.declaration,
1194
+ capability: n.capability
1195
+ }),
1196
+ path: [n.declaration]
1197
+ });
947
1198
  if (t.private) for (const m of privateProblems(t)) ctx.addIssue({
948
1199
  code: "custom",
949
1200
  message: m,
@@ -961,6 +1212,17 @@ z.object({
961
1212
  to
962
1213
  })
963
1214
  });
1215
+ for (const t of ts) if (t.source !== void 0 && !ids.has(t.source)) ctx.addIssue({
1216
+ code: "custom",
1217
+ message: schemaProblemText("reference_target_missing", {
1218
+ collection: t.slug,
1219
+ to: t.source
1220
+ })
1221
+ });
1222
+ for (const t of ts) for (const to of referenceTargets(t.fields)) if (to === "380c5450-9f5e-5b10-8273-c3e1d86aa266") ctx.addIssue({
1223
+ code: "custom",
1224
+ message: schemaProblemText("reference_to_files", { collection: t.slug })
1225
+ });
964
1226
  for (const t of ts) {
965
1227
  const keys = new Set(t.fields.map((f) => f.key));
966
1228
  for (const c of t.counts ?? []) {
@@ -1010,7 +1272,7 @@ z.object({
1010
1272
  })
1011
1273
  }).superRefine((m, ctx) => {
1012
1274
  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({
1275
+ for (const t of m.collections) for (const { key, name } of richTextComponents(t.fields)) if (!known.has(name)) ctx.addIssue({
1014
1276
  code: "custom",
1015
1277
  message: schemaProblemText("component_unknown", {
1016
1278
  collection: t.slug,
@@ -1020,15 +1282,14 @@ z.object({
1020
1282
  });
1021
1283
  });
1022
1284
  /** コレクションの一覧として読めるか(コレクションごとに 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));
1285
+ 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
1286
  /**
1025
1287
  * 保存した版とファイルの読み込み(寛容: 旧い語を今の名前にした値をそのまま返し、規則で拒まない、既定を書き込まない)
1026
1288
  * - コレクションの一覧として読めない値だけ例外(壊れた版)
1027
1289
  * - 見える範囲などの読み替えは audienceOf と resolvedSchema(保存の形には書き戻さない)
1028
1290
  */
1029
1291
  function parseSchema(json) {
1030
- const normalized = normalizeLegacySchema(json);
1031
- if (!readable(normalized)) throw new Error("schema_unreadable");
1032
- return normalized;
1292
+ if (!readable(json)) throw new Error("schema_unreadable");
1293
+ return json;
1033
1294
  }
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 };
1295
+ export { isIndexableField as a, DECLARED_COLLECTION_KINDS as c, parseSchema as i, schemaProblemText as l, RESERVED_FIELD_KEYS as n, AGGREGATE_BUCKETS as o, fieldDefSchema as r, AGGREGATE_OPS as s, COLLECTION_SLUG_PATTERN as t };