diff --git a/stdlib/Ajv.affine b/stdlib/Ajv.affine new file mode 100644 index 0000000..6e0f251 --- /dev/null +++ b/stdlib/Ajv.affine @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: PMPL-1.0-or-later +// Copyright (c) 2026 Jonathan D.A. Jewell +// +// Ajv.affine — extern bindings for AJV v8 JSON Schema Validator. +// The Node-CJS shim instantiates ajv@8 with allErrors:true, strict:false +// and ajv-formats@3 applied. All handles are opaque Int. + +module Ajv; + +pub extern type AjvInstance; +pub extern type Validator; + +pub extern fn ajv_new() -> AjvInstance; +pub extern fn ajv_compile(a: AjvInstance, schema_json: String) -> Validator; +pub extern fn ajv_validate(v: Validator, value_json: String) -> Bool; +pub extern fn ajv_errors_json(v: Validator) -> String; diff --git a/stdlib/Crypto.affine b/stdlib/Crypto.affine new file mode 100644 index 0000000..36713d4 --- /dev/null +++ b/stdlib/Crypto.affine @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: PMPL-1.0-or-later +// Copyright (c) 2026 Jonathan D.A. Jewell +// +// Crypto.affine — extern bindings for crypto primitives and wall-clock time. +// The Node-CJS shim wraps Node's built-in node:crypto and Date.now(). + +module Crypto; + +pub extern fn random_string(n: Int) -> String; +pub extern fn random_f64() -> Float; +pub extern fn time_ms() -> Int; diff --git a/stdlib/Grammy.affine b/stdlib/Grammy.affine new file mode 100644 index 0000000..ae7baca --- /dev/null +++ b/stdlib/Grammy.affine @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: PMPL-1.0-or-later +// Copyright (c) 2026 Jonathan D.A. Jewell +// +// Grammy.affine — extern bindings for the Grammy Telegram Bot framework. +// +// All Grammy host objects are opaque Int handles maintained by the Node-CJS +// shim. Function names mirror the Grammy/Telegram API where possible, with +// namespaces flattened (e.g. bot.api.sendMessage -> bot_send_message). +// +// API surface: the subset used by avow-protocol/telegram-bot in standards. + +module Grammy; + +pub extern type Bot; +pub extern type Context; +pub extern type BotInfo; + +pub extern fn bot_new(token: String) -> Bot; +pub extern fn bot_command(b: Bot, command: String, handler: Int) -> Int; +pub extern fn bot_catch(b: Bot, err_handler: Int) -> Int; +pub extern fn bot_start(b: Bot, on_start_handler: Int) -> Int; +pub extern fn bot_send_message(b: Bot, chat_id: Int, text: String, parse_mode: String) -> Int; + +pub extern fn ctx_from_id(ctx: Context) -> Option; +pub extern fn ctx_from_username(ctx: Context) -> Option; +pub extern fn ctx_reply(ctx: Context, text: String, parse_mode: String) -> Int; + +pub extern fn botinfo_username(info: BotInfo) -> String; + +pub extern fn set_interval(handler: Int, interval_ms: Int) -> Int; diff --git a/stdlib/Network.affine b/stdlib/Network.affine new file mode 100644 index 0000000..b32c551 --- /dev/null +++ b/stdlib/Network.affine @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: PMPL-1.0-or-later +// Copyright (c) 2026 Jonathan D.A. Jewell +// +// Network.affine — extern bindings for synchronous HTTP requests. +// The Node-CJS shim wraps Node's built-in node:https via a sync adapter. + +module Network; + +pub extern fn http_get_status(url: String) -> Int; +pub extern fn http_get_response_time_ms(url: String) -> Int; diff --git a/stdlib/Sqlite.affine b/stdlib/Sqlite.affine new file mode 100644 index 0000000..d317074 --- /dev/null +++ b/stdlib/Sqlite.affine @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: PMPL-1.0-or-later +// Copyright (c) 2026 Jonathan D.A. Jewell +// +// Sqlite.affine — extern bindings for an SQLite backend. +// +// All database handles are opaque Int. Query parameters are JSON-encoded +// strings; each result row is returned as a JSON-encoded string for +// caller-side decoding. The Node-CJS shim wraps Deno sqlite or node:sqlite. + +module Sqlite; + +pub extern type Db; + +pub extern fn db_open(path: String) -> Db; +pub extern fn db_close(d: Db) -> Int; +pub extern fn db_execute(d: Db, sql: String) -> Int; +pub extern fn db_query(d: Db, sql: String, params_json: String) -> String; +pub extern fn db_query_one(d: Db, sql: String, params_json: String) -> String; +pub extern fn db_query_int(d: Db, sql: String, params_json: String) -> Int;