svelte-docinfo 0.1.0

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 (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +349 -0
  3. package/dist/analyze-core.d.ts +1386 -0
  4. package/dist/analyze-core.d.ts.map +1 -0
  5. package/dist/analyze-core.js +324 -0
  6. package/dist/analyze.d.ts +137 -0
  7. package/dist/analyze.d.ts.map +1 -0
  8. package/dist/analyze.js +148 -0
  9. package/dist/cli.d.ts +102 -0
  10. package/dist/cli.d.ts.map +1 -0
  11. package/dist/cli.js +206 -0
  12. package/dist/concurrency.d.ts +38 -0
  13. package/dist/concurrency.d.ts.map +1 -0
  14. package/dist/concurrency.js +57 -0
  15. package/dist/declaration-build.d.ts +164 -0
  16. package/dist/declaration-build.d.ts.map +1 -0
  17. package/dist/declaration-build.js +15 -0
  18. package/dist/declaration-helpers.d.ts +169 -0
  19. package/dist/declaration-helpers.d.ts.map +1 -0
  20. package/dist/declaration-helpers.js +239 -0
  21. package/dist/dep-resolver.d.ts +166 -0
  22. package/dist/dep-resolver.d.ts.map +1 -0
  23. package/dist/dep-resolver.js +144 -0
  24. package/dist/diagnostics.d.ts +650 -0
  25. package/dist/diagnostics.d.ts.map +1 -0
  26. package/dist/diagnostics.js +377 -0
  27. package/dist/discovery.d.ts +115 -0
  28. package/dist/discovery.d.ts.map +1 -0
  29. package/dist/discovery.js +126 -0
  30. package/dist/exports.d.ts +105 -0
  31. package/dist/exports.d.ts.map +1 -0
  32. package/dist/exports.js +274 -0
  33. package/dist/files.d.ts +77 -0
  34. package/dist/files.d.ts.map +1 -0
  35. package/dist/files.js +95 -0
  36. package/dist/index.d.ts +32 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +30 -0
  39. package/dist/log.d.ts +32 -0
  40. package/dist/log.d.ts.map +1 -0
  41. package/dist/log.js +11 -0
  42. package/dist/logo.d.ts +8 -0
  43. package/dist/logo.d.ts.map +1 -0
  44. package/dist/logo.js +9 -0
  45. package/dist/main.d.ts +11 -0
  46. package/dist/main.d.ts.map +1 -0
  47. package/dist/main.js +18 -0
  48. package/dist/paths.d.ts +35 -0
  49. package/dist/paths.d.ts.map +1 -0
  50. package/dist/paths.js +34 -0
  51. package/dist/postprocess.d.ts +145 -0
  52. package/dist/postprocess.d.ts.map +1 -0
  53. package/dist/postprocess.js +305 -0
  54. package/dist/session.d.ts +248 -0
  55. package/dist/session.d.ts.map +1 -0
  56. package/dist/session.js +496 -0
  57. package/dist/source-config.d.ts +330 -0
  58. package/dist/source-config.d.ts.map +1 -0
  59. package/dist/source-config.js +356 -0
  60. package/dist/source.d.ts +126 -0
  61. package/dist/source.d.ts.map +1 -0
  62. package/dist/source.js +68 -0
  63. package/dist/svelte.d.ts +179 -0
  64. package/dist/svelte.d.ts.map +1 -0
  65. package/dist/svelte.js +898 -0
  66. package/dist/tsdoc.d.ts +145 -0
  67. package/dist/tsdoc.d.ts.map +1 -0
  68. package/dist/tsdoc.js +262 -0
  69. package/dist/types.d.ts +3381 -0
  70. package/dist/types.d.ts.map +1 -0
  71. package/dist/types.js +588 -0
  72. package/dist/typescript-exports.d.ts +91 -0
  73. package/dist/typescript-exports.d.ts.map +1 -0
  74. package/dist/typescript-exports.js +656 -0
  75. package/dist/typescript-extract-class.d.ts +29 -0
  76. package/dist/typescript-extract-class.d.ts.map +1 -0
  77. package/dist/typescript-extract-class.js +251 -0
  78. package/dist/typescript-extract-function.d.ts +47 -0
  79. package/dist/typescript-extract-function.d.ts.map +1 -0
  80. package/dist/typescript-extract-function.js +108 -0
  81. package/dist/typescript-extract-shared.d.ts +166 -0
  82. package/dist/typescript-extract-shared.d.ts.map +1 -0
  83. package/dist/typescript-extract-shared.js +528 -0
  84. package/dist/typescript-extract-type-properties.d.ts +34 -0
  85. package/dist/typescript-extract-type-properties.d.ts.map +1 -0
  86. package/dist/typescript-extract-type-properties.js +241 -0
  87. package/dist/typescript-extract-type.d.ts +48 -0
  88. package/dist/typescript-extract-type.d.ts.map +1 -0
  89. package/dist/typescript-extract-type.js +238 -0
  90. package/dist/typescript-program.d.ts +211 -0
  91. package/dist/typescript-program.d.ts.map +1 -0
  92. package/dist/typescript-program.js +290 -0
  93. package/dist/vite.d.ts +116 -0
  94. package/dist/vite.d.ts.map +1 -0
  95. package/dist/vite.js +418 -0
  96. package/package.json +131 -0
  97. package/virtual-svelte-docinfo.d.ts +49 -0
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Persistent analysis session — δ-shaped API over a `ts.LanguageService`.
3
+ *
4
+ * Maps cleanly onto LSP and Vite/HMR consumers:
5
+ *
6
+ * - `setFile` / `setFiles` — additive ingest; transform-if-Svelte, lex
7
+ * specifiers, resolve imports (parallel), push content/virtual to the LS.
8
+ * Returns ingest-time diagnostics + a `changed` flag. Cache-hit no-op
9
+ * when content matches AND the mode-specific cache key matches (resolver
10
+ * identity for lex+resolve, dependency-snapshot equality for pre-resolved).
11
+ * - `deleteFile` — drop owned entry, evict from LS.
12
+ * - `has` / `list` — owned-set introspection (covers what consumers used to
13
+ * get from their own mirror caches).
14
+ * - `query` — sync analysis pass against the current owned set; returns
15
+ * analysis-pass diagnostics only (ingest diagnostics surface via the
16
+ * `setFile`/`setFiles` returns).
17
+ * - `dispose` — release LS resources.
18
+ *
19
+ * The session owns a single `Map<id, OwnedEntry>` covering content, svelte
20
+ * virtuals, unfiltered deps, the mode-specific cache key (resolver identity
21
+ * or pre-resolved snapshot), and ingest-time diagnostics. svelte2tsx runs
22
+ * at most once per content change. Resolver work parallelizes across the
23
+ * batch in phase 2 of the three-phase setFiles pipeline; fully pre-resolved
24
+ * batches skip phase 2 (and the default-resolver construction) entirely.
25
+ *
26
+ * @see `analyze-core.ts` for the two-phase analysis orchestrator
27
+ * @see `dep-resolver.ts` for the `ImportResolver` token contract
28
+ *
29
+ * @module
30
+ */
31
+ import { type AnalysisLanguageServiceOptions } from './typescript-program.js';
32
+ import type { Diagnostic } from './diagnostics.js';
33
+ import type { AnalysisLog } from './log.js';
34
+ import { type ResolveImport } from './dep-resolver.js';
35
+ import type { SourceFileInfo } from './source.js';
36
+ import { type ModuleSourceOptions } from './source-config.js';
37
+ import { AnalyzeResultJson, type OnDuplicates } from './analyze-core.js';
38
+ /**
39
+ * Options for a per-file or per-batch resolver override.
40
+ *
41
+ * Identity is required (not optional) — silently coalescing missing identities
42
+ * to a function reference would destroy cache reuse when the same logical
43
+ * resolver is wrapped in fresh closures across calls.
44
+ */
45
+ export interface SetFileOptions {
46
+ /**
47
+ * Per-call override of the session-default resolver — a bare
48
+ * `ResolveImportFn` or a token-paired `ImportResolver` (see `ResolveImport`).
49
+ *
50
+ * A bare function is normalized with a fresh identity on each call, so the
51
+ * files touched by this call re-resolve rather than cache-hitting — the
52
+ * expected behavior for a deliberate one-off override. To reuse the resolve
53
+ * cache across calls, pass an `ImportResolver` with a stable `identity`.
54
+ */
55
+ resolveImport?: ResolveImport;
56
+ }
57
+ /**
58
+ * Result of `setFile` (single-file ingest).
59
+ *
60
+ * `changed` is `true` when content or the mode-specific cache key (resolver
61
+ * identity for lex+resolve; dependency snapshot for pre-resolved) differed
62
+ * from the cached entry — the owned entry was rewritten. An LS push
63
+ * accompanies the entry write only when the file is TS/JS or has a
64
+ * successful Svelte virtual; CSS/JSON and transform-failed Svelte rewrite
65
+ * the entry without touching the LS. `false` indicates a cache-hit no-op:
66
+ * the cached `ingestDiagnostics` are returned but no work ran.
67
+ */
68
+ export interface SetFileResult {
69
+ /** Whether content or the mode-specific cache key differed from the cached entry. */
70
+ changed: boolean;
71
+ /** Ingest-time diagnostics for this file (durable on the entry). */
72
+ diagnostics: Array<Diagnostic>;
73
+ }
74
+ /**
75
+ * Result of `setFiles` (batch ingest).
76
+ *
77
+ * Carries both aggregate views (`changedIds`, pre-flattened `diagnostics`)
78
+ * and a structured `perFile` map. HMR-style consumers want
79
+ * `changedIds.size > 0` as the hot check; LSP-style consumers want per-file
80
+ * diagnostic association via `perFile`. Both are populated in the same
81
+ * single-pass walk over the batch — no extra cost.
82
+ */
83
+ export interface SetFilesResult {
84
+ /**
85
+ * IDs whose content or mode-specific cache key differed from the cached
86
+ * entry — the subset of input file IDs that actually triggered work.
87
+ * Empty when every file was a cache-hit no-op.
88
+ */
89
+ changedIds: ReadonlySet<string>;
90
+ /**
91
+ * Pre-flattened union of every file's `ingestDiagnostics`. Consumers
92
+ * can group by `Diagnostic.file` for per-file publish.
93
+ */
94
+ diagnostics: Array<Diagnostic>;
95
+ /**
96
+ * Per-file `SetFileResult` keyed by input file ID. Use this when the
97
+ * grouping `Diagnostic.file` would do isn't enough — e.g., LSP wanting
98
+ * to publish empty-diagnostic-list updates for files that ingested
99
+ * cleanly.
100
+ */
101
+ perFile: ReadonlyMap<string, SetFileResult>;
102
+ }
103
+ /**
104
+ * Per-call input to `query`.
105
+ */
106
+ export interface QueryOptions {
107
+ /** Behavior when duplicate declaration names are found across modules. */
108
+ onDuplicates?: OnDuplicates;
109
+ /** Per-call logger override (defaults to the session-level logger). */
110
+ log?: AnalysisLog;
111
+ }
112
+ /**
113
+ * Persistent analysis handle.
114
+ *
115
+ * **Concurrency**: not safe across overlapping calls. Serialize externally
116
+ * (each caller awaits the previous `setFile`/`setFiles` before starting the
117
+ * next). The LS underneath is sync, but the resolver phase awaits I/O for
118
+ * async resolvers (Vite/Rollup), so the session does cross await boundaries.
119
+ *
120
+ * **Cache-hit semantics**: per-entry, all-or-nothing. The implementation
121
+ * must not split the guarantee across separate caches (e.g. transform-cache
122
+ * hit + lex re-run). The match criterion is mode-discriminated:
123
+ *
124
+ * - lex+resolve mode: `existing.content === incoming.content` AND
125
+ * `existing.resolverIdentity === incoming.resolverIdentity`.
126
+ * - pre-resolved mode: `existing.content === incoming.content` AND
127
+ * `arraysShallowEqual(existing.preResolvedDepsSnapshot, incoming.dependencies)`.
128
+ *
129
+ * Mode flips (an entry previously ingested as lex+resolve now arrives with
130
+ * `dependencies`, or vice versa) always cache-miss.
131
+ *
132
+ * **Promise resolution**: `setFile` / `setFiles` resolve only after the
133
+ * serial LS push (phase 3) completes for every file in the batch. Awaiting
134
+ * the returned promise is sufficient — no separate flush step.
135
+ */
136
+ export interface AnalysisSession {
137
+ /**
138
+ * Ingest one file's content into the session. Idempotent on cache hit.
139
+ *
140
+ * @returns `{changed, diagnostics}` — `changed: false` indicates a
141
+ * cache-hit no-op where the cached ingest diagnostics are returned.
142
+ */
143
+ setFile(file: SourceFileInfo, opts?: SetFileOptions): Promise<SetFileResult>;
144
+ /**
145
+ * Ingest a batch of files. Additive — never removes; use `deleteFile` for
146
+ * removal. Cache hits are folded into the result with `changed: false`.
147
+ */
148
+ setFiles(files: ReadonlyArray<SourceFileInfo>, opts?: SetFileOptions): Promise<SetFilesResult>;
149
+ /** Drop a file from the session and evict from the LS. */
150
+ deleteFile(id: string): Promise<void>;
151
+ /** Whether the given file ID is currently owned by the session. */
152
+ has(id: string): boolean;
153
+ /** Snapshot of currently-owned file IDs (sort order is insertion order). */
154
+ list(): ReadonlyArray<string>;
155
+ /**
156
+ * Run a two-phase analysis pass against the current owned set.
157
+ *
158
+ * @returns analyzed modules and analysis-pass diagnostics. Ingest
159
+ * diagnostics from prior `setFile`/`setFiles` calls are NOT included
160
+ * here — concat with those returns for the full picture.
161
+ * @throws Error if `onDuplicates: 'throw'` and duplicates exist
162
+ */
163
+ query(opts?: QueryOptions): AnalyzeResultJson;
164
+ /**
165
+ * Concatenated ingest-time diagnostics across every owned entry — the
166
+ * cumulative view of every `setFile`/`setFiles` return, kept current as
167
+ * entries are added/replaced/deleted.
168
+ *
169
+ * Lets long-lived consumers (Vite plugin, LSP) publish the full ingest
170
+ * picture without tracking per-batch returns themselves. Cheap: walks
171
+ * the owned map.
172
+ */
173
+ allIngestDiagnostics(): Array<Diagnostic>;
174
+ /**
175
+ * Release LS resources and clear the owned set. The session must not be
176
+ * used after disposal.
177
+ */
178
+ dispose(): void;
179
+ }
180
+ /**
181
+ * Options for `createAnalysisSession`.
182
+ *
183
+ * `documentRegistry` flows through to the underlying `LanguageService` only.
184
+ * `tsconfig` and `compilerOptions` flow to both the LS *and* the lazy default
185
+ * `ImportResolver` (`getDefaultResolver` re-invokes `loadTsconfig` with them
186
+ * to produce a merged `ts.CompilerOptions` for module resolution). The two
187
+ * paths share the same merge semantics — user-supplied `compilerOptions`
188
+ * override parsed tsconfig keys, but never bypass the tsconfig.json file
189
+ * requirement.
190
+ *
191
+ * `projectRoot` and `virtualFiles` from the LS options shape are excluded —
192
+ * the session derives `projectRoot` from `sourceOptions` and manages
193
+ * svelte2tsx virtuals internally per file.
194
+ */
195
+ export interface AnalysisSessionOptions extends Omit<AnalysisLanguageServiceOptions, 'projectRoot' | 'virtualFiles'> {
196
+ /**
197
+ * Module source options for path extraction and source filtering.
198
+ *
199
+ * Must be a fully-constructed `ModuleSourceOptions` — the session re-runs
200
+ * `normalizeSourceOptions` (idempotent) but does not apply any defaults.
201
+ * Pass through `createSourceOptions(projectRoot, overrides?)` to merge with
202
+ * `DEFAULT_SOURCE_OPTIONS`. (The `Partial<SourceOptionsDefaults>` ergonomic
203
+ * shape exists only on `AnalyzeFromFilesOptions.sourceOptions`, where the
204
+ * defaults merge happens inside `analyzeFromFiles`.)
205
+ */
206
+ sourceOptions: ModuleSourceOptions;
207
+ /**
208
+ * Session-default custom import resolver used when no per-call override is
209
+ * supplied — a bare `ResolveImportFn` or a token-paired `ImportResolver`
210
+ * (see `ResolveImport`). A bare function is normalized once at construction,
211
+ * so its synthesized identity is stable for the session's lifetime (cache
212
+ * reuse works). When omitted, the session lazily constructs the TS+tsconfig
213
+ * default on first use.
214
+ */
215
+ resolveImport?: ResolveImport;
216
+ /** Optional logger for session-level messages. */
217
+ log?: AnalysisLog;
218
+ }
219
+ /**
220
+ * Create a persistent analysis session.
221
+ *
222
+ * @example Vite plugin integration
223
+ * ```ts
224
+ * const session = createAnalysisSession({sourceOptions, resolveImport, log});
225
+ * await session.setFiles(initialFiles);
226
+ * const result = session.query();
227
+ * // on watcher events:
228
+ * await session.setFile({id, content});
229
+ * await session.deleteFile(removedId);
230
+ * const next = session.query();
231
+ * // on shutdown:
232
+ * session.dispose();
233
+ * ```
234
+ *
235
+ * @example One-shot via the public wrapper
236
+ * ```ts
237
+ * // Equivalent to `analyze(...)` — the wrapper goes through a session internally.
238
+ * const session = createAnalysisSession({sourceOptions});
239
+ * try {
240
+ * await session.setFiles(sourceFiles);
241
+ * return session.query({onDuplicates: 'throw'});
242
+ * } finally {
243
+ * session.dispose();
244
+ * }
245
+ * ```
246
+ */
247
+ export declare const createAnalysisSession: (options: AnalysisSessionOptions) => AnalysisSession;
248
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAIN,KAAK,8BAA8B,EACnC,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,UAAU,CAAC;AAE1C,OAAO,EAEN,KAAK,aAAa,EAKlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,aAAa,CAAC;AAChD,OAAO,EAAC,KAAK,mBAAmB,EAAmC,MAAM,oBAAoB,CAAC;AAG9F,OAAO,EAGN,iBAAiB,EACjB,KAAK,YAAY,EACjB,MAAM,mBAAmB,CAAC;AAG3B;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC9B;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa;IAC7B,qFAAqF;IACrF,OAAO,EAAE,OAAO,CAAC;IACjB,oEAAoE;IACpE,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;CAC/B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