@stonecrop/stonecrop 0.24.0 → 0.26.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/registry.d.ts +2 -1
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +4 -5
- 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 +21 -5
- package/dist/stonecrop.js +84 -76
- package/dist/stonecrop.js.map +1 -1
- package/package.json +4 -4
- package/src/registry.ts +5 -6
- package/src/stonecrop.ts +21 -4
- package/src/types/stonecrop.ts +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/stonecrop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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.
|
|
38
|
-
"@stonecrop/atable": "0.
|
|
39
|
-
"@stonecrop/schema": "0.
|
|
37
|
+
"@stonecrop/aform": "0.26.0",
|
|
38
|
+
"@stonecrop/atable": "0.26.0",
|
|
39
|
+
"@stonecrop/schema": "0.26.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@microsoft/api-documenter": "^7.30.5",
|
package/src/registry.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ResolvedField, ResolvedLink, ResolvedScalar, ResolvedTable, ResolvedFieldset } from '@stonecrop/aform'
|
|
2
|
-
import
|
|
2
|
+
import { resolvedFieldsToColumns } from '@stonecrop/aform'
|
|
3
|
+
import type { DoctypeField, LinkDeclaration, TableViewConfig, ValueField } from '@stonecrop/schema'
|
|
3
4
|
import { componentCategory, componentLinkExpansion, resolveLinkRenderMode } from '@stonecrop/schema'
|
|
4
5
|
import { Router } from 'vue-router'
|
|
5
6
|
|
|
@@ -249,14 +250,12 @@ export default class Registry {
|
|
|
249
250
|
|
|
250
251
|
/**
|
|
251
252
|
* Build a `ResolvedTable` from a resolved Link field with many cardinality.
|
|
252
|
-
*
|
|
253
|
+
* Columns come from {@link @stonecrop/aform#resolvedFieldsToColumns}, the shared definition of
|
|
254
|
+
* which resolved fields a cell can render.
|
|
253
255
|
* @internal
|
|
254
256
|
*/
|
|
255
257
|
private buildTableConfig(field: ValueField, childSchema: ResolvedField[], component?: string): ResolvedTable {
|
|
256
|
-
|
|
257
|
-
const columns: ColumnSchema[] = childSchema
|
|
258
|
-
.filter((f): f is ResolvedScalar => f.kind === 'field')
|
|
259
|
-
.map(({ kind: _k, ...col }) => col)
|
|
258
|
+
const columns = resolvedFieldsToColumns(childSchema)
|
|
260
259
|
|
|
261
260
|
const config: TableViewConfig = (field as ValueField & { config?: TableViewConfig }).config ?? { view: 'list' }
|
|
262
261
|
const { options: _opt, cardinality: _card, ...fieldRest } = field
|
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,
|
|
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
|
-
|
|
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):
|
|
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
|
}
|
package/src/types/stonecrop.ts
CHANGED
|
@@ -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.
|