effect-app 4.0.0-beta.248 → 4.0.0-beta.249
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 +9 -1
- package/dist/Emailer.d.ts +51 -0
- package/dist/Emailer.d.ts.map +1 -0
- package/dist/Emailer.js +7 -0
- package/dist/Model/Repository/Registry.d.ts +21 -0
- package/dist/Model/Repository/Registry.d.ts.map +1 -0
- package/dist/Model/Repository/Registry.js +18 -0
- package/dist/Model/Repository/ext.d.ts +60 -0
- package/dist/Model/Repository/ext.d.ts.map +1 -0
- package/dist/Model/Repository/ext.js +122 -0
- package/dist/Model/Repository/internal/internal.d.ts +62 -0
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -0
- package/dist/Model/Repository/internal/internal.js +413 -0
- package/dist/Model/Repository/legacy.d.ts +21 -0
- package/dist/Model/Repository/legacy.d.ts.map +1 -0
- package/dist/Model/Repository/legacy.js +2 -0
- package/dist/Model/Repository/makeRepo.d.ts +53 -0
- package/dist/Model/Repository/makeRepo.d.ts.map +1 -0
- package/dist/Model/Repository/makeRepo.js +27 -0
- package/dist/Model/Repository/service.d.ts +97 -0
- package/dist/Model/Repository/service.d.ts.map +1 -0
- package/dist/Model/Repository/service.js +2 -0
- package/dist/Model/Repository/validation.d.ts +71 -0
- package/dist/Model/Repository/validation.d.ts.map +1 -0
- package/dist/Model/Repository/validation.js +32 -0
- package/dist/Model/Repository.d.ts +7 -0
- package/dist/Model/Repository.d.ts.map +1 -0
- package/dist/Model/Repository.js +7 -0
- package/dist/Model/dsl.d.ts +33 -0
- package/dist/Model/dsl.d.ts.map +1 -0
- package/dist/Model/dsl.js +43 -0
- package/dist/Model/filter/filterApi.d.ts +30 -0
- package/dist/Model/filter/filterApi.d.ts.map +1 -0
- package/dist/Model/filter/filterApi.js +2 -0
- package/dist/Model/filter/types/errors.d.ts +29 -0
- package/dist/Model/filter/types/errors.d.ts.map +1 -0
- package/dist/Model/filter/types/errors.js +2 -0
- package/dist/Model/filter/types/fields.d.ts +15 -0
- package/dist/Model/filter/types/fields.d.ts.map +1 -0
- package/dist/Model/filter/types/fields.js +2 -0
- package/dist/Model/filter/types/path/common.d.ts +316 -0
- package/dist/Model/filter/types/path/common.d.ts.map +1 -0
- package/dist/Model/filter/types/path/common.js +2 -0
- package/dist/Model/filter/types/path/eager.d.ts +95 -0
- package/dist/Model/filter/types/path/eager.d.ts.map +1 -0
- package/dist/Model/filter/types/path/eager.js +31 -0
- package/dist/Model/filter/types/path/index.d.ts +4 -0
- package/dist/Model/filter/types/path/index.d.ts.map +1 -0
- package/dist/Model/filter/types/path/index.js +3 -0
- package/dist/Model/filter/types/utils.d.ts +79 -0
- package/dist/Model/filter/types/utils.d.ts.map +1 -0
- package/dist/Model/filter/types/utils.js +2 -0
- package/dist/Model/filter/types/validator.d.ts +30 -0
- package/dist/Model/filter/types/validator.d.ts.map +1 -0
- package/dist/Model/filter/types/validator.js +2 -0
- package/dist/Model/filter/types.d.ts +5 -0
- package/dist/Model/filter/types.d.ts.map +1 -0
- package/dist/Model/filter/types.js +7 -0
- package/dist/Model/query/dsl.d.ts +446 -0
- package/dist/Model/query/dsl.d.ts.map +1 -0
- package/dist/Model/query/dsl.js +342 -0
- package/dist/Model/query/new-kid-interpreter.d.ts +136 -0
- package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -0
- package/dist/Model/query/new-kid-interpreter.js +336 -0
- package/dist/Model/query.d.ts +15 -0
- package/dist/Model/query.d.ts.map +1 -0
- package/dist/Model/query.js +3 -0
- package/dist/Model.d.ts +5 -0
- package/dist/Model.d.ts.map +1 -0
- package/dist/Model.js +5 -0
- package/dist/QueueMaker.d.ts +13 -0
- package/dist/QueueMaker.d.ts.map +1 -0
- package/dist/QueueMaker.js +4 -0
- package/dist/RequestContext.d.ts +103 -0
- package/dist/RequestContext.d.ts.map +1 -0
- package/dist/RequestContext.js +49 -0
- package/dist/Store.d.ts +147 -0
- package/dist/Store.d.ts.map +1 -0
- package/dist/Store.js +95 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +40 -0
- package/dist/toast.d.ts +51 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +34 -0
- package/dist/withToast.d.ts +30 -0
- package/dist/withToast.d.ts.map +1 -0
- package/dist/withToast.js +64 -0
- package/package.json +113 -1
- package/src/Emailer.ts +51 -0
- package/src/Model/Repository/Registry.ts +34 -0
- package/src/Model/Repository/ext.ts +375 -0
- package/src/Model/Repository/internal/internal.ts +708 -0
- package/src/Model/Repository/legacy.ts +29 -0
- package/src/Model/Repository/makeRepo.ts +144 -0
- package/src/Model/Repository/service.ts +639 -0
- package/src/Model/Repository/validation.ts +31 -0
- package/src/Model/Repository.ts +6 -0
- package/src/Model/dsl.ts +129 -0
- package/src/Model/filter/filterApi.ts +60 -0
- package/src/Model/filter/types/errors.ts +47 -0
- package/src/Model/filter/types/fields.ts +50 -0
- package/src/Model/filter/types/path/common.ts +404 -0
- package/src/Model/filter/types/path/eager.ts +297 -0
- package/src/Model/filter/types/path/index.ts +4 -0
- package/src/Model/filter/types/utils.ts +128 -0
- package/src/Model/filter/types/validator.ts +46 -0
- package/src/Model/filter/types.ts +6 -0
- package/src/Model/query/dsl.ts +2546 -0
- package/src/Model/query/new-kid-interpreter.ts +484 -0
- package/src/Model/query.ts +13 -0
- package/src/Model.ts +4 -0
- package/src/QueueMaker.ts +19 -0
- package/src/RequestContext.ts +62 -0
- package/src/Store.ts +243 -0
- package/src/index.ts +2 -0
- package/src/runtime.ts +56 -0
- package/src/toast.ts +54 -0
- package/src/withToast.ts +133 -0
- package/test/dist/rpc-dynamic-middleware.test.d.ts.map +1 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
|
+
import type { OptimisticConcurrencyException } from "../../client/errors.js"
|
|
4
|
+
import type * as Effect from "../../Effect.js"
|
|
5
|
+
import type * as Option from "../../Option.js"
|
|
6
|
+
import type * as S from "../../Schema.js"
|
|
7
|
+
|
|
8
|
+
export interface Mapped1<A, IdKey extends keyof A, R> {
|
|
9
|
+
all: Effect.Effect<A[], S.SchemaError, R>
|
|
10
|
+
save: (...xes: readonly A[]) => Effect.Effect<void, OptimisticConcurrencyException | S.SchemaError, R>
|
|
11
|
+
find: (id: A[IdKey]) => Effect.Effect<Option.Option<A>, S.SchemaError, R>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// TODO: auto use project, and select fields from the From side of schema only
|
|
15
|
+
export interface Mapped2<A, R> {
|
|
16
|
+
all: Effect.Effect<A[], S.SchemaError, R>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Mapped<Encoded> {
|
|
20
|
+
<A, R, IdKey extends keyof A>(schema: S.Codec<A, Encoded, R>): Mapped1<A, IdKey, R>
|
|
21
|
+
// TODO: constrain on Encoded2 having to contain only fields that fit Encoded
|
|
22
|
+
<A, Encoded2, R>(schema: S.Codec<A, Encoded2, R>): Mapped2<A, R>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface MM<Repo, Encoded> {
|
|
26
|
+
<A, R, IdKey extends keyof A>(schema: S.Codec<A, Encoded, R>): Effect.Effect<Mapped1<A, IdKey, R>, never, Repo>
|
|
27
|
+
// TODO: constrain on Encoded2 having to contain only fields that fit Encoded
|
|
28
|
+
<A, Encoded2, R>(schema: S.Codec<A, Encoded2, R>): Effect.Effect<Mapped2<A, R>, never, Repo>
|
|
29
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
|
+
|
|
7
|
+
// import type { ParserEnv } from "../../Schema/custom/Parser.js"
|
|
8
|
+
|
|
9
|
+
import type { NonEmptyReadonlyArray } from "../../Array.js"
|
|
10
|
+
import type * as Context from "../../Context.js"
|
|
11
|
+
import * as Effect from "../../Effect.js"
|
|
12
|
+
import type * as S from "../../Schema.js"
|
|
13
|
+
import type { StoreConfig, StoreMaker } from "../../Store.js"
|
|
14
|
+
import type { FieldValues } from "../filter/types.js"
|
|
15
|
+
import { type ExtendedRepository, extendRepo } from "./ext.js"
|
|
16
|
+
import { makeRepoInternal } from "./internal/internal.js"
|
|
17
|
+
import { RepositoryRegistry } from "./Registry.js"
|
|
18
|
+
import type { Repository } from "./service.js"
|
|
19
|
+
|
|
20
|
+
export interface RepositoryOptions<
|
|
21
|
+
IdKey extends keyof T & keyof Encoded,
|
|
22
|
+
Encoded extends FieldValues,
|
|
23
|
+
T,
|
|
24
|
+
ItemType extends string,
|
|
25
|
+
Evt = never,
|
|
26
|
+
RPublish = never,
|
|
27
|
+
E = never,
|
|
28
|
+
RInitial = never,
|
|
29
|
+
RCtx = never,
|
|
30
|
+
RSchema = never
|
|
31
|
+
> {
|
|
32
|
+
/**
|
|
33
|
+
* Specify the idKey of the Type side, if it's different from the default "id".
|
|
34
|
+
* Does not change the Encoded side, which is always "id" to support database drivers.
|
|
35
|
+
* At this time as queries are operating on the Encoded side, the queries must still specify "id" regardless.
|
|
36
|
+
*/
|
|
37
|
+
idKey: IdKey
|
|
38
|
+
/**
|
|
39
|
+
* just in time Migration: for complex migrations that aren't just default simple values
|
|
40
|
+
* use the config.defaultValues instead for simple default values
|
|
41
|
+
*/
|
|
42
|
+
jitM?: (pm: Encoded) => Encoded
|
|
43
|
+
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
44
|
+
partitionValue?: (e?: Encoded) => string
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Optional handler to be able to publish events after successfull save.
|
|
48
|
+
*/
|
|
49
|
+
publishEvents?: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, RPublish>
|
|
50
|
+
/**
|
|
51
|
+
* Optional creator for initial data in the table when it's created for the first itme.
|
|
52
|
+
*/
|
|
53
|
+
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
54
|
+
/**
|
|
55
|
+
* Optional context to be provided to Schema decode/encode.
|
|
56
|
+
* Useful for effectful transformations like XWithItems, where items is a transformation retrieving elements from another database table or other source.
|
|
57
|
+
*/
|
|
58
|
+
schemaContext?: Context.Context<RCtx>
|
|
59
|
+
|
|
60
|
+
overrides?: (
|
|
61
|
+
repo: Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>
|
|
62
|
+
) => Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create a repository instance.
|
|
67
|
+
* @param itemType an identifier used for the table name and e.g NotFoundError
|
|
68
|
+
* @param schema the Schema used for this Repository
|
|
69
|
+
* @param options @see RepositoryOptions
|
|
70
|
+
* @returns a Repository
|
|
71
|
+
*/
|
|
72
|
+
export const makeRepo: {
|
|
73
|
+
<
|
|
74
|
+
ItemType extends string,
|
|
75
|
+
RSchema,
|
|
76
|
+
Encoded extends FieldValues,
|
|
77
|
+
T,
|
|
78
|
+
IdKey extends keyof T & keyof Encoded,
|
|
79
|
+
E = never,
|
|
80
|
+
Evt = never,
|
|
81
|
+
RInitial = never,
|
|
82
|
+
RPublish = never,
|
|
83
|
+
RCtx = never
|
|
84
|
+
>(
|
|
85
|
+
itemType: ItemType,
|
|
86
|
+
schema: S.Codec<T, Encoded, RSchema>,
|
|
87
|
+
options: RepositoryOptions<IdKey, Encoded, T, ItemType, Evt, RPublish, E, RInitial, RCtx, RSchema>
|
|
88
|
+
): Effect.Effect<
|
|
89
|
+
ExtendedRepository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>,
|
|
90
|
+
E,
|
|
91
|
+
RInitial | StoreMaker | RepositoryRegistry
|
|
92
|
+
>
|
|
93
|
+
<
|
|
94
|
+
ItemType extends string,
|
|
95
|
+
RSchema,
|
|
96
|
+
Encoded extends FieldValues,
|
|
97
|
+
T extends { id: unknown },
|
|
98
|
+
E = never,
|
|
99
|
+
Evt = never,
|
|
100
|
+
RInitial = never,
|
|
101
|
+
RPublish = never,
|
|
102
|
+
RCtx = never
|
|
103
|
+
>(
|
|
104
|
+
itemType: ItemType,
|
|
105
|
+
schema: S.Codec<T, Encoded, RSchema>,
|
|
106
|
+
options: Omit<RepositoryOptions<"id", Encoded, T, ItemType, Evt, RPublish, E, RInitial, RCtx, RSchema>, "idKey">
|
|
107
|
+
): Effect.Effect<
|
|
108
|
+
ExtendedRepository<T, Encoded, Evt, ItemType, "id", Exclude<RSchema, RCtx>, RPublish, RCtx>,
|
|
109
|
+
E,
|
|
110
|
+
RInitial | StoreMaker | RepositoryRegistry
|
|
111
|
+
>
|
|
112
|
+
} = <
|
|
113
|
+
ItemType extends string,
|
|
114
|
+
RSchema,
|
|
115
|
+
Encoded extends FieldValues,
|
|
116
|
+
T,
|
|
117
|
+
IdKey extends keyof T & keyof Encoded,
|
|
118
|
+
E = never,
|
|
119
|
+
RInitial = never,
|
|
120
|
+
RPublish = never,
|
|
121
|
+
Evt = never,
|
|
122
|
+
RCtx = never
|
|
123
|
+
>(
|
|
124
|
+
itemType: ItemType,
|
|
125
|
+
schema: S.Codec<T, Encoded, RSchema>,
|
|
126
|
+
options: Omit<RepositoryOptions<IdKey, Encoded, T, ItemType, Evt, RPublish, E, RInitial, RCtx, RSchema>, "idKey"> & {
|
|
127
|
+
idKey?: IdKey
|
|
128
|
+
}
|
|
129
|
+
) =>
|
|
130
|
+
Effect.gen(function*() {
|
|
131
|
+
const mkRepo = makeRepoInternal<Evt>()(
|
|
132
|
+
itemType,
|
|
133
|
+
schema,
|
|
134
|
+
options?.jitM ? (pm) => options.jitM!(pm) : (pm) => pm,
|
|
135
|
+
(e, _etag) => ({ ...e, _etag }),
|
|
136
|
+
options.idKey ?? "id" as any
|
|
137
|
+
)
|
|
138
|
+
let r = yield* mkRepo.make<RInitial, E, RPublish, RCtx>(options as any)
|
|
139
|
+
if (options.overrides) r = options.overrides(r)
|
|
140
|
+
const repo = extendRepo(r)
|
|
141
|
+
const registry = yield* RepositoryRegistry
|
|
142
|
+
registry.register(itemType, repo)
|
|
143
|
+
return repo
|
|
144
|
+
})
|