@specific.dev/spectest 0.35.1 → 0.36.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.
@@ -1,3 +1,4 @@
1
+ import type { ServiceSetupContext } from "../index.js";
1
2
  import { type SqlClient } from "../sql.js";
2
3
  export interface PostgresOptions {
3
4
  /** Image tag for the official `postgres` image. Default `"18-alpine"`.
@@ -32,6 +33,28 @@ export interface PostgresOptions {
32
33
  args?: string[];
33
34
  /** Extra environment variables forwarded to the container. */
34
35
  env?: Record<string, string>;
36
+ /**
37
+ * One-shot hook that runs after the ready probe passes, before any
38
+ * dependent service starts and before any test. This is where schema
39
+ * and seed data go: the daemon captures the result into the
40
+ * warm-template snapshot, so it never runs again on a warm start or a
41
+ * fork.
42
+ *
43
+ * The argument is the full test context plus this service's `name` and
44
+ * its {@link PostgresHelpers}, so the instrumented client is already
45
+ * built:
46
+ *
47
+ * ```ts
48
+ * db: postgres({
49
+ * database: "todos", user: "todos", password: "todos",
50
+ * setup: async ({ helpers }) => {
51
+ * await helpers.client`CREATE TABLE todos (
52
+ * id SERIAL PRIMARY KEY, text TEXT NOT NULL)`;
53
+ * },
54
+ * }),
55
+ * ```
56
+ */
57
+ setup?: (args: ServiceSetupContext<PostgresHelpers>) => void | Promise<void>;
35
58
  }
36
59
  /** Helpers a `postgres(...)` service exposes on `ctx.svc.<name>`. */
37
60
  export interface PostgresHelpers {
@@ -67,6 +90,7 @@ export interface PostgresHelpers {
67
90
  * ```
68
91
  */
69
92
  export declare function postgres(opts: PostgresOptions): {
93
+ setup?: ((args: ServiceSetupContext<PostgresHelpers>) => void | Promise<void>) | undefined;
70
94
  env: {
71
95
  POSTGRES_DB: string;
72
96
  POSTGRES_USER: string;
@@ -54,5 +54,10 @@ export function postgres(opts) {
54
54
  `@${name}:${port}/${encodeURIComponent(opts.database)}`;
55
55
  return { client: new SQL(url, { label: name }) };
56
56
  },
57
+ // The user's hook, forwarded verbatim — postgres() declares none of
58
+ // its own. If it ever gains one, CHAIN the user's after it (the way
59
+ // `serviceGroup` chains a group hook after the primary part's) rather
60
+ // than letting either one win.
61
+ ...(opts.setup ? { setup: opts.setup } : {}),
57
62
  };
58
63
  }
package/dist/index.d.ts CHANGED
@@ -455,8 +455,17 @@ export interface ServiceDefinition<H extends Record<string, any> = Record<string
455
455
  }
456
456
  /** A services map — what users pass to `environment.services`. Entries
457
457
  * can be plain `ServiceConfig` literals or `ServiceDefinition`s that
458
- * carry a `helpers` factory (e.g. what `postgres(...)` returns). */
459
- export type ServicesMap = Record<string, ServiceConfig>;
458
+ * carry a `helpers` factory (e.g. what `postgres(...)` returns).
459
+ *
460
+ * The entry type is `ServiceDefinition`, not `ServiceConfig`: at runtime
461
+ * the map really does hold `helpers`/`setup` (the daemon reads them off
462
+ * each entry), and both are optional, so every plain `ServiceConfig`
463
+ * still satisfies it. Narrowing this to `ServiceConfig` — the wire type,
464
+ * which by definition carries no functions — made the natural way to
465
+ * hoist a services map out of `index.ts` (`… satisfies ServicesMap`) fail
466
+ * the typecheck on any service declaring a hook, while the same literal
467
+ * written inline passed. */
468
+ export type ServicesMap = Record<string, ServiceDefinition<any>>;
460
469
  /** Awaited return type of a service's `helpers` factory, or `never` if
461
470
  * the service doesn't ship one. */
462
471
  type HelpersOf<D> = D extends {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specific.dev/spectest",
3
- "version": "0.35.1",
3
+ "version": "0.36.0",
4
4
  "description": "Spectest SDK for defining test environments in TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",