corebasic 1.0.206 → 1.0.208
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/suffix/date.js +103 -0
- package/libs/dip/suffix/index.js +249 -0
- package/libs/dip/suffix/policy.js +156 -0
- package/libs/dip/suffix/query.js +289 -0
- package/libs/dip/suffix/suffix.js +109 -0
- package/libs/dip/suffix/tests/date.test.js +416 -0
- package/libs/dip/suffix/tests/index.test.js +653 -0
- package/libs/dip/suffix/tests/policy.applySuffixPolicy.test.js +642 -0
- package/libs/dip/suffix/tests/policy.test.js +675 -0
- package/libs/dip/suffix/tests/suffix.test.js +622 -0
- package/libs/dip.js +3 -3
- package/libs/elabase.js +34 -30
- package/libs/features.js +3 -3
- package/package.json +1 -1
package/libs/elabase.js
CHANGED
|
@@ -2,7 +2,7 @@ import axios from 'axios'
|
|
|
2
2
|
import {default as dipper, shard_stats as ShardStats} from './dipper.js'
|
|
3
3
|
import * as Utils from './utils.js'
|
|
4
4
|
import * as Cpp from './cpp.js'
|
|
5
|
-
|
|
5
|
+
import {applySuffixPolicy} from './dip/suffix/policy.js'
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
@@ -74,17 +74,17 @@ export const globalMeta = args => {
|
|
|
74
74
|
}
|
|
75
75
|
export const companyMeta = (company, args) => {
|
|
76
76
|
if (typeof company !== "string" && !Array.isArray(company))
|
|
77
|
-
throw
|
|
77
|
+
throw new Error("Error: Invalid company provided in Dip.companyMeta()")
|
|
78
78
|
if (!company || (typeof company === "string" && company.trim() === "") || company === "GLOBAL" || (Array.isArray(company) && (!company.length || company.some(item => typeof item !== "string" || item.trim() === "" || item === "GLOBAL")) ))
|
|
79
|
-
throw
|
|
79
|
+
throw new Error("Error: Invalid company provided in Dip.companyMeta()")
|
|
80
80
|
|
|
81
81
|
return new DipMeta({...args, outlet: "GLOBAL", company})
|
|
82
82
|
}
|
|
83
83
|
export const outletMeta = (outlet, args) => {
|
|
84
84
|
if (typeof outlet !== "string" && !Array.isArray(outlet))
|
|
85
|
-
throw
|
|
85
|
+
throw new Error("Error: Invalid outlet provided in Dip.outletMeta()")
|
|
86
86
|
if (!outlet || (typeof outlet === "string" && outlet.trim() === "") || outlet === "GLOBAL" || (Array.isArray(outlet) && (!outlet.length || outlet.some(item => typeof item !== "string" || item.trim() === "" || item === "GLOBAL")) ))
|
|
87
|
-
throw
|
|
87
|
+
throw new Error("Error: Invalid outlet provided in Dip.outletMeta()")
|
|
88
88
|
|
|
89
89
|
return new DipMeta({...args, company: "GLOBAL", outlet})
|
|
90
90
|
}
|
|
@@ -92,38 +92,38 @@ export const outletMeta = (outlet, args) => {
|
|
|
92
92
|
export const customMeta = (company, outlet, args) => {
|
|
93
93
|
|
|
94
94
|
if (typeof company !== "string" && !Array.isArray(company))
|
|
95
|
-
throw
|
|
95
|
+
throw new Error("Error: Invalid company provided in Dip.customMeta()")
|
|
96
96
|
if (typeof outlet !== "string" && !Array.isArray(outlet))
|
|
97
|
-
throw
|
|
97
|
+
throw new Error("Error: Invalid outlet provided in Dip.customMeta()")
|
|
98
98
|
|
|
99
99
|
if (!company || (typeof company === "string" && company.trim() === "") || company === "GLOBAL" || (Array.isArray(company) && (!company.length || company.some(item => typeof item !== "string" || item.trim() === "" || item === "GLOBAL")) ))
|
|
100
|
-
throw
|
|
100
|
+
throw new Error("Error: Invalid company provided in Dip.customMeta()"}
|
|
101
101
|
if (!outlet || (typeof outlet === "string" && outlet.trim() === "") || outlet === "GLOBAL" || (Array.isArray(outlet) && (!outlet.length || outlet.some(item => typeof item !== "string" || item.trim() === "" || item === "GLOBAL")) ))
|
|
102
|
-
throw
|
|
102
|
+
throw new Error("Error: Invalid outlet provided in Dip.customMeta()")
|
|
103
103
|
|
|
104
104
|
return new DipMeta({...args, company, outlet})
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
function validate_collection(collection, fn_name) {
|
|
108
108
|
if ((typeof collection === 'string' && collection.trim() === "") || (typeof collection !== 'string' && !Array.isArray(collection)) || (Array.isArray(collection) && (!collection.length || collection.some(item => typeof item !== "string" || item.trim() === "")))) {
|
|
109
|
-
throw
|
|
109
|
+
throw new Error(`Error: Invalid collection ${fn_name}`)
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
function validate_meta(meta, fn_name) {
|
|
114
114
|
if (!meta || typeof meta !== 'object') {
|
|
115
|
-
throw
|
|
115
|
+
throw new Error(`Error: Invalid meta ${fn_name}`)
|
|
116
116
|
}
|
|
117
117
|
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() === "")))) {
|
|
118
|
-
throw
|
|
118
|
+
throw new Error(`Error: Invalid meta.company ${fn_name}`)
|
|
119
119
|
}
|
|
120
120
|
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() === "")))) {
|
|
121
|
-
throw
|
|
121
|
+
throw new Error(`Error: Invalid meta.outlet ${fn_name}`)
|
|
122
122
|
}
|
|
123
123
|
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() === ""))) {
|
|
124
|
-
throw
|
|
124
|
+
throw new Error(`Error: Invalid meta.suffix ${fn_name}`)
|
|
125
125
|
} else if (typeof meta.suffix === 'string' && meta.suffix.trim() === "")
|
|
126
|
-
throw
|
|
126
|
+
throw new Error(`Error: Invalid meta.suffix ${fn_name}`)
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
function generate_suffix(meta) {
|
|
@@ -202,7 +202,7 @@ export const batch = async (callback, arg) => { // Convenience function with aut
|
|
|
202
202
|
// Ported
|
|
203
203
|
export function batchSubmit(batch_id, arg) {
|
|
204
204
|
if (!batch_id || !batches[batch_id] || !batches[batch_id].length)
|
|
205
|
-
throw
|
|
205
|
+
throw new Error(`Error: Invalid batch in Dip.batchSubmit()`)
|
|
206
206
|
let txns = batches[batch_id]
|
|
207
207
|
const executor = arg?.executor ?? batches[batch_id].find(txn => txn.executor)?.executor
|
|
208
208
|
const syncMode = arg?.syncMode ?? batches[batch_id].find(txn => txn.syncMode)?.syncMode
|
|
@@ -231,7 +231,7 @@ export const schema = async (name) => {
|
|
|
231
231
|
} catch (e) {
|
|
232
232
|
// Delete the broken promise from cache so a retry can occur later
|
|
233
233
|
delete SCHEMAS_JSON_PROMISES[name]
|
|
234
|
-
throw
|
|
234
|
+
throw new Error(`Error: Failed to load schema ${name} in Dip`)
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
|
|
@@ -248,7 +248,7 @@ function init_collections_config() {
|
|
|
248
248
|
for (let collection in COLLECTIONS_JSON) {
|
|
249
249
|
let config = COLLECTIONS_JSON[collection]
|
|
250
250
|
if (config.suffix !== undefined && (typeof config.suffix !== "object" || Array.isArray(config.suffix)) ) {
|
|
251
|
-
throw
|
|
251
|
+
throw new Error(`Error: Initiating collection configs failed. Invalid suffix in collection: ${collection}`)
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
}
|
|
@@ -276,9 +276,9 @@ function validate_topology(meta, collection, fn_name) {
|
|
|
276
276
|
|
|
277
277
|
function check_core_meta(config, meta, suffix) {
|
|
278
278
|
if (config.company !== meta.company && typeof config.company !== "object")
|
|
279
|
-
throw
|
|
279
|
+
throw new Error(`Error: Incompatible meta.company config for collection: ${collection}${suffix ? ' suffix: ' + suffix : ''}${fn_name ? ` ${fn_name}` : ''}`)
|
|
280
280
|
if (config.outlet !== meta.outlet && typeof config.outlet !== "object")
|
|
281
|
-
throw
|
|
281
|
+
throw new Error(`Error: Incompatible meta.outlet config for collection: ${collection}${suffix ? ' suffix: ' + suffix : ''}${fn_name ? ` ${fn_name}` : ''}`)
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
check_core_meta(config, meta)
|
|
@@ -323,7 +323,8 @@ export const insert = async (meta, collection, value, options, extras) => {
|
|
|
323
323
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
324
324
|
}
|
|
325
325
|
arg = Object.assign(arg, extras)
|
|
326
|
-
arg.suffix =
|
|
326
|
+
arg.suffix = await applySuffixPolicy(COLLECTIONS_JSON, collection, arg.insert, true, arg)
|
|
327
|
+
arg.suffix = (arg.suffix ?? []).concat(generate_suffix(meta))
|
|
327
328
|
arg.executor = meta.executor ?? "native"
|
|
328
329
|
arg = Object.assign({}, topology_meta, arg)
|
|
329
330
|
if (options?._id) {
|
|
@@ -333,7 +334,7 @@ export const insert = async (meta, collection, value, options, extras) => {
|
|
|
333
334
|
|
|
334
335
|
if (meta.batch) {
|
|
335
336
|
if (!batches[meta.batch])
|
|
336
|
-
throw
|
|
337
|
+
throw new Error('Error: Invalid batch in Dip.insert()')
|
|
337
338
|
batches[meta.batch].push(arg)
|
|
338
339
|
return
|
|
339
340
|
}
|
|
@@ -365,12 +366,13 @@ export const query = async (meta, collection, query, options, extras) => {
|
|
|
365
366
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
366
367
|
}
|
|
367
368
|
arg = Object.assign(arg, extras)
|
|
368
|
-
arg.suffix =
|
|
369
|
+
arg.suffix = await applySuffixPolicy(COLLECTIONS_JSON, collection, arg.query, false, arg)
|
|
370
|
+
arg.suffix = (arg.suffix ?? []).concat(generate_suffix(meta))
|
|
369
371
|
arg.executor = meta.executor ?? "native"
|
|
370
372
|
arg = Object.assign({}, topology_meta, arg)
|
|
371
373
|
if (meta.batch) {
|
|
372
374
|
if (!batches[meta.batch])
|
|
373
|
-
throw
|
|
375
|
+
throw new Error('Error: Invalid batch in Dip.query()')
|
|
374
376
|
batches[meta.batch].push(arg)
|
|
375
377
|
return
|
|
376
378
|
}
|
|
@@ -416,12 +418,13 @@ export const update = async (meta, collection, query, update, options, extras) =
|
|
|
416
418
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
417
419
|
}
|
|
418
420
|
arg = Object.assign(arg, extras)
|
|
419
|
-
arg.suffix =
|
|
421
|
+
arg.suffix = await applySuffixPolicy(COLLECTIONS_JSON, collection, arg.query, false, arg)
|
|
422
|
+
arg.suffix = (arg.suffix ?? []).concat(generate_suffix(meta))
|
|
420
423
|
arg.executor = meta.executor ?? "native"
|
|
421
424
|
arg = Object.assign({}, topology_meta, arg)
|
|
422
425
|
if (meta.batch) {
|
|
423
426
|
if (!batches[meta.batch])
|
|
424
|
-
throw
|
|
427
|
+
throw new Error('Error: Invalid batch in Dip.update()')
|
|
425
428
|
batches[meta.batch].push(arg)
|
|
426
429
|
return
|
|
427
430
|
}
|
|
@@ -441,7 +444,7 @@ export const remove = async (meta, collection, query, options, extras) => {
|
|
|
441
444
|
validate_collection(collection, 'in Dip.remove()')
|
|
442
445
|
|
|
443
446
|
if (Utils.isEmpty(query._id) && !meta.allowDangerousRemove)
|
|
444
|
-
throw
|
|
447
|
+
throw new Error("Error: Dip.remove() without _id blocked by default (Dangerous Operation). Set meta.allowDangerousRemove if intentional.")
|
|
445
448
|
|
|
446
449
|
validate_meta(meta, 'in Dip.remove()')
|
|
447
450
|
|
|
@@ -457,12 +460,13 @@ export const remove = async (meta, collection, query, options, extras) => {
|
|
|
457
460
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
458
461
|
}
|
|
459
462
|
arg = Object.assign(arg, extras)
|
|
460
|
-
arg.suffix =
|
|
463
|
+
arg.suffix = await applySuffixPolicy(COLLECTIONS_JSON, collection, arg.query, false, arg)
|
|
464
|
+
arg.suffix = (arg.suffix ?? []).concat(generate_suffix(meta))
|
|
461
465
|
arg.executor = meta.executor ?? "native"
|
|
462
466
|
arg = Object.assign({}, topology_meta, arg)
|
|
463
467
|
if (meta.batch) {
|
|
464
468
|
if (!batches[meta.batch])
|
|
465
|
-
throw
|
|
469
|
+
throw new Error('Error: Invalid batch in Dip.query()')
|
|
466
470
|
batches[meta.batch].push(arg)
|
|
467
471
|
return
|
|
468
472
|
}
|
|
@@ -559,7 +563,7 @@ function parseBinaryResponse(result) {
|
|
|
559
563
|
return {metadata: result.body, content: result.body.items}
|
|
560
564
|
}
|
|
561
565
|
if (!contentType.includes("application/dip")) {
|
|
562
|
-
throw
|
|
566
|
+
throw new Error("Error: Dip unsupported media. Invalid content-type.")
|
|
563
567
|
}
|
|
564
568
|
|
|
565
569
|
const arrayBuffer = result.body
|
package/libs/features.js
CHANGED
|
@@ -43,13 +43,13 @@ let SERVICE_ADDRESS = process.env.APP_ENDPOINT || 'http://127.0.0.1:3000'
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
export const get = feature => {
|
|
46
|
-
const throwError = () => {throw
|
|
46
|
+
const throwError = () => {throw new Error(`Feature ${feature} not found in internal or external list during Features.subscribe call`)}
|
|
47
47
|
let {api, service = SERVICE_ADDRESS, topic} = getFeature(feature) ?? SLYP_FEATURES_LIST[feature] ?? throwError()
|
|
48
48
|
return {api, service, topic}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export const send = async (meta, feature, data, params) => {
|
|
52
|
-
const throwError = () => {throw
|
|
52
|
+
const throwError = () => {throw new Error(`Feature ${feature} not found in internal or external list during inter feature call`)}
|
|
53
53
|
let {api, service = SERVICE_ADDRESS} = getFeature(feature) ?? SLYP_FEATURES_LIST[feature] ?? throwError()
|
|
54
54
|
let method = getFeatureMethod(api)
|
|
55
55
|
let url = getFeatureUrl(api)
|
|
@@ -58,7 +58,7 @@ export const send = async (meta, feature, data, params) => {
|
|
|
58
58
|
for (let key in params)
|
|
59
59
|
url = url.replace(`:${key}`, params[key])
|
|
60
60
|
if (url.includes(':'))
|
|
61
|
-
throw {feature
|
|
61
|
+
throw new Error(`Error: Internal feature call send on feature: ${feature} when api/params/substitution`)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
let payload = { ...meta, data, feature, txn: Utils.uid() }
|