primitive-admin 1.2.0-alpha.9 → 1.3.0-alpha.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 (546) hide show
  1. package/README.md +258 -186
  2. package/assets/skill/skills/primitive-platform/SKILL.md +93 -27
  3. package/dist/bin/primitive.js +15 -89
  4. package/dist/bin/primitive.js.map +1 -1
  5. package/dist/src/commands/admins.js +80 -17
  6. package/dist/src/commands/admins.js.map +1 -1
  7. package/dist/src/commands/agent-sessions.d.ts +129 -0
  8. package/dist/src/commands/agent-sessions.js +532 -20
  9. package/dist/src/commands/agent-sessions.js.map +1 -1
  10. package/dist/src/commands/analytics.js +207 -155
  11. package/dist/src/commands/analytics.js.map +1 -1
  12. package/dist/src/commands/apps-children.js +3 -0
  13. package/dist/src/commands/apps-children.js.map +1 -1
  14. package/dist/src/commands/apps-transitions.d.ts +39 -0
  15. package/dist/src/commands/apps-transitions.js +198 -0
  16. package/dist/src/commands/apps-transitions.js.map +1 -0
  17. package/dist/src/commands/apps.d.ts +17 -0
  18. package/dist/src/commands/apps.js +108 -3
  19. package/dist/src/commands/apps.js.map +1 -1
  20. package/dist/src/commands/auth-sessions.js +2 -0
  21. package/dist/src/commands/auth-sessions.js.map +1 -1
  22. package/dist/src/commands/auth.js +138 -44
  23. package/dist/src/commands/auth.js.map +1 -1
  24. package/dist/src/commands/blob-buckets.js +2 -0
  25. package/dist/src/commands/blob-buckets.js.map +1 -1
  26. package/dist/src/commands/collections.js +318 -256
  27. package/dist/src/commands/collections.js.map +1 -1
  28. package/dist/src/commands/comparisons.js +2 -0
  29. package/dist/src/commands/comparisons.js.map +1 -1
  30. package/dist/src/commands/config.d.ts +2 -2
  31. package/dist/src/commands/config.js +59 -33
  32. package/dist/src/commands/config.js.map +1 -1
  33. package/dist/src/commands/connections.js +2 -0
  34. package/dist/src/commands/connections.js.map +1 -1
  35. package/dist/src/commands/database-type-configs.js +5 -3
  36. package/dist/src/commands/database-type-configs.js.map +1 -1
  37. package/dist/src/commands/databases.js +6 -4
  38. package/dist/src/commands/databases.js.map +1 -1
  39. package/dist/src/commands/db3-types.d.ts +15 -0
  40. package/dist/src/commands/db3-types.js +159 -0
  41. package/dist/src/commands/db3-types.js.map +1 -0
  42. package/dist/src/commands/db3.d.ts +24 -0
  43. package/dist/src/commands/db3.js +1444 -0
  44. package/dist/src/commands/db3.js.map +1 -0
  45. package/dist/src/commands/documents.d.ts +110 -10
  46. package/dist/src/commands/documents.js +1012 -748
  47. package/dist/src/commands/documents.js.map +1 -1
  48. package/dist/src/commands/email-templates.js +74 -0
  49. package/dist/src/commands/email-templates.js.map +1 -1
  50. package/dist/src/commands/env.js +8 -4
  51. package/dist/src/commands/env.js.map +1 -1
  52. package/dist/src/commands/function-trigger-commands.d.ts +28 -0
  53. package/dist/src/commands/function-trigger-commands.js +341 -0
  54. package/dist/src/commands/function-trigger-commands.js.map +1 -0
  55. package/dist/src/commands/functions.js +376 -30
  56. package/dist/src/commands/functions.js.map +1 -1
  57. package/dist/src/commands/groups.js +168 -50
  58. package/dist/src/commands/groups.js.map +1 -1
  59. package/dist/src/commands/guides.js +7 -5
  60. package/dist/src/commands/guides.js.map +1 -1
  61. package/dist/src/commands/hosting.d.ts +8 -0
  62. package/dist/src/commands/hosting.js +346 -0
  63. package/dist/src/commands/hosting.js.map +1 -0
  64. package/dist/src/commands/init.js +129 -38
  65. package/dist/src/commands/init.js.map +1 -1
  66. package/dist/src/commands/integrations.js +82 -53
  67. package/dist/src/commands/integrations.js.map +1 -1
  68. package/dist/src/commands/locks.d.ts +5 -3
  69. package/dist/src/commands/locks.js +19 -61
  70. package/dist/src/commands/locks.js.map +1 -1
  71. package/dist/src/commands/metadata-category-configs.d.ts +2 -2
  72. package/dist/src/commands/metadata-category-configs.js +4 -2
  73. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  74. package/dist/src/commands/metadata.js +41 -0
  75. package/dist/src/commands/metadata.js.map +1 -1
  76. package/dist/src/commands/prompts.js +75 -52
  77. package/dist/src/commands/prompts.js.map +1 -1
  78. package/dist/src/commands/rate-counters.d.ts +19 -0
  79. package/dist/src/commands/rate-counters.js +104 -0
  80. package/dist/src/commands/rate-counters.js.map +1 -0
  81. package/dist/src/commands/rule-sets.d.ts +1 -1
  82. package/dist/src/commands/rule-sets.js +2 -1
  83. package/dist/src/commands/rule-sets.js.map +1 -1
  84. package/dist/src/commands/schemas.d.ts +15 -0
  85. package/dist/src/commands/schemas.js +122 -0
  86. package/dist/src/commands/schemas.js.map +1 -0
  87. package/dist/src/commands/scripts.d.ts +9 -17
  88. package/dist/src/commands/scripts.js +24 -479
  89. package/dist/src/commands/scripts.js.map +1 -1
  90. package/dist/src/commands/secrets.js +47 -3
  91. package/dist/src/commands/secrets.js.map +1 -1
  92. package/dist/src/commands/sessions.js +2 -0
  93. package/dist/src/commands/sessions.js.map +1 -1
  94. package/dist/src/commands/skill.js +2 -0
  95. package/dist/src/commands/skill.js.map +1 -1
  96. package/dist/src/commands/sync-schemas.d.ts +202 -0
  97. package/dist/src/commands/sync-schemas.js +629 -0
  98. package/dist/src/commands/sync-schemas.js.map +1 -0
  99. package/dist/src/commands/sync-user-properties.d.ts +118 -0
  100. package/dist/src/commands/sync-user-properties.js +276 -0
  101. package/dist/src/commands/sync-user-properties.js.map +1 -0
  102. package/dist/src/commands/sync.d.ts +518 -546
  103. package/dist/src/commands/sync.js +3010 -4877
  104. package/dist/src/commands/sync.js.map +1 -1
  105. package/dist/src/commands/tokens.js +5 -3
  106. package/dist/src/commands/tokens.js.map +1 -1
  107. package/dist/src/commands/transitions.d.ts +54 -0
  108. package/dist/src/commands/transitions.js +418 -0
  109. package/dist/src/commands/transitions.js.map +1 -0
  110. package/dist/src/commands/usage.d.ts +18 -0
  111. package/dist/src/commands/usage.js +343 -0
  112. package/dist/src/commands/usage.js.map +1 -0
  113. package/dist/src/commands/user-properties.d.ts +14 -0
  114. package/dist/src/commands/user-properties.js +79 -0
  115. package/dist/src/commands/user-properties.js.map +1 -0
  116. package/dist/src/commands/users.js +911 -18
  117. package/dist/src/commands/users.js.map +1 -1
  118. package/dist/src/commands/vars.js +2 -0
  119. package/dist/src/commands/vars.js.map +1 -1
  120. package/dist/src/commands/waitlist.js +39 -4
  121. package/dist/src/commands/waitlist.js.map +1 -1
  122. package/dist/src/commands/workflows.d.ts +5 -83
  123. package/dist/src/commands/workflows.js +57 -2282
  124. package/dist/src/commands/workflows.js.map +1 -1
  125. package/dist/src/lib/analytics-query.d.ts +58 -0
  126. package/dist/src/lib/analytics-query.js +134 -0
  127. package/dist/src/lib/analytics-query.js.map +1 -0
  128. package/dist/src/lib/api-client.d.ts +1818 -438
  129. package/dist/src/lib/api-client.js +965 -544
  130. package/dist/src/lib/api-client.js.map +1 -1
  131. package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
  132. package/dist/src/lib/app-settings-descriptor.js +6 -0
  133. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  134. package/dist/src/lib/auth-fixtures.d.ts +44 -0
  135. package/dist/src/lib/auth-fixtures.js +61 -0
  136. package/dist/src/lib/auth-fixtures.js.map +1 -0
  137. package/dist/src/lib/auth-flow.d.ts +34 -1
  138. package/dist/src/lib/auth-flow.js +429 -13
  139. package/dist/src/lib/auth-flow.js.map +1 -1
  140. package/dist/src/lib/block-layout.d.ts +12 -23
  141. package/dist/src/lib/block-layout.js +26 -92
  142. package/dist/src/lib/block-layout.js.map +1 -1
  143. package/dist/src/lib/block-selector.d.ts +8 -14
  144. package/dist/src/lib/block-selector.js +8 -19
  145. package/dist/src/lib/block-selector.js.map +1 -1
  146. package/dist/src/lib/child-apps-local.d.ts +3 -1
  147. package/dist/src/lib/child-apps-local.js +9 -1
  148. package/dist/src/lib/child-apps-local.js.map +1 -1
  149. package/dist/src/lib/cli-manifest.d.ts +9 -0
  150. package/dist/src/lib/cli-manifest.js +10 -1
  151. package/dist/src/lib/cli-manifest.js.map +1 -1
  152. package/dist/src/lib/cli-version.d.ts +14 -0
  153. package/dist/src/lib/cli-version.js +38 -0
  154. package/dist/src/lib/cli-version.js.map +1 -0
  155. package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
  156. package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
  157. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
  158. package/dist/src/lib/collection-export.d.ts +76 -15
  159. package/dist/src/lib/collection-export.js +116 -23
  160. package/dist/src/lib/collection-export.js.map +1 -1
  161. package/dist/src/lib/collection-principal.d.ts +22 -0
  162. package/dist/src/lib/collection-principal.js +35 -0
  163. package/dist/src/lib/collection-principal.js.map +1 -0
  164. package/dist/src/lib/command-groups.d.ts +30 -0
  165. package/dist/src/lib/command-groups.js +109 -0
  166. package/dist/src/lib/command-groups.js.map +1 -0
  167. package/dist/src/lib/command-status.d.ts +147 -0
  168. package/dist/src/lib/command-status.js +266 -0
  169. package/dist/src/lib/command-status.js.map +1 -0
  170. package/dist/src/lib/config-object-descriptor.d.ts +9 -22
  171. package/dist/src/lib/config-object-descriptor.js +107 -276
  172. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  173. package/dist/src/lib/config-surface.d.ts +3 -7
  174. package/dist/src/lib/config-surface.js +9 -13
  175. package/dist/src/lib/config-surface.js.map +1 -1
  176. package/dist/src/lib/config-toml.d.ts +11 -2
  177. package/dist/src/lib/config-toml.js +25 -2
  178. package/dist/src/lib/config-toml.js.map +1 -1
  179. package/dist/src/lib/credentials-home.d.ts +7 -0
  180. package/dist/src/lib/credentials-home.js +45 -10
  181. package/dist/src/lib/credentials-home.js.map +1 -1
  182. package/dist/src/lib/credentials-lock.d.ts +14 -6
  183. package/dist/src/lib/credentials-lock.js +90 -10
  184. package/dist/src/lib/credentials-lock.js.map +1 -1
  185. package/dist/src/lib/credentials-store.d.ts +123 -70
  186. package/dist/src/lib/credentials-store.js +358 -113
  187. package/dist/src/lib/credentials-store.js.map +1 -1
  188. package/dist/src/lib/custodian.d.ts +8 -0
  189. package/dist/src/lib/custodian.js +18 -0
  190. package/dist/src/lib/custodian.js.map +1 -0
  191. package/dist/src/lib/data-input.d.ts +1 -1
  192. package/dist/src/lib/data-input.js +1 -1
  193. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
  194. package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
  195. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  196. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +38 -1
  197. package/dist/src/lib/db-codegen/dbTypeIR.js +29 -7
  198. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  199. package/dist/src/lib/db-type-records.d.ts +106 -0
  200. package/dist/src/lib/db-type-records.js +224 -0
  201. package/dist/src/lib/db-type-records.js.map +1 -0
  202. package/dist/src/lib/db3-export.d.ts +287 -0
  203. package/dist/src/lib/db3-export.js +647 -0
  204. package/dist/src/lib/db3-export.js.map +1 -0
  205. package/dist/src/lib/db3-index-output.d.ts +116 -0
  206. package/dist/src/lib/db3-index-output.js +223 -0
  207. package/dist/src/lib/db3-index-output.js.map +1 -0
  208. package/dist/src/lib/db3-type-models.d.ts +134 -0
  209. package/dist/src/lib/db3-type-models.js +452 -0
  210. package/dist/src/lib/db3-type-models.js.map +1 -0
  211. package/dist/src/lib/deprecation.d.ts +2 -2
  212. package/dist/src/lib/deprecation.js +2 -2
  213. package/dist/src/lib/document-ingest-artifact.d.ts +13 -0
  214. package/dist/src/lib/document-ingest-artifact.js +36 -6
  215. package/dist/src/lib/document-ingest-artifact.js.map +1 -1
  216. package/dist/src/lib/document-ingest-format2.d.ts +36 -0
  217. package/dist/src/lib/document-ingest-format2.js +78 -0
  218. package/dist/src/lib/document-ingest-format2.js.map +1 -0
  219. package/dist/src/lib/document-ingest-input.d.ts +9 -0
  220. package/dist/src/lib/document-ingest-input.js +28 -1
  221. package/dist/src/lib/document-ingest-input.js.map +1 -1
  222. package/dist/src/lib/document-ingest.d.ts +11 -1
  223. package/dist/src/lib/document-ingest.js +16 -0
  224. package/dist/src/lib/document-ingest.js.map +1 -1
  225. package/dist/src/lib/document-schema-rows.d.ts +42 -0
  226. package/dist/src/lib/document-schema-rows.js +53 -0
  227. package/dist/src/lib/document-schema-rows.js.map +1 -0
  228. package/dist/src/lib/experimental-apis.d.ts +36 -0
  229. package/dist/src/lib/experimental-apis.js +46 -0
  230. package/dist/src/lib/experimental-apis.js.map +1 -0
  231. package/dist/src/lib/file-attachment.d.ts +24 -0
  232. package/dist/src/lib/file-attachment.js +31 -0
  233. package/dist/src/lib/file-attachment.js.map +1 -0
  234. package/dist/src/lib/function-authorize-check.d.ts +142 -0
  235. package/dist/src/lib/function-authorize-check.js +311 -0
  236. package/dist/src/lib/function-authorize-check.js.map +1 -0
  237. package/dist/src/lib/function-authorize-view.d.ts +27 -0
  238. package/dist/src/lib/function-authorize-view.js +88 -0
  239. package/dist/src/lib/function-authorize-view.js.map +1 -0
  240. package/dist/src/lib/function-bundle.d.ts +27 -5
  241. package/dist/src/lib/function-bundle.js +142 -7
  242. package/dist/src/lib/function-bundle.js.map +1 -1
  243. package/dist/src/lib/function-collect.d.ts +90 -12
  244. package/dist/src/lib/function-collect.js +482 -12
  245. package/dist/src/lib/function-collect.js.map +1 -1
  246. package/dist/src/lib/function-db-types.d.ts +65 -11
  247. package/dist/src/lib/function-db-types.js +297 -157
  248. package/dist/src/lib/function-db-types.js.map +1 -1
  249. package/dist/src/lib/function-document-types.d.ts +19 -7
  250. package/dist/src/lib/function-document-types.js +24 -12
  251. package/dist/src/lib/function-document-types.js.map +1 -1
  252. package/dist/src/lib/function-lint.d.ts +57 -0
  253. package/dist/src/lib/function-lint.js +234 -0
  254. package/dist/src/lib/function-lint.js.map +1 -0
  255. package/dist/src/lib/function-log-row.js +21 -2
  256. package/dist/src/lib/function-log-row.js.map +1 -1
  257. package/dist/src/lib/function-run.d.ts +13 -21
  258. package/dist/src/lib/function-run.js +14 -27
  259. package/dist/src/lib/function-run.js.map +1 -1
  260. package/dist/src/lib/function-schema-codegen.d.ts +86 -22
  261. package/dist/src/lib/function-schema-codegen.js +194 -88
  262. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  263. package/dist/src/lib/function-schema-refs.d.ts +98 -0
  264. package/dist/src/lib/function-schema-refs.js +177 -0
  265. package/dist/src/lib/function-schema-refs.js.map +1 -0
  266. package/dist/src/lib/function-sync.d.ts +109 -6
  267. package/dist/src/lib/function-sync.js +179 -26
  268. package/dist/src/lib/function-sync.js.map +1 -1
  269. package/dist/src/lib/function-trigger-listing.d.ts +11 -6
  270. package/dist/src/lib/function-trigger-listing.js +32 -11
  271. package/dist/src/lib/function-trigger-listing.js.map +1 -1
  272. package/dist/src/lib/function-typecheck.d.ts +52 -0
  273. package/dist/src/lib/function-typecheck.js +174 -54
  274. package/dist/src/lib/function-typecheck.js.map +1 -1
  275. package/dist/src/lib/function-versions.d.ts +2 -0
  276. package/dist/src/lib/function-versions.js +1 -0
  277. package/dist/src/lib/function-versions.js.map +1 -1
  278. package/dist/src/lib/generated-build-flags.d.ts +13 -0
  279. package/dist/src/lib/generated-build-flags.js +14 -0
  280. package/dist/src/lib/generated-build-flags.js.map +1 -0
  281. package/dist/src/lib/generated-command-status.d.ts +6 -0
  282. package/dist/src/lib/generated-command-status.js +469 -0
  283. package/dist/src/lib/generated-command-status.js.map +1 -0
  284. package/dist/src/lib/generated-config-surfaces.d.ts +538 -141
  285. package/dist/src/lib/generated-config-surfaces.js +1772 -1854
  286. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  287. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  288. package/dist/src/lib/generated-sdk-types.js +1 -1
  289. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  290. package/dist/src/lib/hosting-build.d.ts +97 -0
  291. package/dist/src/lib/hosting-build.js +204 -0
  292. package/dist/src/lib/hosting-build.js.map +1 -0
  293. package/dist/src/lib/hosting-client.d.ts +167 -0
  294. package/dist/src/lib/hosting-client.js +340 -0
  295. package/dist/src/lib/hosting-client.js.map +1 -0
  296. package/dist/src/lib/hosting-environments.d.ts +32 -0
  297. package/dist/src/lib/hosting-environments.js +74 -0
  298. package/dist/src/lib/hosting-environments.js.map +1 -0
  299. package/dist/src/lib/hosting-errors.d.ts +30 -0
  300. package/dist/src/lib/hosting-errors.js +43 -0
  301. package/dist/src/lib/hosting-errors.js.map +1 -0
  302. package/dist/src/lib/hosting-token.d.ts +46 -0
  303. package/dist/src/lib/hosting-token.js +60 -0
  304. package/dist/src/lib/hosting-token.js.map +1 -0
  305. package/dist/src/lib/hosting-wait.d.ts +42 -0
  306. package/dist/src/lib/hosting-wait.js +84 -0
  307. package/dist/src/lib/hosting-wait.js.map +1 -0
  308. package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
  309. package/dist/src/lib/hosting-wfp-upload.js +149 -0
  310. package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
  311. package/dist/src/lib/init-assets.d.ts +2 -6
  312. package/dist/src/lib/init-assets.js +11 -27
  313. package/dist/src/lib/init-assets.js.map +1 -1
  314. package/dist/src/lib/init-ios-links.d.ts +11 -7
  315. package/dist/src/lib/init-ios-links.js +28 -22
  316. package/dist/src/lib/init-ios-links.js.map +1 -1
  317. package/dist/src/lib/init-login-note.d.ts +13 -0
  318. package/dist/src/lib/init-login-note.js +22 -0
  319. package/dist/src/lib/init-login-note.js.map +1 -0
  320. package/dist/src/lib/init-schema.d.ts +15 -0
  321. package/dist/src/lib/init-schema.js +54 -0
  322. package/dist/src/lib/init-schema.js.map +1 -1
  323. package/dist/src/lib/integration-test-request.d.ts +54 -0
  324. package/dist/src/lib/integration-test-request.js +207 -0
  325. package/dist/src/lib/integration-test-request.js.map +1 -0
  326. package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
  327. package/dist/src/lib/invoker-shared-enums.js +98 -0
  328. package/dist/src/lib/invoker-shared-enums.js.map +1 -0
  329. package/dist/src/lib/json-value.d.ts +6 -0
  330. package/dist/src/lib/json-value.js +13 -0
  331. package/dist/src/lib/json-value.js.map +1 -0
  332. package/dist/src/lib/load-routes.d.ts +33 -0
  333. package/dist/src/lib/load-routes.js +35 -0
  334. package/dist/src/lib/load-routes.js.map +1 -0
  335. package/dist/src/lib/log-inspection.d.ts +23 -4
  336. package/dist/src/lib/log-inspection.js +14 -5
  337. package/dist/src/lib/log-inspection.js.map +1 -1
  338. package/dist/src/lib/login-exchange-check.d.ts +18 -0
  339. package/dist/src/lib/login-exchange-check.js +27 -0
  340. package/dist/src/lib/login-exchange-check.js.map +1 -0
  341. package/dist/src/lib/login-scope-lines.d.ts +17 -7
  342. package/dist/src/lib/login-scope-lines.js +33 -10
  343. package/dist/src/lib/login-scope-lines.js.map +1 -1
  344. package/dist/src/lib/metadata-report.d.ts +85 -0
  345. package/dist/src/lib/metadata-report.js +81 -0
  346. package/dist/src/lib/metadata-report.js.map +1 -0
  347. package/dist/src/lib/object-status-filter.d.ts +9 -1
  348. package/dist/src/lib/object-status-filter.js +9 -1
  349. package/dist/src/lib/object-status-filter.js.map +1 -1
  350. package/dist/src/lib/output.d.ts +1 -1
  351. package/dist/src/lib/output.js +3 -1
  352. package/dist/src/lib/output.js.map +1 -1
  353. package/dist/src/lib/pin-refusal-hint.d.ts +12 -0
  354. package/dist/src/lib/pin-refusal-hint.js +35 -0
  355. package/dist/src/lib/pin-refusal-hint.js.map +1 -0
  356. package/dist/src/lib/platform-owned.js +5 -0
  357. package/dist/src/lib/platform-owned.js.map +1 -1
  358. package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
  359. package/dist/src/lib/primitive-declaration-names.js +22 -0
  360. package/dist/src/lib/primitive-declaration-names.js.map +1 -0
  361. package/dist/src/lib/primitive-declaration.d.ts +174 -0
  362. package/dist/src/lib/primitive-declaration.js +792 -0
  363. package/dist/src/lib/primitive-declaration.js.map +1 -0
  364. package/dist/src/lib/primitive-env-plugin.d.ts +99 -0
  365. package/dist/src/lib/primitive-env-plugin.js +408 -0
  366. package/dist/src/lib/primitive-env-plugin.js.map +1 -0
  367. package/dist/src/lib/project-login-apps.d.ts +8 -0
  368. package/dist/src/lib/project-login-apps.js +27 -0
  369. package/dist/src/lib/project-login-apps.js.map +1 -0
  370. package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
  371. package/dist/src/lib/prompt-schema-codegen.js +96 -100
  372. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  373. package/dist/src/lib/prompt-schema-document.d.ts +35 -0
  374. package/dist/src/lib/prompt-schema-document.js +92 -0
  375. package/dist/src/lib/prompt-schema-document.js.map +1 -0
  376. package/dist/src/lib/prompt-schema-refs.d.ts +173 -0
  377. package/dist/src/lib/prompt-schema-refs.js +478 -0
  378. package/dist/src/lib/prompt-schema-refs.js.map +1 -0
  379. package/dist/src/lib/records-verbs.d.ts +79 -0
  380. package/dist/src/lib/records-verbs.js +45 -0
  381. package/dist/src/lib/records-verbs.js.map +1 -0
  382. package/dist/src/lib/register-commands.d.ts +36 -0
  383. package/dist/src/lib/register-commands.js +37 -0
  384. package/dist/src/lib/register-commands.js.map +1 -0
  385. package/dist/src/lib/retired-imports.d.ts +53 -0
  386. package/dist/src/lib/retired-imports.js +120 -0
  387. package/dist/src/lib/retired-imports.js.map +1 -0
  388. package/dist/src/lib/run-status.d.ts +1 -1
  389. package/dist/src/lib/run-status.generated.d.ts +2 -2
  390. package/dist/src/lib/run-status.generated.js +3 -1
  391. package/dist/src/lib/run-status.generated.js.map +1 -1
  392. package/dist/src/lib/run-status.js +1 -1
  393. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
  394. package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
  395. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
  396. package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
  397. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +227 -0
  398. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
  399. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
  400. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
  401. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
  402. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +218 -0
  403. package/dist/src/lib/schema-codegen/generated-field-grammar.js +397 -0
  404. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
  405. package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
  406. package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
  407. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
  408. package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
  409. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
  410. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
  411. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +258 -0
  412. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +422 -0
  413. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -0
  414. package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
  415. package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
  416. package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
  417. package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
  418. package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
  419. package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
  420. package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
  421. package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
  422. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
  423. package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
  424. package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
  425. package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
  426. package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
  427. package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
  428. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
  429. package/dist/src/lib/schema-codegen/naming.d.ts +35 -0
  430. package/dist/src/lib/schema-codegen/naming.js +83 -0
  431. package/dist/src/lib/schema-codegen/naming.js.map +1 -0
  432. package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
  433. package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
  434. package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
  435. package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
  436. package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
  437. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
  438. package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
  439. package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
  440. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
  441. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +109 -0
  442. package/dist/src/lib/schema-codegen/schemaToTs.js +269 -0
  443. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -0
  444. package/dist/src/lib/schema-codegen/valuesLists.d.ts +48 -0
  445. package/dist/src/lib/schema-codegen/valuesLists.js +144 -0
  446. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
  447. package/dist/src/lib/schema-family-index.d.ts +228 -0
  448. package/dist/src/lib/schema-family-index.js +813 -0
  449. package/dist/src/lib/schema-family-index.js.map +1 -0
  450. package/dist/src/lib/schema-pins.d.ts +82 -0
  451. package/dist/src/lib/schema-pins.js +198 -0
  452. package/dist/src/lib/schema-pins.js.map +1 -0
  453. package/dist/src/lib/schema-preview.d.ts +244 -0
  454. package/dist/src/lib/schema-preview.js +498 -0
  455. package/dist/src/lib/schema-preview.js.map +1 -0
  456. package/dist/src/lib/scope-request.d.ts +23 -11
  457. package/dist/src/lib/scope-request.js +69 -31
  458. package/dist/src/lib/scope-request.js.map +1 -1
  459. package/dist/src/lib/session-scope.d.ts +26 -0
  460. package/dist/src/lib/session-scope.js +58 -0
  461. package/dist/src/lib/session-scope.js.map +1 -0
  462. package/dist/src/lib/skill-installer.d.ts +2 -2
  463. package/dist/src/lib/skill-installer.js +2 -21
  464. package/dist/src/lib/skill-installer.js.map +1 -1
  465. package/dist/src/lib/step-run-table.d.ts +1 -2
  466. package/dist/src/lib/step-run-table.js +1 -2
  467. package/dist/src/lib/step-run-table.js.map +1 -1
  468. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
  469. package/dist/src/lib/swift-codegen/agentGenerator.js +25 -23
  470. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  471. package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
  472. package/dist/src/lib/swift-codegen/banners.js +12 -0
  473. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  474. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
  475. package/dist/src/lib/swift-codegen/functionGenerator.js +169 -51
  476. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  477. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +33 -9
  478. package/dist/src/lib/swift-codegen/schemaToSwift.js +215 -179
  479. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  480. package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
  481. package/dist/src/lib/swift-codegen/sharedGenerator.js +165 -0
  482. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
  483. package/dist/src/lib/swift-codegen/swiftKeys.d.ts +19 -0
  484. package/dist/src/lib/swift-codegen/swiftKeys.js +31 -0
  485. package/dist/src/lib/swift-codegen/swiftKeys.js.map +1 -0
  486. package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
  487. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
  488. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
  489. package/dist/src/lib/sync-resource-types.d.ts +117 -31
  490. package/dist/src/lib/sync-resource-types.js +197 -189
  491. package/dist/src/lib/sync-resource-types.js.map +1 -1
  492. package/dist/src/lib/sync-selectors.d.ts +7 -0
  493. package/dist/src/lib/sync-selectors.js +22 -2
  494. package/dist/src/lib/sync-selectors.js.map +1 -1
  495. package/dist/src/lib/template.d.ts +39 -3
  496. package/dist/src/lib/template.js +103 -14
  497. package/dist/src/lib/template.js.map +1 -1
  498. package/dist/src/lib/test-case-file-names.d.ts +3 -5
  499. package/dist/src/lib/test-case-file-names.js +3 -5
  500. package/dist/src/lib/test-case-file-names.js.map +1 -1
  501. package/dist/src/lib/test-runs.d.ts +45 -0
  502. package/dist/src/lib/test-runs.js +150 -0
  503. package/dist/src/lib/test-runs.js.map +1 -0
  504. package/dist/src/lib/test-users.d.ts +25 -0
  505. package/dist/src/lib/test-users.js +36 -0
  506. package/dist/src/lib/test-users.js.map +1 -0
  507. package/dist/src/lib/toml-database-config.d.ts +4 -2
  508. package/dist/src/lib/toml-database-config.js +11 -6
  509. package/dist/src/lib/toml-database-config.js.map +1 -1
  510. package/dist/src/lib/toml-scalar-edit.js +6 -4
  511. package/dist/src/lib/toml-scalar-edit.js.map +1 -1
  512. package/dist/src/lib/transition-warnings.d.ts +21 -0
  513. package/dist/src/lib/transition-warnings.js +49 -0
  514. package/dist/src/lib/transition-warnings.js.map +1 -0
  515. package/dist/src/lib/user-index.d.ts +80 -0
  516. package/dist/src/lib/user-index.js +166 -0
  517. package/dist/src/lib/user-index.js.map +1 -0
  518. package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
  519. package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
  520. package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
  521. package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
  522. package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
  523. package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
  524. package/dist/src/lib/user-walk.d.ts +31 -0
  525. package/dist/src/lib/user-walk.js +102 -0
  526. package/dist/src/lib/user-walk.js.map +1 -0
  527. package/dist/src/lib/webhook-capture.d.ts +43 -0
  528. package/dist/src/lib/webhook-capture.js +91 -0
  529. package/dist/src/lib/webhook-capture.js.map +1 -0
  530. package/dist/src/lib/webhook-deliver.d.ts +18 -20
  531. package/dist/src/lib/webhook-deliver.js +34 -89
  532. package/dist/src/lib/webhook-deliver.js.map +1 -1
  533. package/dist/src/lib/webhook-test-run.d.ts +32 -0
  534. package/dist/src/lib/webhook-test-run.js +108 -0
  535. package/dist/src/lib/webhook-test-run.js.map +1 -0
  536. package/dist/src/lib/worker-perf-format.d.ts +22 -0
  537. package/dist/src/lib/worker-perf-format.js +27 -0
  538. package/dist/src/lib/worker-perf-format.js.map +1 -0
  539. package/dist/src/types/index.d.ts +20 -65
  540. package/dist/src/validators.d.ts +7 -55
  541. package/dist/src/validators.js +7 -53
  542. package/dist/src/validators.js.map +1 -1
  543. package/dist/src/vite.d.ts +17 -0
  544. package/dist/src/vite.js +18 -0
  545. package/dist/src/vite.js.map +1 -0
  546. package/package.json +20 -9
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * JSON-Schema → Swift `Codable` converter for `swift-codegen` (issue #1547,
3
- * Phase 1). The Swift counterpart of `workflow-codegen/schemaToTs.ts`.
3
+ * Phase 1). The Swift counterpart of `schema-codegen/schemaToTs.ts`.
4
4
  *
5
- * Both emitters read the SAME drift-guarded interpretation of the JSON-Schema
6
- * subset the workflow platform supports — the vendored `SchemaDescriptor`
7
- * (`workflow-codegen/generated-schema-descriptor.ts`, a byte copy of the server
8
- * validator). Only the emitted syntax differs, so a generated Swift type can
9
- * never promise a shape the runtime validator rejects. See the design and
10
- * maintainer decision on issue #1547.
5
+ * Both emitters render the SAME lowered node (`schema-codegen/schemaIR.ts`,
6
+ * #5542), which `lowerSchema` reads from the drift-guarded interpretation of
7
+ * the JSON-Schema subset the workflow platform supports — the vendored
8
+ * `SchemaDescriptor` (a byte copy of the server validator's). Only the emitted
9
+ * syntax differs, so a generated Swift type can never promise a shape the
10
+ * runtime validator rejects, nor decide a shape the TS type does not. See the
11
+ * design and maintainer decision on issue #1547.
11
12
  *
12
13
  * Where Swift diverges from TypeScript:
13
14
  *
@@ -20,7 +21,13 @@
20
21
  * - **Un-descended nodes** (`$ref`, `allOf`, `format`, tuple `items`,
21
22
  * `patternProperties`, numeric constraints, multi-scalar non-null unions,
22
23
  * mixed-type enums, open-object extra values) → `JSONValue`, the Swift
23
- * analog of TS `unknown`.
24
+ * analog of TS `unknown`. So is an `anyOf` (Swift has no untagged union)
25
+ * and an object or array `const` or `enum` member (#5544).
26
+ * - **`nullable: true`** (#5544) → the inner type, optional. A ROOT that is a
27
+ * nullable object, tagged union or string enum declares `<Root>Value` and
28
+ * `public typealias <Root> = <Root>Value?`.
29
+ * - **A named reference** (#5544) → the referenced type's name, declared in
30
+ * the shared file, with no nested declaration.
24
31
  * - **`never`** (an uninhabitable enum after the type gate) → a strict codegen
25
32
  * error, since the field can never be constructed (Fork 4).
26
33
  * - **Scalar `enum`, all strings** → a nested `enum … : String, Codable,
@@ -47,9 +54,15 @@
47
54
  *
48
55
  * Errors are named (`SwiftCodegenError`) and carry the source file and schema
49
56
  * path for diagnostics (binding item 6).
57
+ *
58
+ * Constraint and annotation keywords render as `///` lines (#5530,
59
+ * `schema-codegen/schemaDocs.ts`) on each declared property's `public var`
60
+ * and on the root declaration. Nested type declarations carry none: a nested
61
+ * declaration's first line names its type (`declTypeName`).
50
62
  */
51
- import { describeSchema, isType, } from "../workflow-codegen/generated-schema-descriptor.js";
52
- import { schemaRejectsEmptyObject } from "../workflow-codegen/schemaToTs.js";
63
+ import { admitsNull, assertNever, lowerSchema, } from "../schema-codegen/schemaIR.js";
64
+ import { schemaRejectsEmptyObject } from "../schema-codegen/schemaToTs.js";
65
+ import { renderSwiftDocLines } from "../schema-codegen/schemaDocs.js";
53
66
  import { enumCaseIdentifier, enumCaseNames, enumTypeName, escapeIfReserved, structTypeName, swiftPropertyName, unescapeIdentifier, } from "./swiftNaming.js";
54
67
  /** Re-exported so the invoker phases share ONE required-vs-optional decision. */
55
68
  export { schemaRejectsEmptyObject };
@@ -108,6 +121,14 @@ export function renderSwiftRootType(rootTypeName, schema, ctx) {
108
121
  * `nil` fall through to the client's "omit `rootInput`" path.
109
122
  */
110
123
  export function renderSwiftRootTypeDetail(rootTypeName, schema, ctx) {
124
+ return renderSwiftRootShape(rootTypeName, lowerSchema(schema, { named: ctx?.named }), ctx);
125
+ }
126
+ /**
127
+ * `renderSwiftRootTypeDetail` for a schema already lowered (#5542,
128
+ * `schema-codegen/schemaIR.ts`): the same declaration from the same node the
129
+ * TypeScript renderer reads.
130
+ */
131
+ export function renderSwiftRootShape(rootTypeName, lowered, ctx) {
111
132
  const state = {
112
133
  sourceFile: ctx?.sourceFile,
113
134
  path: rootTypeName,
@@ -118,27 +139,62 @@ export function renderSwiftRootTypeDetail(rootTypeName, schema, ctx) {
118
139
  });
119
140
  },
120
141
  };
121
- const d = describeSchema(schema);
122
- // A qualifying `oneOf` becomes a root enum with associated values.
123
- if (d.oneOf) {
124
- if (d.oneOf.kind === "invalid") {
125
- state.fail(`swift codegen: ${d.oneOf.reason}`);
142
+ const shape = lowered.shape;
143
+ // The root's doc lines sit directly above the root declaration.
144
+ const documented = (decl) => [...renderSwiftDocLines(lowered.docs, ""), decl].join("\n");
145
+ switch (shape.kind) {
146
+ // A tagged union becomes a root enum with associated values.
147
+ case "tagged":
148
+ return { decl: documented(renderOneOfEnum(rootTypeName, shape, 0, state)), optional: false };
149
+ // #5544 — a nullable root that is a struct or an enum declares
150
+ // `<Root>Value` and an optional alias, which the invoker branches on as
151
+ // for a nullable root union.
152
+ case "nullable": {
153
+ const valueName = `${rootTypeName}Value`;
154
+ const inner = shape.inner;
155
+ const decl = inner.kind === "object"
156
+ ? renderStruct(valueName, inner, 0, state)
157
+ : inner.kind === "tagged"
158
+ ? renderOneOfEnum(valueName, inner, 0, state)
159
+ : inner.kind === "literals" && allStrings(inner.values)
160
+ ? renderStringEnum(valueName, inner.values, 0)
161
+ : null;
162
+ if (decl === null)
163
+ break;
164
+ return {
165
+ decl: `${decl}\n\n${documented(`${ACCESS} typealias ${rootTypeName} = ${valueName}?`)}`,
166
+ optional: true,
167
+ };
126
168
  }
127
- return { decl: renderOneOfEnum(rootTypeName, d.oneOf, 0, state), optional: false };
128
- }
129
- // A root scalar `enum` (all strings) becomes a top-level String enum.
130
- const rootEnum = renderStringEnumIfApplicable(d, rootTypeName, 0, state);
131
- if (rootEnum)
132
- return { decl: rootEnum, optional: false };
133
- // A root object becomes a struct.
134
- if (d.singularType === "object" && d.object) {
135
- return { decl: renderStruct(rootTypeName, d.object, 0, state), optional: false };
169
+ // A root all-string enum becomes a top-level String enum.
170
+ case "literals":
171
+ if (allStrings(shape.values)) {
172
+ return { decl: documented(renderStringEnum(rootTypeName, shape.values, 0)), optional: false };
173
+ }
174
+ break;
175
+ // A root object becomes a struct, whatever its `enum` says.
176
+ case "object":
177
+ return { decl: documented(renderStruct(rootTypeName, shape, 0, state)), optional: false };
178
+ case "never":
179
+ case "refused":
180
+ // `renderTypeRef` refuses both.
181
+ break;
182
+ case "unknown":
183
+ case "scalar":
184
+ case "union":
185
+ case "map":
186
+ case "array":
187
+ case "untagged":
188
+ case "named":
189
+ break;
190
+ default:
191
+ return assertNever(shape);
136
192
  }
137
193
  // Anything else (scalar, array, union, un-descended) is a typealias to the
138
194
  // reference type. Nested type declarations (e.g. an array's element struct)
139
- // are emitted before the alias.
140
- const ref = renderTypeRef(schema, rootTypeName, 0, state);
141
- const alias = `${ACCESS} typealias ${rootTypeName} = ${optionalize(ref)}`;
195
+ // are emitted before the alias, and the root's doc lines after them.
196
+ const ref = renderTypeRef(shape, rootTypeName, 0, state);
197
+ const alias = documented(`${ACCESS} typealias ${rootTypeName} = ${optionalize(ref)}`);
142
198
  return {
143
199
  decl: ref.decls.length > 0 ? `${ref.decls.join("\n\n")}\n\n${alias}` : alias,
144
200
  optional: ref.nullable,
@@ -146,116 +202,101 @@ export function renderSwiftRootTypeDetail(rootTypeName, schema, ctx) {
146
202
  }
147
203
  /** Apply `?` to a reference type when the node is nullable. */
148
204
  function optionalize(ref) {
149
- return ref.nullable ? `${ref.expr}?` : ref.expr;
205
+ return ref.nullable && !ref.optionalAlias ? `${ref.expr}?` : ref.expr;
150
206
  }
207
+ const allStrings = (values) => values.every((v) => typeof v === "string");
208
+ /** A reference to `JSONValue`, the Swift analog of TS `unknown`. */
209
+ const jsonValue = (nullable) => ({ expr: "JSONValue", nullable, decls: [] });
151
210
  /**
152
- * Render a schema node as a Swift type reference, accumulating any nested type
211
+ * Render a lowered node as a Swift type reference, accumulating any nested type
153
212
  * declarations. `nameHint` is the base name for a nested named type (usually the
154
213
  * property name). `indent` is where the nested declarations are placed.
155
214
  */
156
- function renderTypeRef(schema, nameHint, indent, state) {
157
- const d = describeSchema(schema);
158
- // Discriminated union → a named enum type.
159
- if (d.oneOf) {
160
- if (d.oneOf.kind === "invalid") {
161
- state.fail(`swift codegen: ${d.oneOf.reason}`);
162
- }
163
- const typeName = structTypeName(nameHint);
164
- const decl = renderOneOfEnum(typeName, d.oneOf, indent, {
165
- ...state,
166
- path: `${state.path}.${nameHint}`,
167
- });
168
- return { expr: typeName, nullable: false, decls: [decl] };
169
- }
170
- // Scalar `enum`.
171
- if (d.enumValues) {
172
- return renderEnumRef(d, nameHint, indent, state);
173
- }
174
- // Type union (e.g. `["string","null"]`).
175
- if (d.isUnion) {
176
- return renderUnionRef(d);
177
- }
178
- // No usable single type, not an enum/union/oneOf → un-descended → JSONValue.
179
- if (d.singularType === null) {
180
- return { expr: "JSONValue", nullable: false, decls: [] };
181
- }
182
- if (d.singularType === "object") {
183
- if (d.object) {
215
+ function renderTypeRef(shape, nameHint, indent, state) {
216
+ switch (shape.kind) {
217
+ // Discriminated union → a named enum type.
218
+ case "tagged": {
184
219
  const typeName = structTypeName(nameHint);
185
- const decl = renderStruct(typeName, d.object, indent, {
220
+ const decl = renderOneOfEnum(typeName, shape, indent, {
186
221
  ...state,
187
222
  path: `${state.path}.${nameHint}`,
188
223
  });
189
224
  return { expr: typeName, nullable: false, decls: [decl] };
190
225
  }
226
+ case "refused":
227
+ return state.fail(`swift codegen: ${shape.reason}`);
228
+ // An enum no value satisfies: a Swift field that can never be constructed
229
+ // is a strict codegen error (Fork 4); TS renders `never`.
230
+ case "never":
231
+ return state.fail("swift codegen: enum has no value satisfying its declared type (uninhabitable / never)");
232
+ // All-string members → a nested `String` enum. Mixed-type, non-string,
233
+ // object or array values fall back to JSONValue; a `null` in the raw enum
234
+ // makes it nullable, which JSONValue already covers.
235
+ case "literals": {
236
+ if (allStrings(shape.values)) {
237
+ const typeName = enumTypeName(nameHint);
238
+ return {
239
+ expr: typeName,
240
+ nullable: false,
241
+ decls: [renderStringEnum(typeName, shape.values, indent)],
242
+ };
243
+ }
244
+ return jsonValue(shape.nullable);
245
+ }
246
+ // Type union (e.g. `["string","null"]`).
247
+ case "union":
248
+ return renderUnionRef(shape.types);
249
+ // Not enforced, or not descended → JSONValue.
250
+ case "unknown":
251
+ return jsonValue(shape.nullable);
252
+ case "scalar":
253
+ // `null` singular type → JSONValue, which includes null.
254
+ if (shape.type === "null")
255
+ return jsonValue(true);
256
+ return { expr: SCALAR_SWIFT[shape.type], nullable: false, decls: [] };
191
257
  // Open object with no declared properties → an untyped dictionary.
192
- return { expr: "[String: JSONValue]", nullable: false, decls: [] };
193
- }
194
- if (d.singularType === "array") {
195
- const items = d.array ? d.array.items : undefined;
196
- // Missing or tuple `items` (array of schemas) is not descended → [JSONValue].
197
- if (!items || typeof items !== "object" || Array.isArray(items)) {
198
- return { expr: "[JSONValue]", nullable: false, decls: [] };
258
+ case "map":
259
+ return { expr: "[String: JSONValue]", nullable: false, decls: [] };
260
+ case "object": {
261
+ const typeName = structTypeName(nameHint);
262
+ const decl = renderStruct(typeName, shape, indent, {
263
+ ...state,
264
+ path: `${state.path}.${nameHint}`,
265
+ });
266
+ return { expr: typeName, nullable: false, decls: [decl] };
199
267
  }
200
- const elem = renderTypeRef(items, `${nameHint}Item`, indent, {
201
- ...state,
202
- path: `${state.path}.${nameHint}[]`,
203
- });
204
- return {
205
- expr: `[${optionalize(elem)}]`,
206
- nullable: false,
207
- decls: elem.decls,
208
- };
209
- }
210
- // `null` singular type, or an unknown/unmodeled type name → JSONValue.
211
- const scalar = SCALAR_SWIFT[d.singularType];
212
- if (scalar)
213
- return { expr: scalar, nullable: false, decls: [] };
214
- return {
215
- expr: "JSONValue",
216
- nullable: d.singularType === "null",
217
- decls: [],
218
- };
219
- }
220
- /**
221
- * Render a scalar `enum` node. All-string members → a nested `String` enum;
222
- * an empty reachable set → `never` (codegen error); anything else (mixed-type
223
- * or non-string scalars) → `JSONValue` (Fork 4).
224
- */
225
- function renderEnumRef(d, nameHint, indent, state) {
226
- const decl = renderStringEnumIfApplicable(d, enumTypeName(nameHint), indent, state);
227
- if (decl) {
228
- return { expr: enumTypeName(nameHint), nullable: false, decls: [decl] };
229
- }
230
- // Not an all-string enum: mixed-type or non-string scalar values fall back to
231
- // JSONValue (faithful to TS `unknown`). A `null` member makes the node
232
- // nullable, which JSONValue already covers.
233
- const hasNull = (d.enumValues ?? []).includes(null);
234
- return { expr: "JSONValue", nullable: hasNull, decls: [] };
268
+ case "array": {
269
+ // Missing or tuple `items` lowers to `unknown` → [JSONValue].
270
+ const elem = renderTypeRef(shape.items, `${nameHint}Item`, indent, {
271
+ ...state,
272
+ path: `${state.path}.${nameHint}[]`,
273
+ });
274
+ return {
275
+ expr: `[${optionalize(elem)}]`,
276
+ nullable: false,
277
+ decls: elem.decls,
278
+ };
279
+ }
280
+ // #5544 — Swift has no untagged union: JSONValue, optional when the node
281
+ // admits null.
282
+ case "untagged":
283
+ return jsonValue(admitsNull(shape));
284
+ case "nullable":
285
+ return { ...renderTypeRef(shape.inner, nameHint, indent, state), nullable: true };
286
+ // A type the shared file declares: referenced, never nested. A target
287
+ // that admits null is declared as an Optional alias, so the reference is
288
+ // nullable without a second `?`.
289
+ case "named":
290
+ return shape.targetNullable
291
+ ? { expr: shape.name, nullable: true, decls: [], optionalAlias: true }
292
+ : { expr: shape.name, nullable: shape.nullable, decls: [] };
293
+ default:
294
+ return assertNever(shape);
295
+ }
235
296
  }
236
- /**
237
- * If `d` is a scalar `enum` whose reachable members (after the type gate) are
238
- * ALL strings, return a nested `String` enum declaration named `typeName`.
239
- * Returns `null` when it is not an all-string enum. Throws on an uninhabitable
240
- * (`never`) enum.
241
- */
242
- function renderStringEnumIfApplicable(d, typeName, indent, state) {
243
- if (!d.enumValues)
244
- return null;
245
- const allowedTypes = d.types;
246
- const candidates = allowedTypes.length > 0
247
- ? d.enumValues.filter((v) => allowedTypes.some((t) => isType(v, t)))
248
- : d.enumValues;
249
- if (candidates.length === 0) {
250
- // No enum member satisfies the declared type gate: the runtime rejects
251
- // every value. This is `never` on the TS side; a Swift field that can never
252
- // be constructed is a strict codegen error (Fork 4).
253
- state.fail("swift codegen: enum has no value satisfying its declared type (uninhabitable / never)");
254
- }
255
- const allStrings = candidates.every((v) => typeof v === "string");
256
- if (!allStrings)
257
- return null;
258
- const cases = enumCaseNames(candidates);
297
+ /** A nested (or root) `String` enum named `typeName`, one case per distinct value. */
298
+ function renderStringEnum(typeName, values, indent) {
299
+ const cases = enumCaseNames(values);
259
300
  const pad = INDENT_UNIT.repeat(indent);
260
301
  const inner = INDENT_UNIT.repeat(indent + 1);
261
302
  const lines = [];
@@ -270,50 +311,41 @@ function renderStringEnumIfApplicable(d, typeName, indent, state) {
270
311
  return lines.join("\n");
271
312
  }
272
313
  /**
273
- * Render a type union (`type: [...]`). A single non-null scalar (optionally with
274
- * `null`) → that scalar (nullable if `null` present). Multiple distinct scalars,
275
- * or any object/array member → `JSONValue` (no untagged union in Swift).
314
+ * Render a type union (`type: [...]`, scalars only). A single non-null scalar
315
+ * (optionally with `null`) → that scalar (nullable if `null` present). Multiple
316
+ * distinct scalars → `JSONValue` (no untagged union in Swift).
276
317
  */
277
- function renderUnionRef(d) {
278
- const hasNull = d.types.includes("null");
279
- const nonNull = d.types.filter((t) => t !== "null");
318
+ function renderUnionRef(types) {
319
+ const hasNull = types.includes("null");
280
320
  const mapped = [];
281
- for (const t of nonNull) {
321
+ for (const t of types) {
322
+ if (t === "null")
323
+ continue;
282
324
  const s = SCALAR_SWIFT[t];
283
- if (!s) {
284
- // object / array / unknown member → not representable as a Swift union.
285
- return { expr: "JSONValue", nullable: hasNull, decls: [] };
286
- }
287
325
  if (!mapped.includes(s))
288
326
  mapped.push(s);
289
327
  }
290
328
  if (mapped.length === 0) {
291
329
  // `["null"]` only → JSONValue (which includes null).
292
- return { expr: "JSONValue", nullable: true, decls: [] };
330
+ return jsonValue(true);
293
331
  }
294
332
  if (mapped.length === 1) {
295
333
  return { expr: mapped[0], nullable: hasNull, decls: [] };
296
334
  }
297
335
  // Multi-scalar non-null union (e.g. ["string","number"]) → JSONValue (Fork 4).
298
- return { expr: "JSONValue", nullable: hasNull, decls: [] };
336
+ return jsonValue(hasNull);
299
337
  }
300
338
  /**
301
- * Render an object descriptor as a Swift `struct`. `required[]` drives
302
- * optionality; an open object gains an `extra: [String: JSONValue]` catch-all.
303
- * Emits a public memberwise initializer always, `CodingKeys` when a wire key
304
- * isn't its Swift name (or when custom Codable is needed), and custom
305
- * `init(from:)`/`encode(to:)` when required-nullable properties or the
306
- * open-object catch-all require it.
339
+ * Render an object node as a Swift `struct`. `required` drives optionality
340
+ * (a tagged union's member object already lists its discriminant); an open
341
+ * object gains an `extra: [String: JSONValue]` catch-all. Emits a public
342
+ * memberwise initializer always, `CodingKeys` when a wire key isn't its Swift
343
+ * name (or when custom Codable is needed), and custom `init(from:)`/
344
+ * `encode(to:)` when required-nullable properties or the open-object catch-all
345
+ * require it.
307
346
  */
308
- function renderStruct(typeName, objectDesc, indent, state, forcedRequired = []) {
309
- const { properties, required, additionalPropertiesClosed } = objectDesc;
310
- const requiredSet = new Set([
311
- ...(Array.isArray(required)
312
- ? required.filter((k) => typeof k === "string")
313
- : []),
314
- ...forcedRequired,
315
- ]);
316
- const isOpen = !additionalPropertiesClosed;
347
+ function renderStruct(typeName, shape, indent, state) {
348
+ const isOpen = shape.open;
317
349
  const nestedDecls = [];
318
350
  const usedTypeNames = new Set();
319
351
  const props = [];
@@ -325,8 +357,9 @@ function renderStruct(typeName, objectDesc, indent, state, forcedRequired = [])
325
357
  }
326
358
  usedSwiftNames.add(bare);
327
359
  };
328
- for (const wireKey of Object.keys(properties)) {
329
- const ref = renderTypeRef(properties[wireKey], wireKey, indent + 1, {
360
+ for (const member of shape.members) {
361
+ const wireKey = member.name;
362
+ const ref = renderTypeRef(member.shape, wireKey, indent + 1, {
330
363
  ...state,
331
364
  path: `${state.path}.${wireKey}`,
332
365
  });
@@ -343,22 +376,21 @@ function renderStruct(typeName, objectDesc, indent, state, forcedRequired = [])
343
376
  }
344
377
  const swiftName = swiftPropertyName(wireKey);
345
378
  recordName(swiftName);
346
- const isRequired = requiredSet.has(wireKey);
347
379
  props.push({
348
380
  wireKey,
349
381
  swiftName,
350
382
  type: ref.expr,
351
- optionalType: !isRequired || ref.nullable,
352
- requiredNullable: isRequired && ref.nullable,
353
- requiredNonNull: isRequired && !ref.nullable,
383
+ optionalType: !member.required || ref.nullable,
384
+ ...(ref.optionalAlias ? { optionalAlias: true } : {}),
385
+ requiredNullable: member.required && ref.nullable,
386
+ requiredNonNull: member.required && !ref.nullable,
387
+ docs: member.docs,
354
388
  });
355
389
  }
356
390
  // A key listed in `required` but absent from `properties` has no child schema,
357
391
  // yet the validator still rejects an object missing it. Emit it as a required
358
392
  // `JSONValue` member so the generated type demands the key too.
359
- for (const wireKey of requiredSet) {
360
- if (Object.prototype.hasOwnProperty.call(properties, wireKey))
361
- continue;
393
+ for (const wireKey of shape.requiredUndeclared) {
362
394
  const swiftName = swiftPropertyName(wireKey);
363
395
  recordName(swiftName);
364
396
  props.push({
@@ -398,9 +430,11 @@ function renderStruct(typeName, objectDesc, indent, state, forcedRequired = [])
398
430
  }
399
431
  if (nestedDecls.length > 0)
400
432
  out.push("");
401
- // Stored properties.
433
+ // Stored properties, each declared one under its doc lines.
402
434
  for (const p of props) {
403
- out.push(`${b}${ACCESS} var ${p.swiftName}: ${p.type}${p.optionalType ? "?" : ""}`);
435
+ if (p.docs)
436
+ out.push(...renderSwiftDocLines(p.docs, b));
437
+ out.push(`${b}${ACCESS} var ${p.swiftName}: ${propertyType(p)}`);
404
438
  }
405
439
  if (isOpen) {
406
440
  out.push(`${b}/// Extra keys the schema does not model, preserved round-trip.`);
@@ -423,12 +457,16 @@ function renderStruct(typeName, objectDesc, indent, state, forcedRequired = [])
423
457
  out.push(`${pad}}`);
424
458
  return out.join("\n");
425
459
  }
460
+ /** A property's declared type: `T?` when it admits nil, unless `T` is already Optional. */
461
+ function propertyType(p) {
462
+ return `${p.type}${p.optionalType && !p.optionalAlias ? "?" : ""}`;
463
+ }
426
464
  function renderMemberwiseInit(props, isOpen, catchAllName, indent) {
427
465
  const pad = INDENT_UNIT.repeat(indent);
428
466
  const body = INDENT_UNIT.repeat(indent + 1);
429
467
  const params = [];
430
468
  for (const p of props) {
431
- const type = `${p.type}${p.optionalType ? "?" : ""}`;
469
+ const type = propertyType(p);
432
470
  // Optional-typed params default to nil for ergonomics.
433
471
  params.push(`${p.swiftName}: ${type}${p.optionalType ? " = nil" : ""}`);
434
472
  }
@@ -483,7 +521,8 @@ function renderCustomDecodeEncode(props, isOpen, catchAllName, indent) {
483
521
  }
484
522
  else {
485
523
  // Optional or required-nullable: lenient decode (a missing key → nil).
486
- lines.push(`${b}self.${p.swiftName} = try container.decodeIfPresent(${p.type}.self, forKey: .${p.swiftName})`);
524
+ // An Optional alias decodes as a double Optional, flattened.
525
+ lines.push(`${b}self.${p.swiftName} = try container.decodeIfPresent(${p.type}.self, forKey: .${p.swiftName})${p.optionalAlias ? " ?? nil" : ""}`);
487
526
  }
488
527
  }
489
528
  if (isOpen) {
@@ -539,17 +578,17 @@ function renderCustomDecodeEncode(props, isOpen, catchAllName, indent) {
539
578
  * decoding a branch rejects a conflicting discriminator value and encoding
540
579
  * re-emits the tag (binding item 4).
541
580
  */
542
- function renderOneOfEnum(typeName, oneOf, indent, state) {
581
+ function renderOneOfEnum(typeName, tagged, indent, state) {
543
582
  const pad = INDENT_UNIT.repeat(indent);
544
583
  const b = INDENT_UNIT.repeat(indent + 1);
545
584
  const b2 = INDENT_UNIT.repeat(indent + 2);
546
585
  const b3 = INDENT_UNIT.repeat(indent + 3);
547
- const { discriminant, members } = oneOf;
586
+ const { discriminant, members } = tagged;
548
587
  // Assign each branch a case name (deduped) and a branch struct type name.
549
588
  const usedCaseNames = new Map();
550
589
  const usedBranchTypes = new Set();
551
590
  const branches = members.map((m) => {
552
- const valueStr = String(m.discriminantValue);
591
+ const valueStr = String(m.tag);
553
592
  // Case name derived from the discriminator value, deduped. Dedup on the
554
593
  // UN-escaped base and re-escape once, so a reserved-word discriminator
555
594
  // (`default`) that collides gets `default_2`, not the uncompilable
@@ -570,21 +609,18 @@ function renderOneOfEnum(typeName, oneOf, indent, state) {
570
609
  lines.push(`${b}case ${br.caseName}(${br.branchType})`);
571
610
  }
572
611
  lines.push("");
573
- // Nested branch structs. Each renders from its member object descriptor with
574
- // the discriminant forced required.
612
+ // Nested branch structs, each from its member object (the discriminant
613
+ // already required).
575
614
  for (const br of branches) {
576
- const md = describeSchema(br.member.schema);
577
- if (!md.object) {
578
- // Guaranteed by the descriptor (every member is `type: "object"`), but be
579
- // defensive rather than emit broken Swift.
580
- state.fail(`swift codegen: oneOf branch for ${discriminant}=${String(br.member.discriminantValue)} is not an object`);
581
- }
582
- const decl = renderStruct(br.branchType, md.object, indent + 1, { ...state, path: `${state.path}.${br.branchType}` }, [discriminant]);
615
+ const decl = renderStruct(br.branchType, br.member.object, indent + 1, {
616
+ ...state,
617
+ path: `${state.path}.${br.branchType}`,
618
+ });
583
619
  lines.push(decl);
584
620
  lines.push("");
585
621
  }
586
622
  // Discriminator coding key.
587
- const tagKind = discriminatorTagKind(members.map((m) => m.discriminantValue));
623
+ const tagKind = discriminatorTagKind(members.map((m) => m.tag));
588
624
  lines.push(`${b}private enum DiscriminatorKey: String, CodingKey {`);
589
625
  lines.push(`${b2}case tag = ${swiftString(discriminant)}`);
590
626
  lines.push(`${b}}`);
@@ -596,7 +632,7 @@ function renderOneOfEnum(typeName, oneOf, indent, state) {
596
632
  lines.push(`${b2}let tag = try container.decode(${tagKind.swiftType}.self, forKey: .tag)`);
597
633
  lines.push(`${b2}switch tag {`);
598
634
  for (const br of branches) {
599
- lines.push(`${b2}case ${tagKind.literal(br.member.discriminantValue)}:`);
635
+ lines.push(`${b2}case ${tagKind.literal(br.member.tag)}:`);
600
636
  lines.push(`${b3}self = .${br.caseName}(try ${br.branchType}(from: decoder))`);
601
637
  }
602
638
  lines.push(`${b2}default:`);
@@ -608,7 +644,7 @@ function renderOneOfEnum(typeName, oneOf, indent, state) {
608
644
  lines.push(`${b2}let tag = try container.decode(JSONValue.self, forKey: .tag)`);
609
645
  branches.forEach((br, i) => {
610
646
  const kw = i === 0 ? "if" : "} else if";
611
- lines.push(`${b2}${kw} tag == ${jsonValueLiteral(br.member.discriminantValue)} {`);
647
+ lines.push(`${b2}${kw} tag == ${jsonValueLiteral(br.member.tag)} {`);
612
648
  lines.push(`${b3}self = .${br.caseName}(try ${br.branchType}(from: decoder))`);
613
649
  });
614
650
  lines.push(`${b2}} else {`);