panko_serializer 0.8.4 → 1.0.0

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 (144) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -6
  3. data/lib/panko/array_serializer.rb +55 -16
  4. data/lib/panko/code_gen/active_record/access_classifier.rb +65 -0
  5. data/lib/panko/code_gen/active_record/define_attribute_methods.rb +13 -0
  6. data/lib/panko/code_gen/code_builder.rb +32 -0
  7. data/lib/panko/code_gen/compile_cache.rb +28 -0
  8. data/lib/panko/code_gen/compiler.rb +56 -0
  9. data/lib/panko/code_gen/config.rb +79 -0
  10. data/lib/panko/code_gen/datetime_format.rb +38 -0
  11. data/lib/panko/code_gen/descriptor.rb +136 -0
  12. data/lib/panko/code_gen/descriptor_builder.rb +166 -0
  13. data/lib/panko/code_gen/dump.rb +52 -0
  14. data/lib/panko/code_gen/errors.rb +21 -0
  15. data/lib/panko/code_gen/filter.rb +29 -0
  16. data/lib/panko/code_gen/filter_adapter.rb +44 -0
  17. data/lib/panko/code_gen/filters/indexed.rb +62 -0
  18. data/lib/panko/code_gen/filters/none.rb +19 -0
  19. data/lib/panko/code_gen/generator.rb +23 -0
  20. data/lib/panko/code_gen/generators/banner.rb +27 -0
  21. data/lib/panko/code_gen/generators/class_emitter.rb +120 -0
  22. data/lib/panko/code_gen/generators/cycle_membership.rb +53 -0
  23. data/lib/panko/code_gen/generators/descriptor_walk.rb +22 -0
  24. data/lib/panko/code_gen/generators/fanout.rb +60 -0
  25. data/lib/panko/code_gen/generators/field_index.rb +31 -0
  26. data/lib/panko/code_gen/generators/field_walk.rb +38 -0
  27. data/lib/panko/code_gen/generators/generated_names.rb +73 -0
  28. data/lib/panko/code_gen/generators/hash_sink.rb +217 -0
  29. data/lib/panko/code_gen/generators/json_sink.rb +290 -0
  30. data/lib/panko/code_gen/generators/record_access/generic.rb +92 -0
  31. data/lib/panko/code_gen/generators/record_access/specialized.rb +90 -0
  32. data/lib/panko/code_gen/generators/release.rb +60 -0
  33. data/lib/panko/code_gen/generators/sink.rb +80 -0
  34. data/lib/panko/code_gen/instance_pool.rb +27 -0
  35. data/lib/panko/code_gen/runtime.rb +27 -0
  36. data/lib/panko/code_gen/serializer_cache.rb +242 -0
  37. data/lib/panko/code_gen/validators/callable_arity.rb +42 -0
  38. data/lib/panko/code_gen/validators/name_uniqueness.rb +44 -0
  39. data/lib/panko/code_gen/validators/source_resolution.rb +48 -0
  40. data/lib/panko/code_gen/validators/validator.rb +19 -0
  41. data/lib/panko/code_gen/writers_pool.rb +51 -0
  42. data/lib/panko/code_gen.rb +82 -0
  43. data/lib/panko/compile_all.rb +80 -0
  44. data/lib/panko/compile_all_result.rb +21 -0
  45. data/lib/panko/config.rb +71 -0
  46. data/lib/panko/descriptor.rb +93 -0
  47. data/lib/panko/response.rb +40 -8
  48. data/lib/panko/serializer.rb +175 -91
  49. data/lib/panko/serializer_resolver.rb +2 -8
  50. data/lib/panko/version.rb +1 -1
  51. data/lib/panko_serializer.rb +3 -5
  52. metadata +49 -99
  53. data/.clang-format +0 -3
  54. data/.github/dependabot.yml +0 -6
  55. data/.github/workflows/database_matrix.yml +0 -85
  56. data/.github/workflows/docs.yml +0 -39
  57. data/.github/workflows/lint.yml +0 -30
  58. data/.github/workflows/tests.yml +0 -34
  59. data/.gitignore +0 -20
  60. data/.rspec +0 -2
  61. data/.rubocop.yml +0 -37
  62. data/Appraisals +0 -28
  63. data/Gemfile +0 -37
  64. data/Rakefile +0 -93
  65. data/benchmarks/BENCHMARKS.md +0 -48
  66. data/benchmarks/allocs.rb +0 -23
  67. data/benchmarks/app.rb +0 -11
  68. data/benchmarks/benchmarking_support.rb +0 -44
  69. data/benchmarks/bm_ams_0_10.rb +0 -43
  70. data/benchmarks/bm_object_writer.rb +0 -65
  71. data/benchmarks/bm_panko_json.rb +0 -60
  72. data/benchmarks/bm_panko_object.rb +0 -46
  73. data/benchmarks/bm_plain_object.rb +0 -99
  74. data/benchmarks/bm_serialization_descriptor.rb +0 -76
  75. data/benchmarks/bm_serializer_resolver.rb +0 -22
  76. data/benchmarks/bm_to_object.rb +0 -81
  77. data/benchmarks/profile.rb +0 -86
  78. data/benchmarks/sanity.rb +0 -83
  79. data/benchmarks/setup.rb +0 -56
  80. data/benchmarks/type_casts/bm_active_record.rb +0 -58
  81. data/benchmarks/type_casts/bm_panko.rb +0 -65
  82. data/benchmarks/type_casts/support.rb +0 -27
  83. data/docs/docs/associations.md +0 -107
  84. data/docs/docs/attributes.md +0 -150
  85. data/docs/docs/design-choices.md +0 -127
  86. data/docs/docs/getting-started.md +0 -70
  87. data/docs/docs/introduction.md +0 -13
  88. data/docs/docs/performance.md +0 -32
  89. data/docs/docs/response-bag.md +0 -83
  90. data/docs/docusaurus.config.js +0 -86
  91. data/docs/package-lock.json +0 -17872
  92. data/docs/package.json +0 -18
  93. data/docs/sidebars.json +0 -15
  94. data/docs/src/css/customTheme.css +0 -9
  95. data/docs/static/.DS_Store +0 -0
  96. data/docs/static/CNAME +0 -1
  97. data/docs/static/css/custom.css +0 -51
  98. data/docs/static/img/favicon.ico +0 -0
  99. data/docs/static/img/oss_logo.png +0 -0
  100. data/docs/static/img/undraw_code_review.svg +0 -1
  101. data/docs/static/img/undraw_monitor.svg +0 -1
  102. data/docs/static/img/undraw_note_list.svg +0 -1
  103. data/docs/static/img/undraw_online.svg +0 -1
  104. data/docs/static/img/undraw_open_source.svg +0 -1
  105. data/docs/static/img/undraw_operating_system.svg +0 -1
  106. data/docs/static/img/undraw_react.svg +0 -1
  107. data/docs/static/img/undraw_tweetstorm.svg +0 -1
  108. data/docs/static/img/undraw_youtube_tutorial.svg +0 -1
  109. data/docs/static/index.html +0 -14
  110. data/ext/panko_serializer/attributes_writer/active_record.c +0 -181
  111. data/ext/panko_serializer/attributes_writer/active_record.h +0 -17
  112. data/ext/panko_serializer/attributes_writer/attributes_writer.c +0 -55
  113. data/ext/panko_serializer/attributes_writer/attributes_writer.h +0 -35
  114. data/ext/panko_serializer/attributes_writer/common.c +0 -10
  115. data/ext/panko_serializer/attributes_writer/common.h +0 -9
  116. data/ext/panko_serializer/attributes_writer/hash.c +0 -13
  117. data/ext/panko_serializer/attributes_writer/hash.h +0 -7
  118. data/ext/panko_serializer/attributes_writer/plain.c +0 -13
  119. data/ext/panko_serializer/attributes_writer/plain.h +0 -7
  120. data/ext/panko_serializer/attributes_writer/type_cast/time_conversion.c +0 -156
  121. data/ext/panko_serializer/attributes_writer/type_cast/time_conversion.h +0 -10
  122. data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +0 -398
  123. data/ext/panko_serializer/attributes_writer/type_cast/type_cast.h +0 -81
  124. data/ext/panko_serializer/common.h +0 -9
  125. data/ext/panko_serializer/extconf.rb +0 -28
  126. data/ext/panko_serializer/panko_serializer.c +0 -181
  127. data/ext/panko_serializer/panko_serializer.h +0 -12
  128. data/ext/panko_serializer/serialization_descriptor/association.c +0 -90
  129. data/ext/panko_serializer/serialization_descriptor/association.h +0 -20
  130. data/ext/panko_serializer/serialization_descriptor/attribute.c +0 -96
  131. data/ext/panko_serializer/serialization_descriptor/attribute.h +0 -27
  132. data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.c +0 -177
  133. data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.h +0 -30
  134. data/gemfiles/7.2.0.gemfile +0 -41
  135. data/gemfiles/7.2.0.gemfile.lock +0 -221
  136. data/gemfiles/8.0.0.gemfile +0 -41
  137. data/gemfiles/8.0.0.gemfile.lock +0 -239
  138. data/gemfiles/8.1.0.gemfile +0 -41
  139. data/gemfiles/8.1.0.gemfile.lock +0 -248
  140. data/lib/panko/association.rb +0 -17
  141. data/lib/panko/attribute.rb +0 -29
  142. data/lib/panko/object_writer.rb +0 -68
  143. data/lib/panko/serialization_descriptor.rb +0 -180
  144. data/panko_serializer.gemspec +0 -36
