Skip to content

Commit a6fbe6a

Browse files
chore: wip
1 parent c582b27 commit a6fbe6a

File tree

10 files changed

+1185
-35
lines changed

10 files changed

+1185
-35
lines changed

bun.lockb

6.55 KB
Binary file not shown.

storage/framework/api/api-types.ts

Lines changed: 647 additions & 0 deletions
Large diffs are not rendered by default.

storage/framework/api/openapi.json

Lines changed: 406 additions & 0 deletions
Large diffs are not rendered by default.

storage/framework/core/actions/src/orm/generate-model.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { log } from '@stacksjs/logging'
22
import { getModelName, getTableName } from '@stacksjs/orm'
33
import { path } from '@stacksjs/path'
44
import { fs, glob } from '@stacksjs/storage'
5-
import { camelCase, capitalCase, pascalCase, plural } from '@stacksjs/strings'
5+
import { camelCase, pascalCase, plural } from '@stacksjs/strings'
66
import type { Model, RelationConfig } from '@stacksjs/types'
77
import { isString } from '@stacksjs/validation'
88
export interface FieldArrayElement {
@@ -651,7 +651,6 @@ async function generateModelString(
651651
const tableRelation = relation.table || ''
652652
const pivotTableRelation = relation.pivotTable
653653
const formattedModelRelation = modelRelation.toLowerCase()
654-
const capitalizeTableRelation = tableRelation.charAt(0).toUpperCase() + tableRelation.slice(1)
655654

656655
const relationType = getRelationType(relation.relationship)
657656
const relationCount = getRelationCount(relation.relationship)

storage/framework/core/api/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "0.61.24",
55
"description": "The Stacks array utilities.",
66
"author": "Chris Breuer",
7+
"contributors": ["Chris Breuer <chris@stacksjs.org>"],
78
"license": "MIT",
89
"funding": "https://github.com/sponsors/chrisbbreuer",
910
"homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/arrays#readme",
@@ -35,10 +36,10 @@
3536
},
3637
"module": "dist/index.js",
3738
"types": "dist/index.d.ts",
38-
"contributors": ["Chris Breuer <chris@stacksjs.org>"],
3939
"files": ["README.md", "dist", "src"],
4040
"scripts": {
4141
"build": "bun --bun build.ts",
42+
"generate-types": "openapi-typescript ./../../api/openapi.json --output ./../../api/api-types.ts",
4243
"typecheck": "bun --bun tsc --noEmit",
4344
"prepublishOnly": "bun run build"
4445
},
@@ -47,7 +48,8 @@
4748
},
4849
"dependencies": {
4950
"@stacksjs/utils": "workspace:*",
50-
"ofetch": "^1.3.4"
51+
"ofetch": "^1.3.4",
52+
"openapi-typescript": "^7.0.0"
5153
},
5254
"devDependencies": {
5355
"@stacksjs/development": "workspace:*"
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { path } from '@stacksjs/path'
2+
import { route } from '@stacksjs/router'
3+
4+
interface Route {
5+
name: string
6+
method: string
7+
url: string
8+
uri: string
9+
callback: string
10+
pattern: RegExp
11+
statusCode: number
12+
paramNames: string[]
13+
middleware: string[]
14+
}
15+
16+
async function generateOpenAPISpec() {
17+
const routeLists: any[] = await route.getRoutes()
18+
19+
const openAPISpec = {
20+
openapi: '3.0.0',
21+
info: {
22+
title: 'Generated API',
23+
version: '1.0.0',
24+
},
25+
paths: {} as Record<string, any>,
26+
components: {
27+
schemas: {} as Record<string, any>,
28+
},
29+
}
30+
31+
routeLists.forEach((route) => {
32+
const path = route.url.replace(/{([^}]+)}/g, '{$1}')
33+
if (!openAPISpec.paths[path]) {
34+
openAPISpec.paths[path] = {}
35+
}
36+
37+
openAPISpec.paths[path][route.method.toLowerCase()] = {
38+
summary: route.name,
39+
operationId: route.callback,
40+
parameters: route.paramNames.map((param) => ({
41+
name: param,
42+
in: 'path',
43+
required: true,
44+
schema: {
45+
type: 'string',
46+
},
47+
})),
48+
responses: {
49+
[route.statusCode]: {
50+
description: 'Successful response',
51+
content: {
52+
'application/json': {
53+
schema: {
54+
type: 'object',
55+
properties: {},
56+
},
57+
},
58+
},
59+
},
60+
},
61+
}
62+
63+
// Add schemas to components if they are not already defined
64+
if (route.responseSchema) {
65+
const schemaName = `${route.name.replace(/\./g, '')}Response`
66+
openAPISpec.components.schemas[schemaName] = route.responseSchema
67+
openAPISpec.paths[path][route.method.toLowerCase()].responses[route.statusCode].content[
68+
'application/json'
69+
].schema = {
70+
$ref: `#/components/schemas/${schemaName}`,
71+
}
72+
}
73+
74+
if (route.requestSchema) {
75+
const schemaName = `${route.name.replace(/\./g, '')}Request`
76+
openAPISpec.components.schemas[schemaName] = route.requestSchema
77+
openAPISpec.paths[path][route.method.toLowerCase()].requestBody.content['application/json'].schema = {
78+
$ref: `#/components/schemas/${schemaName}`,
79+
}
80+
}
81+
})
82+
83+
return openAPISpec
84+
}
85+
86+
const openAPISpec = await generateOpenAPISpec()
87+
88+
const file = Bun.file(path.projectStoragePath(`framework/api/openapi.json`))
89+
90+
const writer = file.writer()
91+
92+
writer.write(JSON.stringify(openAPISpec.toString()))
93+
94+
await writer.end()

