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,32 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg id="OrangeORM" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300">
3
+ <defs>
4
+ <style>#boats path {stroke-width: 0px}#name path {fill: #64b756}.lines {fill: #f7931e}.boat1 {fill: #fde4c7}.boat2 {fill: #fcd7ab}.boat3 {fill: #fbc98f}.boat4 {fill: #fabb72}.boat5 {fill: #f9ae56}.boat6 {fill: #f8a13a}#shell {fill: none;stroke-miterlimit: 10;stroke: #f7931e;stroke-linecap: round;stroke-width: 11px}</style>
5
+ </defs>
6
+ <g id="name">
7
+ <path d="M62.78,214.16c0,7.33-5.51,12.94-13.01,12.94s-13.01-5.61-13.01-12.94,5.51-12.94,13.01-12.94,13.01,5.61,13.01,12.94ZM58.95,214.16c0-5.54-3.82-9.42-9.19-9.42s-9.19,3.89-9.19,9.42,3.82,9.42,9.19,9.42,9.19-3.89,9.19-9.42Z"/>
8
+ <path d="M72.04,201.67c3.04,0,4.99.37,6.6,1.46,2.74,1.83,2.96,4.79,2.96,5.87,0,3.59-2.21,6.21-5.55,6.96l7.8,10.66h-4.61l-7.16-10.21h-.67v10.21h-3.82v-24.95h4.46ZM71.4,213.11h1.2c1.05,0,5.32-.11,5.32-4.08,0-3.51-3.34-3.85-5.21-3.85h-1.31v7.93Z"/>
9
+ <path d="M102.29,220.59h-10.69l-2.74,6.02h-4.12l12.45-26.4,11.85,26.4h-4.12l-2.62-6.02ZM100.75,217l-3.71-8.45-3.86,8.45h7.57Z"/>
10
+ <path d="M153.09,213.63h10.31v.19c0,4.26-1.27,7.74-3.71,10.1-2.59,2.51-5.66,3.18-8.51,3.18-3.64,0-6.22-1.05-8.51-3.4-2.44-2.51-3.71-5.83-3.71-9.42,0-3.89,1.57-7.26,3.64-9.31,2.14-2.17,5.55-3.74,9.41-3.74,2.25,0,4.57.49,6.52,1.57,2.06,1.16,3.34,2.62,4.05,3.74l-3.04,2.13c-.75-1.05-1.87-2.17-3.07-2.84-1.39-.82-2.89-1.08-4.42-1.08-3.26,0-5.36,1.35-6.6,2.58-1.65,1.65-2.66,4.3-2.66,6.99,0,2.51.94,5.01,2.59,6.77,1.72,1.83,3.86,2.51,6.26,2.51,2.17,0,3.97-.64,5.59-2.21,1.39-1.35,1.95-2.8,2.1-4.23h-6.22v-3.52Z"/>
11
+ <path d="M181.99,205.25h-9.97v6.32h9.67v3.59h-9.67v7.85h9.97v3.59h-13.8v-24.95h13.8v3.59Z"/>
12
+ <path d="M218.5,214.16c0,7.33-5.51,12.94-13.01,12.94s-13.01-5.61-13.01-12.94,5.51-12.94,13.01-12.94,13.01,5.61,13.01,12.94ZM214.67,214.16c0-5.54-3.82-9.42-9.19-9.42s-9.19,3.89-9.19,9.42,3.82,9.42,9.19,9.42,9.19-3.89,9.19-9.42Z"/>
13
+ <path d="M227.76,201.67c3.04,0,4.99.37,6.6,1.46,2.74,1.83,2.96,4.79,2.96,5.87,0,3.59-2.21,6.21-5.55,6.96l7.8,10.66h-4.61l-7.16-10.21h-.67v10.21h-3.82v-24.95h4.46ZM227.12,213.11h1.2c1.05,0,5.32-.11,5.32-4.08,0-3.51-3.34-3.85-5.21-3.85h-1.31v7.93Z"/>
14
+ <path d="M242.57,226.61l5.25-26.82,8.7,19.37,8.77-19.37,4.72,26.82h-3.9l-2.55-15.03-7.27,16.19-7.2-16.23-2.62,15.07h-3.9Z"/>
15
+ <path d="M112.34,226.74v-43.57l18.26,43.36v-24.95h3.85v43.42l-18.26-43.36v25.1h-3.85Z"/>
16
+ </g>
17
+ <g>
18
+ <path class="lines" d="M109.51,179.5H42.49c-3.04,0-5.5,2.46-5.5,5.5s2.46,5.5,5.5,5.5h67.03v-11Z"/>
19
+ <path class="lines" d="M265.82,179.5H114.02l3.97,11h147.83c3.04,0,5.5-2.46,5.5-5.5s-2.46-5.5-5.5-5.5Z"/>
20
+ <path class="lines" d="M265.82,234.06h-128.65v11h128.65c3.04,0,5.5-2.46,5.5-5.5s-2.46-5.5-5.5-5.5Z"/>
21
+ <path class="lines" d="M127.22,234.06H42.49c-3.04,0-5.5,2.46-5.5,5.5s2.46,5.5,5.5,5.5h88.7l-3.97-11Z"/>
22
+ </g>
23
+ <path id="shell" d="M266.1,164.61c0-61.4-50.53-111.93-111.93-111.93s-111.93,50.53-111.93,111.93"/>
24
+ <g id="boats">
25
+ <path class="boat1" d="M163.25,160.02l75.59-43.64c3.34-1.93,7.63-.64,9.33,2.82,2.98,6.07,5.36,12.42,7.11,18.97,1.75,6.54,2.87,13.24,3.32,19.98.26,3.85-2.81,7.11-6.66,7.11h-87.28c-2.87,0-3.89-3.8-1.4-5.24Z"/>
26
+ <path class="boat2" d="M159.42,156.19l43.64-75.59c1.94-3.37,6.33-4.34,9.55-2.17,5.59,3.76,10.81,8.06,15.58,12.83,4.77,4.77,9.07,9.99,12.83,15.58,2.17,3.23,1.19,7.61-2.17,9.55l-75.59,43.64c-2.49,1.44-5.27-1.35-3.84-3.84Z"/>
27
+ <path class="boat3" d="M154.18,154.78v-87.28c0-3.86,3.26-6.93,7.11-6.66,6.75.46,13.44,1.57,19.98,3.32,6.54,1.75,12.9,4.14,18.97,7.11,3.46,1.7,4.75,5.99,2.82,9.33l-43.64,75.59c-1.44,2.49-5.24,1.47-5.24-1.4Z"/>
28
+ <path class="boat4" d="M148.94,156.19l-43.64-75.59c-1.93-3.34-.64-7.63,2.82-9.33,6.07-2.98,12.42-5.36,18.97-7.11,6.54-1.75,13.24-2.87,19.98-3.32,3.85-.26,7.11,2.81,7.11,6.66v87.28c0,2.87-3.8,3.89-5.24,1.4Z"/>
29
+ <path class="boat5" d="M145.1,160.02l-75.59-43.64c-3.37-1.94-4.34-6.33-2.17-9.55,3.76-5.59,8.06-10.81,12.83-15.58,4.77-4.77,9.99-9.07,15.58-12.83,3.23-2.17,7.61-1.19,9.55,2.17l43.64,75.59c1.44,2.49-1.35,5.27-3.84,3.84Z"/>
30
+ <path class="boat6" d="M143.7,165.26H56.42c-3.86,0-6.93-3.26-6.66-7.11.46-6.75,1.57-13.44,3.32-19.98,1.75-6.54,4.14-12.9,7.11-18.97,1.7-3.46,5.99-4.75,9.33-2.82l75.59,43.64c2.49,1.44,1.47,5.24-1.4,5.24Z"/>
31
+ </g>
32
+ </svg>
Binary file
package/package.json ADDED
@@ -0,0 +1,139 @@
1
+ {
2
+ "name": "orange-orm",
3
+ "version": "3.10.2",
4
+ "main": "./src/index.js",
5
+ "browser": "./src/client/index.mjs",
6
+ "bin": {
7
+ "orange-orm": "bin/rdb.js"
8
+ },
9
+ "title": "Orange ORM",
10
+ "description": "Object Relational Mapper",
11
+ "types": "./src/index.d.ts",
12
+ "keywords": [
13
+ "typescript orm",
14
+ "orm",
15
+ "sql",
16
+ "mySql",
17
+ "SQLite",
18
+ "MySQL",
19
+ "mssql",
20
+ "Microsoft Sql Server",
21
+ "PostgreSql",
22
+ "Postgres",
23
+ "pg",
24
+ "sap",
25
+ "sapase",
26
+ "Oracle",
27
+ "rdb",
28
+ "Orange ORM",
29
+ "active record"
30
+ ],
31
+ "authors": [
32
+ "Lars-Erik Roald <lars.roald@gmail.com>"
33
+ ],
34
+ "license": "ISC",
35
+ "codeOfConduct": "https://github.com/alfateam/orange-orm/blob/master/docs/CODE_OF_CONDUCT.md",
36
+ "contributing": "https://github.com/alfateam/orange-orm/blob/master/CONTRIBUTING.md",
37
+ "funding": {
38
+ "type": "github",
39
+ "url": "https://github.com/sponsors/lroal"
40
+ },
41
+ "scripts": {
42
+ "test": "vitest run --threads=false",
43
+ "coverage": "vitest run --coverage.enabled --coverage.reporter='text-summary' --threads=false",
44
+ "testw": "vitest --threads=false update",
45
+ "tscheck": "tsc ./src/index.d.ts --module commonjs --target es2022 --noEmit true --strict true --esModuleInterop true",
46
+ "concat": "node ./src/client/merge.js",
47
+ "build": "rollup -c ./src/client/rollup.config.js && npm run concat",
48
+ "lint": "eslint ./",
49
+ "fix": "eslint ./ --fix",
50
+ "owasp": "owasp-dependency-check --project \"MY_PROJECT\" --scan \"package-lock.json\" --exclude \"dependency-check-bin\" --out \"owasp\" --format HTML"
51
+ },
52
+ "dependencies": {
53
+ "@lroal/on-change": "^4.0.2",
54
+ "@tediousjs/connection-string": "^0.4.1",
55
+ "@types/express": "^4.17.13",
56
+ "@types/oracledb": "^6.0.4",
57
+ "@types/tedious": "^4.0.14",
58
+ "ajv": "^6.10.2",
59
+ "axios": "^1.6.2",
60
+ "deferred": "^0.7.5",
61
+ "fast-json-patch": "^3.1.1",
62
+ "findup-sync": "^5.0.0",
63
+ "glob": "^10.3.4",
64
+ "module-definition": "^4.0.0",
65
+ "node-cls": "^1.0.5",
66
+ "promise": "^8.0.3",
67
+ "rfdc": "^1.2.0",
68
+ "uuid": "^8.3.2"
69
+ },
70
+ "peerDependencies": {
71
+ "msnodesqlv8": "^4.1.0",
72
+ "mysql2": "^2.2.5 || ^3.9.4",
73
+ "oracledb": "^6.3.0",
74
+ "pg": "^8.5.1",
75
+ "pg-native": "^3.0.0",
76
+ "pg-query-stream": "^3.3.2",
77
+ "sqlite3": "^5.0.2",
78
+ "tedious": "^15.1.2 || ^16.0.0 || ^18.1.0"
79
+ },
80
+ "peerDependenciesMeta": {
81
+ "pg": {
82
+ "optional": true
83
+ },
84
+ "pg-query-stream": {
85
+ "optional": true
86
+ },
87
+ "mysql2": {
88
+ "optional": true
89
+ },
90
+ "sqlite3": {
91
+ "optional": true
92
+ },
93
+ "pg-native": {
94
+ "optional": true
95
+ },
96
+ "msnodesqlv8": {
97
+ "optional": true
98
+ },
99
+ "tedious": {
100
+ "optional": true
101
+ }
102
+ },
103
+ "devDependencies": {
104
+ "@rollup/plugin-commonjs": "^21.0.1",
105
+ "@rollup/plugin-node-resolve": "^13.0.0",
106
+ "@typescript-eslint/eslint-plugin": "^5.42.1",
107
+ "@typescript-eslint/parser": "^5.42.1",
108
+ "@vitest/coverage-v8": "^0.34.1",
109
+ "cors": "^2.8.5",
110
+ "eslint": "^8.6.0",
111
+ "eslint-plugin-jest": "^27.1.7",
112
+ "express": "^4.18.2",
113
+ "msnodesqlv8": "^4.1.0",
114
+ "mysql2": "^3.9.4",
115
+ "oracledb": "^6.3.0",
116
+ "owasp-dependency-check": "^0.0.21",
117
+ "pg": "^8.5.1",
118
+ "pg-query-stream": "^3.3.2",
119
+ "rollup": "^2.52.7",
120
+ "sqlite3": "^5.0.2",
121
+ "tedious": "^18.1.0",
122
+ "typescript": "^5.4.5",
123
+ "vitest": "^0.34.1"
124
+ },
125
+ "engines": {
126
+ "node": ">= 8.0.0"
127
+ },
128
+ "repository": {
129
+ "type": "git",
130
+ "url": "git@github.com:alfateam/orange-orm.git"
131
+ },
132
+ "homepage": "https://orange-orm.io",
133
+ "jshintConfig": {
134
+ "asi": true,
135
+ "eqnull": true,
136
+ "undef": true,
137
+ "node": true
138
+ }
139
+ }
@@ -0,0 +1,105 @@
1
+ const fastjson = require('fast-json-patch');
2
+ let { inspect } = require('util');
3
+ let assert = require('assert');
4
+ let fromCompareObject = require('./fromCompareObject');
5
+ let toCompareObject = require('./toCompareObject');
6
+
7
+ function applyPatch({ options = {} }, dto, changes, column) {
8
+ let dtoCompare = toCompareObject(dto);
9
+ changes = validateConflict(dtoCompare, changes);
10
+ fastjson.applyPatch(dtoCompare, changes, true, true);
11
+
12
+ let result = fromCompareObject(dtoCompare);
13
+
14
+ if (Array.isArray(dto))
15
+ dto.length = 0;
16
+ else
17
+ for (let name in dto) {
18
+ delete dto[name];
19
+ }
20
+
21
+ for (let name in result) {
22
+ dto[name] = result[name];
23
+ }
24
+
25
+ return dto;
26
+
27
+ function validateConflict(object, changes) {
28
+ return changes.filter(change => {
29
+ let expectedOldValue = change.oldValue;
30
+ const option = getOption(change.path);
31
+ let readonly = option.readonly;
32
+ if (readonly) {
33
+ const e = new Error(`Cannot update column ${change.path.replace('/', '')} because it is readonly`);
34
+ // @ts-ignore
35
+ e.status = 405;
36
+ throw e;
37
+ }
38
+ let concurrency = option.concurrency || 'optimistic';
39
+ if ((concurrency === 'optimistic') || (concurrency === 'skipOnConflict')) {
40
+ let oldValue = getOldValue(object, change.path);
41
+ try {
42
+ if (column?.tsType === 'DateColumn') {
43
+ assertDatesEqual(oldValue, expectedOldValue);
44
+ }
45
+ else
46
+ assert.deepEqual(oldValue, expectedOldValue);
47
+ }
48
+ catch (e) {
49
+ if (concurrency === 'skipOnConflict')
50
+ return false;
51
+ throw new Error(`The field ${change.path.replace('/', '')} was changed by another user. Expected ${inspect(fromCompareObject(expectedOldValue), false, 10)}, but was ${inspect(fromCompareObject(oldValue), false, 10)}.`);
52
+ }
53
+ }
54
+ return true;
55
+ });
56
+
57
+ function getOldValue(obj, path) {
58
+ let splitPath = path.split('/');
59
+ splitPath.shift();
60
+ return splitPath.reduce(extract, obj);
61
+
62
+ function extract(obj, name) {
63
+ if (obj === Object(obj))
64
+ return obj[name];
65
+ return;
66
+ }
67
+ }
68
+
69
+ }
70
+
71
+ function getOption(path) {
72
+ let splitPath = path.split('/');
73
+ splitPath.shift();
74
+ return splitPath.reduce(extract, options);
75
+
76
+ function extract(obj, name) {
77
+ if (Array.isArray(obj))
78
+ return obj[0] || options;
79
+ if (obj === Object(obj))
80
+ return obj[name] || options;
81
+ return obj;
82
+ }
83
+
84
+ }
85
+ }
86
+
87
+ function assertDatesEqual(date1, date2) {
88
+ if (date1 && date2) {
89
+ const parts1 = date1.split('T');
90
+ const time1parts = (parts1[1] || '').split(/[-+.]/);
91
+ const parts2 = date2.split('T');
92
+ const time2parts = (parts2[1] || '').split(/[-+.]/);
93
+ while (time1parts.length !== time2parts.length) {
94
+ if (time1parts.length > time2parts.length)
95
+ time1parts.pop();
96
+ else if (time1parts.length < time2parts.length)
97
+ time2parts.pop();
98
+ }
99
+ date1 = `${parts1[0]}T${time1parts[0]}`;
100
+ date2 = `${parts2[0]}T${time2parts[0]}`;
101
+ }
102
+ assert.deepEqual(date1, date2);
103
+ }
104
+
105
+ module.exports = applyPatch;
@@ -0,0 +1,46 @@
1
+ class InterceptorProxy {
2
+ constructor() {
3
+ this.requestInterceptors = [];
4
+ this.responseInterceptors = [];
5
+ }
6
+
7
+ get request() {
8
+ return {
9
+ use: (onFulfilled, onRejected) => {
10
+ const id = Math.random().toString(36).substr(2, 9); // unique id
11
+ this.requestInterceptors.push({ id, onFulfilled, onRejected });
12
+ return id;
13
+ },
14
+ eject: (id) => {
15
+ this.requestInterceptors = this.requestInterceptors.filter(interceptor => interceptor.id !== id);
16
+ }
17
+ };
18
+ }
19
+
20
+ get response() {
21
+ return {
22
+ use: (onFulfilled, onRejected) => {
23
+ const id = Math.random().toString(36).substr(2, 9); // unique id
24
+ this.responseInterceptors.push({ id, onFulfilled, onRejected });
25
+ return id;
26
+ },
27
+ eject: (id) => {
28
+ this.responseInterceptors = this.responseInterceptors.filter(interceptor => interceptor.id !== id);
29
+ }
30
+ };
31
+ }
32
+
33
+ applyTo(axiosInstance) {
34
+ for (const { onFulfilled, onRejected } of this.requestInterceptors) {
35
+ axiosInstance.interceptors.request.use(onFulfilled, onRejected);
36
+ }
37
+
38
+ for (const { onFulfilled, onRejected } of this.responseInterceptors) {
39
+ axiosInstance.interceptors.response.use(onFulfilled, onRejected);
40
+ }
41
+ }
42
+ }
43
+
44
+ module.exports = function create() {
45
+ return new InterceptorProxy();
46
+ };
@@ -0,0 +1,72 @@
1
+ function map(index, _fn) {
2
+ const handler = {
3
+ get(target, prop) {
4
+ if (prop === 'map') {
5
+ return () => {
6
+ return new Proxy(onFinal, handler);
7
+ };
8
+ } else if (typeof target[prop] !== 'undefined') {
9
+ return target[prop];
10
+ } else {
11
+ return () => {
12
+ return new Proxy({}, handler);
13
+ };
14
+ }
15
+ },
16
+ apply(target, _thisArg, argumentsList) {
17
+ if (target === onFinal) {
18
+ return target(...argumentsList);
19
+ } else {
20
+ return new Proxy({}, handler);
21
+ }
22
+ },
23
+ set(target, prop, value) {
24
+ target[prop] = value;
25
+ return true;
26
+ },
27
+ };
28
+
29
+ function dbMap(fn) {
30
+ return fn(dbMap);
31
+ }
32
+
33
+ dbMap.http = (url) => url;
34
+ dbMap.pg = throwDb;
35
+ dbMap.postgres = throwDb;
36
+ dbMap.mssql = throwDb;
37
+ dbMap.mssqlNative = throwDb;
38
+ dbMap.mysql = throwDb;
39
+ dbMap.sap = throwDb;
40
+ dbMap.oracle = throwDb;
41
+ dbMap.sqlite = throwDb;
42
+
43
+ function throwDb() {
44
+ throw new Error('Cannot create pool for database outside node');
45
+ }
46
+
47
+ function onFinal(arg) {
48
+ if (arg && arg.db && typeof arg.db === 'function') {
49
+ return index({
50
+ ...arg,
51
+ db: dbMap(arg.db),
52
+ providers: dbMap
53
+ });
54
+ }
55
+
56
+ return index({ ...arg, providers: dbMap });
57
+ }
58
+
59
+ onFinal.http = (url) => index({ db: url, providers: dbMap });
60
+ onFinal.pg = () => index({ db: throwDb, providers: dbMap });
61
+ onFinal.postgres = () => index({ db: throwDb, providers: dbMap });
62
+ onFinal.mssql = () => index({ db: throwDb, providers: dbMap });
63
+ onFinal.mssqlNative = () => index({ db: throwDb, providers: dbMap });
64
+ onFinal.mysql = () => index({ db: throwDb, providers: dbMap });
65
+ onFinal.sap = () => index({ db: throwDb, providers: dbMap });
66
+ onFinal.oracle = () => index({ db: throwDb, providers: dbMap });
67
+ onFinal.sqlite = () => index({ db: throwDb, providers: dbMap });
68
+
69
+ return new Proxy(onFinal, handler);
70
+ }
71
+
72
+ module.exports = map;
@@ -0,0 +1,122 @@
1
+ const jsonpatch = require('fast-json-patch');
2
+ let dateToIsoString = require('../dateToISOString');
3
+ let stringify = require('./stringify');
4
+ let { v4: uuid } = require('uuid');
5
+
6
+ module.exports = function createPatch(original, dto, options) {
7
+ let subject = toCompareObject({ d: original }, options, true);
8
+ let clonedDto = toCompareObject({ d: dto }, options, true);
9
+ let keyPositionMap = toKeyPositionMap(dto);
10
+ let observer = jsonpatch.observe(subject);
11
+ subject.d = clonedDto.d;
12
+ let changes = jsonpatch.generate(observer);
13
+ let clonedOriginal = toCompareObject(original, options);
14
+ let {inserted, deleted, updated} = splitChanges(changes);
15
+ updated.sort(comparePatch);
16
+ return [...inserted, ...updated, ...deleted];
17
+
18
+ function splitChanges(changes) {
19
+ let inserted = [];
20
+ let deleted = [];
21
+ let updated = [];
22
+ for (let change of changes) {
23
+ change.path = change.path.substring(2);
24
+ if (change.op === 'add' && change.path.split('/').length === 2) {
25
+ inserted.push(change);
26
+ }
27
+ else if (change.op === 'remove' && change.path.split('/').length === 2) {
28
+ addOldValue(change);
29
+ deleted.push(change);
30
+ } else {
31
+ addOldValue(change);
32
+ updated.push(change);
33
+ }
34
+ }
35
+ return { inserted, updated, deleted};
36
+ }
37
+
38
+ function addOldValue(change) {
39
+ if (change.op === 'remove' || change.op === 'replace') {
40
+ let splitPath = change.path.split('/');
41
+ splitPath.shift();
42
+ change.oldValue = splitPath.reduce(extract, clonedOriginal);
43
+ }
44
+ else
45
+ return change;
46
+
47
+ function extract(obj, element) {
48
+ return obj[element];
49
+ }
50
+
51
+ return change;
52
+ }
53
+
54
+ function toKeyPositionMap(rows) {
55
+ return rows.reduce((map, element, i) => {
56
+ if (options && options.keys && element === Object(element)) {
57
+ let key = [];
58
+ for (let i = 0; i < options.keys.length; i++) {
59
+ let keyName = options.keys[i].name;
60
+ key.push(negotiateTempKey(element[keyName]));
61
+ }
62
+ map[stringify(key)] = i;
63
+ }
64
+ else if ('id' in element)
65
+ map[stringify([element.id])] = i;
66
+ else
67
+ map[i] = i;
68
+ return map;
69
+ }, {});
70
+
71
+ }
72
+
73
+ function toCompareObject(object, options, isRoot) {
74
+ if (Array.isArray(object)) {
75
+ let copy = { __patchType: 'Array' };
76
+ for (let i = 0; i < object.length; i++) {
77
+ let element = toCompareObject(object[i], options);
78
+ if (options && options.keys && element === Object(element)) {
79
+ let key = [];
80
+ for (let i = 0; i < options.keys.length; i++) {
81
+ let keyName = options.keys[i].name;
82
+ key.push(negotiateTempKey(element[keyName]));
83
+ }
84
+ copy[stringify(key)] = element;
85
+ }
86
+ else if (element === Object(element) && 'id' in element)
87
+ copy[stringify([element.id])] = element;
88
+ else
89
+ copy[i] = element;
90
+ }
91
+ return copy;
92
+ }
93
+ else if (isValidDate(object))
94
+ return dateToIsoString(object);
95
+ else if (object === Object(object)) {
96
+ let copy = {};
97
+ for (let name in object) {
98
+ copy[name] = toCompareObject(object[name], isRoot ? options : options && options.relations && options.relations[name]);
99
+ }
100
+ return copy;
101
+ }
102
+ return object;
103
+ }
104
+
105
+ function isValidDate(d) {
106
+ return d instanceof Date && !isNaN(d);
107
+ }
108
+
109
+ function negotiateTempKey(value) {
110
+ if (value === undefined)
111
+ return `~${uuid()}`;
112
+ else
113
+ return value;
114
+ }
115
+
116
+ function comparePatch(a, b) {
117
+ const aPathArray = a.path.split('/');
118
+ const bPathArray = b.path.split('/');
119
+ return (aPathArray.length - bPathArray.length) || (keyPositionMap[aPathArray[1]] ?? Infinity - keyPositionMap[bPathArray[1]] ?? Infinity) || a.path.localeCompare(b.path);
120
+ }
121
+
122
+ };
@@ -0,0 +1,121 @@
1
+ const connectionCache = new WeakMap();
2
+
3
+
4
+ function createProviders(index) {
5
+
6
+ function dbMap(fn) {
7
+ fn = new Proxy(fn, {});
8
+ return (() => negotiateCachedPool(fn, dbMap));
9
+ }
10
+
11
+ Object.defineProperty(dbMap, 'pg', {
12
+ get: function() {
13
+ return createPool.bind(null, 'pg');
14
+ }
15
+ });
16
+ Object.defineProperty(dbMap, 'postgres', {
17
+ get: function() {
18
+ return createPool.bind(null, 'pg');
19
+ }
20
+ });
21
+ Object.defineProperty(dbMap, 'mssql', {
22
+ get: function() {
23
+ return createPool.bind(null, 'mssql');
24
+ }
25
+ });
26
+ Object.defineProperty(dbMap, 'mssqlNative', {
27
+ get: function() {
28
+ return createPool.bind(null, 'mssqlNative');
29
+ }
30
+ });
31
+ Object.defineProperty(dbMap, 'mysql', {
32
+ get: function() {
33
+ return createPool.bind(null, 'mysql');
34
+ }
35
+ });
36
+ Object.defineProperty(dbMap, 'sap', {
37
+ get: function() {
38
+ return createPool.bind(null, 'sap');
39
+ }
40
+ });
41
+ Object.defineProperty(dbMap, 'oracle', {
42
+ get: function() {
43
+ return createPool.bind(null, 'oracle');
44
+ }
45
+ });
46
+ Object.defineProperty(dbMap, 'sqlite', {
47
+ get: function() {
48
+ return createPool.bind(null, 'sqlite');
49
+ }
50
+ });
51
+ Object.defineProperty(dbMap, 'http', {
52
+ get: function() {
53
+ return createPool.bind(null, 'http');
54
+ }
55
+ });
56
+
57
+ dbMap.express = index.express;
58
+
59
+ function createPool(providerName, ...args) {
60
+ const provider = index[providerName];
61
+ return provider.apply(null, args);
62
+ }
63
+
64
+ return dbMap;
65
+
66
+ }
67
+
68
+ function negotiateCachedPool(fn, providers) {
69
+ let cache = connectionCache.get(fn);
70
+ if (!cache) {
71
+ cache = {};
72
+ connectionCache.set(fn, cache);
73
+ }
74
+
75
+ const dbMap = {
76
+ get pg() {
77
+ return createPool.bind(null, 'pg');
78
+ },
79
+ get postgres() {
80
+ return createPool.bind(null, 'pg');
81
+ },
82
+ get mssql() {
83
+ return createPool.bind(null, 'mssql');
84
+ },
85
+ get mssqlNative() {
86
+ return createPool.bind(null, 'mssqlNative');
87
+ },
88
+ get mysql() {
89
+ return createPool.bind(null, 'mysql');
90
+ },
91
+ get sap() {
92
+ return createPool.bind(null, 'sap');
93
+ },
94
+ get oracle() {
95
+ return createPool.bind(null, 'oracle');
96
+ },
97
+ get sqlite() {
98
+ return createPool.bind(null, 'sqlite');
99
+ },
100
+ get http() {
101
+ return createPool.bind(null, 'http');
102
+ }
103
+ };
104
+
105
+ function createPool(providerName, ...args) {
106
+ const key = JSON.stringify(args);
107
+ if (!cache[providerName])
108
+ cache[providerName] = {};
109
+ let pool = cache[providerName][key];
110
+ if (!pool) {
111
+ pool = providers[providerName].apply(null, args);
112
+ cache[providerName][key] = pool;
113
+ }
114
+ return pool;
115
+ }
116
+ return fn(dbMap);
117
+ }
118
+
119
+
120
+
121
+ module.exports = createProviders;