sg-widgets-core 0.1.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/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/client-BhHppzTV.d.mts +740 -0
- package/dist/client-DwN_-UuF.mjs +1015 -0
- package/dist/index.d.mts +2726 -0
- package/dist/index.mjs +7932 -0
- package/dist/mock.d.mts +167 -0
- package/dist/mock.mjs +3113 -0
- package/package.json +61 -0
package/dist/mock.d.mts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { D as UploadFile, E as ThreadRow, Et as TextSearchFilter, O as UploadResult, R as StatusRecord, _ as SgClient, a as EventLogOptions, bt as EntityRef, c as HierarchyNode, ct as FieldSchema, h as SearchResult, l as HierarchyPath, m as SearchOptions, n as EntityRow, o as EventLogResult, r as EntityTypeInfo, s as FollowingOptions, v as SummarizeOptions, w as TextSearchRow, y as SummarizeResult } from "./client-BhHppzTV.mjs";
|
|
2
|
+
//#region src/mock.d.ts
|
|
3
|
+
/** What the next call should throw instead of answering. */
|
|
4
|
+
export interface MockFailure {
|
|
5
|
+
/** HTTP status. Default 500. */
|
|
6
|
+
status?: number;
|
|
7
|
+
/** `errors[0].title`, which is what `RestClient` puts in `SgApiError.message`. */
|
|
8
|
+
message?: string;
|
|
9
|
+
/** Parsed response body, for code that inspects `SgApiError.body`. */
|
|
10
|
+
body?: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface MockClientOptions {
|
|
13
|
+
/** Fixture seed. The same seed always produces the same site. Default 1. */
|
|
14
|
+
seed?: number;
|
|
15
|
+
/** Simulated round trip, in milliseconds, applied to every call. Default 0. */
|
|
16
|
+
latencyMs?: number;
|
|
17
|
+
/** Arm a failure for the very first call, for demoing an error state without extra wiring. */
|
|
18
|
+
failNext?: MockFailure | null;
|
|
19
|
+
/** How many rows of the scaled types to generate. Default 60 Versions. */
|
|
20
|
+
counts?: {
|
|
21
|
+
versions?: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* What `in_last`, `in_next` and `in_calendar_*` resolve against: an ISO string,
|
|
25
|
+
* epoch milliseconds, or a function read on every call. Default: the current time.
|
|
26
|
+
* Fixture dates are offsets from `MOCK_NOW`, so pin it there to filter them.
|
|
27
|
+
*/
|
|
28
|
+
now?: string | number | (() => number);
|
|
29
|
+
}
|
|
30
|
+
/** Midday on the mock site's today, for a caller pinning `now` so relative-date filters land on the fixtures. */
|
|
31
|
+
export declare const MOCK_NOW: string;
|
|
32
|
+
export declare class MockClient implements SgClient {
|
|
33
|
+
private readonly fixtures;
|
|
34
|
+
private readonly latencyMs;
|
|
35
|
+
private readonly clock;
|
|
36
|
+
private pendingFailure;
|
|
37
|
+
constructor(options?: MockClientOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Make the next call reject with an `SgApiError`, for demoing an error state.
|
|
40
|
+
* Pass `null` to disarm one that was already set.
|
|
41
|
+
*/
|
|
42
|
+
failNext(failure?: MockFailure | null): void;
|
|
43
|
+
/** Rows of a type, in id order. Handy for writing assertions against the fixtures. */
|
|
44
|
+
rowsOf(entityType: string): ReadonlyArray<Readonly<Record<string, unknown>>>;
|
|
45
|
+
private gate;
|
|
46
|
+
private schemaOf;
|
|
47
|
+
entityTypes(): Promise<EntityTypeInfo[]>;
|
|
48
|
+
fields(entityType: string, projectId?: number): Promise<Record<string, FieldSchema>>;
|
|
49
|
+
fieldWithProject(entityType: string, field: string, projectId: number): Promise<FieldSchema>;
|
|
50
|
+
search(entityType: string, options: SearchOptions): Promise<SearchResult>;
|
|
51
|
+
textSearch(text: string, entityTypes: Record<string, TextSearchFilter>, page?: {
|
|
52
|
+
size?: number;
|
|
53
|
+
number?: number;
|
|
54
|
+
}): Promise<TextSearchRow[]>;
|
|
55
|
+
update(entityType: string, id: number, patch: Record<string, unknown>): Promise<EntityRow>;
|
|
56
|
+
/**
|
|
57
|
+
* Counts without paging rows.
|
|
58
|
+
*
|
|
59
|
+
* `count` and the numeric aggregates are modelled; the rest of the vocabulary the
|
|
60
|
+
* endpoint prints is not. A grouping returns one group per distinct value with the
|
|
61
|
+
* empties under a `''` group, `group_value` is what the grouping was computed on and
|
|
62
|
+
* `group_name` the server's render of it, and one type per field per call wins
|
|
63
|
+
* (020_summarize).
|
|
64
|
+
*/
|
|
65
|
+
summarize(entityType: string, options?: SummarizeOptions): Promise<SummarizeResult>;
|
|
66
|
+
/** An entity group's value is the reference with its name and `valid` (020_summarize); a code is itself. */
|
|
67
|
+
private groupValueOf;
|
|
68
|
+
/**
|
|
69
|
+
* A field the server cannot group is 400 `Grouping is not allowed for field
|
|
70
|
+
* <Type>.<field>.` on `image` and `summary` (field_types/image, field_types/summary),
|
|
71
|
+
* and a `pivot_column` is 500 (field_types/pivot_column). `Note.read_by_current_user`,
|
|
72
|
+
* the per-person read state, is refused the same way; the corpus has not measured it.
|
|
73
|
+
*/
|
|
74
|
+
private refuseGrouping;
|
|
75
|
+
/**
|
|
76
|
+
* One level of the navigation tree.
|
|
77
|
+
*
|
|
78
|
+
* The shape is post_hierarchy_expand's: a node with `label`, `ref`, `path` and one
|
|
79
|
+
* level of `children`. Which levels a project has is the site's own navigation
|
|
80
|
+
* configuration and not a fixed hierarchy - the probed site's Shot path runs through
|
|
81
|
+
* the field name `sg_sequence` (post_hierarchy_search) - so this fixture offers the
|
|
82
|
+
* two branches that configuration draws for a stock project: Shots under their
|
|
83
|
+
* Sequence, and Assets flat.
|
|
84
|
+
*/
|
|
85
|
+
hierarchyExpand(path: string): Promise<HierarchyNode>;
|
|
86
|
+
/**
|
|
87
|
+
* Where a row sits in the tree. The endpoint takes an entity and answers its
|
|
88
|
+
* breadcrumb; it does not match words (post_hierarchy_search).
|
|
89
|
+
*/
|
|
90
|
+
hierarchySearch(rootPath: string, entity: EntityRef): Promise<HierarchyPath[]>;
|
|
91
|
+
/** What a level of the tree is called, without opening it. */
|
|
92
|
+
private labelAtPath;
|
|
93
|
+
/** The row a `.../id/<n>` path segment names, from the type the path last named. */
|
|
94
|
+
private rowAtPath;
|
|
95
|
+
/** The breadcrumb to a row, root first, the row itself last. Empty when it is not in the tree. */
|
|
96
|
+
private pathTo;
|
|
97
|
+
statuses(): Promise<StatusRecord[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Create one row and answer it.
|
|
100
|
+
*
|
|
101
|
+
* `project` is the whole contract on a project-scoped type, and the schema's
|
|
102
|
+
* `mandatory` flags are not it: the identity field is optional and the server
|
|
103
|
+
* fills it, except on a Note, which stays titleless (012_create_version,
|
|
104
|
+
* entity_types/Note). Nothing is unique, so two identical creates make two rows.
|
|
105
|
+
*/
|
|
106
|
+
create(entityType: string, body: Record<string, unknown>): Promise<EntityRow>;
|
|
107
|
+
/**
|
|
108
|
+
* Put a file on a row, as the three-call handshake leaves the site.
|
|
109
|
+
*
|
|
110
|
+
* The field in the path picks the kind: `image` a Thumbnail, another field an
|
|
111
|
+
* Attachment on it, no field a generic Attachment on `attachment_links`
|
|
112
|
+
* (recipes/001). The mock moves no bytes, so there is no `ETag` to give back.
|
|
113
|
+
*/
|
|
114
|
+
upload(entityType: string, id: number, file: UploadFile): Promise<UploadResult>;
|
|
115
|
+
/**
|
|
116
|
+
* An entity link is a `{type, id}` hash. A bare id is refused naming the class it
|
|
117
|
+
* got (entity_types/Reply, field_types/entity) and a hash with no `type` naming the
|
|
118
|
+
* missing key (field_types/entity).
|
|
119
|
+
*/
|
|
120
|
+
private checkLink;
|
|
121
|
+
/** The next free id of a type, which is what a create takes. */
|
|
122
|
+
private nextId;
|
|
123
|
+
/** The reverse view of a link the server fills in: a Reply lands in `Note.replies`. */
|
|
124
|
+
private linkBack;
|
|
125
|
+
/**
|
|
126
|
+
* A Note, its Attachments and its Replies in one list in time order.
|
|
127
|
+
*
|
|
128
|
+
* The author key follows the row type, `created_by` on a Note and an Attachment
|
|
129
|
+
* and `user` on a Reply, whose hash carries an avatar the other two do not, and
|
|
130
|
+
* so does what `entityFields` can widen: the Reply entry is accepted and changes
|
|
131
|
+
* nothing (get_entity_notes_id_thread_contents).
|
|
132
|
+
*/
|
|
133
|
+
threadContents(noteId: number, entityFields?: Record<string, string[]>): Promise<ThreadRow[]>;
|
|
134
|
+
/** One thread row, in the flat shape the endpoint answers. */
|
|
135
|
+
private threadRow;
|
|
136
|
+
/** `{id, name, type}`, plus a presigned `image` when the row is a Reply. */
|
|
137
|
+
private threadAuthor;
|
|
138
|
+
/**
|
|
139
|
+
* What changed, newest first. `meta` is read off the row because it takes no
|
|
140
|
+
* filter and no sort, and the cut is made on `project`, `entity`, `event_type`,
|
|
141
|
+
* `attribute_name` and `created_at` (025_event_log).
|
|
142
|
+
*/
|
|
143
|
+
eventLog(options?: EventLogOptions): Promise<EventLogResult>;
|
|
144
|
+
/**
|
|
145
|
+
* Everything one person follows, unpaged. `entity` takes the schema name or the
|
|
146
|
+
* snake_case plural, and both cuts are made server-side
|
|
147
|
+
* (get_entity_human_users_id_following).
|
|
148
|
+
*/
|
|
149
|
+
following(userId: number, options?: FollowingOptions): Promise<EntityRef[]>;
|
|
150
|
+
private displayNameOfRef;
|
|
151
|
+
private decorate;
|
|
152
|
+
private project;
|
|
153
|
+
private resolveProjection;
|
|
154
|
+
/**
|
|
155
|
+
* Resolve a plain or dotted path to the values it reaches. `strict` makes an
|
|
156
|
+
* unknown field or an unknown middle type throw the 400 the API answers in a
|
|
157
|
+
* filter; the projection side wants a silent miss instead.
|
|
158
|
+
*/
|
|
159
|
+
private walk;
|
|
160
|
+
/** The data type a filter path lands on, for choosing the comparison and validating the operator. */
|
|
161
|
+
private dataTypeAt;
|
|
162
|
+
private linkedPair;
|
|
163
|
+
private matchGroup;
|
|
164
|
+
private matchCondition;
|
|
165
|
+
private applySort;
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|