orange-orm 3.10.2

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 (459) hide show
  1. package/.dockerignore +1 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.js +45 -0
  4. package/.gitattributes +3 -0
  5. package/CNAME +1 -0
  6. package/CONTRIBUTING.md +43 -0
  7. package/LICENSE +7 -0
  8. package/README.md +1969 -0
  9. package/SECURITY.md +12 -0
  10. package/bin/build.js +127 -0
  11. package/bin/compile.js +26 -0
  12. package/bin/rdb.js +4 -0
  13. package/docs/CODE_OF_CONDUCT.md +18 -0
  14. package/docs/changelog.md +461 -0
  15. package/docs/docs.md +2373 -0
  16. package/docs/orange.svg +32 -0
  17. package/docs/relations.png +0 -0
  18. package/package.json +139 -0
  19. package/src/applyPatch.js +105 -0
  20. package/src/client/axiosInterceptor.js +46 -0
  21. package/src/client/clientMap.js +72 -0
  22. package/src/client/createPatch.js +122 -0
  23. package/src/client/createProviders.js +121 -0
  24. package/src/client/index.js +997 -0
  25. package/src/client/index.mjs +6295 -0
  26. package/src/client/map.js +110 -0
  27. package/src/client/merge.js +9 -0
  28. package/src/client/netAdapter.js +133 -0
  29. package/src/client/rollup.config.js +12 -0
  30. package/src/client/self.js +4 -0
  31. package/src/client/stringify.js +22 -0
  32. package/src/client/toKeyPositionMap.js +30 -0
  33. package/src/clsTest.js +79 -0
  34. package/src/createDomain/negotiateForwardProperty.js +23 -0
  35. package/src/createDomain.js +31 -0
  36. package/src/dateToISOString.js +25 -0
  37. package/src/emitEvent.js +46 -0
  38. package/src/emptyFilter.js +35 -0
  39. package/src/flags.js +6 -0
  40. package/src/fromCompareObject.js +24 -0
  41. package/src/generic-pool.js +641 -0
  42. package/src/getManyDto/newQuery.js +18 -0
  43. package/src/getManyDto/query/newColumnSql.js +8 -0
  44. package/src/getManyDto/query/newSingleQuery.js +19 -0
  45. package/src/getManyDto/query/singleQuery/newJoinedColumnSql.js +25 -0
  46. package/src/getManyDto/query/singleQuery/newShallowColumnSql.js +25 -0
  47. package/src/getManyDto.js +255 -0
  48. package/src/getTSDefinition.js +510 -0
  49. package/src/hostExpress/executePath.js +433 -0
  50. package/src/hostExpress/getMeta.js +49 -0
  51. package/src/hostExpress.js +125 -0
  52. package/src/hostLocal.js +110 -0
  53. package/src/index.d.ts +324 -0
  54. package/src/index.js +116 -0
  55. package/src/jsconfig.json +8 -0
  56. package/src/lock/toIntKey.js +35 -0
  57. package/src/lock.js +26 -0
  58. package/src/map.d.ts +1729 -0
  59. package/src/mssql/encodeBuffer.js +7 -0
  60. package/src/mssql/newDatabase.js +129 -0
  61. package/src/mssql/newPool.js +19 -0
  62. package/src/mssql/newTransaction.js +69 -0
  63. package/src/mssql/pool/defaults.js +45 -0
  64. package/src/mssql/pool/end.js +13 -0
  65. package/src/mssql/pool/newGenericPool.js +62 -0
  66. package/src/mssql/wrapQuery.js +34 -0
  67. package/src/mySql/deleteFromSql.js +8 -0
  68. package/src/mySql/encodeBoolean.js +7 -0
  69. package/src/mySql/insert.js +21 -0
  70. package/src/mySql/insertSql.js +62 -0
  71. package/src/mySql/lastInsertedSql.js +11 -0
  72. package/src/mySql/limitAndOffset.js +18 -0
  73. package/src/mySql/newDatabase.js +127 -0
  74. package/src/mySql/newPool.js +19 -0
  75. package/src/mySql/newTransaction.js +54 -0
  76. package/src/mySql/pool/defaults.js +16 -0
  77. package/src/mySql/pool/end.js +13 -0
  78. package/src/mySql/pool/negotiatePoolOptions.js +12 -0
  79. package/src/mySql/pool/newGenericPool.js +67 -0
  80. package/src/mySql/selectForUpdateSql.js +3 -0
  81. package/src/mySql/wrapQuery.js +16 -0
  82. package/src/mySql/wrapQueryStream.js +9 -0
  83. package/src/newArray.js +3 -0
  84. package/src/newCollection.js +55 -0
  85. package/src/newId.js +1 -0
  86. package/src/newImmutable.js +22 -0
  87. package/src/newObject.js +5 -0
  88. package/src/oracle/deleteFromSql.js +8 -0
  89. package/src/oracle/encodeBoolean.js +7 -0
  90. package/src/oracle/encodeBuffer.js +7 -0
  91. package/src/oracle/encodeDate.js +7 -0
  92. package/src/oracle/formatDateIn.js +5 -0
  93. package/src/oracle/formatDateOut.js +5 -0
  94. package/src/oracle/insert.js +23 -0
  95. package/src/oracle/insertSql.js +73 -0
  96. package/src/oracle/lastInsertedSql.js +14 -0
  97. package/src/oracle/limitAndOffset.js +18 -0
  98. package/src/oracle/mergeSql.js +79 -0
  99. package/src/oracle/newDatabase.js +128 -0
  100. package/src/oracle/newInsertCommandCore.js +27 -0
  101. package/src/oracle/newPool.js +19 -0
  102. package/src/oracle/newTransaction.js +63 -0
  103. package/src/oracle/outputInsertedSql.js +5 -0
  104. package/src/oracle/pool/defaults.js +45 -0
  105. package/src/oracle/pool/end.js +13 -0
  106. package/src/oracle/pool/newGenericPool.js +64 -0
  107. package/src/oracle/replaceParamChar.js +14 -0
  108. package/src/oracle/selectForUpdateSql.js +3 -0
  109. package/src/oracle/wrapQuery.js +38 -0
  110. package/src/patchRow.js +13 -0
  111. package/src/patchTable.js +317 -0
  112. package/src/pg/deleteFromSql.js +8 -0
  113. package/src/pg/encodeBoolean.js +5 -0
  114. package/src/pg/encodeDate.js +7 -0
  115. package/src/pg/encodeJSON.js +15 -0
  116. package/src/pg/formatDateOut.js +5 -0
  117. package/src/pg/insert.js +14 -0
  118. package/src/pg/insertSql.js +70 -0
  119. package/src/pg/lastInsertedSql.js +11 -0
  120. package/src/pg/limitAndOffset.js +18 -0
  121. package/src/pg/newDatabase.js +153 -0
  122. package/src/pg/newPool.js +19 -0
  123. package/src/pg/newStreamableQuery.js +7 -0
  124. package/src/pg/newTransaction.js +58 -0
  125. package/src/pg/pool/defaults.js +45 -0
  126. package/src/pg/pool/end.js +13 -0
  127. package/src/pg/pool/newPgPool.js +82 -0
  128. package/src/pg/replaceParamChar.js +14 -0
  129. package/src/pg/schema.js +11 -0
  130. package/src/pg/selectForUpdateSql.js +3 -0
  131. package/src/pg/wrapQuery.js +33 -0
  132. package/src/pg/wrapQueryStream.js +20 -0
  133. package/src/pools.js +17 -0
  134. package/src/query/negotiateParameters.js +10 -0
  135. package/src/query/negotiateSql.js +14 -0
  136. package/src/query/wrapQuery.js +17 -0
  137. package/src/query.js +13 -0
  138. package/src/sap/deleteFromSql.js +8 -0
  139. package/src/sap/encodeBoolean.js +7 -0
  140. package/src/sap/encodeBuffer.js +7 -0
  141. package/src/sap/formatDateOut.js +5 -0
  142. package/src/sap/insert.js +21 -0
  143. package/src/sap/insertSql.js +64 -0
  144. package/src/sap/lastInsertedSql.js +12 -0
  145. package/src/sap/limitAndOffset.js +16 -0
  146. package/src/sap/mergeSql.js +73 -0
  147. package/src/sap/newDatabase.js +129 -0
  148. package/src/sap/newPool.js +19 -0
  149. package/src/sap/newTransaction.js +69 -0
  150. package/src/sap/pool/end.js +13 -0
  151. package/src/sap/selectForUpdateSql.js +3 -0
  152. package/src/sqlite/deleteFromSql.js +8 -0
  153. package/src/sqlite/encodeBoolean.js +7 -0
  154. package/src/sqlite/encodeBuffer.js +7 -0
  155. package/src/sqlite/insert.js +21 -0
  156. package/src/sqlite/insertSql.js +64 -0
  157. package/src/sqlite/lastInsertedSql.js +12 -0
  158. package/src/sqlite/limitAndOffset.js +18 -0
  159. package/src/sqlite/newDatabase.js +128 -0
  160. package/src/sqlite/newPool.js +19 -0
  161. package/src/sqlite/newTransaction.js +58 -0
  162. package/src/sqlite/pool/defaults.js +45 -0
  163. package/src/sqlite/pool/end.js +13 -0
  164. package/src/sqlite/pool/newGenericPool.js +59 -0
  165. package/src/sqlite/selectForUpdateSql.js +3 -0
  166. package/src/sqlite/wrapQuery.js +24 -0
  167. package/src/table/aggregate.js +9 -0
  168. package/src/table/begin.js +10 -0
  169. package/src/table/cascadeDelete.js +11 -0
  170. package/src/table/cloneStrategy.js +18 -0
  171. package/src/table/column/binary/newDecode.js +15 -0
  172. package/src/table/column/binary/newEncode.js +23 -0
  173. package/src/table/column/binary/purify.js +12 -0
  174. package/src/table/column/binary.js +12 -0
  175. package/src/table/column/boolean/newDecode.js +12 -0
  176. package/src/table/column/boolean/newEncode.js +36 -0
  177. package/src/table/column/boolean/purify.js +7 -0
  178. package/src/table/column/boolean.js +14 -0
  179. package/src/table/column/date/formatOut.js +11 -0
  180. package/src/table/column/date/newDecode.js +17 -0
  181. package/src/table/column/date/newEncode.js +47 -0
  182. package/src/table/column/date/purify.js +17 -0
  183. package/src/table/column/date/toISOString.js +25 -0
  184. package/src/table/column/date/tryParseISO.js +14 -0
  185. package/src/table/column/date.js +14 -0
  186. package/src/table/column/dateWithTimeZone/newEncode.js +41 -0
  187. package/src/table/column/dateWithTimeZone.js +14 -0
  188. package/src/table/column/encodeFilterArg.js +8 -0
  189. package/src/table/column/equal.js +15 -0
  190. package/src/table/column/extractAlias.js +7 -0
  191. package/src/table/column/greaterThan.js +12 -0
  192. package/src/table/column/greaterThanOrEqual.js +12 -0
  193. package/src/table/column/guid/newDecode.js +10 -0
  194. package/src/table/column/guid/newEncode.js +30 -0
  195. package/src/table/column/guid/purify.js +10 -0
  196. package/src/table/column/guid.js +12 -0
  197. package/src/table/column/in.js +24 -0
  198. package/src/table/column/json/formatOut.js +11 -0
  199. package/src/table/column/json/newDecode.js +21 -0
  200. package/src/table/column/json/newEncode.js +41 -0
  201. package/src/table/column/json/purify.js +7 -0
  202. package/src/table/column/json.js +22 -0
  203. package/src/table/column/lessThan.js +12 -0
  204. package/src/table/column/lessThanOrEqual.js +12 -0
  205. package/src/table/column/negotiateNextAndFilter.js +7 -0
  206. package/src/table/column/negotiateNextOrFilter.js +7 -0
  207. package/src/table/column/negotiateRawSqlFilter.js +74 -0
  208. package/src/table/column/newBoolean.js +54 -0
  209. package/src/table/column/newColumn.js +89 -0
  210. package/src/table/column/newDecodeCore.js +10 -0
  211. package/src/table/column/notEqual.js +15 -0
  212. package/src/table/column/numeric/negotiateDefault.js +5 -0
  213. package/src/table/column/numeric/newDecode.js +16 -0
  214. package/src/table/column/numeric/newEncode.js +25 -0
  215. package/src/table/column/numeric/purify.js +12 -0
  216. package/src/table/column/numeric.js +15 -0
  217. package/src/table/column/string/contains.js +3 -0
  218. package/src/table/column/string/containsCore.js +16 -0
  219. package/src/table/column/string/endsWith.js +3 -0
  220. package/src/table/column/string/endsWithCore.js +16 -0
  221. package/src/table/column/string/iContains.js +3 -0
  222. package/src/table/column/string/iEndsWith.js +3 -0
  223. package/src/table/column/string/iEqual.js +15 -0
  224. package/src/table/column/string/iStartsWith.js +3 -0
  225. package/src/table/column/string/newEncode.js +31 -0
  226. package/src/table/column/string/purify.js +7 -0
  227. package/src/table/column/string/startsWith.js +3 -0
  228. package/src/table/column/string/startsWithCore.js +16 -0
  229. package/src/table/column/string.js +55 -0
  230. package/src/table/column.js +154 -0
  231. package/src/table/commands/beginCommand.js +13 -0
  232. package/src/table/commands/commitCommand.js +9 -0
  233. package/src/table/commands/compressChanges.js +25 -0
  234. package/src/table/commands/delete/createAlias.js +6 -0
  235. package/src/table/commands/delete/newSingleCommand.js +17 -0
  236. package/src/table/commands/delete/singleCommand/joinSql.js +26 -0
  237. package/src/table/commands/delete/singleCommand/newSingleCommandCore.js +19 -0
  238. package/src/table/commands/delete/singleCommand/selectSql.js +11 -0
  239. package/src/table/commands/delete/singleCommand/subFilter.js +19 -0
  240. package/src/table/commands/delete/singleCommand/whereSql.js +25 -0
  241. package/src/table/commands/getChangeSet.js +6 -0
  242. package/src/table/commands/insert/getSqlTemplate.js +68 -0
  243. package/src/table/commands/lastCommandMatches.js +11 -0
  244. package/src/table/commands/negotiateEndEdit.js +7 -0
  245. package/src/table/commands/newDeleteCommand.js +23 -0
  246. package/src/table/commands/newGetLastInsertedCommand.js +49 -0
  247. package/src/table/commands/newGetLastInsertedCommandCore.js +42 -0
  248. package/src/table/commands/newInsertAndForgetCommand.js +55 -0
  249. package/src/table/commands/newInsertCommand.js +56 -0
  250. package/src/table/commands/newInsertCommandCore.js +27 -0
  251. package/src/table/commands/newRow.js +51 -0
  252. package/src/table/commands/newUpdateCommand.js +62 -0
  253. package/src/table/commands/newUpdateCommandCore.js +45 -0
  254. package/src/table/commands/pushCommand.js +10 -0
  255. package/src/table/commands/rollbackCommand.js +13 -0
  256. package/src/table/commit.js +30 -0
  257. package/src/table/count.js +29 -0
  258. package/src/table/createJSONReadStream.js +7 -0
  259. package/src/table/createJSONReadStreamDefault.js +33 -0
  260. package/src/table/createJSONReadStreamNative.js +31 -0
  261. package/src/table/createReadStream.js +24 -0
  262. package/src/table/createReadStreamCoreNative.js +40 -0
  263. package/src/table/createReadStreamDefault.js +102 -0
  264. package/src/table/createReadStreamNative.js +17 -0
  265. package/src/table/delete.js +20 -0
  266. package/src/table/deleteSessionContext.js +17 -0
  267. package/src/table/encodeDbSpecific.js +10 -0
  268. package/src/table/executeQueries/executeChanges.js +35 -0
  269. package/src/table/executeQueries/executeQueriesCore.js +12 -0
  270. package/src/table/executeQueries/executeQuery.js +8 -0
  271. package/src/table/executeQueries/resolveExecuteQuery.js +57 -0
  272. package/src/table/executeQueries.js +15 -0
  273. package/src/table/extractDeleteStrategy.js +9 -0
  274. package/src/table/fuzzyPromise.js +18 -0
  275. package/src/table/getById.js +33 -0
  276. package/src/table/getFirstFromDb.js +10 -0
  277. package/src/table/getFromDbById.js +17 -0
  278. package/src/table/getIdArgs.js +14 -0
  279. package/src/table/getMany.js +26 -0
  280. package/src/table/getManyDto/newQuery.js +32 -0
  281. package/src/table/getManyDto/pg/newQuery.js +8 -0
  282. package/src/table/getManyDto.js +10 -0
  283. package/src/table/getManyDtoFast/getSubRows.js +172 -0
  284. package/src/table/getManyDtoFast/newQuery.js +8 -0
  285. package/src/table/getManyDtoFast/newQueryCore.js +18 -0
  286. package/src/table/getManyDtoFast/query/newSingleQuery.js +20 -0
  287. package/src/table/getManyDtoFast/query/newSubQueries/joinLegToQuery.js +18 -0
  288. package/src/table/getManyDtoFast/query/newSubQueries/manyLegToQuery.js +20 -0
  289. package/src/table/getManyDtoFast/query/newSubQueries/oneLegToQuery.js +21 -0
  290. package/src/table/getManyDtoFast/query/newSubQueries.js +47 -0
  291. package/src/table/getManyDtoFast/query/singleQuery/newShallowColumnSql.js +21 -0
  292. package/src/table/getSessionContext.js +10 -0
  293. package/src/table/getSessionSingleton.js +5 -0
  294. package/src/table/groupBy/newQuery.js +25 -0
  295. package/src/table/groupBy.js +65 -0
  296. package/src/table/hasMany.js +33 -0
  297. package/src/table/hasOne.js +33 -0
  298. package/src/table/insert.js +91 -0
  299. package/src/table/insertDefault.js +88 -0
  300. package/src/table/join.js +42 -0
  301. package/src/table/joinRelation/getRelatives.js +64 -0
  302. package/src/table/log.js +39 -0
  303. package/src/table/negotiateAddStrategy.js +20 -0
  304. package/src/table/negotiateExpandInverse.js +13 -0
  305. package/src/table/newCache.js +96 -0
  306. package/src/table/newCascadeDeleteStrategy.js +30 -0
  307. package/src/table/newGetRelated.js +21 -0
  308. package/src/table/newJoinRelation.js +117 -0
  309. package/src/table/newManyRelation.js +61 -0
  310. package/src/table/newOneRelation.js +61 -0
  311. package/src/table/newPrimaryKeyFilter.js +13 -0
  312. package/src/table/newQuery.js +18 -0
  313. package/src/table/newRelatedTable.js +100 -0
  314. package/src/table/newRowCache.js +106 -0
  315. package/src/table/newThrow.js +11 -0
  316. package/src/table/nullPromise.js +1 -0
  317. package/src/table/objectToCallback.js +7 -0
  318. package/src/table/oneRelation/getRelatives.js +45 -0
  319. package/src/table/popChanges.js +19 -0
  320. package/src/table/promise.js +14 -0
  321. package/src/table/purifyStrategy.js +49 -0
  322. package/src/table/query/extractFilter.js +9 -0
  323. package/src/table/query/extractLimit.js +11 -0
  324. package/src/table/query/extractLimitQuery.js +23 -0
  325. package/src/table/query/extractOffset.js +11 -0
  326. package/src/table/query/extractOrderBy.js +57 -0
  327. package/src/table/query/extractSql.js +10 -0
  328. package/src/table/query/newParameterized.js +38 -0
  329. package/src/table/query/newSingleQuery.js +23 -0
  330. package/src/table/query/parameterized/extractParameters.js +8 -0
  331. package/src/table/query/singleQuery/columnSql/joinLegToColumnSql.js +16 -0
  332. package/src/table/query/singleQuery/columnSql/newJoinedColumnSql.js +27 -0
  333. package/src/table/query/singleQuery/columnSql/newShallowColumnSql.js +37 -0
  334. package/src/table/query/singleQuery/joinSql/joinLegToJoinSql.js +13 -0
  335. package/src/table/query/singleQuery/joinSql/joinLegToShallowJoinSql.js +9 -0
  336. package/src/table/query/singleQuery/joinSql/newDiscriminatorSql.js +11 -0
  337. package/src/table/query/singleQuery/joinSql/newShallowJoinSql.js +9 -0
  338. package/src/table/query/singleQuery/joinSql/newShallowJoinSqlCore.js +25 -0
  339. package/src/table/query/singleQuery/joinSql/oneLegToJoinSql.js +13 -0
  340. package/src/table/query/singleQuery/joinSql/oneLegToShallowJoinSql.js +10 -0
  341. package/src/table/query/singleQuery/negotiateExclusive.js +11 -0
  342. package/src/table/query/singleQuery/negotiateLimit.js +10 -0
  343. package/src/table/query/singleQuery/newColumnSql.js +8 -0
  344. package/src/table/query/singleQuery/newDiscriminatorSql.js +33 -0
  345. package/src/table/query/singleQuery/newJoinSql.js +41 -0
  346. package/src/table/query/singleQuery/newQueryContext.js +20 -0
  347. package/src/table/query/singleQuery/newWhereSql.js +19 -0
  348. package/src/table/readStream/extractLimit.js +7 -0
  349. package/src/table/readStream/extractOrderBy.js +55 -0
  350. package/src/table/readStream/mySql/newQuery.js +16 -0
  351. package/src/table/readStream/mySql/query/newSingleQuery.js +21 -0
  352. package/src/table/readStream/mySql/query/newSubQueries/joinLegToQuery.js +19 -0
  353. package/src/table/readStream/mySql/query/newSubQueries/manyLegToQuery.js +22 -0
  354. package/src/table/readStream/mySql/query/newSubQueries/newQueryCore.js +9 -0
  355. package/src/table/readStream/mySql/query/newSubQueries/newSingleQueryCore.js +18 -0
  356. package/src/table/readStream/mySql/query/newSubQueries/oneLegToQuery.js +22 -0
  357. package/src/table/readStream/mySql/query/newSubQueries.js +47 -0
  358. package/src/table/readStream/mySql/query/singleQuery/newShallowColumnSql.js +17 -0
  359. package/src/table/readStream/newQuery.js +32 -0
  360. package/src/table/readStream/newQueryStream.js +8 -0
  361. package/src/table/readStream/pg/newQuery.js +8 -0
  362. package/src/table/readStream/pg/newQueryCore.js +17 -0
  363. package/src/table/readStream/pg/query/newSingleQuery.js +19 -0
  364. package/src/table/readStream/pg/query/newSubQueries/joinLegToQuery.js +19 -0
  365. package/src/table/readStream/pg/query/newSubQueries/manyLegToQuery.js +22 -0
  366. package/src/table/readStream/pg/query/newSubQueries/oneLegToQuery.js +19 -0
  367. package/src/table/readStream/pg/query/newSubQueries.js +47 -0
  368. package/src/table/readStream/pg/query/singleQuery/newShallowColumnSql.js +19 -0
  369. package/src/table/readStreamDefault/createBatchFilter.js +39 -0
  370. package/src/table/relatedTable/aggregate/aggregateJoinSql.js +37 -0
  371. package/src/table/relatedTable/aggregate/joinSql.js +38 -0
  372. package/src/table/relatedTable/aggregate.js +48 -0
  373. package/src/table/relatedTable/all.js +24 -0
  374. package/src/table/relatedTable/any.js +70 -0
  375. package/src/table/relatedTable/childColumn.js +61 -0
  376. package/src/table/relatedTable/columnAggregate.js +16 -0
  377. package/src/table/relatedTable/columnAggregateGroup.js +59 -0
  378. package/src/table/relatedTable/joinSql.js +40 -0
  379. package/src/table/relatedTable/joinSqlArray.js +32 -0
  380. package/src/table/relatedTable/none.js +22 -0
  381. package/src/table/relatedTable/relatedColumn.js +49 -0
  382. package/src/table/relatedTable/relationFilter.js +16 -0
  383. package/src/table/relatedTable/selectSql.js +11 -0
  384. package/src/table/relatedTable/subFilter.js +16 -0
  385. package/src/table/relatedTable/where.js +50 -0
  386. package/src/table/relatedTable/whereSql.js +41 -0
  387. package/src/table/relation/manyCache/extractParentKey.js +17 -0
  388. package/src/table/relation/manyCache/synchronizeAdded.js +13 -0
  389. package/src/table/relation/manyCache/synchronizeChanged.js +31 -0
  390. package/src/table/relation/manyCache/synchronizeRemoved.js +13 -0
  391. package/src/table/relation/newExpanderCache.js +7 -0
  392. package/src/table/relation/newForeignKeyFilter.js +20 -0
  393. package/src/table/relation/newJoinLeg.js +23 -0
  394. package/src/table/relation/newManyCache.js +57 -0
  395. package/src/table/relation/newManyCacheCore.js +53 -0
  396. package/src/table/relation/newManyLeg.js +15 -0
  397. package/src/table/relation/newOneCache.js +28 -0
  398. package/src/table/relation/newOneLeg.js +25 -0
  399. package/src/table/releaseDbClient.js +15 -0
  400. package/src/table/resultToPromise.js +8 -0
  401. package/src/table/resultToRows/dbRowToRow.js +51 -0
  402. package/src/table/resultToRows/dbRowsToRows.js +13 -0
  403. package/src/table/resultToRows/decodeDbRow.js +25 -0
  404. package/src/table/resultToRows/delete/removeFromCache.js +33 -0
  405. package/src/table/resultToRows/delete.js +31 -0
  406. package/src/table/resultToRows/negotiateQueryContext.js +6 -0
  407. package/src/table/resultToRows/newDecodeDbRow.js +262 -0
  408. package/src/table/resultToRows/toDto/createDto.js +20 -0
  409. package/src/table/resultToRows/toDto/extractStrategy.js +41 -0
  410. package/src/table/resultToRows/toDto.js +92 -0
  411. package/src/table/resultToRows.js +37 -0
  412. package/src/table/rollback.js +31 -0
  413. package/src/table/rowArray/negotiateNextTick.js +11 -0
  414. package/src/table/rowArray/orderBy.js +51 -0
  415. package/src/table/rowArray.js +62 -0
  416. package/src/table/setSessionSingleton.js +5 -0
  417. package/src/table/strategyToSpan.js +49 -0
  418. package/src/table/tryGetById.js +13 -0
  419. package/src/table/tryGetFirstFromDb.js +23 -0
  420. package/src/table/tryGetFromCacheById.js +12 -0
  421. package/src/table/tryGetFromDbById/extractStrategy.js +9 -0
  422. package/src/table/tryGetFromDbById.js +19 -0
  423. package/src/table/tryGetSessionContext.js +16 -0
  424. package/src/table/tryReleaseDbClient.js +14 -0
  425. package/src/table/updateField.js +12 -0
  426. package/src/table/where.js +12 -0
  427. package/src/table.js +174 -0
  428. package/src/tedious/deleteFromSql.js +8 -0
  429. package/src/tedious/encodeBoolean.js +7 -0
  430. package/src/tedious/encodeBuffer.js +7 -0
  431. package/src/tedious/formatDateOut.js +5 -0
  432. package/src/tedious/formatJSONOut.js +5 -0
  433. package/src/tedious/getManyDto/newQuery.js +8 -0
  434. package/src/tedious/getManyDto/newQueryCore.js +18 -0
  435. package/src/tedious/getManyDto/query/newSingleQuery.js +29 -0
  436. package/src/tedious/getManyDto/query/newSubQueries/joinLegToQuery.js +16 -0
  437. package/src/tedious/getManyDto/query/newSubQueries/manyLegToQuery.js +16 -0
  438. package/src/tedious/getManyDto/query/newSubQueries/oneLegToQuery.js +19 -0
  439. package/src/tedious/getManyDto/query/newSubQueries.js +48 -0
  440. package/src/tedious/getManyDto/query/singleQuery/newShallowColumnSql.js +34 -0
  441. package/src/tedious/getManyDto.js +27 -0
  442. package/src/tedious/insert.js +13 -0
  443. package/src/tedious/insertSql.js +70 -0
  444. package/src/tedious/limitAndOffset.js +16 -0
  445. package/src/tedious/mergeSql.js +76 -0
  446. package/src/tedious/newDatabase.js +129 -0
  447. package/src/tedious/newPool.js +19 -0
  448. package/src/tedious/newTransaction.js +72 -0
  449. package/src/tedious/outputInsertedSql.js +11 -0
  450. package/src/tedious/pool/defaults.js +45 -0
  451. package/src/tedious/pool/end.js +13 -0
  452. package/src/tedious/pool/newGenericPool.js +71 -0
  453. package/src/tedious/pool/parseConnectionString.js +40 -0
  454. package/src/tedious/selectForUpdateSql.js +3 -0
  455. package/src/tedious/wrapQuery.js +112 -0
  456. package/src/toCompareObject.js +41 -0
  457. package/src/useHook.js +9 -0
  458. package/src/validateDeleteAllowed.js +49 -0
  459. package/src/validateDeleteConflict.js +92 -0
