diff --git a/helpers/compile/plugins/fill-plugin/fillers/function.ts b/helpers/compile/plugins/fill-plugin/fillers/function.ts new file mode 100644 index 000000000000..8581d768bbee --- /dev/null +++ b/helpers/compile/plugins/fill-plugin/fillers/function.ts @@ -0,0 +1,3 @@ +export const fn = () => {} + +fn.prototype = fn diff --git a/packages/cli/src/Init.ts b/packages/cli/src/Init.ts index 2cad34973935..111876c53137 100644 --- a/packages/cli/src/Init.ts +++ b/packages/cli/src/Init.ts @@ -1,8 +1,9 @@ import type { ConnectorType } from '@prisma/generator-helper' -import type { Command } from '@prisma/sdk' import { arg, canConnectToDatabase, + checkUnsupportedDataProxy, + Command, format, getCommandWithExecutor, HelpError, @@ -134,6 +135,8 @@ export class Init implements Command { return this.help() } + await checkUnsupportedDataProxy('init', args, false) + /** * Validation */ diff --git a/packages/client/edge.d.ts b/packages/client/edge.d.ts new file mode 100644 index 000000000000..483980844cea --- /dev/null +++ b/packages/client/edge.d.ts @@ -0,0 +1 @@ +export * from '.prisma/client' diff --git a/packages/client/edge.js b/packages/client/edge.js new file mode 100644 index 000000000000..8d790165589b --- /dev/null +++ b/packages/client/edge.js @@ -0,0 +1,3 @@ +module.exports = { + ...require('.prisma/client/edge'), +} diff --git a/packages/client/edge/index.d.ts b/packages/client/edge/index.d.ts deleted file mode 100644 index e1051b2162f3..000000000000 --- a/packages/client/edge/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from '../.prisma/client' diff --git a/packages/client/edge/index.js b/packages/client/edge/index.js deleted file mode 100644 index ffb4b3b9cd94..000000000000 --- a/packages/client/edge/index.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - ...require('../.prisma/client/edge'), -} diff --git a/packages/client/helpers/build.ts b/packages/client/helpers/build.ts index 9ebfbb16c201..67c303edf7c5 100644 --- a/packages/client/helpers/build.ts +++ b/packages/client/helpers/build.ts @@ -5,6 +5,9 @@ import type { BuildOptions } from '../../../helpers/compile/build' import { build } from '../../../helpers/compile/build' import { fillPlugin } from '../../../helpers/compile/plugins/fill-plugin/fillPlugin' +const fillPluginPath = path.join('..', '..', 'helpers', 'compile', 'plugins', 'fill-plugin') +const functionPolyfillPath = path.join(fillPluginPath, 'fillers', 'function.ts') + // we define the config for runtime const nodeRuntimeBuildConfig: BuildOptions = { name: 'runtime', @@ -13,6 +16,8 @@ const nodeRuntimeBuildConfig: BuildOptions = { bundle: true, define: { NODE_CLIENT: 'true', + // that fixes an issue with lz-string umd builds + 'define.amd': 'false', }, } @@ -36,9 +41,18 @@ const edgeRuntimeBuildConfig: BuildOptions = { define: { // that helps us to tree-shake unused things out NODE_CLIENT: 'false', + // that fixes an issue with lz-string umd builds + 'define.amd': 'false', }, plugins: [ fillPlugin({ + // we remove eval and Function for vercel + eval: { define: 'undefined' }, + Function: { + define: 'fn', + inject: functionPolyfillPath, + }, + // TODO no tree shaking on wrapper pkgs '@prisma/get-platform': { contents: '' }, // removes un-needed code out of `chalk` diff --git a/packages/client/package.json b/packages/client/package.json index 05629fb918f1..8b3414096b09 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -56,6 +56,8 @@ "runtime", "scripts", "generator-build", + "edge.js", + "edge.d.ts", "index.js", "index.d.ts", "index-browser.js" diff --git a/packages/client/scripts/postinstall.js b/packages/client/scripts/postinstall.js index 9155eeee0181..1f903cb97eb2 100644 --- a/packages/client/scripts/postinstall.js +++ b/packages/client/scripts/postinstall.js @@ -197,7 +197,9 @@ function run(cmd, params, cwd = process.cwd()) { /** * Copies our default "throw" files into the default generation folder. These * files are dummy and informative because they just throw an error to let the - * user know that they have forgotten to run `prisma generate`. + * user know that they have forgotten to run `prisma generate` or that they + * don't have a a schema file yet. We only add these files at the default + * location `node_modules/.prisma/client`. */ async function createDefaultGeneratedThrowFiles() { try { @@ -205,13 +207,10 @@ async function createDefaultGeneratedThrowFiles() { const defaultNodeIndexPath = path.join(dotPrismaClientDir, 'index.js') const defaultNodeIndexDtsPath = path.join(dotPrismaClientDir, 'index.d.ts') const defaultBrowserIndexPath = path.join(dotPrismaClientDir, 'index-browser.js') + const defaultEdgeIndexPath = path.join(dotPrismaClientDir, 'edge.js') + const defaultEdgeIndexDtsPath = path.join(dotPrismaClientDir, 'edge.d.ts') await makeDir(dotPrismaClientDir) - const dotPrismaClientEdgeDir = path.join(dotPrismaClientDir, 'edge') - const defaultEdgeIndexPath = path.join(dotPrismaClientEdgeDir, 'index.js') - const defaultEdgeIndexDtsPath = path.join(dotPrismaClientEdgeDir, 'index.d.ts') - await makeDir(dotPrismaClientEdgeDir) - if (!fs.existsSync(defaultNodeIndexPath)) { await copyFile(path.join(__dirname, 'default-index.js'), defaultNodeIndexPath) } diff --git a/packages/client/src/generation/TSClient/Generatable.ts b/packages/client/src/generation/TSClient/Generatable.ts index 20de764a94e2..6ab59925d4a5 100644 --- a/packages/client/src/generation/TSClient/Generatable.ts +++ b/packages/client/src/generation/TSClient/Generatable.ts @@ -1,6 +1,6 @@ export interface Generatable { toJS?(edge?: boolean): string | Promise - toTS(): string | Promise + toTS(edge?: boolean): string | Promise toBrowserJS?(): string | Promise toTSWithoutNamespace?(): string | Promise } @@ -13,6 +13,6 @@ export function BrowserJS(gen: Generatable): string | Promise { return gen.toBrowserJS?.() ?? '' } -export function TS(gen: Generatable): string | Promise { - return gen.toTS() +export function TS(gen: Generatable, edge = false): string | Promise { + return gen.toTS(edge) } diff --git a/packages/client/src/generation/TSClient/TSClient.ts b/packages/client/src/generation/TSClient/TSClient.ts index c6909a97dcb7..3678149511fe 100644 --- a/packages/client/src/generation/TSClient/TSClient.ts +++ b/packages/client/src/generation/TSClient/TSClient.ts @@ -133,7 +133,10 @@ ${buildNFTAnnotations(dataProxy, engineType, platforms, relativeOutdir)} ` return code } - public toTS(): string { + public toTS(edge = false): string { + // edge exports the same ts definitions as the index + if (edge === true) return `export * from './index'` + const prismaClientClass = new PrismaClientClass( this.dmmf, this.options.datasources, diff --git a/packages/client/src/generation/generateClient.ts b/packages/client/src/generation/generateClient.ts index 80ae62ef06a0..6bebaf8825b4 100644 --- a/packages/client/src/generation/generateClient.ts +++ b/packages/client/src/generation/generateClient.ts @@ -123,17 +123,8 @@ export async function buildClient({ // we only generate the edge client if `--data-proxy` is passed if (dataProxy === true) { - fileMap[path.join('edge', 'index.js')] = await JS(edgeTsClient, true) - fileMap[path.join('edge', 'package.json')] = JSON.stringify( - { - name: '.prisma/client/edge', - main: 'index.js', - types: '../index.d.ts', - browser: '../index-browser.js', - }, - null, - 2, - ) + fileMap['edge.js'] = await JS(edgeTsClient, true) + fileMap['edge.d.ts'] = await TS(edgeTsClient, true) } return { @@ -222,7 +213,6 @@ export async function generateClient(options: GenerateClientOptions): Promise { - if (key === '') return value - if (key === 'parsed') return value - - const cfwEnv = `typeof global !== 'undefined' && global['${key}']` - const vercelEnv = `process.env['${key}']` - const dotEnv = value ? `'${value}'` : 'undefined' - - return `${cfwEnv} || ${vercelEnv} || ${dotEnv}` - }, - 2, - ).replace(/"/g, '') // remove quotes to make code - - return ` -config.injectableEdgeEnv = ${injectableEdgeEnvDeclaration}` -} diff --git a/packages/client/src/generation/utils/buildNFTAnnotations.ts b/packages/client/src/generation/utils/buildNFTAnnotations.ts index 94423154eb7f..26e1cde24672 100644 --- a/packages/client/src/generation/utils/buildNFTAnnotations.ts +++ b/packages/client/src/generation/utils/buildNFTAnnotations.ts @@ -35,10 +35,11 @@ export function buildNFTAnnotations( } const engineAnnotations = map(platforms, (platform) => { - return buildNFTEngineAnnotation(engineType, platform, relativeOutdir) + const engineFilename = getQueryEngineFilename(engineType, platform) + return engineFilename ? buildNFTAnnotation(engineFilename, relativeOutdir) : '' }).join('\n') - const schemaAnnotations = buildNFTSchemaAnnotation(engineType, relativeOutdir) + const schemaAnnotations = buildNFTAnnotation('schema.prisma', relativeOutdir) return `${engineAnnotations}${schemaAnnotations}` } @@ -76,32 +77,3 @@ function buildNFTAnnotation(fileName: string, relativeOutdir: string) { path.join(__dirname, ${JSON.stringify(fileName)}); path.join(process.cwd(), ${JSON.stringify(relativeFilePath)})` } - -/** - * Build an annotation for the prisma client engine files - * @param engineType - * @param platform - * @param relativeOutdir - * @returns - */ -function buildNFTEngineAnnotation(engineType: ClientEngineType, platform: Platform, relativeOutdir: string) { - const engineFilename = getQueryEngineFilename(engineType, platform) - - if (engineFilename === undefined) return '' - - return buildNFTAnnotation(engineFilename, relativeOutdir) -} - -/** - * Build an annotation for the prisma schema files - * @param engineType - * @param relativeOutdir - * @returns - */ -function buildNFTSchemaAnnotation(engineType: ClientEngineType, relativeOutdir: string) { - if (engineType === ClientEngineType.Library || engineType === ClientEngineType.Binary) { - return buildNFTAnnotation('schema.prisma', relativeOutdir) - } - - return '' -} diff --git a/packages/client/src/runtime/getPrismaClient.ts b/packages/client/src/runtime/getPrismaClient.ts index 941bf53c1ca3..82ee214a7cd8 100644 --- a/packages/client/src/runtime/getPrismaClient.ts +++ b/packages/client/src/runtime/getPrismaClient.ts @@ -47,7 +47,7 @@ declare global { } // used by esbuild for tree-shaking -globalThis.NODE_CLIENT = true +typeof globalThis === 'object' ? (globalThis.NODE_CLIENT = true) : 0 function isReadonlyArray(arg: any): arg is ReadonlyArray { return Array.isArray(arg) diff --git a/packages/engine-core/src/common/Engine.ts b/packages/engine-core/src/common/Engine.ts index a802767668b5..50a74780cbbb 100644 --- a/packages/engine-core/src/common/Engine.ts +++ b/packages/engine-core/src/common/Engine.ts @@ -56,7 +56,7 @@ export interface EngineConfig { showColors?: boolean logQueries?: boolean logLevel?: 'info' | 'warn' - env?: Record + env: Record flags?: string[] clientVersion?: string previewFeatures?: string[] diff --git a/packages/engine-core/src/data-proxy/DataProxyEngine.ts b/packages/engine-core/src/data-proxy/DataProxyEngine.ts index 0b9eba66a4e4..f1bad4f5ccd4 100644 --- a/packages/engine-core/src/data-proxy/DataProxyEngine.ts +++ b/packages/engine-core/src/data-proxy/DataProxyEngine.ts @@ -18,16 +18,19 @@ import { request } from './utils/request' const MAX_RETRIES = 10 +// to defer the execution of promises in the constructor +const P = Promise.resolve() + export class DataProxyEngine extends Engine { private inlineSchema: string private inlineSchemaHash: string private inlineDatasources: any private config: EngineConfig private logEmitter: EventEmitter - private env: { [k: string]: string } + private env: { [k in string]?: string } private clientVersion: string - private remoteClientVersion: string + private remoteClientVersion: Promise private headers: { Authorization: string } private host: string @@ -35,7 +38,7 @@ export class DataProxyEngine extends Engine { super() this.config = config - this.env = this.config.env ?? {} + this.env = { ...this.config.env, ...process.env } this.inlineSchema = config.inlineSchema ?? '' this.inlineDatasources = config.inlineDatasources ?? {} this.inlineSchemaHash = config.inlineSchemaHash ?? '' @@ -45,7 +48,7 @@ export class DataProxyEngine extends Engine { this.logEmitter.on('error', () => {}) const [host, apiKey] = this.extractHostAndApiKey() - this.remoteClientVersion = getClientVersion(this.config) + this.remoteClientVersion = P.then(() => getClientVersion(this.config)) this.headers = { Authorization: `Bearer ${apiKey}` } this.host = host } @@ -69,8 +72,8 @@ export class DataProxyEngine extends Engine { } } - private url(s: string) { - return `https://${this.host}/${this.remoteClientVersion}/${this.inlineSchemaHash}/${s}` + private async url(s: string) { + return `https://${this.host}/${await this.remoteClientVersion}/${this.inlineSchemaHash}/${s}` } // TODO: looks like activeProvider is the only thing @@ -86,7 +89,7 @@ export class DataProxyEngine extends Engine { } private async uploadSchema() { - const response = await request(this.url('schema'), { + const response = await request(await this.url('schema'), { method: 'PUT', headers: this.headers, body: this.inlineSchema, @@ -129,10 +132,10 @@ export class DataProxyEngine extends Engine { private async requestInternal(body: Record, headers: Record, attempt: number) { try { this.logEmitter.emit('info', { - message: `Calling ${this.url('graphql')} (n=${attempt})`, + message: `Calling ${await this.url('graphql')} (n=${attempt})`, }) - const response = await request(this.url('graphql'), { + const response = await request(await this.url('graphql'), { method: 'POST', headers: { ...headers, ...this.headers }, body: JSON.stringify(body), diff --git a/packages/engine-core/src/data-proxy/errors/NetworkError.ts b/packages/engine-core/src/data-proxy/errors/NetworkError.ts index 8113d347b1d4..540b90102cfc 100644 --- a/packages/engine-core/src/data-proxy/errors/NetworkError.ts +++ b/packages/engine-core/src/data-proxy/errors/NetworkError.ts @@ -2,13 +2,13 @@ import type { DataProxyErrorInfo } from './DataProxyError' import { DataProxyError } from './DataProxyError' import { setRetryable } from './utils/setRetryable' -export interface NetworkErrorInfo extends DataProxyErrorInfo {} +export interface RequestErrorInfo extends DataProxyErrorInfo {} -export class NetworkError extends DataProxyError { - public name = 'NetworkError' +export class RequestError extends DataProxyError { + public name = 'RequestError' public code = 'P5010' - constructor(info: NetworkErrorInfo) { - super('Cannot fetch data from service', setRetryable(info, true)) + constructor(message: string, info: RequestErrorInfo) { + super(`Cannot fetch data from service:\n${message}`, setRetryable(info, true)) } } diff --git a/packages/engine-core/src/data-proxy/utils/getClientVersion.ts b/packages/engine-core/src/data-proxy/utils/getClientVersion.ts index 66e022a51c78..3ac61a5538cf 100644 --- a/packages/engine-core/src/data-proxy/utils/getClientVersion.ts +++ b/packages/engine-core/src/data-proxy/utils/getClientVersion.ts @@ -1,19 +1,62 @@ +import Debug from '@prisma/debug' +import { version as engineVersion } from '@prisma/engines/package.json' + import type { EngineConfig } from '../../common/Engine' +import { NotImplementedYetError } from '../errors/NotImplementedYetError' +import { request } from './request' + +const semverRegex = /^[1-9][0-9]*\.[0-9]+\.[0-9]+$/ +const prismaNpm = 'https://registry.npmjs.org/prisma' +const debug = Debug('prisma:client:dataproxyEngine') + +async function _getClientVersion(config: EngineConfig) { + const clientVersion = config.clientVersion ?? 'unknown' + + // internal override for testing and manual version overrides + if (process.env.PRISMA_CLIENT_DATA_PROXY_CLIENT_VERSION) { + return process.env.PRISMA_CLIENT_DATA_PROXY_CLIENT_VERSION + } + + const [version, suffix] = clientVersion?.split('-') ?? [] + + // we expect the version to match the pattern major.minor.patch + if (suffix === undefined && semverRegex.test(version)) { + return version + } + + // if it's an integration version, we resolve its data proxy + if (suffix === 'integration' || clientVersion === '0.0.0') { + // we infer the data proxy version from the engine version + const [version] = engineVersion.split('-') ?? [] + const [major, minor, patch] = version.split('.') + + // if a patch has happened, then we return that version + if (patch !== '0') return `${major}.${minor}.${patch}` + + // if not, we know that the minor must be minus with 1 + const published = `${major}.${parseInt(minor) - 1}.x` + + // we don't know what `x` is, so we query the registry + const res = await request(`${prismaNpm}/${published}`, { clientVersion }) + + return ((await res.json())['version'] as string) ?? 'undefined' + } + + // nothing matched, meaning that the provided version is invalid + throw new NotImplementedYetError('Only `major.minor.patch` versions are supported by Prisma Data Proxy.', { + clientVersion, + }) +} /** * Determine the client version to be sent to the DataProxy * @param config * @returns */ -export function getClientVersion(config: EngineConfig) { - const [version, suffix] = config.clientVersion?.split('-') ?? [] +export async function getClientVersion(config: EngineConfig) { + const version = await _getClientVersion(config) - // we expect the version to match the pattern major.minor.patch - if (!suffix && /^[1-9][0-9]*\.[0-9]+\.[0-9]+$/.test(version)) { - return version - } + debug('version', version) - // TODO: we should have a Data Proxy deployment which accepts any - // arbitrary version for testing purposes. - return '3.4.1' // and we default it to the latest stable + return version } diff --git a/packages/engine-core/src/data-proxy/utils/request.ts b/packages/engine-core/src/data-proxy/utils/request.ts index 856a157b488c..53d432d90b85 100644 --- a/packages/engine-core/src/data-proxy/utils/request.ts +++ b/packages/engine-core/src/data-proxy/utils/request.ts @@ -3,7 +3,7 @@ import type Https from 'https' import type { RequestInit, Response } from 'node-fetch' import type { O } from 'ts-toolbelt' -import { NetworkError } from '../errors/NetworkError' +import { RequestError } from '../errors/NetworkError' import { getJSRuntimeName } from './getJSRuntimeName' // our implementation handles less @@ -23,6 +23,7 @@ export async function request( url: string, options: RequestOptions & { clientVersion: string }, ): Promise { + const clientVersion = options.clientVersion const jsRuntimeName = getJSRuntimeName() try { @@ -32,7 +33,8 @@ export async function request( return await nodeFetch(url, options) } } catch (e) { - throw new NetworkError({ clientVersion: options.clientVersion }) + const message = e.message ?? 'Unknown error' + throw new RequestError(message, { clientVersion }) } } @@ -84,7 +86,7 @@ function buildResponse(incomingData: Buffer[], response: IncomingMessage): Reque * @returns */ async function nodeFetch(url: string, options: RequestOptions = {}): Promise { - const https: typeof Https = await globalThis[['e', 'v', 'a', 'l'].join('')](`import('https')`) + const https: typeof Https = include('https') const httpsOptions = buildOptions(options) const incomingData = [] as Buffer[] @@ -101,3 +103,6 @@ async function nodeFetch(url: string, options: RequestOptions = {}): Promise {} diff --git a/packages/sdk/src/__tests__/getGenerators/getGenerators.test.ts b/packages/sdk/src/__tests__/getGenerators/getGenerators.test.ts index b5a96d8172c1..09239dda67d2 100644 --- a/packages/sdk/src/__tests__/getGenerators/getGenerators.test.ts +++ b/packages/sdk/src/__tests__/getGenerators/getGenerators.test.ts @@ -781,8 +781,7 @@ describe('getGenerators', () => { interactiveTransactions preview feature is not yet available with --data-proxy. Please remove interactiveTransactions from the previewFeatures in your schema. - More information in our documentation: - https://pris.ly/d/data-proxy + More information about Data Proxy: https://pris.ly/d/data-proxy " `) } diff --git a/packages/sdk/src/cli/checkUnsupportedDataProxy.ts b/packages/sdk/src/cli/checkUnsupportedDataProxy.ts index e609696a8522..c01616ff75f1 100644 --- a/packages/sdk/src/cli/checkUnsupportedDataProxy.ts +++ b/packages/sdk/src/cli/checkUnsupportedDataProxy.ts @@ -43,7 +43,7 @@ More information about Data Proxy: ${link('https://pris.ly/d/data-proxy-cli')} * @param args the cli command arguments * @param implicitSchema if this command implicitly loads a schema */ -async function _checkUnsupportedDataProxy(command: string, args: Args, implicitSchema: boolean) { +async function checkUnsupportedDataProxyMessage(command: string, args: Args, implicitSchema: boolean) { // when the schema can be implicit, we use its default location if (implicitSchema === true) { args['--schema'] = (await getSchemaPath(args['--schema'])) ?? undefined @@ -53,8 +53,7 @@ async function _checkUnsupportedDataProxy(command: string, args: Args, implicitS for (const [argName, argValue] of argList) { // for all the args that represent an url ensure data proxy isn't used if (argName.includes('url') && argValue.includes('prisma://')) { - console.error(forbiddenCmdWithDataProxyFlagMessage(command)) - process.exit(1) + return forbiddenCmdWithDataProxyFlagMessage(command) } // for all the args that represent a schema path ensure data proxy isn't used @@ -68,15 +67,16 @@ async function _checkUnsupportedDataProxy(command: string, args: Args, implicitS const urlEnvVarValue = urlEnvVarName ? process.env[urlEnvVarName] : undefined if ((urlFromValue ?? urlEnvVarValue)?.startsWith('prisma://')) { - console.error(forbiddenCmdWithDataProxyFlagMessage(command)) - process.exit(1) + return forbiddenCmdWithDataProxyFlagMessage(command) } } } + + return undefined } export async function checkUnsupportedDataProxy(command: string, args: Args, implicitSchema: boolean) { - try { - await _checkUnsupportedDataProxy(command, args, implicitSchema) - } catch {} + const message = await checkUnsupportedDataProxyMessage(command, args, implicitSchema).catch(() => undefined) + + if (message) throw new Error(message) } diff --git a/packages/sdk/src/cli/getGeneratorSuccessMessage.ts b/packages/sdk/src/cli/getGeneratorSuccessMessage.ts index b823c27991c5..023cc6dd2f72 100644 --- a/packages/sdk/src/cli/getGeneratorSuccessMessage.ts +++ b/packages/sdk/src/cli/getGeneratorSuccessMessage.ts @@ -23,7 +23,8 @@ function formatVersion(generator: Generator): string | undefined { if (generator.getProvider() === 'prisma-client-js') { const engineType = getClientEngineType(generator.config) - return version ? `${version} | ${engineType}` : engineType + const engineMode = generator.options?.dataProxy ? 'dataproxy' : engineType + return version ? `${version} | ${engineMode}` : engineMode } return version diff --git a/packages/sdk/src/get-generators/utils/check-feature-flags/checkFeatureFlags.ts b/packages/sdk/src/get-generators/utils/check-feature-flags/checkFeatureFlags.ts index d33a2bd316ef..dfcf32fb042c 100644 --- a/packages/sdk/src/get-generators/utils/check-feature-flags/checkFeatureFlags.ts +++ b/packages/sdk/src/get-generators/utils/check-feature-flags/checkFeatureFlags.ts @@ -1,6 +1,6 @@ import type { ConfigMetaFormat } from '../../../engine-commands' import { GetGeneratorOptions } from '../../getGenerators' -import { forbiddenItxWithDataProxyFlagMessage } from './forbiddenItxWithProxyFlagMessage' +import { forbiddenPreviewFeatureWithDataProxyFlagMessage } from './forbiddenItxWithProxyFlagMessage' /** * Check feature flags and preview features @@ -12,16 +12,18 @@ export function checkFeatureFlags(config: ConfigMetaFormat, options: GetGenerato } function checkForbiddenItxWithDataProxyFlag(config: ConfigMetaFormat, options: GetGeneratorOptions) { - if ( - options.dataProxy === true && + options.dataProxy === true && config.generators.some((generatorConfig) => { - return generatorConfig.previewFeatures.some( - (feature) => feature.toLocaleLowerCase() === 'interactiveTransactions'.toLocaleLowerCase(), - ) + return generatorConfig.previewFeatures.some((feature) => { + if (feature.toLocaleLowerCase() === 'metrics'.toLocaleLowerCase()) { + throw new Error(forbiddenPreviewFeatureWithDataProxyFlagMessage('metrics')) + } + + if (feature.toLocaleLowerCase() === 'interactiveTransactions'.toLocaleLowerCase()) { + throw new Error(forbiddenPreviewFeatureWithDataProxyFlagMessage('interactiveTransactions')) + } + }) }) - ) { - throw new Error(forbiddenItxWithDataProxyFlagMessage) - } } /* Example diff --git a/packages/sdk/src/get-generators/utils/check-feature-flags/forbiddenItxWithProxyFlagMessage.ts b/packages/sdk/src/get-generators/utils/check-feature-flags/forbiddenItxWithProxyFlagMessage.ts index 8f889081b805..f006c3fc5e06 100644 --- a/packages/sdk/src/get-generators/utils/check-feature-flags/forbiddenItxWithProxyFlagMessage.ts +++ b/packages/sdk/src/get-generators/utils/check-feature-flags/forbiddenItxWithProxyFlagMessage.ts @@ -2,10 +2,9 @@ import chalk from 'chalk' import { link } from '../../../utils/link' -export const forbiddenItxWithDataProxyFlagMessage = ` -${chalk.green('interactiveTransactions')} preview feature is not yet available with ${chalk.green('--data-proxy')}. -Please remove ${chalk.red('interactiveTransactions')} from the ${chalk.green('previewFeatures')} in your schema. +export const forbiddenPreviewFeatureWithDataProxyFlagMessage = (previewFeatureName: string) => ` +${chalk.green(previewFeatureName)} preview feature is not yet available with ${chalk.green('--data-proxy')}. +Please remove ${chalk.red(previewFeatureName)} from the ${chalk.green('previewFeatures')} in your schema. -More information in our documentation: -${link('https://pris.ly/d/data-proxy')} +More information about Data Proxy: ${link('https://pris.ly/d/data-proxy')} ` diff --git a/tsconfig.build.regular.json b/tsconfig.build.regular.json index 51a02abe19a2..6dfc2740656a 100644 --- a/tsconfig.build.regular.json +++ b/tsconfig.build.regular.json @@ -17,7 +17,8 @@ "skipDefaultLibCheck": true, "skipLibCheck": true, - "emitDeclarationOnly": true + "emitDeclarationOnly": true, + "resolveJsonModule": true }, "exclude": ["**/dist", "**/node_modules", "**/src/__tests__"] }