create-oc 1.0.1 → 1.1.1

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": "create-oc",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -13,21 +13,12 @@
13
13
  "static": [
14
14
  "public"
15
15
  ]
16
- },
17
- "parameters": {
18
- "userId": {
19
- "default": 1,
20
- "description": "The user id from the user database",
21
- "example": 1,
22
- "mandatory": true,
23
- "type": "number"
24
- }
25
16
  }
26
17
  },
27
18
  "dependencies": {},
28
19
  "devDependencies": {
29
- "oc-server": "^2.0.1",
30
- "oc-template-elm-compiler": "^1.0.1",
20
+ "oc-server": "^2.0.4",
21
+ "oc-template-elm-compiler": "^1.1.0",
31
22
  "elm": "^0.19.1-6",
32
23
  "typescript": "^5.3.3"
33
24
  }
@@ -20,7 +20,16 @@ async function getFunFact(year: number) {
20
20
  }
21
21
 
22
22
  export const server = new Server()
23
- .handler(async (params: { userId: number }, ctx) => {
23
+ .withParameters({
24
+ userId: {
25
+ default: 1,
26
+ description: 'The user id from the user database',
27
+ example: 1,
28
+ mandatory: true,
29
+ type: 'number',
30
+ },
31
+ })
32
+ .handler(async (params, ctx) => {
24
33
  const { userId } = params;
25
34
  const user = await getUser(userId);
26
35
  const [firstName, lastName] = user.name.split(/\s+/);
@@ -15,19 +15,10 @@
15
15
  "src": "src/view.ts",
16
16
  "type": "oc-template-es6"
17
17
  }
18
- },
19
- "parameters": {
20
- "userId": {
21
- "default": 1,
22
- "description": "The user id from the user database",
23
- "example": 1,
24
- "mandatory": true,
25
- "type": "number"
26
- }
27
18
  }
28
19
  },
29
20
  "devDependencies": {
30
- "oc-server": "^2.0.1",
31
- "oc-template-es6-compiler": "^5.0.1"
21
+ "oc-server": "^2.0.4",
22
+ "oc-template-es6-compiler": "^5.1.0"
32
23
  }
33
24
  }
@@ -20,7 +20,16 @@ async function getFunFact(year: number) {
20
20
  }
21
21
 
22
22
  export const server = new Server()
