@nocobase/plugin-data-source-main 2.0.0-alpha.53 → 2.0.0-alpha.54

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.
@@ -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("lodash"),require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-data-source-main",["lodash","@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-data-source-main"]=t(require("lodash"),require("@nocobase/client")):e["@nocobase/plugin-data-source-main"]=t(e.lodash,e["@nocobase/client"])}(self,function(e,t){return function(){"use strict";var r={772:function(e){e.exports=t},467:function(t){t.exports=e}},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={};return!function(){o.r(i);var e=o(772),t=o(467);function r(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 n(e,t,r){return(n=l()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&c(o,r.prototype),o}).apply(null,arguments)}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){var t="function"==typeof Map?new Map:void 0;return(u=function(e){if(null===e||-1===Function.toString.call(e).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,r)}function r(){return n(e,arguments,a(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,e)})(e)}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}i.default=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function o(){var e,t,r,n,i;if(!(this instanceof o))throw TypeError("Cannot call a class as a function");return t=o,r=arguments,t=a(t),e=function(e,t){var r;if(t&&("object"==((r=t)&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,l()?Reflect.construct(t,r||[],a(this).constructor):t.apply(this,r)),i=[],(n="collectionPresetFields")in e?Object.defineProperty(e,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[n]=i,e}return o.prototype=Object.create(e&&e.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),e&&c(o,e),n=[{key:"addCollectionPresetField",value:function(e){this.collectionPresetFields.push(e)}},{key:"removeCollectionPresetField",value:function(e){this.collectionPresetFields=(0,t.reject)(this.collectionPresetFields,function(t){return t.value.name===e})}},{key:"getCollectionPresetFields",value:function(){return(0,t.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){var u=[i,c];if(r)throw TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,n=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(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:"id"}}),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,n=arguments;return new Promise(function(o,i){var a=e.apply(t,n);function c(e){r(a,o,i,c,u,"next",e)}function u(e){r(a,o,i,c,u,"throw",e)}c(void 0)})})()}}],function(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)}}(o.prototype,n),o}(u(e.Plugin))}(),i}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("lodash"),require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-data-source-main",["lodash","@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-data-source-main"]=t(require("lodash"),require("@nocobase/client")):e["@nocobase/plugin-data-source-main"]=t(e.lodash,e["@nocobase/client"])}(self,function(e,t){return function(){"use strict";var r={772:function(e){e.exports=t},467:function(t){t.exports=e}},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={};return!function(){o.r(i);var e=o(772),t=o(467);function r(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 n(e,t,r){return(n=l()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&c(o,r.prototype),o}).apply(null,arguments)}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){var t="function"==typeof Map?new Map:void 0;return(u=function(e){if(null===e||-1===Function.toString.call(e).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,r)}function r(){return n(e,arguments,a(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,e)})(e)}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}i.default=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function o(){var e,t,r,n,i;if(!(this instanceof o))throw TypeError("Cannot call a class as a function");return t=o,r=arguments,t=a(t),e=function(e,t){var r;if(t&&("object"==((r=t)&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,l()?Reflect.construct(t,r||[],a(this).constructor):t.apply(this,r)),i=[],(n="collectionPresetFields")in e?Object.defineProperty(e,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[n]=i,e}return o.prototype=Object.create(e&&e.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),e&&c(o,e),n=[{key:"addCollectionPresetField",value:function(e){this.collectionPresetFields.push(e)}},{key:"removeCollectionPresetField",value:function(e){this.collectionPresetFields=(0,t.reject)(this.collectionPresetFields,function(t){return t.value.name===e})}},{key:"getCollectionPresetFields",value:function(){return(0,t.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){var u=[i,c];if(r)throw TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,n=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(e){return t.addCollectionPresetField({order:100,description:'{{t("Primary key, distributed uniqueness, time-ordering") }}',value:{name:"id",type:"snowflakeId",autoIncrement:!1,primaryKey:!0,allowNull:!1,uiSchema:{type:"number",title:'{{t("ID")}}',"x-component":"InputNumber","x-component-props":{stringMode:!0,separator:"0.00",step:"1"},"x-validator":"integer"},interface:"snowflakeId"}}),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,n=arguments;return new Promise(function(o,i){var a=e.apply(t,n);function c(e){r(a,o,i,c,u,"next",e)}function u(e){r(a,o,i,c,u,"throw",e)}c(void 0)})})()}}],function(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)}}(o.prototype,n),o}(u(e.Plugin))}(),i}()});
@@ -8,15 +8,15 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.0.0-alpha.53",
11
+ "@nocobase/client": "2.0.0-alpha.54",
12
12
  "lodash": "4.17.21",
13
- "@nocobase/database": "2.0.0-alpha.53",
14
- "@nocobase/plugin-error-handler": "2.0.0-alpha.53",
15
- "@nocobase/server": "2.0.0-alpha.53",
13
+ "@nocobase/database": "2.0.0-alpha.54",
14
+ "@nocobase/plugin-error-handler": "2.0.0-alpha.54",
15
+ "@nocobase/server": "2.0.0-alpha.54",
16
16
  "sequelize": "6.35.2",
