@effect-app/infra 0.12.5 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/_cjs/api/defaultErrorHandler.cjs +8 -8
- package/_cjs/api/defaultErrorHandler.cjs.map +1 -1
- package/_cjs/api/routing.cjs +7 -7
- package/_cjs/api/routing.cjs.map +1 -1
- package/_cjs/filter.cjs.map +1 -1
- package/_cjs/services/Repository.cjs +39 -24
- package/_cjs/services/Repository.cjs.map +1 -1
- package/_cjs/services/Store/Cosmos.cjs +3 -7
- package/_cjs/services/Store/Cosmos.cjs.map +1 -1
- package/_cjs/services/Store/codeFilter.test.cjs.map +1 -1
- package/_cjs/services/Store/utils.cjs +2 -2
- package/_cjs/services/Store/utils.cjs.map +1 -1
- package/_cjs/services/simpledb/simpledb.cjs +9 -9
- package/_cjs/services/simpledb/simpledb.cjs.map +1 -1
- package/_src/api/defaultErrorHandler.ts +3 -5
- package/_src/api/routing.ts +12 -13
- package/_src/filter/types/path/common.ts +9 -9
- package/_src/filter/types/path/eager.ts +12 -12
- package/_src/filter/types/utils.ts +1 -1
- package/_src/filter.ts +7 -11
- package/_src/services/Repository.ts +111 -50
- package/_src/services/Store/Cosmos.ts +14 -14
- package/_src/services/Store/codeFilter.test.ts +37 -30
- package/_src/services/Store/utils.ts +34 -34
- package/_src/services/simpledb/simpledb.ts +5 -6
- package/dist/api/defaultErrorHandler.d.ts.map +1 -1
- package/dist/api/defaultErrorHandler.js +11 -11
- package/dist/api/routing.d.ts.map +1 -1
- package/dist/api/routing.js +9 -9
- package/dist/filter/types/path/common.d.ts.map +1 -1
- package/dist/filter/types/path/eager.d.ts.map +1 -1
- package/dist/filter/types/utils.d.ts.map +1 -1
- package/dist/filter.d.ts.map +1 -1
- package/dist/filter.js +2 -2
- package/dist/services/Repository.d.ts +23 -5
- package/dist/services/Repository.d.ts.map +1 -1
- package/dist/services/Repository.js +41 -25
- package/dist/services/Store/Cosmos.js +8 -10
- package/dist/services/Store/codeFilter.test.d.ts.map +1 -1
- package/dist/services/Store/utils.d.ts.map +1 -1
- package/dist/services/Store/utils.js +30 -30
- package/dist/services/simpledb/simpledb.d.ts.map +1 -1
- package/dist/services/simpledb/simpledb.js +9 -9
- package/package.json +4 -4
- package/.jest-cache/haste-map-369fa5ca2164cc35b19159bd76147276-e7a7ff05756c055cb63be97ba8537525-314902b6271c341511f7398a50469024 +0 -0
- package/.jest-cache/haste-map-369fa5ca2164cc35b19159bd76147276-e7a7ff05756c055cb63be97ba8537525-3f072cc7afa09b6adaead0527ab9df83 +0 -0
- package/.jest-cache/haste-map-369fa5ca2164cc35b19159bd76147276-e7a7ff05756c055cb63be97ba8537525-74c3c295c110fc861b6a4c673afc3e24 +0 -0
- package/.jest-cache/haste-map-369fa5ca2164cc35b19159bd76147276-e7a7ff05756c055cb63be97ba8537525-bf6dae8cb9ea9740ceb39aefaf12716c +0 -0
- package/.jest-cache/haste-map-369fa5ca2164cc35b19159bd76147276-e7a7ff05756c055cb63be97ba8537525-cf9d1486029526079a5f68f2041dea02 +0 -0
- package/.jest-cache/haste-map-4ca41cc04e60c616a19cbb483cbf487b-e2f1f4b6d87214e3c49442fed31f310c-b4710ed9fb3d0757c4bf23045c585670 +0 -0
- package/.jest-cache/haste-map-4ca41cc04e60c616a19cbb483cbf487b-e2f1f4b6d87214e3c49442fed31f310c-ee17e5395bb1b7b36a4e2e22a6ae1449 +0 -0
- package/.jest-cache/haste-map-7dc16d7fae8c072843ed1c69eae73100-a8a4225b317477b49bca31f54559afb3-c16136699bb7f463be85273162b447c3 +0 -0
- package/.jest-cache/haste-map-9aa1e395a82e108eb49698982c574272-e2f1f4b6d87214e3c49442fed31f310c-f7435f46fc41ac5a13d06a49cae9a650 +0 -0
- package/.jest-cache/haste-map-9d206b45d610536c9ec65eec263c6964-a8a4225b317477b49bca31f54559afb3-3510506a330b44f1ae629033aac8fbb3 +0 -0
- package/.jest-cache/haste-map-a00ab30d0d656f9d3990958a54b9ccfd-87603b0fc921b26b622a5859b4c92bed-17b550b450b18840c25861aa6e835f0c +0 -0
- package/.jest-cache/haste-map-a00ab30d0d656f9d3990958a54b9ccfd-87603b0fc921b26b622a5859b4c92bed-4dc31290b1efc98335eb4c89167d75c3 +0 -0
- package/.jest-cache/haste-map-ab843cb0ffbadfd0deea4adb182c7ecd-87603b0fc921b26b622a5859b4c92bed-997106edf4bbc31567a378146180e45e +0 -0
- package/.jest-cache/haste-map-ab843cb0ffbadfd0deea4adb182c7ecd-87603b0fc921b26b622a5859b4c92bed-f0cd25414f9ed16c446940ca3aa23c1b +0 -0
- package/.jest-cache/haste-map-cf17f2edf0e949eebfdfca561816457c-e7a7ff05756c055cb63be97ba8537525-2cac07d09e6384e2d37c49714edad0ba +0 -0
- package/.jest-cache/haste-map-cf17f2edf0e949eebfdfca561816457c-e7a7ff05756c055cb63be97ba8537525-d7967c2976c5feac7161c964f0aa442f +0 -0
- package/.jest-cache/haste-map-fb1a173276d25bbff02f815600059283-938122bdc1c8836874b6585d7acb2e99-f705929cca05ce95ceaa6d520b560ce8 +0 -0
|
@@ -44,34 +44,34 @@ const RecordCache = tsplus_module_2.Tag();
|
|
|
44
44
|
exports.RecordCache = RecordCache;
|
|
45
45
|
const LiveRecordCache = tsplus_module_3.toLayer(tracer_1.withCallTrace(fileName_1 + ":31:32")(tsplus_module_1.sync(() => makeLiveRecordCache())), RecordCache);
|
|
46
46
|
exports.LiveRecordCache = LiveRecordCache;
|
|
47
|
-
const getM = type => eff => tracer_1.withCallTrace(fileName_1 + ":
|
|
47
|
+
const getM = type => eff => tracer_1.withCallTrace(fileName_1 + ":34:10")(tsplus_module_1.gen(function* ($) {
|
|
48
48
|
const {
|
|
49
49
|
get
|
|
50
50
|
} = yield* $(tsplus_module_1.service(RecordCache));
|
|
51
|
-
return yield* $(tracer_1.withCallTrace(fileName_1 + ":
|
|
51
|
+
return yield* $(tracer_1.withCallTrace(fileName_1 + ":36:34")(tsplus_module_1.flatMap(eff))(get(type)));
|
|
52
52
|
}));
|
|
53
53
|
function find(tryRead, decode, type) {
|
|
54
54
|
const getCache = getM(type);
|
|
55
|
-
const read = id => tracer_1.withCallTrace(fileName_1 + ":
|
|
55
|
+
const read = id => tracer_1.withCallTrace(fileName_1 + ":54:8")(tsplus_module_3.mapOpt(tracer_1.withCallTrace(fileName_1 + ":53:8")(tsplus_module_3.tapOpt(tracer_1.withCallTrace(fileName_1 + ":47:8")(tsplus_module_3.flatMapOpt(tryRead(id), ({
|
|
56
56
|
data,
|
|
57
57
|
version
|
|
58
|
-
}) => tracer_1.withCallTrace(fileName_1 + ":
|
|
58
|
+
}) => tracer_1.withCallTrace(fileName_1 + ":48:22")(tsplus_module_1.mapBoth(err => new InvalidStateError("DB serialisation Issue", err), data => ({
|
|
59
59
|
data,
|
|
60
60
|
version
|
|
61
61
|
})))(decode(data)))), r => getCache(c => c.set(id, r)))), r => r.data));
|
|
62
|
-
return id => getCache(c => tracer_1.withCallTrace(fileName_1 + ":
|
|
62
|
+
return id => getCache(c => tracer_1.withCallTrace(fileName_1 + ":61:10")(tsplus_module_1.orElse(() => read(id)))(tracer_1.withCallTrace(fileName_1 + ":60:10")(tsplus_module_3.mapOpt(c.find(id), existing => existing.data))));
|
|
63
63
|
}
|
|
64
64
|
function storeDirectly(save, type) {
|
|
65
65
|
const getCache = getM(type);
|
|
66
|
-
return record => getCache(c => tracer_1.withCallTrace(fileName_1 + ":
|
|
66
|
+
return record => getCache(c => tracer_1.withCallTrace(fileName_1 + ":77:10")(tsplus_module_1.map(r => r.data))(tracer_1.withCallTrace(fileName_1 + ":76:10")(tsplus_module_1.tap(r => c.set(record.id, r)))(tracer_1.withCallTrace(fileName_1 + ":75:10")(tsplus_module_1.flatMap(cv => save(record, cv)))(tracer_1.withCallTrace(fileName_1 + ":74:10")(tsplus_module_3.mapOpt(c.find(record.id), x => x.version))))));
|
|
67
67
|
}
|
|
68
68
|
function store(tryRead, save, lock, type) {
|
|
69
69
|
const getCache = getM(type);
|
|
70
|
-
return record => getCache(c => tracer_1.withCallTrace(fileName_1 + ":
|
|
70
|
+
return record => getCache(c => tracer_1.withCallTrace(fileName_1 + ":95:10")(tsplus_module_1.map(r => r.data))(tracer_1.withCallTrace(fileName_1 + ":94:10")(tsplus_module_1.tap(r => c.set(record.id, r)))(tracer_1.withCallTrace(fileName_1 + ":93:10")(tsplus_module_1.flatMap(_ => tsplus_module_4.match(() => save(record, tsplus_module_4.none), confirmVersionAndSave(record))(_)))(tracer_1.withCallTrace(fileName_1 + ":92:10")(tsplus_module_3.mapOpt(c.find(record.id), x => x.version))))));
|
|
71
71
|
function confirmVersionAndSave(record) {
|
|
72
|
-
return cv => tsplus_module_1.scoped(tracer_1.withCallTrace(fileName_1 + ":
|
|
72
|
+
return cv => tsplus_module_1.scoped(tracer_1.withCallTrace(fileName_1 + ":100:23")(tsplus_module_1.zipRight(tracer_1.withCallTrace(fileName_1 + ":113:12")(tsplus_module_1.zipRight(save(record, tsplus_module_4.some(cv))))(tracer_1.withCallTrace(fileName_1 + ":108:12")(tsplus_module_1.tap(({
|
|
73
73
|
version
|
|
74
|
-
}) => version !== cv ? tracer_1.withCallTrace(fileName_1 + ":
|
|
74
|
+
}) => version !== cv ? tracer_1.withCallTrace(fileName_1 + ":110:24")(tsplus_module_1.fail(new _shared.OptimisticLockException(type, record.id))) : tsplus_module_3.unit))(tracer_1.withCallTrace(fileName_1 + ":102:12")(tsplus_module_1.flatMap(_ => tsplus_module_4.match(() => tracer_1.withCallTrace(fileName_1 + ":104:28")(tsplus_module_1.fail(new InvalidStateError("record is gone"))), tsplus_module_1.succeed)(_)))(tryRead(record.id))))))(lock(record.id)));
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
//# sourceMappingURL=simpledb.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpledb.cjs","mappings":";;;;;;;;;;;;;;;AACA;AAA8D;AAAA;;AAGxD,MAAOA,iBA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,EAAE,CAAC,CAAC,GAZjC3B,mEAOO,CAAC;MAAEmB;IAAO,CAAE,KACfA,OAAO,KAAKQ,EAAE,GACX3B,+CAACC,qBAAY,IAAIiC,+BAAuB,CAACnC,IAAI,EAAE2B,MAAM,CAACT,EAAE,CAAC,CAAC,IAC1DT,oBAAY,GAVnBR,uEACW+B,CAAC,IACRC,sBACE,MAAKhC,+CAACC,qBAAY,IAAIV,iBAAiB,CAAC,gBAAgB,CAAC,CAAC,4BAD5DwC,CAAC,CAGA,GALLlB,OAAO,CAACa,MAAM,CAACT,EAAE,CAAC,CAMf,CAKA,CAC+B,GAbpCa,IAAI,CAACJ,MAAM,CAACT,EAAE,CAAC,CAcd,CAAO;EACZ;AACF","names":["InvalidStateError","constructor","message","details","makeLiveRecordCache","m","Map","get","type","tracer_1","tsplus_module_1","ex","nm","set","RecordCache","tsplus_module_2","LiveRecordCache","tsplus_module_3","getM","eff","$","find","tryRead","decode","getCache","read","id","data","version","err","r","c","existing","storeDirectly","save","record","cv","x","store","lock","_","tsplus_module_4","confirmVersionAndSave","OptimisticLockException"],"sourceRoot":"","sources":["../../../_src/services/simpledb/simpledb.ts"],"sourcesContent":[null]}
|
|
@@ -41,11 +41,9 @@ export function defaultErrorHandler<R>(
|
|
|
41
41
|
_: RequestContext,
|
|
42
42
|
r2: Effect<R, SupportedErrors, void>
|
|
43
43
|
) {
|
|
44
|
-
const r3 =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
: r2
|
|
48
|
-
)
|
|
44
|
+
const r3 = req.method === "PATCH"
|
|
45
|
+
? r2.retry(optimisticConcurrencySchedule)
|
|
46
|
+
: r2
|
|
49
47
|
return r3
|
|
50
48
|
.tapErrorCause(cause => cause.isFailure() ? logRequestError(cause) : Effect.unit)
|
|
51
49
|
.catchTag("ValidationError", err =>
|
package/_src/api/routing.ts
CHANGED
|
@@ -338,14 +338,12 @@ export function makeRequestHandler<
|
|
|
338
338
|
.flatMap(r => respond(parsedReq, res, r))
|
|
339
339
|
)
|
|
340
340
|
// Commands should not be interruptable.
|
|
341
|
-
const r = (
|
|
342
|
-
req.method !== "GET" ? handleRequest.uninterruptible : handleRequest
|
|
343
|
-
) // .instrument("Performance.RequestResponse")
|
|
341
|
+
const r = req.method !== "GET" ? handleRequest.uninterruptible : handleRequest // .instrument("Performance.RequestResponse")
|
|
344
342
|
// the first log entry should be of the request start.
|
|
345
343
|
const r2 = makeMiddlewareContext
|
|
346
344
|
? r.provideSomeContextEffect(makeMiddlewareContext(req, res, requestContext))
|
|
347
|
-
|
|
348
|
-
|
|
345
|
+
// PR is not relevant here
|
|
346
|
+
: r as Effect<R, E | ValidationError, void>
|
|
349
347
|
return errorHandler(
|
|
350
348
|
req,
|
|
351
349
|
res,
|
|
@@ -484,11 +482,11 @@ export type RouteAllTest<T extends RequestHandlersTest> = {
|
|
|
484
482
|
export type Flatten<T extends object> = object extends T ? object : {
|
|
485
483
|
[K in keyof T]-?: (
|
|
486
484
|
x: NonNullable<T[K]> extends infer V ? V extends object ? V extends readonly any[] ? Pick<T, K>
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
485
|
+
: FlattenLVL1<V> extends infer FV ? ({
|
|
486
|
+
[P in keyof FV as `${Extract<K, string | number>}.${Extract<P, string | number>}`]: FV[P]
|
|
487
|
+
})
|
|
488
|
+
: never
|
|
489
|
+
: Pick<T, K>
|
|
492
490
|
: never
|
|
493
491
|
) => void
|
|
494
492
|
} extends Record<keyof T, (y: infer O) => void> ? O extends unknown /* infer U */ ? { [K in keyof O]: O[K] } : never
|
|
@@ -497,12 +495,13 @@ export type Flatten<T extends object> = object extends T ? object : {
|
|
|
497
495
|
type FlattenLVL1<T extends object> = object extends T ? object : {
|
|
498
496
|
[K in keyof T]-?: (
|
|
499
497
|
x: NonNullable<T[K]> extends infer V ? V extends object ? V extends readonly any[] ? Pick<T, K>
|
|
500
|
-
|
|
498
|
+
/*: Flatten<V> extends infer FV ? ({
|
|
501
499
|
[P in keyof FV as `${Extract<K, string | number>}.${Extract<P, string | number>}`]: FV[P]
|
|
502
500
|
})
|
|
503
501
|
: never
|
|
504
|
-
*/
|
|
505
|
-
|
|
502
|
+
*/
|
|
503
|
+
: Pick<T, K>
|
|
504
|
+
: never
|
|
506
505
|
: never
|
|
507
506
|
) => void
|
|
508
507
|
} extends Record<keyof T, (y: infer O) => void> ? O extends unknown /* infer U */ ? { [K in keyof O]: O[K] } : never
|
|
@@ -199,7 +199,7 @@ type TryAccessArray<
|
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
201
201
|
export type EvaluateKey<T, K extends Key> = T extends ReadonlyArray<any> ? IsTuple<T> extends true ? TryAccess<T, K>
|
|
202
|
-
: TryAccessArray<T, K>
|
|
202
|
+
: TryAccessArray<T, K>
|
|
203
203
|
: TryAccess<MapKeys<T>, K>
|
|
204
204
|
|
|
205
205
|
/**
|
|
@@ -259,7 +259,7 @@ type NumericObjectKeys<T extends Traversable> = ToKey<
|
|
|
259
259
|
*/
|
|
260
260
|
export type NumericKeys<T extends Traversable> = UnionToIntersection<
|
|
261
261
|
T extends ReadonlyArray<any> ? IsTuple<T> extends true ? [TupleKeys<T>]
|
|
262
|
-
|
|
262
|
+
: [ToKey<ArrayKey>]
|
|
263
263
|
: [NumericObjectKeys<T>]
|
|
264
264
|
>[never]
|
|
265
265
|
|
|
@@ -292,7 +292,7 @@ export type ObjectKeys<T extends Traversable> = Exclude<
|
|
|
292
292
|
* ```
|
|
293
293
|
*/
|
|
294
294
|
export type CheckKeyConstraint<T, K extends Key, U> = K extends any ? EvaluateKey<T, K> extends U ? K
|
|
295
|
-
: never
|
|
295
|
+
: never
|
|
296
296
|
: never
|
|
297
297
|
|
|
298
298
|
/**
|
|
@@ -315,7 +315,7 @@ export type ContainsIndexable<T> = IsNever<
|
|
|
315
315
|
* @typeParam T - non-nullable type whose property should be checked
|
|
316
316
|
*/
|
|
317
317
|
type KeysImpl<T> = [T] extends [Traversable] ? ContainsIndexable<T> extends true ? NumericKeys<T>
|
|
318
|
-
: ObjectKeys<T>
|
|
318
|
+
: ObjectKeys<T>
|
|
319
319
|
: never
|
|
320
320
|
|
|
321
321
|
/**
|
|
@@ -366,11 +366,11 @@ type ValidPathPrefixImpl<
|
|
|
366
366
|
PT extends PathTuple,
|
|
367
367
|
VPT extends PathTuple
|
|
368
368
|
> = PT extends [infer K, ...infer R] ? HasKey<T, AsKey<K>> extends true ? ValidPathPrefixImpl<
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
>
|
|
373
|
-
: VPT
|
|
369
|
+
EvaluateKey<T, AsKey<K>>,
|
|
370
|
+
AsPathTuple<R>,
|
|
371
|
+
AsPathTuple<[...VPT, K]>
|
|
372
|
+
>
|
|
373
|
+
: VPT
|
|
374
374
|
: VPT
|
|
375
375
|
|
|
376
376
|
/**
|
|
@@ -22,9 +22,9 @@ type PathImpl<K extends string | number, V> = V extends
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export type Path<T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
|
|
25
|
-
|
|
26
|
-
}[TupleKeys<T>]
|
|
27
|
-
: PathImpl<ArrayKey, V>
|
|
25
|
+
[K in TupleKeys<T>]-?: PathImpl<K & string, T[K]>
|
|
26
|
+
}[TupleKeys<T>]
|
|
27
|
+
: PathImpl<ArrayKey, V>
|
|
28
28
|
: {
|
|
29
29
|
[K in keyof T]-?: PathImpl<K & string, T[K]>
|
|
30
30
|
}[keyof T]
|
|
@@ -42,7 +42,7 @@ type ArrayPathImpl<K extends string | number, V> = V extends
|
|
|
42
42
|
| Primitive
|
|
43
43
|
| BrowserNativeObject ? never
|
|
44
44
|
: V extends ReadonlyArray<infer U> ? U extends Primitive | BrowserNativeObject ? never
|
|
45
|
-
|
|
45
|
+
: `${K}` | `${K}.${ArrayPath<V>}`
|
|
46
46
|
: `${K}.${ArrayPath<V>}`
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -55,9 +55,9 @@ type ArrayPathImpl<K extends string | number, V> = V extends
|
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
57
|
export type ArrayPath<T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
|
|
58
|
-
|
|
59
|
-
}[TupleKeys<T>]
|
|
60
|
-
: ArrayPathImpl<ArrayKey, V>
|
|
58
|
+
[K in TupleKeys<T>]-?: ArrayPathImpl<K & string, T[K]>
|
|
59
|
+
}[TupleKeys<T>]
|
|
60
|
+
: ArrayPathImpl<ArrayKey, V>
|
|
61
61
|
: {
|
|
62
62
|
[K in keyof T]-?: ArrayPathImpl<K & string, T[K]>
|
|
63
63
|
}[keyof T]
|
|
@@ -79,13 +79,13 @@ export type FieldArrayPath<TFieldValues extends FieldValues> = ArrayPath<TFieldV
|
|
|
79
79
|
*/
|
|
80
80
|
export type PathValue<T, P extends Path<T> | ArrayPath<T>> = T extends any
|
|
81
81
|
? P extends `${infer K}.${infer R}` ? K extends keyof T ? R extends Path<T[K]> ? PathValue<T[K], R>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
: never
|
|
83
|
+
: K extends `${ArrayKey}` ? T extends ReadonlyArray<infer V> ? PathValue<V, R & Path<V>>
|
|
84
|
+
: never
|
|
85
|
+
: never
|
|
86
86
|
: P extends keyof T ? T[P]
|
|
87
87
|
: P extends `${ArrayKey}` ? T extends ReadonlyArray<infer V> ? V
|
|
88
|
-
|
|
88
|
+
: never
|
|
89
89
|
: never
|
|
90
90
|
: never
|
|
91
91
|
|
|
@@ -99,7 +99,7 @@ export type IsFlatObject<T extends object> = Extract<
|
|
|
99
99
|
|
|
100
100
|
export type Merge<A, B> = {
|
|
101
101
|
[K in keyof A | keyof B]?: K extends keyof A & keyof B ? [A[K], B[K]] extends [object, object] ? Merge<A[K], B[K]>
|
|
102
|
-
|
|
102
|
+
: A[K] | B[K]
|
|
103
103
|
: K extends keyof A ? A[K]
|
|
104
104
|
: K extends keyof B ? B[K]
|
|
105
105
|
: never
|
package/_src/filter.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { Where } from "./services/Store.js"
|
|
2
1
|
import type { FieldValues } from "./filter/types/fields.js"
|
|
3
2
|
import type { FieldPath, FieldPathValue } from "./filter/types/path/eager.js"
|
|
3
|
+
import type { Where } from "./services/Store.js"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* the function defaults to "eq", but has additional properties for notEq, in and notIn
|
|
7
7
|
*/
|
|
8
|
-
export interface WhereFilter<TFieldValues extends FieldValues>
|
|
8
|
+
export interface WhereFilter<TFieldValues extends FieldValues>
|
|
9
|
+
extends ReturnType<typeof makeWhereFilter_<TFieldValues>>
|
|
10
|
+
{}
|
|
9
11
|
export function makeWhereFilter<TFieldValues extends FieldValues>() {
|
|
10
12
|
const f = makeWhereFilter_<TFieldValues>()
|
|
11
13
|
return f as WhereFilter<TFieldValues>
|
|
@@ -60,8 +62,6 @@ function makeWhereFilter_<TFieldValues extends FieldValues>() {
|
|
|
60
62
|
return f
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
65
|
export type WhereValue<
|
|
66
66
|
T extends "eq" | "not-eq" | "starts-with" | "ends-with" | "includes" | "contains" | "not-contains",
|
|
67
67
|
A, // extends SupportedValues,
|
|
@@ -145,9 +145,8 @@ function $isnt__<V extends A, A>(v: V) {
|
|
|
145
145
|
return (_: A) => $isnt(_, v)
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
149
148
|
function $in__<A extends SupportedValues, Values extends readonly A[]>(
|
|
150
|
-
...v: Values
|
|
149
|
+
...v: Values
|
|
151
150
|
) {
|
|
152
151
|
return (_: A) => $in(_, ...v)
|
|
153
152
|
}
|
|
@@ -174,7 +173,7 @@ export const Filters = {
|
|
|
174
173
|
$is: $is__,
|
|
175
174
|
$isnt: $isnt__,
|
|
176
175
|
$in: $in__,
|
|
177
|
-
$notIn: $notIn__
|
|
176
|
+
$notIn: $notIn__
|
|
178
177
|
// $contains: $contains__,
|
|
179
178
|
// $notContains: $notContains__,
|
|
180
179
|
}
|
|
@@ -242,7 +241,7 @@ type VType<T> = T extends ValueType<any> ? T["v"] : never
|
|
|
242
241
|
function f(p: string, b: any) {
|
|
243
242
|
if (typeof b === "function") b = b(undefined)
|
|
244
243
|
const obj = typeof b === "object" && b !== null
|
|
245
|
-
return makeFilter(p, obj ? b.v : b, obj ? b.t ?? "eq" : "eq")
|
|
244
|
+
return makeFilter(p, obj ? b.v : b, obj ? b.t ?? "eq" : "eq")
|
|
246
245
|
}
|
|
247
246
|
|
|
248
247
|
function makeFilter<T extends "in" | "not-in" | "eq" | "not-eq">(path: string, value: any, t: T) {
|
|
@@ -256,7 +255,6 @@ type FIL<S, K extends string, T extends "in" | "not-in" | "eq" | "not-eq", V> =
|
|
|
256
255
|
readonly S: S
|
|
257
256
|
}
|
|
258
257
|
|
|
259
|
-
|
|
260
258
|
export function makeFilters<T extends FieldValues>() {
|
|
261
259
|
type Paths = FieldPath<T>
|
|
262
260
|
type Value<TFieldName extends Paths> = FieldPathValue<T, TFieldName>
|
|
@@ -282,8 +280,6 @@ export function makeFilters<T extends FieldValues>() {
|
|
|
282
280
|
return test
|
|
283
281
|
}
|
|
284
282
|
|
|
285
|
-
|
|
286
|
-
|
|
287
283
|
// export function makeFilter<TFieldValues extends FieldValues>() {
|
|
288
284
|
// const f = makeFilter_<TFieldValues>()
|
|
289
285
|
// return f as WhereFilterHelper<TFieldValues>
|