encoded_id 1.0.0.rc7 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/lib/encoded_id/encoders/base_configuration.rb +11 -20
- data/lib/encoded_id/encoders/hashid_configuration.rb +1 -8
- data/lib/encoded_id/encoders/sqids.rb +1 -4
- data/lib/encoded_id/encoders/sqids_configuration.rb +0 -5
- data/lib/encoded_id/encoders/sqids_with_blocklist_mode.rb +1 -3
- data/lib/encoded_id/reversible_id.rb +12 -41
- data/lib/encoded_id/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ccfa7987d3a108bfce0268467b8ae40793226e98f01fa2c331bc1f642026f47b
|
|
4
|
+
data.tar.gz: b4cb2429a8031f0e576f242550397b4683e302a184d57f0c85b870da502e181e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db4ae0c6d8477ea3ab5ada1bcbd959b18420c1aa1be54ec747898d298f16e6dd6a2090ff4a18008fe1711d3641c158bf9a8c1da23a33663be7fbc17a68079409
|
|
7
|
+
data.tar.gz: 4e731df7f992cf6935012cabffc7c6d4923de5db46059c123780d0f6a1dfbe329844ddf074580c67ec1a16101afb9c315175049045bcf5375e6666ae2707fa0b
|
data/CHANGELOG.md
CHANGED
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
- nothing yet
|
|
4
4
|
|
|
5
|
-
## [1.0.0] -
|
|
5
|
+
## [1.0.0] - 2025-11-21
|
|
6
6
|
|
|
7
7
|
- First stable release!
|
|
8
8
|
|
|
9
9
|
**Important!!: `:sqids` are not compatible with `:hashids`, DO NOT CHANGE FROM ONE TO THE OTHER AFTER GOING LIVE.**
|
|
10
10
|
|
|
11
|
+
### Fixed (Rails integration)
|
|
12
|
+
|
|
13
|
+
- Ensure finder methods correctly override their ActiveRecord counterparts
|
|
14
|
+
- Warn when ActiveRecord integration used in model that doesn't use `id` as primary key
|
|
15
|
+
|
|
11
16
|
## [1.0.0.rc7] - 2025-11-19
|
|
12
17
|
|
|
13
18
|
### Breaking changes
|
|
@@ -7,20 +7,16 @@ module EncodedId
|
|
|
7
7
|
# Base configuration class for encoder-specific settings
|
|
8
8
|
# This provides common parameters shared across all encoders
|
|
9
9
|
class BaseConfiguration
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
attr_reader :min_length, :alphabet, :split_at, :split_with,
|
|
22
|
-
:hex_digit_encoding_group_size, :max_length,
|
|
23
|
-
:max_inputs_per_id, :blocklist, :blocklist_mode, :blocklist_max_length
|
|
10
|
+
attr_reader :min_length #: Integer
|
|
11
|
+
attr_reader :alphabet #: Alphabet
|
|
12
|
+
attr_reader :split_at #: Integer?
|
|
13
|
+
attr_reader :split_with #: String?
|
|
14
|
+
attr_reader :hex_digit_encoding_group_size #: Integer
|
|
15
|
+
attr_reader :max_length #: Integer?
|
|
16
|
+
attr_reader :max_inputs_per_id #: Integer
|
|
17
|
+
attr_reader :blocklist #: Blocklist
|
|
18
|
+
attr_reader :blocklist_mode #: Symbol
|
|
19
|
+
attr_reader :blocklist_max_length #: Integer
|
|
24
20
|
|
|
25
21
|
# @rbs (?min_length: Integer, ?alphabet: Alphabet, ?split_at: Integer?, ?split_with: String?, ?hex_digit_encoding_group_size: Integer, ?max_length: Integer?, ?max_inputs_per_id: Integer, ?blocklist: Blocklist | Array[String] | Set[String] | nil, ?blocklist_mode: Symbol, ?blocklist_max_length: Integer) -> void
|
|
26
22
|
def initialize(
|
|
@@ -49,12 +45,7 @@ module EncodedId
|
|
|
49
45
|
validate_blocklist_collision_risk
|
|
50
46
|
end
|
|
51
47
|
|
|
52
|
-
# @rbs () ->
|
|
53
|
-
def encoder_type
|
|
54
|
-
raise NotImplementedError, "Subclasses must implement encoder_type"
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# @rbs () -> untyped
|
|
48
|
+
# @rbs () -> (Hashid | Sqids)
|
|
58
49
|
def create_encoder
|
|
59
50
|
raise NotImplementedError, "Subclasses must implement create_encoder"
|
|
60
51
|
end
|
|
@@ -7,9 +7,7 @@ module EncodedId
|
|
|
7
7
|
# Configuration for Hashids encoder
|
|
8
8
|
# Hashids requires a salt for encoding/decoding
|
|
9
9
|
class HashidConfiguration < BaseConfiguration
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
attr_reader :salt
|
|
10
|
+
attr_reader :salt #: String
|
|
13
11
|
|
|
14
12
|
# @rbs (salt: String, **untyped options) -> void
|
|
15
13
|
def initialize(salt:, **options)
|
|
@@ -17,11 +15,6 @@ module EncodedId
|
|
|
17
15
|
super(**options)
|
|
18
16
|
end
|
|
19
17
|
|
|
20
|
-
# @rbs () -> Symbol
|
|
21
|
-
def encoder_type
|
|
22
|
-
:hashids
|
|
23
|
-
end
|
|
24
|
-
|
|
25
18
|
# Create the Hashid encoder instance
|
|
26
19
|
# @rbs () -> Hashid
|
|
27
20
|
def create_encoder
|
|
@@ -6,10 +6,7 @@ module EncodedId
|
|
|
6
6
|
module Encoders
|
|
7
7
|
# Encoder implementation using the Sqids algorithm for encoding/decoding IDs.
|
|
8
8
|
class Sqids
|
|
9
|
-
# @rbs @sqids:
|
|
10
|
-
# @rbs @min_hash_length: Integer
|
|
11
|
-
# @rbs @alphabet: Alphabet
|
|
12
|
-
# @rbs @blocklist: Blocklist
|
|
9
|
+
# @rbs @sqids: SqidsWithBlocklistMode
|
|
13
10
|
# @rbs @blocklist_mode: Symbol
|
|
14
11
|
# @rbs @blocklist_max_length: Integer
|
|
15
12
|
|
|
@@ -7,11 +7,6 @@ module EncodedId
|
|
|
7
7
|
# Configuration for Sqids encoder
|
|
8
8
|
# Sqids does not use a salt - it shuffles the alphabet deterministically
|
|
9
9
|
class SqidsConfiguration < BaseConfiguration
|
|
10
|
-
# @rbs () -> Symbol
|
|
11
|
-
def encoder_type
|
|
12
|
-
:sqids
|
|
13
|
-
end
|
|
14
|
-
|
|
15
10
|
# Create the Sqids encoder instance
|
|
16
11
|
# @rbs () -> Sqids
|
|
17
12
|
def create_encoder
|
|
@@ -44,10 +44,8 @@ class SqidsWithBlocklistMode < MySqids
|
|
|
44
44
|
true
|
|
45
45
|
when :length_threshold
|
|
46
46
|
id.length <= @blocklist_max_length
|
|
47
|
-
when :raise_if_likely
|
|
48
|
-
# This mode raises at configuration time, so if we get here, we check
|
|
49
|
-
true
|
|
50
47
|
else
|
|
48
|
+
# If :raise_if_likely mode it raises at configuration time, so if we get here, we check
|
|
51
49
|
true
|
|
52
50
|
end
|
|
53
51
|
end
|
|
@@ -10,10 +10,6 @@ module EncodedId
|
|
|
10
10
|
# type encodeableValue = Array[String | Integer] | String | Integer
|
|
11
11
|
|
|
12
12
|
class ReversibleId
|
|
13
|
-
# @rbs @config: Encoders::BaseConfiguration
|
|
14
|
-
# @rbs @hex_represention_encoder: HexRepresentation
|
|
15
|
-
# @rbs @encoder: untyped
|
|
16
|
-
|
|
17
13
|
# Factory method to create a Hashid-based reversible ID
|
|
18
14
|
# @rbs (salt: String, **untyped options) -> ReversibleId
|
|
19
15
|
def self.hashid(salt:, **options)
|
|
@@ -40,40 +36,13 @@ module EncodedId
|
|
|
40
36
|
@encoder = create_encoder
|
|
41
37
|
end
|
|
42
38
|
|
|
43
|
-
#
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
nil
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def min_length
|
|
51
|
-
@config.min_length
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def alphabet
|
|
55
|
-
@config.alphabet
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def split_at
|
|
59
|
-
@config.split_at
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def split_with
|
|
63
|
-
@config.split_with
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
attr_reader :hex_represention_encoder
|
|
67
|
-
|
|
68
|
-
def max_length
|
|
69
|
-
@config.max_length
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def blocklist
|
|
73
|
-
@config.blocklist
|
|
74
|
-
end
|
|
39
|
+
# The configuration object for this encoder instance.
|
|
40
|
+
# Returns either an Encoders::HashidConfiguration or Encoders::SqidsConfiguration.
|
|
41
|
+
# Useful for introspecting settings like alphabet, min_length, blocklist, etc.
|
|
42
|
+
attr_reader :config #: Encoders::BaseConfiguration
|
|
75
43
|
|
|
76
|
-
attr_reader :
|
|
44
|
+
attr_reader :hex_represention_encoder #: HexRepresentation
|
|
45
|
+
attr_reader :encoder #: Encoders::Hashid | Encoders::Sqids
|
|
77
46
|
|
|
78
47
|
# Encode the input values into a hash
|
|
79
48
|
# @rbs (encodeableValue values) -> String
|
|
@@ -122,7 +91,7 @@ module EncodedId
|
|
|
122
91
|
inputs
|
|
123
92
|
end
|
|
124
93
|
|
|
125
|
-
# @rbs () ->
|
|
94
|
+
# @rbs () -> (Encoders::Hashid | Encoders::Sqids)
|
|
126
95
|
def create_encoder
|
|
127
96
|
@config.create_encoder
|
|
128
97
|
end
|
|
@@ -150,7 +119,8 @@ module EncodedId
|
|
|
150
119
|
# Reverses humanize_length transformation: removes separators and optionally downcases
|
|
151
120
|
# @rbs (String str, bool downcase) -> String
|
|
152
121
|
def convert_to_hash(str, downcase)
|
|
153
|
-
|
|
122
|
+
split_with = @config.split_with
|
|
123
|
+
str = str.gsub(split_with, "") if split_with
|
|
154
124
|
str = str.downcase if downcase
|
|
155
125
|
map_equivalent_characters(str)
|
|
156
126
|
end
|
|
@@ -169,9 +139,10 @@ module EncodedId
|
|
|
169
139
|
|
|
170
140
|
# @rbs (String str) -> bool
|
|
171
141
|
def max_length_exceeded?(str)
|
|
172
|
-
|
|
142
|
+
max_len = @config.max_length
|
|
143
|
+
return false unless max_len
|
|
173
144
|
|
|
174
|
-
str.length >
|
|
145
|
+
str.length > max_len
|
|
175
146
|
end
|
|
176
147
|
end
|
|
177
148
|
end
|
data/lib/encoded_id/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: encoded_id
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.0
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stephen Ierodiaconou
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-11-
|
|
10
|
+
date: 2025-11-21 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: sqids
|