@treatwell/moleculer-essentials 1.2.2 → 1.2.3
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/dist/{index-CjA1_Io7.cjs → index-BuNrZnJ4.cjs} +1 -0
- package/dist/{index-yStjjADK.mjs → index-DAz9xV2z.mjs} +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +4 -4
- package/dist/mixins/database.mixin.cjs +16 -76
- package/dist/mixins/database.mixin.d.cts +6 -22
- package/dist/mixins/database.mixin.d.mts +6 -22
- package/dist/mixins/database.mixin.mjs +18 -76
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-BuNrZnJ4.cjs');
|
|
4
4
|
var v4 = require('zod/v4');
|
|
5
5
|
var _2019_js = require('ajv/dist/2019.js');
|
|
6
6
|
var moleculer = require('moleculer');
|
|
@@ -146,7 +146,7 @@ function generateOpenAPISpec({
|
|
|
146
146
|
services,
|
|
147
147
|
getSecuritySchemes
|
|
148
148
|
}) {
|
|
149
|
-
services.forEach((svc) =>
|
|
149
|
+
services.forEach((svc) => compat.merge(doc, svc.settings?.openapi));
|
|
150
150
|
const extractor = new OpenAPIExtractor(doc);
|
|
151
151
|
if (doc.components?.schemas) {
|
|
152
152
|
const { schemas } = doc.components;
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { S as SCHEMA_REF_NAME, z as zodToOpenAPISchema, o as omitFields, G as GetOpenApiParamsSchema, V as ValidationErrorSchema, F as FileTooBigSchema, a as FileNotExistSchema, U as UnauthorizedErrorSchema, b as ServerErrorSchema, C as COERCE_ARRAY_ATTRIBUTE } from './index-
|
|
2
|
-
export { D as DATE_TYPE, E as EMPTY_OBJECT_SCHEMA, O as OBJECTID_TYPE, c as addFieldsToSchema, f as composeSchemas, j as createOpenAPIResponses, e as optionalExceptFields, d as optionalFields, p as pickFields, t as toPartialSchema, i as zodCoerceArray, g as zodDate, h as zodObjectId } from './index-
|
|
1
|
+
import { S as SCHEMA_REF_NAME, z as zodToOpenAPISchema, o as omitFields, G as GetOpenApiParamsSchema, V as ValidationErrorSchema, F as FileTooBigSchema, a as FileNotExistSchema, U as UnauthorizedErrorSchema, b as ServerErrorSchema, C as COERCE_ARRAY_ATTRIBUTE } from './index-DAz9xV2z.mjs';
|
|
2
|
+
export { D as DATE_TYPE, E as EMPTY_OBJECT_SCHEMA, O as OBJECTID_TYPE, c as addFieldsToSchema, f as composeSchemas, j as createOpenAPIResponses, e as optionalExceptFields, d as optionalFields, p as pickFields, t as toPartialSchema, i as zodCoerceArray, g as zodDate, h as zodObjectId } from './index-DAz9xV2z.mjs';
|
|
3
3
|
import { ZodType, ZodObject, ZodOptional, z } from 'zod/v4';
|
|
4
4
|
import { Ajv2019 } from 'ajv/dist/2019.js';
|
|
5
5
|
import { Validators, Errors, Context, ServiceBroker, Service, TracerExporters, MetricReporters } from 'moleculer';
|
|
6
6
|
import addFormats from 'ajv-formats';
|
|
7
7
|
import addKeywords from 'ajv-keywords';
|
|
8
|
-
import { omit, isEqual,
|
|
8
|
+
import { omit, isEqual, isPlainObject } from 'es-toolkit';
|
|
9
9
|
import { parseISO } from 'date-fns';
|
|
10
10
|
import { ObjectId } from 'bson';
|
|
11
11
|
import { w as wrapMixin } from './index-DNJWwcZu.mjs';
|
|
12
12
|
export { a as wrapService } from './index-DNJWwcZu.mjs';
|
|
13
|
-
import { defaultsDeep, isObject } from 'es-toolkit/compat';
|
|
13
|
+
import { merge, defaultsDeep, isObject } from 'es-toolkit/compat';
|
|
14
14
|
import http, { STATUS_CODES } from 'http';
|
|
15
15
|
import { pino } from 'pino';
|
|
16
16
|
import { hostname } from 'node:os';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var v4 = require('zod/v4');
|
|
4
|
-
var index = require('../index-
|
|
4
|
+
var index = require('../index-BuNrZnJ4.cjs');
|
|
5
5
|
var moleculer = require('moleculer');
|
|
6
6
|
var esToolkit = require('es-toolkit');
|
|
7
7
|
var mongodb = require('mongodb');
|
|
@@ -34,6 +34,21 @@ function optimizeQuery(query) {
|
|
|
34
34
|
$or: $or.map((predicate) => ({ ...predicate, ...rest }))
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
function getQueryFromList(type, list) {
|
|
38
|
+
if (!list?.length) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
const res = {};
|
|
42
|
+
list.forEach((el) => {
|
|
43
|
+
if (el.startsWith("-")) {
|
|
44
|
+
const p = el.slice(1);
|
|
45
|
+
res[p] = type === "sort" ? -1 : 0;
|
|
46
|
+
} else {
|
|
47
|
+
res[el] = 1;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
37
52
|
|
|
38
53
|
var QueryOp = /* @__PURE__ */ ((QueryOp2) => {
|
|
39
54
|
QueryOp2["GT"] = "$gt";
|
|
@@ -1074,79 +1089,6 @@ function DatabaseIndexesMixin(opts) {
|
|
|
1074
1089
|
});
|
|
1075
1090
|
}
|
|
1076
1091
|
|
|
1077
|
-
function getFieldMode(fields) {
|
|
1078
|
-
const refField = fields?.[0] === "-_id" ? fields?.[1] : fields?.[0];
|
|
1079
|
-
if (refField && !refField.startsWith("-")) {
|
|
1080
|
-
return "allow";
|
|
1081
|
-
}
|
|
1082
|
-
return "deny";
|
|
1083
|
-
}
|
|
1084
|
-
function filterFields(fields, secureFields) {
|
|
1085
|
-
if (!secureFields?.length) {
|
|
1086
|
-
return fields;
|
|
1087
|
-
}
|
|
1088
|
-
const mode = getFieldMode(fields);
|
|
1089
|
-
switch (mode) {
|
|
1090
|
-
case "deny": {
|
|
1091
|
-
if (fields?.some((f) => !f.startsWith("-"))) {
|
|
1092
|
-
throw new Error('All fields must have a "-" prefix in deny mode');
|
|
1093
|
-
}
|
|
1094
|
-
return [
|
|
1095
|
-
.../* @__PURE__ */ new Set([...fields || [], ...secureFields.map((f) => `-${f}`)])
|
|
1096
|
-
];
|
|
1097
|
-
}
|
|
1098
|
-
case "allow": {
|
|
1099
|
-
if (fields?.some((f) => f.startsWith("-") && f !== "-_id")) {
|
|
1100
|
-
throw new Error('No fields must have a "-" prefix in allow mode');
|
|
1101
|
-
}
|
|
1102
|
-
const filteredFields = fields?.filter(
|
|
1103
|
-
(f) => !secureFields.find((sF) => f === sF || f.startsWith(`${sF}.`))
|
|
1104
|
-
);
|
|
1105
|
-
if (filteredFields?.length === 0) {
|
|
1106
|
-
return ["_id"];
|
|
1107
|
-
}
|
|
1108
|
-
return filteredFields;
|
|
1109
|
-
}
|
|
1110
|
-
default:
|
|
1111
|
-
throw new Error("Should not happen");
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
function filterObjectFields(obj, fields) {
|
|
1115
|
-
if (!fields?.length) {
|
|
1116
|
-
return obj;
|
|
1117
|
-
}
|
|
1118
|
-
let res = obj;
|
|
1119
|
-
const [fieldsRemove, fieldsAdd] = esToolkit.partition(
|
|
1120
|
-
fields || [],
|
|
1121
|
-
(f) => f.startsWith("-")
|
|
1122
|
-
);
|
|
1123
|
-
if (fieldsRemove.length) {
|
|
1124
|
-
res = esToolkit.omit(
|
|
1125
|
-
res,
|
|
1126
|
-
fieldsRemove.map((f) => f.substring(1))
|
|
1127
|
-
);
|
|
1128
|
-
}
|
|
1129
|
-
if (fieldsAdd.length) {
|
|
1130
|
-
res = esToolkit.pick(res, fieldsAdd);
|
|
1131
|
-
}
|
|
1132
|
-
return res;
|
|
1133
|
-
}
|
|
1134
|
-
function getQueryFromList(type, list) {
|
|
1135
|
-
if (!list?.length) {
|
|
1136
|
-
return void 0;
|
|
1137
|
-
}
|
|
1138
|
-
const res = {};
|
|
1139
|
-
list.forEach((el) => {
|
|
1140
|
-
if (el.startsWith("-")) {
|
|
1141
|
-
const p = el.slice(1);
|
|
1142
|
-
res[p] = type === "sort" ? -1 : 0;
|
|
1143
|
-
} else {
|
|
1144
|
-
res[el] = 1;
|
|
1145
|
-
}
|
|
1146
|
-
});
|
|
1147
|
-
return res;
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
1092
|
function DatabaseMethodsMixin(opts) {
|
|
1151
1093
|
return index$1.wrapMixin({
|
|
1152
1094
|
methods: {
|
|
@@ -1657,8 +1599,6 @@ exports.ZodActionSchemaFactory = ZodActionSchemaFactory;
|
|
|
1657
1599
|
exports.addQueryOps = addQueryOps;
|
|
1658
1600
|
exports.addZodQueryOps = addZodQueryOps;
|
|
1659
1601
|
exports.createActions = createActions;
|
|
1660
|
-
exports.filterFields = filterFields;
|
|
1661
|
-
exports.filterObjectFields = filterObjectFields;
|
|
1662
1602
|
exports.getDefaultIndexName = getDefaultIndexName;
|
|
1663
1603
|
exports.getIndexesDifference = getIndexesDifference$1;
|
|
1664
1604
|
exports.getQueryFromList = getQueryFromList;
|
|
@@ -834,6 +834,11 @@ declare function optionalMongoId<T>(schema: JSONSchemaType<WithId<T>>, refName?:
|
|
|
834
834
|
* @param query the query to optimize
|
|
835
835
|
*/
|
|
836
836
|
declare function optimizeQuery<T extends Record<string, unknown>>(query: Filter<T>): Filter<T>;
|
|
837
|
+
/**
|
|
838
|
+
* Return an object with each list item as key and 1/0/-1 as value
|
|
839
|
+
* to be used in mongo projection or sort.
|
|
840
|
+
*/
|
|
841
|
+
declare function getQueryFromList<T extends 'sort' | 'projection', NotOp extends T extends 'sort' ? -1 : 0>(type: T, list?: string[]): Record<string, 1 | NotOp> | undefined;
|
|
837
842
|
|
|
838
843
|
declare function DatabaseMethodsMixin<TSchema extends Document & {
|
|
839
844
|
_id: ObjectId | string;
|
|
@@ -934,26 +939,5 @@ declare function DatabaseMethodsMixin<TSchema extends Document & {
|
|
|
934
939
|
_deleteMany(query: Filter<TSchema>, params: TenantParams<TSchema, TenantField>, options?: DatabaseDeleteManyOptions): Promise<number>;
|
|
935
940
|
}, unknown, unknown>>;
|
|
936
941
|
|
|
937
|
-
|
|
938
|
-
* This function is here to prevent accessing private (secure) fields.
|
|
939
|
-
*
|
|
940
|
-
* It removes any unauthorized fields from the query if it is an
|
|
941
|
-
* "allowed list" mode. In "deny list" mode or if no list,
|
|
942
|
-
* it adds secure fields to the list.
|
|
943
|
-
*
|
|
944
|
-
* If a query is a mixed of both mode, it throws an error.
|
|
945
|
-
*/
|
|
946
|
-
declare function filterFields(fields: string[] | undefined, secureFields: string[] | undefined): string[] | undefined;
|
|
947
|
-
/**
|
|
948
|
-
* Filter an objects following a fields array.
|
|
949
|
-
* A simpler version of mongo projection logic.
|
|
950
|
-
*/
|
|
951
|
-
declare function filterObjectFields<T extends Record<string, unknown>>(obj: Record<string, unknown>, fields?: string[]): T;
|
|
952
|
-
/**
|
|
953
|
-
* Return an object with each list item as key and 1/0/-1 as value
|
|
954
|
-
* to be used in mongo projection or sort.
|
|
955
|
-
*/
|
|
956
|
-
declare function getQueryFromList<T extends 'sort' | 'projection', NotOp extends T extends 'sort' ? -1 : 0>(type: T, list?: string[]): Record<string, 1 | NotOp> | undefined;
|
|
957
|
-
|
|
958
|
-
export { AjvActionSchemaFactory, DATABASE_INDEXES_MIXIN_SYNC_EVENT, DatabaseConnectionMixin, DatabaseIndexesMixin, DatabaseMethodsMixin, EntityNotFoundError, IndexStatus, QueryOp, ZodActionSchemaFactory, addQueryOps, addZodQueryOps, createActions, filterFields, filterObjectFields, getDefaultIndexName, getIndexesDifference, getQueryFromList, isIndexEqual, isIndexNameEqual, isOnAtlas, optimizeQuery, optionalMongoId, parseAndValidateQuery, parseStringifiedQuery, removeMongoId, shouldAutoCreateIndexes, shouldAutoDropIndexes };
|
|
942
|
+
export { AjvActionSchemaFactory, DATABASE_INDEXES_MIXIN_SYNC_EVENT, DatabaseConnectionMixin, DatabaseIndexesMixin, DatabaseMethodsMixin, EntityNotFoundError, IndexStatus, QueryOp, ZodActionSchemaFactory, addQueryOps, addZodQueryOps, createActions, getDefaultIndexName, getIndexesDifference, getQueryFromList, isIndexEqual, isIndexNameEqual, isOnAtlas, optimizeQuery, optionalMongoId, parseAndValidateQuery, parseStringifiedQuery, removeMongoId, shouldAutoCreateIndexes, shouldAutoDropIndexes };
|
|
959
943
|
export type { ActionCountParamsOptions, ActionCreateParamsOptions, ActionGetParamsOptions, ActionListParamsOptions, ActionSchemaFactory, ActionSchemaFactoryOptions, DatabaseActionCountInternalParams, DatabaseActionCountParams, DatabaseActionCreateParams, DatabaseActionEntityResult, DatabaseActionFindParams, DatabaseActionFindResult, DatabaseActionGetInternalParams, DatabaseActionGetParams, DatabaseActionInternalNames, DatabaseActionListParams, DatabaseActionListResult, DatabaseActionNames, DatabaseActionOptions, DatabaseActionPublishedNames, DatabaseActionRemoveParams, DatabaseActionUpdateParams, DatabaseConnectionOptions, DatabaseCountOptions, DatabaseDeleteManyOptions, DatabaseDeleteOneOptions, DatabaseEventDelete, DatabaseEventInsert, DatabaseEventUpdate, DatabaseFindOptions, DatabaseIndexesOptions, DatabaseInsertManyOptions, DatabaseInsertOneOptions, DatabaseMethodsOptions, DatabaseReplaceOneOptions, DatabaseSoftDeleteScope, DatabaseUpdateManyOptions, DatabaseUpdateOneOptions, IndexState, IndexTuple, KeyString, ListSearchIndex, MongoIndex, SearchIndexCustomAnalyzers, SearchIndexDefinition, SearchIndexField, SearchIndexFieldString, SyncIndexesOptions, TenantParams, WithDbFields, WithOptionalId };
|
|
@@ -834,6 +834,11 @@ declare function optionalMongoId<T>(schema: JSONSchemaType<WithId<T>>, refName?:
|
|
|
834
834
|
* @param query the query to optimize
|
|
835
835
|
*/
|
|
836
836
|
declare function optimizeQuery<T extends Record<string, unknown>>(query: Filter<T>): Filter<T>;
|
|
837
|
+
/**
|
|
838
|
+
* Return an object with each list item as key and 1/0/-1 as value
|
|
839
|
+
* to be used in mongo projection or sort.
|
|
840
|
+
*/
|
|
841
|
+
declare function getQueryFromList<T extends 'sort' | 'projection', NotOp extends T extends 'sort' ? -1 : 0>(type: T, list?: string[]): Record<string, 1 | NotOp> | undefined;
|
|
837
842
|
|
|
838
843
|
declare function DatabaseMethodsMixin<TSchema extends Document & {
|
|
839
844
|
_id: ObjectId | string;
|
|
@@ -934,26 +939,5 @@ declare function DatabaseMethodsMixin<TSchema extends Document & {
|
|
|
934
939
|
_deleteMany(query: Filter<TSchema>, params: TenantParams<TSchema, TenantField>, options?: DatabaseDeleteManyOptions): Promise<number>;
|
|
935
940
|
}, unknown, unknown>>;
|
|
936
941
|
|
|
937
|
-
|
|
938
|
-
* This function is here to prevent accessing private (secure) fields.
|
|
939
|
-
*
|
|
940
|
-
* It removes any unauthorized fields from the query if it is an
|
|
941
|
-
* "allowed list" mode. In "deny list" mode or if no list,
|
|
942
|
-
* it adds secure fields to the list.
|
|
943
|
-
*
|
|
944
|
-
* If a query is a mixed of both mode, it throws an error.
|
|
945
|
-
*/
|
|
946
|
-
declare function filterFields(fields: string[] | undefined, secureFields: string[] | undefined): string[] | undefined;
|
|
947
|
-
/**
|
|
948
|
-
* Filter an objects following a fields array.
|
|
949
|
-
* A simpler version of mongo projection logic.
|
|
950
|
-
*/
|
|
951
|
-
declare function filterObjectFields<T extends Record<string, unknown>>(obj: Record<string, unknown>, fields?: string[]): T;
|
|
952
|
-
/**
|
|
953
|
-
* Return an object with each list item as key and 1/0/-1 as value
|
|
954
|
-
* to be used in mongo projection or sort.
|
|
955
|
-
*/
|
|
956
|
-
declare function getQueryFromList<T extends 'sort' | 'projection', NotOp extends T extends 'sort' ? -1 : 0>(type: T, list?: string[]): Record<string, 1 | NotOp> | undefined;
|
|
957
|
-
|
|
958
|
-
export { AjvActionSchemaFactory, DATABASE_INDEXES_MIXIN_SYNC_EVENT, DatabaseConnectionMixin, DatabaseIndexesMixin, DatabaseMethodsMixin, EntityNotFoundError, IndexStatus, QueryOp, ZodActionSchemaFactory, addQueryOps, addZodQueryOps, createActions, filterFields, filterObjectFields, getDefaultIndexName, getIndexesDifference, getQueryFromList, isIndexEqual, isIndexNameEqual, isOnAtlas, optimizeQuery, optionalMongoId, parseAndValidateQuery, parseStringifiedQuery, removeMongoId, shouldAutoCreateIndexes, shouldAutoDropIndexes };
|
|
942
|
+
export { AjvActionSchemaFactory, DATABASE_INDEXES_MIXIN_SYNC_EVENT, DatabaseConnectionMixin, DatabaseIndexesMixin, DatabaseMethodsMixin, EntityNotFoundError, IndexStatus, QueryOp, ZodActionSchemaFactory, addQueryOps, addZodQueryOps, createActions, getDefaultIndexName, getIndexesDifference, getQueryFromList, isIndexEqual, isIndexNameEqual, isOnAtlas, optimizeQuery, optionalMongoId, parseAndValidateQuery, parseStringifiedQuery, removeMongoId, shouldAutoCreateIndexes, shouldAutoDropIndexes };
|
|
959
943
|
export type { ActionCountParamsOptions, ActionCreateParamsOptions, ActionGetParamsOptions, ActionListParamsOptions, ActionSchemaFactory, ActionSchemaFactoryOptions, DatabaseActionCountInternalParams, DatabaseActionCountParams, DatabaseActionCreateParams, DatabaseActionEntityResult, DatabaseActionFindParams, DatabaseActionFindResult, DatabaseActionGetInternalParams, DatabaseActionGetParams, DatabaseActionInternalNames, DatabaseActionListParams, DatabaseActionListResult, DatabaseActionNames, DatabaseActionOptions, DatabaseActionPublishedNames, DatabaseActionRemoveParams, DatabaseActionUpdateParams, DatabaseConnectionOptions, DatabaseCountOptions, DatabaseDeleteManyOptions, DatabaseDeleteOneOptions, DatabaseEventDelete, DatabaseEventInsert, DatabaseEventUpdate, DatabaseFindOptions, DatabaseIndexesOptions, DatabaseInsertManyOptions, DatabaseInsertOneOptions, DatabaseMethodsOptions, DatabaseReplaceOneOptions, DatabaseSoftDeleteScope, DatabaseUpdateManyOptions, DatabaseUpdateOneOptions, IndexState, IndexTuple, KeyString, ListSearchIndex, MongoIndex, SearchIndexCustomAnalyzers, SearchIndexDefinition, SearchIndexField, SearchIndexFieldString, SyncIndexesOptions, TenantParams, WithDbFields, WithOptionalId };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ZodType, z, ZodObject } from 'zod/v4';
|
|
2
|
-
import { o as omitFields, d as optionalFields, S as SCHEMA_REF_NAME, O as OBJECTID_TYPE, C as COERCE_ARRAY_ATTRIBUTE, h as zodObjectId, i as zodCoerceArray, j as createOpenAPIResponses } from '../index-
|
|
2
|
+
import { o as omitFields, d as optionalFields, S as SCHEMA_REF_NAME, O as OBJECTID_TYPE, C as COERCE_ARRAY_ATTRIBUTE, h as zodObjectId, i as zodCoerceArray, j as createOpenAPIResponses } from '../index-DAz9xV2z.mjs';
|
|
3
3
|
import { Errors } from 'moleculer';
|
|
4
|
-
import { isEqual as isEqual$1
|
|
4
|
+
import { isEqual as isEqual$1 } from 'es-toolkit';
|
|
5
5
|
import { MongoClient } from 'mongodb';
|
|
6
6
|
import { w as wrapMixin } from '../index-DNJWwcZu.mjs';
|
|
7
7
|
import { GlobalStoreMixin } from './global-store.mixin.mjs';
|
|
@@ -32,6 +32,21 @@ function optimizeQuery(query) {
|
|
|
32
32
|
$or: $or.map((predicate) => ({ ...predicate, ...rest }))
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
+
function getQueryFromList(type, list) {
|
|
36
|
+
if (!list?.length) {
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
const res = {};
|
|
40
|
+
list.forEach((el) => {
|
|
41
|
+
if (el.startsWith("-")) {
|
|
42
|
+
const p = el.slice(1);
|
|
43
|
+
res[p] = type === "sort" ? -1 : 0;
|
|
44
|
+
} else {
|
|
45
|
+
res[el] = 1;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return res;
|
|
49
|
+
}
|
|
35
50
|
|
|
36
51
|
var QueryOp = /* @__PURE__ */ ((QueryOp2) => {
|
|
37
52
|
QueryOp2["GT"] = "$gt";
|
|
@@ -1072,79 +1087,6 @@ function DatabaseIndexesMixin(opts) {
|
|
|
1072
1087
|
});
|
|
1073
1088
|
}
|
|
1074
1089
|
|
|
1075
|
-
function getFieldMode(fields) {
|
|
1076
|
-
const refField = fields?.[0] === "-_id" ? fields?.[1] : fields?.[0];
|
|
1077
|
-
if (refField && !refField.startsWith("-")) {
|
|
1078
|
-
return "allow";
|
|
1079
|
-
}
|
|
1080
|
-
return "deny";
|
|
1081
|
-
}
|
|
1082
|
-
function filterFields(fields, secureFields) {
|
|
1083
|
-
if (!secureFields?.length) {
|
|
1084
|
-
return fields;
|
|
1085
|
-
}
|
|
1086
|
-
const mode = getFieldMode(fields);
|
|
1087
|
-
switch (mode) {
|
|
1088
|
-
case "deny": {
|
|
1089
|
-
if (fields?.some((f) => !f.startsWith("-"))) {
|
|
1090
|
-
throw new Error('All fields must have a "-" prefix in deny mode');
|
|
1091
|
-
}
|
|
1092
|
-
return [
|
|
1093
|
-
.../* @__PURE__ */ new Set([...fields || [], ...secureFields.map((f) => `-${f}`)])
|
|
1094
|
-
];
|
|
1095
|
-
}
|
|
1096
|
-
case "allow": {
|
|
1097
|
-
if (fields?.some((f) => f.startsWith("-") && f !== "-_id")) {
|
|
1098
|
-
throw new Error('No fields must have a "-" prefix in allow mode');
|
|
1099
|
-
}
|
|
1100
|
-
const filteredFields = fields?.filter(
|
|
1101
|
-
(f) => !secureFields.find((sF) => f === sF || f.startsWith(`${sF}.`))
|
|
1102
|
-
);
|
|
1103
|
-
if (filteredFields?.length === 0) {
|
|
1104
|
-
return ["_id"];
|
|
1105
|
-
}
|
|
1106
|
-
return filteredFields;
|
|
1107
|
-
}
|
|
1108
|
-
default:
|
|
1109
|
-
throw new Error("Should not happen");
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
function filterObjectFields(obj, fields) {
|
|
1113
|
-
if (!fields?.length) {
|
|
1114
|
-
return obj;
|
|
1115
|
-
}
|
|
1116
|
-
let res = obj;
|
|
1117
|
-
const [fieldsRemove, fieldsAdd] = partition(
|
|
1118
|
-
fields || [],
|
|
1119
|
-
(f) => f.startsWith("-")
|
|
1120
|
-
);
|
|
1121
|
-
if (fieldsRemove.length) {
|
|
1122
|
-
res = omit(
|
|
1123
|
-
res,
|
|
1124
|
-
fieldsRemove.map((f) => f.substring(1))
|
|
1125
|
-
);
|
|
1126
|
-
}
|
|
1127
|
-
if (fieldsAdd.length) {
|
|
1128
|
-
res = pick(res, fieldsAdd);
|
|
1129
|
-
}
|
|
1130
|
-
return res;
|
|
1131
|
-
}
|
|
1132
|
-
function getQueryFromList(type, list) {
|
|
1133
|
-
if (!list?.length) {
|
|
1134
|
-
return void 0;
|
|
1135
|
-
}
|
|
1136
|
-
const res = {};
|
|
1137
|
-
list.forEach((el) => {
|
|
1138
|
-
if (el.startsWith("-")) {
|
|
1139
|
-
const p = el.slice(1);
|
|
1140
|
-
res[p] = type === "sort" ? -1 : 0;
|
|
1141
|
-
} else {
|
|
1142
|
-
res[el] = 1;
|
|
1143
|
-
}
|
|
1144
|
-
});
|
|
1145
|
-
return res;
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
1090
|
function DatabaseMethodsMixin(opts) {
|
|
1149
1091
|
return wrapMixin({
|
|
1150
1092
|
methods: {
|
|
@@ -1643,4 +1585,4 @@ function DatabaseMethodsMixin(opts) {
|
|
|
1643
1585
|
});
|
|
1644
1586
|
}
|
|
1645
1587
|
|
|
1646
|
-
export { AjvActionSchemaFactory, DATABASE_INDEXES_MIXIN_SYNC_EVENT, DatabaseConnectionMixin, DatabaseIndexesMixin, DatabaseMethodsMixin, EntityNotFoundError, IndexStatus, QueryOp, ZodActionSchemaFactory, addQueryOps, addZodQueryOps, createActions,
|
|
1588
|
+
export { AjvActionSchemaFactory, DATABASE_INDEXES_MIXIN_SYNC_EVENT, DatabaseConnectionMixin, DatabaseIndexesMixin, DatabaseMethodsMixin, EntityNotFoundError, IndexStatus, QueryOp, ZodActionSchemaFactory, addQueryOps, addZodQueryOps, createActions, getDefaultIndexName, getIndexesDifference$1 as getIndexesDifference, getQueryFromList, isIndexEqual, isIndexNameEqual, isOnAtlas, optimizeQuery, optionalMongoId, parseAndValidateQuery, parseStringifiedQuery, removeMongoId, shouldAutoCreateIndexes, shouldAutoDropIndexes };
|