@stonecrop/stonecrop 0.23.0 → 0.25.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/src/stonecrop.d.ts +4 -5
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/stonecrop.js +17 -1
- package/dist/src/types/stonecrop.d.ts +15 -0
- package/dist/src/types/stonecrop.d.ts.map +1 -1
- package/dist/stonecrop.d.ts +19 -4
- package/dist/stonecrop.js +10 -4
- package/dist/stonecrop.js.map +1 -1
- package/package.json +4 -4
- package/src/stonecrop.ts +21 -4
- package/src/types/stonecrop.ts +16 -0
package/dist/src/stonecrop.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import Registry from './registry';
|
|
|
4
4
|
import { type HSTNode } from './stores/hst';
|
|
5
5
|
import type { OperationLogConfig } from './types/operation-log';
|
|
6
6
|
import type { RouteContext } from './types/registry';
|
|
7
|
-
import type { StonecropOptions } from './types/stonecrop';
|
|
7
|
+
import type { PageInfo, StonecropOptions } from './types/stonecrop';
|
|
8
8
|
/**
|
|
9
9
|
* Main Stonecrop class with HST integration and built-in Operation Log
|
|
10
10
|
* @public
|
|
@@ -393,6 +393,8 @@ export declare class Stonecrop {
|
|
|
393
393
|
* nothing on this side of the wire knows what is safe for an arbitrary backend. A caller that
|
|
394
394
|
* passes none gets whatever the server considers a reasonable page.
|
|
395
395
|
*
|
|
396
|
+
* `options.offset === 0` (or omitted) replaces the doctype's HST records; `offset > 0` appends.
|
|
397
|
+
*
|
|
396
398
|
* @param doctype - The doctype
|
|
397
399
|
* @param options - Query options (filters, orderBy, limit, offset), forwarded to the client
|
|
398
400
|
* @throws Error if no data client has been configured
|
|
@@ -410,10 +412,7 @@ export declare class Stonecrop {
|
|
|
410
412
|
* @returns Page info, or undefined if this doctype's records have not been fetched
|
|
411
413
|
* @public
|
|
412
414
|
*/
|
|
413
|
-
getPageInfo(doctype: string | Doctype):
|
|
414
|
-
hasMore: boolean;
|
|
415
|
-
count?: number;
|
|
416
|
-
} | undefined;
|
|
415
|
+
getPageInfo(doctype: string | Doctype): PageInfo | undefined;
|
|
417
416
|
/**
|
|
418
417
|
* Fetch a single record from the server and store it in HST.
|
|
419
418
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../src/stonecrop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAG1G,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../src/stonecrop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAG1G,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEnE;;;GAGG;AACH,qBAAa,SAAS;IACrB;;;;;OAKG;IACH,MAAM,CAAC,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;KAAE,CAAC;IA2BrE;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAM3B;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC;IAOlD;;;OAGG;IACH,QAAQ,IAAI,OAAO;IAInB;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IA6BnE;;;;;;OAMG;IACH,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IA+B7E;;;;;;;;;OASG;IACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAoB1D;;;;;;;;;;;;;OAaG;IACG,eAAe,CACpB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;KAAE,GAC9C,OAAO,CAAC,IAAI,CAAC;IAgChB;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;CA2BzB"}
|
package/dist/src/stonecrop.js
CHANGED
|
@@ -258,6 +258,8 @@ export class Stonecrop {
|
|
|
258
258
|
* nothing on this side of the wire knows what is safe for an arbitrary backend. A caller that
|
|
259
259
|
* passes none gets whatever the server considers a reasonable page.
|
|
260
260
|
*
|
|
261
|
+
* `options.offset === 0` (or omitted) replaces the doctype's HST records; `offset > 0` appends.
|
|
262
|
+
*
|
|
261
263
|
* @param doctype - The doctype
|
|
262
264
|
* @param options - Query options (filters, orderBy, limit, offset), forwarded to the client
|
|
263
265
|
* @throws Error if no data client has been configured
|
|
@@ -270,10 +272,24 @@ export class Stonecrop {
|
|
|
270
272
|
}
|
|
271
273
|
const result = await this._client.getRecords(doctype, options);
|
|
272
274
|
const records = result.data;
|
|
275
|
+
const offset = options?.offset ?? 0;
|
|
273
276
|
// Page info is kept beside HST, not in it. `getRecordIds` reads the raw keys under a
|
|
274
277
|
// doctype node, so anything filed there becomes a phantom record — the same hazard that
|
|
275
278
|
// ruled out seeding a draft node.
|
|
276
|
-
|
|
279
|
+
const pageEntry = {
|
|
280
|
+
hasMore: result.hasMore,
|
|
281
|
+
offset,
|
|
282
|
+
limit: records.length,
|
|
283
|
+
};
|
|
284
|
+
if (result.count != null) {
|
|
285
|
+
pageEntry.count = result.count;
|
|
286
|
+
}
|
|
287
|
+
this.pageInfo[doctype.slug] = pageEntry;
|
|
288
|
+
// offset === 0 replaces the doctype's HST records; offset > 0 appends. A failed fetch
|
|
289
|
+
// must not clear — that happens only after a successful response lands above.
|
|
290
|
+
if (offset === 0) {
|
|
291
|
+
this.clearRecords(doctype);
|
|
292
|
+
}
|
|
277
293
|
// Key each record by its declared primary key, falling back to `id`. This used to read
|
|
278
294
|
// `record.id` only, which silently dropped every row of a natural-keyed doctype (no `id`
|
|
279
295
|
// column at all) — the records never entered HST, so the list rendered empty and no
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import type { DataClient } from '@stonecrop/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Pagination metadata from the last {@link Stonecrop.getRecords} for a doctype.
|
|
4
|
+
* Kept beside HST, not in it — see {@link Stonecrop.getPageInfo}.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface PageInfo {
|
|
8
|
+
/** Whether the backend holds further records beyond what has been fetched */
|
|
9
|
+
hasMore: boolean;
|
|
10
|
+
/** Total matching the filters when the caller passed includeTotal */
|
|
11
|
+
count?: number;
|
|
12
|
+
/** Offset of the last fetch */
|
|
13
|
+
offset: number;
|
|
14
|
+
/** Number of rows in the last page (result.data.length) */
|
|
15
|
+
limit: number;
|
|
16
|
+
}
|
|
2
17
|
/**
|
|
3
18
|
* Options for constructing a Stonecrop instance directly.
|
|
4
19
|
* When using the Vue plugin, pass these via `InstallOptions` instead.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../../src/types/stonecrop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,UAAU,CAAA;CACnB"}
|
|
1
|
+
{"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../../src/types/stonecrop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACxB,6EAA6E;IAC7E,OAAO,EAAE,OAAO,CAAA;IAChB,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,+BAA+B;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAA;CACb;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,UAAU,CAAA;CACnB"}
|
package/dist/stonecrop.d.ts
CHANGED
|
@@ -1289,6 +1289,22 @@ export declare interface OperationLogSnapshot {
|
|
|
1289
1289
|
*/
|
|
1290
1290
|
export declare type OperationSource = 'user' | 'system' | 'sync' | 'undo' | 'redo';
|
|
1291
1291
|
|
|
1292
|
+
/**
|
|
1293
|
+
* Pagination metadata from the last {@link Stonecrop.getRecords} for a doctype.
|
|
1294
|
+
* Kept beside HST, not in it — see {@link Stonecrop.getPageInfo}.
|
|
1295
|
+
* @public
|
|
1296
|
+
*/
|
|
1297
|
+
export declare interface PageInfo {
|
|
1298
|
+
/** Whether the backend holds further records beyond what has been fetched */
|
|
1299
|
+
hasMore: boolean;
|
|
1300
|
+
/** Total matching the filters when the caller passed includeTotal */
|
|
1301
|
+
count?: number;
|
|
1302
|
+
/** Offset of the last fetch */
|
|
1303
|
+
offset: number;
|
|
1304
|
+
/** Number of rows in the last page (result.data.length) */
|
|
1305
|
+
limit: number;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1292
1308
|
/**
|
|
1293
1309
|
* Pattern matching result for wildcard paths
|
|
1294
1310
|
* @internal
|
|
@@ -1961,6 +1977,8 @@ export declare class Stonecrop {
|
|
|
1961
1977
|
* nothing on this side of the wire knows what is safe for an arbitrary backend. A caller that
|
|
1962
1978
|
* passes none gets whatever the server considers a reasonable page.
|
|
1963
1979
|
*
|
|
1980
|
+
* `options.offset === 0` (or omitted) replaces the doctype's HST records; `offset > 0` appends.
|
|
1981
|
+
*
|
|
1964
1982
|
* @param doctype - The doctype
|
|
1965
1983
|
* @param options - Query options (filters, orderBy, limit, offset), forwarded to the client
|
|
1966
1984
|
* @throws Error if no data client has been configured
|
|
@@ -1978,10 +1996,7 @@ export declare class Stonecrop {
|
|
|
1978
1996
|
* @returns Page info, or undefined if this doctype's records have not been fetched
|
|
1979
1997
|
* @public
|
|
1980
1998
|
*/
|
|
1981
|
-
getPageInfo(doctype: string | Doctype):
|
|
1982
|
-
hasMore: boolean;
|
|
1983
|
-
count?: number;
|
|
1984
|
-
} | undefined;
|
|
1999
|
+
getPageInfo(doctype: string | Doctype): PageInfo | undefined;
|
|
1985
2000
|
/**
|
|
1986
2001
|
* Fetch a single record from the server and store it in HST.
|
|
1987
2002
|
*
|
package/dist/stonecrop.js
CHANGED
|
@@ -1174,6 +1174,8 @@ class M {
|
|
|
1174
1174
|
* nothing on this side of the wire knows what is safe for an arbitrary backend. A caller that
|
|
1175
1175
|
* passes none gets whatever the server considers a reasonable page.
|
|
1176
1176
|
*
|
|
1177
|
+
* `options.offset === 0` (or omitted) replaces the doctype's HST records; `offset > 0` appends.
|
|
1178
|
+
*
|
|
1177
1179
|
* @param doctype - The doctype
|
|
1178
1180
|
* @param options - Query options (filters, orderBy, limit, offset), forwarded to the client
|
|
1179
1181
|
* @throws Error if no data client has been configured
|
|
@@ -1184,10 +1186,14 @@ class M {
|
|
|
1184
1186
|
throw new Error(
|
|
1185
1187
|
"No data client configured. Call setClient() with a DataClient implementation (e.g., StonecropClient from @stonecrop/graphql-client) before fetching records."
|
|
1186
1188
|
);
|
|
1187
|
-
const r = await this._client.getRecords(e, t), i = r.data
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1189
|
+
const r = await this._client.getRecords(e, t), i = r.data, n = t?.offset ?? 0, o = {
|
|
1190
|
+
hasMore: r.hasMore,
|
|
1191
|
+
offset: n,
|
|
1192
|
+
limit: i.length
|
|
1193
|
+
};
|
|
1194
|
+
return r.count != null && (o.count = r.count), this.pageInfo[e.slug] = o, n === 0 && this.clearRecords(e), i.forEach((a) => {
|
|
1195
|
+
const c = e.getRecordId(a);
|
|
1196
|
+
c !== void 0 && this.addRecord(e, c, a);
|
|
1191
1197
|
}), r;
|
|
1192
1198
|
}
|
|
1193
1199
|
/**
|