@sidekickdb/core 2.0.0 → 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 (321) hide show
  1. package/README.md +1 -1
  2. package/__example__/standalone.esm.html +1 -1
  3. package/__example__/standalone.umd.html +2 -2
  4. package/__tests__/src/Reactor.test.ts +70 -25
  5. package/__tests__/src/batchedFrames.test.ts +110 -0
  6. package/__tests__/src/createRouteHandler.test.ts +30 -0
  7. package/__tests__/src/data/zeneca/triples.json +6 -6
  8. package/__tests__/src/dataForQueryMemo.test.ts +4 -4
  9. package/__tests__/src/datalog.test.ts +2 -2
  10. package/__tests__/src/devtool.test.ts +2 -2
  11. package/__tests__/src/endpoints.test.ts +2 -2
  12. package/__tests__/src/infiniteQuery.test.ts +142 -0
  13. package/__tests__/src/notifyScope.test.ts +6 -6
  14. package/__tests__/src/queryValidation.test.ts +3 -3
  15. package/__tests__/src/schema.test.ts +6 -6
  16. package/__tests__/src/serializeSchema.test.ts +2 -2
  17. package/__tests__/src/{instaml.test.ts → sideml.test.ts} +106 -112
  18. package/__tests__/src/{instaql.bench.ts → sideql.bench.ts} +1 -1
  19. package/__tests__/src/{instaql.test.ts → sideql.test.ts} +25 -34
  20. package/__tests__/src/{instaqlInference.test.ts → sideqlInference.test.ts} +1 -1
  21. package/__tests__/src/store.test.ts +32 -32
  22. package/__tests__/src/transactionValidation.test.ts +4 -4
  23. package/__tests__/src/utils/e2e.ts +8 -8
  24. package/dist/commonjs/Connection.d.ts +1 -0
  25. package/dist/commonjs/Connection.d.ts.map +1 -1
  26. package/dist/commonjs/Connection.js +19 -3
  27. package/dist/commonjs/Connection.js.map +1 -1
  28. package/dist/commonjs/IndexedDBStorage.d.ts.map +1 -1
  29. package/dist/commonjs/IndexedDBStorage.js +3 -160
  30. package/dist/commonjs/IndexedDBStorage.js.map +1 -1
  31. package/dist/commonjs/Reactor.d.ts +7 -7
  32. package/dist/commonjs/Reactor.d.ts.map +1 -1
  33. package/dist/commonjs/Reactor.js +37 -38
  34. package/dist/commonjs/Reactor.js.map +1 -1
  35. package/dist/commonjs/{InstantError.d.ts → SidekickError.d.ts} +2 -2
  36. package/dist/commonjs/SidekickError.d.ts.map +1 -0
  37. package/dist/commonjs/{InstantError.js → SidekickError.js} +7 -7
  38. package/dist/commonjs/SidekickError.js.map +1 -0
  39. package/dist/commonjs/Stream.d.ts +5 -5
  40. package/dist/commonjs/Stream.d.ts.map +1 -1
  41. package/dist/commonjs/Stream.js +14 -14
  42. package/dist/commonjs/Stream.js.map +1 -1
  43. package/dist/commonjs/SyncTable.d.ts +3 -3
  44. package/dist/commonjs/SyncTable.d.ts.map +1 -1
  45. package/dist/commonjs/SyncTable.js +7 -7
  46. package/dist/commonjs/SyncTable.js.map +1 -1
  47. package/dist/commonjs/attrTypes.d.ts +11 -11
  48. package/dist/commonjs/attrTypes.d.ts.map +1 -1
  49. package/dist/commonjs/attrTypes.js.map +1 -1
  50. package/dist/commonjs/coreTypes.d.ts +4 -4
  51. package/dist/commonjs/coreTypes.d.ts.map +1 -1
  52. package/dist/commonjs/coreTypes.js.map +1 -1
  53. package/dist/commonjs/createRouteHandler.d.ts +1 -1
  54. package/dist/commonjs/createRouteHandler.d.ts.map +1 -1
  55. package/dist/commonjs/createRouteHandler.js +5 -5
  56. package/dist/commonjs/createRouteHandler.js.map +1 -1
  57. package/dist/commonjs/devtool.js +13 -6
  58. package/dist/commonjs/devtool.js.map +1 -1
  59. package/dist/commonjs/endpoints.d.ts +2 -2
  60. package/dist/commonjs/endpoints.d.ts.map +1 -1
  61. package/dist/commonjs/endpoints.js +3 -3
  62. package/dist/commonjs/endpoints.js.map +1 -1
  63. package/dist/commonjs/framework.d.ts +4 -4
  64. package/dist/commonjs/framework.d.ts.map +1 -1
  65. package/dist/commonjs/framework.js +5 -5
  66. package/dist/commonjs/framework.js.map +1 -1
  67. package/dist/commonjs/helperTypes.d.ts +24 -24
  68. package/dist/commonjs/helperTypes.d.ts.map +1 -1
  69. package/dist/commonjs/helperTypes.js.map +1 -1
  70. package/dist/commonjs/index.d.ts +36 -36
  71. package/dist/commonjs/index.d.ts.map +1 -1
  72. package/dist/commonjs/index.js +36 -36
  73. package/dist/commonjs/index.js.map +1 -1
  74. package/dist/commonjs/infiniteQuery.d.ts +7 -7
  75. package/dist/commonjs/infiniteQuery.d.ts.map +1 -1
  76. package/dist/commonjs/infiniteQuery.js +16 -3
  77. package/dist/commonjs/infiniteQuery.js.map +1 -1
  78. package/dist/commonjs/model/{instaqlResult.d.ts → sideqlResult.d.ts} +2 -2
  79. package/dist/commonjs/model/sideqlResult.d.ts.map +1 -0
  80. package/dist/commonjs/model/{instaqlResult.js → sideqlResult.js} +2 -2
  81. package/dist/commonjs/model/sideqlResult.js.map +1 -0
  82. package/dist/commonjs/notifyScope.js +3 -3
  83. package/dist/commonjs/notifyScope.js.map +1 -1
  84. package/dist/commonjs/parseSchemaFromJSON.d.ts +2 -2
  85. package/dist/commonjs/parseSchemaFromJSON.d.ts.map +1 -1
  86. package/dist/commonjs/parseSchemaFromJSON.js.map +1 -1
  87. package/dist/commonjs/queryTypes.d.ts +32 -32
  88. package/dist/commonjs/queryTypes.d.ts.map +1 -1
  89. package/dist/commonjs/queryTypes.js.map +1 -1
  90. package/dist/commonjs/routeHandlerProtocol.d.ts +7 -7
  91. package/dist/commonjs/routeHandlerProtocol.d.ts.map +1 -1
  92. package/dist/commonjs/routeHandlerProtocol.js.map +1 -1
  93. package/dist/commonjs/rulesTypes.d.ts +20 -20
  94. package/dist/commonjs/rulesTypes.d.ts.map +1 -1
  95. package/dist/commonjs/rulesTypes.js.map +1 -1
  96. package/dist/commonjs/sanityCheckQueries.d.ts +3 -3
  97. package/dist/commonjs/sanityCheckQueries.d.ts.map +1 -1
  98. package/dist/commonjs/sanityCheckQueries.js.map +1 -1
  99. package/dist/commonjs/schema.d.ts +3 -3
  100. package/dist/commonjs/schema.d.ts.map +1 -1
  101. package/dist/commonjs/schema.js +2 -2
  102. package/dist/commonjs/schema.js.map +1 -1
  103. package/dist/commonjs/schemaTypes.d.ts +8 -8
  104. package/dist/commonjs/schemaTypes.d.ts.map +1 -1
  105. package/dist/commonjs/schemaTypes.js +9 -9
  106. package/dist/commonjs/schemaTypes.js.map +1 -1
  107. package/dist/commonjs/{instaml.d.ts → sideml.d.ts} +1 -1
  108. package/dist/commonjs/sideml.d.ts.map +1 -0
  109. package/dist/commonjs/{instaml.js → sideml.js} +10 -7
  110. package/dist/commonjs/sideml.js.map +1 -0
  111. package/dist/commonjs/{instaql.d.ts → sideql.d.ts} +1 -1
  112. package/dist/commonjs/sideql.d.ts.map +1 -0
  113. package/dist/commonjs/{instaql.js → sideql.js} +1 -1
  114. package/dist/commonjs/sideql.js.map +1 -0
  115. package/dist/commonjs/{instatx.d.ts → sidetx.d.ts} +1 -1
  116. package/dist/commonjs/sidetx.d.ts.map +1 -0
  117. package/dist/commonjs/{instatx.js → sidetx.js} +1 -1
  118. package/dist/commonjs/sidetx.js.map +1 -0
  119. package/dist/commonjs/store.d.ts +22 -22
  120. package/dist/commonjs/store.d.ts.map +1 -1
  121. package/dist/commonjs/store.js +0 -2
  122. package/dist/commonjs/store.js.map +1 -1
  123. package/dist/commonjs/transactionValidation.d.ts +1 -1
  124. package/dist/commonjs/transactionValidation.d.ts.map +1 -1
  125. package/dist/commonjs/transactionValidation.js +2 -2
  126. package/dist/commonjs/transactionValidation.js.map +1 -1
  127. package/dist/commonjs/utils/dates.js +31 -31
  128. package/dist/commonjs/utils/dates.js.map +1 -1
  129. package/dist/commonjs/utils/fetch.d.ts +7 -7
  130. package/dist/commonjs/utils/fetch.d.ts.map +1 -1
  131. package/dist/commonjs/utils/fetch.js +8 -8
  132. package/dist/commonjs/utils/fetch.js.map +1 -1
  133. package/dist/commonjs/utils/flags.d.ts +2 -2
  134. package/dist/commonjs/utils/flags.d.ts.map +1 -1
  135. package/dist/commonjs/utils/flags.js +4 -4
  136. package/dist/commonjs/utils/flags.js.map +1 -1
  137. package/dist/commonjs/utils/linkIndex.d.ts +2 -2
  138. package/dist/commonjs/utils/linkIndex.d.ts.map +1 -1
  139. package/dist/commonjs/utils/linkIndex.js.map +1 -1
  140. package/dist/commonjs/warningToggle.d.ts +1 -1
  141. package/dist/commonjs/warningToggle.d.ts.map +1 -1
  142. package/dist/commonjs/warningToggle.js +3 -3
  143. package/dist/commonjs/warningToggle.js.map +1 -1
  144. package/dist/esm/Connection.d.ts +1 -0
  145. package/dist/esm/Connection.d.ts.map +1 -1
  146. package/dist/esm/Connection.js +18 -3
  147. package/dist/esm/Connection.js.map +1 -1
  148. package/dist/esm/IndexedDBStorage.d.ts.map +1 -1
  149. package/dist/esm/IndexedDBStorage.js +4 -161
  150. package/dist/esm/IndexedDBStorage.js.map +1 -1
  151. package/dist/esm/Reactor.d.ts +7 -7
  152. package/dist/esm/Reactor.d.ts.map +1 -1
  153. package/dist/esm/Reactor.js +38 -39
  154. package/dist/esm/Reactor.js.map +1 -1
  155. package/dist/esm/{InstantError.d.ts → SidekickError.d.ts} +2 -2
  156. package/dist/esm/SidekickError.d.ts.map +1 -0
  157. package/dist/esm/{InstantError.js → SidekickError.js} +5 -5
  158. package/dist/esm/SidekickError.js.map +1 -0
  159. package/dist/esm/Stream.d.ts +5 -5
  160. package/dist/esm/Stream.d.ts.map +1 -1
  161. package/dist/esm/Stream.js +12 -12
  162. package/dist/esm/Stream.js.map +1 -1
  163. package/dist/esm/SyncTable.d.ts +3 -3
  164. package/dist/esm/SyncTable.d.ts.map +1 -1
  165. package/dist/esm/SyncTable.js +3 -3
  166. package/dist/esm/SyncTable.js.map +1 -1
  167. package/dist/esm/attrTypes.d.ts +11 -11
  168. package/dist/esm/attrTypes.d.ts.map +1 -1
  169. package/dist/esm/attrTypes.js.map +1 -1
  170. package/dist/esm/coreTypes.d.ts +4 -4
  171. package/dist/esm/coreTypes.d.ts.map +1 -1
  172. package/dist/esm/coreTypes.js.map +1 -1
  173. package/dist/esm/createRouteHandler.d.ts +1 -1
  174. package/dist/esm/createRouteHandler.d.ts.map +1 -1
  175. package/dist/esm/createRouteHandler.js +3 -3
  176. package/dist/esm/createRouteHandler.js.map +1 -1
  177. package/dist/esm/devtool.js +13 -6
  178. package/dist/esm/devtool.js.map +1 -1
  179. package/dist/esm/endpoints.d.ts +2 -2
  180. package/dist/esm/endpoints.d.ts.map +1 -1
  181. package/dist/esm/endpoints.js +3 -3
  182. package/dist/esm/endpoints.js.map +1 -1
  183. package/dist/esm/framework.d.ts +4 -4
  184. package/dist/esm/framework.d.ts.map +1 -1
  185. package/dist/esm/framework.js +6 -6
  186. package/dist/esm/framework.js.map +1 -1
  187. package/dist/esm/helperTypes.d.ts +24 -24
  188. package/dist/esm/helperTypes.d.ts.map +1 -1
  189. package/dist/esm/helperTypes.js.map +1 -1
  190. package/dist/esm/index.d.ts +36 -36
  191. package/dist/esm/index.d.ts.map +1 -1
  192. package/dist/esm/index.js +33 -33
  193. package/dist/esm/index.js.map +1 -1
  194. package/dist/esm/infiniteQuery.d.ts +7 -7
  195. package/dist/esm/infiniteQuery.d.ts.map +1 -1
  196. package/dist/esm/infiniteQuery.js +16 -3
  197. package/dist/esm/infiniteQuery.js.map +1 -1
  198. package/dist/esm/model/{instaqlResult.d.ts → sideqlResult.d.ts} +2 -2
  199. package/dist/esm/model/sideqlResult.d.ts.map +1 -0
  200. package/dist/esm/model/{instaqlResult.js → sideqlResult.js} +2 -2
  201. package/dist/esm/model/sideqlResult.js.map +1 -0
  202. package/dist/esm/notifyScope.js +3 -3
  203. package/dist/esm/notifyScope.js.map +1 -1
  204. package/dist/esm/parseSchemaFromJSON.d.ts +2 -2
  205. package/dist/esm/parseSchemaFromJSON.d.ts.map +1 -1
  206. package/dist/esm/parseSchemaFromJSON.js.map +1 -1
  207. package/dist/esm/queryTypes.d.ts +32 -32
  208. package/dist/esm/queryTypes.d.ts.map +1 -1
  209. package/dist/esm/queryTypes.js.map +1 -1
  210. package/dist/esm/routeHandlerProtocol.d.ts +7 -7
  211. package/dist/esm/routeHandlerProtocol.d.ts.map +1 -1
  212. package/dist/esm/routeHandlerProtocol.js.map +1 -1
  213. package/dist/esm/rulesTypes.d.ts +20 -20
  214. package/dist/esm/rulesTypes.d.ts.map +1 -1
  215. package/dist/esm/rulesTypes.js.map +1 -1
  216. package/dist/esm/sanityCheckQueries.d.ts +3 -3
  217. package/dist/esm/sanityCheckQueries.d.ts.map +1 -1
  218. package/dist/esm/sanityCheckQueries.js.map +1 -1
  219. package/dist/esm/schema.d.ts +3 -3
  220. package/dist/esm/schema.d.ts.map +1 -1
  221. package/dist/esm/schema.js +3 -3
  222. package/dist/esm/schema.js.map +1 -1
  223. package/dist/esm/schemaTypes.d.ts +8 -8
  224. package/dist/esm/schemaTypes.d.ts.map +1 -1
  225. package/dist/esm/schemaTypes.js +5 -5
  226. package/dist/esm/schemaTypes.js.map +1 -1
  227. package/dist/esm/{instaml.d.ts → sideml.d.ts} +1 -1
  228. package/dist/esm/sideml.d.ts.map +1 -0
  229. package/dist/esm/{instaml.js → sideml.js} +6 -3
  230. package/dist/esm/sideml.js.map +1 -0
  231. package/dist/esm/{instaql.d.ts → sideql.d.ts} +1 -1
  232. package/dist/esm/sideql.d.ts.map +1 -0
  233. package/dist/esm/{instaql.js → sideql.js} +1 -1
  234. package/dist/esm/sideql.js.map +1 -0
  235. package/dist/esm/{instatx.d.ts → sidetx.d.ts} +1 -1
  236. package/dist/esm/sidetx.d.ts.map +1 -0
  237. package/dist/esm/{instatx.js → sidetx.js} +1 -1
  238. package/dist/esm/sidetx.js.map +1 -0
  239. package/dist/esm/store.d.ts +22 -22
  240. package/dist/esm/store.d.ts.map +1 -1
  241. package/dist/esm/store.js +0 -2
  242. package/dist/esm/store.js.map +1 -1
  243. package/dist/esm/transactionValidation.d.ts +1 -1
  244. package/dist/esm/transactionValidation.d.ts.map +1 -1
  245. package/dist/esm/transactionValidation.js +1 -1
  246. package/dist/esm/transactionValidation.js.map +1 -1
  247. package/dist/esm/utils/dates.js +31 -31
  248. package/dist/esm/utils/dates.js.map +1 -1
  249. package/dist/esm/utils/fetch.d.ts +7 -7
  250. package/dist/esm/utils/fetch.d.ts.map +1 -1
  251. package/dist/esm/utils/fetch.js +6 -6
  252. package/dist/esm/utils/fetch.js.map +1 -1
  253. package/dist/esm/utils/flags.d.ts +2 -2
  254. package/dist/esm/utils/flags.d.ts.map +1 -1
  255. package/dist/esm/utils/flags.js +3 -3
  256. package/dist/esm/utils/flags.js.map +1 -1
  257. package/dist/esm/utils/linkIndex.d.ts +2 -2
  258. package/dist/esm/utils/linkIndex.d.ts.map +1 -1
  259. package/dist/esm/utils/linkIndex.js.map +1 -1
  260. package/dist/esm/warningToggle.d.ts +1 -1
  261. package/dist/esm/warningToggle.d.ts.map +1 -1
  262. package/dist/esm/warningToggle.js +1 -1
  263. package/dist/esm/warningToggle.js.map +1 -1
  264. package/dist/standalone/index.js +2705 -2791
  265. package/dist/standalone/index.umd.cjs +9 -6
  266. package/package.json +3 -3
  267. package/src/Connection.ts +18 -3
  268. package/src/IndexedDBStorage.ts +3 -181
  269. package/src/Reactor.js +40 -39
  270. package/src/{InstantError.ts → SidekickError.ts} +4 -4
  271. package/src/Stream.ts +35 -32
  272. package/src/SyncTable.ts +6 -6
  273. package/src/attrTypes.ts +15 -11
  274. package/src/coreTypes.ts +5 -5
  275. package/src/createRouteHandler.ts +9 -7
  276. package/src/devtool.ts +13 -6
  277. package/src/endpoints.ts +4 -4
  278. package/src/framework.ts +13 -13
  279. package/src/helperTypes.ts +37 -37
  280. package/src/index.ts +123 -123
  281. package/src/infiniteQuery.ts +39 -22
  282. package/src/model/{instaqlResult.js → sideqlResult.js} +1 -1
  283. package/src/notifyScope.ts +3 -3
  284. package/src/parseSchemaFromJSON.ts +2 -2
  285. package/src/queryTypes.ts +55 -55
  286. package/src/routeHandlerProtocol.ts +8 -8
  287. package/src/rulesTypes.ts +23 -23
  288. package/src/sanityCheckQueries.ts +9 -9
  289. package/src/schema.ts +3 -3
  290. package/src/schemaTypes.ts +11 -9
  291. package/src/{instaml.ts → sideml.ts} +17 -14
  292. package/src/{instaql.ts → sideql.ts} +5 -5
  293. package/src/store.ts +35 -36
  294. package/src/transactionValidation.ts +1 -1
  295. package/src/utils/dates.ts +31 -31
  296. package/src/utils/fetch.ts +13 -13
  297. package/src/utils/flags.ts +3 -3
  298. package/src/utils/linkIndex.ts +2 -2
  299. package/src/warningToggle.ts +1 -1
  300. package/vite.config.ts +1 -1
  301. package/dist/commonjs/InstantError.d.ts.map +0 -1
  302. package/dist/commonjs/InstantError.js.map +0 -1
  303. package/dist/commonjs/instaml.d.ts.map +0 -1
  304. package/dist/commonjs/instaml.js.map +0 -1
  305. package/dist/commonjs/instaql.d.ts.map +0 -1
  306. package/dist/commonjs/instaql.js.map +0 -1
  307. package/dist/commonjs/instatx.d.ts.map +0 -1
  308. package/dist/commonjs/instatx.js.map +0 -1
  309. package/dist/commonjs/model/instaqlResult.d.ts.map +0 -1
  310. package/dist/commonjs/model/instaqlResult.js.map +0 -1
  311. package/dist/esm/InstantError.d.ts.map +0 -1
  312. package/dist/esm/InstantError.js.map +0 -1
  313. package/dist/esm/instaml.d.ts.map +0 -1
  314. package/dist/esm/instaml.js.map +0 -1
  315. package/dist/esm/instaql.d.ts.map +0 -1
  316. package/dist/esm/instaql.js.map +0 -1
  317. package/dist/esm/instatx.d.ts.map +0 -1
  318. package/dist/esm/instatx.js.map +0 -1
  319. package/dist/esm/model/instaqlResult.d.ts.map +0 -1
  320. package/dist/esm/model/instaqlResult.js.map +0 -1
  321. /package/src/{instatx.ts → sidetx.ts} +0 -0
