Skip to content

Commit f728e2e

Browse files
committed
init
0 parents  commit f728e2e

15 files changed

+1924
-0
lines changed

.gitignore

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# .gitignore
2+
3+
# OS generated files
4+
.DS_Store
5+
.DS_Store?
6+
._*
7+
.Spotlight-V100
8+
.Trashes
9+
ehthumbs.db
10+
Thumbs.db
11+
desktop.ini
12+
13+
# Logs
14+
logs
15+
*.log
16+
npm-debug.log*
17+
yarn-debug.log*
18+
yarn-error.log*
19+
20+
# Runtime data
21+
pids
22+
*.pid
23+
*.seed
24+
*.pid.lock
25+
26+
# Directory for instrumented libs generated by jscoverage/JSCover
27+
lib-cov
28+
29+
# Coverage directory used by tools like istanbul
30+
coverage
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Dependency directories
45+
node_modules/
46+
jspm_packages/
47+
48+
# TypeScript v1.x
49+
*.ts~
50+
*.tsx~
51+
52+
# Optional npm cache directory
53+
.npm
54+
55+
# Optional eslint cache
56+
.eslintcache
57+
58+
# Optional REPL history
59+
.node_repl_history
60+
61+
# Output of 'npm pack'
62+
*.tgz
63+
64+
# dotenv environment variable files
65+
.env
66+
.env.test
67+
68+
# next.js build output
69+
.next
70+
71+
# Nuxt.js build output
72+
.nuxt
73+
74+
# vuepress build output
75+
.vuepress/dist
76+
77+
# Serverless directories
78+
.serverless/
79+
80+
# IDE files
81+
.vscode/
82+
*.iml
83+
.idea/
84+
*.suo
85+
*.sln
86+
*.user
87+
*.userosscache
88+
*.sublime*
89+
90+
# project
91+
/.archive

.gitlab-ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
image: node:16
2+
3+
before_script:
4+
- npm install
5+
6+
test:
7+
script:
8+
- npm run test

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Bas Edwon
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.

