@uniforge/testing 0.1.0-alpha.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.
Files changed (85) hide show
  1. package/dist/auth/index.d.cts +177 -0
  2. package/dist/auth/index.d.ts +177 -0
  3. package/dist/auth/index.js +459 -0
  4. package/dist/auth/index.js.map +1 -0
  5. package/dist/auth/index.mjs +418 -0
  6. package/dist/auth/index.mjs.map +1 -0
  7. package/dist/billing/index.d.cts +27 -0
  8. package/dist/billing/index.d.ts +27 -0
  9. package/dist/billing/index.js +208 -0
  10. package/dist/billing/index.js.map +1 -0
  11. package/dist/billing/index.mjs +178 -0
  12. package/dist/billing/index.mjs.map +1 -0
  13. package/dist/database/index.d.cts +399 -0
  14. package/dist/database/index.d.ts +399 -0
  15. package/dist/database/index.js +19054 -0
  16. package/dist/database/index.js.map +1 -0
  17. package/dist/database/index.mjs +19046 -0
  18. package/dist/database/index.mjs.map +1 -0
  19. package/dist/graphql/index.d.cts +23 -0
  20. package/dist/graphql/index.d.ts +23 -0
  21. package/dist/graphql/index.js +18511 -0
  22. package/dist/graphql/index.js.map +1 -0
  23. package/dist/graphql/index.mjs +18505 -0
  24. package/dist/graphql/index.mjs.map +1 -0
  25. package/dist/index.d.cts +10 -0
  26. package/dist/index.d.ts +10 -0
  27. package/dist/index.js +31 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/index.mjs +6 -0
  30. package/dist/index.mjs.map +1 -0
  31. package/dist/multi-store/index.d.cts +66 -0
  32. package/dist/multi-store/index.d.ts +66 -0
  33. package/dist/multi-store/index.js +319 -0
  34. package/dist/multi-store/index.js.map +1 -0
  35. package/dist/multi-store/index.mjs +287 -0
  36. package/dist/multi-store/index.mjs.map +1 -0
  37. package/dist/multi-tenant/index.d.cts +15 -0
  38. package/dist/multi-tenant/index.d.ts +15 -0
  39. package/dist/multi-tenant/index.js +87 -0
  40. package/dist/multi-tenant/index.js.map +1 -0
  41. package/dist/multi-tenant/index.mjs +57 -0
  42. package/dist/multi-tenant/index.mjs.map +1 -0
  43. package/dist/performance/index.d.cts +60 -0
  44. package/dist/performance/index.d.ts +60 -0
  45. package/dist/performance/index.js +280 -0
  46. package/dist/performance/index.js.map +1 -0
  47. package/dist/performance/index.mjs +246 -0
  48. package/dist/performance/index.mjs.map +1 -0
  49. package/dist/platform/index.d.cts +71 -0
  50. package/dist/platform/index.d.ts +71 -0
  51. package/dist/platform/index.js +435 -0
  52. package/dist/platform/index.js.map +1 -0
  53. package/dist/platform/index.mjs +396 -0
  54. package/dist/platform/index.mjs.map +1 -0
  55. package/dist/rbac/index.d.cts +21 -0
  56. package/dist/rbac/index.d.ts +21 -0
  57. package/dist/rbac/index.js +178 -0
  58. package/dist/rbac/index.js.map +1 -0
  59. package/dist/rbac/index.mjs +150 -0
  60. package/dist/rbac/index.mjs.map +1 -0
  61. package/dist/security/index.d.cts +73 -0
  62. package/dist/security/index.d.ts +73 -0
  63. package/dist/security/index.js +246 -0
  64. package/dist/security/index.js.map +1 -0
  65. package/dist/security/index.mjs +211 -0
  66. package/dist/security/index.mjs.map +1 -0
  67. package/dist/shopify-api/index.d.cts +139 -0
  68. package/dist/shopify-api/index.d.ts +139 -0
  69. package/dist/shopify-api/index.js +469 -0
  70. package/dist/shopify-api/index.js.map +1 -0
  71. package/dist/shopify-api/index.mjs +439 -0
  72. package/dist/shopify-api/index.mjs.map +1 -0
  73. package/dist/shopify-compliance/index.d.cts +85 -0
  74. package/dist/shopify-compliance/index.d.ts +85 -0
  75. package/dist/shopify-compliance/index.js +287 -0
  76. package/dist/shopify-compliance/index.js.map +1 -0
  77. package/dist/shopify-compliance/index.mjs +259 -0
  78. package/dist/shopify-compliance/index.mjs.map +1 -0
  79. package/dist/webhooks/index.d.cts +127 -0
  80. package/dist/webhooks/index.d.ts +127 -0
  81. package/dist/webhooks/index.js +18934 -0
  82. package/dist/webhooks/index.js.map +1 -0
  83. package/dist/webhooks/index.mjs +18916 -0
  84. package/dist/webhooks/index.mjs.map +1 -0
  85. package/package.json +112 -0
