Skip to content

Commit

Permalink
Add internal prefix to the runtime config function
Browse files Browse the repository at this point in the history
  • Loading branch information
stocaaro committed Nov 14, 2024
1 parent 798683d commit 517f304
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void describe('FunctionDataConfigGenerator', () => {
'testFunction'
);
const configExport =
'export const { libraryOptions, resourceConfig } = await getAmplifyClientsConfiguration(env);';
'export const { libraryOptions, resourceConfig } = await internalGetAmplifyClientConfiguration(env);';

functionDataConfigGenerator.generateDataConfigShim();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import path from 'path';
const lambdaDataConfigTemplate = (
functionName: string
) => `// This file is auto-generated by Amplify. Edits will be overwritten.
import { getAmplifyClientsConfiguration } from "@aws-amplify/backend-function/runtime";
import { internalGetAmplifyClientConfiguration } from "@aws-amplify/backend-function/runtime";
import { env } from "../env/${functionName}";
export const { libraryOptions, resourceConfig } = await getAmplifyClientsConfiguration(env);
export const { libraryOptions, resourceConfig } = await internalGetAmplifyClientConfiguration(env);
`;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { beforeEach, describe, it, mock } from 'node:test';
import assert from 'assert';
import { NoSuchKey, S3, S3ServiceException } from '@aws-sdk/client-s3';

import { getAmplifyClientsConfiguration } from './get_amplify_clients_configuration.js';
import { internalGetAmplifyClientConfiguration } from './get_amplify_clients_configuration.js';

const validEnv = {
AMPLIFY_DATA_MODEL_INTROSPECTION_SCHEMA_BUCKET_NAME:
Expand All @@ -18,7 +18,7 @@ const validEnv = {

let mockS3Client: S3;

void describe('getAmplifyClientsConfiguration', () => {
void describe('internalGetAmplifyClientConfiguration', () => {
beforeEach(() => {
mockS3Client = new S3();
});
Expand All @@ -27,7 +27,7 @@ void describe('getAmplifyClientsConfiguration', () => {
void it(`returns empty config objects when ${envFieldToExclude} is not included`, async () => {
const env = { ...validEnv } as Record<string, string>;
delete env[envFieldToExclude];
assert.deepEqual(await getAmplifyClientsConfiguration(env), {
assert.deepEqual(await internalGetAmplifyClientConfiguration(env), {
resourceConfig: {},
libraryOptions: {},
});
Expand All @@ -36,7 +36,7 @@ void describe('getAmplifyClientsConfiguration', () => {
void it(`returns empty config objects when ${envFieldToExclude} is not a string`, async () => {
const env = { ...validEnv } as Record<string, unknown>;
env[envFieldToExclude] = 123;
assert.deepEqual(await getAmplifyClientsConfiguration(env), {
assert.deepEqual(await internalGetAmplifyClientConfiguration(env), {
resourceConfig: {},
libraryOptions: {},
});
Expand All @@ -50,7 +50,8 @@ void describe('getAmplifyClientsConfiguration', () => {
mock.method(mockS3Client, 'send', s3ClientSendMock);

await assert.rejects(
async () => await getAmplifyClientsConfiguration(validEnv, mockS3Client),
async () =>
await internalGetAmplifyClientConfiguration(validEnv, mockS3Client),
new Error(
'Error retrieving the schema from S3. Please confirm that your project has a `defineData` included in the `defineBackend` definition.'
)
Expand All @@ -69,7 +70,8 @@ void describe('getAmplifyClientsConfiguration', () => {
mock.method(mockS3Client, 'send', s3ClientSendMock);

await assert.rejects(
async () => await getAmplifyClientsConfiguration(validEnv, mockS3Client),
async () =>
await internalGetAmplifyClientConfiguration(validEnv, mockS3Client),
new Error(
'Error retrieving the schema from S3. You may need to grant this function authorization on the schema. TEST_ERROR: TEST_MESSAGE.'
)
Expand All @@ -83,7 +85,8 @@ void describe('getAmplifyClientsConfiguration', () => {
mock.method(mockS3Client, 'send', s3ClientSendMock);

await assert.rejects(
async () => await getAmplifyClientsConfiguration(validEnv, mockS3Client),
async () =>
await internalGetAmplifyClientConfiguration(validEnv, mockS3Client),
new Error('Test Error')
);
});
Expand All @@ -99,7 +102,7 @@ void describe('getAmplifyClientsConfiguration', () => {
mock.method(mockS3Client, 'send', s3ClientSendMock);

const { resourceConfig, libraryOptions } =
await getAmplifyClientsConfiguration(validEnv, mockS3Client);
await internalGetAmplifyClientConfiguration(validEnv, mockS3Client);

assert.deepEqual(
await libraryOptions.Auth.credentialsProvider.getCredentialsAndIdentityId?.(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type DataClientReturn<T> = T extends DataClientEnv
* @param env - The environment variables for the data client
* @returns An object containing the `resourceConfig` and `libraryOptions`
*/
export const getAmplifyClientsConfiguration = async <T>(
export const internalGetAmplifyClientConfiguration = async <T>(
env: T,
s3Client?: S3Client
): Promise<DataClientReturn<T>> => {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-function/src/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { getAmplifyClientsConfiguration } from './get_amplify_clients_configuration.js';
export { internalGetAmplifyClientConfiguration } from './get_amplify_clients_configuration.js';

0 comments on commit 517f304

Please sign in to comment.