@happyvertical/smrt-config 0.30.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.
@@ -0,0 +1,665 @@
1
+ import { DomainKnowledgeConfig } from '@happyvertical/smrt-types';
2
+
3
+ /**
4
+ * CLI package configuration.
5
+ *
6
+ * Placed under the `cli` key in `smrt.config.js`. Consumed by
7
+ * `@happyvertical/smrt-cli` for `smrt db:*` and migration commands.
8
+ *
9
+ * @example
10
+ * ```js
11
+ * export default defineConfig({
12
+ * cli: {
13
+ * database: { type: 'sqlite', url: 'file:./local.db' },
14
+ * migrations: { mode: 'dynamic', directory: './migrations' },
15
+ * },
16
+ * });
17
+ * ```
18
+ *
19
+ * @see {@link DatabaseConfig}
20
+ * @see {@link MigrationsConfig}
21
+ */
22
+ export declare interface CliConfig {
23
+ /**
24
+ * Database connection settings
25
+ */
26
+ database?: DatabaseConfig;
27
+ /**
28
+ * Migration settings
29
+ */
30
+ migrations?: MigrationsConfig;
31
+ /**
32
+ * Required manifest/object/field/database-shape contract for schema commands.
33
+ */
34
+ schemaContract?: SchemaContractConfig;
35
+ }
36
+
37
+ /**
38
+ * Database connection configuration for CLI commands.
39
+ *
40
+ * Placed under `cli.database` in `smrt.config.js`. Used by
41
+ * `@happyvertical/smrt-cli` to connect for migration and inspection commands.
42
+ *
43
+ * @see {@link CliConfig}
44
+ */
45
+ export declare interface DatabaseConfig {
46
+ /**
47
+ * Database type
48
+ *
49
+ * @default 'sqlite'
50
+ */
51
+ type?: 'sqlite' | 'postgres' | 'duckdb';
52
+ /**
53
+ * Database connection URL
54
+ *
55
+ * For SQLite: file path or ':memory:'
56
+ * For PostgreSQL: postgresql://user:pass@host:port/dbname
57
+ */
58
+ url?: string;
59
+ }
60
+
61
+ /**
62
+ * Export configuration for static site generation.
63
+ *
64
+ * Placed under the `export` key in `smrt.config.js`. Controls how database
65
+ * records are exported to static files during SSG builds. Each additional
66
+ * key beyond `fieldExportDefault` and `format` defines a named export file.
67
+ *
68
+ * @example
69
+ * ```js
70
+ * export default defineConfig({
71
+ * export: {
72
+ * fieldExportDefault: true,
73
+ * articles: { types: ['Article'], filters: { status: ['published'] } },
74
+ * games: { types: ['Game'], orderBy: '-date', format: 'ndjson' },
75
+ * },
76
+ * });
77
+ * ```
78
+ *
79
+ * @see {@link ExportFileConfig}
80
+ * @see {@link exportConfig}
81
+ */
82
+ export declare interface ExportConfig {
83
+ /**
84
+ * Default export behavior for fields without explicit `exported` annotation
85
+ *
86
+ * - true: Export all fields by default (simpler, for most sites)
87
+ * - false: Only export fields with explicit `exported: true`
88
+ *
89
+ * @default true
90
+ */
91
+ fieldExportDefault?: boolean;
92
+ /**
93
+ * Default output format for all exports
94
+ * @default 'json'
95
+ */
96
+ format?: 'json' | 'ndjson' | 'csv' | 'sqlite';
97
+ /**
98
+ * Export file configurations
99
+ * Keys become filenames (e.g., 'contents' -> 'contents.json')
100
+ */
101
+ [filename: string]: ExportFileConfig | boolean | string | undefined;
102
+ }
103
+
104
+ /**
105
+ * Configuration for a single SSG export file.
106
+ *
107
+ * Each key in {@link ExportConfig} (besides `fieldExportDefault` and `format`)
108
+ * becomes the output filename. Records are queried from the database, filtered,
109
+ * ordered, and written to `{key}.json` (or the specified format).
110
+ *
111
+ * @example
112
+ * ```js
113
+ * export default defineConfig({
114
+ * export: {
115
+ * articles: {
116
+ * types: ['Article'],
117
+ * filters: { status: ['published'] },
118
+ * orderBy: '-publishDate',
119
+ * limit: 500,
120
+ * },
121
+ * },
122
+ * });
123
+ * ```
124
+ *
125
+ * @see {@link ExportConfig}
126
+ * @see {@link ExportFilterValue}
127
+ */
128
+ export declare interface ExportFileConfig {
129
+ /**
130
+ * SMRT object types to include in this export
131
+ * Uses className (e.g., 'MeetingRecap', 'Game')
132
+ */
133
+ types: string[];
134
+ /**
135
+ * Field whitelist - only export these fields
136
+ * If specified, overrides exclude and fieldExportDefault
137
+ */
138
+ include?: string[];
139
+ /**
140
+ * Field blacklist - exclude these fields
141
+ * Applied after schema-level exported: false check
142
+ */
143
+ exclude?: string[];
144
+ /**
145
+ * Filters to apply when querying records
146
+ * Keys are field names, values are filter conditions
147
+ *
148
+ * @example
149
+ * filters: {
150
+ * status: ['published'], // shorthand for status IN ('published')
151
+ * publish_date: { gte: '2025-01-01' },
152
+ * council_slug: ['town-of-bentley'],
153
+ * }
154
+ */
155
+ filters?: Record<string, string[] | number[] | ExportFilterValue>;
156
+ /**
157
+ * Output format for this file
158
+ * @default 'json'
159
+ */
160
+ format?: 'json' | 'ndjson' | 'csv' | 'sqlite';
161
+ /**
162
+ * Field to order by
163
+ * Prefix with '-' for descending (e.g., '-publish_date')
164
+ */
165
+ orderBy?: string;
166
+ /**
167
+ * Maximum records per file
168
+ * If exceeded, creates paginated files (e.g., contents-1.json, contents-2.json)
169
+ */
170
+ limit?: number;
171
+ /**
172
+ * Create separate files per unique value of this field
173
+ * e.g., shardBy: 'year' creates contents-2024.json, contents-2025.json
174
+ */
175
+ shardBy?: string;
176
+ }
177
+
178
+ /**
179
+ * Filter operators for export queries.
180
+ *
181
+ * Used as values in {@link ExportFileConfig.filters} to build SQL `WHERE`
182
+ * clauses when exporting records to static files.
183
+ *
184
+ * @example
185
+ * ```js
186
+ * filters: {
187
+ * publishDate: { gte: '2025-01-01', lt: '2026-01-01' },
188
+ * status: { in: ['published', 'featured'] },
189
+ * }
190
+ * ```
191
+ *
192
+ * @see {@link ExportFileConfig}
193
+ */
194
+ export declare interface ExportFilterValue {
195
+ /** Equals (shorthand: just the value) */
196
+ eq?: string | number | boolean;
197
+ /** Not equals */
198
+ ne?: string | number | boolean;
199
+ /** Greater than */
200
+ gt?: string | number;
201
+ /** Greater than or equal */
202
+ gte?: string | number;
203
+ /** Less than */
204
+ lt?: string | number;
205
+ /** Less than or equal */
206
+ lte?: string | number;
207
+ /** In array */
208
+ in?: (string | number)[];
209
+ /** Contains (text) */
210
+ contains?: string;
211
+ }
212
+
213
+ /**
214
+ * Options accepted by {@link loadConfig}.
215
+ *
216
+ * All fields are optional; omitting them triggers cosmiconfig's default
217
+ * search behaviour (scan `cwd` upward for `smrt.config.{js,mjs,cjs,json}`).
218
+ */
219
+ export declare interface LoadConfigOptions {
220
+ /**
221
+ * Absolute or relative path to a specific config file.
222
+ * When provided, cosmiconfig loads this file directly instead of searching.
223
+ */
224
+ configPath?: string;
225
+ /**
226
+ * Whether to search parent directories when no config is found in `cwd`.
227
+ *
228
+ * @default true
229
+ */
230
+ searchParents?: boolean;
231
+ /**
232
+ * Whether to cache the loaded config in `globalThis.__smrtLoaderCachedConfig`.
233
+ * Disable for test isolation or hot-reload scenarios.
234
+ *
235
+ * @default true
236
+ */
237
+ cache?: boolean;
238
+ }
239
+
240
+ /**
241
+ * Database migrations configuration.
242
+ *
243
+ * Controls how migrations are generated, stored, and applied. Placed under
244
+ * the `cli.migrations` key in `smrt.config.js` and consumed by
245
+ * `@happyvertical/smrt-cli` migration commands (`smrt db:migrate`, etc.).
246
+ *
247
+ * @see {@link CliConfig}
248
+ */
249
+ export declare interface MigrationsConfig {
250
+ /**
251
+ * Directory for migration files (relative to project root)
252
+ *
253
+ * @default './migrations'
254
+ */
255
+ directory?: string;
256
+ /**
257
+ * Table name for tracking applied migrations
258
+ *
259
+ * @default '_smrt_schema_migrations'
260
+ */
261
+ table?: string;
262
+ /**
263
+ * Legacy file format setting. File-backed migration generation is not supported.
264
+ *
265
+ * @default 'sql'
266
+ */
267
+ format?: 'sql' | 'typescript';
268
+ /**
269
+ * Migration file naming strategy
270
+ *
271
+ * - 'sequence': Sequential numbers (0001, 0002, ...)
272
+ * - 'timestamp': Unix timestamp-based (20240115143052)
273
+ *
274
+ * @default 'sequence'
275
+ */
276
+ naming?: 'sequence' | 'timestamp';
277
+ /**
278
+ * Migration mode.
279
+ *
280
+ * SMRT schema migrations are manifest-driven. File-backed modes are not
281
+ * supported unless a future file migration executor is implemented.
282
+ *
283
+ * @default 'dynamic'
284
+ */
285
+ mode?: 'dynamic';
286
+ /**
287
+ * Configure mode per environment.
288
+ *
289
+ * Overrides the `mode` setting based on NODE_ENV
290
+ */
291
+ modeByEnvironment?: {
292
+ development?: 'dynamic';
293
+ test?: 'dynamic';
294
+ staging?: 'dynamic';
295
+ production?: 'dynamic';
296
+ };
297
+ /**
298
+ * Automatically generate DOWN scripts where safe
299
+ *
300
+ * Some operations (DROP COLUMN) may lose data and should be reviewed.
301
+ *
302
+ * @default true
303
+ */
304
+ autoGenerateDown?: boolean;
305
+ /**
306
+ * PostgreSQL-specific settings
307
+ */
308
+ postgres?: MigrationsPostgresConfig;
309
+ }
310
+
311
+ /**
312
+ * PostgreSQL-specific migration settings.
313
+ *
314
+ * Nested under `migrations.postgres` in {@link MigrationsConfig}.
315
+ */
316
+ export declare interface MigrationsPostgresConfig {
317
+ /**
318
+ * Use CREATE INDEX CONCURRENTLY for index creation
319
+ * Avoids table locks but cannot run in a transaction
320
+ *
321
+ * @default true
322
+ */
323
+ useConcurrently?: boolean;
324
+ /**
325
+ * Lock timeout for migration statements
326
+ *
327
+ * @default '30s'
328
+ */
329
+ lockTimeout?: string;
330
+ /**
331
+ * Statement timeout for migration execution
332
+ *
333
+ * @default '60s'
334
+ */
335
+ statementTimeout?: string;
336
+ }
337
+
338
+ /**
339
+ * Semantic schema contract enforced by SMRT schema commands.
340
+ *
341
+ * Object and field requirements are checked against the loaded SMRT registry.
342
+ * Required fields are also translated to physical table/column checks after
343
+ * migration/status introspection. `requiredDatabaseShape` is reserved for
344
+ * database objects that SMRT cannot infer from manifests.
345
+ */
346
+ export declare interface SchemaContractConfig {
347
+ requiredObjects?: string[];
348
+ requiredFields?: string[];
349
+ requiredDatabaseShape?: {
350
+ tables?: string[];
351
+ columns?: string[];
352
+ indexes?: string[];
353
+ };
354
+ }
355
+
356
+ /**
357
+ * Site identity and configuration for SMRT site templates.
358
+ *
359
+ * Placed under the `site` key in `smrt.config.js`. Retrieved at runtime
360
+ * via {@link getSiteConfig}. Used by site templates
361
+ * (`template-sveltekit`, `template-site-static-json`) to define name,
362
+ * description, navigation, location, and theme.
363
+ *
364
+ * @example
365
+ * ```js
366
+ * export default defineConfig({
367
+ * site: {
368
+ * name: 'Bentley Alberta',
369
+ * description: 'Community news for Bentley, AB',
370
+ * url: 'https://bentley.ca',
371
+ * location: { name: 'Bentley', latitude: 52.4, longitude: -113.9, timezone: 'America/Edmonton' },
372
+ * navigation: { primary: [{ label: 'Home', href: '/' }] },
373
+ * },
374
+ * });
375
+ * ```
376
+ *
377
+ * @see {@link getSiteConfig}
378
+ * @see {@link SiteLocation}
379
+ * @see {@link SiteNavigation}
380
+ * @see {@link SiteTheme}
381
+ */
382
+ export declare interface SiteConfig {
383
+ /** Full site name (e.g., "Bentley Alberta") */
384
+ name: string;
385
+ /** Short name for mobile/compact displays */
386
+ shortName?: string;
387
+ /** Site description for SEO */
388
+ description: string;
389
+ /** Production URL */
390
+ url?: string;
391
+ /** Contact email for the site */
392
+ contactEmail?: string;
393
+ /** Publisher/organization info */
394
+ publisher?: SitePublisher;
395
+ /** Geographic location */
396
+ location: SiteLocation;
397
+ /** Navigation structure */
398
+ navigation: SiteNavigation;
399
+ /** Theme/branding */
400
+ theme?: SiteTheme;
401
+ /** Additional metadata */
402
+ meta?: {
403
+ /** Theme color for mobile browsers */
404
+ themeColor?: string;
405
+ /** Open Graph locale */
406
+ ogLocale?: string;
407
+ /** Google Tag Manager ID */
408
+ gtmId?: string;
409
+ };
410
+ }
411
+
412
+ /**
413
+ * Geographic location for the site, used for proximity search and display.
414
+ *
415
+ * @see {@link SiteConfig}
416
+ */
417
+ export declare interface SiteLocation {
418
+ /** Display name (e.g., "Bentley" or "Bentley, AB") */
419
+ name: string;
420
+ /** Latitude coordinate */
421
+ latitude: number;
422
+ /** Longitude coordinate */
423
+ longitude: number;
424
+ /** IANA timezone (e.g., "America/Edmonton") */
425
+ timezone: string;
426
+ }
427
+
428
+ /**
429
+ * Site navigation structure containing primary and optional footer links.
430
+ *
431
+ * @see {@link SiteConfig}
432
+ * @see {@link SiteNavigationLink}
433
+ */
434
+ export declare interface SiteNavigation {
435
+ /** Primary navigation links (header) */
436
+ primary: SiteNavigationLink[];
437
+ /** Footer navigation links */
438
+ footer?: SiteNavigationLink[];
439
+ }
440
+
441
+ /**
442
+ * A single navigation link item used in site menus.
443
+ *
444
+ * @see {@link SiteNavigation}
445
+ */
446
+ export declare interface SiteNavigationLink {
447
+ label: string;
448
+ href: string;
449
+ icon?: string;
450
+ }
451
+
452
+ /**
453
+ * Publisher or organization information displayed in site footers and metadata.
454
+ *
455
+ * @see {@link SiteConfig}
456
+ */
457
+ export declare interface SitePublisher {
458
+ /** Organization name (e.g., "Blindman Press") */
459
+ name: string;
460
+ /** Organization website URL */
461
+ url?: string;
462
+ /** GitHub organization URL */
463
+ github?: string;
464
+ }
465
+
466
+ /**
467
+ * Site theme and branding color palette.
468
+ *
469
+ * Colors should be provided as CSS hex values (e.g., `'#3b82f6'`).
470
+ *
471
+ * @see {@link SiteConfig}
472
+ */
473
+ export declare interface SiteTheme {
474
+ /** Primary brand color (hex) */
475
+ primaryColor: string;
476
+ /** Light variant of primary color */
477
+ primaryLight?: string;
478
+ /** Dark variant of primary color */
479
+ primaryDark?: string;
480
+ }
481
+
482
+ /**
483
+ * Root SMRT configuration structure.
484
+ *
485
+ * This is the shape of the object returned by `smrt.config.{js,ts,json}` and
486
+ * consumed by {@link loadConfig}. Use {@link defineConfig} for type-safe
487
+ * authoring with IDE auto-completion.
488
+ *
489
+ * Priority order (highest to lowest):
490
+ * 1. Runtime overrides set via {@link setConfig}
491
+ * 2. File-based config loaded by {@link loadConfig}
492
+ * 3. Defaults passed to {@link getModuleConfig} / {@link getPackageConfig}
493
+ *
494
+ * @example
495
+ * ```js
496
+ * // smrt.config.js
497
+ * import { defineConfig } from '@happyvertical/smrt-config';
498
+ *
499
+ * export default defineConfig({
500
+ * smrt: { logLevel: 'info', environment: 'production' },
501
+ * site: { name: 'My Site', ... },
502
+ * modules: { praeco: { rssLimit: 50 } },
503
+ * packages: { ai: { defaultModel: 'gpt-4o' } },
504
+ * });
505
+ * ```
506
+ *
507
+ * @see {@link loadConfig}
508
+ * @see {@link defineConfig}
509
+ * @see {@link SmrtGlobalConfig}
510
+ */
511
+ export declare interface SmrtConfig {
512
+ /** Global SMRT framework options — lowest-priority base for all modules. */
513
+ smrt?: SmrtGlobalConfig;
514
+ /** Site identity and configuration (for site templates). */
515
+ site?: SiteConfig;
516
+ /** Export configuration for static site generation. */
517
+ export?: ExportConfig;
518
+ /** Domain-scoped agent/developer knowledge generation and exposure. */
519
+ knowledge?: DomainKnowledgeConfig;
520
+ /**
521
+ * Module-scoped configurations keyed by module name.
522
+ * Retrieved via {@link getModuleConfig}.
523
+ */
524
+ modules?: {
525
+ [moduleName: string]: Record<string, unknown>;
526
+ };
527
+ /**
528
+ * Package-scoped configurations keyed by package name.
529
+ * Retrieved via {@link getPackageConfig}.
530
+ */
531
+ packages?: {
532
+ [packageName: string]: Record<string, unknown>;
533
+ };
534
+ }
535
+
536
+ /**
537
+ * Global SMRT framework options that apply to all modules unless overridden.
538
+ *
539
+ * Placed under the `smrt` key in `smrt.config.js`. Values here propagate
540
+ * as the lowest-priority base for every `getModuleConfig()` and
541
+ * `getPackageConfig()` call.
542
+ *
543
+ * @example
544
+ * ```js
545
+ * // smrt.config.js
546
+ * export default defineConfig({
547
+ * smrt: {
548
+ * logLevel: 'debug',
549
+ * environment: 'development',
550
+ * embeddings: { provider: 'local' },
551
+ * },
552
+ * });
553
+ * ```
554
+ *
555
+ * @see {@link SmrtConfig}
556
+ * @see {@link getModuleConfig}
557
+ * @see {@link getPackageConfig}
558
+ */
559
+ export declare interface SmrtGlobalConfig {
560
+ cacheDir?: string;
561
+ logLevel?: 'debug' | 'info' | 'warn' | 'error';
562
+ environment?: 'development' | 'production' | 'test';
563
+ /**
564
+ * Schema migration strategy when parent class schema changes
565
+ *
566
+ * Options:
567
+ * - 'warn': Log warning about schema mismatch, require manual migration (safest)
568
+ * - 'auto-add': Automatically ALTER TABLE to add new parent fields (default, convenient)
569
+ *
570
+ * Note: Removing columns is never automatic - always requires manual migration
571
+ *
572
+ * @default 'auto-add'
573
+ */
574
+ schemaMigration?: {
575
+ strategy?: 'warn' | 'auto-add';
576
+ };
577
+ /**
578
+ * Inheritance configuration
579
+ */
580
+ inheritance?: {
581
+ /**
582
+ * Behavior when an ancestor class is missing from the registry
583
+ *
584
+ * Options:
585
+ * - 'error': Throw an error (strict, catches bugs)
586
+ * - 'warn': Log warning and skip (lenient, default)
587
+ *
588
+ * @default 'warn'
589
+ */
590
+ onMissingAncestor?: 'error' | 'warn';
591
+ /**
592
+ * Size of LRU cache for inheritance chains and merged fields
593
+ *
594
+ * Higher values improve performance but use more memory.
595
+ * Each entry stores one inheritance chain (array of strings).
596
+ *
597
+ * @default 200
598
+ */
599
+ cacheSize?: number;
600
+ };
601
+ /**
602
+ * Embedding configuration for semantic search
603
+ *
604
+ * Project-level settings that apply to all SMRT objects
605
+ * unless overridden in the @smrt() decorator.
606
+ */
607
+ embeddings?: {
608
+ /**
609
+ * Standard dimensions for embeddings in this project
610
+ *
611
+ * All embeddings should use the same dimensions for consistency.
612
+ * Common values: 384, 768, 1536
613
+ *
614
+ * @default 768
615
+ */
616
+ dimensions?: number;
617
+ /**
618
+ * Embedding provider type
619
+ *
620
+ * - 'local': Use local Node.js model (@xenova/transformers)
621
+ * - 'ai': Use AI library (OpenAI, etc.)
622
+ * - 'auto': Try local first, fallback to AI
623
+ *
624
+ * @default 'local'
625
+ */
626
+ provider?: 'local' | 'ai' | 'auto';
627
+ /**
628
+ * Local model to use (when provider is 'local' or 'auto')
629
+ *
630
+ * Hugging Face model ID for @xenova/transformers.
631
+ * Model is downloaded on first use (~440MB for bge-base-en-v1.5).
632
+ *
633
+ * @default 'Xenova/bge-base-en-v1.5'
634
+ */
635
+ localModel?: string;
636
+ /**
637
+ * AI model to use (when provider is 'ai' or fallback)
638
+ *
639
+ * OpenAI embedding model name.
640
+ *
641
+ * @default 'text-embedding-3-small'
642
+ */
643
+ aiModel?: string;
644
+ /**
645
+ * Whether to fallback to AI if local embedding fails
646
+ *
647
+ * Only applies when provider is 'auto'.
648
+ *
649
+ * @default true
650
+ */
651
+ fallbackToAI?: boolean;
652
+ /**
653
+ * Storage mode for embeddings
654
+ *
655
+ * - 'json': Store as JSON text, in-memory similarity (works everywhere)
656
+ * - 'native': Use database vector operations when available, fallback to json
657
+ *
658
+ * @default 'json'
659
+ */
660
+ storage?: 'json' | 'native';
661
+ };
662
+ [key: string]: unknown;
663
+ }
664
+
665
+ export { }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}