remult 3.4.2 → 3.5.0-next.1

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 (55) hide show
  1. package/esm/internals.js +1 -0
  2. package/esm/postgres/postgres-data-provider.js +4 -5
  3. package/esm/remult-duckdb.js +4 -0
  4. package/esm/remult-knex/index.js +40 -8
  5. package/esm/remult-mongo.js +25 -7
  6. package/esm/remult-sqlite-core.js +4 -1
  7. package/esm/server/remult-api-server.js +1 -1
  8. package/esm/src/buildRestDataProvider.js +4 -2
  9. package/esm/src/data-api.js +2 -2
  10. package/esm/src/data-interfaces.js +2 -1
  11. package/esm/src/data-providers/array-entity-data-provider.js +5 -0
  12. package/esm/src/data-providers/rest-data-provider-using-fetch.js +2 -2
  13. package/esm/src/data-providers/retry.js +11 -6
  14. package/esm/src/data-providers/sql-database.js +40 -30
  15. package/esm/src/live-query/SubscriptionChannel.js +13 -8
  16. package/esm/src/remult-static.js +1 -0
  17. package/esm/src/remult3/Fields.js +14 -14
  18. package/esm/src/remult3/RepositoryImplementation.js +45 -32
  19. package/esm/src/sort.js +18 -0
  20. package/index.d.ts +1 -1
  21. package/internals.d.ts +1 -0
  22. package/internals.js +3 -1
  23. package/package.json +41 -1
  24. package/postgres/postgres-data-provider.d.ts +2 -3
  25. package/postgres/postgres-data-provider.js +4 -4
  26. package/remult-duckdb.d.ts +2 -0
  27. package/remult-duckdb.js +4 -0
  28. package/remult-knex/index.d.ts +2 -0
  29. package/remult-knex/index.js +125 -78
  30. package/remult-mongo.js +28 -7
  31. package/remult-sqlite-core.d.ts +2 -1
  32. package/remult-sqlite-core.js +4 -0
  33. package/server/remult-api-server.d.ts +12 -1
  34. package/server/remult-api-server.js +1 -1
  35. package/src/buildRestDataProvider.js +3 -1
  36. package/src/column-interfaces.d.ts +5 -1
  37. package/src/data-api.js +2 -2
  38. package/src/data-interfaces.d.ts +0 -1
  39. package/src/data-interfaces.js +3 -0
  40. package/src/data-providers/array-entity-data-provider.js +5 -0
  41. package/src/data-providers/rest-data-provider-using-fetch.js +1 -1
  42. package/src/data-providers/retry.d.ts +4 -1
  43. package/src/data-providers/retry.js +26 -16
  44. package/src/data-providers/sql-database.d.ts +7 -3
  45. package/src/data-providers/sql-database.js +99 -81
  46. package/src/live-query/SubscriptionChannel.js +16 -10
  47. package/src/remult-static.d.ts +2 -0
  48. package/src/remult-static.js +1 -0
  49. package/src/remult3/Fields.d.ts +5 -3
  50. package/src/remult3/Fields.js +24 -13
  51. package/src/remult3/RepositoryImplementation.js +274 -264
  52. package/src/remult3/remult3.d.ts +6 -1
  53. package/src/sort.d.ts +19 -0
  54. package/src/sort.js +20 -1
  55. package/src/sql-command.d.ts +2 -1
@@ -724,6 +724,9 @@ export interface LiveQueryChangeInfo<entityType> {
724
724
  * to update the component's state based on the live query changes.
725
725
  *
726
726
  * @param {entityType[] | undefined} prevState The previous state of the array of result items.
727
+ * @param {{ pos?: 'auto' | 'first' | 'last' }} [options] Controls where added items are placed.
728
+ * `'auto'` (default) keeps the array sorted by the query's `orderBy` (or the entity's `defaultOrderBy`, falling back to `'last'` when neither is set);
729
+ * `'first'` prepends added items; `'last'` appends them.
727
730
  * @returns {entityType[]} The updated array of result items after applying the changes.
728
731
  *
729
732
  * @example
@@ -738,7 +741,9 @@ export interface LiveQueryChangeInfo<entityType> {
738
741
  * .subscribe(info => setTasks(info.applyChanges));
739
742
  * }, []);
740
743
  */
741
- applyChanges(prevState: entityType[] | undefined): entityType[];
744
+ applyChanges(prevState: entityType[] | undefined, options?: {
745
+ pos?: 'auto' | 'first' | 'last';
746
+ }): entityType[];
742
747
  }
