@foretag/tanstack-db-surrealdb 0.6.2 → 0.6.3

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.
package/dist/index.js CHANGED
@@ -124,20 +124,14 @@ var isRecordIdString = (value) => {
124
124
  return idx > 0 && idx < value.length - 1;
125
125
  };
126
126
  var looksLikeTableName = (value) => /^[A-Za-z_][A-Za-z0-9_-]*$/.test(value);
127
- var getCtorName = (value) => {
128
- if (!value || typeof value !== "object") return void 0;
129
- const ctor = value.constructor;
130
- return typeof ctor?.name === "string" ? ctor.name : void 0;
131
- };
132
127
  var isCrossRuntimeRecordIdObject = (value) => {
133
128
  if (!value || typeof value !== "object" || value instanceof surrealdb.RecordId) {
134
129
  return false;
135
130
  }
136
131
  const obj = value;
137
132
  if (typeof obj.toString !== "function") return false;
133
+ if (obj.toString === Object.prototype.toString) return false;
138
134
  if (!("table" in obj) || !("id" in obj)) return false;
139
- const ctorName = getCtorName(value);
140
- if (!ctorName || !/^RecordId\d*$/.test(ctorName)) return false;
141
135
  const tableValue = obj.table;
142
136
  const table = typeof tableValue === "string" ? tableValue : tableValue != null ? String(tableValue) : "";
143
137
  const idValue = obj.id;
@@ -163,11 +157,11 @@ var unwrapIdWrapper = (value) => {
163
157
  var asCanonicalRecordIdFromCrossRuntimeObject = (value) => {
164
158
  if (!isCrossRuntimeRecordIdObject(value)) return void 0;
165
159
  const obj = value;
166
- const tableRaw = typeof obj.table === "string" ? obj.table : String(obj.table);
167
- const table = stripOuterQuotes(tableRaw).trim();
168
- const id = String(obj.id);
169
- const fromFields = table && id && looksLikeTableName(table) ? `${table}:${id}` : void 0;
170
- if (fromFields) return toCanonicalRecordIdString(fromFields);
160
+ const table = typeof obj.table === "string" ? stripOuterQuotes(obj.table).trim() : void 0;
161
+ const id = typeof obj.id === "string" || typeof obj.id === "number" || typeof obj.id === "bigint" ? String(obj.id) : void 0;
162
+ if (table && id && looksLikeTableName(table)) {
163
+ return toCanonicalRecordIdString(`${table}:${id}`);
164
+ }
171
165
  return toCanonicalRecordIdString(String(obj.toString()));
172
166
  };
173
167
  var asCanonicalRecordIdString = (value) => {
@@ -187,10 +181,15 @@ var toNativeRecordIdLikeValue = (value) => {
187
181
  if (value instanceof surrealdb.RecordId) {
188
182
  const canonical2 = asCanonicalRecordIdString(value);
189
183
  if (!canonical2) return value;
190
- return getNativeRecordId(canonical2);
184
+ recordIdIdentityPool.set(canonical2, value);
185
+ nativeRecordIdPool.set(canonical2, value);
186
+ return value;
191
187
  }
192
188
  const canonical = asCanonicalRecordIdString(value);
193
189
  if (!canonical) return value;
190
+ if (isCrossRuntimeRecordIdObject(value)) {
191
+ recordIdIdentityPool.set(canonical, value);
192
+ }
194
193
  return getNativeRecordId(canonical);
195
194
  };
196
195
  var normalizeRecordIdLikeValue = (value) => {
@@ -703,19 +702,22 @@ function defaultAad(ctx) {
703
702
  return toBytes(`${ctx.table}:${base}:${ctx.id}`);
704
703
  }
705
704
  var syncModeFrom = (syncMode) => syncMode ?? "eager";
706
- var subsetCacheKey = (subset) => JSON.stringify(subset, (_key, value) => {
707
- if (value instanceof Date) return value.toISOString();
708
- if (value instanceof surrealdb.RecordId) return toRecordIdString(value);
709
- if (typeof value === "function") return void 0;
710
- if (value && typeof value === "object" && "table" in value && "id" in value) {
711
- try {
712
- return toRecordIdString(String(value));
713
- } catch {
714
- return value;
705
+ var subsetCacheKey = (subset) => {
706
+ const seen = /* @__PURE__ */ new WeakSet();
707
+ return JSON.stringify(subset, (_key, value) => {
708
+ if (value instanceof Date) return value.toISOString();
709
+ if (value instanceof surrealdb.RecordId) return toRecordIdString(value);
710
+ if (typeof value === "bigint") return value.toString();
711
+ if (typeof value === "function") return `[fn:${value.name || "anonymous"}]`;
712
+ if (value && typeof value === "object") {
713
+ const canonical = asCanonicalRecordIdString(value);
714
+ if (canonical) return canonical;
715
+ if (seen.has(value)) return "[Circular]";
716
+ seen.add(value);
715
717
  }
716
- }
717
- return value;
718
- });
718
+ return value;
719
+ }) ?? "";
720
+ };
719
721
  function modernSurrealCollectionOptions(config) {
720
722
  const {
721
723
  db,