@tstdl/base 0.92.142 → 0.92.143

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 (223) hide show
  1. package/ai/ai-file.service.js +1 -1
  2. package/ai/ai.service.js +3 -3
  3. package/ai/types.d.ts +1 -1
  4. package/api/client/client.d.ts +1 -1
  5. package/api/client/client.js +10 -4
  6. package/api/server/middlewares/content-type.middleware.js +8 -7
  7. package/api/types.js +1 -1
  8. package/authentication/client/authentication.service.js +3 -3
  9. package/authentication/server/authentication-ancillary.service.d.ts +11 -1
  10. package/authentication/server/authentication-ancillary.service.js +1 -1
  11. package/authentication/server/authentication-secret-requirements.validator.js +1 -1
  12. package/authentication/server/authentication.api-controller.js +22 -10
  13. package/authentication/server/authentication.service.d.ts +11 -5
  14. package/authentication/server/authentication.service.js +97 -49
  15. package/authentication/server/drizzle.config.js +2 -2
  16. package/authentication/server/module.js +1 -1
  17. package/cancellation/token.d.ts +2 -2
  18. package/cancellation/token.js +4 -4
  19. package/cookie/cookie.js +2 -2
  20. package/document-management/api/document-management.api.d.ts +122 -24
  21. package/document-management/api/document-management.api.js +17 -0
  22. package/document-management/{server/services → authorization}/document-management-authorization.service.d.ts +7 -7
  23. package/document-management/authorization/document-management-authorization.service.js +2 -0
  24. package/document-management/authorization/index.d.ts +2 -0
  25. package/document-management/authorization/index.js +2 -0
  26. package/document-management/authorization/policies.d.ts +38 -0
  27. package/document-management/authorization/policies.js +2 -0
  28. package/document-management/index.d.ts +1 -0
  29. package/document-management/index.js +1 -0
  30. package/document-management/models/document-assignment-scope.model.d.ts +1 -0
  31. package/document-management/models/document-assignment-scope.model.js +10 -3
  32. package/document-management/models/document-assignment-task.model.d.ts +1 -0
  33. package/document-management/models/document-assignment-task.model.js +8 -2
  34. package/document-management/models/document-category.model.d.ts +1 -0
  35. package/document-management/models/document-category.model.js +7 -1
  36. package/document-management/models/document-collection-assignment.model.d.ts +1 -0
  37. package/document-management/models/document-collection-assignment.model.js +12 -4
  38. package/document-management/models/document-collection.model.d.ts +2 -0
  39. package/document-management/models/document-collection.model.js +8 -2
  40. package/document-management/models/document-management-table.d.ts +3 -1
  41. package/document-management/models/document-management-table.js +2 -2
  42. package/document-management/models/document-property-value.model.d.ts +1 -0
  43. package/document-management/models/document-property-value.model.js +9 -3
  44. package/document-management/models/document-property.model.d.ts +1 -0
  45. package/document-management/models/document-property.model.js +8 -2
  46. package/document-management/models/document-request-collection-assignment.model.d.ts +1 -0
  47. package/document-management/models/document-request-collection-assignment.model.js +12 -4
  48. package/document-management/models/document-request-template.d.ts +1 -0
  49. package/document-management/models/document-request-template.js +6 -1
  50. package/document-management/models/document-request.model.d.ts +1 -0
  51. package/document-management/models/document-request.model.js +10 -1
  52. package/document-management/models/document-requests-template.d.ts +1 -0
  53. package/document-management/models/document-requests-template.js +7 -3
  54. package/document-management/models/document-tag-assignment.model.d.ts +8 -0
  55. package/document-management/models/document-tag-assignment.model.js +40 -0
  56. package/document-management/models/document-tag.model.d.ts +6 -0
  57. package/document-management/models/{document-request-submission.model.js → document-tag.model.js} +14 -18
  58. package/document-management/models/document-type-property.model.d.ts +1 -0
  59. package/document-management/models/document-type-property.model.js +7 -2
  60. package/document-management/models/document-type-validation.model.d.ts +1 -0
  61. package/document-management/models/document-type-validation.model.js +8 -2
  62. package/document-management/models/document-type.model.d.ts +1 -0
  63. package/document-management/models/document-type.model.js +7 -2
  64. package/document-management/models/document-validation-definition.model.d.ts +1 -0
  65. package/document-management/models/document-validation-definition.model.js +7 -2
  66. package/document-management/models/document-validation-execution-related-document.model.d.ts +1 -0
  67. package/document-management/models/document-validation-execution-related-document.model.js +10 -3
  68. package/document-management/models/document-validation-execution.model.d.ts +1 -0
  69. package/document-management/models/document-validation-execution.model.js +9 -3
  70. package/document-management/models/document-workflow.model.d.ts +4 -1
  71. package/document-management/models/document-workflow.model.js +16 -4
  72. package/document-management/models/document.model.d.ts +2 -2
  73. package/document-management/models/document.model.js +9 -8
  74. package/document-management/models/index.d.ts +2 -1
  75. package/document-management/models/index.js +2 -1
  76. package/document-management/server/api/document-management.api.d.ts +4 -1
  77. package/document-management/server/api/document-management.api.js +113 -22
  78. package/document-management/server/configure.d.ts +2 -2
  79. package/document-management/server/configure.js +7 -7
  80. package/document-management/server/drizzle/0000_parallel_mantis.sql +359 -0
  81. package/document-management/server/drizzle/meta/0000_snapshot.json +784 -260
  82. package/document-management/server/drizzle/meta/_journal.json +2 -2
  83. package/document-management/server/module.d.ts +2 -2
  84. package/document-management/server/module.js +2 -2
  85. package/document-management/server/schemas.d.ts +6 -5
  86. package/document-management/server/schemas.js +12 -11
  87. package/document-management/server/services/document-category-type.service.d.ts +19 -10
  88. package/document-management/server/services/document-category-type.service.js +34 -27
  89. package/document-management/server/services/document-collection.service.d.ts +13 -6
  90. package/document-management/server/services/document-collection.service.js +36 -12
  91. package/document-management/server/services/document-file.service.d.ts +8 -7
  92. package/document-management/server/services/document-file.service.js +28 -33
  93. package/document-management/server/services/document-management-ai.service.d.ts +5 -4
  94. package/document-management/server/services/document-management-ai.service.js +51 -28
  95. package/document-management/server/services/document-management-ancillary.service.d.ts +3 -21
  96. package/document-management/server/services/document-management-ancillary.service.js +0 -24
  97. package/document-management/server/services/document-management-observation.service.d.ts +15 -0
  98. package/document-management/server/services/document-management-observation.service.js +160 -0
  99. package/document-management/server/services/document-management.service.d.ts +6 -5
  100. package/document-management/server/services/document-management.service.js +112 -86
  101. package/document-management/server/services/document-property.service.d.ts +15 -7
  102. package/document-management/server/services/document-property.service.js +52 -20
  103. package/document-management/server/services/document-request.service.d.ts +13 -24
  104. package/document-management/server/services/document-request.service.js +39 -62
  105. package/document-management/server/services/document-tag.service.d.ts +10 -0
  106. package/document-management/server/services/document-tag.service.js +59 -0
  107. package/document-management/server/services/document-validation.service.d.ts +8 -8
  108. package/document-management/server/services/document-validation.service.js +41 -40
  109. package/document-management/server/services/document-workflow.service.d.ts +6 -5
  110. package/document-management/server/services/document-workflow.service.js +54 -43
  111. package/document-management/server/services/document.service.d.ts +12 -11
  112. package/document-management/server/services/document.service.js +64 -40
  113. package/document-management/server/services/index.d.ts +2 -1
  114. package/document-management/server/services/index.js +2 -1
  115. package/document-management/server/services/singleton.js +2 -2
  116. package/document-management/server/validators/ai-validation-executor.js +4 -4
  117. package/document-management/service-models/document-collection-metadata.service-model.d.ts +14 -0
  118. package/document-management/service-models/document-collection-metadata.service-model.js +1 -0
  119. package/document-management/service-models/document-folders.view-model.d.ts +1 -7
  120. package/document-management/service-models/document-folders.view-model.js +3 -15
  121. package/document-management/service-models/document-management.view-model.d.ts +20 -6
  122. package/document-management/service-models/document-management.view-model.js +62 -8
  123. package/document-management/service-models/document.service-model.d.ts +14 -11
  124. package/document-management/service-models/document.service-model.js +11 -2
  125. package/document-management/service-models/enriched/enriched-document-assignment.view.d.ts +1 -1
  126. package/document-management/service-models/enriched/enriched-document-assignment.view.js +0 -2
  127. package/document-management/service-models/enriched/enriched-document-category.view.d.ts +11 -1
  128. package/document-management/service-models/enriched/enriched-document-category.view.js +44 -1
  129. package/document-management/service-models/enriched/enriched-document-collection.view.d.ts +4 -2
  130. package/document-management/service-models/enriched/enriched-document-collection.view.js +13 -3
  131. package/document-management/service-models/enriched/enriched-document-management-data.view.d.ts +2 -0
  132. package/document-management/service-models/enriched/enriched-document-management-data.view.js +4 -2
  133. package/document-management/service-models/enriched/enriched-document-request.view.d.ts +1 -0
  134. package/document-management/service-models/enriched/enriched-document-request.view.js +2 -0
  135. package/document-management/service-models/enriched/enriched-document-type.view.d.ts +9 -1
  136. package/document-management/service-models/enriched/enriched-document-type.view.js +28 -1
  137. package/document-management/service-models/enriched/enriched-document.view.d.ts +7 -6
  138. package/document-management/service-models/enriched/enriched-document.view.js +29 -6
  139. package/document-management/service-models/{normalized-requests-template-data.model.d.ts → enriched/enriched-requests-template-data.model.d.ts} +6 -6
  140. package/document-management/service-models/{normalized-requests-template-data.model.js → enriched/enriched-requests-template-data.model.js} +1 -1
  141. package/document-management/service-models/enriched/index.d.ts +1 -0
  142. package/document-management/service-models/enriched/index.js +1 -0
  143. package/document-management/service-models/index.d.ts +2 -2
  144. package/document-management/service-models/index.js +2 -2
  145. package/examples/document-management/categories-and-types.d.ts +33 -31
  146. package/examples/document-management/categories-and-types.js +33 -0
  147. package/examples/document-management/main.d.ts +5 -4
  148. package/examples/document-management/main.js +13 -7
  149. package/function/log.js +2 -2
  150. package/http/server/node/module.d.ts +4 -1
  151. package/http/server/node/module.js +10 -1
  152. package/http/server/node/node-http-server.d.ts +3 -6
  153. package/http/server/node/node-http-server.js +68 -67
  154. package/injector/inject.js +6 -6
  155. package/injector/injector.js +3 -3
  156. package/jsx/is-component-class.js +1 -1
  157. package/key-value-store/key-value.store.d.ts +38 -7
  158. package/key-value-store/key-value.store.js +2 -1
  159. package/key-value-store/mongo/mongo-key-value.store.d.ts +1 -0
  160. package/key-value-store/mongo/mongo-key-value.store.js +14 -5
  161. package/key-value-store/postgres/drizzle/0000_shocking_slipstream.sql +12 -0
  162. package/key-value-store/postgres/drizzle/meta/0000_snapshot.json +97 -0
  163. package/key-value-store/postgres/drizzle/meta/_journal.json +13 -0
  164. package/key-value-store/postgres/drizzle.config.d.ts +2 -0
  165. package/key-value-store/postgres/drizzle.config.js +11 -0
  166. package/key-value-store/postgres/index.d.ts +2 -0
  167. package/key-value-store/postgres/index.js +2 -0
  168. package/key-value-store/postgres/key-value-store.service.d.ts +17 -0
  169. package/key-value-store/postgres/key-value-store.service.js +65 -0
  170. package/key-value-store/postgres/models/index.d.ts +2 -0
  171. package/key-value-store/postgres/models/index.js +2 -0
  172. package/key-value-store/postgres/models/key-value.model.d.ts +7 -0
  173. package/key-value-store/postgres/models/key-value.model.js +35 -0
  174. package/key-value-store/postgres/models/schemas.d.ts +3 -0
  175. package/key-value-store/postgres/models/schemas.js +4 -0
  176. package/key-value-store/postgres/module.d.ts +6 -0
  177. package/key-value-store/postgres/module.js +23 -0
  178. package/lock/web/web-lock.d.ts +0 -1
  179. package/lock/web/web-lock.js +6 -13
  180. package/orm/data-types/timestamp.js +1 -1
  181. package/orm/decorators.d.ts +37 -29
  182. package/orm/decorators.js +44 -24
  183. package/orm/entity.d.ts +1 -0
  184. package/orm/query.d.ts +10 -2
  185. package/orm/repository.types.d.ts +2 -1
  186. package/orm/schemas/json.d.ts +12 -6
  187. package/orm/schemas/json.js +12 -5
  188. package/orm/server/database.js +5 -2
  189. package/orm/server/drizzle/schema-converter.js +40 -11
  190. package/orm/server/query-converter.d.ts +2 -1
  191. package/orm/server/query-converter.js +57 -34
  192. package/orm/server/repository.d.ts +26 -43
  193. package/orm/server/repository.js +106 -39
  194. package/orm/server/transaction.d.ts +2 -1
  195. package/orm/server/transaction.js +3 -0
  196. package/orm/server/transactional.d.ts +5 -1
  197. package/orm/server/transactional.js +34 -4
  198. package/package.json +14 -11
  199. package/process/spawn.js +0 -1
  200. package/promise/deferred-promise.d.ts +4 -3
  201. package/promise/deferred-promise.js +13 -5
  202. package/queue/postgres/queue.js +8 -8
  203. package/reflection/utils.js +3 -3
  204. package/schema/decorators/class.js +0 -1
  205. package/schema/decorators/schema.js +1 -1
  206. package/schema/schemas/boolean.d.ts +1 -1
  207. package/schema/schemas/boolean.js +2 -2
  208. package/schema/schemas/number.js +3 -3
  209. package/schema/schemas/object.js +5 -6
  210. package/sse/server-sent-events-source.js +4 -1
  211. package/utils/compression.js +9 -9
  212. package/utils/date-time.d.ts +1 -0
  213. package/utils/date-time.js +18 -4
  214. package/utils/equals.d.ts +7 -0
  215. package/utils/equals.js +17 -2
  216. package/utils/function/memoize.js +10 -2
  217. package/utils/jwt.js +3 -3
  218. package/utils/object/property-name.d.ts +2 -2
  219. package/utils/timing.d.ts +2 -2
  220. package/utils/timing.js +12 -12
  221. package/document-management/models/document-request-submission.model.d.ts +0 -7
  222. package/document-management/server/drizzle/0000_moaning_luckman.sql +0 -305
  223. package/document-management/server/services/document-management-authorization.service.js +0 -28
