primitive-admin 1.2.0-alpha.15 → 1.2.0-alpha.16

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 (202) hide show
  1. package/README.md +84 -0
  2. package/dist/src/commands/admins.js +1 -0
  3. package/dist/src/commands/admins.js.map +1 -1
  4. package/dist/src/commands/analytics.js +2 -4
  5. package/dist/src/commands/analytics.js.map +1 -1
  6. package/dist/src/commands/apps-transitions.d.ts +39 -0
  7. package/dist/src/commands/apps-transitions.js +198 -0
  8. package/dist/src/commands/apps-transitions.js.map +1 -0
  9. package/dist/src/commands/apps.d.ts +11 -0
  10. package/dist/src/commands/apps.js +50 -5
  11. package/dist/src/commands/apps.js.map +1 -1
  12. package/dist/src/commands/auth-sessions.js +2 -0
  13. package/dist/src/commands/auth-sessions.js.map +1 -1
  14. package/dist/src/commands/auth.js +5 -0
  15. package/dist/src/commands/auth.js.map +1 -1
  16. package/dist/src/commands/blob-buckets.js +2 -0
  17. package/dist/src/commands/blob-buckets.js.map +1 -1
  18. package/dist/src/commands/collections.js +2 -13
  19. package/dist/src/commands/collections.js.map +1 -1
  20. package/dist/src/commands/comparisons.js +2 -0
  21. package/dist/src/commands/comparisons.js.map +1 -1
  22. package/dist/src/commands/config.js +2 -0
  23. package/dist/src/commands/config.js.map +1 -1
  24. package/dist/src/commands/connections.js +2 -2
  25. package/dist/src/commands/connections.js.map +1 -1
  26. package/dist/src/commands/db3.js +79 -21
  27. package/dist/src/commands/db3.js.map +1 -1
  28. package/dist/src/commands/email-templates.js +2 -0
  29. package/dist/src/commands/email-templates.js.map +1 -1
  30. package/dist/src/commands/env.js +2 -0
  31. package/dist/src/commands/env.js.map +1 -1
  32. package/dist/src/commands/functions.js +45 -3
  33. package/dist/src/commands/functions.js.map +1 -1
  34. package/dist/src/commands/groups.js +2 -0
  35. package/dist/src/commands/groups.js.map +1 -1
  36. package/dist/src/commands/guides.js +2 -0
  37. package/dist/src/commands/guides.js.map +1 -1
  38. package/dist/src/commands/hosting.d.ts +8 -0
  39. package/dist/src/commands/hosting.js +346 -0
  40. package/dist/src/commands/hosting.js.map +1 -0
  41. package/dist/src/commands/init.js +2 -0
  42. package/dist/src/commands/init.js.map +1 -1
  43. package/dist/src/commands/integrations.js +2 -0
  44. package/dist/src/commands/integrations.js.map +1 -1
  45. package/dist/src/commands/locks.js +2 -0
  46. package/dist/src/commands/locks.js.map +1 -1
  47. package/dist/src/commands/metadata-category-configs.js +1 -1
  48. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  49. package/dist/src/commands/metadata.js +2 -2
  50. package/dist/src/commands/metadata.js.map +1 -1
  51. package/dist/src/commands/prompts.js +2 -0
  52. package/dist/src/commands/prompts.js.map +1 -1
  53. package/dist/src/commands/rate-counters.d.ts +19 -0
  54. package/dist/src/commands/rate-counters.js +104 -0
  55. package/dist/src/commands/rate-counters.js.map +1 -0
  56. package/dist/src/commands/rule-sets.js +2 -2
  57. package/dist/src/commands/rule-sets.js.map +1 -1
  58. package/dist/src/commands/schemas.js +4 -4
  59. package/dist/src/commands/schemas.js.map +1 -1
  60. package/dist/src/commands/secrets.js +2 -0
  61. package/dist/src/commands/secrets.js.map +1 -1
  62. package/dist/src/commands/skill.js +2 -0
  63. package/dist/src/commands/skill.js.map +1 -1
  64. package/dist/src/commands/sync.d.ts +101 -2
  65. package/dist/src/commands/sync.js +391 -62
  66. package/dist/src/commands/sync.js.map +1 -1
  67. package/dist/src/commands/tokens.js +2 -0
  68. package/dist/src/commands/tokens.js.map +1 -1
  69. package/dist/src/commands/transitions.d.ts +54 -0
  70. package/dist/src/commands/transitions.js +418 -0
  71. package/dist/src/commands/transitions.js.map +1 -0
  72. package/dist/src/commands/usage.d.ts +18 -0
  73. package/dist/src/commands/usage.js +343 -0
  74. package/dist/src/commands/usage.js.map +1 -0
  75. package/dist/src/commands/user-properties.js +2 -2
  76. package/dist/src/commands/user-properties.js.map +1 -1
  77. package/dist/src/commands/users.js +28 -29
  78. package/dist/src/commands/users.js.map +1 -1
  79. package/dist/src/commands/vars.js +2 -0
  80. package/dist/src/commands/vars.js.map +1 -1
  81. package/dist/src/commands/waitlist.js +2 -2
  82. package/dist/src/commands/waitlist.js.map +1 -1
  83. package/dist/src/lib/api-client.d.ts +606 -2
  84. package/dist/src/lib/api-client.js +157 -6
  85. package/dist/src/lib/api-client.js.map +1 -1
  86. package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
  87. package/dist/src/lib/app-settings-descriptor.js +6 -0
  88. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  89. package/dist/src/lib/auth-flow.d.ts +33 -0
  90. package/dist/src/lib/auth-flow.js +404 -13
  91. package/dist/src/lib/auth-flow.js.map +1 -1
  92. package/dist/src/lib/cli-manifest.d.ts +5 -4
  93. package/dist/src/lib/cli-manifest.js.map +1 -1
  94. package/dist/src/lib/command-groups.d.ts +30 -0
  95. package/dist/src/lib/command-groups.js +109 -0
  96. package/dist/src/lib/command-groups.js.map +1 -0
  97. package/dist/src/lib/command-status.d.ts +56 -19
  98. package/dist/src/lib/command-status.js +101 -19
  99. package/dist/src/lib/command-status.js.map +1 -1
  100. package/dist/src/lib/config-object-descriptor.js +0 -1
  101. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  102. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +7 -0
  103. package/dist/src/lib/db-codegen/dbTypeIR.js +3 -0
  104. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  105. package/dist/src/lib/db-type-records.d.ts +12 -1
  106. package/dist/src/lib/db-type-records.js +8 -3
  107. package/dist/src/lib/db-type-records.js.map +1 -1
  108. package/dist/src/lib/db3-export.js +2 -2
  109. package/dist/src/lib/db3-export.js.map +1 -1
  110. package/dist/src/lib/db3-index-output.d.ts +26 -3
  111. package/dist/src/lib/db3-index-output.js +48 -12
  112. package/dist/src/lib/db3-index-output.js.map +1 -1
  113. package/dist/src/lib/db3-type-models.d.ts +11 -1
  114. package/dist/src/lib/db3-type-models.js +22 -2
  115. package/dist/src/lib/db3-type-models.js.map +1 -1
  116. package/dist/src/lib/function-authorize-view.d.ts +12 -0
  117. package/dist/src/lib/function-authorize-view.js +34 -0
  118. package/dist/src/lib/function-authorize-view.js.map +1 -1
  119. package/dist/src/lib/function-collect.d.ts +13 -0
  120. package/dist/src/lib/function-collect.js +37 -7
  121. package/dist/src/lib/function-collect.js.map +1 -1
  122. package/dist/src/lib/function-db-types.d.ts +14 -8
  123. package/dist/src/lib/function-db-types.js +56 -21
  124. package/dist/src/lib/function-db-types.js.map +1 -1
  125. package/dist/src/lib/function-lint.d.ts +24 -1
  126. package/dist/src/lib/function-lint.js +123 -1
  127. package/dist/src/lib/function-lint.js.map +1 -1
  128. package/dist/src/lib/function-schema-codegen.d.ts +31 -7
  129. package/dist/src/lib/function-schema-codegen.js +131 -36
  130. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  131. package/dist/src/lib/function-sync.js +9 -1
  132. package/dist/src/lib/function-sync.js.map +1 -1
  133. package/dist/src/lib/generated-command-status.d.ts +6 -0
  134. package/dist/src/lib/generated-command-status.js +469 -0
  135. package/dist/src/lib/generated-command-status.js.map +1 -0
  136. package/dist/src/lib/generated-config-surfaces.d.ts +28 -3
  137. package/dist/src/lib/generated-config-surfaces.js +91 -16
  138. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  139. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  140. package/dist/src/lib/generated-sdk-types.js +1 -1
  141. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  142. package/dist/src/lib/hosting-build.d.ts +97 -0
  143. package/dist/src/lib/hosting-build.js +204 -0
  144. package/dist/src/lib/hosting-build.js.map +1 -0
  145. package/dist/src/lib/hosting-client.d.ts +167 -0
  146. package/dist/src/lib/hosting-client.js +340 -0
  147. package/dist/src/lib/hosting-client.js.map +1 -0
  148. package/dist/src/lib/hosting-environments.d.ts +32 -0
  149. package/dist/src/lib/hosting-environments.js +74 -0
  150. package/dist/src/lib/hosting-environments.js.map +1 -0
  151. package/dist/src/lib/hosting-errors.d.ts +30 -0
  152. package/dist/src/lib/hosting-errors.js +43 -0
  153. package/dist/src/lib/hosting-errors.js.map +1 -0
  154. package/dist/src/lib/hosting-token.d.ts +46 -0
  155. package/dist/src/lib/hosting-token.js +60 -0
  156. package/dist/src/lib/hosting-token.js.map +1 -0
  157. package/dist/src/lib/hosting-wait.d.ts +42 -0
  158. package/dist/src/lib/hosting-wait.js +84 -0
  159. package/dist/src/lib/hosting-wait.js.map +1 -0
  160. package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
  161. package/dist/src/lib/hosting-wfp-upload.js +149 -0
  162. package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
  163. package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
  164. package/dist/src/lib/invoker-shared-enums.js +98 -0
  165. package/dist/src/lib/invoker-shared-enums.js.map +1 -0
  166. package/dist/src/lib/log-inspection.d.ts +4 -1
  167. package/dist/src/lib/log-inspection.js.map +1 -1
  168. package/dist/src/lib/primitive-declaration.d.ts +32 -1
  169. package/dist/src/lib/primitive-declaration.js +153 -19
  170. package/dist/src/lib/primitive-declaration.js.map +1 -1
  171. package/dist/src/lib/prompt-schema-codegen.d.ts +1 -1
  172. package/dist/src/lib/prompt-schema-codegen.js +31 -19
  173. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  174. package/dist/src/lib/prompt-schema-refs.d.ts +9 -0
  175. package/dist/src/lib/prompt-schema-refs.js +28 -2
  176. package/dist/src/lib/prompt-schema-refs.js.map +1 -1
  177. package/dist/src/lib/register-commands.d.ts +14 -6
  178. package/dist/src/lib/register-commands.js +19 -83
  179. package/dist/src/lib/register-commands.js.map +1 -1
  180. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +10 -4
  181. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -1
  182. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +11 -2
  183. package/dist/src/lib/schema-codegen/generated-field-grammar.js +22 -4
  184. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -1
  185. package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
  186. package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
  187. package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
  188. package/dist/src/lib/schema-codegen/valuesLists.d.ts +15 -2
  189. package/dist/src/lib/schema-codegen/valuesLists.js +19 -3
  190. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -1
  191. package/dist/src/lib/swift-codegen/functionGenerator.js +4 -3
  192. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  193. package/dist/src/lib/swift-codegen/sharedGenerator.js +50 -5
  194. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -1
  195. package/dist/src/lib/sync-resource-types.js +0 -3
  196. package/dist/src/lib/sync-resource-types.js.map +1 -1
  197. package/dist/src/lib/toml-database-config.js +3 -1
  198. package/dist/src/lib/toml-database-config.js.map +1 -1
  199. package/dist/src/lib/transition-warnings.d.ts +21 -0
  200. package/dist/src/lib/transition-warnings.js +49 -0
  201. package/dist/src/lib/transition-warnings.js.map +1 -0
  202. package/package.json +2 -2
