@osdk/create-app 0.13.0 → 0.14.0-main-20240503154621

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 (48) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/js/index.browser.mjs +8 -2
  3. package/build/js/index.browser.mjs.map +1 -1
  4. package/build/js/index.cjs +8 -2
  5. package/build/js/index.cjs.map +1 -1
  6. package/build/js/index.mjs +8 -2
  7. package/build/js/index.mjs.map +1 -1
  8. package/build/types/prompts/promptTemplate.d.ts.map +1 -1
  9. package/build/types/templates.d.ts +1 -0
  10. package/build/types/templates.d.ts.map +1 -1
  11. package/package.json +1 -1
  12. package/templates/template-next-static-export/package.json.hbs +1 -1
  13. package/templates/template-tutorial-todo-app/.eslintrc.cjs +18 -0
  14. package/templates/template-tutorial-todo-app/README.md.hbs +33 -0
  15. package/templates/template-tutorial-todo-app/index.html +13 -0
  16. package/templates/template-tutorial-todo-app/package.json.hbs +31 -0
  17. package/templates/template-tutorial-todo-app/public/todo-app.svg +4 -0
  18. package/templates/template-tutorial-todo-app/src/AuthCallback.tsx +24 -0
  19. package/templates/template-tutorial-todo-app/src/AuthenticatedRoute.tsx +33 -0
  20. package/templates/template-tutorial-todo-app/src/CreateProjectButton.tsx +33 -0
  21. package/templates/template-tutorial-todo-app/src/CreateProjectDialog.tsx +56 -0
  22. package/templates/template-tutorial-todo-app/src/CreateTaskButton.tsx.hbs +35 -0
  23. package/templates/template-tutorial-todo-app/src/CreateTaskDialog.tsx.hbs +52 -0
  24. package/templates/template-tutorial-todo-app/src/DeleteProjectButton.tsx.hbs +34 -0
  25. package/templates/template-tutorial-todo-app/src/DeleteProjectDialog.tsx.hbs +46 -0
  26. package/templates/template-tutorial-todo-app/src/Dialog.module.css +5 -0
  27. package/templates/template-tutorial-todo-app/src/Dialog.tsx +19 -0
  28. package/templates/template-tutorial-todo-app/src/Home.module.css +35 -0
  29. package/templates/template-tutorial-todo-app/src/Home.tsx.hbs +62 -0
  30. package/templates/template-tutorial-todo-app/src/Layout.module.css +16 -0
  31. package/templates/template-tutorial-todo-app/src/Layout.tsx +21 -0
  32. package/templates/template-tutorial-todo-app/src/Login.module.css +5 -0
  33. package/templates/template-tutorial-todo-app/src/Login.tsx +42 -0
  34. package/templates/template-tutorial-todo-app/src/ProjectSelect.tsx.hbs +40 -0
  35. package/templates/template-tutorial-todo-app/src/TaskList.module.css +6 -0
  36. package/templates/template-tutorial-todo-app/src/TaskList.tsx.hbs +38 -0
  37. package/templates/template-tutorial-todo-app/src/TaskListItem.module.css +3 -0
  38. package/templates/template-tutorial-todo-app/src/TaskListItem.tsx.hbs +37 -0
  39. package/templates/template-tutorial-todo-app/src/client.ts.hbs +31 -0
  40. package/templates/template-tutorial-todo-app/src/index.css +73 -0
  41. package/templates/template-tutorial-todo-app/src/main.tsx +33 -0
  42. package/templates/template-tutorial-todo-app/src/mocks.ts.hbs +208 -0
  43. package/templates/template-tutorial-todo-app/src/useProjectTasks.ts.hbs +59 -0
  44. package/templates/template-tutorial-todo-app/src/useProjects.ts.hbs +44 -0
  45. package/templates/template-tutorial-todo-app/src/vite-env.d.ts +1 -0
  46. package/templates/template-tutorial-todo-app/tsconfig.json +25 -0
  47. package/templates/template-tutorial-todo-app/tsconfig.node.json +10 -0
  48. package/templates/template-tutorial-todo-app/vite.config.ts.hbs +19 -0
