@wordpress/abilities 0.1.1-next.dc3f6d3c1.0 → 0.2.1-next.6deb34194.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +32 -40
  3. package/build/api.js +19 -66
  4. package/build/api.js.map +3 -3
  5. package/build/index.js.map +2 -2
  6. package/build/store/actions.js +41 -31
  7. package/build/store/actions.js.map +2 -2
  8. package/build/store/constants.js +6 -15
  9. package/build/store/constants.js.map +2 -2
  10. package/build/store/index.js +1 -27
  11. package/build/store/index.js.map +3 -3
  12. package/build/store/reducer.js +2 -22
  13. package/build/store/reducer.js.map +2 -2
  14. package/build/store/selectors.js +1 -1
  15. package/build/store/selectors.js.map +2 -2
  16. package/build/store/types.js +19 -0
  17. package/build/store/types.js.map +7 -0
  18. package/build/types.js.map +1 -1
  19. package/build-module/api.js +20 -57
  20. package/build-module/api.js.map +2 -2
  21. package/build-module/index.js.map +2 -2
  22. package/build-module/store/actions.js +43 -32
  23. package/build-module/store/actions.js.map +2 -2
  24. package/build-module/store/constants.js +4 -10
  25. package/build-module/store/constants.js.map +2 -2
  26. package/build-module/store/index.js +3 -34
  27. package/build-module/store/index.js.map +2 -2
  28. package/build-module/store/reducer.js +2 -24
  29. package/build-module/store/reducer.js.map +2 -2
  30. package/build-module/store/selectors.js +1 -1
  31. package/build-module/store/selectors.js.map +2 -2
  32. package/build-module/store/types.js +1 -0
  33. package/build-module/store/types.js.map +7 -0
  34. package/build-types/api.d.ts +16 -23
  35. package/build-types/api.d.ts.map +1 -1
  36. package/build-types/index.d.ts +1 -1
  37. package/build-types/index.d.ts.map +1 -1
  38. package/build-types/store/actions.d.ts +5 -27
  39. package/build-types/store/actions.d.ts.map +1 -1
  40. package/build-types/store/constants.d.ts +2 -5
  41. package/build-types/store/constants.d.ts.map +1 -1
  42. package/build-types/store/index.d.ts +1 -1
  43. package/build-types/store/index.d.ts.map +1 -1
  44. package/build-types/store/reducer.d.ts +21 -11
  45. package/build-types/store/reducer.d.ts.map +1 -1
  46. package/build-types/store/selectors.d.ts +2 -1
  47. package/build-types/store/selectors.d.ts.map +1 -1
  48. package/build-types/store/types.d.ts +18 -0
  49. package/build-types/store/types.d.ts.map +1 -0
  50. package/build-types/types.d.ts +14 -24
  51. package/build-types/types.d.ts.map +1 -1
  52. package/package.json +15 -9
  53. package/src/api.ts +43 -123
  54. package/src/index.ts +0 -1
  55. package/src/store/actions.ts +61 -46
  56. package/src/store/constants.ts +4 -5
  57. package/src/store/index.ts +2 -34
  58. package/src/store/reducer.ts +27 -33
  59. package/src/store/selectors.ts +3 -7
  60. package/src/store/tests/actions.test.ts +100 -244
  61. package/src/store/tests/reducer.test.ts +0 -451
  62. package/src/store/tests/selectors.test.ts +1 -1
  63. package/src/store/types.ts +19 -0
  64. package/src/tests/api.test.ts +112 -158
  65. package/src/types.ts +14 -26
  66. package/build/store/resolvers.js +0 -107
  67. package/build/store/resolvers.js.map +0 -7
  68. package/build/store/tests/actions.test.js +0 -792
  69. package/build/store/tests/actions.test.js.map +0 -7
  70. package/build/store/tests/reducer.test.js +0 -743
  71. package/build/store/tests/reducer.test.js.map +0 -7
  72. package/build/store/tests/resolvers.test.js +0 -520
  73. package/build/store/tests/resolvers.test.js.map +0 -7
  74. package/build/store/tests/selectors.test.js +0 -349
  75. package/build/store/tests/selectors.test.js.map +0 -7
  76. package/build/tests/api.test.js +0 -546
  77. package/build/tests/api.test.js.map +0 -7
  78. package/build/tests/validation.test.js +0 -453
  79. package/build/tests/validation.test.js.map +0 -7
  80. package/build-module/store/resolvers.js +0 -84
  81. package/build-module/store/resolvers.js.map +0 -7
  82. package/build-module/store/tests/actions.test.js +0 -804
  83. package/build-module/store/tests/actions.test.js.map +0 -7
  84. package/build-module/store/tests/reducer.test.js +0 -726
  85. package/build-module/store/tests/reducer.test.js.map +0 -7
  86. package/build-module/store/tests/resolvers.test.js +0 -523
  87. package/build-module/store/tests/resolvers.test.js.map +0 -7
  88. package/build-module/store/tests/selectors.test.js +0 -352
  89. package/build-module/store/tests/selectors.test.js.map +0 -7
  90. package/build-module/tests/api.test.js +0 -530
  91. package/build-module/tests/api.test.js.map +0 -7
  92. package/build-module/tests/validation.test.js +0 -451
  93. package/build-module/tests/validation.test.js.map +0 -7
  94. package/build-types/store/resolvers.d.ts +0 -47
  95. package/build-types/store/resolvers.d.ts.map +0 -1
  96. package/src/store/resolvers.ts +0 -151
  97. package/src/store/tests/resolvers.test.ts +0 -642
