{"version":3,"file":"fluig-dataset.mjs","sources":["../../../projects/fluig-dataset/src/lib/fluig-dataset.config.ts","../../../projects/fluig-dataset/src/lib/fluig-dataset.types.ts","../../../projects/fluig-dataset/src/lib/fluig-dataset.service.ts","../../../projects/fluig-dataset/src/lib/fluig-dataset.provider.ts","../../../projects/fluig-dataset/src/public-api.ts","../../../projects/fluig-dataset/src/fluig-dataset.ts"],"sourcesContent":["/** @format */\n\nimport { InjectionToken } from '@angular/core';\n\n/** Type of cache storage */\nexport type CacheType = 'LOCAL' | 'SESSION';\n\n/** Expiration times in milliseconds */\nexport interface Expiration {\n  /** Expiration time in milliseconds */\n  SHORT?: number;\n  /** Expiration time in milliseconds */\n  MEDIUM?: number;\n  /** Expiration time in milliseconds */\n  LONG?: number;\n  /** Expiration time in milliseconds */\n  VERYLONG?: number;\n}\n\n/** Configuration for FluigDatasetService */\nexport interface FluigDatasetConfig {\n  /**\n   * `LOCAL` cache will be stored in localStorage\n   * `SESSION` cache will be stored in sessionStorage\n   * Default is `SESSION`\n   */\n  cacheType: CacheType;\n  /** Cache expiration times */\n  expiration?: {\n    /** Default expiration time */\n    default?: 'NOCACHE' | keyof Expiration;\n    /** Expiration times in milliseconds */\n    times?: Expiration;\n  };\n}\n\nexport const DEFAULT_FLUIG_DATASET_CONFIG: FluigDatasetConfig = {\n  cacheType: 'SESSION',\n  expiration: {\n    default: 'MEDIUM',\n    times: {\n      SHORT: 600_000, // 10 minutes\n      MEDIUM: 9_000_000, // 2.5 hours\n      LONG: 18_000_000, // 5 hours\n      VERYLONG: 36_000_000, // 10 hours\n    },\n  },\n};\n\nexport const FLUIG_DATASET_CONFIG = new InjectionToken<FluigDatasetConfig>(\n  'FLUIG_DATASET_CONFIG',\n  {\n    providedIn: 'root',\n    factory: (): FluigDatasetConfig => DEFAULT_FLUIG_DATASET_CONFIG,\n  }\n);\n","/** @format */\n\n// AI slop that acctually works...\ntype Without<T, K> = { [P in Exclude<keyof T, keyof K>]?: never };\ntype XOR<T, U> = (Without<T, U> & U) | (Without<U, T> & T);\n\n/** Special value to represent null in a constraint value */\nexport const NULL_VALUE = '___NULL___VALUE___' as const;\n\n/**\n * Search type:\n * `MUST`    : Must match the value or range\n * `MUST_NOT`: Must not match the value or range\n * `SHOULD`  : Should match the value or range (optional)\n */\nexport type ConstraintType = 'MUST' | 'MUST_NOT' | 'SHOULD';\n\n/** Constraint value: string, number or boolean */\nexport type ConstraintValue = string | number | boolean;\n\n/** Constraint definition */\nexport interface Constraint {\n  field: string;\n  initialValue: ConstraintValue | typeof NULL_VALUE;\n  finalValue: ConstraintValue | typeof NULL_VALUE;\n  type: ConstraintType;\n  likeSearch: boolean;\n}\n\n/** Options for fetching a dataset */\nexport type DatasetOptions = {\n  /** Fields to be returned */\n  fields?: string[];\n  /** Constraints/filters to be applied */\n  constraints?: Constraint[];\n  /** Order by field and direction */\n  orderBy?: {\n    /** Field to order by */\n    field: string;\n    /** Direction: `asc` (ascending) or `desc` (descending) */\n    direction?: 'asc' | 'desc';\n  };\n  /** Maximum number of records to return */\n  limit?: number;\n  /** Number of records to skip (for pagination) */\n  offset?: number;\n  /** Cache expiration time */\n  expiration?: 'VERYLONG' | 'LONG' | 'MEDIUM' | 'SHORT' | 'NOCACHE';\n};\n\n/**\n * Constraint as single value, representing `initialValue` and `finalValue`\n *\n * - If `type` is not provided, the `finalValue` will be `___NULL___VALUE___`\n * - If `type` is provided, the `finalValue` will be the same as `initialValue`\n *\n * if `value` is `nullish`, it will be converted to a special\n * string `___NULL___VALUE___` to represent null in Fluig\n */\nexport type ConstraintValueSingle = {\n  value: ConstraintValue | null | undefined;\n};\n\n/**\n * Constraint as range, using `from` and optional `to` values,\n * representing `initialValue` and `finalValue` respectively.\n *\n * - If `to` is not provided, the `finalValue` will be `initialValue`\n * - If `to` is provided, the `finalValue` will be `to`\n * - If `type` is not provided, it will default to `MUST`\n *\n * if `from` or `to` are `nullish`, they will be converted to a special\n * string `___NULL___VALUE___` to represent null in Fluig\n */\nexport type ConstraintValueRange = {\n  /** Range with `from` and optional `to` values */\n  range: {\n    /** Start of the range (initialValue) */\n    from: ConstraintValue | null | undefined;\n    /** End of the range (finalValue), if not provided, will be the same as `from` */\n    to?: ConstraintValue | null | undefined;\n  };\n};\n\n/** Options for creating a constraint */\nexport type ConstraintOptions = {\n  /** Field to apply the constraint on */\n  field: string;\n  /**\n   * Search type:\n   * `MUST`    : Must match the value or range\n   * `MUST_NOT`: Must not match the value or range\n   * `SHOULD`  : Should match the value or range (optional)\n   *\n   * If not provided, it will default to `MUST` when using `range` (from/to) or\n   * a single `value`.\n   */\n  type?: ConstraintType;\n  /** Enable like search */\n  likeSearch?: boolean;\n} & XOR<ConstraintValueSingle, ConstraintValueRange>;\n\n/** Dataset structure with columns and values */\nexport interface Dataset<T extends Record<string, unknown>> {\n  /** Column names */\n  columns: Extract<keyof T, string>[];\n  /** Dataset values/rows */\n  values: T[];\n}\n","/** @format */\n\nimport { HttpParams } from '@angular/common/http';\nimport { Injectable, inject } from '@angular/core';\nimport {\n  Observable,\n  catchError,\n  finalize,\n  from,\n  of,\n  shareReplay,\n  switchMap,\n  tap,\n  throwError,\n} from 'rxjs';\n\nimport { FluigAPIService } from 'fluig-api';\n\nimport {\n  Dataset,\n  Constraint,\n  ConstraintType,\n  DatasetOptions,\n  ConstraintOptions,\n  NULL_VALUE,\n} from './fluig-dataset.types';\nimport { Expiration, FLUIG_DATASET_CONFIG } from './fluig-dataset.config';\n\nclass DatasetParams {\n  private params = new HttpParams();\n  set(key: string, value: string | number | boolean) {\n    this.params = this.params.set(key, value);\n    return this;\n  }\n  append(key: string, value: string | number | boolean) {\n    this.params = this.params.append(key, value);\n    return this;\n  }\n  getParams(): HttpParams {\n    return this.params;\n  }\n}\n\n@Injectable({ providedIn: 'root' })\nexport class FluigDatasetService {\n  private readonly cfg = inject(FLUIG_DATASET_CONFIG);\n  private readonly fluigAPI = inject(FluigAPIService);\n\n  private readonly inProgress = new Map<string, Observable<Dataset<any>>>();\n\n  private getExpirationTime(key: keyof Expiration): number {\n    if (!this.cfg) return 0;\n    if (!this.cfg.expiration) return 0;\n    if (!this.cfg.expiration.times) return 0;\n    return this.cfg.expiration.times[key] || 0;\n  }\n\n  private makeCacheKey(datasetId: string, options?: DatasetOptions) {\n    return this.hash(`${datasetId}:${JSON.stringify(options)}`);\n  }\n\n  private get useLocalStorage() {\n    return this.cfg.cacheType === 'LOCAL';\n  }\n  private get useSessionStorage() {\n    return this.cfg.cacheType === 'SESSION';\n  }\n  private saveToLocalStorage(key: string, data: unknown) {\n    localStorage.setItem(key, JSON.stringify(data));\n  }\n  private saveToSessionStorage(key: string, data: unknown) {\n    sessionStorage.setItem(key, JSON.stringify(data));\n  }\n  private saveToStorage(key: string, data: unknown) {\n    if (this.useLocalStorage) this.saveToLocalStorage(key, data);\n    if (this.useSessionStorage) this.saveToSessionStorage(key, data);\n  }\n\n  private getItemFromLocalStorage(key: string) {\n    return localStorage.getItem(key);\n  }\n  private getItemFromSessionStorage(key: string) {\n    return sessionStorage.getItem(key);\n  }\n  private getCachedData(key: string) {\n    if (this.useLocalStorage) return this.getItemFromLocalStorage(key);\n    if (this.useSessionStorage) return this.getItemFromSessionStorage(key);\n    return null;\n  }\n  private isDataCached(key: string) {\n    return this.getCachedData(key) != null;\n  }\n\n  private removeDataFromLocalStorage(key: string): void {\n    localStorage.removeItem(key);\n  }\n  private removeDataFromSessionStorage(key: string): void {\n    sessionStorage.removeItem(key);\n  }\n  private removeCachedData(key: string): void {\n    if (this.useLocalStorage) this.removeDataFromLocalStorage(key);\n    if (this.useSessionStorage) this.removeDataFromSessionStorage(key);\n  }\n\n  private async hash(text: string): Promise<string> {\n    const c = (globalThis as any).crypto;\n    if (!c) {\n      // Fallback to FNV-1a hash if crypto.subtle is not available\n      let h = 0x811c9dc5;\n      for (let i = 0; i < text.length; i++) {\n        h ^= text.charCodeAt(i);\n        h =\n          (h + ((h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24))) >>> 0;\n      }\n      return h.toString(16);\n    }\n\n    const encoder = new TextEncoder(),\n      data = encoder.encode(text),\n      hashBuffer = await c.subtle.digest('SHA-256', data),\n      hashArray = Array.from(new Uint8Array(hashBuffer)),\n      hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');\n    return hashHex;\n  }\n\n  public createConstraint(options: ConstraintOptions): Constraint {\n    const hasValue = 'value' in options,\n      hasRange = 'range' in options;\n\n    if ((hasValue && hasRange) || (!hasValue && !hasRange)) {\n      throw new Error(\n        'ConstraintOptions must include either \"value\" or \"range\", but not both.'\n      );\n    }\n\n    const field = options.field;\n    const type: ConstraintType = options.type ?? 'MUST';\n    const likeSearch = options.likeSearch ?? false;\n\n    if (hasValue) {\n      const initialValue: Constraint['initialValue'] =\n        options.value ?? NULL_VALUE;\n\n      const finalValue: Constraint['finalValue'] =\n        options.type === undefined ? NULL_VALUE : initialValue;\n\n      return { field, initialValue, finalValue, type, likeSearch };\n    }\n\n    if (hasRange) {\n      const from: Constraint['initialValue'] =\n        options.range.from ?? NULL_VALUE;\n\n      const to: Constraint['finalValue'] =\n        options.range.to === undefined\n          ? from\n          : (options.range.to ?? NULL_VALUE);\n\n      return { field, initialValue: from, finalValue: to, type, likeSearch };\n    }\n\n    throw new Error(\n      'ConstraintOptions must include either \"value\" or \"range\", but not both.'\n    );\n  }\n\n  private fetchAndCacheDataset<T extends Record<string, unknown>>(\n    datasetId: string,\n    cacheKey: string,\n    options?: DatasetOptions\n  ): Observable<Dataset<T>> {\n    const expiration =\n      options == null || options.expiration == null\n        ? this.cfg.expiration && this.cfg.expiration.default\n          ? this.cfg.expiration.default\n          : 'NOCACHE'\n        : options.expiration;\n\n    const cacheExpirationTime =\n      expiration === 'NOCACHE' ? 0 : this.getExpirationTime(expiration);\n\n    if (cacheExpirationTime > 0) {\n      const cachedItem = this.getCachedData(cacheKey);\n      if (cachedItem) {\n        const { timestamp, data } = JSON.parse(cachedItem);\n        const age = Date.now() - timestamp;\n        if (age < cacheExpirationTime) {\n          return of(data as Dataset<T>);\n        }\n        this.removeCachedData(cacheKey);\n      }\n    }\n\n    const params = new DatasetParams();\n    params.set('datasetId', datasetId);\n\n    if (options != null) {\n      if (options.orderBy != null) {\n        const orderBy = options.orderBy.field;\n        const direction = options.orderBy.direction ?? 'asc';\n        params.set('orderBy', `${orderBy};${direction}`);\n      }\n\n      if (options.limit != null) {\n        params.set('limit', options.limit);\n      }\n\n      if (options.offset != null) {\n        params.set('offset', options.offset);\n      }\n\n      if (options.fields != null && options.fields.length > 0) {\n        options.fields.forEach((field) => params.append('field', field));\n      }\n\n      if (options.constraints != null && options.constraints.length > 0) {\n        options.constraints.forEach((constraint) => {\n          params\n            .append('constraintsField', constraint.field)\n            .append('constraintsInitialValue', constraint.initialValue)\n            .append('constraintsFinalValue', constraint.finalValue)\n            .append('constraintsType', constraint.type)\n            .append('constraintsLikeSearch', constraint.likeSearch);\n        });\n      }\n    }\n\n    return this.fluigAPI\n      .get<Dataset<T>>('/dataset/api/v2/dataset-handle/search', {\n        params: params.getParams(),\n      })\n      .pipe(\n        catchError((error) => throwError(() => error)),\n        tap((data) => {\n          if (cacheExpirationTime > 0 && !this.isDataCached(cacheKey)) {\n            this.saveToStorage(cacheKey, { timestamp: Date.now(), data });\n          }\n        })\n      );\n  }\n\n  private normalizeOptions(\n    options?: DatasetOptions\n  ): DatasetOptions | undefined {\n    if (!options) return options;\n    return {\n      ...options,\n      fields: options.fields ? [...options.fields].sort() : undefined,\n      constraints: options.constraints\n        ? [...options.constraints].sort((a, b) =>\n            a.field.localeCompare(b.field)\n          )\n        : undefined,\n      orderBy: options.orderBy\n        ? {\n            field: options.orderBy.field,\n            direction: options.orderBy.direction ?? 'asc',\n          }\n        : undefined,\n    };\n  }\n\n  /**\n   * Fetches a dataset from Fluig API, with caching support.\n   * - If the dataset is already being fetched, it will return the same observable.\n   * - If the dataset is cached and not expired, it will return the cached data.\n   * - If the dataset is not cached or expired, it will fetch from the API and cache it.\n   *\n   * @param options DatasetOptions\n   * @returns Observable<Dataset<T>>\n   */\n  public getDataset<T extends Record<string, unknown>>(\n    datasetId: string,\n    options?: DatasetOptions\n  ): Observable<Dataset<T>> {\n    const normalized = this.normalizeOptions(options);\n    return from(this.makeCacheKey(datasetId, normalized)).pipe(\n      switchMap((hashedKey) => {\n        if (this.inProgress.has(hashedKey)) {\n          return this.inProgress.get(hashedKey) as Observable<Dataset<T>>;\n        }\n\n        const source$ = this.fetchAndCacheDataset<T>(\n          datasetId,\n          hashedKey,\n          normalized\n        ).pipe(\n          finalize(() => this.inProgress.delete(hashedKey)),\n          shareReplay({ bufferSize: 1, refCount: false }),\n          catchError((error) => {\n            this.removeCachedData(hashedKey);\n            return throwError(() => error);\n          })\n        );\n\n        this.inProgress.set(hashedKey, source$);\n        return source$;\n      })\n    );\n  }\n}\n","/** @format */\n\nimport {\n  FLUIG_DATASET_CONFIG,\n  DEFAULT_FLUIG_DATASET_CONFIG,\n  FluigDatasetConfig,\n} from './fluig-dataset.config';\n\nimport { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\n\nexport function provideFluigDatasetConfig(\n  config: Partial<FluigDatasetConfig>\n): EnvironmentProviders {\n  const defaultConfig = DEFAULT_FLUIG_DATASET_CONFIG;\n  const merged: FluigDatasetConfig = {\n    ...defaultConfig,\n    ...config,\n    expiration: {\n      ...defaultConfig.expiration,\n      ...config.expiration,\n      times: {\n        ...defaultConfig.expiration?.times,\n        ...config.expiration?.times,\n      },\n    },\n  };\n  return makeEnvironmentProviders([\n    { provide: FLUIG_DATASET_CONFIG, useValue: merged },\n  ]);\n}\n","/** @format */\n\n/* Public API Surface of fluig-dataset */\n\nexport { FLUIG_DATASET_CONFIG } from './lib/fluig-dataset.config';\nexport * from './lib/fluig-dataset.types';\nexport * from './lib/fluig-dataset.service';\nexport * from './lib/fluig-dataset.provider';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAAA;AAoCO,MAAM,4BAA4B,GAAuB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