@tonysamperi/ts-mapi-core 2.0.0-beta.5 → 2.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-DoiEsQxI.cjs';
1
+ import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-BdPg-J7L.cjs';
2
2
  import { SmpLoggerMethods } from '@tonysamperi/logger';
3
3
  export { smpNoop } from '@tonysamperi/logger';
4
4
  import { S as SmpResponseMessage, a as SmpResponseMessageTypes, b as SmpGenericResponseBase } from './smp-generic-response-base.interface-C0On2LBc.cjs';
@@ -15,9 +15,9 @@ declare abstract class SmpAbstractTtlCacheStrategy extends SmpAbstractCacheStrat
15
15
  protected abstract _removeRaw(key: string): void;
16
16
  protected abstract _writeRaw(key: string, value: unknown, ttl?: number): void;
17
17
  flush(): void;
18
- read<T = any>(key: string): T | undefined;
18
+ read<T = unknown>(key: string): T | undefined;
19
19
  remove(key: string): void;
20
- write<T = any>(key: string, value: T, ttl?: number): void;
20
+ write<T = unknown>(key: string, value: T, ttl?: number): void;
21
21
  protected _isSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
22
22
  }
23
23
 
@@ -682,7 +682,8 @@ declare class SmpAesCrypt {
682
682
  protected _password: string;
683
683
  protected _salt: string;
684
684
  protected _initVector?: string | undefined;
685
- protected get _iv(): WordArray | undefined;
685
+ protected _iv: WordArray | undefined;
686
+ protected _key: WordArray;
686
687
  protected _mode: typeof CBC;
687
688
  protected _padding: typeof PKCS7;
688
689
  constructor(_password: string, _salt: string, _initVector?: string | undefined);
@@ -708,6 +709,7 @@ declare class SmpAesCrypt {
708
709
  declare class SmpCrypto {
709
710
  static base64Decode(str: string): string;
710
711
  static base64Encode(str: string): string;
712
+ static generateCorrelationId(): string;
711
713
  static md5(data: string): string;
712
714
  static sha1(data: string): string;
713
715
  static sha256(data: string): string;
@@ -793,7 +795,7 @@ declare class SmpGiftcardTransaction implements SmpGiftcardTransactionPlain {
793
795
  protected _hashStrategy: (str: string) => WordArray;
794
796
  /**
795
797
  *
796
- * @param gc giftcard code
798
+ * @param gc gift card code
797
799
  * @param op operation
798
800
  * @param ot original transaction in case of refund
799
801
  * @param unixTimestampOrMilliseconds
@@ -851,6 +853,7 @@ declare class SmpCommonUtils {
851
853
  static assertIsTruthy<T>(condition: T, withMessage?: string): asserts condition;
852
854
  static buildPath(...args: any[]): string;
853
855
  static downloadBlob(blob: Blob, filename: string): void;
856
+ static fixDecimalPrecision(value: number, precision?: number): number;
854
857
  static generateRandomHexString(length?: number): string;
855
858
  static generateUUID(): string;
856
859
  static getDecimalPrecision(val: number | string): number;
@@ -987,6 +990,6 @@ declare class SmpInMemoryCache extends SmpAbstractTtlCacheStrategy {
987
990
  */
988
991
  declare function smpIsSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
989
992
 
990
- declare const VERSION: "2.0.0-beta.5";
993
+ declare const VERSION: "2.0.0-beta.6";
991
994
 
992
995
  export { SMP_HEALTHZ, SmpAbstractCacheStrategy, SmpAbstractTtlCacheStrategy, SmpAesCrypt, SmpApiCommonUtils, SmpBaseJwtToken, SmpBaseJwtTokenPlain, SmpBrowserCache, SmpCachedValue, SmpCommonUtils, SmpCrypto, type SmpDynamicFetchReturn, SmpErrorResponse, type SmpErrorResponseCreateOpts, SmpFilterException, type SmpGenericConstructor, SmpGenericResponse, SmpGenericResponseBase, type SmpGenericResponseCreateOpts, SmpGiftcardTransaction, type SmpGiftcardTransactionConfig, SmpGiftcardTransactionHashStrategies, SmpGiftcardTransactionOps, type SmpGiftcardTransactionPlain, SmpHttpSessionStorageCache, SmpHttpStatusCodes, type SmpHttpTwoConfig, SmpHttpTwoService, SmpInMemoryCache, type SmpMarketingCloudValidationResponse, type SmpMarketingCloudValidationResponseKo, type SmpMarketingCloudValidationResponseOk, SmpMarketingCloudValidators, type SmpPrimitive, SmpRegularExpressions, SmpResponseMessage, SmpResponseMessageTypes, SmpRestVerbs, SmpSecureCode, SmpSid, type SmpWithDateTimeAsDate, VERSION, smpApplyMixin, smpIsSmpCachedValue };
package/dist/cjs/rxjs.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var s=(t,r)=>f(t,"name",{value:r,configurable:!0});var C=(t,r)=>{for(var e in r)f(t,e,{get:r[e],enumerable:!0})},N=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of j(r))!E.call(t,n)&&n!==e&&f(t,n,{get:()=>r[n],enumerable:!(o=b(r,n))||o.enumerable});return t};var O=t=>N(f({},"__esModule",{value:!0}),t);var $={};C($,{SmpAbstractRxjsTtlCacheStrategy:()=>a,SmpRxjsInMemoryCache:()=>x,smpRxjsCatchOnly:()=>I,smpRxjsQueue:()=>T,smpRxjsSequence:()=>V,smpRxjsThrowIfEmpty:()=>y,smpRxjsThrowOnCondition:()=>M});module.exports=O($);var d=require("rxjs"),_=require("ts-luxon");var m=class{static{s(this,"SmpAbstractCacheStrategy")}};function R(t){return typeof t=="object"&&t!==null&&"value"in t&&"expiry"in t&&typeof t.expiry=="number"}s(R,"smpIsSmpCachedValue");var a=class extends m{static{s(this,"SmpAbstractRxjsTtlCacheStrategy")}flush(){return this._flushRaw()}read(r){return this._readRaw(r).pipe((0,d.map)(e=>{if(this._isSmpCachedValue(e)){if(e.expiry>=_.DateTime.now().ts)return e.value;this._removeRaw(r).subscribe();return}return e}))}remove(r){return this._removeRaw(r)}write(r,e,o){let n;if(isNaN(+o)||+o<=0)n=this._writeRaw(r,e,o);else{let c=_.DateTime.now().ts+o*1e3,w={value:e,expiry:c};n=this._writeRaw(r,w,o)}return n.subscribe({error:s(c=>console.error(`${this.constructor.name}::write: error occurred`,c),"error")}),n}_isSmpCachedValue(r){return R(r)}};var h=require("rxjs");function I(t,r){return e=>e.pipe((0,h.catchError)(o=>(typeof t==typeof isNaN?v(t)?A(o,t):t(o):!1)?r(o):(0,h.throwError)(()=>o)))}s(I,"smpRxjsCatchOnly");function v(t){try{return Reflect.construct(String,[],t),!0}catch{return!1}}s(v,"isConstructor");function A(t,r){return typeof t=="object"&&t!==null&&t.constructor===r}s(A,"isExactInstance");var u=require("rxjs");var x=class extends a{static{s(this,"SmpRxjsInMemoryCache")}static _storage=new Map;get _staticSelf(){return this.constructor}_flushRaw(){return this._staticSelf._storage.clear(),(0,u.of)(void 0)}_readRaw(r){return(0,u.of)(this._staticSelf._storage.get(r))}_removeRaw(r){return this._staticSelf._storage.delete(r),(0,u.of)(void 0)}_writeRaw(r,e){return this._staticSelf._storage.set(r,e),(0,u.of)(void 0)}};var i=require("rxjs");function S(t){let r=[];function e(o){return o>=t.length?(0,i.of)(r):(0,i.defer)(()=>t[o]()).pipe((0,i.switchMap)(n=>(r[o]=n,e(o+1))))}return s(e,"runStep"),e(0)}s(S,"smpRxjsSequence");function T(t){if(Array.isArray(t))return S(t);{let r=Object.keys(t),e=r.map(o=>t[o]);return S(e).pipe((0,i.map)(o=>{let n={};return r.forEach((c,w)=>{n[c]=o[w]}),n}))}}s(T,"smpRxjsQueue");var p=require("rxjs");function V(t){return(0,p.from)(t).pipe((0,p.concatMap)(e=>e()),(0,p.toArray)())}s(V,"smpRxjsSequence");var g=require("rxjs");function y(t=J){return r=>r.pipe((0,g.map)(e=>{if(~q.indexOf(JSON.stringify(e)))throw t(e);return e}))}s(y,"smpRxjsThrowIfEmpty");var q=[void 0,null,!1,0,"","0",[],{}].map(t=>JSON.stringify(t)),J=s(()=>new Error,"defaultErrorFactory");var l=require("rxjs");function M(t,r){return e=>e.pipe((0,l.filter)(o=>!t(o)),(0,l.defaultIfEmpty)(!1),y(r))}s(M,"smpRxjsThrowOnCondition");0&&(module.exports={SmpAbstractRxjsTtlCacheStrategy,SmpRxjsInMemoryCache,smpRxjsCatchOnly,smpRxjsQueue,smpRxjsSequence,smpRxjsThrowIfEmpty,smpRxjsThrowOnCondition});
1
+ "use strict";var a=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var s=(r,t)=>a(r,"name",{value:t,configurable:!0});var N=(r,t)=>{for(var e in t)a(r,e,{get:t[e],enumerable:!0})},A=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of I(t))!T.call(r,n)&&n!==e&&a(r,n,{get:()=>t[n],enumerable:!(o=O(t,n))||o.enumerable});return r};var v=r=>A(a({},"__esModule",{value:!0}),r);var Q={};N(Q,{SmpAbstractRxjsTtlCacheStrategy:()=>c,SmpRxjsInMemoryCache:()=>x,smpRxjsCatchOnly:()=>S,smpRxjsQueue:()=>g,smpRxjsSequence:()=>b,smpRxjsThrowIfEmpty:()=>l,smpRxjsThrowOnCondition:()=>E});module.exports=v(Q);var d=require("rxjs"),R=require("ts-luxon");var u=class{static{s(this,"SmpAbstractCacheStrategy")}};function _(r){return typeof r=="object"&&r!==null&&"value"in r&&"expiry"in r&&typeof r.expiry=="number"}s(_,"smpIsSmpCachedValue");var c=class extends u{static{s(this,"SmpAbstractRxjsTtlCacheStrategy")}flush(){return this._flushRaw()}read(t){return this._readRaw(t).pipe((0,d.map)(e=>{if(this._isSmpCachedValue(e)){if(e.expiry>=R.DateTime.now().ts)return e.value;this._removeRaw(t).subscribe();return}return e}))}remove(t){return this._removeRaw(t)}write(t,e,o){let n;if(isNaN(+o)||+o<=0)n=this._writeRaw(t,e,o);else{let m=R.DateTime.now().ts+o*1e3,y={value:e,expiry:m};n=this._writeRaw(t,y,o)}return n.subscribe({error:s(m=>console.error(`${this.constructor.name}::write: error occurred`,m),"error")}),n}_isSmpCachedValue(t){return _(t)}};var h=require("rxjs");function S(r,t){return e=>e.pipe((0,h.catchError)(o=>(typeof r==typeof isNaN?q(r)?M(o,r):r(o):!1)?t(o):(0,h.throwError)(()=>o)))}s(S,"smpRxjsCatchOnly");function q(r){try{return Reflect.construct(String,[],r),!0}catch{return!1}}s(q,"isConstructor");function M(r,t){return typeof r=="object"&&r!==null&&r.constructor===t}s(M,"isExactInstance");var i=require("rxjs");var x=class extends c{static{s(this,"SmpRxjsInMemoryCache")}static _storage=new Map;get _staticSelf(){return this.constructor}_flushRaw(){return(0,i.defer)(()=>(this._staticSelf._storage.clear(),(0,i.of)(void 0)))}_readRaw(t){return(0,i.defer)(()=>(0,i.of)(this._staticSelf._storage.get(t)))}_removeRaw(t){return(0,i.defer)(()=>(this._staticSelf._storage.delete(t),(0,i.of)(void 0)))}_writeRaw(t,e){return this._staticSelf._storage.set(t,e),(0,i.of)(void 0)}};var p=require("rxjs");function j(r){let t=[];function e(o){return o>=r.length?(0,p.of)(t):(0,p.defer)(()=>r[o]()).pipe((0,p.switchMap)(n=>(t[o]=n,e(o+1))))}return s(e,"runStep"),e(0)}s(j,"smpRxjsSequence");function g(r){if(Array.isArray(r))return j(r);{let t=Object.keys(r),e=t.map(o=>r[o]);return j(e).pipe((0,p.map)(o=>{let n={};return t.forEach((m,y)=>{n[m]=o[y]}),n}))}}s(g,"smpRxjsQueue");var f=require("rxjs");function b(r){return(0,f.from)(r).pipe((0,f.concatMap)(e=>e()),(0,f.toArray)())}s(b,"smpRxjsSequence");var C=require("rxjs");function l(r=J){return t=>t.pipe((0,C.map)(e=>{if(~V.indexOf(JSON.stringify(e)))throw r(e);return e}))}s(l,"smpRxjsThrowIfEmpty");var V=[void 0,null,!1,0,"","0",[],{}].map(r=>JSON.stringify(r)),J=s(()=>new Error,"defaultErrorFactory");var w=require("rxjs");function E(r,t){return e=>e.pipe((0,w.filter)(o=>!r(o)),(0,w.defaultIfEmpty)(!1),l(t))}s(E,"smpRxjsThrowOnCondition");0&&(module.exports={SmpAbstractRxjsTtlCacheStrategy,SmpRxjsInMemoryCache,smpRxjsCatchOnly,smpRxjsQueue,smpRxjsSequence,smpRxjsThrowIfEmpty,smpRxjsThrowOnCondition});
2
2
  //# sourceMappingURL=rxjs.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/rxjs.ts","../../src/shared/rxjs/smp-abstract-rxjs-ttl-cache-strategy.class.ts","../../src/shared/utils/cache/smp-abstract-cache-strategy.class.ts","../../src/shared/utils/cache/smp-is-smp-cached-value.function.ts","../../src/shared/rxjs/smp-rxjs-catch-only.function.ts","../../src/shared/rxjs/smp-rxjs-in-memory-cache.class.ts","../../src/shared/rxjs/smp-rxjs-queue.function.ts","../../src/shared/rxjs/smp-rxjs-sequence.function.ts","../../src/shared/rxjs/smp-rxjs-throw-if-empty.function.ts","../../src/shared/rxjs/smp-rxjs-throw-on-condition.function.ts"],"sourcesContent":["export * from \"./shared/rxjs/index.js\";\n","import {map, Observable} from \"rxjs\";\nimport {DateTime} from \"ts-luxon\";\n//\nimport {SmpAbstractCacheStrategy} from \"../utils/cache/smp-abstract-cache-strategy.class.js\";\nimport {SmpCachedValue} from \"../utils/cache/smp-cached-value.interface.js\";\nimport {smpIsSmpCachedValue} from \"../utils/cache/smp-is-smp-cached-value.function.js\";\n\nexport abstract class SmpAbstractRxjsTtlCacheStrategy extends SmpAbstractCacheStrategy {\n\n protected abstract _flushRaw(): Observable<void>;\n\n protected abstract _readRaw(key: string): Observable<unknown | undefined>;\n\n protected abstract _removeRaw(key: string): Observable<void>;\n\n protected abstract _writeRaw(key: string, value: unknown, ttl?: number): Observable<void>;\n\n flush(): Observable<void> {\n return this._flushRaw();\n }\n\n read<T = any>(key: string): Observable<T | undefined> {\n return this._readRaw(key).pipe(\n map((storedValue) => {\n if (this._isSmpCachedValue<T>(storedValue)) {\n if (storedValue.expiry >= DateTime.now().ts) {\n return storedValue.value as T;\n }\n this._removeRaw(key).subscribe(); // fire-and-forget\n\n return void 0;\n }\n\n return storedValue as T | undefined;\n })\n );\n }\n\n remove(key: string) {\n return this._removeRaw(key);\n }\n\n write<T = any>(key: string, value: T, ttl?: number): Observable<void> {\n let obs$: Observable<void>;\n\n if (isNaN(+ttl!) || +ttl! <= 0) {\n obs$ = this._writeRaw(key, value, ttl);\n }\n else {\n const expiry = DateTime.now().ts + ttl! * 1000;\n const wrappedValue: SmpCachedValue<T> = {\n value,\n expiry\n };\n obs$ = this._writeRaw(key, wrappedValue, ttl);\n }\n\n // Fire-and-forget\n obs$.subscribe({\n error: (err) => console.error(`${this.constructor.name}::write: error occurred`, err)\n });\n\n return obs$;\n }\n\n protected _isSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T> {\n return smpIsSmpCachedValue(value);\n }\n}\n","import {Observable} from \"rxjs\";\n\n/**\n * Abstract class representing a caching strategy. This class is intended to be extended by concrete implementations\n * and provides an interface for performing common caching operations such as reading, writing, removing, and flushing cache entries.\n * You shouldn't need to implement this: you can go with SmpAbstractTtlCacheStrategy or SmpRxjsAbstractCacheStrategy, depending on what type of cache you want to implement.\n * For instance, for a local cache, you may stay sync, while for a Valkey cache, you should start with the rxjs.\n */\nexport abstract class SmpAbstractCacheStrategy {\n abstract read<T = any>(key: string): T | undefined | Observable<T | undefined>;\n\n abstract write<T = any>(key: string, value: T, ttl?: number): void | Observable<void>;\n\n abstract remove(key: string): void | Observable<void>;\n\n abstract flush(): void | Observable<void>;\n}\n","import {SmpCachedValue} from \"./smp-cached-value.interface.js\";\n\n/**\n * Tells you if a value is a SmpCachedValue\n * @param value\n */\nexport function smpIsSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"value\" in value &&\n \"expiry\" in value &&\n typeof (value as any).expiry === \"number\"\n );\n}\n","import {Observable, OperatorFunction, catchError, throwError} from \"rxjs\";\nimport type {ObservableInput, ObservedValueOf} from \"rxjs\";\n\nexport function smpRxjsCatchOnly<T, E extends Error, O extends ObservableInput<any>>(\n errorFilter: (new (...args: any[]) => E) | ((err: unknown) => boolean),\n selector: (err: E) => O\n): OperatorFunction<T, T | ObservedValueOf<O>> {\n return (source: Observable<T>) =>\n source.pipe(\n catchError((err: unknown) => {\n const matches = typeof errorFilter === typeof isNaN\n ? isConstructor(errorFilter)\n ? isExactInstance(err, errorFilter as new (...args: any[]) => E)\n : (errorFilter as (err: unknown) => boolean)(err)\n : false;\n\n if (matches) {\n return selector(err as E);\n }\n return throwError(() => err);\n })\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nfunction isConstructor(fn: unknown): fn is Function {\n try {\n // try creating a dummy instance\n Reflect.construct(String, [], fn as any);\n return true;\n }\n catch {\n return false;\n }\n}\n\n// Ensures that the error is an *exact* instance of the given error constructor, not a subclass\nfunction isExactInstance<E extends Error>(err: unknown, ctor: new (...args: any[]) => E): boolean {\n return (\n typeof err === \"object\" &&\n err !== null &&\n err.constructor === ctor\n );\n}\n","import {defer, Observable, of} from \"rxjs\";\n//\nimport {SmpAbstractRxjsTtlCacheStrategy} from \"./smp-abstract-rxjs-ttl-cache-strategy.class.js\";\n\nexport class SmpRxjsInMemoryCache extends SmpAbstractRxjsTtlCacheStrategy {\n\n private static _storage = new Map<string, any>();\n\n protected get _staticSelf(): typeof SmpRxjsInMemoryCache {\n return this.constructor as typeof SmpRxjsInMemoryCache;\n }\n\n protected _flushRaw(): Observable<void> {\n this._staticSelf._storage.clear();\n\n return of(void 0);\n }\n\n protected _readRaw(key: string): Observable<any | undefined> {\n return of(this._staticSelf._storage.get(key));\n }\n\n protected _removeRaw(key: string): Observable<void> {\n this._staticSelf._storage.delete(key);\n\n return of(void 0);\n }\n\n protected _writeRaw(key: string, value: any): Observable<void> {\n this._staticSelf._storage.set(key, value);\n\n return of(void 0);\n }\n}\n\n","import {map, Observable, of, defer, switchMap} from \"rxjs\";\n\nfunction smpRxjsSequence<T extends any[]>(steps: { [K in keyof T]: () => Observable<T[K]> }): Observable<T> {\n const results: Partial<T>[] = [];\n\n function runStep(index: number): Observable<T> {\n if (index >= steps.length) {\n return of(results as T);\n }\n\n return defer(() => steps[index]()).pipe(\n switchMap((value) => {\n results[index] = value;\n return runStep(index + 1);\n })\n );\n }\n\n return runStep(0);\n}\n\n// Overloads for array or object input\ntype ObsFnMap = Record<string, () => Observable<any>>;\n\nexport function smpRxjsQueue<T extends any[]>(source: { [K in keyof T]: () => Observable<T[K]> }): Observable<T>;\nexport function smpRxjsQueue<T extends ObsFnMap>(source: T): Observable<{ [K in keyof T]: T[K] extends () => Observable<infer U> ? U : never }>;\nexport function smpRxjsQueue(\n source: (() => Observable<any>)[] | ObsFnMap\n): Observable<any> {\n if (Array.isArray(source)) {\n // use a strongly typed sequence for the array of steps\n return smpRxjsSequence(source as any);\n }\n else {\n // for object, convert values, then reconstruct object mapping with correct types\n const keys = Object.keys(source);\n const stepsArray = keys.map((key) => source[key]);\n\n return smpRxjsSequence(stepsArray as any).pipe(\n map((results: any[]) => {\n const acc: any = {};\n keys.forEach((key, i) => {\n acc[key] = results[i];\n });\n return acc;\n })\n );\n }\n}\n\n\n","import {concatMap, from, Observable, toArray} from \"rxjs\";\n\n/**\n * Old version of the sequence. Now rewritten using recursion, which is way faster.\n * But you can use this if you want to stick with the rxjs pattern\n * @param steps\n */\nexport function smpRxjsSequence<T extends any[]>(\n steps: { [K in keyof T]: () => Observable<T[K]> }\n): Observable<T> {\n // Cast to readonly tuple of functions to keep tuple inference\n const stepFunctions = steps as readonly (() => Observable<T[number]>)[];\n\n return from(stepFunctions).pipe(\n concatMap(step => step()),\n toArray()\n // TS loses tuple typing here, so we cast the result back to T\n // This cast is safe because we control the input and ordering\n ) as Observable<T>;\n}\n","import {map, Observable, OperatorFunction} from \"rxjs\";\n\n/**\n * If the source observable completes emitting an empty value (empty array or object will be considered empty), it will emit\n * an error. The error will be created at that time by the optional\n * `errorFactory` argument, otherwise, the error will be {@link Error}.\n *\n * ## Example\n *\n * Throw an error if the query didn't match anything\n *\n * ```ts\n * import { of, takeUntil, timer, throwIfEmpty } from 'rxjs';\n *\n * const query$ = of([]);\n *\n * query$.pipe(\n * smpRxjsThrowIfEmpty(() => new Error('The query had no results'))\n * )\n * .subscribe({\n * next() {\n * console.log(\"The query had results\");\n * },\n * error(err) {\n * console.error(err.message);\n * }\n * });\n * ```\n *\n * @param errorFactory A factory function called to produce the\n * error to be thrown when the source observable completes without emitting a\n * value.\n * @return A function that returns an Observable that throws an error if the\n * source Observable completed without emitting.\n */\nexport function smpRxjsThrowIfEmpty<T>(errorFactory: (value: T) => any = defaultErrorFactory): OperatorFunction<T, T> {\n return (source: Observable<T>) => source.pipe(\n map(v => {\n if (~emptyValues.indexOf(JSON.stringify(v))) {\n throw errorFactory(v);\n }\n\n return v;\n })\n );\n}\n\nconst emptyValues = [void 0, null, false, 0, \"\", \"0\", [], {}].map((v) =>\n JSON.stringify(v)\n);\n\nconst defaultErrorFactory = (): Error => new Error();\n","import {defaultIfEmpty, filter, Observable, OperatorFunction} from \"rxjs\";\n//\nimport {smpRxjsThrowIfEmpty} from \"./smp-rxjs-throw-if-empty.function.js\";\n\n/**\n * Custom RxJS operator that filters the source observable based on a condition\n * and throws an error if the resulting observable is empty.\n *\n * @template T The type of items emitted by the source observable.\n * @param {function(T): boolean} condition - A function that takes a value from the source observable and returns a boolean.\n * If the function returns `true`, the value will be emitted; otherwise, it will be filtered out.\n * @param {function(): Error} [errorFactory] - An optional function that returns an error to be thrown if the resulting observable is empty.\n * If not provided, a default error will be thrown.\n * @returns {OperatorFunction<T, T>} An operator function that can be used in the RxJS pipeline.\n *\n * @example\n * import { of } from 'rxjs';\n * import { smpRxjsThrowOnCondition } from \"./path-to-your-file\";\n *\n * const source$ = of(1, 5, -3, 7, 12).pipe(\n * smpRxjsThrowOnCondition(value => value >= 0, () => new Error(\"Value is less than 0\")),\n * smpRxjsThrowOnCondition(value => value > 12, () => new Error(\"Value is lower than 12\"))\n * );\n *\n * source$.subscribe({\n * next: value => console.log(\"Value:\", value),\n * error: err => console.error(\"Error:\", err)\n * });\n */\nexport function smpRxjsThrowOnCondition<T>(\n condition: (value: T) => boolean,\n errorFactory?: (value: T) => any\n): OperatorFunction<T, T> {\n return (source: Observable<T>) =>\n source.pipe(\n filter((v: T) => !condition(v)), // Invert the condition because if I need to throw on that condition we should filter all that don't match\n defaultIfEmpty(false as unknown as T), // We nuke type errors, cause when falsy smpRxjsThrowIfEmpty will throw\n smpRxjsThrowIfEmpty(errorFactory)\n );\n}\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,EAAA,yBAAAC,EAAA,qBAAAC,EAAA,iBAAAC,EAAA,oBAAAC,EAAA,wBAAAC,EAAA,4BAAAC,IAAA,eAAAC,EAAAT,GCAA,IAAAU,EAA8B,gBAC9BC,EAAuB,oBCOhB,IAAeC,EAAf,KAAeA,CANtB,MAMsBA,CAAAA,EAAAA,iCAQtB,ECVO,SAASC,EAAuBC,EAAc,CACjD,OACI,OAAOA,GAAU,UACjBA,IAAU,MACV,UAAWA,GACX,WAAYA,GACZ,OAAQA,EAAcC,QAAW,QAEzC,CARgBF,EAAAA,EAAAA,uBFCT,IAAeG,EAAf,cAAuDC,CAAAA,CAP9D,MAO8DA,CAAAA,EAAAA,wCAU1DC,OAA0B,CACtB,OAAO,KAAKC,UAAS,CACzB,CAEAC,KAAcC,EAAwC,CAClD,OAAO,KAAKC,SAASD,CAAAA,EAAKE,QACtBC,OAAKC,GAAAA,CACD,GAAI,KAAKC,kBAAqBD,CAAAA,EAAc,CACxC,GAAIA,EAAYE,QAAUC,WAASC,IAAG,EAAGC,GACrC,OAAOL,EAAYM,MAEvB,KAAKC,WAAWX,CAAAA,EAAKY,UAAS,EAE9B,MACJ,CAEA,OAAOR,CACX,CAAA,CAAA,CAER,CAEAS,OAAOb,EAAa,CAChB,OAAO,KAAKW,WAAWX,CAAAA,CAC3B,CAEAc,MAAed,EAAaU,EAAUK,EAAgC,CAClE,IAAIC,EAEJ,GAAIC,MAAM,CAACF,CAAAA,GAAS,CAACA,GAAQ,EACzBC,EAAO,KAAKE,UAAUlB,EAAKU,EAAOK,CAAAA,MAEjC,CACD,IAAMT,EAASC,W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AAgD,gBAmCzC,SAASC,EAAuBC,EAAkCC,EAAmB,CACxF,OAAQC,GAA0BA,EAAOC,QACrCC,OAAIC,GAAAA,CACA,GAAI,CAACC,EAAYC,QAAQC,KAAKC,UAAUJ,CAAAA,CAAAA,EACpC,MAAML,EAAaK,CAAAA,EAGvB,OAAOA,CACX,CAAA,CAAA,CAER,CAVgBN,EAAAA,EAAAA,uBAYhB,IAAMO,EAAc,CAAC,OAAQ,KAAM,GAAO,EAAG,GAAI,IAAK,CAAA,EAAI,CAAC,GAAGF,IAAKC,GAC/DG,KAAKC,UAAUJ,CAAAA,CAAAA,EAGbJ,EAAsBS,EAAA,IAAa,IAAIC,MAAjB,uBCnD5B,IAAAC,EAAmE,gBA6B5D,SAASC,EACZC,EACAC,EAAgC,CAEhC,OAAQC,GACJA,EAAOC,QACHC,UAAQC,GAAS,CAACL,EAAUK,CAAAA,CAAAA,KAC5BC,kBAAe,EAAA,EACfC,EAAoBN,CAAAA,CAAAA,CAEhC,CAVgBF,EAAAA,EAAAA","names":["rxjs_exports","__export","SmpAbstractRxjsTtlCacheStrategy","SmpRxjsInMemoryCache","smpRxjsCatchOnly","smpRxjsQueue","smpRxjsSequence","smpRxjsThrowIfEmpty","smpRxjsThrowOnCondition","__toCommonJS","import_rxjs","import_ts_luxon","SmpAbstractCacheStrategy","smpIsSmpCachedValue","value","expiry","SmpAbstractRxjsTtlCacheStrategy","SmpAbstractCacheStrategy","flush","_flushRaw","read","key","_readRaw","pipe","map","storedValue","_isSmpCachedValue","expiry","DateTime","now","ts","value","_removeRaw","subscribe","remove","write","ttl","obs$","isNaN","_writeRaw","wrappedValue","error","__name","err","console","name","smpIsSmpCachedValue","import_rxjs","smpRxjsCatchOnly","errorFilter","selector","source","pipe","catchError","err","isNaN","isConstructor","isExactInstance","throwError","fn","Reflect","construct","String","ctor","import_rxjs","SmpRxjsInMemoryCache","SmpAbstractRxjsTtlCacheStrategy","_storage","Map","_staticSelf","_flushRaw","clear","of","_readRaw","key","get","_removeRaw","delete","_writeRaw","value","set","import_rxjs","smpRxjsSequence","steps","results","runStep","index","length","of","defer","pipe","switchMap","value","smpRxjsQueue","source","Array","isArray","keys","Object","stepsArray","map","key","acc","forEach","i","import_rxjs","smpRxjsSequence","steps","from","stepFunctions","pipe","concatMap","step","toArray","import_rxjs","smpRxjsThrowIfEmpty","errorFactory","defaultErrorFactory","source","pipe","map","v","emptyValues","indexOf","JSON","stringify","__name","Error","import_rxjs","smpRxjsThrowOnCondition","condition","errorFactory","source","pipe","filter","v","defaultIfEmpty","smpRxjsThrowIfEmpty"]}