23
- .handler(async (params: { userId: number }) => {
23
+ .withParameters({
24
+ userId: {
25
+ default: 1,
26
+ description: 'The user id from the user database',
27
+ example: 1,
28
+ mandatory: true,
29
+ type: 'number',
30
+ },
31
+ })
32
+ .handler(async (params) => {
24
33
  const { userId } = params;
25
34
  const user = await getUser(userId);
26
35
  const [firstName, lastName] = user.name.split(/\s+/);
@@ -18,15 +18,6 @@
18
18
  "static": [
19
19
  "public"
20
20
  ]
21
- },
22
- "parameters": {
23
- "userId": {
24
- "default": 1,
25
- "description": "The user id from the user database",
26
- "example": 1,
27
- "mandatory": true,
28
- "type": "number"
29
- }
30
21
  }
31
22
  },
32
23
  "dependencies": {},
@@ -35,8 +26,8 @@
35
26
  "@testing-library/react": "^14.0.0",
36
27
  "@testing-library/user-event": "^14.4.3",
37
28
  "jsdom": "^21.1.1",
38
- "oc-server": "^2.0.1",
39
- "oc-template-preact-compiler": "^1.0.1",
29
+ "oc-server": "^2.0.4",
30
+ "oc-template-preact-compiler": "^1.1.0",
40
31
  "preact": "^10.13.2",
41
32
  "typescript": "5.0.2",
42
33
  "vitest": "^0.29.7"
@@ -17,12 +17,24 @@ describe('App - Page', () => {
17
17
  it('Gets more data when clicking the button', () => {
18
18
  getData.mockImplementationOnce(() => Promise.resolve({}));
19
19
  render(
20
- <DataProvider value={{ firstName: 'firstName', lastName: 'lastName', userId: 0, getData }}>
21
- <App firstName="firstName" lastName="lastName" userId={0} />
20
+ <DataProvider
21
+ value={{
22
+ firstName: 'firstName',
23
+ lastName: 'lastName',
24
+ userId: 0,
25
+ getData,
26
+ }}
27
+ >
28
+ <App
29
+ firstName="firstName"
30
+ lastName="lastName"
31
+ born={1991}
32
+ hobbies={[]}
33
+ />
22
34
  </DataProvider>
23
35
  );
24
36
 
25
- const extraInfoButton = screen.getByText(/Get extra information/i);
37
+ const extraInfoButton = screen.getByText(/Fun year fact/i);
26
38
  expect(extraInfoButton).toBeTruthy();
27
39
  });
28
40
  });
@@ -20,7 +20,16 @@ async function getFunFact(year: number) {
20
20
  }
21
21
 
22
22
  export const server = new Server()
23
- .handler(async (params: { userId: number }) => {
23
+ .withParameters({
24
+ userId: {
25
+ default: 1,
26
+ description: 'The user id from the user database',
27
+ example: 1,
28
+ mandatory: true,
29
+ type: 'number',
30
+ },
31
+ })
32
+ .handler(async (params) => {
24
33
  const { userId } = params;
25
34
  const user = await getUser(userId);
26
35
  const [firstName, lastName] = user.name.split(/\s+/);
@@ -18,15 +18,6 @@
18
18
  "static": [
19
19
  "public"
20
20
  ]
21
- },
22
- "parameters": {
23
- "userId": {
24
- "default": 1,
25
- "description": "The user id from the user database",
26
- "example": 1,
27
- "mandatory": true,
28
- "type": "number"
29
- }
30
21
  }
31
22
  },
32
23
  "dependencies": {},
@@ -35,8 +26,8 @@
35
26
  "@testing-library/user-event": "^14.4.3",
36
27
  "@types/react": "^18.0.28",
37
28
  "jsdom": "^21.1.1",
38
- "oc-server": "^2.0.1",
39
- "oc-template-react-compiler": "^7.0.1",
29
+ "oc-server": "^2.0.4",
30
+ "oc-template-react-compiler": "^7.1.0",
40
31
  "react": "18.3.1",
41
32
  "react-dom": "18.3.1",
42
33
  "typescript": "5.1.3",
@@ -26,14 +26,19 @@ describe('App - Page', () => {
26
26
  lastName: 'lastName',
27
27
  userId: 0,
28
28
  getData,
29
- getSetting
29
+ getSetting,
30
30
  }}
31
31
  >
32
- <App firstName="firstName" lastName="lastName" userId={0} />
32
+ <App
33
+ firstName="firstName"
34
+ lastName="lastName"
35
+ born={1991}
36
+ hobbies={[]}
37
+ />
33
38
  </DataProvider>
34
39
  );
35
40
 
36
- const extraInfoButton = screen.getByText(/Get extra information/i);
41
+ const extraInfoButton = screen.getByText(/Fun year fact/i);
37
42
  expect(extraInfoButton).toBeTruthy();
38
43
  });
39
44
  });
@@ -20,7 +20,16 @@ async function getFunFact(year: number) {
20
20
  }
21
21
 
22
22
  export const server = new Server()
23
- .handler(async (params: { userId: number }) => {
23
+ .withParameters({
24
+ userId: {
25
+ default: 1,
26
+ description: 'The user id from the user database',
27
+ example: 1,
28
+ mandatory: true,
29
+ type: 'number',
30
+ },
31
+ })
32
+ .handler(async (params) => {
24
33
  const { userId } = params;
25
34
  const user = await getUser(userId);
26
35
  const [firstName, lastName] = user.name.split(/\s+/);
@@ -18,15 +18,6 @@
18
18
  "static": [
19
19
  "public"
20
20
  ]
21
- },
22
- "parameters": {
23
- "userId": {
24
- "default": 1,
25
- "description": "The user id from the user database",
26
- "example": 1,
27
- "mandatory": true,
28
- "type": "number"
29
- }
30
21
  }
31
22
  },
32
23
  "devDependencies": {
@@ -34,8 +25,8 @@
34
25
  "@testing-library/jest-dom": "^6.5.0",
35
26
  "@types/testing-library__jest-dom": "^5.14.5",
36
27
  "jsdom": "^21.1.1",
37
- "oc-server": "^2.0.1",
38
- "oc-template-solid-compiler": "^1.0.1",
28
+ "oc-server": "^2.0.4",
29
+ "oc-template-solid-compiler": "^1.1.0",
39
30
  "solid-js": "^1.8.21",
40
31
  "typescript": "5.5.4",
41
32
  "vitest": "^2.0.5"
@@ -24,14 +24,19 @@ describe('App - Page', () => {
24
24
  lastName: 'lastName',
25
25
  userId: 0,
26
26
  getData,
27
- getSetting
27
+ getSetting,
28
28
  }}
29
29
  >
30
- <App />
30
+ <App
31
+ firstName="firstName"
32
+ lastName="lastName"
33
+ born={1991}
34
+ hobbies={[]}
35
+ />
31
36
  </DataProvider>
32
37
  ));
33
38
 
34
- const extraInfoButton = getByText(/Get extra information/i);
39
+ const extraInfoButton = getByText(/Fun year fact/i);
35
40
  expect(extraInfoButton).toBeTruthy();
36
41
  });
