Skip to content

Commit

Permalink
store: fix warning bug
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Oct 28, 2023
1 parent 432d4ec commit dcd24cf
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/store/src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import primary from "./primary.js";

const last = -1;
const ending = -3;
const {
EmptyStoreDirectory,
InvalidType,
MissingPrimaryKey,
MissingStoreDirectory,
TransactionRolledBack,
} = errors;

const make_transaction = async env => {
const [transaction] = await Promise.all(env.drivers.map(driver =>
Expand All @@ -23,9 +30,8 @@ const make_transaction = async env => {
const valid_type = ({ base, validate }) =>
base !== undefined && typeof validate === "function";

const valid = (type, name, store) => valid_type(type)
? type
: errors.InvalidType.throw(name, store);
const valid = (type, name, store) =>
valid_type(type) ? type : InvalidType.throw(name, store);

export default ({
// directory for stores
Expand All @@ -43,7 +49,7 @@ export default ({
async init(app, next) {
const root = app.root.join(directory);
if (!await root.exists) {
errors.MissingStoreDirectory.warn(app.log, root);
MissingStoreDirectory.warn(app.log, root);
return next(app);
}

Expand All @@ -63,7 +69,7 @@ export default ({
.filter(([property, type]) => valid(type, property, store)));

exports.ambiguous !== true && schema.id === undefined
&& errors.MissingPrimaryKey.throw(primary, store,
&& MissingPrimaryKey.throw(primary, store,
"export const ambiguous = true;");

const pathed = store.replaceAll("/", ".");
Expand All @@ -80,8 +86,8 @@ export default ({
}),
);

if (Object.keys(stores.length === 0)) {
errors.EmptyStoreDirectory.warn(app.log, root);
if (Object.keys(stores.length) === 0) {
EmptyStoreDirectory.warn(app.log, root);
return next(app);
}

Expand Down Expand Up @@ -122,7 +128,7 @@ export default ({
);
} catch (error) {
env.log.auto(error);
errors.TransactionRolledBack.warn(env.log, id, error.name);
TransactionRolledBack.warn(env.log, id, error.name);

// let core handle error
throw error;
Expand Down

0 comments on commit dcd24cf

Please sign in to comment.