@reactionary/core 0.0.64 → 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.
@@ -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 context = this.context || RequestContextSchema.parse({
34
- languageContext: {
35
- locale: "en-US",
36
- currencyCode: "USD",
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
@@ -78,8 +78,12 @@ function Reactionary(options) {
78
78
  return descriptor;
79
79
  };
80
80
  }
81
+ function validateInput() {
82
+ console.log("foo");
83
+ }
81
84
  export {
82
85
  Reactionary,
83
86
  ReactionaryDecoratorOptions,
84
- getTracer
87
+ getTracer,
88
+ validateInput
85
89
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/core",
3
- "version": "0.0.64",
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
  }
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  createPaginatedResponseSchema
3
3
  } from "../schemas/models/base.model.js";
4
+ import {} from "../schemas/session.schema.js";
4
5
  import { hasher } from "node-object-hash";
5
6
  class BaseProvider {
6
7
  constructor(schema, cache, context) {
@@ -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 { RequestContext } from '../schemas/session.schema.js';
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)