Skip to content

Commit 8d28950

Browse files
committed
Merge branch 'next' of https://github.com/devforth/adminforth into feat/bulkActionComponent
2 parents afe97c6 + 217f98b commit 8d28950

File tree

33 files changed

+405
-111
lines changed

33 files changed

+405
-111
lines changed

adminforth/auth.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,21 @@ class AdminForthAuth implements IAdminForthAuth {
8282
username: string,
8383
pk: string | null
8484
}) {
85+
console.log("in days", expireInDays);
8586
const expiresIn: string = expireInDays ? `${expireInDays}d` : (process.env.ADMINFORTH_AUTH_EXPIRESIN || '24h');
87+
console.log("in string", expiresIn);
8688
// might be h,m,d in string
89+
8790
const expiresInSec = parseTimeToSeconds(expiresIn);
8891

92+
console.log("expiresInSec", expiresInSec);
93+
8994
const token = this.issueJWT({ username, pk}, 'auth', expiresIn);
95+
console.log("token", token);
9096
const expiresCookieFormat = new Date(Date.now() + expiresInSec * 1000).toUTCString();
91-
97+
console.log("expiresCookieFormat", expiresCookieFormat);
9298
const brandSlug = this.adminforth.config.customization.brandNameSlug;
99+
console.log("brandSlug", brandSlug);
93100
response.setHeader('Set-Cookie', `adminforth_${brandSlug}_jwt=${token}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${expiresCookieFormat}`);
94101
}
95102

