@checkstack/common 0.13.0 → 0.14.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @checkstack/common
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 13373ce: Break the publish-time dependency cycle between `@checkstack/backend-api` and `@checkstack/cache-api` / `@checkstack/queue-api`.
8
+
9
+ `cache-api` and `queue-api` only ever used `Logger` and `Migration` from `backend-api` as `import type`, yet declared `@checkstack/backend-api` as a runtime dependency. In the monorepo this is harmless (everything resolves via `workspace:*`), but once published, `bun publish` freezes each `workspace:*` into a concrete pin of the _other_ package's then-current version. Because the dependency is mutual, a consumer installing these packages from the registry must resolve `backend-api -> cache-api -> backend-api -> ...` backward through release history until it reaches ancient versions that shipped raw `workspace:*` ranges and a long-removed `@checkstack/cache-api@0.1.0` pin - which fail to resolve. This surfaced as `bun install` errors (and a missing `checkstack-dev` binary) in freshly scaffolded standalone plugins.
10
+
11
+ `Logger` and `Migration` now live in `@checkstack/common` (a dependency-free leaf package). `@checkstack/backend-api` re-exports both for backward compatibility, so existing `import type { Logger, Migration } from "@checkstack/backend-api"` call sites are unchanged. `cache-api` and `queue-api` now depend on `@checkstack/common` instead of `@checkstack/backend-api`, removing the cycle.
12
+
3
13
  ## 0.13.0
4
14
 
5
15
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/common",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "license": "Elastic-2.0",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -20,7 +20,7 @@
20
20
  "devDependencies": {
21
21
  "typescript": "^5.7.2",
22
22
  "@checkstack/tsconfig": "0.0.7",
23
- "@checkstack/scripts": "0.3.4"
23
+ "@checkstack/scripts": "0.4.0"
24
24
  },
25
25
  "scripts": {
26
26
  "typecheck": "tsgo -b",
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from "./types";
2
+ export * from "./logger";
3
+ export * from "./migration";
2
4
  export * from "./actor";
3
5
  export * from "./pagination";
4
6
  export * from "./routes";
package/src/logger.ts ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Backend logger interface used everywhere in the platform via `RpcContext.logger`
3
+ * and the various `coreServices.logger` accessors.
4
+ *
5
+ * Each method accepts a free-form trailing argument list (`...args: unknown[]`)
6
+ * so the long-standing varargs callsites - `logger.error("…", err)` where `err`
7
+ * is an `Error`, or `logger.info("…", value1, value2)` - keep working unchanged.
8
+ *
9
+ * For NEW code, prefer the structured-metadata shape:
10
+ *
11
+ * logger.info("did something", { userId, durationMs });
12
+ *
13
+ * Winston's `splat` handling treats a single trailing plain object as
14
+ * structured metadata (merged into the log entry), and an `Error` instance as
15
+ * a special-cased error (with stack). Either shape lands in the same vararg
16
+ * slot here, so this signature covers both without overload churn.
17
+ *
18
+ * Auto-injected metadata (when the request flows through
19
+ * `correlationMiddleware`): `{ correlationId, pluginId, userId? }`. Do NOT
20
+ * include secrets in the structured-metadata object - it is forwarded
21
+ * verbatim to the log destination.
22
+ *
23
+ * Lives in `@checkstack/common` (rather than `@checkstack/backend-api`) so that
24
+ * low-level packages such as `@checkstack/cache-api` and `@checkstack/queue-api`
25
+ * can reference it without taking a dependency on `backend-api` - which would
26
+ * create a publish-time dependency cycle. `@checkstack/backend-api` re-exports
27
+ * it for backward compatibility.
28
+ */
29
+ export interface Logger {
30
+ info(message: string, ...args: unknown[]): void;
31
+ error(message: string, ...args: unknown[]): void;
32
+ warn(message: string, ...args: unknown[]): void;
33
+ debug(message: string, ...args: unknown[]): void;
34
+ /**
35
+ * Returns a derived logger with the supplied metadata bound to every
36
+ * subsequent log entry. Used by `correlationMiddleware` to attach
37
+ * `{ correlationId, pluginId, userId? }`, and available to handlers that
38
+ * want a tighter scope (e.g. `ctx.logger.child({ jobId })`).
39
+ *
40
+ * Optional only to keep minimal test-mock logger objects compatible with
41
+ * this interface - production loggers (Winston via `core/backend`) always
42
+ * implement it. Call sites that rely on metadata binding should branch
43
+ * on presence and fall back to the base logger when it is not available.
44
+ */
45
+ child?(meta: Record<string, unknown>): Logger;
46
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Type-safe migration from one data version to another.
3
+ * Used for backward-compatible schema evolution (see `Versioned` /
4
+ * `MigrationBuilder` in `@checkstack/backend-api`).
5
+ *
6
+ * Lives in `@checkstack/common` (rather than `@checkstack/backend-api`) so that
7
+ * low-level packages such as `@checkstack/cache-api` and `@checkstack/queue-api`
8
+ * can reference it without taking a dependency on `backend-api` - which would
9
+ * create a publish-time dependency cycle. `@checkstack/backend-api` re-exports
10
+ * it for backward compatibility.
11
+ */
12
+ export interface Migration<TFrom = unknown, TTo = unknown> {
13
+ /** Version number migrating from */
14
+ fromVersion: number;
15
+ /** Version number migrating to (must be fromVersion + 1) */
16
+ toVersion: number;
17
+ /** Human-readable description of what this migration does */
18
+ description: string;
19
+ /** Migration function that transforms old data to new format */
20
+ migrate(data: TFrom): TTo | Promise<TTo>;
21
+ }