@stdex/create 0.0.0-stage → 1.2.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 (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -2
  3. package/README_EN.md +67 -0
  4. package/package.json +40 -3
  5. package/src/eslint.config.js +2 -0
  6. package/src/index.js +233 -0
  7. package/templates/base/eslint.config.js +2 -0
  8. package/templates/base/index.js +3 -0
  9. package/templates/base/package.json +16 -0
  10. package/templates/miniprogram/README.md +27 -0
  11. package/templates/miniprogram/_gitignore +3 -0
  12. package/templates/miniprogram/eslint.config.cjs +25 -0
  13. package/templates/miniprogram/gulpfile.js +81 -0
  14. package/templates/miniprogram/package.json +22 -0
  15. package/templates/miniprogram/project.config.json +31 -0
  16. package/templates/miniprogram/project.private.config.json +8 -0
  17. package/templates/miniprogram/src/app.json +16 -0
  18. package/templates/miniprogram/src/app.scss +0 -0
  19. package/templates/miniprogram/src/app.ts +6 -0
  20. package/templates/miniprogram/src/lib/app-data.ts +46 -0
  21. package/templates/miniprogram/src/pages/index/index.json +3 -0
  22. package/templates/miniprogram/src/pages/index/index.scss +11 -0
  23. package/templates/miniprogram/src/pages/index/index.ts +13 -0
  24. package/templates/miniprogram/src/pages/index/index.wxml +1 -0
  25. package/templates/miniprogram/src/sitemap.json +9 -0
  26. package/templates/miniprogram/tsconfig.json +11 -0
  27. package/templates/miniprogram/typings/index.d.ts +5 -0
  28. package/templates/miniprogram/typings/types/index.d.ts +1 -0
  29. package/templates/miniprogram/typings/types/wx/index.d.ts +162 -0
  30. package/templates/miniprogram/typings/types/wx/lib.wx.api.d.ts +32387 -0
  31. package/templates/miniprogram/typings/types/wx/lib.wx.app.d.ts +400 -0
  32. package/templates/miniprogram/typings/types/wx/lib.wx.behavior.d.ts +68 -0
  33. package/templates/miniprogram/typings/types/wx/lib.wx.canvas.d.ts +2623 -0
  34. package/templates/miniprogram/typings/types/wx/lib.wx.cloud.d.ts +1016 -0
  35. package/templates/miniprogram/typings/types/wx/lib.wx.component.d.ts +700 -0
  36. package/templates/miniprogram/typings/types/wx/lib.wx.event.d.ts +1436 -0
  37. package/templates/miniprogram/typings/types/wx/lib.wx.page.d.ts +272 -0
  38. package/templates/miniprogram/typings/types/wx/lib.wx.phys3D.d.ts +409 -0
  39. package/templates/miniprogram/typings/types/wx/lib.wx.wasm.d.ts +152 -0
  40. package/templates/miniprogram/typings/types/wx/lib.wx.xr-frame.d.ts +15631 -0
  41. package/templates/miniprogram/variables.json +11 -0
  42. package/templates/service/README.md +64 -0
  43. package/templates/service/_env +1 -0
  44. package/templates/service/_gitignore +5 -0
  45. package/templates/service/eslint.config.js +2 -0
  46. package/templates/service/package.json +48 -0
  47. package/templates/service/prisma/schema.prisma +40 -0
  48. package/templates/service/prisma/sql/demoTypedSql.sql +1 -0
  49. package/templates/service/prisma.config.ts +12 -0
  50. package/templates/service/setup.js +4 -0
  51. package/templates/service/src/cache.ts +28 -0
  52. package/templates/service/src/config.ts +49 -0
  53. package/templates/service/src/controllers/common.ts +43 -0
  54. package/templates/service/src/controllers/demo-school.ts +7 -0
  55. package/templates/service/src/controllers/demo-student.ts +7 -0
  56. package/templates/service/src/controllers/index.ts +15 -0
  57. package/templates/service/src/database.ts +52 -0
  58. package/templates/service/src/index.ts +15 -0
  59. package/templates/service/src/logger.ts +10 -0
  60. package/templates/service/src/routes/demo-school.ts +9 -0
  61. package/templates/service/src/routes/index.ts +3 -0
  62. package/templates/service/src/routes/router.ts +42 -0
  63. package/templates/service/src/tasks/common.ts +25 -0
  64. package/templates/service/src/tasks/demo-school.ts +10 -0
  65. package/templates/service/src/tasks/index.ts +1 -0
  66. package/templates/service/tsconfig.build.json +9 -0
  67. package/templates/service/tsconfig.json +10 -0
  68. package/templates/site/_gitignore +3 -0
  69. package/templates/site/_pnpm-workspace.yaml +4 -0
  70. package/templates/site/eslint.config.js +19 -0
  71. package/templates/site/package.json +41 -0
  72. package/templates/site/public/favicon.png +0 -0
  73. package/templates/site/src/app/header.tsx +31 -0
  74. package/templates/site/src/app/index.tsx +38 -0
  75. package/templates/site/src/app/layout.tsx +63 -0
  76. package/templates/site/src/app/menu.tsx +115 -0
  77. package/templates/site/src/app/router.tsx +50 -0
  78. package/templates/site/src/app/style.css +9 -0
  79. package/templates/site/src/assets/logo.png +0 -0
  80. package/templates/site/src/components/Breadcrumb.tsx +47 -0
  81. package/templates/site/src/components/DevStatus.tsx +14 -0
  82. package/templates/site/src/index.html +13 -0
  83. package/templates/site/src/index.tsx +5 -0
  84. package/templates/site/src/lib/config.ts +6 -0
  85. package/templates/site/src/lib/init-dayjs.ts +8 -0
  86. package/templates/site/src/lib/logging.ts +5 -0
  87. package/templates/site/src/views/dashboard.tsx +7 -0
  88. package/templates/site/src/views/school-detail.tsx +13 -0
  89. package/templates/site/src/views/school-ranking.tsx +7 -0
  90. package/templates/site/src/views/schools.tsx +43 -0
  91. package/templates/site/src/views/setting.tsx +7 -0
  92. package/templates/site/src/views/student-score.tsx +7 -0
  93. package/templates/site/src/views/students.tsx +7 -0
  94. package/templates/site/tsconfig.json +10 -0
  95. package/templates/site/vite.config.js +60 -0
@@ -0,0 +1,1016 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) 2023 Tencent, Inc. All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ ***************************************************************************** */
22
+
23
+ /**
24
+ * Common interfaces and types
25
+ */
26
+
27
+ interface IAPIError {
28
+ errMsg: string
29
+ }
30
+
31
+ interface IAPIParam<T = any> {
32
+ config?: ICloudConfig
33
+ success?: (res: T) => void
34
+ fail?: (err: IAPIError) => void
35
+ complete?: (val: T | IAPIError) => void
36
+ }
37
+
38
+ interface IAPISuccessParam {
39
+ errMsg: string
40
+ }
41
+
42
+ type IAPICompleteParam = IAPISuccessParam | IAPIError
43
+
44
+ type IAPIFunction<T, P extends IAPIParam<T>> = (param?: P) => Promise<T>
45
+
46
+ interface IInitCloudConfig {
47
+ env?:
48
+ | string
49
+ | {
50
+ database?: string
51
+ functions?: string
52
+ storage?: string
53
+ }
54
+ traceUser?: boolean
55
+ }
56
+
57
+ interface ICloudConfig {
58
+ env?: string
59
+ traceUser?: boolean
60
+ }
61
+
62
+ interface IICloudAPI {
63
+ init: (config?: IInitCloudConfig) => void
64
+ [api: string]: AnyFunction | IAPIFunction<any, any>
65
+ }
66
+
67
+ interface ICloudService {
68
+ name: string
69
+
70
+ getAPIs: () => { [name: string]: IAPIFunction<any, any> }
71
+ }
72
+
73
+ interface ICloudServices {
74
+ [serviceName: string]: ICloudService
75
+ }
76
+
77
+ interface ICloudMetaData {
78
+ session_id: string
79
+ }
80
+
81
+ declare class InternalSymbol {}
82
+
83
+ interface AnyObject {
84
+ [x: string]: any
85
+ }
86
+
87
+ type AnyArray = any[]
88
+
89
+ type AnyFunction = (...args: any[]) => any
90
+
91
+ /**
92
+ * extend wx with cloud
93
+ */
94
+ interface WxCloud {
95
+ init: (config?: ICloudConfig) => void
96
+
97
+ callFunction(param: OQ<ICloud.CallFunctionParam>): void
98
+ callFunction(
99
+ param: RQ<ICloud.CallFunctionParam>
100
+ ): Promise<ICloud.CallFunctionResult>
101
+
102
+ uploadFile(param: OQ<ICloud.UploadFileParam>): WechatMiniprogram.UploadTask
103
+ uploadFile(
104
+ param: RQ<ICloud.UploadFileParam>
105
+ ): Promise<ICloud.UploadFileResult>
106
+
107
+ downloadFile(
108
+ param: OQ<ICloud.DownloadFileParam>
109
+ ): WechatMiniprogram.DownloadTask
110
+ downloadFile(
111
+ param: RQ<ICloud.DownloadFileParam>
112
+ ): Promise<ICloud.DownloadFileResult>
113
+
114
+ getTempFileURL(param: OQ<ICloud.GetTempFileURLParam>): void
115
+ getTempFileURL(
116
+ param: RQ<ICloud.GetTempFileURLParam>
117
+ ): Promise<ICloud.GetTempFileURLResult>
118
+
119
+ deleteFile(param: OQ<ICloud.DeleteFileParam>): void
120
+ deleteFile(
121
+ param: RQ<ICloud.DeleteFileParam>
122
+ ): Promise<ICloud.DeleteFileResult>
123
+
124
+ database: (config?: ICloudConfig) => DB.Database
125
+
126
+ CloudID: ICloud.ICloudIDConstructor
127
+ CDN: ICloud.ICDNConstructor
128
+
129
+ callContainer(param: OQ<ICloud.CallContainerParam>): void
130
+ callContainer(
131
+ param: RQ<ICloud.CallContainerParam>
132
+ ): Promise<ICloud.CallContainerResult>
133
+
134
+ connectContainer(param: OQ<ICloud.ConnectContainerParam>): void
135
+ connectContainer(
136
+ param: RQ<ICloud.ConnectContainerParam>
137
+ ): Promise<ICloud.ConnectContainerResult>
138
+
139
+ services: ICloud.CloudServices
140
+ }
141
+
142
+ declare namespace ICloud {
143
+ interface ICloudAPIParam<T = any> extends IAPIParam<T> {
144
+ config?: ICloudConfig
145
+ }
146
+
147
+ // === API: callFunction ===
148
+ type CallFunctionData = AnyObject
149
+
150
+ interface CallFunctionResult extends IAPISuccessParam {
151
+ result: AnyObject | string | undefined
152
+ }
153
+
154
+ interface CallFunctionParam extends ICloudAPIParam<CallFunctionResult> {
155
+ name: string
156
+ data?: CallFunctionData
157
+ slow?: boolean
158
+ }
159
+ // === end ===
160
+
161
+ // === API: container ===
162
+ type CallContainerData = AnyObject
163
+
164
+ interface CallContainerResult extends IAPISuccessParam {
165
+ data: any
166
+ statusCode: number
167
+ header: Record<string, any>
168
+ callID: string
169
+ }
170
+
171
+ interface CallContainerParam extends ICloudAPIParam<CallContainerResult> {
172
+ path: string
173
+ service?: string
174
+ method?: string
175
+ header?: Record<string, any>
176
+ data?: any // string, object, ArrayBuffer
177
+ dataType?: string
178
+ responseType?: string
179
+ timeout?: number
180
+ verbose?: boolean
181
+ followRedirect?: boolean
182
+ }
183
+
184
+ interface ConnectContainerResult extends IAPISuccessParam {
185
+ socketTask: WechatMiniprogram.SocketTask
186
+ }
187
+
188
+ interface ConnectSocketOptions extends IAPIParam<void> {
189
+ header?: Record<string, string>
190
+ protocols?: string[]
191
+ tcpNoDelay?: boolean
192
+ perMessageDeflate?: boolean
193
+ timeout?: number
194
+ }
195
+
196
+ type ConnectContainerParam = Omit<
197
+ ConnectSocketOptions,
198
+ 'success' | 'fail' | 'complete'
199
+ > &
200
+ ICloudAPIParam<ConnectContainerResult> & {
201
+ service: string
202
+ path?: string
203
+ }
204
+ // === end ===
205
+
206
+ // === API: services ===
207
+ type AsyncSession<T> = T | PromiseLike<T>
208
+ interface GatewayCallOptions {
209
+ path: string
210
+ data: any
211
+ shouldSerialize?: boolean
212
+ apiVersion?: number
213
+ }
214
+ interface GatewayInstance {
215
+ call: (
216
+ param: CallContainerParam & GatewayCallOptions
217
+ ) => Promise<CallContainerResult>
218
+ refresh: (session: AsyncSession<string>) => Promise<void>
219
+ }
220
+ interface GatewayConstructOptions {
221
+ id: string
222
+ appid?: string
223
+ domain?: string
224
+ keepalive?: boolean
225
+ prefetch?: boolean
226
+ prefetchOptions?: {
227
+ concurrent?: number
228
+ enableQuic?: boolean
229
+ enableHttp2?: boolean
230
+ }
231
+ }
232
+ interface CloudServices {
233
+ Gateway: (opts: GatewayConstructOptions) => GatewayInstance
234
+ }
235
+ // === end ===
236
+
237
+ // === API: uploadFile ===
238
+ interface UploadFileResult extends IAPISuccessParam {
239
+ fileID: string
240
+ statusCode: number
241
+ }
242
+
243
+ interface UploadFileParam extends ICloudAPIParam<UploadFileResult> {
244
+ cloudPath: string
245
+ filePath: string
246
+ header?: AnyObject
247
+ }
248
+ // === end ===
249
+
250
+ // === API: downloadFile ===
251
+ interface DownloadFileResult extends IAPISuccessParam {
252
+ tempFilePath: string
253
+ statusCode: number
254
+ }
255
+
256
+ interface DownloadFileParam extends ICloudAPIParam<DownloadFileResult> {
257
+ fileID: string
258
+ cloudPath?: string
259
+ }
260
+ // === end ===
261
+
262
+ // === API: getTempFileURL ===
263
+ interface GetTempFileURLResult extends IAPISuccessParam {
264
+ fileList: GetTempFileURLResultItem[]
265
+ }
266
+
267
+ interface GetTempFileURLResultItem {
268
+ fileID: string
269
+ tempFileURL: string
270
+ maxAge: number
271
+ status: number
272
+ errMsg: string
273
+ }
274
+
275
+ interface GetTempFileURLParam extends ICloudAPIParam<GetTempFileURLResult> {
276
+ fileList: string[]
277
+ }
278
+ // === end ===
279
+
280
+ // === API: deleteFile ===
281
+ interface DeleteFileResult extends IAPISuccessParam {
282
+ fileList: DeleteFileResultItem[]
283
+ }
284
+
285
+ interface DeleteFileResultItem {
286
+ fileID: string
287
+ status: number
288
+ errMsg: string
289
+ }
290
+
291
+ interface DeleteFileParam extends ICloudAPIParam<DeleteFileResult> {
292
+ fileList: string[]
293
+ }
294
+ // === end ===
295
+
296
+ // === API: CloudID ===
297
+ abstract class CloudID {
298
+ constructor(cloudID: string)
299
+ }
300
+
301
+ interface ICloudIDConstructor {
302
+ new (cloudId: string): CloudID
303
+ (cloudId: string): CloudID
304
+ }
305
+ // === end ===
306
+
307
+ // === API: CDN ===
308
+ abstract class CDN {
309
+ target: string | ArrayBuffer | ICDNFilePathSpec
310
+ constructor(target: string | ArrayBuffer | ICDNFilePathSpec)
311
+ }
312
+
313
+ interface ICDNFilePathSpec {
314
+ type: 'filePath'
315
+ filePath: string
316
+ }
317
+
318
+ interface ICDNConstructor {
319
+ new (options: string | ArrayBuffer | ICDNFilePathSpec): CDN
320
+ (options: string | ArrayBuffer | ICDNFilePathSpec): CDN
321
+ }
322
+ // === end ===
323
+ }
324
+
325
+ // === Database ===
326
+ declare namespace DB {
327
+ /**
328
+ * The class of all exposed cloud database instances
329
+ */
330
+ class Database {
331
+ readonly config: ICloudConfig
332
+ readonly command: DatabaseCommand
333
+ readonly Geo: IGeo
334
+ readonly serverDate: () => ServerDate
335
+ readonly RegExp: IRegExpConstructor
336
+
337
+ private constructor()
338
+
339
+ collection(collectionName: string): CollectionReference
340
+ }
341
+
342
+ class CollectionReference extends Query {
343
+ readonly collectionName: string
344
+
345
+ private constructor(name: string, database: Database)
346
+
347
+ doc(docId: string | number): DocumentReference
348
+
349
+ add(options: OQ<IAddDocumentOptions>): void
350
+ add(options: RQ<IAddDocumentOptions>): Promise<IAddResult>
351
+ }
352
+
353
+ class DocumentReference {
354
+ private constructor(docId: string | number, database: Database)
355
+
356
+ field(object: Record<string, any>): this
357
+
358
+ get(options: OQ<IGetDocumentOptions>): void
359
+ get(options?: RQ<IGetDocumentOptions>): Promise<IQuerySingleResult>
360
+
361
+ set(options: OQ<ISetSingleDocumentOptions>): void
362
+ set(options?: RQ<ISetSingleDocumentOptions>): Promise<ISetResult>
363
+
364
+ update(options: OQ<IUpdateSingleDocumentOptions>): void
365
+ update(
366
+ options?: RQ<IUpdateSingleDocumentOptions>
367
+ ): Promise<IUpdateResult>
368
+
369
+ remove(options: OQ<IRemoveSingleDocumentOptions>): void
370
+ remove(
371
+ options?: RQ<IRemoveSingleDocumentOptions>
372
+ ): Promise<IRemoveResult>
373
+
374
+ watch(options: IWatchOptions): RealtimeListener
375
+ }
376
+
377
+ class RealtimeListener {
378
+ // "And Now His Watch Is Ended"
379
+ close: () => Promise<void>
380
+ }
381
+
382
+ class Query {
383
+ where(condition: IQueryCondition): Query
384
+
385
+ orderBy(fieldPath: string, order: string): Query
386
+
387
+ limit(max: number): Query
388
+
389
+ skip(offset: number): Query
390
+
391
+ field(object: Record<string, any>): Query
392
+
393
+ get(options: OQ<IGetDocumentOptions>): void
394
+ get(options?: RQ<IGetDocumentOptions>): Promise<IQueryResult>
395
+
396
+ count(options: OQ<ICountDocumentOptions>): void
397
+ count(options?: RQ<ICountDocumentOptions>): Promise<ICountResult>
398
+
399
+ watch(options: IWatchOptions): RealtimeListener
400
+ }
401
+
402
+ interface DatabaseCommand {
403
+ eq(val: any): DatabaseQueryCommand
404
+ neq(val: any): DatabaseQueryCommand
405
+ gt(val: any): DatabaseQueryCommand
406
+ gte(val: any): DatabaseQueryCommand
407
+ lt(val: any): DatabaseQueryCommand
408
+ lte(val: any): DatabaseQueryCommand
409
+ in(val: any[]): DatabaseQueryCommand
410
+ nin(val: any[]): DatabaseQueryCommand
411
+
412
+ geoNear(options: IGeoNearCommandOptions): DatabaseQueryCommand
413
+ geoWithin(options: IGeoWithinCommandOptions): DatabaseQueryCommand
414
+ geoIntersects(
415
+ options: IGeoIntersectsCommandOptions
416
+ ): DatabaseQueryCommand
417
+
418
+ and(
419
+ ...expressions: Array<DatabaseLogicCommand | IQueryCondition>
420
+ ): DatabaseLogicCommand
421
+ or(
422
+ ...expressions: Array<DatabaseLogicCommand | IQueryCondition>
423
+ ): DatabaseLogicCommand
424
+ nor(
425
+ ...expressions: Array<DatabaseLogicCommand | IQueryCondition>
426
+ ): DatabaseLogicCommand
427
+ not(expression: DatabaseLogicCommand): DatabaseLogicCommand
428
+
429
+ exists(val: boolean): DatabaseQueryCommand
430
+
431
+ mod(divisor: number, remainder: number): DatabaseQueryCommand
432
+
433
+ all(val: any[]): DatabaseQueryCommand
434
+ elemMatch(val: any): DatabaseQueryCommand
435
+ size(val: number): DatabaseQueryCommand
436
+
437
+ set(val: any): DatabaseUpdateCommand
438
+ remove(): DatabaseUpdateCommand
439
+ inc(val: number): DatabaseUpdateCommand
440
+ mul(val: number): DatabaseUpdateCommand
441
+ min(val: number): DatabaseUpdateCommand
442
+ max(val: number): DatabaseUpdateCommand
443
+ rename(val: string): DatabaseUpdateCommand
444
+ bit(val: number): DatabaseUpdateCommand
445
+
446
+ push(...values: any[]): DatabaseUpdateCommand
447
+ pop(): DatabaseUpdateCommand
448
+ shift(): DatabaseUpdateCommand
449
+ unshift(...values: any[]): DatabaseUpdateCommand
450
+ addToSet(val: any): DatabaseUpdateCommand
451
+ pull(val: any): DatabaseUpdateCommand
452
+ pullAll(val: any): DatabaseUpdateCommand
453
+
454
+ project: {
455
+ slice(val: number | [number, number]): DatabaseProjectionCommand
456
+ }
457
+
458
+ aggregate: {
459
+ __safe_props__?: Set<string>
460
+
461
+ abs(val: any): DatabaseAggregateCommand
462
+ add(val: any): DatabaseAggregateCommand
463
+ addToSet(val: any): DatabaseAggregateCommand
464
+ allElementsTrue(val: any): DatabaseAggregateCommand
465
+ and(val: any): DatabaseAggregateCommand
466
+ anyElementTrue(val: any): DatabaseAggregateCommand
467
+ arrayElemAt(val: any): DatabaseAggregateCommand
468
+ arrayToObject(val: any): DatabaseAggregateCommand
469
+ avg(val: any): DatabaseAggregateCommand
470
+ ceil(val: any): DatabaseAggregateCommand
471
+ cmp(val: any): DatabaseAggregateCommand
472
+ concat(val: any): DatabaseAggregateCommand
473
+ concatArrays(val: any): DatabaseAggregateCommand
474
+ cond(val: any): DatabaseAggregateCommand
475
+ convert(val: any): DatabaseAggregateCommand
476
+ dateFromParts(val: any): DatabaseAggregateCommand
477
+ dateToParts(val: any): DatabaseAggregateCommand
478
+ dateFromString(val: any): DatabaseAggregateCommand
479
+ dateToString(val: any): DatabaseAggregateCommand
480
+ dayOfMonth(val: any): DatabaseAggregateCommand
481
+ dayOfWeek(val: any): DatabaseAggregateCommand
482
+ dayOfYear(val: any): DatabaseAggregateCommand
483
+ divide(val: any): DatabaseAggregateCommand
484
+ eq(val: any): DatabaseAggregateCommand
485
+ exp(val: any): DatabaseAggregateCommand
486
+ filter(val: any): DatabaseAggregateCommand
487
+ first(val: any): DatabaseAggregateCommand
488
+ floor(val: any): DatabaseAggregateCommand
489
+ gt(val: any): DatabaseAggregateCommand
490
+ gte(val: any): DatabaseAggregateCommand
491
+ hour(val: any): DatabaseAggregateCommand
492
+ ifNull(val: any): DatabaseAggregateCommand
493
+ in(val: any): DatabaseAggregateCommand
494
+ indexOfArray(val: any): DatabaseAggregateCommand
495
+ indexOfBytes(val: any): DatabaseAggregateCommand
496
+ indexOfCP(val: any): DatabaseAggregateCommand
497
+ isArray(val: any): DatabaseAggregateCommand
498
+ isoDayOfWeek(val: any): DatabaseAggregateCommand
499
+ isoWeek(val: any): DatabaseAggregateCommand
500
+ isoWeekYear(val: any): DatabaseAggregateCommand
501
+ last(val: any): DatabaseAggregateCommand
502
+ let(val: any): DatabaseAggregateCommand
503
+ literal(val: any): DatabaseAggregateCommand
504
+ ln(val: any): DatabaseAggregateCommand
505
+ log(val: any): DatabaseAggregateCommand
506
+ log10(val: any): DatabaseAggregateCommand
507
+ lt(val: any): DatabaseAggregateCommand
508
+ lte(val: any): DatabaseAggregateCommand
509
+ ltrim(val: any): DatabaseAggregateCommand
510
+ map(val: any): DatabaseAggregateCommand
511
+ max(val: any): DatabaseAggregateCommand
512
+ mergeObjects(val: any): DatabaseAggregateCommand
513
+ meta(val: any): DatabaseAggregateCommand
514
+ min(val: any): DatabaseAggregateCommand
515
+ millisecond(val: any): DatabaseAggregateCommand
516
+ minute(val: any): DatabaseAggregateCommand
517
+ mod(val: any): DatabaseAggregateCommand
518
+ month(val: any): DatabaseAggregateCommand
519
+ multiply(val: any): DatabaseAggregateCommand
520
+ neq(val: any): DatabaseAggregateCommand
521
+ not(val: any): DatabaseAggregateCommand
522
+ objectToArray(val: any): DatabaseAggregateCommand
523
+ or(val: any): DatabaseAggregateCommand
524
+ pow(val: any): DatabaseAggregateCommand
525
+ push(val: any): DatabaseAggregateCommand
526
+ range(val: any): DatabaseAggregateCommand
527
+ reduce(val: any): DatabaseAggregateCommand
528
+ reverseArray(val: any): DatabaseAggregateCommand
529
+ rtrim(val: any): DatabaseAggregateCommand
530
+ second(val: any): DatabaseAggregateCommand
531
+ setDifference(val: any): DatabaseAggregateCommand
532
+ setEquals(val: any): DatabaseAggregateCommand
533
+ setIntersection(val: any): DatabaseAggregateCommand
534
+ setIsSubset(val: any): DatabaseAggregateCommand
535
+ setUnion(val: any): DatabaseAggregateCommand
536
+ size(val: any): DatabaseAggregateCommand
537
+ slice(val: any): DatabaseAggregateCommand
538
+ split(val: any): DatabaseAggregateCommand
539
+ sqrt(val: any): DatabaseAggregateCommand
540
+ stdDevPop(val: any): DatabaseAggregateCommand
541
+ stdDevSamp(val: any): DatabaseAggregateCommand
542
+ strcasecmp(val: any): DatabaseAggregateCommand
543
+ strLenBytes(val: any): DatabaseAggregateCommand
544
+ strLenCP(val: any): DatabaseAggregateCommand
545
+ substr(val: any): DatabaseAggregateCommand
546
+ substrBytes(val: any): DatabaseAggregateCommand
547
+ substrCP(val: any): DatabaseAggregateCommand
548
+ subtract(val: any): DatabaseAggregateCommand
549
+ sum(val: any): DatabaseAggregateCommand
550
+ switch(val: any): DatabaseAggregateCommand
551
+ toBool(val: any): DatabaseAggregateCommand
552
+ toDate(val: any): DatabaseAggregateCommand
553
+ toDecimal(val: any): DatabaseAggregateCommand
554
+ toDouble(val: any): DatabaseAggregateCommand
555
+ toInt(val: any): DatabaseAggregateCommand
556
+ toLong(val: any): DatabaseAggregateCommand
557
+ toObjectId(val: any): DatabaseAggregateCommand
558
+ toString(val: any): DatabaseAggregateCommand
559
+ toLower(val: any): DatabaseAggregateCommand
560
+ toUpper(val: any): DatabaseAggregateCommand
561
+ trim(val: any): DatabaseAggregateCommand
562
+ trunc(val: any): DatabaseAggregateCommand
563
+ type(val: any): DatabaseAggregateCommand
564
+ week(val: any): DatabaseAggregateCommand
565
+ year(val: any): DatabaseAggregateCommand
566
+ zip(val: any): DatabaseAggregateCommand
567
+ }
568
+ }
569
+
570
+ class DatabaseAggregateCommand {}
571
+
572
+ enum LOGIC_COMMANDS_LITERAL {
573
+ AND = 'and',
574
+ OR = 'or',
575
+ NOT = 'not',
576
+ NOR = 'nor'
577
+ }
578
+
579
+ class DatabaseLogicCommand {
580
+ and(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
581
+ or(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
582
+ nor(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
583
+ not(expression: DatabaseLogicCommand): DatabaseLogicCommand
584
+ }
585
+
586
+ enum QUERY_COMMANDS_LITERAL {
587
+ // comparison
588
+ EQ = 'eq',
589
+ NEQ = 'neq',
590
+ GT = 'gt',
591
+ GTE = 'gte',
592
+ LT = 'lt',
593
+ LTE = 'lte',
594
+ IN = 'in',
595
+ NIN = 'nin',
596
+ // geo
597
+ GEO_NEAR = 'geoNear',
598
+ GEO_WITHIN = 'geoWithin',
599
+ GEO_INTERSECTS = 'geoIntersects',
600
+ // element
601
+ EXISTS = 'exists',
602
+ // evaluation
603
+ MOD = 'mod',
604
+ // array
605
+ ALL = 'all',
606
+ ELEM_MATCH = 'elemMatch',
607
+ SIZE = 'size'
608
+ }
609
+
610
+ class DatabaseQueryCommand extends DatabaseLogicCommand {
611
+ eq(val: any): DatabaseLogicCommand
612
+ neq(val: any): DatabaseLogicCommand
613
+ gt(val: any): DatabaseLogicCommand
614
+ gte(val: any): DatabaseLogicCommand
615
+ lt(val: any): DatabaseLogicCommand
616
+ lte(val: any): DatabaseLogicCommand
617
+ in(val: any[]): DatabaseLogicCommand
618
+ nin(val: any[]): DatabaseLogicCommand
619
+
620
+ exists(val: boolean): DatabaseLogicCommand
621
+
622
+ mod(divisor: number, remainder: number): DatabaseLogicCommand
623
+
624
+ all(val: any[]): DatabaseLogicCommand
625
+ elemMatch(val: any): DatabaseLogicCommand
626
+ size(val: number): DatabaseLogicCommand
627
+
628
+ geoNear(options: IGeoNearCommandOptions): DatabaseLogicCommand
629
+ geoWithin(options: IGeoWithinCommandOptions): DatabaseLogicCommand
630
+ geoIntersects(
631
+ options: IGeoIntersectsCommandOptions
632
+ ): DatabaseLogicCommand
633
+ }
634
+
635
+ enum PROJECTION_COMMANDS_LITERAL {
636
+ SLICE = 'slice'
637
+ }
638
+
639
+ class DatabaseProjectionCommand {}
640
+
641
+ enum UPDATE_COMMANDS_LITERAL {
642
+ // field
643
+ SET = 'set',
644
+ REMOVE = 'remove',
645
+ INC = 'inc',
646
+ MUL = 'mul',
647
+ MIN = 'min',
648
+ MAX = 'max',
649
+ RENAME = 'rename',
650
+ // bitwise
651
+ BIT = 'bit',
652
+ // array
653
+ PUSH = 'push',
654
+ POP = 'pop',
655
+ SHIFT = 'shift',
656
+ UNSHIFT = 'unshift',
657
+ ADD_TO_SET = 'addToSet',
658
+ PULL = 'pull',
659
+ PULL_ALL = 'pullAll'
660
+ }
661
+
662
+ class DatabaseUpdateCommand {}
663
+
664
+ class Batch {}
665
+
666
+ /**
667
+ * A contract that all API provider must adhere to
668
+ */
669
+ class APIBaseContract<
670
+ PromiseReturn,
671
+ CallbackReturn,
672
+ Param extends IAPIParam,
673
+ Context = any
674
+ > {
675
+ getContext(param: Param): Context
676
+
677
+ /**
678
+ * In case of callback-style invocation, this function will be called
679
+ */
680
+ getCallbackReturn(param: Param, context: Context): CallbackReturn
681
+
682
+ getFinalParam<T extends Param>(param: Param, context: Context): T
683
+
684
+ run<T extends Param>(param: T): Promise<PromiseReturn>
685
+ }
686
+
687
+ interface IGeoPointConstructor {
688
+ new (longitude: number, latitide: number): GeoPoint
689
+ new (geojson: IGeoJSONPoint): GeoPoint
690
+ (longitude: number, latitide: number): GeoPoint
691
+ (geojson: IGeoJSONPoint): GeoPoint
692
+ }
693
+
694
+ interface IGeoMultiPointConstructor {
695
+ new (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint
696
+ (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint
697
+ }
698
+
699
+ interface IGeoLineStringConstructor {
700
+ new (points: GeoPoint[] | IGeoJSONLineString): GeoLineString
701
+ (points: GeoPoint[] | IGeoJSONLineString): GeoLineString
702
+ }
703
+
704
+ interface IGeoMultiLineStringConstructor {
705
+ new (
706
+ lineStrings: GeoLineString[] | IGeoJSONMultiLineString
707
+ ): GeoMultiLineString
708
+ (
709
+ lineStrings: GeoLineString[] | IGeoJSONMultiLineString
710
+ ): GeoMultiLineString
711
+ }
712
+
713
+ interface IGeoPolygonConstructor {
714
+ new (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon
715
+ (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon
716
+ }
717
+
718
+ interface IGeoMultiPolygonConstructor {
719
+ new (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon
720
+ (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon
721
+ }
722
+
723
+ interface IGeo {
724
+ Point: IGeoPointConstructor
725
+ MultiPoint: IGeoMultiPointConstructor
726
+ LineString: IGeoLineStringConstructor
727
+ MultiLineString: IGeoMultiLineStringConstructor
728
+ Polygon: IGeoPolygonConstructor
729
+ MultiPolygon: IGeoMultiPolygonConstructor
730
+ }
731
+
732
+ interface IGeoJSONPoint {
733
+ type: 'Point'
734
+ coordinates: [number, number]
735
+ }
736
+
737
+ interface IGeoJSONMultiPoint {
738
+ type: 'MultiPoint'
739
+ coordinates: Array<[number, number]>
740
+ }
741
+
742
+ interface IGeoJSONLineString {
743
+ type: 'LineString'
744
+ coordinates: Array<[number, number]>
745
+ }
746
+
747
+ interface IGeoJSONMultiLineString {
748
+ type: 'MultiLineString'
749
+ coordinates: Array<Array<[number, number]>>
750
+ }
751
+
752
+ interface IGeoJSONPolygon {
753
+ type: 'Polygon'
754
+ coordinates: Array<Array<[number, number]>>
755
+ }
756
+
757
+ interface IGeoJSONMultiPolygon {
758
+ type: 'MultiPolygon'
759
+ coordinates: Array<Array<Array<[number, number]>>>
760
+ }
761
+
762
+ type IGeoJSONObject =
763
+ | IGeoJSONPoint
764
+ | IGeoJSONMultiPoint
765
+ | IGeoJSONLineString
766
+ | IGeoJSONMultiLineString
767
+ | IGeoJSONPolygon
768
+ | IGeoJSONMultiPolygon
769
+
770
+ abstract class GeoPoint {
771
+ longitude: number
772
+ latitude: number
773
+
774
+ constructor(longitude: number, latitude: number)
775
+
776
+ toJSON(): Record<string, any>
777
+ toString(): string
778
+ }
779
+
780
+ abstract class GeoMultiPoint {
781
+ points: GeoPoint[]
782
+
783
+ constructor(points: GeoPoint[])
784
+
785
+ toJSON(): IGeoJSONMultiPoint
786
+ toString(): string
787
+ }
788
+
789
+ abstract class GeoLineString {
790
+ points: GeoPoint[]
791
+
792
+ constructor(points: GeoPoint[])
793
+
794
+ toJSON(): IGeoJSONLineString
795
+ toString(): string
796
+ }
797
+
798
+ abstract class GeoMultiLineString {
799
+ lines: GeoLineString[]
800
+
801
+ constructor(lines: GeoLineString[])
802
+
803
+ toJSON(): IGeoJSONMultiLineString
804
+ toString(): string
805
+ }
806
+
807
+ abstract class GeoPolygon {
808
+ lines: GeoLineString[]
809
+
810
+ constructor(lines: GeoLineString[])
811
+
812
+ toJSON(): IGeoJSONPolygon
813
+ toString(): string
814
+ }
815
+
816
+ abstract class GeoMultiPolygon {
817
+ polygons: GeoPolygon[]
818
+
819
+ constructor(polygons: GeoPolygon[])
820
+
821
+ toJSON(): IGeoJSONMultiPolygon
822
+ toString(): string
823
+ }
824
+
825
+ type GeoInstance =
826
+ | GeoPoint
827
+ | GeoMultiPoint
828
+ | GeoLineString
829
+ | GeoMultiLineString
830
+ | GeoPolygon
831
+ | GeoMultiPolygon
832
+
833
+ interface IGeoNearCommandOptions {
834
+ geometry: GeoPoint
835
+ maxDistance?: number
836
+ minDistance?: number
837
+ }
838
+
839
+ interface IGeoWithinCommandOptions {
840
+ geometry: GeoPolygon | GeoMultiPolygon
841
+ }
842
+
843
+ interface IGeoIntersectsCommandOptions {
844
+ geometry:
845
+ | GeoPoint
846
+ | GeoMultiPoint
847
+ | GeoLineString
848
+ | GeoMultiLineString
849
+ | GeoPolygon
850
+ | GeoMultiPolygon
851
+ }
852
+
853
+ interface IServerDateOptions {
854
+ offset: number
855
+ }
856
+
857
+ abstract class ServerDate {
858
+ readonly options: IServerDateOptions
859
+ constructor(options?: IServerDateOptions)
860
+ }
861
+
862
+ interface IRegExpOptions {
863
+ regexp: string
864
+ options?: string
865
+ }
866
+
867
+ interface IRegExpConstructor {
868
+ new (options: IRegExpOptions): RegExp
869
+ (options: IRegExpOptions): RegExp
870
+ }
871
+
872
+ abstract class RegExp {
873
+ readonly regexp: string
874
+ readonly options: string
875
+ constructor(options: IRegExpOptions)
876
+ }
877
+
878
+ type DocumentId = string | number
879
+
880
+ interface IDocumentData {
881
+ _id?: DocumentId
882
+ [key: string]: any
883
+ }
884
+
885
+ type IDBAPIParam = IAPIParam
886
+
887
+ interface IAddDocumentOptions extends IDBAPIParam {
888
+ data: IDocumentData
889
+ }
890
+
891
+ type IGetDocumentOptions = IDBAPIParam
892
+
893
+ type ICountDocumentOptions = IDBAPIParam
894
+
895
+ interface IUpdateDocumentOptions extends IDBAPIParam {
896
+ data: IUpdateCondition
897
+ }
898
+
899
+ interface IUpdateSingleDocumentOptions extends IDBAPIParam {
900
+ data: IUpdateCondition
901
+ }
902
+
903
+ interface ISetDocumentOptions extends IDBAPIParam {
904
+ data: IUpdateCondition
905
+ }
906
+
907
+ interface ISetSingleDocumentOptions extends IDBAPIParam {
908
+ data: IUpdateCondition
909
+ }
910
+
911
+ interface IRemoveDocumentOptions extends IDBAPIParam {
912
+ query: IQueryCondition
913
+ }
914
+
915
+ type IRemoveSingleDocumentOptions = IDBAPIParam
916
+
917
+ interface IWatchOptions {
918
+ // server realtime data init & change event
919
+ onChange: (snapshot: ISnapshot) => void
920
+ // error while connecting / listening
921
+ onError: (error: any) => void
922
+ }
923
+
924
+ interface ISnapshot {
925
+ id: number
926
+ docChanges: ISingleDBEvent[]
927
+ docs: Record<string, any>
928
+ type?: SnapshotType
929
+ }
930
+
931
+ type SnapshotType = 'init'
932
+
933
+ interface ISingleDBEvent {
934
+ id: number
935
+ dataType: DataType
936
+ queueType: QueueType
937
+ docId: string
938
+ doc: Record<string, any>
939
+ updatedFields?: Record<string, any>
940
+ removedFields?: string[]
941
+ }
942
+
943
+ type DataType = 'init' | 'update' | 'replace' | 'add' | 'remove' | 'limit'
944
+
945
+ type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update'
946
+
947
+ interface IQueryCondition {
948
+ [key: string]: any
949
+ }
950
+
951
+ type IStringQueryCondition = string
952
+
953
+ interface IQueryResult extends IAPISuccessParam {
954
+ data: IDocumentData[]
955
+ }
956
+
957
+ interface IQuerySingleResult extends IAPISuccessParam {
958
+ data: IDocumentData
959
+ }
960
+
961
+ interface IUpdateCondition {
962
+ [key: string]: any
963
+ }
964
+
965
+ type IStringUpdateCondition = string
966
+
967
+ interface IAddResult extends IAPISuccessParam {
968
+ _id: DocumentId
969
+ }
970
+
971
+ interface IUpdateResult extends IAPISuccessParam {
972
+ stats: {
973
+ updated: number
974
+ // created: number,
975
+ }
976
+ }
977
+
978
+ interface ISetResult extends IAPISuccessParam {
979
+ _id: DocumentId
980
+ stats: {
981
+ updated: number
982
+ created: number
983
+ }
984
+ }
985
+
986
+ interface IRemoveResult extends IAPISuccessParam {
987
+ stats: {
988
+ removed: number
989
+ }
990
+ }
991
+
992
+ interface ICountResult extends IAPISuccessParam {
993
+ total: number
994
+ }
995
+ }
996
+
997
+ type Optional<T> = { [K in keyof T]+?: T[K] }
998
+
999
+ type OQ<
1000
+ T extends Optional<
1001
+ Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
1002
+ >
1003
+ > =
1004
+ | (RQ<T> & Required<Pick<T, 'success'>>)
1005
+ | (RQ<T> & Required<Pick<T, 'fail'>>)
1006
+ | (RQ<T> & Required<Pick<T, 'complete'>>)
1007
+ | (RQ<T> & Required<Pick<T, 'success' | 'fail'>>)
1008
+ | (RQ<T> & Required<Pick<T, 'success' | 'complete'>>)
1009
+ | (RQ<T> & Required<Pick<T, 'fail' | 'complete'>>)
1010
+ | (RQ<T> & Required<Pick<T, 'fail' | 'complete' | 'success'>>)
1011
+
1012
+ type RQ<
1013
+ T extends Optional<
1014
+ Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
1015
+ >
1016
+ > = Pick<T, Exclude<keyof T, 'complete' | 'success' | 'fail'>>