@contentrain/query 4.0.0 → 5.0.1
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 -21
- package/README.md +253 -260
- package/dist/cli.cjs +78 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +81 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/generate-C5Qz8qKt.mjs +855 -0
- package/dist/generate-C5Qz8qKt.mjs.map +1 -0
- package/dist/generate-CPKYh6ZU.cjs +858 -0
- package/dist/generator/generate.cjs +3 -0
- package/dist/generator/generate.d.cts +14 -0
- package/dist/generator/generate.d.cts.map +1 -0
- package/dist/generator/generate.d.mts +14 -0
- package/dist/generator/generate.d.mts.map +1 -0
- package/dist/generator/generate.mjs +2 -0
- package/dist/index.cjs +356 -0
- package/dist/index.d.cts +108 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +108 -565
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +349 -30
- package/dist/index.mjs.map +1 -0
- package/package.json +53 -38
- package/dist/index.d.ts +0 -565
- package/dist/index.js +0 -30
package/dist/index.d.mts
CHANGED
|
@@ -1,565 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
interface IJSONRelationManager {
|
|
110
|
-
loadRelations: (modelId: string) => Promise<IJSONRelationConfig[]>;
|
|
111
|
-
resolveRelation: <T extends IBaseJSONRecord, R extends IBaseJSONRecord>(modelId: string, relationField: keyof T, data: T[], locale?: string) => Promise<R[]>;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
interface IDBRecord {
|
|
115
|
-
id: string;
|
|
116
|
-
created_at: string;
|
|
117
|
-
updated_at: string;
|
|
118
|
-
status: ContentrainStatus;
|
|
119
|
-
scheduled?: boolean;
|
|
120
|
-
_relations?: {
|
|
121
|
-
[key: string]: IDBRecord | IDBRecord[];
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
interface IDBTranslationRecord extends IDBRecord {
|
|
125
|
-
readonly locale: string;
|
|
126
|
-
readonly [key: string]: unknown;
|
|
127
|
-
}
|
|
128
|
-
interface IDBRelation {
|
|
129
|
-
readonly id: string;
|
|
130
|
-
readonly source_model: string;
|
|
131
|
-
readonly source_id: string;
|
|
132
|
-
readonly target_model: string;
|
|
133
|
-
readonly target_id: string;
|
|
134
|
-
readonly field_id: string;
|
|
135
|
-
readonly type: 'one-to-one' | 'one-to-many';
|
|
136
|
-
readonly created_at: string;
|
|
137
|
-
readonly updated_at: string;
|
|
138
|
-
}
|
|
139
|
-
interface ISQLiteLoaderOptions {
|
|
140
|
-
databasePath: string;
|
|
141
|
-
cache?: boolean;
|
|
142
|
-
maxCacheSize?: number;
|
|
143
|
-
modelTTL?: number | Record<string, number>;
|
|
144
|
-
defaultLocale?: string;
|
|
145
|
-
sorting?: {
|
|
146
|
-
field: string;
|
|
147
|
-
direction: 'asc' | 'desc';
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
interface ISQLiteContent<TData extends IDBRecord> {
|
|
151
|
-
readonly default: TData[];
|
|
152
|
-
readonly translations?: Record<string, IDBTranslationRecord[]>;
|
|
153
|
-
}
|
|
154
|
-
interface ISQLiteLoaderResult<TData extends IDBRecord> {
|
|
155
|
-
readonly model: {
|
|
156
|
-
readonly metadata: {
|
|
157
|
-
readonly modelId: string;
|
|
158
|
-
readonly name: string;
|
|
159
|
-
readonly type: 'SQLite';
|
|
160
|
-
readonly localization: boolean;
|
|
161
|
-
readonly isServerless: boolean;
|
|
162
|
-
};
|
|
163
|
-
readonly fields: Array<{
|
|
164
|
-
readonly name: string;
|
|
165
|
-
readonly fieldId: string;
|
|
166
|
-
readonly type: string;
|
|
167
|
-
}>;
|
|
168
|
-
};
|
|
169
|
-
readonly content: ISQLiteContent<TData>;
|
|
170
|
-
}
|
|
171
|
-
interface ISQLiteConnection {
|
|
172
|
-
query: <T>(sql: string, params?: unknown[]) => Promise<T[]>;
|
|
173
|
-
get: <T>(sql: string, params?: unknown[]) => Promise<T | undefined>;
|
|
174
|
-
close: () => void;
|
|
175
|
-
}
|
|
176
|
-
interface ISQLiteContentManager {
|
|
177
|
-
findById: <T extends IDBRecord>(model: string, id: string) => Promise<T | undefined>;
|
|
178
|
-
findAll: <T extends IDBRecord>(model: string, conditions?: Partial<T>) => Promise<T[]>;
|
|
179
|
-
}
|
|
180
|
-
interface ISQLiteRelationManager {
|
|
181
|
-
loadRelations: (model: string, sourceIds: string[], fieldId: string) => Promise<IDBRelation[]>;
|
|
182
|
-
loadRelatedContent: <T extends IDBRecord>(relations: IDBRelation[], locale?: string) => Promise<T[]>;
|
|
183
|
-
getRelationTypes: (model: string) => Promise<Record<string, 'one-to-one' | 'one-to-many'>>;
|
|
184
|
-
}
|
|
185
|
-
interface ISQLiteTranslationManager {
|
|
186
|
-
hasTranslations: (model: string) => Promise<boolean>;
|
|
187
|
-
loadTranslations: (model: string, ids: string[], locale?: string) => Promise<Record<string, IDBTranslationRecord>>;
|
|
188
|
-
getLocales: (model: string) => Promise<string[]>;
|
|
189
|
-
getMainColumns: (model: string) => Promise<string[]>;
|
|
190
|
-
getTranslationColumns: (model: string) => Promise<string[]>;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
declare class SQLiteConnection {
|
|
194
|
-
private readonly db;
|
|
195
|
-
constructor(databasePath: string);
|
|
196
|
-
private setupDatabase;
|
|
197
|
-
query<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
198
|
-
get<T>(sql: string, params?: unknown[]): Promise<T | undefined>;
|
|
199
|
-
close(): Promise<void>;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
declare class SQLiteContentManager {
|
|
203
|
-
protected readonly databasePath: string;
|
|
204
|
-
protected readonly connection: SQLiteConnection;
|
|
205
|
-
constructor(databasePath: string);
|
|
206
|
-
query<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
207
|
-
findById<T extends IDBRecord>(model: string, id: string): Promise<T | undefined>;
|
|
208
|
-
findAll<T extends IDBRecord>(model: string, conditions?: Partial<T>): Promise<T[]>;
|
|
209
|
-
getTableCount(): Promise<number>;
|
|
210
|
-
close(): Promise<void>;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
declare class SQLiteRelationManager extends SQLiteContentManager {
|
|
214
|
-
private readonly translationManager;
|
|
215
|
-
constructor(databasePath: string);
|
|
216
|
-
loadRelations(model: string, sourceIds: string[], fieldId: string): Promise<IDBRelation[]>;
|
|
217
|
-
loadRelatedContent<T extends IDBRecord>(relations: IDBRelation[], locale?: string): Promise<T[]>;
|
|
218
|
-
getRelationTypes(model: string): Promise<Record<string, 'one-to-one' | 'one-to-many'>>;
|
|
219
|
-
getRelationFields(model: string): Promise<string[]>;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
declare class SQLiteTranslationManager extends SQLiteContentManager {
|
|
223
|
-
constructor(databasePath: string);
|
|
224
|
-
hasTranslations(model: string): Promise<boolean>;
|
|
225
|
-
loadTranslations(model: string, ids: string[], locale?: string): Promise<Record<string, IDBTranslationRecord>>;
|
|
226
|
-
getLocales(model: string): Promise<string[]>;
|
|
227
|
-
getMainColumns(model: string): Promise<string[]>;
|
|
228
|
-
getTranslationColumns(model: string): Promise<string[]>;
|
|
229
|
-
getAllColumns(model: string): Promise<string[]>;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
declare class SQLiteLoader<TData extends IDBRecord = IDBRecord> {
|
|
233
|
-
private readonly options;
|
|
234
|
-
readonly contentManager: SQLiteContentManager;
|
|
235
|
-
readonly relationManager: SQLiteRelationManager;
|
|
236
|
-
readonly translationManager: SQLiteTranslationManager;
|
|
237
|
-
private readonly cache?;
|
|
238
|
-
private readonly modelTTL;
|
|
239
|
-
private readonly modelConfigs;
|
|
240
|
-
constructor(options: ISQLiteLoaderOptions);
|
|
241
|
-
query<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
242
|
-
findById<T extends IDBRecord>(model: string, id: string): Promise<T | undefined>;
|
|
243
|
-
findAll<T extends IDBRecord>(model: string, conditions?: Partial<T>): Promise<T[]>;
|
|
244
|
-
private getCacheKey;
|
|
245
|
-
private getModelTTL;
|
|
246
|
-
private loadWithTranslations;
|
|
247
|
-
private getModelFields;
|
|
248
|
-
private mapSystemFields;
|
|
249
|
-
private mapRelationFields;
|
|
250
|
-
private mapTranslationFields;
|
|
251
|
-
private getFieldType;
|
|
252
|
-
resolveRelations<TRelation extends IDBRecord>(modelId: string, fieldId: string, data: TData[]): Promise<TRelation[]>;
|
|
253
|
-
load(model: string): Promise<ISQLiteLoaderResult<TData>>;
|
|
254
|
-
clearCache(): Promise<void>;
|
|
255
|
-
refreshCache(modelId: string): Promise<void>;
|
|
256
|
-
getCacheStats(): Promise<ICacheStats>;
|
|
257
|
-
close(): Promise<void>;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
interface IQueryExecutor<TData, TInclude extends Include = Include, TOptions extends QueryOptions = QueryOptions> {
|
|
261
|
-
execute: (params: {
|
|
262
|
-
model: string;
|
|
263
|
-
filters?: Filter[];
|
|
264
|
-
includes?: TInclude;
|
|
265
|
-
sorting?: Sort[];
|
|
266
|
-
pagination?: Pagination;
|
|
267
|
-
options?: TOptions;
|
|
268
|
-
}) => Promise<QueryResult<TData>>;
|
|
269
|
-
}
|
|
270
|
-
declare abstract class BaseQueryExecutor<TData, TInclude extends Include = Include, TOptions extends QueryOptions = QueryOptions> implements IQueryExecutor<TData, TInclude, TOptions> {
|
|
271
|
-
protected applyStringOperation(value: string, operator: StringOperator, searchValue: string): boolean;
|
|
272
|
-
protected resolveIncludes(model: string, data: TData[], includes: TInclude, options: TOptions): Promise<TData[]>;
|
|
273
|
-
protected abstract resolveRelation(model: string, field: string, data: TData[], options: TOptions): Promise<TData[]>;
|
|
274
|
-
abstract execute(params: {
|
|
275
|
-
model: string;
|
|
276
|
-
filters?: Filter[];
|
|
277
|
-
includes?: TInclude;
|
|
278
|
-
sorting?: Sort[];
|
|
279
|
-
pagination?: Pagination;
|
|
280
|
-
options?: TOptions;
|
|
281
|
-
}): Promise<QueryResult<TData>>;
|
|
282
|
-
protected applyFilters(data: TData[], filters?: Filter[]): TData[];
|
|
283
|
-
protected applySorting(data: TData[], sorting?: Sort[]): TData[];
|
|
284
|
-
protected applyPagination(data: TData[], limit?: number, offset?: number): TData[];
|
|
285
|
-
protected compareValues(itemValue: any, operator: string, value: any): boolean;
|
|
286
|
-
protected getPaginationInfo(pagination: Pagination | undefined, total: number): QueryResult<TData>['pagination'];
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
declare class SQLiteQueryExecutor<TData extends IDBRecord> extends BaseQueryExecutor<TData, Include, SQLiteOptions> {
|
|
290
|
-
private loader;
|
|
291
|
-
constructor(loader: SQLiteLoader<TData>);
|
|
292
|
-
setLoader(loader: SQLiteLoader<TData>): void;
|
|
293
|
-
protected resolveRelation(model: string, field: string, data: TData[], options: SQLiteOptions): Promise<TData[]>;
|
|
294
|
-
execute(params: {
|
|
295
|
-
model: string;
|
|
296
|
-
filters?: Filter[];
|
|
297
|
-
sorting?: Sort[];
|
|
298
|
-
pagination?: {
|
|
299
|
-
limit?: number;
|
|
300
|
-
offset?: number;
|
|
301
|
-
};
|
|
302
|
-
options?: SQLiteOptions;
|
|
303
|
-
}): Promise<QueryResult<TData>>;
|
|
304
|
-
private buildSQLQuery;
|
|
305
|
-
private buildSQL;
|
|
306
|
-
private addTranslationJoin;
|
|
307
|
-
private buildConditionWithoutParams;
|
|
308
|
-
private getTotal;
|
|
309
|
-
protected getPaginationInfo(pagination: {
|
|
310
|
-
limit?: number;
|
|
311
|
-
offset?: number;
|
|
312
|
-
} | undefined, total: number): {
|
|
313
|
-
limit: number;
|
|
314
|
-
offset: number;
|
|
315
|
-
hasMore: boolean;
|
|
316
|
-
} | undefined;
|
|
317
|
-
private query;
|
|
318
|
-
private mainColumns;
|
|
319
|
-
private translationColumns;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
type StringOperator = 'eq' | 'ne' | 'contains' | 'startsWith' | 'endsWith';
|
|
323
|
-
type NumericOperator = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
|
|
324
|
-
type ArrayOperator = 'in' | 'nin';
|
|
325
|
-
type Operator = StringOperator | NumericOperator | ArrayOperator;
|
|
326
|
-
interface Filter {
|
|
327
|
-
field: string;
|
|
328
|
-
operator: Operator;
|
|
329
|
-
value: any;
|
|
330
|
-
}
|
|
331
|
-
interface Sort {
|
|
332
|
-
field: string;
|
|
333
|
-
direction: 'asc' | 'desc';
|
|
334
|
-
}
|
|
335
|
-
interface Pagination {
|
|
336
|
-
limit?: number;
|
|
337
|
-
offset?: number;
|
|
338
|
-
}
|
|
339
|
-
interface QueryOptions {
|
|
340
|
-
locale?: string;
|
|
341
|
-
cache?: boolean;
|
|
342
|
-
ttl?: number;
|
|
343
|
-
}
|
|
344
|
-
interface QueryResult<TData> {
|
|
345
|
-
data: TData[];
|
|
346
|
-
total: number;
|
|
347
|
-
pagination?: {
|
|
348
|
-
limit: number;
|
|
349
|
-
offset: number;
|
|
350
|
-
hasMore: boolean;
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
interface IncludeOptions {
|
|
354
|
-
relation: string;
|
|
355
|
-
locale?: string;
|
|
356
|
-
}
|
|
357
|
-
type Include = string | IncludeOptions | (string | IncludeOptions)[];
|
|
358
|
-
interface IBaseQueryBuilder<TData> {
|
|
359
|
-
where: (field: keyof TData, operator: Operator, value: any) => this;
|
|
360
|
-
orderBy: (field: keyof TData, direction?: 'asc' | 'desc') => this;
|
|
361
|
-
limit: (count: number) => this;
|
|
362
|
-
offset: (count: number) => this;
|
|
363
|
-
get: () => Promise<QueryResult<TData>>;
|
|
364
|
-
first: () => Promise<TData | null>;
|
|
365
|
-
count: () => Promise<number>;
|
|
366
|
-
cache: (ttl?: number) => this;
|
|
367
|
-
noCache: () => this;
|
|
368
|
-
bypassCache: () => this;
|
|
369
|
-
}
|
|
370
|
-
interface SQLiteOptions {
|
|
371
|
-
includes?: IncludeOptions[];
|
|
372
|
-
locale?: string;
|
|
373
|
-
translations?: boolean;
|
|
374
|
-
}
|
|
375
|
-
type SupportedLocale = string;
|
|
376
|
-
type RelationConfig<T> = {
|
|
377
|
-
[K in keyof T]: T[K] extends {
|
|
378
|
-
_relations?: infer R;
|
|
379
|
-
} ? R : never;
|
|
380
|
-
}[keyof T];
|
|
381
|
-
interface QueryConfig<TModel extends IDBRecord, TLocale extends SupportedLocale = string, TRelations extends Record<string, any> = Record<string, any>> {
|
|
382
|
-
model: TModel;
|
|
383
|
-
locale: TLocale;
|
|
384
|
-
relations: {
|
|
385
|
-
[K in keyof TRelations]: {
|
|
386
|
-
relation: K;
|
|
387
|
-
locale?: TLocale;
|
|
388
|
-
};
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
interface ISQLiteQuery<TModel extends IDBRecord, TLocale extends SupportedLocale = string, TRelations extends Record<string, any> = Record<string, any>> extends IBaseQueryBuilder<TModel> {
|
|
392
|
-
include: <K extends keyof TRelations>(relations: K | K[] | {
|
|
393
|
-
relation: K;
|
|
394
|
-
locale?: TLocale;
|
|
395
|
-
} | Array<{
|
|
396
|
-
relation: K;
|
|
397
|
-
locale?: TLocale;
|
|
398
|
-
}>) => this;
|
|
399
|
-
locale: (code: TLocale) => this;
|
|
400
|
-
setLoader: (loader: SQLiteLoader<TModel>) => this;
|
|
401
|
-
}
|
|
402
|
-
interface SQLQuery {
|
|
403
|
-
select: string[];
|
|
404
|
-
from: string;
|
|
405
|
-
joins: SQLJoin[];
|
|
406
|
-
where: Filter[];
|
|
407
|
-
orderBy: Sort[];
|
|
408
|
-
parameters: unknown[];
|
|
409
|
-
pagination?: Pagination;
|
|
410
|
-
options?: SQLiteOptions;
|
|
411
|
-
}
|
|
412
|
-
interface SQLJoin {
|
|
413
|
-
type: 'LEFT' | 'INNER';
|
|
414
|
-
table: string;
|
|
415
|
-
alias: string;
|
|
416
|
-
conditions: string[];
|
|
417
|
-
}
|
|
418
|
-
interface JSONOptions extends QueryOptions {
|
|
419
|
-
defaultLocale?: string;
|
|
420
|
-
}
|
|
421
|
-
interface IJSONQuery<TData extends IBaseJSONRecord> extends IBaseQueryBuilder<TData> {
|
|
422
|
-
include: (relations: string | string[], reference?: string) => this;
|
|
423
|
-
locale: (code: string, defaultLocale?: string) => this;
|
|
424
|
-
}
|
|
425
|
-
interface SQLiteQueryConfig<TData extends IDBRecord> {
|
|
426
|
-
model: string;
|
|
427
|
-
loader?: SQLiteLoader<TData>;
|
|
428
|
-
options?: SQLiteOptions;
|
|
429
|
-
}
|
|
430
|
-
interface ISQLiteQueryBuilder<TData extends IDBRecord> {
|
|
431
|
-
model: string;
|
|
432
|
-
executor: SQLiteQueryExecutor<TData>;
|
|
433
|
-
options: SQLiteOptions;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
declare class JSONContentManager {
|
|
437
|
-
protected readonly contentDir: string;
|
|
438
|
-
protected readonly defaultLocale?: string | undefined;
|
|
439
|
-
private readonly modelConfigCache;
|
|
440
|
-
private readonly contentCache;
|
|
441
|
-
constructor(contentDir: string, defaultLocale?: string | undefined);
|
|
442
|
-
private getContentCacheKey;
|
|
443
|
-
loadModelConfig(modelId: string): Promise<IJSONModelConfig>;
|
|
444
|
-
loadModelContent<T extends IBaseJSONRecord>(modelId: string, locale?: string): Promise<IJSONContentFile<T>>;
|
|
445
|
-
loadAssets(): Promise<any[]>;
|
|
446
|
-
getModelLocales(modelId: string): Promise<string[]>;
|
|
447
|
-
clearCache(): Promise<void>;
|
|
448
|
-
getCacheStats(): {
|
|
449
|
-
modelConfigs: number;
|
|
450
|
-
contents: number;
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
declare class JSONLoader<TData extends IBaseJSONRecord> extends JSONContentManager {
|
|
455
|
-
private readonly options;
|
|
456
|
-
private readonly relationManager;
|
|
457
|
-
private readonly cache?;
|
|
458
|
-
private readonly modelConfigs;
|
|
459
|
-
constructor(options: IJSONLoaderOptions);
|
|
460
|
-
private getCacheKey;
|
|
461
|
-
private getModelTTL;
|
|
462
|
-
load(modelId: string): Promise<IJSONLoaderResult<TData>>;
|
|
463
|
-
resolveRelations<TRelation extends IBaseJSONRecord>(modelId: string, relationKey: keyof TData, data: TData[]): Promise<TRelation[]>;
|
|
464
|
-
clearCache(): Promise<void>;
|
|
465
|
-
refreshCache(modelId: string): Promise<void>;
|
|
466
|
-
getCacheStats(): ICacheStats;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
declare class QueryFactory {
|
|
470
|
-
private static loader;
|
|
471
|
-
static setLoader(loader: SQLiteLoader<IDBRecord> | JSONLoader<IBaseJSONRecord>): void;
|
|
472
|
-
static createSQLiteBuilder<TData extends IDBRecord>(model: string, loader?: SQLiteLoader<TData>): ISQLiteQuery<TData>;
|
|
473
|
-
static createJSONBuilder<TData extends IBaseJSONRecord>(model: string, loader?: JSONLoader<TData>): IJSONQuery<TData>;
|
|
474
|
-
static createBuilder<TData extends IDBRecord | IBaseJSONRecord>(model: string, loader?: SQLiteLoader<TData & IDBRecord> | JSONLoader<TData & IBaseJSONRecord>): TData extends IDBRecord ? ISQLiteQuery<TData & IDBRecord> : IJSONQuery<TData & IBaseJSONRecord>;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
declare const loggers: {
|
|
478
|
-
cache: {
|
|
479
|
-
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
480
|
-
info: (message: string, data?: Record<string, unknown>) => void;
|
|
481
|
-
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
482
|
-
error: (message: string, data?: Record<string, unknown>) => void;
|
|
483
|
-
};
|
|
484
|
-
query: {
|
|
485
|
-
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
486
|
-
info: (message: string, data?: Record<string, unknown>) => void;
|
|
487
|
-
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
488
|
-
error: (message: string, data?: Record<string, unknown>) => void;
|
|
489
|
-
};
|
|
490
|
-
loader: {
|
|
491
|
-
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
492
|
-
info: (message: string, data?: Record<string, unknown>) => void;
|
|
493
|
-
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
494
|
-
error: (message: string, data?: Record<string, unknown>) => void;
|
|
495
|
-
};
|
|
496
|
-
sqlite: {
|
|
497
|
-
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
498
|
-
info: (message: string, data?: Record<string, unknown>) => void;
|
|
499
|
-
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
500
|
-
error: (message: string, data?: Record<string, unknown>) => void;
|
|
501
|
-
};
|
|
502
|
-
relation: {
|
|
503
|
-
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
504
|
-
info: (message: string, data?: Record<string, unknown>) => void;
|
|
505
|
-
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
506
|
-
error: (message: string, data?: Record<string, unknown>) => void;
|
|
507
|
-
};
|
|
508
|
-
translation: {
|
|
509
|
-
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
510
|
-
info: (message: string, data?: Record<string, unknown>) => void;
|
|
511
|
-
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
512
|
-
error: (message: string, data?: Record<string, unknown>) => void;
|
|
513
|
-
};
|
|
514
|
-
executor: {
|
|
515
|
-
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
516
|
-
info: (message: string, data?: Record<string, unknown>) => void;
|
|
517
|
-
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
518
|
-
error: (message: string, data?: Record<string, unknown>) => void;
|
|
519
|
-
};
|
|
520
|
-
default: {
|
|
521
|
-
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
522
|
-
info: (message: string, data?: Record<string, unknown>) => void;
|
|
523
|
-
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
524
|
-
error: (message: string, data?: Record<string, unknown>) => void;
|
|
525
|
-
};
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
declare class MemoryCache {
|
|
529
|
-
private cache;
|
|
530
|
-
private options;
|
|
531
|
-
private stats;
|
|
532
|
-
constructor(options?: IMemoryCacheOptions);
|
|
533
|
-
private calculateSize;
|
|
534
|
-
set<T>(key: string, data: T, ttl?: number): Promise<void>;
|
|
535
|
-
private findOldestKey;
|
|
536
|
-
get<T>(key: string): Promise<T | null>;
|
|
537
|
-
delete(key: string): Promise<void>;
|
|
538
|
-
clear(): Promise<void>;
|
|
539
|
-
private cleanupCache;
|
|
540
|
-
getStats(): IBaseCacheStats;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
interface ContentrainSDKOptions {
|
|
544
|
-
contentDir?: string;
|
|
545
|
-
databasePath?: string;
|
|
546
|
-
cache?: boolean;
|
|
547
|
-
ttl?: number;
|
|
548
|
-
maxCacheSize?: number;
|
|
549
|
-
defaultLocale?: string;
|
|
550
|
-
modelTTL?: Record<string, number>;
|
|
551
|
-
logger?: ILogger;
|
|
552
|
-
}
|
|
553
|
-
declare class ContentrainSDK {
|
|
554
|
-
private static loader;
|
|
555
|
-
private readonly options;
|
|
556
|
-
private readonly type;
|
|
557
|
-
constructor(type: LoaderType, options: ContentrainSDKOptions);
|
|
558
|
-
query<TData extends IDBRecord | IBaseJSONRecord>(model: string): TData extends IDBRecord ? ISQLiteQuery<TData & IDBRecord> : IJSONQuery<TData & IBaseJSONRecord>;
|
|
559
|
-
load<TData extends IDBRecord | IBaseJSONRecord>(model: string): Promise<TData>;
|
|
560
|
-
clearCache(): Promise<void>;
|
|
561
|
-
refreshCache(model: string): Promise<void>;
|
|
562
|
-
getCacheStats(): Promise<ICacheStats>;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
export { type ArrayOperator, ContentrainSDK, type ContentrainSDKOptions, type ContentrainStatus, type Filter, type IBaseJSONRecord, type IBaseLoader, type IBaseQueryBuilder, type IDBRecord, type IDBRelation, type IDBTranslationRecord, type IJSONContent, type IJSONContentFile, type IJSONContentManager, type IJSONLoaderOptions, type IJSONLoaderResult, type IJSONModelConfig, type IJSONQuery, type IJSONRelationConfig, type IJSONRelationManager, type ILogger, type ISQLiteConnection, type ISQLiteContent, type ISQLiteContentManager, type ISQLiteLoaderOptions, type ISQLiteLoaderResult, type ISQLiteQuery, type ISQLiteQueryBuilder, type ISQLiteRelationManager, type ISQLiteTranslationManager, type Include, type IncludeOptions, JSONLoader, type JSONOptions, type LoaderType, MemoryCache, type NumericOperator, type Operator, type Pagination, type QueryConfig, QueryFactory, type QueryOptions, type QueryResult, type RelationConfig, type RelationType, type SQLJoin, type SQLQuery, SQLiteLoader, type SQLiteOptions, type SQLiteQueryConfig, type Sort, type StringOperator, type SupportedLocale, loggers };
|
|
1
|
+
import { ContentStatus, ContentrainConfig, FieldDef, FieldType, ModelDefinition, ModelKind } from "@contentrain/types";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/query.d.ts
|
|
4
|
+
interface RelationMeta {
|
|
5
|
+
target: string | string[];
|
|
6
|
+
multi: boolean;
|
|
7
|
+
}
|
|
8
|
+
type RelationResolver = (model: string, id: string, locale: string | null) => Record<string, unknown> | undefined;
|
|
9
|
+
declare class QueryBuilder<T extends object> {
|
|
10
|
+
private _data;
|
|
11
|
+
private _locale;
|
|
12
|
+
private _filters;
|
|
13
|
+
private _sortField;
|
|
14
|
+
private _sortOrder;
|
|
15
|
+
private _limit;
|
|
16
|
+
private _offset;
|
|
17
|
+
private _includes;
|
|
18
|
+
private _relationMeta;
|
|
19
|
+
private _resolver;
|
|
20
|
+
private _defaultLocale;
|
|
21
|
+
constructor(data: Map<string, T[]>, relationMeta?: Record<string, RelationMeta>, resolver?: RelationResolver, defaultLocale?: string);
|
|
22
|
+
locale(lang: string): this;
|
|
23
|
+
where<K extends string & keyof T>(field: K, value: T[K]): this;
|
|
24
|
+
sort<K extends string & keyof T>(field: K, order?: 'asc' | 'desc'): this;
|
|
25
|
+
limit(n: number): this;
|
|
26
|
+
offset(n: number): this;
|
|
27
|
+
include(...fields: string[]): this;
|
|
28
|
+
all(): T[];
|
|
29
|
+
first(): T | undefined;
|
|
30
|
+
private _resolveData;
|
|
31
|
+
private _resolveIncludes;
|
|
32
|
+
private _resolveId;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/runtime/singleton.d.ts
|
|
36
|
+
declare class SingletonAccessor<T extends Record<string, unknown>> {
|
|
37
|
+
private _data;
|
|
38
|
+
private _locale;
|
|
39
|
+
private _defaultLocale;
|
|
40
|
+
private _includes;
|
|
41
|
+
private _relationMeta;
|
|
42
|
+
private _resolveEntry?;
|
|
43
|
+
constructor(data: Map<string, T>, defaultLocale?: string, relationMeta?: Record<string, {
|
|
44
|
+
target: string | string[];
|
|
45
|
+
multi: boolean;
|
|
46
|
+
}>, resolveEntry?: (model: string, id: string, locale: string) => unknown);
|
|
47
|
+
locale(lang: string): this;
|
|
48
|
+
include(...fields: string[]): this;
|
|
49
|
+
get(): T;
|
|
50
|
+
private _resolveIncludes;
|
|
51
|
+
private _resolveId;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/runtime/dictionary.d.ts
|
|
55
|
+
declare class DictionaryAccessor {
|
|
56
|
+
private _data;
|
|
57
|
+
private _locale;
|
|
58
|
+
private _defaultLocale;
|
|
59
|
+
constructor(data: Map<string, Record<string, string>>, defaultLocale?: string);
|
|
60
|
+
locale(lang: string): this;
|
|
61
|
+
get(): Record<string, string>;
|
|
62
|
+
get(key: string): string | undefined;
|
|
63
|
+
get(key: string, params: Record<string, string | number>): string;
|
|
64
|
+
private _resolveData;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/runtime/document.d.ts
|
|
68
|
+
declare class DocumentQuery<T extends object> {
|
|
69
|
+
private _data;
|
|
70
|
+
private _locale;
|
|
71
|
+
private _filters;
|
|
72
|
+
private _includes;
|
|
73
|
+
private _relationMeta;
|
|
74
|
+
private _resolver;
|
|
75
|
+
private _defaultLocale;
|
|
76
|
+
constructor(data: Map<string, T[]>, relationMeta?: Record<string, RelationMeta>, resolver?: RelationResolver, defaultLocale?: string);
|
|
77
|
+
locale(lang: string): this;
|
|
78
|
+
where<K extends string & keyof T>(field: K, value: T[K]): this;
|
|
79
|
+
include(...fields: string[]): this;
|
|
80
|
+
bySlug(slug: string): T | undefined;
|
|
81
|
+
all(): T[];
|
|
82
|
+
first(): T | undefined;
|
|
83
|
+
private _resolveData;
|
|
84
|
+
private _resolveIncludes;
|
|
85
|
+
private _resolveId;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/index.d.ts
|
|
89
|
+
/**
|
|
90
|
+
* Factory for framework SDK authors.
|
|
91
|
+
* Returns the generated client module loaded from .contentrain/client/.
|
|
92
|
+
*
|
|
93
|
+
* Usage (Nuxt composable):
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { createContentrainClient } from '@contentrain/query'
|
|
96
|
+
* const client = createContentrainClient()
|
|
97
|
+
* const posts = client.query('blog-post').locale('en').all()
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function createContentrainClient(projectRoot?: string): Promise<{
|
|
101
|
+
query: (model: string) => QueryBuilder<Record<string, unknown>>;
|
|
102
|
+
singleton: (model: string) => SingletonAccessor<Record<string, unknown>>;
|
|
103
|
+
dictionary: (model: string) => DictionaryAccessor;
|
|
104
|
+
document: (model: string) => DocumentQuery<Record<string, unknown>>;
|
|
105
|
+
}>;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { type ContentStatus, type ContentrainConfig, DictionaryAccessor, DocumentQuery, type FieldDef, type FieldType, type ModelDefinition, type ModelKind, QueryBuilder, type RelationMeta, type RelationResolver, SingletonAccessor, createContentrainClient, createContentrainClient as default };
|
|
108
|
+
//# sourceMappingURL=index.d.mts.map
|