adminforth/dataConnectors/postgres.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,57 +97,62 @@ class PostgresConnector extends AdminForthBaseConnector implements IAdminForthDa
9797
rows.forEach((row) => {
9898
const field: any = {};
9999
const baseType = row.type.toLowerCase();
100-
if (baseType == 'int') {
100+
const isPgArray = baseType.endsWith('[]');
101+
const normalizedBaseType = isPgArray ? baseType.slice(0, -2) : baseType;
102+
if (normalizedBaseType == 'int') {
101103
field.type = AdminForthDataTypes.INTEGER;
102104
field._underlineType = 'int';
103105

104-
} else if (baseType.includes('float') || baseType.includes('double')) {
106+
} else if (normalizedBaseType.includes('float') || normalizedBaseType.includes('double')) {
105107
field.type = AdminForthDataTypes.FLOAT;
106108
field._underlineType = 'float';
107109

108-
} else if (baseType.includes('bool')) {
110+
} else if (normalizedBaseType.includes('bool')) {
109111
field.type = AdminForthDataTypes.BOOLEAN;
110112
field._underlineType = 'bool';
111113

112-
} else if (baseType == 'uuid') {
114+
} else if (normalizedBaseType == 'uuid') {
113115
field.type = AdminForthDataTypes.STRING;
114116
field._underlineType = 'uuid';
115117

116-
} else if (baseType.includes('character varying')) {
118+
} else if (normalizedBaseType.includes('character varying')) {
117119
field.type = AdminForthDataTypes.STRING;
118120
field._underlineType = 'varchar';
119-
const length = baseType.match(/\d+/);
121+
const length = normalizedBaseType.match(/\d+/);
120122
field.maxLength = length ? parseInt(length[0]) : null;
121123

122-
} else if (baseType == 'text') {
124+
} else if (normalizedBaseType == 'text') {
123125
field.type = AdminForthDataTypes.TEXT;
124126
field._underlineType = 'text';
125127

126-
} else if (baseType.includes('decimal(') || baseType.includes('numeric(')) {
128+
} else if (normalizedBaseType.includes('decimal(') || normalizedBaseType.includes('numeric(')) {
127129
field.type = AdminForthDataTypes.DECIMAL;
128130
field._underlineType = 'decimal';
129-
const [precision, scale] = baseType.match(/\d+/g);
131+
const [precision, scale] = normalizedBaseType.match(/\d+/g);
130132
field.precision = parseInt(precision);
131133
field.scale = parseInt(scale);
132134

133-
} else if (baseType == 'real') {
135+
} else if (normalizedBaseType == 'real') {
134136
field.type = AdminForthDataTypes.FLOAT;
135137
field._underlineType = 'real';
136138

137-
} else if (baseType == 'date') {
139+
} else if (normalizedBaseType == 'date') {
138140
field.type = AdminForthDataTypes.DATE;
139141
field._underlineType = 'timestamp';
140142

141-
} else if (baseType.includes('date') || baseType.includes('time')) {
143+
} else if (normalizedBaseType.includes('date') || normalizedBaseType.includes('time')) {
142144
field.type = AdminForthDataTypes.DATETIME;
143145
field._underlineType = 'timestamp';
144-
} else if (baseType == 'json' || baseType == 'jsonb') {
146+
} else if (normalizedBaseType == 'json' || normalizedBaseType == 'jsonb') {
145147
field.type = AdminForthDataTypes.JSON;
146148
field._underlineType = 'json';
147149
} else {
148150
field.type = 'unknown'
149151
}
150152
field._baseTypeDebug = baseType;
153+
if (isPgArray) {
154+
field._isPgArray = true;
155+
}
151156
field.primaryKey = row.pk == 1;
152157
field.default = row.dflt_value;
153158
field.required = row.notnull && !row.dflt_value;
@@ -211,11 +216,22 @@ class PostgresConnector extends AdminForthBaseConnector implements IAdminForthDa
211216
} else if (field._underlineType == 'varchar') {
212217
return dayjs(value).toISOString();
213218
}
219+
} else if (field.isArray?.enabled) {
220+
if (value === null || value === undefined) {
221+
return null;
222+
}
223+
if (field._isPgArray) {
224+
return value;
225+
}
226+
if (field._underlineType == 'json') {
227+
return JSON.stringify(value);
228+
}
229+
return JSON.stringify(value);
214230
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
215231
return value === null ? null : (value ? 1 : 0);
216232
} else if (field.type == AdminForthDataTypes.JSON) {
217233
if (field._underlineType == 'json') {
218-
return value;
234+
return typeof value === 'string' || value === null ? value : JSON.stringify(value);
219235
} else {
220236
return JSON.stringify(value);
221237
}
135 KB
Loading
157 KB
Loading
71 KB
Loading
70.2 KB
Loading
71 KB
Loading
305 KB
Loading
300 KB
Loading
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
slug: context7-setup-vscode
3+
title: "How to set up Context7 MCP in Visual Studio Code"
4+
authors: ypechorkin
5+
tags: [context7, MCP]
6+
description: "Context7 MCP installation guide"
7+
---
8+
9+
This guide shows how you can set up Context7 MCP in your Visual Studio Code IDE (VS Code)
10+
<!-- truncate -->
11+
12+
### Preparation
13+
14+
First of all, you'll need to update VS Code to version 1.105.1 or higher. To check your version, go to `Help -> About`.
15+
16+
If you used a `.deb` file to install VS Code, just run these commands in the terminal to install updates:
17+
```bash
18+
sudo apt update
19+
sudo apt install code
20+
```
21+
22+
Before opening VS Code, we need to get the Context7 API key. For this, go to https://context7.com/dashboard, create a new account, and copy the API key.
23+
24+
### Setup
25+
26+
Now we can proceed with the setup:
27+
1) After opening VS Code, go to the extensions tab, where you'll see the new `MCP SERVERS` tab. Click on `Enable MCP Servers Marketplace`.
28+
![](image_1.png)
29+
30+
2) Find Context7 in the list and press `Install`:
31+
![](image_2.png)
32+
33+
3) Go to `Show Configuration JSON`:
34+
![](image_3.png)
35+
36+
4) Click `Edit`:
37+
![](image_4.png)
38+
39+
5) Insert your API key:
40+
![](image_5.png)
41+
42+
The installation is complete. You can now use it.
43+
44+
### Example: Installation of the Bulk-ai-flow Plugin
45+
46+
Here is an example prompt you can use to add the adminforth bulk-ai-flow plugin:
47+
48+
**Prompt:**
49+
`Add adminforth bulk-ai-flow plugin to this file using Context7 MCP`
50+
51+
**Generated Code:**
52+
![](image_6.png)
53+
54+
**Result:**
55+
![](image_7.png)
56+
57+
As we can see, the generation works really well.
58+
59+
### Tips
60+
If you don’t want to add `use context7` to every prompt, you can [define a simple rule in your MCP client's rule section](https://github.com/upstash/context7?tab=readme-ov-file#-tips).
61+
62+
If you're using github copilot, you can:
63+
1) In the root of your repository, create the .github directory if it does not already exist.
64+
2) create a file named `.github/copilot-instructions.md`
65+
3) Inside of new file add:
66+
67+
```txt
68+
Always use context7 when I need code generation, setup or configuration steps, or
69+
library/API documentation. This means you should automatically use the Context7 MCP
70+
tools to resolve library id and get library docs without me having to explicitly ask.
71+
```

0 commit comments

Comments
 (0)