@storecraft/database-sql-base 1.0.0 → 1.0.2
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/README.md +30 -12
- package/index.js +172 -1
- package/{tsconfig.json → jsconfig.json} +1 -5
- package/migrate.js +25 -19
- package/migrations.mysql/00000_init_tables.js +6 -5
- package/migrations.postgres/00000_init_tables.js +15 -14
- package/migrations.shared/00001_seed_email_templates copy.js +262 -0
- package/migrations.shared/00001_seed_email_templates.js +5 -238
- package/migrations.sqlite/00000_init_tables.js +12 -12
- package/package.json +2 -4
- package/src/con.auth_users.js +5 -2
- package/src/con.collections.js +2 -2
- package/src/con.customers.js +2 -2
- package/src/con.discounts.js +3 -3
- package/src/con.discounts.utils.js +11 -11
- package/src/con.helpers.json.js +3 -3
- package/src/con.images.js +5 -5
- package/src/con.notifications.js +2 -2
- package/src/con.orders.js +19 -4
- package/src/con.posts.js +2 -2
- package/src/con.products.js +5 -5
- package/src/con.search.js +7 -7
- package/src/con.shared.experiment.js +723 -0
- package/src/con.shared.js +55 -21
- package/src/con.shipping.js +2 -2
- package/src/con.storefronts.js +2 -2
- package/src/con.tags.js +2 -2
- package/src/con.templates.js +22 -7
- package/src/utils.query.js +6 -6
- package/tests/runner.mssql-local.test.js +10 -6
- package/tests/runner.mysql-local.test.js +16 -63
- package/tests/runner.postgres-local.test.js +17 -62
- package/tests/runner.sqlite-local.test.js +15 -64
- package/tests/sandbox.test.js +15 -13
- package/types.public.d.ts +12 -4
- package/types.sql.tables.d.ts +4 -2
- package/driver.js +0 -190
- package/tests/query.cursor.test.js +0 -389
- package/tests/query.vql.test.js +0 -71
package/src/con.shared.js
CHANGED
@@ -1,14 +1,48 @@
|
|
1
|
-
import { ExpressionWrapper, InsertQueryBuilder, Transaction } from 'kysely'
|
1
|
+
import { ExpressionWrapper, InsertQueryBuilder, Kysely, Transaction } from 'kysely'
|
2
2
|
import { jsonArrayFrom, stringArrayFrom } from './con.helpers.json.js'
|
3
3
|
import { SQL } from '../index.js';
|
4
4
|
import { query_to_eb } from './utils.query.js';
|
5
5
|
|
6
|
+
/**
|
7
|
+
* @template K
|
8
|
+
* @typedef {K extends Kysely<infer D> ? D : unknown} KDB
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @description Use the current kysely connection as transaction if
|
14
|
+
* it already a transaction, otherwise eecute a new transaction.
|
15
|
+
*
|
16
|
+
* @param {Kysely<Database>} k
|
17
|
+
*
|
18
|
+
*/
|
19
|
+
export const safe_trx = (k) => {
|
20
|
+
if(k.isTransaction) {
|
21
|
+
return {
|
22
|
+
/**
|
23
|
+
*
|
24
|
+
* @param {(k: Kysely<Database>) => Promise<any>} cb
|
25
|
+
*/
|
26
|
+
execute: (cb) => {
|
27
|
+
return cb(k);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
return {
|
33
|
+
/**
|
34
|
+
* @param {(k: Transaction<Database>) => Promise<any>} cb
|
35
|
+
*/
|
36
|
+
execute: (cb) => k.transaction().execute(cb)
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
6
40
|
|
7
41
|
/**
|
8
42
|
* @param {SQL} driver
|
9
43
|
* @param {keyof Database} table_name
|
10
44
|
*
|
11
|
-
* @returns {import('@storecraft/core/
|
45
|
+
* @returns {import('@storecraft/core/database').db_crud["count"]}
|
12
46
|
*/
|
13
47
|
export const count_regular = (driver, table_name) => {
|
14
48
|
return async (query) => {
|
@@ -78,7 +112,7 @@ export const where_id_or_handle_table = (id_or_handle) => {
|
|
78
112
|
export const delete_entity_values_by_value_or_reporter = (entity_table_name) => {
|
79
113
|
/**
|
80
114
|
*
|
81
|
-
* @param {
|
115
|
+
* @param {Kysely<Database>} trx
|
82
116
|
* @param {string} value delete by entity value
|
83
117
|
* @param {string} [reporter] delete by reporter
|
84
118
|
*/
|
@@ -104,7 +138,7 @@ export const delete_entity_values_of_by_entity_id_or_handle =
|
|
104
138
|
(entity_table_name) => {
|
105
139
|
/**
|
106
140
|
*
|
107
|
-
* @param {
|
141
|
+
* @param {Kysely<import('../index.js').Database>} trx
|
108
142
|
* @param {string} entity_id delete by id
|
109
143
|
* @param {string} [entity_handle=entity_id] delete by handle
|
110
144
|
*/
|
@@ -127,7 +161,7 @@ export const delete_entity_values_of_by_entity_id_or_handle =
|
|
127
161
|
export const insert_entity_array_values_of = (entity_table_name) => {
|
128
162
|
/**
|
129
163
|
*
|
130
|
-
* @param {
|
164
|
+
* @param {Kysely<Database>} trx
|
131
165
|
* @param {string[]} values values of the entity
|
132
166
|
* @param {string} item_id whom the tags belong to
|
133
167
|
* @param {string} [item_handle] whom the tags belong to
|
@@ -175,7 +209,7 @@ export const insert_entity_array_values_of = (entity_table_name) => {
|
|
175
209
|
export const insert_entity_values_of = (entity_table_name) => {
|
176
210
|
/**
|
177
211
|
*
|
178
|
-
* @param {
|
212
|
+
* @param {Kysely<Database>} trx
|
179
213
|
* @param {{value: string, reporter: string}[]} values values of the entity
|
180
214
|
* @param {string} item_id whom the tags belong to
|
181
215
|
* @param {string} [item_handle] whom the tags belong to
|
@@ -206,7 +240,7 @@ export const insert_entity_values_of = (entity_table_name) => {
|
|
206
240
|
*/
|
207
241
|
export const insert_entity_array_values_with_delete_of = (entity_table) => {
|
208
242
|
/**
|
209
|
-
* @param {
|
243
|
+
* @param {Kysely<Database>} trx
|
210
244
|
* @param {string[]} values values of the entity
|
211
245
|
* @param {string} item_id entity id
|
212
246
|
* @param {string} [item_handle] entity handle
|
@@ -235,7 +269,7 @@ export const delete_media_of = delete_entity_values_of_by_entity_id_or_handle('e
|
|
235
269
|
/**
|
236
270
|
* @template {keyof Database} T
|
237
271
|
*
|
238
|
-
* @param {
|
272
|
+
* @param {Kysely<Database>} trx
|
239
273
|
* @param {T} table_name
|
240
274
|
* @param {import('kysely').InsertObject<Database, T>} item values of the entity
|
241
275
|
*
|
@@ -258,7 +292,7 @@ export const regular_upsert_me = async (trx, table_name, item) => {
|
|
258
292
|
|
259
293
|
/**
|
260
294
|
*
|
261
|
-
* @param {
|
295
|
+
* @param {Kysely<Database>} trx
|
262
296
|
* @param {keyof Database} table_name
|
263
297
|
* @param {string} id_or_handle
|
264
298
|
*/
|
@@ -273,7 +307,7 @@ export const delete_me = async (trx, table_name, id_or_handle) => {
|
|
273
307
|
*
|
274
308
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
275
309
|
* @param {string | ExpressionWrapper<Database>} id_or_handle
|
276
|
-
* @param {import('../types.public.
|
310
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
277
311
|
*/
|
278
312
|
export const with_tags = (eb, id_or_handle, sql_type) => {
|
279
313
|
return stringArrayFrom(
|
@@ -287,7 +321,7 @@ export const with_tags = (eb, id_or_handle, sql_type) => {
|
|
287
321
|
*
|
288
322
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
289
323
|
* @param {string | ExpressionWrapper<Database>} id_or_handle
|
290
|
-
* @param {import('../types.public.
|
324
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
291
325
|
*/
|
292
326
|
export const with_search = (eb, id_or_handle, sql_type) => {
|
293
327
|
return stringArrayFrom(
|
@@ -301,7 +335,7 @@ export const with_search = (eb, id_or_handle, sql_type) => {
|
|
301
335
|
*
|
302
336
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
303
337
|
* @param {string | ExpressionWrapper<Database>} id_or_handle
|
304
|
-
* @param {import('../types.public.
|
338
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
305
339
|
*/
|
306
340
|
export const with_media = (eb, id_or_handle, sql_type) => {
|
307
341
|
return stringArrayFrom(
|
@@ -331,7 +365,7 @@ const select_base_from = (eb, table) => {
|
|
331
365
|
*
|
332
366
|
* @param {import('kysely').ExpressionBuilder<Database, 'products'>} eb
|
333
367
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
334
|
-
* @param {import('../types.public.
|
368
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
335
369
|
*/
|
336
370
|
export const products_with_collections = (eb, product_id_or_handle, sql_type) => {
|
337
371
|
return jsonArrayFrom(
|
@@ -355,7 +389,7 @@ export const products_with_collections = (eb, product_id_or_handle, sql_type) =>
|
|
355
389
|
*
|
356
390
|
* @param {import('kysely').ExpressionBuilder<Database, 'products'>} eb
|
357
391
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
358
|
-
* @param {import('../types.public.
|
392
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
359
393
|
*/
|
360
394
|
export const products_with_discounts = (eb, product_id_or_handle, sql_type) => {
|
361
395
|
return jsonArrayFrom(
|
@@ -382,7 +416,7 @@ export const products_with_discounts = (eb, product_id_or_handle, sql_type) => {
|
|
382
416
|
*
|
383
417
|
* @param {import('kysely').ExpressionBuilder<Database, 'products'>} eb
|
384
418
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
385
|
-
* @param {import('../types.public.
|
419
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
386
420
|
*/
|
387
421
|
export const products_with_variants = (eb, product_id_or_handle, sql_type) => {
|
388
422
|
return jsonArrayFrom(
|
@@ -413,7 +447,7 @@ export const products_with_variants = (eb, product_id_or_handle, sql_type) => {
|
|
413
447
|
*
|
414
448
|
* @param {import('kysely').ExpressionBuilder<Database, 'products'>} eb
|
415
449
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
416
|
-
* @param {import('../types.public.
|
450
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
417
451
|
*/
|
418
452
|
export const products_with_related_products = (eb, product_id_or_handle, sql_type) => {
|
419
453
|
return jsonArrayFrom(
|
@@ -445,7 +479,7 @@ export const products_with_related_products = (eb, product_id_or_handle, sql_typ
|
|
445
479
|
*
|
446
480
|
* @param {import('kysely').ExpressionBuilder<Database, 'storefronts'>} eb
|
447
481
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
448
|
-
* @param {import('../types.public.
|
482
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
449
483
|
*/
|
450
484
|
export const storefront_with_collections = (eb, sf_id_or_handle, sql_type) => {
|
451
485
|
return jsonArrayFrom(
|
@@ -469,7 +503,7 @@ export const storefront_with_collections = (eb, sf_id_or_handle, sql_type) => {
|
|
469
503
|
*
|
470
504
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
471
505
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
472
|
-
* @param {import('../types.public.
|
506
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
473
507
|
*/
|
474
508
|
export const storefront_with_products = (eb, sf_id_or_handle, sql_type) => {
|
475
509
|
return jsonArrayFrom(
|
@@ -500,7 +534,7 @@ export const storefront_with_products = (eb, sf_id_or_handle, sql_type) => {
|
|
500
534
|
*
|
501
535
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
502
536
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
503
|
-
* @param {import('../types.public.
|
537
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
504
538
|
*/
|
505
539
|
export const storefront_with_discounts = (eb, sf_id_or_handle, sql_type) => {
|
506
540
|
return jsonArrayFrom(
|
@@ -527,7 +561,7 @@ export const storefront_with_discounts = (eb, sf_id_or_handle, sql_type) => {
|
|
527
561
|
*
|
528
562
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
529
563
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
530
|
-
* @param {import('../types.public.
|
564
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
531
565
|
*/
|
532
566
|
export const storefront_with_posts = (eb, sf_id_or_handle, sql_type) => {
|
533
567
|
return jsonArrayFrom(
|
@@ -551,7 +585,7 @@ export const storefront_with_posts = (eb, sf_id_or_handle, sql_type) => {
|
|
551
585
|
*
|
552
586
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
553
587
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
554
|
-
* @param {import('../types.public.
|
588
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
555
589
|
*/
|
556
590
|
export const storefront_with_shipping = (eb, sf_id_or_handle, sql_type) => {
|
557
591
|
return jsonArrayFrom(
|
package/src/con.shipping.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { SQL } from '../
|
1
|
+
import { SQL } from '../index.js'
|
2
2
|
import { report_document_media } from './con.images.js'
|
3
3
|
import { count_regular, delete_entity_values_by_value_or_reporter,
|
4
4
|
delete_me, delete_media_of, delete_search_of,
|
@@ -9,7 +9,7 @@ import { sanitize_array } from './utils.funcs.js'
|
|
9
9
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
10
10
|
|
11
11
|
/**
|
12
|
-
* @typedef {import('@storecraft/core/
|
12
|
+
* @typedef {import('@storecraft/core/database').db_shipping} db_col
|
13
13
|
*/
|
14
14
|
export const table_name = 'shipping_methods'
|
15
15
|
|
package/src/con.storefronts.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { SQL } from '../
|
1
|
+
import { SQL } from '../index.js'
|
2
2
|
import { report_document_media } from './con.images.js'
|
3
3
|
import { delete_entity_values_of_by_entity_id_or_handle,
|
4
4
|
delete_me, delete_media_of, delete_search_of,
|
@@ -13,7 +13,7 @@ import { sanitize_array } from './utils.funcs.js'
|
|
13
13
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
14
14
|
|
15
15
|
/**
|
16
|
-
* @typedef {import('@storecraft/core/
|
16
|
+
* @typedef {import('@storecraft/core/database').db_storefronts} db_col
|
17
17
|
*/
|
18
18
|
export const table_name = 'storefronts'
|
19
19
|
|
package/src/con.tags.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { SQL } from '../
|
1
|
+
import { SQL } from '../index.js'
|
2
2
|
import { count_regular, delete_me, delete_search_of, insert_search_of,
|
3
3
|
regular_upsert_me, where_id_or_handle_table } from './con.shared.js'
|
4
4
|
import { sanitize_array } from './utils.funcs.js'
|
5
5
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
6
6
|
|
7
7
|
/**
|
8
|
-
* @typedef {import('@storecraft/core/
|
8
|
+
* @typedef {import('@storecraft/core/database').db_tags} db_col
|
9
9
|
*/
|
10
10
|
export const table_name = 'tags'
|
11
11
|
|
package/src/con.templates.js
CHANGED
@@ -1,15 +1,28 @@
|
|
1
1
|
import { Kysely } from 'kysely'
|
2
|
-
import { SQL } from '../
|
2
|
+
import { SQL } from '../index.js'
|
3
3
|
import { count_regular, delete_me, delete_search_of, insert_search_of,
|
4
|
-
regular_upsert_me, where_id_or_handle_table } from './con.shared.js'
|
4
|
+
regular_upsert_me, safe_trx, where_id_or_handle_table } from './con.shared.js'
|
5
5
|
import { sanitize_array } from './utils.funcs.js'
|
6
6
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
7
|
+
import { base64 } from '@storecraft/core/crypto';
|
7
8
|
|
8
9
|
/**
|
9
|
-
* @typedef {import('@storecraft/core/
|
10
|
+
* @typedef {import('@storecraft/core/database').db_templates} db_col
|
10
11
|
*/
|
11
12
|
export const table_name = 'templates'
|
12
13
|
|
14
|
+
/**
|
15
|
+
* @description if `base64_` prefixed then decode the postfix and return it,
|
16
|
+
* otherwise, just return the original value.
|
17
|
+
* @param {string} val
|
18
|
+
*/
|
19
|
+
const decode_if_base64 = val => {
|
20
|
+
if(!val.startsWith('base64_'))
|
21
|
+
return val;
|
22
|
+
|
23
|
+
const b64 = val.split('base64_').at(1) ?? '';
|
24
|
+
return base64.decode(b64);
|
25
|
+
}
|
13
26
|
|
14
27
|
/**
|
15
28
|
* @param {Kysely<import('../index.js').Database>} client
|
@@ -20,8 +33,9 @@ export const table_name = 'templates'
|
|
20
33
|
export const upsert = (client) => {
|
21
34
|
return async (item, search_terms) => {
|
22
35
|
try {
|
23
|
-
const
|
36
|
+
const t2 = await safe_trx(client).execute(
|
24
37
|
async (trx) => {
|
38
|
+
|
25
39
|
await insert_search_of(trx, search_terms, item.id, item.handle, table_name);
|
26
40
|
await regular_upsert_me(trx, table_name, {
|
27
41
|
created_at: item.created_at,
|
@@ -29,12 +43,13 @@ export const upsert = (client) => {
|
|
29
43
|
id: item.id,
|
30
44
|
title: item.title,
|
31
45
|
handle: item.handle,
|
32
|
-
template_html: item.template_html,
|
33
|
-
template_text: item.template_text,
|
46
|
+
template_html: decode_if_base64(item.template_html),
|
47
|
+
template_text: decode_if_base64(item.template_text),
|
34
48
|
reference_example_input: JSON.stringify(item.reference_example_input ?? {})
|
35
49
|
});
|
36
50
|
}
|
37
|
-
)
|
51
|
+
)
|
52
|
+
|
38
53
|
} catch(e) {
|
39
54
|
console.log(e);
|
40
55
|
return false;
|
package/src/utils.query.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @typedef {import("../index.js").Database} Database
|
3
3
|
*/
|
4
4
|
|
5
|
-
import { parse } from "@storecraft/core/
|
5
|
+
import { parse } from "@storecraft/core/vql";
|
6
6
|
|
7
7
|
/**
|
8
8
|
* Convert an API Query cursor into mongo dialect, also sanitize.
|
@@ -13,7 +13,7 @@ import { parse } from "@storecraft/core/v-ql";
|
|
13
13
|
* 4. (a1, a2, a3) >= (b1, b2, b3) ==> (a1 > b1) || (a1=b1 & a2>b2) || (a1=b1 & a2=b2 & a3>=b3)
|
14
14
|
*
|
15
15
|
* @param {import("kysely").ExpressionBuilder<Database>} eb
|
16
|
-
* @param {import("@storecraft/core/
|
16
|
+
* @param {import("@storecraft/core/api").Cursor} c
|
17
17
|
* @param {'>' | '>=' | '<' | '<='} relation
|
18
18
|
* @param {(x: [k: string, v: any]) => [k: string, v: any]} transformer Your chance to change key and value
|
19
19
|
*/
|
@@ -73,7 +73,7 @@ export const query_cursor_to_eb = (eb, c, relation, transformer=(x)=>x) => {
|
|
73
73
|
|
74
74
|
/**
|
75
75
|
* @param {import("kysely").ExpressionBuilder<Database>} eb
|
76
|
-
* @param {import("@storecraft/core/
|
76
|
+
* @param {import("@storecraft/core/vql").VQL.Node} node
|
77
77
|
* @param {keyof Database} table_name
|
78
78
|
*/
|
79
79
|
export const query_vql_node_to_eb = (eb, node, table_name) => {
|
@@ -120,7 +120,7 @@ export const query_vql_node_to_eb = (eb, node, table_name) => {
|
|
120
120
|
|
121
121
|
/**
|
122
122
|
* @param {import("kysely").ExpressionBuilder<Database>} eb
|
123
|
-
* @param {import("@storecraft/core/
|
123
|
+
* @param {import("@storecraft/core/vql").VQL.Node} root
|
124
124
|
* @param {keyof Database} table_name
|
125
125
|
*/
|
126
126
|
export const query_vql_to_eb = (eb, root, table_name) => {
|
@@ -133,7 +133,7 @@ export const query_vql_to_eb = (eb, root, table_name) => {
|
|
133
133
|
*
|
134
134
|
*
|
135
135
|
* @param {import("kysely").ExpressionBuilder<Database>} eb
|
136
|
-
* @param {import("@storecraft/core/
|
136
|
+
* @param {import("@storecraft/core/api").ApiQuery} q
|
137
137
|
* @param {keyof Database} table_name
|
138
138
|
*
|
139
139
|
*/
|
@@ -177,7 +177,7 @@ const SIGN = {
|
|
177
177
|
/**
|
178
178
|
* Convert an API Query into mongo dialect, also sanitize.
|
179
179
|
*
|
180
|
-
* @param {import("@storecraft/core/
|
180
|
+
* @param {import("@storecraft/core/api").ApiQuery} q
|
181
181
|
*/
|
182
182
|
export const query_to_sort = (q={}) => {
|
183
183
|
// const sort_sign = q.order === 'asc' ? 'asc' : 'desc';
|
@@ -1,11 +1,16 @@
|
|
1
1
|
import { App } from '@storecraft/core';
|
2
2
|
import { SQL } from '@storecraft/database-sql-base';
|
3
|
-
import {
|
4
|
-
import
|
3
|
+
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
|
4
|
+
import { NodePlatform } from '@storecraft/core/platform/node';
|
5
|
+
import { api } from '@storecraft/core/test-runner'
|
5
6
|
import { MssqlDialect } from 'kysely';
|
6
7
|
import * as Tedious from 'tedious';
|
7
8
|
import * as Tarn from 'tarn';
|
8
9
|
|
10
|
+
/**
|
11
|
+
* NOTE: NON FUNCTIONAL YET
|
12
|
+
*/
|
13
|
+
|
9
14
|
const dialect = new MssqlDialect({
|
10
15
|
tarn: {
|
11
16
|
...Tarn,
|
@@ -42,26 +47,25 @@ export const create_app = async () => {
|
|
42
47
|
}),
|
43
48
|
null, null, {
|
44
49
|
auth_admins_emails: ['admin@sc.com'],
|
45
|
-
auth_password_hash_rounds: 100,
|
46
50
|
auth_secret_access_token: 'auth_secret_access_token',
|
47
51
|
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
48
52
|
}
|
49
53
|
);
|
50
54
|
|
51
55
|
await app.init();
|
52
|
-
await app.db
|
56
|
+
await migrateToLatest(app.db, false);
|
53
57
|
return app;
|
54
58
|
}
|
55
59
|
|
56
60
|
async function test() {
|
57
61
|
const app = await create_app();
|
58
62
|
|
59
|
-
Object.entries(
|
63
|
+
Object.entries(api).slice(0, -1).forEach(
|
60
64
|
([name, runner]) => {
|
61
65
|
runner.create(app).run();
|
62
66
|
}
|
63
67
|
);
|
64
|
-
const last_test = Object.values(
|
68
|
+
const last_test = Object.values(api).at(-1).create(app);
|
65
69
|
last_test.after(async () => { await app.db.disconnect() });
|
66
70
|
last_test.run();
|
67
71
|
}
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { App } from '@storecraft/core';
|
2
2
|
import { SQL } from '@storecraft/database-sql-base';
|
3
|
-
import {
|
4
|
-
import
|
3
|
+
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
|
4
|
+
import { NodePlatform } from '@storecraft/core/platform/node';
|
5
|
+
import { api } from '@storecraft/core/test-runner'
|
5
6
|
import { MysqlDialect } from 'kysely';
|
6
7
|
import { createPool } from 'mysql2'
|
7
8
|
|
@@ -16,22 +17,23 @@ export const dialect = new MysqlDialect({
|
|
16
17
|
});
|
17
18
|
|
18
19
|
export const create_app = async () => {
|
19
|
-
|
20
|
-
|
21
|
-
new SQL({
|
22
|
-
dialect: dialect,
|
23
|
-
dialect_type: 'MYSQL'
|
24
|
-
}),
|
25
|
-
null, null, {
|
20
|
+
const app = new App(
|
21
|
+
{
|
26
22
|
auth_admins_emails: ['admin@sc.com'],
|
27
|
-
auth_password_hash_rounds: 100,
|
28
23
|
auth_secret_access_token: 'auth_secret_access_token',
|
29
24
|
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
30
25
|
}
|
31
|
-
)
|
26
|
+
)
|
27
|
+
.withPlatform(new NodePlatform())
|
28
|
+
.withDatabase(
|
29
|
+
new SQL({
|
30
|
+
dialect: dialect,
|
31
|
+
dialect_type: 'MYSQL'
|
32
|
+
})
|
33
|
+
)
|
32
34
|
|
33
35
|
await app.init();
|
34
|
-
await app.db
|
36
|
+
await migrateToLatest(app.db, false);
|
35
37
|
|
36
38
|
return app;
|
37
39
|
}
|
@@ -39,63 +41,14 @@ export const create_app = async () => {
|
|
39
41
|
async function test() {
|
40
42
|
const app = await create_app();
|
41
43
|
|
42
|
-
Object.entries(
|
44
|
+
Object.entries(api).slice(0, -1).forEach(
|
43
45
|
([name, runner]) => {
|
44
46
|
runner.create(app).run();
|
45
47
|
}
|
46
48
|
);
|
47
|
-
const last_test = Object.values(
|
49
|
+
const last_test = Object.values(api).at(-1).create(app);
|
48
50
|
last_test.after(async () => { await app.db.disconnect() });
|
49
51
|
last_test.run();
|
50
52
|
}
|
51
53
|
|
52
54
|
test();
|
53
|
-
|
54
|
-
async function test2() {
|
55
|
-
const app = await create_app();
|
56
|
-
|
57
|
-
// api_index.api_auth_test.create(app).run();
|
58
|
-
|
59
|
-
// api_index.api_tags_crud_test.create(app).run();
|
60
|
-
// api_index.api_tags_list_test.create(app).run();
|
61
|
-
|
62
|
-
// api_index.api_collections_crud_test.create(app).run();
|
63
|
-
// api_index.api_collections_list_test.create(app).run();
|
64
|
-
// api_index.api_collections_products_test.create(app).run();
|
65
|
-
|
66
|
-
// api_index.api_products_crud_test.create(app).run();
|
67
|
-
// api_index.api_products_collections_test.create(app).run();
|
68
|
-
// api_index.api_products_list_test.create(app).run();
|
69
|
-
// api_index.api_products_discounts_test.create(app).run();
|
70
|
-
// api_index.api_products_variants_test.create(app).run();
|
71
|
-
|
72
|
-
// api_index.api_shipping_crud_test.create(app).run();
|
73
|
-
// api_index.api_shipping_list_test.create(app).run();
|
74
|
-
|
75
|
-
// api_index.api_posts_crud_test.create(app).run();
|
76
|
-
// api_index.api_posts_list_test.create(app).run();
|
77
|
-
|
78
|
-
// api_index.api_customers_crud_test.create(app).run();
|
79
|
-
// api_index.api_customers_list_test.create(app).run();
|
80
|
-
|
81
|
-
api_index.api_orders_crud_test.create(app).run();
|
82
|
-
api_index.api_orders_list_test.create(app).run();
|
83
|
-
|
84
|
-
api_index.api_storefronts_crud_test.create(app).run();
|
85
|
-
api_index.api_storefronts_list_test.create(app).run();
|
86
|
-
api_index.api_storefronts_all_connections_test.create(app).run();
|
87
|
-
|
88
|
-
api_index.api_notifications_crud_test.create(app).run();
|
89
|
-
api_index.api_notifications_list_test.create(app).run();
|
90
|
-
|
91
|
-
api_index.api_images_crud_test.create(app).run();
|
92
|
-
api_index.api_images_list_test.create(app).run();
|
93
|
-
|
94
|
-
api_index.api_discounts_crud_test.create(app).run();
|
95
|
-
api_index.api_discounts_list_test.create(app).run();
|
96
|
-
api_index.api_discounts_products_test.create(app).run();
|
97
|
-
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
// test2();
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { App } from '@storecraft/core';
|
2
2
|
import { SQL } from '@storecraft/database-sql-base';
|
3
|
-
import {
|
4
|
-
import
|
3
|
+
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
|
4
|
+
import { NodePlatform } from '@storecraft/core/platform/node';
|
5
|
+
import { api } from '@storecraft/core/test-runner'
|
5
6
|
import { PostgresDialect } from 'kysely';
|
6
7
|
import pg from 'pg'
|
7
8
|
|
@@ -15,85 +16,39 @@ const pg_dialect = new PostgresDialect({
|
|
15
16
|
});
|
16
17
|
|
17
18
|
export const create_app = async () => {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
dialect: pg_dialect,
|
22
|
-
dialect_type: 'POSTGRES'
|
23
|
-
}),
|
24
|
-
null, null, {
|
19
|
+
|
20
|
+
const app = new App(
|
21
|
+
{
|
25
22
|
auth_admins_emails: ['admin@sc.com'],
|
26
|
-
auth_password_hash_rounds: 100,
|
27
23
|
auth_secret_access_token: 'auth_secret_access_token',
|
28
24
|
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
29
25
|
}
|
26
|
+
)
|
27
|
+
.withPlatform(new NodePlatform())
|
28
|
+
.withDatabase(
|
29
|
+
new SQL({
|
30
|
+
dialect: pg_dialect,
|
31
|
+
dialect_type: 'POSTGRES'
|
32
|
+
})
|
30
33
|
);
|
31
34
|
|
32
35
|
await app.init();
|
33
|
-
await app.db
|
36
|
+
await migrateToLatest(app.db, false);
|
37
|
+
|
34
38
|
return app;
|
35
39
|
}
|
36
40
|
|
37
41
|
async function test() {
|
38
42
|
const app = await create_app();
|
39
43
|
|
40
|
-
Object.entries(
|
44
|
+
Object.entries(api).slice(0, -1).forEach(
|
41
45
|
([name, runner]) => {
|
42
46
|
runner.create(app).run();
|
43
47
|
}
|
44
48
|
);
|
45
|
-
const last_test = Object.values(
|
49
|
+
const last_test = Object.values(api).at(-1).create(app);
|
46
50
|
last_test.after(async () => { await app.db.disconnect() });
|
47
51
|
last_test.run();
|
48
52
|
}
|
49
53
|
|
50
54
|
test();
|
51
|
-
|
52
|
-
async function test2() {
|
53
|
-
const app = await create_app();
|
54
|
-
|
55
|
-
api_index.api_auth_test.create(app).run();
|
56
|
-
|
57
|
-
api_index.api_tags_crud_test.create(app).run();
|
58
|
-
api_index.api_tags_list_test.create(app).run();
|
59
|
-
|
60
|
-
api_index.api_collections_crud_test.create(app).run();
|
61
|
-
api_index.api_collections_list_test.create(app).run();
|
62
|
-
api_index.api_collections_products_test.create(app).run();
|
63
|
-
|
64
|
-
api_index.api_products_crud_test.create(app).run();
|
65
|
-
api_index.api_products_collections_test.create(app).run();
|
66
|
-
api_index.api_products_list_test.create(app).run();
|
67
|
-
api_index.api_products_discounts_test.create(app).run();
|
68
|
-
api_index.api_products_variants_test.create(app).run();
|
69
|
-
|
70
|
-
api_index.api_shipping_crud_test.create(app).run();
|
71
|
-
api_index.api_shipping_list_test.create(app).run();
|
72
|
-
|
73
|
-
api_index.api_posts_crud_test.create(app).run();
|
74
|
-
api_index.api_posts_list_test.create(app).run();
|
75
|
-
|
76
|
-
api_index.api_customers_crud_test.create(app).run();
|
77
|
-
api_index.api_customers_list_test.create(app).run();
|
78
|
-
|
79
|
-
api_index.api_orders_crud_test.create(app).run();
|
80
|
-
api_index.api_orders_list_test.create(app).run();
|
81
|
-
|
82
|
-
api_index.api_storefronts_crud_test.create(app).run();
|
83
|
-
api_index.api_storefronts_list_test.create(app).run();
|
84
|
-
api_index.api_storefronts_all_connections_test.create(app).run();
|
85
|
-
|
86
|
-
api_index.api_notifications_crud_test.create(app).run();
|
87
|
-
api_index.api_notifications_list_test.create(app).run();
|
88
|
-
|
89
|
-
api_index.api_images_crud_test.create(app).run();
|
90
|
-
api_index.api_images_list_test.create(app).run();
|
91
|
-
|
92
|
-
api_index.api_discounts_crud_test.create(app).run();
|
93
|
-
api_index.api_discounts_list_test.create(app).run();
|
94
|
-
api_index.api_discounts_products_test.create(app).run();
|
95
|
-
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
// test2();
|