corebasic 1.0.180 → 1.0.181

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 +52 -0
  2. package/package.json +1 -1
package/libs/elabase.js CHANGED
@@ -54,6 +54,54 @@ export function start(dbName) {
54
54
  }
55
55
  }
56
56
 
57
+ function generate_suffix(meta) {
58
+
59
+ if (!meta || typeof meta !== 'object') {
60
+ throw {message: "Dip Error. Invalid meta"}
61
+ }
62
+ if ((typeof meta.company === 'string' && meta.company.trim() === "") || (typeof meta.company !== 'string' && !Array.isArray(meta.company)) || (Array.isArray(meta.company) && (!meta.company.length || meta.company.some(item => typeof item !== "string"|| item.trim() === "")))) {
63
+ throw {message: "Dip Error. Invalid meta.company"}
64
+ }
65
+ if ((typeof meta.outlet === 'string' && meta.outlet.trim() === "") || (typeof meta.outlet !== 'string' && !Array.isArray(meta.outlet)) || (Array.isArray(meta.outlet) && (!meta.outlet.length || meta.outlet.some(item => typeof item !== "string" || item.trim() === "")))) {
66
+ throw {message: "Dip Error. Invalid meta.outlet"}
67
+ }
68
+ if ((meta.suffix !== undefined && typeof meta.suffix !== 'string' && !Array.isArray(meta.suffix)) || (Array.isArray(meta.suffix) && meta.suffix.some(item => typeof item !== "string" || item.trim() === ""))) {
69
+ throw {message: "Dip Error. Invalid meta.suffix"}
70
+ } else if (typeof meta.suffix === 'string' && meta.suffix.trim() === "")
71
+ throw {message: "Dip Error. Invalid meta.suffix"}
72
+
73
+
74
+ let company = typeof meta.company == 'string' ? [meta.company] : (meta.company?.length ? meta.company : [])
75
+ let outlet = typeof meta.outlet == 'string' ? [meta.outlet] : (meta.outlet?.length ? meta.outlet : [])
76
+ let suffix = typeof meta.suffix == 'string' ? [meta.suffix] : (meta.suffix?.length ? meta.suffix : [])
77
+
78
+ company = company.filter(item => item.trim() !== "")
79
+ outlet = outlet.filter(item => item.trim() !== "")
80
+ suffix = suffix.filter(item => item.trim() !== "")
81
+
82
+ company = company.length ? company : [""]
83
+ outlet = outlet.length ? outlet : [""]
84
+ suffix = suffix.length ? suffix : [""]
85
+
86
+ company = new Set(company)
87
+ outlet = new Set(outlet)
88
+ suffix = new Set(suffix)
89
+
90
+ // console.log(company, outlet, suffix)
91
+ let suffixes = []
92
+ for (let c of company) {
93
+ for (let o of outlet) {
94
+ for (let s of suffix) {
95
+ let pathSegments = [c, o, s].filter(segment => segment !== "");
96
+ if (pathSegments.length > 0) {
97
+ suffixes.push(pathSegments.join('/'));
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ return suffixes
104
+ }
57
105
 
58
106
  let isBranch = false
59
107
  let batches = []
@@ -101,6 +149,7 @@ export const insert = async (meta, collection, value, _id, extras) => {
101
149
 
102
150
  var arg = {
103
151
  collection: collection,
152
+ suffix: generate_suffix(meta),
104
153
  insert: value,
105
154
  ...(meta.DIP_URL ? {DIP_URL: meta.DIP_URL} : {}),
106
155
  ...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
@@ -144,6 +193,7 @@ export const query = async (meta, collection, query, options, extras) => {
144
193
 
145
194
  var arg = {
146
195
  collection: collection,
196
+ suffix: generate_suffix(meta),
147
197
  query: query,
148
198
  options: options ? options : {},
149
199
  ...(meta.DIP_URL ? {DIP_URL: meta.DIP_URL} : {}),
@@ -202,6 +252,7 @@ export const update = async (meta, collection, query, update, options, extras) =
202
252
 
203
253
  var arg = {
204
254
  collection: collection,
255
+ suffix: generate_suffix(meta),
205
256
  query: query,
206
257
  update: update,
207
258
  options: options ? options : {},
@@ -237,6 +288,7 @@ export const remove = async (meta, collection, query, options, extras) => {
237
288
 
238
289
  var arg = {
239
290
  collection: collection,
291
+ suffix: generate_suffix(meta),
240
292
  query: query,
241
293
  delete: true,
242
294
  options: options ? options : {},
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.180",
4
+ "version": "1.0.181",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {