plainscript-lang 1.0.1 → 1.0.2-latest
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 -729
- package/compiler/bundler.js +2 -2
- package/compiler/cli.js +69 -73
- package/compiler/dependency-detector.js +5 -0
- package/compiler/formatter.js +1 -1
- package/compiler/generator.js +931 -89
- package/compiler/lexer.js +129 -53
- package/compiler/parser.js +995 -152
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +98 -435
- package/docs/PLAINSCRIPT-SPEC.md +335 -0
- package/docs/index.html +101 -608
- package/docs/website/script.js +59 -943
- package/docs/website/style.css +74 -656
- package/examples/ai-providers.pln +7 -0
- package/examples/arrays.pln +4 -0
- package/examples/async-errors.pln +18 -0
- package/examples/auth-api.pln +9 -0
- 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 +7 -0
- package/examples/cache-schedule.pln +22 -0
- package/examples/collections.pln +15 -0
- package/examples/concurrency.pln +18 -0
- package/examples/conditions.pln +22 -0
- package/examples/database.pln +8 -0
- package/examples/day2.pln +7 -0
- package/examples/day3.pln +5 -0
- package/examples/deployment.pln +6 -0
- package/examples/email-send.pln +3 -0
- package/examples/error-handling.pln +7 -0
- package/examples/expressions.pln +7 -0
- package/examples/file-uploads.pln +10 -0
- package/examples/files-and-config.pln +6 -0
- package/examples/files.pln +12 -0
- package/examples/football-backend/{app.ps → app.pln} +22 -21
- package/examples/functions.pln +17 -0
- package/examples/hello.pln +2 -0
- package/examples/http-client.pln +3 -0
- package/examples/http.pln +11 -0
- package/examples/id-verification/{app.ps → app.pln} +5 -4
- package/examples/id-verification/make-sample-id.js +29 -42
- package/examples/json.pln +11 -0
- package/examples/loops.pln +18 -0
- package/examples/modules/app.pln +3 -0
- package/examples/modules/main.pln +4 -0
- package/examples/modules/math.pln +9 -0
- package/examples/mongo.pln +33 -0
- package/examples/objects.pln +4 -0
- package/examples/ocr.pln +22 -0
- package/examples/packages.pln +6 -0
- package/examples/record-kinds.pln +7 -0
- package/examples/records.pln +15 -0
- package/examples/rest-api-fetch.pln +10 -0
- package/examples/rest-api.pln +8 -0
- package/examples/scheduled-tasks.pln +4 -0
- package/examples/search-and-filter.pln +4 -0
- package/examples/server.pln +6 -0
- package/examples/sessions-and-cookies.pln +8 -0
- package/examples/sqlite.pln +23 -0
- package/examples/start.pln +2 -0
- package/examples/stdlib.pln +4 -0
- package/examples/telegram-ai-bot.pln +19 -0
- package/examples/telegram-bot.pln +6 -0
- package/examples/testing.pln +13 -0
- package/examples/web-api.pln +27 -0
- package/examples/web-app.pln +8 -0
- package/examples/websocket-server.pln +6 -0
- package/examples/websocket.pln +13 -0
- package/examples/whatsapp-bot/{pairing.ps → pairing.pln} +4 -5
- package/examples/whatsapp-bot/qr.pln +12 -0
- package/package.json +3 -2
- package/docs/PLINJS_SPEC.md +0 -1151
- package/examples/arrays.ps +0 -13
- package/examples/auth-api.ps +0 -56
- package/examples/cache-and-jobs.ps +0 -29
- package/examples/concurrency.ps +0 -49
- package/examples/database.ps +0 -41
- package/examples/day2.ps +0 -7
- package/examples/day3.ps +0 -11
- package/examples/deployment.ps +0 -12
- package/examples/email-send.ps +0 -22
- package/examples/error-handling.ps +0 -54
- package/examples/expressions.ps +0 -40
- package/examples/file-uploads.ps +0 -39
- package/examples/files-and-config.ps +0 -47
- package/examples/hello.ps +0 -3
- package/examples/http-client.ps +0 -44
- package/examples/loops.ps +0 -17
- package/examples/modules/app.ps +0 -16
- package/examples/modules/math.ps +0 -20
- package/examples/objects.ps +0 -12
- package/examples/record-kinds.ps +0 -43
- package/examples/rest-api-fetch.ps +0 -94
- package/examples/rest-api.ps +0 -68
- package/examples/scheduled-tasks.ps +0 -23
- package/examples/search-and-filter.ps +0 -34
- package/examples/server.ps +0 -25
- package/examples/sessions-and-cookies.ps +0 -54
- package/examples/start.ps +0 -2
- package/examples/stdlib.ps +0 -41
- package/examples/telegram-bot.ps +0 -42
- package/examples/web-app.ps +0 -20
- package/examples/websocket-server.ps +0 -27
- package/examples/whatsapp-bot/qr.ps +0 -8
package/examples/arrays.ps
DELETED
package/examples/auth-api.ps
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.0.1 — API key protection, rate limits and tokens
|
|
2
|
-
//
|
|
3
|
-
// Run with: API_KEY=my-secret plainscript run examples/auth-api.ps
|
|
4
|
-
// Then try:
|
|
5
|
-
// curl -H "x-api-key: my-secret" http://localhost:3000/status
|
|
6
|
-
// curl http://localhost:3000/status # 401 without the key
|
|
7
|
-
//
|
|
8
|
-
// Routes registered after "require api key" are guarded; the health route is
|
|
9
|
-
// registered first so uptime checks keep working.
|
|
10
|
-
|
|
11
|
-
web app
|
|
12
|
-
|
|
13
|
-
route get "/health"
|
|
14
|
-
reply "alive"
|
|
15
|
-
done
|
|
16
|
-
|
|
17
|
-
require api key from env("API_KEY")
|
|
18
|
-
limit requests to 60 per minute
|
|
19
|
-
|
|
20
|
-
remember secret as env("TOKEN_SECRET")
|
|
21
|
-
|
|
22
|
-
route get "/status"
|
|
23
|
-
reply json
|
|
24
|
-
status is "ok"
|
|
25
|
-
version is "1.0.1"
|
|
26
|
-
done
|
|
27
|
-
done
|
|
28
|
-
|
|
29
|
-
route post "/token"
|
|
30
|
-
remember payload as
|
|
31
|
-
sub is "user-1"
|
|
32
|
-
role is "admin"
|
|
33
|
-
done
|
|
34
|
-
remember issued as createToken(payload, secret, 1800)
|
|
35
|
-
reply json
|
|
36
|
-
token is issued
|
|
37
|
-
done
|
|
38
|
-
done
|
|
39
|
-
|
|
40
|
-
route get "/verify"
|
|
41
|
-
remember supplied as header("x-token")
|
|
42
|
-
remember claims as readToken(supplied, secret)
|
|
43
|
-
if claims is empty
|
|
44
|
-
status 401
|
|
45
|
-
reply json
|
|
46
|
-
error is "invalid or expired token"
|
|
47
|
-
done
|
|
48
|
-
otherwise
|
|
49
|
-
reply json
|
|
50
|
-
sub is sub of claims
|
|
51
|
-
role is role of claims
|
|
52
|
-
done
|
|
53
|
-
done
|
|
54
|
-
done
|
|
55
|
-
|
|
56
|
-
start 3000
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// PlainScript v2.1 — Cache, background jobs and cron working together
|
|
2
|
-
//
|
|
3
|
-
// Run with: REDIS_URL=redis://localhost:6379 plainscript run examples/cache-and-jobs.ps
|
|
4
|
-
//
|
|
5
|
-
// Heavy work is pushed off the request path with "run background", shared
|
|
6
|
-
// state lives in Redis, and a cron job refreshes it every minute.
|
|
7
|
-
|
|
8
|
-
cache env("REDIS_URL")
|
|
9
|
-
|
|
10
|
-
make generateReport()
|
|
11
|
-
show "Generating report…"
|
|
12
|
-
give "report-data-" + date()
|
|
13
|
-
done
|
|
14
|
-
|
|
15
|
-
// Refresh the cached report every minute
|
|
16
|
-
schedule "* * * * *"
|
|
17
|
-
run background cacheSet("report", generateReport())
|
|
18
|
-
done
|
|
19
|
-
|
|
20
|
-
remember report as cacheGet("report")
|
|
21
|
-
if report is empty
|
|
22
|
-
show "No report yet — generating one now"
|
|
23
|
-
remember fresh as generateReport()
|
|
24
|
-
cacheSet("report", fresh, 3600)
|
|
25
|
-
otherwise
|
|
26
|
-
show "Cached report: " + report
|
|
27
|
-
done
|
|
28
|
-
|
|
29
|
-
show "Cache demo running"
|
package/examples/concurrency.ps
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.0.1 — Concurrency: combinators, timeouts and workers
|
|
2
|
-
//
|
|
3
|
-
// Run with: plainscript run examples/concurrency.ps
|
|
4
|
-
//
|
|
5
|
-
// all / any / settled run several promises in parallel; withTimeout bounds
|
|
6
|
-
// how long one may take; run background fires work without blocking.
|
|
7
|
-
|
|
8
|
-
make fetchUsers()
|
|
9
|
-
sleep(300)
|
|
10
|
-
give { source: "users", count: 42 }
|
|
11
|
-
done
|
|
12
|
-
|
|
13
|
-
make fetchOrders()
|
|
14
|
-
sleep(150)
|
|
15
|
-
give { source: "orders", count: 17 }
|
|
16
|
-
done
|
|
17
|
-
|
|
18
|
-
make flakyFetch()
|
|
19
|
-
remember data as jsonDecode("not json")
|
|
20
|
-
give data
|
|
21
|
-
done
|
|
22
|
-
|
|
23
|
-
// Every item must resolve — an array of results
|
|
24
|
-
remember dashboard as all of [fetchUsers(), fetchOrders()]
|
|
25
|
-
for each panel in dashboard
|
|
26
|
-
show source of panel + ": " + text(count of panel)
|
|
27
|
-
done
|
|
28
|
-
|
|
29
|
-
// First to settle wins
|
|
30
|
-
remember first as any of [fetchUsers(), fetchOrders()]
|
|
31
|
-
show "first: " + source of first
|
|
32
|
-
|
|
33
|
-
// Never throws; each outcome is a record with a status
|
|
34
|
-
remember results as settled of [fetchUsers(), flakyFetch()]
|
|
35
|
-
for each outcome in results
|
|
36
|
-
if status of outcome is "fulfilled"
|
|
37
|
-
show "ok: " + text(value of outcome)
|
|
38
|
-
otherwise
|
|
39
|
-
show "failed: " + message of reason of outcome
|
|
40
|
-
done
|
|
41
|
-
done
|
|
42
|
-
|
|
43
|
-
// Bound a slow call
|
|
44
|
-
remember bounded as withTimeout(fetchUsers(), 2000)
|
|
45
|
-
show "bounded result ready"
|
|
46
|
-
|
|
47
|
-
// Fire-and-forget background work
|
|
48
|
-
run background fetchUsers()
|
|
49
|
-
show "background job launched — this line prints immediately"
|
package/examples/database.ps
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// PlainScript v2.1 — Databases: SQLite, parameters and transactions
|
|
2
|
-
//
|
|
3
|
-
// Run with: plainscript run examples/database.ps
|
|
4
|
-
//
|
|
5
|
-
// SQL placeholders are written {likeThis} and bind to PlainScript variables of
|
|
6
|
-
// the same name. A transaction block runs all enclosed writes atomically.
|
|
7
|
-
|
|
8
|
-
database "plainscript-demo.db"
|
|
9
|
-
|
|
10
|
-
execute
|
|
11
|
-
CREATE TABLE IF NOT EXISTS users (
|
|
12
|
-
name TEXT,
|
|
13
|
-
age NUMBER
|
|
14
|
-
)
|
|
15
|
-
done
|
|
16
|
-
|
|
17
|
-
remember who as "ana"
|
|
18
|
-
insert
|
|
19
|
-
INSERT INTO users (name, age) VALUES ({who}, 30)
|
|
20
|
-
done
|
|
21
|
-
|
|
22
|
-
// Several writes that must succeed or fail together
|
|
23
|
-
transaction
|
|
24
|
-
insert
|
|
25
|
-
INSERT INTO users (name, age) VALUES ('bo', 31)
|
|
26
|
-
done
|
|
27
|
-
insert
|
|
28
|
-
INSERT INTO users (name, age) VALUES ('cy', 40)
|
|
29
|
-
done
|
|
30
|
-
done
|
|
31
|
-
|
|
32
|
-
remember minAge as 30
|
|
33
|
-
remember adults as query
|
|
34
|
-
SELECT name FROM users WHERE age >= {minAge} ORDER BY name
|
|
35
|
-
done
|
|
36
|
-
|
|
37
|
-
for each row in adults
|
|
38
|
-
show row.name
|
|
39
|
-
done
|
|
40
|
-
|
|
41
|
-
show "Database demo complete"
|
package/examples/day2.ps
DELETED
package/examples/day3.ps
DELETED
package/examples/deployment.ps
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.0.1 — runtime dependency and deployment example
|
|
2
|
-
//
|
|
3
|
-
// `plainscript build` and `plainscript run` detect express from `web app` and install it
|
|
4
|
-
// when it is missing. `plainscript start` builds src/app.ps by default.
|
|
5
|
-
|
|
6
|
-
web app
|
|
7
|
-
|
|
8
|
-
route "/"
|
|
9
|
-
reply "PlainScript is ready to deploy!"
|
|
10
|
-
done
|
|
11
|
-
|
|
12
|
-
start 3000
|
package/examples/email-send.ps
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// PlainScript v2.1 — Sending email
|
|
2
|
-
//
|
|
3
|
-
// Run with: MAIL_PASS=secret plainscript run examples/email-send.ps
|
|
4
|
-
//
|
|
5
|
-
// Configure the outgoing transport once, then send as many mails as you
|
|
6
|
-
// like. Credentials come from the environment — never hardcode them.
|
|
7
|
-
|
|
8
|
-
mail transport
|
|
9
|
-
host is "smtp.gmail.com"
|
|
10
|
-
port is 587
|
|
11
|
-
user is env("EMAIL_USER")
|
|
12
|
-
pass is env("EMAIL_PASS")
|
|
13
|
-
done
|
|
14
|
-
|
|
15
|
-
send mail
|
|
16
|
-
from is "hello@plainscript.dev"
|
|
17
|
-
to is "you@example.com"
|
|
18
|
-
subject is "Hello from PlainScript"
|
|
19
|
-
text is "This email was sent from a PlainScript program."
|
|
20
|
-
done
|
|
21
|
-
|
|
22
|
-
show "Email sent successfully"
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.0.1 — Robust error handling
|
|
2
|
-
//
|
|
3
|
-
// Run with: plainscript run examples/error-handling.ps
|
|
4
|
-
//
|
|
5
|
-
// Shows deterministic recovery: typed "recover" blocks, silent swallowing,
|
|
6
|
-
// and automatic retries with backoff for flaky operations.
|
|
7
|
-
|
|
8
|
-
make parseSettings(raw)
|
|
9
|
-
remember settings as jsonDecode(raw)
|
|
10
|
-
if settings is empty
|
|
11
|
-
give { theme: "light" }
|
|
12
|
-
otherwise
|
|
13
|
-
give settings
|
|
14
|
-
done
|
|
15
|
-
done
|
|
16
|
-
|
|
17
|
-
// Recover with the thrown value
|
|
18
|
-
try
|
|
19
|
-
remember settings as parseSettings("{ bad json")
|
|
20
|
-
show theme of settings
|
|
21
|
-
recover as err
|
|
22
|
-
show "falling back: " + message of err
|
|
23
|
-
remember settings as { theme: "dark" }
|
|
24
|
-
show theme of settings
|
|
25
|
-
done
|
|
26
|
-
|
|
27
|
-
// Multiple typed recover clauses win on error name
|
|
28
|
-
try
|
|
29
|
-
remember parsed as jsonDecode("also not json")
|
|
30
|
-
recover when err catches "SyntaxError"
|
|
31
|
-
show "JSON parse error caught: " + message of err
|
|
32
|
-
recover as err
|
|
33
|
-
show "some other error: " + message of err
|
|
34
|
-
done
|
|
35
|
-
|
|
36
|
-
// Swallow failures silently when no recover is present
|
|
37
|
-
try
|
|
38
|
-
remember probe as read("does-not-exist.txt")
|
|
39
|
-
done
|
|
40
|
-
show "survived the failed read"
|
|
41
|
-
|
|
42
|
-
// Automatic retry with a delay
|
|
43
|
-
remember logs as []
|
|
44
|
-
make fetchStatus()
|
|
45
|
-
add("trying…" to logs)
|
|
46
|
-
give read("status.db.json")
|
|
47
|
-
done
|
|
48
|
-
|
|
49
|
-
retry 3 times every 1 second
|
|
50
|
-
remember body as fetchStatus()
|
|
51
|
-
show body
|
|
52
|
-
done
|
|
53
|
-
|
|
54
|
-
show length(logs)
|
package/examples/expressions.ps
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.1 — PlainScript Expressions Examples
|
|
2
|
-
|
|
3
|
-
remember players as ["Haaland", "Foden", "Rodri"]
|
|
4
|
-
|
|
5
|
-
// Items
|
|
6
|
-
show first player from players
|
|
7
|
-
show last player from players
|
|
8
|
-
show player two from players
|
|
9
|
-
|
|
10
|
-
first player from players becomes "Kane"
|
|
11
|
-
show first player from players
|
|
12
|
-
|
|
13
|
-
// Collections
|
|
14
|
-
show players length
|
|
15
|
-
|
|
16
|
-
add("Palmer" to players)
|
|
17
|
-
show players length
|
|
18
|
-
|
|
19
|
-
remove("Rodri" from players)
|
|
20
|
-
show players length
|
|
21
|
-
|
|
22
|
-
if players contains "Foden"
|
|
23
|
-
show "Foden is in the squad"
|
|
24
|
-
done
|
|
25
|
-
|
|
26
|
-
// Properties
|
|
27
|
-
remember user as
|
|
28
|
-
name is "Ayokunle"
|
|
29
|
-
age is 17
|
|
30
|
-
done
|
|
31
|
-
|
|
32
|
-
show name of user
|
|
33
|
-
|
|
34
|
-
name of user becomes "Ayo"
|
|
35
|
-
show name of user
|
|
36
|
-
|
|
37
|
-
// Files
|
|
38
|
-
write("Hello from PlainScript Expressions" to "expressions.txt")
|
|
39
|
-
remember content as read("expressions.txt")
|
|
40
|
-
show content
|
package/examples/file-uploads.ps
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.0.1 — File uploads
|
|
2
|
-
//
|
|
3
|
-
// Run with: plainscript run examples/file-uploads.ps
|
|
4
|
-
// Then try:
|
|
5
|
-
// curl -F photo=@some-image.png http://localhost:3000/upload
|
|
6
|
-
// curl -F doc=@notes.txt http://localhost:3000/upload-many
|
|
7
|
-
//
|
|
8
|
-
// Uploaded files are kept in memory (no folder) so nothing touches the disk.
|
|
9
|
-
// A file over 5 MB is rejected with HTTP 413 and a non-image with HTTP 415.
|
|
10
|
-
|
|
11
|
-
web app
|
|
12
|
-
|
|
13
|
-
accept uploads limit "5 MB" allow ["image/png", "image/jpeg", "text/plain"]
|
|
14
|
-
|
|
15
|
-
route post "/upload"
|
|
16
|
-
remember file as upload("file")
|
|
17
|
-
if file is not empty
|
|
18
|
-
reply json
|
|
19
|
-
name is name of file
|
|
20
|
-
type is type of file
|
|
21
|
-
size is size of file
|
|
22
|
-
done
|
|
23
|
-
otherwise
|
|
24
|
-
reply json
|
|
25
|
-
error is "no file under the 'file' field"
|
|
26
|
-
done
|
|
27
|
-
done
|
|
28
|
-
done
|
|
29
|
-
|
|
30
|
-
route post "/upload-many"
|
|
31
|
-
remember files as uploads("docs")
|
|
32
|
-
gather each file in files giving name of file
|
|
33
|
-
reply json
|
|
34
|
-
received is length(files)
|
|
35
|
-
names is files
|
|
36
|
-
done
|
|
37
|
-
done
|
|
38
|
-
|
|
39
|
-
start 3000
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.0.1 — File I/O, YAML and environment configuration
|
|
2
|
-
//
|
|
3
|
-
// Run with: plainscript run examples/files-and-config.ps
|
|
4
|
-
//
|
|
5
|
-
// Writes and reads files, walks a folder, round-trips YAML and applies a
|
|
6
|
-
// .env file. Everything is deterministic and dependency-free.
|
|
7
|
-
|
|
8
|
-
makeFolder("example-output")
|
|
9
|
-
writeFile("example-output/greeting.txt", "Hello, files!")
|
|
10
|
-
writeLine("example-output/log.txt", "first line")
|
|
11
|
-
appendLine("example-output/log.txt", "second line")
|
|
12
|
-
|
|
13
|
-
show readFile("example-output/greeting.txt")
|
|
14
|
-
show readFile("example-output/log.txt")
|
|
15
|
-
show fileExists("example-output/greeting.txt")
|
|
16
|
-
show fileSize("example-output/greeting.txt")
|
|
17
|
-
show fileType("example-output") // directory
|
|
18
|
-
show lastModified("example-output/greeting.txt")
|
|
19
|
-
|
|
20
|
-
show listFolder("example-output")
|
|
21
|
-
show walkFolder("example-output")
|
|
22
|
-
|
|
23
|
-
remember settings as
|
|
24
|
-
app is "plainscript"
|
|
25
|
-
limits is { requests: 100, window: "hour" }
|
|
26
|
-
done
|
|
27
|
-
|
|
28
|
-
remember encoded as yamlEncode(settings)
|
|
29
|
-
show encoded
|
|
30
|
-
|
|
31
|
-
remember parsed as yamlDecode(encoded)
|
|
32
|
-
show app of parsed
|
|
33
|
-
remember limits as limits of parsed
|
|
34
|
-
show requests of limits
|
|
35
|
-
|
|
36
|
-
load env file ".env"
|
|
37
|
-
show env("APP_ENV")
|
|
38
|
-
|
|
39
|
-
// JSON round-trip stays convenient too
|
|
40
|
-
remember backup as jsonEncode(settings)
|
|
41
|
-
show jsonDecode(backup)
|
|
42
|
-
|
|
43
|
-
// Clean up after ourselves
|
|
44
|
-
deleteFile("example-output/greeting.txt")
|
|
45
|
-
deleteFile("example-output/log.txt")
|
|
46
|
-
deleteFolder("example-output")
|
|
47
|
-
show "cleanup done"
|
package/examples/hello.ps
DELETED
package/examples/http-client.ps
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.0.1 — HTTP client: every method, headers and timeouts
|
|
2
|
-
//
|
|
3
|
-
// Run with: plainscript run examples/http-client.ps
|
|
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 {
|
|
14
|
-
title: "Hello from PlainScript",
|
|
15
|
-
userId: 1
|
|
16
|
-
}
|
|
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 {
|
|
24
|
-
title: "Updated",
|
|
25
|
-
body: "new body",
|
|
26
|
-
userId: 1
|
|
27
|
-
}
|
|
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 {
|
|
32
|
-
title: "Patched title"
|
|
33
|
-
}
|
|
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 {
|
|
42
|
-
Authorization: "Bearer test"
|
|
43
|
-
} timeout 3000
|
|
44
|
-
show "guard called? " + text(ok of guarded) + " (status " + text(status of guarded) + ")"
|
package/examples/loops.ps
DELETED
package/examples/modules/app.ps
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.0.1 — Importing your own modules
|
|
2
|
-
//
|
|
3
|
-
// Run with: plainscript run examples/modules/app.ps
|
|
4
|
-
//
|
|
5
|
-
// Files are compiled in dependency order (deepest first), so the helpers in
|
|
6
|
-
// math.ps are visible here before app.ps runs.
|
|
7
|
-
|
|
8
|
-
import "./math.ps"
|
|
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)
|
package/examples/modules/math.ps
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.0.1 — reusable module, imported by app.ps
|
|
2
|
-
|
|
3
|
-
remember PI as 3.14
|
|
4
|
-
|
|
5
|
-
make double(n)
|
|
6
|
-
give n * 2
|
|
7
|
-
done
|
|
8
|
-
|
|
9
|
-
make square(n)
|
|
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
|
package/examples/objects.ps
DELETED
package/examples/record-kinds.ps
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// PlainScript v1.0.1 — Record kinds, generators and the test DSL
|
|
2
|
-
//
|
|
3
|
-
// Run with: plainscript run examples/record-kinds.ps
|
|
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
|
|
12
|
-
done
|
|
13
|
-
|
|
14
|
-
remember fav as create a Book with title "IOPL in Action" and pages 240
|
|
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, { author: "Ada" })
|
|
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([fav, extended])
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// REST API with upstream fetches — multi-source integration example
|
|
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
|
-
|
|
7
|
-
web app
|
|
8
|
-
|
|
9
|
-
// Health check
|
|
10
|
-
route get "/health"
|
|
11
|
-
reply json
|
|
12
|
-
status is "ok"
|
|
13
|
-
version is "0.1.7"
|
|
14
|
-
done
|
|
15
|
-
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 []
|
|
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
|