@voyantjs/markets 0.1.0
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/LICENSE +109 -0
- package/README.md +34 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/routes.d.ts +1182 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +208 -0
- package/dist/schema.d.ts +1527 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +231 -0
- package/dist/service.d.ts +459 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +403 -0
- package/dist/validation.d.ts +451 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +160 -0
- package/package.json +51 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,gBAAgB,0EAA8D,CAAA;AAC3F,eAAO,MAAM,oBAAoB,uEAA+D,CAAA;AAChG,eAAO,MAAM,qBAAqB,iFAIhC,CAAA;AACF,eAAO,MAAM,sBAAsB,yEAKjC,CAAA;AACF,eAAO,MAAM,gBAAgB,mGAO3B,CAAA;AAEF,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsBnB,CAAA;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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B,CAAC,YAAY,CAAA;AACzE,MAAM,MAAM,iBAAiB,GAAG,OAAO,kBAAkB,CAAC,YAAY,CAAA;AACtE,MAAM,MAAM,oBAAoB,GAAG,OAAO,kBAAkB,CAAC,YAAY,CAAA;AAEzE,eAAO,MAAM,gBAAgB;;;;;;EAM1B,CAAA;AAEH,eAAO,MAAM,sBAAsB;;EAKhC,CAAA;AAEH,eAAO,MAAM,yBAAyB;;EAKnC,CAAA;AAEH,eAAO,MAAM,mBAAmB;;EAE7B,CAAA;AAEH,eAAO,MAAM,sBAAsB;;EAKhC,CAAA;AAEH,eAAO,MAAM,4BAA4B;;;;EAOtC,CAAA;AAEH,eAAO,MAAM,2BAA2B;;;EASrC,CAAA;AAEH,eAAO,MAAM,2BAA2B;;;EASrC,CAAA"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { typeId, typeIdRef } from "@voyantjs/db/lib/typeid-column";
|
|
2
|
+
import { relations } from "drizzle-orm";
|
|
3
|
+
import { boolean, date, index, integer, jsonb, numeric, pgEnum, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
|
|
4
|
+
export const marketStatusEnum = pgEnum("market_status", ["active", "inactive", "archived"]);
|
|
5
|
+
export const marketVisibilityEnum = pgEnum("market_visibility", ["public", "private", "hidden"]);
|
|
6
|
+
export const marketSellabilityEnum = pgEnum("market_sellability", [
|
|
7
|
+
"sellable",
|
|
8
|
+
"on_request",
|
|
9
|
+
"unavailable",
|
|
10
|
+
]);
|
|
11
|
+
export const marketChannelScopeEnum = pgEnum("market_channel_scope", [
|
|
12
|
+
"all",
|
|
13
|
+
"b2c",
|
|
14
|
+
"b2b",
|
|
15
|
+
"internal",
|
|
16
|
+
]);
|
|
17
|
+
export const fxRateSourceEnum = pgEnum("fx_rate_source", [
|
|
18
|
+
"manual",
|
|
19
|
+
"ecb",
|
|
20
|
+
"custom",
|
|
21
|
+
"channel",
|
|
22
|
+
"supplier",
|
|
23
|
+
"other",
|
|
24
|
+
]);
|
|
25
|
+
export const markets = pgTable("markets", {
|
|
26
|
+
id: typeId("markets"),
|
|
27
|
+
code: text("code").notNull(),
|
|
28
|
+
name: text("name").notNull(),
|
|
29
|
+
status: marketStatusEnum("status").notNull().default("active"),
|
|
30
|
+
regionCode: text("region_code"),
|
|
31
|
+
countryCode: text("country_code"),
|
|
32
|
+
defaultLanguageTag: text("default_language_tag").notNull(),
|
|
33
|
+
defaultCurrency: text("default_currency").notNull(),
|
|
34
|
+
timezone: text("timezone"),
|
|
35
|
+
taxContext: text("tax_context"),
|
|
36
|
+
metadata: jsonb("metadata").$type(),
|
|
37
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
38
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
39
|
+
}, (table) => [
|
|
40
|
+
uniqueIndex("uidx_markets_code").on(table.code),
|
|
41
|
+
index("idx_markets_status").on(table.status),
|
|
42
|
+
index("idx_markets_country").on(table.countryCode),
|
|
43
|
+
]);
|
|
44
|
+
export const marketLocales = pgTable("market_locales", {
|
|
45
|
+
id: typeId("market_locales"),
|
|
46
|
+
marketId: typeIdRef("market_id")
|
|
47
|
+
.notNull()
|
|
48
|
+
.references(() => markets.id, { onDelete: "cascade" }),
|
|
49
|
+
languageTag: text("language_tag").notNull(),
|
|
50
|
+
isDefault: boolean("is_default").notNull().default(false),
|
|
51
|
+
sortOrder: integer("sort_order").notNull().default(0),
|
|
52
|
+
active: boolean("active").notNull().default(true),
|
|
53
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
54
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
55
|
+
}, (table) => [
|
|
56
|
+
index("idx_market_locales_market").on(table.marketId),
|
|
57
|
+
index("idx_market_locales_language").on(table.languageTag),
|
|
58
|
+
uniqueIndex("uidx_market_locales_market_language").on(table.marketId, table.languageTag),
|
|
59
|
+
]);
|
|
60
|
+
export const marketCurrencies = pgTable("market_currencies", {
|
|
61
|
+
id: typeId("market_currencies"),
|
|
62
|
+
marketId: typeIdRef("market_id")
|
|
63
|
+
.notNull()
|
|
64
|
+
.references(() => markets.id, { onDelete: "cascade" }),
|
|
65
|
+
currencyCode: text("currency_code").notNull(),
|
|
66
|
+
isDefault: boolean("is_default").notNull().default(false),
|
|
67
|
+
isSettlement: boolean("is_settlement").notNull().default(false),
|
|
68
|
+
isReporting: boolean("is_reporting").notNull().default(false),
|
|
69
|
+
sortOrder: integer("sort_order").notNull().default(0),
|
|
70
|
+
active: boolean("active").notNull().default(true),
|
|
71
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
72
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
73
|
+
}, (table) => [
|
|
74
|
+
index("idx_market_currencies_market").on(table.marketId),
|
|
75
|
+
index("idx_market_currencies_code").on(table.currencyCode),
|
|
76
|
+
uniqueIndex("uidx_market_currencies_market_code").on(table.marketId, table.currencyCode),
|
|
77
|
+
]);
|
|
78
|
+
export const fxRateSets = pgTable("fx_rate_sets", {
|
|
79
|
+
id: typeId("fx_rate_sets"),
|
|
80
|
+
source: fxRateSourceEnum("source").notNull().default("manual"),
|
|
81
|
+
baseCurrency: text("base_currency").notNull(),
|
|
82
|
+
effectiveAt: timestamp("effective_at", { withTimezone: true }).notNull(),
|
|
83
|
+
observedAt: timestamp("observed_at", { withTimezone: true }),
|
|
84
|
+
sourceReference: text("source_reference"),
|
|
85
|
+
notes: text("notes"),
|
|
86
|
+
metadata: jsonb("metadata").$type(),
|
|
87
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
88
|
+
}, (table) => [
|
|
89
|
+
index("idx_fx_rate_sets_base_currency").on(table.baseCurrency),
|
|
90
|
+
index("idx_fx_rate_sets_effective_at").on(table.effectiveAt),
|
|
91
|
+
index("idx_fx_rate_sets_source").on(table.source),
|
|
92
|
+
]);
|
|
93
|
+
export const exchangeRates = pgTable("exchange_rates", {
|
|
94
|
+
id: typeId("exchange_rates"),
|
|
95
|
+
fxRateSetId: typeIdRef("fx_rate_set_id")
|
|
96
|
+
.notNull()
|
|
97
|
+
.references(() => fxRateSets.id, { onDelete: "cascade" }),
|
|
98
|
+
baseCurrency: text("base_currency").notNull(),
|
|
99
|
+
quoteCurrency: text("quote_currency").notNull(),
|
|
100
|
+
rateDecimal: numeric("rate_decimal", { precision: 18, scale: 8 }).notNull(),
|
|
101
|
+
inverseRateDecimal: numeric("inverse_rate_decimal", { precision: 18, scale: 8 }),
|
|
102
|
+
observedAt: timestamp("observed_at", { withTimezone: true }),
|
|
103
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
104
|
+
}, (table) => [
|
|
105
|
+
index("idx_exchange_rates_rate_set").on(table.fxRateSetId),
|
|
106
|
+
index("idx_exchange_rates_pair").on(table.baseCurrency, table.quoteCurrency),
|
|
107
|
+
uniqueIndex("uidx_exchange_rates_set_pair").on(table.fxRateSetId, table.baseCurrency, table.quoteCurrency),
|
|
108
|
+
]);
|
|
109
|
+
export const marketPriceCatalogs = pgTable("market_price_catalogs", {
|
|
110
|
+
id: typeId("market_price_catalogs"),
|
|
111
|
+
marketId: typeIdRef("market_id")
|
|
112
|
+
.notNull()
|
|
113
|
+
.references(() => markets.id, { onDelete: "cascade" }),
|
|
114
|
+
priceCatalogId: typeIdRef("price_catalog_id").notNull(),
|
|
115
|
+
isDefault: boolean("is_default").notNull().default(false),
|
|
116
|
+
priority: integer("priority").notNull().default(0),
|
|
117
|
+
active: boolean("active").notNull().default(true),
|
|
118
|
+
notes: text("notes"),
|
|
119
|
+
metadata: jsonb("metadata").$type(),
|
|
120
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
121
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
122
|
+
}, (table) => [
|
|
123
|
+
index("idx_market_price_catalogs_market").on(table.marketId),
|
|
124
|
+
index("idx_market_price_catalogs_catalog").on(table.priceCatalogId),
|
|
125
|
+
index("idx_market_price_catalogs_active").on(table.active),
|
|
126
|
+
uniqueIndex("uidx_market_price_catalogs_market_catalog").on(table.marketId, table.priceCatalogId),
|
|
127
|
+
]);
|
|
128
|
+
export const marketProductRules = pgTable("market_product_rules", {
|
|
129
|
+
id: typeId("market_product_rules"),
|
|
130
|
+
marketId: typeIdRef("market_id")
|
|
131
|
+
.notNull()
|
|
132
|
+
.references(() => markets.id, { onDelete: "cascade" }),
|
|
133
|
+
productId: text("product_id").notNull(),
|
|
134
|
+
optionId: text("option_id"),
|
|
135
|
+
priceCatalogId: typeIdRef("price_catalog_id").references(() => marketPriceCatalogs.id, {
|
|
136
|
+
onDelete: "set null",
|
|
137
|
+
}),
|
|
138
|
+
visibility: marketVisibilityEnum("visibility").notNull().default("public"),
|
|
139
|
+
sellability: marketSellabilityEnum("sellability").notNull().default("sellable"),
|
|
140
|
+
channelScope: marketChannelScopeEnum("channel_scope").notNull().default("all"),
|
|
141
|
+
active: boolean("active").notNull().default(true),
|
|
142
|
+
availableFrom: date("available_from"),
|
|
143
|
+
availableTo: date("available_to"),
|
|
144
|
+
notes: text("notes"),
|
|
145
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
146
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
147
|
+
}, (table) => [
|
|
148
|
+
index("idx_market_product_rules_market").on(table.marketId),
|
|
149
|
+
index("idx_market_product_rules_product").on(table.productId),
|
|
150
|
+
index("idx_market_product_rules_option").on(table.optionId),
|
|
151
|
+
index("idx_market_product_rules_catalog").on(table.priceCatalogId),
|
|
152
|
+
index("idx_market_product_rules_active").on(table.active),
|
|
153
|
+
]);
|
|
154
|
+
export const marketChannelRules = pgTable("market_channel_rules", {
|
|
155
|
+
id: typeId("market_channel_rules"),
|
|
156
|
+
marketId: typeIdRef("market_id")
|
|
157
|
+
.notNull()
|
|
158
|
+
.references(() => markets.id, { onDelete: "cascade" }),
|
|
159
|
+
channelId: text("channel_id").notNull(),
|
|
160
|
+
priceCatalogId: typeIdRef("price_catalog_id").references(() => marketPriceCatalogs.id, {
|
|
161
|
+
onDelete: "set null",
|
|
162
|
+
}),
|
|
163
|
+
visibility: marketVisibilityEnum("visibility").notNull().default("public"),
|
|
164
|
+
sellability: marketSellabilityEnum("sellability").notNull().default("sellable"),
|
|
165
|
+
active: boolean("active").notNull().default(true),
|
|
166
|
+
priority: integer("priority").notNull().default(0),
|
|
167
|
+
notes: text("notes"),
|
|
168
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
169
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
170
|
+
}, (table) => [
|
|
171
|
+
index("idx_market_channel_rules_market").on(table.marketId),
|
|
172
|
+
index("idx_market_channel_rules_channel").on(table.channelId),
|
|
173
|
+
index("idx_market_channel_rules_catalog").on(table.priceCatalogId),
|
|
174
|
+
index("idx_market_channel_rules_active").on(table.active),
|
|
175
|
+
]);
|
|
176
|
+
export const marketsRelations = relations(markets, ({ many }) => ({
|
|
177
|
+
locales: many(marketLocales),
|
|
178
|
+
currencies: many(marketCurrencies),
|
|
179
|
+
priceCatalogs: many(marketPriceCatalogs),
|
|
180
|
+
productRules: many(marketProductRules),
|
|
181
|
+
channelRules: many(marketChannelRules),
|
|
182
|
+
}));
|
|
183
|
+
export const marketLocalesRelations = relations(marketLocales, ({ one }) => ({
|
|
184
|
+
market: one(markets, {
|
|
185
|
+
fields: [marketLocales.marketId],
|
|
186
|
+
references: [markets.id],
|
|
187
|
+
}),
|
|
188
|
+
}));
|
|
189
|
+
export const marketCurrenciesRelations = relations(marketCurrencies, ({ one }) => ({
|
|
190
|
+
market: one(markets, {
|
|
191
|
+
fields: [marketCurrencies.marketId],
|
|
192
|
+
references: [markets.id],
|
|
193
|
+
}),
|
|
194
|
+
}));
|
|
195
|
+
export const fxRateSetsRelations = relations(fxRateSets, ({ many }) => ({
|
|
196
|
+
exchangeRates: many(exchangeRates),
|
|
197
|
+
}));
|
|
198
|
+
export const exchangeRatesRelations = relations(exchangeRates, ({ one }) => ({
|
|
199
|
+
fxRateSet: one(fxRateSets, {
|
|
200
|
+
fields: [exchangeRates.fxRateSetId],
|
|
201
|
+
references: [fxRateSets.id],
|
|
202
|
+
}),
|
|
203
|
+
}));
|
|
204
|
+
export const marketPriceCatalogsRelations = relations(marketPriceCatalogs, ({ one, many }) => ({
|
|
205
|
+
market: one(markets, {
|
|
206
|
+
fields: [marketPriceCatalogs.marketId],
|
|
207
|
+
references: [markets.id],
|
|
208
|
+
}),
|
|
209
|
+
productRules: many(marketProductRules),
|
|
210
|
+
channelRules: many(marketChannelRules),
|
|
211
|
+
}));
|
|
212
|
+
export const marketProductRulesRelations = relations(marketProductRules, ({ one }) => ({
|
|
213
|
+
market: one(markets, {
|
|
214
|
+
fields: [marketProductRules.marketId],
|
|
215
|
+
references: [markets.id],
|
|
216
|
+
}),
|
|
217
|
+
priceCatalog: one(marketPriceCatalogs, {
|
|
218
|
+
fields: [marketProductRules.priceCatalogId],
|
|
219
|
+
references: [marketPriceCatalogs.id],
|
|
220
|
+
}),
|
|
221
|
+
}));
|
|
222
|
+
export const marketChannelRulesRelations = relations(marketChannelRules, ({ one }) => ({
|
|
223
|
+
market: one(markets, {
|
|
224
|
+
fields: [marketChannelRules.marketId],
|
|
225
|
+
references: [markets.id],
|
|
226
|
+
}),
|
|
227
|
+
priceCatalog: one(marketPriceCatalogs, {
|
|
228
|
+
fields: [marketChannelRules.priceCatalogId],
|
|
229
|
+
references: [marketPriceCatalogs.id],
|
|
230
|
+
}),
|
|
231
|
+
}));
|