@criterionx/core 0.3.0 → 0.3.2
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/dist/index.d.ts +51 -1
- package/dist/index.js +18 -1
- package/package.json +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -120,4 +120,54 @@ declare class Engine {
|
|
|
120
120
|
*/
|
|
121
121
|
declare const engine: Engine;
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
/**
|
|
124
|
+
* JSON Schema representation
|
|
125
|
+
*/
|
|
126
|
+
interface JsonSchema {
|
|
127
|
+
$schema?: string;
|
|
128
|
+
type?: string;
|
|
129
|
+
properties?: Record<string, JsonSchema>;
|
|
130
|
+
required?: string[];
|
|
131
|
+
additionalProperties?: boolean;
|
|
132
|
+
items?: JsonSchema;
|
|
133
|
+
enum?: unknown[];
|
|
134
|
+
[key: string]: unknown;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Decision schema export
|
|
138
|
+
*/
|
|
139
|
+
interface DecisionSchema {
|
|
140
|
+
id: string;
|
|
141
|
+
version: string;
|
|
142
|
+
inputSchema: JsonSchema;
|
|
143
|
+
outputSchema: JsonSchema;
|
|
144
|
+
profileSchema: JsonSchema;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Convert a Zod schema to JSON Schema
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* import { toJsonSchema } from "@criterionx/core";
|
|
152
|
+
* import { z } from "zod";
|
|
153
|
+
*
|
|
154
|
+
* const schema = z.object({ name: z.string(), age: z.number() });
|
|
155
|
+
* const jsonSchema = toJsonSchema(schema);
|
|
156
|
+
* // { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name", "age"] }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare function toJsonSchema(schema: ZodSchema): JsonSchema;
|
|
160
|
+
/**
|
|
161
|
+
* Extract JSON Schemas from a decision
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import { extractDecisionSchema } from "@criterionx/core";
|
|
166
|
+
*
|
|
167
|
+
* const schema = extractDecisionSchema(myDecision);
|
|
168
|
+
* // { id: "my-decision", version: "1.0.0", inputSchema: {...}, outputSchema: {...}, profileSchema: {...} }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
declare function extractDecisionSchema(decision: Decision<unknown, unknown, unknown>): DecisionSchema;
|
|
172
|
+
|
|
173
|
+
export { type Decision, type DecisionMeta, type DecisionSchema, Engine, type JsonSchema, type ProfileRegistry, type Result, type ResultMeta, type ResultStatus, type Rule, type RuleTrace, type RunOptions, createProfileRegistry, createRule, defineDecision, engine, extractDecisionSchema, isInlineProfile, toJsonSchema };
|
package/dist/index.js
CHANGED
|
@@ -201,11 +201,28 @@ var Engine = class {
|
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
var engine = new Engine();
|
|
204
|
+
|
|
205
|
+
// src/schema.ts
|
|
206
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
207
|
+
function toJsonSchema(schema) {
|
|
208
|
+
return zodToJsonSchema(schema, { $refStrategy: "none" });
|
|
209
|
+
}
|
|
210
|
+
function extractDecisionSchema(decision) {
|
|
211
|
+
return {
|
|
212
|
+
id: decision.id,
|
|
213
|
+
version: decision.version,
|
|
214
|
+
inputSchema: toJsonSchema(decision.inputSchema),
|
|
215
|
+
outputSchema: toJsonSchema(decision.outputSchema),
|
|
216
|
+
profileSchema: toJsonSchema(decision.profileSchema)
|
|
217
|
+
};
|
|
218
|
+
}
|
|
204
219
|
export {
|
|
205
220
|
Engine,
|
|
206
221
|
createProfileRegistry,
|
|
207
222
|
createRule,
|
|
208
223
|
defineDecision,
|
|
209
224
|
engine,
|
|
210
|
-
|
|
225
|
+
extractDecisionSchema,
|
|
226
|
+
isInlineProfile,
|
|
227
|
+
toJsonSchema
|
|
211
228
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@criterionx/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Universal decision engine for business-critical decisions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -44,11 +44,14 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"zod": "^3.22.0"
|
|
46
46
|
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"zod-to-json-schema": "^3.22.0"
|
|
49
|
+
},
|
|
47
50
|
"devDependencies": {
|
|
48
|
-
"@vitest/coverage-v8": "^
|
|
51
|
+
"@vitest/coverage-v8": "^4.0.0",
|
|
49
52
|
"tsup": "^8.0.0",
|
|
50
53
|
"typescript": "^5.3.0",
|
|
51
|
-
"vitest": "^
|
|
54
|
+
"vitest": "^4.0.16",
|
|
52
55
|
"zod": "^3.22.0"
|
|
53
56
|
},
|
|
54
57
|
"engines": {
|