30 Commits

Author SHA1 Message Date
c95f3251bb update dependnecies and add graph of microutils repo 2025-08-18 11:18:56 +06:00
7e886d5e65 Update index.md 2025-08-06 17:47:28 +06:00
a6097e6784 update dependencies 2025-06-30 14:02:57 +06:00
ec5bcaf058 update ktgbotapi index.md 2025-06-30 14:01:28 +06:00
2c97740abb Update index.md 2025-06-25 16:27:40 +06:00
a2798c3b2e update info about support telegram bot api 2025-02-15 20:57:47 +06:00
34abb664b9 Update index.md 2025-01-03 10:47:29 +06:00
1149abc79f Add sample link for navigation 2024-12-26 08:48:47 +06:00
faa3573546 Update index.md 2024-11-02 00:02:30 +06:00
6e7cf1cb0e small docs actualization 2024-09-23 00:47:59 +06:00
c7e552ebb5 update dependencies 2024-09-23 00:23:42 +06:00
329a9ba310 update info in tgbotapi supported telegram bot api 2024-08-26 08:31:45 +06:00
c74bafb4a3 update dependencies 2024-08-26 08:29:36 +06:00
256226044f Merge pull request #6 from InsanusMokrassar/renovate/configure
Configure Renovate
2024-08-26 08:11:54 +06:00
renovate[bot]
1b02e8a7e4 Add renovate.json 2024-08-26 02:11:20 +00:00
7b0a171bd3 Update supported version of tg bot api 2024-06-27 07:26:53 +06:00
4410bb3b28 Update index.md 2024-06-01 13:56:12 +06:00
0931cbd97d add note about behaviour builder long polling 2024-05-29 16:31:35 +06:00
228c7704f5 implovement in generate from template 2024-05-15 18:33:10 +06:00
6377aefb6a update supportable version of telegram bot api 2024-05-10 20:00:58 +06:00
3c433daa6b fix in artifact name of colors 2024-05-05 17:02:34 +06:00
a6c1aacf40 add colors 2024-05-04 23:57:45 +06:00
4dd90738ba add inmemory tutorial 2024-05-04 22:28:25 +06:00
68426c126d complete first version of repos tutor 2024-05-04 21:57:17 +06:00
ca7eedbb74 add repo about key value repo 2024-05-04 21:03:17 +06:00
006f0b69d8 start including of repos tutorials 2024-05-02 18:46:04 +06:00
df2812a04d add micro_utils startup docs 2024-04-22 16:44:19 +06:00
9ec30af2ad add docs fleet install config and update dependencies 2024-03-06 17:32:17 +06:00
c8caed5b3a update supported version of tgbotapi 2024-02-17 01:54:32 +06:00
c0e7ac5f27 update krontab docs 2024-02-11 12:20:13 +06:00
16 changed files with 1132 additions and 466 deletions

View File

@@ -1,5 +1,11 @@
{
"configurations": [
{
"type": "command",
"name": "Install",
"program": "poetry",
"args": ["install", "--no-root"],
},
{
"type": "command",
"name": "Rebuild",
@@ -12,5 +18,12 @@
"program": "poetry",
"args": ["run", "mkdocs", "serve"],
},
{
"type": "command",
"name": "Generate MicroUtils",
"program": "kotlin",
"args": ["../../generate_from_template.kts"],
"workingDir": "./docs/micro_utils/",
},
]
}

View File

