@stone-js/starters 0.8.8 → 0.8.10

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.
Files changed (101) hide show
  1. package/README.md +2 -2
  2. package/basic-react-declarative/app/Application.tsx +0 -2
  3. package/basic-react-declarative/package.json +7 -7
  4. package/basic-react-declarative/public/favicon.svg +16 -0
  5. package/basic-react-declarative/tests/Application.spec.ts +25 -100
  6. package/basic-react-imperative/app/Application.tsx +2 -17
  7. package/basic-react-imperative/package.json +7 -7
  8. package/basic-react-imperative/public/favicon.svg +16 -0
  9. package/basic-react-imperative/tests/Application.spec.ts +25 -86
  10. package/basic-react-native-declarative/App.tsx +192 -0
  11. package/basic-react-native-declarative/LICENSE +21 -0
  12. package/basic-react-native-declarative/README.md +35 -0
  13. package/basic-react-native-declarative/adapter/NativeAdapter.ts +108 -0
  14. package/basic-react-native-declarative/adapter/NativeErrorHandler.ts +53 -0
  15. package/basic-react-native-declarative/adapter/NativeEventSource.ts +58 -0
  16. package/basic-react-native-declarative/adapter/RawResponseWrapper.ts +30 -0
  17. package/basic-react-native-declarative/adapter/declarations.ts +40 -0
  18. package/basic-react-native-declarative/adapter/middleware.ts +73 -0
  19. package/basic-react-native-declarative/adapter/nativeAdapterBlueprint.ts +51 -0
  20. package/basic-react-native-declarative/adapter/renderSink.ts +52 -0
  21. package/basic-react-native-declarative/app/Application.ts +17 -0
  22. package/basic-react-native-declarative/app/WelcomeController.ts +66 -0
  23. package/basic-react-native-declarative/app.json +25 -0
  24. package/basic-react-native-declarative/assets/android-icon-background.png +0 -0
  25. package/basic-react-native-declarative/assets/android-icon-foreground.png +0 -0
  26. package/basic-react-native-declarative/assets/android-icon-monochrome.png +0 -0
  27. package/basic-react-native-declarative/assets/favicon.png +0 -0
  28. package/basic-react-native-declarative/assets/icon.png +0 -0
  29. package/basic-react-native-declarative/assets/splash-icon.png +0 -0
  30. package/basic-react-native-declarative/babel.config.js +16 -0
  31. package/basic-react-native-declarative/index.ts +22 -0
  32. package/basic-react-native-declarative/metro.config.js +7 -0
  33. package/basic-react-native-declarative/package.json +41 -0
  34. package/basic-react-native-declarative/tests/Application.spec.ts +65 -0
  35. package/basic-react-native-declarative/tsconfig.json +16 -0
  36. package/basic-react-native-declarative/vitest.config.ts +27 -0
  37. package/basic-service-declarative/app/Application.ts +0 -2
  38. package/basic-service-declarative/package.json +6 -6
  39. package/basic-service-declarative/tests/Application.spec.ts +20 -53
  40. package/basic-service-imperative/app/Application.ts +2 -14
  41. package/basic-service-imperative/package.json +6 -6
  42. package/basic-service-imperative/tests/Application.spec.ts +19 -44
  43. package/continuum-showcase/package.json +11 -10
  44. package/continuum-showcase/public/favicon.svg +16 -0
  45. package/continuum-showcase/stone.config.mjs +2 -2
  46. package/continuum-showcase/tests/application.spec.ts +30 -0
  47. package/full-react-declarative/app/Application.ts +0 -4
  48. package/full-react-declarative/package.json +12 -12
  49. package/full-react-declarative/public/favicon.svg +16 -0
  50. package/full-react-declarative/stone.config.mjs +2 -2
  51. package/full-react-declarative/tests/application.spec.ts +30 -0
  52. package/full-react-imperative/app/Application.ts +1 -3
  53. package/full-react-imperative/package.json +12 -12
  54. package/full-react-imperative/public/favicon.svg +16 -0
  55. package/full-react-imperative/stone.config.mjs +2 -2
  56. package/full-react-imperative/tests/application.spec.ts +30 -0
  57. package/full-service-declarative/app/Application.ts +5 -2
  58. package/full-service-declarative/app/configurations/AppConfiguration.ts +1 -3
  59. package/full-service-declarative/package.json +13 -12
  60. package/full-service-declarative/stone.config.mjs +2 -2
  61. package/full-service-declarative/tests/application.spec.ts +30 -0
  62. package/full-service-imperative/app/Application.ts +8 -2
  63. package/full-service-imperative/app/configurations/AppConfiguration.ts +1 -3
  64. package/full-service-imperative/package.json +13 -12
  65. package/full-service-imperative/stone.config.mjs +2 -2
  66. package/full-service-imperative/tests/application.spec.ts +30 -0
  67. package/package.json +15 -1
  68. package/standard-react-declarative/package.json +11 -10
  69. package/standard-react-declarative/public/favicon.svg +16 -0
  70. package/standard-react-declarative/tests/application.spec.ts +30 -0
  71. package/standard-react-imperative/package.json +11 -10
  72. package/standard-react-imperative/public/favicon.svg +16 -0
  73. package/standard-react-imperative/tests/application.spec.ts +30 -0
  74. package/standard-service-declarative/package.json +9 -8
  75. package/standard-service-declarative/tests/Application.spec.ts +22 -94
  76. package/standard-service-imperative/package.json +9 -8
  77. package/standard-service-imperative/tests/Application.spec.ts +22 -78
  78. package/basic-react-declarative/vitest.config.ts +0 -24
  79. package/basic-react-imperative/vitest.config.ts +0 -24
  80. package/basic-service-declarative/vitest.config.ts +0 -24
  81. package/basic-service-imperative/vitest.config.ts +0 -24
  82. package/continuum-showcase/tests/HomePage.spec.tsx +0 -41
  83. package/continuum-showcase/vitest.config.ts +0 -31
  84. package/full-react-declarative/tests/AppLayout.spec.ts +0 -51
  85. package/full-react-declarative/tests/HomePage.spec.ts +0 -38
  86. package/full-react-declarative/vitest.config.ts +0 -24
  87. package/full-react-imperative/tests/HomePage.spec.ts +0 -45
  88. package/full-react-imperative/tests/LayoutHeader.spec.ts +0 -39
  89. package/full-react-imperative/vitest.config.ts +0 -24
  90. package/full-service-declarative/tests/PostService.spec.ts +0 -56
  91. package/full-service-declarative/tests/WelcomeEventHandler.spec.ts +0 -54
  92. package/full-service-declarative/vitest.config.ts +0 -24
  93. package/full-service-imperative/tests/PostService.spec.ts +0 -47
  94. package/full-service-imperative/tests/WelcomeEventHandler.spec.ts +0 -31
  95. package/full-service-imperative/vitest.config.ts +0 -24
  96. package/standard-react-declarative/tests/WelcomePage.spec.ts +0 -71
  97. package/standard-react-declarative/vitest.config.ts +0 -24
  98. package/standard-react-imperative/tests/WelcomePage.spec.ts +0 -53
  99. package/standard-react-imperative/vitest.config.ts +0 -24
  100. package/standard-service-declarative/vitest.config.ts +0 -24
  101. package/standard-service-imperative/vitest.config.ts +0 -24
