@gravity-ui/data-source 0.10.0-alpha.1 → 0.10.0-alpha.10

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 (70) hide show
  1. package/build/cjs/react/components/Async/Async.d.ts +3 -0
  2. package/build/cjs/react/components/Async/Async.js +18 -0
  3. package/build/cjs/react/components/Async/Async.js.map +1 -0
  4. package/build/cjs/react/components/Async/index.d.ts +3 -0
  5. package/build/cjs/react/components/Async/index.js +20 -0
  6. package/build/cjs/react/components/Async/index.js.map +1 -0
  7. package/build/cjs/react/components/Async/types.d.ts +9 -0
  8. package/build/cjs/react/components/Async/types.js +6 -0
  9. package/build/cjs/react/components/Async/types.js.map +1 -0
  10. package/build/cjs/react/components/Async/withAsync.d.ts +3 -0
  11. package/build/cjs/react/components/Async/withAsync.js +26 -0
  12. package/build/cjs/react/components/Async/withAsync.js.map +1 -0
  13. package/build/cjs/react/components/AsyncBoundary/AsyncBoundary.js +3 -2
  14. package/build/cjs/react/components/AsyncBoundary/AsyncBoundary.js.map +1 -1
  15. package/build/cjs/react/components/AsyncBoundary/types.d.ts +3 -3
  16. package/build/cjs/react/components/AsyncBoundary/types.js.map +1 -1
  17. package/build/cjs/react/components/AsyncBoundary/withAsyncBoundary.d.ts +3 -2
  18. package/build/cjs/react/components/AsyncBoundary/withAsyncBoundary.js +9 -5
  19. package/build/cjs/react/components/AsyncBoundary/withAsyncBoundary.js.map +1 -1
  20. package/build/cjs/react/index.d.ts +1 -0
  21. package/build/cjs/react/index.js +12 -0
  22. package/build/cjs/react/index.js.map +1 -1
  23. package/build/cjs/react-query/components/QueryAsyncBoundary/types.d.ts +5 -4
  24. package/build/cjs/react-query/components/QueryAsyncBoundary/types.js.map +1 -1
  25. package/build/cjs/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.d.ts +3 -2
  26. package/build/cjs/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.js +9 -5
  27. package/build/cjs/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.js.map +1 -1
  28. package/build/esm/react/components/Async/Async.d.ts +3 -0
  29. package/build/esm/react/components/Async/Async.js +11 -0
  30. package/build/esm/react/components/Async/Async.js.map +1 -0
  31. package/build/esm/react/components/Async/index.d.ts +3 -0
  32. package/build/esm/react/components/Async/index.js +3 -0
  33. package/build/esm/react/components/Async/index.js.map +1 -0
  34. package/build/esm/react/components/Async/types.d.ts +9 -0
  35. package/build/esm/react/components/Async/types.js +2 -0
  36. package/build/esm/react/components/Async/types.js.map +1 -0
  37. package/build/esm/react/components/Async/withAsync.d.ts +3 -0
  38. package/build/esm/react/components/Async/withAsync.js +19 -0
  39. package/build/esm/react/components/Async/withAsync.js.map +1 -0
  40. package/build/esm/react/components/AsyncBoundary/AsyncBoundary.js +3 -2
  41. package/build/esm/react/components/AsyncBoundary/AsyncBoundary.js.map +1 -1
  42. package/build/esm/react/components/AsyncBoundary/types.d.ts +3 -3
  43. package/build/esm/react/components/AsyncBoundary/types.js.map +1 -1
  44. package/build/esm/react/components/AsyncBoundary/withAsyncBoundary.d.ts +3 -2
  45. package/build/esm/react/components/AsyncBoundary/withAsyncBoundary.js +9 -5
  46. package/build/esm/react/components/AsyncBoundary/withAsyncBoundary.js.map +1 -1
  47. package/build/esm/react/index.d.ts +1 -0
  48. package/build/esm/react/index.js +1 -0
  49. package/build/esm/react/index.js.map +1 -1
  50. package/build/esm/react-query/components/QueryAsyncBoundary/types.d.ts +5 -4
  51. package/build/esm/react-query/components/QueryAsyncBoundary/types.js.map +1 -1
  52. package/build/esm/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.d.ts +3 -2
  53. package/build/esm/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.js +9 -5
  54. package/build/esm/react-query/components/QueryAsyncBoundary/withQueryAsyncBoundary.js.map +1 -1
  55. package/build/plugin/esbuild.cjs +1 -1
  56. package/build/plugin/esbuild.mjs +1 -1
  57. package/build/plugin/{factory-Cdmba_F_.cjs → factory-B49Ym3ij.cjs} +197 -56
  58. package/build/plugin/{factory-2tSt4Rte.mjs → factory-C_-OCKcW.mjs} +197 -56
  59. package/build/plugin/index.cjs +1 -1
  60. package/build/plugin/index.mjs +1 -1
  61. package/build/plugin/rollup.cjs +1 -1
  62. package/build/plugin/rollup.mjs +1 -1
  63. package/build/plugin/rspack.cjs +1 -1
  64. package/build/plugin/rspack.mjs +1 -1
  65. package/build/plugin/typings/client.d.ts +16 -4
  66. package/build/plugin/vite.cjs +1 -1
  67. package/build/plugin/vite.mjs +1 -1
  68. package/build/plugin/webpack.cjs +1 -1
  69. package/build/plugin/webpack.mjs +1 -1
  70. package/package.json +1 -4
