corebasic 1.0.188 → 1.0.190

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 +69 -8
  2. package/package.json +1 -1
package/libs/elabase.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import axios from 'axios'
2
2
  import {default as dipper, shard_stats as ShardStats} from './dipper.js'
3
+ import * as Utils from './utils.js'
3
4
 
4
5
 
5
6
 
@@ -10,13 +11,6 @@ export const shard_stats = ShardStats
10
11
 
11
12
 
12
13
 
13
-
14
-
15
- let Utils = {
16
- isEmpty: function(arg) { return arg === "" || arg == undefined || !arg ? true : false },
17
- requisites: { startElabase: function () { } }
18
- }
19
-
20
14
  let Events = {
21
15
  send: function() { }
22
16
  }
@@ -46,11 +40,11 @@ let internal = {
46
40
 
47
41
  let db = internal.db // default database
48
42
 
43
+
49
44
  export function start(dbName) {
50
45
  if (!Utils.isEmpty(dbName) && Utils.isEmpty(db)) {
51
46
  internal.db = "data/" + dbName
52
47
  db = "data/" + dbName
53
- Utils.requisites.startElabase()
54
48
  }
55
49
  }
56
50
 
@@ -168,6 +162,61 @@ export function batchSubmit(batch, arg) {
168
162
  })
169
163
  }
170
164
 
165
+
166
+ const COLLECTIONS_JSON = await (async () => {
167
+ try {
168
+ return await Utils.fileToJson(new URL('../../..', import.meta.url), 'collections.json')
169
+ } catch(e) {
170
+ console.error(e)
171
+ console.warn("Warn: Dip Failed to load collections.json. Semantics, topology and legality enforcement is not active")
172
+ }
173
+ })();
174
+
175
+ function init_collections_config() {
176
+ for (let collection in COLLECTIONS_JSON) {
177
+ let config = COLLECTIONS_JSON[collection]
178
+ if (config.suffix !== undefined && (typeof config.suffix !== "object" || Array.isArray(config.suffix)) ) {
179
+ throw {message: `Error: Initiating collection configs failed. Invalid suffix in collection: ${collection}`}
180
+ }
181
+ }
182
+ }
183
+ if (COLLECTIONS_JSON)
184
+ init_collections_config()
185
+
186
+
187
+ function validate_topology(meta, collection, fn_name) {
188
+
189
+ let new_meta = meta
190
+
191
+ let config = COLLECTIONS_JSON?.[collection]
192
+ if (!config) {
193
+ console.warn(`Warn: Nonexistant config for collection: ${collection}${fn_name ? ` in ${fn_name}` : ''}`)
194
+ return new_meta
195
+ }
196
+
197
+ function check_core_meta(config, meta, suffix) {
198
+ if (config.company !== meta.company && typeof config.company !== "object")
199
+ throw {message: `Error: Incompatible meta.company config for collection: ${collection}${suffix ? ' suffix: ' + suffix : ''}${fn_name ? ` in ${fn_name}` : ''}`}
200
+ if (config.outlet !== meta.outlet && typeof config.outlet !== "object")
201
+ throw {message: `Error: Incompatible meta.outlet config for collection: ${collection}${suffix ? ' suffix: ' + suffix : ''}${fn_name ? ` in ${fn_name}` : ''}`}
202
+ }
203
+
204
+ check_core_meta(config, meta)
205
+
206
+ if (config.suffix && meta.suffix) {
207
+ if (!config.suffix[meta.suffix]) {
208
+ console.warn(`Warn: Nonexistant suffix config for collection: ${collection} suffix:${meta.suffix}${fn_name ? ` in ${fn_name}` : ''}`)
209
+ return new_meta
210
+ }
211
+ check_core_meta(config.suffix[meta.suffix], meta, meta.suffix)
212
+ new_meta = Object.assign({}, {...config, suffix: undefined, company: undefined, outlet: undefined}, {...config.suffix[meta.suffix], company: undefined, outlet: undefined}, meta)
213
+ } else {
214
+ new_meta = Object.assign({}, {...config, suffix: undefined, company: undefined, outlet: undefined}, {company: undefined, outlet: undefined}, meta)
215
+ }
216
+
217
+ return new_meta
218
+ }
219
+
171
220
  export const operation = async (name, extras) => {
172
221
  return execute({ operation: name, ...extras })
173
222
  }
@@ -179,6 +228,8 @@ export const insert = async (meta, collection, value, _id, extras) => {
179
228
 
180
229
  validate_meta(meta, 'in Dip.insert()')
181
230
 
231
+ const topology_meta = validate_topology(meta, collection, 'in Dip.insert()')
232
+
182
233
  var arg = {
183
234
  collection: collection,
184
235
  suffix: generate_suffix(meta),
@@ -187,6 +238,7 @@ export const insert = async (meta, collection, value, _id, extras) => {
187
238
  ...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
188
239
  }
189
240
  arg = Object.assign(arg, extras)
241
+ arg = Object.assign({}, topology_meta, arg)
190
242
  if (_id)
191
243
  arg._id = _id
192
244
 
@@ -217,6 +269,8 @@ export const query = async (meta, collection, query, options, extras) => {
217
269
 
218
270
  validate_meta(meta, 'in Dip.query()')
219
271
 
272
+ const topology_meta = validate_topology(meta, collection, 'in Dip.query()')
273
+
220
274
  var arg = {
221
275
  collection: collection,
222
276
  suffix: generate_suffix(meta),
@@ -226,6 +280,7 @@ export const query = async (meta, collection, query, options, extras) => {
226
280
  ...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
227
281
  }
228
282
  arg = Object.assign(arg, extras)
283
+ arg = Object.assign({}, topology_meta, arg)
229
284
  if (meta.batch) {
230
285
  if (!batches[meta.batch])
231
286
  throw {message: 'Error: Invalid batch in Dip.query()'}
@@ -261,6 +316,8 @@ export const update = async (meta, collection, query, update, options, extras) =
261
316
 
262
317
  validate_meta(meta, 'in Dip.update()')
263
318
 
319
+ const topology_meta = validate_topology(meta, collection, 'in Dip.update()')
320
+
264
321
  var arg = {
265
322
  collection: collection,
266
323
  suffix: generate_suffix(meta),
@@ -271,6 +328,7 @@ export const update = async (meta, collection, query, update, options, extras) =
271
328
  ...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
272
329
  }
273
330
  arg = Object.assign(arg, extras)
331
+ arg = Object.assign({}, topology_meta, arg)
274
332
  if (meta.batch) {
275
333
  if (!batches[meta.batch])
276
334
  throw {message: 'Error: Invalid batch in Dip.update()'}
@@ -295,6 +353,8 @@ export const remove = async (meta, collection, query, options, extras) => {
295
353
 
296
354
  validate_meta(meta, 'in Dip.remove()')
297
355
 
356
+ const topology_meta = validate_topology(meta, collection, 'in Dip.remove()')
357
+
298
358
  var arg = {
299
359
  collection: collection,
300
360
  suffix: generate_suffix(meta),
@@ -305,6 +365,7 @@ export const remove = async (meta, collection, query, options, extras) => {
305
365
  ...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
306
366
  }
307
367
  arg = Object.assign(arg, extras)
368
+ arg = Object.assign({}, topology_meta, arg)
308
369
  if (meta.batch) {
309
370
  if (!batches[meta.batch])
310
371
  throw {message: 'Error: Invalid batch in Dip.query()'}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.188",
4
+ "version": "1.0.190",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {