oc 0.50.44 → 0.50.47

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,25 +0,0 @@
1
- {
2
- "name": "test",
3
- "description": "",
4
- "version": "1.0.0",
5
- "scripts": {
6
- "dev": "oc-server dev",
7
- "start": "oc dev .. --components test"
8
- },
9
- "oc": {
10
- "files": {
11
- "data": "src/server.ts",
12
- "static": [
13
- "public"
14
- ],
15
- "template": {
16
- "src": "src/view.ts",
17
- "type": "oc-template-es6"
18
- }
19
- }
20
- },
21
- "devDependencies": {
22
- "oc-server": "^3.0.0",
23
- "oc-template-es6-compiler": "^7.0.0"
24
- }
25
- }
@@ -1,66 +0,0 @@
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({
23
- development: {
24
- // Echo console logs from the browser to the server
25
- console: true,
26
- },
27
- })
28
- .withParameters({
29
- userId: {
30
- default: 1,
31
- description: 'The user id from the user database',
32
- example: 1,
33
- mandatory: true,
34
- type: 'number',
35
- },
36
- })
37
- .handler(async (params) => {
38
- const { userId } = params;
39
- const user = await getUser(userId);
40
- const [firstName, lastName] = user.name.split(/\s+/);
41
-
42
- if (firstName === 'Invalid') {
43
- return;
44
- }
45
-
46
- return {
47
- firstName,
48
- lastName,
49
- born: user.born,
50
- hobbies: user.hobbies,
51
- };
52
- })
53
- .action('funFact', async (params: { year: number }) => {
54
- const { year } = params;
55
- const funFact = await getFunFact(year);
56
-
57
- return {
58
- funFact,
59
- };
60
- });
61
-
62
- declare module 'oc-server' {
63
- interface Register {
64
- server: typeof server;
65
- }
66
- }
@@ -1,30 +0,0 @@
1
- .container {
2
- background-color: #3b246c;
3
- color: #fff;
4
- font-family: sans-serif;
5
- padding: 40px;
6
- }
7
-
8
- .button {
9
- background-color: #a97613;
10
- border: none;
11
- padding: 15px 32px;
12
- text-align: center;
13
- font-size: 16px;
14
- text-decoration: none;
15
- display: inline-block;
16
- color: inherit;
17
- cursor: pointer;
18
- }
19
-
20
- .info {
21
- margin-bottom: 20px;
22
- }
23
-
24
- .block {
25
- margin: 6px 0;
26
- }
27
-
28
- .button:hover {
29
- background-color: #c79535;
30
- }
@@ -1,46 +0,0 @@
1
- import { InitialData, serverClient } from 'oc-server';
2
- import styles from './styles.css';
3
- import logo from '../public/logo.png';
4
- import { getSettings } from 'oc-server';
5
-
6
- const onRender = (cb: (element: HTMLElement) => void) => {
7
- const isBrowser = typeof window !== 'undefined';
8
- if (isBrowser) {
9
- const { id } = getSettings();
10
- window.oc.events.on('oc:rendered', (e, data) => {
11
- if (String(data.id) === id) {
12
- cb(data.element);
13
- }
14
- });
15
- }
16
- };
17
-
18
- export default ({ firstName, lastName, hobbies, born }: InitialData) => {
19
- onRender((element) => {
20
- element
21
- .querySelector(`.${styles.button}`)
22
- ?.addEventListener('click', async () => {
23
- const { funFact } = await serverClient.funFact({ year: born });
24
- element.querySelector('#fun-year-fact')!.innerHTML = funFact;
25
- });
26
- });
27
-
28
- return /* html */ `
29
- <div class="${styles.container}">
30
- <img width="50" height="50" src="${logo}" alt="Logo" />
31
- <h1 style="margin: 0 0 20px 0;">
32
- Hello, <span style="text-decoration: underline;">${firstName}</span> ${lastName}
33
- </h1>
34
- <div class=${styles.info}>
35
- <div class=${styles.block}>Born: ${born}</div>
36
- <div class=${styles.block}>
37
- <div>Hobbies: ${hobbies.map((x) => x.toLowerCase()).join(', ')}</div>
38
- </div>
39
- </div>
40
- <div id="fun-year-fact"></div>
41
- <button class=${styles.button}>
42
- Fun year fact
43
- </button>
44
- </div>
45
- `;
46
- };
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es5",
4
- "lib": ["dom", "dom.iterable", "esnext"],
5
- "strict": true,
6
- "allowJs": true,
7
- "skipLibCheck": true,
8
- "esModuleInterop": true,
9
- "allowSyntheticDefaultImports": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "noFallthroughCasesInSwitch": true,
12
- "module": "esnext",
13
- "moduleResolution": "node",
14
- "resolveJsonModule": true,
15
- "isolatedModules": true
16
- }
17
- }