@cleanweb/oore 2.0.0-alpha.33 → 2.0.0-alpha.35

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.
Files changed (134) hide show
  1. package/build/base/index.d.ts +3 -3
  2. package/build/base/index.js +19 -3
  3. package/build/base/merged-state.d.ts +1 -0
  4. package/build/base/merged-state.js +58 -30
  5. package/build/base/methods.d.ts +6 -5
  6. package/build/base/methods.js +28 -19
  7. package/build/base/state/class-types.d.ts +2 -2
  8. package/build/base/state/class-types.js +2 -1
  9. package/build/base/state/class.d.ts +1 -1
  10. package/build/base/state/class.js +72 -45
  11. package/build/base/state/hook-types.d.ts +1 -1
  12. package/build/base/state/hook-types.js +2 -1
  13. package/build/base/state/hooks.d.ts +1 -1
  14. package/build/base/state/hooks.js +16 -8
  15. package/build/base/state/index.d.ts +6 -5
  16. package/build/base/state/index.js +32 -3
  17. package/build/classy/class/index.d.ts +5 -18
  18. package/build/classy/class/index.js +87 -98
  19. package/build/classy/class/types/extractor.d.ts +1 -1
  20. package/build/classy/class/types/extractor.js +2 -1
  21. package/build/classy/class/utils/function-name.js +5 -1
  22. package/build/classy/index.d.ts +3 -3
  23. package/build/classy/index.js +19 -3
  24. package/build/classy/instance/index.d.ts +4 -4
  25. package/build/classy/instance/index.js +88 -58
  26. package/build/classy/instance/mount-callbacks.d.ts +1 -1
  27. package/build/classy/instance/mount-callbacks.js +12 -8
  28. package/build/classy/instance/types/hook.d.ts +1 -1
  29. package/build/classy/instance/types/hook.js +2 -1
  30. package/build/classy/logic/index.d.ts +2 -2
  31. package/build/classy/logic/index.js +32 -22
  32. package/build/classy/logic/types/hook.d.ts +1 -1
  33. package/build/classy/logic/types/hook.js +2 -1
  34. package/build/docs-src/api/base-classes.d.ts +3 -3
  35. package/build/docs-src/api/base-classes.js +9 -3
  36. package/build/docs-src/api/index.d.ts +8 -8
  37. package/build/docs-src/api/index.js +39 -8
  38. package/build/docs-src/api/references.d.ts +5 -5
  39. package/build/docs-src/api/references.js +31 -5
  40. package/build/globals.d.ts +83 -130
  41. package/build/globals.js +4 -0
  42. package/build/helpers/errors.js +5 -1
  43. package/build/helpers/index.d.ts +4 -7
  44. package/build/helpers/index.js +23 -8
  45. package/build/helpers/mount-state.js +10 -6
  46. package/build/helpers/rerender.js +16 -12
  47. package/build/helpers/type-guards.js +6 -2
  48. package/build/helpers/use-component/index.d.ts +1 -1
  49. package/build/helpers/use-component/index.js +9 -5
  50. package/build/helpers/use-component/types.js +2 -1
  51. package/build/index.d.ts +4 -3
  52. package/build/index.js +19 -3
  53. package/build/slots/hook.d.ts +2 -2
  54. package/build/slots/hook.js +78 -44
  55. package/build/slots/index.d.ts +1 -1
  56. package/build/slots/index.js +17 -1
  57. package/build/slots/types.d.ts +14 -11
  58. package/build/slots/types.js +2 -1
  59. package/build/tsconfig.json +6 -9
  60. package/package.json +11 -31
  61. package/build/_cjs/base/index.d.ts +0 -3
  62. package/build/_cjs/base/index.js +0 -19
  63. package/build/_cjs/base/merged-state.d.ts +0 -19
  64. package/build/_cjs/base/merged-state.js +0 -60
  65. package/build/_cjs/base/methods.d.ts +0 -58
  66. package/build/_cjs/base/methods.js +0 -95
  67. package/build/_cjs/base/state/class-types.d.ts +0 -20
  68. package/build/_cjs/base/state/class-types.js +0 -2
  69. package/build/_cjs/base/state/class.d.ts +0 -69
  70. package/build/_cjs/base/state/class.js +0 -129
  71. package/build/_cjs/base/state/hook-types.d.ts +0 -32
  72. package/build/_cjs/base/state/hook-types.js +0 -2
  73. package/build/_cjs/base/state/hooks.d.ts +0 -12
  74. package/build/_cjs/base/state/hooks.js +0 -41
  75. package/build/_cjs/base/state/index.d.ts +0 -8
  76. package/build/_cjs/base/state/index.js +0 -34
  77. package/build/_cjs/classy/class/index.d.ts +0 -128
  78. package/build/_cjs/classy/class/index.js +0 -176
  79. package/build/_cjs/classy/class/types/extractor.d.ts +0 -5
  80. package/build/_cjs/classy/class/types/extractor.js +0 -2
  81. package/build/_cjs/classy/class/utils/function-name.d.ts +0 -2
  82. package/build/_cjs/classy/class/utils/function-name.js +0 -17
  83. package/build/_cjs/classy/index.d.ts +0 -3
  84. package/build/_cjs/classy/index.js +0 -19
  85. package/build/_cjs/classy/instance/index.d.ts +0 -144
  86. package/build/_cjs/classy/instance/index.js +0 -177
  87. package/build/_cjs/classy/instance/mount-callbacks.d.ts +0 -5
  88. package/build/_cjs/classy/instance/mount-callbacks.js +0 -30
  89. package/build/_cjs/classy/instance/types/hook.d.ts +0 -13
  90. package/build/_cjs/classy/instance/types/hook.js +0 -2
  91. package/build/_cjs/classy/logic/index.d.ts +0 -116
  92. package/build/_cjs/classy/logic/index.js +0 -123
  93. package/build/_cjs/classy/logic/types/hook.d.ts +0 -16
  94. package/build/_cjs/classy/logic/types/hook.js +0 -2
  95. package/build/_cjs/docs-src/api/base-classes.d.ts +0 -3
  96. package/build/_cjs/docs-src/api/base-classes.js +0 -9
  97. package/build/_cjs/docs-src/api/index.d.ts +0 -13
  98. package/build/_cjs/docs-src/api/index.js +0 -44
  99. package/build/_cjs/docs-src/api/references.d.ts +0 -5
  100. package/build/_cjs/docs-src/api/references.js +0 -31
  101. package/build/_cjs/helpers/debounce/index.d.ts +0 -55
  102. package/build/_cjs/helpers/debounce/index.js +0 -111
  103. package/build/_cjs/helpers/debounce/react-state.d.ts +0 -13
  104. package/build/_cjs/helpers/debounce/react-state.js +0 -30
  105. package/build/_cjs/helpers/errors.d.ts +0 -10
  106. package/build/_cjs/helpers/errors.js +0 -21
  107. package/build/_cjs/helpers/index.d.ts +0 -16
  108. package/build/_cjs/helpers/index.js +0 -34
  109. package/build/_cjs/helpers/mount-state.d.ts +0 -5
  110. package/build/_cjs/helpers/mount-state.js +0 -25
  111. package/build/_cjs/helpers/object-gate.d.ts +0 -74
  112. package/build/_cjs/helpers/object-gate.js +0 -67
  113. package/build/_cjs/helpers/rerender.d.ts +0 -24
  114. package/build/_cjs/helpers/rerender.js +0 -42
  115. package/build/_cjs/helpers/type-guards.d.ts +0 -1
  116. package/build/_cjs/helpers/type-guards.js +0 -8
  117. package/build/_cjs/helpers/use-component/index.d.ts +0 -6
  118. package/build/_cjs/helpers/use-component/index.js +0 -17
  119. package/build/_cjs/helpers/use-component/types.d.ts +0 -22
  120. package/build/_cjs/helpers/use-component/types.js +0 -2
  121. package/build/_cjs/index.d.ts +0 -3
  122. package/build/_cjs/index.js +0 -19
  123. package/build/_cjs/slots/hook.d.ts +0 -20
  124. package/build/_cjs/slots/hook.js +0 -147
  125. package/build/_cjs/slots/index.d.ts +0 -1
  126. package/build/_cjs/slots/index.js +0 -17
  127. package/build/_cjs/slots/types.d.ts +0 -128
  128. package/build/_cjs/slots/types.js +0 -2
  129. package/build/helpers/debounce/index.d.ts +0 -55
  130. package/build/helpers/debounce/index.js +0 -107
  131. package/build/helpers/debounce/react-state.d.ts +0 -13
  132. package/build/helpers/debounce/react-state.js +0 -27
  133. package/build/helpers/object-gate.d.ts +0 -74
  134. package/build/helpers/object-gate.js +0 -64
