Skip to content

Commit 7d36ebe

Browse files
committed
fix: minor updates
1 parent 037ec16 commit 7d36ebe

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

src/app-definition-generator.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import _s from 'underscore.string'
55
import { dump as yamlDump } from 'js-yaml'
66
import { getEntityNameStrings, kebabCase } from './string-utils.js'
77

8+
export enum PermissionModel {
9+
Global = 'Global',
10+
User = 'User',
11+
Organization = 'Organization',
12+
}
13+
814
export interface App {
915
entities: AppEntity[]
1016
name: string
11-
permissionModel: string
17+
permissionModel: PermissionModel
1218
}
1319

1420
export interface AppEntityProperty {
@@ -117,8 +123,8 @@ function writeAppYamlToFileSystem({ app, appName, appDescription }: { app: App;
117123
title: app.name,
118124
description: appDescription, // `${app.name} App`,
119125
'x-codeGenie': {
120-
// region: 'us-west-2',
121-
permissionModel: app.permissionModel,
126+
region: 'us-west-2',
127+
permissionModel: ['Global', 'User', 'Organization'].includes(app.permissionModel) ? app.permissionModel : 'Global',
122128
defaultAuthRoute,
123129
entities,
124130
},
@@ -241,12 +247,13 @@ function getDynamoDbSettings({ app, entity }: { app: App; entity: AppEntity }) {
241247
const dynamoDbSettings: any = {}
242248
const isRootEntity = getIsRootEntity({ entity })
243249

244-
// Don't mess with the User entity
245250
if (entity.name === 'User') return dynamoDbSettings
246251

247252
if (isRootEntity) {
248-
dynamoDbSettings.partitionKey = 'userId'
249-
dynamoDbSettings.sortKey = getIdProperty({ entity })
253+
if (['User', 'Organization'].includes(app.permissionModel)) {
254+
dynamoDbSettings.partitionKey = app.permissionModel === 'User' ? 'userId' : 'orgId'
255+
dynamoDbSettings.sortKey = getIdProperty({ entity })
256+
}
250257
} else {
251258
const belongsToEntity = getBelongsToEntity({ app, entity })
252259
if (!belongsToEntity) {
@@ -327,21 +334,9 @@ function getPropertyType({ entityProperty }: { entityProperty: AppEntityProperty
327334
}
328335
}
329336

330-
function hasUserIdProperty({ entity }: { entity: AppEntity }) {
331-
return Boolean(entity.properties.userId)
332-
}
333-
334337
function getJsonSchemaProperties({ app, entity }: { app: App; entity: AppEntity }) {
335338
const jsonSchemaProperties: any = {}
336339

337-
if (getIsRootEntity({ entity }) && !hasUserIdProperty({ entity })) {
338-
jsonSchemaProperties.userId = {
339-
type: 'string',
340-
// description: 'User',
341-
readOnly: true,
342-
}
343-
}
344-
345340
for (const [propertyName, property] of Object.entries(entity.properties)) {
346341
const schemaProperties: any = {
347342
...getPropertyType({ entityProperty: property }),
@@ -356,7 +351,7 @@ function getJsonSchemaProperties({ app, entity }: { app: App; entity: AppEntity
356351
}
357352

358353
if (property.title) schemaProperties.title = property.title
359-
// if (property.description) schemaProperties.description = property.description
354+
if (property.description) schemaProperties.description = property.description
360355
if (property.isReadOnly) schemaProperties.readOnly = property.isReadOnly
361356
if (property.defaultValue) schemaProperties.default = property.defaultValue
362357
if (property.enumOptions) schemaProperties.enum = property.enumOptions

src/commands/generate.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ generating app...
6868
awsProfileToCopy: Flags.string({
6969
char: 'p',
7070
description:
71-
"The AWS Profile to copy in the ~/.aws/credentials file and used to deploy the application. Defaults to the 'default' profile. Specify --no-copy-aws-profile to skip this step",
71+
"The AWS Profile to copy in the ~/.aws/credentials file and used to deploy the application. Defaults to the 'default' profile. Specify --noCopyAwsProfile to skip this step",
7272
default: 'default',
7373
}),
7474
noCopyAwsProfile: Flags.boolean({
@@ -84,11 +84,16 @@ generating app...
8484
required: false,
8585
default: false,
8686
}),
87+
generateAppDefinitionOnly: Flags.boolean({
88+
description: 'Generates app definition only (run `@codegenie/cli generate` without `--description` to generate source code).',
89+
required: false,
90+
default: false,
91+
}),
8792
}
8893

8994
async run(): Promise<{ description?: string; deploy: boolean; awsProfileToCopy: string; appDir: string }> {
9095
const { flags } = await this.parse(Generate)
91-
const { description, deploy, awsProfileToCopy, noCopyAwsProfile } = flags
96+
const { description, deploy, awsProfileToCopy, noCopyAwsProfile, generateAppDefinitionOnly } = flags
9297

9398
if (description && description.length > 500) {
9499
this.error('description must be less than 500 characters.', {
@@ -109,12 +114,21 @@ generating app...
109114

110115
// Usually we expect that `generate --description` is run NOT within an existing Code Genie project directory; therefore
111116
// hasExistingAppDefinition will usually be false. If `generate --description` is run within an existing Code Genie project directory,
112-
// handleExistingAppDefinition will throw unless --replaceAppDefinitionf is included, in which case we want `appDir` to remain as cwd().
117+
// handleExistingAppDefinition will throw unless --replaceAppDefinition is included, in which case we want `appDir` to remain as cwd().
113118
if (!hasExistingAppDefinition) {
114119
appDir = getAppOutputDir({ appName: generateAppDefinitionResult.appName })
115120
}
116121
}
117122

123+
if (generateAppDefinitionOnly) {
124+
return {
125+
description,
126+
deploy,
127+
awsProfileToCopy,
128+
appDir,
129+
}
130+
}
131+
118132
const { headObjectPresignedUrl, getObjectPresignedUrl } = await this.uploadAppDefinition({ appDir })
119133

120134
await this.downloadProject({
@@ -173,8 +187,8 @@ For now you can open \`./${appDirRelative}\` in your favorite IDE like VS Code.
173187
/**
174188
* Checks if a .codegenie directory already exists so that it doesn't accidentally get overwritten.
175189
*
176-
* Users can specify --replace-app-definition if they would prefer to ignore this and replace the directory.
177-
* @throws When a .codegenie directory exists and --replace-app-definition wasn't specified
190+
* Users can specify --replaceAppDefinition if they would prefer to ignore this and replace the directory.
191+
* @throws When a .codegenie directory exists and --replaceAppDefinition wasn't specified
178192
*/
179193
async handleExistingAppDefinition() {
180194
const { flags } = await this.parse(Generate)
@@ -193,7 +207,7 @@ For now you can open \`./${appDirRelative}\` in your favorite IDE like VS Code.
193207
code: 'CODEGENIE_DIR_EXISTS',
194208
suggestions: [
195209
'If you want to regenerate based on the existing App Definition defined in .codegenie: run the same command again without the `--description` flag.',
196-
"If you'd rather replace the existing .codegenie directory with a new AI-generated App Definition, re-run the command again with the `--replace-app-definition` flag.",
210+
"If you'd rather replace the existing .codegenie directory with a new AI-generated App Definition, re-run the command again with the `--replaceAppDefinition` flag.",
197211
],
198212
})
199213
}
@@ -351,11 +365,11 @@ For now you can open \`./${appDirRelative}\` in your favorite IDE like VS Code.
351365
}
352366

353367
async runInitDev({ appDir, appName }: { appDir: string; appName: string }): Promise<undefined> {
354-
ux.action.start('🌩️ Deploying to AWS')
355368
const appDirRelative = getAppOutputDir({ appName, absolute: false })
356369
this.log(
357370
`The first deploy may take up to 10 minutes, but you don't have to wait that long to get started! Open \`./${appDirRelative}\` in your favorite IDE like VS Code to explore your project source code. Tip: You may even be able to simply run \`code ./${appDirRelative}\` in a separate terminal to open it.`
358371
)
372+
ux.action.start('🌩️ Deploying to AWS')
359373
execSync('npm run init:dev', {
360374
stdio: 'inherit',
361375
cwd: appDir,

0 commit comments

Comments
 (0)