crud-query-parser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/README.md +154 -0
- package/dist/adapters/typeorm/index.d.mts +84 -0
- package/dist/adapters/typeorm/index.d.ts +84 -0
- package/dist/adapters/typeorm/index.js +2 -0
- package/dist/adapters/typeorm/index.js.map +1 -0
- package/dist/adapters/typeorm/index.mjs +2 -0
- package/dist/adapters/typeorm/index.mjs.map +1 -0
- package/dist/crud-request-CvDKp6Iy.d.mts +83 -0
- package/dist/crud-request-CvDKp6Iy.d.ts +83 -0
- package/dist/filters/index.d.mts +37 -0
- package/dist/filters/index.d.ts +37 -0
- package/dist/filters/index.js +2 -0
- package/dist/filters/index.js.map +1 -0
- package/dist/filters/index.mjs +2 -0
- package/dist/filters/index.mjs.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/parsed-request-where.builder-CTGRmvAX.d.ts +42 -0
- package/dist/parsed-request-where.builder-LCWNWCt6.d.mts +42 -0
- package/dist/parsers/crud/index.d.mts +20 -0
- package/dist/parsers/crud/index.d.ts +20 -0
- package/dist/parsers/crud/index.js +2 -0
- package/dist/parsers/crud/index.js.map +1 -0
- package/dist/parsers/crud/index.mjs +2 -0
- package/dist/parsers/crud/index.mjs.map +1 -0
- package/dist/query-adapter-BliD9hJN.d.mts +55 -0
- package/dist/query-adapter-Vebxws3V.d.ts +55 -0
- package/package.json +107 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
import { c as CrudRequest, d as CrudRequestWhere } from '../crud-request-CvDKp6Iy.js';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Ensures a condition is always applied to the query
|
5
|
+
*
|
6
|
+
* @param request The parsed request
|
7
|
+
* @param condition The condition that needs to be applied
|
8
|
+
*/
|
9
|
+
declare function ensureCondition(request: CrudRequest, condition: CrudRequestWhere): CrudRequest;
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Ensures that the limit will be set following a maximum rule
|
13
|
+
*
|
14
|
+
* @param request The parsed request
|
15
|
+
* @param defaultLimit The default limit number
|
16
|
+
* @param maxLimit The maximum allowed limit number
|
17
|
+
*/
|
18
|
+
declare function ensureLimit(request: CrudRequest, defaultLimit: number, maxLimit: number): CrudRequest;
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Filters access to an allowlist of properties and relations.
|
22
|
+
* No selecting, filtering, sorting and joining can be done on a property that is not listed.
|
23
|
+
*
|
24
|
+
* @param request The parsed request
|
25
|
+
* @param allowedProperties The list of properties (in case of a field path, separated by dot) that will be allowed
|
26
|
+
*/
|
27
|
+
declare function filterProperties(request: CrudRequest, allowedProperties: string[]): CrudRequest;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Filters access to an allowlist of relations.
|
31
|
+
*
|
32
|
+
* @param request The parsed request
|
33
|
+
* @param allowedRelations The list of relations (in case of a field path, separated by dot) that will be allowed
|
34
|
+
*/
|
35
|
+
declare function filterRelations(request: CrudRequest, allowedRelations: string[]): CrudRequest;
|
36
|
+
|
37
|
+
export { ensureCondition, ensureLimit, filterProperties, filterRelations };
|
@@ -0,0 +1,2 @@
|
|
1
|
+
"use strict";var f=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var n=(r,e)=>f(r,"name",{value:e,configurable:!0});var C=(r,e)=>{for(var t in e)f(r,t,{get:e[t],enumerable:!0})},R=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of l(e))!c.call(r,i)&&i!==t&&f(r,i,{get:()=>e[i],enumerable:!(o=m(e,i))||o.enumerable});return r};var p=r=>R(f({},"__esModule",{value:!0}),r);var W={};C(W,{ensureCondition:()=>a,ensureLimit:()=>h,filterProperties:()=>x,filterRelations:()=>q});module.exports=p(W);function a(r,e){return r.where.and?{...r,where:{and:[...r.where.and,e]}}:{...r,where:{and:[e,r.where]}}}n(a,"ensureCondition");function h(r,e,t){return{...r,limit:Math.min(Math.max(r.limit??e,1),t)}}n(h,"ensureLimit");function x(r,e){let t=r.select;t.length===0?t=e.map(u=>({field:u.split(".")})):t=r.select.filter(u=>e.includes(u.field.join(".")));let o=d(r.where,e),i=r.order.filter(u=>e.includes(u.field.join("."))),s=r.relations.filter(u=>e.includes(u.field.join(".")));return{...r,select:t,where:o,order:i,relations:s}}n(x,"filterProperties");function d(r,e){return r.or?{or:r.or.map(t=>d(t,e))}:r.and?{and:r.and.map(t=>d(t,e))}:r.field&&!e.includes(r.field.join("."))?{and:[]}:r}n(d,"filterPropertyAccessWhere");function q(r,e){let t=r.relations.filter(o=>e.includes(o.field.join(".")));return{...r,relations:t}}n(q,"filterRelations");0&&(module.exports={ensureCondition,ensureLimit,filterProperties,filterRelations});
|
2
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/filters/index.ts","../../src/filters/conditions/ensureCondition.ts","../../src/filters/limit/ensureLimit.ts","../../src/filters/property/filterProperties.ts","../../src/filters/property/filterRelations.ts"],"sourcesContent":["\r\nexport * from './conditions/ensureCondition';\r\nexport * from './limit/ensureLimit';\r\nexport * from './property/filterProperties';\r\nexport * from './property/filterRelations';\r\n","import { CrudRequest } from '../../models/crud-request';\r\nimport { CrudRequestWhere } from '../../models/crud-request-where';\r\n\r\n/**\r\n * Ensures a condition is always applied to the query\r\n *\r\n * @param request The parsed request\r\n * @param condition The condition that needs to be applied\r\n */\r\nexport function ensureCondition(request: CrudRequest, condition: CrudRequestWhere): CrudRequest {\r\n // If there is already an \"AND\" condition, we'll just append to that\r\n if (request.where.and) {\r\n return {\r\n ...request,\r\n where: {\r\n and: [\r\n ...request.where.and,\r\n condition,\r\n ]\r\n }\r\n }\r\n }\r\n\r\n return {\r\n ...request,\r\n where: {\r\n and: [\r\n condition,\r\n request.where,\r\n ],\r\n },\r\n };\r\n}\r\n","import { CrudRequest } from '../../models/crud-request';\r\n\r\n/**\r\n * Ensures that the limit will be set following a maximum rule\r\n *\r\n * @param request The parsed request\r\n * @param defaultLimit The default limit number\r\n * @param maxLimit The maximum allowed limit number\r\n */\r\nexport function ensureLimit(request: CrudRequest, defaultLimit: number, maxLimit: number): CrudRequest {\r\n return {\r\n ...request,\r\n limit: Math.min(Math.max(request.limit ?? defaultLimit, 1), maxLimit),\r\n };\r\n}\r\n","import { CrudRequest } from '../../models/crud-request';\r\nimport { CrudRequestWhere } from '../../models/crud-request-where';\r\n\r\n/**\r\n * Filters access to an allowlist of properties and relations.\r\n * No selecting, filtering, sorting and joining can be done on a property that is not listed.\r\n *\r\n * @param request The parsed request\r\n * @param allowedProperties The list of properties (in case of a field path, separated by dot) that will be allowed\r\n */\r\nexport function filterProperties(\r\n request: CrudRequest,\r\n allowedProperties: string[],\r\n): CrudRequest {\r\n let select = request.select;\r\n\r\n if (select.length === 0) {\r\n select = allowedProperties.map(prop => ({ field: prop.split('.') }));\r\n } else {\r\n select = request.select.filter(item => allowedProperties.includes(item.field.join('.')));\r\n }\r\n\r\n const where = filterPropertyAccessWhere(request.where, allowedProperties);\r\n\r\n const order = request.order.filter(item => allowedProperties.includes(item.field.join('.')));\r\n\r\n // TODO allow relations by the first part of field paths\r\n const relations = request.relations.filter(item => allowedProperties.includes(item.field.join('.')));\r\n\r\n return {\r\n ...request,\r\n select,\r\n where,\r\n order,\r\n relations,\r\n };\r\n}\r\n\r\nfunction filterPropertyAccessWhere(\r\n where: CrudRequestWhere,\r\n allowedProperties: string[],\r\n): CrudRequestWhere {\r\n if (where.or) {\r\n return {\r\n or: where.or.map(w => filterPropertyAccessWhere(w, allowedProperties)),\r\n };\r\n }\r\n\r\n if (where.and) {\r\n return {\r\n and: where.and.map(w => filterPropertyAccessWhere(w, allowedProperties)),\r\n };\r\n }\r\n\r\n if (where.field) {\r\n // We'll return an empty AND where if the field is not allowed\r\n if (!allowedProperties.includes(where.field.join('.')))\r\n return { and: [] };\r\n }\r\n\r\n return where;\r\n}\r\n\r\n","import { CrudRequest } from '../../models/crud-request';\r\n\r\n/**\r\n * Filters access to an allowlist of relations.\r\n *\r\n * @param request The parsed request\r\n * @param allowedRelations The list of relations (in case of a field path, separated by dot) that will be allowed\r\n */\r\nexport function filterRelations(\r\n request: CrudRequest,\r\n allowedRelations: string[],\r\n): CrudRequest {\r\n const relations = request.relations.filter(item => allowedRelations.includes(item.field.join('.')));\r\n\r\n return {\r\n ...request,\r\n relations,\r\n };\r\n}\r\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,gBAAAC,EAAA,qBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAN,GCSO,SAASO,EAAgBC,EAAsBC,EAA0C,CAE9F,OAAID,EAAQ,MAAM,IACT,CACL,GAAGA,EACH,MAAO,CACL,IAAK,CACH,GAAGA,EAAQ,MAAM,IACjBC,CACF,CACF,CACF,EAGK,CACL,GAAGD,EACH,MAAO,CACL,IAAK,CACHC,EACAD,EAAQ,KACV,CACF,CACF,CACF,CAvBgBE,EAAAH,EAAA,mBCAT,SAASI,EAAYC,EAAsBC,EAAsBC,EAA+B,CACrG,MAAO,CACL,GAAGF,EACH,MAAO,KAAK,IAAI,KAAK,IAAIA,EAAQ,OAASC,EAAc,CAAC,EAAGC,CAAQ,CACtE,CACF,CALgBC,EAAAJ,EAAA,eCCT,SAASK,EACdC,EACAC,EACa,CACb,IAAIC,EAASF,EAAQ,OAEjBE,EAAO,SAAW,EACpBA,EAASD,EAAkB,IAAIE,IAAS,CAAE,MAAOA,EAAK,MAAM,GAAG,CAAE,EAAE,EAEnED,EAASF,EAAQ,OAAO,OAAOI,GAAQH,EAAkB,SAASG,EAAK,MAAM,KAAK,GAAG,CAAC,CAAC,EAGzF,IAAMC,EAAQC,EAA0BN,EAAQ,MAAOC,CAAiB,EAElEM,EAAQP,EAAQ,MAAM,OAAOI,GAAQH,EAAkB,SAASG,EAAK,MAAM,KAAK,GAAG,CAAC,CAAC,EAGrFI,EAAYR,EAAQ,UAAU,OAAOI,GAAQH,EAAkB,SAASG,EAAK,MAAM,KAAK,GAAG,CAAC,CAAC,EAEnG,MAAO,CACL,GAAGJ,EACH,OAAAE,EACA,MAAAG,EACA,MAAAE,EACA,UAAAC,CACF,CACF,CA1BgBC,EAAAV,EAAA,oBA4BhB,SAASO,EACPD,EACAJ,EACkB,CAClB,OAAII,EAAM,GACD,CACL,GAAIA,EAAM,GAAG,IAAIK,GAAKJ,EAA0BI,EAAGT,CAAiB,CAAC,CACvE,EAGEI,EAAM,IACD,CACL,IAAKA,EAAM,IAAI,IAAIK,GAAKJ,EAA0BI,EAAGT,CAAiB,CAAC,CACzE,EAGEI,EAAM,OAEJ,CAACJ,EAAkB,SAASI,EAAM,MAAM,KAAK,GAAG,CAAC,EAC5C,CAAE,IAAK,CAAC,CAAE,EAGdA,CACT,CAvBSI,EAAAH,EAAA,6BC9BF,SAASK,EACdC,EACAC,EACa,CACb,IAAMC,EAAYF,EAAQ,UAAU,OAAOG,GAAQF,EAAiB,SAASE,EAAK,MAAM,KAAK,GAAG,CAAC,CAAC,EAElG,MAAO,CACL,GAAGH,EACH,UAAAE,CACF,CACF,CAVgBE,EAAAL,EAAA","names":["filters_exports","__export","ensureCondition","ensureLimit","filterProperties","filterRelations","__toCommonJS","ensureCondition","request","condition","__name","ensureLimit","request","defaultLimit","maxLimit","__name","filterProperties","request","allowedProperties","select","prop","item","where","filterPropertyAccessWhere","order","relations","__name","w","filterRelations","request","allowedRelations","relations","item","__name"]}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
var s=Object.defineProperty;var n=(r,e)=>s(r,"name",{value:e,configurable:!0});function l(r,e){return r.where.and?{...r,where:{and:[...r.where.and,e]}}:{...r,where:{and:[e,r.where]}}}n(l,"ensureCondition");function R(r,e,t){return{...r,limit:Math.min(Math.max(r.limit??e,1),t)}}n(R,"ensureLimit");function h(r,e){let t=r.select;t.length===0?t=e.map(i=>({field:i.split(".")})):t=r.select.filter(i=>e.includes(i.field.join(".")));let u=o(r.where,e),f=r.order.filter(i=>e.includes(i.field.join("."))),d=r.relations.filter(i=>e.includes(i.field.join(".")));return{...r,select:t,where:u,order:f,relations:d}}n(h,"filterProperties");function o(r,e){return r.or?{or:r.or.map(t=>o(t,e))}:r.and?{and:r.and.map(t=>o(t,e))}:r.field&&!e.includes(r.field.join("."))?{and:[]}:r}n(o,"filterPropertyAccessWhere");function W(r,e){let t=r.relations.filter(u=>e.includes(u.field.join(".")));return{...r,relations:t}}n(W,"filterRelations");export{l as ensureCondition,R as ensureLimit,h as filterProperties,W as filterRelations};
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/filters/conditions/ensureCondition.ts","../../src/filters/limit/ensureLimit.ts","../../src/filters/property/filterProperties.ts","../../src/filters/property/filterRelations.ts"],"sourcesContent":["import { CrudRequest } from '../../models/crud-request';\r\nimport { CrudRequestWhere } from '../../models/crud-request-where';\r\n\r\n/**\r\n * Ensures a condition is always applied to the query\r\n *\r\n * @param request The parsed request\r\n * @param condition The condition that needs to be applied\r\n */\r\nexport function ensureCondition(request: CrudRequest, condition: CrudRequestWhere): CrudRequest {\r\n // If there is already an \"AND\" condition, we'll just append to that\r\n if (request.where.and) {\r\n return {\r\n ...request,\r\n where: {\r\n and: [\r\n ...request.where.and,\r\n condition,\r\n ]\r\n }\r\n }\r\n }\r\n\r\n return {\r\n ...request,\r\n where: {\r\n and: [\r\n condition,\r\n request.where,\r\n ],\r\n },\r\n };\r\n}\r\n","import { CrudRequest } from '../../models/crud-request';\r\n\r\n/**\r\n * Ensures that the limit will be set following a maximum rule\r\n *\r\n * @param request The parsed request\r\n * @param defaultLimit The default limit number\r\n * @param maxLimit The maximum allowed limit number\r\n */\r\nexport function ensureLimit(request: CrudRequest, defaultLimit: number, maxLimit: number): CrudRequest {\r\n return {\r\n ...request,\r\n limit: Math.min(Math.max(request.limit ?? defaultLimit, 1), maxLimit),\r\n };\r\n}\r\n","import { CrudRequest } from '../../models/crud-request';\r\nimport { CrudRequestWhere } from '../../models/crud-request-where';\r\n\r\n/**\r\n * Filters access to an allowlist of properties and relations.\r\n * No selecting, filtering, sorting and joining can be done on a property that is not listed.\r\n *\r\n * @param request The parsed request\r\n * @param allowedProperties The list of properties (in case of a field path, separated by dot) that will be allowed\r\n */\r\nexport function filterProperties(\r\n request: CrudRequest,\r\n allowedProperties: string[],\r\n): CrudRequest {\r\n let select = request.select;\r\n\r\n if (select.length === 0) {\r\n select = allowedProperties.map(prop => ({ field: prop.split('.') }));\r\n } else {\r\n select = request.select.filter(item => allowedProperties.includes(item.field.join('.')));\r\n }\r\n\r\n const where = filterPropertyAccessWhere(request.where, allowedProperties);\r\n\r\n const order = request.order.filter(item => allowedProperties.includes(item.field.join('.')));\r\n\r\n // TODO allow relations by the first part of field paths\r\n const relations = request.relations.filter(item => allowedProperties.includes(item.field.join('.')));\r\n\r\n return {\r\n ...request,\r\n select,\r\n where,\r\n order,\r\n relations,\r\n };\r\n}\r\n\r\nfunction filterPropertyAccessWhere(\r\n where: CrudRequestWhere,\r\n allowedProperties: string[],\r\n): CrudRequestWhere {\r\n if (where.or) {\r\n return {\r\n or: where.or.map(w => filterPropertyAccessWhere(w, allowedProperties)),\r\n };\r\n }\r\n\r\n if (where.and) {\r\n return {\r\n and: where.and.map(w => filterPropertyAccessWhere(w, allowedProperties)),\r\n };\r\n }\r\n\r\n if (where.field) {\r\n // We'll return an empty AND where if the field is not allowed\r\n if (!allowedProperties.includes(where.field.join('.')))\r\n return { and: [] };\r\n }\r\n\r\n return where;\r\n}\r\n\r\n","import { CrudRequest } from '../../models/crud-request';\r\n\r\n/**\r\n * Filters access to an allowlist of relations.\r\n *\r\n * @param request The parsed request\r\n * @param allowedRelations The list of relations (in case of a field path, separated by dot) that will be allowed\r\n */\r\nexport function filterRelations(\r\n request: CrudRequest,\r\n allowedRelations: string[],\r\n): CrudRequest {\r\n const relations = request.relations.filter(item => allowedRelations.includes(item.field.join('.')));\r\n\r\n return {\r\n ...request,\r\n relations,\r\n };\r\n}\r\n"],"mappings":"+EASO,SAASA,EAAgBC,EAAsBC,EAA0C,CAE9F,OAAID,EAAQ,MAAM,IACT,CACL,GAAGA,EACH,MAAO,CACL,IAAK,CACH,GAAGA,EAAQ,MAAM,IACjBC,CACF,CACF,CACF,EAGK,CACL,GAAGD,EACH,MAAO,CACL,IAAK,CACHC,EACAD,EAAQ,KACV,CACF,CACF,CACF,CAvBgBE,EAAAH,EAAA,mBCAT,SAASI,EAAYC,EAAsBC,EAAsBC,EAA+B,CACrG,MAAO,CACL,GAAGF,EACH,MAAO,KAAK,IAAI,KAAK,IAAIA,EAAQ,OAASC,EAAc,CAAC,EAAGC,CAAQ,CACtE,CACF,CALgBC,EAAAJ,EAAA,eCCT,SAASK,EACdC,EACAC,EACa,CACb,IAAIC,EAASF,EAAQ,OAEjBE,EAAO,SAAW,EACpBA,EAASD,EAAkB,IAAIE,IAAS,CAAE,MAAOA,EAAK,MAAM,GAAG,CAAE,EAAE,EAEnED,EAASF,EAAQ,OAAO,OAAOI,GAAQH,EAAkB,SAASG,EAAK,MAAM,KAAK,GAAG,CAAC,CAAC,EAGzF,IAAMC,EAAQC,EAA0BN,EAAQ,MAAOC,CAAiB,EAElEM,EAAQP,EAAQ,MAAM,OAAOI,GAAQH,EAAkB,SAASG,EAAK,MAAM,KAAK,GAAG,CAAC,CAAC,EAGrFI,EAAYR,EAAQ,UAAU,OAAOI,GAAQH,EAAkB,SAASG,EAAK,MAAM,KAAK,GAAG,CAAC,CAAC,EAEnG,MAAO,CACL,GAAGJ,EACH,OAAAE,EACA,MAAAG,EACA,MAAAE,EACA,UAAAC,CACF,CACF,CA1BgBC,EAAAV,EAAA,oBA4BhB,SAASO,EACPD,EACAJ,EACkB,CAClB,OAAII,EAAM,GACD,CACL,GAAIA,EAAM,GAAG,IAAIK,GAAKJ,EAA0BI,EAAGT,CAAiB,CAAC,CACvE,EAGEI,EAAM,IACD,CACL,IAAKA,EAAM,IAAI,IAAIK,GAAKJ,EAA0BI,EAAGT,CAAiB,CAAC,CACzE,EAGEI,EAAM,OAEJ,CAACJ,EAAkB,SAASI,EAAM,MAAM,KAAK,GAAG,CAAC,EAC5C,CAAE,IAAK,CAAC,CAAE,EAGdA,CACT,CAvBSI,EAAAH,EAAA,6BC9BF,SAASK,EACdC,EACAC,EACa,CACb,IAAMC,EAAYF,EAAQ,UAAU,OAAOG,GAAQF,EAAiB,SAASE,EAAK,MAAM,KAAK,GAAG,CAAC,CAAC,EAElG,MAAO,CACL,GAAGH,EACH,UAAAE,CACF,CACF,CAVgBE,EAAAL,EAAA","names":["ensureCondition","request","condition","__name","ensureLimit","request","defaultLimit","maxLimit","__name","filterProperties","request","allowedProperties","select","prop","item","where","filterPropertyAccessWhere","order","relations","__name","w","filterRelations","request","allowedRelations","relations","item","__name"]}
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
export { G as GetManyResult, Q as QueryAdapter } from './query-adapter-BliD9hJN.mjs';
|
2
|
+
export { P as ParsedRequestWhereBuilder, R as RequestParamValue, a as RequestParser } from './parsed-request-where.builder-LCWNWCt6.mjs';
|
3
|
+
export { c as CrudRequest, C as CrudRequestFields, b as CrudRequestOrder, a as CrudRequestRelation, d as CrudRequestWhere, e as CrudRequestWhereAND, g as CrudRequestWhereField, f as CrudRequestWhereOR, i as CrudRequestWhereOperator, h as CrudRequestWhereValueType, F as FieldPath, P as ParsedRequestSelect } from './crud-request-CvDKp6Iy.mjs';
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
export { G as GetManyResult, Q as QueryAdapter } from './query-adapter-Vebxws3V.js';
|
2
|
+
export { P as ParsedRequestWhereBuilder, R as RequestParamValue, a as RequestParser } from './parsed-request-where.builder-CTGRmvAX.js';
|
3
|
+
export { c as CrudRequest, C as CrudRequestFields, b as CrudRequestOrder, a as CrudRequestRelation, d as CrudRequestWhere, e as CrudRequestWhereAND, g as CrudRequestWhereField, f as CrudRequestWhereOR, i as CrudRequestWhereOperator, h as CrudRequestWhereValueType, F as FieldPath, P as ParsedRequestSelect } from './crud-request-CvDKp6Iy.js';
|
package/dist/index.js
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
"use strict";var l=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var u=(n,r)=>l(n,"name",{value:r,configurable:!0});var w=(n,r)=>{for(var t in r)l(n,t,{get:r[t],enumerable:!0})},a=(n,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of N(r))!_.call(n,i)&&i!==t&&l(n,i,{get:()=>r[i],enumerable:!(s=h(r,i))||s.enumerable});return n};var T=n=>a(l({},"__esModule",{value:!0}),n);var R={};w(R,{CrudRequestWhereOperator:()=>o,ParsedRequestWhereBuilder:()=>d});module.exports=T(R);var o=(e=>(e.EQ="eq",e.NEQ="neq",e.GT="gt",e.GTE="gte",e.LT="lt",e.LTE="lte",e.STARTS="starts",e.ENDS="ends",e.CONTAINS="contains",e.NOT_CONTAINS="not_contains",e.IN="in",e.NOT_IN="not_in",e.BETWEEN="between",e.IS_NULL="is_null",e.NOT_NULL="not_null",e.EQ_LOWER="eq_lower",e.NEQ_LOWER="neq_lower",e.STARTS_LOWER="starts_lower",e.ENDS_LOWER="ends_lower",e.CONTAINS_LOWER="contains_lower",e.NOT_CONTAINS_LOWER="not_contains_lower",e.IN_LOWER="in_lower",e.NOT_IN_LOWER="not_in_lower",e))(o||{});var d=class n{constructor(r={and:[]},t){this.where=r;this.parent=t}static{u(this,"ParsedRequestWhereBuilder")}addAnd(){if(!this.where.or)return this;let r={and:[]},t=new n(r,this);return this.where.or.push(r),t}addOr(){if(!this.where.and)return this;let r={or:[]},t=new n(r,this);return this.where.and.push(r),t}addField(r,t,s){let i={field:r,operator:t,value:s};if(this.where.and)this.where.and.push(i);else if(this.where.or)this.where.or.push(i);else throw new Error("Invalid where");return this}build(){return this.parent?this.parent.build():this.where}};0&&(module.exports={CrudRequestWhereOperator,ParsedRequestWhereBuilder});
|
2
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/models/crud-request-where.ts","../src/utils/parsed-request-where.builder.ts"],"sourcesContent":["// Models\r\nexport * from './models/query-adapter';\r\nexport * from './models/request-parser';\r\n\r\nexport * from './models/get-many-result';\r\nexport * from './models/field-path';\r\nexport * from './models/crud-request';\r\nexport * from './models/crud-request-where';\r\n\r\n// Utilities\r\nexport * from './utils/parsed-request-where.builder';\r\n\r\n","import { FieldPath } from './field-path';\r\n\r\nexport type CrudRequestWhere = CrudRequestWhereAND | CrudRequestWhereOR | CrudRequestWhereField;\r\n\r\nexport interface CrudRequestWhereAND {\r\n field?: never;\r\n or?: never;\r\n and: CrudRequestWhere[];\r\n}\r\n\r\nexport interface CrudRequestWhereOR {\r\n field?: never;\r\n or: CrudRequestWhere[];\r\n and?: never;\r\n}\r\n\r\nexport interface CrudRequestWhereField {\r\n\r\n /**\r\n * Field path\r\n *\r\n * For post.category.name, this would be [\"post\", \"category\", \"name\"]\r\n */\r\n field: FieldPath;\r\n\r\n /**\r\n * The operator of the comparison\r\n */\r\n operator: CrudRequestWhereOperator;\r\n\r\n /**\r\n * The value to compare\r\n */\r\n value: CrudRequestWhereValueType | CrudRequestWhereValueType[];\r\n\r\n or?: never;\r\n and?: never;\r\n}\r\n\r\nexport type CrudRequestWhereValueType = string | number | boolean | Date | null | undefined;\r\n\r\nexport enum CrudRequestWhereOperator {\r\n EQ = 'eq',\r\n NEQ = 'neq',\r\n GT = 'gt',\r\n GTE = 'gte',\r\n LT = 'lt',\r\n LTE = 'lte',\r\n STARTS = 'starts',\r\n ENDS = 'ends',\r\n CONTAINS = 'contains',\r\n NOT_CONTAINS = 'not_contains',\r\n IN = 'in',\r\n NOT_IN = 'not_in',\r\n BETWEEN = 'between',\r\n IS_NULL = 'is_null',\r\n NOT_NULL = 'not_null',\r\n EQ_LOWER = 'eq_lower',\r\n NEQ_LOWER = 'neq_lower',\r\n STARTS_LOWER = 'starts_lower',\r\n ENDS_LOWER = 'ends_lower',\r\n CONTAINS_LOWER = 'contains_lower',\r\n NOT_CONTAINS_LOWER = 'not_contains_lower',\r\n IN_LOWER = 'in_lower',\r\n NOT_IN_LOWER = 'not_in_lower',\r\n}\r\n","import {\r\n CrudRequestWhere,\r\n CrudRequestWhereAND,\r\n CrudRequestWhereField,\r\n CrudRequestWhereOperator,\r\n CrudRequestWhereOR,\r\n CrudRequestWhereValueType\r\n} from '../models/crud-request-where';\r\n\r\n/**\r\n * A helper class that makes it easier to create a CrudRequestWhere\r\n */\r\nexport class ParsedRequestWhereBuilder {\r\n\r\n constructor(\r\n private readonly where: CrudRequestWhereAND | CrudRequestWhereOR = { and: [] },\r\n private readonly parent?: ParsedRequestWhereBuilder,\r\n ) { }\r\n\r\n /**\r\n * Adds an AND bracket\r\n */\r\n public addAnd(): ParsedRequestWhereBuilder {\r\n if (!this.where.or) {\r\n return this;\r\n }\r\n\r\n const inside: CrudRequestWhereAND = { and: [] };\r\n const builder = new ParsedRequestWhereBuilder(inside, this);\r\n\r\n this.where.or.push(inside);\r\n\r\n return builder;\r\n }\r\n\r\n /**\r\n * Adds an OR bracket\r\n */\r\n public addOr(): ParsedRequestWhereBuilder {\r\n if (!this.where.and) {\r\n return this;\r\n }\r\n\r\n const inside: CrudRequestWhereOR = { or: [] };\r\n const builder = new ParsedRequestWhereBuilder(inside, this);\r\n\r\n this.where.and.push(inside);\r\n\r\n return builder;\r\n }\r\n\r\n /**\r\n * Adds a field comparison\r\n *\r\n * @param field The field path\r\n * @param operator The comparison operator\r\n * @param value The value to compare\r\n */\r\n public addField(field: string[], operator: CrudRequestWhereOperator, value: CrudRequestWhereValueType): ParsedRequestWhereBuilder {\r\n const whereField: CrudRequestWhereField = {\r\n field,\r\n operator,\r\n value,\r\n };\r\n\r\n if (this.where.and) {\r\n this.where.and.push(whereField);\r\n } else if (this.where.or) {\r\n this.where.or.push(whereField);\r\n } else {\r\n throw new Error('Invalid where');\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Constructs the final where condition\r\n */\r\n public build(): CrudRequestWhere {\r\n if (this.parent) {\r\n return this.parent.build();\r\n }\r\n\r\n return this.where;\r\n }\r\n\r\n}\r\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,EAAA,8BAAAC,IAAA,eAAAC,EAAAJ,GCyCO,IAAKK,OACVA,EAAA,GAAK,KACLA,EAAA,IAAM,MACNA,EAAA,GAAK,KACLA,EAAA,IAAM,MACNA,EAAA,GAAK,KACLA,EAAA,IAAM,MACNA,EAAA,OAAS,SACTA,EAAA,KAAO,OACPA,EAAA,SAAW,WACXA,EAAA,aAAe,eACfA,EAAA,GAAK,KACLA,EAAA,OAAS,SACTA,EAAA,QAAU,UACVA,EAAA,QAAU,UACVA,EAAA,SAAW,WACXA,EAAA,SAAW,WACXA,EAAA,UAAY,YACZA,EAAA,aAAe,eACfA,EAAA,WAAa,aACbA,EAAA,eAAiB,iBACjBA,EAAA,mBAAqB,qBACrBA,EAAA,SAAW,WACXA,EAAA,aAAe,eAvBLA,OAAA,IC7BL,IAAMC,EAAN,MAAMC,CAA0B,CAErC,YACmBC,EAAkD,CAAE,IAAK,CAAC,CAAE,EAC5DC,EACjB,CAFiB,WAAAD,EACA,YAAAC,CACf,CAjBN,MAYuC,CAAAC,EAAA,kCAU9B,QAAoC,CACzC,GAAI,CAAC,KAAK,MAAM,GACd,OAAO,KAGT,IAAMC,EAA8B,CAAE,IAAK,CAAC,CAAE,EACxCC,EAAU,IAAIL,EAA0BI,EAAQ,IAAI,EAE1D,YAAK,MAAM,GAAG,KAAKA,CAAM,EAElBC,CACT,CAKO,OAAmC,CACxC,GAAI,CAAC,KAAK,MAAM,IACd,OAAO,KAGT,IAAMD,EAA6B,CAAE,GAAI,CAAC,CAAE,EACtCC,EAAU,IAAIL,EAA0BI,EAAQ,IAAI,EAE1D,YAAK,MAAM,IAAI,KAAKA,CAAM,EAEnBC,CACT,CASO,SAASC,EAAiBC,EAAoCC,EAA6D,CAChI,IAAMC,EAAoC,CACxC,MAAAH,EACA,SAAAC,EACA,MAAAC,CACF,EAEA,GAAI,KAAK,MAAM,IACb,KAAK,MAAM,IAAI,KAAKC,CAAU,UACrB,KAAK,MAAM,GACpB,KAAK,MAAM,GAAG,KAAKA,CAAU,MAE7B,OAAM,IAAI,MAAM,eAAe,EAGjC,OAAO,IACT,CAKO,OAA0B,CAC/B,OAAI,KAAK,OACA,KAAK,OAAO,MAAM,EAGpB,KAAK,KACd,CAEF","names":["src_exports","__export","CrudRequestWhereOperator","ParsedRequestWhereBuilder","__toCommonJS","CrudRequestWhereOperator","ParsedRequestWhereBuilder","_ParsedRequestWhereBuilder","where","parent","__name","inside","builder","field","operator","value","whereField"]}
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
var u=Object.defineProperty;var s=(t,r)=>u(t,"name",{value:r,configurable:!0});var o=(e=>(e.EQ="eq",e.NEQ="neq",e.GT="gt",e.GTE="gte",e.LT="lt",e.LTE="lte",e.STARTS="starts",e.ENDS="ends",e.CONTAINS="contains",e.NOT_CONTAINS="not_contains",e.IN="in",e.NOT_IN="not_in",e.BETWEEN="between",e.IS_NULL="is_null",e.NOT_NULL="not_null",e.EQ_LOWER="eq_lower",e.NEQ_LOWER="neq_lower",e.STARTS_LOWER="starts_lower",e.ENDS_LOWER="ends_lower",e.CONTAINS_LOWER="contains_lower",e.NOT_CONTAINS_LOWER="not_contains_lower",e.IN_LOWER="in_lower",e.NOT_IN_LOWER="not_in_lower",e))(o||{});var l=class t{constructor(r={and:[]},n){this.where=r;this.parent=n}static{s(this,"ParsedRequestWhereBuilder")}addAnd(){if(!this.where.or)return this;let r={and:[]},n=new t(r,this);return this.where.or.push(r),n}addOr(){if(!this.where.and)return this;let r={or:[]},n=new t(r,this);return this.where.and.push(r),n}addField(r,n,d){let i={field:r,operator:n,value:d};if(this.where.and)this.where.and.push(i);else if(this.where.or)this.where.or.push(i);else throw new Error("Invalid where");return this}build(){return this.parent?this.parent.build():this.where}};export{o as CrudRequestWhereOperator,l as ParsedRequestWhereBuilder};
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/models/crud-request-where.ts","../src/utils/parsed-request-where.builder.ts"],"sourcesContent":["import { FieldPath } from './field-path';\r\n\r\nexport type CrudRequestWhere = CrudRequestWhereAND | CrudRequestWhereOR | CrudRequestWhereField;\r\n\r\nexport interface CrudRequestWhereAND {\r\n field?: never;\r\n or?: never;\r\n and: CrudRequestWhere[];\r\n}\r\n\r\nexport interface CrudRequestWhereOR {\r\n field?: never;\r\n or: CrudRequestWhere[];\r\n and?: never;\r\n}\r\n\r\nexport interface CrudRequestWhereField {\r\n\r\n /**\r\n * Field path\r\n *\r\n * For post.category.name, this would be [\"post\", \"category\", \"name\"]\r\n */\r\n field: FieldPath;\r\n\r\n /**\r\n * The operator of the comparison\r\n */\r\n operator: CrudRequestWhereOperator;\r\n\r\n /**\r\n * The value to compare\r\n */\r\n value: CrudRequestWhereValueType | CrudRequestWhereValueType[];\r\n\r\n or?: never;\r\n and?: never;\r\n}\r\n\r\nexport type CrudRequestWhereValueType = string | number | boolean | Date | null | undefined;\r\n\r\nexport enum CrudRequestWhereOperator {\r\n EQ = 'eq',\r\n NEQ = 'neq',\r\n GT = 'gt',\r\n GTE = 'gte',\r\n LT = 'lt',\r\n LTE = 'lte',\r\n STARTS = 'starts',\r\n ENDS = 'ends',\r\n CONTAINS = 'contains',\r\n NOT_CONTAINS = 'not_contains',\r\n IN = 'in',\r\n NOT_IN = 'not_in',\r\n BETWEEN = 'between',\r\n IS_NULL = 'is_null',\r\n NOT_NULL = 'not_null',\r\n EQ_LOWER = 'eq_lower',\r\n NEQ_LOWER = 'neq_lower',\r\n STARTS_LOWER = 'starts_lower',\r\n ENDS_LOWER = 'ends_lower',\r\n CONTAINS_LOWER = 'contains_lower',\r\n NOT_CONTAINS_LOWER = 'not_contains_lower',\r\n IN_LOWER = 'in_lower',\r\n NOT_IN_LOWER = 'not_in_lower',\r\n}\r\n","import {\r\n CrudRequestWhere,\r\n CrudRequestWhereAND,\r\n CrudRequestWhereField,\r\n CrudRequestWhereOperator,\r\n CrudRequestWhereOR,\r\n CrudRequestWhereValueType\r\n} from '../models/crud-request-where';\r\n\r\n/**\r\n * A helper class that makes it easier to create a CrudRequestWhere\r\n */\r\nexport class ParsedRequestWhereBuilder {\r\n\r\n constructor(\r\n private readonly where: CrudRequestWhereAND | CrudRequestWhereOR = { and: [] },\r\n private readonly parent?: ParsedRequestWhereBuilder,\r\n ) { }\r\n\r\n /**\r\n * Adds an AND bracket\r\n */\r\n public addAnd(): ParsedRequestWhereBuilder {\r\n if (!this.where.or) {\r\n return this;\r\n }\r\n\r\n const inside: CrudRequestWhereAND = { and: [] };\r\n const builder = new ParsedRequestWhereBuilder(inside, this);\r\n\r\n this.where.or.push(inside);\r\n\r\n return builder;\r\n }\r\n\r\n /**\r\n * Adds an OR bracket\r\n */\r\n public addOr(): ParsedRequestWhereBuilder {\r\n if (!this.where.and) {\r\n return this;\r\n }\r\n\r\n const inside: CrudRequestWhereOR = { or: [] };\r\n const builder = new ParsedRequestWhereBuilder(inside, this);\r\n\r\n this.where.and.push(inside);\r\n\r\n return builder;\r\n }\r\n\r\n /**\r\n * Adds a field comparison\r\n *\r\n * @param field The field path\r\n * @param operator The comparison operator\r\n * @param value The value to compare\r\n */\r\n public addField(field: string[], operator: CrudRequestWhereOperator, value: CrudRequestWhereValueType): ParsedRequestWhereBuilder {\r\n const whereField: CrudRequestWhereField = {\r\n field,\r\n operator,\r\n value,\r\n };\r\n\r\n if (this.where.and) {\r\n this.where.and.push(whereField);\r\n } else if (this.where.or) {\r\n this.where.or.push(whereField);\r\n } else {\r\n throw new Error('Invalid where');\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Constructs the final where condition\r\n */\r\n public build(): CrudRequestWhere {\r\n if (this.parent) {\r\n return this.parent.build();\r\n }\r\n\r\n return this.where;\r\n }\r\n\r\n}\r\n"],"mappings":"+EAyCO,IAAKA,OACVA,EAAA,GAAK,KACLA,EAAA,IAAM,MACNA,EAAA,GAAK,KACLA,EAAA,IAAM,MACNA,EAAA,GAAK,KACLA,EAAA,IAAM,MACNA,EAAA,OAAS,SACTA,EAAA,KAAO,OACPA,EAAA,SAAW,WACXA,EAAA,aAAe,eACfA,EAAA,GAAK,KACLA,EAAA,OAAS,SACTA,EAAA,QAAU,UACVA,EAAA,QAAU,UACVA,EAAA,SAAW,WACXA,EAAA,SAAW,WACXA,EAAA,UAAY,YACZA,EAAA,aAAe,eACfA,EAAA,WAAa,aACbA,EAAA,eAAiB,iBACjBA,EAAA,mBAAqB,qBACrBA,EAAA,SAAW,WACXA,EAAA,aAAe,eAvBLA,OAAA,IC7BL,IAAMC,EAAN,MAAMC,CAA0B,CAErC,YACmBC,EAAkD,CAAE,IAAK,CAAC,CAAE,EAC5DC,EACjB,CAFiB,WAAAD,EACA,YAAAC,CACf,CAjBN,MAYuC,CAAAC,EAAA,kCAU9B,QAAoC,CACzC,GAAI,CAAC,KAAK,MAAM,GACd,OAAO,KAGT,IAAMC,EAA8B,CAAE,IAAK,CAAC,CAAE,EACxCC,EAAU,IAAIL,EAA0BI,EAAQ,IAAI,EAE1D,YAAK,MAAM,GAAG,KAAKA,CAAM,EAElBC,CACT,CAKO,OAAmC,CACxC,GAAI,CAAC,KAAK,MAAM,IACd,OAAO,KAGT,IAAMD,EAA6B,CAAE,GAAI,CAAC,CAAE,EACtCC,EAAU,IAAIL,EAA0BI,EAAQ,IAAI,EAE1D,YAAK,MAAM,IAAI,KAAKA,CAAM,EAEnBC,CACT,CASO,SAASC,EAAiBC,EAAoCC,EAA6D,CAChI,IAAMC,EAAoC,CACxC,MAAAH,EACA,SAAAC,EACA,MAAAC,CACF,EAEA,GAAI,KAAK,MAAM,IACb,KAAK,MAAM,IAAI,KAAKC,CAAU,UACrB,KAAK,MAAM,GACpB,KAAK,MAAM,GAAG,KAAKA,CAAU,MAE7B,OAAM,IAAI,MAAM,eAAe,EAGjC,OAAO,IACT,CAKO,OAA0B,CAC/B,OAAI,KAAK,OACA,KAAK,OAAO,MAAM,EAGpB,KAAK,KACd,CAEF","names":["CrudRequestWhereOperator","ParsedRequestWhereBuilder","_ParsedRequestWhereBuilder","where","parent","__name","inside","builder","field","operator","value","whereField"]}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { c as CrudRequest, e as CrudRequestWhereAND, f as CrudRequestWhereOR, i as CrudRequestWhereOperator, h as CrudRequestWhereValueType, d as CrudRequestWhere } from './crud-request-CvDKp6Iy.js';
|
2
|
+
|
3
|
+
type RequestParamValue = string | string[] | undefined;
|
4
|
+
interface RequestParser {
|
5
|
+
/**
|
6
|
+
* Parses a query string into a parsed request object
|
7
|
+
*
|
8
|
+
* @param query The query string map
|
9
|
+
*/
|
10
|
+
parse(query: Record<string, RequestParamValue>): CrudRequest;
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* A helper class that makes it easier to create a CrudRequestWhere
|
15
|
+
*/
|
16
|
+
declare class ParsedRequestWhereBuilder {
|
17
|
+
private readonly where;
|
18
|
+
private readonly parent?;
|
19
|
+
constructor(where?: CrudRequestWhereAND | CrudRequestWhereOR, parent?: ParsedRequestWhereBuilder | undefined);
|
20
|
+
/**
|
21
|
+
* Adds an AND bracket
|
22
|
+
*/
|
23
|
+
addAnd(): ParsedRequestWhereBuilder;
|
24
|
+
/**
|
25
|
+
* Adds an OR bracket
|
26
|
+
*/
|
27
|
+
addOr(): ParsedRequestWhereBuilder;
|
28
|
+
/**
|
29
|
+
* Adds a field comparison
|
30
|
+
*
|
31
|
+
* @param field The field path
|
32
|
+
* @param operator The comparison operator
|
33
|
+
* @param value The value to compare
|
34
|
+
*/
|
35
|
+
addField(field: string[], operator: CrudRequestWhereOperator, value: CrudRequestWhereValueType): ParsedRequestWhereBuilder;
|
36
|
+
/**
|
37
|
+
* Constructs the final where condition
|
38
|
+
*/
|
39
|
+
build(): CrudRequestWhere;
|
40
|
+
}
|
41
|
+
|
42
|
+
export { ParsedRequestWhereBuilder as P, type RequestParamValue as R, type RequestParser as a };
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { c as CrudRequest, e as CrudRequestWhereAND, f as CrudRequestWhereOR, i as CrudRequestWhereOperator, h as CrudRequestWhereValueType, d as CrudRequestWhere } from './crud-request-CvDKp6Iy.mjs';
|
2
|
+
|
3
|
+
type RequestParamValue = string | string[] | undefined;
|
4
|
+
interface RequestParser {
|
5
|
+
/**
|
6
|
+
* Parses a query string into a parsed request object
|
7
|
+
*
|
8
|
+
* @param query The query string map
|
9
|
+
*/
|
10
|
+
parse(query: Record<string, RequestParamValue>): CrudRequest;
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* A helper class that makes it easier to create a CrudRequestWhere
|
15
|
+
*/
|
16
|
+
declare class ParsedRequestWhereBuilder {
|
17
|
+
private readonly where;
|
18
|
+
private readonly parent?;
|
19
|
+
constructor(where?: CrudRequestWhereAND | CrudRequestWhereOR, parent?: ParsedRequestWhereBuilder | undefined);
|
20
|
+
/**
|
21
|
+
* Adds an AND bracket
|
22
|
+
*/
|
23
|
+
addAnd(): ParsedRequestWhereBuilder;
|
24
|
+
/**
|
25
|
+
* Adds an OR bracket
|
26
|
+
*/
|
27
|
+
addOr(): ParsedRequestWhereBuilder;
|
28
|
+
/**
|
29
|
+
* Adds a field comparison
|
30
|
+
*
|
31
|
+
* @param field The field path
|
32
|
+
* @param operator The comparison operator
|
33
|
+
* @param value The value to compare
|
34
|
+
*/
|
35
|
+
addField(field: string[], operator: CrudRequestWhereOperator, value: CrudRequestWhereValueType): ParsedRequestWhereBuilder;
|
36
|
+
/**
|
37
|
+
* Constructs the final where condition
|
38
|
+
*/
|
39
|
+
build(): CrudRequestWhere;
|
40
|
+
}
|
41
|
+
|
42
|
+
export { ParsedRequestWhereBuilder as P, type RequestParamValue as R, type RequestParser as a };
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { a as RequestParser, R as RequestParamValue, P as ParsedRequestWhereBuilder } from '../../parsed-request-where.builder-LCWNWCt6.mjs';
|
2
|
+
import { c as CrudRequest, P as ParsedRequestSelect, a as CrudRequestRelation, b as CrudRequestOrder } from '../../crud-request-CvDKp6Iy.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Parses a request based on the @nestjsx/crud format.
|
6
|
+
*/
|
7
|
+
declare class CrudRequestParser implements RequestParser {
|
8
|
+
parse(query: Record<string, RequestParamValue>): CrudRequest;
|
9
|
+
protected parseSelect(select: ParsedRequestSelect, rawSelect: RequestParamValue): void;
|
10
|
+
protected parseJoin(requestFields: ParsedRequestSelect, relations: CrudRequestRelation[], rawJoin: RequestParamValue): void;
|
11
|
+
protected parseOrder(ordering: CrudRequestOrder[], rawOrder: RequestParamValue): void;
|
12
|
+
protected parseNumber(raw: RequestParamValue): number | undefined;
|
13
|
+
protected parseLimits(rawLimit: RequestParamValue, rawOffset: RequestParamValue, rawPage: RequestParamValue): {
|
14
|
+
limit: number | undefined;
|
15
|
+
offset: number | undefined;
|
16
|
+
};
|
17
|
+
protected parseSearch(builder: ParsedRequestWhereBuilder, rawSearch: RequestParamValue): void;
|
18
|
+
}
|
19
|
+
|
20
|
+
export { CrudRequestParser };
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { a as RequestParser, R as RequestParamValue, P as ParsedRequestWhereBuilder } from '../../parsed-request-where.builder-CTGRmvAX.js';
|
2
|
+
import { c as CrudRequest, P as ParsedRequestSelect, a as CrudRequestRelation, b as CrudRequestOrder } from '../../crud-request-CvDKp6Iy.js';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Parses a request based on the @nestjsx/crud format.
|
6
|
+
*/
|
7
|
+
declare class CrudRequestParser implements RequestParser {
|
8
|
+
parse(query: Record<string, RequestParamValue>): CrudRequest;
|
9
|
+
protected parseSelect(select: ParsedRequestSelect, rawSelect: RequestParamValue): void;
|
10
|
+
protected parseJoin(requestFields: ParsedRequestSelect, relations: CrudRequestRelation[], rawJoin: RequestParamValue): void;
|
11
|
+
protected parseOrder(ordering: CrudRequestOrder[], rawOrder: RequestParamValue): void;
|
12
|
+
protected parseNumber(raw: RequestParamValue): number | undefined;
|
13
|
+
protected parseLimits(rawLimit: RequestParamValue, rawOffset: RequestParamValue, rawPage: RequestParamValue): {
|
14
|
+
limit: number | undefined;
|
15
|
+
offset: number | undefined;
|
16
|
+
};
|
17
|
+
protected parseSearch(builder: ParsedRequestWhereBuilder, rawSearch: RequestParamValue): void;
|
18
|
+
}
|
19
|
+
|
20
|
+
export { CrudRequestParser };
|
@@ -0,0 +1,2 @@
|
|
1
|
+
"use strict";var c=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var u=(s,e)=>c(s,"name",{value:e,configurable:!0});var S=(s,e)=>{for(var r in e)c(s,r,{get:e[r],enumerable:!0})},_=(s,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of T(e))!O.call(s,t)&&t!==r&&c(s,t,{get:()=>e[t],enumerable:!(i=E(e,t))||i.enumerable});return s};var $=s=>_(c({},"__esModule",{value:!0}),s);var A={};S(A,{CrudRequestParser:()=>m});module.exports=$(A);var h=class s{constructor(e={and:[]},r){this.where=e;this.parent=r}static{u(this,"ParsedRequestWhereBuilder")}addAnd(){if(!this.where.or)return this;let e={and:[]},r=new s(e,this);return this.where.or.push(e),r}addOr(){if(!this.where.and)return this;let e={or:[]},r=new s(e,this);return this.where.and.push(e),r}addField(e,r,i){let t={field:e,operator:r,value:i};if(this.where.and)this.where.and.push(t);else if(this.where.or)this.where.or.push(t);else throw new Error("Invalid where");return this}build(){return this.parent?this.parent.build():this.where}};function f(s){return s!=null}u(f,"isValid");function l(s,e,r=[]){if(typeof e!="object")return;let i=Object.keys(e);if(i.length===0)return;let{$or:t,$and:n,...o}=e;if(n){let d=n.length>1||i.length>1?s.addAnd():s;n.forEach(a=>l(d,a,r)),R(d,o,r);return}if(t&&i.length===1){let d=t.length>1?s.addOr():s;t.forEach(a=>l(d,a,r));return}if(t){let d=s.addAnd(),a=t.length>1?d.addOr():d;R(d,o,r),t.forEach(p=>l(a,p,r));return}i.length>1&&(s=s.addAnd()),R(s,o,r)}u(l,"parseCrudSearch");function R(s,e,r){for(let i of Object.keys(e)){let t=e[i];if(!f(t))continue;let n=[...r,...i.split(".")];if(Array.isArray(t)){t.forEach(o=>l(s,o,n));continue}N(s,n,t)}}u(R,"parseCrudSearchFields");function N(s,e,r){if(typeof r!="object"){s.addField(e,"eq",r);return}let i={$eq:"eq",$ne:"neq",$gt:"gt",$lt:"lt",$gte:"gte",$lte:"lte",$starts:"starts",$ends:"ends",$cont:"contains",$excl:"not_contains",$in:"in",$notin:"not_in",$between:"between",$isnull:"is_null",$notnull:"not_null",$eqL:"eq_lower",$neL:"neq_lower",$startsL:"starts_lower",$endsL:"ends_lower",$contL:"contains_lower",$exclL:"not_contains_lower",$inL:"in_lower",$notinL:"not_in_lower"},t=Object.keys(r);for(let n of t){if(!i[n])continue;let o=r[n];Array.isArray(o)?o.forEach(d=>s.addField(e,i[n],d)):s.addField(e,i[n],o)}r.$or&&N(s.addOr(),e,r.$or)}u(N,"parseCrudSearchField");var m=class{static{u(this,"CrudRequestParser")}parse(e){let r=[],i=[],t=[],n=new h;this.parseSelect(r,e.fields||e.select),this.parseJoin(r,i,e.join),this.parseOrder(t,e.sort),this.parseSearch(n,e.s);let{limit:o,offset:d}=this.parseLimits(e.limit,e.offset,e.page);return{select:r,relations:i,order:t,where:n.build(),limit:o,offset:d}}parseSelect(e,r){if(!r)return;(Array.isArray(r)?r:r.split(",")).forEach(t=>{e.push({field:t.split(".")})})}parseJoin(e,r,i){if(!i)return;if(Array.isArray(i)){i.forEach(a=>this.parseJoin(e,r,a));return}let t=i.toString(),[n,o]=t.split("||",2),d=n.split(".");r.push({field:d}),o&&o.split(",").forEach(p=>{e.push({field:[...d,p]})})}parseOrder(e,r){if(!r)return;if(Array.isArray(r)){r.forEach(n=>this.parseOrder(e,n));return}let[i,t]=r.split(",");e.push({field:i.split("."),order:t?.toUpperCase()==="DESC"?"DESC":"ASC"})}parseNumber(e){if(Array.isArray(e)&&(e=e.length>0?e[0]:void 0),!f(e))return;let r=+e;return isNaN(r)?void 0:r}parseLimits(e,r,i){let t=this.parseNumber(e),n=this.parseNumber(r);if(t&&!n){let o=this.parseNumber(i);o&&(n=t*o)}return{limit:t,offset:n}}parseSearch(e,r){if(Array.isArray(r)&&(r=r.length>0?r[0]:void 0),!r)return;let i=JSON.parse(r);l(e,i)}};0&&(module.exports={CrudRequestParser});
|
2
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/parsers/crud/index.ts","../../../src/utils/parsed-request-where.builder.ts","../../../src/utils/functions.ts","../../../src/parsers/crud/parseCrudSearch.ts","../../../src/parsers/crud/crud-request.parser.ts"],"sourcesContent":["\r\nexport * from './crud-request.parser';\r\n","import {\r\n CrudRequestWhere,\r\n CrudRequestWhereAND,\r\n CrudRequestWhereField,\r\n CrudRequestWhereOperator,\r\n CrudRequestWhereOR,\r\n CrudRequestWhereValueType\r\n} from '../models/crud-request-where';\r\n\r\n/**\r\n * A helper class that makes it easier to create a CrudRequestWhere\r\n */\r\nexport class ParsedRequestWhereBuilder {\r\n\r\n constructor(\r\n private readonly where: CrudRequestWhereAND | CrudRequestWhereOR = { and: [] },\r\n private readonly parent?: ParsedRequestWhereBuilder,\r\n ) { }\r\n\r\n /**\r\n * Adds an AND bracket\r\n */\r\n public addAnd(): ParsedRequestWhereBuilder {\r\n if (!this.where.or) {\r\n return this;\r\n }\r\n\r\n const inside: CrudRequestWhereAND = { and: [] };\r\n const builder = new ParsedRequestWhereBuilder(inside, this);\r\n\r\n this.where.or.push(inside);\r\n\r\n return builder;\r\n }\r\n\r\n /**\r\n * Adds an OR bracket\r\n */\r\n public addOr(): ParsedRequestWhereBuilder {\r\n if (!this.where.and) {\r\n return this;\r\n }\r\n\r\n const inside: CrudRequestWhereOR = { or: [] };\r\n const builder = new ParsedRequestWhereBuilder(inside, this);\r\n\r\n this.where.and.push(inside);\r\n\r\n return builder;\r\n }\r\n\r\n /**\r\n * Adds a field comparison\r\n *\r\n * @param field The field path\r\n * @param operator The comparison operator\r\n * @param value The value to compare\r\n */\r\n public addField(field: string[], operator: CrudRequestWhereOperator, value: CrudRequestWhereValueType): ParsedRequestWhereBuilder {\r\n const whereField: CrudRequestWhereField = {\r\n field,\r\n operator,\r\n value,\r\n };\r\n\r\n if (this.where.and) {\r\n this.where.and.push(whereField);\r\n } else if (this.where.or) {\r\n this.where.or.push(whereField);\r\n } else {\r\n throw new Error('Invalid where');\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Constructs the final where condition\r\n */\r\n public build(): CrudRequestWhere {\r\n if (this.parent) {\r\n return this.parent.build();\r\n }\r\n\r\n return this.where;\r\n }\r\n\r\n}\r\n","import { CrudRequestFields } from '../models/crud-request';\r\n\r\n/*export function setFieldByPath<T>(obj: ParsedRequestFields<T>, field: string, value: T): void {\r\n const parts = field.split('.');\r\n\r\n while (parts.length > 1) {\r\n const name = parts.shift();\r\n\r\n if (!Array.isArray(obj[name]))\r\n obj[name] = {};\r\n\r\n obj = obj[name] as ParsedRequestFields<T>;\r\n }\r\n\r\n obj[parts.shift()] = value;\r\n}*/\r\n\r\nexport function ensureArray<T>(fieldName: string, data: T[] | any, minLength: number = 0): T[] {\r\n if (!Array.isArray(data) || data.length < minLength)\r\n throw new Error(`${fieldName} must be an array with at least ${minLength} items`);\r\n\r\n return data;\r\n}\r\n\r\nexport function ensureFalsy(fieldName: string, data: any) {\r\n if (data)\r\n throw new Error(`${fieldName} must be null`);\r\n}\r\n\r\nexport function isValid(value: any): value is object {\r\n return value !== null && value !== undefined;\r\n}\r\n","import { ParsedRequestWhereBuilder } from '../../utils/parsed-request-where.builder';\r\nimport { CrudRequestWhereOperator } from '../../models/crud-request-where';\r\nimport { SCondition, SField, SFieldOperator, SFields } from './types';\r\nimport { isValid } from '../../utils/functions';\r\n\r\n/**\r\n * Parses a crud request condition and inserts into a ParsedRequestWhereBuilder\r\n *\r\n * @param builder The builder that the condition will be inserted to\r\n * @param cond The condition that must be parsed\r\n * @param context The field context\r\n */\r\nexport function parseCrudSearch(builder: ParsedRequestWhereBuilder, cond: SCondition, context: string[] = []) {\r\n if (typeof cond !== 'object')\r\n return;\r\n\r\n const keys = Object.keys(cond);\r\n\r\n if (keys.length === 0)\r\n return;\r\n\r\n const { $or, $and, ...innerFields } = cond;\r\n\r\n // { $and: [..., ...] }\r\n if ($and) {\r\n const andBuilder = $and.length > 1 || keys.length > 1 ? builder.addAnd() : builder;\r\n\r\n $and.forEach(c => parseCrudSearch(andBuilder, c, context));\r\n\r\n parseCrudSearchFields(andBuilder, innerFields as Omit<Omit<SFields, '$or'>, '$and'>, context);\r\n\r\n return;\r\n }\r\n\r\n // { $or: [..., ...] }\r\n if ($or && keys.length === 1) {\r\n const orBuilder = $or.length > 1 ? builder.addOr() : builder;\r\n\r\n $or.forEach(c => parseCrudSearch(orBuilder, c, context));\r\n\r\n return;\r\n }\r\n\r\n // { $or: [...], field1: ..., field2: ... }\r\n if ($or) {\r\n const andBuilder = builder.addAnd();\r\n const orBuilder = $or.length > 1 ? andBuilder.addOr() : andBuilder;\r\n\r\n parseCrudSearchFields(andBuilder, innerFields as Omit<Omit<SFields, '$or'>, '$and'>, context);\r\n\r\n $or.forEach(c => parseCrudSearch(orBuilder, c, context));\r\n\r\n return;\r\n }\r\n\r\n if (keys.length > 1)\r\n builder = builder.addAnd();\r\n\r\n parseCrudSearchFields(builder, innerFields as Omit<Omit<SFields, '$or'>, '$and'>, context);\r\n}\r\n\r\n/**\r\n * Parses an object from the crud request full of fields\r\n *\r\n * @param builder The builder\r\n * @param fields The fields object\r\n * @param context The context\r\n */\r\nfunction parseCrudSearchFields(builder: ParsedRequestWhereBuilder, fields: Omit<Omit<SFields, '$or'>, '$and'>, context: string[]): void {\r\n // { name: 'John', age: { $gte: 18 }, 'posts.name': { $cont: 'Greetings' } }\r\n for (const name of Object.keys(fields)) {\r\n const field = fields[name];\r\n\r\n if (!isValid(field))\r\n continue;\r\n\r\n const fieldPath = [...context, ...name.split('.')];\r\n\r\n // { name: [{ $or: [...] }] }\r\n if (Array.isArray(field)) {\r\n field.forEach(f => parseCrudSearch(builder, f, fieldPath));\r\n continue;\r\n }\r\n\r\n parseCrudSearchField(builder, fieldPath, field);\r\n }\r\n}\r\n\r\n/**\r\n * Parses a single field\r\n *\r\n * @param builder The builder\r\n * @param name The name path\r\n * @param field The field value or operator\r\n */\r\nfunction parseCrudSearchField(builder: ParsedRequestWhereBuilder, name: string[], field: SField): void {\r\n // Primitive Value\r\n // { field: 'text', field2: 12, field3: true }\r\n if (typeof field !== 'object') {\r\n builder.addField(name, CrudRequestWhereOperator.EQ, field);\r\n return;\r\n }\r\n\r\n type OperatorType = Exclude<Exclude<keyof SFieldOperator, '$or'>, '$and'>;\r\n\r\n // Operator\r\n // { field: { $gte: 10 } }\r\n const operatorMap: Record<OperatorType, CrudRequestWhereOperator> = {\r\n $eq: CrudRequestWhereOperator.EQ,\r\n $ne: CrudRequestWhereOperator.NEQ,\r\n $gt: CrudRequestWhereOperator.GT,\r\n $lt: CrudRequestWhereOperator.LT,\r\n $gte: CrudRequestWhereOperator.GTE,\r\n $lte: CrudRequestWhereOperator.LTE,\r\n $starts: CrudRequestWhereOperator.STARTS,\r\n $ends: CrudRequestWhereOperator.ENDS,\r\n $cont: CrudRequestWhereOperator.CONTAINS,\r\n $excl: CrudRequestWhereOperator.NOT_CONTAINS,\r\n $in: CrudRequestWhereOperator.IN,\r\n $notin: CrudRequestWhereOperator.NOT_IN,\r\n $between: CrudRequestWhereOperator.BETWEEN,\r\n $isnull: CrudRequestWhereOperator.IS_NULL,\r\n $notnull: CrudRequestWhereOperator.NOT_NULL,\r\n $eqL: CrudRequestWhereOperator.EQ_LOWER,\r\n $neL: CrudRequestWhereOperator.NEQ_LOWER,\r\n $startsL: CrudRequestWhereOperator.STARTS_LOWER,\r\n $endsL: CrudRequestWhereOperator.ENDS_LOWER,\r\n $contL: CrudRequestWhereOperator.CONTAINS_LOWER,\r\n $exclL: CrudRequestWhereOperator.NOT_CONTAINS_LOWER,\r\n $inL: CrudRequestWhereOperator.IN_LOWER,\r\n $notinL: CrudRequestWhereOperator.NOT_IN_LOWER,\r\n };\r\n\r\n const keys = Object.keys(field) as OperatorType[];\r\n\r\n for (let key of keys) {\r\n if (!operatorMap[key])\r\n continue;\r\n\r\n const value = field[key];\r\n\r\n if (Array.isArray(value))\r\n value.forEach(val => builder.addField(name, operatorMap[key], val));\r\n else\r\n builder.addField(name, operatorMap[key], value);\r\n }\r\n\r\n if (field.$or) {\r\n parseCrudSearchField(builder.addOr(), name, field.$or);\r\n }\r\n}\r\n","import { RequestParamValue, RequestParser } from '../../models/request-parser';\r\nimport {\r\n CrudRequest,\r\n CrudRequestOrder,\r\n CrudRequestRelation,\r\n ParsedRequestSelect\r\n} from '../../models/crud-request';\r\nimport { ParsedRequestWhereBuilder } from '../../utils/parsed-request-where.builder';\r\nimport { parseCrudSearch } from './parseCrudSearch';\r\nimport { isValid } from '../../utils/functions';\r\nimport { SCondition } from './types';\r\n\r\n/**\r\n * Parses a request based on the @nestjsx/crud format.\r\n */\r\nexport class CrudRequestParser implements RequestParser {\r\n\r\n public parse(query: Record<string, RequestParamValue>): CrudRequest {\r\n const select: ParsedRequestSelect = [];\r\n const relations: CrudRequestRelation[] = [];\r\n const ordering: CrudRequestOrder[] = [];\r\n const where = new ParsedRequestWhereBuilder();\r\n\r\n this.parseSelect(select, query['fields'] || query['select']);\r\n this.parseJoin(select, relations, query['join']);\r\n this.parseOrder(ordering, query['sort']);\r\n this.parseSearch(where, query['s']);\r\n\r\n const { limit, offset } = this.parseLimits(query['limit'], query['offset'], query['page']);\r\n\r\n return {\r\n select,\r\n relations,\r\n order: ordering,\r\n where: where.build(),\r\n limit,\r\n offset,\r\n };\r\n }\r\n\r\n protected parseSelect(select: ParsedRequestSelect, rawSelect: RequestParamValue): void {\r\n if (!rawSelect)\r\n return;\r\n\r\n const selectFields = Array.isArray(rawSelect) ? rawSelect : rawSelect.split(',');\r\n\r\n selectFields.forEach(field => {\r\n select.push({\r\n field: field.split('.'),\r\n });\r\n });\r\n }\r\n\r\n protected parseJoin(requestFields: ParsedRequestSelect, relations: CrudRequestRelation[], rawJoin: RequestParamValue): void {\r\n if (!rawJoin)\r\n return;\r\n\r\n if (Array.isArray(rawJoin)) {\r\n rawJoin.forEach(value => this.parseJoin(requestFields, relations, value));\r\n return;\r\n }\r\n\r\n const join = rawJoin.toString();\r\n\r\n const [field, select] = join.split('||', 2);\r\n const fieldPath = field.split('.');\r\n\r\n relations.push({\r\n field: fieldPath,\r\n });\r\n\r\n if (select) {\r\n const selectFields = select.split(',');\r\n\r\n selectFields.forEach(f => {\r\n requestFields.push({\r\n field: [...fieldPath, f],\r\n });\r\n });\r\n }\r\n }\r\n\r\n protected parseOrder(ordering: CrudRequestOrder[], rawOrder: RequestParamValue): void {\r\n if (!rawOrder)\r\n return;\r\n\r\n if (Array.isArray(rawOrder)) {\r\n rawOrder.forEach(value => this.parseOrder(ordering, value));\r\n return;\r\n }\r\n\r\n const [field, direction] = rawOrder.split(',');\r\n\r\n ordering.push({\r\n field: field.split('.'),\r\n order: direction?.toUpperCase() === 'DESC' ? 'DESC' : 'ASC',\r\n });\r\n }\r\n\r\n protected parseNumber(raw: RequestParamValue): number | undefined {\r\n if (Array.isArray(raw))\r\n raw = raw.length > 0 ? raw[0] : undefined;\r\n\r\n if (!isValid(raw))\r\n return undefined;\r\n\r\n const num = +raw;\r\n\r\n return isNaN(num) ? undefined : num;\r\n }\r\n\r\n protected parseLimits(rawLimit: RequestParamValue, rawOffset: RequestParamValue, rawPage: RequestParamValue) {\r\n const limit = this.parseNumber(rawLimit);\r\n let offset = this.parseNumber(rawOffset);\r\n\r\n if (limit && !offset) {\r\n const page = this.parseNumber(rawPage);\r\n\r\n if (page)\r\n offset = limit * page;\r\n }\r\n\r\n return { limit, offset };\r\n }\r\n\r\n protected parseSearch(builder: ParsedRequestWhereBuilder, rawSearch: RequestParamValue): void {\r\n if (Array.isArray(rawSearch))\r\n rawSearch = rawSearch.length > 0 ? rawSearch[0] : undefined;\r\n\r\n if (!rawSearch)\r\n return;\r\n\r\n const search: SCondition = JSON.parse(rawSearch);\r\n\r\n parseCrudSearch(builder, search);\r\n }\r\n\r\n}\r\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GCYO,IAAMI,EAAN,MAAMC,CAA0B,CAErC,YACmBC,EAAkD,CAAE,IAAK,CAAC,CAAE,EAC5DC,EACjB,CAFiB,WAAAD,EACA,YAAAC,CACf,CAjBN,MAYuC,CAAAC,EAAA,kCAU9B,QAAoC,CACzC,GAAI,CAAC,KAAK,MAAM,GACd,OAAO,KAGT,IAAMC,EAA8B,CAAE,IAAK,CAAC,CAAE,EACxCC,EAAU,IAAIL,EAA0BI,EAAQ,IAAI,EAE1D,YAAK,MAAM,GAAG,KAAKA,CAAM,EAElBC,CACT,CAKO,OAAmC,CACxC,GAAI,CAAC,KAAK,MAAM,IACd,OAAO,KAGT,IAAMD,EAA6B,CAAE,GAAI,CAAC,CAAE,EACtCC,EAAU,IAAIL,EAA0BI,EAAQ,IAAI,EAE1D,YAAK,MAAM,IAAI,KAAKA,CAAM,EAEnBC,CACT,CASO,SAASC,EAAiBC,EAAoCC,EAA6D,CAChI,IAAMC,EAAoC,CACxC,MAAAH,EACA,SAAAC,EACA,MAAAC,CACF,EAEA,GAAI,KAAK,MAAM,IACb,K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,QAAQJ,GAAS,KAAK,WAAWT,EAAUS,CAAK,CAAC,EAC1D,MACF,CAEA,GAAM,CAACH,EAAOQ,CAAS,EAAID,EAAS,MAAM,GAAG,EAE7Cb,EAAS,KAAK,CACZ,MAAOM,EAAM,MAAM,GAAG,EACtB,MAAOQ,GAAW,YAAY,IAAM,OAAS,OAAS,KACxD,CAAC,CACH,CAEU,YAAYC,EAA4C,CAIhE,GAHI,MAAM,QAAQA,CAAG,IACnBA,EAAMA,EAAI,OAAS,EAAIA,EAAI,CAAC,EAAI,QAE9B,CAACC,EAAQD,CAAG,EACd,OAEF,IAAME,EAAM,CAACF,EAEb,OAAO,MAAME,CAAG,EAAI,OAAYA,CAClC,CAEU,YAAYC,EAA6BC,EAA8BC,EAA4B,CAC3G,IAAMjB,EAAQ,KAAK,YAAYe,CAAQ,EACnCd,EAAS,KAAK,YAAYe,CAAS,EAEvC,GAAIhB,GAAS,CAACC,EAAQ,CACpB,IAAMiB,EAAO,KAAK,YAAYD,CAAO,EAEjCC,IACFjB,EAASD,EAAQkB,EACrB,CAEA,MAAO,CAAE,MAAAlB,EAAO,OAAAC,CAAO,CACzB,CAEU,YAAYkB,EAAoCC,EAAoC,CAI5F,GAHI,MAAM,QAAQA,CAAS,IACzBA,EAAYA,EAAU,OAAS,EAAIA,EAAU,CAAC,EAAI,QAEhD,CAACA,EACH,OAEF,IAAMC,EAAqB,KAAK,MAAMD,CAAS,EAE/CE,EAAgBH,EAASE,CAAM,CACjC,CAEF","names":["crud_exports","__export","CrudRequestParser","__toCommonJS","ParsedRequestWhereBuilder","_ParsedRequestWhereBuilder","where","parent","__name","inside","builder","field","operator","value","whereField","isValid","value","__name","parseCrudSearch","builder","cond","context","keys","$or","$and","innerFields","andBuilder","c","parseCrudSearchFields","orBuilder","__name","fields","name","field","isValid","fieldPath","f","parseCrudSearchField","operatorMap","key","value","val","CrudRequestParser","__name","query","select","relations","ordering","where","ParsedRequestWhereBuilder","limit","offset","rawSelect","field","requestFields","rawJoin","value","join","fieldPath","f","rawOrder","direction","raw","isValid","num","rawLimit","rawOffset","rawPage","page","builder","rawSearch","search","parseCrudSearch"]}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
var N=Object.defineProperty;var u=(i,r)=>N(i,"name",{value:r,configurable:!0});var c=class i{constructor(r={and:[]},e){this.where=r;this.parent=e}static{u(this,"ParsedRequestWhereBuilder")}addAnd(){if(!this.where.or)return this;let r={and:[]},e=new i(r,this);return this.where.or.push(r),e}addOr(){if(!this.where.and)return this;let r={or:[]},e=new i(r,this);return this.where.and.push(r),e}addField(r,e,s){let t={field:r,operator:e,value:s};if(this.where.and)this.where.and.push(t);else if(this.where.or)this.where.or.push(t);else throw new Error("Invalid where");return this}build(){return this.parent?this.parent.build():this.where}};function h(i){return i!=null}u(h,"isValid");function l(i,r,e=[]){if(typeof r!="object")return;let s=Object.keys(r);if(s.length===0)return;let{$or:t,$and:n,...o}=r;if(n){let d=n.length>1||s.length>1?i.addAnd():i;n.forEach(a=>l(d,a,e)),p(d,o,e);return}if(t&&s.length===1){let d=t.length>1?i.addOr():i;t.forEach(a=>l(d,a,e));return}if(t){let d=i.addAnd(),a=t.length>1?d.addOr():d;p(d,o,e),t.forEach(f=>l(a,f,e));return}s.length>1&&(i=i.addAnd()),p(i,o,e)}u(l,"parseCrudSearch");function p(i,r,e){for(let s of Object.keys(r)){let t=r[s];if(!h(t))continue;let n=[...e,...s.split(".")];if(Array.isArray(t)){t.forEach(o=>l(i,o,n));continue}R(i,n,t)}}u(p,"parseCrudSearchFields");function R(i,r,e){if(typeof e!="object"){i.addField(r,"eq",e);return}let s={$eq:"eq",$ne:"neq",$gt:"gt",$lt:"lt",$gte:"gte",$lte:"lte",$starts:"starts",$ends:"ends",$cont:"contains",$excl:"not_contains",$in:"in",$notin:"not_in",$between:"between",$isnull:"is_null",$notnull:"not_null",$eqL:"eq_lower",$neL:"neq_lower",$startsL:"starts_lower",$endsL:"ends_lower",$contL:"contains_lower",$exclL:"not_contains_lower",$inL:"in_lower",$notinL:"not_in_lower"},t=Object.keys(e);for(let n of t){if(!s[n])continue;let o=e[n];Array.isArray(o)?o.forEach(d=>i.addField(r,s[n],d)):i.addField(r,s[n],o)}e.$or&&R(i.addOr(),r,e.$or)}u(R,"parseCrudSearchField");var m=class{static{u(this,"CrudRequestParser")}parse(r){let e=[],s=[],t=[],n=new c;this.parseSelect(e,r.fields||r.select),this.parseJoin(e,s,r.join),this.parseOrder(t,r.sort),this.parseSearch(n,r.s);let{limit:o,offset:d}=this.parseLimits(r.limit,r.offset,r.page);return{select:e,relations:s,order:t,where:n.build(),limit:o,offset:d}}parseSelect(r,e){if(!e)return;(Array.isArray(e)?e:e.split(",")).forEach(t=>{r.push({field:t.split(".")})})}parseJoin(r,e,s){if(!s)return;if(Array.isArray(s)){s.forEach(a=>this.parseJoin(r,e,a));return}let t=s.toString(),[n,o]=t.split("||",2),d=n.split(".");e.push({field:d}),o&&o.split(",").forEach(f=>{r.push({field:[...d,f]})})}parseOrder(r,e){if(!e)return;if(Array.isArray(e)){e.forEach(n=>this.parseOrder(r,n));return}let[s,t]=e.split(",");r.push({field:s.split("."),order:t?.toUpperCase()==="DESC"?"DESC":"ASC"})}parseNumber(r){if(Array.isArray(r)&&(r=r.length>0?r[0]:void 0),!h(r))return;let e=+r;return isNaN(e)?void 0:e}parseLimits(r,e,s){let t=this.parseNumber(r),n=this.parseNumber(e);if(t&&!n){let o=this.parseNumber(s);o&&(n=t*o)}return{limit:t,offset:n}}parseSearch(r,e){if(Array.isArray(e)&&(e=e.length>0?e[0]:void 0),!e)return;let s=JSON.parse(e);l(r,s)}};export{m as CrudRequestParser};
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/parsed-request-where.builder.ts","../../../src/utils/functions.ts","../../../src/parsers/crud/parseCrudSearch.ts","../../../src/parsers/crud/crud-request.parser.ts"],"sourcesContent":["import {\r\n CrudRequestWhere,\r\n CrudRequestWhereAND,\r\n CrudRequestWhereField,\r\n CrudRequestWhereOperator,\r\n CrudRequestWhereOR,\r\n CrudRequestWhereValueType\r\n} from '../models/crud-request-where';\r\n\r\n/**\r\n * A helper class that makes it easier to create a CrudRequestWhere\r\n */\r\nexport class ParsedRequestWhereBuilder {\r\n\r\n constructor(\r\n private readonly where: CrudRequestWhereAND | CrudRequestWhereOR = { and: [] },\r\n private readonly parent?: ParsedRequestWhereBuilder,\r\n ) { }\r\n\r\n /**\r\n * Adds an AND bracket\r\n */\r\n public addAnd(): ParsedRequestWhereBuilder {\r\n if (!this.where.or) {\r\n return this;\r\n }\r\n\r\n const inside: CrudRequestWhereAND = { and: [] };\r\n const builder = new ParsedRequestWhereBuilder(inside, this);\r\n\r\n this.where.or.push(inside);\r\n\r\n return builder;\r\n }\r\n\r\n /**\r\n * Adds an OR bracket\r\n */\r\n public addOr(): ParsedRequestWhereBuilder {\r\n if (!this.where.and) {\r\n return this;\r\n }\r\n\r\n const inside: CrudRequestWhereOR = { or: [] };\r\n const builder = new ParsedRequestWhereBuilder(inside, this);\r\n\r\n this.where.and.push(inside);\r\n\r\n return builder;\r\n }\r\n\r\n /**\r\n * Adds a field comparison\r\n *\r\n * @param field The field path\r\n * @param operator The comparison operator\r\n * @param value The value to compare\r\n */\r\n public addField(field: string[], operator: CrudRequestWhereOperator, value: CrudRequestWhereValueType): ParsedRequestWhereBuilder {\r\n const whereField: CrudRequestWhereField = {\r\n field,\r\n operator,\r\n value,\r\n };\r\n\r\n if (this.where.and) {\r\n this.where.and.push(whereField);\r\n } else if (this.where.or) {\r\n this.where.or.push(whereField);\r\n } else {\r\n throw new Error('Invalid where');\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Constructs the final where condition\r\n */\r\n public build(): CrudRequestWhere {\r\n if (this.parent) {\r\n return this.parent.build();\r\n }\r\n\r\n return this.where;\r\n }\r\n\r\n}\r\n","import { CrudRequestFields } from '../models/crud-request';\r\n\r\n/*export function setFieldByPath<T>(obj: ParsedRequestFields<T>, field: string, value: T): void {\r\n const parts = field.split('.');\r\n\r\n while (parts.length > 1) {\r\n const name = parts.shift();\r\n\r\n if (!Array.isArray(obj[name]))\r\n obj[name] = {};\r\n\r\n obj = obj[name] as ParsedRequestFields<T>;\r\n }\r\n\r\n obj[parts.shift()] = value;\r\n}*/\r\n\r\nexport function ensureArray<T>(fieldName: string, data: T[] | any, minLength: number = 0): T[] {\r\n if (!Array.isArray(data) || data.length < minLength)\r\n throw new Error(`${fieldName} must be an array with at least ${minLength} items`);\r\n\r\n return data;\r\n}\r\n\r\nexport function ensureFalsy(fieldName: string, data: any) {\r\n if (data)\r\n throw new Error(`${fieldName} must be null`);\r\n}\r\n\r\nexport function isValid(value: any): value is object {\r\n return value !== null && value !== undefined;\r\n}\r\n","import { ParsedRequestWhereBuilder } from '../../utils/parsed-request-where.builder';\r\nimport { CrudRequestWhereOperator } from '../../models/crud-request-where';\r\nimport { SCondition, SField, SFieldOperator, SFields } from './types';\r\nimport { isValid } from '../../utils/functions';\r\n\r\n/**\r\n * Parses a crud request condition and inserts into a ParsedRequestWhereBuilder\r\n *\r\n * @param builder The builder that the condition will be inserted to\r\n * @param cond The condition that must be parsed\r\n * @param context The field context\r\n */\r\nexport function parseCrudSearch(builder: ParsedRequestWhereBuilder, cond: SCondition, context: string[] = []) {\r\n if (typeof cond !== 'object')\r\n return;\r\n\r\n const keys = Object.keys(cond);\r\n\r\n if (keys.length === 0)\r\n return;\r\n\r\n const { $or, $and, ...innerFields } = cond;\r\n\r\n // { $and: [..., ...] }\r\n if ($and) {\r\n const andBuilder = $and.length > 1 || keys.length > 1 ? builder.addAnd() : builder;\r\n\r\n $and.forEach(c => parseCrudSearch(andBuilder, c, context));\r\n\r\n parseCrudSearchFields(andBuilder, innerFields as Omit<Omit<SFields, '$or'>, '$and'>, context);\r\n\r\n return;\r\n }\r\n\r\n // { $or: [..., ...] }\r\n if ($or && keys.length === 1) {\r\n const orBuilder = $or.length > 1 ? builder.addOr() : builder;\r\n\r\n $or.forEach(c => parseCrudSearch(orBuilder, c, context));\r\n\r\n return;\r\n }\r\n\r\n // { $or: [...], field1: ..., field2: ... }\r\n if ($or) {\r\n const andBuilder = builder.addAnd();\r\n const orBuilder = $or.length > 1 ? andBuilder.addOr() : andBuilder;\r\n\r\n parseCrudSearchFields(andBuilder, innerFields as Omit<Omit<SFields, '$or'>, '$and'>, context);\r\n\r\n $or.forEach(c => parseCrudSearch(orBuilder, c, context));\r\n\r\n return;\r\n }\r\n\r\n if (keys.length > 1)\r\n builder = builder.addAnd();\r\n\r\n parseCrudSearchFields(builder, innerFields as Omit<Omit<SFields, '$or'>, '$and'>, context);\r\n}\r\n\r\n/**\r\n * Parses an object from the crud request full of fields\r\n *\r\n * @param builder The builder\r\n * @param fields The fields object\r\n * @param context The context\r\n */\r\nfunction parseCrudSearchFields(builder: ParsedRequestWhereBuilder, fields: Omit<Omit<SFields, '$or'>, '$and'>, context: string[]): void {\r\n // { name: 'John', age: { $gte: 18 }, 'posts.name': { $cont: 'Greetings' } }\r\n for (const name of Object.keys(fields)) {\r\n const field = fields[name];\r\n\r\n if (!isValid(field))\r\n continue;\r\n\r\n const fieldPath = [...context, ...name.split('.')];\r\n\r\n // { name: [{ $or: [...] }] }\r\n if (Array.isArray(field)) {\r\n field.forEach(f => parseCrudSearch(builder, f, fieldPath));\r\n continue;\r\n }\r\n\r\n parseCrudSearchField(builder, fieldPath, field);\r\n }\r\n}\r\n\r\n/**\r\n * Parses a single field\r\n *\r\n * @param builder The builder\r\n * @param name The name path\r\n * @param field The field value or operator\r\n */\r\nfunction parseCrudSearchField(builder: ParsedRequestWhereBuilder, name: string[], field: SField): void {\r\n // Primitive Value\r\n // { field: 'text', field2: 12, field3: true }\r\n if (typeof field !== 'object') {\r\n builder.addField(name, CrudRequestWhereOperator.EQ, field);\r\n return;\r\n }\r\n\r\n type OperatorType = Exclude<Exclude<keyof SFieldOperator, '$or'>, '$and'>;\r\n\r\n // Operator\r\n // { field: { $gte: 10 } }\r\n const operatorMap: Record<OperatorType, CrudRequestWhereOperator> = {\r\n $eq: CrudRequestWhereOperator.EQ,\r\n $ne: CrudRequestWhereOperator.NEQ,\r\n $gt: CrudRequestWhereOperator.GT,\r\n $lt: CrudRequestWhereOperator.LT,\r\n $gte: CrudRequestWhereOperator.GTE,\r\n $lte: CrudRequestWhereOperator.LTE,\r\n $starts: CrudRequestWhereOperator.STARTS,\r\n $ends: CrudRequestWhereOperator.ENDS,\r\n $cont: CrudRequestWhereOperator.CONTAINS,\r\n $excl: CrudRequestWhereOperator.NOT_CONTAINS,\r\n $in: CrudRequestWhereOperator.IN,\r\n $notin: CrudRequestWhereOperator.NOT_IN,\r\n $between: CrudRequestWhereOperator.BETWEEN,\r\n $isnull: CrudRequestWhereOperator.IS_NULL,\r\n $notnull: CrudRequestWhereOperator.NOT_NULL,\r\n $eqL: CrudRequestWhereOperator.EQ_LOWER,\r\n $neL: CrudRequestWhereOperator.NEQ_LOWER,\r\n $startsL: CrudRequestWhereOperator.STARTS_LOWER,\r\n $endsL: CrudRequestWhereOperator.ENDS_LOWER,\r\n $contL: CrudRequestWhereOperator.CONTAINS_LOWER,\r\n $exclL: CrudRequestWhereOperator.NOT_CONTAINS_LOWER,\r\n $inL: CrudRequestWhereOperator.IN_LOWER,\r\n $notinL: CrudRequestWhereOperator.NOT_IN_LOWER,\r\n };\r\n\r\n const keys = Object.keys(field) as OperatorType[];\r\n\r\n for (let key of keys) {\r\n if (!operatorMap[key])\r\n continue;\r\n\r\n const value = field[key];\r\n\r\n if (Array.isArray(value))\r\n value.forEach(val => builder.addField(name, operatorMap[key], val));\r\n else\r\n builder.addField(name, operatorMap[key], value);\r\n }\r\n\r\n if (field.$or) {\r\n parseCrudSearchField(builder.addOr(), name, field.$or);\r\n }\r\n}\r\n","import { RequestParamValue, RequestParser } from '../../models/request-parser';\r\nimport {\r\n CrudRequest,\r\n CrudRequestOrder,\r\n CrudRequestRelation,\r\n ParsedRequestSelect\r\n} from '../../models/crud-request';\r\nimport { ParsedRequestWhereBuilder } from '../../utils/parsed-request-where.builder';\r\nimport { parseCrudSearch } from './parseCrudSearch';\r\nimport { isValid } from '../../utils/functions';\r\nimport { SCondition } from './types';\r\n\r\n/**\r\n * Parses a request based on the @nestjsx/crud format.\r\n */\r\nexport class CrudRequestParser implements RequestParser {\r\n\r\n public parse(query: Record<string, RequestParamValue>): CrudRequest {\r\n const select: ParsedRequestSelect = [];\r\n const relations: CrudRequestRelation[] = [];\r\n const ordering: CrudRequestOrder[] = [];\r\n const where = new ParsedRequestWhereBuilder();\r\n\r\n this.parseSelect(select, query['fields'] || query['select']);\r\n this.parseJoin(select, relations, query['join']);\r\n this.parseOrder(ordering, query['sort']);\r\n this.parseSearch(where, query['s']);\r\n\r\n const { limit, offset } = this.parseLimits(query['limit'], query['offset'], query['page']);\r\n\r\n return {\r\n select,\r\n relations,\r\n order: ordering,\r\n where: where.build(),\r\n limit,\r\n offset,\r\n };\r\n }\r\n\r\n protected parseSelect(select: ParsedRequestSelect, rawSelect: RequestParamValue): void {\r\n if (!rawSelect)\r\n return;\r\n\r\n const selectFields = Array.isArray(rawSelect) ? rawSelect : rawSelect.split(',');\r\n\r\n selectFields.forEach(field => {\r\n select.push({\r\n field: field.split('.'),\r\n });\r\n });\r\n }\r\n\r\n protected parseJoin(requestFields: ParsedRequestSelect, relations: CrudRequestRelation[], rawJoin: RequestParamValue): void {\r\n if (!rawJoin)\r\n return;\r\n\r\n if (Array.isArray(rawJoin)) {\r\n rawJoin.forEach(value => this.parseJoin(requestFields, relations, value));\r\n return;\r\n }\r\n\r\n const join = rawJoin.toString();\r\n\r\n const [field, select] = join.split('||', 2);\r\n const fieldPath = field.split('.');\r\n\r\n relations.push({\r\n field: fieldPath,\r\n });\r\n\r\n if (select) {\r\n const selectFields = select.split(',');\r\n\r\n selectFields.forEach(f => {\r\n requestFields.push({\r\n field: [...fieldPath, f],\r\n });\r\n });\r\n }\r\n }\r\n\r\n protected parseOrder(ordering: CrudRequestOrder[], rawOrder: RequestParamValue): void {\r\n if (!rawOrder)\r\n return;\r\n\r\n if (Array.isArray(rawOrder)) {\r\n rawOrder.forEach(value => this.parseOrder(ordering, value));\r\n return;\r\n }\r\n\r\n const [field, direction] = rawOrder.split(',');\r\n\r\n ordering.push({\r\n field: field.split('.'),\r\n order: direction?.toUpperCase() === 'DESC' ? 'DESC' : 'ASC',\r\n });\r\n }\r\n\r\n protected parseNumber(raw: RequestParamValue): number | undefined {\r\n if (Array.isArray(raw))\r\n raw = raw.length > 0 ? raw[0] : undefined;\r\n\r\n if (!isValid(raw))\r\n return undefined;\r\n\r\n const num = +raw;\r\n\r\n return isNaN(num) ? undefined : num;\r\n }\r\n\r\n protected parseLimits(rawLimit: RequestParamValue, rawOffset: RequestParamValue, rawPage: RequestParamValue) {\r\n const limit = this.parseNumber(rawLimit);\r\n let offset = this.parseNumber(rawOffset);\r\n\r\n if (limit && !offset) {\r\n const page = this.parseNumber(rawPage);\r\n\r\n if (page)\r\n offset = limit * page;\r\n }\r\n\r\n return { limit, offset };\r\n }\r\n\r\n protected parseSearch(builder: ParsedRequestWhereBuilder, rawSearch: RequestParamValue): void {\r\n if (Array.isArray(rawSearch))\r\n rawSearch = rawSearch.length > 0 ? rawSearch[0] : undefined;\r\n\r\n if (!rawSearch)\r\n return;\r\n\r\n const search: SCondition = JSON.parse(rawSearch);\r\n\r\n parseCrudSearch(builder, search);\r\n }\r\n\r\n}\r\n"],"mappings":"+EAYO,IAAMA,EAAN,MAAMC,CAA0B,CAErC,YACmBC,EAAkD,CAAE,IAAK,CAAC,CAAE,EAC5DC,EACjB,CAFiB,WAAAD,EACA,YAAAC,CACf,CAjBN,MAYuC,CAAAC,EAAA,kCAU9B,QAAoC,CACzC,GAAI,CAAC,KAAK,MAAM,GACd,OAAO,KAGT,IAAMC,EAA8B,CAAE,IAAK,CAAC,CAAE,EACxCC,EAAU,IAAIL,EAA0BI,EAAQ,IAAI,EAE1D,YAAK,MAAM,GA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AAgBH,EAASE,CAAM,CACjC,CAEF","names":["ParsedRequestWhereBuilder","_ParsedRequestWhereBuilder","where","parent","__name","inside","builder","field","operator","value","whereField","isValid","value","__name","parseCrudSearch","builder","cond","context","keys","$or","$and","innerFields","andBuilder","c","parseCrudSearchFields","orBuilder","__name","fields","name","field","isValid","fieldPath","f","parseCrudSearchField","operatorMap","key","value","val","CrudRequestParser","__name","query","select","relations","ordering","where","ParsedRequestWhereBuilder","limit","offset","rawSelect","field","requestFields","rawJoin","value","join","fieldPath","rawOrder","direction","raw","isValid","num","rawLimit","rawOffset","rawPage","page","builder","rawSearch","search","parseCrudSearch"]}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { c as CrudRequest } from './crud-request-CvDKp6Iy.mjs';
|
2
|
+
|
3
|
+
interface GetManyResult<T> {
|
4
|
+
/**
|
5
|
+
* The entity list
|
6
|
+
*/
|
7
|
+
data: T[];
|
8
|
+
/**
|
9
|
+
* The amount of entities returned
|
10
|
+
*/
|
11
|
+
count: number;
|
12
|
+
/**
|
13
|
+
* The total amount of entities in the database
|
14
|
+
*/
|
15
|
+
total: number;
|
16
|
+
/**
|
17
|
+
* The current page number
|
18
|
+
*/
|
19
|
+
page: number;
|
20
|
+
/**
|
21
|
+
* The total page amount
|
22
|
+
*/
|
23
|
+
pageCount: number;
|
24
|
+
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Represents a class that can build queries based on parsed requests
|
28
|
+
*
|
29
|
+
* @param T The database adapter query builder object
|
30
|
+
*/
|
31
|
+
interface QueryAdapter<T, BaseEntity = any> {
|
32
|
+
/**
|
33
|
+
* Converts a parsed request object into a database query format
|
34
|
+
*
|
35
|
+
* @param baseQuery The base query to start of
|
36
|
+
* @param request The parsed request object
|
37
|
+
*/
|
38
|
+
build<E extends BaseEntity>(baseQuery: T, request: CrudRequest): T;
|
39
|
+
/**
|
40
|
+
* Fetches one entity based on a parsed request object
|
41
|
+
*
|
42
|
+
* @param baseQuery The base query to start of
|
43
|
+
* @param request The parsed request object
|
44
|
+
*/
|
45
|
+
getOne<E extends BaseEntity>(baseQuery: T, request: CrudRequest): Promise<E | null>;
|
46
|
+
/**
|
47
|
+
* Fetches a paginated list of entities based on a parsed request object
|
48
|
+
*
|
49
|
+
* @param baseQuery The base query to start of
|
50
|
+
* @param request The parsed request object
|
51
|
+
*/
|
52
|
+
getMany<E extends BaseEntity>(baseQuery: T, request: CrudRequest): Promise<GetManyResult<E>>;
|
53
|
+
}
|
54
|
+
|
55
|
+
export type { GetManyResult as G, QueryAdapter as Q };
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { c as CrudRequest } from './crud-request-CvDKp6Iy.js';
|
2
|
+
|
3
|
+
interface GetManyResult<T> {
|
4
|
+
/**
|
5
|
+
* The entity list
|
6
|
+
*/
|
7
|
+
data: T[];
|
8
|
+
/**
|
9
|
+
* The amount of entities returned
|
10
|
+
*/
|
11
|
+
count: number;
|
12
|
+
/**
|
13
|
+
* The total amount of entities in the database
|
14
|
+
*/
|
15
|
+
total: number;
|
16
|
+
/**
|
17
|
+
* The current page number
|
18
|
+
*/
|
19
|
+
page: number;
|
20
|
+
/**
|
21
|
+
* The total page amount
|
22
|
+
*/
|
23
|
+
pageCount: number;
|
24
|
+
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Represents a class that can build queries based on parsed requests
|
28
|
+
*
|
29
|
+
* @param T The database adapter query builder object
|
30
|
+
*/
|
31
|
+
interface QueryAdapter<T, BaseEntity = any> {
|
32
|
+
/**
|
33
|
+
* Converts a parsed request object into a database query format
|
34
|
+
*
|
35
|
+
* @param baseQuery The base query to start of
|
36
|
+
* @param request The parsed request object
|
37
|
+
*/
|
38
|
+
build<E extends BaseEntity>(baseQuery: T, request: CrudRequest): T;
|
39
|
+
/**
|
40
|
+
* Fetches one entity based on a parsed request object
|
41
|
+
*
|
42
|
+
* @param baseQuery The base query to start of
|
43
|
+
* @param request The parsed request object
|
44
|
+
*/
|
45
|
+
getOne<E extends BaseEntity>(baseQuery: T, request: CrudRequest): Promise<E | null>;
|
46
|
+
/**
|
47
|
+
* Fetches a paginated list of entities based on a parsed request object
|
48
|
+
*
|
49
|
+
* @param baseQuery The base query to start of
|
50
|
+
* @param request The parsed request object
|
51
|
+
*/
|
52
|
+
getMany<E extends BaseEntity>(baseQuery: T, request: CrudRequest): Promise<GetManyResult<E>>;
|
53
|
+
}
|
54
|
+
|
55
|
+
export type { GetManyResult as G, QueryAdapter as Q };
|
package/package.json
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
{
|
2
|
+
"name": "crud-query-parser",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "Parses HTTP requests and converts them into database queries",
|
5
|
+
"license": "MIT",
|
6
|
+
"author": "Guilherme Chaguri",
|
7
|
+
"scripts": {
|
8
|
+
"build": "tsup",
|
9
|
+
"prepublishOnly": "npm run build"
|
10
|
+
},
|
11
|
+
"tsup": {
|
12
|
+
"entry": [
|
13
|
+
"src/index.ts",
|
14
|
+
"src/adapters/typeorm/index.ts",
|
15
|
+
"src/parsers/crud/index.ts",
|
16
|
+
"src/filters/index.ts"
|
17
|
+
],
|
18
|
+
"target": "es2022",
|
19
|
+
"format": [
|
20
|
+
"esm",
|
21
|
+
"cjs"
|
22
|
+
],
|
23
|
+
"outDir": "./dist",
|
24
|
+
"dts": true,
|
25
|
+
"cjsInterop": true,
|
26
|
+
"minify": true,
|
27
|
+
"splitting": false,
|
28
|
+
"sourcemap": true,
|
29
|
+
"clean": true,
|
30
|
+
"skipNodeModulesBundle": true,
|
31
|
+
"keepNames": true,
|
32
|
+
"bundle": true
|
33
|
+
},
|
34
|
+
"files": [
|
35
|
+
"dist"
|
36
|
+
],
|
37
|
+
"main": "./dist/index.js",
|
38
|
+
"types": "./dist/index.d.ts",
|
39
|
+
"exports": {
|
40
|
+
".": {
|
41
|
+
"import": {
|
42
|
+
"default": "./dist/index.mjs",
|
43
|
+
"types": "./dist/index.d.mts"
|
44
|
+
},
|
45
|
+
"require": {
|
46
|
+
"default": "./dist/index.js",
|
47
|
+
"types": "./dist/index.d.ts"
|
48
|
+
}
|
49
|
+
},
|
50
|
+
"./adapters/typeorm": {
|
51
|
+
"import": {
|
52
|
+
"default": "./dist/adapters/typeorm/index.mjs",
|
53
|
+
"types": "./dist/adapters/typeorm/index.d.mts"
|
54
|
+
},
|
55
|
+
"require": {
|
56
|
+
"default": "./dist/adapters/typeorm/index.js",
|
57
|
+
"types": "./dist/adapters/typeorm/index.d.ts"
|
58
|
+
}
|
59
|
+
},
|
60
|
+
"./parsers/crud": {
|
61
|
+
"import": {
|
62
|
+
"default": "./dist/parsers/crud/index.mjs",
|
63
|
+
"types": "./dist/parsers/crud/index.d.mts"
|
64
|
+
},
|
65
|
+
"require": {
|
66
|
+
"default": "./dist/parsers/crud/index.js",
|
67
|
+
"types": "./dist/parsers/crud/index.d.ts"
|
68
|
+
}
|
69
|
+
},
|
70
|
+
"./filters": {
|
71
|
+
"import": {
|
72
|
+
"default": "./dist/filters/index.mjs",
|
73
|
+
"types": "./dist/filters/index.d.mts"
|
74
|
+
},
|
75
|
+
"require": {
|
76
|
+
"default": "./dist/filters/index.js",
|
77
|
+
"types": "./dist/filters/index.d.ts"
|
78
|
+
}
|
79
|
+
}
|
80
|
+
},
|
81
|
+
"peerDependencies": {
|
82
|
+
"@nestjs/core": ">=10.0.0",
|
83
|
+
"@nestjs/swagger": ">=7.0.0",
|
84
|
+
"typeorm": "0.2.x || 0.3.x"
|
85
|
+
},
|
86
|
+
"peerDependenciesMeta": {
|
87
|
+
"@nestjs/core": {
|
88
|
+
"optional": true
|
89
|
+
},
|
90
|
+
"@nestjs/swagger": {
|
91
|
+
"optional": true
|
92
|
+
},
|
93
|
+
"typeorm": {
|
94
|
+
"optional": true
|
95
|
+
}
|
96
|
+
},
|
97
|
+
"devDependencies": {
|
98
|
+
"@nestjs/common": "^10.3.9",
|
99
|
+
"@nestjs/swagger": "^7.3.1",
|
100
|
+
"@types/node": "^17.0.23",
|
101
|
+
"reflect-metadata": "^0.2.2",
|
102
|
+
"sqlite3": "^5.1.7",
|
103
|
+
"tsup": "^8.1.0",
|
104
|
+
"typeorm": "^0.3.20",
|
105
|
+
"typescript": "^5.5.2"
|
106
|
+
}
|
107
|
+
}
|