@ztimson/utils 0.21.0 → 0.21.2
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/array.d.ts +7 -0
- package/dist/aset.d.ts +6 -6
- package/dist/cache.d.ts +17 -5
- package/dist/emitter.d.ts +5 -5
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +438 -370
- package/dist/index.mjs.map +1 -1
- package/dist/logger.d.ts +6 -7
- package/dist/misc.d.ts +11 -0
- package/dist/path-events.d.ts +145 -0
- package/dist/time.d.ts +2 -2
- package/package.json +1 -1
- package/dist/makeArray.ts +0 -7
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ASet } from './aset.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Available methods:
|
|
5
|
+
* * - All/Wildcard
|
|
6
|
+
* n - None
|
|
7
|
+
* c - Create
|
|
8
|
+
* r - Read
|
|
9
|
+
* u - Update
|
|
10
|
+
* d - Delete
|
|
11
|
+
* x - Execute
|
|
12
|
+
*/
|
|
13
|
+
export type Method = '*' | 'n' | 'c' | 'r' | 'u' | 'd' | 'x';
|
|
14
|
+
/**
|
|
15
|
+
* Shorthand for creating Event from a string
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const event: Event = PE`users/system:*`;
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param {TemplateStringsArray} str String that will be parsed into Event
|
|
23
|
+
* @param {string} args
|
|
24
|
+
* @return {PathEvent} Event object
|
|
25
|
+
*/
|
|
26
|
+
export declare function PE(str: TemplateStringsArray, ...args: string[]): PathEvent;
|
|
27
|
+
/**
|
|
28
|
+
* Shorthand for creating Event strings, ensures paths are correct
|
|
29
|
+
*
|
|
30
|
+
* @param {TemplateStringsArray} str
|
|
31
|
+
* @param {string} args
|
|
32
|
+
* @return {string}
|
|
33
|
+
* @constructor
|
|
34
|
+
*/
|
|
35
|
+
export declare function PES(str: TemplateStringsArray, ...args: any[]): string;
|
|
36
|
+
export declare class PathError extends Error {
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A event broken down into its core components for easy processing
|
|
40
|
+
* Event Structure: `module/path/name:property:method`
|
|
41
|
+
* Example: `users/system:crud` or `storage/some/path/file.txt:r`
|
|
42
|
+
*/
|
|
43
|
+
export declare class PathEvent {
|
|
44
|
+
/** First directory in path */
|
|
45
|
+
module: string;
|
|
46
|
+
/** Entire path, including the module & name */
|
|
47
|
+
fullPath: string;
|
|
48
|
+
/** Path including the name, excluding the module */
|
|
49
|
+
path: string;
|
|
50
|
+
/** Last sagment of path */
|
|
51
|
+
name: string;
|
|
52
|
+
/** List of methods */
|
|
53
|
+
methods: ASet<Method>;
|
|
54
|
+
/** All/Wildcard specified */
|
|
55
|
+
get all(): boolean;
|
|
56
|
+
set all(v: boolean);
|
|
57
|
+
/** None specified */
|
|
58
|
+
get none(): boolean;
|
|
59
|
+
set none(v: boolean);
|
|
60
|
+
/** Create method specified */
|
|
61
|
+
get create(): boolean;
|
|
62
|
+
set create(v: boolean);
|
|
63
|
+
/** Read method specified */
|
|
64
|
+
get read(): boolean;
|
|
65
|
+
set read(v: boolean);
|
|
66
|
+
/** Update method specified */
|
|
67
|
+
get update(): boolean;
|
|
68
|
+
set update(v: boolean);
|
|
69
|
+
/** Delete method specified */
|
|
70
|
+
get delete(): boolean;
|
|
71
|
+
set delete(v: boolean);
|
|
72
|
+
constructor(Event: string | PathEvent);
|
|
73
|
+
/**
|
|
74
|
+
* Combine multiple events into one parsed object. Longest path takes precedent, but all subsequent methods are
|
|
75
|
+
* combined until a "none" is reached
|
|
76
|
+
*
|
|
77
|
+
* @param {string | PathEvent} paths Events as strings or pre-parsed
|
|
78
|
+
* @return {PathEvent} Final combined permission
|
|
79
|
+
*/
|
|
80
|
+
static combine(...paths: (string | PathEvent)[]): PathEvent;
|
|
81
|
+
/**
|
|
82
|
+
* Squash 2 sets of paths & return true if any overlap is found
|
|
83
|
+
*
|
|
84
|
+
* @param {string | PathEvent | (string | PathEvent)[]} target Array of Events as strings or pre-parsed
|
|
85
|
+
* @param has Target must have at least one of these path
|
|
86
|
+
* @return {boolean} Whether there is any overlap
|
|
87
|
+
*/
|
|
88
|
+
static has(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Squash 2 sets of paths & return true if the target has all paths
|
|
91
|
+
*
|
|
92
|
+
* @param {string | PathEvent | (string | PathEvent)[]} target Array of Events as strings or pre-parsed
|
|
93
|
+
* @param has Target must have all these paths
|
|
94
|
+
* @return {boolean} Whether there is any overlap
|
|
95
|
+
*/
|
|
96
|
+
static hasAll(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Same as `has` but raises an error if there is no overlap
|
|
99
|
+
*
|
|
100
|
+
* @param {string | string[]} target Array of Events as strings or pre-parsed
|
|
101
|
+
* @param has Target must have at least one of these path
|
|
102
|
+
*/
|
|
103
|
+
static hasFatal(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): void;
|
|
104
|
+
/**
|
|
105
|
+
* Same as `hasAll` but raises an error if the target is missing any paths
|
|
106
|
+
*
|
|
107
|
+
* @param {string | string[]} target Array of Events as strings or pre-parsed
|
|
108
|
+
* @param has Target must have all these paths
|
|
109
|
+
*/
|
|
110
|
+
static hasAllFatal(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): void;
|
|
111
|
+
/**
|
|
112
|
+
* Create event string from its components
|
|
113
|
+
*
|
|
114
|
+
* @param {string | string[]} path Event path
|
|
115
|
+
* @param {Method} methods Event method
|
|
116
|
+
* @return {string} String representation of Event
|
|
117
|
+
*/
|
|
118
|
+
static toString(path: string | string[], methods: Method | Method[]): string;
|
|
119
|
+
/**
|
|
120
|
+
* Create event string from its components
|
|
121
|
+
*
|
|
122
|
+
* @return {string} String representation of Event
|
|
123
|
+
*/
|
|
124
|
+
toString(): string;
|
|
125
|
+
}
|
|
126
|
+
export type PathListener = (event: PathEvent, ...args: any[]) => any;
|
|
127
|
+
export type PathUnsubscribe = () => void;
|
|
128
|
+
export interface IPathEventEmitter {
|
|
129
|
+
emit(event: string, ...args: any[]): void;
|
|
130
|
+
off(listener: PathListener): void;
|
|
131
|
+
on(event: string, listener: PathListener): PathUnsubscribe;
|
|
132
|
+
once(event: string, listener?: PathListener): Promise<any>;
|
|
133
|
+
relayEvents(emitter: PathEventEmitter): void;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Event emitter that uses paths allowing listeners to listen to different combinations of modules, paths & methods
|
|
137
|
+
*/
|
|
138
|
+
export declare class PathEventEmitter implements IPathEventEmitter {
|
|
139
|
+
private listeners;
|
|
140
|
+
emit(event: string | PathEvent, ...args: any[]): void;
|
|
141
|
+
off(listener: PathListener): void;
|
|
142
|
+
on(event: string | string[], listener: PathListener): PathUnsubscribe;
|
|
143
|
+
once(event: string | string[], listener?: PathListener): Promise<any>;
|
|
144
|
+
relayEvents(emitter: IPathEventEmitter): void;
|
|
145
|
+
}
|
package/dist/time.d.ts
CHANGED
|
@@ -24,14 +24,14 @@ export declare function sleep(ms: number): Promise<void>;
|
|
|
24
24
|
* ```js
|
|
25
25
|
* let loading = true;
|
|
26
26
|
* setTimeout(() => wait = false, 1000);
|
|
27
|
-
* await
|
|
27
|
+
* await sleepWhile(() => loading); // Won't continue until loading flag is false
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
30
30
|
* @param {() => boolean | Promise<boolean>} fn Return true to continue
|
|
31
31
|
* @param {number} checkInterval Run function ever x milliseconds
|
|
32
32
|
* @return {Promise<void>} Callback when sleep is over
|
|
33
33
|
*/
|
|
34
|
-
export declare function
|
|
34
|
+
export declare function sleepWhile(fn: () => boolean | Promise<boolean>, checkInterval?: number): Promise<void>;
|
|
35
35
|
/**
|
|
36
36
|
* Calculate the number of milliseconds until date/time
|
|
37
37
|
*
|
package/package.json
CHANGED