Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JsonDB.d.ts 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { Config } from "./lib/JsonDBConfig";
  2. export declare type FindCallback = (entry: any, index: number | string) => boolean;
  3. export declare class JsonDB {
  4. private loaded;
  5. private data;
  6. private readonly config;
  7. /**
  8. * JSONDB Constructor
  9. * @param filename where to save the "DB". Can also be used to give the whole configuration
  10. * @param saveOnPush save the database at each push command into the json file
  11. * @param humanReadable the JSON file will be readable easily by a human
  12. * @param separator what to use as separator
  13. */
  14. constructor(filename: string | Config, saveOnPush?: boolean, humanReadable?: boolean, separator?: string);
  15. /**
  16. * Process datapath into different parts
  17. * @param dataPath
  18. */
  19. private processDataPath;
  20. private retrieveData;
  21. private getParentData;
  22. /**
  23. * Get the wanted data
  24. * @param dataPath path of the data to retrieve
  25. */
  26. getData(dataPath: string): any;
  27. /**
  28. * Same as getData only here it's directly typed to your object
  29. * @param dataPath path of the data to retrieve
  30. */
  31. getObject<T>(dataPath: string): T;
  32. /**
  33. * Check for existing datapath
  34. * @param dataPath
  35. */
  36. exists(dataPath: string): boolean;
  37. /**
  38. * Returns the number of element which constitutes the array
  39. * @param dataPath
  40. */
  41. count(dataPath: string): number;
  42. /**
  43. * Returns the index of the object that meets the criteria submitted. Returns -1, if no match is found.
  44. * @param dataPath base dataPath from where to start searching
  45. * @param searchValue value to look for in the dataPath
  46. * @param propertyName name of the property to look for searchValue
  47. */
  48. getIndex(dataPath: string, searchValue: (string | number), propertyName?: string): number;
  49. /**
  50. * Return the index of the value inside the array. Returns -1, if no match is found.
  51. * @param dataPath base dataPath from where to start searching
  52. * @param searchValue value to look for in the dataPath
  53. */
  54. getIndexValue(dataPath: string, searchValue: (string | number)): number;
  55. private getArrayData;
  56. /**
  57. * Find all specific entry in an array/object
  58. * @param rootPath base dataPath from where to start searching
  59. * @param callback method to filter the result and find the wanted entry. Receive the entry and it's index.
  60. */
  61. filter<T>(rootPath: string, callback: FindCallback): T[] | undefined;
  62. /**
  63. * Find a specific entry in an array/object
  64. * @param rootPath base dataPath from where to start searching
  65. * @param callback method to filter the result and find the wanted entry. Receive the entry and it's index.
  66. */
  67. find<T>(rootPath: string, callback: FindCallback): T | undefined;
  68. /**
  69. * Pushing data into the database
  70. * @param dataPath path leading to the data
  71. * @param data data to push
  72. * @param override overriding or not the data, if not, it will merge them
  73. */
  74. push(dataPath: string, data: any, override?: boolean): void;
  75. /**
  76. * Delete the data
  77. * @param dataPath path leading to the data
  78. */
  79. delete(dataPath: string): void;
  80. /**
  81. * Only use this if you know what you're doing.
  82. * It reset the full data of the database.
  83. * @param data
  84. */
  85. resetData(data: any): void;
  86. /**
  87. * Reload the database from the file
  88. */
  89. reload(): void;
  90. /**
  91. * Manually load the database
  92. * It is automatically called when the first getData is done
  93. */
  94. load(): void;
  95. /**
  96. * Manually save the database
  97. * By default you can't save the database if it's not loaded
  98. * @param force force the save of the database
  99. */
  100. save(force?: boolean): void;
  101. }