@balena/pinejs 14.51.1 → 14.51.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.
@@ -1,3 +1,20 @@
1
+ - commits:
2
+ - subject: "Docs: Improve getting started doc"
3
+ hash: ee7df5cc1793438b8cc69b37607677fb7256e887
4
+ body: |
5
+ Give preference to TypeScript over CoffeeScript for the example app.
6
+ Improve code blocks by giving them types and removing unnecessary
7
+ characters to enable better copy-paste when viewing on GitHub.
8
+ footer:
9
+ Change-type: patch
10
+ change-type: patch
11
+ Signed-off-by: Josh Bowling <josh@monarci.com>
12
+ signed-off-by: Josh Bowling <josh@monarci.com>
13
+ author: Josh Bowling
14
+ nested: []
15
+ version: 14.51.2
16
+ title: ""
17
+ date: 2022-11-02T00:51:06.545Z
1
18
  - commits:
2
19
  - subject: "Docs: Fix TypeScript getting started example"
3
20
  hash: 491a79b281ed551cdf174412df7466cf411befb4
@@ -11,7 +28,7 @@
11
28
  nested: []
12
29
  version: 14.51.1
13
30
  title: ""
14
- date: 2022-11-01T06:47:04.345Z
31
+ date: 2022-11-01T06:55:17.123Z
15
32
  - commits:
16
33
  - subject: Update lodash typings
17
34
  hash: 734fd4c97f9438df4d2f80430739a4f1036e62cf
package/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file
4
4
  automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
5
5
  This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ # v14.51.2
8
+ ## (2022-11-02)
9
+
10
+ * Docs: Improve getting started doc [Josh Bowling]
11
+
7
12
  # v14.51.1
8
13
  ## (2022-11-01)
9
14
 
package/VERSION CHANGED
@@ -1 +1 @@
1
- 14.51.1
1
+ 14.51.2
@@ -8,30 +8,30 @@ Let's create a new Pine.js application. We will see that by defining our model r
8
8
 
9
9
  To begin with, you'll need to install PostgreSQL on your system, and configure a database and a user with read/write/metadata permissions on the database. In this guide, we will use `example` as the database name and `exampler` as the user name. Open your favorite terminal and type the following commands:
10
10
 
11
- ```
12
- $ createuser -W exampler
13
- $ createdb example -O exampler
11
+ ```sh
12
+ createuser -W exampler
13
+ createdb example -O exampler
14
14
  ```
15
15
 
16
16
  The above commands will create a user with name `exampler` and will prompt for a password, and then will set `exampler` as the database owner. You can also use your favorite tool to achieve the same result, such as pgAdmin.
17
17
 
18
18
  Next you'll need to install Pine.js as a dependency of your application. Go to a new directory that will use for your application. Let's say `pine-get-started` and type:
19
19
 
20
- ```
21
- $ npm init
20
+ ```sh
21
+ npm init
22
22
  ```
23
23
 
24
24
  Feel free to enter any information you like for your application when prompted, like application name, version, description, etc. The above command will initialize your application by creating the `package.json` file.
25
25
 
