corebasic 1.0.187 → 1.0.189

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.
package/libs/dip.js CHANGED
@@ -12,7 +12,7 @@ export const batchBegin = Elabase.batchBegin
12
12
  export const batchAbort = Elabase.batchAbort
13
13
  export const batchSubmit = Elabase.batchSubmit
14
14
  export const batch = Elabase.batch
15
- export const global = Elabase.global
15
+ export const globalMeta = Elabase.globalMeta
16
16
 
17
17
  export const shard_stats = Elabase.shard_stats
18
18
  export let config = Elabase.config
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,15 +40,15 @@ 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
 
57
- export const global = args => {
51
+ export const globalMeta = args => {
58
52
  let obj = { ...args, company: "GLOBAL", outlet: "GLOBAL" }
59
53
  return {
60
54
  ...obj,
@@ -168,6 +162,63 @@ 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
+ Utils.log(config, meta)
202
+ throw {message: `Error: Incompatible meta.outlet config for collection: ${collection}${suffix ? ' suffix: ' + suffix : ''}${fn_name ? ` in ${fn_name}` : ''}`}
203
+ }
204
+ }
205
+
206
+ check_core_meta(config, meta)
207
+
208
+ if (config.suffix && meta.suffix) {
209
+ if (!config.suffix[meta.suffix]) {
210
+ console.warn(`Warn: Nonexistant suffix config for collection: ${collection} suffix:${meta.suffix}${fn_name ? ` in ${fn_name}` : ''}`)
211
+ return new_meta
212
+ }
213
+ check_core_meta(config.suffix[meta.suffix], meta, meta.suffix)
214
+ new_meta = Object.assign({}, {...config, suffix: undefined, company: undefined, outlet: undefined}, {...config.suffix[meta.suffix], company: undefined, outlet: undefined}, meta)
215
+ } else {
216
+ new_meta = Object.assign({}, {...config, suffix: undefined, company: undefined, outlet: undefined}, {company: undefined, outlet: undefined}, meta)
217
+ }
218
+
219
+ return new_meta
220
+ }
221
+
171
222
  export const operation = async (name, extras) => {
172
223
  return execute({ operation: name, ...extras })
173
224
  }
@@ -179,6 +230,8 @@ export const insert = async (meta, collection, value, _id, extras) => {
179
230
 
180
231
  validate_meta(meta, 'in Dip.insert()')
181
232
 
233
+ const topology_meta = validate_topology(meta, collection, 'in Dip.insert()')
234
+
182
235
  var arg = {
183
236
  collection: collection,
184
237
  suffix: generate_suffix(meta),
@@ -187,6 +240,7 @@ export const insert = async (meta, collection, value, _id, extras) => {
187
240
  ...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
188
241
  }
189
242
  arg = Object.assign(arg, extras)
243
+ arg = Object.assign({}, topology_meta, arg)
190
244
  if (_id)
191
245
  arg._id = _id
192
246
 
@@ -217,6 +271,8 @@ export const query = async (meta, collection, query, options, extras) => {
217
271
 
218
272
  validate_meta(meta, 'in Dip.query()')
219
273
 
274
+ const topology_meta = validate_topology(meta, collection, 'in Dip.query()')
275
+
220
276
  var arg = {
221
277
  collection: collection,
222
278
  suffix: generate_suffix(meta),
@@ -226,6 +282,7 @@ export const query = async (meta, collection, query, options, extras) => {
226
282
  ...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
227
283
  }
228
284
  arg = Object.assign(arg, extras)
285
+ arg = Object.assign({}, topology_meta, arg)
229
286
  if (meta.batch) {
230
287
  if (!batches[meta.batch])
231
288
  throw {message: 'Error: Invalid batch in Dip.query()'}
@@ -261,6 +318,8 @@ export const update = async (meta, collection, query, update, options, extras) =
261
318
 
262
319
  validate_meta(meta, 'in Dip.update()')
263
320
 
321
+ const topology_meta = validate_topology(meta, collection, 'in Dip.update()')
322
+
264
323
  var arg = {
265
324
  collection: collection,
266
325
  suffix: generate_suffix(meta),
@@ -271,6 +330,7 @@ export const update = async (meta, collection, query, update, options, extras) =
271
330
  ...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
272
331
  }
273
332
  arg = Object.assign(arg, extras)
333
+ arg = Object.assign({}, topology_meta, arg)
274
334
  if (meta.batch) {
275
335
  if (!batches[meta.batch])
276
336
  throw {message: 'Error: Invalid batch in Dip.update()'}
@@ -295,6 +355,8 @@ export const remove = async (meta, collection, query, options, extras) => {
295
355
 
296
356
  validate_meta(meta, 'in Dip.remove()')
297
357
 
358
+ const topology_meta = validate_topology(meta, collection, 'in Dip.remove()')
359
+
298
360
  var arg = {
299
361
  collection: collection,
300
362
  suffix: generate_suffix(meta),
@@ -305,6 +367,7 @@ export const remove = async (meta, collection, query, options, extras) => {
305
367
  ...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
306
368
  }
307
369
  arg = Object.assign(arg, extras)
370
+ arg = Object.assign({}, topology_meta, arg)
308
371
  if (meta.batch) {
309
372
  if (!batches[meta.batch])
310
373
  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.187",
4
+ "version": "1.0.189",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {