primitive-admin 1.0.62 → 1.0.64

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 (344) hide show
  1. package/README.md +132 -42
  2. package/assets/skill/skills/primitive-platform/SKILL.md +142 -661
  3. package/dist/bin/primitive.js +121 -41
  4. package/dist/bin/primitive.js.map +1 -1
  5. package/dist/src/commands/admins.js +37 -50
  6. package/dist/src/commands/admins.js.map +1 -1
  7. package/dist/src/commands/analytics.js +178 -9
  8. package/dist/src/commands/analytics.js.map +1 -1
  9. package/dist/src/commands/apps.js +17 -7
  10. package/dist/src/commands/apps.js.map +1 -1
  11. package/dist/src/commands/auth-sessions.d.ts +7 -0
  12. package/dist/src/commands/auth-sessions.js +144 -0
  13. package/dist/src/commands/auth-sessions.js.map +1 -0
  14. package/dist/src/commands/auth.js +76 -116
  15. package/dist/src/commands/auth.js.map +1 -1
  16. package/dist/src/commands/blob-buckets.js +2 -1
  17. package/dist/src/commands/blob-buckets.js.map +1 -1
  18. package/dist/src/commands/catalog.js +26 -10
  19. package/dist/src/commands/catalog.js.map +1 -1
  20. package/dist/src/commands/collection-type-configs.js +3 -10
  21. package/dist/src/commands/collection-type-configs.js.map +1 -1
  22. package/dist/src/commands/collections.js +736 -19
  23. package/dist/src/commands/collections.js.map +1 -1
  24. package/dist/src/commands/config.js +13 -27
  25. package/dist/src/commands/config.js.map +1 -1
  26. package/dist/src/commands/connections.js +8 -9
  27. package/dist/src/commands/connections.js.map +1 -1
  28. package/dist/src/commands/cron-triggers.js +2 -1
  29. package/dist/src/commands/cron-triggers.js.map +1 -1
  30. package/dist/src/commands/database-type-configs.js +5 -12
  31. package/dist/src/commands/database-type-configs.js.map +1 -1
  32. package/dist/src/commands/databases.js +59 -72
  33. package/dist/src/commands/databases.js.map +1 -1
  34. package/dist/src/commands/documents.d.ts +58 -0
  35. package/dist/src/commands/documents.js +1623 -95
  36. package/dist/src/commands/documents.js.map +1 -1
  37. package/dist/src/commands/email-templates.js +5 -4
  38. package/dist/src/commands/email-templates.js.map +1 -1
  39. package/dist/src/commands/env.d.ts +1 -1
  40. package/dist/src/commands/env.js +106 -44
  41. package/dist/src/commands/env.js.map +1 -1
  42. package/dist/src/commands/feature-flags.js +2 -1
  43. package/dist/src/commands/feature-flags.js.map +1 -1
  44. package/dist/src/commands/functions.d.ts +20 -0
  45. package/dist/src/commands/functions.js +1630 -0
  46. package/dist/src/commands/functions.js.map +1 -0
  47. package/dist/src/commands/group-type-configs.js +2 -1
  48. package/dist/src/commands/group-type-configs.js.map +1 -1
  49. package/dist/src/commands/groups.js +30 -17
  50. package/dist/src/commands/groups.js.map +1 -1
  51. package/dist/src/commands/guides.js +17 -11
  52. package/dist/src/commands/guides.js.map +1 -1
  53. package/dist/src/commands/init.d.ts +24 -12
  54. package/dist/src/commands/init.js +198 -110
  55. package/dist/src/commands/init.js.map +1 -1
  56. package/dist/src/commands/integrations.js +65 -26
  57. package/dist/src/commands/integrations.js.map +1 -1
  58. package/dist/src/commands/locks.js +17 -2
  59. package/dist/src/commands/locks.js.map +1 -1
  60. package/dist/src/commands/metadata-category-configs.js +2 -1
  61. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  62. package/dist/src/commands/metadata.js +8 -1
  63. package/dist/src/commands/metadata.js.map +1 -1
  64. package/dist/src/commands/prompts.js +106 -59
  65. package/dist/src/commands/prompts.js.map +1 -1
  66. package/dist/src/commands/rule-sets.js +3 -10
  67. package/dist/src/commands/rule-sets.js.map +1 -1
  68. package/dist/src/commands/scripts.d.ts +10 -0
  69. package/dist/src/commands/scripts.js +159 -25
  70. package/dist/src/commands/scripts.js.map +1 -1
  71. package/dist/src/commands/secrets.js +2 -1
  72. package/dist/src/commands/secrets.js.map +1 -1
  73. package/dist/src/commands/sessions.js +10 -9
  74. package/dist/src/commands/sessions.js.map +1 -1
  75. package/dist/src/commands/sync-app-settings.js +3 -5
  76. package/dist/src/commands/sync-app-settings.js.map +1 -1
  77. package/dist/src/commands/sync.d.ts +391 -44
  78. package/dist/src/commands/sync.js +2622 -534
  79. package/dist/src/commands/sync.js.map +1 -1
  80. package/dist/src/commands/tokens.js +2 -1
  81. package/dist/src/commands/tokens.js.map +1 -1
  82. package/dist/src/commands/users.js +19 -10
  83. package/dist/src/commands/users.js.map +1 -1
  84. package/dist/src/commands/vars.js +2 -1
  85. package/dist/src/commands/vars.js.map +1 -1
  86. package/dist/src/commands/waitlist.js +2 -1
  87. package/dist/src/commands/waitlist.js.map +1 -1
  88. package/dist/src/commands/webhooks.d.ts +29 -0
  89. package/dist/src/commands/webhooks.js +135 -64
  90. package/dist/src/commands/webhooks.js.map +1 -1
  91. package/dist/src/commands/workflows.d.ts +1 -29
  92. package/dist/src/commands/workflows.js +113 -179
  93. package/dist/src/commands/workflows.js.map +1 -1
  94. package/dist/src/lib/api-client.d.ts +628 -14
  95. package/dist/src/lib/api-client.js +776 -70
  96. package/dist/src/lib/api-client.js.map +1 -1
  97. package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
  98. package/dist/src/lib/app-settings-descriptor.js +9 -1
  99. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  100. package/dist/src/lib/block-selector.d.ts +58 -0
  101. package/dist/src/lib/block-selector.js +92 -0
  102. package/dist/src/lib/block-selector.js.map +1 -0
  103. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +24 -54
  104. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +31 -153
  105. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -1
  106. package/dist/src/lib/collection-export.d.ts +184 -0
  107. package/dist/src/lib/collection-export.js +252 -0
  108. package/dist/src/lib/collection-export.js.map +1 -0
  109. package/dist/src/lib/config-json-field.d.ts +28 -0
  110. package/dist/src/lib/config-json-field.js +56 -0
  111. package/dist/src/lib/config-json-field.js.map +1 -0
  112. package/dist/src/lib/config-object-descriptor.js +88 -6
  113. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  114. package/dist/src/lib/config-payload.d.ts +8 -1
  115. package/dist/src/lib/config-payload.js +49 -4
  116. package/dist/src/lib/config-payload.js.map +1 -1
  117. package/dist/src/lib/config-surface.d.ts +12 -1
  118. package/dist/src/lib/config-surface.js +71 -3
  119. package/dist/src/lib/config-surface.js.map +1 -1
  120. package/dist/src/lib/config.d.ts +31 -13
  121. package/dist/src/lib/config.js +34 -70
  122. package/dist/src/lib/config.js.map +1 -1
  123. package/dist/src/lib/credentials-store.d.ts +37 -22
  124. package/dist/src/lib/credentials-store.js +103 -97
  125. package/dist/src/lib/credentials-store.js.map +1 -1
  126. package/dist/src/lib/db-codegen/dbTypeIR.js +8 -0
  127. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  128. package/dist/src/lib/deprecation.d.ts +22 -0
  129. package/dist/src/lib/deprecation.js +43 -0
  130. package/dist/src/lib/deprecation.js.map +1 -0
  131. package/dist/src/lib/document-export-permissions.d.ts +30 -0
  132. package/dist/src/lib/document-export-permissions.js +54 -0
  133. package/dist/src/lib/document-export-permissions.js.map +1 -0
  134. package/dist/src/lib/document-ingest-artifact.d.ts +120 -0
  135. package/dist/src/lib/document-ingest-artifact.js +505 -0
  136. package/dist/src/lib/document-ingest-artifact.js.map +1 -0
  137. package/dist/src/lib/document-ingest-input.d.ts +51 -0
  138. package/dist/src/lib/document-ingest-input.js +132 -0
  139. package/dist/src/lib/document-ingest-input.js.map +1 -0
  140. package/dist/src/lib/document-ingest-rows.d.ts +137 -0
  141. package/dist/src/lib/document-ingest-rows.js +181 -0
  142. package/dist/src/lib/document-ingest-rows.js.map +1 -0
  143. package/dist/src/lib/document-ingest.d.ts +101 -0
  144. package/dist/src/lib/document-ingest.js +384 -0
  145. package/dist/src/lib/document-ingest.js.map +1 -0
  146. package/dist/src/lib/env-resolver-core.d.ts +128 -17
  147. package/dist/src/lib/env-resolver-core.js +204 -22
  148. package/dist/src/lib/env-resolver-core.js.map +1 -1
  149. package/dist/src/lib/env-resolver.d.ts +18 -3
  150. package/dist/src/lib/env-resolver.js +23 -3
  151. package/dist/src/lib/env-resolver.js.map +1 -1
  152. package/dist/src/lib/function-bundle.d.ts +147 -0
  153. package/dist/src/lib/function-bundle.js +341 -0
  154. package/dist/src/lib/function-bundle.js.map +1 -0
  155. package/dist/src/lib/function-collect.d.ts +123 -0
  156. package/dist/src/lib/function-collect.js +610 -0
  157. package/dist/src/lib/function-collect.js.map +1 -0
  158. package/dist/src/lib/function-db-types.d.ts +202 -0
  159. package/dist/src/lib/function-db-types.js +870 -0
  160. package/dist/src/lib/function-db-types.js.map +1 -0
  161. package/dist/src/lib/function-document-types.d.ts +144 -0
  162. package/dist/src/lib/function-document-types.js +370 -0
  163. package/dist/src/lib/function-document-types.js.map +1 -0
  164. package/dist/src/lib/function-grants-preflight.d.ts +64 -0
  165. package/dist/src/lib/function-grants-preflight.js +105 -0
  166. package/dist/src/lib/function-grants-preflight.js.map +1 -0
  167. package/dist/src/lib/function-log-lines.d.ts +76 -0
  168. package/dist/src/lib/function-log-lines.js +160 -0
  169. package/dist/src/lib/function-log-lines.js.map +1 -0
  170. package/dist/src/lib/function-log-row.d.ts +29 -0
  171. package/dist/src/lib/function-log-row.js +73 -0
  172. package/dist/src/lib/function-log-row.js.map +1 -0
  173. package/dist/src/lib/function-log-tail.d.ts +132 -0
  174. package/dist/src/lib/function-log-tail.js +262 -0
  175. package/dist/src/lib/function-log-tail.js.map +1 -0
  176. package/dist/src/lib/function-run.d.ts +289 -0
  177. package/dist/src/lib/function-run.js +389 -0
  178. package/dist/src/lib/function-run.js.map +1 -0
  179. package/dist/src/lib/function-schema-codegen.d.ts +143 -0
  180. package/dist/src/lib/function-schema-codegen.js +420 -0
  181. package/dist/src/lib/function-schema-codegen.js.map +1 -0
  182. package/dist/src/lib/function-sync.d.ts +459 -0
  183. package/dist/src/lib/function-sync.js +1258 -0
  184. package/dist/src/lib/function-sync.js.map +1 -0
  185. package/dist/src/lib/function-trigger-listing.d.ts +27 -0
  186. package/dist/src/lib/function-trigger-listing.js +70 -0
  187. package/dist/src/lib/function-trigger-listing.js.map +1 -0
  188. package/dist/src/lib/function-typecheck.d.ts +86 -0
  189. package/dist/src/lib/function-typecheck.js +370 -0
  190. package/dist/src/lib/function-typecheck.js.map +1 -0
  191. package/dist/src/lib/function-versions.d.ts +122 -0
  192. package/dist/src/lib/function-versions.js +182 -0
  193. package/dist/src/lib/function-versions.js.map +1 -0
  194. package/dist/src/lib/generated-allowlist.js +4 -0
  195. package/dist/src/lib/generated-allowlist.js.map +1 -1
  196. package/dist/src/lib/generated-config-surfaces.d.ts +2332 -78
  197. package/dist/src/lib/generated-config-surfaces.js +6979 -468
  198. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  199. package/dist/src/lib/generated-sdk-types.d.ts +12 -0
  200. package/dist/src/lib/generated-sdk-types.js +13 -0
  201. package/dist/src/lib/generated-sdk-types.js.map +1 -0
  202. package/dist/src/lib/init-adopt.js +2 -2
  203. package/dist/src/lib/init-adopt.js.map +1 -1
  204. package/dist/src/lib/init-assets.js +3 -3
  205. package/dist/src/lib/init-client-platforms.d.ts +14 -0
  206. package/dist/src/lib/init-client-platforms.js +71 -0
  207. package/dist/src/lib/init-client-platforms.js.map +1 -0
  208. package/dist/src/lib/init-config.d.ts +1 -1
  209. package/dist/src/lib/init-email-redirect-uris.d.ts +37 -0
  210. package/dist/src/lib/init-email-redirect-uris.js +46 -0
  211. package/dist/src/lib/init-email-redirect-uris.js.map +1 -0
  212. package/dist/src/lib/init-ios-links.d.ts +41 -0
  213. package/dist/src/lib/init-ios-links.js +67 -1
  214. package/dist/src/lib/init-ios-links.js.map +1 -1
  215. package/dist/src/lib/init-plan.d.ts +1 -1
  216. package/dist/src/lib/init-plan.js +1 -1
  217. package/dist/src/lib/init-xcode.d.ts +6 -5
  218. package/dist/src/lib/init-xcode.js +34 -10
  219. package/dist/src/lib/init-xcode.js.map +1 -1
  220. package/dist/src/lib/integration-selector.d.ts +42 -0
  221. package/dist/src/lib/integration-selector.js +46 -0
  222. package/dist/src/lib/integration-selector.js.map +1 -0
  223. package/dist/src/lib/ios-app-id.d.ts +34 -0
  224. package/dist/src/lib/ios-app-id.js +69 -0
  225. package/dist/src/lib/ios-app-id.js.map +1 -0
  226. package/dist/src/lib/list-options.d.ts +68 -0
  227. package/dist/src/lib/list-options.js +89 -0
  228. package/dist/src/lib/list-options.js.map +1 -0
  229. package/dist/src/lib/local-state.d.ts +1 -1
  230. package/dist/src/lib/local-state.js +1 -1
  231. package/dist/src/lib/local-test-cases.d.ts +63 -0
  232. package/dist/src/lib/local-test-cases.js +136 -0
  233. package/dist/src/lib/local-test-cases.js.map +1 -0
  234. package/dist/src/lib/log-inspection.d.ts +152 -5
  235. package/dist/src/lib/log-inspection.js +179 -2
  236. package/dist/src/lib/log-inspection.js.map +1 -1
  237. package/dist/src/lib/logout-admin-session.d.ts +33 -0
  238. package/dist/src/lib/logout-admin-session.js +70 -0
  239. package/dist/src/lib/logout-admin-session.js.map +1 -0
  240. package/dist/src/lib/output.d.ts +15 -0
  241. package/dist/src/lib/output.js +28 -0
  242. package/dist/src/lib/output.js.map +1 -1
  243. package/dist/src/lib/paginate.d.ts +15 -0
  244. package/dist/src/lib/paginate.js +17 -0
  245. package/dist/src/lib/paginate.js.map +1 -1
  246. package/dist/src/lib/project-config.d.ts +46 -21
  247. package/dist/src/lib/project-config.js +74 -47
  248. package/dist/src/lib/project-config.js.map +1 -1
  249. package/dist/src/lib/prompt-cost-format.d.ts +11 -0
  250. package/dist/src/lib/prompt-cost-format.js +41 -0
  251. package/dist/src/lib/prompt-cost-format.js.map +1 -0
  252. package/dist/src/lib/prompt-schema-codegen.d.ts +147 -0
  253. package/dist/src/lib/prompt-schema-codegen.js +462 -0
  254. package/dist/src/lib/prompt-schema-codegen.js.map +1 -0
  255. package/dist/src/lib/refresh-admin-credentials.d.ts +9 -1
  256. package/dist/src/lib/refresh-admin-credentials.js +22 -2
  257. package/dist/src/lib/refresh-admin-credentials.js.map +1 -1
  258. package/dist/src/lib/resolve-owner.d.ts +19 -0
  259. package/dist/src/lib/resolve-owner.js +20 -0
  260. package/dist/src/lib/resolve-owner.js.map +1 -0
  261. package/dist/src/lib/skill-installer.d.ts +49 -3
  262. package/dist/src/lib/skill-installer.js +275 -100
  263. package/dist/src/lib/skill-installer.js.map +1 -1
  264. package/dist/src/lib/snapshot-audit-source.d.ts +45 -0
  265. package/dist/src/lib/snapshot-audit-source.js +58 -0
  266. package/dist/src/lib/snapshot-audit-source.js.map +1 -0
  267. package/dist/src/lib/snapshot-audit-store.d.ts +52 -0
  268. package/dist/src/lib/snapshot-audit-store.js +196 -0
  269. package/dist/src/lib/snapshot-audit-store.js.map +1 -0
  270. package/dist/src/lib/snapshot-audit.d.ts +207 -0
  271. package/dist/src/lib/snapshot-audit.js +431 -0
  272. package/dist/src/lib/snapshot-audit.js.map +1 -0
  273. package/dist/src/lib/snapshot-build-rows.d.ts +60 -0
  274. package/dist/src/lib/snapshot-build-rows.js +87 -0
  275. package/dist/src/lib/snapshot-build-rows.js.map +1 -0
  276. package/dist/src/lib/snapshot-build.d.ts +50 -0
  277. package/dist/src/lib/snapshot-build.js +111 -0
  278. package/dist/src/lib/snapshot-build.js.map +1 -0
  279. package/dist/src/lib/snapshot-manifest-layout.d.ts +61 -0
  280. package/dist/src/lib/snapshot-manifest-layout.js +70 -0
  281. package/dist/src/lib/snapshot-manifest-layout.js.map +1 -0
  282. package/dist/src/lib/snapshots.d.ts +8 -9
  283. package/dist/src/lib/snapshots.js +20 -83
  284. package/dist/src/lib/snapshots.js.map +1 -1
  285. package/dist/src/lib/step-run-table.d.ts +43 -0
  286. package/dist/src/lib/step-run-table.js +129 -0
  287. package/dist/src/lib/step-run-table.js.map +1 -0
  288. package/dist/src/lib/storage-pending-retry.d.ts +26 -0
  289. package/dist/src/lib/storage-pending-retry.js +42 -0
  290. package/dist/src/lib/storage-pending-retry.js.map +1 -0
  291. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +42 -0
  292. package/dist/src/lib/swift-codegen/agentGenerator.js +118 -0
  293. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -0
  294. package/dist/src/lib/swift-codegen/banners.d.ts +24 -0
  295. package/dist/src/lib/swift-codegen/banners.js +25 -0
  296. package/dist/src/lib/swift-codegen/banners.js.map +1 -0
  297. package/dist/src/lib/swift-codegen/dbGenerator.js +19 -7
  298. package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -1
  299. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +139 -0
  300. package/dist/src/lib/swift-codegen/functionGenerator.js +462 -0
  301. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -0
  302. package/dist/src/lib/swift-codegen/generator.d.ts +7 -1
  303. package/dist/src/lib/swift-codegen/generator.js +28 -11
  304. package/dist/src/lib/swift-codegen/generator.js.map +1 -1
  305. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +15 -0
  306. package/dist/src/lib/swift-codegen/schemaToSwift.js +21 -4
  307. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  308. package/dist/src/lib/sync-paths.d.ts +72 -55
  309. package/dist/src/lib/sync-paths.js +97 -100
  310. package/dist/src/lib/sync-paths.js.map +1 -1
  311. package/dist/src/lib/sync-resource-types.d.ts +23 -4
  312. package/dist/src/lib/sync-resource-types.js +106 -8
  313. package/dist/src/lib/sync-resource-types.js.map +1 -1
  314. package/dist/src/lib/sync-selectors.d.ts +45 -2
  315. package/dist/src/lib/sync-selectors.js +66 -5
  316. package/dist/src/lib/sync-selectors.js.map +1 -1
  317. package/dist/src/lib/template.d.ts +2 -2
  318. package/dist/src/lib/template.js +2 -2
  319. package/dist/src/lib/test-case-file-names.d.ts +40 -0
  320. package/dist/src/lib/test-case-file-names.js +91 -0
  321. package/dist/src/lib/test-case-file-names.js.map +1 -0
  322. package/dist/src/lib/test-case-keys.d.ts +1 -1
  323. package/dist/src/lib/test-case-keys.js +1 -1
  324. package/dist/src/lib/test-case-variables.d.ts +14 -0
  325. package/dist/src/lib/test-case-variables.js +42 -0
  326. package/dist/src/lib/test-case-variables.js.map +1 -1
  327. package/dist/src/lib/toml-database-config.js +19 -2
  328. package/dist/src/lib/toml-database-config.js.map +1 -1
  329. package/dist/src/lib/web-url.d.ts +40 -0
  330. package/dist/src/lib/web-url.js +76 -0
  331. package/dist/src/lib/web-url.js.map +1 -0
  332. package/dist/src/lib/webhook-deliver.d.ts +209 -0
  333. package/dist/src/lib/webhook-deliver.js +519 -0
  334. package/dist/src/lib/webhook-deliver.js.map +1 -0
  335. package/dist/src/lib/workflow-codegen/generator.d.ts +1 -1
  336. package/dist/src/lib/workflow-codegen/generator.js +1 -1
  337. package/dist/src/lib/workflow-toml-validator.d.ts +17 -8
  338. package/dist/src/lib/workflow-toml-validator.js +25 -12
  339. package/dist/src/lib/workflow-toml-validator.js.map +1 -1
  340. package/dist/src/lib/workflow-usage.d.ts +196 -0
  341. package/dist/src/lib/workflow-usage.js +310 -0
  342. package/dist/src/lib/workflow-usage.js.map +1 -0
  343. package/dist/src/types/index.d.ts +12 -2
  344. package/package.json +5 -4
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Resolve the identifier the `prompts tests` and `workflows tests` verbs take
3
+ * (issue #3249).
4
+ *
5
+ * The block-testing endpoints key on the composite `<type>#<blockId>` and
6
+ * never check that the block exists, so an identifier that names no prompt or
7
+ * workflow came back as an empty page rather than a 404: `tests list <key>`
8
+ * printed "No test cases found." and exited 0, and a checked-in
9
+ * `prompts/<key>.tests/` sidecar looked unregistered until the id was tried.
10
+ * The key is what an author has to hand — `prompts list` prints it beside the
11
+ * id, and the config tree, `config push` and the test sidecars are all
12
+ * key-addressed — so a wrong identifier was indistinguishable from a block
13
+ * with no cases.
14
+ *
15
+ * Resolving here — against the app's own list — is what makes an empty
16
+ * listing mean "this block exists and has no cases", the same answer #3000
17
+ * gave the integration verbs (`integration-selector.ts`). The list is the one
18
+ * call that can answer both halves: it maps a key to its id and it proves the
19
+ * identifier belongs to THIS app. It is drained across every page, because
20
+ * the server pages prompts at 50 and workflows at 25 by default. Archived
21
+ * blocks are included, because their cases stay inspectable.
22
+ *
23
+ * Keys are matched exactly first. The server does not lowercase prompt or
24
+ * workflow keys on write, so a case-insensitive match is a fallback that
25
+ * resolves only when it is unambiguous — two keys differing only in case are
26
+ * refused by name rather than picked between (the `resolveScript` rule in
27
+ * `scripts.ts`).
28
+ */
29
+ import { paginateAll } from "./paginate.js";
30
+ const PROMPT_KIND = {
31
+ noun: "prompt",
32
+ idField: "promptId",
33
+ keyField: "promptKey",
34
+ listCommand: "primitive prompts list",
35
+ };
36
+ const WORKFLOW_KIND = {
37
+ noun: "workflow",
38
+ idField: "workflowId",
39
+ keyField: "workflowKey",
40
+ listCommand: "primitive workflows list",
41
+ };
42
+ /** The largest page the list endpoints accept (#1316), so a drain is few calls. */
43
+ const PAGE_LIMIT = 100;
44
+ /**
45
+ * Map a prompt ID or key to its prompt ID.
46
+ *
47
+ * Throws — naming the identifier — when nothing in the app matches, so the
48
+ * caller's existing catch prints the message and exits non-zero.
49
+ */
50
+ export function resolvePromptSelector(client, appId, selector) {
51
+ return resolveBlockSelector(PROMPT_KIND, (params) => client.listPrompts(appId, params), appId, selector);
52
+ }
53
+ /** The same resolution for a workflow ID or key. */
54
+ export function resolveWorkflowSelector(client, appId, selector) {
55
+ return resolveBlockSelector(WORKFLOW_KIND, (params) => client.listWorkflows(appId, params), appId, selector);
56
+ }
57
+ async function resolveBlockSelector(kind, list, appId, selector) {
58
+ const identifier = (selector ?? "").trim();
59
+ if (!identifier) {
60
+ throw new Error(`A ${kind.noun} ID or key is required.`);
61
+ }
62
+ const items = await paginateAll((cursor) => list(cursor ? { cursor, limit: PAGE_LIMIT } : { limit: PAGE_LIMIT }));
63
+ const keyOf = (item) => typeof item?.[kind.keyField] === "string" ? item[kind.keyField] : undefined;
64
+ let match = items.find((item) => item?.[kind.idField] === identifier) ??
65
+ items.find((item) => keyOf(item) === identifier);
66
+ if (!match) {
67
+ const lowered = identifier.toLowerCase();
68
+ const ci = items.filter((item) => keyOf(item)?.toLowerCase() === lowered);
69
+ if (ci.length > 1) {
70
+ const candidates = ci
71
+ .map((item) => keyOf(item))
72
+ .sort()
73
+ .join(", ");
74
+ throw new Error(`${capitalize(kind.noun)} key is ambiguous: ${identifier}. Did you mean: ${candidates}? ` +
75
+ `Keys differing only in case must be given exactly, or by ID.`);
76
+ }
77
+ match = ci[0];
78
+ }
79
+ if (!match) {
80
+ throw new Error(`No ${kind.noun} '${identifier}' in app ${appId}. ` +
81
+ `Pass a ${kind.noun} key or ID from '${kind.listCommand}'.`);
82
+ }
83
+ const blockKey = keyOf(match);
84
+ return {
85
+ blockId: match[kind.idField] ?? identifier,
86
+ ...(blockKey ? { blockKey } : {}),
87
+ };
88
+ }
89
+ function capitalize(word) {
90
+ return word.charAt(0).toUpperCase() + word.slice(1);
91
+ }
92
+ //# sourceMappingURL=block-selector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-selector.js","sourceRoot":"","sources":["../../../src/lib/block-selector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA6B5C,MAAM,WAAW,GAAc;IAC7B,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,wBAAwB;CACtC,CAAC;AAEF,MAAM,aAAa,GAAc;IAC/B,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,YAAY;IACrB,QAAQ,EAAE,aAAa;IACvB,WAAW,EAAE,0BAA0B;CACxC,CAAC;AAEF,mFAAmF;AACnF,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAoB,EACpB,KAAa,EACb,QAAgB;IAEhB,OAAO,oBAAoB,CACzB,WAAW,EACX,CAAC,MAAM,EAAE,EAAE,CAAC,MAA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AAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC"}
@@ -1,68 +1,38 @@
1
1
  /**
2
2
  * Shared source-directory resolution for the CLI codegen commands
3
- * (`workflows codegen` #1442 and `databases codegen` #814, issue #1510).
3
+ * (`workflows codegen` #1442, `databases codegen` #814, `databases schema
4
+ * generate` #666, issue #1510).
4
5
  *
5
- * Both commands read a set of `*.toml` schemas out of a synced sub-directory
6
- * (`workflows/` or `database-type-configs/`) and render `*.generated.ts` beside them.
7
- * Historically each command located that source directory by scanning EVERY
8
- * `.primitive/sync/<env>/<appId>/<subdir>` slot and either hard-erroring on
9
- * more than one (`workflows`) or silently merging across environments
10
- * (`databases`, via a `seenTypes` dedup). Neither did any environment
11
- * resolution, so `PRIMITIVE_ENV=dev workflows codegen` would happily generate
12
- * from the `alpha` TOML while `databases codegen` followed a different env —
13
- * the two generated-type trees could come from different environments in one
14
- * run.
6
+ * Each of them reads a set of `*.toml` schemas out of one synced sub-directory
7
+ * (`workflows/`, `database-type-configs/`) and renders `*.generated.ts` beside
8
+ * them. It used to take four branches to say which directory that was: a
9
+ * `--dir` override, the resolved environment, an `--app`-alone fallback, and —
10
+ * when none of those answered — a SCAN of every `primitive/<env>/<subdir>` that resolved
11
+ * if exactly one environment happened to have the directory. The scan is how
12
+ * `PRIMITIVE_ENV=dev workflows codegen` could generate from the `alpha` TOML,
13
+ * and how two codegen commands in one run could read two different
14
+ * environments.
15
15
  *
16
- * This helper resolves the source directory the same way every other CLI
17
- * command targets an environment: `--env` → `PRIMITIVE_ENV` →
18
- * `defaultEnvironment` → single-env → error. `--dir` and `--app` remain
19
- * explicit overrides. It returns ONLY the resolved source directory; TOML
20
- * collection, type filtering/dedup, and output-dir defaulting stay in each
21
- * command.
16
+ * There is one branch now (#3154, intent criterion 4): the sub-directory of
17
+ * the environment's own tree. `resolveSyncDir()` refuses rather than guesses,
18
+ * so an ambiguous project, an unknown `--env` and no project at all each reach
19
+ * the user as themselves.
22
20
  *
23
- * Design notes (binding, from the plan of record for #1510):
24
- * - Call `getCurrentEnvironment()` DIRECTLY when no `--dir` override is given.
25
- * `resolveSyncDir()`'s internal `safeEnv()` swallows the resolver's
26
- * ambiguity error and falls back to `./config`, so genuine ambiguity must
27
- * be surfaced here, not through `resolveSyncDir()`.
21
+ * Design notes that survive:
28
22
  * - Throw plain `Error`s; the calling commands keep their existing
29
- * `error(); process.exit(1)` convention (they catch at the boundary).
30
- * - Do NOT use `resolveAppId()` — it is auth-oriented and exits the process,
31
- * which is wrong for an offline codegen path.
32
- * - Preserve the `--app`-alone legacy fallback: when `--app` is given, NO
33
- * environment was explicitly requested, and env resolution fails (or there
34
- * is no project config / legacy bare-dir mode), scan
35
- * `.primitive/sync/<env>/<app>/<subdir>` for that specific app, resolving
36
- * when it appears under exactly one env and erroring (naming the candidate
37
- * envs) when it appears under more than one. This keeps the existing
38
- * integration contract
39
- * (`cli/tests/integration/workflows-codegen.test.ts`) intact.
40
- * - Do NOT fall through to that scan when an environment WAS explicitly named
41
- * (`--env` or `PRIMITIVE_ENV`) but is invalid/unknown: surface the
42
- * resolver's error instead, so an explicit env selection never silently
43
- * generates code from a different synced environment.
23
+ * `error(); process.exit(1)` convention (they catch at the boundary). A
24
+ * `PrimitiveEnvError` from the resolver is an Error too, and its message is
25
+ * already the one the user needs.
26
+ * - Do NOT use `resolveAppId()` — it is auth-oriented, and codegen is
27
+ * offline.
44
28
  */
45
- export interface ResolveCodegenSourceDirOptions {
46
- /** `--app <app-id>` override, if the user passed it. */
47
- app?: string;
48
- /** The resolved sync-directory override (`--dir <path>`), if the user passed it. */
49
- syncDir?: string;
50
- }
51
29
  export interface ResolveCodegenSourceDirArgs {
52
30
  /** The synced sub-directory to resolve, e.g. "workflows" or "database-type-configs". */
53
31
  subdir: string;
54
- /** Parsed command options (`--app`, plus the resolved `--dir` override). */
55
- options: ResolveCodegenSourceDirOptions;
56
- /**
57
- * Working directory the legacy scan is rooted at. Defaults to
58
- * `process.cwd()`; parameterised so unit tests can point it at a tmp tree
59
- * (vitest workers can't `chdir`).
60
- */
61
- cwd?: string;
62
32
  }
63
33
  /**
64
- * Resolves the single source directory a codegen command should read its
65
- * `*.toml` schemas from. Throws a plain `Error` (with a user-facing message)
66
- * when the directory can't be resolved unambiguously or doesn't exist.
34
+ * The single source directory a codegen command reads its `*.toml` schemas
35
+ * from. Throws with a user-facing message when the environment cannot be
36
+ * resolved or the directory is not there.
67
37
  */
68
38
  export declare function resolveCodegenSourceDir(args: ResolveCodegenSourceDirArgs): string;
@@ -1,168 +1,46 @@
1
1
  /**
2
2
  * Shared source-directory resolution for the CLI codegen commands
3
- * (`workflows codegen` #1442 and `databases codegen` #814, issue #1510).
3
+ * (`workflows codegen` #1442, `databases codegen` #814, `databases schema
4
+ * generate` #666, issue #1510).
4
5
  *
5
- * Both commands read a set of `*.toml` schemas out of a synced sub-directory
6
- * (`workflows/` or `database-type-configs/`) and render `*.generated.ts` beside them.
7
- * Historically each command located that source directory by scanning EVERY
8
- * `.primitive/sync/<env>/<appId>/<subdir>` slot and either hard-erroring on
9
- * more than one (`workflows`) or silently merging across environments
10
- * (`databases`, via a `seenTypes` dedup). Neither did any environment
11
- * resolution, so `PRIMITIVE_ENV=dev workflows codegen` would happily generate
12
- * from the `alpha` TOML while `databases codegen` followed a different env —
13
- * the two generated-type trees could come from different environments in one
14
- * run.
6
+ * Each of them reads a set of `*.toml` schemas out of one synced sub-directory
7
+ * (`workflows/`, `database-type-configs/`) and renders `*.generated.ts` beside
8
+ * them. It used to take four branches to say which directory that was: a
9
+ * `--dir` override, the resolved environment, an `--app`-alone fallback, and —
10
+ * when none of those answered — a SCAN of every `primitive/<env>/<subdir>` that resolved
11
+ * if exactly one environment happened to have the directory. The scan is how
12
+ * `PRIMITIVE_ENV=dev workflows codegen` could generate from the `alpha` TOML,
13
+ * and how two codegen commands in one run could read two different
14
+ * environments.
15
15
  *
16
- * This helper resolves the source directory the same way every other CLI
17
- * command targets an environment: `--env` → `PRIMITIVE_ENV` →
18
- * `defaultEnvironment` → single-env → error. `--dir` and `--app` remain
19
- * explicit overrides. It returns ONLY the resolved source directory; TOML
20
- * collection, type filtering/dedup, and output-dir defaulting stay in each
21
- * command.
16
+ * There is one branch now (#3154, intent criterion 4): the sub-directory of
17
+ * the environment's own tree. `resolveSyncDir()` refuses rather than guesses,
18
+ * so an ambiguous project, an unknown `--env` and no project at all each reach
19
+ * the user as themselves.
22
20
  *
23
- * Design notes (binding, from the plan of record for #1510):
24
- * - Call `getCurrentEnvironment()` DIRECTLY when no `--dir` override is given.
25
- * `resolveSyncDir()`'s internal `safeEnv()` swallows the resolver's
26
- * ambiguity error and falls back to `./config`, so genuine ambiguity must
27
- * be surfaced here, not through `resolveSyncDir()`.
21
+ * Design notes that survive:
28
22
  * - Throw plain `Error`s; the calling commands keep their existing
29
- * `error(); process.exit(1)` convention (they catch at the boundary).
30
- * - Do NOT use `resolveAppId()` — it is auth-oriented and exits the process,
31
- * which is wrong for an offline codegen path.
32
- * - Preserve the `--app`-alone legacy fallback: when `--app` is given, NO
33
- * environment was explicitly requested, and env resolution fails (or there
34
- * is no project config / legacy bare-dir mode), scan
35
- * `.primitive/sync/<env>/<app>/<subdir>` for that specific app, resolving
36
- * when it appears under exactly one env and erroring (naming the candidate
37
- * envs) when it appears under more than one. This keeps the existing
38
- * integration contract
39
- * (`cli/tests/integration/workflows-codegen.test.ts`) intact.
40
- * - Do NOT fall through to that scan when an environment WAS explicitly named
41
- * (`--env` or `PRIMITIVE_ENV`) but is invalid/unknown: surface the
42
- * resolver's error instead, so an explicit env selection never silently
43
- * generates code from a different synced environment.
23
+ * `error(); process.exit(1)` convention (they catch at the boundary). A
24
+ * `PrimitiveEnvError` from the resolver is an Error too, and its message is
25
+ * already the one the user needs.
26
+ * - Do NOT use `resolveAppId()` — it is auth-oriented, and codegen is
27
+ * offline.
44
28
  */
45
- import { existsSync, readdirSync } from "fs";
46
- import { basename, dirname, join } from "path";
47
- import { getCurrentEnvironment, getExplicitEnvName } from "../env-resolver.js";
48
- import { getCurrentAppId } from "../config.js";
49
- import { resolveSyncDir, assertSafePathComponent } from "../sync-paths.js";
29
+ import { existsSync } from "fs";
30
+ import { join } from "path";
31
+ import { resolveSyncDir } from "../sync-paths.js";
50
32
  /**
51
- * Resolves the single source directory a codegen command should read its
52
- * `*.toml` schemas from. Throws a plain `Error` (with a user-facing message)
53
- * when the directory can't be resolved unambiguously or doesn't exist.
33
+ * The single source directory a codegen command reads its `*.toml` schemas
34
+ * from. Throws with a user-facing message when the environment cannot be
35
+ * resolved or the directory is not there.
54
36
  */
55
37
  export function resolveCodegenSourceDir(args) {
56
- const { subdir, options } = args;
57
- const cwd = args.cwd ?? process.cwd();
58
- // 1. --dir is an explicit override: use <dir>/<subdir> verbatim.
59
- if (options.syncDir) {
60
- return requireExisting(join(options.syncDir, subdir), subdir, undefined);
61
- }
62
- // 2. Resolve the active environment. Call getCurrentEnvironment() directly
63
- // (not via resolveSyncDir/safeEnv) so a genuinely ambiguous project
64
- // surfaces the resolver's "No environment selected… Available: …" error
65
- // with a non-zero exit — unless the caller narrowed the target with
66
- // --app AND did not name an environment, in which case we fall back to the
67
- // legacy per-app scan.
68
- //
69
- // The `--app`-alone fallback only applies when NO environment was
70
- // explicitly requested (neither `--env` nor `PRIMITIVE_ENV`). When the
71
- // user DID name an env but it's invalid/unknown, getCurrentEnvironment()
72
- // throws; we must surface that error (non-zero exit) rather than silently
73
- // scanning the app under some OTHER synced environment — that would
74
- // generate code from the wrong env instead of honoring the explicit
75
- // selection.
76
- const explicitEnvRequested = getExplicitEnvName() !== null || !!process.env.PRIMITIVE_ENV;
77
- let env;
78
- try {
79
- env = getCurrentEnvironment();
80
- }
81
- catch (err) {
82
- if (options.app && !explicitEnvRequested) {
83
- return scanSyncTree({ subdir, appId: options.app, cwd });
84
- }
85
- throw err;
86
- }
87
- // 3. Project mode: resolve the app id and build the env/app-scoped path.
88
- if (env) {
89
- const appId = options.app ?? env.config.appId ?? getCurrentAppId();
90
- if (!appId) {
91
- throw new Error(`No app configured for environment "${env.name}" in .primitive/config.json ` +
92
- `and no --app given. Add "appId" to the environment or pass --app <app-id>.`);
93
- }
94
- // resolveSyncDir re-reads the (cached) resolved env and guards appId via
95
- // assertSafePathComponent, so an unsafe --app is rejected here.
96
- const dir = join(resolveSyncDir({ appId }), subdir);
97
- return requireExisting(dir, subdir, appId);
98
- }
99
- // 4. Legacy / bare-dir mode (no .primitive/config.json): scan the sync tree,
100
- // filtered to --app when given. This preserves the pre-#1510 behavior.
101
- return scanSyncTree({ subdir, appId: options.app, cwd });
102
- }
103
- /**
104
- * Legacy fallback: scan `<cwd>/.primitive/sync/<env>/<app>/<subdir>` for a
105
- * source directory. When `appId` is given, only that app's slots are
106
- * considered. Resolves to the single match; errors clearly on zero or on
107
- * ambiguity (naming the candidate apps or envs).
108
- */
109
- function scanSyncTree(args) {
110
- const { subdir, appId, cwd } = args;
111
- // Defence-in-depth: an --app value flows into a file-system path below, so
112
- // reject separators / `..` before using it.
113
- if (appId)
114
- assertSafePathComponent(appId, "appId");
115
- const root = join(cwd, ".primitive", "sync");
116
- const found = [];
117
- if (existsSync(root)) {
118
- for (const envName of readdirSync(root)) {
119
- const envDir = join(root, envName);
120
- try {
121
- for (const app of readdirSync(envDir)) {
122
- if (appId && app !== appId)
123
- continue;
124
- const candidate = join(envDir, app, subdir);
125
- if (existsSync(candidate))
126
- found.push(candidate);
127
- }
128
- }
129
- catch {
130
- // Not a directory (or unreadable) — skip.
131
- }
132
- }
133
- }
134
- if (found.length === 0) {
135
- throw new Error(notFoundMessage(subdir, appId));
136
- }
137
- if (found.length > 1) {
138
- if (appId) {
139
- const envs = [
140
- ...new Set(found.map((d) => basename(dirname(dirname(d))))),
141
- ];
142
- throw new Error(`App "${appId}" has a ${subdir}/ directory under multiple environments: ` +
143
- `${envs.join(", ")}.\n` +
144
- found.map((d) => ` ${d}`).join("\n") +
145
- `\nPass --env <name> or --dir to select one.`);
146
- }
147
- const apps = [...new Set(found.map((d) => basename(dirname(d))))];
148
- throw new Error(`Found ${subdir}/ directories for more than one app/env:\n` +
149
- found.map((d) => ` ${d}`).join("\n") +
150
- `\nCodegen writes into one output dir, so it must run against one app. ` +
151
- `Pass --app <app-id> (found: ${apps.join(", ")}) or --dir to select one.`);
152
- }
153
- return found[0];
154
- }
155
- /** Verifies `dir` exists, throwing the standard "no source dir" error otherwise. */
156
- function requireExisting(dir, subdir, appId) {
38
+ const { subdir } = args;
39
+ const dir = join(resolveSyncDir(), subdir);
157
40
  if (!existsSync(dir)) {
158
- throw new Error(notFoundMessage(subdir, appId));
41
+ throw new Error(`No ${subdir}/ directory in ${dir}. Run \`primitive config pull\` first, ` +
42
+ `or select another environment with --env <name>.`);
159
43
  }
160
44
  return dir;
161
45
  }
162
- function notFoundMessage(subdir, appId) {
163
- return appId
164
- ? `No ${subdir}/ directory found for app "${appId}" under .primitive/sync/. ` +
165
- `Check the --app id, pass --dir, or run \`primitive config pull\` first.`
166
- : `No ${subdir}/ directory found. Pass --dir or run \`primitive config pull\` first.`;
167
- }
168
46
  //# sourceMappingURL=resolveCodegenSourceDir.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveCodegenSourceDir.js","sourceRoot":"","sources":["../../../../src/lib/codegen-shared/resolveCodegenSourceDir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;A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AC;IAED,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,oFAAoF;AACpF,SAAS,eAAe,CACtB,GAAW,EACX,MAAc,EACd,KAAyB;IAEzB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,eAAe,CAAC,MAAc,EAAE,KAAyB;IAChE,OAAO,KAAK;QACV,CAAC,CAAC,MAAM,MAAM,8BAA8B,KAAK,4BAA4B;YACzE,yEAAyE;QAC7E,CAAC,CAAC,MAAM,MAAM,uEAAuE,CAAC;AAC1F,CAAC"}
1
+ {"version":3,"file":"resolveCodegenSourceDir.js","sourceRoot":"","sources":["../../../../src/lib/codegen-shared/resolveCodegenSourceDir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOlD;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAiC;IACvE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACxB,MAAM,GAAG,GAAG,IAAI,CAAC,cAAc,EAAE,EAAE,MAAM,CAAC,CAAC;IAC3C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,MAAM,MAAM,kBAAkB,GAAG,yCAAyC;YACxE,kDAAkD,CACrD,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,184 @@
1
+ /**
2
+ * The `collections.json` artifact, and the decisions an import makes from it
3
+ * (#3643).
4
+ *
5
+ * `documents export-all` / `documents import` carry Yjs state, blobs,
6
+ * permissions and aliases, but nothing about collections: which exist, what
7
+ * each contains, who its members are and at what level, its group grants, and
8
+ * who owns it. This module is the half of `collections export` /
9
+ * `collections import` that needs no server — the file's shape, the plan the
10
+ * import builds from it, the comparisons that plan rests on, and the exit
11
+ * rule — so each is checkable on its own, as `document-ingest-rows` and
12
+ * `snapshot-build-rows` are for their commands.
13
+ *
14
+ * The one thing that does NOT live here is resolution: which userId an email
15
+ * answers to, whether a document exists, whether a group exists. Those are
16
+ * reads against a real server, they are the facts the plan is built from, and
17
+ * the command performs them and hands the answers in.
18
+ */
19
+ /** The only file version this CLI reads or writes. */
20
+ export declare const COLLECTION_EXPORT_VERSION = 1;
21
+ /** Its name inside an export directory, beside `manifest.json`. */
22
+ export declare const COLLECTION_EXPORT_FILENAME = "collections.json";
23
+ export type CollectionPermission = "reader" | "read-write";
24
+ export interface ExportedOwner {
25
+ /** The SOURCE app's userId. Meaningful in the target only for a same-app import. */
26
+ userId: string;
27
+ /** Present when the source server could resolve it; the only cross-app identity. */
28
+ email?: string;
29
+ }
30
+ export interface ExportedMember extends ExportedOwner {
31
+ permission: CollectionPermission;
32
+ }
33
+ export interface ExportedGroupGrant {
34
+ groupType: string;
35
+ groupId: string;
36
+ permission: CollectionPermission;
37
+ }
38
+ export interface ExportedCollectionDocument {
39
+ documentId: string;
40
+ addedAt?: string | null;
41
+ }
42
+ export interface ExportedCollection {
43
+ collectionId: string;
44
+ name: string;
45
+ description: string | null;
46
+ collectionType: string | null;
47
+ contextId: string | null;
48
+ createdAt: string | null;
49
+ owner: ExportedOwner | null;
50
+ documents: ExportedCollectionDocument[];
51
+ members: ExportedMember[];
52
+ groups: ExportedGroupGrant[];
53
+ }
54
+ export interface CollectionExportFile {
55
+ version: number;
56
+ exportedAt: string;
57
+ sourceAppId: string;
58
+ collectionCount: number;
59
+ collections: ExportedCollection[];
60
+ }
61
+ /**
62
+ * Resolve the `<path>` an import was given to the file it must read.
63
+ *
64
+ * Both forms work: an export DIRECTORY (the one `documents export-all` also
65
+ * wrote into) and the file itself.
66
+ */
67
+ export declare function resolveCollectionExportPath(inputPath: string): string;
68
+ /**
69
+ * Read and validate `collections.json`.
70
+ *
71
+ * Every refusal here happens BEFORE any request: a file this CLI cannot read
72
+ * is not a reason to start writing collections into the target app.
73
+ */
74
+ export declare function readCollectionExportFile(inputPath: string): CollectionExportFile;
75
+ export type CollectionImportAction = "create" | "merge" | "skip" | "refused";
76
+ /** Which part of a collection a per-item problem is about. */
77
+ export type CollectionProblemKind = "owner" | "collection" | "document" | "member" | "group";
78
+ export interface CollectionImportProblem {
79
+ sourceCollectionId: string;
80
+ name: string;
81
+ kind: CollectionProblemKind;
82
+ /** The offending identity: a userId, an email, a documentId, `type/id`. */
83
+ id: string;
84
+ reason: string;
85
+ }
86
+ /** The target collection a name match found, as far as compatibility cares. */
87
+ export interface ExistingTargetCollection {
88
+ collectionId: string;
89
+ createdBy: string;
90
+ collectionType: string | null;
91
+ contextId: string | null;
92
+ }
93
+ export interface CollectionResolution {
94
+ /** The userId the owner resolved to in the TARGET app, or null. */
95
+ ownerUserId: string | null;
96
+ /** Why the owner could not be resolved — becomes the refusal's reason. */
97
+ ownerReason?: string;
98
+ /** The target collection carrying this exact name, if any. */
99
+ existing?: ExistingTargetCollection | null;
100
+ /** The source id of an earlier collection in the same file with this name. */
101
+ duplicateOfSourceId?: string | null;
102
+ }
103
+ export interface CollectionPlanRow {
104
+ sourceCollectionId: string;
105
+ name: string;
106
+ action: CollectionImportAction;
107
+ /** Why it was refused or skipped. Absent for `create`/`merge`. */
108
+ reason?: string;
109
+ /** Where it lands: known up front only for a `merge`. */
110
+ targetCollectionId?: string;
111
+ /** The resolved owner, for a `create`. */
112
+ ownerUserId?: string;
113
+ /** A refusal that must also be REPORTED as a problem carries it here. */
114
+ problem?: Omit<CollectionImportProblem, "sourceCollectionId" | "name">;
115
+ }
116
+ /**
117
+ * Which of `createdBy`, `collectionType` and `contextId` a name match differs
118
+ * on — the fields the server will never let an update change
119
+ * (`collections-controller.ts` rejects type and context; `createdBy` is
120
+ * immutable), so a difference cannot be merged away (F2).
121
+ *
122
+ * Returns null when the match is compatible.
123
+ */
124
+ export declare function incompatibleField(collection: Pick<ExportedCollection, "collectionType" | "contextId">, existing: ExistingTargetCollection, ownerUserId: string): "owner" | "collectionType" | "contextId" | null;
125
+ /** What to do about one recorded group grant, given the target's grants. */
126
+ export type GrantDisposition = "grant" | "already-applied" | "update";
127
+ /**
128
+ * Compare a recorded grant with the target's.
129
+ *
130
+ * A grant already at the recorded level counts as applied without a write. A
131
+ * grant at a DIFFERENT level is sent: #3163 recomputes each document's
132
+ * materialized `DocumentGroupPermission` from its live sources on every
133
+ * collection-wide change, so the new level reaches what the group's members can
134
+ * actually do. Before that it did not — `materializeDGP` left an existing row
135
+ * alone once the collection was one of its sources — which is why the import
136
+ * used to report such a grant instead of changing it (F3).
137
+ */
138
+ export declare function grantDisposition(wanted: ExportedGroupGrant, targetGrants: ExportedGroupGrant[]): GrantDisposition;
139
+ /** The line a level change is announced with, named from and to. */
140
+ export declare function grantUpdateLine(groupLabel: string, existingPermission: string, wantedPermission: string): string;
141
+ /**
142
+ * What a server refusal reads as in a per-item problem.
143
+ *
144
+ * The prose alone is not enough to act on. `COLLECTION_FANOUT_LIMIT` is the
145
+ * case that matters here: past `COLLECTION_GROUP_FANOUT_MAX` documents the
146
+ * server refuses a collection-wide group change whole (#3163), and the remedy —
147
+ * split the collection, or grant its documents one at a time — is nothing like
148
+ * the remedy for a 404 group. Carrying the code makes the two tellable apart by
149
+ * a script as well as by a reader.
150
+ */
151
+ export declare function serverReason(err: any): string;
152
+ /**
153
+ * Decide what happens to one collection, from the facts the resolve phase read.
154
+ *
155
+ * Nothing here talks to a server: every input is already an answer.
156
+ */
157
+ export declare function planCollection(collection: ExportedCollection, resolution: CollectionResolution, options: {
158
+ overwrite: boolean;
159
+ }): CollectionPlanRow;
160
+ /**
161
+ * The source ids of earlier same-named collections, keyed by source id.
162
+ *
163
+ * The FIRST collection with a name is the one that may land; every later one
164
+ * maps to it here and is refused.
165
+ */
166
+ export declare function duplicateNameSources(collections: ExportedCollection[]): Map<string, string>;
167
+ export interface CollectionImportSummary {
168
+ created: number;
169
+ merged: number;
170
+ skipped: number;
171
+ refused: number;
172
+ groupsGranted: number;
173
+ membersAdded: number;
174
+ documentsAdded: number;
175
+ }
176
+ export declare function emptyImportSummary(): CollectionImportSummary;
177
+ /**
178
+ * The exit rule, in one place: 1 when any per-item problem was reported.
179
+ *
180
+ * A skip for a name collision is NOT a problem — it is the documented way to
181
+ * re-run an import without `--overwrite`. A refusal is, because something the
182
+ * operator asked for did not happen.
183
+ */
184
+ export declare function importExitCode(problems: CollectionImportProblem[]): number;