@feltdb/core 0.8.3 → 0.8.5

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 (193) hide show
  1. package/dist/cli/commands.js +4 -1
  2. package/dist/cli/provisioning-neutrality.js +79 -0
  3. package/dist/collection.d.ts +43 -1
  4. package/dist/collection.d.ts.map +1 -1
  5. package/dist/collection.js +192 -22
  6. package/dist/create/create.js +25 -21
  7. package/dist/create/managed-account.js +11 -0
  8. package/dist/create/package-versions.js +1 -1
  9. package/dist/create/server-source/Cargo.lock +165 -0
  10. package/dist/create/server-source/Cargo.toml +9 -0
  11. package/dist/create/server-source/crates/feltdb/Cargo.toml +3 -0
  12. package/dist/create/server-source/crates/feltdb/benches/gate13_baseline.rs +44 -44
  13. package/dist/create/server-source/crates/feltdb/benches/gate13_phase_7_1_release_economics.rs +12 -24
  14. package/dist/create/server-source/crates/feltdb/benches/gate_13_redux.rs +7 -13
  15. package/dist/create/server-source/crates/feltdb/benches/gate_13_regression_runner.rs +13 -10
  16. package/dist/create/server-source/crates/feltdb/benches/gate_14a_concurrent_writer_scaling.rs +12 -9
  17. package/dist/create/server-source/crates/feltdb/benches/gate_14a_production_admission_revalidation.rs +78 -25
  18. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc2_admission_contract.rs +16 -13
  19. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc_root_cause.rs +13 -5
  20. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync1_queued_prototype.rs +41 -22
  21. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync_economics.rs +33 -15
  22. package/dist/create/server-source/crates/feltdb/benches/gate_14b_causal_backlog_scaling.rs +100 -33
  23. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_contract_test.rs +56 -20
  24. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_scaling.rs +116 -41
  25. package/dist/create/server-source/crates/feltdb/benches/gate_14d_combined_dimension_scaling.rs +186 -55
  26. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_2_optimization_benchmark.rs +64 -26
  27. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_3_crossover_analysis.rs +46 -15
  28. package/dist/create/server-source/crates/feltdb/src/admission.rs +8 -15
  29. package/dist/create/server-source/crates/feltdb/src/admission_contract_tests.rs +43 -13
  30. package/dist/create/server-source/crates/feltdb/src/adversarial_transport.rs +15 -42
  31. package/dist/create/server-source/crates/feltdb/src/analytics.rs +65 -19
  32. package/dist/create/server-source/crates/feltdb/src/application.rs +113 -30
  33. package/dist/create/server-source/crates/feltdb/src/authorization_security_tests.rs +475 -140
  34. package/dist/create/server-source/crates/feltdb/src/cardinality_diagnostics.rs +17 -15
  35. package/dist/create/server-source/crates/feltdb/src/cardinality_endpoint.rs +0 -1
  36. package/dist/create/server-source/crates/feltdb/src/causal_backlog_bound.rs +59 -15
  37. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier.rs +266 -114
  38. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier_phase_7_1.rs +25 -7
  39. package/dist/create/server-source/crates/feltdb/src/concurrency_fuzzing.rs +10 -15
  40. package/dist/create/server-source/crates/feltdb/src/consistency_contract.rs +3 -11
  41. package/dist/create/server-source/crates/feltdb/src/crash_atomic_boundary.rs +14 -5
  42. package/dist/create/server-source/crates/feltdb/src/crash_injection.rs +21 -25
  43. package/dist/create/server-source/crates/feltdb/src/crash_recovery_tests.rs +14 -11
  44. package/dist/create/server-source/crates/feltdb/src/dedup_bound_investigation.rs +103 -22
  45. package/dist/create/server-source/crates/feltdb/src/distributed_indexing.rs +18 -15
  46. package/dist/create/server-source/crates/feltdb/src/durability_guarantees.rs +12 -8
  47. package/dist/create/server-source/crates/feltdb/src/durable_dedup_set.rs +1 -5
  48. package/dist/create/server-source/crates/feltdb/src/durable_operation_identity.rs +87 -23
  49. package/dist/create/server-source/crates/feltdb/src/durable_operation_log.rs +3 -7
  50. package/dist/create/server-source/crates/feltdb/src/durable_sync.rs +10 -9
  51. package/dist/create/server-source/crates/feltdb/src/equality_index.rs +595 -0
  52. package/dist/create/server-source/crates/feltdb/src/in_process_transport.rs +1 -6
  53. package/dist/create/server-source/crates/feltdb/src/indexing.rs +35 -38
  54. package/dist/create/server-source/crates/feltdb/src/lib.rs +1050 -117
  55. package/dist/create/server-source/crates/feltdb/src/managed_cas_tests.rs +4 -1
  56. package/dist/create/server-source/crates/feltdb/src/metrics.rs +0 -1
  57. package/dist/create/server-source/crates/feltdb/src/multi_node_convergence.rs +1 -2
  58. package/dist/create/server-source/crates/feltdb/src/multi_operation_transaction.rs +107 -30
  59. package/dist/create/server-source/crates/feltdb/src/observability.rs +19 -6
  60. package/dist/create/server-source/crates/feltdb/src/operation_algebra.rs +12 -11
  61. package/dist/create/server-source/crates/feltdb/src/operation_log.rs +9 -4
  62. package/dist/create/server-source/crates/feltdb/src/p1_application_atomicity.rs +65 -18
  63. package/dist/create/server-source/crates/feltdb/src/p1_atomicity_acceptance.rs +193 -57
  64. package/dist/create/server-source/crates/feltdb/src/partition_reconciliation.rs +37 -27
  65. package/dist/create/server-source/crates/feltdb/src/permutation_scheduler.rs +38 -10
  66. package/dist/create/server-source/crates/feltdb/src/persistence_reality.rs +20 -14
  67. package/dist/create/server-source/crates/feltdb/src/phase1b_acceptance.rs +394 -229
  68. package/dist/create/server-source/crates/feltdb/src/phase1c1_acceptance.rs +8 -6
  69. package/dist/create/server-source/crates/feltdb/src/phase1c2_acceptance.rs +11 -13
  70. package/dist/create/server-source/crates/feltdb/src/phase1c3_acceptance.rs +90 -72
  71. package/dist/create/server-source/crates/feltdb/src/phase1c_atomicity_proof.rs +3 -3
  72. package/dist/create/server-source/crates/feltdb/src/phase5_integration.rs +33 -11
  73. package/dist/create/server-source/crates/feltdb/src/phase5_scenarios.rs +6 -6
  74. package/dist/create/server-source/crates/feltdb/src/phase6_adversarial_scenarios.rs +14 -56
  75. package/dist/create/server-source/crates/feltdb/src/phase6_convergence_validator.rs +29 -27
  76. package/dist/create/server-source/crates/feltdb/src/phase6_persistence.rs +35 -17
  77. package/dist/create/server-source/crates/feltdb/src/phase_1c_real_tcp.rs +8 -2
  78. package/dist/create/server-source/crates/feltdb/src/phase_2a_failures.rs +59 -15
  79. package/dist/create/server-source/crates/feltdb/src/phase_2b_network.rs +70 -17
  80. package/dist/create/server-source/crates/feltdb/src/phase_2c_cascading.rs +23 -6
  81. package/dist/create/server-source/crates/feltdb/src/phase_3_durability.rs +12 -3
  82. package/dist/create/server-source/crates/feltdb/src/phase_4_baseline.rs +41 -11
  83. package/dist/create/server-source/crates/feltdb/src/phase_5_soak.rs +56 -25
  84. package/dist/create/server-source/crates/feltdb/src/policy_evaluation.rs +701 -245
  85. package/dist/create/server-source/crates/feltdb/src/production_api.rs +31 -13
  86. package/dist/create/server-source/crates/feltdb/src/query_execution_diagnostics.rs +126 -0
  87. package/dist/create/server-source/crates/feltdb/src/query_performance.rs +6 -8
  88. package/dist/create/server-source/crates/feltdb/src/replay_fuzzing.rs +5 -5
  89. package/dist/create/server-source/crates/feltdb/src/replica_acknowledgements.rs +48 -18
  90. package/dist/create/server-source/crates/feltdb/src/replica_membership.rs +30 -11
  91. package/dist/create/server-source/crates/feltdb/src/replication_manager.rs +6 -3
  92. package/dist/create/server-source/crates/feltdb/src/replication_protocol.rs +4 -3
  93. package/dist/create/server-source/crates/feltdb/src/sharding.rs +36 -10
  94. package/dist/create/server-source/crates/feltdb/src/state_conflict_contract.rs +516 -0
  95. package/dist/create/server-source/crates/feltdb/src/state_contract.rs +305 -6
  96. package/dist/create/server-source/crates/feltdb/src/state_diff_contract.rs +222 -0
  97. package/dist/create/server-source/crates/feltdb/src/state_facade.rs +82 -54
  98. package/dist/create/server-source/crates/feltdb/src/state_hash.rs +2 -2
  99. package/dist/create/server-source/crates/feltdb/src/state_model.rs +1514 -537
  100. package/dist/create/server-source/crates/feltdb/src/state_transition_store.rs +6 -3
  101. package/dist/create/server-source/crates/feltdb/src/state_trigger.rs +672 -0
  102. package/dist/create/server-source/crates/feltdb/src/submission.rs +5 -11
  103. package/dist/create/server-source/crates/feltdb/src/sync.rs +12 -0
  104. package/dist/create/server-source/crates/feltdb/src/tcp_transport.rs +6 -8
  105. package/dist/create/server-source/crates/feltdb/src/transaction_api.rs +24 -35
  106. package/dist/create/server-source/crates/feltdb/src/transaction_invariants.rs +24 -8
  107. package/dist/create/server-source/crates/feltdb/src/transaction_preconditions.rs +248 -59
  108. package/dist/create/server-source/crates/feltdb/src/transactions.rs +17 -20
  109. package/dist/create/server-source/crates/feltdb/src/trigger_contract.rs +749 -0
  110. package/dist/create/server-source/crates/feltdb/src/worker_mesh.rs +1 -0
  111. package/dist/create/server-source/crates/feltdb/src/workload.rs +512 -4
  112. package/dist/create/server-source/crates/feltdb/src/workload_diagnostics.rs +442 -0
  113. package/dist/create/server-source/crates/feltdb/tests/branching_evidence.rs +299 -0
  114. package/dist/create/server-source/crates/feltdb/tests/current_revision_authority_evidence.rs +288 -0
  115. package/dist/create/server-source/crates/feltdb/tests/durable_format_compatibility.rs +392 -0
  116. package/dist/create/server-source/crates/feltdb/tests/feltdb_state_boundary_tests.rs +436 -220
  117. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_conflict_contract_corpus.json +1916 -0
  118. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_diff_contract_corpus.json +1878 -0
  119. package/dist/create/server-source/crates/feltdb/tests/fixtures/trigger_contract_corpus.json +1862 -0
  120. package/dist/create/server-source/crates/feltdb/tests/pr34_query_collection.rs +234 -0
  121. package/dist/create/server-source/crates/feltdb/tests/pr35_equality_index.rs +947 -0
  122. package/dist/create/server-source/crates/feltdb/tests/pr7_self_authorization_proof.rs +5 -8
  123. package/dist/create/server-source/crates/feltdb/tests/pr8_vocabulary_assessment.rs +52 -44
  124. package/dist/create/server-source/crates/feltdb/tests/pr9_phase2_boundary_tests.rs +33 -16
  125. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3a_path_a_tests.rs +22 -7
  126. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_authorized_mutations.rs +41 -22
  127. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_role_based_authorization.rs +25 -8
  128. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_simple_auth_delete.rs +9 -6
  129. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_team_delete_role_authorization.rs +120 -69
  130. package/dist/create/server-source/crates/feltdb/tests/pr9_teams_role_based_access.rs +21 -10
  131. package/dist/create/server-source/crates/feltdb/tests/production_readiness_contract.rs +1032 -0
  132. package/dist/create/server-source/crates/feltdb/tests/reconciliation_application.rs +868 -0
  133. package/dist/create/server-source/crates/feltdb/tests/reconciliation_wire_format_evidence.rs +221 -0
  134. package/dist/create/server-source/crates/feltdb/tests/resource_scoped_revisions.rs +338 -0
  135. package/dist/create/server-source/crates/feltdb/tests/revision_identity_contract.rs +1039 -0
  136. package/dist/create/server-source/crates/feltdb/tests/revision_model_decision.rs +739 -0
  137. package/dist/create/server-source/crates/feltdb/tests/revision_retention_boundary_evidence.rs +427 -0
  138. package/dist/create/server-source/crates/feltdb/tests/saas_authorization_integration.rs +3 -3
  139. package/dist/create/server-source/crates/feltdb/tests/saas_invitation_lifecycle.rs +25 -22
  140. package/dist/create/server-source/crates/feltdb/tests/state_conflict_contract_conformance.rs +1799 -0
  141. package/dist/create/server-source/crates/feltdb/tests/state_diff_contract_conformance.rs +1316 -0
  142. package/dist/create/server-source/crates/feltdb/tests/state_model_integration.rs +53 -61
  143. package/dist/create/server-source/crates/feltdb/tests/state_persistence_integration.rs +156 -61
  144. package/dist/create/server-source/crates/feltdb/tests/state_store_boundary_evidence.rs +299 -0
  145. package/dist/create/server-source/crates/feltdb/tests/sync_divergence_evidence.rs +255 -0
  146. package/dist/create/server-source/crates/feltdb/tests/three_way_input_boundary_evidence.rs +249 -0
  147. package/dist/create/server-source/crates/feltdb/tests/trigger_contract_conformance.rs +994 -0
  148. package/dist/create/server-source/crates/feltdb-server/src/app_state.rs +2 -1
  149. package/dist/create/server-source/crates/feltdb-server/src/audit.rs +1137 -29
  150. package/dist/create/server-source/crates/feltdb-server/src/auth.rs +164 -13
  151. package/dist/create/server-source/crates/feltdb-server/src/main.rs +800 -34
  152. package/dist/db.d.ts +33 -34
  153. package/dist/db.d.ts.map +1 -1
  154. package/dist/db.js +74 -20
  155. package/dist/deployment.d.ts +30 -0
  156. package/dist/deployment.d.ts.map +1 -0
  157. package/dist/deployment.js +130 -0
  158. package/dist/embedded-transaction.d.ts +22 -4
  159. package/dist/embedded-transaction.d.ts.map +1 -1
  160. package/dist/embedded-transaction.js +51 -5
  161. package/dist/feltdb.d.ts +14 -2
  162. package/dist/feltdb.d.ts.map +1 -1
  163. package/dist/file-db.js +1 -1
  164. package/dist/http-client.d.ts +14 -0
  165. package/dist/http-client.d.ts.map +1 -1
  166. package/dist/http-client.js +23 -5
  167. package/dist/http-db.d.ts +119 -1
  168. package/dist/http-db.d.ts.map +1 -1
  169. package/dist/http-db.js +346 -31
  170. package/dist/index-core.d.ts +2 -0
  171. package/dist/index-core.d.ts.map +1 -1
  172. package/dist/index-core.js +2 -0
  173. package/dist/index.d.ts.map +1 -1
  174. package/dist/index.js +9 -0
  175. package/dist/indexeddb-db.d.ts.map +1 -1
  176. package/dist/indexeddb-db.js +35 -21
  177. package/dist/managed-recovery.d.ts +192 -0
  178. package/dist/managed-recovery.d.ts.map +1 -0
  179. package/dist/managed-recovery.js +242 -0
  180. package/dist/memory-db.js +1 -1
  181. package/dist/studio-app/assets/{feltdb_wasm-DB8cX151.js → feltdb_wasm-DaNwCLRX.js} +1 -1
  182. package/dist/studio-app/assets/feltdb_wasm_bg-DnsHNv6g.wasm +0 -0
  183. package/dist/studio-app/assets/index-j8IlhNqJ.js +29 -0
  184. package/dist/studio-app/index.html +1 -1
  185. package/dist/transaction.d.ts +30 -0
  186. package/dist/transaction.d.ts.map +1 -1
  187. package/dist/transaction.js +41 -0
  188. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  189. package/dist/workload.d.ts +2 -1
  190. package/dist/workload.d.ts.map +1 -1
  191. package/package.json +1 -1
  192. package/dist/studio-app/assets/feltdb_wasm_bg-ClhDHp0S.wasm +0 -0
  193. package/dist/studio-app/assets/index-B0k4UAlI.js +0 -29