@@ -1,4 +1,3 @@
1
- import { subcommandStatus } from "../lib/command-status.js";
2
1
  import { EXPERIMENTAL_APIS } from "../lib/generated-build-flags.js";
3
2
  import { configFamilyServed, servedPushPruneSpecs } from "../lib/experimental-apis.js";
4
3
  import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, unlinkSync, rmdirSync, statSync } from "fs";
@@ -45,7 +44,7 @@ import { agentDeclarationFunctionKeys, resolveAgentDeclaration, } from "../lib/g
45
44
  import { AGENT_TEST_CASE_FIELDS, resolveAgentTestCase, } from "../lib/generated-config-surfaces.js";
46
45
  // #3799 — the meaning-preserving schema translation, vendored the same way, so
47
46
  // the preflight refuses exactly the schemas the admin routes refuse.
48
- import { agentSchemaTranslationRefusals, promptSchemaDeficits, promptSchemaRefusals } from "../lib/generated-config-surfaces.js";
47
+ import { agentSchemaTranslationRefusals, promptSchemaDeficits } from "../lib/generated-config-surfaces.js";
49
48
  // #4441 — the rule for a change to a function an agent uses, vendored the same
50
49
  // way, so the preflight refuses exactly the changes the function routes refuse.
51
50
  import { agentFunctionChangeRefusals, agentFunctionUses, } from "../lib/generated-config-surfaces.js";
