@gravity-ui/data-source 0.10.0-alpha.7 → 0.10.0-alpha.8

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-Dq6kUGl-.cjs");
1
+ const require_factory = require("./factory-GDKkqVwg.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-Ds3_-8kv.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-Dwr-yuOT.mjs";
2
2
  import { createEsbuildPlugin } from "unplugin";
3
3
  //#region src/plugin/esbuild.ts
4
4
  var esbuild_default = createEsbuildPlugin(dataSourceLazyUnpluginFactory);
@@ -102,7 +102,7 @@ function extractHocInfo(hocsSet, filename, source) {
102
102
  for (const node of program.body) {
103
103
  if (node.type !== "ExportNamedDeclaration" || node.exportKind === "type" || node.declaration?.type !== "VariableDeclaration") continue;
104
104
  for (const decl of node.declaration.declarations) {
105
- if (decl.id.type !== "Identifier" || !decl.init || decl.init.type !== "CallExpression" || decl.init.callee.type !== "Identifier" || decl.init.arguments.length !== 3) continue;
105
+ if (decl.id.type !== "Identifier" || !decl.init || decl.init.type !== "CallExpression" || decl.init.callee.type !== "Identifier" || decl.init.arguments.length < 2) continue;
106
106
  const hocEntry = trackedHocs.get(decl.init.callee.name);
107
107
  if (!hocEntry) continue;
108
108
  const [contentArg, loadingArg, errorArg] = decl.init.arguments;
@@ -128,12 +128,12 @@ function extractHocInfo(hocsSet, filename, source) {
128
128
  argEnd: loadingArg.end,
129
129
  imports: filterNeededImports(importDecls, collectIdentifiers(loadingArg))
130
130
  },
131
- error: {
131
+ error: errorArg ? {
132
132
  argSource: source.slice(errorArg.start, errorArg.end),
133
133
  argStart: errorArg.start,
134
134
  argEnd: errorArg.end,
135
135
  imports: filterNeededImports(importDecls, collectIdentifiers(errorArg))
136
- }
136
+ } : null
137
137
  };
138
138
  }
139
139
  }
@@ -318,15 +318,13 @@ function parseProgram(filename, source) {
318
318
  }
319
319
  //#endregion
320
320
  //#region src/plugin/core/generate.ts
321
- function generateAuxModule(sourceFile, info, type, options = {}) {
322
- const auxInfo = info[type];
323
- const name = info.exportedName;
321
+ function generateAuxModule(sourceFile, exportedName, info, type, options = {}) {
324
322
  const suffix = COMPANION_TYPES[type];
325
323
  const cleanSourceFile = stripQuery(sourceFile);
326
324
  const code = [
327
- renderImports(auxInfo.imports),
325
+ renderImports(info.imports),
328
326
  "",
329
- `export const ${name}${suffix} = ${auxInfo.argSource};`,
327
+ `export const ${exportedName}${suffix} = ${info.argSource};`,
330
328
  ""
331
329
  ].join("\n").trimStart();
332
330
  return transformJsx(makeCompanionId(type, cleanSourceFile), code, options);
@@ -336,21 +334,19 @@ function generateLazyModule(sourceFile, info, options = {}) {
336
334
  const name = info.exportedName;
337
335
  const cleanSourceFile = stripQuery(sourceFile);
338
336
  const base = `./${path.basename(cleanSourceFile, path.extname(cleanSourceFile))}`;
339
- const code = [
337
+ const hocBinding = info.hocImportedName === "default" ? info.hocLocalName : info.hocImportedName;
338
+ const lines = [
340
339
  `import {lazy} from '${importSource}';`,
341
340
  "",
342
341
  info.hocImportedName === "default" ? `import ${info.hocLocalName} from '${info.hocImportSource}';` : `import {${info.hocImportedName}} from '${info.hocImportSource}';`,
343
342
  "",
344
- `import {${name}Loading} from '${base}.Loading';`,
345
- `import {${name}Error} from '${base}.Error';`,
346
- ``,
347
- `export const ${name}Lazy = ${info.hocImportedName === "default" ? info.hocLocalName : info.hocImportedName}(`,
348
- ` lazy(() => import('${base}').then((m) => ({default: m.${name}Content}))),`,
349
- ` ${name}Loading,`,
350
- ` ${name}Error,`,
351
- `);`,
352
- ``
353
- ].join("\n");
343
+ `import {${name}Loading} from '${base}.Loading';`
344
+ ];
345
+ if (info.error) lines.push(`import {${name}Error} from '${base}.Error';`);
346
+ lines.push("", `export const ${name}Lazy = ${hocBinding}(`, ` lazy(() => import('${base}').then((m) => ({default: m.${name}Content}))),`, ` ${name}Loading,`);
347
+ if (info.error) lines.push(` ${name}Error,`);
348
+ lines.push(`);`, ``);
349
+ const code = lines.join("\n");
354
350
  const filename = makeCompanionId("lazy", cleanSourceFile);
355
351
  return {
356
352
  code,
@@ -431,9 +427,11 @@ function transformDefinitionModule(s, filename, info) {
431
427
  const name = info.exportedName;
432
428
  const cleanFilename = stripQuery(filename);
433
429
  const localSource = `./${path.basename(cleanFilename, path.extname(cleanFilename))}`;
434
- s.prepend(`${renderNamedImport(`${name}Loading`, `${name}Loading`, makeCompanionId("loading", localSource))}\n${renderNamedImport(`${name}Error`, `${name}Error`, makeCompanionId("error", localSource))}\n`);
430
+ const prependImports = [renderNamedImport(`${name}Loading`, `${name}Loading`, makeCompanionId("loading", localSource))];
431
+ if (info.error) prependImports.push(renderNamedImport(`${name}Error`, `${name}Error`, makeCompanionId("error", localSource)));
432
+ s.prepend(prependImports.join("\n") + "\n");
435
433
  s.overwrite(info.loading.argStart, info.loading.argEnd, `${name}Loading`);
436
- s.overwrite(info.error.argStart, info.error.argEnd, `${name}Error`);
434
+ if (info.error) s.overwrite(info.error.argStart, info.error.argEnd, `${name}Error`);
437
435
  if (info.content.kind === "identifier") s.append(`\nexport {${info.content.name} as ${name}Content};\n`);
438
436
  else {
439
437
  s.appendLeft(info.hocExportStart, `const ${name}Content = ${info.content.argSource};\n\n`);
@@ -477,13 +475,20 @@ function renderNamedImport(local, imported, source) {
477
475
  }
478
476
  //#endregion
479
477
  //#region src/plugin/core/factory.ts
480
- const DEFAULT_HOCS = [{
481
- from: "@gravity-ui/data-source",
482
- name: "withAsyncBoundary"
483
- }, {
484
- from: "@gravity-ui/data-source",
485
- name: "withQueryAsyncBoundary"
486
- }];
478
+ const DEFAULT_HOCS = [
479
+ {
480
+ from: "@gravity-ui/data-source",
481
+ name: "withAsync"
482
+ },
483
+ {
484
+ from: "@gravity-ui/data-source",
485
+ name: "withAsyncBoundary"
486
+ },
487
+ {
488
+ from: "@gravity-ui/data-source",
489
+ name: "withQueryAsyncBoundary"
490
+ }
491
+ ];
487
492
  const DEFAULT_INCLUDE = /\.(tsx?|jsx?)$/;
488
493
  const VIRTUAL_EXCLUDE = new RegExp(`${VIRTUAL_PREFIX}|${encodeURIComponent(VIRTUAL_PREFIX)}`);
489
494
  const dataSourceLazyUnpluginFactory = (options = {}) => {
@@ -537,12 +542,13 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
537
542
  this.addWatchFile(parsedId.sourceFile);
538
543
  const info = getHocInfo(parsedId.sourceFile);
539
544
  if (!info) return null;
540
- switch (parsedId.type) {
541
- case "loading":
542
- case "error": return generateAuxModule(parsedId.sourceFile, info, parsedId.type, options.generateOptions);
543
- case "lazy": return generateLazyModule(parsedId.sourceFile, info, options.generateOptions);
544
- default: return assertNever(parsedId.type);
545
+ if (parsedId.type === "loading" || parsedId.type === "error") {
546
+ const auxInfo = info[parsedId.type];
547
+ if (!auxInfo) return null;
548
+ return generateAuxModule(parsedId.sourceFile, info.exportedName, auxInfo, parsedId.type, options.generateOptions);
545
549
  }
550
+ if (parsedId.type === "lazy") return generateLazyModule(parsedId.sourceFile, info, options.generateOptions);
551
+ return assertNever(parsedId.type);
546
552
  }
547
553
  },
548
554
  transform: {
@@ -619,7 +625,7 @@ function isInside(info, access) {
619
625
  function dropAccessesInsideHocArgs(info, usages) {
620
626
  const result = [];
621
627
  for (const usage of usages) {
622
- const accesses = usage.accesses.filter((access) => !isInside(info.loading, access) && !isInside(info.error, access) && !(info.content.kind === "inline" && isInside(info.content, access)));
628
+ const accesses = usage.accesses.filter((access) => !isInside(info.loading, access) && !(info.error && isInside(info.error, access)) && !(info.content.kind === "inline" && isInside(info.content, access)));
623
629
  if (accesses.length === 0) continue;
624
630
  if (accesses.length === usage.accesses.length) {
625
631
  result.push(usage);
@@ -127,7 +127,7 @@ function extractHocInfo(hocsSet, filename, source) {
127
127
  for (const node of program.body) {
128
128
  if (node.type !== "ExportNamedDeclaration" || node.exportKind === "type" || node.declaration?.type !== "VariableDeclaration") continue;
129
129
  for (const decl of node.declaration.declarations) {
130
- if (decl.id.type !== "Identifier" || !decl.init || decl.init.type !== "CallExpression" || decl.init.callee.type !== "Identifier" || decl.init.arguments.length !== 3) continue;
130
+ if (decl.id.type !== "Identifier" || !decl.init || decl.init.type !== "CallExpression" || decl.init.callee.type !== "Identifier" || decl.init.arguments.length < 2) continue;
131
131
  const hocEntry = trackedHocs.get(decl.init.callee.name);
132
132
  if (!hocEntry) continue;
133
133
  const [contentArg, loadingArg, errorArg] = decl.init.arguments;
@@ -153,12 +153,12 @@ function extractHocInfo(hocsSet, filename, source) {
153
153
  argEnd: loadingArg.end,
154
154
  imports: filterNeededImports(importDecls, collectIdentifiers(loadingArg))
155
155
  },
156
- error: {
156
+ error: errorArg ? {
157
157
  argSource: source.slice(errorArg.start, errorArg.end),
158
158
  argStart: errorArg.start,
159
159
  argEnd: errorArg.end,
160
160
  imports: filterNeededImports(importDecls, collectIdentifiers(errorArg))
161
- }
161
+ } : null
162
162
  };
163
163
  }
164
164
  }
@@ -343,15 +343,13 @@ function parseProgram(filename, source) {
343
343
  }
344
344
  //#endregion
345
345
  //#region src/plugin/core/generate.ts
346
- function generateAuxModule(sourceFile, info, type, options = {}) {
347
- const auxInfo = info[type];
348
- const name = info.exportedName;
346
+ function generateAuxModule(sourceFile, exportedName, info, type, options = {}) {
349
347
  const suffix = COMPANION_TYPES[type];
350
348
  const cleanSourceFile = stripQuery(sourceFile);
351
349
  const code = [
352
- renderImports(auxInfo.imports),
350
+ renderImports(info.imports),
353
351
  "",
354
- `export const ${name}${suffix} = ${auxInfo.argSource};`,
352
+ `export const ${exportedName}${suffix} = ${info.argSource};`,
355
353
  ""
356
354
  ].join("\n").trimStart();
357
355
  return transformJsx(makeCompanionId(type, cleanSourceFile), code, options);
@@ -361,21 +359,19 @@ function generateLazyModule(sourceFile, info, options = {}) {
361
359
  const name = info.exportedName;
362
360
  const cleanSourceFile = stripQuery(sourceFile);
363
361
  const base = `./${node_path.default.basename(cleanSourceFile, node_path.default.extname(cleanSourceFile))}`;
364
- const code = [
362
+ const hocBinding = info.hocImportedName === "default" ? info.hocLocalName : info.hocImportedName;
363
+ const lines = [
365
364
  `import {lazy} from '${importSource}';`,
366
365
  "",
367
366
  info.hocImportedName === "default" ? `import ${info.hocLocalName} from '${info.hocImportSource}';` : `import {${info.hocImportedName}} from '${info.hocImportSource}';`,
368
367
  "",
369
- `import {${name}Loading} from '${base}.Loading';`,
370
- `import {${name}Error} from '${base}.Error';`,
371
- ``,
372
- `export const ${name}Lazy = ${info.hocImportedName === "default" ? info.hocLocalName : info.hocImportedName}(`,
373
- ` lazy(() => import('${base}').then((m) => ({default: m.${name}Content}))),`,
374
- ` ${name}Loading,`,
375
- ` ${name}Error,`,
376
- `);`,
377
- ``
378
- ].join("\n");
368
+ `import {${name}Loading} from '${base}.Loading';`
369
+ ];
370
+ if (info.error) lines.push(`import {${name}Error} from '${base}.Error';`);
371
+ lines.push("", `export const ${name}Lazy = ${hocBinding}(`, ` lazy(() => import('${base}').then((m) => ({default: m.${name}Content}))),`, ` ${name}Loading,`);
372
+ if (info.error) lines.push(` ${name}Error,`);
373
+ lines.push(`);`, ``);
374
+ const code = lines.join("\n");
379
375
  const filename = makeCompanionId("lazy", cleanSourceFile);
380
376
  return {
381
377
  code,
@@ -456,9 +452,11 @@ function transformDefinitionModule(s, filename, info) {
456
452
  const name = info.exportedName;
457
453
  const cleanFilename = stripQuery(filename);
458
454
  const localSource = `./${node_path.default.basename(cleanFilename, node_path.default.extname(cleanFilename))}`;
459
- s.prepend(`${renderNamedImport(`${name}Loading`, `${name}Loading`, makeCompanionId("loading", localSource))}\n${renderNamedImport(`${name}Error`, `${name}Error`, makeCompanionId("error", localSource))}\n`);
455
+ const prependImports = [renderNamedImport(`${name}Loading`, `${name}Loading`, makeCompanionId("loading", localSource))];
456
+ if (info.error) prependImports.push(renderNamedImport(`${name}Error`, `${name}Error`, makeCompanionId("error", localSource)));
457
+ s.prepend(prependImports.join("\n") + "\n");
460
458
  s.overwrite(info.loading.argStart, info.loading.argEnd, `${name}Loading`);
461
- s.overwrite(info.error.argStart, info.error.argEnd, `${name}Error`);
459
+ if (info.error) s.overwrite(info.error.argStart, info.error.argEnd, `${name}Error`);
462
460
  if (info.content.kind === "identifier") s.append(`\nexport {${info.content.name} as ${name}Content};\n`);
463
461
  else {
464
462
  s.appendLeft(info.hocExportStart, `const ${name}Content = ${info.content.argSource};\n\n`);
@@ -502,13 +500,20 @@ function renderNamedImport(local, imported, source) {
502
500
  }
503
501
  //#endregion
504
502
  //#region src/plugin/core/factory.ts
505
- const DEFAULT_HOCS = [{
506
- from: "@gravity-ui/data-source",
507
- name: "withAsyncBoundary"
508
- }, {
509
- from: "@gravity-ui/data-source",
510
- name: "withQueryAsyncBoundary"
511
- }];
503
+ const DEFAULT_HOCS = [
504
+ {
505
+ from: "@gravity-ui/data-source",
506
+ name: "withAsync"
507
+ },
508
+ {
509
+ from: "@gravity-ui/data-source",
510
+ name: "withAsyncBoundary"
511
+ },
512
+ {
513
+ from: "@gravity-ui/data-source",
514
+ name: "withQueryAsyncBoundary"
515
+ }
516
+ ];
512
517
  const DEFAULT_INCLUDE = /\.(tsx?|jsx?)$/;
513
518
  const VIRTUAL_EXCLUDE = new RegExp(`${VIRTUAL_PREFIX}|${encodeURIComponent(VIRTUAL_PREFIX)}`);
514
519
  const dataSourceLazyUnpluginFactory = (options = {}) => {
@@ -562,12 +567,13 @@ const dataSourceLazyUnpluginFactory = (options = {}) => {
562
567
  this.addWatchFile(parsedId.sourceFile);
563
568
  const info = getHocInfo(parsedId.sourceFile);
564
569
  if (!info) return null;
565
- switch (parsedId.type) {
566
- case "loading":
567
- case "error": return generateAuxModule(parsedId.sourceFile, info, parsedId.type, options.generateOptions);
568
- case "lazy": return generateLazyModule(parsedId.sourceFile, info, options.generateOptions);
569
- default: return assertNever(parsedId.type);
570
+ if (parsedId.type === "loading" || parsedId.type === "error") {
571
+ const auxInfo = info[parsedId.type];
572
+ if (!auxInfo) return null;
573
+ return generateAuxModule(parsedId.sourceFile, info.exportedName, auxInfo, parsedId.type, options.generateOptions);
570
574
  }
575
+ if (parsedId.type === "lazy") return generateLazyModule(parsedId.sourceFile, info, options.generateOptions);
576
+ return assertNever(parsedId.type);
571
577
  }
572
578
  },
573
579
  transform: {
@@ -644,7 +650,7 @@ function isInside(info, access) {
644
650
  function dropAccessesInsideHocArgs(info, usages) {
645
651
  const result = [];
646
652
  for (const usage of usages) {
647
- const accesses = usage.accesses.filter((access) => !isInside(info.loading, access) && !isInside(info.error, access) && !(info.content.kind === "inline" && isInside(info.content, access)));
653
+ const accesses = usage.accesses.filter((access) => !isInside(info.loading, access) && !(info.error && isInside(info.error, access)) && !(info.content.kind === "inline" && isInside(info.content, access)));
648
654
  if (accesses.length === 0) continue;
649
655
  if (accesses.length === usage.accesses.length) {
650
656
  result.push(usage);
@@ -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-Dq6kUGl-.cjs");
5
+ const require_factory = require("./factory-GDKkqVwg.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-Ds3_-8kv.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory, t as DEFAULT_HOCS } from "./factory-Dwr-yuOT.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-Dq6kUGl-.cjs");
1
+ const require_factory = require("./factory-GDKkqVwg.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-Ds3_-8kv.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-Dwr-yuOT.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-Dq6kUGl-.cjs");
1
+ const require_factory = require("./factory-GDKkqVwg.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-Ds3_-8kv.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-Dwr-yuOT.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-Dq6kUGl-.cjs");
1
+ const require_factory = require("./factory-GDKkqVwg.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-Ds3_-8kv.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-Dwr-yuOT.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-Dq6kUGl-.cjs");
1
+ const require_factory = require("./factory-GDKkqVwg.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-Ds3_-8kv.mjs";
1
+ import { n as dataSourceLazyUnpluginFactory } from "./factory-Dwr-yuOT.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.7",
3
+ "version": "0.10.0-alpha.8",
4
4
  "description": "A wrapper around data fetching",
5
5
  "keywords": [
6
6
  "data-fetching",