@uql/core 0.4.81 → 0.4.84

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.
Files changed (49) hide show
  1. package/README.md +36 -51
  2. package/dialect/abstractSqlDialect-spec.d.ts +49 -0
  3. package/dialect/abstractSqlDialect-spec.js +765 -0
  4. package/dialect/mysqlDialect.spec.d.ts +6 -0
  5. package/dialect/mysqlDialect.spec.js +33 -0
  6. package/dialect/postgresDialect.spec.d.ts +1 -0
  7. package/dialect/postgresDialect.spec.js +139 -0
  8. package/dialect/sqliteDialect.spec.d.ts +1 -0
  9. package/dialect/sqliteDialect.spec.js +12 -0
  10. package/entity/decorator/definition.js +18 -18
  11. package/entity/decorator/definition.spec.d.ts +1 -0
  12. package/entity/decorator/definition.spec.js +725 -0
  13. package/entity/decorator/relation.spec.d.ts +1 -0
  14. package/entity/decorator/relation.spec.js +55 -0
  15. package/options.spec.d.ts +1 -0
  16. package/options.spec.js +50 -0
  17. package/package.json +3 -3
  18. package/querier/abstractQuerier-it.d.ts +41 -0
  19. package/querier/abstractQuerier-it.js +410 -0
  20. package/querier/abstractSqlQuerier-it.d.ts +9 -0
  21. package/querier/abstractSqlQuerier-it.js +19 -0
  22. package/querier/abstractSqlQuerier-spec.d.ts +53 -0
  23. package/querier/abstractSqlQuerier-spec.js +607 -0
  24. package/querier/decorator/injectQuerier.spec.d.ts +1 -0
  25. package/querier/decorator/injectQuerier.spec.js +108 -0
  26. package/querier/decorator/transactional.spec.d.ts +1 -0
  27. package/querier/decorator/transactional.spec.js +241 -0
  28. package/repository/genericRepository.spec.d.ts +1 -0
  29. package/repository/genericRepository.spec.js +86 -0
  30. package/test/entityMock.d.ts +180 -0
  31. package/test/entityMock.js +451 -0
  32. package/test/index.d.ts +3 -0
  33. package/test/index.js +7 -0
  34. package/test/it.util.d.ts +4 -0
  35. package/test/it.util.js +60 -0
  36. package/test/spec.util.d.ts +13 -0
  37. package/test/spec.util.js +54 -0
  38. package/type/entity.d.ts +15 -20
  39. package/type/entity.js +1 -1
  40. package/type/utility.d.ts +1 -1
  41. package/type/utility.js +1 -1
  42. package/util/dialect.util.spec.d.ts +1 -0
  43. package/util/dialect.util.spec.js +23 -0
  44. package/util/object.util.spec.d.ts +1 -0
  45. package/util/object.util.spec.js +26 -0
  46. package/util/sql.util.spec.d.ts +1 -0
  47. package/util/sql.util.spec.js +164 -0
  48. package/util/string.util.spec.d.ts +1 -0
  49. package/util/string.util.spec.js +26 -0
package/README.md CHANGED
@@ -55,8 +55,8 @@ Given it is just a small library with serializable `JSON` syntax, the queries ca
55
55
  | `MySQL` | `@uql/mysql` |
56
56
  | `MariaDB` | `@uql/maria` |
57
57
  | `PostgreSQL` | `@uql/postgres` |
58
- | `SQLite` | `@uql/sqlite` |
59
58
  | `MongoDB` | `@uql/mongo` |
59
+ | `SQLite` | `@uql/sqlite` |
60
60
 
61
61
  E.g. for `PostgreSQL`
62
62
 
