@point-hub/papi 0.5.14 → 0.5.16

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/lib/index.js CHANGED
@@ -71742,6 +71742,37 @@ function mongodbErrorHandlerMiddleware() {
71742
71742
  next(err);
71743
71743
  };
71744
71744
  }
71745
+ // src/database/mongodb/mongodb-compose.ts
71746
+ function composeUpdate(data, parentKey = "") {
71747
+ const updates = { $set: {}, $unset: {} };
71748
+ function isObject2(value) {
71749
+ return typeof value === "object" && value !== null && !Array.isArray(value);
71750
+ }
71751
+ function process2(value, keyPath) {
71752
+ if (value === "" || value === null || value === undefined) {
71753
+ updates.$unset[keyPath] = "";
71754
+ } else if (Array.isArray(value)) {
71755
+ value.forEach((item, index) => {
71756
+ process2(item, `${keyPath}.${index}`);
71757
+ });
71758
+ } else if (isObject2(value)) {
71759
+ Object.entries(value).forEach(([k, v]) => {
71760
+ process2(v, `${keyPath}.${k}`);
71761
+ });
71762
+ } else if (value !== undefined) {
71763
+ updates.$set[keyPath] = value;
71764
+ }
71765
+ }
71766
+ Object.entries(data).forEach(([key, value]) => {
71767
+ const fullKey = parentKey ? `${parentKey}.${key}` : key;
71768
+ process2(value, fullKey);
71769
+ });
71770
+ if (updates.$set && Object.keys(updates.$set).length === 0)
71771
+ delete updates.$set;
71772
+ if (updates.$unset && Object.keys(updates.$unset).length === 0)
71773
+ delete updates.$unset;
71774
+ return updates;
71775
+ }
71745
71776
  // src/test/utils.ts
71746
71777
  class DatabaseTestUtil {
71747
71778
  static dbConnection;
@@ -71790,6 +71821,75 @@ class DatabaseTestUtil {
71790
71821
  return await DatabaseTestUtil.dbConnection.collection(collection).retrieveAll(query);
71791
71822
  }
71792
71823
  }
71824
+ // src/database/mongodb/mongodb-query-filters.ts
71825
+ var addRegexFilter = (filters, field, value) => {
71826
+ if (value?.trim()) {
71827
+ filters.push({ [field]: { $regex: value.trim(), $options: "i" } });
71828
+ }
71829
+ };
71830
+ var addNumberFilter = (filters, field, value) => {
71831
+ if (typeof value !== "string" || value.trim() === "")
71832
+ return;
71833
+ const constraints = parseComparisons(value);
71834
+ const mongoFilter = {};
71835
+ if (constraints.eq !== undefined) {
71836
+ filters.push({ [field]: constraints.eq });
71837
+ return;
71838
+ }
71839
+ if (constraints.gt !== undefined)
71840
+ mongoFilter["$gt"] = constraints.gt;
71841
+ if (constraints.gte !== undefined)
71842
+ mongoFilter["$gte"] = constraints.gte;
71843
+ if (constraints.lt !== undefined)
71844
+ mongoFilter["$lt"] = constraints.lt;
71845
+ if (constraints.lte !== undefined)
71846
+ mongoFilter["$lte"] = constraints.lte;
71847
+ if (Object.keys(mongoFilter).length > 0) {
71848
+ filters.push({ [field]: mongoFilter });
71849
+ }
71850
+ };
71851
+ var parseComparisons = (expr) => {
71852
+ const cleanedExpr = expr.replace(/\s+/g, "");
71853
+ if (/^\d+$/.test(cleanedExpr)) {
71854
+ return { eq: parseInt(cleanedExpr, 10) };
71855
+ }
71856
+ const regex = /(<=|>=|<|>)(\d+)/g;
71857
+ const result = {};
71858
+ let matchedStr = "";
71859
+ let hasLowerBound = false;
71860
+ let hasUpperBound = false;
71861
+ let match;
71862
+ while ((match = regex.exec(cleanedExpr)) !== null) {
71863
+ const [full, operator, valueStr] = match;
71864
+ const value = parseInt(valueStr, 10);
71865
+ matchedStr += full;
71866
+ switch (operator) {
71867
+ case ">":
71868
+ case ">=":
71869
+ if (hasLowerBound)
71870
+ throw new BaseErrorHandler.ApiError("Bad Request", { message: "Only one lower-bound operator allowed." });
71871
+ result[operator === ">" ? "gt" : "gte"] = value;
71872
+ hasLowerBound = true;
71873
+ break;
71874
+ case "<":
71875
+ case "<=":
71876
+ if (hasUpperBound)
71877
+ throw new BaseErrorHandler.ApiError("Bad Request", { message: "Only one upper-bound operator allowed." });
71878
+ result[operator === "<" ? "lt" : "lte"] = value;
71879
+ hasUpperBound = true;
71880
+ break;
71881
+ }
71882
+ }
71883
+ if (cleanedExpr.length > 0 && matchedStr !== cleanedExpr) {
71884
+ throw new BaseErrorHandler.ApiError("Bad Request", { message: `Malformed input: '${expr}' is not a number` });
71885
+ }
71886
+ return result;
71887
+ };
71888
+ var mongodb_query_filters_default = {
71889
+ parseComparisons,
71890
+ addNumberFilter,
71891
+ addRegexFilter
71892
+ };
71793
71893
  // node_modules/@point-hub/express-factory/lib/index.js
