@harperfast/template-vanilla-ts-studio 0.7.0
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/.aiignore +1 -0
- package/.gitignore +147 -0
- package/README.md +50 -0
- package/config.yaml +24 -0
- package/graphql.config.yml +3 -0
- package/package.json +9 -0
- package/resources/examplePeople.ts +20 -0
- package/resources/exampleSocket.ts +41 -0
- package/resources/greeting.ts +29 -0
- package/schemas/examplePeople.graphql +7 -0
- package/tsconfig.json +10 -0
- package/web/index.html +28 -0
- package/web/index.js +18 -0
- package/web/styles.css +57 -0
package/.aiignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.env
|
package/.gitignore
ADDED
|
@@ -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/
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# your-project-name-here
|
|
2
|
+
|
|
3
|
+
Your new app is now deployed and running on Harper Fabric!
|
|
4
|
+
|
|
5
|
+
Here's what you should do next:
|
|
6
|
+
|
|
7
|
+
### Define Your Schema
|
|
8
|
+
|
|
9
|
+
Tap [+ New Table](./schemas/examplePeople.graphql?ShowNewTableModal=true) when viewing a schema file, and you'll be guided through the available options.
|
|
10
|
+
|
|
11
|
+
The [schemas/examplePeople.graphql](./schemas/examplePeople.graphql) is an example table schema definition. This is the main starting point for defining your [database schema](./databases), specifying which tables you want and what attributes/fields they should have.
|
|
12
|
+
|
|
13
|
+
Open your [schemas/examplePeople.graphql](./schemas/examplePeople.graphql) to take a look at an example schema. You can add as many table definitions to a single schema file as you want. You can also create one file per schema.
|
|
14
|
+
|
|
15
|
+
These schemas are the heart of a great Harper app. This is the main starting point for defining your [database schema](./databases), specifying which tables you want and what attributes/fields they should have. REST endpoints will get stood up for any table that you `@export`.
|
|
16
|
+
|
|
17
|
+
### Add Custom Endpoints
|
|
18
|
+
|
|
19
|
+
The [resources/greeting.ts](./resources/greeting.ts) provides a template for defining TypeScript resource classes, for customized application logic in your endpoints.
|
|
20
|
+
|
|
21
|
+
### View Your Website
|
|
22
|
+
|
|
23
|
+
Pop open [http://localhost:9926](http://localhost:9926) to view [web/index.html](./web/index.html) in your browser.
|
|
24
|
+
|
|
25
|
+
### Use Your API
|
|
26
|
+
|
|
27
|
+
Head to the [APIs](./apis) tab to explore your endpoints and exercise them. You can click the "Authenticate" button to
|
|
28
|
+
see what different users will be able to access through your API.
|
|
29
|
+
|
|
30
|
+
Test your application works by querying the `/Greeting` endpoint:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
curl http://localhost:9926/Greeting
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You should see the following:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{ "greeting": "Hello, world!" }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Configure Your App
|
|
43
|
+
|
|
44
|
+
Take a look at the [default configuration](./config.yaml), which specifies how files are handled in your application.
|
|
45
|
+
|
|
46
|
+
## Keep Going!
|
|
47
|
+
|
|
48
|
+
For more information about getting started with Harper and building applications, see our [getting started guide](https://docs.harperdb.io/docs).
|
|
49
|
+
|
|
50
|
+
For more information on Harper Components, see the [Components documentation](https://docs.harperdb.io/docs/reference/components).
|
package/config.yaml
ADDED
|
@@ -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: 'schemas/*.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/*'
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type RequestTargetOrId, tables } from 'harperdb';
|
|
2
|
+
|
|
3
|
+
export interface ExamplePerson {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
tag: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class ExamplePeople extends tables.ExamplePeople<ExamplePerson> {
|
|
10
|
+
// we can define our own custom POST handler
|
|
11
|
+
async post(target: RequestTargetOrId, newRecord: Omit<ExamplePerson, 'id'>) {
|
|
12
|
+
// do something with the incoming content;
|
|
13
|
+
return super.post(target, newRecord);
|
|
14
|
+
}
|
|
15
|
+
// or custom GET handler
|
|
16
|
+
async get(target: RequestTargetOrId): Promise<ExamplePerson> {
|
|
17
|
+
// we can modify this resource before returning
|
|
18
|
+
return super.get(target);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type IterableEventQueue, RequestTarget, Resource, tables } from 'harperdb';
|
|
2
|
+
|
|
3
|
+
interface ExampleSocketRecord {
|
|
4
|
+
id: string;
|
|
5
|
+
type?: 'get' | 'put';
|
|
6
|
+
name: string;
|
|
7
|
+
tag: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class ExampleSocket extends Resource<ExampleSocketRecord> {
|
|
11
|
+
static loadAsInstance = false;
|
|
12
|
+
|
|
13
|
+
// This customizes handling the socket connections; tables can have this method too!
|
|
14
|
+
async *connect(
|
|
15
|
+
target: RequestTarget,
|
|
16
|
+
incomingMessages: IterableEventQueue<ExampleSocketRecord>,
|
|
17
|
+
): AsyncIterable<ExampleSocketRecord> {
|
|
18
|
+
const subscription = await tables.ExamplePeople.subscribe(target);
|
|
19
|
+
if (!incomingMessages) {
|
|
20
|
+
// Server sent events, no incoming messages!
|
|
21
|
+
// Subscribe to changes to the table.
|
|
22
|
+
return subscription;
|
|
23
|
+
}
|
|
24
|
+
for await (let message of incomingMessages) {
|
|
25
|
+
const { type, id, name, tag } = message;
|
|
26
|
+
switch (type) {
|
|
27
|
+
case 'get':
|
|
28
|
+
const loaded = await tables.ExamplePeople.get(id);
|
|
29
|
+
yield {
|
|
30
|
+
type: 'get',
|
|
31
|
+
id,
|
|
32
|
+
...(loaded ? loaded : {}),
|
|
33
|
+
};
|
|
34
|
+
break;
|
|
35
|
+
case 'put':
|
|
36
|
+
await tables.ExamplePeople.put(id, { name, tag });
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type RecordObject, type RequestTargetOrId, Resource } from 'harperdb';
|
|
2
|
+
|
|
3
|
+
interface GreetingRecord {
|
|
4
|
+
greeting: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class Greeting extends Resource<GreetingRecord> {
|
|
8
|
+
static loadAsInstance = false;
|
|
9
|
+
|
|
10
|
+
async post(target: RequestTargetOrId, newRecord: Partial<GreetingRecord & RecordObject>): Promise<GreetingRecord> {
|
|
11
|
+
return { greeting: 'Greetings, post!' };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async get(target?: RequestTargetOrId): Promise<GreetingRecord> {
|
|
15
|
+
return { greeting: 'Greetings, get!' };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async put(target: RequestTargetOrId, record: GreetingRecord & RecordObject): Promise<GreetingRecord> {
|
|
19
|
+
return { greeting: 'Greetings, put!' };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async patch(target: RequestTargetOrId, record: Partial<GreetingRecord & RecordObject>): Promise<GreetingRecord> {
|
|
23
|
+
return { greeting: 'Greetings, patch!' };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async delete(target: RequestTargetOrId): Promise<boolean> {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -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 ExamplePeople @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
|
+
}
|
package/tsconfig.json
ADDED
package/web/index.html
ADDED
|
@@ -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>your-project-name-here</title>
|
|
7
|
+
<link rel="stylesheet" href="styles.css" />
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<main>
|
|
11
|
+
<h1>your-project-name-here</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>
|
package/web/index.js
ADDED
|
@@ -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
|
+
});
|
package/web/styles.css
ADDED
|
@@ -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
|
+
}
|