plugin-data-source-postgres 0.0.0-stage → 2.0.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.
- package/README.md +9 -3
- package/client-v2.js +1 -0
- package/client.js +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/985.34da95acdf7743ab.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/constants.js +45 -0
- package/dist/externalVersion.js +28 -0
- package/dist/locale/en-US.json +141 -0
- package/dist/locale/zh-CN.json +141 -0
- package/dist/server/collections/adjacency-list-repository.js +340 -0
- package/dist/server/collections/index.js +45 -0
- package/dist/server/collections/sql-collection.js +84 -0
- package/dist/server/collections/sql-model.js +147 -0
- package/dist/server/collections/tree-collection.js +118 -0
- package/dist/server/hooks/field-hooks.js +392 -0
- package/dist/server/index.js +38 -0
- package/dist/server/plugin.js +690 -0
- package/dist/server/postgres-collection-manager.js +701 -0
- package/dist/server/postgres-datasource.js +327 -0
- package/dist/server/utils/sql-validator.js +203 -0
- package/dist/server/utils/validation-error.js +59 -0
- package/package.json +51 -4
- package/server.js +1 -0
- package/src/client/AddCollectionAction.tsx +307 -0
- package/src/client/ConfigurationForm.tsx +203 -0
- package/src/client/PostgresCollectionTemplate.tsx +109 -0
- package/src/client/__tests__/client-v1.test.tsx +265 -0
- package/src/client/collection-templates/CalendarCollectionTemplate.tsx +141 -0
- package/src/client/collection-templates/FileCollectionTemplate.tsx +154 -0
- package/src/client/collection-templates/SQLCollectionTemplate.tsx +184 -0
- package/src/client/collection-templates/TreeCollectionTemplate.tsx +136 -0
- package/src/client/collection-templates/base-template-helper.ts +62 -0
- package/src/client/collection-templates/field-interfaces-config.ts +73 -0
- package/src/client/collection-templates/index.ts +19 -0
- package/src/client/index.tsx +69 -0
- package/src/client-v2/PostgresAddCollection.tsx +422 -0
- package/src/client-v2/PostgresConfigForm.tsx +178 -0
- package/src/client-v2/PostgresDeleteCollection.tsx +83 -0
- package/src/client-v2/__tests__/plugin.test.tsx +372 -0
- package/src/client-v2/collection-options.ts +22 -0
- package/src/client-v2/index.tsx +10 -0
- package/src/client-v2/plugin.tsx +71 -0
- package/src/constants.ts +20 -0
- package/src/locale/en-US.json +141 -0
- package/src/locale/zh-CN.json +141 -0
- package/src/server/__tests__/field-hooks.test.ts +357 -0
- package/src/server/__tests__/postgres-data-source.integration.test.ts +543 -0
- package/src/server/__tests__/postgres-datasource.unit.test.ts +1538 -0
- package/src/server/__tests__/sql-model.test.ts +115 -0
- package/src/server/__tests__/sql-validator.test.ts +119 -0
- package/src/server/collections/adjacency-list-repository.ts +378 -0
- package/src/server/collections/index.ts +19 -0
- package/src/server/collections/sql-collection.ts +66 -0
- package/src/server/collections/sql-model.ts +158 -0
- package/src/server/collections/tree-collection.ts +102 -0
- package/src/server/hooks/field-hooks.ts +514 -0
- package/src/server/index.ts +13 -0
- package/src/server/plugin.ts +764 -0
- package/src/server/postgres-collection-manager.ts +827 -0
- package/src/server/postgres-datasource.ts +365 -0
- package/src/server/utils/sql-validator.ts +203 -0
- package/src/server/utils/validation-error.ts +38 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ISchema } from '@formily/react';
|
|
11
|
+
import { CollectionTemplate } from '@nocobase/client';
|
|
12
|
+
import { NAMESPACE } from '../../constants';
|
|
13
|
+
import { nsT, SQL_FIELD_INTERFACES } from './base-template-helper';
|
|
14
|
+
|
|
15
|
+
type TemplateManagerArg = ConstructorParameters<typeof CollectionTemplate>[0];
|
|
16
|
+
type TemplateDefault = NonNullable<CollectionTemplate['default']> & {
|
|
17
|
+
sqlFields?: Array<{ name: string; type: string }>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* SQL Collection Template for PostgreSQL
|
|
22
|
+
* Collections created from custom SQL queries (similar to views)
|
|
23
|
+
*/
|
|
24
|
+
export class PostgresSQLCollectionTemplate extends CollectionTemplate {
|
|
25
|
+
name = 'sql';
|
|
26
|
+
title = nsT('SQL collection');
|
|
27
|
+
order = 5;
|
|
28
|
+
color = 'cyan';
|
|
29
|
+
supportDataSourceType = ['postgres-external'];
|
|
30
|
+
description = nsT('Collections created from custom SQL queries, read-only by default');
|
|
31
|
+
|
|
32
|
+
constructor(collectionTemplateManager: TemplateManagerArg) {
|
|
33
|
+
super(collectionTemplateManager);
|
|
34
|
+
|
|
35
|
+
this.availableFieldInterfaces = SQL_FIELD_INTERFACES;
|
|
36
|
+
this.configurableProperties = this._getConfigurableProperties();
|
|
37
|
+
this.default = this._getDefault();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private translate(key: string): string {
|
|
41
|
+
const manager = this.collectionTemplateManager as
|
|
42
|
+
| { dataSourceManager?: { app?: { i18n?: { t: (k: string, opts?: Record<string, unknown>) => string } } } }
|
|
43
|
+
| undefined;
|
|
44
|
+
return manager?.dataSourceManager?.app?.i18n?.t(key, { ns: NAMESPACE }) || key;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
_getConfigurableProperties(): Record<string, ISchema> {
|
|
48
|
+
return {
|
|
49
|
+
title: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
title: nsT('Collection display name'),
|
|
52
|
+
required: true,
|
|
53
|
+
'x-decorator': 'FormItem',
|
|
54
|
+
'x-component': 'Input',
|
|
55
|
+
},
|
|
56
|
+
name: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
title: nsT('Collection name'),
|
|
59
|
+
required: true,
|
|
60
|
+
'x-decorator': 'FormItem',
|
|
61
|
+
'x-component': 'Input',
|
|
62
|
+
'x-disabled': false,
|
|
63
|
+
'x-read-only': false,
|
|
64
|
+
'x-component-props': {
|
|
65
|
+
disabled: false,
|
|
66
|
+
placeholder: nsT('Please input collection name'),
|
|
67
|
+
},
|
|
68
|
+
'x-validator': [
|
|
69
|
+
{
|
|
70
|
+
pattern: /^[a-zA-Z][a-zA-Z0-9_]*$/,
|
|
71
|
+
message: nsT('Must start with a letter and can only contain letters, numbers, and underscores'),
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
description: nsT(
|
|
75
|
+
'Use letters, numbers and underscores, must start with a letter. Example: analytics, reports, queries',
|
|
76
|
+
),
|
|
77
|
+
},
|
|
78
|
+
sql: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
title: nsT('SQL query'),
|
|
81
|
+
required: true,
|
|
82
|
+
'x-decorator': 'FormItem',
|
|
83
|
+
'x-component': 'Input.TextArea',
|
|
84
|
+
'x-component-props': {
|
|
85
|
+
rows: 10,
|
|
86
|
+
placeholder: nsT('SELECT * FROM your_table WHERE ...'),
|
|
87
|
+
},
|
|
88
|
+
description: nsT(
|
|
89
|
+
'Custom SQL query to retrieve data. Must be a SELECT statement. The collection will be read-only.',
|
|
90
|
+
),
|
|
91
|
+
},
|
|
92
|
+
sqlFields: {
|
|
93
|
+
type: 'array',
|
|
94
|
+
title: nsT('Query columns'),
|
|
95
|
+
'x-decorator': 'FormItem',
|
|
96
|
+
'x-component': 'ArrayItems',
|
|
97
|
+
'x-validator': (value: Array<{ name?: string }> = []) => {
|
|
98
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
99
|
+
return this.translate('Add at least one query column');
|
|
100
|
+
}
|
|
101
|
+
const names = value.map((item) => item?.name?.trim()).filter(Boolean);
|
|
102
|
+
if (names.length !== value.length) {
|
|
103
|
+
return this.translate('Column name is required');
|
|
104
|
+
}
|
|
105
|
+
if (new Set(names).size !== names.length) {
|
|
106
|
+
return this.translate('Column names must be unique');
|
|
107
|
+
}
|
|
108
|
+
return '';
|
|
109
|
+
},
|
|
110
|
+
items: {
|
|
111
|
+
type: 'object',
|
|
112
|
+
'x-component': 'Space',
|
|
113
|
+
properties: {
|
|
114
|
+
name: {
|
|
115
|
+
type: 'string',
|
|
116
|
+
required: true,
|
|
117
|
+
'x-decorator': 'FormItem',
|
|
118
|
+
'x-component': 'Input',
|
|
119
|
+
'x-component-props': {
|
|
120
|
+
placeholder: nsT('Column name'),
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
type: {
|
|
124
|
+
type: 'string',
|
|
125
|
+
required: true,
|
|
126
|
+
default: 'string',
|
|
127
|
+
'x-decorator': 'FormItem',
|
|
128
|
+
'x-component': 'Select',
|
|
129
|
+
'x-component-props': {
|
|
130
|
+
style: { width: 150 },
|
|
131
|
+
},
|
|
132
|
+
enum: [
|
|
133
|
+
{ value: 'string', label: nsT('Text') },
|
|
134
|
+
{ value: 'text', label: nsT('Long text') },
|
|
135
|
+
{ value: 'integer', label: nsT('Integer') },
|
|
136
|
+
{ value: 'bigInt', label: nsT('Big integer') },
|
|
137
|
+
{ value: 'decimal', label: nsT('Decimal') },
|
|
138
|
+
{ value: 'boolean', label: nsT('Boolean') },
|
|
139
|
+
{ value: 'date', label: nsT('Date and time') },
|
|
140
|
+
{ value: 'json', label: nsT('JSON') },
|
|
141
|
+
{ value: 'uuid', label: nsT('UUID') },
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
remove: {
|
|
145
|
+
type: 'void',
|
|
146
|
+
'x-decorator': 'FormItem',
|
|
147
|
+
'x-component': 'ArrayItems.Remove',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
properties: {
|
|
152
|
+
addition: {
|
|
153
|
+
type: 'void',
|
|
154
|
+
title: nsT('Add query column'),
|
|
155
|
+
'x-component': 'ArrayItems.Addition',
|
|
156
|
+
'x-component-props': {
|
|
157
|
+
defaultValue: { name: '', type: 'string' },
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
description: {
|
|
163
|
+
type: 'string',
|
|
164
|
+
title: nsT('Description'),
|
|
165
|
+
'x-decorator': 'FormItem',
|
|
166
|
+
'x-component': 'Input.TextArea',
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
_getDefault(): TemplateDefault {
|
|
172
|
+
return {
|
|
173
|
+
fields: [],
|
|
174
|
+
sqlFields: [{ name: '', type: 'string' }],
|
|
175
|
+
autoGenId: false,
|
|
176
|
+
createdBy: false,
|
|
177
|
+
updatedBy: false,
|
|
178
|
+
createdAt: false,
|
|
179
|
+
updatedAt: false,
|
|
180
|
+
sortable: false,
|
|
181
|
+
logging: false,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ISchema } from '@formily/react';
|
|
11
|
+
import { CollectionTemplate } from '@nocobase/client';
|
|
12
|
+
import { nsT, TREE_FIELD_INTERFACES } from './base-template-helper';
|
|
13
|
+
|
|
14
|
+
type TemplateManagerArg = ConstructorParameters<typeof CollectionTemplate>[0];
|
|
15
|
+
type TemplateDefault = NonNullable<CollectionTemplate['default']>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Tree Collection Template for PostgreSQL
|
|
19
|
+
* Collections with parent-child relationships for tree structures
|
|
20
|
+
*/
|
|
21
|
+
export class PostgresTreeCollectionTemplate extends CollectionTemplate {
|
|
22
|
+
name = 'tree';
|
|
23
|
+
title = nsT('Tree collection');
|
|
24
|
+
order = 3;
|
|
25
|
+
color = 'green';
|
|
26
|
+
supportDataSourceType = ['postgres-external'];
|
|
27
|
+
description = nsT('Collections organized in parent-child tree structure, like categories, departments, etc');
|
|
28
|
+
|
|
29
|
+
constructor(collectionTemplateManager: TemplateManagerArg) {
|
|
30
|
+
super(collectionTemplateManager);
|
|
31
|
+
|
|
32
|
+
this.availableFieldInterfaces = TREE_FIELD_INTERFACES;
|
|
33
|
+
this.configurableProperties = this._getConfigurableProperties();
|
|
34
|
+
this.default = this._getDefault();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_getConfigurableProperties(): Record<string, ISchema> {
|
|
38
|
+
return {
|
|
39
|
+
title: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
title: nsT('Collection display name'),
|
|
42
|
+
required: true,
|
|
43
|
+
'x-decorator': 'FormItem',
|
|
44
|
+
'x-component': 'Input',
|
|
45
|
+
},
|
|
46
|
+
name: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
title: nsT('Collection name'),
|
|
49
|
+
required: true,
|
|
50
|
+
'x-decorator': 'FormItem',
|
|
51
|
+
'x-component': 'Input',
|
|
52
|
+
'x-disabled': false,
|
|
53
|
+
'x-read-only': false,
|
|
54
|
+
'x-component-props': {
|
|
55
|
+
disabled: false,
|
|
56
|
+
placeholder: nsT('Please input collection name'),
|
|
57
|
+
},
|
|
58
|
+
'x-validator': [
|
|
59
|
+
{
|
|
60
|
+
pattern: /^[a-zA-Z][a-zA-Z0-9_]*$/,
|
|
61
|
+
message: nsT('Must start with a letter and can only contain letters, numbers, and underscores'),
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
description: nsT(
|
|
65
|
+
'Use letters, numbers and underscores, must start with a letter. Example: categories, departments',
|
|
66
|
+
),
|
|
67
|
+
},
|
|
68
|
+
description: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
title: nsT('Description'),
|
|
71
|
+
'x-decorator': 'FormItem',
|
|
72
|
+
'x-component': 'Input.TextArea',
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
_getDefault(): TemplateDefault {
|
|
78
|
+
return {
|
|
79
|
+
fields: [
|
|
80
|
+
{
|
|
81
|
+
name: 'id',
|
|
82
|
+
type: 'bigInt',
|
|
83
|
+
interface: 'id',
|
|
84
|
+
primaryKey: true,
|
|
85
|
+
autoIncrement: true,
|
|
86
|
+
uiSchema: {
|
|
87
|
+
type: 'number',
|
|
88
|
+
title: nsT('ID'),
|
|
89
|
+
'x-component': 'InputNumber',
|
|
90
|
+
'x-read-pretty': true,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'name',
|
|
95
|
+
type: 'string',
|
|
96
|
+
interface: 'input',
|
|
97
|
+
uiSchema: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
title: nsT('Name'),
|
|
100
|
+
'x-component': 'Input',
|
|
101
|
+
required: true,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'parentId',
|
|
106
|
+
type: 'bigInt',
|
|
107
|
+
interface: 'integer',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'parent',
|
|
111
|
+
type: 'belongsTo',
|
|
112
|
+
interface: 'm2o',
|
|
113
|
+
foreignKey: 'parentId',
|
|
114
|
+
targetKey: 'id',
|
|
115
|
+
treeParent: true,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: 'children',
|
|
119
|
+
type: 'hasMany',
|
|
120
|
+
interface: 'o2m',
|
|
121
|
+
foreignKey: 'parentId',
|
|
122
|
+
sourceKey: 'id',
|
|
123
|
+
treeChildren: true,
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
tree: 'parentId',
|
|
127
|
+
autoGenId: true,
|
|
128
|
+
createdBy: false,
|
|
129
|
+
updatedBy: false,
|
|
130
|
+
createdAt: true,
|
|
131
|
+
updatedAt: true,
|
|
132
|
+
sortable: true,
|
|
133
|
+
logging: false,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Helper constants for all PostgreSQL templates
|
|
11
|
+
// Import complete field interfaces configuration
|
|
12
|
+
import { NAMESPACE } from '../../constants';
|
|
13
|
+
import { POSTGRES_AVAILABLE_INTERFACES } from './field-interfaces-config';
|
|
14
|
+
|
|
15
|
+
export const nsT = (key: string) => `{{t(${JSON.stringify(key)}, { ns: "${NAMESPACE}" })}}`;
|
|
16
|
+
|
|
17
|
+
// Calendar, Tree, and File templates support all field types
|
|
18
|
+
export const CALENDAR_FIELD_INTERFACES = POSTGRES_AVAILABLE_INTERFACES;
|
|
19
|
+
export const TREE_FIELD_INTERFACES = POSTGRES_AVAILABLE_INTERFACES;
|
|
20
|
+
export const FILE_FIELD_INTERFACES = POSTGRES_AVAILABLE_INTERFACES;
|
|
21
|
+
|
|
22
|
+
// SQL and View templates support read-only subset (they're based on queries/views)
|
|
23
|
+
export const SQL_FIELD_INTERFACES = {
|
|
24
|
+
include: [
|
|
25
|
+
// Basic text types (read-only)
|
|
26
|
+
'input',
|
|
27
|
+
'textarea',
|
|
28
|
+
'email',
|
|
29
|
+
'url',
|
|
30
|
+
'phone',
|
|
31
|
+
// Numeric types (read-only)
|
|
32
|
+
'integer',
|
|
33
|
+
'number',
|
|
34
|
+
'percent',
|
|
35
|
+
'currency',
|
|
36
|
+
// Visual
|
|
37
|
+
'password',
|
|
38
|
+
'color',
|
|
39
|
+
'icon',
|
|
40
|
+
// Choices (single selection for display)
|
|
41
|
+
'checkbox',
|
|
42
|
+
'select',
|
|
43
|
+
'radio',
|
|
44
|
+
// Date & Time (all variants for display)
|
|
45
|
+
'datetime',
|
|
46
|
+
'datetimeNoTz',
|
|
47
|
+
'date',
|
|
48
|
+
'time',
|
|
49
|
+
'unixTimestamp',
|
|
50
|
+
// Advanced types (read-only)
|
|
51
|
+
'json',
|
|
52
|
+
'uuid',
|
|
53
|
+
// Media (read-only display)
|
|
54
|
+
'richText',
|
|
55
|
+
'markdown',
|
|
56
|
+
'attachment',
|
|
57
|
+
// System fields
|
|
58
|
+
'id',
|
|
59
|
+
'createdAt',
|
|
60
|
+
'updatedAt',
|
|
61
|
+
],
|
|
62
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Complete Field Interfaces Configuration for PostgreSQL Templates
|
|
12
|
+
* Matches main datasource field types
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const POSTGRES_AVAILABLE_INTERFACES = {
|
|
16
|
+
include: [
|
|
17
|
+
// Basic text types (Single line text, Long text, Phone, Email, URL)
|
|
18
|
+
'input', // Single line text
|
|
19
|
+
'textarea', // Long text
|
|
20
|
+
'phone', // Phone
|
|
21
|
+
'email', // Email
|
|
22
|
+
'url', // URL
|
|
23
|
+
|
|
24
|
+
// Numeric types (Integer, Number, Percent)
|
|
25
|
+
'integer', // Integer
|
|
26
|
+
'number', // Number
|
|
27
|
+
'percent', // Percent
|
|
28
|
+
'currency', // Currency (bonus)
|
|
29
|
+
|
|
30
|
+
// Security (Password)
|
|
31
|
+
'password', // Password
|
|
32
|
+
|
|
33
|
+
// Visual (Color, Icon)
|
|
34
|
+
'color', // Color
|
|
35
|
+
'icon', // Icon
|
|
36
|
+
|
|
37
|
+
// Choices (Checkbox, Single select, Multiple select, Radio group, Checkbox group)
|
|
38
|
+
'checkbox', // Checkbox (boolean)
|
|
39
|
+
'select', // Single select
|
|
40
|
+
'multipleSelect', // Multiple select
|
|
41
|
+
'radio', // Radio group
|
|
42
|
+
'checkboxGroup', // Checkbox group
|
|
43
|
+
|
|
44
|
+
// Media (Markdown, Rich Text)
|
|
45
|
+
'markdown', // Markdown
|
|
46
|
+
'richText', // Rich Text
|
|
47
|
+
|
|
48
|
+
// Date & Time (all variants)
|
|
49
|
+
'datetime', // Datetime (with time zone)
|
|
50
|
+
'datetimeNoTz', // Datetime (without time zone)
|
|
51
|
+
'date', // DateOnly
|
|
52
|
+
'time', // Time
|
|
53
|
+
'unixTimestamp', // Unix Timestamp
|
|
54
|
+
|
|
55
|
+
// Advanced types
|
|
56
|
+
'json', // JSON field
|
|
57
|
+
'uuid', // UUID
|
|
58
|
+
|
|
59
|
+
// Relationships (NocoBase interface names)
|
|
60
|
+
'm2o', // Many to One
|
|
61
|
+
'obo', // One to One (belongs to)
|
|
62
|
+
'oho', // One to One (has one)
|
|
63
|
+
'o2m', // One to Many
|
|
64
|
+
'm2m', // Many to Many
|
|
65
|
+
'm2m_array', // Many to Many (array)
|
|
66
|
+
|
|
67
|
+
// System fields
|
|
68
|
+
'id', // ID (auto)
|
|
69
|
+
'createdAt', // Created at
|
|
70
|
+
'updatedAt', // Updated at
|
|
71
|
+
'sort', // Sort order
|
|
72
|
+
],
|
|
73
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* PostgreSQL Collection Templates
|
|
12
|
+
* Export all available collection templates for PostgreSQL datasource
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export { PostgresGeneralCollectionTemplate } from '../PostgresCollectionTemplate';
|
|
16
|
+
export { PostgresCalendarCollectionTemplate } from './CalendarCollectionTemplate';
|
|
17
|
+
export { PostgresTreeCollectionTemplate } from './TreeCollectionTemplate';
|
|
18
|
+
export { PostgresFileCollectionTemplate } from './FileCollectionTemplate';
|
|
19
|
+
export { PostgresSQLCollectionTemplate } from './SQLCollectionTemplate';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { DatabaseOutlined } from '@ant-design/icons';
|
|
11
|
+
import { Plugin } from '@nocobase/client';
|
|
12
|
+
import PluginDataSourceManagerClient from '@nocobase/plugin-data-source-manager/client';
|
|
13
|
+
import { ConfigurationForm } from './ConfigurationForm';
|
|
14
|
+
import { DATA_SOURCE_TYPE, NAMESPACE } from '../constants';
|
|
15
|
+
import {
|
|
16
|
+
PostgresGeneralCollectionTemplate,
|
|
17
|
+
PostgresCalendarCollectionTemplate,
|
|
18
|
+
PostgresTreeCollectionTemplate,
|
|
19
|
+
PostgresFileCollectionTemplate,
|
|
20
|
+
PostgresSQLCollectionTemplate,
|
|
21
|
+
} from './collection-templates';
|
|
22
|
+
import { PostgresAddCollection } from './AddCollectionAction';
|
|
23
|
+
import enUS from '../locale/en-US.json';
|
|
24
|
+
import zhCN from '../locale/zh-CN.json';
|
|
25
|
+
|
|
26
|
+
export class PluginDataSourcePostgresClient extends Plugin {
|
|
27
|
+
async afterAdd() {
|
|
28
|
+
this.app.i18n.addResources('en-US', NAMESPACE, enUS);
|
|
29
|
+
this.app.i18n.addResources('zh-CN', NAMESPACE, zhCN);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async load() {
|
|
33
|
+
const dsManagerPlugin = this.app.pm.get(PluginDataSourceManagerClient);
|
|
34
|
+
if (!dsManagerPlugin) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const templates = [
|
|
39
|
+
PostgresGeneralCollectionTemplate,
|
|
40
|
+
PostgresCalendarCollectionTemplate,
|
|
41
|
+
PostgresTreeCollectionTemplate,
|
|
42
|
+
PostgresFileCollectionTemplate,
|
|
43
|
+
PostgresSQLCollectionTemplate,
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
dsManagerPlugin.registerType(DATA_SOURCE_TYPE, {
|
|
47
|
+
name: DATA_SOURCE_TYPE,
|
|
48
|
+
label: this.app.i18n.t('External PostgreSQL Database', { ns: NAMESPACE }),
|
|
49
|
+
icon: DatabaseOutlined,
|
|
50
|
+
DataSourceSettingsForm: ConfigurationForm,
|
|
51
|
+
allowCollectionCreate: true,
|
|
52
|
+
allowCollectionDeletion: true,
|
|
53
|
+
disabledConfigureFields: false,
|
|
54
|
+
disableAddFields: false,
|
|
55
|
+
collectionListParams: () => ({
|
|
56
|
+
pageSize: 50,
|
|
57
|
+
sort: 'sort',
|
|
58
|
+
filter: {
|
|
59
|
+
'hidden.$isFalsy': true,
|
|
60
|
+
},
|
|
61
|
+
appends: ['fields'],
|
|
62
|
+
}),
|
|
63
|
+
AddCollection: PostgresAddCollection,
|
|
64
|
+
collectionTemplates: templates,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default PluginDataSourcePostgresClient;
|