@superbee/core 0.1.6 → 0.2.0-pre.10

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 (248) hide show
  1. package/README.md +127 -0
  2. package/dist/artifact-contract.d.ts +90 -0
  3. package/dist/artifact-contract.d.ts.map +1 -0
  4. package/dist/artifact-contract.js +205 -0
  5. package/dist/artifact-contract.js.map +1 -0
  6. package/dist/backend.d.ts +16 -1
  7. package/dist/backend.d.ts.map +1 -1
  8. package/dist/backend.js +112 -47
  9. package/dist/backend.js.map +1 -1
  10. package/dist/bundle-ops.d.ts +42 -0
  11. package/dist/bundle-ops.d.ts.map +1 -0
  12. package/dist/bundle-ops.js +88 -0
  13. package/dist/bundle-ops.js.map +1 -0
  14. package/dist/bundle.d.ts +10 -28
  15. package/dist/bundle.d.ts.map +1 -1
  16. package/dist/bundle.js +12 -69
  17. package/dist/bundle.js.map +1 -1
  18. package/dist/document-codec.d.ts +6 -1
  19. package/dist/document-codec.d.ts.map +1 -1
  20. package/dist/document-codec.js +8 -4
  21. package/dist/document-codec.js.map +1 -1
  22. package/dist/document-field-actions.d.ts +107 -0
  23. package/dist/document-field-actions.d.ts.map +1 -0
  24. package/dist/document-field-actions.js +302 -0
  25. package/dist/document-field-actions.js.map +1 -0
  26. package/dist/document-mutation.d.ts +61 -3
  27. package/dist/document-mutation.d.ts.map +1 -1
  28. package/dist/document-mutation.js +116 -25
  29. package/dist/document-mutation.js.map +1 -1
  30. package/dist/document-write-policy.d.ts +0 -1
  31. package/dist/document-write-policy.d.ts.map +1 -1
  32. package/dist/document-write-policy.js +7 -4
  33. package/dist/document-write-policy.js.map +1 -1
  34. package/dist/engine.d.ts +3 -1
  35. package/dist/engine.d.ts.map +1 -1
  36. package/dist/engine.js +6 -4
  37. package/dist/engine.js.map +1 -1
  38. package/dist/file-journaled-backend-internal.d.ts +19 -0
  39. package/dist/file-journaled-backend-internal.d.ts.map +1 -0
  40. package/dist/file-journaled-backend-internal.js +10 -0
  41. package/dist/file-journaled-backend-internal.js.map +1 -0
  42. package/dist/file-journaled-backend.d.ts +162 -0
  43. package/dist/file-journaled-backend.d.ts.map +1 -0
  44. package/dist/file-journaled-backend.js +1113 -0
  45. package/dist/file-journaled-backend.js.map +1 -0
  46. package/dist/filesystem-host.d.ts +15 -0
  47. package/dist/filesystem-host.d.ts.map +1 -0
  48. package/dist/filesystem-host.js +20 -0
  49. package/dist/filesystem-host.js.map +1 -0
  50. package/dist/filesystem-identity.d.ts +86 -4
  51. package/dist/filesystem-identity.d.ts.map +1 -1
  52. package/dist/filesystem-identity.js +338 -102
  53. package/dist/filesystem-identity.js.map +1 -1
  54. package/dist/filesystem-lock.d.ts +16 -3
  55. package/dist/filesystem-lock.d.ts.map +1 -1
  56. package/dist/filesystem-lock.js +323 -77
  57. package/dist/filesystem-lock.js.map +1 -1
  58. package/dist/filesystem-push-role.d.ts +77 -0
  59. package/dist/filesystem-push-role.d.ts.map +1 -0
  60. package/dist/filesystem-push-role.js +165 -0
  61. package/dist/filesystem-push-role.js.map +1 -0
  62. package/dist/filesystem.d.ts +17 -0
  63. package/dist/filesystem.d.ts.map +1 -0
  64. package/dist/filesystem.js +18 -0
  65. package/dist/filesystem.js.map +1 -0
  66. package/dist/freshness.d.ts +10 -7
  67. package/dist/freshness.d.ts.map +1 -1
  68. package/dist/freshness.js +14 -11
  69. package/dist/freshness.js.map +1 -1
  70. package/dist/frontmatter-contract.d.ts +2 -2
  71. package/dist/frontmatter-contract.js +2 -2
  72. package/dist/frontmatter.d.ts +11 -1
  73. package/dist/frontmatter.d.ts.map +1 -1
  74. package/dist/frontmatter.js +20 -7
  75. package/dist/frontmatter.js.map +1 -1
  76. package/dist/governed-body-write.d.ts +106 -0
  77. package/dist/governed-body-write.d.ts.map +1 -0
  78. package/dist/governed-body-write.js +251 -0
  79. package/dist/governed-body-write.js.map +1 -0
  80. package/dist/heads-digest.d.ts +32 -0
  81. package/dist/heads-digest.d.ts.map +1 -0
  82. package/dist/heads-digest.js +37 -0
  83. package/dist/heads-digest.js.map +1 -0
  84. package/dist/host-policy-snapshot.d.ts +9 -0
  85. package/dist/host-policy-snapshot.d.ts.map +1 -0
  86. package/dist/host-policy-snapshot.js +33 -0
  87. package/dist/host-policy-snapshot.js.map +1 -0
  88. package/dist/host-text.d.ts +31 -0
  89. package/dist/host-text.d.ts.map +1 -0
  90. package/dist/host-text.js +77 -0
  91. package/dist/host-text.js.map +1 -0
  92. package/dist/hosted-transport/answer-rows.d.ts +216 -0
  93. package/dist/hosted-transport/answer-rows.d.ts.map +1 -0
  94. package/dist/hosted-transport/answer-rows.js +396 -0
  95. package/dist/hosted-transport/answer-rows.js.map +1 -0
  96. package/dist/hosted-transport/carrier.d.ts +142 -0
  97. package/dist/hosted-transport/carrier.d.ts.map +1 -0
  98. package/dist/hosted-transport/carrier.js +241 -0
  99. package/dist/hosted-transport/carrier.js.map +1 -0
  100. package/dist/hosted-transport/history-pages.d.ts +55 -0
  101. package/dist/hosted-transport/history-pages.d.ts.map +1 -0
  102. package/dist/hosted-transport/history-pages.js +69 -0
  103. package/dist/hosted-transport/history-pages.js.map +1 -0
  104. package/dist/hosted-transport/index.d.ts +18 -0
  105. package/dist/hosted-transport/index.d.ts.map +1 -0
  106. package/dist/hosted-transport/index.js +18 -0
  107. package/dist/hosted-transport/index.js.map +1 -0
  108. package/dist/hosted-transport/operations.d.ts +85 -0
  109. package/dist/hosted-transport/operations.d.ts.map +1 -0
  110. package/dist/hosted-transport/operations.js +128 -0
  111. package/dist/hosted-transport/operations.js.map +1 -0
  112. package/dist/hosted-transport/paged-reads.d.ts +87 -0
  113. package/dist/hosted-transport/paged-reads.d.ts.map +1 -0
  114. package/dist/hosted-transport/paged-reads.js +238 -0
  115. package/dist/hosted-transport/paged-reads.js.map +1 -0
  116. package/dist/hosted-transport/read-adapter.d.ts +250 -0
  117. package/dist/hosted-transport/read-adapter.d.ts.map +1 -0
  118. package/dist/hosted-transport/read-adapter.js +557 -0
  119. package/dist/hosted-transport/read-adapter.js.map +1 -0
  120. package/dist/hosted-transport/root-write.d.ts +114 -0
  121. package/dist/hosted-transport/root-write.d.ts.map +1 -0
  122. package/dist/hosted-transport/root-write.js +171 -0
  123. package/dist/hosted-transport/root-write.js.map +1 -0
  124. package/dist/hosted-transport/whole-document-transport.d.ts +174 -0
  125. package/dist/hosted-transport/whole-document-transport.d.ts.map +1 -0
  126. package/dist/hosted-transport/whole-document-transport.js +411 -0
  127. package/dist/hosted-transport/whole-document-transport.js.map +1 -0
  128. package/dist/index.d.ts +29 -8
  129. package/dist/index.d.ts.map +1 -1
  130. package/dist/index.js +26 -6
  131. package/dist/index.js.map +1 -1
  132. package/dist/indexeddb-backend.d.ts +197 -0
  133. package/dist/indexeddb-backend.d.ts.map +1 -0
  134. package/dist/indexeddb-backend.js +1183 -0
  135. package/dist/indexeddb-backend.js.map +1 -0
  136. package/dist/journaled-backend.d.ts +467 -0
  137. package/dist/journaled-backend.d.ts.map +1 -0
  138. package/dist/journaled-backend.js +389 -0
  139. package/dist/journaled-backend.js.map +1 -0
  140. package/dist/kind-coverage.d.ts +99 -0
  141. package/dist/kind-coverage.d.ts.map +1 -0
  142. package/dist/kind-coverage.js +186 -0
  143. package/dist/kind-coverage.js.map +1 -0
  144. package/dist/kind-field-mutation.d.ts +15 -0
  145. package/dist/kind-field-mutation.d.ts.map +1 -0
  146. package/dist/kind-field-mutation.js +160 -0
  147. package/dist/kind-field-mutation.js.map +1 -0
  148. package/dist/kinds.d.ts +31 -1
  149. package/dist/kinds.d.ts.map +1 -1
  150. package/dist/kinds.js +86 -17
  151. package/dist/kinds.js.map +1 -1
  152. package/dist/links.d.ts +1 -1
  153. package/dist/links.d.ts.map +1 -1
  154. package/dist/links.js +5 -10
  155. package/dist/links.js.map +1 -1
  156. package/dist/managed-document-metadata.d.ts +2 -0
  157. package/dist/managed-document-metadata.d.ts.map +1 -0
  158. package/dist/managed-document-metadata.js +9 -0
  159. package/dist/managed-document-metadata.js.map +1 -0
  160. package/dist/meaningful-change-time.d.ts +6 -6
  161. package/dist/meaningful-change-time.d.ts.map +1 -1
  162. package/dist/meaningful-change-time.js +12 -13
  163. package/dist/meaningful-change-time.js.map +1 -1
  164. package/dist/memory-backend.d.ts +2 -2
  165. package/dist/memory-backend.d.ts.map +1 -1
  166. package/dist/memory-backend.js +32 -16
  167. package/dist/memory-backend.js.map +1 -1
  168. package/dist/mutation.d.ts.map +1 -1
  169. package/dist/mutation.js +2 -2
  170. package/dist/mutation.js.map +1 -1
  171. package/dist/page.d.ts.map +1 -1
  172. package/dist/page.js +2 -1
  173. package/dist/page.js.map +1 -1
  174. package/dist/paths.d.ts +6 -2
  175. package/dist/paths.d.ts.map +1 -1
  176. package/dist/paths.js +35 -33
  177. package/dist/paths.js.map +1 -1
  178. package/dist/platform.d.ts +239 -0
  179. package/dist/platform.d.ts.map +1 -0
  180. package/dist/platform.js +82 -0
  181. package/dist/platform.js.map +1 -0
  182. package/dist/portable-export.d.ts +119 -0
  183. package/dist/portable-export.d.ts.map +1 -0
  184. package/dist/portable-export.js +501 -0
  185. package/dist/portable-export.js.map +1 -0
  186. package/dist/publication-filesystem.d.ts +1 -1
  187. package/dist/publication-filesystem.d.ts.map +1 -1
  188. package/dist/publication-filesystem.js +1 -1
  189. package/dist/publication-filesystem.js.map +1 -1
  190. package/dist/query-filter.d.ts +7 -2
  191. package/dist/query-filter.d.ts.map +1 -1
  192. package/dist/query-filter.js +24 -1
  193. package/dist/query-filter.js.map +1 -1
  194. package/dist/query-order.d.ts +22 -0
  195. package/dist/query-order.d.ts.map +1 -0
  196. package/dist/query-order.js +42 -0
  197. package/dist/query-order.js.map +1 -0
  198. package/dist/recipes.d.ts +3 -1
  199. package/dist/recipes.d.ts.map +1 -1
  200. package/dist/recipes.js +4 -4
  201. package/dist/recipes.js.map +1 -1
  202. package/dist/remote-backend.d.ts +114 -22
  203. package/dist/remote-backend.d.ts.map +1 -1
  204. package/dist/remote-backend.js +285 -44
  205. package/dist/remote-backend.js.map +1 -1
  206. package/dist/remote-document-codec.d.ts +15 -0
  207. package/dist/remote-document-codec.d.ts.map +1 -0
  208. package/dist/remote-document-codec.js +103 -0
  209. package/dist/remote-document-codec.js.map +1 -0
  210. package/dist/remote-error.d.ts +38 -0
  211. package/dist/remote-error.d.ts.map +1 -0
  212. package/dist/remote-error.js +59 -0
  213. package/dist/remote-error.js.map +1 -0
  214. package/dist/remote-operations.d.ts +63 -0
  215. package/dist/remote-operations.d.ts.map +1 -0
  216. package/dist/remote-operations.js +125 -0
  217. package/dist/remote-operations.js.map +1 -0
  218. package/dist/remote-parsers.d.ts +86 -0
  219. package/dist/remote-parsers.d.ts.map +1 -0
  220. package/dist/remote-parsers.js +181 -0
  221. package/dist/remote-parsers.js.map +1 -0
  222. package/dist/remote.d.ts +7 -2
  223. package/dist/remote.d.ts.map +1 -1
  224. package/dist/remote.js +6 -1
  225. package/dist/remote.js.map +1 -1
  226. package/dist/sha256.d.ts +21 -0
  227. package/dist/sha256.d.ts.map +1 -0
  228. package/dist/sha256.js +114 -0
  229. package/dist/sha256.js.map +1 -0
  230. package/dist/storage.d.ts +8 -2
  231. package/dist/storage.d.ts.map +1 -1
  232. package/dist/storage.js +11 -2
  233. package/dist/storage.js.map +1 -1
  234. package/dist/types.d.ts +40 -5
  235. package/dist/types.d.ts.map +1 -1
  236. package/dist/uncertain-write.d.ts +178 -0
  237. package/dist/uncertain-write.d.ts.map +1 -0
  238. package/dist/uncertain-write.js +198 -0
  239. package/dist/uncertain-write.js.map +1 -0
  240. package/dist/version-transport.d.ts +7 -0
  241. package/dist/version-transport.d.ts.map +1 -1
  242. package/dist/version-transport.js +9 -0
  243. package/dist/version-transport.js.map +1 -1
  244. package/dist/versioning.d.ts +18 -7
  245. package/dist/versioning.d.ts.map +1 -1
  246. package/dist/versioning.js +23 -14
  247. package/dist/versioning.js.map +1 -1
  248. package/package.json +75 -4