@@ -1,16 +1,11 @@
1
1
  import {
2
2
  coerceQuery,
3
3
  QueryValidationError,
4
- type InstantCoreDatabase,
4
+ type SidekickCoreDatabase,
5
5
  type ValidQuery,
6
6
  } from './index.ts';
7
- import {
8
- InstaQLResponse,
9
- InstaQLOptions,
10
- Cursor,
11
- Order,
12
- } from './queryTypes.ts';
13
- import { InstantSchemaDef } from './schemaTypes.ts';
7
+ import { SideQLResponse, SideQLOptions, Cursor, Order } from './queryTypes.ts';
8
+ import { SidekickSchemaDef } from './schemaTypes.ts';
14
9
  import { assert } from './utils/error.ts';
15
10
 
16
11
  // Example for {order: {value: "asc"}}
@@ -111,7 +106,7 @@ const readCanLoadNextPage = (forwardChunks: Map<string, Chunk>) => {
111
106
  };
112
107
 
113
108
  const reverseOrder = <
114
- Schema extends InstantSchemaDef<any, any, any>,
109
+ Schema extends SidekickSchemaDef<any, any, any>,
115
110
  Entity extends keyof Schema['entities'],
116
111
  >(
117
112
  order?: Order<Schema, Entity>,
@@ -133,7 +128,7 @@ const reverseOrder = <
133
128
  };
