shelving 1.76.2 → 1.79.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 (308) hide show
  1. package/{api → modules/api}/Resource.d.ts +0 -0
  2. package/{api → modules/api}/Resource.js +0 -0
  3. package/{api → modules/api}/index.d.ts +0 -0
  4. package/{api → modules/api}/index.js +0 -0
  5. package/{constraint → modules/constraint}/Constraint.d.ts +0 -0
  6. package/{constraint → modules/constraint}/Constraint.js +0 -0
  7. package/{constraint → modules/constraint}/Constraints.d.ts +1 -1
  8. package/{constraint → modules/constraint}/Constraints.js +0 -0
  9. package/{constraint → modules/constraint}/FilterConstraint.d.ts +6 -6
  10. package/{constraint → modules/constraint}/FilterConstraint.js +1 -1
  11. package/{constraint → modules/constraint}/FilterConstraints.d.ts +5 -5
  12. package/{constraint → modules/constraint}/FilterConstraints.js +0 -0
  13. package/{constraint → modules/constraint}/QueryConstraints.d.ts +4 -4
  14. package/{constraint → modules/constraint}/QueryConstraints.js +2 -2
  15. package/{constraint → modules/constraint}/SortConstraint.d.ts +4 -3
  16. package/{constraint → modules/constraint}/SortConstraint.js +2 -3
  17. package/{constraint → modules/constraint}/SortConstraints.d.ts +5 -5
  18. package/{constraint → modules/constraint}/SortConstraints.js +0 -0
  19. package/{constraint → modules/constraint}/index.d.ts +0 -0
  20. package/{constraint → modules/constraint}/index.js +0 -0
  21. package/{db → modules/db}/Change.d.ts +10 -13
  22. package/{db → modules/db}/Change.js +2 -2
  23. package/modules/db/Collection.d.ts +74 -0
  24. package/{db → modules/db}/Collection.js +47 -7
  25. package/modules/db/Database.d.ts +76 -0
  26. package/modules/db/Database.js +95 -0
  27. package/{db → modules/db}/Item.d.ts +9 -9
  28. package/{db → modules/db}/Item.js +19 -21
  29. package/{db → modules/db}/Query.d.ts +6 -6
  30. package/{db → modules/db}/Query.js +2 -3
  31. package/{db → modules/db}/index.d.ts +0 -0
  32. package/{db → modules/db}/index.js +0 -0
  33. package/{error → modules/error}/AssertionError.d.ts +0 -0
  34. package/{error → modules/error}/AssertionError.js +0 -0
  35. package/{error → modules/error}/ConditionError.d.ts +0 -0
  36. package/{error → modules/error}/ConditionError.js +0 -0
  37. package/{error → modules/error}/PermissionError.d.ts +0 -0
  38. package/{error → modules/error}/PermissionError.js +0 -0
  39. package/{error → modules/error}/RequiredError.d.ts +0 -0
  40. package/{error → modules/error}/RequiredError.js +0 -0
  41. package/{error → modules/error}/ThroughError.d.ts +0 -0
  42. package/{error → modules/error}/ThroughError.js +0 -0
  43. package/{error → modules/error}/UnsupportedError.d.ts +0 -0
  44. package/{error → modules/error}/UnsupportedError.js +0 -0
  45. package/{error → modules/error}/ValidationError.d.ts +0 -0
  46. package/{error → modules/error}/ValidationError.js +0 -0
  47. package/{error → modules/error}/index.d.ts +0 -0
  48. package/{error → modules/error}/index.js +0 -0
  49. package/{feedback → modules/feedback}/ErrorFeedback.d.ts +0 -0
  50. package/{feedback → modules/feedback}/ErrorFeedback.js +1 -5
  51. package/{feedback → modules/feedback}/Feedback.d.ts +0 -0
  52. package/{feedback → modules/feedback}/Feedback.js +1 -5
  53. package/{feedback → modules/feedback}/InvalidFeedback.d.ts +0 -0
  54. package/{feedback → modules/feedback}/InvalidFeedback.js +1 -5
  55. package/{feedback → modules/feedback}/SuccessFeedback.d.ts +0 -0
  56. package/{feedback → modules/feedback}/SuccessFeedback.js +1 -5
  57. package/{feedback → modules/feedback}/WarningFeedback.d.ts +0 -0
  58. package/{feedback → modules/feedback}/WarningFeedback.js +1 -5
  59. package/{feedback → modules/feedback}/hydrations.d.ts +0 -0
  60. package/{feedback → modules/feedback}/hydrations.js +0 -0
  61. package/{feedback → modules/feedback}/index.d.ts +0 -0
  62. package/{feedback → modules/feedback}/index.js +0 -0
  63. package/{firestore → modules/firestore}/client/FirestoreClientProvider.d.ts +3 -3
  64. package/{firestore → modules/firestore}/client/FirestoreClientProvider.js +4 -4
  65. package/{firestore → modules/firestore}/client/index.d.ts +0 -0
  66. package/{firestore → modules/firestore}/client/index.js +0 -0
  67. package/{firestore → modules/firestore}/lite/FirestoreLiteProvider.d.ts +3 -3
  68. package/{firestore → modules/firestore}/lite/FirestoreLiteProvider.js +4 -4
  69. package/{firestore → modules/firestore}/lite/index.d.ts +0 -0
  70. package/{firestore → modules/firestore}/lite/index.js +0 -0
  71. package/{firestore → modules/firestore}/server/FirestoreServerProvider.d.ts +3 -3
  72. package/{firestore → modules/firestore}/server/FirestoreServerProvider.js +4 -4
  73. package/{firestore → modules/firestore}/server/index.d.ts +0 -0
  74. package/{firestore → modules/firestore}/server/index.js +0 -0
  75. package/{index.d.ts → modules/index.d.ts} +0 -0
  76. package/{index.js → modules/index.js} +0 -0
  77. package/{markup → modules/markup}/index.d.ts +0 -0
  78. package/{markup → modules/markup}/index.js +0 -0
  79. package/{markup → modules/markup}/options.d.ts +0 -0
  80. package/{markup → modules/markup}/options.js +0 -0
  81. package/{markup → modules/markup}/regexp.d.ts +0 -0
  82. package/{markup → modules/markup}/regexp.js +0 -0
  83. package/{markup → modules/markup}/render.d.ts +0 -0
  84. package/{markup → modules/markup}/render.js +0 -0
  85. package/{markup → modules/markup}/rules.d.ts +0 -0
  86. package/{markup → modules/markup}/rules.js +0 -0
  87. package/{observe → modules/observe}/AbstractObserver.d.ts +0 -0
  88. package/{observe → modules/observe}/AbstractObserver.js +0 -0
  89. package/{observe → modules/observe}/AsyncObserver.d.ts +0 -0
  90. package/{observe → modules/observe}/AsyncObserver.js +0 -0
  91. package/{observe → modules/observe}/LastSubject.d.ts +0 -0
  92. package/{observe → modules/observe}/LastSubject.js +0 -0
  93. package/{observe → modules/observe}/MatchObserver.d.ts +0 -0
  94. package/{observe → modules/observe}/MatchObserver.js +0 -0
  95. package/{observe → modules/observe}/MatchableObserver.d.ts +0 -0
  96. package/{observe → modules/observe}/MatchableObserver.js +0 -0
  97. package/{observe → modules/observe}/Observable.d.ts +0 -0
  98. package/{observe → modules/observe}/Observable.js +0 -0
  99. package/{observe → modules/observe}/Observer.d.ts +0 -0
  100. package/{observe → modules/observe}/Observer.js +0 -0
  101. package/{observe → modules/observe}/OnceObserver.d.ts +0 -0
  102. package/{observe → modules/observe}/OnceObserver.js +0 -0
  103. package/{observe → modules/observe}/Subject.d.ts +0 -0
  104. package/{observe → modules/observe}/Subject.js +0 -0
  105. package/{observe → modules/observe}/ThroughObserver.d.ts +0 -0
  106. package/{observe → modules/observe}/ThroughObserver.js +0 -0
  107. package/{observe → modules/observe}/TransformObserver.d.ts +0 -0
  108. package/{observe → modules/observe}/TransformObserver.js +0 -0
  109. package/{observe → modules/observe}/TransformableObserver.d.ts +0 -0
  110. package/{observe → modules/observe}/TransformableObserver.js +0 -0
  111. package/{observe → modules/observe}/index.d.ts +0 -0
  112. package/{observe → modules/observe}/index.js +0 -0
  113. package/{observe → modules/observe}/util.d.ts +0 -0
  114. package/{observe → modules/observe}/util.js +0 -0
  115. package/{provider → modules/provider}/BatchProvider.d.ts +0 -0
  116. package/{provider → modules/provider}/BatchProvider.js +0 -0
  117. package/{provider → modules/provider}/CacheProvider.d.ts +3 -3
  118. package/{provider → modules/provider}/CacheProvider.js +6 -6
  119. package/{provider → modules/provider}/DebugProvider.d.ts +5 -5
  120. package/{provider → modules/provider}/DebugProvider.js +12 -12
  121. package/{provider → modules/provider}/MemoryProvider.d.ts +5 -5
  122. package/{provider → modules/provider}/MemoryProvider.js +9 -8
  123. package/{provider → modules/provider}/Provider.d.ts +7 -7
  124. package/{provider → modules/provider}/Provider.js +0 -0
  125. package/{provider → modules/provider}/ThroughProvider.d.ts +5 -5
  126. package/{provider → modules/provider}/ThroughProvider.js +4 -4
  127. package/{provider → modules/provider}/ValidationProvider.d.ts +11 -11
  128. package/{provider → modules/provider}/ValidationProvider.js +29 -28
  129. package/{provider → modules/provider}/index.d.ts +0 -0
  130. package/{provider → modules/provider}/index.js +0 -0
  131. package/{react → modules/react}/index.d.ts +0 -0
  132. package/{react → modules/react}/index.js +0 -0
  133. package/{react → modules/react}/useCache.d.ts +0 -0
  134. package/{react → modules/react}/useCache.js +0 -0
  135. package/{react → modules/react}/useInstance.d.ts +0 -0
  136. package/{react → modules/react}/useInstance.js +0 -0
  137. package/{react → modules/react}/useItem.d.ts +7 -7
  138. package/{react → modules/react}/useItem.js +0 -0
  139. package/{react → modules/react}/useLazy.d.ts +0 -0
  140. package/{react → modules/react}/useLazy.js +0 -0
  141. package/{react → modules/react}/useQuery.d.ts +10 -10
  142. package/{react → modules/react}/useQuery.js +0 -0
  143. package/{react → modules/react}/useReduce.d.ts +0 -0
  144. package/{react → modules/react}/useReduce.js +0 -0
  145. package/{react → modules/react}/useSubscribe.d.ts +0 -0
  146. package/{react → modules/react}/useSubscribe.js +0 -0
  147. package/{schema → modules/schema}/AllowSchema.d.ts +0 -0
  148. package/{schema → modules/schema}/AllowSchema.js +0 -0
  149. package/{schema → modules/schema}/ArraySchema.d.ts +0 -0
  150. package/{schema → modules/schema}/ArraySchema.js +0 -0
  151. package/{schema → modules/schema}/BooleanSchema.d.ts +0 -0
  152. package/{schema → modules/schema}/BooleanSchema.js +0 -0
  153. package/{schema → modules/schema}/ColorSchema.d.ts +0 -0
  154. package/{schema → modules/schema}/ColorSchema.js +0 -0
  155. package/{schema → modules/schema}/DataSchema.d.ts +5 -1
  156. package/{schema → modules/schema}/DataSchema.js +0 -0
  157. package/{schema → modules/schema}/DateSchema.d.ts +0 -0
  158. package/{schema → modules/schema}/DateSchema.js +0 -0
  159. package/{schema → modules/schema}/EmailSchema.d.ts +0 -0
  160. package/{schema → modules/schema}/EmailSchema.js +0 -0
  161. package/{schema → modules/schema}/KeySchema.d.ts +0 -0
  162. package/{schema → modules/schema}/KeySchema.js +0 -0
  163. package/{schema → modules/schema}/LinkSchema.d.ts +0 -0
  164. package/{schema → modules/schema}/LinkSchema.js +0 -0
  165. package/{schema → modules/schema}/NumberSchema.d.ts +0 -0
  166. package/{schema → modules/schema}/NumberSchema.js +0 -0
  167. package/{schema → modules/schema}/ObjectSchema.d.ts +0 -0
  168. package/{schema → modules/schema}/ObjectSchema.js +0 -0
  169. package/{schema → modules/schema}/OptionalSchema.d.ts +0 -0
  170. package/{schema → modules/schema}/OptionalSchema.js +0 -0
  171. package/{schema → modules/schema}/PhoneSchema.d.ts +0 -0
  172. package/{schema → modules/schema}/PhoneSchema.js +0 -0
  173. package/{schema → modules/schema}/RequiredSchema.d.ts +0 -0
  174. package/{schema → modules/schema}/RequiredSchema.js +0 -0
  175. package/{schema → modules/schema}/Schema.d.ts +0 -0
  176. package/{schema → modules/schema}/Schema.js +0 -0
  177. package/{schema → modules/schema}/SlugSchema.d.ts +0 -0
  178. package/{schema → modules/schema}/SlugSchema.js +0 -0
  179. package/{schema → modules/schema}/StringSchema.d.ts +0 -0
  180. package/{schema → modules/schema}/StringSchema.js +0 -0
  181. package/{schema → modules/schema}/ThroughSchema.d.ts +0 -0
  182. package/{schema → modules/schema}/ThroughSchema.js +0 -0
  183. package/{schema → modules/schema}/index.d.ts +0 -0
  184. package/{schema → modules/schema}/index.js +0 -0
  185. package/{state → modules/state}/ArrayState.d.ts +0 -0
  186. package/{state → modules/state}/ArrayState.js +0 -0
  187. package/{state → modules/state}/BooleanState.d.ts +0 -0
  188. package/{state → modules/state}/BooleanState.js +0 -0
  189. package/{state → modules/state}/DataState.d.ts +3 -3
  190. package/{state → modules/state}/DataState.js +0 -0
  191. package/{state → modules/state}/ObjectState.d.ts +0 -0
  192. package/{state → modules/state}/ObjectState.js +0 -0
  193. package/{state → modules/state}/SelfClosingState.d.ts +0 -0
  194. package/{state → modules/state}/SelfClosingState.js +0 -0
  195. package/{state → modules/state}/State.d.ts +0 -0
  196. package/{state → modules/state}/State.js +0 -0
  197. package/{state → modules/state}/index.d.ts +0 -0
  198. package/{state → modules/state}/index.js +0 -0
  199. package/{test → modules/test}/basics.d.ts +0 -0
  200. package/{test → modules/test}/basics.js +0 -0
  201. package/{test → modules/test}/index.d.ts +0 -0
  202. package/{test → modules/test}/index.js +0 -0
  203. package/{test → modules/test}/people.d.ts +0 -0
  204. package/{test → modules/test}/people.js +0 -0
  205. package/{test → modules/test}/util.d.ts +0 -0
  206. package/{test → modules/test}/util.js +0 -0
  207. package/{update → modules/update}/ArrayUpdate.d.ts +0 -0
  208. package/{update → modules/update}/ArrayUpdate.js +0 -0
  209. package/{update → modules/update}/DataUpdate.d.ts +15 -7
  210. package/{update → modules/update}/DataUpdate.js +28 -21
  211. package/{update → modules/update}/Delete.d.ts +0 -0
  212. package/{update → modules/update}/Delete.js +0 -0
  213. package/{update → modules/update}/Increment.d.ts +0 -0
  214. package/{update → modules/update}/Increment.js +0 -0
  215. package/{update → modules/update}/ObjectUpdate.d.ts +0 -0
  216. package/{update → modules/update}/ObjectUpdate.js +0 -0
  217. package/{update → modules/update}/Update.d.ts +0 -0
  218. package/{update → modules/update}/Update.js +0 -0
  219. package/{update → modules/update}/hydrations.d.ts +0 -0
  220. package/{update → modules/update}/hydrations.js +0 -0
  221. package/{update → modules/update}/index.d.ts +0 -0
  222. package/{update → modules/update}/index.js +0 -0
  223. package/{util → modules/util}/array.d.ts +0 -0
  224. package/{util → modules/util}/array.js +0 -0
  225. package/{util → modules/util}/assert.d.ts +0 -0
  226. package/{util → modules/util}/assert.js +0 -0
  227. package/{util → modules/util}/async.d.ts +0 -0
  228. package/{util → modules/util}/async.js +0 -0
  229. package/{util → modules/util}/boolean.d.ts +0 -0
  230. package/{util → modules/util}/boolean.js +0 -0
  231. package/{util → modules/util}/class.d.ts +0 -0
  232. package/{util → modules/util}/class.js +0 -0
  233. package/{util → modules/util}/clone.d.ts +0 -0
  234. package/{util → modules/util}/clone.js +0 -0
  235. package/{util → modules/util}/color.d.ts +0 -0
  236. package/{util → modules/util}/color.js +0 -0
  237. package/{util → modules/util}/data.d.ts +0 -0
  238. package/{util → modules/util}/data.js +0 -0
  239. package/{util → modules/util}/date.d.ts +0 -0
  240. package/{util → modules/util}/date.js +0 -0
  241. package/{util → modules/util}/debug.d.ts +0 -0
  242. package/{util → modules/util}/debug.js +0 -0
  243. package/{util → modules/util}/diff.d.ts +0 -0
  244. package/{util → modules/util}/diff.js +0 -0
  245. package/{util → modules/util}/entry.d.ts +0 -0
  246. package/{util → modules/util}/entry.js +0 -0
  247. package/{util → modules/util}/equal.d.ts +0 -0
  248. package/{util → modules/util}/equal.js +0 -0
  249. package/{util → modules/util}/error.d.ts +0 -0
  250. package/{util → modules/util}/error.js +0 -0
  251. package/{util → modules/util}/filter.d.ts +0 -0
  252. package/{util → modules/util}/filter.js +0 -0
  253. package/{util → modules/util}/function.d.ts +0 -0
  254. package/{util → modules/util}/function.js +0 -0
  255. package/{util → modules/util}/hydrate.d.ts +0 -0
  256. package/{util → modules/util}/hydrate.js +0 -0
  257. package/{util → modules/util}/index.d.ts +0 -0
  258. package/{util → modules/util}/index.js +0 -0
  259. package/{util → modules/util}/iterate.d.ts +0 -0
  260. package/{util → modules/util}/iterate.js +0 -0
  261. package/{util → modules/util}/jsx.d.ts +0 -0
  262. package/{util → modules/util}/jsx.js +0 -0
  263. package/{util → modules/util}/lazy.d.ts +0 -0
  264. package/{util → modules/util}/lazy.js +0 -0
  265. package/{util → modules/util}/map.d.ts +0 -0
  266. package/{util → modules/util}/map.js +0 -0
  267. package/{util → modules/util}/match.d.ts +0 -0
  268. package/{util → modules/util}/match.js +0 -0
  269. package/{util → modules/util}/merge.d.ts +0 -0
  270. package/{util → modules/util}/merge.js +0 -0
  271. package/{util → modules/util}/null.d.ts +0 -0
  272. package/{util → modules/util}/null.js +0 -0
  273. package/{util → modules/util}/number.d.ts +0 -0
  274. package/{util → modules/util}/number.js +0 -0
  275. package/{util → modules/util}/object.d.ts +0 -0
  276. package/{util → modules/util}/object.js +0 -0
  277. package/{util → modules/util}/random.d.ts +0 -0
  278. package/{util → modules/util}/random.js +0 -0
  279. package/{util → modules/util}/regexp.d.ts +0 -0
  280. package/{util → modules/util}/regexp.js +0 -0
  281. package/{util → modules/util}/serialise.d.ts +0 -0
  282. package/{util → modules/util}/serialise.js +0 -0
  283. package/{util → modules/util}/set.d.ts +0 -0
  284. package/{util → modules/util}/set.js +0 -0
  285. package/{util → modules/util}/sort.d.ts +0 -0
  286. package/{util → modules/util}/sort.js +0 -0
  287. package/{util → modules/util}/source.d.ts +0 -0
  288. package/{util → modules/util}/source.js +0 -0
  289. package/{util → modules/util}/string.d.ts +0 -0
  290. package/{util → modules/util}/string.js +0 -0
  291. package/{util → modules/util}/template.d.ts +0 -0
  292. package/{util → modules/util}/template.js +0 -0
  293. package/{util → modules/util}/timeout.d.ts +0 -0
  294. package/{util → modules/util}/timeout.js +0 -0
  295. package/{util → modules/util}/transform.d.ts +3 -3
  296. package/{util → modules/util}/transform.js +0 -0
  297. package/{util → modules/util}/undefined.d.ts +0 -0
  298. package/{util → modules/util}/undefined.js +0 -0
  299. package/{util → modules/util}/units.d.ts +0 -0
  300. package/{util → modules/util}/units.js +0 -0
  301. package/{util → modules/util}/url.d.ts +0 -0
  302. package/{util → modules/util}/url.js +0 -0
  303. package/{util → modules/util}/validate.d.ts +0 -0
  304. package/{util → modules/util}/validate.js +0 -0
  305. package/package.json +8 -8
  306. package/db/Collection.d.ts +0 -46
  307. package/db/Database.d.ts +0 -42
  308. package/db/Database.js +0 -43
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -2,7 +2,7 @@ import type { Data } from "../util/data.js";
2
2
  import { ImmutableArray } from "../util/array.js";
