@seljs/env 1.0.0 → 1.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,371 @@
1
+ import { SOLIDITY_TYPES } from "@seljs/types";
2
+ //#region src/builtins.ts
3
+ /**
4
+ * Built-in CEL functions available in SEL expressions.
5
+ * These functions are part of the CEL standard library.
6
+ */
7
+ const CEL_BUILTIN_FUNCTIONS = [
8
+ {
9
+ name: "size",
10
+ signature: "size(list|map|string|bytes): int",
11
+ description: "Returns the size of a collection or string",
12
+ params: [{
13
+ name: "value",
14
+ type: "list|map|string|bytes"
15
+ }],
16
+ returns: "int"
17
+ },
18
+ {
19
+ name: "size",
20
+ signature: "string.size(): int",
21
+ description: "Returns the length of the string",
22
+ params: [],
23
+ returns: "int",
24
+ receiverType: "string"
25
+ },
26
+ {
27
+ name: "size",
28
+ signature: "list.size(): int",
29
+ description: "Returns the number of elements in the list",
30
+ params: [],
31
+ returns: "int",
32
+ receiverType: "list"
33
+ },
34
+ {
35
+ name: "size",
36
+ signature: "map.size(): int",
37
+ description: "Returns the number of entries in the map",
38
+ params: [],
39
+ returns: "int",
40
+ receiverType: "map"
41
+ },
42
+ {
43
+ name: "size",
44
+ signature: "bytes.size(): int",
45
+ description: "Returns the number of bytes",
46
+ params: [],
47
+ returns: "int",
48
+ receiverType: "bytes"
49
+ },
50
+ {
51
+ name: "type",
52
+ signature: "type(value): type",
53
+ description: "Returns the type of a value",
54
+ params: [{
55
+ name: "value",
56
+ type: "any"
57
+ }],
58
+ returns: "type"
59
+ },
60
+ {
61
+ name: "int",
62
+ signature: "int(value): int",
63
+ description: "Converts a value to an integer",
64
+ params: [{
65
+ name: "value",
66
+ type: "any"
67
+ }],
68
+ returns: "int"
69
+ },
70
+ {
71
+ name: "uint",
72
+ signature: "uint(value): uint",
73
+ description: "Converts a value to an unsigned integer",
74
+ params: [{
75
+ name: "value",
76
+ type: "any"
77
+ }],
78
+ returns: "uint"
79
+ },
80
+ {
81
+ name: "double",
82
+ signature: "double(value): double",
83
+ description: "Converts a value to a double",
84
+ params: [{
85
+ name: "value",
86
+ type: "any"
87
+ }],
88
+ returns: "double"
89
+ },
90
+ {
91
+ name: "string",
92
+ signature: "string(value): string",
93
+ description: "Converts a value to a string",
94
+ params: [{
95
+ name: "value",
96
+ type: "any"
97
+ }],
98
+ returns: "string"
99
+ },
100
+ {
101
+ name: "bytes",
102
+ signature: "bytes(value): bytes",
103
+ description: "Converts a value to bytes",
104
+ params: [{
105
+ name: "value",
106
+ type: "any"
107
+ }],
108
+ returns: "bytes"
109
+ },
110
+ {
111
+ name: "dyn",
112
+ signature: "dyn(value): dyn",
113
+ description: "Converts a value to a dynamic type",
114
+ params: [{
115
+ name: "value",
116
+ type: "any"
117
+ }],
118
+ returns: "dyn"
119
+ },
120
+ {
121
+ name: "bool",
122
+ signature: "bool(value): bool",
123
+ description: "Converts a value to a boolean",
124
+ params: [{
125
+ name: "value",
126
+ type: "string"
127
+ }],
128
+ returns: "bool"
129
+ },
130
+ {
131
+ name: "solInt",
132
+ signature: "solInt(string): sol_int",
133
+ description: "Converts a string or int to a sol_int (arbitrary-precision integer)",
134
+ params: [{
135
+ name: "value",
136
+ type: "string|int"
137
+ }],
138
+ returns: "sol_int"
139
+ },
140
+ {
141
+ name: "solAddress",
142
+ signature: "solAddress(string): sol_address",
143
+ description: "Converts a hex string to a sol_address type",
144
+ params: [{
145
+ name: "value",
146
+ type: "string"
147
+ }],
148
+ returns: "sol_address"
149
+ },
150
+ {
151
+ name: "parseUnits",
152
+ signature: "parseUnits(string|int|double|sol_int, int): sol_int",
153
+ description: "Scales a human-readable value by 10^decimals, producing a sol_int. Mirrors viem/ethers parseUnits.",
154
+ params: [{
155
+ name: "value",
156
+ type: "string|int|double|sol_int"
157
+ }, {
158
+ name: "decimals",
159
+ type: "int"
160
+ }],
161
+ returns: "sol_int"
162
+ },
163
+ {
164
+ name: "formatUnits",
165
+ signature: "formatUnits(sol_int|int, int): double",
166
+ description: "Scales a sol_int down by 10^decimals, producing a double for readable comparisons.",
167
+ params: [{
168
+ name: "value",
169
+ type: "sol_int|int"
170
+ }, {
171
+ name: "decimals",
172
+ type: "int"
173
+ }],
174
+ returns: "double"
175
+ },
176
+ {
177
+ name: "min",
178
+ signature: "min(sol_int|int, sol_int|int): sol_int",
179
+ description: "Returns the smaller of two integer values",
180
+ params: [{
181
+ name: "a",
182
+ type: "sol_int|int"
183
+ }, {
184
+ name: "b",
185
+ type: "sol_int|int"
186
+ }],
187
+ returns: "sol_int"
188
+ },
189
+ {
190
+ name: "max",
191
+ signature: "max(sol_int|int, sol_int|int): sol_int",
192
+ description: "Returns the larger of two integer values",
193
+ params: [{
194
+ name: "a",
195
+ type: "sol_int|int"
196
+ }, {
197
+ name: "b",
198
+ type: "sol_int|int"
199
+ }],
200
+ returns: "sol_int"
201
+ },
202
+ {
203
+ name: "abs",
204
+ signature: "abs(sol_int|int): sol_int",
205
+ description: "Returns the absolute value of an integer",
206
+ params: [{
207
+ name: "value",
208
+ type: "sol_int|int"
209
+ }],
210
+ returns: "sol_int"
211
+ },
212
+ {
213
+ name: "isZeroAddress",
214
+ signature: "isZeroAddress(sol_address|string): bool",
215
+ description: "Returns true if the address is the zero address (0x0000...0000)",
216
+ params: [{
217
+ name: "address",
218
+ type: "sol_address|string"
219
+ }],
220
+ returns: "bool"
221
+ },
222
+ {
223
+ name: "timestamp",
224
+ signature: "timestamp(string): timestamp",
225
+ description: "Parses a timestamp string",
226
+ params: [{
227
+ name: "value",
228
+ type: "string"
229
+ }],
230
+ returns: "timestamp"
231
+ },
232
+ {
233
+ name: "duration",
234
+ signature: "duration(string): duration",
235
+ description: "Parses a duration string",
236
+ params: [{
237
+ name: "value",
238
+ type: "string"
239
+ }],
240
+ returns: "duration"
241
+ },
242
+ {
243
+ name: "matches",
244
+ signature: "string.matches(pattern): bool",
245
+ description: "Tests if a string matches a regex pattern",
246
+ params: [{
247
+ name: "pattern",
248
+ type: "string"
249
+ }],
250
+ returns: "bool",
251
+ receiverType: "string"
252
+ },
253
+ {
254
+ name: "contains",
255
+ signature: "string.contains(substring): bool",
256
+ description: "Tests if a string contains a substring",
257
+ params: [{
258
+ name: "substring",
259
+ type: "string"
260
+ }],
261
+ returns: "bool",
262
+ receiverType: "string"
263
+ },
264
+ {
265
+ name: "startsWith",
266
+ signature: "string.startsWith(prefix): bool",
267
+ description: "Tests if a string starts with a prefix",
268
+ params: [{
269
+ name: "prefix",
270
+ type: "string"
271
+ }],
272
+ returns: "bool",
273
+ receiverType: "string"
274
+ },
275
+ {
276
+ name: "endsWith",
277
+ signature: "string.endsWith(suffix): bool",
278
+ description: "Tests if a string ends with a suffix",
279
+ params: [{
280
+ name: "suffix",
281
+ type: "string"
282
+ }],
283
+ returns: "bool",
284
+ receiverType: "string"
285
+ }
286
+ ];
287
+ /**
288
+ * Built-in CEL macros available in SEL expressions.
289
+ * Macros are syntactic sugar that expand to function calls.
290
+ */
291
+ const CEL_BUILTIN_MACROS = [
292
+ {
293
+ name: "all",
294
+ pattern: "list.all(identifier, predicate)",
295
+ description: "Returns true if all elements satisfy the predicate",
296
+ example: "tokens.all(t, t.balance > 0)"
297
+ },
298
+ {
299
+ name: "exists",
300
+ pattern: "list.exists(identifier, predicate)",
301
+ description: "Returns true if any element satisfies the predicate",
302
+ example: "users.exists(u, u.isAdmin)"
303
+ },
304
+ {
305
+ name: "exists_one",
306
+ pattern: "list.exists_one(identifier, predicate)",
307
+ description: "Returns true if exactly one element satisfies the predicate",
308
+ example: "tokens.exists_one(t, t.id == 123)"
309
+ },
310
+ {
311
+ name: "map",
312
+ pattern: "list.map(identifier, transform)",
313
+ description: "Transforms each element in the list",
314
+ example: "tokens.map(t, t.balance)"
315
+ },
316
+ {
317
+ name: "map",
318
+ pattern: "list.map(identifier, predicate, transform)",
319
+ description: "Transforms elements that satisfy the predicate",
320
+ example: "tokens.map(t, t.balance > 0, t.balance)"
321
+ },
322
+ {
323
+ name: "filter",
324
+ pattern: "list.filter(identifier, predicate)",
325
+ description: "Filters elements by predicate",
326
+ example: "users.filter(u, u.age >= 18)"
327
+ },
328
+ {
329
+ name: "has",
330
+ pattern: "has(e.f)",
331
+ description: "Tests if a field exists on an object",
332
+ example: "has(user.email)"
333
+ },
334
+ {
335
+ name: "cel.bind",
336
+ pattern: "cel.bind(var, value, expr)",
337
+ description: "Binds a variable for use in an expression",
338
+ example: "cel.bind(x, user.balance, x > 1000)"
339
+ }
340
+ ];
341
+ /**
342
+ * Primitive types from Solidity available in SEL.
343
+ * These are the basic type building blocks for the schema.
344
+ */
345
+ const SOLIDITY_PRIMITIVE_TYPES = [
346
+ ...SOLIDITY_TYPES.map((it) => {
347
+ if (it.type !== "custom") return null;
348
+ return {
349
+ name: it.name,
350
+ kind: "primitive",
351
+ description: it.schema.description
352
+ };
353
+ }).filter((it) => it !== null),
354
+ {
355
+ name: "bool",
356
+ kind: "primitive",
357
+ description: "Boolean value (true or false)"
358
+ },
359
+ {
360
+ name: "string",
361
+ kind: "primitive",
362
+ description: "UTF-8 string"
363
+ },
364
+ {
365
+ name: "bytes32",
366
+ kind: "primitive",
367
+ description: "32-byte fixed array"
368
+ }
369
+ ];
370
+ //#endregion
371
+ export { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES };
package/dist/index.cjs ADDED
@@ -0,0 +1,8 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_builtins = require("./builtins.cjs");
3
+ const require_builder = require("./builder.cjs");
4
+ exports.CEL_BUILTIN_FUNCTIONS = require_builtins.CEL_BUILTIN_FUNCTIONS;
5
+ exports.CEL_BUILTIN_MACROS = require_builtins.CEL_BUILTIN_MACROS;
6
+ exports.SOLIDITY_PRIMITIVE_TYPES = require_builtins.SOLIDITY_PRIMITIVE_TYPES;
7
+ exports.buildSchema = require_builder.buildSchema;
8
+ exports.buildStructFields = require_builder.buildStructFields;
@@ -0,0 +1,3 @@
1
+ import { BuildStructFieldsResult, ContractInput, SchemaBuilderConfig, StructTypeDefinition, buildSchema, buildStructFields } from "./builder.cjs";
2
+ import { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES } from "./builtins.cjs";
3
+ export { BuildStructFieldsResult, CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, ContractInput, SOLIDITY_PRIMITIVE_TYPES, SchemaBuilderConfig, StructTypeDefinition, buildSchema, buildStructFields };
@@ -0,0 +1,3 @@
1
+ import { BuildStructFieldsResult, ContractInput, SchemaBuilderConfig, StructTypeDefinition, buildSchema, buildStructFields } from "./builder.mjs";
2
+ import { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES } from "./builtins.mjs";
3
+ export { BuildStructFieldsResult, CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, ContractInput, SOLIDITY_PRIMITIVE_TYPES, SchemaBuilderConfig, StructTypeDefinition, buildSchema, buildStructFields };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES } from "./builtins.mjs";
2
+ import { buildSchema, buildStructFields } from "./builder.mjs";
3
+ export { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES, buildSchema, buildStructFields };
package/package.json CHANGED
@@ -1,30 +1,36 @@
1
1
  {
2
2
  "name": "@seljs/env",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
+ "repository": {
5
+ "url": "https://github.com/abinnovision/seljs"
6
+ },
4
7
  "license": "Apache-2.0",
5
8
  "author": {
6
9
  "name": "abi group GmbH",
7
10
  "email": "info@abigroup.io",
8
11
  "url": "https://abigroup.io/"
9
12
  },
10
- "repository": {
11
- "url": "https://github.com/abinnovision/seljs"
12
- },
13
13
  "type": "module",
14
14
  "exports": {
15
15
  ".": {
16
- "import": "./dist/index.js",
17
- "types": "./dist/index.d.ts"
16
+ "import": {
17
+ "types": "./dist/index.d.mts",
18
+ "default": "./dist/index.mjs"
19
+ },
20
+ "require": {
21
+ "types": "./dist/index.d.cts",
22
+ "default": "./dist/index.cjs"
23
+ }
18
24
  }
19
25
  },
20
- "main": "./dist/index.js",
21
- "types": "./dist/index.d.ts",
26
+ "main": "./dist/index.cjs",
27
+ "types": "./dist/index.d.cts",
22
28
  "files": [
23
29
  "dist",
24
30
  "LICENSE.md"
25
31
  ],
26
32
  "scripts": {
27
- "build": "tsc -p tsconfig.build.json",
33
+ "build": "tsdown",
28
34
  "format:check": "prettier --check '{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml}'",
29
35
  "format:fix": "prettier --write '{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml}'",
30
36
  "lint:check": "eslint '{{src,test}/**/*,*}.{t,j}s{,x}'",
@@ -42,9 +48,9 @@
42
48
  ]
43
49
  },