README.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Indexer
2+
3+
[![npm](https://img.shields.io/npm/v/@plaindb/index?style=flat&logo=npm)](https://www.npmjs.com/package/@plaindb/index)
4+
[![pipeline](https://gitlab.com/frenware/framework/plaindb/index/badges/master/pipeline.svg)](https://gitlab.com/frenware/framework/plaindb/index/-/pipelines)
5+
[![license](https://img.shields.io/npm/l/@plaindb/index)](https://gitlab.com/frenware/framework/plaindb/index/-/blob/master/LICENSE)
6+
[![downloads](https://img.shields.io/npm/dw/@plaindb/index)](https://www.npmjs.com/package/@plaindb/index)
7+
8+
[![Gitlab](https://img.shields.io/badge/Gitlab%20-%20?logo=gitlab&color=%23383a40)](https://gitlab.com/frenware/framework/plaindb/index)
9+
[![Github](https://img.shields.io/badge/Github%20-%20?logo=github&color=%23383a40)](https://github.com/basedwon/index)
10+
[![Twitter](https://img.shields.io/badge/@basdwon%20-%20?logo=twitter&color=%23383a40)](https://twitter.com/basdwon)
11+
[![Discord](https://img.shields.io/badge/Basedwon%20-%20?logo=discord&color=%23383a40)](https://discordapp.com/users/basedwon)
12+
13+
A comprehensive indexing solution built to cater to a wide variety of indexing requirements. It provides a robust API for adding, removing, updating, and finding data based on multiple types of index fields. Including an inverted-indexing of words within a text field.
14+
15+
## Features
16+
17+
- Dynamic field creation for indexing
18+
- Supports single, multi, and text-based fields
19+
- Extensible with custom index field types
20+
- Asynchronous API support
21+
- Transactional batch operations
22+
- Formatter and reducer customization
23+
24+
## Installation
25+
26+
Install the package with:
27+
28+
```bash
29+
npm install @plaindb/index
30+
```
31+
32+
## Usage
33+
34+
First, import the `Indexer` library.
35+
36+
```js
37+
import Indexer from '@plaindb/index'
38+
```
39+
or
40+
```js
41+
const Indexer = require('@plaindb/index')
42+
```
43+
44+
### Initialize the Index
45+
46+
```js
47+
const storage = // Your storage instance
48+
const index = new Index(storage, ['name', 'age|gender', 'description text'])
49+
```
50+
51+
### Adding an Entity
52+
53+
```js
54+
await index.add({
55+
id: 1,
56+
name: 'John',
57+
age: 30,
58+
gender: 'male',
59+
description: 'Software Engineer'
60+
})
61+
```
62+
63+
### Removing an Entity
64+
65+
```js
66+
await index.remove({
67+
id: 1
68+
})
69+
```
70+
71+
### Updating an Entity
72+
73+
```js
74+
await index.update(oldEntity, newEntity)
75+
```
76+
77+
### Finding Entities
78+
79+
You can find entities based on index fields:
80+
81+
```js
82+
const results = await index.find('age', 30)
83+
```
84+
85+
### Custom Formatter and Reducer
86+
87+
You can provide custom formatter and reducer functions through the `opts` parameter:
88+
89+
```js
90+
const index = new Index(storage, ['name'], {
91+
formatter: new CustomFormatter(),
92+
reducer: (entity) => entity.customId
93+
})
94+
```
95+
96+
## Documentation
97+
98+
- [API Reference](/docs/api.md)
99+
100+
101+
102+
103+
104+
## API
105+
106+
### Classes
107+
108+
- `Index`: Manages multiple index fields and dispatches operations.
109+
- `IndexFactory`: Creates index fields dynamically.
110+
- `IndexField`: Abstract class for index fields.
111+
- `SingleIndexField`: Index field for single properties.
112+
- `MultiIndexField`: Index field for multi-properties.
113+
- `TextIndexField`: Index field for text-based searching.
114+
115+
### Methods
116+
117+
- `Index.by(slug)`: Dynamically add an index field.
118+
- `Index.add(entity)`: Add an entity to the index.
119+
- `Index.remove(entity)`: Remove an entity from the index.
120+
- `Index.update(oldEntity, newEntity)`: Update an entity in the index.
121+
- `Index.find(query, ...values)`: Find entities based on a query.
122+
123+
## Extending
124+
125+
To extend the library with a custom index field, create a class extending `IndexField` and register it via `Registry`.
126+
127+
128+
129+
130+
131+
## API
132+
133+
- `Index`
134+
- `constructor(storage, fields[], opts)`
135+
- `by(slug: string): Index`
136+
- `add(entity: object): Promise`
137+
- `remove(entity: object): Promise`
138+
- `update(oldEntity: object, newEntity: object): Promise`
139+
- `find(query: string|object, ...values): Promise`
140+
- `IndexField`
141+
- `constructor(index, options)`
142+
- `normalize(value): any`
143+
- `buildOps(type: string, entity: object, ops: array): array`
144+
- `add(entity: object, ops: array): array`
145+
- `update(oldEntity: object, newEntity: object, ops: array): array`
146+
- `remove(entity: object, ops: array): array`
147+
- `find(...query): Promise`
148+
- `SingleIndexField`
149+
- `find(query: any): Promise`
150+
- `MultiIndexField`
151+
- `getKeys(field: string): array`
152+
- `getPath(entity: object): string`
153+
- `find(...query): Promise`
154+
- `TextIndexField`
155+
- `getKeys(field: string): array`
156+
- `isMatch(oldEntity: object, newEntity: object): boolean`
157+
- `buildOps(type: string, entity: object, ops: array): array`
158+
- `find(...query): Promise`
159+
- `IndexFactory`
160+
- `constructor(index)`
161+
- `getFieldKey(slug: string): string`
162+
- `getFieldType(slug: string): object`
163+
- `createField(definition: string): IndexField`
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
## Tests
174+
175+
In order to run the test suite, simply clone the repository and install its dependencies:
176+
177+
```bash
178+
git clone https://gitlab.com/frenware/framework/plaindb/index.git
179+
cd indexer
180+
npm install
181+
```
182+
183+
To run the tests:
184+
185+
```bash
186+
npm test
187+
```
188+
189+
## Contributing
190+
191+
Thank you! Please see our [contributing guidelines](/docs/contributing.md) for details.
192+
193+
## Donations
194+
195+
If you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!
196+
197+
**Bitcoin (BTC):**
198+
```
199+
1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF
200+
```
201+
202+
**Monero (XMR):**
203+
```
204+
46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ
205+
```
206+
207+
## License
208+
209+
@plaindb/index is [MIT licensed](https://gitlab.com/frenware/framework/plaindb/index/-/blob/master/LICENSE).

0 commit comments

Comments
 (0)