@@ -24,8 +24,8 @@ export class BooleanSchema extends SimpleSchema {
24
24
  default:
25
25
  return { success: false };
26
26
  }
27
- }
28
- }
27
+ },
28
+ },
29
29
  });
30
30
  }
31
31
  }
@@ -17,13 +17,13 @@ export class NumberSchema extends SimpleSchema {
17
17
  : { success: true, value: result, valid: true };
18
18
  },
19
19
  boolean: (value) => ({ success: true, value: globalThis.Number(value), valid: true }),
20
- bigint: (value) => ({ success: true, value: globalThis.Number(value), valid: false })
20
+ bigint: (value) => ({ success: true, value: globalThis.Number(value), valid: false }),
21
21
  },
22
22
  constraints: [
23
23
  (options?.integer == true) ? (value) => globalThis.Number.isInteger(value) ? ({ success: true }) : ({ success: false, error: 'Value is not an integer.' }) : null,
24
24
  isNumber(options?.minimum) ? (value) => (value >= this.minimum) ? ({ success: true }) : ({ success: false, error: `Value must be more than or equal to ${this.minimum}.` }) : null,
25
- isNumber(options?.maximum) ? (value) => (value <= this.maximum) ? ({ success: true }) : ({ success: false, error: `Value must be less than or equal to ${this.maximum}.` }) : null
26
- ]
25
+ isNumber(options?.maximum) ? (value) => (value <= this.maximum) ? ({ success: true }) : ({ success: false, error: `Value must be less than or equal to ${this.maximum}.` }) : null,
26
+ ],
27
27
  });