@@ -1,8 +1,9 @@
1
- import type { AsyncBoundaryProps } from '../../../react';
1
+ import type { ComponentType } from 'react';
2
+ import type { AsyncBoundaryProps, ErrorViewProps } from '../../../react';
2
3
  export interface QueryAsyncBoundaryProps extends AsyncBoundaryProps {
3
4
  }
4
- export interface QueryAsyncBoundaryComponent<TProps extends object> extends React.FC<TProps> {
5
+ export interface QueryAsyncBoundaryComponent<TProps extends object = {}, TLoadingProps extends object = {}, TErrorProps extends object = {}> extends React.FC<TProps & TLoadingProps & Omit<TErrorProps, keyof ErrorViewProps>> {
5
6
  Content: React.ComponentType<TProps>;
6
- Loading: QueryAsyncBoundaryProps['LoadingView'];
7
- Error: QueryAsyncBoundaryProps['ErrorView'];
7
+ Loading: ComponentType<TLoadingProps & Partial<TProps>>;
8
+ Error: ComponentType<ErrorViewProps & TErrorProps & Partial<TProps>>;
8
9
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {AsyncBoundaryProps} from '../../../react';\n\nexport interface QueryAsyncBoundaryProps extends AsyncBoundaryProps {}\n\nexport interface QueryAsyncBoundaryComponent<TProps extends object> extends React.FC<TProps> {\n Content: React.ComponentType<TProps>;\n Loading: QueryAsyncBoundaryProps['LoadingView'];\n Error: QueryAsyncBoundaryProps['ErrorView'];\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {ComponentType} from 'react';\n\nimport type {AsyncBoundaryProps, ErrorViewProps} from '../../../react';\n\nexport interface QueryAsyncBoundaryProps extends AsyncBoundaryProps {}\n\nexport interface QueryAsyncBoundaryComponent<\n TProps extends object = {},\n TLoadingProps extends object = {},\n TErrorProps extends object = {},\n> extends React.FC<TProps & TLoadingProps & Omit<TErrorProps, keyof ErrorViewProps>> {\n Content: React.ComponentType<TProps>;\n Loading: ComponentType<TLoadingProps & Partial<TProps>>;\n Error: ComponentType<ErrorViewProps & TErrorProps & Partial<TProps>>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,3 +1,4 @@
1
1
  import React from 'react';
2
- import type { QueryAsyncBoundaryComponent, QueryAsyncBoundaryProps } from './types';
3
- export declare const withQueryAsyncBoundary: <TProps extends object>(Component: React.ComponentType<TProps>, LoadingView: QueryAsyncBoundaryProps["LoadingView"], ErrorView: QueryAsyncBoundaryProps["ErrorView"]) => QueryAsyncBoundaryComponent<TProps>;
2
+ import type { ErrorViewProps } from '../../../react';
3
+ import type { QueryAsyncBoundaryComponent } from './types';
4
+ export declare const withQueryAsyncBoundary: <TProps extends object = {}, TLoadingProps extends object = {}, TErrorProps extends object = {}>(Component: React.ComponentType<TProps>, LoadingView: React.ComponentType<TLoadingProps & Partial<TProps>>, ErrorView: React.ComponentType<ErrorViewProps & TErrorProps & Partial<TProps>>) => QueryAsyncBoundaryComponent<TProps, TLoadingProps, TErrorProps>;
@@ -2,18 +2,22 @@ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import React from 'react';
3
3
  import { QueryAsyncBoundary } from './QueryAsyncBoundary';
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
- export var withQueryAsyncBoundary = function withQueryAsyncBoundary(Component, LoadingView, ErrorView) {
5
+ export var withQueryAsyncBoundary = function withQueryAsyncBoundary(Component, _LoadingView, _ErrorView) {
6
6
  var WrappedComponent = function WrappedComponent(props) {
7
7
  return /*#__PURE__*/_jsx(QueryAsyncBoundary, {
8
- LoadingView: LoadingView,
9
- ErrorView: ErrorView,
8
+ LoadingView: function LoadingView() {
9
+ return /*#__PURE__*/_jsx(_LoadingView, _objectSpread({}, props));
10
+ },
11
+ ErrorView: function ErrorView(errorProps) {
12
+ return /*#__PURE__*/_jsx(_ErrorView, _objectSpread(_objectSpread({}, props), errorProps));
13
+ },
10
14
  children: /*#__PURE__*/_jsx(Component, _objectSpread({}, props))
11
15
  });
12
16
  };
13
17
  WrappedComponent.displayName = "WithQueryAsyncBoundary(".concat(Component.displayName || Component.name, ")");
14
18
  WrappedComponent.Content = Component;
15
- WrappedComponent.Loading = LoadingView;
16
- WrappedComponent.Error = ErrorView;
19
+ WrappedComponent.Loading = _LoadingView;
20
+ WrappedComponent.Error = _ErrorView;
17
21
  return WrappedComponent;
18
22
  };
19
23
  // #sourceMappingURL=withQueryAsyncBoundary.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","QueryAsyncBoundary","jsx","_jsx","withQueryAsyncBoundary","Component","LoadingView","ErrorView","WrappedComponent","props","children","_objectSpread","displayName","concat","name","Content","Loading","Error"],"sources":["withQueryAsyncBoundary.tsx"],"sourcesContent":["import React from 'react';\n\nimport {QueryAsyncBoundary} from './QueryAsyncBoundary';\nimport type {QueryAsyncBoundaryComponent, QueryAsyncBoundaryProps} from './types';\n\nexport const withQueryAsyncBoundary = <TProps extends object>(\n Component: React.ComponentType<TProps>,\n LoadingView: QueryAsyncBoundaryProps['LoadingView'],\n ErrorView: QueryAsyncBoundaryProps['ErrorView'],\n) => {\n const WrappedComponent = ((props: TProps) => (\n <QueryAsyncBoundary LoadingView={LoadingView} ErrorView={ErrorView}>\n <Component {...props} />\n </QueryAsyncBoundary>\n )) as QueryAsyncBoundaryComponent<TProps>;\n\n WrappedComponent.displayName = `WithQueryAsyncBoundary(${\n Component.displayName || Component.name\n })`;\n\n WrappedComponent.Content = Component;\n WrappedComponent.Loading = LoadingView;\n WrappedComponent.Error = ErrorView;\n\n return WrappedComponent;\n};\n"],"mappings":";AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAAQC,kBAAkB,QAAO,sBAAsB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGxD,OAAO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAsBA,CAC/BC,SAAsC,EACtCC,WAAmD,EACnDC,SAA+C,EAC9C;EACD,IAAMC,gBAAgB,GAAI,SAApBA,gBAAgBA,CAAKC,KAAa;IAAA,oBACpCN,IAAA,CAACF,kBAAkB;MAACK,WAAW,EAAEA,WAAY;MAACC,SAAS,EAAEA,SAAU;MAAAG,QAAA,eAC/DP,IAAA,CAACE,SAAS,EAAAM,aAAA,KAAKF,KAAK,CAAG;IAAC,CACR,CAAC;EAAA,CACgB;EAEzCD,gBAAgB,CAACI,WAAW,6BAAAC,MAAA,CACxBR,SAAS,CAACO,WAAW,IAAIP,SAAS,CAACS,IAAI,MACxC;EAEHN,gBAAgB,CAACO,OAAO,GAAGV,SAAS;EACpCG,gBAAgB,CAACQ,OAAO,GAAGV,WAAW;EACtCE,gBAAgB,CAACS,KAAK,GAAGV,SAAS;EAElC,OAAOC,gBAAgB;AAC3B,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","QueryAsyncBoundary","jsx","_jsx","withQueryAsyncBoundary","Component","LoadingView","ErrorView","WrappedComponent","props","_LoadingView","_objectSpread","errorProps","_ErrorView","children","displayName","concat","name","Content","Loading","Error"],"sources":["withQueryAsyncBoundary.tsx"],"sourcesContent":["import React from 'react';\n\nimport type {ErrorViewProps} from '../../../react';\n\nimport {QueryAsyncBoundary} from './QueryAsyncBoundary';\nimport type {QueryAsyncBoundaryComponent} from './types';\n\nexport const withQueryAsyncBoundary = <\n TProps extends object = {},\n TLoadingProps extends object = {},\n TErrorProps extends object = {},\n>(\n Component: React.ComponentType<TProps>,\n LoadingView: React.ComponentType<TLoadingProps & Partial<TProps>>,\n ErrorView: React.ComponentType<ErrorViewProps & TErrorProps & Partial<TProps>>,\n) => {\n const WrappedComponent = ((props: TProps & TLoadingProps & TErrorProps) => (\n <QueryAsyncBoundary\n LoadingView={() => <LoadingView {...props} />}\n ErrorView={(errorProps) => <ErrorView {...props} {...errorProps} />}\n >\n <Component {...props} />\n </QueryAsyncBoundary>\n )) as QueryAsyncBoundaryComponent<TProps, TLoadingProps, TErrorProps>;\n\n WrappedComponent.displayName = `WithQueryAsyncBoundary(${\n Component.displayName || Component.name\n })`;\n\n WrappedComponent.Content = Component;\n WrappedComponent.Loading = LoadingView;\n WrappedComponent.Error = ErrorView;\n\n return WrappedComponent;\n};\n"],"mappings":";AAAA,OAAOA,KAAK,MAAM,OAAO;AAIzB,SAAQC,kBAAkB,QAAO,sBAAsB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGxD,OAAO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAsBA,CAK/BC,SAAsC,EACtCC,YAAiE,EACjEC,UAA8E,EAC7E;EACD,IAAMC,gBAAgB,GAAI,SAApBA,gBAAgBA,CAAKC,KAA2C;IAAA,oBAClEN,IAAA,CAACF,kBAAkB;MACfK,WAAW,EAAE,SAAbA,WAAWA,CAAA;QAAA,oBAAQH,IAAA,CAACO,YAAW,EAAAC,aAAA,KAAKF,KAAK,CAAG,CAAC;MAAA,CAAC;MAC9CF,SAAS,EAAE,SAAXA,SAASA,CAAGK,UAAU;QAAA,oBAAKT,IAAA,CAACU,UAAS,EAAAF,aAAA,CAAAA,aAAA,KAAKF,KAAK,GAAMG,UAAU,CAAG,CAAC;MAAA,CAAC;MAAAE,QAAA,eAEpEX,IAAA,CAACE,SAAS,EAAAM,aAAA,KAAKF,KAAK,CAAG;IAAC,CACR,CAAC;EAAA,CAC4C;EAErED,gBAAgB,CAACO,WAAW,6BAAAC,MAAA,CACxBX,SAAS,CAACU,WAAW,IAAIV,SAAS,CAACY,IAAI,MACxC;EAEHT,gBAAgB,CAACU,OAAO,GAAGb,SAAS;EACpCG,gBAAgB,CAACW,OAAO,GAAGb,YAAW;EACtCE,gBAAgB,CAACY,KAAK,GAAGb,UAAS;EAElC,OAAOC,gBAAgB;AAC3B,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- const require_factory = require("./factory-Cdmba_F_.cjs");
1
+ const require_factory = require("./factory-B49Ym3ij.cjs");
2
2
  //#region src/plugin/esbuild.ts
3
3
  var esbuild_default = (0, require("unplugin").createEsbuildPlugin)(require_factory.dataSourceLazyUnpluginFactory);
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { n as dataSourceLazyUnpluginFactory } from "./factory-2tSt4Rte.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-C_-OCKcW.mjs";
2
2
  import { createEsbuildPlugin } from "unplugin";
3
3
  //#region src/plugin/esbuild.ts
4
4
  var esbuild_default = createEsbuildPlugin(dataSourceLazyUnpluginFactory);
@@ -49,11 +49,12 @@ function isCompanionSuffix(suffix) {
49
49
  return COMPANION_SUFFIXES_SET.has(suffix);
50
50
  }
51
51
  function makeVirtualId(type, sourceFile) {
52
- return `${VIRTUAL_PREFIX}:${type}:${sourceFile}`;
52
+ return `${VIRTUAL_PREFIX}:${type}:${stripQuery(sourceFile)}`;
53
53
  }
54
54
  function parseVirtualId(id) {
55
- if (id.indexOf("\0dsl-plugin") !== 0) return null;
56
- const rest = id.slice(12);
55
+ const prefixIndex = id.indexOf(VIRTUAL_PREFIX);
56
+ if (prefixIndex === -1) return null;
57
+ const rest = id.slice(prefixIndex + 11 + 1);
57
58
  const colonIndex = rest.indexOf(":");
58
59
  if (colonIndex === -1) return null;
59
60
  const type = rest.slice(0, colonIndex);
@@ -65,8 +66,9 @@ function parseVirtualId(id) {
65
66
  }
66
67
  function makeCompanionId(type, sourceFile) {
67
68
  const suffix = COMPANION_TYPES[type];
68
- const ext = node_path.default.extname(sourceFile);
69
- return `${ext ? sourceFile.slice(0, -ext.length) : sourceFile}.${suffix}${ext}`;
69
+ const cleanSourceFile = stripQuery(sourceFile);
70
+ const ext = node_path.default.extname(cleanSourceFile);
71
+ return `${ext ? cleanSourceFile.slice(0, -ext.length) : cleanSourceFile}.${suffix}${ext}`;
70
72
  }
71
73
  function parseCompanionId(id) {
72
74
  const suffixIndex = id.lastIndexOf(".");
@@ -81,6 +83,14 @@ function parseCompanionId(id) {
81
83
  function isRelativeId(id) {
82
84
  return id[0] === ".";
83
85
  }
86
+ function toRelativeImportSource(fromFile, toFile) {
87
+ const fromDir = node_path.default.dirname(stripQuery(fromFile));
88
+ let rel = node_path.default.relative(fromDir, toFile);
89
+ if (node_path.default.sep !== "/") rel = rel.split(node_path.default.sep).join("/");
90
+ if (!rel.startsWith(".")) rel = `./${rel}`;
91
+ const ext = node_path.default.extname(rel);
92
+ return ext ? rel.slice(0, -ext.length) : rel;
93
+ }
84
94
  function stripQuery(id) {
85
95
  const queryIndex = id.indexOf("?");
86
96
  return queryIndex === -1 ? id : id.slice(0, queryIndex);
@@ -118,7 +128,7 @@ function extractHocInfo(hocsSet, filename, source) {
118
128
  for (const node of program.body) {
119
129
  if (node.type !== "ExportNamedDeclaration" || node.exportKind === "type" || node.declaration?.type !== "VariableDeclaration") continue;
120
130
  for (const decl of node.declaration.declarations) {
121
- if (decl.id.type !== "Identifier" || !decl.init || decl.init.type !== "CallExpression" || decl.init.callee.type !== "Identifier" || decl.init.arguments.length !== 3) continue;
131
+ if (decl.id.type !== "Identifier" || !decl.init || decl.init.type !== "CallExpression" || decl.init.callee.type !== "Identifier" || decl.init.arguments.length < 2) continue;
122
132
  const hocEntry = trackedHocs.get(decl.init.callee.name);
123
133
  if (!hocEntry) continue;
124
134
  const [contentArg, loadingArg, errorArg] = decl.init.arguments;
@@ -144,17 +154,70 @@ function extractHocInfo(hocsSet, filename, source) {
144
154
  argEnd: loadingArg.end,
145
155
  imports: filterNeededImports(importDecls, collectIdentifiers(loadingArg))
146
156
  },
147
- error: {
157
+ error: errorArg ? {
148
158
  argSource: source.slice(errorArg.start, errorArg.end),
149
159
  argStart: errorArg.start,
150
160
  argEnd: errorArg.end,
151
161
  imports: filterNeededImports(importDecls, collectIdentifiers(errorArg))
152
- }
162
+ } : null
153
163
  };
154
164
  }
155
165
  }
156
166
  return null;
157
167
  }
168
+ function extractReExports(filename, source) {
169
+ const named = /* @__PURE__ */ new Map();
170
+ const stars = [];
171
+ const program = parseProgram(filename, source);
172
+ if (!program) return {
173
+ named,
174
+ stars
175
+ };
176
+ const localImports = /* @__PURE__ */ new Map();
177
+ for (const node of program.body) {
178
+ if (node.type !== "ImportDeclaration" || node.importKind === "type") continue;
179
+ for (const spec of node.specifiers) {
180
+ if (spec.type !== "ImportSpecifier" || spec.importKind === "type") continue;
181
+ const importedName = spec.imported.type === "Literal" ? spec.imported.value : spec.imported.name;
182
+ localImports.set(spec.local.name, {
183
+ source: node.source.value,
184
+ importedName
185
+ });
186
+ }
187
+ }
188
+ for (const node of program.body) {
189
+ if (node.type === "ExportAllDeclaration" && node.exportKind !== "type" && !node.exported) {
190
+ stars.push(node.source.value);
191
+ continue;
192
+ }
193
+ if (node.type !== "ExportNamedDeclaration" || node.exportKind === "type") continue;
194
+ if (node.source) {
195
+ const src = node.source.value;
196
+ for (const spec of node.specifiers) {
197
+ if (spec.exportKind === "type") continue;
198
+ const localName = spec.local.type === "Literal" ? spec.local.value : spec.local.name;
199
+ const exportedName = spec.exported.type === "Literal" ? spec.exported.value : spec.exported.name;
200
+ named.set(exportedName, {
201
+ source: src,
202
+ importedName: localName
203
+ });
204
+ }
205
+ continue;
206
+ }
207
+ if (node.declaration) continue;
208
+ for (const spec of node.specifiers) {
209
+ if (spec.exportKind === "type" || spec.local.type === "Literal") continue;
210
+ const target = localImports.get(spec.local.name);
211
+ if (!target) continue;
212
+ const exportedName = spec.exported.type === "Literal" ? spec.exported.value : spec.exported.name;
213
+ named.set(exportedName, target);
214
+ }
215
+ }
216
+ return {
217
+ named,
218
+ stars
219
+ };
220
+ }
158
221
  const COMPANION_PROPS_RE = new RegExp(`\\.(${Object.values(COMPANION_TYPES).join("|")})\\b`);
159
222
  function extractUsages(filename, source) {
160
223
  const result = [];
@@ -281,39 +344,33 @@ function parseProgram(filename, source) {
281
344
  }
282
345
  //#endregion
283
346
  //#region src/plugin/core/generate.ts
284
- function generateAuxModule(sourceFile, info, type, options = {}) {
285
- const auxInfo = info[type];
286
- const name = info.exportedName;
347
+ function generateAuxModuleCode(exportedName, info, type) {
287
348
  const suffix = COMPANION_TYPES[type];
288
- const cleanSourceFile = stripQuery(sourceFile);
289
- const code = [
290
- renderImports(auxInfo.imports),
349
+ return [
350
+ renderImports(info.imports),
291
351
  "",
292
- `export const ${name}${suffix} = ${auxInfo.argSource};`,
352
+ `export const ${exportedName}${suffix} = ${info.argSource};`,
293
353
  ""
294
354
  ].join("\n").trimStart();
295
- return transformJsx(makeCompanionId(type, cleanSourceFile), code, options);
296
355
  }
297
356
  function generateLazyModule(sourceFile, info, options = {}) {
298
357
  const importSource = options.jsx?.importSource ?? "react";
299
358
  const name = info.exportedName;
300
359
  const cleanSourceFile = stripQuery(sourceFile);
301
360
  const base = `./${node_path.default.basename(cleanSourceFile, node_path.default.extname(cleanSourceFile))}`;
302
- const code = [
361
+ const hocBinding = info.hocImportedName === "default" ? info.hocLocalName : info.hocImportedName;
362
+ const lines = [
303
363
  `import {lazy} from '${importSource}';`,
304
364
  "",
305
365
  info.hocImportedName === "default" ? `import ${info.hocLocalName} from '${info.hocImportSource}';` : `import {${info.hocImportedName}} from '${info.hocImportSource}';`,
306
366
  "",
307
- `import {${name}Loading} from '${base}.Loading';`,
308
- `import {${name}Error} from '${base}.Error';`,
309
- ``,
310
- `export const ${name}Lazy = ${info.hocImportedName === "default" ? info.hocLocalName : info.hocImportedName}(`,
311
- ` lazy(() => import('${base}').then((m) => ({default: m.${name}Content}))),`,
312
- ` ${name}Loading,`,
313
- ` ${name}Error,`,
314
- `);`,
315
- ``
316
- ].join("\n");
367
+ `import {${name}Loading} from '${base}.Loading';`
368
+ ];
369
+ if (info.error) lines.push(`import {${name}Error} from '${base}.Error';`);
370
+ lines.push("", `export const ${name}Lazy = ${hocBinding}(`, ` lazy(() => import('${base}').then((m) => ({default: m.${name}Content}))),`, ` ${name}Loading,`);
371
+ if (info.error) lines.push(` ${name}Error,`);
372
+ lines.push(`);`, ``);
373
+ const code = lines.join("\n");
317
374
  const filename = makeCompanionId("lazy", cleanSourceFile);
318
375
  return {
319
376
  code,
@@ -324,7 +381,7 @@ function generateLazyModule(sourceFile, info, options = {}) {
324
381
  }).toString()
325
382
  };
326
383
  }
327
- function transformJsx(filename, code, options) {
384
+ function transformJsx(filename, code, options = {}) {
328
385
  const result = (0, oxc_transform.transformSync)(filename, code, {
329
386
  lang: "tsx",
330
387
  jsx: options.jsx,
@@ -394,9 +451,11 @@ function transformDefinitionModule(s, filename, info) {
394
451
  const name = info.exportedName;
395
452
  const cleanFilename = stripQuery(filename);
396
453
  const localSource = `./${node_path.default.basename(cleanFilename, node_path.default.extname(cleanFilename))}`;
397
- s.prepend(`${renderNamedImport(`${name}Loading`, `${name}Loading`, makeCompanionId("loading", localSource))}\n${renderNamedImport(`${name}Error`, `${name}Error`, makeCompanionId("error", localSource))}\n`);
454
+ const prependImports = [renderNamedImport(`${name}Loading`, `${name}Loading`, makeCompanionId("loading", localSource))];
455
+ if (info.error) prependImports.push(renderNamedImport(`${name}Error`, `${name}Error`, makeCompanionId("error", localSource)));
456
+ s.prepend(prependImports.join("\n") + "\n");
398
457
  s.overwrite(info.loading.argStart, info.loading.argEnd, `${name}Loading`);
399
- s.overwrite(info.error.argStart, info.error.argEnd, `${name}Error`);
458
+ if (info.error) s.overwrite(info.error.argStart, info.error.argEnd, `${name}Error`);
400
459
  if (info.content.kind === "identifier") s.append(`\nexport {${info.content.name} as ${name}Content};\n`);
401
460
  else {
402
461
  s.appendLeft(info.hocExportStart, `const ${name}Content = ${info.content.argSource};\n\n`);
@@ -405,15 +464,15 @@ function transformDefinitionModule(s, filename, info) {
405
464
  }
406
465
  }
407
466
  function transformUsages(s, usages) {
408
- for (const { spec, accesses } of usages) for (const access of accesses) s.overwrite(access.start, access.end, `${spec.localName}${access.prop}`);
467
+ for (const { usage } of usages) for (const access of usage.accesses) s.overwrite(access.start, access.end, `${usage.spec.localName}${access.prop}`);
409
468
  const newImports = [];
410
- for (const { decl, spec, accesses } of usages) {
411
- const propsUsed = new Set(accesses.map((access) => access.prop));
412
- for (const prop of propsUsed) newImports.push(renderNamedImport(`${spec.localName}${prop}`, `${spec.importedName}${prop}`, makeCompanionId(COMPANION_TYPE_BY_SUFFIX[prop], decl.source)));
469
+ for (const { usage, hocImportSource, hocExportedName } of usages) {
470
+ const propsUsed = new Set(usage.accesses.map((access) => access.prop));
471
+ for (const prop of propsUsed) newImports.push(renderNamedImport(`${usage.spec.localName}${prop}`, `${hocExportedName}${prop}`, makeCompanionId(COMPANION_TYPE_BY_SUFFIX[prop], hocImportSource)));
413
472
  }
414
473
  if (newImports.length > 0) s.prepend(newImports.join("\n") + "\n");
415
474
  const localsByDecl = /* @__PURE__ */ new Map();
416
- for (const usage of usages) {
475
+ for (const { usage } of usages) {
417
476
  if (usage.hasOtherUsages) continue;
418
477
  let locals = localsByDecl.get(usage.decl);
419
478
  if (!locals) localsByDecl.set(usage.decl, locals = /* @__PURE__ */ new Set());
@@ -440,13 +499,20 @@ function renderNamedImport(local, imported, source) {
440
499
  }
441
500
  //#endregion
442
501
  //#region src/plugin/core/factory.ts
443
- const DEFAULT_HOCS = [{
444
- from: "@gravity-ui/data-source",
445
- name: "withAsyncBoundary"
446
- }, {
447
- from: "@gravity-ui/data-source",
448
- name: "withQueryAsyncBoundary"
449
- }];
502
+ const DEFAULT_HOCS = [
503
+ {
504
+ from: "@gravity-ui/data-source",
505
+ name: "withAsync"
506
+ },
507
+ {
508
+ from: "@gravity-ui/data-source",
509
+ name: "withAsyncBoundary"
510
+ },
511
+ {
512
+ from: "@gravity-ui/data-source",
513
+ name: "withQueryAsyncBoundary"
514
+ }
515
+ ];
450
516
  const DEFAULT_INCLUDE = /\.(tsx?|jsx?)$/;
451
517
  const VIRTUAL_EXCLUDE = new RegExp(`${VIRTUAL_PREFIX}|${encodeURIComponent(VIRTUAL_PREFIX)}`);
452
518
  const dataSourceLazyUnpluginFactory = (options = {}) => {
@@ -458,6 +524,7 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
458
524
  const hocsSet = new Set(hocPatterns.map((pattern) => getHocString(pattern.from, pattern.name)));
459
525
  const hocsRegexp = new RegExp(Array.from(new Set(hocPatterns.map((pattern) => pattern.name))).map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"));
460
526
  const hocInfoCache = /* @__PURE__ */ new Map();
527
+ const reExportsCache = /* @__PURE__ */ new Map();
461
528
  const getHocInfo = (sourceFile, source) => {
462
529
  const key = stripQuery(sourceFile);
463
530
  const cachedInfo = hocInfoCache.get(key);
@@ -467,6 +534,53 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
467
534
  hocInfoCache.set(key, info);
468
535
  return info;
469
536
  };
537
+ const getReExports = (sourceFile, source) => {
538
+ const key = stripQuery(sourceFile);
539
+ const cachedReExports = reExportsCache.get(key);
540
+ if (cachedReExports) return cachedReExports;
541
+ const reExports = extractReExports(key, source ?? node_fs.default.readFileSync(key, "utf-8"));
542
+ reExportsCache.set(key, reExports);
543
+ return reExports;
544
+ };
545
+ const resolveHocSourceFile = async (ctx, file, importedName, visited = /* @__PURE__ */ new Set()) => {
546
+ const visitKey = `${file}\0${importedName}`;
547
+ if (visited.has(visitKey)) return null;
548
+ visited.add(visitKey);
549
+ const directInfo = getHocInfo(file);
550
+ if (directInfo && directInfo.exportedName === importedName) return {
551
+ file,
552
+ info: directInfo
553
+ };
554
+ const reExports = getReExports(file);
555
+ const named = reExports.named.get(importedName);
556
+ if (named) {
557
+ const resolved = await resolveSourceFile(ctx, named.source, file);
558
+ if (resolved) {
559
+ const next = await resolveHocSourceFile(ctx, resolved, named.importedName, visited);
560
+ if (next) return next;
561
+ }
562
+ }
563
+ for (const starSource of reExports.stars) {
564
+ const resolved = await resolveSourceFile(ctx, starSource, file);
565
+ if (!resolved) continue;
566
+ const next = await resolveHocSourceFile(ctx, resolved, importedName, visited);
567
+ if (next) return next;
568
+ }
569
+ return null;
570
+ };
571
+ const verifyUsages = async (ctx, usages, importerId) => {
572
+ return (await Promise.all(usages.map(async (usage) => {
573
+ const resolvedSourceFile = await resolveSourceFile(ctx, usage.decl.source, importerId);
574
+ if (!resolvedSourceFile) return null;
575
+ const target = await resolveHocSourceFile(ctx, resolvedSourceFile, usage.spec.importedName);
576
+ if (!target) return null;
577
+ return {
578
+ usage,
579
+ hocImportSource: toRelativeImportSource(importerId, target.file),
580
+ hocExportedName: target.info.exportedName
581
+ };
582
+ }))).filter((usage) => usage !== null);
583
+ };
470
584
  return {
471
585
  name: "data-source-lazy",
472
586
  enforce: "pre",
@@ -485,18 +599,29 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
485
599
  },
486
600
  load: {
487
601
  filter: { id: new RegExp(VIRTUAL_PREFIX) },
488
- handler(id) {
602
+ async handler(id) {
489
603
  const parsedId = parseVirtualId(id);
490
604
  if (!parsedId) return null;
491
605
  this.addWatchFile(parsedId.sourceFile);
492
606
  const info = getHocInfo(parsedId.sourceFile);
493
607
  if (!info) return null;
494
- switch (parsedId.type) {
495
- case "loading":
496
- case "error": return generateAuxModule(parsedId.sourceFile, info, parsedId.type, options.generateOptions);
497
- case "lazy": return generateLazyModule(parsedId.sourceFile, info, options.generateOptions);
498
- default: return assertNever(parsedId.type);
608
+ if (parsedId.type === "loading" || parsedId.type === "error") {
609
+ const auxInfo = info[parsedId.type];
610
+ if (!auxInfo) return null;
611
+ const filename = makeCompanionId(parsedId.type, parsedId.sourceFile);
612
+ const code = generateAuxModuleCode(info.exportedName, auxInfo, parsedId.type);
613
+ const usages = extractUsages(filename, code);
614
+ const verifiedUsages = await verifyUsages(this, usages, parsedId.sourceFile);
615
+ let resultCode = code;
616
+ if (verifiedUsages.length > 0) {
617
+ const s = new magic_string.default(code);
618
+ transformUsages(s, verifiedUsages);
619
+ resultCode = s.toString();
620
+ }
621
+ return transformJsx(filename, resultCode, options.generateOptions);
499
622
  }
623
+ if (parsedId.type === "lazy") return generateLazyModule(parsedId.sourceFile, info, options.generateOptions);
624
+ return assertNever(parsedId.type);
500
625
  }
501
626
  },
502
627
  transform: {
@@ -508,13 +633,8 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
508
633
  const info = getHocInfo(id, code);
509
634
  const usages = extractUsages(id, code);
510
635
  if (!info && usages.length === 0) return null;
511
- const verifiedUsages = (await Promise.all(usages.map(async (usage) => {
512
- const resolvedSourceFile = await resolveSourceFile(this, usage.decl.source, id);
513
- if (!resolvedSourceFile) return null;
514
- const usageInfo = getHocInfo(resolvedSourceFile);
515
- if (!usageInfo || usageInfo.exportedName !== usage.spec.importedName) return null;
516
- return usage;
517
- }))).filter((usage) => usage !== null);
636
+ const filteredUsages = info ? dropAccessesInsideHocArgs(info, usages) : usages;
637
+ const verifiedUsages = await verifyUsages(this, filteredUsages, id);
518
638
  if (!info && verifiedUsages.length === 0) return null;
519
639
  const s = new magic_string.default(code);
520
640
  if (info) transformDefinitionModule(s, id, info);
@@ -530,10 +650,31 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
530
650
  }
531
651
  },
532
652
  watchChange(id) {
533
- hocInfoCache.delete(stripQuery(id));
653
+ const key = stripQuery(id);
654
+ hocInfoCache.delete(key);
655
+ reExportsCache.delete(key);
534
656
  }
535
657
  };
536
658
  };
659
+ function isInside(info, access) {
660
+ return info.argStart <= access.start && access.end <= info.argEnd;
661
+ }
662
+ function dropAccessesInsideHocArgs(info, usages) {
663
+ const result = [];
664
+ for (const usage of usages) {
665
+ const accesses = usage.accesses.filter((access) => !isInside(info.loading, access) && !(info.error && isInside(info.error, access)) && !(info.content.kind === "inline" && isInside(info.content, access)));
666
+ if (accesses.length === 0) continue;
667
+ if (accesses.length === usage.accesses.length) {
668
+ result.push(usage);
669
+ continue;
670
+ }
671
+ result.push({
672
+ ...usage,
673
+ accesses
674
+ });
675
+ }
676
+ return result;
677
+ }
537
678
  //#endregion
538
679
  Object.defineProperty(exports, "DEFAULT_HOCS", {
539
680
  enumerable: true,