@koolbase/core 12.49.0 → 12.50.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/database-errors.d.ts +19 -3
- package/dist/cjs/database-errors.js +12 -3
- package/dist/cjs/database.js +11 -2
- package/dist/cjs/types.d.ts +10 -2
- package/dist/cjs/types.js +11 -2
- package/dist/esm/database-errors.d.ts +19 -3
- package/dist/esm/database-errors.js +12 -3
- package/dist/esm/database.js +11 -2
- package/dist/esm/types.d.ts +10 -2
- package/dist/esm/types.js +11 -2
- package/package.json +1 -1
|
@@ -188,11 +188,27 @@ export declare class KoolbaseProviderInvalidError extends KoolbaseDataError {
|
|
|
188
188
|
export declare class KoolbaseRevisionMismatchError extends KoolbaseDataError {
|
|
189
189
|
readonly expectedRevision?: number | undefined;
|
|
190
190
|
readonly currentRevision?: number | undefined;
|
|
191
|
-
/**
|
|
191
|
+
/**
|
|
192
|
+
* The record as the server holds it now. Absent when the caller may not
|
|
193
|
+
* read it ({@link readable} false): a failed write never discloses it.
|
|
194
|
+
*/
|
|
192
195
|
readonly current?: Record<string, unknown> | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* Whether the caller may read the record now. False: the server withheld
|
|
198
|
+
* it and said only the revisions. Undefined from an older API.
|
|
199
|
+
*/
|
|
200
|
+
readonly readable?: boolean | undefined;
|
|
193
201
|
constructor(message?: string, expectedRevision?: number | undefined, currentRevision?: number | undefined,
|
|
194
|
-
/**
|
|
195
|
-
|
|
202
|
+
/**
|
|
203
|
+
* The record as the server holds it now. Absent when the caller may not
|
|
204
|
+
* read it ({@link readable} false): a failed write never discloses it.
|
|
205
|
+
*/
|
|
206
|
+
current?: Record<string, unknown> | undefined,
|
|
207
|
+
/**
|
|
208
|
+
* Whether the caller may read the record now. False: the server withheld
|
|
209
|
+
* it and said only the revisions. Undefined from an older API.
|
|
210
|
+
*/
|
|
211
|
+
readable?: boolean | undefined);
|
|
196
212
|
}
|
|
197
213
|
/**
|
|
198
214
|
* The same idempotency key sent with different data.
|
|
@@ -253,12 +253,21 @@ class KoolbaseProviderInvalidError extends KoolbaseDataError {
|
|
|
253
253
|
exports.KoolbaseProviderInvalidError = KoolbaseProviderInvalidError;
|
|
254
254
|
class KoolbaseRevisionMismatchError extends KoolbaseDataError {
|
|
255
255
|
constructor(message, expectedRevision, currentRevision,
|
|
256
|
-
/**
|
|
257
|
-
|
|
256
|
+
/**
|
|
257
|
+
* The record as the server holds it now. Absent when the caller may not
|
|
258
|
+
* read it ({@link readable} false): a failed write never discloses it.
|
|
259
|
+
*/
|
|
260
|
+
current,
|
|
261
|
+
/**
|
|
262
|
+
* Whether the caller may read the record now. False: the server withheld
|
|
263
|
+
* it and said only the revisions. Undefined from an older API.
|
|
264
|
+
*/
|
|
265
|
+
readable) {
|
|
258
266
|
super(message ?? 'The record has changed since you read it', 'revision_mismatch');
|
|
259
267
|
this.expectedRevision = expectedRevision;
|
|
260
268
|
this.currentRevision = currentRevision;
|
|
261
269
|
this.current = current;
|
|
270
|
+
this.readable = readable;
|
|
262
271
|
this.name = 'KoolbaseRevisionMismatchError';
|
|
263
272
|
Object.setPrototypeOf(this, KoolbaseRevisionMismatchError.prototype);
|
|
264
273
|
}
|
|
@@ -595,7 +604,7 @@ function koolbaseDataError(status, body, fallbackMessage = 'Request failed') {
|
|
|
595
604
|
// exactly this. attach() still puts the whole bag on the error, so
|
|
596
605
|
// nothing is lost for a caller reading it directly.
|
|
597
606
|
const d = (body?.details ?? {});
|
|
598
|
-
return attach(new KoolbaseRevisionMismatchError(message, d.expected_revision, d.current_revision, d.record));
|
|
607
|
+
return attach(new KoolbaseRevisionMismatchError(message, d.expected_revision, d.current_revision, d.record, typeof d.readable === 'boolean' ? d.readable : undefined));
|
|
599
608
|
}
|
|
600
609
|
// Two codes, one situation — the database and fiscal packages name it
|
|
601
610
|
// differently and a caller should not have to know which spoke.
|
package/dist/cjs/database.js
CHANGED
|
@@ -33,9 +33,18 @@ function batchOpToWire(op) {
|
|
|
33
33
|
case 'insert':
|
|
34
34
|
return { type: 'insert', collection: op.collection, data: op.data };
|
|
35
35
|
case 'update':
|
|
36
|
-
return {
|
|
36
|
+
return {
|
|
37
|
+
type: 'update',
|
|
38
|
+
record_id: op.recordId,
|
|
39
|
+
data: op.data,
|
|
40
|
+
...(op.expectedRevision !== undefined ? { expected_revision: op.expectedRevision } : {}),
|
|
41
|
+
};
|
|
37
42
|
case 'delete':
|
|
38
|
-
return {
|
|
43
|
+
return {
|
|
44
|
+
type: 'delete',
|
|
45
|
+
record_id: op.recordId,
|
|
46
|
+
...(op.expectedRevision !== undefined ? { expected_revision: op.expectedRevision } : {}),
|
|
47
|
+
};
|
|
39
48
|
case 'upsert':
|
|
40
49
|
return {
|
|
41
50
|
type: 'upsert',
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -719,9 +719,13 @@ export type BatchOp = {
|
|
|
719
719
|
type: 'update';
|
|
720
720
|
recordId: string;
|
|
721
721
|
data: Record<string, unknown>;
|
|
722
|
+
/** Conditional: applies only if the record still carries this revision; a mismatch rolls back the whole batch. */
|
|
723
|
+
expectedRevision?: number;
|
|
722
724
|
} | {
|
|
723
725
|
type: 'delete';
|
|
724
726
|
recordId: string;
|
|
727
|
+
/** Conditional, as update's (needs the API with conditional batch deletes). */
|
|
728
|
+
expectedRevision?: number;
|
|
725
729
|
} | {
|
|
726
730
|
type: 'upsert';
|
|
727
731
|
collection: string;
|
|
@@ -735,8 +739,12 @@ export type BatchOp = {
|
|
|
735
739
|
*/
|
|
736
740
|
export declare const BatchOp: {
|
|
737
741
|
insert: (collection: string, data: Record<string, unknown>) => BatchOp;
|
|
738
|
-
update: (recordId: string, data: Record<string, unknown
|
|
739
|
-
|
|
742
|
+
update: (recordId: string, data: Record<string, unknown>, opts?: {
|
|
743
|
+
expectedRevision?: number;
|
|
744
|
+
}) => BatchOp;
|
|
745
|
+
delete: (recordId: string, opts?: {
|
|
746
|
+
expectedRevision?: number;
|
|
747
|
+
}) => BatchOp;
|
|
740
748
|
upsert: (collection: string, opts: {
|
|
741
749
|
match: Record<string, unknown>;
|
|
742
750
|
data: Record<string, unknown>;
|
package/dist/cjs/types.js
CHANGED
|
@@ -29,8 +29,17 @@ var FunctionRuntime;
|
|
|
29
29
|
*/
|
|
30
30
|
exports.BatchOp = {
|
|
31
31
|
insert: (collection, data) => ({ type: 'insert', collection, data }),
|
|
32
|
-
update: (recordId, data) => ({
|
|
33
|
-
|
|
32
|
+
update: (recordId, data, opts) => ({
|
|
33
|
+
type: 'update',
|
|
34
|
+
recordId,
|
|
35
|
+
data,
|
|
36
|
+
...(opts?.expectedRevision !== undefined ? { expectedRevision: opts.expectedRevision } : {}),
|
|
37
|
+
}),
|
|
38
|
+
delete: (recordId, opts) => ({
|
|
39
|
+
type: 'delete',
|
|
40
|
+
recordId,
|
|
41
|
+
...(opts?.expectedRevision !== undefined ? { expectedRevision: opts.expectedRevision } : {}),
|
|
42
|
+
}),
|
|
34
43
|
upsert: (collection, opts) => ({
|
|
35
44
|
type: 'upsert',
|
|
36
45
|
collection,
|
|
@@ -188,11 +188,27 @@ export declare class KoolbaseProviderInvalidError extends KoolbaseDataError {
|
|
|
188
188
|
export declare class KoolbaseRevisionMismatchError extends KoolbaseDataError {
|
|
189
189
|
readonly expectedRevision?: number | undefined;
|
|
190
190
|
readonly currentRevision?: number | undefined;
|
|
191
|
-
/**
|
|
191
|
+
/**
|
|
192
|
+
* The record as the server holds it now. Absent when the caller may not
|
|
193
|
+
* read it ({@link readable} false): a failed write never discloses it.
|
|
194
|
+
*/
|
|
192
195
|
readonly current?: Record<string, unknown> | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* Whether the caller may read the record now. False: the server withheld
|
|
198
|
+
* it and said only the revisions. Undefined from an older API.
|
|
199
|
+
*/
|
|
200
|
+
readonly readable?: boolean | undefined;
|
|
193
201
|
constructor(message?: string, expectedRevision?: number | undefined, currentRevision?: number | undefined,
|
|
194
|
-
/**
|
|
195
|
-
|
|
202
|
+
/**
|
|
203
|
+
* The record as the server holds it now. Absent when the caller may not
|
|
204
|
+
* read it ({@link readable} false): a failed write never discloses it.
|
|
205
|
+
*/
|
|
206
|
+
current?: Record<string, unknown> | undefined,
|
|
207
|
+
/**
|
|
208
|
+
* Whether the caller may read the record now. False: the server withheld
|
|
209
|
+
* it and said only the revisions. Undefined from an older API.
|
|
210
|
+
*/
|
|
211
|
+
readable?: boolean | undefined);
|
|
196
212
|
}
|
|
197
213
|
/**
|
|
198
214
|
* The same idempotency key sent with different data.
|
|
@@ -233,12 +233,21 @@ export class KoolbaseProviderInvalidError extends KoolbaseDataError {
|
|
|
233
233
|
}
|
|
234
234
|
export class KoolbaseRevisionMismatchError extends KoolbaseDataError {
|
|
235
235
|
constructor(message, expectedRevision, currentRevision,
|
|
236
|
-
/**
|
|
237
|
-
|
|
236
|
+
/**
|
|
237
|
+
* The record as the server holds it now. Absent when the caller may not
|
|
238
|
+
* read it ({@link readable} false): a failed write never discloses it.
|
|
239
|
+
*/
|
|
240
|
+
current,
|
|
241
|
+
/**
|
|
242
|
+
* Whether the caller may read the record now. False: the server withheld
|
|
243
|
+
* it and said only the revisions. Undefined from an older API.
|
|
244
|
+
*/
|
|
245
|
+
readable) {
|
|
238
246
|
super(message ?? 'The record has changed since you read it', 'revision_mismatch');
|
|
239
247
|
this.expectedRevision = expectedRevision;
|
|
240
248
|
this.currentRevision = currentRevision;
|
|
241
249
|
this.current = current;
|
|
250
|
+
this.readable = readable;
|
|
242
251
|
this.name = 'KoolbaseRevisionMismatchError';
|
|
243
252
|
Object.setPrototypeOf(this, KoolbaseRevisionMismatchError.prototype);
|
|
244
253
|
}
|
|
@@ -557,7 +566,7 @@ export function koolbaseDataError(status, body, fallbackMessage = 'Request faile
|
|
|
557
566
|
// exactly this. attach() still puts the whole bag on the error, so
|
|
558
567
|
// nothing is lost for a caller reading it directly.
|
|
559
568
|
const d = (body?.details ?? {});
|
|
560
|
-
return attach(new KoolbaseRevisionMismatchError(message, d.expected_revision, d.current_revision, d.record));
|
|
569
|
+
return attach(new KoolbaseRevisionMismatchError(message, d.expected_revision, d.current_revision, d.record, typeof d.readable === 'boolean' ? d.readable : undefined));
|
|
561
570
|
}
|
|
562
571
|
// Two codes, one situation — the database and fiscal packages name it
|
|
563
572
|
// differently and a caller should not have to know which spoke.
|
package/dist/esm/database.js
CHANGED
|
@@ -30,9 +30,18 @@ function batchOpToWire(op) {
|
|
|
30
30
|
case 'insert':
|
|
31
31
|
return { type: 'insert', collection: op.collection, data: op.data };
|
|
32
32
|
case 'update':
|
|
33
|
-
return {
|
|
33
|
+
return {
|
|
34
|
+
type: 'update',
|
|
35
|
+
record_id: op.recordId,
|
|
36
|
+
data: op.data,
|
|
37
|
+
...(op.expectedRevision !== undefined ? { expected_revision: op.expectedRevision } : {}),
|
|
38
|
+
};
|
|
34
39
|
case 'delete':
|
|
35
|
-
return {
|
|
40
|
+
return {
|
|
41
|
+
type: 'delete',
|
|
42
|
+
record_id: op.recordId,
|
|
43
|
+
...(op.expectedRevision !== undefined ? { expected_revision: op.expectedRevision } : {}),
|
|
44
|
+
};
|
|
36
45
|
case 'upsert':
|
|
37
46
|
return {
|
|
38
47
|
type: 'upsert',
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -719,9 +719,13 @@ export type BatchOp = {
|
|
|
719
719
|
type: 'update';
|
|
720
720
|
recordId: string;
|
|
721
721
|
data: Record<string, unknown>;
|
|
722
|
+
/** Conditional: applies only if the record still carries this revision; a mismatch rolls back the whole batch. */
|
|
723
|
+
expectedRevision?: number;
|
|
722
724
|
} | {
|
|
723
725
|
type: 'delete';
|
|
724
726
|
recordId: string;
|
|
727
|
+
/** Conditional, as update's (needs the API with conditional batch deletes). */
|
|
728
|
+
expectedRevision?: number;
|
|
725
729
|
} | {
|
|
726
730
|
type: 'upsert';
|
|
727
731
|
collection: string;
|
|
@@ -735,8 +739,12 @@ export type BatchOp = {
|
|
|
735
739
|
*/
|
|
736
740
|
export declare const BatchOp: {
|
|
737
741
|
insert: (collection: string, data: Record<string, unknown>) => BatchOp;
|
|
738
|
-
update: (recordId: string, data: Record<string, unknown
|
|
739
|
-
|
|
742
|
+
update: (recordId: string, data: Record<string, unknown>, opts?: {
|
|
743
|
+
expectedRevision?: number;
|
|
744
|
+
}) => BatchOp;
|
|
745
|
+
delete: (recordId: string, opts?: {
|
|
746
|
+
expectedRevision?: number;
|
|
747
|
+
}) => BatchOp;
|
|
740
748
|
upsert: (collection: string, opts: {
|
|
741
749
|
match: Record<string, unknown>;
|
|
742
750
|
data: Record<string, unknown>;
|
package/dist/esm/types.js
CHANGED
|
@@ -26,8 +26,17 @@ export var FunctionRuntime;
|
|
|
26
26
|
*/
|
|
27
27
|
export const BatchOp = {
|
|
28
28
|
insert: (collection, data) => ({ type: 'insert', collection, data }),
|
|
29
|
-
update: (recordId, data) => ({
|
|
30
|
-
|
|
29
|
+
update: (recordId, data, opts) => ({
|
|
30
|
+
type: 'update',
|
|
31
|
+
recordId,
|
|
32
|
+
data,
|
|
33
|
+
...(opts?.expectedRevision !== undefined ? { expectedRevision: opts.expectedRevision } : {}),
|
|
34
|
+
}),
|
|
35
|
+
delete: (recordId, opts) => ({
|
|
36
|
+
type: 'delete',
|
|
37
|
+
recordId,
|
|
38
|
+
...(opts?.expectedRevision !== undefined ? { expectedRevision: opts.expectedRevision } : {}),
|
|
39
|
+
}),
|
|
31
40
|
upsert: (collection, opts) => ({
|
|
32
41
|
type: 'upsert',
|
|
33
42
|
collection,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.50.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",
|