@rainbow-o23/n3 0.1.1
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/.babelrc +11 -0
- package/.eslintrc +23 -0
- package/README.md +584 -0
- package/index.cjs +2283 -0
- package/index.d.ts +5 -0
- package/index.js +2229 -0
- package/lib/error-codes.d.ts +17 -0
- package/lib/http/fetch-step.d.ts +53 -0
- package/lib/http/index.d.ts +2 -0
- package/lib/http/types.d.ts +21 -0
- package/lib/step/abstract-fragmentary-pipeline-step.d.ts +44 -0
- package/lib/step/async-step-sets.d.ts +5 -0
- package/lib/step/conditional-step-sets.d.ts +23 -0
- package/lib/step/delete-property-step.d.ts +11 -0
- package/lib/step/each-step-sets.d.ts +14 -0
- package/lib/step/get-property-step.d.ts +11 -0
- package/lib/step/index.d.ts +14 -0
- package/lib/step/ref-pipeline-step.d.ts +15 -0
- package/lib/step/ref-step-step.d.ts +14 -0
- package/lib/step/routes-step-sets.d.ts +30 -0
- package/lib/step/snippet-step.d.ts +19 -0
- package/lib/step/snowflake-step.d.ts +6 -0
- package/lib/step/step-sets.d.ts +19 -0
- package/lib/step/types.d.ts +13 -0
- package/lib/step/utils.d.ts +23 -0
- package/lib/typeorm/abstract-datasource.d.ts +22 -0
- package/lib/typeorm/better-sqlite3-datasource.d.ts +7 -0
- package/lib/typeorm/datasource-manager.d.ts +25 -0
- package/lib/typeorm/index.d.ts +7 -0
- package/lib/typeorm/mssql-datasource.d.ts +6 -0
- package/lib/typeorm/mysql-datasource.d.ts +6 -0
- package/lib/typeorm/oracle-datasource.d.ts +6 -0
- package/lib/typeorm/pgsql-datasource.d.ts +6 -0
- package/lib/typeorm-step/abstract-typeorm-by-sql-step.d.ts +62 -0
- package/lib/typeorm-step/abstract-typeorm-load-by-sql-step.d.ts +10 -0
- package/lib/typeorm-step/abstract-typeorm-step.d.ts +30 -0
- package/lib/typeorm-step/index.d.ts +12 -0
- package/lib/typeorm-step/type-orm-transactional-step-sets.d.ts +22 -0
- package/lib/typeorm-step/typeorm-bulk-save-by-sql-step.d.ts +9 -0
- package/lib/typeorm-step/typeorm-by-snippet-step.d.ts +21 -0
- package/lib/typeorm-step/typeorm-load-entity-by-id-step.d.ts +12 -0
- package/lib/typeorm-step/typeorm-load-many-by-sql-step.d.ts +6 -0
- package/lib/typeorm-step/typeorm-load-one-by-sql-step.d.ts +6 -0
- package/lib/typeorm-step/typeorm-save-by-sql-step.d.ts +9 -0
- package/lib/typeorm-step/typeorm-save-entity-step.d.ts +32 -0
- package/lib/typeorm-step/types.d.ts +22 -0
- package/package.json +74 -0
- package/rollup.config.base.js +33 -0
- package/rollup.config.ci.js +3 -0
- package/rollup.config.js +3 -0
- package/src/index.ts +7 -0
- package/src/lib/error-codes.ts +18 -0
- package/src/lib/http/fetch-step.ts +290 -0
- package/src/lib/http/index.ts +3 -0
- package/src/lib/http/types.ts +33 -0
- package/src/lib/step/abstract-fragmentary-pipeline-step.ts +367 -0
- package/src/lib/step/async-step-sets.ts +14 -0
- package/src/lib/step/conditional-step-sets.ts +115 -0
- package/src/lib/step/delete-property-step.ts +33 -0
- package/src/lib/step/each-step-sets.ts +80 -0
- package/src/lib/step/get-property-step.ts +34 -0
- package/src/lib/step/index.ts +18 -0
- package/src/lib/step/ref-pipeline-step.ts +65 -0
- package/src/lib/step/ref-step-step.ts +59 -0
- package/src/lib/step/routes-step-sets.ts +147 -0
- package/src/lib/step/snippet-step.ts +80 -0
- package/src/lib/step/snowflake-step.ts +16 -0
- package/src/lib/step/step-sets.ts +99 -0
- package/src/lib/step/types.ts +23 -0
- package/src/lib/step/utils.ts +109 -0
- package/src/lib/typeorm/abstract-datasource.ts +58 -0
- package/src/lib/typeorm/better-sqlite3-datasource.ts +29 -0
- package/src/lib/typeorm/datasource-manager.ts +104 -0
- package/src/lib/typeorm/index.ts +9 -0
- package/src/lib/typeorm/mssql-datasource.ts +131 -0
- package/src/lib/typeorm/mysql-datasource.ts +35 -0
- package/src/lib/typeorm/oracle-datasource.ts +27 -0
- package/src/lib/typeorm/pgsql-datasource.ts +25 -0
- package/src/lib/typeorm-step/abstract-typeorm-by-sql-step.ts +556 -0
- package/src/lib/typeorm-step/abstract-typeorm-load-by-sql-step.ts +31 -0
- package/src/lib/typeorm-step/abstract-typeorm-step.ts +241 -0
- package/src/lib/typeorm-step/index.ts +17 -0
- package/src/lib/typeorm-step/type-orm-transactional-step-sets.ts +129 -0
- package/src/lib/typeorm-step/typeorm-bulk-save-by-sql-step.ts +29 -0
- package/src/lib/typeorm-step/typeorm-by-snippet-step.ts +83 -0
- package/src/lib/typeorm-step/typeorm-load-entity-by-id-step.ts +35 -0
- package/src/lib/typeorm-step/typeorm-load-many-by-sql-step.ts +13 -0
- package/src/lib/typeorm-step/typeorm-load-one-by-sql-step.ts +13 -0
- package/src/lib/typeorm-step/typeorm-save-by-sql-step.ts +24 -0
- package/src/lib/typeorm-step/typeorm-save-entity-step.ts +109 -0
- package/src/lib/typeorm-step/types.ts +25 -0
- package/test/step/snippet-step.test.ts +21 -0
- package/test/step/snowflake-step.test.ts +22 -0
- package/test/step/typeorm-by-sql-autonomous.test.ts +117 -0
- package/test/step/typeorm-by-sql-transactional.test.ts +215 -0
- package/test/step/typeorm-entity.test.ts +50 -0
- package/tsconfig.json +36 -0
package/.babelrc
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"root": true,
|
|
3
|
+
"parser": "@typescript-eslint/parser",
|
|
4
|
+
"plugins": [
|
|
5
|
+
"@typescript-eslint"
|
|
6
|
+
],
|
|
7
|
+
"extends": [
|
|
8
|
+
"eslint:recommended",
|
|
9
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
10
|
+
"plugin:@typescript-eslint/recommended"
|
|
11
|
+
],
|
|
12
|
+
"rules": {
|
|
13
|
+
"no-plusplus": 0,
|
|
14
|
+
"no-mixed-spaces-and-tabs": [
|
|
15
|
+
"error",
|
|
16
|
+
"smart-tabs"
|
|
17
|
+
],
|
|
18
|
+
"@typescript-eslint/no-empty-interface": "off",
|
|
19
|
+
"@typescript/no-non-null-assertion": "off",
|
|
20
|
+
"@typescript-eslint/adjacent-overload-signatures": "off",
|
|
21
|
+
"@typescript-eslint/ban-ts-comment": "error"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
# o23/n3
|
|
2
|
+
|
|
3
|
+
`o23/n3` provides the most basic pipeline steps.
|
|
4
|
+
|
|
5
|
+
## Snippet Supporting
|
|
6
|
+
|
|
7
|
+
Almost all pipeline steps use dynamic snippets to some extent. In order to facilitate various operations on objects in the snippet, `o23/n3`
|
|
8
|
+
injects rich function support in advance when executing these scripts. All the function support provided by the pipeline steps can be
|
|
9
|
+
directly obtained and used in scripts using the `$helpers` handle. For example:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
const currentTime = $helpers.$date.now();
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
When using scripts, pay attention to the usage of variables. Typically:
|
|
16
|
+
|
|
17
|
+
- `$factor` represents the incoming data and can be used in most snippet definitions,
|
|
18
|
+
- `$result` represents the processed data and only appears in the `toResponse` snippet of `Fragmentary`,
|
|
19
|
+
- `$request` represents the original request data and can be used in almost all snippets, but it is not recommended,
|
|
20
|
+
- `$helpers` represents function supporting and can be used in all snippets,
|
|
21
|
+
- `$options` represents a set of data, usually in error handles.
|
|
22
|
+
|
|
23
|
+
## Basic Steps
|
|
24
|
+
|
|
25
|
+
### Fragmentary
|
|
26
|
+
|
|
27
|
+
Usually, when processing logic, we do not need all the memory contexts, but only need to extract certain fragments for processing and return
|
|
28
|
+
the processing results to the context for subsequent logic to continue processing. Therefore, `o23/n3` provides a relevant implementation,
|
|
29
|
+
allowing pipeline steps to flexibly access the relevant memory data and write back the processed result data to the context in the required
|
|
30
|
+
format. All pipeline steps should inherit from this implementation to obtain the same capabilities.
|
|
31
|
+
|
|
32
|
+
#### Constructor Parameters
|
|
33
|
+
|
|
34
|
+
| Name | Type | Default Value | Comments |
|
|
35
|
+
|--------------------------|----------------------------------------------------------------------------------------------------------------|---------------|-------------------------------------|
|
|
36
|
+
| fromRequest | ScriptFuncOrBody\<GetInFragmentFromRequestFunc> | | Get data from request. |
|
|
37
|
+
| toResponse | ScriptFuncOrBody\<SetOutFragmentToResponseFunc> | | Write data to response. |
|
|
38
|
+
| mergeRequest | boolean or string | false | Shortcut to merge data to response. |
|
|
39
|
+
| errorHandles.catchable | ScriptFuncOrBody<HandleCatchableError<In, InFragment, OutFragment>><br>or Array\<PipelineStepBuilder> | | Catchable error handler. |
|
|
40
|
+
| errorHandles.uncatchable | ScriptFuncOrBody<HandleUncatchableError<In, InFragment, OutFragment>><br>or Array\<PipelineStepBuilder> | | Uncatchable error handler. |
|
|
41
|
+
| errorHandles.exposed | ScriptFuncOrBody<HandleExposedUncatchableError<In, InFragment, OutFragment>><br>or Array\<PipelineStepBuilder> | | Exposed uncatchable error handler. |
|
|
42
|
+
| errorHandles.any | ScriptFuncOrBody<HandleAnyError<In, InFragment, OutFragment>><br>or Array\<PipelineStepBuilder> | | Any error handler. |
|
|
43
|
+
|
|
44
|
+
#### Merge Request
|
|
45
|
+
|
|
46
|
+
| Prerequisite | Behavior |
|
|
47
|
+
|------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
48
|
+
| No `toResponse` defined, `mergeRequest` is true | Unbox result and merge into original request content.<br> Make sure request content and result can be unboxed. |
|
|
49
|
+
| No `toResponse` defined, `mergeRequest` is string | Use value of `mergeRequest` as key, merge result into original request content.<br> Make sure request content can be unboxed. |
|
|
50
|
+
| No `toResponse` defined, no `mergeRequest` defined | Return result directly. |
|
|
51
|
+
| With `toResponse` defined, `mergeRequest` is true | Execute `toResponse` first, unbox result and merge into original request content.<br> Make sure request content and result can be unboxed. |
|
|
52
|
+
| With `toResponse` defined, `mergeRequest` is string | Execute `toResponse` first, use value of `mergeRequest` as key, merge result into original request content.<br> Make sure request content can be unboxed. |
|
|
53
|
+
| With `toResponse` defined, no `mergeRequest` defined | Execute `toResponse` first, return result directly. |
|
|
54
|
+
|
|
55
|
+
#### Error Handles
|
|
56
|
+
|
|
57
|
+
Each type of error handle can be either a snippet or a set of pipeline steps. If it is defined as pipeline steps, the first step will
|
|
58
|
+
receive the request data in the following format:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const RequestContent = {$code: errorCode, $error: error, $factor: fragment, $request: request};
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Except for the first step, each subsequent step will receive request data that depends on the processing result of the previous step.
|
|
65
|
+
|
|
66
|
+
### Get Property
|
|
67
|
+
|
|
68
|
+
#### Constructor Parameters
|
|
69
|
+
|
|
70
|
+
| Name | Type | Default Value | Comments |
|
|
71
|
+
|--------------|--------|---------------|--------------------------------------------------------|
|
|
72
|
+
| propertyName | string | | Supports multi-level property names, connected by `.`. |
|
|
73
|
+
|
|
74
|
+
> The data source of given property name is after `fromRequest` transformation.
|
|
75
|
+
|
|
76
|
+
### Delete Property
|
|
77
|
+
|
|
78
|
+
#### Constructor Parameters
|
|
79
|
+
|
|
80
|
+
| Name | Type | Default Value | Comments |
|
|
81
|
+
|---------------|--------------------------|---------------|----------|
|
|
82
|
+
| propertyNames | string or Array\<string> | | |
|
|
83
|
+
|
|
84
|
+
> Multi-level property names is not supported, make sure the data source of given property name is after `fromRequest` transformation.
|
|
85
|
+
|
|
86
|
+
### Snippet
|
|
87
|
+
|
|
88
|
+
#### Constructor Parameters
|
|
89
|
+
|
|
90
|
+
| Name | Type | Default Value | Comments |
|
|
91
|
+
|---------|--------------------------------|---------------|----------|
|
|
92
|
+
| snippet | ScriptFuncOrBody\<PerformFunc> | | |
|
|
93
|
+
|
|
94
|
+
### Step Sets
|
|
95
|
+
|
|
96
|
+
#### Constructor Parameters
|
|
97
|
+
|
|
98
|
+
| Name | Type | Default Value | Comments |
|
|
99
|
+
|-------|-----------------------------|---------------|----------|
|
|
100
|
+
| steps | Array\<PipelineStepBuilder> | | |
|
|
101
|
+
|
|
102
|
+
Execute the given pipeline steps in order.
|
|
103
|
+
|
|
104
|
+
### Conditional
|
|
105
|
+
|
|
106
|
+
#### Constructor Parameters
|
|
107
|
+
|
|
108
|
+
| Name | Type | Default Value | Comments |
|
|
109
|
+
|----------------|---------------------------------------|---------------|----------|
|
|
110
|
+
| check | ScriptFuncOrBody\<ConditionCheckFunc> | | |
|
|
111
|
+
| steps | Array\<PipelineStepBuilder> | | |
|
|
112
|
+
| otherwiseSteps | Array\<PipelineStepBuilder> | | |
|
|
113
|
+
|
|
114
|
+
First, execute the `check` snippet and return true. Then execute the given pipeline steps in order. Otherwise, execute the given `otherwise`
|
|
115
|
+
pipeline steps in order.
|
|
116
|
+
|
|
117
|
+
### Routes (Switch)
|
|
118
|
+
|
|
119
|
+
#### Constructor Parameters
|
|
120
|
+
|
|
121
|
+
| Name | Type | Default Value | Comments |
|
|
122
|
+
|------------------|--------------------------------------|---------------|----------|
|
|
123
|
+
| conditionalSteps | Array\<RoutesConditionalStepOptions> | | |
|
|
124
|
+
| otherwiseSteps | Array\<PipelineStepBuilder> | | |
|
|
125
|
+
|
|
126
|
+
The conditional step is defined as follows:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
export interface RoutesConditionalStepOptions {
|
|
130
|
+
check: ScriptFuncOrBody<ConditionCheckFunc>,
|
|
131
|
+
steps?: Array<PipelineStepBuilder>;
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Execute each given condition `check` in order. If a condition is true, execute the corresponding pipeline steps in order. If none of the
|
|
136
|
+
conditions are true, execute the given `otherwise` pipeline steps in order.
|
|
137
|
+
|
|
138
|
+
### For Each
|
|
139
|
+
|
|
140
|
+
#### Constructor Parameters
|
|
141
|
+
|
|
142
|
+
| Name | Type | Default Value | Comments |
|
|
143
|
+
|---------------------|-----------------------------|---------------|----------|
|
|
144
|
+
| originalContentName | string | $content | |
|
|
145
|
+
| itemName | string | $item | |
|
|
146
|
+
| steps | Array\<PipelineStepBuilder> | | |
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
const RequestContent = {$code: errorCode, $error: error, $factor: fragment, $request: request};
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The specified set of pipeline steps will be applied to each element of the array, and all the execution results will be gathered into an
|
|
153
|
+
array and returned. It is important to note that the error handles of the `For Each` pipeline steps will be used for each iteration of
|
|
154
|
+
executing individual elements, rather than being applied to the execution of the array as a whole. If the array is empty, the given pipeline
|
|
155
|
+
steps will not be executed. The request data obtained in the first step of each element's execution will appear in the following format:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const RequestContent = {$content: content, $item: element, $semaphore};
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
If you need to terminate the loop prematurely, you just need to return the `$semaphore` signal from the request data. The loop will
|
|
162
|
+
automatically end, and the collected processing results will be gathered and returned as an array.
|
|
163
|
+
|
|
164
|
+
### Trigger Pipeline
|
|
165
|
+
|
|
166
|
+
#### Constructor Parameters
|
|
167
|
+
|
|
168
|
+
| Name | Type | Default Value | Comments |
|
|
169
|
+
|------|--------|---------------|----------------|
|
|
170
|
+
| code | string | | Pipeline code. |
|
|
171
|
+
|
|
172
|
+
Execute the specified pipeline.
|
|
173
|
+
|
|
174
|
+
### Trigger Pipeline Step
|
|
175
|
+
|
|
176
|
+
#### Constructor Parameters
|
|
177
|
+
|
|
178
|
+
| Name | Type | Default Value | Comments |
|
|
179
|
+
|------|--------|---------------|---------------------|
|
|
180
|
+
| code | string | | Pipeline step code. |
|
|
181
|
+
|
|
182
|
+
Execute the specified pipeline step.
|
|
183
|
+
|
|
184
|
+
### Async
|
|
185
|
+
|
|
186
|
+
#### Constructor Parameters
|
|
187
|
+
|
|
188
|
+
| Name | Type | Default Value | Comments |
|
|
189
|
+
|-------|-----------------------------|---------------|----------|
|
|
190
|
+
| steps | Array\<PipelineStepBuilder> | | |
|
|
191
|
+
|
|
192
|
+
Execute the given pipeline steps in order, but asynchronous. Therefore, no result returned.
|
|
193
|
+
|
|
194
|
+
## Database (TypeOrm) Steps
|
|
195
|
+
|
|
196
|
+
### Environment Parameters
|
|
197
|
+
|
|
198
|
+
| Name | Type | Default Value | Comments |
|
|
199
|
+
|-----------------------------|---------|---------------|-------------------------------------------|
|
|
200
|
+
| `typeorm.DB.type` | string | | Database type, `mysql`, `better-sqlite3`. |
|
|
201
|
+
| `typeorm.DB.kept.on.global` | boolean | | Keep database instance in memory or not. |
|
|
202
|
+
|
|
203
|
+
`DB` represents database name.
|
|
204
|
+
|
|
205
|
+
- For mysql, default kept on global is true,
|
|
206
|
+
- For Better-SQLite3, default kept on global is false.
|
|
207
|
+
|
|
208
|
+
#### MySQL
|
|
209
|
+
|
|
210
|
+
When `typeorm.DB.type=mysql`:
|
|
211
|
+
|
|
212
|
+
| Name | Type | Default Value | Comments |
|
|
213
|
+
|-------------------------------------|---------|---------------------|-----------------------------------------------------------------------------------------------------------------------|
|
|
214
|
+
| `typeorm.DB.host` | string | localhost | MySQL host. |
|
|
215
|
+
| `typeorm.DB.port` | number | 3306 | MySQL port. |
|
|
216
|
+
| `typeorm.DB.username` | string | | MySQL username. |
|
|
217
|
+
| `typeorm.DB.password` | string | | MySQL password. |
|
|
218
|
+
| `typeorm.DB.database` | string | | MySQL database name. |
|
|
219
|
+
| `typeorm.DB.charset` | string | | MySQL database charset. |
|
|
220
|
+
| `typeorm.DB.timezone` | string | | MySQL database timezone. |
|
|
221
|
+
| `typeorm.DB.pool.size` | number | | MySQL connection pool size. |
|
|
222
|
+
| `typeorm.DB.synchronize` | boolean | false | |
|
|
223
|
+
| `typeorm.DB.logging` | boolean | false | |
|
|
224
|
+
| `typeorm.DB.connect.timeout` | number | | |
|
|
225
|
+
| `typeorm.DB.acquire.timeout` | number | | |
|
|
226
|
+
| `typeorm.DB.insecure.auth` | boolean | |
|
|
227
|
+
| `typeorm.DB.support.big.numbers` | boolean | true | |
|
|
228
|
+
| `typeorm.DB.big.number.strings` | boolean | false | |
|
|
229
|
+
| `typeorm.DB.date.strings` | boolean | | |
|
|
230
|
+
| `typeorm.DB.debug` | boolean | | |
|
|
231
|
+
| `typeorm.DB.trace` | boolean | | |
|
|
232
|
+
| `typeorm.DB.multiple.statements` | boolean | false | |
|
|
233
|
+
| `typeorm.DB.legacy.spatial.support` | boolean | | |
|
|
234
|
+
| `typeorm.DB.timestamp.format.write` | string | %Y-%m-%d %H:%k:%s | PgSQL timestamp write format, should compatible with `format.datetime`, which default value is `YYYY-MM-DD HH:mm:ss`. |
|
|
235
|
+
| `typeorm.DB.timestamp.format.read` | string | YYYY-MM-DD HH:mm:ss | PgSQL timestamp read format. |
|
|
236
|
+
|
|
237
|
+
> Mysql driver read `DateTime` column to javascript `string`.
|
|
238
|
+
|
|
239
|
+
#### PostgreSQL
|
|
240
|
+
|
|
241
|
+
When `typeorm.DB.type=pgsql`:
|
|
242
|
+
|
|
243
|
+
| Name | Type | Default Value | Comments |
|
|
244
|
+
|-------------------------------------|---------|--------------------------|-----------------------------------------------------------------------------------------------------------------------|
|
|
245
|
+
| `typeorm.DB.host` | string | localhost | PgSQL host. |
|
|
246
|
+
| `typeorm.DB.port` | number | 5432 | PgSQL port. |
|
|
247
|
+
| `typeorm.DB.username` | string | | PgSQL username. |
|
|
248
|
+
| `typeorm.DB.password` | string | | PgSQL password. |
|
|
249
|
+
| `typeorm.DB.database` | string | | PgSQL database name. |
|
|
250
|
+
| `typeorm.DB.schema` | string | | PgSQL schema name. |
|
|
251
|
+
| `typeorm.DB.pool.size` | number | | PgSQL connection pool size. |
|
|
252
|
+
| `typeorm.DB.synchronize` | boolean | false | |
|
|
253
|
+
| `typeorm.DB.logging` | boolean | false | |
|
|
254
|
+
| `typeorm.DB.connect.timeout` | number | | |
|
|
255
|
+
| `typeorm.DB.timestamp.format.write` | string | YYYY-MM-DD HH24:MI:SS | PgSQL timestamp write format, should compatible with `format.datetime`, which default value is `YYYY-MM-DD HH:mm:ss`. |
|
|
256
|
+
| `typeorm.DB.timestamp.format.read` | string | YYYY-MM-DDTHH:mm:ss.SSSZ | PgSQL timestamp read format. |
|
|
257
|
+
|
|
258
|
+
> PgSQL driver read `DateTime` column to javascript `Date`.
|
|
259
|
+
|
|
260
|
+
#### MSSQL
|
|
261
|
+
|
|
262
|
+
When `typeorm.DB.type=mssql`:
|
|
263
|
+
|
|
264
|
+
| Name | Type | Default Value | Comments |
|
|
265
|
+
|-------------------------------------------------|---------|---------------------|-----------------------------------------------------------------------------------------------------------------------|
|
|
266
|
+
| `typeorm.DB.host` | string | localhost | MSSQL host. |
|
|
267
|
+
| `typeorm.DB.port` | number | 5432 | MSSQL port. |
|
|
268
|
+
| `typeorm.DB.username` | string | | MSSQL username. |
|
|
269
|
+
| `typeorm.DB.password` | string | | MSSQL password. |
|
|
270
|
+
| `typeorm.DB.database` | string | | MSSQL database name. |
|
|
271
|
+
| `typeorm.DB.schema` | string | | MSSQL schema name. |
|
|
272
|
+
| `typeorm.DB.pool.size` | number | | MSSQL connection pool size. |
|
|
273
|
+
| `typeorm.DB.synchronize` | boolean | false | |
|
|
274
|
+
| `typeorm.DB.logging` | boolean | false | |
|
|
275
|
+
| `typeorm.DB.authentication.type` | string | | MSSQL authentication type. |
|
|
276
|
+
| `typeorm.DB.domain` | string | | MSSQL domain. |
|
|
277
|
+
| `typeorm.DB.azure.ad.access.token` | string | | MSSQL azure ad access token. |
|
|
278
|
+
| `typeorm.DB.azure.ad.msi.app.service.client.id` | string | | MSSQL azure ad msi app service client id. |
|
|
279
|
+
| `typeorm.DB.azure.ad.msi.app.service.endpoint` | string | | MSSQL azure ad msi app service endpoint. |
|
|
280
|
+
| `typeorm.DB.azure.ad.msi.app.service.secret` | string | | MSSQL azure ad msi app service secret. |
|
|
281
|
+
| `typeorm.DB.azure.ad.msi.vm.client.id` | string | | MSSQL azure ad msi vm client id. |
|
|
282
|
+
| `typeorm.DB.azure.ad.msi.vm.endpoint` | string | | MSSQL azure ad msi vm endpoint. |
|
|
283
|
+
| `typeorm.DB.azure.ad.msi.vm.client.secret` | string | | MSSQL azure ad msi vm client secret. |
|
|
284
|
+
| `typeorm.DB.azure.ad.msi.vm.tenant.id` | string | | MSSQL azure ad msi vm tenant id. |
|
|
285
|
+
| `typeorm.DB.connect.timeout` | number | | |
|
|
286
|
+
| `typeorm.DB.request.timeout` | number | | |
|
|
287
|
+
| `typeorm.DB.pool.max` | number | 5 | |
|
|
288
|
+
| `typeorm.DB.pool.min` | number | 1 | |
|
|
289
|
+
| `typeorm.DB.pool.acquire.timeout` | number | | |
|
|
290
|
+
| `typeorm.DB.pool.idle.timeout` | number | | |
|
|
291
|
+
| `typeorm.DB.instance` | string | | |
|
|
292
|
+
| `typeorm.DB.ansi.null.enabled` | boolean | | |
|
|
293
|
+
| `typeorm.DB.cancel.timeout` | number | | |
|
|
294
|
+
| `typeorm.DB.use.utc` | boolean | | |
|
|
295
|
+
| `typeorm.DB.encrypt` | boolean | | |
|
|
296
|
+
| `typeorm.DB.crypto.credentials` | string | | |
|
|
297
|
+
| `typeorm.DB.tds.version` | string | | |
|
|
298
|
+
| `typeorm.DB.arithmetic.abort` | boolean | | |
|
|
299
|
+
| `typeorm.DB.trust.server.certificate` | boolean | | |
|
|
300
|
+
| `typeorm.DB.timestamp.format.write` | string | yyyy-MM-dd hh:mm:ss | MSSQL timestamp write format, should compatible with `format.datetime`, which default value is `YYYY-MM-DD HH:mm:ss`. |
|
|
301
|
+
| `typeorm.DB.timestamp.format.read` | string | YYYY-MM-DD HH:mm:ss | MSSQL timestamp read format. |
|
|
302
|
+
|
|
303
|
+
> [MSSQL of TypeORM](https://typeorm.io/data-source-options#mssql-data-source-options) for more details.
|
|
304
|
+
|
|
305
|
+
> MSSQL driver read `DateTime` column to javascript `Date`.
|
|
306
|
+
|
|
307
|
+
#### Oracle
|
|
308
|
+
|
|
309
|
+
When `typeorm.DB.type=oracle`:
|
|
310
|
+
|
|
311
|
+
| Name | Type | Default Value | Comments |
|
|
312
|
+
|-------------------------------------|---------|-----------------------|------------------------------------------------------------------------------------------------------------------------|
|
|
313
|
+
| `typeorm.DB.host` | string | localhost | Oracle host. |
|
|
314
|
+
| `typeorm.DB.port` | number | 5432 | Oracle port. |
|
|
315
|
+
| `typeorm.DB.username` | string | | Oracle username. |
|
|
316
|
+
| `typeorm.DB.password` | string | | Oracle password. |
|
|
317
|
+
| `typeorm.DB.database` | string | | Oracle database name. |
|
|
318
|
+
| `typeorm.DB.sid` | string | | Oracle database sid. |
|
|
319
|
+
| `typeorm.DB.service.name` | string | | Oracle database service name. |
|
|
320
|
+
| `typeorm.DB.connect.string` | string | | Oracle connect string. |
|
|
321
|
+
| `typeorm.DB.schema` | string | | Oracle schema name. |
|
|
322
|
+
| `typeorm.DB.pool.size` | number | | Oracle connection pool size. |
|
|
323
|
+
| `typeorm.DB.synchronize` | boolean | false | |
|
|
324
|
+
| `typeorm.DB.logging` | boolean | false | |
|
|
325
|
+
| `typeorm.DB.timestamp.format.write` | string | YYYY-MM-DD HH24:MI:SS | Oracle timestamp write format, should compatible with `format.datetime`, which default value is `YYYY-MM-DD HH:mm:ss`. |
|
|
326
|
+
| `typeorm.DB.timestamp.format.read` | string | YYYY-MM-DD HH:mm:ss | Oracle timestamp read format. |
|
|
327
|
+
|
|
328
|
+
> Oracle driver read `DateTime` column to javascript `Date`.
|
|
329
|
+
|
|
330
|
+
#### Better SQLite3
|
|
331
|
+
|
|
332
|
+
When `typeorm.DB.type=better-sqlite3`:
|
|
333
|
+
|
|
334
|
+
| Name | Type | Default Value | Comments |
|
|
335
|
+
|--------------------------|---------|---------------|----------|
|
|
336
|
+
| `typeorm.DB.database` | string | :memory: | |
|
|
337
|
+
| `typeorm.DB.synchronize` | boolean | false | |
|
|
338
|
+
| `typeorm.DB.logging` | boolean | false | |
|
|
339
|
+
|
|
340
|
+
> SQLite save `DateTime` column as javascript `string`.
|
|
341
|
+
|
|
342
|
+
> NEVER use it in production.
|
|
343
|
+
|
|
344
|
+
### Constructor Parameters
|
|
345
|
+
|
|
346
|
+
| Name | Type | Default Value | Comments |
|
|
347
|
+
|-----------------|---------|---------------|--------------------------------|
|
|
348
|
+
| dataSourceName | string | | Database name, `DB`. |
|
|
349
|
+
| transactionName | string | | Transaction name. |
|
|
350
|
+
| autonomous | boolean | false | Autonomous transaction or not. |
|
|
351
|
+
|
|
352
|
+
Autonomous transactions take precedence over the transaction name, meaning that if an autonomous transaction is enabled, the transaction
|
|
353
|
+
specified by the transaction name will be ignored. If you need to use the transaction name, you must nest the pipeline steps within
|
|
354
|
+
transactional step sets, and ensure that the datasource name and transaction name remain the same.
|
|
355
|
+
|
|
356
|
+
### By Entity
|
|
357
|
+
|
|
358
|
+
#### Load Entity by ID
|
|
359
|
+
|
|
360
|
+
##### Constructor Parameters
|
|
361
|
+
|
|
362
|
+
| Name | Type | Default Value | Comments |
|
|
363
|
+
|------------|--------|---------------|----------------------|
|
|
364
|
+
| entityName | string | | TypeOrm entity name. |
|
|
365
|
+
|
|
366
|
+
##### Request and Response
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
// request
|
|
370
|
+
export type TypeOrmIdType = string | number | bigint;
|
|
371
|
+
// response
|
|
372
|
+
export type TypeOrmEntityToLoad = Undefinable<DeepPartial<ObjectLiteral>>;
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
#### Save Entity
|
|
376
|
+
|
|
377
|
+
##### Constructor Parameters
|
|
378
|
+
|
|
379
|
+
| Name | Type | Default Value | Comments |
|
|
380
|
+
|------------------------|----------------------------------------|---------------|----------------------|
|
|
381
|
+
| entityName | string | | TypeOrm entity name. |
|
|
382
|
+
| fillIdBySnowflake | boolean | false | |
|
|
383
|
+
| uniquenessCheckSnippet | ScriptFuncOrBody\<UniquenessCheckFunc> | | |
|
|
384
|
+
|
|
385
|
+
##### Request and Response
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
// request
|
|
389
|
+
export type EntityToSave = DeepPartial<ObjectLiteral>;
|
|
390
|
+
// response
|
|
391
|
+
export type EntityToSave = DeepPartial<ObjectLiteral>;
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### By SQL
|
|
395
|
+
|
|
396
|
+
#### Environment Parameters
|
|
397
|
+
|
|
398
|
+
| Name | Type | Default Value | Comments |
|
|
399
|
+
|-----------------------------|---------|---------------|--------------------------|
|
|
400
|
+
| `typeorm.sql.cache.enabled` | boolean | true | Cache parsed sql or not. |
|
|
401
|
+
|
|
402
|
+
> Parsed SQL will not be cached when there is one-of syntax.
|
|
403
|
+
|
|
404
|
+
#### Constructor Parameters
|
|
405
|
+
|
|
406
|
+
| Name | Type | Default Value | Comments |
|
|
407
|
+
|------|--------|---------------|----------|
|
|
408
|
+
| sql | string | | SQL |
|
|
409
|
+
|
|
410
|
+
#### Native SQL Support & Enhancement
|
|
411
|
+
|
|
412
|
+
SQL supports native database syntax. At the same time, `o23/n3` enhances SQL syntax, allowing the use of the `$property` syntax to retrieve
|
|
413
|
+
corresponding data from data objects, also supports multi-level property names, connected by `.`. For example, `$person.name` represents
|
|
414
|
+
that `person` is an object and `name` is a property under `person`. The following are the supported syntax features:
|
|
415
|
+
|
|
416
|
+
- `IN ($...names)`: `one-of`, `names` should be an array,
|
|
417
|
+
- `LIKE $name%`: `starts-with`,
|
|
418
|
+
- `LIKE $%name`: `ends-with`,
|
|
419
|
+
- `LIKE $%name%`: `contains`.
|
|
420
|
+
|
|
421
|
+
> Name mapping is case-sensitive.
|
|
422
|
+
> `LIKE` is case-sensitive.
|
|
423
|
+
|
|
424
|
+
Since different databases have varying degrees of support for dialects, `o23/n3` also provides appropriate enhanced support for this:
|
|
425
|
+
|
|
426
|
+
- For pagination, `$.limit($offset, $limit)` will be translated and executed in the appropriate dialect. For example,
|
|
427
|
+
- `MySQL` uses `LIMIT $offset, $limit`,
|
|
428
|
+
- `PostgreSQL` uses `OFFSET $offset LIMIT $limit`.
|
|
429
|
+
- `MSSQL` uses `OFFSET $offset ROWS FETCH NEXT $limit ROWS ONLY`,
|
|
430
|
+
- SQL Server requires an `ORDER BY` clause for pagination SQL. If there is no `ORDER BY` clause, will
|
|
431
|
+
use `ORDER BY 1 OFFSET $offset ROWS FETCH NEXT $limit ROWS ONLY`.
|
|
432
|
+
- For JSON column, because some databases (such as MSSQL) do not have a JSON column type, they cannot automatically replace strings in the
|
|
433
|
+
result set with JSON objects,
|
|
434
|
+
- Use `config as "config.@json"` to explicitly indicate that the `config` column is of JSON data type.
|
|
435
|
+
- Use `$config.@json` to explicitly indicate that the `config` property of given parameters is of JSON data type.
|
|
436
|
+
- For boolean column which use numeric(int/smallint/tinyint) as storage type, because some databases (such as PostgreSQL) cannot
|
|
437
|
+
automatically convert boolean values in memory to numeric 0 or 1 in the database,
|
|
438
|
+
- Use `enabled as "enabled.@bool"` to explicitly indicate that the `enabled` column is of boolean in-memory and numeric in database data
|
|
439
|
+
type.
|
|
440
|
+
- Use `$enabled.@bool` to explicitly indicate that the `enabled` property of given parameters is of boolean in-memory and numeric in
|
|
441
|
+
database data type.
|
|
442
|
+
- For datetime (MySQL, MSSQL) / timestamp (Oracle, PostgreSQL) column,
|
|
443
|
+
- Use `created_at as "createAt.@ts"` to explicitly indicate that the `createAt` column is of string in-memory and timestamp in database
|
|
444
|
+
data type.
|
|
445
|
+
- Use `$createAt.@ts` to explicitly indicate that the `createAt` property of given parameters is of string in-memory and timestamp in
|
|
446
|
+
database data type.
|
|
447
|
+
|
|
448
|
+
> We recommend that if you need to consider support for multiple database dialects, using enhanced syntax will make it easier to write SQL.
|
|
449
|
+
> If you only need to support a specific database, then using its standard syntax is sufficient.
|
|
450
|
+
|
|
451
|
+
> It is important to note that some databases (such as `PostgreSQL`) do not differentiate column names by case. This can affect the property
|
|
452
|
+
> names of the returned objects in the result set (usually recommended in camel case). Therefore, even though it is not a syntax
|
|
453
|
+
> enhancement, it is strongly recommended to use aliases to standardize the column names in the returned result set, for
|
|
454
|
+
> example, `PERSON_NAME AS "personName"`, please pay attention to the use of quotation marks to correctly preserve the case.
|
|
455
|
+
|
|
456
|
+
#### Load One by SQL
|
|
457
|
+
|
|
458
|
+
##### Request and Response
|
|
459
|
+
|
|
460
|
+
```typescript
|
|
461
|
+
// request
|
|
462
|
+
export interface TypeOrmLoadBasis extends TypeOrmBasis {
|
|
463
|
+
params?: Array<TypeOrmEntityValue> | TypeOrmEntityToSave;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// response
|
|
467
|
+
export type TypeOrmEntityToLoad = Undefinable<DeepPartial<ObjectLiteral>>;
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
#### Load Many by SQL
|
|
471
|
+
|
|
472
|
+
##### Request and Response
|
|
473
|
+
|
|
474
|
+
```typescript
|
|
475
|
+
// request
|
|
476
|
+
export interface TypeOrmLoadBasis extends TypeOrmBasis {
|
|
477
|
+
params?: Array<TypeOrmEntityValue> | TypeOrmEntityToSave;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// response
|
|
481
|
+
Array<TypeOrmEntityToLoad>;
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
#### Save by SQL
|
|
485
|
+
|
|
486
|
+
##### Request and Response
|
|
487
|
+
|
|
488
|
+
```typescript
|
|
489
|
+
// request
|
|
490
|
+
export interface TypeOrmSaveBasis extends TypeOrmBasis {
|
|
491
|
+
values?: Array<TypeOrmEntityValue> | TypeOrmEntityToSave;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// response
|
|
495
|
+
export type TypeOrmIdOfInserted = TypeOrmIdType;
|
|
496
|
+
export type TypeOrmCountOfAffected = number;
|
|
497
|
+
export type TypeOrmWrittenResult = TypeOrmIdOfInserted | TypeOrmCountOfAffected;
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
#### Bulk Save by SQL
|
|
501
|
+
|
|
502
|
+
##### Request and Response
|
|
503
|
+
|
|
504
|
+
```typescript
|
|
505
|
+
// request
|
|
506
|
+
export interface TypeOrmBulkSaveBasis extends TypeOrmBasis {
|
|
507
|
+
items?: Array<Array<TypeOrmEntityValue> | TypeOrmEntityToSave>;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// response
|
|
511
|
+
export type TypeOrmIdsOfInserted = Array<TypeOrmIdOfInserted>;
|
|
512
|
+
export type TypeOrmCountsOfAffected = Array<TypeOrmCountOfAffected>;
|
|
513
|
+
export type TypeOrmBulkWrittenResult = TypeOrmIdsOfInserted | TypeOrmCountsOfAffected;
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### By Snippet
|
|
517
|
+
|
|
518
|
+
#### Constructor Parameters
|
|
519
|
+
|
|
520
|
+
| Name | Type | Default Value | Comments |
|
|
521
|
+
|---------|---------------------------------------|---------------|----------|
|
|
522
|
+
| snippet | ScriptFuncOrBody\<TypeOrmPerformFunc> | | |
|
|
523
|
+
|
|
524
|
+
A TypeOrm Query Runner instance, `$runner`, will be passed to the snippet, and the snippet can use this instance to perform any operation on
|
|
525
|
+
the database.
|
|
526
|
+
|
|
527
|
+
> You do not need to manually start a transaction, whether you are using autonomous transaction or if it is nested within
|
|
528
|
+
> transaction step sets. The `$runner` instance passed to the snippet will automatically start a transaction.
|
|
529
|
+
|
|
530
|
+
### Transactional
|
|
531
|
+
|
|
532
|
+
Transactional step sets are a wrapper for a set of pipeline steps that require the same transaction. It means that all the
|
|
533
|
+
sub-steps inside a transactional step set can be executed within a single transaction. However, not all sub-steps within the set necessarily
|
|
534
|
+
have to be transactional. Only the ones that need to be executed within the same transaction need to define the same transaction name as the
|
|
535
|
+
step set. Additionally, nested transactions are also supported, which means Transactional Step Sets can be nested as well.
|
|
536
|
+
|
|
537
|
+
> Steps with same datasource name and transaction name should be within same transaction.
|
|
538
|
+
|
|
539
|
+
### Constructor Parameters
|
|
540
|
+
|
|
541
|
+
| Name | Type | Default Value | Comments |
|
|
542
|
+
|-----------------|-----------------------------|----------------------|------------------------|
|
|
543
|
+
| dataSourceName | string | | Datasource name, `DB`. |
|
|
544
|
+
| transactionName | string | $default-transaction | Transaction name. |
|
|
545
|
+
| steps | Array\<PipelineStepBuilder> | | Sub steps. |
|
|
546
|
+
|
|
547
|
+
## Http Steps
|
|
548
|
+
|
|
549
|
+
### Fetch
|
|
550
|
+
|
|
551
|
+
#### Environment Parameters
|
|
552
|
+
|
|
553
|
+
| Name | Type | Default Value | Comments |
|
|
554
|
+
|---------------------------------------|---------|---------------|-----------------------------------------------------------------------------------------------------------------------------------|
|
|
555
|
+
| `endpoints.SYSTEM.ENDPOINT.url` | string | | Endpoint URL. |
|
|
556
|
+
| `endpoints.SYSTEM.ENDPOINT.method` | string | POST | Endpoint http method. |
|
|
557
|
+
| `endpoints.SYSTEM.ENDPOINT.headers` | string | | Endpoint request headers, use global headers if this parameter doesn't present.<br>Format follows `name=value[;name=value[...]]`. |
|
|
558
|
+
| `endpoints.SYSTEM.global.headers` | string | | Endpoint system global request headers.<br>Format follows `name=value[;name=value[...]]`. |
|
|
559
|
+
| `endpoints.SYSTEM.ENDPOINT.timeout` | string | | Endpoint request timeout, in milliseconds, use global timeout if this parameter doesn't present. |
|
|
560
|
+
| `endpoints.SYSTEM.global.timeout` | string | -1 | Endpoint system global timeout, in milliseconds, `-1` represents no timeout. |
|
|
561
|
+
| `endpoints.SYSTEM.ENDPOINT.body.used` | boolean | true | Endpoint use request body or not. |
|
|
562
|
+
|
|
563
|
+
`SYSTEM` represents endpoint system, `ENDPOINT` represents endpoint url. For example:
|
|
564
|
+
|
|
565
|
+
```properties
|
|
566
|
+
CFG_ENDPOINTS_ORDER_PURCHASE_URL=https://order.com/purchase
|
|
567
|
+
CFG_ENDPOINTS_ORDER_PAYMENT_URL=https://order.com/payment
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
#### Constructor Parameters
|
|
571
|
+
|
|
572
|
+
| Name | Type | Default Value | Comments |
|
|
573
|
+
|----------------------|------------------------------------------------------------|---------------|------------------------------------------------|
|
|
574
|
+
| endpointSystemCode | string | | Endpoint system code. |
|
|
575
|
+
| endpointName | string | | Endpoint name. |
|
|
576
|
+
| urlGenerate | ScriptFuncOrBody\<HttpGenerateUrl> | | Endpoint url generator, `$endpointUrl`. |
|
|
577
|
+
| headersGenerate | ScriptFuncOrBody\<HttpGenerateHeaders> | | Endpoint request headers generator. |
|
|
578
|
+
| bodyGenerate | ScriptFuncOrBody\<HttpGenerateBody> | | Endpoint request body generator. |
|
|
579
|
+
| responseGenerate | ScriptFuncOrBody\<HttpGenerateResponse> | | Endpoint response body generator, `$response`. |
|
|
580
|
+
| responseErrorHandles | {[key: HttpErrorCode]: ScriptFuncOrBody\<HttpHandleError>} | | Endpoint response error handlers. |
|
|
581
|
+
|
|
582
|
+
## Installation
|
|
583
|
+
|
|
584
|
+
Note since nestjs only support commonjs module, which means `node-fetch` 3 series cannot be imported since it is built on esm mode.
|