44
50
  "dependencies": {
45
- "@seljs/common": "1.0.0",
46
- "@seljs/schema": "1.0.0",
47
- "@seljs/types": "1.0.0",
51
+ "@seljs/common": "1.0.1",
52
+ "@seljs/schema": "1.0.1",
53
+ "@seljs/types": "1.0.1",
48
54
  "abitype": "^1.2.3",
49
55
  "viem": "^2.47.2"
50
56
  },
@@ -54,6 +60,7 @@
54
60
  "@seljs-internal/tsconfig": "^0.0.0",
55
61
  "eslint": "^9.39.4",
56
62
  "prettier": "^3.8.1",
63
+ "tsdown": "^0.21.3",
57
64
  "typescript": "^5.9.3",
58
65
  "vitest": "^4.0.18"
59
66
  },
package/dist/builder.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import type { SELSchema } from "@seljs/schema";
2
- import type { ContextDefinition } from "@seljs/types";
3
- import type { AbiParameter } from "abitype";
4
- import type { Abi, Address } from "viem";
5
- export interface StructTypeDefinition {
6
- typeName: string;
7
- fields: Record<string, string>;
8
- }
9
- export interface BuildStructFieldsResult {
10
- fields: Record<string, string>;
11
- nestedTypes: StructTypeDefinition[];
12
- }
13
- /**
14
- * Recursively builds struct field definitions.
15
- *
16
- * @param components Array of ABI parameters representing the components of a tuple type.
17
- * @param parentTypeName Name to use for the struct type representing the current level of nesting.
18
- */
19
- export declare const buildStructFields: (components: readonly AbiParameter[], parentTypeName: string) => BuildStructFieldsResult;
20
- export interface ContractInput {
21
- address: Address;
22
- abi: Abi;
23
- description?: string;
24
- }
25
- export interface SchemaBuilderConfig {
26
- contracts?: Record<string, ContractInput>;
27
- context?: ContextDefinition;
28
- }
29
- /**
30
- * Builds a SELSchema based on the provided configuration, which includes contract definitions and an optional context for variables.
31
- *
32
- * @param config Configuration object containing contract definitions and an optional context for variables.
33
- * @returns A SELSchema object representing the schema for the SEL environment.
34
- */
35
- export declare const buildSchema: (config: SchemaBuilderConfig) => SELSchema;
36
- //# sourceMappingURL=builder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAGX,SAAS,EAGT,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAEX,iBAAiB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,GAAG,EAAe,OAAO,EAAE,MAAM,MAAM,CAAC;AAEtD,MAAM,WAAW,oBAAoB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,uBAAuB;IACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACpC;AAiDD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC7B,YAAY,SAAS,YAAY,EAAE,EACnC,gBAAgB,MAAM,KACpB,uBAiCF,CAAC;AAoMF,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,GAAG,CAAC;IACT,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC1C,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC5B;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,mBAAmB,KAAG,SAezD,CAAC"}