showwhat 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 +59 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -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,59 @@
|
|
|
1
|
+
# showwhat
|
|
2
|
+
|
|
3
|
+
Feature flag resolution engine — the main entry point for **showwhat**, a lightweight, extensible feature flag library.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install showwhat
|
|
9
|
+
pnpm add showwhat
|
|
10
|
+
yarn add showwhat
|
|
11
|
+
|
|
12
|
+
# Other runtimes
|
|
13
|
+
bun add showwhat
|
|
14
|
+
deno install npm:showwhat
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { MemoryData, showwhat } from "showwhat";
|
|
21
|
+
|
|
22
|
+
const data = await MemoryData.fromObject({
|
|
23
|
+
definitions: {
|
|
24
|
+
checkout_v2: {
|
|
25
|
+
variations: [{ value: true, conditions: [{ type: "env", value: "prod" }] }, { value: false }],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const result = await showwhat({
|
|
31
|
+
key: "checkout_v2",
|
|
32
|
+
context: { env: "prod" },
|
|
33
|
+
options: { data },
|
|
34
|
+
});
|
|
35
|
+
console.log(result.value); // true
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- `showwhat()` resolution engine with context validation
|
|
41
|
+
- Built-in condition evaluators: `string`, `number`, `datetime`, `bool`, `env`, `startAt`, `endAt`
|
|
42
|
+
- Custom evaluators via `registerEvaluators()`
|
|
43
|
+
- YAML and JSON parsing with schema validation
|
|
44
|
+
- Pluggable data sources (`DefinitionReader` / `DefinitionWriter`)
|
|
45
|
+
- Typed error hierarchy
|
|
46
|
+
|
|
47
|
+
This package re-exports everything from `@showwhat/core`.
|
|
48
|
+
|
|
49
|
+
## Documentation
|
|
50
|
+
|
|
51
|
+
- [Quick Start](https://showwhat.yeojz.dev/docs/) — installation and first definition
|
|
52
|
+
- [Conditions](https://showwhat.yeojz.dev/docs/conditions) — built-in condition types and usage
|
|
53
|
+
- [Context](https://showwhat.yeojz.dev/docs/context) — runtime context object
|
|
54
|
+
- [Definitions](https://showwhat.yeojz.dev/docs/definitions) — definition structure and variations
|
|
55
|
+
- [Core API](https://showwhat.yeojz.dev/docs/core) — `showwhat()`, `resolve()`, parsing, and more
|
|
56
|
+
- [Errors](https://showwhat.yeojz.dev/docs/errors) — error types and when they are thrown
|
|
57
|
+
- [Custom Conditions](https://showwhat.yeojz.dev/docs/custom-conditions) — writing your own evaluators
|
|
58
|
+
- [Custom Data Sources](https://showwhat.yeojz.dev/docs/custom-data-sources) — implementing `DefinitionReader`
|
|
59
|
+
- [MemoryData](https://showwhat.yeojz.dev/docs/memory) — in-memory data source
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ResolverOptions, DefinitionReader, ConditionEvaluators, BuiltinCondition, Context, Resolution } from '@showwhat/core';
|
|
2
|
+
export * from '@showwhat/core';
|
|
3
|
+
|
|
4
|
+
type ShowWhatOptions = ResolverOptions & {
|
|
5
|
+
data: DefinitionReader;
|
|
6
|
+
};
|
|
7
|
+
declare function showwhat({ key, context, options, }: {
|
|
8
|
+
key: string;
|
|
9
|
+
context: Context;
|
|
10
|
+
options: ShowWhatOptions;
|
|
11
|
+
}): Promise<Resolution>;
|
|
12
|
+
declare function registerEvaluators<T extends string>(extra: ConditionEvaluators<T>): ConditionEvaluators<BuiltinCondition["type"] | T>;
|
|
13
|
+
|
|
14
|
+
export { type ShowWhatOptions, registerEvaluators, showwhat };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
ContextSchema,
|
|
4
|
+
builtinEvaluators,
|
|
5
|
+
DefinitionNotFoundError,
|
|
6
|
+
ValidationError,
|
|
7
|
+
resolve
|
|
8
|
+
} from "@showwhat/core";
|
|
9
|
+
export * from "@showwhat/core";
|
|
10
|
+
async function showwhat({
|
|
11
|
+
key,
|
|
12
|
+
context,
|
|
13
|
+
options
|
|
14
|
+
}) {
|
|
15
|
+
const contextResult = ContextSchema.safeParse(context);
|
|
16
|
+
if (!contextResult.success) {
|
|
17
|
+
throw new ValidationError(
|
|
18
|
+
contextResult.error.issues.map((i) => `[${i.path.join(".")}] ${i.message}`).join("; "),
|
|
19
|
+
"context"
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
const validatedContext = contextResult.data;
|
|
23
|
+
const def = await options.data.get(key);
|
|
24
|
+
if (!def) {
|
|
25
|
+
throw new DefinitionNotFoundError(key);
|
|
26
|
+
}
|
|
27
|
+
const result = await resolve({
|
|
28
|
+
definitions: { [key]: def },
|
|
29
|
+
context: validatedContext,
|
|
30
|
+
options: {
|
|
31
|
+
evaluators: options.evaluators ?? builtinEvaluators,
|
|
32
|
+
fallback: options.fallback,
|
|
33
|
+
logger: options.logger
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return result[key];
|
|
37
|
+
}
|
|
38
|
+
var COMPOSITE_TYPES = /* @__PURE__ */ new Set(["and", "or"]);
|
|
39
|
+
function registerEvaluators(extra) {
|
|
40
|
+
for (const key of Object.keys(extra)) {
|
|
41
|
+
if (COMPOSITE_TYPES.has(key)) {
|
|
42
|
+
throw new Error(`Cannot register reserved condition type "${key}"`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { ...builtinEvaluators, ...extra };
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
registerEvaluators,
|
|
49
|
+
showwhat
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n ContextSchema,\n builtinEvaluators,\n DefinitionNotFoundError,\n ValidationError,\n resolve,\n} from \"@showwhat/core\";\nimport type {\n BuiltinCondition,\n ConditionEvaluators,\n Context,\n DefinitionReader,\n Resolution,\n ResolverOptions,\n} from \"@showwhat/core\";\n\nexport * from \"@showwhat/core\";\n\nexport type ShowWhatOptions = ResolverOptions & {\n data: DefinitionReader;\n};\n\nexport async function showwhat({\n key,\n context,\n options,\n}: {\n key: string;\n context: Context;\n options: ShowWhatOptions;\n}): Promise<Resolution> {\n const contextResult = ContextSchema.safeParse(context);\n if (!contextResult.success) {\n throw new ValidationError(\n contextResult.error.issues.map((i) => `[${i.path.join(\".\")}] ${i.message}`).join(\"; \"),\n \"context\",\n );\n }\n\n const validatedContext = contextResult.data;\n const def = await options.data.get(key);\n\n if (!def) {\n throw new DefinitionNotFoundError(key);\n }\n\n const result = await resolve({\n definitions: { [key]: def },\n context: validatedContext,\n options: {\n evaluators: options.evaluators ?? builtinEvaluators,\n fallback: options.fallback,\n logger: options.logger,\n },\n });\n\n return result[key];\n}\n\nconst COMPOSITE_TYPES = new Set([\"and\", \"or\"]);\n\nexport function registerEvaluators<T extends string>(\n extra: ConditionEvaluators<T>,\n): ConditionEvaluators<BuiltinCondition[\"type\"] | T> {\n for (const key of Object.keys(extra)) {\n if (COMPOSITE_TYPES.has(key)) {\n throw new Error(`Cannot register reserved condition type \"${key}\"`);\n }\n }\n return { ...builtinEvaluators, ...extra };\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUP,cAAc;AAMd,eAAsB,SAAS;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AACF,GAIwB;AACtB,QAAM,gBAAgB,cAAc,UAAU,OAAO;AACrD,MAAI,CAAC,cAAc,SAAS;AAC1B,UAAM,IAAI;AAAA,MACR,cAAc,MAAM,OAAO,IAAI,CAAC,MAAM,IAAI,EAAE,KAAK,KAAK,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,IAAI;AAAA,MACrF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,mBAAmB,cAAc;AACvC,QAAM,MAAM,MAAM,QAAQ,KAAK,IAAI,GAAG;AAEtC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,wBAAwB,GAAG;AAAA,EACvC;AAEA,QAAM,SAAS,MAAM,QAAQ;AAAA,IAC3B,aAAa,EAAE,CAAC,GAAG,GAAG,IAAI;AAAA,IAC1B,SAAS;AAAA,IACT,SAAS;AAAA,MACP,YAAY,QAAQ,cAAc;AAAA,MAClC,UAAU,QAAQ;AAAA,MAClB,QAAQ,QAAQ;AAAA,IAClB;AAAA,EACF,CAAC;AAED,SAAO,OAAO,GAAG;AACnB;AAEA,IAAM,kBAAkB,oBAAI,IAAI,CAAC,OAAO,IAAI,CAAC;AAEtC,SAAS,mBACd,OACmD;AACnD,aAAW,OAAO,OAAO,KAAK,KAAK,GAAG;AACpC,QAAI,gBAAgB,IAAI,GAAG,GAAG;AAC5B,YAAM,IAAI,MAAM,4CAA4C,GAAG,GAAG;AAAA,IACpE;AAAA,EACF;AACA,SAAO,EAAE,GAAG,mBAAmB,GAAG,MAAM;AAC1C;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "showwhat",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Feature flag resolution engine",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"feature-flags",
|
|
7
|
+
"feature-toggles",
|
|
8
|
+
"feature-management",
|
|
9
|
+
"flag-evaluation",
|
|
10
|
+
"targeting",
|
|
11
|
+
"showwhat"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/yeojz/showwhat.git",
|
|
17
|
+
"directory": "packages/showwhat"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://showwhat.yeojz.dev",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/yeojz/showwhat/issues"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=22.0.0"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@showwhat/core": "1.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^25.4.0",
|
|
43
|
+
"@vitest/coverage-v8": "^4.0.0",
|
|
44
|
+
"tsup": "^8.0.0",
|
|
45
|
+
"typescript": "^5.4.0",
|
|
46
|
+
"vitest": "^4.0.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"clean": "rm -rf dist .tsbuildinfo",
|
|
51
|
+
"lint": "eslint src",
|
|
52
|
+
"typecheck": "tsc --noEmit"
|
|
53
|
+
}
|
|
54
|
+
}
|