Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 45fb58a

Browse files
committed
chore: module names + documentation + name consistency
build: - renamed project to `cufyorg-serialization` - repository expected to be renamed to `cufyorg/serialization` - all subprojects are now prefixed with `cufyorg-` - pumbed dependency versions style: - split large files into smaller ones refactor: - bson Id renamed to ID with deprecated typealiases with the old names - removed unnecessary overloades perf: - inline everywhere
1 parent 51801a0 commit 45fb58a

67 files changed

Lines changed: 1663 additions & 1280 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Partial Encoding / Decoding (PED) [![](https://jitpack.io/v/org.cufy/ped.svg)](https://jitpack.io/#org.cufy/ped)
1+
# Cufyorg: Serialization (including: Partial Encoding / Decoding "PED") [![](https://jitpack.io/v/org.cufy/serialization.svg)](https://jitpack.io/#org.cufy/serialization)
22

33
Serialization Extensions and Serializers for enhancing partial encoding and decoding
44
that uses no object mapping.
@@ -17,9 +17,9 @@ repositories {
1717

1818
dependencies {
1919
// Replace TAG with the desired version
20-
implementation("org.cufy.ped:bson:TAG")
21-
implementation("org.cufy.ped:json:TAG")
22-
implementation("org.cufy.ped:ped-core:TAG")
23-
implementation("org.cufy.ped:ped-bson:TAG")
20+
implementation("org.cufy.serialization:cufyorg-bson:TAG")
21+
implementation("org.cufy.serialization:cufyorg-json:TAG")
22+
implementation("org.cufy.serialization:cufyorg-PED-core:TAG")
23+
implementation("org.cufy.serialization:cufyorg-PED-bson:TAG")
2424
}
2525
```

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tasks.wrapper {
1111
}
1212

1313
subprojects {
14-
group = "org.cufy.kped"
14+
group = "org.cufy.serialization"
1515

1616
repositories {
1717
mavenCentral()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ kotlin {
1212
sourceSets {
1313
commonMain {
1414
dependencies {
15-
implementation(project(":bson"))
16-
implementation(project(":ped-core"))
15+
implementation(project(":cufyorg-bson"))
16+
implementation(project(":cufyorg-PED-core"))
1717

1818
implementation(kotlin("stdlib"))
1919
implementation(libs.kotlin.serialization.json)

ped-bson/src/commonMain/kotlin/Bson.kt renamed to cufyorg-PED-bson/src/commonMain/kotlin/Bson.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,17 @@ object Bson {
8989
val ObjectId = BsonObjectIdCodec
9090

9191
/**
92-
* The codec for [Id] and [BsonObjectId] or [BsonString].
92+
* The codec for [ID] and [BsonObjectId] or [BsonString].
9393
*
9494
* @since 2.0.0
9595
*/
96-
val Id = BsonIdCodec
96+
@Deprecated("use ID instead", ReplaceWith("ID"))
97+
val Id = BsonIDCodec
98+
99+
/**
100+
* The codec for [ID] and [BsonObjectId] or [BsonString].
101+
*
102+
* @since 2.0.0
103+
*/
104+
val ID = BsonIDCodec
97105
}

ped-bson/src/commonMain/kotlin/BsonCodecs.kt renamed to cufyorg-PED-bson/src/commonMain/kotlin/BsonCodecs.kt

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import kotlin.Result.Companion.success
3333
* @since 2.0.0
3434
*/
3535
class BsonNullableCodec<I, O : BsonElement>(
36-
@Suppress("MemberVisibilityCanBePrivate")
3736
val codec: Codec<I, O>,
3837
) : NullableCodec<I, BsonElement> {
3938
override fun encode(value: Any?) =
@@ -77,7 +76,6 @@ val <I, O : BsonElement> FieldCodec<I, O>.Nullable: BsonNullableFieldCodec<I, Bs
7776
* individual item.
7877
*/
7978
class BsonArrayCodec<I, O : BsonElement>(
80-
@Suppress("MemberVisibilityCanBePrivate")
8179
val codec: Codec<I, O>,
8280
) : Codec<List<I>, BsonArray> {
8381
override fun encode(value: Any?) =
@@ -113,14 +111,6 @@ val <I, O : BsonElement> Codec<I, O>.Array: BsonArrayCodec<I, O>
113111
val <I, O : BsonElement> FieldCodec<I, O>.Array: BsonFieldCodec<List<I>, BsonArray>
114112
get() = FieldCodec(name, (this as Codec<I, O>).Array)
115113

116-
/**
117-
* Obtain a codec for [List] and [BsonArray] that
118-
* uses this codec to encode/decode each
119-
* individual item.
120-
*/
121-
val <I, O : BsonElement> BsonFieldCodec<I, O>.Array: BsonFieldCodec<List<I>, BsonArray>
122-
get() = FieldCodec(name, (this as Codec<I, O>).Array)
123-
124114
/* ============= ------------------ ============= */
125115

126116
/**
@@ -292,22 +282,25 @@ object BsonObjectIdCodec : Codec<ObjectId, BsonObjectId> {
292282

293283
/* ============= ------------------ ============= */
294284

285+
@Deprecated("use BsonIDCodec instead", ReplaceWith("BsonIDCodec"))
286+
typealias BsonIdCodec = BsonIDCodec
287+
295288
/**
296-
* The codec for [Id] and [BsonObjectId] or [BsonString].
289+
* The codec for [ID] and [BsonObjectId] or [BsonString].
297290
*
298291
* @since 2.0.0
299292
*/
300-
object BsonIdCodec : Codec<Id<*>, BsonElement> {
293+
object BsonIDCodec : Codec<ID<*>, BsonElement> {
301294
override fun encode(value: Any?) =
302-
tryInlineCodec(value) { it: Id<*> ->
295+
tryInlineCodec(value) { it: ID<*> ->
303296
success(it.bson)
304297
}
305298

306299
override fun decode(value: Any?) =
307300
tryInlineCodec(value) { it: BsonElement ->
308301
when (it) {
309-
is BsonObjectId -> success(Id<Any>(it.value))
310-
is BsonString -> success(Id(it.value))
302+
is BsonObjectId -> success(ID<Any>(it.value))
303+
is BsonString -> success(ID(it.value))
311304
else -> failure(
312305
CodecException(
313306
"Cannot decode ${it::class}; expected either " +
@@ -321,9 +314,9 @@ object BsonIdCodec : Codec<Id<*>, BsonElement> {
321314
/**
322315
* Return this codec casted to [T].
323316
*/
324-
operator fun <T> invoke(): Codec<Id<T>, BsonElement> {
317+
operator fun <T> invoke(): Codec<ID<T>, BsonElement> {
325318
@Suppress("UNCHECKED_CAST")
326-
return this as Codec<Id<T>, BsonElement>
319+
return this as Codec<ID<T>, BsonElement>
327320
}
328321
}
329322

@@ -355,9 +348,3 @@ class EnumCodec<I, O>(private val pairs: List<Pair<I, O>>) : Codec<I, O> {
355348
}
356349

357350
/* ============= ------------------ ============= */
358-
359-
inline operator fun <I> Codec<I, BsonDocument>.invoke(block: BsonDocumentBlock): I {
360-
return decode(BsonDocument(block), this)
361-
}
362-
363-
/* ============= ------------------ ============= */

ped-bson/src/commonMain/kotlin/BsonFieldCodec.kt renamed to cufyorg-PED-bson/src/commonMain/kotlin/BsonFieldCodec.kt

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package org.cufy.ped
1717

18-
import org.cufy.bson.BsonDocumentLike
1918
import org.cufy.bson.BsonElement
19+
import org.cufy.bson.DeprecatedWithContextParameters
2020
import org.cufy.bson.MutableBsonMapField
2121

2222
/* ============= ------------------ ============= */
@@ -43,6 +43,7 @@ import org.cufy.bson.MutableBsonMapField
4343
* @author LSafer
4444
* @since 2.0.0
4545
*/
46+
@DeprecatedWithContextParameters
4647
interface BsonFieldCodec<I, O : BsonElement> : FieldCodec<I, O>, MutableBsonMapField<I> {
4748
override fun encode(value: I): BsonElement =
4849
encode(value, this)
@@ -53,6 +54,7 @@ interface BsonFieldCodec<I, O : BsonElement> : FieldCodec<I, O>, MutableBsonMapF
5354
* and backed by the given [codec].
5455
*/
5556
@Suppress("FunctionName")
57+
@DeprecatedWithContextParameters
5658
fun <I, O : BsonElement> FieldCodec(name: String, codec: Codec<I, O>): BsonFieldCodec<I, O> {
5759
return object : BsonFieldCodec<I, O>, Codec<I, O> by codec {
5860
override val name = name
@@ -64,7 +66,8 @@ fun <I, O : BsonElement> FieldCodec(name: String, codec: Codec<I, O>): BsonField
6466
/**
6567
* Return a new codec backed by this codec that returns the given [defaultValue] when decoding fails.
6668
*/
67-
@PedMarker3
69+
@PEDMarker3
70+
@DeprecatedWithContextParameters
6871
infix fun <I, O : BsonElement> BsonFieldCodec<I, O>.defaultIn(defaultValue: I): BsonFieldCodec<I, O> {
6972
val codec = this as Codec<I, O>
7073
return FieldCodec(name, codec defaultIn defaultValue)
@@ -73,7 +76,8 @@ infix fun <I, O : BsonElement> BsonFieldCodec<I, O>.defaultIn(defaultValue: I):
7376
/**
7477
* Return a new codec backed by this codec that returns the result of invoking the given [block] when decoding fails.
7578
*/
76-
@PedMarker3
79+
@PEDMarker3
80+
@DeprecatedWithContextParameters
7781
infix fun <I, O : BsonElement> BsonFieldCodec<I, O>.catchIn(block: (Throwable) -> I): BsonFieldCodec<I, O> {
7882
val codec = this as Codec<I, O>
7983
return FieldCodec(name, codec catchIn block)
@@ -82,7 +86,8 @@ infix fun <I, O : BsonElement> BsonFieldCodec<I, O>.catchIn(block: (Throwable) -
8286
/**
8387
* Return a new codec backed by this codec that returns the given [defaultValue] when encoding fails.
8488
*/
85-
@PedMarker3
89+
@PEDMarker3
90+
@DeprecatedWithContextParameters
8691
infix fun <I, O : BsonElement> BsonFieldCodec<I, O>.defaultOut(defaultValue: O): BsonFieldCodec<I, O> {
8792
val codec = this as Codec<I, O>
8893
return FieldCodec(name, codec defaultOut defaultValue)
@@ -91,29 +96,21 @@ infix fun <I, O : BsonElement> BsonFieldCodec<I, O>.defaultOut(defaultValue: O):
9196
/**
9297
* Return a new codec backed by this codec that returns the result of invoking the given [block] when encoding fails.
9398
*/
94-
@PedMarker3
99+
@PEDMarker3
100+
@DeprecatedWithContextParameters
95101
infix fun <I, O : BsonElement> BsonFieldCodec<I, O>.catchOut(block: (Throwable) -> O): BsonFieldCodec<I, O> {
96102
val codec = this as Codec<I, O>
97103
return FieldCodec(name, codec catchOut block)
98104
}
99105

100106
/* ============= ------------------ ============= */
101107

102-
/**
103-
* Return a field codec derived from this one with
104-
* its name tagged with the given language [tag].
105-
*/
106-
@PedMarker3
107-
infix fun <I, O : BsonElement> BsonFieldCodec<I, O>.lang(tag: String): BsonFieldCodec<I, O> {
108-
if (tag.isEmpty()) return this
109-
return FieldCodec("$name#$tag", this)
110-
}
111-
112108
/**
113109
* Create a new field codec with the given [name]
114110
* and backed by [this] codec.
115111
*/
116-
@PedMarker3
112+
@PEDMarker3
113+
@DeprecatedWithContextParameters
117114
infix fun <I, O : BsonElement> Codec<I, O>.at(name: String): BsonFieldCodec<I, O> {
118115
return FieldCodec(name, this)
119116
}
@@ -131,18 +128,10 @@ infix fun <I, O : BsonElement> Codec<I, O>.at(name: String): BsonFieldCodec<I, O
131128
* }
132129
* ```
133130
*/
134-
@PedMarker3
131+
@PEDMarker3
132+
@DeprecatedWithContextParameters
135133
infix fun <I, O : BsonElement> String.be(codec: Codec<I, O>): BsonFieldCodec<I, O> {
136134
return FieldCodec(this, codec)
137135
}
138136

139-
/**
140-
* Get the value of the field with the name of the
141-
* given [codec] and decode it using the given [codec].
142-
*/
143-
operator fun <I> BsonDocumentLike.get(codec: FieldCodec<I, out BsonElement>): I {
144-
val element = this[codec.name]
145-
return decodeAny(element, codec)
146-
}
147-
148137
/* ============= ------------------ ============= */

ped-bson/src/commonMain/kotlin/BsonNullableFieldCodec.kt renamed to cufyorg-PED-bson/src/commonMain/kotlin/BsonNullableFieldCodec.kt

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.cufy.ped
1717

1818
import org.cufy.bson.BsonElement
19+
import org.cufy.bson.DeprecatedWithContextParameters
1920
import org.cufy.bson.MutableBsonMapField
2021

2122
/* ============= ------------------ ============= */
@@ -42,13 +43,15 @@ import org.cufy.bson.MutableBsonMapField
4243
* @author LSafer
4344
* @since 2.0.0
4445
*/
46+
@DeprecatedWithContextParameters
4547
interface BsonNullableFieldCodec<I, O : BsonElement> : NullableFieldCodec<I, O>, BsonFieldCodec<I?, O>
4648

4749
/**
4850
* Create a new field codec with the given [name]
4951
* and backed by the given [codec].
5052
*/
5153
@Suppress("FunctionName")
54+
@DeprecatedWithContextParameters
5255
fun <I, O : BsonElement> FieldCodec(name: String, codec: NullableCodec<I, O>): BsonNullableFieldCodec<I, O> {
5356
return object : BsonNullableFieldCodec<I, O>, NullableCodec<I, O> by codec {
5457
override val name = name
@@ -60,7 +63,8 @@ fun <I, O : BsonElement> FieldCodec(name: String, codec: NullableCodec<I, O>): B
6063
/**
6164
* Return a new codec backed by this codec that returns the given [defaultValue] when decoding fails.
6265
*/
63-
@PedMarker3
66+
@PEDMarker3
67+
@DeprecatedWithContextParameters
6468
infix fun <I, O : BsonElement> BsonNullableFieldCodec<I, O>.defaultIn(defaultValue: I): BsonNullableFieldCodec<I, O> {
6569
val codec = this as NullableCodec<I, O>
6670
return FieldCodec(name, codec defaultIn defaultValue)
@@ -69,7 +73,8 @@ infix fun <I, O : BsonElement> BsonNullableFieldCodec<I, O>.defaultIn(defaultVal
6973
/**
7074
* Return a new codec backed by this codec that returns the result of invoking the given [block] when decoding fails.
7175
*/
72-
@PedMarker3
76+
@PEDMarker3
77+
@DeprecatedWithContextParameters
7378
infix fun <I, O : BsonElement> BsonNullableFieldCodec<I, O>.catchIn(block: (Throwable) -> I): BsonNullableFieldCodec<I, O> {
7479
val codec = this as NullableCodec<I, O>
7580
return FieldCodec(name, codec catchIn block)
@@ -78,7 +83,8 @@ infix fun <I, O : BsonElement> BsonNullableFieldCodec<I, O>.catchIn(block: (Thro
7883
/**
7984
* Return a new codec backed by this codec that returns the given [defaultValue] when encoding fails.
8085
*/
81-
@PedMarker3
86+
@PEDMarker3
87+
@DeprecatedWithContextParameters
8288
infix fun <I, O : BsonElement> BsonNullableFieldCodec<I, O>.defaultOut(defaultValue: O): BsonNullableFieldCodec<I, O> {
8389
val codec = this as NullableCodec<I, O>
8490
return FieldCodec(name, codec defaultOut defaultValue)
@@ -87,29 +93,21 @@ infix fun <I, O : BsonElement> BsonNullableFieldCodec<I, O>.defaultOut(defaultVa
8793
/**
8894
* Return a new codec backed by this codec that returns the result of invoking the given [block] when encoding fails.
8995
*/
90-
@PedMarker3
96+
@PEDMarker3
97+
@DeprecatedWithContextParameters
9198
infix fun <I, O : BsonElement> BsonNullableFieldCodec<I, O>.catchOut(block: (Throwable) -> O): BsonNullableFieldCodec<I, O> {
9299
val codec = this as NullableCodec<I, O>
93100
return FieldCodec(name, codec catchOut block)
94101
}
95102

96103
/* ============= ------------------ ============= */
97104

98-
/**
99-
* Return a field codec derived from this one with
100-
* its name tagged with the given language [tag].
101-
*/
102-
@PedMarker3
103-
infix fun <I, O : BsonElement> BsonNullableFieldCodec<I, O>.lang(tag: String): BsonNullableFieldCodec<I, O> {
104-
if (tag.isEmpty()) return this
105-
return FieldCodec("$name#$tag", this)
106-
}
107-
108105
/**
109106
* Create a new field codec with the given [name]
110107
* and backed by [this] codec.
111108
*/
112-
@PedMarker3
109+
@PEDMarker3
110+
@DeprecatedWithContextParameters
113111
infix fun <I, O : BsonElement> NullableCodec<I, O>.at(name: String): BsonNullableFieldCodec<I, O> {
114112
return FieldCodec(name, this)
115113
}
@@ -127,7 +125,8 @@ infix fun <I, O : BsonElement> NullableCodec<I, O>.at(name: String): BsonNullabl
127125
* }
128126
* ```
129127
*/
130-
@PedMarker3
128+
@PEDMarker3
129+
@DeprecatedWithContextParameters
131130
infix fun <I, O : BsonElement> String.be(codec: NullableCodec<I, O>): BsonNullableFieldCodec<I, O> {
132131
return FieldCodec(this, codec)
133132
}

0 commit comments

Comments
 (0)