@storecraft/database-sql-base 1.0.1 → 1.0.3

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,118 +1,122 @@
1
- import { App } from '@storecraft/core';
2
- import { SQL } from '@storecraft/database-sql-base';
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'
6
- import { MssqlDialect } from 'kysely';
7
- import * as Tedious from 'tedious';
8
- import * as Tarn from 'tarn';
9
-
10
- const dialect = new MssqlDialect({
11
- tarn: {
12
- ...Tarn,
13
- options: {
14
- min: 0,
15
- max: 10,
16
- },
17
- },
18
- tedious: {
19
- ...Tedious,
20
- connectionFactory: () => new Tedious.Connection({
21
- authentication: {
22
- options: {
23
- password: process.env.MSSQL_PASSWORD,
24
- userName: process.env.MSSQL_USER,
25
- },
26
- type: 'default',
27
- },
28
- options: {
29
- port: parseInt(process.env.MSSQL_PORT),
30
- trustServerCertificate: true,
31
- },
32
- server: process.env.MSSQL_HOST,
33
- }),
34
- },
35
- });
36
-
37
- export const create_app = async () => {
38
- let app = new App(
39
- new NodePlatform(),
40
- new SQL({
41
- dialect: dialect,
42
- dialect_type: 'MSSQL'
43
- }),
44
- null, null, {
45
- auth_admins_emails: ['admin@sc.com'],
46
- auth_secret_access_token: 'auth_secret_access_token',
47
- auth_secret_refresh_token: 'auth_secret_refresh_token'
48
- }
49
- );
50
-
51
- await app.init();
52
- await migrateToLatest(app.db, false);
53
- return app;
54
- }
55
-
56
- async function test() {
57
- const app = await create_app();
58
-
59
- Object.entries(api_index).slice(0, -1).forEach(
60
- ([name, runner]) => {
61
- runner.create(app).run();
62
- }
63
- );
64
- const last_test = Object.values(api_index).at(-1).create(app);
65
- last_test.after(async () => { await app.db.disconnect() });
66
- last_test.run();
67
- }
68
-
69
- test();
70
-
71
- async function test2() {
72
- const app = await create_app();
73
-
74
- // api_index.api_auth_test.create(app).run();
75
-
76
- // api_index.api_tags_crud_test.create(app).run();
77
- // api_index.api_tags_list_test.create(app).run();
78
-
79
- // api_index.api_collections_crud_test.create(app).run();
80
- // api_index.api_collections_list_test.create(app).run();
81
- // api_index.api_collections_products_test.create(app).run();
82
-
83
- // api_index.api_products_crud_test.create(app).run();
84
- // api_index.api_products_collections_test.create(app).run();
85
- // api_index.api_products_list_test.create(app).run();
86
- // api_index.api_products_discounts_test.create(app).run();
87
- // api_index.api_products_variants_test.create(app).run();
88
-
89
- // api_index.api_shipping_crud_test.create(app).run();
90
- // api_index.api_shipping_list_test.create(app).run();
91
-
92
- // api_index.api_posts_crud_test.create(app).run();
93
- // api_index.api_posts_list_test.create(app).run();
94
-
95
- // api_index.api_customers_crud_test.create(app).run();
96
- // api_index.api_customers_list_test.create(app).run();
97
-
98
- // api_index.api_orders_crud_test.create(app).run();
99
- // api_index.api_orders_list_test.create(app).run();
100
-
101
- // api_index.api_storefronts_crud_test.create(app).run();
102
- // api_index.api_storefronts_list_test.create(app).run();
103
- // api_index.api_storefronts_all_connections_test.create(app).run();
104
-
105
- // api_index.api_notifications_crud_test.create(app).run();
106
- // api_index.api_notifications_list_test.create(app).run();
107
-
108
- api_index.api_images_crud_test.create(app).run();
109
- api_index.api_images_list_test.create(app).run();
110
-
111
- // api_index.api_discounts_crud_test.create(app).run();
112
- // api_index.api_discounts_list_test.create(app).run();
113
- // api_index.api_discounts_products_test.create(app).run();
114
-
115
-
116
- }
117
-
118
- // test2();
1
+ // import { App } from '@storecraft/core';
2
+ // import { SQL } from '@storecraft/database-sql-base';
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'
6
+ // import { MssqlDialect } from 'kysely';
7
+ // import * as Tedious from 'tedious';
8
+ // import * as Tarn from 'tarn';
9
+
10
+ // /**
11
+ // * NOTE: NON FUNCTIONAL YET
12
+ // */
13
+
14
+ // const dialect = new MssqlDialect({
15
+ // tarn: {
16
+ // ...Tarn,
17
+ // options: {
18
+ // min: 0,
19
+ // max: 10,
20
+ // },
21
+ // },
22
+ // tedious: {
23
+ // ...Tedious,
24
+ // connectionFactory: () => new Tedious.Connection({
25
+ // authentication: {
26
+ // options: {
27
+ // password: process.env.MSSQL_PASSWORD,
28
+ // userName: process.env.MSSQL_USER,
29
+ // },
30
+ // type: 'default',
31
+ // },
32
+ // options: {
33
+ // port: parseInt(process.env.MSSQL_PORT),
34
+ // trustServerCertificate: true,
35
+ // },
36
+ // server: process.env.MSSQL_HOST,
37
+ // }),
38
+ // },
39
+ // });
40
+
41
+ // export const create_app = async () => {
42
+ // let app = new App(
43
+ // new NodePlatform(),
44
+ // new SQL({
45
+ // dialect: dialect,
46
+ // dialect_type: 'MSSQL'
47
+ // }),
48
+ // null, null, {
49
+ // auth_admins_emails: ['admin@sc.com'],
50
+ // auth_secret_access_token: 'auth_secret_access_token',
51
+ // auth_secret_refresh_token: 'auth_secret_refresh_token'
52
+ // }
53
+ // );
54
+
55
+ // await app.init();
56
+ // await migrateToLatest(app.db, false);
57
+ // return app;
58
+ // }
59
+
60
+ // async function test() {
61
+ // const app = await create_app();
62
+
63
+ // Object.entries(api).slice(0, -1).forEach(
64
+ // ([name, runner]) => {
65
+ // runner.create(app).run();
66
+ // }
67
+ // );
68
+ // const last_test = Object.values(api).at(-1).create(app);
69
+ // last_test.after(async () => { await app.db.disconnect() });
70
+ // last_test.run();
71
+ // }
72
+
73
+ // test();
74
+
75
+ // async function test2() {
76
+ // const app = await create_app();
77
+
78
+ // // api_index.api_auth_test.create(app).run();
79
+
80
+ // // api_index.api_tags_crud_test.create(app).run();
81
+ // // api_index.api_tags_list_test.create(app).run();
82
+
83
+ // // api_index.api_collections_crud_test.create(app).run();
84
+ // // api_index.api_collections_list_test.create(app).run();
85
+ // // api_index.api_collections_products_test.create(app).run();
86
+
87
+ // // api_index.api_products_crud_test.create(app).run();
88
+ // // api_index.api_products_collections_test.create(app).run();
89
+ // // api_index.api_products_list_test.create(app).run();
90
+ // // api_index.api_products_discounts_test.create(app).run();
91
+ // // api_index.api_products_variants_test.create(app).run();
92
+
93
+ // // api_index.api_shipping_crud_test.create(app).run();
94
+ // // api_index.api_shipping_list_test.create(app).run();
95
+
96
+ // // api_index.api_posts_crud_test.create(app).run();
97
+ // // api_index.api_posts_list_test.create(app).run();
98
+
99
+ // // api_index.api_customers_crud_test.create(app).run();
100
+ // // api_index.api_customers_list_test.create(app).run();
101
+
102
+ // // api_index.api_orders_crud_test.create(app).run();
103
+ // // api_index.api_orders_list_test.create(app).run();
104
+
105
+ // // api_index.api_storefronts_crud_test.create(app).run();
106
+ // // api_index.api_storefronts_list_test.create(app).run();
107
+ // // api_index.api_storefronts_all_connections_test.create(app).run();
108
+
109
+ // // api_index.api_notifications_crud_test.create(app).run();
110
+ // // api_index.api_notifications_list_test.create(app).run();
111
+
112
+ // api_index.api_images_crud_test.create(app).run();
113
+ // api_index.api_images_list_test.create(app).run();
114
+
115
+ // // api_index.api_discounts_crud_test.create(app).run();
116
+ // // api_index.api_discounts_list_test.create(app).run();
117
+ // // api_index.api_discounts_products_test.create(app).run();
118
+
119
+
120
+ // }
121
+
122
+ // // test2();
@@ -1,8 +1,8 @@
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 { MysqlDialect } from 'kysely';
7
7
  import { createPool } from 'mysql2'