@@ -1,128 +0,0 @@
1
- import type { ReactElement, ReactNode, ComponentType, JSX } from 'react';
2
- /** @todo ComponentType force children to be ReactNode, but custom components can have any children type. */
3
- type JSXTagLike = string | keyof JSX.IntrinsicElements | ComponentType<any>;
4
- /** This fixes overly narrow T type used by React's ComponentProps type. */
5
- export type ComponentProps<T extends JSXTagLike> = (T extends ComponentType<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : {});
6
- export type TSlotName = keyof any;
7
- export type TSlotAlias = keyof any;
8
- /**
9
- * A map of slot aliases to actual {@link SlotComponent}s.
10
- *
11
- * The `useSlots` hook will create a corresponding key for
12
- * each alias in this record to hold any `ReactNode`s rendered for that slot.
13
- */
14
- export type TSlotsRecord<TKey extends TSlotAlias = TSlotAlias> = {
15
- [Key in TKey]: SlotComponent<string | ComponentType<any>>;
16
- };
17
- export type DisplayNamedComponent<TComponent extends ComponentType<any> = ComponentType<any>, TName extends string = string> = TComponent & {
18
- displayName: TName;
19
- };
20
- interface ISlotConfig<TName> {
21
- slotName?: TName;
22
- }
23
- /**
24
- * A child component used to insert content into a specific slot in the parent component.
25
- * This can either be a string, or a React component with a `slotName` property.
26
- *
27
- * > `displayName` is no longer supported as a fallback for `slotName`.
28
- *
29
- * ### Strings
30
- * For strings, they are treated by React a native tags. This lets you use custom strings
31
- * as if you are rendering a custom Web Component, or simply handle specific HTML tags in a specific way.
32
- *
33
- * If using a custom string, you will want to handle it in the parent component by simply forwarding the slot's
34
- * props to an actual element of your choice.
35
- *
36
- * So consumers may pass the following as `children`.
37
- * ```jsx
38
- * <option-slot>Click</option-slot>
39
- * ```
40
- * and you can map that to
41
- * ```jsx
42
- * <button
43
- * {...slotNodes.Option[0].props}
44
- * type="button"
45
- * />
46
- * ```
47
- *
48
- * ### React Components
49
- * For slot components that are actual React components, the parent can simply
50
- * render the slot node directly.
51
- *
52
- * So consumers may pass the following as `children`.
53
- * ```jsx
54
- * <Parent.Slots.Content>
55
- * Some awesome content.
56
- * </Parent.Slots.Content>
57
- * ```
58
- * and you can map that to
59
- * ```jsx
60
- * return <>
61
- * <h1>Title</h1>
62
- * {slotNodes.Content}
63
- * <footer>Powered by oore</footer>
64
- * </>
65
- * ```
66
- *
67
- * This means `Parent.Slots.Content` must be defined as a proper React component
68
- * and is solely responsible for doing something with the `"Some awesome content."`
69
- * which was passed into it as children.
70
- *
71
- * This is unlike the string version where the parent component
72
- * extracts the props passed to the slot and handles
73
- * what the slot actually renders.
74
- */
75
- export type SlotComponent<TComponent extends JSXTagLike = ComponentType<any>, TName extends TSlotName = TSlotName> = (TComponent extends string ? TComponent : TComponent & ISlotConfig<TName>);
76
- /**
77
- * A parent component which accepts content that can be grouped into predefined slots.
78
- * By convention, it should have a `slots` property which is a {@link TSlotsRecord}.
79
- *
80
- * This allows consumers access the predefined slot components
81
- * directly from the parent component itself,
82
- * through an alias that is easy to remember.
83
- */
84
- export type SlottedComponent<TOwner extends object = ComponentType<any>, TSlots extends TSlotsRecord = TSlotsRecord> = TOwner & {
85
- Slots: TSlots;
86
- requiredSlotAliases?: Array<keyof TSlots>;
87
- };
88
- export type TypedNode<P, T extends JSXTagLike> = Omit<ReactElement<P>, 'type'> & {
89
- type: T;
90
- };
91
- export type TSlotNode<TSlotted extends SlottedComponent, Key extends keyof TSlotted['Slots'] = keyof TSlotted['Slots']> = (TypedNode<ComponentProps<TSlotted['Slots'][Key]>, TSlotted['Slots'][Key]>);
92
- /**
93
- * A record of slot aliases mapped to the corresponding `ReactNode`(s)
94
- * to be rendered for that slot.
95
- */
96
- export type TSlotNodes<TSlotted extends SlottedComponent> = {
97
- [Key in keyof TSlotted['Slots']]?: Array<TSlotNode<TSlotted, Key>>;
98
- };
99
- export type TUseSlotsResult<TSlotted extends SlottedComponent> = Readonly<[
100
- /**
101
- * A record of slot aliases to their corresponding React nodes.
102
- * Each alias maps to an array of one or more React nodes that were passed
103
- * as children for that slot.
104
- *
105
- * If a slot was not rendered in `children`, it's alias will be `undefined` in this object.
106
- */
107
- slotNodes: TSlotNodes<TSlotted>,
108
- /**
109
- * Valid React nodes passed as children which did not match any of the
110
- * predefined slots.
111
- */
112
- unmatchedChildren: ReactNode[],
113
- /**
114
- * Items included in `children` which are not valid React nodes.
115
- */
116
- invalidChildren: any[]
117
- ]>;
118
- export interface IUseSlots {
119
- <TSlotted extends SlottedComponent>(
120
- /**
121
- * Your component's `children` prop.
122
- * The nodes it contains will be categorized and
123
- * grouped according to the predefined {@link slotComponents}.
124
- */
125
- children: ReactNode, Caller: TSlotted): TUseSlotsResult<TSlotted>;
126
- }
127
- export type PotentialSlotComponent = string | SlotComponent | ComponentType<any>;
128
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,55 +0,0 @@
1
- interface IDebouncedFunction<TFunc extends AnyFunction> {
2
- (...args: Parameters<TFunc>): Promise<ReturnType<TFunc>>;
3
- /**
4
- * Called internally to trigger the callback with the most recent args
5
- * after the delay expires. Can be used to manually trigger the callback
6
- * before the normal delay time. If no pending call exists, flush() becomes a no-op.
7
- */
8
- flush: (isEager?: true) => void;
9
- }
10
- export interface IDelayConfig {
11
- /**
12
- * A non-zero delay in milliseconds.
13
- * @default 0
14
- */
15
- delay?: number;
16
- /**
17
- * The 'last-call' value specifies that the timer should be applied from the time of the most recent call.
18
- * That means each new call while a delay is active will reset the timer, thereby extending the delay.
19
- * In other words, it is a "time after inactivity" delay.
20
- * Specifying 'first-call' instead will make it use a "time after initial call" delay strategy.
21
- */
22
- anchor?: 'first-call' | 'last-call';
23
- /**
24
- * Controls eager execution behavior:
25
- * - `false`: Initial call waits for the delay period before executing.
26
- * - `'no-queue'`: Initial call fires immediately. Subsequent calls during the delay period
27
- * are skipped and return the promise from the initial call. Ideal for preventing
28
- * duplicate actions like clicking a download button twice.
29
- * - `'with-queue'`: Initial call fires immediately. After the initial flush, the promise
30
- * is discarded. The next call during the delay period creates a new workorder that will
31
- * be maintained until the next flush. Ideal for debounced search inputs and similar use cases.
32
- * @default 'with-queue'
33
- */
34
- eager?: false | 'no-queue' | 'with-queue';
35
- }
36
- interface IDebounce {
37
- <TFunc extends AnyFunction>(callback: TFunc, delayConfigArg?: number | IDelayConfig): IDebouncedFunction<TFunc>;
38
- }
39
- /**
40
- * Wraps the provided function with a debounce.
41
- *
42
- * Behavior during the delay period depends on the `eager` configuration:
43
- * - `eager: false`: All calls wait for the delay. New calls overwrite the existing call.
44
- * - `eager: 'no-queue'`: First call fires immediately. Subsequent calls during the delay
45
- * period are skipped and return the same promise as the initial call.
46
- * - `eager: 'with-queue'` (default): First call fires immediately. After the flush, the next call
47
- * creates a new workorder that will be fired after the delay. New calls overwrite queued args.
48
- *
49
- * Once the timer expires, the most recent call is fired.
50
- *
51
- * Note: Returned promises may resolve with values from calls made with
52
- * different arguments. Avoid using this for functions where argument-specific results matter.
53
- */
54
- export declare const debounce: IDebounce;
55
- export {};
@@ -1,107 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- /**
11
- * Wraps the provided function with a debounce.
12
- *
13
- * Behavior during the delay period depends on the `eager` configuration:
14
- * - `eager: false`: All calls wait for the delay. New calls overwrite the existing call.
15
- * - `eager: 'no-queue'`: First call fires immediately. Subsequent calls during the delay
16
- * period are skipped and return the same promise as the initial call.
17
- * - `eager: 'with-queue'` (default): First call fires immediately. After the flush, the next call
18
- * creates a new workorder that will be fired after the delay. New calls overwrite queued args.
19
- *
20
- * Once the timer expires, the most recent call is fired.
21
- *
22
- * Note: Returned promises may resolve with values from calls made with
23
- * different arguments. Avoid using this for functions where argument-specific results matter.
24
- */
25
- export const debounce = (...init) => {
26
- const [callback, delayArg] = init;
27
- const delayConfig = {
28
- delay: 1000,
29
- anchor: 'first-call',
30
- eager: 'with-queue',
31
- };
32
- if (typeof delayArg === 'number') {
33
- delayConfig.delay = delayArg || 1000;
34
- }
35
- else if (delayArg) {
36
- for (const _key in delayArg) {
37
- const key = _key;
38
- if (delayArg[key] !== undefined) {
39
- // @ts-expect-error
40
- delayConfig[key] = delayArg[key];
41
- }
42
- }
43
- }
44
- let nextCall = null;
45
- const debouncedFunction = (...args) => {
46
- let currentWork;
47
- if (nextCall) {
48
- if (delayConfig.eager !== 'no-queue') {
49
- nextCall = Object.assign(Object.assign({}, nextCall), { args, work: nextCall.work || Promise.withResolvers() });
50
- }
51
- currentWork = nextCall.work;
52
- if (delayConfig.anchor === 'last-call') {
53
- clearTimeout(nextCall.timeout);
54
- nextCall.timeout = setTimeout(debouncedFunction.flush, delayConfig.delay);
55
- }
56
- }
57
- else {
58
- // No active delay, create new call
59
- nextCall = {
60
- args,
61
- timeout: setTimeout(debouncedFunction.flush, delayConfig.delay),
62
- work: Promise.withResolvers(),
63
- };
64
- currentWork = nextCall.work;
65
- // Fire immediately if eager mode is enabled (no-queue or with-queue)
66
- if (delayConfig.eager !== false) {
67
- debouncedFunction.flush(true);
68
- }
69
- }
70
- if (!currentWork) {
71
- throw new Error('[debounce] `currentWork` was not initialized.');
72
- }
73
- return currentWork.promise;
74
- };
75
- debouncedFunction.flush = (isEager) => {
76
- if (!(nextCall === null || nextCall === void 0 ? void 0 : nextCall.args)) {
77
- nextCall = null;
78
- // console.log('Queue is empty. Nothing to flush.');
79
- return;
80
- }
81
- // Capture queue values.
82
- const { resolve, reject } = nextCall.work || {};
83
- const args = nextCall.args;
84
- // Clear the queue for new debounced calls.
85
- if (isEager) {
86
- delete nextCall.args;
87
- if (delayConfig.eager === 'with-queue') {
88
- delete nextCall.work;
89
- }
90
- }
91
- else {
92
- nextCall = null;
93
- }
94
- // Execute the pending call.
95
- (() => __awaiter(void 0, void 0, void 0, function* () {
96
- try {
97
- // const result = (await callback(...args)) ?? {};
98
- // result.__debounceFlushedWithArgs = args;
99
- resolve === null || resolve === void 0 ? void 0 : resolve(yield callback(...args));
100
- }
101
- catch (reason) {
102
- reject === null || reject === void 0 ? void 0 : reject(reason);
103
- }
104
- }))();
105
- };
106
- return debouncedFunction;
107
- };
@@ -1,13 +0,0 @@
1
- import type { SetStateAction } from 'react';
2
- import { debounce } from './index.js';
3
- type TDebounceConfig = Exclude<Parameters<typeof debounce>[1], number>;
4
- type TDelayConfig = number | TDebounceConfig & {
5
- staging?: boolean;
6
- };
7
- export declare function useDebouncedState<T extends any>(init: T, config: TDelayConfig): readonly [T, {
8
- (value: SetStateAction<T>): void;
9
- flush: (isEager?: true) => void;
10
- pause(): void;
11
- resume(): void;
12
- }, T];
13
- export {};
@@ -1,27 +0,0 @@
1
- import { useCallback, useMemo, useState } from 'react';
2
- import { debounce } from './index.js';
3
- export function useDebouncedState(init, config) {
4
- const [debouncedValue, setDebouncedValue] = useState(init);
5
- const [stagedValue, setStagedValue] = useState(init);
6
- const [paused, setPaused] = useState(false);
7
- const enableStaging = typeof config === 'object' && config.staging === true;
8
- const debounceArgs = [setDebouncedValue, config];
9
- const debouncedSetter = useCallback(debounce(...debounceArgs), debounceArgs);
10
- const setter = useMemo(() => {
11
- const _setter = (value) => {
12
- if (enableStaging) {
13
- setStagedValue(value);
14
- }
15
- if (paused) {
16
- console.warn('[useDebouncedState] Skipping debounced state update. Updates were paused with `setter.pause()`. Call `setter.play()` to resume.');
17
- }
18
- else
19
- debouncedSetter(value);
20
- };
21
- _setter.flush = debouncedSetter.flush;
22
- _setter.pause = () => setPaused(true);
23
- _setter.resume = () => setPaused(false);
24
- return _setter;
25
- }, [enableStaging, debouncedSetter]);
26
- return [debouncedValue, setter, stagedValue];
27
- }
@@ -1,74 +0,0 @@
1
- type TRecord = Record<keyof any, any>;
2
- declare namespace _ObjectGate {
3
- /** Configure property access for a proxy object. */
4
- interface IGateConfig<TSource extends TRecord> {
5
- /**
6
- * The keys to be exposed for read access through the proxy.
7
- * Defaults to [`Reflect.ownKeys(source)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys) —
8
- * so if omitted, all ["_own properties_"](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Enumerability_and_ownership_of_properties)
9
- * present on the source at
10
- * instantiation time will be exposed for read access through the proxy.
11
- */
12
- getters?: Readonly<Array<keyof TSource>>;
13
- /**
14
- * Keys that should definitely be omitted from read access,
15
- * even if they are present in {@link getters}.
16
- * @default [] - Empty array.
17
- */
18
- gettersExclude?: Readonly<Array<keyof TSource>>;
19
- /**
20
- * The keys to be exposed for write access through the proxy.
21
- * This defaults to an empty array, so if omitted, none of the gated
22
- * properties will be writeable.
23
- * @default [] - Empty array.
24
- */
25
- setters?: Readonly<Array<keyof TSource> | true>;
26
- /**
27
- * Keys that should definitely be omitted from write access,
28
- * even if they are present in {@link setters}.
29
- * @default [] - Empty array.
30
- */
31
- settersExclude?: Readonly<Array<keyof TSource>>;
32
- }
33
- type Params<TSource extends TRecord> = [
34
- /**
35
- * The target object, where the actual values are stored.
36
- * Keys on the created gate object will use JavaScript getters to return
37
- * the real-time value of the same key from this source object.
38
- */
39
- source: TSource,
40
- /** @see {@link IGateConfig} */
41
- config?: Readonly<IGateConfig<TSource>>
42
- ];
43
- class Gate<TSource extends TRecord> {
44
- constructor(...params: Params<TSource>);
45
- }
46
- interface IConstructor {
47
- new <TOutput extends Partial<TSource>, TSource extends TRecord>(...params: _ObjectGate.Params<TSource>): TOutput;
48
- }
49
- }
50
- /**
51
- * Creates a new object that acts as a real-time proxy
52
- * for the {@link _ObjectGate.Params | `source`} object.
53
- * This lets you prevent access to some properties, effectively making them private,
54
- * while selectively exposing access to only the properties you specify
55
- * in the {@link _ObjectGate.IGateConfig.getters | `getters`} config option.
56
- *
57
- * The exposed properties are read-only by default,
58
- * exposing only a [getter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description)
59
- * with no corresponding [setter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set#description).
60
- *
61
- * The {@link _ObjectGate.Params | `config`} argument also lets you selectively allow
62
- * write access to specific properties through the
63
- * {@link _ObjectGate.IGateConfig.setters | `setters`} config option.
64
- *
65
- * Unlike [`structuredClone`](https://developer.mozilla.org/docs/Web/API/Window/structuredClone)
66
- * this doesn't return a _copy_ of the `source` object.
67
- *
68
- * Instead, it returns a _**Real-time proxy**_. This means that a value is read
69
- * from the source object each time a property is accessed through the proxy.
70
- * So accessing a property through the gate object is guaranteed to always return
71
- * the latest value.
72
- */
73
- export declare const ObjectGate: _ObjectGate.IConstructor;
74
- export {};
@@ -1,64 +0,0 @@
1
- var _ObjectGate;
2
- (function (_ObjectGate) {
3
- class Gate {
4
- constructor(...params) {
5
- var _a, _b, _c, _d;
6
- const [source, config] = params;
7
- const getters = (_a = config === null || config === void 0 ? void 0 : config.getters) !== null && _a !== void 0 ? _a : Reflect.ownKeys(source);
8
- const gettersExclude = (_b = config === null || config === void 0 ? void 0 : config.gettersExclude) !== null && _b !== void 0 ? _b : [];
9
- const setters = (config === null || config === void 0 ? void 0 : config.setters) === true
10
- ? getters
11
- : ((_c = config === null || config === void 0 ? void 0 : config.setters) !== null && _c !== void 0 ? _c : []);
12
- const settersExclude = (_d = config === null || config === void 0 ? void 0 : config.settersExclude) !== null && _d !== void 0 ? _d : [];
13
- getters.forEach((_key) => {
14
- const key = _key;
15
- if (gettersExclude.includes(key))
16
- return;
17
- Object.defineProperty(this, key, {
18
- enumerable: true,
19
- configurable: true,
20
- get() {
21
- return source[key];
22
- },
23
- });
24
- });
25
- setters.forEach((_key) => {
26
- const key = _key;
27
- if (settersExclude.includes(key))
28
- return;
29
- Object.defineProperty(this, key, {
30
- enumerable: true,
31
- set(value) {
32
- source[key] = value;
33
- },
34
- });
35
- });
36
- }
37
- }
38
- _ObjectGate.Gate = Gate;
39
- ;
40
- })(_ObjectGate || (_ObjectGate = {}));
41
- /**
42
- * Creates a new object that acts as a real-time proxy
43
- * for the {@link _ObjectGate.Params | `source`} object.
44
- * This lets you prevent access to some properties, effectively making them private,
45
- * while selectively exposing access to only the properties you specify
46
- * in the {@link _ObjectGate.IGateConfig.getters | `getters`} config option.
47
- *
48
- * The exposed properties are read-only by default,
49
- * exposing only a [getter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description)
50
- * with no corresponding [setter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set#description).
51
- *
52
- * The {@link _ObjectGate.Params | `config`} argument also lets you selectively allow
53
- * write access to specific properties through the
54
- * {@link _ObjectGate.IGateConfig.setters | `setters`} config option.
55
- *
56
- * Unlike [`structuredClone`](https://developer.mozilla.org/docs/Web/API/Window/structuredClone)
57
- * this doesn't return a _copy_ of the `source` object.
58
- *
59
- * Instead, it returns a _**Real-time proxy**_. This means that a value is read
60
- * from the source object each time a property is accessed through the proxy.
61
- * So accessing a property through the gate object is guaranteed to always return
62
- * the latest value.
63
- */
64
- export const ObjectGate = _ObjectGate.Gate;