@@ -0,0 +1,280 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/performance/index.ts
21
+ var performance_exports = {};
22
+ __export(performance_exports, {
23
+ MockCacheManager: () => MockCacheManager,
24
+ createTestBatchConfig: () => createTestBatchConfig,
25
+ createTestCacheConfig: () => createTestCacheConfig,
26
+ createTestCacheEntry: () => createTestCacheEntry,
27
+ createTestCacheMetrics: () => createTestCacheMetrics,
28
+ createTestQueryCostConfig: () => createTestQueryCostConfig,
29
+ createTestQueryCostEntry: () => createTestQueryCostEntry,
30
+ createTestQueryCostReport: () => createTestQueryCostReport
31
+ });
32
+ module.exports = __toCommonJS(performance_exports);
33
+
34
+ // src/performance/factories.ts
35
+ function createTestCacheConfig(overrides) {
36
+ const defaults = {
37
+ defaultTTL: 6e4,
38
+ maxEntries: 1e3
39
+ };
40
+ const result = { ...defaults };
41
+ if (overrides?.defaultTTL !== void 0) {
42
+ result.defaultTTL = overrides.defaultTTL;
43
+ }
44
+ if (overrides?.maxEntries !== void 0) {
45
+ result.maxEntries = overrides.maxEntries;
46
+ }
47
+ if (overrides?.keyPrefix !== void 0) {
48
+ result.keyPrefix = overrides.keyPrefix;
49
+ }
50
+ if (overrides?.strategies !== void 0) {
51
+ result.strategies = overrides.strategies;
52
+ }
53
+ return result;
54
+ }
55
+ function createTestCacheEntry(overrides) {
56
+ const now = Date.now();
57
+ const defaults = {
58
+ key: "test-key",
59
+ value: "test-value",
60
+ createdAt: now,
61
+ expiresAt: now + 6e4,
62
+ hits: 0
63
+ };
64
+ return { ...defaults, ...overrides };
65
+ }
66
+ function createTestCacheMetrics(overrides) {
67
+ const defaults = {
68
+ hits: 0,
69
+ misses: 0,
70
+ hitRate: 0,
71
+ totalEntries: 0,
72
+ evictions: 0
73
+ };
74
+ return { ...defaults, ...overrides };
75
+ }
76
+ function createTestQueryCostConfig(overrides) {
77
+ const defaults = {
78
+ maxCostPerSecond: 1e3,
79
+ trackingWindowMs: 6e4
80
+ };
81
+ const result = { ...defaults };
82
+ if (overrides?.maxCostPerSecond !== void 0) {
83
+ result.maxCostPerSecond = overrides.maxCostPerSecond;
84
+ }
85
+ if (overrides?.trackingWindowMs !== void 0) {
86
+ result.trackingWindowMs = overrides.trackingWindowMs;
87
+ }
88
+ if (overrides?.alertThreshold !== void 0) {
89
+ result.alertThreshold = overrides.alertThreshold;
90
+ }
91
+ return result;
92
+ }
93
+ function createTestQueryCostEntry(overrides) {
94
+ const defaults = {
95
+ query: "{ shop { name } }",
96
+ actualCost: 10,
97
+ requestedCost: 12,
98
+ timestamp: Date.now()
99
+ };
100
+ return { ...defaults, ...overrides };
101
+ }
102
+ function createTestQueryCostReport(overrides) {
103
+ const defaults = {
104
+ totalCost: 0,
105
+ averageCost: 0,
106
+ maxCost: 0,
107
+ queryCount: 0,
108
+ costPerSecond: 0,
109
+ topQueries: [],
110
+ isOverBudget: false
111
+ };
112
+ return { ...defaults, ...overrides };
113
+ }
114
+ function createTestBatchConfig(overrides) {
115
+ const defaults = {
116
+ maxBatchSize: 10,
117
+ delayMs: 50
118
+ };
119
+ const result = { ...defaults };
120
+ if (overrides?.maxBatchSize !== void 0) {
121
+ result.maxBatchSize = overrides.maxBatchSize;
122
+ }
123
+ if (overrides?.delayMs !== void 0) {
124
+ result.delayMs = overrides.delayMs;
125
+ }
126
+ if (overrides?.maxDelayMs !== void 0) {
127
+ result.maxDelayMs = overrides.maxDelayMs;
128
+ }
129
+ return result;
130
+ }
131
+
132
+ // src/performance/mock-cache-manager.ts
133
+ var MockCacheManager = class {
134
+ config;
135
+ store = /* @__PURE__ */ new Map();
136
+ _hits = 0;
137
+ _misses = 0;
138
+ _evictions = 0;
139
+ /** Recorded keys for get() calls. */
140
+ getCalls = [];
141
+ /** Recorded keys for set() calls. */
142
+ setCalls = [];
143
+ /** Recorded keys for delete() calls. */
144
+ deleteCalls = [];
145
+ /** Recorded patterns for invalidate() calls. */
146
+ invalidateCalls = [];
147
+ constructor(config) {
148
+ this.config = {
149
+ defaultTTL: config?.defaultTTL ?? 6e4,
150
+ maxEntries: config?.maxEntries ?? 1e3
151
+ };
152
+ if (config?.keyPrefix !== void 0) {
153
+ this.config.keyPrefix = config.keyPrefix;
154
+ }
155
+ if (config?.strategies !== void 0) {
156
+ this.config.strategies = config.strategies;
157
+ }
158
+ }
159
+ async get(key) {
160
+ this.getCalls.push(key);
161
+ const entry = this.store.get(key);
162
+ if (!entry) {
163
+ this._misses++;
164
+ return void 0;
165
+ }
166
+ if (Date.now() >= entry.expiresAt) {
167
+ this.store.delete(key);
168
+ this._misses++;
169
+ return void 0;
170
+ }
171
+ this._hits++;
172
+ const updated = {
173
+ ...entry,
174
+ hits: entry.hits + 1
175
+ };
176
+ this.store.set(key, updated);
177
+ return updated;
178
+ }
179
+ async set(key, value, ttl) {
180
+ const callRecord = { key, value };
181
+ if (ttl !== void 0) {
182
+ callRecord.ttl = ttl;
183
+ }
184
+ this.setCalls.push(callRecord);
185
+ const resolvedTTL = ttl ?? this.config.defaultTTL;
186
+ const now = Date.now();
187
+ if (!this.store.has(key) && this.store.size >= this.config.maxEntries) {
188
+ let oldestKey;
189
+ let oldestTime = Infinity;
190
+ for (const [k, v] of this.store) {
191
+ if (v.createdAt < oldestTime) {
192
+ oldestTime = v.createdAt;
193
+ oldestKey = k;
194
+ }
195
+ }
196
+ if (oldestKey !== void 0) {
197
+ this.store.delete(oldestKey);
198
+ this._evictions++;
199
+ }
200
+ }
201
+ const entry = {
202
+ key,
203
+ value,
204
+ createdAt: now,
205
+ expiresAt: now + resolvedTTL,
206
+ hits: 0
207
+ };
208
+ this.store.set(key, entry);
209
+ }
210
+ async delete(key) {
211
+ this.deleteCalls.push(key);
212
+ return this.store.delete(key);
213
+ }
214
+ async invalidate(pattern) {
215
+ this.invalidateCalls.push(pattern);
216
+ let count = 0;
217
+ for (const key of [...this.store.keys()]) {
218
+ if (key.startsWith(pattern)) {
219
+ this.store.delete(key);
220
+ count++;
221
+ }
222
+ }
223
+ return count;
224
+ }
225
+ async has(key) {
226
+ const entry = this.store.get(key);
227
+ if (!entry) return false;
228
+ if (Date.now() >= entry.expiresAt) {
229
+ this.store.delete(key);
230
+ return false;
231
+ }
232
+ return true;
233
+ }
234
+ async warm(entries) {
235
+ for (const entry of entries) {
236
+ await this.set(entry.key, entry.value, entry.ttl);
237
+ }
238
+ }
239
+ getMetrics() {
240
+ const total = this._hits + this._misses;
241
+ return {
242
+ hits: this._hits,
243
+ misses: this._misses,
244
+ hitRate: total === 0 ? 0 : this._hits / total,
245
+ totalEntries: this.store.size,
246
+ evictions: this._evictions
247
+ };
248
+ }
249
+ resetMetrics() {
250
+ this._hits = 0;
251
+ this._misses = 0;
252
+ this._evictions = 0;
253
+ }
254
+ async clear() {
255
+ this.store.clear();
256
+ }
257
+ /** Reset all state: store, metrics, and recorded calls. */
258
+ _reset() {
259
+ this.store.clear();
260
+ this._hits = 0;
261
+ this._misses = 0;
262
+ this._evictions = 0;
263
+ this.getCalls = [];
264
+ this.setCalls = [];
265
+ this.deleteCalls = [];
266
+ this.invalidateCalls = [];
267
+ }
268
+ };
269
+ // Annotate the CommonJS export names for ESM import in node:
270
+ 0 && (module.exports = {
271
+ MockCacheManager,
272
+ createTestBatchConfig,
273
+ createTestCacheConfig,
274
+ createTestCacheEntry,
275
+ createTestCacheMetrics,
276
+ createTestQueryCostConfig,
277
+ createTestQueryCostEntry,
278
+ createTestQueryCostReport
279
+ });
280
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/performance/index.ts","../../src/performance/factories.ts","../../src/performance/mock-cache-manager.ts"],"sourcesContent":["/**\n * @uniforge/testing - Performance\n *\n * Mock performance utilities and test data factories for performance testing.\n */\n\nexport {\n createTestCacheConfig,\n createTestCacheEntry,\n createTestCacheMetrics,\n createTestQueryCostConfig,\n createTestQueryCostEntry,\n createTestQueryCostReport,\n createTestBatchConfig,\n} from './factories';\n\nexport { MockCacheManager } from './mock-cache-manager';\n","/**\n * Test data factories for performance types.\n *\n * Each factory provides sensible defaults that can be overridden.\n */\n\nimport type {\n CacheManagerConfig,\n CacheEntry,\n CacheMetrics,\n QueryCostConfig,\n QueryCostEntry,\n QueryCostReport,\n BatchConfig,\n} from '@uniforge/platform-core/performance';\n\nexport function createTestCacheConfig(\n overrides?: Partial<CacheManagerConfig>,\n): CacheManagerConfig {\n const defaults: CacheManagerConfig = {\n defaultTTL: 60000,\n maxEntries: 1000,\n };\n\n const result: CacheManagerConfig = { ...defaults };\n\n if (overrides?.defaultTTL !== undefined) {\n result.defaultTTL = overrides.defaultTTL;\n }\n if (overrides?.maxEntries !== undefined) {\n result.maxEntries = overrides.maxEntries;\n }\n if (overrides?.keyPrefix !== undefined) {\n result.keyPrefix = overrides.keyPrefix;\n }\n if (overrides?.strategies !== undefined) {\n result.strategies = overrides.strategies;\n }\n\n return result;\n}\n\nexport function createTestCacheEntry<T = string>(\n overrides?: Partial<CacheEntry<T>>,\n): CacheEntry<T> {\n const now = Date.now();\n const defaults: CacheEntry<T> = {\n key: 'test-key',\n value: 'test-value' as unknown as T,\n createdAt: now,\n expiresAt: now + 60000,\n hits: 0,\n };\n\n return { ...defaults, ...overrides };\n}\n\nexport function createTestCacheMetrics(\n overrides?: Partial<CacheMetrics>,\n): CacheMetrics {\n const defaults: CacheMetrics = {\n hits: 0,\n misses: 0,\n hitRate: 0,\n totalEntries: 0,\n evictions: 0,\n };\n\n return { ...defaults, ...overrides };\n}\n\nexport function createTestQueryCostConfig(\n overrides?: Partial<QueryCostConfig>,\n): QueryCostConfig {\n const defaults: QueryCostConfig = {\n maxCostPerSecond: 1000,\n trackingWindowMs: 60000,\n };\n\n const result: QueryCostConfig = { ...defaults };\n\n if (overrides?.maxCostPerSecond !== undefined) {\n result.maxCostPerSecond = overrides.maxCostPerSecond;\n }\n if (overrides?.trackingWindowMs !== undefined) {\n result.trackingWindowMs = overrides.trackingWindowMs;\n }\n if (overrides?.alertThreshold !== undefined) {\n result.alertThreshold = overrides.alertThreshold;\n }\n\n return result;\n}\n\nexport function createTestQueryCostEntry(\n overrides?: Partial<QueryCostEntry>,\n): QueryCostEntry {\n const defaults: QueryCostEntry = {\n query: '{ shop { name } }',\n actualCost: 10,\n requestedCost: 12,\n timestamp: Date.now(),\n };\n\n return { ...defaults, ...overrides };\n}\n\nexport function createTestQueryCostReport(\n overrides?: Partial<QueryCostReport>,\n): QueryCostReport {\n const defaults: QueryCostReport = {\n totalCost: 0,\n averageCost: 0,\n maxCost: 0,\n queryCount: 0,\n costPerSecond: 0,\n topQueries: [],\n isOverBudget: false,\n };\n\n return { ...defaults, ...overrides };\n}\n\nexport function createTestBatchConfig(\n overrides?: Partial<BatchConfig>,\n): BatchConfig {\n const defaults: BatchConfig = {\n maxBatchSize: 10,\n delayMs: 50,\n };\n\n const result: BatchConfig = { ...defaults };\n\n if (overrides?.maxBatchSize !== undefined) {\n result.maxBatchSize = overrides.maxBatchSize;\n }\n if (overrides?.delayMs !== undefined) {\n result.delayMs = overrides.delayMs;\n }\n if (overrides?.maxDelayMs !== undefined) {\n result.maxDelayMs = overrides.maxDelayMs;\n }\n\n return result;\n}\n","/**\n * Mock CacheManager for unit testing.\n *\n * Provides an in-memory implementation of CacheManager backed by\n * a Map, with metrics tracking and call recording.\n */\n\nimport type {\n CacheManager,\n CacheManagerConfig,\n CacheEntry,\n CacheMetrics,\n} from '@uniforge/platform-core/performance';\n\nexport class MockCacheManager implements CacheManager {\n readonly config: CacheManagerConfig;\n\n private store = new Map<string, CacheEntry>();\n\n private _hits = 0;\n private _misses = 0;\n private _evictions = 0;\n\n /** Recorded keys for get() calls. */\n getCalls: string[] = [];\n\n /** Recorded keys for set() calls. */\n setCalls: Array<{ key: string; value: unknown; ttl?: number }> = [];\n\n /** Recorded keys for delete() calls. */\n deleteCalls: string[] = [];\n\n /** Recorded patterns for invalidate() calls. */\n invalidateCalls: string[] = [];\n\n constructor(config?: Partial<CacheManagerConfig>) {\n this.config = {\n defaultTTL: config?.defaultTTL ?? 60000,\n maxEntries: config?.maxEntries ?? 1000,\n };\n if (config?.keyPrefix !== undefined) {\n (this.config as { keyPrefix: string }).keyPrefix = config.keyPrefix;\n }\n if (config?.strategies !== undefined) {\n (this.config as { strategies: CacheManagerConfig['strategies'] }).strategies = config.strategies;\n }\n }\n\n async get<T = unknown>(key: string): Promise<CacheEntry<T> | undefined> {\n this.getCalls.push(key);\n const entry = this.store.get(key) as CacheEntry<T> | undefined;\n\n if (!entry) {\n this._misses++;\n return undefined;\n }\n\n if (Date.now() >= entry.expiresAt) {\n this.store.delete(key);\n this._misses++;\n return undefined;\n }\n\n this._hits++;\n const updated: CacheEntry<T> = {\n ...entry,\n hits: entry.hits + 1,\n };\n this.store.set(key, updated as CacheEntry);\n return updated;\n }\n\n async set<T = unknown>(key: string, value: T, ttl?: number): Promise<void> {\n const callRecord: { key: string; value: unknown; ttl?: number } = { key, value };\n if (ttl !== undefined) {\n callRecord.ttl = ttl;\n }\n this.setCalls.push(callRecord);\n\n const resolvedTTL = ttl ?? this.config.defaultTTL;\n const now = Date.now();\n\n // Evict oldest if at capacity\n if (!this.store.has(key) && this.store.size >= this.config.maxEntries) {\n let oldestKey: string | undefined;\n let oldestTime = Infinity;\n for (const [k, v] of this.store) {\n if (v.createdAt < oldestTime) {\n oldestTime = v.createdAt;\n oldestKey = k;\n }\n }\n if (oldestKey !== undefined) {\n this.store.delete(oldestKey);\n this._evictions++;\n }\n }\n\n const entry: CacheEntry = {\n key,\n value,\n createdAt: now,\n expiresAt: now + resolvedTTL,\n hits: 0,\n };\n this.store.set(key, entry);\n }\n\n async delete(key: string): Promise<boolean> {\n this.deleteCalls.push(key);\n return this.store.delete(key);\n }\n\n async invalidate(pattern: string): Promise<number> {\n this.invalidateCalls.push(pattern);\n let count = 0;\n for (const key of [...this.store.keys()]) {\n if (key.startsWith(pattern)) {\n this.store.delete(key);\n count++;\n }\n }\n return count;\n }\n\n async has(key: string): Promise<boolean> {\n const entry = this.store.get(key);\n if (!entry) return false;\n if (Date.now() >= entry.expiresAt) {\n this.store.delete(key);\n return false;\n }\n return true;\n }\n\n async warm(entries: Array<{ key: string; value: unknown; ttl?: number }>): Promise<void> {\n for (const entry of entries) {\n await this.set(entry.key, entry.value, entry.ttl);\n }\n }\n\n getMetrics(): CacheMetrics {\n const total = this._hits + this._misses;\n return {\n hits: this._hits,\n misses: this._misses,\n hitRate: total === 0 ? 0 : this._hits / total,\n totalEntries: this.store.size,\n evictions: this._evictions,\n };\n }\n\n resetMetrics(): void {\n this._hits = 0;\n this._misses = 0;\n this._evictions = 0;\n }\n\n async clear(): Promise<void> {\n this.store.clear();\n }\n\n /** Reset all state: store, metrics, and recorded calls. */\n _reset(): void {\n this.store.clear();\n this._hits = 0;\n this._misses = 0;\n this._evictions = 0;\n this.getCalls = [];\n this.setCalls = [];\n this.deleteCalls = [];\n this.invalidateCalls = [];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACgBO,SAAS,sBACd,WACoB;AACpB,QAAM,WAA+B;AAAA,IACnC,YAAY;AAAA,IACZ,YAAY;AAAA,EACd;AAEA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ance/factories.ts
2
+ function createTestCacheConfig(overrides) {
3
+ const defaults = {
4
+ defaultTTL: 6e4,
5
+ maxEntries: 1e3
6
+ };
7
+ const result = { ...defaults };
8
+ if (overrides?.defaultTTL !== void 0) {
9
+ result.defaultTTL = overrides.defaultTTL;
10
+ }
11
+ if (overrides?.maxEntries !== void 0) {
12
+ result.maxEntries = overrides.maxEntries;
13
+ }
14
+ if (overrides?.keyPrefix !== void 0) {
15
+ result.keyPrefix = overrides.keyPrefix;
16
+ }
17
+ if (overrides?.strategies !== void 0) {
18
+ result.strategies = overrides.strategies;
19
+ }
20
+ return result;
21
+ }
22
+ function createTestCacheEntry(overrides) {
23
+ const now = Date.now();
24
+ const defaults = {
25
+ key: "test-key",
26
+ value: "test-value",
27
+ createdAt: now,
28
+ expiresAt: now + 6e4,
29
+ hits: 0
30
+ };
31
+ return { ...defaults, ...overrides };
32
+ }
33
+ function createTestCacheMetrics(overrides) {
34
+ const defaults = {
35
+ hits: 0,
36
+ misses: 0,
37
+ hitRate: 0,
38
+ totalEntries: 0,
39
+ evictions: 0
40
+ };
41
+ return { ...defaults, ...overrides };
42
+ }
43
+ function createTestQueryCostConfig(overrides) {
44
+ const defaults = {
45
+ maxCostPerSecond: 1e3,
46
+ trackingWindowMs: 6e4
47
+ };
48
+ const result = { ...defaults };
49
+ if (overrides?.maxCostPerSecond !== void 0) {
50
+ result.maxCostPerSecond = overrides.maxCostPerSecond;
51
+ }
52
+ if (overrides?.trackingWindowMs !== void 0) {
53
+ result.trackingWindowMs = overrides.trackingWindowMs;
54
+ }
55
+ if (overrides?.alertThreshold !== void 0) {
56
+ result.alertThreshold = overrides.alertThreshold;
57
+ }
58
+ return result;
59
+ }
60
+ function createTestQueryCostEntry(overrides) {
61
+ const defaults = {
62
+ query: "{ shop { name } }",
63
+ actualCost: 10,
64
+ requestedCost: 12,
65
+ timestamp: Date.now()
66
+ };
67
+ return { ...defaults, ...overrides };
68
+ }
69
+ function createTestQueryCostReport(overrides) {
70
+ const defaults = {
71
+ totalCost: 0,
72
+ averageCost: 0,
73
+ maxCost: 0,
74
+ queryCount: 0,
75
+ costPerSecond: 0,
76
+ topQueries: [],
77
+ isOverBudget: false
78
+ };
79
+ return { ...defaults, ...overrides };
80
+ }
81
+ function createTestBatchConfig(overrides) {
82
+ const defaults = {
83
+ maxBatchSize: 10,
84
+ delayMs: 50
85
+ };
86
+ const result = { ...defaults };
87
+ if (overrides?.maxBatchSize !== void 0) {
88
+ result.maxBatchSize = overrides.maxBatchSize;
89
+ }
90
+ if (overrides?.delayMs !== void 0) {
91
+ result.delayMs = overrides.delayMs;
92
+ }
93
+ if (overrides?.maxDelayMs !== void 0) {
94
+ result.maxDelayMs = overrides.maxDelayMs;
95
+ }
96
+ return result;
97
+ }
98
+
99
+ // src/performance/mock-cache-manager.ts
100
+ var MockCacheManager = class {
101
+ config;
102
+ store = /* @__PURE__ */ new Map();
103
+ _hits = 0;
104
+ _misses = 0;
105
+ _evictions = 0;
106
+ /** Recorded keys for get() calls. */
107
+ getCalls = [];
108
+ /** Recorded keys for set() calls. */
109
+ setCalls = [];
110
+ /** Recorded keys for delete() calls. */
111
+ deleteCalls = [];
112
+ /** Recorded patterns for invalidate() calls. */
113
+ invalidateCalls = [];
114
+ constructor(config) {
115
+ this.config = {
116
+ defaultTTL: config?.defaultTTL ?? 6e4,
117
+ maxEntries: config?.maxEntries ?? 1e3
118
+ };
119
+ if (config?.keyPrefix !== void 0) {
120
+ this.config.keyPrefix = config.keyPrefix;
121
+ }
122
+ if (config?.strategies !== void 0) {
123
+ this.config.strategies = config.strategies;
124
+ }
125
+ }
126
+ async get(key) {
127
+ this.getCalls.push(key);
128
+ const entry = this.store.get(key);
129
+ if (!entry) {
130
+ this._misses++;
131
+ return void 0;
132
+ }
133
+ if (Date.now() >= entry.expiresAt) {
134
+ this.store.delete(key);
135
+ this._misses++;
136
+ return void 0;
137
+ }
138
+ this._hits++;
139
+ const updated = {
140
+ ...entry,
141
+ hits: entry.hits + 1
142
+ };
143
+ this.store.set(key, updated);
144
+ return updated;
145
+ }
146
+ async set(key, value, ttl) {
147
+ const callRecord = { key, value };
148
+ if (ttl !== void 0) {
149
+ callRecord.ttl = ttl;
150
+ }
151
+ this.setCalls.push(callRecord);
152
+ const resolvedTTL = ttl ?? this.config.defaultTTL;
153
+ const now = Date.now();
154
+ if (!this.store.has(key) && this.store.size >= this.config.maxEntries) {
155
+ let oldestKey;
156
+ let oldestTime = Infinity;
157
+ for (const [k, v] of this.store) {
158
+ if (v.createdAt < oldestTime) {
159
+ oldestTime = v.createdAt;
160
+ oldestKey = k;
161
+ }
162
+ }
163
+ if (oldestKey !== void 0) {
164
+ this.store.delete(oldestKey);
165
+ this._evictions++;
166
+ }
167
+ }
168
+ const entry = {
169
+ key,
170
+ value,
171
+ createdAt: now,
172
+ expiresAt: now + resolvedTTL,
173
+ hits: 0
174
+ };
175
+ this.store.set(key, entry);
176
+ }
177
+ async delete(key) {
178
+ this.deleteCalls.push(key);
179
+ return this.store.delete(key);
180
+ }
181
+ async invalidate(pattern) {
182
+ this.invalidateCalls.push(pattern);
183
+ let count = 0;
184
+ for (const key of [...this.store.keys()]) {
185
+ if (key.startsWith(pattern)) {
186
+ this.store.delete(key);
187
+ count++;
188
+ }
189
+ }
190
+ return count;
191
+ }
192
+ async has(key) {
193
+ const entry = this.store.get(key);
194
+ if (!entry) return false;
195
+ if (Date.now() >= entry.expiresAt) {
196
+ this.store.delete(key);
197
+ return false;
198
+ }
199
+ return true;
200
+ }
201
+ async warm(entries) {
202
+ for (const entry of entries) {
203
+ await this.set(entry.key, entry.value, entry.ttl);
204
+ }
205
+ }
206
+ getMetrics() {
207
+ const total = this._hits + this._misses;
208
+ return {
209
+ hits: this._hits,
210
+ misses: this._misses,
211
+ hitRate: total === 0 ? 0 : this._hits / total,
212
+ totalEntries: this.store.size,
213
+ evictions: this._evictions
214
+ };
215
+ }
216
+ resetMetrics() {
217
+ this._hits = 0;
218
+ this._misses = 0;
219
+ this._evictions = 0;
220
+ }
221
+ async clear() {
222
+ this.store.clear();
223
+ }
224
+ /** Reset all state: store, metrics, and recorded calls. */
225
+ _reset() {
226
+ this.store.clear();
227
+ this._hits = 0;
228
+ this._misses = 0;
229
+ this._evictions = 0;
230
+ this.getCalls = [];
231
+ this.setCalls = [];
232
+ this.deleteCalls = [];
233
+ this.invalidateCalls = [];
234
+ }
235
+ };
236
+ export {
237
+ MockCacheManager,
238
+ createTestBatchConfig,
239
+ createTestCacheConfig,
240
+ createTestCacheEntry,
241
+ createTestCacheMetrics,
242
+ createTestQueryCostConfig,
243
+ createTestQueryCostEntry,
244
+ createTestQueryCostReport
245
+ };
246
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/performance/factories.ts","../../src/performance/mock-cache-manager.ts"],"sourcesContent":["/**\n * Test data factories for performance types.\n *\n * Each factory provides sensible defaults that can be overridden.\n */\n\nimport type {\n CacheManagerConfig,\n CacheEntry,\n CacheMetrics,\n QueryCostConfig,\n QueryCostEntry,\n QueryCostReport,\n BatchConfig,\n} from '@uniforge/platform-core/performance';\n\nexport function createTestCacheConfig(\n overrides?: Partial<CacheManagerConfig>,\n): CacheManagerConfig {\n const defaults: CacheManagerConfig = {\n defaultTTL: 60000,\n maxEntries: 1000,\n };\n\n const result: CacheManagerConfig = { ...defaults };\n\n if (overrides?.defaultTTL !== undefined) {\n result.defaultTTL = overrides.defaultTTL;\n }\n if (overrides?.maxEntries !== undefined) {\n result.maxEntries = overrides.maxEntries;\n }\n if (overrides?.keyPrefix !== undefined) {\n result.keyPrefix = overrides.keyPrefix;\n }\n if (overrides?.strategies !== undefined) {\n result.strategies = overrides.strategies;\n }\n\n return result;\n}\n\nexport function createTestCacheEntry<T = string>(\n overrides?: Partial<CacheEntry<T>>,\n): CacheEntry<T> {\n const now = Date.now();\n const defaults: CacheEntry<T> = {\n key: 'test-key',\n value: 'test-value' as unknown as T,\n createdAt: now,\n expiresAt: now + 60000,\n hits: 0,\n };\n\n return { ...defaults, ...overrides };\n}\n\nexport function createTestCacheMetrics(\n overrides?: Partial<CacheMetrics>,\n): CacheMetrics {\n const defaults: CacheMetrics = {\n hits: 0,\n misses: 0,\n hitRate: 0,\n totalEntries: 0,\n evictions: 0,\n };\n\n return { ...defaults, ...overrides };\n}\n\nexport function createTestQueryCostConfig(\n overrides?: Partial<QueryCostConfig>,\n): QueryCostConfig {\n const defaults: QueryCostConfig = {\n maxCostPerSecond: 1000,\n trackingWindowMs: 60000,\n };\n\n const result: QueryCostConfig = { ...defaults };\n\n if (overrides?.maxCostPerSecond !== undefined) {\n result.maxCostPerSecond = overrides.maxCostPerSecond;\n }\n if (overrides?.trackingWindowMs !== undefined) {\n result.trackingWindowMs = overrides.trackingWindowMs;\n }\n if (overrides?.alertThreshold !== undefined) {\n result.alertThreshold = overrides.alertThreshold;\n }\n\n return result;\n}\n\nexport function createTestQueryCostEntry(\n overrides?: Partial<QueryCostEntry>,\n): QueryCostEntry {\n const defaults: QueryCostEntry = {\n query: '{ shop { name } }',\n actualCost: 10,\n requestedCost: 12,\n timestamp: Date.now(),\n };\n\n return { ...defaults, ...overrides };\n}\n\nexport function createTestQueryCostReport(\n overrides?: Partial<QueryCostReport>,\n): QueryCostReport {\n const defaults: QueryCostReport = {\n totalCost: 0,\n averageCost: 0,\n maxCost: 0,\n queryCount: 0,\n costPerSecond: 0,\n topQueries: [],\n isOverBudget: false,\n };\n\n return { ...defaults, ...overrides };\n}\n\nexport function createTestBatchConfig(\n overrides?: Partial<BatchConfig>,\n): BatchConfig {\n const defaults: BatchConfig = {\n maxBatchSize: 10,\n delayMs: 50,\n };\n\n const result: BatchConfig = { ...defaults };\n\n if (overrides?.maxBatchSize !== undefined) {\n result.maxBatchSize = overrides.maxBatchSize;\n }\n if (overrides?.delayMs !== undefined) {\n result.delayMs = overrides.delayMs;\n }\n if (overrides?.maxDelayMs !== undefined) {\n result.maxDelayMs = overrides.maxDelayMs;\n }\n\n return result;\n}\n","/**\n * Mock CacheManager for unit testing.\n *\n * Provides an in-memory implementation of CacheManager backed by\n * a Map, with metrics tracking and call recording.\n */\n\nimport type {\n CacheManager,\n CacheManagerConfig,\n CacheEntry,\n CacheMetrics,\n} from '@uniforge/platform-core/performance';\n\nexport class MockCacheManager implements CacheManager {\n readonly config: CacheManagerConfig;\n\n private store = new Map<string, CacheEntry>();\n\n private _hits = 0;\n private _misses = 0;\n private _evictions = 0;\n\n /** Recorded keys for get() calls. */\n getCalls: string[] = [];\n\n /** Recorded keys for set() calls. */\n setCalls: Array<{ key: string; value: unknown; ttl?: number }> = [];\n\n /** Recorded keys for delete() calls. */\n deleteCalls: string[] = [];\n\n /** Recorded patterns for invalidate() calls. */\n invalidateCalls: string[] = [];\n\n constructor(config?: Partial<CacheManagerConfig>) {\n this.config = {\n defaultTTL: config?.defaultTTL ?? 60000,\n maxEntries: config?.maxEntries ?? 1000,\n };\n if (config?.keyPrefix !== undefined) {\n (this.config as { keyPrefix: string }).keyPrefix = config.keyPrefix;\n }\n if (config?.strategies !== undefined) {\n (this.config as { strategies: CacheManagerConfig['strategies'] }).strategies = config.strategies;\n }\n }\n\n async get<T = unknown>(key: string): Promise<CacheEntry<T> | undefined> {\n this.getCalls.push(key);\n const entry = this.store.get(key) as CacheEntry<T> | undefined;\n\n if (!entry) {\n this._misses++;\n return undefined;\n }\n\n if (Date.now() >= entry.expiresAt) {\n this.store.delete(key);\n this._misses++;\n return undefined;\n }\n\n this._hits++;\n const updated: CacheEntry<T> = {\n ...entry,\n hits: entry.hits + 1,\n };\n this.store.set(key, updated as CacheEntry);\n return updated;\n }\n\n async set<T = unknown>(key: string, value: T, ttl?: number): Promise<void> {\n const callRecord: { key: string; value: unknown; ttl?: number } = { key, value };\n if (ttl !== undefined) {\n callRecord.ttl = ttl;\n }\n this.setCalls.push(callRecord);\n\n const resolvedTTL = ttl ?? this.config.defaultTTL;\n const now = Date.now();\n\n // Evict oldest if at capacity\n if (!this.store.has(key) && this.store.size >= this.config.maxEntries) {\n let oldestKey: string | undefined;\n let oldestTime = Infinity;\n for (const [k, v] of this.store) {\n if (v.createdAt < oldestTime) {\n oldestTime = v.createdAt;\n oldestKey = k;\n }\n }\n if (oldestKey !== undefined) {\n this.store.delete(oldestKey);\n this._evictions++;\n }\n }\n\n const entry: CacheEntry = {\n key,\n value,\n createdAt: now,\n expiresAt: now + resolvedTTL,\n hits: 0,\n };\n this.store.set(key, entry);\n }\n\n async delete(key: string): Promise<boolean> {\n this.deleteCalls.push(key);\n return this.store.delete(key);\n }\n\n async invalidate(pattern: string): Promise<number> {\n this.invalidateCalls.push(pattern);\n let count = 0;\n for (const key of [...this.store.keys()]) {\n if (key.startsWith(pattern)) {\n this.store.delete(key);\n count++;\n }\n }\n return count;\n }\n\n async has(key: string): Promise<boolean> {\n const entry = this.store.get(key);\n if (!entry) return false;\n if (Date.now() >= entry.expiresAt) {\n this.store.delete(key);\n return false;\n }\n return true;\n }\n\n async warm(entries: Array<{ key: string; value: unknown; ttl?: number }>): Promise<void> {\n for (const entry of entries) {\n await this.set(entry.key, entry.value, entry.ttl);\n }\n }\n\n getMetrics(): CacheMetrics {\n const total = this._hits + this._misses;\n return {\n hits: this._hits,\n misses: this._misses,\n hitRate: total === 0 ? 0 : this._hits / total,\n totalEntries: this.store.size,\n evictions: this._evictions,\n };\n }\n\n resetMetrics(): void {\n this._hits = 0;\n this._misses = 0;\n this._evictions = 0;\n }\n\n async clear(): Promise<void> {\n this.store.clear();\n }\n\n /** Reset all state: store, metrics, and recorded calls. */\n _reset(): void {\n this.store.clear();\n this._hits = 0;\n this._misses = 0;\n this._evictions = 0;\n this.getCalls = [];\n this.setCalls = [];\n this.deleteCalls = [];\n this.invalidateCalls = [];\n }\n}\n"],"mappings":";AAgBO,SAAS,sBACd,WACoB;AACpB,QAAM,WAA+B;AAAA,IACnC,YAAY;AAAA,IACZ,YAAY;AAAA,EACd;AAEA,QAAM,SAA6B,EAAE,GAAG,SAAS;AAEjD,MAAI,WAAW,eAAe,QAA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W,OAAO,CAAC,GAAG,KAAK,MAAM,KAAK,CAAC,GAAG;AACxC,UAAI,IAAI,WAAW,OAAO,GAAG;AAC3B,aAAK,MAAM,OAAO,GAAG;AACrB;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,IAAI,KAA+B;AACvC,UAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;AAChC,QAAI,CAAC,MAAO,QAAO;AACnB,QAAI,KAAK,IAAI,KAAK,MAAM,WAAW;AACjC,WAAK,MAAM,OAAO,GAAG;AACrB,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,SAA8E;AACvF,eAAW,SAAS,SAAS;AAC3B,YAAM,KAAK,IAAI,MAAM,KAAK,MAAM,OAAO,MAAM,GAAG;AAAA,IAClD;AAAA,EACF;AAAA,EAEA,aAA2B;AACzB,UAAM,QAAQ,KAAK,QAAQ,KAAK;AAChC,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,QAAQ,KAAK;AAAA,MACb,SAAS,UAAU,IAAI,IAAI,KAAK,QAAQ;AAAA,MACxC,cAAc,KAAK,MAAM;AAAA,MACzB,WAAW,KAAK;AAAA,IAClB;AAAA,EACF;AAAA,EAEA,eAAqB;AACnB,SAAK,QAAQ;AACb,SAAK,UAAU;AACf,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,MAAM,QAAuB;AAC3B,SAAK,MAAM,MAAM;AAAA,EACnB;AAAA;AAAA,EAGA,SAAe;AACb,SAAK,MAAM,MAAM;AACjB,SAAK,QAAQ;AACb,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,SAAK,WAAW,CAAC;AACjB,SAAK,WAAW,CAAC;AACjB,SAAK,cAAc,CAAC;AACpB,SAAK,kBAAkB,CAAC;AAAA,EAC1B;AACF;","names":[]}
@@ -0,0 +1,71 @@
1
+ import { PlatformProvider, PlatformCapabilities, Money, Product, ProductVariant, ProductImage, Order, OrderLineItem, Customer, PlatformRegistry, PlatformId, ProductService, ListOptions, PaginatedResult, CreateProductInput, UpdateProductInput, OrderService, CustomerService, CreateCustomerInput, UpdateCustomerInput } from '@uniforge/platform-core/platform';
2
+
3
+ /**
4
+ * Test data factories for platform types.
5
+ *
6
+ * Each factory provides sensible defaults that can be overridden.
7
+ */
8
+
9
+ declare function createTestMoney(overrides?: Partial<Money>): Money;
10
+ declare function createTestCapabilities(overrides?: Partial<PlatformCapabilities>): PlatformCapabilities;
11
+ declare function createTestPlatformProvider(overrides?: Partial<PlatformProvider>): PlatformProvider;
12
+ declare function createTestProductImage(overrides?: Partial<ProductImage>): ProductImage;
13
+ declare function createTestProductVariant(overrides?: Partial<ProductVariant>): ProductVariant;
14
+ declare function createTestProduct(overrides?: Partial<Product>): Product;
15
+ declare function createTestOrderLineItem(overrides?: Partial<OrderLineItem>): OrderLineItem;
16
+ declare function createTestOrder(overrides?: Partial<Order>): Order;
17
+ declare function createTestCustomer(overrides?: Partial<Customer>): Customer;
18
+
19
+ /**
20
+ * Mock PlatformRegistry for unit testing.
21
+ *
22
+ * In-memory implementation of the PlatformRegistry interface
23
+ * with a _reset() method for test isolation.
24
+ */
25
+
26
+ declare class MockPlatformRegistry implements PlatformRegistry {
27
+ private providers;
28
+ register(provider: PlatformProvider): void;
29
+ get(platformId: PlatformId): PlatformProvider | undefined;
30
+ has(platformId: PlatformId): boolean;
31
+ list(): PlatformId[];
32
+ getAll(): PlatformProvider[];
33
+ _reset(): void;
34
+ }
35
+
36
+ /**
37
+ * Mock commerce services for unit testing.
38
+ *
39
+ * In-memory implementations of ProductService, OrderService,
40
+ * and CustomerService with helpers for seeding test data.
41
+ */
42
+
43
+ declare class MockProductService implements ProductService {
44
+ private products;
45
+ _addProduct(product: Product): void;
46
+ _reset(): void;
47
+ getProduct(id: string): Promise<Product | null>;
48
+ listProducts(options?: ListOptions): Promise<PaginatedResult<Product>>;
49
+ createProduct(input: CreateProductInput): Promise<Product>;
50
+ updateProduct(id: string, input: UpdateProductInput): Promise<Product>;
51
+ deleteProduct(id: string): Promise<void>;
52
+ }
53
+ declare class MockOrderService implements OrderService {
54
+ private orders;
55
+ _addOrder(order: Order): void;
56
+ _reset(): void;
57
+ getOrder(id: string): Promise<Order | null>;
58
+ listOrders(options?: ListOptions): Promise<PaginatedResult<Order>>;
59
+ }
60
+ declare class MockCustomerService implements CustomerService {
61
+ private customers;
62
+ _addCustomer(customer: Customer): void;
63
+ _reset(): void;
64
+ getCustomer(id: string): Promise<Customer | null>;
65
+ listCustomers(options?: ListOptions): Promise<PaginatedResult<Customer>>;
66
+ createCustomer(input: CreateCustomerInput): Promise<Customer>;
67
+ updateCustomer(id: string, input: UpdateCustomerInput): Promise<Customer>;
68
+ deleteCustomer(id: string): Promise<void>;
69
+ }
70
+
71
+ export { MockCustomerService, MockOrderService, MockPlatformRegistry, MockProductService, createTestCapabilities, createTestCustomer, createTestMoney, createTestOrder, createTestOrderLineItem, createTestPlatformProvider, createTestProduct, createTestProductImage, createTestProductVariant };