plainscript-lang 1.0.36 → 1.0.361
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 +251 -19
- package/compiler/bundler.js +4 -4
- package/compiler/cli.js +18 -18
- package/compiler/dependency-detector.js +34 -22
- package/compiler/generator.js +286 -186
- package/compiler/lexer.js +49 -39
- package/compiler/parser.js +552 -181
- package/compiler/sourcemap.js +1 -1
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +2 -2
- package/docs/FB-PROMPT.md +524 -0
- package/docs/GAME-PROMPT.md +56 -55
- package/docs/PLAINSCRIPT-SPEC.md +16 -15
- package/docs/index.html +13 -6
- package/docs/website/script.js +1 -1
- package/docs/website/style.css +3 -3
- package/examples/ai-providers.pln +1 -1
- package/examples/arrays.pln +1 -1
- package/examples/async-errors.pln +2 -1
- package/examples/auth-api.pln +1 -1
- package/examples/auth-sessions.pln +1 -1
- package/examples/basics.pln +1 -1
- package/examples/bots.pln +1 -1
- package/examples/browser-interactive/README.md +3 -3
- package/examples/browser-interactive/src/interactive.pln +1 -1
- package/examples/cache-and-jobs.pln +1 -1
- package/examples/cache-schedule.pln +1 -1
- package/examples/canvas-game/README.md +4 -4
- package/examples/canvas-game/src/game.pln +1 -1
- package/examples/collections.pln +1 -1
- package/examples/concurrency.pln +1 -1
- package/examples/conditions.pln +1 -1
- package/examples/database.pln +1 -1
- package/examples/day2.pln +1 -1
- package/examples/day3.pln +1 -1
- package/examples/deployment.pln +1 -1
- package/examples/email-send.pln +1 -1
- package/examples/error-handling.pln +3 -2
- package/examples/expressions.pln +1 -1
- package/examples/file-uploads.pln +1 -1
- package/examples/files-and-config.pln +1 -1
- package/examples/files.pln +1 -1
- package/examples/football-backend/app.pln +1 -1
- package/examples/functions.pln +1 -1
- package/examples/hello.pln +1 -1
- package/examples/http-client.pln +1 -1
- package/examples/http.pln +1 -1
- package/examples/id-verification/app.pln +1 -1
- package/examples/javascript-library/README.md +6 -6
- package/examples/javascript-library/public/index.html +1 -1
- package/examples/javascript-library/src/interop.pln +1 -1
- package/examples/json.pln +1 -1
- package/examples/loops.pln +1 -1
- package/examples/modules/app.pln +1 -1
- package/examples/modules/main.pln +1 -1
- package/examples/modules/math.pln +1 -1
- package/examples/mongo.pln +1 -1
- package/examples/objects.pln +1 -1
- package/examples/ocr.pln +1 -1
- package/examples/packages.pln +1 -1
- package/examples/record-kinds.pln +1 -1
- package/examples/records.pln +1 -1
- package/examples/rest-api-fetch.pln +1 -1
- package/examples/rest-api.pln +1 -1
- package/examples/scheduled-tasks.pln +1 -1
- package/examples/search-and-filter.pln +1 -1
- package/examples/server.pln +1 -1
- package/examples/sessions-and-cookies.pln +1 -1
- package/examples/sqlite.pln +1 -1
- package/examples/start.pln +1 -1
- package/examples/stdlib.pln +1 -1
- package/examples/string-verbs.pln +1 -1
- package/examples/telegram-ai-bot.pln +1 -1
- package/examples/telegram-bot.pln +1 -1
- package/examples/testing.pln +1 -1
- package/examples/three-dimensional/README.md +2 -2
- package/examples/three-dimensional/src/scene.pln +1 -1
- package/examples/web-api.pln +1 -1
- package/examples/web-app.pln +1 -1
- package/examples/websocket-server.pln +1 -1
- package/examples/websocket.pln +1 -1
- package/examples/whatsapp-bot/pairing.pln +2 -2
- package/examples/whatsapp-bot/qr.pln +2 -2
- package/package.json +7 -9
package/compiler/generator.js
CHANGED
|
@@ -11,9 +11,9 @@ const KNOWN_PACKAGES = {
|
|
|
11
11
|
path: `const path = require('path');`,
|
|
12
12
|
axios: `const axios = require('axios');`,
|
|
13
13
|
chalk: `const chalk = require('chalk');`,
|
|
14
|
-
// v2.1.0
|
|
14
|
+
// v2.1.0 - PostgreSQL driver behind the friendly "postgres" name.
|
|
15
15
|
postgres: `const { Pool } = require('pg');`,
|
|
16
|
-
// v2.2.0
|
|
16
|
+
// v2.2.0 - MongoDB driver.
|
|
17
17
|
mongodb: `const { MongoClient } = require('mongodb');`,
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -22,7 +22,7 @@ const KNOWN_PACKAGES = {
|
|
|
22
22
|
const NPM_NAME = {
|
|
23
23
|
sqlite: 'better-sqlite3',
|
|
24
24
|
postgres: 'pg',
|
|
25
|
-
// v2.1.1
|
|
25
|
+
// v2.1.1 - portable WebAssembly SQLite engine used by the "database"
|
|
26
26
|
// statement as an automatic fallback (or explicit choice) when
|
|
27
27
|
// better-sqlite3's native binding is unavailable.
|
|
28
28
|
'wasm-sqlite': 'sql.js',
|
|
@@ -42,7 +42,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
42
42
|
fs: `const fs = require('fs');`,
|
|
43
43
|
path: `const path = require('path');`,
|
|
44
44
|
crypto: `const crypto = require('crypto');`,
|
|
45
|
-
// v1.0.1
|
|
45
|
+
// v1.0.1 - env-file runtime. Applies KEY=VALUE pairs from a .env file to
|
|
46
46
|
// process.env. Blank lines and `#` comment lines are skipped.
|
|
47
47
|
dotenv: [
|
|
48
48
|
`function __loadEnvFile(path) {`,
|
|
@@ -61,7 +61,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
61
61
|
` }`,
|
|
62
62
|
`}`,
|
|
63
63
|
].join('\n'),
|
|
64
|
-
// v1.1.1
|
|
64
|
+
// v1.1.1 - ask runtime (RFC-0011 §14)
|
|
65
65
|
ask: [
|
|
66
66
|
`const readline = require('readline');`,
|
|
67
67
|
`async function __ask(prompt = '') {`,
|
|
@@ -73,7 +73,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
73
73
|
` }`,
|
|
74
74
|
`}`,
|
|
75
75
|
].join('\n'),
|
|
76
|
-
// v2.0.1
|
|
76
|
+
// v2.0.1 - OCR runtime (tesseract.js). Extracts text from an image file.
|
|
77
77
|
// The worker is created per call and always terminated, so repeated ocr
|
|
78
78
|
// statements do not leak workers.
|
|
79
79
|
ocr: [
|
|
@@ -88,7 +88,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
88
88
|
` }`,
|
|
89
89
|
`}`,
|
|
90
90
|
].join('\n'),
|
|
91
|
-
// v1.0.
|
|
91
|
+
// v1.0.361 - DOM browser runtime (select/selectAll/parseHTML). Browser
|
|
92
92
|
// globals are guarded so the generated JS explains the problem when it is
|
|
93
93
|
// run under Node instead of failing with a ReferenceError midpoint.
|
|
94
94
|
dom: [
|
|
@@ -107,7 +107,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
107
107
|
` return template.content;`,
|
|
108
108
|
`}`,
|
|
109
109
|
].join('\n'),
|
|
110
|
-
// v1.0.
|
|
110
|
+
// v1.0.361 - input runtime: pointer coordinates, gamepads, dropped files.
|
|
111
111
|
input: [
|
|
112
112
|
`function __localPoint(e, canvas) {`,
|
|
113
113
|
` if (typeof document === 'undefined') throw new Error('localPoint(...) needs a browser (document is not defined in Node).');`,
|
|
@@ -125,7 +125,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
125
125
|
` return [...(event && event.dataTransfer ? event.dataTransfer.files : [])];`,
|
|
126
126
|
`}`,
|
|
127
127
|
].join('\n'),
|
|
128
|
-
// v1.0.
|
|
128
|
+
// v1.0.361 - asset-loading runtime (images, JSON, bytes, data URLs). All
|
|
129
129
|
// helpers return promises; the STDLIB entries await them.
|
|
130
130
|
assets: [
|
|
131
131
|
`function __loadImage(url) {`,
|
|
@@ -162,7 +162,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
162
162
|
` });`,
|
|
163
163
|
`}`,
|
|
164
164
|
].join('\n'),
|
|
165
|
-
// v1.0.
|
|
165
|
+
// v1.0.361 - Web Audio runtime. The AudioContext is created once and shared
|
|
166
166
|
// (browsers cap the number), and resumed on demand because autoplay policies
|
|
167
167
|
// start it suspended.
|
|
168
168
|
audio: [
|
|
@@ -205,7 +205,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
205
205
|
` });`,
|
|
206
206
|
`}`,
|
|
207
207
|
].join('\n'),
|
|
208
|
-
// v1.0.
|
|
208
|
+
// v1.0.361 - WebGL runtime: context selection plus the three compile/link/
|
|
209
209
|
// buffer helpers behind the gl* stdlib entries.
|
|
210
210
|
gl: [
|
|
211
211
|
`function __glContext(canvas) {`,
|
|
@@ -246,7 +246,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
246
246
|
` return buffer;`,
|
|
247
247
|
`}`,
|
|
248
248
|
].join('\n'),
|
|
249
|
-
// v1.0.1
|
|
249
|
+
// v1.0.1 - shared runtime helpers for reflection, binary-size, YAML subset
|
|
250
250
|
// parsing/emitting, spread of timeouts, and set/map helpers. Injected lazily
|
|
251
251
|
// when any feature that needs them is used.
|
|
252
252
|
core: [
|
|
@@ -379,7 +379,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
379
379
|
` });`,
|
|
380
380
|
`}`,
|
|
381
381
|
].join('\n'),
|
|
382
|
-
// v1.0.35
|
|
382
|
+
// v1.0.35 - dependency-free SVG images and visualizations.
|
|
383
383
|
// The image value is an SVG string, so it can be saved, embedded, or returned
|
|
384
384
|
// from a web route without a native graphics dependency.
|
|
385
385
|
visualization: [
|
|
@@ -471,7 +471,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
471
471
|
` return 'data:image/svg+xml;base64,' + Buffer.from(String(image == null ? '' : image), 'utf8').toString('base64');`,
|
|
472
472
|
`}`,
|
|
473
473
|
].join('\n'),
|
|
474
|
-
// v1.0.1
|
|
474
|
+
// v1.0.1 - process execution (child processes).
|
|
475
475
|
process: [
|
|
476
476
|
`const { execFile } = require('child_process');`,
|
|
477
477
|
`function __runCommand(command, args) {`,
|
|
@@ -482,11 +482,11 @@ const BUILTIN_DECLARATIONS = {
|
|
|
482
482
|
` });`,
|
|
483
483
|
`}`,
|
|
484
484
|
].join('\n'),
|
|
485
|
-
// v1.0.1
|
|
485
|
+
// v1.0.1 - Map helpers.
|
|
486
486
|
mapset: [
|
|
487
487
|
`function __mapSet(map, key, value) { map.set(key, value); return map; }`,
|
|
488
488
|
].join('\n'),
|
|
489
|
-
// v2.2.0
|
|
489
|
+
// v2.2.0 - collection primitives (flatten / pick / omit / groupBy).
|
|
490
490
|
coll: [
|
|
491
491
|
`function __flatten(list) {`,
|
|
492
492
|
` const out = [];`,
|
|
@@ -529,7 +529,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
529
529
|
` return { items: slice, count: total, page, pages, perPage, hasNext: page < pages, hasPrev: page > 1 };`,
|
|
530
530
|
`}`,
|
|
531
531
|
].join('\n'),
|
|
532
|
-
// v1.0.1
|
|
532
|
+
// v1.0.1 - dynamic module loader.
|
|
533
533
|
loadmodule: [
|
|
534
534
|
`function __loadModule(spec) {`,
|
|
535
535
|
` const path = require('path');`,
|
|
@@ -538,7 +538,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
538
538
|
` catch (e) { if (spec[0] !== '.') return require(spec); throw e; }`,
|
|
539
539
|
`}`,
|
|
540
540
|
].join('\n'),
|
|
541
|
-
// v1.0.1
|
|
541
|
+
// v1.0.1 - recursive directory walker (returns full paths, files first).
|
|
542
542
|
walk: [
|
|
543
543
|
`function __walkFolder(dir) {`,
|
|
544
544
|
` const fs = require('fs');`,
|
|
@@ -556,7 +556,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
556
556
|
` return out;`,
|
|
557
557
|
`}`,
|
|
558
558
|
].join('\n'),
|
|
559
|
-
// v2.1.0
|
|
559
|
+
// v2.1.0 - request validation runtime. Returns the names of required
|
|
560
560
|
// fields whose value is missing (undefined/null/empty string) in data.
|
|
561
561
|
validation: [
|
|
562
562
|
`function __validate(data, fields) {`,
|
|
@@ -566,7 +566,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
566
566
|
` });`,
|
|
567
567
|
`}`,
|
|
568
568
|
].join('\n'),
|
|
569
|
-
// v2.1.0
|
|
569
|
+
// v2.1.0 - email runtime (nodemailer). One transport per program; sending
|
|
570
570
|
// fails with a teaching error when no transport was configured.
|
|
571
571
|
mailer: [
|
|
572
572
|
`const nodemailer = require('nodemailer');`,
|
|
@@ -577,12 +577,12 @@ const BUILTIN_DECLARATIONS = {
|
|
|
577
577
|
` return __mailTransport.sendMail(options);`,
|
|
578
578
|
`}`,
|
|
579
579
|
].join('\n'),
|
|
580
|
-
// v2.1.0
|
|
580
|
+
// v2.1.0 - cron scheduling runtime (croner). Zero dependencies, validates
|
|
581
581
|
// expressions at registration time.
|
|
582
582
|
scheduler: [
|
|
583
583
|
`const cron = require('croner');`,
|
|
584
584
|
].join('\n'),
|
|
585
|
-
// v2.1.0
|
|
585
|
+
// v2.1.0 - WebSocket runtime (ws). Standalone server bound to its own port.
|
|
586
586
|
websocket: [
|
|
587
587
|
`const { WebSocketServer } = require('ws');`,
|
|
588
588
|
`function __wsServerCreate(port, handlers) {`,
|
|
@@ -606,7 +606,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
606
606
|
` }`,
|
|
607
607
|
`}`,
|
|
608
608
|
].join('\n'),
|
|
609
|
-
// v2.1.0
|
|
609
|
+
// v2.1.0 - cache runtime (Redis via the redis package). The client is
|
|
610
610
|
// created by the "cache" statement; accessors fail with a teaching error
|
|
611
611
|
// when no cache was configured.
|
|
612
612
|
cache: [
|
|
@@ -633,7 +633,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
633
633
|
` return __memCache.delete(key) ? 1 : 0;`,
|
|
634
634
|
`}`,
|
|
635
635
|
].join('\n'),
|
|
636
|
-
// v2.1.1
|
|
636
|
+
// v2.1.1 - WhatsApp runtime (@whiskeysockets/baileys behind the
|
|
637
637
|
// "whatsapp bot" block). Everything Baileys-shaped stays in here: socket
|
|
638
638
|
// creation, auth-state files, QR rendering, pairing codes, connection
|
|
639
639
|
// lifecycle and messages.upsert normalization. PlainScript programs only ever
|
|
@@ -641,7 +641,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
641
641
|
whatsapp: [
|
|
642
642
|
`const { __whatsappStart, __whatsappPair, __whatsappOnMessage, __whatsappReply, __whatsappSend, __whatsappDownload } = (() => {`,
|
|
643
643
|
` let sock = null;`,
|
|
644
|
-
` let __waBaileysPkg = '@
|
|
644
|
+
` let __waBaileysPkg = '@whiskeysockets/baileys';`,
|
|
645
645
|
` const handlers = [];`,
|
|
646
646
|
` const __waSilentLogger = (() => {`,
|
|
647
647
|
` const noop = () => {};`,
|
|
@@ -751,7 +751,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
751
751
|
` }`,
|
|
752
752
|
` function __whatsappOnMessage(handler) { handlers.push(handler); }`,
|
|
753
753
|
` async function __whatsappStart(options) {`,
|
|
754
|
-
` __waBaileysPkg = options.baileys || '@
|
|
754
|
+
` __waBaileysPkg = options.baileys || '@whiskeysockets/baileys';`,
|
|
755
755
|
` const baileys = require(__waBaileysPkg);`,
|
|
756
756
|
` const makeWASocket = baileys.default;`,
|
|
757
757
|
` const { useMultiFileAuthState, makeCacheableSignalKeyStore, DisconnectReason } = baileys;`,
|
|
@@ -766,7 +766,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
766
766
|
// Auth/session persistence: useMultiFileAuthState stores credentials in
|
|
767
767
|
// the folder from `auth "<name>"`; saveCreds writes every update back.
|
|
768
768
|
` const { state, saveCreds } = await useMultiFileAuthState(folder);`,
|
|
769
|
-
// v2.14
|
|
769
|
+
// v2.14 - adopt the proven pairing-safe socket settings used by the
|
|
770
770
|
// reference Dual-Crasher build on the qwerty fork: a fixed Baileys protocol
|
|
771
771
|
// version and the exact browser fingerprint that survives WhatsApp's
|
|
772
772
|
// handshake without a 428 connection close.
|
|
@@ -783,7 +783,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
783
783
|
` auth: { creds: state.creds, keys: makeCacheableSignalKeyStore(state.keys, __waSilentLogger) },`,
|
|
784
784
|
` });`,
|
|
785
785
|
` sock.ev.on('creds.update', saveCreds);`,
|
|
786
|
-
// Pairing codes are requested two seconds after socket creation
|
|
786
|
+
// Pairing codes are requested two seconds after socket creation - asking
|
|
787
787
|
// earlier aborts the link attempt. PlainScript retries a few times (spam)
|
|
788
788
|
// so a dropped request never blocks linking. The number was validated at
|
|
789
789
|
// compile time; no custom suffix is applied.
|
|
@@ -983,7 +983,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
983
983
|
` return { __whatsappStart, __whatsappPair, __whatsappOnMessage, __whatsappReply, __whatsappSend, __whatsappDownload };`,
|
|
984
984
|
`})();`,
|
|
985
985
|
].join('\n'),
|
|
986
|
-
// v2.1.1
|
|
986
|
+
// v2.1.1 - HTTP client runtime on the global fetch API (Node.js 18+).
|
|
987
987
|
// Every response becomes a PlainScript-friendly record: { ok, status, headers,
|
|
988
988
|
// data }, where data holds parsed JSON when the content type says JSON.
|
|
989
989
|
http: [
|
|
@@ -1020,7 +1020,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1020
1020
|
` return { ok: response.ok, status: response.status, headers: Object.fromEntries(response.headers.entries()), data };`,
|
|
1021
1021
|
`}`,
|
|
1022
1022
|
].join('\n'),
|
|
1023
|
-
// v2.2.0
|
|
1023
|
+
// v2.2.0 - provider-neutral AI runtime. `chat` and `embedText` speak
|
|
1024
1024
|
// OpenAI-compatible APIs, including Groq, OpenRouter, Together, Fireworks,
|
|
1025
1025
|
// and DeepSeek. A custom `base` and `key` can be supplied per call.
|
|
1026
1026
|
ai: [
|
|
@@ -1080,7 +1080,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1080
1080
|
` return dot / (Math.sqrt(na) * Math.sqrt(nb));`,
|
|
1081
1081
|
`}`,
|
|
1082
1082
|
].join('\n'),
|
|
1083
|
-
// v2.1.1
|
|
1083
|
+
// v2.1.1 - file upload runtime (multer behind "accept uploads"). Files are
|
|
1084
1084
|
// held in memory by default or written to disk when a folder is given.
|
|
1085
1085
|
// Normalised records expose: name, type, size, data (buffer) and path.
|
|
1086
1086
|
uploads: [
|
|
@@ -1124,7 +1124,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1124
1124
|
` return (req.files || []).filter((f) => f.fieldname === field).map(__normalizeUpload);`,
|
|
1125
1125
|
`}`,
|
|
1126
1126
|
].join('\n'),
|
|
1127
|
-
// v2.1.1
|
|
1127
|
+
// v2.1.1 - cookie helpers shared by the cookie() accessor and the session
|
|
1128
1128
|
// runtime.
|
|
1129
1129
|
cookies: [
|
|
1130
1130
|
`function __parseCookies(header) {`,
|
|
@@ -1145,7 +1145,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1145
1145
|
` return value === undefined ? null : value;`,
|
|
1146
1146
|
`}`,
|
|
1147
1147
|
].join('\n'),
|
|
1148
|
-
// v2.1.1
|
|
1148
|
+
// v2.1.1 - session runtime. Cookie-signed session ids backed by an
|
|
1149
1149
|
// in-memory store (sessions reset when the server restarts).
|
|
1150
1150
|
sessions: [
|
|
1151
1151
|
`const __sessionStore = new Map();`,
|
|
@@ -1188,7 +1188,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1188
1188
|
` response.setHeader('Set-Cookie', 'plainscript.sid=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0');`,
|
|
1189
1189
|
`}`,
|
|
1190
1190
|
].join('\n'),
|
|
1191
|
-
// v2.1.1
|
|
1191
|
+
// v2.1.1 - authentication runtime: scrypt password hashing and signed
|
|
1192
1192
|
// tokens (HS256 format), both zero-dependency.
|
|
1193
1193
|
auth: [
|
|
1194
1194
|
`const __authCrypto = require('crypto');`,
|
|
@@ -1233,7 +1233,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1233
1233
|
` }`,
|
|
1234
1234
|
`}`,
|
|
1235
1235
|
].join('\n'),
|
|
1236
|
-
// v2.1.1
|
|
1236
|
+
// v2.1.1 - Google sign-in (OAuth 2.0 authorization code flow). Registers
|
|
1237
1237
|
// two endpoints: /auth/google (redirect) and the configured callback URL
|
|
1238
1238
|
// (token exchange + profile fetch), then redirects to the landing page.
|
|
1239
1239
|
oauth: [
|
|
@@ -1288,7 +1288,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1288
1288
|
` });`,
|
|
1289
1289
|
`}`,
|
|
1290
1290
|
].join('\n'),
|
|
1291
|
-
// v2.1.1
|
|
1291
|
+
// v2.1.1 - per-IP request rate limiting with an in-memory sliding window.
|
|
1292
1292
|
ratelimit: [
|
|
1293
1293
|
`function __rateLimit(options) {`,
|
|
1294
1294
|
` const hits = new Map();`,
|
|
@@ -1313,13 +1313,13 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1313
1313
|
` };`,
|
|
1314
1314
|
`}`,
|
|
1315
1315
|
].join('\n'),
|
|
1316
|
-
// v2.1.1
|
|
1316
|
+
// v2.1.1 - pause helper for "retry N times every N seconds".
|
|
1317
1317
|
retry: [
|
|
1318
1318
|
`const __retrySleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));`,
|
|
1319
1319
|
].join('\n'),
|
|
1320
|
-
// IOPL-native
|
|
1320
|
+
// IOPL-native - event emitter runtime.
|
|
1321
1321
|
__emitter: 'const __emitter = new (require("events").EventEmitter)();',
|
|
1322
|
-
// IOPL-native
|
|
1322
|
+
// IOPL-native - line-by-line file streaming runtime.
|
|
1323
1323
|
__streamFile: [
|
|
1324
1324
|
`async function __streamFile(path, fn) {`,
|
|
1325
1325
|
` const fs = require('fs');`,
|
|
@@ -1327,7 +1327,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1327
1327
|
` for await (const line of rl) await fn(line);`,
|
|
1328
1328
|
`}`,
|
|
1329
1329
|
].join('\n'),
|
|
1330
|
-
// v2.1.1
|
|
1330
|
+
// v2.1.1 - SQLite runtime with a portable engine chain. Default order:
|
|
1331
1331
|
// better-sqlite3 (native binding) first, sql.js (WebAssembly) as fallback.
|
|
1332
1332
|
// Both engines are wrapped in the same tiny synchronous surface that PlainScript
|
|
1333
1333
|
// generates (prepare().all()/.run(), exec(), transaction()), so compiled
|
|
@@ -1545,7 +1545,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1545
1545
|
` inline_keyboard: [rows.map(([text, data]) => ({ text, callback_data: data }))],`,
|
|
1546
1546
|
` },`,
|
|
1547
1547
|
` });`,
|
|
1548
|
-
// v2.0.1
|
|
1548
|
+
// v2.0.1 - createTelegramBot is defined inside this module so its handler
|
|
1549
1549
|
// registry (`handlers`) and API transport (`call`, `sleep`) are in scope.
|
|
1550
1550
|
// Defining it outside made every BOT.onCommand/onPattern/onCallback call
|
|
1551
1551
|
// throw "ReferenceError: handlers is not defined", so no rendered inline
|
|
@@ -1664,11 +1664,11 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1664
1664
|
symbolSpecies: (_args) => `Symbol.species`,
|
|
1665
1665
|
// Runtime constructors
|
|
1666
1666
|
sqlite: (args, context) => `new Database(${args.map(arg => generateExpr(arg, context)).join(', ')})`,
|
|
1667
|
-
// v0.6
|
|
1667
|
+
// v0.6 - runtime standard library
|
|
1668
1668
|
print: (args, context) => `console.log(${args.map(arg => generateExpr(arg, context)).join(', ')})`,
|
|
1669
1669
|
readFile: (args, context) => `fs.readFileSync(${generateExpr(args[0], context)}, 'utf8')`,
|
|
1670
1670
|
writeFile: (args, context) => `fs.writeFileSync(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)}, 'utf8')`,
|
|
1671
|
-
// v2.4.0
|
|
1671
|
+
// v2.4.0 - dependency-free SVG image and visualization helpers.
|
|
1672
1672
|
svgImage: (args, context) => {
|
|
1673
1673
|
ensureBuiltin(context, 'visualization');
|
|
1674
1674
|
return `__svgImage(${args.map(arg => generateExpr(arg, context)).join(', ')})`;
|
|
@@ -1699,7 +1699,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1699
1699
|
env: (args, context) => `process.env[${generateExpr(args[0], context)}]`,
|
|
1700
1700
|
exit: (args, context) => `process.exit(${args.length ? generateExpr(args[0], context) : '0'})`,
|
|
1701
1701
|
uuid: (_args, context) => `crypto.randomUUID()`,
|
|
1702
|
-
// v1.2
|
|
1702
|
+
// v1.2 - Telegram runtime helpers
|
|
1703
1703
|
bot: (args, context) => {
|
|
1704
1704
|
ensureBuiltin(context, 'telegram');
|
|
1705
1705
|
markAsync(context);
|
|
@@ -1741,7 +1741,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1741
1741
|
const params = args.length > 1 ? generateExpr(args[1], context) : '{}';
|
|
1742
1742
|
return `await Telegram.call(${method}, ${params})`;
|
|
1743
1743
|
},
|
|
1744
|
-
// v2.1.0
|
|
1744
|
+
// v2.1.0 - HTTP request accessors. Only meaningful inside a route handler,
|
|
1745
1745
|
// where Express provides req/res.
|
|
1746
1746
|
param: (args, context) => routeAccessor('param', 'params', args, context),
|
|
1747
1747
|
query: (args, context) => routeAccessor('query', 'query', args, context),
|
|
@@ -1758,13 +1758,13 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1758
1758
|
if (!args || args.length === 0) return base;
|
|
1759
1759
|
return `${base}[${generateExpr(args[0], context)}]`;
|
|
1760
1760
|
},
|
|
1761
|
-
// v2.1.0
|
|
1761
|
+
// v2.1.0 - request validation. Returns the list of missing required fields.
|
|
1762
1762
|
validate: (args, context) => {
|
|
1763
1763
|
ensureBuiltin(context, 'validation');
|
|
1764
1764
|
return `__validate(${args.map(arg => generateExpr(arg, context)).join(', ')})`;
|
|
1765
1765
|
},
|
|
1766
1766
|
|
|
1767
|
-
// ── v2.1.0
|
|
1767
|
+
// ── v2.1.0 - filesystem helpers (sync, matching readFile/writeFile style)
|
|
1768
1768
|
|
|
1769
1769
|
copyFile: (args, context) => { ensureBuiltin(context, 'fs'); return `fs.copyFileSync(${args.map(a => generateExpr(a, context)).join(', ')})`; },
|
|
1770
1770
|
moveFile: (args, context) => { ensureBuiltin(context, 'fs'); return `fs.renameSync(${args.map(a => generateExpr(a, context)).join(', ')})`; },
|
|
@@ -1782,7 +1782,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1782
1782
|
return `fs.writeFileSync(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`;
|
|
1783
1783
|
},
|
|
1784
1784
|
|
|
1785
|
-
// ── v2.1.0
|
|
1785
|
+
// ── v2.1.0 - text, number and collection helpers
|
|
1786
1786
|
|
|
1787
1787
|
trim: (args, context) => `String(${generateExpr(args[0], context)}).trim()`,
|
|
1788
1788
|
replace: (args, context) => {
|
|
@@ -1813,7 +1813,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1813
1813
|
hasKey: (args, context) => `Object.prototype.hasOwnProperty.call(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
1814
1814
|
merge: (args, context) => `{ ...${generateExpr(args[0], context)}, ...${generateExpr(args[1], context)} }`,
|
|
1815
1815
|
|
|
1816
|
-
// ── v2.2.0
|
|
1816
|
+
// ── v2.2.0 - collection & string primitives (IOPL-native, dependency-free).
|
|
1817
1817
|
// A numeric range [start..end], stepping by 1 (or `step` when given).
|
|
1818
1818
|
range: (args, context) => {
|
|
1819
1819
|
const start = generateExpr(args[0], context);
|
|
@@ -1830,7 +1830,11 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1830
1830
|
ensureBuiltin(context, 'coll');
|
|
1831
1831
|
return `__flatten(${generateExpr(args[0], context)})`;
|
|
1832
1832
|
},
|
|
1833
|
-
includes: (args, context) =>
|
|
1833
|
+
includes: (args, context) => {
|
|
1834
|
+
const coll = generateExpr(args[0], context);
|
|
1835
|
+
const val = generateExpr(args[1], context);
|
|
1836
|
+
return `(${coll} instanceof Set ? ${coll}.has(${val}) : (${coll}).includes(${val}))`;
|
|
1837
|
+
},
|
|
1834
1838
|
paginate: (args, context) => {
|
|
1835
1839
|
ensureBuiltin(context, 'coll');
|
|
1836
1840
|
return `__paginate(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)}, ${args.length > 2 ? generateExpr(args[2], context) : '10'})`;
|
|
@@ -1858,7 +1862,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1858
1862
|
padStart: (args, context) => `String(${generateExpr(args[0], context)}).padStart(${generateExpr(args[1], context)}, String(${args.length > 2 ? generateExpr(args[2], context) : '" "'}))`,
|
|
1859
1863
|
padEnd: (args, context) => `String(${generateExpr(args[0], context)}).padEnd(${generateExpr(args[1], context)}, String(${args.length > 2 ? generateExpr(args[2], context) : '" "'}))`,
|
|
1860
1864
|
|
|
1861
|
-
// ── v2.3.0
|
|
1865
|
+
// ── v2.3.0 - Proxy and Reflect (IOPL-native).
|
|
1862
1866
|
// Proxy creation: proxy(target, handler)
|
|
1863
1867
|
proxy: (args, context) => `new Proxy(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
1864
1868
|
// Proxy revocable: proxyRevocable(target, handler) -> { proxy, revoke }
|
|
@@ -1878,8 +1882,8 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1878
1882
|
reflectSet: (args, context) => `Reflect.set(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
1879
1883
|
reflectSetPrototypeOf: (args, context) => `Reflect.setPrototypeOf(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
1880
1884
|
|
|
1881
|
-
// ── v1.0.1
|
|
1882
|
-
// first non-null, non-undefined argument
|
|
1885
|
+
// ── v1.0.1 - nullable / regex / date helpers (IOPL-native).
|
|
1886
|
+
// first non-null, non-undefined argument - IOPL null-coalescing.
|
|
1883
1887
|
coalesce: (args, context) =>
|
|
1884
1888
|
`(() => { const __vals = [${args.map(a => generateExpr(a, context)).join(', ')}]; for (const __v of __vals) if (__v !== null && __v !== undefined) return __v; return undefined; })()`,
|
|
1885
1889
|
// regex-aware replace (replace() is literal-only).
|
|
@@ -1895,7 +1899,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
1895
1899
|
return `__formatDate(${value}, ${pattern})`;
|
|
1896
1900
|
},
|
|
1897
1901
|
|
|
1898
|
-
// ── v1.0.2
|
|
1902
|
+
// ── v1.0.2 - Native Date/DateTime/Regex support (IOPL-native, no JS gateway needed).
|
|
1899
1903
|
// Create a new Date object. With no args: now. With 1 arg: parse ISO string or timestamp.
|
|
1900
1904
|
// With multiple args: year, month (1-12), day, hour, min, sec, ms.
|
|
1901
1905
|
newDate: (args, context) => {
|
|
@@ -2033,7 +2037,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2033
2037
|
return `${text}.split(new RegExp(${pattern}, ${flags}))`;
|
|
2034
2038
|
},
|
|
2035
2039
|
|
|
2036
|
-
// ── v2.1.0
|
|
2040
|
+
// ── v2.1.0 - cache (Redis) accessors. All async.
|
|
2037
2041
|
|
|
2038
2042
|
cacheGet: (args, context) => {
|
|
2039
2043
|
ensureBuiltin(context, 'cache');
|
|
@@ -2056,14 +2060,14 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2056
2060
|
return `await __cacheDelete(String(${generateExpr(args[0], context)}))`;
|
|
2057
2061
|
},
|
|
2058
2062
|
|
|
2059
|
-
// v2.1.0
|
|
2063
|
+
// v2.1.0 - email sending helper (statement form uses this too).
|
|
2060
2064
|
sendMail: (args, context) => {
|
|
2061
2065
|
ensureBuiltin(context, 'mailer');
|
|
2062
2066
|
markAsync(context);
|
|
2063
2067
|
return `__mailSend(${args.map(arg => generateExpr(arg, context)).join(', ')})`;
|
|
2064
2068
|
},
|
|
2065
2069
|
|
|
2066
|
-
// ── v2.1.1
|
|
2070
|
+
// ── v2.1.1 - uploads, cookies, passwords and tokens
|
|
2067
2071
|
|
|
2068
2072
|
// upload("field") / uploads("field") read files registered by
|
|
2069
2073
|
// "accept uploads". Single file → record or null; plural → array.
|
|
@@ -2106,7 +2110,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2106
2110
|
return `readToken(${args.map(arg => generateExpr(arg, context)).join(', ')})`;
|
|
2107
2111
|
},
|
|
2108
2112
|
|
|
2109
|
-
// ── v1.0.1
|
|
2113
|
+
// ── v1.0.1 - capability-gap stdlib (reflection, binary, concurrency, ...) ──
|
|
2110
2114
|
|
|
2111
2115
|
// Reflection
|
|
2112
2116
|
typeOf: (args, context) => { ensureBuiltin(context, 'core'); return `__typeOf(${generateExpr(args[0], context)})`; },
|
|
@@ -2137,7 +2141,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2137
2141
|
return `crypto.createHash('md5').update(String(${generateExpr(args[0], context)})).digest('hex')`;
|
|
2138
2142
|
},
|
|
2139
2143
|
|
|
2140
|
-
// Serialization
|
|
2144
|
+
// Serialization - minimal dependency-free YAML subset (see __yamlParse).
|
|
2141
2145
|
yamlDecode: (args, context) => { ensureBuiltin(context, 'core'); return `__yamlParse(${generateExpr(args[0], context)})`; },
|
|
2142
2146
|
yamlEncode: (args, context) => { ensureBuiltin(context, 'core'); return `__yamlStringify(${generateExpr(args[0], context)})`; },
|
|
2143
2147
|
|
|
@@ -2167,7 +2171,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2167
2171
|
// Generators / iterables
|
|
2168
2172
|
spread: (args, context) => `[...${generateExpr(args[0], context)}]`,
|
|
2169
2173
|
|
|
2170
|
-
// v1.0.1
|
|
2174
|
+
// v1.0.1 - dynamic module loading (the runtime companion to `import "./x.pt"`).
|
|
2171
2175
|
// Resolves relative to the bundler's CWD so `loadModule("./m")` behaves like
|
|
2172
2176
|
// `require.resolve` from the program root.
|
|
2173
2177
|
loadModule: (args, context) => {
|
|
@@ -2175,7 +2179,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2175
2179
|
return `__loadModule(${generateExpr(args[0], context)})`;
|
|
2176
2180
|
},
|
|
2177
2181
|
|
|
2178
|
-
// ── v2.2.0
|
|
2182
|
+
// ── v2.2.0 - AI/ML. `chat`/`embedText` call an OpenAI-compatible endpoint
|
|
2179
2183
|
// (key from OPENAI_API_KEY, base from OPENAI_BASE_URL); `similarity` runs
|
|
2180
2184
|
// offline cosine similarity over any two equal-length numeric vectors.
|
|
2181
2185
|
chat: (args, context) => {
|
|
@@ -2276,7 +2280,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2276
2280
|
return `fs.appendFileSync(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)} + '\\n', 'utf8')`;
|
|
2277
2281
|
},
|
|
2278
2282
|
|
|
2279
|
-
// ── v1.0.2
|
|
2283
|
+
// ── v1.0.2 - Extended Math functions (IOPL-native).
|
|
2280
2284
|
abs: (args, context) => `Math.abs(${generateExpr(args[0], context)})`,
|
|
2281
2285
|
min: (args, context) => `Math.min(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2282
2286
|
max: (args, context) => `Math.max(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
@@ -2316,7 +2320,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2316
2320
|
hypot: (args, context) => `Math.hypot(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2317
2321
|
cbrt: (args, context) => `Math.cbrt(${generateExpr(args[0], context)})`,
|
|
2318
2322
|
|
|
2319
|
-
// ── v1.0.2
|
|
2323
|
+
// ── v1.0.2 - Extended String functions (IOPL-native).
|
|
2320
2324
|
trim: (args, context) => `String(${generateExpr(args[0], context)}).trim()`,
|
|
2321
2325
|
trimStart: (args, context) => `String(${generateExpr(args[0], context)}).trimStart()`,
|
|
2322
2326
|
trimEnd: (args, context) => `String(${generateExpr(args[0], context)}).trimEnd()`,
|
|
@@ -2348,7 +2352,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2348
2352
|
toString: (args, context) => `String(${generateExpr(args[0], context)}).toString()`,
|
|
2349
2353
|
stringValueOf: (args, context) => `String(${generateExpr(args[0], context)}).valueOf()`,
|
|
2350
2354
|
|
|
2351
|
-
// ── v1.0.2
|
|
2355
|
+
// ── v1.0.2 - Extended Array/Collection functions (IOPL-native).
|
|
2352
2356
|
push: (args, context) => `(${generateExpr(args[0], context)}).push(${args.slice(1).map(a => generateExpr(a, context)).join(', ')})`,
|
|
2353
2357
|
pop: (args, context) => `(${generateExpr(args[0], context)}).pop()`,
|
|
2354
2358
|
shift: (args, context) => `(${generateExpr(args[0], context)}).shift()`,
|
|
@@ -2364,7 +2368,12 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2364
2368
|
findLastIndex: (args, context) => `(${generateExpr(args[0], context)}).findLastIndex(${generateExpr(args[1], context)})`,
|
|
2365
2369
|
indexOf: (args, context) => `(${generateExpr(args[0], context)}).indexOf(${generateExpr(args[1], context)}${args.length > 2 ? ', ' + generateExpr(args[2], context) : ''})`,
|
|
2366
2370
|
lastIndexOf: (args, context) => `(${generateExpr(args[0], context)}).lastIndexOf(${generateExpr(args[1], context)}${args.length > 2 ? ', ' + generateExpr(args[2], context) : ''})`,
|
|
2367
|
-
includes: (args, context) =>
|
|
2371
|
+
includes: (args, context) => {
|
|
2372
|
+
const coll = generateExpr(args[0], context);
|
|
2373
|
+
const val = generateExpr(args[1], context);
|
|
2374
|
+
const fromIndex = args.length > 2 ? ', ' + generateExpr(args[2], context) : '';
|
|
2375
|
+
return `(${coll} instanceof Set ? ${coll}.has(${val}) : (${coll}).includes(${val}${fromIndex}))`;
|
|
2376
|
+
},
|
|
2368
2377
|
join: (args, context) => `(${generateExpr(args[0], context)}).join(${args.length > 1 ? generateExpr(args[1], context) : '","'})`,
|
|
2369
2378
|
reverse: (args, context) => `[...${generateExpr(args[0], context)}].reverse()`,
|
|
2370
2379
|
sort: (args, context) => `[...${generateExpr(args[0], context)}].sort(${args.length > 1 ? generateExpr(args[1], context) : '(a, b) => (a < b ? -1 : a > b ? 1 : 0)'})`,
|
|
@@ -2386,7 +2395,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2386
2395
|
values: (args, context) => `Object.values(${generateExpr(args[0], context)})`,
|
|
2387
2396
|
entries: (args, context) => `Object.entries(${generateExpr(args[0], context)})`,
|
|
2388
2397
|
|
|
2389
|
-
// ── v1.0.2
|
|
2398
|
+
// ── v1.0.2 - Extended Object functions (IOPL-native).
|
|
2390
2399
|
assign: (args, context) => `Object.assign(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2391
2400
|
create: (args, context) => `Object.create(${generateExpr(args[0], context)}${args.length > 1 ? ', ' + generateExpr(args[1], context) : ''})`,
|
|
2392
2401
|
defineProperty: (args, context) => `Object.defineProperty(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
@@ -2406,7 +2415,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2406
2415
|
seal: (args, context) => `Object.seal(${generateExpr(args[0], context)})`,
|
|
2407
2416
|
hasOwn: (args, context) => `Object.hasOwn(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
2408
2417
|
|
|
2409
|
-
// ── v1.0.2
|
|
2418
|
+
// ── v1.0.2 - Promise/Async utilities (IOPL-native).
|
|
2410
2419
|
Promise: {
|
|
2411
2420
|
resolve: (args, context) => `Promise.resolve(${generateExpr(args[0], context)})`,
|
|
2412
2421
|
reject: (args, context) => `Promise.reject(${generateExpr(args[0], context)})`,
|
|
@@ -2440,11 +2449,11 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2440
2449
|
return `Promise.race([${generateExpr(args[0], context)}, new Promise((_, r) => setTimeout(() => r(new Error('Timed out')), ${ms}))])`;
|
|
2441
2450
|
},
|
|
2442
2451
|
|
|
2443
|
-
// ── v1.0.2
|
|
2452
|
+
// ── v1.0.2 - JSON utilities (IOPL-native).
|
|
2444
2453
|
jsonParse: (args, context) => `JSON.parse(${generateExpr(args[0], context)})`,
|
|
2445
2454
|
stringify: (args, context) => `JSON.stringify(${generateExpr(args[0], context)}${args.length > 1 ? ', ' + generateExpr(args[1], context) : ''}${args.length > 2 ? ', ' + generateExpr(args[2], context) : ''})`,
|
|
2446
2455
|
|
|
2447
|
-
// ── v1.0.2
|
|
2456
|
+
// ── v1.0.2 - Type checking utilities (IOPL-native).
|
|
2448
2457
|
isArray: (args, context) => `Array.isArray(${generateExpr(args[0], context)})`,
|
|
2449
2458
|
isInteger: (args, context) => `Number.isInteger(${generateExpr(args[0], context)})`,
|
|
2450
2459
|
isNaN: (args, context) => `Number.isNaN(${generateExpr(args[0], context)})`,
|
|
@@ -2453,12 +2462,12 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2453
2462
|
parseInt: (args, context) => `parseInt(${generateExpr(args[0], context)}${args.length > 1 ? ', ' + generateExpr(args[1], context) : ''})`,
|
|
2454
2463
|
parseFloat: (args, context) => `parseFloat(${generateExpr(args[0], context)})`,
|
|
2455
2464
|
|
|
2456
|
-
// ── v1.0.2
|
|
2465
|
+
// ── v1.0.2 - Array static methods (IOPL-native).
|
|
2457
2466
|
arrayFrom: (args, context) => `Array.from(${generateExpr(args[0], context)}${args.length > 1 ? ', ' + generateExpr(args[1], context) : ''})`,
|
|
2458
2467
|
arrayOf: (args, context) => `Array.of(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2459
2468
|
arrayIsArray: (args, context) => `Array.isArray(${generateExpr(args[0], context)})`,
|
|
2460
2469
|
|
|
2461
|
-
// ── v1.0.2
|
|
2470
|
+
// ── v1.0.2 - Object static methods (IOPL-native).
|
|
2462
2471
|
objectFromEntries: (args, context) => `Object.fromEntries(${generateExpr(args[0], context)})`,
|
|
2463
2472
|
objectGetOwnPropertySymbols: (args, context) => `Object.getOwnPropertySymbols(${generateExpr(args[0], context)})`,
|
|
2464
2473
|
objectGetOwnPropertyDescriptors: (args, context) => `Object.getOwnPropertyDescriptors(${generateExpr(args[0], context)})`,
|
|
@@ -2482,7 +2491,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2482
2491
|
objectFreeze: (args, context) => `Object.freeze(${generateExpr(args[0], context)})`,
|
|
2483
2492
|
objectSeal: (args, context) => `Object.seal(${generateExpr(args[0], context)})`,
|
|
2484
2493
|
|
|
2485
|
-
// ── v1.0.2
|
|
2494
|
+
// ── v1.0.2 - Symbol support (IOPL-native).
|
|
2486
2495
|
symbol: (args, context) => `Symbol(${args.length > 0 ? generateExpr(args[0], context) : 'undefined'})`,
|
|
2487
2496
|
symbolFor: (args, context) => `Symbol.for(${generateExpr(args[0], context)})`,
|
|
2488
2497
|
symbolKeyFor: (args, context) => `Symbol.keyFor(${generateExpr(args[0], context)})`,
|
|
@@ -2499,7 +2508,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2499
2508
|
symbolToPrimitive: (_args) => `Symbol.toPrimitive`,
|
|
2500
2509
|
symbolUnscopables: (_args) => `Symbol.unscopables`,
|
|
2501
2510
|
|
|
2502
|
-
// ── v1.0.2
|
|
2511
|
+
// ── v1.0.2 - Math static methods (IOPL-native).
|
|
2503
2512
|
mathAbs: (args, context) => `Math.abs(${generateExpr(args[0], context)})`,
|
|
2504
2513
|
mathMin: (args, context) => `Math.min(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2505
2514
|
mathMax: (args, context) => `Math.max(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
@@ -2537,7 +2546,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2537
2546
|
mathHypot: (args, context) => `Math.hypot(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2538
2547
|
mathCbrt: (args, context) => `Math.cbrt(${generateExpr(args[0], context)})`,
|
|
2539
2548
|
|
|
2540
|
-
// ── v1.0.2
|
|
2549
|
+
// ── v1.0.2 - TypedArray support (IOPL-native).
|
|
2541
2550
|
int8Array: (args, context) => `new Int8Array(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2542
2551
|
uint8Array: (args, context) => `new Uint8Array(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2543
2552
|
uint8ClampedArray: (args, context) => `new Uint8ClampedArray(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
@@ -2552,25 +2561,25 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2552
2561
|
dataView: (args, context) => `new DataView(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2553
2562
|
arrayBuffer: (args, context) => `new ArrayBuffer(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2554
2563
|
|
|
2555
|
-
// ── v1.0.2
|
|
2564
|
+
// ── v1.0.2 - Global objects access (IOPL-native).
|
|
2556
2565
|
globalThis: (_args) => `globalThis`,
|
|
2557
2566
|
console: (_args) => `console`,
|
|
2558
2567
|
process: (_args) => `process`,
|
|
2559
2568
|
Buffer: (_args) => `Buffer`,
|
|
2560
2569
|
|
|
2561
|
-
// ── v2.3.0
|
|
2570
|
+
// ── v2.3.0 - EventSource / Server-Sent Events (IOPL-native).
|
|
2562
2571
|
eventSource: (args, context) => `new EventSource(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2563
2572
|
|
|
2564
|
-
// ── v2.2.0
|
|
2573
|
+
// ── v2.2.0 - URL and URLSearchParams (IOPL-native).
|
|
2565
2574
|
url: (args, context) => `new URL(${generateExpr(args[0], context)}${args[1] ? `, ${generateExpr(args[1], context)}` : ''})`,
|
|
2566
2575
|
urlSearchParams: (args, context) => `new URLSearchParams(${args.length ? generateExpr(args[0], context) : ''})`,
|
|
2567
2576
|
|
|
2568
|
-
// ── v2.2.0
|
|
2577
|
+
// ── v2.2.0 - Intl / Internationalization (IOPL-native).
|
|
2569
2578
|
dateTimeFormat: (args, context) => `new Intl.DateTimeFormat(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
2570
2579
|
numberFormat: (args, context) => `new Intl.NumberFormat(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
2571
2580
|
collator: (args, context) => `new Intl.Collator(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
2572
2581
|
|
|
2573
|
-
// ── v2.2.0
|
|
2582
|
+
// ── v2.2.0 - Crypto / Web Crypto API (IOPL-native).
|
|
2574
2583
|
cryptoRandomUUID: (_args) => `crypto.randomUUID()`,
|
|
2575
2584
|
cryptoGetRandomValues: (args, context) => `crypto.getRandomValues(${generateExpr(args[0], context)})`,
|
|
2576
2585
|
cryptoSubtleDigest: (args, context) => `crypto.subtle.digest(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
@@ -2585,13 +2594,13 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2585
2594
|
cryptoSubtleWrapKey: (args, context) => `crypto.subtle.wrapKey(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2586
2595
|
cryptoSubtleUnwrapKey: (args, context) => `crypto.subtle.unwrapKey(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2587
2596
|
|
|
2588
|
-
// ── v2.2.0
|
|
2597
|
+
// ── v2.2.0 - WeakMap / WeakSet / WeakRef / FinalizationRegistry (IOPL-native).
|
|
2589
2598
|
weakMap: (_args) => `new WeakMap()`,
|
|
2590
2599
|
weakSet: (_args) => `new WeakSet()`,
|
|
2591
2600
|
weakRef: (args, context) => `new WeakRef(${generateExpr(args[0], context)})`,
|
|
2592
2601
|
finalizationRegistry: (args, context) => `new FinalizationRegistry(${generateExpr(args[0], context)})`,
|
|
2593
2602
|
|
|
2594
|
-
// ── v2.2.0
|
|
2603
|
+
// ── v2.2.0 - Proxy / Reflect (IOPL-native).
|
|
2595
2604
|
proxy: (args, context) => `new Proxy(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
2596
2605
|
reflectGet: (args, context) => `Reflect.get(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
2597
2606
|
reflectSet: (args, context) => `Reflect.set(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)}, ${generateExpr(args[2], context)})`,
|
|
@@ -2603,7 +2612,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2603
2612
|
reflectDefineProperty: (args, context) => `Reflect.defineProperty(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2604
2613
|
reflectGetOwnPropertyDescriptor: (args, context) => `Reflect.getOwnPropertyDescriptor(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
2605
2614
|
|
|
2606
|
-
// ── v2.2.0
|
|
2615
|
+
// ── v2.2.0 - Symbol (IOPL-native).
|
|
2607
2616
|
symbol: (args, context) => `Symbol(${args.length ? generateExpr(args[0], context) : 'undefined'})`,
|
|
2608
2617
|
symbolFor: (args, context) => `Symbol.for(${generateExpr(args[0], context)})`,
|
|
2609
2618
|
symbolKeyFor: (args, context) => `Symbol.keyFor(${generateExpr(args[0], context)})`,
|
|
@@ -2620,12 +2629,12 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2620
2629
|
symbolToPrimitive: (_args) => `Symbol.toPrimitive`,
|
|
2621
2630
|
symbolUnscopables: (_args) => `Symbol.unscopables`,
|
|
2622
2631
|
|
|
2623
|
-
// ── v2.2.0
|
|
2632
|
+
// ── v2.2.0 - BigInt (IOPL-native).
|
|
2624
2633
|
bigInt: (args, context) => `BigInt(${generateExpr(args[0], context)})`,
|
|
2625
2634
|
bigIntAsIntN: (args, context) => `BigInt.asIntN(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
2626
2635
|
bigIntAsUintN: (args, context) => `BigInt.asUintN(${generateExpr(args[0], context)}, ${generateExpr(args[1], context)})`,
|
|
2627
2636
|
|
|
2628
|
-
// ── v2.2.0
|
|
2637
|
+
// ── v2.2.0 - Atomics / SharedArrayBuffer (IOPL-native).
|
|
2629
2638
|
atomicsAdd: (args, context) => `Atomics.add(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2630
2639
|
atomicsSub: (args, context) => `Atomics.sub(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2631
2640
|
atomicsAnd: (args, context) => `Atomics.and(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
@@ -2640,7 +2649,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2640
2649
|
atomicsIsLockFree: (args, context) => `Atomics.isLockFree(${generateExpr(args[0], context)})`,
|
|
2641
2650
|
sharedArrayBuffer: (args, context) => `new SharedArrayBuffer(${generateExpr(args[0], context)})`,
|
|
2642
2651
|
|
|
2643
|
-
// ── v2.2.0
|
|
2652
|
+
// ── v2.2.0 - Error subclasses (IOPL-native).
|
|
2644
2653
|
error: (args, context) => `new Error(${args.length ? generateExpr(args[0], context) : ''})`,
|
|
2645
2654
|
typeError: (args, context) => `new TypeError(${args.length ? generateExpr(args[0], context) : ''})`,
|
|
2646
2655
|
rangeError: (args, context) => `new RangeError(${args.length ? generateExpr(args[0], context) : ''})`,
|
|
@@ -2650,12 +2659,12 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2650
2659
|
uriError: (args, context) => `new URIError(${args.length ? generateExpr(args[0], context) : ''})`,
|
|
2651
2660
|
aggregateError: (args, context) => `new AggregateError(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2652
2661
|
|
|
2653
|
-
// ── v2.2.0
|
|
2662
|
+
// ── v2.2.0 - Blob / File / FormData (IOPL-native, browser-compatible).
|
|
2654
2663
|
blob: (args, context) => `new Blob(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2655
2664
|
file: (args, context) => `new File(${args.map(a => generateExpr(a, context)).join(', ')})`,
|
|
2656
2665
|
formData: (_args) => `new FormData()`,
|
|
2657
2666
|
|
|
2658
|
-
// ── v1.0.
|
|
2667
|
+
// ── v1.0.361 - browser DOM (IOPL-native). All helpers guard their browser
|
|
2659
2668
|
// global, so the generated output throws a clear teaching error under Node.
|
|
2660
2669
|
select: (args, context) => {
|
|
2661
2670
|
ensureBuiltin(context, 'dom');
|
|
@@ -2673,7 +2682,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2673
2682
|
return `__parseHTML(${generateExpr(args[0], context)})`;
|
|
2674
2683
|
},
|
|
2675
2684
|
|
|
2676
|
-
// ── v1.0.
|
|
2685
|
+
// ── v1.0.361 - browser input (IOPL-native).
|
|
2677
2686
|
localPoint: (args, context) => {
|
|
2678
2687
|
ensureBuiltin(context, 'input');
|
|
2679
2688
|
requireArgs('localPoint', args, 2, 'localPoint(event, canvas)');
|
|
@@ -2689,7 +2698,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2689
2698
|
return `__droppedFiles(${generateExpr(args[0], context)})`;
|
|
2690
2699
|
},
|
|
2691
2700
|
|
|
2692
|
-
// ── v1.0.
|
|
2701
|
+
// ── v1.0.361 - browser assets (IOPL-native). Each awaitable helper is
|
|
2693
2702
|
// awaited here, so the surrounding function/handler is marked async.
|
|
2694
2703
|
loadImage: (args, context) => {
|
|
2695
2704
|
ensureBuiltin(context, 'assets');
|
|
@@ -2722,7 +2731,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2722
2731
|
return `(await __readDataUrl(${generateExpr(args[0], context)}))`;
|
|
2723
2732
|
},
|
|
2724
2733
|
|
|
2725
|
-
// ── v1.0.
|
|
2734
|
+
// ── v1.0.361 - Web Audio (IOPL-native).
|
|
2726
2735
|
audioContext: (_args, context) => {
|
|
2727
2736
|
ensureBuiltin(context, 'audio');
|
|
2728
2737
|
return `__audioContext()`;
|
|
@@ -2733,7 +2742,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2733
2742
|
return `__audioTone(${args.map(a => generateExpr(a, context)).join(', ')})`;
|
|
2734
2743
|
},
|
|
2735
2744
|
|
|
2736
|
-
// ── v1.0.
|
|
2745
|
+
// ── v1.0.361 - WebSocket send helper (works with any WebSocket-like object,
|
|
2737
2746
|
// browser or Node): strings go through verbatim, everything else is JSON.
|
|
2738
2747
|
webSocketSend: (args, context) => {
|
|
2739
2748
|
requireArgs('webSocketSend', args, 2, 'webSocketSend(socket, { type: "move", x: 10 })');
|
|
@@ -2742,7 +2751,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2742
2751
|
return `${ws}.send(typeof (${value}) === 'string' ? (${value}) : JSON.stringify(${value}))`;
|
|
2743
2752
|
},
|
|
2744
2753
|
|
|
2745
|
-
// ── v1.0.
|
|
2754
|
+
// ── v1.0.361 - WebGL (IOPL-native).
|
|
2746
2755
|
webglContext: (args, context) => {
|
|
2747
2756
|
ensureBuiltin(context, 'gl');
|
|
2748
2757
|
requireOneArg('webglContext', args);
|
|
@@ -2769,7 +2778,7 @@ const BUILTIN_DECLARATIONS = {
|
|
|
2769
2778
|
// record that this scope emitted an `await` so handler and function bodies can
|
|
2770
2779
|
// decide their own async-ness at generation time (see generateBlock). Routing
|
|
2771
2780
|
// every await-emitting construct through this single function removes the need
|
|
2772
|
-
// for a separate hand-maintained registry of async statement types
|
|
2781
|
+
// for a separate hand-maintained registry of async statement types - so a new
|
|
2773
2782
|
// async keyword can never silently break when used inside a route, listener, or
|
|
2774
2783
|
// function.
|
|
2775
2784
|
function markAsync(context) {
|
|
@@ -2777,7 +2786,7 @@ function markAsync(context) {
|
|
|
2777
2786
|
// Only a construct that awaits at the true top level needs the program
|
|
2778
2787
|
// wrapped in an async IIFE. Awaits emitted inside a user function (inFunction)
|
|
2779
2788
|
// or inside a route/listener/404 handler (inHandler) are handled by marking
|
|
2780
|
-
// that function/handler async instead
|
|
2789
|
+
// that function/handler async instead - they must not drag the whole program
|
|
2781
2790
|
// into an async wrapper, or "top-level use wraps the whole program" would be
|
|
2782
2791
|
// the only safe nesting level for a new async keyword.
|
|
2783
2792
|
if (!context.inFunction && !context.inHandler) context.needsAsync = true;
|
|
@@ -2788,7 +2797,7 @@ function markAsync(context) {
|
|
|
2788
2797
|
// This is the single source of truth for whether a route handler, listener,
|
|
2789
2798
|
// 404 handler, or user function must be declared `async`. Previously this was
|
|
2790
2799
|
// decided by a separate AST walker (containsAsyncBlock) that had to be kept in
|
|
2791
|
-
// sync by hand with every construct that compiles down to `await`
|
|
2800
|
+
// sync by hand with every construct that compiles down to `await` - the exact
|
|
2792
2801
|
// fragility that made "top-level use wraps the whole program" the only place
|
|
2793
2802
|
// certain keywords (like ocr) were guaranteed to work. By observing the output
|
|
2794
2803
|
// of generation instead, whatever a body contains is handled correctly, even if
|
|
@@ -2802,7 +2811,7 @@ function generateBlock(statements, indent, context) {
|
|
|
2802
2811
|
return { out, emitted };
|
|
2803
2812
|
}
|
|
2804
2813
|
|
|
2805
|
-
// v2.1.0
|
|
2814
|
+
// v2.1.0 - generate a request accessor (param/query/header). These compile to
|
|
2806
2815
|
// direct Express req.<bucket>[key] reads and are rejected outside routes so
|
|
2807
2816
|
// mistakes surface at compile time with a teaching error.
|
|
2808
2817
|
function routeAccessor(name, bucket, args, context) {
|
|
@@ -2817,7 +2826,7 @@ function routeAccessor(name, bucket, args, context) {
|
|
|
2817
2826
|
return `req.${bucket}[${generateExpr(args[0], context)}]`;
|
|
2818
2827
|
}
|
|
2819
2828
|
|
|
2820
|
-
// v2.1.1
|
|
2829
|
+
// v2.1.1 - compile-time guard shared by request-scoped accessors that do not
|
|
2821
2830
|
// follow the req.<bucket> shape (upload/uploads/cookie).
|
|
2822
2831
|
function routeOnly(name, example) {
|
|
2823
2832
|
if (!_inRoute) {
|
|
@@ -2847,15 +2856,15 @@ let _inRoute = false;
|
|
|
2847
2856
|
// True while generating inside a Telegram handler body. Remaps PlainScript's
|
|
2848
2857
|
// "reply" statement to send a chat message instead of an HTTP response.
|
|
2849
2858
|
let _inTelegram = false;
|
|
2850
|
-
// v2.1.1
|
|
2859
|
+
// v2.1.1 - true while generating inside a WhatsApp "on message" handler.
|
|
2851
2860
|
// Remaps PlainScript's "reply" to a WhatsApp chat message and PlainScript's "message"
|
|
2852
2861
|
// identifier to the normalized message record of the current delivery.
|
|
2853
2862
|
let _inWhatsApp = false;
|
|
2854
|
-
// v2.1.0
|
|
2863
|
+
// v2.1.0 - active "group" prefixes. Route paths are prefixed with the
|
|
2855
2864
|
// concatenation of every enclosing group, innermost last.
|
|
2856
2865
|
const _routePrefixes = [];
|
|
2857
2866
|
|
|
2858
|
-
// v2.1.0
|
|
2867
|
+
// v2.1.0 - active SQL driver. "sqlite" (default) targets better-sqlite3's
|
|
2859
2868
|
// synchronous prepare/run/exec API; "pg" targets node-postgres pools and
|
|
2860
2869
|
// makes every SQL statement async. Set by database/postgres declarations.
|
|
2861
2870
|
let _sqlDriver = 'sqlite';
|
|
@@ -2868,7 +2877,7 @@ function routePath(path) {
|
|
|
2868
2877
|
return _routePrefixes.join('') + path;
|
|
2869
2878
|
}
|
|
2870
2879
|
|
|
2871
|
-
// v2.1.0
|
|
2880
|
+
// v2.1.0 - render the JavaScript expression that executes one SQL statement
|
|
2872
2881
|
// under the active driver. kind: query | write | execute.
|
|
2873
2882
|
function emitSqlCall(kind, sql, params, indent, context) {
|
|
2874
2883
|
const args = params.join(', ');
|
|
@@ -2935,7 +2944,7 @@ function npmPackageName(moduleName) {
|
|
|
2935
2944
|
|
|
2936
2945
|
function emitRequire(context, moduleName, alias) {
|
|
2937
2946
|
// A specifier may carry a version range ("left-pad@^1.3.0"). require() takes
|
|
2938
|
-
// the bare name only
|
|
2947
|
+
// the bare name only - the range is the installer's business (plain install).
|
|
2939
2948
|
const { name: bareName } = splitPackageSpec(moduleName);
|
|
2940
2949
|
const npmName = npmPackageName(bareName);
|
|
2941
2950
|
|
|
@@ -2965,7 +2974,7 @@ function emitRequire(context, moduleName, alias) {
|
|
|
2965
2974
|
|
|
2966
2975
|
if (KNOWN_PACKAGES[bareName]) return KNOWN_PACKAGES[bareName];
|
|
2967
2976
|
|
|
2968
|
-
// RFC-0011 §5.1
|
|
2977
|
+
// RFC-0011 §5.1 - arbitrary npm packages. A name that is not a valid JS
|
|
2969
2978
|
// identifier (e.g. node-fetch) is required for its side effect only.
|
|
2970
2979
|
if (isValidIdentifier(bareName)) {
|
|
2971
2980
|
return `const ${bareName} = require('${npmName}');`;
|
|
@@ -3022,7 +3031,7 @@ function generate(ast, contextOrOptions = createGenerationContext(), options = {
|
|
|
3022
3031
|
context = createGenerationContext(opts);
|
|
3023
3032
|
}
|
|
3024
3033
|
|
|
3025
|
-
// v1.0.1
|
|
3034
|
+
// v1.0.1 - reset per-program test bookkeeping so repeated generate() calls
|
|
3026
3035
|
// (build pipeline) start clean.
|
|
3027
3036
|
__testCount = 0;
|
|
3028
3037
|
__testCatchers = [];
|
|
@@ -3063,7 +3072,7 @@ function generate(ast, contextOrOptions = createGenerationContext(), options = {
|
|
|
3063
3072
|
lines.push(`if (typeof module !== 'undefined') { module.exports = { ${exported.join(', ')} }; }`);
|
|
3064
3073
|
}
|
|
3065
3074
|
|
|
3066
|
-
// v1.0.1
|
|
3075
|
+
// v1.0.1 - native test runner. When any "test ... done" block exists, emit
|
|
3067
3076
|
// the runner helper, register each test after its function declaration, and
|
|
3068
3077
|
// execute them. Each failure prints a message and sets process.exitCode = 1.
|
|
3069
3078
|
if (__testCatchers.length > 0) {
|
|
@@ -3071,7 +3080,7 @@ function generate(ast, contextOrOptions = createGenerationContext(), options = {
|
|
|
3071
3080
|
`const __tests = [];`,
|
|
3072
3081
|
`function __check(op, a, b) {`,
|
|
3073
3082
|
` const ok = op === 'contains'`,
|
|
3074
|
-
` ? String(a).includes(String(b))`,
|
|
3083
|
+
` ? (a instanceof Set ? a.has(b) : String(a).includes(String(b)))`,
|
|
3075
3084
|
` : op === 'is'`,
|
|
3076
3085
|
` ? a === b`,
|
|
3077
3086
|
` : op === 'raises'`,
|
|
@@ -3107,7 +3116,7 @@ function generate(ast, contextOrOptions = createGenerationContext(), options = {
|
|
|
3107
3116
|
return jsCode;
|
|
3108
3117
|
}
|
|
3109
3118
|
|
|
3110
|
-
// ── v1.0.1
|
|
3119
|
+
// ── v1.0.1 - test DSL bookkeeping ───────────────────────────────────────────
|
|
3111
3120
|
let __testCount = 0;
|
|
3112
3121
|
let __testCatchers = [];
|
|
3113
3122
|
let __inTest = false;
|
|
@@ -3120,8 +3129,14 @@ function generateCondition(cond, context) {
|
|
|
3120
3129
|
return `${generateExpr(cond.left, context)} ${cond.op} ${generateExpr(cond.right, context)}`;
|
|
3121
3130
|
|
|
3122
3131
|
case 'UnaryCondition':
|
|
3123
|
-
if (cond.op === 'isEmpty')
|
|
3124
|
-
|
|
3132
|
+
if (cond.op === 'isEmpty') {
|
|
3133
|
+
const expr = generateExpr(cond.left, context);
|
|
3134
|
+
return `(${expr} instanceof Map || ${expr} instanceof Set ? ${expr}.size === 0 : (typeof ${expr} === 'object' && ${expr} !== null ? Object.keys(${expr}).length === 0 : (${expr}).length === 0))`;
|
|
3135
|
+
}
|
|
3136
|
+
if (cond.op === 'isNotEmpty') {
|
|
3137
|
+
const expr = generateExpr(cond.left, context);
|
|
3138
|
+
return `(${expr} instanceof Map || ${expr} instanceof Set ? ${expr}.size > 0 : (typeof ${expr} === 'object' && ${expr} !== null ? Object.keys(${expr}).length > 0 : (${expr}).length > 0))`;
|
|
3139
|
+
}
|
|
3125
3140
|
throw new Error(`Unknown unary condition op "${cond.op}".`);
|
|
3126
3141
|
|
|
3127
3142
|
case 'BetweenCondition': {
|
|
@@ -3129,14 +3144,49 @@ function generateCondition(cond, context) {
|
|
|
3129
3144
|
return `${expr} >= ${generateExpr(cond.low, context)} && ${expr} <= ${generateExpr(cond.high, context)}`;
|
|
3130
3145
|
}
|
|
3131
3146
|
|
|
3132
|
-
case '
|
|
3133
|
-
|
|
3147
|
+
case 'InCondition': {
|
|
3148
|
+
const right = generateExpr(cond.right, context);
|
|
3149
|
+
const left = generateExpr(cond.left, context);
|
|
3150
|
+
return `(${right} instanceof Set ? ${right}.has(${left}) : (${right}).includes(${left}))`;
|
|
3151
|
+
}
|
|
3152
|
+
|
|
3153
|
+
case 'NotInCondition': {
|
|
3154
|
+
const right = generateExpr(cond.right, context);
|
|
3155
|
+
const left = generateExpr(cond.left, context);
|
|
3156
|
+
return `!(${right} instanceof Set ? ${right}.has(${left}) : (${right}).includes(${left}))`;
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3159
|
+
case 'StringCondition': {
|
|
3160
|
+
const left = generateExpr(cond.left, context);
|
|
3161
|
+
const right = generateExpr(cond.right, context);
|
|
3162
|
+
if (cond.method === 'includes') {
|
|
3163
|
+
return `(${left} instanceof Set ? ${left}.has(${right}) : (${left}).includes(${right}))`;
|
|
3164
|
+
}
|
|
3165
|
+
return `(${left}).${cond.method}(${right})`;
|
|
3166
|
+
}
|
|
3134
3167
|
|
|
3135
|
-
// v2.1.1
|
|
3168
|
+
// v2.1.1 - and / or / not combinators. The Boolean combinators operate on
|
|
3169
|
+
// the same LogicalCondition nodes at both the condition level and the
|
|
3170
|
+
// expression level, so an operand may be either a pure condition node
|
|
3171
|
+
// (comparison) or an arbitrary value expression (`f()`, a collection, a
|
|
3172
|
+
// number, a `set with ...` literal). Pure conditions recurse through the
|
|
3173
|
+
// condition generator; everything else is emitted as a general expression.
|
|
3136
3174
|
case 'LogicalCondition': {
|
|
3137
|
-
|
|
3175
|
+
const CONDITION_TYPES = [
|
|
3176
|
+
'BinaryCondition',
|
|
3177
|
+
'UnaryCondition',
|
|
3178
|
+
'BetweenCondition',
|
|
3179
|
+
'StringCondition',
|
|
3180
|
+
'InCondition',
|
|
3181
|
+
'NotInCondition',
|
|
3182
|
+
'LogicalCondition',
|
|
3183
|
+
];
|
|
3184
|
+
const emit = (n) => CONDITION_TYPES.includes(n.type)
|
|
3185
|
+
? generateCondition(n, context)
|
|
3186
|
+
: generateExpr(n, context);
|
|
3187
|
+
if (cond.op === 'not') return `!(${emit(cond.operand)})`;
|
|
3138
3188
|
const jsOp = cond.op === 'and' ? '&&' : '||';
|
|
3139
|
-
return `${
|
|
3189
|
+
return `${emit(cond.left)} ${jsOp} ${emit(cond.right)}`;
|
|
3140
3190
|
}
|
|
3141
3191
|
|
|
3142
3192
|
default:
|
|
@@ -3163,7 +3213,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3163
3213
|
return `${indent}console.log(${generateExpr(node.value, context)});`;
|
|
3164
3214
|
|
|
3165
3215
|
case 'GiveStatement':
|
|
3166
|
-
return `${indent}return
|
|
3216
|
+
return `${indent}return${node.value ? ' ' + generateExpr(node.value, context) : ''};`;
|
|
3167
3217
|
|
|
3168
3218
|
case 'BecomeStatement': {
|
|
3169
3219
|
// Handle destructuring: [a, b] = arr / {x, y} = obj
|
|
@@ -3190,11 +3240,11 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3190
3240
|
return `${indent}${target} ${op} ${value};`;
|
|
3191
3241
|
}
|
|
3192
3242
|
|
|
3193
|
-
// v1.0.1
|
|
3243
|
+
// v1.0.1 - record kinds: `define a kind called "Person" with ... done`.
|
|
3194
3244
|
// Names are emitted as a JS factory that returns a fresh plain object with
|
|
3195
3245
|
// declared defaults. Constructors prompt for required fields at compile
|
|
3196
3246
|
// time via `create a Person with ...` (see GenerateExpr CreateKind).
|
|
3197
|
-
// v1.0.2
|
|
3247
|
+
// v1.0.2 - supports `extends` for inheritance.
|
|
3198
3248
|
case 'DefineKindStatement': {
|
|
3199
3249
|
let defaults = '';
|
|
3200
3250
|
if (node.extends) {
|
|
@@ -3223,14 +3273,14 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3223
3273
|
].join('\n');
|
|
3224
3274
|
}
|
|
3225
3275
|
|
|
3226
|
-
// v1.0.1
|
|
3276
|
+
// v1.0.1 - load env file "<path>": apply KEY=VALUE pairs to process.env.
|
|
3227
3277
|
// Blank lines and `#` comments are skipped; values keep their text.
|
|
3228
3278
|
case 'LoadEnvFileStatement': {
|
|
3229
3279
|
ensureBuiltin(context, 'dotenv');
|
|
3230
3280
|
return `${indent}__loadEnvFile(${JSON.stringify(node.path)});`;
|
|
3231
3281
|
}
|
|
3232
3282
|
|
|
3233
|
-
// v1.0.1
|
|
3283
|
+
// v1.0.1 - native test DSL. `test "<name>" ... done` registers a runnable
|
|
3234
3284
|
// unit; all tests are executed after the program body with a tiny runner.
|
|
3235
3285
|
case 'TestStatement': {
|
|
3236
3286
|
__testCount++;
|
|
@@ -3243,7 +3293,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3243
3293
|
return `${indent}function ${fnName}() {\n${body}\n${indent}}`;
|
|
3244
3294
|
}
|
|
3245
3295
|
|
|
3246
|
-
// v1.0.1
|
|
3296
|
+
// v1.0.1 - assertion `check <a> (equals|is|contains|raises) <b>`.
|
|
3247
3297
|
// For `raises`, `a` is wrapped in a thunk so the expression is evaluated
|
|
3248
3298
|
// inside the runner's try/catch (its thrown error is the subject).
|
|
3249
3299
|
case 'CheckStatement': {
|
|
@@ -3271,7 +3321,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3271
3321
|
return exports.map(e => `${indent}${e}`).join('\n');
|
|
3272
3322
|
}
|
|
3273
3323
|
|
|
3274
|
-
// v1.0.1
|
|
3324
|
+
// v1.0.1 - generators: `yield <expr>` (or bare `yield`).
|
|
3275
3325
|
case 'YieldStatement': {
|
|
3276
3326
|
if (!context.inFunction) {
|
|
3277
3327
|
throw new Error('"yield" can only be used inside a function created with "make".\n\nExample:\n make countUp(n)\n let i = 0\n while i less than n\n i = i + 1\n yield i\n done\n done');
|
|
@@ -3342,7 +3392,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3342
3392
|
return `${indent}let ${node.variable} = await __ask(${prompt});`;
|
|
3343
3393
|
}
|
|
3344
3394
|
|
|
3345
|
-
// v2.0.1
|
|
3395
|
+
// v2.0.1 - ocr "<image>" as <variable> [using "<lang>"]
|
|
3346
3396
|
case 'OcrStatement': {
|
|
3347
3397
|
ensureBuiltin(context, 'ocr');
|
|
3348
3398
|
markAsync(context);
|
|
@@ -3394,6 +3444,15 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3394
3444
|
return out;
|
|
3395
3445
|
}
|
|
3396
3446
|
|
|
3447
|
+
case 'RepeatTimesStatement': {
|
|
3448
|
+
context.loopDepth++;
|
|
3449
|
+
const body = node.body.map(s => generateStatement(s, indent + ' ', context)).join('\n');
|
|
3450
|
+
context.loopDepth--;
|
|
3451
|
+
const count = generateExpr(node.count, context);
|
|
3452
|
+
const idxVar = `__repeat_i_${context.loopDepth + 1}`;
|
|
3453
|
+
return `${indent}for (let ${idxVar} = 0; ${idxVar} < ${count}; ${idxVar}++) {\n${body}\n${indent}}`;
|
|
3454
|
+
}
|
|
3455
|
+
|
|
3397
3456
|
case 'ForEachStatement': {
|
|
3398
3457
|
context.loopDepth++;
|
|
3399
3458
|
const body = node.body.map(s => generateStatement(s, indent + ' ', context)).join('\n');
|
|
@@ -3405,7 +3464,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3405
3464
|
context.loopDepth++;
|
|
3406
3465
|
const body = node.body.map(s => generateStatement(s, indent + ' ', context)).join('\n');
|
|
3407
3466
|
context.loopDepth--;
|
|
3408
|
-
// for index <name> in <collection>
|
|
3467
|
+
// for index <name> in <collection> - zero-based index over a list.
|
|
3409
3468
|
if (node.over != null) {
|
|
3410
3469
|
const coll = generateExpr(node.over, context);
|
|
3411
3470
|
return `${indent}for (let ${node.name} = 0; ${node.name} < ${coll}.length; ${node.name}++) {\n${body}\n${indent}}`;
|
|
@@ -3489,7 +3548,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3489
3548
|
return `${indent}class ${node.name}${superClass} {\n${body}\n${indent}}`;
|
|
3490
3549
|
}
|
|
3491
3550
|
|
|
3492
|
-
// v0.3
|
|
3551
|
+
// v0.3 - Express runtime
|
|
3493
3552
|
|
|
3494
3553
|
case 'ListenStatement': {
|
|
3495
3554
|
const prevInHandler = context.inHandler;
|
|
@@ -3546,7 +3605,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3546
3605
|
return `${indent}res.json({ ${props} });`;
|
|
3547
3606
|
}
|
|
3548
3607
|
|
|
3549
|
-
// v1.2
|
|
3608
|
+
// v1.2 - reply <value> with buttons … done (Telegram inline keyboard).
|
|
3550
3609
|
// The AST stores rows of { text, data } objects (parser.js). The Telegram
|
|
3551
3610
|
// runtime's keyboard() expects a flat list of [text, data] pairs, so each
|
|
3552
3611
|
// button is rendered as [text, data] and rows are merged into that list.
|
|
@@ -3560,13 +3619,13 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3560
3619
|
case 'ServeFolderStatement':
|
|
3561
3620
|
return `${indent}app.use(express.static(${JSON.stringify(node.folder)}));`;
|
|
3562
3621
|
|
|
3563
|
-
// v0.6
|
|
3622
|
+
// v0.6 - Express DX
|
|
3564
3623
|
|
|
3565
3624
|
case 'WebAppStatement':
|
|
3566
3625
|
return [
|
|
3567
3626
|
emitRequire(context, 'express'),
|
|
3568
3627
|
`${indent}const app = express();`,
|
|
3569
|
-
// v2.1.0
|
|
3628
|
+
// v2.1.0 - parse JSON request bodies so POST/PUT handlers can read
|
|
3570
3629
|
// "body of request". Harmless for GET-only v2.0.1 programs.
|
|
3571
3630
|
`${indent}app.use(express.json());`,
|
|
3572
3631
|
]
|
|
@@ -3583,7 +3642,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3583
3642
|
return `${indent}app.${node.method}(${JSON.stringify(routePath(node.path))}, ${handlerAsync}(req, res) => {\n${block.out}\n${indent}});`;
|
|
3584
3643
|
}
|
|
3585
3644
|
|
|
3586
|
-
// v2.1.0
|
|
3645
|
+
// v2.1.0 - group "<prefix>" ... done: composes routes under a shared
|
|
3587
3646
|
// prefix. Groups nest; every enclosed route (either form) gets the
|
|
3588
3647
|
// concatenated prefix. Non-route statements run in program order.
|
|
3589
3648
|
case 'GroupStatement': {
|
|
@@ -3593,7 +3652,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3593
3652
|
return body;
|
|
3594
3653
|
}
|
|
3595
3654
|
|
|
3596
|
-
// v2.1.0
|
|
3655
|
+
// v2.1.0 - status <expr>: sets the HTTP response status code. Only valid
|
|
3597
3656
|
// inside a route handler (res is in scope there).
|
|
3598
3657
|
case 'StatusStatement':
|
|
3599
3658
|
if (!_inRoute) {
|
|
@@ -3601,14 +3660,14 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3601
3660
|
}
|
|
3602
3661
|
return `${indent}res.status(${generateExpr(node.value, context)});`;
|
|
3603
3662
|
|
|
3604
|
-
// v2.2.0
|
|
3663
|
+
// v2.2.0 - redirect to "<url>": sends an HTTP redirect from a route.
|
|
3605
3664
|
case 'RedirectStatement':
|
|
3606
3665
|
if (!_inRoute) {
|
|
3607
3666
|
throw new Error('"redirect to" can only be used inside a route handler.\n\nExample:\n route get "/old"\n redirect to "/new"\n done');
|
|
3608
3667
|
}
|
|
3609
3668
|
return `${indent}res.redirect(${generateExpr(node.url, context)});`;
|
|
3610
3669
|
|
|
3611
|
-
// v2.1.0
|
|
3670
|
+
// v2.1.0 - allow cors: enables cross-origin requests on the current app.
|
|
3612
3671
|
// Applies to routes registered after this statement.
|
|
3613
3672
|
case 'AllowCorsStatement':
|
|
3614
3673
|
return [
|
|
@@ -3621,7 +3680,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3621
3680
|
`${indent}});`,
|
|
3622
3681
|
].join('\n');
|
|
3623
3682
|
|
|
3624
|
-
// ── v2.1.1
|
|
3683
|
+
// ── v2.1.1 - uploads, auth middleware, rate limiting, OAuth ────────────
|
|
3625
3684
|
// These register Express middleware in program order; routes declared
|
|
3626
3685
|
// after them are protected / wired accordingly.
|
|
3627
3686
|
|
|
@@ -3634,7 +3693,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3634
3693
|
return `${indent}app.use(__uploads({ ${options.join(', ')} }));`;
|
|
3635
3694
|
}
|
|
3636
3695
|
|
|
3637
|
-
// require api key from <expr>
|
|
3696
|
+
// require api key from <expr> - rejects requests whose x-api-key header
|
|
3638
3697
|
// does not match. The expected key may come from env("...") or anywhere.
|
|
3639
3698
|
case 'RequireApiKeyStatement':
|
|
3640
3699
|
return [
|
|
@@ -3676,7 +3735,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3676
3735
|
return `${indent}__googleOAuth(app, { ${parts} });`;
|
|
3677
3736
|
}
|
|
3678
3737
|
|
|
3679
|
-
// ── v2.1.1
|
|
3738
|
+
// ── v2.1.1 - route-scoped state: cookies and sessions
|
|
3680
3739
|
|
|
3681
3740
|
case 'DestroySessionStatement':
|
|
3682
3741
|
if (!_inRoute) {
|
|
@@ -3702,7 +3761,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3702
3761
|
}
|
|
3703
3762
|
return `${indent}res.clearCookie(${JSON.stringify(node.name)}, { path: '/' });`;
|
|
3704
3763
|
|
|
3705
|
-
// when nothing matches … done
|
|
3764
|
+
// when nothing matches … done - the 404 catch-all. Registered in source
|
|
3706
3765
|
// position, so it must come after every route (Express matches handlers
|
|
3707
3766
|
// in registration order).
|
|
3708
3767
|
case 'NotFoundStatement': {
|
|
@@ -3716,7 +3775,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3716
3775
|
return `${indent}app.use((${handlerAsync}req, res) => {\n${block.out}\n${indent}});`;
|
|
3717
3776
|
}
|
|
3718
3777
|
|
|
3719
|
-
// ── v2.1.1
|
|
3778
|
+
// ── v2.1.1 - error handling and retries
|
|
3720
3779
|
|
|
3721
3780
|
case 'TryStatement': {
|
|
3722
3781
|
const tryBody = (node.tryBody || node.body || []).map(s => generateStatement(s, indent + ' ', context)).join('\n');
|
|
@@ -3788,11 +3847,11 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3788
3847
|
case 'StartStatement':
|
|
3789
3848
|
return `${indent}app.listen(${generateExpr(node.port, context)});`;
|
|
3790
3849
|
|
|
3791
|
-
// v0.6
|
|
3850
|
+
// v0.6 - SQLite DX. v2.1.0 adds parameterized SQL, captured results and
|
|
3792
3851
|
// transactions; the driver switches to PostgreSQL when a "postgres"
|
|
3793
3852
|
// declaration is active.
|
|
3794
3853
|
|
|
3795
|
-
// database "<file>" [using "<driver>"]
|
|
3854
|
+
// database "<file>" [using "<driver>"] - v2.1.1 opens through the
|
|
3796
3855
|
// portable engine chain: better-sqlite3 when its native binding works on
|
|
3797
3856
|
// this machine, sql.js otherwise ("using" forces one engine). The opened
|
|
3798
3857
|
// handle exposes the same prepare/exec/transaction surface either way,
|
|
@@ -3806,7 +3865,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3806
3865
|
return `${indent}const db = await __dbOpen(${JSON.stringify(node.file)}, ${driverArg});`;
|
|
3807
3866
|
}
|
|
3808
3867
|
|
|
3809
|
-
// v2.1.0
|
|
3868
|
+
// v2.1.0 - postgres "<connection>": node-postgres pool bound to "db".
|
|
3810
3869
|
// Every SQL statement afterwards compiles to async pool queries.
|
|
3811
3870
|
case 'PostgresStatement': {
|
|
3812
3871
|
_sqlDriver = 'pg';
|
|
@@ -3818,7 +3877,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3818
3877
|
].filter(Boolean).map(line => line.startsWith('const ') ? `${indent}${line}` : line).join('\n');
|
|
3819
3878
|
}
|
|
3820
3879
|
|
|
3821
|
-
// v2.2.0
|
|
3880
|
+
// v2.2.0 - mongo "<connection>" [db "<name>"]: MongoDB client bound to "db".
|
|
3822
3881
|
// Uses the mongodb driver; subsequent query/insert/update/delete/execute
|
|
3823
3882
|
// statements compile to MongoDB collection operations.
|
|
3824
3883
|
case 'MongoStatement': {
|
|
@@ -3846,7 +3905,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3846
3905
|
case 'ExecuteStatement':
|
|
3847
3906
|
return `${indent}${emitSqlCall('execute', node.sql, node.params, indent, context)};`;
|
|
3848
3907
|
|
|
3849
|
-
// v2.1.0
|
|
3908
|
+
// v2.1.0 - remember <name> as query|insert|update|delete … done
|
|
3850
3909
|
case 'RememberSqlStatement': {
|
|
3851
3910
|
const kind = node.kind === 'query' ? 'query'
|
|
3852
3911
|
: node.kind === 'execute' ? 'execute'
|
|
@@ -3856,7 +3915,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3856
3915
|
return `${indent}let ${node.name} = ${emitSqlCall(kind, node.sql, node.params, indent, context)};`;
|
|
3857
3916
|
}
|
|
3858
3917
|
|
|
3859
|
-
// v2.1.0
|
|
3918
|
+
// v2.1.0 - transaction … done: all enclosed database statements run
|
|
3860
3919
|
// atomically (all succeed or none are applied).
|
|
3861
3920
|
case 'TransactionStatement': {
|
|
3862
3921
|
if (_sqlDriver === 'pg') {
|
|
@@ -3891,7 +3950,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3891
3950
|
].join('\n');
|
|
3892
3951
|
}
|
|
3893
3952
|
|
|
3894
|
-
// v1.2
|
|
3953
|
+
// v1.2 - Telegram statements
|
|
3895
3954
|
|
|
3896
3955
|
case 'TelegramCommandStatement': {
|
|
3897
3956
|
ensureBuiltin(context, 'telegram');
|
|
@@ -3920,18 +3979,18 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3920
3979
|
return `${indent}await BOT.start();`;
|
|
3921
3980
|
}
|
|
3922
3981
|
|
|
3923
|
-
// ── v2.1.1
|
|
3982
|
+
// ── v2.1.1 - WhatsApp statements ────────────────────────────────────────
|
|
3924
3983
|
|
|
3925
|
-
// whatsapp bot … done
|
|
3984
|
+
// whatsapp bot … done - starts the Baileys runtime with the declared
|
|
3926
3985
|
// auth folder and login mode, then registers every "on message" handler.
|
|
3927
3986
|
// When no login line is present (login is null), only registers handlers
|
|
3928
|
-
// without auto-starting
|
|
3987
|
+
// without auto-starting - used by hybrid bots that pair on-demand.
|
|
3929
3988
|
case 'WhatsAppBotStatement': {
|
|
3930
3989
|
ensureBuiltin(context, 'whatsapp');
|
|
3931
3990
|
markAsync(context);
|
|
3932
3991
|
const lines = [];
|
|
3933
3992
|
if (node.login) {
|
|
3934
|
-
// v2.1.2
|
|
3993
|
+
// v2.1.2 - the pairing phone may be a compile-time literal or any
|
|
3935
3994
|
// PlainScript expression (e.g. a variable filled by `ask`). Runtime values
|
|
3936
3995
|
// are normalized/validated by __waNormalizePhone at startup.
|
|
3937
3996
|
let loginArg;
|
|
@@ -3957,7 +4016,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3957
4016
|
return lines.join('\n');
|
|
3958
4017
|
}
|
|
3959
4018
|
|
|
3960
|
-
// pair whatsapp "<phone>"
|
|
4019
|
+
// pair whatsapp "<phone>" - on-demand WhatsApp pairing session.
|
|
3961
4020
|
// When _inTelegram is true, relays the pairing code and connection status
|
|
3962
4021
|
// to the Telegram chat via ctx.chatId.
|
|
3963
4022
|
case 'WhatsAppPairStatement': {
|
|
@@ -3974,7 +4033,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3974
4033
|
return `${indent}await __whatsappPair(${phoneArg}, null, null);`;
|
|
3975
4034
|
}
|
|
3976
4035
|
|
|
3977
|
-
// on message … done
|
|
4036
|
+
// on message … done - registers the handler that receives each incoming
|
|
3978
4037
|
// WhatsApp message as a normalized PlainScript record on `message`.
|
|
3979
4038
|
case 'WhatsAppOnMessageStatement': {
|
|
3980
4039
|
ensureBuiltin(context, 'whatsapp');
|
|
@@ -3990,7 +4049,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3990
4049
|
].join('\n');
|
|
3991
4050
|
}
|
|
3992
4051
|
|
|
3993
|
-
// log message
|
|
4052
|
+
// log message - prints the current message record. Handler-only by
|
|
3994
4053
|
// design: outside "on message" there is no message to log.
|
|
3995
4054
|
case 'WhatsAppLogStatement':
|
|
3996
4055
|
if (!_inWhatsApp) {
|
|
@@ -3999,7 +4058,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
3999
4058
|
ensureBuiltin(context, 'whatsapp');
|
|
4000
4059
|
return `${indent}console.log(__waCtx.message);`;
|
|
4001
4060
|
|
|
4002
|
-
// v2.14
|
|
4061
|
+
// v2.14 - download "<path>" - saves the current message's media to a file.
|
|
4003
4062
|
// Handler-only by design: outside "on message" there is no message media.
|
|
4004
4063
|
case 'WhatsAppDownloadStatement':
|
|
4005
4064
|
if (!_inWhatsApp) {
|
|
@@ -4009,7 +4068,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
4009
4068
|
markAsync(context);
|
|
4010
4069
|
return `${indent}await __whatsappDownload(__waCtx.message, ${JSON.stringify(node.filePath)});`;
|
|
4011
4070
|
|
|
4012
|
-
// v2.1.0
|
|
4071
|
+
// v2.1.0 - mail, cache, scheduling, background jobs, websocket
|
|
4013
4072
|
|
|
4014
4073
|
case 'MailTransportStatement': {
|
|
4015
4074
|
ensureBuiltin(context, 'mailer');
|
|
@@ -4043,7 +4102,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
4043
4102
|
return `${indent}await __mailSend({ ${fields} });`;
|
|
4044
4103
|
}
|
|
4045
4104
|
|
|
4046
|
-
// cache "<redis-url>"
|
|
4105
|
+
// cache "<redis-url>" - connects the shared Redis client. At the top
|
|
4047
4106
|
// level the connect is awaited in program order; inside functions it is
|
|
4048
4107
|
// connected fire-and-forget.
|
|
4049
4108
|
case 'CacheStatement': {
|
|
@@ -4077,7 +4136,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
4077
4136
|
].join('\n');
|
|
4078
4137
|
}
|
|
4079
4138
|
|
|
4080
|
-
// v1.0.
|
|
4139
|
+
// v1.0.361 - every frame … done: one requestAnimationFrame loop. The next
|
|
4081
4140
|
// frame is scheduled after the body so the body always runs once per
|
|
4082
4141
|
// frame; an awaiting body makes the callback async automatically.
|
|
4083
4142
|
case 'EveryFrameStatement': {
|
|
@@ -4094,7 +4153,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
4094
4153
|
].join('\n');
|
|
4095
4154
|
}
|
|
4096
4155
|
|
|
4097
|
-
// v1.0.
|
|
4156
|
+
// v1.0.361 - after <n> <unit> … done: one-shot setTimeout. The delay is an
|
|
4098
4157
|
// expression scaled by the unit; an awaiting body makes the callback async.
|
|
4099
4158
|
case 'AfterStatement': {
|
|
4100
4159
|
const delay = generateExpr(node.delay, context);
|
|
@@ -4231,7 +4290,7 @@ function generateStatement(node, indent = '', context = createGenerationContext(
|
|
|
4231
4290
|
return `${indent}__emitter.on(${event}, (${node.paramName}) => {\n${body}\n${indent}});`;
|
|
4232
4291
|
}
|
|
4233
4292
|
|
|
4234
|
-
// v1.0.
|
|
4293
|
+
// v1.0.361 - when <target> "<event>" happens [as <name>] … done: DOM event
|
|
4235
4294
|
// listener. The handler param defaults to "event"; an awaiting body makes
|
|
4236
4295
|
// the callback async automatically.
|
|
4237
4296
|
case 'WhenTargetedStatement': {
|
|
@@ -4281,6 +4340,16 @@ function generateLValue(node, context) {
|
|
|
4281
4340
|
|
|
4282
4341
|
function generateExpr(node, context = createGenerationContext()) {
|
|
4283
4342
|
switch (node.type) {
|
|
4343
|
+
case 'BinaryCondition':
|
|
4344
|
+
case 'UnaryCondition':
|
|
4345
|
+
case 'BetweenCondition':
|
|
4346
|
+
case 'InCondition':
|
|
4347
|
+
case 'NotInCondition':
|
|
4348
|
+
case 'StringCondition':
|
|
4349
|
+
case 'LogicalCondition':
|
|
4350
|
+
// Comparisons are first-class expressions (e.g. `(x) -> x is above 3`),
|
|
4351
|
+
// so emit the same code the condition level produces.
|
|
4352
|
+
return generateCondition(node, context);
|
|
4284
4353
|
case 'DictionaryLiteral': {
|
|
4285
4354
|
if (!node.pairs || node.pairs.length === 0) return 'new Map()';
|
|
4286
4355
|
const pairs = node.pairs.map(p => `[${generateExpr(p.key, context)}, ${generateExpr(p.value, context)}]`);
|
|
@@ -4315,13 +4384,13 @@ function generateExpr(node, context = createGenerationContext()) {
|
|
|
4315
4384
|
case 'CollectionReflectExpression': {
|
|
4316
4385
|
const target = generateExpr(node.target, context);
|
|
4317
4386
|
if (node.accessor === 'keys') {
|
|
4318
|
-
return `Array.from(${target}.keys())`;
|
|
4387
|
+
return `(${target} instanceof Map || ${target} instanceof Set ? Array.from(${target}.keys()) : Object.keys(${target}))`;
|
|
4319
4388
|
}
|
|
4320
4389
|
if (node.accessor === 'values') {
|
|
4321
|
-
return `Array.from(${target}.values())`;
|
|
4390
|
+
return `(${target} instanceof Map || ${target} instanceof Set ? Array.from(${target}.values()) : Object.values(${target}))`;
|
|
4322
4391
|
}
|
|
4323
4392
|
if (node.accessor === 'entries') {
|
|
4324
|
-
return `Array.from(${target}.entries())`;
|
|
4393
|
+
return `(${target} instanceof Map || ${target} instanceof Set ? Array.from(${target}.entries()) : Object.entries(${target}))`;
|
|
4325
4394
|
}
|
|
4326
4395
|
if (node.accessor === 'size') {
|
|
4327
4396
|
return `(${target} instanceof Map || ${target} instanceof Set ? ${target}.size : (${target} && ${target}.size !== undefined ? ${target}.size : ${target}?.length))`;
|
|
@@ -4330,23 +4399,11 @@ function generateExpr(node, context = createGenerationContext()) {
|
|
|
4330
4399
|
}
|
|
4331
4400
|
case 'StringLiteral': return JSON.stringify(node.value);
|
|
4332
4401
|
case 'NumberLiteral': return String(node.value);
|
|
4333
|
-
// v2.1.1
|
|
4402
|
+
// v2.1.1 - boolean and null literals are PlainScript keywords.
|
|
4334
4403
|
case 'BooleanLiteral': return String(node.value);
|
|
4335
4404
|
case 'NullLiteral': return 'null';
|
|
4336
|
-
|
|
4337
|
-
//
|
|
4338
|
-
// -(2 + 3) does not flatten to -2 + 3.
|
|
4339
|
-
case 'UnaryExpression':
|
|
4340
|
-
return `${node.operator}${node.operand.type === 'BinaryExpression'
|
|
4341
|
-
? `(${generateExpr(node.operand, context)})`
|
|
4342
|
-
: generateExpr(node.operand, context)}`;
|
|
4343
|
-
// v2.1.1 — wait for <expr>: awaits an async value (fetch promises,
|
|
4344
|
-
// async functions called from PlainScript, etc.).
|
|
4345
|
-
case 'AwaitExpression': {
|
|
4346
|
-
markAsync(context);
|
|
4347
|
-
return `(await ${generateExpr(node.value, context)})`;
|
|
4348
|
-
}
|
|
4349
|
-
// v2.1.1 — HTTP client: get/post/put/patch/delete "<url>" with clauses.
|
|
4405
|
+
|
|
4406
|
+
// v2.1.1 - HTTP client: get/post/put/patch/delete "<url>" with clauses.
|
|
4350
4407
|
case 'HttpCall': {
|
|
4351
4408
|
ensureBuiltin(context, 'http');
|
|
4352
4409
|
markAsync(context);
|
|
@@ -4409,7 +4466,7 @@ function generateExpr(node, context = createGenerationContext()) {
|
|
|
4409
4466
|
return `{ ${props} }`;
|
|
4410
4467
|
}
|
|
4411
4468
|
|
|
4412
|
-
// v1.2
|
|
4469
|
+
// v1.2 - Inline object literal: { key: value, ... }
|
|
4413
4470
|
case 'InlineObjectLiteral': {
|
|
4414
4471
|
const props = node.properties
|
|
4415
4472
|
.map(p => `${JSON.stringify(p.key)}: ${generateExpr(p.value, context)}`)
|
|
@@ -4435,12 +4492,47 @@ function generateExpr(node, context = createGenerationContext()) {
|
|
|
4435
4492
|
case 'OptionalCallExpression':
|
|
4436
4493
|
return `${generateExpr(node.callee.object, context)}?.${node.callee.property}(${node.args.map(arg => generateExpr(arg, context)).join(', ')})`;
|
|
4437
4494
|
|
|
4495
|
+
// Function expression: (params) -> expression → (params) => expression.
|
|
4496
|
+
// Block-bodied form: (params) do ... done → (params) => { ... } - reuses
|
|
4497
|
+
// generateBlock, the same body emitter as `make` functions, so closures,
|
|
4498
|
+
// effects, loops, conditionals, early returns, and async/await behave
|
|
4499
|
+
// exactly like ordinary functions.
|
|
4500
|
+
case 'ArrowFunctionExpression': {
|
|
4501
|
+
const prevInFunction = context.inFunction;
|
|
4502
|
+
context.inFunction = true;
|
|
4503
|
+
const prevAwait = context.emittedAwait;
|
|
4504
|
+
context.emittedAwait = false;
|
|
4505
|
+
const paramStr = node.params.map(p => typeof p === 'object' && p ? p.name : p).join(', ');
|
|
4506
|
+
if (node.block) {
|
|
4507
|
+
const block = generateBlock(node.body, ' ', context);
|
|
4508
|
+
const isAsync = block.emitted ? 'async ' : '';
|
|
4509
|
+
context.emittedAwait = prevAwait;
|
|
4510
|
+
context.inFunction = prevInFunction;
|
|
4511
|
+
return `${isAsync}(${paramStr}) => {\n${block.out}\n}`;
|
|
4512
|
+
}
|
|
4513
|
+
const body = generateExpr(node.body, context);
|
|
4514
|
+
const emitted = context.emittedAwait;
|
|
4515
|
+
context.emittedAwait = prevAwait;
|
|
4516
|
+
context.inFunction = prevInFunction;
|
|
4517
|
+
const isAsync = emitted ? 'async ' : '';
|
|
4518
|
+
return `${isAsync}(${paramStr}) => ${body}`;
|
|
4519
|
+
}
|
|
4520
|
+
|
|
4438
4521
|
case 'CallExpression': {
|
|
4439
|
-
// Method call: receiver.method(args). Member access invoked with parens
|
|
4522
|
+
// Method call: receiver.method(args). Member access invoked with parens -
|
|
4440
4523
|
// e.g. path.join("a", "b"), mrz.parse(line), fs.existsSync(("x")).
|
|
4524
|
+
// Postfix calls f()(), arr[0](1), mul(6)(7) also bind here; any composite
|
|
4525
|
+
// callee (arrow, binary, comparison/logical condition) is parenthesised so
|
|
4526
|
+
// the call still applies to the whole value, not its last operand.
|
|
4441
4527
|
if (node.callee) {
|
|
4442
4528
|
const args = node.args.map(arg => generateExpr(arg, context)).join(', ');
|
|
4443
|
-
|
|
4529
|
+
const callee = generateExpr(node.callee, context);
|
|
4530
|
+
const composite = node.callee.type === 'ArrowFunctionExpression' ||
|
|
4531
|
+
node.callee.type === 'BinaryExpression' ||
|
|
4532
|
+
node.callee.type === 'LogicalCondition' ||
|
|
4533
|
+
node.callee.type === 'ComparisonCondition' ||
|
|
4534
|
+
node.callee.type === 'UnaryExpression';
|
|
4535
|
+
return `${composite ? `(${callee})` : callee}(${args})`;
|
|
4444
4536
|
}
|
|
4445
4537
|
if (STDLIB[node.name]) {
|
|
4446
4538
|
if (node.name === 'readFile' || node.name === 'writeFile' ||
|
|
@@ -4454,7 +4546,7 @@ function generateExpr(node, context = createGenerationContext()) {
|
|
|
4454
4546
|
return `${node.name}(${node.args.map(arg => generateExpr(arg, context)).join(', ')})`;
|
|
4455
4547
|
}
|
|
4456
4548
|
|
|
4457
|
-
// v1.1
|
|
4549
|
+
// v1.1 - Item expressions
|
|
4458
4550
|
case 'FirstItem':
|
|
4459
4551
|
return `${generateExpr(node.collection, context)}[0]`;
|
|
4460
4552
|
|
|
@@ -4467,9 +4559,14 @@ function generateExpr(node, context = createGenerationContext()) {
|
|
|
4467
4559
|
case 'LengthExpression':
|
|
4468
4560
|
return `${generateExpr(node.object, context)}.length`;
|
|
4469
4561
|
|
|
4470
|
-
|
|
4562
|
+
case 'CountOfExpression': {
|
|
4563
|
+
const obj = generateExpr(node.object, context);
|
|
4564
|
+
return `((${obj} && ${obj}.count !== undefined) ? ${obj}.count : ((${obj} && ${obj}.length !== undefined) ? ${obj}.length : ((${obj} && ${obj}.size !== undefined) ? ${obj}.size : 0)))`;
|
|
4565
|
+
}
|
|
4566
|
+
|
|
4567
|
+
// v1.1 - Property access
|
|
4471
4568
|
case 'OfExpression': {
|
|
4472
|
-
// v2.1.1
|
|
4569
|
+
// v2.1.1 - "session of request" / "user of request" read server-side
|
|
4473
4570
|
// state managed by the session and OAuth runtimes.
|
|
4474
4571
|
if (node.object.type === 'Identifier' && node.object.name === 'request' &&
|
|
4475
4572
|
node.property.type === 'Identifier') {
|
|
@@ -4487,18 +4584,21 @@ function generateExpr(node, context = createGenerationContext()) {
|
|
|
4487
4584
|
return `${generateExpr(node.object, context)}.${generateExpr(node.property, context)}`;
|
|
4488
4585
|
}
|
|
4489
4586
|
|
|
4490
|
-
// v1.1
|
|
4587
|
+
// v1.1 - Collection operations
|
|
4491
4588
|
case 'AddCall':
|
|
4492
4589
|
return `${generateExpr(node.collection, context)}.push(${generateExpr(node.value, context)})`;
|
|
4493
4590
|
|
|
4494
|
-
case 'RemoveCall':
|
|
4495
|
-
|
|
4591
|
+
case 'RemoveCall': {
|
|
4592
|
+
const coll = generateExpr(node.collection, context);
|
|
4593
|
+
const val = generateExpr(node.value, context);
|
|
4594
|
+
return `${coll} instanceof Map || ${coll} instanceof Set ? ${coll}.delete(${val}) : ${coll}.splice(${coll}.indexOf(${val}), 1)`;
|
|
4595
|
+
}
|
|
4496
4596
|
|
|
4497
4597
|
case 'WriteCall':
|
|
4498
4598
|
ensureBuiltin(context, 'fs');
|
|
4499
4599
|
return `fs.writeFileSync(${generateExpr(node.data, context)}, ${generateExpr(node.file, context)}, 'utf8')`;
|
|
4500
4600
|
|
|
4501
|
-
// v1.0.1
|
|
4601
|
+
// v1.0.1 - record constructor: `create a Person with name "Ada" and age 17`
|
|
4502
4602
|
// calls the kind factory that `define a kind called "Person"` registered.
|
|
4503
4603
|
case 'CreateKindExpression': {
|
|
4504
4604
|
const fields = node.pairs
|
|
@@ -4507,7 +4607,7 @@ function generateExpr(node, context = createGenerationContext()) {
|
|
|
4507
4607
|
return `${node.kind}({ ${fields} })`;
|
|
4508
4608
|
}
|
|
4509
4609
|
|
|
4510
|
-
// v1.0.1
|
|
4610
|
+
// v1.0.1 - concurrency combinators: `all of [...]` / `any of [...]` /
|
|
4511
4611
|
// `settled of [...]`. All are awaited; `settled` returns status records.
|
|
4512
4612
|
case 'ConcurrencyExpression': {
|
|
4513
4613
|
markAsync(context);
|
|
@@ -4517,7 +4617,7 @@ function generateExpr(node, context = createGenerationContext()) {
|
|
|
4517
4617
|
return `(await Promise.all(${rhs}))`;
|
|
4518
4618
|
}
|
|
4519
4619
|
|
|
4520
|
-
// v1.0.1
|
|
4620
|
+
// v1.0.1 - `spread of <collection>` → a fresh array from an iterable.
|
|
4521
4621
|
case 'SpreadExpression':
|
|
4522
4622
|
return `[...${generateExpr(node.collection, context)}]`;
|
|
4523
4623
|
|