Skip to content

Commit

Permalink
generate; use cosmiconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
brettstack committed Jan 10, 2024
1 parent 4169c83 commit 1525955
Show file tree
Hide file tree
Showing 13 changed files with 959 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"perfectionist/sort-imports": "off",
"perfectionist/sort-objects": "off",
"perfectionist/sort-union-types": "off",
"perfectionist/sort-object-types": "off"
"perfectionist/sort-object-types": "off",
"jsdoc/require-jsdoc": "off",
"jsdoc/require-returns": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
node_modules
oclif.lock
oclif.manifest.json

code-genie/
scavenger-hunt-app/
2 changes: 1 addition & 1 deletion .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
experimentalTernaries: true
semi: false
singleQuote: true
printWidth: 180
printWidth: 160
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,22 @@
"@oclif/plugin-plugins": "^4",
"@oclif/plugin-update": "^4.1.7",
"@oclif/plugin-warn-if-update-available": "^3.0.9",
"axios": "^1.6.5",
"cosmiconfig": "^9.0.0",
"js-yaml": "^4.1.0",
"pkce-challenge": "^4.0.1"
"pkce-challenge": "^4.0.1",
"pluralize": "^8.0.0",
"underscore.string": "^3.3.6"
},
"devDependencies": {
"@oclif/prettier-config": "^0.2.1",
"@oclif/test": "^3",
"@types/chai": "^4",
"@types/js-yaml": "^4.0.9",
"@types/mocha": "^10",
"@types/node": "^18",
"@types/pluralize": "^0.0.33",
"@types/underscore.string": "^0.0.41",
"chai": "^4",
"eslint": "^8",
"eslint-config-oclif": "^5",
Expand Down Expand Up @@ -84,4 +91,4 @@
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif readme && git add README.md"
}
}
}
202 changes: 202 additions & 0 deletions src/app-definition-generator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import util from 'node:util'
import { expect } from '@oclif/test'
import { App, getJsonSchemasFromEntities } from './app-definition-generator.js'
import codeGenieSampleOpenAiOutputJson from './sample-api-output.js'

describe('main', () => {
it('getJsonSchemasFromEntities returns entity schemas from openai response', () => {
const entitySchemas = getJsonSchemasFromEntities({ app: codeGenieSampleOpenAiOutputJson as unknown as App })
console.log(util.inspect(entitySchemas, { showHidden: false, depth: null, colors: true }))
expect(entitySchemas).equal([
{
entityName: 'App',
fileName: 'app.yaml',
jsonSchema: {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'App',
'x-codeGenie': {
idProperty: 'appId',
nameProperty: 'name',
dynamodb: { partitionKey: 'userId', sortKey: 'appId' },
isRootEntity: true,
hasMany: {
Entity: { $ref: './entity.yaml' },
Build: { $ref: './build.yaml' },
},
},
allOf: [{ type: 'object', $ref: '#/definitions/attributes' }],
definitions: {
attributes: {
type: 'object',
properties: {
userId: { type: 'string', readOnly: true },
appId: { type: 'string', readOnly: true },
name: { type: 'string' },
description: { type: 'string' },
logo: {
type: 'string',
contentEncoding: 'base64',
contentMediaType: 'image/png',
},
primaryBrandColor: { type: 'string' },
region: {
type: 'enum',
enum: ['us-east-1', 'us-west-2', 'eu-west-1', 'ap-southeast-1', 'ap-northeast-1'],
},
permissionModel: {
type: 'enum',
enum: ['Global', 'User', 'Organization'],
},
},
required: ['appId', 'name'],
additionalProperties: false,
},
},
},
},
{
entityName: 'Entity',
fileName: 'entity.yaml',
jsonSchema: {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'Entity',
'x-codeGenie': {
idProperty: 'entityId',
nameProperty: 'name',
dynamodb: { partitionKey: 'appId', sortKey: 'entityId' },
hasMany: {
Property: { $ref: './property.yaml' },
Many: { $ref: './many.yaml' },
},
},
allOf: [{ type: 'object', $ref: '#/definitions/attributes' }],
definitions: {
attributes: {
type: 'object',
properties: {
entityId: { type: 'string', readOnly: true },
appId: {
type: 'string',
readOnly: true,
'x-codeGenie': { foreignKey: { referencedEntity: 'App' } },
},
name: { type: 'string' },
idProperty: { type: 'string' },
nameProperty: { type: 'string' },
imageProperty: { type: 'string' },
partitionKey: { type: 'string' },
sortKey: { type: 'string' },
listView: { type: 'enum', enum: ['Card List', 'Table'] },
},
required: ['entityId', 'appId', 'name'],
additionalProperties: false,
},
},
},
},
{
entityName: 'Property',
fileName: 'property.yaml',
jsonSchema: {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'Property',
'x-codeGenie': {
idProperty: 'propertyId',
nameProperty: 'propertyId',
dynamodb: { partitionKey: 'entityId', sortKey: 'propertyId' },
onCreate: 'REMAIN_ON_CURRENT_PAGE',
buildDetailsPage: false,
},
allOf: [{ type: 'object', $ref: '#/definitions/attributes' }],
definitions: {
attributes: {
type: 'object',
properties: {
propertyId: { type: 'string', readOnly: true },
entityId: {
type: 'string',
readOnly: true,
'x-codeGenie': { foreignKey: { referencedEntity: 'Entity' } },
},
name: { type: 'string' },
description: { type: 'string' },
type: {
type: 'enum',
enum: ['string', 'number', 'integer', 'boolean', 'enum', 'array'],
},
enum: { type: 'array', items: { type: 'string' }, enum: [] },
},
required: ['propertyId', 'entityId'],
additionalProperties: false,
},
},
},
},
{
entityName: 'Many',
fileName: 'many.yaml',
jsonSchema: {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'Many',
'x-codeGenie': {
idProperty: 'manyId',
nameProperty: 'manyId',
dynamodb: { partitionKey: 'entityId', sortKey: 'manyId' },
onCreate: 'REMAIN_ON_CURRENT_PAGE',
buildDetailsPage: false,
},
allOf: [{ type: 'object', $ref: '#/definitions/attributes' }],
definitions: {
attributes: {
type: 'object',
properties: {
manyId: { type: 'string', readOnly: true },
entityId: {
type: 'string',
readOnly: true,
'x-codeGenie': { foreignKey: { referencedEntity: 'Entity' } },
},
foreignEntityId: { type: 'string' },
},
required: ['manyId', 'entityId'],
additionalProperties: false,
},
},
},
},
{
entityName: 'Build',
fileName: 'build.yaml',
jsonSchema: {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'Build',
'x-codeGenie': {
idProperty: 'buildId',
nameProperty: 'buildId',
dynamodb: { partitionKey: 'appId', sortKey: 'buildId' },
onCreate: 'REMAIN_ON_CURRENT_PAGE',
buildDetailsPage: false,
},
allOf: [{ type: 'object', $ref: '#/definitions/attributes' }],
definitions: {
attributes: {
type: 'object',
properties: {
buildId: { type: 'string', readOnly: true },
appId: {
type: 'string',
readOnly: true,
'x-codeGenie': { foreignKey: { referencedEntity: 'App' } },
},
entityId: { type: 'string' },
buildDateTime: { type: 'string', format: 'date-time' },
},
required: ['buildId', 'appId'],
additionalProperties: false,
},
},
},
},
])
})
})
Loading

0 comments on commit 1525955

Please sign in to comment.