ivue 1.6.1 → 2.0.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/README.md +171 -33
- package/bin/ivue.mjs +152 -0
- package/dist/Reactive.d.ts +131 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +88 -206
- package/dist/index.umd.js +1 -1
- package/lib/Reactive.ts +285 -114
- package/lib/__tests__/Reactive.vitest.spec.ts +1056 -0
- package/lib/__tests__/ReactiveAdversarial.vitest.spec.ts +182 -0
- package/lib/__tests__/coverage-completion.vitest.spec.ts +24 -0
- package/lib/__tests__/ivue.vitest.spec.ts +76 -19
- package/lib/index.ts +1 -2
- package/package.json +39 -10
- package/skills/ivue/SKILL.md +726 -0
- package/dist/ivue.d.ts +0 -310
package/dist/ivue.d.ts
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import type { ExtractPropTypes, Ref, ToRef } from 'vue';
|
|
2
|
-
import type { Ref as DemiRef } from 'vue-demi';
|
|
3
|
-
/** Types */
|
|
4
|
-
/**
|
|
5
|
-
* IVue core reactive instance type with an extended .toRefs() method added.
|
|
6
|
-
*/
|
|
7
|
-
export declare type IVue<T extends AnyClass> = InstanceType<T> & {
|
|
8
|
-
toRefs: IVueToRefsFn<T>;
|
|
9
|
-
clone: IVueClone<T>;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Type definition for `.clone()` method creates a deep clone of the ivue instance.
|
|
13
|
-
*/
|
|
14
|
-
export declare type IVueClone<T extends AnyClass> = (...cloneArgs: CloneArgsFor<InstanceType<T>>) => IVue<T>;
|
|
15
|
-
/**
|
|
16
|
-
* Type definition for `.toRefs()` method converts reactive class properties to composable .value properties.
|
|
17
|
-
* But if props = true OR unwrap = true is specified, the refs will be unwrapped refs to be able to be merged with the the root class properties without losing reactivity.
|
|
18
|
-
*/
|
|
19
|
-
/** Extract only non-method keys from a type */
|
|
20
|
-
declare type NonMethodKeys<T> = {
|
|
21
|
-
[K in keyof T]: T[K] extends AnyFn ? never : K;
|
|
22
|
-
}[keyof T];
|
|
23
|
-
/** Create a type with only data properties and accessors */
|
|
24
|
-
declare type DataProperties<T> = Pick<T, NonMethodKeys<T>>;
|
|
25
|
-
/**
|
|
26
|
-
* Simplified IVueToRefsFn that only works with data properties
|
|
27
|
-
*/
|
|
28
|
-
interface IVueToRefsFn<T extends AnyClass> {
|
|
29
|
-
<P extends keyof IVueRefs<InstanceType<T>>>(props: P[]): Pick<IVueRefs<InstanceType<T>>, P>;
|
|
30
|
-
<P extends keyof IVueRefs<InstanceType<T>>>(props: P[], unwrap: false): Pick<IVueRefs<InstanceType<T>>, P>;
|
|
31
|
-
<P extends keyof DataProperties<InstanceType<T>>>(props: P[], unwrap: true): Pick<DataProperties<InstanceType<T>>, P>;
|
|
32
|
-
(props: true): DataProperties<InstanceType<T>>;
|
|
33
|
-
(props: false): IVueRefs<InstanceType<T>>;
|
|
34
|
-
(): IVueRefs<InstanceType<T>>;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Converts a class properties to a composable .value Refs using ToRef vue type,
|
|
38
|
-
* also knows NOT to convert functions to .value Refs but to leave them as is.
|
|
39
|
-
*/
|
|
40
|
-
export declare type IVueRefs<T> = {
|
|
41
|
-
[K in keyof T as T[K] extends AnyFn ? never : K]: ToRef<T[K]>;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Unwraps Ref Recursively, helps resolve fully the bare value types of any type T
|
|
45
|
-
* because sometimes the Refs are returned as they are with `.value` from computeds,
|
|
46
|
-
* thus inferring nested ComputedRef<ComputedRef<ComputedRef<Ref>>> types, which
|
|
47
|
-
* are difficult to fully resolve to bare values without this utility.
|
|
48
|
-
* Also support Vue 3 Demi for vue-use library support.
|
|
49
|
-
*/
|
|
50
|
-
declare type UnwrapRefRecursively<T = any> = T extends Ref | DemiRef ? UnwrapRefRecursively<T['value']> : T;
|
|
51
|
-
/**
|
|
52
|
-
* Helper type for Use type, unwraps any type of Vue 3 composable return object down to its bare types.
|
|
53
|
-
*/
|
|
54
|
-
declare type UnwrapComposableRefs<T> = T extends Ref | DemiRef ? UnwrapRefRecursively<T> : {
|
|
55
|
-
[K in keyof T]: T[K] extends Ref | DemiRef ? UnwrapRefRecursively<T[K]> : T[K];
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Fully unwraps to bare value types any Vue 3 composable return definition type.
|
|
59
|
-
*/
|
|
60
|
-
export declare type Use<T = any> = T extends Ref | DemiRef ? UnwrapRefRecursively<T> : UnwrapComposableRefs<T extends AnyFn ? ReturnType<T> : T>;
|
|
61
|
-
/**
|
|
62
|
-
* Extracts object defined emit types by converting them to a plain interface.
|
|
63
|
-
*/
|
|
64
|
-
export declare type ExtractEmitTypes<T extends Record<string, any>> = UnionToIntersection<RecordToUnion<{
|
|
65
|
-
[K in keyof T]: (evt: K, ...args: Parameters<T[K]>) => void;
|
|
66
|
-
}>>;
|
|
67
|
-
/**
|
|
68
|
-
* Extract properties as all assigned properties because they have defaults.
|
|
69
|
-
*/
|
|
70
|
-
export declare type ExtractPropDefaultTypes<O> = {
|
|
71
|
-
[K in keyof O]: ValueOf<ExtractPropTypes<O>, K>;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Extend slots interface T with prefixed 'before--' & 'after--' slots to create fully extensible flexible slots.
|
|
75
|
-
*/
|
|
76
|
-
export declare type ExtendSlots<T> = PrefixKeys<T, 'before--'> & T & PrefixKeys<T, 'after--'>;
|
|
77
|
-
/** Helper Types. */
|
|
78
|
-
/**
|
|
79
|
-
* Any JavaScript function of any type.
|
|
80
|
-
*/
|
|
81
|
-
export declare type AnyFn = (...args: any[]) => any;
|
|
82
|
-
/**
|
|
83
|
-
* Any JavaScript class of any type.
|
|
84
|
-
*/
|
|
85
|
-
export declare type AnyClass = new (...args: any[]) => any;
|
|
86
|
-
/**
|
|
87
|
-
* Accessors map type.
|
|
88
|
-
*/
|
|
89
|
-
declare type Accessors = Map<string, PropertyDescriptor>;
|
|
90
|
-
/**
|
|
91
|
-
* Infer paramaters of a constructor function of a Class.
|
|
92
|
-
*/
|
|
93
|
-
export declare type InferredArgs<T> = T extends {
|
|
94
|
-
new (...args: infer P): any;
|
|
95
|
-
} ? P : never[];
|
|
96
|
-
/**
|
|
97
|
-
* Prefix keys of an interface T with a prefix P.
|
|
98
|
-
*/
|
|
99
|
-
export declare type PrefixKeys<T, P extends string | undefined = undefined> = {
|
|
100
|
-
[K in Extract<keyof T, string> as P extends string ? `${P}${K}` : K]: T[K];
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Get function arguments Parmeters<F> parameter by key K
|
|
104
|
-
*/
|
|
105
|
-
export declare type FnParameter<F extends AnyFn, K extends number> = Parameters<F>[K];
|
|
106
|
-
/**
|
|
107
|
-
* Convert Union Type to Intersection Type.
|
|
108
|
-
*/
|
|
109
|
-
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
110
|
-
/**
|
|
111
|
-
* Convert Record to Union Type.
|
|
112
|
-
*/
|
|
113
|
-
declare type RecordToUnion<T extends Record<string, any>> = T[keyof T];
|
|
114
|
-
/**
|
|
115
|
-
* Gets object T property by key [K].
|
|
116
|
-
*/
|
|
117
|
-
declare type ValueOf<T extends Record<any, any>, K> = T[K];
|
|
118
|
-
/**
|
|
119
|
-
* Props Map Value type.
|
|
120
|
-
*/
|
|
121
|
-
declare type PropsMapValue = {
|
|
122
|
-
allProps: Map<string, PropKind>;
|
|
123
|
-
onlyProps: Set<string>;
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Accessors and Methods map type.
|
|
127
|
-
*/
|
|
128
|
-
declare type AccessorsMethodsMap = {
|
|
129
|
-
accessors: Accessors;
|
|
130
|
-
methods: Set<string>;
|
|
131
|
-
};
|
|
132
|
-
export declare type IVueInstanceBase = {
|
|
133
|
-
init?: (...args: any[]) => void;
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* IVue static configuration interface.
|
|
137
|
-
*/
|
|
138
|
-
export interface IVueStaticConfig<T> {
|
|
139
|
-
ivueGlobalStore?: boolean;
|
|
140
|
-
ivueCloneByReference?: Set<keyof T>;
|
|
141
|
-
ivueDisableReactivity?: Set<keyof T>;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* IVue constructor type.
|
|
145
|
-
*/
|
|
146
|
-
export declare type IVueConstructor<T> = new (...args: any[]) => T;
|
|
147
|
-
/**
|
|
148
|
-
* IVue class type with static configuration.
|
|
149
|
-
*/
|
|
150
|
-
export declare type IVueClass<T> = IVueConstructor<T> & IVueStaticConfig<T>;
|
|
151
|
-
/**
|
|
152
|
-
* Get IVue init() method arguments IVueInitArgs<T>
|
|
153
|
-
*/
|
|
154
|
-
export declare type IVueInitArgs<T extends IVueInstanceBase> = T['init'] extends (...args: any[]) => any ? Parameters<T['init']> : never;
|
|
155
|
-
/**
|
|
156
|
-
* Get Interface's method keys MethodKeys<T>
|
|
157
|
-
*/
|
|
158
|
-
declare type MethodKeys<T> = {
|
|
159
|
-
[P in keyof T]: T[P] extends (...args: any[]) => any ? P : never;
|
|
160
|
-
}[keyof T];
|
|
161
|
-
/**
|
|
162
|
-
* Get Interface's property's function arguments Parameters<F>
|
|
163
|
-
*/
|
|
164
|
-
export declare type IFnParameters<T extends Record<any, any> | InstanceType<AnyClass>, K extends MethodKeys<T>> = Parameters<Extract<Required<Pick<T, K>>[K], AnyFn>>;
|
|
165
|
-
/**
|
|
166
|
-
* Get Interface's [T] property's [P] function arguments Parmeters<F> parameter by key [K]
|
|
167
|
-
*/
|
|
168
|
-
export declare type IFnParameter<T extends Record<any, any>, P extends keyof T, K extends number> = FnParameter<ValueOf<T, P>, K>;
|
|
169
|
-
export declare type IVueDeepCloneArgsMap = Map<AnyClass, any[]>;
|
|
170
|
-
declare type CloneArgsFor<T> = T extends {
|
|
171
|
-
init: (isClone: boolean, ...rest: infer A) => any;
|
|
172
|
-
} ? A : [];
|
|
173
|
-
/** Types End. */
|
|
174
|
-
export declare const IVUE_INSTANCE_SYMBOL: unique symbol;
|
|
175
|
-
/**
|
|
176
|
-
* Stores accessors for each class prototype processed by
|
|
177
|
-
* @see {getClassAccessorsMethodsMap}. Uses WeakMap to allow garbage collection
|
|
178
|
-
* of unused class accessors, ensuring memory efficiency in long-running applications.
|
|
179
|
-
*/
|
|
180
|
-
export declare let accessorsMethodsMaps: WeakMap<object, AccessorsMethodsMap>;
|
|
181
|
-
/**
|
|
182
|
-
* Property kind enum for distinguishing between data properties and accessors.
|
|
183
|
-
*/
|
|
184
|
-
declare const enum PropKind {
|
|
185
|
-
Data = 0,
|
|
186
|
-
Accessor = 2
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Stores properties for each class prototype processed by
|
|
190
|
-
* @see {getClassPropertiesAccessorsMap}. Uses WeakMap to allow garbage collection
|
|
191
|
-
* of unused class properties, ensuring memory efficiency in long-running applications.
|
|
192
|
-
*/
|
|
193
|
-
export declare let propertiesAccessorsMaps: WeakMap<object, PropsMapValue>;
|
|
194
|
-
/**
|
|
195
|
-
* Infinite Vue (ivue) class reactive initializer.
|
|
196
|
-
*
|
|
197
|
-
* Converts class instance to a reactive object,
|
|
198
|
-
* where accessors are converted to computeds.
|
|
199
|
-
*
|
|
200
|
-
* You can turn off computed behaviour by adding static
|
|
201
|
-
* ivue object and setting the getter props to false.
|
|
202
|
-
* class ClassName {
|
|
203
|
-
* static ivue = {
|
|
204
|
-
* getter: false
|
|
205
|
-
* }
|
|
206
|
-
* // .getter -> will be a standard JS non-computed getter
|
|
207
|
-
* get getter () { return 'hello world'; }
|
|
208
|
-
* }
|
|
209
|
-
*
|
|
210
|
-
* @param className Any Class
|
|
211
|
-
* @param args Class constructor arguments that you would pass to a `new AnyClass(args...)`
|
|
212
|
-
* @returns {IVue<T>}
|
|
213
|
-
*/
|
|
214
|
-
export declare const ivue: <T extends AnyClass>(className: T, ...args: InferredArgs<T>) => IVue<T>;
|
|
215
|
-
/**
|
|
216
|
-
* `iref()` is an alias for Vue ref() function but returns an unwrapped type without the .value
|
|
217
|
-
* `iref()` does not alter the behavior of ref(), but simply transforms the type to an unwrapped raw value.
|
|
218
|
-
* @param val T
|
|
219
|
-
* @returns {T} Ref but with type unwrapped
|
|
220
|
-
*/
|
|
221
|
-
export declare const iref: <T = any>(value?: T | undefined) => T;
|
|
222
|
-
/**
|
|
223
|
-
* `ishallowRef()` is an alias for Vue shallowRef() function but returns an unwrapped type without the .value
|
|
224
|
-
* `ishallowRef()` does not alter the behavior of shallowRef(), but simply transforms the type to an unwrapped raw value.
|
|
225
|
-
* @param val T
|
|
226
|
-
* @returns {T} ShallowRef but with type unwrapped
|
|
227
|
-
*/
|
|
228
|
-
export declare const ishallowRef: <T = any>(value?: T | undefined) => T;
|
|
229
|
-
/**
|
|
230
|
-
* `iuse()` is a helper function that unwraps any Vue 3 composable return type down to its bare types.
|
|
231
|
-
*
|
|
232
|
-
* It does not alter the behavior of the composable, but simply transforms the type to an unwrapped raw value.
|
|
233
|
-
*
|
|
234
|
-
* @param obj Any Vue 3 composable return type or any object or any type
|
|
235
|
-
* @returns {Use<T>} Composable with types unwrapped
|
|
236
|
-
*/
|
|
237
|
-
export declare const iuse: <T extends object>(obj: T) => Use<T>; /** Unwrap any other Object or any type down to its bare types. */
|
|
238
|
-
/**
|
|
239
|
-
* Vue props interface in defineComponent() style.
|
|
240
|
-
*/
|
|
241
|
-
export declare type VuePropsObject = Record<string, {
|
|
242
|
-
type: any;
|
|
243
|
-
default?: any;
|
|
244
|
-
required?: boolean;
|
|
245
|
-
}>;
|
|
246
|
-
/**
|
|
247
|
-
* Vue Props with default properties declared as existing and having values.
|
|
248
|
-
*/
|
|
249
|
-
export declare type VuePropsWithDefaults<T extends VuePropsObject> = {
|
|
250
|
-
[K in keyof T]: {
|
|
251
|
-
type: T[K]['type'];
|
|
252
|
-
default: T[K]['default'];
|
|
253
|
-
required?: boolean;
|
|
254
|
-
};
|
|
255
|
-
};
|
|
256
|
-
/**
|
|
257
|
-
* Determines if the value is a JavaScript Class.
|
|
258
|
-
* Note that class is a class function in JavaScript.
|
|
259
|
-
*
|
|
260
|
-
* @param val Any value
|
|
261
|
-
* @returns boolean If it's a JavaScript Class returns true
|
|
262
|
-
*/
|
|
263
|
-
export declare const isClass: (val: any) => boolean;
|
|
264
|
-
/**
|
|
265
|
-
* Creates props with defaults in defineComponent() style.
|
|
266
|
-
*
|
|
267
|
-
* Merge defaults regular object with Vue types object
|
|
268
|
-
* declared in defineComponent() style.
|
|
269
|
-
*
|
|
270
|
-
* This is made so that the defaults can be declared "as they are"
|
|
271
|
-
* without requiring objects to be function callbacks returning an object.
|
|
272
|
-
*
|
|
273
|
-
* // You don't need to wrap objects in () => ({ nest: { nest :{} } })
|
|
274
|
-
* // You can just delcare them normally.
|
|
275
|
-
* const defaults = {
|
|
276
|
-
* nest: {
|
|
277
|
-
* nest
|
|
278
|
-
* }
|
|
279
|
-
* }
|
|
280
|
-
*
|
|
281
|
-
* This function will create the Vue expected callbacks for Objects, Arrays & Classes
|
|
282
|
-
* but leave primitive properties and functions intact so that
|
|
283
|
-
* the final object is fully defineComponent() style compatible.
|
|
284
|
-
*
|
|
285
|
-
* @param defaults Regular object of default key -> values
|
|
286
|
-
* @param typedProps Props declared in defineComponent() style with type and possibly required declared, but without default
|
|
287
|
-
* @returns Props declared in defineComponent() style with all properties having default property declared.
|
|
288
|
-
*/
|
|
289
|
-
export declare const propsWithDefaults: <T extends VuePropsObject>(defaults: Record<string, any>, typedProps: T, deepCloneArgs?: IVueDeepCloneArgsMap | undefined) => VuePropsWithDefaults<T>;
|
|
290
|
-
/**
|
|
291
|
-
* Copies own properties (including symbols and non-enumerable) from source to target.
|
|
292
|
-
* Recursively deep clones values, but preserves getters/setters as-is.
|
|
293
|
-
*/
|
|
294
|
-
export declare const copyOwnProps: (source: any, target: any, deepCloneArgs: IVueDeepCloneArgsMap | undefined, seen: WeakMap<object, any>) => void;
|
|
295
|
-
export declare let activeDeepCloneArgsMap: WeakMap<AnyClass, IVueDeepCloneArgsMap>;
|
|
296
|
-
export declare const deepClone: (source: any, deepCloneArgs?: IVueDeepCloneArgsMap, seen?: WeakMap<object, any>) => any;
|
|
297
|
-
/**
|
|
298
|
-
* Clears the accessorsMethodsMaps, and propertiesAccessorsMaps WeakMaps.
|
|
299
|
-
* Useful for SSR scenarios where you want to reset the cache between requests.
|
|
300
|
-
* Also useful for testing purposes to ensure a clean state.
|
|
301
|
-
*/
|
|
302
|
-
export declare const clearCache: () => void;
|
|
303
|
-
/** Exported for testing purposes. */
|
|
304
|
-
export declare const __test__: {
|
|
305
|
-
copyOwnProps: (source: any, target: any, deepCloneArgs: IVueDeepCloneArgsMap | undefined, seen: WeakMap<object, any>) => void;
|
|
306
|
-
getClassAccessorsMethodsMap: (className: AnyClass) => AccessorsMethodsMap;
|
|
307
|
-
getClassPropertiesAccessorsMap: (obj: object) => PropsMapValue;
|
|
308
|
-
};
|
|
309
|
-
/** Necessary ivue.ts to be treated as a module. */
|
|
310
|
-
export {};
|