26
- ```
27
- $ npm install --save @balena/pinejs
26
+ ```sh
27
+ npm install @balena/pinejs
28
28
  ```
29
29
 
30
30
  The above commands will install pinejs as a dependency for your application, i.e. it will create the node_modules directory that amongst others will contain Pine.js, and will update the corresponding record in your `package.json` file.
31
31
 
32
32
  Let's see what your directory looks like now:
33
33
 
34
- ```
34
+ ```sh
35
35
  $ tree -L 3
36
36
  .
37
37
  ├── node_modules
@@ -44,7 +44,7 @@ Now, create a directory for our source files, `src` and enter that directory.
44
44
 
45
45
  First, we have to create a configuration file, `config.json` that will provide to Pine.js the necessary configuration regarding the resource model and the user permissions. Open your favorite editor and type the following into the `config.json` file:
46
46
 
47
- ```
47
+ ```json
48
48
  {
49
49
  "models": [{
50
50
  "modelName": "Example",
@@ -89,19 +89,55 @@ Fact Type: device has type
89
89
 
90
90
  In this model we are defining an entity called `device`, this entity has some attributes such as `name`, `note` and `type`, along with some constraints, ensuring that a device must have exactly one device type, and at most one name and one note. The `Vocabulary` declaration is a convenient way for partitioning parts of larger sbvr files.
91
91
 
92
- ### Initialise a CoffeeScript project
92
+ ### Initialise a TypeScript project
93
93
 
94
94
  Now, let's create a small main file for our application that will call the Pine.js server. Let's install some basic dependencies:
95
+ Create a small main file for our application that will call the Pine.js server. Let's install some basic dependencies:
95
96
 
97
+ ```sh
98
+ npm install express body-parser
99
+ npm install -D typescript ts-node @types/express
96
100
  ```
97
- $ npm install --save coffeescript
98
- $ npm install --save express
99
- $ npm install --save body-parser
101
+
102
+ And inside your `src` folder, create a file `app.ts` with the following content:
103
+
104
+ ```typescript
105
+ import express, { Request, Response } from 'express';
106
+ import * as pine from '@balena/pinejs';
107
+
108
+ const app = express();
109
+ app.use(express.urlencoded({ extended: true }));
110
+ app.use(express.json());
111
+
112
+ app.use('/ping', (_req: Request, res: Response) => {
113
+ res.sendStatus(200);
114
+ });
115
+
116
+ pine.init(app).then(() => {
117
+ app.listen(1337, () => {
118
+ console.log('server started');
119
+ });
120
+ });
100
121
  ```
101
122
 
102
- And inside your `src` folder, create a file `app.coffee` with the following content:
123
+ Inside your `package.json` file enter the following line inside the section `scripts`:
103
124
 
104
125
  ```
126
+ "start": "ts-node src/app.ts src"
127
+ ```
128
+
129
+ ### Initialise a CoffeeScript project
130
+
131
+ Alternatively, here's an example of the same small application written in CoffeeScript.
132
+ Install some basic dependencies:
133
+
134
+ ```sh
135
+ npm install coffeescript express body-parser
136
+ ```
137
+
138
+ And inside your `src` folder, create a file `app.coffee` with the following content:
139
+
140
+ ```coffeescript
105
141
  pinejs = require '@balena/pinejs'
106
142
  express = require 'express'
107
143
  app = express()
@@ -120,7 +156,6 @@ pinejs.init(app)
120
156
  console.info('Server started')
121
157
  ```
122
158
 
123
-
124
159
  Finally, inside your `package.json` file enter the following line inside the section `scripts`:
125
160
 
126
161
  ```
@@ -129,7 +164,7 @@ Finally, inside your `package.json` file enter the following line inside the sec
129
164
 
130
165
  Let's see what our application directory looks like now:
131
166
 
132
- ```
167
+ ```sh
133
168
  $ tree -L 3
134
169
  .
135
170
  ├── node_modules
@@ -169,44 +204,12 @@ $ tree -L 3
169
204
  └── example.sbvr
170
205
  ```
171
206
 
172
- ### Initialise a TypeScript project
173
-
174
- ```sh
175
- npm install express body-parser
176
- npm install -D typescript ts-node @types/express
177
- ```
178
-
179
- ```typescript
180
- import express, { Request, Response } from 'express';
181
- import * as pine from '@balena/pinejs';
182
-
183
- const app = express();
184
- app.use(express.urlencoded({ extended: true }));
185
- app.use(express.json());
186
-
187
- app.use('/ping', (_req: Request, res: Response) => {
188
- res.sendStatus(200);
189
- });
190
-
191
- pine.init(app).then(() => {
192
- app.listen(1337, () => {
193
- console.log('server started');
194
- });
195
- });
196
- ```
197
-
198
- Inside your `package.json` file enter the following line inside the section `scripts`:
199
-
200
- ```
201
- "start": "ts-node src/app.ts src"
202
- ```
203
-
204
207
  ### Start the server
205
208
 
206
209
  Assuming postgreSQL is running, execute the following command, replacing `[your_password]` with the password you set for the user `exampler`.
207
210
 
208
- ```
209
- $ DATABASE_URL=postgres://exampler:[your_password]@localhost:5432/example npm start
211
+ ```sh
212
+ DATABASE_URL=postgres://exampler:[your_password]@localhost:5432/example npm start
210
213
  ```