@@ -56,9 +55,9 @@ import { resolvePromptStrictOutput } from "../lib/generated-config-surfaces.js";
56
55
  // `config push` sends, and the bytes `config pull` writes back.
57
56
  import { applyFunctionPull, buildFunctionConfigPush, buildFunctionConfigPushDetailed, createDocumentSchemaDropWarner, documentSchemaRetentionFailure, buildFunctionCreatePayload, buildFunctionUpdatePayload, functionDiffEntity, functionTomlPreflightErrors, functionPushPreRefusal, functionVersionRefusalMessage, unchangedAccessWarning, planDocumentSchemaPull, planFunctionPull, serializeFunction, } from "../lib/function-sync.js";
58
57
  import { compileFunctionToml, functionFileLabel } from "../lib/function-schema-refs.js";
59
- import { compilePromptToml, promptSchemaCycleError, preparePromptSchemaRefs, promptConfigSchemaPayload, promptDependenciesOf, promptPlacementErrors, promptPushDependencies, promptSchemaPayload, withSchemaPayload, } from "../lib/prompt-schema-refs.js";
58
+ import { compilePromptToml, promptSchemaCycleError, promptSchemaKeywordRefusals, preparePromptSchemaRefs, promptConfigSchemaPayload, promptDependenciesOf, promptPlacementErrors, promptPushDependencies, promptSchemaPayload, withSchemaPayload, } from "../lib/prompt-schema-refs.js";
60
59
  import { promptFamilyIndexLoader, rememberRemoteFunctions, rememberRemotePrompts } from "../lib/schema-family-index.js";
61
- import { promptConfigName, promptFileLabel } from "../lib/prompt-schema-document.js";
60
+ import { promptFileLabel } from "../lib/prompt-schema-document.js";
62
61
  import { rememberRemoteSchemaFiles, rememberedRemoteDb3Types, rememberRemoteDb3Types, schemaFamilyIndexLoader } from "../lib/schema-family-index.js";
63
62
  import { createSchemaPinJudge, schemaFileReader, schemaPinHint } from "../lib/schema-pins.js";
64
63
  import { attachDependants, functionSchemaPreview, promptSchemaPreview, renderDependantsLine, renderSchemaPreviewLines, } from "../lib/schema-preview.js";
@@ -112,6 +111,18 @@ function printStaleInstanceWarning(updated) {
112
111
  warn(` ${w.message}`);
113
112
  }
114
113
  }
114
+ /**
115
+ * #6019: the changes `--allow-field-removal` let through on one type, as the
116
+ * type write answered them (`appendOnlyOverride.reasons`), one line each.
117
+ */
118
+ function printAppendOnlyOverride(type, answer) {
119
+ const reasons = answer?.appendOnlyOverride?.reasons;
120
+ if (!Array.isArray(reasons) || reasons.length === 0)
121
+ return;
122
+ warn(` --allow-field-removal let ${reasons.length} change${reasons.length === 1 ? "" : "s"} through on ${type}:`);
123
+ for (const line of appendOnlyReasonLines(type, reasons))
124
+ warn(` ${line}`);
125
+ }
115
126
  /**
116
127
  * The current environment's baseline. Every reader goes through
117
128
  * `resolveSyncStateReadPath`, so a machine-local environment reads its own
@@ -1546,7 +1557,11 @@ function buildConfigPayloadFields(tomlConfig, create, tomlOwned) {
1546
1557
  * are checked one by one and the unknown keys reported together, so a typo in
1547
1558
  * the third `[[configs]]` block is as loud as one in the first.
1548
1559
  */
