js-routes 1.4.14 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +15 -0
- data/.gitignore +2 -0
- data/.nvmrc +1 -0
- data/.travis.yml +2 -1
- data/CHANGELOG.md +15 -0
- data/Readme.md +90 -28
- data/VERSION_2_UPGRADE.md +61 -0
- data/js-routes.gemspec +6 -3
- data/lib/js_routes.rb +94 -54
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.d.ts +64 -0
- data/lib/routes.js +480 -524
- data/lib/routes.js.map +1 -0
- data/lib/routes.ts +683 -0
- data/package.json +36 -0
- data/spec/js_routes/default_serializer_spec.rb +19 -3
- data/spec/js_routes/{amd_compatibility_spec.rb → module_types/amd_spec.rb} +1 -4
- data/spec/js_routes/{common_js_compatibility_spec.rb → module_types/cjs_spec.rb} +5 -2
- data/spec/js_routes/module_types/esm_spec.rb +45 -0
- data/spec/js_routes/{generated_javascript_spec.rb → module_types/umd_spec.rb} +32 -21
- data/spec/js_routes/options_spec.rb +19 -6
- data/spec/js_routes/rails_routes_compatibility_spec.rb +54 -25
- data/spec/js_routes/zzz_last_post_rails_init_spec.rb +2 -2
- data/spec/spec_helper.rb +25 -17
- data/tsconfig.json +32 -0
- data/yarn.lock +2145 -0
- metadata +24 -15
- data/lib/routes.js.coffee +0 -416
data/lib/routes.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["routes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0DH,aAAa,CAAC,OAAO,CACnB,CAAC,IAAa,EAAwB,EAAE;IACtC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAE,GAAW,EAAE,EAAE,CAC9C,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnD,IAAK,SASJ;IATD,WAAK,SAAS;QACZ,2CAAS,CAAA;QACT,uCAAO,CAAA;QACP,6CAAU,CAAA;QAC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WAAW,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;QACxD,CAAC;KACF,CAAC;IAEF,MAAM,MAAM,GAAG;QACb,GAAG,KAAK;QACR,SAAS,EAAE,CAAC,MAA8B,EAAE,EAAE;YAC5C,OAAO,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;QACD,MAAM,EAAE,GAAkB,EAAE;YAC1B,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC;QACD,SAAS,EAAE,CAAC,MAAe,EAAU,EAAE;YACrC,OAAO,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;QACD,GAAG,aAAa,CAAC,aAAa;KAC/B,CAAC;IAEF,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAEvD,IAAI,aAAa,CAAC,WAAW,EAAE;QAC7B,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;KACxD;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CACF,CAAC,IAAI,CAAC,CAAC"}
|
data/lib/routes.ts
ADDED
@@ -0,0 +1,683 @@
|
|
1
|
+
/**
|
2
|
+
* File generated by js-routes RubyVariables.GEM_VERSION
|
3
|
+
* Based on Rails RubyVariables.RAILS_VERSION routes of RubyVariables.APP_CLASS
|
4
|
+
*/
|
5
|
+
|
6
|
+
type RouteParameter = unknown;
|
7
|
+
type RouteParameters = Record<string, RouteParameter>;
|
8
|
+
type Serializer = (value: unknown) => string;
|
9
|
+
type RouteHelper = {
|
10
|
+
(...args: RouteParameter[]): string;
|
11
|
+
requiredParams(): string[];
|
12
|
+
toString(): string;
|
13
|
+
};
|
14
|
+
|
15
|
+
type RouteHelpers = Record<string, RouteHelper>;
|
16
|
+
|
17
|
+
type Configuration = {
|
18
|
+
prefix: string;
|
19
|
+
default_url_options: RouteParameters;
|
20
|
+
special_options_key: string;
|
21
|
+
serializer: Serializer;
|
22
|
+
};
|
23
|
+
|
24
|
+
type Optional<T> = { [P in keyof T]?: T[P] | null };
|
25
|
+
interface RouterExposedMethods {
|
26
|
+
config(): Configuration;
|
27
|
+
configure(arg: Partial<Configuration>): Configuration;
|
28
|
+
serialize: Serializer;
|
29
|
+
}
|
30
|
+
|
31
|
+
type KeywordUrlOptions = Optional<{
|
32
|
+
host: string;
|
33
|
+
protocol: string;
|
34
|
+
subdomain: string;
|
35
|
+
port: string;
|
36
|
+
anchor: string;
|
37
|
+
trailing_slash: boolean;
|
38
|
+
}>;
|
39
|
+
|
40
|
+
type PartsTable = Record<string, { r?: boolean; d?: unknown }>;
|
41
|
+
|
42
|
+
type ModuleType = "CJS" | "AMD" | "UMD" | "ESM";
|
43
|
+
|
44
|
+
declare const RubyVariables: {
|
45
|
+
PREFIX: string;
|
46
|
+
DEPRECATED_GLOBBING_BEHAVIOR: boolean;
|
47
|
+
SPECIAL_OPTIONS_KEY: string;
|
48
|
+
DEFAULT_URL_OPTIONS: RouteParameters;
|
49
|
+
SERIALIZER: Serializer;
|
50
|
+
NAMESPACE: string;
|
51
|
+
ROUTES_OBJECT: RouteHelpers;
|
52
|
+
MODULE_TYPE: ModuleType | null;
|
53
|
+
WRAPPER: <T>(callback: T) => T;
|
54
|
+
};
|
55
|
+
|
56
|
+
declare const define:
|
57
|
+
| undefined
|
58
|
+
| (((arg: unknown[], callback: () => unknown) => void) & { amd?: unknown });
|
59
|
+
|
60
|
+
declare const module: { exports: any } | undefined;
|
61
|
+
|
62
|
+
RubyVariables.WRAPPER(
|
63
|
+
(that: unknown): RouterExposedMethods => {
|
64
|
+
const hasProp = (value: unknown, key: string) =>
|
65
|
+
Object.prototype.hasOwnProperty.call(value, key);
|
66
|
+
enum NodeTypes {
|
67
|
+
GROUP = 1,
|
68
|
+
CAT = 2,
|
69
|
+
SYMBOL = 3,
|
70
|
+
OR = 4,
|
71
|
+
STAR = 5,
|
72
|
+
LITERAL = 6,
|
73
|
+
SLASH = 7,
|
74
|
+
DOT = 8,
|
75
|
+
}
|
76
|
+
type RouteNodes = {
|
77
|
+
[NodeTypes.GROUP]: { left: RouteTree; right: never };
|
78
|
+
[NodeTypes.STAR]: { left: RouteTree; right: never };
|
79
|
+
[NodeTypes.LITERAL]: { left: string; right: never };
|
80
|
+
[NodeTypes.SLASH]: { left: "/"; right: never };
|
81
|
+
[NodeTypes.DOT]: { left: "."; right: never };
|
82
|
+
[NodeTypes.CAT]: { left: RouteTree; right: RouteTree };
|
83
|
+
[NodeTypes.SYMBOL]: { left: string; right: never };
|
84
|
+
};
|
85
|
+
type RouteNode<T extends keyof RouteNodes> = [
|
86
|
+
T,
|
87
|
+
RouteNodes[T]["left"],
|
88
|
+
RouteNodes[T]["right"]
|
89
|
+
];
|
90
|
+
type RouteTree = {
|
91
|
+
[T in keyof RouteNodes]: RouteNode<T>;
|
92
|
+
}[keyof RouteNodes];
|
93
|
+
|
94
|
+
const Root = that;
|
95
|
+
type ModuleDefinition = {
|
96
|
+
define: (routes: unknown) => void;
|
97
|
+
support: () => boolean;
|
98
|
+
};
|
99
|
+
const ModuleReferences: Record<ModuleType, ModuleDefinition> = {
|
100
|
+
CJS: {
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
102
|
+
define: (routes) => (module!.exports = routes),
|
103
|
+
support: () => typeof module === "object",
|
104
|
+
},
|
105
|
+
AMD: {
|
106
|
+
define: (routes) =>
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
108
|
+
define!([], function () {
|
109
|
+
return routes;
|
110
|
+
}),
|
111
|
+
support: () => typeof define === "function" && !!define.amd,
|
112
|
+
},
|
113
|
+
UMD: {
|
114
|
+
define: (routes) => {
|
115
|
+
if (ModuleReferences.AMD.support()) {
|
116
|
+
ModuleReferences.AMD.define(routes);
|
117
|
+
} else {
|
118
|
+
if (ModuleReferences.CJS.support()) {
|
119
|
+
try {
|
120
|
+
ModuleReferences.CJS.define(routes);
|
121
|
+
} catch (error) {
|
122
|
+
if (error.name !== "TypeError") throw error;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
},
|
127
|
+
support: () =>
|
128
|
+
ModuleReferences.AMD.support() || ModuleReferences.CJS.support(),
|
129
|
+
},
|
130
|
+
ESM: {
|
131
|
+
define: () => null,
|
132
|
+
support: () => true,
|
133
|
+
},
|
134
|
+
};
|
135
|
+
|
136
|
+
class ParametersMissing extends Error {
|
137
|
+
readonly keys: string[];
|
138
|
+
constructor(...keys: string[]) {
|
139
|
+
super(`Route missing required keys: ${keys.join(", ")}`);
|
140
|
+
this.keys = keys;
|
141
|
+
Object.setPrototypeOf(this, Object.getPrototypeOf(this));
|
142
|
+
this.name = ParametersMissing.name;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
const DeprecatedGlobbingBehavior =
|
147
|
+
RubyVariables.DEPRECATED_GLOBBING_BEHAVIOR;
|
148
|
+
|
149
|
+
const UriEncoderSegmentRegex = /[^a-zA-Z0-9\-._~!$&'()*+,;=:@]/g;
|
150
|
+
|
151
|
+
const ReservedOptions = [
|
152
|
+
"anchor",
|
153
|
+
"trailing_slash",
|
154
|
+
"subdomain",
|
155
|
+
"host",
|
156
|
+
"port",
|
157
|
+
"protocol",
|
158
|
+
] as const;
|
159
|
+
type ReservedOption = typeof ReservedOptions[any];
|
160
|
+
|
161
|
+
class UtilsClass {
|
162
|
+
configuration: Configuration = {
|
163
|
+
prefix: RubyVariables.PREFIX,
|
164
|
+
default_url_options: RubyVariables.DEFAULT_URL_OPTIONS,
|
165
|
+
special_options_key: RubyVariables.SPECIAL_OPTIONS_KEY,
|
166
|
+
serializer:
|
167
|
+
RubyVariables.SERIALIZER || this.default_serializer.bind(this),
|
168
|
+
};
|
169
|
+
|
170
|
+
default_serializer(value: any, prefix?: string | null): string {
|
171
|
+
if (this.is_nullable(value)) {
|
172
|
+
return "";
|
173
|
+
}
|
174
|
+
if (!prefix && !this.is_object(value)) {
|
175
|
+
throw new Error("Url parameters should be a javascript hash");
|
176
|
+
}
|
177
|
+
prefix = prefix || "";
|
178
|
+
const result: string[] = [];
|
179
|
+
if (this.is_array(value)) {
|
180
|
+
for (const element of value) {
|
181
|
+
result.push(this.default_serializer(element, prefix + "[]"));
|
182
|
+
}
|
183
|
+
} else if (this.is_object(value)) {
|
184
|
+
for (let key in value) {
|
185
|
+
if (!hasProp(value, key)) continue;
|
186
|
+
let prop = value[key];
|
187
|
+
if (this.is_nullable(prop) && prefix) {
|
188
|
+
prop = "";
|
189
|
+
}
|
190
|
+
if (this.is_not_nullable(prop)) {
|
191
|
+
if (prefix) {
|
192
|
+
key = prefix + "[" + key + "]";
|
193
|
+
}
|
194
|
+
result.push(this.default_serializer(prop, key));
|
195
|
+
}
|
196
|
+
}
|
197
|
+
} else {
|
198
|
+
if (this.is_not_nullable(value)) {
|
199
|
+
result.push(
|
200
|
+
encodeURIComponent(prefix) + "=" + encodeURIComponent("" + value)
|
201
|
+
);
|
202
|
+
}
|
203
|
+
}
|
204
|
+
return result.join("&");
|
205
|
+
}
|
206
|
+
|
207
|
+
serialize(object: unknown): string {
|
208
|
+
return this.configuration.serializer(object);
|
209
|
+
}
|
210
|
+
|
211
|
+
extract_options(
|
212
|
+
number_of_params: number,
|
213
|
+
args: RouteParameter[]
|
214
|
+
): {
|
215
|
+
args: RouteParameter[];
|
216
|
+
options: KeywordUrlOptions & RouteParameters;
|
217
|
+
} {
|
218
|
+
const last_el = args[args.length - 1];
|
219
|
+
if (
|
220
|
+
(args.length > number_of_params && last_el === 0) ||
|
221
|
+
(this.is_object(last_el) &&
|
222
|
+
!this.looks_like_serialized_model(last_el))
|
223
|
+
) {
|
224
|
+
if (this.is_object(last_el)) {
|
225
|
+
delete last_el[this.configuration.special_options_key];
|
226
|
+
}
|
227
|
+
return {
|
228
|
+
args: args.slice(0, args.length - 1),
|
229
|
+
options: last_el as KeywordUrlOptions & RouteParameters,
|
230
|
+
};
|
231
|
+
} else {
|
232
|
+
return { args, options: {} };
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
looks_like_serialized_model(
|
237
|
+
object: any
|
238
|
+
): object is
|
239
|
+
| { id: unknown }
|
240
|
+
| { to_param: unknown }
|
241
|
+
| { toParam: unknown } {
|
242
|
+
return (
|
243
|
+
this.is_object(object) &&
|
244
|
+
!object[this.configuration.special_options_key] &&
|
245
|
+
("id" in object || "to_param" in object || "toParam" in object)
|
246
|
+
);
|
247
|
+
}
|
248
|
+
|
249
|
+
path_identifier(object: unknown): string {
|
250
|
+
const result = this.unwrap_path_identifier(object);
|
251
|
+
return this.is_nullable(result) ? "" : "" + result;
|
252
|
+
}
|
253
|
+
|
254
|
+
unwrap_path_identifier(object: any): unknown {
|
255
|
+
let result: any = object;
|
256
|
+
if (!this.is_object(object)) {
|
257
|
+
return object;
|
258
|
+
}
|
259
|
+
if ("to_param" in object) {
|
260
|
+
result = object.to_param;
|
261
|
+
} else if ("toParam" in object) {
|
262
|
+
result = object.toParam;
|
263
|
+
} else if ("id" in object) {
|
264
|
+
result = object.id;
|
265
|
+
} else {
|
266
|
+
result = object;
|
267
|
+
}
|
268
|
+
return this.is_callable(result) ? result.call(object) : result;
|
269
|
+
}
|
270
|
+
|
271
|
+
partition_parameters(
|
272
|
+
parts: string[],
|
273
|
+
required_params: string[],
|
274
|
+
default_options: RouteParameters,
|
275
|
+
call_arguments: RouteParameter[]
|
276
|
+
): {
|
277
|
+
url_parameters: KeywordUrlOptions;
|
278
|
+
query_parameters: RouteParameters;
|
279
|
+
} {
|
280
|
+
// eslint-disable-next-line prefer-const
|
281
|
+
let { args, options } = this.extract_options(
|
282
|
+
parts.length,
|
283
|
+
call_arguments
|
284
|
+
);
|
285
|
+
if (args.length > parts.length) {
|
286
|
+
throw new Error("Too many parameters provided for path");
|
287
|
+
}
|
288
|
+
let use_all_parts = args.length > required_params.length;
|
289
|
+
const parts_options: RouteParameters = {};
|
290
|
+
for (const key in options) {
|
291
|
+
const value = options[key];
|
292
|
+
if (!hasProp(options, key)) continue;
|
293
|
+
use_all_parts = true;
|
294
|
+
if (parts.includes(key)) {
|
295
|
+
parts_options[key] = value;
|
296
|
+
}
|
297
|
+
}
|
298
|
+
options = {
|
299
|
+
...this.configuration.default_url_options,
|
300
|
+
...default_options,
|
301
|
+
...options,
|
302
|
+
};
|
303
|
+
|
304
|
+
const url_parameters: KeywordUrlOptions = {};
|
305
|
+
const query_parameters: RouteParameters = {};
|
306
|
+
for (const key in options) {
|
307
|
+
if (!hasProp(options, key)) continue;
|
308
|
+
const value = options[key];
|
309
|
+
if (this.is_reserved_option(key)) {
|
310
|
+
url_parameters[key] = value as any;
|
311
|
+
} else {
|
312
|
+
if (
|
313
|
+
!this.is_nullable(value) &&
|
314
|
+
(value !== default_options[key] || required_params.includes(key))
|
315
|
+
) {
|
316
|
+
query_parameters[key] = value;
|
317
|
+
}
|
318
|
+
}
|
319
|
+
}
|
320
|
+
const route_parts = use_all_parts ? parts : required_params;
|
321
|
+
let i = 0;
|
322
|
+
for (const part of route_parts) {
|
323
|
+
if (i < args.length) {
|
324
|
+
if (!hasProp(parts_options, part)) {
|
325
|
+
query_parameters[part] = args[i];
|
326
|
+
++i;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
}
|
330
|
+
return { url_parameters, query_parameters };
|
331
|
+
}
|
332
|
+
build_route(
|
333
|
+
parts: string[],
|
334
|
+
required_params: string[],
|
335
|
+
default_options: RouteParameters,
|
336
|
+
route: RouteTree,
|
337
|
+
full_url: boolean,
|
338
|
+
args: RouteParameter[]
|
339
|
+
): string {
|
340
|
+
const { url_parameters, query_parameters } = this.partition_parameters(
|
341
|
+
parts,
|
342
|
+
required_params,
|
343
|
+
default_options,
|
344
|
+
args
|
345
|
+
);
|
346
|
+
const missing_params = required_params.filter(
|
347
|
+
(param) =>
|
348
|
+
!hasProp(query_parameters, param) ||
|
349
|
+
this.is_nullable(query_parameters[param])
|
350
|
+
);
|
351
|
+
if (missing_params.length) {
|
352
|
+
throw new ParametersMissing(...missing_params);
|
353
|
+
}
|
354
|
+
let result = this.get_prefix() + this.visit(route, query_parameters);
|
355
|
+
if (url_parameters.trailing_slash) {
|
356
|
+
result = result.replace(/(.*?)[/]?$/, "$1/");
|
357
|
+
}
|
358
|
+
const url_params = this.serialize(query_parameters);
|
359
|
+
if (url_params.length) {
|
360
|
+
result += "?" + url_params;
|
361
|
+
}
|
362
|
+
result += url_parameters.anchor ? "#" + url_parameters.anchor : "";
|
363
|
+
if (full_url) {
|
364
|
+
result = this.route_url(url_parameters) + result;
|
365
|
+
}
|
366
|
+
return result;
|
367
|
+
}
|
368
|
+
|
369
|
+
visit(
|
370
|
+
route: RouteTree,
|
371
|
+
parameters: RouteParameters,
|
372
|
+
optional = false
|
373
|
+
): string {
|
374
|
+
switch (route[0]) {
|
375
|
+
case NodeTypes.GROUP:
|
376
|
+
return this.visit(route[1], parameters, true);
|
377
|
+
case NodeTypes.CAT:
|
378
|
+
return this.visit_cat(route, parameters, optional);
|
379
|
+
case NodeTypes.SYMBOL:
|
380
|
+
return this.visit_symbol(route, parameters, optional);
|
381
|
+
case NodeTypes.STAR:
|
382
|
+
return this.visit_globbing(route[1], parameters, true);
|
383
|
+
case NodeTypes.LITERAL:
|
384
|
+
case NodeTypes.SLASH:
|
385
|
+
case NodeTypes.DOT:
|
386
|
+
return route[1];
|
387
|
+
default:
|
388
|
+
throw new Error("Unknown Rails node type");
|
389
|
+
}
|
390
|
+
}
|
391
|
+
|
392
|
+
is_not_nullable<T>(object: T): object is NonNullable<T> {
|
393
|
+
return !this.is_nullable(object);
|
394
|
+
}
|
395
|
+
|
396
|
+
is_nullable(object: unknown): object is null | undefined {
|
397
|
+
return object === undefined || object === null;
|
398
|
+
}
|
399
|
+
|
400
|
+
visit_cat(
|
401
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
402
|
+
[_type, left, right]: RouteNode<NodeTypes.CAT>,
|
403
|
+
parameters: RouteParameters,
|
404
|
+
optional: boolean
|
405
|
+
): string {
|
406
|
+
const left_part = this.visit(left, parameters, optional);
|
407
|
+
const right_part = this.visit(right, parameters, optional);
|
408
|
+
if (
|
409
|
+
optional &&
|
410
|
+
((this.is_optional_node(left[0]) && !left_part) ||
|
411
|
+
(this.is_optional_node(right[0]) && !right_part))
|
412
|
+
) {
|
413
|
+
return "";
|
414
|
+
}
|
415
|
+
return left_part + right_part;
|
416
|
+
}
|
417
|
+
|
418
|
+
visit_symbol(
|
419
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
420
|
+
[_type, key]: RouteNode<NodeTypes.SYMBOL>,
|
421
|
+
parameters: RouteParameters,
|
422
|
+
optional: boolean
|
423
|
+
): string {
|
424
|
+
const value = this.path_identifier(parameters[key]);
|
425
|
+
delete parameters[key];
|
426
|
+
if (value.length) {
|
427
|
+
return this.encode_segment(value);
|
428
|
+
}
|
429
|
+
if (optional) {
|
430
|
+
return "";
|
431
|
+
} else {
|
432
|
+
throw new ParametersMissing(key);
|
433
|
+
}
|
434
|
+
}
|
435
|
+
|
436
|
+
encode_segment(segment: string): string {
|
437
|
+
return segment.replace(UriEncoderSegmentRegex, function (str) {
|
438
|
+
return encodeURIComponent(str);
|
439
|
+
});
|
440
|
+
}
|
441
|
+
|
442
|
+
is_optional_node(node: NodeTypes): boolean {
|
443
|
+
return [NodeTypes.STAR, NodeTypes.SYMBOL, NodeTypes.CAT].includes(node);
|
444
|
+
}
|
445
|
+
|
446
|
+
build_path_spec(route: RouteTree, wildcard = false): string {
|
447
|
+
let key: string;
|
448
|
+
switch (route[0]) {
|
449
|
+
case NodeTypes.GROUP:
|
450
|
+
return "(" + this.build_path_spec(route[1]) + ")";
|
451
|
+
case NodeTypes.CAT:
|
452
|
+
return (
|
453
|
+
this.build_path_spec(route[1]) + this.build_path_spec(route[2])
|
454
|
+
);
|
455
|
+
case NodeTypes.STAR:
|
456
|
+
return this.build_path_spec(route[1], true);
|
457
|
+
case NodeTypes.SYMBOL:
|
458
|
+
key = route[1];
|
459
|
+
if (wildcard) {
|
460
|
+
return (key.startsWith("*") ? "" : "*") + key;
|
461
|
+
} else {
|
462
|
+
return ":" + key;
|
463
|
+
}
|
464
|
+
break;
|
465
|
+
case NodeTypes.SLASH:
|
466
|
+
case NodeTypes.DOT:
|
467
|
+
case NodeTypes.LITERAL:
|
468
|
+
return route[1];
|
469
|
+
default:
|
470
|
+
throw new Error("Unknown Rails node type");
|
471
|
+
}
|
472
|
+
}
|
473
|
+
|
474
|
+
visit_globbing(
|
475
|
+
route: RouteTree,
|
476
|
+
parameters: RouteParameters,
|
477
|
+
optional: boolean
|
478
|
+
): string {
|
479
|
+
const key = route[1] as string;
|
480
|
+
let value = parameters[key];
|
481
|
+
delete parameters[key];
|
482
|
+
if (this.is_nullable(value)) {
|
483
|
+
return this.visit(route, parameters, optional);
|
484
|
+
}
|
485
|
+
if (this.is_array(value)) {
|
486
|
+
value = value.join("/");
|
487
|
+
}
|
488
|
+
value = this.path_identifier(value as any);
|
489
|
+
|
490
|
+
return DeprecatedGlobbingBehavior ? "" + value : encodeURI("" + value);
|
491
|
+
}
|
492
|
+
|
493
|
+
get_prefix(): string {
|
494
|
+
const prefix = this.configuration.prefix;
|
495
|
+
return prefix.match("/$")
|
496
|
+
? prefix.substring(0, prefix.length - 1)
|
497
|
+
: prefix;
|
498
|
+
}
|
499
|
+
|
500
|
+
route(
|
501
|
+
parts_table: PartsTable,
|
502
|
+
route_spec: RouteTree,
|
503
|
+
full_url = false
|
504
|
+
): RouteHelper {
|
505
|
+
const required_params: string[] = [];
|
506
|
+
const parts: string[] = [];
|
507
|
+
const default_options: RouteParameters = {};
|
508
|
+
for (const [part, { r: required, d: value }] of Object.entries(
|
509
|
+
parts_table
|
510
|
+
)) {
|
511
|
+
parts.push(part);
|
512
|
+
if (required) {
|
513
|
+
required_params.push(part);
|
514
|
+
}
|
515
|
+
if (this.is_not_nullable(value)) {
|
516
|
+
default_options[part] = value;
|
517
|
+
}
|
518
|
+
}
|
519
|
+
const result = (...args: RouteParameter[]): string => {
|
520
|
+
return this.build_route(
|
521
|
+
parts,
|
522
|
+
required_params,
|
523
|
+
default_options,
|
524
|
+
route_spec,
|
525
|
+
full_url,
|
526
|
+
args
|
527
|
+
);
|
528
|
+
};
|
529
|
+
result.requiredParams = () => required_params;
|
530
|
+
result.toString = () => {
|
531
|
+
return this.build_path_spec(route_spec);
|
532
|
+
};
|
533
|
+
return result;
|
534
|
+
}
|
535
|
+
|
536
|
+
route_url(route_defaults: KeywordUrlOptions): string {
|
537
|
+
const hostname = route_defaults.host || this.current_host();
|
538
|
+
if (!hostname) {
|
539
|
+
return "";
|
540
|
+
}
|
541
|
+
const subdomain = route_defaults.subdomain
|
542
|
+
? route_defaults.subdomain + "."
|
543
|
+
: "";
|
544
|
+
const protocol = route_defaults.protocol || this.current_protocol();
|
545
|
+
let port =
|
546
|
+
route_defaults.port ||
|
547
|
+
(!route_defaults.host ? this.current_port() : undefined);
|
548
|
+
port = port ? ":" + port : "";
|
549
|
+
return protocol + "://" + subdomain + hostname + port;
|
550
|
+
}
|
551
|
+
|
552
|
+
has_location(): boolean {
|
553
|
+
return this.is_not_nullable(window) && !!window.location;
|
554
|
+
}
|
555
|
+
|
556
|
+
current_host(): string | null {
|
557
|
+
if (this.has_location()) {
|
558
|
+
return window.location.hostname;
|
559
|
+
} else {
|
560
|
+
return null;
|
561
|
+
}
|
562
|
+
}
|
563
|
+
|
564
|
+
current_protocol(): string {
|
565
|
+
if (this.has_location() && window.location.protocol !== "") {
|
566
|
+
return window.location.protocol.replace(/:$/, "");
|
567
|
+
} else {
|
568
|
+
return "http";
|
569
|
+
}
|
570
|
+
}
|
571
|
+
current_port(): string {
|
572
|
+
if (this.has_location() && window.location.port !== "") {
|
573
|
+
return window.location.port;
|
574
|
+
} else {
|
575
|
+
return "";
|
576
|
+
}
|
577
|
+
}
|
578
|
+
|
579
|
+
is_object(value: unknown): value is Record<string, unknown> {
|
580
|
+
return (
|
581
|
+
typeof value === "object" &&
|
582
|
+
Object.prototype.toString.call(value) === "[object Object]"
|
583
|
+
);
|
584
|
+
}
|
585
|
+
|
586
|
+
is_array<T>(object: unknown | T[]): object is T[] {
|
587
|
+
return object instanceof Array;
|
588
|
+
}
|
589
|
+
|
590
|
+
is_callable(object: unknown): object is Function {
|
591
|
+
return typeof object === "function" && !!object.call;
|
592
|
+
}
|
593
|
+
|
594
|
+
is_reserved_option(key: unknown): key is ReservedOption {
|
595
|
+
return ReservedOptions.includes(key as any);
|
596
|
+
}
|
597
|
+
|
598
|
+
namespace(
|
599
|
+
object: any,
|
600
|
+
namespace: string | null | undefined,
|
601
|
+
routes: unknown
|
602
|
+
): unknown {
|
603
|
+
const parts = namespace?.split(".") || [];
|
604
|
+
if (parts.length === 0) {
|
605
|
+
return routes;
|
606
|
+
}
|
607
|
+
for (let index = 0; index < parts.length; index++) {
|
608
|
+
const part = parts[index];
|
609
|
+
if (index < parts.length - 1) {
|
610
|
+
object = object[part] || (object[part] = {});
|
611
|
+
} else {
|
612
|
+
return (object[part] = routes);
|
613
|
+
}
|
614
|
+
}
|
615
|
+
}
|
616
|
+
|
617
|
+
configure(new_config: Partial<Configuration>): Configuration {
|
618
|
+
this.configuration = { ...this.configuration, ...new_config };
|
619
|
+
return this.configuration;
|
620
|
+
}
|
621
|
+
|
622
|
+
config(): Configuration {
|
623
|
+
return { ...this.configuration };
|
624
|
+
}
|
625
|
+
|
626
|
+
is_module_supported(name: ModuleType): boolean {
|
627
|
+
return ModuleReferences[name].support();
|
628
|
+
}
|
629
|
+
|
630
|
+
ensure_module_supported(name: ModuleType): void {
|
631
|
+
if (!this.is_module_supported(name)) {
|
632
|
+
throw new Error(`${name} is not supported by runtime`);
|
633
|
+
}
|
634
|
+
}
|
635
|
+
|
636
|
+
define_module(
|
637
|
+
name: ModuleType | null,
|
638
|
+
module: RouterExposedMethods
|
639
|
+
): void {
|
640
|
+
if (!name) {
|
641
|
+
return;
|
642
|
+
}
|
643
|
+
this.ensure_module_supported(name);
|
644
|
+
ModuleReferences[name].define(module);
|
645
|
+
}
|
646
|
+
}
|
647
|
+
|
648
|
+
const Utils = new UtilsClass();
|
649
|
+
|
650
|
+
// We want this helper name to be short
|
651
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
652
|
+
const __jsr = {
|
653
|
+
r(
|
654
|
+
parts_table: PartsTable,
|
655
|
+
route_spec: RouteTree,
|
656
|
+
full_url?: boolean
|
657
|
+
): RouteHelper {
|
658
|
+
return Utils.route(parts_table, route_spec, full_url);
|
659
|
+
},
|
660
|
+
};
|
661
|
+
|
662
|
+
const result = {
|
663
|
+
...__jsr,
|
664
|
+
configure: (config: Partial<Configuration>) => {
|
665
|
+
return Utils.configure(config);
|
666
|
+
},
|
667
|
+
config: (): Configuration => {
|
668
|
+
return Utils.config();
|
669
|
+
},
|
670
|
+
serialize: (object: unknown): string => {
|
671
|
+
return Utils.serialize(object);
|
672
|
+
},
|
673
|
+
...RubyVariables.ROUTES_OBJECT,
|
674
|
+
};
|
675
|
+
|
676
|
+
Utils.namespace(Root, RubyVariables.NAMESPACE, result);
|
677
|
+
|
678
|
+
if (RubyVariables.MODULE_TYPE) {
|
679
|
+
Utils.define_module(RubyVariables.MODULE_TYPE, result);
|
680
|
+
}
|
681
|
+
return result;
|
682
|
+
}
|
683
|
+
)(this);
|