convex-ents 0.7.1 → 0.7.2
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/deletion.js.map +1 -1
- package/dist/functions.js +17 -3
- package/dist/functions.js.map +1 -1
- package/dist/index.js +34 -13
- package/dist/index.js.map +1 -1
- package/dist/schema.js +17 -10
- package/dist/schema.js.map +1 -1
- package/dist/writer.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -367,16 +367,23 @@ var EntDefinitionImpl = class {
|
|
|
367
367
|
};
|
|
368
368
|
function getEntDefinitions(schema) {
|
|
369
369
|
const tables = schema.tables;
|
|
370
|
-
return Object.
|
|
371
|
-
(acc, tableName) =>
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
370
|
+
return Object.entries(tables).reduce(
|
|
371
|
+
(acc, [tableName, table]) => {
|
|
372
|
+
acc[tableName] = {
|
|
373
|
+
indexes: table.indexes.reduce(
|
|
374
|
+
(acc2, { indexDescriptor, fields }) => {
|
|
375
|
+
acc2[indexDescriptor] = fields;
|
|
376
|
+
return acc2;
|
|
377
|
+
},
|
|
378
|
+
{}
|
|
379
|
+
),
|
|
380
|
+
defaults: table.defaults,
|
|
381
|
+
edges: table.edgeConfigs,
|
|
382
|
+
fields: table.fieldConfigs,
|
|
383
|
+
deletionConfig: table.deletionConfig
|
|
384
|
+
};
|
|
385
|
+
return acc;
|
|
386
|
+
},
|
|
380
387
|
{}
|
|
381
388
|
);
|
|
382
389
|
}
|
|
@@ -932,11 +939,22 @@ var PromiseTableImpl = class extends PromiseQueryOrNullImpl {
|
|
|
932
939
|
}
|
|
933
940
|
};
|
|
934
941
|
} : async () => {
|
|
935
|
-
const [indexName,
|
|
936
|
-
const
|
|
942
|
+
const [indexName, ...values] = args;
|
|
943
|
+
const fieldNames = getIndexFields(
|
|
944
|
+
this.entDefinitions,
|
|
945
|
+
this.table,
|
|
946
|
+
indexName
|
|
947
|
+
);
|
|
948
|
+
const doc = await this.ctx.db.query(this.table).withIndex(
|
|
949
|
+
indexName,
|
|
950
|
+
(q) => values.reduce((q2, value, i) => q2.eq(fieldNames[i], value), q)
|
|
951
|
+
).unique();
|
|
937
952
|
if (throwIfNull && doc === null) {
|
|
938
953
|
throw new Error(
|
|
939
|
-
`Table "${this.table}" does not contain document with field
|
|
954
|
+
`Table "${this.table}" does not contain document with field${values.reduce(
|
|
955
|
+
(message, value, i) => `${message} "${fieldNames[i]}" = \`${value}\``,
|
|
956
|
+
""
|
|
957
|
+
)}`
|
|
940
958
|
);
|
|
941
959
|
}
|
|
942
960
|
return loadedRetriever(doc);
|
|
@@ -1629,6 +1647,9 @@ async function filterByReadRule(ctx, entDefinitions, table, docs, throwIfNull) {
|
|
|
1629
1647
|
);
|
|
1630
1648
|
return docs.filter((_, i) => decisions[i]);
|
|
1631
1649
|
}
|
|
1650
|
+
function getIndexFields(entDefinitions, table, index) {
|
|
1651
|
+
return entDefinitions[table].indexes[index];
|
|
1652
|
+
}
|
|
1632
1653
|
function getReadRule(entDefinitions, table) {
|
|
1633
1654
|
return entDefinitions.rules?.[table]?.read;
|
|
1634
1655
|
}
|