@reactionary/core 0.0.68 → 0.0.70
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/decorators/reactionary.decorator.js +50 -33
- package/index.js +10 -10
- package/package.json +1 -1
- package/schemas/mutations/checkout.mutation.js +1 -1
- package/schemas/queries/category.query.js +10 -10
- package/src/decorators/reactionary.decorator.d.ts +22 -3
- package/src/index.d.ts +2 -2
- package/src/schemas/queries/category.query.d.ts +10 -10
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
trace,
|
|
3
|
-
SpanKind
|
|
4
|
-
} from "@opentelemetry/api";
|
|
1
|
+
import { trace, SpanKind } from "@opentelemetry/api";
|
|
5
2
|
const TRACER_NAME = "@reactionary";
|
|
6
3
|
const TRACER_VERSION = "0.0.1";
|
|
7
4
|
let globalTracer = null;
|
|
@@ -36,7 +33,6 @@ class ReactionaryDecoratorOptions {
|
|
|
36
33
|
this.cacheTimeToLiveInSeconds = 60;
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
;
|
|
40
36
|
function Reactionary(options) {
|
|
41
37
|
return function(target, propertyKey, descriptor) {
|
|
42
38
|
const original = descriptor.value;
|
|
@@ -48,42 +44,63 @@ function Reactionary(options) {
|
|
|
48
44
|
);
|
|
49
45
|
}
|
|
50
46
|
descriptor.value = async function(...args) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
ttlSeconds: configuration.cacheTimeToLiveInSeconds,
|
|
64
|
-
dependencyIds
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
span.end();
|
|
68
|
-
if (!result) {
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
if (result instanceof Array) {
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
return this.assert(result);
|
|
47
|
+
return traceSpan(scope, async () => {
|
|
48
|
+
const input = validateInput(args[0], configuration.inputSchema);
|
|
49
|
+
const cacheKey = this.generateCacheKeyForQuery(scope, input);
|
|
50
|
+
const fromCache = await this.cache.get(cacheKey, this.schema);
|
|
51
|
+
let result = fromCache;
|
|
52
|
+
if (!result) {
|
|
53
|
+
result = await original.apply(this, [input]);
|
|
54
|
+
const dependencyIds = this.generateDependencyIdsForModel(result);
|
|
55
|
+
this.cache.put(cacheKey, result, {
|
|
56
|
+
ttlSeconds: configuration.cacheTimeToLiveInSeconds,
|
|
57
|
+
dependencyIds
|
|
58
|
+
});
|
|
75
59
|
}
|
|
76
|
-
|
|
60
|
+
return validateOutput(result, configuration.outputSchema);
|
|
61
|
+
});
|
|
77
62
|
};
|
|
78
63
|
return descriptor;
|
|
79
64
|
};
|
|
80
65
|
}
|
|
81
|
-
function validateInput() {
|
|
82
|
-
|
|
66
|
+
function validateInput(input, schema) {
|
|
67
|
+
if (!schema) {
|
|
68
|
+
return input;
|
|
69
|
+
}
|
|
70
|
+
const parsed = schema.parse(input);
|
|
71
|
+
return parsed;
|
|
72
|
+
}
|
|
73
|
+
function validateOutput(output, schema) {
|
|
74
|
+
if (!schema) {
|
|
75
|
+
return output;
|
|
76
|
+
}
|
|
77
|
+
const parsed = schema.parse(output);
|
|
78
|
+
return parsed;
|
|
79
|
+
}
|
|
80
|
+
async function traceSpan(name, fn) {
|
|
81
|
+
const tracer = getTracer();
|
|
82
|
+
return tracer.startActiveSpan(name, async (span) => {
|
|
83
|
+
try {
|
|
84
|
+
return fn();
|
|
85
|
+
} catch (err) {
|
|
86
|
+
if (err instanceof Error) {
|
|
87
|
+
span.recordException(err);
|
|
88
|
+
span.setStatus({ code: 2, message: err.message });
|
|
89
|
+
} else {
|
|
90
|
+
span.recordException({ message: String(err) });
|
|
91
|
+
span.setStatus({ code: 2, message: String(err) });
|
|
92
|
+
}
|
|
93
|
+
throw err;
|
|
94
|
+
} finally {
|
|
95
|
+
span.end();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
83
98
|
}
|
|
84
99
|
export {
|
|
85
100
|
Reactionary,
|
|
86
101
|
ReactionaryDecoratorOptions,
|
|
87
102
|
getTracer,
|
|
88
|
-
|
|
103
|
+
traceSpan,
|
|
104
|
+
validateInput,
|
|
105
|
+
validateOutput
|
|
89
106
|
};
|
package/index.js
CHANGED
|
@@ -140,11 +140,11 @@ import {
|
|
|
140
140
|
import {
|
|
141
141
|
BaseQuerySchema,
|
|
142
142
|
CartQueryByIdSchema,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
CategoryQueryByIdSchema,
|
|
144
|
+
CategoryQueryBySlugSchema,
|
|
145
|
+
CategoryQueryForBreadcrumbSchema,
|
|
146
|
+
CategoryQueryForChildCategoriesSchema,
|
|
147
|
+
CategoryQueryForTopCategoriesSchema,
|
|
148
148
|
CheckoutQueryByIdSchema,
|
|
149
149
|
CheckoutQueryForAvailablePaymentMethodsSchema,
|
|
150
150
|
CheckoutQueryForAvailableShippingMethodsSchema,
|
|
@@ -197,11 +197,11 @@ export {
|
|
|
197
197
|
CategoryIdentifierSchema,
|
|
198
198
|
CategoryPaginatedResultSchema,
|
|
199
199
|
CategoryProvider,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
CategoryQueryByIdSchema,
|
|
201
|
+
CategoryQueryBySlugSchema,
|
|
202
|
+
CategoryQueryForBreadcrumbSchema,
|
|
203
|
+
CategoryQueryForChildCategoriesSchema,
|
|
204
|
+
CategoryQueryForTopCategoriesSchema,
|
|
205
205
|
CategorySchema,
|
|
206
206
|
CheckoutIdentifierSchema,
|
|
207
207
|
CheckoutItemIdentifierSchema,
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@ const CheckoutMutationRemovePaymentInstructionSchema = BaseMutationSchema.extend
|
|
|
23
23
|
checkout: CartIdentifierSchema.required()
|
|
24
24
|
});
|
|
25
25
|
const CheckoutMutationSetShippingInstructionSchema = BaseMutationSchema.extend({
|
|
26
|
-
shippingInstruction: ShippingInstructionSchema.omit({ meta: true
|
|
26
|
+
shippingInstruction: ShippingInstructionSchema.omit({ meta: true }).required(),
|
|
27
27
|
checkout: CartIdentifierSchema.required()
|
|
28
28
|
});
|
|
29
29
|
export {
|
|
@@ -2,26 +2,26 @@ import { z } from "zod";
|
|
|
2
2
|
import { CategoryIdentifierSchema } from "../models/identifiers.model.js";
|
|
3
3
|
import { BaseQuerySchema } from "./base.query.js";
|
|
4
4
|
import { PaginationOptionsSchema } from "../models/base.model.js";
|
|
5
|
-
const
|
|
5
|
+
const CategoryQueryByIdSchema = BaseQuerySchema.extend({
|
|
6
6
|
id: CategoryIdentifierSchema.default(() => CategoryIdentifierSchema.parse({}))
|
|
7
7
|
});
|
|
8
|
-
const
|
|
8
|
+
const CategoryQueryBySlugSchema = BaseQuerySchema.extend({
|
|
9
9
|
slug: z.string().default("")
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const CategoryQueryForBreadcrumbSchema = BaseQuerySchema.extend({
|
|
12
12
|
id: CategoryIdentifierSchema.default(() => CategoryIdentifierSchema.parse({}))
|
|
13
13
|
});
|
|
14
|
-
const
|
|
14
|
+
const CategoryQueryForChildCategoriesSchema = BaseQuerySchema.extend({
|
|
15
15
|
parentId: CategoryIdentifierSchema.default(() => CategoryIdentifierSchema.parse({})),
|
|
16
16
|
paginationOptions: PaginationOptionsSchema.default(() => PaginationOptionsSchema.parse({}))
|
|
17
17
|
});
|
|
18
|
-
const
|
|
18
|
+
const CategoryQueryForTopCategoriesSchema = BaseQuerySchema.extend({
|
|
19
19
|
paginationOptions: PaginationOptionsSchema.default(() => PaginationOptionsSchema.parse({}))
|
|
20
20
|
});
|
|
21
21
|
export {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
CategoryQueryByIdSchema,
|
|
23
|
+
CategoryQueryBySlugSchema,
|
|
24
|
+
CategoryQueryForBreadcrumbSchema,
|
|
25
|
+
CategoryQueryForChildCategoriesSchema,
|
|
26
|
+
CategoryQueryForTopCategoriesSchema
|
|
27
27
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BaseProvider } from '../providers/index.js';
|
|
2
2
|
import type { Tracer } from '@opentelemetry/api';
|
|
3
|
+
import type { z } from 'zod';
|
|
3
4
|
export declare function getTracer(): Tracer;
|
|
4
5
|
/**
|
|
5
6
|
* The options associated with annotating a provider function and marking
|
|
@@ -27,8 +28,14 @@ export declare class ReactionaryDecoratorOptions {
|
|
|
27
28
|
* given query.
|
|
28
29
|
*/
|
|
29
30
|
cacheTimeToLiveInSeconds: number;
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The schema for the input (query or mutation) type, for validation purposes
|
|
33
|
+
*/
|
|
34
|
+
inputSchema?: z.ZodType;
|
|
35
|
+
/**
|
|
36
|
+
* The schema for the primary output type, for validation purposes
|
|
37
|
+
*/
|
|
38
|
+
outputSchema?: z.ZodType;
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
41
|
* Decorator for provider functions to provide functionality such as caching, tracing and type-checked
|
|
@@ -36,4 +43,16 @@ export declare class ReactionaryDecoratorOptions {
|
|
|
36
43
|
* providers.
|
|
37
44
|
*/
|
|
38
45
|
export declare function Reactionary(options: Partial<ReactionaryDecoratorOptions>): (target: BaseProvider, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
39
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Utility function to handle input validation.
|
|
48
|
+
*/
|
|
49
|
+
export declare function validateInput(input: any, schema: z.ZodType | undefined): any;
|
|
50
|
+
/**
|
|
51
|
+
* Utility function to handle output validation.
|
|
52
|
+
*/
|
|
53
|
+
export declare function validateOutput(output: any, schema: z.ZodType | undefined): any;
|
|
54
|
+
/**
|
|
55
|
+
* Utility function to wrap entry / exit into decorated functions in a
|
|
56
|
+
* traced span for OTEL handling.
|
|
57
|
+
*/
|
|
58
|
+
export declare function traceSpan<T>(name: string, fn: () => Promise<T> | T): Promise<T>;
|
package/src/index.d.ts
CHANGED
|
@@ -12,6 +12,6 @@ export { AddressIdentifierSchema, AddressSchema, AnalyticsEventSchema, Anonymous
|
|
|
12
12
|
export type { Address, AddressIdentifier, AnalyticsEvent, AnonymousIdentity, BaseModel, CacheInformation, Cart, CartIdentifier, CartItem, CartItemIdentifier, Category, CategoryIdentifier, CategoryPaginatedResult, Checkout, CheckoutIdentifier, CheckoutItem, CheckoutItemIdentifier, CostBreakDown, Currency, FacetIdentifier, FacetValueIdentifier, FulfillmentCenterIdentifier, GuestIdentity, IdentifierType, Identity, IdentityIdentifier, Image, Inventory, InventoryIdentifier, ItemCostBreakdown, Meta, MonetaryAmount, Order, OrderIdentifier, OrderItem, OrderItemIdentifier, PaginationOptions, PaymentInstruction, PaymentInstructionIdentifier, PaymentMethod, PaymentMethodIdentifier, PaymentStatus, PickupPoint, PickupPointIdentifier, Price, PriceIdentifier, Product, ProductAttribute, ProductAttributeIdentifier, ProductAttributeValue, ProductAttributeValueIdentifier, ProductIdentifier, ProductOption, ProductOptionIdentifier, ProductOptionValue, ProductOptionValueIdentifier, ProductSearchResult, ProductSearchResultFacet, ProductSearchResultFacetValue, ProductSearchResultItem, ProductSearchResultItemVariant, ProductVariant, ProductVariantIdentifier, ProductVariantOption, Profile, RegisteredIdentity, SearchIdentifier, ShippingInstruction, ShippingMethod, ShippingMethodIdentifier, Store, StoreIdentifier, TieredPrice, WebStoreIdentifier, } from './schemas/models/index.js';
|
|
13
13
|
export { AnalyticsMutationSchema, AnalyticsMutationSearchEventSchema, AnalyticsMutationSearchProductClickEventSchema, BaseMutationSchema, CartMutationAddPaymentMethodSchema, CartMutationApplyCouponSchema, CartMutationChangeCurrencySchema, CartMutationCheckoutSchema, CartMutationDeleteCartSchema, CartMutationItemAddSchema, CartMutationItemQuantityChangeSchema, CartMutationItemRemoveSchema, CartMutationRemoveCouponSchema, CartMutationRemovePaymentMethodSchema, CartMutationSetBillingAddressSchema, CartMutationSetShippingInfoSchema, CheckoutMutationAddPaymentInstructionSchema, CheckoutMutationFinalizeCheckoutSchema, CheckoutMutationInitiateCheckoutSchema, CheckoutMutationRemovePaymentInstructionSchema, CheckoutMutationSetShippingAddressSchema, CheckoutMutationSetShippingInstructionSchema, IdentityMutationLoginSchema, IdentityMutationLogoutSchema, IdentityMutationRegisterSchema, ProfileMutationUpdateSchema, } from './schemas/mutations/index.js';
|
|
14
14
|
export type { AnalyticsMutation, AnalyticsMutationSearchEvent, AnalyticsMutationSearchProductClickEvent, BaseMutation, CartMutationAddPaymentMethod, CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationCheckout, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartMutationRemovePaymentMethod, CartMutationSetBillingAddress, CartMutationSetShippingInfo, CheckoutMutationAddPaymentInstruction, CheckoutMutationFinalizeCheckout, CheckoutMutationInitiateCheckout, CheckoutMutationRemovePaymentInstruction, CheckoutMutationSetShippingAddress, CheckoutMutationSetShippingInstruction, IdentityMutationLogin, IdentityMutationLogout, IdentityMutationRegister, ProfileMutationUpdate, } from './schemas/mutations/index.js';
|
|
15
|
-
export { BaseQuerySchema, CartQueryByIdSchema,
|
|
16
|
-
export type { BaseQuery, CartQueryById, CheckoutQueryById, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods, IdentityQuerySelf, InventoryQueryBySKU, OrderQueryById, PriceQueryBySku, ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, ProductQueryVariants, ProductSearchQueryByTerm, ProfileQuerySelf, StoreQueryByProximity, } from './schemas/queries/index.js';
|
|
15
|
+
export { BaseQuerySchema, CartQueryByIdSchema, CategoryQueryByIdSchema, CategoryQueryBySlugSchema, CategoryQueryForBreadcrumbSchema, CategoryQueryForChildCategoriesSchema, CategoryQueryForTopCategoriesSchema, CheckoutQueryByIdSchema, CheckoutQueryForAvailablePaymentMethodsSchema, CheckoutQueryForAvailableShippingMethodsSchema, IdentityQuerySelfSchema, InventoryQueryBySKUSchema, OrderQueryByIdSchema, PriceQueryBySkuSchema, ProductQueryByIdSchema, ProductQueryBySKUSchema, ProductQueryBySlugSchema, ProductQueryVariantsSchema, ProductSearchQueryByTermSchema, ProfileQuerySelfSchema, StoreQueryByProximitySchema, } from './schemas/queries/index.js';
|
|
16
|
+
export type { BaseQuery, CartQueryById, CheckoutQueryById, CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods, IdentityQuerySelf, InventoryQueryBySKU, OrderQueryById, PriceQueryBySku, ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, ProductQueryVariants, ProductSearchQueryByTerm, ProfileQuerySelf, StoreQueryByProximity, } from './schemas/queries/index.js';
|
|
17
17
|
export { createInitialRequestContext } from './initialization.js';
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const CategoryQueryByIdSchema: z.ZodObject<{
|
|
3
3
|
id: z.ZodDefault<z.ZodObject<{
|
|
4
4
|
key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
|
|
5
5
|
}, z.core.$loose>>;
|
|
6
6
|
}, z.core.$loose>;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const CategoryQueryBySlugSchema: z.ZodObject<{
|
|
8
8
|
slug: z.ZodDefault<z.ZodString>;
|
|
9
9
|
}, z.core.$loose>;
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const CategoryQueryForBreadcrumbSchema: z.ZodObject<{
|
|
11
11
|
id: z.ZodDefault<z.ZodObject<{
|
|
12
12
|
key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
|
|
13
13
|
}, z.core.$loose>>;
|
|
14
14
|
}, z.core.$loose>;
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const CategoryQueryForChildCategoriesSchema: z.ZodObject<{
|
|
16
16
|
parentId: z.ZodDefault<z.ZodObject<{
|
|
17
17
|
key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
|
|
18
18
|
}, z.core.$loose>>;
|
|
@@ -21,14 +21,14 @@ export declare const CategoryQueryForChildCategories: z.ZodObject<{
|
|
|
21
21
|
pageSize: z.ZodDefault<z.ZodNumber>;
|
|
22
22
|
}, z.core.$loose>>;
|
|
23
23
|
}, z.core.$loose>;
|
|
24
|
-
export declare const
|
|
24
|
+
export declare const CategoryQueryForTopCategoriesSchema: z.ZodObject<{
|
|
25
25
|
paginationOptions: z.ZodDefault<z.ZodObject<{
|
|
26
26
|
pageNumber: z.ZodDefault<z.ZodNumber>;
|
|
27
27
|
pageSize: z.ZodDefault<z.ZodNumber>;
|
|
28
28
|
}, z.core.$loose>>;
|
|
29
29
|
}, z.core.$loose>;
|
|
30
|
-
export type CategoryQueryById = z.infer<typeof
|
|
31
|
-
export type CategoryQueryBySlug = z.infer<typeof
|
|
32
|
-
export type CategoryQueryForBreadcrumb = z.infer<typeof
|
|
33
|
-
export type CategoryQueryForChildCategories = z.infer<typeof
|
|
34
|
-
export type CategoryQueryForTopCategories = z.infer<typeof
|
|
30
|
+
export type CategoryQueryById = z.infer<typeof CategoryQueryByIdSchema>;
|
|
31
|
+
export type CategoryQueryBySlug = z.infer<typeof CategoryQueryBySlugSchema>;
|
|
32
|
+
export type CategoryQueryForBreadcrumb = z.infer<typeof CategoryQueryForBreadcrumbSchema>;
|
|
33
|
+
export type CategoryQueryForChildCategories = z.infer<typeof CategoryQueryForChildCategoriesSchema>;
|
|
34
|
+
export type CategoryQueryForTopCategories = z.infer<typeof CategoryQueryForTopCategoriesSchema>;
|