Skip to content

Commit

Permalink
fix(QuickMongo): allowing normal string to be passed as a key
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowplay1 committed Aug 24, 2024
1 parent 88f5bd4 commit b4ce260
Show file tree
Hide file tree
Showing 10 changed files with 529 additions and 131 deletions.
12 changes: 7 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,26 @@ module.exports = {
'never'
],

'@typescript-eslint/no-extra-semi': 'warn',

'@typescript-eslint/ban-types': 'off',
'no-plusplus': 'off',
'implicit-arrow-linebreak': 'off',
'operator-linebreak': 'off',

'arrow-body-style': 'off',
'no-param-reassign': 'off',
'consistent-return': 'off',
'function-paren-newline': 'off',
'no-mixed-spaces-and-tabs': 'off',

'eol-last': 'warn',

'linebreak-style': [
'error',
'unix'
],

'@typescript-eslint/no-extra-semi': 'warn',

'@typescript-eslint/consistent-type-definitions': [
'warn',
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

## 🕘 | Changelog

**v3.0.1**
- Now all the `key` parameters allow to pass in the normal `string` type, alongside the **keys autocomplete** feature released in **v3.0.0**.

**v3.0.0**
- Improved documentation, fixed typos & mismatches.
- Fixed minor types bugs.
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `quick-mongo-super v3.0.0` documentation
# `quick-mongo-super v3.0.1` documentation

## Classes
- [`QuickMongo<K, V>`](classes/QuickMongo.md)
Expand All @@ -21,6 +21,7 @@
- [`ExtractObjectKeys<T>`](types/ExtractObjectKeys.md)
- [`ExtractObjectValues<T>`](types/ExtractObjectValues.md)
- [`ExtractObjectEntries<T>`](types/ExtractObjectEntries.md)
- [`AutocompletableString<S>`](types/AutocompletableString.md)

## Interfaces
- [`IDatabaseConfiguration`](interfaces/IDatabaseConfiguration.md)
Expand Down
29 changes: 15 additions & 14 deletions docs/classes/QuickMongo.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ You can see the **detailed** examples on usage of each method in both **JavaScri
- [`FirstObjectKey<TKey>`](../types/FirstObjectKey.md)
- [`ObjectPath<T, TKey>`](../types/ObjectPath.md)
- [`ObjectValue<T, P>`](../types/ObjectValue.md)
- [`AutocompletableString<S>`](../types/AutocompletableString.md)
- Interfaces:
- [`IDatabaseConfiguration`](../interfaces/IDatabaseConfiguration.md)
- [`IDatabaseInternalStructure<T>`](../interfaces/IDatabaseInternalStructure.md)
Expand Down Expand Up @@ -82,7 +83,7 @@ new QuickMongo<K, V>(quickMongoClient: QuickMongoClient, databaseOptions?: IData

## Methods

## `get<P extends ObjectPath<V>>(key: P): Maybe<ObjectValue<V, P>>`
## `get<P extends ObjectPath<V>>(key: AutocompletableString<P>): Maybe<ObjectValue<V, P>>`
Retrieves a value from database by a key.

- **Parameters:**
Expand All @@ -99,7 +100,7 @@ Retrieves a value from database by a key.
console.log(objectPropertyAccessed) // -> []
```

## `getFromDatabase<P extends ObjectPath<V>>(key: P): Promise<Maybe<ObjectValue<V, P>>>`
## `getFromDatabase<P extends ObjectPath<V>>(key: AutocompletableString<P>): Promise<Maybe<ObjectValue<V, P>>>`
Retrieves a value from database by a key via sending a **direct request** to remote cluster, **omitting** the cache.

- **Parameters:**
Expand All @@ -117,7 +118,7 @@ Retrieves a value from database by a key via sending a **direct request** to rem
```


## `fetch<P extends ObjectPath<V>>(key: P): Maybe<ObjectValue<V, P>>`
## `fetch<P extends ObjectPath<V>>(key: AutocompletableString<P>): Maybe<ObjectValue<V, P>>`
Retrieves a value from database by a key.

- **Parameters:**
Expand All @@ -135,7 +136,7 @@ Retrieves a value from database by a key.
```


## `has<P extends ObjectPath<V>>(key: P): boolean`
## `has<P extends ObjectPath<V>>(key: AutocompletableString<P>): boolean`
Determines if the data is stored in database.

- **Parameters:**
Expand All @@ -156,7 +157,7 @@ Determines if the data is stored in database.
```


## `set<P extends ObjectPath<V>>(key: P, value: ObjectValue<V, P>): Promise<If<IsObject<V>, FirstObjectKey<P>, V>>`
## `set<P extends ObjectPath<V>>(key: AutocompletableString<P>, value: ObjectValue<V, P>): Promise<If<IsObject<V>, FirstObjectKey<P>, V>>`
Writes the specified value into database under the specified key.

- **Parameters:**
Expand Down Expand Up @@ -190,7 +191,7 @@ Writes the specified value into database under the specified key.
```


## `delete<P extends ObjectPath<V>>(key: P): Promise<boolean>`
## `delete<P extends ObjectPath<V>>(key: AutocompletableString<P>): Promise<boolean>`
Deletes the data from database by key.

- **Parameters:**
Expand All @@ -215,7 +216,7 @@ Sends a read, write and delete requests to the remote database and returns the r
```


## `add<P extends ObjectPath<V>>(key: P, numberToAdd: number): Promise<number>`
## `add<P extends ObjectPath<V>>(key: AutocompletableString<P>, numberToAdd: number): Promise<number>`
Performs an arithmetical addition on a target number in the database.

**[!!!] The type of target value must be a number.**
Expand All @@ -233,7 +234,7 @@ Performs an arithmetical addition on a target number in the database.
```


## `subtract<P extends ObjectPath<V>>(key: P, numberToSubtract: number): Promise<number>`
## `subtract<P extends ObjectPath<V>>(key: AutocompletableString<P>, numberToSubtract: number): Promise<number>`
Performs an arithmetical subtraction on a target number in the database.

**[!!!] The type of target value must be a number.**
Expand All @@ -245,7 +246,7 @@ Performs an arithmetical subtraction on a target number in the database.
- **Returns:** `Promise<number>` - Subtraction operation result.


## `isTargetArray<P extends ObjectPath<V>>(key: P): boolean`
## `isTargetArray<P extends ObjectPath<V>>(key: AutocompletableString<P>): boolean`
Determines whether the specified target is an array.

- **Parameters:**
Expand All @@ -259,7 +260,7 @@ Determines whether the specified target is an array.
```


## `isTargetNumber<P extends ObjectPath<V>>(key: P): boolean`
## `isTargetNumber<P extends ObjectPath<V>>(key: AutocompletableString<P>): boolean`
Determines whether the specified target is a number.

- **Parameters:**
Expand Down Expand Up @@ -334,7 +335,7 @@ Iterates over root database values and checks if the specified condition in the
- **Returns:** `boolean


## `push<P extends ObjectPath<V>>(key: P, ...values: RestOrArray<ExtractFromArray<ObjectValue<V, P>>>): Promise<ExtractFromArray<ObjectValue<V, P>>[]>`
## `push<P extends ObjectPath<V>>(key: AutocompletableString<P>, ...values: RestOrArray<ExtractFromArray<ObjectValue<V, P>>>): Promise<ExtractFromArray<ObjectValue<V, P>>[]>`
Pushes the specified value(s) into the target array in the database.

**[!!!] The type of target value must be an array.**
Expand All @@ -351,7 +352,7 @@ Pushes the specified value(s) into the target array in the database.
```


## `pull<P extends ObjectPath<V>>(key: P, targetArrayElementIndex: number, value: ObjectValue<V, P>): Promise<ExtractFromArray<ObjectValue<V, P>>[]>`
## `pull<P extends ObjectPath<V>>(key: AutocompletableString<P>, targetArrayElementIndex: number, value: ObjectValue<V, P>): Promise<ExtractFromArray<ObjectValue<V, P>>[]>`
Pushes the specified value into the target array in the database.

**[!!!] The type of target value must be an array.**
Expand All @@ -369,7 +370,7 @@ Pushes the specified value into the target array in the database.
```


## `pop<P extends ObjectPath<V>>(key: P, ...targetArrayElementIndexes: RestOrArray<ExtractFromArray<number>>): Promise<ExtractFromArray<ObjectValue<V, P>>[]>`
## `pop<P extends ObjectPath<V>>(key: AutocompletableString<P>, ...targetArrayElementIndexes: RestOrArray<ExtractFromArray<number>>): Promise<ExtractFromArray<ObjectValue<V, P>>[]>`
Removes the specified element(s) from the target array in the database.

**[!!!] The type of target value must be an array.**
Expand Down Expand Up @@ -412,7 +413,7 @@ Returns an array of object values by specified database key.
```


## `random<P extends ObjectPath<V>>(key: P): Maybe<ObjectValue<V, P>>`
## `random<P extends ObjectPath<V>>(key: AutocompletableString<P>): Maybe<ObjectValue<V, P>>`
Picks a random element of array in the database and returns the picked array element.

- **Parameters:**
Expand Down
11 changes: 11 additions & 0 deletions docs/types/AutocompletableString.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# **`AutocompletableString<S>` Type**

Makes an autocompletable union string type compatible with a `string` type.

## Implementation
```ts
export type AutocompletableString<S extends string> = S | (string & {})
```
- **Type Parameters:**
- `S` (`string`): The autocompletable union string type to make compatible with a `string` type.
Loading

0 comments on commit b4ce260

Please sign in to comment.