storage/framework/core/components/auth/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
<template>
55
<div class="bg-neutral-100/66 dark:bg-neutral-900 px-4">
6-
<Signup />
6+
<TwoFactorChallenge />
77
</div>
88
</template>

storage/framework/core/components/auth/src/components/TwoFactorChallenge.vue

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,38 @@
22
<div class="py-32">
33
<div class="mx-auto max-w-sm px-8 py-4 rounded-md shadow-md">
44
<div class="card-body">
5-
<form method="POST" action="/two-factor-challenge">
6-
<div>
7-
<h3 class="text-center text-sm text-gray-900 font-semibold">
8-
Two Factor Authentication
9-
</h3>
10-
<label for="code" class="block text-sm font-medium leading-6 mt-4 text-gray-900">
11-
Authentication code
12-
</label>
13-
<div class="relative mt-2 rounded-md shadow-sm">
14-
<input id="code" type="code" name="code" placeholder="XXXXXX" class="block w-full px-2 rounded-md border-0 py-2 pr-10 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
15-
</div>
5+
<div>
6+
<h3 class="text-center text-sm text-gray-900 font-semibold">
7+
Two Factor Authentication
8+
</h3>
9+
<label for="code" class="block text-sm font-medium leading-6 mt-4 text-gray-900">
10+
Authentication code
11+
</label>
12+
<div class="flex mt-2 rounded-md shadow-sm space-x-2">
13+
<input id="code" type="code" maxlength="1" name="code" placeholder="-" class="block text-center w-full px-2 rounded-md border-0 py-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
14+
<input id="code" type="code" maxlength="1" name="code" placeholder="-" class="block text-center w-full px-2 rounded-md border-0 py-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
15+
<input id="code" type="code" maxlength="1" name="code" placeholder="-" class="block text-center w-full px-2 rounded-md border-0 py-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
16+
<input id="code" type="code" maxlength="1" name="code" placeholder="-" class="block text-center w-full px-2 rounded-md border-0 py-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
17+
<input id="code" type="code" maxlength="1" name="code" placeholder="-" class="block text-center w-full px-2 rounded-md border-0 py-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
18+
<input id="code" type="code" maxlength="1" name="code" placeholder="-" class="block text-center w-full px-2 rounded-md border-0 py-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
1619
</div>
17-
<div class="py-4">
18-
<button type="submit" class="relative w-full font-semibold border-teal text-white bg-teal flex items-center justify-center h-8 px-4 rounded-full focus:outline-none">
19-
Verify
20-
</button>
21-
</div>
22-
<div>
23-
<p class="text-gray-700 font-semibold text-xs">
24-
Open your Symantec 2FA app to view your authentication code.
25-
</p>
26-
</div>
27-
<div class="mt-4">
28-
<p class="text-gray-700 font-semibold text-xs">
29-
Having Problems?
30-
</p>
31-
<a href="/two-factor-authentication?mode=recovery" class="hover:underline text-blue-500 text-xs">Use recovery code instead</a>
32-
</div>
33-
</form>
20+
</div>
21+
<div class="py-4">
22+
<button type="submit" class="relative w-full font-semibold border-teal text-white bg-teal flex items-center justify-center h-8 px-4 rounded-full focus:outline-none">
23+
Verify
24+
</button>
25+
</div>
26+
<div>
27+
<p class="text-gray-700 font-semibold text-xs">
28+
Open your Symantec 2FA app to view your authentication code.
29+
</p>
30+
</div>
31+
<div class="mt-4">
32+
<p class="text-gray-700 font-semibold text-xs">
33+
Having Problems?
34+
</p>
35+
<a href="#" class="hover:underline text-blue-500 text-xs">Use recovery code instead</a>
36+
</div>
3437
</div>
3538
</div>
3639
</div>

storage/framework/core/router/src/router.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Action } from '@stacksjs/actions'
22
import { log } from '@stacksjs/logging'
33
import { path as p, projectStoragePath, routesPath } from '@stacksjs/path'
4-
import { request } from '@stacksjs/router'
54
import { kebabCase, pascalCase } from '@stacksjs/strings'
65
import type { Job } from '@stacksjs/types'
76
import type { RedirectCode, Route, RouteGroupOptions, RouterInterface, StatusCode } from '@stacksjs/types'

storage/framework/core/router/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ok } from '@stacksjs/error-handling'
22
import { path } from '@stacksjs/path'
33
import { route } from './router'
44

5-
import { camelCase, lowercase, pascalCase } from '@stacksjs/strings'
5+
import { camelCase } from '@stacksjs/strings'
66

77
export async function listRoutes() {
88
const routeLists = await route.getRoutes()

0 commit comments

Comments
 (0)