effect-app 4.0.0-beta.281 → 4.0.0-beta.283
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 +32 -0
- package/dist/DataDependencies.d.ts +159 -0
- package/dist/DataDependencies.d.ts.map +1 -0
- package/dist/DataDependencies.js +44 -0
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -1
- package/dist/Model/Repository/internal/internal.js +16 -8
- package/dist/Model/query/new-kid-interpreter.js +2 -2
- package/dist/QueueMaker.d.ts +8 -10
- package/dist/QueueMaker.d.ts.map +1 -1
- package/dist/QueueMaker.js +9 -2
- package/dist/Schema/Class.d.ts +1 -1
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +2 -2
- package/dist/Schema/ext.d.ts +1 -1
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/moreStrings.d.ts +1 -1
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/numbers.d.ts +1 -1
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/schema.d.ts +1 -1
- package/dist/Schema/schema.d.ts.map +1 -1
- package/dist/Schema/schema.js +2 -2
- package/dist/Schema/strings.d.ts +1 -1
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema.d.ts +14 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +3 -2
- package/dist/SchemaAST.d.ts +23 -0
- package/dist/SchemaAST.d.ts.map +1 -0
- package/dist/SchemaAST.js +25 -0
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +44 -7
- package/dist/client/makeClient.d.ts +19 -23
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +3 -10
- package/dist/client.d.ts +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/rpc/Invalidation.d.ts +994 -2
- package/dist/rpc/Invalidation.d.ts.map +1 -1
- package/dist/rpc/Invalidation.js +10 -3
- package/package.json +2 -2
- package/src/DataDependencies.ts +78 -0
- package/src/Model/Repository/internal/internal.ts +15 -1
- package/src/Model/query/new-kid-interpreter.ts +1 -1
- package/src/QueueMaker.ts +8 -16
- package/src/Schema/Class.ts +1 -1
- package/src/Schema/ext.ts +1 -1
- package/src/Schema/moreStrings.ts +1 -1
- package/src/Schema/numbers.ts +1 -1
- package/src/Schema/schema.ts +1 -1
- package/src/Schema/strings.ts +1 -1
- package/src/Schema.ts +14 -1
- package/src/SchemaAST.ts +29 -0
- package/src/client/apiClientFactory.ts +64 -16
- package/src/client/makeClient.ts +12 -22
- package/src/client.ts +1 -0
- package/src/rpc/Invalidation.ts +16 -2
- package/test/dist/rpc.test.d.ts.map +1 -1
- package/test/rpc.test.ts +7 -8
package/src/client/makeClient.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type * as Exit from "effect/Exit"
|
|
2
|
-
import * as SchemaTransformation from "effect/SchemaTransformation"
|
|
3
2
|
import { type GetContextConfig, type RpcContextMap } from "../rpc/RpcContextMap.ts"
|
|
4
3
|
import * as S from "../Schema.ts"
|
|
5
4
|
import { AST } from "../Schema.ts"
|
|
@@ -20,15 +19,6 @@ export interface ClientMiddleware<RequestContextMap extends Record<string, RpcCo
|
|
|
20
19
|
const merge = (a: any, b: Array<any>) =>
|
|
21
20
|
a !== undefined && b.length ? S.Union([a, ...b]) : a !== undefined ? a : b.length ? S.Union(b) : S.Never
|
|
22
21
|
|
|
23
|
-
/**
|
|
24
|
-
* Whatever the input, we will only decode or encode to void
|
|
25
|
-
*/
|
|
26
|
-
export const ForceVoid = S
|
|
27
|
-
.declare((_: unknown): _ is unknown => true)
|
|
28
|
-
.pipe(
|
|
29
|
-
S.decodeTo(S.Any, SchemaTransformation.transform<unknown, unknown>({ decode: () => void 0, encode: () => void 0 }))
|
|
30
|
-
)
|
|
31
|
-
|
|
32
22
|
type SchemaOrFields<T> = T extends S.Top ? T : T extends S.Struct.Fields ? S.Struct<T> : S.Void
|
|
33
23
|
|
|
34
24
|
type TaggedRequestSchema<Tag extends string, Payload extends S.Struct.Fields> = S.Struct<
|
|
@@ -46,7 +36,7 @@ type QueryOnlyResources<Resources> = {
|
|
|
46
36
|
type InputFromPayload<Payload extends S.Struct.Fields> = keyof Payload extends never ? void
|
|
47
37
|
: S.Struct<Payload>["Type"]
|
|
48
38
|
|
|
49
|
-
type OutputFromSuccess<Success extends S.Top> = Success extends typeof
|
|
39
|
+
type OutputFromSuccess<Success extends S.Top> = Success extends typeof S.Void ? void : Success["Type"]
|
|
50
40
|
|
|
51
41
|
type InvalidationResources = Record<string, Record<string, unknown>>
|
|
52
42
|
|
|
@@ -176,9 +166,9 @@ export const makeRpcClient = <
|
|
|
176
166
|
)
|
|
177
167
|
const successSchema = config?.success
|
|
178
168
|
? S.isSchema(config.success)
|
|
179
|
-
? AST.isVoid(config.success.ast) ?
|
|
169
|
+
? AST.isVoid(config.success.ast) ? S.Void : config.success
|
|
180
170
|
: S.Struct(config.success)
|
|
181
|
-
:
|
|
171
|
+
: S.Void
|
|
182
172
|
|
|
183
173
|
const finalConfig = (config as any)?.final
|
|
184
174
|
const finalSchema = finalConfig && S.isSchema(finalConfig) ? finalConfig : undefined
|
|
@@ -327,7 +317,7 @@ export const makeRpcClient = <
|
|
|
327
317
|
Self,
|
|
328
318
|
Tag,
|
|
329
319
|
Payload,
|
|
330
|
-
typeof
|
|
320
|
+
typeof S.Void,
|
|
331
321
|
ErrorResult<C & { error: Error }>,
|
|
332
322
|
Omit<
|
|
333
323
|
& Omit<C, "invalidatesQueries">
|
|
@@ -336,7 +326,7 @@ export const makeRpcClient = <
|
|
|
336
326
|
InvalidationConfigForCommand<
|
|
337
327
|
Resources,
|
|
338
328
|
Payload,
|
|
339
|
-
typeof
|
|
329
|
+
typeof S.Void,
|
|
340
330
|
ErrorResult<C & { error: Error }>
|
|
341
331
|
>
|
|
342
332
|
>,
|
|
@@ -372,11 +362,11 @@ export const makeRpcClient = <
|
|
|
372
362
|
Self,
|
|
373
363
|
Tag,
|
|
374
364
|
Payload,
|
|
375
|
-
typeof
|
|
365
|
+
typeof S.Void,
|
|
376
366
|
ErrorResult<C>,
|
|
377
367
|
Omit<
|
|
378
368
|
& Omit<C, "invalidatesQueries">
|
|
379
|
-
& Partial<InvalidationConfigForCommand<Resources, Payload, typeof
|
|
369
|
+
& Partial<InvalidationConfigForCommand<Resources, Payload, typeof S.Void, ErrorResult<C>>>,
|
|
380
370
|
"success" | "error" | "stream"
|
|
381
371
|
>,
|
|
382
372
|
ModuleName,
|
|
@@ -507,7 +497,7 @@ export const makeRpcClient = <
|
|
|
507
497
|
Self,
|
|
508
498
|
Tag,
|
|
509
499
|
Payload,
|
|
510
|
-
typeof
|
|
500
|
+
typeof S.Void,
|
|
511
501
|
ErrorResult<C & { error: Error }>,
|
|
512
502
|
Omit<
|
|
513
503
|
& Omit<C, "invalidatesQueries">
|
|
@@ -518,7 +508,7 @@ export const makeRpcClient = <
|
|
|
518
508
|
InvalidationConfigForCommand<
|
|
519
509
|
Resources,
|
|
520
510
|
Payload,
|
|
521
|
-
typeof
|
|
511
|
+
typeof S.Void,
|
|
522
512
|
ErrorResult<C & { error: Error }>
|
|
523
513
|
>
|
|
524
514
|
>,
|
|
@@ -549,11 +539,11 @@ export const makeRpcClient = <
|
|
|
549
539
|
Self,
|
|
550
540
|
Tag,
|
|
551
541
|
Payload,
|
|
552
|
-
typeof
|
|
542
|
+
typeof S.Void,
|
|
553
543
|
ErrorResult<C>,
|
|
554
544
|
Omit<
|
|
555
545
|
& Omit<C, "invalidatesQueries">
|
|
556
|
-
& Partial<InvalidationConfigForCommand<Resources, Payload, typeof
|
|
546
|
+
& Partial<InvalidationConfigForCommand<Resources, Payload, typeof S.Void, ErrorResult<C>>>,
|
|
557
547
|
"success" | "error" | "stream"
|
|
558
548
|
>,
|
|
559
549
|
ModuleName,
|
|
@@ -570,7 +560,7 @@ export const makeRpcClient = <
|
|
|
570
560
|
Self,
|
|
571
561
|
Tag,
|
|
572
562
|
Payload,
|
|
573
|
-
typeof
|
|
563
|
+
typeof S.Void,
|
|
574
564
|
ErrorResult<{}>,
|
|
575
565
|
Record<string, never>,
|
|
576
566
|
ModuleName,
|
package/src/client.ts
CHANGED
package/src/rpc/Invalidation.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as Ref from "effect/Ref"
|
|
|
2
2
|
import { Rpc } from "effect/unstable/rpc"
|
|
3
3
|
import { type ClientForOptions, makeQueryKey } from "../client/clientFor.ts"
|
|
4
4
|
import * as Context from "../Context.ts"
|
|
5
|
+
import * as DataDependencies from "../DataDependencies.ts"
|
|
5
6
|
import * as Effect from "../Effect.ts"
|
|
6
7
|
import * as S from "../Schema.ts"
|
|
7
8
|
|
|
@@ -23,7 +24,7 @@ const normalizeKey = (input: InvalidationKeyInput): InvalidationKey => {
|
|
|
23
24
|
const isBatch = (
|
|
24
25
|
input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>
|
|
25
26
|
): input is ReadonlyArray<InvalidationKeyInput> =>
|
|
26
|
-
Array.isArray(input) && input
|
|
27
|
+
Array.isArray(input) && input[0] !== undefined && typeof input[0] !== "string"
|
|
27
28
|
|
|
28
29
|
const normalizeInputs = (
|
|
29
30
|
input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>
|
|
@@ -46,9 +47,22 @@ export const InvalidationKeys = S.Array(InvalidationKey)
|
|
|
46
47
|
export type InvalidationKeys = S.Schema.Type<typeof InvalidationKeys>
|
|
47
48
|
|
|
48
49
|
/** Metadata included in every command response for server-driven cache invalidation. */
|
|
49
|
-
export const CommandMetaData = S.Struct({
|
|
50
|
+
export const CommandMetaData = S.Struct({
|
|
51
|
+
invalidateQueries: InvalidationKeys,
|
|
52
|
+
dataDependencies: DataDependencies.DataDependencySet
|
|
53
|
+
})
|
|
50
54
|
export type CommandMetaData = S.Schema.Type<typeof CommandMetaData>
|
|
51
55
|
|
|
56
|
+
export const emptyDataDependencies: DataDependencies.DataDependencySet = { reads: [], writes: [] }
|
|
57
|
+
|
|
58
|
+
export const makeMetaData = (
|
|
59
|
+
invalidateQueries: InvalidationKeys,
|
|
60
|
+
dataDependencies: DataDependencies.DataDependencySet = emptyDataDependencies
|
|
61
|
+
): CommandMetaData => ({ invalidateQueries, dataDependencies })
|
|
62
|
+
|
|
63
|
+
export const QueryResponseWithMetaData = <S extends S.Top>(success: S) =>
|
|
64
|
+
S.Struct({ payload: success, metadata: S.Struct({ dataDependencies: DataDependencies.DataDependencySet }) })
|
|
65
|
+
|
|
52
66
|
/**
|
|
53
67
|
* Wraps a command's success schema so that the wire format carries both the `payload`
|
|
54
68
|
* (the handler's actual return value) and `metadata` (server-driven cache invalidation keys).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.test.d.ts","sourceRoot":"","sources":["../rpc.test.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"rpc.test.d.ts","sourceRoot":"","sources":["../rpc.test.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACrF,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;;;;;;;;;;;;;;;;;;;;;;;;AAE7C,qBAAa,iBAAkB,SAAQ,sBAIrC;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAI0B,KAAK;;;;AAKpC,qBAAa,KAAM,SAAQ,UAQzB;CAAG"}
|
package/test/rpc.test.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type * as Effect from "effect/Effect"
|
|
|
2
2
|
import type * as Option from "effect/Option"
|
|
3
3
|
import { expect, test } from "vitest"
|
|
4
4
|
import { makeRpcClient, NotLoggedInError, UnauthorizedError } from "../src/client.js"
|
|
5
|
-
import { ForceVoid } from "../src/client/makeClient.js"
|
|
6
5
|
import { S } from "../src/index.js"
|
|
7
6
|
import { RpcContextMap } from "../src/rpc.js"
|
|
8
7
|
|
|
@@ -34,17 +33,17 @@ declare const _statsSuccess: typeof Stats.success.Type
|
|
|
34
33
|
declare const _statsError: typeof Stats.error.Type
|
|
35
34
|
declare const _statsRequestType: typeof Stats.type
|
|
36
35
|
|
|
37
|
-
test("
|
|
36
|
+
test("Void decodes and encodes as void", () => {
|
|
38
37
|
const statsFromMake = Stats.make({})
|
|
39
38
|
const statsFromMakeOption = Stats.makeOption({})
|
|
40
39
|
const statsFromMakeEffect = Stats.makeEffect({})
|
|
41
40
|
|
|
42
|
-
expect(S.decodeUnknownSync(
|
|
43
|
-
expect(S.is(
|
|
44
|
-
expect(S.decodeUnknownSync(
|
|
45
|
-
expect(S.is(
|
|
46
|
-
expect(S.encodeUnknownSync(
|
|
47
|
-
expect(S.encodeUnknownSync(S.toCodecJson(
|
|
41
|
+
expect(S.decodeUnknownSync(S.Void)(undefined)).toBe(undefined)
|
|
42
|
+
expect(S.is(S.Void)(undefined)).toBe(true)
|
|
43
|
+
expect(S.decodeUnknownSync(S.Void)("test")).toBe(undefined)
|
|
44
|
+
expect(S.is(S.Void)("test")).toBe(true)
|
|
45
|
+
expect(S.encodeUnknownSync(S.Void)("test")).toBe(undefined)
|
|
46
|
+
expect(S.encodeUnknownSync(S.toCodecJson(S.Void))("test")).toBe(null)
|
|
48
47
|
expectTypeOf<typeof _stats>().toEqualTypeOf<Stats>()
|
|
49
48
|
expectTypeOf<typeof _statsSuccess>().toEqualTypeOf<{
|
|
50
49
|
readonly usersActive24Hours: number
|