@directive-run/knowledge 0.4.2 → 0.5.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 +1 -1
- package/examples/contact-form.ts +2 -2
- package/examples/dashboard-loader.ts +4 -4
- package/examples/form-wizard.ts +6 -6
- package/examples/newsletter.ts +2 -2
- package/examples/permissions.ts +1 -1
- package/examples/shopping-cart.ts +11 -11
- package/examples/sudoku.ts +10 -10
- package/examples/topic-guard.ts +3 -3
- package/package.json +3 -3
package/LICENSE
CHANGED
package/examples/contact-form.ts
CHANGED
|
@@ -197,8 +197,8 @@ const contactForm = createModule("contact-form", {
|
|
|
197
197
|
facts.subject !== "" &&
|
|
198
198
|
facts.message.trim().length >= 10,
|
|
199
199
|
|
|
200
|
-
canSubmit: (facts,
|
|
201
|
-
if (!
|
|
200
|
+
canSubmit: (facts, derived) => {
|
|
201
|
+
if (!derived.isValid) {
|
|
202
202
|
return false;
|
|
203
203
|
}
|
|
204
204
|
if (facts.status !== "idle") {
|
|
@@ -180,10 +180,10 @@ export const dashboardLoaderModule = createModule("dashboard-loader", {
|
|
|
180
180
|
return resources.some((r) => r.status === "loading");
|
|
181
181
|
},
|
|
182
182
|
|
|
183
|
-
combinedStatus: (facts,
|
|
184
|
-
const loaded =
|
|
185
|
-
const anyErr =
|
|
186
|
-
const anyLoad =
|
|
183
|
+
combinedStatus: (facts, derived) => {
|
|
184
|
+
const loaded = derived.loadedCount;
|
|
185
|
+
const anyErr = derived.anyError;
|
|
186
|
+
const anyLoad = derived.anyLoading;
|
|
187
187
|
const allIdle = [
|
|
188
188
|
facts.profile,
|
|
189
189
|
facts.preferences,
|
package/examples/form-wizard.ts
CHANGED
|
@@ -127,23 +127,23 @@ export const wizardModule = createModule("wizard", {
|
|
|
127
127
|
return facts.plan !== "";
|
|
128
128
|
},
|
|
129
129
|
|
|
130
|
-
currentStepValid: (facts,
|
|
130
|
+
currentStepValid: (facts, derived) => {
|
|
131
131
|
if (facts.currentStep === 0) {
|
|
132
|
-
return
|
|
132
|
+
return derived.step0Valid;
|
|
133
133
|
}
|
|
134
134
|
if (facts.currentStep === 1) {
|
|
135
|
-
return
|
|
135
|
+
return derived.step1Valid;
|
|
136
136
|
}
|
|
137
137
|
if (facts.currentStep === 2) {
|
|
138
|
-
return
|
|
138
|
+
return derived.step2Valid;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
return false;
|
|
142
142
|
},
|
|
143
143
|
|
|
144
|
-
canAdvance: (facts,
|
|
144
|
+
canAdvance: (facts, derived) => {
|
|
145
145
|
return (
|
|
146
|
-
|
|
146
|
+
derived.currentStepValid && facts.currentStep < facts.totalSteps - 1
|
|
147
147
|
);
|
|
148
148
|
},
|
|
149
149
|
|
package/examples/newsletter.ts
CHANGED
|
@@ -102,8 +102,8 @@ const newsletter = createModule("newsletter", {
|
|
|
102
102
|
|
|
103
103
|
isValid: (facts) => EMAIL_REGEX.test(facts.email),
|
|
104
104
|
|
|
105
|
-
canSubmit: (facts,
|
|
106
|
-
if (!
|
|
105
|
+
canSubmit: (facts, derived) => {
|
|
106
|
+
if (!derived.isValid) {
|
|
107
107
|
return false;
|
|
108
108
|
}
|
|
109
109
|
if (facts.status !== "idle") {
|
package/examples/permissions.ts
CHANGED
|
@@ -138,7 +138,7 @@ export const permissionsModule = createModule("permissions", {
|
|
|
138
138
|
canManageUsers: (facts) => facts.self.permissions.includes("users.manage"),
|
|
139
139
|
canViewAnalytics: (facts) =>
|
|
140
140
|
facts.self.permissions.includes("analytics.view"),
|
|
141
|
-
isAdmin: (_facts,
|
|
141
|
+
isAdmin: (_facts, derived) => derived.canManageUsers,
|
|
142
142
|
permissionCount: (facts) => facts.self.permissions.length,
|
|
143
143
|
},
|
|
144
144
|
|
|
@@ -187,23 +187,23 @@ export const cartModule = createModule("cart", {
|
|
|
187
187
|
return facts.self.items.length === 0;
|
|
188
188
|
},
|
|
189
189
|
|
|
190
|
-
discount: (facts,
|
|
191
|
-
const sub =
|
|
190
|
+
discount: (facts, derived) => {
|
|
191
|
+
const sub = derived.subtotal;
|
|
192
192
|
|
|
193
193
|
return sub * (facts.self.couponDiscount / 100);
|
|
194
194
|
},
|
|
195
195
|
|
|
196
|
-
tax: (facts,
|
|
197
|
-
const sub =
|
|
198
|
-
const disc =
|
|
196
|
+
tax: (facts, derived) => {
|
|
197
|
+
const sub = derived.subtotal;
|
|
198
|
+
const disc = derived.discount;
|
|
199
199
|
|
|
200
200
|
return (sub - disc) * 0.08;
|
|
201
201
|
},
|
|
202
202
|
|
|
203
|
-
total: (_facts,
|
|
204
|
-
const sub =
|
|
205
|
-
const disc =
|
|
206
|
-
const tx =
|
|
203
|
+
total: (_facts, derived) => {
|
|
204
|
+
const sub = derived.subtotal;
|
|
205
|
+
const disc = derived.discount;
|
|
206
|
+
const tx = derived.tax;
|
|
207
207
|
|
|
208
208
|
return sub - disc + tx;
|
|
209
209
|
},
|
|
@@ -214,8 +214,8 @@ export const cartModule = createModule("cart", {
|
|
|
214
214
|
);
|
|
215
215
|
},
|
|
216
216
|
|
|
217
|
-
freeShipping: (_facts,
|
|
218
|
-
const sub =
|
|
217
|
+
freeShipping: (_facts, derived) => {
|
|
218
|
+
const sub = derived.subtotal;
|
|
219
219
|
|
|
220
220
|
return sub >= 75;
|
|
221
221
|
},
|
package/examples/sudoku.ts
CHANGED
|
@@ -147,10 +147,10 @@ export const sudokuGame = createModule("sudoku", {
|
|
|
147
147
|
return findConflicts(facts.grid);
|
|
148
148
|
},
|
|
149
149
|
|
|
150
|
-
conflictIndices: (facts,
|
|
150
|
+
conflictIndices: (facts, derived) => {
|
|
151
151
|
const indices = new Set<number>();
|
|
152
152
|
const givens = facts.givens;
|
|
153
|
-
for (const c of
|
|
153
|
+
for (const c of derived.conflicts) {
|
|
154
154
|
// Only highlight player-placed cells, not givens
|
|
155
155
|
if (!givens.has(c.index)) {
|
|
156
156
|
indices.add(c.index);
|
|
@@ -160,8 +160,8 @@ export const sudokuGame = createModule("sudoku", {
|
|
|
160
160
|
return indices;
|
|
161
161
|
},
|
|
162
162
|
|
|
163
|
-
hasConflicts: (_facts,
|
|
164
|
-
return
|
|
163
|
+
hasConflicts: (_facts, derived) => {
|
|
164
|
+
return derived.conflicts.length > 0;
|
|
165
165
|
},
|
|
166
166
|
|
|
167
167
|
filledCount: (facts) => {
|
|
@@ -176,16 +176,16 @@ export const sudokuGame = createModule("sudoku", {
|
|
|
176
176
|
return count;
|
|
177
177
|
},
|
|
178
178
|
|
|
179
|
-
progress: (_facts,
|
|
180
|
-
return Math.round((
|
|
179
|
+
progress: (_facts, derived) => {
|
|
180
|
+
return Math.round((derived.filledCount / 81) * 100);
|
|
181
181
|
},
|
|
182
182
|
|
|
183
183
|
isComplete: (facts) => {
|
|
184
184
|
return isBoardComplete(facts.grid);
|
|
185
185
|
},
|
|
186
186
|
|
|
187
|
-
isSolved: (_facts,
|
|
188
|
-
return
|
|
187
|
+
isSolved: (_facts, derived) => {
|
|
188
|
+
return derived.isComplete && !derived.hasConflicts;
|
|
189
189
|
},
|
|
190
190
|
|
|
191
191
|
selectedPeers: (facts) => {
|
|
@@ -206,8 +206,8 @@ export const sudokuGame = createModule("sudoku", {
|
|
|
206
206
|
return facts.grid[sel];
|
|
207
207
|
},
|
|
208
208
|
|
|
209
|
-
sameValueIndices: (facts,
|
|
210
|
-
const val =
|
|
209
|
+
sameValueIndices: (facts, derived) => {
|
|
210
|
+
const val = derived.highlightValue;
|
|
211
211
|
if (val === 0) {
|
|
212
212
|
return new Set<number>();
|
|
213
213
|
}
|
package/examples/topic-guard.ts
CHANGED
|
@@ -106,12 +106,12 @@ export const topicGuardModule = createModule("topic-guard", {
|
|
|
106
106
|
.length;
|
|
107
107
|
},
|
|
108
108
|
|
|
109
|
-
blockRate: (facts,
|
|
110
|
-
const total =
|
|
109
|
+
blockRate: (facts, derived) => {
|
|
110
|
+
const total = derived.messageCount;
|
|
111
111
|
if (total === 0) {
|
|
112
112
|
return "0%";
|
|
113
113
|
}
|
|
114
|
-
const blocked =
|
|
114
|
+
const blocked = derived.blockedCount;
|
|
115
115
|
const rate = Math.round((blocked / total) * 100);
|
|
116
116
|
|
|
117
117
|
return `${rate}%`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directive-run/knowledge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Knowledge files, examples, and validation for Directive — the constraint-driven TypeScript runtime.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jason Comes",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"tsx": "^4.19.2",
|
|
51
51
|
"typescript": "^5.7.2",
|
|
52
52
|
"vitest": "^3.0.0",
|
|
53
|
-
"@directive-run/core": "0.
|
|
54
|
-
"@directive-run/ai": "0.
|
|
53
|
+
"@directive-run/core": "0.5.0",
|
|
54
|
+
"@directive-run/ai": "0.5.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "tsx scripts/generate-api-skeleton.ts && tsx scripts/extract-examples.ts && tsup",
|