convex-ents 0.9.2 → 0.9.4

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
@@ -134,10 +134,13 @@ function defineEntSchema(schema, options) {
134
134
  const edgeTable = defineEnt({
135
135
  [forwardId]: import_values.v.id(tableName),
136
136
  [inverseId]: import_values.v.id(otherTableName)
137
- }).index(forwardId, [forwardId]).index(inverseId, [inverseId]).index(`${forwardId}_${inverseId}`, [forwardId, inverseId]);
137
+ }).index(forwardId, [forwardId]).index(inverseId, [inverseId]).index(edgeCompoundIndexName(forwardId, inverseId), [
138
+ forwardId,
139
+ inverseId
140
+ ]);
138
141
  const isSymmetric = inverseEdge === void 0;
139
142
  if (!isSymmetric) {
140
- edgeTable.index(`${inverseId}_${forwardId}`, [
143
+ edgeTable.index(edgeCompoundIndexName(inverseId, forwardId), [
141
144
  inverseId,
142
145
  forwardId
143
146
  ]);
@@ -161,6 +164,9 @@ function defineEntSchema(schema, options) {
161
164
  }
162
165
  return (0, import_server.defineSchema)(schema, options);
163
166
  }
167
+ function edgeCompoundIndexName(idA, idB) {
168
+ return `${idA}_${idB}`;
169
+ }
164
170
  function canBeInverseEdge(tableName, edge, isSelfDirected) {
165
171
  return (candidate) => {
166
172
  if (candidate.to !== tableName) {
@@ -518,7 +524,10 @@ var WriterImplBase = class _WriterImplBase {
518
524
  await Promise.all(
519
525
  idOrIds.add.map(async (id) => {
520
526
  const existing = await this.ctx.db.query(edgeDefinition.table).withIndex(
521
- edgeDefinition.field,
527
+ edgeCompoundIndexName(
528
+ edgeDefinition.field,
529
+ edgeDefinition.ref
530
+ ),
522
531
  (q) => q.eq(edgeDefinition.field, docId).eq(
523
532
  edgeDefinition.ref,
524
533
  id
@@ -1169,7 +1178,10 @@ var PromiseEdgeOrNullImpl = class _PromiseEdgeOrNullImpl extends PromiseEntsOrNu
1169
1178
  return null;
1170
1179
  }
1171
1180
  const edgeDoc = this.ctx.db.query(this.edgeDefinition.table).withIndex(
1172
- `${this.edgeDefinition.field}_${this.edgeDefinition.ref}`,
1181
+ edgeCompoundIndexName(
1182
+ this.edgeDefinition.field,
1183
+ this.edgeDefinition.ref
1184
+ ),
1173
1185
  (q) => q.eq(this.edgeDefinition.field, sourceId).eq(
1174
1186
  this.edgeDefinition.ref,
1175
1187
  targetId
@@ -1364,7 +1376,7 @@ var PromiseEntOrNullImpl = class extends Promise {
1364
1376
  return new PromiseEdgeOrNullImpl(
1365
1377
  this.ctx,
1366
1378
  this.entDefinitions,
1367
- this.table,
1379
+ edgeDefinition.to,
1368
1380
  edgeDefinition,
1369
1381
  async () => {
1370
1382
  const { id } = await this.retrieve();