@common-stack/rollup-vite-utils 6.0.6-alpha.5 → 6.0.6-alpha.52

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 (124) hide show
  1. package/lib/config-schema.cjs +111 -0
  2. package/lib/config-schema.cjs.map +1 -0
  3. package/lib/config-schema.js +111 -0
  4. package/lib/config-schema.js.map +1 -0
  5. package/lib/default-config.json.cjs +2 -2
  6. package/lib/default-config.json.js +2 -2
  7. package/lib/index.cjs +1 -1
  8. package/lib/index.js +1 -1
  9. package/lib/interfaces/types.cjs +6 -0
  10. package/lib/interfaces/types.cjs.map +1 -0
  11. package/lib/interfaces/types.d.ts +41 -24
  12. package/lib/interfaces/types.js +6 -0
  13. package/lib/interfaces/types.js.map +1 -0
  14. package/lib/preStartup/configLoader/index.cjs +1 -1
  15. package/lib/preStartup/configLoader/index.cjs.map +1 -1
  16. package/lib/preStartup/configLoader/index.js +1 -1
  17. package/lib/preStartup/configLoader/index.js.map +1 -1
  18. package/lib/preStartup/copyIfVersionChanged.cjs +1 -1
  19. package/lib/preStartup/copyIfVersionChanged.cjs.map +1 -1
  20. package/lib/preStartup/copyIfVersionChanged.js +1 -1
  21. package/lib/preStartup/copyIfVersionChanged.js.map +1 -1
  22. package/lib/rollup/index.d.ts +1 -0
  23. package/lib/rollup/modifyLibFiles/extractGraphQLQueries.cjs +1 -1
  24. package/lib/rollup/modifyLibFiles/extractGraphQLQueries.cjs.map +1 -1
  25. package/lib/rollup/modifyLibFiles/extractGraphQLQueries.js +1 -1
  26. package/lib/rollup/modifyLibFiles/extractGraphQLQueries.js.map +1 -1
  27. package/lib/rollup/modifyLibFiles/handleComponentOrDialog.cjs +212 -110
  28. package/lib/rollup/modifyLibFiles/handleComponentOrDialog.cjs.map +1 -1
  29. package/lib/rollup/modifyLibFiles/handleComponentOrDialog.d.ts +41 -0
  30. package/lib/rollup/modifyLibFiles/handleComponentOrDialog.js +212 -110
  31. package/lib/rollup/modifyLibFiles/handleComponentOrDialog.js.map +1 -1
  32. package/lib/rollup/modifyLibFiles/handleImportPaths.cjs +4 -3
  33. package/lib/rollup/modifyLibFiles/handleImportPaths.cjs.map +1 -1
  34. package/lib/rollup/modifyLibFiles/handleImportPaths.js +4 -3
  35. package/lib/rollup/modifyLibFiles/handleImportPaths.js.map +1 -1
  36. package/lib/rollup/modifyLibFiles/utils.cjs +7 -7
  37. package/lib/rollup/modifyLibFiles/utils.cjs.map +1 -1
  38. package/lib/rollup/modifyLibFiles/utils.d.ts +1 -1
  39. package/lib/rollup/modifyLibFiles/utils.js +7 -7
  40. package/lib/rollup/modifyLibFiles/utils.js.map +1 -1
  41. package/lib/rollup/rollupPluginGenerateJson.cjs +2 -3
  42. package/lib/rollup/rollupPluginGenerateJson.cjs.map +1 -1
  43. package/lib/rollup/rollupPluginGenerateJson.js +2 -3
  44. package/lib/rollup/rollupPluginGenerateJson.js.map +1 -1
  45. package/lib/rollup/rollupPluginModifyLibFiles.cjs +25 -14
  46. package/lib/rollup/rollupPluginModifyLibFiles.cjs.map +1 -1
  47. package/lib/rollup/rollupPluginModifyLibFiles.js +25 -14
  48. package/lib/rollup/rollupPluginModifyLibFiles.js.map +1 -1
  49. package/lib/rollup/rollupPluginUpdateFromConfig.cjs +122 -0
  50. package/lib/rollup/rollupPluginUpdateFromConfig.cjs.map +1 -0
  51. package/lib/rollup/rollupPluginUpdateFromConfig.d.ts +1 -0
  52. package/lib/rollup/rollupPluginUpdateFromConfig.js +122 -0
  53. package/lib/rollup/rollupPluginUpdateFromConfig.js.map +1 -0
  54. package/lib/utils/index.d.ts +1 -0
  55. package/lib/utils/parseUtility.d.ts +3 -0
  56. package/lib/utils/verifyConfig.cjs +13 -0
  57. package/lib/utils/verifyConfig.cjs.map +1 -0
  58. package/lib/utils/verifyConfig.d.ts +2 -0
  59. package/lib/utils/verifyConfig.js +13 -0
  60. package/lib/utils/verifyConfig.js.map +1 -0
  61. package/lib/utils/withErrorHandleUtil.cjs +3 -7
  62. package/lib/utils/withErrorHandleUtil.cjs.map +1 -1
  63. package/lib/utils/withErrorHandleUtil.js +3 -7
  64. package/lib/utils/withErrorHandleUtil.js.map +1 -1
  65. package/lib/vite-wrappers/custom-routes.cjs +43 -0
  66. package/lib/vite-wrappers/custom-routes.cjs.map +1 -0
  67. package/lib/vite-wrappers/custom-routes.d.ts +2 -0
  68. package/lib/vite-wrappers/custom-routes.js +43 -0
  69. package/lib/vite-wrappers/custom-routes.js.map +1 -0
  70. package/lib/vite-wrappers/generators/clientLoaderGenerator.cjs +149 -0
  71. package/lib/vite-wrappers/generators/clientLoaderGenerator.cjs.map +1 -0
  72. package/lib/vite-wrappers/generators/clientLoaderGenerator.d.ts +17 -0
  73. package/lib/vite-wrappers/generators/clientLoaderGenerator.js +149 -0
  74. package/lib/vite-wrappers/generators/clientLoaderGenerator.js.map +1 -0
  75. package/lib/vite-wrappers/generators/clientLoaderGenerator.test.d.ts +1 -0
  76. package/lib/vite-wrappers/generators/generateHasConfiguration.cjs +20 -0
  77. package/lib/vite-wrappers/generators/generateHasConfiguration.cjs.map +1 -0
  78. package/lib/vite-wrappers/generators/generateHasConfiguration.d.ts +10 -0
  79. package/lib/vite-wrappers/generators/generateHasConfiguration.js +20 -0
  80. package/lib/vite-wrappers/generators/generateHasConfiguration.js.map +1 -0
  81. package/lib/vite-wrappers/generators/generateHasPermission.cjs +29 -0
  82. package/lib/vite-wrappers/generators/generateHasPermission.cjs.map +1 -0
  83. package/lib/vite-wrappers/generators/generateHasPermission.d.ts +9 -0
  84. package/lib/vite-wrappers/generators/generateHasPermission.js +29 -0
  85. package/lib/vite-wrappers/generators/generateHasPermission.js.map +1 -0
  86. package/lib/vite-wrappers/generators/generateHasPermission.test.d.ts +1 -0
  87. package/lib/vite-wrappers/generators/loaderGenerator.cjs +197 -0
  88. package/lib/vite-wrappers/generators/loaderGenerator.cjs.map +1 -0
  89. package/lib/vite-wrappers/generators/loaderGenerator.d.ts +44 -0
  90. package/lib/vite-wrappers/{loaderGenerator.js → generators/loaderGenerator.js} +74 -122
  91. package/lib/vite-wrappers/generators/loaderGenerator.js.map +1 -0
  92. package/lib/vite-wrappers/generators/loaderGenerator.test.d.ts +1 -0
  93. package/lib/vite-wrappers/generators/utils/pickConfig.cjs +16 -0
  94. package/lib/vite-wrappers/generators/utils/pickConfig.cjs.map +1 -0
  95. package/lib/vite-wrappers/generators/utils/pickConfig.d.ts +10 -0
  96. package/lib/vite-wrappers/generators/utils/pickConfig.js +16 -0
  97. package/lib/vite-wrappers/generators/utils/pickConfig.js.map +1 -0
  98. package/lib/vite-wrappers/generators/utils/resourceParams.cjs +36 -0
  99. package/lib/vite-wrappers/generators/utils/resourceParams.cjs.map +1 -0
  100. package/lib/vite-wrappers/generators/utils/resourceParams.d.ts +11 -0
  101. package/lib/vite-wrappers/generators/utils/resourceParams.js +36 -0
  102. package/lib/vite-wrappers/generators/utils/resourceParams.js.map +1 -0
  103. package/lib/vite-wrappers/icon-switch.cjs +4 -4
  104. package/lib/vite-wrappers/icon-switch.cjs.map +1 -1
  105. package/lib/vite-wrappers/icon-switch.d.ts +1 -1
  106. package/lib/vite-wrappers/icon-switch.js +4 -4
  107. package/lib/vite-wrappers/icon-switch.js.map +1 -1
  108. package/lib/vite-wrappers/index.d.ts +3 -0
  109. package/lib/vite-wrappers/json-wrappers.cjs +103 -14
  110. package/lib/vite-wrappers/json-wrappers.cjs.map +1 -1
  111. package/lib/vite-wrappers/json-wrappers.d.ts +33 -0
  112. package/lib/vite-wrappers/json-wrappers.js +103 -14
  113. package/lib/vite-wrappers/json-wrappers.js.map +1 -1
  114. package/lib/vite-wrappers/wrapperComponent.cjs +190 -125
  115. package/lib/vite-wrappers/wrapperComponent.cjs.map +1 -1
  116. package/lib/vite-wrappers/wrapperComponent.d.ts +9 -0
  117. package/lib/vite-wrappers/wrapperComponent.js +190 -125
  118. package/lib/vite-wrappers/wrapperComponent.js.map +1 -1
  119. package/package.json +7 -5
  120. package/lib/vite-wrappers/loaderGenerator.cjs +0 -245
  121. package/lib/vite-wrappers/loaderGenerator.cjs.map +0 -1
  122. package/lib/vite-wrappers/loaderGenerator.d.ts +0 -18
  123. package/lib/vite-wrappers/loaderGenerator.js.map +0 -1
  124. /package/lib/{vite-wrappers/loaderGenerator.test.d.ts → rollup/modifyLibFiles/handleComponentOrDialog.test.d.ts} +0 -0
