@reactionary/core 0.0.32 → 0.0.34

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.
Files changed (45) hide show
  1. package/cache/cache-evaluation.interface.js +0 -0
  2. package/cache/cache.interface.js +0 -0
  3. package/cache/noop-cache.js +27 -0
  4. package/cache/redis-cache.js +60 -0
  5. package/client/client-builder.js +44 -0
  6. package/client/client.js +29 -0
  7. package/decorators/trpc.decorators.js +66 -0
  8. package/index.js +40 -764
  9. package/package.json +1 -1
  10. package/providers/analytics.provider.js +6 -0
  11. package/providers/base.provider.js +30 -0
  12. package/providers/cart.provider.js +6 -0
  13. package/providers/identity.provider.js +6 -0
  14. package/providers/inventory.provider.js +6 -0
  15. package/providers/price.provider.js +6 -0
  16. package/providers/product.provider.js +6 -0
  17. package/providers/search.provider.js +6 -0
  18. package/schemas/capabilities.schema.js +13 -0
  19. package/schemas/models/analytics.model.js +5 -0
  20. package/schemas/models/base.model.js +17 -0
  21. package/schemas/models/cart.model.js +16 -0
  22. package/schemas/models/currency.model.js +187 -0
  23. package/schemas/models/identifiers.model.js +39 -0
  24. package/schemas/models/identity.model.js +14 -0
  25. package/schemas/models/inventory.model.js +8 -0
  26. package/schemas/models/price.model.js +16 -0
  27. package/schemas/models/product.model.js +26 -0
  28. package/schemas/models/search.model.js +32 -0
  29. package/schemas/mutations/analytics.mutation.js +20 -0
  30. package/schemas/mutations/base.mutation.js +5 -0
  31. package/schemas/mutations/cart.mutation.js +22 -0
  32. package/schemas/mutations/identity.mutation.js +11 -0
  33. package/schemas/mutations/inventory.mutation.js +5 -0
  34. package/schemas/mutations/price.mutation.js +5 -0
  35. package/schemas/mutations/product.mutation.js +5 -0
  36. package/schemas/mutations/search.mutation.js +5 -0
  37. package/schemas/queries/analytics.query.js +5 -0
  38. package/schemas/queries/base.query.js +5 -0
  39. package/schemas/queries/cart.query.js +11 -0
  40. package/schemas/queries/identity.query.js +5 -0
  41. package/schemas/queries/inventory.query.js +8 -0
  42. package/schemas/queries/price.query.js +8 -0
  43. package/schemas/queries/product.query.js +12 -0
  44. package/schemas/queries/search.query.js +8 -0
  45. package/schemas/session.schema.js +9 -0
