js-routes 2.2.3 → 2.2.4
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 +5 -0
- data/Readme.md +1 -1
- data/lib/js_routes/generators/middleware.rb +1 -1
- data/lib/js_routes/instance.rb +1 -1
- data/lib/js_routes/middleware.rb +6 -2
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.d.ts +1 -0
- data/lib/routes.js +13 -2
- data/lib/routes.ts +12 -2
- data/spec/js_routes/default_serializer_spec.rb +4 -4
- data/spec/js_routes/module_types/amd_spec.rb +1 -1
- data/spec/js_routes/module_types/cjs_spec.rb +1 -1
- data/spec/js_routes/module_types/dts/routes.spec.d.ts +1 -0
- data/spec/js_routes/module_types/esm_spec.rb +2 -2
- data/spec/js_routes/module_types/nil_spec.rb +7 -7
- data/spec/js_routes/options_spec.rb +79 -79
- data/spec/js_routes/rails_routes_compatibility_spec.rb +123 -136
- data/spec/js_routes/route_specification_spec.rb +40 -0
- data/spec/spec_helper.rb +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66ff94f5c78d966f76e2a9f47d1c838c757c3e243c37f03599b24c286b15b9b7
|
4
|
+
data.tar.gz: c5803e4a35b99923769970149f07a6893a84c6343f10f76c8a89645974dce959
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a34c75f950a02a6634687889e4072f7d88f37520a6dc2ba5bfd2ccbbb71962159a70170bf7ac55b22db45de2727f7c573dfce8c80debc33f34abbd9cb1132c1f
|
7
|
+
data.tar.gz: 779b340c9dac721c8b427a16011ed961a05dde4d15594838649fb0860bac42e60344a682718a0b94f35f785350126ca59c7f739dac43cb47e0a7b84e45fa468a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## master
|
2
2
|
|
3
|
+
## v2.2.5
|
4
|
+
|
5
|
+
* Fix middleware generator [#300](https://github.com/railsware/js-routes/issues/300)
|
6
|
+
* Support `params` special parameter
|
7
|
+
|
3
8
|
## v2.2.4
|
4
9
|
|
5
10
|
* Fix rails engine loading if sprockets is not in Gemfile. Fixes [#294](https://github.com/railsware/js-routes/issues/294)
|
data/Readme.md
CHANGED
data/lib/js_routes/instance.rb
CHANGED
data/lib/js_routes/middleware.rb
CHANGED
@@ -21,12 +21,16 @@ module JsRoutes
|
|
21
21
|
def update_js_routes
|
22
22
|
new_mtime = routes_mtime
|
23
23
|
unless new_mtime == @mtime
|
24
|
-
|
25
|
-
JsRoutes.definitions!
|
24
|
+
regenerate
|
26
25
|
@mtime = new_mtime
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
29
|
+
def regenerate
|
30
|
+
JsRoutes.generate!
|
31
|
+
JsRoutes.definitions!
|
32
|
+
end
|
33
|
+
|
30
34
|
def routes_mtime
|
31
35
|
File.mtime(@routes_file)
|
32
36
|
rescue Errno::ENOENT
|
data/lib/js_routes/version.rb
CHANGED
data/lib/routes.d.ts
CHANGED
@@ -53,6 +53,7 @@ declare type KeywordUrlOptions = Optional<{
|
|
53
53
|
port: string | number;
|
54
54
|
anchor: string;
|
55
55
|
trailing_slash: boolean;
|
56
|
+
params: RouteParameters;
|
56
57
|
}>;
|
57
58
|
declare type RouteOptions = KeywordUrlOptions & RouteParameters;
|
58
59
|
declare type PartsTable = Record<string, {
|
data/lib/routes.js
CHANGED
@@ -222,12 +222,23 @@ RubyVariables.WRAPPER(() => {
|
|
222
222
|
...options,
|
223
223
|
};
|
224
224
|
const keyword_parameters = {};
|
225
|
-
|
225
|
+
let query_parameters = {};
|
226
226
|
for (const key in options) {
|
227
227
|
if (!hasProp(options, key))
|
228
228
|
continue;
|
229
229
|
const value = options[key];
|
230
|
-
if (
|
230
|
+
if (key === "params") {
|
231
|
+
if (this.is_object(value)) {
|
232
|
+
query_parameters = {
|
233
|
+
...query_parameters,
|
234
|
+
...value,
|
235
|
+
};
|
236
|
+
}
|
237
|
+
else {
|
238
|
+
throw new Error("params value should always be an object");
|
239
|
+
}
|
240
|
+
}
|
241
|
+
else if (this.is_reserved_option(key)) {
|
231
242
|
keyword_parameters[key] = value;
|
232
243
|
}
|
233
244
|
else {
|
data/lib/routes.ts
CHANGED
@@ -70,6 +70,7 @@ type KeywordUrlOptions = Optional<{
|
|
70
70
|
port: string | number;
|
71
71
|
anchor: string;
|
72
72
|
trailing_slash: boolean;
|
73
|
+
params: RouteParameters;
|
73
74
|
}>;
|
74
75
|
|
75
76
|
type RouteOptions = KeywordUrlOptions & RouteParameters;
|
@@ -365,11 +366,20 @@ RubyVariables.WRAPPER(
|
|
365
366
|
};
|
366
367
|
|
367
368
|
const keyword_parameters: KeywordUrlOptions = {};
|
368
|
-
|
369
|
+
let query_parameters: RouteParameters = {};
|
369
370
|
for (const key in options) {
|
370
371
|
if (!hasProp(options, key)) continue;
|
371
372
|
const value = options[key];
|
372
|
-
if (
|
373
|
+
if (key === "params") {
|
374
|
+
if (this.is_object(value)) {
|
375
|
+
query_parameters = {
|
376
|
+
...query_parameters,
|
377
|
+
...(value as RouteParameters),
|
378
|
+
};
|
379
|
+
} else {
|
380
|
+
throw new Error("params value should always be an object");
|
381
|
+
}
|
382
|
+
} else if (this.is_reserved_option(key)) {
|
373
383
|
keyword_parameters[key] = value as any;
|
374
384
|
} else {
|
375
385
|
if (
|
@@ -7,25 +7,25 @@ describe JsRoutes, "#serialize" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should provide this method" do
|
10
|
-
|
10
|
+
expectjs("Routes.serialize({a: 1, b: [2,3], c: {d: 4, e: 5}, f: ''})").to eq(
|
11
11
|
"a=1&b%5B%5D=2&b%5B%5D=3&c%5Bd%5D=4&c%5Be%5D=5&f="
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should provide this method" do
|
16
|
-
|
16
|
+
expectjs("Routes.serialize({a: 1, b: [2,3], c: {d: 4, e: 5}, f: ''})").to eq(
|
17
17
|
"a=1&b%5B%5D=2&b%5B%5D=3&c%5Bd%5D=4&c%5Be%5D=5&f="
|
18
18
|
)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "works with JS suckiness" do
|
22
|
-
|
22
|
+
expectjs(
|
23
23
|
[
|
24
24
|
"const query = Object.create(null);",
|
25
25
|
"query.a = 1;",
|
26
26
|
"query.b = 2;",
|
27
27
|
"Routes.serialize(query);",
|
28
28
|
].join("\n")
|
29
|
-
)
|
29
|
+
).to eq("a=1&b=2")
|
30
30
|
end
|
31
31
|
end
|
@@ -29,7 +29,7 @@ EOF
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should working from require" do
|
32
|
-
|
32
|
+
expectjs("require(['js-routes'], function(r){ return r.inboxes_path(); })").to eq(test_routes.inboxes_path())
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -10,6 +10,6 @@ describe JsRoutes, "compatibility with CJS" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should define module exports" do
|
13
|
-
|
13
|
+
expectjs("module.exports.inboxes_path()").to eq(test_routes.inboxes_path())
|
14
14
|
end
|
15
15
|
end
|
@@ -53,6 +53,7 @@ declare type KeywordUrlOptions = Optional<{
|
|
53
53
|
port: string | number;
|
54
54
|
anchor: string;
|
55
55
|
trailing_slash: boolean;
|
56
|
+
params: RouteParameters;
|
56
57
|
}>;
|
57
58
|
declare type RouteOptions = KeywordUrlOptions & RouteParameters;
|
58
59
|
declare type PartsTable = Record<string, {
|
@@ -13,7 +13,7 @@ describe JsRoutes, "compatibility with ESM" do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "defines route helpers" do
|
16
|
-
|
16
|
+
expectjs("inboxes_path()").to eq(test_routes.inboxes_path())
|
17
17
|
end
|
18
18
|
|
19
19
|
it "exports route helpers" do
|
@@ -33,7 +33,7 @@ DOC
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "defines utility methods" do
|
36
|
-
|
36
|
+
expectjs("serialize({a: 1, b: 2})").to eq({a: 1, b: 2}.to_param)
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "compiled javascript asset" do
|
@@ -36,7 +36,7 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should be possible" do
|
39
|
-
|
39
|
+
expectjs("r.inboxes_path()").to eq(test_routes.inboxes_path())
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -50,8 +50,8 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
|
|
50
50
|
evaljs(generated_js)
|
51
51
|
end
|
52
52
|
it "should use this namespace for routing" do
|
53
|
-
|
54
|
-
|
53
|
+
expectjs("window.Routes").to be_nil
|
54
|
+
expectjs("window.PHM.inboxes_path").not_to be_nil
|
55
55
|
end
|
56
56
|
|
57
57
|
describe "is nested" do
|
@@ -60,7 +60,7 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
|
|
60
60
|
let(:_options) { {namespace: "PHM.Routes"} }
|
61
61
|
|
62
62
|
it "should use this namespace for routing" do
|
63
|
-
|
63
|
+
expectjs("PHM.Routes.inboxes_path").not_to be_nil
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -68,7 +68,7 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
|
|
68
68
|
let(:_options) { {namespace: "PHM.Routes"} }
|
69
69
|
|
70
70
|
it "should initialize namespace" do
|
71
|
-
|
71
|
+
expectjs("window.PHM.Routes.inboxes_path").not_to be_nil
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -77,8 +77,8 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
|
|
77
77
|
let(:_options) { {namespace: "PHM.Routes"} }
|
78
78
|
|
79
79
|
it "should not overwrite existing parts" do
|
80
|
-
|
81
|
-
|
80
|
+
expectjs("window.PHM.Utils").not_to be_nil
|
81
|
+
expectjs("window.PHM.Routes.inboxes_path").not_to be_nil
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|