enroute 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a65a1195f13ae4e7252622ddbc6da85afd4076aff0e954acb1460ea5792b4018
4
- data.tar.gz: 3ee3e8d588d5b525122530b89d20561eaaef96d4967e952c9b291ee9c74036ad
3
+ metadata.gz: e448075c7d87f3b0a6c937069a8d97aabafc703eb1a32de10ed724c7360eb09a
4
+ data.tar.gz: 0440e5b70267913d65ed6876884a0bde6eb3d76d9b9ab7432d248706cbc5585b
5
5
  SHA512:
6
- metadata.gz: e2b6a3fab6873badc69fb61a1708dc6a090861b7f8859145e97492d97fc04a9dde3e314861b999756c3e9ba0c7db4bb5c93058f63d5b4d83f4542b989ac00e1f
7
- data.tar.gz: c608f1415e466716c2f423f70e857739963963cc19d27976cded97bb2e0c4b48c9f726f2fa1307f15c96389868f2efa24d9e93e0b1ce6ff4e212016878fe3c46
6
+ metadata.gz: 630f02374224590f3f51283d6b2735cabafc52454139e295be371cf5381a99c5d27f15d3d6fee4b46a7e09462cb6b6d5f20919e0956c94667beca4933743a9be
7
+ data.tar.gz: 485794ae75c343f3d198c206a0e9e89ba8d512d8a931f6414ef77a9b96a8d552b3a9bc1b428abb5b550ba3f621c5c7ff7684d24afbb9f66279f5d34edab4dfaa
@@ -19,14 +19,14 @@ jobs:
19
19
  strategy:
20
20
  fail-fast: false
21
21
  matrix:
22
- ruby: ["2.7", "3.0", "3.1"]
23
- node: ["16", "17"]
22
+ ruby: ["3.1", "3.2", "3.3"]
23
+ node: ["18", "20"]
24
24
  gemfile:
25
+ - gemfiles/rails_7_1.gemfile
25
26
  - gemfiles/rails_7_0.gemfile
26
- - gemfiles/rails_6_1.gemfile
27
27
 
28
28
  steps:
29
- - uses: actions/checkout@v3
29
+ - uses: actions/checkout@v4
30
30
 
31
31
  - uses: actions/cache@v3
32
32
  with:
@@ -36,7 +36,7 @@ jobs:
36
36
  hashFiles('package.json') }}
37
37
 
38
38
  - name: Set up Node
39
- uses: actions/setup-node@v3
39
+ uses: actions/setup-node@v4
40
40
  with:
41
41
  node-version: ${{ matrix.node }}
42
42
 
data/.rubocop.yml CHANGED
@@ -8,3 +8,9 @@ AllCops:
8
8
  Exclude:
9
9
  - vendor/**/*
10
10
  - gemfiles/**/*
11
+
12
+ Minitest/MultipleAssertions:
13
+ Enabled: false
14
+
15
+ Gemspec/DevelopmentDependencies:
16
+ Enabled: false
data/.tool-versions CHANGED
@@ -1 +1,2 @@
1
- nodejs 16.13.1
1
+ nodejs 21.6.1
2
+ ruby 3.3.0
data/README.md CHANGED
@@ -83,10 +83,10 @@ You can then import any route that's been exported. Parameters are positional.
83
83
  ```typescript
84
84
  import { userUrl } from "./routes";
85
85
 
86
- userUrl(1234);
86
+ userUrl({ id: 1234 });
87
87
  //=> "/users/1234"
88
88
 
89
- userUrl(1234, "json");
89
+ userUrl({ id: 1234, format: "json" });
90
90
  //=> "/users/1234.json"
91
91
  ```
92
92
 
@@ -100,7 +100,7 @@ import { editSettingsUrl } from "./routes";
100
100
  editSettingsUrl();
101
101
  //=> "/settings/edit"
102
102
 
103
- editSettingsUrl("security");
103
+ editSettingsUrl({ section: "security" });
104
104
  //=> "/settings/edit/security"
