@xuda.io/xuda-dbs-plugin-xuda 1.0.113 → 1.0.115

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/studio.mjs +23 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-dbs-plugin-xuda",
3
- "version": "1.0.113",
3
+ "version": "1.0.115",
4
4
  "description": "Xuda Database Socket for Xuda's proprietary structure powered by CouchDB",
5
5
  "scripts": {
6
6
  "pub": "npm version patch --force && npm publish --access public"
package/studio.mjs CHANGED
@@ -1,4 +1,6 @@
1
- const check_unique = async function (e, docP, table_obj, db) {
1
+ var _this = {};
2
+
3
+ export const check_unique = async function (e, docP, table_obj, db) {
2
4
  var len = docP.udfIndex.length;
3
5
  if (!len) {
4
6
  return { code: -11, data: "table must have primary index" };
@@ -168,19 +170,20 @@ const find_item_by_key = function (arr, key, val) {
168
170
  });
169
171
  };
170
172
 
171
- const get_cast_val = async function (source, attributeP, typeP, valP) {
172
- return xu_cast(
173
- typeP,
174
- valP,
175
- function (res) {
176
- var msg = `error converting ${attributeP} from ${valP} to ${typeP}`;
177
- console.error(source, msg);
178
- },
179
- function (res) {
180
- var msg = `type mismatch auto conversion made to ${attributeP} from value ${valP} to ${typeP}`;
181
- console.warn(source, msg);
182
- }
183
- );
173
+ const get_cast_val = async function (e, source, attributeP, typeP, valP) {
174
+ const success = function (res) {
175
+ var msg = `error converting ${attributeP} from ${valP} to ${typeP}`;
176
+ console.error(source, msg);
177
+ };
178
+ const fail = function (res) {
179
+ var msg = `type mismatch auto conversion made to ${attributeP} from value ${valP} to ${typeP}`;
180
+ console.warn(source, msg);
181
+ };
182
+
183
+ if (_this.xu_cast) {
184
+ return e.xu_cast(typeP, valP, success, fail);
185
+ }
186
+ return xu_cast(typeP, valP, success, fail);
184
187
  };
185
188
 
186
189
  const get_opt = function (e, table_obj) {
@@ -1288,7 +1291,7 @@ export const create = async (params, resolve, reject) => {
1288
1291
  if (index_ret < 0) throw index_ret.data;
1289
1292
  doc.udfIndex = index_ret.data;
1290
1293
 
1291
- const ret = await check_unique(e, doc, table_obj, db);
1294
+ const ret = await this.check_unique(e, doc, table_obj, db);
1292
1295
  if (ret.code < 0) {
1293
1296
  throw ret;
1294
1297
  }
@@ -1324,7 +1327,7 @@ export const create = async (params, resolve, reject) => {
1324
1327
  return index_ret;
1325
1328
  }
1326
1329
  doc.udfIndex = index_ret.data;
1327
- const ret = await check_unique(e, doc, table_obj, db);
1330
+ const ret = await this.check_unique(e, doc, table_obj, db);
1328
1331
  if (ret.code < 0) {
1329
1332
  return reject(ret.data);
1330
1333
  }
@@ -1420,7 +1423,7 @@ export const update = async (params, resolve, reject) => {
1420
1423
  return index_ret;
1421
1424
  }
1422
1425
  doc.udfIndex = index_ret.data;
1423
- const ret = await check_unique(e, doc, table_obj, db);
1426
+ const ret = await this.check_unique(e, doc, table_obj, db);
1424
1427
  if (ret.code < 0) {
1425
1428
  return ret;
1426
1429
  }
@@ -1523,3 +1526,6 @@ export const create_design = async (params, resolve, reject) => {
1523
1526
  return resolve(err);
1524
1527
  }
1525
1528
  };
1529
+ export const init_module = async (params) => {
1530
+ _this.xu_cast = params.xu_cast;
1531
+ };