@storecraft/database-sql-base 1.0.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.
Files changed (49) hide show
  1. package/README.md +126 -0
  2. package/TODO.md +2 -0
  3. package/db-strategy.md +3 -0
  4. package/driver.js +190 -0
  5. package/index.js +3 -0
  6. package/migrate.js +66 -0
  7. package/migrations.mssql/00000_init_tables.js +268 -0
  8. package/migrations.mysql/00000_init_tables.js +372 -0
  9. package/migrations.mysql/00001_seed_email_templates.js +1 -0
  10. package/migrations.postgres/00000_init_tables.js +358 -0
  11. package/migrations.postgres/00001_seed_email_templates.js +1 -0
  12. package/migrations.shared/00001_seed_email_templates.js +260 -0
  13. package/migrations.sqlite/00000_init_tables.js +357 -0
  14. package/migrations.sqlite/00001_seed_email_templates.js +1 -0
  15. package/package.json +47 -0
  16. package/src/con.auth_users.js +159 -0
  17. package/src/con.collections.js +197 -0
  18. package/src/con.customers.js +202 -0
  19. package/src/con.discounts.js +225 -0
  20. package/src/con.discounts.utils.js +180 -0
  21. package/src/con.helpers.json.js +231 -0
  22. package/src/con.helpers.json.mssql.js +233 -0
  23. package/src/con.helpers.json.mysql.js +239 -0
  24. package/src/con.helpers.json.postgres.js +223 -0
  25. package/src/con.helpers.json.sqlite.js +263 -0
  26. package/src/con.images.js +230 -0
  27. package/src/con.notifications.js +149 -0
  28. package/src/con.orders.js +156 -0
  29. package/src/con.posts.js +147 -0
  30. package/src/con.products.js +497 -0
  31. package/src/con.search.js +148 -0
  32. package/src/con.shared.js +616 -0
  33. package/src/con.shipping.js +147 -0
  34. package/src/con.storefronts.js +301 -0
  35. package/src/con.tags.js +120 -0
  36. package/src/con.templates.js +133 -0
  37. package/src/kysely.sanitize.plugin.js +40 -0
  38. package/src/utils.funcs.js +77 -0
  39. package/src/utils.query.js +195 -0
  40. package/tests/query.cursor.test.js +389 -0
  41. package/tests/query.vql.test.js +71 -0
  42. package/tests/runner.mssql-local.test.js +118 -0
  43. package/tests/runner.mysql-local.test.js +101 -0
  44. package/tests/runner.postgres-local.test.js +99 -0
  45. package/tests/runner.sqlite-local.test.js +99 -0
  46. package/tests/sandbox.test.js +71 -0
  47. package/tsconfig.json +21 -0
  48. package/types.public.d.ts +19 -0
  49. package/types.sql.tables.d.ts +247 -0
