plainscript-lang 1.0.2-rfc → 1.0.3-beta
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/README.md +194 -736
- package/compiler/cli.js +13 -17
- package/compiler/generator.js +93 -21
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +98 -536
- package/docs/PLAINSCRIPT-SPEC.md +308 -557
- package/docs/index.html +101 -599
- package/docs/website/script.js +59 -1029
- package/docs/website/style.css +74 -656
- package/examples/ai-providers.pln +7 -0
- package/examples/arrays.pln +4 -12
- package/examples/async-errors.pln +18 -0
- package/examples/auth-api.pln +3 -50
- package/examples/auth-sessions.pln +32 -0
- package/examples/basics.pln +14 -0
- package/examples/bots.pln +13 -0
- package/examples/cache-and-jobs.pln +6 -28
- package/examples/cache-schedule.pln +22 -0
- package/examples/collections.pln +15 -0
- package/examples/concurrency.pln +12 -43
- package/examples/conditions.pln +22 -0
- package/examples/database.pln +6 -39
- package/examples/day2.pln +6 -6
- package/examples/day3.pln +4 -10
- package/examples/deployment.pln +3 -9
- package/examples/email-send.pln +3 -22
- package/examples/error-handling.pln +6 -54
- package/examples/expressions.pln +7 -40
- package/examples/file-uploads.pln +5 -34
- package/examples/files-and-config.pln +5 -46
- package/examples/files.pln +12 -0
- package/examples/football-backend/app.pln +21 -20
- package/examples/functions.pln +17 -0
- package/examples/hello.pln +2 -3
- package/examples/http-client.pln +3 -44
- package/examples/http.pln +11 -0
- package/examples/id-verification/app.pln +4 -3
- package/examples/id-verification/make-sample-id.js +29 -42
- package/examples/json.pln +11 -0
- package/examples/loops.pln +13 -11
- package/examples/modules/app.pln +3 -16
- package/examples/modules/main.pln +4 -0
- package/examples/modules/math.pln +5 -16
- package/examples/objects.pln +3 -11
- package/examples/ocr.pln +22 -0
- package/examples/packages.pln +6 -0
- package/examples/record-kinds.pln +6 -42
- package/examples/records.pln +15 -0
- package/examples/rest-api-fetch.pln +6 -90
- package/examples/rest-api.pln +5 -65
- package/examples/scheduled-tasks.pln +4 -23
- package/examples/search-and-filter.pln +4 -34
- package/examples/server.pln +5 -24
- package/examples/sessions-and-cookies.pln +4 -50
- package/examples/sqlite.pln +23 -0
- package/examples/start.pln +2 -2
- package/examples/stdlib.pln +4 -41
- package/examples/telegram-ai-bot.pln +19 -0
- package/examples/telegram-bot.pln +4 -40
- package/examples/testing.pln +13 -0
- package/examples/web-api.pln +27 -0
- package/examples/web-app.pln +4 -16
- package/examples/websocket-server.pln +5 -26
- package/examples/websocket.pln +13 -0
- package/examples/whatsapp-bot/pairing.pln +4 -5
- package/examples/whatsapp-bot/qr.pln +7 -3
- package/package.json +2 -2
|
@@ -1,29 +1,31 @@
|
|
|
1
|
+
// PlainScript 1.0.3-beta: a complete authenticated SQLite API.
|
|
2
|
+
|
|
1
3
|
web app
|
|
2
|
-
database ":memory:"
|
|
4
|
+
database ":memory:" using "wasm"
|
|
3
5
|
enable sessions "touchline-session-secret"
|
|
4
6
|
remember coachHash as hashPassword("touchline")
|
|
5
7
|
|
|
6
8
|
execute
|
|
7
|
-
|
|
8
|
-
id
|
|
9
|
-
name
|
|
10
|
-
played
|
|
11
|
-
won
|
|
12
|
-
drawn
|
|
13
|
-
lost
|
|
9
|
+
CREATE TABLE teams (
|
|
10
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
11
|
+
name TEXT NOT NULL,
|
|
12
|
+
played INTEGER DEFAULT 0,
|
|
13
|
+
won INTEGER DEFAULT 0,
|
|
14
|
+
drawn INTEGER DEFAULT 0,
|
|
15
|
+
lost INTEGER DEFAULT 0
|
|
14
16
|
)
|
|
15
17
|
done
|
|
16
18
|
|
|
17
19
|
insert
|
|
18
|
-
|
|
19
|
-
(
|
|
20
|
-
(
|
|
21
|
-
(
|
|
20
|
+
INSERT INTO teams (name, played, won, drawn, lost) VALUES
|
|
21
|
+
("Thunder FC", 3, 2, 1, 0),
|
|
22
|
+
("Harbor City", 3, 1, 1, 1),
|
|
23
|
+
("Old Dock", 3, 0, 2, 1)
|
|
22
24
|
done
|
|
23
25
|
|
|
24
26
|
route post "/login"
|
|
25
|
-
remember
|
|
26
|
-
if
|
|
27
|
+
remember valid as checkPassword(password of body of request, coachHash)
|
|
28
|
+
if valid is true
|
|
27
29
|
user of session of request becomes username of body of request
|
|
28
30
|
reply json
|
|
29
31
|
token is createToken(username of body of request, "touchline-secret")
|
|
@@ -47,7 +49,7 @@ require api key from "coach-key-42"
|
|
|
47
49
|
|
|
48
50
|
route get "/teams"
|
|
49
51
|
remember rows as query
|
|
50
|
-
|
|
52
|
+
SELECT id, name, played, won, drawn, lost FROM teams ORDER BY name
|
|
51
53
|
done
|
|
52
54
|
reply json
|
|
53
55
|
teams is rows
|
|
@@ -56,14 +58,13 @@ done
|
|
|
56
58
|
|
|
57
59
|
route post "/teams"
|
|
58
60
|
remember missing as validate(body of request, list with "name")
|
|
59
|
-
|
|
60
|
-
if problems more than 0
|
|
61
|
+
if length(missing) more than 0
|
|
61
62
|
status 400
|
|
62
63
|
reply missing
|
|
63
64
|
otherwise
|
|
64
65
|
remember teamName as name of body of request
|
|
65
66
|
insert
|
|
66
|
-
|
|
67
|
+
INSERT INTO teams (name, played, won, drawn, lost) VALUES ({teamName}, 0, 0, 0, 0)
|
|
67
68
|
done
|
|
68
69
|
reply json
|
|
69
70
|
added is teamName
|
|
@@ -73,7 +74,7 @@ done
|
|
|
73
74
|
|
|
74
75
|
route get "/standings"
|
|
75
76
|
remember rows as query
|
|
76
|
-
|
|
77
|
+
SELECT name, won, drawn, lost FROM teams ORDER BY won DESC, name
|
|
77
78
|
done
|
|
78
79
|
reply json
|
|
79
80
|
standings is rows
|
|
@@ -87,4 +88,4 @@ when nothing matches
|
|
|
87
88
|
done
|
|
88
89
|
done
|
|
89
90
|
|
|
90
|
-
start 0
|
|
91
|
+
start 0
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// PlainScript 1.0.3-beta: functions, defaults, and returns.
|
|
2
|
+
|
|
3
|
+
make greet(name)
|
|
4
|
+
give `Hello, ${name}!`
|
|
5
|
+
done
|
|
6
|
+
|
|
7
|
+
make add(a, b)
|
|
8
|
+
give a + b
|
|
9
|
+
done
|
|
10
|
+
|
|
11
|
+
make label(name as "guest")
|
|
12
|
+
give `User: ${name}`
|
|
13
|
+
done
|
|
14
|
+
|
|
15
|
+
show greet("Ada")
|
|
16
|
+
show add(2, 3)
|
|
17
|
+
show label()
|
package/examples/hello.pln
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
show name
|
|
1
|
+
// PlainScript 1.0.3-beta: hello world.
|
|
2
|
+
show "Hello, PlainScript!"
|
package/examples/http-client.pln
CHANGED
|
@@ -1,44 +1,3 @@
|
|
|
1
|
-
// PlainScript
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
// Uses the public JSONPlaceholder API. Every call returns a record with
|
|
6
|
-
// ok / status / headers / data; JSON bodies are parsed automatically.
|
|
7
|
-
|
|
8
|
-
// GET with an explicit timeout
|
|
9
|
-
remember users as get "https://jsonplaceholder.typicode.com/users" timeout 8000
|
|
10
|
-
show "GET users -> " + text(status of users) + ", count " + text(length(data of users))
|
|
11
|
-
|
|
12
|
-
// POST an inline object, sent as JSON
|
|
13
|
-
remember created as post "https://jsonplaceholder.typicode.com/posts" with record with
|
|
14
|
-
title "Hello from PlainScript" and
|
|
15
|
-
userId 1
|
|
16
|
-
done
|
|
17
|
-
show "POST -> status " + text(status of created)
|
|
18
|
-
if ok of created is true
|
|
19
|
-
show "new post id " + text(id of data of created)
|
|
20
|
-
done
|
|
21
|
-
|
|
22
|
-
// PUT replaces the whole resource
|
|
23
|
-
remember replaced as put "https://jsonplaceholder.typicode.com/posts/1" with record with
|
|
24
|
-
title "Updated" and
|
|
25
|
-
body "new body" and
|
|
26
|
-
userId 1
|
|
27
|
-
done
|
|
28
|
-
show "PUT -> status " + text(status of replaced)
|
|
29
|
-
|
|
30
|
-
// PATCH merges into the resource
|
|
31
|
-
remember patched as patch "https://jsonplaceholder.typicode.com/posts/1" with record with
|
|
32
|
-
title "Patched title"
|
|
33
|
-
done
|
|
34
|
-
show "PATCH -> status " + text(status of patched)
|
|
35
|
-
|
|
36
|
-
// DELETE
|
|
37
|
-
remember removed as delete "https://jsonplaceholder.typicode.com/posts/1"
|
|
38
|
-
show "DELETE -> ok " + text(ok of removed)
|
|
39
|
-
|
|
40
|
-
// Custom headers and error surfacing
|
|
41
|
-
remember guarded as get "https://api.example.com/private" headers record with
|
|
42
|
-
Authorization "Bearer test"
|
|
43
|
-
done timeout 3000
|
|
44
|
-
show "guard called? " + text(ok of guarded) + " (status " + text(status of guarded) + ")"
|
|
1
|
+
// PlainScript 1.0.3-beta: HTTP client request.
|
|
2
|
+
remember response as get "https://example.com" timeout 5000
|
|
3
|
+
show response.status
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// PlainScript 1.0.3-beta: HTTP client requests.
|
|
2
|
+
|
|
3
|
+
remember response as get "https://example.com/api/items" timeout 5000
|
|
4
|
+
if response.ok is true
|
|
5
|
+
show response.data
|
|
6
|
+
otherwise
|
|
7
|
+
show response.status
|
|
8
|
+
done
|
|
9
|
+
|
|
10
|
+
remember created as post "https://example.com/api/items" with {name: "Ada"} headers {contentType: "application/json"}
|
|
11
|
+
show created.status
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
// PlainScript 1.0.3-beta: upload and OCR verification service.
|
|
2
|
+
|
|
1
3
|
web app
|
|
2
4
|
accept uploads limit "5 MB" allow list with "image/png", "image/jpeg" folder "uploads"
|
|
3
5
|
|
|
4
6
|
route post "/verify"
|
|
5
7
|
remember found as uploads("id")
|
|
6
|
-
|
|
7
|
-
if count is 0
|
|
8
|
+
if length(found) is 0
|
|
8
9
|
status 400
|
|
9
10
|
reply json
|
|
10
11
|
error is "Attach the ID image in the id field"
|
|
@@ -26,4 +27,4 @@ route post "/verify"
|
|
|
26
27
|
done
|
|
27
28
|
done
|
|
28
29
|
|
|
29
|
-
start 0
|
|
30
|
+
start 0
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// Encodes a name as crisp black-on-white pixel text inside a valid PNG
|
|
5
|
-
// (hand-rolled encoder: zlib deflate + CRC32, no external packages).
|
|
6
|
-
//
|
|
7
|
-
// Usage:
|
|
8
|
-
// node make-sample-id.js writes sample-id.png ("ADA LOVELACE")
|
|
9
|
-
// node make-sample-id.js out.png "IDA CARD"
|
|
10
|
-
//
|
|
11
|
-
// As a module: const { createIdPng } = require('./make-sample-id')
|
|
2
|
+
// Dependency-free PNG generator used by the acceptance test.
|
|
12
3
|
|
|
13
4
|
'use strict';
|
|
5
|
+
|
|
14
6
|
const fs = require('fs');
|
|
15
7
|
const path = require('path');
|
|
16
8
|
const zlib = require('zlib');
|
|
17
9
|
|
|
18
|
-
// 5x7 pixel font. Each glyph is 7 rows; each row is a 5-bit number
|
|
19
|
-
// (bit 4 = leftmost column). Only the characters this sample needs.
|
|
20
10
|
const FONT = {
|
|
21
11
|
A: [14, 17, 17, 31, 17, 17, 17],
|
|
22
12
|
C: [14, 17, 16, 16, 16, 17, 14],
|
|
@@ -33,7 +23,7 @@ const FONT = {
|
|
|
33
23
|
|
|
34
24
|
const WIDTH = 480;
|
|
35
25
|
const HEIGHT = 160;
|
|
36
|
-
const SCALE = 6;
|
|
26
|
+
const SCALE = 6;
|
|
37
27
|
const MARGIN_X = 24;
|
|
38
28
|
const LINE_HEIGHT = 60;
|
|
39
29
|
|
|
@@ -41,7 +31,10 @@ function drawText(pixels, text, x0, y0) {
|
|
|
41
31
|
let x = x0;
|
|
42
32
|
for (const ch of text.toUpperCase()) {
|
|
43
33
|
const glyph = FONT[ch];
|
|
44
|
-
if (!glyph) {
|
|
34
|
+
if (!glyph) {
|
|
35
|
+
x += 6 * SCALE;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
45
38
|
for (let row = 0; row < 7; row++) {
|
|
46
39
|
for (let col = 0; col < 5; col++) {
|
|
47
40
|
if ((glyph[row] >> (4 - col)) & 1) {
|
|
@@ -50,19 +43,19 @@ function drawText(pixels, text, x0, y0) {
|
|
|
50
43
|
const px = x + col * SCALE + dx;
|
|
51
44
|
const py = y0 + row * SCALE + dy;
|
|
52
45
|
if (px >= 0 && px < WIDTH && py >= 0 && py < HEIGHT) {
|
|
53
|
-
const
|
|
54
|
-
pixels[
|
|
46
|
+
const index = (py * WIDTH + px) * 3;
|
|
47
|
+
pixels[index] = pixels[index + 1] = pixels[index + 2] = 0;
|
|
55
48
|
}
|
|
56
49
|
}
|
|
57
50
|
}
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
|
-
x += 6 * SCALE;
|
|
54
|
+
x += 6 * SCALE;
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
57
|
|
|
65
|
-
function crc32(
|
|
58
|
+
function crc32(buffer) {
|
|
66
59
|
let table = crc32.table;
|
|
67
60
|
if (!table) {
|
|
68
61
|
table = crc32.table = new Int32Array(256);
|
|
@@ -73,41 +66,35 @@ function crc32(buf) {
|
|
|
73
66
|
}
|
|
74
67
|
}
|
|
75
68
|
let crc = -1;
|
|
76
|
-
for (
|
|
69
|
+
for (const byte of buffer) crc = (crc >>> 8) ^ table[(crc ^ byte) & 0xff];
|
|
77
70
|
return (crc ^ -1) >>> 0;
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
function chunk(type, data) {
|
|
81
|
-
const
|
|
82
|
-
|
|
74
|
+
const length = Buffer.alloc(4);
|
|
75
|
+
length.writeUInt32BE(data.length);
|
|
83
76
|
const body = Buffer.concat([Buffer.from(type, 'ascii'), data]);
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
return Buffer.concat([
|
|
77
|
+
const checksum = Buffer.alloc(4);
|
|
78
|
+
checksum.writeUInt32BE(crc32(body));
|
|
79
|
+
return Buffer.concat([length, body, checksum]);
|
|
87
80
|
}
|
|
88
81
|
|
|
89
82
|
function createIdPng(lines) {
|
|
90
|
-
const pixels = Buffer.alloc(WIDTH * HEIGHT * 3, 255);
|
|
91
|
-
lines.forEach((line, index) =>
|
|
92
|
-
drawText(pixels, line, MARGIN_X, 24 + index * LINE_HEIGHT);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// PNG scanlines: one filter byte (0 = None) per row.
|
|
83
|
+
const pixels = Buffer.alloc(WIDTH * HEIGHT * 3, 255);
|
|
84
|
+
lines.forEach((line, index) => drawText(pixels, line, MARGIN_X, 24 + index * LINE_HEIGHT));
|
|
96
85
|
const raw = Buffer.alloc(HEIGHT * (WIDTH * 3 + 1));
|
|
97
86
|
for (let y = 0; y < HEIGHT; y++) {
|
|
98
87
|
raw[y * (WIDTH * 3 + 1)] = 0;
|
|
99
88
|
pixels.copy(raw, y * (WIDTH * 3 + 1) + 1, y * WIDTH * 3, (y + 1) * WIDTH * 3);
|
|
100
89
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
ihdr[9] = 2; // color type: truecolor RGB
|
|
107
|
-
|
|
90
|
+
const header = Buffer.alloc(13);
|
|
91
|
+
header.writeUInt32BE(WIDTH, 0);
|
|
92
|
+
header.writeUInt32BE(HEIGHT, 4);
|
|
93
|
+
header[8] = 8;
|
|
94
|
+
header[9] = 2;
|
|
108
95
|
return Buffer.concat([
|
|
109
96
|
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
110
|
-
chunk('IHDR',
|
|
97
|
+
chunk('IHDR', header),
|
|
111
98
|
chunk('IDAT', zlib.deflateSync(raw)),
|
|
112
99
|
chunk('IEND', Buffer.alloc(0)),
|
|
113
100
|
]);
|
|
@@ -116,8 +103,8 @@ function createIdPng(lines) {
|
|
|
116
103
|
module.exports = { createIdPng, FONT, WIDTH, HEIGHT, SCALE, MARGIN_X, LINE_HEIGHT };
|
|
117
104
|
|
|
118
105
|
if (require.main === module) {
|
|
119
|
-
const
|
|
106
|
+
const output = process.argv[2] || path.join(__dirname, 'sample-id.png');
|
|
120
107
|
const lines = process.argv.length > 3 ? process.argv.slice(3) : ['ADA LOVELACE', 'ID CARD'];
|
|
121
|
-
fs.writeFileSync(
|
|
122
|
-
console.log(`wrote ${
|
|
123
|
-
}
|
|
108
|
+
fs.writeFileSync(output, createIdPng(lines));
|
|
109
|
+
console.log(`wrote ${output}`);
|
|
110
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// PlainScript 1.0.3-beta: JSON values and transformations.
|
|
2
|
+
|
|
3
|
+
remember person as record with name "Ada" and role "engineer" done
|
|
4
|
+
|
|
5
|
+
remember encoded as jsonEncode(person)
|
|
6
|
+
remember decoded as jsonDecode(encoded)
|
|
7
|
+
show decoded.name
|
|
8
|
+
show decoded.role
|
|
9
|
+
|
|
10
|
+
remember payload as {ok: true, count: 2}
|
|
11
|
+
show jsonEncode(payload)
|
package/examples/loops.pln
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
"Haaland",
|
|
3
|
-
"Foden",
|
|
4
|
-
"Rodri"
|
|
1
|
+
// PlainScript 1.0.3-beta: collection and numeric loops.
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
show player
|
|
8
|
-
done
|
|
3
|
+
remember colors as list with "red", "green", "blue"
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
for each color in colors
|
|
6
|
+
show color
|
|
7
|
+
done
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
for index position from 0 to 2
|
|
10
|
+
show position
|
|
11
|
+
show colors at position 1
|
|
14
12
|
done
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
remember count as 0
|
|
15
|
+
while count is less than 3
|
|
16
|
+
show count
|
|
17
|
+
count becomes count + 1
|
|
18
|
+
done
|
package/examples/modules/app.pln
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
// PlainScript
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
// Files are compiled in dependency order (deepest first), so the helpers in
|
|
6
|
-
// math.pln are visible here before app.pln runs.
|
|
7
|
-
|
|
8
|
-
import "./math.pln"
|
|
9
|
-
|
|
10
|
-
show PI // 3.14
|
|
11
|
-
show double(21) // 42
|
|
12
|
-
show square(9) // 81
|
|
13
|
-
show circumference(10) // 62.8
|
|
14
|
-
|
|
15
|
-
remember radius as 2.5
|
|
16
|
-
show "circle area: " + text(square(radius) * PI)
|
|
1
|
+
// PlainScript 1.0.3-beta: module entry point.
|
|
2
|
+
import { circleArea } from "./math.pln"
|
|
3
|
+
show circleArea(2)
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
// PlainScript
|
|
1
|
+
// PlainScript 1.0.3-beta: an imported module.
|
|
2
2
|
|
|
3
|
-
remember PI as 3.
|
|
3
|
+
remember PI as 3.14159
|
|
4
4
|
|
|
5
|
-
make
|
|
6
|
-
give
|
|
5
|
+
make circleArea(radius)
|
|
6
|
+
give PI * radius * radius
|
|
7
7
|
done
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
give n * n
|
|
11
|
-
done
|
|
12
|
-
|
|
13
|
-
make circumference(radius)
|
|
14
|
-
give 2 * PI * radius
|
|
15
|
-
done
|
|
16
|
-
|
|
17
|
-
export PI
|
|
18
|
-
export double
|
|
19
|
-
export square
|
|
20
|
-
export circumference
|
|
9
|
+
export circleArea
|
package/examples/objects.pln
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
age is 17
|
|
4
|
-
country is "Nigeria"
|
|
5
|
-
done
|
|
6
|
-
|
|
1
|
+
// PlainScript 1.0.3-beta: object literals and member access.
|
|
2
|
+
remember user as {name: "Ada", active: true}
|
|
7
3
|
show user.name
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
user.age becomes 18
|
|
11
|
-
|
|
12
|
-
show user.age
|
|
4
|
+
user.active becomes false
|
package/examples/ocr.pln
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// PlainScript 1.0.3-beta: upload handling and OCR.
|
|
2
|
+
|
|
3
|
+
web app
|
|
4
|
+
accept uploads limit "5 MB" allow list with "image/png", "image/jpeg" folder "uploads"
|
|
5
|
+
|
|
6
|
+
route post "/scan"
|
|
7
|
+
remember files as uploads("document")
|
|
8
|
+
if length(files) is 0
|
|
9
|
+
status 400
|
|
10
|
+
reply json
|
|
11
|
+
error is "document is required"
|
|
12
|
+
done
|
|
13
|
+
otherwise
|
|
14
|
+
remember document as upload("document")
|
|
15
|
+
ocr path of document as text
|
|
16
|
+
reply json
|
|
17
|
+
text is text
|
|
18
|
+
done
|
|
19
|
+
done
|
|
20
|
+
done
|
|
21
|
+
|
|
22
|
+
start 0
|
|
@@ -1,43 +1,7 @@
|
|
|
1
|
-
// PlainScript
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// Defines a schema, builds instances, composes records, streams values from
|
|
6
|
-
// generators, and verifies behaviour with the built-in test runner.
|
|
7
|
-
|
|
8
|
-
define a kind called "Book" with
|
|
9
|
-
title is ""
|
|
10
|
-
pages is 0
|
|
11
|
-
rating is 0
|
|
1
|
+
// PlainScript 1.0.3-beta: record kind construction.
|
|
2
|
+
define a kind called "Player" with
|
|
3
|
+
name is ""
|
|
4
|
+
goals is 0
|
|
12
5
|
done
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
fav.rating becomes 4.5
|
|
16
|
-
|
|
17
|
-
show title of fav
|
|
18
|
-
show pages of fav
|
|
19
|
-
show rating of fav
|
|
20
|
-
|
|
21
|
-
remember extended as merge(fav, record with author "Ada" done)
|
|
22
|
-
show author of extended
|
|
23
|
-
show fieldsOf(extended)
|
|
24
|
-
|
|
25
|
-
test "book schema"
|
|
26
|
-
check title of fav equals "IOPL in Action"
|
|
27
|
-
check rating of fav equals 4.5
|
|
28
|
-
check hasField(fav, "author") equals false
|
|
29
|
-
done
|
|
30
|
-
|
|
31
|
-
test "generator"
|
|
32
|
-
remember ids as spread of range(1, 4)
|
|
33
|
-
check length(ids) equals 3
|
|
34
|
-
check sum(ids) equals 6
|
|
35
|
-
done
|
|
36
|
-
|
|
37
|
-
make makeTitles(catalog)
|
|
38
|
-
for each book in catalog
|
|
39
|
-
yield title of book
|
|
40
|
-
done
|
|
41
|
-
done
|
|
42
|
-
|
|
43
|
-
show spread of makeTitles(list with fav, extended)
|
|
6
|
+
remember player as create a Player with name "Ada" and goals 4
|
|
7
|
+
show player.name
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// PlainScript 1.0.3-beta: record kinds and record values.
|
|
2
|
+
|
|
3
|
+
define a kind called "Player" with
|
|
4
|
+
name is ""
|
|
5
|
+
goals is 0
|
|
6
|
+
done
|
|
7
|
+
|
|
8
|
+
remember player as create a Player with name "Ada" and goals 4
|
|
9
|
+
show player.name
|
|
10
|
+
if player has field "goals"
|
|
11
|
+
show "goals are present"
|
|
12
|
+
done
|
|
13
|
+
|
|
14
|
+
remember team as record with name "Harbor City" and founded 2020 done
|
|
15
|
+
show team.name
|
|
@@ -1,94 +1,10 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// A REST API that calls other APIs with the built-in HTTP client and
|
|
4
|
-
// combines the results. Everything here compiles deterministically:
|
|
5
|
-
// no rules, no AI, no hidden code generation.
|
|
6
|
-
|
|
1
|
+
// PlainScript 1.0.3-beta: fetch an upstream API from a route.
|
|
7
2
|
web app
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
route get "/health"
|
|
3
|
+
route get "/proxy"
|
|
4
|
+
remember upstream as get "https://example.com/data" timeout 5000
|
|
11
5
|
reply json
|
|
12
|
-
status is
|
|
13
|
-
|
|
6
|
+
status is upstream.status
|
|
7
|
+
data is upstream.body
|
|
14
8
|
done
|
|
15
9
|
done
|
|
16
|
-
|
|
17
|
-
// Fetch a random user from randomuser.me
|
|
18
|
-
route get "/api/random-user"
|
|
19
|
-
remember response as get "https://randomuser.me/api/"
|
|
20
|
-
if ok of response is true
|
|
21
|
-
reply data of response
|
|
22
|
-
otherwise
|
|
23
|
-
status 502
|
|
24
|
-
reply json
|
|
25
|
-
error is "Failed to fetch user"
|
|
26
|
-
done
|
|
27
|
-
done
|
|
28
|
-
done
|
|
29
|
-
|
|
30
|
-
// Fetch multiple APIs and combine the results
|
|
31
|
-
route get "/api/dashboard"
|
|
32
|
-
remember userRes as get "https://randomuser.me/api/"
|
|
33
|
-
remember jokeRes as get "https://official-joke-api.appspot.com/random_joke"
|
|
34
|
-
|
|
35
|
-
remember user as null
|
|
36
|
-
remember joke as null
|
|
37
|
-
|
|
38
|
-
if ok of userRes is true
|
|
39
|
-
user becomes first person from results of data of userRes
|
|
40
|
-
done
|
|
41
|
-
|
|
42
|
-
if ok of jokeRes is true
|
|
43
|
-
joke becomes data of jokeRes
|
|
44
|
-
done
|
|
45
|
-
|
|
46
|
-
reply json
|
|
47
|
-
user is user
|
|
48
|
-
joke is joke
|
|
49
|
-
done
|
|
50
|
-
done
|
|
51
|
-
|
|
52
|
-
// Search with query parameters
|
|
53
|
-
route get "/api/search"
|
|
54
|
-
remember q as query("q")
|
|
55
|
-
remember limit as query("limit")
|
|
56
|
-
remember results as list
|
|
57
|
-
reply json
|
|
58
|
-
q is q
|
|
59
|
-
limit is limit
|
|
60
|
-
results is results
|
|
61
|
-
done
|
|
62
|
-
done
|
|
63
|
-
|
|
64
|
-
// Create an item
|
|
65
|
-
route post "/api/items"
|
|
66
|
-
reply json
|
|
67
|
-
created is true
|
|
68
|
-
item is body of request
|
|
69
|
-
done
|
|
70
|
-
done
|
|
71
|
-
|
|
72
|
-
// Update an item
|
|
73
|
-
route put "/api/items/:id"
|
|
74
|
-
remember id as param("id")
|
|
75
|
-
reply json
|
|
76
|
-
updated is id
|
|
77
|
-
item is body of request
|
|
78
|
-
done
|
|
79
|
-
done
|
|
80
|
-
|
|
81
|
-
// Delete an item
|
|
82
|
-
route delete "/api/items/:id"
|
|
83
|
-
remember id as param("id")
|
|
84
|
-
reply json
|
|
85
|
-
deleted is id
|
|
86
|
-
done
|
|
87
|
-
done
|
|
88
|
-
|
|
89
|
-
when nothing matches
|
|
90
|
-
status 404
|
|
91
|
-
reply "no such road"
|
|
92
|
-
done
|
|
93
|
-
|
|
94
|
-
start 3000
|
|
10
|
+
start 3000
|