134
129
 
135
130
  const resolveOrder = <
136
- Schema extends InstantSchemaDef<any, any, any>,
131
+ Schema extends SidekickSchemaDef<any, any, any>,
137
132
  Entity extends keyof Schema['entities'],
138
133
  >(
139
134
  order?: Order<Schema, Entity>,
@@ -169,7 +164,7 @@ const normalizeChunks = (
169
164
  const PRE_BOOTSTRAP_CURSOR: Cursor = ['bootstrap', 'bootstrap', 'bootstrap', 1];
170
165
 
171
166
  export type InfiniteQueryCallbackResponse<
172
- Schema extends InstantSchemaDef<any, any, any>,
167
+ Schema extends SidekickSchemaDef<any, any, any>,
173
168
  Query extends Record<string, any>,
174
169
  UseDatesLocal extends boolean,
175
170
  > =
@@ -180,19 +175,19 @@ export type InfiniteQueryCallbackResponse<
180
175
  }
181
176
  | {
182
177
  error: undefined;
183
- data: InstaQLResponse<Schema, Query, UseDatesLocal>;
178
+ data: SideQLResponse<Schema, Query, UseDatesLocal>;
184
179
  canLoadNextPage: boolean;
185
180
  };
186
181
 
187
182
  export const subscribeInfiniteQuery = <
188
- Schema extends InstantSchemaDef<any, any, any>,
183
+ Schema extends SidekickSchemaDef<any, any, any>,
189
184
  Q extends ValidQuery<Q, Schema>,
190
185
  UseDates extends boolean,
191
186
  >(
192
- db: InstantCoreDatabase<Schema, UseDates>,
187
+ db: SidekickCoreDatabase<Schema, UseDates>,
193
188
  fullQuery: Q,
194
189
  cb: (resp: InfiniteQueryCallbackResponse<Schema, Q, UseDates>) => void,
195
- opts?: InstaQLOptions,
190
+ opts?: SideQLOptions,
196
191
  ): InfiniteQuerySubscription => {
197
192
  const { entityName, entityQuery: query } = splitAndValidateQuery(fullQuery);
198
193
 
@@ -209,6 +204,9 @@ export const subscribeInfiniteQuery = <
209
204
  let isActive = true;
210
205
  let lastReverseAdvancedChunkKey: string | null = null;
211
206
  let starterUnsub: (() => void) | null = null;
207
+ // SidekickDB: id of the first row of a full page shown from optimistic data,
208
+ // before the server gave a start cursor.
209
+ let optimisticPageFirstId: string | null = null;
212
210
 
213
211
  const sendError = (err: { message: string }) => {
214
212
  cb({ error: err, data: undefined, canLoadNextPage: false });
@@ -219,7 +217,7 @@ export const subscribeInfiniteQuery = <
219
217
 
220
218
  const { chunks, data } = normalizeChunks(forwardChunks, reverseChunks);
221
219
  cb({
222
- data: { [entity]: data } as InstaQLResponse<
220
+ data: { [entity]: data } as SideQLResponse<
223
221
  Schema,
224
222
  typeof query,
225
223
  UseDates
@@ -321,13 +319,17 @@ export const subscribeInfiniteQuery = <
321
319
  allUnsubs.set(chunkSubKey('reverse', startCursor), querySub);
322
320
  };
323
321
 
324
- const pushNewForward = (startCursor: Cursor, afterInclusive = false) => {
322
+ const pushNewForward = (
323
+ startCursor: Cursor,
324
+ afterInclusive = false,
325
+ limit = pageSize,
326
+ ) => {
325
327
  const querySub = db.subscribeQuery(
326
328
  {
327
329
  [entity]: {
328
330
  ...query,
329
331
  $: {
330
- limit: pageSize,
332
+ limit,
331
333
  after: startCursor,
332
334
  afterInclusive,
333
335
  where: query.$?.where,
@@ -492,6 +494,7 @@ export const subscribeInfiniteQuery = <
492
494
  // state.
493
495
  const initialForwardCursor = pageInfo.startCursor;
494
496
  if (!initialForwardCursor) {
497
+ optimisticPageFirstId ??= rows[0]?.id ?? null;
495
498
  setForwardChunk(PRE_BOOTSTRAP_CURSOR, {
496
499
  data: rows,
497
500
  status: 'pre-bootstrap',
@@ -501,7 +504,21 @@ export const subscribeInfiniteQuery = <
501
504
 
502
505
  forwardChunks.delete(makeChunkKey(PRE_BOOTSTRAP_CURSOR));
503
506
 
504
- pushNewForward(initialForwardCursor, true);
507
+ // SidekickDB: rows added before an optimistic full page while the
508
+ // server had not yet answered with a start cursor would otherwise push
509
+ // that page's last rows out of the first chunk. The first chunk keeps
510
+ // them by growing by that many rows.
511
+ const shownStart = rows.findIndex(
512
+ (row: any) => row.id === optimisticPageFirstId,
513
+ );
514
+ const serverStart = rows.findIndex(
515
+ (row: any) => row.id === initialForwardCursor[0],
516
+ );
517
+ const addedBefore =
518
+ serverStart >= 0 && shownStart > serverStart
519
+ ? shownStart - serverStart
520
+ : 0;
521
+ pushNewForward(initialForwardCursor, true, pageSize + addedBefore);
505
522
  pushNewReverse(pageInfo.startCursor);
506
523
  hasKickstarted = true;
507
524
  },
@@ -526,13 +543,13 @@ export const subscribeInfiniteQuery = <
526
543
  };
527
544
 
528
545
  export const getInfiniteQueryInitialSnapshot = <
529
- Schema extends InstantSchemaDef<any, any, any>,
546
+ Schema extends SidekickSchemaDef<any, any, any>,
530
547
  Q extends ValidQuery<Q, Schema>,
531
548
  UseDates extends boolean,
532
549
  >(
533
- db: InstantCoreDatabase<Schema, UseDates>,
550
+ db: SidekickCoreDatabase<Schema, UseDates>,
534
551
  fullQuery: Q | null,
535
- opts?: InstaQLOptions,
552
+ opts?: SideQLOptions,
536
553
  ):
537
554
  | InfiniteQueryCallbackResponse<Schema, Q, UseDates>
538
555
  | {
@@ -13,7 +13,7 @@ function _extractTriplesHelper(idNodes, acc = []) {
13
13
  }
14
14
 
15
15
  /**
16
- * Marshall instaql-result into list of triples. Instaql-result may have
16
+ * Marshall sideql-result into list of triples. Sideql-result may have
17
17
  * multiple datalog-results, each datalog-result may have multiple join-rows
18
18
  * and each join-row may have triples.The union of these triples may have
19
19
  * duplicates, so we dedup them.
@@ -128,7 +128,7 @@ export function mutationFootprint(
128
128
  return fp;
129
129
  }
130
130
 
131
- // The `where` operators instaql understands. Anything else is unknown.
131
+ // The `where` operators sideql understands. Anything else is unknown.
132
132
  const WHERE_OPS = new Set([
133
133
  '$in',
134
134
  'in',
@@ -183,7 +183,7 @@ function readWhere(
183
183
  }
184
184
  continue;
185
185
  }
186
- // instaql ignores it.
186
+ // sideql ignores it.
187
187
  if (k === '$entityIdStartsWith') continue;
188
188
  if (!isKnownWhereValue(v)) return false;
189
189
 
@@ -250,7 +250,7 @@ function readLevel(
250
250
  if (typeof f !== 'string') return false;
251
251
  fp.keys.add(`a|${etype}|${f}`);
252
252
  }
253
- // instaql always returns the id.
253
+ // sideql always returns the id.
254
254
  fp.keys.add(`a|${etype}|id`);
255
255
  }
256
256
 
@@ -1,9 +1,9 @@
1
1
  import { i } from './schema.ts';
2
- import { DataAttrDef, InstantSchemaDef } from './schemaTypes.ts';
2
+ import { DataAttrDef, SidekickSchemaDef } from './schemaTypes.ts';
3
3
 
4
4
  export const parseSchemaFromJSON = (
5
5
  s: any,
6
- ): InstantSchemaDef<any, any, any> => {
6
+ ): SidekickSchemaDef<any, any, any> => {
7
7
  // Parse entities
8
8
  const entities: Record<string, any> = {};
9
9
 
package/src/queryTypes.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  import type {
5
5
  EntitiesDef,
6
6
  IContainEntitiesAndLinks,
7
- InstantGraph,
7
+ SidekickGraph,
8
8
  LinkAttrDef,
9
9
  RuleParams,
10
10
  ResolveAttrs,
@@ -12,7 +12,7 @@ import type {
12
12
  DataAttrDef,
13
13
  AttrsDefs,
14
14
  EntityDefFromSchema,
15
- InstantUnknownSchemaDef,
15
+ SidekickUnknownSchemaDef,
16
16
  } from './schemaTypes.ts';
17
17
 
18
18
  type BuiltIn = Date | Function | Error | RegExp;
@@ -164,7 +164,7 @@ type $Option<
164
164
  afterInclusive?: boolean;
165
165
  before?: Cursor;
166
166
  beforeInclusive?: boolean;
167
- fields?: InstaQLFields<S, K>;
167
+ fields?: SideQLFields<S, K>;
168
168
  };
169
169
  };
170
170
 
@@ -178,14 +178,14 @@ interface Query {
178
178
  [namespace: string]: NamespaceVal;
179
179
  }
180
180
 
181
- type InstantObject = {
181
+ type SidekickObject = {
182
182
  id: string;
183
183
  [prop: string]: any;
184
184
  };
185
185
 
186
186
  type ResponseObject<K, Schema> = K extends keyof Schema
187
187
  ? { id: string } & Schema[K]
188
- : InstantObject;
188
+ : SidekickObject;
189
189
 
190
190
  type IsEmptyObject<T> = T extends Record<string, never> ? true : false;
191
191
 
@@ -209,14 +209,14 @@ type QueryResponse<
209
209
  WithCardinalityInference extends boolean = false,
210
210
  UseDates extends boolean = false,
211
211
  > =
212
- Schema extends InstantGraph<infer E, any>
213
- ? InstaQLQueryResult<E, Q, WithCardinalityInference, UseDates>
212
+ Schema extends SidekickGraph<infer E, any>
213
+ ? SideQLQueryResult<E, Q, WithCardinalityInference, UseDates>
214
214
  : ResponseOf<{ [K in keyof Q]: Remove$<Q[K]> }, Schema>;
215
215
 
216
- type InstaQLResponse<Schema, Q, UseDates extends boolean = false> =
216
+ type SideQLResponse<Schema, Q, UseDates extends boolean = false> =
217
217
  Schema extends IContainEntitiesAndLinks<any, any>
218
- ? Q extends InstaQLParams<Schema> | undefined
219
- ? InstaQLResult<Schema, Q, UseDates>
218
+ ? Q extends SideQLParams<Schema> | undefined
219
+ ? SideQLResult<Schema, Q, UseDates>
220
220
  : never
221
221
  : never;
222
222
 
@@ -270,12 +270,12 @@ type SafeLookup<T, K extends readonly PropertyKey[]> = K extends [
270
270
  : T;
271
271
 
272
272
  // ==========
273
- // InstaQL helpers
273
+ // SideQL helpers
274
274
 
275
- type InstaQLEntitySubqueryResult<
275
+ type SideQLEntitySubqueryResult<
276
276
  Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
277
277
  EntityName extends keyof Schema['entities'],
278
- Query extends InstaQLEntitySubquery<Schema, EntityName> | undefined = {},
278
+ Query extends SideQLEntitySubquery<Schema, EntityName> | undefined = {},
279
279
  UseDates extends boolean = false,
280
280
  > = {
281
281
  [QueryPropName in keyof Query]: Schema['entities'][EntityName]['links'][QueryPropName] extends LinkAttrDef<
@@ -285,7 +285,7 @@ type InstaQLEntitySubqueryResult<
285
285
  ? LinkedEntityName extends keyof Schema['entities']
286
286
  ? Cardinality extends 'one'
287
287
  ?
288
- | InstaQLEntity<
288
+ | SideQLEntity<
289
289
  Schema,
290
290
  LinkedEntityName,
291
291
  Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>,
@@ -293,7 +293,7 @@ type InstaQLEntitySubqueryResult<
293
293
  UseDates
294
294
  >
295
295
  | undefined
296
- : InstaQLEntity<
296
+ : SideQLEntity<
297
297
  Schema,
298
298
  LinkedEntityName,
299
299
  Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>,
@@ -304,7 +304,7 @@ type InstaQLEntitySubqueryResult<
304
304
  : never;
305
305
  };
306
306
 
307
- type InstaQLQueryEntityLinksResult<
307
+ type SideQLQueryEntityLinksResult<
308
308
  Entities extends EntitiesDef,
309
309
  EntityName extends keyof Entities,
310
310
  Query extends {
@@ -321,7 +321,7 @@ type InstaQLQueryEntityLinksResult<
321
321
  ? WithCardinalityInference extends true
322
322
  ? Cardinality extends 'one'
323
323
  ?
324
- | InstaQLQueryEntityResult<
324
+ | SideQLQueryEntityResult<
325
325
  Entities,
326
326
  LinkedEntityName,
327
327
  Query[QueryPropName],
@@ -329,14 +329,14 @@ type InstaQLQueryEntityLinksResult<
329
329
  UseDates
330
330
  >
331
331
  | undefined
332
- : InstaQLQueryEntityResult<
332
+ : SideQLQueryEntityResult<
333
333
  Entities,
334
334
  LinkedEntityName,
335
335
  Query[QueryPropName],
336
336
  WithCardinalityInference,
337
337
  UseDates
338
338
  >[]
339
- : InstaQLQueryEntityResult<
339
+ : SideQLQueryEntityResult<
340
340
  Entities,
341
341
  LinkedEntityName,
342
342
  Query[QueryPropName],
@@ -352,7 +352,7 @@ type DistributePick<T, K extends string> = T extends any
352
352
  ? { [P in K]: P extends keyof T ? T[P] : never }
353
353
  : never;
354
354
 
355
- type InstaQLFields<
355
+ type SideQLFields<
356
356
  S extends IContainEntitiesAndLinks<any, any>,
357
357
  K extends keyof S['entities'],
358
358
  > = (Extract<keyof ResolveEntityAttrs<S['entities'][K]>, string> | 'id')[];
@@ -364,21 +364,21 @@ type ComputeAttrs<
364
364
  ? DistributePick<AllAttrs, Exclude<Fields[number], 'id'>>
365
365
  : AllAttrs;
366
366
 
367
- type InstaQLEntity<
367
+ type SideQLEntity<
368
368
  Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
369
369
  EntityName extends keyof Schema['entities'],
370
- Subquery extends InstaQLEntitySubquery<Schema, EntityName> | undefined = {},
371
- Fields extends InstaQLFields<Schema, EntityName> | undefined = undefined,
370
+ Subquery extends SideQLEntitySubquery<Schema, EntityName> | undefined = {},
371
+ Fields extends SideQLFields<Schema, EntityName> | undefined = undefined,
372
372
  UseDates extends boolean = false,
373
373
  > = Expand<
374
374
  { id: string } & ComputeAttrs<
375
375
  ResolveEntityAttrs<Schema['entities'][EntityName], UseDates>,
376
376
  Fields
377
377
  > &
378
- InstaQLEntitySubqueryResult<Schema, EntityName, Subquery, UseDates>
378
+ SideQLEntitySubqueryResult<Schema, EntityName, Subquery, UseDates>
379
379
  >;
380
380
 
381
- export type InstaQLQueryEntityResult<
381
+ export type SideQLQueryEntityResult<
382
382
  Entities extends EntitiesDef,
383
383
  EntityName extends keyof Entities,
384
384
  Query extends {
@@ -387,7 +387,7 @@ export type InstaQLQueryEntityResult<
387
387
  WithCardinalityInference extends boolean,
388
388
  UseDates extends boolean,
389
389
  > = { id: string } & ResolveAttrs<Entities, EntityName, UseDates> &
390
- InstaQLQueryEntityLinksResult<
390
+ SideQLQueryEntityLinksResult<
391
391
  Entities,
392
392
  EntityName,
393
393
  Query,
@@ -395,14 +395,14 @@ export type InstaQLQueryEntityResult<
395
395
  UseDates
396
396
  >;
397
397
 
398
- type InstaQLQueryResult<
398
+ type SideQLQueryResult<
399
399
  Entities extends EntitiesDef,
400
400
  Query,
401
401
  WithCardinalityInference extends boolean,
402
402
  UseDates extends boolean,
403
403
  > = {
404
404
  [QueryPropName in keyof Query]: QueryPropName extends keyof Entities
405
- ? InstaQLQueryEntityResult<
405
+ ? SideQLQueryEntityResult<
406
406
  Entities,
407
407
  QueryPropName,
408
408
  Query[QueryPropName],
@@ -412,13 +412,13 @@ type InstaQLQueryResult<
412
412
  : never;
413
413
  };
414
414
 
415
- type InstaQLResult<
415
+ type SideQLResult<
416
416
  Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
417
- Query extends InstaQLParams<Schema> | undefined,
417
+ Query extends SideQLParams<Schema> | undefined,
418
418
  UseDates extends boolean = false,
419
419
  > = Expand<{
420
420
  [QueryPropName in keyof Query]: QueryPropName extends keyof Schema['entities']
421
- ? InstaQLEntity<
421
+ ? SideQLEntity<
422
422
  Schema,
423
423
  QueryPropName,
424
424
  Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>,
@@ -428,52 +428,52 @@ type InstaQLResult<
428
428
  : never;
429
429
  }>;
430
430
 
431
- type InstaQLEntitySubquery<
431
+ type SideQLEntitySubquery<
432
432
  Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
433
433
  EntityName extends keyof Schema['entities'],
434
434
  > = {
435
435
  [QueryPropName in keyof Schema['entities'][EntityName]['links']]?:
436
436
  | $Option<Schema, EntityName>
437
437
  | ($Option<Schema, EntityName> &
438
- InstaQLEntitySubquery<
438
+ SideQLEntitySubquery<
439
439
  Schema,
440
440
  Schema['entities'][EntityName]['links'][QueryPropName]['entityName']
441
441
  >);
442
442
  };
443
443
 
444
- type InstaQLQuerySubqueryParams<
444
+ type SideQLQuerySubqueryParams<
445
445
  S extends IContainEntitiesAndLinks<any, any>,
446
446
  E extends keyof S['entities'],
447
447
  > = {
448
448
  [K in keyof S['entities'][E]['links']]?:
449
449
  | $Option<S, S['entities'][E]['links'][K]['entityName']>
450
450
  | ($Option<S, S['entities'][E]['links'][K]['entityName']> &
451
- InstaQLQuerySubqueryParams<
451
+ SideQLQuerySubqueryParams<
452
452
  S,
453
453
  S['entities'][E]['links'][K]['entityName']
454
454
  >);
455
455
  };
456
456
 
457
- type InstaQLParams<S extends IContainEntitiesAndLinks<any, any>> = {
457
+ type SideQLParams<S extends IContainEntitiesAndLinks<any, any>> = {
458
458
  [K in keyof S['entities']]?:
459
459
  | $Option<S, K>
460
- | ($Option<S, K> & InstaQLQuerySubqueryParams<S, K>);
460
+ | ($Option<S, K> & SideQLQuerySubqueryParams<S, K>);
461
461
  };
462
462
 
463
463
  /**
464
464
  * @deprecated
465
- * `InstaQLQueryParams` is deprecated. Use `InstaQLParams` instead.
465
+ * `SideQLQueryParams` is deprecated. Use `SideQLParams` instead.
466
466
  *
467
467
  * @example
468
468
  * // Before
469
- * const myQuery = {...} satisfies InstaQLQueryParams<Schema>
469
+ * const myQuery = {...} satisfies SideQLQueryParams<Schema>
470
470
  * // After
471
- * const myQuery = {...} satisfies InstaQLParams<Schema>
471
+ * const myQuery = {...} satisfies SideQLParams<Schema>
472
472
  */
473
- type InstaQLQueryParams<S extends IContainEntitiesAndLinks<any, any>> =
474
- InstaQLParams<S>;
473
+ type SideQLQueryParams<S extends IContainEntitiesAndLinks<any, any>> =
474
+ SideQLParams<S>;
475
475
 
476
- type InstaQLOptions = {
476
+ type SideQLOptions = {
477
477
  ruleParams: RuleParams;
478
478
  };
479
479
 
@@ -692,8 +692,8 @@ type ExtractAttrFromDotPath<
692
692
  type ValidQuery<
693
693
  Q extends Record<string, any>,
694
694
  S extends IContainEntitiesAndLinks<any, any>,
695
- > = S extends InstantUnknownSchemaDef
696
- ? InstaQLParams<S>
695
+ > = S extends SidekickUnknownSchemaDef
696
+ ? SideQLParams<S>
697
697
  : keyof Q extends keyof S['entities']
698
698
  ? {
699
699
  [K in keyof S['entities']]?: ValidQueryObject<Q[K], S, K, true>;
@@ -703,19 +703,19 @@ type ValidQuery<
703
703
  export {
704
704
  Query,
705
705
  QueryResponse,
706
- InstaQLResponse,
706
+ SideQLResponse,
707
707
  PageInfoResponse,
708
- InstantObject,
708
+ SidekickObject,
709
709
  Exactly,
710
710
  Remove$,
711
711
  ValidQuery,
712
- InstaQLQueryResult,
713
- InstaQLParams,
714
- InstaQLOptions,
715
- InstaQLEntitySubquery,
716
- InstaQLEntity,
717
- InstaQLResult,
718
- InstaQLFields,
712
+ SideQLQueryResult,
713
+ SideQLParams,
714
+ SideQLOptions,
715
+ SideQLEntitySubquery,
716
+ SideQLEntity,
717
+ SideQLResult,
718
+ SideQLFields,
719
719
  Cursor,
720
- InstaQLQueryParams,
720
+ SideQLQueryParams,
721
721
  };
@@ -2,23 +2,23 @@ import type { User } from './clientTypes.ts';
2
2
 
3
3
  /**
4
4
  * Known payloads sent to `firstPartyPath` and handled by
5
- * `createInstantRouteHandler`.
5
+ * `createSidekickRouteHandler`.
6
6
  */
7
- export type InstantRouteHandlerPayloadByType = {
7
+ export type SidekickRouteHandlerPayloadByType = {
8
8
  'sync-user': {
9
9
  appId: string;
10
10
  user: User | null;
11
11
  };
12
12
  };
13
13
 
14
- /** Known `type` values for Instant route handler request bodies. */
15
- export type InstantRouteHandlerType = keyof InstantRouteHandlerPayloadByType;
14
+ /** Known `type` values for SidekickDB route handler request bodies. */
15
+ export type SidekickRouteHandlerType = keyof SidekickRouteHandlerPayloadByType;
16
16
 
17
- /** A valid request body for Instant's first-party route handler protocol. */
18
- export type InstantRouteHandlerBody<
19
- Type extends InstantRouteHandlerType = InstantRouteHandlerType,
17
+ /** A valid request body for SidekickDB's first-party route handler protocol. */
18
+ export type SidekickRouteHandlerBody<
19
+ Type extends SidekickRouteHandlerType = SidekickRouteHandlerType,
20
20
  > = {
21
21
  [KnownType in Type]: {
22
22
  type: KnownType;
23
- } & InstantRouteHandlerPayloadByType[KnownType];
23
+ } & SidekickRouteHandlerPayloadByType[KnownType];
24
24
  }[Type];
package/src/rulesTypes.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { InstantSchemaDef, InstantUnknownSchema } from './schemaTypes.ts';
1
+ import { SidekickSchemaDef, SidekickUnknownSchema } from './schemaTypes.ts';
2
2
 
3
- type InstantRulesAttrsAllowBlock = {
3
+ type SidekickRulesAttrsAllowBlock = {
4
4
  $default?: string | null | undefined;
5
5
  view?: string | null | undefined;
6
6
  create?: string | null | undefined;
@@ -8,7 +8,7 @@ type InstantRulesAttrsAllowBlock = {
8
8
  delete?: string | null | undefined;
9
9
  };
10
10
 
11
- export type InstantRulesAllowBlock = InstantRulesAttrsAllowBlock & {
11
+ export type SidekickRulesAllowBlock = SidekickRulesAttrsAllowBlock & {
12
12
  link?: { [key: string]: string } | null | undefined;
13
13
  unlink?: { [key: string]: string } | null | undefined;
14
14
  };
@@ -18,13 +18,13 @@ export type InstantRulesAllowBlock = InstantRulesAttrsAllowBlock & {
18
18
  * - `'greedy'`: tokens trickle in continuously over the period.
19
19
  * - `'interval'`: all tokens are added at once when the period elapses.
20
20
  */
21
- export type InstantRulesRateLimitRefillType = 'interval' | 'greedy';
21
+ export type SidekickRulesRateLimitRefillType = 'interval' | 'greedy';
22
22
 
23
23
  /**
24
24
  * Configuration for how a rate limit bucket refills.
25
25
  * All fields are optional and have sensible defaults.
26
26
  */
27
- export type InstantRulesRateLimitRefill = {
27
+ export type SidekickRulesRateLimitRefill = {
28
28
  /** Number of tokens added per refill. Defaults to the bucket's capacity. */
29
29
  amount?: number | null | undefined;
30
30
  /**
@@ -33,41 +33,41 @@ export type InstantRulesRateLimitRefill = {
33
33
  */
34
34
  period?: string | null | undefined;
35
35
  /** Refill strategy. Defaults to `"greedy"`. */
36
- type?: InstantRulesRateLimitRefillType | null | undefined;
36
+ type?: SidekickRulesRateLimitRefillType | null | undefined;
37
37
  };
38
38
 
39
39
  /**
40
40
  * A single rate limit within a bucket. Each limit represents one token bucket
41
41
  * constraint. You can combine multiple limits (e.g. a burst limit and a sustained limit).
42
42
  */
43
- export type InstantRulesRateLimitLimit = {
43
+ export type SidekickRulesRateLimitLimit = {
44
44
  /** Maximum number of tokens in the bucket. */
45
45
  capacity: number;
46
46
  /** Refill configuration. Defaults to greedy refill of the full capacity every hour. */
47
- refill?: InstantRulesRateLimitRefill | null | undefined;
47
+ refill?: SidekickRulesRateLimitRefill | null | undefined;
48
48
  };
49
49
 
50
50
  /**
51
51
  * A named rate limit bucket configuration. Use in permission rules via
52
52
  * `rateLimit.bucketName.limit(key)`.
53
53
  */
54
- export type InstantRulesRateLimit = {
54
+ export type SidekickRulesRateLimit = {
55
55
  /** One or more token bucket limits to apply. */
56
- limits: Array<InstantRulesRateLimitLimit>;
56
+ limits: Array<SidekickRulesRateLimitLimit>;
57
57
  };
58
58
 
59
59
  /**
60
60
  * Map of rate limit names to their configurations.
61
61
  * Defined under the `$rateLimits` key in your permission rules.
62
62
  */
63
- export type InstantRulesRateLimits = Record<string, InstantRulesRateLimit>;
63
+ export type SidekickRulesRateLimits = Record<string, SidekickRulesRateLimit>;
64
64
 
65
- type InstantRulesEntityBlock<
66
- Schema extends InstantSchemaDef<any, any, any>,
65
+ type SidekickRulesEntityBlock<
66
+ Schema extends SidekickSchemaDef<any, any, any>,
67
67
  EntityName extends keyof Schema['entities'],
68
68
  > = {
69
69
  bind?: string[] | Record<string, string>;
70
- allow: InstantRulesAllowBlock;
70
+ allow: SidekickRulesAllowBlock;
71
71
  fields?: {
72
72
  [AttrName in Exclude<
73
73
  keyof Schema['entities'][EntityName]['attrs'],
@@ -83,21 +83,21 @@ type InstantRulesEntityBlock<
83
83
  // 2. If you do pass a schema, then we can handle each special key separately
84
84
  // without it collapsing into string.
85
85
 
86
- export type InstantRules<
87
- Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,
86
+ export type SidekickRules<
87
+ Schema extends SidekickSchemaDef<any, any, any> = SidekickUnknownSchema,
88
88
  > = {
89
89
  [K in 'attrs' | '$default' | '$rateLimits']?: K extends 'attrs'
90
90
  ? {
91
91
  bind?: string[] | Record<string, string>;
92
- allow: InstantRulesAttrsAllowBlock;
92
+ allow: SidekickRulesAttrsAllowBlock;
93
93
  }
94
94
  : K extends '$default'
95
95
  ? {
96
96
  bind?: string[] | Record<string, string>;
97
- allow: InstantRulesAllowBlock;
97
+ allow: SidekickRulesAllowBlock;
98
98
  }
99
99
  : K extends '$rateLimits'
100
- ? InstantRulesRateLimits
100
+ ? SidekickRulesRateLimits
101
101
  : never;
102
102
  } & {
103
103
  [K in
@@ -107,16 +107,16 @@ export type InstantRules<
107
107
  | '$rateLimits']?: K extends 'attrs'
108
108
  ? {
109
109
  bind?: string[] | Record<string, string>;
110
- allow: InstantRulesAttrsAllowBlock;
110
+ allow: SidekickRulesAttrsAllowBlock;
111
111
  }
112
112
  : K extends '$default'
113
113
  ? {
114
114
  bind?: string[] | Record<string, string>;
115
- allow: InstantRulesAllowBlock;
115
+ allow: SidekickRulesAllowBlock;
116
116
  }
117
117
  : K extends '$rateLimits'
118
- ? InstantRulesRateLimits
118
+ ? SidekickRulesRateLimits
119
119
  : K extends keyof Schema['entities']
120
- ? InstantRulesEntityBlock<Schema, K>
120
+ ? SidekickRulesEntityBlock<Schema, K>
121
121
  : never;
122
122
  };