plugin-data-source-postgres 0.0.0-stage → 2.0.1
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 +29 -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 +149 -0
- package/dist/server/collections/tree-collection.js +118 -0
- package/dist/server/hooks/field-hooks.js +412 -0
- package/dist/server/index.js +38 -0
- package/dist/server/plugin.js +1273 -0
- package/dist/server/postgres-collection-manager.js +868 -0
- package/dist/server/postgres-datasource.js +361 -0
- package/dist/server/utils/sql-validator.js +253 -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 +2423 -0
- package/src/server/__tests__/sql-model.test.ts +159 -0
- package/src/server/__tests__/sql-validator.test.ts +126 -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 +548 -0
- package/src/server/index.ts +13 -0
- package/src/server/plugin.ts +1499 -0
- package/src/server/postgres-collection-manager.ts +1027 -0
- package/src/server/postgres-datasource.ts +410 -0
- package/src/server/utils/sql-validator.ts +258 -0
- package/src/server/utils/validation-error.ts +38 -0
|
@@ -0,0 +1,265 @@
|
|
|
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 React from 'react';
|
|
11
|
+
import { createForm } from '@formily/core';
|
|
12
|
+
import { FormProvider, VoidField } from '@formily/react';
|
|
13
|
+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
14
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
15
|
+
import { NAMESPACE } from '../../constants';
|
|
16
|
+
import { PostgresAddCollectionAction } from '../AddCollectionAction';
|
|
17
|
+
import { ConfigurationForm } from '../ConfigurationForm';
|
|
18
|
+
import {
|
|
19
|
+
PostgresCalendarCollectionTemplate,
|
|
20
|
+
PostgresFileCollectionTemplate,
|
|
21
|
+
PostgresGeneralCollectionTemplate,
|
|
22
|
+
PostgresSQLCollectionTemplate,
|
|
23
|
+
PostgresTreeCollectionTemplate,
|
|
24
|
+
} from '../collection-templates';
|
|
25
|
+
import enUS from '../../locale/en-US.json';
|
|
26
|
+
import zhCN from '../../locale/zh-CN.json';
|
|
27
|
+
|
|
28
|
+
let capturedSchema: Record<string, unknown> | undefined;
|
|
29
|
+
let capturedScope: Record<string, unknown> | undefined;
|
|
30
|
+
const apiRequestSpy = vi.fn().mockResolvedValue({ data: {} });
|
|
31
|
+
const reloadDataSourceSpy = vi.fn().mockResolvedValue(undefined);
|
|
32
|
+
const refreshCMSpy = vi.fn().mockResolvedValue(undefined);
|
|
33
|
+
const refreshResourceSpy = vi.fn().mockResolvedValue(undefined);
|
|
34
|
+
const setVisibleSpy = vi.fn();
|
|
35
|
+
|
|
36
|
+
vi.mock('react-router-dom', () => ({
|
|
37
|
+
useParams: () => ({ name: 'pg-v1' }),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
vi.mock('@nocobase/client', () => ({
|
|
41
|
+
SchemaComponent: ({ schema, scope }: { schema: Record<string, unknown>; scope?: Record<string, unknown> }) => {
|
|
42
|
+
capturedSchema = schema;
|
|
43
|
+
capturedScope = scope;
|
|
44
|
+
return null;
|
|
45
|
+
},
|
|
46
|
+
ActionContextProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
|
47
|
+
RecordProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
|
48
|
+
useCompile: () => (value: unknown) => String(value ?? ''),
|
|
49
|
+
useRecord: () => undefined,
|
|
50
|
+
useCancelAction: () => ({ run: vi.fn() }),
|
|
51
|
+
useRequest: () => ({ data: undefined }),
|
|
52
|
+
useAPIClient: () => ({ request: apiRequestSpy }),
|
|
53
|
+
useActionContext: () => ({ setVisible: setVisibleSpy }),
|
|
54
|
+
useCollectionManager_deprecated: () => ({ refreshCM: refreshCMSpy }),
|
|
55
|
+
useResourceActionContext: () => ({ refresh: refreshResourceSpy }),
|
|
56
|
+
useDataSourceManager: () => ({
|
|
57
|
+
collectionTemplateManager: undefined,
|
|
58
|
+
getDataSource: () => ({ reload: reloadDataSourceSpy }),
|
|
59
|
+
}),
|
|
60
|
+
CollectionTemplate: class MockCollectionTemplate {
|
|
61
|
+
collectionTemplateManager: unknown;
|
|
62
|
+
availableFieldInterfaces: unknown;
|
|
63
|
+
configurableProperties: unknown;
|
|
64
|
+
default: unknown;
|
|
65
|
+
constructor(manager: unknown) {
|
|
66
|
+
this.collectionTemplateManager = manager;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
afterEach(() => {
|
|
72
|
+
cleanup();
|
|
73
|
+
capturedSchema = undefined;
|
|
74
|
+
capturedScope = undefined;
|
|
75
|
+
vi.clearAllMocks();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
function collectTranslationKeys(value: unknown, keys: Set<string>): void {
|
|
79
|
+
if (typeof value === 'string') {
|
|
80
|
+
const regex = /\{\{t\("([^"]+)",\s*\{\s*ns:\s*"([^"]+)"\s*\}\)\}\}/g;
|
|
81
|
+
let match = regex.exec(value);
|
|
82
|
+
while (match) {
|
|
83
|
+
expect(match[2]).toBe(NAMESPACE);
|
|
84
|
+
keys.add(match[1]);
|
|
85
|
+
match = regex.exec(value);
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
for (const item of value) collectTranslationKeys(item, keys);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (value && typeof value === 'object') {
|
|
94
|
+
for (const entry of Object.values(value)) collectTranslationKeys(entry, keys);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
describe('PostgreSQL legacy client v1', () => {
|
|
99
|
+
it('syncs options.addAllCollections, options.autoDiscover, and preserves selectedCollections when editing v2 data sources', async () => {
|
|
100
|
+
const form = createForm({
|
|
101
|
+
values: {
|
|
102
|
+
options: {
|
|
103
|
+
host: 'db.test',
|
|
104
|
+
addAllCollections: false,
|
|
105
|
+
autoDiscover: true,
|
|
106
|
+
selectedCollections: ['orders', 'customers'],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
render(
|
|
112
|
+
<FormProvider form={form}>
|
|
113
|
+
<ConfigurationForm from="edit" />
|
|
114
|
+
</FormProvider>,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
await waitFor(() => {
|
|
118
|
+
expect(form.values.options.addAllCollections).toBe(false);
|
|
119
|
+
expect(form.values.options.autoDiscover).toBe(false);
|
|
120
|
+
expect(form.values.collections).toEqual([
|
|
121
|
+
{ name: 'orders', selected: true },
|
|
122
|
+
{ name: 'customers', selected: true },
|
|
123
|
+
]);
|
|
124
|
+
expect(form.values.__postgresPreserveSelection).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const advanced = (
|
|
128
|
+
capturedSchema as {
|
|
129
|
+
properties: {
|
|
130
|
+
options: { properties: { tabs: { properties: { advanced: { properties: Record<string, unknown> } } } } };
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
).properties.options.properties.tabs.properties.advanced.properties;
|
|
134
|
+
expect(advanced.addAllCollections).toBeDefined();
|
|
135
|
+
expect(advanced.autoDiscover).toBeDefined();
|
|
136
|
+
|
|
137
|
+
cleanup();
|
|
138
|
+
const createFormInstance = createForm({ values: { options: { addAllCollections: false } } });
|
|
139
|
+
render(
|
|
140
|
+
<FormProvider form={createFormInstance}>
|
|
141
|
+
<ConfigurationForm from="create" />
|
|
142
|
+
</FormProvider>,
|
|
143
|
+
);
|
|
144
|
+
await waitFor(() => {
|
|
145
|
+
expect(createFormInstance.values.options.autoDiscover).toBe(false);
|
|
146
|
+
});
|
|
147
|
+
expect(createFormInstance.values.__postgresPreserveSelection).toBeUndefined();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('defines editable query column inputs with validation on PostgresSQLCollectionTemplate', () => {
|
|
151
|
+
const template = new PostgresSQLCollectionTemplate({
|
|
152
|
+
dataSourceManager: {
|
|
153
|
+
app: {
|
|
154
|
+
i18n: {
|
|
155
|
+
t: (key: string) => zhCN[key as keyof typeof zhCN] || key,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
} as never);
|
|
160
|
+
|
|
161
|
+
expect(template.default?.fields).toEqual([]);
|
|
162
|
+
expect((template.default as { sqlFields?: unknown[] })?.sqlFields).toEqual([{ name: '', type: 'string' }]);
|
|
163
|
+
const sqlFields = template.configurableProperties?.sqlFields as {
|
|
164
|
+
'x-component': string;
|
|
165
|
+
'x-validator': (value?: Array<{ name?: string }>) => string;
|
|
166
|
+
};
|
|
167
|
+
expect(sqlFields['x-component']).toBe('ArrayItems');
|
|
168
|
+
expect(sqlFields['x-validator']([])).toBe(zhCN['Add at least one query column']);
|
|
169
|
+
expect(sqlFields['x-validator']([{ name: ' ' }])).toBe(zhCN['Column name is required']);
|
|
170
|
+
expect(sqlFields['x-validator']([{ name: 'id' }, { name: 'id' }])).toBe(zhCN['Column names must be unique']);
|
|
171
|
+
expect(sqlFields['x-validator']([{ name: 'id' }, { name: 'revenue' }])).toBe('');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('scopes all v1 schema translations to NAMESPACE and defines every key in en-US and zh-CN', () => {
|
|
175
|
+
const form = createForm({ values: { options: {} } });
|
|
176
|
+
render(
|
|
177
|
+
<FormProvider form={form}>
|
|
178
|
+
<ConfigurationForm />
|
|
179
|
+
</FormProvider>,
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const templates = [
|
|
183
|
+
new PostgresGeneralCollectionTemplate(undefined as never),
|
|
184
|
+
new PostgresCalendarCollectionTemplate(undefined as never),
|
|
185
|
+
new PostgresFileCollectionTemplate(undefined as never),
|
|
186
|
+
new PostgresTreeCollectionTemplate(undefined as never),
|
|
187
|
+
new PostgresSQLCollectionTemplate(undefined as never),
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
const keys = new Set<string>();
|
|
191
|
+
collectTranslationKeys(capturedSchema, keys);
|
|
192
|
+
for (const template of templates) {
|
|
193
|
+
collectTranslationKeys(template.title, keys);
|
|
194
|
+
collectTranslationKeys(template.description, keys);
|
|
195
|
+
collectTranslationKeys(template.configurableProperties, keys);
|
|
196
|
+
collectTranslationKeys(template.default, keys);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
expect(keys.size).toBeGreaterThan(20);
|
|
200
|
+
for (const key of keys) {
|
|
201
|
+
expect(enUS).toHaveProperty([key]);
|
|
202
|
+
expect(zhCN).toHaveProperty([key]);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('maps sqlFields into fields and refreshes ResourceActionContext after v1 collection creation', async () => {
|
|
207
|
+
const form = createForm({
|
|
208
|
+
values: {
|
|
209
|
+
name: 'sales_report',
|
|
210
|
+
title: 'Sales Report',
|
|
211
|
+
template: 'sql',
|
|
212
|
+
sql: 'SELECT id, total FROM orders',
|
|
213
|
+
sqlFields: [
|
|
214
|
+
{ name: ' id ', type: 'integer' },
|
|
215
|
+
{ name: 'total', type: 'decimal' },
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
form.createVoidField({ name: 'submitBtn' });
|
|
220
|
+
|
|
221
|
+
function Harness() {
|
|
222
|
+
const useCreate = capturedScope?.useCreatePostgresCollection as (() => { run: () => Promise<void> }) | undefined;
|
|
223
|
+
const action = useCreate?.();
|
|
224
|
+
return (
|
|
225
|
+
<button type="button" onClick={() => action?.run()}>
|
|
226
|
+
RunCreate
|
|
227
|
+
</button>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
render(<PostgresAddCollectionAction />);
|
|
232
|
+
expect(typeof capturedScope?.useCreatePostgresCollection).toBe('function');
|
|
233
|
+
|
|
234
|
+
render(
|
|
235
|
+
<FormProvider form={form}>
|
|
236
|
+
<VoidField name="submitBtn">
|
|
237
|
+
<Harness />
|
|
238
|
+
</VoidField>
|
|
239
|
+
</FormProvider>,
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
fireEvent.click(screen.getByRole('button', { name: 'RunCreate' }));
|
|
243
|
+
|
|
244
|
+
await waitFor(() => {
|
|
245
|
+
expect(apiRequestSpy).toHaveBeenCalledWith({
|
|
246
|
+
url: 'dataSources/pg-v1/collections:create',
|
|
247
|
+
method: 'post',
|
|
248
|
+
data: expect.objectContaining({
|
|
249
|
+
name: 'sales_report',
|
|
250
|
+
template: 'sql',
|
|
251
|
+
sql: 'SELECT id, total FROM orders',
|
|
252
|
+
fields: [
|
|
253
|
+
{ name: 'id', type: 'integer', interface: 'integer' },
|
|
254
|
+
{ name: 'total', type: 'decimal', interface: 'number' },
|
|
255
|
+
],
|
|
256
|
+
}),
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
const sentData = apiRequestSpy.mock.calls[0][0].data as Record<string, unknown>;
|
|
260
|
+
expect('sqlFields' in sentData).toBe(false);
|
|
261
|
+
expect(reloadDataSourceSpy).toHaveBeenCalledOnce();
|
|
262
|
+
expect(refreshCMSpy).toHaveBeenCalledOnce();
|
|
263
|
+
expect(refreshResourceSpy).toHaveBeenCalledOnce();
|
|
264
|
+
});
|
|
265
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
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 { CALENDAR_FIELD_INTERFACES, nsT } from './base-template-helper';
|
|
13
|
+
|
|
14
|
+
type TemplateManagerArg = ConstructorParameters<typeof CollectionTemplate>[0];
|
|
15
|
+
type TemplateDefault = NonNullable<CollectionTemplate['default']>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Calendar Collection Template for PostgreSQL
|
|
19
|
+
* Collections with start/end date fields for calendar view
|
|
20
|
+
*/
|
|
21
|
+
export class PostgresCalendarCollectionTemplate extends CollectionTemplate {
|
|
22
|
+
name = 'calendar';
|
|
23
|
+
title = nsT('Calendar collection');
|
|
24
|
+
order = 2;
|
|
25
|
+
color = 'orange';
|
|
26
|
+
supportDataSourceType = ['postgres-external'];
|
|
27
|
+
description = nsT('Collections used for calendar events, with start and end date fields');
|
|
28
|
+
|
|
29
|
+
constructor(collectionTemplateManager: TemplateManagerArg) {
|
|
30
|
+
super(collectionTemplateManager);
|
|
31
|
+
|
|
32
|
+
this.availableFieldInterfaces = CALENDAR_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: events, meetings, tasks',
|
|
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: 'title',
|
|
95
|
+
type: 'string',
|
|
96
|
+
interface: 'input',
|
|
97
|
+
uiSchema: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
title: nsT('Title'),
|
|
100
|
+
'x-component': 'Input',
|
|
101
|
+
required: true,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'start',
|
|
106
|
+
type: 'date',
|
|
107
|
+
interface: 'datetime',
|
|
108
|
+
uiSchema: {
|
|
109
|
+
type: 'string',
|
|
110
|
+
title: nsT('Start date'),
|
|
111
|
+
'x-component': 'DatePicker',
|
|
112
|
+
'x-component-props': {
|
|
113
|
+
showTime: true,
|
|
114
|
+
},
|
|
115
|
+
required: true,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'end',
|
|
120
|
+
type: 'date',
|
|
121
|
+
interface: 'datetime',
|
|
122
|
+
uiSchema: {
|
|
123
|
+
type: 'string',
|
|
124
|
+
title: nsT('End date'),
|
|
125
|
+
'x-component': 'DatePicker',
|
|
126
|
+
'x-component-props': {
|
|
127
|
+
showTime: true,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
autoGenId: true,
|
|
133
|
+
createdBy: false,
|
|
134
|
+
updatedBy: false,
|
|
135
|
+
createdAt: true,
|
|
136
|
+
updatedAt: true,
|
|
137
|
+
sortable: true,
|
|
138
|
+
logging: false,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
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 { FILE_FIELD_INTERFACES, nsT } from './base-template-helper';
|
|
13
|
+
|
|
14
|
+
type TemplateManagerArg = ConstructorParameters<typeof CollectionTemplate>[0];
|
|
15
|
+
type TemplateDefault = NonNullable<CollectionTemplate['default']>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* File Collection Template for PostgreSQL
|
|
19
|
+
* Collections for file/attachment management
|
|
20
|
+
*/
|
|
21
|
+
export class PostgresFileCollectionTemplate extends CollectionTemplate {
|
|
22
|
+
name = 'file';
|
|
23
|
+
title = nsT('File collection');
|
|
24
|
+
order = 4;
|
|
25
|
+
color = 'purple';
|
|
26
|
+
supportDataSourceType = ['postgres-external'];
|
|
27
|
+
description = nsT('Collections for storing file metadata and attachments');
|
|
28
|
+
|
|
29
|
+
constructor(collectionTemplateManager: TemplateManagerArg) {
|
|
30
|
+
super(collectionTemplateManager);
|
|
31
|
+
|
|
32
|
+
this.availableFieldInterfaces = FILE_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: documents, images, attachments',
|
|
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: 'filename',
|
|
95
|
+
type: 'string',
|
|
96
|
+
interface: 'input',
|
|
97
|
+
uiSchema: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
title: nsT('Filename'),
|
|
100
|
+
'x-component': 'Input',
|
|
101
|
+
required: true,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'title',
|
|
106
|
+
type: 'string',
|
|
107
|
+
interface: 'input',
|
|
108
|
+
uiSchema: {
|
|
109
|
+
type: 'string',
|
|
110
|
+
title: nsT('Title'),
|
|
111
|
+
'x-component': 'Input',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'url',
|
|
116
|
+
type: 'string',
|
|
117
|
+
interface: 'url',
|
|
118
|
+
uiSchema: {
|
|
119
|
+
type: 'string',
|
|
120
|
+
title: nsT('URL'),
|
|
121
|
+
'x-component': 'Input.URL',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: 'mimetype',
|
|
126
|
+
type: 'string',
|
|
127
|
+
interface: 'input',
|
|
128
|
+
uiSchema: {
|
|
129
|
+
type: 'string',
|
|
130
|
+
title: nsT('MIME type'),
|
|
131
|
+
'x-component': 'Input',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'size',
|
|
136
|
+
type: 'bigInt',
|
|
137
|
+
interface: 'integer',
|
|
138
|
+
uiSchema: {
|
|
139
|
+
type: 'number',
|
|
140
|
+
title: nsT('File size'),
|
|
141
|
+
'x-component': 'InputNumber',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
autoGenId: true,
|
|
146
|
+
createdBy: false,
|
|
147
|
+
updatedBy: false,
|
|
148
|
+
createdAt: true,
|
|
149
|
+
updatedAt: true,
|
|
150
|
+
sortable: false,
|
|
151
|
+
logging: false,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|