@reactionary/core 0.0.65 → 0.0.66
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/client/client-builder.js +9 -18
- package/decorators/reactionary.decorator.js +5 -1
- package/package.json +3 -2
- package/providers/base.provider.js +1 -0
- package/src/client/client-builder.d.ts +1 -1
- package/src/decorators/reactionary.decorator.d.ts +3 -0
- package/src/providers/base.provider.d.ts +1 -1
package/client/client-builder.js
CHANGED
|
@@ -3,43 +3,34 @@ import {
|
|
|
3
3
|
RequestContextSchema
|
|
4
4
|
} from "../schemas/session.schema.js";
|
|
5
5
|
class ClientBuilder {
|
|
6
|
-
constructor() {
|
|
6
|
+
constructor(context) {
|
|
7
7
|
this.factories = [];
|
|
8
|
+
this.context = context;
|
|
8
9
|
}
|
|
9
10
|
withCapability(factory) {
|
|
10
|
-
const newBuilder = new ClientBuilder();
|
|
11
|
+
const newBuilder = new ClientBuilder(this.context);
|
|
11
12
|
newBuilder.factories = [...this.factories, factory];
|
|
12
13
|
newBuilder.cache = this.cache;
|
|
13
14
|
newBuilder.context = this.context;
|
|
14
15
|
return newBuilder;
|
|
15
16
|
}
|
|
16
17
|
withCache(cache) {
|
|
17
|
-
const newBuilder = new ClientBuilder();
|
|
18
|
+
const newBuilder = new ClientBuilder(this.context);
|
|
18
19
|
newBuilder.factories = [...this.factories];
|
|
19
20
|
newBuilder.cache = cache;
|
|
20
21
|
newBuilder.context = this.context;
|
|
21
22
|
return newBuilder;
|
|
22
23
|
}
|
|
23
|
-
withContext(context) {
|
|
24
|
-
const newBuilder = new ClientBuilder();
|
|
25
|
-
newBuilder.factories = [...this.factories];
|
|
26
|
-
newBuilder.cache = this.cache;
|
|
27
|
-
newBuilder.context = context;
|
|
28
|
-
return newBuilder;
|
|
29
|
-
}
|
|
30
24
|
build() {
|
|
31
25
|
let client = {};
|
|
32
26
|
const sharedCache = this.cache || new NoOpCache();
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
countryCode: "US"
|
|
38
|
-
}
|
|
39
|
-
});
|
|
27
|
+
const validatedContext = RequestContextSchema.safeParse(this.context);
|
|
28
|
+
if (!validatedContext.success) {
|
|
29
|
+
throw new Error("Invalid context: " + validatedContext.error);
|
|
30
|
+
}
|
|
40
31
|
const mergedAnalytics = [];
|
|
41
32
|
for (const factory of this.factories) {
|
|
42
|
-
const provider = factory(sharedCache, context);
|
|
33
|
+
const provider = factory(sharedCache, this.context);
|
|
43
34
|
client = {
|
|
44
35
|
...client,
|
|
45
36
|
...provider
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -9,5 +9,6 @@
|
|
|
9
9
|
"node-object-hash": "^3.1.1",
|
|
10
10
|
"@opentelemetry/api": "^1.9.0"
|
|
11
11
|
},
|
|
12
|
-
"type": "module"
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false
|
|
13
14
|
}
|
|
@@ -7,9 +7,9 @@ export declare class ClientBuilder<TClient = object> {
|
|
|
7
7
|
private factories;
|
|
8
8
|
private cache;
|
|
9
9
|
private context;
|
|
10
|
+
constructor(context: RequestContext);
|
|
10
11
|
withCapability<TNew extends Partial<Client>>(factory: CapabilityFactory<TNew>): ClientBuilder<MergeCapabilities<TClient, TNew>>;
|
|
11
12
|
withCache(cache: Cache): ClientBuilder<TClient>;
|
|
12
|
-
withContext(context: RequestContext): ClientBuilder<TClient>;
|
|
13
13
|
build(): TClient & {
|
|
14
14
|
cache: Cache;
|
|
15
15
|
};
|
|
@@ -27,6 +27,8 @@ export declare class ReactionaryDecoratorOptions {
|
|
|
27
27
|
* given query.
|
|
28
28
|
*/
|
|
29
29
|
cacheTimeToLiveInSeconds: number;
|
|
30
|
+
inputSchema?: any;
|
|
31
|
+
outputSchema?: any;
|
|
30
32
|
}
|
|
31
33
|
/**
|
|
32
34
|
* Decorator for provider functions to provide functionality such as caching, tracing and type-checked
|
|
@@ -34,3 +36,4 @@ export declare class ReactionaryDecoratorOptions {
|
|
|
34
36
|
* providers.
|
|
35
37
|
*/
|
|
36
38
|
export declare function Reactionary(options: Partial<ReactionaryDecoratorOptions>): (target: BaseProvider, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
39
|
+
export declare function validateInput(): void;
|
|
@@ -2,7 +2,7 @@ import type { z } from 'zod';
|
|
|
2
2
|
import type { BaseModel } from '../schemas/models/base.model.js';
|
|
3
3
|
import { createPaginatedResponseSchema } from '../schemas/models/base.model.js';
|
|
4
4
|
import type { Cache } from '../cache/cache.interface.js';
|
|
5
|
-
import type
|
|
5
|
+
import { type RequestContext } from '../schemas/session.schema.js';
|
|
6
6
|
import type { IdentifierType } from '../schemas/models/identifiers.model.js';
|
|
7
7
|
/**
|
|
8
8
|
* Base capability provider, responsible for mutations (changes) and queries (fetches)
|