@coffer-org/sdk 1.3.0 → 1.4.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/fields.d.ts +18 -36
- package/dist/logger.d.ts +18 -0
- package/dist/logger.js +57 -0
- package/package.json +1 -1
package/dist/fields.d.ts
CHANGED
|
@@ -201,8 +201,7 @@ export declare function isJsonStored(field: FieldMeta | FieldClient): boolean;
|
|
|
201
201
|
export { LANGUAGES, SEX_OPTIONS, WEEKDAY_OPTIONS } from './fields/constants.ts';
|
|
202
202
|
export { parseUrl, buildUrl, hrefOf, type UrlValue } from './fields/url.ts';
|
|
203
203
|
export declare function applyMultiple(base: FieldMeta, multiple: boolean): FieldMeta;
|
|
204
|
-
export
|
|
205
|
-
}
|
|
204
|
+
export type StringOpts = FieldCoreOpts;
|
|
206
205
|
export declare function string(o: StringOpts & {
|
|
207
206
|
key: string;
|
|
208
207
|
}): FieldItem;
|
|
@@ -214,10 +213,8 @@ export declare function string(o: StringOpts & {
|
|
|
214
213
|
key?: undefined;
|
|
215
214
|
value?: undefined;
|
|
216
215
|
}): FieldMeta;
|
|
217
|
-
export
|
|
218
|
-
|
|
219
|
-
export interface LocalFileOpts extends LocalPathOpts {
|
|
220
|
-
}
|
|
216
|
+
export type LocalPathOpts = FieldCoreOpts;
|
|
217
|
+
export type LocalFileOpts = LocalPathOpts;
|
|
221
218
|
export declare function localDir(o: LocalPathOpts & {
|
|
222
219
|
key: string;
|
|
223
220
|
}): FieldItem;
|
|
@@ -240,8 +237,7 @@ export declare function localFile(o: LocalFileOpts & {
|
|
|
240
237
|
key?: undefined;
|
|
241
238
|
value?: undefined;
|
|
242
239
|
}): FieldMeta;
|
|
243
|
-
export
|
|
244
|
-
}
|
|
240
|
+
export type TextOpts = FieldCoreOpts;
|
|
245
241
|
export declare function text(o: TextOpts & {
|
|
246
242
|
key: string;
|
|
247
243
|
}): FieldItem;
|
|
@@ -275,8 +271,7 @@ export declare function smallText(o: TextOpts & {
|
|
|
275
271
|
key?: undefined;
|
|
276
272
|
value?: undefined;
|
|
277
273
|
}): FieldMeta;
|
|
278
|
-
export
|
|
279
|
-
}
|
|
274
|
+
export type RealOpts = FieldCoreOpts;
|
|
280
275
|
export declare function real(o: RealOpts & {
|
|
281
276
|
key: string;
|
|
282
277
|
}): FieldItem;
|
|
@@ -288,8 +283,7 @@ export declare function real(o: RealOpts & {
|
|
|
288
283
|
key?: undefined;
|
|
289
284
|
value?: undefined;
|
|
290
285
|
}): FieldMeta;
|
|
291
|
-
export
|
|
292
|
-
}
|
|
286
|
+
export type IntOpts = FieldCoreOpts;
|
|
293
287
|
export declare function int(o: IntOpts & {
|
|
294
288
|
key: string;
|
|
295
289
|
}): FieldItem;
|
|
@@ -301,8 +295,7 @@ export declare function int(o: IntOpts & {
|
|
|
301
295
|
key?: undefined;
|
|
302
296
|
value?: undefined;
|
|
303
297
|
}): FieldMeta;
|
|
304
|
-
export
|
|
305
|
-
}
|
|
298
|
+
export type DateOpts = FieldCoreOpts;
|
|
306
299
|
export declare function date(o: DateOpts & {
|
|
307
300
|
key: string;
|
|
308
301
|
}): FieldItem;
|
|
@@ -314,8 +307,7 @@ export declare function date(o: DateOpts & {
|
|
|
314
307
|
key?: undefined;
|
|
315
308
|
value?: undefined;
|
|
316
309
|
}): FieldMeta;
|
|
317
|
-
export
|
|
318
|
-
}
|
|
310
|
+
export type TimeOpts = FieldCoreOpts;
|
|
319
311
|
export declare function time(o: TimeOpts & {
|
|
320
312
|
key: string;
|
|
321
313
|
}): FieldItem;
|
|
@@ -327,8 +319,7 @@ export declare function time(o: TimeOpts & {
|
|
|
327
319
|
key?: undefined;
|
|
328
320
|
value?: undefined;
|
|
329
321
|
}): FieldMeta;
|
|
330
|
-
export
|
|
331
|
-
}
|
|
322
|
+
export type DateTimeOpts = FieldCoreOpts;
|
|
332
323
|
export declare function datetime(o: DateTimeOpts & {
|
|
333
324
|
key: string;
|
|
334
325
|
}): FieldItem;
|
|
@@ -340,8 +331,7 @@ export declare function datetime(o: DateTimeOpts & {
|
|
|
340
331
|
key?: undefined;
|
|
341
332
|
value?: undefined;
|
|
342
333
|
}): FieldMeta;
|
|
343
|
-
export
|
|
344
|
-
}
|
|
334
|
+
export type BooleanOpts = FieldCoreOpts;
|
|
345
335
|
export declare function boolean(o: BooleanOpts & {
|
|
346
336
|
key: string;
|
|
347
337
|
}): FieldItem;
|
|
@@ -353,8 +343,7 @@ export declare function boolean(o: BooleanOpts & {
|
|
|
353
343
|
key?: undefined;
|
|
354
344
|
value?: undefined;
|
|
355
345
|
}): FieldMeta;
|
|
356
|
-
export
|
|
357
|
-
}
|
|
346
|
+
export type TriStateOpts = FieldCoreOpts;
|
|
358
347
|
export declare function triState(o: TriStateOpts & {
|
|
359
348
|
key: string;
|
|
360
349
|
}): FieldItem;
|
|
@@ -398,8 +387,7 @@ export declare function relation(o: RelationOpts & {
|
|
|
398
387
|
value?: undefined;
|
|
399
388
|
}): FieldMeta;
|
|
400
389
|
export declare function bindSelectSourceZod(field: FieldMeta, values: string[]): void;
|
|
401
|
-
export
|
|
402
|
-
}
|
|
390
|
+
export type JsonOpts = FieldCoreOpts;
|
|
403
391
|
export declare function json(o: JsonOpts & {
|
|
404
392
|
key: string;
|
|
405
393
|
}): FieldItem;
|
|
@@ -439,8 +427,7 @@ export declare function measured(o: MeasuredOpts & {
|
|
|
439
427
|
key?: undefined;
|
|
440
428
|
value?: undefined;
|
|
441
429
|
}): FieldMeta;
|
|
442
|
-
export
|
|
443
|
-
}
|
|
430
|
+
export type MoneyOpts = FieldCoreOpts;
|
|
444
431
|
export declare function money(o: MoneyOpts & {
|
|
445
432
|
key: string;
|
|
446
433
|
}): FieldItem;
|
|
@@ -452,8 +439,7 @@ export declare function money(o: MoneyOpts & {
|
|
|
452
439
|
key?: undefined;
|
|
453
440
|
value?: undefined;
|
|
454
441
|
}): FieldMeta;
|
|
455
|
-
export
|
|
456
|
-
}
|
|
442
|
+
export type CodeFieldOpts = FieldCoreOpts;
|
|
457
443
|
export declare function code(o: CodeFieldOpts & {
|
|
458
444
|
key: string;
|
|
459
445
|
}): FieldItem;
|
|
@@ -465,8 +451,7 @@ export declare function code(o: CodeFieldOpts & {
|
|
|
465
451
|
key?: undefined;
|
|
466
452
|
value?: undefined;
|
|
467
453
|
}): FieldMeta;
|
|
468
|
-
export
|
|
469
|
-
}
|
|
454
|
+
export type GeoOpts = FieldCoreOpts;
|
|
470
455
|
export declare function geo(o: GeoOpts & {
|
|
471
456
|
key: string;
|
|
472
457
|
}): FieldItem;
|
|
@@ -518,8 +503,7 @@ export declare function period(o: PeriodOpts & {
|
|
|
518
503
|
key?: undefined;
|
|
519
504
|
value?: undefined;
|
|
520
505
|
}): FieldMeta;
|
|
521
|
-
export
|
|
522
|
-
}
|
|
506
|
+
export type FileOpts = FieldCoreOpts;
|
|
523
507
|
export type ImageOpts = FileOpts;
|
|
524
508
|
export declare function file(o: FileOpts & {
|
|
525
509
|
key: string;
|
|
@@ -629,8 +613,7 @@ export interface KeyValueOpts extends FieldCoreOpts {
|
|
|
629
613
|
export declare function keyValue(raw: KeyValueOpts & {
|
|
630
614
|
key: string;
|
|
631
615
|
}): GroupEl;
|
|
632
|
-
export
|
|
633
|
-
}
|
|
616
|
+
export type RangeOpts = FieldCoreOpts;
|
|
634
617
|
export declare function numberRange(o: RangeOpts & {
|
|
635
618
|
key: string;
|
|
636
619
|
}): FieldItem;
|
|
@@ -653,8 +636,7 @@ export declare function realRange(o: RangeOpts & {
|
|
|
653
636
|
key?: undefined;
|
|
654
637
|
value?: undefined;
|
|
655
638
|
}): FieldMeta;
|
|
656
|
-
export
|
|
657
|
-
}
|
|
639
|
+
export type EmbedOpts = FieldCoreOpts;
|
|
658
640
|
export declare function embed(o: EmbedOpts & {
|
|
659
641
|
key: string;
|
|
660
642
|
}): FieldItem;
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface Logger {
|
|
2
|
+
debug(msg: string, extra?: Record<string, unknown>): void;
|
|
3
|
+
info(msg: string, extra?: Record<string, unknown>): void;
|
|
4
|
+
warn(msg: string, extra?: unknown): void;
|
|
5
|
+
error(msg: string, extra?: unknown): void;
|
|
6
|
+
}
|
|
7
|
+
export interface RootLogger {
|
|
8
|
+
child(bindings: Record<string, unknown>): RootLogger;
|
|
9
|
+
debug(obj: unknown, msg?: string): void;
|
|
10
|
+
info(obj: unknown, msg?: string): void;
|
|
11
|
+
warn(obj: unknown, msg?: string): void;
|
|
12
|
+
error(obj: unknown, msg?: string): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const LOG_LEVEL: string;
|
|
15
|
+
export declare function parseTags(raw: string | undefined): Set<string>;
|
|
16
|
+
export declare function tagEnabled(tag: string, tags: Set<string>): boolean;
|
|
17
|
+
export declare function setRootLogger(l: RootLogger | null): void;
|
|
18
|
+
export declare function getLogger(tag: string): Logger;
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const LEVEL_NUM = { trace: 10, debug: 20, info: 30, warn: 40, error: 50 };
|
|
2
|
+
export const LOG_LEVEL = process.env.LOG_LEVEL ?? 'info';
|
|
3
|
+
export function parseTags(raw) {
|
|
4
|
+
return new Set((raw ?? '')
|
|
5
|
+
.split(',')
|
|
6
|
+
.map((t) => t.trim())
|
|
7
|
+
.filter(Boolean));
|
|
8
|
+
}
|
|
9
|
+
export function tagEnabled(tag, tags) {
|
|
10
|
+
return tags.size === 0 || tags.has(tag);
|
|
11
|
+
}
|
|
12
|
+
const TAGS = parseTags(process.env.LOG_TAGS);
|
|
13
|
+
const CONSOLE_THRESHOLD = LEVEL_NUM[LOG_LEVEL] ?? LEVEL_NUM.info;
|
|
14
|
+
let root = null;
|
|
15
|
+
const children = new Map();
|
|
16
|
+
export function setRootLogger(l) {
|
|
17
|
+
root = l;
|
|
18
|
+
children.clear();
|
|
19
|
+
}
|
|
20
|
+
export function getLogger(tag) {
|
|
21
|
+
const emit = (level, msg, extra) => {
|
|
22
|
+
if (!tagEnabled(tag, TAGS))
|
|
23
|
+
return;
|
|
24
|
+
if (root) {
|
|
25
|
+
let child = children.get(tag);
|
|
26
|
+
if (!child) {
|
|
27
|
+
child = root.child({ tag });
|
|
28
|
+
children.set(tag, child);
|
|
29
|
+
}
|
|
30
|
+
if (extra === undefined)
|
|
31
|
+
child[level](msg);
|
|
32
|
+
else if (extra instanceof Error)
|
|
33
|
+
child[level]({ err: extra }, msg);
|
|
34
|
+
else if (typeof extra === 'object')
|
|
35
|
+
child[level](extra, msg);
|
|
36
|
+
else
|
|
37
|
+
child[level]({ err: extra }, msg);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (LEVEL_NUM[level] < CONSOLE_THRESHOLD)
|
|
41
|
+
return;
|
|
42
|
+
const line = `[${tag}] ${msg}`;
|
|
43
|
+
const rest = extra === undefined ? [] : [extra];
|
|
44
|
+
if (level === 'error')
|
|
45
|
+
console.error(line, ...rest);
|
|
46
|
+
else if (level === 'warn')
|
|
47
|
+
console.warn(line, ...rest);
|
|
48
|
+
else
|
|
49
|
+
console.log(line, ...rest);
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
debug: (msg, extra) => emit('debug', msg, extra),
|
|
53
|
+
info: (msg, extra) => emit('info', msg, extra),
|
|
54
|
+
warn: (msg, extra) => emit('warn', msg, extra),
|
|
55
|
+
error: (msg, extra) => emit('error', msg, extra),
|
|
56
|
+
};
|
|
57
|
+
}
|