8
8
 
@@ -41,63 +41,14 @@ export const create_app = async () => {
41
41
  async function test() {
42
42
  const app = await create_app();
43
43
 
44
- Object.entries(api_index).slice(0, -1).forEach(
44
+ Object.entries(api).slice(0, -1).forEach(
45
45
  ([name, runner]) => {
46
46
  runner.create(app).run();
47
47
  }
48
48
  );
49
- const last_test = Object.values(api_index).at(-1).create(app);
49
+ const last_test = Object.values(api).at(-1).create(app);
50
50
  last_test.after(async () => { await app.db.disconnect() });
51
51
  last_test.run();
52
52
  }
53
53
 
54
54
  test();
55
-
56
- async function test2() {
57
- const app = await create_app();
58
-
59
- // api_index.api_auth_test.create(app).run();
60
-
61
- // api_index.api_tags_crud_test.create(app).run();
62
- // api_index.api_tags_list_test.create(app).run();
63
-
64
- // api_index.api_collections_crud_test.create(app).run();
65
- // api_index.api_collections_list_test.create(app).run();
66
- // api_index.api_collections_products_test.create(app).run();
67
-
68
- // api_index.api_products_crud_test.create(app).run();
69
- // api_index.api_products_collections_test.create(app).run();
70
- // api_index.api_products_list_test.create(app).run();
71
- // api_index.api_products_discounts_test.create(app).run();
72
- // api_index.api_products_variants_test.create(app).run();
73
-
74
- // api_index.api_shipping_crud_test.create(app).run();
75
- // api_index.api_shipping_list_test.create(app).run();
76
-
77
- // api_index.api_posts_crud_test.create(app).run();
78
- // api_index.api_posts_list_test.create(app).run();
79
-
80
- // api_index.api_customers_crud_test.create(app).run();
81
- // api_index.api_customers_list_test.create(app).run();
82
-
83
- api_index.api_orders_crud_test.create(app).run();
84
- api_index.api_orders_list_test.create(app).run();
85
-
86
- api_index.api_storefronts_crud_test.create(app).run();
87
- api_index.api_storefronts_list_test.create(app).run();
88
- api_index.api_storefronts_all_connections_test.create(app).run();
89
-
90
- api_index.api_notifications_crud_test.create(app).run();
91
- api_index.api_notifications_list_test.create(app).run();
92
-
93
- api_index.api_images_crud_test.create(app).run();
94
- api_index.api_images_list_test.create(app).run();
95
-
96
- api_index.api_discounts_crud_test.create(app).run();
97
- api_index.api_discounts_list_test.create(app).run();
98
- api_index.api_discounts_products_test.create(app).run();
99
-
100
-
101
- }
102
-
103
- // test2();
@@ -1,8 +1,8 @@
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 { PostgresDialect } from 'kysely';
7
7
  import pg from 'pg'
8
8
 
@@ -41,63 +41,14 @@ export const create_app = async () => {
41
41
  async function test() {
42
42
  const app = await create_app();
43
43
 
44
- Object.entries(api_index).slice(0, -1).forEach(
44
+ Object.entries(api).slice(0, -1).forEach(
45
45
  ([name, runner]) => {
46
46
  runner.create(app).run();
47
47
  }
48
48
  );
49
- const last_test = Object.values(api_index).at(-1).create(app);
49
+ const last_test = Object.values(api).at(-1).create(app);
50
50
  last_test.after(async () => { await app.db.disconnect() });
51
51
  last_test.run();
52
52
  }
53
53
 
54
54
  test();
55
-
56
- async function test2() {
57
- const app = await create_app();
58
-
59
- api_index.api_auth_test.create(app).run();
60
-
61
- api_index.api_tags_crud_test.create(app).run();
62
- api_index.api_tags_list_test.create(app).run();
63
-
64
- api_index.api_collections_crud_test.create(app).run();
65
- api_index.api_collections_list_test.create(app).run();
66
- api_index.api_collections_products_test.create(app).run();
67
-
68
- api_index.api_products_crud_test.create(app).run();
69
- api_index.api_products_collections_test.create(app).run();
70
- api_index.api_products_list_test.create(app).run();
71
- api_index.api_products_discounts_test.create(app).run();
72
- api_index.api_products_variants_test.create(app).run();
73
-
74
- api_index.api_shipping_crud_test.create(app).run();
75
- api_index.api_shipping_list_test.create(app).run();
76
-
77
- api_index.api_posts_crud_test.create(app).run();
78
- api_index.api_posts_list_test.create(app).run();
79
-
80
- api_index.api_customers_crud_test.create(app).run();
81
- api_index.api_customers_list_test.create(app).run();
82
-
83
- api_index.api_orders_crud_test.create(app).run();
84
- api_index.api_orders_list_test.create(app).run();
85
-
86
- api_index.api_storefronts_crud_test.create(app).run();
87
- api_index.api_storefronts_list_test.create(app).run();
88
- api_index.api_storefronts_all_connections_test.create(app).run();
89
-
90
- api_index.api_notifications_crud_test.create(app).run();
91
- api_index.api_notifications_list_test.create(app).run();
92
-
93
- api_index.api_images_crud_test.create(app).run();
94
- api_index.api_images_list_test.create(app).run();
95
-
96
- api_index.api_discounts_crud_test.create(app).run();
97
- api_index.api_discounts_list_test.create(app).run();
98
- api_index.api_discounts_products_test.create(app).run();
99
-
100
-
101
- }
102
-
103
- // test2();
@@ -1,8 +1,8 @@
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 SQLite from 'better-sqlite3'
7
7
  import { SqliteDialect } from 'kysely';
8
8
  import { homedir } from 'node:os';
@@ -37,65 +37,14 @@ export const create_app = async () => {
37
37
  async function test() {
38
38
  const app = await create_app();
39
39
 
40
- Object.entries(api_index).slice(0, -1).forEach(
40
+ Object.entries(api).slice(0, -1).forEach(
41
41
  ([name, runner]) => {
42
42
  runner.create(app).run();
43
43
  }
44
44
  );
45
- const last_test = Object.values(api_index).at(-1).create(app);
45
+ const last_test = Object.values(api).at(-1).create(app);
46
46
  last_test.after(async () => { await app.db.disconnect() });
47
47
  last_test.run();
48
48
  }
49
49
 
50
50
  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_checkout_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,5 +1,5 @@
1
1
  import { App } from '@storecraft/core';
2
- import { NodePlatform } from '@storecraft/platforms/node';
2
+ import { NodePlatform } from '@storecraft/core/platform/node';
3
3
  import { SqliteDialect } from 'kysely';
4
4
  import { homedir } from 'os';
5
5
  import { join } from 'path';
@@ -11,7 +11,7 @@ import { AttributeType, AuthUserType, Role, TagType,
11
11
  OrderPaymentGatewayData, NotificationType,
12
12
  NotificationAction,
13
13
  DiscountInfo,
14
- DiscountApplicationEnum} from '@storecraft/core/v-api'
14
+ DiscountApplicationEnum} from '@storecraft/core/api'
15
15
  import {
16
16
  ColumnType,
17
17
  Generated,
@@ -120,8 +120,10 @@ export interface Base {
120
120
  export interface AuthUserTypeTable extends Base {
121
121
  email: string;
122
122
  password: string;
123
- confirmed_mail: number
123
+ confirmed_mail: number;
124
124
  roles: JSONColumnType<Role[]>;
125
+ firstname: string;
126
+ lastname: string;
125
127
  }
126
128
 
127
129
  export interface TagsTable extends Base {
package/driver.js DELETED
@@ -1,174 +0,0 @@
1
- import { App } from '@storecraft/core';
2
- import { impl as auth_users } from './src/con.auth_users.js';
3
- import { impl as collections } from './src/con.collections.js';
4
- import { impl as customers } from './src/con.customers.js';
5
- import { impl as discounts } from './src/con.discounts.js';
6
- import { impl as images } from './src/con.images.js';
7
- import { impl as notifications } from './src/con.notifications.js';
8
- import { impl as orders } from './src/con.orders.js';
9
- import { impl as posts } from './src/con.posts.js';
10
- import { impl as products } from './src/con.products.js';
11
- import { impl as shipping } from './src/con.shipping.js';
12
- import { impl as storefronts } from './src/con.storefronts.js';
13
- import { impl as tags } from './src/con.tags.js';
14
- import { impl as templates } from './src/con.templates.js';
15
- import { impl as search } from './src/con.search.js';
16
- import { Kysely, ParseJSONResultsPlugin } from 'kysely'
17
- import { SanitizePlugin } from './src/kysely.sanitize.plugin.js';
18
-
19
-
20
- /**
21
- * @param {any} b
22
- * @param {string} msg
23
- */
24
- const assert = (b, msg) => {
25
- if(!Boolean(b)) throw new Error(msg);
26
- }
27
-
28
- /**
29
- * @typedef {import('./types.public.d.ts').Config} Config
30
- * @typedef {import('./types.sql.tables.d.ts').Database} Database
31
- * @typedef {import('kysely').Dialect} Dialect
32
- * @typedef {import('@storecraft/core/v-database').db_driver} db_driver
33
- */
34
-
35
- /**
36
- * @implements {db_driver}
37
- */
38
- export class SQL {
39
-
40
- /** @type {boolean} */
41
- #_is_ready;
42
-
43
- /** @type {App<any, any, any>} */
44
- #_app;
45
-
46
- /** @type {Config} */
47
- #_config;
48
-
49
- /** @type {Kysely<Database>} */
50
- #_client;
51
-
52
- /** @type {db_driver["resources"]} */
53
- #_resources;
54
-
55
- /**
56
- *
57
- * @param {Config} [config] config
58
- */
59
- constructor(config) {
60
- this.#_is_ready = false;
61
- this.#_config = config;
62
-
63
- assert(
64
- this.#_config.dialect,
65
- 'No Dialect found !'
66
- );
67
-
68
- assert(
69
- this.#_config.dialect_type,
70
- 'No Dialect Type specified !'
71
- );
72
-
73
- this.#_client = new Kysely(
74
- {
75
- dialect: this.#_config.dialect,
76
- plugins: [
77
- new ParseJSONResultsPlugin(),
78
- new SanitizePlugin()
79
- ]
80
- }
81
- );
82
- }
83
-
84
- throwIfNotReady() {
85
- assert(
86
- this.isReady,
87
- 'Database not ready !!! you need to `.init()` it'
88
- );
89
- }
90
-
91
- /**
92
- *
93
- * @param {App<any, any, any>} app
94
- *
95
- *
96
- * @returns {Promise<this>}
97
- */
98
- async init(app) {
99
- if(this.isReady)
100
- return this;
101
-
102
- this.#_app = app;
103
-
104
- this.#_resources = {
105
- auth_users: auth_users(this),
106
- collections: collections(this),
107
- customers: customers(this),
108
- discounts: discounts(this),
109
- images: images(this),
110
- notifications: notifications(this),
111
- orders: orders(this),
112
- posts: posts(this),
113
- products: products(this),
114
- storefronts: storefronts(this),
115
- tags: tags(this),
116
- shipping_methods: shipping(this),
117
- templates: templates(this),
118
- search: search(this),
119
- }
120
-
121
- this.#_is_ready = true;
122
-
123
- return this;
124
- }
125
-
126
- async disconnect() {
127
- await this.client.destroy();
128
- return true;
129
- }
130
-
131
- /**
132
- * `database` resources
133
- */
134
- get resources () {
135
- return this.#_resources;
136
- }
137
-
138
- get name() {
139
- return this?.config?.db_name ?? 'main';
140
- }
141
-
142
- get app() {
143
- return this.#_app;
144
- }
145
-
146
- get client() {
147
- return this.#_client;
148
- }
149
-
150
- get config() {
151
- return this.#_config;
152
- }
153
-
154
- get isReady() {
155
- return this.#_is_ready;
156
- }
157
-
158
- get dialectType() {
159
- return this.#_config.dialect_type;
160
- }
161
-
162
- get isSqlite() {
163
- return this.dialectType==='SQLITE';
164
- }
165
-
166
- get isPostgres() {
167
- return this.dialectType==='POSTGRES';
168
- }
169
-
170
- get isMysql() {
171
- return this.dialectType==='MYSQL';
172
- }
173
-
174
- }