@@ -11,7 +11,7 @@
[![KDocs](https://img.shields.io/badge/KDocs-323330?style=for-the-badge&logo=Kotlin&logoColor=7F52FF)](https://insanusmokrassar.github.io/krontab/)
Library was created to give oppotunity to launch some things from time to time according to some schedule in
Library was created to give opportunity to launch some things from time to time according to some schedule in
runtime of applications.
## How to use
@@ -77,7 +77,7 @@ doWhile("/5 * * * *") {
}
```
An other version:
Another version:
```kotlin
doInfinity("/5 * * * *") {
@@ -166,7 +166,7 @@ coroutine is alive` and in fact executing will be stopped when coroutine became
### KronScheduler as a Flow
Any `KronScheduler`can e converted to a `Flow<DateTime` using extension `asFlow`:
Any `KronScheduler` can be converted to a `Flow<DateTime>` using extension `asFlow`:
```kotlin
val kronScheduler = buildSchedule {
@@ -178,7 +178,7 @@ val kronScheduler = buildSchedule {
val flow = kronScheduler.asFlow()
```
So, in this case any operations related to flow are available and it is expected that they will work correctly. For
So, in this case any operations related to flow are available, and it is expected that they will work correctly. For
example, it is possible to use this flow with `takeWhile`:
```kotlin
@@ -191,7 +191,7 @@ flow.takeWhile {
### Offsets
Offsets in this library works via passing parameter ending with `o` in any place after `month` config. Currently
Offsets in this library works via passing parameter ending with `o` in any place after `month` config. Currently,
there is only one format supported for offsets: minutes of offsets. To use time zones you will need to call `next`
method with `DateTimeTz` argument or `nextTimeZoned` method with any `KronScheduler` instance, but in case if this
scheduler is not instance of `KronSchedulerTz` it will work like you passed just `DateTime`.
@@ -211,4 +211,4 @@ Unlike original CRON, here week days:
* Works as `AND`: cron date time will search first day which will pass requirement according all parameters including
week days
* You may use any related to numbers syntax with week days: `0-3w`, `0,1,2,3w`, etc.
* Week days (like years and offsets) are optional and can be placed anywhere after `month`
* Week days (as well as years and offsets) are optional and can be placed anywhere after `month`

View File

@@ -0,0 +1,42 @@
group=dev.inmo
artifact=micro_utils.colors.common
package=$group.$artifact
central_package=$group/$artifact
# Colors [![Maven Central](https://maven-badges.herokuapp.com/maven-central/${central_package}/badge.svg)](https://maven-badges.herokuapp.com/maven-central/${central_package})
* `Group`: `$group`
* `ArtifactId`: `$artifact`
Adding dependency:
```groovy
implementation "$group:$artifact:latest"
```
> INFO:
>
> All the samples below will represent `HEXAColor` with `r==0xaa`, `g==0xff`, `b==0x00` and `a==0xff`
This package contains mainly one file: [HEXAColor](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.colors.common/-h-e-x-a-color/index.html). This file
contains unified color with HEXA format. It consumes `UInt` by default constructor and r/g/b/a parameters in other main constructors:
```kotlin
HEXAColor(0xaaff00ffu) // 0xRGBAu as UInt
HEXAColor(r = 0xaa, g = 0xff, b = 0x00, a = 0xff)
HEXAColor(r = 0xaa, g = 0xff, b = 0x00, aOfOne = 1f)
```
Besides, you may use one of converters:
```kotlin
HEXAColor.fromAhex(0xffaaff00u) // 0xARGBu as UInt
HEXAColor.parse("rgba(aa, ff, 00, ff)")
HEXAColor.parse("rgba(aa, ff, 00)")
HEXAColor.parse("#af0")
HEXAColor.parse("#af0f")
HEXAColor.parse("#aaff00")
HEXAColor.parse("#aaff00ff")
```

View File

@@ -0,0 +1,39 @@
# Colors
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/micro_utils.colors.common/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/micro_utils.colors.common)
* `Group`: `dev.inmo`
* `ArtifactId`: `micro_utils.colors.common`
Adding dependency:
```groovy
implementation "dev.inmo:micro_utils.colors.common:latest"
```
> INFO:
>
> All the samples below will represent `HEXAColor` with `r==0xaa`, `g==0xff`, `b==0x00` and `a==0xff`
This package contains mainly one file: [HEXAColor](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.colors.common/-h-e-x-a-color/index.html). This file
contains unified color with HEXA format. It consumes `UInt` by default constructor and r/g/b/a parameters in other main constructors:
```kotlin
HEXAColor(0xaaff00ffu) // 0xRGBAu as UInt
HEXAColor(r = 0xaa, g = 0xff, b = 0x00, a = 0xff)
HEXAColor(r = 0xaa, g = 0xff, b = 0x00, aOfOne = 1f)
```
Besides, you may use one of converters:
```kotlin
HEXAColor.fromAhex(0xffaaff00u) // 0xARGBu as UInt
HEXAColor.parse("rgba(aa, ff, 00, ff)")
HEXAColor.parse("rgba(aa, ff, 00)")
HEXAColor.parse("#af0")
HEXAColor.parse("#af0f")
HEXAColor.parse("#aaff00")
HEXAColor.parse("#aaff00ff")
```

View File

@@ -17,3 +17,183 @@ First of all, this library collection is oriented to use next technologies:
> Me and the users of this library will try hard to keep its docs as actual as possible, but in case
> you will find some inconsistency of docs and library work (signatures, behaviour, API) you may write
> me directly in my [telegram](https://t.me/InsanusMokrassar)
```mermaid
flowchart LR
%% Project Build & Infrastructure
subgraph "Project Build & Infrastructure"
gradleWrapper("Gradle Wrapper & Plugins"):::buildInfra
CI("CI Workflows"):::buildInfra
templates("Gradle Templates"):::buildInfra
end
%% Core Utility Layer
subgraph "Core Utility Layer"
common("common"):::core
colors("colors"):::core
safe_wrapper("safe_wrapper"):::core
resources("resources"):::core
end
%% Feature-Specific Modules
subgraph "Feature-Specific Modules"
crypto("crypto"):::feature
mime_types("mime_types"):::feature
language_codes("language_codes"):::feature
matrix("matrix"):::feature
selector("selector"):::feature
transactions("transactions"):::feature
end
%% Asynchronous Helpers
subgraph "Asynchronous Helpers"
coroutines("coroutines"):::async
compose("coroutines/compose"):::async
end
%% Serialization Helpers
subgraph "Serialization Helpers"
base64("serialization/base64"):::serialization
encapsulator("serialization/encapsulator"):::serialization
mapper("serialization/mapper"):::serialization
typed_serializer("serialization/typed_serializer"):::serialization
end
%% Repository Abstractions
subgraph "Repository Abstractions"
repos_common("repos/common (API)"):::repos
repos_inmemory("repos/inmemory"):::repos
repos_cache("repos/cache"):::repos
repos_exposed("repos/exposed"):::repos
repos_ktor_client("repos/ktor/client"):::repos
repos_ktor_common("repos/ktor/common"):::repos
repos_ktor_server("repos/ktor/server"):::repos
end
%% Ktor Extensions
subgraph "Ktor Extensions"
ktor_common("ktor/common"):::ktor
ktor_client("ktor/client"):::ktor
ktor_server("ktor/server"):::ktor
end
%% Dependency Injection (Koin)
subgraph "Dependency Injection (Koin)"
koin_api("koin/src"):::di
koin_generator("koin/generator"):::di
end
%% KSP Code-Generation Modules
subgraph "KSP Code-Generation Modules"
ksp_classcasts("ksp/classcasts"):::ksp
ksp_sealed("ksp/sealed"):::ksp
ksp_variations("ksp/variations"):::ksp
ksp_generator("ksp/generator"):::ksp
end
%% Android UI Wrappers
subgraph "Android UI Wrappers"
alerts("android/alerts"):::android
pickers("android/pickers"):::android
recyclerview("android/recyclerview"):::android
smalltextfield("android/smalltextfield"):::android
end
%% Startup Plugins & Templates
subgraph "Startup Plugins & Templates"
startup_plugin("startup/plugin"):::startup
startup_launcher("startup/launcher"):::startup
startup_template("startup/template"):::startup
end
%% Dependencies Arrows
common -->|feeds into| crypto
common -->|feeds into| mime_types
common -->|feeds into| language_codes
common -->|feeds into| matrix
common -->|feeds into| selector
common -->|feeds into| transactions
common -->|feeds into| coroutines
coroutines -->|extends| compose
common -->|feeds into| base64
common -->|feeds into| encapsulator
common -->|feeds into| mapper
common -->|feeds into| typed_serializer
common -->|feeds into| repos_common
repos_common -->|implemented by| repos_inmemory
repos_common -->|implemented by| repos_cache
repos_common -->|implemented by| repos_exposed
repos_common -->|implemented by| repos_ktor_client
repos_common -->|implemented by| repos_ktor_common
repos_common -->|implemented by| repos_ktor_server
ktor_common -->|used by| ktor_client
ktor_common -->|used by| ktor_server
ksp_generator -->|used by| koin_generator
ksp_generator -->|used by| ksp_classcasts
ksp_generator -->|used by| ksp_sealed
ksp_generator -->|used by| ksp_variations
common -->|feeds into| alerts
common -->|feeds into| pickers
common -->|feeds into| recyclerview
common -->|feeds into| smalltextfield
%% Click Events
click templates "https://github.com/insanusmokrassar/microutils/tree/master/gradle/templates/"
click common "https://github.com/insanusmokrassar/microutils/tree/master/common/"
click colors "https://github.com/insanusmokrassar/microutils/tree/master/colors/"
click safe_wrapper "https://github.com/insanusmokrassar/microutils/tree/master/safe_wrapper/"
click resources "https://github.com/insanusmokrassar/microutils/tree/master/resources/"
click crypto "https://github.com/insanusmokrassar/microutils/tree/master/crypto/"
click mime_types "https://github.com/insanusmokrassar/microutils/tree/master/mime_types/"
click language_codes "https://github.com/insanusmokrassar/microutils/tree/master/language_codes/"
click matrix "https://github.com/insanusmokrassar/microutils/tree/master/matrix/"
click selector "https://github.com/insanusmokrassar/microutils/tree/master/selector/"
click transactions "https://github.com/insanusmokrassar/microutils/tree/master/transactions/"
click coroutines "https://github.com/insanusmokrassar/microutils/tree/master/coroutines/"
click compose "https://github.com/insanusmokrassar/microutils/tree/master/coroutines/compose/"
click base64 "https://github.com/insanusmokrassar/microutils/tree/master/serialization/base64/"
click encapsulator "https://github.com/insanusmokrassar/microutils/tree/master/serialization/encapsulator/"
click mapper "https://github.com/insanusmokrassar/microutils/tree/master/serialization/mapper/"
click typed_serializer "https://github.com/insanusmokrassar/microutils/tree/master/serialization/typed_serializer/"
click repos_common "https://github.com/insanusmokrassar/microutils/tree/master/repos/common/"
click repos_inmemory "https://github.com/insanusmokrassar/microutils/tree/master/repos/inmemory/"
click repos_cache "https://github.com/insanusmokrassar/microutils/tree/master/repos/cache/"
click repos_exposed "https://github.com/insanusmokrassar/microutils/tree/master/repos/exposed/"
click repos_ktor_client "https://github.com/insanusmokrassar/microutils/tree/master/repos/ktor/client/"
click repos_ktor_common "https://github.com/insanusmokrassar/microutils/tree/master/repos/ktor/common/"
click repos_ktor_server "https://github.com/insanusmokrassar/microutils/tree/master/repos/ktor/server/"
click koin_api "https://github.com/insanusmokrassar/microutils/tree/master/koin/src/"
click koin_generator "https://github.com/insanusmokrassar/microutils/tree/master/koin/generator/"
click ksp_classcasts "https://github.com/insanusmokrassar/microutils/tree/master/ksp/classcasts/"
click ksp_sealed "https://github.com/insanusmokrassar/microutils/tree/master/ksp/sealed/"
click ksp_variations "https://github.com/insanusmokrassar/microutils/tree/master/ksp/variations/"
click ksp_generator "https://github.com/insanusmokrassar/microutils/tree/master/ksp/generator/"
click alerts "https://github.com/insanusmokrassar/microutils/tree/master/android/alerts/"
click pickers "https://github.com/insanusmokrassar/microutils/tree/master/android/pickers/"
click recyclerview "https://github.com/insanusmokrassar/microutils/tree/master/android/recyclerview/"
click smalltextfield "https://github.com/insanusmokrassar/microutils/tree/master/android/smalltextfield/"
click startup_plugin "https://github.com/insanusmokrassar/microutils/tree/master/startup/plugin/"
click startup_launcher "https://github.com/insanusmokrassar/microutils/tree/master/startup/launcher/"
click startup_template "https://github.com/insanusmokrassar/microutils/tree/master/startup/template/"
%% Styles
%% classDef buildInfra fill:#eee,stroke:#666,stroke-width:1px;
%% classDef core fill:#cce5ff,stroke:#004085,stroke-width:1px;
%% classDef feature fill:#e2e3e5,stroke:#636f83,stroke-width:1px;
%% classDef async fill:#d1ecf1,stroke:#0c5460,stroke-width:1px;
%% classDef serialization fill:#fff3cd,stroke:#856404,stroke-width:1px;
%% classDef repos fill:#d4edda,stroke:#155724,stroke-width:1px;
%% classDef ktor fill:#ffe5b4,stroke:#ff8c00,stroke-width:1px;
%% classDef di fill:#f5c6cb,stroke:#721c24,stroke-width:1px;
%% classDef ksp fill:#f8d7da,stroke:#721c24,stroke-width:1px;
%% classDef android fill:#e2e7ec,stroke:#1f2a36,stroke-width:1px;
%% classDef startup fill:#f0f3bd,stroke:#a2a04f,stroke-width:1px;
```
Generated with [gitdiagram](https://gitdiagram.com/insanusmokrassar/microutils) and edited then

View File

@@ -0,0 +1,119 @@
# Repos
Repositories in this library are unified interfaces to work with different types of standard repos:
* CRUD (create/read/update/delete)
* Key-value
* Key-value**s**
## CRUD
Default interface for any `CRUD`-oriented realization of repositories. This type of repos separated to three interfaces:
* [ReadCRUDRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-read-c-r-u-d-repo/index.html)
* [WriteCRUDRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-c-r-u-d-repo/index.html)
* [CRUDRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-c-r-u-d-repo/index.html)
```mermaid
flowchart TB
ReadCRUDRepo --> CRUDRepo
WriteCRUDRepo --> CRUDRepo
```
`CRUDRepo` extends both `ReadCRUDRepo` and `WriteCRUDRepo`.
CRUD repos __do not__ support forced placing of data by id when data is not in repo. That means, that you can't set data in repo by id
which absent in the repository.
### `ReadCRUDRepo`
Contains read-only operations, such as [getById](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-read-c-r-u-d-repo/get-by-id.html),
[contains](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-read-c-r-u-d-repo/contains.html). This interface can't be observed because of it does not suppose
any mutable operation.
### `WriteCRUDRepo`
Contains write-only operations, such as [create](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-c-r-u-d-repo/create.html),
[update](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-c-r-u-d-repo/update.html). This interface can be observed via its flows:
* [newObjectsFlow](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-c-r-u-d-repo/new-objects-flow.html) for newely
[create](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-c-r-u-d-repo/create.html)d objects
* [updatedObjectsFlow](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-c-r-u-d-repo/updated-objects-flow.html) for old
[update](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-c-r-u-d-repo/update.html)d objects
* [deletedObjectsIdsFlow](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-c-r-u-d-repo/deleted-objects-ids-flow.html) for
[delete](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-c-r-u-d-repo/delete-by-id.html)d objects
> INFO:
>
> By default, all mutating operations consumes `List`s of data (`List<New>` for `create`, `List<Pair<Id, New>>` for `update` and `List<Id>` for delete),
> but all they have their extension function-variations with one/two args (like `create` with `New` arg)
* `create` operation consumes list of `New` variants of object and produces `Registered`s list. In most cases, `Registered` variant of object should have
`Id` of registered object, but it is not required for repo.
* `update` operation consumes list of pairs with `Id` and `New` objects and produces list of `Registered` objects.
* `deleteById` operation consumes list of `Id`s and do not consume anything except of notifying via `deletedObjectsIdsFlow`.
## KeyValue
Key-value repos has been created to support work with classic key-value stores, where keys are unique across all the repo when values are not unique.
As well as all the others types of repos, this one have two basic types:
[ReadKeyValueRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-read-key-value-repo/index.html) and
[WriteKeyValueRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-key-value-repo/index.html)
### ReadKeyValueRepo
Read repo provides functions like: [contains](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-read-key-value-repo/contains.html),
[get](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-read-key-value-repo/get.html) or
[values](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-read-key-value-repo/values.html).
### WritekeyValueRepo
Contains write-only operations. This interface can be observed via its flows:
* [onNewValue](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-key-value-repo/on-new-value.html) to retrieve newely set values and keys
* [onValueRemoved](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-key-value-repo/on-value-removed.html) for the values removed from repo
> INFO:
>
> By default, all mutating operations consumes some collections. For example, [set](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-key-value-repo/set.html)
> require `Map` with `Key`s and `Value`s and do not returns anything. Instead, it will throw notification via `onNewValue` flow
>
> All the methods on `WriteKeyValueRepo` have their variances with `pairs` (for set) or plain `vararg`s.
* `set` operation consumes map of `Key`s and their `Value`s, set them and produces updates via `onNewValue`
* `unset` operation consumes list of `Key`s, removing `Value` by `Key` and produces updates via `onValueRemoved`
* `unsetWithValues` consumes list of `Value`s, removing all `Key`s with the `Value`s equal to one of the input `Value`s, and then produces updates via `onValueRemoved`
## KeyValues
This type of repos contains muliple `Value`s by their unique `Key`. It is not guaranteed, that `Value`s list by any `Key` will contains only unique values,
but in most cases `Value`s list will not contains copies/same objects.
### [ReadKeyValuesRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-read-key-values-repo/index.html)
Contains operations for work with value/values getting and checking. For example:
[count](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-read-key-values-repo/count.html) for checking of amount of all values in repo
or values by key; [get](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-read-key-values-repo/get.html) for getting of values by
`pagination`.
### [WriteKeyValuesRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-key-values-repo/index.html)
Contains write-only operations. This interface can be observed via its flows:
* [onNewValue](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-key-values-repo/on-new-value.html) will pass `Key` and `Value` when `Value` has been added to the `Key`
* [onValueRemoved](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-key-values-repo/on-value-removed.html) will pass `Key` and `Value` when `Value` has been removed for the `Key`
* [onDataCleared](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-key-values-repo/on-data-cleared.html) will pass `Key` when **all** its values has been
removed by the `clear` operation
> INFO:
>
> In difference with other repos, not all the methods of write key values repo require collections.
>
> All the methods on `WriteKeyValuesRepo` have their variances with `pairs` (for set) or plain `vararg`s.
* `add` will add `Value`s to their `Key`s without any removing of data
* `clear` removes all `Value`s by `Key` and `Key` itself from repo
* `clearWithValue` removes all `Value` with full clear of all data by `Key`s with incoming `Value`
* `remove` consumes `Map` of `Key`s and the `Value`s which should be removed for each `Key`
* `removeWithValue` will remove only `Value` from all `Key`s collections without their full wipe
* `set` consumes `Map` of `Key`s and the `Value`s and will **rewrite** currently exists list of `Value`s and set the `Value`s for their `Key`

View File

@@ -0,0 +1,20 @@
# In memory
In memory realizations contains several simple variants:
* [MapCRUDRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-map-c-r-u-d-repo/index.html)
* [MapKeyValueRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-map-key-value-repo/index.html)
* [MapKeyValuesRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-map-key-values-repo/index.html)
Each realization contains `Write` and `Read` parents.
There are several important moments:
## [WriteMapCRUDRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-write-map-c-r-u-d-repo/index.html) (and [MapCRUDRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-map-c-r-u-d-repo/index.html))
It is an abstract repo with abstract functions: `updateObject` and `createObject`. Both functions require from realization to create `Registered` variant from incoming data and
both will be called within repo [locker.withWriteLock](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.coroutines/with-write-lock.html).
You may use functions [MapCRUDRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-map-c-r-u-d-repo.html) with
passing the callbacks `updateObject` and `createObject` which will be used in their realizations of default [MapCRUDRepo](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.repos/-map-c-r-u-d-repo/index.html)
variant

View File

@@ -0,0 +1,95 @@
# Startup
[![Maven Central](https://img.shields.io/maven-central/v/dev.inmo/micro_utils.common?label=latest_version&style=flat-square)](https://github.com/InsanusMokrassar/MicroUtils)
* **Plugins Package**: `dev.inmo:micro_utils.startup.plugin`
* **Launcher Package**: `dev.inmo:micro_utils.startup.launcher`
This package contains unified simple `Plugin`/`Launcher` tools for separating of your apps parts
Launching logic:
```mermaid
flowchart TB
StartLauncherPlugin.startAsync
StartLauncherPlugin.startAsync --> KoinInit["Koin.init"]
KoinInit --> StartLauncherPlugin.setupDI
subgraph StartLauncherPlugin.setupDI
direction LR
AddDefaultDependencies["Default dependencies: config as JsonObject, config as object, CoroutineScope, Json"]
SubPluginsSetupDI["Calling setupDI in subplugins"]
AddDefaultDependencies --> SubPluginsSetupDI
end
StartLauncherPlugin.setupDI --> startKoin
startKoin --> StartLauncherPlugin.startPlugin
subgraph StartLauncherPlugin.startPlugin
direction LR
LaunchSubplugins["Asynchronously (in CoroutineScope from Koin) start subplugins"]
end
StartLauncherPlugin.startPlugin --> ReturnKoinAppAndLaunchJob["Return koinApp and laucnhing job"]
```
## Plugin
To define plugin, you must use `StartPlugin` as supertype for your plugin. Restrictions are simple: plugins must be an `object` or `class` with empty constructor. Basic sample is here:
```kotlin
object YourPlugin : StartPlugin {
// Body of your plugin
}
```
Each plugin may contains to parts:
* `setupDI` function to set up DI part
* `startPlugin` function to start plugin
```kotlin
object YourPlugin : StartPlugin {
override fun Module.setupDI(config: JsonObject) {
// here you may setup any DI content you wish to be available in context of current Koin module
}
override fun startPlugin(koin: Koin) {
// all staff from setupDI and the same function of other plugins is available in koin
}
}
```
## Launcher
Basically, launcher module can be used to start application directly from `gradle`. Let's imagine you have this gradle groovy config:
```groovy
plugins {
id 'org.jetbrains.kotlin.jvm'
id "org.jetbrains.kotlin.plugin.serialization"
id 'application'
}
dependencies {
// kotlin and other dependencies
implementation ("dev.inmo:micro_utils.startup.launcher:$latest_version")
}
application {
mainClassName = 'dev.inmo.micro_utils.startup.launcher.MainKt'
}
```
You will be able to run your project with gradle command `./gradlew run --args="path/to/config.json"`. `config.json` must contains something like:
```json
{
"plugins": [
"dev.inmo.micro_utils.startup.launcher.HelloWorldPlugin"
]
}
```
In current case you will see in logger different logs about launching including log from `HelloWorldPlugin` with text `Hello world`.

View File

@@ -9,8 +9,10 @@
Plugin is a partially independent part of bot. Plugin have several parts:
* `setupDI` - this method should be used to configure DI part of module
* `setupBotPlugin` - method to start/configure your bot actions
* `setupBotClient` - method to configure telegram bot in case you need it. Called synchronously when `TelegramBot`
initializing in `single` in `setupDI` of `PlaguBot`
* `setupBotPlugin` - method to start/configure your **bot** actions. Called asynchronously in `buildBehaviourWithFSM`
in `startPlugin` of `PlaguBot`
Plugin realization should be an `object` or `class` with empty constructor.
@@ -20,6 +22,11 @@ Most important of bot is `main` function (full reference: `dev.inmo.plagubot.App
Bot is initializing with the next algorithm:
---
**OLD**
```mermaid
flowchart TB
main["Main"]

View File

@@ -1,6 +1,6 @@
# TelegramBotAPI
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-7.0-blue)](https://core.telegram.org/bots/api-changelog#december-29-2023)
[![Maven Central Version](https://img.shields.io/maven-central/v/dev.inmo/tgbotapi)](https://central.sonatype.com/artifact/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-9.0-blue)](https://core.telegram.org/bots/api-changelog#april-11-2025)
<!--- [![Telegram Channel](./resources/tg_channel_qr.jpg)](https://t.me/ktgbotapi) --->

View File

@@ -66,3 +66,62 @@ bot.buildBehaviour {
}
}
```
## Long polling
In case you wish to start long polling, you have two options:
* Start long polling with `buildBehaviour` additional functions
* Start long polling from using the result of `buildBehaviour`
> NOTE: **More info**
>
> More info about updates retrieving you may read at the [Long Polling](../updates/long-polling.md) and [Webhooks](../updates/webhooks.md)
> articles
### Long polling from `buildBehaviour`
With prepared bot:
```kotlin
val bot = telegramBot("TOKEN")
bot.buildBehaviourWithLongPolling {
onCommand(
"start",
requireOnlyCommandInMessage = true // it is default, but you can overwrite it with `requireOnlyCommandInMessage = false`
) {
// ...
}
}
```
Without prepared bot:
```kotlin
telegramBotWithBehaviourAndLongPolling("TOKEN") {
onCommand(
"start",
requireOnlyCommandInMessage = true // it is default, but you can overwrite it with `requireOnlyCommandInMessage = false`
) {
// ...
}
}
```
### Long polling from the result of behaviour building
```kotlin
val bot = telegramBot("TOKEN")
val rootContext = bot.buildBehaviour {
onCommand(
"start",
requireOnlyCommandInMessage = true // it is default, but you can overwrite it with `requireOnlyCommandInMessage = false`
) {
// ...
}
}
bot.longPolling(rootContext) // start listening updates
```

111
generate_from_template.kts Normal file
View File

@@ -0,0 +1,111 @@
import kotlin.collections.LinkedHashSet
import java.io.File
val templateEnding = Regex("\\.ktstemplate(\\.[^\\.]*)*$")
val templateOnlyEnding = Regex("\\.ktstemplate")
val singleArgumentRegex = Regex("^[\\w\\d]+$")
val splitterRegex = Regex("[ ]*=[ ]*")
sealed interface Mode {
fun filesList(folder: File): Sequence<File>
data object Recursive : Mode {
override fun filesList(folder: File): Sequence<File> {
return sequence {
val folders = mutableListOf<File>()
folders.add(folder)
while (folders.isNotEmpty()) {
val currentFolder = folders.removeAt(0)
currentFolder.listFiles().toList().forEach {
when {
it.isFile -> yield(it)
it.isDirectory -> folders.add(it)
}
}
}
}
}
}
data object Plain : Mode {
override fun filesList(folder: File): Sequence<File> {
return sequence {
folder.listFiles().forEach {
yield(it)
}
}
}
}
}
var mode: Mode = Mode.Recursive
val folders = args.mapNotNull {
if (it.startsWith("-")) { // assume some arg
when (it) {
"--plain" -> mode = Mode.Plain
"--recursive" -> mode = Mode.Recursive
"--help" -> {
println("[...pathnames] [--recursive] [--plain]")
println("...pathnames - Pass any count of folder or files paths")
println("--recursive - (default) Use recursive visiting of folders for each path in pathnames")
println("--plain - (default) Use plain (non-recursive) visiting of folders for each path in pathnames")
}
}
null
} else {
File(it)
}
}.ifEmpty {
listOf(File("./"))
}
fun String.replaceVariables(variables: Map<String, String>): String {
var currentLine = this
variables.forEach { (k, v) ->
currentLine = currentLine.replace("\${${k}}", v)
if (k.matches(singleArgumentRegex)) {
currentLine = currentLine.replace("\$${k}", v)
}
}
return currentLine
}
fun generateFromTemplate(folder: File, file: File) {
val targetFile = File(folder, file.name.replace(templateOnlyEnding, ""))
val variables = mutableMapOf<String, String>()
var writeVariables = true
var text = ""
file.readLines().forEach { line ->
when {
writeVariables && line.startsWith("#") -> {
writeVariables = false
}
writeVariables -> {
val splitted = line.split(splitterRegex)
if (splitted.size > 1) {
val k = splitted[0]
val v = splitted[1].replaceVariables(variables)
variables[k] = v
}
return@forEach
}
}
text += line.let {
line.replaceVariables(variables) + "\n"
}
}
targetFile.writeText(text)
println("${targetFile.absolutePath} has been recreated")
}
if (args.none { it == "--help" }) {
folders.forEach { folder ->
mode.filesList(folder).forEach { file ->
if (file.name.contains(templateEnding)) {
generateFromTemplate(file.parentFile, file)
}
}
}
}

View File

@@ -10,7 +10,13 @@ nav:
- Home: 'index.md'
- 'MicroUtils':
- 'micro_utils/index.md'
- KDocs: 'https://microutils.inmo.dev/index.html'
- 'micro_utils/resources.md'
- 'micro_utils/startup.md'
- 'micro_utils/colors.md'
- 'Repos':
- 'micro_utils/repos/index.md'
- 'micro_utils/repos/inmemory.md'
- 'Telegram Bot API':
- 'tgbotapi/index.md'
- KDocs: 'https://tgbotapi.inmo.dev'
@@ -49,6 +55,7 @@ nav:
- 'kslog/setup.md'
- 'kslog/logging.md'
- 'Navigation':
- Sample: 'https://insanusmokrassar.github.io/navigation/'
- 'navigation/index.md'
- 'navigation/getting-started.md'
- 'Services':
@@ -85,7 +92,7 @@ theme:
- content.action.view
- content.code.annotate
- content.code.copy
# - content.tabs.link
- content.tabs.link
- content.tooltips
# - header.autohide
# - navigation.expand

870
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,13 +6,13 @@ authors = ["InsanusMokrassar"]
[tool.poetry.dependencies]
python = "^3.8"
mkdocs = "^1.5.3"
mkdocs = "^1.6.1"
markdown-callouts = "^0.4.0"
mkdocs-autorefs = "^0.5.0"
mkdocs-autorefs = "^1.2.0"
mkdocs-include-dir-to-nav = "^1.2.0"
mkdocs-material = "^9.5.6"
pymdown-extensions = "^10.7"
mkdocs-mermaid2-plugin = "^1.1.1"
mkdocs-material = "^9.6.17"
pymdown-extensions = "^10.6.1"
mkdocs-mermaid2-plugin = "^1.2.1"
[tool.poetry.dev-dependencies]

6
renovate.json Normal file
View File

@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
]
}