@typesol/cli 0.49.0 → 0.51.0
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/CHANGELOG.md +541 -0
- package/NOTICE +9 -0
- package/README.md +34 -15
- package/SECURITY.md +6 -3
- package/dist/cli.js +36 -5
- package/dist/compiler/analyze.d.ts +10 -1
- package/dist/compiler/analyze.js +234 -20
- package/dist/compiler/diagnostics.d.ts +4 -0
- package/dist/compiler/diagnostics.js +5 -1
- package/dist/compiler/emit/base.d.ts +35 -4
- package/dist/compiler/emit/base.js +46 -4
- package/dist/compiler/emit/borsh.js +8 -8
- package/dist/compiler/emit/calls.d.ts +6 -0
- package/dist/compiler/emit/calls.js +98 -18
- package/dist/compiler/emit/cpi-core.d.ts +3 -0
- package/dist/compiler/emit/cpi-core.js +11 -5
- package/dist/compiler/emit/cpi.js +6 -4
- package/dist/compiler/emit/create.js +9 -9
- package/dist/compiler/emit/expressions.d.ts +9 -1
- package/dist/compiler/emit/expressions.js +77 -0
- package/dist/compiler/emit/function.d.ts +2 -0
- package/dist/compiler/emit/function.js +71 -15
- package/dist/compiler/emit/outline.d.ts +35 -0
- package/dist/compiler/emit/outline.js +547 -0
- package/dist/compiler/emit/program.js +19 -4
- package/dist/compiler/emit/rbtree.js +1 -1
- package/dist/compiler/emit/shared.d.ts +69 -4
- package/dist/compiler/emit/shared.js +44 -9
- package/dist/compiler/emit/statements.d.ts +36 -2
- package/dist/compiler/emit/statements.js +332 -29
- package/dist/compiler/emit/storage.d.ts +16 -0
- package/dist/compiler/emit/storage.js +134 -13
- package/dist/compiler/emit/views.js +1 -1
- package/dist/compiler/hints.d.ts +1 -1
- package/dist/compiler/hints.js +9 -1
- package/dist/compiler/idl.js +1 -1
- package/dist/compiler/index.d.ts +30 -2
- package/dist/compiler/index.js +94 -16
- package/dist/compiler/model.d.ts +13 -1
- package/dist/compiler/stack.d.ts +71 -0
- package/dist/compiler/stack.js +309 -0
- package/dist/compiler/toolchain.d.ts +87 -5
- package/dist/compiler/toolchain.js +384 -19
- package/dist/keys.d.ts +12 -1
- package/dist/keys.js +57 -7
- package/dist/workspace.d.ts +9 -0
- package/dist/workspace.js +91 -16
- package/docker/deps/0.50.0.lock.json +1206 -0
- package/docker/deps/0.51.0.lock.json +1206 -0
- package/docs/architecture.md +1 -1
- package/docs/audit.md +16 -13
- package/docs/case-study-escrow.md +1 -1
- package/docs/case-study-jito-mev.md +14 -14
- package/docs/case-study-marginfi.md +127 -127
- package/docs/case-study-multisig.md +16 -4
- package/docs/case-study-raydium-clmm.md +44 -28
- package/docs/case-study-raydium-cp-swap.md +18 -18
- package/docs/cli.md +5 -4
- package/docs/glossary.md +2 -1
- package/docs/language-accounts.md +16 -10
- package/docs/language-basics.md +29 -2
- package/docs/language-builtins.md +4 -2
- package/docs/language-cpi.md +34 -0
- package/docs/language-native.md +50 -4
- package/docs/language-pdas.md +6 -2
- package/docs/language-statements.md +103 -12
- package/docs/language-types.md +93 -8
- package/docs/runtime.md +20 -3
- package/docs/security-model.md +6 -3
- package/docs/stability.md +10 -5
- package/docs/testing.md +6 -2
- package/docs/troubleshooting.md +45 -1
- package/lib/typesol.d.ts +25 -3
- package/llms-full.txt +403 -54
- package/package.json +1 -1
- package/releases/0.49.0.json +857 -0
- package/releases/0.50.0.json +874 -0
- package/runtime/typesol_builtins.c +47 -2
- package/runtime/typesol_rt.h +254 -54
package/dist/workspace.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { agentsMd, CLAUDE_MD, cursorRule, MCP_JSON } from "./ai.js";
|
|
15
15
|
import { createHash } from "node:crypto";
|
|
16
|
-
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, statSync, unlinkSync,
|
|
16
|
+
import { closeSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeSync } from "node:fs";
|
|
17
17
|
import os from "node:os";
|
|
18
18
|
import path from "node:path";
|
|
19
19
|
import ts from "typescript";
|
|
@@ -97,13 +97,45 @@ export function programAddress(ws, name, opts = {}) {
|
|
|
97
97
|
if (recorded && recorded !== address)
|
|
98
98
|
throw new Error(`${name}: ${path.relative(ws.root, paths.keypair)} is ${address}, but ${CONFIG} records ${recorded}. Restore the right keypair.`);
|
|
99
99
|
if (!recorded) {
|
|
100
|
-
|
|
101
|
-
raw
|
|
102
|
-
|
|
100
|
+
// Another process (a first build of another program, under its own lock) may be recording its address now.
|
|
101
|
+
updateConfig(ws, (raw) => {
|
|
102
|
+
const entry = raw.programs[name];
|
|
103
|
+
const current = typeof entry === "object" ? entry : { path: entry ?? ws.programs[name].path };
|
|
104
|
+
if (current.address && current.address !== address)
|
|
105
|
+
throw new Error(`${name}: ${CONFIG} now records ${current.address}, but ${path.relative(ws.root, paths.keypair)} is ${address}. Restore the right keypair.`);
|
|
106
|
+
raw.programs[name] = { ...current, address };
|
|
107
|
+
});
|
|
103
108
|
ws.programs[name].address = address;
|
|
104
109
|
}
|
|
105
110
|
return { address, created };
|
|
106
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Change typesol.json: read it, `edit` it and write it back, one process at a time (`<file>.lock`, as a build's
|
|
114
|
+
* lock), the new text written to a temporary file and renamed over it, so that concurrent first builds each keep
|
|
115
|
+
* their address and no reader sees a partly written file.
|
|
116
|
+
*/
|
|
117
|
+
export function updateConfig(ws, edit) {
|
|
118
|
+
withLockFile(`${ws.file}.lock`, () => {
|
|
119
|
+
const raw = JSON.parse(readFileSync(ws.file, "utf8"));
|
|
120
|
+
edit(raw);
|
|
121
|
+
// A linked typesol.json stays a link: the file it points to is the one replaced.
|
|
122
|
+
const target = realpathSync(ws.file);
|
|
123
|
+
const tmp = `${target}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
124
|
+
writeNewFile(tmp, JSON.stringify(raw, null, 2) + "\n");
|
|
125
|
+
try {
|
|
126
|
+
renameSync(tmp, target);
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
try {
|
|
130
|
+
unlinkSync(tmp);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// Already gone.
|
|
134
|
+
}
|
|
135
|
+
throw e;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
107
139
|
/** Build every program (or the ones named). */
|
|
108
140
|
export function buildWorkspace(ws, names = Object.keys(ws.programs), opts = {}) {
|
|
109
141
|
return names.map((name) => {
|
|
@@ -112,7 +144,7 @@ export function buildWorkspace(ws, names = Object.keys(ws.programs), opts = {})
|
|
|
112
144
|
// another process building it at the same time (vitest runs test files in parallel workers) would overwrite them.
|
|
113
145
|
return withBuildLock(paths.outDir, () => {
|
|
114
146
|
const { address, created, keyless } = programAddress(ws, name, { needKeypair: opts.needKeypair });
|
|
115
|
-
const result = build(paths.entry, paths.outDir, address, { sbpf: opts.sbpf ?? ws.sbpf, profile: opts.profile });
|
|
147
|
+
const result = build(paths.entry, paths.outDir, address, { sbpf: opts.sbpf ?? ws.sbpf, profile: opts.profile, stackAuto: opts.stackAuto });
|
|
116
148
|
// The TypeScript client (docs/client.md) is written with the build, from the same IDL.
|
|
117
149
|
const clientPath = writeClient(result.idl, path.join(paths.outDir, `${result.model.name}.client.ts`)).path;
|
|
118
150
|
return { paths, address, created, keyless, result, clientPath };
|
|
@@ -217,7 +249,10 @@ const LOCK_POLL_MS = 100;
|
|
|
217
249
|
*/
|
|
218
250
|
export function withBuildLock(dir, fn) {
|
|
219
251
|
mkdirSync(dir, { recursive: true });
|
|
220
|
-
|
|
252
|
+
return withLockFile(path.join(dir, ".typesol-build.lock"), fn);
|
|
253
|
+
}
|
|
254
|
+
/** Run `fn` holding `lock` (see withBuildLock): created exclusively, taken over when its holder is gone or it is stale. */
|
|
255
|
+
function withLockFile(lock, fn) {
|
|
221
256
|
const me = `${os.hostname()} ${process.pid} ${Date.now()}`;
|
|
222
257
|
const deadline = Date.now() + LOCK_STALE_MS + 60_000;
|
|
223
258
|
for (;;) {
|
|
@@ -401,11 +436,52 @@ export function scaffold(dir, name, template = "counter", opts = {}) {
|
|
|
401
436
|
const agent = existing.some((f) => AGENT_FILES.includes(f));
|
|
402
437
|
if (existing.length)
|
|
403
438
|
throw new Error(`refusing to overwrite: ${existing.join(", ")}${agent ? " (--no-agent-files leaves out the files for AI coding agents)" : ""}`);
|
|
439
|
+
writeProjectFiles(dir, files);
|
|
440
|
+
return Object.keys(files);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Write new files under `root` (paths relative to it). Refuses, before writing anything, a path through a symbolic link
|
|
444
|
+
* below `root` (a linked directory or a link where a file goes, which would put the file outside the project), then
|
|
445
|
+
* creates each directory and each file exclusively, so an existing file (or one created meanwhile) is never overwritten.
|
|
446
|
+
* `root` itself may be a link: the project is where it points.
|
|
447
|
+
*/
|
|
448
|
+
function writeProjectFiles(root, files) {
|
|
449
|
+
for (const file of Object.keys(files)) {
|
|
450
|
+
const parts = file.split("/");
|
|
451
|
+
for (let i = 1; i <= parts.length; i++) {
|
|
452
|
+
const rel = parts.slice(0, i).join("/");
|
|
453
|
+
let link = false;
|
|
454
|
+
try {
|
|
455
|
+
link = lstatSync(path.join(root, rel)).isSymbolicLink();
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
break; // Does not exist: neither does anything below it.
|
|
459
|
+
}
|
|
460
|
+
if (link)
|
|
461
|
+
throw new Error(`refusing to write ${file}: ${rel} is a symbolic link (it may point outside the project); replace it with a directory or file of the project`);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
404
464
|
for (const [file, text] of Object.entries(files)) {
|
|
405
|
-
mkdirSync(path.dirname(path.join(
|
|
406
|
-
|
|
465
|
+
mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
|
|
466
|
+
try {
|
|
467
|
+
writeNewFile(path.join(root, file), text);
|
|
468
|
+
}
|
|
469
|
+
catch (e) {
|
|
470
|
+
if (e.code === "EEXIST")
|
|
471
|
+
throw new Error(`refusing to overwrite: ${file}`);
|
|
472
|
+
throw e;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
/** Create `file` with `text`; fails with EEXIST if anything (a file, a link, even a dangling one) is already there. */
|
|
477
|
+
function writeNewFile(file, text) {
|
|
478
|
+
const fd = openSync(file, "wx");
|
|
479
|
+
try {
|
|
480
|
+
writeSync(fd, text);
|
|
481
|
+
}
|
|
482
|
+
finally {
|
|
483
|
+
closeSync(fd);
|
|
407
484
|
}
|
|
408
|
-
return Object.keys(files);
|
|
409
485
|
}
|
|
410
486
|
/**
|
|
411
487
|
* Add a program to an existing project: programs/<name>.ts and tests/<name>.test.ts from a template, and its entry in
|
|
@@ -421,13 +497,12 @@ export function addProgram(ws, name, template = "counter") {
|
|
|
421
497
|
const existing = Object.keys(files).filter((f) => existsSync(path.join(ws.root, f)));
|
|
422
498
|
if (existing.length)
|
|
423
499
|
throw new Error(`refusing to overwrite: ${existing.join(", ")}`);
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
writeFileSync(ws.file, JSON.stringify(raw, null, 2) + "\n");
|
|
500
|
+
writeProjectFiles(ws.root, files);
|
|
501
|
+
updateConfig(ws, (raw) => {
|
|
502
|
+
if (raw.programs[name])
|
|
503
|
+
throw new Error(`${CONFIG} already has a program "${name}"`);
|
|
504
|
+
raw.programs[name] = { path: `programs/${name}.ts` };
|
|
505
|
+
});
|
|
431
506
|
ws.programs[name] = { path: `programs/${name}.ts` };
|
|
432
507
|
const pkgFile = path.join(ws.root, "package.json");
|
|
433
508
|
const pkg = existsSync(pkgFile)
|