@stacksjs/orm 0.64.6 → 0.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +0,0 @@
1
- export const dynamodbClient = {
2
- // async createTable(tableName: string, callback: (table: Table) => void): Promise<void> {
3
- // const table = new Table()
4
- // callback(table)
5
- // table.execute() // Simulate the execution of the table creation
6
- // console.log(`Table "${tableName}" created.`)
7
- // },
8
-
9
- async dropTable(tableName: string): Promise<void> {
10
- console.log(`Table "${tableName}" dropped.`)
11
- },
12
-
13
- async find(id: number): Promise<any> {
14
- return { id }
15
- },
16
- }
File without changes
File without changes
@@ -1,38 +0,0 @@
1
- import type { ProjectsTable } from '../../../../orm/src/models/Project'
2
- import type { SubscriberEmailsTable } from '../../../../orm/src/models/SubscriberEmail'
3
- import type { PersonalAccessTokensTable } from '../../../../orm/src/models/AccessToken'
4
- import type { TeamsTable } from '../../../../orm/src/models/Team'
5
- import type { SubscribersTable } from '../../../../orm/src/models/Subscriber'
6
- import type { DeploymentsTable } from '../../../../orm/src/models/Deployment'
7
- import type { ReleasesTable } from '../../../../orm/src/models/Release'
8
- import type { UsersTable } from '../../../../orm/src/models/User'
9
- import type { PostsTable } from '../../../../orm/src/models/Post'
10
- import type { Generated } from 'kysely'
11
-
12
- export interface TeamPersonalAccessTokensTable {
13
- id: Generated<number>
14
- team_id: number
15
- accesstoken_id: number
16
- }export interface TeamUsersTable {
17
- id: Generated<number>
18
- team_id: number
19
- user_id: number
20
- }export interface UserTeamsTable {
21
- id: Generated<number>
22
- user_id: number
23
- team_id: number
24
- }
25
- export interface Database {
26
- projects: ProjectsTable
27
- subscriber_emails: SubscriberEmailsTable
28
- personal_access_tokens: PersonalAccessTokensTable
29
- team_personal_access_tokens: UserTeamsTable
30
- team_users: UserTeamsTable
31
- teams: TeamsTable
32
- subscribers: SubscribersTable
33
- deployments: DeploymentsTable
34
- releases: ReleasesTable
35
- user_teams: UserTeamsTable
36
- users: UsersTable
37
- posts: PostsTable
38
- }
package/src/index.ts DELETED
@@ -1,16 +0,0 @@
1
- // import { config } from '@stacksjs/config'
2
-
3
- // import { dynamodbClient } from './drivers/dynamodb'
4
-
5
- // if (config.database.default === 'dynamodb') {
6
- // dynamodbClient.createTable('users', (table) => {
7
- // table.string('id').primary()
8
- // table.string('name')
9
- // table.string('email')
10
- // table.string('password')
11
- // table.timestamps()
12
- // })
13
- // }
14
-
15
- export * from './utils'
16
- export * from './generated/types'
package/src/types.ts DELETED
@@ -1,11 +0,0 @@
1
- export interface OrmDriver {
2
- find: (id: number) => Promise<any>
3
- create: (data: any) => Promise<any>
4
- update: (id: number, data: any) => Promise<any>
5
- delete: (id: number) => Promise<any>
6
- all: () => Promise<any[]>
7
- where: (column: string, value: any) => Promise<any[]>
8
- // Custom methods
9
- // createTable: (tableName: string, callback: (table: Table) => void) => Promise<void>;
10
- // dropTable: (tableName: string) => Promise<void>; -- i don't think we need this bc we do not support the down method
11
- }
package/src/utils.ts DELETED
@@ -1,64 +0,0 @@
1
- import { generator, parser, traverse } from '@stacksjs/build'
2
- import { path } from '@stacksjs/path'
3
- import { fs } from '@stacksjs/storage'
4
- import { plural, snakeCase } from '@stacksjs/strings'
5
- import type { Attributes } from '@stacksjs/types'
6
- import type { Model } from '@stacksjs/types'
7
-
8
- type ModelPath = string
9
-
10
- export async function modelTableName(model: Model | ModelPath): Promise<string> {
11
- if (typeof model === 'string') {
12
- model = (await import(model)).default as Model
13
- }
14
-
15
- return model.table ?? snakeCase(plural(model?.name || ''))
16
- }
17
-
18
- export function getModelName(model: Model, modelPath: string): string {
19
- if (model.name) return model.name
20
-
21
- const baseName = path.basename(modelPath)
22
-
23
- return baseName.replace(/\.ts$/, '')
24
- }
25
-
26
- export function getTableName(model: Model, modelPath: string): string {
27
- if (model.table) return model.table
28
-
29
- return snakeCase(plural(getModelName(model, modelPath)))
30
- }
31
-
32
- export async function extractFieldsFromModel(filePath: string) {
33
- // Read the TypeScript file
34
- const content = fs.readFileSync(filePath, 'utf8')
35
-
36
- // Parse the file content into an AST
37
- const ast = parser.parse(content, {
38
- sourceType: 'module',
39
- plugins: ['typescript', 'classProperties', 'decorators-legacy'],
40
- })
41
-
42
- let fields: Attributes | undefined
43
-
44
- // Traverse the AST to find the `fields` object
45
- traverse(ast, {
46
- ObjectExpression(path) {
47
- // Look for the `fields` key in the object
48
- const fieldsProperty = path.node.properties.find((property) => property.key?.name === 'attributes')
49
-
50
- if (fieldsProperty?.value) {
51
- // Convert the AST back to code (stringify)
52
- const generated = generator(fieldsProperty.value, {}, content)
53
- fields = generated.code
54
- path.stop() // Stop traversing further once we found the fields
55
- }
56
- },
57
- })
58
-
59
- return fields
60
- }
61
-
62
- export function userModels() {
63
- return import.meta.glob<{ default: Model }>(path.userModelsPath('*.ts'))
64
- }