@hf-chimera/store
Version:
Cross-end reactivity API
210 lines (201 loc) • 8.22 kB
JavaScript
//#region src/shared/errors.ts
var ChimeraError = class extends Error {};
var ChimeraInternalError = class extends ChimeraError {
constructor(message, options) {
super(`${message}\nIf you have this bug, feel free to create an issue in https://github.com/hf-chimera/store/issues`, options);
}
};
//#endregion
//#region src/order/errors.ts
var ChimeraOrderError = class extends ChimeraError {};
var ChimeraOrderTypeError = class extends ChimeraOrderError {};
var ChimeraOrderTypeComparisonError = class extends ChimeraOrderTypeError {
constructor(a, b) {
super(`Unsupported comparison "${a}"(${typeof a}[${a != null ? a.constructor.name : a}]) with "${b}"(${typeof b}[${b != null ? b.constructor.name : b}])`);
}
};
//#endregion
//#region src/query/errors.ts
const formatDeepErrorMessage = (message, cause) => `${message}: ${cause instanceof Error ? `\n ${cause.stack}` : cause}`;
var ChimeraQueryError = class extends ChimeraError {
entityName;
constructor(entityName, message, options) {
super(message, options);
this.entityName = entityName;
}
};
var ChimeraQueryIdMismatchError = class extends ChimeraQueryError {
old;
new;
constructor(entityName, oldId, newId) {
super(entityName, `
Can't update "${entityName}" item if the change updates it's [id] (changed from "${oldId}" to "${newId}").
If such an update should not be an error, update <idGetter> field in "${entityName}" entity config to make Chimera get the [id] value properly.
`.trim());
this.old = oldId;
this.new = newId;
}
};
var ChimeraQueryNotSpecifiedError = class extends ChimeraQueryError {
methodName;
constructor(entityName, methodName) {
super(entityName, `<${methodName}> for entity "${entityName}" was not specified`);
this.methodName = methodName;
}
};
var ChimeraQueryTrustError = class extends ChimeraQueryError {
constructor(entityName, description) {
super(entityName, `
DO NOT IGNORE THIS ERROR OR YOUR PROD MAY BREAK!
Looks like your "${entityName}" query provider ${description}
By default Chimera tend to trust external query provider to avoid extra data processing.
If it is not your case, set field "trustQuery" to "false" in config defaults or for specific entity.
This error visible only if "devMode" is "true".
If you'll ignore it, your production may fail, because Chimera won't check the data correctness.
`.trim());
}
};
var ChimeraQueryTrustIdMismatchError = class extends ChimeraQueryTrustError {
old;
new;
constructor(entityName, oldId, newId) {
super(entityName, `
returned an item with [id] that not matches with the [id] of item that was updated (changed from "${oldId}" to "${newId}").
If it is not an error, update <idGetter> field in "${entityName}" entity config to make Chimera get the [id] value properly.
`.trim());
this.old = oldId;
this.new = newId;
}
};
var ChimeraQueryTrustFetchedCollectionError = class extends ChimeraQueryTrustError {
old;
new;
constructor(entityName, input, output) {
super(entityName, "returned not properly sorted or ordered collection.");
this.old = input;
this.new = output;
}
};
var ChimeraQueryFetchingError = class extends ChimeraQueryError {
constructor(entityName, cause) {
super(entityName, formatDeepErrorMessage("Something went wrong", cause), { cause });
}
};
var ChimeraQueryDeletingError = class extends ChimeraQueryError {
constructor(entityName, cause) {
super(entityName, formatDeepErrorMessage("Something went wrong", cause), { cause });
}
};
var ChimeraQueryNotReadyError = class extends ChimeraQueryError {
constructor(entityName) {
super(entityName, "Unable to get unready value.");
}
};
var ChimeraQueryDeletedItemError = class extends ChimeraQueryError {
constructor(entityName, id) {
super(entityName, `Unable to updated deleted item with [id] "${id}."`);
}
};
var ChimeraQueryUnsuccessfulDeletionError = class extends ChimeraQueryError {
constructor(entityName, id) {
super(entityName, `Item with [id] "${id}" was not deleted.`);
}
};
var ChimeraQueryAlreadyRunningError = class extends ChimeraQueryError {
constructor(entityName, status) {
super(entityName, `Unable to operate query. Other process already running ${status}.`);
}
};
var ChimeraQueryNotCreatedError = class extends ChimeraQueryError {
constructor(entityName) {
super(entityName, "Unable to operate not created item.");
}
};
//#endregion
//#region src/debug/defaults.ts
const chimeraDefaultDebugConfig = {
devMode: false,
logs: "info",
name: "chimera"
};
//#endregion
//#region src/filter/defaults.ts
const getKeyFromOperation = (operator) => JSON.stringify(operator);
const chimeraDefaultGetKeyFromFilter = (filter) => JSON.stringify(filter);
const chimeraDefaultFilterOperators = {
contains: (a, b) => {
if (typeof a === "string") return a.includes(b);
if (Array.isArray(a)) return Array.isArray(b) ? b.every((v) => a.includes(v)) : a.includes(b);
return false;
},
endsWith: (a, b) => a.endsWith(b),
startsWith: (a, b) => a.startsWith(b),
eq: (a, b) => a === b,
gt: (a, b) => a > b,
gte: (a, b) => a >= b,
in: (a, b) => (Array.isArray(a) ? a : [a]).some((v) => b.includes(v)),
lt: (a, b) => a < b,
lte: (a, b) => a <= b,
neq: (a, b) => a !== b,
notIn: (a, b) => (Array.isArray(a) ? a : [a]).every((v) => !b.includes(v))
};
const chimeraDefaultFilterConfig = {
getFilterKey: chimeraDefaultGetKeyFromFilter,
getOperatorKey: getKeyFromOperation,
operators: chimeraDefaultFilterOperators
};
//#endregion
//#region src/order/defaults.ts
const chimeraDefaultComparator = (a, b) => {
let result = 0;
if (typeof a === "string" && typeof b === "string") result = a.localeCompare(b);
else if (typeof a === "number" && typeof b === "number" || typeof a === "boolean" && typeof b === "boolean") result = a - b;
else if (a instanceof Date && b instanceof Date) result = a.getTime() - b.getTime();
else if (a == null || b == null) result = a == b ? 0 : a == null ? -1 : 1;
else throw new ChimeraOrderTypeComparisonError(a, b);
return result;
};
const chimeraDefaultKeyFromOrder = (order) => JSON.stringify(order);
const chimeraDefaultOrderConfig = {
getKey: chimeraDefaultKeyFromOrder,
primitiveComparator: chimeraDefaultComparator
};
//#endregion
//#region src/query/defaults.ts
const chimeraDefaultQueryConfig = {
defaults: {
batchedCreator: (entity) => {
throw new ChimeraQueryNotSpecifiedError(entity, "batchedCreator");
},
batchedDeleter: (entity) => {
throw new ChimeraQueryNotSpecifiedError(entity, "batchedDeleter");
},
batchedUpdater: (entity) => {
throw new ChimeraQueryNotSpecifiedError(entity, "batchedUpdater");
},
collectionFetcher: (entity) => {
throw new ChimeraQueryNotSpecifiedError(entity, "collectionFetcher");
},
idGetter: (entity) => {
throw new ChimeraQueryNotSpecifiedError(entity, "idGetter");
},
itemCreator: (entity) => {
throw new ChimeraQueryNotSpecifiedError(entity, "itemCreator");
},
itemDeleter: (entity) => {
throw new ChimeraQueryNotSpecifiedError(entity, "itemDeleter");
},
itemFetcher: (entity) => {
throw new ChimeraQueryNotSpecifiedError(entity, "itemFetcher");
},
itemUpdater: (entity) => {
throw new ChimeraQueryNotSpecifiedError(entity, "itemUpdater");
},
trustQuery: true,
updateDebounceTimeout: 0
},
entities: {}
};
//#endregion
export { ChimeraOrderError as C, ChimeraInternalError as D, ChimeraError as E, ChimeraQueryUnsuccessfulDeletionError as S, ChimeraOrderTypeError as T, ChimeraQueryNotReadyError as _, chimeraDefaultFilterConfig as a, ChimeraQueryTrustFetchedCollectionError as b, getKeyFromOperation as c, ChimeraQueryDeletedItemError as d, ChimeraQueryDeletingError as f, ChimeraQueryNotCreatedError as g, ChimeraQueryIdMismatchError as h, chimeraDefaultOrderConfig as i, chimeraDefaultDebugConfig as l, ChimeraQueryFetchingError as m, chimeraDefaultComparator as n, chimeraDefaultFilterOperators as o, ChimeraQueryError as p, chimeraDefaultKeyFromOrder as r, chimeraDefaultGetKeyFromFilter as s, chimeraDefaultQueryConfig as t, ChimeraQueryAlreadyRunningError as u, ChimeraQueryNotSpecifiedError as v, ChimeraOrderTypeComparisonError as w, ChimeraQueryTrustIdMismatchError as x, ChimeraQueryTrustError as y };
//# sourceMappingURL=defaults-CLUQg2zK.js.map