create-oc 0.0.10 → 0.0.12
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 +1 -1
- package/templates/elm/package.json +9 -6
- package/templates/elm/public/logo.png +0 -0
- package/templates/elm/src/Main.elm +58 -69
- package/templates/elm/src/index.js +12 -0
- package/templates/elm/src/server.ts +40 -11
- package/templates/es6/.vscode/extensions.json +3 -0
- package/templates/es6/package.json +11 -12
- package/templates/es6/public/logo.png +0 -0
- package/templates/es6/src/server.ts +50 -0
- package/templates/es6/src/view.ts +33 -0
- package/templates/preact/package.json +4 -3
- package/templates/preact/src/App.tsx +21 -23
- package/templates/preact/src/server.ts +28 -13
- package/templates/preact/tsconfig.json +5 -1
- package/templates/react/package.json +2 -2
- package/templates/react/src/App.tsx +4 -4
- package/templates/react/src/server.ts +1 -1
- package/templates/solid/package.json +2 -2
- package/templates/solid/src/App.tsx +20 -20
- package/templates/solid/src/server.ts +28 -14
- package/templates/vue/package.json +3 -3
- package/templates/vue/src/App.vue +24 -13
- package/templates/vue/src/server.ts +28 -14
- package/templates/es6/css/styles.css +0 -3
- package/templates/es6/img/logo.png +0 -0
- package/templates/es6/server.ts +0 -11
- package/templates/es6/view.ts +0 -10
- package/templates/preact/src/types.ts +0 -15
- package/templates/solid/src/types.ts +0 -15
- package/templates/vue/src/types.ts +0 -15
- /package/templates/{vue → es6}/src/styles.css +0 -0
package/package.json
CHANGED
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|
"files": {
|
|
8
8
|
"data": "src/server.ts",
|
|
9
9
|
"template": {
|
|
10
|
-
"src": "src/
|
|
10
|
+
"src": "src/index.js",
|
|
11
11
|
"type": "oc-template-elm"
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
"static": [
|
|
14
|
+
"public"
|
|
15
|
+
]
|
|
13
16
|
},
|
|
14
17
|
"parameters": {
|
|
15
18
|
"userId": {
|
|
@@ -23,9 +26,9 @@
|
|
|
23
26
|
},
|
|
24
27
|
"dependencies": {},
|
|
25
28
|
"devDependencies": {
|
|
26
|
-
"oc-server": "
|
|
27
|
-
"oc-template-elm-compiler": "
|
|
28
|
-
"elm": "
|
|
29
|
-
"typescript": "
|
|
29
|
+
"oc-server": "^0.3.0",
|
|
30
|
+
"oc-template-elm-compiler": "^0.3.0",
|
|
31
|
+
"elm": "^0.19.1-6",
|
|
32
|
+
"typescript": "^5.3.3"
|
|
30
33
|
}
|
|
31
34
|
}
|
|
Binary file
|
|
@@ -28,18 +28,20 @@ main =
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
type alias Model =
|
|
31
|
-
{
|
|
31
|
+
{ staticPath: String, firstName : String, lastName : String, born : Int, hobbies : List String, funFact: Maybe String }
|
|
32
|
+
|
|
33
|
+
type alias FactModel =
|
|
34
|
+
{ funFact: String }
|
|
32
35
|
|
|
33
36
|
|
|
34
37
|
type alias DataRequest =
|
|
35
|
-
{
|
|
38
|
+
{ year : Int }
|
|
36
39
|
|
|
37
40
|
|
|
38
41
|
encode : DataRequest -> E.Value
|
|
39
42
|
encode data =
|
|
40
43
|
E.object
|
|
41
|
-
[ ( "
|
|
42
|
-
, ( "moreData", E.bool True )
|
|
44
|
+
[ ( "year", E.int data.year )
|
|
43
45
|
]
|
|
44
46
|
|
|
45
47
|
|
|
@@ -50,7 +52,7 @@ init flags =
|
|
|
50
52
|
model
|
|
51
53
|
|
|
52
54
|
Err _ ->
|
|
53
|
-
{
|
|
55
|
+
{ staticPath = "", firstName = "", lastName = "", born = 0, hobbies = [], funFact = Nothing }
|
|
54
56
|
, Cmd.none
|
|
55
57
|
)
|
|
56
58
|
|
|
@@ -70,111 +72,98 @@ isJust data =
|
|
|
70
72
|
|
|
71
73
|
|
|
72
74
|
type Msg
|
|
73
|
-
=
|
|
75
|
+
= GetFunFact
|
|
74
76
|
| Recv E.Value
|
|
75
77
|
|
|
76
78
|
|
|
77
79
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
78
80
|
update msg model =
|
|
79
81
|
case msg of
|
|
80
|
-
|
|
81
|
-
( model, DataRequest model.
|
|
82
|
+
GetFunFact ->
|
|
83
|
+
( model, DataRequest model.born |> encode |> askFunFact )
|
|
82
84
|
|
|
83
85
|
Recv data ->
|
|
84
|
-
( case D.decodeValue
|
|
86
|
+
( case D.decodeValue factDecoder data of
|
|
85
87
|
Ok newModel ->
|
|
86
|
-
newModel
|
|
88
|
+
{ model | funFact = Just newModel }
|
|
87
89
|
|
|
88
90
|
Err _ ->
|
|
89
|
-
{
|
|
91
|
+
{ staticPath = "", firstName = "", lastName = "", born = 0, hobbies = [], funFact = Nothing }
|
|
90
92
|
, Cmd.none
|
|
91
93
|
)
|
|
92
94
|
|
|
93
|
-
|
|
94
|
-
|
|
95
95
|
-- VIEW
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
inputStyle : Style
|
|
99
|
-
inputStyle =
|
|
100
|
-
Css.batch
|
|
101
|
-
[ border3 (px 5) solid (rgb 255 240 255)
|
|
102
|
-
, boxShadow5 inset zero zero (px 8) (rgba 0 0 0 0.1)
|
|
103
|
-
, padding (px 15)
|
|
104
|
-
, backgroundColor (rgba 255 255 255 0.5)
|
|
105
|
-
, margin (px 10)
|
|
106
|
-
]
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
htmlIf : Html msg -> Bool -> Html msg
|
|
110
|
-
htmlIf el cond =
|
|
111
|
-
if cond then
|
|
112
|
-
el
|
|
113
|
-
|
|
114
|
-
else
|
|
115
|
-
text ""
|
|
116
|
-
|
|
117
|
-
|
|
118
97
|
view : Model -> Html Msg
|
|
119
98
|
view model =
|
|
120
|
-
div
|
|
121
|
-
|
|
122
|
-
|
|
99
|
+
div [ css
|
|
100
|
+
[ backgroundColor (hex "3b246c")
|
|
101
|
+
, color (hex "fff")
|
|
102
|
+
, fontFamilies [ "sans-serif" ]
|
|
103
|
+
, padding (px 40)
|
|
123
104
|
]
|
|
124
105
|
]
|
|
125
|
-
[
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
,
|
|
129
|
-
,
|
|
130
|
-
|
|
131
|
-
[]
|
|
132
|
-
|
|
133
|
-
[ css [ inputStyle ]
|
|
134
|
-
, type_ "text"
|
|
135
|
-
, placeholder "Email"
|
|
136
|
-
, value model.email
|
|
106
|
+
[ img [ Html.Styled.Attributes.width 50, Html.Styled.Attributes.height 50, src (model.staticPath ++ "public/logo.png"), alt "Logo" ] []
|
|
107
|
+
, h1 [ css [ margin4 (px 0) (px 0) (px 20) (px 0) ] ]
|
|
108
|
+
[ text ("Hello, ")
|
|
109
|
+
, span [ css [ textDecoration underline ] ] [text (model.firstName)]
|
|
110
|
+
, text( " " ++ model.lastName ) ]
|
|
111
|
+
, div [ css [ marginBottom (px 20) ] ]
|
|
112
|
+
[ div [ css [ margin2 (px 6) (px 0) ] ] [ text ("Born: " ++ String.fromInt model.born) ]
|
|
113
|
+
, div [ css [ margin2 (px 6) (px 0) ] ] [ text ("Hobbies: " ++ String.join ", " (List.map String.toLower model.hobbies)) ]
|
|
137
114
|
]
|
|
138
|
-
|
|
139
|
-
, case model.age of
|
|
115
|
+
, case model.funFact of
|
|
140
116
|
Nothing ->
|
|
141
117
|
text ""
|
|
142
118
|
|
|
143
|
-
Just
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
119
|
+
Just fact ->
|
|
120
|
+
div [] [text (fact)]
|
|
121
|
+
, button [ css
|
|
122
|
+
[ backgroundColor (hex "a97613")
|
|
123
|
+
, border (px 0)
|
|
124
|
+
, padding2 (px 15) (px 32)
|
|
125
|
+
, textAlign center
|
|
126
|
+
, fontSize (px 16)
|
|
127
|
+
, textDecoration none
|
|
128
|
+
, display inlineBlock
|
|
129
|
+
, color inherit
|
|
130
|
+
, cursor pointer
|
|
131
|
+
]
|
|
132
|
+
, onClick GetFunFact
|
|
133
|
+
]
|
|
134
|
+
[ text "Fun year fact" ]
|
|
135
|
+
|
|
152
136
|
]
|
|
153
137
|
|
|
154
138
|
|
|
155
|
-
|
|
156
139
|
-- SUBSCRIPTIONS
|
|
157
140
|
|
|
158
141
|
|
|
159
142
|
subscriptions : Model -> Sub Msg
|
|
160
143
|
subscriptions _ =
|
|
161
|
-
|
|
144
|
+
getFunFact Recv
|
|
162
145
|
|
|
163
146
|
|
|
164
147
|
decoder : D.Decoder Model
|
|
165
148
|
decoder =
|
|
166
|
-
D.
|
|
167
|
-
(D.field "
|
|
168
|
-
(D.field "
|
|
169
|
-
(D.field "
|
|
170
|
-
(D.
|
|
149
|
+
D.map6 Model
|
|
150
|
+
(D.field "staticPath" D.string)
|
|
151
|
+
(D.field "firstName" D.string)
|
|
152
|
+
(D.field "lastName" D.string)
|
|
153
|
+
(D.field "born" D.int)
|
|
154
|
+
(D.field "hobbies" (D.list D.string))
|
|
155
|
+
(D.maybe (D.field "funFact" D.string))
|
|
171
156
|
|
|
157
|
+
-- decoder of a single string field
|
|
158
|
+
factDecoder : D.Decoder String
|
|
159
|
+
factDecoder =
|
|
160
|
+
D.field "funFact" D.string
|
|
172
161
|
|
|
173
162
|
|
|
174
163
|
-- PORTS
|
|
175
164
|
|
|
176
165
|
|
|
177
|
-
port
|
|
166
|
+
port askFunFact : E.Value -> Cmd msg
|
|
178
167
|
|
|
179
168
|
|
|
180
|
-
port
|
|
169
|
+
port getFunFact : (E.Value -> msg) -> Sub msg
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { serverClient } from 'oc-server';
|
|
2
|
+
import { Elm } from './Main.elm';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
js: (app) => {
|
|
6
|
+
app.ports.askFunFact.subscribe(async (params) => {
|
|
7
|
+
const data = await serverClient.funFact(params);
|
|
8
|
+
app.ports.getFunFact.send(data);
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
program: Elm.Main,
|
|
12
|
+
};
|
|
@@ -1,22 +1,51 @@
|
|
|
1
1
|
import { Server } from 'oc-server';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
{ name: 'John Doe',
|
|
5
|
-
{ name: 'Jane Doe',
|
|
3
|
+
const userDatabase = [
|
|
4
|
+
{ name: 'John Doe', born: 1986, hobbies: ['Swimming', 'Basketball'] },
|
|
5
|
+
{ name: 'Jane Doe', born: 1991, hobbies: ['Running', 'Rugby'] },
|
|
6
6
|
];
|
|
7
7
|
|
|
8
|
+
const yearsFunFactDatabase: Record<number, string> = {
|
|
9
|
+
1986: "Halley's Comet made its closest approach to Earth in 1986, visible to the naked eye.",
|
|
10
|
+
1987: 'The first Final Fantasy game was released in 1987.',
|
|
11
|
+
1991: 'The first web page was created in 1991 by Tim Berners-Lee.',
|
|
12
|
+
};
|
|
13
|
+
|
|
8
14
|
async function getUser(userId: number) {
|
|
9
|
-
return
|
|
15
|
+
return userDatabase[userId];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function getFunFact(year: number) {
|
|
19
|
+
return yearsFunFactDatabase[year];
|
|
10
20
|
}
|
|
11
21
|
|
|
12
|
-
export const server = new Server(async (params: { userId: number
|
|
13
|
-
const {
|
|
14
|
-
const
|
|
22
|
+
export const server = new Server(async (params: { userId: number }, ctx) => {
|
|
23
|
+
const { userId } = params;
|
|
24
|
+
const user = await getUser(userId);
|
|
25
|
+
const [firstName, lastName] = user.name.split(/\s+/);
|
|
26
|
+
|
|
27
|
+
if (firstName === 'Invalid') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
15
30
|
|
|
16
31
|
return {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
firstName,
|
|
33
|
+
lastName,
|
|
34
|
+
born: user.born,
|
|
35
|
+
hobbies: user.hobbies,
|
|
36
|
+
staticPath: ctx.staticPath,
|
|
37
|
+
};
|
|
38
|
+
}).action('funFact', async (params: { year: number }) => {
|
|
39
|
+
const { year } = params;
|
|
40
|
+
const funFact = await getFunFact(year);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
funFact,
|
|
21
44
|
};
|
|
22
45
|
});
|
|
46
|
+
|
|
47
|
+
declare module 'oc-server' {
|
|
48
|
+
interface Register {
|
|
49
|
+
server: typeof server;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -4,28 +4,27 @@
|
|
|
4
4
|
"version": "1.0.0",
|
|
5
5
|
"oc": {
|
|
6
6
|
"files": {
|
|
7
|
-
"data": "server.
|
|
7
|
+
"data": "src/server.ts",
|
|
8
8
|
"static": [
|
|
9
|
-
"
|
|
10
|
-
"css"
|
|
9
|
+
"public"
|
|
11
10
|
],
|
|
12
11
|
"template": {
|
|
13
|
-
"src": "view.
|
|
12
|
+
"src": "src/view.ts",
|
|
14
13
|
"type": "oc-template-es6"
|
|
15
14
|
}
|
|
16
15
|
},
|
|
17
16
|
"parameters": {
|
|
18
|
-
"
|
|
19
|
-
"default":
|
|
20
|
-
"description": "
|
|
21
|
-
"example":
|
|
22
|
-
"mandatory":
|
|
23
|
-
"type": "
|
|
17
|
+
"userId": {
|
|
18
|
+
"default": 1,
|
|
19
|
+
"description": "The user id from the user database",
|
|
20
|
+
"example": 1,
|
|
21
|
+
"mandatory": true,
|
|
22
|
+
"type": "number"
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
|
-
"oc-server": "
|
|
29
|
-
"oc-template-es6-compiler": "
|
|
27
|
+
"oc-server": "^0.3.0",
|
|
28
|
+
"oc-template-es6-compiler": "^4.0.3"
|
|
30
29
|
}
|
|
31
30
|
}
|
|
Binary file
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Server } from 'oc-server';
|
|
2
|
+
|
|
3
|
+
const userDatabase = [
|
|
4
|
+
{ name: 'John Doe', born: 1986, hobbies: ['Swimming', 'Basketball'] },
|
|
5
|
+
{ name: 'Jane Doe', born: 1991, hobbies: ['Running', 'Rugby'] },
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
const yearsFunFactDatabase: Record<number, string> = {
|
|
9
|
+
1986: "Halley's Comet made its closest approach to Earth in 1986, visible to the naked eye.",
|
|
10
|
+
1987: 'The first Final Fantasy game was released in 1987.',
|
|
11
|
+
1991: 'The first web page was created in 1991 by Tim Berners-Lee.',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
async function getUser(userId: number) {
|
|
15
|
+
return userDatabase[userId];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function getFunFact(year: number) {
|
|
19
|
+
return yearsFunFactDatabase[year];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const server = new Server(async (params: { userId: number }) => {
|
|
23
|
+
const { userId } = params;
|
|
24
|
+
const user = await getUser(userId);
|
|
25
|
+
const [firstName, lastName] = user.name.split(/\s+/);
|
|
26
|
+
|
|
27
|
+
if (firstName === 'Invalid') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
firstName,
|
|
33
|
+
lastName,
|
|
34
|
+
born: user.born,
|
|
35
|
+
hobbies: user.hobbies,
|
|
36
|
+
};
|
|
37
|
+
}).action('funFact', async (params: { year: number }) => {
|
|
38
|
+
const { year } = params;
|
|
39
|
+
const funFact = await getFunFact(year);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
funFact,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
declare module 'oc-server' {
|
|
47
|
+
interface Register {
|
|
48
|
+
server: typeof server;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { InitialData, serverClient } from 'oc-server';
|
|
2
|
+
import styles from './styles.css';
|
|
3
|
+
import logo from '../public/logo.png';
|
|
4
|
+
|
|
5
|
+
declare const window: Window & {
|
|
6
|
+
getFunFact: () => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default ({ firstName, lastName, hobbies, born }: InitialData) => {
|
|
10
|
+
window.getFunFact = async () => {
|
|
11
|
+
const { funFact } = await serverClient.funFact({ year: born });
|
|
12
|
+
document.querySelector('#funfact')!.innerHTML = funFact;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return /* html */ `
|
|
16
|
+
<div class="${styles.container}">
|
|
17
|
+
<img width="50" height="50" src="${logo}" alt="Logo" />
|
|
18
|
+
<h1 style="margin: 0 0 20px 0;">
|
|
19
|
+
Hello, <span style="text-decoration: underline;">${firstName}</span> ${lastName}
|
|
20
|
+
</h1>
|
|
21
|
+
<div class=${styles.info}>
|
|
22
|
+
<div class=${styles.block}>Born: ${born}</div>
|
|
23
|
+
<div class=${styles.block}>
|
|
24
|
+
<div>Hobbies: ${hobbies.map((x) => x.toLowerCase()).join(', ')}</div>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
<div id="funfact"></div>
|
|
28
|
+
<button class=${styles.button} onclick="getFunFact()">
|
|
29
|
+
Fun year fact
|
|
30
|
+
</button>
|
|
31
|
+
</div>
|
|
32
|
+
`;
|
|
33
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "base-component-
|
|
2
|
+
"name": "base-component-preact",
|
|
3
3
|
"description": "",
|
|
4
4
|
"version": "1.0.0",
|
|
5
5
|
"scripts": {
|
|
@@ -30,11 +30,12 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@preact/preset-vite": "^2.7.0",
|
|
33
34
|
"@testing-library/react": "^14.0.0",
|
|
34
35
|
"@testing-library/user-event": "^14.4.3",
|
|
35
36
|
"jsdom": "^21.1.1",
|
|
36
|
-
"oc-server": "
|
|
37
|
-
"oc-template-preact-compiler": "0.
|
|
37
|
+
"oc-server": "^0.3.0",
|
|
38
|
+
"oc-template-preact-compiler": "^0.4.1",
|
|
38
39
|
"preact": "^10.13.2",
|
|
39
40
|
"typescript": "5.0.2",
|
|
40
41
|
"vitest": "^0.29.7"
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import { useState } from 'preact/hooks';
|
|
2
|
-
import {
|
|
3
|
-
import { serverClient } from 'oc-server';
|
|
2
|
+
import { ActionOutput, InitialData, serverClient } from 'oc-server';
|
|
4
3
|
import styles from './styles.css';
|
|
5
|
-
import
|
|
4
|
+
import logo from '../public/logo.png';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
getMoreData?: boolean;
|
|
9
|
-
}
|
|
6
|
+
type AdditionalData = ActionOutput<'funFact'>;
|
|
10
7
|
|
|
11
|
-
const App = () => {
|
|
12
|
-
const { firstName, lastName,
|
|
13
|
-
const
|
|
14
|
-
|
|
8
|
+
const App = (props: InitialData) => {
|
|
9
|
+
const { firstName, lastName, born, hobbies } = props;
|
|
10
|
+
const [additionalData, setAdditionalData] = useState<AdditionalData | null>(
|
|
11
|
+
null
|
|
12
|
+
);
|
|
15
13
|
const [error, setError] = useState('');
|
|
16
14
|
|
|
17
|
-
const
|
|
15
|
+
const getFunFact = async () => {
|
|
18
16
|
setError('');
|
|
19
17
|
try {
|
|
20
|
-
const data = await serverClient.
|
|
18
|
+
const data = await serverClient.funFact({ year: born });
|
|
21
19
|
setAdditionalData(data);
|
|
22
20
|
} catch (err) {
|
|
23
21
|
setError(String(err));
|
|
@@ -30,20 +28,20 @@ const App = () => {
|
|
|
30
28
|
|
|
31
29
|
return (
|
|
32
30
|
<div className={styles.container}>
|
|
33
|
-
<img width="50" height="50" src={
|
|
31
|
+
<img width="50" height="50" src={logo} alt="Logo" />
|
|
34
32
|
<h1 style={{ margin: '0 0 20px 0' }}>
|
|
35
|
-
Hello, <span style={{ textDecoration: 'underline' }}>{firstName}</span>
|
|
33
|
+
Hello, <span style={{ textDecoration: 'underline' }}>{firstName}</span>{' '}
|
|
34
|
+
{lastName}
|
|
36
35
|
</h1>
|
|
37
|
-
{
|
|
38
|
-
<div className={styles.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Hobbies: {additionalData.hobbies.map((x) => x.toLowerCase()).join(', ')}
|
|
42
|
-
</div>
|
|
36
|
+
<div className={styles.info}>
|
|
37
|
+
<div className={styles.block}>Born: {born}</div>
|
|
38
|
+
<div className={styles.block}>
|
|
39
|
+
Hobbies: {hobbies.map((x) => x.toLowerCase()).join(', ')}
|
|
43
40
|
</div>
|
|
44
|
-
|
|
45
|
-
<
|
|
46
|
-
|
|
41
|
+
</div>
|
|
42
|
+
{additionalData && <div>{additionalData.funFact}</div>}
|
|
43
|
+
<button className={styles.button} onClick={getFunFact}>
|
|
44
|
+
Fun year fact
|
|
47
45
|
</button>
|
|
48
46
|
</div>
|
|
49
47
|
);
|
|
@@ -1,30 +1,45 @@
|
|
|
1
1
|
import { Server } from 'oc-server';
|
|
2
|
-
import { AdditionalData, ClientProps, OcParameters } from './types';
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
{ name: 'John Doe',
|
|
6
|
-
{ name: 'Jane Doe',
|
|
3
|
+
const userDatabase = [
|
|
4
|
+
{ name: 'John Doe', born: 1986, hobbies: ['Swimming', 'Basketball'] },
|
|
5
|
+
{ name: 'Jane Doe', born: 1991, hobbies: ['Running', 'Rugby'] },
|
|
7
6
|
];
|
|
8
7
|
|
|
8
|
+
const yearsFunFactDatabase: Record<number, string> = {
|
|
9
|
+
1986: "Halley's Comet made its closest approach to Earth in 1986, visible to the naked eye.",
|
|
10
|
+
1987: 'The first Final Fantasy game was released in 1987.',
|
|
11
|
+
1991: 'The first web page was created in 1991 by Tim Berners-Lee.',
|
|
12
|
+
};
|
|
13
|
+
|
|
9
14
|
async function getUser(userId: number) {
|
|
10
|
-
return
|
|
15
|
+
return userDatabase[userId];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function getFunFact(year: number) {
|
|
19
|
+
return yearsFunFactDatabase[year];
|
|
11
20
|
}
|
|
12
21
|
|
|
13
|
-
export const server = new Server(async (params:
|
|
14
|
-
const
|
|
22
|
+
export const server = new Server(async (params: { userId: number }) => {
|
|
23
|
+
const { userId } = params;
|
|
24
|
+
const user = await getUser(userId);
|
|
15
25
|
const [firstName, lastName] = user.name.split(/\s+/);
|
|
16
26
|
|
|
27
|
+
if (firstName === 'Invalid') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
17
31
|
return {
|
|
18
|
-
userId: params.userId,
|
|
19
32
|
firstName,
|
|
20
|
-
lastName
|
|
33
|
+
lastName,
|
|
34
|
+
born: user.born,
|
|
35
|
+
hobbies: user.hobbies,
|
|
21
36
|
};
|
|
22
|
-
}).action('
|
|
23
|
-
const
|
|
37
|
+
}).action('funFact', async (params: { year: number }) => {
|
|
38
|
+
const { year } = params;
|
|
39
|
+
const funFact = await getFunFact(year);
|
|
24
40
|
|
|
25
41
|
return {
|
|
26
|
-
|
|
27
|
-
hobbies: user.hobbies
|
|
42
|
+
funFact,
|
|
28
43
|
};
|
|
29
44
|
});
|
|
30
45
|
|
|
@@ -20,7 +20,11 @@
|
|
|
20
20
|
"resolveJsonModule": true,
|
|
21
21
|
"isolatedModules": true,
|
|
22
22
|
"jsx": "react-jsx",
|
|
23
|
-
"jsxImportSource": "preact"
|
|
23
|
+
"jsxImportSource": "preact",
|
|
24
|
+
"paths": {
|
|
25
|
+
"react": ["./node_modules/preact/compat/"],
|
|
26
|
+
"react-dom": ["./node_modules/preact/compat/"]
|
|
27
|
+
}
|
|
24
28
|
},
|
|
25
29
|
"include": ["src"],
|
|
26
30
|
"exclude": ["src/_package"]
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@testing-library/user-event": "^14.4.3",
|
|
35
35
|
"@types/react": "^18.0.28",
|
|
36
36
|
"jsdom": "^21.1.1",
|
|
37
|
-
"oc-server": "
|
|
38
|
-
"oc-template-react-compiler": "^6.
|
|
37
|
+
"oc-server": "^0.3.0",
|
|
38
|
+
"oc-template-react-compiler": "^6.1.0",
|
|
39
39
|
"react": "18.2.0",
|
|
40
40
|
"react-dom": "18.2.0",
|
|
41
41
|
"typescript": "5.1.3",
|
|
@@ -3,7 +3,7 @@ import { serverClient, InitialData, ActionOutput } from 'oc-server';
|
|
|
3
3
|
import styles from './styles.css';
|
|
4
4
|
import logo from '../public/logo.png';
|
|
5
5
|
|
|
6
|
-
type AdditionalData = ActionOutput<'
|
|
6
|
+
type AdditionalData = ActionOutput<'funFact'>;
|
|
7
7
|
|
|
8
8
|
const App: React.FC<InitialData> = (props: InitialData) => {
|
|
9
9
|
const { firstName, lastName, born, hobbies } = props;
|
|
@@ -12,10 +12,10 @@ const App: React.FC<InitialData> = (props: InitialData) => {
|
|
|
12
12
|
);
|
|
13
13
|
const [error, setError] = useState('');
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const getFunFact = async () => {
|
|
16
16
|
setError('');
|
|
17
17
|
try {
|
|
18
|
-
const data = await serverClient.
|
|
18
|
+
const data = await serverClient.funFact({ year: born });
|
|
19
19
|
setAdditionalData(data);
|
|
20
20
|
} catch (err) {
|
|
21
21
|
setError(String(err));
|
|
@@ -40,7 +40,7 @@ const App: React.FC<InitialData> = (props: InitialData) => {
|
|
|
40
40
|
</div>
|
|
41
41
|
</div>
|
|
42
42
|
{additionalData && <div>{additionalData.funFact}</div>}
|
|
43
|
-
<button className={styles.button} onClick={
|
|
43
|
+
<button className={styles.button} onClick={getFunFact}>
|
|
44
44
|
Fun year fact
|
|
45
45
|
</button>
|
|
46
46
|
</div>
|
|
@@ -34,7 +34,7 @@ export const server = new Server(async (params: { userId: number }) => {
|
|
|
34
34
|
born: user.born,
|
|
35
35
|
hobbies: user.hobbies,
|
|
36
36
|
};
|
|
37
|
-
}).action('
|
|
37
|
+
}).action('funFact', async (params: { year: number }) => {
|
|
38
38
|
const { year } = params;
|
|
39
39
|
const funFact = await getFunFact(year);
|
|
40
40
|
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"@testing-library/jest-dom": "^5.16.5",
|
|
34
34
|
"@types/testing-library__jest-dom": "^5.14.5",
|
|
35
35
|
"jsdom": "^21.1.1",
|
|
36
|
-
"oc-server": "
|
|
37
|
-
"oc-template-solid-compiler": "
|
|
36
|
+
"oc-server": "^0.3.0",
|
|
37
|
+
"oc-template-solid-compiler": "^0.7.0",
|
|
38
38
|
"solid-js": "^1.8.7",
|
|
39
39
|
"typescript": "5.0.2",
|
|
40
40
|
"vitest": "^0.29.7"
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import { createSignal, Show, For } from 'solid-js';
|
|
2
|
-
import {
|
|
3
|
-
import { serverClient } from 'oc-server';
|
|
2
|
+
import { serverClient, InitialData, ActionOutput } from 'oc-server';
|
|
4
3
|
import styles from './styles.css';
|
|
5
|
-
import
|
|
4
|
+
import logo from '../public/logo.png';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
getMoreData?: boolean;
|
|
9
|
-
}
|
|
6
|
+
type AdditionalData = ActionOutput<'funFact'>;
|
|
10
7
|
|
|
11
|
-
const App = () => {
|
|
12
|
-
const { firstName, lastName,
|
|
13
|
-
const
|
|
14
|
-
|
|
8
|
+
const App = (props: InitialData) => {
|
|
9
|
+
const { firstName, lastName, born, hobbies } = props;
|
|
10
|
+
const [additionalData, setAdditionalData] =
|
|
11
|
+
createSignal<AdditionalData | null>(null);
|
|
15
12
|
const [error, setError] = createSignal('');
|
|
16
13
|
|
|
17
14
|
async function handleClick() {
|
|
18
|
-
const data = await serverClient.
|
|
15
|
+
const data = await serverClient.funFact({ year: born });
|
|
19
16
|
|
|
20
17
|
try {
|
|
21
18
|
setAdditionalData(data);
|
|
@@ -27,20 +24,23 @@ const App = () => {
|
|
|
27
24
|
return (
|
|
28
25
|
<Show when={!error()} fallback={<div>Something wrong happened!</div>}>
|
|
29
26
|
<div class={styles.container}>
|
|
30
|
-
<img width="50" height="50" src={
|
|
27
|
+
<img width="50" height="50" src={logo} alt="Logo" />
|
|
31
28
|
<h1 style={{ margin: '0 0 20px 0' }}>
|
|
32
|
-
Hello,
|
|
29
|
+
Hello,{' '}
|
|
30
|
+
<span style={{ 'text-decoration': 'underline' }}>{firstName}</span>{' '}
|
|
31
|
+
{lastName}
|
|
33
32
|
</h1>
|
|
34
|
-
<
|
|
35
|
-
<div class={styles.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Hobbies: <For each={additionalData()!.hobbies}>{(hobby) => <div>{hobby}</div>}</For>
|
|
39
|
-
</div>
|
|
33
|
+
<div class={styles.info}>
|
|
34
|
+
<div class={styles.block}>Born: {born}</div>
|
|
35
|
+
<div class={styles.block}>
|
|
36
|
+
Hobbies: {hobbies.map((x) => x.toLowerCase()).join(', ')}
|
|
40
37
|
</div>
|
|
38
|
+
</div>
|
|
39
|
+
<Show when={additionalData()}>
|
|
40
|
+
<div>{additionalData()!.funFact}</div>
|
|
41
41
|
</Show>
|
|
42
42
|
<button class={styles.button} onClick={handleClick}>
|
|
43
|
-
|
|
43
|
+
Fun year fact
|
|
44
44
|
</button>
|
|
45
45
|
</div>
|
|
46
46
|
</Show>
|
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
import { Server } from 'oc-server';
|
|
2
|
-
import { ClientProps, OcParameters } from './types';
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
{ name: 'John Doe',
|
|
6
|
-
{ name: 'Jane Doe',
|
|
3
|
+
const userDatabase = [
|
|
4
|
+
{ name: 'John Doe', born: 1986, hobbies: ['Swimming', 'Basketball'] },
|
|
5
|
+
{ name: 'Jane Doe', born: 1991, hobbies: ['Running', 'Rugby'] },
|
|
7
6
|
];
|
|
8
7
|
|
|
8
|
+
const yearsFunFactDatabase: Record<number, string> = {
|
|
9
|
+
1986: "Halley's Comet made its closest approach to Earth in 1986, visible to the naked eye.",
|
|
10
|
+
1987: 'The first Final Fantasy game was released in 1987.',
|
|
11
|
+
1991: 'The first web page was created in 1991 by Tim Berners-Lee.',
|
|
12
|
+
};
|
|
13
|
+
|
|
9
14
|
async function getUser(userId: number) {
|
|
10
|
-
return
|
|
15
|
+
return userDatabase[userId];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function getFunFact(year: number) {
|
|
19
|
+
return yearsFunFactDatabase[year];
|
|
11
20
|
}
|
|
12
21
|
|
|
13
|
-
export const server = new Server(async (params:
|
|
22
|
+
export const server = new Server(async (params: { userId: number }) => {
|
|
14
23
|
const { userId } = params;
|
|
15
24
|
const user = await getUser(userId);
|
|
16
|
-
|
|
17
25
|
const [firstName, lastName] = user.name.split(/\s+/);
|
|
26
|
+
|
|
27
|
+
if (firstName === 'Invalid') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
return {
|
|
19
|
-
userId,
|
|
20
32
|
firstName,
|
|
21
|
-
lastName
|
|
33
|
+
lastName,
|
|
34
|
+
born: user.born,
|
|
35
|
+
hobbies: user.hobbies,
|
|
22
36
|
};
|
|
23
|
-
}).action('
|
|
24
|
-
const {
|
|
25
|
-
const
|
|
37
|
+
}).action('funFact', async (params: { year: number }) => {
|
|
38
|
+
const { year } = params;
|
|
39
|
+
const funFact = await getFunFact(year);
|
|
40
|
+
|
|
26
41
|
return {
|
|
27
|
-
|
|
28
|
-
hobbies: user.hobbies
|
|
42
|
+
funFact,
|
|
29
43
|
};
|
|
30
44
|
});
|
|
31
45
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "base-component-
|
|
2
|
+
"name": "base-component-vue",
|
|
3
3
|
"description": "",
|
|
4
4
|
"version": "1.0.0",
|
|
5
5
|
"scripts": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"@types/testing-library__jest-dom": "^5.14.5",
|
|
34
34
|
"@vitejs/plugin-vue": "^5.0.0",
|
|
35
35
|
"jsdom": "^21.1.1",
|
|
36
|
-
"oc-server": "
|
|
37
|
-
"oc-template-vue-compiler": "
|
|
36
|
+
"oc-server": "^0.3.0",
|
|
37
|
+
"oc-template-vue-compiler": "^0.2.0",
|
|
38
38
|
"typescript": "5.0.2",
|
|
39
39
|
"vitest": "^0.29.7",
|
|
40
40
|
"vue": "^3.3.11",
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import { ref } from 'vue'
|
|
3
3
|
import logo from '../public/logo.png';
|
|
4
4
|
import { serverClient, ActionOutput } from 'oc-server'
|
|
5
|
-
const props = defineProps<{
|
|
5
|
+
const props = defineProps<{ firstName: string, lastName: string, born: number, hobbies: string[] }>()
|
|
6
6
|
|
|
7
|
-
const additionalData = ref<ActionOutput<'
|
|
8
|
-
async function
|
|
9
|
-
additionalData.value = await serverClient.
|
|
7
|
+
const additionalData = ref<ActionOutput<'funFact'> | null>(null);
|
|
8
|
+
async function getFunFact() {
|
|
9
|
+
additionalData.value = await serverClient.funFact({ year: props.born });
|
|
10
10
|
}
|
|
11
|
+
const hobbies = props.hobbies.map((x) => x.toLowerCase()).join(', ')
|
|
11
12
|
</script>
|
|
12
13
|
|
|
13
14
|
<template>
|
|
@@ -17,17 +18,15 @@ async function getAdditionalData() {
|
|
|
17
18
|
<h1>
|
|
18
19
|
Hello, <span>{{ firstName }}</span> {{ lastName }}
|
|
19
20
|
</h1>
|
|
20
|
-
<div className=
|
|
21
|
-
<div className=
|
|
22
|
-
<div className=
|
|
23
|
-
Hobbies:
|
|
24
|
-
<span v-for="hobby in additionalData.hobbies" :key="hobby">
|
|
25
|
-
{{ hobby.toLowerCase() }}
|
|
26
|
-
</span>
|
|
21
|
+
<div className="info">
|
|
22
|
+
<div className="block">Born: {{ born }}</div>
|
|
23
|
+
<div className="block">
|
|
24
|
+
Hobbies: {{ hobbies }}
|
|
27
25
|
</div>
|
|
28
26
|
</div>
|
|
29
|
-
<
|
|
30
|
-
|
|
27
|
+
<div v-if="additionalData">{{ additionalData?.funFact }}</div>
|
|
28
|
+
<button className="button" @click="getFunFact">
|
|
29
|
+
Fun year fact
|
|
31
30
|
</button>
|
|
32
31
|
</div>
|
|
33
32
|
</template>
|
|
@@ -52,6 +51,10 @@ async function getAdditionalData() {
|
|
|
52
51
|
cursor: pointer;
|
|
53
52
|
}
|
|
54
53
|
|
|
54
|
+
.button:hover {
|
|
55
|
+
background-color: #c79535;
|
|
56
|
+
}
|
|
57
|
+
|
|
55
58
|
h1 {
|
|
56
59
|
margin: 0 0 20px 0;
|
|
57
60
|
}
|
|
@@ -59,4 +62,12 @@ h1 {
|
|
|
59
62
|
span {
|
|
60
63
|
text-decoration: underline;
|
|
61
64
|
}
|
|
65
|
+
|
|
66
|
+
.info {
|
|
67
|
+
margin-bottom: 20px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.block {
|
|
71
|
+
margin: 6px 0;
|
|
72
|
+
}
|
|
62
73
|
</style>
|
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
import { Server } from 'oc-server';
|
|
2
|
-
import { ClientProps, OcParameters } from './types';
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
{ name: 'John Doe',
|
|
6
|
-
{ name: 'Jane Doe',
|
|
3
|
+
const userDatabase = [
|
|
4
|
+
{ name: 'John Doe', born: 1986, hobbies: ['Swimming', 'Basketball'] },
|
|
5
|
+
{ name: 'Jane Doe', born: 1991, hobbies: ['Running', 'Rugby'] },
|
|
7
6
|
];
|
|
8
7
|
|
|
8
|
+
const yearsFunFactDatabase: Record<number, string> = {
|
|
9
|
+
1986: "Halley's Comet made its closest approach to Earth in 1986, visible to the naked eye.",
|
|
10
|
+
1987: 'The first Final Fantasy game was released in 1987.',
|
|
11
|
+
1991: 'The first web page was created in 1991 by Tim Berners-Lee.',
|
|
12
|
+
};
|
|
13
|
+
|
|
9
14
|
async function getUser(userId: number) {
|
|
10
|
-
return
|
|
15
|
+
return userDatabase[userId];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function getFunFact(year: number) {
|
|
19
|
+
return yearsFunFactDatabase[year];
|
|
11
20
|
}
|
|
12
21
|
|
|
13
|
-
export const server = new Server(async (params:
|
|
22
|
+
export const server = new Server(async (params: { userId: number }) => {
|
|
14
23
|
const { userId } = params;
|
|
15
24
|
const user = await getUser(userId);
|
|
16
|
-
|
|
17
25
|
const [firstName, lastName] = user.name.split(/\s+/);
|
|
26
|
+
|
|
27
|
+
if (firstName === 'Invalid') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
return {
|
|
19
|
-
userId,
|
|
20
32
|
firstName,
|
|
21
|
-
lastName
|
|
33
|
+
lastName,
|
|
34
|
+
born: user.born,
|
|
35
|
+
hobbies: user.hobbies,
|
|
22
36
|
};
|
|
23
|
-
}).action('
|
|
24
|
-
const {
|
|
25
|
-
const
|
|
37
|
+
}).action('funFact', async (params: { year: number }) => {
|
|
38
|
+
const { year } = params;
|
|
39
|
+
const funFact = await getFunFact(year);
|
|
40
|
+
|
|
26
41
|
return {
|
|
27
|
-
|
|
28
|
-
hobbies: user.hobbies
|
|
42
|
+
funFact,
|
|
29
43
|
};
|
|
30
44
|
});
|
|
31
45
|
|
|
Binary file
|
package/templates/es6/server.ts
DELETED
package/templates/es6/view.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface OcParameters {
|
|
2
|
-
userId: number;
|
|
3
|
-
getMoreData?: boolean;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface AdditionalData {
|
|
7
|
-
hobbies: string[];
|
|
8
|
-
age: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ClientProps extends Partial<AdditionalData> {
|
|
12
|
-
userId: number;
|
|
13
|
-
firstName: string;
|
|
14
|
-
lastName: string;
|
|
15
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface OcParameters {
|
|
2
|
-
userId: number;
|
|
3
|
-
getMoreData?: boolean;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface AdditionalData {
|
|
7
|
-
hobbies: string[];
|
|
8
|
-
age: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ClientProps extends Partial<AdditionalData> {
|
|
12
|
-
userId: number;
|
|
13
|
-
firstName: string;
|
|
14
|
-
lastName: string;
|
|
15
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface OcParameters {
|
|
2
|
-
userId: number;
|
|
3
|
-
getMoreData?: boolean;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface AdditionalData {
|
|
7
|
-
hobbies: string[];
|
|
8
|
-
age: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ClientProps extends Partial<AdditionalData> {
|
|
12
|
-
userId: number;
|
|
13
|
-
firstName: string;
|
|
14
|
-
lastName: string;
|
|
15
|
-
}
|
|
File without changes
|