@ahoo-wang/fetcher-wow 3.15.2 → 3.15.4
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/README.md +133 -7
- package/README.zh-CN.md +133 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -171,11 +171,41 @@ import {
|
|
|
171
171
|
ne,
|
|
172
172
|
gt,
|
|
173
173
|
lt,
|
|
174
|
+
gte,
|
|
175
|
+
lte,
|
|
174
176
|
contains,
|
|
175
177
|
isIn,
|
|
178
|
+
notIn,
|
|
176
179
|
between,
|
|
180
|
+
allIn,
|
|
181
|
+
startsWith,
|
|
182
|
+
endsWith,
|
|
183
|
+
match,
|
|
184
|
+
elemMatch,
|
|
185
|
+
isNull,
|
|
186
|
+
notNull,
|
|
187
|
+
isTrue,
|
|
188
|
+
isFalse,
|
|
189
|
+
exists,
|
|
190
|
+
raw,
|
|
177
191
|
today,
|
|
192
|
+
beforeToday,
|
|
193
|
+
tomorrow,
|
|
194
|
+
thisWeek,
|
|
195
|
+
nextWeek,
|
|
196
|
+
lastWeek,
|
|
197
|
+
thisMonth,
|
|
198
|
+
lastMonth,
|
|
199
|
+
recentDays,
|
|
200
|
+
earlierDays,
|
|
178
201
|
active,
|
|
202
|
+
all,
|
|
203
|
+
id,
|
|
204
|
+
ids,
|
|
205
|
+
aggregateId,
|
|
206
|
+
aggregateIds,
|
|
207
|
+
tenantId,
|
|
208
|
+
ownerId,
|
|
179
209
|
} from '@ahoo-wang/fetcher-wow';
|
|
180
210
|
|
|
181
211
|
// Simple conditions
|
|
@@ -184,6 +214,47 @@ const simpleConditions = [
|
|
|
184
214
|
ne('status', 'inactive'),
|
|
185
215
|
gt('age', 18),
|
|
186
216
|
lt('score', 100),
|
|
217
|
+
gte('rating', 4.0),
|
|
218
|
+
lte('price', 100),
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
// String conditions
|
|
222
|
+
const stringConditions = [
|
|
223
|
+
contains('email', '@company.com'),
|
|
224
|
+
startsWith('username', 'j'),
|
|
225
|
+
endsWith('domain', '.com'),
|
|
226
|
+
isIn('status', 'active', 'pending'),
|
|
227
|
+
notIn('role', 'guest', 'banned'),
|
|
228
|
+
match('description', 'search keywords'),
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
// Null checks
|
|
232
|
+
const nullConditions = [
|
|
233
|
+
isNull('deletedAt'),
|
|
234
|
+
notNull('email'),
|
|
235
|
+
isTrue('isActive'),
|
|
236
|
+
isFalse('isDeleted'),
|
|
237
|
+
exists('phoneNumber'),
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
// Array conditions
|
|
241
|
+
const arrayConditions = [
|
|
242
|
+
allIn('tags', 'react', 'typescript'),
|
|
243
|
+
elemMatch('items', eq('quantity', 0)),
|
|
244
|
+
];
|
|
245
|
+
|
|
246
|
+
// Date conditions
|
|
247
|
+
const dateConditions = [
|
|
248
|
+
today('createdAt'),
|
|
249
|
+
beforeToday('lastLogin', 7), // 7 days before today (i.e., within last 7 days)
|
|
250
|
+
tomorrow('scheduledDate'),
|
|
251
|
+
thisWeek('updatedAt'),
|
|
252
|
+
nextWeek('startDate'),
|
|
253
|
+
lastWeek('endDate'),
|
|
254
|
+
thisMonth('createdDate'),
|
|
255
|
+
lastMonth('expirationDate'),
|
|
256
|
+
recentDays('createdAt', 5), // Last 5 days including today
|
|
257
|
+
earlierDays('createdAt', 3), // More than 3 days ago
|
|
187
258
|
];
|
|
188
259
|
|
|
189
260
|
// Complex conditions
|
|
@@ -198,15 +269,24 @@ const complexCondition = and(
|
|
|
198
269
|
active(),
|
|
199
270
|
);
|
|
200
271
|
|
|
201
|
-
//
|
|
202
|
-
const
|
|
203
|
-
today('createdAt'),
|
|
204
|
-
beforeToday('lastLogin', 7), // Within last 7 days
|
|
205
|
-
thisWeek('updatedAt'),
|
|
206
|
-
lastMonth('createdDate'),
|
|
207
|
-
];
|
|
272
|
+
// Raw condition for advanced use cases
|
|
273
|
+
const rawCondition = raw({ $text: { $search: 'keywords' } });
|
|
208
274
|
```
|
|
209
275
|
|
|
276
|
+
**Operator Reference:**
|
|
277
|
+
|
|
278
|
+
| Category | Operators |
|
|
279
|
+
|----------|-----------|
|
|
280
|
+
| Logical | `and`, `or`, `nor` |
|
|
281
|
+
| Comparison | `eq`, `ne`, `gt`, `lt`, `gte`, `lte` |
|
|
282
|
+
| String | `contains`, `startsWith`, `endsWith`, `match` |
|
|
283
|
+
| Collection | `isIn`, `notIn`, `allIn`, `elemMatch` |
|
|
284
|
+
| Null/Boolean | `isNull`, `notNull`, `isTrue`, `isFalse`, `exists` |
|
|
285
|
+
| Date | `today`, `beforeToday(days)`, `tomorrow`, `thisWeek`, `nextWeek`, `lastWeek`, `thisMonth`, `lastMonth`, `recentDays(days)`, `earlierDays(days)` |
|
|
286
|
+
| ID | `id`, `ids`, `aggregateId`, `aggregateIds`, `tenantId`, `ownerId` |
|
|
287
|
+
| State | `active`, `all`, `deleted` |
|
|
288
|
+
| Special | `raw` (for advanced database-specific queries) |
|
|
289
|
+
|
|
210
290
|
#### SnapshotQueryClient
|
|
211
291
|
|
|
212
292
|
Client for querying materialized snapshots with comprehensive query operations:
|
|
@@ -327,6 +407,52 @@ const singleState = await cartSnapshotQueryClient.singleState(singleQuery);
|
|
|
327
407
|
snapshot.
|
|
328
408
|
- `singleState(singleQuery: SingleQuery): Promise<Partial<S>>` - Retrieves a single snapshot state.
|
|
329
409
|
|
|
410
|
+
#### QueryClientFactory
|
|
411
|
+
|
|
412
|
+
Factory for creating pre-configured query clients. Useful when you need multiple clients with shared configuration.
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
import {
|
|
416
|
+
QueryClientFactory,
|
|
417
|
+
ResourceAttributionPathSpec,
|
|
418
|
+
all,
|
|
419
|
+
} from '@ahoo-wang/fetcher-wow';
|
|
420
|
+
import { idGenerator } from '@ahoo-wang/fetcher-cosec';
|
|
421
|
+
|
|
422
|
+
// Create a factory with default options
|
|
423
|
+
const factory = new QueryClientFactory({
|
|
424
|
+
contextAlias: 'example',
|
|
425
|
+
aggregateName: 'cart',
|
|
426
|
+
resourceAttribution: ResourceAttributionPathSpec.OWNER,
|
|
427
|
+
fetcher: exampleFetcher,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// Create a snapshot query client
|
|
431
|
+
const snapshotClient = factory.createSnapshotQueryClient({
|
|
432
|
+
aggregateName: 'cart',
|
|
433
|
+
});
|
|
434
|
+
const carts = await snapshotClient.listState({ condition: all() });
|
|
435
|
+
|
|
436
|
+
// Create a state aggregate client
|
|
437
|
+
const stateClient = factory.createLoadStateAggregateClient({
|
|
438
|
+
aggregateName: 'cart',
|
|
439
|
+
});
|
|
440
|
+
const cart = await stateClient.load('cart-123');
|
|
441
|
+
|
|
442
|
+
// Create an event stream query client
|
|
443
|
+
const eventClient = factory.createEventStreamQueryClient({
|
|
444
|
+
aggregateName: 'cart',
|
|
445
|
+
});
|
|
446
|
+
const events = await eventClient.list({ condition: all() });
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
**Methods:**
|
|
450
|
+
|
|
451
|
+
- `createSnapshotQueryClient(options?: QueryClientOptions): SnapshotQueryClient` - Creates a client for querying snapshots.
|
|
452
|
+
- `createLoadStateAggregateClient(options?: QueryClientOptions): LoadStateAggregateClient` - Creates a client for loading aggregate state by ID.
|
|
453
|
+
- `createOwnerLoadStateAggregateClient(options?: QueryClientOptions): LoadOwnerStateAggregateClient` - Creates a client for loading the current owner's aggregate state.
|
|
454
|
+
- `createEventStreamQueryClient(options?: QueryClientOptions): EventStreamQueryClient` - Creates a client for querying event streams.
|
|
455
|
+
|
|
330
456
|
#### EventStreamQueryClient
|
|
331
457
|
|
|
332
458
|
Client for querying domain event streams with comprehensive query operations:
|
package/README.zh-CN.md
CHANGED
|
@@ -163,11 +163,41 @@ import {
|
|
|
163
163
|
ne,
|
|
164
164
|
gt,
|
|
165
165
|
lt,
|
|
166
|
+
gte,
|
|
167
|
+
lte,
|
|
166
168
|
contains,
|
|
167
169
|
isIn,
|
|
170
|
+
notIn,
|
|
168
171
|
between,
|
|
172
|
+
allIn,
|
|
173
|
+
startsWith,
|
|
174
|
+
endsWith,
|
|
175
|
+
match,
|
|
176
|
+
elemMatch,
|
|
177
|
+
isNull,
|
|
178
|
+
notNull,
|
|
179
|
+
isTrue,
|
|
180
|
+
isFalse,
|
|
181
|
+
exists,
|
|
182
|
+
raw,
|
|
169
183
|
today,
|
|
184
|
+
beforeToday,
|
|
185
|
+
tomorrow,
|
|
186
|
+
thisWeek,
|
|
187
|
+
nextWeek,
|
|
188
|
+
lastWeek,
|
|
189
|
+
thisMonth,
|
|
190
|
+
lastMonth,
|
|
191
|
+
recentDays,
|
|
192
|
+
earlierDays,
|
|
170
193
|
active,
|
|
194
|
+
all,
|
|
195
|
+
id,
|
|
196
|
+
ids,
|
|
197
|
+
aggregateId,
|
|
198
|
+
aggregateIds,
|
|
199
|
+
tenantId,
|
|
200
|
+
ownerId,
|
|
171
201
|
} from '@ahoo-wang/fetcher-wow';
|
|
172
202
|
|
|
173
203
|
// 简单条件
|
|
@@ -176,6 +206,47 @@ const simpleConditions = [
|
|
|
176
206
|
ne('status', 'inactive'),
|
|
177
207
|
gt('age', 18),
|
|
178
208
|
lt('score', 100),
|
|
209
|
+
gte('rating', 4.0),
|
|
210
|
+
lte('price', 100),
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
// 字符串条件
|
|
214
|
+
const stringConditions = [
|
|
215
|
+
contains('email', '@company.com'),
|
|
216
|
+
startsWith('username', 'j'),
|
|
217
|
+
endsWith('domain', '.com'),
|
|
218
|
+
isIn('status', 'active', 'pending'),
|
|
219
|
+
notIn('role', 'guest', 'banned'),
|
|
220
|
+
match('description', 'search keywords'),
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
// 空值检查
|
|
224
|
+
const nullConditions = [
|
|
225
|
+
isNull('deletedAt'),
|
|
226
|
+
notNull('email'),
|
|
227
|
+
isTrue('isActive'),
|
|
228
|
+
isFalse('isDeleted'),
|
|
229
|
+
exists('phoneNumber'),
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
// 数组条件
|
|
233
|
+
const arrayConditions = [
|
|
234
|
+
allIn('tags', 'react', 'typescript'),
|
|
235
|
+
elemMatch('items', eq('quantity', 0)),
|
|
236
|
+
];
|
|
237
|
+
|
|
238
|
+
// 日期条件
|
|
239
|
+
const dateConditions = [
|
|
240
|
+
today('createdAt'),
|
|
241
|
+
beforeToday('lastLogin', 7), // 7天前(即过去7天内)
|
|
242
|
+
tomorrow('scheduledDate'),
|
|
243
|
+
thisWeek('updatedAt'),
|
|
244
|
+
nextWeek('startDate'),
|
|
245
|
+
lastWeek('endDate'),
|
|
246
|
+
thisMonth('createdDate'),
|
|
247
|
+
lastMonth('expirationDate'),
|
|
248
|
+
recentDays('createdAt', 5), // 最近5天,包括今天
|
|
249
|
+
earlierDays('createdAt', 3), // 3天之前
|
|
179
250
|
];
|
|
180
251
|
|
|
181
252
|
// 复杂条件
|
|
@@ -190,15 +261,24 @@ const complexCondition = and(
|
|
|
190
261
|
active(),
|
|
191
262
|
);
|
|
192
263
|
|
|
193
|
-
//
|
|
194
|
-
const
|
|
195
|
-
today('createdAt'),
|
|
196
|
-
beforeToday('lastLogin', 7), // 最近7天内
|
|
197
|
-
thisWeek('updatedAt'),
|
|
198
|
-
lastMonth('createdDate'),
|
|
199
|
-
];
|
|
264
|
+
// 高级用法的原始条件
|
|
265
|
+
const rawCondition = raw({ $text: { $search: 'keywords' } });
|
|
200
266
|
```
|
|
201
267
|
|
|
268
|
+
**操作符参考:**
|
|
269
|
+
|
|
270
|
+
| 类别 | 操作符 |
|
|
271
|
+
|----------|-----------|
|
|
272
|
+
| 逻辑 | `and`, `or`, `nor` |
|
|
273
|
+
| 比较 | `eq`, `ne`, `gt`, `lt`, `gte`, `lte` |
|
|
274
|
+
| 字符串 | `contains`, `startsWith`, `endsWith`, `match` |
|
|
275
|
+
| 集合 | `isIn`, `notIn`, `allIn`, `elemMatch` |
|
|
276
|
+
| 空值/布尔 | `isNull`, `notNull`, `isTrue`, `isFalse`, `exists` |
|
|
277
|
+
| 日期 | `today`, `beforeToday(days)`, `tomorrow`, `thisWeek`, `nextWeek`, `lastWeek`, `thisMonth`, `lastMonth`, `recentDays(days)`, `earlierDays(days)` |
|
|
278
|
+
| ID | `id`, `ids`, `aggregateId`, `aggregateIds`, `tenantId`, `ownerId` |
|
|
279
|
+
| 状态 | `active`, `all`, `deleted` |
|
|
280
|
+
| 特殊 | `raw`(用于高级数据库特定查询)
|
|
281
|
+
|
|
202
282
|
#### SnapshotQueryClient
|
|
203
283
|
|
|
204
284
|
用于查询物化快照的客户端,支持全面的查询操作:
|
|
@@ -316,6 +396,52 @@ const singleState = await cartSnapshotQueryClient.singleState(singleQuery);
|
|
|
316
396
|
- `single(singleQuery: SingleQuery): Promise<Partial<MaterializedSnapshot<S>>>` - 检索单个物化快照。
|
|
317
397
|
- `singleState(singleQuery: SingleQuery): Promise<Partial<S>>` - 检索单个快照状态。
|
|
318
398
|
|
|
399
|
+
#### QueryClientFactory
|
|
400
|
+
|
|
401
|
+
用于创建预配置查询客户端的工厂。当您需要具有共享配置的多个客户端时,这非常有用。
|
|
402
|
+
|
|
403
|
+
```typescript
|
|
404
|
+
import {
|
|
405
|
+
QueryClientFactory,
|
|
406
|
+
ResourceAttributionPathSpec,
|
|
407
|
+
all,
|
|
408
|
+
} from '@ahoo-wang/fetcher-wow';
|
|
409
|
+
import { idGenerator } from '@ahoo-wang/fetcher-cosec';
|
|
410
|
+
|
|
411
|
+
// 使用默认选项创建工厂
|
|
412
|
+
const factory = new QueryClientFactory({
|
|
413
|
+
contextAlias: 'example',
|
|
414
|
+
aggregateName: 'cart',
|
|
415
|
+
resourceAttribution: ResourceAttributionPathSpec.OWNER,
|
|
416
|
+
fetcher: exampleFetcher,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// 创建快照查询客户端
|
|
420
|
+
const snapshotClient = factory.createSnapshotQueryClient({
|
|
421
|
+
aggregateName: 'cart',
|
|
422
|
+
});
|
|
423
|
+
const carts = await snapshotClient.listState({ condition: all() });
|
|
424
|
+
|
|
425
|
+
// 创建状态聚合客户端
|
|
426
|
+
const stateClient = factory.createLoadStateAggregateClient({
|
|
427
|
+
aggregateName: 'cart',
|
|
428
|
+
});
|
|
429
|
+
const cart = await stateClient.load('cart-123');
|
|
430
|
+
|
|
431
|
+
// 创建事件流查询客户端
|
|
432
|
+
const eventClient = factory.createEventStreamQueryClient({
|
|
433
|
+
aggregateName: 'cart',
|
|
434
|
+
});
|
|
435
|
+
const events = await eventClient.list({ condition: all() });
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
**方法:**
|
|
439
|
+
|
|
440
|
+
- `createSnapshotQueryClient(options?: QueryClientOptions): SnapshotQueryClient` - 创建用于查询快照的客户端。
|
|
441
|
+
- `createLoadStateAggregateClient(options?: QueryClientOptions): LoadStateAggregateClient` - 创建用于按 ID 加载聚合状态的客户端。
|
|
442
|
+
- `createOwnerLoadStateAggregateClient(options?: QueryClientOptions): LoadOwnerStateAggregateClient` - 创建用于加载当前所有者聚合状态的客户端。
|
|
443
|
+
- `createEventStreamQueryClient(options?: QueryClientOptions): EventStreamQueryClient` - 创建用于查询事件流的客户端。
|
|
444
|
+
|
|
319
445
|
#### EventStreamQueryClient
|
|
320
446
|
|
|
321
447
|
用于查询领域事件流的客户端,支持全面的查询操作:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahoo-wang/fetcher-wow",
|
|
3
|
-
"version": "3.15.
|
|
3
|
+
"version": "3.15.4",
|
|
4
4
|
"description": "Support for Wow(https://github.com/Ahoo-Wang/Wow) in Fetcher",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fetch",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
"@vitest/coverage-v8": "^4.1.4",
|
|
58
58
|
"@vitest/ui": "^4.1.4",
|
|
59
59
|
"eslint": "^9.39.4",
|
|
60
|
-
"globals": "^17.
|
|
60
|
+
"globals": "^17.5.0",
|
|
61
61
|
"prettier": "^3.8.1",
|
|
62
62
|
"typescript": "^6.0.2",
|
|
63
|
-
"typescript-eslint": "^8.58.
|
|
63
|
+
"typescript-eslint": "^8.58.2",
|
|
64
64
|
"unplugin-dts": "1.0.0-beta.6",
|
|
65
65
|
"vite": "^8.0.8",
|
|
66
66
|
"vite-bundle-analyzer": "^1.3.7",
|