tantan-typeorm-gs 1.0.0

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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/bun.lock +300 -0
  4. package/docs/authentication.md +118 -0
  5. package/docs/configuration.md +680 -0
  6. package/docs/contributing.md +177 -0
  7. package/docs/crud.md +351 -0
  8. package/docs/custom-client.md +165 -0
  9. package/docs/development.md +243 -0
  10. package/docs/entities.md +502 -0
  11. package/docs/find-options.md +296 -0
  12. package/docs/google-cloud.md +101 -0
  13. package/docs/installation.md +51 -0
  14. package/docs/integration-testing.md +178 -0
  15. package/docs/limitations.md +223 -0
  16. package/docs/pagination.md +384 -0
  17. package/docs/performance.md +171 -0
  18. package/docs/security.md +153 -0
  19. package/docs/sorting.md +0 -0
  20. package/docs/supported-features.md +310 -0
  21. package/docs/synchronization.md +203 -0
  22. package/package.json +43 -0
  23. package/src/client/index.ts +589 -0
  24. package/src/core/data-source.ts +47 -0
  25. package/src/core/driver.ts +290 -0
  26. package/src/core/error.ts +144 -0
  27. package/src/core/memory.ts +152 -0
  28. package/src/core/query/interpreter.ts +949 -0
  29. package/src/core/query/runner.ts +1297 -0
  30. package/src/core/query/types.ts +155 -0
  31. package/src/core/schema-builder.ts +64 -0
  32. package/src/core/types.ts +113 -0
  33. package/src/core/utils.ts +13 -0
  34. package/src/index.ts +3 -0
  35. package/tantan-typeorm-gs.code-workspace +8 -0
  36. package/test/base/0001-data-source.test.ts +252 -0
  37. package/test/base/0002-operator.test.ts +616 -0
  38. package/test/base/0003-select.test.ts +281 -0
  39. package/test/base/0004-aggregate.test.ts +213 -0
  40. package/test/base/0005-transcation.test.ts +1566 -0
  41. package/test/base/0006-relation.test.ts +1611 -0
  42. package/test/base/0007-logging.test.ts +182 -0
  43. package/test/base/0008-soft-delete.test.ts +649 -0
  44. package/test/google-sheets/0001-client.test.ts +1705 -0
  45. package/test/google-sheets/0002-worksheet-management.test.ts +408 -0
  46. package/test/google-sheets/0003-data-source.test.ts +1935 -0
  47. package/test/google-sheets/0004-transactions.test.ts +952 -0
  48. package/test/google-sheets/0005-operator.test.ts +1124 -0
  49. package/test/google-sheets/0006-object-criteria.test.ts +283 -0
  50. package/test/google-sheets/0007-performance.test.ts +532 -0
  51. package/test/public-api.test.ts +34 -0
  52. package/tsconfig.build.json +21 -0
  53. package/tsconfig.json +34 -0
