lib.wx.cloud.d.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. /*! *****************************************************************************
  2. Copyright (c) 2021 Tencent, Inc. All rights reserved.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. this software and associated documentation files (the "Software"), to deal in
  5. the Software without restriction, including without limitation the rights to
  6. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  7. of the Software, and to permit persons to whom the Software is furnished to do
  8. so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.
  18. ***************************************************************************** */
  19. interface IAPIError {
  20. errMsg: string
  21. }
  22. interface IAPIParam<T = any> {
  23. config?: ICloudConfig
  24. success?: (res: T) => void
  25. fail?: (err: IAPIError) => void
  26. complete?: (val: T | IAPIError) => void
  27. }
  28. interface IAPISuccessParam {
  29. errMsg: string
  30. }
  31. type IAPICompleteParam = IAPISuccessParam | IAPIError
  32. type IAPIFunction<T, P extends IAPIParam<T>> = (param?: P) => Promise<T>
  33. interface IInitCloudConfig {
  34. env?:
  35. | string
  36. | {
  37. database?: string
  38. functions?: string
  39. storage?: string
  40. }
  41. traceUser?: boolean
  42. }
  43. interface ICloudConfig {
  44. env?: string
  45. traceUser?: boolean
  46. }
  47. interface IICloudAPI {
  48. init: (config?: IInitCloudConfig) => void
  49. [api: string]: AnyFunction | IAPIFunction<any, any>
  50. }
  51. interface ICloudService {
  52. name: string
  53. getAPIs: () => { [name: string]: IAPIFunction<any, any> }
  54. }
  55. interface ICloudServices {
  56. [serviceName: string]: ICloudService
  57. }
  58. interface ICloudMetaData {
  59. session_id: string
  60. }
  61. declare class InternalSymbol {}
  62. interface AnyObject {
  63. [x: string]: any
  64. }
  65. type AnyArray = any[]
  66. type AnyFunction = (...args: any[]) => any
  67. /**
  68. * extend wx with cloud
  69. */
  70. interface WxCloud {
  71. init: (config?: ICloudConfig) => void
  72. callFunction(param: OQ<ICloud.CallFunctionParam>): void
  73. callFunction(
  74. param: RQ<ICloud.CallFunctionParam>
  75. ): Promise<ICloud.CallFunctionResult>
  76. uploadFile(param: OQ<ICloud.UploadFileParam>): WechatMiniprogram.UploadTask
  77. uploadFile(
  78. param: RQ<ICloud.UploadFileParam>
  79. ): Promise<ICloud.UploadFileResult>
  80. downloadFile(
  81. param: OQ<ICloud.DownloadFileParam>
  82. ): WechatMiniprogram.DownloadTask
  83. downloadFile(
  84. param: RQ<ICloud.DownloadFileParam>
  85. ): Promise<ICloud.DownloadFileResult>
  86. getTempFileURL(param: OQ<ICloud.GetTempFileURLParam>): void
  87. getTempFileURL(
  88. param: RQ<ICloud.GetTempFileURLParam>
  89. ): Promise<ICloud.GetTempFileURLResult>
  90. deleteFile(param: OQ<ICloud.DeleteFileParam>): void
  91. deleteFile(
  92. param: RQ<ICloud.DeleteFileParam>
  93. ): Promise<ICloud.DeleteFileResult>
  94. database: (config?: ICloudConfig) => DB.Database
  95. CloudID: ICloud.ICloudIDConstructor
  96. CDN: ICloud.ICDNConstructor
  97. }
  98. declare namespace ICloud {
  99. interface ICloudAPIParam<T = any> extends IAPIParam<T> {
  100. config?: ICloudConfig
  101. }
  102. // === API: callFunction ===
  103. type CallFunctionData = AnyObject
  104. interface CallFunctionResult extends IAPISuccessParam {
  105. result: AnyObject | string | undefined
  106. }
  107. interface CallFunctionParam extends ICloudAPIParam<CallFunctionResult> {
  108. name: string
  109. data?: CallFunctionData
  110. slow?: boolean
  111. }
  112. // === end ===
  113. // === API: uploadFile ===
  114. interface UploadFileResult extends IAPISuccessParam {
  115. fileID: string
  116. statusCode: number
  117. }
  118. interface UploadFileParam extends ICloudAPIParam<UploadFileResult> {
  119. cloudPath: string
  120. filePath: string
  121. header?: AnyObject
  122. }
  123. // === end ===
  124. // === API: downloadFile ===
  125. interface DownloadFileResult extends IAPISuccessParam {
  126. tempFilePath: string
  127. statusCode: number
  128. }
  129. interface DownloadFileParam extends ICloudAPIParam<DownloadFileResult> {
  130. fileID: string
  131. cloudPath?: string
  132. }
  133. // === end ===
  134. // === API: getTempFileURL ===
  135. interface GetTempFileURLResult extends IAPISuccessParam {
  136. fileList: GetTempFileURLResultItem[]
  137. }
  138. interface GetTempFileURLResultItem {
  139. fileID: string
  140. tempFileURL: string
  141. maxAge: number
  142. status: number
  143. errMsg: string
  144. }
  145. interface GetTempFileURLParam extends ICloudAPIParam<GetTempFileURLResult> {
  146. fileList: string[]
  147. }
  148. // === end ===
  149. // === API: deleteFile ===
  150. interface DeleteFileResult extends IAPISuccessParam {
  151. fileList: DeleteFileResultItem[]
  152. }
  153. interface DeleteFileResultItem {
  154. fileID: string
  155. status: number
  156. errMsg: string
  157. }
  158. interface DeleteFileParam extends ICloudAPIParam<DeleteFileResult> {
  159. fileList: string[]
  160. }
  161. // === end ===
  162. // === API: CloudID ===
  163. abstract class CloudID {
  164. constructor(cloudID: string)
  165. }
  166. interface ICloudIDConstructor {
  167. new (cloudId: string): CloudID
  168. (cloudId: string): CloudID
  169. }
  170. // === end ===
  171. // === API: CDN ===
  172. abstract class CDN {
  173. target: string | ArrayBuffer | ICDNFilePathSpec
  174. constructor(target: string | ArrayBuffer | ICDNFilePathSpec)
  175. }
  176. interface ICDNFilePathSpec {
  177. type: 'filePath'
  178. filePath: string
  179. }
  180. interface ICDNConstructor {
  181. new (options: string | ArrayBuffer | ICDNFilePathSpec): CDN
  182. (options: string | ArrayBuffer | ICDNFilePathSpec): CDN
  183. }
  184. // === end ===
  185. }
  186. // === Database ===
  187. declare namespace DB {
  188. /**
  189. * The class of all exposed cloud database instances
  190. */
  191. class Database {
  192. readonly config: ICloudConfig
  193. readonly command: DatabaseCommand
  194. readonly Geo: IGeo
  195. readonly serverDate: () => ServerDate
  196. readonly RegExp: IRegExpConstructor
  197. private constructor()
  198. collection(collectionName: string): CollectionReference
  199. }
  200. class CollectionReference extends Query {
  201. readonly collectionName: string
  202. private constructor(name: string, database: Database)
  203. doc(docId: string | number): DocumentReference
  204. add(options: OQ<IAddDocumentOptions>): void
  205. add(options: RQ<IAddDocumentOptions>): Promise<IAddResult>
  206. }
  207. class DocumentReference {
  208. private constructor(docId: string | number, database: Database)
  209. field(object: Record<string, any>): this
  210. get(options: OQ<IGetDocumentOptions>): void
  211. get(options?: RQ<IGetDocumentOptions>): Promise<IQuerySingleResult>
  212. set(options: OQ<ISetSingleDocumentOptions>): void
  213. set(options?: RQ<ISetSingleDocumentOptions>): Promise<ISetResult>
  214. update(options: OQ<IUpdateSingleDocumentOptions>): void
  215. update(
  216. options?: RQ<IUpdateSingleDocumentOptions>
  217. ): Promise<IUpdateResult>
  218. remove(options: OQ<IRemoveSingleDocumentOptions>): void
  219. remove(
  220. options?: RQ<IRemoveSingleDocumentOptions>
  221. ): Promise<IRemoveResult>
  222. watch(options: IWatchOptions): RealtimeListener
  223. }
  224. class RealtimeListener {
  225. // "And Now His Watch Is Ended"
  226. close: () => Promise<void>
  227. }
  228. class Query {
  229. where(condition: IQueryCondition): Query
  230. orderBy(fieldPath: string, order: string): Query
  231. limit(max: number): Query
  232. skip(offset: number): Query
  233. field(object: Record<string, any>): Query
  234. get(options: OQ<IGetDocumentOptions>): void
  235. get(options?: RQ<IGetDocumentOptions>): Promise<IQueryResult>
  236. count(options: OQ<ICountDocumentOptions>): void
  237. count(options?: RQ<ICountDocumentOptions>): Promise<ICountResult>
  238. watch(options: IWatchOptions): RealtimeListener
  239. }
  240. interface DatabaseCommand {
  241. eq(val: any): DatabaseQueryCommand
  242. neq(val: any): DatabaseQueryCommand
  243. gt(val: any): DatabaseQueryCommand
  244. gte(val: any): DatabaseQueryCommand
  245. lt(val: any): DatabaseQueryCommand
  246. lte(val: any): DatabaseQueryCommand
  247. in(val: any[]): DatabaseQueryCommand
  248. nin(val: any[]): DatabaseQueryCommand
  249. geoNear(options: IGeoNearCommandOptions): DatabaseQueryCommand
  250. geoWithin(options: IGeoWithinCommandOptions): DatabaseQueryCommand
  251. geoIntersects(
  252. options: IGeoIntersectsCommandOptions
  253. ): DatabaseQueryCommand
  254. and(
  255. ...expressions: Array<DatabaseLogicCommand | IQueryCondition>
  256. ): DatabaseLogicCommand
  257. or(
  258. ...expressions: Array<DatabaseLogicCommand | IQueryCondition>
  259. ): DatabaseLogicCommand
  260. nor(
  261. ...expressions: Array<DatabaseLogicCommand | IQueryCondition>
  262. ): DatabaseLogicCommand
  263. not(expression: DatabaseLogicCommand): DatabaseLogicCommand
  264. exists(val: boolean): DatabaseQueryCommand
  265. mod(divisor: number, remainder: number): DatabaseQueryCommand
  266. all(val: any[]): DatabaseQueryCommand
  267. elemMatch(val: any): DatabaseQueryCommand
  268. size(val: number): DatabaseQueryCommand
  269. set(val: any): DatabaseUpdateCommand
  270. remove(): DatabaseUpdateCommand
  271. inc(val: number): DatabaseUpdateCommand
  272. mul(val: number): DatabaseUpdateCommand
  273. min(val: number): DatabaseUpdateCommand
  274. max(val: number): DatabaseUpdateCommand
  275. rename(val: string): DatabaseUpdateCommand
  276. bit(val: number): DatabaseUpdateCommand
  277. push(...values: any[]): DatabaseUpdateCommand
  278. pop(): DatabaseUpdateCommand
  279. shift(): DatabaseUpdateCommand
  280. unshift(...values: any[]): DatabaseUpdateCommand
  281. addToSet(val: any): DatabaseUpdateCommand
  282. pull(val: any): DatabaseUpdateCommand
  283. pullAll(val: any): DatabaseUpdateCommand
  284. project: {
  285. slice(val: number | [number, number]): DatabaseProjectionCommand
  286. }
  287. aggregate: {
  288. __safe_props__?: Set<string>
  289. abs(val: any): DatabaseAggregateCommand
  290. add(val: any): DatabaseAggregateCommand
  291. addToSet(val: any): DatabaseAggregateCommand
  292. allElementsTrue(val: any): DatabaseAggregateCommand
  293. and(val: any): DatabaseAggregateCommand
  294. anyElementTrue(val: any): DatabaseAggregateCommand
  295. arrayElemAt(val: any): DatabaseAggregateCommand
  296. arrayToObject(val: any): DatabaseAggregateCommand
  297. avg(val: any): DatabaseAggregateCommand
  298. ceil(val: any): DatabaseAggregateCommand
  299. cmp(val: any): DatabaseAggregateCommand
  300. concat(val: any): DatabaseAggregateCommand
  301. concatArrays(val: any): DatabaseAggregateCommand
  302. cond(val: any): DatabaseAggregateCommand
  303. convert(val: any): DatabaseAggregateCommand
  304. dateFromParts(val: any): DatabaseAggregateCommand
  305. dateToParts(val: any): DatabaseAggregateCommand
  306. dateFromString(val: any): DatabaseAggregateCommand
  307. dateToString(val: any): DatabaseAggregateCommand
  308. dayOfMonth(val: any): DatabaseAggregateCommand
  309. dayOfWeek(val: any): DatabaseAggregateCommand
  310. dayOfYear(val: any): DatabaseAggregateCommand
  311. divide(val: any): DatabaseAggregateCommand
  312. eq(val: any): DatabaseAggregateCommand
  313. exp(val: any): DatabaseAggregateCommand
  314. filter(val: any): DatabaseAggregateCommand
  315. first(val: any): DatabaseAggregateCommand
  316. floor(val: any): DatabaseAggregateCommand
  317. gt(val: any): DatabaseAggregateCommand
  318. gte(val: any): DatabaseAggregateCommand
  319. hour(val: any): DatabaseAggregateCommand
  320. ifNull(val: any): DatabaseAggregateCommand
  321. in(val: any): DatabaseAggregateCommand
  322. indexOfArray(val: any): DatabaseAggregateCommand
  323. indexOfBytes(val: any): DatabaseAggregateCommand
  324. indexOfCP(val: any): DatabaseAggregateCommand
  325. isArray(val: any): DatabaseAggregateCommand
  326. isoDayOfWeek(val: any): DatabaseAggregateCommand
  327. isoWeek(val: any): DatabaseAggregateCommand
  328. isoWeekYear(val: any): DatabaseAggregateCommand
  329. last(val: any): DatabaseAggregateCommand
  330. let(val: any): DatabaseAggregateCommand
  331. literal(val: any): DatabaseAggregateCommand
  332. ln(val: any): DatabaseAggregateCommand
  333. log(val: any): DatabaseAggregateCommand
  334. log10(val: any): DatabaseAggregateCommand
  335. lt(val: any): DatabaseAggregateCommand
  336. lte(val: any): DatabaseAggregateCommand
  337. ltrim(val: any): DatabaseAggregateCommand
  338. map(val: any): DatabaseAggregateCommand
  339. max(val: any): DatabaseAggregateCommand
  340. mergeObjects(val: any): DatabaseAggregateCommand
  341. meta(val: any): DatabaseAggregateCommand
  342. min(val: any): DatabaseAggregateCommand
  343. millisecond(val: any): DatabaseAggregateCommand
  344. minute(val: any): DatabaseAggregateCommand
  345. mod(val: any): DatabaseAggregateCommand
  346. month(val: any): DatabaseAggregateCommand
  347. multiply(val: any): DatabaseAggregateCommand
  348. neq(val: any): DatabaseAggregateCommand
  349. not(val: any): DatabaseAggregateCommand
  350. objectToArray(val: any): DatabaseAggregateCommand
  351. or(val: any): DatabaseAggregateCommand
  352. pow(val: any): DatabaseAggregateCommand
  353. push(val: any): DatabaseAggregateCommand
  354. range(val: any): DatabaseAggregateCommand
  355. reduce(val: any): DatabaseAggregateCommand
  356. reverseArray(val: any): DatabaseAggregateCommand
  357. rtrim(val: any): DatabaseAggregateCommand
  358. second(val: any): DatabaseAggregateCommand
  359. setDifference(val: any): DatabaseAggregateCommand
  360. setEquals(val: any): DatabaseAggregateCommand
  361. setIntersection(val: any): DatabaseAggregateCommand
  362. setIsSubset(val: any): DatabaseAggregateCommand
  363. setUnion(val: any): DatabaseAggregateCommand
  364. size(val: any): DatabaseAggregateCommand
  365. slice(val: any): DatabaseAggregateCommand
  366. split(val: any): DatabaseAggregateCommand
  367. sqrt(val: any): DatabaseAggregateCommand
  368. stdDevPop(val: any): DatabaseAggregateCommand
  369. stdDevSamp(val: any): DatabaseAggregateCommand
  370. strcasecmp(val: any): DatabaseAggregateCommand
  371. strLenBytes(val: any): DatabaseAggregateCommand
  372. strLenCP(val: any): DatabaseAggregateCommand
  373. substr(val: any): DatabaseAggregateCommand
  374. substrBytes(val: any): DatabaseAggregateCommand
  375. substrCP(val: any): DatabaseAggregateCommand
  376. subtract(val: any): DatabaseAggregateCommand
  377. sum(val: any): DatabaseAggregateCommand
  378. switch(val: any): DatabaseAggregateCommand
  379. toBool(val: any): DatabaseAggregateCommand
  380. toDate(val: any): DatabaseAggregateCommand
  381. toDecimal(val: any): DatabaseAggregateCommand
  382. toDouble(val: any): DatabaseAggregateCommand
  383. toInt(val: any): DatabaseAggregateCommand
  384. toLong(val: any): DatabaseAggregateCommand
  385. toObjectId(val: any): DatabaseAggregateCommand
  386. toString(val: any): DatabaseAggregateCommand
  387. toLower(val: any): DatabaseAggregateCommand
  388. toUpper(val: any): DatabaseAggregateCommand
  389. trim(val: any): DatabaseAggregateCommand
  390. trunc(val: any): DatabaseAggregateCommand
  391. type(val: any): DatabaseAggregateCommand
  392. week(val: any): DatabaseAggregateCommand
  393. year(val: any): DatabaseAggregateCommand
  394. zip(val: any): DatabaseAggregateCommand
  395. }
  396. }
  397. class DatabaseAggregateCommand {}
  398. enum LOGIC_COMMANDS_LITERAL {
  399. AND = 'and',
  400. OR = 'or',
  401. NOT = 'not',
  402. NOR = 'nor'
  403. }
  404. class DatabaseLogicCommand {
  405. and(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
  406. or(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
  407. nor(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
  408. not(expression: DatabaseLogicCommand): DatabaseLogicCommand
  409. }
  410. enum QUERY_COMMANDS_LITERAL {
  411. // comparison
  412. EQ = 'eq',
  413. NEQ = 'neq',
  414. GT = 'gt',
  415. GTE = 'gte',
  416. LT = 'lt',
  417. LTE = 'lte',
  418. IN = 'in',
  419. NIN = 'nin',
  420. // geo
  421. GEO_NEAR = 'geoNear',
  422. GEO_WITHIN = 'geoWithin',
  423. GEO_INTERSECTS = 'geoIntersects',
  424. // element
  425. EXISTS = 'exists',
  426. // evaluation
  427. MOD = 'mod',
  428. // array
  429. ALL = 'all',
  430. ELEM_MATCH = 'elemMatch',
  431. SIZE = 'size'
  432. }
  433. class DatabaseQueryCommand extends DatabaseLogicCommand {
  434. eq(val: any): DatabaseLogicCommand
  435. neq(val: any): DatabaseLogicCommand
  436. gt(val: any): DatabaseLogicCommand
  437. gte(val: any): DatabaseLogicCommand
  438. lt(val: any): DatabaseLogicCommand
  439. lte(val: any): DatabaseLogicCommand
  440. in(val: any[]): DatabaseLogicCommand
  441. nin(val: any[]): DatabaseLogicCommand
  442. exists(val: boolean): DatabaseLogicCommand
  443. mod(divisor: number, remainder: number): DatabaseLogicCommand
  444. all(val: any[]): DatabaseLogicCommand
  445. elemMatch(val: any): DatabaseLogicCommand
  446. size(val: number): DatabaseLogicCommand
  447. geoNear(options: IGeoNearCommandOptions): DatabaseLogicCommand
  448. geoWithin(options: IGeoWithinCommandOptions): DatabaseLogicCommand
  449. geoIntersects(
  450. options: IGeoIntersectsCommandOptions
  451. ): DatabaseLogicCommand
  452. }
  453. enum PROJECTION_COMMANDS_LITERAL {
  454. SLICE = 'slice'
  455. }
  456. class DatabaseProjectionCommand {}
  457. enum UPDATE_COMMANDS_LITERAL {
  458. // field
  459. SET = 'set',
  460. REMOVE = 'remove',
  461. INC = 'inc',
  462. MUL = 'mul',
  463. MIN = 'min',
  464. MAX = 'max',
  465. RENAME = 'rename',
  466. // bitwise
  467. BIT = 'bit',
  468. // array
  469. PUSH = 'push',
  470. POP = 'pop',
  471. SHIFT = 'shift',
  472. UNSHIFT = 'unshift',
  473. ADD_TO_SET = 'addToSet',
  474. PULL = 'pull',
  475. PULL_ALL = 'pullAll'
  476. }
  477. class DatabaseUpdateCommand {}
  478. class Batch {}
  479. /**
  480. * A contract that all API provider must adhere to
  481. */
  482. class APIBaseContract<
  483. PromiseReturn,
  484. CallbackReturn,
  485. Param extends IAPIParam,
  486. Context = any
  487. > {
  488. getContext(param: Param): Context
  489. /**
  490. * In case of callback-style invocation, this function will be called
  491. */
  492. getCallbackReturn(param: Param, context: Context): CallbackReturn
  493. getFinalParam<T extends Param>(param: Param, context: Context): T
  494. run<T extends Param>(param: T): Promise<PromiseReturn>
  495. }
  496. interface IGeoPointConstructor {
  497. new (longitude: number, latitide: number): GeoPoint
  498. new (geojson: IGeoJSONPoint): GeoPoint
  499. (longitude: number, latitide: number): GeoPoint
  500. (geojson: IGeoJSONPoint): GeoPoint
  501. }
  502. interface IGeoMultiPointConstructor {
  503. new (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint
  504. (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint
  505. }
  506. interface IGeoLineStringConstructor {
  507. new (points: GeoPoint[] | IGeoJSONLineString): GeoLineString
  508. (points: GeoPoint[] | IGeoJSONLineString): GeoLineString
  509. }
  510. interface IGeoMultiLineStringConstructor {
  511. new (
  512. lineStrings: GeoLineString[] | IGeoJSONMultiLineString
  513. ): GeoMultiLineString
  514. (
  515. lineStrings: GeoLineString[] | IGeoJSONMultiLineString
  516. ): GeoMultiLineString
  517. }
  518. interface IGeoPolygonConstructor {
  519. new (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon
  520. (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon
  521. }
  522. interface IGeoMultiPolygonConstructor {
  523. new (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon
  524. (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon
  525. }
  526. interface IGeo {
  527. Point: IGeoPointConstructor
  528. MultiPoint: IGeoMultiPointConstructor
  529. LineString: IGeoLineStringConstructor
  530. MultiLineString: IGeoMultiLineStringConstructor
  531. Polygon: IGeoPolygonConstructor
  532. MultiPolygon: IGeoMultiPolygonConstructor
  533. }
  534. interface IGeoJSONPoint {
  535. type: 'Point'
  536. coordinates: [number, number]
  537. }
  538. interface IGeoJSONMultiPoint {
  539. type: 'MultiPoint'
  540. coordinates: Array<[number, number]>
  541. }
  542. interface IGeoJSONLineString {
  543. type: 'LineString'
  544. coordinates: Array<[number, number]>
  545. }
  546. interface IGeoJSONMultiLineString {
  547. type: 'MultiLineString'
  548. coordinates: Array<Array<[number, number]>>
  549. }
  550. interface IGeoJSONPolygon {
  551. type: 'Polygon'
  552. coordinates: Array<Array<[number, number]>>
  553. }
  554. interface IGeoJSONMultiPolygon {
  555. type: 'MultiPolygon'
  556. coordinates: Array<Array<Array<[number, number]>>>
  557. }
  558. type IGeoJSONObject =
  559. | IGeoJSONPoint
  560. | IGeoJSONMultiPoint
  561. | IGeoJSONLineString
  562. | IGeoJSONMultiLineString
  563. | IGeoJSONPolygon
  564. | IGeoJSONMultiPolygon
  565. abstract class GeoPoint {
  566. longitude: number
  567. latitude: number
  568. constructor(longitude: number, latitude: number)
  569. toJSON(): Record<string, any>
  570. toString(): string
  571. }
  572. abstract class GeoMultiPoint {
  573. points: GeoPoint[]
  574. constructor(points: GeoPoint[])
  575. toJSON(): IGeoJSONMultiPoint
  576. toString(): string
  577. }
  578. abstract class GeoLineString {
  579. points: GeoPoint[]
  580. constructor(points: GeoPoint[])
  581. toJSON(): IGeoJSONLineString
  582. toString(): string
  583. }
  584. abstract class GeoMultiLineString {
  585. lines: GeoLineString[]
  586. constructor(lines: GeoLineString[])
  587. toJSON(): IGeoJSONMultiLineString
  588. toString(): string
  589. }
  590. abstract class GeoPolygon {
  591. lines: GeoLineString[]
  592. constructor(lines: GeoLineString[])
  593. toJSON(): IGeoJSONPolygon
  594. toString(): string
  595. }
  596. abstract class GeoMultiPolygon {
  597. polygons: GeoPolygon[]
  598. constructor(polygons: GeoPolygon[])
  599. toJSON(): IGeoJSONMultiPolygon
  600. toString(): string
  601. }
  602. type GeoInstance =
  603. | GeoPoint
  604. | GeoMultiPoint
  605. | GeoLineString
  606. | GeoMultiLineString
  607. | GeoPolygon
  608. | GeoMultiPolygon
  609. interface IGeoNearCommandOptions {
  610. geometry: GeoPoint
  611. maxDistance?: number
  612. minDistance?: number
  613. }
  614. interface IGeoWithinCommandOptions {
  615. geometry: GeoPolygon | GeoMultiPolygon
  616. }
  617. interface IGeoIntersectsCommandOptions {
  618. geometry:
  619. | GeoPoint
  620. | GeoMultiPoint
  621. | GeoLineString
  622. | GeoMultiLineString
  623. | GeoPolygon
  624. | GeoMultiPolygon
  625. }
  626. interface IServerDateOptions {
  627. offset: number
  628. }
  629. abstract class ServerDate {
  630. readonly options: IServerDateOptions
  631. constructor(options?: IServerDateOptions)
  632. }
  633. interface IRegExpOptions {
  634. regexp: string
  635. options?: string
  636. }
  637. interface IRegExpConstructor {
  638. new (options: IRegExpOptions): RegExp
  639. (options: IRegExpOptions): RegExp
  640. }
  641. abstract class RegExp {
  642. readonly regexp: string
  643. readonly options: string
  644. constructor(options: IRegExpOptions)
  645. }
  646. type DocumentId = string | number
  647. interface IDocumentData {
  648. _id?: DocumentId
  649. [key: string]: any
  650. }
  651. type IDBAPIParam = IAPIParam
  652. interface IAddDocumentOptions extends IDBAPIParam {
  653. data: IDocumentData
  654. }
  655. type IGetDocumentOptions = IDBAPIParam
  656. type ICountDocumentOptions = IDBAPIParam
  657. interface IUpdateDocumentOptions extends IDBAPIParam {
  658. data: IUpdateCondition
  659. }
  660. interface IUpdateSingleDocumentOptions extends IDBAPIParam {
  661. data: IUpdateCondition
  662. }
  663. interface ISetDocumentOptions extends IDBAPIParam {
  664. data: IUpdateCondition
  665. }
  666. interface ISetSingleDocumentOptions extends IDBAPIParam {
  667. data: IUpdateCondition
  668. }
  669. interface IRemoveDocumentOptions extends IDBAPIParam {
  670. query: IQueryCondition
  671. }
  672. type IRemoveSingleDocumentOptions = IDBAPIParam
  673. interface IWatchOptions {
  674. // server realtime data init & change event
  675. onChange: (snapshot: ISnapshot) => void
  676. // error while connecting / listening
  677. onError: (error: any) => void
  678. }
  679. interface ISnapshot {
  680. id: number
  681. docChanges: ISingleDBEvent[]
  682. docs: Record<string, any>
  683. type?: SnapshotType
  684. }
  685. type SnapshotType = 'init'
  686. interface ISingleDBEvent {
  687. id: number
  688. dataType: DataType
  689. queueType: QueueType
  690. docId: string
  691. doc: Record<string, any>
  692. updatedFields?: Record<string, any>
  693. removedFields?: string[]
  694. }
  695. type DataType = 'init' | 'update' | 'replace' | 'add' | 'remove' | 'limit'
  696. type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update'
  697. interface IQueryCondition {
  698. [key: string]: any
  699. }
  700. type IStringQueryCondition = string
  701. interface IQueryResult extends IAPISuccessParam {
  702. data: IDocumentData[]
  703. }
  704. interface IQuerySingleResult extends IAPISuccessParam {
  705. data: IDocumentData
  706. }
  707. interface IUpdateCondition {
  708. [key: string]: any
  709. }
  710. type IStringUpdateCondition = string
  711. interface IAddResult extends IAPISuccessParam {
  712. _id: DocumentId
  713. }
  714. interface IUpdateResult extends IAPISuccessParam {
  715. stats: {
  716. updated: number
  717. // created: number,
  718. }
  719. }
  720. interface ISetResult extends IAPISuccessParam {
  721. _id: DocumentId
  722. stats: {
  723. updated: number
  724. created: number
  725. }
  726. }
  727. interface IRemoveResult extends IAPISuccessParam {
  728. stats: {
  729. removed: number
  730. }
  731. }
  732. interface ICountResult extends IAPISuccessParam {
  733. total: number
  734. }
  735. }
  736. type Optional<T> = { [K in keyof T]+?: T[K] }
  737. type OQ<
  738. T extends Optional<
  739. Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
  740. >
  741. > =
  742. | (RQ<T> & Required<Pick<T, 'success'>>)
  743. | (RQ<T> & Required<Pick<T, 'fail'>>)
  744. | (RQ<T> & Required<Pick<T, 'complete'>>)
  745. | (RQ<T> & Required<Pick<T, 'success' | 'fail'>>)
  746. | (RQ<T> & Required<Pick<T, 'success' | 'complete'>>)
  747. | (RQ<T> & Required<Pick<T, 'fail' | 'complete'>>)
  748. | (RQ<T> & Required<Pick<T, 'fail' | 'complete' | 'success'>>)
  749. type RQ<
  750. T extends Optional<
  751. Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
  752. >
  753. > = Pick<T, Exclude<keyof T, 'complete' | 'success' | 'fail'>>