@@ -1,24 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- include: ['./tests/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
8
- coverage: {
9
- provider: 'v8',
10
- include: ['app/**/*.ts', 'app/**/*.tsx'],
11
- reporter: ['text', 'html'],
12
- reportsDirectory: './coverage',
13
- thresholds: {
14
- 100: true
15
- },
16
- watermarks: {
17
- statements: [60, 80],
18
- functions: [60, 80],
19
- branches: [60, 80],
20
- lines: [60, 80]
21
- }
22
- },
23
- }
24
- });
@@ -1,56 +0,0 @@
1
- import { NotFoundError } from '@stone-js/http-core'
2
- import { PostService } from '../app/services/PostService'
3
- import { PostRepository } from '../app/repositories/PostRepository'
4
- import { Post } from '../app/models/Post'
5
-
6
- // Neutralize the @Service decorator to lighten the test environment,
7
- // while keeping the real `isNotEmpty` helper so we assert real behavior.
8
- vi.mock(import('@stone-js/core'), async (importOriginal) => {
9
- const actual = await importOriginal()
10
- return {
11
- ...actual,
12
- Service: vi.fn(() => vi.fn()),
13
- }
14
- })
15
-
16
- describe('PostService', () => {
17
- let service: PostService
18
- let postRepository: PostRepository
19
-
20
- beforeEach(() => {
21
- postRepository = {
22
- list: vi.fn(),
23
- findById: vi.fn(),
24
- } as unknown as PostRepository
25
-
26
- service = new PostService({ postRepository })
27
- })
28
-
29
- it('should delegate list() to the repository with the given limit', async () => {
30
- // Arrange
31
- const posts = [{ id: 1, title: 'Hello' }] as unknown as Post[]
32
- ;(postRepository.list as any).mockResolvedValue(posts)
33
-
34
- // Act
35
- const result = await service.list(5)
36
-
37
- // Assert
38
- expect(result).toBe(posts)
39
- expect(postRepository.list).toHaveBeenCalledWith({ limit: 5 })
40
- })
41
-
42
- it('should return the post when found and throw NotFoundError otherwise', async () => {
43
- // Arrange
44
- const post = { id: 42, title: 'Answer' } as unknown as Post
45
- ;(postRepository.findById as any).mockResolvedValueOnce(post)
46
-
47
- // Act & Assert (found)
48
- await expect(service.findById(42)).resolves.toBe(post)
49
-
50
- // Arrange (not found)
51
- ;(postRepository.findById as any).mockResolvedValueOnce(undefined)
52
-
53
- // Act & Assert (not found)
54
- await expect(service.findById(99)).rejects.toBeInstanceOf(NotFoundError)
55
- })
56
- })
@@ -1,54 +0,0 @@
1
- import { WelcomeEventHandler } from '../app/handlers/WelcomeEventHandler'
2
- import { IncomingHttpEvent } from '@stone-js/http-core'
3
-
4
- // Neutralize the routing/http decorators to lighten the test environment,
5
- // while asserting the real branded payload the handler returns.
6
- vi.mock(import('@stone-js/router'), async (importOriginal) => {
7
- const actual = await importOriginal()
8
- return {
9
- ...actual,
10
- EventHandler: vi.fn(() => vi.fn()),
11
- Get: vi.fn(() => vi.fn()),
12
- }
13
- })
14
-
15
- vi.mock(import('@stone-js/http-core'), async (importOriginal) => {
16
- const actual = await importOriginal()
17
- return {
18
- ...actual,
19
- JsonHttpResponse: vi.fn(() => vi.fn()),
20
- }
21
- })
22
-
23
- describe('WelcomeEventHandler', () => {
24
- let handler: WelcomeEventHandler
25
-
26
- beforeEach(() => {
27
- handler = new WelcomeEventHandler()
28
- })
29
-
30
- const makeEvent = (name?: string): IncomingHttpEvent => ({
31
- get: vi.fn((_key: string, fallback: string) => name ?? fallback),
32
- }) as unknown as IncomingHttpEvent
33
-
34
- it('should return a branded Stone.js payload greeting the given name', () => {
35
- // Act
36
- const payload = handler.welcome(makeEvent('Ada'))
37
-
38
- // Assert
39
- expect(payload.message).toBe('Hello Ada! Welcome to Stone.js.')
40
- expect(payload.framework.name).toBe('Stone.js')
41
- expect(payload.framework.tagline).toBe('The continuum framework')
42
- expect(payload.framework.docs).toBe('https://stonejs.dev')
43
- expect(payload.framework.github).toBe('https://github.com/stone-foundation/stone-js-framework')
44
- })
45
-
46
- it('should fall back to the default name when none is provided', () => {
47
- // Act
48
- const payload = handler.welcome(makeEvent())
49
-
50
- // Assert
51
- expect(payload.message).toBe('Hello Stone! Welcome to Stone.js.')
52
- expect(payload.framework.name).toBe('Stone.js')
53
- })
54
- })
@@ -1,24 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- include: ['./tests/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
8
- coverage: {
9
- provider: 'v8',
10
- include: ['app/**/*.ts'],
11
- reporter: ['text', 'html'],
12
- reportsDirectory: './coverage',
13
- thresholds: {
14
- 100: true
15
- },
16
- watermarks: {
17
- statements: [60, 80],
18
- functions: [60, 80],
19
- branches: [60, 80],
20
- lines: [60, 80]
21
- }
22
- },
23
- }
24
- });
@@ -1,47 +0,0 @@
1
- import { NotFoundError } from '@stone-js/http-core'
2
- import { factoryPostService } from '../app/services/PostService'
3
- import { IPostService } from '../app/services/contracts/IPostService'
4
- import { IPostRepository } from '../app/repositories/contracts/IPostRepository'
5
- import { Post } from '../app/models/Post'
6
-
7
- describe('factoryPostService', () => {
8
- let service: IPostService
9
- let postRepository: IPostRepository
10
-
11
- beforeEach(() => {
12
- postRepository = {
13
- list: vi.fn(),
14
- findById: vi.fn(),
15
- } as unknown as IPostRepository
16
-
17
- service = factoryPostService({ postRepository })
18
- })
19
-
20
- it('should delegate list() to the repository with the given limit', async () => {
21
- // Arrange
22
- const posts = [{ id: 1, title: 'Hello' }] as unknown as Post[]
23
- ;(postRepository.list as any).mockResolvedValue(posts)
24
-
25
- // Act
26
- const result = await service.list(5)
27
-
28
- // Assert
29
- expect(result).toBe(posts)
30
- expect(postRepository.list).toHaveBeenCalledWith({ limit: 5 })
31
- })
32
-
33
- it('should return the post when found and throw NotFoundError otherwise', async () => {
34
- // Arrange
35
- const post = { id: 42, title: 'Answer' } as unknown as Post
36
- ;(postRepository.findById as any).mockResolvedValueOnce(post)
37
-
38
- // Act & Assert (found)
39
- await expect(service.findById(42)).resolves.toBe(post)
40
-
41
- // Arrange (not found)
42
- ;(postRepository.findById as any).mockResolvedValueOnce(undefined)
43
-
44
- // Act & Assert (not found)
45
- await expect(service.findById(99)).rejects.toBeInstanceOf(NotFoundError)
46
- })
47
- })
@@ -1,31 +0,0 @@
1
- import { IncomingHttpEvent } from '@stone-js/http-core'
2
- import { factoryWelcomeEventHandler, WelcomePayload } from '../app/handlers/WelcomeEventHandler'
3
-
4
- describe('factoryWelcomeEventHandler', () => {
5
- const makeEvent = (name?: string): IncomingHttpEvent => ({
6
- get: vi.fn((_key: string, fallback: string) => name ?? fallback),
7
- }) as unknown as IncomingHttpEvent
8
-
9
- it('should return a branded Stone.js payload greeting the given name', () => {
10
- // Act
11
- const handler = factoryWelcomeEventHandler()
12
- const payload = handler(makeEvent('Ada')) as unknown as WelcomePayload
13
-
14
- // Assert
15
- expect(payload.message).toBe('Hello Ada! Welcome to Stone.js.')
16
- expect(payload.framework.name).toBe('Stone.js')
17
- expect(payload.framework.tagline).toBe('The continuum framework')
18
- expect(payload.framework.docs).toBe('https://stonejs.dev')
19
- expect(payload.framework.github).toBe('https://github.com/stone-foundation/stone-js-framework')
20
- })
21
-
22
- it('should fall back to the default name when none is provided', () => {
23
- // Act
24
- const handler = factoryWelcomeEventHandler()
25
- const payload = handler(makeEvent()) as unknown as WelcomePayload
26
-
27
- // Assert
28
- expect(payload.message).toBe('Hello Stone! Welcome to Stone.js.')
29
- expect(payload.framework.name).toBe('Stone.js')
30
- })
31
- })
@@ -1,24 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- include: ['./tests/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
8
- coverage: {
9
- provider: 'v8',
10
- include: ['app/**/*.ts'],
11
- reporter: ['text', 'html'],
12
- reportsDirectory: './coverage',
13
- thresholds: {
14
- 100: true
15
- },
16
- watermarks: {
17
- statements: [60, 80],
18
- functions: [60, 80],
19
- branches: [60, 80],
20
- lines: [60, 80]
21
- }
22
- },
23
- }
24
- });
@@ -1,71 +0,0 @@
1
- import { ILogger } from '@stone-js/core'
2
- import { renderToString } from 'react-dom/server'
3
- import { ReactIncomingEvent } from '@stone-js/use-react'
4
- import { WelcomePage } from '../app/pages/welcome/WelcomePage'
5
- import { WelcomeService } from '../app/services/WelcomeService'
6
-
7
- // We must mock decorators to lighten the test environment
8
- vi.mock('@stone-js/use-react', async (importOriginal) => {
9
- const actual: any = await importOriginal()
10
- return {
11
- ...actual,
12
- Page: vi.fn(() => vi.fn()),
13
- }
14
- })
15
-
16
- // We must mock decorators to lighten the test environment
17
- vi.mock('@stone-js/core', async (importOriginal) => {
18
- const actual: any = await importOriginal()
19
- return {
20
- ...actual,
21
- Service: vi.fn(() => vi.fn()),
22
- }
23
- })
24
-
25
- describe('WelcomePage', () => {
26
- let page: WelcomePage
27
- let mockedLogger: ILogger
28
-
29
- beforeEach(() => {
30
- mockedLogger = {
31
- info: vi.fn(),
32
- } as unknown as ILogger
33
-
34
- page = new WelcomePage({ welcomeService: new WelcomeService({ logger: mockedLogger }) })
35
- })
36
-
37
- it('should handle incoming events', () => {
38
- // Arrange
39
- const expectedMessage = 'Hello World!'
40
- const event = { get: () => 'World' } as unknown as ReactIncomingEvent
41
-
42
- // Act
43
- const response = page.handle(event)
44
-
45
- // Assert
46
- expect(response.message).toBe(expectedMessage)
47
- expect(mockedLogger.info).toHaveBeenCalledWith('Welcome World')
48
- })
49
-
50
- it('should render the message', () => {
51
- // Arrange
52
- const message = 'Hello World!'
53
-
54
- // Act
55
- const response = renderToString(page.render({ data: { message } } as any))
56
-
57
- // Assert
58
- expect(response).toContain(message)
59
- })
60
-
61
- it('should render the Stone.js logo', () => {
62
- // Act
63
- const response = renderToString(page.render({ data: { message: 'Hello World!' } } as any))
64
-
65
- // Assert
66
- expect(response).toContain('/logo.svg')
67
- expect(response).toContain('alt="Stone.js"')
68
- expect(response).toContain('Welcome')
69
- expect(response).toContain('Stone.js')
70
- })
71
- })
@@ -1,24 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- include: ['./tests/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
8
- coverage: {
9
- provider: 'v8',
10
- include: ['app/**/*.ts', 'app/**/*.tsx'],
11
- reporter: ['text', 'html'],
12
- reportsDirectory: './coverage',
13
- thresholds: {
14
- 100: true
15
- },
16
- watermarks: {
17
- statements: [60, 80],
18
- functions: [60, 80],
19
- branches: [60, 80],
20
- lines: [60, 80]
21
- }
22
- },
23
- }
24
- });
@@ -1,53 +0,0 @@
1
- import { ILogger } from '@stone-js/core'
2
- import { renderToString } from 'react-dom/server'
3
- import { ReactIncomingEvent } from '@stone-js/use-react'
4
- import { WelcomePage } from '../app/pages/welcome/WelcomePage'
5
- import { WelcomeService } from '../app/services/WelcomeService'
6
-
7
- describe('WelcomePage', () => {
8
- let page: any
9
- let mockedLogger: ILogger
10
-
11
- beforeEach(() => {
12
- mockedLogger = {
13
- info: vi.fn(),
14
- } as unknown as ILogger
15
-
16
- page = WelcomePage({ welcomeService: WelcomeService({ logger: mockedLogger }) })
17
- })
18
-
19
- it('should handle incoming events', () => {
20
- // Arrange
21
- const expectedMessage = 'Hello World!'
22
- const event = { get: () => 'World' } as unknown as ReactIncomingEvent
23
-
24
- // Act
25
- const response = page.handle(event) as { message: string }
26
-
27
- // Assert
28
- expect(response.message).toBe(expectedMessage)
29
- expect(mockedLogger.info).toHaveBeenCalledWith('Welcome World')
30
- })
31
-
32
- it('should render the message', () => {
33
- // Arrange
34
- const message = 'Hello World!'
35
-
36
- // Act
37
- const response = renderToString(page.render({ data: { message } } as any))
38
-
39
- // Assert
40
- expect(response).toContain(message)
41
- })
42
-
43
- it('should render the Stone.js logo', () => {
44
- // Act
45
- const response = renderToString(page.render({ data: { message: 'Hello World!' } } as any))
46
-
47
- // Assert
48
- expect(response).toContain('/logo.svg')
49
- expect(response).toContain('alt="Stone.js"')
50
- expect(response).toContain('Welcome')
51
- expect(response).toContain('Stone.js')
52
- })
53
- })
@@ -1,24 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- include: ['./tests/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
8
- coverage: {
9
- provider: 'v8',
10
- include: ['app/**/*.ts', 'app/**/*.tsx'],
11
- reporter: ['text', 'html'],
12
- reportsDirectory: './coverage',
13
- thresholds: {
14
- 100: true
15
- },
16
- watermarks: {
17
- statements: [60, 80],
18
- functions: [60, 80],
19
- branches: [60, 80],
20
- lines: [60, 80]
21
- }
22
- },
23
- }
24
- });
@@ -1,24 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- include: ['./tests/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
8
- coverage: {
9
- provider: 'v8',
10
- include: ['app/**/*.ts'],
11
- reporter: ['text', 'html'],
12
- reportsDirectory: './coverage',
13
- thresholds: {
14
- 100: true
15
- },
16
- watermarks: {
17
- statements: [60, 80],
18
- functions: [60, 80],
19
- branches: [60, 80],
20
- lines: [60, 80]
21
- }
22
- },
23
- }
24
- });
@@ -1,24 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- include: ['./tests/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
8
- coverage: {
9
- provider: 'v8',
10
- include: ['app/**/*.ts'],
11
- reporter: ['text', 'html'],
12
- reportsDirectory: './coverage',
13
- thresholds: {
14
- 100: true
15
- },
16
- watermarks: {
17
- statements: [60, 80],
18
- functions: [60, 80],
19
- branches: [60, 80],
20
- lines: [60, 80]
21
- }
22
- },
23
- }
24
- });