@volter/world-core 2.0.0 → 2.0.1

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.
@@ -0,0 +1,2 @@
1
+ export * from './engine.js';
2
+ export * from './lua.js';
@@ -0,0 +1,6 @@
1
+ // THE KERNEL'S REDIS LIBRARY (`@volter/world-core/redis`): Redis's command semantics over the World's tree and its Lua
2
+ // interpreter. Shared by every pack that serves a Redis (the upstash
3
+ // pack's REST envelope, the redis pack's own protocol), each through its dialect; the kernel names no vendor.
4
+ // docs/contributing/architecture.md, "Other wires: lanes, headers and line protocols".
5
+ export * from "./engine.js";
6
+ export * from "./lua.js";
@@ -0,0 +1,153 @@
1
+ /** A Lua runtime/parse error. Surfaces to the caller as a Redis script error, never as a result. */
2
+ export declare class LuaError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ /** A library's null that is not nil (lua-cjson's `cjson.null`, a lightuserdata in Redis): a value a table can hold,
6
+ * and nil when a script returns it to Redis. */
7
+ export declare const LUA_NULL: LuaValue;
8
+ /** A Lua table. Array part + hash part, exactly like the real thing (1-based array indices). */
9
+ export declare class LuaTable {
10
+ readonly map: Map<string | number | boolean, LuaValue>;
11
+ get(k: LuaValue): LuaValue;
12
+ set(k: LuaValue, v: LuaValue): void;
13
+ /** A non-nil value at a non-nil key. */
14
+ private store;
15
+ /** `#t` — the border of the array part: the largest n where t[1..n] are all non-nil. */
16
+ get length(): number;
17
+ static fromArray(values: LuaValue[]): LuaTable;
18
+ toArray(): LuaValue[];
19
+ }
20
+ export type LuaFunction = (args: LuaValue[]) => LuaValue[];
21
+ /** `null` stands for Lua `nil` (JS `undefined` is never used as a value in this interpreter). */
22
+ export type LuaValue = null | boolean | number | string | LuaTable | LuaFunction;
23
+ type TokKind = 'name' | 'number' | 'string' | 'op' | 'keyword' | 'eof';
24
+ type Token = {
25
+ kind: TokKind;
26
+ value: string;
27
+ line: number;
28
+ };
29
+ export declare function tokenize(src: string): Token[];
30
+ type Expr = {
31
+ t: 'nil';
32
+ } | {
33
+ t: 'true';
34
+ } | {
35
+ t: 'false';
36
+ } | {
37
+ t: 'num';
38
+ v: number;
39
+ } | {
40
+ t: 'str';
41
+ v: string;
42
+ } | {
43
+ t: 'name';
44
+ v: string;
45
+ } | {
46
+ t: 'index';
47
+ obj: Expr;
48
+ key: Expr;
49
+ } | {
50
+ t: 'call';
51
+ fn: Expr;
52
+ args: Expr[];
53
+ line?: number;
54
+ } | {
55
+ t: 'bin';
56
+ op: string;
57
+ l: Expr;
58
+ r: Expr;
59
+ } | {
60
+ t: 'un';
61
+ op: string;
62
+ e: Expr;
63
+ } | {
64
+ t: 'table';
65
+ array: Expr[];
66
+ pairs: Array<{
67
+ k: Expr;
68
+ v: Expr;
69
+ }>;
70
+ } | {
71
+ t: 'func';
72
+ params: string[];
73
+ body: Stat[];
74
+ };
75
+ type Stat = {
76
+ t: 'local';
77
+ names: string[];
78
+ exprs: Expr[];
79
+ } | {
80
+ t: 'assign';
81
+ targets: Expr[];
82
+ exprs: Expr[];
83
+ } | {
84
+ t: 'callstat';
85
+ call: Expr;
86
+ } | {
87
+ t: 'if';
88
+ branches: Array<{
89
+ cond: Expr;
90
+ body: Stat[];
91
+ }>;
92
+ orelse: Stat[] | null;
93
+ } | {
94
+ t: 'while';
95
+ cond: Expr;
96
+ body: Stat[];
97
+ } | {
98
+ t: 'repeat';
99
+ body: Stat[];
100
+ cond: Expr;
101
+ } | {
102
+ t: 'fornum';
103
+ name: string;
104
+ from: Expr;
105
+ to: Expr;
106
+ step: Expr | null;
107
+ body: Stat[];
108
+ } | {
109
+ t: 'forin';
110
+ names: string[];
111
+ exprs: Expr[];
112
+ body: Stat[];
113
+ } | {
114
+ t: 'do';
115
+ body: Stat[];
116
+ } | {
117
+ t: 'return';
118
+ exprs: Expr[];
119
+ } | {
120
+ t: 'break';
121
+ };
122
+ /** Parse Lua source into a chunk. Exported so a test can prove a bad script fails at PARSE time. */
123
+ export declare function parseLua(src: string): Stat[];
124
+ export declare function luaTruthy(v: LuaValue): boolean;
125
+ export declare function luaTypeName(v: LuaValue): string;
126
+ /** Lua 5.1's `%.14g` number formatting — `3` prints as "3", not "3.0". */
127
+ export declare function numberToLuaString(n: number): string;
128
+ /** `tonumber`, exactly: a number passes through, a numeric string converts, anything else is nil. */
129
+ export declare function luaToNumber(v: LuaValue, base?: number): LuaValue;
130
+ /** What the host must supply: a synchronous `redis.call`, plus KEYS/ARGV. */
131
+ export type LuaHost = {
132
+ /** Run one Redis command, called from the script's line `line`. MUST throw to abort the script the way `redis.call` does. */
133
+ call: (args: string[], line: number) => LuaValue;
134
+ keys: string[];
135
+ argv: string[];
136
+ /** The wire's environment, installed after the standard library so it may replace it: it names the command API
137
+ * (`commandApi`: call, pcall, error_reply, status_reply, sha1hex, log…) as scripts call it — Redis's scripts
138
+ * call it `redis` and `server` — and adds the runtime libraries its server loads (lua-libs.ts). */
139
+ extend?: (globals: {
140
+ get(name: string): LuaValue;
141
+ set(name: string, value: LuaValue): void;
142
+ commandApi: LuaTable;
143
+ }) => void;
144
+ /** How a Lua number becomes a `redis.call` argument; truncated toward zero when absent. */
145
+ numberArg: (n: number) => string;
146
+ };
147
+ /** Lua `==`: same type required (no string/number coercion); tables compare by identity. */
148
+ export declare function luaEquals(l: LuaValue, r: LuaValue): boolean;
149
+ /** Parse + run a script. Returns the Lua value the chunk returned (or `nil`). */
150
+ export declare function runLua(script: string, host: LuaHost): LuaValue;
151
+ /** The SHA1 real Redis keys the script cache by — the same hex digest `SCRIPT LOAD` returns. */
152
+ export declare function luaScriptSha1(script: string): string;
153
+ export {};