743
748
  export interface FindOptions<entityType> extends FindOptionsBase<entityType> {
744
749
  /** Number of rows returned. _(Defaults to 100 in the browser)_
package/src/sort.d.ts CHANGED
@@ -72,5 +72,24 @@ export interface SortSegment {
72
72
  field: FieldMetadata;
73
73
  isDescending?: boolean;
74
74
  }
75
+ export interface NullOrder {
76
+ asc: 'NULLS FIRST' | 'NULLS LAST';
77
+ desc: 'NULLS FIRST' | 'NULLS LAST';
78
+ }
79
+ /**
80
+ * Where NULL sorts, for the whole app: set it on both the server and the client.
81
+ * @see https://remult.dev/docs/field-types#where-null-sorts
82
+ */
83
+ export declare const NullSort: {
84
+ order: NullOrder | 'native';
85
+ };
86
+ /** Where the database sorts NULL when `ORDER BY` does not say, and how `ORDER BY` puts it elsewhere. */
87
+ export interface NativeNullSort {
88
+ /** `unknown`: `ORDER BY` always writes the NULL order. */
89
+ order: NullOrder | 'unknown';
90
+ syntax: 'NULLS FIRST/LAST' | 'CASE WHEN';
91
+ }
92
+ /** Remult's own order, without a database: `native` is NULL lowest. */
93
+ export declare function isNullFirstSort(isDescending?: boolean): boolean;
75
94
  export declare function compareForSort(left: any, right: any, descending: boolean | undefined): number;
76
95
  export declare function fixValueForSort(a: any): any;
package/src/sort.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Sort = void 0;
3
+ exports.NullSort = exports.Sort = void 0;
4
+ exports.isNullFirstSort = isNullFirstSort;
4
5
  exports.compareForSort = compareForSort;
5
6
  exports.fixValueForSort = fixValueForSort;
6
7
  var tslib_1 = require("tslib");
8
+ var remult_static_js_1 = require("./remult-static.js");
7
9
  var relationInfoMember_js_1 = require("./remult3/relationInfoMember.js");
8
10
  /**
9
11
  * The `Sort` class is used to describe sorting criteria for queries. It is mainly used internally,
@@ -218,9 +220,26 @@ var Sort = /** @class */ (function () {
218
220
  return Sort;
219
221
  }());
220
222
  exports.Sort = Sort;
223
+ /**
224
+ * Where NULL sorts, for the whole app: set it on both the server and the client.
225
+ * @see https://remult.dev/docs/field-types#where-null-sorts
226
+ */
227
+ exports.NullSort = remult_static_js_1.remultStatic.nullSort || (remult_static_js_1.remultStatic.nullSort = { order: 'native' });
228
+ /** Remult's own order, without a database: `native` is NULL lowest. */
229
+ function isNullFirstSort(isDescending) {
230
+ if (exports.NullSort.order === 'native')
231
+ return !isDescending;
232
+ return exports.NullSort.order[isDescending ? 'desc' : 'asc'] === 'NULLS FIRST';
233
+ }
221
234
  function compareForSort(left, right, descending) {
222
235
  left = fixValueForSort(left);
223
236
  right = fixValueForSort(right);
237
+ // `null > 'a'` and `null < 'a'` are both false, which is not an order.
238
+ if (left == null || right == null) {
239
+ if (left == right)
240
+ return 0;
241
+ return (left == null) === isNullFirstSort(descending) ? -1 : 1;
242
+ }
224
243
  var r = 0;
225
244
  if (left > right)
226
245
  r = 1;
@@ -1,4 +1,5 @@
1
1
  import type { EntityMetadata } from './remult3/remult3.js';
2
+ import type { NativeNullSort } from './sort.js';
2
3
  export interface SqlImplementation extends HasWrapIdentifier {
3
4
  getLimitSqlSyntax(limit: number, offset: number): string;
4
5
  createCommand(): SqlCommand;
@@ -9,7 +10,7 @@ export interface SqlImplementation extends HasWrapIdentifier {
9
10
  /** true by default */
10
11
  doesNotSupportReturningSyntax?: boolean;
11
12
  doesNotSupportReturningSyntaxOnlyForUpdate?: boolean;
12
- orderByNullsFirst?: boolean;
13
+ nativeNullSort: NativeNullSort;
13
14
  /** Bound-variable cap per statement. Default 2000 (SQL Server is 2100). */
14
15
  maxParametersInOneSqlStatement?: number;
15
16
  end(): Promise<void>;