@litepos/autoquery 5.0.1 → 5.0.2

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.
Files changed (2) hide show
  1. package/README.md +189 -22
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # pkg-placeholder
1
+ # @litepos/autoquery
2
2
 
3
3
  [![npm version][npm-version-src]][npm-version-href]
4
4
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
@@ -6,37 +6,204 @@
6
6
  [![JSDocs][jsdocs-src]][jsdocs-href]
7
7
  [![License][license-src]][license-href]
8
8
 
9
- _description_
9
+ A TypeScript library for building type-safe queries for LitePOS API endpoints. AutoQuery provides a fluent interface for constructing complex database queries with support for various operators, filtering, sorting, and pagination.
10
10
 
11
- ## Note for Developers
11
+ ## Features
12
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.
13
+ - 🎯 **Type-safe query building** - Full TypeScript support with compile-time type checking
14
+ - 🔍 **Rich filtering operators** - Numeric, string, date, and array operators
15
+ - 📊 **Built-in pagination** - Skip/take functionality with total count support
16
+ - 🔄 **Flexible sorting** - Ascending and descending order by any field
17
+ - 📅 **Date operations** - Specialized date filtering with month/day operators
18
+ - 🏗️ **Fluent API** - Chainable methods for intuitive query construction
19
+ - 🎨 **LitePOS integration** - Designed specifically for LitePOS API endpoints
14
20
 
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.
21
+ ## Installation
16
22
 
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.
23
+ ```bash
24
+ npm install @litepos/autoquery
25
+ # or
26
+ pnpm add @litepos/autoquery
27
+ # or
28
+ yarn add @litepos/autoquery
29
+ ```
18
30
 
