@happyvertical/smrt-core 0.36.3 → 0.36.5
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/dist/collection.d.ts +8 -3
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +6 -0
- package/dist/collection.js.map +1 -1
- package/dist/manifest/static-manifest.d.ts.map +1 -1
- package/dist/manifest/static-manifest.js +13 -198
- package/dist/manifest/static-manifest.js.map +1 -1
- package/dist/manifest/store.js +2 -2
- package/dist/manifest/store.js.map +1 -1
- package/dist/manifest/test-manifest-stub.d.ts.map +1 -1
- package/dist/manifest/test-manifest-stub.js +13 -198
- package/dist/manifest/test-manifest-stub.js.map +1 -1
- package/dist/manifest.json +13 -175
- package/dist/registry/types.d.ts +21 -0
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +9 -0
- package/dist/registry.js.map +1 -1
- package/dist/scanner/manifest-generator.d.ts +2 -0
- package/dist/scanner/manifest-generator.d.ts.map +1 -1
- package/dist/scanner/manifest-generator.js +30 -1
- package/dist/scanner/manifest-generator.js.map +1 -1
- package/dist/smrt-knowledge.json +14 -26
- package/dist/vite-plugin/index.d.ts.map +1 -1
- package/dist/vite-plugin/index.js +2 -0
- package/dist/vite-plugin/index.js.map +1 -1
- package/package.json +10 -10
package/dist/smrt-knowledge.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-06-
|
|
3
|
+
"generatedAt": "2026-06-26T14:50:08.273Z",
|
|
4
4
|
"packageName": "@happyvertical/smrt-core",
|
|
5
|
-
"packageVersion": "0.36.
|
|
5
|
+
"packageVersion": "0.36.5",
|
|
6
6
|
"sourceManifestPath": "dist/manifest.json",
|
|
7
7
|
"agentDocPath": "AGENTS.md",
|
|
8
8
|
"sourceHashes": {
|
|
9
|
-
"manifest": "
|
|
10
|
-
"packageJson": "
|
|
9
|
+
"manifest": "7b03901f87ad62c612e320cd5094666dfaa983a7e21f6a1ba2680934eb94a4b3",
|
|
10
|
+
"packageJson": "f0610836fc1ea8faf9dddc4487dfbf17aed41cda0eeb143d101304f154880de0",
|
|
11
11
|
"agents": "0fa157a078aa44a0bc104540bd27f0b1e52e66549b7994cba751438a8d44c827"
|
|
12
12
|
},
|
|
13
13
|
"exports": [
|
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"getDiff",
|
|
131
131
|
"getFields",
|
|
132
132
|
"getFieldsSync",
|
|
133
|
+
"getItemClass",
|
|
133
134
|
"getOrUpsert",
|
|
134
135
|
"getStiChildMetaType",
|
|
135
136
|
"initialize",
|
|
@@ -153,15 +154,13 @@
|
|
|
153
154
|
"name": "SmrtHierarchical",
|
|
154
155
|
"qualifiedName": "@happyvertical/smrt-core:SmrtHierarchical",
|
|
155
156
|
"collection": "smrthierarchicals",
|
|
156
|
-
"tableName": "smrt_hierarchicals",
|
|
157
157
|
"packageName": "@happyvertical/smrt-core",
|
|
158
158
|
"extends": "SmrtObject",
|
|
159
159
|
"fields": [
|
|
160
160
|
{
|
|
161
161
|
"name": "parentId",
|
|
162
162
|
"type": "text",
|
|
163
|
-
"required": false
|
|
164
|
-
"columnType": "TEXT"
|
|
163
|
+
"required": false
|
|
165
164
|
}
|
|
166
165
|
],
|
|
167
166
|
"relationships": [],
|
|
@@ -174,9 +173,7 @@
|
|
|
174
173
|
"moveTo"
|
|
175
174
|
],
|
|
176
175
|
"surfaces": [],
|
|
177
|
-
"relationshipFeatures": [
|
|
178
|
-
"uuidColumns"
|
|
179
|
-
],
|
|
176
|
+
"relationshipFeatures": [],
|
|
180
177
|
"tags": [],
|
|
181
178
|
"risks": []
|
|
182
179
|
},
|
|
@@ -184,7 +181,6 @@
|
|
|
184
181
|
"name": "SmrtJunction",
|
|
185
182
|
"qualifiedName": "@happyvertical/smrt-core:SmrtJunction",
|
|
186
183
|
"collection": "smrtjunctions",
|
|
187
|
-
"tableName": "smrt_junctions",
|
|
188
184
|
"packageName": "@happyvertical/smrt-core",
|
|
189
185
|
"extends": "SmrtCollection",
|
|
190
186
|
"fields": [],
|
|
@@ -197,9 +193,7 @@
|
|
|
197
193
|
"setLinks"
|
|
198
194
|
],
|
|
199
195
|
"surfaces": [],
|
|
200
|
-
"relationshipFeatures": [
|
|
201
|
-
"uuidColumns"
|
|
202
|
-
],
|
|
196
|
+
"relationshipFeatures": [],
|
|
203
197
|
"tags": [],
|
|
204
198
|
"risks": []
|
|
205
199
|
},
|
|
@@ -272,33 +266,28 @@
|
|
|
272
266
|
"name": "SmrtPolymorphicAssociation",
|
|
273
267
|
"qualifiedName": "@happyvertical/smrt-core:SmrtPolymorphicAssociation",
|
|
274
268
|
"collection": "smrtpolymorphicassociations",
|
|
275
|
-
"tableName": "smrt_polymorphic_associations",
|
|
276
269
|
"packageName": "@happyvertical/smrt-core",
|
|
277
270
|
"extends": "SmrtObject",
|
|
278
271
|
"fields": [
|
|
279
272
|
{
|
|
280
273
|
"name": "metaType",
|
|
281
274
|
"type": "text",
|
|
282
|
-
"required": true
|
|
283
|
-
"columnType": "TEXT"
|
|
275
|
+
"required": true
|
|
284
276
|
},
|
|
285
277
|
{
|
|
286
278
|
"name": "metaId",
|
|
287
279
|
"type": "text",
|
|
288
|
-
"required": true
|
|
289
|
-
"columnType": "TEXT"
|
|
280
|
+
"required": true
|
|
290
281
|
},
|
|
291
282
|
{
|
|
292
283
|
"name": "role",
|
|
293
284
|
"type": "text",
|
|
294
|
-
"required": true
|
|
295
|
-
"columnType": "TEXT"
|
|
285
|
+
"required": true
|
|
296
286
|
},
|
|
297
287
|
{
|
|
298
288
|
"name": "sortOrder",
|
|
299
289
|
"type": "integer",
|
|
300
|
-
"required": false
|
|
301
|
-
"columnType": "INTEGER"
|
|
290
|
+
"required": false
|
|
302
291
|
}
|
|
303
292
|
],
|
|
304
293
|
"relationships": [],
|
|
@@ -307,8 +296,7 @@
|
|
|
307
296
|
],
|
|
308
297
|
"surfaces": [],
|
|
309
298
|
"relationshipFeatures": [
|
|
310
|
-
"SmrtPolymorphicAssociation"
|
|
311
|
-
"uuidColumns"
|
|
299
|
+
"SmrtPolymorphicAssociation"
|
|
312
300
|
],
|
|
313
301
|
"tags": [],
|
|
314
302
|
"risks": []
|
|
@@ -330,7 +318,7 @@
|
|
|
330
318
|
"junctionCollections": 0,
|
|
331
319
|
"hierarchicalObjects": 0,
|
|
332
320
|
"polymorphicAssociations": 1,
|
|
333
|
-
"uuidColumns":
|
|
321
|
+
"uuidColumns": 3
|
|
334
322
|
},
|
|
335
323
|
"agentDoc": "# @happyvertical/smrt-core\n\nORM, code generation, AI integration, and the DispatchBus. Everything else builds on this.\n\n## Key Classes\n\n| Class | File | Purpose |\n|-------|------|---------|\n| SmrtObject | `src/object.ts` | Base persistent object — save, delete, is(), do(), loadFromId/Slug |\n| SmrtCollection | `src/collection.ts` | CRUD collection — list, get, create, delete, getOrUpsert |\n| ObjectRegistry | `src/registry.ts` | Global singleton (globalThis) — class metadata, fields, STI chains, manifests |\n| DispatchBus | `src/dispatch/bus.ts` | Inter-agent messaging — emit, subscribe (persistent), process |\n| GlobalInterceptors | `src/interceptors.ts` | Plugin system — beforeList/Get/Save/Delete hooks (used by tenancy) |\n\n## SmrtObject Lifecycle\n\n`constructor(options)` → `initialize()` → ready for `save()`/`delete()`/`loadFromId()`\n\n- `initialize()`: loads field initializers, applies option values (options override initializers), loads from DB if id/slug provided\n- `save()`: upsert with STI validation, interceptor execution, auto-embeddings. Persisted objects (`isPersisted` — set by DB hydration and successful saves) upsert on `['id']` so natural-key edits (e.g. slug renames) update in place; new objects upsert on the natural-key conflict columns for ingestion-style dedup (#1472)\n- `is(criteria)` / `do(instructions)` / `describe()`: AI operations via function calling. They inject the object's own `toPublicJSON()` (sensitive fields stripped) as a \"content body\" so the model reasons over the instance. Options: `includeData: false` skips injection (for callers that already curate the relevant fields into the instruction); `maxDataLength` overrides the truncation budget. Neither key is forwarded to `ai.message()`. (#1567)\n- `getSlug()`: auto-generates from name → title → label → id\n- `loadRelated(fieldName)`: lazy-loads relationships (cached in `_loadedRelationships` Map)\n\n## SmrtCollection Query\n\n```typescript\nawait collection.list({\n where: { status: 'active', price: { op: '>', value: 10 } },\n limit: 50, offset: 0, orderBy: 'created_at DESC'\n});\n```\n\n**WHERE operators**: `=`, `>`, `<`, `>=`, `<=`, `!=`, `in`, `not in`, `like`, `is null`, `is not null`. Arrays auto-detect `IN`. Dot notation for JSON paths: `metadata.userId`.\n\nSTI child collections auto-filter by `_meta_type`.\n\n## @smrt() Decorator Options\n\nKey options: `tableName`, `tableStrategy` ('cti'|'sti'), `conflictColumns`, `api`/`mcp`/`cli` (generation config), `ai` (callable methods), `hooks` (beforeSave/afterSave/beforeDelete/afterDelete), `embeddings` (auto-generate), `tenantScoped`, `agent`.\n\nRegistration sets `SMRT_TABLE_NAME` static property (survives minification).\n\n## Domain Knowledge Artifacts\n\n`smrtPlugin()` writes runtime manifests and agent/developer knowledge artifacts:\n\n- local dev/build: `.smrt/manifest.json` and `.smrt/smrt-knowledge.json`\n- package build: `dist/manifest.json` and `dist/smrt-knowledge.json`\n\nKeep `manifest.json` runtime-focused. `smrt-knowledge.json` is the deterministic\nagent contract for downstream review and architecture tools.\n\nConfig precedence for knowledge is defaults → top-level `knowledge` in\n`smrt.config.ts` → `packages[packageName].knowledge` → plugin option →\nobject-level `@smrt({ knowledge })`.\n\nObject-level `knowledge: false` excludes an object from authored context only;\nit must not change runtime manifest registration. Use\n`knowledge: { tags, summary, risks }` for review-sensitive domain objects.\n\nHTTP knowledge routes are disabled by default. If `knowledge.api.enabled` is\ntrue, generated SvelteKit routes must stay GET-only and guarded by dev mode or\nadmin auth.\n\n## DispatchBus\n\n- `emit(signalType, payload, metadata)` → creates persistent Dispatch record\n- `on(pattern, handler)` → in-memory handler (immediate)\n- `subscribe({ signalType, subscriber })` → persistent subscription (survives restarts)\n- `process(subscriberName, handler)` → process pending dispatches\n- Wildcards: `campaign.*` matches `campaign.completed` (single segment only)\n- Tables: `_smrt_dispatch`, `_smrt_dispatch_subscriptions`\n- Status: `pending → processing → completed` (or `failed`)\n\n## Single Table Inheritance (STI)\n\n- Base: `@smrt({ tableStrategy: 'sti' })` — children inherit, share one table\n- Discriminator: `_meta_type` column with qualified names (`@happyvertical/smrt-content:Article`)\n- Child fields: `@meta()` decorator → stored in `_meta_data` JSONB (not as columns)\n- Polymorphic queries: collection loads `_meta_type`, creates correct subclass dynamically\n- Validation: fail-fast on save if `_meta_type` missing or mismatched\n\n## Code Generators\n\n| Generator | Location | Output |\n|-----------|----------|--------|\n| REST API | `src/generators/rest.ts` | OpenAPI-compliant CRUD endpoints |\n| CLI | `src/generators/cli.ts` | `objectname:action` admin commands — writable allowlist, exhaustive-include, `--from-file`, fail-closed tenant context |\n| MCP Server | `src/generators/mcp.ts` | Model Context Protocol tools |\n\n## Child Accessors (R10)\n\n`src/child-accessors.ts` installs a consistent `get<FieldName>()` instance method for every `@oneToMany` field at `@smrt()` registration time (e.g. `@oneToMany('OrderItem') items` → `order.getItems()`), delegating to `loadRelatedMany`. Two invariants:\n\n- **Additive** — never overwrites a hand-rolled method of the same name (checks the whole prototype chain). `Profile.getMetadata()` (key-value) and `ProfileRelationship.getTerms()` are preserved.\n- **Runtime-only** — attached to the prototype, invisible to the build-time manifest, so it never leaks into the REST/CLI/MCP surface.\n\nWhen the target declares multiple FKs back to the parent, annotate `@oneToMany(Target, { foreignKey: '<inverseField>' })`; `loadRelatedMany` and the eager `include:` loader both honor it (else first-match).\n\n## Vite Plugin\n\n```typescript\n// vite.config.ts — required for @smrt() decorators\nexport default defineConfig({\n esbuild: {\n tsconfigRaw: {\n compilerOptions: { experimentalDecorators: true, emitDecoratorMetadata: true }\n }\n }\n});\n```\n\n## Gotchas\n\n- **Never override toJSON()** — handles STI discriminator + meta field extraction. Use `transformJSON()`\n- **Property init order**: TypeScript initializers run first, then `initialize()` applies option values (options win)\n- **No runtime schema creation**: application tables must be prepared explicitly via migrations/tooling; runtime only verifies and fails clearly\n- **Retry logic**: `db.get()` (3 retries, 250ms) and `db.upsert()` (3 retries, 500ms) have built-in retry\n- **Field caching**: `_cachedFields` populated during `Collection.create()` — eliminates async `getFields()` per query\n- **Smart cloning**: arrays/objects shallow-cloned in property init to prevent aliasing (Issue #22)\n- **Table verification cache**: `isTableVerified(dbUrl, tableName)` avoids redundant `tableExists()` calls\n- **Manifest required**: build-time AST scanning creates manifest. Without vitest plugin → \"No field metadata\"\n- **Vite plugin loads scanner from `dist/` first**: `src/vite-plugin/import-build-aware.ts` prefers `dist/` when it exists on disk; it only falls back to `src/` on fresh clones. So if you edit `src/scanner/*.ts` or `src/schema/generator.ts` and want those edits reflected in consumer manifest generation, you must rebuild (`pnpm build` or have `pnpm dev` / `pnpm build:watch` running in core). This is intentional — sniffing `.ts` vs `.js` via `import.meta.url` was non-deterministic under tsx and broke 12–13 publishes (#1139).\n"
|
|
336
324
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite-plugin/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAelD,YAAY,EACV,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,0BAA0B;IAC1B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,GAAG,CAAC,EAA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AO,GAAE,iBAAsB,GAAG,MAAM,CAg2BlE"}
|
|
@@ -603,8 +603,10 @@ function smrtPlugin(options = {}) {
|
|
|
603
603
|
dist: "../scanner.js"
|
|
604
604
|
});
|
|
605
605
|
const manifestGen = new ManifestGenerator();
|
|
606
|
+
manifestGen.normalizeReportTenantScope(newManifest);
|
|
606
607
|
manifestGen.injectTenantScopedFields(newManifest);
|
|
607
608
|
manifestGen.mergeInheritedFields(newManifest);
|
|
609
|
+
manifestGen.normalizeReportObjects(newManifest);
|
|
608
610
|
manifestGen.generateValidationRules(newManifest);
|
|
609
611
|
manifestGen.generateSchemas(newManifest);
|
|
610
612
|
manifestGen.assertTenantScopedSchemaContract(newManifest);
|