@@ -1,453 +0,0 @@
1
- "use strict";
2
-
3
- // packages/abilities/src/tests/validation.test.ts
4
- var import_validation = require("../validation");
5
- describe("validateValueFromSchema", () => {
6
- describe("type validation", () => {
7
- it("should validate string type", () => {
8
- const schema = { type: "string" };
9
- expect((0, import_validation.validateValueFromSchema)("hello", schema)).toBe(true);
10
- expect((0, import_validation.validateValueFromSchema)(123, schema)).toBe(
11
- " is not of type string."
12
- );
13
- });
14
- it("should validate number type", () => {
15
- const schema = { type: "number" };
16
- expect((0, import_validation.validateValueFromSchema)(123, schema)).toBe(true);
17
- expect((0, import_validation.validateValueFromSchema)(45.67, schema)).toBe(true);
18
- expect((0, import_validation.validateValueFromSchema)("hello", schema)).toBe(
19
- " is not of type number."
20
- );
21
- });
22
- it("should validate boolean type", () => {
23
- const schema = { type: "boolean" };
24
- expect((0, import_validation.validateValueFromSchema)(true, schema)).toBe(true);
25
- expect((0, import_validation.validateValueFromSchema)(false, schema)).toBe(true);
26
- expect((0, import_validation.validateValueFromSchema)("true", schema)).toBe(
27
- " is not of type boolean."
28
- );
29
- });
30
- it("should validate array type", () => {
31
- const schema = { type: "array" };
32
- expect((0, import_validation.validateValueFromSchema)([1, 2, 3], schema)).toBe(
33
- true
34
- );
35
- expect((0, import_validation.validateValueFromSchema)({}, schema)).toBe(
36
- " is not of type array."
37
- );
38
- });
39
- it("should validate object type", () => {
40
- const schema = { type: "object" };
41
- expect((0, import_validation.validateValueFromSchema)({ a: 1 }, schema)).toBe(true);
42
- expect((0, import_validation.validateValueFromSchema)([], schema)).toBe(
43
- " is not of type object."
44
- );
45
- });
46
- });
47
- describe("object validation", () => {
48
- it("should validate required properties", () => {
49
- const schema = {
50
- type: "object",
51
- properties: {
52
- name: { type: "string" },
53
- age: { type: "number" }
54
- },
55
- required: ["name"]
56
- };
57
- expect(
58
- (0, import_validation.validateValueFromSchema)({ name: "John", age: 30 }, schema)
59
- ).toBe(true);
60
- expect((0, import_validation.validateValueFromSchema)({ name: "John" }, schema)).toBe(
61
- true
62
- );
63
- expect((0, import_validation.validateValueFromSchema)({ age: 30 }, schema)).toBe(
64
- "name is a required property of ."
65
- );
66
- });
67
- it("should validate nested objects", () => {
68
- const schema = {
69
- type: "object",
70
- properties: {
71
- user: {
72
- type: "object",
73
- properties: {
74
- name: { type: "string" }
75
- },
76
- required: ["name"]
77
- }
78
- }
79
- };
80
- expect(
81
- (0, import_validation.validateValueFromSchema)({ user: { name: "John" } }, schema)
82
- ).toBe(true);
83
- expect((0, import_validation.validateValueFromSchema)({ user: {} }, schema)).toBe(
84
- "name is a required property of [user]."
85
- );
86
- });
87
- it("should validate additionalProperties: false", () => {
88
- const schema = {
89
- type: "object",
90
- properties: {
91
- name: { type: "string" }
92
- },
93
- additionalProperties: false
94
- };
95
- expect((0, import_validation.validateValueFromSchema)({ name: "John" }, schema)).toBe(
96
- true
97
- );
98
- expect(
99
- (0, import_validation.validateValueFromSchema)(
100
- { name: "John", extra: "value" },
101
- schema
102
- )
103
- ).toBe("extra is not a valid property of Object.");
104
- });
105
- });
106
- describe("array validation", () => {
107
- it("should validate array items", () => {
108
- const schema = {
109
- type: "array",
110
- items: { type: "number" }
111
- };
112
- expect((0, import_validation.validateValueFromSchema)([1, 2, 3], schema)).toBe(
113
- true
114
- );
115
- expect((0, import_validation.validateValueFromSchema)([1, "two", 3], schema)).toBe(
116
- "[1] is not of type number."
117
- );
118
- });
119
- });
120
- describe("edge cases", () => {
121
- it("should pass validation when empty schema provided", () => {
122
- const consoleSpy = jest.spyOn(console, "warn").mockImplementation();
123
- expect((0, import_validation.validateValueFromSchema)("anything", {})).toBe(true);
124
- expect(consoleSpy).toHaveBeenCalledWith(
125
- 'The "type" schema keyword for value is required.'
126
- );
127
- consoleSpy.mockRestore();
128
- });
129
- it("should warn when type is missing but still pass validation", () => {
130
- const consoleSpy = jest.spyOn(console, "warn").mockImplementation();
131
- const schema = { properties: { name: { type: "string" } } };
132
- const result = (0, import_validation.validateValueFromSchema)({ name: "test" }, schema);
133
- expect(result).toBe(true);
134
- expect(consoleSpy).toHaveBeenCalledWith(
135
- 'The "type" schema keyword for value is required.'
136
- );
137
- consoleSpy.mockRestore();
138
- });
139
- it("should include param name in warning when provided", () => {
140
- const consoleSpy = jest.spyOn(console, "warn").mockImplementation();
141
- const schema = { format: "email" };
142
- const result = (0, import_validation.validateValueFromSchema)(
143
- "test@example.com",
144
- schema,
145
- "email_field"
146
- );
147
- expect(result).toBe(true);
148
- expect(consoleSpy).toHaveBeenCalledWith(
149
- 'The "type" schema keyword for email_field is required.'
150
- );
151
- consoleSpy.mockRestore();
152
- });
153
- it("should handle null values correctly", () => {
154
- const schema = { type: ["string", "null"] };
155
- expect((0, import_validation.validateValueFromSchema)(null, schema)).toBe(true);
156
- expect((0, import_validation.validateValueFromSchema)("hello", schema)).toBe(true);
157
- });
158
- });
159
- describe("AI-relevant format validation", () => {
160
- it("should validate email format", () => {
161
- const schema = { type: "string", format: "email" };
162
- expect(
163
- (0, import_validation.validateValueFromSchema)("user@example.com", schema)
164
- ).toBe(true);
165
- expect((0, import_validation.validateValueFromSchema)("invalid-email", schema)).toBe(
166
- "Invalid email address."
167
- );
168
- });
169
- it("should validate date-time format", () => {
170
- const schema = { type: "string", format: "date-time" };
171
- expect(
172
- (0, import_validation.validateValueFromSchema)("2024-01-15T10:30:00Z", schema)
173
- ).toBe(true);
174
- expect(
175
- (0, import_validation.validateValueFromSchema)("2024-01-15T10:30:00.123Z", schema)
176
- ).toBe(true);
177
- expect((0, import_validation.validateValueFromSchema)("not-a-date", schema)).toBe(
178
- "Invalid date."
179
- );
180
- });
181
- it("should validate UUID format", () => {
182
- const schema = { type: "string", format: "uuid" };
183
- expect(
184
- (0, import_validation.validateValueFromSchema)(
185
- "123e4567-e89b-12d3-a456-426614174000",
186
- schema
187
- )
188
- ).toBe(true);
189
- expect((0, import_validation.validateValueFromSchema)("not-a-uuid", schema)).toBe(
190
- " is not a valid UUID."
191
- );
192
- });
193
- it("should validate IPv4 format", () => {
194
- const schema = { type: "string", format: "ipv4" };
195
- expect((0, import_validation.validateValueFromSchema)("192.168.1.1", schema)).toBe(
196
- true
197
- );
198
- expect((0, import_validation.validateValueFromSchema)("256.256.256.256", schema)).toBe(
199
- " is not a valid IP address."
200
- );
201
- });
202
- it("should validate hostname format", () => {
203
- const schema = { type: "string", format: "hostname" };
204
- expect((0, import_validation.validateValueFromSchema)("example.com", schema)).toBe(
205
- true
206
- );
207
- expect((0, import_validation.validateValueFromSchema)("sub.example.com", schema)).toBe(
208
- true
209
- );
210
- expect((0, import_validation.validateValueFromSchema)("not a hostname!", schema)).toBe(
211
- " is not a valid hostname."
212
- );
213
- });
214
- });
215
- describe("pattern validation", () => {
216
- it("should validate string patterns", () => {
217
- const schema = { type: "string", pattern: "^[A-Z][a-z]+$" };
218
- expect((0, import_validation.validateValueFromSchema)("Hello", schema)).toBe(true);
219
- expect((0, import_validation.validateValueFromSchema)("hello", schema)).toBe(
220
- " does not match pattern ^[A-Z][a-z]+$."
221
- );
222
- });
223
- });
224
- describe("number constraints", () => {
225
- it("should validate minimum and maximum", () => {
226
- const schema = { type: "number", minimum: 0, maximum: 100 };
227
- expect((0, import_validation.validateValueFromSchema)(50, schema)).toBe(true);
228
- expect((0, import_validation.validateValueFromSchema)(0, schema)).toBe(true);
229
- expect((0, import_validation.validateValueFromSchema)(100, schema)).toBe(true);
230
- expect((0, import_validation.validateValueFromSchema)(-1, schema)).toBe(
231
- " must be greater than or equal to 0"
232
- );
233
- expect((0, import_validation.validateValueFromSchema)(101, schema)).toBe(
234
- " must be less than or equal to 100"
235
- );
236
- });
237
- it("should validate multipleOf", () => {
238
- const schema = { type: "number", multipleOf: 5 };
239
- expect((0, import_validation.validateValueFromSchema)(10, schema)).toBe(true);
240
- expect((0, import_validation.validateValueFromSchema)(15, schema)).toBe(true);
241
- expect((0, import_validation.validateValueFromSchema)(7, schema)).toBe(
242
- " must be a multiple of 5."
243
- );
244
- });
245
- });
246
- describe("enum validation", () => {
247
- it("should validate enum values", () => {
248
- const schema = {
249
- type: "string",
250
- enum: ["read", "write", "execute"]
251
- };
252
- expect((0, import_validation.validateValueFromSchema)("read", schema)).toBe(true);
253
- expect((0, import_validation.validateValueFromSchema)("delete", schema)).toBe(
254
- " is not one of read, write, execute."
255
- );
256
- });
257
- });
258
- describe("anyOf validation", () => {
259
- it("should validate anyOf schemas", () => {
260
- const schema = {
261
- anyOf: [{ type: "string" }, { type: "number" }]
262
- };
263
- expect((0, import_validation.validateValueFromSchema)("hello", schema)).toBe(true);
264
- expect((0, import_validation.validateValueFromSchema)(42, schema)).toBe(true);
265
- expect((0, import_validation.validateValueFromSchema)(true, schema)).toBe(
266
- " is invalid (failed anyOf validation)."
267
- );
268
- });
269
- });
270
- describe("strict JSON validation (no type coercion)", () => {
271
- it('should NOT coerce string "true" to boolean', () => {
272
- const schema = { type: "boolean" };
273
- expect((0, import_validation.validateValueFromSchema)(true, schema)).toBe(true);
274
- expect((0, import_validation.validateValueFromSchema)(false, schema)).toBe(true);
275
- expect((0, import_validation.validateValueFromSchema)("true", schema)).toBe(
276
- " is not of type boolean."
277
- );
278
- expect((0, import_validation.validateValueFromSchema)("1", schema)).toBe(
279
- " is not of type boolean."
280
- );
281
- });
282
- it("should NOT accept empty string as object", () => {
283
- const schema = { type: "object" };
284
- expect((0, import_validation.validateValueFromSchema)({}, schema)).toBe(true);
285
- expect((0, import_validation.validateValueFromSchema)("", schema)).toBe(
286
- " is not of type object."
287
- );
288
- });
289
- });
290
- describe("string length constraints", () => {
291
- it("should validate minLength constraint", () => {
292
- const schema = { type: "string", minLength: 3 };
293
- expect((0, import_validation.validateValueFromSchema)("hello", schema)).toBe(true);
294
- expect((0, import_validation.validateValueFromSchema)("hi", schema)).toBe(
295
- " must be at least 3 characters long."
296
- );
297
- });
298
- it("should validate maxLength constraint", () => {
299
- const schema = { type: "string", maxLength: 5 };
300
- expect((0, import_validation.validateValueFromSchema)("hello", schema)).toBe(true);
301
- expect((0, import_validation.validateValueFromSchema)("hello world", schema)).toBe(
302
- " must be at most 5 characters long."
303
- );
304
- });
305
- it("should handle singular character in length messages", () => {
306
- const minSchema = { type: "string", minLength: 1 };
307
- expect((0, import_validation.validateValueFromSchema)("", minSchema)).toBe(
308
- " must be at least 1 character long."
309
- );
310
- const maxSchema = { type: "string", maxLength: 1 };
311
- expect((0, import_validation.validateValueFromSchema)("ab", maxSchema)).toBe(
312
- " must be at most 1 character long."
313
- );
314
- });
315
- });
316
- describe("array item constraints", () => {
317
- it("should validate minItems constraint", () => {
318
- const schema = { type: "array", minItems: 2 };
319
- expect((0, import_validation.validateValueFromSchema)([1, 2, 3], schema)).toBe(
320
- true
321
- );
322
- expect((0, import_validation.validateValueFromSchema)([1], schema)).toBe(
323
- " must contain at least 2 items."
324
- );
325
- });
326
- it("should validate maxItems constraint", () => {
327
- const schema = { type: "array", maxItems: 3 };
328
- expect((0, import_validation.validateValueFromSchema)([1, 2, 3], schema)).toBe(
329
- true
330
- );
331
- expect((0, import_validation.validateValueFromSchema)([1, 2, 3, 4], schema)).toBe(
332
- " must contain at most 3 items."
333
- );
334
- });
335
- it("should validate uniqueItems constraint", () => {
336
- const schema = { type: "array", uniqueItems: true };
337
- expect((0, import_validation.validateValueFromSchema)([1, 2, 3], schema)).toBe(
338
- true
339
- );
340
- expect((0, import_validation.validateValueFromSchema)([1, 2, 2, 3], schema)).toBe(
341
- " has duplicate items."
342
- );
343
- });
344
- it("should handle singular item in item messages", () => {
345
- const minSchema = { type: "array", minItems: 1 };
346
- expect((0, import_validation.validateValueFromSchema)([], minSchema)).toBe(
347
- " must contain at least 1 item."
348
- );
349
- const maxSchema = { type: "array", maxItems: 1 };
350
- expect((0, import_validation.validateValueFromSchema)([1, 2], maxSchema)).toBe(
351
- " must contain at most 1 item."
352
- );
353
- });
354
- });
355
- describe("object property constraints", () => {
356
- it("should validate minProperties constraint", () => {
357
- const schema = { type: "object", minProperties: 2 };
358
- expect((0, import_validation.validateValueFromSchema)({ a: 1, b: 2 }, schema)).toBe(
359
- true
360
- );
361
- expect((0, import_validation.validateValueFromSchema)({ a: 1 }, schema)).toBe(
362
- " must contain at least 2 properties."
363
- );
364
- });
365
- it("should validate maxProperties constraint", () => {
366
- const schema = { type: "object", maxProperties: 2 };
367
- expect((0, import_validation.validateValueFromSchema)({ a: 1, b: 2 }, schema)).toBe(
368
- true
369
- );
370
- expect(
371
- (0, import_validation.validateValueFromSchema)({ a: 1, b: 2, c: 3 }, schema)
372
- ).toBe(" must contain at most 2 properties.");
373
- });
374
- it("should handle singular property in property messages", () => {
375
- const minSchema = { type: "object", minProperties: 1 };
376
- expect((0, import_validation.validateValueFromSchema)({}, minSchema)).toBe(
377
- " must contain at least 1 property."
378
- );
379
- const maxSchema = { type: "object", maxProperties: 1 };
380
- expect((0, import_validation.validateValueFromSchema)({ a: 1, b: 2 }, maxSchema)).toBe(
381
- " must contain at most 1 property."
382
- );
383
- });
384
- });
385
- describe("schema edge cases and errors", () => {
386
- it("should handle empty schema object as valid but warn about missing type", () => {
387
- const consoleSpy = jest.spyOn(console, "warn").mockImplementation();
388
- expect((0, import_validation.validateValueFromSchema)("anything", {})).toBe(true);
389
- expect(consoleSpy).toHaveBeenCalledWith(
390
- 'The "type" schema keyword for value is required.'
391
- );
392
- consoleSpy.mockRestore();
393
- });
394
- it("should warn for invalid schema types but still pass validation", () => {
395
- const consoleSpy = jest.spyOn(console, "warn").mockImplementation();
396
- expect(
397
- (0, import_validation.validateValueFromSchema)(
398
- "anything",
399
- void 0
400
- )
401
- ).toBe(true);
402
- expect(consoleSpy).toHaveBeenCalledWith(
403
- "Schema must be an object. Received undefined."
404
- );
405
- consoleSpy.mockClear();
406
- expect(
407
- (0, import_validation.validateValueFromSchema)(
408
- 123,
409
- null
410
- )
411
- ).toBe(true);
412
- expect(consoleSpy).toHaveBeenCalledWith(
413
- "Schema must be an object. Received object."
414
- // typeof null === 'object'
415
- );
416
- consoleSpy.mockClear();
417
- expect(
418
- (0, import_validation.validateValueFromSchema)(
419
- true,
420
- false
421
- )
422
- ).toBe(true);
423
- expect(consoleSpy).toHaveBeenCalledWith(
424
- "Schema must be an object. Received boolean."
425
- );
426
- consoleSpy.mockRestore();
427
- });
428
- it("should handle schema compilation errors", () => {
429
- const invalidSchema = { type: "invalid-type" };
430
- const consoleErrorSpy = jest.spyOn(console, "error").mockImplementation();
431
- const result = (0, import_validation.validateValueFromSchema)("test", invalidSchema);
432
- expect(result).toBe("Invalid schema provided for validation.");
433
- expect(consoleErrorSpy).toHaveBeenCalledWith(
434
- "Schema compilation error:",
435
- expect.any(Error)
436
- );
437
- consoleErrorSpy.mockRestore();
438
- });
439
- it("should handle const validation keyword", () => {
440
- const schema = {
441
- type: "string",
442
- const: "exact-value"
443
- };
444
- expect((0, import_validation.validateValueFromSchema)("exact-value", schema)).toBe(
445
- true
446
- );
447
- expect((0, import_validation.validateValueFromSchema)("different-value", schema)).toBe(
448
- "must be equal to constant"
449
- );
450
- });
451
- });
452
- });
453
- //# sourceMappingURL=validation.test.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/tests/validation.test.ts"],
4
- "sourcesContent": ["/**\n * Tests for schema validation utilities.\n */\n\n/**\n * Internal dependencies\n */\nimport { validateValueFromSchema } from '../validation';\n\ndescribe( 'validateValueFromSchema', () => {\n\tdescribe( 'type validation', () => {\n\t\tit( 'should validate string type', () => {\n\t\t\tconst schema = { type: 'string' };\n\t\t\texpect( validateValueFromSchema( 'hello', schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 123, schema ) ).toBe(\n\t\t\t\t' is not of type string.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate number type', () => {\n\t\t\tconst schema = { type: 'number' };\n\t\t\texpect( validateValueFromSchema( 123, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 45.67, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'hello', schema ) ).toBe(\n\t\t\t\t' is not of type number.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate boolean type', () => {\n\t\t\tconst schema = { type: 'boolean' };\n\t\t\texpect( validateValueFromSchema( true, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( false, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'true', schema ) ).toBe(\n\t\t\t\t' is not of type boolean.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate array type', () => {\n\t\t\tconst schema = { type: 'array' };\n\t\t\texpect( validateValueFromSchema( [ 1, 2, 3 ], schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( {}, schema ) ).toBe(\n\t\t\t\t' is not of type array.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate object type', () => {\n\t\t\tconst schema = { type: 'object' };\n\t\t\texpect( validateValueFromSchema( { a: 1 }, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( [], schema ) ).toBe(\n\t\t\t\t' is not of type object.'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'object validation', () => {\n\t\tit( 'should validate required properties', () => {\n\t\t\tconst schema = {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {\n\t\t\t\t\tname: { type: 'string' },\n\t\t\t\t\tage: { type: 'number' },\n\t\t\t\t},\n\t\t\t\trequired: [ 'name' ],\n\t\t\t};\n\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema( { name: 'John', age: 30 }, schema )\n\t\t\t).toBe( true );\n\t\t\texpect( validateValueFromSchema( { name: 'John' }, schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( { age: 30 }, schema ) ).toBe(\n\t\t\t\t'name is a required property of .'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate nested objects', () => {\n\t\t\tconst schema = {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {\n\t\t\t\t\tuser: {\n\t\t\t\t\t\ttype: 'object',\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tname: { type: 'string' },\n\t\t\t\t\t\t},\n\t\t\t\t\t\trequired: [ 'name' ],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema( { user: { name: 'John' } }, schema )\n\t\t\t).toBe( true );\n\t\t\texpect( validateValueFromSchema( { user: {} }, schema ) ).toBe(\n\t\t\t\t'name is a required property of [user].'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate additionalProperties: false', () => {\n\t\t\tconst schema = {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {\n\t\t\t\t\tname: { type: 'string' },\n\t\t\t\t},\n\t\t\t\tadditionalProperties: false,\n\t\t\t};\n\n\t\t\texpect( validateValueFromSchema( { name: 'John' }, schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema(\n\t\t\t\t\t{ name: 'John', extra: 'value' },\n\t\t\t\t\tschema\n\t\t\t\t)\n\t\t\t).toBe( 'extra is not a valid property of Object.' );\n\t\t} );\n\t} );\n\n\tdescribe( 'array validation', () => {\n\t\tit( 'should validate array items', () => {\n\t\t\tconst schema = {\n\t\t\t\ttype: 'array',\n\t\t\t\titems: { type: 'number' },\n\t\t\t};\n\n\t\t\texpect( validateValueFromSchema( [ 1, 2, 3 ], schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( [ 1, 'two', 3 ], schema ) ).toBe(\n\t\t\t\t'[1] is not of type number.'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'edge cases', () => {\n\t\tit( 'should pass validation when empty schema provided', () => {\n\t\t\tconst consoleSpy = jest\n\t\t\t\t.spyOn( console, 'warn' )\n\t\t\t\t.mockImplementation();\n\n\t\t\texpect( validateValueFromSchema( 'anything', {} ) ).toBe( true );\n\t\t\texpect( consoleSpy ).toHaveBeenCalledWith(\n\t\t\t\t'The \"type\" schema keyword for value is required.'\n\t\t\t);\n\n\t\t\tconsoleSpy.mockRestore();\n\t\t} );\n\n\t\tit( 'should warn when type is missing but still pass validation', () => {\n\t\t\tconst consoleSpy = jest\n\t\t\t\t.spyOn( console, 'warn' )\n\t\t\t\t.mockImplementation();\n\t\t\tconst schema = { properties: { name: { type: 'string' } } };\n\t\t\tconst result = validateValueFromSchema( { name: 'test' }, schema );\n\n\t\t\texpect( result ).toBe( true );\n\t\t\texpect( consoleSpy ).toHaveBeenCalledWith(\n\t\t\t\t'The \"type\" schema keyword for value is required.'\n\t\t\t);\n\n\t\t\tconsoleSpy.mockRestore();\n\t\t} );\n\n\t\tit( 'should include param name in warning when provided', () => {\n\t\t\tconst consoleSpy = jest\n\t\t\t\t.spyOn( console, 'warn' )\n\t\t\t\t.mockImplementation();\n\t\t\tconst schema = { format: 'email' }; // Schema without type\n\t\t\tconst result = validateValueFromSchema(\n\t\t\t\t'test@example.com',\n\t\t\t\tschema,\n\t\t\t\t'email_field'\n\t\t\t);\n\n\t\t\texpect( result ).toBe( true );\n\t\t\texpect( consoleSpy ).toHaveBeenCalledWith(\n\t\t\t\t'The \"type\" schema keyword for email_field is required.'\n\t\t\t);\n\n\t\t\tconsoleSpy.mockRestore();\n\t\t} );\n\n\t\tit( 'should handle null values correctly', () => {\n\t\t\tconst schema = { type: [ 'string', 'null' ] };\n\t\t\texpect( validateValueFromSchema( null, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'hello', schema ) ).toBe( true );\n\t\t} );\n\t} );\n\n\tdescribe( 'AI-relevant format validation', () => {\n\t\tit( 'should validate email format', () => {\n\t\t\tconst schema = { type: 'string', format: 'email' };\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema( 'user@example.com', schema )\n\t\t\t).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'invalid-email', schema ) ).toBe(\n\t\t\t\t'Invalid email address.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate date-time format', () => {\n\t\t\tconst schema = { type: 'string', format: 'date-time' };\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema( '2024-01-15T10:30:00Z', schema )\n\t\t\t).toBe( true );\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema( '2024-01-15T10:30:00.123Z', schema )\n\t\t\t).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'not-a-date', schema ) ).toBe(\n\t\t\t\t'Invalid date.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate UUID format', () => {\n\t\t\tconst schema = { type: 'string', format: 'uuid' };\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema(\n\t\t\t\t\t'123e4567-e89b-12d3-a456-426614174000',\n\t\t\t\t\tschema\n\t\t\t\t)\n\t\t\t).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'not-a-uuid', schema ) ).toBe(\n\t\t\t\t' is not a valid UUID.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate IPv4 format', () => {\n\t\t\tconst schema = { type: 'string', format: 'ipv4' };\n\t\t\texpect( validateValueFromSchema( '192.168.1.1', schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( '256.256.256.256', schema ) ).toBe(\n\t\t\t\t' is not a valid IP address.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate hostname format', () => {\n\t\t\tconst schema = { type: 'string', format: 'hostname' };\n\t\t\texpect( validateValueFromSchema( 'example.com', schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( 'sub.example.com', schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( 'not a hostname!', schema ) ).toBe(\n\t\t\t\t' is not a valid hostname.'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'pattern validation', () => {\n\t\tit( 'should validate string patterns', () => {\n\t\t\tconst schema = { type: 'string', pattern: '^[A-Z][a-z]+$' };\n\t\t\texpect( validateValueFromSchema( 'Hello', schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'hello', schema ) ).toBe(\n\t\t\t\t' does not match pattern ^[A-Z][a-z]+$.'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'number constraints', () => {\n\t\tit( 'should validate minimum and maximum', () => {\n\t\t\tconst schema = { type: 'number', minimum: 0, maximum: 100 };\n\t\t\texpect( validateValueFromSchema( 50, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 0, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 100, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( -1, schema ) ).toBe(\n\t\t\t\t' must be greater than or equal to 0'\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( 101, schema ) ).toBe(\n\t\t\t\t' must be less than or equal to 100'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate multipleOf', () => {\n\t\t\tconst schema = { type: 'number', multipleOf: 5 };\n\t\t\texpect( validateValueFromSchema( 10, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 15, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 7, schema ) ).toBe(\n\t\t\t\t' must be a multiple of 5.'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'enum validation', () => {\n\t\tit( 'should validate enum values', () => {\n\t\t\tconst schema = {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: [ 'read', 'write', 'execute' ],\n\t\t\t};\n\t\t\texpect( validateValueFromSchema( 'read', schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'delete', schema ) ).toBe(\n\t\t\t\t' is not one of read, write, execute.'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'anyOf validation', () => {\n\t\tit( 'should validate anyOf schemas', () => {\n\t\t\tconst schema = {\n\t\t\t\tanyOf: [ { type: 'string' }, { type: 'number' } ],\n\t\t\t};\n\t\t\texpect( validateValueFromSchema( 'hello', schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 42, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( true, schema ) ).toBe(\n\t\t\t\t' is invalid (failed anyOf validation).'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'strict JSON validation (no type coercion)', () => {\n\t\tit( 'should NOT coerce string \"true\" to boolean', () => {\n\t\t\tconst schema = { type: 'boolean' };\n\t\t\texpect( validateValueFromSchema( true, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( false, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'true', schema ) ).toBe(\n\t\t\t\t' is not of type boolean.'\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( '1', schema ) ).toBe(\n\t\t\t\t' is not of type boolean.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should NOT accept empty string as object', () => {\n\t\t\tconst schema = { type: 'object' };\n\t\t\texpect( validateValueFromSchema( {}, schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( '', schema ) ).toBe(\n\t\t\t\t' is not of type object.'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'string length constraints', () => {\n\t\tit( 'should validate minLength constraint', () => {\n\t\t\tconst schema = { type: 'string', minLength: 3 };\n\t\t\texpect( validateValueFromSchema( 'hello', schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'hi', schema ) ).toBe(\n\t\t\t\t' must be at least 3 characters long.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate maxLength constraint', () => {\n\t\t\tconst schema = { type: 'string', maxLength: 5 };\n\t\t\texpect( validateValueFromSchema( 'hello', schema ) ).toBe( true );\n\t\t\texpect( validateValueFromSchema( 'hello world', schema ) ).toBe(\n\t\t\t\t' must be at most 5 characters long.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should handle singular character in length messages', () => {\n\t\t\tconst minSchema = { type: 'string', minLength: 1 };\n\t\t\texpect( validateValueFromSchema( '', minSchema ) ).toBe(\n\t\t\t\t' must be at least 1 character long.'\n\t\t\t);\n\n\t\t\tconst maxSchema = { type: 'string', maxLength: 1 };\n\t\t\texpect( validateValueFromSchema( 'ab', maxSchema ) ).toBe(\n\t\t\t\t' must be at most 1 character long.'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'array item constraints', () => {\n\t\tit( 'should validate minItems constraint', () => {\n\t\t\tconst schema = { type: 'array', minItems: 2 };\n\t\t\texpect( validateValueFromSchema( [ 1, 2, 3 ], schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( [ 1 ], schema ) ).toBe(\n\t\t\t\t' must contain at least 2 items.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate maxItems constraint', () => {\n\t\t\tconst schema = { type: 'array', maxItems: 3 };\n\t\t\texpect( validateValueFromSchema( [ 1, 2, 3 ], schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( [ 1, 2, 3, 4 ], schema ) ).toBe(\n\t\t\t\t' must contain at most 3 items.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate uniqueItems constraint', () => {\n\t\t\tconst schema = { type: 'array', uniqueItems: true };\n\t\t\texpect( validateValueFromSchema( [ 1, 2, 3 ], schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( [ 1, 2, 2, 3 ], schema ) ).toBe(\n\t\t\t\t' has duplicate items.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should handle singular item in item messages', () => {\n\t\t\tconst minSchema = { type: 'array', minItems: 1 };\n\t\t\texpect( validateValueFromSchema( [], minSchema ) ).toBe(\n\t\t\t\t' must contain at least 1 item.'\n\t\t\t);\n\n\t\t\tconst maxSchema = { type: 'array', maxItems: 1 };\n\t\t\texpect( validateValueFromSchema( [ 1, 2 ], maxSchema ) ).toBe(\n\t\t\t\t' must contain at most 1 item.'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'object property constraints', () => {\n\t\tit( 'should validate minProperties constraint', () => {\n\t\t\tconst schema = { type: 'object', minProperties: 2 };\n\t\t\texpect( validateValueFromSchema( { a: 1, b: 2 }, schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( { a: 1 }, schema ) ).toBe(\n\t\t\t\t' must contain at least 2 properties.'\n\t\t\t);\n\t\t} );\n\n\t\tit( 'should validate maxProperties constraint', () => {\n\t\t\tconst schema = { type: 'object', maxProperties: 2 };\n\t\t\texpect( validateValueFromSchema( { a: 1, b: 2 }, schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema( { a: 1, b: 2, c: 3 }, schema )\n\t\t\t).toBe( ' must contain at most 2 properties.' );\n\t\t} );\n\n\t\tit( 'should handle singular property in property messages', () => {\n\t\t\tconst minSchema = { type: 'object', minProperties: 1 };\n\t\t\texpect( validateValueFromSchema( {}, minSchema ) ).toBe(\n\t\t\t\t' must contain at least 1 property.'\n\t\t\t);\n\n\t\t\tconst maxSchema = { type: 'object', maxProperties: 1 };\n\t\t\texpect( validateValueFromSchema( { a: 1, b: 2 }, maxSchema ) ).toBe(\n\t\t\t\t' must contain at most 1 property.'\n\t\t\t);\n\t\t} );\n\t} );\n\n\tdescribe( 'schema edge cases and errors', () => {\n\t\tit( 'should handle empty schema object as valid but warn about missing type', () => {\n\t\t\tconst consoleSpy = jest\n\t\t\t\t.spyOn( console, 'warn' )\n\t\t\t\t.mockImplementation();\n\n\t\t\t// Empty object schema triggers warning about missing type\n\t\t\texpect( validateValueFromSchema( 'anything', {} ) ).toBe( true );\n\t\t\texpect( consoleSpy ).toHaveBeenCalledWith(\n\t\t\t\t'The \"type\" schema keyword for value is required.'\n\t\t\t);\n\n\t\t\tconsoleSpy.mockRestore();\n\t\t} );\n\n\t\tit( 'should warn for invalid schema types but still pass validation', () => {\n\t\t\tconst consoleSpy = jest\n\t\t\t\t.spyOn( console, 'warn' )\n\t\t\t\t.mockImplementation();\n\n\t\t\t// Testing edge cases where schema is not a valid object\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema(\n\t\t\t\t\t'anything',\n\t\t\t\t\tundefined as unknown as Record< string, any >\n\t\t\t\t)\n\t\t\t).toBe( true );\n\t\t\texpect( consoleSpy ).toHaveBeenCalledWith(\n\t\t\t\t'Schema must be an object. Received undefined.'\n\t\t\t);\n\n\t\t\tconsoleSpy.mockClear();\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema(\n\t\t\t\t\t123,\n\t\t\t\t\tnull as unknown as Record< string, any >\n\t\t\t\t)\n\t\t\t).toBe( true );\n\t\t\texpect( consoleSpy ).toHaveBeenCalledWith(\n\t\t\t\t'Schema must be an object. Received object.' // typeof null === 'object'\n\t\t\t);\n\n\t\t\tconsoleSpy.mockClear();\n\t\t\texpect(\n\t\t\t\tvalidateValueFromSchema(\n\t\t\t\t\ttrue,\n\t\t\t\t\tfalse as unknown as Record< string, any >\n\t\t\t\t)\n\t\t\t).toBe( true );\n\t\t\texpect( consoleSpy ).toHaveBeenCalledWith(\n\t\t\t\t'Schema must be an object. Received boolean.'\n\t\t\t);\n\n\t\t\tconsoleSpy.mockRestore();\n\t\t} );\n\n\t\tit( 'should handle schema compilation errors', () => {\n\t\t\t// Pass an invalid schema that will cause compilation error\n\t\t\tconst invalidSchema = { type: 'invalid-type' };\n\t\t\tconst consoleErrorSpy = jest\n\t\t\t\t.spyOn( console, 'error' )\n\t\t\t\t.mockImplementation();\n\n\t\t\tconst result = validateValueFromSchema( 'test', invalidSchema );\n\n\t\t\texpect( result ).toBe( 'Invalid schema provided for validation.' );\n\t\t\texpect( consoleErrorSpy ).toHaveBeenCalledWith(\n\t\t\t\t'Schema compilation error:',\n\t\t\t\texpect.any( Error )\n\t\t\t);\n\n\t\t\tconsoleErrorSpy.mockRestore();\n\t\t} );\n\n\t\tit( 'should handle const validation keyword', () => {\n\t\t\tconst schema = {\n\t\t\t\ttype: 'string',\n\t\t\t\tconst: 'exact-value',\n\t\t\t};\n\n\t\t\texpect( validateValueFromSchema( 'exact-value', schema ) ).toBe(\n\t\t\t\ttrue\n\t\t\t);\n\t\t\texpect( validateValueFromSchema( 'different-value', schema ) ).toBe(\n\t\t\t\t'must be equal to constant'\n\t\t\t);\n\t\t} );\n\t} );\n} );\n"],
5
- "mappings": ";;;AAOA,wBAAwC;AAExC,SAAU,2BAA2B,MAAM;AAC1C,WAAU,mBAAmB,MAAM;AAClC,OAAI,+BAA+B,MAAM;AACxC,YAAM,SAAS,EAAE,MAAM,SAAS;AAChC,iBAAQ,2CAAyB,SAAS,MAAO,CAAE,EAAE,KAAM,IAAK;AAChE,iBAAQ,2CAAyB,KAAK,MAAO,CAAE,EAAE;AAAA,QAChD;AAAA,MACD;AAAA,IACD,CAAE;AAEF,OAAI,+BAA+B,MAAM;AACxC,YAAM,SAAS,EAAE,MAAM,SAAS;AAChC,iBAAQ,2CAAyB,KAAK,MAAO,CAAE,EAAE,KAAM,IAAK;AAC5D,iBAAQ,2CAAyB,OAAO,MAAO,CAAE,EAAE,KAAM,IAAK;AAC9D,iBAAQ,2CAAyB,SAAS,MAAO,CAAE,EAAE;AAAA,QACpD;AAAA,MACD;AAAA,IACD,CAAE;AAEF,OAAI,gCAAgC,MAAM;AACzC,YAAM,SAAS,EAAE,MAAM,UAAU;AACjC,iBAAQ,2CAAyB,MAAM,MAAO,CAAE,EAAE,KAAM,IAAK;AAC7D,iBAAQ,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jE,aAAQ,eAAgB,EAAE;AAAA,QACzB;AAAA,QACA,OAAO,IAAK,KAAM;AAAA,MACnB;AAEA,sBAAgB,YAAY;AAAA,IAC7B,CAAE;AAEF,OAAI,0CAA0C,MAAM;AACnD,YAAM,SAAS;AAAA,QACd,MAAM;AAAA,QACN,OAAO;AAAA,MACR;AAEA,iBAAQ,2CAAyB,eAAe,MAAO,CAAE,EAAE;AAAA,QAC1D;AAAA,MACD;AACA,iBAAQ,2CAAyB,mBAAmB,MAAO,CAAE,EAAE;AAAA,QAC9D;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AACH,CAAE;",
6
- "names": []
7
- }
@@ -1,84 +0,0 @@
1
- // packages/abilities/src/store/resolvers.ts
2
- import { store as coreStore } from "@wordpress/core-data";
3
- import { ENTITY_KIND, ENTITY_NAME, ENTITY_NAME_CATEGORIES } from "./constants";
4
- import {
5
- receiveAbilities,
6
- receiveCategories,
7
- registerAbility,
8
- registerAbilityCategory
9
- } from "./actions";
10
- function getAbilities() {
11
- return async ({ dispatch, registry, select }) => {
12
- const existingAbilities = select.getAbilities();
13
- const hasServerAbilities = existingAbilities.some(
14
- (ability) => !ability.callback
15
- );
16
- if (hasServerAbilities) {
17
- return;
18
- }
19
- const abilities = await registry.resolveSelect(coreStore).getEntityRecords(ENTITY_KIND, ENTITY_NAME, {
20
- per_page: -1
21
- });
22
- dispatch(receiveAbilities(abilities || []));
23
- };
24
- }
25
- function getAbility(name) {
26
- return async ({ dispatch, registry, select }) => {
27
- const existingAbility = select.getAbility(name);
28
- if (existingAbility) {
29
- return;
30
- }
31
- try {
32
- const ability = await registry.resolveSelect(coreStore).getEntityRecord(ENTITY_KIND, ENTITY_NAME, name);
33
- if (ability) {
34
- await dispatch(registerAbility(ability));
35
- }
36
- } catch (error) {
37
- console.debug(`Ability not found: ${name}`);
38
- }
39
- };
40
- }
41
- function getAbilityCategories() {
42
- return async ({ dispatch, registry, select }) => {
43
- const existingCategories = select.getAbilityCategories();
44
- const hasServerCategories = existingCategories.some(
45
- (category) => !category.meta?._clientRegistered
46
- );
47
- if (hasServerCategories) {
48
- return;
49
- }
50
- const categories = await registry.resolveSelect(coreStore).getEntityRecords(ENTITY_KIND, ENTITY_NAME_CATEGORIES, {
51
- per_page: -1
52
- });
53
- dispatch(receiveCategories(categories || []));
54
- };
55
- }
56
- function getAbilityCategory(slug) {
57
- return async ({ dispatch, registry, select }) => {
58
- const existingCategory = select.getAbilityCategory(slug);
59
- if (existingCategory) {
60
- return;
61
- }
62
- try {
63
- const category = await registry.resolveSelect(coreStore).getEntityRecord(ENTITY_KIND, ENTITY_NAME_CATEGORIES, slug);
64
- if (category) {
65
- await dispatch(
66
- registerAbilityCategory(category.slug, {
67
- label: category.label,
68
- description: category.description,
69
- meta: category.meta
70
- })
71
- );
72
- }
73
- } catch (error) {
74
- console.debug(`Category not found: ${slug}`);
75
- }
76
- };
77
- }
78
- export {
79
- getAbilities,
80
- getAbility,
81
- getAbilityCategories,
82
- getAbilityCategory
83
- };
84
- //# sourceMappingURL=resolvers.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/store/resolvers.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { Ability, AbilityCategory } from '../types';\nimport { ENTITY_KIND, ENTITY_NAME, ENTITY_NAME_CATEGORIES } from './constants';\nimport {\n\treceiveAbilities,\n\treceiveCategories,\n\tregisterAbility,\n\tregisterAbilityCategory,\n} from './actions';\n\n/**\n * Resolver for getAbilities selector.\n * Fetches all abilities from the server.\n *\n * The resolver only fetches once (without query args filter) and stores all abilities.\n * Query args filtering handled client-side by the selector for better performance\n * and to avoid multiple API requests when filtering by different categories.\n */\nexport function getAbilities() {\n\t// @ts-expect-error - registry types are not yet available\n\treturn async ( { dispatch, registry, select } ) => {\n\t\tconst existingAbilities = select.getAbilities();\n\n\t\t// Check if we have any server-side abilities (abilities without callbacks)\n\t\t// Client abilities have callbacks and are registered immediately on page load\n\t\t// We only want to skip fetching if we've already fetched server abilities\n\t\tconst hasServerAbilities = existingAbilities.some(\n\t\t\t( ability: Ability ) => ! ability.callback\n\t\t);\n\n\t\tif ( hasServerAbilities ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst abilities = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( ENTITY_KIND, ENTITY_NAME, {\n\t\t\t\tper_page: -1,\n\t\t\t} );\n\n\t\tdispatch( receiveAbilities( abilities || [] ) );\n\t};\n}\n\n/**\n * Resolver for getAbility selector.\n * Fetches a specific ability from the server if not already in store.\n *\n * @param name Ability name.\n */\nexport function getAbility( name: string ) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn async ( { dispatch, registry, select } ) => {\n\t\t// Check if ability already exists in store (i.e. client ability or already fetched)\n\t\tconst existingAbility = select.getAbility( name );\n\t\tif ( existingAbility ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst ability = await registry\n\t\t\t\t.resolveSelect( coreStore )\n\t\t\t\t.getEntityRecord( ENTITY_KIND, ENTITY_NAME, name );\n\n\t\t\tif ( ability ) {\n\t\t\t\tawait dispatch( registerAbility( ability ) );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\t// If ability doesn't exist or error, we'll return undefined from the selector\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.debug( `Ability not found: ${ name }` );\n\t\t}\n\t};\n}\n\n/**\n * Resolver for getAbilityCategories selector.\n * Fetches all categories from the server.\n *\n * The resolver only fetches once and stores all categories.\n */\nexport function getAbilityCategories() {\n\t// @ts-expect-error - registry types are not yet available\n\treturn async ( { dispatch, registry, select } ) => {\n\t\tconst existingCategories = select.getAbilityCategories();\n\n\t\t// Check if we have any server-side categories (categories without meta._clientRegistered flag)\n\t\t// Client categories have meta._clientRegistered=true and might be registered immediately\n\t\t// We only want to skip fetching if we've already fetched server categories\n\t\tconst hasServerCategories = existingCategories.some(\n\t\t\t( category: AbilityCategory ) => ! category.meta?._clientRegistered\n\t\t);\n\n\t\tif ( hasServerCategories ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst categories = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecords( ENTITY_KIND, ENTITY_NAME_CATEGORIES, {\n\t\t\t\tper_page: -1,\n\t\t\t} );\n\n\t\tdispatch( receiveCategories( categories || [] ) );\n\t};\n}\n\n/**\n * Resolver for getAbilityCategory selector.\n * Fetches a specific category from the server if not already in store.\n *\n * @param slug Category slug.\n */\nexport function getAbilityCategory( slug: string ) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn async ( { dispatch, registry, select } ) => {\n\t\t// Check if category already exists in store (either client-registered or server-fetched).\n\t\t// This prevents unnecessary network requests while allowing client-side categories\n\t\t// to be retrieved immediately without hitting the API.\n\t\tconst existingCategory = select.getAbilityCategory( slug );\n\t\tif ( existingCategory ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst category = await registry\n\t\t\t\t.resolveSelect( coreStore )\n\t\t\t\t.getEntityRecord( ENTITY_KIND, ENTITY_NAME_CATEGORIES, slug );\n\n\t\t\tif ( category ) {\n\t\t\t\tawait dispatch(\n\t\t\t\t\tregisterAbilityCategory( category.slug, {\n\t\t\t\t\t\tlabel: category.label,\n\t\t\t\t\t\tdescription: category.description,\n\t\t\t\t\t\tmeta: category.meta,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.debug( `Category not found: ${ slug }` );\n\t\t}\n\t};\n}\n"],
5
- "mappings": ";AAGA,SAAS,SAAS,iBAAiB;AAMnC,SAAS,aAAa,aAAa,8BAA8B;AACjE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAUA,SAAS,eAAe;AAE9B,SAAO,OAAQ,EAAE,UAAU,UAAU,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