@tahminator/sapling 2.1.0-beta.39c06f1e → 2.1.0-beta.4344e0ca

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.
package/dist/index.cjs CHANGED
@@ -409,7 +409,7 @@ let HealthRegistrar = class HealthRegistrar {
409
409
  /**
410
410
  * Add a health check.
411
411
  *
412
- * Health checks will be used to determine whether service can service traffic or not (a.k.a `liveness`).
412
+ * Health checks will be used to determine whether service can serve traffic or not (a.k.a `liveness`).
413
413
  */
414
414
  add(healthCheck) {
415
415
  this._checks.push(healthCheck);
@@ -421,7 +421,16 @@ let HealthRegistrar = class HealthRegistrar {
421
421
  _markReady() {
422
422
  this._ready = true;
423
423
  }
424
- async check() {
424
+ /**
425
+ * @internal
426
+ */
427
+ async ready() {
428
+ return this._ready;
429
+ }
430
+ /**
431
+ * @internal
432
+ */
433
+ async live() {
425
434
  if (!this._ready) return false;
426
435
  return (await Promise.all(this._checks.map((c) => c()))).every((c) => c === true);
427
436
  }
@@ -516,7 +525,7 @@ var Sapling = class Sapling {
516
525
  return function(...args) {
517
526
  const server = originalListen.apply(target, args);
518
527
  server.once("listening", () => {
519
- Sapling.onPostStartup();
528
+ Sapling._onPostStartup();
520
529
  console.log("Sapling successfully initialized post-startup hooks on server start");
521
530
  });
522
531
  return server;
@@ -525,7 +534,11 @@ var Sapling = class Sapling {
525
534
  return Reflect.get(target, prop, receiver);
526
535
  } });
527
536
  }
528
- static onPostStartup() {
537
+ /**
538
+ * @internal
539
+ * visible for testing
540
+ */
541
+ static _onPostStartup() {
529
542
  _InjectableRegistry.get(HealthRegistrar)?._markReady();
530
543
  }
531
544
  /**
@@ -1213,11 +1226,11 @@ let DefaultHealthMiddleware = class DefaultHealthMiddleware {
1213
1226
  this.healthRegistrar = healthRegistrar;
1214
1227
  }
1215
1228
  async readiness(_request, _response, _next) {
1216
- const up = await this.healthRegistrar.check();
1229
+ const up = await this.healthRegistrar.ready();
1217
1230
  return ResponseEntity.ok().body({ up });
1218
1231
  }
1219
1232
  async liveness(_request, _response, _next) {
1220
- const up = await this.healthRegistrar.check();
1233
+ const up = await this.healthRegistrar.live();
1221
1234
  return ResponseEntity.ok().body({ up });
1222
1235
  }
1223
1236
  };
package/dist/index.d.cts CHANGED
@@ -853,7 +853,11 @@ declare class Sapling {
853
853
  * ```
854
854
  */
855
855
  static registerApp(app: e.Express): e.Express;
856
- static onPostStartup(): void;
856
+ /**
857
+ * @internal
858
+ * visible for testing
859
+ */
860
+ static _onPostStartup(): void;
857
861
  /**
858
862
  * Serialize a value into a JSON string.
859
863
  *
@@ -1123,7 +1127,7 @@ declare class HealthRegistrar {
1123
1127
  /**
1124
1128
  * Add a health check.
1125
1129
  *
1126
- * Health checks will be used to determine whether service can service traffic or not (a.k.a `liveness`).
1130
+ * Health checks will be used to determine whether service can serve traffic or not (a.k.a `liveness`).
1127
1131
  */
1128
1132
  add(healthCheck: HealthCheck): void;
1129
1133
  /**
@@ -1131,7 +1135,14 @@ declare class HealthRegistrar {
1131
1135
  * checks have been registered and server is, at the very least, alive.
1132
1136
  */
1133
1137
  _markReady(): void;
1134
- check(): Promise<boolean>;
1138
+ /**
1139
+ * @internal
1140
+ */
1141
+ ready(): Promise<boolean>;
1142
+ /**
1143
+ * @internal
1144
+ */
1145
+ live(): Promise<boolean>;
1135
1146
  }
1136
1147
  //#endregion
1137
1148
  //#region src/middleware/default/health/index.d.ts
package/dist/index.d.mts CHANGED
@@ -853,7 +853,11 @@ declare class Sapling {
853
853
  * ```
854
854
  */
855
855
  static registerApp(app: e.Express): e.Express;
856
- static onPostStartup(): void;
856
+ /**
857
+ * @internal
858
+ * visible for testing
859
+ */
860
+ static _onPostStartup(): void;
857
861
  /**
858
862
  * Serialize a value into a JSON string.
859
863
  *
@@ -1123,7 +1127,7 @@ declare class HealthRegistrar {
1123
1127
  /**
1124
1128
  * Add a health check.
1125
1129
  *
1126
- * Health checks will be used to determine whether service can service traffic or not (a.k.a `liveness`).
1130
+ * Health checks will be used to determine whether service can serve traffic or not (a.k.a `liveness`).
1127
1131
  */
1128
1132
  add(healthCheck: HealthCheck): void;
1129
1133
  /**
@@ -1131,7 +1135,14 @@ declare class HealthRegistrar {
1131
1135
  * checks have been registered and server is, at the very least, alive.
1132
1136
  */
1133
1137
  _markReady(): void;
1134
- check(): Promise<boolean>;
1138
+ /**
1139
+ * @internal
1140
+ */
1141
+ ready(): Promise<boolean>;
1142
+ /**
1143
+ * @internal
1144
+ */
1145
+ live(): Promise<boolean>;
1135
1146
  }
1136
1147
  //#endregion
1137
1148
  //#region src/middleware/default/health/index.d.ts
package/dist/index.mjs CHANGED
@@ -384,7 +384,7 @@ let HealthRegistrar = class HealthRegistrar {
384
384
  /**
385
385
  * Add a health check.
386
386
  *
387
- * Health checks will be used to determine whether service can service traffic or not (a.k.a `liveness`).
387
+ * Health checks will be used to determine whether service can serve traffic or not (a.k.a `liveness`).
388
388
  */
389
389
  add(healthCheck) {
390
390
  this._checks.push(healthCheck);
@@ -396,7 +396,16 @@ let HealthRegistrar = class HealthRegistrar {
396
396
  _markReady() {
397
397
  this._ready = true;
398
398
  }
399
- async check() {
399
+ /**
400
+ * @internal
401
+ */
402
+ async ready() {
403
+ return this._ready;
404
+ }
405
+ /**
406
+ * @internal
407
+ */
408
+ async live() {
400
409
  if (!this._ready) return false;
401
410
  return (await Promise.all(this._checks.map((c) => c()))).every((c) => c === true);
402
411
  }
@@ -491,7 +500,7 @@ var Sapling = class Sapling {
491
500
  return function(...args) {
492
501
  const server = originalListen.apply(target, args);
493
502
  server.once("listening", () => {
494
- Sapling.onPostStartup();
503
+ Sapling._onPostStartup();
495
504
  console.log("Sapling successfully initialized post-startup hooks on server start");
496
505
  });
497
506
  return server;
@@ -500,7 +509,11 @@ var Sapling = class Sapling {
500
509
  return Reflect.get(target, prop, receiver);
501
510
  } });
502
511
  }
503
- static onPostStartup() {
512
+ /**
513
+ * @internal
514
+ * visible for testing
515
+ */
516
+ static _onPostStartup() {
504
517
  _InjectableRegistry.get(HealthRegistrar)?._markReady();
505
518
  }
506
519
  /**
@@ -1188,11 +1201,11 @@ let DefaultHealthMiddleware = class DefaultHealthMiddleware {
1188
1201
  this.healthRegistrar = healthRegistrar;
1189
1202
  }
1190
1203
  async readiness(_request, _response, _next) {
1191
- const up = await this.healthRegistrar.check();
1204
+ const up = await this.healthRegistrar.ready();
1192
1205
  return ResponseEntity.ok().body({ up });
1193
1206
  }
1194
1207
  async liveness(_request, _response, _next) {
1195
- const up = await this.healthRegistrar.check();
1208
+ const up = await this.healthRegistrar.live();
1196
1209
  return ResponseEntity.ok().body({ up });
1197
1210
  }
1198
1211
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tahminator/sapling",
3
- "version": "2.1.0-beta.39c06f1e",
3
+ "version": "2.1.0-beta.4344e0ca",
4
4
  "author": "Tahmid Ahmed",
5
5
  "description": "A library to help you write cleaner Express.js code",
6
6
  "repository": {