@nocobase/plugin-data-source-main 1.6.0-alpha.3 → 1.6.0-alpha.31
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/dist/client/index.d.ts +22 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +6 -6
- package/dist/locale/it-IT.json +4 -0
- package/dist/server/collections/collectionCategories.js +1 -0
- package/dist/server/collections/collections.js +1 -0
- package/dist/server/collections/fields.js +1 -0
- package/dist/server/hooks/afterCreateForForeignKeyField.js +10 -4
- package/dist/server/migrations/20241230000001-update-bigint-to-unixtimestamp.d.ts +13 -0
- package/dist/server/migrations/20241230000001-update-bigint-to-unixtimestamp.js +59 -0
- package/dist/server/migrations/20250123000001-remove-schema-options.d.ts +13 -0
- package/dist/server/migrations/20250123000001-remove-schema-options.js +52 -0
- package/dist/server/models/field.d.ts +1 -0
- package/dist/server/models/field.js +23 -2
- package/dist/server/repositories/collection-repository.js +5 -1
- package/dist/server/resourcers/collections.js +1 -1
- package/dist/server/server.js +28 -5
- package/package.json +2 -2
package/dist/client/index.d.ts
CHANGED
|
@@ -7,7 +7,29 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Plugin } from '@nocobase/client';
|
|
10
|
+
type PresetFieldConfig = {
|
|
11
|
+
order: number;
|
|
12
|
+
description: string;
|
|
13
|
+
value: {
|
|
14
|
+
name: string;
|
|
15
|
+
interface: string;
|
|
16
|
+
type: string;
|
|
17
|
+
uiSchema: Record<string, any>;
|
|
18
|
+
field?: string;
|
|
19
|
+
[T: string]: any;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
10
22
|
declare class PluginDataSourceMainClient extends Plugin {
|
|
23
|
+
collectionPresetFields: {
|
|
24
|
+
order: number;
|
|
25
|
+
value: any;
|
|
26
|
+
}[];
|
|
27
|
+
addCollectionPresetField(config: PresetFieldConfig): void;
|
|
28
|
+
removeCollectionPresetField(fieldName: string): void;
|
|
29
|
+
getCollectionPresetFields(): {
|
|
30
|
+
order: number;
|
|
31
|
+
value: any;
|
|
32
|
+
}[];
|
|
11
33
|
load(): Promise<void>;
|
|
12
34
|
}
|
|
13
35
|
export default PluginDataSourceMainClient;
|
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-data-source-main",["@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-data-source-main"]=t(require("@nocobase/client")):e["@nocobase/plugin-data-source-main"]=t(e["@nocobase/client"])}(self,function(e){return function(){"use strict";var
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client"),require("lodash")):"function"==typeof define&&define.amd?define("@nocobase/plugin-data-source-main",["@nocobase/client","lodash"],t):"object"==typeof exports?exports["@nocobase/plugin-data-source-main"]=t(require("@nocobase/client"),require("lodash")):e["@nocobase/plugin-data-source-main"]=t(e["@nocobase/client"],e.lodash)}(self,function(e,t){return function(){"use strict";var r={772:function(t){t.exports=e},467:function(e){e.exports=t}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return r[e](i,i.exports,o),i.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};o.r(i);var a=o(772),c=o(467);function u(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){r(e);return}c.done?t(u):Promise.resolve(u).then(n,o)}function l(e,t,r){return(l=y()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&f(o,r.prototype),o}).apply(null,arguments)}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function p(e){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t){return(f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function d(e){var t="function"==typeof Map?new Map:void 0;return(d=function(e){var r;if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return l(e,arguments,p(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),f(n,e)})(e)}function y(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(y=function(){return!!e})()}var b=function(e){var t,r,n;function o(){var e,t,r,n,i,a,c;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),t=this,r=o,n=arguments,r=p(r),e=function(e,t){return t&&("object"===function(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}(t)||"function"==typeof t)?t:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(t,y()?Reflect.construct(r,n||[],p(t).constructor):r.apply(t,n)),c=[],(a="collectionPresetFields")in(i=e)?Object.defineProperty(i,a,{value:c,enumerable:!0,configurable:!0,writable:!0}):i[a]=c,e}return!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&f(e,t)}(o,e),t=o,r=[{key:"addCollectionPresetField",value:function(e){this.collectionPresetFields.push(e)}},{key:"removeCollectionPresetField",value:function(e){this.collectionPresetFields=(0,c.reject)(this.collectionPresetFields,function(t){return t.value.name===e})}},{key:"getCollectionPresetFields",value:function(){return(0,c.orderBy)(this.collectionPresetFields,["order"],["asc"])}},{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(e){return t.addCollectionPresetField({order:100,description:'{{t("Primary key, unique identifier, self growth") }}',value:{name:"id",type:"bigInt",autoIncrement:!0,primaryKey:!0,allowNull:!1,uiSchema:{type:"number",title:'{{t("ID")}}',"x-component":"InputNumber","x-read-pretty":!0},interface:"integer"}}),t.addCollectionPresetField({order:200,description:'{{t("Store the creation time of each record")}}',value:{name:"createdAt",interface:"createdAt",type:"date",field:"createdAt",uiSchema:{type:"datetime",title:'{{t("Created at")}}',"x-component":"DatePicker","x-component-props":{},"x-read-pretty":!0}}}),t.addCollectionPresetField({order:300,description:'{{t("Store the creation user of each record") }}',value:{name:"createdBy",interface:"createdBy",type:"belongsTo",target:"users",foreignKey:"createdById",uiSchema:{type:"object",title:'{{t("Created by")}}',"x-component":"AssociationField","x-component-props":{fieldNames:{value:"id",label:"nickname"}},"x-read-pretty":!0}}}),t.addCollectionPresetField({order:400,description:'{{t("Store the last update time of each record")}}',value:{type:"date",field:"updatedAt",name:"updatedAt",interface:"updatedAt",uiSchema:{type:"datetime",title:'{{t("Last updated at")}}',"x-component":"DatePicker","x-component-props":{},"x-read-pretty":!0}}}),t.addCollectionPresetField({order:500,description:'{{t("Store the last update user of each record")}}',value:{type:"belongsTo",target:"users",foreignKey:"updatedById",name:"updatedBy",interface:"updatedBy",uiSchema:{type:"object",title:'{{t("Last updated by")}}',"x-component":"AssociationField","x-component-props":{fieldNames:{value:"id",label:"nickname"}},"x-read-pretty":!0}}}),[2]})},function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){u(i,n,o,a,c,"next",e)}function c(e){u(i,n,o,a,c,"throw",e)}a(void 0)})})()}}],s(t.prototype,r),o}(d(a.Plugin));return i.default=b,i}()});
|
package/dist/externalVersion.js
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "1.6.0-alpha.
|
|
12
|
-
"@nocobase/database": "1.6.0-alpha.3",
|
|
13
|
-
"@nocobase/plugin-error-handler": "1.6.0-alpha.3",
|
|
14
|
-
"@nocobase/server": "1.6.0-alpha.3",
|
|
11
|
+
"@nocobase/client": "1.6.0-alpha.31",
|
|
15
12
|
"lodash": "4.17.21",
|
|
16
|
-
"@nocobase/
|
|
17
|
-
"@nocobase/
|
|
13
|
+
"@nocobase/database": "1.6.0-alpha.31",
|
|
14
|
+
"@nocobase/plugin-error-handler": "1.6.0-alpha.31",
|
|
15
|
+
"@nocobase/server": "1.6.0-alpha.31",
|
|
16
|
+
"@nocobase/test": "1.6.0-alpha.31",
|
|
17
|
+
"@nocobase/utils": "1.6.0-alpha.31",
|
|
18
18
|
"sequelize": "6.35.2",
|
|
19
19
|
"dayjs": "1.11.10"
|
|
20
20
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
{
|
|
2
|
+
"field-name-exists": "Il nome del campo \"{{name}}\" esiste già nella raccolta \"{{collectionName}}\"",
|
|
3
|
+
"field-is-depended-on-by-other": "Impossibile eliminare il campo \"{{fieldName}}\" in \"{{fieldCollectionName}}\", è utilizzato dal campo \"{{dependedFieldName}}\" in \"{{dependedFieldCollectionName}}\" come \"{{dependedFieldAs}}\""
|
|
4
|
+
}
|
|
@@ -83,7 +83,7 @@ function afterCreateForForeignKeyField(db) {
|
|
|
83
83
|
}
|
|
84
84
|
return data;
|
|
85
85
|
}
|
|
86
|
-
async function createFieldIfNotExists({ values, transaction }) {
|
|
86
|
+
async function createFieldIfNotExists({ values, transaction, interfaceType = null }) {
|
|
87
87
|
const { collectionName, name } = values;
|
|
88
88
|
if (!collectionName || !name) {
|
|
89
89
|
throw new Error(`field options invalid`);
|
|
@@ -104,13 +104,17 @@ function afterCreateForForeignKeyField(db) {
|
|
|
104
104
|
instance.set("isForeignKey", true);
|
|
105
105
|
await instance.save({ transaction });
|
|
106
106
|
} else {
|
|
107
|
-
const
|
|
107
|
+
const createOptions = {
|
|
108
108
|
values: {
|
|
109
109
|
isForeignKey: true,
|
|
110
110
|
...values
|
|
111
111
|
},
|
|
112
112
|
transaction
|
|
113
|
-
}
|
|
113
|
+
};
|
|
114
|
+
if (interfaceType === "m2o") {
|
|
115
|
+
createOptions["context"] = {};
|
|
116
|
+
}
|
|
117
|
+
const creatInstance = await r.create(createOptions);
|
|
114
118
|
creatInstance.set("sort", 1);
|
|
115
119
|
await creatInstance.save({ transaction });
|
|
116
120
|
}
|
|
@@ -149,13 +153,15 @@ function afterCreateForForeignKeyField(db) {
|
|
|
149
153
|
collectionName: target,
|
|
150
154
|
...values
|
|
151
155
|
},
|
|
156
|
+
interfaceType,
|
|
152
157
|
transaction
|
|
153
158
|
});
|
|
154
159
|
} else if (["obo", "m2o"].includes(interfaceType)) {
|
|
155
160
|
const values = generateFkOptions(collectionName, foreignKey);
|
|
156
161
|
await createFieldIfNotExists({
|
|
157
162
|
values: { collectionName, ...values },
|
|
158
|
-
transaction
|
|
163
|
+
transaction,
|
|
164
|
+
interfaceType
|
|
159
165
|
});
|
|
160
166
|
} else if (["linkTo", "m2m"].includes(interfaceType)) {
|
|
161
167
|
if (type !== "belongsToMany") {
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { Migration } from '@nocobase/server';
|
|
10
|
+
export default class extends Migration {
|
|
11
|
+
on: string;
|
|
12
|
+
up(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var update_bigint_to_unixtimestamp_exports = {};
|
|
28
|
+
__export(update_bigint_to_unixtimestamp_exports, {
|
|
29
|
+
default: () => update_bigint_to_unixtimestamp_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(update_bigint_to_unixtimestamp_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
/* istanbul ignore file -- @preserve */
|
|
34
|
+
class update_bigint_to_unixtimestamp_default extends import_server.Migration {
|
|
35
|
+
on = "afterLoad";
|
|
36
|
+
async up() {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const Field = this.context.db.getRepository("fields");
|
|
39
|
+
const fields = await Field.find({
|
|
40
|
+
filter: {
|
|
41
|
+
interface: "unixTimestamp",
|
|
42
|
+
type: "bigInt"
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
for (const field of fields) {
|
|
46
|
+
const uiSchema = field.get("uiSchema");
|
|
47
|
+
uiSchema["x-component-props"] = {
|
|
48
|
+
picker: "date",
|
|
49
|
+
dateFormat: "YYYY-MM-DD",
|
|
50
|
+
timeFormat: "HH:mm:ss",
|
|
51
|
+
showTime: ((_a = uiSchema["x-component-props"]) == null ? void 0 : _a.showTime) || true,
|
|
52
|
+
accuracy: ((_b = uiSchema["x-component-props"]) == null ? void 0 : _b.accuracy) || "second"
|
|
53
|
+
};
|
|
54
|
+
field.set("type", "unixTimestamp");
|
|
55
|
+
field.set("uiSchema", uiSchema);
|
|
56
|
+
await field.save();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { Migration } from '@nocobase/server';
|
|
10
|
+
export default class extends Migration {
|
|
11
|
+
on: string;
|
|
12
|
+
up(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var remove_schema_options_exports = {};
|
|
28
|
+
__export(remove_schema_options_exports, {
|
|
29
|
+
default: () => remove_schema_options_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(remove_schema_options_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
/* istanbul ignore file -- @preserve */
|
|
34
|
+
class remove_schema_options_default extends import_server.Migration {
|
|
35
|
+
on = "afterLoad";
|
|
36
|
+
async up() {
|
|
37
|
+
const CollectionRepository = this.context.db.getRepository("collections");
|
|
38
|
+
const collections = await CollectionRepository.find({
|
|
39
|
+
filter: {
|
|
40
|
+
"options.from": "db2cm"
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
for (const collection of collections) {
|
|
44
|
+
const collectionSchema = collection.get("schema");
|
|
45
|
+
const dbSchema = this.context.db.options.schema || "public";
|
|
46
|
+
if (collectionSchema && collectionSchema == dbSchema) {
|
|
47
|
+
collection.set("schema", void 0);
|
|
48
|
+
await collection.save();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __export = (target, all) => {
|
|
15
17
|
for (var name in all)
|
|
@@ -23,6 +25,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
25
|
}
|
|
24
26
|
return to;
|
|
25
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
|
+
));
|
|
26
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
37
|
var field_exports = {};
|
|
28
38
|
__export(field_exports, {
|
|
@@ -30,6 +40,7 @@ __export(field_exports, {
|
|
|
30
40
|
});
|
|
31
41
|
module.exports = __toCommonJS(field_exports);
|
|
32
42
|
var import_database = require("@nocobase/database");
|
|
43
|
+
var import_lodash = __toESM(require("lodash"));
|
|
33
44
|
class FieldModel extends import_database.MagicAttributeModel {
|
|
34
45
|
get db() {
|
|
35
46
|
return this.constructor.database;
|
|
@@ -48,10 +59,13 @@ class FieldModel extends import_database.MagicAttributeModel {
|
|
|
48
59
|
if (skipExist && collection.hasField(name)) {
|
|
49
60
|
return collection.getField(name);
|
|
50
61
|
}
|
|
51
|
-
const options = this.
|
|
62
|
+
const options = this.toJSON();
|
|
52
63
|
const field = await (async () => {
|
|
53
64
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
54
|
-
return collection.setField(name,
|
|
65
|
+
return collection.setField(name, {
|
|
66
|
+
...options,
|
|
67
|
+
__sort: this.get("sort")
|
|
68
|
+
});
|
|
55
69
|
})();
|
|
56
70
|
await this.db.emitAsync("field:loaded", {
|
|
57
71
|
fieldKey: this.get("key"),
|
|
@@ -169,6 +183,13 @@ class FieldModel extends import_database.MagicAttributeModel {
|
|
|
169
183
|
}
|
|
170
184
|
return this.db.getCollection(collectionName);
|
|
171
185
|
}
|
|
186
|
+
toJSON() {
|
|
187
|
+
const json = super.toJSON();
|
|
188
|
+
if (json.interface === "unixTimestamp" && json.accuracy) {
|
|
189
|
+
import_lodash.default.set(json, "uiSchema.x-component-props.accuracy", json.accuracy);
|
|
190
|
+
}
|
|
191
|
+
return json;
|
|
192
|
+
}
|
|
172
193
|
}
|
|
173
194
|
// Annotate the CommonJS export names for ESM import in node:
|
|
174
195
|
0 && (module.exports = {
|
|
@@ -153,9 +153,13 @@ class CollectionRepository extends import_database.Repository {
|
|
|
153
153
|
...field.options
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
|
+
const collectionOptions = options;
|
|
157
|
+
if (collectionOptions.schema && collectionOptions.schema == (this.database.options.schema || "public")) {
|
|
158
|
+
delete collectionOptions.schema;
|
|
159
|
+
}
|
|
156
160
|
await this.create({
|
|
157
161
|
values: {
|
|
158
|
-
...
|
|
162
|
+
...collectionOptions,
|
|
159
163
|
fields,
|
|
160
164
|
from: "db2cm"
|
|
161
165
|
}
|
package/dist/server/server.js
CHANGED
|
@@ -45,16 +45,16 @@ var import_server = require("@nocobase/server");
|
|
|
45
45
|
var import_lodash = __toESM(require("lodash"));
|
|
46
46
|
var import_path = __toESM(require("path"));
|
|
47
47
|
var import__ = require(".");
|
|
48
|
+
var import_field_is_depended_on_by_other = require("./errors/field-is-depended-on-by-other");
|
|
49
|
+
var import_field_name_exists_error = require("./errors/field-name-exists-error");
|
|
48
50
|
var import_hooks = require("./hooks");
|
|
51
|
+
var import_beforeCreateCheckFieldInMySQL = require("./hooks/beforeCreateCheckFieldInMySQL");
|
|
49
52
|
var import_beforeCreateForValidateField = require("./hooks/beforeCreateForValidateField");
|
|
50
53
|
var import_beforeCreateForViewCollection = require("./hooks/beforeCreateForViewCollection");
|
|
54
|
+
var import_beforeDestoryField = require("./hooks/beforeDestoryField");
|
|
51
55
|
var import_models = require("./models");
|
|
52
56
|
var import_collections = __toESM(require("./resourcers/collections"));
|
|
53
57
|
var import_views = __toESM(require("./resourcers/views"));
|
|
54
|
-
var import_field_name_exists_error = require("./errors/field-name-exists-error");
|
|
55
|
-
var import_beforeDestoryField = require("./hooks/beforeDestoryField");
|
|
56
|
-
var import_field_is_depended_on_by_other = require("./errors/field-is-depended-on-by-other");
|
|
57
|
-
var import_beforeCreateCheckFieldInMySQL = require("./hooks/beforeCreateCheckFieldInMySQL");
|
|
58
58
|
class PluginDataSourceMainServer extends import_server.Plugin {
|
|
59
59
|
loadFilter = {};
|
|
60
60
|
setLoadFilter(filter) {
|
|
@@ -103,6 +103,11 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
this.app.db.on("collections.beforeCreate", (0, import_beforeCreateForViewCollection.beforeCreateForViewCollection)(this.db));
|
|
106
|
+
this.app.db.on("collections.beforeCreate", async (model, options) => {
|
|
107
|
+
if (this.app.db.getCollection(model.get("name")) && model.get("from") !== "db2cm" && !model.get("isThrough")) {
|
|
108
|
+
throw new Error(`Collection named ${model.get("name")} already exists`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
106
111
|
this.app.db.on(
|
|
107
112
|
"collections.afterSaveWithAssociations",
|
|
108
113
|
async (model, { context, transaction }) => {
|
|
@@ -324,6 +329,25 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
324
329
|
}
|
|
325
330
|
await next();
|
|
326
331
|
});
|
|
332
|
+
this.app.resourceManager.use(async function pushUISchemaWhenUpdateCollectionField(ctx, next) {
|
|
333
|
+
var _a;
|
|
334
|
+
const { resourceName, actionName } = ctx.action;
|
|
335
|
+
if (resourceName === "collections" && actionName === "create") {
|
|
336
|
+
const { values } = ctx.action.params;
|
|
337
|
+
const keys = Object.keys(values);
|
|
338
|
+
const presetKeys = ["createdAt", "createdBy", "updatedAt", "updatedBy"];
|
|
339
|
+
for (const presetKey of presetKeys) {
|
|
340
|
+
if (keys.includes(presetKey)) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
values[presetKey] = !!((_a = values.fields) == null ? void 0 : _a.find((v) => v.name === presetKey));
|
|
344
|
+
}
|
|
345
|
+
ctx.action.mergeParams({
|
|
346
|
+
values
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
await next();
|
|
350
|
+
});
|
|
327
351
|
this.app.acl.allow("collections", "list", "loggedIn");
|
|
328
352
|
this.app.acl.allow("collections", "listMeta", "loggedIn");
|
|
329
353
|
this.app.acl.allow("collectionCategories", "list", "loggedIn");
|
|
@@ -337,7 +361,6 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
337
361
|
});
|
|
338
362
|
}
|
|
339
363
|
async load() {
|
|
340
|
-
await this.importCollections(import_path.default.resolve(__dirname, "./collections"));
|
|
341
364
|
this.db.getRepository("collections").setApp(this.app);
|
|
342
365
|
const errorHandlerPlugin = this.app.getPlugin("error-handler");
|
|
343
366
|
errorHandlerPlugin.errorHandler.register(
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "数据源:主数据库",
|
|
5
5
|
"description": "NocoBase main database, supports relational databases such as PostgreSQL, MySQL, MariaDB and so on.",
|
|
6
6
|
"description.zh-CN": "NocoBase 主数据库,支持 PostgreSQL、MySQL、MariaDB 等关系型数据库。",
|
|
7
|
-
"version": "1.6.0-alpha.
|
|
7
|
+
"version": "1.6.0-alpha.31",
|
|
8
8
|
"main": "./dist/server/index.js",
|
|
9
9
|
"homepage": "https://docs.nocobase.com/handbook/data-source-main",
|
|
10
10
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/data-source-main",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@nocobase/test": "1.x",
|
|
23
23
|
"@nocobase/utils": "1.x"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "2f118f0a0691dd51c437f208b1166258a615b6a8",
|
|
26
26
|
"keywords": [
|
|
27
27
|
"Data sources"
|
|
28
28
|
]
|