@happyvertical/smrt-core 0.40.31 → 0.40.32

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.
Files changed (46) hide show
  1. package/dist/browser.js +2 -2
  2. package/dist/consumer-plugin/index.d.ts +5 -0
  3. package/dist/consumer-plugin/index.d.ts.map +1 -1
  4. package/dist/consumer-plugin/index.js +6 -38
  5. package/dist/consumer-plugin/index.js.map +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/manifest/static-manifest.js +2 -2
  8. package/dist/manifest/static-manifest.js.map +1 -1
  9. package/dist/manifest/store.js +1 -1
  10. package/dist/manifest/test-manifest-stub.js +2 -2
  11. package/dist/manifest/test-manifest-stub.js.map +1 -1
  12. package/dist/manifest.json +2 -2
  13. package/dist/prebuild/index.d.ts.map +1 -1
  14. package/dist/prebuild/index.js +10 -4
  15. package/dist/prebuild/index.js.map +1 -1
  16. package/dist/smrt-knowledge.json +4 -4
  17. package/dist/system/compatibility.d.ts +12 -0
  18. package/dist/system/compatibility.d.ts.map +1 -1
  19. package/dist/system/compatibility.js +51 -2
  20. package/dist/system/compatibility.js.map +1 -1
  21. package/dist/system/index.js +2 -2
  22. package/dist/vite-plugin/api-client-entries.d.ts +17 -0
  23. package/dist/vite-plugin/api-client-entries.d.ts.map +1 -1
  24. package/dist/vite-plugin/api-client-entries.js +116 -23
  25. package/dist/vite-plugin/api-client-entries.js.map +1 -1
  26. package/dist/vite-plugin/generated-client.d.ts +7 -0
  27. package/dist/vite-plugin/generated-client.d.ts.map +1 -0
  28. package/dist/vite-plugin/generated-client.js +134 -0
  29. package/dist/vite-plugin/generated-client.js.map +1 -0
  30. package/dist/vite-plugin/index.d.ts +5 -0
  31. package/dist/vite-plugin/index.d.ts.map +1 -1
  32. package/dist/vite-plugin/index.js +19 -151
  33. package/dist/vite-plugin/index.js.map +1 -1
  34. package/dist/vite-plugin/sveltekit-generator.d.ts +1 -1
  35. package/dist/vite-plugin/sveltekit-generator.d.ts.map +1 -1
  36. package/dist/vite-plugin/sveltekit-generator.js +12 -12
  37. package/dist/vite-plugin/sveltekit-generator.js.map +1 -1
  38. package/dist/vite-plugin/sync-apply-route.d.ts.map +1 -1
  39. package/dist/vite-plugin/sync-apply-route.js +2 -5
  40. package/dist/vite-plugin/sync-apply-route.js.map +1 -1
  41. package/dist/vite-plugin/web-collections.d.ts +2 -0
  42. package/dist/vite-plugin/web-collections.d.ts.map +1 -1
  43. package/dist/vite-plugin/web-collections.js +62 -3
  44. package/dist/vite-plugin/web-collections.js.map +1 -1
  45. package/dist/vite-plugin.js +2 -2
  46. package/package.json +4 -4
@@ -1,10 +1,10 @@
1
- import { findCliApiCoherenceViolations, generateSvelteKitRoutes, methodNameToKebab, resolveApiActionRouteConfig, resolveApiActionSet, validateCliIncludeAgainstApi } from "./sveltekit-generator.js";
2
- import { buildWebCollectionDefinition, buildWebToolDescriptors, computeWebManifestHash, isCollectionManifestClass, selectWebCollectionEntries } from "./web-collections.js";
1
+ import { findCliApiCoherenceViolations, generateSvelteKitRoutes, methodNameToKebab, resolveApiActionSet, validateCliIncludeAgainstApi } from "./sveltekit-generator.js";
2
+ import { buildWebCollectionDefinition, buildWebToolDescriptors, computeWebManifestHash, selectWebCollectionEntries } from "./web-collections.js";
3
3
  import { buildDomainKnowledgeManifest } from "../knowledge.js";
4
4
  import { importWorkspaceModule } from "../utils/import-workspace-module.js";
5
5
  import { discoverSmrtPackages } from "../manifest/discover-smrt-packages.js";
