@happyvertical/smrt-core 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.
- package/AGENTS.md +124 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +7 -0
- package/README.md +265 -0
- package/bin/smrt-prebuild.js +26 -0
- package/dist/__tests__/fixtures/advisor-test-classes.d.ts +28 -0
- package/dist/__tests__/fixtures/advisor-test-classes.d.ts.map +1 -0
- package/dist/__tests__/fixtures/collection-coverage-fixtures.d.ts +12 -0
- package/dist/__tests__/fixtures/collection-coverage-fixtures.d.ts.map +1 -0
- package/dist/__tests__/fixtures/inheritance-resolver-fixtures.d.ts +28 -0
- package/dist/__tests__/fixtures/inheritance-resolver-fixtures.d.ts.map +1 -0
- package/dist/__tests__/fixtures/inheritance-test-classes.d.ts +43 -0
- package/dist/__tests__/fixtures/inheritance-test-classes.d.ts.map +1 -0
- package/dist/__tests__/fixtures/mcp-integration-test-classes.d.ts +18 -0
- package/dist/__tests__/fixtures/mcp-integration-test-classes.d.ts.map +1 -0
- package/dist/__tests__/fixtures/object-ai-memory-fixtures.d.ts +15 -0
- package/dist/__tests__/fixtures/object-ai-memory-fixtures.d.ts.map +1 -0
- package/dist/__tests__/fixtures/object-spec-test-classes.d.ts +13 -0
- package/dist/__tests__/fixtures/object-spec-test-classes.d.ts.map +1 -0
- package/dist/__tests__/fixtures/registry-test-classes.d.ts +23 -0
- package/dist/__tests__/fixtures/registry-test-classes.d.ts.map +1 -0
- package/dist/adapters/ai-usage.d.ts +23 -0
- package/dist/adapters/ai-usage.d.ts.map +1 -0
- package/dist/adapters/ai-usage.js +105 -0
- package/dist/adapters/ai-usage.js.map +1 -0
- package/dist/adapters/cost-rates.d.ts +20 -0
- package/dist/adapters/cost-rates.d.ts.map +1 -0
- package/dist/adapters/cost-rates.js +40 -0
- package/dist/adapters/cost-rates.js.map +1 -0
- package/dist/adapters/index.d.ts +19 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/metrics.d.ts +111 -0
- package/dist/adapters/metrics.d.ts.map +1 -0
- package/dist/adapters/metrics.js +169 -0
- package/dist/adapters/metrics.js.map +1 -0
- package/dist/adapters/pubsub.d.ts +124 -0
- package/dist/adapters/pubsub.d.ts.map +1 -0
- package/dist/adapters/pubsub.js +121 -0
- package/dist/adapters/pubsub.js.map +1 -0
- package/dist/browser.d.ts +32 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +68 -0
- package/dist/browser.js.map +1 -0
- package/dist/child-accessors.d.ts +27 -0
- package/dist/child-accessors.d.ts.map +1 -0
- package/dist/child-accessors.js +35 -0
- package/dist/child-accessors.js.map +1 -0
- package/dist/class.d.ts +313 -0
- package/dist/class.d.ts.map +1 -0
- package/dist/class.js +896 -0
- package/dist/class.js.map +1 -0
- package/dist/collection-cache.d.ts +110 -0
- package/dist/collection-cache.d.ts.map +1 -0
- package/dist/collection-cache.js +187 -0
- package/dist/collection-cache.js.map +1 -0
- package/dist/collection.d.ts +894 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/collection.js +1987 -0
- package/dist/collection.js.map +1 -0
- package/dist/config/global-config.d.ts +3 -0
- package/dist/config/global-config.d.ts.map +1 -0
- package/dist/config/global-config.js +19 -0
- package/dist/config/global-config.js.map +1 -0
- package/dist/config.d.ts +145 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +57 -0
- package/dist/config.js.map +1 -0
- package/dist/consumer-plugin/index.d.ts +22 -0
- package/dist/consumer-plugin/index.d.ts.map +1 -0
- package/dist/consumer-plugin/index.js +452 -0
- package/dist/consumer-plugin/index.js.map +1 -0
- package/dist/consumer-plugin.d.ts +8 -0
- package/dist/consumer-plugin.d.ts.map +1 -0
- package/dist/consumer-plugin.js +5 -0
- package/dist/consumer-plugin.js.map +1 -0
- package/dist/database.d.ts +95 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +32 -0
- package/dist/database.js.map +1 -0
- package/dist/decorators/compatibility.d.ts +14 -0
- package/dist/decorators/compatibility.d.ts.map +1 -0
- package/dist/decorators/compatibility.js +111 -0
- package/dist/decorators/compatibility.js.map +1 -0
- package/dist/decorators/index.d.ts +381 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +104 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/dispatch/bus.d.ts +306 -0
- package/dist/dispatch/bus.d.ts.map +1 -0
- package/dist/dispatch/bus.js +583 -0
- package/dist/dispatch/bus.js.map +1 -0
- package/dist/dispatch/collections/DispatchSubscriptions.d.ts +79 -0
- package/dist/dispatch/collections/DispatchSubscriptions.d.ts.map +1 -0
- package/dist/dispatch/collections/DispatchSubscriptions.js +243 -0
- package/dist/dispatch/collections/DispatchSubscriptions.js.map +1 -0
- package/dist/dispatch/collections/Dispatches.d.ts +98 -0
- package/dist/dispatch/collections/Dispatches.d.ts.map +1 -0
- package/dist/dispatch/collections/Dispatches.js +358 -0
- package/dist/dispatch/collections/Dispatches.js.map +1 -0
- package/dist/dispatch/index.d.ts +47 -0
- package/dist/dispatch/index.d.ts.map +1 -0
- package/dist/dispatch/models/Dispatch.d.ts +101 -0
- package/dist/dispatch/models/Dispatch.d.ts.map +1 -0
- package/dist/dispatch/models/Dispatch.js +162 -0
- package/dist/dispatch/models/Dispatch.js.map +1 -0
- package/dist/dispatch/models/DispatchSubscription.d.ts +83 -0
- package/dist/dispatch/models/DispatchSubscription.d.ts.map +1 -0
- package/dist/dispatch/models/DispatchSubscription.js +112 -0
- package/dist/dispatch/models/DispatchSubscription.js.map +1 -0
- package/dist/dispatch/tenant-resolver.d.ts +98 -0
- package/dist/dispatch/tenant-resolver.d.ts.map +1 -0
- package/dist/dispatch/tenant-resolver.js +32 -0
- package/dist/dispatch/tenant-resolver.js.map +1 -0
- package/dist/dispatch/types.d.ts +149 -0
- package/dist/dispatch/types.d.ts.map +1 -0
- package/dist/embeddings/hash.d.ts +33 -0
- package/dist/embeddings/hash.d.ts.map +1 -0
- package/dist/embeddings/hash.js +37 -0
- package/dist/embeddings/hash.js.map +1 -0
- package/dist/embeddings/index.d.ts +36 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/provider.d.ts +75 -0
- package/dist/embeddings/provider.d.ts.map +1 -0
- package/dist/embeddings/provider.js +170 -0
- package/dist/embeddings/provider.js.map +1 -0
- package/dist/embeddings/similarity.d.ts +47 -0
- package/dist/embeddings/similarity.d.ts.map +1 -0
- package/dist/embeddings/similarity.js +64 -0
- package/dist/embeddings/similarity.js.map +1 -0
- package/dist/embeddings/storage.d.ts +125 -0
- package/dist/embeddings/storage.d.ts.map +1 -0
- package/dist/embeddings/storage.js +283 -0
- package/dist/embeddings/storage.js.map +1 -0
- package/dist/embeddings/types.d.ts +250 -0
- package/dist/embeddings/types.d.ts.map +1 -0
- package/dist/errors.d.ts +363 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +669 -0
- package/dist/errors.js.map +1 -0
- package/dist/generators/cli.d.ts +162 -0
- package/dist/generators/cli.d.ts.map +1 -0
- package/dist/generators/cli.js +462 -0
- package/dist/generators/cli.js.map +1 -0
- package/dist/generators/index.d.ts +13 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/mcp-runtime-template.d.ts +60 -0
- package/dist/generators/mcp-runtime-template.d.ts.map +1 -0
- package/dist/generators/mcp-runtime-template.js +509 -0
- package/dist/generators/mcp-runtime-template.js.map +1 -0
- package/dist/generators/mcp.d.ts +231 -0
- package/dist/generators/mcp.d.ts.map +1 -0
- package/dist/generators/mcp.js +1220 -0
- package/dist/generators/mcp.js.map +1 -0
- package/dist/generators/rest.d.ts +171 -0
- package/dist/generators/rest.d.ts.map +1 -0
- package/dist/generators/rest.js +591 -0
- package/dist/generators/rest.js.map +1 -0
- package/dist/generators/swagger.d.ts +21 -0
- package/dist/generators/swagger.d.ts.map +1 -0
- package/dist/generators/swagger.js +307 -0
- package/dist/generators/swagger.js.map +1 -0
- package/dist/generators/tenant-gate.d.ts +74 -0
- package/dist/generators/tenant-gate.d.ts.map +1 -0
- package/dist/generators/tenant-gate.js +15 -0
- package/dist/generators/tenant-gate.js.map +1 -0
- package/dist/generators.d.ts +8 -0
- package/dist/generators.d.ts.map +1 -0
- package/dist/generators.js +19 -0
- package/dist/generators.js.map +1 -0
- package/dist/hierarchical.d.ts +103 -0
- package/dist/hierarchical.d.ts.map +1 -0
- package/dist/hierarchical.js +184 -0
- package/dist/hierarchical.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +202 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors.d.ts +251 -0
- package/dist/interceptors.d.ts.map +1 -0
- package/dist/interceptors.js +259 -0
- package/dist/interceptors.js.map +1 -0
- package/dist/junction.d.ts +99 -0
- package/dist/junction.d.ts.map +1 -0
- package/dist/junction.js +136 -0
- package/dist/junction.js.map +1 -0
- package/dist/knowledge.d.ts +11 -0
- package/dist/knowledge.d.ts.map +1 -0
- package/dist/knowledge.js +310 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/lazy-config.d.ts +160 -0
- package/dist/lazy-config.d.ts.map +1 -0
- package/dist/lazy-config.js +146 -0
- package/dist/lazy-config.js.map +1 -0
- package/dist/manifest/discover-base-classes.d.ts +78 -0
- package/dist/manifest/discover-base-classes.d.ts.map +1 -0
- package/dist/manifest/discover-base-classes.js +85 -0
- package/dist/manifest/discover-base-classes.js.map +1 -0
- package/dist/manifest/discover-smrt-packages.d.ts +48 -0
- package/dist/manifest/discover-smrt-packages.d.ts.map +1 -0
- package/dist/manifest/discover-smrt-packages.js +361 -0
- package/dist/manifest/discover-smrt-packages.js.map +1 -0
- package/dist/manifest/generator.d.ts +93 -0
- package/dist/manifest/generator.d.ts.map +1 -0
- package/dist/manifest/generator.js +380 -0
- package/dist/manifest/generator.js.map +1 -0
- package/dist/manifest/index.d.ts +16 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +51 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/manager.d.ts +51 -0
- package/dist/manifest/manager.d.ts.map +1 -0
- package/dist/manifest/manager.js +89 -0
- package/dist/manifest/manager.js.map +1 -0
- package/dist/manifest/manifest-loader.d.ts +187 -0
- package/dist/manifest/manifest-loader.d.ts.map +1 -0
- package/dist/manifest/manifest-loader.js +847 -0
- package/dist/manifest/manifest-loader.js.map +1 -0
- package/dist/manifest/sources/composite.d.ts +22 -0
- package/dist/manifest/sources/composite.d.ts.map +1 -0
- package/dist/manifest/sources/composite.js +60 -0
- package/dist/manifest/sources/composite.js.map +1 -0
- package/dist/manifest/sources/embedded.d.ts +7 -0
- package/dist/manifest/sources/embedded.d.ts.map +1 -0
- package/dist/manifest/sources/embedded.js +30 -0
- package/dist/manifest/sources/embedded.js.map +1 -0
- package/dist/manifest/sources/explicit-paths.d.ts +17 -0
- package/dist/manifest/sources/explicit-paths.d.ts.map +1 -0
- package/dist/manifest/sources/explicit-paths.js +35 -0
- package/dist/manifest/sources/explicit-paths.js.map +1 -0
- package/dist/manifest/sources/fallback.d.ts +25 -0
- package/dist/manifest/sources/fallback.d.ts.map +1 -0
- package/dist/manifest/sources/fallback.js +63 -0
- package/dist/manifest/sources/fallback.js.map +1 -0
- package/dist/manifest/sources/index.d.ts +17 -0
- package/dist/manifest/sources/index.d.ts.map +1 -0
- package/dist/manifest/sources/local-test.d.ts +7 -0
- package/dist/manifest/sources/local-test.d.ts.map +1 -0
- package/dist/manifest/sources/local-test.js +21 -0
- package/dist/manifest/sources/local-test.js.map +1 -0
- package/dist/manifest/sources/static.d.ts +7 -0
- package/dist/manifest/sources/static.d.ts.map +1 -0
- package/dist/manifest/sources/static.js +19 -0
- package/dist/manifest/sources/static.js.map +1 -0
- package/dist/manifest/sources/test.d.ts +7 -0
- package/dist/manifest/sources/test.d.ts.map +1 -0
- package/dist/manifest/sources/test.js +21 -0
- package/dist/manifest/sources/test.js.map +1 -0
- package/dist/manifest/sources/types.d.ts +79 -0
- package/dist/manifest/sources/types.d.ts.map +1 -0
- package/dist/manifest/sources/types.js +61 -0
- package/dist/manifest/sources/types.js.map +1 -0
- package/dist/manifest/static-manifest.d.ts +4 -0
- package/dist/manifest/static-manifest.d.ts.map +1 -0
- package/dist/manifest/static-manifest.js +1535 -0
- package/dist/manifest/static-manifest.js.map +1 -0
- package/dist/manifest/store.d.ts +111 -0
- package/dist/manifest/store.d.ts.map +1 -0
- package/dist/manifest/store.js +431 -0
- package/dist/manifest/store.js.map +1 -0
- package/dist/manifest/test-manifest-loader.d.ts +3 -0
- package/dist/manifest/test-manifest-loader.d.ts.map +1 -0
- package/dist/manifest/test-manifest-stub.d.ts +4 -0
- package/dist/manifest/test-manifest-stub.d.ts.map +1 -0
- package/dist/manifest/test-manifest-stub.js +80013 -0
- package/dist/manifest/test-manifest-stub.js.map +1 -0
- package/dist/manifest.d.ts +8 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +20 -0
- package/dist/manifest.js.map +1 -0
- package/dist/manifest.json +1489 -0
- package/dist/mcp-advisor/index.d.ts +499 -0
- package/dist/mcp-advisor/index.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/add-ai-methods.d.ts +6 -0
- package/dist/mcp-advisor/tools/add-ai-methods.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/configure-decorators.d.ts +6 -0
- package/dist/mcp-advisor/tools/configure-decorators.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/generate-collection.d.ts +6 -0
- package/dist/mcp-advisor/tools/generate-collection.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/generate-field-definitions.d.ts +6 -0
- package/dist/mcp-advisor/tools/generate-field-definitions.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/generate-smrt-class.d.ts +6 -0
- package/dist/mcp-advisor/tools/generate-smrt-class.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/get-object-config.d.ts +6 -0
- package/dist/mcp-advisor/tools/get-object-config.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/get-object-schema.d.ts +10 -0
- package/dist/mcp-advisor/tools/get-object-schema.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/list-registered-objects.d.ts +9 -0
- package/dist/mcp-advisor/tools/list-registered-objects.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/preview-api-endpoints.d.ts +9 -0
- package/dist/mcp-advisor/tools/preview-api-endpoints.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/preview-mcp-tools.d.ts +9 -0
- package/dist/mcp-advisor/tools/preview-mcp-tools.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/validate-smrt-object.d.ts +6 -0
- package/dist/mcp-advisor/tools/validate-smrt-object.d.ts.map +1 -0
- package/dist/mcp-advisor/types.d.ts +209 -0
- package/dist/mcp-advisor/types.d.ts.map +1 -0
- package/dist/migrations/backfill-tracker.d.ts +84 -0
- package/dist/migrations/backfill-tracker.d.ts.map +1 -0
- package/dist/migrations/backfill-tracker.js +118 -0
- package/dist/migrations/backfill-tracker.js.map +1 -0
- package/dist/migrations/checksum.d.ts +43 -0
- package/dist/migrations/checksum.d.ts.map +1 -0
- package/dist/migrations/checksum.js +32 -0
- package/dist/migrations/checksum.js.map +1 -0
- package/dist/migrations/differ.d.ts +186 -0
- package/dist/migrations/differ.d.ts.map +1 -0
- package/dist/migrations/differ.js +601 -0
- package/dist/migrations/differ.js.map +1 -0
- package/dist/migrations/generator.d.ts +133 -0
- package/dist/migrations/generator.d.ts.map +1 -0
- package/dist/migrations/generator.js +328 -0
- package/dist/migrations/generator.js.map +1 -0
- package/dist/migrations/index.d.ts +20 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/orchestrate.d.ts +148 -0
- package/dist/migrations/orchestrate.d.ts.map +1 -0
- package/dist/migrations/orchestrate.js +118 -0
- package/dist/migrations/orchestrate.js.map +1 -0
- package/dist/migrations/tracker.d.ts +134 -0
- package/dist/migrations/tracker.d.ts.map +1 -0
- package/dist/migrations/tracker.js +624 -0
- package/dist/migrations/tracker.js.map +1 -0
- package/dist/migrations/types.d.ts +221 -0
- package/dist/migrations/types.d.ts.map +1 -0
- package/dist/migrations.d.ts +7 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +26 -0
- package/dist/migrations.js.map +1 -0
- package/dist/node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js +56 -0
- package/dist/node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js.map +1 -0
- package/dist/node_modules/.pnpm/brace-expansion@5.0.5/node_modules/brace-expansion/dist/esm/index.js +163 -0
- package/dist/node_modules/.pnpm/brace-expansion@5.0.5/node_modules/brace-expansion/dist/esm/index.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/assert-valid-pattern.js +13 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/assert-valid-pattern.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/ast.js +654 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/ast.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/brace-expressions.js +111 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/brace-expressions.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/escape.js +10 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/escape.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/index.js +824 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/index.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/unescape.js +10 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/unescape.js.map +1 -0
- package/dist/object.d.ts +1202 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +2731 -0
- package/dist/object.js.map +1 -0
- package/dist/polymorphic-association.d.ts +69 -0
- package/dist/polymorphic-association.d.ts.map +1 -0
- package/dist/polymorphic-association.js +96 -0
- package/dist/polymorphic-association.js.map +1 -0
- package/dist/prebuild/cli.d.ts +7 -0
- package/dist/prebuild/cli.d.ts.map +1 -0
- package/dist/prebuild/cli.js +29 -0
- package/dist/prebuild/cli.js.map +1 -0
- package/dist/prebuild/index.d.ts +22 -0
- package/dist/prebuild/index.d.ts.map +1 -0
- package/dist/prebuild/index.js +239 -0
- package/dist/prebuild/index.js.map +1 -0
- package/dist/prebuild.d.ts +8 -0
- package/dist/prebuild.d.ts.map +1 -0
- package/dist/prebuild.js +6 -0
- package/dist/prebuild.js.map +1 -0
- package/dist/registry/cache-config.d.ts +13 -0
- package/dist/registry/cache-config.d.ts.map +1 -0
- package/dist/registry/cache-config.js +17 -0
- package/dist/registry/cache-config.js.map +1 -0
- package/dist/registry/class-registration.d.ts +31 -0
- package/dist/registry/class-registration.d.ts.map +1 -0
- package/dist/registry/class-registration.js +1074 -0
- package/dist/registry/class-registration.js.map +1 -0
- package/dist/registry/collection-resolution.d.ts +45 -0
- package/dist/registry/collection-resolution.d.ts.map +1 -0
- package/dist/registry/collection-resolution.js +121 -0
- package/dist/registry/collection-resolution.js.map +1 -0
- package/dist/registry/collision-policy.d.ts +179 -0
- package/dist/registry/collision-policy.d.ts.map +1 -0
- package/dist/registry/collision-policy.js +153 -0
- package/dist/registry/collision-policy.js.map +1 -0
- package/dist/registry/diagnostics.d.ts +58 -0
- package/dist/registry/diagnostics.d.ts.map +1 -0
- package/dist/registry/diagnostics.js +54 -0
- package/dist/registry/diagnostics.js.map +1 -0
- package/dist/registry/embedding-manager.d.ts +23 -0
- package/dist/registry/embedding-manager.d.ts.map +1 -0
- package/dist/registry/embedding-manager.js +62 -0
- package/dist/registry/embedding-manager.js.map +1 -0
- package/dist/registry/index.d.ts +13 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/inheritance-resolver.d.ts +13 -0
- package/dist/registry/inheritance-resolver.d.ts.map +1 -0
- package/dist/registry/inheritance-resolver.js +244 -0
- package/dist/registry/inheritance-resolver.js.map +1 -0
- package/dist/registry/manifest-field-merge.d.ts +4 -0
- package/dist/registry/manifest-field-merge.d.ts.map +1 -0
- package/dist/registry/manifest-field-merge.js +82 -0
- package/dist/registry/manifest-field-merge.js.map +1 -0
- package/dist/registry/name-resolver.d.ts +102 -0
- package/dist/registry/name-resolver.d.ts.map +1 -0
- package/dist/registry/name-resolver.js +241 -0
- package/dist/registry/name-resolver.js.map +1 -0
- package/dist/registry/relationship-graph.d.ts +16 -0
- package/dist/registry/relationship-graph.d.ts.map +1 -0
- package/dist/registry/relationship-graph.js +79 -0
- package/dist/registry/relationship-graph.js.map +1 -0
- package/dist/registry/schema-builder.d.ts +113 -0
- package/dist/registry/schema-builder.d.ts.map +1 -0
- package/dist/registry/schema-builder.js +474 -0
- package/dist/registry/schema-builder.js.map +1 -0
- package/dist/registry/shared-state.d.ts +62 -0
- package/dist/registry/shared-state.d.ts.map +1 -0
- package/dist/registry/shared-state.js +135 -0
- package/dist/registry/shared-state.js.map +1 -0
- package/dist/registry/types.d.ts +667 -0
- package/dist/registry/types.d.ts.map +1 -0
- package/dist/registry/validator.d.ts +13 -0
- package/dist/registry/validator.d.ts.map +1 -0
- package/dist/registry/validator.js +138 -0
- package/dist/registry/validator.js.map +1 -0
- package/dist/registry.d.ts +1358 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +2301 -0
- package/dist/registry.js.map +1 -0
- package/dist/runtime/client.d.ts +34 -0
- package/dist/runtime/client.d.ts.map +1 -0
- package/dist/runtime/client.js +104 -0
- package/dist/runtime/client.js.map +1 -0
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/mcp.d.ts +47 -0
- package/dist/runtime/mcp.d.ts.map +1 -0
- package/dist/runtime/mcp.js +72 -0
- package/dist/runtime/mcp.js.map +1 -0
- package/dist/runtime/server.d.ts +92 -0
- package/dist/runtime/server.d.ts.map +1 -0
- package/dist/runtime/server.js +390 -0
- package/dist/runtime/server.js.map +1 -0
- package/dist/runtime/types.d.ts +58 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +10 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scanner/import-scanner.d.ts +7 -0
- package/dist/scanner/import-scanner.d.ts.map +1 -0
- package/dist/scanner/index.d.ts +12 -0
- package/dist/scanner/index.d.ts.map +1 -0
- package/dist/scanner/manifest-generator.d.ts +304 -0
- package/dist/scanner/manifest-generator.d.ts.map +1 -0
- package/dist/scanner/manifest-generator.js +1707 -0
- package/dist/scanner/manifest-generator.js.map +1 -0
- package/dist/scanner/test-file-patterns.d.ts +18 -0
- package/dist/scanner/test-file-patterns.d.ts.map +1 -0
- package/dist/scanner/test-file-patterns.js +16 -0
- package/dist/scanner/test-file-patterns.js.map +1 -0
- package/dist/scanner/types.d.ts +313 -0
- package/dist/scanner/types.d.ts.map +1 -0
- package/dist/scanner/types.js +2 -0
- package/dist/scanner/types.js.map +1 -0
- package/dist/scanner.d.ts +6 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +6 -0
- package/dist/scanner.js.map +1 -0
- package/dist/schema/code-generator.d.ts +53 -0
- package/dist/schema/code-generator.d.ts.map +1 -0
- package/dist/schema/ddl/base-strategy.d.ts +80 -0
- package/dist/schema/ddl/base-strategy.d.ts.map +1 -0
- package/dist/schema/ddl/base-strategy.js +240 -0
- package/dist/schema/ddl/base-strategy.js.map +1 -0
- package/dist/schema/ddl/duckdb-strategy.d.ts +33 -0
- package/dist/schema/ddl/duckdb-strategy.d.ts.map +1 -0
- package/dist/schema/ddl/duckdb-strategy.js +74 -0
- package/dist/schema/ddl/duckdb-strategy.js.map +1 -0
- package/dist/schema/ddl/index.d.ts +53 -0
- package/dist/schema/ddl/index.d.ts.map +1 -0
- package/dist/schema/ddl/index.js +80 -0
- package/dist/schema/ddl/index.js.map +1 -0
- package/dist/schema/ddl/json-duckdb-strategy.d.ts +8 -0
- package/dist/schema/ddl/json-duckdb-strategy.d.ts.map +1 -0
- package/dist/schema/ddl/json-duckdb-strategy.js +14 -0
- package/dist/schema/ddl/json-duckdb-strategy.js.map +1 -0
- package/dist/schema/ddl/postgres-strategy.d.ts +29 -0
- package/dist/schema/ddl/postgres-strategy.d.ts.map +1 -0
- package/dist/schema/ddl/postgres-strategy.js +102 -0
- package/dist/schema/ddl/postgres-strategy.js.map +1 -0
- package/dist/schema/ddl/sqlite-strategy.d.ts +38 -0
- package/dist/schema/ddl/sqlite-strategy.d.ts.map +1 -0
- package/dist/schema/ddl/sqlite-strategy.js +74 -0
- package/dist/schema/ddl/sqlite-strategy.js.map +1 -0
- package/dist/schema/ddl/types.d.ts +114 -0
- package/dist/schema/ddl/types.d.ts.map +1 -0
- package/dist/schema/generator.d.ts +176 -0
- package/dist/schema/generator.d.ts.map +1 -0
- package/dist/schema/generator.js +1076 -0
- package/dist/schema/generator.js.map +1 -0
- package/dist/schema/index-utils.d.ts +19 -0
- package/dist/schema/index-utils.d.ts.map +1 -0
- package/dist/schema/index-utils.js +32 -0
- package/dist/schema/index-utils.js.map +1 -0
- package/dist/schema/index.d.ts +13 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/override-system.d.ts +43 -0
- package/dist/schema/override-system.d.ts.map +1 -0
- package/dist/schema/schema-aggregator.d.ts +112 -0
- package/dist/schema/schema-aggregator.d.ts.map +1 -0
- package/dist/schema/schema-manager.d.ts +95 -0
- package/dist/schema/schema-manager.d.ts.map +1 -0
- package/dist/schema/schema-manager.js +283 -0
- package/dist/schema/schema-manager.js.map +1 -0
- package/dist/schema/sql-identifiers.d.ts +107 -0
- package/dist/schema/sql-identifiers.d.ts.map +1 -0
- package/dist/schema/sql-identifiers.js +190 -0
- package/dist/schema/sql-identifiers.js.map +1 -0
- package/dist/schema/table-verifier.d.ts +10 -0
- package/dist/schema/table-verifier.d.ts.map +1 -0
- package/dist/schema/table-verifier.js +37 -0
- package/dist/schema/table-verifier.js.map +1 -0
- package/dist/schema/types.d.ts +241 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/utils.d.ts +32 -0
- package/dist/schema/utils.d.ts.map +1 -0
- package/dist/schema/utils.js +134 -0
- package/dist/schema/utils.js.map +1 -0
- package/dist/scripts/create-wrappers.js +89 -0
- package/dist/scripts/generate-manifest.js +155 -0
- package/dist/scripts/generate-test-manifest.js +77 -0
- package/dist/scripts/migrate-datetime-to-timestamp.ts +310 -0
- package/dist/scripts/prepack.js +49 -0
- package/dist/signals/bus.d.ts +64 -0
- package/dist/signals/bus.d.ts.map +1 -0
- package/dist/signals/bus.js +102 -0
- package/dist/signals/bus.js.map +1 -0
- package/dist/signals/index.d.ts +11 -0
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/sanitizer.d.ts +54 -0
- package/dist/signals/sanitizer.d.ts.map +1 -0
- package/dist/signals/sanitizer.js +111 -0
- package/dist/signals/sanitizer.js.map +1 -0
- package/dist/smrt-knowledge.json +335 -0
- package/dist/system/compatibility.d.ts +8 -0
- package/dist/system/compatibility.d.ts.map +1 -0
- package/dist/system/compatibility.js +409 -0
- package/dist/system/compatibility.js.map +1 -0
- package/dist/system/index.d.ts +9 -0
- package/dist/system/index.d.ts.map +1 -0
- package/dist/system/schema.d.ts +69 -0
- package/dist/system/schema.d.ts.map +1 -0
- package/dist/system/schema.js +271 -0
- package/dist/system/schema.js.map +1 -0
- package/dist/system/types.d.ts +135 -0
- package/dist/system/types.d.ts.map +1 -0
- package/dist/system-fields.d.ts +44 -0
- package/dist/system-fields.d.ts.map +1 -0
- package/dist/system-fields.js +55 -0
- package/dist/system-fields.js.map +1 -0
- package/dist/table-cache.d.ts +28 -0
- package/dist/table-cache.d.ts.map +1 -0
- package/dist/table-cache.js +21 -0
- package/dist/table-cache.js.map +1 -0
- package/dist/test-utils.d.ts +140 -0
- package/dist/test-utils.d.ts.map +1 -0
- package/dist/testing/database.d.ts +73 -0
- package/dist/testing/database.d.ts.map +1 -0
- package/dist/testing/database.js +204 -0
- package/dist/testing/database.js.map +1 -0
- package/dist/testing/index.d.ts +21 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing.d.ts +6 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +5 -0
- package/dist/testing.js.map +1 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/tool-executor.d.ts +101 -0
- package/dist/tools/tool-executor.d.ts.map +1 -0
- package/dist/tools/tool-executor.js +142 -0
- package/dist/tools/tool-executor.js.map +1 -0
- package/dist/tools/tool-generator.d.ts +54 -0
- package/dist/tools/tool-generator.d.ts.map +1 -0
- package/dist/tools/tool-generator.js +121 -0
- package/dist/tools/tool-generator.js.map +1 -0
- package/dist/utils/chunk.d.ts +32 -0
- package/dist/utils/chunk.d.ts.map +1 -0
- package/dist/utils/chunk.js +14 -0
- package/dist/utils/chunk.js.map +1 -0
- package/dist/utils/import-workspace-module.d.ts +8 -0
- package/dist/utils/import-workspace-module.d.ts.map +1 -0
- package/dist/utils/import-workspace-module.js +81 -0
- package/dist/utils/import-workspace-module.js.map +1 -0
- package/dist/utils/json.d.ts +102 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +43 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/lru-cache.d.ts +69 -0
- package/dist/utils/lru-cache.d.ts.map +1 -0
- package/dist/utils/lru-cache.js +100 -0
- package/dist/utils/lru-cache.js.map +1 -0
- package/dist/utils/naming.d.ts +16 -0
- package/dist/utils/naming.d.ts.map +1 -0
- package/dist/utils/naming.js +23 -0
- package/dist/utils/naming.js.map +1 -0
- package/dist/utils/qualified-names.d.ts +122 -0
- package/dist/utils/qualified-names.d.ts.map +1 -0
- package/dist/utils/qualified-names.js +82 -0
- package/dist/utils/qualified-names.js.map +1 -0
- package/dist/utils/scanner-module.d.ts +37 -0
- package/dist/utils/scanner-module.d.ts.map +1 -0
- package/dist/utils.d.ts +177 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +185 -0
- package/dist/utils.js.map +1 -0
- package/dist/vite-plugin/import-build-aware.d.ts +68 -0
- package/dist/vite-plugin/import-build-aware.d.ts.map +1 -0
- package/dist/vite-plugin/import-build-aware.js +72 -0
- package/dist/vite-plugin/import-build-aware.js.map +1 -0
- package/dist/vite-plugin/index.d.ts +59 -0
- package/dist/vite-plugin/index.d.ts.map +1 -0
- package/dist/vite-plugin/index.js +1400 -0
- package/dist/vite-plugin/index.js.map +1 -0
- package/dist/vite-plugin/sveltekit-generator.d.ts +66 -0
- package/dist/vite-plugin/sveltekit-generator.d.ts.map +1 -0
- package/dist/vite-plugin/sveltekit-generator.js +1375 -0
- package/dist/vite-plugin/sveltekit-generator.js.map +1 -0
- package/dist/vite-plugin/templates/default-ui.ts +432 -0
- package/dist/vite-plugin/templates/default.html +206 -0
- package/dist/vite-plugin.d.ts +8 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +11 -0
- package/dist/vite-plugin.js.map +1 -0
- package/package.json +208 -0
|
@@ -0,0 +1,894 @@
|
|
|
1
|
+
import { SmrtClassOptions, SmrtClass } from './class';
|
|
2
|
+
import { CollectionCacheConfig } from './collection-cache';
|
|
3
|
+
import { SmrtObject } from './object';
|
|
4
|
+
/**
|
|
5
|
+
* Keys from SmrtObject and SmrtClass that should not appear as user-facing
|
|
6
|
+
* create/update input fields. These are framework-internal properties.
|
|
7
|
+
*/
|
|
8
|
+
type SmrtInternalKeys = keyof SmrtClass | '_tableName' | '_loadedRelationships' | '_id' | '_slug' | '_context' | '_ai' | '_fs' | '_db' | '_className' | 'options' | '_skipLoad' | '_skipAutoEmbeddings' | '_extractingFields' | 'initialize' | 'save' | 'delete' | 'loadFromId' | 'loadFromSlug' | 'is' | 'do' | 'toJSON' | 'transformJSON';
|
|
9
|
+
/**
|
|
10
|
+
* Input type for `collection.create()`. Constrains input to valid model fields
|
|
11
|
+
* while preserving backwards compatibility via an index signature escape hatch.
|
|
12
|
+
*
|
|
13
|
+
* Provides IDE autocompletion for known fields from the model class while still
|
|
14
|
+
* accepting arbitrary keys for dynamic usage patterns (e.g., STI meta fields).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // IDE will suggest: name, price, quantity, categoryId, etc.
|
|
19
|
+
* await productCollection.create({
|
|
20
|
+
* name: 'Widget',
|
|
21
|
+
* price: 9.99,
|
|
22
|
+
* _meta_type: 'SpecialProduct', // STI discriminator
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export type SmrtCreateInput<T extends SmrtObject> = Partial<Omit<{
|
|
27
|
+
[K in keyof T as T[K] extends (...args: any[]) => any ? never : K]: T[K];
|
|
28
|
+
}, SmrtInternalKeys>> & {
|
|
29
|
+
/** STI discriminator for polymorphic creation */
|
|
30
|
+
_meta_type?: string;
|
|
31
|
+
/** Skip database loading (framework internal) */
|
|
32
|
+
_skipLoad?: boolean;
|
|
33
|
+
/** Skip save-time embedding auto-generation (framework internal) */
|
|
34
|
+
_skipAutoEmbeddings?: boolean;
|
|
35
|
+
/** Allow arbitrary additional fields for dynamic usage */
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* WHERE clause type for `collection.list()`.
|
|
40
|
+
*
|
|
41
|
+
* Uses `Record<string, unknown>` because WHERE keys often include operator
|
|
42
|
+
* suffixes (e.g., `'price >'`, `'name like'`, `'status in'`) which can't be
|
|
43
|
+
* expressed as mapped types from model properties. Runtime validation in
|
|
44
|
+
* `convertWhereKeys()` handles field and operator checking.
|
|
45
|
+
*/
|
|
46
|
+
export type SmrtWhereClause<T extends SmrtObject> = Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Configuration options for SmrtCollection
|
|
49
|
+
*/
|
|
50
|
+
export interface SmrtCollectionOptions extends SmrtClassOptions {
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Typed CRUD collection for a specific `SmrtObject` subclass.
|
|
54
|
+
*
|
|
55
|
+
* Each concrete collection pairs with exactly one model class via the required
|
|
56
|
+
* `static readonly _itemClass` property. Use the static `create()` factory —
|
|
57
|
+
* not `new` — to get a fully initialized, ready-to-query instance.
|
|
58
|
+
*
|
|
59
|
+
* Key capabilities:
|
|
60
|
+
* - **Query**: `list()`, `get()`, `count()`, `query()` (raw SQL), `listByIds()`
|
|
61
|
+
* - **Mutation**: `create()`, `getOrUpsert()`, `delete()`
|
|
62
|
+
* - **Eager loading**: pass `include: ['fieldName']` to `list()` to avoid N+1 queries
|
|
63
|
+
* - **STI support**: automatically filters by `_meta_type` for child collections;
|
|
64
|
+
* polymorphically hydrates the correct subclass when listing/getting
|
|
65
|
+
* - **Interceptors**: all read/write paths run `GlobalInterceptors` hooks
|
|
66
|
+
* (used by multi-tenancy, audit logging, etc.)
|
|
67
|
+
*
|
|
68
|
+
* @typeParam ModelType - The `SmrtObject` subclass managed by this collection
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* @smrt()
|
|
73
|
+
* class Product extends SmrtObject {
|
|
74
|
+
* name: string = '';
|
|
75
|
+
* price: number = 0.0;
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* @smrt()
|
|
79
|
+
* class Products extends SmrtCollection<Product> {
|
|
80
|
+
* static readonly _itemClass = Product;
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* const products = await Products.create({ db: myDb });
|
|
84
|
+
* const widget = await products.create({ name: 'Widget', price: 9.99 });
|
|
85
|
+
* const all = await products.list({ where: { 'price >': 5 }, orderBy: 'price ASC' });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare class SmrtCollection<ModelType extends SmrtObject> extends SmrtClass {
|
|
89
|
+
/**
|
|
90
|
+
* Cached fields for sync access during queries.
|
|
91
|
+
* Populated during create() to avoid async getFields() calls on every query.
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
private _cachedFields;
|
|
95
|
+
private getRegisteredItemClass;
|
|
96
|
+
private getResolvedItemClassName;
|
|
97
|
+
private getResolvedItemQualifiedName;
|
|
98
|
+
/**
|
|
99
|
+
* Convert WHERE clause field names from camelCase to snake_case while preserving operators.
|
|
100
|
+
* Validates operators and field names to prevent SQL injection and invalid queries.
|
|
101
|
+
*
|
|
102
|
+
* Uses cached fields for sync access (issue #663) to avoid async overhead on every query.
|
|
103
|
+
*
|
|
104
|
+
* @param where - WHERE clause object with camelCase field names
|
|
105
|
+
* @returns WHERE clause object with snake_case field names
|
|
106
|
+
* @private
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* // Input: { 'typeId': 'foo', 'categoryId >': 100 }
|
|
111
|
+
* // Output: { 'type_id': 'foo', 'category_id >': 100 }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
private convertWhereKeys;
|
|
115
|
+
/**
|
|
116
|
+
* Gets the class constructor for items in this collection
|
|
117
|
+
*/
|
|
118
|
+
protected get _itemClass(): (new (options: any) => ModelType) & {
|
|
119
|
+
create(options: any): ModelType | Promise<ModelType>;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Static reference to the item class constructor
|
|
123
|
+
*/
|
|
124
|
+
static readonly _itemClass: any;
|
|
125
|
+
/**
|
|
126
|
+
* Validates that the collection is properly configured
|
|
127
|
+
* Call this during development to catch configuration issues early
|
|
128
|
+
*/
|
|
129
|
+
static validate(): void;
|
|
130
|
+
/**
|
|
131
|
+
* Database table name for this collection
|
|
132
|
+
*/
|
|
133
|
+
_tableName: string;
|
|
134
|
+
/**
|
|
135
|
+
* Creates a new SmrtCollection instance
|
|
136
|
+
*
|
|
137
|
+
* @deprecated Use the static create() factory method instead
|
|
138
|
+
* @param options - Configuration options
|
|
139
|
+
*/
|
|
140
|
+
constructor(options?: SmrtCollectionOptions);
|
|
141
|
+
/**
|
|
142
|
+
* Factory method — the recommended way to instantiate a collection.
|
|
143
|
+
*
|
|
144
|
+
* Creates the collection instance, calls `initialize()`, and pre-populates
|
|
145
|
+
* the field cache used by synchronous query helpers.
|
|
146
|
+
*
|
|
147
|
+
* Pass the same `options` object you received in a `SmrtObject` constructor
|
|
148
|
+
* or a `SvelteKit` load function to share the database connection.
|
|
149
|
+
*
|
|
150
|
+
* @param options - Database, AI, filesystem, and other configuration options.
|
|
151
|
+
* At minimum, provide `db` (or `persistence`) to connect to a database.
|
|
152
|
+
* @returns A fully initialized, ready-to-query collection instance
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // Share a DB connection from a SvelteKit load function
|
|
157
|
+
* const products = await Products.create(event.locals.smrtOptions);
|
|
158
|
+
*
|
|
159
|
+
* // Explicit configuration
|
|
160
|
+
* const products = await Products.create({
|
|
161
|
+
* db: myDb,
|
|
162
|
+
* ai: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY },
|
|
163
|
+
* });
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
static create<T extends SmrtCollection<any>>(this: new (options?: SmrtCollectionOptions) => T, options?: SmrtClassOptions): Promise<T>;
|
|
167
|
+
/**
|
|
168
|
+
* Async initialization hook for the collection.
|
|
169
|
+
*
|
|
170
|
+
* Called automatically by the static `create()` factory. In most cases you
|
|
171
|
+
* do not need to call this directly — use `create()` instead.
|
|
172
|
+
*
|
|
173
|
+
* Runtime schema checks are deferred until a query actually touches the
|
|
174
|
+
* backing table. This keeps collection construction safe during SSR and
|
|
175
|
+
* import-time module evaluation without mutating application schema.
|
|
176
|
+
*
|
|
177
|
+
* @returns This instance (enables chaining)
|
|
178
|
+
*/
|
|
179
|
+
initialize(): Promise<this>;
|
|
180
|
+
/**
|
|
181
|
+
* Verify that the collection's backing table exists before running a query.
|
|
182
|
+
*
|
|
183
|
+
* This is a fail-fast check only. It does not create or alter schema.
|
|
184
|
+
*/
|
|
185
|
+
ensureStorageReady(): Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* Find a single record by criteria (convenience method - delegates to get())
|
|
188
|
+
*
|
|
189
|
+
* @param options - Query options with where clause
|
|
190
|
+
* @returns Promise resolving to the object or null if not found
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* const councils = await Councils.create({ persistence: { type: 'sql', url: 'db.sqlite' } });
|
|
195
|
+
* const council = await councils.findOne({ where: { name: 'Example Council' } });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
findOne(options: {
|
|
199
|
+
where: Record<string, any>;
|
|
200
|
+
}): Promise<ModelType | null>;
|
|
201
|
+
/**
|
|
202
|
+
* Find a record by ID (convenience method - delegates to get())
|
|
203
|
+
*
|
|
204
|
+
* @param id - Record ID to find (string or Field instance)
|
|
205
|
+
* @returns Promise resolving to the object or null if not found
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const councils = await Councils.create({ persistence: { type: 'sql', url: 'db.sqlite' } });
|
|
210
|
+
* const council = await councils.findById('uuid-123');
|
|
211
|
+
*
|
|
212
|
+
* // Also works with Field instances (e.g., from foreignKey fields)
|
|
213
|
+
* const meeting = new Meeting({ councilId: 'uuid-123' });
|
|
214
|
+
* const council = await councils.findById(meeting.councilId);
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
findById(id: string): Promise<ModelType | null>;
|
|
218
|
+
/**
|
|
219
|
+
* Find all records matching criteria (convenience method - delegates to list())
|
|
220
|
+
*
|
|
221
|
+
* @param options - Query options (where, orderBy, limit, etc.)
|
|
222
|
+
* @returns Promise resolving to array of objects
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const councils = await Councils.create({ persistence: { type: 'sql', url: 'db.sqlite' } });
|
|
227
|
+
* const active = await councils.findAll({ where: { status: 'active' } });
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
findAll(options?: {
|
|
231
|
+
where?: SmrtWhereClause<ModelType>;
|
|
232
|
+
orderBy?: string | string[];
|
|
233
|
+
limit?: number;
|
|
234
|
+
offset?: number;
|
|
235
|
+
include?: string[];
|
|
236
|
+
}): Promise<ModelType[]>;
|
|
237
|
+
/**
|
|
238
|
+
* Find multiple objects by their IDs in a single query.
|
|
239
|
+
*
|
|
240
|
+
* This is a convenience method that avoids N+1 queries when you have
|
|
241
|
+
* a list of IDs and need to fetch the corresponding records.
|
|
242
|
+
*
|
|
243
|
+
* @param ids - Array of UUIDs to fetch
|
|
244
|
+
* @returns Promise resolving to array of objects (order not guaranteed)
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* const profiles = await profileCollection.listByIds(['id1', 'id2', 'id3']);
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
listByIds(ids: string[]): Promise<ModelType[]>;
|
|
252
|
+
/**
|
|
253
|
+
* Resolve the effective cache config for a read (issue #1498).
|
|
254
|
+
*
|
|
255
|
+
* Per-call options win: `false` forces a fresh read, `{ ttl }` enables
|
|
256
|
+
* caching for this call. Otherwise falls back to the model-level
|
|
257
|
+
* `@smrt({ cache })` config (inheritance-aware). Returns undefined when
|
|
258
|
+
* the read should go straight to the database — the default.
|
|
259
|
+
*/
|
|
260
|
+
private resolveReadCacheConfig;
|
|
261
|
+
/**
|
|
262
|
+
* Execute a SELECT, optionally through the collection read cache.
|
|
263
|
+
*
|
|
264
|
+
* The cache key is the final SQL + bound parameters — computed after
|
|
265
|
+
* interceptors (tenancy filters) and STI discriminators are applied, so
|
|
266
|
+
* differently-scoped queries can never share an entry. Cached values are
|
|
267
|
+
* raw rows; hydration and read interceptors still run on every call.
|
|
268
|
+
*/
|
|
269
|
+
private queryRowsWithCache;
|
|
270
|
+
/**
|
|
271
|
+
* Retrieves a single object from the collection by ID, slug, or a custom filter.
|
|
272
|
+
*
|
|
273
|
+
* Filter resolution:
|
|
274
|
+
* - UUID string → `WHERE id = ?`
|
|
275
|
+
* - Non-UUID string → `WHERE slug = ? AND context = ''`
|
|
276
|
+
* - Object → `WHERE <key> = <value> [AND ...]`
|
|
277
|
+
*
|
|
278
|
+
* For STI child collections, an `AND _meta_type = '<qualifiedName>'` clause is
|
|
279
|
+
* automatically appended so you only receive the correct subclass.
|
|
280
|
+
*
|
|
281
|
+
* Runs `beforeGet` / `afterGet` interceptors (used by multi-tenancy, etc.).
|
|
282
|
+
*
|
|
283
|
+
* @param filter - UUID string, slug string, or a WHERE conditions object
|
|
284
|
+
* @param options.cache - Opt-in read-through cache for this call
|
|
285
|
+
* (`{ ttl }` in milliseconds), or `false` to force a fresh read when the
|
|
286
|
+
* model opted in via `@smrt({ cache })`. Defaults to the model config.
|
|
287
|
+
* @returns The matching object instance, or `null` if not found
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* // By UUID
|
|
292
|
+
* const product = await products.get('550e8400-e29b-41d4-a716-446655440000');
|
|
293
|
+
*
|
|
294
|
+
* // By slug
|
|
295
|
+
* const product = await products.get('my-widget');
|
|
296
|
+
*
|
|
297
|
+
* // By custom filter
|
|
298
|
+
* const product = await products.get({ sku: 'WID-001' });
|
|
299
|
+
*
|
|
300
|
+
* // Cached read (memoized for 60s, invalidated on writes)
|
|
301
|
+
* const product = await products.get('my-widget', { cache: { ttl: 60_000 } });
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
304
|
+
* @see {@link list} for multiple results
|
|
305
|
+
* @see {@link findById} / {@link findOne} for convenience aliases
|
|
306
|
+
*/
|
|
307
|
+
get(filter: string | Record<string, any>, options?: {
|
|
308
|
+
cache?: CollectionCacheConfig | false;
|
|
309
|
+
}): Promise<ModelType | null>;
|
|
310
|
+
/**
|
|
311
|
+
* Lists records from the collection with flexible filtering options
|
|
312
|
+
*
|
|
313
|
+
* @param options - Query options object
|
|
314
|
+
* @param options.where - Record of conditions to filter results. Each key can include an operator
|
|
315
|
+
* separated by a space (e.g., 'price >', 'name like'). Default operator is '='.
|
|
316
|
+
* @param options.offset - Number of records to skip
|
|
317
|
+
* @param options.limit - Maximum number of records to return
|
|
318
|
+
* @param options.orderBy - Field(s) to order results by, with optional direction
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* // Find active products priced between $100-$200
|
|
323
|
+
* await collection.list({
|
|
324
|
+
* where: {
|
|
325
|
+
* 'price >': 100,
|
|
326
|
+
* 'price <=': 200,
|
|
327
|
+
* 'status': 'active', // equals operator is default
|
|
328
|
+
* 'category in': ['A', 'B', 'C'], // IN operator for arrays
|
|
329
|
+
* 'name like': '%shirt%', // LIKE for pattern matching
|
|
330
|
+
* 'deleted_at !=': null // exclude deleted items
|
|
331
|
+
* },
|
|
332
|
+
* limit: 10,
|
|
333
|
+
* offset: 0
|
|
334
|
+
* });
|
|
335
|
+
*
|
|
336
|
+
* // Find users matching pattern but not in specific roles
|
|
337
|
+
* await users.list({
|
|
338
|
+
* where: {
|
|
339
|
+
* 'email like': '%@company.com',
|
|
340
|
+
* 'active': true,
|
|
341
|
+
* 'role in': ['guest', 'blocked'],
|
|
342
|
+
* 'last_login <': lastMonth
|
|
343
|
+
* }
|
|
344
|
+
* });
|
|
345
|
+
* ```
|
|
346
|
+
*
|
|
347
|
+
* @returns Promise resolving to an array of model instances
|
|
348
|
+
*/
|
|
349
|
+
list(options?: {
|
|
350
|
+
where?: SmrtWhereClause<ModelType>;
|
|
351
|
+
offset?: number;
|
|
352
|
+
limit?: number;
|
|
353
|
+
orderBy?: string | string[];
|
|
354
|
+
/**
|
|
355
|
+
* Relationships to eagerly load (avoids N+1 query problem)
|
|
356
|
+
* @example
|
|
357
|
+
* ```typescript
|
|
358
|
+
* // Load orders with their customers pre-loaded
|
|
359
|
+
* const orders = await orderCollection.list({
|
|
360
|
+
* include: ['customerId']
|
|
361
|
+
* });
|
|
362
|
+
* // Access customer without additional query
|
|
363
|
+
* orders[0].getRelated('customerId');
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
include?: string[];
|
|
367
|
+
/**
|
|
368
|
+
* Opt-in read-through cache for this call (issue #1498).
|
|
369
|
+
*
|
|
370
|
+
* Pass `{ ttl }` (milliseconds) to memoize the result rows keyed by
|
|
371
|
+
* the final query shape. Mutations through SMRT invalidate the
|
|
372
|
+
* table's entries automatically. Pass `false` to force a fresh read
|
|
373
|
+
* when the model opted in via `@smrt({ cache })`. Defaults to the
|
|
374
|
+
* model-level config; uncached when neither is set.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* const published = await resumes.list({
|
|
379
|
+
* where: { status: 'published' },
|
|
380
|
+
* cache: { ttl: 60_000 },
|
|
381
|
+
* });
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
cache?: CollectionCacheConfig | false;
|
|
385
|
+
}): Promise<ModelType[]>;
|
|
386
|
+
/**
|
|
387
|
+
* Eagerly load relationships for a collection of instances
|
|
388
|
+
*
|
|
389
|
+
* Optimizes loading by batching queries for foreignKey relationships to avoid N+1 queries.
|
|
390
|
+
*
|
|
391
|
+
* @param instances - Array of object instances to load relationships for
|
|
392
|
+
* @param relationships - Array of relationship field names to load
|
|
393
|
+
* @private
|
|
394
|
+
*/
|
|
395
|
+
private eagerLoadRelationships;
|
|
396
|
+
/**
|
|
397
|
+
* Batch load foreignKey relationships to avoid N+1 queries
|
|
398
|
+
*
|
|
399
|
+
* @param instances - Instances to load relationships for
|
|
400
|
+
* @param fieldName - Name of the foreignKey field
|
|
401
|
+
* @param relationship - Relationship metadata
|
|
402
|
+
* @private
|
|
403
|
+
*/
|
|
404
|
+
private batchLoadForeignKeys;
|
|
405
|
+
/**
|
|
406
|
+
* Batch load oneToMany relationships
|
|
407
|
+
*
|
|
408
|
+
* @param instances - Instances to load relationships for
|
|
409
|
+
* @param fieldName - Name of the oneToMany field
|
|
410
|
+
* @param relationship - Relationship metadata
|
|
411
|
+
* @private
|
|
412
|
+
*/
|
|
413
|
+
private batchLoadOneToMany;
|
|
414
|
+
/**
|
|
415
|
+
* Batch-load manyToMany relationships through a junction table.
|
|
416
|
+
*
|
|
417
|
+
* Issues two queries instead of N: one against the junction table to map
|
|
418
|
+
* source IDs to target IDs, and one against the target table to hydrate
|
|
419
|
+
* the related rows. Results are grouped by source instance.
|
|
420
|
+
*
|
|
421
|
+
* @param instances - Instances whose manyToMany field should be populated
|
|
422
|
+
* @param fieldName - Name of the @manyToMany decorated field
|
|
423
|
+
* @param relationship - Relationship metadata from the registry
|
|
424
|
+
* @private
|
|
425
|
+
*/
|
|
426
|
+
private batchLoadManyToMany;
|
|
427
|
+
/**
|
|
428
|
+
* Creates and persists a new instance of the collection's item class.
|
|
429
|
+
*
|
|
430
|
+
* Instantiates the model with the given field values, calls `initialize()`,
|
|
431
|
+
* assigns a UUID if none is provided, then calls `save()` to write the row
|
|
432
|
+
* to the database.
|
|
433
|
+
*
|
|
434
|
+
* For STI collections, pass `_meta_type` to create a specific subclass.
|
|
435
|
+
* The correct constructor is resolved via `ObjectRegistry` (polymorphic creation).
|
|
436
|
+
*
|
|
437
|
+
* @param options - Field values for the new object. Accepts any public field on
|
|
438
|
+
* the model class plus the STI `_meta_type` discriminator.
|
|
439
|
+
* @returns The newly created and saved model instance
|
|
440
|
+
* @throws {ValidationError} If a `required` field is missing or a unique constraint is violated
|
|
441
|
+
* @throws {DatabaseError} If the write fails
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```typescript
|
|
445
|
+
* // Regular creation
|
|
446
|
+
* const product = await products.create({ name: 'Widget', price: 9.99 });
|
|
447
|
+
* console.log(product.id); // UUID assigned during save
|
|
448
|
+
*
|
|
449
|
+
* // STI polymorphic creation
|
|
450
|
+
* const article = await contents.create({
|
|
451
|
+
* _meta_type: '@happyvertical/smrt-content:Article',
|
|
452
|
+
* title: 'Hello World',
|
|
453
|
+
* });
|
|
454
|
+
* ```
|
|
455
|
+
*
|
|
456
|
+
* @see {@link getOrUpsert} to avoid duplicates by finding-or-creating
|
|
457
|
+
*/
|
|
458
|
+
create(options: SmrtCreateInput<ModelType>): Promise<ModelType>;
|
|
459
|
+
/**
|
|
460
|
+
* Creates an instance of the correct subclass for STI polymorphic queries
|
|
461
|
+
*
|
|
462
|
+
* @param className - Name of the class to instantiate (from _meta_type)
|
|
463
|
+
* @param options - Data to initialize the instance with
|
|
464
|
+
* @returns Promise resolving to the instance of the correct subclass
|
|
465
|
+
* @private
|
|
466
|
+
*/
|
|
467
|
+
private createPolymorphic;
|
|
468
|
+
/**
|
|
469
|
+
* Finds an existing record matching `data` or creates it if not found.
|
|
470
|
+
*
|
|
471
|
+
* Look-up priority:
|
|
472
|
+
* 1. `data.id` — query by primary key
|
|
473
|
+
* 2. `data.slug` — query by slug + context
|
|
474
|
+
* 3. Fallback — query by the full `data` object as a WHERE clause
|
|
475
|
+
*
|
|
476
|
+
* If a matching record is found, it is updated with any changed fields from
|
|
477
|
+
* `data` (diffed against the existing record) and saved. If no match is
|
|
478
|
+
* found, `defaults` are merged with `data` and a new record is created.
|
|
479
|
+
*
|
|
480
|
+
* @param data - The field values to find or upsert
|
|
481
|
+
* @param defaults - Extra default values applied only when creating a new record
|
|
482
|
+
* @returns The existing (possibly updated) or newly created object instance
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```typescript
|
|
486
|
+
* // Find-or-create a tag by slug
|
|
487
|
+
* const tag = await tags.getOrUpsert({ slug: 'javascript', name: 'JavaScript' });
|
|
488
|
+
*
|
|
489
|
+
* // With defaults applied only on creation
|
|
490
|
+
* const user = await users.getOrUpsert(
|
|
491
|
+
* { email: 'alice@example.com' },
|
|
492
|
+
* { role: 'member', active: true },
|
|
493
|
+
* );
|
|
494
|
+
* ```
|
|
495
|
+
*
|
|
496
|
+
* @see {@link create} for always-insert semantics
|
|
497
|
+
* @see {@link get} for read-only lookup
|
|
498
|
+
*/
|
|
499
|
+
getOrUpsert(data: any, defaults?: any): Promise<ModelType>;
|
|
500
|
+
/**
|
|
501
|
+
* Gets differences between an existing object and new data
|
|
502
|
+
*
|
|
503
|
+
* @param existing - Existing object
|
|
504
|
+
* @param data - New data
|
|
505
|
+
* @returns Object containing only the changed fields
|
|
506
|
+
*/
|
|
507
|
+
getDiff(existing: Record<string, any>, data: Record<string, any>): Promise<Record<string, any> | null>;
|
|
508
|
+
private getDiffSync;
|
|
509
|
+
/**
|
|
510
|
+
* Gets field definitions for the collection's item class
|
|
511
|
+
*
|
|
512
|
+
* @returns Object containing field definitions
|
|
513
|
+
*/
|
|
514
|
+
getFields(): Promise<Record<string, any>>;
|
|
515
|
+
/**
|
|
516
|
+
* Normalize user input into the model's logical field names before diffing or creation.
|
|
517
|
+
*
|
|
518
|
+
* Accepts both camelCase and snake_case keys while preserving framework meta fields.
|
|
519
|
+
*/
|
|
520
|
+
private normalizeLogicalData;
|
|
521
|
+
/**
|
|
522
|
+
* Preserve persisted core timestamp fields during lightweight hydration.
|
|
523
|
+
*/
|
|
524
|
+
private withHydratedCoreFields;
|
|
525
|
+
/**
|
|
526
|
+
* Treat date-equivalent values as unchanged even if their runtime types differ.
|
|
527
|
+
*/
|
|
528
|
+
private areEquivalentValues;
|
|
529
|
+
/**
|
|
530
|
+
* Convert supported date inputs into comparable timestamps.
|
|
531
|
+
*/
|
|
532
|
+
private toComparableTime;
|
|
533
|
+
/**
|
|
534
|
+
* Gets field definitions synchronously from cache.
|
|
535
|
+
*
|
|
536
|
+
* This method provides sync access to fields for use in query methods,
|
|
537
|
+
* avoiding the async overhead of getFields() on every query.
|
|
538
|
+
* Fields are cached during create() initialization.
|
|
539
|
+
*
|
|
540
|
+
* @returns Map containing field definitions
|
|
541
|
+
* @private
|
|
542
|
+
*/
|
|
543
|
+
getFieldsSync(): Record<string, any>;
|
|
544
|
+
/**
|
|
545
|
+
* Generates database schema for the collection's item class
|
|
546
|
+
*
|
|
547
|
+
* Leverages ObjectRegistry's cached schema for instant retrieval.
|
|
548
|
+
*
|
|
549
|
+
* @returns Schema object for database setup
|
|
550
|
+
*/
|
|
551
|
+
generateSchema(): Promise<string>;
|
|
552
|
+
/**
|
|
553
|
+
* Gets the database table name for this collection
|
|
554
|
+
*/
|
|
555
|
+
get tableName(): string;
|
|
556
|
+
/**
|
|
557
|
+
* Generates a table name from the collection class name
|
|
558
|
+
*
|
|
559
|
+
* @returns Generated table name
|
|
560
|
+
*/
|
|
561
|
+
generateTableName(): string;
|
|
562
|
+
/**
|
|
563
|
+
* Deletes a record from the collection by ID
|
|
564
|
+
*
|
|
565
|
+
* Loads the object and calls its delete() method, ensuring all interceptors
|
|
566
|
+
* and lifecycle hooks (beforeDelete/afterDelete) are executed correctly.
|
|
567
|
+
*
|
|
568
|
+
* @param id - The ID of the record to delete
|
|
569
|
+
* @returns Promise resolving to true if deleted, false if not found
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```typescript
|
|
573
|
+
* const success = await collection.delete('some-uuid');
|
|
574
|
+
* if (success) {
|
|
575
|
+
* console.log('Record deleted');
|
|
576
|
+
* }
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
delete(id: string): Promise<boolean>;
|
|
580
|
+
/**
|
|
581
|
+
* Returns the number of records matching the given filter conditions.
|
|
582
|
+
*
|
|
583
|
+
* Executes a `SELECT COUNT(*)` query with the same WHERE conversion as
|
|
584
|
+
* `list()` (camelCase field names, operator suffixes, STI auto-filtering).
|
|
585
|
+
* `limit`, `offset`, and `orderBy` are not applicable and are ignored.
|
|
586
|
+
*
|
|
587
|
+
* Note: `count()` is never served from the read cache (issue #1498) — only
|
|
588
|
+
* `list()`/`get()` are. On a page that caches `list()`, a `count()` issued
|
|
589
|
+
* in the same request reflects the live database and may briefly diverge
|
|
590
|
+
* from the cached rows within the TTL window.
|
|
591
|
+
*
|
|
592
|
+
* @param options.where - Filter conditions (same syntax as `list()`)
|
|
593
|
+
* @returns Total count of matching records as an integer
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```typescript
|
|
597
|
+
* const total = await products.count();
|
|
598
|
+
* const activeCount = await products.count({ where: { status: 'active' } });
|
|
599
|
+
* const expensiveCount = await products.count({ where: { 'price >': 100 } });
|
|
600
|
+
* ```
|
|
601
|
+
*
|
|
602
|
+
* @see {@link list} for retrieving the actual records
|
|
603
|
+
*/
|
|
604
|
+
count(options?: {
|
|
605
|
+
where?: Record<string, any>;
|
|
606
|
+
}): Promise<number>;
|
|
607
|
+
/**
|
|
608
|
+
* Execute a raw SQL query and hydrate results as collection item instances
|
|
609
|
+
*
|
|
610
|
+
* Provides full SQL power for complex queries (JOINs, CTEs, NOT EXISTS, etc.)
|
|
611
|
+
* while still returning properly hydrated SMRT objects.
|
|
612
|
+
*
|
|
613
|
+
* @param sql - Raw SQL query string (should select from this.tableName)
|
|
614
|
+
* @param params - Query parameters for prepared statement
|
|
615
|
+
* @returns Promise resolving to array of hydrated model instances
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```typescript
|
|
619
|
+
* // Find meetings without corresponding recaps (NOT EXISTS pattern)
|
|
620
|
+
* const meetings = await meetingCollection.query(`
|
|
621
|
+
* SELECT m.* FROM meetings m
|
|
622
|
+
* WHERE m.start_date < datetime('now')
|
|
623
|
+
* AND NOT EXISTS (
|
|
624
|
+
* SELECT 1 FROM contents c
|
|
625
|
+
* WHERE c.meeting_id = m.id
|
|
626
|
+
* AND c._meta_type = 'MeetingRecap'
|
|
627
|
+
* )
|
|
628
|
+
* ORDER BY m.start_date DESC
|
|
629
|
+
* LIMIT ?
|
|
630
|
+
* `, [10]);
|
|
631
|
+
*
|
|
632
|
+
* // Complex JOIN query
|
|
633
|
+
* const products = await productCollection.query(`
|
|
634
|
+
* SELECT p.* FROM products p
|
|
635
|
+
* INNER JOIN categories c ON p.category_id = c.id
|
|
636
|
+
* WHERE c.name = ? AND p.price > ?
|
|
637
|
+
* ORDER BY p.price ASC
|
|
638
|
+
* `, ['Electronics', 100]);
|
|
639
|
+
* ```
|
|
640
|
+
*/
|
|
641
|
+
query(sql: string, params?: any[], options?: {
|
|
642
|
+
allowRawOnTenantScoped?: boolean;
|
|
643
|
+
}): Promise<ModelType[]>;
|
|
644
|
+
private hydrateResultRow;
|
|
645
|
+
/**
|
|
646
|
+
* Remember collection-level context
|
|
647
|
+
*
|
|
648
|
+
* Stores context applicable to all instances of this collection type.
|
|
649
|
+
* Use for patterns that apply to the entire collection (e.g., default parsing strategies).
|
|
650
|
+
*
|
|
651
|
+
* @param options - Context options
|
|
652
|
+
* @returns Promise that resolves when context is stored
|
|
653
|
+
* @example
|
|
654
|
+
* ```typescript
|
|
655
|
+
* // Remember a default parsing strategy for all documents
|
|
656
|
+
* await documentCollection.remember({
|
|
657
|
+
* scope: 'parser/default',
|
|
658
|
+
* key: 'selector',
|
|
659
|
+
* value: { pattern: '.content article' },
|
|
660
|
+
* confidence: 0.8
|
|
661
|
+
* });
|
|
662
|
+
*
|
|
663
|
+
* // Update an existing context entry by specifying id
|
|
664
|
+
* await documentCollection.remember({
|
|
665
|
+
* id: 'existing-context-id',
|
|
666
|
+
* scope: 'parser/default',
|
|
667
|
+
* key: 'selector',
|
|
668
|
+
* value: { pattern: '.content main article' },
|
|
669
|
+
* confidence: 0.85
|
|
670
|
+
* });
|
|
671
|
+
* ```
|
|
672
|
+
*/
|
|
673
|
+
remember(options: {
|
|
674
|
+
id?: string;
|
|
675
|
+
scope: string;
|
|
676
|
+
key: string;
|
|
677
|
+
value: any;
|
|
678
|
+
metadata?: any;
|
|
679
|
+
confidence?: number;
|
|
680
|
+
version?: number;
|
|
681
|
+
expiresAt?: Date;
|
|
682
|
+
}): Promise<void>;
|
|
683
|
+
/**
|
|
684
|
+
* Recall collection-level context
|
|
685
|
+
*
|
|
686
|
+
* Retrieves context that applies to all instances of this collection.
|
|
687
|
+
*
|
|
688
|
+
* @param options - Recall options
|
|
689
|
+
* @returns Promise resolving to the context value or null if not found
|
|
690
|
+
* @example
|
|
691
|
+
* ```typescript
|
|
692
|
+
* // Recall default parsing strategy
|
|
693
|
+
* const strategy = await documentCollection.recall({
|
|
694
|
+
* scope: 'parser/default',
|
|
695
|
+
* key: 'selector',
|
|
696
|
+
* minConfidence: 0.5
|
|
697
|
+
* });
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
|
+
recall(options: {
|
|
701
|
+
scope: string;
|
|
702
|
+
key: string;
|
|
703
|
+
includeAncestors?: boolean;
|
|
704
|
+
minConfidence?: number;
|
|
705
|
+
}): Promise<any | null>;
|
|
706
|
+
/**
|
|
707
|
+
* Recall all collection-level context in a scope
|
|
708
|
+
*
|
|
709
|
+
* Returns a Map of key -> value for all collection contexts matching the criteria.
|
|
710
|
+
*
|
|
711
|
+
* @param options - Recall options
|
|
712
|
+
* @returns Promise resolving to Map of key -> value pairs
|
|
713
|
+
* @example
|
|
714
|
+
* ```typescript
|
|
715
|
+
* // Get all default strategies
|
|
716
|
+
* const strategies = await documentCollection.recallAll({
|
|
717
|
+
* scope: 'parser/default',
|
|
718
|
+
* minConfidence: 0.5
|
|
719
|
+
* });
|
|
720
|
+
* ```
|
|
721
|
+
*/
|
|
722
|
+
recallAll(options?: {
|
|
723
|
+
scope?: string;
|
|
724
|
+
includeDescendants?: boolean;
|
|
725
|
+
minConfidence?: number;
|
|
726
|
+
}): Promise<Map<string, any>>;
|
|
727
|
+
/**
|
|
728
|
+
* Forget collection-level context
|
|
729
|
+
*
|
|
730
|
+
* Deletes collection context by scope and key.
|
|
731
|
+
*
|
|
732
|
+
* @param options - Context identification
|
|
733
|
+
* @returns Promise that resolves when context is deleted
|
|
734
|
+
* @example
|
|
735
|
+
* ```typescript
|
|
736
|
+
* // Remove a default strategy
|
|
737
|
+
* await documentCollection.forget({
|
|
738
|
+
* scope: 'parser/default',
|
|
739
|
+
* key: 'selector'
|
|
740
|
+
* });
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
forget(options: {
|
|
744
|
+
scope: string;
|
|
745
|
+
key: string;
|
|
746
|
+
}): Promise<void>;
|
|
747
|
+
/**
|
|
748
|
+
* Forget all collection-level context in a scope
|
|
749
|
+
*
|
|
750
|
+
* Deletes all collection contexts matching the scope pattern.
|
|
751
|
+
*
|
|
752
|
+
* @param options - Scope options
|
|
753
|
+
* @returns Promise resolving to number of contexts deleted
|
|
754
|
+
* @example
|
|
755
|
+
* ```typescript
|
|
756
|
+
* // Clear all default strategies
|
|
757
|
+
* const count = await documentCollection.forgetScope({
|
|
758
|
+
* scope: 'parser/default',
|
|
759
|
+
* includeDescendants: true
|
|
760
|
+
* });
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
763
|
+
forgetScope(options: {
|
|
764
|
+
scope: string;
|
|
765
|
+
includeDescendants?: boolean;
|
|
766
|
+
}): Promise<number>;
|
|
767
|
+
/**
|
|
768
|
+
* Semantic search by text query
|
|
769
|
+
*
|
|
770
|
+
* Generates an embedding for the query text and finds similar objects
|
|
771
|
+
* based on cosine similarity of stored embeddings.
|
|
772
|
+
*
|
|
773
|
+
* @param query - Text to search for
|
|
774
|
+
* @param options - Search options
|
|
775
|
+
* @param options.field - Specific field to search (defaults to first embedding field)
|
|
776
|
+
* @param options.limit - Maximum results to return (default: 10)
|
|
777
|
+
* @param options.minSimilarity - Minimum similarity threshold 0-1 (default: 0)
|
|
778
|
+
* @param options.where - Additional WHERE filters to apply
|
|
779
|
+
* @returns Promise resolving to array of objects with _similarity score
|
|
780
|
+
*
|
|
781
|
+
* @example
|
|
782
|
+
* ```typescript
|
|
783
|
+
* const results = await articles.semanticSearch('machine learning trends', {
|
|
784
|
+
* limit: 10,
|
|
785
|
+
* minSimilarity: 0.7
|
|
786
|
+
* });
|
|
787
|
+
*
|
|
788
|
+
* for (const article of results) {
|
|
789
|
+
* console.log(`${article.title} (similarity: ${article._similarity})`);
|
|
790
|
+
* }
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
793
|
+
semanticSearch(query: string, options?: {
|
|
794
|
+
field?: string;
|
|
795
|
+
limit?: number;
|
|
796
|
+
minSimilarity?: number;
|
|
797
|
+
where?: Record<string, any>;
|
|
798
|
+
}): Promise<Array<ModelType & {
|
|
799
|
+
_similarity: number;
|
|
800
|
+
}>>;
|
|
801
|
+
/**
|
|
802
|
+
* Find objects similar to a given object
|
|
803
|
+
*
|
|
804
|
+
* Uses stored embeddings to find objects most similar to the provided object.
|
|
805
|
+
*
|
|
806
|
+
* @param object - Object to find similar items for (or object ID)
|
|
807
|
+
* @param options - Search options
|
|
808
|
+
* @param options.field - Specific field to compare (defaults to first embedding field)
|
|
809
|
+
* @param options.limit - Maximum results to return (default: 5)
|
|
810
|
+
* @param options.excludeSelf - Whether to exclude the source object (default: true)
|
|
811
|
+
* @returns Promise resolving to array of similar objects with _similarity score
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
* ```typescript
|
|
815
|
+
* const article = await articles.get('some-article-id');
|
|
816
|
+
* const similar = await articles.findSimilar(article, {
|
|
817
|
+
* limit: 5,
|
|
818
|
+
* excludeSelf: true
|
|
819
|
+
* });
|
|
820
|
+
* ```
|
|
821
|
+
*/
|
|
822
|
+
findSimilar(object: ModelType | string, options?: {
|
|
823
|
+
field?: string;
|
|
824
|
+
limit?: number;
|
|
825
|
+
excludeSelf?: boolean;
|
|
826
|
+
}): Promise<Array<ModelType & {
|
|
827
|
+
_similarity: number;
|
|
828
|
+
}>>;
|
|
829
|
+
/**
|
|
830
|
+
* Find objects similar to a raw embedding vector
|
|
831
|
+
*
|
|
832
|
+
* Low-level method for finding objects by embedding similarity.
|
|
833
|
+
*
|
|
834
|
+
* @param embedding - Embedding vector to compare against
|
|
835
|
+
* @param options - Search options
|
|
836
|
+
* @param options.field - Field name to search (defaults to first embedding field)
|
|
837
|
+
* @param options.limit - Maximum results to return (default: 10)
|
|
838
|
+
* @param options.minSimilarity - Minimum similarity threshold 0-1 (default: 0)
|
|
839
|
+
* @param options.where - Additional WHERE filters to apply
|
|
840
|
+
* @returns Promise resolving to array of objects with _similarity score
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* ```typescript
|
|
844
|
+
* // Using a pre-computed embedding
|
|
845
|
+
* const results = await articles.findSimilarToEmbedding(myEmbedding, {
|
|
846
|
+
* limit: 10,
|
|
847
|
+
* minSimilarity: 0.5
|
|
848
|
+
* });
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
findSimilarToEmbedding(embedding: number[], options?: {
|
|
852
|
+
field?: string;
|
|
853
|
+
limit?: number;
|
|
854
|
+
minSimilarity?: number;
|
|
855
|
+
where?: Record<string, any>;
|
|
856
|
+
}): Promise<Array<ModelType & {
|
|
857
|
+
_similarity: number;
|
|
858
|
+
}>>;
|
|
859
|
+
/**
|
|
860
|
+
* Generate missing embeddings for all objects in the collection
|
|
861
|
+
*
|
|
862
|
+
* Batch generates embeddings for objects that don't have them yet
|
|
863
|
+
* or have stale embeddings.
|
|
864
|
+
*
|
|
865
|
+
* @param options - Generation options
|
|
866
|
+
* @param options.batchSize - Number of objects to process at once (default: 50)
|
|
867
|
+
* @param options.onProgress - Progress callback
|
|
868
|
+
* @returns Promise resolving to generation statistics
|
|
869
|
+
*
|
|
870
|
+
* @example
|
|
871
|
+
* ```typescript
|
|
872
|
+
* const stats = await articles.generateMissingEmbeddings({
|
|
873
|
+
* batchSize: 100,
|
|
874
|
+
* onProgress: ({ completed, total }) => {
|
|
875
|
+
* console.log(`Progress: ${completed}/${total}`);
|
|
876
|
+
* }
|
|
877
|
+
* });
|
|
878
|
+
*
|
|
879
|
+
* console.log(`Generated: ${stats.generated}, Skipped: ${stats.skipped}`);
|
|
880
|
+
* ```
|
|
881
|
+
*/
|
|
882
|
+
generateMissingEmbeddings(options?: {
|
|
883
|
+
batchSize?: number;
|
|
884
|
+
onProgress?: (progress: {
|
|
885
|
+
completed: number;
|
|
886
|
+
total: number;
|
|
887
|
+
}) => void;
|
|
888
|
+
}): Promise<{
|
|
889
|
+
generated: number;
|
|
890
|
+
skipped: number;
|
|
891
|
+
}>;
|
|
892
|
+
}
|
|
893
|
+
export {};
|
|
894
|
+
//# sourceMappingURL=collection.d.ts.map
|