71794
71894
  class Factory {
71795
71895
  constructor() {
@@ -71900,11 +72000,13 @@ var BaseErrorHandler = {
71900
72000
  };
71901
72001
  export {
71902
72002
  stubDir,
72003
+ composeUpdate,
71903
72004
  DatabaseTestUtil,
71904
72005
  Server as BaseServer,
71905
72006
  BaseMongoServerError,
71906
72007
  BaseMongoErrorHandler,
71907
72008
  BaseMongoDBQuerystring,
72009
+ mongodb_query_filters_default as BaseMongoDBQueryFilters,
71908
72010
  BaseMongoDBHelper,
71909
72011
  BaseMongoDBConnection,
71910
72012
  Factory as BaseFactory,
@@ -0,0 +1,23 @@
1
+ type Primitive = string | number | boolean | null | undefined;
2
+ type Data = Primitive | DataObject | DataArray;
3
+ interface DataObject {
4
+ [key: string]: Data;
5
+ }
6
+ type DataArray = Array<Data>;
7
+ interface MongoUpdate {
8
+ $set?: Record<string, unknown>;
9
+ $unset?: Record<string, string>;
10
+ }
11
+ /**
12
+ * Compose MongoDB update operators ($set and $unset) based on input data.
13
+ * Fields with empty string or null values will be added to $unset,
14
+ * all other fields will be added to $set.
15
+ * Supports nested objects and arrays.
16
+ *
17
+ * @param data - Input object to transform
18
+ * @param parentKey - Internal key path prefix for recursion
19
+ * @returns MongoDB update object with $set and/or $unset
20
+ */
21
+ export declare function composeUpdate(data: DataObject, parentKey?: string): MongoUpdate;
22
+ export {};
23
+ //# sourceMappingURL=mongodb-compose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongodb-compose.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongodb-compose.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;AAE7D,KAAK,IAAI,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAA;AAC9C,UAAU,UAAU;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB;AACD,KAAK,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,CAAA;AAE5B,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,SAAK,GAAG,WAAW,CAgC3E"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mongodb-compose.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongodb-compose.spec.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongodb-compose.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Adds a case-insensitive regex filter to the filters array if a value is provided.
3
+ *
4
+ * @param filters - An array of MongoDB filter objects to be modified.
5
+ * @param field - The field name to apply the regex on.
6
+ * @param value - The string value to search for (optional). If empty or only whitespace, no filter is added.
7
+ */
8
+ export declare const addRegexFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void;
9
+ /**
10
+ * Adds a numeric filter to the filters array based on comparison operators or a single value.
11
+ *
12
+ * Accepts expressions like `">10<20"`, `"<=15"`, `"=5"` or `"50"` (interpreted as equality).
13
+ *
14
+ * @param filters - An array of MongoDB filter objects to be modified.
15
+ * @param field - The field name to apply the numeric comparison on.
16
+ * @param value - A string representing the numeric comparison(s).
17
+ */
18
+ export declare const addNumberFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void;
19
+ /**
20
+ * Parses a string expression into MongoDB-style numeric comparison operators.
21
+ *
22
+ * Supported formats:
23
+ * - `"50"` → `{ eq: 50 }`
24
+ * - `">10"` → `{ gt: 10 }`
25
+ * - `"<=15"` → `{ lte: 15 }`
26
+ * - `">=5<20"` → `{ gte: 5, lt: 20 }`
27
+ *
28
+ * Constraints:
29
+ * - Only one lower-bound (`>` or `>=`) and one upper-bound (`<` or `<=`) operator are allowed.
30
+ * - Throws an API error for malformed or ambiguous expressions.
31
+ *
32
+ * @param expr - A string representing numeric comparisons.
33
+ * @returns An object with numeric comparison constraints.
34
+ *
35
+ * @throws Will throw an API error if the input format is invalid or has duplicate bounds.
36
+ */
37
+ export declare const parseComparisons: (expr: string) => {
38
+ gt?: number;
39
+ gte?: number;
40
+ lt?: number;
41
+ lte?: number;
42
+ eq?: number;
43
+ };
44
+ declare const _default: {
45
+ parseComparisons: (expr: string) => {
46
+ gt?: number;
47
+ gte?: number;
48
+ lt?: number;
49
+ lte?: number;
50
+ eq?: number;
51
+ };
52
+ addNumberFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void;
53
+ addRegexFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void;
54
+ };
55
+ export default _default;
56
+ //# sourceMappingURL=mongodb-query-filters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongodb-query-filters.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongodb-query-filters.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,MAAM,EAAE,QAAQ,MAAM,SAI/F,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,MAAM,EAAE,QAAQ,MAAM,SAmBhG,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,MAAM,KACX;IACD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,EAAE,CAAC,EAAE,MAAM,CAAA;CA2CZ,CAAA;;6BAjDO,MAAM,KACX;QACD,EAAE,CAAC,EAAE,MAAM,CAAA;QACX,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,EAAE,CAAC,EAAE,MAAM,CAAA;QACX,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,EAAE,CAAC,EAAE,MAAM,CAAA;KACZ;+BA/CwC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,MAAM,UAAU,MAAM;8BAfzD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,MAAM,UAAU,MAAM;;AA0GhG,wBAIC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mongodb-query-filters.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongodb-query-filters.spec.d.ts","sourceRoot":"","sources":["../../../../src/database/mongodb/mongodb-query-filters.spec.ts"],"names":[],"mappings":""}
@@ -11,6 +11,7 @@ export declare const stubDir: string;
11
11
  export { ExpressCli as BaseConsoleCli } from '@point-hub/express-cli';
12
12
  export declare const BaseConsoleCommand: typeof BaseCommand;
13
13
  export declare const BaseConsoleKernel: typeof ConsoleKernel;
14
+ export { composeUpdate } from './database/mongodb/mongodb-compose';
14
15
  export { DatabaseTestUtil } from './test/utils';
15
16
  export declare const BaseDatabaseConnection: typeof DatabaseConnection;
16
17
  export declare const BaseMongoDBConnection: typeof MongoDBConnection;
@@ -26,6 +27,7 @@ export declare const BaseMongoDBQuerystring: {
26
27
  convertStringToArray: typeof import("./database/mongodb/mongodb-querystring").convertStringToArray;
27
28
  convertArrayToObject: typeof import("./database/mongodb/mongodb-querystring").convertArrayToObject;
28
29
  };
30
+ export { default as BaseMongoDBQueryFilters } from './database/mongodb/mongodb-query-filters';
29
31
  export declare const BaseMongoServerError: typeof MongoServerError;
30
32
  export declare const BaseMongoErrorHandler: typeof MongoErrorHandler;
31
33
  export { default as BaseFactory } from '@point-hub/express-factory';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EACL,QAAQ,EACR,SAAS,EACT,sBAAsB,EACtB,IAAI,EACJ,qBAAqB,EAErB,KAAK,cAAc,EACpB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAA;AAEjE,OAAO,6BAA6B,MAAM,+CAA+C,CAAA;AAEzF,eAAO,MAAM,OAAO,QAAqF,CAAA;AAGzG,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACrE,eAAO,MAAM,kBAAkB,oBAAc,CAAA;AAC7C,eAAO,MAAM,iBAAiB,sBAAgB,CAAA;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,eAAO,MAAM,sBAAsB,2BAAqB,CAAA;AACxD,eAAO,MAAM,qBAAqB,0BAAoB,CAAA;AACtD,eAAO,MAAM,iBAAiB,sBAAgB,CAAA;AAC9C,eAAO,MAAM,sBAAsB;;;;;;;;;;CAAc,CAAA;AACjD,eAAO,MAAM,oBAAoB,yBAAmB,CAAA;AACpD,eAAO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AAM,EACN,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,EACf,mBAAmB,EACnB,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,QAAQ,GACT,MAAM,oBAAoB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@point-hub/papi",
3
- "version": "0.5.14",
3
+ "version": "0.5.16",
4
4
  "description": "Point API Framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",