@showwhat/core 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/LICENSE +21 -0
- package/README.md +58 -0
- package/dist/index.d.ts +413 -0
- package/dist/index.js +800 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gerald Yeo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @showwhat/core
|
|
2
|
+
|
|
3
|
+
> **Most users should install [`showwhat`](../showwhat) instead.** This package contains the low-level engine internals. The `showwhat` package re-exports everything from `@showwhat/core` and adds the main `showwhat()` entry point.
|
|
4
|
+
|
|
5
|
+
Low-level condition engine and schemas for **showwhat** - a lightweight, extensible feature flag library.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @showwhat/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { MemoryData, resolve, builtinEvaluators } from "@showwhat/core";
|
|
17
|
+
|
|
18
|
+
const data = await MemoryData.fromObject({
|
|
19
|
+
definitions: {
|
|
20
|
+
checkout_v2: {
|
|
21
|
+
variations: [{ value: true, conditions: [{ type: "env", value: "prod" }] }, { value: false }],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const def = await data.get("checkout_v2");
|
|
27
|
+
|
|
28
|
+
const result = await resolve({
|
|
29
|
+
definitions: { checkout_v2: def! },
|
|
30
|
+
context: { env: "prod" },
|
|
31
|
+
options: { evaluators: builtinEvaluators },
|
|
32
|
+
});
|
|
33
|
+
console.log(result.checkout_v2.value); // true
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
> **Note:** The resolver is strict — evaluators must be passed explicitly. There is no default evaluator set injected automatically.
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- Built-in condition types: `string`, `number`, `datetime`, `bool`, `env`, `startAt`, `endAt`
|
|
41
|
+
- Composite conditions with `and`/`or` logic
|
|
42
|
+
- Custom condition types via `registerEvaluators()`
|
|
43
|
+
- YAML and JSON parsing with schema validation
|
|
44
|
+
- Pluggable data sources (`DefinitionReader` / `DefinitionWriter`)
|
|
45
|
+
- Typed error hierarchy
|
|
46
|
+
- Preset condition shortcuts
|
|
47
|
+
|
|
48
|
+
## Documentation
|
|
49
|
+
|
|
50
|
+
- [Quick Start](https://showwhat.yeojz.dev/docs/) — installation and first definition
|
|
51
|
+
- [Conditions](https://showwhat.yeojz.dev/docs/conditions) — built-in condition types and usage
|
|
52
|
+
- [Context](https://showwhat.yeojz.dev/docs/context) — runtime context object
|
|
53
|
+
- [Definitions](https://showwhat.yeojz.dev/docs/definitions) — definition structure and variations
|
|
54
|
+
- [Core API](https://showwhat.yeojz.dev/docs/core) — `showwhat()`, `resolve()`, parsing, and more
|
|
55
|
+
- [Errors](https://showwhat.yeojz.dev/docs/errors) — error types and when they are thrown
|
|
56
|
+
- [Custom Conditions](https://showwhat.yeojz.dev/docs/custom-conditions) — writing your own evaluators
|
|
57
|
+
- [Custom Data Sources](https://showwhat.yeojz.dev/docs/custom-data-sources) — implementing `DefinitionReader`
|
|
58
|
+
- [MemoryData](https://showwhat.yeojz.dev/docs/memory) — in-memory data source
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { ZodError, z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare class ShowwhatError extends Error {
|
|
4
|
+
constructor(message: string);
|
|
5
|
+
}
|
|
6
|
+
declare class ParseError extends ShowwhatError {
|
|
7
|
+
readonly line?: number | undefined;
|
|
8
|
+
constructor(message: string, line?: number | undefined);
|
|
9
|
+
}
|
|
10
|
+
declare class ValidationError extends ShowwhatError {
|
|
11
|
+
readonly issues: ZodError["issues"];
|
|
12
|
+
constructor(message: string, context?: string);
|
|
13
|
+
}
|
|
14
|
+
declare class SchemaValidationError extends ValidationError {
|
|
15
|
+
constructor(zodError: ZodError, context?: string);
|
|
16
|
+
}
|
|
17
|
+
declare class DefinitionNotFoundError extends ShowwhatError {
|
|
18
|
+
readonly key: string;
|
|
19
|
+
constructor(key: string);
|
|
20
|
+
}
|
|
21
|
+
declare class DefinitionInactiveError extends ShowwhatError {
|
|
22
|
+
readonly key: string;
|
|
23
|
+
constructor(key: string);
|
|
24
|
+
}
|
|
25
|
+
declare class VariationNotFoundError extends ShowwhatError {
|
|
26
|
+
readonly key: string;
|
|
27
|
+
constructor(key: string);
|
|
28
|
+
}
|
|
29
|
+
declare class InvalidContextError extends ShowwhatError {
|
|
30
|
+
readonly key: string;
|
|
31
|
+
readonly value: string | number | boolean;
|
|
32
|
+
constructor(key: string, value: string | number | boolean);
|
|
33
|
+
}
|
|
34
|
+
declare class DataError extends ShowwhatError {
|
|
35
|
+
readonly cause?: unknown | undefined;
|
|
36
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare const PRIMITIVE_CONDITION_TYPES: {
|
|
40
|
+
readonly string: "string";
|
|
41
|
+
readonly number: "number";
|
|
42
|
+
readonly bool: "bool";
|
|
43
|
+
readonly datetime: "datetime";
|
|
44
|
+
};
|
|
45
|
+
type PrimitiveConditionType = (typeof PRIMITIVE_CONDITION_TYPES)[keyof typeof PRIMITIVE_CONDITION_TYPES];
|
|
46
|
+
declare const CONDITION_TYPES: {
|
|
47
|
+
readonly env: "env";
|
|
48
|
+
readonly startAt: "startAt";
|
|
49
|
+
readonly endAt: "endAt";
|
|
50
|
+
readonly and: "and";
|
|
51
|
+
readonly or: "or";
|
|
52
|
+
readonly string: "string";
|
|
53
|
+
readonly number: "number";
|
|
54
|
+
readonly bool: "bool";
|
|
55
|
+
readonly datetime: "datetime";
|
|
56
|
+
};
|
|
57
|
+
declare const CONTEXT_KEYS: {
|
|
58
|
+
readonly env: "env";
|
|
59
|
+
readonly at: "at";
|
|
60
|
+
};
|
|
61
|
+
declare const StringConditionSchema: z.ZodObject<{
|
|
62
|
+
id: z.ZodOptional<z.ZodString>;
|
|
63
|
+
type: z.ZodLiteral<"string">;
|
|
64
|
+
key: z.ZodString;
|
|
65
|
+
op: z.ZodEnum<{
|
|
66
|
+
eq: "eq";
|
|
67
|
+
neq: "neq";
|
|
68
|
+
in: "in";
|
|
69
|
+
nin: "nin";
|
|
70
|
+
regex: "regex";
|
|
71
|
+
}>;
|
|
72
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
type StringCondition = z.infer<typeof StringConditionSchema>;
|
|
75
|
+
declare const NumberConditionSchema: z.ZodObject<{
|
|
76
|
+
id: z.ZodOptional<z.ZodString>;
|
|
77
|
+
type: z.ZodLiteral<"number">;
|
|
78
|
+
key: z.ZodString;
|
|
79
|
+
op: z.ZodEnum<{
|
|
80
|
+
eq: "eq";
|
|
81
|
+
neq: "neq";
|
|
82
|
+
in: "in";
|
|
83
|
+
nin: "nin";
|
|
84
|
+
gt: "gt";
|
|
85
|
+
gte: "gte";
|
|
86
|
+
lt: "lt";
|
|
87
|
+
lte: "lte";
|
|
88
|
+
}>;
|
|
89
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodArray<z.ZodNumber>]>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
type NumberCondition = z.infer<typeof NumberConditionSchema>;
|
|
92
|
+
declare const DatetimeConditionSchema: z.ZodObject<{
|
|
93
|
+
id: z.ZodOptional<z.ZodString>;
|
|
94
|
+
type: z.ZodLiteral<"datetime">;
|
|
95
|
+
key: z.ZodString;
|
|
96
|
+
op: z.ZodEnum<{
|
|
97
|
+
eq: "eq";
|
|
98
|
+
gt: "gt";
|
|
99
|
+
gte: "gte";
|
|
100
|
+
lt: "lt";
|
|
101
|
+
lte: "lte";
|
|
102
|
+
}>;
|
|
103
|
+
value: z.ZodISODateTime;
|
|
104
|
+
}, z.core.$strip>;
|
|
105
|
+
type DatetimeCondition = z.infer<typeof DatetimeConditionSchema>;
|
|
106
|
+
declare const BoolConditionSchema: z.ZodObject<{
|
|
107
|
+
id: z.ZodOptional<z.ZodString>;
|
|
108
|
+
type: z.ZodLiteral<"bool">;
|
|
109
|
+
key: z.ZodString;
|
|
110
|
+
op: z.ZodOptional<z.ZodLiteral<"eq">>;
|
|
111
|
+
value: z.ZodBoolean;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
type BoolCondition = z.infer<typeof BoolConditionSchema>;
|
|
114
|
+
declare const EnvConditionSchema: z.ZodObject<{
|
|
115
|
+
id: z.ZodOptional<z.ZodString>;
|
|
116
|
+
type: z.ZodLiteral<"env">;
|
|
117
|
+
op: z.ZodOptional<z.ZodLiteral<"eq">>;
|
|
118
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
119
|
+
}, z.core.$strip>;
|
|
120
|
+
type EnvCondition = z.infer<typeof EnvConditionSchema>;
|
|
121
|
+
declare const StartAtConditionSchema: z.ZodObject<{
|
|
122
|
+
id: z.ZodOptional<z.ZodString>;
|
|
123
|
+
type: z.ZodLiteral<"startAt">;
|
|
124
|
+
value: z.ZodISODateTime;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
type StartAtCondition = z.infer<typeof StartAtConditionSchema>;
|
|
127
|
+
declare const EndAtConditionSchema: z.ZodObject<{
|
|
128
|
+
id: z.ZodOptional<z.ZodString>;
|
|
129
|
+
type: z.ZodLiteral<"endAt">;
|
|
130
|
+
value: z.ZodISODateTime;
|
|
131
|
+
}, z.core.$strip>;
|
|
132
|
+
type EndAtCondition = z.infer<typeof EndAtConditionSchema>;
|
|
133
|
+
declare const BuiltinConditionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
134
|
+
id: z.ZodOptional<z.ZodString>;
|
|
135
|
+
type: z.ZodLiteral<"string">;
|
|
136
|
+
key: z.ZodString;
|
|
137
|
+
op: z.ZodEnum<{
|
|
138
|
+
eq: "eq";
|
|
139
|
+
neq: "neq";
|
|
140
|
+
in: "in";
|
|
141
|
+
nin: "nin";
|
|
142
|
+
regex: "regex";
|
|
143
|
+
}>;
|
|
144
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
145
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
146
|
+
id: z.ZodOptional<z.ZodString>;
|
|
147
|
+
type: z.ZodLiteral<"number">;
|
|
148
|
+
key: z.ZodString;
|
|
149
|
+
op: z.ZodEnum<{
|
|
150
|
+
eq: "eq";
|
|
151
|
+
neq: "neq";
|
|
152
|
+
in: "in";
|
|
153
|
+
nin: "nin";
|
|
154
|
+
gt: "gt";
|
|
155
|
+
gte: "gte";
|
|
156
|
+
lt: "lt";
|
|
157
|
+
lte: "lte";
|
|
158
|
+
}>;
|
|
159
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodArray<z.ZodNumber>]>;
|
|
160
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
161
|
+
id: z.ZodOptional<z.ZodString>;
|
|
162
|
+
type: z.ZodLiteral<"datetime">;
|
|
163
|
+
key: z.ZodString;
|
|
164
|
+
op: z.ZodEnum<{
|
|
165
|
+
eq: "eq";
|
|
166
|
+
gt: "gt";
|
|
167
|
+
gte: "gte";
|
|
168
|
+
lt: "lt";
|
|
169
|
+
lte: "lte";
|
|
170
|
+
}>;
|
|
171
|
+
value: z.ZodISODateTime;
|
|
172
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
173
|
+
id: z.ZodOptional<z.ZodString>;
|
|
174
|
+
type: z.ZodLiteral<"bool">;
|
|
175
|
+
key: z.ZodString;
|
|
176
|
+
op: z.ZodOptional<z.ZodLiteral<"eq">>;
|
|
177
|
+
value: z.ZodBoolean;
|
|
178
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
179
|
+
id: z.ZodOptional<z.ZodString>;
|
|
180
|
+
type: z.ZodLiteral<"env">;
|
|
181
|
+
op: z.ZodOptional<z.ZodLiteral<"eq">>;
|
|
182
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
183
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
184
|
+
id: z.ZodOptional<z.ZodString>;
|
|
185
|
+
type: z.ZodLiteral<"startAt">;
|
|
186
|
+
value: z.ZodISODateTime;
|
|
187
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
188
|
+
id: z.ZodOptional<z.ZodString>;
|
|
189
|
+
type: z.ZodLiteral<"endAt">;
|
|
190
|
+
value: z.ZodISODateTime;
|
|
191
|
+
}, z.core.$strip>], "type">;
|
|
192
|
+
type BuiltinCondition = z.infer<typeof BuiltinConditionSchema>;
|
|
193
|
+
type Condition = BuiltinCondition | {
|
|
194
|
+
id?: string;
|
|
195
|
+
type: "and";
|
|
196
|
+
conditions: Condition[];
|
|
197
|
+
} | {
|
|
198
|
+
id?: string;
|
|
199
|
+
type: "or";
|
|
200
|
+
conditions: Condition[];
|
|
201
|
+
} | {
|
|
202
|
+
type: string;
|
|
203
|
+
[key: string]: unknown;
|
|
204
|
+
};
|
|
205
|
+
declare const AndConditionSchema: z.ZodObject<{
|
|
206
|
+
id: z.ZodOptional<z.ZodString>;
|
|
207
|
+
type: z.ZodLiteral<"and">;
|
|
208
|
+
conditions: z.ZodArray<z.ZodLazy<z.ZodType<Condition, unknown, z.core.$ZodTypeInternals<Condition, unknown>>>>;
|
|
209
|
+
}, z.core.$strip>;
|
|
210
|
+
declare const OrConditionSchema: z.ZodObject<{
|
|
211
|
+
id: z.ZodOptional<z.ZodString>;
|
|
212
|
+
type: z.ZodLiteral<"or">;
|
|
213
|
+
conditions: z.ZodArray<z.ZodLazy<z.ZodType<Condition, unknown, z.core.$ZodTypeInternals<Condition, unknown>>>>;
|
|
214
|
+
}, z.core.$strip>;
|
|
215
|
+
declare const ConditionSchema: z.ZodType<Condition>;
|
|
216
|
+
type AndCondition = z.infer<typeof AndConditionSchema>;
|
|
217
|
+
type OrCondition = z.infer<typeof OrConditionSchema>;
|
|
218
|
+
type CompositeCondition = AndCondition | OrCondition;
|
|
219
|
+
declare function isAndCondition(c: Condition): c is AndCondition;
|
|
220
|
+
declare function isOrCondition(c: Condition): c is OrCondition;
|
|
221
|
+
|
|
222
|
+
declare const ContextSchema: z.ZodRecord<z.ZodString, z.ZodType<ContextValue, unknown, z.core.$ZodTypeInternals<ContextValue, unknown>>>;
|
|
223
|
+
type ContextPrimitive = string | number | boolean;
|
|
224
|
+
type ContextValue = ContextPrimitive | ContextPrimitive[] | {
|
|
225
|
+
[key: string]: ContextValue;
|
|
226
|
+
};
|
|
227
|
+
type Context = Record<string, ContextValue>;
|
|
228
|
+
|
|
229
|
+
type VariationValue = unknown;
|
|
230
|
+
declare const VariationValueSchema: z.ZodType<VariationValue>;
|
|
231
|
+
declare const VariationSchema: z.ZodObject<{
|
|
232
|
+
id: z.ZodOptional<z.ZodString>;
|
|
233
|
+
value: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
234
|
+
conditions: z.ZodOptional<z.ZodArray<z.ZodType<Condition, unknown, z.core.$ZodTypeInternals<Condition, unknown>>>>;
|
|
235
|
+
description: z.ZodOptional<z.ZodString>;
|
|
236
|
+
}, z.core.$strip>;
|
|
237
|
+
type Variation = z.infer<typeof VariationSchema>;
|
|
238
|
+
|
|
239
|
+
declare const DefinitionSchema: z.ZodObject<{
|
|
240
|
+
id: z.ZodOptional<z.ZodString>;
|
|
241
|
+
active: z.ZodOptional<z.ZodBoolean>;
|
|
242
|
+
description: z.ZodOptional<z.ZodString>;
|
|
243
|
+
variations: z.ZodArray<z.ZodObject<{
|
|
244
|
+
id: z.ZodOptional<z.ZodString>;
|
|
245
|
+
value: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
246
|
+
conditions: z.ZodOptional<z.ZodArray<z.ZodType<Condition, unknown, z.core.$ZodTypeInternals<Condition, unknown>>>>;
|
|
247
|
+
description: z.ZodOptional<z.ZodString>;
|
|
248
|
+
}, z.core.$strip>>;
|
|
249
|
+
}, z.core.$strip>;
|
|
250
|
+
type Definition = z.infer<typeof DefinitionSchema>;
|
|
251
|
+
declare const DefinitionsSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
252
|
+
id: z.ZodOptional<z.ZodString>;
|
|
253
|
+
active: z.ZodOptional<z.ZodBoolean>;
|
|
254
|
+
description: z.ZodOptional<z.ZodString>;
|
|
255
|
+
variations: z.ZodArray<z.ZodObject<{
|
|
256
|
+
id: z.ZodOptional<z.ZodString>;
|
|
257
|
+
value: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
258
|
+
conditions: z.ZodOptional<z.ZodArray<z.ZodType<Condition, unknown, z.core.$ZodTypeInternals<Condition, unknown>>>>;
|
|
259
|
+
description: z.ZodOptional<z.ZodString>;
|
|
260
|
+
}, z.core.$strip>>;
|
|
261
|
+
}, z.core.$strip>>;
|
|
262
|
+
type Definitions = z.infer<typeof DefinitionsSchema>;
|
|
263
|
+
declare const FileFormatSchema: z.ZodObject<{
|
|
264
|
+
definitions: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
265
|
+
id: z.ZodOptional<z.ZodString>;
|
|
266
|
+
active: z.ZodOptional<z.ZodBoolean>;
|
|
267
|
+
description: z.ZodOptional<z.ZodString>;
|
|
268
|
+
variations: z.ZodArray<z.ZodObject<{
|
|
269
|
+
id: z.ZodOptional<z.ZodString>;
|
|
270
|
+
value: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
271
|
+
conditions: z.ZodOptional<z.ZodArray<z.ZodType<Condition, unknown, z.core.$ZodTypeInternals<Condition, unknown>>>>;
|
|
272
|
+
description: z.ZodOptional<z.ZodString>;
|
|
273
|
+
}, z.core.$strip>>;
|
|
274
|
+
}, z.core.$strip>>;
|
|
275
|
+
presets: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
276
|
+
type: z.ZodString;
|
|
277
|
+
key: z.ZodOptional<z.ZodString>;
|
|
278
|
+
defaults: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
279
|
+
}, z.core.$strip>>>;
|
|
280
|
+
}, z.core.$strict>;
|
|
281
|
+
type FileFormat = z.infer<typeof FileFormatSchema>;
|
|
282
|
+
|
|
283
|
+
type PresetDefinition = {
|
|
284
|
+
type: string;
|
|
285
|
+
key?: string;
|
|
286
|
+
defaults?: Record<string, unknown>;
|
|
287
|
+
};
|
|
288
|
+
type Presets = Record<string, PresetDefinition>;
|
|
289
|
+
declare const PRIMITIVE_TYPES: Set<string>;
|
|
290
|
+
declare const PresetsSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
291
|
+
type: z.ZodString;
|
|
292
|
+
key: z.ZodOptional<z.ZodString>;
|
|
293
|
+
defaults: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
294
|
+
}, z.core.$strip>>;
|
|
295
|
+
|
|
296
|
+
declare const ResolutionSchema: z.ZodObject<{
|
|
297
|
+
key: z.ZodString;
|
|
298
|
+
value: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
299
|
+
meta: z.ZodObject<{
|
|
300
|
+
context: z.ZodRecord<z.ZodString, z.ZodType<ContextValue, unknown, z.core.$ZodTypeInternals<ContextValue, unknown>>>;
|
|
301
|
+
variation: z.ZodObject<{
|
|
302
|
+
index: z.ZodNumber;
|
|
303
|
+
id: z.ZodOptional<z.ZodString>;
|
|
304
|
+
description: z.ZodOptional<z.ZodString>;
|
|
305
|
+
conditionCount: z.ZodNumber;
|
|
306
|
+
}, z.core.$strip>;
|
|
307
|
+
annotations: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
308
|
+
}, z.core.$strip>;
|
|
309
|
+
}, z.core.$strip>;
|
|
310
|
+
type Resolution = z.infer<typeof ResolutionSchema>;
|
|
311
|
+
|
|
312
|
+
type Annotations = Record<string, unknown>;
|
|
313
|
+
type ConditionEvaluatorArgs = {
|
|
314
|
+
condition: unknown;
|
|
315
|
+
context: Readonly<Context>;
|
|
316
|
+
annotations: Annotations;
|
|
317
|
+
depth: string;
|
|
318
|
+
};
|
|
319
|
+
type ConditionEvaluator = (args: ConditionEvaluatorArgs) => Promise<boolean>;
|
|
320
|
+
type ConditionEvaluators<T extends string = string> = Record<T, ConditionEvaluator>;
|
|
321
|
+
declare const noConditionEvaluator: ConditionEvaluator;
|
|
322
|
+
|
|
323
|
+
interface Logger {
|
|
324
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
325
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
326
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
327
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
328
|
+
}
|
|
329
|
+
declare const noopLogger: Logger;
|
|
330
|
+
|
|
331
|
+
type EvaluateConditionArgs = {
|
|
332
|
+
condition: Condition;
|
|
333
|
+
context: Readonly<Context>;
|
|
334
|
+
evaluators: ConditionEvaluators;
|
|
335
|
+
annotations: Annotations;
|
|
336
|
+
depth?: string;
|
|
337
|
+
logger?: Logger;
|
|
338
|
+
fallback?: ConditionEvaluator;
|
|
339
|
+
};
|
|
340
|
+
declare function evaluateCondition({ condition, context, evaluators, annotations, depth, logger, fallback, }: EvaluateConditionArgs): Promise<boolean>;
|
|
341
|
+
|
|
342
|
+
declare const builtinEvaluators: ConditionEvaluators<BuiltinCondition["type"]>;
|
|
343
|
+
|
|
344
|
+
type ResolverOptions = {
|
|
345
|
+
evaluators?: ConditionEvaluators;
|
|
346
|
+
fallback?: ConditionEvaluator;
|
|
347
|
+
logger?: Logger;
|
|
348
|
+
};
|
|
349
|
+
declare function resolveVariation({ variations, context, options, }: {
|
|
350
|
+
variations: Variation[];
|
|
351
|
+
context: Readonly<Context>;
|
|
352
|
+
options?: ResolverOptions;
|
|
353
|
+
}): Promise<{
|
|
354
|
+
variation: Variation;
|
|
355
|
+
variationIndex: number;
|
|
356
|
+
annotations: Annotations;
|
|
357
|
+
} | null>;
|
|
358
|
+
/**
|
|
359
|
+
* Resolve all definitions against the given context.
|
|
360
|
+
*
|
|
361
|
+
* Uses `Promise.all` — if any single key fails (not found, inactive, no match),
|
|
362
|
+
* the entire call rejects. Callers who need partial results should resolve
|
|
363
|
+
* keys individually via `resolveVariation`.
|
|
364
|
+
*/
|
|
365
|
+
declare function resolve({ definitions, context, options, }: {
|
|
366
|
+
definitions: Definitions;
|
|
367
|
+
context: Readonly<Context>;
|
|
368
|
+
options?: ResolverOptions;
|
|
369
|
+
}): Promise<Record<string, Resolution>>;
|
|
370
|
+
|
|
371
|
+
interface DefinitionReader {
|
|
372
|
+
get(key: string): Promise<Definition | null>;
|
|
373
|
+
getAll(): Promise<Definitions>;
|
|
374
|
+
load?(): Promise<void>;
|
|
375
|
+
close?(): Promise<void>;
|
|
376
|
+
ping?(): Promise<void>;
|
|
377
|
+
}
|
|
378
|
+
interface DefinitionWriter {
|
|
379
|
+
put(key: string, definition: Definition): Promise<void>;
|
|
380
|
+
delete(key: string): Promise<void>;
|
|
381
|
+
putMany(flags: Definitions, options?: {
|
|
382
|
+
replace?: boolean;
|
|
383
|
+
}): Promise<void>;
|
|
384
|
+
listKeys(): Promise<string[]>;
|
|
385
|
+
load?(): Promise<void>;
|
|
386
|
+
close?(): Promise<void>;
|
|
387
|
+
ping?(): Promise<void>;
|
|
388
|
+
}
|
|
389
|
+
interface DefinitionData extends DefinitionReader, DefinitionWriter {
|
|
390
|
+
}
|
|
391
|
+
interface PresetReader {
|
|
392
|
+
getPresets(): Promise<Presets>;
|
|
393
|
+
getPresets(key: string): Promise<Presets>;
|
|
394
|
+
}
|
|
395
|
+
declare function isWritable(reader: DefinitionReader): reader is DefinitionData;
|
|
396
|
+
declare class MemoryData implements DefinitionReader, PresetReader {
|
|
397
|
+
#private;
|
|
398
|
+
private constructor();
|
|
399
|
+
static fromObject(raw: unknown): Promise<MemoryData>;
|
|
400
|
+
static fromYaml(yaml: string): Promise<MemoryData>;
|
|
401
|
+
get(key: string): Promise<Definition | null>;
|
|
402
|
+
getAll(): Promise<Definitions>;
|
|
403
|
+
getPresets(): Promise<Presets>;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
declare function parseYaml(input: string): Promise<FileFormat>;
|
|
407
|
+
declare function parseObject(raw: unknown): Promise<FileFormat>;
|
|
408
|
+
declare function parsePresetsObject(raw: unknown): Promise<Presets>;
|
|
409
|
+
declare function parsePresetsYaml(input: string): Promise<Presets>;
|
|
410
|
+
|
|
411
|
+
declare function createPresetConditions(presets: Presets): ConditionEvaluators;
|
|
412
|
+
|
|
413
|
+
export { type AndCondition, type Annotations, type BoolCondition, BoolConditionSchema, type BuiltinCondition, BuiltinConditionSchema, CONDITION_TYPES, CONTEXT_KEYS, type CompositeCondition, type Condition, type ConditionEvaluator, type ConditionEvaluatorArgs, type ConditionEvaluators, ConditionSchema, type Context, ContextSchema, type ContextValue, DataError, type DatetimeCondition, DatetimeConditionSchema, type Definition, type DefinitionData, DefinitionInactiveError, DefinitionNotFoundError, type DefinitionReader, DefinitionSchema, type DefinitionWriter, type Definitions, DefinitionsSchema, type EndAtCondition, EndAtConditionSchema, type EnvCondition, EnvConditionSchema, type EvaluateConditionArgs, type FileFormat, FileFormatSchema, InvalidContextError, type Logger, MemoryData, type NumberCondition, NumberConditionSchema, type OrCondition, PRIMITIVE_CONDITION_TYPES, PRIMITIVE_TYPES, ParseError, type PresetDefinition, type PresetReader, type Presets, PresetsSchema, type PrimitiveConditionType, type Resolution, ResolutionSchema, type ResolverOptions, SchemaValidationError, ShowwhatError, type StartAtCondition, StartAtConditionSchema, type StringCondition, StringConditionSchema, ValidationError, type Variation, VariationNotFoundError, VariationSchema, type VariationValue, VariationValueSchema, builtinEvaluators, createPresetConditions, evaluateCondition, isAndCondition, isOrCondition, isWritable, noConditionEvaluator, noopLogger, parseObject, parsePresetsObject, parsePresetsYaml, parseYaml, resolve, resolveVariation };
|