@stonecrop/stonecrop 0.39.0 → 0.40.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/stonecrop.d.ts +122 -4
- package/dist/stonecrop.js +381 -36
- package/dist/stonecrop.js.map +1 -1
- package/package.json +4 -4
package/dist/stonecrop.d.ts
CHANGED
|
@@ -158,6 +158,37 @@ export declare interface BatchOperation {
|
|
|
158
158
|
*/
|
|
159
159
|
export declare type ClientHandlerApi = Record<string, unknown>;
|
|
160
160
|
|
|
161
|
+
/**
|
|
162
|
+
* Build a new record, once, from every starting value: the schema's empty values, the doctype's `defaults`, then
|
|
163
|
+
* the source the app registered for it. Layers apply in that order, so the registered source wins however long
|
|
164
|
+
* the doctype's took.
|
|
165
|
+
*
|
|
166
|
+
* Nothing is returned until every value is in, so nothing is written to the record after a user can see it.
|
|
167
|
+
* A value that throws, rejects, or has not arrived within `timeoutMs` (default {@link DEFAULTS_TIMEOUT_MS}) is
|
|
168
|
+
* skipped and reported with `console.warn`; the record still opens with everything else.
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
export declare function composeNewRecord(registry: Registry, doctype: Doctype, options?: ComposeNewRecordOptions): Promise<ComposeNewRecordResult>;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Options for composing a new record.
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
export declare type ComposeNewRecordOptions = {
|
|
178
|
+
/** The moment `"now"` resolves to. Defaults to the time of the call. */
|
|
179
|
+
now?: Date;
|
|
180
|
+
/** How long to wait for starting values that have not arrived, in milliseconds. */
|
|
181
|
+
timeoutMs?: number;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* A composed new record, complete: every starting value that arrived in time is in it.
|
|
186
|
+
* @public
|
|
187
|
+
*/
|
|
188
|
+
export declare type ComposeNewRecordResult = {
|
|
189
|
+
record: Record<string, unknown>;
|
|
190
|
+
};
|
|
191
|
+
|
|
161
192
|
/**
|
|
162
193
|
* Factory function for HST creation
|
|
163
194
|
* Creates a new HSTNode proxy for hierarchical state tree navigation.
|
|
@@ -202,6 +233,51 @@ export declare interface CrossTabMessage {
|
|
|
202
233
|
*/
|
|
203
234
|
export declare type CrossTabMessageType = 'operation' | 'undo' | 'redo' | 'sync-request' | 'sync-response';
|
|
204
235
|
|
|
236
|
+
/**
|
|
237
|
+
* How long a new record waits for a starting value that has not arrived. A value still missing by then is
|
|
238
|
+
* skipped and reported, and the record opens without it.
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
export declare const DEFAULTS_TIMEOUT_MS = 5000;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Context passed to defaults functions at document or field level.
|
|
245
|
+
* @public
|
|
246
|
+
*/
|
|
247
|
+
export declare type DefaultsContext = {
|
|
248
|
+
doctype: Doctype;
|
|
249
|
+
record: Record<string, unknown>;
|
|
250
|
+
fieldname?: string;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* A fixed starting value, as a doctype file can hold it: plain data, nested like the record.
|
|
255
|
+
* @public
|
|
256
|
+
*/
|
|
257
|
+
export declare type DefaultsData = string | number | boolean | null | DefaultsData[] | {
|
|
258
|
+
[field: string]: DefaultsData;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Nested object in the same shape as a composed record (HST / formData).
|
|
263
|
+
* @public
|
|
264
|
+
*/
|
|
265
|
+
export declare type DefaultsDocument = {
|
|
266
|
+
[field: string]: DefaultsValue;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Static document or a function that returns one (sync blocks, promise loads).
|
|
271
|
+
* @public
|
|
272
|
+
*/
|
|
273
|
+
export declare type DefaultsSource = DefaultsDocument | ((ctx: DefaultsContext) => DefaultsDocument | Promise<DefaultsDocument>);
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* A value inside a registered defaults document.
|
|
277
|
+
* @public
|
|
278
|
+
*/
|
|
279
|
+
export declare type DefaultsValue = string | number | boolean | null | DefaultsDocument | DefaultsValue[] | ((ctx: DefaultsContext) => DefaultsValue | Promise<DefaultsValue>);
|
|
280
|
+
|
|
205
281
|
/**
|
|
206
282
|
* Doctype runtime class with Immutable.js collections for HST change tracking.
|
|
207
283
|
* @public
|
|
@@ -249,6 +325,12 @@ export declare class Doctype {
|
|
|
249
325
|
* @readonly
|
|
250
326
|
*/
|
|
251
327
|
readonly displayField?: string;
|
|
328
|
+
/**
|
|
329
|
+
* Starting values for new records: fixed data in the shape of the record.
|
|
330
|
+
* @public
|
|
331
|
+
* @readonly
|
|
332
|
+
*/
|
|
333
|
+
readonly defaults?: DoctypeDefaults;
|
|
252
334
|
/**
|
|
253
335
|
* Creates a new Doctype instance
|
|
254
336
|
* @param doctype - The doctype name
|
|
@@ -258,7 +340,7 @@ export declare class Doctype {
|
|
|
258
340
|
* @param links - Optional relationship links to other doctypes
|
|
259
341
|
* @param displayField - Optional field used when displaying references to this doctype
|
|
260
342
|
*/
|
|
261
|
-
constructor(doctype: string, schema: ImmutableDoctype['schema'], workflow: ImmutableDoctype['workflow'], component?: Component, links?: Record<string, LinkDeclaration>, displayField?: string);
|
|
343
|
+
constructor(doctype: string, schema: ImmutableDoctype['schema'], workflow: ImmutableDoctype['workflow'], component?: Component, links?: Record<string, LinkDeclaration>, displayField?: string, defaults?: DoctypeDefaults);
|
|
262
344
|
/**
|
|
263
345
|
* Creates a Doctype instance from a plain configuration object.
|
|
264
346
|
* Handles conversion of arrays to Immutable.js collections internally.
|
|
@@ -462,6 +544,17 @@ export declare type DoctypeConfig = {
|
|
|
462
544
|
workflow?: UnknownMachineConfig | WorkflowMeta;
|
|
463
545
|
/** Ancestor doctype for inheritance */
|
|
464
546
|
inherits?: string;
|
|
547
|
+
/** Starting values for new records: fixed data in the shape of the record */
|
|
548
|
+
defaults?: DoctypeDefaults;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* A doctype's own starting values for a new record: fixed data in the shape of the record. Anything worked out when
|
|
553
|
+
* a record is made (today's date, a value looked up for the user's company) is registered on the registry instead.
|
|
554
|
+
* @public
|
|
555
|
+
*/
|
|
556
|
+
export declare type DoctypeDefaults = {
|
|
557
|
+
[field: string]: DefaultsData;
|
|
465
558
|
};
|
|
466
559
|
|
|
467
560
|
/**
|
|
@@ -979,7 +1072,7 @@ export declare type HSTStonecropReturn = BaseStonecropReturn & {
|
|
|
979
1072
|
* @param path - The HST path where initialized data should be stored
|
|
980
1073
|
* @param doctype - The doctype to initialize
|
|
981
1074
|
*/
|
|
982
|
-
initializeNestedData: (path: string, doctype: Doctype) => void
|
|
1075
|
+
initializeNestedData: (path: string, doctype: Doctype) => Promise<void>;
|
|
983
1076
|
/**
|
|
984
1077
|
* Fetch a record and its nested data from the server.
|
|
985
1078
|
* Stores each field at its own HST path per the field-level convention.
|
|
@@ -1397,6 +1490,11 @@ export declare class Registry {
|
|
|
1397
1490
|
* @internal
|
|
1398
1491
|
*/
|
|
1399
1492
|
private _ancestorIndexDirty;
|
|
1493
|
+
/**
|
|
1494
|
+
* The app's starting values for each doctype, by slug: one registration per doctype (functions allowed).
|
|
1495
|
+
* @internal
|
|
1496
|
+
*/
|
|
1497
|
+
private registeredDefaults;
|
|
1400
1498
|
/**
|
|
1401
1499
|
* The Vue router instance
|
|
1402
1500
|
* @see {@link https://router.vuejs.org/}
|
|
@@ -1459,7 +1557,7 @@ export declare class Registry {
|
|
|
1459
1557
|
*
|
|
1460
1558
|
* - `kind: 'table'` or `kind: 'link'` → `[]` or `{}`
|
|
1461
1559
|
* - `kind: 'fieldset'` → its children, at the top level of the record: a fieldset is layout
|
|
1462
|
-
* - `kind: 'field'` →
|
|
1560
|
+
* - `kind: 'field'` → an empty value for the component's category; falls back to `null`
|
|
1463
1561
|
*
|
|
1464
1562
|
* @param schema - The resolved schema array to derive defaults from
|
|
1465
1563
|
* @returns A plain object with default values for each field
|
|
@@ -1513,6 +1611,26 @@ export declare class Registry {
|
|
|
1513
1611
|
* @internal
|
|
1514
1612
|
*/
|
|
1515
1613
|
private _ensureAncestorIndex;
|
|
1614
|
+
/**
|
|
1615
|
+
* Register the app's starting values for a doctype, by its name or its slug (typically from app bootstrap).
|
|
1616
|
+
* Either one is keyed the way {@link Doctype.slug} is, so `'OrderItem'` and `'order-item'` register for the
|
|
1617
|
+
* same doctype, whether or not it has been added yet.
|
|
1618
|
+
*
|
|
1619
|
+
* They apply over the doctype's own `defaults` for every new record, and a function here runs for each one, so
|
|
1620
|
+
* it can work out what a doctype file cannot (today's date, a value looked up for the user's company). A doctype
|
|
1621
|
+
* takes one registration: a second replaces the first, with a warning.
|
|
1622
|
+
* @public
|
|
1623
|
+
*/
|
|
1624
|
+
registerDefaults(doctype: string, source: DefaultsSource): void;
|
|
1625
|
+
/**
|
|
1626
|
+
* @internal
|
|
1627
|
+
*/
|
|
1628
|
+
getRegisteredDefaults(slug: string): DefaultsSource | undefined;
|
|
1629
|
+
/**
|
|
1630
|
+
* Compose a new record, once, from every starting value. See {@link composeNewRecord}.
|
|
1631
|
+
* @public
|
|
1632
|
+
*/
|
|
1633
|
+
composeNewRecord(doctype: Doctype, options?: ComposeNewRecordOptions): Promise<ComposeNewRecordResult>;
|
|
1516
1634
|
}
|
|
1517
1635
|
|
|
1518
1636
|
/**
|
|
@@ -2084,7 +2202,7 @@ export declare class Stonecrop {
|
|
|
2084
2202
|
* @param doctype - The doctype to initialize
|
|
2085
2203
|
* @public
|
|
2086
2204
|
*/
|
|
2087
|
-
initializeNestedData(path: string, doctype: Doctype): void
|
|
2205
|
+
initializeNestedData(path: string, doctype: Doctype): Promise<void>;
|
|
2088
2206
|
/**
|
|
2089
2207
|
* Fetch a record and its nested data from the server.
|
|
2090
2208
|
*
|