1549
- export function configUnknownKeyError(filePath, tomlData, table) {
1560
+ export function configUnknownKeyError(filePath, tomlData, table,
1561
+ // #5993 — the surface the file belongs to, when a key's sentence depends on
1562
+ // it: a db3 type file and a database type file share the `type` prefix.
1563
+ surfaceLabel) {
1564
+ const prefix = table.tomlPath.join(".");
1550
1565
  const at = table.tomlPath.reduce((node, segment) => (node == null ? node : node[segment]), tomlData);
1551
1566
  const entries = table.repeated
1552
1567
  ? Array.isArray(at)
@@ -1560,8 +1575,12 @@ export function configUnknownKeyError(filePath, tomlData, table) {
1560
1575
  // where the CLI looked.
1561
1576
  const groupedUnknown = new Set();
1562
1577
  for (const entry of entries) {
1563
- for (const key of findUnknownTomlKeys(entry, table))
1578
+ for (const key of findUnknownTomlKeys(entry, table)) {
1579
+ // #5993 — the empty placeholder an earlier pull wrote is accepted.
1580
+ if (retiredTomlKey(prefix, key, surfaceLabel)?.emptyAccepted && entry?.[key] === "")
1581
+ continue;
1564
1582
  unknown.add(key);
1583
+ }
1565
1584
  for (const key of findUnknownGroupedTomlKeys(entry, table)) {
1566
1585
  groupedUnknown.add(key);
1567
1586
  }
@@ -1575,16 +1594,15 @@ export function configUnknownKeyError(filePath, tomlData, table) {
1575
1594
  // #3642 — a spelling retired from TOML only (a flat chat key under
1576
1595
  // `[[configs]]`) is answered from the same module, before the misplaced-key
1577
1596
  // line below could send the author to the block without saying why.
1578
- const prefix = table.tomlPath.join(".");
1579
1597
  const retiredHere = [...unknown]
1580
- .filter((k) => retiredTomlKey(prefix, k))
1598
+ .filter((k) => retiredTomlKey(prefix, k, surfaceLabel))
1581
1599
  .sort();
1582
1600
  const trulyUnknown = [...unknown]
1583
- .filter((k) => !retiredTomlKey(prefix, k))
1601
+ .filter((k) => !retiredTomlKey(prefix, k, surfaceLabel))
1584
1602
  .sort();
1585
1603
  const messages = [];
1586
1604
  for (const key of retiredHere) {
1587
- messages.push(`${filePath}: ${prefix}.${key} — ${retiredTomlKey(prefix, key).toml}`);
1605
+ messages.push(`${filePath}: ${prefix}.${key} — ${retiredTomlKey(prefix, key, surfaceLabel).toml}`);
1588
1606
  }
1589
1607
  // #3626, SO3626-013 — a key the definition DOES declare, written at the
1590
1608
  // table root when it is authored under a group. Before grouping,
@@ -2664,24 +2682,9 @@ export function promptKindFileErrors(filePath, tomlData) {
2664
2682
  // #5538 — a keyword the lossless Gemini translator or the engine would
2665
2683
  // refuse, judged on the compiled schemas with the server's own rule, one
2666
2684
  // `<CODE>: <line>` per keyword as a compile refusal prints. A refused
2667
- // compile is reported above and not judged again.
2668
- if (!compiledSchemas.refusal && prompt && typeof prompt === "object") {
2669
- const compiledEntries = Array.isArray(compiledSchemas.parsed?.configs) ? compiledSchemas.parsed.configs : [];
2670
- const deficits = promptSchemaDeficits({
2671
- inputSchema: prompt.inputSchema,
2672
- outputSchema: prompt.outputSchema,
2673
- agent: prompt.agent,
2674
- configs: compiledEntries.map((entry, index) => ({
2675
- name: promptConfigName(entry, index),
2676
- provider: String(entry?.provider ?? ""),
2677
- status: entry?.status === undefined ? undefined : String(entry.status),
2678
- outputSchema: entry?.chat && typeof entry.chat === "object" ? entry.chat.outputSchema : undefined,
2679
- })),
2680
- });
2681
- for (const refusal of promptSchemaRefusals(deficits)) {
2682
- errors.push(`${promptFileLabel(filePath)}: ${refusal.code}: ${refusal.message}`);
2683
- }
2684
- }
2685
+ // compile is reported above and not judged again. `functions codegen`
2686
+ // refuses with these same lines (#5894).
2687
+ errors.push(...promptSchemaKeywordRefusals(filePath, compiledSchemas));
2685
2688
  for (const [index, rawEntry] of entries.entries()) {
2686
2689
  // #3642 — the blocks are read as the file wrote them. A chat key at the
2687
2690
  // entry's root is the retired flat spelling, which the unknown-key check
@@ -3317,7 +3320,7 @@ export function configFileValidationMessages(filePath, tomlData, surface, tables
3317
3320
  // be misleading.
3318
3321
  messages.push(...configDocumentShapeErrors(filePath, tomlData, surface));
3319
3322
  for (const table of tables) {
3320
- const unknownKeyError = configUnknownKeyError(filePath, tomlData, table);
3323
+ const unknownKeyError = configUnknownKeyError(filePath, tomlData, table, surface.label);
3321
3324
  if (unknownKeyError)
3322
3325
  messages.push(unknownKeyError);
3323
3326
  }
@@ -3765,6 +3768,11 @@ export function dbTypeOwnedScalars(table = DATABASE_TYPE_TABLE) {
3765
3768
  ];
3766
3769
  }
3767
3770
  export const DB_TYPE_OWNED_SCALARS = dbTypeOwnedScalars();
3771
+ /**
3772
+ * #5993 — the fields a `db3-types/` file owns: the db3 type table's, which
3773
+ * declares no rule set, so a db3 push body carries no `ruleSetId` at all.
3774
+ */
3775
+ export const DB3_TYPE_OWNED_SCALARS = dbTypeOwnedScalars(DB3_TYPE_TABLE);
3768
3776
  // User-facing TOML key names for the "Cleared <field>" push output, for the
3769
3777
  // field whose wire name differs from the key the user writes.
3770
3778
  const DB_TYPE_FIELD_LABELS = {
@@ -3799,9 +3807,11 @@ export function hasMeaningfulValue(v) {
3799
3807
  * converges the server to the local TOML: a field removed from the file lands
3800
3808
  * as `null` and is cleared.
3801
3809
  */
3802
- export function buildOwnedScalarUpdate(typeConfig) {
3810
+ export function buildOwnedScalarUpdate(typeConfig,
3811
+ // #5993 — a db3 type passes `DB3_TYPE_OWNED_SCALARS`.
3812
+ ownedFields = DB_TYPE_OWNED_SCALARS) {
3803
3813
  const u = {};
3804
- for (const key of DB_TYPE_OWNED_SCALARS) {
3814
+ for (const key of ownedFields) {
3805
3815
  u[key] = typeConfig[key] ?? null;
3806
3816
  }
3807
3817
  return u;
@@ -3898,8 +3908,11 @@ table = DATABASE_TYPE_TABLE) {
3898
3908
  mode: "create",
3899
3909
  }));
3900
3910
  canonicalizeDatabaseTypeConfig(typeConfig);
3901
- // The `ruleSetName` reference; it resolves to an id later.
3902
- applyRuleSetReference(typeSection, typeConfig);
3911
+ // The `ruleSetName` reference; it resolves to an id later. #5993 — only for
3912
+ // a table that declares one: a db3 type takes no rule set.
3913
+ if (table.fields.some((f) => f.field === "ruleSetId")) {
3914
+ applyRuleSetReference(typeSection, typeConfig);
3915
+ }
3903
3916
  if (tomlData.triggers) {
3904
3917
  typeConfig.triggers = tomlData.triggers;
3905
3918
  }
@@ -4668,8 +4681,269 @@ export const DB3_TYPE_DIFF_SPEC = {
4668
4681
  table: DB3_TYPE_TABLE,
4669
4682
  parse: (doc) => parseDb3TypeToml(doc).typeConfig,
4670
4683
  serialize: (record, maps) => serializeDb3Type(record, maps.ruleSetIdToName),
4684
+ // #5993 — a db3 type takes no rule set: its projection carries nothing
4685
+ // about one, resolved or not, so a stored binding is no difference.
4686
+ ruleSetRef: false,
4687
+ extras: (entity) => ({
4688
+ schema: entity.schema ?? null,
4689
+ triggers: entity.triggers ?? null,
4690
+ metadataManifest: entity.metadataManifest ?? null,
4691
+ }),
4671
4692
  describe: (entity) => `db3 type "${entity?.databaseType}"`,
4672
4693
  };
4694
+ /**
4695
+ * #5993 — the db3 type's `[type]` table as CLIs before #5993 read it, with
4696
+ * the rule set field, for `EARLIER_DB3_TYPE_DIFF_SPEC` alone.
4697
+ */
4698
+ const EARLIER_DB3_TYPE_TABLE = {
4699
+ ...DB3_TYPE_TABLE,
4700
+ fields: [
4701
+ DB3_TYPE_TABLE.fields[0],
4702
+ DATABASE_TYPE_TABLE.fields.find((f) => f.field === "ruleSetId"),
4703
+ ...DB3_TYPE_TABLE.fields.slice(1),
4704
+ ],
4705
+ };
4706
+ /**
4707
+ * #5993 — the projection a sync baseline stamped by an earlier CLI was hashed
4708
+ * over: the db3 type's, rule set included. Read only to recognize such a
4709
+ * baseline as the live row's (`decideDb3TypePush`).
4710
+ */
4711
+ const EARLIER_DB3_TYPE_DIFF_SPEC = {
4712
+ ...CONFIG_DIFF_SPECS["database-type-config"],
4713
+ label: "db3-type",
4714
+ table: EARLIER_DB3_TYPE_TABLE,
4715
+ parse: (doc) => parseDatabaseTypeToml(doc, EARLIER_DB3_TYPE_TABLE).typeConfig,
4716
+ serialize: (record, maps) => stringifyConfigToml(buildDatabaseTypeTomlData(record, maps.ruleSetIdToName, EARLIER_DB3_TYPE_TABLE)),
4717
+ describe: (entity) => `db3 type "${entity?.databaseType}"`,
4718
+ };
4719
+ /**
4720
+ * `config push`'s gate for one `db3-types/` file: `decidePushForConfig` over
4721
+ * `DB3_TYPE_DIFF_SPEC`.
4722
+ *
4723
+ * #5993 — a baseline an earlier CLI stamped was hashed with the rule set, so
4724
+ * for a row with a stored binding it equals no projection this CLI makes, and
4725
+ * an ordinary edit would read as both sides having moved. A baseline that
4726
+ * equals the live row under that earlier projection says the server has not
4727
+ * moved since: it is read as the live row's current hash.
4728
+ */
4729
+ export function decideDb3TypePush(input) {
4730
+ let entry = input.entry;
4731
+ const record = input.live?.record;
4732
+ if (record && entry?.semanticHash !== undefined) {
4733
+ try {
4734
+ const current = hashRemoteConfigForDiff(DB3_TYPE_DIFF_SPEC, record, input.maps);
4735
+ if (entry.semanticHash !== current &&
4736
+ entry.semanticHash === hashRemoteConfigForDiff(EARLIER_DB3_TYPE_DIFF_SPEC, record, input.maps)) {
4737
+ entry = { ...entry, semanticHash: current };
4738
+ }
4739
+ }
4740
+ catch {
4741
+ // The gate below reports a row it cannot project.
4742
+ }
4743
+ }
4744
+ return decidePushForConfig({ ...input, spec: DB3_TYPE_DIFF_SPEC, entry });
4745
+ }
4746
+ /**
4747
+ * The body `PUT db3-types/:name` is sent for one parsed `db3-types/` file,
4748
+ * before its concurrency guard. The file owns every field: an absent one is
4749
+ * sent as null and cleared (#1567). #5993 — no `ruleSetId`: a db3 type takes
4750
+ * none.
4751
+ */
4752
+ export function buildDb3TypePushBody(typeConfig, options) {
4753
+ const body = {
4754
+ ...buildOwnedScalarUpdate(typeConfig, DB3_TYPE_OWNED_SCALARS),
4755
+ triggers: typeConfig.triggers ?? null,
4756
+ metadataManifest: typeConfig.metadataManifest ?? null,
4757
+ };
4758
+ if (typeof typeConfig.schema === "string" && typeConfig.schema.trim().length > 0)
4759
+ body.schema = typeConfig.schema;
4760
+ else if (options.serverHasSchema)
4761
+ body.schema = null;
4762
+ return body;
4763
+ }
4764
+ /** `<type>: <path>: <reason>`, one line per change the append-only rule refused or let through (#6019). */
4765
+ export function appendOnlyReasonLines(type, reasons) {
4766
+ return reasons.map((r) => `${type}: ${r.path}: ${r.reason}`);
4767
+ }
4768
+ /** The reasons of a `409 DB3_TYPE_NOT_APPEND_ONLY`, or `null` for any other error. */
4769
+ export function appendOnlyReasonsOf(err) {
4770
+ if (!(err instanceof ApiError) || err.code !== "DB3_TYPE_NOT_APPEND_ONLY")
4771
+ return null;
4772
+ const details = err.details && !Array.isArray(err.details) ? err.details : {};
4773
+ return Array.isArray(details.reasons) ? details.reasons : [];
4774
+ }
4775
+ /**
4776
+ * #6019 — whether a failed preflight request says nothing about the write it
4777
+ * asked about: no HTTP answer at all, a 5xx, a timeout (408) or a throttle
4778
+ * (429). Any other 4xx is the server's final answer for that body.
4779
+ */
4780
+ export function preflightFailureIsInconclusive(err) {
4781
+ if (!(err instanceof ApiError))
4782
+ return true;
4783
+ const status = err.statusCode;
4784
+ if (typeof status !== "number" || status <= 0)
4785
+ return true;
4786
+ return status >= 500 || status === 408 || status === 429;
4787
+ }
4788
+ function preflightErrorText(err) {
4789
+ if (err instanceof ApiError)
4790
+ return `${err.statusCode}${err.code ? ` ${err.code}` : ""}: ${err.message}`;
4791
+ return err instanceof Error ? err.message : String(err);
4792
+ }
4793
+ /**
4794
+ * One preflight request, retried while its failure is inconclusive
4795
+ * ({@link preflightFailureIsInconclusive}), up to `attempts` tries. Answers the
4796
+ * value, or the last error.
4797
+ */
4798
+ export async function preflightCall(send, retryDelayMs = 500, attempts = 3) {
4799
+ let last;
4800
+ for (let attempt = 1; attempt <= attempts; attempt++) {
4801
+ try {
4802
+ return { ok: true, value: await send() };
4803
+ }
4804
+ catch (err) {
4805
+ last = err;
4806
+ if (!preflightFailureIsInconclusive(err) || attempt === attempts)
4807
+ break;
4808
+ if (retryDelayMs > 0)
4809
+ await new Promise((r) => setTimeout(r, retryDelayMs * attempt));
4810
+ }
4811
+ }
4812
+ return { ok: false, error: last };
4813
+ }
4814
+ /**
4815
+ * #6019 — the append-only preflight of `config push`: before any type row is
4816
+ * written, dry-run every schema update the run is about to make to an
4817
+ * existing type, from `db3-types/` and `database-type-configs/` alike, and
4818
+ * answer every type the server refuses `DB3_TYPE_NOT_APPEND_ONLY`. A file the
4819
+ * run would not write (unchanged, drifted, in conflict, or a create) is not
4820
+ * asked; a legacy file skipped as its selected db3 twin's duplicate is not
4821
+ * asked twice. A `DB3_TYPE_FIELD_REMOVAL_NOT_ENABLED` answer is thrown. Any
4822
+ * other server refusal (a 4xx) is final for that write, so it is left to the
4823
+ * apply loops, which meet it again as before. A failure that says nothing
4824
+ * about the write (no answer, a 5xx, 408, 429), on the dry run or the type
4825
+ * listing, is retried; if it persists the preflight throws, so no type row is
4826
+ * written by a run whose types were not all validated.
4827
+ */
4828
+ export async function preflightDb3TypeAppendOnly(input) {
4829
+ const { client, appId, configDir, selectFiles, maps, syncState, force, allowFieldRemoval } = input;
4830
+ const retryDelayMs = input.retryDelayMs ?? 500;
4831
+ const db3Dir = join(configDir, "db3-types");
4832
+ const legacyDir = join(configDir, "database-type-configs");
4833
+ const db3Files = existsSync(db3Dir) ? selectFiles("db3-type", db3Dir, readdirSync(db3Dir).filter((f) => f.endsWith(".toml"))) : [];
4834
+ const legacyFiles = existsSync(legacyDir)
4835
+ ? selectFiles("database-type-config", legacyDir, readdirSync(legacyDir).filter((f) => f.endsWith(".toml")))
4836
+ : [];
4837
+ if (db3Files.length === 0 && legacyFiles.length === 0)
4838
+ return [];
4839
+ const live = new Map();
4840
+ const listed = await preflightCall(() => client.listDatabaseTypeConfigs(appId), retryDelayMs);
4841
+ if (!listed.ok) {
4842
+ throw new Error(`The append-only preflight could not list this app's types (${preflightErrorText(listed.error)}). ` +
4843
+ "No type was written; run the push again.");
4844
+ }
4845
+ for (const c of Array.isArray(listed.value) ? listed.value : [])
4846
+ if (c?.databaseType)
4847
+ live.set(c.databaseType, c);
4848
+ const refusals = [];
4849
+ const ask = async (type, send) => {
4850
+ const answer = await preflightCall(send, retryDelayMs);
4851
+ if (answer.ok)
4852
+ return;
4853
+ const err = answer.error;
4854
+ if (err instanceof ApiError && err.code === "DB3_TYPE_FIELD_REMOVAL_NOT_ENABLED") {
4855
+ throw new ApiError(`DB3_TYPE_FIELD_REMOVAL_NOT_ENABLED: ${err.message}`, err.statusCode, err.code, err.details);
4856
+ }
4857
+ const reasons = appendOnlyReasonsOf(err);
4858
+ if (reasons) {
4859
+ refusals.push({ type, reasons });
4860
+ return;
4861
+ }
4862
+ if (preflightFailureIsInconclusive(err)) {
4863
+ throw new Error(`The append-only preflight could not validate type "${type}" (${preflightErrorText(err)}). ` +
4864
+ "No type was written; run the push again.");
4865
+ }
4866
+ };
4867
+ const hasSchema = (row) => typeof row?.schema === "string" && row.schema.trim().length > 0;
4868
+ const db3Names = new Set();
4869
+ if (db3Files.length > 0) {
4870
+ const resolution = resolveDb3TypeModels(db3Dir);
4871
+ for (const file of db3Files) {
4872
+ const filePath = join(db3Dir, file);
4873
+ const tomlData = resolution.documents.get(file) ?? parseTomlFile(filePath);
4874
+ const { typeConfig } = parseDb3TypeToml(tomlData);
4875
+ const name = typeConfig.databaseType || basename(file, ".toml");
4876
+ db3Names.add(name);
4877
+ const row = live.get(name);
4878
+ if (!row)
4879
+ continue;
4880
+ withDerivedIdentity(tomlData, "type", { name });
4881
+ const gate = decideDb3TypePush({
4882
+ maps,
4883
+ localParsed: tomlData,
4884
+ live: { record: row, extra: {}, modifiedAt: row.modifiedAt },
4885
+ entry: syncState?.entities?.db3Types?.[name],
4886
+ localFileHash: computeFileHash(filePath),
4887
+ force,
4888
+ });
4889
+ if (gate.action !== "update")
4890
+ continue;
4891
+ const body = buildDb3TypePushBody(typeConfig, { serverHasSchema: hasSchema(row) });
4892
+ if (!("schema" in body))
4893
+ continue;
4894
+ await ask(name, () => client.pushDb3Type(appId, name, body, { dryRun: true, allowFieldRemoval }));
4895
+ }
4896
+ }
4897
+ if (legacyFiles.length > 0) {
4898
+ const agreeing = new Set(classifyDb3TypeTwins(configDir, maps).agreeing);
4899
+ const spec = configDiffSpec("database-type-config");
4900
+ for (const file of legacyFiles) {
4901
+ const filePath = join(legacyDir, file);
4902
+ const tomlData = parseTomlFile(filePath);
4903
+ const { typeConfig } = parseDatabaseTypeToml(tomlData);
4904
+ const name = typeConfig.databaseType || basename(file, ".toml");
4905
+ // The selected db3 twin's dry run already asked for this schema.
4906
+ if (agreeing.has(name) && db3Names.has(name))
4907
+ continue;
4908
+ const row = live.get(name);
4909
+ if (!row)
4910
+ continue;
4911
+ withDerivedIdentity(tomlData, "type", { databaseType: name });
4912
+ const gate = decidePushForConfig({
4913
+ spec,
4914
+ maps,
4915
+ localParsed: tomlData,
4916
+ live: { record: row, extra: {}, modifiedAt: row.modifiedAt },
4917
+ entry: syncState?.entities?.databaseTypes?.[name],
4918
+ localFileHash: computeFileHash(filePath),
4919
+ force,
4920
+ });
4921
+ if (gate.action !== "update")
4922
+ continue;
4923
+ // The schema the legacy apply loop sends (`computeTypeUpdateData`).
4924
+ const localHasSchema = typeof typeConfig.schema === "string" && typeConfig.schema.trim().length > 0;
4925
+ if (!localHasSchema && !hasSchema(row))
4926
+ continue;
4927
+ const schema = localHasSchema ? typeConfig.schema : null;
4928
+ await ask(name, () => client.updateDatabaseTypeConfig(appId, name, { schema }, undefined, { dryRun: true, allowFieldRemoval }));
4929
+ }
4930
+ }
4931
+ return refusals;
4932
+ }
4933
+ /**
4934
+ * #5993 — whether a `database-type-configs/` file whose db3 twin agrees with
4935
+ * it must still go through the database type push: its rule set, which the
4936
+ * twin comparison leaves out, differs from the live row's. Empty and null
4937
+ * read alike. Without live rows there is nothing to compare against, and the
4938
+ * twin is skipped as before.
4939
+ */
4940
+ export function legacyTwinPushesItsRuleSet(input) {
4941
+ if (!input.liveAvailable)
4942
+ return false;
4943
+ const local = input.localRuleSetId || null;
4944
+ const live = input.live?.ruleSetId || null;
4945
+ return local !== live;
4946
+ }
4673
4947
  /**
4674
4948
  * #5025 — what a `config push` conflict on `db3-types/<name>.toml` says when
4675
4949
  * the server holds a type of that name this tree never pulled: a database
@@ -4749,7 +5023,9 @@ export function classifyDb3TypeTwins(configDir, maps = { ruleSetIdToName: new Ma
4749
5023
  let same = false;
4750
5024
  try {
4751
5025
  const db3Side = projectLocalConfig(DB3_TYPE_DIFF_SPEC, parsed, maps);
4752
- const legacySide = projectLocalConfig(configDiffSpec("database-type-config"), twin.parsed, maps);
5026
+ // #5993 — a db3 type takes no rule set, so the legacy file's is left
5027
+ // out, resolved (`ruleSetId`) or not (`_unresolvedRuleSetName`).
5028
+ const { ruleSetId: _ruleSetId, _unresolvedRuleSetName: _unresolved, ...legacySide } = projectLocalConfig(configDiffSpec("database-type-config"), twin.parsed, maps);
4753
5029
  same = computeExpandedContentHash(withParsedSchema(db3Side)) === computeExpandedContentHash(withParsedSchema(legacySide));
4754
5030
  }
4755
5031
  catch {
@@ -5678,7 +5954,12 @@ export function sameConfigAs(label, serverContent, filePath, maps, extra) {
5678
5954
  export function sameDb3TypeAs(serverContent, maps) {
5679
5955
  return (localContent) => {
5680
5956
  try {
5681
- const local = projectLocalConfig(DB3_TYPE_DIFF_SPEC, parseConfigToml(localContent), maps);
5957
+ const parsed = parseConfigToml(localContent);
5958
+ // #5993 — as `sameConfigAs`: a file push would refuse (one naming a
5959
+ // rule set) is rewritten, whatever else it says.
5960
+ if (pullMustRewrite("db3-type", parsed))
5961
+ return false;
5962
+ const local = projectLocalConfig(DB3_TYPE_DIFF_SPEC, parsed, maps);
5682
5963
  const server = projectLocalConfig(DB3_TYPE_DIFF_SPEC, parseConfigToml(serverContent), maps);
5683
5964
  return computeExpandedContentHash(local) === computeExpandedContentHash(server);
5684
5965
  }
@@ -9199,6 +9480,7 @@ export function registerConfigSyncCommands(sync, options = {}) {
9199
9480
  .option("--prune", "Delete remote entities whose local TOML was removed since the last sync (issue #1655)")
9200
9481
  .option("-y, --yes", "Skip the interactive confirmation before pruning (for CI / automation)")
9201
9482
  .option("--accept-warnings", "Commit schema diffs that have operations with dynamic refs (issue #666 SCHEMA_HAS_UNCHECKABLE_OPS escape hatch)")
9483
+ .option("--allow-field-removal", "Push db3 type changes that would make stored records unreadable (removed fields or models, changed types). Needs `[app] allowFieldRemoval = true` already stored by an earlier push")
9202
9484
  // #3320 — what this command actually guarantees, said where it is run.
9203
9485
  // Two stages, and only the first is all-or-nothing.
9204
9486
  .addHelpText("after", `
@@ -9338,6 +9620,26 @@ What a push guarantees (two stages):
9338
9620
  }
9339
9621
  }
9340
9622
  info(`Pushing configuration for app ${resolvedAppId}...`);
9623
+ // #6019 — `--allow-field-removal` works only on an app whose STORED
9624
+ // settings already enable it. Checked before anything is applied, since
9625
+ // this run applies app.toml before its types: enabling the setting and
9626
+ // using it takes two pushes.
9627
+ const allowFieldRemoval = !!options.allowFieldRemoval;
9628
+ if (allowFieldRemoval) {
9629
+ let stored = null;
9630
+ try {
9631
+ stored = await client.getAppSettings(resolvedAppId);
9632
+ }
9633
+ catch (err) {
9634
+ error(`--allow-field-removal: could not read this app's stored settings (${err?.message ?? err}). Nothing was applied.`);
9635
+ process.exit(1);
9636
+ }
9637
+ if (stored?.allowFieldRemoval !== true) {
9638
+ error("--allow-field-removal needs this app's stored settings to have allowFieldRemoval = true before the push. " +
9639
+ "Nothing was applied. Set `[app] allowFieldRemoval = true` in app.toml, run `primitive config push`, then push again with --allow-field-removal.");
9640
+ process.exit(1);
9641
+ }
9642
+ }
9341
9643
  // The state this push STARTS from, so the failure path below can tell a
9342
9644
  // run that recorded something from one that recorded nothing (#2936).
9343
9645
  // Every applied write stamps what it did into `syncState` — an id for a
@@ -11949,6 +12251,32 @@ What a push guarantees (two stages):
11949
12251
  // the same name that reads the same type is synced with this one (the
11950
12252
  // preflight refused a pair that differs), so the legacy loop below
11951
12253
  // skips it.
12254
+ // #6019 — validate every type before writing any: one dry run per
12255
+ // schema update this run makes, from db3-types/ and
12256
+ // database-type-configs/ alike, before either loop writes a row.
12257
+ {
12258
+ await loadLiveRuleSets();
12259
+ const refused = await preflightDb3TypeAppendOnly({
12260
+ client,
12261
+ appId: resolvedAppId,
12262
+ configDir,
12263
+ selectFiles,
12264
+ maps: pushDiffMaps,
12265
+ syncState,
12266
+ force: !!options.force,
12267
+ allowFieldRemoval,
12268
+ });
12269
+ if (refused.length > 0) {
12270
+ const count = refused.reduce((n, r) => n + r.reasons.length, 0);
12271
+ error(`DB3_TYPE_NOT_APPEND_ONLY: ${refused.length} type${refused.length === 1 ? "" : "s"} with db3s would make stored data unreadable ` +
12272
+ `(${count} change${count === 1 ? "" : "s"}). No type was written.`);
12273
+ for (const { type, reasons } of refused)
12274
+ for (const line of appendOnlyReasonLines(type, reasons))
12275
+ error(` ${line}`);
12276
+ throw new Error("Refused by the append-only rule. These changes are allowed while no db3 of the type exists; to make them anyway, " +
12277
+ "set `[app] allowFieldRemoval = true` in app.toml, push it, then push again with --allow-field-removal.");
12278
+ }
12279
+ }
11952
12280
  const db3TwinNames = new Set();
11953
12281
  const db3TypesDir = join(configDir, "db3-types");
11954
12282
  if (existsSync(db3TypesDir)) {
@@ -11981,7 +12309,6 @@ What a push guarantees (two stages):
11981
12309
  if (agreeingTwins.has(name))
11982
12310
  db3TwinNames.add(name);
11983
12311
  withDerivedIdentity(tomlData, "type", { name });
11984
- resolveRuleSetReference(typeConfig, ruleSetNameToId, `db3 type ${name}`, { hint: ruleSetSelectionHint });
11985
12312
  const entry = syncState?.entities?.db3Types?.[name];
11986
12313
  const live = db3TypesLiveOk ? liveDb3Types.get(name) : undefined;
11987
12314
  const record = (modifiedAt, semanticHash, hasSchema) => {
@@ -12007,8 +12334,7 @@ What a push guarantees (two stages):
12007
12334
  gate = { action: "create" };
12008
12335
  }
12009
12336
  else if (db3TypesLiveOk && live) {
12010
- gate = decidePushForConfig({
12011
- spec: DB3_TYPE_DIFF_SPEC,
12337
+ gate = decideDb3TypePush({
12012
12338
  maps: pushDiffMaps,
12013
12339
  localParsed: tomlData,
12014
12340
  live: { record: live, extra: {}, modifiedAt: live.modifiedAt },
@@ -12044,24 +12370,17 @@ What a push guarantees (two stages):
12044
12370
  const exists = db3TypesLiveOk ? !!live : !!entry;
12045
12371
  const serverHasSchema = live ? typeof live.schema === "string" && live.schema.trim().length > 0 : !!entry?.hasSchema;
12046
12372
  // The file owns every field: an absent one is sent as null and cleared (#1567).
12047
- const body = {
12048
- ...buildOwnedScalarUpdate(typeConfig),
12049
- triggers: typeConfig.triggers ?? null,
12050
- metadataManifest: typeConfig.metadataManifest ?? null,
12051
- };
12052
- if (typeof typeConfig.schema === "string" && typeConfig.schema.trim().length > 0)
12053
- body.schema = typeConfig.schema;
12054
- else if (serverHasSchema)
12055
- body.schema = null;
12373
+ const body = buildDb3TypePushBody(typeConfig, { serverHasSchema });
12056
12374
  const expectedModifiedAt = !options.force && exists ? (gate?.action === "update" ? gate.expectedModifiedAt : live?.modifiedAt ?? entry?.modifiedAt) : undefined;
12057
12375
  if (expectedModifiedAt)
12058
12376
  body.expectedModifiedAt = expectedModifiedAt;
12059
12377
  changes.push({ type: "db3-type", action: exists ? "update" : "create", key: name });
12060
12378
  try {
12061
- const answer = await client.pushDb3Type(resolvedAppId, name, body, { dryRun: !!options.dryRun });
12379
+ const answer = await client.pushDb3Type(resolvedAppId, name, body, { dryRun: !!options.dryRun, allowFieldRemoval });
12062
12380
  if (options.dryRun)
12063
12381
  continue;
12064
12382
  info(` ${answer.created ? "Created" : "Updated"} db3 type: ${name}`);
12383
+ printAppendOnlyOverride(name, answer);
12065
12384
  printStaleInstanceWarning(answer);
12066
12385
  if (answer.push?.runId) {
12067
12386
  info(` Pushing revision ${answer.revision.generation} to the db3s of ${name}: run ${answer.push.runId} — ` +
@@ -12084,6 +12403,11 @@ What a push guarantees (two stages):
12084
12403
  });
12085
12404
  continue;
12086
12405
  }
12406
+ // #6019 — a refusal the preflight did not meet (the type gained a db3 since) still lists its reasons.
12407
+ const appendOnly = appendOnlyReasonsOf(err);
12408
+ if (appendOnly)
12409
+ for (const line of appendOnlyReasonLines(name, appendOnly))
12410
+ error(` ${line}`);
12087
12411
  throw wrapEntityError(err, exists ? "update" : "create", "db3 type", name);
12088
12412
  }
12089
12413
  }
@@ -12121,8 +12445,11 @@ What a push guarantees (two stages):
12121
12445
  const tomlData = parseTomlFile(filePath);
12122
12446
  const { typeConfig } = parseDatabaseTypeToml(tomlData);
12123
12447
  const dbType = typeConfig.databaseType || basename(file, ".toml");
12124
- // #4802 — one type with the db3-types/ file of its name, pushed above.
12125
- if (db3TwinNames.has(dbType)) {
12448
+ // #4802 — one type with the db3-types/ file of its name, pushed
12449
+ // above. #5993 — unless its rule set, which a db3 type does not
12450
+ // take and the twin comparison leaves out, is not the live row's:
12451
+ // then it is pushed as any legacy file is.
12452
+ if (db3TwinNames.has(dbType) && !databaseTypesLiveOk) {
12126
12453
  skippedCount++;
12127
12454
  continue;
12128
12455
  }
@@ -12133,6 +12460,15 @@ What a push guarantees (two stages):
12133
12460
  resolveRuleSetReference(typeConfig, ruleSetNameToId, `database type ${dbType}`, {
12134
12461
  hint: ruleSetSelectionHint,
12135
12462
  });
12463
+ if (db3TwinNames.has(dbType) &&
12464
+ !legacyTwinPushesItsRuleSet({
12465
+ localRuleSetId: typeConfig.ruleSetId,
12466
+ liveAvailable: databaseTypesLiveOk,
12467
+ live: liveDatabaseTypes.get(dbType),
12468
+ })) {
12469
+ skippedCount++;
12470
+ continue;
12471
+ }
12136
12472
  const existingEntry = syncState?.entities?.databaseTypes?.[dbType];
12137
12473
  /**
12138
12474
  * This type as the server holds it NOW.
@@ -12327,6 +12663,7 @@ What a push guarantees (two stages):
12327
12663
  await client.updateDatabaseTypeConfig(resolvedAppId, dbType, computeTypeUpdateData(), validateExpectedModifiedAt, {
12328
12664
  dryRun: true,
12329
12665
  acceptWarnings: !!options.acceptWarnings,
12666
+ allowFieldRemoval,
12330
12667
  });
12331
12668
  }
12332
12669
  else if (!typeExistsOnServer) {
@@ -12457,8 +12794,10 @@ What a push guarantees (two stages):
12457
12794
  const updated = await client.updateDatabaseTypeConfig(resolvedAppId, dbType, updateData, expectedModifiedAt, {
12458
12795
  dryRun: false,
12459
12796
  acceptWarnings: !!options.acceptWarnings,
12797
+ allowFieldRemoval,
12460
12798
  });
12461
12799
  info(` Updated database type: ${dbType}`);
12800
+ printAppendOnlyOverride(dbType, updated);
12462
12801
  // Issue #1567: name each owned scalar this push cleared, so
12463
12802
  // removing a rule (triggers, autoPopulatedFields) is never
12464
12803
  // silent.
@@ -12661,8 +13000,10 @@ What a push guarantees (two stages):
12661
13000
  const reconciled = await client.updateDatabaseTypeConfig(resolvedAppId, dbType, reconcileData, undefined, {
12662
13001
  dryRun: false,
12663
13002
  acceptWarnings: !!options.acceptWarnings,
13003
+ allowFieldRemoval,
12664
13004
  });
12665
13005
  printStaleInstanceWarning(reconciled);
13006
+ printAppendOnlyOverride(dbType, reconciled);
12666
13007
  if (syncState?.entities?.databaseTypes?.[dbType] &&
12667
13008
  reconciled?.modifiedAt) {
12668
13009
  syncState.entities.databaseTypes[dbType].modifiedAt =
@@ -15466,17 +15807,5 @@ What a push guarantees (two stages):
15466
15807
  }
15467
15808
  info("Run 'primitive config diff' to inspect the restored state versus the server.");
15468
15809
  });
15469
- // Every run of pull, diff and push lists the database-type-configs
15470
- // (deprecated) and metadata-category-configs (experimental) families:
15471
- // pull and diff before any selection, push whenever the family's
15472
- // directory exists, which `config init` and `config pull` always create.
15473
- // A production build leaves the experimental family alone, so only the
15474
- // deprecated listing remains.
15475
- for (const verb of ["pull", "diff", "push"]) {
15476
- subcommandStatus(sync, verb, {
15477
- stability: experimental ? "experimental" : "production",
15478
- deprecated: true,
15479
- });
15480
- }
15481
15810
  }
15482
15811
  //# sourceMappingURL=sync.js.map