@storecraft/database-sql-base 1.0.1 → 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.
@@ -1,4 +1,4 @@
1
- import { SQL } from '../driver.js'
1
+ import { SQL } from '../index.js'
2
2
  import { sanitize_array } from './utils.funcs.js'
3
3
  import { count_regular, delete_me, insert_search_of, insert_tags_of, regular_upsert_me,
4
4
  where_id_or_handle_table,
@@ -7,7 +7,7 @@ import { count_regular, delete_me, insert_search_of, insert_tags_of, regular_ups
7
7
  import { query_to_eb, query_to_sort } from './utils.query.js';
8
8
 
9
9
  /**
10
- * @typedef {import('@storecraft/core/v-database').db_auth_users} db_col
10
+ * @typedef {import('@storecraft/core/database').db_auth_users} db_col
11
11
  */
12
12
 
13
13
  export const table_name = 'auth_users';
@@ -36,6 +36,8 @@ const upsert = (driver) => {
36
36
  updated_at: item.updated_at,
37
37
  id: item.id,
38
38
  roles: JSON.stringify(item.roles),
39
+ firstname: item.firstname,
40
+ lastname: item.lastname
39
41
  });
40
42
  }
41
43
  );
@@ -1,4 +1,4 @@
1
- import { SQL } from '../driver.js'
1
+ import { SQL } from '../index.js'
2
2
  import { report_document_media } from './con.images.js'
