create-harper 0.0.1 → 0.0.2

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 (102) hide show
  1. package/lib/constants/defaultTargetDir.js +1 -0
  2. package/lib/constants/frameworks.js +75 -0
  3. package/lib/constants/helpMessage.js +23 -0
  4. package/lib/constants/renameFiles.js +6 -0
  5. package/lib/constants/templates.js +6 -0
  6. package/lib/fs/applyAndWriteTemplateFile.js +9 -0
  7. package/lib/fs/copy.js +11 -0
  8. package/lib/fs/copyDir.js +12 -0
  9. package/lib/fs/crawlTemplateDir.js +18 -0
  10. package/lib/fs/editFile.js +6 -0
  11. package/lib/fs/emptyDir.js +14 -0
  12. package/lib/fs/formatTargetDir.js +3 -0
  13. package/lib/fs/isEmpty.js +6 -0
  14. package/lib/install.js +17 -0
  15. package/lib/pkg/getFullCustomCommand.js +47 -0
  16. package/lib/pkg/getInstallCommand.js +6 -0
  17. package/lib/pkg/getRunCommand.js +12 -0
  18. package/lib/pkg/isValidPackageName.js +5 -0
  19. package/lib/pkg/pkgFromUserAgent.js +9 -0
  20. package/lib/pkg/toValidPackageName.js +8 -0
  21. package/lib/run.js +14 -0
  22. package/lib/start.js +15 -0
  23. package/package.json +10 -2
  24. package/template-barebones/README.md +7 -0
  25. package/template-barebones/config.yaml +7 -0
  26. package/template-barebones/package.json +14 -0
  27. package/template-barebones/schema.graphql +1 -0
  28. package/template-react/README.md +45 -0
  29. package/template-react/_github/workflow/deploy.yaml +40 -0
  30. package/template-react/config.yaml +23 -0
  31. package/template-react/deploy-template/config.yaml +2 -0
  32. package/template-react/deploy-template/fastify/static.js +14 -0
  33. package/template-react/deploy-template/package.json +5 -0
  34. package/template-react/index.html +13 -0
  35. package/template-react/package.json +24 -0
  36. package/template-react/public/react.svg +14 -0
  37. package/template-react/public/typescript.svg +16 -0
  38. package/template-react/public/vite.svg +42 -0
  39. package/template-react/resources.js +27 -0
  40. package/template-react/schema.graphql +5 -0
  41. package/template-react/src/App.jsx +34 -0
  42. package/template-react/src/main.jsx +13 -0
  43. package/template-react/src/style.css +96 -0
  44. package/template-react/src/vite-env.d.ts +9 -0
  45. package/template-react/vite.config.js +22 -0
  46. package/template-react-ts/README.md +45 -0
  47. package/template-react-ts/_github/workflow/deploy.yaml +40 -0
  48. package/template-react-ts/config.yaml +23 -0
  49. package/template-react-ts/deploy-template/config.yaml +2 -0
  50. package/template-react-ts/deploy-template/fastify/static.js +14 -0
  51. package/template-react-ts/deploy-template/package.json +5 -0
  52. package/template-react-ts/index.html +13 -0
  53. package/template-react-ts/package.json +28 -0
  54. package/template-react-ts/public/react.svg +14 -0
  55. package/template-react-ts/public/typescript.svg +16 -0
  56. package/template-react-ts/public/vite.svg +42 -0
  57. package/template-react-ts/resources.ts +52 -0
  58. package/template-react-ts/schema.graphql +5 -0
  59. package/template-react-ts/src/App.tsx +34 -0
  60. package/template-react-ts/src/main.tsx +13 -0
  61. package/template-react-ts/src/style.css +96 -0
  62. package/template-react-ts/src/vite-env.d.ts +9 -0
  63. package/template-react-ts/tsconfig.json +34 -0
  64. package/template-react-ts/vite.config.ts +22 -0
  65. package/template-shared/_aiignore +1 -0
  66. package/template-shared/_env.example +3 -0
  67. package/template-shared/_gitignore +147 -0
  68. package/template-shared/graphql.config.yml +3 -0
  69. package/template-studio/README.md +34 -0
  70. package/template-studio/config.yaml +24 -0
  71. package/template-studio/package.json +14 -0
  72. package/template-studio/resources.js +27 -0
  73. package/template-studio/schema.graphql +7 -0
  74. package/template-studio/web/index.html +28 -0
  75. package/template-studio/web/index.js +18 -0
  76. package/template-studio/web/styles.css +57 -0
  77. package/template-studio-ts/README.md +34 -0
  78. package/template-studio-ts/config.yaml +24 -0
  79. package/template-studio-ts/package.json +14 -0
  80. package/template-studio-ts/resources.ts +52 -0
  81. package/template-studio-ts/schema.graphql +7 -0
  82. package/template-studio-ts/tsconfig.json +10 -0
  83. package/template-studio-ts/web/index.html +28 -0
  84. package/template-studio-ts/web/index.js +18 -0
  85. package/template-studio-ts/web/styles.css +57 -0
  86. package/template-vanilla/README.md +57 -0
  87. package/template-vanilla/config.yaml +24 -0
  88. package/template-vanilla/package.json +14 -0
  89. package/template-vanilla/resources.js +27 -0
  90. package/template-vanilla/schema.graphql +7 -0
  91. package/template-vanilla/web/index.html +28 -0
  92. package/template-vanilla/web/index.js +18 -0
  93. package/template-vanilla/web/styles.css +57 -0
  94. package/template-vanilla-ts/README.md +57 -0
  95. package/template-vanilla-ts/config.yaml +24 -0
  96. package/template-vanilla-ts/package.json +14 -0
  97. package/template-vanilla-ts/resources.ts +52 -0
  98. package/template-vanilla-ts/schema.graphql +7 -0
  99. package/template-vanilla-ts/tsconfig.json +10 -0
  100. package/template-vanilla-ts/web/index.html +28 -0
  101. package/template-vanilla-ts/web/index.js +18 -0
  102. package/template-vanilla-ts/web/styles.css +57 -0
