@apifuse/provider-sdk 2.2.0-beta.40 → 2.2.0-beta.41

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 (44) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/bin/apifuse-check.ts +61 -0
  3. package/bin/apifuse-migrate-shape.ts +84 -0
  4. package/bin/apifuse-submit-check.ts +1760 -222
  5. package/dist/cli/commands.d.ts +1 -1
  6. package/dist/cli/commands.js +8 -0
  7. package/dist/cli/create.js +6 -0
  8. package/dist/cli/migrate-provider-shape.d.ts +52 -0
  9. package/dist/cli/migrate-provider-shape.js +515 -0
  10. package/dist/cli/templates/provider/provider.json.tpl +6 -0
  11. package/dist/contract.js +1 -0
  12. package/dist/define.js +22 -1
  13. package/dist/error-observability.d.ts +7 -0
  14. package/dist/error-observability.js +61 -0
  15. package/dist/errors.d.ts +15 -0
  16. package/dist/fixture-sanitization.js +13 -3
  17. package/dist/index.d.ts +1 -1
  18. package/dist/provider.d.ts +1 -1
  19. package/dist/runtime/executor.js +11 -1
  20. package/dist/server/error-observability.d.ts +1 -0
  21. package/dist/server/error-observability.js +1 -0
  22. package/dist/server/index.d.ts +2 -1
  23. package/dist/server/self-test.js +3 -0
  24. package/dist/server/serve-implementation.d.ts +12 -0
  25. package/dist/server/serve-implementation.js +135 -66
  26. package/dist/types.d.ts +18 -10
  27. package/package.json +3 -3
  28. package/src/cli/commands.ts +10 -0
  29. package/src/cli/create.ts +6 -0
  30. package/src/cli/migrate-provider-shape.ts +701 -0
  31. package/src/cli/templates/provider/provider.json.tpl +6 -0
  32. package/src/contract.ts +1 -0
  33. package/src/define.ts +33 -1
  34. package/src/error-observability.ts +64 -0
  35. package/src/errors.ts +16 -0
  36. package/src/fixture-sanitization.ts +19 -3
  37. package/src/index.ts +1 -0
  38. package/src/provider.ts +1 -0
  39. package/src/runtime/executor.ts +13 -1
  40. package/src/server/error-observability.ts +1 -0
  41. package/src/server/index.ts +2 -0
  42. package/src/server/self-test.ts +5 -0
  43. package/src/server/serve-implementation.ts +172 -84
  44. package/src/types.ts +38 -27
package/src/types.ts CHANGED
@@ -760,38 +760,13 @@ export interface HealthCheckCaseResult {
760
760
  * so authors get IntelliSense and compile-time errors when accessing fields
761
761
  * that do not exist on the operation's declared output schema.
762
762
  */
763
- export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
763
+ export type HealthCheckCase<TInput = unknown, TOutput = unknown> = {
764
764
  /** Human-readable case name; unique within the suite. */
765
765
  name: string;
766
766
  /** Optional longer description shown on ops dashboards. */
767
767
  description?: string;
768
768
  /** Input passed to the operation handler for this case. */
769
769
  input: TInput;
770
- /**
771
- * Optional runtime input preparation hook for volatile probes. Use this when
772
- * the durable probe input must be derived from a live read-only operation
773
- * immediately before the checked operation executes.
774
- */
775
- prepareInput?: (
776
- ctx: HealthCheckInputPreparationContext<TInput>,
777
- ) => TInput | Promise<TInput>;
778
- /**
779
- * Assertion executed against the operation's response and timing.
780
- *
781
- * - Throw to fail the case (recorded as `down`).
782
- * - Return `{ status: "degraded", label }` to flag without failing.
783
- * - Return `void` (implicit) for `ok`.
784
- *
785
- * MUST NOT access scheduler, recorder, or any runtime type — pure data
786
- * + lambda only.
787
- */
788
- assertions: (
789
- ctx: HealthCheckAssertionContext<TOutput>,
790
- ) =>
791
- | void
792
- | Promise<void>
793
- | HealthCheckCaseResult
794
- | Promise<HealthCheckCaseResult>;
795
770
  /** Override per-case degradation threshold (ms); falls back to the suite default. */
796
771
  degradedThresholdMs?: number;
797
772
  /** Override per-case timeout in milliseconds; falls back to the suite/provider/runtime default. */
@@ -800,7 +775,43 @@ export interface HealthCheckCase<TInput = unknown, TOutput = unknown> {
800
775
  expectedStatus?: "ok" | "degraded";
801
776
  /** Runtime gate (env-driven); if returns false the case is skipped & logged. */
802
777
  enabled?: () => boolean;
803
- }
778
+ } & (
779
+ | {
780
+ /**
781
+ * Optional runtime input preparation hook for volatile probes. Use this when
782
+ * the durable probe input must be derived from a live read-only operation
783
+ * immediately before the checked operation executes.
784
+ */
785
+ prepareInput?: (
786
+ ctx: HealthCheckInputPreparationContext<TInput>,
787
+ ) => TInput | Promise<TInput>;
788
+ /**
789
+ * Assertion executed against the operation's response and timing.
790
+ *
791
+ * - Throw to fail the case (recorded as `down`).
792
+ * - Return `{ status: "degraded", label }` to flag without failing.
793
+ * - Return `void` (implicit) for `ok`.
794
+ *
795
+ * MUST NOT access scheduler, recorder, or any runtime type — pure data
796
+ * + lambda only.
797
+ */
798
+ assertions: (
799
+ ctx: HealthCheckAssertionContext<TOutput>,
800
+ ) =>
801
+ | void
802
+ | Promise<void>
803
+ | HealthCheckCaseResult
804
+ | Promise<HealthCheckCaseResult>;
805
+ /** Declarative scenarios replace the imperative preparation and assertion hooks. */
806
+ scenario?: never;
807
+ }
808
+ | {
809
+ /** Declarative scenario executed by the health-monitor runtime. */
810
+ scenario: HealthScenario;
811
+ prepareInput?: never;
812
+ assertions?: never;
813
+ }
814
+ );
804
815
 
805
816
  /**
806
817
  * Operation-level health-check suite. At least one case is required when