@osdk/create-app 0.15.0-main-20240509180744 → 0.16.0-main-20240520210317

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 (91) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/bin/createOsdkApp.mjs +1 -1
  3. package/build/{js/index.mjs → browser/index.js} +2 -2
  4. package/build/{js → cjs}/index.cjs +1 -1
  5. package/build/{js/index.browser.mjs → esm/index.js} +2 -2
  6. package/package.json +12 -12
  7. package/templates/template-next-static-export/package.json.hbs +1 -1
  8. package/templates/template-react/package.json.hbs +6 -6
  9. package/templates/template-tutorial-todo-app/package.json.hbs +6 -6
  10. package/templates/template-tutorial-todo-app/src/{CreateTaskButton.tsx.hbs → CreateTaskButton.tsx} +2 -2
  11. package/templates/template-tutorial-todo-app/src/{CreateTaskDialog.tsx.hbs → CreateTaskDialog.tsx} +2 -2
  12. package/templates/template-tutorial-todo-app/src/{DeleteProjectButton.tsx.hbs → DeleteProjectButton.tsx} +2 -2
  13. package/templates/template-tutorial-todo-app/src/{DeleteProjectDialog.tsx.hbs → DeleteProjectDialog.tsx} +2 -2
  14. package/templates/template-tutorial-todo-app/src/{Home.tsx.hbs → Home.tsx} +2 -2
  15. package/templates/template-tutorial-todo-app/src/{ProjectSelect.tsx.hbs → ProjectSelect.tsx} +4 -4
  16. package/templates/template-tutorial-todo-app/src/{TaskList.tsx.hbs → TaskList.tsx} +2 -2
  17. package/templates/template-tutorial-todo-app/src/{TaskListItem.tsx.hbs → TaskListItem.tsx} +3 -3
  18. package/templates/template-tutorial-todo-app/src/mocks.ts +137 -0
  19. package/templates/template-tutorial-todo-app/src/{useProjectTasks.ts.hbs → useProjectTasks.ts} +13 -17
  20. package/templates/template-tutorial-todo-app/src/{useProjects.ts.hbs → useProjects.ts} +6 -7
  21. package/templates/template-vue/package.json.hbs +1 -1
  22. package/templates/template-tutorial-todo-app/src/mocks.ts.hbs +0 -208
  23. /package/build/{js/index.browser.mjs.map → browser/index.js.map} +0 -0
  24. /package/build/{js → cjs}/index.cjs.map +0 -0
  25. /package/build/{types → esm}/cli.d.ts +0 -0
  26. /package/build/{types → esm}/cli.d.ts.map +0 -0
  27. /package/build/{types → esm}/cli.test.d.ts +0 -0
  28. /package/build/{types → esm}/cli.test.d.ts.map +0 -0
  29. /package/build/{types → esm}/consola.d.ts +0 -0
  30. /package/build/{types → esm}/consola.d.ts.map +0 -0
  31. /package/build/{types → esm}/generate/generateEnv.d.ts +0 -0
  32. /package/build/{types → esm}/generate/generateEnv.d.ts.map +0 -0
  33. /package/build/{types → esm}/generate/generateEnv.test.d.ts +0 -0
  34. /package/build/{types → esm}/generate/generateEnv.test.d.ts.map +0 -0
  35. /package/build/{types → esm}/generate/generateFoundryConfigJson.d.ts +0 -0
  36. /package/build/{types → esm}/generate/generateFoundryConfigJson.d.ts.map +0 -0
  37. /package/build/{types → esm}/generate/generateFoundryConfigJson.test.d.ts +0 -0
  38. /package/build/{types → esm}/generate/generateFoundryConfigJson.test.d.ts.map +0 -0
  39. /package/build/{types → esm}/generate/generateNpmRc.d.ts +0 -0
  40. /package/build/{types → esm}/generate/generateNpmRc.d.ts.map +0 -0
  41. /package/build/{types → esm}/generate/generateNpmRc.test.d.ts +0 -0
  42. /package/build/{types → esm}/generate/generateNpmRc.test.d.ts.map +0 -0
  43. /package/build/{types → esm}/highlight.d.ts +0 -0
  44. /package/build/{types → esm}/highlight.d.ts.map +0 -0
  45. /package/build/{types → esm}/index.d.ts +0 -0
  46. /package/build/{types → esm}/index.d.ts.map +0 -0
  47. /package/build/{js/index.mjs.map → esm/index.js.map} +0 -0
  48. /package/build/{types → esm}/prompts/promptApplicationRid.d.ts +0 -0
  49. /package/build/{types → esm}/prompts/promptApplicationRid.d.ts.map +0 -0
  50. /package/build/{types → esm}/prompts/promptApplicationRid.test.d.ts +0 -0
  51. /package/build/{types → esm}/prompts/promptApplicationRid.test.d.ts.map +0 -0
  52. /package/build/{types → esm}/prompts/promptApplicationUrl.d.ts +0 -0
  53. /package/build/{types → esm}/prompts/promptApplicationUrl.d.ts.map +0 -0
  54. /package/build/{types → esm}/prompts/promptApplicationUrl.test.d.ts +0 -0
  55. /package/build/{types → esm}/prompts/promptApplicationUrl.test.d.ts.map +0 -0
  56. /package/build/{types → esm}/prompts/promptClientId.d.ts +0 -0
  57. /package/build/{types → esm}/prompts/promptClientId.d.ts.map +0 -0
  58. /package/build/{types → esm}/prompts/promptClientId.test.d.ts +0 -0
  59. /package/build/{types → esm}/prompts/promptClientId.test.d.ts.map +0 -0
  60. /package/build/{types → esm}/prompts/promptCorsProxy.d.ts +0 -0
  61. /package/build/{types → esm}/prompts/promptCorsProxy.d.ts.map +0 -0
  62. /package/build/{types → esm}/prompts/promptCorsProxy.test.d.ts +0 -0
  63. /package/build/{types → esm}/prompts/promptCorsProxy.test.d.ts.map +0 -0
  64. /package/build/{types → esm}/prompts/promptFoundryUrl.d.ts +0 -0
  65. /package/build/{types → esm}/prompts/promptFoundryUrl.d.ts.map +0 -0
  66. /package/build/{types → esm}/prompts/promptFoundryUrl.test.d.ts +0 -0
  67. /package/build/{types → esm}/prompts/promptFoundryUrl.test.d.ts.map +0 -0
  68. /package/build/{types → esm}/prompts/promptOsdkPackage.d.ts +0 -0
  69. /package/build/{types → esm}/prompts/promptOsdkPackage.d.ts.map +0 -0
  70. /package/build/{types → esm}/prompts/promptOsdkPackage.test.d.ts +0 -0
  71. /package/build/{types → esm}/prompts/promptOsdkPackage.test.d.ts.map +0 -0
  72. /package/build/{types → esm}/prompts/promptOsdkRegistryUrl.d.ts +0 -0
  73. /package/build/{types → esm}/prompts/promptOsdkRegistryUrl.d.ts.map +0 -0
  74. /package/build/{types → esm}/prompts/promptOsdkRegistryUrl.test.d.ts +0 -0
  75. /package/build/{types → esm}/prompts/promptOsdkRegistryUrl.test.d.ts.map +0 -0
  76. /package/build/{types → esm}/prompts/promptOverwrite.d.ts +0 -0
  77. /package/build/{types → esm}/prompts/promptOverwrite.d.ts.map +0 -0
  78. /package/build/{types → esm}/prompts/promptOverwrite.test.d.ts +0 -0
  79. /package/build/{types → esm}/prompts/promptOverwrite.test.d.ts.map +0 -0
  80. /package/build/{types → esm}/prompts/promptProject.d.ts +0 -0
  81. /package/build/{types → esm}/prompts/promptProject.d.ts.map +0 -0
  82. /package/build/{types → esm}/prompts/promptProject.test.d.ts +0 -0
  83. /package/build/{types → esm}/prompts/promptProject.test.d.ts.map +0 -0
  84. /package/build/{types → esm}/prompts/promptTemplate.d.ts +0 -0
  85. /package/build/{types → esm}/prompts/promptTemplate.d.ts.map +0 -0
  86. /package/build/{types → esm}/prompts/promptTemplate.test.d.ts +0 -0
  87. /package/build/{types → esm}/prompts/promptTemplate.test.d.ts.map +0 -0
  88. /package/build/{types → esm}/run.d.ts +0 -0
  89. /package/build/{types → esm}/run.d.ts.map +0 -0
  90. /package/build/{types → esm}/templates.d.ts +0 -0
  91. /package/build/{types → esm}/templates.d.ts.map +0 -0
