{"_id":"@ao-tools/tstl-ao","_rev":"2-b396d91378e9a28c22cf1344118f4091","name":"@ao-tools/tstl-ao","dist-tags":{"latest":"0.2.5"},"versions":{"0.1.4":{"name":"@ao-tools/tstl-ao","version":"0.1.4","keywords":["lua","ao","arweave","typescript"],"author":{"name":"Kay Plößer"},"license":"MIT","_id":"@ao-tools/tstl-ao@0.1.4","maintainers":[{"name":"kay-is","email":"k@kay.is"}],"homepage":"https://github.com/ao-tools/tstl-ao#readme","bugs":{"url":"https://github.com/ao-tools/tstl-ao/issues"},"dist":{"shasum":"9acbc9be06d831ed83ded9a564ae3cff44fd8dda","tarball":"https://registry.npmjs.org/@ao-tools/tstl-ao/-/tstl-ao-0.1.4.tgz","fileCount":8,"integrity":"sha512-qQvQCKeKXr/LxiBwroROADKTa5Bu/KHnhNv+DBC/I7lDvfnc7Ursz+66eiqoKvGGEMSRzrCnf8beyn1mVouEYg==","signatures":[{"sig":"MEUCIEmivmCW1tTxpNCCDryV7FVmmLvTkbW5ejHXoezWUyEPAiEA7Hp7bGMC6RhtlDxzFCYlo8f0kMXa6ZKRaq3ryQWZTyo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19234},"types":"index.d.ts","_npmUser":{"name":"kay-is","email":"k@kay.is"},"repository":{"url":"git+https://github.com/ao-tools/tstl-ao.git","type":"git"},"_npmVersion":"10.9.0","description":"TypeScript-to-Lua type declaration for AO processes.","directories":{},"_nodeVersion":"22.12.0","_hasShrinkwrap":false,"peerDependencies":{"lua-types":"*","typescript":"*","typescript-to-lua":"*","@typescript-to-lua/language-extensions":"*"},"_npmOperationalInternal":{"tmp":"tmp/tstl-ao_0.1.4_1737307916254_0.7779089877614955","host":"s3://npm-registry-packages-npm-production"}},"0.2.4":{"name":"@ao-tools/tstl-ao","version":"0.2.4","keywords":["lua","ao","arweave","typescript"],"author":{"name":"Kay Plößer"},"license":"MIT","_id":"@ao-tools/tstl-ao@0.2.4","maintainers":[{"name":"kay-is","email":"k@kay.is"}],"homepage":"https://github.com/ao-tools/tstl-ao#readme","bugs":{"url":"https://github.com/ao-tools/tstl-ao/issues"},"dist":{"shasum":"23db6aa4d50ae6f33fb6b46c9c487b10bbdec0d6","tarball":"https://registry.npmjs.org/@ao-tools/tstl-ao/-/tstl-ao-0.2.4.tgz","fileCount":8,"integrity":"sha512-Zsb8ylI8NGpTSdMtC9x6G3nRDvwAlwV5gmCchlAcKpFp3MW+h5tDjHQiX4DRuecKuA7pW7GwjA+4G/1ZFnbX6A==","signatures":[{"sig":"MEYCIQCg1X19GKBRaVs5uknmxG8xlat+kANon/Ob/xhHMo1DvQIhAJrU41mjRgNWJwU9qYI5Sr3JcMpEB61hQkKYlR+mq0+c","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19251},"types":"index.d.ts","_npmUser":{"name":"kay-is","email":"k@kay.is"},"repository":{"url":"git+https://github.com/ao-tools/tstl-ao.git","type":"git"},"_npmVersion":"10.9.0","description":"TypeScript-to-Lua type declaration for AO processes.","directories":{},"_nodeVersion":"22.12.0","_hasShrinkwrap":false,"peerDependencies":{"lua-types":"*","typescript":"*","typescript-to-lua":"*","@typescript-to-lua/language-extensions":"*"},"_npmOperationalInternal":{"tmp":"tmp/tstl-ao_0.2.4_1737311863122_0.7068060379395915","host":"s3://npm-registry-packages-npm-production"}},"0.2.5":{"name":"@ao-tools/tstl-ao","version":"0.2.5","description":"TypeScript-to-Lua type declaration for AO processes.","author":{"name":"Kay Plößer"},"repository":{"type":"git","url":"git+https://github.com/ao-tools/tstl-ao.git"},"license":"MIT","types":"index.d.ts","keywords":["lua","ao","arweave","typescript"],"peerDependencies":{"typescript":"*","typescript-to-lua":"*","lua-types":"*","@typescript-to-lua/language-extensions":"*"},"_id":"@ao-tools/tstl-ao@0.2.5","bugs":{"url":"https://github.com/ao-tools/tstl-ao/issues"},"homepage":"https://github.com/ao-tools/tstl-ao#readme","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-m8ltC+2s762JWsDiTmge7Su41+niq7acCXXhpGt3+Fuabi+vZxXBtvNEoyxEcYIKgFFGk+vBWuDZ+x1r9w4G4g==","shasum":"657e310bab579027c38756ff2e4dfbed8b6b574e","tarball":"https://registry.npmjs.org/@ao-tools/tstl-ao/-/tstl-ao-0.2.5.tgz","fileCount":9,"unpackedSize":19395,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCHPZK/VlczpdIReFbFsII0GegKVGDlsqDjyJ61+GNJDwIgI+BARoNDO0AtwNSBdnI1gGStLT3oukmC5XPDTOcJXKU="}]},"_npmUser":{"name":"kay-is","email":"k@kay.is"},"directories":{},"maintainers":[{"name":"kay-is","email":"k@kay.is"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tstl-ao_0.2.5_1737311968605_0.27418288813713954"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-19T17:31:56.111Z","modified":"2025-01-19T18:39:28.987Z","0.1.4":"2025-01-19T17:31:56.440Z","0.2.4":"2025-01-19T18:37:43.317Z","0.2.5":"2025-01-19T18:39:28.816Z"},"bugs":{"url":"https://github.com/ao-tools/tstl-ao/issues"},"author":{"name":"Kay Plößer"},"license":"MIT","homepage":"https://github.com/ao-tools/tstl-ao#readme","keywords":["lua","ao","arweave","typescript"],"repository":{"type":"git","url":"git+https://github.com/ao-tools/tstl-ao.git"},"description":"TypeScript-to-Lua type declaration for AO processes.","maintainers":[{"name":"kay-is","email":"k@kay.is"}],"readme":"# TSTL-AO\r\n\r\nThis package contains ambient/global type declarations for\r\n[AO](https://cookbook_ao.ar.io/) processes. It's used together with\r\n[TypeScript-to-Lua](https://typescripttolua.github.io/) to compile TypeScript\r\nto Lua code that can run on AOS.\r\n\r\nThis allows autocompletion for globals and modules of AOS and Lua's standard\r\nlibrary. If you export your types, you can also use them in your client to get\r\nend-to-end type safety.\r\n\r\n## Installation\r\n\r\nInstall this package and its peer dependencies:\r\n\r\n    npm i -D @ao-tools/tstl-ao typescript typescript-to-lua lua-types @typescript-to-lua/language-extensions\r\n\r\n- typescript and typescript-to-lua for compilation\r\n- [lua-types](https://github.com/TypeScriptToLua/lua-types) contains type definitions for the Lua standard library.\r\n- [@typescript-to-lua/language-extensions](https://typescripttolua.github.io/docs/advanced/language-extensions) enables to type Lua constructs that don't map directly to TypeScript.\r\n\r\n## Setup\r\n\r\nCreate a `tsconfig.json` file with the following content:\r\n\r\n```json\r\n{\r\n  \"$schema\": \"https://raw.githubusercontent.com/TypeScriptToLua/TypeScriptToLua/master/tsconfig-schema.json\",\r\n  \"include\": [\"path/to/process.ts\"],\r\n  \"compilerOptions\": {\r\n    \"strict\": true,\r\n    \"target\": \"ESNext\",\r\n    \"lib\": [\"ESNext\"],\r\n    \"moduleResolution\": \"Node\",\r\n    \"types\": [\r\n      \"lua-types/5.3\",\r\n      \"@typescript-to-lua/language-extensions\",\r\n      \"@ao-tools/tstl-ao\"\r\n    ]\r\n  },\r\n  \"tstl\": {\r\n    \"luaTarget\": \"5.3\",\r\n    \"luaBundleEntry\": \"path/to/process.ts\",\r\n    \"luaBundle\": \"path/to/build/process.lua\",\r\n    \"luaLibImport\": \"require-minimal\",\r\n    \"noHeader\": true\r\n  }\r\n}\r\n```\r\n\r\n`include` and `luaBundleEntry` must at least contain the path to your process\r\nentry file.\r\n\r\n`luaBundle` contains the file path where TSTL saves the Lua bundle.\r\n\r\n`luaLibImport` is the setting that controls built-in JavaScript APIs like\r\n`string.split` or `Object.keys`. `require-minimal` is the most robust setting\r\nthat allows the use of those APIs without importing all of TSTL's JavaScript\r\nshims.\r\n\r\nIf you don't want to use any of those APIs, you can set this to `none`\r\nand save some space by using the built-in AOS modules instead.\r\n\r\nIf you only use very few of those APIs you can use `inline`.\r\n\r\n## Caveats\r\n\r\nLua isn't JavaScript, so there is no 100% compat. These are the differences you\r\nmight encounter.\r\n\r\n### Different comparison results\r\n\r\n- `\"\" == true`\r\n- `NaN == true`\r\n- `0 == true`\r\n- `null === undefined` (Note: tripple equals!)\r\n\r\nUsing `===` an `!==` resolves all but the last difference.\r\n\r\n### `undefined` and `null` deletes array and object items\r\n\r\n`a.x = null` and `a.x = undefined` are equivalent to `delete a.x`\r\n\r\n### No RegExp\r\n\r\nTSTL doesn't shim JavaScript regular expressions. Use `string.find()` instead.\r\n\r\n### No `for ... in` array iterations\r\n\r\nYou can't iterate an array with `for ... in`, use `for ... of`, `.forEach`, or\r\n`.map` instead.\r\n\r\n### Unstable sorting\r\n\r\nThe `table.sort` function is not stable.\r\n\r\n### Local variable limit\r\n\r\nYou can only declare 200 variable per function.\r\n\r\n### Variable JSON encoding\r\n\r\nThe `json.encode` function will encode both, an empty array and an empty object\r\nto an empty array.\r\n\r\n### Co-routines yield without await\r\n\r\nCalling `ao.send().receive()` will stop the execution of the following lines of\r\ncode until the target process replies.\r\n\r\nConsider `const x = ao.send().receive()` to work similar to\r\n`const x = await ao.send()`.\r\n\r\n## Example\r\n\r\nThe following code uses built-in modules of AOS, defines a type and sets up an\r\ninfo handler.\r\n\r\nFile: `backend/process.ts`\r\n\r\n```typescript\r\nimport * as Crypto from \".crypto\"\r\nimport * as Json from \"json\"\r\n\r\nexport type InfoResponse = {\r\n  Id: string\r\n  Name: string\r\n  Owner: string\r\n  MemoryUsage: number\r\n  PseudoRandom: number\r\n  Time: number\r\n}\r\n\r\nHandlers.add(\"example-handler\", \"Info\", (message) => {\r\n  const info: InfoResponse = {\r\n    // AOS global variables\r\n    Id: ao.id,\r\n    Name: Name,\r\n    Owner: Owner,\r\n    // AOS module function\r\n    PseudoRandom: Crypto.random(0, 100),\r\n    // Lua standard library function\r\n    MemoryUsage: collectgarbage(\"count\"),\r\n    Time: os.time(),\r\n  }\r\n\r\n  message.reply({\r\n    // AOS module function\r\n    Data: Json.encode(info),\r\n  })\r\n})\r\n```\r\n\r\nYou an use the `InfoResponse` type when parsing the messge data on a client.\r\n\r\nFile: `frontend/client.ts`\r\n\r\n```typescript\r\nimport * as aoconnect from \"@permaweb/aoconnect\"\r\nimport type { InfoResponse } from \"../backend/process.ts\"\r\n\r\nconst result = await aoconnect.dryrun({\r\n  process: \"<PROCESS_ID>\"\r\n  tags: [{name: \"Action\", value: \"Info\"}]\r\n})\r\n\r\nconst response: InfoResponse = JSON.parse(result.Messages.pop().Data)\r\n```\r\n","readmeFilename":"README.md"}