@atlassian/clientside-extensions-schema 5.1.6-eadeedb5-mltiipai → 6.0.0-m002
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/dist/cjs/bin/generate-from-schema.js +2 -2
- package/dist/cjs/bin/generate-from-schema.js.map +1 -1
- package/dist/cjs/bin/generate-graphql-definitions.js.map +1 -1
- package/dist/cjs/bin/generate-module-definitions-file.js.map +1 -1
- package/dist/cjs/code-generator/code-generator.js.map +1 -1
- package/dist/cjs/code-generator/react.js +0 -2
- package/dist/cjs/code-generator/react.js.map +1 -1
- package/dist/cjs/code-generator/type-definitions.js +1 -1
- package/dist/cjs/code-generator/type-definitions.js.map +1 -1
- package/dist/cjs/graphql-definition.js +2 -27
- package/dist/cjs/graphql-definition.js.map +1 -1
- package/dist/cjs/loader/schema-loader.js +1 -1
- package/dist/cjs/loader/schema-loader.js.map +1 -1
- package/dist/cjs/scalars/extensions/ModalOnAction.js +1 -1
- package/dist/cjs/scalars/extensions/ModalOnAction.js.map +1 -1
- package/dist/cjs/scalars/extensions/PanelOnAction.js +1 -1
- package/dist/cjs/scalars/extensions/PanelOnAction.js.map +1 -1
- package/dist/cjs/scalars/types.js +1 -2
- package/dist/cjs/scalars/types.js.map +1 -1
- package/dist/cjs/utils/ast-utils.js +1 -1
- package/dist/cjs/utils/ast-utils.js.map +1 -1
- package/dist/cjs/utils/create-schema.js.map +1 -1
- package/dist/cjs/utils/pascal-case.js +2 -2
- package/dist/cjs/utils/pascal-case.js.map +1 -1
- package/dist/cjs/utils/schema-document-populator.js +0 -1
- package/dist/cjs/utils/schema-document-populator.js.map +1 -1
- package/dist/cjs/utils/schema-document-serializer.js.map +1 -1
- package/dist/cjs/utils/schema.js +0 -1
- package/dist/cjs/utils/schema.js.map +1 -1
- package/dist/cjs/utils/validator-generator.js +6 -6
- package/dist/cjs/utils/validator-generator.js.map +1 -1
- package/dist/cjs/utils/validator-types.js +1 -1
- package/dist/cjs/utils/validator-types.js.map +1 -1
- package/dist/cjs/utils.js +1 -3
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/bin/generate-from-schema.js +1 -1
- package/dist/esm/bin/generate-from-schema.js.map +1 -1
- package/dist/esm/bin/generate-graphql-definitions.js.map +1 -1
- package/dist/esm/bin/generate-module-definitions-file.js.map +1 -1
- package/dist/esm/code-generator/code-generator.js.map +1 -1
- package/dist/esm/code-generator/react.js +0 -2
- package/dist/esm/code-generator/react.js.map +1 -1
- package/dist/esm/code-generator/type-definitions.js.map +1 -1
- package/dist/esm/loader/schema-loader.js.map +1 -1
- package/dist/esm/scalars/extensions/ModalOnAction.js +1 -1
- package/dist/esm/scalars/extensions/ModalOnAction.js.map +1 -1
- package/dist/esm/scalars/extensions/PanelOnAction.js +1 -1
- package/dist/esm/scalars/extensions/PanelOnAction.js.map +1 -1
- package/dist/esm/scalars/types.js +0 -1
- package/dist/esm/scalars/types.js.map +1 -1
- package/dist/esm/utils/ast-utils.js.map +1 -1
- package/dist/esm/utils/create-schema.js.map +1 -1
- package/dist/esm/utils/pascal-case.js +1 -1
- package/dist/esm/utils/pascal-case.js.map +1 -1
- package/dist/esm/utils/schema-document-populator.js +0 -1
- package/dist/esm/utils/schema-document-populator.js.map +1 -1
- package/dist/esm/utils/schema-document-serializer.js.map +1 -1
- package/dist/esm/utils/schema.js +0 -1
- package/dist/esm/utils/schema.js.map +1 -1
- package/dist/esm/utils/validator-generator.js +6 -6
- package/dist/esm/utils/validator-generator.js.map +1 -1
- package/dist/esm/utils.js +0 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/code-generator/react.d.ts.map +1 -1
- package/dist/types/scalars/types.d.ts.map +1 -1
- package/dist/types/utils/ast-utils.d.ts.map +1 -1
- package/dist/types/utils/create-schema.d.ts.map +1 -1
- package/dist/types/utils/injcect-types.d.ts.map +1 -1
- package/dist/types/utils/inject-built-in-scalars.d.ts.map +1 -1
- package/dist/types/utils/inject-provided-types.d.ts.map +1 -1
- package/dist/types/utils/pascal-case.d.ts.map +1 -1
- package/dist/types/utils/schema-document-populator.d.ts.map +1 -1
- package/dist/types/utils/schema-document-serializer.d.ts.map +1 -1
- package/dist/types/utils/schema.d.ts.map +1 -1
- package/dist/types/utils/validator-checks.d.ts.map +1 -1
- package/dist/types/utils/validator-generator.d.ts.map +1 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/lib/bin/generate-from-schema.ts +1 -1
- package/lib/code-generator/react.ts +0 -2
- package/lib/scalars/types.ts +0 -1
- package/lib/utils/pascal-case.ts +1 -1
- package/lib/utils/schema-document-populator.ts +0 -2
- package/lib/utils/schema.ts +0 -2
- package/lib/utils/validator-generator.test.ts +2 -2
- package/lib/utils/validator-generator.ts +7 -10
- package/lib/utils.ts +0 -1
- package/package.json +18 -20
|
@@ -9,7 +9,7 @@ const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
|
9
9
|
const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
|
|
10
10
|
const rimraf_1 = require("rimraf");
|
|
11
11
|
const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
|
|
12
|
-
const
|
|
12
|
+
const snakeCase_1 = tslib_1.__importDefault(require("lodash/snakeCase"));
|
|
13
13
|
const code_generator_1 = tslib_1.__importDefault(require("../code-generator/code-generator"));
|
|
14
14
|
const schema_1 = require("../utils/schema");
|
|
15
15
|
const appendExtension = (baseFileName, extension) => {
|
|
@@ -19,7 +19,7 @@ const getGeneratorTargetDirectory = (filePath) => {
|
|
|
19
19
|
return path_1.default.join(path_1.default.dirname(filePath), 'generated');
|
|
20
20
|
};
|
|
21
21
|
const ensureFileName = (name) => {
|
|
22
|
-
return (0,
|
|
22
|
+
return (0, snakeCase_1.default)(name);
|
|
23
23
|
};
|
|
24
24
|
const bustCacheForFile = (filePath) => {
|
|
25
25
|
delete require.cache[require.resolve(filePath)]; // watch mode cache busting
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-from-schema.js","sourceRoot":"","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;aACtE;QACL,CAAC,CAAC,CAAC;KACV;AACL,CAAC,CAAC;AACF,oEAAoE;AACpE,eAAK;KACA,OAAO,CACJ,cAAc,EACd,iEAAiE,EACjE,CAAC,OAAO,EAAE,EAAE;IACR,OAAO;SACF,MAAM,CAAC,MAAM,EAAE;QACZ,QAAQ,EAAE,+BAA+B;QACzC,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;KACrB,CAAC;SACD,MAAM,CAAC,aAAa,EAAE;QACnB,QAAQ,EAAE,gCAAgC;QAC1C,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,IAAI;KAChB,CAAC;SACD,MAAM,CAAC,gBAAgB,EAAE;QACtB,QAAQ,EAAE,kDAAkD;QAC5D,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,EAAE;KACd,CAAC;QACF,mBAAmB;SAClB,MAAM,CAAC,gBAAgB,EAAE;QACtB,QAAQ,EAAE,sDAAsD;QAChE,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACjB,CAAC;SACD,MAAM,CAAC,OAAO,EAAE;QACb,QAAQ,EAAE,iDAAiD;QAC3D,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACjB,CAAC;SACD,MAAM,CAAC,KAAK,EAAE;QACX,QAAQ,EAAE,+EAA+E;QACzF,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;KACzB,CAAC,CAAC;AACX,CAAC,EACD,GAAG,CACN;KACA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,4BAA4B","sourcesContent":["#!/usr/bin/env node\nimport { glob } from 'glob';\nimport yargs from 'yargs';\nimport path from 'path';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp';\nimport { rimraf } from 'rimraf';\nimport chokidar from 'chokidar';\nimport snakeCase from 'lodash.snakecase';\nimport generateCode from '../code-generator/code-generator';\nimport { loadSchema } from '../utils/schema';\n\nimport type { FileWriter, GeneratorOptions } from '../code-generator/code-generator';\n\nconst appendExtension = (baseFileName: string, extension: string) => {\n return `${baseFileName}.${extension}`;\n};\n\nconst getGeneratorTargetDirectory = (filePath: string) => {\n return path.join(path.dirname(filePath), 'generated');\n};\n\nconst ensureFileName = (name: string) => {\n return snakeCase(name) as string;\n};\n\nconst bustCacheForFile = (filePath: string) => {\n delete require.cache[require.resolve(filePath)]; // watch mode cache busting\n};\n\nconst toRelativeIfExists = (filePath: string) => {\n if (!filePath) {\n return null;\n }\n\n return `./${filePath}`;\n};\n\nconst writeContentsToFile =\n (targetDirectory: string): FileWriter =>\n async (baseIdentifier: string, typescriptCode: string, javascriptCode: string) => {\n const baseFilename = ensureFileName(baseIdentifier);\n const wrapperFileNameTs = path.join(targetDirectory, appendExtension(baseFilename, 'ts'));\n const wrapperFileNameJs = path.join(targetDirectory, appendExtension(baseFilename, 'js'));\n await mkdirp(path.dirname(wrapperFileNameTs));\n await fs.promises.writeFile(wrapperFileNameTs, typescriptCode, 'utf8');\n await fs.promises.writeFile(wrapperFileNameJs, javascriptCode, 'utf8');\n\n return toRelativeIfExists(baseFilename);\n };\n\nconst generateContentForSchemaFile = async (filePath: string, generatorOptions: GeneratorOptions) => {\n bustCacheForFile(filePath);\n const schemaData = await loadSchema(filePath);\n if (!schemaData) {\n return;\n }\n const targetDirectory = getGeneratorTargetDirectory(filePath);\n try {\n await generateCode(schemaData, generatorOptions, writeContentsToFile(targetDirectory), true);\n } catch (e) {\n console.error(`Something went wrong trying to generate the hooks for your extension point specified at \"${filePath}\".\nIf this persists, feel free to raise an issue with us at: https://bitbucket.org/atlassian/atlassian-clientside-extensions/issues\n\nProvided Schema:\n${schemaData}\nOriginal Error:\n${e}`);\n }\n};\n\nconst cleanupTargetDir = async (targetDir: string) => {\n await rimraf(targetDir);\n};\n\ntype Options = yargs.Arguments<{\n glob: string;\n cwd: string;\n watch: boolean;\n providedTypes: string;\n strictMode: boolean;\n validatorOnly: boolean;\n}>;\n\nconst getProvidedTypesPaths = async (options: Options): Promise<string[]> => {\n let paths: string[] = [];\n const { providedTypes: pattern, cwd } = options;\n\n if (pattern) {\n paths = await glob(pattern, { cwd, ignore: '**/node_modules/**', dotRelative: true });\n\n if (!paths.length) {\n console.warn(`Schema code generator: Provided pattern \"${pattern}\" could not find any files with GraphQL provided types`);\n }\n }\n\n return paths;\n};\n\nconst generate = async (options: Options, providedTypesPaths: string[]) => {\n const { glob: pattern, cwd, strictMode, validatorOnly } = options;\n\n // TODO: Extract all this\n const resultFiles = await glob(pattern, { cwd, ignore: '**/node_modules/**', dotRelative: true });\n const absoluteFilePaths = resultFiles.map((filePath) => path.resolve(path.join(cwd, filePath)));\n\n // eslint-disable-next-line no-restricted-syntax\n for (const absolutePath of absoluteFilePaths) {\n // we have to run this first to remove all preexisting directories before generating any files\n // eslint-disable-next-line no-await-in-loop\n await cleanupTargetDir(getGeneratorTargetDirectory(absolutePath));\n }\n\n const generatorOptions: GeneratorOptions = {\n providedTypesPaths,\n strictMode,\n validatorOnly,\n };\n\n // eslint-disable-next-line no-restricted-syntax\n for (const absolutePath of absoluteFilePaths) {\n bustCacheForFile(absolutePath);\n // eslint-disable-next-line no-await-in-loop\n await generateContentForSchemaFile(absolutePath, generatorOptions);\n }\n};\n\nconst run = async (options: Options) => {\n // TODO: Refactor this part to be more smart about watching changes in provided types\n let providedTypesPaths = await getProvidedTypesPaths(options);\n\n await generate(options, providedTypesPaths);\n\n if (options.watch) {\n console.log('Schema code generator watching for changes....');\n chokidar\n .watch([options.glob, options.providedTypes], {\n cwd: options.cwd,\n ignored: (changedFilePath: string) => {\n return changedFilePath.includes('node_modules');\n },\n })\n .on('all', async (eventName: string, filePath: string) => {\n // eslint-disable-next-line no-console\n console.log(`Schema code generator detected changes. Rebuilding \"${filePath}\"...`);\n const absolutePath = path.resolve(path.join(options.cwd, filePath));\n if (eventName !== 'unlink') {\n bustCacheForFile(absolutePath);\n\n // TODO: Refactor this part to be more smart about watching changes in provided types\n providedTypesPaths = await getProvidedTypesPaths(options);\n\n const generatorOptions: GeneratorOptions = {\n providedTypesPaths,\n strictMode: options.strictMode,\n validatorOnly: options.validatorOnly,\n };\n\n await generateContentForSchemaFile(absolutePath, generatorOptions);\n }\n });\n }\n};\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\nyargs\n .command(\n '$0 [options]',\n 'Generate hooks and other related code based on provided schema.',\n (builder) => {\n builder\n .option('glob', {\n describe: `Glob pattern to find schemas.`,\n type: 'string',\n demandOption: true,\n })\n .option('strict-mode', {\n describe: 'Toggles validation strict mode',\n type: 'boolean',\n default: true,\n })\n .option('provided-types', {\n describe: `Glob pattern to find provided types for schemas.`,\n type: 'string',\n default: '',\n })\n /** @since 2.1.0 */\n .option('validator-only', {\n describe: `Only generate validators for the given schema files.`,\n type: 'boolean',\n default: false,\n })\n .option('watch', {\n describe: `Continuously watch for and generate on changes.`,\n type: 'boolean',\n default: false,\n })\n .option('cwd', {\n describe: `The cwd in which the glob is searching for schemas. Defaults to process.cwd()`,\n type: 'string',\n default: process.cwd(),\n });\n },\n run,\n )\n .help().argv; // for --help and -h to work\n"]}
|
|
1
|
+
{"version":3,"file":"generate-from-schema.js","sourceRoot":"","sources":["../../../lib/bin/generate-from-schema.ts"],"names":[],"mappings":";;;;AACA,+BAA4B;AAC5B,0DAA0B;AAC1B,wDAAwB;AACxB,oDAAoB;AACpB,4DAA4B;AAC5B,mCAAgC;AAChC,gEAAgC;AAChC,yEAAyC;AACzC,8FAA4D;AAC5D,4CAA6C;AAI7C,MAAM,eAAe,GAAG,CAAC,YAAoB,EAAE,SAAiB,EAAE,EAAE;IAChE,OAAO,GAAG,YAAY,IAAI,SAAS,EAAE,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,2BAA2B,GAAG,CAAC,QAAgB,EAAE,EAAE;IACrD,OAAO,cAAI,CAAC,IAAI,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,C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M,CAAC,gBAAgB,EAAE;QACtB,QAAQ,EAAE,kDAAkD;QAC5D,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,EAAE;KACd,CAAC;QACF,mBAAmB;SAClB,MAAM,CAAC,gBAAgB,EAAE;QACtB,QAAQ,EAAE,sDAAsD;QAChE,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACjB,CAAC;SACD,MAAM,CAAC,OAAO,EAAE;QACb,QAAQ,EAAE,iDAAiD;QAC3D,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACjB,CAAC;SACD,MAAM,CAAC,KAAK,EAAE;QACX,QAAQ,EAAE,+EAA+E;QACzF,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;KACzB,CAAC,CAAC;AACX,CAAC,EACD,GAAG,CACN;KACA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,4BAA4B","sourcesContent":["#!/usr/bin/env node\nimport { glob } from 'glob';\nimport yargs from 'yargs';\nimport path from 'path';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp';\nimport { rimraf } from 'rimraf';\nimport chokidar from 'chokidar';\nimport snakeCase from 'lodash/snakeCase';\nimport generateCode from '../code-generator/code-generator';\nimport { loadSchema } from '../utils/schema';\n\nimport type { FileWriter, GeneratorOptions } from '../code-generator/code-generator';\n\nconst appendExtension = (baseFileName: string, extension: string) => {\n return `${baseFileName}.${extension}`;\n};\n\nconst getGeneratorTargetDirectory = (filePath: string) => {\n return path.join(path.dirname(filePath), 'generated');\n};\n\nconst ensureFileName = (name: string) => {\n return snakeCase(name) as string;\n};\n\nconst bustCacheForFile = (filePath: string) => {\n delete require.cache[require.resolve(filePath)]; // watch mode cache busting\n};\n\nconst toRelativeIfExists = (filePath: string) => {\n if (!filePath) {\n return null;\n }\n\n return `./${filePath}`;\n};\n\nconst writeContentsToFile =\n (targetDirectory: string): FileWriter =>\n async (baseIdentifier: string, typescriptCode: string, javascriptCode: string) => {\n const baseFilename = ensureFileName(baseIdentifier);\n const wrapperFileNameTs = path.join(targetDirectory, appendExtension(baseFilename, 'ts'));\n const wrapperFileNameJs = path.join(targetDirectory, appendExtension(baseFilename, 'js'));\n await mkdirp(path.dirname(wrapperFileNameTs));\n await fs.promises.writeFile(wrapperFileNameTs, typescriptCode, 'utf8');\n await fs.promises.writeFile(wrapperFileNameJs, javascriptCode, 'utf8');\n\n return toRelativeIfExists(baseFilename);\n };\n\nconst generateContentForSchemaFile = async (filePath: string, generatorOptions: GeneratorOptions) => {\n bustCacheForFile(filePath);\n const schemaData = await loadSchema(filePath);\n if (!schemaData) {\n return;\n }\n const targetDirectory = getGeneratorTargetDirectory(filePath);\n try {\n await generateCode(schemaData, generatorOptions, writeContentsToFile(targetDirectory), true);\n } catch (e) {\n console.error(`Something went wrong trying to generate the hooks for your extension point specified at \"${filePath}\".\nIf this persists, feel free to raise an issue with us at: https://bitbucket.org/atlassian/atlassian-clientside-extensions/issues\n\nProvided Schema:\n${schemaData}\nOriginal Error:\n${e}`);\n }\n};\n\nconst cleanupTargetDir = async (targetDir: string) => {\n await rimraf(targetDir);\n};\n\ntype Options = yargs.Arguments<{\n glob: string;\n cwd: string;\n watch: boolean;\n providedTypes: string;\n strictMode: boolean;\n validatorOnly: boolean;\n}>;\n\nconst getProvidedTypesPaths = async (options: Options): Promise<string[]> => {\n let paths: string[] = [];\n const { providedTypes: pattern, cwd } = options;\n\n if (pattern) {\n paths = await glob(pattern, { cwd, ignore: '**/node_modules/**', dotRelative: true });\n\n if (!paths.length) {\n console.warn(`Schema code generator: Provided pattern \"${pattern}\" could not find any files with GraphQL provided types`);\n }\n }\n\n return paths;\n};\n\nconst generate = async (options: Options, providedTypesPaths: string[]) => {\n const { glob: pattern, cwd, strictMode, validatorOnly } = options;\n\n // TODO: Extract all this\n const resultFiles = await glob(pattern, { cwd, ignore: '**/node_modules/**', dotRelative: true });\n const absoluteFilePaths = resultFiles.map((filePath) => path.resolve(path.join(cwd, filePath)));\n\n // eslint-disable-next-line no-restricted-syntax\n for (const absolutePath of absoluteFilePaths) {\n // we have to run this first to remove all preexisting directories before generating any files\n // eslint-disable-next-line no-await-in-loop\n await cleanupTargetDir(getGeneratorTargetDirectory(absolutePath));\n }\n\n const generatorOptions: GeneratorOptions = {\n providedTypesPaths,\n strictMode,\n validatorOnly,\n };\n\n // eslint-disable-next-line no-restricted-syntax\n for (const absolutePath of absoluteFilePaths) {\n bustCacheForFile(absolutePath);\n // eslint-disable-next-line no-await-in-loop\n await generateContentForSchemaFile(absolutePath, generatorOptions);\n }\n};\n\nconst run = async (options: Options) => {\n // TODO: Refactor this part to be more smart about watching changes in provided types\n let providedTypesPaths = await getProvidedTypesPaths(options);\n\n await generate(options, providedTypesPaths);\n\n if (options.watch) {\n console.log('Schema code generator watching for changes....');\n chokidar\n .watch([options.glob, options.providedTypes], {\n cwd: options.cwd,\n ignored: (changedFilePath: string) => {\n return changedFilePath.includes('node_modules');\n },\n })\n .on('all', async (eventName: string, filePath: string) => {\n // eslint-disable-next-line no-console\n console.log(`Schema code generator detected changes. Rebuilding \"${filePath}\"...`);\n const absolutePath = path.resolve(path.join(options.cwd, filePath));\n if (eventName !== 'unlink') {\n bustCacheForFile(absolutePath);\n\n // TODO: Refactor this part to be more smart about watching changes in provided types\n providedTypesPaths = await getProvidedTypesPaths(options);\n\n const generatorOptions: GeneratorOptions = {\n providedTypesPaths,\n strictMode: options.strictMode,\n validatorOnly: options.validatorOnly,\n };\n\n await generateContentForSchemaFile(absolutePath, generatorOptions);\n }\n });\n }\n};\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\nyargs\n .command(\n '$0 [options]',\n 'Generate hooks and other related code based on provided schema.',\n (builder) => {\n builder\n .option('glob', {\n describe: `Glob pattern to find schemas.`,\n type: 'string',\n demandOption: true,\n })\n .option('strict-mode', {\n describe: 'Toggles validation strict mode',\n type: 'boolean',\n default: true,\n })\n .option('provided-types', {\n describe: `Glob pattern to find provided types for schemas.`,\n type: 'string',\n default: '',\n })\n /** @since 2.1.0 */\n .option('validator-only', {\n describe: `Only generate validators for the given schema files.`,\n type: 'boolean',\n default: false,\n })\n .option('watch', {\n describe: `Continuously watch for and generate on changes.`,\n type: 'boolean',\n default: false,\n })\n .option('cwd', {\n describe: `The cwd in which the glob is searching for schemas. Defaults to process.cwd()`,\n type: 'string',\n default: process.cwd(),\n });\n },\n run,\n )\n .help().argv; // for --help and -h to work\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-graphql-definitions.js","sourceRoot":"","sources":["../../../lib/bin/generate-graphql-definitions.ts"],"names":[],"mappings":";;;;AACA,0DAA0B;AAC1B,oDAAoB;AACpB,wDAAwB;AACxB,uFAAuD;AAKvD,MAAM,GAAG,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;IACnC,MAAM,WAAW,GAAG,MAAM,IAAA,4BAAkB,GAAE,CAAC;IAE/C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"generate-graphql-definitions.js","sourceRoot":"","sources":["../../../lib/bin/generate-graphql-definitions.ts"],"names":[],"mappings":";;;;AACA,0DAA0B;AAC1B,oDAAoB;AACpB,wDAAwB;AACxB,uFAAuD;AAKvD,MAAM,GAAG,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;IACnC,MAAM,WAAW,GAAG,MAAM,IAAA,4BAAkB,GAAE,CAAC;IAE/C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,MAAM,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACvG,IAAI,CAAC;QACD,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC;EAClB,QAAQ,EAAE,CAAC,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,kCAAkC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC,CAAC;AAEF,oEAAoE;AACpE,eAAK;KACA,OAAO,CACJ,WAAW,EACX,0GAA0G,EAC1G,CAAC,OAAO,EAAE,EAAE;IACR,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE;QACvB,QAAQ,EAAE,mCAAmC;QAC7C,IAAI,EAAE,QAAQ;KACjB,CAAC,CAAC;AACP,CAAC,EACD,GAAG,CACN;KACA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,4BAA4B","sourcesContent":["#!/usr/bin/env node\nimport yargs from 'yargs';\nimport fs from 'fs';\nimport path from 'path';\nimport graphqlDefinitions from '../graphql-definition';\n\ntype Options = {\n path?: string;\n};\nconst run = async (options: Options) => {\n const definitions = await graphqlDefinitions();\n\n if (!options.path) {\n console.log(definitions);\n process.exit(0);\n }\n\n const filePath = path.isAbsolute(options.path) ? options.path : path.join(process.cwd(), options.path);\n try {\n await fs.promises.writeFile(filePath, definitions, 'utf8');\n console.log(`Successfully wrote definitions to\n${filePath}`);\n process.exit(0);\n } catch (e) {\n console.error(`Failed to write definitions to ${filePath}.`, e);\n process.exit(1);\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\nyargs\n .command(\n '$0 [path]',\n 'Generate a definition file of available Scalars, Enums and Union types baked into clientside extensions.',\n (builder) => {\n builder.positional('path', {\n describe: `Filepath to store definitions in.`,\n type: 'string',\n });\n },\n run,\n )\n .help().argv; // for --help and -h to work\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-module-definitions-file.js","sourceRoot":"","sources":["../../../lib/bin/generate-module-definitions-file.ts"],"names":[],"mappings":";;;;AACA,+BAAwC;AACxC,0DAA0B;AAC1B,oDAAoB;AACpB,kGAAgE;AAOhE,MAAM,GAAG,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;IACnC,MAAM,WAAW,GAAG,IAAA,0BAAc,EAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"generate-module-definitions-file.js","sourceRoot":"","sources":["../../../lib/bin/generate-module-definitions-file.ts"],"names":[],"mappings":";;;;AACA,+BAAwC;AACxC,0DAA0B;AAC1B,oDAAoB;AACpB,kGAAgE;AAOhE,MAAM,GAAG,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;IACnC,MAAM,WAAW,GAAG,IAAA,0BAAc,EAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,yBAAyB;IACzB,MAAM,UAAU,GAAG,OAAO,CAAC,IAAK,CAAC;IAEjC,MAAM,QAAQ,GAAG,IAAA,iBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;IACvF,IAAI,CAAC;QACD,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC;EAClB,QAAQ,EAAE,CAAC,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,kCAAkC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC,CAAC;AAEF,oEAAoE;AACpE,eAAK;KACA,OAAO,CACJ,qBAAqB,EACrB,0GAA0G,EAC1G,CAAC,OAAO,EAAE,EAAE;IACR,OAAO;SACF,UAAU,CAAC,MAAM,EAAE;QAChB,QAAQ,EAAE,mCAAmC;QAC7C,IAAI,EAAE,QAAQ;KACjB,CAAC;SAED,MAAM,CAAC,aAAa,EAAE;QACnB,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,uFAAuF;QACjG,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,eAAe;KAC3B,CAAC,CAAC;AACX,CAAC,EACD,GAAG,CACN;KACA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,4BAA4B","sourcesContent":["#!/usr/bin/env node\nimport { isAbsolute, join } from 'path';\nimport yargs from 'yargs';\nimport fs from 'fs';\nimport getDefinitions from '../code-generator/type-definitions';\n\ntype Options = {\n path?: string;\n moduleGlob: string;\n};\n\nconst run = async (options: Options) => {\n const definitions = getDefinitions(options.moduleGlob);\n\n if (!options.path) {\n console.log(definitions);\n process.exit(0);\n }\n\n // we now know it exists!\n const optionPath = options.path!;\n\n const filePath = isAbsolute(optionPath) ? optionPath : join(process.cwd(), optionPath);\n try {\n await fs.promises.writeFile(filePath, definitions, 'utf8');\n console.log(`Successfully wrote definitions to\n${filePath}`);\n process.exit(0);\n } catch (e) {\n console.error(`Failed to write definitions to ${filePath}.`, e);\n process.exit(1);\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\nyargs\n .command(\n '$0 [path] [options]',\n 'Generate a definition file of available Scalars, Enums and Union types baked into clientside extensions.',\n (builder) => {\n builder\n .positional('path', {\n describe: `Filepath to store definitions in.`,\n type: 'string',\n })\n\n .option('module-glob', {\n alias: 'mg',\n describe: 'The name of the module the definitions are generated for. Defaults to \"*.cse.graphql\"',\n type: 'string',\n default: '*.cse.graphql',\n });\n },\n run,\n )\n .help().argv; // for --help and -h to work\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-generator.js","sourceRoot":"","sources":["../../../lib/code-generator/code-generator.ts"],"names":[],"mappings":";;;AAAA,uDAAiC;AACjC,kFAAsE;AACtE,0DAAuF;AACvF,sEAA+D;AAC/D,oFAA8E;AAC9E,qFAAqD;AACrD,mFAAiD;AACjD,4CAA6C;AAC7C,oCAAqC;AAErC,4DAAoD;AAEpD,MAAM,kBAAkB,GAAG,CAAC,MAAc,EAAE,EAAE;IAC1C,MAAM,MAAM,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACnG,OAAO,MAAM,CAAC,UAAU,CAAC;AAC7B,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,YAAoB,EAAE,YAAoB,EAAE,EAAE;IACpE,MAAM,MAAM,GAAG,IAAA,+BAAe,EAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IAC3D,MAAM,cAAc,GAAG,IAAI,wBAAc,EAAE,CAAC;IAC5C,IAAA,4CAAgB,EAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IACzC,OAAO,cAAc,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAAC,YAAoB,EAAsB,EAAE;;IACvE,MAAM,QAAQ,GAAG,gBAAgB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC1D,OAAO,MAAA,MAAA,QAAQ,CAAC,aAAa,CA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CAAC,aAAa,CAAC,CAAmC,CAAC;AAChH,CAAC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import * as ts from 'typescript';\nimport { populateDocument } from '../utils/schema-document-populator';\nimport { getSchemaObject, SchemaDefinitionMissingError } from '../utils/create-schema';\nimport { createValidator } from '../utils/validator-generator';\nimport { serializeSchemaDocument } from '../utils/schema-document-serializer';\nimport SchemaDocument from '../utils/SchemaDocument';\nimport injectTypes from '../utils/injcect-types';\nimport { loadSchema } from '../utils/schema';\nimport { isNotNull } from '../utils';\nimport type { ValidationOptions } from '../utils/validator-types';\nimport generateReactExtensionWrapper from './react';\n\nconst generateJavascript = (source: string) => {\n const result = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } });\n return result.outputText;\n};\n\nconst schemaToDocument = (schemaString: string, baseTypeName: string) => {\n const schema = getSchemaObject(schemaString, baseTypeName);\n const schemaDocument = new SchemaDocument();\n populateDocument(schemaDocument, schema);\n return schemaDocument;\n};\n\nconst getExtensionPointName = (schemaString: string): string | undefined => {\n const document = schemaToDocument(schemaString, 'Schema');\n return document.getObjectType('Schema')?.meta?.extensionPoint as string;\n};\n\nconst createValidatorForSchema = (schemaString: string, baseTypeName: string, options: ValidationOptions) => {\n return createValidator(schemaToDocument(schemaString, baseTypeName), baseTypeName, options);\n};\n\ntype ValidatorGeneratorOptions = {\n strictMode: boolean;\n};\n\nconst generateValidators = async (extensionPoint: string, schema: string, fileWriter: FileWriter, options: ValidatorGeneratorOptions) => {\n const attributeValidationOptions: ValidationOptions = {\n ...options,\n checkExcessiveKeys: false, // TODO: This should be enabled in the future\n };\n const attributeValidatorTypescript = createValidatorForSchema(schema, 'Schema', attributeValidationOptions);\n\n const validatorFile = await fileWriter(\n `${extensionPoint}_validator`,\n attributeValidatorTypescript,\n generateJavascript(attributeValidatorTypescript),\n );\n\n try {\n const contextValidationOptions: ValidationOptions = {\n ...options,\n checkExcessiveKeys: true,\n };\n const contextValidatorTypescript = createValidatorForSchema(schema, 'ContextSchema', contextValidationOptions);\n const contextValidatorFile = await fileWriter(\n `${extensionPoint}_validator_context`,\n contextValidatorTypescript,\n generateJavascript(contextValidatorTypescript),\n );\n return [validatorFile, contextValidatorFile];\n } catch (e) {\n // we allow for a missing context schema, as not all extension points have a context\n if (e instanceof SchemaDefinitionMissingError) {\n return [validatorFile];\n }\n\n // else rethrow\n throw e;\n }\n};\n\nconst getSchemaDocumentContent = (schemaDocument: string, contextSchemaDocument: string) => `\nimport { SerializedDocument } from '@atlassian/clientside-extensions-schema';\n\nconst schemaDocument: SerializedDocument = ${schemaDocument};\n\nconst contextSchemaDocument: SerializedDocument = ${contextSchemaDocument}\n\nexport {schemaDocument, contextSchemaDocument }\n`;\n\nconst generateSchemaDocuments = async (extensionPoint: string, schema: string, fileWriter: FileWriter) => {\n const schemaDocument = serializeSchemaDocument(extensionPoint, schema, 'Schema');\n const contextSchemaDocument = serializeSchemaDocument(extensionPoint, schema, 'ContextSchema');\n\n const schemaDocumentsTypescript = getSchemaDocumentContent(\n JSON.stringify(schemaDocument, null, 4),\n JSON.stringify(contextSchemaDocument, null, 4),\n );\n const schemaDocumentsFile = await fileWriter(\n `${extensionPoint}_schema_documents`,\n schemaDocumentsTypescript,\n generateJavascript(schemaDocumentsTypescript),\n );\n\n return schemaDocumentsFile as string;\n};\n\nexport type FileWriter = (baseFilename: string, typescriptCode: string, javascriptCode: string) => Promise<string | null>;\n\nexport interface GeneratorOptions {\n providedTypesPaths: string[];\n strictMode: boolean;\n validatorOnly: boolean;\n}\n\nconst defaultOptions: GeneratorOptions = {\n providedTypesPaths: [],\n strictMode: true,\n validatorOnly: false,\n};\n\nconst getGeneratedCode = async (\n attributeValidatorLocation: string | null,\n contextValidatorLocation: string | null,\n extensionPoint: string,\n schema: string,\n fileWriter: FileWriter,\n) => {\n const schemaDocumentsFile = await generateSchemaDocuments(extensionPoint, schema, fileWriter);\n return generateReactExtensionWrapper(attributeValidatorLocation, contextValidatorLocation, extensionPoint, schemaDocumentsFile);\n};\n\ntype GeneratedReturnType = [extensionPoint: string, generatedTsCdode: string, generatedJsCode: string];\n\ntype ReturnWithoutWrite<WriteBaseT extends boolean> = WriteBaseT extends true ? void : GeneratedReturnType;\n\nasync function generateCode<WriteBaseT extends boolean>(\n schema: string,\n options: Partial<GeneratorOptions>,\n fileWriter: FileWriter,\n writeBase: WriteBaseT,\n): Promise<ReturnWithoutWrite<WriteBaseT>> {\n const { providedTypesPaths, strictMode, validatorOnly }: GeneratorOptions = { ...defaultOptions, ...options };\n if (!writeBase && validatorOnly) {\n throw new Error('The \"validatorOnly\" option is not available when \"writeBase\" is not true!');\n }\n\n // Extend schema with custom provided types\n const maybeProvidedTypesSchema: (string | null)[] = await Promise.all(providedTypesPaths.map((filePath) => loadSchema(filePath)));\n const providedTypesSchema: string[] = maybeProvidedTypesSchema.filter(isNotNull);\n const baseSchema = injectTypes(schema, providedTypesSchema);\n\n // Read the extension point\n const extensionPoint = getExtensionPointName(baseSchema);\n\n if (!extensionPoint) {\n throw new Error(`Could not extract the extension point from your provided schema.\nPlease ensure you specify the extensionPoint as part of the meta data within the description of your Schema.\n\nExample:\n\n\"\"\"\n---\nextensionPoint: specify-your-extension-point-name-here\n---\nThis is the description of your Schema\n\"\"\"\ntype Schema {\n // content of your schema…\n}\n`);\n }\n\n const validatorGeneratorOptions: ValidatorGeneratorOptions = {\n strictMode,\n };\n\n const [validatorFile, contextValidatorFile] = await generateValidators(\n extensionPoint,\n baseSchema,\n fileWriter,\n validatorGeneratorOptions,\n );\n\n if (validatorOnly) {\n return undefined as ReturnWithoutWrite<WriteBaseT>;\n }\n\n const generatedCode = await getGeneratedCode(validatorFile, contextValidatorFile, extensionPoint, baseSchema, fileWriter);\n\n if (writeBase) {\n await fileWriter(extensionPoint, generatedCode, generateJavascript(generatedCode));\n return undefined as ReturnWithoutWrite<WriteBaseT>;\n }\n\n return [extensionPoint, generatedCode, generateJavascript(generatedCode)] as ReturnWithoutWrite<WriteBaseT>;\n}\n\nexport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IAC3C,MAAM,wBAAwB,GAAsB,MAAM,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClI,MAAM,mBAAmB,GAAa,wBAAwB,CAAC,MAAM,CAAC,iBAAS,CAAC,CAAC;IACjF,MAAM,UAAU,GAAG,IAAA,uBAAW,EAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAE5D,2BAA2B;IAC3B,MAAM,cAAc,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAEzD,IAAI,CAAC,cAAc,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC;;;;;;;;;;;;;;CAcvB,CAAC,CAAC;IACC,CAAC;IAED,MAAM,yBAAyB,GAA8B;QACzD,UAAU;KACb,CAAC;IAEF,MAAM,CAAC,aAAa,EAAE,oBAAoB,CAAC,GAAG,MAAM,kBAAkB,CAClE,cAAc,EACd,UAAU,EACV,UAAU,EACV,yBAAyB,CAC5B,CAAC;IAEF,IAAI,aAAa,EAAE,CAAC;QAChB,OAAO,SAA2C,CAAC;IACvD,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,aAAa,EAAE,oBAAoB,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAE1H,IAAI,SAAS,EAAE,CAAC;QACZ,MAAM,UAAU,CAAC,cAAc,EAAE,aAAa,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAC;QACnF,OAAO,SAA2C,CAAC;IACvD,CAAC;IAED,OAAO,CAAC,cAAc,EAAE,aAAa,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAmC,CAAC;AAChH,CAAC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import * as ts from 'typescript';\nimport { populateDocument } from '../utils/schema-document-populator';\nimport { getSchemaObject, SchemaDefinitionMissingError } from '../utils/create-schema';\nimport { createValidator } from '../utils/validator-generator';\nimport { serializeSchemaDocument } from '../utils/schema-document-serializer';\nimport SchemaDocument from '../utils/SchemaDocument';\nimport injectTypes from '../utils/injcect-types';\nimport { loadSchema } from '../utils/schema';\nimport { isNotNull } from '../utils';\nimport type { ValidationOptions } from '../utils/validator-types';\nimport generateReactExtensionWrapper from './react';\n\nconst generateJavascript = (source: string) => {\n const result = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } });\n return result.outputText;\n};\n\nconst schemaToDocument = (schemaString: string, baseTypeName: string) => {\n const schema = getSchemaObject(schemaString, baseTypeName);\n const schemaDocument = new SchemaDocument();\n populateDocument(schemaDocument, schema);\n return schemaDocument;\n};\n\nconst getExtensionPointName = (schemaString: string): string | undefined => {\n const document = schemaToDocument(schemaString, 'Schema');\n return document.getObjectType('Schema')?.meta?.extensionPoint as string;\n};\n\nconst createValidatorForSchema = (schemaString: string, baseTypeName: string, options: ValidationOptions) => {\n return createValidator(schemaToDocument(schemaString, baseTypeName), baseTypeName, options);\n};\n\ntype ValidatorGeneratorOptions = {\n strictMode: boolean;\n};\n\nconst generateValidators = async (extensionPoint: string, schema: string, fileWriter: FileWriter, options: ValidatorGeneratorOptions) => {\n const attributeValidationOptions: ValidationOptions = {\n ...options,\n checkExcessiveKeys: false, // TODO: This should be enabled in the future\n };\n const attributeValidatorTypescript = createValidatorForSchema(schema, 'Schema', attributeValidationOptions);\n\n const validatorFile = await fileWriter(\n `${extensionPoint}_validator`,\n attributeValidatorTypescript,\n generateJavascript(attributeValidatorTypescript),\n );\n\n try {\n const contextValidationOptions: ValidationOptions = {\n ...options,\n checkExcessiveKeys: true,\n };\n const contextValidatorTypescript = createValidatorForSchema(schema, 'ContextSchema', contextValidationOptions);\n const contextValidatorFile = await fileWriter(\n `${extensionPoint}_validator_context`,\n contextValidatorTypescript,\n generateJavascript(contextValidatorTypescript),\n );\n return [validatorFile, contextValidatorFile];\n } catch (e) {\n // we allow for a missing context schema, as not all extension points have a context\n if (e instanceof SchemaDefinitionMissingError) {\n return [validatorFile];\n }\n\n // else rethrow\n throw e;\n }\n};\n\nconst getSchemaDocumentContent = (schemaDocument: string, contextSchemaDocument: string) => `\nimport { SerializedDocument } from '@atlassian/clientside-extensions-schema';\n\nconst schemaDocument: SerializedDocument = ${schemaDocument};\n\nconst contextSchemaDocument: SerializedDocument = ${contextSchemaDocument}\n\nexport {schemaDocument, contextSchemaDocument }\n`;\n\nconst generateSchemaDocuments = async (extensionPoint: string, schema: string, fileWriter: FileWriter) => {\n const schemaDocument = serializeSchemaDocument(extensionPoint, schema, 'Schema');\n const contextSchemaDocument = serializeSchemaDocument(extensionPoint, schema, 'ContextSchema');\n\n const schemaDocumentsTypescript = getSchemaDocumentContent(\n JSON.stringify(schemaDocument, null, 4),\n JSON.stringify(contextSchemaDocument, null, 4),\n );\n const schemaDocumentsFile = await fileWriter(\n `${extensionPoint}_schema_documents`,\n schemaDocumentsTypescript,\n generateJavascript(schemaDocumentsTypescript),\n );\n\n return schemaDocumentsFile as string;\n};\n\nexport type FileWriter = (baseFilename: string, typescriptCode: string, javascriptCode: string) => Promise<string | null>;\n\nexport interface GeneratorOptions {\n providedTypesPaths: string[];\n strictMode: boolean;\n validatorOnly: boolean;\n}\n\nconst defaultOptions: GeneratorOptions = {\n providedTypesPaths: [],\n strictMode: true,\n validatorOnly: false,\n};\n\nconst getGeneratedCode = async (\n attributeValidatorLocation: string | null,\n contextValidatorLocation: string | null,\n extensionPoint: string,\n schema: string,\n fileWriter: FileWriter,\n) => {\n const schemaDocumentsFile = await generateSchemaDocuments(extensionPoint, schema, fileWriter);\n return generateReactExtensionWrapper(attributeValidatorLocation, contextValidatorLocation, extensionPoint, schemaDocumentsFile);\n};\n\ntype GeneratedReturnType = [extensionPoint: string, generatedTsCdode: string, generatedJsCode: string];\n\ntype ReturnWithoutWrite<WriteBaseT extends boolean> = WriteBaseT extends true ? void : GeneratedReturnType;\n\nasync function generateCode<WriteBaseT extends boolean>(\n schema: string,\n options: Partial<GeneratorOptions>,\n fileWriter: FileWriter,\n writeBase: WriteBaseT,\n): Promise<ReturnWithoutWrite<WriteBaseT>> {\n const { providedTypesPaths, strictMode, validatorOnly }: GeneratorOptions = { ...defaultOptions, ...options };\n if (!writeBase && validatorOnly) {\n throw new Error('The \"validatorOnly\" option is not available when \"writeBase\" is not true!');\n }\n\n // Extend schema with custom provided types\n const maybeProvidedTypesSchema: (string | null)[] = await Promise.all(providedTypesPaths.map((filePath) => loadSchema(filePath)));\n const providedTypesSchema: string[] = maybeProvidedTypesSchema.filter(isNotNull);\n const baseSchema = injectTypes(schema, providedTypesSchema);\n\n // Read the extension point\n const extensionPoint = getExtensionPointName(baseSchema);\n\n if (!extensionPoint) {\n throw new Error(`Could not extract the extension point from your provided schema.\nPlease ensure you specify the extensionPoint as part of the meta data within the description of your Schema.\n\nExample:\n\n\"\"\"\n---\nextensionPoint: specify-your-extension-point-name-here\n---\nThis is the description of your Schema\n\"\"\"\ntype Schema {\n // content of your schema…\n}\n`);\n }\n\n const validatorGeneratorOptions: ValidatorGeneratorOptions = {\n strictMode,\n };\n\n const [validatorFile, contextValidatorFile] = await generateValidators(\n extensionPoint,\n baseSchema,\n fileWriter,\n validatorGeneratorOptions,\n );\n\n if (validatorOnly) {\n return undefined as ReturnWithoutWrite<WriteBaseT>;\n }\n\n const generatedCode = await getGeneratedCode(validatorFile, contextValidatorFile, extensionPoint, baseSchema, fileWriter);\n\n if (writeBase) {\n await fileWriter(extensionPoint, generatedCode, generateJavascript(generatedCode));\n return undefined as ReturnWithoutWrite<WriteBaseT>;\n }\n\n return [extensionPoint, generatedCode, generateJavascript(generatedCode)] as ReturnWithoutWrite<WriteBaseT>;\n}\n\nexport default generateCode;\n"]}
|
|
@@ -82,8 +82,6 @@ export const ExtensionPoint: React.FC<ExcludedExtensionPointProps> = ({ children
|
|
|
82
82
|
|
|
83
83
|
const schemaDocuments = { schema: schemaDocument, contextSchema: contextSchemaDocument };
|
|
84
84
|
|
|
85
|
-
const schemaDocuments = { schema: schemaDocument, contextSchema: contextSchemaDocument };
|
|
86
|
-
|
|
87
85
|
export const ExtensionPointInfo: React.FC<{}> = () => {
|
|
88
86
|
|
|
89
87
|
// we don't do JSX here because we currently don't have tooling in place to transpile the jsx into typescript/javascript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../../lib/code-generator/react.ts"],"names":[],"mappings":";;AAAA,MAAM,6BAA6B,GAAG,CAClC,0BAAyC,EACzC,wBAAuC,EACvC,cAA6B,EAC7B,mBAAkC,EACpC,EAAE;;IACA,MAAM,2BAA2B,GAAa,EAAE,CAAC;IACjD,MAAM,gBAAgB,GAAG,0BAA0B;QAC/C,CAAC,CAAC,mDAAmD,0BAA0B,IAAI;QACnF,CAAC,CAAC,EAAE,CAAC;IACT,IAAI,0BAA0B,EAAE;
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../../lib/code-generator/react.ts"],"names":[],"mappings":";;AAAA,MAAM,6BAA6B,GAAG,CAClC,0BAAyC,EACzC,wBAAuC,EACvC,cAA6B,EAC7B,mBAAkC,EACpC,EAAE;;IACA,MAAM,2BAA2B,GAAa,EAAE,CAAC;IACjD,MAAM,gBAAgB,GAAG,0BAA0B;QAC/C,CAAC,CAAC,mDAAmD,0BAA0B,IAAI;QACnF,CAAC,CAAC,EAAE,CAAC;IACT,IAAI,0BAA0B,EAAE,CAAC;QAC7B,2BAA2B,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,uBAAuB,GAAG,wBAAwB;QACpD,CAAC,CAAC,iDAAiD,wBAAwB,IAAI;QAC/E,CAAC,CAAC,EAAE,CAAC;IACT,IAAI,wBAAwB,EAAE,CAAC;QAC3B,2BAA2B,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACzD,CAAC;IAED,OAAO;;;;;;;;;;;;;EAaT,gBAAgB;EAChB,uBAAuB;yDACgC,mBAAmB;;iCAE3C,MAAA,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,mCAAI,MAAM;;6BAE5C,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwDlE,CAAC,QAAQ,EAAE,CAAC;AACb,CAAC,CAAC;AAEF,kBAAe,6BAA6B,CAAC","sourcesContent":["const generateReactExtensionWrapper = (\n attributeValidatorLocation: string | null,\n contextValidatorLocation: string | null,\n extensionPoint: string | null,\n schemaDocumentsFile: string | null,\n) => {\n const extendedSchemaContextOption: string[] = [];\n const validationImport = attributeValidatorLocation\n ? `import { validate as attributeValidator } from '${attributeValidatorLocation}';`\n : '';\n if (attributeValidatorLocation) {\n extendedSchemaContextOption.push('attributeValidator');\n }\n\n const contextValidationImport = contextValidatorLocation\n ? `import { validate as contextValidator } from '${contextValidatorLocation}';`\n : '';\n if (contextValidatorLocation) {\n extendedSchemaContextOption.push('contextValidator');\n }\n\n return `\nimport {\n useExtensionsLoadingState as useExtensionsLoadingStateOrig,\n useExtensions as useExtensionsOrig,\n useExtensionsUnsupported as useExtensionsUnsupportedOrig,\n useExtensionsAll as useExtensionsAllOrig,\n ExtensionPoint as ExtensionPointOrig,\n ExtensionPointInfo as ExtensionPointInfoOrig,\n Options\n} from '@atlassian/clientside-extensions-components';\nimport type { ExtensionPointProps } from '@atlassian/clientside-extensions-components';\nimport * as React from 'react';\nimport type { ExtensionAttributes, Context } from '@atlassian/clientside-extensions-registry';\n${validationImport}\n${contextValidationImport}\nimport { schemaDocument, contextSchemaDocument } from '${schemaDocumentsFile}';\n\nconst extensionPoint: string = ${JSON.stringify(extensionPoint) ?? 'null'};\n\nconst options: Options = { ${extendedSchemaContextOption.join(', ')} };\n\nexport const useExtensionsLoadingState = <\n ContextT extends Context<{}> | null = null,\n AttributeU extends ExtensionAttributes = ExtensionAttributes\n>(\n context: ContextT\n) => {\n return useExtensionsLoadingStateOrig<ContextT, AttributeU>(extensionPoint, context, options);\n};\n\nexport const useExtensions = <\n ContextT extends Context<{}> | null = null,\n AttributeU extends ExtensionAttributes = ExtensionAttributes\n>(\n context: ContextT\n) => {\n return useExtensionsOrig<ContextT, AttributeU>(extensionPoint, context, options);\n};\n\nexport const useExtensionsUnsupported = <\n ContextT extends Context<{}> | null = null,\n AttributeU extends ExtensionAttributes = ExtensionAttributes\n>(\n context: ContextT\n) => {\n return useExtensionsUnsupportedOrig<ContextT, AttributeU>(extensionPoint, context, options);\n};\n\nexport const useExtensionsAll = <\n ContextT extends Context<{}> | null = null,\n AttributeU extends ExtensionAttributes = ExtensionAttributes\n>(\n context: ContextT\n) => {\n return useExtensionsAllOrig<ContextT, AttributeU>(extensionPoint, context, options);\n};\n\n\ntype ExcludedExtensionPointProps = Omit<ExtensionPointProps, 'options' | 'name'>;\n\nexport const ExtensionPoint: React.FC<ExcludedExtensionPointProps> = ({ children, ...newProps }) => {\n // we don't do JSX here because we currently don't have tooling in place to transpile the jsx into typescript/javascript\n return React.createElement(ExtensionPointOrig, { ...newProps, options, name: extensionPoint }, children);\n};\n\nconst schemaDocuments = { schema: schemaDocument, contextSchema: contextSchemaDocument };\n\nexport const ExtensionPointInfo: React.FC<{}> = () => {\n \n // we don't do JSX here because we currently don't have tooling in place to transpile the jsx into typescript/javascript\n return React.createElement(ExtensionPointInfoOrig, {\n name: extensionPoint,\n schemaDocuments: schemaDocuments,\n });\n};\n`.trimLeft();\n};\n\nexport default generateReactExtensionWrapper;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = getDefinitions;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const typescript_1 = tslib_1.__importDefault(require("typescript"));
|
|
5
6
|
const path_1 = require("path");
|
|
@@ -65,5 +66,4 @@ const getReactDefinitions = () => {
|
|
|
65
66
|
function getDefinitions(moduleGlob) {
|
|
66
67
|
return wrapInModuleDefinition(getReactDefinitions(), moduleGlob);
|
|
67
68
|
}
|
|
68
|
-
exports.default = getDefinitions;
|
|
69
69
|
//# sourceMappingURL=type-definitions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-definitions.js","sourceRoot":"","sources":["../../../lib/code-generator/type-definitions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-definitions.js","sourceRoot":"","sources":["../../../lib/code-generator/type-definitions.ts"],"names":[],"mappings":";;AA8EA,iCAEC;;AA/ED,oEAA4B;AAC5B,+BAAyC;AACzC,4DAAoD;AAEpD,MAAM,2BAA2B,GAAG,CAAC,WAAmB,EAAU,EAAE;IAChE,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;IACnD,MAAM,oBAAoB,GAAG,cAAc,CAAC;IAE5C,MAAM,iBAAiB,GAAG,eAAe,CAAC;IAC1C,MAAM,mBAAmB,GAAG,MAAM,CAAC;IAEnC,MAAM,OAAO,GAAuB;QAChC,CAAC,kBAAkB,EAAE,oBAAoB,CAAC;QAC1C,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;KAC3C,CAAC;IAEF,KAAK,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,OAAO,EAAE,CAAC;QACvC,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,WAAmB,EAAE,UAAkB,EAAE,EAAE;IACvE,OAAO,mBAAmB,UAAU;EACtC,2BAA2B,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;;CAEvE,CAAC;AACF,CAAC,CAAC;AAEF,sEAAsE;AACtE,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IAC9C,M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,mBAAmB,GAAG,GAAG,EAAE;IAC7B,OAAO,wBAAwB,CAAC,IAAA,eAA6B,EAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3F,CAAC,CAAC;AAEF,sEAAsE;AACtE,SAAwB,cAAc,CAAC,UAAkB;IACrD,OAAO,sBAAsB,CAAC,mBAAmB,EAAE,EAAE,UAAU,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type { CompilerOptions } from 'typescript';\nimport ts from 'typescript';\nimport { basename, extname } from 'path';\nimport generateReactExtensionWrapper from './react';\n\nconst removeNestedDeclareKeywords = (definitions: string): string => {\n const declareConstRegExp = /export declare const/g;\n const declareConstReplacer = 'export const';\n\n const declareTypeRegExp = /declare type/g;\n const declareTypeReplacer = 'type';\n\n const regExps: [RegExp, string][] = [\n [declareConstRegExp, declareConstReplacer],\n [declareTypeRegExp, declareTypeReplacer],\n ];\n\n for (const [regExp, replacer] of regExps) {\n definitions = definitions.replace(regExp, replacer);\n }\n\n return definitions;\n};\n\nconst wrapInModuleDefinition = (definitions: string, moduleGlob: string) => {\n return `declare module '${moduleGlob}' {\n${removeNestedDeclareKeywords(definitions).replace(/^/gm, ' '.repeat(4))}\n}\n`;\n};\n\n// Generate a fake wrapper and make typescript generate typings for it\nconst generateModuleDescriptor = (code: string) => {\n const baseFilename = `FAKE_NAME${Math.floor(Math.random() * 1000)}`;\n\n let definition = '';\n\n const compilerOptions: CompilerOptions = {\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n strict: true,\n\n // We don't want to check the declarations files at this point,\n // https://github.com/microsoft/TypeScript/wiki/Performance#skipping-dts-checking\n skipLibCheck: true,\n\n // We don't want to put all the types definitions by default\n // https://github.com/microsoft/TypeScript/wiki/Performance#controlling-types-inclusion\n types: [],\n };\n\n const host = ts.createCompilerHost(compilerOptions);\n const oldRead = host.readFile;\n host.readFile = (fileName: string) => {\n if (baseFilename === basename(fileName, extname(fileName))) {\n return code;\n }\n return oldRead(fileName);\n };\n host.writeFile = (fileName: string, contents: string) => {\n if (basename(fileName).startsWith(baseFilename) && fileName.endsWith('.d.ts')) {\n definition = contents;\n }\n };\n\n // Prepare and emit the d.ts files\n const program = ts.createProgram([baseFilename], compilerOptions, host);\n program.emit();\n\n return definition;\n};\n\nconst getReactDefinitions = () => {\n return generateModuleDescriptor(generateReactExtensionWrapper(null, null, null, null));\n};\n\n// Generate a fake wrapper and make typescript generate typings for it\nexport default function getDefinitions(moduleGlob: string) {\n return wrapInModuleDefinition(getReactDefinitions(), moduleGlob);\n}\n"]}
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
const glob_1 = require("glob");
|
|
27
4
|
const scalarToDefinitionString = (scalar) => {
|
|
@@ -36,16 +13,14 @@ scalar ${scalar.name}
|
|
|
36
13
|
const getScalars = async () => {
|
|
37
14
|
const scalarFiles = await (0, glob_1.glob)('./scalars/**/*.js', { cwd: __dirname, dotRelative: true });
|
|
38
15
|
const scalars = (await Promise.all(scalarFiles.map(async (filePath) => {
|
|
39
|
-
|
|
40
|
-
return (await (_a = filePath, Promise.resolve().then(() => __importStar(require(_a))))).default;
|
|
16
|
+
return (await import(filePath)).default;
|
|
41
17
|
}))).filter(Boolean);
|
|
42
18
|
return scalars.map(scalarToDefinitionString).join('\n\n');
|
|
43
19
|
};
|
|
44
20
|
const getProvidedTypes = async () => {
|
|
45
21
|
const providedTypesFiles = await (0, glob_1.glob)('./providedTypes/*.js', { cwd: __dirname, dotRelative: true });
|
|
46
22
|
const providedTypes = await Promise.all(providedTypesFiles.map(async (filePath) => {
|
|
47
|
-
|
|
48
|
-
return (await (_a = filePath, Promise.resolve().then(() => __importStar(require(_a))))).default;
|
|
23
|
+
return (await import(filePath)).default;
|
|
49
24
|
}));
|
|
50
25
|
return providedTypes.join('\n\n');
|
|
51
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-definition.js","sourceRoot":"","sources":["../../lib/graphql-definition.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"graphql-definition.js","sourceRoot":"","sources":["../../lib/graphql-definition.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAG5B,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAAE,EAAE;IAChD,OAAO;;EAET,MAAM,CAAC,WAAW;WACT,OAAO,MAAM,CAAC,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc;;SAE3G,MAAM,CAAC,IAAI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CAAC,CAAC","sourcesContent":["import { glob } from 'glob';\nimport type { Scalar } from './scalars/types';\n\nconst scalarToDefinitionString = (scalar: Scalar) => {\n return `\n\"\"\"\n${scalar.description}\nExample: ${typeof scalar.defaultExample === 'string' ? JSON.stringify(scalar.defaultExample) : scalar.defaultExample}\n\"\"\"\nscalar ${scalar.name}\n`;\n};\n\nconst getScalars = async () => {\n const scalarFiles = await glob('./scalars/**/*.js', { cwd: __dirname, dotRelative: true });\n const scalars = (\n await Promise.all(\n scalarFiles.map(async (filePath) => {\n return (await import(filePath)).default as Scalar;\n }),\n )\n ).filter(Boolean);\n\n return scalars.map(scalarToDefinitionString).join('\\n\\n');\n};\n\nconst getProvidedTypes = async () => {\n const providedTypesFiles = await glob('./providedTypes/*.js', { cwd: __dirname, dotRelative: true });\n const providedTypes = await Promise.all(\n providedTypesFiles.map(async (filePath) => {\n return (await import(filePath)).default as string;\n }),\n );\n\n return providedTypes.join('\\n\\n');\n};\n\nexport default async () => {\n const scalarDefinitions = await getScalars();\n const providedTypesDefinitions = await getProvidedTypes();\n\n return `\n###########################################################\n# GENERATED: Scalar definitions for clientside extensions #\n###########################################################\n${scalarDefinitions}\n\n############################################################################\n# GENERATED: Other provided types, enums, unions for clientside extensions #\n############################################################################\n${providedTypesDefinitions}\n`;\n};\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = schemaLoader;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const loader_utils_1 = require("loader-utils");
|
|
5
6
|
const glob_1 = require("glob");
|
|
@@ -79,5 +80,4 @@ async function schemaLoader(content) {
|
|
|
79
80
|
callback(error);
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
exports.default = schemaLoader;
|
|
83
83
|
//# sourceMappingURL=schema-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-loader.js","sourceRoot":"","sources":["../../../lib/loader/schema-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema-loader.js","sourceRoot":"","sources":["../../../lib/loader/schema-loader.ts"],"names":[],"mappings":";;AAkDA,+BA4DC;;AA9GD,+CAAuE;AACvE,+BAA4B;AAC5B,+CAAwC;AAIxC,8FAA4D;AAC5D,sFAA0C;AAG1C,MAAM,UAAU,GAAG,CAAC,aAA4B,EAAE,UAAkB,EAAE,OAAe,EAAE,EAAE,CACrF,IAAA,8BAAe,EAAC,aAAa,EAAE,GAAG,UAAU,mBAAmB,EAAE;IAC7D,OAAO,EAAE,aAAa,CAAC,WAAW;IAClC,OAAO;CACV,CAAC,CAAC;AAEP,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE5C,MAAM,iBAAiB,GAAG,KAAK,EAAE,OAAe,EAAE,GAAY,EAAqB,EAAE;IACjF,MAAM,aAAa,GAAG,MAAM,IAAA,WAAI,EAAC,OAAO,EAAE;QACtC,MAAM,EAAE,oBAAoB;QAC5B,QAAQ,EAAE,IAAI;QACd,GAAG;QACH,WAAW,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,wCAAwC,OAAO,wDAAwD,CAAC,CAAC;IAC1H,CAAC;IAED,OAAO,aAAa,CAAC;AACzB,CAAC,CAAC;AAEF,4IAA4I;AAC5I,iIAAiI;AACjI,wGAAwG;AACxG,+CAA+C;AAC/C,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC/C,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC,CAAC;AAEF,uFAAuF;AACvF,MAAM,iBAAiB,GAAG,gDAAgD,CAAC;AAE3E,MAAM,oBAAoB,GAAkB;IACxC,aAAa,EAAE,EAAE;IACjB,UAAU,EAAE,IAAI;CACnB,CAAC;AA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gBAAgB,GAA8B;YAChD,kBAAkB;YAClB,UAAU;SACb,CAAC;QAEF,MAAM,CAAC,EAAE,AAAD,EAAG,mBAAmB,CAAC,GAAG,MAAM,IAAA,wBAAY,EAChD,OAAO,EACP,gBAAgB,EAChB,KAAK,EAAE,cAAsB,EAAE,cAAsB,EAAE,cAAsB,EAAE,EAAE;YAC7E,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;YAC3E,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;YAExC,MAAM,YAAY,GAAG,aAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;YAE/D,OAAO,KAAK,iBAAiB,IAAI,YAAY,YAAY,QAAQ,EAAE,CAAC;QACxE,CAAC,EACD,KAAK,CACR,CAAC;QACF,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,MAAM,KAAK,GAAG,GAAY,CAAC;QAE3B,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;AACL,CAAC","sourcesContent":["import { getOptions, interpolateName, parseQuery } from 'loader-utils';\nimport { glob } from 'glob';\nimport { validate } from 'schema-utils';\n\nimport type { Schema } from 'schema-utils/declarations/validate';\nimport type { GeneratorOptions } from '../code-generator/code-generator';\nimport generateCode from '../code-generator/code-generator';\nimport schema from './loader-schema.json';\nimport type { LoaderOptions, LoaderContext, LoaderCallback, QueryObject } from './types';\n\nconst toFilename = (loaderContext: LoaderContext, identifier: string, content: string) =>\n interpolateName(loaderContext, `${identifier}.[contenthash].js`, {\n context: loaderContext.rootContext,\n content,\n });\n\nconst fileStore = new Map<string, string>();\n\nconst findProvidedTypes = async (pattern: string, cwd?: string): Promise<string[]> => {\n const providedTypes = await glob(pattern, {\n ignore: '**/node_modules/**',\n absolute: true,\n cwd,\n dotRelative: true,\n });\n\n if (!providedTypes.length) {\n console.warn(`CSE schema-loader: Provided pattern \"${pattern}\" could not find any files with GraphQL provided types`);\n }\n\n return providedTypes;\n};\n\n// We need a way to serialize and convert Windows OS style path before outputting it as a string. The webpack loader had issues when the \"\\\"\n// directory separator character was not escaped and as a result the file path end-up glued together e.g. \"C:foobarfile.graphql\".\n// The solution is either to convert this path \"C:\\foo\\bar\\file.graphql\" to \"C:\\\\foo\\\\bar\\\\file.graphql\"\n// or to a unix style \"C:/foo/bar/file.graphql\"\nconst serializePath = (filePath: string): string => {\n return filePath.replace(/\\\\/g, '\\\\\\\\');\n};\n\n// The full name of the webpack GraphQL loader we are referencing in the generated code\nconst graphqlLoaderPath = '@atlassian/clientside-extensions-schema/loader';\n\nconst defaultLoaderOptions: LoaderOptions = {\n providedTypes: '',\n strictMode: true,\n};\n\n// get's a \"this\" context so !MUST! be a \"function\" and !NOT! an arrow-function\nexport default async function schemaLoader(this: LoaderContext, content: string) {\n const callback = this.async() as LoaderCallback;\n\n // Get and validate loader options\n const loaderOptions: Readonly<LoaderOptions> = getOptions(this);\n\n validate(schema as Schema, loaderOptions, { name: 'CSE schema-loader' });\n\n const { providedTypes: providedTypesPattern, strictMode }: LoaderOptions = { ...defaultLoaderOptions, ...loaderOptions };\n\n // Get provided types\n let providedTypesPaths: string[] = [];\n\n if (providedTypesPattern) {\n providedTypesPaths = await findProvidedTypes(providedTypesPattern, loaderOptions.cwd);\n\n // Track custom type files\n providedTypesPaths.forEach((file: string) => this.addDependency(file));\n }\n\n // Run schema compiler\n const loaderContext = this as LoaderContext;\n\n if (this.resourceQuery) {\n const rqOptions = parseQuery(this.resourceQuery) as QueryObject;\n\n if (rqOptions.subfile && fileStore.has(rqOptions.subfile)) {\n callback(null, fileStore.get(rqOptions.subfile));\n return;\n }\n\n callback(new Error(`CSE Schema-loader: Unknown subfile ${rqOptions.subfile} requested.`));\n return;\n }\n\n try {\n const generatorOptions: Partial<GeneratorOptions> = {\n providedTypesPaths,\n strictMode,\n };\n\n const [, , generatedJavascript] = await generateCode(\n content,\n generatorOptions,\n async (baseIdentifier: string, typescriptCode: string, javascriptCode: string) => {\n const filename = toFilename(loaderContext, baseIdentifier, javascriptCode);\n fileStore.set(filename, javascriptCode);\n\n const resourcePath = serializePath(loaderContext.resourcePath);\n\n return `!!${graphqlLoaderPath}!${resourcePath}?subfile=${filename}`;\n },\n false,\n );\n callback(null, generatedJavascript);\n } catch (err) {\n const error = err as Error;\n\n callback(error);\n }\n}\n"]}
|
|
@@ -5,7 +5,7 @@ const ModalOnActionScalar = {
|
|
|
5
5
|
name: 'ModalOnAction',
|
|
6
6
|
description: 'The value should be a callback function expecting to receive the Modal-API. See https://developer.atlassian.com/server/framework/clientside-extensions/reference/api/modal-api/',
|
|
7
7
|
validationType: types_1.ValidationTypes.function,
|
|
8
|
-
typescriptType: 'Function',
|
|
8
|
+
typescriptType: 'Function', // TODO: type this better
|
|
9
9
|
defaultExample: () => { }, // TODO: example this better
|
|
10
10
|
};
|
|
11
11
|
exports.default = ModalOnActionScalar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModalOnAction.js","sourceRoot":"","sources":["../../../../lib/scalars/extensions/ModalOnAction.ts"],"names":[],"mappings":";;AACA,oCAA2C;AAE3C,MAAM,mBAAmB,GAAW;IAChC,IAAI,EAAE,eAAe;IACrB,WAAW,EACP,iLAAiL;IACrL,cAAc,EAAE,uBAAe,CAAC,QAAQ;IACxC,cAAc,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"ModalOnAction.js","sourceRoot":"","sources":["../../../../lib/scalars/extensions/ModalOnAction.ts"],"names":[],"mappings":";;AACA,oCAA2C;AAE3C,MAAM,mBAAmB,GAAW;IAChC,IAAI,EAAE,eAAe;IACrB,WAAW,EACP,iLAAiL;IACrL,cAAc,EAAE,uBAAe,CAAC,QAAQ;IACxC,cAAc,EAAE,UAAU,EAAE,yBAAyB;IACrD,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,4BAA4B;CACzD,CAAC;AAEF,kBAAe,mBAAmB,CAAC","sourcesContent":["import type { Scalar } from '../types';\nimport { ValidationTypes } from '../types';\n\nconst ModalOnActionScalar: Scalar = {\n name: 'ModalOnAction',\n description:\n 'The value should be a callback function expecting to receive the Modal-API. See https://developer.atlassian.com/server/framework/clientside-extensions/reference/api/modal-api/',\n validationType: ValidationTypes.function,\n typescriptType: 'Function', // TODO: type this better\n defaultExample: () => {}, // TODO: example this better\n};\n\nexport default ModalOnActionScalar;\n"]}
|
|
@@ -5,7 +5,7 @@ const PanelOnActionScalar = {
|
|
|
5
5
|
name: 'PanelOnAction',
|
|
6
6
|
description: 'The value should be a callback function expecting to receive the Panel-API. See https://developer.atlassian.com/server/framework/clientside-extensions/reference/api/panel-api/',
|
|
7
7
|
validationType: types_1.ValidationTypes.function,
|
|
8
|
-
typescriptType: 'Function',
|
|
8
|
+
typescriptType: 'Function', // TODO: type this better
|
|
9
9
|
defaultExample: () => { }, // TODO: example this better
|
|
10
10
|
};
|
|
11
11
|
exports.default = PanelOnActionScalar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelOnAction.js","sourceRoot":"","sources":["../../../../lib/scalars/extensions/PanelOnAction.ts"],"names":[],"mappings":";;AACA,oCAA2C;AAE3C,MAAM,mBAAmB,GAAW;IAChC,IAAI,EAAE,eAAe;IACrB,WAAW,EACP,iLAAiL;IACrL,cAAc,EAAE,uBAAe,CAAC,QAAQ;IACxC,cAAc,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"PanelOnAction.js","sourceRoot":"","sources":["../../../../lib/scalars/extensions/PanelOnAction.ts"],"names":[],"mappings":";;AACA,oCAA2C;AAE3C,MAAM,mBAAmB,GAAW;IAChC,IAAI,EAAE,eAAe;IACrB,WAAW,EACP,iLAAiL;IACrL,cAAc,EAAE,uBAAe,CAAC,QAAQ;IACxC,cAAc,EAAE,UAAU,EAAE,yBAAyB;IACrD,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,4BAA4B;CACzD,CAAC;AAEF,kBAAe,mBAAmB,CAAC","sourcesContent":["import type { Scalar } from '../types';\nimport { ValidationTypes } from '../types';\n\nconst PanelOnActionScalar: Scalar = {\n name: 'PanelOnAction',\n description:\n 'The value should be a callback function expecting to receive the Panel-API. See https://developer.atlassian.com/server/framework/clientside-extensions/reference/api/panel-api/',\n validationType: ValidationTypes.function,\n typescriptType: 'Function', // TODO: type this better\n defaultExample: () => {}, // TODO: example this better\n};\n\nexport default PanelOnActionScalar;\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ValidationTypes = void 0;
|
|
4
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
5
4
|
var ValidationTypes;
|
|
6
5
|
(function (ValidationTypes) {
|
|
7
6
|
ValidationTypes[ValidationTypes["boolean"] = 0] = "boolean";
|
|
@@ -12,5 +11,5 @@ var ValidationTypes;
|
|
|
12
11
|
ValidationTypes[ValidationTypes["promise"] = 5] = "promise";
|
|
13
12
|
ValidationTypes[ValidationTypes["function"] = 6] = "function";
|
|
14
13
|
ValidationTypes[ValidationTypes["constant"] = 7] = "constant";
|
|
15
|
-
})(ValidationTypes
|
|
14
|
+
})(ValidationTypes || (exports.ValidationTypes = ValidationTypes = {}));
|
|
16
15
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../lib/scalars/types.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../lib/scalars/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,eASX;AATD,WAAY,eAAe;IACvB,2DAAO,CAAA;IACP,yDAAM,CAAA;IACN,yDAAM,CAAA;IACN,qDAAI,CAAA;IACJ,yDAAM,CAAA;IACN,2DAAO,CAAA;IACP,6DAAQ,CAAA;IACR,6DAAQ,CAAA;AACZ,CAAC,EATW,eAAe,+BAAf,eAAe,QAS1B","sourcesContent":["export enum ValidationTypes {\n boolean,\n number,\n string,\n date,\n regexp,\n promise,\n function,\n constant,\n}\n\nexport interface Scalar {\n name: string;\n description: string;\n typescriptType: string;\n validationType: ValidationTypes;\n defaultExample: unknown;\n acceptedValue?: unknown;\n}\n"]}
|
|
@@ -45,7 +45,7 @@ var BaseType;
|
|
|
45
45
|
BaseType[BaseType["union"] = 1] = "union";
|
|
46
46
|
BaseType[BaseType["enum"] = 2] = "enum";
|
|
47
47
|
BaseType[BaseType["object"] = 3] = "object";
|
|
48
|
-
})(BaseType
|
|
48
|
+
})(BaseType || (exports.BaseType = BaseType = {}));
|
|
49
49
|
const getBaseTypeType = (baseType) => {
|
|
50
50
|
if ((0, graphql_1.isScalarType)(baseType)) {
|
|
51
51
|
return BaseType.scalar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-utils.js","sourceRoot":"","sources":["../../../lib/utils/ast-utils.ts"],"names":[],"mappings":";;;;AASA,qCAAyG;AACzG,sEAAiC;AACjC,wEAAuC;AAKhC,MAAM,mBAAmB,GAAG,CAAC,UAAuB,EAAwE,EAAE;IACjI,OAAO,IAAA,uBAAa,EAAC,UAAU,CAAC,IAAI,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAC;AAC/D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B;AAEK,MAAM,YAAY,GAAG,CAAC,UAAyB,EAAmB,EAAE;IACvE,MAAM,SAAS,GAAoB,EAAE,CAAC;IACtC,IAAI,aAAa,GAAG,UAAU,CAAC;IAC/B,OAAO,IAAA,2BAAmB,EAAC,aAAa,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"ast-utils.js","sourceRoot":"","sources":["../../../lib/utils/ast-utils.ts"],"names":[],"mappings":";;;;AASA,qCAAyG;AACzG,sEAAiC;AACjC,wEAAuC;AAKhC,MAAM,mBAAmB,GAAG,CAAC,UAAuB,EAA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G,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE;QAChE,MAAM,QAAQ,GAAG,IAAA,uBAAa,EAAC,IAAI,CAAC,CAAC;QACrC,MAAM,cAAc,GAAG,IAAA,mBAAW,EAAC,IAAI,CAAC,CAAC;QACzC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,sBAAsB,CAAC,WAAW,CAAC,CAAC;QAC9D,OAAO;YACH,IAAI;YACJ,QAAQ;YACR,IAAI;YACJ,WAAW,EAAE,OAAO;YACpB,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,GAAG,IAAI,EAAE;YACrB,SAAS,EAAE,IAAA,oBAAY,EAAC,IAAI,CAAC;YAC7B,QAAQ,EAAE;gBACN,IAAI,EAAE,IAAA,uBAAe,EAAC,cAAc,CAAC;gBACrC,IAAI,EAAE,GAAG,cAAc,EAAE;gBACzB,SAAS,EAAE,cAAc;aAC5B;SACJ,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEK,MAAM,wBAAwB,GAAG,CAAC,UAA6B,EAAc,EAAE;IAClF,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC;IACzC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,sBAAsB,CAAC,WAAW,CAAC,CAAC;IAC9D,OAAO;QACH,IAAI,EAAE,IAAA,qBAAU,EAAC,IAAI,CAAC;QACtB,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,OAAO;QACpB,IAAI,EAAE,IAAI;QACV,WAAW,EAAE,6BAA6B,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;KACrE,CAAC;AACN,CAAC,CAAC;AAVW,QAAA,wBAAwB,4BAUnC","sourcesContent":["import type {\n GraphQLField,\n GraphQLFieldMap,\n GraphQLList,\n GraphQLNonNull,\n GraphQLObjectType,\n GraphQLOutputType,\n GraphQLType,\n} from 'graphql';\nimport { isEnumType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType } from 'graphql';\nimport matter from 'gray-matter';\nimport pascalCase from './pascal-case';\n\nexport type NonNullNonListType = Exclude<GraphQLOutputType, GraphQLList<GraphQLOutputType> | GraphQLNonNull<GraphQLOutputType>>;\nexport type AcceptedTypes = GraphQLOutputType;\n\nexport const isListOrNonNullType = (typeObject: GraphQLType): typeObject is GraphQLList<GraphQLType> | GraphQLNonNull<GraphQLType> => {\n return isNonNullType(typeObject) || isListType(typeObject);\n};\n\nexport const getTypeStack = (typeObject: AcceptedTypes): AcceptedTypes[] => {\n const typeStack: AcceptedTypes[] = [];\n let drillDownType = typeObject;\n while (isListOrNonNullType(drillDownType)) {\n typeStack.push(drillDownType);\n drillDownType = drillDownType.ofType;\n }\n typeStack.push(drillDownType);\n\n return typeStack;\n};\n\nexport const getBaseType = (typeObject: AcceptedTypes) => {\n return getTypeStack(typeObject).pop() as NonNullNonListType;\n};\n\nexport const isFirstRequired = (typeStack: AcceptedTypes[]) => {\n return isNonNullType(typeStack[0]);\n};\n\nexport const isStackEndRequired = (typeStack: AcceptedTypes[]) => {\n if (typeStack.length < 2) {\n return false;\n }\n return isNonNullType(typeStack[typeStack.length - 2]);\n};\n\nexport const containsListType = (typeStack: AcceptedTypes[]): boolean => {\n return typeStack.some((stackItem) => isListType(stackItem));\n};\n\nexport enum BaseType {\n scalar,\n union,\n enum,\n object,\n}\n\nexport const getBaseTypeType = (baseType: NonNullNonListType) => {\n if (isScalarType(baseType)) {\n return BaseType.scalar;\n }\n\n if (isUnionType(baseType)) {\n return BaseType.union;\n }\n\n if (isEnumType(baseType)) {\n return BaseType.enum;\n }\n\n if (isObjectType(baseType)) {\n return BaseType.object;\n }\n\n throw new Error(`The type: ${baseType} is not supported.`);\n};\n\nconst getMetaFromDescription = (description: GraphQLField<unknown, unknown>['description']) => {\n const input = description || '';\n\n const { data, content } = matter(input);\n return { data, content };\n};\n\nexport interface BaseTypeDescriptor {\n type: BaseType;\n reference: NonNullNonListType;\n name: string;\n}\n\nexport interface ObjectType {\n name: string;\n type: GraphQLObjectType;\n description: string;\n meta: { [key: string]: unknown };\n descriptors: FieldDescriptor[];\n}\n\nexport interface FieldDescriptor {\n required: boolean;\n description: string;\n meta: { [key: string]: unknown };\n name: string;\n typeString: string;\n typeStack: AcceptedTypes[];\n type: AcceptedTypes;\n baseType: BaseTypeDescriptor;\n}\n\nconst getObjectTypeFieldDescriptors = (fields: GraphQLFieldMap<unknown, unknown>) => {\n return Object.entries(fields).map(([name, { type, description }]) => {\n const required = isNonNullType(type);\n const baseTypeObject = getBaseType(type);\n const { data, content } = getMetaFromDescription(description);\n return {\n name,\n required,\n type,\n description: content,\n meta: data,\n typeString: `${type}`,\n typeStack: getTypeStack(type),\n baseType: {\n type: getBaseTypeType(baseTypeObject),\n name: `${baseTypeObject}`,\n reference: baseTypeObject,\n },\n };\n });\n};\n\nexport const getObjectTypeDescription = (objectType: GraphQLObjectType): ObjectType => {\n const { name, description } = objectType;\n const { data, content } = getMetaFromDescription(description);\n return {\n name: pascalCase(name),\n type: objectType,\n description: content,\n meta: data,\n descriptors: getObjectTypeFieldDescriptors(objectType.getFields()),\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-schema.js","sourceRoot":"","sources":["../../../lib/utils/create-schema.ts"],"names":[],"mappings":";;;;AAEA,kDAA6D;AAE7D,oFAAmD;AACnD,4FAA0D;AAC1D,gGAA6D;AAEtD,MAAM,sBAAsB,GAAG,CAAC,UAAkB,EAAE,YAAwB,2BAAgB,EAAE,EAAE;IACnG,IAAI;
|
|
1
|
+
{"version":3,"file":"create-schema.js","sourceRoot":"","sources":["../../../lib/utils/create-schema.ts"],"names":[],"mappings":";;;;AAEA,kDAA6D;AAE7D,oFAAmD;AACnD,4FAA0D;AAC1D,gGAA6D;AAEtD,MAAM,sBAAsB,GAAG,CAAC,UAAkB,EAAE,YAAwB,2BAAgB,EAAE,EAAE;IACnG,IAAI,CAAC;QACD,MAAM,QAAQ,GAAG,IAAA,iCAAoB,EAAC,IAAA,+BAAmB,EAAC,UAAU,CAAC,CAAC,CAAC;QACvE,OAAO,IAAA,6BAAoB,EAAC;YACxB,QAAQ;YACR,SAAS;YACT,yBAAyB,EAAE;gBACvB,8BAA8B,EAAE,QAAQ;aAC3C;SACJ,CAAC,CAAC;IACP,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,MAAM,KAAK,GAAG,GAAY,CAAC;QAE3B,MAAM,IAAI,KAAK,CAAC;;EAEtB,UAAU;;;;EAIV,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAClB,CAAC;AACL,CAAC,CAAC;AArBW,QAAA,sBAAsB,0BAqBjC;AAEF,MAAa,4BAA6B,SAAQ,KAAK;IACnD,YAAY,CAAS;QACjB,KAAK,CAAC,CAAC,CAAC,CAAC;QAET,gCAAgC;QAChC,mJAAmJ;QACnJ,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,4BAA4B,CAAC,SAAS,CAAC,CAAC;IACxE,CAAC;CACJ;AARD,oEAQC;AAED;;;;;;GAMG;AACI,MAAM,eAAe,GAAG,CAAC,YAAoB,EAAE,YAAoB,EAAqB,EAAE;IAC7F,MAAM,MAAM,GAAG,IAAA,8BAAsB,EAAC,YAAY,CAAC,CAAC;IACpD,MAAM,gBAAgB,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,YAAY,CAAsB,CAAC;IAEhF,IAAI,gBAAgB,KAAK,IAAI,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;QAC9D,MAAM,IAAI,4BAA4B,CAAC,kCAAkC,YAAY,GAAG,CAAC,CAAC;IAC9F,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC5B,CAAC,CAAC;AATW,QAAA,eAAe,mBAS1B","sourcesContent":["import type { GraphQLObjectType } from 'graphql';\nimport type { IResolvers } from '@graphql-tools/utils';\nimport { makeExecutableSchema } from '@graphql-tools/schema';\n\nimport defaultResolvers from './default-resolvers';\nimport injectProvidedTypes from './inject-provided-types';\nimport injectBuiltInScalars from './inject-built-in-scalars';\n\nexport const createExecutableSchema = (baseSchema: string, resolvers: IResolvers = defaultResolvers) => {\n try {\n const typeDefs = injectBuiltInScalars(injectProvidedTypes(baseSchema));\n return makeExecutableSchema({\n typeDefs,\n resolvers,\n resolverValidationOptions: {\n requireResolversForResolveType: 'ignore',\n },\n });\n } catch (err) {\n const error = err as Error;\n\n throw new Error(`Failed to parse\nschema:\n${baseSchema}\n\n\nmessage:\n${error.toString()}`);\n }\n};\n\nexport class SchemaDefinitionMissingError extends Error {\n constructor(m: string) {\n super(m);\n\n // Set the prototype explicitly.\n // see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(this, SchemaDefinitionMissingError.prototype);\n }\n}\n\n/**\n * Extracts the GraphQL object type definition of the object type of name <basename> from the GraphQL definition\n *\n * @param schemaString - GraphQL schema string\n * @param baseTypeName - name of the type we want to extract\n * @returns - Object type\n */\nexport const getSchemaObject = (schemaString: string, baseTypeName: string): GraphQLObjectType => {\n const schema = createExecutableSchema(schemaString);\n const schemaDefinition = schema.getTypeMap()[baseTypeName] as GraphQLObjectType;\n\n if (schemaDefinition === null || schemaDefinition === undefined) {\n throw new SchemaDefinitionMissingError(`No Schema definition found for ${baseTypeName}!`);\n }\n\n return schemaDefinition;\n};\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const
|
|
4
|
+
const camelCase_1 = tslib_1.__importDefault(require("lodash/camelCase"));
|
|
5
5
|
const pascalCase = (str) => {
|
|
6
|
-
const camelCased = (0,
|
|
6
|
+
const camelCased = (0, camelCase_1.default)(str);
|
|
7
7
|
return camelCased.charAt(0).toUpperCase() + camelCased.slice(1);
|
|
8
8
|
};
|
|
9
9
|
exports.default = pascalCase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pascal-case.js","sourceRoot":"","sources":["../../../lib/utils/pascal-case.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"pascal-case.js","sourceRoot":"","sources":["../../../lib/utils/pascal-case.ts"],"names":[],"mappings":";;;AAAA,yEAAyC;AAEzC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE;IAC/B,MAAM,UAAU,GAAG,IAAA,mBAAS,EAAC,GAAG,CAAC,CAAC;IAClC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC","sourcesContent":["import camelCase from 'lodash/camelCase';\n\nconst pascalCase = (str: string) => {\n const camelCased = camelCase(str);\n return camelCased.charAt(0).toUpperCase() + camelCased.slice(1);\n};\n\nexport default pascalCase;\n"]}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.populateDocument = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const ast_utils_1 = require("./ast-utils");
|
|
6
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
7
6
|
const populateDocument = (schemaDocument, schemaObject) => {
|
|
8
7
|
if ((0, graphql_1.isObjectType)(schemaObject)) {
|
|
9
8
|
// circuit breaker
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-document-populator.js","sourceRoot":"","sources":["../../../lib/utils/schema-document-populator.ts"],"names":[],"mappings":";;;AAAA,qCAAkH;AAGlH,2CAAoE;
|
|
1
|
+
{"version":3,"file":"schema-document-populator.js","sourceRoot":"","sources":["../../../lib/utils/schema-document-populator.ts"],"names":[],"mappings":";;;AAAA,qCAAkH;AAGlH,2CAAoE;AAC7D,MAAM,gBAAgB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c,CAAC;IAC1B,CAAC;IAED,IAAI,IAAA,yBAAe,EAAC,YAAY,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,wCAAwC,YAAY,0DAA0D,CAAC,CAAC;IACpI,CAAC;IAED,IAAI,IAAA,2BAAiB,EAAC,YAAY,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,wCAAwC,YAAY,sDAAsD,CAAC,CAAC;IAChI,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,YAAY,0CAA0C,CAAC,CAAC;AACpH,CAAC,CAAC;AA9CW,QAAA,gBAAgB,oBA8C3B","sourcesContent":["import { isEnumType, isInputObjectType, isInterfaceType, isObjectType, isScalarType, isUnionType } from 'graphql';\nimport type SchemaDocument from './SchemaDocument';\nimport type { NonNullNonListType } from './ast-utils';\nimport { getBaseType, getObjectTypeDescription } from './ast-utils';\nexport const populateDocument = (schemaDocument: SchemaDocument, schemaObject: NonNullNonListType) => {\n if (isObjectType(schemaObject)) {\n // circuit breaker\n if (schemaDocument.getObjectTypes().has(schemaObject.name)) {\n return schemaDocument;\n }\n\n schemaDocument.addObjectType(schemaObject.name, getObjectTypeDescription(schemaObject));\n\n Object.values(schemaObject.getFields())\n .map((field) => getBaseType(field.type))\n .forEach((fieldBase) => {\n populateDocument(schemaDocument, fieldBase);\n });\n\n return schemaDocument;\n }\n\n if (isScalarType(schemaObject)) {\n schemaDocument.addScalar(schemaObject);\n return schemaDocument;\n }\n\n if (isEnumType(schemaObject)) {\n schemaDocument.addEnumType(schemaObject);\n return schemaDocument;\n }\n\n if (isUnionType(schemaObject)) {\n schemaDocument.addUnionType(schemaObject);\n // typings here are broken?!\n (schemaObject.getTypes() as unknown as NonNullNonListType[]).forEach((fieldBase) => {\n populateDocument(schemaDocument, fieldBase);\n });\n return schemaDocument;\n }\n\n if (isInterfaceType(schemaObject)) {\n throw new Error(`Encountered unsupported declaration: ${schemaObject}. Interface types are currently not supported! Aborting.`);\n }\n\n if (isInputObjectType(schemaObject)) {\n throw new Error(`Encountered unsupported declaration: ${schemaObject}. Input types are currently not supported! Aborting.`);\n }\n\n throw new Error(`Encountered unsupported declaration: ${schemaObject}. Failed to populate document. Aborting.`);\n};\n"]}
|