@framesquared/data 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/dist/Operation-4K76GXM7.js +7 -0
- package/dist/Operation-4K76GXM7.js.map +1 -0
- package/dist/chunk-CJJTXTV2.js +30 -0
- package/dist/chunk-CJJTXTV2.js.map +1 -0
- package/dist/index.d.ts +1028 -0
- package/dist/index.js +2931 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1028 @@
|
|
|
1
|
+
import { Base } from '@framesquared/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @framesquared/data – Field system
|
|
5
|
+
*
|
|
6
|
+
* Defines field types with type coercion, serialization, and defaults.
|
|
7
|
+
*/
|
|
8
|
+
declare enum FieldType {
|
|
9
|
+
STRING = "string",
|
|
10
|
+
INT = "int",
|
|
11
|
+
FLOAT = "float",
|
|
12
|
+
BOOLEAN = "boolean",
|
|
13
|
+
DATE = "date",
|
|
14
|
+
AUTO = "auto"
|
|
15
|
+
}
|
|
16
|
+
type Validator = (value: unknown, record?: any) => string | null;
|
|
17
|
+
interface FieldDefinition {
|
|
18
|
+
name: string;
|
|
19
|
+
type?: FieldType;
|
|
20
|
+
defaultValue?: unknown;
|
|
21
|
+
convert?: (value: unknown, record?: any) => unknown;
|
|
22
|
+
serialize?: (value: unknown, record?: any) => unknown;
|
|
23
|
+
mapping?: string;
|
|
24
|
+
persist?: boolean;
|
|
25
|
+
critical?: boolean;
|
|
26
|
+
allowNull?: boolean;
|
|
27
|
+
sortType?: string;
|
|
28
|
+
validators?: Validator[];
|
|
29
|
+
}
|
|
30
|
+
declare abstract class Field {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly type: FieldType;
|
|
33
|
+
readonly mapping: string | undefined;
|
|
34
|
+
readonly persist: boolean;
|
|
35
|
+
readonly critical: boolean;
|
|
36
|
+
readonly allowNull: boolean;
|
|
37
|
+
readonly sortType: string | undefined;
|
|
38
|
+
readonly validators: Validator[];
|
|
39
|
+
private readonly customConvert?;
|
|
40
|
+
private readonly customSerialize?;
|
|
41
|
+
private readonly customDefault;
|
|
42
|
+
constructor(def: FieldDefinition);
|
|
43
|
+
/** Type-specific default (overridden by subclasses). */
|
|
44
|
+
get defaultValue(): unknown;
|
|
45
|
+
/** Subclass provides the type-specific default. */
|
|
46
|
+
protected abstract getTypeDefault(): unknown;
|
|
47
|
+
/**
|
|
48
|
+
* Converts a raw value to the field's type.
|
|
49
|
+
* If a custom `convert` was specified in the definition, it is used.
|
|
50
|
+
* Otherwise delegates to the subclass's `coerce()`.
|
|
51
|
+
*/
|
|
52
|
+
convert(value: unknown, record?: any): unknown;
|
|
53
|
+
/** Type-specific coercion (subclasses override). */
|
|
54
|
+
protected abstract coerce(value: unknown): unknown;
|
|
55
|
+
/**
|
|
56
|
+
* Serializes a value for transport.
|
|
57
|
+
*/
|
|
58
|
+
serialize(value: unknown, record?: any): unknown;
|
|
59
|
+
}
|
|
60
|
+
declare class StringField extends Field {
|
|
61
|
+
constructor(def: Omit<FieldDefinition, 'type'> & {
|
|
62
|
+
type?: FieldType;
|
|
63
|
+
});
|
|
64
|
+
protected getTypeDefault(): unknown;
|
|
65
|
+
protected coerce(value: unknown): unknown;
|
|
66
|
+
}
|
|
67
|
+
declare class IntField extends Field {
|
|
68
|
+
constructor(def: Omit<FieldDefinition, 'type'> & {
|
|
69
|
+
type?: FieldType;
|
|
70
|
+
});
|
|
71
|
+
protected getTypeDefault(): unknown;
|
|
72
|
+
protected coerce(value: unknown): unknown;
|
|
73
|
+
}
|
|
74
|
+
declare class FloatField extends Field {
|
|
75
|
+
constructor(def: Omit<FieldDefinition, 'type'> & {
|
|
76
|
+
type?: FieldType;
|
|
77
|
+
});
|
|
78
|
+
protected getTypeDefault(): unknown;
|
|
79
|
+
protected coerce(value: unknown): unknown;
|
|
80
|
+
}
|
|
81
|
+
declare class BooleanField extends Field {
|
|
82
|
+
constructor(def: Omit<FieldDefinition, 'type'> & {
|
|
83
|
+
type?: FieldType;
|
|
84
|
+
});
|
|
85
|
+
protected getTypeDefault(): unknown;
|
|
86
|
+
protected coerce(value: unknown): unknown;
|
|
87
|
+
}
|
|
88
|
+
declare class DateField extends Field {
|
|
89
|
+
constructor(def: Omit<FieldDefinition, 'type'> & {
|
|
90
|
+
type?: FieldType;
|
|
91
|
+
});
|
|
92
|
+
protected getTypeDefault(): unknown;
|
|
93
|
+
protected coerce(value: unknown): unknown;
|
|
94
|
+
serialize(value: unknown): unknown;
|
|
95
|
+
}
|
|
96
|
+
declare class AutoField extends Field {
|
|
97
|
+
constructor(def: Omit<FieldDefinition, 'type'> & {
|
|
98
|
+
type?: FieldType;
|
|
99
|
+
});
|
|
100
|
+
protected getTypeDefault(): unknown;
|
|
101
|
+
protected coerce(value: unknown): unknown;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates a Field instance from a definition or shorthand string.
|
|
105
|
+
*/
|
|
106
|
+
declare function createField(def: FieldDefinition | string): Field;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @framesquared/data – ModelCollection
|
|
110
|
+
*
|
|
111
|
+
* A lightweight collection of Model instances, used by HasMany and
|
|
112
|
+
* ManyToMany associations. Provides add/remove/filter/getById.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
declare class ModelCollection {
|
|
116
|
+
private items;
|
|
117
|
+
getCount(): number;
|
|
118
|
+
getAll(): Model[];
|
|
119
|
+
add(record: Model): void;
|
|
120
|
+
remove(record: Model): void;
|
|
121
|
+
getById(id: string | number): Model | undefined;
|
|
122
|
+
filter(fn: (record: Model) => boolean): Model[];
|
|
123
|
+
destroyAll(): void;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Extended collection for ManyToMany that exposes link/unlink semantics.
|
|
127
|
+
*/
|
|
128
|
+
declare class ManyToManyCollection extends ModelCollection {
|
|
129
|
+
private junctions;
|
|
130
|
+
link(record: Model, _junctionData?: Record<string, unknown>): void;
|
|
131
|
+
unlink(record: Model): void;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @framesquared/data – Model
|
|
136
|
+
*
|
|
137
|
+
* The foundation of the data layer. A Model represents a record with
|
|
138
|
+
* typed fields, dirty tracking, validation, and event notification.
|
|
139
|
+
*
|
|
140
|
+
* Instances are wrapped in a Proxy so `record.name` transparently
|
|
141
|
+
* delegates to `get('name')` / `set('name', value)` for field access.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
interface ValidationError {
|
|
145
|
+
field: string;
|
|
146
|
+
message: string;
|
|
147
|
+
}
|
|
148
|
+
interface ValidationResult {
|
|
149
|
+
valid: boolean;
|
|
150
|
+
errors: ValidationError[];
|
|
151
|
+
}
|
|
152
|
+
declare class Model extends Base {
|
|
153
|
+
static $className: string;
|
|
154
|
+
/** Field definitions — override in subclasses. */
|
|
155
|
+
static fields: (FieldDefinition | string)[];
|
|
156
|
+
/** Name of the ID field. */
|
|
157
|
+
static idProperty: string;
|
|
158
|
+
/** Resolved Field instances keyed by name. */
|
|
159
|
+
$fieldMap: Map<string, Field>;
|
|
160
|
+
/** Current field values. */
|
|
161
|
+
$data: Record<string, unknown>;
|
|
162
|
+
/** Previous values for dirty fields (fieldName → old value). */
|
|
163
|
+
modified: Record<string, unknown>;
|
|
164
|
+
/** Per-instance association storage: assocName → Model | ModelCollection */
|
|
165
|
+
$associations: Map<string, Model | ModelCollection | ManyToManyCollection>;
|
|
166
|
+
constructor(_data?: Record<string, unknown>);
|
|
167
|
+
/**
|
|
168
|
+
* Factory method that sets up fields, applies data, wraps in proxy.
|
|
169
|
+
*/
|
|
170
|
+
static create(this: typeof Model, data?: Record<string, unknown>): Model;
|
|
171
|
+
/** @internal Loads initial data without marking as dirty. */
|
|
172
|
+
$loadData(rawData: Record<string, unknown>): void;
|
|
173
|
+
get(fieldName: string): unknown;
|
|
174
|
+
set(fieldNameOrData: string | Record<string, unknown>, value?: unknown): string[];
|
|
175
|
+
getData(options?: {
|
|
176
|
+
serialize?: boolean;
|
|
177
|
+
}): Record<string, unknown>;
|
|
178
|
+
isModified(fieldName?: string): boolean;
|
|
179
|
+
getChanges(): Record<string, unknown>;
|
|
180
|
+
commit(silent?: boolean): void;
|
|
181
|
+
reject(silent?: boolean): void;
|
|
182
|
+
getId(): string | number;
|
|
183
|
+
setId(id: string | number): void;
|
|
184
|
+
get phantom(): boolean;
|
|
185
|
+
validate(): ValidationResult;
|
|
186
|
+
isValid(): boolean;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @framesquared/data – Built-in validators
|
|
191
|
+
*
|
|
192
|
+
* Each factory returns a Validator function: (value) => errorMsg | null
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Value must not be null, undefined, or empty string.
|
|
197
|
+
*/
|
|
198
|
+
declare function presence(message?: string): Validator;
|
|
199
|
+
/**
|
|
200
|
+
* String length must be within min/max bounds.
|
|
201
|
+
*/
|
|
202
|
+
declare function length(opts: {
|
|
203
|
+
min?: number;
|
|
204
|
+
max?: number;
|
|
205
|
+
message?: string;
|
|
206
|
+
}): Validator;
|
|
207
|
+
/**
|
|
208
|
+
* Value must match the given regex.
|
|
209
|
+
*/
|
|
210
|
+
declare function formatValidator(pattern: RegExp, message?: string): Validator;
|
|
211
|
+
/**
|
|
212
|
+
* Value must be in the allowed list.
|
|
213
|
+
*/
|
|
214
|
+
declare function inclusion(list: unknown[], message?: string): Validator;
|
|
215
|
+
/**
|
|
216
|
+
* Value must NOT be in the disallowed list.
|
|
217
|
+
*/
|
|
218
|
+
declare function exclusion(list: unknown[], message?: string): Validator;
|
|
219
|
+
/**
|
|
220
|
+
* Numeric value must be within min/max.
|
|
221
|
+
*/
|
|
222
|
+
declare function rangeValidator(opts: {
|
|
223
|
+
min?: number;
|
|
224
|
+
max?: number;
|
|
225
|
+
message?: string;
|
|
226
|
+
}): Validator;
|
|
227
|
+
declare function email(message?: string): Validator;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @framesquared/data – Association (base class)
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
interface AssociationConfig {
|
|
234
|
+
model: string | typeof Model;
|
|
235
|
+
foreignKey: string;
|
|
236
|
+
primaryKey?: string;
|
|
237
|
+
getterName?: string;
|
|
238
|
+
setterName?: string;
|
|
239
|
+
cascade?: boolean;
|
|
240
|
+
/** For ManyToMany: junction model name or class */
|
|
241
|
+
through?: string;
|
|
242
|
+
/** For ManyToMany: the other foreign key in the junction */
|
|
243
|
+
otherKey?: string;
|
|
244
|
+
}
|
|
245
|
+
type AssociationType = 'hasOne' | 'hasMany' | 'belongsTo' | 'manyToMany';
|
|
246
|
+
declare class Association {
|
|
247
|
+
readonly type: AssociationType;
|
|
248
|
+
readonly config: AssociationConfig;
|
|
249
|
+
readonly ownerModelName: string;
|
|
250
|
+
/** Resolved associated model class (may be null until forward ref resolves). */
|
|
251
|
+
associatedModel: typeof Model | null;
|
|
252
|
+
constructor(type: AssociationType, ownerModelName: string, config: AssociationConfig);
|
|
253
|
+
/**
|
|
254
|
+
* The property name used for nested JSON loading and as the
|
|
255
|
+
* default getter/collection accessor name.
|
|
256
|
+
*/
|
|
257
|
+
get associationName(): string;
|
|
258
|
+
get getterName(): string;
|
|
259
|
+
get setterName(): string;
|
|
260
|
+
get foreignKey(): string;
|
|
261
|
+
get primaryKey(): string;
|
|
262
|
+
get cascade(): boolean;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @framesquared/data – Schema
|
|
267
|
+
*
|
|
268
|
+
* Singleton registry for Model classes and their associations.
|
|
269
|
+
* Handles forward references: if Model A declares an association to
|
|
270
|
+
* Model B by string name before B is registered, the reference is
|
|
271
|
+
* resolved when B is later registered.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
declare class SchemaImpl {
|
|
275
|
+
/**
|
|
276
|
+
* Registers a Model class and processes its association declarations.
|
|
277
|
+
* If the model has `static hasOne`, `static hasMany`, `static belongsTo`,
|
|
278
|
+
* or `static manyToMany` arrays, creates Association instances for each.
|
|
279
|
+
*/
|
|
280
|
+
register(ModelClass: typeof Model): void;
|
|
281
|
+
/**
|
|
282
|
+
* Retrieves a registered Model class by name.
|
|
283
|
+
*/
|
|
284
|
+
get(name: string): typeof Model | undefined;
|
|
285
|
+
/**
|
|
286
|
+
* Returns all Association instances owned by the given model name.
|
|
287
|
+
*/
|
|
288
|
+
getAssociations(modelName: string): Association[];
|
|
289
|
+
/**
|
|
290
|
+
* Clears all registrations (for testing).
|
|
291
|
+
*/
|
|
292
|
+
clear(): void;
|
|
293
|
+
private processAssociations;
|
|
294
|
+
}
|
|
295
|
+
/** Singleton. */
|
|
296
|
+
declare const Schema: SchemaImpl;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* @framesquared/data – HasOne association
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
declare class HasOne extends Association {
|
|
303
|
+
constructor(ownerModelName: string, config: AssociationConfig);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* @framesquared/data – HasMany association
|
|
308
|
+
*/
|
|
309
|
+
|
|
310
|
+
declare class HasMany extends Association {
|
|
311
|
+
constructor(ownerModelName: string, config: AssociationConfig);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @framesquared/data – BelongsTo association
|
|
316
|
+
*/
|
|
317
|
+
|
|
318
|
+
declare class BelongsTo extends Association {
|
|
319
|
+
constructor(ownerModelName: string, config: AssociationConfig);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @framesquared/data – ManyToMany association
|
|
324
|
+
*/
|
|
325
|
+
|
|
326
|
+
declare class ManyToMany extends Association {
|
|
327
|
+
constructor(ownerModelName: string, config: AssociationConfig);
|
|
328
|
+
get through(): string;
|
|
329
|
+
get otherKey(): string;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @framesquared/data – Collection
|
|
334
|
+
*
|
|
335
|
+
* An ordered, optionally keyed collection used internally by Store.
|
|
336
|
+
* Provides add, insert, remove, sort, find, and iteration.
|
|
337
|
+
*/
|
|
338
|
+
declare class Collection<T> {
|
|
339
|
+
private items;
|
|
340
|
+
private keyMap;
|
|
341
|
+
private keyFn;
|
|
342
|
+
constructor(keyFn?: (item: T) => unknown);
|
|
343
|
+
getCount(): number;
|
|
344
|
+
getAt(index: number): T | undefined;
|
|
345
|
+
getByKey(key: unknown): T | undefined;
|
|
346
|
+
indexOf(item: T): number;
|
|
347
|
+
contains(item: T): boolean;
|
|
348
|
+
add(item: T): void;
|
|
349
|
+
insert(index: number, item: T): void;
|
|
350
|
+
remove(item: T): T | undefined;
|
|
351
|
+
removeAt(index: number, count?: number): T[];
|
|
352
|
+
clear(): void;
|
|
353
|
+
toArray(): T[];
|
|
354
|
+
each(fn: (item: T, index: number) => boolean | void): void;
|
|
355
|
+
find(fn: (item: T) => boolean): T | undefined;
|
|
356
|
+
filter(fn: (item: T) => boolean): T[];
|
|
357
|
+
sort(compareFn: (a: T, b: T) => number): void;
|
|
358
|
+
first(): T | undefined;
|
|
359
|
+
last(): T | undefined;
|
|
360
|
+
getRange(start?: number, end?: number): T[];
|
|
361
|
+
/** Rebuilds the key map (call after sort or external mutation). */
|
|
362
|
+
rekey(): void;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* @framesquared/data – Store
|
|
367
|
+
*
|
|
368
|
+
* A client-side collection of Model records with sorting, filtering,
|
|
369
|
+
* grouping, events, and sync/change tracking.
|
|
370
|
+
*/
|
|
371
|
+
|
|
372
|
+
interface Sorter {
|
|
373
|
+
property: string;
|
|
374
|
+
direction: 'ASC' | 'DESC';
|
|
375
|
+
sorterFn?: (a: Model, b: Model) => number;
|
|
376
|
+
}
|
|
377
|
+
type FilterOperator = '=' | '!=' | '<' | '<=' | '>' | '>=' | 'like' | 'in' | 'notin';
|
|
378
|
+
interface Filter {
|
|
379
|
+
property: string;
|
|
380
|
+
value: unknown;
|
|
381
|
+
operator?: FilterOperator;
|
|
382
|
+
filterFn?: (record: Model) => boolean;
|
|
383
|
+
anyMatch?: boolean;
|
|
384
|
+
caseSensitive?: boolean;
|
|
385
|
+
}
|
|
386
|
+
interface Group {
|
|
387
|
+
name: string;
|
|
388
|
+
children: Model[];
|
|
389
|
+
}
|
|
390
|
+
interface StoreConfig {
|
|
391
|
+
model: typeof Model;
|
|
392
|
+
data?: Record<string, unknown>[];
|
|
393
|
+
}
|
|
394
|
+
declare class Store extends Base {
|
|
395
|
+
static $className: string;
|
|
396
|
+
private ModelClass;
|
|
397
|
+
private data;
|
|
398
|
+
private allData;
|
|
399
|
+
private currentSorters;
|
|
400
|
+
private currentFilters;
|
|
401
|
+
private groupField;
|
|
402
|
+
private groupDirection;
|
|
403
|
+
private cachedGroups;
|
|
404
|
+
private removedRecords;
|
|
405
|
+
$destroyHooks: (() => void)[];
|
|
406
|
+
constructor(config: StoreConfig);
|
|
407
|
+
private loadData;
|
|
408
|
+
add(...records: Model[]): Model[];
|
|
409
|
+
insert(index: number, ...records: Model[]): Model[];
|
|
410
|
+
remove(...records: Model[]): Model[];
|
|
411
|
+
removeAt(index: number, count?: number): Model[];
|
|
412
|
+
removeAll(silent?: boolean): void;
|
|
413
|
+
getAt(index: number): Model | undefined;
|
|
414
|
+
getById(id: string | number): Model | undefined;
|
|
415
|
+
getRange(start?: number, end?: number): Model[];
|
|
416
|
+
getCount(): number;
|
|
417
|
+
getTotalCount(): number;
|
|
418
|
+
indexOf(record: Model): number;
|
|
419
|
+
contains(record: Model): boolean;
|
|
420
|
+
first(): Model | undefined;
|
|
421
|
+
last(): Model | undefined;
|
|
422
|
+
each(fn: (record: Model, index: number) => boolean | void): void;
|
|
423
|
+
collect(fieldName: string): unknown[];
|
|
424
|
+
getData(): Collection<Model>;
|
|
425
|
+
sort(fieldOrSorters?: string | Sorter[], direction?: 'ASC' | 'DESC'): void;
|
|
426
|
+
getSorters(): Sorter[];
|
|
427
|
+
filter(fieldOrFilters: string | Filter[], value?: unknown): void;
|
|
428
|
+
clearFilter(suppressEvent?: boolean): void;
|
|
429
|
+
getFilters(): Filter[];
|
|
430
|
+
private applyFilters;
|
|
431
|
+
group(field: string, direction?: 'ASC' | 'DESC'): void;
|
|
432
|
+
clearGrouping(): void;
|
|
433
|
+
isGrouped(): boolean;
|
|
434
|
+
getGroups(): Group[];
|
|
435
|
+
private invalidateGroups;
|
|
436
|
+
getModifiedRecords(): Model[];
|
|
437
|
+
getNewRecords(): Model[];
|
|
438
|
+
getRemovedRecords(): Model[];
|
|
439
|
+
commitChanges(): void;
|
|
440
|
+
rejectChanges(): void;
|
|
441
|
+
private fire;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* @framesquared/data – ResultSet
|
|
446
|
+
*/
|
|
447
|
+
|
|
448
|
+
interface ResultSetConfig {
|
|
449
|
+
records: Model[];
|
|
450
|
+
total?: number;
|
|
451
|
+
success: boolean;
|
|
452
|
+
message?: string;
|
|
453
|
+
}
|
|
454
|
+
declare class ResultSet {
|
|
455
|
+
readonly records: Model[];
|
|
456
|
+
readonly total: number;
|
|
457
|
+
readonly success: boolean;
|
|
458
|
+
readonly message: string | undefined;
|
|
459
|
+
constructor(config: ResultSetConfig);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @framesquared/data – Operation
|
|
464
|
+
*/
|
|
465
|
+
|
|
466
|
+
type OperationAction = 'create' | 'read' | 'update' | 'destroy';
|
|
467
|
+
interface OperationConfig {
|
|
468
|
+
action: OperationAction;
|
|
469
|
+
records?: Model[];
|
|
470
|
+
params?: Record<string, unknown>;
|
|
471
|
+
filters?: any[];
|
|
472
|
+
sorters?: any[];
|
|
473
|
+
start?: number;
|
|
474
|
+
limit?: number;
|
|
475
|
+
page?: number;
|
|
476
|
+
}
|
|
477
|
+
declare class Operation {
|
|
478
|
+
readonly action: OperationAction;
|
|
479
|
+
readonly records: Model[];
|
|
480
|
+
readonly params: Record<string, unknown>;
|
|
481
|
+
readonly filters: any[] | undefined;
|
|
482
|
+
readonly sorters: any[] | undefined;
|
|
483
|
+
readonly start: number | undefined;
|
|
484
|
+
readonly limit: number | undefined;
|
|
485
|
+
readonly page: number | undefined;
|
|
486
|
+
result: ResultSet | null;
|
|
487
|
+
constructor(config: OperationConfig);
|
|
488
|
+
setResult(rs: ResultSet): void;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* @framesquared/data – Readers
|
|
493
|
+
*
|
|
494
|
+
* Parse raw server response data into ResultSet instances.
|
|
495
|
+
*/
|
|
496
|
+
|
|
497
|
+
interface JsonReaderConfig {
|
|
498
|
+
model: typeof Model;
|
|
499
|
+
rootProperty?: string;
|
|
500
|
+
totalProperty?: string;
|
|
501
|
+
successProperty?: string;
|
|
502
|
+
messageProperty?: string;
|
|
503
|
+
}
|
|
504
|
+
declare class JsonReader {
|
|
505
|
+
protected config: JsonReaderConfig;
|
|
506
|
+
constructor(config: JsonReaderConfig);
|
|
507
|
+
read(data: unknown): ResultSet;
|
|
508
|
+
}
|
|
509
|
+
interface ArrayReaderConfig {
|
|
510
|
+
model: typeof Model;
|
|
511
|
+
}
|
|
512
|
+
declare class ArrayReader {
|
|
513
|
+
private config;
|
|
514
|
+
constructor(config: ArrayReaderConfig);
|
|
515
|
+
read(data: unknown[][]): ResultSet;
|
|
516
|
+
}
|
|
517
|
+
interface XmlReaderConfig {
|
|
518
|
+
model: typeof Model;
|
|
519
|
+
record: string;
|
|
520
|
+
}
|
|
521
|
+
declare class XmlReader {
|
|
522
|
+
private config;
|
|
523
|
+
constructor(config: XmlReaderConfig);
|
|
524
|
+
read(xmlString: string): ResultSet;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* @framesquared/data – Writers
|
|
529
|
+
*
|
|
530
|
+
* Serialize Model records for transport to the server.
|
|
531
|
+
*/
|
|
532
|
+
|
|
533
|
+
interface JsonWriterConfig {
|
|
534
|
+
writeAllFields?: boolean;
|
|
535
|
+
allowSingle?: boolean;
|
|
536
|
+
encode?: boolean;
|
|
537
|
+
rootProperty?: string;
|
|
538
|
+
}
|
|
539
|
+
declare class JsonWriter {
|
|
540
|
+
private config;
|
|
541
|
+
constructor(config: JsonWriterConfig);
|
|
542
|
+
write(records: Model[]): unknown;
|
|
543
|
+
private serializeRecord;
|
|
544
|
+
}
|
|
545
|
+
interface XmlWriterConfig {
|
|
546
|
+
documentRoot?: string;
|
|
547
|
+
record?: string;
|
|
548
|
+
}
|
|
549
|
+
declare class XmlWriter {
|
|
550
|
+
private config;
|
|
551
|
+
constructor(config: XmlWriterConfig);
|
|
552
|
+
write(records: Model[]): string;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* @framesquared/data – Proxy (abstract base)
|
|
557
|
+
*/
|
|
558
|
+
|
|
559
|
+
interface BatchOptions {
|
|
560
|
+
create?: Model[];
|
|
561
|
+
update?: Model[];
|
|
562
|
+
destroy?: Model[];
|
|
563
|
+
}
|
|
564
|
+
interface Batch {
|
|
565
|
+
success: boolean;
|
|
566
|
+
operations: Operation[];
|
|
567
|
+
}
|
|
568
|
+
interface ProxyConfig {
|
|
569
|
+
model: typeof Model;
|
|
570
|
+
[key: string]: unknown;
|
|
571
|
+
}
|
|
572
|
+
declare abstract class Proxy {
|
|
573
|
+
readonly model: typeof Model;
|
|
574
|
+
constructor(config: ProxyConfig);
|
|
575
|
+
abstract read(operation: Operation, signal?: AbortSignal): Promise<ResultSet>;
|
|
576
|
+
abstract create(operation: Operation): Promise<ResultSet>;
|
|
577
|
+
abstract update(operation: Operation): Promise<ResultSet>;
|
|
578
|
+
abstract destroy(operation: Operation): Promise<ResultSet>;
|
|
579
|
+
batch(options: BatchOptions): Promise<Batch>;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* @framesquared/data – Client Proxies
|
|
584
|
+
*
|
|
585
|
+
* MemoryProxy, LocalStorageProxy, SessionStorageProxy
|
|
586
|
+
*/
|
|
587
|
+
|
|
588
|
+
interface MemoryProxyConfig extends ProxyConfig {
|
|
589
|
+
data?: Record<string, unknown>[];
|
|
590
|
+
}
|
|
591
|
+
declare class MemoryProxy extends Proxy {
|
|
592
|
+
private store;
|
|
593
|
+
constructor(config: MemoryProxyConfig);
|
|
594
|
+
read(operation: Operation): Promise<ResultSet>;
|
|
595
|
+
create(operation: Operation): Promise<ResultSet>;
|
|
596
|
+
update(operation: Operation): Promise<ResultSet>;
|
|
597
|
+
destroy(operation: Operation): Promise<ResultSet>;
|
|
598
|
+
}
|
|
599
|
+
interface WebStorageProxyConfig extends ProxyConfig {
|
|
600
|
+
id: string;
|
|
601
|
+
}
|
|
602
|
+
declare abstract class WebStorageProxy extends Proxy {
|
|
603
|
+
protected storageId: string;
|
|
604
|
+
protected abstract getStorage(): Storage;
|
|
605
|
+
constructor(config: WebStorageProxyConfig);
|
|
606
|
+
private loadAll;
|
|
607
|
+
private saveAll;
|
|
608
|
+
read(_operation: Operation): Promise<ResultSet>;
|
|
609
|
+
create(operation: Operation): Promise<ResultSet>;
|
|
610
|
+
update(operation: Operation): Promise<ResultSet>;
|
|
611
|
+
destroy(operation: Operation): Promise<ResultSet>;
|
|
612
|
+
}
|
|
613
|
+
declare class LocalStorageProxy extends WebStorageProxy {
|
|
614
|
+
protected getStorage(): Storage;
|
|
615
|
+
}
|
|
616
|
+
declare class SessionStorageProxy extends WebStorageProxy {
|
|
617
|
+
protected getStorage(): Storage;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* @framesquared/data – Server Proxies
|
|
622
|
+
*
|
|
623
|
+
* AjaxProxy (fetch-based) and RestProxy (RESTful URL patterns).
|
|
624
|
+
*/
|
|
625
|
+
|
|
626
|
+
interface AjaxProxyConfig extends ProxyConfig {
|
|
627
|
+
url: string;
|
|
628
|
+
api?: Partial<Record<string, string>>;
|
|
629
|
+
headers?: Record<string, string>;
|
|
630
|
+
timeout?: number;
|
|
631
|
+
withCredentials?: boolean;
|
|
632
|
+
}
|
|
633
|
+
declare class AjaxProxy extends Proxy {
|
|
634
|
+
protected url: string;
|
|
635
|
+
protected api: Partial<Record<string, string>>;
|
|
636
|
+
protected headers: Record<string, string>;
|
|
637
|
+
protected timeout: number;
|
|
638
|
+
protected withCredentials: boolean;
|
|
639
|
+
protected reader: JsonReader;
|
|
640
|
+
protected writer: JsonWriter;
|
|
641
|
+
constructor(config: AjaxProxyConfig);
|
|
642
|
+
read(operation: Operation, signal?: AbortSignal): Promise<ResultSet>;
|
|
643
|
+
create(operation: Operation): Promise<ResultSet>;
|
|
644
|
+
update(operation: Operation): Promise<ResultSet>;
|
|
645
|
+
destroy(operation: Operation): Promise<ResultSet>;
|
|
646
|
+
protected buildUrl(operation: Operation, action: string): string;
|
|
647
|
+
protected doRequest(operation: Operation, action: string, signal?: AbortSignal): Promise<ResultSet>;
|
|
648
|
+
}
|
|
649
|
+
interface RestProxyConfig extends AjaxProxyConfig {
|
|
650
|
+
appendId?: boolean;
|
|
651
|
+
}
|
|
652
|
+
declare class RestProxy extends AjaxProxy {
|
|
653
|
+
private appendId;
|
|
654
|
+
constructor(config: RestProxyConfig);
|
|
655
|
+
protected buildUrl(operation: Operation, action: string): string;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* @framesquared/data – NodeInterface
|
|
660
|
+
*
|
|
661
|
+
* Mixin applied to Model instances to give them tree-node capabilities:
|
|
662
|
+
* parent/child/sibling navigation, depth, expand/collapse state,
|
|
663
|
+
* cascadeBy, bubble, getPath, findChild, sort, and nested serialization.
|
|
664
|
+
*/
|
|
665
|
+
|
|
666
|
+
interface NodeInterface extends Model {
|
|
667
|
+
parentNode: NodeInterface | null;
|
|
668
|
+
childNodes: NodeInterface[];
|
|
669
|
+
firstChild: NodeInterface | null;
|
|
670
|
+
lastChild: NodeInterface | null;
|
|
671
|
+
previousSibling: NodeInterface | null;
|
|
672
|
+
nextSibling: NodeInterface | null;
|
|
673
|
+
depth: number;
|
|
674
|
+
/** Node state */
|
|
675
|
+
expanded: boolean;
|
|
676
|
+
loaded: boolean;
|
|
677
|
+
isLeaf(): boolean;
|
|
678
|
+
isRoot(): boolean;
|
|
679
|
+
isExpanded(): boolean;
|
|
680
|
+
isLoaded(): boolean;
|
|
681
|
+
appendChild(child: NodeInterface): void;
|
|
682
|
+
removeChild(child: NodeInterface): void;
|
|
683
|
+
insertBefore(newChild: NodeInterface, refChild: NodeInterface): void;
|
|
684
|
+
getPath(separator?: string): string;
|
|
685
|
+
cascadeBy(fn: (node: NodeInterface) => boolean | void): void;
|
|
686
|
+
bubble(fn: (node: NodeInterface) => boolean | void): void;
|
|
687
|
+
contains(child: NodeInterface): boolean;
|
|
688
|
+
findChild(field: string, value: unknown, deep?: boolean): NodeInterface | undefined;
|
|
689
|
+
sort(sorters: Sorter[]): void;
|
|
690
|
+
serialize(): any;
|
|
691
|
+
eachChild(fn: (child: NodeInterface, index: number) => boolean | void, scope?: object): void;
|
|
692
|
+
indexOf(child: NodeInterface): number;
|
|
693
|
+
getChildAt(index: number): NodeInterface | undefined;
|
|
694
|
+
childCount(): number;
|
|
695
|
+
hasChildNodes(): boolean;
|
|
696
|
+
getChildren(deep?: boolean): NodeInterface[];
|
|
697
|
+
findChildBy(predicate: (node: NodeInterface) => boolean | void, deep?: boolean): NodeInterface | undefined;
|
|
698
|
+
removeAll(): NodeInterface[];
|
|
699
|
+
copy(deep?: boolean): NodeInterface;
|
|
700
|
+
getDepth(): number;
|
|
701
|
+
}
|
|
702
|
+
declare function applyNodeInterface(model: Model, depth?: number): void;
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* @framesquared/data – TreeStore
|
|
706
|
+
*
|
|
707
|
+
* Manages hierarchical (tree) data. Records are enhanced with
|
|
708
|
+
* NodeInterface for parent/child navigation, expand/collapse,
|
|
709
|
+
* and nested serialization.
|
|
710
|
+
*/
|
|
711
|
+
|
|
712
|
+
interface TreeStoreConfig {
|
|
713
|
+
model?: typeof Model;
|
|
714
|
+
root?: Record<string, unknown>;
|
|
715
|
+
proxy?: any;
|
|
716
|
+
}
|
|
717
|
+
declare class TreeStore extends Base {
|
|
718
|
+
static $className: string;
|
|
719
|
+
private ModelClass;
|
|
720
|
+
private rootNode;
|
|
721
|
+
private nodeMap;
|
|
722
|
+
$destroyHooks: (() => void)[];
|
|
723
|
+
constructor(config: TreeStoreConfig);
|
|
724
|
+
getRoot(): NodeInterface;
|
|
725
|
+
getRootNode(): NodeInterface;
|
|
726
|
+
/**
|
|
727
|
+
* Replaces the root with new data (or a pre-built node).
|
|
728
|
+
* Fires 'rootchange'.
|
|
729
|
+
*/
|
|
730
|
+
setRoot(nodeOrData: NodeInterface | Record<string, unknown>): NodeInterface;
|
|
731
|
+
private isNodeInterface;
|
|
732
|
+
private replaceRoot;
|
|
733
|
+
getNodeById(id: string | number): NodeInterface | undefined;
|
|
734
|
+
appendChild(parent: NodeInterface, child: NodeInterface): void;
|
|
735
|
+
removeChild(parent: NodeInterface, child: NodeInterface): void;
|
|
736
|
+
insertBefore(node: NodeInterface, refNode: NodeInterface): void;
|
|
737
|
+
expandNode(node: NodeInterface): void;
|
|
738
|
+
collapseNode(node: NodeInterface): void;
|
|
739
|
+
findNode(field: string, value: unknown): NodeInterface | undefined;
|
|
740
|
+
private findNodeImpl;
|
|
741
|
+
collapseAll(): void;
|
|
742
|
+
expandAll(): void;
|
|
743
|
+
getCount(): number;
|
|
744
|
+
getTotalCount(): number;
|
|
745
|
+
flattenNodes(): Model[];
|
|
746
|
+
private flattenWalk;
|
|
747
|
+
private buildNode;
|
|
748
|
+
private registerRecursive;
|
|
749
|
+
private unregisterRecursive;
|
|
750
|
+
private fire;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* @framesquared/data – TreeModel
|
|
755
|
+
*
|
|
756
|
+
* A convenience Model subclass with NodeInterface pre-applied via create().
|
|
757
|
+
*/
|
|
758
|
+
|
|
759
|
+
declare class TreeModel extends Model {
|
|
760
|
+
static $className: string;
|
|
761
|
+
static idProperty: string;
|
|
762
|
+
static defaultRootId: string;
|
|
763
|
+
static defaultRootText: string;
|
|
764
|
+
static fields: ({
|
|
765
|
+
name: string;
|
|
766
|
+
type: FieldType;
|
|
767
|
+
defaultValue?: undefined;
|
|
768
|
+
} | {
|
|
769
|
+
name: string;
|
|
770
|
+
type: FieldType;
|
|
771
|
+
defaultValue: string;
|
|
772
|
+
} | {
|
|
773
|
+
name: string;
|
|
774
|
+
type: FieldType;
|
|
775
|
+
defaultValue: boolean;
|
|
776
|
+
})[];
|
|
777
|
+
/**
|
|
778
|
+
* Factory method that creates a TreeModel instance with NodeInterface
|
|
779
|
+
* already applied.
|
|
780
|
+
*/
|
|
781
|
+
static create(this: typeof Model, data?: Record<string, unknown>): InstanceType<typeof Model> & NodeInterface;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* @framesquared/data – TreeReader
|
|
786
|
+
*
|
|
787
|
+
* Reads nested (hierarchical) JSON data, flattening it into a ResultSet
|
|
788
|
+
* while preserving the children references.
|
|
789
|
+
*/
|
|
790
|
+
|
|
791
|
+
interface TreeReaderConfig extends JsonReaderConfig {
|
|
792
|
+
/** Name of the property that holds child records. Defaults to 'children'. */
|
|
793
|
+
childrenProperty?: string;
|
|
794
|
+
}
|
|
795
|
+
declare class TreeReader extends JsonReader {
|
|
796
|
+
readonly childrenProperty: string;
|
|
797
|
+
constructor(config: TreeReaderConfig);
|
|
798
|
+
/**
|
|
799
|
+
* Reads data, recursively collecting ALL nodes (at all levels) into a flat
|
|
800
|
+
* ResultSet. The original children references are preserved on the raw
|
|
801
|
+
* objects, so the tree structure is available to callers (e.g. TreeStore).
|
|
802
|
+
*/
|
|
803
|
+
read(data: unknown): ResultSet;
|
|
804
|
+
/**
|
|
805
|
+
* Returns `{ root, records }` where `root` is the first raw record and
|
|
806
|
+
* `records` is the full flat list of all nodes.
|
|
807
|
+
*/
|
|
808
|
+
readTree(data: Record<string, unknown>): {
|
|
809
|
+
root: Record<string, unknown>;
|
|
810
|
+
records: Record<string, unknown>[];
|
|
811
|
+
};
|
|
812
|
+
private extractRootArray;
|
|
813
|
+
private collectFlat;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* @framesquared/data – TreeWriter
|
|
818
|
+
*
|
|
819
|
+
* Serializes tree nodes (NodeInterface) into nested JSON structures.
|
|
820
|
+
*/
|
|
821
|
+
|
|
822
|
+
interface TreeWriterConfig {
|
|
823
|
+
/** Name of the property used for child records. Defaults to 'children'. */
|
|
824
|
+
childrenProperty?: string;
|
|
825
|
+
}
|
|
826
|
+
declare class TreeWriter {
|
|
827
|
+
readonly childrenProperty: string;
|
|
828
|
+
constructor(config?: TreeWriterConfig);
|
|
829
|
+
/**
|
|
830
|
+
* Serializes an array of root-level NodeInterface records to plain objects.
|
|
831
|
+
* Children are nested under the configured `childrenProperty`.
|
|
832
|
+
*/
|
|
833
|
+
writeRecords(records: NodeInterface[]): Record<string, unknown>[];
|
|
834
|
+
private writeRecord;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* @framesquared/data – BufferedStore
|
|
839
|
+
*
|
|
840
|
+
* For large datasets — loads pages of data on demand via a proxy.
|
|
841
|
+
* Uses a sparse page map instead of loading all records.
|
|
842
|
+
* Prefetches adjacent pages based on configurable buffer zones.
|
|
843
|
+
*/
|
|
844
|
+
|
|
845
|
+
interface BufferedStoreConfig {
|
|
846
|
+
model: typeof Model;
|
|
847
|
+
pageSize?: number;
|
|
848
|
+
leadingBufferZone?: number;
|
|
849
|
+
trailingBufferZone?: number;
|
|
850
|
+
proxy?: any;
|
|
851
|
+
}
|
|
852
|
+
declare class BufferedStore extends Base {
|
|
853
|
+
static $className: string;
|
|
854
|
+
private pageSize;
|
|
855
|
+
private leadingBufferZone;
|
|
856
|
+
private trailingBufferZone;
|
|
857
|
+
private proxyRef;
|
|
858
|
+
/** Page number → array of Model records for that page. */
|
|
859
|
+
private pageMap;
|
|
860
|
+
/** Total count from the server. */
|
|
861
|
+
private totalCount;
|
|
862
|
+
/** All loaded records in a flat sparse index. */
|
|
863
|
+
private recordMap;
|
|
864
|
+
/** Pages currently being fetched (to avoid duplicate requests). */
|
|
865
|
+
private pendingPages;
|
|
866
|
+
$destroyHooks: (() => void)[];
|
|
867
|
+
constructor(config: BufferedStoreConfig);
|
|
868
|
+
getPageSize(): number;
|
|
869
|
+
getCount(): number;
|
|
870
|
+
getTotalCount(): number;
|
|
871
|
+
getAt(index: number): Model | undefined;
|
|
872
|
+
isPageLoaded(pageNumber: number): boolean;
|
|
873
|
+
/**
|
|
874
|
+
* Ensures the given range [start, end] of row indices is loaded.
|
|
875
|
+
* Loads missing pages from the proxy and fires 'guaranteedrange'
|
|
876
|
+
* when the requested range is fully available.
|
|
877
|
+
*/
|
|
878
|
+
guaranteeRange(start: number, end: number): Promise<void>;
|
|
879
|
+
private loadPage;
|
|
880
|
+
private prefetchBufferZones;
|
|
881
|
+
private fire;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* @framesquared/data – GraphQLProxy
|
|
886
|
+
*
|
|
887
|
+
* Sends GraphQL queries for read and mutations for CUD operations.
|
|
888
|
+
* Parses response using a rootProperty path into the GraphQL data.
|
|
889
|
+
*/
|
|
890
|
+
|
|
891
|
+
interface GraphQLProxyConfig extends ProxyConfig {
|
|
892
|
+
url: string;
|
|
893
|
+
query?: string;
|
|
894
|
+
mutation?: string;
|
|
895
|
+
rootProperty?: string;
|
|
896
|
+
headers?: Record<string, string>;
|
|
897
|
+
}
|
|
898
|
+
declare class GraphQLProxy extends Proxy {
|
|
899
|
+
private url;
|
|
900
|
+
private query;
|
|
901
|
+
private mutation;
|
|
902
|
+
private rootProperty;
|
|
903
|
+
private headers;
|
|
904
|
+
constructor(config: GraphQLProxyConfig);
|
|
905
|
+
read(operation: Operation): Promise<ResultSet>;
|
|
906
|
+
create(operation: Operation): Promise<ResultSet>;
|
|
907
|
+
update(operation: Operation): Promise<ResultSet>;
|
|
908
|
+
destroy(operation: Operation): Promise<ResultSet>;
|
|
909
|
+
private doRequest;
|
|
910
|
+
private extractByPath;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* @framesquared/data – WebSocketProxy
|
|
915
|
+
*
|
|
916
|
+
* Maintains a WebSocket connection for real-time data. Sends
|
|
917
|
+
* CRUD operations as JSON messages. Auto-reconnects on disconnect.
|
|
918
|
+
*/
|
|
919
|
+
|
|
920
|
+
interface WebSocketProxyConfig extends ProxyConfig {
|
|
921
|
+
url: string;
|
|
922
|
+
protocol?: string;
|
|
923
|
+
reconnect?: boolean;
|
|
924
|
+
reconnectInterval?: number;
|
|
925
|
+
}
|
|
926
|
+
declare class WebSocketProxy extends Proxy {
|
|
927
|
+
private url;
|
|
928
|
+
private reconnect;
|
|
929
|
+
private reconnectInterval;
|
|
930
|
+
private ws;
|
|
931
|
+
private listeners;
|
|
932
|
+
private intentionalClose;
|
|
933
|
+
private reconnectTimer;
|
|
934
|
+
constructor(config: WebSocketProxyConfig);
|
|
935
|
+
connect(): void;
|
|
936
|
+
disconnect(): void;
|
|
937
|
+
send(operation: Operation): void;
|
|
938
|
+
read(operation: Operation): Promise<ResultSet>;
|
|
939
|
+
create(operation: Operation): Promise<ResultSet>;
|
|
940
|
+
update(operation: Operation): Promise<ResultSet>;
|
|
941
|
+
destroy(operation: Operation): Promise<ResultSet>;
|
|
942
|
+
on(event: string, fn: Function): void;
|
|
943
|
+
off(event: string, fn: Function): void;
|
|
944
|
+
private fire;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
/**
|
|
948
|
+
* @framesquared/data – BatchProxy
|
|
949
|
+
*
|
|
950
|
+
* Combines multiple operations into a single HTTP request.
|
|
951
|
+
* Unwraps the batch response into individual ResultSets.
|
|
952
|
+
*/
|
|
953
|
+
|
|
954
|
+
interface BatchProxyConfig extends ProxyConfig {
|
|
955
|
+
url: string;
|
|
956
|
+
headers?: Record<string, string>;
|
|
957
|
+
}
|
|
958
|
+
declare class BatchProxy extends Proxy {
|
|
959
|
+
private url;
|
|
960
|
+
private headers;
|
|
961
|
+
constructor(config: BatchProxyConfig);
|
|
962
|
+
/**
|
|
963
|
+
* Send multiple operations as a single batched request.
|
|
964
|
+
* Returns an array of ResultSets, one per operation.
|
|
965
|
+
*/
|
|
966
|
+
sendBatch(operations: Operation[]): Promise<ResultSet[]>;
|
|
967
|
+
read(operation: Operation): Promise<ResultSet>;
|
|
968
|
+
create(operation: Operation): Promise<ResultSet>;
|
|
969
|
+
update(operation: Operation): Promise<ResultSet>;
|
|
970
|
+
destroy(operation: Operation): Promise<ResultSet>;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* @framesquared/data – Connection
|
|
975
|
+
*
|
|
976
|
+
* Centralized fetch() wrapper. Supports request and response
|
|
977
|
+
* interceptors, default headers, and global error handling.
|
|
978
|
+
*/
|
|
979
|
+
type RequestInterceptor = (url: string, init: RequestInit) => [string, RequestInit];
|
|
980
|
+
type ResponseInterceptor = (response: any) => any;
|
|
981
|
+
type ErrorHandler = (error: Error) => void;
|
|
982
|
+
declare const Connection: {
|
|
983
|
+
/**
|
|
984
|
+
* Fetch with interceptors and default headers applied.
|
|
985
|
+
*/
|
|
986
|
+
fetch(url: string, init?: RequestInit): Promise<any>;
|
|
987
|
+
addRequestInterceptor(fn: RequestInterceptor): void;
|
|
988
|
+
addResponseInterceptor(fn: ResponseInterceptor): void;
|
|
989
|
+
setDefaultHeaders(headers: Record<string, string>): void;
|
|
990
|
+
setErrorHandler(handler: ErrorHandler): void;
|
|
991
|
+
reset(): void;
|
|
992
|
+
};
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* @framesquared/data – Session
|
|
996
|
+
*
|
|
997
|
+
* Manages a set of related model instances. Tracks all CRUD
|
|
998
|
+
* operations as a unit. save() sends all changes via a BatchProxy.
|
|
999
|
+
* commit()/reject() clear tracked changes.
|
|
1000
|
+
*/
|
|
1001
|
+
|
|
1002
|
+
interface SessionChanges {
|
|
1003
|
+
create: Model[];
|
|
1004
|
+
update: Model[];
|
|
1005
|
+
destroy: Model[];
|
|
1006
|
+
}
|
|
1007
|
+
declare class Session {
|
|
1008
|
+
private created;
|
|
1009
|
+
private updated;
|
|
1010
|
+
private destroyed;
|
|
1011
|
+
trackCreate(record: Model): void;
|
|
1012
|
+
trackUpdate(record: Model): void;
|
|
1013
|
+
trackDestroy(record: Model): void;
|
|
1014
|
+
getCreated(): Model[];
|
|
1015
|
+
getUpdated(): Model[];
|
|
1016
|
+
getDestroyed(): Model[];
|
|
1017
|
+
getChanges(): SessionChanges;
|
|
1018
|
+
isDirty(): boolean;
|
|
1019
|
+
save(proxy: BatchProxy): Promise<{
|
|
1020
|
+
success: boolean;
|
|
1021
|
+
results: ResultSet[];
|
|
1022
|
+
}>;
|
|
1023
|
+
commit(): void;
|
|
1024
|
+
reject(): void;
|
|
1025
|
+
private recordKey;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
export { AjaxProxy, type AjaxProxyConfig, ArrayReader, type ArrayReaderConfig, Association, type AssociationConfig, type AssociationType, AutoField, type Batch, type BatchOptions, BatchProxy, type BatchProxyConfig, BelongsTo, BooleanField, BufferedStore, type BufferedStoreConfig, Collection, Connection, DateField, Field, type FieldDefinition, FieldType, type Filter, type FilterOperator, FloatField, GraphQLProxy, type GraphQLProxyConfig, type Group, HasMany, HasOne, IntField, JsonReader, type JsonReaderConfig, JsonWriter, type JsonWriterConfig, LocalStorageProxy, ManyToMany, ManyToManyCollection, MemoryProxy, type MemoryProxyConfig, Model, ModelCollection, type NodeInterface, Operation, type OperationAction, type OperationConfig, Proxy, type ProxyConfig, RestProxy, type RestProxyConfig, ResultSet, type ResultSetConfig, Schema, Session, type SessionChanges, SessionStorageProxy, type Sorter, Store, type StoreConfig, StringField, TreeModel, TreeReader, type TreeReaderConfig, TreeStore, type TreeStoreConfig, TreeWriter, type TreeWriterConfig, type ValidationError, type ValidationResult, type Validator, WebSocketProxy, type WebSocketProxyConfig, type WebStorageProxyConfig, XmlReader, type XmlReaderConfig, XmlWriter, type XmlWriterConfig, applyNodeInterface, createField, email, exclusion, formatValidator, inclusion, length, presence, rangeValidator };
|