ia-common 1.1.1-beta.3 → 1.1.1-beta.5
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.
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
+
// create a safe global reference
|
|
3
|
+
var __js_cols_global = typeof globalThis !== "undefined"
|
|
4
|
+
? globalThis
|
|
5
|
+
: typeof window !== "undefined"
|
|
6
|
+
? window
|
|
7
|
+
: typeof global !== "undefined"
|
|
8
|
+
? global
|
|
9
|
+
: this;
|
|
10
|
+
// reuse an existing global js_cols if present, otherwise create it
|
|
11
|
+
var js_cols = __js_cols_global.js_cols || {};
|
|
12
|
+
// Optionally set back the global for scripts that expect it
|
|
13
|
+
__js_cols_global.js_cols = js_cols;
|
|
2
14
|
//Copyright 2010 Thomas Stjernegaard Jeppesen. All Rights Reserved.
|
|
3
15
|
//Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
16
|
//you may not use this file except in compliance with the License.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Modify } from "../@type";
|
|
1
|
+
import { EntityEnum, IEntitySearch, Modify } from "../@type";
|
|
2
2
|
/**
|
|
3
3
|
* Returns epoch time (ms) for today's date at the given local time (IST).
|
|
4
4
|
*/
|
|
@@ -83,3 +83,6 @@ export declare function toDateFromEpoch(epoch: number): Date;
|
|
|
83
83
|
*/
|
|
84
84
|
export declare function deepMerge(existing: any, incoming: any): any;
|
|
85
85
|
export declare function groupByOneToOneFunction<T, K>(list: T[], keyGetter: (input: T) => K): Map<K, T>;
|
|
86
|
+
export declare function getPropertyFilterByPermissionFn<T extends EntityEnum>(permissionFilterConfig: {
|
|
87
|
+
[key: string]: () => Promise<IEntitySearch<T>>;
|
|
88
|
+
}, propertyNames: string[], userPermission: string, filterDto: IEntitySearch<T>, emptyValue?: any): Promise<IEntitySearch<T>>;
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.groupByOneToOneFunction = exports.deepMerge = exports.toDateFromEpoch = exports.groupByFunction = exports.transformDate = exports.getStringValues = exports.getTodayISTEpoch = void 0;
|
|
12
|
+
exports.getPropertyFilterByPermissionFn = exports.groupByOneToOneFunction = exports.deepMerge = exports.toDateFromEpoch = exports.groupByFunction = exports.transformDate = exports.getStringValues = exports.getTodayISTEpoch = void 0;
|
|
13
|
+
const _type_1 = require("../@type");
|
|
4
14
|
/**
|
|
5
15
|
* Returns epoch time (ms) for today's date at the given local time (IST).
|
|
6
16
|
*/
|
|
@@ -133,3 +143,135 @@ function groupByOneToOneFunction(list, keyGetter) {
|
|
|
133
143
|
return map;
|
|
134
144
|
}
|
|
135
145
|
exports.groupByOneToOneFunction = groupByOneToOneFunction;
|
|
146
|
+
function getPropertyFilterByPermissionFn(permissionFilterConfig, propertyNames, userPermission, filterDto, emptyValue = []) {
|
|
147
|
+
var _a, _b;
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const permissionFilterData = yield permissionFilterConfig[userPermission]();
|
|
150
|
+
const result = {
|
|
151
|
+
name: filterDto.name,
|
|
152
|
+
include: {},
|
|
153
|
+
};
|
|
154
|
+
for (const propertyName of propertyNames) {
|
|
155
|
+
const dtoInclude = (_a = filterDto.include) !== null && _a !== void 0 ? _a : {};
|
|
156
|
+
const dtoFilter = dtoInclude[propertyName];
|
|
157
|
+
const permissionInclude = (_b = permissionFilterData.include) !== null && _b !== void 0 ? _b : {};
|
|
158
|
+
const permissionFilter = permissionInclude[propertyName];
|
|
159
|
+
const isDtoPresent = Array.isArray(dtoFilter) && dtoFilter.length > 0;
|
|
160
|
+
const isPermissionPresent = Array.isArray(permissionFilter) && permissionFilter.length > 0;
|
|
161
|
+
// --------- CASE 1: Permission says allow all ([]) ----------
|
|
162
|
+
if (Array.isArray(permissionFilter) && permissionFilter.length === 0) {
|
|
163
|
+
result.include[propertyName] = dtoFilter !== null && dtoFilter !== void 0 ? dtoFilter : []; // allow everything
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
// --------- CASE 2: Permission has restriction ----------
|
|
167
|
+
if (isPermissionPresent) {
|
|
168
|
+
if (isDtoPresent) {
|
|
169
|
+
const intersection = (0, _type_1.arrayIntersection)(permissionFilter, dtoFilter);
|
|
170
|
+
result.include[propertyName] =
|
|
171
|
+
intersection.length > 0 ? intersection : emptyValue;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
// no dto filter → use full permission filter
|
|
175
|
+
result.include[propertyName] = permissionFilter;
|
|
176
|
+
}
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
// --------- CASE 3: No permission restriction → use dto filter ----------
|
|
180
|
+
result.include[propertyName] = dtoFilter;
|
|
181
|
+
}
|
|
182
|
+
return result;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
exports.getPropertyFilterByPermissionFn = getPropertyFilterByPermissionFn;
|
|
186
|
+
// export async function getPropertyFilterByPermissionFn<T extends EntityEnum>(
|
|
187
|
+
// permissionFilterConfig: {
|
|
188
|
+
// [key: string]: () => Promise<IEntitySearch<T>>;
|
|
189
|
+
// },
|
|
190
|
+
// propertyNames: (keyof EnumEntityType<T>)[],
|
|
191
|
+
// userPermission: string,
|
|
192
|
+
// filterDto: IEntitySearch<T>,
|
|
193
|
+
// emptyValue: any = []
|
|
194
|
+
// ) {
|
|
195
|
+
// const filterData = await permissionFilterConfig[userPermission]();
|
|
196
|
+
// const result: IEntitySearch<T> = {
|
|
197
|
+
// name: filterDto.name,
|
|
198
|
+
// include: {},
|
|
199
|
+
// };
|
|
200
|
+
// const permissionInclude = filterData.include ?? {}; // <-- FIX
|
|
201
|
+
// for (const propertyName of propertyNames) {
|
|
202
|
+
// const dtoFilterInclude = filterDto.include;
|
|
203
|
+
// const dtoFilter = dtoFilterInclude![propertyName as keyof IEntitySearch<T>];
|
|
204
|
+
// const permissionFilter =
|
|
205
|
+
// permissionInclude[propertyName as keyof IEntitySearch<T>];
|
|
206
|
+
// const isDtoFilterIdPresent = dtoFilter && dtoFilter.length > 0;
|
|
207
|
+
// const isPermissionFilterIdPresent =
|
|
208
|
+
// permissionFilter &&
|
|
209
|
+
// Array.isArray(permissionFilter) &&
|
|
210
|
+
// permissionFilter.length > 0;
|
|
211
|
+
// if (!result.include) result.include = {};
|
|
212
|
+
// result.include[propertyName as keyof IEntitySearch<T>] =
|
|
213
|
+
// isPermissionFilterIdPresent
|
|
214
|
+
// ? isDtoFilterIdPresent
|
|
215
|
+
// ? arrayIntersection(permissionFilter as any[], dtoFilter).length > 0
|
|
216
|
+
// ? arrayIntersection(permissionFilter as any[], dtoFilter)
|
|
217
|
+
// : emptyValue
|
|
218
|
+
// : permissionFilter
|
|
219
|
+
// : dtoFilter ?? emptyValue;
|
|
220
|
+
// }
|
|
221
|
+
// return result;
|
|
222
|
+
// }
|
|
223
|
+
// export function getFilterByPermission<T extends EnumEntityType<EntityEnum>>(
|
|
224
|
+
// permissionFilterConfig: {
|
|
225
|
+
// [key: string]: IEntityFilterData<T>;
|
|
226
|
+
// },
|
|
227
|
+
// propertyName: keyof T,
|
|
228
|
+
// userPermission: string,
|
|
229
|
+
// filterDto: IEntityFilterData<T>,
|
|
230
|
+
// emptyValue: any = []
|
|
231
|
+
// ) {
|
|
232
|
+
// const dtoFilter = filterDto[propertyName as keyof IEntityFilterData<T>];
|
|
233
|
+
// const permissionFilter =
|
|
234
|
+
// permissionFilterConfig[userPermission][
|
|
235
|
+
// propertyName as keyof IEntityFilterData<T>
|
|
236
|
+
// ];
|
|
237
|
+
// const isDtoFilterIdPresent = dtoFilter && dtoFilter.length > 0;
|
|
238
|
+
// const isPermissionFilterIdPresent =
|
|
239
|
+
// permissionFilter && permissionFilter.length > 0;
|
|
240
|
+
// return {
|
|
241
|
+
// [propertyName]: isPermissionFilterIdPresent
|
|
242
|
+
// ? isDtoFilterIdPresent
|
|
243
|
+
// ? arrayIntersection(permissionFilter as any[], dtoFilter).length > 0
|
|
244
|
+
// ? arrayIntersection(permissionFilter as any[], dtoFilter)
|
|
245
|
+
// : emptyValue
|
|
246
|
+
// : permissionFilter
|
|
247
|
+
// : dtoFilter,
|
|
248
|
+
// };
|
|
249
|
+
// }
|
|
250
|
+
// export async function getFilterByPermissionFn<
|
|
251
|
+
// T extends EnumEntityType<EntityEnum>
|
|
252
|
+
// >(
|
|
253
|
+
// permissionFilterConfig: {
|
|
254
|
+
// [key: string]: () => Promise<IEntityFilterData<T>>;
|
|
255
|
+
// },
|
|
256
|
+
// propertyName: keyof T,
|
|
257
|
+
// userPermission: string,
|
|
258
|
+
// filterDto: IEntityFilterData<T>,
|
|
259
|
+
// emptyValue: any = []
|
|
260
|
+
// ) {
|
|
261
|
+
// const filterData = await permissionFilterConfig[userPermission]();
|
|
262
|
+
// const dtoFilter = filterDto[propertyName as keyof IEntityFilterData<T>];
|
|
263
|
+
// const permissionFilter =
|
|
264
|
+
// filterData[propertyName as keyof IEntityFilterData<T>];
|
|
265
|
+
// const isDtoFilterIdPresent = dtoFilter && dtoFilter.length > 0;
|
|
266
|
+
// const isPermissionFilterIdPresent =
|
|
267
|
+
// permissionFilter && permissionFilter.length > 0;
|
|
268
|
+
// return {
|
|
269
|
+
// [propertyName]: isPermissionFilterIdPresent
|
|
270
|
+
// ? isDtoFilterIdPresent
|
|
271
|
+
// ? arrayIntersection(permissionFilter as any[], dtoFilter).length > 0
|
|
272
|
+
// ? arrayIntersection(permissionFilter as any[], dtoFilter)
|
|
273
|
+
// : emptyValue
|
|
274
|
+
// : permissionFilter
|
|
275
|
+
// : dtoFilter,
|
|
276
|
+
// };
|
|
277
|
+
// }
|