@sidekickdb/core 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. package/__example__/standalone.esm.html +1 -1
  2. package/__example__/standalone.umd.html +2 -2
  3. package/__tests__/src/Reactor.test.ts +70 -25
  4. package/__tests__/src/batchedFrames.test.ts +110 -0
  5. package/__tests__/src/createRouteHandler.test.ts +30 -0
  6. package/__tests__/src/data/zeneca/triples.json +6 -6
  7. package/__tests__/src/dataForQueryMemo.test.ts +4 -4
  8. package/__tests__/src/datalog.test.ts +2 -2
  9. package/__tests__/src/devtool.test.ts +2 -2
  10. package/__tests__/src/endpoints.test.ts +2 -2
  11. package/__tests__/src/infiniteQuery.test.ts +142 -0
  12. package/__tests__/src/notifyScope.test.ts +6 -6
  13. package/__tests__/src/queryValidation.test.ts +3 -3
  14. package/__tests__/src/schema.test.ts +6 -6
  15. package/__tests__/src/serializeSchema.test.ts +2 -2
  16. package/__tests__/src/{instaml.test.ts → sideml.test.ts} +106 -112
  17. package/__tests__/src/{instaql.bench.ts → sideql.bench.ts} +1 -1
  18. package/__tests__/src/{instaql.test.ts → sideql.test.ts} +25 -34
  19. package/__tests__/src/{instaqlInference.test.ts → sideqlInference.test.ts} +1 -1
  20. package/__tests__/src/store.test.ts +32 -32
  21. package/__tests__/src/transactionValidation.test.ts +4 -4
  22. package/__tests__/src/utils/e2e.ts +8 -8
  23. package/dist/commonjs/Connection.d.ts +1 -0
  24. package/dist/commonjs/Connection.d.ts.map +1 -1
  25. package/dist/commonjs/Connection.js +19 -3
  26. package/dist/commonjs/Connection.js.map +1 -1
  27. package/dist/commonjs/IndexedDBStorage.d.ts.map +1 -1
  28. package/dist/commonjs/IndexedDBStorage.js +3 -160
  29. package/dist/commonjs/IndexedDBStorage.js.map +1 -1
  30. package/dist/commonjs/Reactor.d.ts +7 -7
  31. package/dist/commonjs/Reactor.d.ts.map +1 -1
  32. package/dist/commonjs/Reactor.js +37 -38
  33. package/dist/commonjs/Reactor.js.map +1 -1
  34. package/dist/commonjs/{InstantError.d.ts → SidekickError.d.ts} +2 -2
  35. package/dist/commonjs/SidekickError.d.ts.map +1 -0
  36. package/dist/commonjs/{InstantError.js → SidekickError.js} +7 -7
  37. package/dist/commonjs/SidekickError.js.map +1 -0
  38. package/dist/commonjs/Stream.d.ts +5 -5
  39. package/dist/commonjs/Stream.d.ts.map +1 -1
  40. package/dist/commonjs/Stream.js +14 -14
  41. package/dist/commonjs/Stream.js.map +1 -1
  42. package/dist/commonjs/SyncTable.d.ts +3 -3
  43. package/dist/commonjs/SyncTable.d.ts.map +1 -1
  44. package/dist/commonjs/SyncTable.js +7 -7
  45. package/dist/commonjs/SyncTable.js.map +1 -1
  46. package/dist/commonjs/attrTypes.d.ts +11 -11
  47. package/dist/commonjs/attrTypes.d.ts.map +1 -1
  48. package/dist/commonjs/attrTypes.js.map +1 -1
  49. package/dist/commonjs/coreTypes.d.ts +4 -4
  50. package/dist/commonjs/coreTypes.d.ts.map +1 -1
  51. package/dist/commonjs/coreTypes.js.map +1 -1
  52. package/dist/commonjs/createRouteHandler.d.ts +1 -1
  53. package/dist/commonjs/createRouteHandler.d.ts.map +1 -1
  54. package/dist/commonjs/createRouteHandler.js +5 -5
  55. package/dist/commonjs/createRouteHandler.js.map +1 -1
  56. package/dist/commonjs/devtool.js +13 -6
  57. package/dist/commonjs/devtool.js.map +1 -1
  58. package/dist/commonjs/endpoints.d.ts +2 -2
  59. package/dist/commonjs/endpoints.d.ts.map +1 -1
  60. package/dist/commonjs/endpoints.js +3 -3
  61. package/dist/commonjs/endpoints.js.map +1 -1
  62. package/dist/commonjs/framework.d.ts +4 -4
  63. package/dist/commonjs/framework.d.ts.map +1 -1
  64. package/dist/commonjs/framework.js +5 -5
  65. package/dist/commonjs/framework.js.map +1 -1
  66. package/dist/commonjs/helperTypes.d.ts +24 -24
  67. package/dist/commonjs/helperTypes.d.ts.map +1 -1
  68. package/dist/commonjs/helperTypes.js.map +1 -1
  69. package/dist/commonjs/index.d.ts +36 -36
  70. package/dist/commonjs/index.d.ts.map +1 -1
  71. package/dist/commonjs/index.js +36 -36
  72. package/dist/commonjs/index.js.map +1 -1
  73. package/dist/commonjs/infiniteQuery.d.ts +7 -7
  74. package/dist/commonjs/infiniteQuery.d.ts.map +1 -1
  75. package/dist/commonjs/infiniteQuery.js +16 -3
  76. package/dist/commonjs/infiniteQuery.js.map +1 -1
  77. package/dist/commonjs/model/{instaqlResult.d.ts → sideqlResult.d.ts} +2 -2
  78. package/dist/commonjs/model/sideqlResult.d.ts.map +1 -0
  79. package/dist/commonjs/model/{instaqlResult.js → sideqlResult.js} +2 -2
  80. package/dist/commonjs/model/sideqlResult.js.map +1 -0
  81. package/dist/commonjs/notifyScope.js +3 -3
  82. package/dist/commonjs/notifyScope.js.map +1 -1
  83. package/dist/commonjs/parseSchemaFromJSON.d.ts +2 -2
  84. package/dist/commonjs/parseSchemaFromJSON.d.ts.map +1 -1
  85. package/dist/commonjs/parseSchemaFromJSON.js.map +1 -1
  86. package/dist/commonjs/queryTypes.d.ts +32 -32
  87. package/dist/commonjs/queryTypes.d.ts.map +1 -1
  88. package/dist/commonjs/queryTypes.js.map +1 -1
  89. package/dist/commonjs/routeHandlerProtocol.d.ts +7 -7
  90. package/dist/commonjs/routeHandlerProtocol.d.ts.map +1 -1
  91. package/dist/commonjs/routeHandlerProtocol.js.map +1 -1
  92. package/dist/commonjs/rulesTypes.d.ts +20 -20
  93. package/dist/commonjs/rulesTypes.d.ts.map +1 -1
  94. package/dist/commonjs/rulesTypes.js.map +1 -1
  95. package/dist/commonjs/sanityCheckQueries.d.ts +3 -3
  96. package/dist/commonjs/sanityCheckQueries.d.ts.map +1 -1
  97. package/dist/commonjs/sanityCheckQueries.js.map +1 -1
  98. package/dist/commonjs/schema.d.ts +3 -3
  99. package/dist/commonjs/schema.d.ts.map +1 -1
  100. package/dist/commonjs/schema.js +2 -2
  101. package/dist/commonjs/schema.js.map +1 -1
  102. package/dist/commonjs/schemaTypes.d.ts +8 -8
  103. package/dist/commonjs/schemaTypes.d.ts.map +1 -1
  104. package/dist/commonjs/schemaTypes.js +9 -9
  105. package/dist/commonjs/schemaTypes.js.map +1 -1
  106. package/dist/commonjs/{instaml.d.ts → sideml.d.ts} +1 -1
  107. package/dist/commonjs/sideml.d.ts.map +1 -0
  108. package/dist/commonjs/{instaml.js → sideml.js} +10 -7
  109. package/dist/commonjs/sideml.js.map +1 -0
  110. package/dist/commonjs/{instaql.d.ts → sideql.d.ts} +1 -1
  111. package/dist/commonjs/sideql.d.ts.map +1 -0
  112. package/dist/commonjs/{instaql.js → sideql.js} +1 -1
  113. package/dist/commonjs/sideql.js.map +1 -0
  114. package/dist/commonjs/{instatx.d.ts → sidetx.d.ts} +1 -1
  115. package/dist/commonjs/sidetx.d.ts.map +1 -0
  116. package/dist/commonjs/{instatx.js → sidetx.js} +1 -1
  117. package/dist/commonjs/sidetx.js.map +1 -0
  118. package/dist/commonjs/store.d.ts +22 -22
  119. package/dist/commonjs/store.d.ts.map +1 -1
  120. package/dist/commonjs/store.js +0 -2
  121. package/dist/commonjs/store.js.map +1 -1
  122. package/dist/commonjs/transactionValidation.d.ts +1 -1
  123. package/dist/commonjs/transactionValidation.d.ts.map +1 -1
  124. package/dist/commonjs/transactionValidation.js +2 -2
  125. package/dist/commonjs/transactionValidation.js.map +1 -1
  126. package/dist/commonjs/utils/dates.js +31 -31
  127. package/dist/commonjs/utils/dates.js.map +1 -1
  128. package/dist/commonjs/utils/fetch.d.ts +7 -7
  129. package/dist/commonjs/utils/fetch.d.ts.map +1 -1
  130. package/dist/commonjs/utils/fetch.js +8 -8
  131. package/dist/commonjs/utils/fetch.js.map +1 -1
  132. package/dist/commonjs/utils/flags.d.ts +2 -2
  133. package/dist/commonjs/utils/flags.d.ts.map +1 -1
  134. package/dist/commonjs/utils/flags.js +4 -4
  135. package/dist/commonjs/utils/flags.js.map +1 -1
  136. package/dist/commonjs/utils/linkIndex.d.ts +2 -2
  137. package/dist/commonjs/utils/linkIndex.d.ts.map +1 -1
  138. package/dist/commonjs/utils/linkIndex.js.map +1 -1
  139. package/dist/commonjs/warningToggle.d.ts +1 -1
  140. package/dist/commonjs/warningToggle.d.ts.map +1 -1
  141. package/dist/commonjs/warningToggle.js +3 -3
  142. package/dist/commonjs/warningToggle.js.map +1 -1
  143. package/dist/esm/Connection.d.ts +1 -0
  144. package/dist/esm/Connection.d.ts.map +1 -1
  145. package/dist/esm/Connection.js +18 -3
  146. package/dist/esm/Connection.js.map +1 -1
  147. package/dist/esm/IndexedDBStorage.d.ts.map +1 -1
  148. package/dist/esm/IndexedDBStorage.js +4 -161
  149. package/dist/esm/IndexedDBStorage.js.map +1 -1
  150. package/dist/esm/Reactor.d.ts +7 -7
  151. package/dist/esm/Reactor.d.ts.map +1 -1
  152. package/dist/esm/Reactor.js +38 -39
  153. package/dist/esm/Reactor.js.map +1 -1
  154. package/dist/esm/{InstantError.d.ts → SidekickError.d.ts} +2 -2
  155. package/dist/esm/SidekickError.d.ts.map +1 -0
  156. package/dist/esm/{InstantError.js → SidekickError.js} +5 -5
  157. package/dist/esm/SidekickError.js.map +1 -0
  158. package/dist/esm/Stream.d.ts +5 -5
  159. package/dist/esm/Stream.d.ts.map +1 -1
  160. package/dist/esm/Stream.js +12 -12
  161. package/dist/esm/Stream.js.map +1 -1
  162. package/dist/esm/SyncTable.d.ts +3 -3
  163. package/dist/esm/SyncTable.d.ts.map +1 -1
  164. package/dist/esm/SyncTable.js +3 -3
  165. package/dist/esm/SyncTable.js.map +1 -1
  166. package/dist/esm/attrTypes.d.ts +11 -11
  167. package/dist/esm/attrTypes.d.ts.map +1 -1
  168. package/dist/esm/attrTypes.js.map +1 -1
  169. package/dist/esm/coreTypes.d.ts +4 -4
  170. package/dist/esm/coreTypes.d.ts.map +1 -1
  171. package/dist/esm/coreTypes.js.map +1 -1
  172. package/dist/esm/createRouteHandler.d.ts +1 -1
  173. package/dist/esm/createRouteHandler.d.ts.map +1 -1
  174. package/dist/esm/createRouteHandler.js +3 -3
  175. package/dist/esm/createRouteHandler.js.map +1 -1
  176. package/dist/esm/devtool.js +13 -6
  177. package/dist/esm/devtool.js.map +1 -1
  178. package/dist/esm/endpoints.d.ts +2 -2
  179. package/dist/esm/endpoints.d.ts.map +1 -1
  180. package/dist/esm/endpoints.js +3 -3
  181. package/dist/esm/endpoints.js.map +1 -1
  182. package/dist/esm/framework.d.ts +4 -4
  183. package/dist/esm/framework.d.ts.map +1 -1
  184. package/dist/esm/framework.js +6 -6
  185. package/dist/esm/framework.js.map +1 -1
  186. package/dist/esm/helperTypes.d.ts +24 -24
  187. package/dist/esm/helperTypes.d.ts.map +1 -1
  188. package/dist/esm/helperTypes.js.map +1 -1
  189. package/dist/esm/index.d.ts +36 -36
  190. package/dist/esm/index.d.ts.map +1 -1
  191. package/dist/esm/index.js +33 -33
  192. package/dist/esm/index.js.map +1 -1
  193. package/dist/esm/infiniteQuery.d.ts +7 -7
  194. package/dist/esm/infiniteQuery.d.ts.map +1 -1
  195. package/dist/esm/infiniteQuery.js +16 -3
  196. package/dist/esm/infiniteQuery.js.map +1 -1
  197. package/dist/esm/model/{instaqlResult.d.ts → sideqlResult.d.ts} +2 -2
  198. package/dist/esm/model/sideqlResult.d.ts.map +1 -0
  199. package/dist/esm/model/{instaqlResult.js → sideqlResult.js} +2 -2
  200. package/dist/esm/model/sideqlResult.js.map +1 -0
  201. package/dist/esm/notifyScope.js +3 -3
  202. package/dist/esm/notifyScope.js.map +1 -1
  203. package/dist/esm/parseSchemaFromJSON.d.ts +2 -2
  204. package/dist/esm/parseSchemaFromJSON.d.ts.map +1 -1
  205. package/dist/esm/parseSchemaFromJSON.js.map +1 -1
  206. package/dist/esm/queryTypes.d.ts +32 -32
  207. package/dist/esm/queryTypes.d.ts.map +1 -1
  208. package/dist/esm/queryTypes.js.map +1 -1
  209. package/dist/esm/routeHandlerProtocol.d.ts +7 -7
  210. package/dist/esm/routeHandlerProtocol.d.ts.map +1 -1
  211. package/dist/esm/routeHandlerProtocol.js.map +1 -1
  212. package/dist/esm/rulesTypes.d.ts +20 -20
  213. package/dist/esm/rulesTypes.d.ts.map +1 -1
  214. package/dist/esm/rulesTypes.js.map +1 -1
  215. package/dist/esm/sanityCheckQueries.d.ts +3 -3
  216. package/dist/esm/sanityCheckQueries.d.ts.map +1 -1
  217. package/dist/esm/sanityCheckQueries.js.map +1 -1
  218. package/dist/esm/schema.d.ts +3 -3
  219. package/dist/esm/schema.d.ts.map +1 -1
  220. package/dist/esm/schema.js +3 -3
  221. package/dist/esm/schema.js.map +1 -1
  222. package/dist/esm/schemaTypes.d.ts +8 -8
  223. package/dist/esm/schemaTypes.d.ts.map +1 -1
  224. package/dist/esm/schemaTypes.js +5 -5
  225. package/dist/esm/schemaTypes.js.map +1 -1
  226. package/dist/esm/{instaml.d.ts → sideml.d.ts} +1 -1
  227. package/dist/esm/sideml.d.ts.map +1 -0
  228. package/dist/esm/{instaml.js → sideml.js} +6 -3
  229. package/dist/esm/sideml.js.map +1 -0
  230. package/dist/esm/{instaql.d.ts → sideql.d.ts} +1 -1
  231. package/dist/esm/sideql.d.ts.map +1 -0
  232. package/dist/esm/{instaql.js → sideql.js} +1 -1
  233. package/dist/esm/sideql.js.map +1 -0
  234. package/dist/esm/{instatx.d.ts → sidetx.d.ts} +1 -1
  235. package/dist/esm/sidetx.d.ts.map +1 -0
  236. package/dist/esm/{instatx.js → sidetx.js} +1 -1
  237. package/dist/esm/sidetx.js.map +1 -0
  238. package/dist/esm/store.d.ts +22 -22
  239. package/dist/esm/store.d.ts.map +1 -1
  240. package/dist/esm/store.js +0 -2
  241. package/dist/esm/store.js.map +1 -1
  242. package/dist/esm/transactionValidation.d.ts +1 -1
  243. package/dist/esm/transactionValidation.d.ts.map +1 -1
  244. package/dist/esm/transactionValidation.js +1 -1
  245. package/dist/esm/transactionValidation.js.map +1 -1
  246. package/dist/esm/utils/dates.js +31 -31
  247. package/dist/esm/utils/dates.js.map +1 -1
  248. package/dist/esm/utils/fetch.d.ts +7 -7
  249. package/dist/esm/utils/fetch.d.ts.map +1 -1
  250. package/dist/esm/utils/fetch.js +6 -6
  251. package/dist/esm/utils/fetch.js.map +1 -1
  252. package/dist/esm/utils/flags.d.ts +2 -2
  253. package/dist/esm/utils/flags.d.ts.map +1 -1
  254. package/dist/esm/utils/flags.js +3 -3
  255. package/dist/esm/utils/flags.js.map +1 -1
  256. package/dist/esm/utils/linkIndex.d.ts +2 -2
  257. package/dist/esm/utils/linkIndex.d.ts.map +1 -1
  258. package/dist/esm/utils/linkIndex.js.map +1 -1
  259. package/dist/esm/warningToggle.d.ts +1 -1
  260. package/dist/esm/warningToggle.d.ts.map +1 -1
  261. package/dist/esm/warningToggle.js +1 -1
  262. package/dist/esm/warningToggle.js.map +1 -1
  263. package/dist/standalone/index.js +2705 -2791
  264. package/dist/standalone/index.umd.cjs +9 -6
  265. package/package.json +2 -2
  266. package/src/Connection.ts +18 -3
  267. package/src/IndexedDBStorage.ts +3 -181
  268. package/src/Reactor.js +40 -39
  269. package/src/{InstantError.ts → SidekickError.ts} +4 -4
  270. package/src/Stream.ts +35 -32
  271. package/src/SyncTable.ts +6 -6
  272. package/src/attrTypes.ts +15 -11
  273. package/src/coreTypes.ts +5 -5
  274. package/src/createRouteHandler.ts +9 -7
  275. package/src/devtool.ts +13 -6
  276. package/src/endpoints.ts +4 -4
  277. package/src/framework.ts +13 -13
  278. package/src/helperTypes.ts +37 -37
  279. package/src/index.ts +123 -123
  280. package/src/infiniteQuery.ts +39 -22
  281. package/src/model/{instaqlResult.js → sideqlResult.js} +1 -1
  282. package/src/notifyScope.ts +3 -3
  283. package/src/parseSchemaFromJSON.ts +2 -2
  284. package/src/queryTypes.ts +55 -55
  285. package/src/routeHandlerProtocol.ts +8 -8
  286. package/src/rulesTypes.ts +23 -23
  287. package/src/sanityCheckQueries.ts +9 -9
  288. package/src/schema.ts +3 -3
  289. package/src/schemaTypes.ts +11 -9
  290. package/src/{instaml.ts → sideml.ts} +17 -14
  291. package/src/{instaql.ts → sideql.ts} +5 -5
  292. package/src/store.ts +35 -36
  293. package/src/transactionValidation.ts +1 -1
  294. package/src/utils/dates.ts +31 -31
  295. package/src/utils/fetch.ts +13 -13
  296. package/src/utils/flags.ts +3 -3
  297. package/src/utils/linkIndex.ts +2 -2
  298. package/src/warningToggle.ts +1 -1
  299. package/vite.config.ts +1 -1
  300. package/dist/commonjs/InstantError.d.ts.map +0 -1
  301. package/dist/commonjs/InstantError.js.map +0 -1
  302. package/dist/commonjs/instaml.d.ts.map +0 -1
  303. package/dist/commonjs/instaml.js.map +0 -1
  304. package/dist/commonjs/instaql.d.ts.map +0 -1
  305. package/dist/commonjs/instaql.js.map +0 -1
  306. package/dist/commonjs/instatx.d.ts.map +0 -1
  307. package/dist/commonjs/instatx.js.map +0 -1
  308. package/dist/commonjs/model/instaqlResult.d.ts.map +0 -1
  309. package/dist/commonjs/model/instaqlResult.js.map +0 -1
  310. package/dist/esm/InstantError.d.ts.map +0 -1
  311. package/dist/esm/InstantError.js.map +0 -1
  312. package/dist/esm/instaml.d.ts.map +0 -1
  313. package/dist/esm/instaml.js.map +0 -1
  314. package/dist/esm/instaql.d.ts.map +0 -1
  315. package/dist/esm/instaql.js.map +0 -1
  316. package/dist/esm/instatx.d.ts.map +0 -1
  317. package/dist/esm/instatx.js.map +0 -1
  318. package/dist/esm/model/instaqlResult.d.ts.map +0 -1
  319. package/dist/esm/model/instaqlResult.js.map +0 -1
  320. /package/src/{instatx.ts → sidetx.ts} +0 -0