@@ -0,0 +1,247 @@
1
+ import { AttributeType, AuthUserType, Role, TagType,
2
+ CollectionType, ProductType, ShippingMethodType,
3
+ VariantOption, PostType, CustomerType,
4
+ VariantOptionSelection, OrderData, StorefrontType,
5
+ AddressType, ImageType,
6
+ OrderContact,
7
+ LineItem,
8
+ OrderStatus, DiscountType,
9
+ PricingData,
10
+ ValidationEntry,
11
+ OrderPaymentGatewayData, NotificationType,
12
+ NotificationAction,
13
+ DiscountInfo,
14
+ DiscountApplicationEnum} from '@storecraft/core/v-api'
15
+ import {
16
+ ColumnType,
17
+ Generated,
18
+ JSONColumnType,
19
+ } from 'kysely'
20
+
21
+ export interface Database {
22
+ auth_users: AuthUserTypeTable,
23
+ tags: TagsTable
24
+ collections: CollectionsTable,
25
+ shipping_methods: ShippingMethodsTable;
26
+ posts: PostsTable;
27
+ customers: CustomersTable;
28
+ orders: OrdersTable;
29
+ notifications: NotificationsTable;
30
+ images: ImagesTable;
31
+ discounts: DiscountsTable;
32
+ templates: TemplatesTable;
33
+
34
+ storefronts: StorefrontsTable;
35
+ storefronts_to_other: storefronts_to_other;
36
+
37
+ products: ProductsTable,
38
+ products_to_collections: products_to_collections;
39
+ products_to_discounts: products_to_discounts;
40
+ products_to_variants: products_to_variants;
41
+ products_to_related_products: products_to_related_products;
42
+
43
+ entity_to_media: entity_to_media,
44
+ entity_to_tags_projections: entity_to_tags_projections,
45
+ entity_to_search_terms: entity_to_search_terms,
46
+ }
47
+
48
+ export interface entity_to_value {
49
+ id: Generated<number>,
50
+ /** The entity ID */
51
+ entity_id: string,
52
+ /** The entity handle */
53
+ entity_handle: string | undefined,
54
+ /** The value reported */
55
+ value: string
56
+ /** reporter is a segmentation technique, it adds another dimension.
57
+ * If reporter is `null`, then it means the `entity_id` was the reporter */
58
+ reporter: string | undefined;
59
+ /** The context of the values */
60
+ context: string | undefined;
61
+ }
62
+
63
+ export interface entity_to_media extends entity_to_value {}
64
+ export interface entity_to_tags_projections extends entity_to_value {}
65
+ export interface entity_to_search_terms extends entity_to_value {}
66
+
67
+ /**
68
+ * here:
69
+ * - entity_id, entity_handle = product id, product handle
70
+ * - value, reporter = collection id, collection handle
71
+ */
72
+ export interface products_to_collections extends entity_to_value {}
73
+
74
+ /**
75
+ * here:
76
+ * - entity_id, entity_handle = product id, product handle
77
+ * - value, reporter = discount id, discount handle
78
+ */
79
+ export interface products_to_discounts extends entity_to_value {}
80
+
81
+ /**
82
+ * here:
83
+ * - (entity_id, entity_handle) = (parent product id, parent product handle)
84
+ * - (value, reporter) = (variant product id, variant product handle)
85
+ */
86
+ export interface products_to_variants extends entity_to_value {}
87
+
88
+ /**
89
+ * here:
90
+ * - (entity_id, entity_handle) = (parent product id, parent product handle)
91
+ * - (value, reporter) = (related product id, related product handle)
92
+ */
93
+ export interface products_to_related_products extends entity_to_value {}
94
+
95
+ /**
96
+ * storefronts to products/collections/posts/discounts/shipping
97
+ * here:
98
+ * - entity_id, entity_handle = storefront id, storefront handle
99
+ * - value, reporter = other entity id, other entity handle, i.e(product_id, product_handle)
100
+ * - context = `products` / `collections` / `posts` / `discounts` / `shipping`
101
+ *
102
+ * This will probably be a small table hence everything is recorded in the same table.
103
+ * Usually, a user will have:
104
+ * - small number of storefronts
105
+ * - small number of attached products/collections/posts/discounts/shipping per storefront
106
+ */
107
+ export interface storefronts_to_other extends entity_to_value {}
108
+
109
+
110
+ export interface Base {
111
+ attributes: JSONColumnType<AttributeType[] | undefined>;
112
+ description: ColumnType<string | undefined>;
113
+ active: ColumnType<number | undefined>;
114
+ created_at: ColumnType<string>;
115
+ updated_at: ColumnType<string>;
116
+ id: string;
117
+ handle: string;
118
+ }
119
+
120
+ export interface AuthUserTypeTable extends Base {
121
+ email: string;
122
+ password: string;
123
+ confirmed_mail: number
124
+ roles: JSONColumnType<Role[]>;
125
+ }
126
+
127
+ export interface TagsTable extends Base {
128
+ values: JSONColumnType<string[]>;
129
+ }
130
+
131
+ export interface CollectionsTable extends Base {
132
+ title: string;
133
+ published: string | undefined;
134
+ }
135
+
136
+ export interface TemplatesTable extends Base {
137
+ template_html?: string;
138
+ template_text?: string;
139
+ reference_example_input?: JSONColumnType<object>;
140
+ title: string;
141
+ }
142
+
143
+ export interface ProductsTable extends Base {
144
+ title: string;
145
+ video: string;
146
+ price: number;
147
+ isbn: string;
148
+ qty: number;
149
+ compare_at_price: number;
150
+ variants_options: JSONColumnType<VariantOption[]>;
151
+ //for variant children
152
+ parent_handle: string;
153
+ parent_id: string;
154
+ variant_hint: JSONColumnType<VariantOptionSelection[]>;
155
+ }
156
+
157
+ export interface ShippingMethodsTable extends Base {
158
+ title: string;
159
+ price: number;
160
+ }
161
+
162
+ export interface PostsTable extends Base {
163
+ title: string;
164
+ text: string;
165
+ }
166
+
167
+ export interface CustomersTable extends Base {
168
+ auth_id: string;
169
+ firstname: string;
170
+ lastname: string;
171
+ email: string;
172
+ phone_number: string;
173
+ address: JSONColumnType<AddressType>;
174
+ }
175
+
176
+ export interface OrdersTable extends Base {
177
+ /** buyer info */
178
+ contact: JSONColumnType<OrderContact>;
179
+ /** shipping address info */
180
+ address: JSONColumnType<AddressType>;
181
+ /** line items is a list of the purchased products */
182
+ line_items: JSONColumnType<LineItem[]>;
183
+ /** notes for the order */
184
+ notes: string;
185
+ /** shipping method info */
186
+ shipping_method: JSONColumnType<ShippingMethodType>;
187
+ /** status of checkout, fulfillment and payment */
188
+ status: JSONColumnType<OrderStatus>;
189
+ /** pricing information */
190
+ pricing: JSONColumnType<PricingData>;
191
+ /** in case the order went through validation */
192
+ validation: JSONColumnType<ValidationEntry[]>;
193
+ /** payment gateway info and status */
194
+ payment_gateway: JSONColumnType<OrderPaymentGatewayData>;
195
+ /** a list of manual coupons snapshots that were used */
196
+ coupons: JSONColumnType<DiscountType[]>;
197
+ /** Internal for querying */
198
+ _customer_id: string;
199
+ _customer_email: string;
200
+ _status_payment_id: number;
201
+ _status_checkout_id: number;
202
+ _status_fulfillment_id: number;
203
+ }
204
+
205
+ export interface StorefrontsTable extends Base {
206
+ /** readable title */
207
+ title: string;
208
+ /** video url */
209
+ video: string;
210
+ /** exported storefront json */
211
+ published: string;
212
+ }
213
+
214
+ export interface NotificationsTable extends Base {
215
+ /** message of notification, can be markdown, markup or plain text */
216
+ message: string;
217
+ /** author of the notification */
218
+ author: string;
219
+ /** list of actions */
220
+ actions: JSONColumnType<NotificationAction[]>;
221
+ // for local usage as well
222
+ search: JSONColumnType<string[]>;
223
+ }
224
+
225
+ export interface ImagesTable extends Base {
226
+ name: string;
227
+ url: string;
228
+ }
229
+
230
+ export interface DiscountsTable extends Base {
231
+ /** title */
232
+ title: string;
233
+ /** discount code */
234
+ handle: string;
235
+ priority: number;
236
+ /** the collection handle that contains the applicable discount products */
237
+ published?: string;
238
+ /** details and filters of the discount */
239
+ info: JSONColumnType<DiscountInfo>;
240
+ /** discount application (automatic and coupons) */
241
+ application: JSONColumnType<DiscountApplicationEnum>;
242
+ /** internal usage, the application type id */
243
+ _application_id: number;
244
+ /** internal usage, the discount type id */
245
+ _discount_type_id: number;
246
+ }
247
+