28
28
  this.integer = options?.integer ?? false;
29
29
  this.minimum = options?.minimum ?? null;
@@ -1,4 +1,3 @@
1
- /* eslint-disable max-depth */
2
1
  import { createDecorator, reflectionRegistry } from '../../reflection/index.js';
3
2
  import { SchemaError } from '../../schema/schema.error.js';
4
3
  import { toArray } from '../../utils/array/array.js';
@@ -93,7 +92,7 @@ export function assign(...schemasOrTypes) {
93
92
  mask: schemas.findLast((schema) => isNotNull(schema.mask))?.mask,
94
93
  unknownProperties: schemas.findLast((schema) => isNotNull(schema.unknownProperties))?.unknownProperties,
95
94
  unknownPropertiesKey: schemas.findLast((schema) => isNotNull(schema.unknownPropertiesKey))?.unknownPropertiesKey,
96
- description: schemas.findLast((schema) => isNotNull(schema.description))?.description
95
+ description: schemas.findLast((schema) => isNotNull(schema.description))?.description,
97
96
  });
98
97
  }
99
98
  export function partial(schemaOrType, keyOrKeys) {
@@ -105,7 +104,7 @@ export function partial(schemaOrType, keyOrKeys) {
105
104
  return object(mapObjectValues(schema.properties, mapper), {
106
105
  mask: schema.mask,
107
106
  unknownProperties: schema.unknownProperties,
108
- unknownPropertiesKey: schema.unknownPropertiesKey
107
+ unknownPropertiesKey: schema.unknownPropertiesKey,
109
108
  });
110
109
  }
111
110
  export function pick(schemaOrType, keys) {
@@ -114,7 +113,7 @@ export function pick(schemaOrType, keys) {
114
113
  return object(filterObject(schema.properties, (_, key) => keyArray.includes(key)), {
115
114
  mask: schema.mask,
116
115
  unknownProperties: schema.unknownProperties,
117
- unknownPropertiesKey: schema.unknownPropertiesKey
116
+ unknownPropertiesKey: schema.unknownPropertiesKey,
118
117
  });
119
118
  }
120
119
  export function omit(schemaOrType, keys) {
@@ -123,7 +122,7 @@ export function omit(schemaOrType, keys) {
123
122
  return object(filterObject(schema.properties, (_, key) => !keysArray.includes(key)), {
124
123
  mask: schema.mask,
125
124
  unknownProperties: schema.unknownProperties,
126
- unknownPropertiesKey: schema.unknownPropertiesKey
125
+ unknownPropertiesKey: schema.unknownPropertiesKey,
127
126
  });
128
127
  }
129
128
  export function getSchemaFromReflection(type) {
@@ -152,7 +151,7 @@ function _tryGetSchemaFromReflection(type) {
152
151
  unknownProperties: typeData.unknownProperties,
153
152
  unknownPropertiesKey: typeData.unknownPropertiesKey,
154
153
  description: typeData.description,
155
- example: typeData.example
154
+ example: typeData.example,
156
155
  });
157
156
  const prototype = Reflect.getPrototypeOf(type);
158
157
  if (isNotNull(prototype) && reflectionRegistry.hasType(prototype)) {
@@ -15,7 +15,10 @@ export class ServerSentEventsSource {
15
15
  this.#writer = this.#writable.getWriter();
16
16
  this.#writer.closed
17
17
  .then(() => (this.#closed.set(true)))
18
- .catch((error) => this.#error.set(error));
18
+ .catch((error) => {
19
+ this.#error.set(error);
20
+ this.#closed.set(true);
21
+ });
19
22
  }
20
23
  async close() {
21
24
  await this.#writer.close();
@@ -11,24 +11,24 @@ export function compressString(input, algorithm, options) {
11
11
  export function compress(buffer, algorithm, options) {
12
12
  const compressedBuffer = _compress(buffer, algorithm, options);
13
13
  return {
14
- toBuffer: async () => compressedBuffer,
14
+ toBuffer: async () => await compressedBuffer,
15
15
  toHex: async () => encodeHex(await compressedBuffer),
16
16
  toBase64: async () => encodeBase64(await compressedBuffer),
17
17
  toBase64Url: async () => encodeBase64Url(await compressedBuffer),
18
- toZBase32: async () => zBase32Encode(await compressedBuffer)
18
+ toZBase32: async () => zBase32Encode(await compressedBuffer),
19
19
  };
20
20
  }
21
21
  const compressFunction = {
22
22
  'gzip': 'gzip',
23
23
  'brotli': 'brotliCompress',
24
24
  'deflate': 'deflate',
25
- 'deflate-raw': 'deflateRaw'
25
+ 'deflate-raw': 'deflateRaw',
26
26
  };
27
27
  async function _compress(buffer, algorithm, options) {
28
28
  const zlib = await dynamicImport('zlib');
29
29
  const compressor = zlib[compressFunction[algorithm]];
30
30
  assertDefined(compressor, `Unsupported algorithm ${algorithm}`);
31
- return new Promise((resolve, reject) => {
31
+ return await new Promise((resolve, reject) => {
32
32
  const callback = (error, result) => {
33
33
  if (isNotNullOrUndefined(error)) {
34
34
  reject(error);
@@ -52,12 +52,12 @@ export function decompressString(input, encoding, algorithm, options) {
52
52
  export function decompress(buffer, algorithm, options) {
53
53
  const decompressedBuffer = _decompress(buffer, algorithm, options);
54
54
  return {
55
- toBuffer: async () => decompressedBuffer,
55
+ toBuffer: async () => await decompressedBuffer,
56
56
  toHex: async () => encodeHex(await decompressedBuffer),
57
57
  toBase64: async () => encodeBase64(await decompressedBuffer),
58
58
  toBase64Url: async () => encodeBase64Url(await decompressedBuffer),
59
59
  toZBase32: async () => zBase32Encode(await decompressedBuffer),
60
- toUtf8: async () => decodeText(await decompressedBuffer)
60
+ toUtf8: async () => decodeText(await decompressedBuffer),
61
61
  };
62
62
  }
63
63
  export function decompressStream(stream, algorithm, options) {
@@ -68,13 +68,13 @@ const decompressFunction = {
68
68
  'gzip': 'gunzip',
69
69
  'brotli': 'brotliDecompress',
70
70
  'deflate': 'inflate',
71
- 'deflate-raw': 'inflateRaw'
71
+ 'deflate-raw': 'inflateRaw',
72
72
  };
73
73
  async function _decompress(buffer, algorithm, options) {
74
74
  const zlib = await dynamicImport('zlib');
75
75
  const decompressor = zlib[decompressFunction[algorithm]];
76
76
  assertDefined(decompressor, `Unsupported algorithm ${algorithm}`);
77
- return new Promise((resolve, reject) => {
77
+ return await new Promise((resolve, reject) => {
78
78
  const callback = (error, result) => {
79
79
  if (isNotNullOrUndefined(error)) {
80
80
  reject(error);
@@ -95,7 +95,7 @@ const decompressStreamFunction = {
95
95
  'gzip': 'createGunzip',
96
96
  'brotli': 'createBrotliDecompress',
97
97
  'deflate': 'createInflate',
98
- 'deflate-raw': 'createInflateRaw'
98
+ 'deflate-raw': 'createInflateRaw',
99
99
  };
100
100
  async function _decompressStream(stream, algorithm, options) {
101
101
  const zlib = await dynamicImport('zlib');
@@ -50,6 +50,7 @@ export declare function numericDateToDateObject(numericDate: number): {
50
50
  };
51
51
  export declare function numericDateTimeToTimestamp({ date, time }: NumericDateTime): number;
52
52
  export declare function dateObjectToDateTime(dateObject: ZonedDateObject, units?: DateObjectUnits, options?: DateTimeJSOptions): DateTime;
53
+ export declare function tryDateObjectToNumericDate(dateObject: DateObject): number | null;
53
54
  export declare function dateObjectToNumericDate(dateObject: DateObject): number;
54
55
  export declare function dateTimeToNumericDate(dateTime: DateTime): number;
55
56
  export declare function numericDateToDateTime(numericDate: number, units?: DateObjectUnits, options?: DateTimeJSOptions): DateTime;
@@ -60,13 +60,13 @@ export function numericTimeToTimeObject(time) {
60
60
  hour: Math.floor(time / millisecondsPerHour),
61
61
  minute: Math.floor((time % millisecondsPerHour) / millisecondsPerMinute),
62
62
  second: Math.floor((time % millisecondsPerMinute) / millisecondsPerSecond),
63
- millisecond: Math.floor(time % millisecondsPerSecond)
63
+ millisecond: Math.floor(time % millisecondsPerSecond),
64
64
  };
65
65
  }
66
66
  export function timestampToNumericDateAndTime(timestamp) {
67
67
  return {
68
68
  date: timestampToNumericDate(timestamp),
69
- time: timestampToTime(timestamp)
69
+ time: timestampToTime(timestamp),
70
70
  };
71
71
  }
72
72
  export function numericDateToTimestamp(numericDate) {
@@ -81,17 +81,31 @@ export function numericDateToDateObject(numericDate) {
81
81
  return {
82
82
  year: date.getUTCFullYear(),
83
83
  month: date.getUTCMonth() + 1,
84
- day: date.getUTCDate()
84
+ day: date.getUTCDate(),
85
85
  };
86
86
  }
87
87
  export function numericDateTimeToTimestamp({ date, time }) {
88
88
  return numericDateToTimestamp(date) + time;
89
89
  }
90
90
  export function dateObjectToDateTime(dateObject, units, options) {
91
- return DateTime.fromObject({ ...dateObject, ...units }, options);
91
+ const dateTime = DateTime.fromObject({ ...dateObject, ...units }, options);
92
+ if (!dateTime.isValid) {
93
+ throw new Error(`Invalid date object: ${dateTime.invalidExplanation}`);
94
+ }
95
+ return dateTime;
96
+ }
97
+ export function tryDateObjectToNumericDate(dateObject) {
98
+ const dateTime = DateTime.fromObject({ ...dateObject }, { zone: 'UTC' });
99
+ if (!dateTime.isValid) {
100
+ return null;
101
+ }
102
+ return dateTimeToNumericDate(dateTime);
92
103
  }
93
104
  export function dateObjectToNumericDate(dateObject) {
94
105
  const dateTime = DateTime.fromObject({ ...dateObject }, { zone: 'UTC' });
106
+ if (!dateTime.isValid) {
107
+ throw new Error(`Invalid date: ${dateTime.invalidExplanation}`);
108
+ }
95
109
  return dateTimeToNumericDate(dateTime);
96
110
  }
97
111
  export function dateTimeToNumericDate(dateTime) {
package/utils/equals.d.ts CHANGED
@@ -27,4 +27,11 @@ export declare function equals(a: any, b: any, options?: EqualsOptions, __intern
27
27
  * compares to binary types for equal content
28
28
  */
29
29
  export declare function binaryEquals(bufferA: BinaryData, bufferB: BinaryData): boolean;
30
+ /**
31
+ * Compares two buffers in a way that is resistant to timing attacks.
32
+ * @param untrusted The first buffer to compare. It's length is used to determine the iterations of the comparison. This should be the untrusted input to minimize information leakage.
33
+ * @param trusted The second buffer to compare. This should be the secret.
34
+ * @returns True if the buffers are equal, false otherwise.
35
+ */
36
+ export declare function timingSafeBinaryEquals(untrusted: BinaryData, trusted: BinaryData): boolean;
30
37
  export {};
package/utils/equals.js CHANGED
@@ -5,9 +5,8 @@ import { sort } from './iterable-helpers/sort.js';
5
5
  import { objectKeys } from './object/object.js';
6
6
  import { isDefined, isNotNull, isNull } from './type-guards.js';
7
7
  const equalsSymbol = Symbol('equals');
8
- // eslint-disable-next-line @typescript-eslint/no-redeclare, @typescript-eslint/naming-convention
9
8
  export const Equals = {
10
- symbol: equalsSymbol
9
+ symbol: equalsSymbol,
11
10
  };
12
11
  export function strictEquals(a, b) {
13
12
  return a === b;
@@ -115,3 +114,19 @@ export function binaryEquals(bufferA, bufferB) {
115
114
  }
116
115
  return true;
117
116
  }
117
+ /**
118
+ * Compares two buffers in a way that is resistant to timing attacks.
119
+ * @param untrusted The first buffer to compare. It's length is used to determine the iterations of the comparison. This should be the untrusted input to minimize information leakage.
120
+ * @param trusted The second buffer to compare. This should be the secret.
121
+ * @returns True if the buffers are equal, false otherwise.
122
+ */
123
+ export function timingSafeBinaryEquals(untrusted, trusted) {
124
+ const a = toUint8Array(untrusted, false);
125
+ const b = toUint8Array(trusted, false);
126
+ const compareTarget = (a.length > b.length) ? a : b;
127
+ let diff = a.length ^ b.length;
128
+ for (let i = 0; i < a.length; i++) {
129
+ diff |= a[i] ^ compareTarget[i];
130
+ }
131
+ return diff == 0;
132
+ }
@@ -1,7 +1,7 @@
1
1
  import { IterableWeakMap } from '../../data-structures/iterable-weak-map.js';
2
2
  import { MultiKeyMap } from '../../data-structures/multi-key-map.js';
3
3
  import { createAccessorDecorator } from '../../reflection/index.js';
4
- import { assertDefinedPass } from '../type-guards.js';
4
+ import { assertDefinedPass, isDefined } from '../type-guards.js';
5
5
  /**
6
6
  * Memoizes a function with an arbitrary number of parameters. If you only need a single parameter, {@link memoizeSingle} is faster
7
7
  * @param fn function memoize
@@ -67,6 +67,7 @@ export function Memoize() {
67
67
  return createAccessorDecorator({
68
68
  handler: (data) => {
69
69
  const getter = assertDefinedPass(data.descriptor.get, 'Memoize requires an getter for accessors.'); // eslint-disable-line @typescript-eslint/unbound-method
70
+ const setter = data.descriptor.set; // eslint-disable-line @typescript-eslint/unbound-method
70
71
  function cachedGetter() {
71
72
  if (cache.has(this)) {
72
73
  return cache.get(this); // eslint-disable-line @typescript-eslint/no-unsafe-return
@@ -75,7 +76,14 @@ export function Memoize() {
75
76
  cache.set(this, value);
76
77
  return value; // eslint-disable-line @typescript-eslint/no-unsafe-return
77
78
  }
78
- return { get: cachedGetter };
79
+ function cachedSetter(value) {
80
+ setter?.call(this, value);
81
+ cache.delete(this);
82
+ }
83
+ return {
84
+ get: cachedGetter,
85
+ set: isDefined(setter) ? cachedSetter : undefined,
86
+ };
79
87
  },
80
88
  });
81
89
  }
package/utils/jwt.js CHANGED
@@ -3,7 +3,7 @@ import { toArray } from './array/array.js';
3
3
  import { decodeBase64Url, encodeBase64Url } from './base64.js';
4
4
  import { importHmacKey, sign } from './cryptography.js';
5
5
  import { encodeUtf8 } from './encoding.js';
6
- import { binaryEquals } from './equals.js';
6
+ import { timingSafeBinaryEquals } from './equals.js';
7
7
  export function parseJwtTokenString(tokenString) {
8
8
  const splits = tokenString.split('.');
9
9
  if (splits.length != 3) {
@@ -64,7 +64,7 @@ export async function parseAndValidateJwtTokenString(tokenString, allowedAlgorit
64
64
  throw new InvalidTokenError('Invalid signature algorithm');
65
65
  }
66
66
  const calculatedSignature = await getSignature(encodeUtf8(`${encoded.header}.${encoded.payload}`), token.header.alg, key);
67
- const validSignature = binaryEquals(calculatedSignature, bytes.signature);
67
+ const validSignature = timingSafeBinaryEquals(bytes.signature, calculatedSignature);
68
68
  if (!validSignature) {
69
69
  throw new InvalidTokenError('Invalid token signature');
70
70
  }
@@ -81,7 +81,7 @@ async function getSignature(data, algorithm, secret) {
81
81
  const hashAlgorithm = getHmacHashAlgorithm(algorithm);
82
82
  const hmacKey = await importHmacKey(hashAlgorithm, secret, false);
83
83
  const hmacSignature = sign('HMAC', hmacKey, data);
84
- return hmacSignature.toBuffer();
84
+ return await hmacSignature.toBuffer();
85
85
  }
86
86
  function getHmacHashAlgorithm(algorithm) {
87
87
  return algorithm.replace('HS', 'SHA-');
@@ -16,8 +16,8 @@ export type PropertyNameOfExpressionObject<T> = {
16
16
  };
17
17
  };
18
18
  export type FlatPropertyNameOfExpressionObject<T> = {
19
- [P in keyof DeepFlatten<T>]: FlatPropertyNameOfExpressionObject<DeepFlatten<DeepNonNullable<T>>[P]> & {
20
- [cast]<U extends DeepFlatten<T>[P]>(): FlatPropertyNameOfExpressionObject<DeepNonNullable<U>>;
19
+ [P in keyof DeepFlatten<DeepNonNullable<T>>]: FlatPropertyNameOfExpressionObject<DeepFlatten<DeepNonNullable<T>>[P]> & {
20
+ [cast]<U extends DeepFlatten<DeepNonNullable<T>>[P]>(): FlatPropertyNameOfExpressionObject<DeepNonNullable<U>>;
21
21
  };
22
22
  };
23
23
  export declare function getPropertyName(name: string): PropertyName;
package/utils/timing.d.ts CHANGED
@@ -8,9 +8,9 @@ export declare function timeout(milliseconds?: number, options?: {
8
8
  /** Timeout until specified time */
9
9
  export declare function timeoutUntil(timestamp: number | Date): Promise<void>;
10
10
  /** Timeout for specified duration */
11
- export declare function cancelableTimeout(milliseconds: number, cancelSignal: Observable<void> | CancellationSignal): Promise<boolean>;
11
+ export declare function cancelableTimeout(milliseconds: number, cancelSignal: Observable<void> | CancellationSignal): Promise<'timeout' | 'canceled'>;
12
12
  /** Timeout until specified time */
13
- export declare function cancelableTimeoutUntil(timestamp: number | Date, cancelSignal: Observable<void> | CancellationSignal): Promise<boolean>;
13
+ export declare function cancelableTimeoutUntil(timestamp: number | Date, cancelSignal: Observable<void> | CancellationSignal): Promise<'timeout' | 'canceled'>;
14
14
  export declare function withTimeout<T>(milliseconds: number, promiseOrProvider: ValueOrProvider<Promise<T>>, options?: {
15
15
  errorMessage?: string;
16
16
  }): Promise<T>;
package/utils/timing.js CHANGED
@@ -5,7 +5,7 @@ import { _throw } from './throw.js';
5
5
  import { resolveValueOrProvider } from './value-or-provider.js';
6
6
  /** Timeout for specified duration */
7
7
  export async function timeout(milliseconds = 0, options) {
8
- return new Promise((resolve) => {
8
+ await new Promise((resolve) => {
9
9
  const abortListener = () => clearTimeout(timeoutRef);
10
10
  const timeoutRef = setTimeout(() => {
11
11
  options?.abortSignal?.removeEventListener('abort', abortListener);
@@ -17,39 +17,39 @@ export async function timeout(milliseconds = 0, options) {
17
17
  /** Timeout until specified time */
18
18
  export async function timeoutUntil(timestamp) {
19
19
  const left = timestamp.valueOf() - Date.now();
20
- return timeout(left);
20
+ await timeout(left);
21
21
  }
22
22
  /** Timeout for specified duration */
23
23
  export async function cancelableTimeout(milliseconds, cancelSignal) {
24
24
  const observable = (cancelSignal instanceof CancellationSignal) ? cancelSignal.set$ : cancelSignal;
25
- return firstValueFrom(race([
26
- timer(milliseconds).pipe(map(() => false)),
27
- observable.pipe(map(() => true))
25
+ return await firstValueFrom(race([
26
+ timer(milliseconds).pipe(map(() => 'timeout')),
27
+ observable.pipe(map(() => 'canceled')),
28
28
  ]));
29
29
  }
30
30
  /** Timeout until specified time */
31
31
  export async function cancelableTimeoutUntil(timestamp, cancelSignal) {
32
32
  const left = timestamp.valueOf() - Date.now();
33
- return cancelableTimeout(left, cancelSignal);
33
+ return await cancelableTimeout(left, cancelSignal);
34
34
  }
35
35
  export async function withTimeout(milliseconds, promiseOrProvider, options) {
36
36
  const abortController = new AbortController();
37
37
  const promise = resolveValueOrProvider(promiseOrProvider);
38
38
  void promise.then(() => abortController.abort());
39
- return Promise.race([
39
+ return await Promise.race([
40
40
  promise,
41
- timeout(milliseconds, { abortSignal: abortController.signal }).then(() => _throw(new TimeoutError(options?.errorMessage)))
41
+ timeout(milliseconds, { abortSignal: abortController.signal }).then(() => _throw(new TimeoutError(options?.errorMessage))),
42
42
  ]);
43
43
  }
44
44
  export async function immediate() {
45
- return new Promise(setImmediate);
45
+ await new Promise(setImmediate);
46
46
  }
47
47
  export async function nextTick() {
48
- return new Promise((resolve) => process.nextTick(resolve));
48
+ await new Promise((resolve) => process.nextTick(resolve));
49
49
  }
50
50
  export async function animationFrame() {
51
- return new Promise(requestAnimationFrame);
51
+ return await new Promise(requestAnimationFrame);
52
52
  }
53
53
  export async function idle(timeout) {
54
- return new Promise((resolve) => requestIdleCallback(resolve, { timeout }));
54
+ return await new Promise((resolve) => requestIdleCallback(resolve, { timeout }));
55
55
  }
@@ -1,7 +0,0 @@
1
- import { Entity } from '../../orm/entity.js';
2
- import { Uuid } from '../../orm/types.js';
3
- export declare class DocumentRequestSubmission extends Entity {
4
- static readonly entityName: 'DocumentRequestSubmission';
5
- requestId: Uuid;
6
- documentId: Uuid;
7
- }