UNPKG

@hf-chimera/store

Version:

Cross-end reactivity API

1 lines 14.6 kB
{"version":3,"file":"defaults-C48gY1ow.cjs","names":["getKeyFromOperation: ChimeraKeyFromOperatorGetter","chimeraDefaultGetKeyFromFilter: ChimeraKeyFromFilterGetter","chimeraDefaultComparator: ChimeraPrimitiveComparator","chimeraDefaultKeyFromOrder: ChimeraKeyFromOrderGetter"],"sources":["../src/shared/errors.ts","../src/order/errors.ts","../src/query/errors.ts","../src/debug/defaults.ts","../src/filter/defaults.ts","../src/order/defaults.ts","../src/query/defaults.ts"],"sourcesContent":["export class ChimeraError extends Error {}\n\nexport class ChimeraInternalError extends ChimeraError {\n\tconstructor(message: string, options?: ErrorOptions) {\n\t\tsuper(\n\t\t\t`${message}\\nIf you have this bug, feel free to create an issue in https://github.com/hf-chimera/store/issues`,\n\t\t\toptions,\n\t\t);\n\t}\n}\n","import { ChimeraError } from \"../shared/errors.ts\";\n\nexport class ChimeraOrderError extends ChimeraError {}\n\nexport class ChimeraOrderTypeError extends ChimeraOrderError {}\n\nexport class ChimeraOrderTypeComparisonError extends ChimeraOrderTypeError {\n\tconstructor(a: unknown, b: unknown) {\n\t\tsuper(\n\t\t\t`Unsupported comparison \"${a}\"(${typeof a}[${a != null ? a.constructor.name : a}]) with \"${b}\"(${typeof b}[${b != null ? b.constructor.name : b}])`,\n\t\t);\n\t}\n}\n","import { ChimeraError } from \"../shared/errors.ts\";\nimport type { ChimeraEntityId } from \"../shared/types.ts\";\nimport type { ChimeraQueryFetchingState } from \"./types.ts\";\n\nconst formatDeepErrorMessage = (message: string, cause: unknown): string =>\n\t`${message}: ${cause instanceof Error ? `\\n ${cause.stack}` : cause}`;\n\nexport class ChimeraQueryError extends ChimeraError {\n\treadonly entityName: string;\n\n\tconstructor(entityName: string, message: string, options?: ErrorOptions) {\n\t\tsuper(message, options);\n\t\tthis.entityName = entityName;\n\t}\n}\n\nexport class ChimeraQueryIdMismatchError extends ChimeraQueryError {\n\treadonly old: ChimeraEntityId;\n\treadonly new: ChimeraEntityId;\n\n\tconstructor(entityName: string, oldId: ChimeraEntityId, newId: ChimeraEntityId) {\n\t\tsuper(\n\t\t\tentityName,\n\t\t\t`\nCan't update \"${entityName}\" item if the change updates it's [id] (changed from \"${oldId}\" to \"${newId}\").\nIf such an update should not be an error, update <idGetter> field in \"${entityName}\" entity config to make Chimera get the [id] value properly.\n\t\t`.trim(),\n\t\t);\n\t\tthis.old = oldId;\n\t\tthis.new = newId;\n\t}\n}\n\nexport class ChimeraQueryNotSpecifiedError extends ChimeraQueryError {\n\treadonly methodName: string;\n\n\tconstructor(entityName: string, methodName: string) {\n\t\tsuper(entityName, `<${methodName}> for entity \"${entityName}\" was not specified`);\n\t\tthis.methodName = methodName;\n\t}\n}\n\nexport class ChimeraQueryTrustError extends ChimeraQueryError {\n\tconstructor(entityName: string, description: string) {\n\t\tsuper(\n\t\t\tentityName,\n\t\t\t`\nDO NOT IGNORE THIS ERROR OR YOUR PROD MAY BREAK!\n\nLooks like your \"${entityName}\" query provider ${description}\n\nBy default Chimera tend to trust external query provider to avoid extra data processing.\nIf it is not your case, set field \"trustQuery\" to \"false\" in config defaults or for specific entity.\nThis error visible only if \"devMode\" is \"true\".\nIf you'll ignore it, your production may fail, because Chimera won't check the data correctness.\n`.trim(),\n\t\t);\n\t}\n}\n\nexport class ChimeraQueryTrustIdMismatchError extends ChimeraQueryTrustError {\n\treadonly old: ChimeraEntityId;\n\treadonly new: ChimeraEntityId;\n\n\tconstructor(entityName: string, oldId: ChimeraEntityId, newId: ChimeraEntityId) {\n\t\tsuper(\n\t\t\tentityName,\n\t\t\t`\nreturned an item with [id] that not matches with the [id] of item that was updated (changed from \"${oldId}\" to \"${newId}\"). \nIf it is not an error, update <idGetter> field in \"${entityName}\" entity config to make Chimera get the [id] value properly.\n`.trim(),\n\t\t);\n\t\tthis.old = oldId;\n\t\tthis.new = newId;\n\t}\n}\n\nexport class ChimeraQueryTrustFetchedCollectionError extends ChimeraQueryTrustError {\n\treadonly old: unknown[];\n\treadonly new: unknown[];\n\n\tconstructor(entityName: string, input: unknown[], output: unknown[]) {\n\t\tsuper(entityName, \"returned not properly sorted or ordered collection.\");\n\t\tthis.old = input;\n\t\tthis.new = output;\n\t}\n}\n\nexport class ChimeraQueryFetchingError extends ChimeraQueryError {\n\tconstructor(entityName: string, cause: unknown) {\n\t\tsuper(entityName, formatDeepErrorMessage(\"Something went wrong\", cause), { cause });\n\t}\n}\n\nexport class ChimeraQueryDeletingError extends ChimeraQueryError {\n\tconstructor(entityName: string, cause: unknown) {\n\t\tsuper(entityName, formatDeepErrorMessage(\"Something went wrong\", cause), { cause });\n\t}\n}\n\nexport class ChimeraQueryNotReadyError extends ChimeraQueryError {\n\tconstructor(entityName: string) {\n\t\tsuper(entityName, \"Unable to get unready value.\");\n\t}\n}\n\nexport class ChimeraQueryDeletedItemError extends ChimeraQueryError {\n\tconstructor(entityName: string, id: ChimeraEntityId) {\n\t\tsuper(entityName, `Unable to updated deleted item with [id] \"${id}.\"`);\n\t}\n}\n\nexport class ChimeraQueryUnsuccessfulDeletionError extends ChimeraQueryError {\n\tconstructor(entityName: string, id: ChimeraEntityId) {\n\t\tsuper(entityName, `Item with [id] \"${id}\" was not deleted.`);\n\t}\n}\n\nexport class ChimeraQueryAlreadyRunningError extends ChimeraQueryError {\n\tconstructor(entityName: string, status: ChimeraQueryFetchingState) {\n\t\tsuper(entityName, `Unable to operate query. Other process already running ${status}.`);\n\t}\n}\n\nexport class ChimeraQueryNotCreatedError extends ChimeraQueryError {\n\tconstructor(entityName: string) {\n\t\tsuper(entityName, \"Unable to operate not created item.\");\n\t}\n}\n","import type { ChimeraDebugConfig } from \"./types.ts\";\n\nexport const chimeraDefaultDebugConfig = {\n\tdevMode: false,\n\tlogs: \"info\",\n\tname: \"chimera\",\n} satisfies Required<ChimeraDebugConfig>;\n","import type {\n\tChimeraFilterConfig,\n\tChimeraKeyFromFilterGetter,\n\tChimeraKeyFromOperatorGetter,\n\tChimeraOperatorMap,\n} from \"./types.ts\";\n\nexport const getKeyFromOperation: ChimeraKeyFromOperatorGetter = (operator) => JSON.stringify(operator);\nexport const chimeraDefaultGetKeyFromFilter: ChimeraKeyFromFilterGetter = (filter) => JSON.stringify(filter);\n\nexport const chimeraDefaultFilterOperators = {\n\tcontains: <\n\t\tI extends string | unknown[],\n\t\tT extends I extends never[] ? unknown : I extends unknown[] ? I[number] | I : I extends string ? string : never,\n\t>(\n\t\ta: I,\n\t\tb: T,\n\t) => {\n\t\tif (typeof a === \"string\") return a.includes(b as string);\n\t\tif (Array.isArray(a)) return Array.isArray(b) ? b.every((v) => a.includes(v)) : a.includes(b);\n\t\treturn false;\n\t},\n\tendsWith: (a: string, b: string) => a.endsWith(b),\n\tstartsWith: (a: string, b: string) => a.startsWith(b),\n\teq: <T>(a: T, b: T) => a === b,\n\tgt: (a, b) => a > b,\n\tgte: (a, b) => a >= b,\n\tin: <I, T extends I extends never[] ? unknown[] : I extends unknown[] ? I : I[]>(a: I, b: T) =>\n\t\t(Array.isArray(a) ? a : [a]).some((v) => b.includes(v)),\n\tlt: (a, b) => a < b,\n\tlte: (a, b) => a <= b,\n\tneq: <T>(a: T, b: T) => a !== b,\n\tnotIn: (a, b) => (Array.isArray(a) ? a : [a]).every((v) => !b.includes(v)),\n} satisfies ChimeraOperatorMap;\n\nexport const chimeraDefaultFilterConfig = {\n\tgetFilterKey: chimeraDefaultGetKeyFromFilter,\n\tgetOperatorKey: getKeyFromOperation,\n\toperators: chimeraDefaultFilterOperators,\n} satisfies ChimeraFilterConfig<typeof chimeraDefaultFilterOperators>;\n","import { ChimeraOrderTypeComparisonError } from \"./errors.ts\";\nimport type { ChimeraKeyFromOrderGetter, ChimeraOrderConfig, ChimeraPrimitiveComparator } from \"./types.ts\";\n\nexport const chimeraDefaultComparator: ChimeraPrimitiveComparator = (a: unknown, b: unknown): number => {\n\tlet result = 0;\n\n\tif (typeof a === \"string\" && typeof b === \"string\") {\n\t\tresult = a.localeCompare(b);\n\t} else if ((typeof a === \"number\" && typeof b === \"number\") || (typeof a === \"boolean\" && typeof b === \"boolean\")) {\n\t\tresult = (a as number) - (b as number);\n\t} else if (a instanceof Date && b instanceof Date) {\n\t\tresult = a.getTime() - b.getTime();\n\t} else if (a == null || b == null) {\n\t\t// biome-ignore lint/suspicious/noDoubleEquals: At least one of the operands should be null or undefined. If one of them is null and the other is undefined, we should get true.\n\t\tresult = a == b ? 0 : a == null ? -1 : 1;\n\t} else {\n\t\tthrow new ChimeraOrderTypeComparisonError(a, b);\n\t}\n\treturn result;\n};\n\nexport const chimeraDefaultKeyFromOrder: ChimeraKeyFromOrderGetter = (order): string => JSON.stringify(order);\n\nexport const chimeraDefaultOrderConfig = {\n\tgetKey: chimeraDefaultKeyFromOrder,\n\tprimitiveComparator: chimeraDefaultComparator,\n} satisfies Required<ChimeraOrderConfig>;\n","import type { chimeraDefaultFilterOperators } from \"../filter/defaults\";\nimport type { ChimeraEntityMap } from \"../shared/types.ts\";\nimport { ChimeraQueryNotSpecifiedError } from \"./errors.ts\";\nimport type { ChimeraQueryConfig, ChimeraQueryDefaultsConfig } from \"./types.ts\";\n\nexport const chimeraDefaultQueryConfig = {\n\tdefaults: {\n\t\tbatchedCreator: (entity: string) => {\n\t\t\tthrow new ChimeraQueryNotSpecifiedError(entity, \"batchedCreator\");\n\t\t},\n\t\tbatchedDeleter: (entity: string) => {\n\t\t\tthrow new ChimeraQueryNotSpecifiedError(entity, \"batchedDeleter\");\n\t\t},\n\t\tbatchedUpdater: (entity: string) => {\n\t\t\tthrow new ChimeraQueryNotSpecifiedError(entity, \"batchedUpdater\");\n\t\t},\n\n\t\tcollectionFetcher: (entity: string) => {\n\t\t\tthrow new ChimeraQueryNotSpecifiedError(entity, \"collectionFetcher\");\n\t\t},\n\n\t\tidGetter: (entity: string) => {\n\t\t\tthrow new ChimeraQueryNotSpecifiedError(entity, \"idGetter\");\n\t\t},\n\n\t\titemCreator: (entity: string) => {\n\t\t\tthrow new ChimeraQueryNotSpecifiedError(entity, \"itemCreator\");\n\t\t},\n\n\t\titemDeleter: (entity: string) => {\n\t\t\tthrow new ChimeraQueryNotSpecifiedError(entity, \"itemDeleter\");\n\t\t},\n\t\titemFetcher: (entity: string) => {\n\t\t\tthrow new ChimeraQueryNotSpecifiedError(entity, \"itemFetcher\");\n\t\t},\n\n\t\titemUpdater: (entity: string) => {\n\t\t\tthrow new ChimeraQueryNotSpecifiedError(entity, \"itemUpdater\");\n\t\t},\n\t\ttrustQuery: true,\n\t\tupdateDebounceTimeout: 0,\n\t} as Required<ChimeraQueryDefaultsConfig<ChimeraEntityMap, typeof chimeraDefaultFilterOperators>>,\n\tentities: {},\n} satisfies ChimeraQueryConfig<ChimeraEntityMap, typeof chimeraDefaultFilterOperators>;\n"],"mappings":";;AAAA,IAAa,eAAb,cAAkC,MAAM;AAExC,IAAa,uBAAb,cAA0C,aAAa;CACtD,YAAY,SAAiB,SAAwB;AACpD,QACC,GAAG,QAAQ,qGACX,QACA;;;;;;ACLH,IAAa,oBAAb,cAAuC,aAAa;AAEpD,IAAa,wBAAb,cAA2C,kBAAkB;AAE7D,IAAa,kCAAb,cAAqD,sBAAsB;CAC1E,YAAY,GAAY,GAAY;AACnC,QACC,2BAA2B,EAAE,IAAI,OAAO,EAAE,GAAG,KAAK,OAAO,EAAE,YAAY,OAAO,EAAE,WAAW,EAAE,IAAI,OAAO,EAAE,GAAG,KAAK,OAAO,EAAE,YAAY,OAAO,EAAE,IAChJ;;;;;;ACNH,MAAM,0BAA0B,SAAiB,UAChD,GAAG,QAAQ,IAAI,iBAAiB,QAAQ,OAAO,MAAM,UAAU;AAEhE,IAAa,oBAAb,cAAuC,aAAa;CACnD,AAAS;CAET,YAAY,YAAoB,SAAiB,SAAwB;AACxE,QAAM,SAAS,QAAQ;AACvB,OAAK,aAAa;;;AAIpB,IAAa,8BAAb,cAAiD,kBAAkB;CAClE,AAAS;CACT,AAAS;CAET,YAAY,YAAoB,OAAwB,OAAwB;AAC/E,QACC,YACA;gB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