@litepos/autoquery 5.0.1

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-PRESENT Anthony Fu <https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # pkg-placeholder
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![bundle][bundle-src]][bundle-href]
6
+ [![JSDocs][jsdocs-src]][jsdocs-href]
7
+ [![License][license-src]][license-href]
8
+
9
+ _description_
10
+
11
+ ## Note for Developers
12
+
13
+ This starter recommands using [npm Trusted Publisher](https://github.com/e18e/ecosystem-issues/issues/201), where the release is done on CI to ensure the security of the packages.
14
+
15
+ To do so, you need to run `pnpm publish` manually for the very first time to create the package on npm, and then go to `https://www.npmjs.com/package/<your-package-name>/access` to set the connection to your GitHub repo.
16
+
17
+ Then for the future releases, you can run `pnpm run release` to do the release and the GitHub Actions will take care of the release process.
18
+
19
+ ## Sponsors
20
+
21
+ <p align="center">
22
+ <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
23
+ <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
24
+ </a>
25
+ </p>
26
+
27
+ ## License
28
+
29
+ [MIT](./LICENSE) License © [Anthony Fu](https://github.com/antfu)
30
+
31
+ <!-- Badges -->
32
+
33
+ [npm-version-src]: https://img.shields.io/npm/v/pkg-placeholder?style=flat&colorA=080f12&colorB=1fa669
34
+ [npm-version-href]: https://npmjs.com/package/pkg-placeholder
35
+ [npm-downloads-src]: https://img.shields.io/npm/dm/pkg-placeholder?style=flat&colorA=080f12&colorB=1fa669
36
+ [npm-downloads-href]: https://npmjs.com/package/pkg-placeholder
37
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/pkg-placeholder?style=flat&colorA=080f12&colorB=1fa669&label=minzip
38
+ [bundle-href]: https://bundlephobia.com/result?p=pkg-placeholder
39
+ [license-src]: https://img.shields.io/github/license/antfu/pkg-placeholder.svg?style=flat&colorA=080f12&colorB=1fa669
40
+ [license-href]: https://github.com/antfu/pkg-placeholder/blob/main/LICENSE
41
+ [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
42
+ [jsdocs-href]: https://www.jsdocs.io/package/pkg-placeholder
@@ -0,0 +1,164 @@
1
+ //#region src/index.d.ts
2
+ /**
3
+ * The IBaseParams interface provides a structure for query parameters commonly used
4
+ * in API requests to manipulate the presentation and organization of returned data.
5
+ *
6
+ * @property {string} [skip] - The number of records to skip before starting to collect the response set.
7
+ * @property {string} [take] - The limit on the number of records to return in the response set.
8
+ * @property {string} [format] - The desired format of the response (e.g., 'json', 'xml').
9
+ * @property {string} [include] - A way to include data from related tables/entities.
10
+ * @property {string} [jsconfig] - JavaScript configuration for client-side handling of the response.
11
+ * @property {string} [orderBy] - A parameter to specify the field to order the results by in ascending order.
12
+ * @property {string} [orderByDesc] - A parameter to specify the field to order the results by in descending order.
13
+ */
14
+ interface IBaseParams {
15
+ skip?: number;
16
+ take?: number;
17
+ format?: string;
18
+ include?: string;
19
+ jsconfig?: string;
20
+ orderBy?: string;
21
+ orderByDesc?: string;
22
+ }
23
+ interface IInvoiceParams extends IBaseParams {
24
+ RefIdContains?: string;
25
+ GrandTotal?: number;
26
+ StatusContains?: string;
27
+ PaidAtAfter?: string;
28
+ PaidAtBefore?: string;
29
+ PaidAtStartsWith?: string;
30
+ }
31
+ interface IInvoicesQuery {
32
+ params: IInvoiceParams;
33
+ }
34
+ declare class InvoicesQuery implements IInvoicesQuery {
35
+ params: {
36
+ format: string;
37
+ Include: string;
38
+ jsconfig: string;
39
+ };
40
+ constructor(params: IInvoiceParams);
41
+ }
42
+ interface IQueryResponse<T> {
43
+ offset?: number;
44
+ total?: number;
45
+ results?: T[];
46
+ meta?: {
47
+ [index: string]: string;
48
+ };
49
+ responseStatus?: ResponseStatus;
50
+ }
51
+ interface ResponseStatus {
52
+ errorCode?: string;
53
+ message?: string;
54
+ stackTrace?: string;
55
+ errors?: ValidationError[];
56
+ }
57
+ interface ValidationError {
58
+ errorCode?: string;
59
+ fieldName?: string;
60
+ message?: string;
61
+ }
62
+ declare class QueryResponse<T> {
63
+ offset?: number;
64
+ total?: number;
65
+ results?: T[];
66
+ meta?: {
67
+ [index: string]: string;
68
+ };
69
+ responseStatus?: ResponseStatus;
70
+ }
71
+ declare enum SortOrder {
72
+ Asc = "asc",
73
+ Desc = "desc",
74
+ }
75
+ type EnumToString<T> = T extends string ? string : T;
76
+ type QueryableType<T> = { [K in keyof T]: T[K] extends Date ? Date : T[K] extends number ? number : EnumToString<T[K]> };
77
+ type Operator<T> = T extends number ? keyof typeof NumericOperators | keyof typeof NullOperators : T extends Date ? keyof typeof DateOperators | keyof typeof NullOperators : T extends string ? keyof typeof StringOperators | keyof typeof ArrayOperators | keyof typeof NullOperators : string extends T ? keyof typeof StringOperators | keyof typeof ArrayOperators | keyof typeof NullOperators : keyof typeof NullOperators;
78
+ type OperatorValueMap<T = any> = { [K in Operator<T>]: T extends Date ? (K extends keyof typeof DateOperators ? DateOperatorValueMap[K] : K extends keyof typeof NullOperators ? boolean : never) : T extends number ? (K extends keyof typeof NumericOperators ? number : K extends keyof typeof NullOperators ? boolean : never) : T extends string ? (K extends keyof typeof StringOperators ? string : K extends keyof typeof ArrayOperators ? string[] : K extends keyof typeof NullOperators ? boolean : never) : string extends T ? (K extends keyof typeof StringOperators ? string : K extends keyof typeof ArrayOperators ? string[] : K extends keyof typeof NullOperators ? boolean : never) : K extends keyof typeof NullOperators ? boolean : never };
79
+ declare enum NumericOperators {
80
+ '>' = 0,
81
+ '>=' = 1,
82
+ '<' = 2,
83
+ '<=' = 3,
84
+ '=' = 4,
85
+ 'GreaterThan' = 5,
86
+ 'GreaterThanOrEqualTo' = 6,
87
+ 'LessThan' = 7,
88
+ 'LessThanOrEqualTo' = 8,
89
+ 'EqualTo' = 9,
90
+ 'NotEqualTo' = 10,
91
+ }
92
+ declare enum StringOperators {
93
+ 'Contains' = 0,
94
+ 'NotContains' = 1,
95
+ 'StartsWith' = 2,
96
+ 'EndsWith' = 3,
97
+ "Like" = 4,
98
+ }
99
+ declare enum ArrayOperators {
100
+ 'In' = 0,
101
+ 'NotIn' = 1,
102
+ }
103
+ declare enum NullOperators {
104
+ 'IsNull' = 0,
105
+ // Check if field IS NULL
106
+ 'IsNotNull' = 1,
107
+ }
108
+ declare enum MonthOperator {
109
+ WithinAMonth = "Contains",
110
+ }
111
+ declare enum DayOperator {
112
+ At = "StartsWith",
113
+ }
114
+ declare enum DateOperators {
115
+ 'GreaterThan' = 0,
116
+ 'GreaterThanOrEqualTo' = 1,
117
+ 'LessThan' = 2,
118
+ 'LessThanOrEqualTo' = 3,
119
+ 'Between' = 4,
120
+ // BETWEEN value1 AND value2
121
+ 'StartsWith' = 5,
122
+ // For exact date matching (e.g., "2019-01-01")
123
+ 'Contains' = 6,
124
+ }
125
+ type DateOperatorValueMap = {
126
+ 'GreaterThan': string;
127
+ 'GreaterThanOrEqualTo': string;
128
+ 'LessThan': string;
129
+ 'LessThanOrEqualTo': string;
130
+ 'Between': [string, string];
131
+ 'StartsWith': string;
132
+ 'Contains': MonthValues;
133
+ };
134
+ declare enum MonthValues {
135
+ Jan = "-01-",
136
+ Feb = "-02-",
137
+ Mar = "-03-",
138
+ Apr = "-04-",
139
+ May = "-05-",
140
+ Jun = "-06-",
141
+ Jul = "-07-",
142
+ Aug = "-08-",
143
+ Sep = "-09-",
144
+ Oct = "-10-",
145
+ Nov = "-11-",
146
+ Dec = "-12-",
147
+ }
148
+ declare class QueryBuilder<T> {
149
+ private params;
150
+ addParam<K extends keyof T, O extends Operator<QueryableType<T>[K]>>(property: K, operator: O, value: OperatorValueMap<QueryableType<T>[K]>[O]): this;
151
+ addRawParam(key: string, value: string): this;
152
+ includeTotal(flag: boolean): this;
153
+ skip(skip: number): this;
154
+ take(take: number): this;
155
+ sortBy<K extends keyof T>(property: K, orderBy: SortOrder): this;
156
+ jsconfig(param: string): this;
157
+ /** @internal */
158
+ _build(): Record<string, string>;
159
+ }
160
+ type QueryEtcParams = {
161
+ search_keywords?: string;
162
+ };
163
+ //#endregion
164
+ export { ArrayOperators, DateOperatorValueMap, DateOperators, DayOperator, EnumToString, IBaseParams, IInvoiceParams, IInvoicesQuery, IQueryResponse, InvoicesQuery, MonthOperator, MonthValues, NullOperators, NumericOperators, Operator, OperatorValueMap, QueryBuilder, QueryEtcParams, QueryResponse, QueryableType, ResponseStatus, SortOrder, StringOperators, ValidationError };
package/dist/index.js ADDED
@@ -0,0 +1,133 @@
1
+ //#region src/index.ts
2
+ var InvoicesQuery = class {
3
+ params = {
4
+ format: "json",
5
+ Include: "total",
6
+ jsconfig: "dh:iso8601dt"
7
+ };
8
+ constructor(params) {
9
+ this.params = {
10
+ ...this.params,
11
+ ...params
12
+ };
13
+ }
14
+ };
15
+ var QueryResponse = class {
16
+ offset;
17
+ total;
18
+ results;
19
+ meta;
20
+ responseStatus;
21
+ };
22
+ let SortOrder = /* @__PURE__ */ function(SortOrder$1) {
23
+ SortOrder$1["Asc"] = "asc";
24
+ SortOrder$1["Desc"] = "desc";
25
+ return SortOrder$1;
26
+ }({});
27
+ let NumericOperators = /* @__PURE__ */ function(NumericOperators$1) {
28
+ NumericOperators$1[NumericOperators$1[">"] = 0] = ">";
29
+ NumericOperators$1[NumericOperators$1[">="] = 1] = ">=";
30
+ NumericOperators$1[NumericOperators$1["<"] = 2] = "<";
31
+ NumericOperators$1[NumericOperators$1["<="] = 3] = "<=";
32
+ NumericOperators$1[NumericOperators$1["="] = 4] = "=";
33
+ NumericOperators$1[NumericOperators$1["GreaterThan"] = 5] = "GreaterThan";
34
+ NumericOperators$1[NumericOperators$1["GreaterThanOrEqualTo"] = 6] = "GreaterThanOrEqualTo";
35
+ NumericOperators$1[NumericOperators$1["LessThan"] = 7] = "LessThan";
36
+ NumericOperators$1[NumericOperators$1["LessThanOrEqualTo"] = 8] = "LessThanOrEqualTo";
37
+ NumericOperators$1[NumericOperators$1["EqualTo"] = 9] = "EqualTo";
38
+ NumericOperators$1[NumericOperators$1["NotEqualTo"] = 10] = "NotEqualTo";
39
+ return NumericOperators$1;
40
+ }({});
41
+ let StringOperators = /* @__PURE__ */ function(StringOperators$1) {
42
+ StringOperators$1[StringOperators$1["Contains"] = 0] = "Contains";
43
+ StringOperators$1[StringOperators$1["NotContains"] = 1] = "NotContains";
44
+ StringOperators$1[StringOperators$1["StartsWith"] = 2] = "StartsWith";
45
+ StringOperators$1[StringOperators$1["EndsWith"] = 3] = "EndsWith";
46
+ StringOperators$1[StringOperators$1["Like"] = 4] = "Like";
47
+ return StringOperators$1;
48
+ }({});
49
+ let ArrayOperators = /* @__PURE__ */ function(ArrayOperators$1) {
50
+ ArrayOperators$1[ArrayOperators$1["In"] = 0] = "In";
51
+ ArrayOperators$1[ArrayOperators$1["NotIn"] = 1] = "NotIn";
52
+ return ArrayOperators$1;
53
+ }({});
54
+ let NullOperators = /* @__PURE__ */ function(NullOperators$1) {
55
+ NullOperators$1[NullOperators$1["IsNull"] = 0] = "IsNull";
56
+ NullOperators$1[NullOperators$1["IsNotNull"] = 1] = "IsNotNull";
57
+ return NullOperators$1;
58
+ }({});
59
+ let MonthOperator = /* @__PURE__ */ function(MonthOperator$1) {
60
+ MonthOperator$1["WithinAMonth"] = "Contains";
61
+ return MonthOperator$1;
62
+ }({});
63
+ let DayOperator = /* @__PURE__ */ function(DayOperator$1) {
64
+ DayOperator$1["At"] = "StartsWith";
65
+ return DayOperator$1;
66
+ }({});
67
+ let DateOperators = /* @__PURE__ */ function(DateOperators$1) {
68
+ DateOperators$1[DateOperators$1["GreaterThan"] = 0] = "GreaterThan";
69
+ DateOperators$1[DateOperators$1["GreaterThanOrEqualTo"] = 1] = "GreaterThanOrEqualTo";
70
+ DateOperators$1[DateOperators$1["LessThan"] = 2] = "LessThan";
71
+ DateOperators$1[DateOperators$1["LessThanOrEqualTo"] = 3] = "LessThanOrEqualTo";
72
+ DateOperators$1[DateOperators$1["Between"] = 4] = "Between";
73
+ DateOperators$1[DateOperators$1["StartsWith"] = 5] = "StartsWith";
74
+ DateOperators$1[DateOperators$1["Contains"] = 6] = "Contains";
75
+ return DateOperators$1;
76
+ }({});
77
+ let MonthValues = /* @__PURE__ */ function(MonthValues$1) {
78
+ MonthValues$1["Jan"] = "-01-";
79
+ MonthValues$1["Feb"] = "-02-";
80
+ MonthValues$1["Mar"] = "-03-";
81
+ MonthValues$1["Apr"] = "-04-";
82
+ MonthValues$1["May"] = "-05-";
83
+ MonthValues$1["Jun"] = "-06-";
84
+ MonthValues$1["Jul"] = "-07-";
85
+ MonthValues$1["Aug"] = "-08-";
86
+ MonthValues$1["Sep"] = "-09-";
87
+ MonthValues$1["Oct"] = "-10-";
88
+ MonthValues$1["Nov"] = "-11-";
89
+ MonthValues$1["Dec"] = "-12-";
90
+ return MonthValues$1;
91
+ }({});
92
+ var QueryBuilder = class {
93
+ params = {};
94
+ addParam(property, operator, value) {
95
+ const key = `${property.toString()}${operator}`;
96
+ if (operator === "IsNull" || operator === "IsNotNull") this.params[key] = "";
97
+ else this.params[key] = `${value}`;
98
+ return this;
99
+ }
100
+ addRawParam(key, value) {
101
+ this.params[key] = value;
102
+ return this;
103
+ }
104
+ includeTotal(flag) {
105
+ if (flag) this.params["include"] = "total";
106
+ return this;
107
+ }
108
+ skip(skip) {
109
+ this.params["skip"] = `${skip}`;
110
+ return this;
111
+ }
112
+ take(take) {
113
+ this.params["take"] = `${take}`;
114
+ return this;
115
+ }
116
+ sortBy(property, orderBy) {
117
+ if (orderBy === SortOrder.Asc) this.params["OrderBy"] = `${property.toString()}`;
118
+ else this.params["OrderByDesc"] = `${property.toString()}`;
119
+ return this;
120
+ }
121
+ jsconfig(param) {
122
+ this.params["jsconfig"] = param;
123
+ return this;
124
+ }
125
+ /** @internal */
126
+ _build() {
127
+ this.params["jsconfig"] = "dh:iso8601dt";
128
+ return this.params;
129
+ }
130
+ };
131
+
132
+ //#endregion
133
+ export { ArrayOperators, DateOperators, DayOperator, InvoicesQuery, MonthOperator, MonthValues, NullOperators, NumericOperators, QueryBuilder, QueryResponse, SortOrder, StringOperators };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@litepos/autoquery",
3
+ "type": "module",
4
+ "version": "5.0.1",
5
+ "packageManager": "pnpm@10.17.1",
6
+ "description": "AutoQuery is a library for building queries for LitePOS.",
7
+ "author": "LitePOS <info@litepos.ai>",
8
+ "license": "MIT",
9
+ "keywords": ["litepos", "autoquery", "query", "database", "sql"],
10
+ "sideEffects": false,
11
+ "exports": {
12
+ ".": "./dist/index.js",
13
+ "./package.json": "./package.json"
14
+ },
15
+ "main": "./dist/index.js",
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsdown",
23
+ "dev": "tsdown --watch",
24
+ "lint": "eslint",
25
+ "prepublishOnly": "nr build",
26
+ "release": "bumpp",
27
+ "start": "tsx src/index.ts",
28
+ "test": "vitest",
29
+ "typecheck": "tsc --noEmit",
30
+ "prepare": "simple-git-hooks"
31
+ },
32
+ "devDependencies": {
33
+ "@antfu/eslint-config": "catalog:cli",
34
+ "@antfu/ni": "catalog:cli",
35
+ "@antfu/utils": "catalog:inlined",
36
+ "@types/node": "catalog:types",
37
+ "bumpp": "catalog:cli",
38
+ "eslint": "catalog:cli",
39
+ "lint-staged": "catalog:cli",
40
+ "simple-git-hooks": "catalog:cli",
41
+ "tinyexec": "catalog:testing",
42
+ "tsdown": "catalog:cli",
43
+ "tsx": "catalog:cli",
44
+ "typescript": "catalog:cli",
45
+ "vite": "catalog:cli",
46
+ "vitest": "catalog:testing",
47
+ "vitest-package-exports": "catalog:testing",
48
+ "yaml": "catalog:testing"
49
+ },
50
+ "simple-git-hooks": {
51
+ "pre-commit": "pnpm i --frozen-lockfile --ignore-scripts --offline && npx lint-staged"
52
+ },
53
+ "lint-staged": {
54
+ "*": "eslint --fix"
55
+ }
56
+ }