@gravity-ui/data-source 0.10.0-alpha.5 → 0.10.0-alpha.6

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.
@@ -1,4 +1,4 @@
1
- const require_factory = require("./factory-CmOH3Kh6.cjs");
1
+ const require_factory = require("./factory-CIwgQy1N.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--H-amlua.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-C-n_7Tjo.mjs";
2
2
  import { createEsbuildPlugin } from "unplugin";
3
3
  //#region src/plugin/esbuild.ts
4
4
  var esbuild_default = createEsbuildPlugin(dataSourceLazyUnpluginFactory);
@@ -131,6 +131,59 @@ function extractHocInfo(hocsSet, filename, source) {
131
131
  }
132
132
  return null;
133
133
  }
134
+ function extractReExports(filename, source) {
135
+ const named = /* @__PURE__ */ new Map();
136
+ const stars = [];
137
+ const program = parseProgram(filename, source);
138
+ if (!program) return {
139
+ named,
140
+ stars
141
+ };
142
+ const localImports = /* @__PURE__ */ new Map();
143
+ for (const node of program.body) {
144
+ if (node.type !== "ImportDeclaration" || node.importKind === "type") continue;
145
+ for (const spec of node.specifiers) {
146
+ if (spec.type !== "ImportSpecifier" || spec.importKind === "type") continue;
147
+ const importedName = spec.imported.type === "Literal" ? spec.imported.value : spec.imported.name;
148
+ localImports.set(spec.local.name, {
149
+ source: node.source.value,
150
+ importedName
151
+ });
152
+ }
153
+ }
154
+ for (const node of program.body) {
155
+ if (node.type === "ExportAllDeclaration" && node.exportKind !== "type" && !node.exported) {
156
+ stars.push(node.source.value);
157
+ continue;
158
+ }
159
+ if (node.type !== "ExportNamedDeclaration" || node.exportKind === "type") continue;
160
+ if (node.source) {
161
+ const src = node.source.value;
162
+ for (const spec of node.specifiers) {
163
+ if (spec.exportKind === "type") continue;
164
+ const localName = spec.local.type === "Literal" ? spec.local.value : spec.local.name;
165
+ const exportedName = spec.exported.type === "Literal" ? spec.exported.value : spec.exported.name;
166
+ named.set(exportedName, {
167
+ source: src,
168
+ importedName: localName
169
+ });
170
+ }
171
+ continue;
172
+ }
173
+ if (node.declaration) continue;
174
+ for (const spec of node.specifiers) {
175
+ if (spec.exportKind === "type" || spec.local.type === "Literal") continue;
176
+ const target = localImports.get(spec.local.name);
177
+ if (!target) continue;
178
+ const exportedName = spec.exported.type === "Literal" ? spec.exported.value : spec.exported.name;
179
+ named.set(exportedName, target);
180
+ }
181
+ }
182
+ return {
183
+ named,
184
+ stars
185
+ };
186
+ }
134
187
  const COMPANION_PROPS_RE = new RegExp(`\\.(${Object.values(COMPANION_TYPES).join("|")})\\b`);
135
188
  function extractUsages(filename, source) {
136
189
  const result = [];
@@ -381,15 +434,15 @@ function transformDefinitionModule(s, filename, info) {
381
434
  }
382
435
  }
