corebasic 1.0.125 → 1.0.126

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/libs/elabase.js +18 -1
  2. package/package.json +1 -1
package/libs/elabase.js CHANGED
@@ -91,6 +91,7 @@ export const insert = async (meta, collection, value, _id) => {
91
91
  if (typeof value === "object" && !Array.isArray(value))
92
92
  value.company = meta.company
93
93
  }
94
+ value.outlet = value.outlet ?? meta.outlet
94
95
  // ---------------------
95
96
 
96
97
  var arg = {
@@ -102,6 +103,13 @@ export const insert = async (meta, collection, value, _id) => {
102
103
  if (_id)
103
104
  arg._id = _id
104
105
 
106
+ if (!(["string", "number"].includes(typeof arg?._id)))
107
+ throw {message: "Error: invalid _id in Dip.insert()"}
108
+ if (typeof arg?._id === "string" && arg._id.trim().length === 0)
109
+ throw {message: "Error: invalid _id in Dip.insert()"}
110
+
111
+ if ((!arg._id && arg._id !== 0))
112
+
105
113
  if (isTransaction) {
106
114
  transactions.push(arg)
107
115
  return
@@ -166,8 +174,17 @@ export const update = async (meta, collection, query, update, options) => {
166
174
  query.company = meta.company
167
175
  update.$set = update.$set ?? {}
168
176
  update.$set.company = meta.company
169
- if (update?.$setOnInsert)
177
+ if (options?.upsert) {
178
+ update.$setOnInsert = update.$setOnInsert ?? {}
170
179
  update.$setOnInsert.company = meta.company
180
+ update.$setOnInsert.outlet = update.$setOnInsert.outlet ?? update.$set?.outlet ?? meta.outlet
181
+
182
+ let _id = update.$setOnInsert._id ?? update.$set?._id ?? query?._id
183
+ if (!(["string", "number"].includes(typeof _id)))
184
+ throw {message: "Error: invalid _id in Dip.update() with upsert"}
185
+ if (typeof _id === "string" && _id.trim().length === 0)
186
+ throw {message: "Error: invalid _id in Dip.update() with upsert"}
187
+ }
171
188
  }
172
189
  // ---------------------
173
190
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.125",
4
+ "version": "1.0.126",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {