@nocobase/plugin-data-source-main 2.1.0-alpha.13 → 2.1.0-alpha.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.
@@ -0,0 +1,243 @@
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
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var collections_exports = {};
38
+ __export(collections_exports, {
39
+ buildTemplateBaseline: () => buildTemplateBaseline,
40
+ composeCollectionDefinition: () => composeCollectionDefinition,
41
+ normalizeCollectionInput: () => normalizeCollectionInput
42
+ });
43
+ module.exports = __toCommonJS(collections_exports);
44
+ var import_lodash = __toESM(require("lodash"));
45
+ var import_constants = require("./constants");
46
+ var import_fields = require("./fields");
47
+ function buildPresetFields(options) {
48
+ const fields = [];
49
+ if (options.includeId) {
50
+ fields.push((0, import_fields.normalizeFieldInput)({ name: "id", interface: "snowflakeId", title: "ID" }));
51
+ }
52
+ if (options.includeCreatedAt) {
53
+ fields.push((0, import_fields.normalizeFieldInput)({ name: "createdAt", interface: "createdAt", title: "Created at" }));
54
+ }
55
+ if (options.includeCreatedBy) {
56
+ fields.push((0, import_fields.normalizeFieldInput)({ name: "createdBy", interface: "createdBy", title: "Created by" }));
57
+ }
58
+ if (options.includeUpdatedAt) {
59
+ fields.push((0, import_fields.normalizeFieldInput)({ name: "updatedAt", interface: "updatedAt", title: "Last updated at" }));
60
+ }
61
+ if (options.includeUpdatedBy) {
62
+ fields.push((0, import_fields.normalizeFieldInput)({ name: "updatedBy", interface: "updatedBy", title: "Last updated by" }));
63
+ }
64
+ return fields;
65
+ }
66
+ function buildTemplateBaseline(input) {
67
+ const template = input.template || "general";
68
+ const name = input.name;
69
+ const titleField = input.titleField || "title";
70
+ switch (template) {
71
+ case "general":
72
+ return {
73
+ template,
74
+ logging: input.logging ?? true,
75
+ autoGenId: false,
76
+ fields: buildPresetFields({
77
+ includeId: true,
78
+ includeCreatedAt: true,
79
+ includeCreatedBy: true,
80
+ includeUpdatedAt: true,
81
+ includeUpdatedBy: true
82
+ })
83
+ };
84
+ case "tree":
85
+ return {
86
+ template,
87
+ logging: input.logging ?? true,
88
+ view: false,
89
+ tree: input.tree || "adjacencyList",
90
+ autoGenId: false,
91
+ fields: [
92
+ (0, import_fields.normalizeFieldInput)({
93
+ name: "parentId",
94
+ interface: "integer",
95
+ type: "bigInt",
96
+ isForeignKey: true,
97
+ autoFill: false,
98
+ title: "Parent ID"
99
+ }),
100
+ (0, import_fields.normalizeFieldInput)({
101
+ name: "parent",
102
+ interface: "m2o",
103
+ target: name,
104
+ foreignKey: "parentId",
105
+ treeParent: true,
106
+ onDelete: "CASCADE",
107
+ targetTitleField: titleField,
108
+ title: "Parent"
109
+ }),
110
+ (0, import_fields.normalizeFieldInput)({
111
+ name: "children",
112
+ interface: "o2m",
113
+ target: name,
114
+ foreignKey: "parentId",
115
+ treeChildren: true,
116
+ onDelete: "CASCADE",
117
+ targetTitleField: titleField,
118
+ title: "Children"
119
+ }),
120
+ ...buildPresetFields({
121
+ includeId: true,
122
+ includeCreatedAt: true,
123
+ includeCreatedBy: true,
124
+ includeUpdatedAt: true,
125
+ includeUpdatedBy: true
126
+ })
127
+ ]
128
+ };
129
+ case "file":
130
+ return {
131
+ template,
132
+ logging: input.logging ?? true,
133
+ view: false,
134
+ createdBy: true,
135
+ updatedBy: true,
136
+ fields: [
137
+ (0, import_fields.normalizeFieldInput)({ name: "title", interface: "input", title: "Title" }),
138
+ (0, import_fields.normalizeFieldInput)({ name: "filename", interface: "input", title: "File name" }),
139
+ (0, import_fields.normalizeFieldInput)({ name: "extname", interface: "input", title: "Extension name" }),
140
+ (0, import_fields.normalizeFieldInput)({ name: "size", interface: "integer", type: "integer", title: "Size" }),
141
+ (0, import_fields.normalizeFieldInput)({ name: "mimetype", interface: "input", title: "MIME type" }),
142
+ (0, import_fields.normalizeFieldInput)({ name: "path", interface: "textarea", type: "text", title: "Path" }),
143
+ (0, import_fields.normalizeFieldInput)({ name: "url", interface: "url", type: "text", title: "URL" }),
144
+ (0, import_fields.normalizeFieldInput)({ name: "preview", interface: "url", type: "text", field: "url", title: "Preview" }),
145
+ (0, import_fields.normalizeFieldInput)({
146
+ name: "storage",
147
+ interface: "m2o",
148
+ target: "storages",
149
+ foreignKey: "storageId",
150
+ targetTitleField: "title",
151
+ title: "Storage"
152
+ }),
153
+ (0, import_fields.normalizeFieldInput)({
154
+ name: "meta",
155
+ interface: "json",
156
+ type: "jsonb",
157
+ defaultValue: {},
158
+ title: "Meta"
159
+ }),
160
+ ...buildPresetFields({
161
+ includeId: true,
162
+ includeCreatedAt: true,
163
+ includeCreatedBy: true,
164
+ includeUpdatedAt: true,
165
+ includeUpdatedBy: true
166
+ })
167
+ ]
168
+ };
169
+ case "calendar":
170
+ return {
171
+ template,
172
+ logging: input.logging ?? true,
173
+ createdBy: true,
174
+ updatedBy: true,
175
+ createdAt: true,
176
+ updatedAt: true,
177
+ sortable: input.sortable ?? true,
178
+ fields: [
179
+ (0, import_fields.normalizeFieldInput)({
180
+ name: "cron",
181
+ interface: "select",
182
+ type: "string",
183
+ title: "Repeats",
184
+ uiSchema: {
185
+ type: "string",
186
+ title: "Repeats",
187
+ "x-component": "CronSet",
188
+ "x-component-props": "allowClear",
189
+ enum: [
190
+ { label: "Daily", value: "0 0 0 * * ?" },
191
+ { label: "Weekly", value: "every_week" },
192
+ { label: "Monthly", value: "every_month" },
193
+ { label: "Yearly", value: "every_year" }
194
+ ]
195
+ }
196
+ }),
197
+ (0, import_fields.normalizeFieldInput)({
198
+ name: "exclude",
199
+ interface: "json",
200
+ type: "json",
201
+ title: "Exclude"
202
+ })
203
+ ]
204
+ };
205
+ case "view":
206
+ return { template, view: true, schema: input.schema || "public" };
207
+ case "inherit":
208
+ return { template, inherits: input.inherits };
209
+ case "sql":
210
+ default:
211
+ return { template };
212
+ }
213
+ }
214
+ function normalizeCollectionInput(input, options = {}) {
215
+ const values = import_lodash.default.cloneDeep(input || {});
216
+ if ((options.mode || "create") === "create") {
217
+ values.template = values.template || "general";
218
+ values.title = values.title || (0, import_constants.toDisplayTitle)(values.name);
219
+ }
220
+ if (Array.isArray(values.fields)) {
221
+ values.fields = values.fields.map((field) => (0, import_fields.normalizeFieldInput)(field, { collectionName: values.name }));
222
+ }
223
+ return values;
224
+ }
225
+ function composeCollectionDefinition(input, options = {}) {
226
+ const baseline = options.mode === "create" ? buildTemplateBaseline(input) : {};
227
+ const baselineFields = Array.isArray(baseline.fields) ? baseline.fields : [];
228
+ const inputFields = Array.isArray(input.fields) ? input.fields : [];
229
+ return normalizeCollectionInput(
230
+ {
231
+ ...baseline,
232
+ ...input,
233
+ fields: (0, import_constants.uniqueByName)([...baselineFields, ...inputFields])
234
+ },
235
+ options
236
+ );
237
+ }
238
+ // Annotate the CommonJS export names for ESM import in node:
239
+ 0 && (module.exports = {
240
+ buildTemplateBaseline,
241
+ composeCollectionDefinition,
242
+ normalizeCollectionInput
243
+ });
@@ -0,0 +1,24 @@
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
+ export type PlainObject = Record<string, any>;
10
+ export type TemplateName = 'general' | 'tree' | 'file' | 'calendar' | 'sql' | 'view' | 'inherit';
11
+ export declare const TEMPLATE_NAMES: TemplateName[];
12
+ export declare const MULTI_COMPONENT_INTERFACES: Set<string>;
13
+ export declare const ARRAY_DEFAULT_INTERFACES: Set<string>;
14
+ export declare const CHOICE_INTERFACES: Set<string>;
15
+ export declare const RELATION_INTERFACES: Set<string>;
16
+ export declare const INTERFACE_ALIASES: Record<string, string>;
17
+ export declare const PLUGIN_REQUIREMENTS: Record<string, {
18
+ runtimeName: string;
19
+ packageName: string;
20
+ capability: string;
21
+ }>;
22
+ export declare function toDisplayTitle(value?: string): string;
23
+ export declare function normalizeChoiceEnum(enumValues?: any[]): any[];
24
+ export declare function uniqueByName(fields: PlainObject[]): PlainObject[];
@@ -0,0 +1,187 @@
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
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var constants_exports = {};
38
+ __export(constants_exports, {
39
+ ARRAY_DEFAULT_INTERFACES: () => ARRAY_DEFAULT_INTERFACES,
40
+ CHOICE_INTERFACES: () => CHOICE_INTERFACES,
41
+ INTERFACE_ALIASES: () => INTERFACE_ALIASES,
42
+ MULTI_COMPONENT_INTERFACES: () => MULTI_COMPONENT_INTERFACES,
43
+ PLUGIN_REQUIREMENTS: () => PLUGIN_REQUIREMENTS,
44
+ RELATION_INTERFACES: () => RELATION_INTERFACES,
45
+ TEMPLATE_NAMES: () => TEMPLATE_NAMES,
46
+ normalizeChoiceEnum: () => normalizeChoiceEnum,
47
+ toDisplayTitle: () => toDisplayTitle,
48
+ uniqueByName: () => uniqueByName
49
+ });
50
+ module.exports = __toCommonJS(constants_exports);
51
+ var import_lodash = __toESM(require("lodash"));
52
+ const TEMPLATE_NAMES = ["general", "tree", "file", "calendar", "sql", "view", "inherit"];
53
+ const MULTI_COMPONENT_INTERFACES = /* @__PURE__ */ new Set([
54
+ "multipleSelect",
55
+ "checkboxGroup",
56
+ "m2m",
57
+ "o2m",
58
+ "attachment",
59
+ "mbm"
60
+ ]);
61
+ const ARRAY_DEFAULT_INTERFACES = /* @__PURE__ */ new Set(["multipleSelect", "checkboxGroup"]);
62
+ const CHOICE_INTERFACES = /* @__PURE__ */ new Set(["select", "multipleSelect", "radioGroup", "checkboxGroup"]);
63
+ const RELATION_INTERFACES = /* @__PURE__ */ new Set(["m2o", "o2m", "m2m", "obo", "oho", "mbm"]);
64
+ const INTERFACE_ALIASES = {
65
+ text: "textarea",
66
+ longText: "textarea",
67
+ singleSelect: "select",
68
+ multiSelect: "multipleSelect",
69
+ singleLineText: "input",
70
+ date: "dateOnly",
71
+ dateOnly: "dateOnly",
72
+ datetimeWithoutTz: "datetimeNoTz",
73
+ datetimeWithoutTimezone: "datetimeNoTz",
74
+ datetimeWithTimezone: "datetime",
75
+ unixTs: "unixTimestamp",
76
+ o2o: "obo"
77
+ };
78
+ const PLUGIN_REQUIREMENTS = {
79
+ file: {
80
+ runtimeName: "file-manager",
81
+ packageName: "@nocobase/plugin-file-manager",
82
+ capability: "file collection template"
83
+ },
84
+ attachment: {
85
+ runtimeName: "file-manager",
86
+ packageName: "@nocobase/plugin-file-manager",
87
+ capability: "attachment field and attachments collection"
88
+ },
89
+ attachmentURL: {
90
+ runtimeName: "field-attachment-url",
91
+ packageName: "@nocobase/plugin-field-attachment-url",
92
+ capability: "attachmentURL field"
93
+ },
94
+ vditor: {
95
+ runtimeName: "field-markdown-vditor",
96
+ packageName: "@nocobase/plugin-field-markdown-vditor",
97
+ capability: "vditor field"
98
+ },
99
+ point: {
100
+ runtimeName: "map",
101
+ packageName: "@nocobase/plugin-map",
102
+ capability: "point geometry field"
103
+ },
104
+ lineString: {
105
+ runtimeName: "map",
106
+ packageName: "@nocobase/plugin-map",
107
+ capability: "lineString geometry field"
108
+ },
109
+ circle: {
110
+ runtimeName: "map",
111
+ packageName: "@nocobase/plugin-map",
112
+ capability: "circle geometry field"
113
+ },
114
+ polygon: {
115
+ runtimeName: "map",
116
+ packageName: "@nocobase/plugin-map",
117
+ capability: "polygon geometry field"
118
+ },
119
+ chinaRegion: {
120
+ runtimeName: "field-china-region",
121
+ packageName: "@nocobase/plugin-field-china-region",
122
+ capability: "chinaRegion field and chinaRegions backing collection"
123
+ },
124
+ formula: {
125
+ runtimeName: "field-formula",
126
+ packageName: "@nocobase/plugin-field-formula",
127
+ capability: "formula field"
128
+ },
129
+ sort: {
130
+ runtimeName: "field-sort",
131
+ packageName: "@nocobase/plugin-field-sort",
132
+ capability: "sort field"
133
+ },
134
+ code: {
135
+ runtimeName: "field-code",
136
+ packageName: "@nocobase/plugin-field-code",
137
+ capability: "code field"
138
+ },
139
+ sequence: {
140
+ runtimeName: "field-sequence",
141
+ packageName: "@nocobase/plugin-field-sequence",
142
+ capability: "sequence field"
143
+ },
144
+ encryption: {
145
+ runtimeName: "field-encryption",
146
+ packageName: "@nocobase/plugin-field-encryption",
147
+ capability: "encryption field"
148
+ },
149
+ mbm: {
150
+ runtimeName: "field-m2m-array",
151
+ packageName: "@nocobase/plugin-field-m2m-array",
152
+ capability: "many-to-many array field"
153
+ }
154
+ };
155
+ function toDisplayTitle(value) {
156
+ if (!value) {
157
+ return value;
158
+ }
159
+ return import_lodash.default.startCase(value.replace(/[._-]+/g, " "));
160
+ }
161
+ function normalizeChoiceEnum(enumValues = []) {
162
+ return enumValues.map((item) => {
163
+ if (import_lodash.default.isPlainObject(item)) {
164
+ return item;
165
+ }
166
+ return {
167
+ label: String(item),
168
+ value: item
169
+ };
170
+ });
171
+ }
172
+ function uniqueByName(fields) {
173
+ return import_lodash.default.uniqBy(fields.filter(Boolean).reverse(), "name").reverse();
174
+ }
175
+ // Annotate the CommonJS export names for ESM import in node:
176
+ 0 && (module.exports = {
177
+ ARRAY_DEFAULT_INTERFACES,
178
+ CHOICE_INTERFACES,
179
+ INTERFACE_ALIASES,
180
+ MULTI_COMPONENT_INTERFACES,
181
+ PLUGIN_REQUIREMENTS,
182
+ RELATION_INTERFACES,
183
+ TEMPLATE_NAMES,
184
+ normalizeChoiceEnum,
185
+ toDisplayTitle,
186
+ uniqueByName
187
+ });
@@ -0,0 +1,12 @@
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
+ import { PlainObject } from './constants';
10
+ export declare function normalizeInterfaceName(value?: string): string;
11
+ export declare function normalizeFieldInput(input: PlainObject, context?: PlainObject): PlainObject;
12
+ export declare function normalizeFieldList(fields?: PlainObject[], collectionName?: string): PlainObject[];