@@ -86,17 +86,17 @@ Initialization should be done once (e.g. in one of the bootstrap files of your a
86
86
  import { setOptions } from '@uql/core';
87
87
  import { PgQuerierPool } from '@uql/postgres';
88
88
 
89
- setOptions({
90
- querierPool: new PgQuerierPool(
91
- {
92
- host: 'localhost',
93
- user: 'theUser',
94
- password: 'thePassword',
95
- database: 'theDatabase',
96
- },
97
- console.log
98
- ),
99
- });
89
+ const querierPool = new PgQuerierPool(
90
+ {
91
+ host: 'localhost',
92
+ user: 'theUser',
93
+ password: 'thePassword',
94
+ database: 'theDatabase',
95
+ },
96
+ console.log
97
+ );
98
+
99
+ setOptions({ querierPool });
100
100
  ```
101
101
 
102
102
  ## <a name="entities"></a> Entities
@@ -104,6 +104,8 @@ setOptions({
104
104
  Take any dump class (aka DTO) and annotate it with the decorators from `'@uql/core/entity'`.
105
105
 
106
106
  ```ts
107
+ import { v4 as uuidv4 } from 'uuid';
108
+
107
109
  import { Field, ManyToOne, Id, OneToMany, Entity, OneToOne, ManyToMany } from '@uql/core/entity';
108
110
 
109
111
  @Entity()
@@ -111,21 +113,21 @@ export class Profile {
111
113
  /**
112
114
  * primary key
113
115
  */
114
- @Id()
115
- id?: number;
116
+ @Id({ onInsert: uuidv4 })
117
+ id?: string;
116
118
  @Field()
117
119
  picture?: string;
118
120
  /**
119
121
  * foreign-keys are really simple to specify.
120
122
  */
121
123
  @Field({ reference: () => User })
122
- creatorId?: number;
124
+ creatorId?: string;
123
125
  }
124
126
 
125
127
  @Entity()
126
128
  export class User {
127
- @Id()
128
- id?: number;
129
+ @Id({ onInsert: uuidv4 })
130
+ id?: string;
129
131
  @Field()
130
132
  name?: string;
131
133
  @Field()
@@ -141,8 +143,8 @@ export class User {
141
143
 
142
144
  @Entity()
143
145
  export class MeasureUnitCategory {
144
- @Id()
145
- id?: number;
146
+ @Id({ onInsert: uuidv4 })
147
+ id?: string;
146
148
  @Field()
147
149
  name?: string;
148
150
  @OneToMany({ entity: () => MeasureUnit, mappedBy: (measureUnit) => measureUnit.category })
@@ -151,20 +153,20 @@ export class MeasureUnitCategory {
151
153
 
152
154
  @Entity()
153
155
  export class MeasureUnit {
154
- @Id()
155
- id?: number;
156
+ @Id({ onInsert: uuidv4 })
157
+ id?: string;
156
158
  @Field()
157
159
  name?: string;
158
160
  @Field({ reference: () => MeasureUnitCategory })
159
- categoryId?: number;
161
+ categoryId?: string;
160
162
  @ManyToOne({ cascade: 'persist' })
161
163
  category?: MeasureUnitCategory;
162
164
  }
163
165
 
164
166
  @Entity()
165
167
  export class Item {
166
- @Id()
167
- id?: number;
168
+ @Id({ onInsert: uuidv4 })
169
+ id?: string;
168
170
  @Field()
169
171
  name?: string;
170
172
  @Field()
@@ -177,8 +179,8 @@ export class Item {
177
179
 
178
180
  @Entity()
179
181
  export class Tag {
180
- @Id()
181
- id?: number;
182
+ @Id({ onInsert: uuidv4 })
183
+ id?: string;
182
184
  @Field()
183
185
  name?: string;
184
186
  @ManyToMany({ entity: () => Item, mappedBy: (item) => item.tags })
@@ -187,12 +189,12 @@ export class Tag {
187
189
 
188
190
  @Entity()
189
191
  export class ItemTag {
190
- @Id()
191
- id?: number;
192
+ @Id({ onInsert: uuidv4 })
193
+ id?: string;
192
194
  @Field({ reference: () => Item })
193
- itemId?: number;
195
+ itemId?: string;
194
196
  @Field({ reference: () => Tag })
195
- tagId?: number;
197
+ tagId?: string;
196
198
  }
197
199
  ```
198
200
 
@@ -252,6 +254,7 @@ import { getQuerier } from '@uql/core';
252
254
 
253
255
  async function confirm(confirmation: Confirmation): Promise<void> {
254
256
  const querier = await getQuerier();
257
+
255
258
  await querier.transaction(async () => {
256
259
  if (confirmation.action === 'signup') {
257
260
  await querier.insertOne(User, {
@@ -276,6 +279,7 @@ That &#9650; can also be implemented as this &#9660; (for more granular control)
276
279
  ```ts
277
280
  async function confirm(confirmation: Confirmation): Promise<void> {
278
281
  const querier = await getQuerier();
282
+
279
283
  try {
280
284
  await querier.beginTransaction();
281
285
  if (confirmation.action === 'signup') {
@@ -326,27 +330,8 @@ import { querierMiddleware } from '@uql/express';
326
330
 
327
331
  const app = express();
328
332
 
329
- app
330
- // ...
331
- .use(
332
- '/api',
333
-
334
- // this will generate REST APIs for the entities.
335
- querierMiddleware({
336
- // all entities will be automatically exposed unless
337
- // 'include' or 'exclude' options are provided.
338
- exclude: [Confirmation],
339
-
340
- // `augmentQuery` callback allows to extend all then queries that are requested to the API,
341
- // so it is a good place to add additional filters to the queries,
342
- // e.g. for multi tenant apps.
343
- augmentQuery: <E>(meta: EntityMeta<E>, qm: Query<E>, req: express.Request): Query<E> => {
344
- // ensure the user can only see the data that belongs to his company.
345
- qm.$filter = augmentFilter(meta, qm.$filter, { companyId: req.identity.companyId } as QueryFilter<E>);
346
- return qm;
347
- },
348
- })
349
- );
333
+ // this will generate REST APIs for the entities.
334
+ app.use('/api', querierMiddleware());
350
335
  ```
351
336
 
352
337
  ## <a name="client"></a> Easily call the generated REST APIs from the Client
@@ -0,0 +1,49 @@
1
+ import { Spec } from '@uql/core/test';
2
+ import { AbstractSqlDialect } from './abstractSqlDialect';
3
+ export declare abstract class AbstractSqlDialectSpec implements Spec {
4
+ readonly dialect: AbstractSqlDialect;
5
+ constructor(dialect: AbstractSqlDialect);
6
+ shouldBeValidEscapeCharacter(): void;
7
+ shouldBeginTransaction(): void;
8
+ shouldInsertMany(): void;
9
+ shouldInsertOne(): void;
10
+ shouldInsertWithOnInsertId(): void;
11
+ shouldInsertManyWithSpecifiedIdsAndOnInsertIdAsDefault(): void;
12
+ shouldUpdate(): void;
13
+ shouldFind(): void;
14
+ shouldBeSecure(): void;
15
+ shouldFind$and(): void;
16
+ shouldFind$or(): void;
17
+ shouldFind$not(): void;
18
+ shouldFind$nor(): void;
19
+ shouldFind$orAnd$and(): void;
20
+ shouldFindSingle$filter(): void;
21
+ shouldFindMultipleComparisonOperators(): void;
22
+ shouldFind$ne(): void;
23
+ shouldFindIsNull(): void;
24
+ shouldFind$in(): void;
25
+ shouldFind$nin(): void;
26
+ shouldFind$projectFields(): void;
27
+ shouldFind$projectOneToOne(): void;
28
+ shouldFind$projectManyToOne(): void;
29
+ shouldFind$projectWithAllFieldsAndSpecificFieldsAndFilter(): void;
30
+ shouldVirtualField(): void;
31
+ shouldFind$projectDeep(): void;
32
+ shouldFind$group(): void;
33
+ shouldFind$limit(): void;
34
+ shouldFind$skip(): void;
35
+ shouldFind$project(): void;
36
+ shouldDelete(): void;
37
+ shouldFind$projectRaw(): void;
38
+ shouldFind$filterRaw(): void;
39
+ shouldFind$startsWith(): void;
40
+ shouldFind$istartsWith(): void;
41
+ shouldFind$endsWith(): void;
42
+ shouldFind$iendsWith(): void;
43
+ shouldFind$includes(): void;
44
+ shouldFind$iincludes(): void;
45
+ shouldFind$like(): void;
46
+ shouldFind$ilike(): void;
47
+ shouldFind$regex(): void;
48
+ shouldFind$text(): void;
49
+ }