package/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # @osdk/create-app
2
2
 
3
- ## 0.15.0-main-20240509180744
3
+ ## 0.16.0-main-20240520210317
4
+
5
+ ### Minor Changes
6
+
7
+ - 471a618: Make tutorial app not depend on OSDK imports
8
+
9
+ ## 0.15.0
4
10
 
5
11
  ### Minor Changes
6
12
 
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  // @ts-check
3
3
 
4
- import { cli } from "../build/js/index.mjs";
4
+ import { cli } from "../build/esm/index.js";
5
5
  cli();
@@ -451,7 +451,7 @@ async function run({
451
451
 
452
452
  // src/cli.ts
453
453
  async function cli(args = process.argv) {
454
- const base = yargs(hideBin(args)).version("0.15.0-main-20240509180744").wrap(Math.min(150, yargs().terminalWidth())).strict().help().command("$0 [project] [--<option>]", "Create a new OSDK application based on framework templates. Information may be provided through options to skip interactive prompts.", (yargs2) => yargs2.positional("project", {
454
+ const base = yargs(hideBin(args)).version("0.16.0-main-20240520210317").wrap(Math.min(150, yargs().terminalWidth())).strict().help().command("$0 [project] [--<option>]", "Create a new OSDK application based on framework templates. Information may be provided through options to skip interactive prompts.", (yargs2) => yargs2.positional("project", {
455
455
  type: "string",
456
456
  describe: "Project name to create"
457
457
  }).option("overwrite", {
@@ -516,4 +516,4 @@ async function cli(args = process.argv) {
516
516
 
517
517
  export { TEMPLATES, cli, run };
518
518
  //# sourceMappingURL=out.js.map
519
- //# sourceMappingURL=index.mjs.map
519
+ //# sourceMappingURL=index.js.map
@@ -461,7 +461,7 @@ async function run({
461
461
 
462
462
  // src/cli.ts
463
463
  async function cli(args = process.argv) {
464
- const base = yargs__default.default(helpers.hideBin(args)).version("0.15.0-main-20240509180744").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().command("$0 [project] [--<option>]", "Create a new OSDK application based on framework templates. Information may be provided through options to skip interactive prompts.", (yargs2) => yargs2.positional("project", {
464
+ const base = yargs__default.default(helpers.hideBin(args)).version("0.16.0-main-20240520210317").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().command("$0 [project] [--<option>]", "Create a new OSDK application based on framework templates. Information may be provided through options to skip interactive prompts.", (yargs2) => yargs2.positional("project", {
465
465
  type: "string",
466
466
  describe: "Project name to create"
467
467
  }).option("overwrite", {
@@ -451,7 +451,7 @@ async function run({
451
451
 
452
452
  // src/cli.ts
453
453
  async function cli(args = process.argv) {
454
- const base = yargs(hideBin(args)).version("0.15.0-main-20240509180744").wrap(Math.min(150, yargs().terminalWidth())).strict().help().command("$0 [project] [--<option>]", "Create a new OSDK application based on framework templates. Information may be provided through options to skip interactive prompts.", (yargs2) => yargs2.positional("project", {
454
+ const base = yargs(hideBin(args)).version("0.16.0-main-20240520210317").wrap(Math.min(150, yargs().terminalWidth())).strict().help().command("$0 [project] [--<option>]", "Create a new OSDK application based on framework templates. Information may be provided through options to skip interactive prompts.", (yargs2) => yargs2.positional("project", {
455
455
  type: "string",
456
456
  describe: "Project name to create"
457
457
  }).option("overwrite", {
@@ -516,4 +516,4 @@ async function cli(args = process.argv) {
516
516
 
517
517
  export { TEMPLATES, cli, run };
518
518
  //# sourceMappingURL=out.js.map
519
- //# sourceMappingURL=index.browser.mjs.map
519
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osdk/create-app",
3
- "version": "0.15.0-main-20240509180744",
3
+ "version": "0.16.0-main-20240520210317",
4
4
  "description": "",
5
5
  "access": "public",
6
6
  "license": "Apache-2.0",
@@ -10,14 +10,12 @@
10
10
  },
11
11
  "exports": {
12
12
  ".": {
13
- "types": "./build/types/index.d.ts",
14
- "browser": "./build/js/index.browser.mjs",
15
- "import": "./build/js/index.mjs"
13
+ "import": "./build/esm/index.js",
14
+ "browser": "./build/browser/index.browser.js"
16
15
  },
17
16
  "./*": {
18
- "types": "./build/types/public/*.d.ts",
19
- "browser": "./build/js/public/*.browser.mjs",
20
- "import": "./build/js/public/*.mjs"
17
+ "import": "./build/esm/public/*.js",
18
+ "browser": "./build/browser/public/*.js"
21
19
  }
22
20
  },
23
21
  "dependencies": {
@@ -40,17 +38,19 @@
40
38
  "create-osdk-app": "bin/createOsdkApp.mjs"
41
39
  },
42
40
  "files": [
43
- "build/types",
44
- "build/js",
41
+ "build/cjs",
42
+ "build/esm",
43
+ "build/browser",
45
44
  "CHANGELOG.md",
46
45
  "package.json",
47
46
  "templates",
48
47
  "*.d.ts"
49
48
  ],
50
- "module": "./build/js/index.mjs",
51
- "types": "./build/types/index.d.ts",
49
+ "module": "./build/esm/index.js",
50
+ "types": "./build/esm/index.d.ts",
52
51
  "type": "module",
53
52
  "scripts": {
53
+ "check-attw": "../../scripts/build_common/check-attw.sh esm",
54
54
  "clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
55
55
  "fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
56
56
  "lint": "eslint . && dprint check --config $(find-up dprint.json)",
@@ -58,6 +58,6 @@
58
58
  "test:watch": "vitest",
59
59
  "transpile": "tsup",
60
60
  "transpileWatch": "tsup --watch",
61
- "typecheck": "tsc-absolute"
61
+ "typecheck": "../../scripts/build_common/typecheck.sh esm"
62
62
  }
63
63
  }
@@ -19,7 +19,7 @@
19
19
  "@types/react": "^18",
20
20
  "@types/react-dom": "^18",
21
21
  "eslint": "^8.57.0",
22
- "eslint-config-next": "14.0.4",
22
+ "eslint-config-next": "^14.2.3",
23
23
  "typescript": "^5"
24
24
  }
25
25
  }
@@ -11,20 +11,20 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "{{osdkPackage}}": "latest",
14
- "react": "^18.2.0",
15
- "react-dom": "^18.2.0",
16
- "react-router-dom": "^6.20.1"
14
+ "react": "^18",
15
+ "react-dom": "^18",
16
+ "react-router-dom": "^6.23.1"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/react": "^18",
20
- "@types/react-dom": "^18.2.15",
20
+ "@types/react-dom": "^18",
21
21
  "@typescript-eslint/eslint-plugin": "^7.8.0",
22
22
  "@typescript-eslint/parser": "^7.8.0",
23
23
  "@vitejs/plugin-react": "^4.2.0",
24
24
  "eslint": "^8.57.0",
25
- "eslint-plugin-react-hooks": "^4.6.0",
25
+ "eslint-plugin-react-hooks": "^4.6.2",
26
26
  "eslint-plugin-react-refresh": "^0.4.6",
27
27
  "typescript": "^5.2.2",
28
- "vite": "^5.0.13"
28
+ "vite": "^5.2.11"
29
29
  }
30
30
  }
@@ -11,21 +11,21 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "{{osdkPackage}}": "latest",
14
- "react": "^18.2.0",
15
- "react-dom": "^18.2.0",
16
- "react-router-dom": "^6.20.1",
14
+ "react": "^18",
15
+ "react-dom": "^18",
16
+ "react-router-dom": "^6.23.1",
17
17
  "swr": "^2.2.5"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/react": "^18",
21
- "@types/react-dom": "^18.2.15",
21
+ "@types/react-dom": "^18",
22
22
  "@typescript-eslint/eslint-plugin": "^7.8.0",
23
23
  "@typescript-eslint/parser": "^7.8.0",
24
24
  "@vitejs/plugin-react": "^4.2.0",
25
25
  "eslint": "^8.57.0",
26
- "eslint-plugin-react-hooks": "^4.6.0",
26
+ "eslint-plugin-react-hooks": "^4.6.2",
27
27
  "eslint-plugin-react-refresh": "^0.4.6",
28
28
  "typescript": "^5.2.2",
29
- "vite": "^5.0.13"
29
+ "vite": "^5.2.11"
30
30
  }
31
31
  }
@@ -1,10 +1,10 @@
1
- import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
1
  import { useCallback, useState } from "react";
3
2
  import CreateTaskDialog from "./CreateTaskDialog";
3
+ import { MockProject } from "./mocks";
4
4
  import { useProjectTasks } from "./useProjectTasks";
5
5
 
6
6
  interface CreateTaskButtonProps {
7
- project: OsdkTodoProject;
7
+ project: MockProject;
8
8
  }
9
9
 
10
10
  function CreateTaskButton({ project }: CreateTaskButtonProps) {
@@ -1,10 +1,10 @@
1
- import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
1
  import { ChangeEvent, useCallback, useEffect, useState } from "react";
3
2
  import Dialog from "./Dialog";
3
+ import { MockProject } from "./mocks";
4
4
  import { useProjectTasks } from "./useProjectTasks";
5
5
 
6
6
  interface CreateTaskDialogProps {
7
- project: OsdkTodoProject;
7
+ project: MockProject;
8
8
  isOpen: boolean;
9
9
  onClose: () => void;
10
10
  }
@@ -1,10 +1,10 @@
1
- import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
1
  import { useCallback, useState } from "react";
3
2
  import DeleteProjectDialog from "./DeleteProjectDialog";
3
+ import { MockProject } from "./mocks";
4
4
  import useProjects from "./useProjects";
5
5
 
6
6
  interface DeleteProjectButtonProps {
7
- project: OsdkTodoProject;
7
+ project: MockProject;
8
8
  }
9
9
 
10
10
  function DeleteProjectButton({ project }: DeleteProjectButtonProps) {
@@ -1,10 +1,10 @@
1
- import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
1
  import { useCallback, useState } from "react";
3
2
  import Dialog from "./Dialog";
3
+ import { MockProject } from "./mocks";
4
4
  import useProjects from "./useProjects";
5
5
 
6
6
  interface DeleteProjectDialogProps {
7
- project: OsdkTodoProject;
7
+ project: MockProject;
8
8
  isOpen: boolean;
9
9
  onClose: () => void;
10
10
  }
@@ -1,10 +1,10 @@
1
- import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
1
  import { useCallback, useEffect, useState } from "react";
3
2
  import CreateProjectButton from "./CreateProjectButton";
4
3
  import CreateTaskButton from "./CreateTaskButton";
5
4
  import DeleteProjectButton from "./DeleteProjectButton";
6
5
  import css from "./Home.module.css";
7
6
  import Layout from "./Layout";
7
+ import { MockProject } from "./mocks";
8
8
  import ProjectSelect from "./ProjectSelect";
9
9
  import TaskList from "./TaskList";
10
10
  import useProjects from "./useProjects";
@@ -15,7 +15,7 @@ function Home() {
15
15
  const project = projects?.find((p) => p.id === projectId);
16
16
 
17
17
  const handleSelectProject = useCallback(
18
- (p: OsdkTodoProject) => setProjectId(p.id),
18
+ (p: MockProject) => setProjectId(p.id),
19
19
  [],
20
20
  );
21
21
 
@@ -1,10 +1,10 @@
1
- import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
1
  import { ChangeEvent, useCallback } from "react";
2
+ import { MockProject } from "./mocks";
3
3
 
4
4
  interface ProjectSelectProps {
5
- project: OsdkTodoProject | undefined;
6
- projects: OsdkTodoProject[];
7
- onSelectProject: (project: OsdkTodoProject) => void;
5
+ project: MockProject | undefined;
6
+ projects: MockProject[];
7
+ onSelectProject: (project: MockProject) => void;
8
8
  }
9
9
 
10
10
  function ProjectSelect({
@@ -1,10 +1,10 @@
1
- import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
1
+ import { MockProject } from "./mocks";
2
2
  import css from "./TaskList.module.css";
3
3
  import TaskListItem from "./TaskListItem";
4
4
  import { useProjectTasks } from "./useProjectTasks";
5
5
 
6
6
  interface TaskListProps {
7
- project: OsdkTodoProject;
7
+ project: MockProject;
8
8
  }
9
9
 
10
10
  function TaskList({ project }: TaskListProps) {
@@ -1,10 +1,10 @@
1
- import { OsdkTodoTask } from "{{osdkPackage}}/ontology/objects";
2
1
  import { useCallback, useState } from "react";
2
+ import { MockTask } from "./mocks";
3
3
  import css from "./TaskListItem.module.css";
4
4
 
5
5
  interface TaskListItemProps {
6
- task: OsdkTodoTask;
7
- deleteTask: (task: OsdkTodoTask) => Promise<void>;
6
+ task: MockTask;
7
+ deleteTask: (task: MockTask) => Promise<void>;
8
8
  }
9
9
 
10
10
  function TaskListItem({ task, deleteTask }: TaskListItemProps) {
@@ -0,0 +1,137 @@
1
+ export interface MockProject {
2
+ __apiName: string;
3
+ __primaryKey: string;
4
+ id: string;
5
+ name: string;
6
+ tasks: MockTask[];
7
+ }
8
+
9
+ export interface MockTask {
10
+ __apiName: string;
11
+ __primaryKey: string;
12
+ id: string;
13
+ title: string;
14
+ }
15
+
16
+ const projects: MockProject[] = [
17
+ {
18
+ __apiName: "MockProject",
19
+ __primaryKey: "1",
20
+ id: "1",
21
+ name: "Fake Project",
22
+ tasks: [
23
+ {
24
+ __apiName: "MockTask",
25
+ __primaryKey: "1",
26
+ id: "1",
27
+ title: "Try to",
28
+ },
29
+ {
30
+ __apiName: "MockTask",
31
+ __primaryKey: "2",
32
+ id: "2",
33
+ title: "Implement this",
34
+ },
35
+ {
36
+ __apiName: "MockTask",
37
+ __primaryKey: "3",
38
+ id: "3",
39
+ title: "With the Ontology SDK!",
40
+ },
41
+ ],
42
+ },
43
+ {
44
+ __apiName: "MockProject",
45
+ __primaryKey: "2",
46
+ id: "2",
47
+ name: "Yet Another Fake Project",
48
+ tasks: [
49
+ {
50
+ __apiName: "MockTask",
51
+ __primaryKey: "4",
52
+ id: "4",
53
+ title: "More tasks here",
54
+ },
55
+ ],
56
+ },
57
+ ];
58
+
59
+ async function delay(): Promise<void> {
60
+ return new Promise((resolve) =>
61
+ setTimeout(() => resolve(), 500 + Math.random() * 1000)
62
+ );
63
+ }
64
+
65
+ // Good enough random id for mocks
66
+ function randomId(): string {
67
+ return `${Math.floor(Math.random() * 2 ** 31)}`;
68
+ }
69
+
70
+ async function getProjects(): Promise<MockProject[]> {
71
+ await delay();
72
+ const result = [...projects];
73
+ result.sort((p1, p2) => p1.name.localeCompare(p2.name));
74
+ return result;
75
+ }
76
+
77
+ async function createProject({
78
+ name,
79
+ }: {
80
+ name: string;
81
+ }): Promise<MockTask["__primaryKey"]> {
82
+ await delay();
83
+ const id = randomId();
84
+ projects.push({
85
+ __apiName: "MockProject",
86
+ __primaryKey: id,
87
+ id,
88
+ name,
89
+ tasks: [],
90
+ });
91
+ return id;
92
+ }
93
+
94
+ async function deleteProject(id: string): Promise<void> {
95
+ await delay();
96
+ const idx = projects.findIndex((p) => p.id === id);
97
+ if (idx !== -1) {
98
+ projects.splice(idx, 1);
99
+ }
100
+ }
101
+
102
+ async function createTask({
103
+ title,
104
+ projectId,
105
+ }: {
106
+ title: string;
107
+ projectId: string;
108
+ }): Promise<MockTask["__primaryKey"]> {
109
+ await delay();
110
+ const project = projects.find((p) => p.id === projectId);
111
+ if (project == null) {
112
+ throw new Error(`Project ${projectId} not found!`);
113
+ }
114
+ const id = randomId();
115
+ project.tasks.unshift({ __apiName: "MockTask", __primaryKey: id, id, title });
116
+ return id;
117
+ }
118
+
119
+ async function deleteTask(id: string): Promise<void> {
120
+ await delay();
121
+ for (const project of projects) {
122
+ const idx = project.tasks.findIndex((t) => t.id === id);
123
+ if (idx !== -1) {
124
+ project.tasks.splice(idx, 1);
125
+ }
126
+ }
127
+ }
128
+
129
+ const Mocks = {
130
+ getProjects,
131
+ createProject,
132
+ deleteProject,
133
+ createTask,
134
+ deleteTask,
135
+ };
136
+
137
+ export default Mocks;
@@ -1,42 +1,38 @@
1
- import { OsdkTodoProject, OsdkTodoTask } from "{{osdkPackage}}/ontology/objects";
2
1
  import { useCallback } from "react";
3
2
  import useSWR from "swr";
4
- import Mocks from "./mocks";
3
+ import Mocks, { MockProject, MockTask } from "./mocks";
5
4
 
6
- export function useProjectTasks(project: OsdkTodoProject | undefined) {
7
- const { data, isLoading, isValidating, error, mutate } = useSWR<OsdkTodoTask[]>(
5
+ export function useProjectTasks(project: MockProject | undefined) {
6
+ const { data, isLoading, isValidating, error, mutate } = useSWR<MockTask[]>(
8
7
  project != null ? `projects/${project.id}/tasks` : null,
8
+ // Try to implement this with the Ontology SDK!
9
9
  async () => {
10
10
  if (project == null) {
11
11
  return [];
12
12
  }
13
- const result = await project.osdkTodoTasks.all();
14
- if (result.type !== "ok") {
15
- throw result.error;
16
- }
17
- return result.value;
18
- }
13
+ return project.tasks;
14
+ },
19
15
  );
20
16
 
21
17
  const createTask: (
22
- name: string
23
- ) => Promise<OsdkTodoTask["__primaryKey"] | undefined> = useCallback(
24
- async (name) => {
18
+ title: string,
19
+ ) => Promise<MockTask["__primaryKey"] | undefined> = useCallback(
20
+ async (title) => {
25
21
  if (project == null) {
26
22
  return undefined;
27
23
  }
28
24
  // Try to implement this with the Ontology SDK!
29
25
  const id = await Mocks.createTask({
30
- name,
26
+ title,
31
27
  projectId: project.__primaryKey,
32
28
  });
33
29
  await mutate();
34
30
  return id;
35
31
  },
36
- [project, mutate]
32
+ [project, mutate],
37
33
  );
38
34
 
39
- const deleteTask: (task: OsdkTodoTask) => Promise<void> = useCallback(
35
+ const deleteTask: (task: MockTask) => Promise<void> = useCallback(
40
36
  async (task) => {
41
37
  if (project == null) {
42
38
  return;
@@ -45,7 +41,7 @@ export function useProjectTasks(project: OsdkTodoProject | undefined) {
45
41
  await Mocks.deleteTask(task.__primaryKey);
46
42
  await mutate();
47
43
  },
48
- [project, mutate]
44
+ [project, mutate],
49
45
  );
50
46
 
51
47
  return {
@@ -1,17 +1,16 @@
1
- import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
1
  import { useCallback } from "react";
3
2
  import useSWR from "swr";
4
- import Mocks from "./mocks";
3
+ import Mocks, { MockProject } from "./mocks";
5
4
 
6
5
  function useProjects() {
7
6
  const { data, isLoading, isValidating, error, mutate } = useSWR<
8
- OsdkTodoProject[]
7
+ MockProject[]
9
8
  >("projects", async () => {
10
9
  // Try to implement this with the Ontology SDK!
11
10
  return Mocks.getProjects();
12
11
  });
13
12
 
14
- const createProject: (name: string) => Promise<OsdkTodoProject["__primaryKey"]> =
13
+ const createProject: (name: string) => Promise<MockProject["__primaryKey"]> =
15
14
  useCallback(
16
15
  async (name) => {
17
16
  // Try to implement this with the Ontology SDK!
@@ -19,16 +18,16 @@ function useProjects() {
19
18
  await mutate();
20
19
  return id;
21
20
  },
22
- [mutate]
21
+ [mutate],
23
22
  );
24
23
 
25
- const deleteProject: (project: OsdkTodoProject) => Promise<void> = useCallback(
24
+ const deleteProject: (project: MockProject) => Promise<void> = useCallback(
26
25
  async (project) => {
27
26
  // Try to implement this with the Ontology SDK!
28
27
  await Mocks.deleteProject(project.__primaryKey);
29
28
  await mutate();
30
29
  },
31
- [mutate]
30
+ [mutate],
32
31
  );
33
32
 
34
33
  return {
@@ -16,7 +16,7 @@
16
16
  "devDependencies": {
17
17
  "@vitejs/plugin-vue": "^4.5.0",
18
18
  "typescript": "^5.2.2",
19
- "vite": "^5.0.13",
19
+ "vite": "^5.2.11",
20
20
  "vue-tsc": "^1.8.22"
21
21
  }
22
22
  }
@@ -1,208 +0,0 @@
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;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes