convex-ents
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -584,7 +584,18 @@ "use strict"; | ||
} : async () => { | ||
const [indexName, value] = args; | ||
const doc = await this.ctx.db.query(this.table).withIndex(indexName, (q) => q.eq(indexName, value)).unique(); | ||
const [indexName, ...values] = args; | ||
const fieldNames = getIndexFields( | ||
this.entDefinitions, | ||
this.table, | ||
indexName | ||
); | ||
const doc = await this.ctx.db.query(this.table).withIndex( | ||
indexName, | ||
(q) => values.reduce((q2, value, i) => q2.eq(fieldNames[i], value), q) | ||
).unique(); | ||
if (throwIfNull && doc === null) { | ||
throw new Error( | ||
`Table "${this.table}" does not contain document with field "${indexName}" = \`${value}\`` | ||
`Table "${this.table}" does not contain document with field${values.reduce( | ||
(message, value, i) => `${message} "${fieldNames[i]}" = \`${value}\``, | ||
"" | ||
)}` | ||
); | ||
@@ -1282,2 +1293,5 @@ } | ||
} | ||
function getIndexFields(entDefinitions, table, index) { | ||
return entDefinitions[table].indexes[index]; | ||
} | ||
function getReadRule(entDefinitions, table) { | ||
@@ -1284,0 +1298,0 @@ return entDefinitions.rules?.[table]?.read; |
@@ -370,12 +370,19 @@ "use strict"; | ||
const tables = schema.tables; | ||
return Object.keys(tables).reduce( | ||
(acc, tableName) => ({ | ||
...acc, | ||
[tableName]: { | ||
defaults: tables[tableName].defaults, | ||
edges: tables[tableName].edgeConfigs, | ||
fields: tables[tableName].fieldConfigs, | ||
deletionConfig: tables[tableName].deletionConfig | ||
} | ||
}), | ||
return Object.entries(tables).reduce( | ||
(acc, [tableName, table]) => { | ||
acc[tableName] = { | ||
indexes: table.indexes.reduce( | ||
(acc2, { indexDescriptor, fields }) => { | ||
acc2[indexDescriptor] = fields; | ||
return acc2; | ||
}, | ||
{} | ||
), | ||
defaults: table.defaults, | ||
edges: table.edgeConfigs, | ||
fields: table.fieldConfigs, | ||
deletionConfig: table.deletionConfig | ||
}; | ||
return acc; | ||
}, | ||
{} | ||
@@ -936,7 +943,18 @@ ); | ||
} : async () => { | ||
const [indexName, value] = args; | ||
const doc = await this.ctx.db.query(this.table).withIndex(indexName, (q) => q.eq(indexName, value)).unique(); | ||
const [indexName, ...values] = args; | ||
const fieldNames = getIndexFields( | ||
this.entDefinitions, | ||
this.table, | ||
indexName | ||
); | ||
const doc = await this.ctx.db.query(this.table).withIndex( | ||
indexName, | ||
(q) => values.reduce((q2, value, i) => q2.eq(fieldNames[i], value), q) | ||
).unique(); | ||
if (throwIfNull && doc === null) { | ||
throw new Error( | ||
`Table "${this.table}" does not contain document with field "${indexName}" = \`${value}\`` | ||
`Table "${this.table}" does not contain document with field${values.reduce( | ||
(message, value, i) => `${message} "${fieldNames[i]}" = \`${value}\``, | ||
"" | ||
)}` | ||
); | ||
@@ -1634,2 +1652,5 @@ } | ||
} | ||
function getIndexFields(entDefinitions, table, index) { | ||
return entDefinitions[table].indexes[index]; | ||
} | ||
function getReadRule(entDefinitions, table) { | ||
@@ -1636,0 +1657,0 @@ return entDefinitions.rules?.[table]?.read; |
@@ -365,12 +365,19 @@ "use strict"; | ||
const tables = schema.tables; | ||
return Object.keys(tables).reduce( | ||
(acc, tableName) => ({ | ||
...acc, | ||
[tableName]: { | ||
defaults: tables[tableName].defaults, | ||
edges: tables[tableName].edgeConfigs, | ||
fields: tables[tableName].fieldConfigs, | ||
deletionConfig: tables[tableName].deletionConfig | ||
} | ||
}), | ||
return Object.entries(tables).reduce( | ||
(acc, [tableName, table]) => { | ||
acc[tableName] = { | ||
indexes: table.indexes.reduce( | ||
(acc2, { indexDescriptor, fields }) => { | ||
acc2[indexDescriptor] = fields; | ||
return acc2; | ||
}, | ||
{} | ||
), | ||
defaults: table.defaults, | ||
edges: table.edgeConfigs, | ||
fields: table.fieldConfigs, | ||
deletionConfig: table.deletionConfig | ||
}; | ||
return acc; | ||
}, | ||
{} | ||
@@ -377,0 +384,0 @@ ); |
{ | ||
"name": "convex-ents", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"description": "Relations, default values, unique fields, RLS for Convex", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
794916
5775