File without changes
File without changes
@@ -0,0 +1,27 @@
1
+ class NoOpCache {
2
+ async get(_key, _schema) {
3
+ return null;
4
+ }
5
+ async put(_key, _value, _ttlSeconds) {
6
+ return;
7
+ }
8
+ async del(_keys) {
9
+ return;
10
+ }
11
+ async keys(_pattern) {
12
+ return [];
13
+ }
14
+ async clear(_pattern) {
15
+ return;
16
+ }
17
+ async getStats() {
18
+ return {
19
+ hits: 0,
20
+ misses: 0,
21
+ size: 0
22
+ };
23
+ }
24
+ }
25
+ export {
26
+ NoOpCache
27
+ };
@@ -0,0 +1,60 @@
1
+ import { Redis } from "@upstash/redis";
2
+ class RedisCache {
3
+ constructor() {
4
+ this.redis = Redis.fromEnv();
5
+ }
6
+ async get(key, schema) {
7
+ if (!key) {
8
+ return null;
9
+ }
10
+ const unvalidated = await this.redis.get(key);
11
+ const parsed = schema.safeParse(unvalidated);
12
+ if (parsed.success) {
13
+ return parsed.data;
14
+ }
15
+ return null;
16
+ }
17
+ async put(key, value, ttlSeconds) {
18
+ if (!key) {
19
+ return;
20
+ }
21
+ const options = ttlSeconds ? { ex: ttlSeconds } : void 0;
22
+ await this.redis.set(key, value, options);
23
+ }
24
+ async del(keys) {
25
+ const keyArray = Array.isArray(keys) ? keys : [keys];
26
+ for (const key of keyArray) {
27
+ if (key.includes("*")) {
28
+ const matchingKeys = await this.redis.keys(key);
29
+ if (matchingKeys.length > 0) {
30
+ await this.redis.del(...matchingKeys);
31
+ }
32
+ } else {
33
+ await this.redis.del(key);
34
+ }
35
+ }
36
+ }
37
+ async keys(pattern) {
38
+ return await this.redis.keys(pattern);
39
+ }
40
+ async clear(pattern) {
41
+ const searchPattern = pattern || "*";
42
+ const keys = await this.redis.keys(searchPattern);
43
+ if (keys.length > 0) {
44
+ await this.redis.del(...keys);
45
+ }
46
+ }
47
+ async getStats() {
48
+ const keys = await this.redis.keys("*");
49
+ return {
50
+ hits: 0,
51
+ // Would need to track this separately
52
+ misses: 0,
53
+ // Would need to track this separately
54
+ size: keys.length
55
+ };
56
+ }
57
+ }
58
+ export {
59
+ RedisCache
60
+ };
@@ -0,0 +1,44 @@
1
+ import { NoOpCache } from "../cache/noop-cache";
2
+ class ClientBuilder {
3
+ constructor() {
4
+ this.factories = [];
5
+ }
6
+ withCapability(factory) {
7
+ const newBuilder = new ClientBuilder();
8
+ newBuilder.factories = [...this.factories, factory];
9
+ newBuilder.cache = this.cache;
10
+ return newBuilder;
11
+ }
12
+ withCache(cache) {
13
+ const newBuilder = new ClientBuilder();
14
+ newBuilder.factories = [...this.factories];
15
+ newBuilder.cache = cache;
16
+ return newBuilder;
17
+ }
18
+ build() {
19
+ let client = {};
20
+ const sharedCache = this.cache || new NoOpCache();
21
+ const mergedAnalytics = [];
22
+ for (const factory of this.factories) {
23
+ const provider = factory(sharedCache);
24
+ client = {
25
+ ...client,
26
+ ...provider
27
+ };
28
+ if (provider.analytics) {
29
+ mergedAnalytics.push(...provider.analytics);
30
+ }
31
+ }
32
+ if (mergedAnalytics.length > 0) {
33
+ client["analytics"] = mergedAnalytics;
34
+ }
35
+ const completeClient = {
36
+ ...client,
37
+ cache: sharedCache
38
+ };
39
+ return completeClient;
40
+ }
41
+ }
42
+ export {
43
+ ClientBuilder
44
+ };
@@ -0,0 +1,29 @@
1
+ import { RedisCache } from "../cache/redis-cache";
2
+ function buildClient(providerFactories, options = {}) {
3
+ let client = {};
4
+ const sharedCache = options.cache || new RedisCache();
5
+ const mergedAnalytics = [];
6
+ for (const factory of providerFactories) {
7
+ const provider = factory(sharedCache);
8
+ client = {
9
+ ...client,
10
+ ...provider
11
+ };
12
+ if (provider.analytics) {
13
+ mergedAnalytics.push(...provider.analytics);
14
+ }
15
+ }
16
+ client.analytics = mergedAnalytics;
17
+ const completeClient = {
18
+ ...client,
19
+ cache: sharedCache
20
+ };
21
+ return completeClient;
22
+ }
23
+ function createCache() {
24
+ return new RedisCache();
25
+ }
26
+ export {
27
+ buildClient,
28
+ createCache
29
+ };
@@ -0,0 +1,66 @@
1
+ import "reflect-metadata";
2
+ const TRPC_QUERY_METADATA_KEY = Symbol("trpc:query");
3
+ const TRPC_MUTATION_METADATA_KEY = Symbol("trpc:mutation");
4
+ function trpcQuery(options = {}) {
5
+ return function(target, propertyKey, descriptor) {
6
+ const metadata = {
7
+ methodName: String(propertyKey),
8
+ isQuery: true,
9
+ isMutation: false,
10
+ options
11
+ };
12
+ Reflect.defineMetadata(TRPC_QUERY_METADATA_KEY, metadata, target, propertyKey);
13
+ const existingMethods = Reflect.getMetadata(TRPC_QUERY_METADATA_KEY, target.constructor) || [];
14
+ existingMethods.push({ propertyKey, metadata });
15
+ Reflect.defineMetadata(TRPC_QUERY_METADATA_KEY, existingMethods, target.constructor);
16
+ };
17
+ }
18
+ function trpcMutation(options = {}) {
19
+ return function(target, propertyKey, descriptor) {
20
+ const metadata = {
21
+ methodName: String(propertyKey),
22
+ isQuery: false,
23
+ isMutation: true,
24
+ options
25
+ };
26
+ Reflect.defineMetadata(TRPC_MUTATION_METADATA_KEY, metadata, target, propertyKey);
27
+ const existingMethods = Reflect.getMetadata(TRPC_MUTATION_METADATA_KEY, target.constructor) || [];
28
+ existingMethods.push({ propertyKey, metadata });
29
+ Reflect.defineMetadata(TRPC_MUTATION_METADATA_KEY, existingMethods, target.constructor);
30
+ };
31
+ }
32
+ function getTRPCQueryMethods(target) {
33
+ const constructor = typeof target === "function" ? target : target.constructor;
34
+ return Reflect.getMetadata(TRPC_QUERY_METADATA_KEY, constructor) || [];
35
+ }
36
+ function getTRPCMutationMethods(target) {
37
+ const constructor = typeof target === "function" ? target : target.constructor;
38
+ return Reflect.getMetadata(TRPC_MUTATION_METADATA_KEY, constructor) || [];
39
+ }
40
+ function getAllTRPCMethods(target) {
41
+ return [
42
+ ...getTRPCQueryMethods(target),
43
+ ...getTRPCMutationMethods(target)
44
+ ];
45
+ }
46
+ function isTRPCQuery(target, methodName) {
47
+ return !!Reflect.getMetadata(TRPC_QUERY_METADATA_KEY, target, methodName);
48
+ }
49
+ function isTRPCMutation(target, methodName) {
50
+ return !!Reflect.getMetadata(TRPC_MUTATION_METADATA_KEY, target, methodName);
51
+ }
52
+ function isTRPCMethod(target, methodName) {
53
+ return isTRPCQuery(target, methodName) || isTRPCMutation(target, methodName);
54
+ }
55
+ export {
56
+ TRPC_MUTATION_METADATA_KEY,
57
+ TRPC_QUERY_METADATA_KEY,
58
+ getAllTRPCMethods,
59
+ getTRPCMutationMethods,
60
+ getTRPCQueryMethods,
61
+ isTRPCMethod,
62
+ isTRPCMutation,
63
+ isTRPCQuery,
64
+ trpcMutation,
65
+ trpcQuery
66
+ };