@@ -1,70 +0,0 @@
1
- ---
2
- id: getting-started
3
- title: Getting Started
4
- sidebar_label: Getting Started
5
- ---
6
- ## Installation
7
-
8
- To install Panko, all you need is to add it to your Gemfile:
9
-
10
- ```ruby
11
-
12
- gem "panko_serializer"
13
-
14
- ```
15
-
16
- Then, install it on the command line:
17
-
18
- ```
19
-
20
- bundle install
21
-
22
- ```
23
-
24
- ## Creating your first serializer
25
-
26
- Let's create a serializer and use it inside of a Rails controller:
27
-
28
- ```ruby
29
- class PostSerializer < Panko::Serializer
30
- attributes :title
31
- end
32
-
33
- class UserSerializer < Panko::Serializer
34
- attributes :id, :name, :age
35
-
36
- has_many :posts, serializer: PostSerializer
37
- end
38
- ```
39
-
40
- ### Serializing an object
41
-
42
- And now serialize a single object:
43
-
44
- ```ruby
45
-
46
- # Using Oj serializer
47
- PostSerializer.new.serialize_to_json(Post.first)
48
-
49
- # or, similar to #serializable_hash
50
- PostSerializer.new.serialize(Post.first).to_json
51
-
52
- ```
53
-
54
- ### Using the serializers in a controller
55
-
56
- As you can see, defining serializers is simple and resembles ActiveModelSerializers 0.9.
57
- To utilize the `UserSerializer` inside a Rails controller and serialize some users, all we need to do is:
58
-
59
- ```ruby
60
-
61
- class UsersController < ApplicationController
62
- def index
63
- users = User.includes(:posts).all
64
- render json: Panko::ArraySerializer.new(users, each_serializer: UserSerializer).to_json
65
- end
66
- end
67
-
68
- ```
69
-
70
- And voila, we have an endpoint which serializes users using Panko!
@@ -1,13 +0,0 @@
1
- ---
2
- id: index
3
- title: Introduction
4
- sidebar_label: Introduction
5
- slug: /
6
- ---
7
- Panko is a library which is inspired by ActiveModelSerializers 0.9 for serializing ActiveRecord/Ruby objects to JSON strings, fast.
8
-
9
- To achieve it's [performance](https://panko.dev/performance/):
10
-
11
- - Oj - Panko relies on Oj since it's fast and allow to serialize incrementally using `Oj::StringWriter`.
12
- - Serialization Descriptor - Panko computes most of the metadata ahead of time, to save time later in serialization.
13
- - Type casting — Panko does type casting by itself, instead of relying on ActiveRecord.
@@ -1,32 +0,0 @@
1
- ---
2
- id: performance
3
- title: Performance
4
- sidebar_label: Performance
5
- ---
6
- The performance of Panko is measured using microbenchmarks and load testing.
7
-
8
- ## Microbenchmarks
9
-
10
- The following microbenchmarks are run on MacBook Pro (16-inch, 2021, M1 Max), Ruby 3.2.0 with Rails 7.0.5
11
- demonstrating the performance of ActiveModelSerializers 0.10.13 and Panko 0.8.0.
12
-
13
- | Benchmark | AMS ip/s | Panko ip/s |
14
- | ----------------- | -------- | ---------- |
15
- | Simple_Posts_2300 | 11.72 | 523.05 |
16
- | Simple_Posts_50 | 557.29 | 23,011.9 |
17
- | HasOne_Posts_2300 | 5.91 | 233.44 |
18
- | HasOne_Posts_50 | 285.8 | 10,362.79 |
19
-
20
- ## Real-world benchmark
21
-
22
- The real-world benchmark here is an endpoint which serializes 7,884 entries with 48 attributes and no associations.
23
- The benchmark took place in an environment that simulates production environment and run using `wrk` from machine on the same cluster.
24
-
25
- | Metric | AMS | Panko |
26
- | ------------------ | ----- | ----- |
27
- | Avg Response Time | 4.89s | 1.48s |
28
- | Max Response Time | 5.42s | 1.83s |
29
- | 99th Response Time | 5.42s | 1.74s |
30
- | Total Requests | 61 | 202 |
31
-
32
- _Thanks to [Bringg](https://www.bringg.com) for providing the infrastructure for the benchmarks._
@@ -1,83 +0,0 @@
1
- ---
2
- id: response-bag
3
- title: Response
4
- sidebar_label: Response
5
- ---
6
- Let's say you have some JSON payload which is constructed using Panko serialization result,
7
- like this:
8
-
9
- ```ruby
10
-
11
- class PostsController < ApplicationController
12
- def index
13
- posts = Post.all
14
- render json: {
15
- success: true,
16
- total_count: posts.count,
17
- posts: Panko::ArraySerializer.new(posts, each_serializer: PostSerializer).to_json
18
- }
19
- end
20
- end
21
-
22
- ```
23
-
24
- The output of the above will be a JSON string (for `posts`) inside a JSON string and this were `Panko::Response` shines.
25
-
26
- ```ruby
27
-
28
- class PostsController < ApplicationController
29
- def index
30
- posts = Post.all
31
- render json: Panko::Response.new(
32
- success: true,
33
- total_count: posts.count,
34
- posts: Panko::ArraySerializer.new(posts, each_serializer: PostSerializer)
35
- )
36
- end
37
- end
38
-
39
- ```
40
-
41
- And everything will work as expected!
42
-
43
- For a single object serialization, we need to use a different API (since `Panko::Serializer` doesn't accept an object in it's constructor):
44
-
45
- ```ruby
46
-
47
- class PostsController < ApplicationController
48
- def show
49
- post = Post.find(params[:id])
50
-
51
- render(
52
- json: Panko::Response.create do |r|
53
- {
54
- success: true,
55
- post: r.serializer(post, PostSerializer)
56
- }
57
- end
58
- )
59
- end
60
- end
61
-
62
- ```
63
-
64
- ## JsonValue
65
-
66
- Let's take the above example further, we will serialize the posts and cache it as JSON string in our Cache.
67
- Now, you can wrap the cached value with `Panko::JsonValue`, like here:
68
-
69
- ```ruby
70
-
71
- class PostsController < ApplicationController
72
- def index
73
- posts = Cache.get("/posts")
74
-
75
- render json: Panko::Response.new(
76
- success: true,
77
- total_count: posts.count,
78
- posts: Panko::JsonValue.from(posts)
79
- )
80
- end
81
- end
82
-
83
- ```
@@ -1,86 +0,0 @@
1
- module.exports = {
2
- "title": "Panko Serializers",
3
- "tagline": "High Performance JSON Serialization for ActiveRecord & Ruby Objects",
4
- "url": "https://panko.dev",
5
- "baseUrl": "/",
6
- "organizationName": "yosiat",
7
- "projectName": "panko_serializer",
8
- "favicon": "favicon.ico",
9
- "customFields": {
10
- "repoPath": "yosiat/panko_serializer",
11
- "repoUrl": "https://github.com/yosiat/panko_serializer",
12
- },
13
- "onBrokenLinks": "log",
14
- "onBrokenMarkdownLinks": "log",
15
- "presets": [
16
- [
17
- "@docusaurus/preset-classic",
18
- {
19
- "docs": {
20
- "path": "./docs",
21
- "showLastUpdateAuthor": false,
22
- "showLastUpdateTime": false,
23
- "sidebarPath": "./sidebars.json",
24
- "routeBasePath": process.env.NODE_ENV === 'production' ? '/docs' : '/',
25
- },
26
- "blog": false,
27
- "pages": false,
28
- "theme": {
29
- "customCss": "./src/css/customTheme.css"
30
- }
31
- }
32
- ]
33
- ],
34
- "plugins": [],
35
- "themeConfig": {
36
- colorMode: {
37
- defaultMode: 'light',
38
- disableSwitch: true,
39
- },
40
- "navbar": {
41
- "title": "Panko Serializers",
42
- "items": [
43
- {
44
- "to": "introduction",
45
- "label": "Docs",
46
- "position": "left"
47
- }
48
- ]
49
- },
50
- "image": "img/undraw_online.svg",
51
- "footer": {
52
- "links": [
53
- {
54
- title: "GitHub",
55
- items: [
56
- {
57
- label: "Repository",
58
- href: "https://github.com/yosiat/panko_serializer"
59
- },
60
- {
61
- label: "Discussions",
62
- href: "https://github.com/yosiat/panko_serializer/discussions"
63
- },
64
- {
65
- label: "Issues",
66
- href: "https://github.com/yosiat/panko_serializer/issues"
67
- },
68
- {
69
- "html": `
70
- <iframe
71
- src="https://ghbtns.com/github-btn.html?user=yosiat&amp;repo=panko_serializer&amp;type=star&amp;count=true&amp;size=medium"
72
- title="GitHub Stars"
73
- />`
74
- }
75
- ]
76
- }
77
- ],
78
- "copyright": `Copyright © ${new Date().getFullYear()} Panko Serializer`,
79
- },
80
- prism: {
81
- theme: require('prism-react-renderer').themes.github, // Optional: Customize theme
82
- darkTheme: require('prism-react-renderer').themes.dracula, // Optional: Dark theme
83
- additionalLanguages: ['ruby'], // Add Ruby as an additional language
84
- },
85
- }
86
- }