@atlassian/clientside-extensions-schema 5.0.0 → 5.1.0-9864e593-me132vr9
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 +7 -7
- package/dist/cjs/bin/generate-from-schema.js.map +1 -1
- package/dist/cjs/bin/generate-graphql-definitions.js +4 -4
- package/dist/cjs/bin/generate-graphql-definitions.js.map +1 -1
- package/dist/cjs/bin/generate-module-definitions-file.js +3 -3
- package/dist/cjs/bin/generate-module-definitions-file.js.map +1 -1
- package/dist/cjs/code-generator/code-generator.js +4 -4
- package/dist/cjs/code-generator/code-generator.js.map +1 -1
- package/dist/cjs/code-generator/type-definitions.js +2 -2
- package/dist/cjs/code-generator/type-definitions.js.map +1 -1
- package/dist/cjs/graphql-definition.js +9 -3
- package/dist/cjs/graphql-definition.js.map +1 -1
- package/dist/cjs/loader/schema-loader.js +2 -2
- package/dist/cjs/loader/schema-loader.js.map +1 -1
- package/dist/cjs/providedTypes/index.js +2 -2
- package/dist/cjs/providedTypes/index.js.map +1 -1
- package/dist/cjs/scalars/index.js +15 -15
- package/dist/cjs/scalars/index.js.map +1 -1
- package/dist/cjs/utils/ast-utils.js +2 -2
- package/dist/cjs/utils/ast-utils.js.map +1 -1
- package/dist/cjs/utils/create-schema.js +3 -3
- package/dist/cjs/utils/create-schema.js.map +1 -1
- package/dist/cjs/utils/default-resolvers.js +1 -1
- package/dist/cjs/utils/default-resolvers.js.map +1 -1
- package/dist/cjs/utils/inject-built-in-scalars.js +1 -1
- package/dist/cjs/utils/inject-built-in-scalars.js.map +1 -1
- package/dist/cjs/utils/inject-provided-types.js +2 -2
- package/dist/cjs/utils/inject-provided-types.js.map +1 -1
- package/dist/cjs/utils/pascal-case.js +1 -1
- package/dist/cjs/utils/pascal-case.js.map +1 -1
- package/dist/cjs/utils/schema-document-serializer.js +1 -1
- package/dist/cjs/utils/schema-document-serializer.js.map +1 -1
- package/dist/cjs/utils/schema.js +1 -1
- package/dist/cjs/utils/schema.js.map +1 -1
- package/dist/cjs/utils/validator-generator.js +1 -1
- package/dist/cjs/utils/validator-generator.js.map +1 -1
- package/dist/types/code-generator/code-generator.d.ts +3 -3
- package/dist/types/code-generator/code-generator.d.ts.map +1 -1
- package/dist/types/loader/types.d.ts +3 -3
- package/dist/types/loader/types.d.ts.map +1 -1
- package/dist/types/utils/ast-utils.d.ts +2 -2
- package/dist/types/utils/ast-utils.d.ts.map +1 -1
- package/dist/types/utils/schema-document-serializer.d.ts +6 -6
- package/dist/types/utils/schema-document-serializer.d.ts.map +1 -1
- package/dist/types/utils/validator-types.d.ts +2 -2
- package/dist/types/utils/validator-types.d.ts.map +1 -1
- package/lib/loader/schema-loader.test.ts +1 -1
- package/package.json +11 -8
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const glob_1 = require("glob");
|
|
6
|
-
const yargs_1 =
|
|
7
|
-
const path_1 =
|
|
8
|
-
const fs_1 =
|
|
9
|
-
const mkdirp_1 =
|
|
6
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
9
|
+
const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
|
|
10
10
|
const rimraf_1 = require("rimraf");
|
|
11
|
-
const chokidar_1 =
|
|
12
|
-
const lodash_snakecase_1 =
|
|
13
|
-
const code_generator_1 =
|
|
11
|
+
const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
|
|
12
|
+
const lodash_snakecase_1 = tslib_1.__importDefault(require("lodash.snakecase"));
|
|
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) => {
|
|
16
16
|
return `${baseFileName}.${extension}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-from-schema.js","sourceRoot":"","sources":["../../../lib/bin/generate-from-schema.ts"],"names":[],"mappings":";;;;AACA,+BAA4B;AAC5B,+DAA0B;AAC1B,6DAAwB;AACxB,yDAAoB;AACpB,iEAA4B;AAC5B,mCAAgC;AAChC,qEAAgC;AAChC,qFAAyC;AACzC,mGAA4D;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,CAAC,IAAY,EAAE,EAAE;IACpC,OAAO,IAAA,0BAAS,EAAC,IAAI,CAAW,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAE,EAAE;IAC1C,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,2BAA2B;AAChF,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAE,EAAE;IAC5C,IAAI,CAAC,QAAQ,EAAE;QACX,OAAO,IAAI,CAAC;KACf;IAED,OAAO,KAAK,QAAQ,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,mBAAmB,GACrB,CAAC,eAAuB,EAAc,EAAE,CACxC,KAAK,EAAE,cAAsB,EAAE,cAAsB,EAAE,cAAsB,EAAE,EAAE;IAC7E,MAAM,YAAY,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;IACpD,MAAM,iBAAiB,GA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OAAO,CAAC,aAAa;iBACvC,CAAC;gBAEF,MAAM,4BAA4B,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;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,gFAAyC;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,OAA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,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"]}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const yargs_1 =
|
|
6
|
-
const fs_1 =
|
|
7
|
-
const path_1 =
|
|
8
|
-
const graphql_definition_1 =
|
|
5
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
6
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
+
const graphql_definition_1 = tslib_1.__importDefault(require("../graphql-definition"));
|
|
9
9
|
const run = async (options) => {
|
|
10
10
|
const definitions = await (0, graphql_definition_1.default)();
|
|
11
11
|
if (!options.path) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-graphql-definitions.js","sourceRoot":"","sources":["../../../lib/bin/generate-graphql-definitions.ts"],"names":[],"mappings":";;;;AACA
|
|
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;QACf,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;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;QACA,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;KACnB;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,KAAK,CAAC,kCAAkC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;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"]}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const yargs_1 =
|
|
7
|
-
const fs_1 =
|
|
8
|
-
const type_definitions_1 =
|
|
6
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
7
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
8
|
+
const type_definitions_1 = tslib_1.__importDefault(require("../code-generator/type-definitions"));
|
|
9
9
|
const run = async (options) => {
|
|
10
10
|
const definitions = (0, type_definitions_1.default)(options.moduleGlob);
|
|
11
11
|
if (!options.path) {
|
|
@@ -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
|
|
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;QACf,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;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;QACA,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;KACnB;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,KAAK,CAAC,kCAAkC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;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,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const ts =
|
|
4
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
5
5
|
const schema_document_populator_1 = require("../utils/schema-document-populator");
|
|
6
6
|
const create_schema_1 = require("../utils/create-schema");
|
|
7
7
|
const validator_generator_1 = require("../utils/validator-generator");
|
|
8
8
|
const schema_document_serializer_1 = require("../utils/schema-document-serializer");
|
|
9
|
-
const SchemaDocument_1 =
|
|
10
|
-
const injcect_types_1 =
|
|
9
|
+
const SchemaDocument_1 = tslib_1.__importDefault(require("../utils/SchemaDocument"));
|
|
10
|
+
const injcect_types_1 = tslib_1.__importDefault(require("../utils/injcect-types"));
|
|
11
11
|
const schema_1 = require("../utils/schema");
|
|
12
12
|
const utils_1 = require("../utils");
|
|
13
|
-
const react_1 =
|
|
13
|
+
const react_1 = tslib_1.__importDefault(require("./react"));
|
|
14
14
|
const generateJavascript = (source) => {
|
|
15
15
|
const result = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } });
|
|
16
16
|
return result.outputText;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-generator.js","sourceRoot":"","sources":["../../../lib/code-generator/code-generator.ts"],"names":[],"mappings":";;;AAAA,4DAAiC;AACjC,kFAAsE;AACtE,0DAAuF;AACvF,sEAA+D;AAC/D,oFAA8E;AAC9E,0FAAqD;AACrD,wFAAiD;AACjD,4CAA6C;AAC7C,oCAAqC;AAErC,iEAAoD;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,CAAC,QAAQ,CAAC,0CAAE,IAAI,0CAAE,cAAwB,CAAC;AAC5E,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,YA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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"]}
|
|
1
|
+
{"version":3,"file":"code-generator.js","sourceRoot":"","sources":["../../../lib/code-generator/code-generator.ts"],"names":[],"mappings":";;;AA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,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;QACjB,MAAM,IAAI,KAAK,CAAC;;;;;;;;;;;;;;CAcvB,CAAC,CAAC;KACE;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;QACf,OAAO,SAA2C,CAAC;KACtD;IAED,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,aAAa,EAAE,oBAAoB,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAE1H,IAAI,SAAS,EAAE;QACX,MAAM,UAAU,CAAC,cAAc,EAAE,aAAa,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAC;QACnF,OAAO,SAA2C,CAAC;KACtD;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"]}
|
|
@@ -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 typescript_1 =
|
|
4
|
+
const typescript_1 = tslib_1.__importDefault(require("typescript"));
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const react_1 =
|
|
6
|
+
const react_1 = tslib_1.__importDefault(require("./react"));
|
|
7
7
|
const removeNestedDeclareKeywords = (definitions) => {
|
|
8
8
|
const declareConstRegExp = /export declare const/g;
|
|
9
9
|
const declareConstReplacer = 'export const';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-definitions.js","sourceRoot":"","sources":["../../../lib/code-generator/type-definitions.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"type-definitions.js","sourceRoot":"","sources":["../../../lib/code-generator/type-definitions.ts"],"names":[],"mappings":";;;AACA,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;QACtC,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;KACvD;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,MAAM,YAAY,GAAG,YAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;IAEpE,IAAI,UAAU,GAAG,EA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AEF,sEAAsE;AACtE,SAAwB,cAAc,CAAC,UAAkB;IACrD,OAAO,sBAAsB,CAAC,mBAAmB,EAAE,EAAE,UAAU,CAAC,CAAC;AACrE,CAAC;AAFD,iCAEC","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,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -32,14 +36,16 @@ scalar ${scalar.name}
|
|
|
32
36
|
const getScalars = async () => {
|
|
33
37
|
const scalarFiles = await (0, glob_1.glob)('./scalars/**/*.js', { cwd: __dirname, dotRelative: true });
|
|
34
38
|
const scalars = (await Promise.all(scalarFiles.map(async (filePath) => {
|
|
35
|
-
|
|
39
|
+
var _a;
|
|
40
|
+
return (await (_a = filePath, Promise.resolve().then(() => __importStar(require(_a))))).default;
|
|
36
41
|
}))).filter(Boolean);
|
|
37
42
|
return scalars.map(scalarToDefinitionString).join('\n\n');
|
|
38
43
|
};
|
|
39
44
|
const getProvidedTypes = async () => {
|
|
40
45
|
const providedTypesFiles = await (0, glob_1.glob)('./providedTypes/*.js', { cwd: __dirname, dotRelative: true });
|
|
41
46
|
const providedTypes = await Promise.all(providedTypesFiles.map(async (filePath) => {
|
|
42
|
-
|
|
47
|
+
var _a;
|
|
48
|
+
return (await (_a = filePath, Promise.resolve().then(() => __importStar(require(_a))))).default;
|
|
43
49
|
}));
|
|
44
50
|
return providedTypes.join('\n\n');
|
|
45
51
|
};
|
|
@@ -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;CACnB,CAAC;AACF,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;IAC1B,MAAM,WAAW,GAAG,MAAM,IAAA,WAAI,EAAC,mBAAmB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3F,MAAM,OAAO,GAAG,CACZ,MAAM,OAAO,CAAC,GAAG,CACb,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;;QAC/B,OAAO,CAAC,YAAa,QAAQ,0DAAC,CAAC,CAAC,OAAiB,CAAC;IACtD,CAAC,CAAC,CACL,CACJ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,OAAO,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9D,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;IAChC,MAAM,kBAAkB,GAAG,MAAM,IAAA,WAAI,EAAC,sBAAsB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IACrG,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CACnC,kBAAkB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;;QACtC,OAAO,CAAC,YAAa,QAAQ,0DAAC,CAAC,CAAC,OAAiB,CAAC;IACtD,CAAC,CAAC,CACL,CAAC;IAEF,OAAO,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF,kBAAe,KAAK,IAAI,EAAE;IACtB,MAAM,iBAAiB,GAAG,MAAM,UAAU,EAAE,CAAC;IAC7C,MAAM,wBAAwB,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAE1D,OAAO;;;;EAIT,iBAAiB;;;;;EAKjB,wBAAwB;CACzB,CAAC;AACF,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"]}
|
|
@@ -4,8 +4,8 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const loader_utils_1 = require("loader-utils");
|
|
5
5
|
const glob_1 = require("glob");
|
|
6
6
|
const schema_utils_1 = require("schema-utils");
|
|
7
|
-
const code_generator_1 =
|
|
8
|
-
const loader_schema_json_1 =
|
|
7
|
+
const code_generator_1 = tslib_1.__importDefault(require("../code-generator/code-generator"));
|
|
8
|
+
const loader_schema_json_1 = tslib_1.__importDefault(require("./loader-schema.json"));
|
|
9
9
|
const toFilename = (loaderContext, identifier, content) => (0, loader_utils_1.interpolateName)(loaderContext, `${identifier}.[contenthash].js`, {
|
|
10
10
|
context: loaderContext.rootContext,
|
|
11
11
|
content,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-loader.js","sourceRoot":"","sources":["../../../lib/loader/schema-loader.ts"],"names":[],"mappings":";;;AAAA,+CAAuE;AACvE,+BAA4B;AAC5B,+CAAwC;AAIxC,
|
|
1
|
+
{"version":3,"file":"schema-loader.js","sourceRoot":"","sources":["../../../lib/loader/schema-loader.ts"],"names":[],"mappings":";;;AAAA,+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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,MAAM,KAAK,GAAG,GAAY,CAAC;QAE3B,QAAQ,CAAC,KAAK,CAAC,CAAC;KACnB;AACL,CAAC;AA5DD,+BA4DC","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"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const IconGlyph_1 =
|
|
5
|
-
const Icon_1 =
|
|
4
|
+
const IconGlyph_1 = tslib_1.__importDefault(require("./IconGlyph"));
|
|
5
|
+
const Icon_1 = tslib_1.__importDefault(require("./Icon"));
|
|
6
6
|
const providedTypes = [IconGlyph_1.default, Icon_1.default];
|
|
7
7
|
exports.default = providedTypes;
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/providedTypes/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/providedTypes/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C;AAC1C,0DAA8B;AAE9B,MAAM,aAAa,GAAG,CAAC,mBAAe,EAAE,cAAQ,CAAC,CAAC;AAElD,kBAAe,aAAa,CAAC","sourcesContent":["import IconGlyphScalar from './IconGlyph';\nimport IconType from './Icon';\n\nconst providedTypes = [IconGlyphScalar, IconType];\n\nexport default providedTypes;\n"]}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const AsyncPanel_1 =
|
|
5
|
-
const Button_1 =
|
|
6
|
-
const Link_1 =
|
|
7
|
-
const Modal_1 =
|
|
8
|
-
const ModalOnAction_1 =
|
|
9
|
-
const Panel_1 =
|
|
10
|
-
const PanelOnAction_1 =
|
|
11
|
-
const Section_1 =
|
|
12
|
-
const Boolean_1 =
|
|
13
|
-
const Date_1 =
|
|
14
|
-
const Function_1 =
|
|
15
|
-
const Number_1 =
|
|
16
|
-
const Promise_1 =
|
|
17
|
-
const RegExp_1 =
|
|
18
|
-
const String_1 =
|
|
4
|
+
const AsyncPanel_1 = tslib_1.__importDefault(require("./extensions/AsyncPanel"));
|
|
5
|
+
const Button_1 = tslib_1.__importDefault(require("./extensions/Button"));
|
|
6
|
+
const Link_1 = tslib_1.__importDefault(require("./extensions/Link"));
|
|
7
|
+
const Modal_1 = tslib_1.__importDefault(require("./extensions/Modal"));
|
|
8
|
+
const ModalOnAction_1 = tslib_1.__importDefault(require("./extensions/ModalOnAction"));
|
|
9
|
+
const Panel_1 = tslib_1.__importDefault(require("./extensions/Panel"));
|
|
10
|
+
const PanelOnAction_1 = tslib_1.__importDefault(require("./extensions/PanelOnAction"));
|
|
11
|
+
const Section_1 = tslib_1.__importDefault(require("./extensions/Section"));
|
|
12
|
+
const Boolean_1 = tslib_1.__importDefault(require("./Boolean"));
|
|
13
|
+
const Date_1 = tslib_1.__importDefault(require("./Date"));
|
|
14
|
+
const Function_1 = tslib_1.__importDefault(require("./Function"));
|
|
15
|
+
const Number_1 = tslib_1.__importDefault(require("./Number"));
|
|
16
|
+
const Promise_1 = tslib_1.__importDefault(require("./Promise"));
|
|
17
|
+
const RegExp_1 = tslib_1.__importDefault(require("./RegExp"));
|
|
18
|
+
const String_1 = tslib_1.__importDefault(require("./String"));
|
|
19
19
|
const scalarsArr = [
|
|
20
20
|
AsyncPanel_1.default,
|
|
21
21
|
Boolean_1.default,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/scalars/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/scalars/index.ts"],"names":[],"mappings":";;;AAAA,iFAAgE;AAChE,yEAAwD;AACxD,qEAAoD;AACpD,uEAAsD;AACtD,uFAA6D;AAC7D,uEAAsD;AACtD,uFAA6D;AAC7D,2EAA0D;AAE1D,gEAAsC;AACtC,0DAAgC;AAChC,kEAAwC;AACxC,8DAAoC;AACpC,gEAAsC;AACtC,8DAAoC;AACpC,8DAAoC;AAGpC,MAAM,UAAU,GAAG;IACf,oBAAyB;IACzB,iBAAa;IACb,gBAAqB;IACrB,cAAU;IACV,kBAAc;IACd,cAAmB;IACnB,eAAoB;IACpB,uBAAmB;IACnB,gBAAY;IACZ,eAAoB;IACpB,uBAAmB;IACnB,iBAAa;IACb,gBAAY;IACZ,iBAAsB;IACtB,gBAAY;CACf,CAAC;AAEF,MAAM,OAAO,GAAwB,IAAI,GAAG,CAAiB,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AAEhH,kBAAe,OAAO,CAAC","sourcesContent":["import AsyncPanelExtensionScalar from './extensions/AsyncPanel';\nimport ButtonExtensionScalar from './extensions/Button';\nimport LinkExtensionScalar from './extensions/Link';\nimport ModalExtensionScalar from './extensions/Modal';\nimport ModalOnActionScalar from './extensions/ModalOnAction';\nimport PanelExtensionScalar from './extensions/Panel';\nimport PanelOnActionScalar from './extensions/PanelOnAction';\nimport SectionExtensionScalar from './extensions/Section';\n\nimport BooleanScalar from './Boolean';\nimport DateScalar from './Date';\nimport FunctionScalar from './Function';\nimport NumberScalar from './Number';\nimport PromiseScalar from './Promise';\nimport RegExpScalar from './RegExp';\nimport StringScalar from './String';\nimport type { Scalar } from './types';\n\nconst scalarsArr = [\n AsyncPanelExtensionScalar,\n BooleanScalar,\n ButtonExtensionScalar,\n DateScalar,\n FunctionScalar,\n LinkExtensionScalar,\n ModalExtensionScalar,\n ModalOnActionScalar,\n NumberScalar,\n PanelExtensionScalar,\n PanelOnActionScalar,\n PromiseScalar,\n RegExpScalar,\n SectionExtensionScalar,\n StringScalar,\n];\n\nconst scalars: Map<string, Scalar> = new Map<string, Scalar>(scalarsArr.map((scalar) => [scalar.name, scalar]));\n\nexport default scalars;\n"]}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getObjectTypeDescription = exports.getBaseTypeType = exports.BaseType = exports.containsListType = exports.isStackEndRequired = exports.isFirstRequired = exports.getBaseType = exports.getTypeStack = exports.isListOrNonNullType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
|
-
const gray_matter_1 =
|
|
7
|
-
const pascal_case_1 =
|
|
6
|
+
const gray_matter_1 = tslib_1.__importDefault(require("gray-matter"));
|
|
7
|
+
const pascal_case_1 = tslib_1.__importDefault(require("./pascal-case"));
|
|
8
8
|
const isListOrNonNullType = (typeObject) => {
|
|
9
9
|
return (0, graphql_1.isNonNullType)(typeObject) || (0, graphql_1.isListType)(typeObject);
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-utils.js","sourceRoot":"","sources":["../../../lib/utils/ast-utils.ts"],"names":[],"mappings":";;;;AASA,qCAAyG;AACzG,
|
|
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;QACvC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC9B,aAAa,GAAG,aAAa,CAAC,MAAM,CAAC;KACxC;IACD,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAE9B,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAVW,QAAA,YAAY,gBAUvB;AAEK,MAAM,WAAW,GAAG,CAAC,UAAyB,EAAE,EAAE;IACrD,OAAO,IAAA,oBAAY,EAAC,UAAU,CAAC,CAAC,GAAG,EAAwB,CAAC;AAChE,CAAC,CAAC;AAFW,QAAA,WAAW,eAEtB;AAEK,MAAM,eAAe,GAAG,CAAC,SAA0B,EAAE,EAAE;IAC1D,OAAO,IAAA,uBAAa,EAAC,SAAS,CAAC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C;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"]}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getSchemaObject = exports.SchemaDefinitionMissingError = exports.createExecutableSchema = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const schema_1 = require("@graphql-tools/schema");
|
|
6
|
-
const default_resolvers_1 =
|
|
7
|
-
const inject_provided_types_1 =
|
|
8
|
-
const inject_built_in_scalars_1 =
|
|
6
|
+
const default_resolvers_1 = tslib_1.__importDefault(require("./default-resolvers"));
|
|
7
|
+
const inject_provided_types_1 = tslib_1.__importDefault(require("./inject-provided-types"));
|
|
8
|
+
const inject_built_in_scalars_1 = tslib_1.__importDefault(require("./inject-built-in-scalars"));
|
|
9
9
|
const createExecutableSchema = (baseSchema, resolvers = default_resolvers_1.default) => {
|
|
10
10
|
try {
|
|
11
11
|
const typeDefs = (0, inject_built_in_scalars_1.default)((0, inject_provided_types_1.default)(baseSchema));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-schema.js","sourceRoot":"","sources":["../../../lib/utils/create-schema.ts"],"names":[],"mappings":";;;;AAEA,kDAA6D;AAE7D,
|
|
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;QACA,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;KACN;IAAC,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,GAAY,CAAC;QAE3B,MAAM,IAAI,KAAK,CAAC;;EAEtB,UAAU;;;;EAIV,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;KACjB;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;QAC7D,MAAM,IAAI,4BAA4B,CAAC,kCAAkC,YAAY,GAAG,CAAC,CAAC;KAC7F;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"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
-
const scalars_1 =
|
|
5
|
+
const scalars_1 = tslib_1.__importDefault(require("../scalars"));
|
|
6
6
|
const toGraphQlScalar = (scalar) => new graphql_1.GraphQLScalarType({
|
|
7
7
|
name: scalar.name,
|
|
8
8
|
description: scalar.description,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-resolvers.js","sourceRoot":"","sources":["../../../lib/utils/default-resolvers.ts"],"names":[],"mappings":";;;AAAA,qCAA4C;AAE5C,
|
|
1
|
+
{"version":3,"file":"default-resolvers.js","sourceRoot":"","sources":["../../../lib/utils/default-resolvers.ts"],"names":[],"mappings":";;;AAAA,qCAA4C;AAE5C,iEAAiC;AAGjC,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,EAAE,CACvC,IAAI,2BAAiB,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC,IAAI;IACjB,WAAW,EAAE,MAAM,CAAC,WAAW;IAC/B,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;IACpB,SAAS,CAAC,KAAc;QACpB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc;IACxC,CAAC;IACD,YAAY,CAAC,GAAY;QACrB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc;IACtC,CAAC;CACJ,CAAC,CAAC;AAEP,MAAM,gBAAgB,GAAe,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtI,kBAAe,gBAAgB,CAAC","sourcesContent":["import { GraphQLScalarType } from 'graphql';\nimport type { IResolvers } from '@graphql-tools/utils';\nimport scalars from '../scalars';\nimport type { Scalar } from '../scalars/types';\n\nconst toGraphQlScalar = (scalar: Scalar) =>\n new GraphQLScalarType({\n name: scalar.name,\n description: scalar.description,\n parseValue: () => {},\n serialize(value: unknown) {\n return String(value); // unimportant\n },\n parseLiteral(ast: unknown) {\n return String(ast); // unimportant\n },\n });\n\nconst defaultResolvers: IResolvers = Object.fromEntries(Array.from(scalars).map(([name, scalar]) => [name, toGraphQlScalar(scalar)]));\n\nexport default defaultResolvers;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const scalars_1 =
|
|
4
|
+
const scalars_1 = tslib_1.__importDefault(require("../scalars"));
|
|
5
5
|
const scalarNames = Array.from(scalars_1.default.keys())
|
|
6
6
|
.map((scalarName) => `scalar ${scalarName}`)
|
|
7
7
|
.join('\n');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-built-in-scalars.js","sourceRoot":"","sources":["../../../lib/utils/inject-built-in-scalars.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"inject-built-in-scalars.js","sourceRoot":"","sources":["../../../lib/utils/inject-built-in-scalars.ts"],"names":[],"mappings":";;;AAAA,iEAAiC;AAEjC,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC;KACzC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,UAAU,EAAE,CAAC;KAC3C,IAAI,CAAC,IAAI,CAAC,CAAC;AAEhB,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAE,EAAE;IAC3C,OAAO;EACT,WAAW;;EAEX,KAAK,EAAE,CAAC;AACV,CAAC,CAAC;AAEF,kBAAe,oBAAoB,CAAC","sourcesContent":["import scalars from '../scalars';\n\nconst scalarNames = Array.from(scalars.keys())\n .map((scalarName) => `scalar ${scalarName}`)\n .join('\\n');\n\nconst injectBuiltInScalars = (query: string) => {\n return `\n${scalarNames}\n\n${query}`;\n};\n\nexport default injectBuiltInScalars;\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const providedTypes_1 =
|
|
5
|
-
const injcect_types_1 =
|
|
4
|
+
const providedTypes_1 = tslib_1.__importDefault(require("../providedTypes"));
|
|
5
|
+
const injcect_types_1 = tslib_1.__importDefault(require("./injcect-types"));
|
|
6
6
|
const injectProvidedTypes = (query) => (0, injcect_types_1.default)(query, providedTypes_1.default);
|
|
7
7
|
exports.default = injectProvidedTypes;
|
|
8
8
|
//# sourceMappingURL=inject-provided-types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-provided-types.js","sourceRoot":"","sources":["../../../lib/utils/inject-provided-types.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"inject-provided-types.js","sourceRoot":"","sources":["../../../lib/utils/inject-provided-types.ts"],"names":[],"mappings":";;;AAAA,6EAA6C;AAC7C,4EAA0C;AAE1C,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,IAAA,uBAAW,EAAC,KAAK,EAAE,uBAAa,CAAC,CAAC;AAEjF,kBAAe,mBAAmB,CAAC","sourcesContent":["import providedTypes from '../providedTypes';\nimport injectTypes from './injcect-types';\n\nconst injectProvidedTypes = (query: string) => injectTypes(query, providedTypes);\n\nexport default injectProvidedTypes;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const lodash_camelcase_1 =
|
|
4
|
+
const lodash_camelcase_1 = tslib_1.__importDefault(require("lodash.camelcase"));
|
|
5
5
|
const pascalCase = (str) => {
|
|
6
6
|
const camelCased = (0, lodash_camelcase_1.default)(str);
|
|
7
7
|
return camelCased.charAt(0).toUpperCase() + camelCased.slice(1);
|
|
@@ -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,gFAAyC;AAEzC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE;IAC/B,MAAM,UAAU,GAAG,IAAA,0BAAS,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"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serializeSchemaDocument = exports.SerializableDocument = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const SchemaDocument_1 =
|
|
5
|
+
const SchemaDocument_1 = tslib_1.__importDefault(require("./SchemaDocument"));
|
|
6
6
|
const schema_document_populator_1 = require("./schema-document-populator");
|
|
7
7
|
const create_schema_1 = require("./create-schema");
|
|
8
8
|
class SerializableDocument extends SchemaDocument_1.default {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-document-serializer.js","sourceRoot":"","sources":["../../../lib/utils/schema-document-serializer.ts"],"names":[],"mappings":";;;;AAEA,
|
|
1
|
+
{"version":3,"file":"schema-document-serializer.js","sourceRoot":"","sources":["../../../lib/utils/schema-document-serializer.ts"],"names":[],"mappings":";;;;AAEA,8EAA8C;AAC9C,2EAA+D;AAC/D,mDAAkD;AAuClD,MAAa,oBAAqB,SAAQ,wBAAc;IACpD,wBAAwB;QACpB,MAAM,qBAAqB,GAA4C,EAAE,CAAC;QAE1E,KAAK,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE;YAC7D,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC;YAEtD,qBAAqB,CAAC,GAAG,CAAC,GAAG;gBACzB,IAAI;gBACJ,WAAW;gBACX,wDAAwD;gBACxD,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC3E,WAAW;oBACX,IAAI;oBACJ,QAAQ;oBACR,IAAI,EAAE,UAAU;iBACnB,CAAC,CAAC;aACN,CAAC;SACL;QAED,OAAO,qBAAqB,CAAC;IACjC,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AI,CAAC,sBAAsB,EAAE;YACxC,UAAU,EAAE,IAAI,CAAC,uBAAuB,EAAE;YAC1C,OAAO,EAAE,IAAI,CAAC,oBAAoB,EAAE;SACvC,CAAC;IACN,CAAC;CACJ;AArED,oDAqEC;AAEM,MAAM,uBAAuB,GAAG,CAAC,cAAsB,EAAE,MAAc,EAAE,QAAgB,EAA6B,EAAE;IAC3H,IAAI;QACA,MAAM,cAAc,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAClD,IAAA,4CAAgB,EAAC,cAAc,EAAE,IAAA,+BAAe,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QAEpE,OAAO,cAAc,CAAC,SAAS,EAAE,CAAC;KACrC;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,CAAC,KAAK,CACT,0DAA0D,cAAc,wBAAwB,QAAQ,cAAc,CACzH,CAAC;QAEF,OAAO,IAAI,CAAC;KACf;AACL,CAAC,CAAC;AAbW,QAAA,uBAAuB,2BAalC","sourcesContent":["import type { Maybe } from 'graphql/jsutils/Maybe';\n\nimport SchemaDocument from './SchemaDocument';\nimport { populateDocument } from './schema-document-populator';\nimport { getSchemaObject } from './create-schema';\n\nexport type SerializedDocument = {\n objectTypes: { [key: string]: SerializedObjectType };\n scalars: { [key: string]: SerializedScalar };\n enumTypes: { [key: string]: SerializedEnumType };\n unionTypes: { [key: string]: SerializedUnionType };\n};\n\nexport type SerializedObjectTypeDescriptor = {\n description?: Maybe<string>;\n name: string;\n required: boolean;\n type: string;\n};\n\nexport type SerializedObjectType = {\n name: string;\n description?: Maybe<string>;\n descriptors: SerializedObjectTypeDescriptor[];\n};\n\nexport type SerializedScalar = {\n name: string;\n description?: Maybe<string>;\n};\n\nexport type SerializedEnumType = {\n name: string;\n description?: Maybe<string>;\n values: string[];\n};\n\nexport type SerializedUnionType = {\n name: string;\n description?: Maybe<string>;\n types: string[];\n};\n\nexport class SerializableDocument extends SchemaDocument {\n getSerializedObjectTypes() {\n const serializedObjectTypes: { [key: string]: SerializedObjectType } = {};\n\n for (const [key, objectType] of this.getObjectTypes().entries()) {\n const { name, description, descriptors } = objectType;\n\n serializedObjectTypes[key] = {\n name,\n description,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n descriptors: descriptors.map(({ description, name, required, typeString }) => ({\n description,\n name,\n required,\n type: typeString,\n })),\n };\n }\n\n return serializedObjectTypes;\n }\n\n getSerializedEnumTypes() {\n const enumTypes: { [key: string]: SerializedEnumType } = {};\n\n for (const enumType of this.getEnumTypes()) {\n const { name, description } = enumType;\n const values = enumType.getValues().map((val) => val.value);\n\n enumTypes[name] = { name, description, values };\n }\n\n return enumTypes;\n }\n\n getSerializedUnionTypes() {\n const unionTypes: { [key: string]: SerializedUnionType } = {};\n\n for (const unionType of this.getUnionTypes()) {\n const { name, description } = unionType;\n const types = unionType.getTypes().map((type) => type.name);\n\n unionTypes[name] = { name, description, types };\n }\n\n return unionTypes;\n }\n\n getSerializedScalars() {\n const scalars: { [key: string]: SerializedScalar } = {};\n\n for (const scalar of this.getScalars()) {\n const { name, description } = scalar;\n\n scalars[name] = { name, description };\n }\n\n return scalars;\n }\n\n serialize(): SerializedDocument {\n return {\n objectTypes: this.getSerializedObjectTypes(),\n enumTypes: this.getSerializedEnumTypes(),\n unionTypes: this.getSerializedUnionTypes(),\n scalars: this.getSerializedScalars(),\n };\n }\n}\n\nexport const serializeSchemaDocument = (extensionPoint: string, schema: string, baseType: string): SerializedDocument | null => {\n try {\n const schemaDocument = new SerializableDocument();\n populateDocument(schemaDocument, getSchemaObject(schema, baseType));\n\n return schemaDocument.serialize();\n } catch (error) {\n console.error(\n `Client-side Extension: the schema for extension point \"${extensionPoint}\" does not contain a ${baseType} definition.`,\n );\n\n return null;\n }\n};\n"]}
|
package/dist/cjs/utils/schema.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadSchema = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const fs_1 =
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
6
|
// eslint-disable-next-line import/prefer-default-export
|
|
7
7
|
const loadSchema = async (filePath) => {
|
|
8
8
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../lib/utils/schema.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../lib/utils/schema.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AAEpB,wDAAwD;AACjD,MAAM,UAAU,GAAG,KAAK,EAAE,QAAgB,EAAE,EAAE;IACjD,IAAI;QACA,MAAM,MAAM,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,EAAE;YACT,OAAO,CAAC,KAAK,CAAC,SAAS,QAAQ,qDAAqD,CAAC,CAAC;YACtF,OAAO,IAAI,CAAC;SACf;QAED,OAAO,MAAM,CAAC;KACjB;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,KAAK,CAAC,mBAAmB,QAAQ,IAAI,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;KACf;AACL,CAAC,CAAC;AAbW,QAAA,UAAU,cAarB","sourcesContent":["import fs from 'fs';\n\n// eslint-disable-next-line import/prefer-default-export\nexport const loadSchema = async (filePath: string) => {\n try {\n const schema = await fs.promises.readFile(filePath, 'utf8');\n if (!schema) {\n console.error(`File \"${filePath}\" does appear to contain any information. Skipping…`);\n return null;\n }\n\n return schema;\n } catch (e) {\n console.error(`Failed to read \"${filePath}\".`);\n return null;\n }\n};\n"]}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createValidator = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
|
-
const scalars_1 =
|
|
6
|
+
const scalars_1 = tslib_1.__importDefault(require("../scalars"));
|
|
7
7
|
const types_1 = require("../scalars/types");
|
|
8
8
|
const ast_utils_1 = require("./ast-utils");
|
|
9
9
|
const validator_checks_1 = require("./validator-checks");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator-generator.js","sourceRoot":"","sources":["../../../lib/utils/validator-generator.ts"],"names":[],"mappings":";;;;AACA,qCAA0F;AAE1F,sEAAiC;AACjC,4CAAmD;AAInD,2CAAoF;AACpF,yDAY4B;AAI5B,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE;IAClC,OAAO,YAAY,IAAI,EAAE,CAAC;AAC9B,CAAC,CAAC;AAEF,IAAI,OAAO,GAAG,CAAC,CAAC;AAChB,MAAM,gBAAgB,GAAG,GAAG,EAAE;IAC1B,OAAO,YAAY,OAAO,EAAE,EAAE,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,GAAG,EAAE;IAC5B,MAAM,IAAI,GAAG,oBAAoB,CAAC;IAClC,MAAM,EAAE,GAAG;QACP,IAAI;;;;;;;;;;;CAWX,CAAC;IACE,OAAO;QACH,EAAE;QACF,IAAI;KACP,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAEzE,MAAM,qBAAqB,GAAG,CAAC,IAAqB,EAAE,EAAE;IACpD,QAAQ,IAAI,EAAE;QACV,KAAK,uBAAe,CAAC,OAAO;YACxB,OAAO,IAAA,mCAAgB,GAAE,CAAC;QAC9B,KAAK,uBAAe,CAAC,QAAQ;YACzB,OAAO,IAAA,sCAAmB,GAAE,CAAC;QACjC,KAAK,uBAAe,CAAC,IAAI;YACrB,OAAO,IAAA,gCAAa,GAAE,CAAC;QAC3B,KAAK,uBAAe,CAAC,QAAQ;YACzB,OAAO,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AM,eAAe,GAAG,CAAC,cAA8B,EAAE,YAAoB,EAAE,OAA0B,EAAE,EAAE;IAChH,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,gDAAgD;IAChD,KAAK,MAAM,UAAU,IAAI,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE;QAC3E,2BAA2B,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;KAC7D;IAED,OAAO;;;;;;;;;;;;;;;;EAgBT,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;uDACqB,YAAY;;;MAG7D,YAAY,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;CAkB/B,CAAC;AACF,CAAC,CAAC;AA9CW,QAAA,eAAe,mBA8C1B","sourcesContent":["import type { GraphQLEnumType, GraphQLObjectType, GraphQLScalarType, GraphQLUnionType } from 'graphql';\nimport { isEnumType, isListType, isObjectType, isScalarType, isUnionType } from 'graphql';\n\nimport scalars from '../scalars';\nimport { ValidationTypes } from '../scalars/types';\n\nimport type SchemaDocument from './SchemaDocument';\nimport type { AcceptedTypes, FieldDescriptor, NonNullNonListType, ObjectType } from './ast-utils';\nimport { containsListType, isFirstRequired, isStackEndRequired } from './ast-utils';\nimport {\n arrayValidator,\n booleanValidator,\n constValueValidator,\n dateValidator,\n enumValidator,\n functionValidator,\n numberValidator,\n objectValidator,\n promiseValidator,\n regexpValidator,\n stringValidator,\n} from './validator-checks';\n\nimport type { ValidationOptions } from './validator-types';\n\nconst createFnName = (hint: string) => {\n return `validate_${hint}`;\n};\n\nlet counter = 0;\nconst createIterFnName = () => {\n return `validate_${counter++}`;\n};\n\nconst stringifyFormatter = () => {\n const name = 'stringifyFormatter';\n const fn = `\nconst ${name} = (_: unknown, value: unknown): string => {\n if (value === undefined) {\n return 'undefined';\n }\n\n if (typeof value === 'function') {\n return value.toString();\n }\n\n return value as string;\n};\n`;\n return {\n fn,\n name,\n };\n};\n\nconst toSafeAttribute = (attribute: string) => JSON.stringify(attribute);\n\nconst getValidatorForScalar = (type: ValidationTypes) => {\n switch (type) {\n case ValidationTypes.boolean:\n return booleanValidator();\n case ValidationTypes.constant:\n return constValueValidator();\n case ValidationTypes.date:\n return dateValidator();\n case ValidationTypes.function:\n return functionValidator();\n case ValidationTypes.number:\n return numberValidator();\n case ValidationTypes.promise:\n return promiseValidator();\n case ValidationTypes.regexp:\n return regexpValidator();\n case ValidationTypes.string:\n return stringValidator();\n default:\n throw new Error(`Unexpected validation type: \"${type}\". Validator generation failed.`);\n }\n};\n\nconst getScalarDefinitionFromName = (name: string) => {\n const scalar = scalars.has(name) && scalars.get(name);\n\n if (!scalar) {\n throw new Error(`Scalar with name: \"${name}\" was not registered. Validator generation failed.`);\n }\n\n return scalar;\n};\n\nconst getErrorMessageForAttribute = (fnStack: Set<string>, objectTypeName: string, attributeName: string, expectedType: string) => {\n const { name, fn } = stringifyFormatter();\n fnStack.add(fn);\n\n return (\n `'\"${objectTypeName}\" failed to validate. Attribute \"${attributeName}\" expected a value of type ${expectedType},` +\n ` but received: ' + JSON.stringify(subject[${JSON.stringify(attributeName)}], ${name})`\n );\n};\n\nconst getErrorMessageForValues = (fnStack: Set<string>, objectTypeName: string, attributeName: string, expectedValues: string[]) => {\n const { name, fn } = stringifyFormatter();\n fnStack.add(fn);\n const exceptedValuesString = expectedValues.map((val) => JSON.stringify(val)).join(', ');\n\n return (\n `'\"${objectTypeName}\" failed to validate. Attribute \"${attributeName}\" expected one of the following values: ${exceptedValuesString}.` +\n ` Received value: ' + JSON.stringify(subject[${JSON.stringify(attributeName)}], ${name})`\n );\n};\n\nconst ifAttributeExistsCheck = (attributeName: string) => {\n const safeAttributeName = toSafeAttribute(attributeName);\n return `${safeAttributeName} in subject && subject[${safeAttributeName}] !== null`;\n};\n\nconst createRequiredElse = (isRequired: boolean, objectTypeName: string, attributeName: string, type: string) => {\n if (!isRequired) {\n return '';\n }\n\n return `else {\n errors.push(errorFactory(errorPrefix, '\"${objectTypeName}\" failed to validate. Attribute \"${attributeName}\" of type ${type} is missing in \"${objectTypeName}\".'));\n}`;\n};\n\nconst conditionValidationScalar = (fnStack: Set<string>, scalar: GraphQLScalarType, runtimeVariable: string) => {\n const scalarDefinition = getScalarDefinitionFromName(scalar.name);\n const { fn, name } = getValidatorForScalar(scalarDefinition.validationType);\n\n fnStack.add(fn);\n\n // we have to treat constants different - as we compare rather than look at a value\n if (scalarDefinition.validationType === ValidationTypes.constant) {\n const { acceptedValue } = scalarDefinition;\n return `!${name}(${toSafeAttribute(acceptedValue as string)}, ${runtimeVariable})`;\n }\n\n return `!${name}(${runtimeVariable})`;\n};\n\nconst getEnumValues = (enumType: GraphQLEnumType) => enumType.getValues().map((value) => value.value);\n\nconst conditionValidationEnum = (fnStack: Set<string>, enumType: GraphQLEnumType, runtimeVariable: string) => {\n const { fn, name } = enumValidator();\n\n fnStack.add(fn);\n\n const acceptableValues = getEnumValues(enumType);\n return `!${name}(${JSON.stringify(acceptableValues)}, ${runtimeVariable})`;\n};\n\nconst getErrorPrefixForObjectType = (objectTypeName: string, attributeName: string) =>\n `\"${objectTypeName}\" failed on attribute \"${attributeName}\". `;\n\nconst callObjectTypeCheck = (fnName: string, errorPrefix: string, runtimeVariable: string, errorsVariables = 'errors') => {\n return `${fnName}(errorPrefix + '${errorPrefix}', ${runtimeVariable}, ${errorsVariables})`;\n};\n\nconst checkObjectType = (fnStack: Set<string>, objectTypeName: string, attributeName: string, objectTypeObject: GraphQLObjectType) => {\n return callObjectTypeCheck(\n createFnName(objectTypeObject.name),\n getErrorPrefixForObjectType(objectTypeName, attributeName),\n `subject[${toSafeAttribute(attributeName)}]`,\n );\n};\n\nconst conditionValidationObjectTypeObject = (fnStack: Set<string>, objectTypeObject: GraphQLObjectType, runtimeVariable: string) => {\n const errorsVariable = 'errorsOrWarnings';\n const objectTypeCheck = callObjectTypeCheck(createFnName(objectTypeObject.name), '', runtimeVariable, errorsVariable);\n\n return `\n (function() {\n const ${errorsVariable} = [];\n const errorPrefix = '';\n\n ${objectTypeCheck};\n\n const errors = ${errorsVariable}.filter(errorOrWarning => errorOrWarning.severity === ErrorLevels.ERROR);\n\n return errors.length !== 0;\n }())`;\n};\n\nconst conditionValidationUnion = (fnStack: Set<string>, unionType: GraphQLUnionType, runtimeVariable: string): string => {\n // built in typing does not reflect reality\n const typesOfUnion = unionType.getTypes() as unknown as NonNullNonListType[];\n\n const checks = typesOfUnion\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n .map((type) => getBaseTypeCondition(fnStack, type, runtimeVariable));\n\n return `${checks.join('&&')}`;\n};\n\nconst getBaseTypeCondition = (fnStack: Set<string>, type: NonNullNonListType | undefined, runtimeVariable: string) => {\n if (isScalarType(type)) {\n return conditionValidationScalar(fnStack, type, runtimeVariable);\n }\n\n if (isEnumType(type)) {\n return conditionValidationEnum(fnStack, type, runtimeVariable);\n }\n\n if (isObjectType(type)) {\n return conditionValidationObjectTypeObject(fnStack, type, runtimeVariable);\n }\n\n if (isUnionType(type)) {\n return conditionValidationUnion(fnStack, type, runtimeVariable);\n }\n\n throw new Error(`Unexpected base type: \"${type}\". No check generation possible. Validator generation failed.`);\n};\n\nconst ifCaseScalar = (fnStack: Set<string>, objectTypeName: string, attributeName: string, scalar: GraphQLScalarType) => {\n const runtimeVariable = `subject[${toSafeAttribute(attributeName)}]`;\n const condition = conditionValidationScalar(fnStack, scalar, runtimeVariable);\n\n return `\n if (${condition}) {\n errors.push(errorFactory(errorPrefix, ${getErrorMessageForAttribute(fnStack, objectTypeName, attributeName, scalar.name)}));\n }\n`;\n};\n\nconst ifCaseEnum = (fnStack: Set<string>, objectTypeName: string, attributeName: string, enumType: GraphQLEnumType) => {\n const runtimeVariable = `subject[${toSafeAttribute(attributeName)}]`;\n const condition = conditionValidationEnum(fnStack, enumType, runtimeVariable);\n\n return `\n if (${condition}) {\n errors.push(errorFactory(errorPrefix, ${getErrorMessageForValues(\n fnStack,\n objectTypeName,\n attributeName,\n getEnumValues(enumType),\n )}));\n }\n`;\n};\n\nconst checkUnionType = (fnStack: Set<string>, objectTypeName: string, attributeName: string, unionType: GraphQLUnionType): string => {\n // typing does not reflect reality\n const typesOfUnion = unionType.getTypes() as unknown as NonNullNonListType[];\n const typeString = typesOfUnion.map((type) => type.name).join(' | ');\n\n const condition = conditionValidationUnion(fnStack, unionType, `subject[${toSafeAttribute(attributeName)}]`);\n\n return `\n (function(){\n if (${condition}) {\n errors.push(errorFactory(errorPrefix, ${getErrorMessageForAttribute(fnStack, objectTypeName, attributeName, typeString)}));\n }\n }())\n`;\n};\n\nconst getBaseTypeCheck = (fnStack: Set<string>, objectTypeName: string, attributeName: string, type: NonNullNonListType) => {\n if (isScalarType(type)) {\n return ifCaseScalar(fnStack, objectTypeName, attributeName, type);\n }\n\n if (isEnumType(type)) {\n return ifCaseEnum(fnStack, objectTypeName, attributeName, type);\n }\n\n if (isObjectType(type)) {\n return checkObjectType(fnStack, objectTypeName, attributeName, type);\n }\n\n if (isUnionType(type)) {\n return checkUnionType(fnStack, objectTypeName, attributeName, type);\n }\n\n throw new Error(`Unexpected base type: \"${type}\". No check generation possible. Validator generation failed.`);\n};\n\nconst createIterationFn = (fnStack: Set<string>, isRequired: boolean, validateFn: string) => {\n const iterFnName = createIterFnName();\n const { name, fn } = arrayValidator();\n fnStack.add(fn);\n fnStack.add(`\nfunction ${iterFnName}(subject: any) {\n ${\n !isRequired\n ? `if (subject === null) {\n return true;\n }`\n : ''\n }\n if(!${name}(subject)) {\n return false;\n }\n\n\n return subject.every( elem => ${validateFn}(elem));\n}\n`);\n return iterFnName;\n};\n\nconst reverseCreateStackValidator = (fnStack: Set<string>, typeStack: AcceptedTypes[], prevValidatorFn?: string): string => {\n if (typeStack.length === 0 && prevValidatorFn) {\n return prevValidatorFn;\n }\n\n const isRequired = isStackEndRequired(typeStack);\n const type = typeStack.pop();\n if (isRequired) {\n typeStack.pop();\n }\n if (!isListType(type)) {\n const validatorCondition = getBaseTypeCondition(fnStack, type, 'subject');\n const validatorNullCheck = isRequired ? '' : 'subject === null || ';\n const validatorFnName = createIterFnName();\n const validatorFnBody = `function ${validatorFnName}(subject: unknown){return ${validatorNullCheck}!(${validatorCondition})}`;\n fnStack.add(validatorFnBody);\n\n return reverseCreateStackValidator(fnStack, typeStack, validatorFnName);\n }\n\n // we have a list\n if (!prevValidatorFn) {\n throw new Error('missing validator fn to call');\n }\n\n const iteratorFnName = createIterationFn(fnStack, isRequired, prevValidatorFn);\n\n return reverseCreateStackValidator(fnStack, typeStack, iteratorFnName);\n};\n\nconst getListCheck = (fnStack: Set<string>, objectTypeName: string, descriptor: FieldDescriptor) => {\n const stackValidatorName = reverseCreateStackValidator(fnStack, descriptor.typeStack);\n return `if (!${stackValidatorName}(subject[${JSON.stringify(descriptor.name)}])) {\n errors.push(errorFactory(errorPrefix, ${getErrorMessageForAttribute(\n fnStack,\n objectTypeName,\n descriptor.name,\n descriptor.typeString,\n )}));\n }\n`;\n};\n\nconst getInnerCheck = (fnStack: Set<string>, objectTypeName: string, descriptor: FieldDescriptor) => {\n const containsList = containsListType(descriptor.typeStack);\n\n // nothing special to do\n if (!containsList) {\n return getBaseTypeCheck(fnStack, objectTypeName, descriptor.name, descriptor.baseType.reference);\n }\n\n return getListCheck(fnStack, objectTypeName, descriptor);\n};\n\nconst getExcessiveKeysCheck = (objectType: ObjectType, options: ValidationOptions) => {\n if (!options.checkExcessiveKeys) {\n return null;\n }\n\n const errorFactoryFn = options.strictMode === true ? 'errorFactory' : 'warningFactory';\n\n const keys = objectType.descriptors.map((descriptor) => descriptor.name);\n return `\nconst expectedKeys = ${JSON.stringify(keys)};\nconst excessiveKeys = Object.keys(subject).filter(key => !expectedKeys.includes(key))\nif (excessiveKeys.length) {\n errors.push(${errorFactoryFn}(errorPrefix, '\"${\n objectType.name\n }\". Excessive key' + (excessiveKeys.length === 1 ? '':'s') + ' [' + excessiveKeys.join(', ') + '] ' + (excessiveKeys.length === 1 ? 'is':'are') + ' not specified in the schema.'));\n}\n\n`;\n};\n\nconst generateObjectTypeValidator = (fnStack: Set<string>, objectType: ObjectType, options: ValidationOptions) => {\n const { name, fn } = objectValidator();\n fnStack.add(fn);\n\n const excessiveKeyValidation = getExcessiveKeysCheck(objectType, options);\n\n const attributeValidation = objectType.descriptors\n .map((descriptor) => {\n // e.g. foo: Number! (then the first element in the stack will be required type)\n const isRequired = isFirstRequired(descriptor.typeStack);\n\n const outerIfCondition = ifAttributeExistsCheck(descriptor.name);\n const outerElseStatement = createRequiredElse(isRequired, objectType.name, descriptor.name, descriptor.typeString);\n\n const baseTypeCheck = getInnerCheck(fnStack, objectType.name, descriptor);\n\n return `\nif (${outerIfCondition}) {\n ${baseTypeCheck}\n} ${outerElseStatement}\n`;\n })\n .join('\\n\\n');\n\n const objectTypeValidationFnName = createFnName(objectType.name);\n const objectTypeValidationFunction = `\nfunction ${objectTypeValidationFnName}(errorPrefix: string, subject: any, errors: ValidationErrorsAndWarnings[]) {\n if(!${name}(subject)) {\n errors.push(\n errorFactory(errorPrefix, '\"${objectType.name}\" failed to validate. Expected an object of type \"${objectType.name}\".'\n ));\n return;\n }\n ${excessiveKeyValidation}\n ${attributeValidation}\n}\n`;\n fnStack.add(objectTypeValidationFunction);\n};\n\n// eslint-disable-next-line import/prefer-default-export\nexport const createValidator = (schemaDocument: SchemaDocument, baseTypeName: string, options: ValidationOptions) => {\n const fnStack = new Set<string>();\n // eslint-disable-next-line no-restricted-syntax\n for (const objectType of Array.from(schemaDocument.getObjectTypes().values())) {\n generateObjectTypeValidator(fnStack, objectType, options);\n }\n\n return `\nimport { ErrorLevels } from '@atlassian/clientside-extensions-schema';\nimport type { Validator, ValidationResult, ValidationError, ValidationWarning } from '@atlassian/clientside-extensions-schema';\n\ntype ValidationErrorsAndWarnings = ValidationError | ValidationWarning;\n\nconst errorFactory = (errorPrefix: string, error: string): ValidationError => ({\n severity: ErrorLevels.ERROR,\n error: errorPrefix + error,\n});\n\nconst warningFactory = (errorPrefix: string, error: string): ValidationWarning => ({\n severity: ErrorLevels.WARNING,\n warning: errorPrefix + error,\n});\n\n${Array.from(fnStack).join('\\n\\n')}\nexport const validate: Validator = function validator${baseTypeName}(subject: unknown): ValidationResult {\n const errorsAndWarnings: ValidationErrorsAndWarnings[] = [];\n\n ${createFnName(baseTypeName)}('', subject, errorsAndWarnings);\n\n const errors: ValidationError[] = [];\n const warnings: ValidationWarning[] = [];\n\n for (const errorOrWarning of errorsAndWarnings) {\n if (errorOrWarning.severity === ErrorLevels.ERROR) {\n errors.push(errorOrWarning);\n } else if (errorOrWarning.severity === ErrorLevels.WARNING) {\n warnings.push(errorOrWarning);\n }\n }\n\n return {\n errors,\n warnings,\n };\n}\n`;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"validator-generator.js","sourceRoot":"","sources":["../../../lib/utils/validator-generator.ts"],"names":[],"mappings":";;;;AACA,qCAA0F;AAE1F,iEAAiC;AACjC,4CAAmD;AAInD,2CAAoF;AACpF,yDAY4B;AAI5B,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE;IAClC,OAAO,YAAY,IAAI,EAAE,CAAC;AAC9B,CAAC,CAAC;AAEF,IAAI,OAAO,GAAG,CAAC,CAAC;AAChB,MAAM,gBAAgB,GAAG,GAAG,EAAE;IAC1B,OAAO,YAAY,OAAO,EAAE,EAAE,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,GAAG,EAAE;IAC5B,MAAM,IAAI,GAAG,oBAAoB,CAAC;IAClC,MAAM,EAAE,GAAG;QACP,IAAI;;;;;;;;;;;CAWX,CAAC;IACE,OAAO;QACH,EAAE;QACF,IAAI;KACP,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAEzE,MAAM,qBAAqB,GAAG,CAAC,IAAqB,EAAE,E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,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACjE,MAAM,4BAA4B,GAAG;WAC9B,0BAA0B;UAC3B,IAAI;;0CAE4B,UAAU,CAAC,IAAI,qDAAqD,UAAU,CAAC,IAAI;;;;MAIvH,sBAAsB;MACtB,mBAAmB;;CAExB,CAAC;IACE,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF,wDAAwD;AACjD,MAAM,eAAe,GAAG,CAAC,cAA8B,EAAE,YAAoB,EAAE,OAA0B,EAAE,EAAE;IAChH,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,gDAAgD;IAChD,KAAK,MAAM,UAAU,IAAI,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE;QAC3E,2BAA2B,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;KAC7D;IAED,OAAO;;;;;;;;;;;;;;;;EAgBT,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;uDACqB,YAAY;;;MAG7D,YAAY,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;CAkB/B,CAAC;AACF,CAAC,CAAC;AA9CW,QAAA,eAAe,mBA8C1B","sourcesContent":["import type { GraphQLEnumType, GraphQLObjectType, GraphQLScalarType, GraphQLUnionType } from 'graphql';\nimport { isEnumType, isListType, isObjectType, isScalarType, isUnionType } from 'graphql';\n\nimport scalars from '../scalars';\nimport { ValidationTypes } from '../scalars/types';\n\nimport type SchemaDocument from './SchemaDocument';\nimport type { AcceptedTypes, FieldDescriptor, NonNullNonListType, ObjectType } from './ast-utils';\nimport { containsListType, isFirstRequired, isStackEndRequired } from './ast-utils';\nimport {\n arrayValidator,\n booleanValidator,\n constValueValidator,\n dateValidator,\n enumValidator,\n functionValidator,\n numberValidator,\n objectValidator,\n promiseValidator,\n regexpValidator,\n stringValidator,\n} from './validator-checks';\n\nimport type { ValidationOptions } from './validator-types';\n\nconst createFnName = (hint: string) => {\n return `validate_${hint}`;\n};\n\nlet counter = 0;\nconst createIterFnName = () => {\n return `validate_${counter++}`;\n};\n\nconst stringifyFormatter = () => {\n const name = 'stringifyFormatter';\n const fn = `\nconst ${name} = (_: unknown, value: unknown): string => {\n if (value === undefined) {\n return 'undefined';\n }\n\n if (typeof value === 'function') {\n return value.toString();\n }\n\n return value as string;\n};\n`;\n return {\n fn,\n name,\n };\n};\n\nconst toSafeAttribute = (attribute: string) => JSON.stringify(attribute);\n\nconst getValidatorForScalar = (type: ValidationTypes) => {\n switch (type) {\n case ValidationTypes.boolean:\n return booleanValidator();\n case ValidationTypes.constant:\n return constValueValidator();\n case ValidationTypes.date:\n return dateValidator();\n case ValidationTypes.function:\n return functionValidator();\n case ValidationTypes.number:\n return numberValidator();\n case ValidationTypes.promise:\n return promiseValidator();\n case ValidationTypes.regexp:\n return regexpValidator();\n case ValidationTypes.string:\n return stringValidator();\n default:\n throw new Error(`Unexpected validation type: \"${type}\". Validator generation failed.`);\n }\n};\n\nconst getScalarDefinitionFromName = (name: string) => {\n const scalar = scalars.has(name) && scalars.get(name);\n\n if (!scalar) {\n throw new Error(`Scalar with name: \"${name}\" was not registered. Validator generation failed.`);\n }\n\n return scalar;\n};\n\nconst getErrorMessageForAttribute = (fnStack: Set<string>, objectTypeName: string, attributeName: string, expectedType: string) => {\n const { name, fn } = stringifyFormatter();\n fnStack.add(fn);\n\n return (\n `'\"${objectTypeName}\" failed to validate. Attribute \"${attributeName}\" expected a value of type ${expectedType},` +\n ` but received: ' + JSON.stringify(subject[${JSON.stringify(attributeName)}], ${name})`\n );\n};\n\nconst getErrorMessageForValues = (fnStack: Set<string>, objectTypeName: string, attributeName: string, expectedValues: string[]) => {\n const { name, fn } = stringifyFormatter();\n fnStack.add(fn);\n const exceptedValuesString = expectedValues.map((val) => JSON.stringify(val)).join(', ');\n\n return (\n `'\"${objectTypeName}\" failed to validate. Attribute \"${attributeName}\" expected one of the following values: ${exceptedValuesString}.` +\n ` Received value: ' + JSON.stringify(subject[${JSON.stringify(attributeName)}], ${name})`\n );\n};\n\nconst ifAttributeExistsCheck = (attributeName: string) => {\n const safeAttributeName = toSafeAttribute(attributeName);\n return `${safeAttributeName} in subject && subject[${safeAttributeName}] !== null`;\n};\n\nconst createRequiredElse = (isRequired: boolean, objectTypeName: string, attributeName: string, type: string) => {\n if (!isRequired) {\n return '';\n }\n\n return `else {\n errors.push(errorFactory(errorPrefix, '\"${objectTypeName}\" failed to validate. Attribute \"${attributeName}\" of type ${type} is missing in \"${objectTypeName}\".'));\n}`;\n};\n\nconst conditionValidationScalar = (fnStack: Set<string>, scalar: GraphQLScalarType, runtimeVariable: string) => {\n const scalarDefinition = getScalarDefinitionFromName(scalar.name);\n const { fn, name } = getValidatorForScalar(scalarDefinition.validationType);\n\n fnStack.add(fn);\n\n // we have to treat constants different - as we compare rather than look at a value\n if (scalarDefinition.validationType === ValidationTypes.constant) {\n const { acceptedValue } = scalarDefinition;\n return `!${name}(${toSafeAttribute(acceptedValue as string)}, ${runtimeVariable})`;\n }\n\n return `!${name}(${runtimeVariable})`;\n};\n\nconst getEnumValues = (enumType: GraphQLEnumType) => enumType.getValues().map((value) => value.value);\n\nconst conditionValidationEnum = (fnStack: Set<string>, enumType: GraphQLEnumType, runtimeVariable: string) => {\n const { fn, name } = enumValidator();\n\n fnStack.add(fn);\n\n const acceptableValues = getEnumValues(enumType);\n return `!${name}(${JSON.stringify(acceptableValues)}, ${runtimeVariable})`;\n};\n\nconst getErrorPrefixForObjectType = (objectTypeName: string, attributeName: string) =>\n `\"${objectTypeName}\" failed on attribute \"${attributeName}\". `;\n\nconst callObjectTypeCheck = (fnName: string, errorPrefix: string, runtimeVariable: string, errorsVariables = 'errors') => {\n return `${fnName}(errorPrefix + '${errorPrefix}', ${runtimeVariable}, ${errorsVariables})`;\n};\n\nconst checkObjectType = (fnStack: Set<string>, objectTypeName: string, attributeName: string, objectTypeObject: GraphQLObjectType) => {\n return callObjectTypeCheck(\n createFnName(objectTypeObject.name),\n getErrorPrefixForObjectType(objectTypeName, attributeName),\n `subject[${toSafeAttribute(attributeName)}]`,\n );\n};\n\nconst conditionValidationObjectTypeObject = (fnStack: Set<string>, objectTypeObject: GraphQLObjectType, runtimeVariable: string) => {\n const errorsVariable = 'errorsOrWarnings';\n const objectTypeCheck = callObjectTypeCheck(createFnName(objectTypeObject.name), '', runtimeVariable, errorsVariable);\n\n return `\n (function() {\n const ${errorsVariable} = [];\n const errorPrefix = '';\n\n ${objectTypeCheck};\n\n const errors = ${errorsVariable}.filter(errorOrWarning => errorOrWarning.severity === ErrorLevels.ERROR);\n\n return errors.length !== 0;\n }())`;\n};\n\nconst conditionValidationUnion = (fnStack: Set<string>, unionType: GraphQLUnionType, runtimeVariable: string): string => {\n // built in typing does not reflect reality\n const typesOfUnion = unionType.getTypes() as unknown as NonNullNonListType[];\n\n const checks = typesOfUnion\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n .map((type) => getBaseTypeCondition(fnStack, type, runtimeVariable));\n\n return `${checks.join('&&')}`;\n};\n\nconst getBaseTypeCondition = (fnStack: Set<string>, type: NonNullNonListType | undefined, runtimeVariable: string) => {\n if (isScalarType(type)) {\n return conditionValidationScalar(fnStack, type, runtimeVariable);\n }\n\n if (isEnumType(type)) {\n return conditionValidationEnum(fnStack, type, runtimeVariable);\n }\n\n if (isObjectType(type)) {\n return conditionValidationObjectTypeObject(fnStack, type, runtimeVariable);\n }\n\n if (isUnionType(type)) {\n return conditionValidationUnion(fnStack, type, runtimeVariable);\n }\n\n throw new Error(`Unexpected base type: \"${type}\". No check generation possible. Validator generation failed.`);\n};\n\nconst ifCaseScalar = (fnStack: Set<string>, objectTypeName: string, attributeName: string, scalar: GraphQLScalarType) => {\n const runtimeVariable = `subject[${toSafeAttribute(attributeName)}]`;\n const condition = conditionValidationScalar(fnStack, scalar, runtimeVariable);\n\n return `\n if (${condition}) {\n errors.push(errorFactory(errorPrefix, ${getErrorMessageForAttribute(fnStack, objectTypeName, attributeName, scalar.name)}));\n }\n`;\n};\n\nconst ifCaseEnum = (fnStack: Set<string>, objectTypeName: string, attributeName: string, enumType: GraphQLEnumType) => {\n const runtimeVariable = `subject[${toSafeAttribute(attributeName)}]`;\n const condition = conditionValidationEnum(fnStack, enumType, runtimeVariable);\n\n return `\n if (${condition}) {\n errors.push(errorFactory(errorPrefix, ${getErrorMessageForValues(\n fnStack,\n objectTypeName,\n attributeName,\n getEnumValues(enumType),\n )}));\n }\n`;\n};\n\nconst checkUnionType = (fnStack: Set<string>, objectTypeName: string, attributeName: string, unionType: GraphQLUnionType): string => {\n // typing does not reflect reality\n const typesOfUnion = unionType.getTypes() as unknown as NonNullNonListType[];\n const typeString = typesOfUnion.map((type) => type.name).join(' | ');\n\n const condition = conditionValidationUnion(fnStack, unionType, `subject[${toSafeAttribute(attributeName)}]`);\n\n return `\n (function(){\n if (${condition}) {\n errors.push(errorFactory(errorPrefix, ${getErrorMessageForAttribute(fnStack, objectTypeName, attributeName, typeString)}));\n }\n }())\n`;\n};\n\nconst getBaseTypeCheck = (fnStack: Set<string>, objectTypeName: string, attributeName: string, type: NonNullNonListType) => {\n if (isScalarType(type)) {\n return ifCaseScalar(fnStack, objectTypeName, attributeName, type);\n }\n\n if (isEnumType(type)) {\n return ifCaseEnum(fnStack, objectTypeName, attributeName, type);\n }\n\n if (isObjectType(type)) {\n return checkObjectType(fnStack, objectTypeName, attributeName, type);\n }\n\n if (isUnionType(type)) {\n return checkUnionType(fnStack, objectTypeName, attributeName, type);\n }\n\n throw new Error(`Unexpected base type: \"${type}\". No check generation possible. Validator generation failed.`);\n};\n\nconst createIterationFn = (fnStack: Set<string>, isRequired: boolean, validateFn: string) => {\n const iterFnName = createIterFnName();\n const { name, fn } = arrayValidator();\n fnStack.add(fn);\n fnStack.add(`\nfunction ${iterFnName}(subject: any) {\n ${\n !isRequired\n ? `if (subject === null) {\n return true;\n }`\n : ''\n }\n if(!${name}(subject)) {\n return false;\n }\n\n\n return subject.every( elem => ${validateFn}(elem));\n}\n`);\n return iterFnName;\n};\n\nconst reverseCreateStackValidator = (fnStack: Set<string>, typeStack: AcceptedTypes[], prevValidatorFn?: string): string => {\n if (typeStack.length === 0 && prevValidatorFn) {\n return prevValidatorFn;\n }\n\n const isRequired = isStackEndRequired(typeStack);\n const type = typeStack.pop();\n if (isRequired) {\n typeStack.pop();\n }\n if (!isListType(type)) {\n const validatorCondition = getBaseTypeCondition(fnStack, type, 'subject');\n const validatorNullCheck = isRequired ? '' : 'subject === null || ';\n const validatorFnName = createIterFnName();\n const validatorFnBody = `function ${validatorFnName}(subject: unknown){return ${validatorNullCheck}!(${validatorCondition})}`;\n fnStack.add(validatorFnBody);\n\n return reverseCreateStackValidator(fnStack, typeStack, validatorFnName);\n }\n\n // we have a list\n if (!prevValidatorFn) {\n throw new Error('missing validator fn to call');\n }\n\n const iteratorFnName = createIterationFn(fnStack, isRequired, prevValidatorFn);\n\n return reverseCreateStackValidator(fnStack, typeStack, iteratorFnName);\n};\n\nconst getListCheck = (fnStack: Set<string>, objectTypeName: string, descriptor: FieldDescriptor) => {\n const stackValidatorName = reverseCreateStackValidator(fnStack, descriptor.typeStack);\n return `if (!${stackValidatorName}(subject[${JSON.stringify(descriptor.name)}])) {\n errors.push(errorFactory(errorPrefix, ${getErrorMessageForAttribute(\n fnStack,\n objectTypeName,\n descriptor.name,\n descriptor.typeString,\n )}));\n }\n`;\n};\n\nconst getInnerCheck = (fnStack: Set<string>, objectTypeName: string, descriptor: FieldDescriptor) => {\n const containsList = containsListType(descriptor.typeStack);\n\n // nothing special to do\n if (!containsList) {\n return getBaseTypeCheck(fnStack, objectTypeName, descriptor.name, descriptor.baseType.reference);\n }\n\n return getListCheck(fnStack, objectTypeName, descriptor);\n};\n\nconst getExcessiveKeysCheck = (objectType: ObjectType, options: ValidationOptions) => {\n if (!options.checkExcessiveKeys) {\n return null;\n }\n\n const errorFactoryFn = options.strictMode === true ? 'errorFactory' : 'warningFactory';\n\n const keys = objectType.descriptors.map((descriptor) => descriptor.name);\n return `\nconst expectedKeys = ${JSON.stringify(keys)};\nconst excessiveKeys = Object.keys(subject).filter(key => !expectedKeys.includes(key))\nif (excessiveKeys.length) {\n errors.push(${errorFactoryFn}(errorPrefix, '\"${\n objectType.name\n }\". Excessive key' + (excessiveKeys.length === 1 ? '':'s') + ' [' + excessiveKeys.join(', ') + '] ' + (excessiveKeys.length === 1 ? 'is':'are') + ' not specified in the schema.'));\n}\n\n`;\n};\n\nconst generateObjectTypeValidator = (fnStack: Set<string>, objectType: ObjectType, options: ValidationOptions) => {\n const { name, fn } = objectValidator();\n fnStack.add(fn);\n\n const excessiveKeyValidation = getExcessiveKeysCheck(objectType, options);\n\n const attributeValidation = objectType.descriptors\n .map((descriptor) => {\n // e.g. foo: Number! (then the first element in the stack will be required type)\n const isRequired = isFirstRequired(descriptor.typeStack);\n\n const outerIfCondition = ifAttributeExistsCheck(descriptor.name);\n const outerElseStatement = createRequiredElse(isRequired, objectType.name, descriptor.name, descriptor.typeString);\n\n const baseTypeCheck = getInnerCheck(fnStack, objectType.name, descriptor);\n\n return `\nif (${outerIfCondition}) {\n ${baseTypeCheck}\n} ${outerElseStatement}\n`;\n })\n .join('\\n\\n');\n\n const objectTypeValidationFnName = createFnName(objectType.name);\n const objectTypeValidationFunction = `\nfunction ${objectTypeValidationFnName}(errorPrefix: string, subject: any, errors: ValidationErrorsAndWarnings[]) {\n if(!${name}(subject)) {\n errors.push(\n errorFactory(errorPrefix, '\"${objectType.name}\" failed to validate. Expected an object of type \"${objectType.name}\".'\n ));\n return;\n }\n ${excessiveKeyValidation}\n ${attributeValidation}\n}\n`;\n fnStack.add(objectTypeValidationFunction);\n};\n\n// eslint-disable-next-line import/prefer-default-export\nexport const createValidator = (schemaDocument: SchemaDocument, baseTypeName: string, options: ValidationOptions) => {\n const fnStack = new Set<string>();\n // eslint-disable-next-line no-restricted-syntax\n for (const objectType of Array.from(schemaDocument.getObjectTypes().values())) {\n generateObjectTypeValidator(fnStack, objectType, options);\n }\n\n return `\nimport { ErrorLevels } from '@atlassian/clientside-extensions-schema';\nimport type { Validator, ValidationResult, ValidationError, ValidationWarning } from '@atlassian/clientside-extensions-schema';\n\ntype ValidationErrorsAndWarnings = ValidationError | ValidationWarning;\n\nconst errorFactory = (errorPrefix: string, error: string): ValidationError => ({\n severity: ErrorLevels.ERROR,\n error: errorPrefix + error,\n});\n\nconst warningFactory = (errorPrefix: string, error: string): ValidationWarning => ({\n severity: ErrorLevels.WARNING,\n warning: errorPrefix + error,\n});\n\n${Array.from(fnStack).join('\\n\\n')}\nexport const validate: Validator = function validator${baseTypeName}(subject: unknown): ValidationResult {\n const errorsAndWarnings: ValidationErrorsAndWarnings[] = [];\n\n ${createFnName(baseTypeName)}('', subject, errorsAndWarnings);\n\n const errors: ValidationError[] = [];\n const warnings: ValidationWarning[] = [];\n\n for (const errorOrWarning of errorsAndWarnings) {\n if (errorOrWarning.severity === ErrorLevels.ERROR) {\n errors.push(errorOrWarning);\n } else if (errorOrWarning.severity === ErrorLevels.WARNING) {\n warnings.push(errorOrWarning);\n }\n }\n\n return {\n errors,\n warnings,\n };\n}\n`;\n};\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type FileWriter = (baseFilename: string, typescriptCode: string, javascriptCode: string) => Promise<string | null>;
|
|
2
2
|
export interface GeneratorOptions {
|
|
3
3
|
providedTypesPaths: string[];
|
|
4
4
|
strictMode: boolean;
|
|
5
5
|
validatorOnly: boolean;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
type GeneratedReturnType = [extensionPoint: string, generatedTsCdode: string, generatedJsCode: string];
|
|
8
|
+
type ReturnWithoutWrite<WriteBaseT extends boolean> = WriteBaseT extends true ? void : GeneratedReturnType;
|
|
9
9
|
declare function generateCode<WriteBaseT extends boolean>(schema: string, options: Partial<GeneratorOptions>, fileWriter: FileWriter, writeBase: WriteBaseT): Promise<ReturnWithoutWrite<WriteBaseT>>;
|
|
10
10
|
export default generateCode;
|
|
11
11
|
//# sourceMappingURL=code-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-generator.d.ts","sourceRoot":"","sources":["../../../lib/code-generator/code-generator.ts"],"names":[],"mappings":"AAoGA,
|
|
1
|
+
{"version":3,"file":"code-generator.d.ts","sourceRoot":"","sources":["../../../lib/code-generator/code-generator.ts"],"names":[],"mappings":"AAoGA,MAAM,MAAM,UAAU,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE1H,MAAM,WAAW,gBAAgB;IAC7B,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;CAC1B;AAmBD,KAAK,mBAAmB,GAAG,CAAC,cAAc,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;AAEvG,KAAK,kBAAkB,CAAC,UAAU,SAAS,OAAO,IAAI,UAAU,SAAS,IAAI,GAAG,IAAI,GAAG,mBAAmB,CAAC;AAE3G,iBAAe,YAAY,CAAC,UAAU,SAAS,OAAO,EAClD,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAClC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,UAAU,GACtB,OAAO,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAuDzC;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OptionObject, getOptions } from 'loader-utils';
|
|
2
|
-
export
|
|
2
|
+
export type LoaderOptions = {
|
|
3
3
|
readonly providedTypes?: string;
|
|
4
4
|
readonly strictMode?: boolean;
|
|
5
5
|
readonly cwd?: string;
|
|
@@ -7,6 +7,6 @@ export declare type LoaderOptions = {
|
|
|
7
7
|
export interface QueryObject extends OptionObject {
|
|
8
8
|
readonly subfile: string;
|
|
9
9
|
}
|
|
10
|
-
export
|
|
11
|
-
export
|
|
10
|
+
export type LoaderContext = Parameters<typeof getOptions>[0];
|
|
11
|
+
export type LoaderCallback = LoaderContext['callback'];
|
|
12
12
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/loader/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE7D,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/loader/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG;IACxB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLOutputType, GraphQLType } from 'graphql';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type NonNullNonListType = Exclude<GraphQLOutputType, GraphQLList<GraphQLOutputType> | GraphQLNonNull<GraphQLOutputType>>;
|
|
3
|
+
export type AcceptedTypes = GraphQLOutputType;
|
|
4
4
|
export declare const isListOrNonNullType: (typeObject: GraphQLType) => typeObject is GraphQLList<GraphQLType> | GraphQLNonNull<GraphQLType>;
|
|
5
5
|
export declare const getTypeStack: (typeObject: AcceptedTypes) => AcceptedTypes[];
|
|
6
6
|
export declare const getBaseType: (typeObject: AcceptedTypes) => NonNullNonListType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-utils.d.ts","sourceRoot":"","sources":["../../../lib/utils/ast-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGR,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACd,MAAM,SAAS,CAAC;AAKjB,
|
|
1
|
+
{"version":3,"file":"ast-utils.d.ts","sourceRoot":"","sources":["../../../lib/utils/ast-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGR,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACd,MAAM,SAAS,CAAC;AAKjB,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,EAAE,WAAW,CAAC,iBAAiB,CAAC,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAChI,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAE9C,eAAO,MAAM,mBAAmB,eAAgB,WAAW,yEAE1D,CAAC;AAEF,eAAO,MAAM,YAAY,eAAgB,aAAa,KAAG,aAAa,EAUrE,CAAC;AAEF,eAAO,MAAM,WAAW,eAAgB,aAAa,uBAEpD,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,aAAa,EAAE,YAEzD,CAAC;AAEF,eAAO,MAAM,kBAAkB,cAAe,aAAa,EAAE,YAK5D,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAe,aAAa,EAAE,KAAG,OAE7D,CAAC;AAEF,oBAAY,QAAQ;IAChB,MAAM,IAAA;IACN,KAAK,IAAA;IACL,IAAI,IAAA;IACJ,MAAM,IAAA;CACT;AAED,eAAO,MAAM,eAAe,aAAc,kBAAkB,aAkB3D,CAAC;AASF,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,kBAAkB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACjC,WAAW,EAAE,eAAe,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,kBAAkB,CAAC;CAChC;AAwBD,eAAO,MAAM,wBAAwB,eAAgB,iBAAiB,KAAG,UAUxE,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Maybe } from 'graphql/jsutils/Maybe';
|
|
2
2
|
import SchemaDocument from './SchemaDocument';
|
|
3
|
-
export
|
|
3
|
+
export type SerializedDocument = {
|
|
4
4
|
objectTypes: {
|
|
5
5
|
[key: string]: SerializedObjectType;
|
|
6
6
|
};
|
|
@@ -14,27 +14,27 @@ export declare type SerializedDocument = {
|
|
|
14
14
|
[key: string]: SerializedUnionType;
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export type SerializedObjectTypeDescriptor = {
|
|
18
18
|
description?: Maybe<string>;
|
|
19
19
|
name: string;
|
|
20
20
|
required: boolean;
|
|
21
21
|
type: string;
|
|
22
22
|
};
|
|
23
|
-
export
|
|
23
|
+
export type SerializedObjectType = {
|
|
24
24
|
name: string;
|
|
25
25
|
description?: Maybe<string>;
|
|
26
26
|
descriptors: SerializedObjectTypeDescriptor[];
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export type SerializedScalar = {
|
|
29
29
|
name: string;
|
|
30
30
|
description?: Maybe<string>;
|
|
31
31
|
};
|
|
32
|
-
export
|
|
32
|
+
export type SerializedEnumType = {
|
|
33
33
|
name: string;
|
|
34
34
|
description?: Maybe<string>;
|
|
35
35
|
values: string[];
|
|
36
36
|
};
|
|
37
|
-
export
|
|
37
|
+
export type SerializedUnionType = {
|
|
38
38
|
name: string;
|
|
39
39
|
description?: Maybe<string>;
|
|
40
40
|
types: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-document-serializer.d.ts","sourceRoot":"","sources":["../../../lib/utils/schema-document-serializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAI9C,
|
|
1
|
+
{"version":3,"file":"schema-document-serializer.d.ts","sourceRoot":"","sources":["../../../lib/utils/schema-document-serializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAI9C,MAAM,MAAM,kBAAkB,GAAG;IAC7B,WAAW,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB,CAAA;KAAE,CAAC;IACrD,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAA;KAAE,CAAC;IAC7C,SAAS,EAAE;QAAE,CAAC,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
1
|
-
export
|
|
1
|
+
export type ValidationOptions = {
|
|
2
2
|
checkExcessiveKeys: boolean;
|
|
3
3
|
strictMode: boolean;
|
|
4
4
|
};
|
|
@@ -18,5 +18,5 @@ export interface ValidationResult {
|
|
|
18
18
|
warnings: ValidationWarning[];
|
|
19
19
|
errors: ValidationError[];
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export type Validator = (input?: unknown) => ValidationResult;
|
|
22
22
|
//# sourceMappingURL=validator-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator-types.d.ts","sourceRoot":"","sources":["../../../lib/utils/validator-types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"validator-types.d.ts","sourceRoot":"","sources":["../../../lib/utils/validator-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC5B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,oBAAY,WAAW;IACnB,KAAK,UAAU;IACf,OAAO,YAAY;CACtB;AAED,MAAM,WAAW,eAAe;IAC5B,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,MAAM,EAAE,eAAe,EAAE,CAAC;CAC7B;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlassian/clientside-extensions-schema",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0-9864e593-me132vr9",
|
|
4
4
|
"description": "Implements the handling of extension-schemas used for validation, code-generation and documentation.",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"homepage": "https://bitbucket.org/atlassian/atlassian-clientside-extensions#readme",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
],
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public",
|
|
63
|
-
"@atlassian:registry": "https://
|
|
63
|
+
"@atlassian:registry": "https://packages.atlassian.com/api/npm/npm-public/"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"prepublish": "yarn build",
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
"verify": "tsc --noEmit -p tsconfig.all.json",
|
|
71
71
|
"watch": "tsc --watch -p tsconfig.cjs.json",
|
|
72
72
|
"test": "jest",
|
|
73
|
-
"test:webpack4": "env NODE_OPTIONS=--openssl-legacy-provider WEBPACK_4=true jest",
|
|
74
73
|
"test:watch": "jest --watch"
|
|
75
74
|
},
|
|
76
75
|
"devDependencies": {
|
|
@@ -80,14 +79,18 @@
|
|
|
80
79
|
"@types/lodash.snakecase": "4.1.6",
|
|
81
80
|
"@types/mkdirp": "1.0.2",
|
|
82
81
|
"@types/webpack": "5.28.0",
|
|
82
|
+
"css-loader": "7.1.2",
|
|
83
83
|
"jest": "27.3.1",
|
|
84
84
|
"jest-in-case": "1.0.2",
|
|
85
|
-
"
|
|
85
|
+
"jest-mock": "30.0.5",
|
|
86
|
+
"mini-css-extract-plugin": "2.9.2",
|
|
87
|
+
"style-loader": "4.0.0",
|
|
88
|
+
"ts-jest": "29.4.1",
|
|
86
89
|
"webpack": "5.64.4",
|
|
87
90
|
"webpack-4": "npm:webpack@4.46.0"
|
|
88
91
|
},
|
|
89
92
|
"dependencies": {
|
|
90
|
-
"@atlassian/clientside-extensions-registry": "^5.
|
|
93
|
+
"@atlassian/clientside-extensions-registry": "^5.1.0-9864e593-me132vr9",
|
|
91
94
|
"@graphql-tools/schema": "^8.0.0",
|
|
92
95
|
"@graphql-tools/utils": "^8.0.0",
|
|
93
96
|
"chokidar": "3.6.0",
|
|
@@ -101,14 +104,14 @@
|
|
|
101
104
|
"rimraf": "6.0.0",
|
|
102
105
|
"schema-utils": "3.1.1",
|
|
103
106
|
"tslib": "^2.2.0",
|
|
104
|
-
"typescript": "4.5
|
|
107
|
+
"typescript": "4.9.5",
|
|
105
108
|
"yargs": "17.2.1"
|
|
106
109
|
},
|
|
107
110
|
"peerDependencies": {
|
|
108
111
|
"webpack": "^4.0.0 || ^5.0.0"
|
|
109
112
|
},
|
|
110
113
|
"engines": {
|
|
111
|
-
"node": ">=20.
|
|
114
|
+
"node": ">=20.18.1"
|
|
112
115
|
},
|
|
113
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "9864e5937d68e51d7a26eece1238be16589135b5"
|
|
114
117
|
}
|