383
436
  function transformUsages(s, usages) {
384
- for (const { spec, accesses } of usages) for (const access of accesses) s.overwrite(access.start, access.end, `${spec.localName}${access.prop}`);
437
+ for (const { usage } of usages) for (const access of usage.accesses) s.overwrite(access.start, access.end, `${usage.spec.localName}${access.prop}`);
385
438
  const newImports = [];
386
- for (const { decl, spec, accesses } of usages) {
387
- const propsUsed = new Set(accesses.map((access) => access.prop));
388
- for (const prop of propsUsed) newImports.push(renderNamedImport(`${spec.localName}${prop}`, `${spec.importedName}${prop}`, makeCompanionId(COMPANION_TYPE_BY_SUFFIX[prop], decl.source)));
439
+ for (const { usage, hocSourceFile, hocExportedName } of usages) {
440
+ const propsUsed = new Set(usage.accesses.map((access) => access.prop));
441
+ for (const prop of propsUsed) newImports.push(renderNamedImport(`${usage.spec.localName}${prop}`, `${hocExportedName}${prop}`, makeCompanionId(COMPANION_TYPE_BY_SUFFIX[prop], hocSourceFile)));
389
442
  }
390
443
  if (newImports.length > 0) s.prepend(newImports.join("\n") + "\n");
391
444
  const localsByDecl = /* @__PURE__ */ new Map();
392
- for (const usage of usages) {
445
+ for (const { usage } of usages) {
393
446
  if (usage.hasOtherUsages) continue;
394
447
  let locals = localsByDecl.get(usage.decl);
395
448
  if (!locals) localsByDecl.set(usage.decl, locals = /* @__PURE__ */ new Set());
@@ -434,6 +487,7 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
434
487
  const hocsSet = new Set(hocPatterns.map((pattern) => getHocString(pattern.from, pattern.name)));
435
488
  const hocsRegexp = new RegExp(Array.from(new Set(hocPatterns.map((pattern) => pattern.name))).map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"));
436
489
  const hocInfoCache = /* @__PURE__ */ new Map();
490
+ const reExportsCache = /* @__PURE__ */ new Map();
437
491
  const getHocInfo = (sourceFile, source) => {
438
492
  const key = stripQuery(sourceFile);
439
493
  const cachedInfo = hocInfoCache.get(key);
@@ -443,6 +497,14 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
443
497
  hocInfoCache.set(key, info);
444
498
  return info;
445
499
  };
500
+ const getReExports = (sourceFile, source) => {
501
+ const key = stripQuery(sourceFile);
502
+ const cachedReExports = reExportsCache.get(key);
503
+ if (cachedReExports) return cachedReExports;
504
+ const reExports = extractReExports(key, source ?? fs.readFileSync(key, "utf-8"));
505
+ reExportsCache.set(key, reExports);
506
+ return reExports;
507
+ };
446
508
  return {
447
509
  name: "data-source-lazy",
448
510
  enforce: "pre",
@@ -485,12 +547,42 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
485
547
  const usages = extractUsages(id, code);
486
548
  if (!info && usages.length === 0) return null;
487
549
  const filteredUsages = info ? dropAccessesInsideHocArgs(info, usages) : usages;
550
+ const resolveHocSourceFile = async (file, importedName, visited = /* @__PURE__ */ new Set()) => {
551
+ const visitKey = `${file}\0${importedName}`;
552
+ if (visited.has(visitKey)) return null;
553
+ visited.add(visitKey);
554
+ const directInfo = getHocInfo(file);
555
+ if (directInfo && directInfo.exportedName === importedName) return {
556
+ file,
557
+ info: directInfo
558
+ };
559
+ const reExports = getReExports(file);
560
+ const named = reExports.named.get(importedName);
561
+ if (named) {
562
+ const resolved = await resolveSourceFile(this, named.source, file);
563
+ if (resolved) {
564
+ const next = await resolveHocSourceFile(resolved, named.importedName, visited);
565
+ if (next) return next;
566
+ }
567
+ }
568
+ for (const starSource of reExports.stars) {
569
+ const resolved = await resolveSourceFile(this, starSource, file);
570
+ if (!resolved) continue;
571
+ const next = await resolveHocSourceFile(resolved, importedName, visited);
572
+ if (next) return next;
573
+ }
574
+ return null;
575
+ };
488
576
  const verifiedUsages = (await Promise.all(filteredUsages.map(async (usage) => {
489
577
  const resolvedSourceFile = await resolveSourceFile(this, usage.decl.source, id);
490
578
  if (!resolvedSourceFile) return null;
491
- const usageInfo = getHocInfo(resolvedSourceFile);
492
- if (!usageInfo || usageInfo.exportedName !== usage.spec.importedName) return null;
493
- return usage;
579
+ const target = await resolveHocSourceFile(resolvedSourceFile, usage.spec.importedName);
580
+ if (!target) return null;
581
+ return {
582
+ usage,
583
+ hocSourceFile: target.file,
584
+ hocExportedName: target.info.exportedName
585
+ };
494
586
  }))).filter((usage) => usage !== null);
495
587
  if (!info && verifiedUsages.length === 0) return null;
496
588
  const s = new MagicString(code);
@@ -507,7 +599,9 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
507
599
  }
508
600
  },
509
601
  watchChange(id) {
510
- hocInfoCache.delete(stripQuery(id));
602
+ const key = stripQuery(id);
603
+ hocInfoCache.delete(key);
604
+ reExportsCache.delete(key);
511
605
  }
512
606
  };
513
607
  };
@@ -156,6 +156,59 @@ function extractHocInfo(hocsSet, filename, source) {
156
156
  }
157
157
  return null;
158
158
  }
159
+ function extractReExports(filename, source) {
160
+ const named = /* @__PURE__ */ new Map();
161
+ const stars = [];
162
+ const program = parseProgram(filename, source);
163
+ if (!program) return {
164
+ named,
165
+ stars
166
+ };
167
+ const localImports = /* @__PURE__ */ new Map();
168
+ for (const node of program.body) {
169
+ if (node.type !== "ImportDeclaration" || node.importKind === "type") continue;
170
+ for (const spec of node.specifiers) {
171
+ if (spec.type !== "ImportSpecifier" || spec.importKind === "type") continue;
172
+ const importedName = spec.imported.type === "Literal" ? spec.imported.value : spec.imported.name;
173
+ localImports.set(spec.local.name, {
174
+ source: node.source.value,
175
+ importedName
176
+ });
177
+ }
178
+ }
179
+ for (const node of program.body) {
180
+ if (node.type === "ExportAllDeclaration" && node.exportKind !== "type" && !node.exported) {
181
+ stars.push(node.source.value);
182
+ continue;
183
+ }
184
+ if (node.type !== "ExportNamedDeclaration" || node.exportKind === "type") continue;
185
+ if (node.source) {
186
+ const src = node.source.value;
187
+ for (const spec of node.specifiers) {
188
+ if (spec.exportKind === "type") continue;
189
+ const localName = spec.local.type === "Literal" ? spec.local.value : spec.local.name;
190
+ const exportedName = spec.exported.type === "Literal" ? spec.exported.value : spec.exported.name;
191
+ named.set(exportedName, {
192
+ source: src,
193
+ importedName: localName
194
+ });
195
+ }
196
+ continue;
197
+ }
198
+ if (node.declaration) continue;
199
+ for (const spec of node.specifiers) {
200
+ if (spec.exportKind === "type" || spec.local.type === "Literal") continue;
201
+ const target = localImports.get(spec.local.name);
202
+ if (!target) continue;
203
+ const exportedName = spec.exported.type === "Literal" ? spec.exported.value : spec.exported.name;
204
+ named.set(exportedName, target);
205
+ }
206
+ }
207
+ return {
208
+ named,
209
+ stars
210
+ };
211
+ }
159
212
  const COMPANION_PROPS_RE = new RegExp(`\\.(${Object.values(COMPANION_TYPES).join("|")})\\b`);
160
213
  function extractUsages(filename, source) {
161
214
  const result = [];
@@ -406,15 +459,15 @@ function transformDefinitionModule(s, filename, info) {
406
459
  }
407
460
  }
408
461
  function transformUsages(s, usages) {
409
- for (const { spec, accesses } of usages) for (const access of accesses) s.overwrite(access.start, access.end, `${spec.localName}${access.prop}`);
462
+ for (const { usage } of usages) for (const access of usage.accesses) s.overwrite(access.start, access.end, `${usage.spec.localName}${access.prop}`);
410
463
  const newImports = [];
411
- for (const { decl, spec, accesses } of usages) {
412
- const propsUsed = new Set(accesses.map((access) => access.prop));
413
- for (const prop of propsUsed) newImports.push(renderNamedImport(`${spec.localName}${prop}`, `${spec.importedName}${prop}`, makeCompanionId(COMPANION_TYPE_BY_SUFFIX[prop], decl.source)));
464
+ for (const { usage, hocSourceFile, hocExportedName } of usages) {
465
+ const propsUsed = new Set(usage.accesses.map((access) => access.prop));
466
+ for (const prop of propsUsed) newImports.push(renderNamedImport(`${usage.spec.localName}${prop}`, `${hocExportedName}${prop}`, makeCompanionId(COMPANION_TYPE_BY_SUFFIX[prop], hocSourceFile)));
414
467
  }
415
468
  if (newImports.length > 0) s.prepend(newImports.join("\n") + "\n");
416
469
  const localsByDecl = /* @__PURE__ */ new Map();
417
- for (const usage of usages) {
470
+ for (const { usage } of usages) {
418
471
  if (usage.hasOtherUsages) continue;
419
472
  let locals = localsByDecl.get(usage.decl);
420
473
  if (!locals) localsByDecl.set(usage.decl, locals = /* @__PURE__ */ new Set());
@@ -459,6 +512,7 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
459
512
  const hocsSet = new Set(hocPatterns.map((pattern) => getHocString(pattern.from, pattern.name)));
460
513
  const hocsRegexp = new RegExp(Array.from(new Set(hocPatterns.map((pattern) => pattern.name))).map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"));
461
514
  const hocInfoCache = /* @__PURE__ */ new Map();
515
+ const reExportsCache = /* @__PURE__ */ new Map();
462
516
  const getHocInfo = (sourceFile, source) => {
463
517
  const key = stripQuery(sourceFile);
464
518
  const cachedInfo = hocInfoCache.get(key);
@@ -468,6 +522,14 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
468
522
  hocInfoCache.set(key, info);
469
523
  return info;
470
524
  };
525
+ const getReExports = (sourceFile, source) => {
526
+ const key = stripQuery(sourceFile);
527
+ const cachedReExports = reExportsCache.get(key);
528
+ if (cachedReExports) return cachedReExports;
529
+ const reExports = extractReExports(key, source ?? node_fs.default.readFileSync(key, "utf-8"));
530
+ reExportsCache.set(key, reExports);
531
+ return reExports;
532
+ };
471
533
  return {
472
534
  name: "data-source-lazy",
473
535
  enforce: "pre",
@@ -510,12 +572,42 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
510
572
  const usages = extractUsages(id, code);
511
573
  if (!info && usages.length === 0) return null;
512
574
  const filteredUsages = info ? dropAccessesInsideHocArgs(info, usages) : usages;
575
+ const resolveHocSourceFile = async (file, importedName, visited = /* @__PURE__ */ new Set()) => {
576
+ const visitKey = `${file}\0${importedName}`;
577
+ if (visited.has(visitKey)) return null;
578
+ visited.add(visitKey);
579
+ const directInfo = getHocInfo(file);
580
+ if (directInfo && directInfo.exportedName === importedName) return {
581
+ file,
582
+ info: directInfo
583
+ };
584
+ const reExports = getReExports(file);
585
+ const named = reExports.named.get(importedName);
586
+ if (named) {
587
+ const resolved = await resolveSourceFile(this, named.source, file);
588
+ if (resolved) {
589
+ const next = await resolveHocSourceFile(resolved, named.importedName, visited);
590
+ if (next) return next;
591
+ }
592
+ }
593
+ for (const starSource of reExports.stars) {
594
+ const resolved = await resolveSourceFile(this, starSource, file);
595
+ if (!resolved) continue;
596
+ const next = await resolveHocSourceFile(resolved, importedName, visited);
597
+ if (next) return next;
598
+ }
599
+ return null;
600
+ };
513
601
  const verifiedUsages = (await Promise.all(filteredUsages.map(async (usage) => {
514
602
  const resolvedSourceFile = await resolveSourceFile(this, usage.decl.source, id);
515
603
  if (!resolvedSourceFile) return null;
516
- const usageInfo = getHocInfo(resolvedSourceFile);
517
- if (!usageInfo || usageInfo.exportedName !== usage.spec.importedName) return null;
518
- return usage;
604
+ const target = await resolveHocSourceFile(resolvedSourceFile, usage.spec.importedName);
605
+ if (!target) return null;
606
+ return {
607
+ usage,
608
+ hocSourceFile: target.file,
609
+ hocExportedName: target.info.exportedName
610
+ };
519
611
  }))).filter((usage) => usage !== null);
520
612
  if (!info && verifiedUsages.length === 0) return null;
521
613
  const s = new magic_string.default(code);
@@ -532,7 +624,9 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
532
624
  }
533
625
  },
534
626
  watchChange(id) {
535
- hocInfoCache.delete(stripQuery(id));
627
+ const key = stripQuery(id);
628
+ hocInfoCache.delete(key);
629
+ reExportsCache.delete(key);
536
630
  }
537
631
  };
538
632
  };
@@ -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-CmOH3Kh6.cjs");
5
+ const require_factory = require("./factory-CIwgQy1N.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--H-amlua.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory, t as DEFAULT_HOCS } from "./factory-C-n_7Tjo.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-CmOH3Kh6.cjs");
1
+ const require_factory = require("./factory-CIwgQy1N.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--H-amlua.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-C-n_7Tjo.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-CmOH3Kh6.cjs");
1
+ const require_factory = require("./factory-CIwgQy1N.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--H-amlua.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-C-n_7Tjo.mjs";
2
2
  import { createRspackPlugin } from "unplugin";
3
3
  //#region src/plugin/rspack.ts
4
4
  var rspack_default = createRspackPlugin(dataSourceLazyUnpluginFactory);
@@ -1,4 +1,4 @@
1
- const require_factory = require("./factory-CmOH3Kh6.cjs");
1
+ const require_factory = require("./factory-CIwgQy1N.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--H-amlua.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-C-n_7Tjo.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-CmOH3Kh6.cjs");
1
+ const require_factory = require("./factory-CIwgQy1N.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--H-amlua.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-C-n_7Tjo.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.5",
3
+ "version": "0.10.0-alpha.6",
4
4
  "description": "A wrapper around data fetching",
5
5
  "keywords": [
6
6
  "data-fetching",