3
3
  import { delete_entity_values_by_value_or_reporter, delete_me,
4
4
  delete_media_of, delete_search_of, delete_tags_of,
@@ -12,7 +12,7 @@ import { query_to_eb, query_to_sort } from './utils.query.js'
12
12
 
13
13
 
14
14
  /**
15
- * @typedef {import('@storecraft/core/v-database').db_collections} db_col
15
+ * @typedef {import('@storecraft/core/database').db_collections} db_col
16
16
  */
17
17
  export const table_name = 'collections'
18
18
 
@@ -1,4 +1,4 @@
1
- import { SQL } from '../driver.js'
1
+ import { SQL } from '../index.js'
2
2
  import { report_document_media } from './con.images.js'
3
3
  import { count_regular, delete_me, delete_media_of, delete_search_of,
4
4
  delete_tags_of, insert_media_of, insert_search_of,
@@ -8,7 +8,7 @@ import { sanitize_array } from './utils.funcs.js'
8
8
  import { query_to_eb, query_to_sort } from './utils.query.js'
9
9
 
10
10
  /**
11
- * @typedef {import('@storecraft/core/v-database').db_customers} db_col
11
+ * @typedef {import('@storecraft/core/database').db_customers} db_col
12
12
  */
13
13
  export const table_name = 'customers'
14
14
 
@@ -1,5 +1,5 @@
1
- import { enums } from '@storecraft/core/v-api'
2
- import { SQL } from '../driver.js'
1
+ import { enums } from '@storecraft/core/api'
2
+ import { SQL } from '../index.js'
3
3
  import { discount_to_conjunctions } from './con.discounts.utils.js'
4
4
  import { delete_entity_values_by_value_or_reporter,
5
5
  delete_me, delete_media_of, delete_search_of,
@@ -12,7 +12,7 @@ import { query_to_eb, query_to_sort } from './utils.query.js'
12
12
  import { report_document_media } from './con.images.js'
13
13
 
14
14
  /**
15
- * @typedef {import('@storecraft/core/v-database').db_discounts} db_col
15
+ * @typedef {import('@storecraft/core/database').db_discounts} db_col
16
16
  */
17
17
  export const table_name = 'discounts'
18
18
 
@@ -1,11 +1,11 @@
1
- import { enums } from "@storecraft/core/v-api";
1
+ import { enums } from "@storecraft/core/api";
2
2
 
3
- /** @param {import("@storecraft/core/v-api").DiscountType} d */
3
+ /** @param {import("@storecraft/core/api").DiscountType} d */
4
4
  const is_order_discount = d => {
5
5
  return (d.info.details.meta.id===enums.DiscountMetaEnum.order.id);
6
6
  }
7
7
 
8
- /** @param {import("@storecraft/core/v-api").DiscountType} d */
8
+ /** @param {import("@storecraft/core/api").DiscountType} d */
9
9
  const is_automatic_discount = d => {
10
10
  return (d.application.id===enums.DiscountApplicationEnum.Auto.id);
11
11
  }
@@ -43,7 +43,7 @@ const eb_in = (eb, table, op, value) => {
43
43
  * create a mongodb conjunctions clauses from discount, intended
44
44
  * for filtering.
45
45
  * @param {import("kysely").ExpressionBuilder<Database, 'products'>} eb
46
- * @param {import("@storecraft/core/v-api").DiscountType} d
46
+ * @param {import("@storecraft/core/api").DiscountType} d
47
47
  */
48
48
  export const discount_to_conjunctions = (eb, d) => {
49
49
  // discount has to be product discount + automatic + active + has filters
@@ -66,7 +66,7 @@ export const discount_to_conjunctions = (eb, d) => {
66
66
  break;
67
67
  case enums.FilterMetaEnum.p_in_products.op:
68
68
  {
69
- /** @type {import("@storecraft/core/v-api").FilterValue_p_in_products} */
69
+ /** @type {import("@storecraft/core/api").FilterValue_p_in_products} */
70
70
  const cast = Array.isArray(filter?.value) ? filter.value : [];
71
71
 
72
72
  conjunctions.push(
@@ -79,7 +79,7 @@ export const discount_to_conjunctions = (eb, d) => {
79
79
  break;
80
80
  case enums.FilterMetaEnum.p_not_in_products.op:
81
81
  {
82
- /** @type {import("@storecraft/core/v-api").FilterValue_p_not_in_products} */
82
+ /** @type {import("@storecraft/core/api").FilterValue_p_not_in_products} */
83
83
  const cast = Array.isArray(filter?.value) ? filter.value : [];
84
84
 
85
85
  conjunctions.push(
@@ -92,7 +92,7 @@ export const discount_to_conjunctions = (eb, d) => {
92
92
  break;
93
93
  case enums.FilterMetaEnum.p_in_tags.op:
94
94
  {
95
- /** @type {import("@storecraft/core/v-api").FilterValue_p_in_tags} */
95
+ /** @type {import("@storecraft/core/api").FilterValue_p_in_tags} */
96
96
  const cast = Array.isArray(filter?.value) ? filter.value : [];
97
97
 
98
98
  conjunctions.push(
@@ -105,7 +105,7 @@ export const discount_to_conjunctions = (eb, d) => {
105
105
  break;
106
106
  case enums.FilterMetaEnum.p_not_in_tags.op:
107
107
  {
108
- /** @type {import("@storecraft/core/v-api").FilterValue_p_not_in_tags} */
108
+ /** @type {import("@storecraft/core/api").FilterValue_p_not_in_tags} */
109
109
  const cast = Array.isArray(filter?.value) ? filter.value : [];
110
110
 
111
111
  conjunctions.push(
@@ -120,7 +120,7 @@ export const discount_to_conjunctions = (eb, d) => {
120
120
  break;
121
121
  case enums.FilterMetaEnum.p_in_collections.op:
122
122
  {
123
- /** @type {import("@storecraft/core/v-api").FilterValue_p_in_collections} */
123
+ /** @type {import("@storecraft/core/api").FilterValue_p_in_collections} */
124
124
  const cast = Array.isArray(filter?.value) ? filter.value : [];
125
125
 
126
126
  // PROBLEM: we only have ids, but use handles in the filters
@@ -134,7 +134,7 @@ export const discount_to_conjunctions = (eb, d) => {
134
134
  break;
135
135
  case enums.FilterMetaEnum.p_not_in_collections.op:
136
136
  {
137
- /** @type {import("@storecraft/core/v-api").FilterValue_p_not_in_collections} */
137
+ /** @type {import("@storecraft/core/api").FilterValue_p_not_in_collections} */
138
138
  const cast = Array.isArray(filter?.value) ? filter.value : [];
139
139
 
140
140
  conjunctions.push(
@@ -149,7 +149,7 @@ export const discount_to_conjunctions = (eb, d) => {
149
149
  break;
150
150
  case enums.FilterMetaEnum.p_in_price_range.op:
151
151
  {
152
- /** @type {import("@storecraft/core/v-api").FilterValue_p_in_price_range} */
152
+ /** @type {import("@storecraft/core/api").FilterValue_p_in_price_range} */
153
153
  const cast = {
154
154
  from: 0,
155
155
  to: Number.POSITIVE_INFINITY,
package/src/con.images.js CHANGED
@@ -1,18 +1,18 @@
1
- import { func } from '@storecraft/core/v-api'
2
- import { SQL } from '../driver.js'
1
+ import { func } from '@storecraft/core/api'
2
+ import { SQL } from '../index.js'
3
3
  import { count_regular, delete_me, delete_search_of,
4
4
  insert_search_of, regular_upsert_me, where_id_or_handle_table
5
5
  } from './con.shared.js'
6
6
  import { sanitize_array } from './utils.funcs.js'
7
7
  import { query_to_eb, query_to_sort } from './utils.query.js'
8
8
  import { Transaction } from 'kysely'
9
- import { ID } from '@storecraft/core/v-api/utils.func.js'
9
+ import { ID } from '@storecraft/core/api/utils.func.js'
10
10
  import {
11
11
  image_url_to_handle, image_url_to_name
12
- } from '@storecraft/core/v-api/con.images.logic.js'
12
+ } from '@storecraft/core/api/con.images.logic.js'
13
13
 
14
14
  /**
15
- * @typedef {import('@storecraft/core/v-database').db_images} db_col
15
+ * @typedef {import('@storecraft/core/database').db_images} db_col
16
16
  */
17
17
  export const table_name = 'images'
18
18
 
@@ -1,4 +1,4 @@
1
- import { SQL } from '../driver.js'
1
+ import { SQL } from '../index.js'
2
2
  import { count_regular, delete_me, delete_search_of,
3
3
  insert_search_of, regular_upsert_me, where_id_or_handle_table,
4
4
  with_search } from './con.shared.js'
@@ -6,7 +6,7 @@ import { sanitize_array } from './utils.funcs.js'
6
6
  import { query_to_eb, query_to_sort } from './utils.query.js'
7
7
 
8
8
  /**
9
- * @typedef {import('@storecraft/core/v-database').db_notifications} db_col
9
+ * @typedef {import('@storecraft/core/database').db_notifications} db_col
10
10
  */
11
11
  export const table_name = 'notifications'
12
12
 
package/src/con.orders.js CHANGED
@@ -1,4 +1,4 @@
1
- import { SQL } from '../driver.js'
1
+ import { SQL } from '../index.js'
2
2
  import { report_document_media } from './con.images.js'
3
3
  import { count_regular, delete_me, delete_media_of, delete_search_of,
4
4
  delete_tags_of, insert_media_of, insert_search_of,
@@ -8,7 +8,7 @@ import { sanitize_array } from './utils.funcs.js'
8
8
  import { query_to_eb, query_to_sort } from './utils.query.js'
9
9
 
10
10
  /**
11
- * @typedef {import('@storecraft/core/v-database').db_orders} db_col
11
+ * @typedef {import('@storecraft/core/database').db_orders} db_col
12
12
  */
13
13
  export const table_name = 'orders'
14
14
 
package/src/con.posts.js CHANGED
@@ -1,4 +1,4 @@
1
- import { SQL } from '../driver.js'
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, delete_tags_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/v-database').db_posts} db_col
12
+ * @typedef {import('@storecraft/core/database').db_posts} db_col
13
13
  */
14
14
  export const table_name = 'posts'
15
15
 
@@ -1,5 +1,5 @@
1
- import { enums } from '@storecraft/core/v-api'
2
- import { SQL } from '../driver.js'
1
+ import { enums } from '@storecraft/core/api'
2
+ import { SQL } from '../index.js'
3
3
  import { delete_entity_values_of_by_entity_id_or_handle, delete_me, delete_media_of,
4
4
  delete_search_of, delete_tags_of,
5
5
  insert_entity_values_of, insert_media_of, insert_search_of,
@@ -18,7 +18,7 @@ import { report_document_media } from './con.images.js'
18
18
 
19
19
 
20
20
  /**
21
- * @typedef {import('@storecraft/core/v-database').db_products} db_col
21
+ * @typedef {import('@storecraft/core/database').db_products} db_col
22
22
  */
23
23
  export const table_name = 'products'
24
24
 
@@ -247,8 +247,8 @@ const getBulk = (driver) => {
247
247
  */
248
248
  const remove_internal = (driver) => {
249
249
  /**
250
- * @param {import('@storecraft/core/v-api').ProductType |
251
- * import('@storecraft/core/v-api').VariantType
250
+ * @param {import('@storecraft/core/api').ProductType |
251
+ * import('@storecraft/core/api').VariantType
252
252
  * } product
253
253
  * @param {Transaction<import('../index.js').Database>} trx
254
254
  */
package/src/con.search.js CHANGED
@@ -1,15 +1,15 @@
1
- import { SQL } from '../driver.js'
1
+ import { SQL } from '../index.js'
2
2
  import { jsonArrayFrom } from './con.helpers.json.js';
3
3
  import { query_to_eb, query_to_sort } from './utils.query.js';
4
4
 
5
5
  /**
6
- * @typedef {import('@storecraft/core/v-database').search} db_col
6
+ * @typedef {import('@storecraft/core/database').search} db_col
7
7
  */
8
8
 
9
9
 
10
10
 
11
11
  /**
12
- * @type {(keyof import('@storecraft/core/v-database').db_driver["resources"])[]}
12
+ * @type {(keyof import('@storecraft/core/database').db_driver["resources"])[]}
13
13
  */
14
14
  const tables = [
15
15
  'tags',
@@ -27,7 +27,7 @@ const tables = [
27
27
  ]
28
28
 
29
29
  /**
30
- * @type {Record<string, keyof import('@storecraft/core/v-database').db_driver["resources"]>}
30
+ * @type {Record<string, keyof import('@storecraft/core/database').db_driver["resources"]>}
31
31
  */
32
32
  const prefix_to_resource = {
33
33
  'au': 'auth_users',
@@ -47,7 +47,7 @@ const prefix_to_resource = {
47
47
  }
48
48
 
49
49
  /**
50
- * @type {Record<keyof import('@storecraft/core/v-database').db_driver["resources"], string[]>}
50
+ * @type {Record<keyof import('@storecraft/core/database').db_driver["resources"], string[]>}
51
51
  */
52
52
  const resource_to_props = {
53
53
  'auth_users': ['id', 'handle'],
@@ -68,7 +68,7 @@ const resource_to_props = {
68
68
  *
69
69
  * @param {string} id
70
70
  *
71
- * @returns {keyof import('@storecraft/core/v-database').db_driver["resources"]}
71
+ * @returns {keyof import('@storecraft/core/database').db_driver["resources"]}
72
72
  */
73
73
  export const id_to_resource = id => {
74
74
  let result = undefined;
@@ -119,7 +119,7 @@ export const quicksearch = (driver) => {
119
119
  )
120
120
  )
121
121
 
122
- /** @type {import('@storecraft/core/v-api').QuickSearchResult} */
122
+ /** @type {import('@storecraft/core/api').QuickSearchResult} */
123
123
  const items = await sts.executeTakeFirst();
124
124
 
125
125
  const sanitized = Object.fromEntries(
@@ -83,7 +83,7 @@ const trans_or_batch = (driver) => {
83
83
  * @param {SQL} driver
84
84
  * @param {keyof Database} table_name
85
85
  *
86
- * @returns {import('@storecraft/core/v-database').db_crud["count"]}
86
+ * @returns {import('@storecraft/core/database').db_crud["count"]}
87
87
  */
88
88
  export const count_regular = (driver, table_name) => {
89
89
  return async (query) => {
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/v-database').db_crud["count"]}
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 {Transaction<Database>} trx
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 {Transaction<import('../index.js').Database>} trx
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 {Transaction<Database>} trx
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 {Transaction<Database>} trx
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 {Transaction<Database>} trx
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 {Transaction<Database>} trx
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 {Transaction<Database>} trx
295
+ * @param {Kysely<Database>} trx
262
296
  * @param {keyof Database} table_name
263
297
  * @param {string} id_or_handle
264
298
  */
@@ -1,4 +1,4 @@
1
- import { SQL } from '../driver.js'
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/v-database').db_shipping} db_col
12
+ * @typedef {import('@storecraft/core/database').db_shipping} db_col
13
13
  */
14
14
  export const table_name = 'shipping_methods'
15
15
 
@@ -1,4 +1,4 @@
1
- import { SQL } from '../driver.js'
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/v-database').db_storefronts} db_col
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 '../driver.js'
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/v-database').db_tags} db_col
8
+ * @typedef {import('@storecraft/core/database').db_tags} db_col
9
9
  */
10
10
  export const table_name = 'tags'
11
11
 
@@ -1,15 +1,28 @@
1
1
  import { Kysely } from 'kysely'
2
- import { SQL } from '../driver.js'
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/v-database').db_templates} db_col
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 t = await client.transaction().execute(
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;
@@ -2,7 +2,7 @@
2
2
  * @typedef {import("../index.js").Database} Database
3
3
  */
4
4
 
5
- import { parse } from "@storecraft/core/v-ql";
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/v-api").Cursor} c
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/v-ql").VQL.Node} node
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/v-ql").VQL.Node} root
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/v-api").ApiQuery} q
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/v-api").ApiQuery} q
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,12 +1,16 @@
1
1
  import { App } from '@storecraft/core';
2
2
  import { SQL } from '@storecraft/database-sql-base';
3
3
  import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
4
- import { NodePlatform } from '@storecraft/platforms/node';
5
- import { api_index } from '@storecraft/test-runner'
4
+ import { NodePlatform } from '@storecraft/core/platform/node';
5
+ import { api } from '@storecraft/core/test-runner'
6
6
  import { MssqlDialect } from 'kysely';
7
7
  import * as Tedious from 'tedious';
8
8
  import * as Tarn from 'tarn';
9
9
 
10
+ /**
11
+ * NOTE: NON FUNCTIONAL YET
12
+ */
13
+
10
14
  const dialect = new MssqlDialect({
11
15
  tarn: {
12
16
  ...Tarn,
@@ -56,12 +60,12 @@ export const create_app = async () => {
56
60
  async function test() {
57
61
  const app = await create_app();
58
62
 
59
- Object.entries(api_index).slice(0, -1).forEach(
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(api_index).at(-1).create(app);
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
  }