@sealcode/sealgen 0.14.12 → 0.14.13

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.
@@ -1 +1,2 @@
1
+ export declare function generateURL(actionName: string, url: string): string;
1
2
  export declare function generateRoutes(): Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -31,7 +31,7 @@ function generateURL(actionName, url) {
31
31
  (part) => part.startsWith(":") ? "${" + part.slice(1) + "}" : encodeURIComponent(part)
32
32
  ).join("/")}\`;
33
33
  ${actionName}URL.params = [${params.map((param) => `"${param}"`).join(",")}];
34
- ${actionName}URL.rawURL = "${url}";`;
34
+ ${actionName}URL.rawURL = "${encodeURI(url)}";`;
35
35
  }
36
36
  async function generateRoutes() {
37
37
  const files = await Promise.all(
@@ -85,6 +85,7 @@ ${files.map(
85
85
  );
86
86
  }
87
87
  export {
88
- generateRoutes
88
+ generateRoutes,
89
+ generateURL
89
90
  };
90
91
  //# sourceMappingURL=generate-routes.js.map
@@ -0,0 +1,40 @@
1
+ import { generateURL } from "./generate-routes.js";
2
+ import * as prettier from "prettier";
3
+ import { getPrettierConfig } from "./utils/prettier.js";
4
+ describe("generate routes", () => {
5
+ it("handles a url with params", async () => {
6
+ assert.strictEqual(
7
+ prettier.format(
8
+ generateURL("EditUser", "/admin/users/:id/edit/"),
9
+ await getPrettierConfig()
10
+ ),
11
+ prettier.format(
12
+ `export const EditUserURL = (id: string) => \`/admin/users/\${id}/edit/\`;
13
+ EditUserURL.params = ["id"];
14
+ EditUserURL.rawURL = "/admin/users/:id/edit/";`,
15
+ await getPrettierConfig()
16
+ )
17
+ );
18
+ });
19
+ it("handles polish characters in the url", () => {
20
+ assert.strictEqual(
21
+ generateURL("Users", "/admin/u\u017Cytkownicy/"),
22
+ `export const UsersURL = "/admin/u%C5%BCytkownicy/";`
23
+ );
24
+ });
25
+ it("handles a url with params and diacritics", async () => {
26
+ assert.strictEqual(
27
+ prettier.format(
28
+ generateURL("EditUser", "/admin/u\u017Cytkownicy/:id/edit/"),
29
+ await getPrettierConfig()
30
+ ),
31
+ prettier.format(
32
+ `export const EditUserURL = (id: string) => \`/admin/u%C5%BCytkownicy/\${id}/edit/\`;
33
+ EditUserURL.params = ["id"];
34
+ EditUserURL.rawURL = "/admin/u%C5%BCytkownicy/:id/edit/";`,
35
+ await getPrettierConfig()
36
+ )
37
+ );
38
+ });
39
+ });
40
+ //# sourceMappingURL=generate-routes.test.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealcode/sealgen",
3
- "version": "0.14.12",
3
+ "version": "0.14.13",
4
4
  "description": "Module to automate adding routes and collections to a sealious application",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -0,0 +1,42 @@
1
+ import { generateURL } from "./generate-routes.js";
2
+ import * as prettier from "prettier";
3
+ import { getPrettierConfig } from "./utils/prettier.js";
4
+
5
+ describe("generate routes", () => {
6
+ it("handles a url with params", async () => {
7
+ assert.strictEqual(
8
+ prettier.format(
9
+ generateURL("EditUser", "/admin/users/:id/edit/"),
10
+ await getPrettierConfig()
11
+ ),
12
+ prettier.format(
13
+ `export const EditUserURL = (id: string) => \`/admin/users/\${id}/edit/\`;
14
+ EditUserURL.params = ["id"];
15
+ EditUserURL.rawURL = "/admin/users/:id/edit/";`,
16
+ await getPrettierConfig()
17
+ )
18
+ );
19
+ });
20
+
21
+ it("handles polish characters in the url", () => {
22
+ assert.strictEqual(
23
+ generateURL("Users", "/admin/użytkownicy/"),
24
+ `export const UsersURL = "/admin/u%C5%BCytkownicy/";`
25
+ );
26
+ });
27
+
28
+ it("handles a url with params and diacritics", async () => {
29
+ assert.strictEqual(
30
+ prettier.format(
31
+ generateURL("EditUser", "/admin/użytkownicy/:id/edit/"),
32
+ await getPrettierConfig()
33
+ ),
34
+ prettier.format(
35
+ `export const EditUserURL = (id: string) => \`/admin/u%C5%BCytkownicy/\${id}/edit/\`;
36
+ EditUserURL.params = ["id"];
37
+ EditUserURL.rawURL = "/admin/u%C5%BCytkownicy/:id/edit/";`,
38
+ await getPrettierConfig()
39
+ )
40
+ );
41
+ });
42
+ });
@@ -24,7 +24,7 @@ async function extractActionName(full_file_path: string): Promise<string> {
24
24
  );
25
25
  }
26
26
 
27
- function generateURL(actionName: string, url: string) {
27
+ export function generateURL(actionName: string, url: string) {
28
28
  const parts = url.split("/");
29
29
  const params = parts
30
30
  .filter((part) => part.startsWith(":"))
@@ -44,7 +44,7 @@ function generateURL(actionName: string, url: string) {
44
44
  ${actionName}URL.params = [${params
45
45
  .map((param) => `"${param}"`)
46
46
  .join(",")}];
47
- ${actionName}URL.rawURL = "${url}";`;
47
+ ${actionName}URL.rawURL = "${encodeURI(url)}";`;
48
48
  }
49
49
 
50
50
  export async function generateRoutes(): Promise<void> {