ugly-app 0.1.12 → 0.1.14
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.
- package/package.json +1 -1
- package/templates/.eslintrc.cjs +20 -0
- package/templates/CLAUDE.md +6 -2
- package/templates/server/index.ts +3 -7
- package/templates/shared/api.ts +2 -2
- package/templates/shared/collections.ts +9 -2
- package/templates/shared/pages.ts +1 -1
- package/templates/shared/types.ts +6 -0
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: { browser: true, es2022: true, node: true },
|
|
4
|
+
extends: [
|
|
5
|
+
'eslint:recommended',
|
|
6
|
+
'plugin:@typescript-eslint/strict',
|
|
7
|
+
'plugin:@typescript-eslint/stylistic',
|
|
8
|
+
],
|
|
9
|
+
parser: '@typescript-eslint/parser',
|
|
10
|
+
parserOptions: { project: './tsconfig.json' },
|
|
11
|
+
plugins: ['@typescript-eslint'],
|
|
12
|
+
rules: {
|
|
13
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
14
|
+
'@typescript-eslint/no-floating-promises': 'error',
|
|
15
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
16
|
+
'@typescript-eslint/no-empty-object-type': 'off',
|
|
17
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
18
|
+
'no-console': 'off',
|
|
19
|
+
},
|
|
20
|
+
};
|
package/templates/CLAUDE.md
CHANGED
|
@@ -39,14 +39,18 @@ Generated by `ugly-app`. See the full framework docs at [npm:ugly-app](https://w
|
|
|
39
39
|
return { greeting: `Hello, ${name}` };
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
|
-
3. Available in handlers: `ctx.db`, `ctx.storage`, `ctx.rateLimit`, `ctx.userId
|
|
42
|
+
3. Available in handlers: `ctx.db`, `ctx.storage`, `ctx.rateLimit`, `ctx.userId` (fetch user via `userHelper.get(ctx.db, ctx.userId)`)
|
|
43
43
|
|
|
44
44
|
## Adding a new database collection
|
|
45
45
|
|
|
46
46
|
1. Add to `shared/collections.ts`:
|
|
47
47
|
```typescript
|
|
48
|
+
import type { MyCollection } from './types';
|
|
48
49
|
export const collections = defineCollections({
|
|
49
|
-
myCollection: {
|
|
50
|
+
myCollection: {
|
|
51
|
+
type: {} as MyCollection,
|
|
52
|
+
meta: { cache: false, trackable: true, public: true, parent: null },
|
|
53
|
+
},
|
|
50
54
|
});
|
|
51
55
|
```
|
|
52
56
|
2. Add TypeScript interface to `shared/types.ts` (create if needed)
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { createApp, createUserHelper, registerFeedbackHandlers } from 'ugly-app';
|
|
2
|
-
import {
|
|
2
|
+
import { dbDefaults } from 'ugly-app/shared';
|
|
3
3
|
import { functions, requests } from '../shared/api';
|
|
4
4
|
import { collections } from '../shared/collections';
|
|
5
5
|
import { pages } from '../shared/pages';
|
|
6
|
-
|
|
7
|
-
// Extend UserBase with any app-specific fields
|
|
8
|
-
export interface User extends UserBase {
|
|
9
|
-
// name?: string;
|
|
10
|
-
}
|
|
6
|
+
import type { User } from '../shared/types';
|
|
11
7
|
|
|
12
8
|
const userHelper = createUserHelper<User>(collections.user);
|
|
13
9
|
|
|
@@ -15,7 +11,7 @@ const app = createApp({ functions, requests }, collections, (configurator) => {
|
|
|
15
11
|
configurator.setPages({ pages });
|
|
16
12
|
configurator.setUserHelper(userHelper);
|
|
17
13
|
configurator.setOnUserCreate(async (userId, info, db) => {
|
|
18
|
-
await userHelper.set(db, { id: userId, ...info });
|
|
14
|
+
await userHelper.set(db, { id: userId, ...dbDefaults(), ...info });
|
|
19
15
|
});
|
|
20
16
|
});
|
|
21
17
|
|
package/templates/shared/api.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { defineCollections } from 'ugly-app/shared';
|
|
2
|
+
import type { User } from './types';
|
|
2
3
|
|
|
3
4
|
export const collections = defineCollections({
|
|
4
|
-
user: {
|
|
5
|
+
user: {
|
|
6
|
+
type: {} as User,
|
|
7
|
+
meta: { cache: true, trackable: false, public: false, parent: null },
|
|
8
|
+
},
|
|
5
9
|
// Add your collections here:
|
|
6
|
-
// post: {
|
|
10
|
+
// post: {
|
|
11
|
+
// type: {} as Post,
|
|
12
|
+
// meta: { cache: false, trackable: true, public: true, parent: null },
|
|
13
|
+
// },
|
|
7
14
|
});
|
|
8
15
|
|
|
9
16
|
export type AppCollections = typeof collections;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { definePage, definePages } from 'ugly-app/shared';
|
|
2
2
|
|
|
3
3
|
export const pages = definePages({
|
|
4
|
-
'': definePage<{}>({ auth: false
|
|
4
|
+
'': definePage<{}>({ auth: false }),
|
|
5
5
|
'auth-demo': definePage<{}>({ auth: false }),
|
|
6
6
|
'user/:userId': definePage<{ userId: string }>(),
|
|
7
7
|
'search': definePage<{ q?: string }>({ auth: false }),
|