@prisma-next/contract 0.3.0-dev.4 → 0.3.0-dev.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.
@@ -0,0 +1,658 @@
1
+ import type { RenderTypeContext, TypesImportSpec } from './types';
2
+
3
+ /**
4
+ * A template-based type renderer (structured form).
5
+ * Uses mustache-style placeholders (e.g., `Vector<{{length}}>`) that are
6
+ * replaced with typeParams values during rendering.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * { kind: 'template', template: 'Vector<{{length}}>' }
11
+ * // With typeParams { length: 1536 }, renders: 'Vector<1536>'
12
+ * ```
13
+ */
14
+ export interface TypeRendererTemplate {
15
+ readonly kind: 'template';
16
+ /** Template string with `{{key}}` placeholders for typeParams values */
17
+ readonly template: string;
18
+ }
19
+
20
+ /**
21
+ * A function-based type renderer for full control over type expression generation.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * {
26
+ * kind: 'function',
27
+ * render: (params, ctx) => `Vector<${params.length}>`
28
+ * }
29
+ * ```
30
+ */
31
+ export interface TypeRendererFunction {
32
+ readonly kind: 'function';
33
+ /** Render function that produces a TypeScript type expression */
34
+ readonly render: (params: Record<string, unknown>, ctx: RenderTypeContext) => string;
35
+ }
36
+
37
+ /**
38
+ * A raw template string type renderer (convenience form).
39
+ * Shorthand for TypeRendererTemplate - just the template string without wrapper.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * 'Vector<{{length}}>'
44
+ * // Equivalent to: { kind: 'template', template: 'Vector<{{length}}>' }
45
+ * ```
46
+ */
47
+ export type TypeRendererString = string;
48
+
49
+ /**
50
+ * A raw function type renderer (convenience form).
51
+ * Shorthand for TypeRendererFunction - just the function without wrapper.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * (params, ctx) => `Vector<${params.length}>`
56
+ * // Equivalent to: { kind: 'function', render: ... }
57
+ * ```
58
+ */
59
+ export type TypeRendererRawFunction = (
60
+ params: Record<string, unknown>,
61
+ ctx: RenderTypeContext,
62
+ ) => string;
63
+
64
+ /**
65
+ * Union of type renderer formats.
66
+ *
67
+ * Supports both structured forms (with `kind` discriminator) and convenience forms:
68
+ * - `string` - Template string with `{{key}}` placeholders (manifest-safe, JSON-serializable)
69
+ * - `function` - Render function for full control (requires runtime execution)
70
+ * - `{ kind: 'template', template: string }` - Structured template form
71
+ * - `{ kind: 'function', render: fn }` - Structured function form
72
+ *
73
+ * Templates are normalized to functions during pack assembly.
74
+ * **Prefer template strings** for most cases - they are JSON-serializable.
75
+ */
76
+ export type TypeRenderer =
77
+ | TypeRendererString
78
+ | TypeRendererRawFunction
79
+ | TypeRendererTemplate
80
+ | TypeRendererFunction;
81
+
82
+ /**
83
+ * Normalized type renderer - always a function after assembly.
84
+ * This is the form received by the emitter.
85
+ */
86
+ export interface NormalizedTypeRenderer {
87
+ readonly codecId: string;
88
+ readonly render: (params: Record<string, unknown>, ctx: RenderTypeContext) => string;
89
+ }
90
+
91
+ /**
92
+ * Interpolates a template string with params values.
93
+ * Used internally by normalizeRenderer to compile templates to functions.
94
+ *
95
+ * @throws Error if a placeholder key is not found in params (except 'CodecTypes')
96
+ */
97
+ export function interpolateTypeTemplate(
98
+ template: string,
99
+ params: Record<string, unknown>,
100
+ ctx: RenderTypeContext,
101
+ ): string {
102
+ return template.replace(/\{\{(\w+)\}\}/g, (_, key: string) => {
103
+ if (key === 'CodecTypes') return ctx.codecTypesName;
104
+ const value = params[key];
105
+ if (value === undefined) {
106
+ throw new Error(
107
+ `Missing template parameter "${key}" in template "${template}". ` +
108
+ `Available params: ${Object.keys(params).join(', ') || '(none)'}`,
109
+ );
110
+ }
111
+ return String(value);
112
+ });
113
+ }
114
+
115
+ /**
116
+ * Normalizes a TypeRenderer to function form.
117
+ * Called during pack assembly, not at emission time.
118
+ *
119
+ * Handles all TypeRenderer forms:
120
+ * - Raw string template: `'Vector<{{length}}>'`
121
+ * - Raw function: `(params, ctx) => ...`
122
+ * - Structured template: `{ kind: 'template', template: '...' }`
123
+ * - Structured function: `{ kind: 'function', render: fn }`
124
+ */
125
+ export function normalizeRenderer(codecId: string, renderer: TypeRenderer): NormalizedTypeRenderer {
126
+ // Handle raw string (template shorthand)
127
+ if (typeof renderer === 'string') {
128
+ return {
129
+ codecId,
130
+ render: (params, ctx) => interpolateTypeTemplate(renderer, params, ctx),
131
+ };
132
+ }
133
+
134
+ // Handle raw function (function shorthand)
135
+ if (typeof renderer === 'function') {
136
+ return { codecId, render: renderer };
137
+ }
138
+
139
+ // Handle structured function form
140
+ if (renderer.kind === 'function') {
141
+ return { codecId, render: renderer.render };
142
+ }
143
+
144
+ // Handle structured template form
145
+ const { template } = renderer;
146
+ return {
147
+ codecId,
148
+ render: (params, ctx) => interpolateTypeTemplate(template, params, ctx),
149
+ };
150
+ }
151
+
152
+ /**
153
+ * Declarative fields that describe component metadata.
154
+ */
155
+ export interface ComponentMetadata {
156
+ /** Component version (semver) */
157
+ readonly version: string;
158
+
159
+ /**
160
+ * Capabilities this component provides.
161
+ *
162
+ * For adapters, capabilities must be declared on the adapter descriptor (so they are emitted into
163
+ * the contract) and also exposed in runtime adapter code (e.g. `adapter.profile.capabilities`);
164
+ * keep these declarations in sync. Targets are identifiers/descriptors and typically do not
165
+ * declare capabilities.
166
+ */
167
+ readonly capabilities?: Record<string, unknown>;
168
+
169
+ /** Type imports for contract.d.ts generation */
170
+ readonly types?: {
171
+ readonly codecTypes?: {
172
+ /**
173
+ * Base codec types import spec.
174
+ * Optional: adapters typically provide this, extensions usually don't.
175
+ */
176
+ readonly import?: TypesImportSpec;
177
+ /**
178
+ * Optional renderers for parameterized codecs owned by this component.
179
+ * Key is codecId (e.g., 'pg/vector@1'), value is the type renderer.
180
+ *
181
+ * Templates are normalized to functions during pack assembly.
182
+ * Duplicate codecId across descriptors is a hard error.
183
+ */
184
+ readonly parameterized?: Record<string, TypeRenderer>;
185
+ /**
186
+ * Optional additional type-only imports required by parameterized renderers.
187
+ *
188
+ * These imports are included in generated `contract.d.ts` but are NOT treated as
189
+ * codec type maps (i.e., they should not be intersected into `export type CodecTypes = ...`).
190
+ *
191
+ * Example: `Vector<N>` for pgvector renderers that emit `Vector<{{length}}>`
192
+ */
193
+ readonly typeImports?: ReadonlyArray<TypesImportSpec>;
194
+ /**
195
+ * Optional control-plane hooks keyed by codecId.
196
+ * Used by family-specific planners/verifiers to handle storage types.
197
+ */
198
+ readonly controlPlaneHooks?: Record<string, unknown>;
199
+ };
200
+ readonly operationTypes?: { readonly import: TypesImportSpec };
201
+ readonly storage?: ReadonlyArray<{
202
+ readonly typeId: string;
203
+ readonly familyId: string;
204
+ readonly targetId: string;
205
+ readonly nativeType?: string;
206
+ }>;
207
+ };
208
+ }
209
+
210
+ /**
211
+ * Base descriptor for any framework component.
212
+ *
213
+ * All component descriptors share these fundamental properties that identify
214
+ * the component and provide its metadata. This interface is extended by
215
+ * specific descriptor types (FamilyDescriptor, TargetDescriptor, etc.).
216
+ *
217
+ * @template Kind - Discriminator literal identifying the component type.
218
+ * Built-in kinds are 'family', 'target', 'adapter', 'driver', 'extension',
219
+ * but the type accepts any string to allow ecosystem extensions.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * // All descriptors have these properties
224
+ * descriptor.kind // The Kind type parameter (e.g., 'family', 'target', or custom kinds)
225
+ * descriptor.id // Unique string identifier (e.g., 'sql', 'postgres')
226
+ * descriptor.version // Component version (semver)
227
+ * ```
228
+ */
229
+ export interface ComponentDescriptor<Kind extends string> extends ComponentMetadata {
230
+ /** Discriminator identifying the component type */
231
+ readonly kind: Kind;
232
+
233
+ /** Unique identifier for this component (e.g., 'sql', 'postgres', 'pgvector') */
234
+ readonly id: string;
235
+ }
236
+
237
+ export interface ContractComponentRequirementsCheckInput {
238
+ readonly contract: {
239
+ readonly target: string;
240
+ readonly targetFamily?: string | undefined;
241
+ readonly extensionPacks?: Record<string, unknown> | undefined;
242
+ };
243
+ readonly expectedTargetFamily?: string | undefined;
244
+ readonly expectedTargetId?: string | undefined;
245
+ readonly providedComponentIds: Iterable<string>;
246
+ }
247
+
248
+ export interface ContractComponentRequirementsCheckResult {
249
+ readonly familyMismatch?: { readonly expected: string; readonly actual: string } | undefined;
250
+ readonly targetMismatch?: { readonly expected: string; readonly actual: string } | undefined;
251
+ readonly missingExtensionPackIds: readonly string[];
252
+ }
253
+
254
+ export function checkContractComponentRequirements(
255
+ input: ContractComponentRequirementsCheckInput,
256
+ ): ContractComponentRequirementsCheckResult {
257
+ const providedIds = new Set<string>();
258
+ for (const id of input.providedComponentIds) {
259
+ providedIds.add(id);
260
+ }
261
+
262
+ const requiredExtensionPackIds = input.contract.extensionPacks
263
+ ? Object.keys(input.contract.extensionPacks)
264
+ : [];
265
+ const missingExtensionPackIds = requiredExtensionPackIds.filter((id) => !providedIds.has(id));
266
+
267
+ const expectedTargetFamily = input.expectedTargetFamily;
268
+ const contractTargetFamily = input.contract.targetFamily;
269
+ const familyMismatch =
270
+ expectedTargetFamily !== undefined &&
271
+ contractTargetFamily !== undefined &&
272
+ contractTargetFamily !== expectedTargetFamily
273
+ ? { expected: expectedTargetFamily, actual: contractTargetFamily }
274
+ : undefined;
275
+
276
+ const expectedTargetId = input.expectedTargetId;
277
+ const contractTargetId = input.contract.target;
278
+ const targetMismatch =
279
+ expectedTargetId !== undefined && contractTargetId !== expectedTargetId
280
+ ? { expected: expectedTargetId, actual: contractTargetId }
281
+ : undefined;
282
+
283
+ return {
284
+ ...(familyMismatch ? { familyMismatch } : {}),
285
+ ...(targetMismatch ? { targetMismatch } : {}),
286
+ missingExtensionPackIds,
287
+ };
288
+ }
289
+
290
+ /**
291
+ * Descriptor for a family component.
292
+ *
293
+ * A "family" represents a category of data sources with shared semantics
294
+ * (e.g., SQL databases, document stores). Families define:
295
+ * - Query semantics and operations (SELECT, INSERT, find, aggregate, etc.)
296
+ * - Contract structure (tables vs collections, columns vs fields)
297
+ * - Type system and codecs
298
+ *
299
+ * Families are the top-level grouping. Each family contains multiple targets
300
+ * (e.g., SQL family contains Postgres, MySQL, SQLite targets).
301
+ *
302
+ * Extended by plane-specific descriptors:
303
+ * - `ControlFamilyDescriptor` - adds `hook` for CLI/tooling operations
304
+ * - `RuntimeFamilyDescriptor` - adds runtime-specific factory methods
305
+ *
306
+ * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')
307
+ *
308
+ * @example
309
+ * ```ts
310
+ * import sql from '@prisma-next/family-sql/control';
311
+ *
312
+ * sql.kind // 'family'
313
+ * sql.familyId // 'sql'
314
+ * sql.id // 'sql'
315
+ * ```
316
+ */
317
+ export interface FamilyDescriptor<TFamilyId extends string> extends ComponentDescriptor<'family'> {
318
+ /** The family identifier (e.g., 'sql', 'document') */
319
+ readonly familyId: TFamilyId;
320
+ }
321
+
322
+ /**
323
+ * Descriptor for a target component.
324
+ *
325
+ * A "target" represents a specific database or data store within a family
326
+ * (e.g., Postgres, MySQL, MongoDB). Targets define:
327
+ * - Native type mappings (e.g., Postgres int4 → TypeScript number)
328
+ * - Target-specific capabilities (e.g., RETURNING, LATERAL joins)
329
+ *
330
+ * Targets are bound to a family and provide the target-specific implementation
331
+ * details that adapters and drivers use.
332
+ *
333
+ * Extended by plane-specific descriptors:
334
+ * - `ControlTargetDescriptor` - adds optional `migrations` capability
335
+ * - `RuntimeTargetDescriptor` - adds runtime factory method
336
+ *
337
+ * @template TFamilyId - Literal type for the family identifier
338
+ * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')
339
+ *
340
+ * @example
341
+ * ```ts
342
+ * import postgres from '@prisma-next/target-postgres/control';
343
+ *
344
+ * postgres.kind // 'target'
345
+ * postgres.familyId // 'sql'
346
+ * postgres.targetId // 'postgres'
347
+ * ```
348
+ */
349
+ export interface TargetDescriptor<TFamilyId extends string, TTargetId extends string>
350
+ extends ComponentDescriptor<'target'> {
351
+ /** The family this target belongs to */
352
+ readonly familyId: TFamilyId;
353
+
354
+ /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */
355
+ readonly targetId: TTargetId;
356
+ }
357
+
358
+ /**
359
+ * Base shape for any pack reference.
360
+ * Pack refs are pure JSON-friendly objects safe to import in authoring flows.
361
+ */
362
+ export interface PackRefBase<Kind extends string, TFamilyId extends string>
363
+ extends ComponentMetadata {
364
+ readonly kind: Kind;
365
+ readonly id: string;
366
+ readonly familyId: TFamilyId;
367
+ readonly targetId?: string;
368
+ }
369
+
370
+ export type TargetPackRef<
371
+ TFamilyId extends string = string,
372
+ TTargetId extends string = string,
373
+ > = PackRefBase<'target', TFamilyId> & {
374
+ readonly targetId: TTargetId;
375
+ };
376
+
377
+ export type AdapterPackRef<
378
+ TFamilyId extends string = string,
379
+ TTargetId extends string = string,
380
+ > = PackRefBase<'adapter', TFamilyId> & {
381
+ readonly targetId: TTargetId;
382
+ };
383
+
384
+ export type ExtensionPackRef<
385
+ TFamilyId extends string = string,
386
+ TTargetId extends string = string,
387
+ > = PackRefBase<'extension', TFamilyId> & {
388
+ readonly targetId: TTargetId;
389
+ };
390
+
391
+ export type DriverPackRef<
392
+ TFamilyId extends string = string,
393
+ TTargetId extends string = string,
394
+ > = PackRefBase<'driver', TFamilyId> & {
395
+ readonly targetId: TTargetId;
396
+ };
397
+
398
+ /**
399
+ * Descriptor for an adapter component.
400
+ *
401
+ * An "adapter" provides the protocol and dialect implementation for a target.
402
+ * Adapters handle:
403
+ * - SQL/query generation (lowering AST to target-specific syntax)
404
+ * - Codec registration (encoding/decoding between JS and wire types)
405
+ * - Type mappings and coercions
406
+ *
407
+ * Adapters are bound to a specific family+target combination and work with
408
+ * any compatible driver for that target.
409
+ *
410
+ * Extended by plane-specific descriptors:
411
+ * - `ControlAdapterDescriptor` - control-plane factory
412
+ * - `RuntimeAdapterDescriptor` - runtime factory
413
+ *
414
+ * @template TFamilyId - Literal type for the family identifier
415
+ * @template TTargetId - Literal type for the target identifier
416
+ *
417
+ * @example
418
+ * ```ts
419
+ * import postgresAdapter from '@prisma-next/adapter-postgres/control';
420
+ *
421
+ * postgresAdapter.kind // 'adapter'
422
+ * postgresAdapter.familyId // 'sql'
423
+ * postgresAdapter.targetId // 'postgres'
424
+ * ```
425
+ */
426
+ export interface AdapterDescriptor<TFamilyId extends string, TTargetId extends string>
427
+ extends ComponentDescriptor<'adapter'> {
428
+ /** The family this adapter belongs to */
429
+ readonly familyId: TFamilyId;
430
+
431
+ /** The target this adapter is designed for */
432
+ readonly targetId: TTargetId;
433
+ }
434
+
435
+ /**
436
+ * Descriptor for a driver component.
437
+ *
438
+ * A "driver" provides the connection and execution layer for a target.
439
+ * Drivers handle:
440
+ * - Connection management (pooling, timeouts, retries)
441
+ * - Query execution (sending SQL/commands, receiving results)
442
+ * - Transaction management
443
+ * - Wire protocol communication
444
+ *
445
+ * Drivers are bound to a specific family+target and work with any compatible
446
+ * adapter. Multiple drivers can exist for the same target (e.g., node-postgres
447
+ * vs postgres.js for Postgres).
448
+ *
449
+ * Extended by plane-specific descriptors:
450
+ * - `ControlDriverDescriptor` - creates driver from connection URL
451
+ * - `RuntimeDriverDescriptor` - creates driver with runtime options
452
+ *
453
+ * @template TFamilyId - Literal type for the family identifier
454
+ * @template TTargetId - Literal type for the target identifier
455
+ *
456
+ * @example
457
+ * ```ts
458
+ * import postgresDriver from '@prisma-next/driver-postgres/control';
459
+ *
460
+ * postgresDriver.kind // 'driver'
461
+ * postgresDriver.familyId // 'sql'
462
+ * postgresDriver.targetId // 'postgres'
463
+ * ```
464
+ */
465
+ export interface DriverDescriptor<TFamilyId extends string, TTargetId extends string>
466
+ extends ComponentDescriptor<'driver'> {
467
+ /** The family this driver belongs to */
468
+ readonly familyId: TFamilyId;
469
+
470
+ /** The target this driver connects to */
471
+ readonly targetId: TTargetId;
472
+ }
473
+
474
+ /**
475
+ * Descriptor for an extension component.
476
+ *
477
+ * An "extension" adds optional capabilities to a target. Extensions can provide:
478
+ * - Additional operations (e.g., vector similarity search with pgvector)
479
+ * - Custom types and codecs (e.g., vector type)
480
+ * - Extended query capabilities
481
+ *
482
+ * Extensions are bound to a specific family+target and are registered in the
483
+ * config alongside the core components. Multiple extensions can be used together.
484
+ *
485
+ * Extended by plane-specific descriptors:
486
+ * - `ControlExtensionDescriptor` - control-plane extension factory
487
+ * - `RuntimeExtensionDescriptor` - runtime extension factory
488
+ *
489
+ * @template TFamilyId - Literal type for the family identifier
490
+ * @template TTargetId - Literal type for the target identifier
491
+ *
492
+ * @example
493
+ * ```ts
494
+ * import pgvector from '@prisma-next/extension-pgvector/control';
495
+ *
496
+ * pgvector.kind // 'extension'
497
+ * pgvector.familyId // 'sql'
498
+ * pgvector.targetId // 'postgres'
499
+ * ```
500
+ */
501
+ export interface ExtensionDescriptor<TFamilyId extends string, TTargetId extends string>
502
+ extends ComponentDescriptor<'extension'> {
503
+ /** The family this extension belongs to */
504
+ readonly familyId: TFamilyId;
505
+
506
+ /** The target this extension is designed for */
507
+ readonly targetId: TTargetId;
508
+ }
509
+
510
+ /**
511
+ * Union type for target-bound component descriptors.
512
+ *
513
+ * Target-bound components are those that must be compatible with a specific
514
+ * family+target combination. This includes targets, adapters, drivers, and
515
+ * extensions. Families are not target-bound.
516
+ *
517
+ * This type is used in migration and verification interfaces to enforce
518
+ * type-level compatibility between components.
519
+ *
520
+ * @template TFamilyId - Literal type for the family identifier
521
+ * @template TTargetId - Literal type for the target identifier
522
+ *
523
+ * @example
524
+ * ```ts
525
+ * // All these components must have matching familyId and targetId
526
+ * const components: TargetBoundComponentDescriptor<'sql', 'postgres'>[] = [
527
+ * postgresTarget,
528
+ * postgresAdapter,
529
+ * postgresDriver,
530
+ * pgvectorExtension,
531
+ * ];
532
+ * ```
533
+ */
534
+ export type TargetBoundComponentDescriptor<TFamilyId extends string, TTargetId extends string> =
535
+ | TargetDescriptor<TFamilyId, TTargetId>
536
+ | AdapterDescriptor<TFamilyId, TTargetId>
537
+ | DriverDescriptor<TFamilyId, TTargetId>
538
+ | ExtensionDescriptor<TFamilyId, TTargetId>;
539
+
540
+ /**
541
+ * Base interface for family instances.
542
+ *
543
+ * A family instance is created by a family descriptor's `create()` method.
544
+ * This base interface carries only the identity; plane-specific interfaces
545
+ * add domain actions (e.g., `emitContract`, `verify` on ControlFamilyInstance).
546
+ *
547
+ * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')
548
+ *
549
+ * @example
550
+ * ```ts
551
+ * const instance = sql.create({ target, adapter, driver, extensions });
552
+ * instance.familyId // 'sql'
553
+ * ```
554
+ */
555
+ export interface FamilyInstance<TFamilyId extends string> {
556
+ /** The family identifier (e.g., 'sql', 'document') */
557
+ readonly familyId: TFamilyId;
558
+ }
559
+
560
+ /**
561
+ * Base interface for target instances.
562
+ *
563
+ * A target instance is created by a target descriptor's `create()` method.
564
+ * This base interface carries only the identity; plane-specific interfaces
565
+ * add target-specific behavior.
566
+ *
567
+ * @template TFamilyId - Literal type for the family identifier
568
+ * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')
569
+ *
570
+ * @example
571
+ * ```ts
572
+ * const instance = postgres.create();
573
+ * instance.familyId // 'sql'
574
+ * instance.targetId // 'postgres'
575
+ * ```
576
+ */
577
+ export interface TargetInstance<TFamilyId extends string, TTargetId extends string> {
578
+ /** The family this target belongs to */
579
+ readonly familyId: TFamilyId;
580
+
581
+ /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */
582
+ readonly targetId: TTargetId;
583
+ }
584
+
585
+ /**
586
+ * Base interface for adapter instances.
587
+ *
588
+ * An adapter instance is created by an adapter descriptor's `create()` method.
589
+ * This base interface carries only the identity; plane-specific interfaces
590
+ * add adapter-specific behavior (e.g., codec registration, query lowering).
591
+ *
592
+ * @template TFamilyId - Literal type for the family identifier
593
+ * @template TTargetId - Literal type for the target identifier
594
+ *
595
+ * @example
596
+ * ```ts
597
+ * const instance = postgresAdapter.create();
598
+ * instance.familyId // 'sql'
599
+ * instance.targetId // 'postgres'
600
+ * ```
601
+ */
602
+ export interface AdapterInstance<TFamilyId extends string, TTargetId extends string> {
603
+ /** The family this adapter belongs to */
604
+ readonly familyId: TFamilyId;
605
+
606
+ /** The target this adapter is designed for */
607
+ readonly targetId: TTargetId;
608
+ }
609
+
610
+ /**
611
+ * Base interface for driver instances.
612
+ *
613
+ * A driver instance is created by a driver descriptor's `create()` method.
614
+ * This base interface carries only the identity; plane-specific interfaces
615
+ * add driver-specific behavior (e.g., `query`, `close` on ControlDriverInstance).
616
+ *
617
+ * @template TFamilyId - Literal type for the family identifier
618
+ * @template TTargetId - Literal type for the target identifier
619
+ *
620
+ * @example
621
+ * ```ts
622
+ * const instance = postgresDriver.create({ databaseUrl });
623
+ * instance.familyId // 'sql'
624
+ * instance.targetId // 'postgres'
625
+ * ```
626
+ */
627
+ export interface DriverInstance<TFamilyId extends string, TTargetId extends string> {
628
+ /** The family this driver belongs to */
629
+ readonly familyId: TFamilyId;
630
+
631
+ /** The target this driver connects to */
632
+ readonly targetId: TTargetId;
633
+ }
634
+
635
+ /**
636
+ * Base interface for extension instances.
637
+ *
638
+ * An extension instance is created by an extension descriptor's `create()` method.
639
+ * This base interface carries only the identity; plane-specific interfaces
640
+ * add extension-specific behavior.
641
+ *
642
+ * @template TFamilyId - Literal type for the family identifier
643
+ * @template TTargetId - Literal type for the target identifier
644
+ *
645
+ * @example
646
+ * ```ts
647
+ * const instance = pgvector.create();
648
+ * instance.familyId // 'sql'
649
+ * instance.targetId // 'postgres'
650
+ * ```
651
+ */
652
+ export interface ExtensionInstance<TFamilyId extends string, TTargetId extends string> {
653
+ /** The family this extension belongs to */
654
+ readonly familyId: TFamilyId;
655
+
656
+ /** The target this extension is designed for */
657
+ readonly targetId: TTargetId;
658
+ }