6
- import { CLIENT_FETCH_RUNTIME } from "../generated-client-runtime.js";
7
- import { selectApiClientEntries } from "./api-client-entries.js";
6
+ import { renderApiClientCrudType, renderApiClientCustomMethodParameters, selectApiClientEntries } from "./api-client-entries.js";
7
+ import { GENERATED_CLIENT_BASE_METHODS, GENERATED_CLIENT_CRUD_METHODS, generateClientModule } from "./generated-client.js";
8
8
  import { importBuildAwareModule } from "./import-build-aware.js";
9
9
  import { existsSync, readFileSync } from "node:fs";
10
10
  import { dirname, join } from "node:path";
@@ -592,125 +592,6 @@ export { setupRoutes as default };
592
592
  return "export function setupRoutes(app, options = {}) { console.warn(\"Routes generation failed\"); }";
593
593
  }
594
594
  }
595
- var GENERATED_CLIENT_CRUD_METHODS = /* @__PURE__ */ new Set([
596
- "list",
597
- "get",
598
- "create",
599
- "update",
600
- "delete"
601
- ]);
602
- var GENERATED_CLIENT_BASE_METHODS = /* @__PURE__ */ new Set([...GENERATED_CLIENT_CRUD_METHODS, "search"]);
603
- function generateClientModule(manifest, options = {}) {
604
- return `
605
- // Auto-generated API client from SMRT objects
606
- // This file is generated automatically - do not edit
607
-
608
- ${CLIENT_FETCH_RUNTIME}
609
-
610
- async function __smrtFetchActionResult(url, init) {
611
- const body = await __smrtFetchJson(url, init);
612
- return body &&
613
- typeof body === 'object' &&
614
- Object.prototype.hasOwnProperty.call(body, 'result')
615
- ? body.result
616
- : body;
617
- }
618
-
619
- function __smrtActionUrl(url, options, pathParamNames, includeQuery) {
620
- const values = options && typeof options === 'object' ? options : {};
621
- const pathParams = new Set(pathParamNames);
622
- let resolvedUrl = url;
623
- for (const name of pathParamNames) {
624
- const value = values[name];
625
- if (value === undefined || value === null) {
626
- throw new Error('Missing generated client route parameter: ' + name);
627
- }
628
- resolvedUrl = resolvedUrl.replace(
629
- '[' + name + ']',
630
- encodeURIComponent(String(value)),
631
- );
632
- }
633
-
634
- if (!includeQuery) return resolvedUrl;
635
-
636
- const searchParams = new URLSearchParams();
637
- for (const [name, value] of Object.entries(values)) {
638
- if (pathParams.has(name) || value === undefined) continue;
639
- if (Array.isArray(value)) {
640
- for (const item of value) searchParams.append(name, String(item));
641
- continue;
642
- }
643
- searchParams.append(
644
- name,
645
- value !== null && typeof value === 'object'
646
- ? JSON.stringify(value)
647
- : String(value),
648
- );
649
- }
650
-
651
- const query = searchParams.toString();
652
- return query ? resolvedUrl + '?' + query : resolvedUrl;
653
- }
654
-
655
- export function createClient(basePath = '/api/v1') {
656
- return {${selectApiClientEntries(manifest).map(({ obj, clientKey }) => {
657
- const { collection, methods = {} } = obj;
658
- const exposedActions = resolveApiActionSet(obj);
659
- const apiConfig = obj.decoratorConfig?.api;
660
- const customMethods = Object.entries(methods).filter(([name, method]) => !GENERATED_CLIENT_CRUD_METHODS.has(name) && method.isPublic && exposedActions.has(name));
661
- const customMethodImpls = customMethods.map(([methodName, method]) => {
662
- const routeConfig = resolveApiActionRouteConfig(methodName, method, apiConfig, { kebabRoutes: options.kebabRoutes }, isCollectionManifestClass(manifest, obj) ? "collection" : method.isStatic ? "collection" : "item");
663
- const urlSegment = routeConfig.pathSegments.join("/");
664
- return ` ${methodName}: (${routeConfig.scope === "collection" ? "options" : "id, options"}) => __smrtFetchActionResult(${`__smrtActionUrl(${routeConfig.scope === "collection" ? `basePath + '/${collection}/${urlSegment}'` : `basePath + '/${collection}/' + id + '/${urlSegment}'`}, options, ${JSON.stringify(routeConfig.pathParamNames)}, ${routeConfig.method === "GET"})`}, ${routeConfig.method === "GET" ? `{
665
- method: 'GET',
666
- headers: { 'Accept': 'application/json' }
667
- }` : `{
668
- method: '${routeConfig.method}',
669
- headers: { 'Content-Type': 'application/json' },
670
- body: JSON.stringify(options || {})
671
- }`})`;
672
- }).join(",\n");
673
- return `
674
- ${clientKey}: {
675
- list: (params) => __smrtFetchJson(basePath + '/${collection}', {
676
- method: 'GET',
677
- headers: { 'Content-Type': 'application/json' }
678
- }),
679
-
680
- get: (id) => __smrtFetchJson(basePath + '/${collection}/' + id, {
681
- method: 'GET',
682
- headers: { 'Content-Type': 'application/json' }
683
- }),
684
-
685
- create: (data) => __smrtFetchJson(basePath + '/${collection}', {
686
- method: 'POST',
687
- headers: { 'Content-Type': 'application/json' },
688
- body: JSON.stringify(data)
689
- }),
690
-
691
- update: (id, data) => __smrtFetchJson(basePath + '/${collection}/' + id, {
692
- method: 'PUT',
693
- headers: { 'Content-Type': 'application/json' },
694
- body: JSON.stringify(data)
695
- }),
696
-
697
- delete: (id) => __smrtFetchOk(basePath + '/${collection}/' + id, {
698
- method: 'DELETE',
699
- headers: { 'Content-Type': 'application/json' }
700
- }),
701
-
702
- search: (query) => __smrtFetchJson(basePath + '/${collection}/search?q=' + encodeURIComponent(query), {
703
- method: 'GET',
704
- headers: { 'Content-Type': 'application/json' }
705
- })${customMethods.length > 0 ? `,\n${customMethodImpls}` : ""}
706
- }`;
707
- }).join(",")}
708
- };
709
- }
710
-
711
- export { createClient as default };
712
- `;
713
- }
714
595
  /**
715
596
  * Generate the virtual web-collection definition module
716
597
  * (`@happyvertical/smrt-virt-web`, #1761).
@@ -932,37 +813,24 @@ ${Object.entries(obj.fields).map(([fieldName, field]) => {
932
813
  updated_at?: string;
933
814
  }`;
934
815
  }).join("\n\n");
935
- const apiClientInterface = selectApiClientEntries(manifest).map(({ obj, clientKey, dataInterfaceName }) => {
816
+ const apiClientInterface = selectApiClientEntries(manifest).map(({ obj, clientKey, dataInterfaceName, crudMethods, customMethods: exposedMethods }) => {
936
817
  const { methods = {} } = obj;
937
- const apiConfig = obj.decoratorConfig?.api;
938
818
  const interfaceName = dataInterfaceName;
939
- const exposedActions = resolveApiActionSet(obj);
940
- const customMethods = Object.entries(methods).filter(([name, method]) => !GENERATED_CLIENT_CRUD_METHODS.has(name) && method.isPublic && exposedActions.has(name));
941
- const customMethodSignatures = customMethods.map(([methodName, method]) => {
942
- const routeConfig = resolveApiActionRouteConfig(methodName, method, apiConfig, {}, isCollectionManifestClass(manifest, obj) ? "collection" : method.isStatic ? "collection" : "item");
943
- const params = method.parameters || [];
944
- const pathParamNames = new Set(routeConfig.pathParamNames);
945
- const hasSingleOptionsParameter = params.length === 1 && params[0]?.name === "options";
946
- const requiredPathProperties = routeConfig.pathParamNames.map((name) => `${name}: string`).join("; ");
947
- let optionsType;
948
- if (hasSingleOptionsParameter) {
949
- const directOptionsType = mapTypeScriptType(params[0].type);
950
- optionsType = requiredPathProperties ? `${directOptionsType} & { ${requiredPathProperties} }` : directOptionsType;
951
- } else {
952
- const parameterNames = new Set(params.map((param) => param.name));
953
- const properties = params.map((param) => `${param.name}${pathParamNames.has(param.name) ? "" : "?"}: ${mapTypeScriptType(param.type)}`);
954
- for (const pathParamName of routeConfig.pathParamNames) if (!parameterNames.has(pathParamName)) properties.push(`${pathParamName}: string`);
955
- optionsType = properties.length > 0 ? `{ ${properties.join("; ")} }` : "Record<string, never>";
956
- }
957
- const optionsParameter = `${routeConfig.pathParamNames.length > 0 ? "options" : "options?"}: ${optionsType}`;
958
- return ` ${methodName}(${routeConfig.scope === "collection" ? optionsParameter : `id: string, ${optionsParameter}`}): Promise<any>;`;
819
+ const exposedActionNames = new Set(exposedMethods.map((method) => method.name));
820
+ const customMethods = Object.entries(methods).filter(([name, method]) => !GENERATED_CLIENT_CRUD_METHODS.has(name) && method.isPublic && exposedActionNames.has(name));
821
+ const customMethodSignatures = customMethods.map(([methodName]) => {
822
+ const exposedMethod = exposedMethods.find(({ name }) => name === methodName);
823
+ if (!exposedMethod) return "";
824
+ return ` ${methodName}(${renderApiClientCustomMethodParameters(exposedMethod, mapTypeScriptType)}): Promise<any>;`;
959
825
  }).join("\n");
960
- const overriddenBaseMethods = customMethods.map(([methodName]) => methodName).filter((methodName) => GENERATED_CLIENT_BASE_METHODS.has(methodName));
961
- const crudOperationsType = overriddenBaseMethods.length > 0 ? `Omit<CrudOperations<${interfaceName}>, ${overriddenBaseMethods.map((methodName) => JSON.stringify(methodName)).join(" | ")}>` : `CrudOperations<${interfaceName}>`;
962
- if (customMethods.length > 0) return ` ${clientKey}: ${crudOperationsType} & {\n${customMethodSignatures}\n };`;
963
- else return ` ${clientKey}: ${crudOperationsType};`;
826
+ const crudOperationsType = renderApiClientCrudType(interfaceName, crudMethods, customMethods.map(([methodName]) => methodName).filter((methodName) => GENERATED_CLIENT_BASE_METHODS.has(methodName)));
827
+ if (customMethods.length > 0) {
828
+ const intersection = crudOperationsType ? `${crudOperationsType} & ` : "";
829
+ return ` ${JSON.stringify(clientKey)}: ${intersection}{\n${customMethodSignatures}\n };`;
830
+ }
831
+ return ` ${JSON.stringify(clientKey)}: ${crudOperationsType ?? "Record<string, never>"};`;
964
832
  }).join("\n");
965
- const webCollectionInterface = selectWebCollectionEntries(manifest).map(({ collection, obj }) => ` ${collection}: SmrtWebCollectionDefinition<import('@happyvertical/smrt-virt-types').${obj.className}Data>;`).join("\n");
833
+ const webCollectionInterface = selectWebCollectionEntries(manifest).map(({ collection, obj }) => ` ${JSON.stringify(collection)}: SmrtWebCollectionDefinition<import('@happyvertical/smrt-virt-types').${obj.className}Data>;`).join("\n");
966
834
  Object.entries(manifest.objects).flatMap(([_name, obj]) => Object.entries(obj.methods).map(([methodName, method]) => ({
967
835
  name: `${methodName}_${obj.collection}`,
968
836
  description: `${method.name} operation on ${obj.collection}`,
@@ -1471,6 +1339,6 @@ export default {};`;
1471
1339
  }
1472
1340
  }
1473
1341
  //#endregion
1474
- export { findCliApiCoherenceViolations, generateInlineRegisterModule, generateSvelteKitRoutes, isRegisterShimModuleId, methodNameToKebab, resolveApiActionSet, smrtPlugin, validateCliIncludeAgainstApi };
1342
+ export { findCliApiCoherenceViolations, generateInlineRegisterModule, generateSvelteKitRoutes, generateTypeDeclarationFile, isRegisterShimModuleId, methodNameToKebab, resolveApiActionSet, smrtPlugin, validateCliIncludeAgainstApi };
1475
1343
 
1476
1344
  //# sourceMappingURL=index.js.map