@koolbase/core 12.52.0 → 12.54.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.
- package/dist/cjs/aggregate.d.ts +94 -0
- package/dist/cjs/database.js +50 -11
- package/dist/cjs/query-builder.d.ts +14 -0
- package/dist/cjs/query-builder.js +11 -0
- package/dist/esm/aggregate.d.ts +94 -0
- package/dist/esm/database.js +50 -11
- package/dist/esm/query-builder.d.ts +14 -0
- package/dist/esm/query-builder.js +11 -0
- package/package.json +1 -1
package/dist/cjs/aggregate.d.ts
CHANGED
|
@@ -80,6 +80,73 @@ export type KoolbaseMeasure = {
|
|
|
80
80
|
byScale?: 1 | 100;
|
|
81
81
|
as: string;
|
|
82
82
|
};
|
|
83
|
+
/** A measure a derived value reads: its name, or its value over the previous window of a comparison. */
|
|
84
|
+
export type KoolbaseDerivedOperand = string | {
|
|
85
|
+
measure: string;
|
|
86
|
+
period: 'previous';
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* A value the server works out from the request's measures, exactly and in
|
|
90
|
+
* one place, so an app does no arithmetic of its own:
|
|
91
|
+
* - `difference`: a minus b
|
|
92
|
+
* - `ratio`: a divided by b
|
|
93
|
+
* - `percent_change`: from b to a, as a fraction (0.25 is up 25%)
|
|
94
|
+
* - `share_of_total`: a group's value over the same measure across every group
|
|
95
|
+
*/
|
|
96
|
+
export type KoolbaseDerived = {
|
|
97
|
+
as: string;
|
|
98
|
+
op: 'difference' | 'ratio' | 'percent_change';
|
|
99
|
+
a: KoolbaseDerivedOperand;
|
|
100
|
+
b: KoolbaseDerivedOperand;
|
|
101
|
+
} | {
|
|
102
|
+
as: string;
|
|
103
|
+
op: 'share_of_total';
|
|
104
|
+
a: string;
|
|
105
|
+
b?: never;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* The same measures over the period before, in one request.
|
|
109
|
+
*
|
|
110
|
+
* `field` is a declared date or date-and-time field, or `created_at`.
|
|
111
|
+
* `period` is a calendar period that is still running (`'month'` compares
|
|
112
|
+
* this month so far with the same days of last month), the last n days
|
|
113
|
+
* against the n before, or a range against one of the same length just
|
|
114
|
+
* before it. `timezone` is required: it decides where a day and a month begin.
|
|
115
|
+
*/
|
|
116
|
+
export interface KoolbaseCompare {
|
|
117
|
+
field: string;
|
|
118
|
+
period: 'day' | 'week' | 'month' | 'quarter' | 'year' | {
|
|
119
|
+
lastDays: number;
|
|
120
|
+
} | {
|
|
121
|
+
from: string;
|
|
122
|
+
to: string;
|
|
123
|
+
};
|
|
124
|
+
timezone: string;
|
|
125
|
+
}
|
|
126
|
+
/** A derived answer: its exact value as a decimal string, or why there is none. */
|
|
127
|
+
export interface KoolbaseDerivedValue {
|
|
128
|
+
value: string | null;
|
|
129
|
+
/**
|
|
130
|
+
* - `no_value`: an operand had nothing to count
|
|
131
|
+
* - `zero_denominator`: a ratio, share or change with nothing to divide by
|
|
132
|
+
* - `new`: a change from 0 to above 0 -- show "New", never a percentage
|
|
133
|
+
* - `no_change`: from 0 to 0 (value is "0")
|
|
134
|
+
* - `no_prior_data`: nothing at all before the current period, so there is no comparison
|
|
135
|
+
*/
|
|
136
|
+
reason?: 'no_value' | 'zero_denominator' | 'new' | 'no_change' | 'no_prior_data';
|
|
137
|
+
}
|
|
138
|
+
/** A window of time: `from` included, `to` not. ISO 8601. */
|
|
139
|
+
export interface KoolbaseSpan {
|
|
140
|
+
from: string;
|
|
141
|
+
to: string;
|
|
142
|
+
}
|
|
143
|
+
/** What a comparison compared, to caption it truthfully. */
|
|
144
|
+
export interface KoolbasePeriods {
|
|
145
|
+
current: KoolbaseSpan;
|
|
146
|
+
previous: KoolbaseSpan;
|
|
147
|
+
/** A calendar period still running: `previous` is the same elapsed span of the one before. */
|
|
148
|
+
partial: boolean;
|
|
149
|
+
}
|
|
83
150
|
/** One aggregation request. */
|
|
84
151
|
export interface KoolbaseAggregateRequest {
|
|
85
152
|
collection: string;
|
|
@@ -97,6 +164,14 @@ export interface KoolbaseAggregateRequest {
|
|
|
97
164
|
groupBy?: KoolbaseGroupBy;
|
|
98
165
|
/** At least one. */
|
|
99
166
|
measures: KoolbaseMeasure[];
|
|
167
|
+
/**
|
|
168
|
+
* Values worked out from the measures, on the server. At most 8. A request
|
|
169
|
+
* with `derived` or `compare` reads what the caller may read: it is never
|
|
170
|
+
* answered on a collection's wider Count rule.
|
|
171
|
+
*/
|
|
172
|
+
derived?: KoolbaseDerived[];
|
|
173
|
+
/** The same measures over the period before. */
|
|
174
|
+
compare?: KoolbaseCompare;
|
|
100
175
|
}
|
|
101
176
|
/** One category and its numbers. */
|
|
102
177
|
export interface KoolbaseAggregateGroup {
|
|
@@ -119,6 +194,13 @@ export interface KoolbaseAggregateGroup {
|
|
|
119
194
|
* and never nothing.
|
|
120
195
|
*/
|
|
121
196
|
fewerThan?: number;
|
|
197
|
+
/** With `compare`: the measures over the previous window, in the same two forms. */
|
|
198
|
+
previous?: {
|
|
199
|
+
values: Record<string, number | null>;
|
|
200
|
+
exact: Record<string, string | null>;
|
|
201
|
+
};
|
|
202
|
+
/** With `derived`: each derived value, keyed by its `as`. */
|
|
203
|
+
derived?: Record<string, KoolbaseDerivedValue>;
|
|
122
204
|
}
|
|
123
205
|
/**
|
|
124
206
|
* How a measure arrived at its number.
|
|
@@ -166,4 +248,16 @@ export interface KoolbaseAggregateResult {
|
|
|
166
248
|
* the caller may read, under the collection's Count rule.
|
|
167
249
|
*/
|
|
168
250
|
fewerThan?: number;
|
|
251
|
+
/** With `compare`: the two windows that were compared. */
|
|
252
|
+
periods?: KoolbasePeriods;
|
|
253
|
+
/** With `compare`: records matched in the previous window. */
|
|
254
|
+
previousMatched?: number;
|
|
255
|
+
/** With `compare`: the previous window's accounting, per measure. */
|
|
256
|
+
previousAccounting?: Record<string, KoolbaseAggregateAccounting>;
|
|
257
|
+
/**
|
|
258
|
+
* With `compare`: false when nothing the caller may read lies before the
|
|
259
|
+
* current period at all -- "this did not exist last month", as distinct
|
|
260
|
+
* from "nothing was sold last month".
|
|
261
|
+
*/
|
|
262
|
+
hasPriorData?: boolean;
|
|
169
263
|
}
|
package/dist/cjs/database.js
CHANGED
|
@@ -723,18 +723,36 @@ class KoolbaseDatabase {
|
|
|
723
723
|
...(m.byScale ? { by_scale: m.byScale } : {}),
|
|
724
724
|
as: m.as,
|
|
725
725
|
})),
|
|
726
|
+
// C6: values the server derives from the measures, and a comparison
|
|
727
|
+
// with the previous period.
|
|
728
|
+
...(request.derived?.length ? { derived: request.derived } : {}),
|
|
729
|
+
...(request.compare
|
|
730
|
+
? {
|
|
731
|
+
compare: {
|
|
732
|
+
field: request.compare.field,
|
|
733
|
+
period: typeof request.compare.period === 'object' && 'lastDays' in request.compare.period
|
|
734
|
+
? { last_days: request.compare.period.lastDays }
|
|
735
|
+
: request.compare.period,
|
|
736
|
+
timezone: request.compare.timezone,
|
|
737
|
+
},
|
|
738
|
+
}
|
|
739
|
+
: {}),
|
|
726
740
|
});
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
741
|
+
const accountingOf = (rawAccounting) => {
|
|
742
|
+
const out = {};
|
|
743
|
+
for (const [name, a] of Object.entries(rawAccounting ?? {})) {
|
|
744
|
+
out[name] = {
|
|
745
|
+
counted: Number(a.counted ?? 0),
|
|
746
|
+
skipped: Number(a.skipped ?? 0),
|
|
747
|
+
skippedReason: a.skipped_reason,
|
|
748
|
+
...(a.skipped_by_field && typeof a.skipped_by_field === 'object'
|
|
749
|
+
? { skippedByField: a.skipped_by_field }
|
|
750
|
+
: {}),
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
return out;
|
|
754
|
+
};
|
|
755
|
+
const accounting = accountingOf(raw.accounting);
|
|
738
756
|
return {
|
|
739
757
|
groups: (raw.groups ?? []).map((g) => ({
|
|
740
758
|
category: String(g.category ?? ''),
|
|
@@ -743,6 +761,18 @@ class KoolbaseDatabase {
|
|
|
743
761
|
exact: g.exact ?? {},
|
|
744
762
|
// Below the collection's count minimum (#299): "Fewer than N".
|
|
745
763
|
...(typeof g.fewer_than === 'number' ? { fewerThan: g.fewer_than } : {}),
|
|
764
|
+
// C6: the previous window's measures, and the derived values.
|
|
765
|
+
...(g.previous && typeof g.previous === 'object'
|
|
766
|
+
? {
|
|
767
|
+
previous: {
|
|
768
|
+
values: g.previous.values ?? {},
|
|
769
|
+
exact: g.previous.exact ?? {},
|
|
770
|
+
},
|
|
771
|
+
}
|
|
772
|
+
: {}),
|
|
773
|
+
...(g.derived && typeof g.derived === 'object'
|
|
774
|
+
? { derived: g.derived }
|
|
775
|
+
: {}),
|
|
746
776
|
})),
|
|
747
777
|
matched: Number(raw.matched ?? 0),
|
|
748
778
|
accounting,
|
|
@@ -752,6 +782,15 @@ class KoolbaseDatabase {
|
|
|
752
782
|
// Below the collection's count minimum (#299): matched is 0 and the
|
|
753
783
|
// number is not said -- show "Fewer than N", never 0.
|
|
754
784
|
...(typeof raw.fewer_than === 'number' ? { fewerThan: raw.fewer_than } : {}),
|
|
785
|
+
// C6, with compare: what was compared, and the previous window's own counts.
|
|
786
|
+
...(raw.periods && typeof raw.periods === 'object'
|
|
787
|
+
? { periods: raw.periods }
|
|
788
|
+
: {}),
|
|
789
|
+
...(typeof raw.previous_matched === 'number' ? { previousMatched: raw.previous_matched } : {}),
|
|
790
|
+
...(raw.previous_accounting && typeof raw.previous_accounting === 'object'
|
|
791
|
+
? { previousAccounting: accountingOf(raw.previous_accounting) }
|
|
792
|
+
: {}),
|
|
793
|
+
...(typeof raw.has_prior_data === 'boolean' ? { hasPriorData: raw.has_prior_data } : {}),
|
|
755
794
|
};
|
|
756
795
|
}
|
|
757
796
|
async conflicts() {
|
|
@@ -36,6 +36,9 @@ export type KbValueJson = {
|
|
|
36
36
|
kind: 'range';
|
|
37
37
|
from: KbValueJson;
|
|
38
38
|
to: KbValueJson;
|
|
39
|
+
} | {
|
|
40
|
+
kind: 'field';
|
|
41
|
+
field: string;
|
|
39
42
|
};
|
|
40
43
|
export type KbWhereNode = {
|
|
41
44
|
op: 'and' | 'or';
|
|
@@ -81,6 +84,17 @@ export declare const KbValue: {
|
|
|
81
84
|
callerUserId: () => KbValueJson;
|
|
82
85
|
/** One of the signed-in user's claims, as the server set it. Refused (caller_claim_missing) without it. */
|
|
83
86
|
callerClaim: (name: string) => KbValueJson;
|
|
87
|
+
/**
|
|
88
|
+
* Another field of the same record, to compare this one with:
|
|
89
|
+
* `KbField('stock').lt(KbValue.field('reorder_level'))`. Both fields must be
|
|
90
|
+
* declared and their types must fit -- number with number, a date with a
|
|
91
|
+
* date or a date and time, a choice with a choice of the same values, a
|
|
92
|
+
* user with a user (or created_by), a reference with a reference to the
|
|
93
|
+
* same collection. With eq, neq, gt, gte, lt, lte, before, after,
|
|
94
|
+
* onOrBefore, onOrAfter and on. A record missing either value never
|
|
95
|
+
* matches. One hop through a reference is allowed: `'order_id.due_date'`.
|
|
96
|
+
*/
|
|
97
|
+
field: (name: string) => KbValueJson;
|
|
84
98
|
};
|
|
85
99
|
/** A record field to filter on: a declared field, or id, created_at, updated_at, created_by. */
|
|
86
100
|
export declare function KbField(name: string): {
|
|
@@ -81,6 +81,17 @@ exports.KbValue = {
|
|
|
81
81
|
callerUserId: () => ({ kind: 'caller', path: 'user_id' }),
|
|
82
82
|
/** One of the signed-in user's claims, as the server set it. Refused (caller_claim_missing) without it. */
|
|
83
83
|
callerClaim: (name) => ({ kind: 'caller', path: `claims.${name}` }),
|
|
84
|
+
/**
|
|
85
|
+
* Another field of the same record, to compare this one with:
|
|
86
|
+
* `KbField('stock').lt(KbValue.field('reorder_level'))`. Both fields must be
|
|
87
|
+
* declared and their types must fit -- number with number, a date with a
|
|
88
|
+
* date or a date and time, a choice with a choice of the same values, a
|
|
89
|
+
* user with a user (or created_by), a reference with a reference to the
|
|
90
|
+
* same collection. With eq, neq, gt, gte, lt, lte, before, after,
|
|
91
|
+
* onOrBefore, onOrAfter and on. A record missing either value never
|
|
92
|
+
* matches. One hop through a reference is allowed: `'order_id.due_date'`.
|
|
93
|
+
*/
|
|
94
|
+
field: (name) => ({ kind: 'field', field: name }),
|
|
84
95
|
};
|
|
85
96
|
/** A record field to filter on: a declared field, or id, created_at, updated_at, created_by. */
|
|
86
97
|
function KbField(name) {
|
package/dist/esm/aggregate.d.ts
CHANGED
|
@@ -80,6 +80,73 @@ export type KoolbaseMeasure = {
|
|
|
80
80
|
byScale?: 1 | 100;
|
|
81
81
|
as: string;
|
|
82
82
|
};
|
|
83
|
+
/** A measure a derived value reads: its name, or its value over the previous window of a comparison. */
|
|
84
|
+
export type KoolbaseDerivedOperand = string | {
|
|
85
|
+
measure: string;
|
|
86
|
+
period: 'previous';
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* A value the server works out from the request's measures, exactly and in
|
|
90
|
+
* one place, so an app does no arithmetic of its own:
|
|
91
|
+
* - `difference`: a minus b
|
|
92
|
+
* - `ratio`: a divided by b
|
|
93
|
+
* - `percent_change`: from b to a, as a fraction (0.25 is up 25%)
|
|
94
|
+
* - `share_of_total`: a group's value over the same measure across every group
|
|
95
|
+
*/
|
|
96
|
+
export type KoolbaseDerived = {
|
|
97
|
+
as: string;
|
|
98
|
+
op: 'difference' | 'ratio' | 'percent_change';
|
|
99
|
+
a: KoolbaseDerivedOperand;
|
|
100
|
+
b: KoolbaseDerivedOperand;
|
|
101
|
+
} | {
|
|
102
|
+
as: string;
|
|
103
|
+
op: 'share_of_total';
|
|
104
|
+
a: string;
|
|
105
|
+
b?: never;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* The same measures over the period before, in one request.
|
|
109
|
+
*
|
|
110
|
+
* `field` is a declared date or date-and-time field, or `created_at`.
|
|
111
|
+
* `period` is a calendar period that is still running (`'month'` compares
|
|
112
|
+
* this month so far with the same days of last month), the last n days
|
|
113
|
+
* against the n before, or a range against one of the same length just
|
|
114
|
+
* before it. `timezone` is required: it decides where a day and a month begin.
|
|
115
|
+
*/
|
|
116
|
+
export interface KoolbaseCompare {
|
|
117
|
+
field: string;
|
|
118
|
+
period: 'day' | 'week' | 'month' | 'quarter' | 'year' | {
|
|
119
|
+
lastDays: number;
|
|
120
|
+
} | {
|
|
121
|
+
from: string;
|
|
122
|
+
to: string;
|
|
123
|
+
};
|
|
124
|
+
timezone: string;
|
|
125
|
+
}
|
|
126
|
+
/** A derived answer: its exact value as a decimal string, or why there is none. */
|
|
127
|
+
export interface KoolbaseDerivedValue {
|
|
128
|
+
value: string | null;
|
|
129
|
+
/**
|
|
130
|
+
* - `no_value`: an operand had nothing to count
|
|
131
|
+
* - `zero_denominator`: a ratio, share or change with nothing to divide by
|
|
132
|
+
* - `new`: a change from 0 to above 0 -- show "New", never a percentage
|
|
133
|
+
* - `no_change`: from 0 to 0 (value is "0")
|
|
134
|
+
* - `no_prior_data`: nothing at all before the current period, so there is no comparison
|
|
135
|
+
*/
|
|
136
|
+
reason?: 'no_value' | 'zero_denominator' | 'new' | 'no_change' | 'no_prior_data';
|
|
137
|
+
}
|
|
138
|
+
/** A window of time: `from` included, `to` not. ISO 8601. */
|
|
139
|
+
export interface KoolbaseSpan {
|
|
140
|
+
from: string;
|
|
141
|
+
to: string;
|
|
142
|
+
}
|
|
143
|
+
/** What a comparison compared, to caption it truthfully. */
|
|
144
|
+
export interface KoolbasePeriods {
|
|
145
|
+
current: KoolbaseSpan;
|
|
146
|
+
previous: KoolbaseSpan;
|
|
147
|
+
/** A calendar period still running: `previous` is the same elapsed span of the one before. */
|
|
148
|
+
partial: boolean;
|
|
149
|
+
}
|
|
83
150
|
/** One aggregation request. */
|
|
84
151
|
export interface KoolbaseAggregateRequest {
|
|
85
152
|
collection: string;
|
|
@@ -97,6 +164,14 @@ export interface KoolbaseAggregateRequest {
|
|
|
97
164
|
groupBy?: KoolbaseGroupBy;
|
|
98
165
|
/** At least one. */
|
|
99
166
|
measures: KoolbaseMeasure[];
|
|
167
|
+
/**
|
|
168
|
+
* Values worked out from the measures, on the server. At most 8. A request
|
|
169
|
+
* with `derived` or `compare` reads what the caller may read: it is never
|
|
170
|
+
* answered on a collection's wider Count rule.
|
|
171
|
+
*/
|
|
172
|
+
derived?: KoolbaseDerived[];
|
|
173
|
+
/** The same measures over the period before. */
|
|
174
|
+
compare?: KoolbaseCompare;
|
|
100
175
|
}
|
|
101
176
|
/** One category and its numbers. */
|
|
102
177
|
export interface KoolbaseAggregateGroup {
|
|
@@ -119,6 +194,13 @@ export interface KoolbaseAggregateGroup {
|
|
|
119
194
|
* and never nothing.
|
|
120
195
|
*/
|
|
121
196
|
fewerThan?: number;
|
|
197
|
+
/** With `compare`: the measures over the previous window, in the same two forms. */
|
|
198
|
+
previous?: {
|
|
199
|
+
values: Record<string, number | null>;
|
|
200
|
+
exact: Record<string, string | null>;
|
|
201
|
+
};
|
|
202
|
+
/** With `derived`: each derived value, keyed by its `as`. */
|
|
203
|
+
derived?: Record<string, KoolbaseDerivedValue>;
|
|
122
204
|
}
|
|
123
205
|
/**
|
|
124
206
|
* How a measure arrived at its number.
|
|
@@ -166,4 +248,16 @@ export interface KoolbaseAggregateResult {
|
|
|
166
248
|
* the caller may read, under the collection's Count rule.
|
|
167
249
|
*/
|
|
168
250
|
fewerThan?: number;
|
|
251
|
+
/** With `compare`: the two windows that were compared. */
|
|
252
|
+
periods?: KoolbasePeriods;
|
|
253
|
+
/** With `compare`: records matched in the previous window. */
|
|
254
|
+
previousMatched?: number;
|
|
255
|
+
/** With `compare`: the previous window's accounting, per measure. */
|
|
256
|
+
previousAccounting?: Record<string, KoolbaseAggregateAccounting>;
|
|
257
|
+
/**
|
|
258
|
+
* With `compare`: false when nothing the caller may read lies before the
|
|
259
|
+
* current period at all -- "this did not exist last month", as distinct
|
|
260
|
+
* from "nothing was sold last month".
|
|
261
|
+
*/
|
|
262
|
+
hasPriorData?: boolean;
|
|
169
263
|
}
|
package/dist/esm/database.js
CHANGED
|
@@ -720,18 +720,36 @@ export class KoolbaseDatabase {
|
|
|
720
720
|
...(m.byScale ? { by_scale: m.byScale } : {}),
|
|
721
721
|
as: m.as,
|
|
722
722
|
})),
|
|
723
|
+
// C6: values the server derives from the measures, and a comparison
|
|
724
|
+
// with the previous period.
|
|
725
|
+
...(request.derived?.length ? { derived: request.derived } : {}),
|
|
726
|
+
...(request.compare
|
|
727
|
+
? {
|
|
728
|
+
compare: {
|
|
729
|
+
field: request.compare.field,
|
|
730
|
+
period: typeof request.compare.period === 'object' && 'lastDays' in request.compare.period
|
|
731
|
+
? { last_days: request.compare.period.lastDays }
|
|
732
|
+
: request.compare.period,
|
|
733
|
+
timezone: request.compare.timezone,
|
|
734
|
+
},
|
|
735
|
+
}
|
|
736
|
+
: {}),
|
|
723
737
|
});
|
|
724
|
-
const
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
738
|
+
const accountingOf = (rawAccounting) => {
|
|
739
|
+
const out = {};
|
|
740
|
+
for (const [name, a] of Object.entries(rawAccounting ?? {})) {
|
|
741
|
+
out[name] = {
|
|
742
|
+
counted: Number(a.counted ?? 0),
|
|
743
|
+
skipped: Number(a.skipped ?? 0),
|
|
744
|
+
skippedReason: a.skipped_reason,
|
|
745
|
+
...(a.skipped_by_field && typeof a.skipped_by_field === 'object'
|
|
746
|
+
? { skippedByField: a.skipped_by_field }
|
|
747
|
+
: {}),
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
return out;
|
|
751
|
+
};
|
|
752
|
+
const accounting = accountingOf(raw.accounting);
|
|
735
753
|
return {
|
|
736
754
|
groups: (raw.groups ?? []).map((g) => ({
|
|
737
755
|
category: String(g.category ?? ''),
|
|
@@ -740,6 +758,18 @@ export class KoolbaseDatabase {
|
|
|
740
758
|
exact: g.exact ?? {},
|
|
741
759
|
// Below the collection's count minimum (#299): "Fewer than N".
|
|
742
760
|
...(typeof g.fewer_than === 'number' ? { fewerThan: g.fewer_than } : {}),
|
|
761
|
+
// C6: the previous window's measures, and the derived values.
|
|
762
|
+
...(g.previous && typeof g.previous === 'object'
|
|
763
|
+
? {
|
|
764
|
+
previous: {
|
|
765
|
+
values: g.previous.values ?? {},
|
|
766
|
+
exact: g.previous.exact ?? {},
|
|
767
|
+
},
|
|
768
|
+
}
|
|
769
|
+
: {}),
|
|
770
|
+
...(g.derived && typeof g.derived === 'object'
|
|
771
|
+
? { derived: g.derived }
|
|
772
|
+
: {}),
|
|
743
773
|
})),
|
|
744
774
|
matched: Number(raw.matched ?? 0),
|
|
745
775
|
accounting,
|
|
@@ -749,6 +779,15 @@ export class KoolbaseDatabase {
|
|
|
749
779
|
// Below the collection's count minimum (#299): matched is 0 and the
|
|
750
780
|
// number is not said -- show "Fewer than N", never 0.
|
|
751
781
|
...(typeof raw.fewer_than === 'number' ? { fewerThan: raw.fewer_than } : {}),
|
|
782
|
+
// C6, with compare: what was compared, and the previous window's own counts.
|
|
783
|
+
...(raw.periods && typeof raw.periods === 'object'
|
|
784
|
+
? { periods: raw.periods }
|
|
785
|
+
: {}),
|
|
786
|
+
...(typeof raw.previous_matched === 'number' ? { previousMatched: raw.previous_matched } : {}),
|
|
787
|
+
...(raw.previous_accounting && typeof raw.previous_accounting === 'object'
|
|
788
|
+
? { previousAccounting: accountingOf(raw.previous_accounting) }
|
|
789
|
+
: {}),
|
|
790
|
+
...(typeof raw.has_prior_data === 'boolean' ? { hasPriorData: raw.has_prior_data } : {}),
|
|
752
791
|
};
|
|
753
792
|
}
|
|
754
793
|
async conflicts() {
|
|
@@ -36,6 +36,9 @@ export type KbValueJson = {
|
|
|
36
36
|
kind: 'range';
|
|
37
37
|
from: KbValueJson;
|
|
38
38
|
to: KbValueJson;
|
|
39
|
+
} | {
|
|
40
|
+
kind: 'field';
|
|
41
|
+
field: string;
|
|
39
42
|
};
|
|
40
43
|
export type KbWhereNode = {
|
|
41
44
|
op: 'and' | 'or';
|
|
@@ -81,6 +84,17 @@ export declare const KbValue: {
|
|
|
81
84
|
callerUserId: () => KbValueJson;
|
|
82
85
|
/** One of the signed-in user's claims, as the server set it. Refused (caller_claim_missing) without it. */
|
|
83
86
|
callerClaim: (name: string) => KbValueJson;
|
|
87
|
+
/**
|
|
88
|
+
* Another field of the same record, to compare this one with:
|
|
89
|
+
* `KbField('stock').lt(KbValue.field('reorder_level'))`. Both fields must be
|
|
90
|
+
* declared and their types must fit -- number with number, a date with a
|
|
91
|
+
* date or a date and time, a choice with a choice of the same values, a
|
|
92
|
+
* user with a user (or created_by), a reference with a reference to the
|
|
93
|
+
* same collection. With eq, neq, gt, gte, lt, lte, before, after,
|
|
94
|
+
* onOrBefore, onOrAfter and on. A record missing either value never
|
|
95
|
+
* matches. One hop through a reference is allowed: `'order_id.due_date'`.
|
|
96
|
+
*/
|
|
97
|
+
field: (name: string) => KbValueJson;
|
|
84
98
|
};
|
|
85
99
|
/** A record field to filter on: a declared field, or id, created_at, updated_at, created_by. */
|
|
86
100
|
export declare function KbField(name: string): {
|
|
@@ -75,6 +75,17 @@ export const KbValue = {
|
|
|
75
75
|
callerUserId: () => ({ kind: 'caller', path: 'user_id' }),
|
|
76
76
|
/** One of the signed-in user's claims, as the server set it. Refused (caller_claim_missing) without it. */
|
|
77
77
|
callerClaim: (name) => ({ kind: 'caller', path: `claims.${name}` }),
|
|
78
|
+
/**
|
|
79
|
+
* Another field of the same record, to compare this one with:
|
|
80
|
+
* `KbField('stock').lt(KbValue.field('reorder_level'))`. Both fields must be
|
|
81
|
+
* declared and their types must fit -- number with number, a date with a
|
|
82
|
+
* date or a date and time, a choice with a choice of the same values, a
|
|
83
|
+
* user with a user (or created_by), a reference with a reference to the
|
|
84
|
+
* same collection. With eq, neq, gt, gte, lt, lte, before, after,
|
|
85
|
+
* onOrBefore, onOrAfter and on. A record missing either value never
|
|
86
|
+
* matches. One hop through a reference is allowed: `'order_id.due_date'`.
|
|
87
|
+
*/
|
|
88
|
+
field: (name) => ({ kind: 'field', field: name }),
|
|
78
89
|
};
|
|
79
90
|
/** A record field to filter on: a declared field, or id, created_at, updated_at, created_by. */
|
|
80
91
|
export function KbField(name) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.54.0",
|
|
4
4
|
"description": "Koolbase SDK core — shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"react-native": "./dist/esm/index.js",
|