skir-java-gen 1.0.4 → 1.0.5

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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -10
  3. package/package.json +13 -9
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Tyler Fibonacci
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.
package/README.md CHANGED
@@ -206,12 +206,12 @@ System.out.println(john.subscriptionStatus().accept(infoTextVisitor));
206
206
  Every frozen struct class and enum class has a static readonly `SERIALIZER` property which can be used for serializing and deserializing instances of the class.
207
207
 
208
208
  ```java
209
- // Serialize 'john' to dense JSON.
210
-
211
209
  final Serializer<User> serializer = User.SERIALIZER;
212
210
 
213
- System.out.println(serializer.toJsonCode(john));
214
- // [42,"John Doe","Coffee is just a socially acceptable form of rage.",[["Dumbo",1.0,"🐘"]],[1]]
211
+ // Serialize 'john' to dense JSON.
212
+ final String johnDenseJson = serializer.toJsonCode(john);
213
+ System.out.println(johnDenseJson);
214
+ // [42,"John Doe",...]
215
215
 
216
216
  // Serialize 'john' to readable JSON.
217
217
  System.out.println(serializer.toJsonCode(john, JsonFlavor.READABLE));
@@ -236,7 +236,8 @@ System.out.println(serializer.toJsonCode(john, JsonFlavor.READABLE));
236
236
  // You should pick the readable flavor mostly for debugging purposes.
237
237
 
238
238
  // Serialize 'john' to binary format.
239
- System.out.println(serializer.toBytes(john));
239
+ final ByteString johnBytes = serializer.toBytes(john);
240
+ System.out.println(johnBytes);
240
241
 
241
242
  // The binary format is not human readable, but it is slightly more compact
242
243
  // than JSON, and serialization/deserialization can be a bit faster in
@@ -249,8 +250,7 @@ System.out.println(serializer.toBytes(john));
249
250
  ```java
250
251
  // Use fromJson(), fromJsonCode() and fromBytes() to deserialize.
251
252
 
252
- final User reserializedJohn =
253
- serializer.fromJsonCode(serializer.toJsonCode(john));
253
+ final User reserializedJohn = serializer.fromJsonCode(johnDenseJson);
254
254
  assert reserializedJohn.equals(john);
255
255
 
256
256
  final User reserializedEvilJohn =
@@ -259,9 +259,42 @@ final User reserializedEvilJohn =
259
259
  serializer.toJsonCode(john, JsonFlavor.READABLE));
260
260
  assert reserializedEvilJohn.equals(evilJohn);
261
261
 
262
- final User reserializedJane =
263
- serializer.fromBytes(serializer.toBytes(jane));
264
- assert reserializedJane.equals(jane);
262
+ assert serializer.fromBytes(johnBytes).equals(john);
263
+ ```
264
+
265
+ ### Primitive serializers
266
+
267
+ ```java
268
+ assert Serializers.bool().toJsonCode(true).equals("1");
269
+ assert Serializers.int32().toJsonCode(3).equals("3");
270
+ assert Serializers.int64().toJsonCode(9223372036854775807L).equals("\"9223372036854775807\"");
271
+ assert Serializers.javaHash64()
272
+ .toJsonCode(new BigInteger("18446744073709551615"))
273
+ .equals("\"18446744073709551615\"");
274
+ assert Serializers.timestamp()
275
+ .toJsonCode(Instant.ofEpochMilli(1743682787000L))
276
+ .equals("1743682787000");
277
+ assert Serializers.float32().toJsonCode(3.14f).equals("3.14");
278
+ assert Serializers.float64().toJsonCode(3.14).equals("3.14");
279
+ assert Serializers.string().toJsonCode("Foo").equals("\"Foo\"");
280
+ assert Serializers.bytes()
281
+ .toJsonCode(ByteString.of((byte) 1, (byte) 2, (byte) 3))
282
+ .equals("\"AQID\"");
283
+ ```
284
+
285
+ ### Composite serializers
286
+
287
+ ```java
288
+ assert Serializers.javaOptional(Serializers.string())
289
+ .toJsonCode(java.util.Optional.of("foo"))
290
+ .equals("\"foo\"");
291
+ assert Serializers.javaOptional(Serializers.string())
292
+ .toJsonCode(java.util.Optional.empty())
293
+ .equals("null");
294
+
295
+ assert Serializers.list(Serializers.bool()) //
296
+ .toJsonCode(List.of(true, false))
297
+ .equals("[1,0]");
265
298
  ```
266
299
 
267
300
  ### Frozen lists and copies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skir-java-gen",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -33,24 +33,28 @@
33
33
  "lint:fix": "eslint src/**/*.ts --fix"
34
34
  },
35
35
  "dependencies": {
36
- "skir-internal": "^0.1.0",
36
+ "skir-internal": "^0.1.1",
37
37
  "zod": "^4.2.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@eslint/js": "^9.39.2",
41
- "@types/mocha": "^10.0.1",
40
+ "@eslint/js": "^10.0.1",
41
+ "@types/mocha": "^10.0.10",
42
42
  "@types/node": "^20.6.0",
43
- "@typescript-eslint/eslint-plugin": "^8.50.1",
44
- "@typescript-eslint/parser": "^8.50.1",
43
+ "@typescript-eslint/eslint-plugin": "^8.56.0",
44
+ "@typescript-eslint/parser": "^8.56.0",
45
45
  "buckwheat": "^1.1.2",
46
- "eslint": "^9.39.2",
46
+ "eslint": "^10.0.1",
47
47
  "mocha": "^11.7.5",
48
48
  "prettier": "^3.2.4",
49
49
  "prettier-plugin-organize-imports": "^4.2.0",
50
- "skir": "^1.0.20",
50
+ "skir": "^1.0.25",
51
51
  "ts-node": "^10.9.2",
52
52
  "tsx": "^4.21.0",
53
53
  "typescript": "^5.2.2",
54
- "typescript-eslint": "^8.50.1"
54
+ "typescript-eslint": "^8.56.0"
55
+ },
56
+ "overrides": {
57
+ "diff": "^8.0.3",
58
+ "minimatch": "^10.2.2"
55
59
  }
56
60
  }