37
42
  });
@@ -20,7 +20,16 @@ async function getFunFact(year: number) {
20
20
  }
21
21
 
22
22
  export const server = new Server()
23
- .handler(async (params: { userId: number }) => {
23
+ .withParameters({
24
+ userId: {
25
+ default: 1,
26
+ description: 'The user id from the user database',
27
+ example: 1,
28
+ mandatory: true,
29
+ type: 'number',
30
+ },
31
+ })
32
+ .handler(async (params) => {
24
33
  const { userId } = params;
25
34
  const user = await getUser(userId);
26
35
  const [firstName, lastName] = user.name.split(/\s+/);
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "base-component-svelte",
3
+ "description": "",
4
+ "version": "1.0.0",
5
+ "scripts": {
6
+ "dev": "oc-server dev",
7
+ "build": "npm run check && oc package .",
8
+ "check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json",
9
+ "test": "vitest"
10
+ },
11
+ "oc": {
12
+ "files": {
13
+ "data": "src/server.ts",
14
+ "template": {
15
+ "src": "src/App.svelte",
16
+ "type": "oc-template-svelte"
17
+ },
18
+ "static": [
19
+ "public"
20
+ ]
21
+ }
22
+ },
23
+ "devDependencies": {
24
+ "@testing-library/jest-dom": "^5.16.5",
25
+ "@types/testing-library__jest-dom": "^5.14.5",
26
+ "@sveltejs/vite-plugin-svelte": "^5.0.3",
27
+ "jsdom": "^21.1.1",
28
+ "oc-server": "^2.0.4",
29
+ "oc-template-svelte-compiler": "^0.0.1",
30
+ "svelte": "^5.23.0",
31
+ "typescript": "5.0.2",
32
+ "vitest": "^0.29.7"
33
+ }
34
+ }
Binary file
@@ -0,0 +1,71 @@
1
+ <script lang="ts">
2
+ import logo from '../public/logo.png';
3
+ import { InitialData, serverClient } from 'oc-server';
4
+
5
+ let funFact: string | null = $state(null);
6
+ let { born, firstName, hobbies, lastName }: InitialData = $props();
7
+ let getFunFact = async () => {
8
+ let response = await serverClient.funFact({ year: born });
9
+ funFact = response.funFact;
10
+ };
11
+ </script>
12
+
13
+ <div class="container">
14
+ <img width="50" height="50" src={logo} alt="Logo" />
15
+
16
+ <h1>
17
+ Hello, <span>{firstName}</span>
18
+ {lastName}
19
+ </h1>
20
+ <div class="info">
21
+ <div class="block">Born: {born}</div>
22
+ <div class="block">
23
+ Hobbies: {hobbies}
24
+ </div>
25
+ </div>
26
+ {#if funFact}
27
+ <div>{funFact}</div>
28
+ {/if}
29
+ <button class="button" onclick={getFunFact}> Fun year fact </button>
30
+ </div>
31
+
32
+ <style>
33
+ .container {
34
+ background-color: #3b246c;
35
+ color: #fff;
36
+ font-family: sans-serif;
37
+ padding: 40px;
38
+ }
39
+
40
+ .button {
41
+ background-color: #a97613;
42
+ border: none;
43
+ padding: 15px 32px;
44
+ text-align: center;
45
+ font-size: 16px;
46
+ text-decoration: none;
47
+ display: inline-block;
48
+ color: inherit;
49
+ cursor: pointer;
50
+ }
51
+
52
+ .button:hover {
53
+ background-color: #c79535;
54
+ }
55
+
56
+ h1 {
57
+ margin: 0 0 20px 0;
58
+ }
59
+
60
+ span {
61
+ text-decoration: underline;
62
+ }
63
+
64
+ .info {
65
+ margin-bottom: 20px;
66
+ }
67
+
68
+ .block {
69
+ margin: 6px 0;
70
+ }
71
+ </style>
@@ -0,0 +1,2 @@
1
+ /// <reference types="svelte" />
2
+ /// <reference types="oc-vite/client" />
@@ -0,0 +1,61 @@
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
+ .withParameters({
24
+ userId: {
25
+ default: 1,
26
+ description: 'The user id from the user database',
27
+ example: 1,
28
+ mandatory: true,
29
+ type: 'number',
30
+ },
31
+ })
32
+ .handler(async (params) => {
33
+ const { userId } = params;
34
+ const user = await getUser(userId);
35
+ const [firstName, lastName] = user.name.split(/\s+/);
36
+
37
+ if (firstName === 'Invalid') {
38
+ return;
39
+ }
40
+
41
+ return {
42
+ firstName,
43
+ lastName,
44
+ born: user.born,
45
+ hobbies: user.hobbies,
46
+ };
47
+ })
48
+ .action('funFact', async (params: { year: number }) => {
49
+ const { year } = params;
50
+ const funFact = await getFunFact(year);
51
+
52
+ return {
53
+ funFact,
54
+ };
55
+ });
56
+
57
+ declare module 'oc-server' {
58
+ interface Register {
59
+ server: typeof server;
60
+ }
61
+ }
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1,30 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "@tsconfig/svelte/tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "ESNext",
5
+ "useDefineForClassFields": true,
6
+ "module": "ESNext",
7
+ "resolveJsonModule": true,
8
+ /**
9
+ * Typecheck JS in `.svelte` and `.js` files by default.
10
+ * Disable checkJs if you'd like to use dynamic types in JS.
11
+ * Note that setting allowJs false does not prevent the use
12
+ * of JS in `.svelte` files.
13
+ */
14
+ "allowJs": true,
15
+ "checkJs": true,
16
+ "isolatedModules": true,
17
+ "moduleDetection": "force"
18
+ },
19
+ "include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"]
20
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ { "path": "./tsconfig.app.json" },
5
+ { "path": "./tsconfig.node.json" }
6
+ ]
7
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4
+ "target": "ES2022",
5
+ "lib": ["ES2023"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "isolatedModules": true,
13
+ "moduleDetection": "force",
14
+ "noEmit": true,
15
+
16
+ /* Linting */
17
+ "strict": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedSideEffectImports": true
22
+ },
23
+ "include": ["vite.config.ts"]
24
+ }
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ // https://vitejs.dev/config/
4
+ export default defineConfig({
5
+ // Add your own plugins here for thinkgs like eslint or typecheckers
6
+ plugins: [],
7
+ // @ts-ignore Missing test property
8
+ test: {
9
+ environment: 'jsdom'
10
+ }
11
+ });
@@ -18,15 +18,6 @@
18
18
  "static": [
19
19
  "public"
20
20
  ]