19
- ## Sponsors
31
+ ## Quick Start
20
32
 
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>
33
+ ```typescript
34
+ import { NumericOperators, QueryBuilder, SortOrder, StringOperators } from '@litepos/autoquery'
35
+
36
+ // Define your data model
37
+ interface Invoice {
38
+ id: number
39
+ refId: string
40
+ grandTotal: number
41
+ status: string
42
+ paidAt: Date
43
+ }
44
+
45
+ // Build a query
46
+ const query = new QueryBuilder<Invoice>()
47
+ .addParam('grandTotal', NumericOperators.GreaterThan, 100)
48
+ .addParam('status', StringOperators.Contains, 'paid')
49
+ .sortBy('paidAt', SortOrder.Desc)
50
+ .skip(0)
51
+ .take(10)
52
+ .includeTotal(true)
53
+
54
+ // Get the query parameters
55
+ const params = query._build()
56
+ ```
57
+
58
+ ## Core Concepts
59
+
60
+ ### QueryBuilder
61
+
62
+ The main class for building queries. It provides a fluent interface for adding filters, sorting, and pagination.
63
+
64
+ ```typescript
65
+ const query = new QueryBuilder<YourDataType>()
66
+ .addParam('field', operator, value)
67
+ .sortBy('field', SortOrder.Asc)
68
+ .skip(0)
69
+ .take(10)
70
+ ```
71
+
72
+ ### Operators
73
+
74
+ AutoQuery supports various operator types for different data types:
75
+
76
+ #### Numeric Operators
77
+ ```typescript
78
+ NumericOperators.GreaterThan
79
+ NumericOperators.LessThan
80
+ NumericOperators.EqualTo
81
+ NumericOperators.Between
82
+ ```
83
+
84
+ #### String Operators
85
+ ```typescript
86
+ StringOperators.Contains
87
+ StringOperators.StartsWith
88
+ StringOperators.EndsWith
89
+ StringOperators.Like
90
+ ```
91
+
92
+ #### Date Operators
93
+ ```typescript
94
+ DateOperators.GreaterThan
95
+ DateOperators.Between
96
+ DateOperators.StartsWith // For exact date matching
97
+ DateOperators.Contains // For month matching
98
+ ```
99
+
100
+ #### Array Operators
101
+ ```typescript
102
+ ArrayOperators.In
103
+ ArrayOperators.NotIn
104
+ ```
105
+
106
+ #### Null Operators
107
+ ```typescript
108
+ NullOperators.IsNull
109
+ NullOperators.IsNotNull
110
+ ```
111
+
112
+ ## Advanced Usage
113
+
114
+ ### Date Filtering
115
+
116
+ ```typescript
117
+ // Filter by exact date
118
+ query.addParam('paidAt', DateOperators.StartsWith, '2019-01-01')
119
+
120
+ // Filter by month
121
+ query.addParam('paidAt', DateOperators.Contains, MonthValues.Jan)
122
+
123
+ // Filter by date range
124
+ query.addParam('paidAt', DateOperators.Between, ['2019-01-01', '2019-12-31'])
125
+ ```
126
+
127
+ ### Complex Queries
128
+
129
+ ```typescript
130
+ const query = new QueryBuilder<Invoice>()
131
+ .addParam('grandTotal', NumericOperators.GreaterThan, 100)
132
+ .addParam('status', StringOperators.In, ['paid', 'pending'])
133
+ .addParam('refId', StringOperators.Contains, 'INV-')
134
+ .addParam('paidAt', NullOperators.IsNotNull)
135
+ .sortBy('grandTotal', SortOrder.Desc)
136
+ .skip(20)
137
+ .take(50)
138
+ .includeTotal(true)
139
+ .jsconfig('dh:iso8601dt')
140
+ ```
141
+
142
+ ### Invoice-Specific Queries
143
+
144
+ ```typescript
145
+ import { IInvoiceParams, InvoicesQuery } from '@litepos/autoquery'
146
+
147
+ const invoiceParams: IInvoiceParams = {
148
+ RefIdContains: 'INV-',
149
+ GrandTotal: 100,
150
+ StatusContains: 'paid',
151
+ PaidAtAfter: '2019-01-01T00:00:00',
152
+ skip: 0,
153
+ take: 10
154
+ }
155
+
156
+ const invoiceQuery = new InvoicesQuery(invoiceParams)
157
+ ```
158
+
159
+ ## API Reference
160
+
161
+ ### QueryBuilder Methods
162
+
163
+ | Method | Description | Parameters |
164
+ |--------|-------------|------------|
165
+ | `addParam` | Add a filter parameter | `property`, `operator`, `value` |
166
+ | `addRawParam` | Add a raw parameter | `key`, `value` |
167
+ | `sortBy` | Set sorting order | `property`, `order` |
168
+ | `skip` | Set number of records to skip | `number` |
169
+ | `take` | Set number of records to take | `number` |
170
+ | `includeTotal` | Include total count in response | `boolean` |
171
+ | `jsconfig` | Set JavaScript configuration | `string` |
172
+
173
+ ### Response Types
174
+
175
+ ```typescript
176
+ interface IQueryResponse<T> {
177
+ offset?: number
178
+ total?: number
179
+ results?: T[]
180
+ meta?: { [index: string]: string }
181
+ responseStatus?: ResponseStatus
182
+ }
183
+ ```
184
+
185
+ ## TypeScript Support
186
+
187
+ AutoQuery is built with TypeScript and provides full type safety:
188
+
189
+ - Compile-time validation of field names
190
+ - Type-safe operator selection based on field types
191
+ - IntelliSense support for all methods and properties
192
+ - Generic type support for custom data models
26
193
 
27
194
  ## License
28
195
 
29
- [MIT](./LICENSE) License © [Anthony Fu](https://github.com/antfu)
196
+ [MIT](./LICENSE) License © [LitePOS](https://litepos.ai)
30
197
 
31
198
  <!-- Badges -->
32
199
 
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
200
+ [npm-version-src]: https://img.shields.io/npm/v/@litepos/autoquery?style=flat&colorA=080f12&colorB=1fa669
201
+ [npm-version-href]: https://npmjs.com/package/@litepos/autoquery
202
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@litepos/autoquery?style=flat&colorA=080f12&colorB=1fa669
203
+ [npm-downloads-href]: https://npmjs.com/package/@litepos/autoquery
204
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/@litepos/autoquery?style=flat&colorA=080f12&colorB=1fa669&label=minzip
205
+ [bundle-href]: https://bundlephobia.com/result?p=@litepos/autoquery
206
+ [license-src]: https://img.shields.io/github/license/litepos/litepos-autoquery.svg?style=flat&colorA=080f12&colorB=1fa669
207
+ [license-href]: https://github.com/litepos/litepos-autoquery/blob/main/LICENSE
41
208
  [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
209
+ [jsdocs-href]: https://www.jsdocs.io/package/@litepos/autoquery
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@litepos/autoquery",
3
3
  "type": "module",
4
- "version": "5.0.1",
4
+ "version": "5.0.2",
5
5
  "packageManager": "pnpm@10.17.1",
6
6
  "description": "AutoQuery is a library for building queries for LitePOS.",
7
7
  "author": "LitePOS <info@litepos.ai>",