@@ -0,0 +1,208 @@
1
+ import { OsdkTodoProject, OsdkTodoTask } from "{{osdkPackage}}/ontology/objects";
2
+ import { LocalDate } from "{{osdkPackage}}";
3
+
4
+ interface MockProject {
5
+ id: string;
6
+ name: string;
7
+ tasks: MockTask[];
8
+ }
9
+
10
+ interface MockTask {
11
+ id: string;
12
+ name: string;
13
+ }
14
+
15
+ const projects: MockProject[] = [
16
+ {
17
+ id: "1",
18
+ name: "Fake Project",
19
+ tasks: [
20
+ {
21
+ id: "1",
22
+ name: "Try to",
23
+ },
24
+ {
25
+ id: "2",
26
+ name: "Implement this",
27
+ },
28
+ {
29
+ id: "3",
30
+ name: "With the Ontology SDK!",
31
+ },
32
+ ],
33
+ },
34
+ {
35
+ id: "2",
36
+ name: "Yet Another Fake Project",
37
+ tasks: [
38
+ {
39
+ id: "4",
40
+ name: "More tasks here",
41
+ },
42
+ ],
43
+ },
44
+ ];
45
+
46
+ async function delay(): Promise<void> {
47
+ return new Promise((resolve) =>
48
+ setTimeout(() => resolve(), 500 + Math.random() * 1000)
49
+ );
50
+ }
51
+
52
+ // Good enough random id for mocks
53
+ function randomId(): string {
54
+ return `${Math.floor(Math.random() * 2 ** 31)}`;
55
+ }
56
+
57
+ async function getProjects(): Promise<OsdkTodoProject[]> {
58
+ await delay();
59
+ const result = [...projects];
60
+ result.sort((p1, p2) => p1.name.localeCompare(p2.name));
61
+ return result.map(project);
62
+ }
63
+
64
+ async function createProject({
65
+ name,
66
+ }: {
67
+ name: string;
68
+ }): Promise<OsdkTodoProject["__primaryKey"]> {
69
+ await delay();
70
+ const id = randomId();
71
+ projects.push({ id, name, tasks: [] });
72
+ return id;
73
+ }
74
+
75
+ async function deleteProject(id: string): Promise<void> {
76
+ await delay();
77
+ const idx = projects.findIndex((p) => p.id === id);
78
+ if (idx !== -1) {
79
+ projects.splice(idx, 1);
80
+ }
81
+ }
82
+
83
+ async function createTask({
84
+ name,
85
+ projectId,
86
+ }: {
87
+ name: string;
88
+ projectId: string;
89
+ }): Promise<OsdkTodoTask["__primaryKey"]> {
90
+ await delay();
91
+ const project = projects.find((p) => p.id === projectId);
92
+ if (project == null) {
93
+ throw new Error(`Project ${projectId} not found!`);
94
+ }
95
+ const id = randomId();
96
+ project.tasks.unshift({ id, name });
97
+ return id;
98
+ }
99
+
100
+ async function deleteTask(id: string): Promise<void> {
101
+ await delay();
102
+ for (const project of projects) {
103
+ const idx = project.tasks.findIndex((t) => t.id === id);
104
+ if (idx !== -1) {
105
+ project.tasks.splice(idx, 1);
106
+ }
107
+ }
108
+ }
109
+
110
+ function project(mockProject: MockProject): OsdkTodoProject {
111
+ return {
112
+ __apiName: "OsdkTodoProject",
113
+ __primaryKey: mockProject.id,
114
+ __rid: `${mockProject.id}`,
115
+ $apiName: "OsdkTodoProject",
116
+ $primaryKey: mockProject.id,
117
+ $rid: `${mockProject.id}`,
118
+ id: mockProject.id,
119
+ name: mockProject.name,
120
+ osdkTodoTasks: {
121
+ all: async () => ({
122
+ type: "ok",
123
+ value: mockProject.tasks.map((mockTask) => task(mockProject, mockTask)),
124
+ }),
125
+ get: async () => ({
126
+ type: "error",
127
+ error: {
128
+ errorType: "UNKNOWN",
129
+ errorName: "UnknownError",
130
+ originalError: "",
131
+ name: "Error",
132
+ message: "Not implemented!",
133
+ },
134
+ }),
135
+ page: async () => ({
136
+ type: "error",
137
+ error: {
138
+ errorType: "UNKNOWN",
139
+ errorName: "UnknownError",
140
+ originalError: "",
141
+ name: "Error",
142
+ message: "Not implemented!",
143
+ },
144
+ }),
145
+ asyncIter: () => {
146
+ throw new Error("Function not implemented.");
147
+ },
148
+ fetchPage: () => {
149
+ throw new Error("Function not implemented.");
150
+ },
151
+ fetchPageWithErrors: () => {
152
+ throw new Error("Function not implemented.");
153
+ },
154
+ fetchOneWithErrors: () => {
155
+ throw new Error("Function not implemented.");
156
+ },
157
+ fetchOne: () => {
158
+ throw new Error("Function not implemented.");
159
+ },
160
+ },
161
+ budget: undefined,
162
+ description: undefined,
163
+ document: undefined,
164
+ };
165
+ }
166
+
167
+ function task(mockProject: MockProject, mockTask: MockTask): OsdkTodoTask {
168
+ return {
169
+ __apiName: "OsdkTodoTask",
170
+ __primaryKey: mockTask.id,
171
+ __rid: `${mockTask.id}`,
172
+ $apiName: "OsdkTodoTask",
173
+ $primaryKey: mockTask.id,
174
+ $rid: `${mockTask.id}`,
175
+ id: mockTask.id,
176
+ title: mockTask.name,
177
+ startDate: LocalDate.now(),
178
+ dueDate: LocalDate.now().plusWeeks(1),
179
+ status: "IN PROGRESS",
180
+ projectId: mockProject.id,
181
+ osdkTodoProject: {
182
+ get: async () => ({
183
+ type: "ok",
184
+ value: project(mockProject),
185
+ }),
186
+ fetchOneWithErrors: () => {
187
+ throw new Error("Function not implemented.");
188
+ },
189
+ fetchOne: () => {
190
+ throw new Error("Function not implemented.");
191
+ },
192
+ },
193
+ description: undefined,
194
+ assignedTo: undefined,
195
+ createdAt: undefined,
196
+ createdBy: undefined,
197
+ };
198
+ }
199
+
200
+ const Mocks = {
201
+ getProjects,
202
+ createProject,
203
+ deleteProject,
204
+ createTask,
205
+ deleteTask,
206
+ };
207
+
208
+ export default Mocks;
@@ -0,0 +1,59 @@
1
+ import { OsdkTodoProject, OsdkTodoTask } from "{{osdkPackage}}/ontology/objects";
2
+ import { useCallback } from "react";
3
+ import useSWR from "swr";
4
+ import Mocks from "./mocks";
5
+
6
+ export function useProjectTasks(project: OsdkTodoProject | undefined) {
7
+ const { data, isLoading, isValidating, error, mutate } = useSWR<OsdkTodoTask[]>(
8
+ project != null ? `projects/${project.id}/tasks` : null,
9
+ async () => {
10
+ if (project == null) {
11
+ return [];
12
+ }
13
+ const result = await project.osdkTodoTasks.all();
14
+ if (result.type !== "ok") {
15
+ throw result.error;
16
+ }
17
+ return result.value;
18
+ }
19
+ );
20
+
21
+ const createTask: (
22
+ name: string
23
+ ) => Promise<OsdkTodoTask["__primaryKey"] | undefined> = useCallback(
24
+ async (name) => {
25
+ if (project == null) {
26
+ return undefined;
27
+ }
28
+ // Try to implement this with the Ontology SDK!
29
+ const id = await Mocks.createTask({
30
+ name,
31
+ projectId: project.__primaryKey,
32
+ });
33
+ await mutate();
34
+ return id;
35
+ },
36
+ [project, mutate]
37
+ );
38
+
39
+ const deleteTask: (task: OsdkTodoTask) => Promise<void> = useCallback(
40
+ async (task) => {
41
+ if (project == null) {
42
+ return;
43
+ }
44
+ // Try to implement this with the Ontology SDK!
45
+ await Mocks.deleteTask(task.__primaryKey);
46
+ await mutate();
47
+ },
48
+ [project, mutate]
49
+ );
50
+
51
+ return {
52
+ tasks: data,
53
+ isLoading,
54
+ isValidating,
55
+ isError: error,
56
+ createTask,
57
+ deleteTask,
58
+ };
59
+ }
@@ -0,0 +1,44 @@
1
+ import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
+ import { useCallback } from "react";
3
+ import useSWR from "swr";
4
+ import Mocks from "./mocks";
5
+
6
+ function useProjects() {
7
+ const { data, isLoading, isValidating, error, mutate } = useSWR<
8
+ OsdkTodoProject[]
9
+ >("projects", async () => {
10
+ // Try to implement this with the Ontology SDK!
11
+ return Mocks.getProjects();
12
+ });
13
+
14
+ const createProject: (name: string) => Promise<OsdkTodoProject["__primaryKey"]> =
15
+ useCallback(
16
+ async (name) => {
17
+ // Try to implement this with the Ontology SDK!
18
+ const id = await Mocks.createProject({ name });
19
+ await mutate();
20
+ return id;
21
+ },
22
+ [mutate]
23
+ );
24
+
25
+ const deleteProject: (project: OsdkTodoProject) => Promise<void> = useCallback(
26
+ async (project) => {
27
+ // Try to implement this with the Ontology SDK!
28
+ await Mocks.deleteProject(project.__primaryKey);
29
+ await mutate();
30
+ },
31
+ [mutate]
32
+ );
33
+
34
+ return {
35
+ projects: data,
36
+ isLoading,
37
+ isValidating,
38
+ isError: error,
39
+ createProject,
40
+ deleteProject,
41
+ };
42
+ }
43
+
44
+ export default useProjects;
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "jsx": "react-jsx",
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noFallthroughCasesInSwitch": true
22
+ },
23
+ "include": ["src"],
24
+ "references": [{ "path": "./tsconfig.node.json" }]
25
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true
8
+ },
9
+ "include": ["vite.config.ts"]
10
+ }
@@ -0,0 +1,19 @@
1
+ import react from "@vitejs/plugin-react";
2
+ import { defineConfig } from "vite";
3
+
4
+ // https://vitejs.dev/config/
5
+ export default defineConfig({
6
+ plugins: [react()],
7
+ server: {
8
+ port: 8080,
9
+ {{#if corsProxy}}
10
+ proxy: {
11
+ "^(/multipass/api|/api)": {
12
+ target: "{{foundryUrl}}",
13
+ changeOrigin: true,
14
+ secure: true,
15
+ },
16
+ },
17
+ {{/if}}
18
+ },
19
+ });