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

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-2tSt4Rte.mjs → factory-BdwLvQEp.mjs} +212 -61
  58. package/build/plugin/{factory-Cdmba_F_.cjs → factory-TMKD3PiJ.cjs} +212 -61
  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
@@ -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 = [];
@@ -234,6 +297,9 @@ function extractUsages(filename, source) {
234
297
  }
235
298
  return result;
236
299
  }
300
+ function isAccessInsideArg(arg, access) {
301
+ return arg.argStart <= access.start && access.end <= arg.argEnd;
302
+ }
237
303
  function collectIdentifiers(node) {
238
304
  const result = /* @__PURE__ */ new Set();
239
305
  walk(node, (current) => {
@@ -281,39 +347,33 @@ function parseProgram(filename, source) {
281
347
  }
282
348
  //#endregion
283
349
  //#region src/plugin/core/generate.ts
284
- function generateAuxModule(sourceFile, info, type, options = {}) {
285
- const auxInfo = info[type];
286
- const name = info.exportedName;
350
+ function generateAuxModuleCode(exportedName, info, type) {
287
351
  const suffix = COMPANION_TYPES[type];
288
- const cleanSourceFile = stripQuery(sourceFile);
289
- const code = [
290
- renderImports(auxInfo.imports),
352
+ return [
353
+ renderImports(info.imports),
291
354
  "",
292
- `export const ${name}${suffix} = ${auxInfo.argSource};`,
355
+ `export const ${exportedName}${suffix} = ${info.argSource};`,
293
356
  ""
294
357
  ].join("\n").trimStart();
295
- return transformJsx(makeCompanionId(type, cleanSourceFile), code, options);
296
358
  }
297
359
  function generateLazyModule(sourceFile, info, options = {}) {
298
360
  const importSource = options.jsx?.importSource ?? "react";
299
361
  const name = info.exportedName;
300
362
  const cleanSourceFile = stripQuery(sourceFile);
301
363
  const base = `./${node_path.default.basename(cleanSourceFile, node_path.default.extname(cleanSourceFile))}`;
302
- const code = [
364
+ const hocBinding = info.hocImportedName === "default" ? info.hocLocalName : info.hocImportedName;
365
+ const lines = [
303
366
  `import {lazy} from '${importSource}';`,
304
367
  "",
305
368
  info.hocImportedName === "default" ? `import ${info.hocLocalName} from '${info.hocImportSource}';` : `import {${info.hocImportedName}} from '${info.hocImportSource}';`,
306
369
  "",
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");
370
+ `import {${name}Loading} from '${base}.Loading';`
371
+ ];
372
+ if (info.error) lines.push(`import {${name}Error} from '${base}.Error';`);
373
+ lines.push("", `export const ${name}Lazy = ${hocBinding}(`, ` lazy(() => import('${base}').then((m) => ({default: m.${name}Content}))),`, ` ${name}Loading,`);
374
+ if (info.error) lines.push(` ${name}Error,`);
375
+ lines.push(`);`, ``);
376
+ const code = lines.join("\n");
317
377
  const filename = makeCompanionId("lazy", cleanSourceFile);
318
378
  return {
319
379
  code,
@@ -324,7 +384,7 @@ function generateLazyModule(sourceFile, info, options = {}) {
324
384
  }).toString()
325
385
  };
326
386
  }
327
- function transformJsx(filename, code, options) {
387
+ function transformJsx(filename, code, options = {}) {
328
388
  const result = (0, oxc_transform.transformSync)(filename, code, {
329
389
  lang: "tsx",
330
390
  jsx: options.jsx,
@@ -390,30 +450,42 @@ function resolveWithCompiler(compiler, directory, request) {
390
450
  }
391
451
  //#endregion
392
452
  //#region src/plugin/core/transform.ts
393
- function transformDefinitionModule(s, filename, info) {
453
+ function transformDefinitionModule(s, filename, info, verifiedUsages) {
394
454
  const name = info.exportedName;
395
455
  const cleanFilename = stripQuery(filename);
396
456
  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`);
457
+ const prependImports = [renderNamedImport(`${name}Loading`, `${name}Loading`, makeCompanionId("loading", localSource))];
458
+ if (info.error) prependImports.push(renderNamedImport(`${name}Error`, `${name}Error`, makeCompanionId("error", localSource)));
459
+ s.prepend(prependImports.join("\n") + "\n");
398
460
  s.overwrite(info.loading.argStart, info.loading.argEnd, `${name}Loading`);
399
- s.overwrite(info.error.argStart, info.error.argEnd, `${name}Error`);
461
+ if (info.error) s.overwrite(info.error.argStart, info.error.argEnd, `${name}Error`);
400
462
  if (info.content.kind === "identifier") s.append(`\nexport {${info.content.name} as ${name}Content};\n`);
401
463
  else {
402
- s.appendLeft(info.hocExportStart, `const ${name}Content = ${info.content.argSource};\n\n`);
464
+ const contentSource = verifiedUsages.length > 0 ? renderInlineContent(info.content, verifiedUsages) : info.content.argSource;
465
+ s.appendLeft(info.hocExportStart, `const ${name}Content = ${contentSource};\n\n`);
403
466
  s.overwrite(info.content.argStart, info.content.argEnd, `${name}Content`);
404
467
  s.append(`\nexport {${name}Content};\n`);
405
468
  }
406
469
  }
407
- 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}`);
470
+ function renderInlineContent(content, usages) {
471
+ const s = new magic_string.default(content.argSource);
472
+ for (const { usage } of usages) for (const access of usage.accesses) if (isAccessInsideArg(content, access)) s.overwrite(access.start - content.argStart, access.end - content.argStart, `${usage.spec.localName}${access.prop}`);
473
+ return s.toString();
474
+ }
475
+ function transformUsages(s, usages, info) {
476
+ const inlineContent = info?.content.kind === "inline" ? info.content : null;
477
+ for (const { usage } of usages) for (const access of usage.accesses) {
478
+ if (inlineContent && isAccessInsideArg(inlineContent, access)) continue;
479
+ s.overwrite(access.start, access.end, `${usage.spec.localName}${access.prop}`);
480
+ }
409
481
  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)));
482
+ for (const { usage, hocImportSource, hocExportedName } of usages) {
483
+ const propsUsed = new Set(usage.accesses.map((access) => access.prop));
484
+ for (const prop of propsUsed) newImports.push(renderNamedImport(`${usage.spec.localName}${prop}`, `${hocExportedName}${prop}`, makeCompanionId(COMPANION_TYPE_BY_SUFFIX[prop], hocImportSource)));
413
485
  }
414
486
  if (newImports.length > 0) s.prepend(newImports.join("\n") + "\n");
415
487
  const localsByDecl = /* @__PURE__ */ new Map();
416
- for (const usage of usages) {
488
+ for (const { usage } of usages) {
417
489
  if (usage.hasOtherUsages) continue;
418
490
  let locals = localsByDecl.get(usage.decl);
419
491
  if (!locals) localsByDecl.set(usage.decl, locals = /* @__PURE__ */ new Set());
@@ -440,13 +512,20 @@ function renderNamedImport(local, imported, source) {
440
512
  }
441
513
  //#endregion
442
514
  //#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
- }];
515
+ const DEFAULT_HOCS = [
516
+ {
517
+ from: "@gravity-ui/data-source",
518
+ name: "withAsync"
519
+ },
520
+ {
521
+ from: "@gravity-ui/data-source",
522
+ name: "withAsyncBoundary"
523
+ },
524
+ {
525
+ from: "@gravity-ui/data-source",
526
+ name: "withQueryAsyncBoundary"
527
+ }
528
+ ];
450
529
  const DEFAULT_INCLUDE = /\.(tsx?|jsx?)$/;
451
530
  const VIRTUAL_EXCLUDE = new RegExp(`${VIRTUAL_PREFIX}|${encodeURIComponent(VIRTUAL_PREFIX)}`);
452
531
  const dataSourceLazyUnpluginFactory = (options = {}) => {
@@ -458,6 +537,7 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
458
537
  const hocsSet = new Set(hocPatterns.map((pattern) => getHocString(pattern.from, pattern.name)));
459
538
  const hocsRegexp = new RegExp(Array.from(new Set(hocPatterns.map((pattern) => pattern.name))).map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"));
460
539
  const hocInfoCache = /* @__PURE__ */ new Map();
540
+ const reExportsCache = /* @__PURE__ */ new Map();
461
541
  const getHocInfo = (sourceFile, source) => {
462
542
  const key = stripQuery(sourceFile);
463
543
  const cachedInfo = hocInfoCache.get(key);
@@ -467,6 +547,53 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
467
547
  hocInfoCache.set(key, info);
468
548
  return info;
469
549
  };
550
+ const getReExports = (sourceFile, source) => {
551
+ const key = stripQuery(sourceFile);
552
+ const cachedReExports = reExportsCache.get(key);
553
+ if (cachedReExports) return cachedReExports;
554
+ const reExports = extractReExports(key, source ?? node_fs.default.readFileSync(key, "utf-8"));
555
+ reExportsCache.set(key, reExports);
556
+ return reExports;
557
+ };
558
+ const resolveHocSourceFile = async (ctx, file, importedName, visited = /* @__PURE__ */ new Set()) => {
559
+ const visitKey = `${file}\0${importedName}`;
560
+ if (visited.has(visitKey)) return null;
561
+ visited.add(visitKey);
562
+ const directInfo = getHocInfo(file);
563
+ if (directInfo && directInfo.exportedName === importedName) return {
564
+ file,
565
+ info: directInfo
566
+ };
567
+ const reExports = getReExports(file);
568
+ const named = reExports.named.get(importedName);
569
+ if (named) {
570
+ const resolved = await resolveSourceFile(ctx, named.source, file);
571
+ if (resolved) {
572
+ const next = await resolveHocSourceFile(ctx, resolved, named.importedName, visited);
573
+ if (next) return next;
574
+ }
575
+ }
576
+ for (const starSource of reExports.stars) {
577
+ const resolved = await resolveSourceFile(ctx, starSource, file);
578
+ if (!resolved) continue;
579
+ const next = await resolveHocSourceFile(ctx, resolved, importedName, visited);
580
+ if (next) return next;
581
+ }
582
+ return null;
583
+ };
584
+ const verifyUsages = async (ctx, usages, importerId) => {
585
+ return (await Promise.all(usages.map(async (usage) => {
586
+ const resolvedSourceFile = await resolveSourceFile(ctx, usage.decl.source, importerId);
587
+ if (!resolvedSourceFile) return null;
588
+ const target = await resolveHocSourceFile(ctx, resolvedSourceFile, usage.spec.importedName);
589
+ if (!target) return null;
590
+ return {
591
+ usage,
592
+ hocImportSource: toRelativeImportSource(importerId, target.file),
593
+ hocExportedName: target.info.exportedName
594
+ };
595
+ }))).filter((usage) => usage !== null);
596
+ };
470
597
  return {
471
598
  name: "data-source-lazy",
472
599
  enforce: "pre",
@@ -485,18 +612,29 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
485
612
  },
486
613
  load: {
487
614
  filter: { id: new RegExp(VIRTUAL_PREFIX) },
488
- handler(id) {
615
+ async handler(id) {
489
616
  const parsedId = parseVirtualId(id);
490
617
  if (!parsedId) return null;
491
618
  this.addWatchFile(parsedId.sourceFile);
492
619
  const info = getHocInfo(parsedId.sourceFile);
493
620
  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);
621
+ if (parsedId.type === "loading" || parsedId.type === "error") {
622
+ const auxInfo = info[parsedId.type];
623
+ if (!auxInfo) return null;
624
+ const filename = makeCompanionId(parsedId.type, parsedId.sourceFile);
625
+ const code = generateAuxModuleCode(info.exportedName, auxInfo, parsedId.type);
626
+ const usages = extractUsages(filename, code);
627
+ const verifiedUsages = await verifyUsages(this, usages, parsedId.sourceFile);
628
+ let resultCode = code;
629
+ if (verifiedUsages.length > 0) {
630
+ const s = new magic_string.default(code);
631
+ transformUsages(s, verifiedUsages);
632
+ resultCode = s.toString();
633
+ }
634
+ return transformJsx(filename, resultCode, options.generateOptions);
499
635
  }
636
+ if (parsedId.type === "lazy") return generateLazyModule(parsedId.sourceFile, info, options.generateOptions);
637
+ return assertNever(parsedId.type);
500
638
  }
501
639
  },
502
640
  transform: {
@@ -508,17 +646,12 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
508
646
  const info = getHocInfo(id, code);
509
647
  const usages = extractUsages(id, code);
510
648
  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);
649
+ const filteredUsages = info ? dropAccessesInsideHocArgs(info, usages) : usages;
650
+ const verifiedUsages = await verifyUsages(this, filteredUsages, id);
518
651
  if (!info && verifiedUsages.length === 0) return null;
519
652
  const s = new magic_string.default(code);
520
- if (info) transformDefinitionModule(s, id, info);
521
- if (verifiedUsages.length > 0) transformUsages(s, verifiedUsages);
653
+ if (info) transformDefinitionModule(s, id, info, verifiedUsages);
654
+ if (verifiedUsages.length > 0) transformUsages(s, verifiedUsages, info);
522
655
  if (!s.hasChanged()) return null;
523
656
  return {
524
657
  code: s.toString(),
@@ -530,10 +663,28 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
530
663
  }
531
664
  },
532
665
  watchChange(id) {
533
- hocInfoCache.delete(stripQuery(id));
666
+ const key = stripQuery(id);
667
+ hocInfoCache.delete(key);
668
+ reExportsCache.delete(key);
534
669
  }
535
670
  };
536
671
  };
672
+ function dropAccessesInsideHocArgs(info, usages) {
673
+ const result = [];
674
+ for (const usage of usages) {
675
+ const accesses = usage.accesses.filter((access) => !isAccessInsideArg(info.loading, access) && !(info.error && isAccessInsideArg(info.error, access)));
676
+ if (accesses.length === 0) continue;
677
+ if (accesses.length === usage.accesses.length) {
678
+ result.push(usage);
679
+ continue;
680
+ }
681
+ result.push({
682
+ ...usage,
683
+ accesses
684
+ });
685
+ }
686
+ return result;
687
+ }
537
688
  //#endregion
538
689
  Object.defineProperty(exports, "DEFAULT_HOCS", {
539
690
  enumerable: true,
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_factory = require("./factory-Cdmba_F_.cjs");
5
+ const require_factory = require("./factory-TMKD3PiJ.cjs");
6
6
  //#region src/plugin/index.ts
7
7
  const DataSourceLazyPlugin = /* @__PURE__ */ (0, require("unplugin").createUnplugin)(require_factory.dataSourceLazyUnpluginFactory);
8
8
  //#endregion
@@ -1,4 +1,4 @@
1
- import { n as dataSourceLazyUnpluginFactory, t as DEFAULT_HOCS } from "./factory-2tSt4Rte.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory, t as DEFAULT_HOCS } from "./factory-BdwLvQEp.mjs";
2
2
  import { createUnplugin } from "unplugin";
3
3
  //#region src/plugin/index.ts
4
4
  const DataSourceLazyPlugin = /* @__PURE__ */ createUnplugin(dataSourceLazyUnpluginFactory);
@@ -1,4 +1,4 @@
1
- const require_factory = require("./factory-Cdmba_F_.cjs");
1
+ const require_factory = require("./factory-TMKD3PiJ.cjs");
2
2
  //#region src/plugin/rollup.ts
3
3
  var rollup_default = (0, require("unplugin").createRollupPlugin)(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-BdwLvQEp.mjs";
2
2
  import { createRollupPlugin } from "unplugin";
3
3
  //#region src/plugin/rollup.ts
4
4
  var rollup_default = createRollupPlugin(dataSourceLazyUnpluginFactory);
@@ -1,4 +1,4 @@
1
- const require_factory = require("./factory-Cdmba_F_.cjs");
1
+ const require_factory = require("./factory-TMKD3PiJ.cjs");
2
2
  //#region src/plugin/rspack.ts
3
3
  var rspack_default = (0, require("unplugin").createRspackPlugin)(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-BdwLvQEp.mjs";
2
2
  import { createRspackPlugin } from "unplugin";
3
3
  //#region src/plugin/rspack.ts
4
4
  var rspack_default = createRspackPlugin(dataSourceLazyUnpluginFactory);
@@ -1,11 +1,23 @@
1
1
  import type {ComponentType} from 'react';
2
2
 
3
3
  declare module '@gravity-ui/data-source' {
4
- interface AsyncBoundaryComponent<TProps extends object> {
5
- Lazy: ComponentType<TProps>;
4
+ interface AsyncComponent<TProps extends object = {}, TLoadingProps extends object = {}> {
5
+ Lazy: ComponentType<TProps & TLoadingProps>;
6
6
  }
7
7
 
8
- interface QueryAsyncBoundaryComponent<TProps extends object> {
9
- Lazy: ComponentType<TProps>;
8
+ interface AsyncBoundaryComponent<
9
+ TProps extends object = {},
10
+ TLoadingProps extends object = {},
11
+ TErrorProps extends object = {},
12
+ > {
13
+ Lazy: ComponentType<TProps & TLoadingProps & Omit<TErrorProps, keyof ErrorViewProps>>;
14
+ }
15
+
16
+ interface QueryAsyncBoundaryComponent<
17
+ TProps extends object = {},
18
+ TLoadingProps extends object = {},
19
+ TErrorProps extends object = {},
20
+ > {
21
+ Lazy: ComponentType<TProps & TLoadingProps & Omit<TErrorProps, keyof ErrorViewProps>>;
10
22
  }
11
23
  }
@@ -1,4 +1,4 @@
1
- const require_factory = require("./factory-Cdmba_F_.cjs");
1
+ const require_factory = require("./factory-TMKD3PiJ.cjs");
2
2
  //#region src/plugin/vite.ts
3
3
  var vite_default = (0, require("unplugin").createVitePlugin)(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-BdwLvQEp.mjs";
2
2
  import { createVitePlugin } from "unplugin";
3
3
  //#region src/plugin/vite.ts
4
4
  var vite_default = createVitePlugin(dataSourceLazyUnpluginFactory);
@@ -1,4 +1,4 @@
1
- const require_factory = require("./factory-Cdmba_F_.cjs");
1
+ const require_factory = require("./factory-TMKD3PiJ.cjs");
2
2
  //#region src/plugin/webpack.ts
3
3
  var webpack_default = (0, require("unplugin").createWebpackPlugin)(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-BdwLvQEp.mjs";
2
2
  import { createWebpackPlugin } from "unplugin";
3
3
  //#region src/plugin/webpack.ts
4
4
  var webpack_default = createWebpackPlugin(dataSourceLazyUnpluginFactory);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/data-source",
3
- "version": "0.10.0-alpha.1",
3
+ "version": "0.10.0-alpha.11",
4
4
  "description": "A wrapper around data fetching",
5
5
  "keywords": [
6
6
  "data-fetching",
@@ -24,9 +24,6 @@
24
24
  "yarn": "Please use npm instead of yarn to install dependencies",
25
25
  "pnpm": "Please use npm instead of pnpm to install dependencies"
26
26
  },
27
- "main": "build/cjs/index.js",
28
- "module": "build/esm/index.js",
29
- "types": "build/esm/index.d.ts",
30
27
  "exports": {
31
28
  ".": {
32
29
  "types": "./build/esm/index.d.ts",