Skip to content

Commit 1ce4261

Browse files
Merge pull request #100 from hyperpolymath/feat/stdlib-extern-bindings
stdlib: add extern binding modules for Grammy, Sqlite, Network, Crypto, Ajv
2 parents cf6e2f5 + 8c6749e commit 1ce4261

5 files changed

Lines changed: 86 additions & 0 deletions

File tree

stdlib/Ajv.affine

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
3+
//
4+
// Ajv.affine — extern bindings for AJV v8 JSON Schema Validator.
5+
// The Node-CJS shim instantiates ajv@8 with allErrors:true, strict:false
6+
// and ajv-formats@3 applied. All handles are opaque Int.
7+
8+
module Ajv;
9+
10+
pub extern type AjvInstance;
11+
pub extern type Validator;
12+
13+
pub extern fn ajv_new() -> AjvInstance;
14+
pub extern fn ajv_compile(a: AjvInstance, schema_json: String) -> Validator;
15+
pub extern fn ajv_validate(v: Validator, value_json: String) -> Bool;
16+
pub extern fn ajv_errors_json(v: Validator) -> String;

stdlib/Crypto.affine

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
3+
//
4+
// Crypto.affine — extern bindings for crypto primitives and wall-clock time.
5+
// The Node-CJS shim wraps Node's built-in node:crypto and Date.now().
6+
7+
module Crypto;
8+
9+
pub extern fn random_string(n: Int) -> String;
10+
pub extern fn random_f64() -> Float;
11+
pub extern fn time_ms() -> Int;

stdlib/Grammy.affine

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
3+
//
4+
// Grammy.affine — extern bindings for the Grammy Telegram Bot framework.
5+
//
6+
// All Grammy host objects are opaque Int handles maintained by the Node-CJS
7+
// shim. Function names mirror the Grammy/Telegram API where possible, with
8+
// namespaces flattened (e.g. bot.api.sendMessage -> bot_send_message).
9+
//
10+
// API surface: the subset used by avow-protocol/telegram-bot in standards.
11+
12+
module Grammy;
13+
14+
pub extern type Bot;
15+
pub extern type Context;
16+
pub extern type BotInfo;
17+
18+
pub extern fn bot_new(token: String) -> Bot;
19+
pub extern fn bot_command(b: Bot, command: String, handler: Int) -> Int;
20+
pub extern fn bot_catch(b: Bot, err_handler: Int) -> Int;
21+
pub extern fn bot_start(b: Bot, on_start_handler: Int) -> Int;
22+
pub extern fn bot_send_message(b: Bot, chat_id: Int, text: String, parse_mode: String) -> Int;
23+
24+
pub extern fn ctx_from_id(ctx: Context) -> Option<Int>;
25+
pub extern fn ctx_from_username(ctx: Context) -> Option<String>;
26+
pub extern fn ctx_reply(ctx: Context, text: String, parse_mode: String) -> Int;
27+
28+
pub extern fn botinfo_username(info: BotInfo) -> String;
29+
30+
pub extern fn set_interval(handler: Int, interval_ms: Int) -> Int;

stdlib/Network.affine

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
3+
//
4+
// Network.affine — extern bindings for synchronous HTTP requests.
5+
// The Node-CJS shim wraps Node's built-in node:https via a sync adapter.
6+
7+
module Network;
8+
9+
pub extern fn http_get_status(url: String) -> Int;
10+
pub extern fn http_get_response_time_ms(url: String) -> Int;

stdlib/Sqlite.affine

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
3+
//
4+
// Sqlite.affine — extern bindings for an SQLite backend.
5+
//
6+
// All database handles are opaque Int. Query parameters are JSON-encoded
7+
// strings; each result row is returned as a JSON-encoded string for
8+
// caller-side decoding. The Node-CJS shim wraps Deno sqlite or node:sqlite.
9+
10+
module Sqlite;
11+
12+
pub extern type Db;
13+
14+
pub extern fn db_open(path: String) -> Db;
15+
pub extern fn db_close(d: Db) -> Int;
16+
pub extern fn db_execute(d: Db, sql: String) -> Int;
17+
pub extern fn db_query(d: Db, sql: String, params_json: String) -> String;
18+
pub extern fn db_query_one(d: Db, sql: String, params_json: String) -> String;
19+
pub extern fn db_query_int(d: Db, sql: String, params_json: String) -> Int;

0 commit comments

Comments
 (0)