105
105
  ```
106
106
 
@@ -139,6 +139,6 @@ found at https://github.com/fnando/enroute/blob/main/LICENSE.md.
139
139
 
140
140
  ## Code of Conduct
141
141
 
142
- Everyone interacting in the enroute project's codebases, issue
143
- trackers, chat rooms and mailing lists is expected to follow the
142
+ Everyone interacting in the enroute project's codebases, issue trackers, chat
143
+ rooms and mailing lists is expected to follow the
144
144
  [code of conduct](https://github.com/fnando/enroute/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+
6
+ gem "rails", "~> 7.1.0"
data/jest.config.js CHANGED
@@ -1,3 +1,4 @@
1
1
  module.exports = {
2
- transform: {"\\.ts$": ["ts-jest"]}
2
+ transform: { "\\.ts$": ["ts-jest"] },
3
+ testEnvironment: "jest-environment-jsdom",
3
4
  };
@@ -54,14 +54,21 @@ module Enroute
54
54
  end
55
55
 
56
56
  def build_ts_args_definition(route)
57
- route[:segments].map do |segment|
57
+ args = route[:segments].each_with_object([]) do |segment, buffer|
58
58
  type = route.dig(:typings, segment)&.chomp ||
59
59
  config.dig(:typings, :_default, segment)&.chomp ||
60
60
  "any"
61
61
 
62
62
  optional = route[:requiredSegments].include?(segment) ? "" : "?"
63
- "#{segment.camelize(:lower)}#{optional}: #{type}"
64
- end.join(", ")
63
+
64
+ buffer << "#{segment.camelize(:lower)}#{optional}: #{type}"
65
+ end
66
+
67
+ args << "params?: Record<string, unknown>"
68
+
69
+ "args?: {#{args.join('; ')}}"
70
+
71
+ # (args + ["params: Record<string, unknown> = {}"]).join(", ")
65
72
  end
66
73
 
67
74
  def build_ts_handler_function(route)
@@ -71,12 +78,21 @@ module Enroute
71
78
 
72
79
  def build_ts_route_function(route)
73
80
  args = build_ts_args_definition(route)
74
- segments = route[:segments].map {|segment| segment.camelize(:lower) }
75
81
 
76
- [
77
- %[export const #{route[:name]}Url = (#{args}): string =>],
78
- %[ #{route[:name]}Handler(#{segments.join(', ')});]
79
- ].join("\n")
82
+ segments = route[:segments].map {|segment| segment.camelize(:lower) }
83
+ destruct = [segments.join(", "), "params"].reject(&:blank?).join(", ")
84
+
85
+ <<~TYPESCRIPT
86
+ export function #{route[:name]}Url(#{args}): string {
87
+ const {#{destruct}} = args ?? {};
88
+ return buildUrl(#{route[:name]}Handler(#{segments.join(', ')}), params ?? {}).url;
89
+ }
90
+
91
+ export function #{route[:name]}Path(#{args}): string {
92
+ const {#{destruct}} = args ?? {};
93
+ return buildUrl(#{route[:name]}Handler(#{segments.join(', ')}), params ?? {}).path;
94
+ }
95
+ TYPESCRIPT
80
96
  end
81
97
  end
82
98
  end
@@ -2,7 +2,13 @@
2
2
  // This file has been automatically generated.
3
3
  // Don't edit it manually. Use `enroute export` instead.
4
4
 
5
- import { zipObject } from "lodash";
5
+ function zipObject(keys: string[], values: unknown[]): Record<string, unknown> {
6
+ return keys.reduce((buffer, key, index) =>
7
+ Object.assign(
8
+ buffer,
9
+ {[key]: values[index]}
10
+ ), {} as Record<string, unknown>)
11
+ }
6
12
 
7
13
  function camelize(text: string): string {
8
14
  return text.replace(
@@ -110,6 +116,24 @@ export type RouteHandler = RouteHelper & {
110
116
  underscore: RouteHelper;
111
117
  };
112
118
 
119
+ const baseUrl = location.protocol + "//" + location.host;
120
+
121
+ const buildUrl = (
122
+ path: string,
123
+ params: Record<string, unknown>
124
+ ): {path: string; url: string} => {
125
+ const url = new URL(baseUrl + path);
126
+
127
+ Object.keys(params).forEach((key) => {
128
+ url.searchParams.set(key, String(params[key]));
129
+ });
130
+
131
+ return {
132
+ path: url.pathname + url.search,
133
+ url: url.toString(),
134
+ };
135
+ }
136
+
113
137
  <%= handler_functions %>
114
138
 
115
139
  <%= route_functions %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Enroute
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
data/package.json CHANGED
@@ -14,5 +14,8 @@
14
14
  "prettier": "*",
15
15
  "ts-jest": "*",
16
16
  "typescript": "*"
17
+ },
18
+ "dependencies": {
19
+ "jest-environment-jsdom": "^29.7.0"
17
20
  }
18
21
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enroute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-12 00:00:00.000000000 Z
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -166,6 +166,7 @@ files:
166
166
  - exe/enroute
167
167
  - gemfiles/rails_6_1.gemfile
168
168
  - gemfiles/rails_7_0.gemfile
169
+ - gemfiles/rails_7_1.gemfile
169
170
  - jest.config.js
170
171
  - lib/enroute.rb
171
172
  - lib/enroute/cli.rb
@@ -198,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
199
  - !ruby/object:Gem::Version
199
200
  version: '0'
200
201
  requirements: []
201
- rubygems_version: 3.3.17
202
+ rubygems_version: 3.5.5
202
203
  signing_key:
203
204
  specification_version: 4
204
205
  summary: Export Rails routes to TypeScript definitions