@hf-chimera/store
Version:
Cross-end reactivity API
372 lines (362 loc) • 11.4 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
Object.defineProperty(exports, 'ChimeraError', {
enumerable: true,
get: function () {
return ChimeraError;
}
});
Object.defineProperty(exports, 'ChimeraInternalError', {
enumerable: true,
get: function () {
return ChimeraInternalError;
}
});
Object.defineProperty(exports, 'ChimeraOrderError', {
enumerable: true,
get: function () {
return ChimeraOrderError;
}
});
Object.defineProperty(exports, 'ChimeraOrderTypeComparisonError', {
enumerable: true,
get: function () {
return ChimeraOrderTypeComparisonError;
}
});
Object.defineProperty(exports, 'ChimeraOrderTypeError', {
enumerable: true,
get: function () {
return ChimeraOrderTypeError;
}
});
Object.defineProperty(exports, 'ChimeraQueryAlreadyRunningError', {
enumerable: true,
get: function () {
return ChimeraQueryAlreadyRunningError;
}
});
Object.defineProperty(exports, 'ChimeraQueryDeletedItemError', {
enumerable: true,
get: function () {
return ChimeraQueryDeletedItemError;
}
});
Object.defineProperty(exports, 'ChimeraQueryDeletingError', {
enumerable: true,
get: function () {
return ChimeraQueryDeletingError;
}
});
Object.defineProperty(exports, 'ChimeraQueryError', {
enumerable: true,
get: function () {
return ChimeraQueryError;
}
});
Object.defineProperty(exports, 'ChimeraQueryFetchingError', {
enumerable: true,
get: function () {
return ChimeraQueryFetchingError;
}
});
Object.defineProperty(exports, 'ChimeraQueryIdMismatchError', {
enumerable: true,
get: function () {
return ChimeraQueryIdMismatchError;
}
});
Object.defineProperty(exports, 'ChimeraQueryNotCreatedError', {
enumerable: true,
get: function () {
return ChimeraQueryNotCreatedError;
}
});
Object.defineProperty(exports, 'ChimeraQueryNotReadyError', {
enumerable: true,
get: function () {
return ChimeraQueryNotReadyError;
}
});
Object.defineProperty(exports, 'ChimeraQueryNotSpecifiedError', {
enumerable: true,
get: function () {
return ChimeraQueryNotSpecifiedError;
}
});
Object.defineProperty(exports, 'ChimeraQueryTrustError', {
enumerable: true,
get: function () {
return ChimeraQueryTrustError;
}
});
Object.defineProperty(exports, 'ChimeraQueryTrustFetchedCollectionError', {
enumerable: true,
get: function () {
return ChimeraQueryTrustFetchedCollectionError;
}
});
Object.defineProperty(exports, 'ChimeraQueryTrustIdMismatchError', {
enumerable: true,
get: function () {
return ChimeraQueryTrustIdMismatchError;
}
});
Object.defineProperty(exports, 'ChimeraQueryUnsuccessfulDeletionError', {
enumerable: true,
get: function () {
return ChimeraQueryUnsuccessfulDeletionError;
}
});
Object.defineProperty(exports, 'chimeraDefaultComparator', {
enumerable: true,
get: function () {
return chimeraDefaultComparator;
}
});
Object.defineProperty(exports, 'chimeraDefaultDebugConfig', {
enumerable: true,
get: function () {
return chimeraDefaultDebugConfig;
}
});
Object.defineProperty(exports, 'chimeraDefaultFilterConfig', {
enumerable: true,
get: function () {
return chimeraDefaultFilterConfig;
}
});
Object.defineProperty(exports, 'chimeraDefaultFilterOperators', {
enumerable: true,
get: function () {
return chimeraDefaultFilterOperators;
}
});
Object.defineProperty(exports, 'chimeraDefaultGetKeyFromFilter', {
enumerable: true,
get: function () {
return chimeraDefaultGetKeyFromFilter;
}
});
Object.defineProperty(exports, 'chimeraDefaultKeyFromOrder', {
enumerable: true,
get: function () {
return chimeraDefaultKeyFromOrder;
}
});
Object.defineProperty(exports, 'chimeraDefaultOrderConfig', {
enumerable: true,
get: function () {
return chimeraDefaultOrderConfig;
}
});
Object.defineProperty(exports, 'chimeraDefaultQueryConfig', {
enumerable: true,
get: function () {
return chimeraDefaultQueryConfig;
}
});
Object.defineProperty(exports, 'getKeyFromOperation', {
enumerable: true,
get: function () {
return getKeyFromOperation;
}
});
//# sourceMappingURL=defaults-C48gY1ow.cjs.map