@@ -3,12 +3,12 @@
3
3
 
4
4
  import type {
5
5
  Cursor,
6
- InstantObject,
7
- InstaQLParams,
8
- InstaQLResponse,
6
+ SidekickObject,
7
+ SideQLParams,
8
+ SideQLResponse,
9
9
  ValidQuery,
10
10
  } from './queryTypes.ts';
11
- import { InstantUnknownSchema } from './schemaTypes.ts';
11
+ import { SidekickUnknownSchema } from './schemaTypes.ts';
12
12
 
13
13
  /**
14
14
  * The purpose of these sanity checks:
@@ -20,9 +20,9 @@ import { InstantUnknownSchema } from './schemaTypes.ts';
20
20
  * * the api is more vebose than this
21
21
  */
22
22
 
23
- export function dummyQuery<Q extends ValidQuery<Q, InstantUnknownSchema>>(
23
+ export function dummyQuery<Q extends ValidQuery<Q, SidekickUnknownSchema>>(
24
24
  _query: Q,
25
- ): InstaQLResponse<InstantUnknownSchema, Q> {
25
+ ): SideQLResponse<SidekickUnknownSchema, Q> {
26
26
  return 1 as any;
27
27
  }
28
28
 
@@ -172,12 +172,12 @@ const sanityCheckQueries = () => {
172
172
  };
173
173
  const sanityCheckSchemalessResponses = () => {
174
174
  // Simple Response
175
- const r1: { users: InstantObject[] } = dummyQuery({ users: {} });
175
+ const r1: { users: SidekickObject[] } = dummyQuery({ users: {} });
176
176
  // Nested Response
177
- const r2: { users: ({ posts: InstantObject[] } & InstantObject)[] } =
177
+ const r2: { users: ({ posts: SidekickObject[] } & SidekickObject)[] } =
178
178
  dummyQuery({ users: { posts: {} } });
179
179
  // $ are ignored
180
- const r3: { users: ({ posts: InstantObject[] } & InstantObject)[] } =
180
+ const r3: { users: ({ posts: SidekickObject[] } & SidekickObject)[] } =
181
181
  dummyQuery({
182
182
  users: {
183
183
  $: { where: { foo: 1 } },
package/src/schema.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  EntityDef,
3
3
  DataAttrDef,
4
- InstantSchemaDef,
4
+ SidekickSchemaDef,
5
5
  type EntitiesDef,
6
6
  type AttrsDefs,
7
7
  type EntitiesWithLinks,
@@ -31,7 +31,7 @@ function graph<
31
31
  EntitiesWithoutLinks extends EntitiesDef,
32
32
  const Links extends LinksDef<EntitiesWithoutLinks>,
33
33
  >(entities: EntitiesWithoutLinks, links: Links) {
34
- return new InstantSchemaDef(
34
+ return new SidekickSchemaDef(
35
35
  enrichEntitiesWithLinks<EntitiesWithoutLinks, Links>(entities, links),
36
36
  // (XXX): LinksDef<any> stems from TypeScript’s inability to reconcile the
37
37
  // type EntitiesWithLinks<EntitiesWithoutLinks, Links> with
@@ -167,7 +167,7 @@ function schema<
167
167
  }) {
168
168
  const linksDef = (links ?? {}) as Links;
169
169
  const roomsDef = (rooms ?? {}) as Rooms;
170
- return new InstantSchemaDef(
170
+ return new SidekickSchemaDef(
171
171
  enrichEntitiesWithLinks<EntitiesWithoutLinks, Links>(entities, linksDef),
172
172
  // (XXX): LinksDef<any> stems from TypeScript's inability to reconcile the
173
173
  // type EntitiesWithLinks<EntitiesWithoutLinks, Links> with
@@ -368,7 +368,9 @@ export type RoomsFromDef<RDef extends RoomsDef> = {
368
368
  };
369
369
 
370
370
  export type RoomsOf<S> =
371
- S extends InstantSchemaDef<any, any, infer RDef> ? RoomsFromDef<RDef> : never;
371
+ S extends SidekickSchemaDef<any, any, infer RDef>
372
+ ? RoomsFromDef<RDef>
373
+ : never;
372
374
 
373
375
  export type PresenceOf<
374
376
  S,
@@ -397,7 +399,7 @@ export interface RoomsDef {
397
399
  [RoomType: string]: RoomDef;
398
400
  }
399
401
 
400
- export class InstantSchemaDef<
402
+ export class SidekickSchemaDef<
401
403
  Entities extends EntitiesDef,
402
404
  Links extends LinksDef<Entities>,
403
405
  Rooms extends RoomsDef,
@@ -430,7 +432,7 @@ export class InstantSchemaDef<
430
432
  */
431
433
  withRoomSchema<_RoomSchema extends RoomSchemaShape>() {
432
434
  type RDef = RoomDefFromShape<_RoomSchema>;
433
- return new InstantSchemaDef<Entities, Links, RDef>(
435
+ return new SidekickSchemaDef<Entities, Links, RDef>(
434
436
  this.entities,
435
437
  this.links,
436
438
  {} as RDef,
@@ -444,7 +446,7 @@ export class InstantSchemaDef<
444
446
  *
445
447
  * @see https://sidekickdb.co/docs/modeling-data
446
448
  */
447
- export class InstantGraph<
449
+ export class SidekickGraph<
448
450
  Entities extends EntitiesDef,
449
451
  Links extends LinksDef<Entities>,
450
452
  RoomSchema extends RoomSchemaShape = {},
@@ -456,7 +458,7 @@ export class InstantGraph<
456
458
  ) {}
457
459
 
458
460
  withRoomSchema<_RoomSchema extends RoomSchemaShape>() {
459
- return new InstantGraph<Entities, Links, _RoomSchema>(
461
+ return new SidekickGraph<Entities, Links, _RoomSchema>(
460
462
  this.entities,
461
463
  this.links,
462
464
  );
@@ -521,14 +523,14 @@ type EntityDefFromShape<Shape, K extends keyof Shape> = EntityDef<
521
523
  export type BackwardsCompatibleSchema<
522
524
  Shape extends { [k: string]: any },
523
525
  RoomSchema extends RoomSchemaShape = {},
524
- > = InstantSchemaDef<
526
+ > = SidekickSchemaDef<
525
527
  { [K in keyof Shape]: EntityDefFromShape<Shape, K> },
526
528
  UnknownLinks<EntitiesDef>,
527
529
  RoomDefFromShape<RoomSchema>
528
530
  >;
529
531
 
530
532
  // ----------
531
- // InstantUnknownSchema
533
+ // SidekickUnknownSchema
532
534
 
533
535
  export type UnknownEntity = EntityDef<
534
536
  {
@@ -564,13 +566,13 @@ export interface UnknownRooms {
564
566
  };
565
567
  }
566
568
 
567
- export class InstantUnknownSchemaDef extends InstantSchemaDef<
569
+ export class SidekickUnknownSchemaDef extends SidekickSchemaDef<
568
570
  UnknownEntities,
569
571
  UnknownLinks<UnknownEntities>,
570
572
  UnknownRooms
571
573
  > {}
572
574
 
573
- export type InstantUnknownSchema = InstantUnknownSchemaDef;
575
+ export type SidekickUnknownSchema = SidekickUnknownSchemaDef;
574
576
 
575
577
  export type CreateParams<
576
578
  Schema extends IContainEntitiesAndLinks<any, any>,
@@ -6,7 +6,7 @@ import {
6
6
  getAttrByReverseIdentName,
7
7
  Store,
8
8
  } from './store.ts';
9
- import { getOps, isLookup, parseLookup } from './instatx.ts';
9
+ import { getOps, isLookup, parseLookup } from './sidetx.ts';
10
10
  import { immutableRemoveUndefined } from './utils/object.js';
11
11
  import { coerceToDate } from './utils/dates.ts';
12
12
  import uuid from './utils/id.ts';
@@ -15,7 +15,7 @@ import {
15
15
  IContainEntitiesAndLinks,
16
16
  LinkDef,
17
17
  } from './schemaTypes.ts';
18
- import { InstantDBAttr, InstantDBIdent } from './attrTypes.ts';
18
+ import { SidekickDBAttr, SidekickDBIdent } from './attrTypes.ts';
19
19
 
20
20
  export type AttrMapping = {
21
21
  attrIdMap: Record<string, string>;
@@ -466,14 +466,14 @@ function createRefAttr(
466
466
  schema: Schema | undefined,
467
467
  etype: string,
468
468
  label: string,
469
- props?: Partial<InstantDBAttr> | undefined,
470
- ): InstantDBAttr {
469
+ props?: Partial<SidekickDBAttr> | undefined,
470
+ ): SidekickDBAttr {
471
471
  const schemaRefProps = schema
472
472
  ? refPropsFromSchema(schema, etype, label)
473
473
  : null;
474
474
  const attrId = uuid();
475
- const fwdIdent: InstantDBIdent = [uuid(), etype, label];
476
- const revIdent: InstantDBIdent = [uuid(), label, etype];
475
+ const fwdIdent: SidekickDBIdent = [uuid(), etype, label];
476
+ const revIdent: SidekickDBIdent = [uuid(), label, etype];
477
477
  return {
478
478
  id: attrId,
479
479
  // @ts-ignore: ts thinks it's any[]
@@ -505,8 +505,11 @@ const SUPPORTS_LOOKUP_ACTIONS = new Set([
505
505
  'ruleParams',
506
506
  ]);
507
507
 
508
- const lookupProps: Partial<InstantDBAttr> = { 'unique?': true, 'index?': true };
509
- const refLookupProps: Partial<InstantDBAttr> = {
508
+ const lookupProps: Partial<SidekickDBAttr> = {
509
+ 'unique?': true,
510
+ 'index?': true,
511
+ };
512
+ const refLookupProps: Partial<SidekickDBAttr> = {
510
513
  ...lookupProps,
511
514
  cardinality: 'one',
512
515
  };
@@ -545,10 +548,10 @@ function createMissingAttrs(
545
548
  ops,
546
549
  ): [AttrsStore, TXStep[]] {
547
550
  const addedIds = new Set();
548
- const localAttrs: InstantDBAttr[] = [];
551
+ const localAttrs: SidekickDBAttr[] = [];
549
552
  const addOps: TXStep[] = [];
550
553
 
551
- function attrByFwdIdent(etype, label): InstantDBAttr | undefined {
554
+ function attrByFwdIdent(etype, label): SidekickDBAttr | undefined {
552
555
  return (
553
556
  getAttrByFwdIdentName(attrsStore, etype, label) ||
554
557
  localAttrs.find(
@@ -559,7 +562,7 @@ function createMissingAttrs(
559
562
  );
560
563
  }
561
564
 
562
- function attrByRevIdent(etype, label): InstantDBAttr | undefined {
565
+ function attrByRevIdent(etype, label): SidekickDBAttr | undefined {
563
566
  return (
564
567
  getAttrByReverseIdentName(attrsStore, etype, label) ||
565
568
  localAttrs.find(
@@ -570,15 +573,15 @@ function createMissingAttrs(
570
573
  );
571
574
  }
572
575
 
573
- function addAttr(attr: InstantDBAttr) {
576
+ function addAttr(attr: SidekickDBAttr) {
574
577
  localAttrs.push(attr);
575
578
  addOps.push(['add-attr', attr]);
576
579
  addedIds.add(attr.id);
577
580
  }
578
581
  function addUnsynced(
579
582
  attr:
580
- | (InstantDBAttr & { isUnsynced?: boolean })
581
- | InstantDBAttr
583
+ | (SidekickDBAttr & { isUnsynced?: boolean })
584
+ | SidekickDBAttr
582
585
  | undefined,
583
586
  ) {
584
587
  if (
@@ -2,7 +2,7 @@ import { query as datalogQuery } from './datalog.js';
2
2
  import { uuidCompare } from './utils/id.ts';
3
3
  import { stringCompare } from './utils/strings.ts';
4
4
  import * as s from './store.ts';
5
- import { InstantDBAttr } from './attrTypes.ts';
5
+ import { SidekickDBAttr } from './attrTypes.ts';
6
6
  import { Cursor } from './queryTypes.ts';
7
7
  import { warningEnabled } from './warningToggle.ts';
8
8
 
@@ -48,7 +48,7 @@ class AttrNotFoundError extends Error {
48
48
  }
49
49
  }
50
50
 
51
- function idAttr(attrsStore: s.AttrsStore, ns: string): InstantDBAttr {
51
+ function idAttr(attrsStore: s.AttrsStore, ns: string): SidekickDBAttr {
52
52
  const attr = s.getPrimaryKeyAttr(attrsStore, ns);
53
53
 
54
54
  if (!attr) {
@@ -90,7 +90,7 @@ function refAttrPat(
90
90
  etype: string,
91
91
  level: number,
92
92
  label: string,
93
- ): [string, number, Pat, InstantDBAttr, boolean] {
93
+ ): [string, number, Pat, SidekickDBAttr, boolean] {
94
94
  const fwdAttr = s.getAttrByFwdIdentName(attrsStore, etype, label);
95
95
  const revAttr = s.getAttrByReverseIdentName(attrsStore, etype, label);
96
96
  const attr = fwdAttr || revAttr;
@@ -149,7 +149,7 @@ function makeLikeMatcher(caseSensitive: boolean, pattern: string) {
149
149
  };
150
150
  }
151
151
 
152
- function parseValue(attr: InstantDBAttr, v: any) {
152
+ function parseValue(attr: SidekickDBAttr, v: any) {
153
153
  if (
154
154
  typeof v !== 'object' ||
155
155
  v.hasOwnProperty('$in') ||
@@ -675,7 +675,7 @@ function objectAttrs(
675
675
  attrsStore: s.AttrsStore,
676
676
  etype,
677
677
  dq,
678
- ): Map<string, InstantDBAttr> | undefined {
678
+ ): Map<string, SidekickDBAttr> | undefined {
679
679
  if (!Array.isArray(dq.fields)) {
680
680
  return s.getBlobAttrs(attrsStore, etype);
681
681
  }
package/src/store.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import { create } from 'mutative';
2
2
  import { immutableDeepMerge } from './utils/object.js';
3
3
  import { coerceToDate } from './utils/dates.ts';
4
- import { InstantDBAttr } from './attrTypes.ts';
4
+ import { SidekickDBAttr } from './attrTypes.ts';
5
5
  import { LinkIndex } from './utils/linkIndex.ts';
6
6
 
7
7
  type Triple = [string, string, any, number];
8
- type Attrs = Record<string, InstantDBAttr>;
8
+ type Attrs = Record<string, SidekickDBAttr>;
9
9
 
10
10
  interface AttrIndexes {
11
- blobAttrs: Map<string, Map<string, InstantDBAttr>>;
12
- primaryKeys: Map<string, InstantDBAttr>;
13
- forwardIdents: Map<string, Map<string, InstantDBAttr>>;
14
- revIdents: Map<string, Map<string, InstantDBAttr>>;
11
+ blobAttrs: Map<string, Map<string, SidekickDBAttr>>;
12
+ primaryKeys: Map<string, SidekickDBAttr>;
13
+ forwardIdents: Map<string, Map<string, SidekickDBAttr>>;
14
+ revIdents: Map<string, Map<string, SidekickDBAttr>>;
15
15
  }
16
16
 
17
17
  export type Store = {
@@ -49,24 +49,25 @@ export interface AttrsStore {
49
49
  attrs: Attrs;
50
50
  linkIndex: LinkIndex | null;
51
51
  resetAttrIndexes(): void;
52
- addAttr(attr: InstantDBAttr): void;
52
+ addAttr(attr: SidekickDBAttr): void;
53
53
  deleteAttr(attrId: string): void;
54
- updateAttr(partialAttr: Partial<InstantDBAttr> & { id: string }): void;
55
- getAttr(id: string): InstantDBAttr | undefined;
56
- blobAttrs: Map<string, Map<string, InstantDBAttr>>;
57
- primaryKeys: Map<string, InstantDBAttr>;
58
- forwardIdents: Map<string, Map<string, InstantDBAttr>>;
59
- revIdents: Map<string, Map<string, InstantDBAttr>>;
54
+ updateAttr(partialAttr: Partial<SidekickDBAttr> & { id: string }): void;
55
+ getAttr(id: string): SidekickDBAttr | undefined;
56
+ blobAttrs: Map<string, Map<string, SidekickDBAttr>>;
57
+ primaryKeys: Map<string, SidekickDBAttr>;
58
+ forwardIdents: Map<string, Map<string, SidekickDBAttr>>;
59
+ revIdents: Map<string, Map<string, SidekickDBAttr>>;
60
60
  toJSON(): AttrsStoreJson;
61
61
  }
62
62
 
63
63
  export class AttrsStoreClass implements AttrsStore {
64
64
  public attrs: Attrs;
65
65
  public linkIndex: LinkIndex | null;
66
- private _blobAttrs: Map<string, Map<string, InstantDBAttr>> | null = null;
67
- private _primaryKeys: Map<string, InstantDBAttr> | null = null;
68
- private _forwardIdents: Map<string, Map<string, InstantDBAttr>> | null = null;
69
- private _revIdents: Map<string, Map<string, InstantDBAttr>> | null = null;
66
+ private _blobAttrs: Map<string, Map<string, SidekickDBAttr>> | null = null;
67
+ private _primaryKeys: Map<string, SidekickDBAttr> | null = null;
68
+ private _forwardIdents: Map<string, Map<string, SidekickDBAttr>> | null =
69
+ null;
70
+ private _revIdents: Map<string, Map<string, SidekickDBAttr>> | null = null;
70
71
  constructor(attrs: Attrs, linkIndex: LinkIndex | null) {
71
72
  this.attrs = attrs;
72
73
  this.linkIndex = linkIndex;
@@ -79,7 +80,7 @@ export class AttrsStoreClass implements AttrsStore {
79
80
  this._revIdents = null;
80
81
  }
81
82
 
82
- public addAttr(attr: InstantDBAttr) {
83
+ public addAttr(attr: SidekickDBAttr) {
83
84
  this.attrs[attr.id] = attr;
84
85
  this.resetAttrIndexes();
85
86
  }
@@ -89,18 +90,18 @@ export class AttrsStoreClass implements AttrsStore {
89
90
  this.resetAttrIndexes();
90
91
  }
91
92
 
92
- public updateAttr(partialAttr: Partial<InstantDBAttr> & { id: string }) {
93
+ public updateAttr(partialAttr: Partial<SidekickDBAttr> & { id: string }) {
93
94
  const attr = this.attrs[partialAttr.id];
94
95
  if (!attr) return;
95
96
  this.attrs[partialAttr.id] = { ...attr, ...partialAttr };
96
97
  this.resetAttrIndexes();
97
98
  }
98
99
 
99
- public getAttr(id: string): InstantDBAttr | undefined {
100
+ public getAttr(id: string): SidekickDBAttr | undefined {
100
101
  return this.attrs[id];
101
102
  }
102
103
 
103
- get blobAttrs(): Map<string, Map<string, InstantDBAttr>> {
104
+ get blobAttrs(): Map<string, Map<string, SidekickDBAttr>> {
104
105
  if (this._blobAttrs) {
105
106
  return this._blobAttrs;
106
107
  }
@@ -114,7 +115,7 @@ export class AttrsStoreClass implements AttrsStore {
114
115
  return this._blobAttrs;
115
116
  }
116
117
 
117
- get primaryKeys(): Map<string, InstantDBAttr> {
118
+ get primaryKeys(): Map<string, SidekickDBAttr> {
118
119
  if (this._primaryKeys) {
119
120
  return this._primaryKeys;
120
121
  }
@@ -129,7 +130,7 @@ export class AttrsStoreClass implements AttrsStore {
129
130
  return this._primaryKeys;
130
131
  }
131
132
 
132
- get forwardIdents(): Map<string, Map<string, InstantDBAttr>> {
133
+ get forwardIdents(): Map<string, Map<string, SidekickDBAttr>> {
133
134
  if (this._forwardIdents) {
134
135
  return this._forwardIdents;
135
136
  }
@@ -143,7 +144,7 @@ export class AttrsStoreClass implements AttrsStore {
143
144
  return this._forwardIdents;
144
145
  }
145
146
 
146
- get revIdents(): Map<string, Map<string, InstantDBAttr>> {
147
+ get revIdents(): Map<string, Map<string, SidekickDBAttr>> {
147
148
  if (this._revIdents) {
148
149
  return this._revIdents;
149
150
  }
@@ -164,19 +165,19 @@ export class AttrsStoreClass implements AttrsStore {
164
165
  }
165
166
  }
166
167
 
167
- function hasEA(attr: InstantDBAttr) {
168
+ function hasEA(attr: SidekickDBAttr) {
168
169
  return attr['cardinality'] === 'one';
169
170
  }
170
171
 
171
- function isRef(attr: InstantDBAttr) {
172
+ function isRef(attr: SidekickDBAttr) {
172
173
  return attr['value-type'] === 'ref';
173
174
  }
174
175
 
175
- export function isBlob(attr: InstantDBAttr) {
176
+ export function isBlob(attr: SidekickDBAttr) {
176
177
  return attr['value-type'] === 'blob';
177
178
  }
178
179
 
179
- function getAttr(attrs: Attrs, attrId: string): InstantDBAttr | undefined {
180
+ function getAttr(attrs: Attrs, attrId: string): SidekickDBAttr | undefined {
180
181
  return attrs[attrId];
181
182
  }
182
183
 
@@ -213,7 +214,7 @@ function setInMap(m: Map<any, any>, path: any[], value: any) {
213
214
  }
214
215
  }
215
216
 
216
- function isDateAttr(attr: InstantDBAttr) {
217
+ function isDateAttr(attr: SidekickDBAttr) {
217
218
  return attr['checked-data-type'] === 'date';
218
219
  }
219
220
 
@@ -248,7 +249,7 @@ function createTripleIndexes(
248
249
  return { eav, aev, vae };
249
250
  }
250
251
 
251
- function createAttrIndexes(attrs: Record<string, InstantDBAttr>): AttrIndexes {
252
+ function createAttrIndexes(attrs: Record<string, SidekickDBAttr>): AttrIndexes {
252
253
  const blobAttrs = new Map();
253
254
  const primaryKeys = new Map();
254
255
  const forwardIdents = new Map();
@@ -410,7 +411,7 @@ export function retractTriple(
410
411
  let _seed = 0;
411
412
  function getCreatedAt(
412
413
  store: Store,
413
- attr: InstantDBAttr,
414
+ attr: SidekickDBAttr,
414
415
  triple: Triple,
415
416
  ): Number {
416
417
  const [eid, aid, v] = triple;
@@ -459,7 +460,6 @@ export function addTriple(
459
460
  if (!attr) {
460
461
  // (XXX): Due to the way we're handling attrs, it's
461
462
  // possible to enter a state where we receive a triple without an attr.
462
- // See: https://github.com/jsventures/instant-local/pull/132 for details.
463
463
  // For now, if we receive a command without an attr, we no-op.
464
464
  return;
465
465
  }
@@ -609,7 +609,7 @@ function resetIndexMap(store: Store, attrsStore, newTriples: Triple[]) {
609
609
  });
610
610
  }
611
611
 
612
- function addAttr(attrsStore: AttrsStore, [attr]: [InstantDBAttr]) {
612
+ function addAttr(attrsStore: AttrsStore, [attr]: [SidekickDBAttr]) {
613
613
  attrsStore.addAttr(attr);
614
614
  }
615
615
 
@@ -627,7 +627,7 @@ function deleteAttr(store: Store, attrsStore: AttrsStore, [id]: [string]) {
627
627
  function updateAttr(
628
628
  store: Store,
629
629
  attrsStore: AttrsStore,
630
- [partialAttr]: [Partial<InstantDBAttr> & { id: string }],
630
+ [partialAttr]: [Partial<SidekickDBAttr> & { id: string }],
631
631
  ) {
632
632
  const attr = attrsStore.getAttr(partialAttr.id);
633
633
  if (!attr) return;
@@ -817,7 +817,7 @@ export function getTriples(store, [e, a, v]) {
817
817
 
818
818
  export function getAsObject(
819
819
  store: Store,
820
- attrs: Map<string, InstantDBAttr> | undefined,
820
+ attrs: Map<string, SidekickDBAttr> | undefined,
821
821
  e: string,
822
822
  ) {
823
823
  const obj = {};
@@ -880,7 +880,6 @@ function findTriple(
880
880
  if (!attr) {
881
881
  // (XXX): Due to the way we're handling attrs, it's
882
882
  // possible to enter a state where we receive a triple without an attr.
883
- // See: https://github.com/jsventures/instant-local/pull/132 for details.
884
883
  // For now, if we receive a command without an attr, we no-op.
885
884
  return;
886
885
  }
@@ -1,4 +1,4 @@
1
- import { TransactionChunk, Op, isLookup } from './instatx.ts';
1
+ import { TransactionChunk, Op, isLookup } from './sidetx.ts';
2
2
  import { IContainEntitiesAndLinks, DataAttrDef } from './schemaTypes.ts';
3
3
  import { validate as validateUUID } from 'uuid';
4
4
 
@@ -1,18 +1,18 @@
1
1
  import { pgTimezoneMatch, pgTimezoneAbbrevs } from './pgtime.ts';
2
2
 
3
3
  // Date parsing functions
4
- function zonedDateTimeStrToInstant(s) {
4
+ function zonedDateTimeStrToDate(s) {
5
5
  return new Date(s);
6
6
  }
7
7
 
8
- function localDateTimeStrToInstant(s) {
8
+ function localDateTimeStrToDate(s) {
9
9
  // Parse as UTC since there's no timezone info
10
10
  return new Date(s + 'Z');
11
11
  }
12
12
 
13
13
  const localDateStrRe = /^(\d+)[\./-](\d+)[\./-](\d+)$/;
14
14
 
15
- function localDateStrToInstant(s) {
15
+ function localDateStrToDate(s) {
16
16
  const match = s.match(localDateStrRe);
17
17
  if (!match) {
18
18
  return null;
@@ -31,14 +31,14 @@ function localDateStrToInstant(s) {
31
31
  }
32
32
 
33
33
  // Custom date formatters
34
- function offioDateStrToInstant(s) {
34
+ function offioDateStrToDate(s) {
35
35
  // Format: "yyyy-MM-dd HH:mm:ss"
36
36
  // Treat as UTC
37
37
  const [datePart, timePart] = s.split(' ');
38
38
  return new Date(datePart + 'T' + timePart + 'Z');
39
39
  }
40
40
 
41
- function zenecaDateStrToInstant(s) {
41
+ function zenecaDateStrToDate(s) {
42
42
  // Format: "yyyy-MM-dd HH:mm:ss.n"
43
43
  // Treat as UTC
44
44
  const [datePart, timeWithNanos] = s.split(' ');
@@ -46,12 +46,12 @@ function zenecaDateStrToInstant(s) {
46
46
  return new Date(datePart + 'T' + timeWithNanos + 'Z');
47
47
  }
48
48
 
49
- function rfc1123ToInstant(s) {
49
+ function rfc1123ToDate(s) {
50
50
  // RFC 1123 format is natively supported by Date constructor
51
51
  return new Date(s);
52
52
  }
53
53
 
54
- function dowMonDayYearStrToInstant(s) {
54
+ function dowMonDayYearStrToDate(s) {
55
55
  // Format: "EEE MMM dd yyyy" (e.g., "Wed Jan 15 2025")
56
56
 
57
57
  //Only parse if the string is in the correct format
@@ -76,7 +76,7 @@ function dowMonDayYearStrToInstant(s) {
76
76
  );
77
77
  }
78
78
 
79
- function iso8601IncompleteOffsetToInstant(s) {
79
+ function iso8601IncompleteOffsetToDate(s) {
80
80
  // Format: "2025-01-02T00:00:00-08" (missing minutes in timezone offset)
81
81
  // Convert to proper ISO 8601 format by adding ":00" to the timezone offset
82
82
  const regex = /^(.+T.+)([+-])(\d{2})$/;
@@ -91,7 +91,7 @@ function iso8601IncompleteOffsetToInstant(s) {
91
91
  return null;
92
92
  }
93
93
 
94
- function iso8601SingleDigitToInstant(s) {
94
+ function iso8601SingleDigitToDate(s) {
95
95
  // Format: "2025-11-2T00:00:00.000Z" or "2025-1-2T00:00:00Z" (single-digit month/day)
96
96
  // Also handles space separator: "2025-1-2 00:00:00"
97
97
  // Also handles single-digit hours/minutes/seconds: "2026-04-28T04:7:00.000Z"
@@ -119,7 +119,7 @@ function iso8601SingleDigitToInstant(s) {
119
119
  return null;
120
120
  }
121
121
 
122
- function usDateTimeStrToInstant(s) {
122
+ function usDateTimeStrToDate(s) {
123
123
  // Format: "M/d/yyyy, h:mm:ss a" (e.g., "8/4/2025, 11:02:31 PM")
124
124
  const [datePart, timePart] = s.split(', ');
125
125
  const [month, day, year] = datePart.split('/').map(Number);
@@ -147,7 +147,7 @@ function usDateTimeStrToInstant(s) {
147
147
  }
148
148
 
149
149
  // https://www.postgresql.org/docs/17/datatype-datetime.html#DATATYPE-DATETIME-SPECIAL-VALUES
150
- function specialStrToInstant(s: string) {
150
+ function specialStrToDate(s: string) {
151
151
  switch (s) {
152
152
  case 'epoch':
153
153
  return new Date(0);
@@ -162,7 +162,7 @@ function specialStrToInstant(s: string) {
162
162
  }
163
163
  }
164
164
 
165
- function pgTimezoneStrToInstant(s: string) {
165
+ function pgTimezoneStrToDate(s: string) {
166
166
  const match = s.match(pgTimezoneMatch);
167
167
  if (!match) {
168
168
  return null;
@@ -178,18 +178,18 @@ function pgTimezoneStrToInstant(s: string) {
178
178
 
179
179
  // Array of parsers
180
180
  const dateParsers = [
181
- localDateStrToInstant,
182
- zenecaDateStrToInstant,
183
- dowMonDayYearStrToInstant,
184
- usDateTimeStrToInstant,
185
- localDateTimeStrToInstant,
186
- iso8601IncompleteOffsetToInstant,
187
- offioDateStrToInstant,
188
- zonedDateTimeStrToInstant,
189
- specialStrToInstant,
190
- pgTimezoneStrToInstant,
191
- iso8601SingleDigitToInstant,
192
- rfc1123ToInstant,
181
+ localDateStrToDate,
182
+ zenecaDateStrToDate,
183
+ dowMonDayYearStrToDate,
184
+ usDateTimeStrToDate,
185
+ localDateTimeStrToDate,
186
+ iso8601IncompleteOffsetToDate,
187
+ offioDateStrToDate,
188
+ zonedDateTimeStrToDate,
189
+ specialStrToDate,
190
+ pgTimezoneStrToDate,
191
+ iso8601SingleDigitToDate,
192
+ rfc1123ToDate,
193
193
  ];
194
194
 
195
195
  // Try to parse with a specific parser
@@ -207,22 +207,22 @@ function tryParseDateString(parser, s: string) {
207
207
  }
208
208
 
209
209
  // Try all parsers until one succeeds
210
- function dateStrToInstant(s) {
210
+ function dateStrToDate(s) {
211
211
  for (const parser of dateParsers) {
212
- const instant = tryParseDateString(parser, s);
213
- if (instant) {
214
- return instant;
212
+ const date = tryParseDateString(parser, s);
213
+ if (date) {
214
+ return date;
215
215
  }
216
216
  }
217
217
  return null;
218
218
  }
219
219
 
220
220
  // Parse JSON string and then try date parsing
221
- function jsonStrToInstant(maybeJson: string) {
221
+ function jsonStrToDate(maybeJson: string) {
222
222
  try {
223
223
  const s = JSON.parse(maybeJson);
224
224
  if (typeof s === 'string') {
225
- return dateStrToInstant(s);
225
+ return dateStrToDate(s);
226
226
  }
227
227
  return null;
228
228
  } catch (e) {
@@ -244,7 +244,7 @@ export function coerceToDate(x: unknown): Date | null | undefined {
244
244
  }
245
245
  if (typeof x === 'string') {
246
246
  const result =
247
- dateStrToInstant(x) || jsonStrToInstant(x) || dateStrToInstant(x.trim());
247
+ dateStrToDate(x) || jsonStrToDate(x) || dateStrToDate(x.trim());
248
248
  if (!result) {
249
249
  throw new Error(`Unable to parse \`${x}\` as a date.`);
250
250
  }