@@ -0,0 +1,283 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import
3
+ {
4
+ Column,
5
+ Entity,
6
+ PrimaryGeneratedColumn,
7
+ } from 'typeorm';
8
+ import { Memory } from '../../src/core/memory';
9
+ import { createGoogleSheetsDataSource, type GoogleSheetsRow } from '../../src';
10
+
11
+ describe('Query Object Criteria', () =>
12
+ {
13
+ @Entity('query_users')
14
+ class QueryUser
15
+ {
16
+ @PrimaryGeneratedColumn()
17
+ id!: number;
18
+
19
+ @Column()
20
+ name!: string;
21
+
22
+ @Column()
23
+ email!: string;
24
+ }
25
+
26
+ async function createDataSource(
27
+ rows: GoogleSheetsRow[] = [],
28
+ )
29
+ {
30
+ const client =
31
+ new Memory({
32
+ query_users: rows,
33
+ });
34
+
35
+ await client.insertHeaders(
36
+ 'query_users',
37
+ [
38
+ 'id',
39
+ 'name',
40
+ 'email',
41
+ ],
42
+ );
43
+
44
+ const dataSource =
45
+ createGoogleSheetsDataSource({
46
+ type: 'google-sheets',
47
+
48
+ client,
49
+
50
+ entities: [
51
+ QueryUser,
52
+ ],
53
+ });
54
+
55
+ await dataSource.initialize();
56
+
57
+ return {
58
+ client,
59
+ dataSource,
60
+ };
61
+ }
62
+
63
+ test(
64
+ 'should find entities using object criteria',
65
+ async () =>
66
+ {
67
+ const {
68
+ dataSource,
69
+ } =
70
+ await createDataSource([
71
+ {
72
+ id: 1,
73
+ name: 'John',
74
+ email: 'john@example.com',
75
+ },
76
+ {
77
+ id: 2,
78
+ name: 'Jane',
79
+ email: 'jane@example.com',
80
+ },
81
+ {
82
+ id: 3,
83
+ name: 'John',
84
+ email: 'john2@example.com',
85
+ },
86
+ ]);
87
+
88
+ try
89
+ {
90
+ const repository =
91
+ dataSource.getRepository(
92
+ QueryUser,
93
+ );
94
+
95
+ const users =
96
+ await repository.find({
97
+ where: {
98
+ name: 'John',
99
+ },
100
+ });
101
+
102
+ expect(users)
103
+ .toEqual([
104
+ {
105
+ id: 1,
106
+ name: 'John',
107
+ email: 'john@example.com',
108
+ },
109
+ {
110
+ id: 3,
111
+ name: 'John',
112
+ email: 'john2@example.com',
113
+ },
114
+ ]);
115
+ }
116
+ finally
117
+ {
118
+ if (dataSource.isInitialized)
119
+ {
120
+ await dataSource.destroy();
121
+ }
122
+ }
123
+ },
124
+ );
125
+
126
+ test(
127
+ 'should find one entity using object criteria',
128
+ async () =>
129
+ {
130
+ const {
131
+ dataSource,
132
+ } =
133
+ await createDataSource([
134
+ {
135
+ id: 1,
136
+ name: 'John',
137
+ email: 'john@example.com',
138
+ },
139
+ {
140
+ id: 2,
141
+ name: 'Jane',
142
+ email: 'jane@example.com',
143
+ },
144
+ ]);
145
+
146
+ try
147
+ {
148
+ const repository =
149
+ dataSource.getRepository(
150
+ QueryUser,
151
+ );
152
+
153
+ const user =
154
+ await repository.findOne({
155
+ where: {
156
+ email: 'jane@example.com',
157
+ },
158
+ });
159
+
160
+ expect(user)
161
+ .toEqual({
162
+ id: 2,
163
+ name: 'Jane',
164
+ email: 'jane@example.com',
165
+ });
166
+ }
167
+ finally
168
+ {
169
+ if (dataSource.isInitialized)
170
+ {
171
+ await dataSource.destroy();
172
+ }
173
+ }
174
+ },
175
+ );
176
+
177
+ test(
178
+ 'should find entities using multiple object criteria',
179
+ async () =>
180
+ {
181
+ const {
182
+ dataSource,
183
+ } =
184
+ await createDataSource([
185
+ {
186
+ id: 1,
187
+ name: 'John',
188
+ email: 'john@example.com',
189
+ },
190
+ {
191
+ id: 2,
192
+ name: 'Jane',
193
+ email: 'jane@example.com',
194
+ },
195
+ {
196
+ id: 3,
197
+ name: 'John',
198
+ email: 'john2@example.com',
199
+ },
200
+ ]);
201
+
202
+ try
203
+ {
204
+ const repository =
205
+ dataSource.getRepository(
206
+ QueryUser,
207
+ );
208
+
209
+ const users =
210
+ await repository.find({
211
+ where: {
212
+ name: 'John',
213
+ email: 'john@example.com',
214
+ },
215
+ });
216
+
217
+ expect(users)
218
+ .toEqual([
219
+ {
220
+ id: 1,
221
+ name: 'John',
222
+ email: 'john@example.com',
223
+ },
224
+ ]);
225
+ }
226
+ finally
227
+ {
228
+ if (dataSource.isInitialized)
229
+ {
230
+ await dataSource.destroy();
231
+ }
232
+ }
233
+ },
234
+ );
235
+
236
+ test(
237
+ 'should return empty result when object criteria does not match',
238
+ async () =>
239
+ {
240
+ const {
241
+ dataSource,
242
+ } =
243
+ await createDataSource([
244
+ {
245
+ id: 1,
246
+ name: 'John',
247
+ email: 'john@example.com',
248
+ },
249
+ {
250
+ id: 2,
251
+ name: 'Jane',
252
+ email: 'jane@example.com',
253
+ },
254
+ ]);
255
+
256
+ try
257
+ {
258
+ const repository =
259
+ dataSource.getRepository(
260
+ QueryUser,
261
+ );
262
+
263
+ const users =
264
+ await repository.find({
265
+ where: {
266
+ name: 'Unknown',
267
+ },
268
+ });
269
+
270
+ expect(users)
271
+ .toEqual([]);
272
+ }
273
+ finally
274
+ {
275
+ if (dataSource.isInitialized)
276
+ {
277
+ await dataSource.destroy();
278
+ }
279
+ }
280
+ },
281
+ );
282
+ },
283
+ );