Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

localforage.d.ts 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. interface LocalForageDbInstanceOptions {
  2. name?: string;
  3. storeName?: string;
  4. }
  5. interface LocalForageOptions extends LocalForageDbInstanceOptions {
  6. driver?: string | string[];
  7. size?: number;
  8. version?: number;
  9. description?: string;
  10. }
  11. interface LocalForageDbMethodsCore {
  12. getItem<T>(key: string, callback?: (err: any, value: T | null) => void): Promise<T | null>;
  13. setItem<T>(key: string, value: T, callback?: (err: any, value: T) => void): Promise<T>;
  14. removeItem(key: string, callback?: (err: any) => void): Promise<void>;
  15. clear(callback?: (err: any) => void): Promise<void>;
  16. length(callback?: (err: any, numberOfKeys: number) => void): Promise<number>;
  17. key(keyIndex: number, callback?: (err: any, key: string) => void): Promise<string>;
  18. keys(callback?: (err: any, keys: string[]) => void): Promise<string[]>;
  19. iterate<T, U>(iteratee: (value: T, key: string, iterationNumber: number) => U,
  20. callback?: (err: any, result: U) => void): Promise<U>;
  21. }
  22. interface LocalForageDropInstanceFn {
  23. (dbInstanceOptions?: LocalForageDbInstanceOptions, callback?: (err: any) => void): Promise<void>;
  24. }
  25. interface LocalForageDriverMethodsOptional {
  26. dropInstance?: LocalForageDropInstanceFn;
  27. }
  28. // duplicating LocalForageDriverMethodsOptional to preserve TS v2.0 support,
  29. // since Partial<> isn't supported there
  30. interface LocalForageDbMethodsOptional {
  31. dropInstance: LocalForageDropInstanceFn;
  32. }
  33. interface LocalForageDriverDbMethods extends LocalForageDbMethodsCore, LocalForageDriverMethodsOptional {}
  34. interface LocalForageDriverSupportFunc {
  35. (): Promise<boolean>;
  36. }
  37. interface LocalForageDriver extends LocalForageDriverDbMethods {
  38. _driver: string;
  39. _initStorage(options: LocalForageOptions): void;
  40. _support?: boolean | LocalForageDriverSupportFunc;
  41. }
  42. interface LocalForageSerializer {
  43. serialize<T>(value: T | ArrayBuffer | Blob, callback: (value: string, error: any) => void): void;
  44. deserialize<T>(value: string): T | ArrayBuffer | Blob;
  45. stringToBuffer(serializedString: string): ArrayBuffer;
  46. bufferToString(buffer: ArrayBuffer): string;
  47. }
  48. interface LocalForageDbMethods extends LocalForageDbMethodsCore, LocalForageDbMethodsOptional {}
  49. interface LocalForage extends LocalForageDbMethods {
  50. LOCALSTORAGE: string;
  51. WEBSQL: string;
  52. INDEXEDDB: string;
  53. /**
  54. * Set and persist localForage options. This must be called before any other calls to localForage are made, but can be called after localForage is loaded.
  55. * If you set any config values with this method they will persist after driver changes, so you can call config() then setDriver()
  56. * @param {LocalForageOptions} options?
  57. */
  58. config(options: LocalForageOptions): boolean;
  59. config(options: string): any;
  60. config(): LocalForageOptions;
  61. /**
  62. * Create a new instance of localForage to point to a different store.
  63. * All the configuration options used by config are supported.
  64. * @param {LocalForageOptions} options
  65. */
  66. createInstance(options: LocalForageOptions): LocalForage;
  67. driver(): string;
  68. /**
  69. * Force usage of a particular driver or drivers, if available.
  70. * @param {string} driver
  71. */
  72. setDriver(driver: string | string[], callback?: () => void, errorCallback?: (error: any) => void): Promise<void>;
  73. defineDriver(driver: LocalForageDriver, callback?: () => void, errorCallback?: (error: any) => void): Promise<void>;
  74. /**
  75. * Return a particular driver
  76. * @param {string} driver
  77. */
  78. getDriver(driver: string): Promise<LocalForageDriver>;
  79. getSerializer(callback?: (serializer: LocalForageSerializer) => void): Promise<LocalForageSerializer>;
  80. supports(driverName: string): boolean;
  81. ready(callback?: (error: any) => void): Promise<void>;
  82. }
  83. declare module "localforage" {
  84. let localforage: LocalForage;
  85. export = localforage;
  86. }