@seljs/common 1.0.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 +8 -0
- package/LICENSE.md +190 -0
- package/dist/abstracts/index.d.ts +2 -0
- package/dist/abstracts/index.d.ts.map +1 -0
- package/dist/abstracts/index.js +1 -0
- package/dist/abstracts/registry.d.ts +41 -0
- package/dist/abstracts/registry.d.ts.map +1 -0
- package/dist/abstracts/registry.js +39 -0
- package/dist/abstracts/registry.test.d.ts +2 -0
- package/dist/abstracts/registry.test.d.ts.map +1 -0
- package/dist/abstracts/registry.test.js +57 -0
- package/dist/ast.d.ts +10 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +12 -0
- package/dist/errors/base.d.ts +9 -0
- package/dist/errors/base.d.ts.map +1 -0
- package/dist/errors/base.js +16 -0
- package/dist/errors/base.test.d.ts +2 -0
- package/dist/errors/base.test.d.ts.map +1 -0
- package/dist/errors/base.test.js +39 -0
- package/dist/errors/errors.d.ts +14 -0
- package/dist/errors/errors.d.ts.map +1 -0
- package/dist/errors/errors.js +13 -0
- package/dist/errors/errors.test.d.ts +2 -0
- package/dist/errors/errors.test.d.ts.map +1 -0
- package/dist/errors/errors.test.js +104 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/utils.d.ts +11 -0
- package/dist/errors/utils.d.ts.map +1 -0
- package/dist/errors/utils.js +6 -0
- package/dist/errors/utils.test.d.ts +2 -0
- package/dist/errors/utils.test.d.ts.map +1 -0
- package/dist/errors/utils.test.js +17 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/naming.d.ts +14 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +13 -0
- package/dist/naming.test.d.ts +2 -0
- package/dist/naming.test.d.ts.map +1 -0
- package/dist/naming.test.js +14 -0
- package/package.json +60 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 abi group GmbH
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/abstracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./registry.js";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base registry providing a generic Map-based store
|
|
3
|
+
* with lookup by name.
|
|
4
|
+
*
|
|
5
|
+
* Subclasses implement `register()` to handle domain-specific
|
|
6
|
+
* validation and transformation before storing entries.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam TConfig - The input configuration type for registration
|
|
9
|
+
* @typeParam TEntry - The stored entry type (what gets retrieved)
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class Registry<TConfig, TEntry> {
|
|
12
|
+
protected readonly entries: Map<string, TEntry>;
|
|
13
|
+
/**
|
|
14
|
+
* Register an entry with domain-specific validation/transformation.
|
|
15
|
+
*
|
|
16
|
+
* @param name - Unique identifier for the entry
|
|
17
|
+
* @param config - Configuration to transform into a stored entry
|
|
18
|
+
* @returns this for method chaining
|
|
19
|
+
*/
|
|
20
|
+
abstract register(name: string, config: TConfig): this;
|
|
21
|
+
/**
|
|
22
|
+
* Get a registered entry by name.
|
|
23
|
+
*
|
|
24
|
+
* @param name - The entry identifier
|
|
25
|
+
* @returns The stored entry, or undefined if not found
|
|
26
|
+
*/
|
|
27
|
+
get(name: string): TEntry | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Get all registered entries.
|
|
30
|
+
*
|
|
31
|
+
* @returns Array of all stored entries
|
|
32
|
+
*/
|
|
33
|
+
getAll(): TEntry[];
|
|
34
|
+
/**
|
|
35
|
+
* Check whether an entry with the given name exists.
|
|
36
|
+
*
|
|
37
|
+
* @param name - The entry identifier
|
|
38
|
+
*/
|
|
39
|
+
has(name: string): boolean;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/abstracts/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,8BAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM;IAC7C,SAAS,CAAC,QAAQ,CAAC,OAAO,sBAA6B;IAEvD;;;;;;OAMG;aACa,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAE7D;;;;;OAKG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI5C;;;;OAIG;IACI,MAAM,IAAI,MAAM,EAAE;IAIzB;;;;OAIG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAGjC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base registry providing a generic Map-based store
|
|
3
|
+
* with lookup by name.
|
|
4
|
+
*
|
|
5
|
+
* Subclasses implement `register()` to handle domain-specific
|
|
6
|
+
* validation and transformation before storing entries.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam TConfig - The input configuration type for registration
|
|
9
|
+
* @typeParam TEntry - The stored entry type (what gets retrieved)
|
|
10
|
+
*/
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
12
|
+
export class Registry {
|
|
13
|
+
entries = new Map();
|
|
14
|
+
/**
|
|
15
|
+
* Get a registered entry by name.
|
|
16
|
+
*
|
|
17
|
+
* @param name - The entry identifier
|
|
18
|
+
* @returns The stored entry, or undefined if not found
|
|
19
|
+
*/
|
|
20
|
+
get(name) {
|
|
21
|
+
return this.entries.get(name);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get all registered entries.
|
|
25
|
+
*
|
|
26
|
+
* @returns Array of all stored entries
|
|
27
|
+
*/
|
|
28
|
+
getAll() {
|
|
29
|
+
return Array.from(this.entries.values());
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check whether an entry with the given name exists.
|
|
33
|
+
*
|
|
34
|
+
* @param name - The entry identifier
|
|
35
|
+
*/
|
|
36
|
+
has(name) {
|
|
37
|
+
return this.entries.has(name);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.test.d.ts","sourceRoot":"","sources":["../../src/abstracts/registry.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { Registry } from "./registry.js";
|
|
3
|
+
class TestRegistry extends Registry {
|
|
4
|
+
register(name, config) {
|
|
5
|
+
this.entries.set(name, { name, value: config.value });
|
|
6
|
+
return this;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
describe("registry", () => {
|
|
10
|
+
it("should register and retrieve an entry", () => {
|
|
11
|
+
const registry = new TestRegistry();
|
|
12
|
+
registry.register("test", { value: "hello" });
|
|
13
|
+
const entry = registry.get("test");
|
|
14
|
+
expect(entry).toEqual({ name: "test", value: "hello" });
|
|
15
|
+
});
|
|
16
|
+
it("should return undefined for unknown entries", () => {
|
|
17
|
+
const registry = new TestRegistry();
|
|
18
|
+
expect(registry.get("unknown")).toBeUndefined();
|
|
19
|
+
});
|
|
20
|
+
it("should check entry existence with has()", () => {
|
|
21
|
+
const registry = new TestRegistry();
|
|
22
|
+
registry.register("test", { value: "hello" });
|
|
23
|
+
expect(registry.has("test")).toBe(true);
|
|
24
|
+
expect(registry.has("unknown")).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
it("should return all entries with getAll()", () => {
|
|
27
|
+
const registry = new TestRegistry();
|
|
28
|
+
registry.register("a", { value: "1" });
|
|
29
|
+
registry.register("b", { value: "2" });
|
|
30
|
+
const entries = registry.getAll();
|
|
31
|
+
expect(entries).toHaveLength(2);
|
|
32
|
+
expect(entries).toEqual(expect.arrayContaining([
|
|
33
|
+
{ name: "a", value: "1" },
|
|
34
|
+
{ name: "b", value: "2" },
|
|
35
|
+
]));
|
|
36
|
+
});
|
|
37
|
+
it("should return empty array when no entries registered", () => {
|
|
38
|
+
const registry = new TestRegistry();
|
|
39
|
+
expect(registry.getAll()).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
it("should overwrite entry on duplicate key registration", () => {
|
|
42
|
+
const registry = new TestRegistry();
|
|
43
|
+
registry.register("test", { value: "first" });
|
|
44
|
+
registry.register("test", { value: "second" });
|
|
45
|
+
const entry = registry.get("test");
|
|
46
|
+
expect(entry).toEqual({ name: "test", value: "second" });
|
|
47
|
+
expect(registry.getAll()).toHaveLength(1);
|
|
48
|
+
});
|
|
49
|
+
it("should support method chaining from register()", () => {
|
|
50
|
+
const registry = new TestRegistry();
|
|
51
|
+
const result = registry
|
|
52
|
+
.register("a", { value: "1" })
|
|
53
|
+
.register("b", { value: "2" });
|
|
54
|
+
expect(result).toBe(registry);
|
|
55
|
+
expect(registry.getAll()).toHaveLength(2);
|
|
56
|
+
});
|
|
57
|
+
});
|
package/dist/ast.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ASTNode } from "@marcbachmann/cel-js";
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether a value is a CEL AST node with `op` and `args` fields.
|
|
4
|
+
*
|
|
5
|
+
* Needed as a runtime guard when traversing into `args` branches that
|
|
6
|
+
* may contain primitives (e.g. string for `id`, LiteralValue for `value`)
|
|
7
|
+
* alongside nested AST nodes.
|
|
8
|
+
*/
|
|
9
|
+
export declare const isAstNode: (value: unknown) => value is ASTNode;
|
|
10
|
+
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,OAKF,CAAC"}
|
package/dist/ast.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a value is a CEL AST node with `op` and `args` fields.
|
|
3
|
+
*
|
|
4
|
+
* Needed as a runtime guard when traversing into `args` branches that
|
|
5
|
+
* may contain primitives (e.g. string for `id`, LiteralValue for `value`)
|
|
6
|
+
* alongside nested AST nodes.
|
|
7
|
+
*/
|
|
8
|
+
export const isAstNode = (value) => typeof value === "object" &&
|
|
9
|
+
value !== null &&
|
|
10
|
+
"op" in value &&
|
|
11
|
+
"args" in value &&
|
|
12
|
+
typeof value.op === "string";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for SEL (Solidity Expression Language).
|
|
3
|
+
* All SEL errors extend this class, enabling catch-all handling
|
|
4
|
+
* via `instanceof SELError`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SELError extends Error {
|
|
7
|
+
constructor(message: string, options?: ErrorOptions);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/errors/base.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,KAAK;gBACf,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAS1D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { hasCaptureStackTrace } from "./utils.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base error class for SEL (Solidity Expression Language).
|
|
4
|
+
* All SEL errors extend this class, enabling catch-all handling
|
|
5
|
+
* via `instanceof SELError`.
|
|
6
|
+
*/
|
|
7
|
+
export class SELError extends Error {
|
|
8
|
+
constructor(message, options) {
|
|
9
|
+
super(message, options);
|
|
10
|
+
this.name = this.constructor.name;
|
|
11
|
+
// Capture stack trace for better debugging (V8 engines).
|
|
12
|
+
if (hasCaptureStackTrace(Error)) {
|
|
13
|
+
Error.captureStackTrace(this, this.constructor);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.test.d.ts","sourceRoot":"","sources":["../../src/errors/base.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { SELError } from "./base.js";
|
|
3
|
+
describe("sELError", () => {
|
|
4
|
+
it("should be an instance of Error", () => {
|
|
5
|
+
const error = new SELError("test message");
|
|
6
|
+
expect(error instanceof Error).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
it("should be an instance of SELError", () => {
|
|
9
|
+
const error = new SELError("test message");
|
|
10
|
+
expect(error instanceof SELError).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
it("should have correct name property", () => {
|
|
13
|
+
const error = new SELError("test message");
|
|
14
|
+
expect(error.name).toBe("SELError");
|
|
15
|
+
});
|
|
16
|
+
it("should have correct message property", () => {
|
|
17
|
+
const error = new SELError("test message");
|
|
18
|
+
expect(error.message).toBe("test message");
|
|
19
|
+
});
|
|
20
|
+
it("should support cause option", () => {
|
|
21
|
+
const originalError = new Error("original");
|
|
22
|
+
const error = new SELError("wrapped", { cause: originalError });
|
|
23
|
+
expect(error.cause).toBe(originalError);
|
|
24
|
+
});
|
|
25
|
+
it("should work without cause option", () => {
|
|
26
|
+
const error = new SELError("test message");
|
|
27
|
+
expect(error.cause).toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
it("should have a stack trace", () => {
|
|
30
|
+
const error = new SELError("test message");
|
|
31
|
+
expect(error.stack).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
it("should use subclass name when extended", () => {
|
|
34
|
+
class CustomError extends SELError {
|
|
35
|
+
}
|
|
36
|
+
const error = new CustomError("test");
|
|
37
|
+
expect(error.name).toBe("CustomError");
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SELError } from "./base.js";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when CEL expression parsing fails.
|
|
4
|
+
* Wraps cel-js ParseError with additional context.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SELParseError extends SELError {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Thrown when Solidity type validation fails.
|
|
10
|
+
* Used for type checking errors specific to Solidity types.
|
|
11
|
+
*/
|
|
12
|
+
export declare class SELTypeError extends SELError {
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;;GAGG;AACH,qBAAa,aAAc,SAAQ,QAAQ;CAAG;AAE9C;;;GAGG;AACH,qBAAa,YAAa,SAAQ,QAAQ;CAAG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SELError } from "./base.js";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when CEL expression parsing fails.
|
|
4
|
+
* Wraps cel-js ParseError with additional context.
|
|
5
|
+
*/
|
|
6
|
+
export class SELParseError extends SELError {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Thrown when Solidity type validation fails.
|
|
10
|
+
* Used for type checking errors specific to Solidity types.
|
|
11
|
+
*/
|
|
12
|
+
export class SELTypeError extends SELError {
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../../src/errors/errors.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { SELError } from "./base.js";
|
|
3
|
+
import { SELParseError, SELTypeError } from "./errors.js";
|
|
4
|
+
describe("sELParseError", () => {
|
|
5
|
+
it("should be an instance of Error", () => {
|
|
6
|
+
const error = new SELParseError("test message");
|
|
7
|
+
expect(error instanceof Error).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
it("should be an instance of SELParseError", () => {
|
|
10
|
+
const error = new SELParseError("test message");
|
|
11
|
+
expect(error instanceof SELParseError).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
it("should be an instance of SELError", () => {
|
|
14
|
+
const error = new SELParseError("test message");
|
|
15
|
+
expect(error instanceof SELError).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
it("should have correct name property", () => {
|
|
18
|
+
const error = new SELParseError("test message");
|
|
19
|
+
expect(error.name).toBe("SELParseError");
|
|
20
|
+
});
|
|
21
|
+
it("should have correct message property", () => {
|
|
22
|
+
const error = new SELParseError("test message");
|
|
23
|
+
expect(error.message).toBe("test message");
|
|
24
|
+
});
|
|
25
|
+
it("should support cause option", () => {
|
|
26
|
+
const originalError = new Error("original");
|
|
27
|
+
const error = new SELParseError("wrapped", { cause: originalError });
|
|
28
|
+
expect(error.cause).toBe(originalError);
|
|
29
|
+
});
|
|
30
|
+
it("should work without cause option", () => {
|
|
31
|
+
const error = new SELParseError("test message");
|
|
32
|
+
expect(error.cause).toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe("sELTypeError", () => {
|
|
36
|
+
it("should be an instance of Error", () => {
|
|
37
|
+
const error = new SELTypeError("test message");
|
|
38
|
+
expect(error instanceof Error).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
it("should be an instance of SELTypeError", () => {
|
|
41
|
+
const error = new SELTypeError("test message");
|
|
42
|
+
expect(error instanceof SELTypeError).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
it("should be an instance of SELError", () => {
|
|
45
|
+
const error = new SELTypeError("test message");
|
|
46
|
+
expect(error instanceof SELError).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
it("should have correct name property", () => {
|
|
49
|
+
const error = new SELTypeError("test message");
|
|
50
|
+
expect(error.name).toBe("SELTypeError");
|
|
51
|
+
});
|
|
52
|
+
it("should have correct message property", () => {
|
|
53
|
+
const error = new SELTypeError("test message");
|
|
54
|
+
expect(error.message).toBe("test message");
|
|
55
|
+
});
|
|
56
|
+
it("should support cause option", () => {
|
|
57
|
+
const originalError = new Error("original");
|
|
58
|
+
const error = new SELTypeError("wrapped", { cause: originalError });
|
|
59
|
+
expect(error.cause).toBe(originalError);
|
|
60
|
+
});
|
|
61
|
+
it("should work without cause option", () => {
|
|
62
|
+
const error = new SELTypeError("test message");
|
|
63
|
+
expect(error.cause).toBeUndefined();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe("error class distinctions", () => {
|
|
67
|
+
it("should distinguish between different error types", () => {
|
|
68
|
+
const parseError = new SELParseError("parse");
|
|
69
|
+
const typeError = new SELTypeError("type");
|
|
70
|
+
expect(parseError instanceof SELParseError).toBe(true);
|
|
71
|
+
expect(parseError instanceof SELTypeError).toBe(false);
|
|
72
|
+
expect(typeError instanceof SELTypeError).toBe(true);
|
|
73
|
+
expect(typeError instanceof SELParseError).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
it("should all be instances of SELError and Error", () => {
|
|
76
|
+
const parseError = new SELParseError("parse");
|
|
77
|
+
const typeError = new SELTypeError("type");
|
|
78
|
+
expect(parseError instanceof SELError).toBe(true);
|
|
79
|
+
expect(typeError instanceof SELError).toBe(true);
|
|
80
|
+
expect(parseError instanceof Error).toBe(true);
|
|
81
|
+
expect(typeError instanceof Error).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe("error wrapping with cause", () => {
|
|
85
|
+
it("should wrap multiple levels of errors", () => {
|
|
86
|
+
const originalError = new Error("original");
|
|
87
|
+
const wrappedError = new SELParseError("wrapped", {
|
|
88
|
+
cause: originalError,
|
|
89
|
+
});
|
|
90
|
+
const finalError = new SELTypeError("final", {
|
|
91
|
+
cause: wrappedError,
|
|
92
|
+
});
|
|
93
|
+
expect(finalError.cause).toBe(wrappedError);
|
|
94
|
+
expect(finalError.cause.cause).toBe(originalError);
|
|
95
|
+
});
|
|
96
|
+
it("should preserve error messages through wrapping", () => {
|
|
97
|
+
const originalError = new Error("original message");
|
|
98
|
+
const wrappedError = new SELParseError("wrapped message", {
|
|
99
|
+
cause: originalError,
|
|
100
|
+
});
|
|
101
|
+
expect(wrappedError.message).toBe("wrapped message");
|
|
102
|
+
expect(wrappedError.cause.message).toBe("original message");
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type ErrorWithCaptureStackTrace = typeof Error & {
|
|
2
|
+
captureStackTrace: (target: object, constructor: unknown) => void;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Type guard to check if the Error constructor has the captureStackTrace method.
|
|
6
|
+
*
|
|
7
|
+
* @param error
|
|
8
|
+
*/
|
|
9
|
+
export declare const hasCaptureStackTrace: (error: typeof Error) => error is ErrorWithCaptureStackTrace;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/errors/utils.ts"],"names":[],"mappings":"AAAA,KAAK,0BAA0B,GAAG,OAAO,KAAK,GAAG;IAChD,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;CAClE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAChC,OAAO,OAAO,KAAK,KACjB,KAAK,IAAI,0BAA0D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../src/errors/utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { hasCaptureStackTrace } from "./utils.js";
|
|
3
|
+
describe("hasCaptureStackTrace", () => {
|
|
4
|
+
it("should return true in V8 environments (Node.js)", () => {
|
|
5
|
+
expect(hasCaptureStackTrace(Error)).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
it("should narrow the type to include captureStackTrace", () => {
|
|
8
|
+
expect(typeof Error.captureStackTrace).toBe("function");
|
|
9
|
+
});
|
|
10
|
+
it("should return false for objects without captureStackTrace", () => {
|
|
11
|
+
// Create a minimal object that looks like typeof Error but lacks captureStackTrace
|
|
12
|
+
const fakeError = {
|
|
13
|
+
prototype: Error.prototype,
|
|
14
|
+
};
|
|
15
|
+
expect(hasCaptureStackTrace(fakeError)).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|
package/dist/index.js
ADDED
package/dist/naming.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates the CEL type name for a contract.
|
|
3
|
+
*
|
|
4
|
+
* @param contractName Raw name of the contract.
|
|
5
|
+
*/
|
|
6
|
+
export declare const contractTypeName: (contractName: string) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Generates the CEL type name for a struct return type.
|
|
9
|
+
*
|
|
10
|
+
* @param contractName Raw name of the contract.
|
|
11
|
+
* @param functionName Raw name of the method.
|
|
12
|
+
*/
|
|
13
|
+
export declare const structTypeName: (contractName: string, functionName: string) => string;
|
|
14
|
+
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../src/naming.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,cAAc,MAAM,KAAG,MACzB,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAC1B,cAAc,MAAM,EACpB,cAAc,MAAM,KAClB,MAAsD,CAAC"}
|
package/dist/naming.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates the CEL type name for a contract.
|
|
3
|
+
*
|
|
4
|
+
* @param contractName Raw name of the contract.
|
|
5
|
+
*/
|
|
6
|
+
export const contractTypeName = (contractName) => `SEL_Contract_${contractName}`;
|
|
7
|
+
/**
|
|
8
|
+
* Generates the CEL type name for a struct return type.
|
|
9
|
+
*
|
|
10
|
+
* @param contractName Raw name of the contract.
|
|
11
|
+
* @param functionName Raw name of the method.
|
|
12
|
+
*/
|
|
13
|
+
export const structTypeName = (contractName, functionName) => `SEL_Struct_${contractName}_${functionName}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.test.d.ts","sourceRoot":"","sources":["../src/naming.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { contractTypeName, structTypeName } from "./naming.js";
|
|
3
|
+
describe("src/naming.ts", () => {
|
|
4
|
+
describe("contractTypeName", () => {
|
|
5
|
+
it("generates contract type name", () => {
|
|
6
|
+
expect(contractTypeName("pool")).toBe("SEL_Contract_pool");
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
describe("structTypeName", () => {
|
|
10
|
+
it("generates struct type name for contract and method", () => {
|
|
11
|
+
expect(structTypeName("pool", "getPool")).toBe("SEL_Struct_pool_getPool");
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@seljs/common",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "abi group GmbH",
|
|
7
|
+
"email": "info@abigroup.io",
|
|
8
|
+
"url": "https://abigroup.io/"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"url": "https://github.com/abinnovision/seljs"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"LICENSE.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -p tsconfig.build.json",
|
|
28
|
+
"format:check": "prettier --check '{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml}'",
|
|
29
|
+
"format:fix": "prettier --write '{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml}'",
|
|
30
|
+
"lint:check": "eslint '{{src,test}/**/*,*}.{t,j}s{,x}'",
|
|
31
|
+
"lint:fix": "eslint '{{src,test}/**/*,*}.{t,j}s{,x}' --fix",
|
|
32
|
+
"test-unit": "vitest run",
|
|
33
|
+
"test-unit:watch": "vitest watch",
|
|
34
|
+
"typecheck": "tsc --noEmit"
|
|
35
|
+
},
|
|
36
|
+
"lint-staged": {
|
|
37
|
+
"{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml}": [
|
|
38
|
+
"prettier --write"
|
|
39
|
+
],
|
|
40
|
+
"{{src,test}/**/*,*}.{t,j}s{,x}": [
|
|
41
|
+
"eslint --fix"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@marcbachmann/cel-js": "^7.5.2"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@abinnovision/eslint-config-base": "^3.2.0",
|
|
49
|
+
"@abinnovision/prettier-config": "^2.1.5",
|
|
50
|
+
"@seljs-internal/tsconfig": "^0.0.0",
|
|
51
|
+
"eslint": "^9.39.4",
|
|
52
|
+
"prettier": "^3.8.1",
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"vitest": "^4.0.18"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"npm": true,
|
|
58
|
+
"npmAccess": "public"
|
|
59
|
+
}
|
|
60
|
+
}
|