@@ -101,18 +101,19 @@ export class IndexedDbJsDb {
101
101
  async commit_transaction(request) {
102
102
  const db = await this.database;
103
103
  const before = this.sequence;
104
- // Structural problems no operations, the same record written twice, an
105
- // invalid name do not depend on stored state, so they are settled before
106
- // opening a transaction. Without this an empty transaction would open a
107
- // transaction that reads nothing and therefore never reaches a decision.
108
- // The IndexedDB path reads presence rather than values for the records a
109
- // transaction touches, so it cannot evaluate a value precondition. It
110
- // therefore leaves `read` undefined, and `decideTransaction` refuses a
111
- // transaction carrying preconditions rather than committing it
112
- // unconditionally an explicit refusal, not a silent one.
113
- const structural = decideTransaction(request, { exists: () => false, hasApplied: () => false });
114
- if (structural.kind === 'reject')
115
- throw new EmbeddedTransactionRejected(structural.reason);
104
+ // A transaction with no operations, or with no identity, would open an
105
+ // IndexedDB transaction that reads nothing and therefore never reaches a
106
+ // decision. Those two are settled first, before a transaction is opened.
107
+ //
108
+ // Nothing else is pre-decided here. Every other question this runtime has
109
+ // to answer -- does the record exist, what version does it hold -- is a
110
+ // question about stored state, and answering it outside the IndexedDB
111
+ // transaction would put another writer between the check and the write.
112
+ if (!request.transactionId?.trim() || request.operations.length === 0) {
113
+ const structural = decideTransaction(request, { exists: () => false, hasApplied: () => false });
114
+ if (structural.kind === 'reject')
115
+ throw new EmbeddedTransactionRejected(structural.reason, structural.failure);
116
+ }
116
117
  // Applied transaction ids live in their own store so identity survives a
117
118
  // page reload the same way records do.
118
119
  const alreadyApplied = await this.request('transactions', store => store.get(request.transactionId));
@@ -130,14 +131,28 @@ export class IndexedDbJsDb {
130
131
  const rows = transaction.objectStore('rows');
131
132
  const changes = transaction.objectStore('changes');
132
133
  const transactions = transaction.objectStore('transactions');
133
- // Read every touched record inside the transaction, so the precondition
134
+ // Read every record the transaction touches -- the ones it writes and
135
+ // the ones it only guards -- inside the transaction, so the precondition
134
136
  // check and the write cannot be separated by another writer.
135
- const present = new Map();
136
- let pending = request.operations.length;
137
+ //
138
+ // The values are read, not merely their presence. A `__version`, an
139
+ // authority epoch and a lease all live in the record body, so reading
140
+ // only the key would leave this runtime unable to evaluate the very
141
+ // predicates every other runtime evaluates, and `putIfAbsent` and
142
+ // `updateIfVersion` would mean something weaker in a browser than they
143
+ // mean anywhere else. `get` is no less atomic than `getKey` here: both
144
+ // are issued inside the same readwrite transaction.
145
+ const records = new Map();
146
+ const touched = [...new Set([
147
+ ...request.operations.map(operation => `${operation.collection}:${operation.id}`),
148
+ ...(request.preconditions ?? []).map(condition => `${condition.collection}:${condition.id}`),
149
+ ])];
150
+ let pending = touched.length;
137
151
  let decided = null;
138
152
  const finish = () => {
139
153
  const plan = decideTransaction(request, {
140
- exists: key => present.get(key) === true,
154
+ exists: key => records.get(key) !== undefined,
155
+ read: key => records.get(key),
141
156
  hasApplied: () => false,
142
157
  });
143
158
  decided = plan;
@@ -163,11 +178,10 @@ export class IndexedDbJsDb {
163
178
  }
164
179
  transactions.put({ transactionId: request.transactionId, committedAt: timestamp }, request.transactionId);
165
180
  };
166
- for (const operation of request.operations) {
167
- const key = `${operation.collection}:${operation.id}`;
168
- const lookup = rows.getKey(key);
181
+ for (const key of touched) {
182
+ const lookup = rows.get(key);
169
183
  lookup.onsuccess = () => {
170
- present.set(key, lookup.result !== undefined);
184
+ records.set(key, lookup.result);
171
185
  pending -= 1;
172
186
  if (pending === 0)
173
187
  finish();
@@ -190,7 +204,7 @@ export class IndexedDbJsDb {
190
204
  if (plan.kind === 'duplicate')
191
205
  return embeddedResult(request, true, before, this.sequence);
192
206
  if (plan.kind === 'reject')
193
- throw new EmbeddedTransactionRejected(plan.reason);
207
+ throw new EmbeddedTransactionRejected(plan.reason, plan.failure);
194
208
  this.sequence += plan.mutations.length;
195
209
  for (const mutation of plan.mutations)
196
210
  this.announceLocalChange(mutation.collection, this.sequence);
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Managed-client recovery primitives.
3
+ *
4
+ * These exist because of one production incident and one line of code:
5
+ *
6
+ * ```ts
7
+ * this.activeRevision ??= this.application_request('/application')
8
+ * .then(value => value.revision_id);
9
+ * ```
10
+ *
11
+ * `??=` caches whatever the expression produced — including a *rejected*
12
+ * promise. One transient timeout during canonical revision discovery therefore
13
+ * became permanent client state: every later operation awaited the same
14
+ * rejection, and the only recovery was to construct a new client. A long-lived
15
+ * `HttpJsDb` never recovered, however healthy the authority became.
16
+ *
17
+ * The distinction the fix rests on is between **sharing an in-flight
18
+ * operation** and **caching its outcome**. Those are different things, and
19
+ * conflating them is what turned a network blip into a poisoned client:
20
+ *
21
+ * ```text
22
+ * SUCCESS the value is cached, permanently
23
+ * IN-FLIGHT concurrent callers share one request
24
+ * FAILURE the in-flight state is cleared, the failure reaches every
25
+ * caller that was waiting, and the next caller starts fresh
26
+ * ```
27
+ *
28
+ * Nothing here retries anything on its own. A retry happens when the
29
+ * application performs another operation, which is deliberate: a client that
30
+ * retried revision discovery by itself would turn a permanently misconfigured
31
+ * application into a request storm against the authority.
32
+ */
33
+ /**
34
+ * Why an operation failed, in the only two categories a client can act on.
35
+ *
36
+ * `transient` means the request may succeed later without anything being
37
+ * fixed: a timeout, a reset connection, a 5xx, a 429. `permanent` means it
38
+ * will not: bad credentials, a missing grant, an application that is not
39
+ * configured the way the client thinks it is. The difference decides whether
40
+ * an automatic reconnect loop should keep trying or stop and wait for someone
41
+ * to change something.
42
+ */
43
+ export type FailureKind = 'transient' | 'permanent';
44
+ export type ManagedFailureClass = 'transient' | 'authentication' | 'authorization' | 'configuration' | 'closed';
45
+ /** A failure rendered for an operator, without swallowing the typed original. */
46
+ export interface ManagedFailure {
47
+ kind: FailureKind;
48
+ failure_class: ManagedFailureClass;
49
+ name: string;
50
+ message: string;
51
+ code?: string;
52
+ status?: number;
53
+ at: string;
54
+ }
55
+ /** Classify a failure without requiring applications to inspect messages. */
56
+ export declare function classifyFailureClass(error: unknown): ManagedFailureClass;
57
+ /**
58
+ * Classify a failure as transient or permanent.
59
+ *
60
+ * The default is `transient`, and deliberately so: misclassifying a transient
61
+ * failure as permanent reproduces the incident this module exists to fix,
62
+ * while misclassifying a permanent one as transient costs a retry the caller
63
+ * was going to make anyway. The asymmetry is the whole point.
64
+ */
65
+ export declare function classifyFailure(error: unknown): FailureKind;
66
+ /** Render a failure for the health surface without discarding the original. */
67
+ export declare function describeFailure(error: unknown): ManagedFailure;
68
+ /** What a client knows about a value it discovers once and then caches. */
69
+ export type DiscoveryState = 'cached' | 'loading' | 'unavailable';
70
+ export interface DiscoverySnapshot {
71
+ state: DiscoveryState;
72
+ consecutive_failures: number;
73
+ last_failure?: ManagedFailure;
74
+ last_success_at?: string;
75
+ }
76
+ /**
77
+ * A value discovered once, shared while in flight, and never cached when it
78
+ * fails.
79
+ *
80
+ * The three invariants, all of which the incident violated:
81
+ *
82
+ * 1. a successful value is cached and never re-fetched;
83
+ * 2. concurrent callers share one request rather than issuing N;
84
+ * 3. a failed request leaves **no** cached state, so the next caller starts a
85
+ * new request — and every caller that was waiting sees the same typed
86
+ * failure, not a different one each.
87
+ */
88
+ export declare class SingleFlightValue<T> {
89
+ private cached?;
90
+ private inFlight?;
91
+ private failures;
92
+ private lastFailure?;
93
+ private lastSuccessAt?;
94
+ /** The cached value, if discovery has ever succeeded. */
95
+ get value(): T | undefined;
96
+ get state(): DiscoveryState;
97
+ snapshot(): DiscoverySnapshot;
98
+ /**
99
+ * Return the value, discovering it with `load` if necessary.
100
+ *
101
+ * `load` runs at most once per in-flight window. It is passed in rather than
102
+ * held so that this type stays a state machine and nothing else: it knows
103
+ * how to share and how to forget, and nothing about HTTP.
104
+ */
105
+ get(load: () => Promise<T>): Promise<T>;
106
+ /**
107
+ * Adopt a value the caller already has, without a request.
108
+ *
109
+ * A revision supplied at construction is as good as one discovered, and the
110
+ * state should say `cached` rather than pretending nothing is known.
111
+ */
112
+ seed(value: T): void;
113
+ /** Forget everything, including a successful value. */
114
+ reset(): void;
115
+ }
116
+ export interface BackoffOptions {
117
+ /** The first delay's ceiling, in milliseconds. */
118
+ base?: number;
119
+ /** The largest ceiling any delay may have. */
120
+ max?: number;
121
+ /** How much the ceiling grows per consecutive failure. */
122
+ factor?: number;
123
+ /** Injected for tests; defaults to Math.random. */
124
+ random?: () => number;
125
+ }
126
+ /**
127
+ * Exponential backoff with a cap and jitter.
128
+ *
129
+ * The jitter is **partial**, not full: a delay is drawn uniformly from the
130
+ * upper half of its ceiling, `[ceiling / 2, ceiling)`. Full jitter — `[0,
131
+ * ceiling)` — would let the fifth consecutive failure sleep for less than the
132
+ * first, which makes "increasing after consecutive failures" untrue and
133
+ * untestable. Partial jitter keeps both properties: every delay is strictly
134
+ * larger than every delay possible at a lower failure count, and two clients
135
+ * failing together still separate, because they draw independently.
136
+ *
137
+ * The previous behaviour was a flat one-second retry, forever. That is
138
+ * neither bounded in aggregate nor jittered, so a managed service coming back
139
+ * after an outage was met by every client it had ever served, in lockstep.
140
+ */
141
+ export declare class BoundedBackoff {
142
+ private readonly base;
143
+ private readonly max;
144
+ private readonly factor;
145
+ private readonly random;
146
+ private consecutive;
147
+ constructor(options?: BackoffOptions);
148
+ /** How many consecutive failures have been recorded. */
149
+ get attempts(): number;
150
+ /** The ceiling this many consecutive failures in, capped. */
151
+ ceiling(attempt?: number): number;
152
+ /** Draw the next delay and count the failure that caused it. */
153
+ next(): number;
154
+ /** A connection that stayed up long enough to count returns us to base. */
155
+ reset(): void;
156
+ }
157
+ /**
158
+ * Sleep, unless the signal aborts first.
159
+ *
160
+ * Two properties matter and both were missing: the timer must not hold a Node
161
+ * process open on its own, and the abort listener must be removed when the
162
+ * timer fires normally. Without the second, a long-lived subscription
163
+ * accumulates one listener per reconnect attempt, which is a leak that only
164
+ * shows up on the clients that have been running longest.
165
+ */
166
+ export declare function cancellableDelay(ms: number, signal: AbortSignal): Promise<void>;
167
+ /** Where the event-stream connection currently is. */
168
+ export type ConnectionState = 'closed' | 'connecting' | 'connected' | 'backoff' | 'failed';
169
+ /** Overall authority usability, independent of event-stream lifecycle. */
170
+ export type AuthorityAvailabilityState = 'unknown' | 'available' | 'recovering' | 'degraded' | 'closed';
171
+ /**
172
+ * Enough structured state to answer one question: is this client connected,
173
+ * recovering, or poisoned?
174
+ *
175
+ * Deliberately not a monitoring framework. It is the operational surface that
176
+ * sits beside — never instead of — the typed error the caller already gets:
177
+ * an application handles `FeltDBServiceError`, an operator reads this.
178
+ */
179
+ export interface ManagedClientHealth {
180
+ connection_state: ConnectionState;
181
+ availability_state: AuthorityAvailabilityState;
182
+ usable: boolean;
183
+ recovery_possible: boolean;
184
+ revision_state: DiscoveryState;
185
+ revision_id?: string;
186
+ consecutive_failures: number;
187
+ last_success_at?: string;
188
+ last_error?: ManagedFailure;
189
+ next_retry_at?: string;
190
+ next_retry_in_ms?: number;
191
+ }
192
+ //# sourceMappingURL=managed-recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managed-recovery.d.ts","sourceRoot":"","sources":["../src/managed-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAQH;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAEpD,MAAM,MAAM,mBAAmB,GAC3B,WAAW,GACX,gBAAgB,GAChB,eAAe,GACf,eAAe,GACf,QAAQ,CAAC;AAEb,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,aAAa,EAAE,mBAAmB,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAQD,6EAA6E;AAC7E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,CAYxE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAE3D;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAY9D;AAMD,2EAA2E;AAC3E,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,SAAS,GAAG,aAAa,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,cAAc,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,YAAY,CAAC,EAAE,cAAc,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,iBAAiB,CAAC,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAC,CAAI;IACnB,OAAO,CAAC,QAAQ,CAAC,CAAa;IAC9B,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,WAAW,CAAC,CAAiB;IACrC,OAAO,CAAC,aAAa,CAAC,CAAS;IAE/B,yDAAyD;IACzD,IAAI,KAAK,IAAI,CAAC,GAAG,SAAS,CAEzB;IAED,IAAI,KAAK,IAAI,cAAc,CAI1B;IAED,QAAQ,IAAI,iBAAiB;IAS7B;;;;;;OAMG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAgCvC;;;;;OAKG;IACH,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAOpB,uDAAuD;IACvD,KAAK,IAAI,IAAI;CAMd;AAMD,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8CAA8C;IAC9C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,WAAW,CAAK;gBAEZ,OAAO,GAAE,cAAmB;IAOxC,wDAAwD;IACxD,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,6DAA6D;IAC7D,OAAO,CAAC,OAAO,SAAmB,GAAG,MAAM;IAI3C,gEAAgE;IAChE,IAAI,IAAI,MAAM;IAOd,2EAA2E;IAC3E,KAAK,IAAI,IAAI;CAGd;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAY/E;AAMD,sDAAsD;AACtD,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE3F,0EAA0E;AAC1E,MAAM,MAAM,0BAA0B,GAAG,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,UAAU,GAAG,QAAQ,CAAC;AAExG;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,eAAe,CAAC;IAClC,kBAAkB,EAAE,0BAA0B,CAAC;IAC/C,MAAM,EAAE,OAAO,CAAC;IAChB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B"}
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Managed-client recovery primitives.
3
+ *
4
+ * These exist because of one production incident and one line of code:
5
+ *
6
+ * ```ts
7
+ * this.activeRevision ??= this.application_request('/application')
8
+ * .then(value => value.revision_id);
9
+ * ```
10
+ *
11
+ * `??=` caches whatever the expression produced — including a *rejected*
12
+ * promise. One transient timeout during canonical revision discovery therefore
13
+ * became permanent client state: every later operation awaited the same
14
+ * rejection, and the only recovery was to construct a new client. A long-lived
15
+ * `HttpJsDb` never recovered, however healthy the authority became.
16
+ *
17
+ * The distinction the fix rests on is between **sharing an in-flight
18
+ * operation** and **caching its outcome**. Those are different things, and
19
+ * conflating them is what turned a network blip into a poisoned client:
20
+ *
21
+ * ```text
22
+ * SUCCESS the value is cached, permanently
23
+ * IN-FLIGHT concurrent callers share one request
24
+ * FAILURE the in-flight state is cleared, the failure reaches every
25
+ * caller that was waiting, and the next caller starts fresh
26
+ * ```
27
+ *
28
+ * Nothing here retries anything on its own. A retry happens when the
29
+ * application performs another operation, which is deliberate: a client that
30
+ * retried revision discovery by itself would turn a permanently misconfigured
31
+ * application into a request storm against the authority.
32
+ */
33
+ import { FeltDBServiceError } from './error-codes.js';
34
+ const PERMANENT_STATUS = new Set([400, 401, 403, 404, 405, 409, 410, 422]);
35
+ const PERMANENT_CODES = new Set([
36
+ 'AUTHENTICATION_REQUIRED', 'AUTHENTICATION_FAILED', 'FORBIDDEN', 'NOT_FOUND',
37
+ 'VALIDATION_ERROR', 'QUERY_INVALID',
38
+ ]);
39
+ /** Classify a failure without requiring applications to inspect messages. */
40
+ export function classifyFailureClass(error) {
41
+ const value = error;
42
+ const status = value?.status;
43
+ const code = typeof value?.code === 'string' ? value.code : undefined;
44
+ if (status === 401 || code === 'AUTHENTICATION_REQUIRED' || code === 'AUTHENTICATION_FAILED')
45
+ return 'authentication';
46
+ if (status === 403 || code === 'FORBIDDEN')
47
+ return 'authorization';
48
+ if ((typeof status === 'number' && [400, 404, 405, 409, 410, 422].includes(status))
49
+ || (code !== undefined && ['NOT_FOUND', 'VALIDATION_ERROR', 'QUERY_INVALID'].includes(code)))
50
+ return 'configuration';
51
+ if (code === 'CLIENT_CLOSED')
52
+ return 'closed';
53
+ return 'transient';
54
+ }
55
+ /**
56
+ * Classify a failure as transient or permanent.
57
+ *
58
+ * The default is `transient`, and deliberately so: misclassifying a transient
59
+ * failure as permanent reproduces the incident this module exists to fix,
60
+ * while misclassifying a permanent one as transient costs a retry the caller
61
+ * was going to make anyway. The asymmetry is the whole point.
62
+ */
63
+ export function classifyFailure(error) {
64
+ return classifyFailureClass(error) === 'transient' ? 'transient' : 'permanent';
65
+ }
66
+ /** Render a failure for the health surface without discarding the original. */
67
+ export function describeFailure(error) {
68
+ const service = error instanceof FeltDBServiceError ? error : undefined;
69
+ const value = error;
70
+ return {
71
+ kind: classifyFailure(error),
72
+ failure_class: classifyFailureClass(error),
73
+ name: value?.name ?? 'Error',
74
+ message: value?.message ?? String(error),
75
+ ...(service?.code !== undefined ? { code: String(service.code) } : {}),
76
+ ...(typeof value?.status === 'number' ? { status: value.status } : {}),
77
+ at: new Date().toISOString(),
78
+ };
79
+ }
80
+ /**
81
+ * A value discovered once, shared while in flight, and never cached when it
82
+ * fails.
83
+ *
84
+ * The three invariants, all of which the incident violated:
85
+ *
86
+ * 1. a successful value is cached and never re-fetched;
87
+ * 2. concurrent callers share one request rather than issuing N;
88
+ * 3. a failed request leaves **no** cached state, so the next caller starts a
89
+ * new request — and every caller that was waiting sees the same typed
90
+ * failure, not a different one each.
91
+ */
92
+ export class SingleFlightValue {
93
+ cached;
94
+ inFlight;
95
+ failures = 0;
96
+ lastFailure;
97
+ lastSuccessAt;
98
+ /** The cached value, if discovery has ever succeeded. */
99
+ get value() {
100
+ return this.cached;
101
+ }
102
+ get state() {
103
+ if (this.cached !== undefined)
104
+ return 'cached';
105
+ if (this.inFlight)
106
+ return 'loading';
107
+ return 'unavailable';
108
+ }
109
+ snapshot() {
110
+ return {
111
+ state: this.state,
112
+ consecutive_failures: this.failures,
113
+ ...(this.lastFailure ? { last_failure: this.lastFailure } : {}),
114
+ ...(this.lastSuccessAt ? { last_success_at: this.lastSuccessAt } : {}),
115
+ };
116
+ }
117
+ /**
118
+ * Return the value, discovering it with `load` if necessary.
119
+ *
120
+ * `load` runs at most once per in-flight window. It is passed in rather than
121
+ * held so that this type stays a state machine and nothing else: it knows
122
+ * how to share and how to forget, and nothing about HTTP.
123
+ */
124
+ get(load) {
125
+ if (this.cached !== undefined)
126
+ return Promise.resolve(this.cached);
127
+ if (this.inFlight)
128
+ return this.inFlight;
129
+ const request = Promise.resolve()
130
+ .then(load)
131
+ .then(value => {
132
+ this.cached = value;
133
+ this.failures = 0;
134
+ this.lastFailure = undefined;
135
+ this.lastSuccessAt = new Date().toISOString();
136
+ return value;
137
+ }, error => {
138
+ // The rejection is recorded and re-thrown. It is never retained as
139
+ // the cached value, which is the entire fix.
140
+ this.failures += 1;
141
+ this.lastFailure = describeFailure(error);
142
+ throw error;
143
+ })
144
+ .finally(() => {
145
+ // Guarded: a slower failed request must not clear a newer in-flight
146
+ // one that a later caller has already started.
147
+ if (this.inFlight === request)
148
+ this.inFlight = undefined;
149
+ });
150
+ this.inFlight = request;
151
+ return request;
152
+ }
153
+ /**
154
+ * Adopt a value the caller already has, without a request.
155
+ *
156
+ * A revision supplied at construction is as good as one discovered, and the
157
+ * state should say `cached` rather than pretending nothing is known.
158
+ */
159
+ seed(value) {
160
+ this.cached = value;
161
+ this.failures = 0;
162
+ this.lastFailure = undefined;
163
+ this.lastSuccessAt = new Date().toISOString();
164
+ }
165
+ /** Forget everything, including a successful value. */
166
+ reset() {
167
+ this.cached = undefined;
168
+ this.inFlight = undefined;
169
+ this.failures = 0;
170
+ this.lastFailure = undefined;
171
+ }
172
+ }
173
+ /**
174
+ * Exponential backoff with a cap and jitter.
175
+ *
176
+ * The jitter is **partial**, not full: a delay is drawn uniformly from the
177
+ * upper half of its ceiling, `[ceiling / 2, ceiling)`. Full jitter — `[0,
178
+ * ceiling)` — would let the fifth consecutive failure sleep for less than the
179
+ * first, which makes "increasing after consecutive failures" untrue and
180
+ * untestable. Partial jitter keeps both properties: every delay is strictly
181
+ * larger than every delay possible at a lower failure count, and two clients
182
+ * failing together still separate, because they draw independently.
183
+ *
184
+ * The previous behaviour was a flat one-second retry, forever. That is
185
+ * neither bounded in aggregate nor jittered, so a managed service coming back
186
+ * after an outage was met by every client it had ever served, in lockstep.
187
+ */
188
+ export class BoundedBackoff {
189
+ base;
190
+ max;
191
+ factor;
192
+ random;
193
+ consecutive = 0;
194
+ constructor(options = {}) {
195
+ this.base = Math.max(1, options.base ?? 500);
196
+ this.max = Math.max(this.base, options.max ?? 30_000);
197
+ this.factor = Math.max(1, options.factor ?? 2);
198
+ this.random = options.random ?? Math.random;
199
+ }
200
+ /** How many consecutive failures have been recorded. */
201
+ get attempts() {
202
+ return this.consecutive;
203
+ }
204
+ /** The ceiling this many consecutive failures in, capped. */
205
+ ceiling(attempt = this.consecutive) {
206
+ return Math.min(this.max, Math.round(this.base * this.factor ** attempt));
207
+ }
208
+ /** Draw the next delay and count the failure that caused it. */
209
+ next() {
210
+ const ceiling = this.ceiling();
211
+ this.consecutive += 1;
212
+ const floor = ceiling / 2;
213
+ return Math.round(floor + this.random() * floor);
214
+ }
215
+ /** A connection that stayed up long enough to count returns us to base. */
216
+ reset() {
217
+ this.consecutive = 0;
218
+ }
219
+ }
220
+ /**
221
+ * Sleep, unless the signal aborts first.
222
+ *
223
+ * Two properties matter and both were missing: the timer must not hold a Node
224
+ * process open on its own, and the abort listener must be removed when the
225
+ * timer fires normally. Without the second, a long-lived subscription
226
+ * accumulates one listener per reconnect attempt, which is a leak that only
227
+ * shows up on the clients that have been running longest.
228
+ */
229
+ export function cancellableDelay(ms, signal) {
230
+ if (signal.aborted)
231
+ return Promise.resolve();
232
+ return new Promise(resolve => {
233
+ const done = () => {
234
+ clearTimeout(timer);
235
+ signal.removeEventListener('abort', done);
236
+ resolve();
237
+ };
238
+ const timer = setTimeout(done, ms);
239
+ timer.unref?.();
240
+ signal.addEventListener('abort', done, { once: true });
241
+ });
242
+ }
package/dist/memory-db.js CHANGED
@@ -56,7 +56,7 @@ export class MemoryJsDb {
56
56
  if (plan.kind === 'duplicate')
57
57
  return embeddedResult(request, true, before, this.sequence);
58
58
  if (plan.kind === 'reject')
59
- throw new EmbeddedTransactionRejected(plan.reason);
59
+ throw new EmbeddedTransactionRejected(plan.reason, plan.failure);
60
60
  for (const mutation of plan.mutations) {
61
61
  if (mutation.value === undefined) {
62
62
  this.rows.delete(mutation.key);
@@ -1 +1 @@
1
- var e=class e{static __wrap(t){let n=Object.create(e.prototype);return n.__wbg_ptr=t,T.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,T.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_jsdb_free(e,0)}acknowledge_peer_operations(e,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=U.jsdb_acknowledge_peer_operations(this.__wbg_ptr,r,i,n);return t.__wrap(a)}add_sync_peer(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_add_sync_peer(this.__wbg_ptr,n,r);return t.__wrap(i)}delete(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_delete(this.__wbg_ptr,n,r);return t.__wrap(i)}execute_canonical_query(e,n,r,i){let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),c=H,l=F(r,U.__wbindgen_malloc,U.__wbindgen_realloc),u=H,d=F(i,U.__wbindgen_malloc,U.__wbindgen_realloc),f=H,p=U.jsdb_execute_canonical_query(this.__wbg_ptr,a,o,s,c,l,u,d,f);return t.__wrap(p)}execute_canonical_transaction(e,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.jsdb_execute_canonical_transaction(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}get(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_get(this.__wbg_ptr,n,r);return t.__wrap(i)}get_capability_records(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_get_capability_records(this.__wbg_ptr,n,r);return t.__wrap(i)}get_pending_for_peer(e,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=U.jsdb_get_pending_for_peer(this.__wbg_ptr,r,i,n);return t.__wrap(a)}get_sequence(){let e=U.jsdb_get_sequence(this.__wbg_ptr);return BigInt.asUintN(64,e)}insert(e,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.jsdb_insert(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}instance_id(){let e,t;try{let n=U.jsdb_instance_id(this.__wbg_ptr);return e=n[0],t=n[1],j(n[0],n[1])}finally{U.__wbindgen_free(e,t,1)}}is_auto_indexed(){return U.jsdb_is_auto_indexed(this.__wbg_ptr)!==0}query(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_query(this.__wbg_ptr,n,r);return t.__wrap(i)}remove_sync_peer(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_remove_sync_peer(this.__wbg_ptr,n,r);return t.__wrap(i)}sync_info(){let e=U.jsdb_sync_info(this.__wbg_ptr);return t.__wrap(e)}update(e,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.jsdb_update(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}};Symbol.dispose&&(e.prototype[Symbol.dispose]=e.prototype.free);var t=class e{static __wrap(t){let n=Object.create(e.prototype);return n.__wbg_ptr=t,E.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,E.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_jsresult_free(e,0)}get data(){let e=U.jsresult_data(this.__wbg_ptr),t;return e[0]!==0&&(t=j(e[0],e[1]),U.__wbindgen_free(e[0],e[1]*1,1)),t}get error(){let e=U.jsresult_error(this.__wbg_ptr),t;return e[0]!==0&&(t=j(e[0],e[1]),U.__wbindgen_free(e[0],e[1]*1,1)),t}get success(){return U.jsresult_success(this.__wbg_ptr)!==0}};Symbol.dispose&&(t.prototype[Symbol.dispose]=t.prototype.free);var n=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,D.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_wasmanalytics_free(e,0)}generate_report(e,t){let n,r;try{let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.wasmanalytics_generate_report(this.__wbg_ptr,o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,I(u[2]);return n=i,r=a,j(i,a)}finally{U.__wbindgen_free(n,r,1)}}get_all_metrics(){let e,t;try{let i=U.wasmanalytics_get_all_metrics(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}get_frequent_fields(e){let t,n;try{let a=U.wasmanalytics_get_frequent_fields(this.__wbg_ptr,e);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,I(a[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}get_index_metrics(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmanalytics_get_index_metrics(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}get_slowest_queries(e){let t,n;try{let a=U.wasmanalytics_get_slowest_queries(this.__wbg_ptr,e);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,I(a[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}constructor(){let e=U.wasmanalytics_new();return this.__wbg_ptr=e,D.register(this,this.__wbg_ptr,this),this}record_index_usage(e,t,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H;U.wasmanalytics_record_index_usage(this.__wbg_ptr,r,i,a,o,n)}record_query(e,t,n,r,i,a){let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H;var u=P(a)?0:F(a,U.__wbindgen_malloc,U.__wbindgen_realloc),d=H;let f=U.wasmanalytics_record_query(this.__wbg_ptr,o,s,c,l,n,r,i,u,d);if(f[1])throw I(f[0])}reset(){U.wasmanalytics_reset(this.__wbg_ptr)}};Symbol.dispose&&(n.prototype[Symbol.dispose]=n.prototype.free);var r=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,O.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_wasmdistributedindexmanager_free(e,0)}create_replicated_index(e,t,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),c=H,l=U.wasmdistributedindexmanager_create_replicated_index(this.__wbg_ptr,r,i,a,o,s,c);if(l[1])throw I(l[0])}detect_conflicts(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmdistributedindexmanager_detect_conflicts(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}get_replication_status(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmdistributedindexmanager_get_replication_status(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}get_replication_targets(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmdistributedindexmanager_get_replication_targets(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}get_sync_status(){let e,t;try{let i=U.wasmdistributedindexmanager_get_sync_status(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}merge_versions(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H,r=U.wasmdistributedindexmanager_merge_versions(this.__wbg_ptr,t,n);if(r[1])throw I(r[0])}constructor(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H,r=U.wasmdistributedindexmanager_new(t,n);return this.__wbg_ptr=r,O.register(this,this.__wbg_ptr,this),this}register_peer(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H;U.wasmdistributedindexmanager_register_peer(this.__wbg_ptr,t,n)}set_peer_reachable(e,t){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H;U.wasmdistributedindexmanager_set_peer_reachable(this.__wbg_ptr,n,r,t)}};Symbol.dispose&&(r.prototype[Symbol.dispose]=r.prototype.free);var i=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,k.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_wasmindexmanager_free(e,0)}create_index(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H,r=U.wasmindexmanager_create_index(this.__wbg_ptr,t,n);if(r[1])throw I(r[0])}get_stats(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmindexmanager_get_stats(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}list_indexes(){let e,t;try{let i=U.wasmindexmanager_list_indexes(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}constructor(){let e=U.wasmindexmanager_new();return this.__wbg_ptr=e,k.register(this,this.__wbg_ptr,this),this}query_index(e,t,n){let r,i;try{let s=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),c=H,l=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),u=H,d=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),f=H,p=U.wasmindexmanager_query_index(this.__wbg_ptr,s,c,l,u,d,f);var a=p[0],o=p[1];if(p[3])throw a=0,o=0,I(p[2]);return r=a,i=o,j(a,o)}finally{U.__wbindgen_free(r,i,1)}}update_record(e,t,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H;var a=P(t)?0:F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H;let s=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),c=H,l=U.wasmindexmanager_update_record(this.__wbg_ptr,r,i,a,o,s,c);if(l[1])throw I(l[0])}};Symbol.dispose&&(i.prototype[Symbol.dispose]=i.prototype.free);var a=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,A.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_wasmshardmanager_free(e,0)}detect_hotspots(){let e,t;try{let i=U.wasmshardmanager_detect_hotspots(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}generate_rebalance_ops(){let e,t;try{let i=U.wasmshardmanager_generate_rebalance_ops(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}get_all_metrics(){let e,t;try{let i=U.wasmshardmanager_get_all_metrics(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}get_distribution_summary(){let e,t;try{let i=U.wasmshardmanager_get_distribution_summary(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}get_shard_for_key(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmshardmanager_get_shard_for_key(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}initialize_shards(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H,r=U.wasmshardmanager_initialize_shards(this.__wbg_ptr,t,n);if(r[1])throw I(r[0])}constructor(e,t){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),a=H,o=U.wasmshardmanager_new(n,r,i,a);return this.__wbg_ptr=o,A.register(this,this.__wbg_ptr,this),this}record_shard_operation(e,t,n,r,i){let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),c=H;U.wasmshardmanager_record_shard_operation(this.__wbg_ptr,a,o,s,c,n,r,i)}};Symbol.dispose&&(a.prototype[Symbol.dispose]=a.prototype.free);function o(e,t){let n,r;try{let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.apply_sync_result(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,I(u[2]);return n=i,r=a,j(i,a)}finally{U.__wbindgen_free(n,r,1)}}function s(e,t,n,r,i,a){let o,s;try{let u=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),d=H,f=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),p=H,m=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),h=H,g=F(r,U.__wbindgen_malloc,U.__wbindgen_realloc),_=H,v=F(i,U.__wbindgen_malloc,U.__wbindgen_realloc),y=H,b=F(a,U.__wbindgen_malloc,U.__wbindgen_realloc),x=H,S=U.authorize_offline(u,d,f,p,m,h,g,_,v,y,b,x);var c=S[0],l=S[1];if(S[3])throw c=0,l=0,I(S[2]);return o=c,s=l,j(c,l)}finally{U.__wbindgen_free(o,s,1)}}function c(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.canonical_bundle_hash(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function l(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.canonicalize_application_manifest(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function u(e,t){let n,r;try{let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.compare_state_schemas(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,I(u[2]);return n=i,r=a,j(i,a)}finally{U.__wbindgen_free(n,r,1)}}function d(e,t){let n,r;try{var i=P(e)?0:F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),a=H;let c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.diff_application_revisions(i,a,c,l);var o=u[0],s=u[1];if(u[3])throw o=0,s=0,I(u[2]);return n=o,r=s,j(o,s)}finally{U.__wbindgen_free(n,r,1)}}function f(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.hash_application_manifest(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function p(e,t){let n,r;try{let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.hash_application_runtime(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,I(u[2]);return n=i,r=a,j(i,a)}finally{U.__wbindgen_free(n,r,1)}}function m(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.hash_state_schema(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function h(t){let n=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.open(n,r);if(i[2])throw I(i[1]);return e.__wrap(i[0])}function g(e,t){let n,r;try{let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.resolve_application_runtime(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,I(u[2]);return n=i,r=a,j(i,a)}finally{U.__wbindgen_free(n,r,1)}}function _(e,t,n,r){let i=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),a=H,o=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.validate_mesh_claim(i,a,o,s,c,l,r);if(u[1])throw I(u[0])}function v(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.validate_state_schema(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function y(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.validate_sync_operation(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function b(e,t){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),a=H,o=U.validate_worker_transition(n,r,i,a);if(o[2])throw I(o[1]);return o[0]!==0}function x(e,t){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),a=H,o=U.validate_workload_transition(n,r,i,a);if(o[2])throw I(o[1]);return o[0]!==0}function S(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H,r=U.verify_bundle_integrity(t,n);if(r[2])throw I(r[1]);return r[0]!==0}function C(e,t,n,r,i,a){let o,s;try{let u=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),d=H,f=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),p=H,m=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),h=H,g=F(r,U.__wbindgen_malloc,U.__wbindgen_realloc),_=H,v=F(i,U.__wbindgen_malloc,U.__wbindgen_realloc),y=H,b=F(a,U.__wbindgen_malloc,U.__wbindgen_realloc),x=H,S=U.verify_signed_grant(u,d,f,p,m,h,g,_,v,y,b,x);var c=S[0],l=S[1];if(S[3])throw c=0,l=0,I(S[2]);return o=c,s=l,j(c,l)}finally{U.__wbindgen_free(o,s,1)}}function w(){return{__proto__:null,"./feltdb_wasm_bg.js":{__proto__:null,__wbg___wbindgen_throw_bb96b2010945f0bc:function(e,t){throw Error(j(e,t))},__wbindgen_cast_0000000000000001:function(e,t){return j(e,t)},__wbindgen_init_externref_table:function(){let e=U.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}}}}var T=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_jsdb_free(e,1)),E=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_jsresult_free(e,1)),D=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_wasmanalytics_free(e,1)),O=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_wasmdistributedindexmanager_free(e,1)),k=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_wasmindexmanager_free(e,1)),A=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_wasmshardmanager_free(e,1));function j(e,t){return B(e>>>0,t)}var M=null;function N(){return(M===null||M.byteLength===0)&&(M=new Uint8Array(U.memory.buffer)),M}function P(e){return e==null}function F(e,t,n){if(n===void 0){let n=V.encode(e),r=t(n.length,1)>>>0;return N().subarray(r,r+n.length).set(n),H=n.length,r}let r=e.length,i=t(r,1)>>>0,a=N(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=N().subarray(i+o,i+r),a=V.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return H=o,i}function I(e){let t=U.__wbindgen_externrefs.get(e);return U.__externref_table_dealloc(e),t}var L=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0});L.decode();var R=2146435072,z=0;function B(e,t){return z+=t,z>=R&&(L=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0}),L.decode(),z=t),L.decode(N().subarray(e,e+t))}var V=new TextEncoder;`encodeInto`in V||(V.encodeInto=function(e,t){let n=V.encode(e);return t.set(n),{read:e.length,written:n.length}});var H=0,U;function W(e,t){return U=e.exports,M=null,U.__wbindgen_start(),U}async function G(e,t){if(typeof Response==`function`&&e instanceof Response){if(!e.ok)throw Error(`failed to fetch Wasm: ${e.status} ${e.statusText} fetching '${e.url}'`);if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}function K(e){if(U!==void 0)return U;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=w();return e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e)),W(new WebAssembly.Instance(e,t),e)}async function q(e){if(U!==void 0)return U;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`)),e===void 0&&(e=new URL(`/assets/feltdb_wasm_bg-ClhDHp0S.wasm`,``+import.meta.url));let t=w();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await G(await e,t);return W(n,r)}export{e as JsDb,t as JsResult,n as WasmAnalytics,r as WasmDistributedIndexManager,i as WasmIndexManager,a as WasmShardManager,o as apply_sync_result,s as authorize_offline,c as canonical_bundle_hash,l as canonicalize_application_manifest,u as compare_state_schemas,q as default,d as diff_application_revisions,f as hash_application_manifest,p as hash_application_runtime,m as hash_state_schema,K as initSync,h as open,g as resolve_application_runtime,_ as validate_mesh_claim,v as validate_state_schema,y as validate_sync_operation,b as validate_worker_transition,x as validate_workload_transition,S as verify_bundle_integrity,C as verify_signed_grant};
1
+ var e=class e{static __wrap(t){let n=Object.create(e.prototype);return n.__wbg_ptr=t,T.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,T.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_jsdb_free(e,0)}acknowledge_peer_operations(e,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=U.jsdb_acknowledge_peer_operations(this.__wbg_ptr,r,i,n);return t.__wrap(a)}add_sync_peer(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_add_sync_peer(this.__wbg_ptr,n,r);return t.__wrap(i)}delete(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_delete(this.__wbg_ptr,n,r);return t.__wrap(i)}execute_canonical_query(e,n,r,i){let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),c=H,l=F(r,U.__wbindgen_malloc,U.__wbindgen_realloc),u=H,d=F(i,U.__wbindgen_malloc,U.__wbindgen_realloc),f=H,p=U.jsdb_execute_canonical_query(this.__wbg_ptr,a,o,s,c,l,u,d,f);return t.__wrap(p)}execute_canonical_transaction(e,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.jsdb_execute_canonical_transaction(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}get(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_get(this.__wbg_ptr,n,r);return t.__wrap(i)}get_capability_records(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_get_capability_records(this.__wbg_ptr,n,r);return t.__wrap(i)}get_pending_for_peer(e,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=U.jsdb_get_pending_for_peer(this.__wbg_ptr,r,i,n);return t.__wrap(a)}get_sequence(){let e=U.jsdb_get_sequence(this.__wbg_ptr);return BigInt.asUintN(64,e)}insert(e,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.jsdb_insert(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}instance_id(){let e,t;try{let n=U.jsdb_instance_id(this.__wbg_ptr);return e=n[0],t=n[1],j(n[0],n[1])}finally{U.__wbindgen_free(e,t,1)}}is_auto_indexed(){return U.jsdb_is_auto_indexed(this.__wbg_ptr)!==0}query(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_query(this.__wbg_ptr,n,r);return t.__wrap(i)}remove_sync_peer(e){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.jsdb_remove_sync_peer(this.__wbg_ptr,n,r);return t.__wrap(i)}sync_info(){let e=U.jsdb_sync_info(this.__wbg_ptr);return t.__wrap(e)}update(e,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.jsdb_update(this.__wbg_ptr,r,i,a,o);return t.__wrap(s)}};Symbol.dispose&&(e.prototype[Symbol.dispose]=e.prototype.free);var t=class e{static __wrap(t){let n=Object.create(e.prototype);return n.__wbg_ptr=t,E.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,E.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_jsresult_free(e,0)}get data(){let e=U.jsresult_data(this.__wbg_ptr),t;return e[0]!==0&&(t=j(e[0],e[1]),U.__wbindgen_free(e[0],e[1]*1,1)),t}get error(){let e=U.jsresult_error(this.__wbg_ptr),t;return e[0]!==0&&(t=j(e[0],e[1]),U.__wbindgen_free(e[0],e[1]*1,1)),t}get success(){return U.jsresult_success(this.__wbg_ptr)!==0}};Symbol.dispose&&(t.prototype[Symbol.dispose]=t.prototype.free);var n=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,D.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_wasmanalytics_free(e,0)}generate_report(e,t){let n,r;try{let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.wasmanalytics_generate_report(this.__wbg_ptr,o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,I(u[2]);return n=i,r=a,j(i,a)}finally{U.__wbindgen_free(n,r,1)}}get_all_metrics(){let e,t;try{let i=U.wasmanalytics_get_all_metrics(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}get_frequent_fields(e){let t,n;try{let a=U.wasmanalytics_get_frequent_fields(this.__wbg_ptr,e);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,I(a[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}get_index_metrics(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmanalytics_get_index_metrics(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}get_slowest_queries(e){let t,n;try{let a=U.wasmanalytics_get_slowest_queries(this.__wbg_ptr,e);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,I(a[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}constructor(){let e=U.wasmanalytics_new();return this.__wbg_ptr=e,D.register(this,this.__wbg_ptr,this),this}record_index_usage(e,t,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H;U.wasmanalytics_record_index_usage(this.__wbg_ptr,r,i,a,o,n)}record_query(e,t,n,r,i,a){let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H;var u=P(a)?0:F(a,U.__wbindgen_malloc,U.__wbindgen_realloc),d=H;let f=U.wasmanalytics_record_query(this.__wbg_ptr,o,s,c,l,n,r,i,u,d);if(f[1])throw I(f[0])}reset(){U.wasmanalytics_reset(this.__wbg_ptr)}};Symbol.dispose&&(n.prototype[Symbol.dispose]=n.prototype.free);var r=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,O.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_wasmdistributedindexmanager_free(e,0)}create_replicated_index(e,t,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H,a=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),c=H,l=U.wasmdistributedindexmanager_create_replicated_index(this.__wbg_ptr,r,i,a,o,s,c);if(l[1])throw I(l[0])}detect_conflicts(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmdistributedindexmanager_detect_conflicts(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}get_replication_status(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmdistributedindexmanager_get_replication_status(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}get_replication_targets(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmdistributedindexmanager_get_replication_targets(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}get_sync_status(){let e,t;try{let i=U.wasmdistributedindexmanager_get_sync_status(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}merge_versions(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H,r=U.wasmdistributedindexmanager_merge_versions(this.__wbg_ptr,t,n);if(r[1])throw I(r[0])}constructor(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H,r=U.wasmdistributedindexmanager_new(t,n);return this.__wbg_ptr=r,O.register(this,this.__wbg_ptr,this),this}register_peer(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H;U.wasmdistributedindexmanager_register_peer(this.__wbg_ptr,t,n)}set_peer_reachable(e,t){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H;U.wasmdistributedindexmanager_set_peer_reachable(this.__wbg_ptr,n,r,t)}};Symbol.dispose&&(r.prototype[Symbol.dispose]=r.prototype.free);var i=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,k.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_wasmindexmanager_free(e,0)}create_index(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H,r=U.wasmindexmanager_create_index(this.__wbg_ptr,t,n);if(r[1])throw I(r[0])}get_stats(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmindexmanager_get_stats(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}list_indexes(){let e,t;try{let i=U.wasmindexmanager_list_indexes(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}constructor(){let e=U.wasmindexmanager_new();return this.__wbg_ptr=e,k.register(this,this.__wbg_ptr,this),this}query_index(e,t,n){let r,i;try{let s=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),c=H,l=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),u=H,d=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),f=H,p=U.wasmindexmanager_query_index(this.__wbg_ptr,s,c,l,u,d,f);var a=p[0],o=p[1];if(p[3])throw a=0,o=0,I(p[2]);return r=a,i=o,j(a,o)}finally{U.__wbindgen_free(r,i,1)}}update_record(e,t,n){let r=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),i=H;var a=P(t)?0:F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H;let s=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),c=H,l=U.wasmindexmanager_update_record(this.__wbg_ptr,r,i,a,o,s,c);if(l[1])throw I(l[0])}};Symbol.dispose&&(i.prototype[Symbol.dispose]=i.prototype.free);var a=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,A.unregister(this),e}free(){let e=this.__destroy_into_raw();U.__wbg_wasmshardmanager_free(e,0)}detect_hotspots(){let e,t;try{let i=U.wasmshardmanager_detect_hotspots(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}generate_rebalance_ops(){let e,t;try{let i=U.wasmshardmanager_generate_rebalance_ops(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}get_all_metrics(){let e,t;try{let i=U.wasmshardmanager_get_all_metrics(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}get_distribution_summary(){let e,t;try{let i=U.wasmshardmanager_get_distribution_summary(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,I(i[2]);return e=n,t=r,j(n,r)}finally{U.__wbindgen_free(e,t,1)}}get_shard_for_key(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.wasmshardmanager_get_shard_for_key(this.__wbg_ptr,a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}initialize_shards(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H,r=U.wasmshardmanager_initialize_shards(this.__wbg_ptr,t,n);if(r[1])throw I(r[0])}constructor(e,t){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),a=H,o=U.wasmshardmanager_new(n,r,i,a);return this.__wbg_ptr=o,A.register(this,this.__wbg_ptr,this),this}record_shard_operation(e,t,n,r,i){let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),c=H;U.wasmshardmanager_record_shard_operation(this.__wbg_ptr,a,o,s,c,n,r,i)}};Symbol.dispose&&(a.prototype[Symbol.dispose]=a.prototype.free);function o(e,t){let n,r;try{let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.apply_sync_result(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,I(u[2]);return n=i,r=a,j(i,a)}finally{U.__wbindgen_free(n,r,1)}}function s(e,t,n,r,i,a){let o,s;try{let u=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),d=H,f=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),p=H,m=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),h=H,g=F(r,U.__wbindgen_malloc,U.__wbindgen_realloc),_=H,v=F(i,U.__wbindgen_malloc,U.__wbindgen_realloc),y=H,b=F(a,U.__wbindgen_malloc,U.__wbindgen_realloc),x=H,S=U.authorize_offline(u,d,f,p,m,h,g,_,v,y,b,x);var c=S[0],l=S[1];if(S[3])throw c=0,l=0,I(S[2]);return o=c,s=l,j(c,l)}finally{U.__wbindgen_free(o,s,1)}}function c(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.canonical_bundle_hash(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function l(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.canonicalize_application_manifest(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function u(e,t){let n,r;try{let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.compare_state_schemas(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,I(u[2]);return n=i,r=a,j(i,a)}finally{U.__wbindgen_free(n,r,1)}}function d(e,t){let n,r;try{var i=P(e)?0:F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),a=H;let c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.diff_application_revisions(i,a,c,l);var o=u[0],s=u[1];if(u[3])throw o=0,s=0,I(u[2]);return n=o,r=s,j(o,s)}finally{U.__wbindgen_free(n,r,1)}}function f(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.hash_application_manifest(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function p(e,t){let n,r;try{let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.hash_application_runtime(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,I(u[2]);return n=i,r=a,j(i,a)}finally{U.__wbindgen_free(n,r,1)}}function m(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.hash_state_schema(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function h(t){let n=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=U.open(n,r);if(i[2])throw I(i[1]);return e.__wrap(i[0])}function g(e,t){let n,r;try{let o=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.resolve_application_runtime(o,s,c,l);var i=u[0],a=u[1];if(u[3])throw i=0,a=0,I(u[2]);return n=i,r=a,j(i,a)}finally{U.__wbindgen_free(n,r,1)}}function _(e,t,n,r){let i=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),a=H,o=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),s=H,c=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),l=H,u=U.validate_mesh_claim(i,a,o,s,c,l,r);if(u[1])throw I(u[0])}function v(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.validate_state_schema(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function y(e){let t,n;try{let a=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),o=H,s=U.validate_sync_operation(a,o);var r=s[0],i=s[1];if(s[3])throw r=0,i=0,I(s[2]);return t=r,n=i,j(r,i)}finally{U.__wbindgen_free(t,n,1)}}function b(e,t){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),a=H,o=U.validate_worker_transition(n,r,i,a);if(o[2])throw I(o[1]);return o[0]!==0}function x(e,t){let n=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),r=H,i=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),a=H,o=U.validate_workload_transition(n,r,i,a);if(o[2])throw I(o[1]);return o[0]!==0}function S(e){let t=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),n=H,r=U.verify_bundle_integrity(t,n);if(r[2])throw I(r[1]);return r[0]!==0}function C(e,t,n,r,i,a){let o,s;try{let u=F(e,U.__wbindgen_malloc,U.__wbindgen_realloc),d=H,f=F(t,U.__wbindgen_malloc,U.__wbindgen_realloc),p=H,m=F(n,U.__wbindgen_malloc,U.__wbindgen_realloc),h=H,g=F(r,U.__wbindgen_malloc,U.__wbindgen_realloc),_=H,v=F(i,U.__wbindgen_malloc,U.__wbindgen_realloc),y=H,b=F(a,U.__wbindgen_malloc,U.__wbindgen_realloc),x=H,S=U.verify_signed_grant(u,d,f,p,m,h,g,_,v,y,b,x);var c=S[0],l=S[1];if(S[3])throw c=0,l=0,I(S[2]);return o=c,s=l,j(c,l)}finally{U.__wbindgen_free(o,s,1)}}function w(){return{__proto__:null,"./feltdb_wasm_bg.js":{__proto__:null,__wbg___wbindgen_throw_bb96b2010945f0bc:function(e,t){throw Error(j(e,t))},__wbindgen_cast_0000000000000001:function(e,t){return j(e,t)},__wbindgen_init_externref_table:function(){let e=U.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}}}}var T=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_jsdb_free(e,1)),E=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_jsresult_free(e,1)),D=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_wasmanalytics_free(e,1)),O=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_wasmdistributedindexmanager_free(e,1)),k=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_wasmindexmanager_free(e,1)),A=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>U.__wbg_wasmshardmanager_free(e,1));function j(e,t){return B(e>>>0,t)}var M=null;function N(){return(M===null||M.byteLength===0)&&(M=new Uint8Array(U.memory.buffer)),M}function P(e){return e==null}function F(e,t,n){if(n===void 0){let n=V.encode(e),r=t(n.length,1)>>>0;return N().subarray(r,r+n.length).set(n),H=n.length,r}let r=e.length,i=t(r,1)>>>0,a=N(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=N().subarray(i+o,i+r),a=V.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return H=o,i}function I(e){let t=U.__wbindgen_externrefs.get(e);return U.__externref_table_dealloc(e),t}var L=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0});L.decode();var R=2146435072,z=0;function B(e,t){return z+=t,z>=R&&(L=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0}),L.decode(),z=t),L.decode(N().subarray(e,e+t))}var V=new TextEncoder;`encodeInto`in V||(V.encodeInto=function(e,t){let n=V.encode(e);return t.set(n),{read:e.length,written:n.length}});var H=0,U;function W(e,t){return U=e.exports,M=null,U.__wbindgen_start(),U}async function G(e,t){if(typeof Response==`function`&&e instanceof Response){if(!e.ok)throw Error(`failed to fetch Wasm: ${e.status} ${e.statusText} fetching '${e.url}'`);if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}function K(e){if(U!==void 0)return U;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=w();return e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e)),W(new WebAssembly.Instance(e,t),e)}async function q(e){if(U!==void 0)return U;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`)),e===void 0&&(e=new URL(`/assets/feltdb_wasm_bg-DnsHNv6g.wasm`,``+import.meta.url));let t=w();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await G(await e,t);return W(n,r)}export{e as JsDb,t as JsResult,n as WasmAnalytics,r as WasmDistributedIndexManager,i as WasmIndexManager,a as WasmShardManager,o as apply_sync_result,s as authorize_offline,c as canonical_bundle_hash,l as canonicalize_application_manifest,u as compare_state_schemas,q as default,d as diff_application_revisions,f as hash_application_manifest,p as hash_application_runtime,m as hash_state_schema,K as initSync,h as open,g as resolve_application_runtime,_ as validate_mesh_claim,v as validate_state_schema,y as validate_sync_operation,b as validate_worker_transition,x as validate_workload_transition,S as verify_bundle_integrity,C as verify_signed_grant};