@@ -0,0 +1,396 @@
1
+ /**
2
+ * The hosted answer grammar, once: how every identified-write answer, every outcome-lookup
3
+ * answer and every read-route answer is classified, whichever client sent the request. The
4
+ * browser editor's body delivery and the CLI's whole-document sync read these same tables, so
5
+ * "recorded", "unknown" and "absent past retention" mean one thing in both.
6
+ *
7
+ * The update rows are hosted's browser table plus the sync quota rows (`request_capacity`),
8
+ * which only the `/sync/v1` routes answer. Until the hosted browser imports this module, hosted's golden exchanges
9
+ * (`test/fixtures/hosted-transport/`, produced from the hosted encoders) pin that these rows
10
+ * classify exactly what the host emits.
11
+ *
12
+ * The rows keep three facts apart: a refusal the host recorded under the request identity is
13
+ * definitive; a refusal answered before dispatch is definitive but unrecorded; and anything the
14
+ * host may have applied without saying so is unknown. Only two refusal codes reach the shared
15
+ * primitive's authorization set and pause the store: `AUTH_REQUIRED` (the carrier denied the
16
+ * request) and `PERMISSION_DENIED` (the host refused the caller's access to the bundle).
17
+ */
18
+ import { isContentVersion } from "../version-transport.js";
19
+ import { stripHostText } from "../host-text.js";
20
+ /**
21
+ * The refusal codes of a sync quota the host enforces on identified writes (`request_capacity`),
22
+ * one per scope it names: the person's rolling daily bound in this bundle, or the bundle's own
23
+ * bound. The shared primitive counts both as pausing refusals, so the store pauses with nothing
24
+ * lost and `resume` requeues the refused intents once the quota resets.
25
+ */
26
+ export const CAPACITY_REFUSAL_CODES = Object.freeze({ principal: "REQUEST_CAPACITY_PRINCIPAL", bundle: "REQUEST_CAPACITY_BUNDLE" });
27
+ /**
28
+ * The refusal code of the host's mass-delete hold (`428 deletions_held`): a delete that would take
29
+ * over half of the bundle's documents within 24 hours, counted over every person and checkout. It
30
+ * never pauses: only a person's typed acknowledgment releases it, never time or a plain resend.
31
+ */
32
+ export const DELETIONS_HELD_REFUSAL_CODE = "DELETIONS_HELD";
33
+ /** The quota scope a refused outcome names, or `null` when it is not a capacity refusal. */
34
+ export function capacityScopeOf(outcome) {
35
+ if (outcome.kind !== "refused")
36
+ return null;
37
+ if (outcome.code === CAPACITY_REFUSAL_CODES.principal)
38
+ return "principal";
39
+ if (outcome.code === CAPACITY_REFUSAL_CODES.bundle)
40
+ return "bundle";
41
+ return null;
42
+ }
43
+ export const UPDATE_ANSWER_ROWS = Object.freeze([
44
+ { answer: "200 ok", recorded: "yes", outcome: "committed" },
45
+ { answer: "200 version_conflict", recorded: "yes", outcome: "conflict" },
46
+ { answer: "200 document_not_found", recorded: "yes", outcome: "conflict" },
47
+ { answer: "200 validation_failed", recorded: "yes", outcome: "refused" },
48
+ { answer: "200 body_edit_mismatch", recorded: "yes", outcome: "refused" },
49
+ { answer: "200 invalid_input", recorded: "settled-only", outcome: "refused" },
50
+ { answer: "200 insufficient_scope", recorded: "no", outcome: "refused", code: "PERMISSION_DENIED" },
51
+ { answer: "200 bundle_not_found", recorded: "no", outcome: "refused", code: "PERMISSION_DENIED" },
52
+ { answer: "200 access_denied", recorded: "no", outcome: "refused", code: "PERMISSION_DENIED" },
53
+ { answer: "200 backend_unavailable", recorded: "settled-only", outcome: "refused" },
54
+ { answer: "200 concurrent_change", recorded: "settled-only", outcome: "refused" },
55
+ { answer: "200 internal_error", recorded: "settled-only", outcome: "refused" },
56
+ { answer: "200 deadline_exceeded", recorded: "settled-only", outcome: "refused" },
57
+ { answer: "200 cancelled", recorded: "settled-only", outcome: "refused" },
58
+ // The remaining not_applied codes of the write schema: definitive once recorded, like the transient ones.
59
+ { answer: "200 result_too_large", recorded: "settled-only", outcome: "refused" },
60
+ { answer: "200 field_action_refused", recorded: "settled-only", outcome: "refused" },
61
+ // A model change the host's compatibility check refused (designs/hosted-model-evolution.md 4.6).
62
+ { answer: "200 definition_incompatible", recorded: "settled-only", outcome: "refused" },
63
+ { answer: "200 document_exists", recorded: "settled-only", outcome: "refused" },
64
+ { answer: "200 candidate_unavailable", recorded: "settled-only", outcome: "refused" },
65
+ { answer: "200 candidate_recovery_unavailable", recorded: "settled-only", outcome: "refused" },
66
+ // A create whose id is not canonical, or folds onto a stored document's id (hosted kernel,
67
+ // tasks/canonical-document-ids-across-surfaces): definitive, like the rows above.
68
+ { answer: "200 document_id_not_canonical", recorded: "settled-only", outcome: "refused" },
69
+ { answer: "200 document_id_collision", recorded: "settled-only", outcome: "refused" },
70
+ // The sync quota, refused before dispatch; the row's outcome code is chosen by the scope the answer names.
71
+ { answer: "200 request_capacity", recorded: "no", outcome: "refused" },
72
+ { answer: "429 request_capacity", recorded: "no", outcome: "refused" },
73
+ // The mass-delete hold, refused before dispatch on a delete; not pausing (see DELETIONS_HELD_REFUSAL_CODE).
74
+ { answer: "428 deletions_held", recorded: "no", outcome: "refused" },
75
+ { answer: "200 write_outcome_unknown", recorded: "maybe", outcome: "unknown" },
76
+ { answer: "200 other", recorded: "unknown", outcome: "unknown" },
77
+ { answer: "400", recorded: "no", outcome: "unknown" },
78
+ { answer: "401 not_applied", recorded: "no", outcome: "refused", code: "AUTH_REQUIRED" },
79
+ { answer: "401 write_outcome_unknown", recorded: "maybe", outcome: "unknown" },
80
+ { answer: "401 other", recorded: "unknown", outcome: "refused", code: "AUTH_REQUIRED" },
81
+ { answer: "403", recorded: "no", outcome: "refused", code: "AUTH_REQUIRED" },
82
+ { answer: "503", recorded: "maybe", outcome: "unknown" },
83
+ { answer: "other status", recorded: "unknown", outcome: "unknown" },
84
+ { answer: "not sent", recorded: "no", outcome: "refused", code: "AUTH_REQUIRED" },
85
+ { answer: "carrier", recorded: "maybe", outcome: "unknown" },
86
+ ]);
87
+ export const OUTCOME_ANSWER_ROWS = Object.freeze([
88
+ { answer: "200 absent", result: "null" },
89
+ { answer: "200 absent past retention", result: "unknown" },
90
+ { answer: "200 pending", result: "null" },
91
+ { answer: "200 committed", result: "committed" },
92
+ { answer: "200 refused", result: "recorded" },
93
+ { answer: "200 committed contradiction", result: "throws" },
94
+ { answer: "400", result: "throws" },
95
+ { answer: "401", result: "throws" },
96
+ { answer: "403", result: "throws" },
97
+ { answer: "503", result: "throws" },
98
+ { answer: "malformed", result: "throws" },
99
+ { answer: "carrier", result: "throws" },
100
+ ]);
101
+ export const READ_ANSWER_ROWS = Object.freeze([
102
+ { answer: "capabilities 200", result: "admitted" },
103
+ { answer: "heads 200", result: "admitted" },
104
+ { answer: "heads 304", result: "not-modified" },
105
+ { answer: "heads 200 page", result: "admitted" },
106
+ { answer: "snapshot 200 complete", result: "admitted" },
107
+ { answer: "snapshot 200 page", result: "admitted" },
108
+ { answer: "snapshot 200 truncated", result: "truncated" },
109
+ { answer: "refusal 409 concurrent_change", result: "restart" },
110
+ { answer: "refusal 400 invalid_input", result: "authority" },
111
+ { answer: "refusal 401 unauthenticated", result: "authority" },
112
+ { answer: "refusal 404 bundle_not_found", result: "authority" },
113
+ { answer: "refusal 422 result_too_large", result: "authority" },
114
+ { answer: "refusal 422 validation_failed", result: "authority" },
115
+ { answer: "refusal 503 backend_unavailable", result: "offline" },
116
+ ]);
117
+ // ── the operation result envelope ──────────────────────────────────────────────────────────
118
+ /** The codes a write refusal may carry: the hosted write schema's closed set. */
119
+ export const WRITE_ERROR_CODES = Object.freeze([
120
+ "field_action_refused",
121
+ "invalid_input",
122
+ "insufficient_scope",
123
+ "bundle_not_found",
124
+ "backend_unavailable",
125
+ "document_not_found",
126
+ "document_exists",
127
+ "version_conflict",
128
+ "body_edit_mismatch",
129
+ "validation_failed",
130
+ "result_too_large",
131
+ "cancelled",
132
+ "deadline_exceeded",
133
+ "concurrent_change",
134
+ "write_outcome_unknown",
135
+ "internal_error",
136
+ "candidate_unavailable",
137
+ "candidate_recovery_unavailable",
138
+ "document_id_not_canonical",
139
+ "document_id_collision",
140
+ "request_capacity",
141
+ "deletions_held",
142
+ "definition_incompatible",
143
+ ]);
144
+ /** The whole-document delete: its success names the tombstone as `version`, and the version that left. */
145
+ export const DELETE_OPERATION_ID = "documents.delete.v1";
146
+ /** At most this many documents are named per finding in {@link definitionFindingsText}; the count says the rest. */
147
+ const FINDING_IDS_SHOWN = 5;
148
+ /** The bound on the findings text: the refusal message is journaled, so it stays small. */
149
+ export const DEFINITION_FINDINGS_TEXT_BYTES = 2048;
150
+ /** One part of a finding as text to show: host text, stripped of control and format characters; absent when not short text. */
151
+ const findingText = (value) => {
152
+ if (typeof value !== "string" || value.length > 256)
153
+ return undefined;
154
+ const text = stripHostText(value, 256);
155
+ return text.length > 0 ? text : undefined;
156
+ };
157
+ /**
158
+ * A model-change refusal's findings (`definitionDetails`) as text a person reads: one clause per
159
+ * finding, naming the rule, the Kind's type and field, the core code, and up to five documents
160
+ * with the full count, within {@link DEFINITION_FINDINGS_TEXT_BYTES}. Read leniently: a finding
161
+ * without a rule, or a part that is not short text, is left out; anything else the host sends is
162
+ * ignored. Empty when nothing is readable. The findings carry no values, bodies or authors, so
163
+ * neither does this.
164
+ */
165
+ export function definitionFindingsText(details) {
166
+ const findings = isRecord(details) && Array.isArray(details.findings) ? details.findings : [];
167
+ const clauses = [];
168
+ for (const finding of findings) {
169
+ if (!isRecord(finding))
170
+ continue;
171
+ const rule = findingText(finding.rule);
172
+ if (!rule)
173
+ continue;
174
+ const type = findingText(finding.type);
175
+ const conventionId = findingText(finding.conventionId);
176
+ const field = findingText(finding.field);
177
+ const detail = findingText(finding.detail);
178
+ const where = [type ? `Kind '${type}'` : conventionId ? `'${conventionId}'` : "", field ? `field '${field}'` : ""].filter(Boolean).join(" ");
179
+ const instances = isRecord(finding.instances) ? finding.instances : undefined;
180
+ const total = instances && Number.isSafeInteger(instances.count) && instances.count > 0 ? instances.count : 0;
181
+ const ids = instances && Array.isArray(instances.ids) ? instances.ids.map(findingText).filter((id) => id !== undefined) : [];
182
+ const shown = ids.slice(0, FINDING_IDS_SHOWN);
183
+ const documents = total > 0 ? `: ${total} document${total === 1 ? "" : "s"}${shown.length > 0 ? `, ${shown.join(", ")}${total > shown.length ? ", ..." : ""}` : ""}` : "";
184
+ clauses.push(`${rule}${where ? ` on ${where}` : ""}${detail ? ` (${detail})` : ""}${documents}`);
185
+ }
186
+ const more = isRecord(details) && details.truncated === true;
187
+ let text = "";
188
+ for (const [index, clause] of clauses.entries()) {
189
+ const next = text === "" ? clause : `${text}; ${clause}`;
190
+ const rest = clauses.length - index;
191
+ if (new TextEncoder().encode(next).byteLength > DEFINITION_FINDINGS_TEXT_BYTES - 32) {
192
+ // One clause alone can pass the bound (every part at the host's 256): it is cut, not dropped.
193
+ return text === "" ? `${clause.slice(0, 512)}...${rest > 1 ? `; and ${rest - 1} more` : ""}` : `${text}; and ${rest} more`;
194
+ }
195
+ text = next;
196
+ }
197
+ return more && text !== "" ? `${text}; and more` : text;
198
+ }
199
+ export class HostedAnswerError extends Error {
200
+ name = "HostedAnswerError";
201
+ }
202
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
203
+ const onlyKeys = (value, allowed) => Object.keys(value).every((key) => allowed.includes(key));
204
+ const DATA_KEYS = ["bundleId", "documentId", "version", "changed", "scope"];
205
+ const DELETE_DATA_KEYS = [...DATA_KEYS, "deletedVersion", "deleted"];
206
+ const ERROR_KEYS = ["code", "message", "retryable", "writeState", "currentVersion", "diagnostics", "fieldActionDetails", "definitionDetails", "candidate", "retentionUnavailable", "scope", "resetAt", "deletions", "baseline"];
207
+ const count = (value) => Number.isSafeInteger(value) && value >= 1;
208
+ /**
209
+ * A write operation's result envelope, admitted or refused as one: the operation it answers,
210
+ * the document it names, and a success with a content version or a refusal with a known code
211
+ * and write state. A refusal's detail blocks (diagnostics, corrective details) are carried but
212
+ * not interpreted here. `write_outcome_unknown` must say its write state is unknown.
213
+ */
214
+ export function parseWriteResult(raw, expected) {
215
+ const refuse = () => new HostedAnswerError("the write result envelope is not one the client admits");
216
+ if (!isRecord(raw) || !onlyKeys(raw, ["ok", "operationId", "data", "error"]) || typeof raw.operationId !== "string" || !expected.operationIds.includes(raw.operationId))
217
+ throw refuse();
218
+ const { operationId } = raw;
219
+ if (raw.ok === true) {
220
+ const data = raw.data;
221
+ // A delete's success, and only a delete's, names the version that left and says it left.
222
+ const deletion = operationId === DELETE_OPERATION_ID;
223
+ if (raw.error !== undefined || !isRecord(data) || !onlyKeys(data, deletion ? DELETE_DATA_KEYS : DATA_KEYS) || typeof data.bundleId !== "string" || data.bundleId.length === 0 ||
224
+ data.documentId !== expected.documentId || (expected.bundleId !== undefined && data.bundleId !== expected.bundleId) ||
225
+ !isContentVersion(data.version) || typeof data.changed !== "boolean" ||
226
+ (deletion && (!isContentVersion(data.deletedVersion) || data.deleted !== true)))
227
+ throw refuse();
228
+ const accepted = data;
229
+ return { ok: true, operationId, data: { ...accepted } };
230
+ }
231
+ if (raw.ok !== false)
232
+ throw refuse();
233
+ const error = raw.error;
234
+ if (raw.data !== undefined || !isRecord(error) || !onlyKeys(error, ERROR_KEYS) || !WRITE_ERROR_CODES.includes(error.code) ||
235
+ typeof error.message !== "string" || error.retryable !== false || (error.writeState !== "not_applied" && error.writeState !== "unknown") ||
236
+ (error.currentVersion !== undefined && !isContentVersion(error.currentVersion)) ||
237
+ (error.code === "write_outcome_unknown" && error.writeState !== "unknown") ||
238
+ (error.code === "request_capacity"
239
+ ? (error.scope !== "principal" && error.scope !== "bundle") || error.writeState !== "not_applied" || (error.resetAt !== undefined && (typeof error.resetAt !== "string" || !Number.isFinite(Date.parse(error.resetAt))))
240
+ : error.scope !== undefined || error.resetAt !== undefined) ||
241
+ (error.code === "deletions_held"
242
+ ? operationId !== DELETE_OPERATION_ID || error.writeState !== "not_applied" || !count(error.deletions) || !count(error.baseline)
243
+ : error.deletions !== undefined || error.baseline !== undefined) ||
244
+ // A model-change refusal says nothing was applied; its findings ride on it alone.
245
+ (error.code === "definition_incompatible" && error.writeState !== "not_applied") ||
246
+ (error.definitionDetails !== undefined && error.code !== "definition_incompatible"))
247
+ throw refuse();
248
+ return { ok: false, operationId, error: { ...error } };
249
+ }
250
+ // ── classifying an identified-write answer ─────────────────────────────────────────────────
251
+ /** The refusals answered before dispatch, by status: the sync quota, and the mass-delete hold. */
252
+ const BEFORE_DISPATCH = new Map([
253
+ [429, { code: "request_capacity", lenient: true }],
254
+ [428, { code: "deletions_held", lenient: false }],
255
+ ]);
256
+ const rowsByAnswer = new Map(UPDATE_ANSWER_ROWS.map((row) => [row.answer, row]));
257
+ /** The row named `answer`; every name this module uses is in the table. */
258
+ export function updateRow(answer) {
259
+ const row = rowsByAnswer.get(answer);
260
+ if (!row)
261
+ throw new RangeError(`no update answer row '${answer}'`);
262
+ return row;
263
+ }
264
+ /** The row an identified-write answer falls under, and the validated envelope when it carries one. */
265
+ export function classifyWriteAnswer(answer, expected) {
266
+ const { status, body } = answer;
267
+ if (status === 200) {
268
+ // The legacy denial is outside the canonical result schema, so it is read before it.
269
+ const legacy = body;
270
+ if (legacy?.ok === false && legacy.error?.code === "access_denied")
271
+ return { row: updateRow("200 access_denied") };
272
+ let result;
273
+ try {
274
+ result = parseWriteResult(body, expected);
275
+ }
276
+ catch {
277
+ return { row: updateRow("200 other") };
278
+ }
279
+ if (result.ok)
280
+ return { row: updateRow("200 ok"), result };
281
+ return { row: rowsByAnswer.get(`200 ${result.error.code}`) ?? updateRow("200 other"), result };
282
+ }
283
+ if (status === 400)
284
+ return { row: updateRow("400") };
285
+ if (status === 401) {
286
+ const error = body?.error;
287
+ if (error?.writeState === "not_applied")
288
+ return { row: updateRow("401 not_applied") };
289
+ if (error?.code === "write_outcome_unknown")
290
+ return { row: updateRow("401 write_outcome_unknown") };
291
+ return { row: updateRow("401 other") };
292
+ }
293
+ if (status === 403)
294
+ return { row: updateRow("403") };
295
+ // The refusals the host answers before dispatch, each with its own status and code. The
296
+ // capacity refusal is read leniently (its early hosts left fields out); the mass-delete hold is
297
+ // parsed exactly as the host sends it, so a 428 that does not say it applied nothing is not one.
298
+ const beforeDispatch = BEFORE_DISPATCH.get(status);
299
+ if (beforeDispatch) {
300
+ const error = body?.error;
301
+ if (!isRecord(error) || error.code !== beforeDispatch.code)
302
+ return { row: updateRow("other status") };
303
+ try {
304
+ const sent = beforeDispatch.lenient ? { retryable: false, writeState: "not_applied", message: "", ...error } : error;
305
+ return { row: updateRow(`${status} ${beforeDispatch.code}`), result: parseWriteResult({ ok: false, operationId: expected.operationIds[0], error: sent }, expected) };
306
+ }
307
+ catch {
308
+ return { row: updateRow("other status") };
309
+ }
310
+ }
311
+ if (status === 503)
312
+ return { row: updateRow("503") };
313
+ return { row: updateRow("other status") };
314
+ }
315
+ // ── the outcome lookup answer ──────────────────────────────────────────────────────────────
316
+ /** Why an outcome lookup could not produce evidence; the primitive counts it as a failed lookup. */
317
+ export class HostedOutcomeError extends Error {
318
+ name = "HostedOutcomeError";
319
+ reason;
320
+ status;
321
+ code;
322
+ constructor(reason, status, code) {
323
+ super(status === undefined ? reason : `${reason}: ${status}${code ? ` ${code}` : ""}`);
324
+ this.reason = reason;
325
+ this.status = status;
326
+ this.code = code;
327
+ }
328
+ }
329
+ /** An outcome answer carries the committed document's exact bytes under this bound. */
330
+ export const OUTCOME_CONTENT_BYTES = 1024 * 1024;
331
+ /** The bytes a canonical base64 string encodes, refused when it is not one or exceeds `maximum`. */
332
+ function decodeBase64(text, maximum) {
333
+ if (text.length > 4 * Math.ceil(maximum / 3) || text.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(text))
334
+ throw new HostedOutcomeError("malformed");
335
+ const binary = atob(text);
336
+ if (binary.length > maximum)
337
+ throw new HostedOutcomeError("malformed");
338
+ const bytes = new Uint8Array(binary.length);
339
+ for (let index = 0; index < binary.length; index++)
340
+ bytes[index] = binary.charCodeAt(index);
341
+ return bytes;
342
+ }
343
+ /**
344
+ * The lookup route's `200` answer, admitted or refused as one: `schemaVersion` 1, the request
345
+ * identity and binding it answers for, and one status. A committed answer carries the original
346
+ * validated success and the committed document's exact bytes as base64 at the receipt's
347
+ * version (a delete's carries none: a tombstone has no bytes); a refused answer carries the
348
+ * original definitive failure. Anything else, including a
349
+ * stored result whose write state is not definitive, is malformed evidence.
350
+ */
351
+ export function decodeOutcomeAnswer(value, expected) {
352
+ const malformed = () => new HostedOutcomeError("malformed");
353
+ if (!isRecord(value))
354
+ throw malformed();
355
+ const body = value;
356
+ if (body.schemaVersion !== 1 || body.requestId !== expected.requestId || body.binding !== expected.binding)
357
+ throw malformed();
358
+ const result = () => {
359
+ try {
360
+ return parseWriteResult(body.result, { operationIds: expected.operationIds, documentId: expected.documentId, bundleId: expected.bundleId });
361
+ }
362
+ catch {
363
+ throw malformed();
364
+ }
365
+ };
366
+ const observation = body.status;
367
+ if (observation === "absent" || observation === "pending") {
368
+ if (body.result !== undefined || body.content !== undefined)
369
+ throw malformed();
370
+ return { status: observation };
371
+ }
372
+ switch (observation) {
373
+ case "committed": {
374
+ const parsed = result();
375
+ // A committed delete carries the recorded result and no content: nothing it committed has bytes.
376
+ if (parsed.ok && parsed.operationId === DELETE_OPERATION_ID) {
377
+ if (body.content !== undefined)
378
+ throw malformed();
379
+ return { status: "committed", result: parsed, content: null };
380
+ }
381
+ const content = body.content;
382
+ if (!parsed.ok || !isRecord(content) || content.encoding !== "base64" || !isContentVersion(content.version) || typeof content.bytes !== "string")
383
+ throw malformed();
384
+ return { status: "committed", result: parsed, content: { version: content.version, bytes: decodeBase64(content.bytes, OUTCOME_CONTENT_BYTES) } };
385
+ }
386
+ case "refused": {
387
+ const parsed = result();
388
+ if (parsed.ok || parsed.error.writeState !== "not_applied" || body.content !== undefined)
389
+ throw malformed();
390
+ return { status: "refused", result: parsed };
391
+ }
392
+ default:
393
+ throw malformed();
394
+ }
395
+ }
396
+ //# sourceMappingURL=answer-rows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answer-rows.js","sourceRoot":"","sources":["../../src/hosted-transport/answer-rows.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAOhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,4BAA4B,EAAE,MAAM,EAAE,yBAAyB,EAAW,CAAC,CAAC;AAG7I;;;;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,CAAC;QACD;YACE,MAAM,SAAS,EAAE,CAAC;IACtB,CAAC;AACH,CAAC"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * The carrier seam: how a hosted request leaves and what comes back, with the credential kept on
3
+ * the carrier's side. The browser's carrier sends the session cookie and CSRF token; the CLI's
4
+ * sends a bearer token. Everything above the seam (the read adapter, the whole-document
5
+ * transport, the answer rows) is the same for both, so one answer grammar serves every client.
6
+ *
7
+ * A carrier reports two failures and never a third: `denied` says nothing left (the credential
8
+ * was already gone, so the request was never sent), and `unavailable` says the request may have
9
+ * left and its answer is unknown. It never reports "not applied" on its own.
10
+ */
11
+ /** A hosted answer as the route sent it: the status, the headers, and the bounded JSON body (undefined when there is none). */
12
+ export type HostedAnswer = {
13
+ status: number;
14
+ headers: Headers;
15
+ body: unknown;
16
+ };
17
+ /** A streamed answer: the body as a stream for a `2xx`, otherwise the bounded refusal envelope. */
18
+ export type HostedStream = {
19
+ status: number;
20
+ headers: Headers;
21
+ } & ({
22
+ ok: true;
23
+ body: ReadableStream<Uint8Array>;
24
+ } | {
25
+ ok: false;
26
+ body: unknown;
27
+ });
28
+ export interface HostedRequestOptions {
29
+ /** Largest answer body admitted, in bytes; a larger or undecodable body is `unavailable`. */
30
+ maximum: number;
31
+ /** The request identity of an identified write or its outcome lookup. */
32
+ writeRequest?: string;
33
+ /**
34
+ * The binding the request is pinned to: the browser's editor recovery target, or the CLI
35
+ * checkout's digest. The carrier decides which header carries it.
36
+ */
37
+ binding?: string;
38
+ /**
39
+ * The tombstone a create acknowledges it re-creates (`X-Superbee-Recreate`), on a create and
40
+ * on that create's outcome lookup only. It is part of the request identity on the host, so a
41
+ * lookup must carry exactly what the write carried.
42
+ */
43
+ recreate?: string;
44
+ /**
45
+ * The agent the client runs under, such as `claude-code` (`X-Superbee-Via`): the unverified
46
+ * `;via=` part of the host's agent label for this write. Attribution only, never authority, and
47
+ * not part of the request identity. Only the whole-document transport's write and outcome
48
+ * requests carry it, and only a token {@link isAgentLabelVia} admits is ever sent.
49
+ */
50
+ via?: string;
51
+ /**
52
+ * A person's typed acknowledgment of the host's mass-delete hold (`X-Superbee-Accept-Deletes`):
53
+ * the deletions they confirmed the bundle's 24-hour window may hold, from 1 to 100,000. Sent on
54
+ * a delete only, and never without that confirmation. Admission only, not part of the request
55
+ * identity.
56
+ */
57
+ acceptDeletes?: number;
58
+ }
59
+ /** The header that carries {@link HostedRequestOptions.acceptDeletes}. */
60
+ export declare const ACCEPT_DELETES_HEADER = "X-Superbee-Accept-Deletes";
61
+ /** The largest acknowledgment the host admits. */
62
+ export declare const MAXIMUM_ACCEPTED_DELETIONS = 100000;
63
+ /** Whether `value` is an acknowledgment count the host admits: an integer from 1 to 100,000. */
64
+ export declare function isAcceptedDeletionCount(value: unknown): value is number;
65
+ /** The header that carries {@link HostedRequestOptions.recreate}. */
66
+ export declare const RECREATE_HEADER = "X-Superbee-Recreate";
67
+ /** The header that carries {@link HostedRequestOptions.via}. */
68
+ export declare const VIA_HEADER = "X-Superbee-Via";
69
+ /**
70
+ * Whether `value` is a `via` token the host admits: 1 to 32 characters of `[a-z0-9._-]`, never
71
+ * starting with `superbee` (Superbee's own names). The same rule as the host's `isAgentLabelVia`;
72
+ * the `/sync/v1` golden exchanges (`create-200-ok-via`, `write-400-invalid-via`) pin the header
73
+ * and the host's refusal. A token the host refused would make every write a terminal 400.
74
+ */
75
+ export declare function isAgentLabelVia(value: unknown): value is string;
76
+ /**
77
+ * A raw-bytes request ({@link HostedCarrier.bytes}), such as one blob of a staged bundle creation
78
+ * (`bundle-create-blob`): the body travels as `application/octet-stream` with its exact
79
+ * `Content-Length`, and the route's own fields travel as headers.
80
+ */
81
+ export interface HostedBytesRequestOptions {
82
+ /** Largest answer body admitted, in bytes; a larger or undecodable body is `unavailable`. */
83
+ maximum: number;
84
+ /** The request identity of the identified write the bytes belong to. */
85
+ writeRequest?: string;
86
+ /**
87
+ * The route's own fields (`X-Superbee-Workspace`, say): `X-Superbee-` names only, and never a
88
+ * header the carrier owns (the request identity, the binding, `recreate`, `via`, the deletion
89
+ * acknowledgment) or a credential. Values are printable ASCII.
90
+ */
91
+ headers?: Readonly<Record<string, string>>;
92
+ }
93
+ export interface HostedCarrier {
94
+ json(path: string, input: unknown, signal: AbortSignal, options: HostedRequestOptions): Promise<HostedAnswer>;
95
+ stream(path: string, input: unknown, signal: AbortSignal): Promise<HostedStream>;
96
+ /**
97
+ * One `POST` whose body is `body` exactly, answered as {@link json} answers. Optional: a carrier
98
+ * without it (the browser's) cannot send raw bytes, and a caller that needs them says so.
99
+ */
100
+ bytes?(path: string, body: Uint8Array, signal: AbortSignal, options: HostedBytesRequestOptions): Promise<HostedAnswer>;
101
+ }
102
+ /**
103
+ * The cause a carrier's `unavailable` carries when the answer was larger than the request's
104
+ * `maximum`: the host answered, and the same request gets the same answer, so a reader may report
105
+ * it as a deterministic refusal rather than an outage. The carrier's code stays `unavailable`.
106
+ */
107
+ export declare class HostedAnswerTooLarge extends Error {
108
+ readonly name = "HostedAnswerTooLarge";
109
+ readonly maximum: number;
110
+ constructor(maximum: number);
111
+ }
112
+ /** True when `error` is a carrier failure because the answer exceeded its bound. */
113
+ export declare function isAnswerTooLarge(error: unknown): boolean;
114
+ export declare class HostedCarrierError extends Error {
115
+ readonly name = "HostedCarrierError";
116
+ readonly code: "denied" | "unavailable";
117
+ constructor(code: "denied" | "unavailable", options?: {
118
+ cause?: unknown;
119
+ });
120
+ }
121
+ export interface FetchCarrierOptions {
122
+ /** The host's origin, e.g. `https://superbee.example`; paths are resolved against it. */
123
+ baseUrl: string;
124
+ /**
125
+ * The credential headers for one request, such as `{ Authorization: "Bearer …" }`. A rejection
126
+ * means no credential is available: the request is not sent and the carrier reports `denied`.
127
+ */
128
+ credentials(signal: AbortSignal): Promise<Record<string, string>>;
129
+ /** The header that carries `binding`. Default `X-Superbee-Checkout`. */
130
+ bindingHeader?: string;
131
+ fetch?: typeof fetch;
132
+ /** Every request is answered within this many milliseconds; a stream restarts it at each chunk. Default 15 s. */
133
+ deadlineMs?: number;
134
+ }
135
+ /**
136
+ * A carrier over `fetch` with caller-supplied credential headers: the shape the CLI's bearer
137
+ * carrier takes. Requests are `POST` with a JSON body (or, through `bytes`, a raw one), never follow
138
+ * redirects, and are refused before sending when the identity, binding or a route header is
139
+ * malformed.
140
+ */
141
+ export declare function createFetchCarrier(options: FetchCarrierOptions): HostedCarrier;
142
+ //# sourceMappingURL=carrier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carrier.d.ts","sourceRoot":"","sources":["../../src/hosted-transport/carrier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,+HAA+H;AAC/H,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAE/E,mGAAmG;AACnG,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,CAAC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAElJ,MAAM,WAAW,oBAAoB;IACnC,6FAA6F;IAC7F,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,0EAA0E;AAC1E,eAAO,MAAM,qBAAqB,8BAA8B,CAAC;AAEjE,kDAAk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