js-routes 2.3.6 → 2.3.7
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 -0
- data/lib/js_routes/instance.rb +6 -1
- data/lib/js_routes/route.rb +1 -1
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.d.ts +21 -21
- data/lib/routes.js +18 -27
- data/lib/routes.ts +600 -615
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e1323cccad426e331d7f99923e967b09d06e028ec3f2665798dad91ff5ce582
|
|
4
|
+
data.tar.gz: 4ddb07ef468133b25d7ace1313b948f689a77a1c576e3102e88ff2b87f82a5c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9840b6fa125bec3de173ce942e7daae8cac4de026d424d70a4bb82d67d9cf075d050c182c02fadef9d5c64a989599dd3a0cbc59197652d836b44f3452588bad2
|
|
7
|
+
data.tar.gz: 449669e3e6719f2c1ee22bd1b6b7bfaa34ca2821f7d6050563d76f43781c8e4efc8c1d6e986443007451550002abad649e6dc6bdf10629ba683be3ccf3f3f1ee
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Pending
|
|
4
|
+
|
|
5
|
+
## [2.3.7]
|
|
6
|
+
|
|
7
|
+
* Obfuscate assignment to module.exports in order to prevent warnings in javascript bundlers, like Vite. Fixes [#337](https://github.com/railsware/js-routes/issues/337).
|
|
8
|
+
|
|
3
9
|
## [2.3.6]
|
|
4
10
|
|
|
5
11
|
* Fixed serialization of empty `Array` and empty `Hash`. Fixes [#336](https://github.com/railsware/js-routes/issues/336).
|
data/lib/js_routes/instance.rb
CHANGED
|
@@ -43,7 +43,12 @@ module JsRoutes
|
|
|
43
43
|
raise("Missing key #{key} in JS template")
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
|
-
|
|
46
|
+
unless @configuration.module_type == "NIL"
|
|
47
|
+
banner + content + routes_export + prevent_types_export
|
|
48
|
+
else
|
|
49
|
+
content.sub('"use strict";', "")
|
|
50
|
+
end
|
|
51
|
+
|
|
47
52
|
end
|
|
48
53
|
|
|
49
54
|
sig { returns(String) }
|
data/lib/js_routes/route.rb
CHANGED
|
@@ -55,7 +55,7 @@ module JsRoutes
|
|
|
55
55
|
if @configuration.dts?
|
|
56
56
|
definition_body
|
|
57
57
|
else
|
|
58
|
-
# For tree-shaking ESM, add a #__PURE__ comment informing
|
|
58
|
+
# For tree-shaking ESM, add a #__PURE__ comment informing js bundlers that the call to `__jsr.r`
|
|
59
59
|
# has no side-effects (e.g. modifying global variables) and is safe to remove when unused.
|
|
60
60
|
# https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sidyeeffects
|
|
61
61
|
pure_comment = @configuration.esm? ? '/*#__PURE__*/ ' : ''
|
data/lib/js_routes/version.rb
CHANGED
data/lib/routes.d.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
type Optional<T> = {
|
|
2
2
|
[P in keyof T]?: T[P] | null;
|
|
3
3
|
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
type Collection<T> = Record<string, T>;
|
|
5
|
+
type BaseRouteParameter = string | boolean | Date | number | bigint;
|
|
6
|
+
type MethodRouteParameter = BaseRouteParameter | (() => BaseRouteParameter);
|
|
7
|
+
type ModelRouteParameter = {
|
|
8
8
|
id: MethodRouteParameter;
|
|
9
9
|
} | {
|
|
10
10
|
to_param: MethodRouteParameter;
|
|
11
11
|
} | {
|
|
12
12
|
toParam: MethodRouteParameter;
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
type RequiredRouteParameter = BaseRouteParameter | ModelRouteParameter;
|
|
15
|
+
type OptionalRouteParameter = undefined | null | RequiredRouteParameter;
|
|
16
|
+
type QueryRouteParameter = OptionalRouteParameter | QueryRouteParameter[] | {
|
|
17
17
|
[k: string]: QueryRouteParameter;
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
type RouteParameters = Collection<QueryRouteParameter>;
|
|
20
|
+
type Serializable = Collection<unknown>;
|
|
21
|
+
type Serializer = (value: Serializable) => string;
|
|
22
|
+
type RouteHelperExtras = {
|
|
23
23
|
requiredParams(): string[];
|
|
24
24
|
toString(): string;
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
type RequiredParameters<T extends number> = T extends 1 ? [RequiredRouteParameter] : T extends 2 ? [RequiredRouteParameter, RequiredRouteParameter] : T extends 3 ? [RequiredRouteParameter, RequiredRouteParameter, RequiredRouteParameter] : T extends 4 ? [
|
|
27
27
|
RequiredRouteParameter,
|
|
28
28
|
RequiredRouteParameter,
|
|
29
29
|
RequiredRouteParameter,
|
|
30
30
|
RequiredRouteParameter
|
|
31
31
|
] : RequiredRouteParameter[];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
type RouteHelperOptions = RouteOptions & Collection<OptionalRouteParameter>;
|
|
33
|
+
type RouteHelper<T extends number = number> = ((...args: [...RequiredParameters<T>, RouteHelperOptions]) => string) & RouteHelperExtras;
|
|
34
|
+
type RouteHelpers = Collection<RouteHelper>;
|
|
35
|
+
type Configuration = {
|
|
36
36
|
prefix: string;
|
|
37
37
|
default_url_options: RouteParameters;
|
|
38
38
|
special_options_key: string;
|
|
@@ -43,7 +43,7 @@ interface RouterExposedMethods {
|
|
|
43
43
|
configure(arg: Partial<Configuration>): Configuration;
|
|
44
44
|
serialize: Serializer;
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
type KeywordUrlOptions = Optional<{
|
|
47
47
|
host: string;
|
|
48
48
|
protocol: string;
|
|
49
49
|
subdomain: string;
|
|
@@ -53,12 +53,12 @@ declare type KeywordUrlOptions = Optional<{
|
|
|
53
53
|
script_name: string;
|
|
54
54
|
params: RouteParameters;
|
|
55
55
|
}>;
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
type RouteOptions = KeywordUrlOptions & RouteParameters;
|
|
57
|
+
type PartsTable = Collection<{
|
|
58
58
|
r?: boolean;
|
|
59
59
|
d?: OptionalRouteParameter;
|
|
60
60
|
}>;
|
|
61
|
-
|
|
61
|
+
type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
|
|
62
62
|
declare const RubyVariables: {
|
|
63
63
|
PREFIX: string;
|
|
64
64
|
DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
|
data/lib/routes.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
RubyVariables.WRAPPER(
|
|
3
|
-
// eslint-disable-next-line
|
|
4
|
-
() => {
|
|
1
|
+
"use strict";
|
|
2
|
+
RubyVariables.WRAPPER(() => {
|
|
5
3
|
const hasProp = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
6
4
|
let NodeTypes;
|
|
7
5
|
(function (NodeTypes) {
|
|
@@ -27,7 +25,12 @@ RubyVariables.WRAPPER(
|
|
|
27
25
|
CJS: {
|
|
28
26
|
define(routes) {
|
|
29
27
|
if (module) {
|
|
30
|
-
|
|
28
|
+
// Some javascript processors (like vite/rolldown)
|
|
29
|
+
// warn on using module dot exports in an ESM module.
|
|
30
|
+
// This just obfuscates that assignment a little so
|
|
31
|
+
// users don't get a warning they can't fix.
|
|
32
|
+
const _mod = module;
|
|
33
|
+
_mod.exports = routes;
|
|
31
34
|
}
|
|
32
35
|
},
|
|
33
36
|
isSupported() {
|
|
@@ -79,7 +82,7 @@ RubyVariables.WRAPPER(
|
|
|
79
82
|
},
|
|
80
83
|
NIL: {
|
|
81
84
|
define() {
|
|
82
|
-
// Defined using RubyVariables.WRAPPER
|
|
85
|
+
// Defined using RubyVariables . WRAPPER
|
|
83
86
|
},
|
|
84
87
|
isSupported() {
|
|
85
88
|
return true;
|
|
@@ -147,12 +150,11 @@ RubyVariables.WRAPPER(
|
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
152
|
else {
|
|
153
|
+
const key = encodeURIComponent(prefix);
|
|
150
154
|
result.push(this.is_not_nullable(value) ||
|
|
151
155
|
RubyVariables.DEPRECATED_NIL_QUERY_PARAMETER_BEHAVIOR
|
|
152
|
-
? encodeURIComponent(
|
|
153
|
-
|
|
154
|
-
encodeURIComponent("" + (value !== null && value !== void 0 ? value : ""))
|
|
155
|
-
: encodeURIComponent(prefix));
|
|
156
|
+
? key + "=" + encodeURIComponent("" + (value !== null && value !== void 0 ? value : ""))
|
|
157
|
+
: key);
|
|
156
158
|
}
|
|
157
159
|
return result.join("&");
|
|
158
160
|
}
|
|
@@ -162,8 +164,7 @@ RubyVariables.WRAPPER(
|
|
|
162
164
|
extract_options(number_of_params, args) {
|
|
163
165
|
const last_el = args[args.length - 1];
|
|
164
166
|
if ((args.length > number_of_params && last_el === 0) ||
|
|
165
|
-
(this.is_object(last_el) &&
|
|
166
|
-
!this.looks_like_serialized_model(last_el))) {
|
|
167
|
+
(this.is_object(last_el) && !this.looks_like_serialized_model(last_el))) {
|
|
167
168
|
if (this.is_object(last_el)) {
|
|
168
169
|
delete last_el[this.configuration.special_options_key];
|
|
169
170
|
}
|
|
@@ -184,8 +185,7 @@ RubyVariables.WRAPPER(
|
|
|
184
185
|
path_identifier(object) {
|
|
185
186
|
const result = this.unwrap_path_identifier(object);
|
|
186
187
|
return this.is_nullable(result) ||
|
|
187
|
-
(RubyVariables.DEPRECATED_FALSE_PARAMETER_BEHAVIOR &&
|
|
188
|
-
result === false)
|
|
188
|
+
(RubyVariables.DEPRECATED_FALSE_PARAMETER_BEHAVIOR && result === false)
|
|
189
189
|
? ""
|
|
190
190
|
: "" + result;
|
|
191
191
|
}
|
|
@@ -209,7 +209,6 @@ RubyVariables.WRAPPER(
|
|
|
209
209
|
return this.is_callable(result) ? result.call(object) : result;
|
|
210
210
|
}
|
|
211
211
|
partition_parameters(parts, required_params, default_options, call_arguments) {
|
|
212
|
-
// eslint-disable-next-line prefer-const
|
|
213
212
|
let { args, options } = this.extract_options(parts.length, call_arguments);
|
|
214
213
|
if (args.length > parts.length) {
|
|
215
214
|
throw new Error("Too many parameters provided for path");
|
|
@@ -514,21 +513,13 @@ RubyVariables.WRAPPER(
|
|
|
514
513
|
const utils = new UtilsClass();
|
|
515
514
|
// We want this helper name to be short
|
|
516
515
|
const __jsr = {
|
|
517
|
-
r(
|
|
518
|
-
return utils.route(parts_table, route_spec, absolute);
|
|
519
|
-
},
|
|
516
|
+
r: utils.route.bind(utils),
|
|
520
517
|
};
|
|
521
518
|
return utils.define_module(RubyVariables.MODULE_TYPE, {
|
|
522
519
|
...__jsr,
|
|
523
|
-
configure: (
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
config: () => {
|
|
527
|
-
return utils.config();
|
|
528
|
-
},
|
|
529
|
-
serialize: (object) => {
|
|
530
|
-
return utils.serialize(object);
|
|
531
|
-
},
|
|
520
|
+
configure: utils.configure.bind(utils),
|
|
521
|
+
config: utils.config.bind(utils),
|
|
522
|
+
serialize: utils.serialize.bind(utils),
|
|
532
523
|
...RubyVariables.ROUTES_OBJECT,
|
|
533
524
|
});
|
|
534
525
|
})();
|