3
3
  import { Constraint } from "./Constraint.js";
4
4
  /** Type of Rule that is powered by several sub-constraints (e.g. `Filters` and `Sorts` and `Query` itself extend this). */
5
- export declare abstract class Constraints<T extends Data, C extends Constraint<T>> extends Constraint<T> implements Iterable<C> {
5
+ export declare abstract class Constraints<T extends Data, C extends Constraint<Partial<T>>> extends Constraint<T> implements Iterable<C> {
6
6
  protected readonly _constraints: ImmutableArray<C>;
7
7
  /** Get the first constraint. */
8
8
  get first(): C | undefined;
@@ -1,8 +1,8 @@
1
- import { ArrayType, ImmutableArray } from "../util/array.js";
2
- import { Data, Key } from "../util/data.js";
1
+ import type { Data, Key } from "../util/data.js";
2
+ import type { Nullish } from "../util/null.js";
3
+ import { ImmutableArray } from "../util/array.js";
3
4
  import { Matchable } from "../util/match.js";
4
- import { NotString } from "../util/string.js";
5
- import { Constraint } from "./Constraint.js";
5
+ import type { Constraint } from "./Constraint.js";
6
6
  /** Possible operator references. */
7
7
  export declare type FilterOperator = "IS" | "NOT" | "IN" | "OUT" | "CONTAINS" | "LT" | "LTE" | "GT" | "GTE";
8
8
  /** Format that allows filters to be specified as a string, e.g. `!name` means `name is not` and `age>` means `age is more than` and `tags[]` means `tags array contains` */
@@ -11,12 +11,12 @@ export declare type FilterKey<T extends Data> = Key<T> | `${Key<T>}` | `!${Key<T
11
11
  export declare type FilterProps<T extends Data> = {
12
12
  [K in Key<T> as `${K}` | `!${K}`]?: T[K] | ImmutableArray<T[K]>;
13
13
  } & {
14
- [K in Key<T> as `${K}[]`]?: T[K] extends ImmutableArray ? ArrayType<T[K]> : never;
14
+ [K in Key<T> as `${K}[]`]?: Required<T>[K] extends ImmutableArray<infer X> ? X : never;
15
15
  } & {
16
16
  [K in Key<T> as `${K}<` | `${K}<=` | `${K}>` | `${K}>=`]?: T[K];
17
17
  };
18
18
  /** List of filters in a flexible format. */
19
- export declare type FilterList<T extends Data> = FilterProps<T> | FilterConstraint<T> | Iterable<FilterList<T> & NotString>;
19
+ export declare type FilterList<T extends Data> = Nullish<FilterProps<T> | FilterConstraint<T>> | Iterable<FilterList<T>>;
20
20
  /**
21
21
  * Filter: filters a list of data.
22
22
  *
@@ -89,7 +89,7 @@ export function* getFilters(filters) {
89
89
  for (const filter of filters)
90
90
  yield* getFilters(filter);
91
91
  }
92
- else {
92
+ else if (filters) {
93
93
  for (const [key, value] of Object.entries(filters))
94
94
  yield new FilterConstraint(key, value);
95
95
  }
@@ -1,6 +1,6 @@
1
1
  import type { Data } from "../util/data.js";
2
2
  import type { Matchable } from "../util/match.js";
3
- import { FilterList, FilterProps, FilterConstraint } from "./FilterConstraint.js";
3
+ import { FilterList, FilterConstraint } from "./FilterConstraint.js";
4
4
  import { Constraints } from "./Constraints.js";
5
5
  /**
6
6
  * Interface to make sure an object implements all matchers.
@@ -8,14 +8,14 @@ import { Constraints } from "./Constraints.js";
8
8
  */
9
9
  export interface Filterable<T extends Data> extends Matchable<T, void> {
10
10
  /** Add a filter to this filterable. */
11
- filter(props: FilterProps<T>): this;
11
+ filter(...filters: FilterList<Partial<T>>[]): this;
12
12
  /** Match an item against the filters specified for this object. */
13
13
  match(item: T): boolean;
14
14
  }
15
15
  /** A set of filters. */
16
- export declare class FilterConstraints<T extends Data = Data> extends Constraints<T, FilterConstraint<T>> implements Filterable<T> {
17
- constructor(...filters: FilterList<T>[]);
18
- filter(...filters: FilterList<T>[]): this;
16
+ export declare class FilterConstraints<T extends Data = Data> extends Constraints<T, FilterConstraint<Partial<T>>> implements Filterable<T> {
17
+ constructor(...filters: FilterList<Partial<T>>[]);
18
+ filter(...filters: FilterList<Partial<T>>[]): this;
19
19
  match(item: T): boolean;
20
20
  transform(items: Iterable<T>): Iterable<T>;
21
21
  toString(): string;
@@ -3,7 +3,7 @@ import { Filterable, FilterConstraints } from "./FilterConstraints.js";
3
3
  import { Sortable, SortConstraints } from "./SortConstraints.js";
4
4
  import { Constraint } from "./Constraint.js";
5
5
  import { FilterList } from "./FilterConstraint.js";
6
- import { SortKeys, SortList } from "./SortConstraint.js";
6
+ import { SortList } from "./SortConstraint.js";
7
7
  /** Interface that combines Filterable, Sortable, Sliceable. */
8
8
  export interface Queryable<T extends Data> extends Filterable<T>, Sortable<T> {
9
9
  /**
@@ -31,11 +31,11 @@ export declare class QueryConstraints<T extends Data = Data> extends Constraint<
31
31
  readonly filters: FilterConstraints<T>;
32
32
  readonly sorts: SortConstraints<T>;
33
33
  readonly limit: number | null;
34
- constructor(filters?: FilterList<T>, sorts?: SortList<T>, limit?: number | null);
35
- filter(...filters: FilterList<T>[]): this;
34
+ constructor(filters?: FilterList<Partial<T>>, sorts?: SortList<Partial<T>>, limit?: number | null);
35
+ filter(...filters: FilterList<Partial<T>>[]): this;
36
36
  get unfilter(): this;
37
37
  match(item: T): boolean;
38
- sort(...keys: SortKeys<T>[]): this;
38
+ sort(...sorts: SortList<Partial<T>>[]): this;
39
39
  get unsort(): this;
40
40
  rank(left: T, right: T): number;
41
41
  after(item: T): this;
@@ -37,11 +37,11 @@ export class QueryConstraints extends Constraint {
37
37
  return this.filters.match(item);
38
38
  }
39
39
  // Implement `Sortable`
40
- sort(...keys) {
40
+ sort(...sorts) {
41
41
  return {
42
42
  __proto__: Object.getPrototypeOf(this),
43
43
  ...this,
44
- sorts: this.sorts.sort(...keys),
44
+ sorts: this.sorts.sort(...sorts),
45
45
  };
46
46
  }
47
47
  get unsort() {
@@ -1,7 +1,8 @@
1
1
  import type { ImmutableArray } from "../util/array.js";
2
- import { Data, Key } from "../util/data.js";
2
+ import type { Data, Key } from "../util/data.js";
3
+ import type { Nullish } from "../util/null.js";
3
4
  import { Rankable } from "../util/sort.js";
4
- import { Constraint } from "./Constraint.js";
5
+ import type { Constraint } from "./Constraint.js";
5
6
  /** Format that allows sorts to be set as a plain string, e.g. `name` sorts by name in ascending order and `!date` sorts by date in descending order. */
6
7
  export declare type SortKey<T extends Data> = Key<T> | `${Key<T>}` | `!${Key<T>}`;
7
8
  /** One or more sort keys. */
@@ -9,7 +10,7 @@ export declare type SortKeys<T extends Data> = SortKey<T> | ImmutableArray<SortK
9
10
  /** Possible operator references. */
10
11
  export declare type SortDirection = "ASC" | "DESC";
11
12
  /** List of sorts in a flexible format. */
12
- export declare type SortList<T extends Data> = SortKeys<T> | SortConstraint<T> | Iterable<SortList<T>>;
13
+ export declare type SortList<T extends Data> = Nullish<SortKeys<T> | SortConstraint<T> | Iterable<SortList<T>>>;
13
14
  /** Sort a list of values. */
14
15
  export declare class SortConstraint<T extends Data = Data> implements Constraint<T>, Rankable<T> {
15
16
  readonly key: string;
@@ -1,4 +1,3 @@
1
- import { getProp } from "../util/data.js";
2
1
  import { rank, rankAsc, rankDesc, sortItems } from "../util/sort.js";
3
2
  /** Sort a list of values. */
4
3
  export class SortConstraint {
@@ -16,7 +15,7 @@ export class SortConstraint {
16
15
  return `"${this.direction === "DESC" ? "!" : ""}${this.key}"`;
17
16
  }
18
17
  rank(left, right) {
19
- return rank(getProp(left, this.key), this.direction === "ASC" ? rankAsc : rankDesc, getProp(right, this.key));
18
+ return rank(left[this.key], this.direction === "ASC" ? rankAsc : rankDesc, right[this.key]);
20
19
  }
21
20
  transform(items) {
22
21
  return sortItems(items, this);
@@ -33,7 +32,7 @@ export function* getSorts(sorts) {
33
32
  else if (sorts instanceof SortConstraint) {
34
33
  yield sorts;
35
34
  }
36
- else {
35
+ else if (sorts) {
37
36
  for (const sort of sorts)
38
37
  yield* getSorts(sort);
39
38
  }
@@ -1,19 +1,19 @@
1
1
  import type { Data } from "../util/data.js";
2
2
  import { Rankable } from "../util/sort.js";
3
3
  import { Constraints } from "./Constraints.js";
4
- import { SortConstraint, SortKeys, SortList } from "./SortConstraint.js";
4
+ import { SortConstraint, SortList } from "./SortConstraint.js";
5
5
  /**
6
6
  * Interface to make sure an object implements all directions.
7
7
  * - Extends `Rankable` so this object itself can be directly be used with `filterItems()` and `filterEntries()`
8
8
  */
9
9
  export interface Sortable<T extends Data> extends Rankable<T> {
10
10
  /** Add one or more sorts to this sortable. */
11
- sort(...keys: SortKeys<T>[]): this;
11
+ sort(...keys: SortList<Partial<T>>[]): this;
12
12
  }
13
13
  /** A set of sorts. */
14
- export declare class SortConstraints<T extends Data = Data> extends Constraints<T, SortConstraint<T>> implements Sortable<T> {
15
- constructor(...sorts: SortList<T>[]);
16
- sort(...sorts: SortList<T>[]): this;
14
+ export declare class SortConstraints<T extends Data = Data> extends Constraints<T, SortConstraint<Partial<T>>> implements Sortable<T> {
15
+ constructor(...sorts: SortList<Partial<T>>[]);
16
+ sort(...sorts: SortList<Partial<T>>[]): this;
17
17
  rank(left: T, right: T): number;
18
18
  transform(items: Iterable<T>): Iterable<T>;
19
19
  toString(): string;
File without changes
File without changes
@@ -1,38 +1,35 @@
1
- import type { Data, Datas, Key, Value } from "../util/data.js";
1
+ import type { Data, Datas, Key } from "../util/data.js";
2
2
  import type { ImmutableArray } from "../util/array.js";
3
3
  import type { Provider, AsyncProvider } from "../provider/Provider.js";
4
- import { DataUpdate } from "../update/DataUpdate.js";
4
+ import { Updates } from "../update/DataUpdate.js";
5
5
  import { Nullish } from "../util/null.js";
6
6
  import { DeepIterable } from "../util/iterate.js";
7
7
  import type { ItemConstraints, ItemData } from "./Item.js";
8
- export interface Change<T extends Datas> {
8
+ /** Change on a collection. */
9
+ export interface Change<T extends Datas, K extends Key<T> = Key<T>> {
9
10
  readonly action: string;
10
- readonly collection: Key<T>;
11
+ readonly collection: K;
11
12
  }
12
13
  /** Add on an item. */
13
- export interface AddChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
14
+ export interface AddChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
14
15
  readonly action: "ADD";
15
- readonly collection: K;
16
16
  readonly data: T[K];
17
17
  }
18
18
  /** Set on an item. */
19
- export interface SetChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
19
+ export interface SetChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
20
20
  readonly action: "SET";
21
- readonly collection: K;
22
21
  readonly id: string;
23
22
  readonly data: T[K];
24
23
  }
25
24
  /** Update change on an item. */
26
- export interface UpdateChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
25
+ export interface UpdateChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
27
26
  readonly action: "UPDATE";
28
- readonly collection: K;
29
27
  readonly id: string;
30
- readonly update: DataUpdate<Value<T>>;
28
+ readonly updates: Updates<T[K]>;
31
29
  }
32
30
  /** Delete change on an item. */
33
- export interface DeleteChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
31
+ export interface DeleteChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
34
32
  readonly action: "DELETE";
35
- readonly collection: K;
36
33
  readonly id: string;
37
34
  }
38
35
  /** Set, update, or delete change on an item. */
@@ -13,7 +13,7 @@ function _changeItem(change) {
13
13
  else if (action === "SET")
14
14
  this.setItem(collection, change.id, change.data);
15
15
  else if (action === "UPDATE")
16
- this.updateQuery(collection, _getItemConstraint(change.id), change.update);
16
+ this.updateQuery(collection, _getItemConstraint(change.id), change.updates);
17
17
  else if (action === "DELETE")
18
18
  this.deleteItem(collection, change.id);
19
19
  return change;
@@ -29,7 +29,7 @@ async function _changeAsyncItem(change) {
29
29
  else if (action === "SET")
30
30
  await this.setItem(collection, change.id, change.data);
31
31
  else if (action === "UPDATE")
32
- await this.updateQuery(collection, _getItemConstraint(change.id), change.update);
32
+ await this.updateQuery(collection, _getItemConstraint(change.id), change.updates);
33
33
  else if (action === "DELETE")
34
34
  await this.deleteItem(collection, change.id);
35
35
  return change;
@@ -0,0 +1,74 @@
1
+ import type { Datas, Key } from "../util/data.js";
2
+ import type { Nullish } from "../util/null.js";
3
+ import type { FilterList } from "../constraint/FilterConstraint.js";
4
+ import type { SortList } from "../constraint/SortConstraint.js";
5
+ import type { DeepIterable } from "../util/iterate.js";
6
+ import type { Updates } from "../update/DataUpdate.js";
7
+ import type { PartialObserver } from "../observe/Observer.js";
8
+ import type { Dispatch } from "../util/function.js";
9
+ import type { Unsubscribe } from "../observe/Observable.js";
10
+ import type { AsyncDatabase, Database } from "./Database.js";
11
+ import { ItemData, AsyncItem, Item, ItemValue } from "./Item.js";
12
+ import { AsyncQuery, Query } from "./Query.js";
13
+ import { AddChange, ItemChanges, WriteChange, UpdateChange, DeleteChange, SetChange } from "./Change.js";
14
+ /** Reference to a collection in a synchronous or asynchronous provider. */
15
+ declare abstract class BaseCollection<T extends Datas = Datas, K extends Key<T> = Key<T>> {
16
+ abstract readonly db: Database<T> | AsyncDatabase<T>;
17
+ abstract readonly collection: K;
18
+ /** Create a query on this item's collection. */
19
+ abstract query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K> | AsyncQuery<T, K>;
20
+ /** Create a query on this item's collection. */
21
+ abstract item(id: string): Item<T, K> | AsyncItem<T, K>;
22
+ /** Run a set of changes on this database. */
23
+ abstract change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K> | Promise<ItemChanges<T, K>>;
24
+ /** Get an item from this collection. */
25
+ abstract get(id: string): ItemValue<T[K]> | Promise<ItemValue<T[K]>>;
26
+ /** Subscribe a document from a collection in this database. */
27
+ subscribe(id: string, next: PartialObserver<ItemValue<T[K]>> | Dispatch<[ItemValue<T[K]>]>): Unsubscribe;
28
+ /** Add an item to this collection. */
29
+ abstract add(data: T[K]): string | Promise<string>;
30
+ /** Set a document in this collection. */
31
+ abstract set(id: string, data: T[K]): void | Promise<void>;
32
+ /** Update a document in this collection. */
33
+ abstract update(id: string, updates: Updates<T[K]>): void | Promise<void>;
34
+ /** Delete a document in this collection. */
35
+ abstract delete(id: string): void | Promise<void>;
36
+ /** Get an add change for this collection. */
37
+ getAdd(data: T[K]): AddChange<T, K>;
38
+ /** Get a set change for this collection. */
39
+ getSet(id: string, data: T[K]): SetChange<T, K>;
40
+ /** Get an update change for this collection. */
41
+ getUpdate(id: string, updates: Updates<T[K]>): UpdateChange<T, K>;
42
+ /** Get a delete change for this collection. */
43
+ getDelete(id: string): DeleteChange<T, K>;
44
+ toString(): K;
45
+ }
46
+ /** Reference to a collection in a synchronous provider. */
47
+ export declare class Collection<T extends Datas = Datas, K extends Key<T> = Key<T>> extends BaseCollection<T, K> {
48
+ readonly db: Database<T>;
49
+ readonly collection: K;
50
+ constructor(db: Database<T>, collection: K);
51
+ query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K>;
52
+ item(id: string): Item<T, K>;
53
+ change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
54
+ get(id: string): ItemValue<T[K]>;
55
+ add(data: T[K]): string;
56
+ set(id: string, data: T[K]): void;
57
+ update(id: string, updates: Updates<T[K]>): void;
58
+ delete(id: string): void;
59
+ }
60
+ /** Reference to a collection in an asynchronous provider. */
61
+ export declare class AsyncCollection<T extends Datas = Datas, K extends Key<T> = Key<T>> extends BaseCollection<T, K> {
62
+ readonly db: AsyncDatabase<T>;
63
+ readonly collection: K;
64
+ constructor(db: AsyncDatabase<T>, collection: K);
65
+ query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): AsyncQuery<T, K>;
66
+ item(id: string): AsyncItem<T, K>;
67
+ change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
68
+ get(id: string): Promise<ItemValue<T[K]>>;
69
+ add(data: T[K]): Promise<string>;
70
+ set(id: string, data: T[K]): Promise<void>;
71
+ update(id: string, updates: Updates<T[K]>): Promise<void>;
72
+ delete(id: string): Promise<void>;
73
+ }
74
+ export {};
@@ -3,9 +3,25 @@ import { AsyncQuery, Query } from "./Query.js";
3
3
  import { changeAsyncProvider, changeProvider } from "./Change.js";
4
4
  /** Reference to a collection in a synchronous or asynchronous provider. */
5
5
  class BaseCollection {
6
+ /** Subscribe a document from a collection in this database. */
7
+ subscribe(id, next) {
8
+ return this.db.subscribe(this.collection, id, typeof next === "function" ? { next } : next);
9
+ }
6
10
  /** Get an add change for this collection. */
7
11
  getAdd(data) {
8
- return { action: "ADD", collection: this.collection, data };
12
+ return this.db.getAdd(this.collection, data);
13
+ }
14
+ /** Get a set change for this collection. */
15
+ getSet(id, data) {
16
+ return this.db.getSet(this.collection, id, data);
17
+ }
18
+ /** Get an update change for this collection. */
19
+ getUpdate(id, updates) {
20
+ return this.db.getUpdate(this.collection, id, updates);
21
+ }
22
+ /** Get a delete change for this collection. */
23
+ getDelete(id) {
24
+ return this.db.getDelete(this.collection, id);
9
25
  }
10
26
  // Implement toString()
11
27
  toString() {
@@ -25,12 +41,24 @@ export class Collection extends BaseCollection {
25
41
  item(id) {
26
42
  return new Item(this.db, this.collection, id);
27
43
  }
28
- add(data) {
29
- return this.db.provider.addItem(this.collection, data);
30
- }
31
44
  change(...changes) {
32
45
  return changeProvider(this.db.provider, changes);
33
46
  }
47
+ get(id) {
48
+ return this.db.get(this.collection, id);
49
+ }
50
+ add(data) {
51
+ return this.db.add(this.collection, data);
52
+ }
53
+ set(id, data) {
54
+ return this.db.set(this.collection, id, data);
55
+ }
56
+ update(id, updates) {
57
+ return this.db.update(this.collection, id, updates);
58
+ }
59
+ delete(id) {
60
+ return this.db.delete(this.collection, id);
61
+ }
34
62
  }
35
63
  /** Reference to a collection in an asynchronous provider. */
36
64
  export class AsyncCollection extends BaseCollection {
@@ -45,10 +73,22 @@ export class AsyncCollection extends BaseCollection {
45
73
  item(id) {
46
74
  return new AsyncItem(this.db, this.collection, id);
47
75
  }
48
- add(data) {
49
- return this.db.provider.addItem(this.collection, data);
50
- }
51
76
  change(...changes) {
52
77
  return changeAsyncProvider(this.db.provider, changes);
53
78
  }
79
+ get(id) {
80
+ return this.db.get(this.collection, id);
81
+ }
82
+ add(data) {
83
+ return this.db.add(this.collection, data);
84
+ }
85
+ set(id, data) {
86
+ return this.db.set(this.collection, id, data);
87
+ }
88
+ update(id, updates) {
89
+ return this.db.update(this.collection, id, updates);
90
+ }
91
+ delete(id) {
92
+ return this.db.delete(this.collection, id);
93
+ }
54
94
  }
@@ -0,0 +1,76 @@
1
+ import type { Key, Datas } from "../util/data.js";
2
+ import type { Nullish } from "../util/null.js";
3
+ import type { DeepIterable } from "../util/iterate.js";
4
+ import type { AsyncProvider, Provider } from "../provider/Provider.js";
5
+ import type { FilterList } from "../constraint/FilterConstraint.js";
6
+ import type { SortList } from "../constraint/SortConstraint.js";
7
+ import type { ItemData, ItemValue } from "../db/Item.js";
8
+ import type { Updates } from "../update/DataUpdate.js";
9
+ import type { PartialObserver } from "../observe/Observer.js";
10
+ import type { Dispatch } from "../util/function.js";
11
+ import type { Unsubscribe } from "../observe/Observable.js";
12
+ import { Item, AsyncItem } from "./Item.js";
13
+ import { Query, AsyncQuery } from "./Query.js";
14
+ import { Collection, AsyncCollection } from "./Collection.js";
15
+ import { AddChange, DeleteChange, ItemChanges, SetChange, UpdateChange, WriteChange } from "./Change.js";
16
+ /** Database with a synchronous or asynchronous provider. */
17
+ declare abstract class BaseDatabase<T extends Datas> {
18
+ abstract readonly provider: Provider<T> | AsyncProvider<T>;
19
+ /** Create a query on a collection in this database. */
20
+ abstract collection<K extends Key<T>>(collection: K): Collection<T, K> | AsyncCollection<T, K>;
21
+ /** Create a query on a collection in this database. */
22
+ abstract query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K> | AsyncQuery<T, K>;
23
+ /** Reference an item in a collection in this database. */
24
+ abstract item<K extends Key<T>>(collection: K, id: string): Item<T, K> | AsyncItem<T, K>;
25
+ /** Run a set of changes in this database. */
26
+ abstract change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T> | Promise<ItemChanges<T>>;
27
+ /** Get a document from a collection in this database. */
28
+ abstract get<K extends Key<T>>(collection: K, id: string): ItemValue<T[K]> | Promise<ItemValue<T[K]>>;
29
+ /** Subscribe a document from a collection in this database. */
30
+ subscribe<K extends Key<T>>(collection: K, id: string, next: PartialObserver<ItemValue<T[K]>> | Dispatch<[ItemValue<T[K]>]>): Unsubscribe;
31
+ /** Add a document to a collection in this database. */
32
+ abstract add<K extends Key<T>>(collection: K, data: T[K]): string | Promise<string>;
33
+ /** Set a document in a collection in this database. */
34
+ abstract set<K extends Key<T>>(collection: K, id: string, data: T[K]): void | Promise<void>;
35
+ /** Update a document in a collection in this database. */
36
+ abstract update<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void | Promise<void>;
37
+ /** Delete a document from a collection in this database. */
38
+ abstract delete<K extends Key<T>>(collection: K, id: string): void | Promise<void>;
39
+ /** Get an add change for a collection in this database. */
40
+ getAdd<K extends Key<T>>(collection: K, data: T[K]): AddChange<T, K>;
41
+ /** Get a set change for a collection in this database. */
42
+ getSet<K extends Key<T>>(collection: K, id: string, data: T[K]): SetChange<T, K>;
43
+ /** Get an update change for a collection in this database. */
44
+ getUpdate<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): UpdateChange<T, K>;
45
+ /** Get a delete change for a collection in this database. */
46
+ getDelete<K extends Key<T>>(collection: K, id: string): DeleteChange<T, K>;
47
+ }
48
+ /** Database with a synchronous provider. */
49
+ export declare class Database<T extends Datas = Datas> extends BaseDatabase<T> {
50
+ readonly provider: Provider<T>;
51
+ constructor(provider: Provider<T>);
52
+ collection<K extends Key<T>>(collection: K): Collection<T, K>;
53
+ query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K>;
54
+ item<K extends Key<T>>(collection: K, id: string): Item<T, K>;
55
+ change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T>;
56
+ get<K extends Key<T>>(collection: K, id: string): ItemValue<T[K]>;
57
+ add<K extends Key<T>>(collection: K, data: T[K]): string;
58
+ set<K extends Key<T>>(collection: K, id: string, data: T[K]): void;
59
+ update<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
60
+ delete<K extends Key<T>>(collection: K, id: string): void;
61
+ }
62
+ /** Database with a synchronous provider. */
63
+ export declare class AsyncDatabase<T extends Datas = Datas> extends BaseDatabase<T> {
64
+ readonly provider: AsyncProvider<T>;
65
+ constructor(provider: AsyncProvider<T>);
66
+ collection<K extends Key<T>>(collection: K): AsyncCollection<T, K>;
67
+ query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): AsyncQuery<T, K>;
68
+ item<K extends Key<T>>(collection: K, id: string): AsyncItem<T, K>;
69
+ change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): Promise<ItemChanges<T>>;
70
+ get<K extends Key<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
71
+ add<K extends Key<T>>(collection: K, data: T[K]): Promise<string>;
72
+ set<K extends Key<T>>(collection: K, id: string, data: T[K]): Promise<void>;
73
+ update<K extends Key<T>>(collection: K, id: string, updates: Updates<T[K]>): Promise<void>;
74
+ delete<K extends Key<T>>(collection: K, id: string): Promise<void>;
75
+ }
76
+ export {};
@@ -0,0 +1,95 @@
1
+ import { Item, AsyncItem } from "./Item.js";
2
+ import { Query, AsyncQuery } from "./Query.js";
3
+ import { Collection, AsyncCollection } from "./Collection.js";
4
+ import { changeAsyncProvider, changeProvider } from "./Change.js";
5
+ /** Database with a synchronous or asynchronous provider. */
6
+ class BaseDatabase {
7
+ /** Subscribe a document from a collection in this database. */
8
+ subscribe(collection, id, next) {
9
+ return this.provider.subscribeItem(collection, id, typeof next === "function" ? { next } : next);
10
+ }
11
+ /** Get an add change for a collection in this database. */
12
+ getAdd(collection, data) {
13
+ return { action: "ADD", collection, data };
14
+ }
15
+ /** Get a set change for a collection in this database. */
16
+ getSet(collection, id, data) {
17
+ return { action: "SET", collection, id, data };
18
+ }
19
+ /** Get an update change for a collection in this database. */
20
+ getUpdate(collection, id, updates) {
21
+ return { action: "UPDATE", collection, id, updates };
22
+ }
23
+ /** Get a delete change for a collection in this database. */
24
+ getDelete(collection, id) {
25
+ return { action: "DELETE", collection, id };
26
+ }
27
+ }
28
+ /** Database with a synchronous provider. */
29
+ export class Database extends BaseDatabase {
30
+ constructor(provider) {
31
+ super();
32
+ this.provider = provider;
33
+ }
34
+ collection(collection) {
35
+ return new Collection(this, collection);
36
+ }
37
+ query(collection, filters, sorts, limit) {
38
+ return new Query(this, collection, filters, sorts, limit);
39
+ }
40
+ item(collection, id) {
41
+ return new Item(this, collection, id);
42
+ }
43
+ change(...changes) {
44
+ return changeProvider(this.provider, changes);
45
+ }
46
+ get(collection, id) {
47
+ return this.provider.getItem(collection, id);
48
+ }
49
+ add(collection, data) {
50
+ return this.provider.addItem(collection, data);
51
+ }
52
+ set(collection, id, data) {
53
+ return this.provider.setItem(collection, id, data);
54
+ }
55
+ update(collection, id, updates) {
56
+ return this.provider.updateItem(collection, id, updates);
57
+ }
58
+ delete(collection, id) {
59
+ return this.provider.deleteItem(collection, id);
60
+ }
61
+ }
62
+ /** Database with a synchronous provider. */
63
+ export class AsyncDatabase extends BaseDatabase {
64
+ constructor(provider) {
65
+ super();
66
+ this.provider = provider;
67
+ }
68
+ collection(collection) {
69
+ return new AsyncCollection(this, collection);
70
+ }
71
+ query(collection, filters, sorts, limit) {
72
+ return new AsyncQuery(this, collection, filters, sorts, limit);
73
+ }
74
+ item(collection, id) {
75
+ return new AsyncItem(this, collection, id);
76
+ }
77
+ change(...changes) {
78
+ return changeAsyncProvider(this.provider, changes);
79
+ }
80
+ get(collection, id) {
81
+ return this.provider.getItem(collection, id);
82
+ }
83
+ add(collection, data) {
84
+ return this.provider.addItem(collection, data);
85
+ }
86
+ set(collection, id, data) {
87
+ return this.provider.setItem(collection, id, data);
88
+ }
89
+ update(collection, id, updates) {
90
+ return this.provider.updateItem(collection, id, updates);
91
+ }
92
+ delete(collection, id) {
93
+ return this.provider.deleteItem(collection, id);
94
+ }
95
+ }