@inglorious/ssx 0.4.1 → 1.0.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/ssx",
3
- "version": "0.4.1",
3
+ "version": "1.0.0",
4
4
  "description": "Server-Side-X. Xecution? Xperience? Who knows.",
5
5
  "author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
@@ -57,12 +57,12 @@ it("should render a page with metadata", async () => {
57
57
  })
58
58
 
59
59
  it("should render a page with pre-fetched data", async () => {
60
- const page = { path: "/posts" }
61
- const module = await import(path.resolve(path.join(PAGES_DIR, "posts.js")))
60
+ const page = { path: "/blog" }
61
+ const module = await import(path.resolve(path.join(PAGES_DIR, "blog.js")))
62
62
 
63
63
  const store = createStore({
64
- types: { posts: module.posts },
65
- entities: { posts: { type: "posts", name: "Antony", posts: [] } },
64
+ types: { blog: module.blog },
65
+ entities: { blog: { type: "blog", name: "Antony", posts: [] } },
66
66
  updateMode: "manual",
67
67
  })
68
68
 
@@ -25,8 +25,8 @@ describe("router", () => {
25
25
 
26
26
  const patterns = routes.map((r) => r.pattern)
27
27
 
28
- expect(patterns).toContain("/posts/:id")
29
- expect(patterns).toContain("/blog/:slug")
28
+ expect(patterns).toContain("/posts/:slug")
29
+ expect(patterns).toContain("/blog")
30
30
  expect(patterns).toContain("/about")
31
31
  expect(patterns).toContain("/")
32
32
  expect(patterns).toContain("/api/*")
@@ -39,7 +39,7 @@ describe("router", () => {
39
39
  // Root usually comes after specific paths but before catch-all if it was a catch-all root,
40
40
  // but here / is static.
41
41
  // Let's just check that we found them.
42
- expect(routes).toHaveLength(6)
42
+ expect(routes).toHaveLength(5)
43
43
  })
44
44
  })
45
45
 
@@ -59,9 +59,9 @@ describe("router", () => {
59
59
  })
60
60
 
61
61
  it("should resolve dynamic page with params", async () => {
62
- const page = await resolvePage("/blog/hello-world", PAGES_DIR)
62
+ const page = await resolvePage("/posts/hello-world", PAGES_DIR)
63
63
  expect(page).not.toBeNull()
64
- expect(page.filePath).toContain("blog")
64
+ expect(page.filePath).toContain("posts")
65
65
  expect(page.params).toEqual({ slug: "hello-world" })
66
66
  })
67
67
 
@@ -35,9 +35,9 @@ it("should generate the app script for a page with an entity", async () => {
35
35
 
36
36
  it("should generate the app script for a page that has metadata", async () => {
37
37
  const page = {
38
- path: "/posts",
39
- modulePath: "posts.js",
40
- filePath: path.join(ROOT_DIR, "pages", "posts.js"),
38
+ path: "/blog",
39
+ modulePath: "blog.js",
40
+ filePath: path.join(ROOT_DIR, "pages", "blog.js"),
41
41
  }
42
42
  const store = await generateStore([page], { rootDir: ROOT_DIR })
43
43
 
package/src/store.js CHANGED
@@ -15,9 +15,15 @@ export async function generateStore(pages = [], options = {}) {
15
15
  types[name] = pageModule[name]
16
16
  }
17
17
 
18
- const { entities } = await import(
19
- pathToFileURL(path.join(rootDir, "entities.js"))
20
- )
18
+ let entities = {}
19
+ try {
20
+ const module = await import(
21
+ pathToFileURL(path.join(rootDir, "entities.js"))
22
+ )
23
+ entities = module.entities
24
+ } catch {
25
+ entities = {}
26
+ }
21
27
 
22
28
  return createStore({ types, entities, updateMode: "manual" })
23
29
  }
package/src/store.test.js CHANGED
@@ -30,11 +30,11 @@ it("should generate the proper types and entities from a page with an entity", a
30
30
 
31
31
  it("should generate the proper types and entities from a page that has metadata", async () => {
32
32
  const page = {
33
- filePath: path.join(ROOT_DIR, "pages", "posts.js"),
33
+ filePath: path.join(ROOT_DIR, "pages", "blog.js"),
34
34
  }
35
35
 
36
36
  const store = await generateStore([page], { rootDir: ROOT_DIR })
37
37
 
38
- expect(store.getType("posts").render).toBeDefined()
38
+ expect(store.getType("blog").render).toBeDefined()
39
39
  expect(store.getState()).toMatchSnapshot()
40
40
  })