@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/stonecrop",
3
- "version": "0.23.0",
3
+ "version": "0.25.0",
4
4
  "description": "Schema-driven framework with XState workflows and HST state management",
5
5
  "bugs": {
6
6
  "url": "https://github.com/agritheory/stonecrop/issues"
@@ -34,9 +34,9 @@
34
34
  "immutable": "^5.1.4",
35
35
  "pinia-shared-state": "^1.0.1",
36
36
  "xstate": "^5.25.0",
37
- "@stonecrop/aform": "0.23.0",
38
- "@stonecrop/schema": "0.23.0",
39
- "@stonecrop/atable": "0.23.0"
37
+ "@stonecrop/aform": "0.25.0",
38
+ "@stonecrop/atable": "0.25.0",
39
+ "@stonecrop/schema": "0.25.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@microsoft/api-documenter": "^7.30.5",
package/src/stonecrop.ts CHANGED
@@ -8,7 +8,7 @@ import { createHST, type HSTNode } from './stores/hst'
8
8
  import { useOperationLogStore } from './stores/operation-log'
9
9
  import type { OperationLogConfig } from './types/operation-log'
10
10
  import type { RouteContext } from './types/registry'
11
- import type { StonecropOptions } from './types/stonecrop'
11
+ import type { PageInfo, StonecropOptions } from './types/stonecrop'
12
12
 
13
13
  /**
14
14
  * Main Stonecrop class with HST integration and built-in Operation Log
@@ -33,7 +33,7 @@ export class Stonecrop {
33
33
  * Per-doctype page info from the last list read, keyed by slug. Reactive so views tracking
34
34
  * it update on fetch. Deliberately not in HST — see {@link Stonecrop.getRecords}.
35
35
  */
36
- private pageInfo: Record<string, { hasMore: boolean; count?: number }> = reactive({})
36
+ private pageInfo: Record<string, PageInfo> = reactive({})
37
37
 
38
38
  /** The registry instance containing all doctype definitions */
39
39
  readonly registry!: Registry
@@ -305,6 +305,8 @@ export class Stonecrop {
305
305
  * nothing on this side of the wire knows what is safe for an arbitrary backend. A caller that
306
306
  * passes none gets whatever the server considers a reasonable page.
307
307
  *
308
+ * `options.offset === 0` (or omitted) replaces the doctype's HST records; `offset > 0` appends.
309
+ *
308
310
  * @param doctype - The doctype
309
311
  * @param options - Query options (filters, orderBy, limit, offset), forwarded to the client
310
312
  * @throws Error if no data client has been configured
@@ -320,11 +322,26 @@ export class Stonecrop {
320
322
 
321
323
  const result = await this._client.getRecords(doctype, options)
322
324
  const records = result.data
325
+ const offset = options?.offset ?? 0
323
326
 
324
327
  // Page info is kept beside HST, not in it. `getRecordIds` reads the raw keys under a
325
328
  // doctype node, so anything filed there becomes a phantom record — the same hazard that
326
329
  // ruled out seeding a draft node.
327
- this.pageInfo[doctype.slug] = { hasMore: result.hasMore, count: result.count }
330
+ const pageEntry: PageInfo = {
331
+ hasMore: result.hasMore,
332
+ offset,
333
+ limit: records.length,
334
+ }
335
+ if (result.count != null) {
336
+ pageEntry.count = result.count
337
+ }
338
+ this.pageInfo[doctype.slug] = pageEntry
339
+
340
+ // offset === 0 replaces the doctype's HST records; offset > 0 appends. A failed fetch
341
+ // must not clear — that happens only after a successful response lands above.
342
+ if (offset === 0) {
343
+ this.clearRecords(doctype)
344
+ }
328
345
 
329
346
  // Key each record by its declared primary key, falling back to `id`. This used to read
330
347
  // `record.id` only, which silently dropped every row of a natural-keyed doctype (no `id`
@@ -351,7 +368,7 @@ export class Stonecrop {
351
368
  * @returns Page info, or undefined if this doctype's records have not been fetched
352
369
  * @public
353
370
  */
354
- getPageInfo(doctype: string | Doctype): { hasMore: boolean; count?: number } | undefined {
371
+ getPageInfo(doctype: string | Doctype): PageInfo | undefined {
355
372
  const slug = typeof doctype === 'string' ? doctype : doctype.slug
356
373
  return this.pageInfo[slug]
357
374
  }
@@ -1,5 +1,21 @@
1
1
  import type { DataClient } from '@stonecrop/schema'
2
2
 
3
+ /**
4
+ * Pagination metadata from the last {@link Stonecrop.getRecords} for a doctype.
5
+ * Kept beside HST, not in it — see {@link Stonecrop.getPageInfo}.
6
+ * @public
7
+ */
8
+ export interface PageInfo {
9
+ /** Whether the backend holds further records beyond what has been fetched */
10
+ hasMore: boolean
11
+ /** Total matching the filters when the caller passed includeTotal */
12
+ count?: number
13
+ /** Offset of the last fetch */
14
+ offset: number
15
+ /** Number of rows in the last page (result.data.length) */
16
+ limit: number
17
+ }
18
+
3
19
  /**
4
20
  * Options for constructing a Stonecrop instance directly.
5
21
  * When using the Vue plugin, pass these via `InstallOptions` instead.