@happyvertical/smrt-core 0.40.63 → 0.40.65
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 +13 -0
- package/README.md +38 -0
- package/dist/__typechecks__/collection-read-plan.d.ts +50 -0
- package/dist/__typechecks__/collection-read-plan.d.ts.map +1 -0
- package/dist/collection-read-plan.d.ts +77 -0
- package/dist/collection-read-plan.d.ts.map +1 -0
- package/dist/collection-read-plan.js +55 -0
- package/dist/collection-read-plan.js.map +1 -0
- package/dist/consumer-plugin/index.d.ts.map +1 -1
- package/dist/consumer-plugin/index.js +44 -5
- package/dist/consumer-plugin/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/manifest/static-manifest.js +1 -1
- package/dist/manifest/static-manifest.js.map +1 -1
- package/dist/manifest/store.js +1 -1
- package/dist/manifest.json +1 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +1 -1
- package/dist/object.js.map +1 -1
- package/dist/registry/class-registration.d.ts.map +1 -1
- package/dist/registry/class-registration.js +53 -3
- package/dist/registry/class-registration.js.map +1 -1
- package/dist/registry/types.d.ts +7 -0
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +5 -4
- package/dist/registry.js.map +1 -1
- package/dist/smrt-knowledge.json +8 -5
- package/dist/vite-plugin/index.d.ts.map +1 -1
- package/dist/vite-plugin/index.js +31 -13
- package/dist/vite-plugin/index.js.map +1 -1
- package/dist/vite-plugin/sveltekit-generator.d.ts.map +1 -1
- package/dist/vite-plugin/sveltekit-generator.js +92 -26
- package/dist/vite-plugin/sveltekit-generator.js.map +1 -1
- package/package.json +8 -5
|
@@ -749,14 +749,18 @@ async function generateRegistrationFile(projectRoot, manifest, options) {
|
|
|
749
749
|
const registrationFilePath = join(configDir, "smrt-register.ts");
|
|
750
750
|
const localObjects = [];
|
|
751
751
|
const packageObjects = /* @__PURE__ */ new Map();
|
|
752
|
+
const registrationBindings = buildRegistrationBindings(manifest);
|
|
752
753
|
for (const [className, objectDef] of Object.entries(manifest.objects)) if (isLocalObject(projectRoot, objectDef)) localObjects.push([className, objectDef]);
|
|
753
754
|
else if (objectDef.packageName) {
|
|
754
755
|
const packageEntry = packageObjects.get(objectDef.packageName) || {
|
|
755
|
-
|
|
756
|
+
objects: [],
|
|
756
757
|
hasCollectionImport: false
|
|
757
758
|
};
|
|
758
759
|
if (isCollectionManifestClass(manifest, objectDef)) packageEntry.hasCollectionImport = true;
|
|
759
|
-
else packageEntry.
|
|
760
|
+
else packageEntry.objects.push({
|
|
761
|
+
simpleName: extractSimpleClassName(className),
|
|
762
|
+
bindingName: registrationBindings.get(className) || extractSimpleClassName(className)
|
|
763
|
+
});
|
|
760
764
|
packageObjects.set(objectDef.packageName, packageEntry);
|
|
761
765
|
} else localObjects.push([className, objectDef]);
|
|
762
766
|
const localNamedImports = /* @__PURE__ */ new Map();
|
|
@@ -773,54 +777,116 @@ async function generateRegistrationFile(projectRoot, manifest, options) {
|
|
|
773
777
|
continue;
|
|
774
778
|
}
|
|
775
779
|
const existing = localNamedImports.get(importPath) ?? [];
|
|
776
|
-
existing.push(
|
|
780
|
+
existing.push({
|
|
781
|
+
simpleName: simpleClassName,
|
|
782
|
+
bindingName: registrationBindings.get(className) || simpleClassName
|
|
783
|
+
});
|
|
777
784
|
localNamedImports.set(importPath, existing);
|
|
778
785
|
}
|
|
779
|
-
const localImports = [...Array.from(localNamedImports.entries()).sort(([left], [right]) => left.localeCompare(right)).map(([importPath,
|
|
780
|
-
return `import { ${
|
|
786
|
+
const localImports = [...Array.from(localNamedImports.entries()).sort(([left], [right]) => left.localeCompare(right)).map(([importPath, importedObjects]) => {
|
|
787
|
+
return `import { ${importedObjects.sort((a, b) => a.bindingName.localeCompare(b.bindingName)).map(formatRegistrationImport).join(", ")} } from '${importPath}';`;
|
|
781
788
|
}), ...Array.from(localSideEffectImports.values()).sort((a, b) => a.localeCompare(b)).map((importPath) => `import '${importPath}';`)].join("\n");
|
|
782
|
-
const
|
|
783
|
-
* Auto-generated SMRT object registration
|
|
784
|
-
* DO NOT EDIT - changes will be overwritten
|
|
785
|
-
*
|
|
786
|
-
* Importing these modules triggers their @smrt() decorators, which perform
|
|
787
|
-
* the initial registration. The explicit re-registration below is intentional:
|
|
788
|
-
* it upgrades bundled runtimes to deterministic qualified registrations.
|
|
789
|
-
*/
|
|
790
|
-
|
|
791
|
-
import { ObjectRegistry } from '@happyvertical/smrt-core';
|
|
792
|
-
|
|
793
|
-
${[Array.from(packageObjects.entries()).sort(([left], [right]) => left.localeCompare(right)).flatMap(([packageName, packageEntry]) => {
|
|
789
|
+
const imports = [Array.from(packageObjects.entries()).sort(([left], [right]) => left.localeCompare(right)).flatMap(([packageName, packageEntry]) => {
|
|
794
790
|
const imports = [];
|
|
795
791
|
if (packageEntry.hasCollectionImport) imports.push(`import '${packageName}';`);
|
|
796
|
-
if (packageEntry.
|
|
797
|
-
const simpleNames = packageEntry.
|
|
792
|
+
if (packageEntry.objects.length > 0) {
|
|
793
|
+
const simpleNames = packageEntry.objects.sort((a, b) => a.bindingName.localeCompare(b.bindingName)).map(formatRegistrationImport);
|
|
798
794
|
imports.push(`import { ${simpleNames.join(", ")} } from '${packageName}';`);
|
|
799
795
|
}
|
|
800
796
|
return imports;
|
|
801
|
-
}).join("\n"), localImports].filter(Boolean).join("\n")
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
797
|
+
}).join("\n"), localImports].filter(Boolean).join("\n");
|
|
798
|
+
const externalRuntimeDependencies = (manifest.smrtDependencies || []).filter((dependency) => dependency !== "@happyvertical/smrt-core");
|
|
799
|
+
let consumerRegistrationImport = "";
|
|
800
|
+
if (externalRuntimeDependencies.length > 0) {
|
|
801
|
+
const consumerRegistrationPath = relative(configDir, join(projectRoot, ".smrt", "register.js")).replace(/\\/g, "/");
|
|
802
|
+
consumerRegistrationImport = `import '${consumerRegistrationPath.startsWith(".") ? consumerRegistrationPath : `./${consumerRegistrationPath}`}';`;
|
|
803
|
+
}
|
|
804
|
+
const registrationManifests = Object.fromEntries(Object.entries(manifest.objects).flatMap(([className, objectDef]) => {
|
|
805
|
+
if (isCollectionManifestClass(manifest, objectDef)) return [];
|
|
806
|
+
const packageName = getRegistrationPackageName(manifest, objectDef, isLocalObject(projectRoot, objectDef));
|
|
807
|
+
if (!packageName) return [];
|
|
808
|
+
return [[className, {
|
|
809
|
+
...manifest,
|
|
810
|
+
packageName,
|
|
811
|
+
objects: { [className]: objectDef }
|
|
812
|
+
}]];
|
|
813
|
+
}));
|
|
814
|
+
const registrationManifestLiteral = JSON.stringify(JSON.stringify(registrationManifests));
|
|
815
|
+
const registrations = Object.entries(manifest.objects).map(([className, objectDef]) => {
|
|
805
816
|
if (isCollectionManifestClass(manifest, objectDef)) return null;
|
|
806
817
|
const simpleClassName = extractSimpleClassName(className);
|
|
818
|
+
const bindingName = registrationBindings.get(className) || simpleClassName;
|
|
807
819
|
const packageName = getRegistrationPackageName(manifest, objectDef, isLocalObject(projectRoot, objectDef));
|
|
808
820
|
if (!packageName) return null;
|
|
809
821
|
const packageNameLiteral = toSingleQuotedStringLiteral(packageName);
|
|
810
|
-
const
|
|
822
|
+
const manifestKeyLiteral = toSingleQuotedStringLiteral(className);
|
|
823
|
+
const singleLineRegistration = `ObjectRegistry.register(${bindingName}, { name: '${simpleClassName}', packageName: ${packageNameLiteral}, _manifest: smrtRegistrationManifests[${manifestKeyLiteral}], _manifestKey: ${manifestKeyLiteral} });`;
|
|
811
824
|
if (singleLineRegistration.length <= BIOME_LINE_WIDTH) return singleLineRegistration;
|
|
812
825
|
return [
|
|
813
|
-
`ObjectRegistry.register(${
|
|
826
|
+
`ObjectRegistry.register(${bindingName}, {`,
|
|
814
827
|
` name: '${simpleClassName}',`,
|
|
815
828
|
` packageName: ${packageNameLiteral},`,
|
|
829
|
+
` _manifest: smrtRegistrationManifests[${manifestKeyLiteral}],`,
|
|
830
|
+
` _manifestKey: ${manifestKeyLiteral},`,
|
|
816
831
|
`});`
|
|
817
832
|
].join("\n");
|
|
818
|
-
}).filter((registration) => registration !== null).join("\n")
|
|
833
|
+
}).filter((registration) => registration !== null).join("\n");
|
|
834
|
+
const registrationContent = `/**
|
|
835
|
+
* Auto-generated SMRT object registration
|
|
836
|
+
* DO NOT EDIT - changes will be overwritten
|
|
837
|
+
*
|
|
838
|
+
* Importing these modules triggers their @smrt() decorators, which perform
|
|
839
|
+
* the initial registration. The explicit re-registration below is intentional:
|
|
840
|
+
* it upgrades bundled runtimes to deterministic qualified registrations.
|
|
841
|
+
*/
|
|
842
|
+
|
|
843
|
+
import { ObjectRegistry } from '@happyvertical/smrt-core';
|
|
844
|
+
|
|
845
|
+
${consumerRegistrationImport}
|
|
846
|
+
${imports}
|
|
847
|
+
|
|
848
|
+
const smrtRegistrationManifests = JSON.parse(${registrationManifestLiteral});
|
|
849
|
+
|
|
850
|
+
// Re-register imported objects with explicit package names for bundled runtimes
|
|
851
|
+
${registrations}
|
|
819
852
|
`;
|
|
820
853
|
if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
|
|
821
854
|
writeFileSync(registrationFilePath, registrationContent, "utf-8");
|
|
822
855
|
console.log(`[smrt] Generated registration file: ${registrationFilePath}`);
|
|
823
856
|
}
|
|
857
|
+
function buildRegistrationBindings(manifest) {
|
|
858
|
+
const keysBySimpleName = /* @__PURE__ */ new Map();
|
|
859
|
+
const reservedBindings = /* @__PURE__ */ new Set();
|
|
860
|
+
for (const [manifestKey, objectDef] of Object.entries(manifest.objects)) {
|
|
861
|
+
if (isCollectionManifestClass(manifest, objectDef)) continue;
|
|
862
|
+
const simpleName = extractSimpleClassName(manifestKey);
|
|
863
|
+
reservedBindings.add(simpleName);
|
|
864
|
+
const keys = keysBySimpleName.get(simpleName) ?? [];
|
|
865
|
+
keys.push(manifestKey);
|
|
866
|
+
keysBySimpleName.set(simpleName, keys);
|
|
867
|
+
}
|
|
868
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
869
|
+
const generatedBindings = /* @__PURE__ */ new Set();
|
|
870
|
+
for (const [simpleName, keys] of keysBySimpleName) {
|
|
871
|
+
const sortedKeys = keys.sort((a, b) => a.localeCompare(b));
|
|
872
|
+
for (const [index, manifestKey] of sortedKeys.entries()) {
|
|
873
|
+
let bindingName = simpleName;
|
|
874
|
+
if (sortedKeys.length > 1) {
|
|
875
|
+
let suffix = index + 1;
|
|
876
|
+
do {
|
|
877
|
+
bindingName = `__smrt_${simpleName}_${suffix}`;
|
|
878
|
+
suffix += 1;
|
|
879
|
+
} while (reservedBindings.has(bindingName) || generatedBindings.has(bindingName));
|
|
880
|
+
generatedBindings.add(bindingName);
|
|
881
|
+
}
|
|
882
|
+
bindings.set(manifestKey, bindingName);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
return bindings;
|
|
886
|
+
}
|
|
887
|
+
function formatRegistrationImport(importedObject) {
|
|
888
|
+
return importedObject.simpleName === importedObject.bindingName ? importedObject.simpleName : `${importedObject.simpleName} as ${importedObject.bindingName}`;
|
|
889
|
+
}
|
|
824
890
|
/**
|
|
825
891
|
* Generates centralized SMRT configuration file
|
|
826
892
|
* Only creates if file doesn't exist (preserves user customizations)
|