@koolbase/core 12.41.0 → 12.42.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.
@@ -48,6 +48,11 @@ export type KbWhereNode = {
48
48
  export interface KbSortField {
49
49
  field: string;
50
50
  dir: 'asc' | 'desc';
51
+ /** A location field's (G5): by distance from this point, nearest first. */
52
+ near?: {
53
+ lat: number;
54
+ lng: number;
55
+ };
51
56
  }
52
57
  export declare const KbWhere: {
53
58
  /** Every condition must hold. */
@@ -98,6 +103,8 @@ export declare function KbField(name: string): {
98
103
  onOrAfter: (when: unknown) => KbWhereNode;
99
104
  /** The calendar day of `when` in the query's zone. */
100
105
  on: (when: unknown) => KbWhereNode;
106
+ /** A location field (G5): records at most `km` from the point, by great-circle distance. A record with no position never matches. */
107
+ within: (lat: number, lng: number, km: number) => KbWhereNode;
101
108
  /** No value: missing, null or an empty list. 0, false and an empty text are values. */
102
109
  isEmpty: () => KbWhereNode;
103
110
  isNotEmpty: () => KbWhereNode;
@@ -108,6 +115,8 @@ export declare function KbField(name: string): {
108
115
  export declare const KbSort: {
109
116
  asc: (field: string) => KbSortField;
110
117
  desc: (field: string) => KbSortField;
118
+ /** A location field (G5) by distance from the point, nearest first; records with no position last. */
119
+ near: (field: string, lat: number, lng: number) => KbSortField;
111
120
  };
112
121
  /** Whether options speak #165's language. */
113
122
  export declare function isTypedQuery(o: {
@@ -25,6 +25,12 @@ exports.KbSort = exports.KbValue = exports.KbWhere = void 0;
25
25
  exports.KbField = KbField;
26
26
  exports.isTypedQuery = isTypedQuery;
27
27
  exports.deviceZone = deviceZone;
28
+ function checkPoint(lat, lng) {
29
+ if (!(lat >= -90 && lat <= 90))
30
+ throw new RangeError(`lat ${lat}: -90 to 90`);
31
+ if (!(lng >= -180 && lng <= 180))
32
+ throw new RangeError(`lng ${lng}: -180 to 180`);
33
+ }
28
34
  function group(op, conditions) {
29
35
  if (conditions.length === 0)
30
36
  throw new TypeError('a group needs at least one condition');
@@ -108,6 +114,13 @@ function KbField(name) {
108
114
  onOrAfter: (when) => withValue('on_or_after', when),
109
115
  /** The calendar day of `when` in the query's zone. */
110
116
  on: (when) => withValue('on', when),
117
+ /** A location field (G5): records at most `km` from the point, by great-circle distance. A record with no position never matches. */
118
+ within: (lat, lng, km) => {
119
+ checkPoint(lat, lng);
120
+ if (!(km > 0))
121
+ throw new RangeError(`km ${km}: more than 0`);
122
+ return withValue('within', { lat, lng, km });
123
+ },
111
124
  /** No value: missing, null or an empty list. 0, false and an empty text are values. */
112
125
  isEmpty: () => bare('is_empty'),
113
126
  isNotEmpty: () => bare('is_not_empty'),
@@ -119,6 +132,11 @@ function KbField(name) {
119
132
  exports.KbSort = {
120
133
  asc: (field) => ({ field, dir: 'asc' }),
121
134
  desc: (field) => ({ field, dir: 'desc' }),
135
+ /** A location field (G5) by distance from the point, nearest first; records with no position last. */
136
+ near: (field, lat, lng) => {
137
+ checkPoint(lat, lng);
138
+ return { field, dir: 'asc', near: { lat, lng } };
139
+ },
122
140
  };
123
141
  /** Whether options speak #165's language. */
124
142
  function isTypedQuery(o) {
@@ -48,6 +48,11 @@ export type KbWhereNode = {
48
48
  export interface KbSortField {
49
49
  field: string;
50
50
  dir: 'asc' | 'desc';
51
+ /** A location field's (G5): by distance from this point, nearest first. */
52
+ near?: {
53
+ lat: number;
54
+ lng: number;
55
+ };
51
56
  }
52
57
  export declare const KbWhere: {
53
58
  /** Every condition must hold. */
@@ -98,6 +103,8 @@ export declare function KbField(name: string): {
98
103
  onOrAfter: (when: unknown) => KbWhereNode;
99
104
  /** The calendar day of `when` in the query's zone. */
100
105
  on: (when: unknown) => KbWhereNode;
106
+ /** A location field (G5): records at most `km` from the point, by great-circle distance. A record with no position never matches. */
107
+ within: (lat: number, lng: number, km: number) => KbWhereNode;
101
108
  /** No value: missing, null or an empty list. 0, false and an empty text are values. */
102
109
  isEmpty: () => KbWhereNode;
103
110
  isNotEmpty: () => KbWhereNode;
@@ -108,6 +115,8 @@ export declare function KbField(name: string): {
108
115
  export declare const KbSort: {
109
116
  asc: (field: string) => KbSortField;
110
117
  desc: (field: string) => KbSortField;
118
+ /** A location field (G5) by distance from the point, nearest first; records with no position last. */
119
+ near: (field: string, lat: number, lng: number) => KbSortField;
111
120
  };
112
121
  /** Whether options speak #165's language. */
113
122
  export declare function isTypedQuery(o: {
@@ -19,6 +19,12 @@
19
19
  * on an undeclared field (`query_field_untyped`). Limits, the server's:
20
20
  * groups 3 deep (the outer group is 1), 20 conditions, 100 values in a list.
21
21
  */
22
+ function checkPoint(lat, lng) {
23
+ if (!(lat >= -90 && lat <= 90))
24
+ throw new RangeError(`lat ${lat}: -90 to 90`);
25
+ if (!(lng >= -180 && lng <= 180))
26
+ throw new RangeError(`lng ${lng}: -180 to 180`);
27
+ }
22
28
  function group(op, conditions) {
23
29
  if (conditions.length === 0)
24
30
  throw new TypeError('a group needs at least one condition');
@@ -102,6 +108,13 @@ export function KbField(name) {
102
108
  onOrAfter: (when) => withValue('on_or_after', when),
103
109
  /** The calendar day of `when` in the query's zone. */
104
110
  on: (when) => withValue('on', when),
111
+ /** A location field (G5): records at most `km` from the point, by great-circle distance. A record with no position never matches. */
112
+ within: (lat, lng, km) => {
113
+ checkPoint(lat, lng);
114
+ if (!(km > 0))
115
+ throw new RangeError(`km ${km}: more than 0`);
116
+ return withValue('within', { lat, lng, km });
117
+ },
105
118
  /** No value: missing, null or an empty list. 0, false and an empty text are values. */
106
119
  isEmpty: () => bare('is_empty'),
107
120
  isNotEmpty: () => bare('is_not_empty'),
@@ -113,6 +126,11 @@ export function KbField(name) {
113
126
  export const KbSort = {
114
127
  asc: (field) => ({ field, dir: 'asc' }),
115
128
  desc: (field) => ({ field, dir: 'desc' }),
129
+ /** A location field (G5) by distance from the point, nearest first; records with no position last. */
130
+ near: (field, lat, lng) => {
131
+ checkPoint(lat, lng);
132
+ return { field, dir: 'asc', near: { lat, lng } };
133
+ },
116
134
  };
117
135
  /** Whether options speak #165's language. */
118
136
  export function isTypedQuery(o) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "12.41.0",
3
+ "version": "12.42.0",
4
4
  "description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/esm/index.d.ts",