effect-app 4.0.0-beta.29 → 4.0.0-beta.291
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 +1397 -0
- package/dist/Array.d.ts +2 -1
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +4 -4
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Config/SecretURL.d.ts +3 -1
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +3 -6
- package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
- package/dist/Config/internal/configSecretURL.js +2 -2
- package/dist/Config.d.ts +2 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +8 -0
- package/dist/ConfigProvider.d.ts +2 -0
- package/dist/ConfigProvider.d.ts.map +1 -0
- package/dist/ConfigProvider.js +6 -0
- package/dist/{ServiceMap.d.ts → Context.d.ts} +18 -20
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +67 -0
- package/dist/DataDependencies.d.ts +388 -0
- package/dist/DataDependencies.d.ts.map +1 -0
- package/dist/DataDependencies.js +64 -0
- package/dist/Effect.d.ts +10 -9
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +5 -8
- package/dist/Emailer.d.ts +51 -0
- package/dist/Emailer.d.ts.map +1 -0
- package/dist/Emailer.js +7 -0
- package/dist/Function.d.ts.map +1 -1
- package/dist/Layer.d.ts +10 -6
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +3 -2
- package/dist/Model/Repository/Registry.d.ts +22 -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 +63 -0
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -0
- package/dist/Model/Repository/internal/internal.js +438 -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 +54 -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 +121 -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 +58 -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 +94 -0
- package/dist/Model/filter/types/path/eager.d.ts.map +1 -0
- package/dist/Model/filter/types/path/eager.js +36 -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 +506 -0
- package/dist/Model/query/dsl.d.ts.map +1 -0
- package/dist/Model/query/dsl.js +376 -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/NonEmptySet.d.ts +3 -1
- package/dist/NonEmptySet.d.ts.map +1 -1
- package/dist/NonEmptySet.js +2 -2
- package/dist/Option.d.ts +1 -0
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +3 -1
- package/dist/Pure.d.ts +7 -5
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +7 -4
- package/dist/QueueMaker.d.ts +11 -0
- package/dist/QueueMaker.d.ts.map +1 -0
- package/dist/QueueMaker.js +11 -0
- package/dist/RequestContext.d.ts +87 -0
- package/dist/RequestContext.d.ts.map +1 -0
- package/dist/RequestContext.js +45 -0
- package/dist/RequestScopedDependencies.d.ts +21 -0
- package/dist/RequestScopedDependencies.d.ts.map +1 -0
- package/dist/RequestScopedDependencies.js +16 -0
- package/dist/Schema/Class.d.ts +188 -19
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +260 -17
- package/dist/Schema/FastCheck.d.ts.map +1 -1
- package/dist/Schema/SchemaParser.d.ts +5 -0
- package/dist/Schema/SchemaParser.d.ts.map +1 -0
- package/dist/Schema/SchemaParser.js +6 -0
- package/dist/Schema/SpecialJsonSchema.d.ts +34 -0
- package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
- package/dist/Schema/SpecialJsonSchema.js +118 -0
- package/dist/Schema/SpecialOpenApi.d.ts +32 -0
- package/dist/Schema/SpecialOpenApi.d.ts.map +1 -0
- package/dist/Schema/SpecialOpenApi.js +123 -0
- package/dist/Schema/brand.d.ts +4 -2
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +3 -1
- package/dist/Schema/email.d.ts.map +1 -1
- package/dist/Schema/email.js +7 -4
- package/dist/Schema/ext.d.ts +338 -55
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +358 -53
- package/dist/Schema/moreStrings.d.ts +82 -36
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +49 -42
- package/dist/Schema/numbers.d.ts +34 -21
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +55 -12
- package/dist/Schema/phoneNumber.d.ts.map +1 -1
- package/dist/Schema/phoneNumber.js +6 -3
- 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 +18 -4
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema/strings.js +1 -5
- package/dist/Schema.d.ts +222 -8
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +191 -12
- package/dist/SchemaAST.d.ts +2 -0
- package/dist/SchemaAST.d.ts.map +1 -0
- package/dist/SchemaAST.js +2 -0
- package/dist/Set.d.ts +4 -1
- package/dist/Set.d.ts.map +1 -1
- package/dist/Set.js +3 -2
- package/dist/Store.d.ts +163 -0
- package/dist/Store.d.ts.map +1 -0
- package/dist/Store.js +113 -0
- package/dist/_ext/Array.d.ts +1 -1
- package/dist/_ext/Array.d.ts.map +1 -1
- package/dist/_ext/Array.js +4 -2
- package/dist/_ext/misc.d.ts +4 -1
- package/dist/_ext/misc.d.ts.map +1 -1
- package/dist/_ext/misc.js +4 -2
- package/dist/_ext/ord.ext.d.ts +2 -1
- package/dist/_ext/ord.ext.d.ts.map +1 -1
- package/dist/_ext/ord.ext.js +2 -2
- package/dist/builtin.d.ts +2 -14
- package/dist/builtin.d.ts.map +1 -1
- package/dist/builtin.js +1 -1
- package/dist/client/InvalidationKeys.d.ts +29 -0
- package/dist/client/InvalidationKeys.d.ts.map +1 -0
- package/dist/client/InvalidationKeys.js +33 -0
- package/dist/client/apiClientFactory.d.ts +19 -31
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +155 -35
- package/dist/client/clientFor.d.ts +54 -18
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/clientFor.js +9 -1
- package/dist/client/errors.d.ts +82 -27
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +75 -19
- package/dist/client/makeClient.d.ts +492 -32
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +62 -28
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -1
- package/dist/faker.d.ts.map +1 -1
- package/dist/http/Request.d.ts +1 -1
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +2 -2
- package/dist/ids.d.ts +42 -14
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +30 -5
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/middleware.d.ts +13 -7
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +14 -8
- package/dist/rpc/Invalidation.d.ts +3140 -0
- package/dist/rpc/Invalidation.d.ts.map +1 -0
- package/dist/rpc/Invalidation.js +178 -0
- package/dist/rpc/MiddlewareMaker.d.ts +11 -7
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +59 -38
- package/dist/rpc/RpcContextMap.d.ts +3 -3
- package/dist/rpc/RpcContextMap.d.ts.map +1 -1
- package/dist/rpc/RpcContextMap.js +4 -4
- package/dist/rpc/RpcMiddleware.d.ts +14 -10
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +2 -2
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +40 -0
- package/dist/setupRequest.d.ts +20 -0
- package/dist/setupRequest.d.ts.map +1 -0
- package/dist/setupRequest.js +72 -0
- package/dist/toast.d.ts +51 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +34 -0
- package/dist/transform.d.ts +1 -1
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +4 -5
- package/dist/utils/effectify.d.ts +1 -1
- package/dist/utils/effectify.d.ts.map +1 -1
- package/dist/utils/effectify.js +2 -2
- package/dist/utils/extend.d.ts.map +1 -1
- package/dist/utils/gen.d.ts +4 -4
- package/dist/utils/gen.d.ts.map +1 -1
- package/dist/utils/logLevel.d.ts +2 -2
- package/dist/utils/logLevel.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +4 -3
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +4 -4
- package/dist/utils.d.ts +34 -39
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +33 -37
- package/dist/validation/validators.d.ts.map +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/withToast.d.ts +30 -0
- package/dist/withToast.d.ts.map +1 -0
- package/dist/withToast.js +64 -0
- package/package.json +22 -251
- package/src/Array.ts +5 -5
- package/src/Chunk.ts +3 -3
- package/src/Config/SecretURL.ts +6 -3
- package/src/Config/internal/configSecretURL.ts +2 -2
- package/src/Config.ts +7 -0
- package/src/ConfigProvider.ts +5 -0
- package/src/{ServiceMap.ts → Context.ts} +56 -63
- package/src/DataDependencies.ts +114 -0
- package/src/Effect.ts +14 -16
- package/src/Emailer.ts +51 -0
- package/src/Inputify.type.ts +1 -1
- package/src/Layer.ts +11 -7
- package/src/Model/Repository/Registry.ts +35 -0
- package/src/Model/Repository/ext.ts +375 -0
- package/src/Model/Repository/internal/internal.ts +755 -0
- package/src/Model/Repository/legacy.ts +29 -0
- package/src/Model/Repository/makeRepo.ts +145 -0
- package/src/Model/Repository/service.ts +676 -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 +329 -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 +2781 -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/NonEmptySet.ts +6 -4
- package/src/Option.ts +2 -0
- package/src/Pure.ts +10 -7
- package/src/QueueMaker.ts +11 -0
- package/src/RequestContext.ts +48 -0
- package/src/RequestScopedDependencies.ts +45 -0
- package/src/Schema/Class.ts +633 -59
- package/src/Schema/SchemaParser.ts +12 -0
- package/src/Schema/SpecialJsonSchema.ts +139 -0
- package/src/Schema/SpecialOpenApi.ts +130 -0
- package/src/Schema/brand.ts +22 -2
- package/src/Schema/email.ts +9 -4
- package/src/Schema/ext.ts +446 -91
- package/src/Schema/moreStrings.ts +147 -68
- package/src/Schema/numbers.ts +97 -28
- package/src/Schema/phoneNumber.ts +9 -5
- package/src/Schema/schema.ts +1 -1
- package/src/Schema/strings.ts +23 -14
- package/src/Schema.ts +397 -26
- package/src/SchemaAST.ts +1 -0
- package/src/Set.ts +6 -2
- package/src/Store.ts +273 -0
- package/src/_ext/Array.ts +4 -2
- package/src/_ext/misc.ts +4 -1
- package/src/_ext/ord.ext.ts +2 -1
- package/src/builtin-json.d.ts +24 -0
- package/src/builtin.ts +16 -21
- package/src/client/InvalidationKeys.ts +50 -0
- package/src/client/apiClientFactory.ts +299 -134
- package/src/client/clientFor.ts +107 -34
- package/src/client/errors.ts +100 -29
- package/src/client/makeClient.ts +586 -78
- package/src/client.ts +6 -4
- package/src/http/Request.ts +3 -3
- package/src/http.ts +1 -1
- package/src/ids.ts +33 -6
- package/src/index.ts +20 -23
- package/src/middleware.ts +13 -9
- package/src/rpc/Invalidation.ts +278 -0
- package/src/rpc/MiddlewareMaker.ts +88 -80
- package/src/rpc/README.md +2 -2
- package/src/rpc/RpcContextMap.ts +7 -6
- package/src/rpc/RpcMiddleware.ts +19 -13
- package/src/rpc.ts +4 -4
- package/src/runtime.ts +56 -0
- package/src/setupRequest.ts +138 -0
- package/src/toast.ts +54 -0
- package/src/transform.ts +4 -4
- package/src/utils/effectify.ts +1 -1
- package/src/utils/gen.ts +8 -8
- package/src/utils/logLevel.ts +1 -1
- package/src/utils/logger.ts +4 -3
- package/src/utils.ts +85 -158
- package/src/validation.ts +2 -2
- package/src/withToast.ts +133 -0
- package/test/dist/rpc.test.d.ts.map +1 -1
- package/test/dist/secretURL.test.d.ts.map +1 -0
- package/test/dist/special.test.d.ts.map +1 -0
- package/test/moreStrings.test.ts +1 -1
- package/test/rpc.test.ts +45 -6
- package/test/schema.test.ts +459 -30
- package/test/secretURL.test.ts +160 -0
- package/test/special.test.ts +1258 -0
- package/test/utils.test.ts +7 -7
- package/tsconfig.base.json +6 -5
- package/tsconfig.json +3 -1
- package/tsconfig.src.json +29 -29
- package/tsconfig.test.json +2 -2
- package/dist/Operations.d.ts +0 -123
- package/dist/Operations.d.ts.map +0 -1
- package/dist/Operations.js +0 -29
- package/dist/ServiceMap.d.ts.map +0 -1
- package/dist/ServiceMap.js +0 -91
- package/eslint.config.mjs +0 -26
- package/src/Operations.ts +0 -55
- package/tsconfig.json.bak +0 -12
package/src/Store.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import type * as Redacted from "effect/Redacted"
|
|
3
|
+
import * as Semaphore from "effect/Semaphore"
|
|
4
|
+
import type { NonEmptyReadonlyArray } from "./Array.ts"
|
|
5
|
+
import type { DatabaseError, OptimisticConcurrencyException } from "./client/errors.ts"
|
|
6
|
+
import * as Context from "./Context.ts"
|
|
7
|
+
import * as Effect from "./Effect.ts"
|
|
8
|
+
import type { FilterResult } from "./Model/filter/filterApi.ts"
|
|
9
|
+
import type { FieldValues } from "./Model/filter/types.ts"
|
|
10
|
+
import type { FieldPath } from "./Model/filter/types/path/index.ts"
|
|
11
|
+
import type { AggregateIrExpression, ComputedProjectionIrExpression, RawQuery } from "./Model/query.ts"
|
|
12
|
+
import type * as Option from "./Option.ts"
|
|
13
|
+
import * as RequestScopedDependencies from "./RequestScopedDependencies.ts"
|
|
14
|
+
import { NonEmptyString255 } from "./Schema.ts"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Adapter-neutral unique-key definition for stores that support unique indexes,
|
|
18
|
+
* such as the Cosmos adapter. This shape is intentionally kept structurally
|
|
19
|
+
* compatible with adapter-specific `UniqueKey` types. Each path identifies a
|
|
20
|
+
* field participating in the unique key, and adapters forward these paths
|
|
21
|
+
* directly to the underlying storage engine.
|
|
22
|
+
*/
|
|
23
|
+
export interface UniqueKey {
|
|
24
|
+
readonly paths: string[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface StoreConfig<E> {
|
|
28
|
+
partitionValue: (e?: E) => string
|
|
29
|
+
/**
|
|
30
|
+
* Primarily used for testing, creating namespaces in the database to separate data e.g to run multiple tests in isolation within the same database.
|
|
31
|
+
* Memory/Disk use separate store instances per namespace. CosmosDB uses namespace-prefixed partition keys. SQL uses a `_namespace` column.
|
|
32
|
+
*/
|
|
33
|
+
allowNamespace?: (namespace: string) => boolean
|
|
34
|
+
/**
|
|
35
|
+
* just in time migrations, supported by the database driver, supporting queries, for simple default values
|
|
36
|
+
*/
|
|
37
|
+
defaultValues?: Partial<E>
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* How many items can be processed in one batch at a time.
|
|
41
|
+
* Defaults to 100 for CosmosDB.
|
|
42
|
+
*/
|
|
43
|
+
maxBulkSize?: number
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Unique indexes, mainly for CosmosDB
|
|
47
|
+
*/
|
|
48
|
+
uniqueKeys?: UniqueKey[]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type SupportedValues = string | boolean | number | null
|
|
52
|
+
export type SupportedValues2 = string | boolean | number
|
|
53
|
+
|
|
54
|
+
// default is eq
|
|
55
|
+
export type Where =
|
|
56
|
+
| { key: string; t?: "eq" | "not-eq"; value: SupportedValues }
|
|
57
|
+
| { key: string; t: "gt" | "lt" | "gte" | "lte"; value: SupportedValues2 }
|
|
58
|
+
| {
|
|
59
|
+
key: string
|
|
60
|
+
t: "contains" | "starts-with" | "ends-with" | "not-contains" | "not-starts-with" | "not-ends-with"
|
|
61
|
+
value: string
|
|
62
|
+
}
|
|
63
|
+
| { key: string; t: "includes" | "not-includes"; value: string }
|
|
64
|
+
| {
|
|
65
|
+
key: string
|
|
66
|
+
t: "in" | "not-in"
|
|
67
|
+
value: readonly (SupportedValues)[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type Filter = readonly FilterResult[]
|
|
71
|
+
|
|
72
|
+
export interface O<TFieldValues extends FieldValues> {
|
|
73
|
+
key: FieldPath<TFieldValues>
|
|
74
|
+
direction: "ASC" | "DESC"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface FilterArgs<Encoded extends FieldValues, U extends keyof Encoded = never> {
|
|
78
|
+
t: Encoded
|
|
79
|
+
filter?: Filter | undefined
|
|
80
|
+
select?:
|
|
81
|
+
| NonEmptyReadonlyArray<
|
|
82
|
+
U | { key: string; subKeys: readonly string[] } | {
|
|
83
|
+
key: string
|
|
84
|
+
computed: ComputedProjectionIrExpression
|
|
85
|
+
} | {
|
|
86
|
+
key: string
|
|
87
|
+
path: string
|
|
88
|
+
} | {
|
|
89
|
+
key: string
|
|
90
|
+
aggregate: AggregateIrExpression
|
|
91
|
+
}
|
|
92
|
+
>
|
|
93
|
+
| undefined
|
|
94
|
+
order?: NonEmptyReadonlyArray<O<NoInfer<Encoded>>>
|
|
95
|
+
limit?: number | undefined
|
|
96
|
+
skip?: number | undefined
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type FilterFunc<Encoded extends FieldValues> = <U extends keyof Encoded = never>(
|
|
100
|
+
args: FilterArgs<Encoded, U>
|
|
101
|
+
) => Effect.Effect<(U extends undefined ? Encoded : Pick<Encoded, U>)[], DatabaseError>
|
|
102
|
+
|
|
103
|
+
export interface Store<
|
|
104
|
+
IdKey extends keyof Encoded,
|
|
105
|
+
Encoded extends FieldValues,
|
|
106
|
+
PM extends PersistenceModelType<Encoded> = PersistenceModelType<Encoded>
|
|
107
|
+
> {
|
|
108
|
+
all: Effect.Effect<PM[], DatabaseError>
|
|
109
|
+
filter: FilterFunc<Encoded>
|
|
110
|
+
find: (id: Encoded[IdKey]) => Effect.Effect<Option.Option<PM>, DatabaseError>
|
|
111
|
+
set: (e: PM) => Effect.Effect<PM, OptimisticConcurrencyException | DatabaseError>
|
|
112
|
+
batchSet: (
|
|
113
|
+
items: NonEmptyReadonlyArray<PM>
|
|
114
|
+
) => Effect.Effect<NonEmptyReadonlyArray<PM>, OptimisticConcurrencyException | DatabaseError>
|
|
115
|
+
bulkSet: (
|
|
116
|
+
items: NonEmptyReadonlyArray<PM>
|
|
117
|
+
) => Effect.Effect<NonEmptyReadonlyArray<PM>, OptimisticConcurrencyException | DatabaseError>
|
|
118
|
+
batchRemove: (ids: NonEmptyReadonlyArray<Encoded[IdKey]>, partitionKey?: string) => Effect.Effect<void, DatabaseError>
|
|
119
|
+
queryRaw: <Out>(query: RawQuery<Encoded, Out>) => Effect.Effect<readonly Out[], DatabaseError>
|
|
120
|
+
/**
|
|
121
|
+
* Explicitly seed a namespace. Primary is seeded eagerly on initialization.
|
|
122
|
+
* Non-primary namespaces must be seeded explicitly before use.
|
|
123
|
+
*/
|
|
124
|
+
seedNamespace: (namespace: string) => Effect.Effect<void, DatabaseError>
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export class StoreMaker extends Context.Opaque<StoreMaker, {
|
|
128
|
+
make: <IdKey extends keyof Encoded, Encoded extends FieldValues, R = never, E = never>(
|
|
129
|
+
name: string,
|
|
130
|
+
idKey: IdKey,
|
|
131
|
+
seed?: Effect.Effect<Iterable<Encoded>, E, R>,
|
|
132
|
+
config?: StoreConfig<Encoded>
|
|
133
|
+
) => Effect.Effect<Store<IdKey, Encoded>, E, R>
|
|
134
|
+
}>()("effect-app/StoreMaker") {
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const makeContextMap = () => {
|
|
138
|
+
const etags = new Map<string, string>()
|
|
139
|
+
const getEtag = (id: string) => etags.get(id)
|
|
140
|
+
const setEtag = (id: string, eTag: string | undefined) => {
|
|
141
|
+
if (eTag === undefined) {
|
|
142
|
+
etags.delete(id)
|
|
143
|
+
} else {
|
|
144
|
+
etags.set(id, eTag)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// const parsedCache = new Map<
|
|
149
|
+
// Parser<any, any, any>,
|
|
150
|
+
// Map<unknown, These.These<unknown, unknown>>
|
|
151
|
+
// >()
|
|
152
|
+
|
|
153
|
+
// const parserCache = new Map<
|
|
154
|
+
// Parser<any, any, any>,
|
|
155
|
+
// (i: any) => These.These<any, any>
|
|
156
|
+
// >()
|
|
157
|
+
|
|
158
|
+
// const setAndReturn = <I, E, A>(
|
|
159
|
+
// p: Parser<I, E, A>,
|
|
160
|
+
// np: (i: I) => These.These<E, A>
|
|
161
|
+
// ) => {
|
|
162
|
+
// parserCache.set(p, np)
|
|
163
|
+
// return np
|
|
164
|
+
// }
|
|
165
|
+
|
|
166
|
+
// const parserEnv: ParserEnv = {
|
|
167
|
+
// // TODO: lax: true would turn off refinement checks, may help on large payloads
|
|
168
|
+
// // but of course removes confirming of validation rules (which may be okay for a database owned by the app, as we write safely)
|
|
169
|
+
// lax: false,
|
|
170
|
+
// cache: {
|
|
171
|
+
// getOrSetParser: (p) => parserCache.get(p) ?? setAndReturn(p, (i) => parserEnv.cache!.getOrSet(i, p)),
|
|
172
|
+
// getOrSetParsers: (parsers) => {
|
|
173
|
+
// return Object.entries(parsers).reduce((prev, [k, v]) => {
|
|
174
|
+
// prev[k] = parserEnv.cache!.getOrSetParser(v)
|
|
175
|
+
// return prev
|
|
176
|
+
// }, {} as any)
|
|
177
|
+
// },
|
|
178
|
+
// getOrSet: (i, parse): any => {
|
|
179
|
+
// const c = parsedCache.get(parse)
|
|
180
|
+
// if (c) {
|
|
181
|
+
// const f = c.get(i)
|
|
182
|
+
// if (f) {
|
|
183
|
+
// // console.log("$$$ cache hit", i)
|
|
184
|
+
// return f
|
|
185
|
+
// } else {
|
|
186
|
+
// const nf = parse(i, parserEnv)
|
|
187
|
+
// c.set(i, nf)
|
|
188
|
+
// return nf
|
|
189
|
+
// }
|
|
190
|
+
// } else {
|
|
191
|
+
// const nf = parse(i, parserEnv)
|
|
192
|
+
// parsedCache.set(parse, new Map([[i, nf]]))
|
|
193
|
+
// return nf
|
|
194
|
+
// }
|
|
195
|
+
// }
|
|
196
|
+
// }
|
|
197
|
+
// }
|
|
198
|
+
|
|
199
|
+
const store = new Map<symbol, unknown>()
|
|
200
|
+
const sem = Semaphore.makeUnsafe(1)
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
createdAt: new Date(),
|
|
204
|
+
get: getEtag,
|
|
205
|
+
set: setEtag,
|
|
206
|
+
getOrCreateStore: <T>(key: symbol, make: () => T): T => {
|
|
207
|
+
let value = store.get(key) as T | undefined
|
|
208
|
+
if (value === undefined) {
|
|
209
|
+
value = make()
|
|
210
|
+
store.set(key, value)
|
|
211
|
+
}
|
|
212
|
+
return value
|
|
213
|
+
},
|
|
214
|
+
getOrCreateStoreEffect: <T, E, R>(key: symbol, make: Effect.Effect<T, E, R>): Effect.Effect<T, E, R> =>
|
|
215
|
+
sem.withPermits(1)(Effect.uninterruptible(Effect.gen(function*() {
|
|
216
|
+
const value = store.get(key) as T | undefined
|
|
217
|
+
if (value !== undefined) return value
|
|
218
|
+
const v = yield* make
|
|
219
|
+
store.set(key, v)
|
|
220
|
+
return v
|
|
221
|
+
}))),
|
|
222
|
+
clear: () => {
|
|
223
|
+
etags.clear()
|
|
224
|
+
store.clear()
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const makeMap = Effect.acquireRelease(
|
|
230
|
+
Effect.sync(() => makeContextMap()),
|
|
231
|
+
(m) => Effect.sync(() => m.clear())
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
export class ContextMap extends Context.Opaque<ContextMap>()("effect-app/ContextMap", { make: makeMap }) {
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export const ContextMapContainer = RequestScopedDependencies.make(
|
|
238
|
+
"ContextMapContainer",
|
|
239
|
+
ContextMap.make.pipe(Effect.map(ContextMap.of))
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
export type ContextMapNotStartedError = RequestScopedDependencies.RequestScopedDependencyNotStartedError
|
|
243
|
+
|
|
244
|
+
export const getContextMap = ContextMapContainer.current
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Runs `make` at most once per ContextMap (i.e. per request) and caches the
|
|
248
|
+
* resulting value in the ContextMap under a fresh symbol. Subsequent calls of
|
|
249
|
+
* the returned Effect within the same ContextMap return the cached value.
|
|
250
|
+
*
|
|
251
|
+
* Uses the ContextMap's shared semaphore for safe single initialization.
|
|
252
|
+
*/
|
|
253
|
+
export const cachedPerRequest = <A, E, R>(
|
|
254
|
+
make: Effect.Effect<A, E, R>
|
|
255
|
+
): Effect.Effect<A, E | ContextMapNotStartedError, R> => {
|
|
256
|
+
const cacheKey = Symbol()
|
|
257
|
+
return getContextMap.pipe(
|
|
258
|
+
Effect.flatMap((ctxMap) => ctxMap.getOrCreateStoreEffect(cacheKey, make))
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const defaultNs: NonEmptyString255 = NonEmptyString255("primary")
|
|
263
|
+
export class storeId extends Context.Reference("StoreId", { defaultValue: (): NonEmptyString255 => defaultNs }) {}
|
|
264
|
+
|
|
265
|
+
export type PersistenceModelType<Encoded extends object> = Encoded & {
|
|
266
|
+
_etag?: string | undefined
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface StorageConfig {
|
|
270
|
+
url: Redacted.Redacted
|
|
271
|
+
prefix: string
|
|
272
|
+
dbName: string
|
|
273
|
+
}
|
package/src/_ext/Array.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as Chunk from "effect-app/Chunk"
|
|
2
|
+
import * as Effect from "effect-app/Effect"
|
|
3
|
+
import * as Equal from "effect/Equal"
|
|
4
|
+
import { NotFoundError } from "../client/errors.ts"
|
|
3
5
|
|
|
4
6
|
function getFirstBy<A, Type extends string>(
|
|
5
7
|
a: Iterable<A>,
|
package/src/_ext/misc.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { Effect, Option, Result, type Scope } from "effect"
|
|
2
1
|
import type { LazyArg } from "effect-app/Function"
|
|
2
|
+
import * as Effect from "effect/Effect"
|
|
3
|
+
import * as Option from "effect/Option"
|
|
4
|
+
import * as Result from "effect/Result"
|
|
5
|
+
import type * as Scope from "effect/Scope"
|
|
3
6
|
|
|
4
7
|
export type _R<T extends Effect.Effect<any, any, any>> = [T] extends [
|
|
5
8
|
Effect.Effect<any, any, infer R>
|
package/src/_ext/ord.ext.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// JSON / Body return-type overrides (`any` -> `unknown`), isolated from
|
|
2
|
+
// `builtin.ts` so consumers that source-link this package (e.g. an embedded
|
|
3
|
+
// Effect-source setup) can toggle them off. As a `declare global`, the override
|
|
4
|
+
// is program-wide: in linked mode it leaks into source-linked Effect and breaks
|
|
5
|
+
// Effect's own `JSON.parse(...)` / `response.json()` call sites (TS2322
|
|
6
|
+
// `unknown` vs `Json`). `builtin.ts` triple-slash-references this file, so
|
|
7
|
+
// normal builds keep the override.
|
|
8
|
+
declare global {
|
|
9
|
+
interface JSON {
|
|
10
|
+
/**
|
|
11
|
+
* Converts a JavaScript Object Notation (JSON) string into an object.
|
|
12
|
+
* @param text A valid JSON string.
|
|
13
|
+
* @param reviver A function that transforms the results. This function is called for each member of the object.
|
|
14
|
+
* If a member contains nested objects, the nested objects are transformed before the parent object is.
|
|
15
|
+
*/
|
|
16
|
+
parse(text: string, reviver?: (this: any, key: string, value: any) => any): unknown
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface Body {
|
|
20
|
+
json(): Promise<unknown>
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {}
|
package/src/builtin.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// oxlint-disable-next-line typescript/triple-slash-reference
|
|
2
|
+
/// <reference path="./builtin-json.d.ts" />
|
|
1
3
|
import type { NonEmptyArray, NonEmptyReadonlyArray } from "effect/Array"
|
|
2
4
|
|
|
3
5
|
declare global {
|
|
@@ -17,34 +19,27 @@ declare global {
|
|
|
17
19
|
split(separator: string | RegExp, limit?: number): [string, ...string[]]
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* Converts a JavaScript Object Notation (JSON) string into an object.
|
|
23
|
-
* @param text A valid JSON string.
|
|
24
|
-
* @param reviver A function that transforms the results. This function is called for each member of the object.
|
|
25
|
-
* If a member contains nested objects, the nested objects are transformed before the parent object is.
|
|
26
|
-
*/
|
|
27
|
-
parse(text: string, reviver?: (this: any, key: string, value: any) => any): unknown
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface Body {
|
|
31
|
-
json(): Promise<unknown>
|
|
32
|
-
}
|
|
22
|
+
// JSON.parse / Body.json overrides live in ./builtin-json.d.ts (referenced
|
|
23
|
+
// above) so a source-linked consumer can disable them in linked mode.
|
|
33
24
|
|
|
34
25
|
interface Array<T> {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
// Conditional return instead of a `this`-typed overload: a `this` overload
|
|
27
|
+
// is selected-then-rejected on union-of-array receivers (TS2684), poisoning
|
|
28
|
+
// foreign code like `(readonly A[] | readonly B[]).map(...)`. A single
|
|
29
|
+
// conditional-return signature refines NonEmpty without a `this` param.
|
|
30
|
+
map<U>(
|
|
31
|
+
callbackfn: (value: T, index: number, array: T[]) => U,
|
|
32
|
+
thisArg?: any
|
|
33
|
+
): this extends NonEmptyArray<any> ? NonEmptyArray<U> : U[]
|
|
39
34
|
}
|
|
40
35
|
interface ReadonlyArray<T> {
|
|
41
36
|
// Subsequent property declarations must have the same type. Property 'length' must be of type 'number', but here has type 'NonNegativeInt'.
|
|
42
37
|
// readonly length: NonNegativeInt
|
|
43
38
|
|
|
44
|
-
map<
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
): NonEmptyReadonlyArray<
|
|
39
|
+
map<U>(
|
|
40
|
+
callbackfn: (value: T, index: number, array: readonly T[]) => U,
|
|
41
|
+
thisArg?: any
|
|
42
|
+
): this extends NonEmptyReadonlyArray<any> ? NonEmptyReadonlyArray<U> : U[]
|
|
48
43
|
}
|
|
49
44
|
}
|
|
50
45
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as Ref from "effect/Ref"
|
|
2
|
+
import * as Context from "../Context.ts"
|
|
3
|
+
import * as Effect from "../Effect.ts"
|
|
4
|
+
import type { InvalidationKey } from "../rpc/Invalidation.ts"
|
|
5
|
+
|
|
6
|
+
export type { InvalidationKey }
|
|
7
|
+
/** Shape of the per-mutation service that accumulates server-provided invalidation keys. */
|
|
8
|
+
export interface InvalidationKeysService {
|
|
9
|
+
readonly add: (key: InvalidationKey) => Effect.Effect<void>
|
|
10
|
+
readonly get: Effect.Effect<ReadonlyArray<InvalidationKey>>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Context.Reference that accumulates invalidation keys received from the server via the
|
|
15
|
+
* `x-invalidate` HTTP response header.
|
|
16
|
+
*
|
|
17
|
+
* The default is a no-op: when not explicitly provided (e.g. outside a mutation wrapper)
|
|
18
|
+
* all calls are ignored. The mutation wrapper in `@effect-app/vue` provides a real
|
|
19
|
+
* implementation backed by a `Ref`.
|
|
20
|
+
*/
|
|
21
|
+
export const InvalidationKeysFromServer = Context.Reference<InvalidationKeysService>(
|
|
22
|
+
"effect-app/client/InvalidationKeysFromServer",
|
|
23
|
+
{
|
|
24
|
+
defaultValue: () => ({
|
|
25
|
+
add: (_key: InvalidationKey) => Effect.void,
|
|
26
|
+
get: Effect.succeed([] as ReadonlyArray<InvalidationKey>)
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
export type InvalidationKeysFromServer = typeof InvalidationKeysFromServer
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a fresh `InvalidationKeysService` implementation backed by a `Ref`.
|
|
34
|
+
*
|
|
35
|
+
* @param ref - The `Ref` that stores the accumulated keys.
|
|
36
|
+
* @param onAdded - V3: Optional Effect run after a key is added. Use to trigger mid-stream
|
|
37
|
+
* query invalidation without waiting for the stream to complete.
|
|
38
|
+
*/
|
|
39
|
+
export const makeInvalidationKeysService = (
|
|
40
|
+
ref: Ref.Ref<ReadonlyArray<InvalidationKey>>,
|
|
41
|
+
onAdded?: (key: InvalidationKey) => Effect.Effect<void>
|
|
42
|
+
): InvalidationKeysService => ({
|
|
43
|
+
// When onAdded is set, fire it immediately without accumulating in the ref —
|
|
44
|
+
// the key is handled on arrival and must not be re-processed at stream end.
|
|
45
|
+
add: (key) =>
|
|
46
|
+
onAdded
|
|
47
|
+
? onAdded(key)
|
|
48
|
+
: Ref.update(ref, (keys) => [...keys, key]),
|
|
49
|
+
get: Ref.get(ref)
|
|
50
|
+
})
|