@codama/fragments 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.
- package/LICENSE +23 -0
- package/README.md +542 -0
- package/dist/index.browser.cjs +208 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.mjs +176 -0
- package/dist/index.browser.mjs.map +1 -0
- package/dist/index.node.cjs +195 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.mjs +163 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/index.react-native.mjs +176 -0
- package/dist/index.react-native.mjs.map +1 -0
- package/dist/javascript.browser.cjs +403 -0
- package/dist/javascript.browser.cjs.map +1 -0
- package/dist/javascript.browser.mjs +353 -0
- package/dist/javascript.browser.mjs.map +1 -0
- package/dist/javascript.node.cjs +390 -0
- package/dist/javascript.node.cjs.map +1 -0
- package/dist/javascript.node.mjs +340 -0
- package/dist/javascript.node.mjs.map +1 -0
- package/dist/javascript.react-native.mjs +353 -0
- package/dist/javascript.react-native.mjs.map +1 -0
- package/dist/rust.browser.cjs +371 -0
- package/dist/rust.browser.cjs.map +1 -0
- package/dist/rust.browser.mjs +322 -0
- package/dist/rust.browser.mjs.map +1 -0
- package/dist/rust.node.cjs +358 -0
- package/dist/rust.node.cjs.map +1 -0
- package/dist/rust.node.mjs +309 -0
- package/dist/rust.node.mjs.map +1 -0
- package/dist/rust.react-native.mjs +322 -0
- package/dist/rust.react-native.mjs.map +1 -0
- package/dist/types/core/BaseFragment.d.ts +21 -0
- package/dist/types/core/BaseFragment.d.ts.map +1 -0
- package/dist/types/core/casing.d.ts +52 -0
- package/dist/types/core/casing.d.ts.map +1 -0
- package/dist/types/core/createFragmentTemplate.d.ts +38 -0
- package/dist/types/core/createFragmentTemplate.d.ts.map +1 -0
- package/dist/types/core/fs.d.ts +28 -0
- package/dist/types/core/fs.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +9 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/mapFragmentContent.d.ts +43 -0
- package/dist/types/core/mapFragmentContent.d.ts.map +1 -0
- package/dist/types/core/path.d.ts +43 -0
- package/dist/types/core/path.d.ts.map +1 -0
- package/dist/types/core/renderMap.d.ts +61 -0
- package/dist/types/core/renderMap.d.ts.map +1 -0
- package/dist/types/core/setFragmentContent.d.ts +23 -0
- package/dist/types/core/setFragmentContent.d.ts.map +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/javascript/ImportMap.d.ts +61 -0
- package/dist/types/javascript/ImportMap.d.ts.map +1 -0
- package/dist/types/javascript/addToImportMap.d.ts +25 -0
- package/dist/types/javascript/addToImportMap.d.ts.map +1 -0
- package/dist/types/javascript/fragment.d.ts +135 -0
- package/dist/types/javascript/fragment.d.ts.map +1 -0
- package/dist/types/javascript/getDocblockFragment.d.ts +53 -0
- package/dist/types/javascript/getDocblockFragment.d.ts.map +1 -0
- package/dist/types/javascript/getExportAllFragment.d.ts +21 -0
- package/dist/types/javascript/getExportAllFragment.d.ts.map +1 -0
- package/dist/types/javascript/getExternalDependencies.d.ts +29 -0
- package/dist/types/javascript/getExternalDependencies.d.ts.map +1 -0
- package/dist/types/javascript/importMapToString.d.ts +40 -0
- package/dist/types/javascript/importMapToString.d.ts.map +1 -0
- package/dist/types/javascript/index.d.ts +23 -0
- package/dist/types/javascript/index.d.ts.map +1 -0
- package/dist/types/javascript/mergeImportMaps.d.ts +34 -0
- package/dist/types/javascript/mergeImportMaps.d.ts.map +1 -0
- package/dist/types/javascript/removeFromImportMap.d.ts +21 -0
- package/dist/types/javascript/removeFromImportMap.d.ts.map +1 -0
- package/dist/types/javascript/resolveImportMap.d.ts +33 -0
- package/dist/types/javascript/resolveImportMap.d.ts.map +1 -0
- package/dist/types/rust/ImportMap.d.ts +52 -0
- package/dist/types/rust/ImportMap.d.ts.map +1 -0
- package/dist/types/rust/addAliasToImportMap.d.ts +24 -0
- package/dist/types/rust/addAliasToImportMap.d.ts.map +1 -0
- package/dist/types/rust/addToImportMap.d.ts +27 -0
- package/dist/types/rust/addToImportMap.d.ts.map +1 -0
- package/dist/types/rust/fragment.d.ts +118 -0
- package/dist/types/rust/fragment.d.ts.map +1 -0
- package/dist/types/rust/getDocblockFragment.d.ts +53 -0
- package/dist/types/rust/getDocblockFragment.d.ts.map +1 -0
- package/dist/types/rust/getExternalDependencies.d.ts +30 -0
- package/dist/types/rust/getExternalDependencies.d.ts.map +1 -0
- package/dist/types/rust/importMapToString.d.ts +30 -0
- package/dist/types/rust/importMapToString.d.ts.map +1 -0
- package/dist/types/rust/index.d.ts +23 -0
- package/dist/types/rust/index.d.ts.map +1 -0
- package/dist/types/rust/mergeImportMaps.d.ts +23 -0
- package/dist/types/rust/mergeImportMaps.d.ts.map +1 -0
- package/dist/types/rust/removeFromImportMap.d.ts +20 -0
- package/dist/types/rust/removeFromImportMap.d.ts.map +1 -0
- package/dist/types/rust/resolveImportMap.d.ts +32 -0
- package/dist/types/rust/resolveImportMap.d.ts.map +1 -0
- package/package.json +106 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { BaseFragment } from './BaseFragment';
|
|
2
|
+
/**
|
|
3
|
+
* Apply a synchronous transformation to a fragment's `content`, returning a
|
|
4
|
+
* new fragment with every other field preserved.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam TFragment - The concrete fragment type. Must extend {@link BaseFragment}.
|
|
7
|
+
* @param fragment - The source fragment.
|
|
8
|
+
* @param mapContent - A function that receives the current content and
|
|
9
|
+
* returns the new content.
|
|
10
|
+
* @return A frozen fragment with the transformed content.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { mapFragmentContent } from '@codama/fragments';
|
|
15
|
+
*
|
|
16
|
+
* const trimmed = mapFragmentContent(fragment, c => c.trimEnd());
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @see {@link mapFragmentContentAsync} for the async variant.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mapFragmentContent<TFragment extends BaseFragment>(fragment: TFragment, mapContent: (content: string) => string): TFragment;
|
|
22
|
+
/**
|
|
23
|
+
* Async variant of {@link mapFragmentContent}: apply an async transformation
|
|
24
|
+
* to a fragment's `content`.
|
|
25
|
+
*
|
|
26
|
+
* @typeParam TFragment - The concrete fragment type. Must extend {@link BaseFragment}.
|
|
27
|
+
* @param fragment - The source fragment.
|
|
28
|
+
* @param mapContent - An async function that receives the current content
|
|
29
|
+
* and returns a promise resolving to the new content.
|
|
30
|
+
* @return A promise that resolves to a frozen fragment with the transformed
|
|
31
|
+
* content.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { mapFragmentContentAsync } from '@codama/fragments';
|
|
36
|
+
*
|
|
37
|
+
* const formatted = await mapFragmentContentAsync(fragment, formatWithPrettier);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @see {@link mapFragmentContent} for the sync variant.
|
|
41
|
+
*/
|
|
42
|
+
export declare function mapFragmentContentAsync<TFragment extends BaseFragment>(fragment: TFragment, mapContent: (content: string) => Promise<string>): Promise<TFragment>;
|
|
43
|
+
//# sourceMappingURL=mapFragmentContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapFragmentContent.d.ts","sourceRoot":"","sources":["../../../src/core/mapFragmentContent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,SAAS,YAAY,EAC7D,QAAQ,EAAE,SAAS,EACnB,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GACxC,SAAS,CAEX;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,uBAAuB,CAAC,SAAS,SAAS,YAAY,EACxE,QAAQ,EAAE,SAAS,EACnB,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GACjD,OAAO,CAAC,SAAS,CAAC,CAEpB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path manipulation helpers used by code generators to assemble output
|
|
3
|
+
* file paths.
|
|
4
|
+
*
|
|
5
|
+
* The {@link Path} type is a thin documentation alias for `string` —
|
|
6
|
+
* any place a generator stores or threads a filesystem-relative path,
|
|
7
|
+
* use this name to communicate intent. The {@link joinPath} and
|
|
8
|
+
* {@link pathDirectory} helpers delegate to `node:path` on Node and
|
|
9
|
+
* fall back to lightweight string manipulation on non-Node platforms.
|
|
10
|
+
*/
|
|
11
|
+
/** A filesystem path inside the generator's output tree. */
|
|
12
|
+
export type Path = string;
|
|
13
|
+
/**
|
|
14
|
+
* Join two or more path segments together. Uses `node:path`'s
|
|
15
|
+
* platform-aware {@link join} on Node; on other platforms (browser,
|
|
16
|
+
* react-native) falls back to a `/`-joined form with consecutive
|
|
17
|
+
* slashes collapsed.
|
|
18
|
+
*/
|
|
19
|
+
export declare function joinPath(...paths: Path[]): string;
|
|
20
|
+
/**
|
|
21
|
+
* Return the directory portion of a path (i.e. everything up to the
|
|
22
|
+
* last `/` segment). Uses `node:path`'s {@link dirname} on Node and a
|
|
23
|
+
* plain `lastIndexOf` fallback on other platforms.
|
|
24
|
+
*/
|
|
25
|
+
export declare function pathDirectory(path: Path): Path;
|
|
26
|
+
/**
|
|
27
|
+
* Return the trailing segment of a path (everything after the last
|
|
28
|
+
* `/`). Uses `node:path`'s {@link basename} on Node and a plain
|
|
29
|
+
* `lastIndexOf` fallback on other platforms.
|
|
30
|
+
*/
|
|
31
|
+
export declare function pathBasename(path: Path): Path;
|
|
32
|
+
/**
|
|
33
|
+
* Compute the POSIX-style relative path from `from` to `to`. Both
|
|
34
|
+
* arguments are treated as `/`-separated logical paths regardless of
|
|
35
|
+
* platform, so the result is consistent across operating systems —
|
|
36
|
+
* suitable for emitting into source code as an import specifier.
|
|
37
|
+
*
|
|
38
|
+
* Node only: non-Node platforms throw {@link CodamaError} because
|
|
39
|
+
* implementing a correct POSIX relative-path algorithm without
|
|
40
|
+
* `node:path` is non-trivial and no current consumer needs it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function relativePath(from: Path, to: Path): string;
|
|
43
|
+
//# sourceMappingURL=path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src/core/path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,4DAA4D;AAC5D,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAE1B;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAMjD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAM9C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAO7C;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,GAAG,MAAM,CAMzD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `RenderMap` is the in-memory data structure a code generator builds
|
|
3
|
+
* up before writing anything to disk: a frozen `ReadonlyMap` keyed by
|
|
4
|
+
* output path, with a `BaseFragment` (or a concrete subtype carrying
|
|
5
|
+
* imports / features / …) as the value. The helpers in this module are
|
|
6
|
+
* pure data operations — they construct, merge, transform, and query
|
|
7
|
+
* render maps without touching the filesystem.
|
|
8
|
+
*
|
|
9
|
+
* {@link writeRenderMap} is the single filesystem-touching entry point
|
|
10
|
+
* here: it walks a finished map and writes every entry. Renderers that
|
|
11
|
+
* tie a render map to a `Visitor` (see `@codama/renderers-core`) layer
|
|
12
|
+
* that on top.
|
|
13
|
+
*/
|
|
14
|
+
import type { BaseFragment } from './BaseFragment';
|
|
15
|
+
import { type Path } from './path';
|
|
16
|
+
/**
|
|
17
|
+
* A frozen map keyed by output {@link Path}, with each entry holding a
|
|
18
|
+
* fragment that will be written to that path. `TFragment` defaults to
|
|
19
|
+
* {@link BaseFragment} but generators typically pass a richer flavor
|
|
20
|
+
* (e.g. `Fragment` from `@codama/fragments/javascript`) to carry
|
|
21
|
+
* imports and other per-file metadata.
|
|
22
|
+
*/
|
|
23
|
+
export type RenderMap<TFragment extends BaseFragment> = ReadonlyMap<Path, TFragment>;
|
|
24
|
+
export declare function createRenderMap<TFragment extends BaseFragment = BaseFragment>(): RenderMap<TFragment>;
|
|
25
|
+
export declare function createRenderMap<TFragment extends BaseFragment>(path: Path, content: TFragment): RenderMap<TFragment>;
|
|
26
|
+
export declare function createRenderMap<TFragment extends BaseFragment>(entries: Record<Path, TFragment | undefined>): RenderMap<TFragment>;
|
|
27
|
+
/** Add or overwrite a single `(path, fragment)` entry. */
|
|
28
|
+
export declare function addToRenderMap<TFragment extends BaseFragment>(renderMap: RenderMap<TFragment>, path: Path, content: TFragment): RenderMap<TFragment>;
|
|
29
|
+
/** Remove the entry at `path`, returning a new frozen map. */
|
|
30
|
+
export declare function removeFromRenderMap<TFragment extends BaseFragment>(renderMap: RenderMap<TFragment>, path: Path): RenderMap<TFragment>;
|
|
31
|
+
/**
|
|
32
|
+
* Combine multiple render maps into one. Later maps overwrite earlier
|
|
33
|
+
* entries at the same path.
|
|
34
|
+
*/
|
|
35
|
+
export declare function mergeRenderMaps<TFragment extends BaseFragment>(renderMaps: RenderMap<TFragment>[]): RenderMap<TFragment>;
|
|
36
|
+
/** Transform every fragment in the map, preserving the keys. */
|
|
37
|
+
export declare function mapRenderMapFragment<TFragment extends BaseFragment>(renderMap: RenderMap<TFragment>, fn: (fragment: TFragment, path: Path) => TFragment): RenderMap<TFragment>;
|
|
38
|
+
/** Async variant of {@link mapRenderMapFragment}. */
|
|
39
|
+
export declare function mapRenderMapFragmentAsync<TFragment extends BaseFragment>(renderMap: RenderMap<TFragment>, fn: (fragment: TFragment, path: Path) => Promise<TFragment>): Promise<RenderMap<TFragment>>;
|
|
40
|
+
/** Transform the `content` of every fragment in the map. */
|
|
41
|
+
export declare function mapRenderMapContent<TFragment extends BaseFragment>(renderMap: RenderMap<TFragment>, fn: (content: string, path: Path) => string): RenderMap<TFragment>;
|
|
42
|
+
/** Async variant of {@link mapRenderMapContent}. */
|
|
43
|
+
export declare function mapRenderMapContentAsync<TFragment extends BaseFragment>(renderMap: RenderMap<TFragment>, fn: (content: string, path: Path) => Promise<string>): Promise<RenderMap<TFragment>>;
|
|
44
|
+
/**
|
|
45
|
+
* Look up the fragment at `path`, throwing a structured
|
|
46
|
+
* {@link CodamaError} when the key is missing.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getFromRenderMap<TFragment extends BaseFragment>(renderMap: RenderMap<TFragment>, path: Path): TFragment;
|
|
49
|
+
/**
|
|
50
|
+
* Test whether the fragment at `path` contains `value`. Accepts either
|
|
51
|
+
* a plain substring or a regular expression.
|
|
52
|
+
*/
|
|
53
|
+
export declare function renderMapContains<TFragment extends BaseFragment>(renderMap: RenderMap<TFragment>, path: Path, value: RegExp | string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Walk the render map and write every entry to disk, rooted at
|
|
56
|
+
* `basePath`. Each path is joined with `basePath` via {@link joinPath}
|
|
57
|
+
* and written via {@link writeFile}; the directory structure is
|
|
58
|
+
* created on demand.
|
|
59
|
+
*/
|
|
60
|
+
export declare function writeRenderMap<TFragment extends BaseFragment>(renderMap: RenderMap<TFragment>, basePath: Path): void;
|
|
61
|
+
//# sourceMappingURL=renderMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderMap.d.ts","sourceRoot":"","sources":["../../../src/core/renderMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,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AE,QAAQ,EAAE,IAAI,GAAG,IAAI,CAIpH"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BaseFragment } from './BaseFragment';
|
|
2
|
+
/**
|
|
3
|
+
* Return a new frozen fragment whose `content` field has been replaced with
|
|
4
|
+
* `content`, preserving every other field of the input fragment.
|
|
5
|
+
*
|
|
6
|
+
* The output keeps the input's exact concrete type (`TFragment`) so callers
|
|
7
|
+
* never lose any extra fields a flavored fragment may carry (imports,
|
|
8
|
+
* features, etc.).
|
|
9
|
+
*
|
|
10
|
+
* @typeParam TFragment - The concrete fragment type. Must extend {@link BaseFragment}.
|
|
11
|
+
* @param fragment - The source fragment to copy.
|
|
12
|
+
* @param content - The new code string.
|
|
13
|
+
* @return A frozen fragment of the same shape as `fragment` with `content` replaced.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { setFragmentContent } from '@codama/fragments';
|
|
18
|
+
*
|
|
19
|
+
* const next = setFragmentContent(prev, prev.content.toUpperCase());
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function setFragmentContent<TFragment extends BaseFragment>(fragment: TFragment, content: string): TFragment;
|
|
23
|
+
//# sourceMappingURL=setFragmentContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setFragmentContent.d.ts","sourceRoot":"","sources":["../../../src/core/setFragmentContent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,SAAS,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAElH"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@codama/fragments`
|
|
3
|
+
*
|
|
4
|
+
* The root entrypoint exposes only the language-agnostic core primitives
|
|
5
|
+
* (`BaseFragment`, `createFragmentTemplate`, `mapFragmentContent`, etc.).
|
|
6
|
+
* Language-aware code — concrete `Fragment` types, `ImportMap` shapes, and
|
|
7
|
+
* `fragment` tagged templates — lives under language subpaths:
|
|
8
|
+
*
|
|
9
|
+
* import { fragment, use, renderPage } from '@codama/fragments/javascript';
|
|
10
|
+
* import { fragment, addFragmentImports } from '@codama/fragments/rust';
|
|
11
|
+
*
|
|
12
|
+
* Generators that don't need language-specific behavior — for example,
|
|
13
|
+
* because they only manipulate the shared `BaseFragment` shape — should
|
|
14
|
+
* import from this root entrypoint.
|
|
15
|
+
*/
|
|
16
|
+
export * from './core';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The data model used by `@codama/fragments/javascript` to track imports
|
|
3
|
+
* symbolically until they are stringified into actual `import { … } from '…';`
|
|
4
|
+
* lines.
|
|
5
|
+
*
|
|
6
|
+
* Imports are accumulated as a `ReadonlyMap<Module, ReadonlyMap<UsedIdentifier, ImportInfo>>`:
|
|
7
|
+
* outer key is the source module, inner key is the identifier used in the
|
|
8
|
+
* consuming code (which may differ from the imported name via aliasing).
|
|
9
|
+
*
|
|
10
|
+
* The format accepted by {@link parseImportInput} is a single string with
|
|
11
|
+
* the same shorthand TypeScript itself uses inside an `import { … }` block:
|
|
12
|
+
*
|
|
13
|
+
* `Foo` — value import; used as `Foo`
|
|
14
|
+
* `type Foo` — type-only import; used as `Foo`
|
|
15
|
+
* `Foo as Bar` — value import aliased; used as `Bar`
|
|
16
|
+
* `type Foo as Bar` — type-only import aliased; used as `Bar`
|
|
17
|
+
*/
|
|
18
|
+
/** A single import shorthand string. See the file-level docblock for the accepted forms. */
|
|
19
|
+
export type ImportInput = string;
|
|
20
|
+
/** A module path: either an absolute (`@scope/pkg`, `pkg`, `pkg/sub`) or a relative (`./foo`, `../bar`) specifier. */
|
|
21
|
+
export type Module = string;
|
|
22
|
+
/** The identifier as it appears in the consuming code (after aliasing). */
|
|
23
|
+
export type UsedIdentifier = string;
|
|
24
|
+
/** A parsed import shorthand. */
|
|
25
|
+
export interface ImportInfo {
|
|
26
|
+
readonly importedIdentifier: string;
|
|
27
|
+
readonly isType: boolean;
|
|
28
|
+
readonly usedIdentifier: UsedIdentifier;
|
|
29
|
+
}
|
|
30
|
+
/** A symbolic import map keyed by module, then by used identifier. */
|
|
31
|
+
export type ImportMap = ReadonlyMap<Module, ReadonlyMap<UsedIdentifier, ImportInfo>>;
|
|
32
|
+
/**
|
|
33
|
+
* Construct an empty, frozen import map.
|
|
34
|
+
*
|
|
35
|
+
* @return A new {@link ImportMap} with no entries.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { createImportMap } from '@codama/fragments/javascript';
|
|
40
|
+
*
|
|
41
|
+
* const empty = createImportMap();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createImportMap(): ImportMap;
|
|
45
|
+
/**
|
|
46
|
+
* Parse a single import shorthand (e.g. `'type Foo as Bar'`) into a
|
|
47
|
+
* structured {@link ImportInfo}.
|
|
48
|
+
*
|
|
49
|
+
* @param input - The shorthand string to parse.
|
|
50
|
+
* @return The parsed info. If the shorthand can't be matched (e.g. it
|
|
51
|
+
* contains illegal whitespace), the entire string is returned unchanged as
|
|
52
|
+
* both the imported and used identifier, with `isType: false`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* parseImportInput('Foo'); // { importedIdentifier: 'Foo', usedIdentifier: 'Foo', isType: false }
|
|
57
|
+
* parseImportInput('type Foo as Bar'); // { importedIdentifier: 'Foo', usedIdentifier: 'Bar', isType: true }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseImportInput(input: ImportInput): ImportInfo;
|
|
61
|
+
//# sourceMappingURL=ImportMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportMap.d.ts","sourceRoot":"","sources":["../../../src/javascript/ImportMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,4FAA4F;AAC5F,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,sHAAsH;AACtH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAE5B,2EAA2E;AAC3E,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC,iCAAiC;AACjC,MAAM,WAAW,UAAU;IACvB,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;CAC3C;AAED,sEAAsE;AACtE,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC,CAAC;AAErF;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,IAAI,SAAS,CAE3C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CAe/D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ImportInput, ImportMap, Module } from './ImportMap';
|
|
2
|
+
/**
|
|
3
|
+
* Append imports to a module entry, returning a new frozen import map. The
|
|
4
|
+
* input map is not mutated.
|
|
5
|
+
*
|
|
6
|
+
* Within a single batch, the same conflict-resolution rule that
|
|
7
|
+
* {@link mergeImportMaps} uses is applied — a value import always wins over
|
|
8
|
+
* a type-only import of the same identifier — so callers don't have to
|
|
9
|
+
* worry about input order when passing both.
|
|
10
|
+
*
|
|
11
|
+
* @param importMap - The import map to extend.
|
|
12
|
+
* @param module - The source module the imports come from.
|
|
13
|
+
* @param imports - The shorthand strings to add. Empty array short-circuits
|
|
14
|
+
* and returns `importMap` unchanged.
|
|
15
|
+
* @return A frozen import map that includes the new entries.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { addToImportMap, createImportMap } from '@codama/fragments/javascript';
|
|
20
|
+
*
|
|
21
|
+
* const map = addToImportMap(createImportMap(), './foo', ['type Foo', 'Bar']);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function addToImportMap(importMap: ImportMap, module: Module, imports: ImportInput[]): ImportMap;
|
|
25
|
+
//# sourceMappingURL=addToImportMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addToImportMap.d.ts","sourceRoot":"","sources":["../../../src/javascript/addToImportMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,WAAW,EAAE,SAAS,EAAE,MAAM,EAAkB,MAAM,aAAa,CAAC;AAI9F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,SAAS,CAWtG"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { BaseFragment } from '../core/BaseFragment';
|
|
2
|
+
import type { ImportInput, ImportMap, Module, UsedIdentifier } from './ImportMap';
|
|
3
|
+
/**
|
|
4
|
+
* The JavaScript-flavored fragment shape: {@link BaseFragment} plus a
|
|
5
|
+
* symbolic {@link ImportMap} carrying the imports the content depends on.
|
|
6
|
+
*
|
|
7
|
+
* Fragments are frozen and composable — interpolating one into another
|
|
8
|
+
* (via the {@link fragment} tag) propagates both content and imports, so
|
|
9
|
+
* generators can build code top-down without threading import bookkeeping
|
|
10
|
+
* through every helper.
|
|
11
|
+
*/
|
|
12
|
+
export type Fragment = BaseFragment & Readonly<{
|
|
13
|
+
imports: ImportMap;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Type guard for the JavaScript-flavored {@link Fragment} shape.
|
|
17
|
+
*
|
|
18
|
+
* @param value - The value to test.
|
|
19
|
+
* @return `true` when `value` is an object carrying both `content` and
|
|
20
|
+
* `imports` fields. The check is structural; downstream code that layers
|
|
21
|
+
* extra fields on top (e.g. a renderer's `features` set) will still match.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isFragment(value: unknown): value is Fragment;
|
|
24
|
+
/**
|
|
25
|
+
* Tagged-template helper for composing JavaScript-flavored fragments.
|
|
26
|
+
* Interpolated values may be:
|
|
27
|
+
*
|
|
28
|
+
* - A {@link Fragment} — content is inlined and imports propagate.
|
|
29
|
+
* - `undefined` — rendered as the empty string (handy for optional
|
|
30
|
+
* sub-fragments).
|
|
31
|
+
* - Anything else — coerced to a string via `String(value)`.
|
|
32
|
+
*
|
|
33
|
+
* @param template - The template-strings array supplied by the tag call site.
|
|
34
|
+
* @param items - The interpolated values, in order.
|
|
35
|
+
* @return A frozen {@link Fragment} with the merged content and imports.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { fragment, use } from '@codama/fragments/javascript';
|
|
40
|
+
*
|
|
41
|
+
* const pdaLink = use('type PdaLinkNode', '../linkNodes/PdaLinkNode');
|
|
42
|
+
* const body = fragment`
|
|
43
|
+
* export interface AccountNode {
|
|
44
|
+
* readonly pda?: ${pdaLink};
|
|
45
|
+
* }
|
|
46
|
+
* `;
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function fragment(template: TemplateStringsArray, ...items: unknown[]): Fragment;
|
|
50
|
+
/**
|
|
51
|
+
* Combine multiple fragments into one. The merge strategy for content is
|
|
52
|
+
* supplied by the caller (`mergeContent`); imports are merged automatically
|
|
53
|
+
* via {@link mergeImportMaps}. Undefined inputs are skipped.
|
|
54
|
+
*
|
|
55
|
+
* @param fragments - The fragments to merge, in order.
|
|
56
|
+
* @param mergeContent - A function that produces the final content string
|
|
57
|
+
* from each surviving fragment's content.
|
|
58
|
+
* @return A frozen merged {@link Fragment}.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { fragment, mergeFragments } from '@codama/fragments/javascript';
|
|
63
|
+
*
|
|
64
|
+
* const merged = mergeFragments(
|
|
65
|
+
* [fragment`a`, fragment`b`, fragment`c`],
|
|
66
|
+
* parts => parts.join(', '),
|
|
67
|
+
* );
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function mergeFragments(fragments: readonly (Fragment | undefined)[], mergeContent: (contents: string[]) => string): Fragment;
|
|
71
|
+
/**
|
|
72
|
+
* Construct a fragment whose content is a single imported identifier and
|
|
73
|
+
* whose import map carries the corresponding import statement.
|
|
74
|
+
*
|
|
75
|
+
* The shorthand accepted in `importInput` is the same as
|
|
76
|
+
* {@link parseImportInput}'s — bare names, `type`-prefixed names, and
|
|
77
|
+
* `as`-aliased names are all supported.
|
|
78
|
+
*
|
|
79
|
+
* @param importInput - The import shorthand (e.g. `'Foo'`, `'type Foo'`,
|
|
80
|
+
* `'Foo as Bar'`).
|
|
81
|
+
* @param module - The module the identifier comes from.
|
|
82
|
+
* @return A frozen {@link Fragment} ready to be interpolated into other
|
|
83
|
+
* fragments.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* import { use } from '@codama/fragments/javascript';
|
|
88
|
+
*
|
|
89
|
+
* use('PdaLinkNode', '../linkNodes/PdaLinkNode');
|
|
90
|
+
* // → content: 'PdaLinkNode'
|
|
91
|
+
* // imports: { '../linkNodes/PdaLinkNode' → PdaLinkNode (value) }
|
|
92
|
+
*
|
|
93
|
+
* use('type Foo as Bar', './foo');
|
|
94
|
+
* // → content: 'Bar'
|
|
95
|
+
* // imports: { './foo' → Foo as Bar (type-only) }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function use(importInput: ImportInput, module: Module): Fragment;
|
|
99
|
+
/**
|
|
100
|
+
* Append imports to an existing fragment's import map. The fragment's
|
|
101
|
+
* content and any other fields are preserved.
|
|
102
|
+
*
|
|
103
|
+
* @param fragment - The source fragment.
|
|
104
|
+
* @param module - The module the new imports come from.
|
|
105
|
+
* @param imports - The import shorthand strings to add.
|
|
106
|
+
* @return A new frozen fragment with the extended import map.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { addFragmentImports, fragment } from '@codama/fragments/javascript';
|
|
111
|
+
*
|
|
112
|
+
* const f = addFragmentImports(fragment`hello`, './foo', ['Foo']);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function addFragmentImports(fragment: Fragment, module: Module, imports: ImportInput[]): Fragment;
|
|
116
|
+
/**
|
|
117
|
+
* Merge additional import maps into an existing fragment's import map. The
|
|
118
|
+
* fragment's content and any other fields are preserved.
|
|
119
|
+
*
|
|
120
|
+
* @param fragment - The source fragment.
|
|
121
|
+
* @param importMaps - The additional maps to merge in.
|
|
122
|
+
* @return A new frozen fragment with the merged import map.
|
|
123
|
+
*/
|
|
124
|
+
export declare function mergeFragmentImports(fragment: Fragment, importMaps: readonly ImportMap[]): Fragment;
|
|
125
|
+
/**
|
|
126
|
+
* Drop identifiers from a fragment's import map. The fragment's content and
|
|
127
|
+
* any other fields are preserved.
|
|
128
|
+
*
|
|
129
|
+
* @param fragment - The source fragment.
|
|
130
|
+
* @param module - The module to remove identifiers from.
|
|
131
|
+
* @param usedIdentifiers - The used-identifier names to drop.
|
|
132
|
+
* @return A new frozen fragment with the trimmed import map.
|
|
133
|
+
*/
|
|
134
|
+
export declare function removeFragmentImports(fragment: Fragment, module: Module, usedIdentifiers: UsedIdentifier[]): Fragment;
|
|
135
|
+
//# sourceMappingURL=fragment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|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qB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,GAAG,QAAQ,CAKrH"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Fragment } from './fragment';
|
|
2
|
+
/**
|
|
3
|
+
* Build a JSDoc-style docblock fragment from an array of lines.
|
|
4
|
+
*
|
|
5
|
+
* Empty or `undefined` input returns `undefined` so the helper composes
|
|
6
|
+
* naturally with the {@link fragment} tag's optional-interpolation
|
|
7
|
+
* behavior — a node's `docs` attribute can be threaded straight in
|
|
8
|
+
* without a ternary guard:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* fragment`${getDocblockFragment(node.docs)}\nexport interface X {}`;
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Single-line input renders as a one-line block (`/** line *\/`);
|
|
15
|
+
* multi-line input renders as a standard multi-line JSDoc block. Empty
|
|
16
|
+
* elements in the array render as bare ` *` lines, useful for paragraph
|
|
17
|
+
* breaks inside a docblock.
|
|
18
|
+
*
|
|
19
|
+
* The helper defangs any literal `*\/` sequences inside the lines (they are
|
|
20
|
+
* rewritten as `*\\/`) so that user-supplied content cannot accidentally
|
|
21
|
+
* close the docblock early.
|
|
22
|
+
*
|
|
23
|
+
* @param lines - The lines of the docblock, or `undefined`. Empty array
|
|
24
|
+
* and `undefined` both return `undefined`.
|
|
25
|
+
* @param options - Optional settings.
|
|
26
|
+
* @param options.withLineJump - When `true`, appends a trailing `\n` after
|
|
27
|
+
* the closing `*\/`. Useful when the docblock is followed by a same-line
|
|
28
|
+
* item like an enum variant.
|
|
29
|
+
* @return A {@link Fragment} carrying the rendered docblock, or `undefined`
|
|
30
|
+
* when `lines` is empty or `undefined`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { getDocblockFragment } from '@codama/fragments/javascript';
|
|
35
|
+
*
|
|
36
|
+
* getDocblockFragment(['Greets the user.'])?.content;
|
|
37
|
+
* // /** Greets the user. *\/
|
|
38
|
+
*
|
|
39
|
+
* getDocblockFragment(['First line.', '', 'Second paragraph.'])?.content;
|
|
40
|
+
* // /**
|
|
41
|
+
* // * First line.
|
|
42
|
+
* // *
|
|
43
|
+
* // * Second paragraph.
|
|
44
|
+
* // *\/
|
|
45
|
+
*
|
|
46
|
+
* getDocblockFragment(undefined);
|
|
47
|
+
* // undefined
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function getDocblockFragment(lines: readonly string[] | undefined, options?: {
|
|
51
|
+
withLineJump?: boolean;
|
|
52
|
+
}): Fragment | undefined;
|
|
53
|
+
//# sourceMappingURL=getDocblockFragment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDocblockFragment.d.ts","sourceRoot":"","sources":["../../../src/javascript/getDocblockFragment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EACpC,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACzC,QAAQ,GAAG,SAAS,CAOtB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Fragment } from './fragment';
|
|
2
|
+
/**
|
|
3
|
+
* Build a fragment that re-exports every binding from a module:
|
|
4
|
+
* `export * from '<module>';`.
|
|
5
|
+
*
|
|
6
|
+
* The fragment carries no imports — `export * from` only forwards bindings
|
|
7
|
+
* out, it does not bring `module` into local scope.
|
|
8
|
+
*
|
|
9
|
+
* @param module - The module specifier being re-exported.
|
|
10
|
+
* @return A {@link Fragment} whose content is `export * from '<module>';`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { getExportAllFragment } from '@codama/fragments/javascript';
|
|
15
|
+
*
|
|
16
|
+
* getExportAllFragment('./accounts').content;
|
|
17
|
+
* // export * from './accounts';
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function getExportAllFragment(module: string): Fragment;
|
|
21
|
+
//# sourceMappingURL=getExportAllFragment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getExportAllFragment.d.ts","sourceRoot":"","sources":["../../../src/javascript/getExportAllFragment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAE7D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ImportMap } from './ImportMap';
|
|
2
|
+
/**
|
|
3
|
+
* Compute the set of external (non-relative) module specifiers an import
|
|
4
|
+
* map references, with dependency-map resolution applied first. The
|
|
5
|
+
* returned values are *root* package names — for `'@scope/pkg/sub'` the
|
|
6
|
+
* value is `'@scope/pkg'`, and for `'pkg/sub'` it is `'pkg'`.
|
|
7
|
+
*
|
|
8
|
+
* Useful for syncing a renderer's generated `package.json` from the
|
|
9
|
+
* imports it ends up emitting.
|
|
10
|
+
*
|
|
11
|
+
* @param importMap - The import map to inspect.
|
|
12
|
+
* @param dependencies - The dependency map to apply before extracting
|
|
13
|
+
* names. Defaults to no resolution.
|
|
14
|
+
* @return A {@link Set} of external root package names.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { addToImportMap, createImportMap, getExternalDependencies } from '@codama/fragments/javascript';
|
|
19
|
+
*
|
|
20
|
+
* let map = createImportMap();
|
|
21
|
+
* map = addToImportMap(map, '@solana/kit', ['Address']);
|
|
22
|
+
* map = addToImportMap(map, '@solana/kit/program-client-core', ['ProgramClient']);
|
|
23
|
+
* map = addToImportMap(map, '../shared', ['Local']);
|
|
24
|
+
* getExternalDependencies(map);
|
|
25
|
+
* // → Set { '@solana/kit' }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function getExternalDependencies(importMap: ImportMap, dependencies?: Record<string, string>): Set<string>;
|
|
29
|
+
//# sourceMappingURL=getExternalDependencies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getExternalDependencies.d.ts","sourceRoot":"","sources":["../../../src/javascript/getExternalDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,SAAS,EAAE,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAUpH"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ImportMap } from './ImportMap';
|
|
2
|
+
/**
|
|
3
|
+
* Render an import map as a block of TypeScript `import { … } from '…';`
|
|
4
|
+
* statements.
|
|
5
|
+
*
|
|
6
|
+
* The map is first resolved against `dependencies` so symbolic module
|
|
7
|
+
* names (e.g. `'solanaAddresses'`, `'generatedAccounts'`) expand to real
|
|
8
|
+
* specifiers; renderers that don't use symbolic names can omit the
|
|
9
|
+
* argument.
|
|
10
|
+
*
|
|
11
|
+
* Output rules:
|
|
12
|
+
* - Modules are sorted with non-relative paths first, then relative;
|
|
13
|
+
* within each group, alphabetical.
|
|
14
|
+
* - Identifiers within each module are alphabetical.
|
|
15
|
+
* - When every import from a given module is type-only, the line is
|
|
16
|
+
* emitted as `import type { … } from '…';` rather than per-identifier
|
|
17
|
+
* `type` — matching the `@solana/eslint-config-solana`
|
|
18
|
+
* consolidate-type-imports convention used across the Codama
|
|
19
|
+
* published surface.
|
|
20
|
+
*
|
|
21
|
+
* @param importMap - The import map to render.
|
|
22
|
+
* @param dependencies - The dependency map to apply before rendering.
|
|
23
|
+
* Defaults to no resolution.
|
|
24
|
+
* @return The block of import lines, or the empty string if the map is
|
|
25
|
+
* empty.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { addToImportMap, createImportMap, importMapToString } from '@codama/fragments/javascript';
|
|
30
|
+
*
|
|
31
|
+
* let map = createImportMap();
|
|
32
|
+
* map = addToImportMap(map, '@codama/spec', ['type Spec']);
|
|
33
|
+
* map = addToImportMap(map, '../shared', ['CamelCaseString']);
|
|
34
|
+
* importMapToString(map);
|
|
35
|
+
* // import type { Spec } from '@codama/spec';
|
|
36
|
+
* // import { CamelCaseString } from '../shared';
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function importMapToString(importMap: ImportMap, dependencies?: Record<string, string>): string;
|
|
40
|
+
//# sourceMappingURL=importMapToString.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importMapToString.d.ts","sourceRoot":"","sources":["../../../src/javascript/importMapToString.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,aAAa,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,SAAS,EAAE,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,MAAM,CAoBzG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@codama/fragments/javascript`
|
|
3
|
+
*
|
|
4
|
+
* The JavaScript / TypeScript flavor of the fragment library: a concrete
|
|
5
|
+
* `Fragment` type carrying a symbolic `ImportMap`, a `fragment` tagged
|
|
6
|
+
* template that propagates imports through interpolation, and helpers
|
|
7
|
+
* for building, merging, resolving, and rendering imports.
|
|
8
|
+
*
|
|
9
|
+
* Re-exports the language-agnostic core too, so consumers only need a
|
|
10
|
+
* single import in the typical case.
|
|
11
|
+
*/
|
|
12
|
+
export * from '../core';
|
|
13
|
+
export * from './ImportMap';
|
|
14
|
+
export * from './addToImportMap';
|
|
15
|
+
export * from './mergeImportMaps';
|
|
16
|
+
export * from './removeFromImportMap';
|
|
17
|
+
export * from './resolveImportMap';
|
|
18
|
+
export * from './getExternalDependencies';
|
|
19
|
+
export * from './importMapToString';
|
|
20
|
+
export * from './fragment';
|
|
21
|
+
export * from './getDocblockFragment';
|
|
22
|
+
export * from './getExportAllFragment';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/javascript/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC"}
|