21
- },
22
- "parameters": {
23
- "userId": {
24
- "default": 1,
25
- "description": "The user id from the user database",
26
- "example": 1,
27
- "mandatory": true,
28
- "type": "number"
29
- }
30
21
  }
31
22
  },
32
23
  "devDependencies": {
@@ -34,8 +25,8 @@
34
25
  "@types/testing-library__jest-dom": "^5.14.5",
35
26
  "@vitejs/plugin-vue": "^5.0.0",
36
27
  "jsdom": "^21.1.1",
37
- "oc-server": "^2.0.1",
38
- "oc-template-vue-compiler": "^1.0.1",
28
+ "oc-server": "^2.0.4",
29
+ "oc-template-vue-compiler": "^1.1.0",
39
30
  "typescript": "5.0.2",
40
31
  "vitest": "^0.29.7",
41
32
  "vue": "^3.3.11",
@@ -20,7 +20,16 @@ async function getFunFact(year: number) {
20
20
  }
21
21
 
22
22
  export const server = new Server()
23
- .handler(async (params: { userId: number }) => {
23
+ .withParameters({
24
+ userId: {
25
+ default: 1,
26
+ description: 'The user id from the user database',
27
+ example: 1,
28
+ mandatory: true,
29
+ type: 'number',
30
+ },
31
+ })
32
+ .handler(async (params) => {
24
33
  const { userId } = params;
25
34
  const user = await getUser(userId);
26
35
  const [firstName, lastName] = user.name.split(/\s+/);