@@ -0,0 +1,96 @@
1
+ :root {
2
+ font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
3
+ line-height: 1.5;
4
+ font-weight: 400;
5
+
6
+ color-scheme: light dark;
7
+ color: rgba(255, 255, 255, 0.87);
8
+ background-color: #242424;
9
+
10
+ font-synthesis: none;
11
+ text-rendering: optimizeLegibility;
12
+ -webkit-font-smoothing: antialiased;
13
+ -moz-osx-font-smoothing: grayscale;
14
+ }
15
+
16
+ a {
17
+ font-weight: 500;
18
+ color: #646cff;
19
+ text-decoration: inherit;
20
+ }
21
+ a:hover {
22
+ color: #535bf2;
23
+ }
24
+
25
+ body {
26
+ margin: 0;
27
+ display: flex;
28
+ place-items: center;
29
+ min-width: 320px;
30
+ min-height: 100vh;
31
+ }
32
+
33
+ h1 {
34
+ font-size: 3.2em;
35
+ line-height: 1.1;
36
+ }
37
+
38
+ #app {
39
+ max-width: 1280px;
40
+ margin: 0 auto;
41
+ padding: 2rem;
42
+ text-align: center;
43
+ }
44
+
45
+ .logo {
46
+ height: 6em;
47
+ padding: 1.5em;
48
+ will-change: filter;
49
+ transition: filter 300ms;
50
+ }
51
+ .logo:hover {
52
+ filter: drop-shadow(0 0 2em #646cffaa);
53
+ }
54
+ .logo.vanilla:hover {
55
+ filter: drop-shadow(0 0 2em #3178c6aa);
56
+ }
57
+
58
+ .card {
59
+ padding: 2em;
60
+ }
61
+
62
+ .read-the-docs {
63
+ color: #888;
64
+ }
65
+
66
+ button {
67
+ border-radius: 8px;
68
+ border: 1px solid transparent;
69
+ padding: 0.6em 1.2em;
70
+ font-size: 1em;
71
+ font-weight: 500;
72
+ font-family: inherit;
73
+ background-color: #1a1a1a;
74
+ cursor: pointer;
75
+ transition: border-color 0.25s;
76
+ }
77
+ button:hover {
78
+ border-color: #646cff;
79
+ }
80
+ button:focus,
81
+ button:focus-visible {
82
+ outline: 4px auto -webkit-focus-ring-color;
83
+ }
84
+
85
+ @media (prefers-color-scheme: light) {
86
+ :root {
87
+ color: #213547;
88
+ background-color: #ffffff;
89
+ }
90
+ a:hover {
91
+ color: #747bff;
92
+ }
93
+ button {
94
+ background-color: #f9f9f9;
95
+ }
96
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ interface ImportMetaEnv {
4
+ readonly VITE_EXAMPLE_ENV_VAR: string;
5
+ }
6
+
7
+ interface ImportMeta {
8
+ readonly env: ImportMetaEnv;
9
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "types": ["vite/client"],
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "jsx": "react-jsx",
11
+ "baseUrl": ".",
12
+ "paths": {
13
+ "@/*": [
14
+ "./src/*"
15
+ ]
16
+ },
17
+
18
+ /* Bundler mode */
19
+ "moduleResolution": "bundler",
20
+ "allowImportingTsExtensions": true,
21
+ "verbatimModuleSyntax": true,
22
+ "moduleDetection": "force",
23
+ "noEmit": true,
24
+
25
+ /* Linting */
26
+ "strict": true,
27
+ "noUnusedLocals": true,
28
+ "noUnusedParameters": true,
29
+ "erasableSyntaxOnly": true,
30
+ "noFallthroughCasesInSwitch": true,
31
+ "noUncheckedSideEffectImports": true
32
+ },
33
+ "include": ["src"]
34
+ }
@@ -0,0 +1,22 @@
1
+ import react from '@vitejs/plugin-react';
2
+ import path from 'node:path';
3
+ import { defineConfig } from 'vite';
4
+
5
+ // https://vite.dev/config/
6
+ export default defineConfig({
7
+ plugins: [
8
+ react(),
9
+ ],
10
+ resolve: {
11
+ alias: {
12
+ '@': path.resolve(__dirname, './src'),
13
+ },
14
+ },
15
+ build: {
16
+ outDir: 'web',
17
+ emptyOutDir: true,
18
+ rolldownOptions: {
19
+ external: ['**/*.test.*', '**/*.spec.*'],
20
+ },
21
+ },
22
+ });
@@ -0,0 +1 @@
1
+ .env
@@ -0,0 +1,3 @@
1
+ CLI_TARGET_USERNAME='YOUR_CLUSTER_USERNAME'
2
+ CLI_TARGET_PASSWORD='YOUR_CLUSER_PASSWORD'
3
+ CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSER_URL_HERE'
@@ -0,0 +1,147 @@
1
+ .DS_Store
2
+
3
+ #
4
+ # https://raw.githubusercontent.com/github/gitignore/refs/heads/main/Node.gitignore
5
+ #
6
+
7
+ # Logs
8
+ logs
9
+ *.log
10
+ npm-debug.log*
11
+ yarn-debug.log*
12
+ yarn-error.log*
13
+ lerna-debug.log*
14
+
15
+ # Diagnostic reports (https://nodejs.org/api/report.html)
16
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
17
+
18
+ # Runtime data
19
+ pids
20
+ *.pid
21
+ *.seed
22
+ *.pid.lock
23
+
24
+ # Directory for instrumented libs generated by jscoverage/JSCover
25
+ lib-cov
26
+
27
+ # Coverage directory used by tools like istanbul
28
+ coverage
29
+ *.lcov
30
+
31
+ # nyc test coverage
32
+ .nyc_output
33
+
34
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
35
+ .grunt
36
+
37
+ # Bower dependency directory (https://bower.io/)
38
+ bower_components
39
+
40
+ # node-waf configuration
41
+ .lock-wscript
42
+
43
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
44
+ build/Release
45
+
46
+ # Dependency directories
47
+ node_modules/
48
+ jspm_packages/
49
+
50
+ # Snowpack dependency directory (https://snowpack.dev/)
51
+ web_modules/
52
+
53
+ # TypeScript cache
54
+ *.tsbuildinfo
55
+
56
+ # Optional npm cache directory
57
+ .npm
58
+
59
+ # Optional eslint cache
60
+ .eslintcache
61
+
62
+ # Optional stylelint cache
63
+ .stylelintcache
64
+
65
+ # Optional REPL history
66
+ .node_repl_history
67
+
68
+ # Output of 'npm pack'
69
+ *.tgz
70
+
71
+ # Yarn Integrity file
72
+ .yarn-integrity
73
+
74
+ # dotenv environment variable files
75
+ .env
76
+ .env.*
77
+ !.env.example
78
+
79
+ # parcel-bundler cache (https://parceljs.org/)
80
+ .cache
81
+ .parcel-cache
82
+
83
+ # Next.js build output
84
+ .next
85
+ out
86
+
87
+ # Nuxt.js build / generate output
88
+ .nuxt
89
+ dist
90
+ .output
91
+
92
+ # Gatsby files
93
+ .cache/
94
+ # Comment in the public line in if your project uses Gatsby and not Next.js
95
+ # https://nextjs.org/blog/next-9-1#public-directory-support
96
+ # public
97
+
98
+ # vuepress build output
99
+ .vuepress/dist
100
+
101
+ # vuepress v2.x temp and cache directory
102
+ .temp
103
+ .cache
104
+
105
+ # Sveltekit cache directory
106
+ .svelte-kit/
107
+
108
+ # vitepress build output
109
+ **/.vitepress/dist
110
+
111
+ # vitepress cache directory
112
+ **/.vitepress/cache
113
+
114
+ # Docusaurus cache and generated files
115
+ .docusaurus
116
+
117
+ # Serverless directories
118
+ .serverless/
119
+
120
+ # FuseBox cache
121
+ .fusebox/
122
+
123
+ # DynamoDB Local files
124
+ .dynamodb/
125
+
126
+ # Firebase cache directory
127
+ .firebase/
128
+
129
+ # TernJS port file
130
+ .tern-port
131
+
132
+ # Stores VSCode versions used for testing VSCode extensions
133
+ .vscode-test
134
+
135
+ # yarn v3
136
+ .pnp.*
137
+ .yarn/*
138
+ !.yarn/patches
139
+ !.yarn/plugins
140
+ !.yarn/releases
141
+ !.yarn/sdks
142
+ !.yarn/versions
143
+
144
+ # Vite files
145
+ vite.config.js.timestamp-*
146
+ vite.config.ts.timestamp-*
147
+ .vite/
@@ -0,0 +1,3 @@
1
+ schema: schema.graphql
2
+ include: node_modules/harperdb/schema.graphql
3
+ documents: '**/*.graphql'
@@ -0,0 +1,34 @@
1
+ # <<projectName>>
2
+
3
+ Your new app is now deployed and running on Harper Fabric!
4
+
5
+ Here's what you should do next:
6
+
7
+ ### 1. Define Your Schema
8
+
9
+ Open your [schema.graphql](./schema.graphql) and tap [+ New Table](./schema.graphql?ShowNewTableModal=true). This is
10
+ your table schema definition, and is the heart of a great Harper app. This is the main starting point for defining your
11
+ [database schema](./databases), specifying which tables you want and what attributes/fields they should have. REST
12
+ endpoints will get stood up for any table that you `@export`.
13
+
14
+ ### 2. Add Custom Endpoints
15
+
16
+ The [resources.js](./resources.js) provides a template for defining JavaScript resource classes for customized
17
+ application logic in your endpoints.
18
+
19
+ ### 3. View Your Website
20
+
21
+ Pop open [http://localhost:9926](http://localhost:9926) to view [web/index.html](./web/index.html) in your browser.
22
+
23
+ ### 4. Use Your API
24
+
25
+ Head to the [APIs](./apis) tab to explore your endpoints and exercise them. You can click the "Authenticate" button to
26
+ see what different users will be able to access through your API.
27
+
28
+ ## Keep Going!
29
+
30
+ For more information about getting started with Harper and building applications, see
31
+ our [getting started guide](https://docs.harperdb.io/docs).
32
+
33
+ For more information on Harper Components, see
34
+ the [Components documentation](https://docs.harperdb.io/docs/reference/components).
@@ -0,0 +1,24 @@
1
+ # yaml-language-server: $schema=./node_modules/harperdb/config-app.schema.json
2
+
3
+ # This is the configuration file for the application.
4
+ # It specifies built-in Harper components that will load the specified feature and files.
5
+ # For more information, see https://docs.harperdb.io/docs/reference/components/built-in-extensions
6
+
7
+ # Load Environment Variables from the specified file
8
+ # loadEnv:
9
+ # files: '.env'
10
+
11
+ # This provides the HTTP REST interface for all exported resources
12
+ rest: true
13
+
14
+ # These reads GraphQL schemas to define the schema of database/tables/attributes.
15
+ graphqlSchema:
16
+ files: 'schema.graphql'
17
+
18
+ # Loads JavaScript modules such that their exports are exported as resources
19
+ jsResource:
20
+ files: 'resources.js'
21
+
22
+ # Serve the static files from the web directory as a web application
23
+ static:
24
+ files: 'web/*'
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "<<packageName>>",
3
+ "version": "1.0.0",
4
+ "description": "Your new Harper app",
5
+ "type": "module",
6
+ "scripts": {
7
+ "start": "harperdb run .",
8
+ "dev": "harperdb dev .",
9
+ "deploy": "npx -y dotenv-cli -- harperdb deploy . restart=rolling replicated=true"
10
+ },
11
+ "devDependencies": {
12
+ "harperdb": "^4.7.15"
13
+ }
14
+ }
@@ -0,0 +1,27 @@
1
+ import { Resource } from 'harperdb';
2
+
3
+ /** Here we can define any JavaScript-based resources and extensions to tables
4
+ import {tables} from 'harperdb';
5
+
6
+ export class MyCustomResource extends tables.TableName {
7
+ // we can define our own custom POST handler
8
+ post(content) {
9
+ // do something with the incoming content;
10
+ return super.post(content);
11
+ }
12
+ // or custom GET handler
13
+ get() {
14
+ // we can modify this resource before returning
15
+ return super.get();
16
+ }
17
+ }
18
+ */
19
+ // we can also define a custom resource without a specific table
20
+ export class Greeting extends Resource {
21
+ // a "Hello, world!" handler
22
+ static loadAsInstance = false; // use the updated/newer Resource API
23
+
24
+ get() {
25
+ return { greeting: 'Hello, world!' };
26
+ }
27
+ }
@@ -0,0 +1,7 @@
1
+ ## Here we can define any tables in our database. This example shows how we define a type as a table using
2
+ ## the type name as the table name and specifying it is an "export" available in the REST and other external protocols.
3
+ type TableName @table @export {
4
+ id: ID @primaryKey # Here we define primary key (must be one)
5
+ name: String # we can define any other attributes here
6
+ tag: String @indexed # we can specify any attributes that should be indexed
7
+ }
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Harper Application Template</title>
7
+ <link rel="stylesheet" href="styles.css" />
8
+ </head>
9
+ <body>
10
+ <main>
11
+ <h1>Harper Application Template</h1>
12
+ <p>
13
+ This is an example of serving static assets using the built-in
14
+ <a
15
+ href="https://docs.harperdb.io/docs/reference/components/built-in-extensions#static"
16
+ >static component</a>. <br />
17
+ You can use this component to serve web applications!
18
+ </p>
19
+ <div>
20
+ <p class="count" id="count">0</p>
21
+ <button class="decrement" id="decrement">-</button>
22
+ <button class="increment" id="increment">+</button>
23
+ </div>
24
+ </main>
25
+
26
+ <script src="index.js"></script>
27
+ </body>
28
+ </html>
@@ -0,0 +1,18 @@
1
+ let count = 0;
2
+ const counterDisplay = document.getElementById('count');
3
+ const decrementButton = document.getElementById('decrement');
4
+ const incrementButton = document.getElementById('increment');
5
+
6
+ function updateDisplay() {
7
+ counterDisplay.textContent = count;
8
+ }
9
+
10
+ decrementButton.addEventListener('click', () => {
11
+ count--;
12
+ updateDisplay();
13
+ });
14
+
15
+ incrementButton.addEventListener('click', () => {
16
+ count++;
17
+ updateDisplay();
18
+ });
@@ -0,0 +1,57 @@
1
+ body {
2
+ font-family: Arial, sans-serif;
3
+ display: flex;
4
+ justify-content: center;
5
+ align-items: center;
6
+ height: 100vh;
7
+ margin: 0;
8
+ background-color: #f5f5f5;
9
+ }
10
+
11
+ main {
12
+ text-align: center;
13
+ background-color: white;
14
+ padding: 2rem;
15
+ border-radius: 8px;
16
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
17
+ }
18
+
19
+ .count {
20
+ font-size: 4rem;
21
+ margin: 1rem 0;
22
+ color: #333;
23
+ }
24
+
25
+ .counter-controls {
26
+ display: flex;
27
+ justify-content: center;
28
+ gap: 1rem;
29
+ }
30
+
31
+ button {
32
+ font-size: 1.5rem;
33
+ width: 3rem;
34
+ height: 3rem;
35
+ border: none;
36
+ border-radius: 50%;
37
+ cursor: pointer;
38
+ transition: background-color 0.2s;
39
+ }
40
+
41
+ .decrement {
42
+ background-color: #ff6b6b;
43
+ color: white;
44
+ }
45
+
46
+ .decrement:hover {
47
+ background-color: #ff5252;
48
+ }
49
+
50
+ .increment {
51
+ background-color: #4ecdc4;
52
+ color: white;
53
+ }
54
+
55
+ .increment:hover {
56
+ background-color: #39b2a9;
57
+ }
@@ -0,0 +1,34 @@
1
+ # <<projectName>>
2
+
3
+ Your new app is now deployed and running on Harper Fabric!
4
+
5
+ Here's what you should do next:
6
+
7
+ ### 1. Define Your Schema
8
+
9
+ Open your [schema.graphql](./schema.graphql) and tap [+ New Table](./schema.graphql?ShowNewTableModal=true). This is
10
+ your table schema definition, and is the heart of a great Harper app. This is the main starting point for defining your
11
+ [database schema](./databases), specifying which tables you want and what attributes/fields they should have. REST
12
+ endpoints will get stood up for any table that you `@export`.
13
+
14
+ ### 2. Add Custom Endpoints
15
+
16
+ The [resources.ts](./resources.ts) provides a template for defining JavaScript resource classes for customized
17
+ application logic in your endpoints.
18
+
19
+ ### 3. View Your Website
20
+
21
+ Pop open [http://localhost:9926](http://localhost:9926) to view [web/index.html](./web/index.html) in your browser.
22
+
23
+ ### 4. Use Your API
24
+
25
+ Head to the [APIs](./apis) tab to explore your endpoints and exercise them. You can click the "Authenticate" button to
26
+ see what different users will be able to access through your API.
27
+
28
+ ## Keep Going!
29
+
30
+ For more information about getting started with Harper and building applications, see
31
+ our [getting started guide](https://docs.harperdb.io/docs).
32
+
33
+ For more information on Harper Components, see
34
+ the [Components documentation](https://docs.harperdb.io/docs/reference/components).
@@ -0,0 +1,24 @@
1
+ # yaml-language-server: $schema=./node_modules/harperdb/config-app.schema.json
2
+
3
+ # This is the configuration file for the application.
4
+ # It specifies built-in Harper components that will load the specified feature and files.
5
+ # For more information, see https://docs.harperdb.io/docs/reference/components/built-in-extensions
6
+
7
+ # Load Environment Variables from the specified file
8
+ # loadEnv:
9
+ # files: '.env'
10
+
11
+ # This provides the HTTP REST interface for all exported resources
12
+ rest: true
13
+
14
+ # These reads GraphQL schemas to define the schema of database/tables/attributes.
15
+ graphqlSchema:
16
+ files: 'schema.graphql'
17
+
18
+ # Loads JavaScript modules such that their exports are exported as resources
19
+ jsResource:
20
+ files: 'resources.ts'
21
+
22
+ # Serve the static files from the web directory as a web application
23
+ static:
24
+ files: 'web/*'
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "<<packageName>>",
3
+ "version": "1.0.0",
4
+ "description": "Your new Harper app",
5
+ "type": "module",
6
+ "scripts": {
7
+ "start": "harperdb run .",
8
+ "dev": "harperdb dev .",
9
+ "deploy": "npx -y dotenv-cli -- harperdb deploy . restart=rolling replicated=true"
10
+ },
11
+ "devDependencies": {
12
+ "harperdb": "^4.7.15"
13
+ }
14
+ }
@@ -0,0 +1,52 @@
1
+ import { type RecordObject, type RequestTargetOrId, Resource } from 'harperdb';
2
+
3
+ /** Here we can define any JavaScript-based resources and extensions to tables
4
+ import { tables, type RequestTarget } from 'harperdb';
5
+
6
+ interface TableNameRecord {
7
+ id: string;
8
+ name: string;
9
+ tag: string;
10
+ }
11
+
12
+ export class TableName extends tables.TableName<TableNameRecord> {
13
+ // we can define our own custom POST handler
14
+ async post(target: RequestTargetOrId, newRecord: Omit<TableNameRecord, 'id'>) {
15
+ // do something with the incoming content;
16
+ return super.post(target, newRecord);
17
+ }
18
+ // or custom GET handler
19
+ async get(target: RequestTarget): Promise<TableNameRecord> {
20
+ // we can modify this resource before returning
21
+ return super.get(target);
22
+ }
23
+ }
24
+ */
25
+
26
+ interface GreetingRecord {
27
+ greeting: string;
28
+ }
29
+
30
+ export class Greeting extends Resource<GreetingRecord> {
31
+ static loadAsInstance = false;
32
+
33
+ async post(target: RequestTargetOrId, newRecord: Partial<GreetingRecord & RecordObject>): Promise<GreetingRecord> {
34
+ return { greeting: 'Greetings, post!' };
35
+ }
36
+
37
+ async get(target?: RequestTargetOrId): Promise<GreetingRecord> {
38
+ return { greeting: 'Greetings, get!' };
39
+ }
40
+
41
+ async put(target: RequestTargetOrId, record: GreetingRecord & RecordObject): Promise<GreetingRecord> {
42
+ return { greeting: 'Greetings, put!' };
43
+ }
44
+
45
+ async patch(target: RequestTargetOrId, record: Partial<GreetingRecord & RecordObject>): Promise<GreetingRecord> {
46
+ return { greeting: 'Greetings, patch!' };
47
+ }
48
+
49
+ async delete(target: RequestTargetOrId): Promise<boolean> {
50
+ return true;
51
+ }
52
+ }
@@ -0,0 +1,7 @@
1
+ ## Here we can define any tables in our database. This example shows how we define a type as a table using
2
+ ## the type name as the table name and specifying it is an "export" available in the REST and other external protocols.
3
+ type TableName @table @export {
4
+ id: ID @primaryKey # Here we define primary key (must be one)
5
+ name: String # we can define any other attributes here
6
+ tag: String @indexed # we can specify any attributes that should be indexed
7
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowImportingTsExtensions": true,
4
+ "lib": [
5
+ "es2015",
6
+ "dom",
7
+ "es2018.asynciterable"
8
+ ]
9
+ }
10
+ }