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

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.
@@ -0,0 +1,5 @@
1
+ const require_factory = require("./factory-Cdmba_F_.cjs");
2
+ //#region src/plugin/esbuild.ts
3
+ var esbuild_default = (0, require("unplugin").createEsbuildPlugin)(require_factory.dataSourceLazyUnpluginFactory);
4
+ //#endregion
5
+ module.exports = esbuild_default;
@@ -0,0 +1,6 @@
1
+ import { r as DataSourceLazyPluginOptions } from "./index-Dv4gZVjD.cjs";
2
+ import * as _$esbuild from "esbuild";
3
+
4
+ //#region src/plugin/esbuild.d.ts
5
+ declare const _default: (options?: DataSourceLazyPluginOptions | undefined) => _$esbuild.Plugin;
6
+ export = _default;
@@ -0,0 +1,555 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ let node_fs = require("node:fs");
24
+ node_fs = __toESM(node_fs);
25
+ let magic_string = require("magic-string");
26
+ magic_string = __toESM(magic_string);
27
+ let oxc_parser = require("oxc-parser");
28
+ let node_path = require("node:path");
29
+ node_path = __toESM(node_path);
30
+ let oxc_transform = require("oxc-transform");
31
+ //#region src/plugin/core/utils.ts
32
+ const VIRTUAL_PREFIX = "\0dsl-plugin";
33
+ const COMPANION_TYPES = {
34
+ loading: "Loading",
35
+ error: "Error",
36
+ lazy: "Lazy"
37
+ };
38
+ const COMPANION_TYPE_BY_SUFFIX = {
39
+ Loading: "loading",
40
+ Error: "error",
41
+ Lazy: "lazy"
42
+ };
43
+ const COMPANION_TYPES_SET = new Set(Object.keys(COMPANION_TYPES));
44
+ const COMPANION_SUFFIXES_SET = new Set(Object.values(COMPANION_TYPES));
45
+ function isCompanionType(type) {
46
+ return COMPANION_TYPES_SET.has(type);
47
+ }
48
+ function isCompanionSuffix(suffix) {
49
+ return COMPANION_SUFFIXES_SET.has(suffix);
50
+ }
51
+ function makeVirtualId(type, sourceFile) {
52
+ return `${VIRTUAL_PREFIX}:${type}:${sourceFile}`;
53
+ }
54
+ function parseVirtualId(id) {
55
+ if (id.indexOf("\0dsl-plugin") !== 0) return null;
56
+ const rest = id.slice(12);
57
+ const colonIndex = rest.indexOf(":");
58
+ if (colonIndex === -1) return null;
59
+ const type = rest.slice(0, colonIndex);
60
+ if (!isCompanionType(type)) return null;
61
+ return {
62
+ type,
63
+ sourceFile: rest.slice(colonIndex + 1)
64
+ };
65
+ }
66
+ function makeCompanionId(type, sourceFile) {
67
+ const suffix = COMPANION_TYPES[type];
68
+ const ext = node_path.default.extname(sourceFile);
69
+ return `${ext ? sourceFile.slice(0, -ext.length) : sourceFile}.${suffix}${ext}`;
70
+ }
71
+ function parseCompanionId(id) {
72
+ const suffixIndex = id.lastIndexOf(".");
73
+ if (suffixIndex === -1) return null;
74
+ const suffix = id.slice(suffixIndex + 1);
75
+ if (!isCompanionSuffix(suffix)) return null;
76
+ return {
77
+ type: COMPANION_TYPE_BY_SUFFIX[suffix],
78
+ sourceFile: id.slice(0, suffixIndex)
79
+ };
80
+ }
81
+ function isRelativeId(id) {
82
+ return id[0] === ".";
83
+ }
84
+ function stripQuery(id) {
85
+ const queryIndex = id.indexOf("?");
86
+ return queryIndex === -1 ? id : id.slice(0, queryIndex);
87
+ }
88
+ function getHocString(from, name) {
89
+ return `${from}/${name}`;
90
+ }
91
+ function assertNever(value) {
92
+ throw new Error(`Unexpected value: ${value}`);
93
+ }
94
+ //#endregion
95
+ //#region src/plugin/core/extract.ts
96
+ function extractHocInfo(hocsSet, filename, source) {
97
+ const program = parseProgram(filename, source);
98
+ if (!program) return null;
99
+ const importDecls = [];
100
+ const trackedHocs = /* @__PURE__ */ new Map();
101
+ for (const node of program.body) {
102
+ if (node.type !== "ImportDeclaration" || node.importKind === "type") continue;
103
+ importDecls.push(node);
104
+ for (const spec of node.specifiers) {
105
+ let importedName;
106
+ if (spec.type === "ImportSpecifier") {
107
+ if (spec.importKind === "type") continue;
108
+ importedName = spec.imported.type === "Literal" ? spec.imported.value : spec.imported.name;
109
+ } else if (spec.type === "ImportDefaultSpecifier") importedName = "default";
110
+ else continue;
111
+ if (hocsSet.has(getHocString(node.source.value, importedName))) trackedHocs.set(spec.local.name, {
112
+ from: node.source.value,
113
+ name: importedName
114
+ });
115
+ }
116
+ }
117
+ if (trackedHocs.size === 0) return null;
118
+ for (const node of program.body) {
119
+ if (node.type !== "ExportNamedDeclaration" || node.exportKind === "type" || node.declaration?.type !== "VariableDeclaration") continue;
120
+ 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;
122
+ const hocEntry = trackedHocs.get(decl.init.callee.name);
123
+ if (!hocEntry) continue;
124
+ const [contentArg, loadingArg, errorArg] = decl.init.arguments;
125
+ const contentInfo = contentArg.type === "Identifier" ? {
126
+ kind: "identifier",
127
+ name: contentArg.name
128
+ } : {
129
+ kind: "inline",
130
+ argSource: source.slice(contentArg.start, contentArg.end),
131
+ argStart: contentArg.start,
132
+ argEnd: contentArg.end
133
+ };
134
+ return {
135
+ hocImportSource: hocEntry.from,
136
+ hocImportedName: hocEntry.name,
137
+ hocLocalName: decl.init.callee.name,
138
+ exportedName: decl.id.name,
139
+ hocExportStart: node.start,
140
+ content: contentInfo,
141
+ loading: {
142
+ argSource: source.slice(loadingArg.start, loadingArg.end),
143
+ argStart: loadingArg.start,
144
+ argEnd: loadingArg.end,
145
+ imports: filterNeededImports(importDecls, collectIdentifiers(loadingArg))
146
+ },
147
+ error: {
148
+ argSource: source.slice(errorArg.start, errorArg.end),
149
+ argStart: errorArg.start,
150
+ argEnd: errorArg.end,
151
+ imports: filterNeededImports(importDecls, collectIdentifiers(errorArg))
152
+ }
153
+ };
154
+ }
155
+ }
156
+ return null;
157
+ }
158
+ const COMPANION_PROPS_RE = new RegExp(`\\.(${Object.values(COMPANION_TYPES).join("|")})\\b`);
159
+ function extractUsages(filename, source) {
160
+ const result = [];
161
+ if (!COMPANION_PROPS_RE.test(source)) return result;
162
+ const program = parseProgram(filename, source);
163
+ if (!program) return result;
164
+ const trackedImports = /* @__PURE__ */ new Map();
165
+ const importLocalStarts = /* @__PURE__ */ new Set();
166
+ for (const node of program.body) {
167
+ if (node.type !== "ImportDeclaration") continue;
168
+ const declMeta = {
169
+ source: node.source.value,
170
+ namedSpecifiers: [],
171
+ start: node.start,
172
+ end: node.end
173
+ };
174
+ for (const spec of node.specifiers) {
175
+ if (spec.type !== "ImportSpecifier") continue;
176
+ const specMeta = {
177
+ localName: spec.local.name,
178
+ importedName: spec.imported.type === "Literal" ? spec.imported.value : spec.imported.name,
179
+ start: spec.start,
180
+ end: spec.end
181
+ };
182
+ declMeta.namedSpecifiers.push(specMeta);
183
+ trackedImports.set(spec.local.name, {
184
+ decl: declMeta,
185
+ spec: specMeta
186
+ });
187
+ importLocalStarts.add(spec.local.start);
188
+ }
189
+ }
190
+ if (trackedImports.size === 0) return result;
191
+ const usages = /* @__PURE__ */ new Map();
192
+ function ensureUsage(name) {
193
+ let usage = usages.get(name);
194
+ if (!usage) usages.set(name, usage = {
195
+ totalStarts: /* @__PURE__ */ new Set(),
196
+ accesses: []
197
+ });
198
+ return usage;
199
+ }
200
+ function trackIdentifier(name, start) {
201
+ if (trackedImports.has(name) && !importLocalStarts.has(start)) ensureUsage(name).totalStarts.add(start);
202
+ }
203
+ function trackCompanionAccess(localName, prop, exprStart, exprEnd) {
204
+ ensureUsage(localName).accesses.push({
205
+ prop,
206
+ start: exprStart,
207
+ end: exprEnd
208
+ });
209
+ }
210
+ new oxc_parser.Visitor({
211
+ Identifier(node) {
212
+ trackIdentifier(node.name, node.start);
213
+ },
214
+ JSXIdentifier(node) {
215
+ trackIdentifier(node.name, node.start);
216
+ },
217
+ MemberExpression(node) {
218
+ if (!node.computed && node.object.type === "Identifier" && trackedImports.has(node.object.name) && node.property.type === "Identifier" && isCompanionSuffix(node.property.name)) trackCompanionAccess(node.object.name, node.property.name, node.start, node.end);
219
+ },
220
+ JSXMemberExpression(node) {
221
+ if (node.object.type === "JSXIdentifier" && trackedImports.has(node.object.name) && isCompanionSuffix(node.property.name)) trackCompanionAccess(node.object.name, node.property.name, node.start, node.end);
222
+ }
223
+ }).visit(program);
224
+ for (const [localName, { accesses, totalStarts }] of usages) {
225
+ if (accesses.length === 0) continue;
226
+ const { decl, spec } = trackedImports.get(localName);
227
+ const hasOtherUsages = totalStarts.size > accesses.length;
228
+ result.push({
229
+ decl,
230
+ spec,
231
+ accesses,
232
+ hasOtherUsages
233
+ });
234
+ }
235
+ return result;
236
+ }
237
+ function collectIdentifiers(node) {
238
+ const result = /* @__PURE__ */ new Set();
239
+ walk(node, (current) => {
240
+ if (isOwnIdentifier(current) || isJSXIdentifier(current)) result.add(current.name);
241
+ });
242
+ return result;
243
+ }
244
+ function filterNeededImports(importDecls, identifiers) {
245
+ const result = [];
246
+ for (const decl of importDecls) {
247
+ if (decl.specifiers.length === 0) {
248
+ result.push(decl);
249
+ continue;
250
+ }
251
+ const specifiers = decl.specifiers.filter((spec) => identifiers.has(spec.local.name));
252
+ if (specifiers.length > 0) result.push({
253
+ ...decl,
254
+ specifiers
255
+ });
256
+ }
257
+ return result;
258
+ }
259
+ function isOwnNode(node) {
260
+ return typeof node === "object" && node !== null && "type" in node && typeof node.type === "string";
261
+ }
262
+ function isOwnIdentifier(node) {
263
+ return node.type === "Identifier";
264
+ }
265
+ function isJSXIdentifier(node) {
266
+ return node.type === "JSXIdentifier";
267
+ }
268
+ function walk(node, visitor) {
269
+ if (!isOwnNode(node)) return;
270
+ visitor(node);
271
+ for (const value of Object.values(node)) if (Array.isArray(value)) for (const item of value) walk(item, visitor);
272
+ else walk(value, visitor);
273
+ }
274
+ function parseProgram(filename, source) {
275
+ const parsed = (0, oxc_parser.parseSync)(filename, source, {
276
+ sourceType: "module",
277
+ range: true
278
+ });
279
+ if (parsed.errors.some((error) => error.severity === "Error")) return null;
280
+ return parsed.program;
281
+ }
282
+ //#endregion
283
+ //#region src/plugin/core/generate.ts
284
+ function generateAuxModule(sourceFile, info, type, options = {}) {
285
+ const auxInfo = info[type];
286
+ const name = info.exportedName;
287
+ const suffix = COMPANION_TYPES[type];
288
+ const cleanSourceFile = stripQuery(sourceFile);
289
+ const code = [
290
+ renderImports(auxInfo.imports),
291
+ "",
292
+ `export const ${name}${suffix} = ${auxInfo.argSource};`,
293
+ ""
294
+ ].join("\n").trimStart();
295
+ return transformJsx(makeCompanionId(type, cleanSourceFile), code, options);
296
+ }
297
+ function generateLazyModule(sourceFile, info, options = {}) {
298
+ const importSource = options.jsx?.importSource ?? "react";
299
+ const name = info.exportedName;
300
+ const cleanSourceFile = stripQuery(sourceFile);
301
+ const base = `./${node_path.default.basename(cleanSourceFile, node_path.default.extname(cleanSourceFile))}`;
302
+ const code = [
303
+ `import {lazy} from '${importSource}';`,
304
+ "",
305
+ info.hocImportedName === "default" ? `import ${info.hocLocalName} from '${info.hocImportSource}';` : `import {${info.hocImportedName}} from '${info.hocImportSource}';`,
306
+ "",
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");
317
+ const filename = makeCompanionId("lazy", cleanSourceFile);
318
+ return {
319
+ code,
320
+ map: new magic_string.default(code).generateMap({
321
+ source: filename,
322
+ includeContent: true,
323
+ hires: false
324
+ }).toString()
325
+ };
326
+ }
327
+ function transformJsx(filename, code, options) {
328
+ const result = (0, oxc_transform.transformSync)(filename, code, {
329
+ lang: "tsx",
330
+ jsx: options.jsx,
331
+ target: options.target,
332
+ sourcemap: true
333
+ });
334
+ if (result.errors.length > 0) {
335
+ const error = result.errors[0];
336
+ throw new Error(error.codeframe ?? error.message);
337
+ }
338
+ return {
339
+ code: result.code,
340
+ map: JSON.stringify(result.map)
341
+ };
342
+ }
343
+ function renderImport(decl) {
344
+ const parts = [];
345
+ const named = [];
346
+ for (const spec of decl.specifiers) if (spec.type === "ImportDefaultSpecifier") parts.push(spec.local.name);
347
+ else if (spec.type === "ImportNamespaceSpecifier") parts.push(`* as ${spec.local.name}`);
348
+ else {
349
+ const imported = spec.imported.type === "Literal" ? JSON.stringify(spec.imported.value) : spec.imported.name;
350
+ const renderedSpec = imported === spec.local.name ? spec.local.name : `${imported} as ${spec.local.name}`;
351
+ named.push(spec.importKind === "type" ? `type ${renderedSpec}` : renderedSpec);
352
+ }
353
+ if (named.length > 0) parts.push(`{${named.join(", ")}}`);
354
+ return `import ${decl.importKind === "type" ? "type " : ""}${parts.join(", ")} from '${decl.source.value}';`;
355
+ }
356
+ function renderImports(imports) {
357
+ return imports.map(renderImport).join("\n");
358
+ }
359
+ //#endregion
360
+ //#region src/plugin/core/resolve.ts
361
+ async function resolveSourceFile(ctx, sourceFile, importer) {
362
+ const nativeCtx = ctx.getNativeBuildContext?.();
363
+ const directory = node_path.default.dirname(importer);
364
+ if (nativeCtx?.framework === "webpack" || nativeCtx?.framework === "rspack") return resolveWithCompiler(nativeCtx.compiler, directory, sourceFile);
365
+ if (nativeCtx?.framework === "esbuild") {
366
+ const result = await nativeCtx.build.resolve(sourceFile, {
367
+ kind: "import-statement",
368
+ importer,
369
+ resolveDir: directory
370
+ });
371
+ return result.errors.length === 0 && result.path ? result.path : null;
372
+ }
373
+ if ("resolve" in ctx && typeof ctx.resolve === "function") {
374
+ const resolved = await ctx.resolve(sourceFile, importer, { skipSelf: true });
375
+ if (!resolved || resolved.external) return null;
376
+ return resolved.id;
377
+ }
378
+ return null;
379
+ }
380
+ function resolveWithCompiler(compiler, directory, request) {
381
+ return new Promise((resolve) => {
382
+ try {
383
+ compiler.resolverFactory.get("normal").resolve({}, directory, request, {}, (error, result) => {
384
+ resolve(!error && typeof result === "string" ? result : null);
385
+ });
386
+ } catch {
387
+ resolve(null);
388
+ }
389
+ });
390
+ }
391
+ //#endregion
392
+ //#region src/plugin/core/transform.ts
393
+ function transformDefinitionModule(s, filename, info) {
394
+ const name = info.exportedName;
395
+ const cleanFilename = stripQuery(filename);
396
+ 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`);
398
+ s.overwrite(info.loading.argStart, info.loading.argEnd, `${name}Loading`);
399
+ s.overwrite(info.error.argStart, info.error.argEnd, `${name}Error`);
400
+ if (info.content.kind === "identifier") s.append(`\nexport {${info.content.name} as ${name}Content};\n`);
401
+ else {
402
+ s.appendLeft(info.hocExportStart, `const ${name}Content = ${info.content.argSource};\n\n`);
403
+ s.overwrite(info.content.argStart, info.content.argEnd, `${name}Content`);
404
+ s.append(`\nexport {${name}Content};\n`);
405
+ }
406
+ }
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}`);
409
+ 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)));
413
+ }
414
+ if (newImports.length > 0) s.prepend(newImports.join("\n") + "\n");
415
+ const localsByDecl = /* @__PURE__ */ new Map();
416
+ for (const usage of usages) {
417
+ if (usage.hasOtherUsages) continue;
418
+ let locals = localsByDecl.get(usage.decl);
419
+ if (!locals) localsByDecl.set(usage.decl, locals = /* @__PURE__ */ new Set());
420
+ locals.add(usage.spec.localName);
421
+ }
422
+ for (const [decl, locals] of localsByDecl) removeImportSpecifiers(s, decl, locals);
423
+ }
424
+ function removeImportSpecifiers(s, decl, localsToRemove) {
425
+ const kept = decl.namedSpecifiers.filter((spec) => !localsToRemove.has(spec.localName));
426
+ if (kept.length === 0) {
427
+ s.remove(decl.start, s.original[decl.end] === "\n" ? decl.end + 1 : decl.end);
428
+ return;
429
+ }
430
+ const firstSpec = decl.namedSpecifiers[0];
431
+ const lastSpec = decl.namedSpecifiers[decl.namedSpecifiers.length - 1];
432
+ const braceOpen = s.original.lastIndexOf("{", firstSpec.start);
433
+ const braceClose = s.original.indexOf("}", lastSpec.end);
434
+ if (braceOpen === -1 || braceClose === -1) return;
435
+ const keptText = kept.map((spec) => s.original.slice(spec.start, spec.end)).join(", ");
436
+ s.overwrite(braceOpen + 1, braceClose, keptText);
437
+ }
438
+ function renderNamedImport(local, imported, source) {
439
+ return `import {${local === imported ? imported : `${imported} as ${local}`}} from '${source}';`;
440
+ }
441
+ //#endregion
442
+ //#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
+ }];
450
+ const DEFAULT_INCLUDE = /\.(tsx?|jsx?)$/;
451
+ const VIRTUAL_EXCLUDE = new RegExp(`${VIRTUAL_PREFIX}|${encodeURIComponent(VIRTUAL_PREFIX)}`);
452
+ const dataSourceLazyUnpluginFactory = (options = {}) => {
453
+ const hocPatterns = options.hocs ?? DEFAULT_HOCS;
454
+ const include = options.include ?? DEFAULT_INCLUDE;
455
+ const exclude = [VIRTUAL_EXCLUDE];
456
+ if (Array.isArray(options.exclude)) exclude.push(...options.exclude);
457
+ else if (options.exclude) exclude.push(options.exclude);
458
+ const hocsSet = new Set(hocPatterns.map((pattern) => getHocString(pattern.from, pattern.name)));
459
+ const hocsRegexp = new RegExp(Array.from(new Set(hocPatterns.map((pattern) => pattern.name))).map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"));
460
+ const hocInfoCache = /* @__PURE__ */ new Map();
461
+ const getHocInfo = (sourceFile, source) => {
462
+ const key = stripQuery(sourceFile);
463
+ const cachedInfo = hocInfoCache.get(key);
464
+ if (cachedInfo !== void 0) return cachedInfo;
465
+ const resolvedSource = source ?? node_fs.default.readFileSync(key, "utf-8");
466
+ const info = hocsRegexp.test(resolvedSource) ? extractHocInfo(hocsSet, key, resolvedSource) : null;
467
+ hocInfoCache.set(key, info);
468
+ return info;
469
+ };
470
+ return {
471
+ name: "data-source-lazy",
472
+ enforce: "pre",
473
+ async resolveId(id, importer) {
474
+ if (!importer) return null;
475
+ const companion = parseCompanionId(id);
476
+ const parsedImporter = parseVirtualId(importer);
477
+ const normalizedImporter = parsedImporter?.sourceFile ?? importer;
478
+ if (companion) {
479
+ if (await resolveSourceFile(this, id, normalizedImporter)) return null;
480
+ const resolvedSourceFile = await resolveSourceFile(this, companion.sourceFile, normalizedImporter);
481
+ return resolvedSourceFile && makeVirtualId(companion.type, resolvedSourceFile);
482
+ }
483
+ if (parsedImporter && isRelativeId(id)) return resolveSourceFile(this, id, parsedImporter.sourceFile);
484
+ return null;
485
+ },
486
+ load: {
487
+ filter: { id: new RegExp(VIRTUAL_PREFIX) },
488
+ handler(id) {
489
+ const parsedId = parseVirtualId(id);
490
+ if (!parsedId) return null;
491
+ this.addWatchFile(parsedId.sourceFile);
492
+ const info = getHocInfo(parsedId.sourceFile);
493
+ 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);
499
+ }
500
+ }
501
+ },
502
+ transform: {
503
+ filter: { id: {
504
+ include,
505
+ exclude
506
+ } },
507
+ async handler(code, id) {
508
+ const info = getHocInfo(id, code);
509
+ const usages = extractUsages(id, code);
510
+ 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);
518
+ if (!info && verifiedUsages.length === 0) return null;
519
+ const s = new magic_string.default(code);
520
+ if (info) transformDefinitionModule(s, id, info);
521
+ if (verifiedUsages.length > 0) transformUsages(s, verifiedUsages);
522
+ if (!s.hasChanged()) return null;
523
+ return {
524
+ code: s.toString(),
525
+ map: s.generateMap({
526
+ source: id,
527
+ hires: true
528
+ }).toString()
529
+ };
530
+ }
531
+ },
532
+ watchChange(id) {
533
+ hocInfoCache.delete(stripQuery(id));
534
+ }
535
+ };
536
+ };
537
+ //#endregion
538
+ Object.defineProperty(exports, "DEFAULT_HOCS", {
539
+ enumerable: true,
540
+ get: function() {
541
+ return DEFAULT_HOCS;
542
+ }
543
+ });
544
+ Object.defineProperty(exports, "__toESM", {
545
+ enumerable: true,
546
+ get: function() {
547
+ return __toESM;
548
+ }
549
+ });
550
+ Object.defineProperty(exports, "dataSourceLazyUnpluginFactory", {
551
+ enumerable: true,
552
+ get: function() {
553
+ return dataSourceLazyUnpluginFactory;
554
+ }
555
+ });
@@ -0,0 +1,23 @@
1
+ import { UnpluginFactory } from "unplugin";
2
+ import { JsxOptions } from "oxc-transform";
3
+ //#region src/plugin/core/generate.d.ts
4
+ interface GenerateOptions {
5
+ jsx?: JsxOptions;
6
+ target?: string | string[];
7
+ }
8
+ //#endregion
9
+ //#region src/plugin/core/factory.d.ts
10
+ interface DataSourceLazyHocPattern {
11
+ from: string;
12
+ name: string;
13
+ }
14
+ interface DataSourceLazyPluginOptions {
15
+ hocs?: DataSourceLazyHocPattern[];
16
+ include?: RegExp | RegExp[];
17
+ exclude?: RegExp | RegExp[];
18
+ generateOptions?: GenerateOptions;
19
+ }
20
+ declare const DEFAULT_HOCS: DataSourceLazyPluginOptions['hocs'];
21
+ declare const dataSourceLazyUnpluginFactory: UnpluginFactory<DataSourceLazyPluginOptions | undefined>;
22
+ //#endregion
23
+ export { dataSourceLazyUnpluginFactory as i, DataSourceLazyHocPattern as n, DataSourceLazyPluginOptions as r, DEFAULT_HOCS as t };
@@ -0,0 +1,12 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ const require_factory = require("./factory-Cdmba_F_.cjs");
6
+ //#region src/plugin/index.ts
7
+ const DataSourceLazyPlugin = /* @__PURE__ */ (0, require("unplugin").createUnplugin)(require_factory.dataSourceLazyUnpluginFactory);
8
+ //#endregion
9
+ exports.DEFAULT_HOCS = require_factory.DEFAULT_HOCS;
10
+ exports.DataSourceLazyPlugin = DataSourceLazyPlugin;
11
+ exports.default = DataSourceLazyPlugin;
12
+ exports.dataSourceLazyUnpluginFactory = require_factory.dataSourceLazyUnpluginFactory;
@@ -0,0 +1,7 @@
1
+ import { i as dataSourceLazyUnpluginFactory, n as DataSourceLazyHocPattern, r as DataSourceLazyPluginOptions, t as DEFAULT_HOCS } from "./index-Dv4gZVjD.cjs";
2
+ import * as _$unplugin from "unplugin";
3
+
4
+ //#region src/plugin/index.d.ts
5
+ declare const DataSourceLazyPlugin: _$unplugin.UnpluginInstance<DataSourceLazyPluginOptions | undefined, boolean>;
6
+ //#endregion
7
+ export { DEFAULT_HOCS, DataSourceLazyHocPattern, DataSourceLazyPlugin, DataSourceLazyPlugin as default, DataSourceLazyPluginOptions, dataSourceLazyUnpluginFactory };
@@ -0,0 +1,5 @@
1
+ const require_factory = require("./factory-Cdmba_F_.cjs");
2
+ //#region src/plugin/rollup.ts
3
+ var rollup_default = (0, require("unplugin").createRollupPlugin)(require_factory.dataSourceLazyUnpluginFactory);
4
+ //#endregion
5
+ module.exports = rollup_default;
@@ -0,0 +1,5 @@
1
+ import { r as DataSourceLazyPluginOptions } from "./index-Dv4gZVjD.cjs";
2
+
3
+ //#region src/plugin/rollup.d.ts
4
+ declare const _default: (options?: DataSourceLazyPluginOptions | undefined) => any;
5
+ export = _default;
@@ -0,0 +1,5 @@
1
+ const require_factory = require("./factory-Cdmba_F_.cjs");
2
+ //#region src/plugin/rspack.ts
3
+ var rspack_default = (0, require("unplugin").createRspackPlugin)(require_factory.dataSourceLazyUnpluginFactory);
4
+ //#endregion
5
+ module.exports = rspack_default;
@@ -0,0 +1,6 @@
1
+ import { r as DataSourceLazyPluginOptions } from "./index-Dv4gZVjD.cjs";
2
+ import * as _$unplugin from "unplugin";
3
+
4
+ //#region src/plugin/rspack.d.ts
5
+ declare const _default: (options?: DataSourceLazyPluginOptions | undefined) => _$unplugin.RspackPluginInstance;
6
+ export = _default;
@@ -0,0 +1,5 @@
1
+ const require_factory = require("./factory-Cdmba_F_.cjs");
2
+ //#region src/plugin/vite.ts
3
+ var vite_default = (0, require("unplugin").createVitePlugin)(require_factory.dataSourceLazyUnpluginFactory);
4
+ //#endregion
5
+ module.exports = vite_default;
@@ -0,0 +1,5 @@
1
+ import { r as DataSourceLazyPluginOptions } from "./index-Dv4gZVjD.cjs";
2
+
3
+ //#region src/plugin/vite.d.ts
4
+ declare const _default: (options?: DataSourceLazyPluginOptions | undefined) => any;
5
+ export = _default;
@@ -0,0 +1,5 @@
1
+ const require_factory = require("./factory-Cdmba_F_.cjs");
2
+ //#region src/plugin/webpack.ts
3
+ var webpack_default = (0, require("unplugin").createWebpackPlugin)(require_factory.dataSourceLazyUnpluginFactory);
4
+ //#endregion
5
+ module.exports = webpack_default;
@@ -0,0 +1,6 @@
1
+ import { r as DataSourceLazyPluginOptions } from "./index-Dv4gZVjD.cjs";
2
+ import * as _$webpack from "webpack";
3
+
4
+ //#region src/plugin/webpack.d.ts
5
+ declare const _default: (options?: DataSourceLazyPluginOptions | undefined) => _$webpack.WebpackPluginInstance;
6
+ export = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/data-source",
3
- "version": "0.9.1-alpha.0",
3
+ "version": "0.10.0-alpha.1",
4
4
  "description": "A wrapper around data fetching",
