tspace-mysql 1.5.2 → 1.5.4

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,8 +1,8 @@
1
1
  declare class StateHandler {
2
2
  private STATE;
3
- constructor(constant: Record<string, any>);
3
+ constructor(state: 'model' | 'db' | 'default');
4
4
  original(): Map<string, any>;
5
- get(key?: string | null): any;
5
+ get(key?: string): any;
6
6
  set(key: string, value: any): void;
7
7
  clone(data: any): void;
8
8
  reset(): void;
@@ -1,18 +1,126 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StateHandler = void 0;
4
+ const STATE_DEFAULT = {};
5
+ const STATE_DB = {
6
+ PRIMARY_KEY: 'id',
7
+ VOID: false,
8
+ RESULT: null,
9
+ DISTINCT: false,
10
+ PLUCK: '',
11
+ SAVE: '',
12
+ DELETE: '',
13
+ UPDATE: '',
14
+ INSERT: '',
15
+ SELECT: [],
16
+ ONLY: [],
17
+ EXCEPTS: [],
18
+ CHUNK: 0,
19
+ COUNT: '',
20
+ FROM: 'FROM',
21
+ JOIN: [],
22
+ WHERE: [],
23
+ GROUP_BY: [],
24
+ ORDER_BY: [],
25
+ LIMIT: '',
26
+ OFFSET: '',
27
+ HAVING: '',
28
+ TABLE_NAME: '',
29
+ UUID_CUSTOM: '',
30
+ HIDDEN: [],
31
+ DEBUG: false,
32
+ UUID: false,
33
+ PAGE: 1,
34
+ PER_PAGE: 1,
35
+ HOOKS: [],
36
+ RETURN_TYPE: null
37
+ };
38
+ const STATE_MODEL = {
39
+ MODEL_NAME: 'MODEL',
40
+ PRIMARY_KEY: 'id',
41
+ VOID: false,
42
+ SELECT: [],
43
+ DELETE: '',
44
+ UPDATE: '',
45
+ INSERT: '',
46
+ ONLY: [],
47
+ EXCEPTS: [],
48
+ CHUNK: 0,
49
+ COUNT: '',
50
+ FROM: 'FROM',
51
+ JOIN: [],
52
+ WHERE: [],
53
+ GROUP_BY: [],
54
+ ORDER_BY: [],
55
+ LIMIT: '',
56
+ OFFSET: '',
57
+ HAVING: '',
58
+ TABLE_NAME: '',
59
+ UUID_FORMAT: 'uuid',
60
+ HIDDEN: [],
61
+ DEBUG: false,
62
+ UUID: false,
63
+ SOFT_DELETE: false,
64
+ SOFT_DELETE_FORMAT: 'deleted_at',
65
+ SOFT_DELETE_RELATIONS: false,
66
+ PAGE: 1,
67
+ PER_PAGE: 1,
68
+ REGISTRY: {},
69
+ RESULT: null,
70
+ PATTERN: 'snake_case',
71
+ DISTINCT: false,
72
+ PLUCK: '',
73
+ SAVE: '',
74
+ HOOKS: [],
75
+ RELATION: [],
76
+ RELATIONS: [],
77
+ RELATIONS_TRASHED: false,
78
+ RELATIONS_EXISTS: false,
79
+ TIMESTAMP: false,
80
+ TIMESTAMP_FORMAT: {
81
+ CREATED_AT: 'created_at',
82
+ UPDATED_AT: 'updated_at'
83
+ },
84
+ LOGGER: false,
85
+ LOGGER_OPTIONS: null,
86
+ TABLE_LOGGER: '$loggers',
87
+ VALIDATE_SCHEMA: false,
88
+ VALIDATE_SCHEMA_DEFINED: null,
89
+ FUNCTION_RELATION: false,
90
+ SCHEMA_TABLE: null,
91
+ RETRY: 0,
92
+ OBSERVER: null,
93
+ DATA: null,
94
+ BEFORE_CREATING_TABLE: null,
95
+ RETURN_TYPE: null
96
+ };
4
97
  class StateHandler {
5
- constructor(constant) {
98
+ constructor(state) {
6
99
  this.STATE = {
7
100
  currentState: new Map(),
8
101
  defaultState: new Map()
9
102
  };
10
- const currentState = new Map(Object.entries(Object.assign({}, constant)));
11
- const defaultState = new Map(Object.entries(Object.assign({}, constant)));
12
- this.STATE = {
13
- currentState,
14
- defaultState
15
- };
103
+ switch (state) {
104
+ case 'db': {
105
+ const currentState = new Map(Object.entries(Object.assign({}, STATE_DB)));
106
+ const defaultState = new Map(Object.entries(Object.assign({}, STATE_DB)));
107
+ this.STATE = { currentState, defaultState };
108
+ return this;
109
+ }
110
+ case 'model': {
111
+ const currentState = new Map(Object.entries(Object.assign({}, STATE_MODEL)));
112
+ const defaultState = new Map(Object.entries(Object.assign({}, STATE_MODEL)));
113
+ this.STATE = { currentState, defaultState };
114
+ return this;
115
+ }
116
+ case 'default': {
117
+ const currentState = new Map(Object.entries(Object.assign({}, STATE_DEFAULT)));
118
+ const defaultState = new Map(Object.entries(Object.assign({}, STATE_DEFAULT)));
119
+ this.STATE = { currentState, defaultState };
120
+ return this;
121
+ }
122
+ default: throw new Error(`Unknown the state : '${state}'`);
123
+ }
16
124
  }
17
125
  original() {
18
126
  return this.STATE.defaultState;
@@ -20,12 +128,18 @@ class StateHandler {
20
128
  get(key) {
21
129
  if (key == null)
22
130
  return this.STATE.currentState;
23
- this._assertError(!this.STATE.currentState.has(key) && key !== 'DEBUG', `Can't get this [ ${key} ]`);
24
- return this.STATE.currentState.get(key.toUpperCase());
131
+ key = key.toUpperCase();
132
+ if (!this.STATE.currentState.has(key) && key !== 'DEBUG') {
133
+ return this._assertError('DEBUG', `This state does not have that key '${key}'`);
134
+ }
135
+ return this.STATE.currentState.get(key);
25
136
  }
26
137
  set(key, value) {
27
- this._assertError(!this.STATE.currentState.has(key), `Can't set this [ ${key} ]`);
28
- this.STATE.currentState.set(key.toUpperCase(), value);
138
+ key = key.toUpperCase();
139
+ if (!this.STATE.currentState.has(key)) {
140
+ return this._assertError(`That key '${key}' can't be set in the state`);
141
+ }
142
+ this.STATE.currentState.set(key, value);
29
143
  return;
30
144
  }
31
145
  clone(data) {
@@ -40,7 +154,7 @@ class StateHandler {
40
154
  this.STATE.currentState.set('LIMIT', '');
41
155
  this.STATE.currentState.set('OFFSET', '');
42
156
  this.STATE.currentState.set('SELECT', []);
43
- this.STATE.currentState.set('GROUP_BY', '');
157
+ this.STATE.currentState.set('GROUP_BY', []);
44
158
  this.STATE.currentState.set('ORDER_BY', []);
45
159
  this.STATE.currentState.set('HAVING', '');
46
160
  this.STATE.currentState.set('JOIN', []);