@beignet/core 0.0.12 → 0.0.14
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/CHANGELOG.md +21 -0
- package/README.md +159 -9
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +29 -1
- package/dist/client/client.js.map +1 -1
- package/dist/entitlements/index.d.ts +234 -0
- package/dist/entitlements/index.d.ts.map +1 -0
- package/dist/entitlements/index.js +172 -0
- package/dist/entitlements/index.js.map +1 -0
- package/dist/error-reporting/index.d.ts +131 -0
- package/dist/error-reporting/index.d.ts.map +1 -0
- package/dist/error-reporting/index.js +112 -0
- package/dist/error-reporting/index.js.map +1 -0
- package/dist/flags/index.d.ts +293 -0
- package/dist/flags/index.d.ts.map +1 -0
- package/dist/flags/index.js +204 -0
- package/dist/flags/index.js.map +1 -0
- package/dist/locks/index.d.ts +155 -0
- package/dist/locks/index.d.ts.map +1 -0
- package/dist/locks/index.js +248 -0
- package/dist/locks/index.js.map +1 -0
- package/dist/payments/index.d.ts +430 -0
- package/dist/payments/index.d.ts.map +1 -0
- package/dist/payments/index.js +230 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/ports/index.d.ts +61 -1
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +33 -0
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/policy.d.ts +104 -0
- package/dist/ports/policy.d.ts.map +1 -1
- package/dist/ports/policy.js +102 -7
- package/dist/ports/policy.js.map +1 -1
- package/dist/search/index.d.ts +175 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +344 -0
- package/dist/search/index.js.map +1 -0
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +9 -1
- package/dist/server/server.js.map +1 -1
- package/dist/testing/index.d.ts +46 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +33 -1
- package/dist/testing/index.js.map +1 -1
- package/package.json +25 -1
- package/src/client/client.ts +33 -1
- package/src/entitlements/index.ts +479 -0
- package/src/error-reporting/index.ts +273 -0
- package/src/flags/index.ts +608 -0
- package/src/locks/index.ts +440 -0
- package/src/payments/index.ts +699 -0
- package/src/ports/index.ts +194 -0
- package/src/ports/policy.ts +272 -7
- package/src/search/index.ts +632 -0
- package/src/server/server.ts +15 -0
- package/src/testing/index.ts +83 -1
package/src/testing/index.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMemoryErrorReporter,
|
|
3
|
+
type MemoryErrorReporterPort,
|
|
4
|
+
} from "../error-reporting/index.js";
|
|
5
|
+
import { createMemoryFlags, type MemoryFlagsPort } from "../flags/index.js";
|
|
1
6
|
import {
|
|
2
7
|
createMemoryIdempotencyStore,
|
|
3
8
|
type MemoryIdempotencyStore,
|
|
4
9
|
} from "../idempotency/index.js";
|
|
10
|
+
import { createMemoryLocks, type MemoryLocksPort } from "../locks/index.js";
|
|
5
11
|
import { createMemoryMailer, type MemoryMailerPort } from "../mail/index.js";
|
|
6
12
|
import {
|
|
7
13
|
createMemoryNotificationPort,
|
|
8
14
|
type MemoryNotificationPort,
|
|
9
15
|
} from "../notifications/index.js";
|
|
10
16
|
import { createMemoryOutbox, type MemoryOutboxPort } from "../outbox/index.js";
|
|
17
|
+
import {
|
|
18
|
+
createMemoryPayments,
|
|
19
|
+
type MemoryPaymentsPort,
|
|
20
|
+
} from "../payments/index.js";
|
|
11
21
|
import {
|
|
12
22
|
type ActivityActor,
|
|
13
23
|
type ActivityTenant,
|
|
@@ -54,6 +64,7 @@ import type {
|
|
|
54
64
|
AnyServiceProvider,
|
|
55
65
|
ProviderSetupResult,
|
|
56
66
|
} from "../providers/provider.js";
|
|
67
|
+
import { createMemorySearch, type MemorySearchPort } from "../search/index.js";
|
|
57
68
|
import { createAmbientAuditLog } from "../server/audit-context.js";
|
|
58
69
|
import {
|
|
59
70
|
clearActiveRequestContext,
|
|
@@ -89,11 +100,19 @@ export interface CommonTestPorts<TxPorts = AnyPorts> {
|
|
|
89
100
|
* Recording event bus.
|
|
90
101
|
*/
|
|
91
102
|
eventBus: EventBusPort;
|
|
103
|
+
/**
|
|
104
|
+
* In-memory error reporter.
|
|
105
|
+
*/
|
|
106
|
+
errorReporter: MemoryErrorReporterPort;
|
|
92
107
|
/**
|
|
93
108
|
* Authorization gate. Apps with real policies should provide their own gate
|
|
94
109
|
* through `overrides`.
|
|
95
110
|
*/
|
|
96
111
|
gate: GatePort<unknown, []>;
|
|
112
|
+
/**
|
|
113
|
+
* In-memory feature flags.
|
|
114
|
+
*/
|
|
115
|
+
flags: MemoryFlagsPort;
|
|
97
116
|
/**
|
|
98
117
|
* In-memory idempotency store.
|
|
99
118
|
*/
|
|
@@ -110,6 +129,10 @@ export interface CommonTestPorts<TxPorts = AnyPorts> {
|
|
|
110
129
|
* No-op logger.
|
|
111
130
|
*/
|
|
112
131
|
logger: LoggerPort;
|
|
132
|
+
/**
|
|
133
|
+
* In-memory lease-backed locks.
|
|
134
|
+
*/
|
|
135
|
+
locks: MemoryLocksPort;
|
|
113
136
|
/**
|
|
114
137
|
* In-memory mailer.
|
|
115
138
|
*/
|
|
@@ -122,6 +145,14 @@ export interface CommonTestPorts<TxPorts = AnyPorts> {
|
|
|
122
145
|
* In-memory outbox.
|
|
123
146
|
*/
|
|
124
147
|
outbox: MemoryOutboxPort;
|
|
148
|
+
/**
|
|
149
|
+
* In-memory payments port.
|
|
150
|
+
*/
|
|
151
|
+
payments: MemoryPaymentsPort;
|
|
152
|
+
/**
|
|
153
|
+
* In-memory search port.
|
|
154
|
+
*/
|
|
155
|
+
search: MemorySearchPort;
|
|
125
156
|
/**
|
|
126
157
|
* In-memory rate limiter.
|
|
127
158
|
*/
|
|
@@ -159,6 +190,10 @@ export interface TestPortsFixture<
|
|
|
159
190
|
* Recorded events published through `eventBus`.
|
|
160
191
|
*/
|
|
161
192
|
events: RecordedEvent[];
|
|
193
|
+
/**
|
|
194
|
+
* Memory error reporter, exposed for assertions.
|
|
195
|
+
*/
|
|
196
|
+
errorReporter: MemoryErrorReporterPort;
|
|
162
197
|
/**
|
|
163
198
|
* Recording job dispatcher port.
|
|
164
199
|
*/
|
|
@@ -179,6 +214,10 @@ export interface TestPortsFixture<
|
|
|
179
214
|
* Memory outbox, exposed for durable workflow assertions.
|
|
180
215
|
*/
|
|
181
216
|
outbox: MemoryOutboxPort;
|
|
217
|
+
/**
|
|
218
|
+
* Memory payments port.
|
|
219
|
+
*/
|
|
220
|
+
payments: MemoryPaymentsPort;
|
|
182
221
|
/**
|
|
183
222
|
* Memory storage port.
|
|
184
223
|
*/
|
|
@@ -191,6 +230,10 @@ export interface TestPortsFixture<
|
|
|
191
230
|
* Test cache port.
|
|
192
231
|
*/
|
|
193
232
|
cache: CachePort;
|
|
233
|
+
/**
|
|
234
|
+
* Test feature flags port.
|
|
235
|
+
*/
|
|
236
|
+
flags: MemoryFlagsPort;
|
|
194
237
|
/**
|
|
195
238
|
* Test rate-limit port.
|
|
196
239
|
*/
|
|
@@ -199,6 +242,14 @@ export interface TestPortsFixture<
|
|
|
199
242
|
* Test logger port.
|
|
200
243
|
*/
|
|
201
244
|
logger: LoggerPort;
|
|
245
|
+
/**
|
|
246
|
+
* Test locks port.
|
|
247
|
+
*/
|
|
248
|
+
locks: MemoryLocksPort;
|
|
249
|
+
/**
|
|
250
|
+
* Test search port.
|
|
251
|
+
*/
|
|
252
|
+
search: MemorySearchPort;
|
|
202
253
|
/**
|
|
203
254
|
* Test clock port.
|
|
204
255
|
*/
|
|
@@ -323,14 +374,22 @@ export function createTestPorts<
|
|
|
323
374
|
const cache = createMemoryCache();
|
|
324
375
|
const clock = options.clock ?? createFrozenClock();
|
|
325
376
|
const { bus: eventBus, events } = createRecordingEventBus();
|
|
377
|
+
const errorReporter = createMemoryErrorReporter();
|
|
378
|
+
const flags = createMemoryFlags();
|
|
326
379
|
const { jobs, dispatchedJobs } = createRecordingJobDispatcher();
|
|
327
380
|
const idempotency = createMemoryIdempotencyStore();
|
|
328
381
|
const ids = options.ids ?? createUuidIdGenerator();
|
|
329
382
|
const logger = createNoopLogger();
|
|
383
|
+
const locks = createMemoryLocks({
|
|
384
|
+
now: () => clock.now(),
|
|
385
|
+
sleep: createClockAwareSleep(clock),
|
|
386
|
+
});
|
|
330
387
|
const mailer = createMemoryMailer();
|
|
331
388
|
const notifications = createMemoryNotificationPort();
|
|
332
389
|
const outbox = createMemoryOutbox();
|
|
390
|
+
const payments = createMemoryPayments();
|
|
333
391
|
const rateLimit = createMemoryRateLimiter();
|
|
392
|
+
const search = createMemorySearch();
|
|
334
393
|
const storage = createMemoryStorage();
|
|
335
394
|
|
|
336
395
|
const defaultPorts = {
|
|
@@ -338,15 +397,20 @@ export function createTestPorts<
|
|
|
338
397
|
cache,
|
|
339
398
|
clock,
|
|
340
399
|
eventBus,
|
|
400
|
+
errorReporter,
|
|
401
|
+
flags,
|
|
341
402
|
gate: createGate({ policies: [] }),
|
|
342
403
|
idempotency,
|
|
343
404
|
ids,
|
|
344
405
|
jobs,
|
|
345
406
|
logger,
|
|
407
|
+
locks,
|
|
346
408
|
mailer,
|
|
347
409
|
notifications,
|
|
348
410
|
outbox,
|
|
411
|
+
payments,
|
|
349
412
|
rateLimit,
|
|
413
|
+
search,
|
|
350
414
|
storage,
|
|
351
415
|
};
|
|
352
416
|
const overrides = completeTestPortOverrides(options.overrides);
|
|
@@ -409,16 +473,21 @@ export function createTestPorts<
|
|
|
409
473
|
audit,
|
|
410
474
|
eventBus,
|
|
411
475
|
events,
|
|
476
|
+
errorReporter,
|
|
412
477
|
jobs,
|
|
413
478
|
dispatchedJobs,
|
|
414
479
|
mailer,
|
|
415
480
|
notifications,
|
|
416
481
|
outbox,
|
|
482
|
+
payments,
|
|
417
483
|
storage,
|
|
418
484
|
idempotency,
|
|
419
485
|
cache,
|
|
486
|
+
flags,
|
|
420
487
|
rateLimit,
|
|
421
488
|
logger,
|
|
489
|
+
locks,
|
|
490
|
+
search,
|
|
422
491
|
clock,
|
|
423
492
|
ids,
|
|
424
493
|
uow,
|
|
@@ -432,6 +501,19 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
|
432
501
|
return proto === Object.prototype || proto === null;
|
|
433
502
|
}
|
|
434
503
|
|
|
504
|
+
function createClockAwareSleep(
|
|
505
|
+
clock: ClockPort,
|
|
506
|
+
): (ms: number) => Promise<void> {
|
|
507
|
+
const maybeFrozenClock = clock as Partial<{ advance(ms: number): void }>;
|
|
508
|
+
if (typeof maybeFrozenClock.advance === "function") {
|
|
509
|
+
return async (ms) => {
|
|
510
|
+
maybeFrozenClock.advance?.(ms);
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
return (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
515
|
+
}
|
|
516
|
+
|
|
435
517
|
function createMissingTestPortMember(
|
|
436
518
|
portKey: string,
|
|
437
519
|
member: string,
|
|
@@ -799,7 +881,7 @@ export interface TestContextFixture<Ctx, Ports extends AnyPorts>
|
|
|
799
881
|
|
|
800
882
|
/**
|
|
801
883
|
* Create a one-call test context fixture for jobs, listeners, schedules,
|
|
802
|
-
* notifications, tasks, and use-case tests.
|
|
884
|
+
* notifications, payments, tasks, and use-case tests.
|
|
803
885
|
*
|
|
804
886
|
* The fixture builds common memory ports through `createTestPorts(...)`,
|
|
805
887
|
* assembles an app context with actor, tenant, request ID, trace ID, auth,
|