@icure/api 6.4.0 → 7.0.0-beta.1

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.
Files changed (154) hide show
  1. package/icc-api/api/IccDeviceApi.d.ts +1 -1
  2. package/icc-api/api/IccDeviceApi.js.map +1 -1
  3. package/icc-api/api/IccDoctemplateApi.js.map +1 -1
  4. package/icc-api/api/IccDocumentTemplateApi.js.map +1 -1
  5. package/icc-api/api/IccHcpartyApi.d.ts +1 -1
  6. package/icc-api/api/IccHcpartyApi.js.map +1 -1
  7. package/icc-api/api/IccPatientApi.d.ts +1 -1
  8. package/icc-api/api/IccPatientApi.js.map +1 -1
  9. package/icc-api/model/MaintenanceTask.d.ts +6 -5
  10. package/icc-api/model/MaintenanceTask.js +5 -0
  11. package/icc-api/model/MaintenanceTask.js.map +1 -1
  12. package/icc-api/model/User.d.ts +23 -1
  13. package/icc-api/model/User.js +21 -0
  14. package/icc-api/model/User.js.map +1 -1
  15. package/icc-api/model/models.d.ts +14 -0
  16. package/icc-api/model/models.js.map +1 -1
  17. package/icc-x-api/crypto/AES.d.ts +2 -0
  18. package/icc-x-api/crypto/AES.js +12 -0
  19. package/icc-x-api/crypto/AES.js.map +1 -1
  20. package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +122 -0
  21. package/icc-x-api/crypto/BaseExchangeKeysManager.js +356 -0
  22. package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -0
  23. package/icc-x-api/crypto/ConfidentialEntities.d.ts +58 -0
  24. package/icc-x-api/crypto/ConfidentialEntities.js +99 -0
  25. package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -0
  26. package/icc-x-api/crypto/CryptoPrimitives.d.ts +31 -0
  27. package/icc-x-api/crypto/CryptoPrimitives.js +55 -0
  28. package/icc-x-api/crypto/CryptoPrimitives.js.map +1 -0
  29. package/icc-x-api/crypto/CryptoStrategies.d.ts +82 -0
  30. package/icc-x-api/crypto/CryptoStrategies.js +3 -0
  31. package/icc-x-api/crypto/CryptoStrategies.js.map +1 -0
  32. package/icc-x-api/crypto/EntitiesEncryption.d.ts +254 -0
  33. package/icc-x-api/crypto/EntitiesEncryption.js +700 -0
  34. package/icc-x-api/crypto/EntitiesEncryption.js.map +1 -0
  35. package/icc-x-api/crypto/ExchangeKeysManager.d.ts +56 -0
  36. package/icc-x-api/crypto/ExchangeKeysManager.js +147 -0
  37. package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -0
  38. package/icc-x-api/crypto/KeyManager.d.ts +103 -0
  39. package/icc-x-api/crypto/KeyManager.js +288 -0
  40. package/icc-x-api/crypto/KeyManager.js.map +1 -0
  41. package/icc-x-api/crypto/KeyRecovery.d.ts +34 -0
  42. package/icc-x-api/crypto/KeyRecovery.js +253 -0
  43. package/icc-x-api/crypto/KeyRecovery.js.map +1 -0
  44. package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +28 -0
  45. package/icc-x-api/crypto/LegacyCryptoStrategies.js +22 -0
  46. package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -0
  47. package/icc-x-api/crypto/RSA.d.ts +19 -20
  48. package/icc-x-api/crypto/RSA.js +30 -1
  49. package/icc-x-api/crypto/RSA.js.map +1 -1
  50. package/icc-x-api/crypto/ShamirKeysManager.d.ts +43 -0
  51. package/icc-x-api/crypto/ShamirKeysManager.js +150 -0
  52. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -0
  53. package/icc-x-api/crypto/ShareMetadataBehaviour.d.ts +19 -0
  54. package/icc-x-api/crypto/ShareMetadataBehaviour.js +24 -0
  55. package/icc-x-api/crypto/ShareMetadataBehaviour.js.map +1 -0
  56. package/icc-x-api/crypto/TransferKeysManager.d.ts +29 -0
  57. package/icc-x-api/crypto/TransferKeysManager.js +121 -0
  58. package/icc-x-api/crypto/TransferKeysManager.js.map +1 -0
  59. package/icc-x-api/crypto/utils.d.ts +46 -0
  60. package/icc-x-api/crypto/utils.js +128 -0
  61. package/icc-x-api/crypto/utils.js.map +1 -1
  62. package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.d.ts +11 -0
  63. package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js +11 -0
  64. package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js.map +1 -1
  65. package/icc-x-api/filters/DeviceByHcPartyFilter.d.ts +11 -0
  66. package/icc-x-api/filters/DeviceByHcPartyFilter.js +11 -0
  67. package/icc-x-api/filters/DeviceByHcPartyFilter.js.map +1 -1
  68. package/icc-x-api/filters/DeviceByIdsFilter.d.ts +11 -0
  69. package/icc-x-api/filters/DeviceByIdsFilter.js +11 -0
  70. package/icc-x-api/filters/DeviceByIdsFilter.js.map +1 -1
  71. package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.d.ts +11 -0
  72. package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js +11 -0
  73. package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js.map +1 -1
  74. package/icc-x-api/icc-accesslog-x-api.d.ts +49 -4
  75. package/icc-x-api/icc-accesslog-x-api.js +112 -102
  76. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  77. package/icc-x-api/icc-calendar-item-x-api.d.ts +53 -5
  78. package/icc-x-api/icc-calendar-item-x-api.js +112 -100
  79. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  80. package/icc-x-api/icc-classification-x-api.d.ts +45 -2
  81. package/icc-x-api/icc-classification-x-api.js +89 -41
  82. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  83. package/icc-x-api/icc-contact-x-api.d.ts +57 -19
  84. package/icc-x-api/icc-contact-x-api.js +149 -154
  85. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  86. package/icc-x-api/icc-crypto-x-api.d.ts +266 -366
  87. package/icc-x-api/icc-crypto-x-api.js +416 -1327
  88. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  89. package/icc-x-api/icc-data-owner-x-api.d.ts +110 -11
  90. package/icc-x-api/icc-data-owner-x-api.js +188 -14
  91. package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
  92. package/icc-x-api/icc-doctemplate-x-api.js +3 -3
  93. package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
  94. package/icc-x-api/icc-document-x-api.d.ts +76 -5
  95. package/icc-x-api/icc-document-x-api.js +137 -59
  96. package/icc-x-api/icc-document-x-api.js.map +1 -1
  97. package/icc-x-api/icc-form-x-api.d.ts +47 -7
  98. package/icc-x-api/icc-form-x-api.js +85 -86
  99. package/icc-x-api/icc-form-x-api.js.map +1 -1
  100. package/icc-x-api/icc-hcparty-x-api.d.ts +1 -1
  101. package/icc-x-api/icc-hcparty-x-api.js +1 -1
  102. package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
  103. package/icc-x-api/icc-helement-x-api.d.ts +50 -3
  104. package/icc-x-api/icc-helement-x-api.js +101 -118
  105. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  106. package/icc-x-api/icc-icure-maintenance-x-api.d.ts +31 -0
  107. package/icc-x-api/icc-icure-maintenance-x-api.js +124 -0
  108. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -0
  109. package/icc-x-api/icc-invoice-x-api.d.ts +45 -5
  110. package/icc-x-api/icc-invoice-x-api.js +89 -64
  111. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  112. package/icc-x-api/icc-maintenance-task-x-api.d.ts +38 -6
  113. package/icc-x-api/icc-maintenance-task-x-api.js +73 -102
  114. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  115. package/icc-x-api/icc-message-x-api.d.ts +55 -2
  116. package/icc-x-api/icc-message-x-api.js +92 -33
  117. package/icc-x-api/icc-message-x-api.js.map +1 -1
  118. package/icc-x-api/icc-patient-x-api.d.ts +67 -7
  119. package/icc-x-api/icc-patient-x-api.js +409 -473
  120. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  121. package/icc-x-api/icc-receipt-x-api.d.ts +49 -5
  122. package/icc-x-api/icc-receipt-x-api.js +85 -47
  123. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  124. package/icc-x-api/icc-time-table-x-api.d.ts +34 -10
  125. package/icc-x-api/icc-time-table-x-api.js +61 -18
  126. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  127. package/icc-x-api/index.d.ts +30 -1
  128. package/icc-x-api/index.js +112 -49
  129. package/icc-x-api/index.js.map +1 -1
  130. package/icc-x-api/maintenance/KeyPairUpdateRequest.d.ts +35 -0
  131. package/icc-x-api/maintenance/KeyPairUpdateRequest.js +54 -0
  132. package/icc-x-api/maintenance/KeyPairUpdateRequest.js.map +1 -0
  133. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.d.ts +9 -0
  134. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js +23 -0
  135. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js.map +1 -0
  136. package/icc-x-api/storage/IcureStorageFacade.d.ts +55 -0
  137. package/icc-x-api/storage/IcureStorageFacade.js +95 -0
  138. package/icc-x-api/storage/IcureStorageFacade.js.map +1 -0
  139. package/icc-x-api/storage/StorageEntryKeysFactory.d.ts +31 -0
  140. package/icc-x-api/storage/StorageEntryKeysFactory.js +3 -0
  141. package/icc-x-api/storage/StorageEntryKeysFactory.js.map +1 -0
  142. package/icc-x-api/utils/collection-utils.d.ts +8 -0
  143. package/icc-x-api/utils/collection-utils.js +26 -0
  144. package/icc-x-api/utils/collection-utils.js.map +1 -0
  145. package/icc-x-api/utils/crypto-utils.d.ts +8 -1
  146. package/icc-x-api/utils/crypto-utils.js +19 -3
  147. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  148. package/icc-x-api/utils/graph-utils.d.ts +45 -0
  149. package/icc-x-api/utils/graph-utils.js +203 -0
  150. package/icc-x-api/utils/graph-utils.js.map +1 -0
  151. package/icc-x-api/utils/lru-temporised-async-cache.d.ts +27 -0
  152. package/icc-x-api/utils/lru-temporised-async-cache.js +120 -0
  153. package/icc-x-api/utils/lru-temporised-async-cache.js.map +1 -0
  154. package/package.json +1 -1
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LruTemporisedAsyncCache = void 0;
4
+ class LruTemporisedAsyncCache {
5
+ /**
6
+ * @param maxCacheSize Maximum size of the cache. Any value <= 0 is considered as no limit.
7
+ * @param lifetimeForValue Get the maximum lifetime for an entry given its value.
8
+ */
9
+ constructor(maxCacheSize, lifetimeForValue) {
10
+ this.nodesMap = new Map();
11
+ this.firstNode = null;
12
+ this.lastNode = null;
13
+ this.maxCacheSize = maxCacheSize;
14
+ this.lifetimeForValue = lifetimeForValue;
15
+ }
16
+ /**
17
+ * Gets a cached value or retrieves it and caches it if the value is not available or if it is available but expired. A value will never be expired
18
+ * if it was not yet retrieved, even if the retrieved value would be expired according to the {@link additionalExpirationCondition}
19
+ * @param key key of the entry
20
+ * @param retrieve given the previous value (if available, expired but not yet removed) of the entry retrieves an updated value.
21
+ * @param additionalExpirationCondition an expiration condition for already cached values to consider in addition to time-based expiration. Returns
22
+ * always false by default, meaning the value is not expired if its lifetime didn't already surpass the maximum lifetime.
23
+ * @return the cached value if present and not expired, else the retrieved value.
24
+ */
25
+ get(key, retrieve, additionalExpirationCondition = () => false) {
26
+ const retrieved = this.nodesMap.get(key);
27
+ if (retrieved !== undefined) {
28
+ this.markUsed(retrieved);
29
+ const cachedValue = retrieved.cachedValue;
30
+ if (retrieved.expired((x) => this.lifetimeForValue(x)) || (cachedValue !== undefined && additionalExpirationCondition(cachedValue))) {
31
+ retrieved.value = this.registerJob(key, () => retrieve(cachedValue));
32
+ }
33
+ return retrieved.valuePromise();
34
+ }
35
+ else {
36
+ const newNode = new CacheNode(key, this.lastNode, null, this.registerJob(key, () => retrieve(undefined)));
37
+ this.addToTail(key, newNode);
38
+ if (this.maxCacheSize > 0 && this.nodesMap.size > this.maxCacheSize)
39
+ this.evict(this.firstNode.key, this.firstNode);
40
+ return newNode.valuePromise();
41
+ }
42
+ }
43
+ clear() {
44
+ this.firstNode = null;
45
+ this.lastNode = null;
46
+ this.nodesMap.clear();
47
+ }
48
+ addToTail(key, node) {
49
+ node.previous = this.lastNode;
50
+ node.next = null;
51
+ if (this.lastNode)
52
+ this.lastNode.next = node;
53
+ this.lastNode = node;
54
+ if (this.firstNode === null)
55
+ this.firstNode = node;
56
+ if (key != null)
57
+ this.nodesMap.set(key, node);
58
+ }
59
+ evict(key, node) {
60
+ if (node.previous)
61
+ node.previous.next = node.next;
62
+ if (node.next)
63
+ node.next.previous = node.previous;
64
+ if (this.firstNode === node)
65
+ this.firstNode = node.next;
66
+ if (this.lastNode === node)
67
+ this.lastNode = node.previous;
68
+ if (key !== null)
69
+ this.nodesMap.delete(key);
70
+ }
71
+ markUsed(node) {
72
+ if (node !== this.lastNode) {
73
+ // No need to modify the nodes map
74
+ this.evict(null, node);
75
+ this.addToTail(null, node);
76
+ }
77
+ }
78
+ registerJob(key, retrieve) {
79
+ // The node may have already been evicted by the time the promise completed if the cached surpassed the maximum size.
80
+ return retrieve()
81
+ .then((v) => {
82
+ const node = this.nodesMap.get(key);
83
+ if (node) {
84
+ node.value = { cached: v, timestamp: Date.now() };
85
+ }
86
+ return v;
87
+ })
88
+ .catch((e) => {
89
+ const node = this.nodesMap.get(key);
90
+ if (node) {
91
+ this.evict(key, node);
92
+ }
93
+ throw e;
94
+ });
95
+ }
96
+ }
97
+ exports.LruTemporisedAsyncCache = LruTemporisedAsyncCache;
98
+ class CacheNode {
99
+ constructor(key, previous, next, value) {
100
+ this.key = key;
101
+ this.previous = previous;
102
+ this.next = next;
103
+ this.value = value;
104
+ }
105
+ expired(lifetimeForValue) {
106
+ if ('timestamp' in this.value) {
107
+ const maxLifetime = lifetimeForValue(this.value.cached);
108
+ return maxLifetime > 0 && Date.now() - this.value.timestamp > maxLifetime;
109
+ }
110
+ else
111
+ return false;
112
+ }
113
+ valuePromise() {
114
+ return 'timestamp' in this.value ? Promise.resolve(this.value.cached) : this.value;
115
+ }
116
+ get cachedValue() {
117
+ return 'timestamp' in this.value ? this.value.cached : undefined;
118
+ }
119
+ }
120
+ //# sourceMappingURL=lru-temporised-async-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lru-temporised-async-cache.js","sourceRoot":"","sources":["../../../icc-x-api/utils/lru-temporised-async-cache.ts"],"names":[],"mappings":";;;AAAA,MAAa,uBAAuB;IAQlC;;;OAGG;IACH,YAAY,YAAoB,EAAE,gBAAsC;QARvD,aAAQ,GAA4B,IAAI,GAAG,EAAE,CAAA;QACtD,cAAS,GAA2B,IAAI,CAAA;QACxC,aAAQ,GAA2B,IAAI,CAAA;QAO7C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;IAC1C,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CACD,GAAM,EACN,QAAsD,EACtD,gCAAuD,GAAG,EAAE,CAAC,KAAK;QAElE,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACxC,IAAI,SAAS,KAAK,SAAS,EAAE;YAC3B,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;YACxB,MAAM,WAAW,GAAG,SAAS,CAAC,WAAW,CAAA;YACzC,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,KAAK,SAAS,IAAI,6BAA6B,CAAC,WAAW,CAAC,CAAC,EAAE;gBACnI,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAA;aACrE;YACD,OAAO,SAAS,CAAC,YAAY,EAAE,CAAA;SAChC;aAAM;YACL,MAAM,OAAO,GAAG,IAAI,SAAS,CAC3B,GAAG,EACH,IAA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,CAAA;IACN,CAAC;CACF;AArGD,0DAqGC;AAID,MAAM,SAAS;IAMb,YAAY,GAAM,EAAE,QAAgC,EAAE,IAA4B,EAAE,KAAiB;QACnG,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,OAAO,CAAC,gBAAsC;QAC5C,IAAI,WAAW,IAAI,IAAI,CAAC,KAAK,EAAE;YAC7B,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YACvD,OAAO,WAAW,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,WAAW,CAAA;SAC1E;;YAAM,OAAO,KAAK,CAAA;IACrB,CAAC;IAED,YAAY;QACV,OAAO,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAA;IACpF,CAAC;IAED,IAAI,WAAW;QACb,OAAO,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;IAClE,CAAC;CACF","sourcesContent":["export class LruTemporisedAsyncCache<K, V> {\n private readonly maxCacheSize: number\n private readonly lifetimeForValue: (value: V) => number\n\n private readonly nodesMap: Map<K, CacheNode<K, V>> = new Map()\n private firstNode: CacheNode<K, V> | null = null\n private lastNode: CacheNode<K, V> | null = null\n\n /**\n * @param maxCacheSize Maximum size of the cache. Any value <= 0 is considered as no limit.\n * @param lifetimeForValue Get the maximum lifetime for an entry given its value.\n */\n constructor(maxCacheSize: number, lifetimeForValue: (value: V) => number) {\n this.maxCacheSize = maxCacheSize\n this.lifetimeForValue = lifetimeForValue\n }\n\n /**\n * Gets a cached value or retrieves it and caches it if the value is not available or if it is available but expired. A value will never be expired\n * if it was not yet retrieved, even if the retrieved value would be expired according to the {@link additionalExpirationCondition}\n * @param key key of the entry\n * @param retrieve given the previous value (if available, expired but not yet removed) of the entry retrieves an updated value.\n * @param additionalExpirationCondition an expiration condition for already cached values to consider in addition to time-based expiration. Returns\n * always false by default, meaning the value is not expired if its lifetime didn't already surpass the maximum lifetime.\n * @return the cached value if present and not expired, else the retrieved value.\n */\n get(\n key: K,\n retrieve: (previousValue: V | undefined) => Promise<V>,\n additionalExpirationCondition: (value: V) => boolean = () => false\n ): Promise<V> {\n const retrieved = this.nodesMap.get(key)\n if (retrieved !== undefined) {\n this.markUsed(retrieved)\n const cachedValue = retrieved.cachedValue\n if (retrieved.expired((x) => this.lifetimeForValue(x)) || (cachedValue !== undefined && additionalExpirationCondition(cachedValue))) {\n retrieved.value = this.registerJob(key, () => retrieve(cachedValue))\n }\n return retrieved.valuePromise()\n } else {\n const newNode = new CacheNode(\n key,\n this.lastNode,\n null,\n this.registerJob(key, () => retrieve(undefined))\n )\n this.addToTail(key, newNode)\n if (this.maxCacheSize > 0 && this.nodesMap.size > this.maxCacheSize) this.evict(this.firstNode!.key, this.firstNode!)\n return newNode.valuePromise()\n }\n }\n\n clear() {\n this.firstNode = null\n this.lastNode = null\n this.nodesMap.clear()\n }\n\n private addToTail(key: K | null, node: CacheNode<K, V>) {\n node.previous = this.lastNode\n node.next = null\n if (this.lastNode) this.lastNode.next = node\n this.lastNode = node\n if (this.firstNode === null) this.firstNode = node\n if (key != null) this.nodesMap.set(key, node)\n }\n\n private evict(key: K | null, node: CacheNode<K, V>) {\n if (node.previous) node.previous.next = node.next\n if (node.next) node.next.previous = node.previous\n if (this.firstNode === node) this.firstNode = node.next\n if (this.lastNode === node) this.lastNode = node.previous\n if (key !== null) this.nodesMap.delete(key)\n }\n\n private markUsed(node: CacheNode<K, V>) {\n if (node !== this.lastNode) {\n // No need to modify the nodes map\n this.evict(null, node)\n this.addToTail(null, node)\n }\n }\n\n private registerJob(key: K, retrieve: () => Promise<V>): Promise<V> {\n // The node may have already been evicted by the time the promise completed if the cached surpassed the maximum size.\n return retrieve()\n .then((v) => {\n const node = this.nodesMap.get(key)\n if (node) {\n node.value = { cached: v, timestamp: Date.now() }\n }\n return v\n })\n .catch((e) => {\n const node = this.nodesMap.get(key)\n if (node) {\n this.evict(key, node)\n }\n throw e\n })\n }\n}\n\ntype Cached<V> = { cached: V; timestamp: number }\n\nclass CacheNode<K, V> {\n readonly key: K\n previous: CacheNode<K, V> | null\n next: CacheNode<K, V> | null\n value: Promise<V> | Cached<V>\n\n constructor(key: K, previous: CacheNode<K, V> | null, next: CacheNode<K, V> | null, value: Promise<V>) {\n this.key = key\n this.previous = previous\n this.next = next\n this.value = value\n }\n\n expired(lifetimeForValue: (value: V) => number): boolean {\n if ('timestamp' in this.value) {\n const maxLifetime = lifetimeForValue(this.value.cached)\n return maxLifetime > 0 && Date.now() - this.value.timestamp > maxLifetime\n } else return false\n }\n\n valuePromise(): Promise<V> {\n return 'timestamp' in this.value ? Promise.resolve(this.value.cached) : this.value\n }\n\n get cachedValue(): V | undefined {\n return 'timestamp' in this.value ? this.value.cached : undefined\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icure/api",
3
- "version": "6.4.0",
3
+ "version": "7.0.0-beta.1",
4
4
  "description": "Typescript version of iCure standalone API client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",