@@ -0,0 +1,110 @@
1
+ const _newTable = require('../table');
2
+ const createProviders = require('./createProviders');
3
+
4
+ function mapRoot(index, fn) {
5
+
6
+ const providers = createProviders(index);
7
+
8
+ return map(index, context, providers, fn);
9
+
10
+ function context(arg) {
11
+
12
+ const tables = {};
13
+ for (let name in context) {
14
+ if (context[name] && context[name]._dbName)
15
+ tables[name] = context[name];
16
+ }
17
+
18
+ if (arg && arg.db && typeof arg.db === 'function') {
19
+ return index({
20
+ ...arg,
21
+ db: providers(arg.db),
22
+ tables, providers
23
+ });
24
+ }
25
+ else
26
+ return index({
27
+ ...arg, tables, providers
28
+ });
29
+ }
30
+ }
31
+
32
+
33
+ function map(index, context, providers, fn) {
34
+ let next = fn({ table: newTable, ...context });
35
+
36
+ for (let name in next) {
37
+ if (next[name] && next[name]._dbName) {
38
+ context[name] = next[name];
39
+ context[name].map = mapTable.bind(null, context[name]);
40
+ }
41
+ }
42
+ context.map = map.bind(null, index, context, providers);
43
+ context.pg = connect.bind(null, 'pg');
44
+ context.postgres = connect.bind(null, 'pg');
45
+ context.mssql = connect.bind(null, 'mssql');
46
+ context.mssqlNative = connect.bind(null, 'mssqlNative');
47
+ context.mysql = connect.bind(null, 'mysql');
48
+ context.sap = connect.bind(null, 'sap');
49
+ context.oracle = connect.bind(null, 'oracle');
50
+ context.sqlite = connect.bind(null, 'sqlite');
51
+ context.http = function(url) {
52
+ return index({ db: url, providers});
53
+ };
54
+
55
+ function connect(name, ...args) {
56
+ const provider = index[name];
57
+ const pool = provider.apply(null, args);
58
+
59
+ const tables = {};
60
+ for (let name in context) {
61
+ if (context[name] && context[name]._dbName)
62
+ tables[name] = context[name];
63
+ }
64
+
65
+ return index({ db: pool, tables, providers });
66
+ }
67
+
68
+ return context;
69
+
70
+ function newTable() {
71
+ let table = _newTable.apply(null, arguments);
72
+ table.map = mapTable.bind(null, table);
73
+ return table;
74
+ }
75
+ }
76
+
77
+ function mapTable(table, fn) {
78
+ let next = fn({ column: table.column, primaryColumn: table.primaryColumn, references: table.join, hasMany, hasOne });
79
+ for (let name in next) {
80
+ if (next[name].as)
81
+ next[name] = next[name].as(name);
82
+ }
83
+
84
+ function hasMany(to) {
85
+ if (!to)
86
+ throw new Error('Missing \'to\' table');
87
+ return { by };
88
+
89
+ function by() {
90
+ const join = to.join(table).by.apply(null, arguments);
91
+ return table.hasMany(join);
92
+ }
93
+ }
94
+
95
+ function hasOne(to) {
96
+ if (!to)
97
+ throw new Error('Missing \'to\' table');
98
+ return { by };
99
+
100
+ function by() {
101
+ const join = to.join(table).by.apply(null, arguments);
102
+ return table.hasOne(join);
103
+ }
104
+ }
105
+
106
+ return table;
107
+
108
+ }
109
+
110
+ module.exports = mapRoot;
@@ -0,0 +1,9 @@
1
+ const fs = require('fs').promises;
2
+
3
+ async function merge() {
4
+ let data1 = await fs.readFile('./src/client/self.js', 'utf8');
5
+ let data2 = await fs.readFile('./src/client/index.mjs', 'utf8');
6
+ await fs.writeFile('./src/client/index.mjs', data1 + data2);
7
+ }
8
+
9
+ merge();
@@ -0,0 +1,133 @@
1
+ const _axios = require('axios');
2
+
3
+ function httpAdapter(baseURL, path, axiosInterceptor) {
4
+ //@ts-ignore
5
+ const axios = _axios.default ? _axios.default.create({ baseURL }) : _axios.create({ baseURL });
6
+ axiosInterceptor.applyTo(axios);
7
+
8
+ let c = {
9
+ get,
10
+ post,
11
+ patch,
12
+ query,
13
+ express
14
+ };
15
+
16
+ return c;
17
+
18
+ async function get() {
19
+ try {
20
+ const headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' };
21
+ const res = await axios.request(path, { headers, method: 'get' });
22
+ return res.data;
23
+ }
24
+ catch (e) {
25
+ if (e.response?.data)
26
+ throw new Error(e.response?.data.replace(/^Error: /, ''));
27
+ else
28
+ throw e;
29
+ }
30
+
31
+ }
32
+
33
+ async function patch(body) {
34
+ try {
35
+
36
+ const headers = { 'Content-Type': 'application/json' };
37
+ const res = await axios.request(path, { headers, method: 'patch', data: body });
38
+ return res.data;
39
+ }
40
+ catch (e) {
41
+ if (e.response?.data)
42
+ throw new Error(e.response?.data.replace(/^Error: /, ''));
43
+ else
44
+ throw e;
45
+ }
46
+
47
+
48
+ }
49
+
50
+ async function post(body) {
51
+ try {
52
+ const headers = { 'Content-Type': 'application/json' };
53
+ const res = await axios.request(path, { headers, method: 'post', data: body });
54
+ return res.data;
55
+ }
56
+ catch (e) {
57
+ if (e.response?.data)
58
+ throw new Error(e.response?.data.replace(/^Error: /, ''));
59
+ else throw e;
60
+ }
61
+ }
62
+
63
+
64
+ function query() {
65
+ throw new Error('Queries are not supported through http');
66
+ }
67
+
68
+ function express() {
69
+ throw new Error('Hosting in express is not supported on the client side');
70
+ }
71
+ }
72
+
73
+ function netAdapter(url, tableName, { axios, tableOptions }) {
74
+
75
+ let c = {
76
+ get,
77
+ post,
78
+ patch,
79
+ query
80
+ };
81
+
82
+ return c;
83
+
84
+ async function get() {
85
+ const adapter = await getInnerAdapter();
86
+ return adapter.get.apply(null, arguments);
87
+ }
88
+
89
+ async function patch(_body) {
90
+ const adapter = await getInnerAdapter();
91
+ return adapter.patch.apply(null, arguments);
92
+ }
93
+
94
+ async function post(_body) {
95
+ const adapter = await getInnerAdapter();
96
+ return adapter.post.apply(null, arguments);
97
+ }
98
+
99
+ async function query() {
100
+ const adapter = await getInnerAdapter();
101
+ return adapter.query.apply(null, arguments);
102
+ }
103
+
104
+ async function getInnerAdapter() {
105
+ const db = await getDb();
106
+ if (typeof db === 'string') {
107
+ return httpAdapter(db, `?table=${tableName}`, axios);
108
+ }
109
+ else if (db && db.transaction) {
110
+ return db.hostLocal({ ...tableOptions, db, table: url });
111
+ }
112
+ else
113
+ throw new Error('Invalid arguments');
114
+ }
115
+
116
+ async function getDb() {
117
+ let db = tableOptions.db;
118
+ if (db.transaction)
119
+ return db;
120
+ if (typeof db === 'function') {
121
+ let dbPromise = db();
122
+ if (dbPromise.then)
123
+ db = await dbPromise;
124
+ else
125
+ db = dbPromise;
126
+ }
127
+
128
+ return db;
129
+ }
130
+
131
+ }
132
+
133
+ module.exports = netAdapter;
@@ -0,0 +1,12 @@
1
+ import commonjs from '@rollup/plugin-commonjs';
2
+ import nodeResolve from '@rollup/plugin-node-resolve';
3
+
4
+ export default {
5
+ input: './src/client/index.js',
6
+ output: {
7
+ file: './src/client/index.mjs',
8
+ format: 'esm'
9
+ },
10
+ plugins: [commonjs(), nodeResolve({browser: true})],
11
+ external: ['vue']
12
+ };
@@ -0,0 +1,4 @@
1
+ void !function() {
2
+ typeof self === 'undefined' && typeof global === 'object'
3
+ ? global.self = global : null;
4
+ }();
@@ -0,0 +1,22 @@
1
+ let dateToISOString = require('../dateToISOString');
2
+ const isNode = (typeof window === 'undefined');
3
+
4
+ function stringify(value) {
5
+ return JSON.stringify(value, replacer);
6
+ }
7
+
8
+ function replacer(key, value) {
9
+ if (isNode && isNodeBuffer(value))
10
+ return value.toString('base64');
11
+ // @ts-ignore
12
+ else if (value instanceof Date && !isNaN(value))
13
+ return dateToISOString(value);
14
+ else
15
+ return value;
16
+ }
17
+
18
+ function isNodeBuffer(object) {
19
+ return Buffer.isBuffer(object);
20
+ }
21
+
22
+ module.exports = stringify;
@@ -0,0 +1,30 @@
1
+ const stringify = require('./stringify');
2
+ const { v4: uuid } = require('uuid');
3
+
4
+ function toKeyPositionMap(rows, options) {
5
+ return rows.reduce((map, element, i) => {
6
+ if (options && options.keys && element === Object(element)) {
7
+ let key = [];
8
+ for (let i = 0; i < options.keys.length; i++) {
9
+ let keyName = options.keys[i].name;
10
+ key.push(negotiateTempKey(element[keyName]));
11
+ }
12
+ map[stringify(key)] = i;
13
+ }
14
+ else if ('id' in element)
15
+ map[stringify(element.id)] = i;
16
+ else
17
+ map[i] = i;
18
+ return map;
19
+ }, {});
20
+
21
+ }
22
+
23
+ function negotiateTempKey(value) {
24
+ if (value === undefined)
25
+ return `~${uuid()}`;
26
+ else
27
+ return value;
28
+ }
29
+
30
+ module.exports = toKeyPositionMap;
package/src/clsTest.js ADDED
@@ -0,0 +1,79 @@
1
+ let cls = require('node-cls');
2
+ const fs = require('fs');
3
+ const log = (str) => fs.writeSync(1, `${str}\n`);
4
+
5
+ function begin(id) {
6
+ return new Promise((resolve) => {
7
+ let context = cls.get();
8
+ context.id = id;
9
+ resolve();
10
+ });
11
+ }
12
+
13
+ function getById() {
14
+ return new Promise((resolve) => {
15
+ let context = cls.get();
16
+ context.id;
17
+ resolve(context.id);
18
+ });
19
+ }
20
+
21
+ async function getFromDb() {
22
+ let c = cls.create();
23
+ await c.start();
24
+ await begin(1);
25
+ await new Promise((resolve) => {
26
+ setTimeout(resolve(), 500);
27
+ });
28
+ await getFromDb2();
29
+
30
+ let c3 = cls.create();
31
+ await c3.start();
32
+ await begin(3);
33
+ let id3 = await getById();
34
+ if (id3 !== 3)
35
+ throw new Error('3 Unexpected context id : ' + id3);
36
+ cls.exit();
37
+
38
+ await getFromDb3();
39
+
40
+ let id = await getById();
41
+ if (id !== 1)
42
+ throw new Error('1 Unexpected context id : ' + id);
43
+ cls.exit();
44
+ }
45
+
46
+ function getFromDb2() {
47
+ return new Promise((resolve) => {
48
+ setTimeout(async () => {
49
+ let c2 = cls.create();
50
+ await c2.start();
51
+ await begin(2);
52
+ let id2 = await getById();
53
+ if (id2 !== 2)
54
+ throw new Error('2 Unexpected context id : ' + id2);
55
+ id2 = cls.active.id;
56
+ if (id2 !== 2)
57
+ throw new Error('2 Unexpected context id : ' + id2);
58
+ cls.exit();
59
+ resolve();
60
+ }, 500);
61
+ });
62
+ }
63
+
64
+ async function getFromDb3() {
65
+ let c3 = cls.create();
66
+ await c3.start();
67
+ await begin(3);
68
+ let id3 = await getById();
69
+ if (id3 !== 3)
70
+ throw new Error('3 Unexpected context id : ' + id3);
71
+ cls.exit();
72
+ }
73
+
74
+
75
+ async function testStart() {
76
+ await getFromDb();
77
+ }
78
+
79
+ testStart().then(() => log('done'), (e) => log(e.stack));
@@ -0,0 +1,23 @@
1
+ function negotiateForwardProperty(oldDomain, newDomain, propertyName) {
2
+ if(newDomain[propertyName]) return;
3
+ if (propertyName === 'rdb') return;
4
+ Object.defineProperty(newDomain, propertyName, {
5
+ enumerable: true,
6
+ get: createGetter(oldDomain, propertyName),
7
+ set: createSetter(oldDomain, propertyName)
8
+ });
9
+ }
10
+
11
+ function createGetter(oldDomain, propName) {
12
+ return function() {
13
+ return oldDomain[propName];
14
+ };
15
+ }
16
+
17
+ function createSetter(oldDomain, propName) {
18
+ return function(value) {
19
+ oldDomain[propName] = value;
20
+ };
21
+ }
22
+
23
+ module.exports = negotiateForwardProperty;
@@ -0,0 +1,31 @@
1
+ let useHook = require('./useHook');
2
+ let cls;
3
+ var Domain = require('domain');
4
+ var negotiateForwardProperty = require('./createDomain/negotiateForwardProperty');
5
+
6
+ function createDomain() {
7
+ var oldDomain = Domain.active || {};
8
+ var domain = Domain.create();
9
+ var ownProperties = Object.getOwnPropertyNames(oldDomain);
10
+ ownProperties.forEach(function(propName) {
11
+ negotiateForwardProperty(oldDomain, domain, propName);
12
+ });
13
+ return domain;
14
+ }
15
+
16
+ function createOnContext() {
17
+ if (!cls)
18
+ cls = require('node-cls');
19
+ return cls.create('rdb');
20
+ }
21
+
22
+
23
+ function _createDomain() {
24
+ if (useHook())
25
+ return createOnContext();
26
+ else
27
+ return createDomain();
28
+
29
+ }
30
+
31
+ module.exports = _createDomain;
@@ -0,0 +1,25 @@
1
+ function dateToISOString(date) {
2
+ let tzo = -date.getTimezoneOffset();
3
+ let dif = tzo >= 0 ? '+' : '-';
4
+
5
+ function pad(num) {
6
+ let norm = Math.floor(Math.abs(num));
7
+ return (norm < 10 ? '0' : '') + norm;
8
+ }
9
+
10
+ function padMilli(d) {
11
+ return (d.getMilliseconds() + '').padStart(3, '0');
12
+ }
13
+
14
+ return date.getFullYear() +
15
+ '-' + pad(date.getMonth() + 1) +
16
+ '-' + pad(date.getDate()) +
17
+ 'T' + pad(date.getHours()) +
18
+ ':' + pad(date.getMinutes()) +
19
+ ':' + pad(date.getSeconds()) +
20
+ '.' + padMilli(date) +
21
+ dif + pad(tzo / 60) +
22
+ ':' + pad(tzo % 60);
23
+ }
24
+
25
+ module.exports = dateToISOString;
@@ -0,0 +1,46 @@
1
+ function emitEvent() {
2
+ var callbacks = [];
3
+ var emit = function() {
4
+
5
+ var copy = callbacks.slice(0, callbacks.length);
6
+ var result = [];
7
+ for (var i = 0; i < copy.length; i++) {
8
+ var callback = copy[i];
9
+ result.push(callback.apply(null,arguments));
10
+ }
11
+ return result;
12
+ };
13
+
14
+ emit.add = function(callback) {
15
+ callbacks.push(callback);
16
+ };
17
+
18
+ emit.tryAdd = function(callback) {
19
+ if (callback)
20
+ emit.add(callback);
21
+ };
22
+
23
+ emit.remove = function(callback) {
24
+ for (var i = 0; i < callbacks.length; i++) {
25
+ if(callbacks[i] === callback){
26
+ callbacks.splice(i,1);
27
+ return;
28
+ }
29
+ }
30
+ };
31
+
32
+ emit.tryRemove = function(callback) {
33
+ if(callback)
34
+ emit.remove(callback);
35
+ };
36
+
37
+ emit.clear = function() {
38
+ callbacks.splice(0, callbacks.length);
39
+ };
40
+
41
+ emit.callbacks = callbacks;
42
+
43
+ return emit;
44
+ }
45
+
46
+ module.exports = emitEvent;
@@ -0,0 +1,35 @@
1
+ var negotiateRawSqlFilter = require('./table/column/negotiateRawSqlFilter');
2
+ var parameterized = require('./table/query/newParameterized')('');
3
+ function emptyFilter() {
4
+ return emptyFilter.and.apply(null, arguments);
5
+ }
6
+
7
+ emptyFilter.sql = parameterized.sql;
8
+ emptyFilter.parameters = parameterized.parameters;
9
+
10
+ emptyFilter.and = function(other) {
11
+ other = negotiateRawSqlFilter(other);
12
+ for (var i = 1; i < arguments.length; i++) {
13
+ other = other.and(arguments[i]);
14
+ }
15
+ return other;
16
+ };
17
+
18
+ emptyFilter.or = function(other) {
19
+ other = negotiateRawSqlFilter(other);
20
+ for (var i = 1; i < arguments.length; i++) {
21
+ other = other.or(arguments[i]);
22
+ }
23
+ return other;
24
+ };
25
+
26
+ emptyFilter.not = function(other) {
27
+ other = negotiateRawSqlFilter(other).not();
28
+ for (var i = 1; i < arguments.length; i++) {
29
+ other = other.and(arguments[i]);
30
+ }
31
+ return other;
32
+
33
+ };
34
+
35
+ module.exports = emptyFilter;
package/src/flags.js ADDED
@@ -0,0 +1,6 @@
1
+ let flags = {
2
+ useProxy: true,
3
+ useLazyDefaults: true
4
+ };
5
+
6
+ module.exports = flags;
@@ -0,0 +1,24 @@
1
+ function fromCompareObject(object) {
2
+ if (object === null || object === undefined) return object;
3
+ if (object.__patchType === 'Array') {
4
+ let copy = [];
5
+ let i = 0;
6
+ for (let id in object) {
7
+ if (id !== '__patchType') {
8
+ copy[i] = fromCompareObject(object[id]);
9
+ i++;
10
+ }
11
+ }
12
+ return copy;
13
+ } else if (object === Object(object)) {
14
+ let copy = {};
15
+ for (let name in object) {
16
+ if (name !== '__patchType')
17
+ copy[name] = fromCompareObject(object[name]);
18
+ }
19
+ return copy;
20
+ }
21
+ return object;
22
+ }
23
+
24
+ module.exports = fromCompareObject;