@voyantjs/markets 0.2.0 → 0.3.1
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/dist/service-core.d.ts +253 -0
- package/dist/service-core.d.ts.map +1 -0
- package/dist/service-core.js +242 -0
- package/dist/service-rules.d.ts +191 -0
- package/dist/service-rules.d.ts.map +1 -0
- package/dist/service-rules.js +155 -0
- package/dist/service-shared.d.ts +36 -0
- package/dist/service-shared.d.ts.map +1 -0
- package/dist/service-shared.js +7 -0
- package/dist/service.d.ts +40 -456
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +40 -401
- package/package.json +6 -4
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { and, asc, eq, sql } from "drizzle-orm";
|
|
2
|
+
import { marketChannelRules, marketPriceCatalogs, marketProductRules, markets } from "./schema.js";
|
|
3
|
+
import { paginate } from "./service-shared.js";
|
|
4
|
+
async function marketExists(db, marketId) {
|
|
5
|
+
const [market] = await db
|
|
6
|
+
.select({ id: markets.id })
|
|
7
|
+
.from(markets)
|
|
8
|
+
.where(eq(markets.id, marketId))
|
|
9
|
+
.limit(1);
|
|
10
|
+
return market ?? null;
|
|
11
|
+
}
|
|
12
|
+
export async function listMarketPriceCatalogs(db, query) {
|
|
13
|
+
const conditions = [];
|
|
14
|
+
if (query.marketId)
|
|
15
|
+
conditions.push(eq(marketPriceCatalogs.marketId, query.marketId));
|
|
16
|
+
if (query.priceCatalogId)
|
|
17
|
+
conditions.push(eq(marketPriceCatalogs.priceCatalogId, query.priceCatalogId));
|
|
18
|
+
if (query.active !== undefined)
|
|
19
|
+
conditions.push(eq(marketPriceCatalogs.active, query.active));
|
|
20
|
+
const where = conditions.length > 0 ? and(...conditions) : undefined;
|
|
21
|
+
return paginate(db
|
|
22
|
+
.select()
|
|
23
|
+
.from(marketPriceCatalogs)
|
|
24
|
+
.where(where)
|
|
25
|
+
.limit(query.limit)
|
|
26
|
+
.offset(query.offset)
|
|
27
|
+
.orderBy(asc(marketPriceCatalogs.createdAt)), db.select({ count: sql `count(*)::int` }).from(marketPriceCatalogs).where(where), query.limit, query.offset);
|
|
28
|
+
}
|
|
29
|
+
export async function getMarketPriceCatalogById(db, id) {
|
|
30
|
+
const [row] = await db
|
|
31
|
+
.select()
|
|
32
|
+
.from(marketPriceCatalogs)
|
|
33
|
+
.where(eq(marketPriceCatalogs.id, id))
|
|
34
|
+
.limit(1);
|
|
35
|
+
return row ?? null;
|
|
36
|
+
}
|
|
37
|
+
export async function createMarketPriceCatalog(db, data) {
|
|
38
|
+
if (!(await marketExists(db, data.marketId)))
|
|
39
|
+
return null;
|
|
40
|
+
const [row] = await db.insert(marketPriceCatalogs).values(data).returning();
|
|
41
|
+
return row ?? null;
|
|
42
|
+
}
|
|
43
|
+
export async function updateMarketPriceCatalog(db, id, data) {
|
|
44
|
+
const [row] = await db
|
|
45
|
+
.update(marketPriceCatalogs)
|
|
46
|
+
.set({ ...data, updatedAt: new Date() })
|
|
47
|
+
.where(eq(marketPriceCatalogs.id, id))
|
|
48
|
+
.returning();
|
|
49
|
+
return row ?? null;
|
|
50
|
+
}
|
|
51
|
+
export async function deleteMarketPriceCatalog(db, id) {
|
|
52
|
+
const [row] = await db
|
|
53
|
+
.delete(marketPriceCatalogs)
|
|
54
|
+
.where(eq(marketPriceCatalogs.id, id))
|
|
55
|
+
.returning({ id: marketPriceCatalogs.id });
|
|
56
|
+
return row ?? null;
|
|
57
|
+
}
|
|
58
|
+
export async function listMarketProductRules(db, query) {
|
|
59
|
+
const conditions = [];
|
|
60
|
+
if (query.marketId)
|
|
61
|
+
conditions.push(eq(marketProductRules.marketId, query.marketId));
|
|
62
|
+
if (query.productId)
|
|
63
|
+
conditions.push(eq(marketProductRules.productId, query.productId));
|
|
64
|
+
if (query.optionId)
|
|
65
|
+
conditions.push(eq(marketProductRules.optionId, query.optionId));
|
|
66
|
+
if (query.sellability)
|
|
67
|
+
conditions.push(eq(marketProductRules.sellability, query.sellability));
|
|
68
|
+
if (query.active !== undefined)
|
|
69
|
+
conditions.push(eq(marketProductRules.active, query.active));
|
|
70
|
+
const where = conditions.length > 0 ? and(...conditions) : undefined;
|
|
71
|
+
return paginate(db
|
|
72
|
+
.select()
|
|
73
|
+
.from(marketProductRules)
|
|
74
|
+
.where(where)
|
|
75
|
+
.limit(query.limit)
|
|
76
|
+
.offset(query.offset)
|
|
77
|
+
.orderBy(asc(marketProductRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(marketProductRules).where(where), query.limit, query.offset);
|
|
78
|
+
}
|
|
79
|
+
export async function getMarketProductRuleById(db, id) {
|
|
80
|
+
const [row] = await db
|
|
81
|
+
.select()
|
|
82
|
+
.from(marketProductRules)
|
|
83
|
+
.where(eq(marketProductRules.id, id))
|
|
84
|
+
.limit(1);
|
|
85
|
+
return row ?? null;
|
|
86
|
+
}
|
|
87
|
+
export async function createMarketProductRule(db, data) {
|
|
88
|
+
if (!(await marketExists(db, data.marketId)))
|
|
89
|
+
return null;
|
|
90
|
+
const [row] = await db.insert(marketProductRules).values(data).returning();
|
|
91
|
+
return row ?? null;
|
|
92
|
+
}
|
|
93
|
+
export async function updateMarketProductRule(db, id, data) {
|
|
94
|
+
const [row] = await db
|
|
95
|
+
.update(marketProductRules)
|
|
96
|
+
.set({ ...data, updatedAt: new Date() })
|
|
97
|
+
.where(eq(marketProductRules.id, id))
|
|
98
|
+
.returning();
|
|
99
|
+
return row ?? null;
|
|
100
|
+
}
|
|
101
|
+
export async function deleteMarketProductRule(db, id) {
|
|
102
|
+
const [row] = await db
|
|
103
|
+
.delete(marketProductRules)
|
|
104
|
+
.where(eq(marketProductRules.id, id))
|
|
105
|
+
.returning({ id: marketProductRules.id });
|
|
106
|
+
return row ?? null;
|
|
107
|
+
}
|
|
108
|
+
export async function listMarketChannelRules(db, query) {
|
|
109
|
+
const conditions = [];
|
|
110
|
+
if (query.marketId)
|
|
111
|
+
conditions.push(eq(marketChannelRules.marketId, query.marketId));
|
|
112
|
+
if (query.channelId)
|
|
113
|
+
conditions.push(eq(marketChannelRules.channelId, query.channelId));
|
|
114
|
+
if (query.sellability)
|
|
115
|
+
conditions.push(eq(marketChannelRules.sellability, query.sellability));
|
|
116
|
+
if (query.active !== undefined)
|
|
117
|
+
conditions.push(eq(marketChannelRules.active, query.active));
|
|
118
|
+
const where = conditions.length > 0 ? and(...conditions) : undefined;
|
|
119
|
+
return paginate(db
|
|
120
|
+
.select()
|
|
121
|
+
.from(marketChannelRules)
|
|
122
|
+
.where(where)
|
|
123
|
+
.limit(query.limit)
|
|
124
|
+
.offset(query.offset)
|
|
125
|
+
.orderBy(asc(marketChannelRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(marketChannelRules).where(where), query.limit, query.offset);
|
|
126
|
+
}
|
|
127
|
+
export async function getMarketChannelRuleById(db, id) {
|
|
128
|
+
const [row] = await db
|
|
129
|
+
.select()
|
|
130
|
+
.from(marketChannelRules)
|
|
131
|
+
.where(eq(marketChannelRules.id, id))
|
|
132
|
+
.limit(1);
|
|
133
|
+
return row ?? null;
|
|
134
|
+
}
|
|
135
|
+
export async function createMarketChannelRule(db, data) {
|
|
136
|
+
if (!(await marketExists(db, data.marketId)))
|
|
137
|
+
return null;
|
|
138
|
+
const [row] = await db.insert(marketChannelRules).values(data).returning();
|
|
139
|
+
return row ?? null;
|
|
140
|
+
}
|
|
141
|
+
export async function updateMarketChannelRule(db, id, data) {
|
|
142
|
+
const [row] = await db
|
|
143
|
+
.update(marketChannelRules)
|
|
144
|
+
.set({ ...data, updatedAt: new Date() })
|
|
145
|
+
.where(eq(marketChannelRules.id, id))
|
|
146
|
+
.returning();
|
|
147
|
+
return row ?? null;
|
|
148
|
+
}
|
|
149
|
+
export async function deleteMarketChannelRule(db, id) {
|
|
150
|
+
const [row] = await db
|
|
151
|
+
.delete(marketChannelRules)
|
|
152
|
+
.where(eq(marketChannelRules.id, id))
|
|
153
|
+
.returning({ id: marketChannelRules.id });
|
|
154
|
+
return row ?? null;
|
|
155
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { exchangeRateListQuerySchema, fxRateSetListQuerySchema, insertExchangeRateSchema, insertFxRateSetSchema, insertMarketChannelRuleSchema, insertMarketCurrencySchema, insertMarketLocaleSchema, insertMarketPriceCatalogSchema, insertMarketProductRuleSchema, insertMarketSchema, marketChannelRuleListQuerySchema, marketCurrencyListQuerySchema, marketListQuerySchema, marketLocaleListQuerySchema, marketPriceCatalogListQuerySchema, marketProductRuleListQuerySchema, updateExchangeRateSchema, updateFxRateSetSchema, updateMarketChannelRuleSchema, updateMarketCurrencySchema, updateMarketLocaleSchema, updateMarketPriceCatalogSchema, updateMarketProductRuleSchema, updateMarketSchema } from "./validation.js";
|
|
3
|
+
export type MarketListQuery = z.infer<typeof marketListQuerySchema>;
|
|
4
|
+
export type MarketLocaleListQuery = z.infer<typeof marketLocaleListQuerySchema>;
|
|
5
|
+
export type MarketCurrencyListQuery = z.infer<typeof marketCurrencyListQuerySchema>;
|
|
6
|
+
export type FxRateSetListQuery = z.infer<typeof fxRateSetListQuerySchema>;
|
|
7
|
+
export type ExchangeRateListQuery = z.infer<typeof exchangeRateListQuerySchema>;
|
|
8
|
+
export type MarketPriceCatalogListQuery = z.infer<typeof marketPriceCatalogListQuerySchema>;
|
|
9
|
+
export type MarketProductRuleListQuery = z.infer<typeof marketProductRuleListQuerySchema>;
|
|
10
|
+
export type MarketChannelRuleListQuery = z.infer<typeof marketChannelRuleListQuerySchema>;
|
|
11
|
+
export type CreateMarketInput = z.infer<typeof insertMarketSchema>;
|
|
12
|
+
export type UpdateMarketInput = z.infer<typeof updateMarketSchema>;
|
|
13
|
+
export type CreateMarketLocaleInput = z.infer<typeof insertMarketLocaleSchema>;
|
|
14
|
+
export type UpdateMarketLocaleInput = z.infer<typeof updateMarketLocaleSchema>;
|
|
15
|
+
export type CreateMarketCurrencyInput = z.infer<typeof insertMarketCurrencySchema>;
|
|
16
|
+
export type UpdateMarketCurrencyInput = z.infer<typeof updateMarketCurrencySchema>;
|
|
17
|
+
export type CreateFxRateSetInput = z.infer<typeof insertFxRateSetSchema>;
|
|
18
|
+
export type UpdateFxRateSetInput = z.infer<typeof updateFxRateSetSchema>;
|
|
19
|
+
export type CreateExchangeRateInput = z.infer<typeof insertExchangeRateSchema>;
|
|
20
|
+
export type UpdateExchangeRateInput = z.infer<typeof updateExchangeRateSchema>;
|
|
21
|
+
export type CreateMarketPriceCatalogInput = z.infer<typeof insertMarketPriceCatalogSchema>;
|
|
22
|
+
export type UpdateMarketPriceCatalogInput = z.infer<typeof updateMarketPriceCatalogSchema>;
|
|
23
|
+
export type CreateMarketProductRuleInput = z.infer<typeof insertMarketProductRuleSchema>;
|
|
24
|
+
export type UpdateMarketProductRuleInput = z.infer<typeof updateMarketProductRuleSchema>;
|
|
25
|
+
export type CreateMarketChannelRuleInput = z.infer<typeof insertMarketChannelRuleSchema>;
|
|
26
|
+
export type UpdateMarketChannelRuleInput = z.infer<typeof updateMarketChannelRuleSchema>;
|
|
27
|
+
export declare function paginate<T extends object>(rowsQuery: Promise<T[]>, countQuery: Promise<Array<{
|
|
28
|
+
count: number;
|
|
29
|
+
}>>, limit: number, offset: number): Promise<{
|
|
30
|
+
data: T[];
|
|
31
|
+
total: number;
|
|
32
|
+
limit: number;
|
|
33
|
+
offset: number;
|
|
34
|
+
}>;
|
|
35
|
+
export declare function toTimestamp(value?: string | null): Date | null;
|
|
36
|
+
//# sourceMappingURL=service-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-shared.d.ts","sourceRoot":"","sources":["../src/service-shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EACV,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,EACrB,6BAA6B,EAC7B,0BAA0B,EAC1B,wBAAwB,EACxB,8BAA8B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AK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM;;;;;GAIf;AAED,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,eAEhD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export async function paginate(rowsQuery, countQuery, limit, offset) {
|
|
2
|
+
const [data, countResult] = await Promise.all([rowsQuery, countQuery]);
|
|
3
|
+
return { data, total: countResult[0]?.count ?? 0, limit, offset };
|
|
4
|
+
}
|
|
5
|
+
export function toTimestamp(value) {
|
|
6
|
+
return value ? new Date(value) : null;
|
|
7
|
+
}
|