1
+ {"version":3,"sources":["../../src/rxjs.ts","../../src/shared/rxjs/smp-abstract-rxjs-ttl-cache-strategy.class.ts","../../src/shared/utils/cache/smp-abstract-cache-strategy.class.ts","../../src/shared/utils/cache/smp-is-smp-cached-value.function.ts","../../src/shared/rxjs/smp-rxjs-catch-only.function.ts","../../src/shared/rxjs/smp-rxjs-in-memory-cache.class.ts","../../src/shared/rxjs/smp-rxjs-queue.function.ts","../../src/shared/rxjs/smp-rxjs-sequence.function.ts","../../src/shared/rxjs/smp-rxjs-throw-if-empty.function.ts","../../src/shared/rxjs/smp-rxjs-throw-on-condition.function.ts"],"sourcesContent":["export * from \"./shared/rxjs/index.js\";\n","import {map, Observable} from \"rxjs\";\nimport {DateTime} from \"ts-luxon\";\n//\nimport {SmpAbstractCacheStrategy} from \"../utils/cache/smp-abstract-cache-strategy.class.js\";\nimport {SmpCachedValue} from \"../utils/cache/smp-cached-value.interface.js\";\nimport {smpIsSmpCachedValue} from \"../utils/cache/smp-is-smp-cached-value.function.js\";\n\nexport abstract class SmpAbstractRxjsTtlCacheStrategy extends SmpAbstractCacheStrategy {\n\n protected abstract _flushRaw(): Observable<void>;\n\n protected abstract _readRaw(key: string): Observable<unknown | undefined>;\n\n protected abstract _removeRaw(key: string): Observable<void>;\n\n protected abstract _writeRaw(key: string, value: unknown, ttl?: number): Observable<void>;\n\n flush(): Observable<void> {\n return this._flushRaw();\n }\n\n read<T = unknown>(key: string): Observable<T | undefined> {\n return this._readRaw(key).pipe(\n map((storedValue) => {\n if (this._isSmpCachedValue<T>(storedValue)) {\n if (storedValue.expiry >= DateTime.now().ts) {\n return storedValue.value as T;\n }\n this._removeRaw(key).subscribe(); // fire-and-forget\n\n return void 0;\n }\n\n return storedValue as T | undefined;\n })\n );\n }\n\n remove(key: string) {\n return this._removeRaw(key);\n }\n\n write<T = any>(key: string, value: T, ttl?: number): Observable<void> {\n let obs$: Observable<void>;\n\n if (isNaN(+ttl!) || +ttl! <= 0) {\n obs$ = this._writeRaw(key, value, ttl);\n }\n else {\n const expiry = DateTime.now().ts + ttl! * 1000;\n const wrappedValue: SmpCachedValue<T> = {\n value,\n expiry\n };\n obs$ = this._writeRaw(key, wrappedValue, ttl);\n }\n\n // Fire-and-forget\n obs$.subscribe({\n error: (err) => console.error(`${this.constructor.name}::write: error occurred`, err)\n });\n\n return obs$;\n }\n\n protected _isSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T> {\n return smpIsSmpCachedValue(value);\n }\n}\n","import {Observable} from \"rxjs\";\n\n/**\n * Abstract class representing a caching strategy. This class is intended to be extended by concrete implementations\n * and provides an interface for performing common caching operations such as reading, writing, removing, and flushing cache entries.\n * You shouldn't need to implement this: you can go with SmpAbstractTtlCacheStrategy or SmpRxjsAbstractCacheStrategy, depending on what type of cache you want to implement.\n * For instance, for a local cache, you may stay sync, while for a Valkey cache, you should start with the rxjs.\n */\nexport abstract class SmpAbstractCacheStrategy {\n abstract read<T = unknown>(key: string): T | undefined | Observable<T | undefined>;\n\n abstract write<T = unknown>(key: string, value: T, ttl?: number): void | Observable<void>;\n\n abstract remove(key: string): void | Observable<void>;\n\n abstract flush(): void | Observable<void>;\n}\n","import {SmpCachedValue} from \"./smp-cached-value.interface.js\";\n\n/**\n * Tells you if a value is a SmpCachedValue\n * @param value\n */\nexport function smpIsSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"value\" in value &&\n \"expiry\" in value &&\n typeof (value as any).expiry === \"number\"\n );\n}\n","import {Observable, OperatorFunction, catchError, throwError} from \"rxjs\";\nimport type {ObservableInput, ObservedValueOf} from \"rxjs\";\n\nexport function smpRxjsCatchOnly<T, E extends Error, O extends ObservableInput<any>>(\n errorFilter: (new (...args: any[]) => E) | ((err: unknown) => boolean),\n selector: (err: E) => O\n): OperatorFunction<T, T | ObservedValueOf<O>> {\n return (source: Observable<T>) =>\n source.pipe(\n catchError((err: unknown) => {\n const matches = typeof errorFilter === typeof isNaN\n ? isConstructor(errorFilter)\n ? isExactInstance(err, errorFilter as new (...args: any[]) => E)\n : (errorFilter as (err: unknown) => boolean)(err)\n : false;\n\n if (matches) {\n return selector(err as E);\n }\n return throwError(() => err);\n })\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nfunction isConstructor(fn: unknown): fn is Function {\n try {\n // try creating a dummy instance\n Reflect.construct(String, [], fn as any);\n return true;\n }\n catch {\n return false;\n }\n}\n\n// Ensures that the error is an *exact* instance of the given error constructor, not a subclass\nfunction isExactInstance<E extends Error>(err: unknown, ctor: new (...args: any[]) => E): boolean {\n return (\n typeof err === \"object\" &&\n err !== null &&\n err.constructor === ctor\n );\n}\n","import {defer, Observable, of} from \"rxjs\";\n//\nimport {SmpAbstractRxjsTtlCacheStrategy} from \"./smp-abstract-rxjs-ttl-cache-strategy.class.js\";\n\nexport class SmpRxjsInMemoryCache extends SmpAbstractRxjsTtlCacheStrategy {\n\n private static _storage = new Map<string, unknown>();\n\n protected get _staticSelf(): typeof SmpRxjsInMemoryCache {\n return this.constructor as typeof SmpRxjsInMemoryCache;\n }\n\n protected _flushRaw(): Observable<void> {\n return defer(() => {\n this._staticSelf._storage.clear();\n\n return of(void 0);\n });\n }\n\n protected _readRaw(key: string): Observable<unknown | undefined> {\n return defer(() => {\n\n return of(this._staticSelf._storage.get(key));\n });\n }\n\n protected _removeRaw(key: string): Observable<void> {\n return defer(() => {\n this._staticSelf._storage.delete(key);\n\n return of(void 0);\n });\n }\n\n protected _writeRaw(key: string, value: any): Observable<void> {\n this._staticSelf._storage.set(key, value);\n\n return of(void 0);\n }\n}\n\n","import {map, Observable, of, defer, switchMap} from \"rxjs\";\n\nfunction smpRxjsSequence<T extends any[]>(steps: { [K in keyof T]: () => Observable<T[K]> }): Observable<T> {\n const results: Partial<T>[] = [];\n\n function runStep(index: number): Observable<T> {\n if (index >= steps.length) {\n return of(results as T);\n }\n\n return defer(() => steps[index]()).pipe(\n switchMap((value) => {\n results[index] = value;\n return runStep(index + 1);\n })\n );\n }\n\n return runStep(0);\n}\n\n// Overloads for array or object input\ntype ObsFnMap = Record<string, () => Observable<any>>;\n\nexport function smpRxjsQueue<T extends any[]>(source: { [K in keyof T]: () => Observable<T[K]> }): Observable<T>;\nexport function smpRxjsQueue<T extends ObsFnMap>(source: T): Observable<{ [K in keyof T]: T[K] extends () => Observable<infer U> ? U : never }>;\nexport function smpRxjsQueue(\n source: (() => Observable<any>)[] | ObsFnMap\n): Observable<any> {\n if (Array.isArray(source)) {\n // use a strongly typed sequence for the array of steps\n return smpRxjsSequence(source as any);\n }\n else {\n // for object, convert values, then reconstruct object mapping with correct types\n const keys = Object.keys(source);\n const stepsArray = keys.map((key) => source[key]);\n\n return smpRxjsSequence(stepsArray as any).pipe(\n map((results: any[]) => {\n const acc: any = {};\n keys.forEach((key, i) => {\n acc[key] = results[i];\n });\n return acc;\n })\n );\n }\n}\n\n\n","import {concatMap, from, Observable, toArray} from \"rxjs\";\n\n/**\n * Old version of the sequence. Now rewritten using recursion, which is way faster.\n * But you can use this if you want to stick with the rxjs pattern\n * @param steps\n */\nexport function smpRxjsSequence<T extends any[]>(\n steps: { [K in keyof T]: () => Observable<T[K]> }\n): Observable<T> {\n // Cast to readonly tuple of functions to keep tuple inference\n const stepFunctions = steps as readonly (() => Observable<T[number]>)[];\n\n return from(stepFunctions).pipe(\n concatMap(step => step()),\n toArray()\n // TS loses tuple typing here, so we cast the result back to T\n // This cast is safe because we control the input and ordering\n ) as Observable<T>;\n}\n","import {map, Observable, OperatorFunction} from \"rxjs\";\n\n/**\n * If the source observable completes emitting an empty value (empty array or object will be considered empty), it will emit\n * an error. The error will be created at that time by the optional\n * `errorFactory` argument, otherwise, the error will be {@link Error}.\n *\n * ## Example\n *\n * Throw an error if the query didn't match anything\n *\n * ```ts\n * import { of, takeUntil, timer, throwIfEmpty } from 'rxjs';\n *\n * const query$ = of([]);\n *\n * query$.pipe(\n * smpRxjsThrowIfEmpty(() => new Error('The query had no results'))\n * )\n * .subscribe({\n * next() {\n * console.log(\"The query had results\");\n * },\n * error(err) {\n * console.error(err.message);\n * }\n * });\n * ```\n *\n * @param errorFactory A factory function called to produce the\n * error to be thrown when the source observable completes without emitting a\n * value.\n * @return A function that returns an Observable that throws an error if the\n * source Observable completed without emitting.\n */\nexport function smpRxjsThrowIfEmpty<T>(errorFactory: (value: T) => any = defaultErrorFactory): OperatorFunction<T, T> {\n return (source: Observable<T>) => source.pipe(\n map(v => {\n if (~emptyValues.indexOf(JSON.stringify(v))) {\n throw errorFactory(v);\n }\n\n return v;\n })\n );\n}\n\nconst emptyValues = [void 0, null, false, 0, \"\", \"0\", [], {}].map((v) =>\n JSON.stringify(v)\n);\n\nconst defaultErrorFactory = (): Error => new Error();\n","import {defaultIfEmpty, filter, Observable, OperatorFunction} from \"rxjs\";\n//\nimport {smpRxjsThrowIfEmpty} from \"./smp-rxjs-throw-if-empty.function.js\";\n\n/**\n * Custom RxJS operator that filters the source observable based on a condition\n * and throws an error if the resulting observable is empty.\n *\n * @template T The type of items emitted by the source observable.\n * @param {function(T): boolean} condition - A function that takes a value from the source observable and returns a boolean.\n * If the function returns `true`, the value will be emitted; otherwise, it will be filtered out.\n * @param {function(): Error} [errorFactory] - An optional function that returns an error to be thrown if the resulting observable is empty.\n * If not provided, a default error will be thrown.\n * @returns {OperatorFunction<T, T>} An operator function that can be used in the RxJS pipeline.\n *\n * @example\n * import { of } from 'rxjs';\n * import { smpRxjsThrowOnCondition } from \"./path-to-your-file\";\n *\n * const source$ = of(1, 5, -3, 7, 12).pipe(\n * smpRxjsThrowOnCondition(value => value >= 0, () => new Error(\"Value is less than 0\")),\n * smpRxjsThrowOnCondition(value => value > 12, () => new Error(\"Value is lower than 12\"))\n * );\n *\n * source$.subscribe({\n * next: value => console.log(\"Value:\", value),\n * error: err => console.error(\"Error:\", err)\n * });\n */\nexport function smpRxjsThrowOnCondition<T>(\n condition: (value: T) => boolean,\n errorFactory?: (value: T) => any\n): OperatorFunction<T, T> {\n return (source: Observable<T>) =>\n source.pipe(\n filter((v: T) => !condition(v)), // Invert the condition because if I need to throw on that condition we should filter all that don't match\n defaultIfEmpty(false as unknown as T), // We nuke type errors, cause when falsy smpRxjsThrowIfEmpty will throw\n smpRxjsThrowIfEmpty(errorFactory)\n );\n}\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,EAAA,yBAAAC,EAAA,qBAAAC,EAAA,iBAAAC,EAAA,oBAAAC,EAAA,wBAAAC,EAAA,4BAAAC,IAAA,eAAAC,EAAAT,GCAA,IAAAU,EAA8B,gBAC9BC,EAAuB,oBCOhB,IAAeC,EAAf,KAAeA,CANtB,MAMsBA,CAAAA,EAAAA,iCAQtB,ECVO,SAASC,EAAuBC,EAAc,CACjD,OACI,OAAOA,GAAU,UACjBA,IAAU,MACV,UAAWA,GACX,WAAYA,GACZ,OAAQA,EAAcC,QAAW,QAEzC,CARgBF,EAAAA,EAAAA,uBFCT,IAAeG,EAAf,cAAuDC,CAAAA,CAP9D,MAO8DA,CAAAA,EAAAA,wCAU1DC,OAA0B,CACtB,OAAO,KAAKC,UAAS,CACzB,CAEAC,KAAkBC,EAAwC,CACtD,OAAO,KAAKC,SAASD,CAAAA,EAAKE,QACtBC,OAAKC,GAAAA,CACD,GAAI,KAAKC,kBAAqBD,CAAAA,EAAc,CACxC,GAAIA,EAAYE,QAAUC,WAASC,IAA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B,EAAgBiB,CAAAA,EAAmBT,QACtCU,OAAKhB,GAAAA,CACD,IAAMkB,EAAW,CAAC,EAClBL,OAAAA,EAAKM,QAAQ,CAACF,EAAKG,IAAAA,CACfF,EAAID,CAAAA,EAAOjB,EAAQoB,CAAAA,CACvB,CAAA,EACOF,CACX,CAAA,CAAA,CAER,CACJ,CAtBgBT,EAAAA,EAAAA,gBC1BhB,IAAAY,EAAmD,gBAO5C,SAASC,EACZC,EAAiD,CAKjD,SAAOC,QAFeD,CAEVE,EAAeC,QACvBC,aAAUC,GAAQA,EAAAA,CAAAA,KAClBC,WAAAA,CAAAA,CAIR,CAZgBP,EAAAA,EAAAA,mBCPhB,IAAAQ,EAAgD,gBAmCzC,SAASC,EAAuBC,EAAkCC,EAAmB,CACxF,OAAQC,GAA0BA,EAAOC,QACrCC,OAAIC,GAAAA,CACA,GAAI,CAACC,EAAYC,QAAQC,KAAKC,UAAUJ,CAAAA,CAAAA,EACpC,MAAML,EAAaK,CAAAA,EAGvB,OAAOA,CACX,CAAA,CAAA,CAER,CAVgBN,EAAAA,EAAAA,uBAYhB,IAAMO,EAAc,CAAC,OAAQ,KAAM,GAAO,EAAG,GAAI,IAAK,CAAA,EAAI,CAAC,GAAGF,IAAKC,GAC/DG,KAAKC,UAAUJ,CAAAA,CAAAA,EAGbJ,EAAsBS,EAAA,IAAa,IAAIC,MAAjB,uBCnD5B,IAAAC,EAAmE,gBA6B5D,SAASC,EACZC,EACAC,EAAgC,CAEhC,OAAQC,GACJA,EAAOC,QACHC,UAAQC,GAAS,CAACL,EAAUK,CAAAA,CAAAA,KAC5BC,kBAAe,EAAA,EACfC,EAAoBN,CAAAA,CAAAA,CAEhC,CAVgBF,EAAAA,EAAAA","names":["rxjs_exports","__export","SmpAbstractRxjsTtlCacheStrategy","SmpRxjsInMemoryCache","smpRxjsCatchOnly","smpRxjsQueue","smpRxjsSequence","smpRxjsThrowIfEmpty","smpRxjsThrowOnCondition","__toCommonJS","import_rxjs","import_ts_luxon","SmpAbstractCacheStrategy","smpIsSmpCachedValue","value","expiry","SmpAbstractRxjsTtlCacheStrategy","SmpAbstractCacheStrategy","flush","_flushRaw","read","key","_readRaw","pipe","map","storedValue","_isSmpCachedValue","expiry","DateTime","now","ts","value","_removeRaw","subscribe","remove","write","ttl","obs$","isNaN","_writeRaw","wrappedValue","error","__name","err","console","name","smpIsSmpCachedValue","import_rxjs","smpRxjsCatchOnly","errorFilter","selector","source","pipe","catchError","err","isNaN","isConstructor","isExactInstance","throwError","fn","Reflect","construct","String","ctor","import_rxjs","SmpRxjsInMemoryCache","SmpAbstractRxjsTtlCacheStrategy","_storage","Map","_staticSelf","_flushRaw","defer","clear","of","_readRaw","key","get","_removeRaw","delete","_writeRaw","value","set","import_rxjs","smpRxjsSequence","steps","results","runStep","index","length","of","defer","pipe","switchMap","value","smpRxjsQueue","source","Array","isArray","keys","Object","stepsArray","map","key","acc","forEach","i","import_rxjs","smpRxjsSequence","steps","from","stepFunctions","pipe","concatMap","step","toArray","import_rxjs","smpRxjsThrowIfEmpty","errorFactory","defaultErrorFactory","source","pipe","map","v","emptyValues","indexOf","JSON","stringify","__name","Error","import_rxjs","smpRxjsThrowOnCondition","condition","errorFactory","source","pipe","filter","v","defaultIfEmpty","smpRxjsThrowIfEmpty"]}
@@ -1,5 +1,5 @@
1
1
  import { Observable, ObservableInput, OperatorFunction, ObservedValueOf } from 'rxjs';
2
- import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-DoiEsQxI.cjs';
2
+ import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-BdPg-J7L.cjs';
3
3
 
4
4
  declare abstract class SmpAbstractRxjsTtlCacheStrategy extends SmpAbstractCacheStrategy {
5
5
  protected abstract _flushRaw(): Observable<void>;
@@ -7,7 +7,7 @@ declare abstract class SmpAbstractRxjsTtlCacheStrategy extends SmpAbstractCacheS
7
7
  protected abstract _removeRaw(key: string): Observable<void>;
8
8
  protected abstract _writeRaw(key: string, value: unknown, ttl?: number): Observable<void>;
9
9
  flush(): Observable<void>;
10
- read<T = any>(key: string): Observable<T | undefined>;
10
+ read<T = unknown>(key: string): Observable<T | undefined>;
11
11
  remove(key: string): Observable<void>;
12
12
  write<T = any>(key: string, value: T, ttl?: number): Observable<void>;
13
13
  protected _isSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
@@ -19,7 +19,7 @@ declare class SmpRxjsInMemoryCache extends SmpAbstractRxjsTtlCacheStrategy {
19
19
  private static _storage;
20
20
  protected get _staticSelf(): typeof SmpRxjsInMemoryCache;
21
21
  protected _flushRaw(): Observable<void>;
22
- protected _readRaw(key: string): Observable<any | undefined>;
22
+ protected _readRaw(key: string): Observable<unknown | undefined>;
23
23
  protected _removeRaw(key: string): Observable<void>;
24
24
  protected _writeRaw(key: string, value: any): Observable<void>;
25
25
  }
@@ -7,8 +7,8 @@ import { Observable } from 'rxjs';
7
7
  * For instance, for a local cache, you may stay sync, while for a Valkey cache, you should start with the rxjs.
8
8
  */
9
9
  declare abstract class SmpAbstractCacheStrategy {
10
- abstract read<T = any>(key: string): T | undefined | Observable<T | undefined>;
11
- abstract write<T = any>(key: string, value: T, ttl?: number): void | Observable<void>;
10
+ abstract read<T = unknown>(key: string): T | undefined | Observable<T | undefined>;
11
+ abstract write<T = unknown>(key: string, value: T, ttl?: number): void | Observable<void>;
12
12
  abstract remove(key: string): void | Observable<void>;
13
13
  abstract flush(): void | Observable<void>;
14
14
  }
@@ -1,4 +1,4 @@
1
- import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-DoiEsQxI.js';
1
+ import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-BdPg-J7L.js';
2
2
  import { SmpLoggerMethods } from '@tonysamperi/logger';
3
3
  export { smpNoop } from '@tonysamperi/logger';
4
4
  import { S as SmpResponseMessage, a as SmpResponseMessageTypes, b as SmpGenericResponseBase } from './smp-generic-response-base.interface-C0On2LBc.js';
@@ -15,9 +15,9 @@ declare abstract class SmpAbstractTtlCacheStrategy extends SmpAbstractCacheStrat
15
15
  protected abstract _removeRaw(key: string): void;
16
16
  protected abstract _writeRaw(key: string, value: unknown, ttl?: number): void;
17
17
  flush(): void;
18
- read<T = any>(key: string): T | undefined;
18
+ read<T = unknown>(key: string): T | undefined;
19
19
  remove(key: string): void;
20
- write<T = any>(key: string, value: T, ttl?: number): void;
20
+ write<T = unknown>(key: string, value: T, ttl?: number): void;
21
21
  protected _isSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
22
22
  }
23
23
 
@@ -682,7 +682,8 @@ declare class SmpAesCrypt {
682
682
  protected _password: string;
683
683
  protected _salt: string;
684
684
  protected _initVector?: string | undefined;
685
- protected get _iv(): WordArray | undefined;
685
+ protected _iv: WordArray | undefined;
686
+ protected _key: WordArray;
686
687
  protected _mode: typeof CBC;
687
688
  protected _padding: typeof PKCS7;
688
689
  constructor(_password: string, _salt: string, _initVector?: string | undefined);
@@ -708,6 +709,7 @@ declare class SmpAesCrypt {
708
709
  declare class SmpCrypto {
709
710
  static base64Decode(str: string): string;
710
711
  static base64Encode(str: string): string;
712
+ static generateCorrelationId(): string;
711
713
  static md5(data: string): string;
712
714
  static sha1(data: string): string;
713
715
  static sha256(data: string): string;
@@ -793,7 +795,7 @@ declare class SmpGiftcardTransaction implements SmpGiftcardTransactionPlain {
793
795
  protected _hashStrategy: (str: string) => WordArray;
794
796
  /**
795
797
  *
796
- * @param gc giftcard code
798
+ * @param gc gift card code
797
799
  * @param op operation
798
800
  * @param ot original transaction in case of refund
799
801
  * @param unixTimestampOrMilliseconds
@@ -851,6 +853,7 @@ declare class SmpCommonUtils {
851
853
  static assertIsTruthy<T>(condition: T, withMessage?: string): asserts condition;
852
854
  static buildPath(...args: any[]): string;
853
855
  static downloadBlob(blob: Blob, filename: string): void;
856
+ static fixDecimalPrecision(value: number, precision?: number): number;
854
857
  static generateRandomHexString(length?: number): string;
855
858
  static generateUUID(): string;
856
859
  static getDecimalPrecision(val: number | string): number;
@@ -987,6 +990,6 @@ declare class SmpInMemoryCache extends SmpAbstractTtlCacheStrategy {
987
990
  */
988
991
  declare function smpIsSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
989
992
 
990
- declare const VERSION: "2.0.0-beta.5";
993
+ declare const VERSION: "2.0.0-beta.6";
991
994
 
992
995
  export { SMP_HEALTHZ, SmpAbstractCacheStrategy, SmpAbstractTtlCacheStrategy, SmpAesCrypt, SmpApiCommonUtils, SmpBaseJwtToken, SmpBaseJwtTokenPlain, SmpBrowserCache, SmpCachedValue, SmpCommonUtils, SmpCrypto, type SmpDynamicFetchReturn, SmpErrorResponse, type SmpErrorResponseCreateOpts, SmpFilterException, type SmpGenericConstructor, SmpGenericResponse, SmpGenericResponseBase, type SmpGenericResponseCreateOpts, SmpGiftcardTransaction, type SmpGiftcardTransactionConfig, SmpGiftcardTransactionHashStrategies, SmpGiftcardTransactionOps, type SmpGiftcardTransactionPlain, SmpHttpSessionStorageCache, SmpHttpStatusCodes, type SmpHttpTwoConfig, SmpHttpTwoService, SmpInMemoryCache, type SmpMarketingCloudValidationResponse, type SmpMarketingCloudValidationResponseKo, type SmpMarketingCloudValidationResponseOk, SmpMarketingCloudValidators, type SmpPrimitive, SmpRegularExpressions, SmpResponseMessage, SmpResponseMessageTypes, SmpRestVerbs, SmpSecureCode, SmpSid, type SmpWithDateTimeAsDate, VERSION, smpApplyMixin, smpIsSmpCachedValue };