@@ -0,0 +1,43 @@
1
+ 'use strict';var fs=require('fs'),path=require('path'),handleComponentOrDialog=require('../rollup/modifyLibFiles/handleComponentOrDialog.cjs');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var fs__namespace=/*#__PURE__*/_interopNamespaceDefault(fs);var path__namespace=/*#__PURE__*/_interopNamespaceDefault(path);// import { getHash } from './json-wrappers';
2
+ function getRootPath() {
3
+ return process.cwd();
4
+ }
5
+ function generateRoute(filePath) {
6
+ const { loaderInfo } = handleComponentOrDialog.extractLoaderInfoFromFile(filePath);
7
+ return { loaderInfo };
8
+ }
9
+ function createDummyFile(route) {
10
+ const routeStr = `${route.id}/${route.path}`;
11
+ const fileName = `DummyRoute-${routeStr}.tsx`;
12
+ const newFilePath = path__namespace.join(getRootPath(), 'app', fileName);
13
+ const dummyComponent = createDummyComponent(route);
14
+ fs__namespace.writeFileSync(newFilePath, dummyComponent, { encoding: 'utf8', flag: 'w' });
15
+ return newFilePath;
16
+ }
17
+ function createDummyComponent(options) {
18
+ const template = `
19
+ import * as React from 'react';
20
+
21
+ export const loader = () => {
22
+ return {
23
+ title: '${options.name ?? 'Test Component'}'
24
+ };
25
+ };
26
+
27
+ export const action = () => {
28
+ return {};
29
+ };
30
+
31
+ export const Component = props => {
32
+ const { loaderData } = props;
33
+ return (
34
+ <>
35
+ <h1>{loaderData?.title}</h1>
36
+ <p>props:</p>
37
+ <code>{JSON.stringify(props, null, 2)}</code>
38
+ </>
39
+ );
40
+ };
41
+ `;
42
+ return template;
43
+ }exports.createDummyFile=createDummyFile;exports.generateRoute=generateRoute;//# sourceMappingURL=custom-routes.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-routes.cjs","sources":["../../src/vite-wrappers/custom-routes.ts"],"sourcesContent":[null],"names":["extractLoaderInfoFromFile","path","fs"],"mappings":"yiBAGA;AAEA,SAAS,WAAW,GAAA;AAChB,IAAA,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC;AACzB,CAAC;AAEK,SAAU,aAAa,CAAC,QAAgB,EAAA;IAC1C,MAAM,EAAE,UAAU,EAAE,GAAGA,iDAAyB,CAAC,QAAQ,CAAC,CAAC;IAC3D,OAAO,EAAE,UAAU,EAAE,CAAC;AAC1B,CAAC;AAEK,SAAU,eAAe,CAAC,KAAU,EAAA;IACtC,MAAM,QAAQ,GAAG,CAAA,EAAG,KAAK,CAAC,EAAE,CAAA,CAAA,EAAI,KAAK,CAAC,IAAI,CAAA,CAAE,CAAC;AAC7C,IAAA,MAAM,QAAQ,GAAG,CAAc,WAAA,EAAA,QAAQ,MAAM,CAAC;AAC9C,IAAA,MAAM,WAAW,GAAGC,eAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC9D,IAAA,MAAM,cAAc,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAEnD,IAAAC,aAAE,CAAC,aAAa,CAAC,WAAW,EAAE,cAAc,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;AAC/E,IAAA,OAAO,WAAW,CAAC;AACvB,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAY,EAAA;AACtC,IAAA,MAAM,QAAQ,GAAG,CAAA;;;;;cAKP,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAAA;;;;;;;;;;;;;;;;;;KAkBzC,CAAC;AAEF,IAAA,OAAO,QAAQ,CAAC;AACpB"}
@@ -0,0 +1,2 @@
1
+ export declare function generateRoute(filePath: string): any;
2
+ export declare function createDummyFile(route: any): string;
@@ -0,0 +1,43 @@
1
+ import*as fs from'fs';import*as path from'path';import {extractLoaderInfoFromFile}from'../rollup/modifyLibFiles/handleComponentOrDialog.js';// import { getHash } from './json-wrappers';
2
+ function getRootPath() {
3
+ return process.cwd();
4
+ }
5
+ function generateRoute(filePath) {
6
+ const { loaderInfo } = extractLoaderInfoFromFile(filePath);
7
+ return { loaderInfo };
8
+ }
9
+ function createDummyFile(route) {
10
+ const routeStr = `${route.id}/${route.path}`;
11
+ const fileName = `DummyRoute-${routeStr}.tsx`;
12
+ const newFilePath = path.join(getRootPath(), 'app', fileName);
13
+ const dummyComponent = createDummyComponent(route);
14
+ fs.writeFileSync(newFilePath, dummyComponent, { encoding: 'utf8', flag: 'w' });
15
+ return newFilePath;
16
+ }
17
+ function createDummyComponent(options) {
18
+ const template = `
19
+ import * as React from 'react';
20
+
21
+ export const loader = () => {
22
+ return {
23
+ title: '${options.name ?? 'Test Component'}'
24
+ };
25
+ };
26
+
27
+ export const action = () => {
28
+ return {};
29
+ };
30
+
31
+ export const Component = props => {
32
+ const { loaderData } = props;
33
+ return (
34
+ <>
35
+ <h1>{loaderData?.title}</h1>
36
+ <p>props:</p>
37
+ <code>{JSON.stringify(props, null, 2)}</code>
38
+ </>
39
+ );
40
+ };
41
+ `;
42
+ return template;
43
+ }export{createDummyFile,generateRoute};//# sourceMappingURL=custom-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-routes.js","sources":["../../src/vite-wrappers/custom-routes.ts"],"sourcesContent":[null],"names":[],"mappings":"4IAGA;AAEA,SAAS,WAAW,GAAA;AAChB,IAAA,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC;AACzB,CAAC;AAEK,SAAU,aAAa,CAAC,QAAgB,EAAA;IAC1C,MAAM,EAAE,UAAU,EAAE,GAAG,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IAC3D,OAAO,EAAE,UAAU,EAAE,CAAC;AAC1B,CAAC;AAEK,SAAU,eAAe,CAAC,KAAU,EAAA;IACtC,MAAM,QAAQ,GAAG,CAAA,EAAG,KAAK,CAAC,EAAE,CAAA,CAAA,EAAI,KAAK,CAAC,IAAI,CAAA,CAAE,CAAC;AAC7C,IAAA,MAAM,QAAQ,GAAG,CAAc,WAAA,EAAA,QAAQ,MAAM,CAAC;AAC9C,IAAA,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC9D,IAAA,MAAM,cAAc,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAEnD,IAAA,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,cAAc,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;AAC/E,IAAA,OAAO,WAAW,CAAC;AACvB,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAY,EAAA;AACtC,IAAA,MAAM,QAAQ,GAAG,CAAA;;;;;cAKP,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAAA;;;;;;;;;;;;;;;;;;KAkBzC,CAAC;AAEF,IAAA,OAAO,QAAQ,CAAC;AACpB"}
@@ -0,0 +1,149 @@
1
+ 'use strict';var lodashEs=require('lodash-es'),generateHasPermission=require('./generateHasPermission.cjs');/**
2
+ * Generates the client-side loader logic for fetching data on the client-side, including caching mechanisms.
3
+ *
4
+ * @param options - The options including GraphQL queries to fetch on the client-side.
5
+ * @returns The generated client loader function string.
6
+ */
7
+ const generateClientLoader = ({ queries }) => {
8
+ if (Object.keys(queries ?? {}).length === 0) {
9
+ return '';
10
+ }
11
+ return `
12
+ const defaultClientLoader = async ({ params, serverLoader, _dataContext = {} }) => {
13
+ const client = window.__CLIENT_SERVICE__?.apolloClient;
14
+ const container = window.__CLIENT_SERVICE__?.container;
15
+
16
+ try {
17
+ // Generate queries object with correct variables
18
+ const queries = ${Object.entries(queries).reduce((acc, [key, value], index) => {
19
+ const formattedValue = value.includes('queryParamsGenerator_')
20
+ ? `queryGeneratorFunc({...params, _dataContext}).${value.split('queryParamsGenerator_')[1]}`
21
+ : value;
22
+ return `${acc}${key}:${formattedValue}${index + 1 === Object.keys(queries).length ? '}' : ','}`;
23
+ }, '{')};
24
+
25
+ // Generate expected query keys
26
+ const queryKeys: string[] = [${Object.keys(queries)
27
+ .map((key) => lodashEs.camelCase(key.replace('Get', '')).replace('Document', 'Query'))
28
+ .map((key) => `'${key}'`)}];
29
+
30
+ let shouldCallServerLoader = false;
31
+ let response = {};
32
+ let cachedData, cacheKey;
33
+
34
+ ${Object.keys(queries)
35
+ .map((queryDoc, index) => `
36
+ // Read from cache using the actual query and variables
37
+ cachedData = client.cache.readQuery({
38
+ query: ${queryDoc},
39
+ variables: queries['${queryDoc}'],
40
+ });
41
+
42
+ // Use the response structure as cacheKey, instead of relying on manually generated cache keys
43
+ cacheKey = cachedData ? [...Object.keys(cachedData)][0] : undefined;
44
+ if (!cachedData) {
45
+ shouldCallServerLoader = true;
46
+ }
47
+ if (cachedData && cacheKey) {
48
+ // If cache is not empty, return the cached data and matches the same structure as the server response
49
+ response[queryKeys[${index}]] = Promise.resolve({ data: { [cacheKey]: cachedData[cacheKey] } });
50
+ }
51
+ `)
52
+ .join('')}
53
+
54
+ if (!shouldCallServerLoader) return response;
55
+
56
+ // If cache is empty, call server loader
57
+ // find a way to avoid looping
58
+ const serverData = await serverLoader();
59
+
60
+ if (serverData?.errors?.length) {
61
+ const store = container.get(ClientTypes.ReduxStore);
62
+ serverData?.errors?.forEach((error) => {
63
+ store.dispatch(error);
64
+ });
65
+ }
66
+
67
+ let queryKey;
68
+ ${Object.keys(queries)
69
+ .map((queryDoc, index) => `
70
+ queryKey = queryKeys[${index}];
71
+ if (!serverData[queryKey].then) return;
72
+ // Write the data back to the cache and use the correct key from the server response
73
+ serverData[queryKey].then(({ data: serverData }) => {
74
+ client.cache.writeQuery({
75
+ query: ${queryDoc},
76
+ variables: queries['${queryDoc}'],
77
+ data: serverData, // Use the server response structure as the data
78
+ });
79
+ });
80
+ `)
81
+ .join('')}
82
+
83
+ return serverData;
84
+
85
+ } catch (err) {
86
+ console.error('Error in defaultClientLoader', err);
87
+ }
88
+ };
89
+ `;
90
+ };
91
+ /**
92
+ * Generates the client-side loader export statements for client-side data fetching and caching.
93
+ *
94
+ * @param options - The component options that control the generation of the loader exports.
95
+ * @param hasMiddleware - A boolean flag to determine if the middleware is included.
96
+ * @param hasQueries - A boolean flag to determine if the component has queries.
97
+ * @returns {string} - The generated client loader export statement.
98
+ */
99
+ function generateClientLoaderExports(options, hasMiddleware, hasQueries) {
100
+ let clientLoaderExport = '';
101
+ clientLoaderExport += generateClientLoader(options);
102
+ clientLoaderExport += `
103
+ export async function clientLoader(params) {
104
+ ${hasMiddleware ? 'const middlewareStack = [];' : ''}
105
+ ${options.authority?.length > 0 || options.extraPermissions?.length > 0 ? 'middlewareStack.push({ name: "permissions", func: permissionMiddleware });\n' : ''}
106
+ ${(options.configurations ?? []).length > 0 ? 'middlewareStack.push({ name: "configurations", func: configurationMiddleware });\n' : ''}
107
+ ${(options.clientMiddlewares ?? [])
108
+ ?.map((_, index) => `middlewareStack.push({ name: "middleware${index + 1}" , func: clientMiddleware${index + 1} });\n`)
109
+ .join('')}
110
+
111
+ // Create resourceParams from extraParams if available, with dynamic resolution of path parameters.
112
+ const resourceParams = ${options.configurations?.length > 0
113
+ ? `
114
+ resolveResourceParamsPlaceholders(
115
+ ${JSON.stringify(options.extraParams?.resourceParams ?? {})},
116
+ params.params || {}
117
+ )`
118
+ : '{}'};
119
+
120
+
121
+ const paramsWithResource = {
122
+ ...params,
123
+ resourceParams,
124
+ configurations: ${JSON.stringify(options.configurations ?? [])},
125
+ };
126
+
127
+ ${hasMiddleware
128
+ ? `
129
+ const apolloClient = window.__CLIENT_SERVICE__?.apolloClient;
130
+ let middlewareData = {};
131
+ if (middlewareStack.length > 0) {
132
+ middlewareData = await clientLoaderWithMiddleware({...paramsWithResource, context:{ apolloClient }}, {}, middlewareStack) || {};
133
+ }
134
+ let { permissions = null, configurations = null, ...rest } = middlewareData;\n`
135
+ : ''}
136
+ let hasPermissions = true;
137
+ ${generateHasPermission.generateHasPermission(options, true)}
138
+
139
+ const paramsWithMiddlewareData = ${hasMiddleware ? `{ ...paramsWithResource, _dataContext: middlewareData }` : '{ ...params }'};
140
+
141
+ let defaultLoaderData = ${hasQueries ? `hasPermissions ? await defaultClientLoader(paramsWithMiddlewareData) : {}` : '{}'};
142
+ let loaderData = ${options.hasClientLoader ? ` hasPermissions ? await clientLoaderFunc(params) : {}` : '{}'};
143
+
144
+ return { ...${hasMiddleware ? `{ permissions, configurations, dataContext: rest }` : `{}`}, ...defaultLoaderData, ...loaderData };
145
+ }
146
+ clientLoader.hydrate = true;
147
+ `;
148
+ return clientLoaderExport;
149
+ }exports.generateClientLoader=generateClientLoader;exports.generateClientLoaderExports=generateClientLoaderExports;//# sourceMappingURL=clientLoaderGenerator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientLoaderGenerator.cjs","sources":["../../../src/vite-wrappers/generators/clientLoaderGenerator.ts"],"sourcesContent":[null],"names":["camelCase","generateHasPermission"],"mappings":"4GAIA;;;;;AAKG;MACU,oBAAoB,GAAG,CAAC,EAAE,OAAO,EAA6B,KAAI;AAC3E,IAAA,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;AACzC,QAAA,OAAO,EAAE,CAAC;KACb;IAED,OAAO,CAAA;;;;;;;AAOe,wBAAA,EAAA,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,KAAK,KAAI;AAC1E,QAAA,MAAM,cAAc,GAAG,KAAK,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BAAA,EAAA,UAAU,GAAG,2EAA2E,GAAG,IAAI,CAAA;qBACtG,OAAO,CAAC,eAAe,GAAG,CAAuD,qDAAA,CAAA,GAAG,IAAI,CAAA;;AAE7F,cAAA,EAAA,aAAa,GAAG,oDAAoD,GAAG,CAAI,EAAA,CAAA,CAAA;;;CAG1F,CAAC;AAEE,IAAA,OAAO,kBAAkB,CAAC;AAC9B"}
@@ -0,0 +1,17 @@
1
+ import { IOptions } from '../../interfaces/types';
2
+ /**
3
+ * Generates the client-side loader logic for fetching data on the client-side, including caching mechanisms.
4
+ *
5
+ * @param options - The options including GraphQL queries to fetch on the client-side.
6
+ * @returns The generated client loader function string.
7
+ */
8
+ export declare const generateClientLoader: ({ queries }: Pick<IOptions, "queries">) => string;
9
+ /**
10
+ * Generates the client-side loader export statements for client-side data fetching and caching.
11
+ *
12
+ * @param options - The component options that control the generation of the loader exports.
13
+ * @param hasMiddleware - A boolean flag to determine if the middleware is included.
14
+ * @param hasQueries - A boolean flag to determine if the component has queries.
15
+ * @returns {string} - The generated client loader export statement.
16
+ */
17
+ export declare function generateClientLoaderExports(options: IOptions, hasMiddleware: boolean, hasQueries: boolean): string;
@@ -0,0 +1,149 @@
1
+ import {camelCase}from'lodash-es';import {generateHasPermission}from'./generateHasPermission.js';/**
2
+ * Generates the client-side loader logic for fetching data on the client-side, including caching mechanisms.
3
+ *
4
+ * @param options - The options including GraphQL queries to fetch on the client-side.
5
+ * @returns The generated client loader function string.
6
+ */
7
+ const generateClientLoader = ({ queries }) => {
8
+ if (Object.keys(queries ?? {}).length === 0) {
9
+ return '';
10
+ }
11
+ return `
12
+ const defaultClientLoader = async ({ params, serverLoader, _dataContext = {} }) => {
13
+ const client = window.__CLIENT_SERVICE__?.apolloClient;
14
+ const container = window.__CLIENT_SERVICE__?.container;
15
+
16
+ try {
17
+ // Generate queries object with correct variables
18
+ const queries = ${Object.entries(queries).reduce((acc, [key, value], index) => {
19
+ const formattedValue = value.includes('queryParamsGenerator_')
20
+ ? `queryGeneratorFunc({...params, _dataContext}).${value.split('queryParamsGenerator_')[1]}`
21
+ : value;
22
+ return `${acc}${key}:${formattedValue}${index + 1 === Object.keys(queries).length ? '}' : ','}`;
23
+ }, '{')};
24
+
25
+ // Generate expected query keys
26
+ const queryKeys: string[] = [${Object.keys(queries)
27
+ .map((key) => camelCase(key.replace('Get', '')).replace('Document', 'Query'))
28
+ .map((key) => `'${key}'`)}];
29
+
30
+ let shouldCallServerLoader = false;
31
+ let response = {};
32
+ let cachedData, cacheKey;
33
+
34
+ ${Object.keys(queries)
35
+ .map((queryDoc, index) => `
36
+ // Read from cache using the actual query and variables
37
+ cachedData = client.cache.readQuery({
38
+ query: ${queryDoc},
39
+ variables: queries['${queryDoc}'],
40
+ });
41
+
42
+ // Use the response structure as cacheKey, instead of relying on manually generated cache keys
43
+ cacheKey = cachedData ? [...Object.keys(cachedData)][0] : undefined;
44
+ if (!cachedData) {
45
+ shouldCallServerLoader = true;
46
+ }
47
+ if (cachedData && cacheKey) {
48
+ // If cache is not empty, return the cached data and matches the same structure as the server response
49
+ response[queryKeys[${index}]] = Promise.resolve({ data: { [cacheKey]: cachedData[cacheKey] } });
50
+ }
51
+ `)
52
+ .join('')}
53
+
54
+ if (!shouldCallServerLoader) return response;
55
+
56
+ // If cache is empty, call server loader
57
+ // find a way to avoid looping
58
+ const serverData = await serverLoader();
59
+
60
+ if (serverData?.errors?.length) {
61
+ const store = container.get(ClientTypes.ReduxStore);
62
+ serverData?.errors?.forEach((error) => {
63
+ store.dispatch(error);
64
+ });
65
+ }
66
+
67
+ let queryKey;
68
+ ${Object.keys(queries)
69
+ .map((queryDoc, index) => `
70
+ queryKey = queryKeys[${index}];
71
+ if (!serverData[queryKey].then) return;
72
+ // Write the data back to the cache and use the correct key from the server response
73
+ serverData[queryKey].then(({ data: serverData }) => {
74
+ client.cache.writeQuery({
75
+ query: ${queryDoc},
76
+ variables: queries['${queryDoc}'],
77
+ data: serverData, // Use the server response structure as the data
78
+ });
79
+ });
80
+ `)
81
+ .join('')}
82
+
83
+ return serverData;
84
+
85
+ } catch (err) {
86
+ console.error('Error in defaultClientLoader', err);
87
+ }
88
+ };
89
+ `;
90
+ };
91
+ /**
92
+ * Generates the client-side loader export statements for client-side data fetching and caching.
93
+ *
94
+ * @param options - The component options that control the generation of the loader exports.
95
+ * @param hasMiddleware - A boolean flag to determine if the middleware is included.
96
+ * @param hasQueries - A boolean flag to determine if the component has queries.
97
+ * @returns {string} - The generated client loader export statement.
98
+ */
99
+ function generateClientLoaderExports(options, hasMiddleware, hasQueries) {
100
+ let clientLoaderExport = '';
101
+ clientLoaderExport += generateClientLoader(options);
102
+ clientLoaderExport += `
103
+ export async function clientLoader(params) {
104
+ ${hasMiddleware ? 'const middlewareStack = [];' : ''}
105
+ ${options.authority?.length > 0 || options.extraPermissions?.length > 0 ? 'middlewareStack.push({ name: "permissions", func: permissionMiddleware });\n' : ''}
106
+ ${(options.configurations ?? []).length > 0 ? 'middlewareStack.push({ name: "configurations", func: configurationMiddleware });\n' : ''}
107
+ ${(options.clientMiddlewares ?? [])
108
+ ?.map((_, index) => `middlewareStack.push({ name: "middleware${index + 1}" , func: clientMiddleware${index + 1} });\n`)
109
+ .join('')}
110
+
111
+ // Create resourceParams from extraParams if available, with dynamic resolution of path parameters.
112
+ const resourceParams = ${options.configurations?.length > 0
113
+ ? `
114
+ resolveResourceParamsPlaceholders(
115
+ ${JSON.stringify(options.extraParams?.resourceParams ?? {})},
116
+ params.params || {}
117
+ )`
118
+ : '{}'};
119
+
120
+
121
+ const paramsWithResource = {
122
+ ...params,
123
+ resourceParams,
124
+ configurations: ${JSON.stringify(options.configurations ?? [])},
125
+ };
126
+
127
+ ${hasMiddleware
128
+ ? `
129
+ const apolloClient = window.__CLIENT_SERVICE__?.apolloClient;
130
+ let middlewareData = {};
131
+ if (middlewareStack.length > 0) {
132
+ middlewareData = await clientLoaderWithMiddleware({...paramsWithResource, context:{ apolloClient }}, {}, middlewareStack) || {};
133
+ }
134
+ let { permissions = null, configurations = null, ...rest } = middlewareData;\n`
135
+ : ''}
136
+ let hasPermissions = true;
137
+ ${generateHasPermission(options, true)}
138
+
139
+ const paramsWithMiddlewareData = ${hasMiddleware ? `{ ...paramsWithResource, _dataContext: middlewareData }` : '{ ...params }'};
140
+
141
+ let defaultLoaderData = ${hasQueries ? `hasPermissions ? await defaultClientLoader(paramsWithMiddlewareData) : {}` : '{}'};
142
+ let loaderData = ${options.hasClientLoader ? ` hasPermissions ? await clientLoaderFunc(params) : {}` : '{}'};
143
+
144
+ return { ...${hasMiddleware ? `{ permissions, configurations, dataContext: rest }` : `{}`}, ...defaultLoaderData, ...loaderData };
145
+ }
146
+ clientLoader.hydrate = true;
147
+ `;
148
+ return clientLoaderExport;
149
+ }export{generateClientLoader,generateClientLoaderExports};//# sourceMappingURL=clientLoaderGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientLoaderGenerator.js","sources":["../../../src/vite-wrappers/generators/clientLoaderGenerator.ts"],"sourcesContent":[null],"names":[],"mappings":"iGAIA;;;;;AAKG;MACU,oBAAoB,GAAG,CAAC,EAAE,OAAO,EAA6B,KAAI;AAC3E,IAAA,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;AACzC,QAAA,OAAO,EAAE,CAAC;KACb;IAED,OAAO,CAAA;;;;;;;AAOe,wBAAA,EAAA,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,KAAK,KAAI;AAC1E,QAAA,MAAM,cAAc,GAAG,KAAK,CAAC,QAAQ,CAAC,uBAAuB,CAAC;cACxD,CAAiD,8CAAA,EAAA,KAAK,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAE,CAAA;cAC1F,KAAK,CAAC;AACZ,QAAA,OAAO,CAAG,EAAA,GAAG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AAA;;;CAG1F,CAAC;AAEE,IAAA,OAAO,kBAAkB,CAAC;AAC9B"}
@@ -0,0 +1,20 @@
1
+ 'use strict';/**
2
+ * Generates the configuration-picking logic for loaders.
3
+ * Filters configurations based on provided configuration keys.
4
+ *
5
+ * @param options - The options containing configuration keys to pick.
6
+ * @param isClient - A flag to specify if it's for client-side loading (default: false).
7
+ * @returns The configuration-picking logic string.
8
+ */
9
+ function generateConfigurationLogic(options, isClient = false) {
10
+ let generates = '';
11
+ // Check if configurations are provided and generate logic for picking configurations based on keys
12
+ if (options.configurations?.length > 0) {
13
+ generates = `
14
+ if (configurations !== null) {
15
+ configurations = pickValues(configurations, ${JSON.stringify(options.configurations)});
16
+ }
17
+ `;
18
+ }
19
+ return generates;
20
+ }exports.generateConfigurationLogic=generateConfigurationLogic;//# sourceMappingURL=generateHasConfiguration.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateHasConfiguration.cjs","sources":["../../../src/vite-wrappers/generators/generateHasConfiguration.ts"],"sourcesContent":[null],"names":[],"mappings":"aAGA;;;;;;;AAOG;SACa,0BAA0B,CAAC,OAAiB,EAAE,WAAoB,KAAK,EAAA;IACnF,IAAI,SAAS,GAAG,EAAE,CAAC;;IAGnB,IAAI,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,CAAC,EAAE;AACpC,QAAA,SAAS,GAAG,CAAA;;AAEsC,wDAAA,EAAA,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;;SAEvF,CAAC;KACL;AACD,IAAA,OAAO,SAAS,CAAC;AACrB"}
@@ -0,0 +1,10 @@
1
+ import { IOptions } from '../../interfaces/types';
2
+ /**
3
+ * Generates the configuration-picking logic for loaders.
4
+ * Filters configurations based on provided configuration keys.
5
+ *
6
+ * @param options - The options containing configuration keys to pick.
7
+ * @param isClient - A flag to specify if it's for client-side loading (default: false).
8
+ * @returns The configuration-picking logic string.
9
+ */
10
+ export declare function generateConfigurationLogic(options: IOptions, isClient?: boolean): string;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Generates the configuration-picking logic for loaders.
3
+ * Filters configurations based on provided configuration keys.
4
+ *
5
+ * @param options - The options containing configuration keys to pick.
6
+ * @param isClient - A flag to specify if it's for client-side loading (default: false).
7
+ * @returns The configuration-picking logic string.
8
+ */
9
+ function generateConfigurationLogic(options, isClient = false) {
10
+ let generates = '';
11
+ // Check if configurations are provided and generate logic for picking configurations based on keys
12
+ if (options.configurations?.length > 0) {
13
+ generates = `
14
+ if (configurations !== null) {
15
+ configurations = pickValues(configurations, ${JSON.stringify(options.configurations)});
16
+ }
17
+ `;
18
+ }
19
+ return generates;
20
+ }export{generateConfigurationLogic};//# sourceMappingURL=generateHasConfiguration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateHasConfiguration.js","sources":["../../../src/vite-wrappers/generators/generateHasConfiguration.ts"],"sourcesContent":[null],"names":[],"mappings":"AAGA;;;;;;;AAOG;SACa,0BAA0B,CAAC,OAAiB,EAAE,WAAoB,KAAK,EAAA;IACnF,IAAI,SAAS,GAAG,EAAE,CAAC;;IAGnB,IAAI,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,CAAC,EAAE;AACpC,QAAA,SAAS,GAAG,CAAA;;AAEsC,wDAAA,EAAA,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;;SAEvF,CAAC;KACL;AACD,IAAA,OAAO,SAAS,CAAC;AACrB"}
@@ -0,0 +1,29 @@
1
+ 'use strict';/**
2
+ * Generates the permission-check logic for loaders, filtering permissions based on authority keys.
3
+ *
4
+ * @param options - The options containing the authority and extraPermissions to check.
5
+ * @param isClient - A flag to specify if it's for client-side loading (default: false).
6
+ * @returns The permission-check logic string.
7
+ */
8
+ function generateHasPermission(options, isClient = false) {
9
+ const hasLoader = isClient ? options.hasClientLoader : options.hasLoader;
10
+ let generates = '';
11
+ // Check if authority or extraPermissions are provided and generate logic for permission checks
12
+ if (options.authority?.length > 0 || options.extraPermissions?.length > 0) {
13
+ generates = `
14
+ if (permissions !== null) {
15
+ const permissionKeys = ${JSON.stringify(options.authority)} || [];
16
+ let extraPermissions = ${JSON.stringify(options.extraPermissions)} || [];
17
+ extraPermissions = permissionKeys.concat(extraPermissions);
18
+ permissions = pickValues(permissions, extraPermissions);
19
+ `;
20
+ // If loader is present, generate logic to determine if required permissions are allowed
21
+ if (hasLoader) {
22
+ generates += `
23
+ hasPermissions = permissionKeys.some(key => ['Allow'].includes(get(permissions.resolveConfiguration, key)));
24
+ `;
25
+ }
26
+ generates += `}`;
27
+ }
28
+ return generates;
29
+ }exports.generateHasPermission=generateHasPermission;//# sourceMappingURL=generateHasPermission.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateHasPermission.cjs","sources":["../../../src/vite-wrappers/generators/generateHasPermission.ts"],"sourcesContent":[null],"names":[],"mappings":"aAGA;;;;;;AAMG;SACa,qBAAqB,CAAC,OAAiB,EAAE,WAAoB,KAAK,EAAA;AAC9E,IAAA,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IACzE,IAAI,SAAS,GAAG,EAAE,CAAC;;AAGnB,IAAA,IAAI,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,gBAAgB,EAAE,MAAM,GAAG,CAAC,EAAE;AACvE,QAAA,SAAS,GAAG,CAAA;;AAEiB,mCAAA,EAAA,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;AACjC,mCAAA,EAAA,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;;;SAGpE,CAAC;;QAGF,IAAI,SAAS,EAAE;AACX,YAAA,SAAS,IAAI,CAAA;;aAEZ,CAAC;SACL;QACD,SAAS,IAAI,GAAG,CAAC;KACpB;AACD,IAAA,OAAO,SAAS,CAAC;AACrB"}
@@ -0,0 +1,9 @@
1
+ import { IOptions } from '../../interfaces/types';
2
+ /**
3
+ * Generates the permission-check logic for loaders, filtering permissions based on authority keys.
4
+ *
5
+ * @param options - The options containing the authority and extraPermissions to check.
6
+ * @param isClient - A flag to specify if it's for client-side loading (default: false).
7
+ * @returns The permission-check logic string.
8
+ */
9
+ export declare function generateHasPermission(options: IOptions, isClient?: boolean): string;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Generates the permission-check logic for loaders, filtering permissions based on authority keys.
3
+ *
4
+ * @param options - The options containing the authority and extraPermissions to check.
5
+ * @param isClient - A flag to specify if it's for client-side loading (default: false).
6
+ * @returns The permission-check logic string.
7
+ */
8
+ function generateHasPermission(options, isClient = false) {
9
+ const hasLoader = isClient ? options.hasClientLoader : options.hasLoader;
10
+ let generates = '';
11
+ // Check if authority or extraPermissions are provided and generate logic for permission checks
12
+ if (options.authority?.length > 0 || options.extraPermissions?.length > 0) {
13
+ generates = `
14
+ if (permissions !== null) {
15
+ const permissionKeys = ${JSON.stringify(options.authority)} || [];
16
+ let extraPermissions = ${JSON.stringify(options.extraPermissions)} || [];
17
+ extraPermissions = permissionKeys.concat(extraPermissions);
18
+ permissions = pickValues(permissions, extraPermissions);
19
+ `;
20
+ // If loader is present, generate logic to determine if required permissions are allowed
21
+ if (hasLoader) {
22
+ generates += `
23
+ hasPermissions = permissionKeys.some(key => ['Allow'].includes(get(permissions.resolveConfiguration, key)));
24
+ `;
25
+ }
26
+ generates += `}`;
27
+ }
28
+ return generates;
29
+ }export{generateHasPermission};//# sourceMappingURL=generateHasPermission.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateHasPermission.js","sources":["../../../src/vite-wrappers/generators/generateHasPermission.ts"],"sourcesContent":[null],"names":[],"mappings":"AAGA;;;;;;AAMG;SACa,qBAAqB,CAAC,OAAiB,EAAE,WAAoB,KAAK,EAAA;AAC9E,IAAA,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IACzE,IAAI,SAAS,GAAG,EAAE,CAAC;;AAGnB,IAAA,IAAI,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,gBAAgB,EAAE,MAAM,GAAG,CAAC,EAAE;AACvE,QAAA,SAAS,GAAG,CAAA;;AAEiB,mCAAA,EAAA,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;AACjC,mCAAA,EAAA,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;;;SAGpE,CAAC;;QAGF,IAAI,SAAS,EAAE;AACX,YAAA,SAAS,IAAI,CAAA;;aAEZ,CAAC;SACL;QACD,SAAS,IAAI,GAAG,CAAC;KACpB;AACD,IAAA,OAAO,SAAS,CAAC;AACrB"}