17
17
  "@formily/json-schema": "2.3.7",
18
- "@nocobase/test": "2.0.0-alpha.53",
19
- "@nocobase/utils": "2.0.0-alpha.53",
20
- "@nocobase/actions": "2.0.0-alpha.53",
18
+ "@nocobase/test": "2.0.0-alpha.54",
19
+ "@nocobase/utils": "2.0.0-alpha.54",
20
+ "@nocobase/actions": "2.0.0-alpha.54",
21
21
  "dayjs": "1.11.13"
22
22
  };
@@ -0,0 +1,14 @@
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
+ appVersion: string;
13
+ up(): Promise<void>;
14
+ }
@@ -0,0 +1,48 @@
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 id2integer_exports = {};
28
+ __export(id2integer_exports, {
29
+ default: () => id2integer_default
30
+ });
31
+ module.exports = __toCommonJS(id2integer_exports);
32
+ var import_server = require("@nocobase/server");
33
+ class id2integer_default extends import_server.Migration {
34
+ on = "afterLoad";
35
+ // 'beforeLoad' or 'afterLoad'
36
+ appVersion = "<2.0.0";
37
+ async up() {
38
+ const repo = this.db.getRepository("fields");
39
+ await repo.update({
40
+ values: {
41
+ interface: "integer"
42
+ },
43
+ filter: {
44
+ interface: "id"
45
+ }
46
+ });
47
+ }
48
+ }
@@ -88,6 +88,9 @@ class CollectionModel extends import_database.MagicAttributeModel {
88
88
  if (!collectionOptions.dumpRules) {
89
89
  import_lodash.default.set(collectionOptions, "dumpRules.group", "custom");
90
90
  }
91
+ const fieldRepo = this.db.getRepository("collections.fields", name);
92
+ const fieldModels = await fieldRepo.find({ transaction });
93
+ collectionOptions["fieldModels"] = fieldModels;
91
94
  collection = this.db.collection(collectionOptions);
92
95
  }
93
96
  if (!skipField) {
@@ -173,17 +176,17 @@ class CollectionModel extends import_database.MagicAttributeModel {
173
176
  collectionName: field.get("collectionName")
174
177
  };
175
178
  });
176
- const beforePendingFields = getPendingField();
177
- const collection = await this.load({
178
- transaction: options == null ? void 0 : options.transaction
179
- });
180
- const afterPendingFields = getPendingField();
181
- const resolvedPendingFields = import_lodash.default.differenceWith(beforePendingFields, afterPendingFields, import_lodash.default.isEqual);
182
- const resolvedPendingFieldsCollections = import_lodash.default.uniq(resolvedPendingFields.map((field) => field.collectionName));
183
- if (Object.keys(collection.model.tableAttributes).length == 0 && !this.db.inDialect("postgres")) {
184
- return;
185
- }
186
179
  try {
180
+ const beforePendingFields = getPendingField();
181
+ const collection = await this.load({
182
+ transaction: options == null ? void 0 : options.transaction
183
+ });
184
+ const afterPendingFields = getPendingField();
185
+ const resolvedPendingFields = import_lodash.default.differenceWith(beforePendingFields, afterPendingFields, import_lodash.default.isEqual);
186
+ const resolvedPendingFieldsCollections = import_lodash.default.uniq(resolvedPendingFields.map((field) => field.collectionName));
187
+ if (Object.keys(collection.model.tableAttributes).length == 0 && !this.db.inDialect("postgres")) {
188
+ return;
189
+ }
187
190
  const syncOptions = {
188
191
  force: false,
189
192
  alter: {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "NocoBase main database, supports relational databases such as PostgreSQL, MySQL, MariaDB and so on.",
7
7
  "description.ru-RU": "Основная база данных NocoBase: поддерживает реляционные СУБД, включая PostgreSQL, MySQL, MariaDB и другие.",
8
8
  "description.zh-CN": "NocoBase 主数据库,支持 PostgreSQL、MySQL、MariaDB 等关系型数据库。",
9
- "version": "2.0.0-alpha.53",
9
+ "version": "2.0.0-alpha.54",
10
10
  "main": "./dist/server/index.js",
11
11
  "homepage": "https://docs.nocobase.com/handbook/data-source-main",
12
12
  "homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/data-source-main",
@@ -25,7 +25,7 @@
25
25
  "@nocobase/test": "2.x",
26
26
  "@nocobase/utils": "2.x"
27
27
  },
28
- "gitHead": "ff30cf8261f5a97b3f24c3752af5bbc564167b37",
28
+ "gitHead": "68c84deaabba0ebec7407bf7245376b8d843449c",
29
29
  "keywords": [
30
30
  "Data sources"
31
31
  ]