211
214
 
212
215
  Pine.js will connect to the `example` database and it will create the database schema and the associated API endpoints. Once the server is up, use your favourite tool, such as pgAdmin, to connect to the database and take a look inside. Among the other things, you will find that Pine.js has created a table called `device`, which will contain the devices we earlier specified in the model. By inspecting the structure of this table, you can see that the constraints specified in sbvr model get directly translated to constraints in the underlying database.
@@ -221,8 +224,8 @@ We will use cURL to make these requests, so open up another terminal window and
221
224
 
222
225
  First of all we need to create a device. To do so type the following in the new window:
223
226
 
224
- ```
225
- $ curl -X POST -d name=testdevice -d note=testnote -d type=raspberry http://localhost:1337/example/device
227
+ ```sh
228
+ curl -X POST -d name=testdevice -d note=testnote -d type=raspberry http://localhost:1337/example/device
226
229
  ```
227
230
 
228
231
  If the creation succeeds the server will respond with an object representing the new entity, in this case it will look something like this:
@@ -235,14 +238,14 @@ Aside from `__metadata` which is used internally, the properties of this object
235
238
 
236
239
  If we ask the server for a list of devices we will see the one we just created:
237
240
 
238
- ```
239
- $ curl -X GET http://localhost:1337/example/device
241
+ ```sh
242
+ curl -X GET http://localhost:1337/example/device
240
243
  ```
241
244
 
242
245
  The server will respond with an array containing all the devices, if we want to access a specific one, it is sufficient to add the id at the end of the URL we pass.
243
246
 
244
- ```
245
- $ curl -X GET 'http://localhost:1337/example/device(1)'
247
+ ```sh
248
+ curl -X GET 'http://localhost:1337/example/device(1)'
246
249
  ```
247
250
 
248
251
  The above cURL request will return the single entity with `id=1`.
@@ -250,8 +253,8 @@ The above cURL request will return the single entity with `id=1`.
250
253
  To modify the device we just created: the OData specification tells us that to do so we can make a `PUT` request to the endpoint that represents the entity.
251
254
  Lets try this:
252
255
 
253
- ```
254
- $ curl -X PUT -d name=testdevice -d note=updatednote 'http://localhost:1337/example/device(1)'
256
+ ```sh
257
+ curl -X PUT -d name=testdevice -d note=updatednote 'http://localhost:1337/example/device(1)'
255
258
 
256
259
  ***
257
260
  Internal Server Error
@@ -261,8 +264,8 @@ What went wrong here? Pine.js is simply preventing us from violating the constra
261
264
 
262
265
  To correctly modify the device we can try:
263
266
 
264
- ```
265
- $ curl -X PUT -d name=testdevice -d note=updatednote -d type=raspberry 'http://localhost:1337/example/device(1)'
267
+ ```sh
268
+ curl -X PUT -d name=testdevice -d note=updatednote -d type=raspberry 'http://localhost:1337/example/device(1)'
266
269
  ```
267
270
 
268
271
  You can now try to delete this entity to restore the database to it’s initial state. Recall from the OData specification that this can be done by performing a DELETE request at the endpoint represented by the entity we intend to delete.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balena/pinejs",
3
- "version": "14.51.1",
3
+ "version": "14.51.2",
4
4
  "main": "out/server-glue/module",
5
5
  "repository": "git@github.com:balena-io/pinejs.git",
6
6
  "license": "Apache-2.0",
@@ -141,6 +141,6 @@
141
141
  "recursive": true
142
142
  },
143
143
  "versionist": {
144
- "publishedAt": "2022-11-01T06:47:05.037Z"
144
+ "publishedAt": "2022-11-02T00:51:07.406Z"
145
145
  }
146
146
  }