corebasic 1.0.209 → 1.0.211
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/policy.js +13 -9
- package/libs/dip/suffix/suffix.js +2 -0
- package/libs/elabase.js +12 -8
- package/package.json +1 -1
|
@@ -136,18 +136,22 @@ export function matchPolicy(query, when, g_obj) {
|
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
|
|
139
|
-
export async function applySuffixPolicy(COLLECTIONS_JSON,
|
|
140
|
-
|
|
141
|
-
const suffixPolicies = typeof collection_policy === "object" && !Array.isArray(collection_policy) ? [collection_policy] : COLLECTIONS_JSON[collection]?.policy ?? []
|
|
139
|
+
export async function applySuffixPolicy(COLLECTIONS_JSON, collections, query, insertMode, arg) {
|
|
140
|
+
collections = Array.isArray(collections) ? collections : [collections]
|
|
142
141
|
let suffixes = []
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
|
|
143
|
+
for (let collection of collections) {
|
|
144
|
+
const collection_policy = COLLECTIONS_JSON[collection]?.policy ?? []
|
|
145
|
+
const suffixPolicies = typeof collection_policy === "object" && !Array.isArray(collection_policy) ? [collection_policy] : COLLECTIONS_JSON[collection]?.policy ?? []
|
|
146
|
+
for (const policy of suffixPolicies) {
|
|
147
|
+
if (matchPolicy(query, policy.when ?? {})) {
|
|
148
|
+
// generate suffixes
|
|
149
|
+
const array = await suffix(query, policy.suffix ?? [], insertMode, arg)
|
|
150
|
+
suffixes.push(...array)
|
|
151
|
+
}
|
|
148
152
|
}
|
|
153
|
+
suffixes = [...new Set(suffixes)];
|
|
149
154
|
}
|
|
150
|
-
suffixes = [...new Set(suffixes)];
|
|
151
155
|
return suffixes
|
|
152
156
|
}
|
|
153
157
|
|
|
@@ -47,6 +47,8 @@ export async function suffix(doc, policies, insertMode, arg) {
|
|
|
47
47
|
console.warn(`Warn: Missing suffix policy min/max bound for ${policy_type} range specified for key ${policy.key} in Dip`)
|
|
48
48
|
} else {
|
|
49
49
|
ranges = fillDates({from, to, fromOp, toOp}, format)
|
|
50
|
+
if (!ranges.length && policy.inferRange)
|
|
51
|
+
ranges = [...new Set([from === undefined ? undefined : formatDate(from, format), to === undefined ? undefined : formatDate(to, format)].filter(item => item))]
|
|
50
52
|
// console.log(ranges)
|
|
51
53
|
if (ranges.length > ls_threshold) {
|
|
52
54
|
keys = [] // Too many suffixes to enumerate. Fall back to Dip.operation("ls").
|
package/libs/elabase.js
CHANGED
|
@@ -323,8 +323,9 @@ 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
|
-
|
|
327
|
-
|
|
326
|
+
let suffix_from_policy = await applySuffixPolicy(COLLECTIONS_JSON, collection, arg.insert, true, arg)
|
|
327
|
+
let suffix_from_meta = generate_suffix(meta)
|
|
328
|
+
arg.suffix = (suffix_from_meta.length ? suffix_from_meta : [""]).flatMap(meta => (suffix_from_policy.length ? suffix_from_policy : [""]).map(policy => meta + policy))
|
|
328
329
|
arg.executor = meta.executor ?? "native"
|
|
329
330
|
arg = Object.assign({}, topology_meta, arg)
|
|
330
331
|
if (options?._id) {
|
|
@@ -366,8 +367,9 @@ export const query = async (meta, collection, query, options, extras) => {
|
|
|
366
367
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
367
368
|
}
|
|
368
369
|
arg = Object.assign(arg, extras)
|
|
369
|
-
|
|
370
|
-
|
|
370
|
+
let suffix_from_policy = await applySuffixPolicy(COLLECTIONS_JSON, collection, arg.query, false, arg)
|
|
371
|
+
let suffix_from_meta = generate_suffix(meta)
|
|
372
|
+
arg.suffix = (suffix_from_meta.length ? suffix_from_meta : [""]).flatMap(meta => (suffix_from_policy.length ? suffix_from_policy : [""]).map(policy => meta + policy))
|
|
371
373
|
arg.executor = meta.executor ?? "native"
|
|
372
374
|
arg = Object.assign({}, topology_meta, arg)
|
|
373
375
|
if (meta.batch) {
|
|
@@ -418,8 +420,9 @@ export const update = async (meta, collection, query, update, options, extras) =
|
|
|
418
420
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
419
421
|
}
|
|
420
422
|
arg = Object.assign(arg, extras)
|
|
421
|
-
|
|
422
|
-
|
|
423
|
+
let suffix_from_policy = await applySuffixPolicy(COLLECTIONS_JSON, collection, arg.query, false, arg)
|
|
424
|
+
let suffix_from_meta = generate_suffix(meta)
|
|
425
|
+
arg.suffix = (suffix_from_meta.length ? suffix_from_meta : [""]).flatMap(meta => (suffix_from_policy.length ? suffix_from_policy : [""]).map(policy => meta + policy))
|
|
423
426
|
arg.executor = meta.executor ?? "native"
|
|
424
427
|
arg = Object.assign({}, topology_meta, arg)
|
|
425
428
|
if (meta.batch) {
|
|
@@ -460,8 +463,9 @@ export const remove = async (meta, collection, query, options, extras) => {
|
|
|
460
463
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
461
464
|
}
|
|
462
465
|
arg = Object.assign(arg, extras)
|
|
463
|
-
|
|
464
|
-
|
|
466
|
+
let suffix_from_policy = await applySuffixPolicy(COLLECTIONS_JSON, collection, arg.query, false, arg)
|
|
467
|
+
let suffix_from_meta = generate_suffix(meta)
|
|
468
|
+
arg.suffix = (suffix_from_meta.length ? suffix_from_meta : [""]).flatMap(meta => (suffix_from_policy.length ? suffix_from_policy : [""]).map(policy => meta + policy))
|
|
465
469
|
arg.executor = meta.executor ?? "native"
|
|
466
470
|
arg = Object.assign({}, topology_meta, arg)
|
|
467
471
|
if (meta.batch) {
|