jsii-rosetta 5.4.32-dev.3 → 5.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -2
- package/lib/commands/convert.js +1 -2
- package/lib/commands/convert.js.map +1 -1
- package/lib/commands/coverage.js +1 -2
- package/lib/commands/coverage.js.map +1 -1
- package/lib/commands/extract.js +2 -3
- package/lib/commands/extract.js.map +1 -1
- package/lib/commands/infuse.js +2 -2
- package/lib/commands/infuse.js.map +1 -1
- package/lib/commands/read.js +1 -2
- package/lib/commands/read.js.map +1 -1
- package/lib/commands/transliterate.js +1 -2
- package/lib/commands/transliterate.js.map +1 -1
- package/lib/commands/trim-cache.js +1 -2
- package/lib/commands/trim-cache.js.map +1 -1
- package/lib/find-utils.js +4 -5
- package/lib/find-utils.js.map +1 -1
- package/lib/fixtures.js +1 -2
- package/lib/fixtures.js.map +1 -1
- package/lib/jsii/assemblies.js +9 -9
- package/lib/jsii/assemblies.js.map +1 -1
- package/lib/jsii/jsii-types.js +2 -3
- package/lib/jsii/jsii-types.js.map +1 -1
- package/lib/jsii/jsii-utils.js +15 -16
- package/lib/jsii/jsii-utils.js.map +1 -1
- package/lib/jsii/packages.js +1 -2
- package/lib/jsii/packages.js.map +1 -1
- package/lib/json.d.ts +0 -2
- package/lib/json.js +2 -3
- package/lib/json.js.map +1 -1
- package/lib/languages/target-language.js +3 -3
- package/lib/languages/target-language.js.map +1 -1
- package/lib/logging.js +6 -6
- package/lib/logging.js.map +1 -1
- package/lib/markdown/escapes.js +2 -3
- package/lib/markdown/escapes.js.map +1 -1
- package/lib/markdown/extract-snippets.js +1 -2
- package/lib/markdown/extract-snippets.js.map +1 -1
- package/lib/markdown/index.js +3 -4
- package/lib/markdown/index.js.map +1 -1
- package/lib/markdown/markdown-renderer.js +5 -5
- package/lib/markdown/markdown-renderer.js.map +1 -1
- package/lib/markdown/markdown.js +5 -6
- package/lib/markdown/markdown.js.map +1 -1
- package/lib/o-tree.js +2 -2
- package/lib/o-tree.js.map +1 -1
- package/lib/renderer.js +3 -2
- package/lib/renderer.js.map +1 -1
- package/lib/rosetta-reader.d.ts +0 -1
- package/lib/snippet-dependencies.js +5 -6
- package/lib/snippet-dependencies.js.map +1 -1
- package/lib/snippet-selectors.js +4 -5
- package/lib/snippet-selectors.js.map +1 -1
- package/lib/snippet.js +11 -11
- package/lib/snippet.js.map +1 -1
- package/lib/strict.js +1 -2
- package/lib/strict.js.map +1 -1
- package/lib/support.js +1 -2
- package/lib/support.js.map +1 -1
- package/lib/tablets/key.js +1 -2
- package/lib/tablets/key.js.map +1 -1
- package/lib/translate.js +4 -4
- package/lib/translate.js.map +1 -1
- package/lib/translate_all.js +1 -2
- package/lib/translate_all.js.map +1 -1
- package/lib/translate_all_worker.js +1 -2
- package/lib/translate_all_worker.js.map +1 -1
- package/lib/typescript/ast-utils.d.ts +1 -1
- package/lib/typescript/ast-utils.js +23 -23
- package/lib/typescript/ast-utils.js.map +1 -1
- package/lib/typescript/imports.d.ts +2 -2
- package/lib/typescript/imports.js +2 -3
- package/lib/typescript/imports.js.map +1 -1
- package/lib/typescript/types.js +16 -17
- package/lib/typescript/types.js.map +1 -1
- package/lib/typescript/visible-spans.js +4 -4
- package/lib/typescript/visible-spans.js.map +1 -1
- package/lib/util.d.ts +0 -1
- package/lib/util.js +19 -19
- package/lib/util.js.map +1 -1
- package/package.json +4 -4
- package/releases.json +4 -3
package/lib/jsii/assemblies.js
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.EXAMPLE_METADATA_JSDOCTAG = void 0;
|
4
|
+
exports.loadAssemblies = loadAssemblies;
|
5
|
+
exports.loadAllDefaultTablets = loadAllDefaultTablets;
|
6
|
+
exports.guessTabletLocation = guessTabletLocation;
|
7
|
+
exports.compressedTabletExists = compressedTabletExists;
|
8
|
+
exports.allSnippetSources = allSnippetSources;
|
9
|
+
exports.allTypeScriptSnippets = allTypeScriptSnippets;
|
10
|
+
exports.findTypeLookupAssembly = findTypeLookupAssembly;
|
11
|
+
exports.findContainingSubmodule = findContainingSubmodule;
|
4
12
|
const node_fs_1 = require("node:fs");
|
5
13
|
const fs = require("node:fs");
|
6
14
|
const path = require("node:path");
|
@@ -45,7 +53,6 @@ function loadAssemblies(assemblyLocations, validateAssemblies) {
|
|
45
53
|
return { assembly, directory, packageJson };
|
46
54
|
}
|
47
55
|
}
|
48
|
-
exports.loadAssemblies = loadAssemblies;
|
49
56
|
/**
|
50
57
|
* Load the default tablets for every assembly, if available
|
51
58
|
*
|
@@ -54,7 +61,6 @@ exports.loadAssemblies = loadAssemblies;
|
|
54
61
|
async function loadAllDefaultTablets(asms) {
|
55
62
|
return (0, util_1.mkDict)(await Promise.all(asms.map(async (a) => [a.directory, await tablets_1.LanguageTablet.fromOptionalFile(guessTabletLocation(a.directory))])));
|
56
63
|
}
|
57
|
-
exports.loadAllDefaultTablets = loadAllDefaultTablets;
|
58
64
|
/**
|
59
65
|
* Returns the location of the tablet file, either .jsii.tabl.json or .jsii.tabl.json.gz.
|
60
66
|
* Assumes that a tablet exists in the directory and if not, the ensuing behavior is
|
@@ -65,11 +71,9 @@ function guessTabletLocation(directory) {
|
|
65
71
|
? path.join(directory, tablets_1.DEFAULT_TABLET_NAME_COMPRESSED)
|
66
72
|
: path.join(directory, tablets_1.DEFAULT_TABLET_NAME);
|
67
73
|
}
|
68
|
-
exports.guessTabletLocation = guessTabletLocation;
|
69
74
|
function compressedTabletExists(directory) {
|
70
75
|
return fs.existsSync(path.join(directory, tablets_1.DEFAULT_TABLET_NAME_COMPRESSED));
|
71
76
|
}
|
72
|
-
exports.compressedTabletExists = compressedTabletExists;
|
73
77
|
/**
|
74
78
|
* Return all markdown and example snippets from the given assembly
|
75
79
|
*/
|
@@ -145,7 +149,6 @@ function allSnippetSources(assembly) {
|
|
145
149
|
}
|
146
150
|
}
|
147
151
|
}
|
148
|
-
exports.allSnippetSources = allSnippetSources;
|
149
152
|
async function allTypeScriptSnippets(assemblies, loose = false) {
|
150
153
|
return Promise.all(assemblies
|
151
154
|
.flatMap((loaded) => allSnippetSources(loaded.assembly).map((source) => ({ source, loaded })))
|
@@ -174,7 +177,6 @@ async function allTypeScriptSnippets(assemblies, loose = false) {
|
|
174
177
|
return (0, fixtures_1.fixturize)(snippet, ignoreFixtureErrors);
|
175
178
|
}));
|
176
179
|
}
|
177
|
-
exports.allTypeScriptSnippets = allTypeScriptSnippets;
|
178
180
|
const MAX_ASM_CACHE = 3;
|
179
181
|
const ASM_CACHE = [];
|
180
182
|
/**
|
@@ -203,7 +205,6 @@ function findTypeLookupAssembly(startingDirectory) {
|
|
203
205
|
ASM_CACHE.unshift(loaded);
|
204
206
|
return loaded;
|
205
207
|
}
|
206
|
-
exports.findTypeLookupAssembly = findTypeLookupAssembly;
|
207
208
|
function loadLookupAssembly(directory) {
|
208
209
|
try {
|
209
210
|
const packageJson = JSON.parse(fs.readFileSync(path.join(directory, 'package.json'), 'utf-8'));
|
@@ -252,7 +253,6 @@ function findContainingSubmodule(assembly, fqn) {
|
|
252
253
|
}
|
253
254
|
return undefined;
|
254
255
|
}
|
255
|
-
exports.findContainingSubmodule = findContainingSubmodule;
|
256
256
|
function withProjectDirectory(dir, snippet) {
|
257
257
|
return (0, snippet_1.updateParameters)(snippet, {
|
258
258
|
[snippet_1.SnippetParameters.$PROJECT_DIRECTORY]: dir,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"assemblies.js","sourceRoot":"","sources":["../../src/jsii/assemblies.ts"],"names":[],"mappings":";;;AAAA,qCAAiD;AACjD,8BAA8B;AAC9B,kCAAkC;AAClC,qCAA0F;AAC1F,mCAAmC;AACnC,0CAAwC;AACxC,mEAAqF;AACrF,wCASoB;AACpB,kEAA6E;AAC7E,sCAA+C;AAC/C,gDAAyG;AACzG,kCAA2D;AAE3D;;;;;;;;;;;;;GAaG;AACU,QAAA,yBAAyB,GAAG,iBAAiB,CAAC;AAe3D;;GAEG;AACH,SAAg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CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,CAAU,CAC9E,CACF,CACF,CAAC;IAEF,OAAO;QACL,GAAG,OAAO;QACV,uBAAuB;KACxB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,MAAsB;IACtC,OAAO,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,IAAI,IAAA,2BAAkB,EAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACxF,CAAC","sourcesContent":["import { promises as fsPromises } from 'node:fs';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { loadAssemblyFromFile, loadAssemblyFromPath, findAssemblyFile } from '@jsii/spec';\nimport * as spec from '@jsii/spec';\nimport { fixturize } from '../fixtures';\nimport { extractTypescriptSnippetsFromMarkdown } from '../markdown/extract-snippets';\nimport {\n TypeScriptSnippet,\n typeScriptSnippetFromSource,\n updateParameters,\n SnippetParameters,\n ApiLocation,\n parseMetadataLine,\n CompilationDependency,\n INITIALIZER_METHOD_NAME,\n} from '../snippet';\nimport { resolveDependenciesFromPackageJson } from '../snippet-dependencies';\nimport { enforcesStrictMode } from '../strict';\nimport { LanguageTablet, DEFAULT_TABLET_NAME, DEFAULT_TABLET_NAME_COMPRESSED } from '../tablets/tablets';\nimport { fmap, mkDict, pathExists, sortBy } from '../util';\n\n/**\n * The JSDoc tag users can use to associate non-visible metadata with an example\n *\n * In a Markdown section, metadata goes after the code block fence, where it will\n * be attached to the example but invisible.\n *\n * ```ts metadata=goes here\n *\n * But in doc comments, '@example' already delineates the example, and any metadata\n * in there added by the '///' tags becomes part of the visible code (there is no\n * place to put hidden information).\n *\n * We introduce the '@exampleMetadata' tag to put that additional information.\n */\nexport const EXAMPLE_METADATA_JSDOCTAG = 'exampleMetadata';\n\ninterface RosettaPackageJson extends spec.PackageJson {\n readonly jsiiRosetta?: {\n readonly strict?: boolean;\n readonly exampleDependencies?: Record<string, string>;\n };\n}\n\nexport interface LoadedAssembly {\n readonly assembly: spec.Assembly;\n readonly directory: string;\n readonly packageJson?: RosettaPackageJson;\n}\n\n/**\n * Load assemblies by filename or directory\n */\nexport function loadAssemblies(\n assemblyLocations: readonly string[],\n validateAssemblies: boolean,\n): readonly LoadedAssembly[] {\n return assemblyLocations.map(loadAssembly);\n\n function loadAssembly(location: string): LoadedAssembly {\n const stat = fs.statSync(location);\n if (stat.isDirectory()) {\n return loadAssembly(findAssemblyFile(location));\n }\n\n const directory = path.dirname(location);\n const pjLocation = path.join(directory, 'package.json');\n\n const assembly = loadAssemblyFromFile(location, validateAssemblies);\n const packageJson = fs.existsSync(pjLocation) ? JSON.parse(fs.readFileSync(pjLocation, 'utf-8')) : undefined;\n\n return { assembly, directory, packageJson };\n }\n}\n\n/**\n * Load the default tablets for every assembly, if available\n *\n * Returns a map of { directory -> tablet }.\n */\nexport async function loadAllDefaultTablets(asms: readonly LoadedAssembly[]): Promise<Record<string, LanguageTablet>> {\n return mkDict(\n await Promise.all(\n asms.map(\n async (a) => [a.directory, await LanguageTablet.fromOptionalFile(guessTabletLocation(a.directory))] as const,\n ),\n ),\n );\n}\n\n/**\n * Returns the location of the tablet file, either .jsii.tabl.json or .jsii.tabl.json.gz.\n * Assumes that a tablet exists in the directory and if not, the ensuing behavior is\n * handled by the caller of this function.\n */\nexport function guessTabletLocation(directory: string) {\n return compressedTabletExists(directory)\n ? path.join(directory, DEFAULT_TABLET_NAME_COMPRESSED)\n : path.join(directory, DEFAULT_TABLET_NAME);\n}\n\nexport function compressedTabletExists(directory: string) {\n return fs.existsSync(path.join(directory, DEFAULT_TABLET_NAME_COMPRESSED));\n}\n\nexport type AssemblySnippetSource =\n | { type: 'markdown'; markdown: string; location: ApiLocation }\n | { type: 'example'; source: string; metadata?: { [key: string]: string }; location: ApiLocation };\n\n/**\n * Return all markdown and example snippets from the given assembly\n */\nexport function allSnippetSources(assembly: spec.Assembly): AssemblySnippetSource[] {\n const ret: AssemblySnippetSource[] = [];\n\n if (assembly.readme) {\n ret.push({\n type: 'markdown',\n markdown: assembly.readme.markdown,\n location: { api: 'moduleReadme', moduleFqn: assembly.name },\n });\n }\n\n for (const [submoduleFqn, submodule] of Object.entries(assembly.submodules ?? {})) {\n if (submodule.readme) {\n ret.push({\n type: 'markdown',\n markdown: submodule.readme.markdown,\n location: { api: 'moduleReadme', moduleFqn: submoduleFqn },\n });\n }\n }\n\n if (assembly.types) {\n for (const type of Object.values(assembly.types)) {\n emitDocs(type.docs, { api: 'type', fqn: type.fqn });\n\n if (spec.isEnumType(type)) {\n for (const m of type.members) emitDocs(m.docs, { api: 'member', fqn: type.fqn, memberName: m.name });\n }\n if (spec.isClassType(type)) {\n emitDocsForCallable(type.initializer, type.fqn);\n }\n if (spec.isClassOrInterfaceType(type)) {\n for (const m of type.methods ?? []) emitDocsForCallable(m, type.fqn, m.name);\n for (const m of type.properties ?? []) emitDocs(m.docs, { api: 'member', fqn: type.fqn, memberName: m.name });\n }\n }\n }\n\n return ret;\n\n function emitDocsForCallable(callable: spec.Callable | undefined, fqn: string, memberName?: string) {\n if (!callable) {\n return;\n }\n emitDocs(callable.docs, memberName ? { api: 'member', fqn, memberName } : { api: 'initializer', fqn });\n\n for (const parameter of callable.parameters ?? []) {\n emitDocs(parameter.docs, {\n api: 'parameter',\n fqn: fqn,\n methodName: memberName ?? INITIALIZER_METHOD_NAME,\n parameterName: parameter.name,\n });\n }\n }\n\n function emitDocs(docs: spec.Docs | undefined, location: ApiLocation) {\n if (!docs) {\n return;\n }\n\n if (docs.remarks) {\n ret.push({\n type: 'markdown',\n markdown: docs.remarks,\n location,\n });\n }\n if (docs.example) {\n ret.push({\n type: 'example',\n source: docs.example,\n metadata: fmap(docs.custom?.[EXAMPLE_METADATA_JSDOCTAG], parseMetadataLine),\n location,\n });\n }\n }\n}\n\nexport async function allTypeScriptSnippets(\n assemblies: readonly LoadedAssembly[],\n loose = false,\n): Promise<TypeScriptSnippet[]> {\n return Promise.all(\n assemblies\n .flatMap((loaded) => allSnippetSources(loaded.assembly).map((source) => ({ source, loaded })))\n .flatMap(({ source, loaded }) => {\n switch (source.type) {\n case 'example':\n return [\n {\n snippet: updateParameters(\n typeScriptSnippetFromSource(\n source.source,\n { api: source.location, field: { field: 'example' } },\n isStrict(loaded),\n ),\n source.metadata ?? {},\n ),\n loaded,\n },\n ];\n case 'markdown':\n return extractTypescriptSnippetsFromMarkdown(source.markdown, source.location, isStrict(loaded)).map(\n (snippet) => ({ snippet, loaded }),\n );\n }\n })\n .map(async ({ snippet, loaded }) => {\n const isInfused = snippet.parameters?.infused != null;\n\n // Ignore fixturization errors if requested on this command, or if the snippet was infused\n const ignoreFixtureErrors = loose || isInfused;\n\n // Also if the snippet was infused: switch off 'strict' mode if it was set\n if (isInfused) {\n snippet = { ...snippet, strict: false };\n }\n\n snippet = await withDependencies(loaded, withProjectDirectory(loaded.directory, snippet));\n return fixturize(snippet, ignoreFixtureErrors);\n }),\n );\n}\n\nexport interface TypeLookupAssembly {\n readonly packageJson: any;\n readonly assembly: spec.Assembly;\n readonly directory: string;\n readonly symbolIdMap: Record<string, string>;\n}\n\nconst MAX_ASM_CACHE = 3;\nconst ASM_CACHE: TypeLookupAssembly[] = [];\n\n/**\n * Recursively searches for a .jsii file in the directory.\n * When file is found, checks cache to see if we already\n * stored the assembly in memory. If not, we synchronously\n * load the assembly into memory.\n */\nexport function findTypeLookupAssembly(startingDirectory: string): TypeLookupAssembly | undefined {\n const pjLocation = findPackageJsonLocation(path.resolve(startingDirectory));\n if (!pjLocation) {\n return undefined;\n }\n const directory = path.dirname(pjLocation);\n\n const fromCache = ASM_CACHE.find((c) => c.directory === directory);\n if (fromCache) {\n return fromCache;\n }\n\n const loaded = loadLookupAssembly(directory);\n if (!loaded) {\n return undefined;\n }\n\n while (ASM_CACHE.length >= MAX_ASM_CACHE) {\n ASM_CACHE.pop();\n }\n ASM_CACHE.unshift(loaded);\n return loaded;\n}\n\nfunction loadLookupAssembly(directory: string): TypeLookupAssembly | undefined {\n try {\n const packageJson = JSON.parse(fs.readFileSync(path.join(directory, 'package.json'), 'utf-8'));\n const assembly: spec.Assembly = loadAssemblyFromPath(directory);\n const symbolIdMap = mkDict([\n ...Object.values(assembly.types ?? {}).map((type) => [type.symbolId ?? '', type.fqn] as const),\n ...Object.entries(assembly.submodules ?? {}).map(([fqn, mod]) => [mod.symbolId ?? '', fqn] as const),\n ]);\n\n return {\n packageJson,\n assembly,\n directory,\n symbolIdMap,\n };\n } catch {\n return undefined;\n }\n}\n\nfunction findPackageJsonLocation(currentPath: string): string | undefined {\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const candidate = path.join(currentPath, 'package.json');\n if (fs.existsSync(candidate)) {\n return candidate;\n }\n\n const parentPath = path.resolve(currentPath, '..');\n if (parentPath === currentPath) {\n return undefined;\n }\n currentPath = parentPath;\n }\n}\n\n/**\n * Find the jsii [sub]module that contains the given FQN\n *\n * @returns `undefined` if the type is a member of the assembly root.\n */\nexport function findContainingSubmodule(assembly: spec.Assembly, fqn: string): string | undefined {\n const submoduleNames = Object.keys(assembly.submodules ?? {});\n sortBy(submoduleNames, (s) => [-s.length]); // Longest first\n for (const s of submoduleNames) {\n if (fqn.startsWith(`${s}.`)) {\n return s;\n }\n }\n return undefined;\n}\n\nfunction withProjectDirectory(dir: string, snippet: TypeScriptSnippet) {\n return updateParameters(snippet, {\n [SnippetParameters.$PROJECT_DIRECTORY]: dir,\n });\n}\n\n/**\n * Return a TypeScript snippet with dependencies added\n *\n * The dependencies will be taken from the package.json, and will consist of:\n *\n * - The package itself\n * - The package's dependencies and peerDependencies (but NOT devDependencies). Will\n * symlink to the files on disk.\n * - Any additional dependencies declared in `jsiiRosetta.exampleDependencies`.\n */\nasync function withDependencies(asm: LoadedAssembly, snippet: TypeScriptSnippet): Promise<TypeScriptSnippet> {\n const compilationDependencies: Record<string, CompilationDependency> = {};\n\n if (await pathExists(path.join(asm.directory, 'package.json'))) {\n compilationDependencies[asm.assembly.name] = {\n type: 'concrete',\n resolvedDirectory: await fsPromises.realpath(asm.directory),\n };\n }\n\n Object.assign(compilationDependencies, await resolveDependenciesFromPackageJson(asm.packageJson, asm.directory));\n\n Object.assign(\n compilationDependencies,\n mkDict(\n Object.entries(asm.packageJson?.jsiiRosetta?.exampleDependencies ?? {}).map(\n ([name, versionRange]) => [name, { type: 'symbolic', versionRange }] as const,\n ),\n ),\n );\n\n return {\n ...snippet,\n compilationDependencies,\n };\n}\n\n/**\n * Whether samples in the assembly should be treated as strict\n *\n * True if the strict flag is found in the package.json (modern) or the assembly itself (legacy).\n */\nfunction isStrict(loaded: LoadedAssembly) {\n return loaded.packageJson?.jsiiRosetta?.strict ?? enforcesStrictMode(loaded.assembly);\n}\n"]}
|
1
|
+
{"version":3,"file":"assemblies.js","sourceRoot":"","sources":["../../src/jsii/assemblies.ts"],"names":[],"mappings":";;;AAsDA,wCAoBC;AAOD,sDAQC;AAOD,kDAIC;AAED,wDAEC;AASD,8CA6EC;AAED,sDA4CC;AAkBD,wDAsBC;AA2CD,0DASC;AAxUD,qCAAiD;AACjD,8BAA8B;AAC9B,kCAAkC;AAClC,qCAA0F;AAC1F,mCAAmC;AACnC,0CAAwC;AACxC,mEAAqF;AACrF,wCASoB;AACpB,kEAA6E;AAC7E,sCAA+C;AAC/C,gDAAyG;AACzG,kCAA2D;AAE3D;;;;;;;;;;;;;GAaG;AACU,QAAA,yBAAyB,GAAG,iBAAiB,CAAC;AAe3D;;GAEG;AACH,SAAgB,cAAc,CAC5B,iBAAoC,EACpC,kBAA2B;IAE3B,OAAO,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAE3C,SAAS,YAAY,CAAC,QAAgB;QACpC,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YACvB,OAAO,YAAY,CAAC,IAAA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promises as fsPromises } from 'node:fs';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { loadAssemblyFromFile, loadAssemblyFromPath, findAssemblyFile } from '@jsii/spec';\nimport * as spec from '@jsii/spec';\nimport { fixturize } from '../fixtures';\nimport { extractTypescriptSnippetsFromMarkdown } from '../markdown/extract-snippets';\nimport {\n TypeScriptSnippet,\n typeScriptSnippetFromSource,\n updateParameters,\n SnippetParameters,\n ApiLocation,\n parseMetadataLine,\n CompilationDependency,\n INITIALIZER_METHOD_NAME,\n} from '../snippet';\nimport { resolveDependenciesFromPackageJson } from '../snippet-dependencies';\nimport { enforcesStrictMode } from '../strict';\nimport { LanguageTablet, DEFAULT_TABLET_NAME, DEFAULT_TABLET_NAME_COMPRESSED } from '../tablets/tablets';\nimport { fmap, mkDict, pathExists, sortBy } from '../util';\n\n/**\n * The JSDoc tag users can use to associate non-visible metadata with an example\n *\n * In a Markdown section, metadata goes after the code block fence, where it will\n * be attached to the example but invisible.\n *\n * ```ts metadata=goes here\n *\n * But in doc comments, '@example' already delineates the example, and any metadata\n * in there added by the '///' tags becomes part of the visible code (there is no\n * place to put hidden information).\n *\n * We introduce the '@exampleMetadata' tag to put that additional information.\n */\nexport const EXAMPLE_METADATA_JSDOCTAG = 'exampleMetadata';\n\ninterface RosettaPackageJson extends spec.PackageJson {\n readonly jsiiRosetta?: {\n readonly strict?: boolean;\n readonly exampleDependencies?: Record<string, string>;\n };\n}\n\nexport interface LoadedAssembly {\n readonly assembly: spec.Assembly;\n readonly directory: string;\n readonly packageJson?: RosettaPackageJson;\n}\n\n/**\n * Load assemblies by filename or directory\n */\nexport function loadAssemblies(\n assemblyLocations: readonly string[],\n validateAssemblies: boolean,\n): readonly LoadedAssembly[] {\n return assemblyLocations.map(loadAssembly);\n\n function loadAssembly(location: string): LoadedAssembly {\n const stat = fs.statSync(location);\n if (stat.isDirectory()) {\n return loadAssembly(findAssemblyFile(location));\n }\n\n const directory = path.dirname(location);\n const pjLocation = path.join(directory, 'package.json');\n\n const assembly = loadAssemblyFromFile(location, validateAssemblies);\n const packageJson = fs.existsSync(pjLocation) ? JSON.parse(fs.readFileSync(pjLocation, 'utf-8')) : undefined;\n\n return { assembly, directory, packageJson };\n }\n}\n\n/**\n * Load the default tablets for every assembly, if available\n *\n * Returns a map of { directory -> tablet }.\n */\nexport async function loadAllDefaultTablets(asms: readonly LoadedAssembly[]): Promise<Record<string, LanguageTablet>> {\n return mkDict(\n await Promise.all(\n asms.map(\n async (a) => [a.directory, await LanguageTablet.fromOptionalFile(guessTabletLocation(a.directory))] as const,\n ),\n ),\n );\n}\n\n/**\n * Returns the location of the tablet file, either .jsii.tabl.json or .jsii.tabl.json.gz.\n * Assumes that a tablet exists in the directory and if not, the ensuing behavior is\n * handled by the caller of this function.\n */\nexport function guessTabletLocation(directory: string) {\n return compressedTabletExists(directory)\n ? path.join(directory, DEFAULT_TABLET_NAME_COMPRESSED)\n : path.join(directory, DEFAULT_TABLET_NAME);\n}\n\nexport function compressedTabletExists(directory: string) {\n return fs.existsSync(path.join(directory, DEFAULT_TABLET_NAME_COMPRESSED));\n}\n\nexport type AssemblySnippetSource =\n | { type: 'markdown'; markdown: string; location: ApiLocation }\n | { type: 'example'; source: string; metadata?: { [key: string]: string }; location: ApiLocation };\n\n/**\n * Return all markdown and example snippets from the given assembly\n */\nexport function allSnippetSources(assembly: spec.Assembly): AssemblySnippetSource[] {\n const ret: AssemblySnippetSource[] = [];\n\n if (assembly.readme) {\n ret.push({\n type: 'markdown',\n markdown: assembly.readme.markdown,\n location: { api: 'moduleReadme', moduleFqn: assembly.name },\n });\n }\n\n for (const [submoduleFqn, submodule] of Object.entries(assembly.submodules ?? {})) {\n if (submodule.readme) {\n ret.push({\n type: 'markdown',\n markdown: submodule.readme.markdown,\n location: { api: 'moduleReadme', moduleFqn: submoduleFqn },\n });\n }\n }\n\n if (assembly.types) {\n for (const type of Object.values(assembly.types)) {\n emitDocs(type.docs, { api: 'type', fqn: type.fqn });\n\n if (spec.isEnumType(type)) {\n for (const m of type.members) emitDocs(m.docs, { api: 'member', fqn: type.fqn, memberName: m.name });\n }\n if (spec.isClassType(type)) {\n emitDocsForCallable(type.initializer, type.fqn);\n }\n if (spec.isClassOrInterfaceType(type)) {\n for (const m of type.methods ?? []) emitDocsForCallable(m, type.fqn, m.name);\n for (const m of type.properties ?? []) emitDocs(m.docs, { api: 'member', fqn: type.fqn, memberName: m.name });\n }\n }\n }\n\n return ret;\n\n function emitDocsForCallable(callable: spec.Callable | undefined, fqn: string, memberName?: string) {\n if (!callable) {\n return;\n }\n emitDocs(callable.docs, memberName ? { api: 'member', fqn, memberName } : { api: 'initializer', fqn });\n\n for (const parameter of callable.parameters ?? []) {\n emitDocs(parameter.docs, {\n api: 'parameter',\n fqn: fqn,\n methodName: memberName ?? INITIALIZER_METHOD_NAME,\n parameterName: parameter.name,\n });\n }\n }\n\n function emitDocs(docs: spec.Docs | undefined, location: ApiLocation) {\n if (!docs) {\n return;\n }\n\n if (docs.remarks) {\n ret.push({\n type: 'markdown',\n markdown: docs.remarks,\n location,\n });\n }\n if (docs.example) {\n ret.push({\n type: 'example',\n source: docs.example,\n metadata: fmap(docs.custom?.[EXAMPLE_METADATA_JSDOCTAG], parseMetadataLine),\n location,\n });\n }\n }\n}\n\nexport async function allTypeScriptSnippets(\n assemblies: readonly LoadedAssembly[],\n loose = false,\n): Promise<TypeScriptSnippet[]> {\n return Promise.all(\n assemblies\n .flatMap((loaded) => allSnippetSources(loaded.assembly).map((source) => ({ source, loaded })))\n .flatMap(({ source, loaded }) => {\n switch (source.type) {\n case 'example':\n return [\n {\n snippet: updateParameters(\n typeScriptSnippetFromSource(\n source.source,\n { api: source.location, field: { field: 'example' } },\n isStrict(loaded),\n ),\n source.metadata ?? {},\n ),\n loaded,\n },\n ];\n case 'markdown':\n return extractTypescriptSnippetsFromMarkdown(source.markdown, source.location, isStrict(loaded)).map(\n (snippet) => ({ snippet, loaded }),\n );\n }\n })\n .map(async ({ snippet, loaded }) => {\n const isInfused = snippet.parameters?.infused != null;\n\n // Ignore fixturization errors if requested on this command, or if the snippet was infused\n const ignoreFixtureErrors = loose || isInfused;\n\n // Also if the snippet was infused: switch off 'strict' mode if it was set\n if (isInfused) {\n snippet = { ...snippet, strict: false };\n }\n\n snippet = await withDependencies(loaded, withProjectDirectory(loaded.directory, snippet));\n return fixturize(snippet, ignoreFixtureErrors);\n }),\n );\n}\n\nexport interface TypeLookupAssembly {\n readonly packageJson: any;\n readonly assembly: spec.Assembly;\n readonly directory: string;\n readonly symbolIdMap: Record<string, string>;\n}\n\nconst MAX_ASM_CACHE = 3;\nconst ASM_CACHE: TypeLookupAssembly[] = [];\n\n/**\n * Recursively searches for a .jsii file in the directory.\n * When file is found, checks cache to see if we already\n * stored the assembly in memory. If not, we synchronously\n * load the assembly into memory.\n */\nexport function findTypeLookupAssembly(startingDirectory: string): TypeLookupAssembly | undefined {\n const pjLocation = findPackageJsonLocation(path.resolve(startingDirectory));\n if (!pjLocation) {\n return undefined;\n }\n const directory = path.dirname(pjLocation);\n\n const fromCache = ASM_CACHE.find((c) => c.directory === directory);\n if (fromCache) {\n return fromCache;\n }\n\n const loaded = loadLookupAssembly(directory);\n if (!loaded) {\n return undefined;\n }\n\n while (ASM_CACHE.length >= MAX_ASM_CACHE) {\n ASM_CACHE.pop();\n }\n ASM_CACHE.unshift(loaded);\n return loaded;\n}\n\nfunction loadLookupAssembly(directory: string): TypeLookupAssembly | undefined {\n try {\n const packageJson = JSON.parse(fs.readFileSync(path.join(directory, 'package.json'), 'utf-8'));\n const assembly: spec.Assembly = loadAssemblyFromPath(directory);\n const symbolIdMap = mkDict([\n ...Object.values(assembly.types ?? {}).map((type) => [type.symbolId ?? '', type.fqn] as const),\n ...Object.entries(assembly.submodules ?? {}).map(([fqn, mod]) => [mod.symbolId ?? '', fqn] as const),\n ]);\n\n return {\n packageJson,\n assembly,\n directory,\n symbolIdMap,\n };\n } catch {\n return undefined;\n }\n}\n\nfunction findPackageJsonLocation(currentPath: string): string | undefined {\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const candidate = path.join(currentPath, 'package.json');\n if (fs.existsSync(candidate)) {\n return candidate;\n }\n\n const parentPath = path.resolve(currentPath, '..');\n if (parentPath === currentPath) {\n return undefined;\n }\n currentPath = parentPath;\n }\n}\n\n/**\n * Find the jsii [sub]module that contains the given FQN\n *\n * @returns `undefined` if the type is a member of the assembly root.\n */\nexport function findContainingSubmodule(assembly: spec.Assembly, fqn: string): string | undefined {\n const submoduleNames = Object.keys(assembly.submodules ?? {});\n sortBy(submoduleNames, (s) => [-s.length]); // Longest first\n for (const s of submoduleNames) {\n if (fqn.startsWith(`${s}.`)) {\n return s;\n }\n }\n return undefined;\n}\n\nfunction withProjectDirectory(dir: string, snippet: TypeScriptSnippet) {\n return updateParameters(snippet, {\n [SnippetParameters.$PROJECT_DIRECTORY]: dir,\n });\n}\n\n/**\n * Return a TypeScript snippet with dependencies added\n *\n * The dependencies will be taken from the package.json, and will consist of:\n *\n * - The package itself\n * - The package's dependencies and peerDependencies (but NOT devDependencies). Will\n * symlink to the files on disk.\n * - Any additional dependencies declared in `jsiiRosetta.exampleDependencies`.\n */\nasync function withDependencies(asm: LoadedAssembly, snippet: TypeScriptSnippet): Promise<TypeScriptSnippet> {\n const compilationDependencies: Record<string, CompilationDependency> = {};\n\n if (await pathExists(path.join(asm.directory, 'package.json'))) {\n compilationDependencies[asm.assembly.name] = {\n type: 'concrete',\n resolvedDirectory: await fsPromises.realpath(asm.directory),\n };\n }\n\n Object.assign(compilationDependencies, await resolveDependenciesFromPackageJson(asm.packageJson, asm.directory));\n\n Object.assign(\n compilationDependencies,\n mkDict(\n Object.entries(asm.packageJson?.jsiiRosetta?.exampleDependencies ?? {}).map(\n ([name, versionRange]) => [name, { type: 'symbolic', versionRange }] as const,\n ),\n ),\n );\n\n return {\n ...snippet,\n compilationDependencies,\n };\n}\n\n/**\n * Whether samples in the assembly should be treated as strict\n *\n * True if the strict flag is found in the package.json (modern) or the assembly itself (legacy).\n */\nfunction isStrict(loaded: LoadedAssembly) {\n return loaded.packageJson?.jsiiRosetta?.strict ?? enforcesStrictMode(loaded.assembly);\n}\n"]}
|
package/lib/jsii/jsii-types.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.determineJsiiType = determineJsiiType;
|
4
|
+
exports.analyzeObjectLiteral = analyzeObjectLiteral;
|
4
5
|
const ts = require("typescript");
|
5
6
|
const jsii_utils_1 = require("./jsii-utils");
|
6
7
|
const types_1 = require("../typescript/types");
|
@@ -63,7 +64,6 @@ function determineJsiiType(typeChecker, type) {
|
|
63
64
|
}
|
64
65
|
return { kind: 'unknown' };
|
65
66
|
}
|
66
|
-
exports.determineJsiiType = determineJsiiType;
|
67
67
|
function analyzeObjectLiteral(typeChecker, node) {
|
68
68
|
const type = (0, types_1.inferredTypeOfExpression)(typeChecker, node);
|
69
69
|
if (!type) {
|
@@ -90,7 +90,6 @@ function analyzeObjectLiteral(typeChecker, node) {
|
|
90
90
|
}
|
91
91
|
return { kind: 'map' };
|
92
92
|
}
|
93
|
-
exports.analyzeObjectLiteral = analyzeObjectLiteral;
|
94
93
|
function findEnclosingCallExpression(node) {
|
95
94
|
while (node) {
|
96
95
|
if (ts.isCallLikeExpression(node)) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jsii-types.js","sourceRoot":"","sources":["../../src/jsii/jsii-types.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"jsii-types.js","sourceRoot":"","sources":["../../src/jsii/jsii-types.ts"],"names":[],"mappings":";;AAaA,8CAoEC;AAQD,oDAgCC;AAzHD,iCAAiC;AAEjC,6CAAyE;AACzE,+CAA6G;AAU7G,SAAgB,iBAAiB,CAAC,WAA2B,EAAE,IAAa;IAC1E,sGAAsG;IACtG,+BAA+B;IAC/B,IAAK,IAAY,CAAC,aAAa,KAAK,OA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AAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import * as ts from 'typescript';\n\nimport { hasAnyFlag, analyzeStructType, JsiiSymbol } from './jsii-utils';\nimport { inferredTypeOfExpression, BuiltInType, builtInTypeName, mapElementType } from '../typescript/types';\n\n// eslint-disable-next-line prettier/prettier\nexport type JsiiType =\n | { kind: 'unknown' }\n | { kind: 'error'; message: string }\n | { kind: 'map' | 'list'; elementType: JsiiType; elementTypeSymbol: ts.Symbol | undefined }\n | { kind: 'namedType'; name: string }\n | { kind: 'builtIn'; builtIn: BuiltInType };\n\nexport function determineJsiiType(typeChecker: ts.TypeChecker, type: ts.Type): JsiiType {\n // this means the snippet didn't have enough info for the TypeScript compiler to figure out the type -\n // so, just render the fallback\n if ((type as any).intrinsicName === 'error') {\n return { kind: 'unknown' };\n }\n\n // The non-nullable version of `void` is `never`, so check first...\n if ((type.flags & (ts.TypeFlags.Void | ts.TypeFlags.VoidLike)) !== 0) {\n return { kind: 'builtIn', builtIn: 'void' };\n }\n // The non-nullable version of `unknown` is some ObjectType, so check first...\n if ((type.flags & (ts.TypeFlags.Unknown | ts.TypeFlags.Any)) !== 0) {\n return { kind: 'builtIn', builtIn: 'any' };\n }\n\n type = type.getNonNullableType();\n\n const mapValuesType = mapElementType(type, typeChecker);\n if (mapValuesType.result === 'map') {\n return {\n kind: 'map',\n elementType: mapValuesType.elementType\n ? determineJsiiType(typeChecker, mapValuesType.elementType)\n : { kind: 'builtIn', builtIn: 'any' },\n elementTypeSymbol: mapValuesType.elementType?.symbol,\n };\n }\n\n if (type.symbol?.name === 'Array') {\n const typeRef = type as ts.TypeReference;\n\n if (typeRef.typeArguments?.length === 1) {\n return {\n kind: 'list',\n elementType: determineJsiiType(typeChecker, typeRef.typeArguments[0]),\n elementTypeSymbol: typeRef.typeArguments[0].symbol,\n };\n }\n\n return {\n kind: 'list',\n elementType: { kind: 'builtIn', builtIn: 'any' },\n elementTypeSymbol: undefined,\n };\n }\n\n // User-defined or aliased type\n if (type.aliasSymbol) {\n return { kind: 'namedType', name: type.aliasSymbol.name };\n }\n if (type.symbol) {\n return { kind: 'namedType', name: type.symbol.name };\n }\n\n const typeScriptBuiltInType = builtInTypeName(type);\n if (typeScriptBuiltInType) {\n return { kind: 'builtIn', builtIn: typeScriptBuiltInType };\n }\n\n if (type.isUnion() || type.isIntersection()) {\n return {\n kind: 'error',\n message: `Type unions or intersections are not supported in examples, got: ${typeChecker.typeToString(type)}`,\n };\n }\n\n return { kind: 'unknown' };\n}\n\nexport type ObjectLiteralAnalysis = ObjectLiteralStruct | { readonly kind: 'map' } | { readonly kind: 'unknown' };\n\nexport type ObjectLiteralStruct =\n | { readonly kind: 'struct'; readonly type: ts.Type; readonly jsiiSym: JsiiSymbol }\n | { readonly kind: 'local-struct'; readonly type: ts.Type };\n\nexport function analyzeObjectLiteral(\n typeChecker: ts.TypeChecker,\n node: ts.ObjectLiteralExpression,\n): ObjectLiteralAnalysis {\n const type = inferredTypeOfExpression(typeChecker, node);\n if (!type) {\n return { kind: 'unknown' };\n }\n\n const call = findEnclosingCallExpression(node);\n const isDeclaredCall = !!(call && typeChecker.getResolvedSignature(call)?.declaration);\n\n if (hasAnyFlag(type.flags, ts.TypeFlags.Any)) {\n // The type checker by itself won't tell us the difference between an `any` that\n // was literally declared as a type in the code, vs an `any` it assumes because it\n // can't find a function's type declaration.\n //\n // Search for the function's declaration and only if we can't find it,\n // the type is actually unknown (otherwise it's a literal 'any').\n return isDeclaredCall ? { kind: 'map' } : { kind: 'unknown' };\n }\n\n // If the type is a union between a struct and something else, return the first possible struct\n const structCandidates = type.isUnion() ? type.types : [type];\n for (const candidate of structCandidates) {\n const structType = analyzeStructType(typeChecker, candidate);\n if (structType) {\n return structType;\n }\n }\n\n return { kind: 'map' };\n}\n\nfunction findEnclosingCallExpression(node?: ts.Node): ts.CallLikeExpression | undefined {\n while (node) {\n if (ts.isCallLikeExpression(node)) {\n return node;\n }\n node = node.parent;\n }\n\n return undefined;\n}\n"]}
|
package/lib/jsii/jsii-utils.js
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.isNamedLikeStruct = isNamedLikeStruct;
|
4
|
+
exports.analyzeStructType = analyzeStructType;
|
5
|
+
exports.isJsiiProtocolType = isJsiiProtocolType;
|
6
|
+
exports.hasAllFlags = hasAllFlags;
|
7
|
+
exports.hasAnyFlag = hasAnyFlag;
|
8
|
+
exports.propertiesOfStruct = propertiesOfStruct;
|
9
|
+
exports.structPropertyAcceptsUndefined = structPropertyAcceptsUndefined;
|
10
|
+
exports.lookupJsiiSymbolFromNode = lookupJsiiSymbolFromNode;
|
11
|
+
exports.resolveJsiiSymbolType = resolveJsiiSymbolType;
|
12
|
+
exports.lookupJsiiSymbol = lookupJsiiSymbol;
|
13
|
+
exports.resolveEnumLiteral = resolveEnumLiteral;
|
14
|
+
exports.resolvedSymbolAtLocation = resolvedSymbolAtLocation;
|
15
|
+
exports.parentSymbol = parentSymbol;
|
16
|
+
exports.simpleName = simpleName;
|
17
|
+
exports.namespaceName = namespaceName;
|
4
18
|
const spec = require("@jsii/spec");
|
5
19
|
const common_1 = require("jsii/common");
|
6
20
|
const ts = require("typescript");
|
@@ -11,7 +25,6 @@ function isNamedLikeStruct(name) {
|
|
11
25
|
// Start with an I and another uppercase character
|
12
26
|
return !/^I[A-Z]/.test(name);
|
13
27
|
}
|
14
|
-
exports.isNamedLikeStruct = isNamedLikeStruct;
|
15
28
|
function analyzeStructType(typeChecker, type) {
|
16
29
|
if (!type.isClassOrInterface() ||
|
17
30
|
!hasAllFlags(type.objectFlags, ts.ObjectFlags.Interface) ||
|
@@ -24,7 +37,6 @@ function analyzeStructType(typeChecker, type) {
|
|
24
37
|
}
|
25
38
|
return { kind: 'local-struct', type };
|
26
39
|
}
|
27
|
-
exports.analyzeStructType = analyzeStructType;
|
28
40
|
/**
|
29
41
|
* Whether the given type is a protocol AND comes from jsii
|
30
42
|
*
|
@@ -75,17 +87,14 @@ function isJsiiProtocolType(typeChecker, type) {
|
|
75
87
|
const jsiiType = resolveJsiiSymbolType(sym);
|
76
88
|
return spec.isInterfaceType(jsiiType) && !jsiiType.datatype;
|
77
89
|
}
|
78
|
-
exports.isJsiiProtocolType = isJsiiProtocolType;
|
79
90
|
function hasAllFlags(flags, test) {
|
80
91
|
// tslint:disable-next-line:no-bitwise
|
81
92
|
return test !== 0 && (flags & test) === test;
|
82
93
|
}
|
83
|
-
exports.hasAllFlags = hasAllFlags;
|
84
94
|
function hasAnyFlag(flags, test) {
|
85
95
|
// tslint:disable-next-line:no-bitwise
|
86
96
|
return test !== 0 && (flags & test) !== 0;
|
87
97
|
}
|
88
|
-
exports.hasAnyFlag = hasAnyFlag;
|
89
98
|
function propertiesOfStruct(type, context) {
|
90
99
|
return type.isClassOrInterface()
|
91
100
|
? type.getProperties().map((s) => {
|
@@ -105,15 +114,12 @@ function propertiesOfStruct(type, context) {
|
|
105
114
|
})
|
106
115
|
: [];
|
107
116
|
}
|
108
|
-
exports.propertiesOfStruct = propertiesOfStruct;
|
109
117
|
function structPropertyAcceptsUndefined(prop) {
|
110
118
|
return prop.questionMark || (!!prop.type && (0, types_1.typeContainsUndefined)(prop.type));
|
111
119
|
}
|
112
|
-
exports.structPropertyAcceptsUndefined = structPropertyAcceptsUndefined;
|
113
120
|
function lookupJsiiSymbolFromNode(typeChecker, node) {
|
114
121
|
return (0, util_1.fmap)(typeChecker.getSymbolAtLocation(node), (s) => lookupJsiiSymbol(typeChecker, s));
|
115
122
|
}
|
116
|
-
exports.lookupJsiiSymbolFromNode = lookupJsiiSymbolFromNode;
|
117
123
|
function resolveJsiiSymbolType(jsiiSymbol) {
|
118
124
|
if (jsiiSymbol.symbolType !== 'type') {
|
119
125
|
throw new Error(`Expected symbol to refer to a 'type', got '${jsiiSymbol.fqn}' which is a '${jsiiSymbol.symbolType}'`);
|
@@ -127,7 +133,6 @@ function resolveJsiiSymbolType(jsiiSymbol) {
|
|
127
133
|
}
|
128
134
|
return type;
|
129
135
|
}
|
130
|
-
exports.resolveJsiiSymbolType = resolveJsiiSymbolType;
|
131
136
|
/**
|
132
137
|
* Returns the jsii FQN for a TypeScript (class or type) symbol
|
133
138
|
*
|
@@ -188,7 +193,6 @@ function lookupJsiiSymbol(typeChecker, sym) {
|
|
188
193
|
return (0, util_1.fmap)(sourceAssembly?.symbolIdMap[typeSymbolId], (fqn) => ({ fqn, sourceAssembly, symbolType: 'type' }));
|
189
194
|
});
|
190
195
|
}
|
191
|
-
exports.lookupJsiiSymbol = lookupJsiiSymbol;
|
192
196
|
function isDeclaration(x) {
|
193
197
|
return (ts.isClassDeclaration(x) ||
|
194
198
|
ts.isNamespaceExportDeclaration(x) ||
|
@@ -211,7 +215,6 @@ function resolveEnumLiteral(typeChecker, type) {
|
|
211
215
|
}
|
212
216
|
return typeChecker.getBaseTypeOfLiteralType(type);
|
213
217
|
}
|
214
|
-
exports.resolveEnumLiteral = resolveEnumLiteral;
|
215
218
|
function resolvedSymbolAtLocation(typeChecker, node) {
|
216
219
|
let symbol = typeChecker.getSymbolAtLocation(node);
|
217
220
|
while (symbol && hasAnyFlag(symbol.flags, ts.SymbolFlags.Alias)) {
|
@@ -219,7 +222,6 @@ function resolvedSymbolAtLocation(typeChecker, node) {
|
|
219
222
|
}
|
220
223
|
return symbol;
|
221
224
|
}
|
222
|
-
exports.resolvedSymbolAtLocation = resolvedSymbolAtLocation;
|
223
225
|
function getSymbolFromDeclaration(decl, typeChecker) {
|
224
226
|
if (!isDeclaration(decl)) {
|
225
227
|
return undefined;
|
@@ -238,19 +240,16 @@ function parentSymbol(sym) {
|
|
238
240
|
sourceAssembly: sym.sourceAssembly,
|
239
241
|
};
|
240
242
|
}
|
241
|
-
exports.parentSymbol = parentSymbol;
|
242
243
|
/**
|
243
244
|
* Get the last part of a dot-separated string
|
244
245
|
*/
|
245
246
|
function simpleName(x) {
|
246
247
|
return x.split('.').slice(-1)[0];
|
247
248
|
}
|
248
|
-
exports.simpleName = simpleName;
|
249
249
|
/**
|
250
250
|
* Get all parts except the last of a dot-separated string
|
251
251
|
*/
|
252
252
|
function namespaceName(x) {
|
253
253
|
return x.split('.').slice(0, -1).join('.');
|
254
254
|
}
|
255
|
-
exports.namespaceName = namespaceName;
|
256
255
|
//# sourceMappingURL=jsii-utils.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jsii-utils.js","sourceRoot":"","sources":["../../src/jsii/jsii-utils.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,wCAA+C;AAC/C,iCAAiC;AAEjC,6CAA0E;AAG1E,+CAA4D;AAC5D,kCAA+B;AAE/B,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,kDAAkD;IAClD,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAHD,8CAGC;AAED,SAAgB,iBAAiB,CAAC,WAA2B,EAAE,IAAa;IAC1E,IACE,CAAC,IAAI,CAAC,kBAAkB,EAAE;QAC1B,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC;QACxD,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EACpC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,OAAO,GAAG,gBAAgB,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3D,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC3C,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC;AACxC,CAAC;AAfD,8CAeC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,kBAAkB,CAAC,WAA2B,EAAE,IAAa;IAC3E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AAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAFD,gCAEC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,CAAS;IACrC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC;AAFD,sCAEC","sourcesContent":["import * as spec from '@jsii/spec';\nimport { symbolIdentifier } from 'jsii/common';\nimport * as ts from 'typescript';\n\nimport { findTypeLookupAssembly, TypeLookupAssembly } from './assemblies';\nimport { ObjectLiteralStruct } from './jsii-types';\nimport { AstRenderer } from '../renderer';\nimport { typeContainsUndefined } from '../typescript/types';\nimport { fmap } from '../util';\n\nexport function isNamedLikeStruct(name: string) {\n // Start with an I and another uppercase character\n return !/^I[A-Z]/.test(name);\n}\n\nexport function analyzeStructType(typeChecker: ts.TypeChecker, type: ts.Type): ObjectLiteralStruct | false {\n if (\n !type.isClassOrInterface() ||\n !hasAllFlags(type.objectFlags, ts.ObjectFlags.Interface) ||\n !isNamedLikeStruct(type.symbol.name)\n ) {\n return false;\n }\n\n const jsiiSym = lookupJsiiSymbol(typeChecker, type.symbol);\n if (jsiiSym) {\n return { kind: 'struct', type, jsiiSym };\n }\n\n return { kind: 'local-struct', type };\n}\n\n/**\n * Whether the given type is a protocol AND comes from jsii\n *\n * - Protocol: a TypeScript interface that is *not* a \"struct\" type.\n * A.k.a. \"behavioral interface\".\n * - From jsii: whether the interface type is defined in and exported\n * via a jsii assembly. There can be literal interfaces defined\n * in an example, and they will not be mangled in the same way\n * as a jsii interface would be.\n *\n *\n * Examples:\n *\n * ```ts\n * // isJsiiProtocolType() -> false: not a protocol\n * interface Banana {\n * readonly arc: number;\n * }\n *\n * // isJsiiProtocolType() -> might be true: depends on whether it was defined\n * // in a jsii assembly.\n * interface IHello {\n * sayIt(): void;\n * }\n *\n * // isJsiiProtocolType() -> false: declared to not be a protocol, even though\n * // it has the naming scheme of one\n * /**\n * * @struct\n * * /\n * interface IPAddress {\n * readonly octets: number[];\n * }\n * ```\n */\nexport function isJsiiProtocolType(typeChecker: ts.TypeChecker, type: ts.Type): boolean | undefined {\n if (!type.isClassOrInterface() || !hasAllFlags(type.objectFlags, ts.ObjectFlags.Interface)) {\n return false;\n }\n\n const sym = lookupJsiiSymbol(typeChecker, type.symbol);\n if (!sym) {\n return false;\n }\n\n if (!sym.sourceAssembly) {\n // No source assembly, so this is a 'fake-from-jsii' type\n return !isNamedLikeStruct(type.symbol.name);\n }\n\n const jsiiType = resolveJsiiSymbolType(sym);\n return spec.isInterfaceType(jsiiType) && !jsiiType.datatype;\n}\n\nexport function hasAllFlags<A extends number>(flags: A, test: A) {\n // tslint:disable-next-line:no-bitwise\n return test !== 0 && (flags & test) === test;\n}\n\nexport function hasAnyFlag<A extends number>(flags: A, test: A) {\n // tslint:disable-next-line:no-bitwise\n return test !== 0 && (flags & test) !== 0;\n}\n\nexport interface StructProperty {\n name: string;\n type: ts.Type | undefined;\n questionMark: boolean;\n}\n\nexport function propertiesOfStruct(type: ts.Type, context: AstRenderer<any>): StructProperty[] {\n return type.isClassOrInterface()\n ? type.getProperties().map((s) => {\n let propType;\n let questionMark = false;\n\n const propSymbol = type.getProperty(s.name)!;\n const symbolDecl = propSymbol.valueDeclaration ?? propSymbol.declarations![0];\n if (ts.isPropertyDeclaration(symbolDecl) || ts.isPropertySignature(symbolDecl)) {\n questionMark = symbolDecl.questionToken !== undefined;\n propType = symbolDecl.type && context.typeOfType(symbolDecl.type);\n }\n\n return {\n name: s.name,\n type: propType,\n questionMark,\n };\n })\n : [];\n}\n\nexport function structPropertyAcceptsUndefined(prop: StructProperty): boolean {\n return prop.questionMark || (!!prop.type && typeContainsUndefined(prop.type));\n}\n\n/**\n * A TypeScript symbol resolved to its jsii type\n */\nexport interface JsiiSymbol {\n /**\n * FQN of the symbol\n *\n * Is either the FQN of a type (for a type). For a membr, the FQN looks like:\n * 'type.fqn#memberName'.\n */\n readonly fqn: string;\n\n /**\n * What kind of symbol this is\n */\n readonly symbolType: 'module' | 'type' | 'member';\n\n /**\n * Assembly where the type was found\n *\n * Might be undefined if the type was FAKE from jsii (for tests)\n */\n readonly sourceAssembly?: TypeLookupAssembly;\n}\n\nexport function lookupJsiiSymbolFromNode(typeChecker: ts.TypeChecker, node: ts.Node): JsiiSymbol | undefined {\n return fmap(typeChecker.getSymbolAtLocation(node), (s) => lookupJsiiSymbol(typeChecker, s));\n}\n\nexport function resolveJsiiSymbolType(jsiiSymbol: JsiiSymbol): spec.Type {\n if (jsiiSymbol.symbolType !== 'type') {\n throw new Error(\n `Expected symbol to refer to a 'type', got '${jsiiSymbol.fqn}' which is a '${jsiiSymbol.symbolType}'`,\n );\n }\n\n if (!jsiiSymbol.sourceAssembly) {\n throw new Error('`resolveJsiiSymbolType: requires an actual source assembly');\n }\n\n const type = jsiiSymbol.sourceAssembly?.assembly.types?.[jsiiSymbol.fqn];\n if (!type) {\n throw new Error(\n `resolveJsiiSymbolType: ${jsiiSymbol.fqn} not found in assembly ${jsiiSymbol.sourceAssembly.assembly.name}`,\n );\n }\n return type;\n}\n\n/**\n * Returns the jsii FQN for a TypeScript (class or type) symbol\n *\n * TypeScript only knows the symbol NAME plus the FILE the symbol is defined\n * in. We need to extract two things:\n *\n * 1. The package name (extracted from the nearest `package.json`)\n * 2. The submodule name (...?? don't know how to get this yet)\n * 3. Any containing type names or namespace names.\n *\n * For tests, we also treat symbols in a file that has the string '/// fake-from-jsii'\n * as coming from jsii.\n */\nexport function lookupJsiiSymbol(typeChecker: ts.TypeChecker, sym: ts.Symbol): JsiiSymbol | undefined {\n // Resolve alias, if it is one. This comes into play if the symbol refers to a module,\n // we need to resolve the alias to find the ACTUAL module.\n if (hasAnyFlag(sym.flags, ts.SymbolFlags.Alias)) {\n sym = typeChecker.getAliasedSymbol(sym);\n }\n\n const decl: ts.Node | undefined = sym.declarations?.[0];\n if (!decl) {\n return undefined;\n }\n\n if (ts.isSourceFile(decl)) {\n // This is a module.\n const sourceAssembly = findTypeLookupAssembly(decl.fileName);\n return fmap(\n sourceAssembly,\n (asm) =>\n ({\n fqn:\n fmap(\n symbolIdentifier(\n typeChecker,\n sym,\n fmap(sourceAssembly, (sa) => ({ assembly: sa.assembly })),\n ),\n (symbolId) => sourceAssembly?.symbolIdMap[symbolId],\n ) ?? sourceAssembly?.assembly.name,\n sourceAssembly: asm,\n symbolType: 'module',\n } as JsiiSymbol),\n );\n }\n\n if (!isDeclaration(decl)) {\n return undefined;\n }\n\n const declaringFile = decl.getSourceFile();\n if (/^\\/\\/\\/ fake-from-jsii/m.test(declaringFile.getFullText())) {\n return { fqn: `fake_jsii.${sym.name}`, symbolType: 'type' };\n }\n\n const declSym = getSymbolFromDeclaration(decl, typeChecker);\n if (!declSym) {\n return undefined;\n }\n\n const fileName = decl.getSourceFile().fileName;\n const sourceAssembly = findTypeLookupAssembly(fileName);\n const symbolId = symbolIdentifier(typeChecker, declSym, { assembly: sourceAssembly?.assembly });\n if (!symbolId) {\n return undefined;\n }\n\n return fmap(/([^#]*)(#.*)?/.exec(symbolId), ([, typeSymbolId, memberFragment]) => {\n if (memberFragment) {\n return fmap(sourceAssembly?.symbolIdMap[typeSymbolId], (fqn) => ({\n fqn: `${fqn}${memberFragment}`,\n sourceAssembly,\n symbolType: 'member',\n }));\n }\n\n return fmap(sourceAssembly?.symbolIdMap[typeSymbolId], (fqn) => ({ fqn, sourceAssembly, symbolType: 'type' }));\n });\n}\n\nfunction isDeclaration(x: ts.Node): x is ts.Declaration {\n return (\n ts.isClassDeclaration(x) ||\n ts.isNamespaceExportDeclaration(x) ||\n ts.isNamespaceExport(x) ||\n ts.isModuleDeclaration(x) ||\n ts.isEnumDeclaration(x) ||\n ts.isEnumMember(x) ||\n ts.isInterfaceDeclaration(x) ||\n ts.isMethodDeclaration(x) ||\n ts.isMethodSignature(x) ||\n ts.isPropertyDeclaration(x) ||\n ts.isPropertySignature(x)\n );\n}\n\n/**\n * If the given type is an enum literal, resolve to the enum type\n */\nexport function resolveEnumLiteral(typeChecker: ts.TypeChecker, type: ts.Type) {\n if (!hasAnyFlag(type.flags, ts.TypeFlags.EnumLiteral)) {\n return type;\n }\n\n return typeChecker.getBaseTypeOfLiteralType(type);\n}\n\nexport function resolvedSymbolAtLocation(typeChecker: ts.TypeChecker, node: ts.Node) {\n let symbol = typeChecker.getSymbolAtLocation(node);\n while (symbol && hasAnyFlag(symbol.flags, ts.SymbolFlags.Alias)) {\n symbol = typeChecker.getAliasedSymbol(symbol);\n }\n return symbol;\n}\n\nfunction getSymbolFromDeclaration(decl: ts.Node, typeChecker: ts.TypeChecker): ts.Symbol | undefined {\n if (!isDeclaration(decl)) {\n return undefined;\n }\n\n const name = ts.getNameOfDeclaration(decl);\n return name ? typeChecker.getSymbolAtLocation(name) : undefined;\n}\n\nexport function parentSymbol(sym: JsiiSymbol): JsiiSymbol | undefined {\n const parts = sym.fqn.split('.');\n if (parts.length === 1) {\n return undefined;\n }\n\n return {\n fqn: parts.slice(0, -1).join('.'),\n symbolType: 'module', // Might not be true, but probably good enough\n sourceAssembly: sym.sourceAssembly,\n };\n}\n\n/**\n * Get the last part of a dot-separated string\n */\nexport function simpleName(x: string) {\n return x.split('.').slice(-1)[0];\n}\n\n/**\n * Get all parts except the last of a dot-separated string\n */\nexport function namespaceName(x: string) {\n return x.split('.').slice(0, -1).join('.');\n}\n"]}
|
1
|
+
{"version":3,"file":"jsii-utils.js","sourceRoot":"","sources":["../../src/jsii/jsii-utils.ts"],"names":[],"mappings":";;AAUA,8CAGC;AAED,8CAeC;AAqCD,gDAiBC;AAED,kCAGC;AAED,gCAGC;AAQD,gDAoBC;AAED,wEAEC;AA2BD,4DAEC;AAED,sDAkBC;AAeD,4CAkEC;AAqBD,gDAMC;AAED,4DAMC;AAWD,oCAWC;AAKD,gCAEC;AAKD,sCAEC;AAvUD,mCAAmC;AACnC,wCAA+C;AAC/C,iCAA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I,GAAG,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClE,CAAC;AAED,SAAgB,YAAY,CAAC,GAAe;IAC1C,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO;QACL,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QACjC,UAAU,EAAE,QAAQ,EAAE,8CAA8C;QACpE,cAAc,EAAE,GAAG,CAAC,cAAc;KACnC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,CAAS;IAClC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,CAAS;IACrC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import * as spec from '@jsii/spec';\nimport { symbolIdentifier } from 'jsii/common';\nimport * as ts from 'typescript';\n\nimport { findTypeLookupAssembly, TypeLookupAssembly } from './assemblies';\nimport { ObjectLiteralStruct } from './jsii-types';\nimport { AstRenderer } from '../renderer';\nimport { typeContainsUndefined } from '../typescript/types';\nimport { fmap } from '../util';\n\nexport function isNamedLikeStruct(name: string) {\n // Start with an I and another uppercase character\n return !/^I[A-Z]/.test(name);\n}\n\nexport function analyzeStructType(typeChecker: ts.TypeChecker, type: ts.Type): ObjectLiteralStruct | false {\n if (\n !type.isClassOrInterface() ||\n !hasAllFlags(type.objectFlags, ts.ObjectFlags.Interface) ||\n !isNamedLikeStruct(type.symbol.name)\n ) {\n return false;\n }\n\n const jsiiSym = lookupJsiiSymbol(typeChecker, type.symbol);\n if (jsiiSym) {\n return { kind: 'struct', type, jsiiSym };\n }\n\n return { kind: 'local-struct', type };\n}\n\n/**\n * Whether the given type is a protocol AND comes from jsii\n *\n * - Protocol: a TypeScript interface that is *not* a \"struct\" type.\n * A.k.a. \"behavioral interface\".\n * - From jsii: whether the interface type is defined in and exported\n * via a jsii assembly. There can be literal interfaces defined\n * in an example, and they will not be mangled in the same way\n * as a jsii interface would be.\n *\n *\n * Examples:\n *\n * ```ts\n * // isJsiiProtocolType() -> false: not a protocol\n * interface Banana {\n * readonly arc: number;\n * }\n *\n * // isJsiiProtocolType() -> might be true: depends on whether it was defined\n * // in a jsii assembly.\n * interface IHello {\n * sayIt(): void;\n * }\n *\n * // isJsiiProtocolType() -> false: declared to not be a protocol, even though\n * // it has the naming scheme of one\n * /**\n * * @struct\n * * /\n * interface IPAddress {\n * readonly octets: number[];\n * }\n * ```\n */\nexport function isJsiiProtocolType(typeChecker: ts.TypeChecker, type: ts.Type): boolean | undefined {\n if (!type.isClassOrInterface() || !hasAllFlags(type.objectFlags, ts.ObjectFlags.Interface)) {\n return false;\n }\n\n const sym = lookupJsiiSymbol(typeChecker, type.symbol);\n if (!sym) {\n return false;\n }\n\n if (!sym.sourceAssembly) {\n // No source assembly, so this is a 'fake-from-jsii' type\n return !isNamedLikeStruct(type.symbol.name);\n }\n\n const jsiiType = resolveJsiiSymbolType(sym);\n return spec.isInterfaceType(jsiiType) && !jsiiType.datatype;\n}\n\nexport function hasAllFlags<A extends number>(flags: A, test: A) {\n // tslint:disable-next-line:no-bitwise\n return test !== 0 && (flags & test) === test;\n}\n\nexport function hasAnyFlag<A extends number>(flags: A, test: A) {\n // tslint:disable-next-line:no-bitwise\n return test !== 0 && (flags & test) !== 0;\n}\n\nexport interface StructProperty {\n name: string;\n type: ts.Type | undefined;\n questionMark: boolean;\n}\n\nexport function propertiesOfStruct(type: ts.Type, context: AstRenderer<any>): StructProperty[] {\n return type.isClassOrInterface()\n ? type.getProperties().map((s) => {\n let propType;\n let questionMark = false;\n\n const propSymbol = type.getProperty(s.name)!;\n const symbolDecl = propSymbol.valueDeclaration ?? propSymbol.declarations![0];\n if (ts.isPropertyDeclaration(symbolDecl) || ts.isPropertySignature(symbolDecl)) {\n questionMark = symbolDecl.questionToken !== undefined;\n propType = symbolDecl.type && context.typeOfType(symbolDecl.type);\n }\n\n return {\n name: s.name,\n type: propType,\n questionMark,\n };\n })\n : [];\n}\n\nexport function structPropertyAcceptsUndefined(prop: StructProperty): boolean {\n return prop.questionMark || (!!prop.type && typeContainsUndefined(prop.type));\n}\n\n/**\n * A TypeScript symbol resolved to its jsii type\n */\nexport interface JsiiSymbol {\n /**\n * FQN of the symbol\n *\n * Is either the FQN of a type (for a type). For a membr, the FQN looks like:\n * 'type.fqn#memberName'.\n */\n readonly fqn: string;\n\n /**\n * What kind of symbol this is\n */\n readonly symbolType: 'module' | 'type' | 'member';\n\n /**\n * Assembly where the type was found\n *\n * Might be undefined if the type was FAKE from jsii (for tests)\n */\n readonly sourceAssembly?: TypeLookupAssembly;\n}\n\nexport function lookupJsiiSymbolFromNode(typeChecker: ts.TypeChecker, node: ts.Node): JsiiSymbol | undefined {\n return fmap(typeChecker.getSymbolAtLocation(node), (s) => lookupJsiiSymbol(typeChecker, s));\n}\n\nexport function resolveJsiiSymbolType(jsiiSymbol: JsiiSymbol): spec.Type {\n if (jsiiSymbol.symbolType !== 'type') {\n throw new Error(\n `Expected symbol to refer to a 'type', got '${jsiiSymbol.fqn}' which is a '${jsiiSymbol.symbolType}'`,\n );\n }\n\n if (!jsiiSymbol.sourceAssembly) {\n throw new Error('`resolveJsiiSymbolType: requires an actual source assembly');\n }\n\n const type = jsiiSymbol.sourceAssembly?.assembly.types?.[jsiiSymbol.fqn];\n if (!type) {\n throw new Error(\n `resolveJsiiSymbolType: ${jsiiSymbol.fqn} not found in assembly ${jsiiSymbol.sourceAssembly.assembly.name}`,\n );\n }\n return type;\n}\n\n/**\n * Returns the jsii FQN for a TypeScript (class or type) symbol\n *\n * TypeScript only knows the symbol NAME plus the FILE the symbol is defined\n * in. We need to extract two things:\n *\n * 1. The package name (extracted from the nearest `package.json`)\n * 2. The submodule name (...?? don't know how to get this yet)\n * 3. Any containing type names or namespace names.\n *\n * For tests, we also treat symbols in a file that has the string '/// fake-from-jsii'\n * as coming from jsii.\n */\nexport function lookupJsiiSymbol(typeChecker: ts.TypeChecker, sym: ts.Symbol): JsiiSymbol | undefined {\n // Resolve alias, if it is one. This comes into play if the symbol refers to a module,\n // we need to resolve the alias to find the ACTUAL module.\n if (hasAnyFlag(sym.flags, ts.SymbolFlags.Alias)) {\n sym = typeChecker.getAliasedSymbol(sym);\n }\n\n const decl: ts.Node | undefined = sym.declarations?.[0];\n if (!decl) {\n return undefined;\n }\n\n if (ts.isSourceFile(decl)) {\n // This is a module.\n const sourceAssembly = findTypeLookupAssembly(decl.fileName);\n return fmap(\n sourceAssembly,\n (asm) =>\n ({\n fqn:\n fmap(\n symbolIdentifier(\n typeChecker,\n sym,\n fmap(sourceAssembly, (sa) => ({ assembly: sa.assembly })),\n ),\n (symbolId) => sourceAssembly?.symbolIdMap[symbolId],\n ) ?? sourceAssembly?.assembly.name,\n sourceAssembly: asm,\n symbolType: 'module',\n } as JsiiSymbol),\n );\n }\n\n if (!isDeclaration(decl)) {\n return undefined;\n }\n\n const declaringFile = decl.getSourceFile();\n if (/^\\/\\/\\/ fake-from-jsii/m.test(declaringFile.getFullText())) {\n return { fqn: `fake_jsii.${sym.name}`, symbolType: 'type' };\n }\n\n const declSym = getSymbolFromDeclaration(decl, typeChecker);\n if (!declSym) {\n return undefined;\n }\n\n const fileName = decl.getSourceFile().fileName;\n const sourceAssembly = findTypeLookupAssembly(fileName);\n const symbolId = symbolIdentifier(typeChecker, declSym, { assembly: sourceAssembly?.assembly });\n if (!symbolId) {\n return undefined;\n }\n\n return fmap(/([^#]*)(#.*)?/.exec(symbolId), ([, typeSymbolId, memberFragment]) => {\n if (memberFragment) {\n return fmap(sourceAssembly?.symbolIdMap[typeSymbolId], (fqn) => ({\n fqn: `${fqn}${memberFragment}`,\n sourceAssembly,\n symbolType: 'member',\n }));\n }\n\n return fmap(sourceAssembly?.symbolIdMap[typeSymbolId], (fqn) => ({ fqn, sourceAssembly, symbolType: 'type' }));\n });\n}\n\nfunction isDeclaration(x: ts.Node): x is ts.Declaration {\n return (\n ts.isClassDeclaration(x) ||\n ts.isNamespaceExportDeclaration(x) ||\n ts.isNamespaceExport(x) ||\n ts.isModuleDeclaration(x) ||\n ts.isEnumDeclaration(x) ||\n ts.isEnumMember(x) ||\n ts.isInterfaceDeclaration(x) ||\n ts.isMethodDeclaration(x) ||\n ts.isMethodSignature(x) ||\n ts.isPropertyDeclaration(x) ||\n ts.isPropertySignature(x)\n );\n}\n\n/**\n * If the given type is an enum literal, resolve to the enum type\n */\nexport function resolveEnumLiteral(typeChecker: ts.TypeChecker, type: ts.Type) {\n if (!hasAnyFlag(type.flags, ts.TypeFlags.EnumLiteral)) {\n return type;\n }\n\n return typeChecker.getBaseTypeOfLiteralType(type);\n}\n\nexport function resolvedSymbolAtLocation(typeChecker: ts.TypeChecker, node: ts.Node) {\n let symbol = typeChecker.getSymbolAtLocation(node);\n while (symbol && hasAnyFlag(symbol.flags, ts.SymbolFlags.Alias)) {\n symbol = typeChecker.getAliasedSymbol(symbol);\n }\n return symbol;\n}\n\nfunction getSymbolFromDeclaration(decl: ts.Node, typeChecker: ts.TypeChecker): ts.Symbol | undefined {\n if (!isDeclaration(decl)) {\n return undefined;\n }\n\n const name = ts.getNameOfDeclaration(decl);\n return name ? typeChecker.getSymbolAtLocation(name) : undefined;\n}\n\nexport function parentSymbol(sym: JsiiSymbol): JsiiSymbol | undefined {\n const parts = sym.fqn.split('.');\n if (parts.length === 1) {\n return undefined;\n }\n\n return {\n fqn: parts.slice(0, -1).join('.'),\n symbolType: 'module', // Might not be true, but probably good enough\n sourceAssembly: sym.sourceAssembly,\n };\n}\n\n/**\n * Get the last part of a dot-separated string\n */\nexport function simpleName(x: string) {\n return x.split('.').slice(-1)[0];\n}\n\n/**\n * Get all parts except the last of a dot-separated string\n */\nexport function namespaceName(x: string) {\n return x.split('.').slice(0, -1).join('.');\n}\n"]}
|
package/lib/jsii/packages.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.jsiiTargetParameter =
|
3
|
+
exports.jsiiTargetParameter = jsiiTargetParameter;
|
4
4
|
function jsiiTargetParameter(target, field) {
|
5
5
|
const path = field.split('.');
|
6
6
|
let r = target.targets;
|
@@ -9,5 +9,4 @@ function jsiiTargetParameter(target, field) {
|
|
9
9
|
}
|
10
10
|
return r;
|
11
11
|
}
|
12
|
-
exports.jsiiTargetParameter = jsiiTargetParameter;
|
13
12
|
//# sourceMappingURL=packages.js.map
|
package/lib/jsii/packages.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"packages.js","sourceRoot":"","sources":["../../src/jsii/packages.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"packages.js","sourceRoot":"","sources":["../../src/jsii/packages.ts"],"names":[],"mappings":";;AAEA,kDAOC;AAPD,SAAgB,mBAAmB,CAAC,MAAuB,EAAE,KAAa;IACxE,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAQ,MAAM,CAAC,OAAO,CAAC;IAC5B,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAC9D,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC","sourcesContent":["import * as spec from '@jsii/spec';\n\nexport function jsiiTargetParameter(target: spec.Targetable, field: string) {\n const path = field.split('.');\n let r: any = target.targets;\n while (path.length > 0 && typeof r === 'object' && r !== null) {\n r = r[path.splice(0, 1)[0]];\n }\n return r;\n}\n"]}
|
package/lib/json.d.ts
CHANGED
package/lib/json.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.parse = parse;
|
4
|
+
exports.stringify = stringify;
|
4
5
|
const node_stream_1 = require("node:stream");
|
5
6
|
const node_util_1 = require("node:util");
|
6
7
|
const stream_json_1 = require("stream-json");
|
@@ -27,7 +28,6 @@ function parse(reader) {
|
|
27
28
|
assembler.connectTo(jsonParser);
|
28
29
|
return asyncPipeline(reader, jsonParser).then(() => assembler.current);
|
29
30
|
}
|
30
|
-
exports.parse = parse;
|
31
31
|
/**
|
32
32
|
* Serializes a possibly large object into the provided writer. The object may
|
33
33
|
* be large enough that the JSON text cannot fit in a single string value.
|
@@ -45,5 +45,4 @@ async function stringify(value, ...writers) {
|
|
45
45
|
reader.push(null);
|
46
46
|
return asyncPipeline(reader, (0, Disassembler_1.disassembler)(), (0, Stringer_1.stringer)(), ...writers);
|
47
47
|
}
|
48
|
-
exports.stringify = stringify;
|
49
48
|
//# sourceMappingURL=json.js.map
|
package/lib/json.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;AAsBA,sBAKC;AAaD,8BASC;AAjDD,6CAAiD;AACjD,yCAAsC;AACtC,6CAAqC;AACrC,mDAAmD;AACnD,2DAAwD;AACxD,mDAAgD;AAEhD,kFAAkF;AAClF,MAAM,aAAa,GAAG,IAAA,qBAAS,EAAC,sBAAQ,CAAC,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,SAAgB,KAAK,CAAC,MAAgB;IACpC,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IAClC,MAAM,UAAU,GAAG,IAAA,oBAAM,GAAE,CAAC;IAC5B,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAChC,OAAO,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACzE,CAAC;AAED;;;;;;;;;;GAUG;AACI,KAAK,UAAU,SAAS,CAC7B,KAAU,EACV,GAAG,OAA8D;IAEjE,MAAM,MAAM,GAAG,IAAI,sBAAQ,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAElB,OAAO,aAAa,CAAC,MAAM,EAAE,IAAA,2BAAY,GAAE,EAAE,IAAA,mBAAQ,GAAE,EAAE,GAAG,OAAO,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import { Readable, pipeline } from 'node:stream';\nimport { promisify } from 'node:util';\nimport { parser } from 'stream-json';\nimport * as Assembler from 'stream-json/Assembler';\nimport { disassembler } from 'stream-json/Disassembler';\nimport { stringer } from 'stream-json/Stringer';\n\n// NB: In node 15+, there is a node:stream.promises object that has this built-in.\nconst asyncPipeline = promisify(pipeline);\n\n/**\n * Asynchronously parses a single JSON value from the provided reader. The JSON\n * text might be longer than what could fit in a single string value, since the\n * processing is done in a streaming manner.\n *\n * Prefer using JSON.parse if you know the entire JSON text is always small\n * enough to fit in a string value, as this would have better performance.\n *\n * @param reader the reader from which to consume JSON text.\n *\n * @returns the parse JSON value as a Javascript value.\n */\nexport function parse(reader: Readable): Promise<any> {\n const assembler = new Assembler();\n const jsonParser = parser();\n assembler.connectTo(jsonParser);\n return asyncPipeline(reader, jsonParser).then(() => assembler.current);\n}\n\n/**\n * Serializes a possibly large object into the provided writer. The object may\n * be large enough that the JSON text cannot fit in a single string value.\n *\n * Prefer using JSON.stringify if you know the object is always small enough\n * that the JSON text can fit in a single string value, as this would have\n * better performance.\n *\n * @param value the value to be serialized.\n * @param writers the sequence of write streams to use to output the JSON text.\n */\nexport async function stringify(\n value: any,\n ...writers: Array<NodeJS.ReadWriteStream | NodeJS.WritableStream>\n): Promise<void> {\n const reader = new Readable({ objectMode: true });\n reader.push(value);\n reader.push(null);\n\n return asyncPipeline(reader, disassembler(), stringer(), ...writers);\n}\n"]}
|
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.TargetLanguage = void 0;
|
4
|
+
exports.targetName = targetName;
|
5
|
+
exports.supportsTransitiveSubmoduleAccess = supportsTransitiveSubmoduleAccess;
|
4
6
|
const assert = require("node:assert");
|
5
7
|
var TargetLanguage;
|
6
8
|
(function (TargetLanguage) {
|
@@ -28,7 +30,6 @@ function targetName(language) {
|
|
28
30
|
return 'go';
|
29
31
|
}
|
30
32
|
}
|
31
|
-
exports.targetName = targetName;
|
32
33
|
/**
|
33
34
|
* Determines whether the supplied language supports transitive submodule
|
34
35
|
* access (similar to how TypeScript/Javascript allows to use a partially
|
@@ -64,5 +65,4 @@ function supportsTransitiveSubmoduleAccess(language) {
|
|
64
65
|
return false;
|
65
66
|
}
|
66
67
|
}
|
67
|
-
exports.supportsTransitiveSubmoduleAccess = supportsTransitiveSubmoduleAccess;
|
68
68
|
//# sourceMappingURL=target-language.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"target-language.js","sourceRoot":"","sources":["../../src/languages/target-language.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"target-language.js","sourceRoot":"","sources":["../../src/languages/target-language.ts"],"names":[],"mappings":";;;AA2BA,gCAgBC;AAwBD,8EAYC;AA/ED,sCAAsC;AAEtC,IAAY,cAOX;AAPD,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,mCAAiB,CAAA;IACjB,+BAAa,CAAA;IACb,2BAAS,CAAA;IACT,kGAAkG;IAClG,sCAAoB,CAAA;AACtB,CAAC,EAPW,cAAc,8BAAd,cAAc,QAOzB;AAED,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;AAgBtE,SAAgB,UAAU,CAAC,QAAwB;IACjD,4FAA4F;IAC5F,sFAAsF;IACtF,MAAM,CAAC,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,kDAAkD,QAAQ,EAAE,CAAC,CAAC;IAE3G,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,cAAc,CAAC,SAAS,CAAC;QAC9B,KAAK,cAAc,CAAC,MAAM;YACxB,OAAO,QAAQ,CAAC;QAClB,KAAK,cAAc,CAAC,MAAM;YACxB,OAAO,QAAQ,CAAC;QAClB,KAAK,cAAc,CAAC,IAAI;YACtB,OAAO,MAAM,CAAC;QAChB,KAAK,cAAc,CAAC,EAAE;YACpB,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,iCAAiC,CAAC,QAAwB;IACxE,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,cAAc,CAAC,SAAS,CAAC;QAC9B,KAAK,cAAc,CAAC,MAAM;YACxB,OAAO,IAAI,CAAC;QACd,KAAK,cAAc,CAAC,MAAM;YACxB,OAAO,IAAI,CAAC;QACd,KAAK,cAAc,CAAC,IAAI;YACtB,OAAO,KAAK,CAAC;QACf,KAAK,cAAc,CAAC,EAAE;YACpB,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC","sourcesContent":["import * as assert from 'node:assert';\n\nexport enum TargetLanguage {\n PYTHON = 'python',\n CSHARP = 'csharp',\n JAVA = 'java',\n GO = 'go',\n /** @internal an alias of PYTHON to make intent clear when language is irrelevant, must be last */\n VISUALIZE = 'python',\n}\n\nconst VALID_TARGET_LANGUAGES = new Set(Object.values(TargetLanguage));\n\nexport function targetName(language: TargetLanguage): 'python' | 'dotnet' | 'java' | 'go';\nexport function targetName(language: TargetLanguage.PYTHON): 'python';\nexport function targetName(language: TargetLanguage.CSHARP): 'dotnet';\nexport function targetName(language: TargetLanguage.JAVA): 'java';\nexport function targetName(language: TargetLanguage.GO): 'go';\n/** @internal an alias of PYTHON to make intent clear when language is irrelevant, must be last override */\nexport function targetName(language: TargetLanguage.VISUALIZE): 'python';\n\n/**\n * @param language a possible value for `TargetLanguage`.\n *\n * @returns the name of the target configuration block for the given language.\n */\nexport function targetName(language: TargetLanguage): 'python' | 'dotnet' | 'java' | 'go';\nexport function targetName(language: TargetLanguage): 'python' | 'dotnet' | 'java' | 'go' {\n // The TypeScript compiler should guarantee the below `switch` statement covers all possible\n // values of the TargetLanguage enum, but we add an assert here for clarity of intent.\n assert(VALID_TARGET_LANGUAGES.has(language), `Invalid/unexpected target language identifier: ${language}`);\n\n switch (language) {\n case TargetLanguage.VISUALIZE:\n case TargetLanguage.PYTHON:\n return 'python';\n case TargetLanguage.CSHARP:\n return 'dotnet';\n case TargetLanguage.JAVA:\n return 'java';\n case TargetLanguage.GO:\n return 'go';\n }\n}\n\n/**\n * Determines whether the supplied language supports transitive submodule\n * access (similar to how TypeScript/Javascript allows to use a partially\n * qualified name to access a namespace-nested value).\n *\n * If `true`, imports will mirror those found in the original TypeScript\n * code, namespace-traversing property accesses will be rendered as such. This\n * means the following snippet would be transformed \"as-is\":\n * ```ts\n * import * as cdk from 'aws-cdk-lib';\n * new cdk.aws_s3.Bucket(this, 'Bucket');\n * ```\n *\n * If `false` on the other hand, each used submodule will be imported\n * separately and namespace-traversing property accesses will be replaced with\n * references to the separately-imported submodule. This means the above\n * snippet would be transformed as if it had been modifired to:\n * ```ts\n * import * as aws_s3 from 'aws-cdk-lib/aws-s3';\n * new aws_s3.Bucket(this, 'Bucket');\n * ```\n */\nexport function supportsTransitiveSubmoduleAccess(language: TargetLanguage): boolean {\n switch (language) {\n case TargetLanguage.VISUALIZE:\n case TargetLanguage.PYTHON:\n return true;\n case TargetLanguage.CSHARP:\n return true;\n case TargetLanguage.JAVA:\n return false;\n case TargetLanguage.GO:\n return false;\n }\n}\n"]}
|
package/lib/logging.js
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.level = exports.LEVEL_VERBOSE = exports.LEVEL_INFO = exports.Level = void 0;
|
4
|
+
exports.configure = configure;
|
5
|
+
exports.warn = warn;
|
6
|
+
exports.error = error;
|
7
|
+
exports.info = info;
|
8
|
+
exports.debug = debug;
|
4
9
|
const util = require("node:util");
|
5
10
|
var Level;
|
6
11
|
(function (Level) {
|
@@ -17,23 +22,18 @@ exports.level = Level.QUIET;
|
|
17
22
|
function configure({ level: newLevel }) {
|
18
23
|
exports.level = newLevel;
|
19
24
|
}
|
20
|
-
exports.configure = configure;
|
21
25
|
function warn(fmt, ...args) {
|
22
26
|
log(Level.WARN, fmt, ...args);
|
23
27
|
}
|
24
|
-
exports.warn = warn;
|
25
28
|
function error(fmt, ...args) {
|
26
29
|
log(Level.ERROR, fmt, ...args);
|
27
30
|
}
|
28
|
-
exports.error = error;
|
29
31
|
function info(fmt, ...args) {
|
30
32
|
log(Level.INFO, fmt, ...args);
|
31
33
|
}
|
32
|
-
exports.info = info;
|
33
34
|
function debug(fmt, ...args) {
|
34
35
|
log(Level.VERBOSE, fmt, ...args);
|
35
36
|
}
|
36
|
-
exports.debug = debug;
|
37
37
|
function log(messageLevel, fmt, ...args) {
|
38
38
|
if (exports.level >= messageLevel) {
|
39
39
|
const levelName = Level[messageLevel];
|
package/lib/logging.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":";;;AAgBA,8BAEC;AAED,oBAEC;AAED,sBAEC;AAED,oBAEC;AAED,sBAEC;AAlCD,kCAAkC;AAElC,IAAY,KAMX;AAND,WAAY,KAAK;IACf,oCAAU,CAAA;IACV,kCAAS,CAAA;IACT,mCAAS,CAAA;IACT,iCAAQ,CAAA;IACR,uCAAW,CAAA;AACb,CAAC,EANW,KAAK,qBAAL,KAAK,QAMhB;AAEY,QAAA,UAAU,GAAW,KAAK,CAAC,IAAI,CAAC;AAChC,QAAA,aAAa,GAAW,KAAK,CAAC,OAAO,CAAC;AAEnD,4DAA4D;AACjD,QAAA,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;AAE/B,SAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAoB;IAC7D,aAAK,GAAG,QAAQ,CAAC;AACnB,CAAC;AAED,SAAgB,IAAI,CAAC,GAAW,EAAE,GAAG,IAAW;IAC9C,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC;AAED,SAAgB,KAAK,CAAC,GAAW,EAAE,GAAG,IAAW;IAC/C,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,SAAgB,IAAI,CAAC,GAAW,EAAE,GAAG,IAAW;IAC9C,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC;AAED,SAAgB,KAAK,CAAC,GAAW,EAAE,GAAG,IAAW;IAC/C,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,GAAG,CAAC,YAAmB,EAAE,GAAW,EAAE,GAAG,IAAW;IAC3D,IAAI,aAAK,IAAI,YAAY,EAAE,CAAC;QAC1B,MAAM,SAAS,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;QACtC,wFAAwF;QACxF,gCAAgC;QAChC,OAAO,CAAC,KAAK,CAAC,mBAAmB,SAAS,KAAK,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC","sourcesContent":["import * as util from 'node:util';\n\nexport enum Level {\n ERROR = -2,\n WARN = -1,\n QUIET = 0,\n INFO = 1,\n VERBOSE = 2,\n}\n\nexport const LEVEL_INFO: number = Level.INFO;\nexport const LEVEL_VERBOSE: number = Level.VERBOSE;\n\n/** The minimal logging level for messages to be emitted. */\nexport let level = Level.QUIET;\n\nexport function configure({ level: newLevel }: { level: Level }) {\n level = newLevel;\n}\n\nexport function warn(fmt: string, ...args: any[]) {\n log(Level.WARN, fmt, ...args);\n}\n\nexport function error(fmt: string, ...args: any[]) {\n log(Level.ERROR, fmt, ...args);\n}\n\nexport function info(fmt: string, ...args: any[]) {\n log(Level.INFO, fmt, ...args);\n}\n\nexport function debug(fmt: string, ...args: any[]) {\n log(Level.VERBOSE, fmt, ...args);\n}\n\nfunction log(messageLevel: Level, fmt: string, ...args: any[]) {\n if (level >= messageLevel) {\n const levelName = Level[messageLevel];\n // `console.error` will automatically be transported from worker child to worker parent,\n // process.stderr.write() won't.\n console.error(`[jsii-rosetta] [${levelName}] ${util.format(fmt, ...args)}`);\n }\n}\n"]}
|