@ai-matrx/records 0.79.1 → 0.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -163,6 +163,7 @@ __export(core_exports, {
163
163
  fieldKindFor: () => fieldKindFor,
164
164
  fieldKindOf: () => fieldKindOf,
165
165
  forgetAllOps: () => forgetAllOps,
166
+ forgetPrimedTablePageBundles: () => forgetPrimedTablePageBundles,
166
167
  hasQuietHours: () => hasQuietHours,
167
168
  highestLevel: () => highestLevel,
168
169
  holdsARetiredChoice: () => holdsARetiredChoice,
@@ -231,6 +232,7 @@ __export(core_exports, {
231
232
  predictWriteRefusals: () => predictWriteRefusals,
232
233
  previewRetype: () => previewRetype,
233
234
  previewRuleChange: () => previewRuleChange,
235
+ primeTablePageBundle: () => primeTablePageBundle,
234
236
  publicFormPath: () => publicFormPath,
235
237
  rankTypedMatches: () => rankTypedMatches,
236
238
  ratingMaxOf: () => ratingMaxOf,
@@ -267,6 +269,7 @@ __export(core_exports, {
267
269
  tableKindMapping: () => tableKindMapping,
268
270
  tableKindSlug: () => tableKindSlug,
269
271
  tableRenderSchema: () => tableRenderSchema,
272
+ takePrimedTablePageBundle: () => takePrimedTablePageBundle,
270
273
  toAoa: () => toAoa,
271
274
  tokenFor: () => tokenFor,
272
275
  twoDigitYear: () => twoDigitYear,
@@ -5101,6 +5104,26 @@ function tableRenderSchema(facts) {
5101
5104
  return { kind: slug, fields: out };
5102
5105
  }
5103
5106
 
5107
+ // src/core/primedBundle.ts
5108
+ var PRIMED_TTL_MS = 15e3;
5109
+ var primed = /* @__PURE__ */ new Map();
5110
+ var primedKey = (organizationId, tableId, viewId) => `${organizationId}|${tableId}|${viewId ?? ""}`;
5111
+ function primeTablePageBundle(input) {
5112
+ const answer = Promise.resolve(input.answer).catch((thrown) => ({ data: null, error: thrown }));
5113
+ primed.set(primedKey(input.organizationId, input.tableId, input.viewId), { answer, at: Date.now() });
5114
+ }
5115
+ function takePrimedTablePageBundle(organizationId, tableId, viewId) {
5116
+ if (!organizationId) return null;
5117
+ const key = primedKey(organizationId, tableId, viewId);
5118
+ const held = primed.get(key);
5119
+ if (!held) return null;
5120
+ primed.delete(key);
5121
+ return Date.now() - held.at < PRIMED_TTL_MS ? held.answer : null;
5122
+ }
5123
+ function forgetPrimedTablePageBundles() {
5124
+ primed.clear();
5125
+ }
5126
+
5104
5127
  // src/core/keysetCursor.ts
5105
5128
  function utf8ToBinary(text2) {
5106
5129
  let out = "";
@@ -6050,13 +6073,20 @@ function createRecordsClient(given) {
6050
6073
  }
6051
6074
  async function fillBundle(tableId, viewId) {
6052
6075
  try {
6053
- const response = await config.dataSource.rpc(
6054
- "table_page_bundle",
6055
- { p_organization_id: org, p_table_id: tableId, p_view_id: typeof viewId === "string" ? viewId : null },
6056
- { schema }
6057
- );
6076
+ const view = typeof viewId === "string" ? viewId : null;
6077
+ const usable = (r) => r !== null && !r.error && r.data !== null && typeof r.data === "object" && Array.isArray(r.data.parts);
6078
+ const primedAnswer = takePrimedTablePageBundle(org, tableId, view);
6079
+ let response = primedAnswer ? await primedAnswer : null;
6080
+ if (!usable(response)) {
6081
+ response = await config.dataSource.rpc(
6082
+ "table_page_bundle",
6083
+ { p_organization_id: org, p_table_id: tableId, p_view_id: view },
6084
+ { schema }
6085
+ );
6086
+ }
6087
+ if (!usable(response)) return;
6058
6088
  const answer = response.data;
6059
- if (response.error || !answer || !Array.isArray(answer.parts)) return;
6089
+ if (!answer || !Array.isArray(answer.parts)) return;
6060
6090
  const now = Date.now();
6061
6091
  for (const part of answer.parts) {
6062
6092
  if (part.error !== void 0 || part.data === void 0) continue;