5
5
  "keywords": [
6
6
  "data-fetching",
@@ -35,27 +35,33 @@
35
35
  },
36
36
  "./plugin": {
37
37
  "types": "./build/plugin/index.d.mts",
38
- "default": "./build/plugin/index.mjs"
38
+ "import": "./build/plugin/index.mjs",
39
+ "require": "./build/plugin/index.cjs"
39
40
  },
40
41
  "./plugin-webpack": {
41
42
  "types": "./build/plugin/webpack.d.mts",
42
- "default": "./build/plugin/webpack.mjs"
43
+ "import": "./build/plugin/webpack.mjs",
44
+ "require": "./build/plugin/webpack.cjs"
43
45
  },
44
46
  "./plugin-rspack": {
45
47
  "types": "./build/plugin/rspack.d.mts",
46
- "default": "./build/plugin/rspack.mjs"
48
+ "import": "./build/plugin/rspack.mjs",
49
+ "require": "./build/plugin/rspack.cjs"
47
50
  },
48
51
  "./plugin-vite": {
49
52
  "types": "./build/plugin/vite.d.mts",
50
- "default": "./build/plugin/vite.mjs"
53
+ "import": "./build/plugin/vite.mjs",
54
+ "require": "./build/plugin/vite.cjs"
51
55
  },
52
56
  "./plugin-rollup": {
53
57
  "types": "./build/plugin/rollup.d.mts",
54
- "default": "./build/plugin/rollup.mjs"
58
+ "import": "./build/plugin/rollup.mjs",
59
+ "require": "./build/plugin/rollup.cjs"
55
60
  },
56
61
  "./plugin-esbuild": {
57
62
  "types": "./build/plugin/esbuild.d.mts",
58
- "default": "./build/plugin/esbuild.mjs"
63
+ "import": "./build/plugin/esbuild.mjs",
64
+ "require": "./build/plugin/esbuild.cjs"
59
65
  },
60
66
  "./plugin-client": {
61
67
  "types": "./build/plugin/typings/client.d.ts"
@@ -82,8 +88,8 @@
82
88
  "dependencies": {
83
89
  "@normy/core": "^0.14.0",
84
90
  "magic-string": "^0.30.21",
85
- "oxc-parser": "^0.130.0",
86
- "oxc-transform": "^0.130.0",
91
+ "oxc-parser": "^0.128.0",
92
+ "oxc-transform": "^0.128.0",
87
93
  "react-error-boundary": "^6.1.1",
88
94
  "unplugin": "^3.0.0",
89
95
  "utility-types": "^3.11.0"