effect-app 4.0.0-beta.304 → 4.0.0-beta.305
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 +6 -0
- package/dist/DataDependencies.d.ts +102 -73
- package/dist/DataDependencies.d.ts.map +1 -1
- package/dist/DataDependencies.js +13 -8
- package/dist/Model/Repository/internal/internal.d.ts +3 -0
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -1
- package/dist/Model/Repository/internal/internal.js +22 -10
- package/dist/Model/Repository/makeRepo.d.ts +7 -0
- package/dist/Model/Repository/makeRepo.d.ts.map +1 -1
- package/dist/Model/Repository/makeRepo.js +1 -1
- package/dist/rpc/Invalidation.d.ts +793 -577
- package/dist/rpc/Invalidation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/DataDependencies.ts +13 -5
- package/src/Model/Repository/internal/internal.ts +41 -9
- package/src/Model/Repository/makeRepo.ts +8 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Invalidation.d.ts","sourceRoot":"","sources":["../../src/rpc/Invalidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAAE,KAAK,gBAAgB,EAAgB,MAAM,wBAAwB,CAAA;AAC5E,OAAO,KAAK,OAAO,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,gBAAgB,MAAM,wBAAwB,CAAA;AAC1D,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAEjC;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAA;CAAE,CAAA;AAmBjH;;;;GAIG;AACH,eAAO,MAAM,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AG,CAAC,CAAC,GAAG,CAAC,CAAC,EAC/D,UAAU,CAAC,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAC7D,CAAA;CACF;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0TAIvB,CAAA"}
|
package/package.json
CHANGED
package/src/DataDependencies.ts
CHANGED
|
@@ -14,7 +14,8 @@ export const DataDependency = S.Union([
|
|
|
14
14
|
}),
|
|
15
15
|
S.Struct({
|
|
16
16
|
type: S.Literal("signal"),
|
|
17
|
-
name: S.String
|
|
17
|
+
name: S.String,
|
|
18
|
+
ids: S.optional(S.NonEmptyArray(S.String))
|
|
18
19
|
})
|
|
19
20
|
])
|
|
20
21
|
export type DataDependency = S.Schema.Type<typeof DataDependency>
|
|
@@ -42,7 +43,6 @@ const sameDomain = (a: DataDependency, b: DataDependency) => a.type === b.type &
|
|
|
42
43
|
|
|
43
44
|
const dependenciesOverlap = (a: DataDependency, b: DataDependency) => {
|
|
44
45
|
if (!sameDomain(a, b)) return false
|
|
45
|
-
if (a.type === "signal" || b.type === "signal") return true
|
|
46
46
|
if (a.ids === undefined || b.ids === undefined) return true
|
|
47
47
|
return a.ids.some((id) => b.ids?.includes(id))
|
|
48
48
|
}
|
|
@@ -57,7 +57,6 @@ const containsDependency = (dependencies: ReadonlySet<DataDependency>, dependenc
|
|
|
57
57
|
const appendDependency = (dependency: DataDependency) => (dependencies: DataDependencies): DataDependencies => {
|
|
58
58
|
const existing = [...dependencies].find((_) => sameDomain(_, dependency))
|
|
59
59
|
if (existing === undefined) return new Set([...dependencies, dependency])
|
|
60
|
-
if (existing.type === "signal" || dependency.type === "signal") return dependencies
|
|
61
60
|
if (existing.ids === undefined) return dependencies
|
|
62
61
|
if (dependency.ids === undefined) {
|
|
63
62
|
return new Set([...dependencies].filter((_) => _ !== existing).concat(dependency))
|
|
@@ -68,10 +67,18 @@ const appendDependency = (dependency: DataDependency) => (dependencies: DataDepe
|
|
|
68
67
|
...new Set([...existing.ids.slice(1), ...dependency.ids].filter((id) => id !== first))
|
|
69
68
|
]
|
|
70
69
|
if (ids.length === existing.ids.length) return dependencies
|
|
71
|
-
const merged = repo(existing.name, ids)
|
|
70
|
+
const merged = existing.type === "repo" ? repo(existing.name, ids) : signal(existing.name, ids)
|
|
72
71
|
return new Set([...dependencies].filter((_) => _ !== existing).concat(merged))
|
|
73
72
|
}
|
|
74
73
|
|
|
74
|
+
export const merge = (...groups: ReadonlyArray<DataDependencies>): DataDependencies => {
|
|
75
|
+
let merged = empty()
|
|
76
|
+
for (const group of groups) {
|
|
77
|
+
for (const dependency of group) merged = appendDependency(dependency)(merged)
|
|
78
|
+
}
|
|
79
|
+
return merged
|
|
80
|
+
}
|
|
81
|
+
|
|
75
82
|
export const DataDependencyRecorder = RequestScopedDependencies.make(
|
|
76
83
|
"effect-app/DataDependencyRecorder",
|
|
77
84
|
Effect.gen(function*() {
|
|
@@ -125,7 +132,8 @@ export const makeDataDependencyRecorder = (
|
|
|
125
132
|
|
|
126
133
|
export const repo = (name: string, ids?: NonEmptyReadonlyArray<string>): DataDependency =>
|
|
127
134
|
ids === undefined ? { type: "repo", name } : { type: "repo", name, ids }
|
|
128
|
-
export const signal = (name: string): DataDependency =>
|
|
135
|
+
export const signal = (name: string, ids?: NonEmptyReadonlyArray<string>): DataDependency =>
|
|
136
|
+
ids === undefined ? { type: "signal", name } : { type: "signal", name, ids }
|
|
129
137
|
|
|
130
138
|
const RepoReadScope = Context.Reference<DataDependency | undefined>("effect-app/DataDependencies/RepoReadScope", {
|
|
131
139
|
defaultValue: () => undefined
|
|
@@ -115,6 +115,7 @@ export function makeRepoInternal<
|
|
|
115
115
|
schemaContext?: Context.Context<RCtx>
|
|
116
116
|
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
117
117
|
dependencyIds?: (item: T) => NonEmptyReadonlyArray<string>
|
|
118
|
+
additionalWriteDependencies?: (item: T) => ReadonlyArray<DataDependencies.DataDependency>
|
|
118
119
|
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
119
120
|
partitionValue?: (e?: Encoded) => string
|
|
120
121
|
}
|
|
@@ -124,6 +125,7 @@ export function makeRepoInternal<
|
|
|
124
125
|
publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, RPublish>
|
|
125
126
|
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
126
127
|
dependencyIds?: (item: T) => NonEmptyReadonlyArray<string>
|
|
128
|
+
additionalWriteDependencies?: (item: T) => ReadonlyArray<DataDependencies.DataDependency>
|
|
127
129
|
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
128
130
|
partitionValue?: (e?: Encoded) => string
|
|
129
131
|
}
|
|
@@ -148,18 +150,28 @@ export function makeRepoInternal<
|
|
|
148
150
|
const recordRead = DataDependencies.readRepo(name)
|
|
149
151
|
const entityDependency = (ids: NonEmptyReadonlyArray<T[IdKey]>) =>
|
|
150
152
|
DataDependencies.repo(name, [String(ids[0]), ...ids.slice(1).map(String)])
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
return
|
|
154
|
-
|
|
155
|
-
...
|
|
156
|
-
|
|
157
|
-
])
|
|
153
|
+
const itemDependencies = (item: T) => {
|
|
154
|
+
const ids = args.dependencyIds?.(item) ?? [String(item[idKey])]
|
|
155
|
+
return [
|
|
156
|
+
DataDependencies.repo(name, ids),
|
|
157
|
+
...(args.additionalWriteDependencies?.(item) ?? [])
|
|
158
|
+
]
|
|
158
159
|
}
|
|
159
160
|
const recordEntityRead = (id: T[IdKey]) => DataDependencies.read(entityDependency([id]))
|
|
160
161
|
const recordEntityWrite = (ids: NonEmptyReadonlyArray<T[IdKey]>) =>
|
|
161
162
|
DataDependencies.write(entityDependency(ids))
|
|
162
|
-
const recordItemWrite = (items: NonEmptyReadonlyArray<T>) =>
|
|
163
|
+
const recordItemWrite = (items: NonEmptyReadonlyArray<T>) =>
|
|
164
|
+
Effect.forEach(
|
|
165
|
+
DataDependencies.merge(new Set(items.flatMap(itemDependencies))),
|
|
166
|
+
DataDependencies.write,
|
|
167
|
+
{ discard: true }
|
|
168
|
+
)
|
|
169
|
+
const recordAdditionalItemWrites = (items: ReadonlyArray<T>) =>
|
|
170
|
+
Effect.forEach(
|
|
171
|
+
DataDependencies.merge(new Set(items.flatMap((item) => args.additionalWriteDependencies?.(item) ?? []))),
|
|
172
|
+
DataDependencies.write,
|
|
173
|
+
{ discard: true }
|
|
174
|
+
)
|
|
163
175
|
const cms = Effect.map(getContextMap.pipe(Effect.orDie), (_) => ({
|
|
164
176
|
get: (id: string) => _.get(`${name}.${id}`),
|
|
165
177
|
set: (id: string, etag: string | undefined) => _.set(`${name}.${id}`, etag)
|
|
@@ -292,6 +304,20 @@ export function makeRepoInternal<
|
|
|
292
304
|
)
|
|
293
305
|
})
|
|
294
306
|
|
|
307
|
+
const loadExistingItems = (ids: ReadonlyArray<T[IdKey]>) =>
|
|
308
|
+
Effect
|
|
309
|
+
.forEach(
|
|
310
|
+
ids,
|
|
311
|
+
(id) =>
|
|
312
|
+
findE(id).pipe(
|
|
313
|
+
Effect.flatMap(Option.match({
|
|
314
|
+
onNone: () => Effect.succeed(Option.none<T>()),
|
|
315
|
+
onSome: (encoded) => decode(encoded).pipe(Effect.orDie, Effect.map(Option.some))
|
|
316
|
+
}))
|
|
317
|
+
)
|
|
318
|
+
)
|
|
319
|
+
.pipe(Effect.map(Array.getSomes))
|
|
320
|
+
|
|
295
321
|
const find = Effect.fn("Repository.find", {
|
|
296
322
|
kind: "client",
|
|
297
323
|
attributes: { "app.entity": name }
|
|
@@ -327,7 +353,10 @@ export function makeRepoInternal<
|
|
|
327
353
|
const it = Chunk.fromIterable(items)
|
|
328
354
|
if (Chunk.isNonEmpty(it)) {
|
|
329
355
|
const values = Chunk.toReadonlyArray(it)
|
|
330
|
-
|
|
356
|
+
const previous = args.additionalWriteDependencies
|
|
357
|
+
? yield* loadExistingItems(values.map((item) => item[idKey]))
|
|
358
|
+
: []
|
|
359
|
+
yield* recordItemWrite([values[0], ...values.slice(1), ...previous])
|
|
331
360
|
}
|
|
332
361
|
const evts = [...events]
|
|
333
362
|
yield* Effect.annotateCurrentSpan({
|
|
@@ -385,6 +414,9 @@ export function makeRepoInternal<
|
|
|
385
414
|
return
|
|
386
415
|
}
|
|
387
416
|
yield* recordEntityWrite(ids)
|
|
417
|
+
if (args.additionalWriteDependencies) {
|
|
418
|
+
yield* loadExistingItems(ids).pipe(Effect.flatMap(recordAdditionalItemWrites))
|
|
419
|
+
}
|
|
388
420
|
const { set } = yield* cms
|
|
389
421
|
const eids = yield* Effect.forEach(ids, (_) => encodeIdOnly(_ as any)).pipe(Effect.orDie)
|
|
390
422
|
yield* Effect.annotateCurrentSpan({ "app.entity.ids": eids })
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type * as Scope from "effect/Scope"
|
|
10
10
|
import type { NonEmptyReadonlyArray } from "../../Array.ts"
|
|
11
11
|
import type * as Context from "../../Context.ts"
|
|
12
|
+
import type * as DataDependencies from "../../DataDependencies.ts"
|
|
12
13
|
import * as Effect from "../../Effect.ts"
|
|
13
14
|
import type * as S from "../../Schema.ts"
|
|
14
15
|
import type { StoreConfig, StoreMaker } from "../../Store.ts"
|
|
@@ -61,6 +62,13 @@ export interface RepositoryOptions<
|
|
|
61
62
|
/** IDs, including aliases, that identify an entity for dependency invalidation. */
|
|
62
63
|
dependencyIds?: (item: T) => NonEmptyReadonlyArray<string>
|
|
63
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Additional derived queries or resources affected by writing an item.
|
|
67
|
+
* Saves invalidate dependencies derived from both the previous and next item;
|
|
68
|
+
* removals derive them from the removed item.
|
|
69
|
+
*/
|
|
70
|
+
additionalWriteDependencies?: (item: T) => ReadonlyArray<DataDependencies.DataDependency>
|
|
71
|
+
|
|
64
72
|
overrides?: (
|
|
65
73
|
repo: Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>
|
|
66
74
|
) => Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>
|