@esportsplus/reactivity 0.25.4 → 0.25.6

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.
@@ -1,6 +1,6 @@
1
1
  declare const COMPILATION_ENTRYPOINT = "reactive";
2
2
  declare const COMPILATION_ENTRYPOINT_REGEX: RegExp;
3
- declare const COMPILATION_NAMESPACE = "reactive";
3
+ declare const COMPILATION_NAMESPACE: string;
4
4
  declare const COMPILATION_TYPE_ARRAY = "array";
5
5
  declare const COMPILATION_TYPE_COMPUTED = "computed";
6
6
  declare const COMPILATION_TYPE_SIGNAL = "signal";
@@ -1,6 +1,7 @@
1
+ import uid from 'node_modules/@esportsplus/typescript/build/transformer/uid';
1
2
  const COMPILATION_ENTRYPOINT = 'reactive';
2
3
  const COMPILATION_ENTRYPOINT_REGEX = /\breactive\b/;
3
- const COMPILATION_NAMESPACE = 'reactive';
4
+ const COMPILATION_NAMESPACE = uid(COMPILATION_ENTRYPOINT);
4
5
  const COMPILATION_TYPE_ARRAY = 'array';
5
6
  const COMPILATION_TYPE_COMPUTED = 'computed';
6
7
  const COMPILATION_TYPE_SIGNAL = 'signal';
@@ -1,25 +1,10 @@
1
- import { Prettify } from '@esportsplus/utilities';
2
1
  import { ReactiveArray } from './array.js';
3
2
  import { Reactive } from '../types.js';
4
- declare const READONLY: unique symbol;
5
3
  type Guard<T> = T extends Record<PropertyKey, unknown> ? T extends {
6
4
  dispose: any;
7
5
  } ? {
8
6
  never: '[ dispose ] is a reserved key';
9
7
  } : T : never;
10
- type Infer<T> = T extends (...args: unknown[]) => Promise<infer R> ? R | undefined : T extends (...args: any[]) => infer R ? R : T extends (infer U)[] ? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'> : T extends ReactiveObject<any> ? T : T extends Record<PropertyKey, unknown> ? {
11
- [K in keyof T]: T[K];
12
- } : T;
13
- type ReactiveObject<T> = T extends Record<PropertyKey, unknown> ? Reactive<Prettify<{
14
- [K in keyof T]: Infer<T[K]>;
15
- } & {
16
- dispose: VoidFunction;
17
- }>> : T extends (infer U)[] ? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'> : never;
18
- declare function reactive<T extends () => unknown>(_input: T): Reactive<ReturnType<T> & {
19
- readonly [READONLY]: true;
20
- }>;
21
- declare function reactive<T extends Record<PropertyKey, any>>(_input: Guard<T>): ReactiveObject<T>;
22
- declare function reactive<T>(_input: T[]): Reactive<T[] & Pick<ReactiveArray<T>, 'clear' | 'on' | 'once'>>;
8
+ declare function reactive<T extends Record<PropertyKey, any>>(_input: Guard<T>): Reactive<T>;
23
9
  export default reactive;
24
10
  export { reactive, ReactiveArray };
25
- export type { Reactive, ReactiveObject };
@@ -1,8 +1,8 @@
1
1
  import { ReactiveArray } from './array.js';
2
- import { PACKAGE } from '../constants.js';
2
+ import { COMPILATION_ENTRYPOINT, PACKAGE } from '../constants.js';
3
3
  function reactive(_input) {
4
- throw new Error(`${PACKAGE}: reactive() called at runtime. ` +
5
- 'Ensure vite-plugin-reactivity-compile is configured.');
4
+ throw new Error(`${PACKAGE}: ${COMPILATION_ENTRYPOINT}() called at runtime. ` +
5
+ 'Ensure vite plugin is configured.');
6
6
  }
7
7
  export default reactive;
8
8
  export { reactive, ReactiveArray };
@@ -1,18 +1,17 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import { uid } from '@esportsplus/typescript/transformer';
3
2
  import { COMPILATION_NAMESPACE } from '../constants.js';
4
3
  import { contains } from './detector.js';
5
4
  import array from './transforms/array.js';
6
5
  import object from './transforms/object.js';
7
6
  import primitives from './transforms/primitives.js';
8
- let ns = uid(COMPILATION_NAMESPACE), transforms = [object, array, primitives];
7
+ let transforms = [object, array, primitives];
9
8
  const transform = (sourceFile) => {
10
9
  let bindings = new Map(), code = sourceFile.getFullText(), current = sourceFile, result, transformed = false;
11
10
  if (!contains(code)) {
12
11
  return { code, sourceFile, transformed: false };
13
12
  }
14
13
  for (let i = 0, n = transforms.length; i < n; i++) {
15
- result = transforms[i](current, bindings, ns);
14
+ result = transforms[i](current, bindings, COMPILATION_NAMESPACE);
16
15
  if (result !== code) {
17
16
  current = ts.createSourceFile(sourceFile.fileName, result, sourceFile.languageVersion, true);
18
17
  code = result;
@@ -20,7 +19,7 @@ const transform = (sourceFile) => {
20
19
  }
21
20
  }
22
21
  if (transformed) {
23
- code = `import * as ${ns} from '@esportsplus/reactivity';\n` + code;
22
+ code = `import * as ${COMPILATION_NAMESPACE} from '@esportsplus/reactivity';\n` + code;
24
23
  sourceFile = ts.createSourceFile(sourceFile.fileName, code, sourceFile.languageVersion, true);
25
24
  }
26
25
  return { code, sourceFile, transformed };
package/build/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { COMPUTED, SIGNAL, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants.js';
2
1
  import { ts } from '@esportsplus/typescript';
2
+ import { COMPUTED, SIGNAL, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants.js';
3
+ import { ReactiveArray } from './reactive/index.js';
3
4
  type BindingType = 'array' | 'computed' | 'object' | 'signal';
4
5
  type Bindings = Map<string, BindingType>;
5
6
  interface Computed<T> {
@@ -24,7 +25,16 @@ interface Link {
24
25
  sub: Computed<unknown>;
25
26
  version: number;
26
27
  }
27
- type Reactive<T> = T;
28
+ declare const READONLY: unique symbol;
29
+ type Reactive<T> = T extends (...args: unknown[]) => Promise<infer R> ? (R | undefined) & {
30
+ readonly [READONLY]: true;
31
+ } : T extends (...args: any[]) => infer R ? R & {
32
+ readonly [READONLY]: true;
33
+ } : T extends (infer U)[] ? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'> : T extends Record<PropertyKey, unknown> ? {
34
+ [K in keyof T]: T[K];
35
+ } & {
36
+ dispose: VoidFunction;
37
+ } : T;
28
38
  type Signal<T> = {
29
39
  subs: Link | null;
30
40
  subsTail: Link | null;
package/package.json CHANGED
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "type": "module",
38
38
  "types": "build/index.d.ts",
39
- "version": "0.25.4",
39
+ "version": "0.25.6",
40
40
  "scripts": {
41
41
  "build": "tsc",
42
42
  "build:test": "pnpm build && vite build --config test/vite.config.ts",
package/src/constants.ts CHANGED
@@ -1,8 +1,10 @@
1
+ import uid from 'node_modules/@esportsplus/typescript/build/transformer/uid';
2
+
1
3
  const COMPILATION_ENTRYPOINT = 'reactive';
2
4
 
3
5
  const COMPILATION_ENTRYPOINT_REGEX = /\breactive\b/;
4
6
 
5
- const COMPILATION_NAMESPACE = 'reactive';
7
+ const COMPILATION_NAMESPACE = uid(COMPILATION_ENTRYPOINT);
6
8
 
7
9
  const COMPILATION_TYPE_ARRAY = 'array';
8
10
 
@@ -1,12 +1,8 @@
1
- import { Prettify } from '@esportsplus/utilities';
2
1
  import { ReactiveArray } from './array';
3
- import { PACKAGE } from '~/constants';
2
+ import { COMPILATION_ENTRYPOINT, PACKAGE } from '~/constants';
4
3
  import { Reactive } from '~/types';
5
4
 
6
5
 
7
- // Branded type to prevent assignment to computed values
8
- declare const READONLY: unique symbol;
9
-
10
6
  type Guard<T> =
11
7
  T extends Record<PropertyKey, unknown>
12
8
  ? T extends { dispose: any }
@@ -14,38 +10,15 @@ type Guard<T> =
14
10
  : T
15
11
  : never;
16
12
 
17
- type Infer<T> =
18
- T extends (...args: unknown[]) => Promise<infer R>
19
- ? R | undefined
20
- : T extends (...args: any[]) => infer R
21
- ? R
22
- : T extends (infer U)[]
23
- ? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'>
24
- : T extends ReactiveObject<any>
25
- ? T
26
- : T extends Record<PropertyKey, unknown>
27
- ? { [K in keyof T]: T[K] }
28
- : T;
29
-
30
- type ReactiveObject<T> =
31
- T extends Record<PropertyKey, unknown>
32
- ? Reactive< Prettify<{ [K in keyof T]: Infer<T[K]> } & { dispose: VoidFunction }> >
33
- : T extends (infer U)[]
34
- ? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'>
35
- : never;
36
-
37
13
 
38
- function reactive<T extends () => unknown>(_input: T): Reactive< ReturnType<T> & { readonly [READONLY]: true } >;
39
- function reactive<T extends Record<PropertyKey, any>>(_input: Guard<T>): ReactiveObject<T>;
40
- function reactive<T>(_input: T[]): Reactive< T[] & Pick<ReactiveArray<T>, 'clear' | 'on' | 'once'> >;
14
+ function reactive<T extends Record<PropertyKey, any>>(_input: Guard<T>): Reactive<T>;
41
15
  function reactive<T>(_input: T): Reactive<T> {
42
16
  throw new Error(
43
- `${PACKAGE}: reactive() called at runtime. ` +
44
- 'Ensure vite-plugin-reactivity-compile is configured.'
17
+ `${PACKAGE}: ${COMPILATION_ENTRYPOINT}() called at runtime. ` +
18
+ 'Ensure vite plugin is configured.'
45
19
  );
46
20
  }
47
21
 
48
22
 
49
23
  export default reactive;
50
24
  export { reactive, ReactiveArray };
51
- export type { Reactive, ReactiveObject };
@@ -1,5 +1,4 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import { uid } from '@esportsplus/typescript/transformer';
3
2
  import { COMPILATION_NAMESPACE } from '~/constants.js';
4
3
  import type { Bindings, TransformResult } from '~/types';
5
4
  import { contains } from './detector';
@@ -8,8 +7,7 @@ import object from './transforms/object';
8
7
  import primitives from './transforms/primitives';
9
8
 
10
9
 
11
- let ns = uid(COMPILATION_NAMESPACE),
12
- transforms = [object, array, primitives];
10
+ let transforms = [object, array, primitives];
13
11
 
14
12
 
15
13
  const transform = (sourceFile: ts.SourceFile): TransformResult => {
@@ -24,7 +22,7 @@ const transform = (sourceFile: ts.SourceFile): TransformResult => {
24
22
  }
25
23
 
26
24
  for (let i = 0, n = transforms.length; i < n; i++) {
27
- result = transforms[i](current, bindings, ns);
25
+ result = transforms[i](current, bindings, COMPILATION_NAMESPACE);
28
26
 
29
27
  if (result !== code) {
30
28
  current = ts.createSourceFile(sourceFile.fileName, result, sourceFile.languageVersion, true);
@@ -34,7 +32,7 @@ const transform = (sourceFile: ts.SourceFile): TransformResult => {
34
32
  }
35
33
 
36
34
  if (transformed) {
37
- code = `import * as ${ns} from '@esportsplus/reactivity';\n` + code;
35
+ code = `import * as ${COMPILATION_NAMESPACE} from '@esportsplus/reactivity';\n` + code;
38
36
  sourceFile = ts.createSourceFile(sourceFile.fileName, code, sourceFile.languageVersion, true);
39
37
  }
40
38
 
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { COMPUTED, SIGNAL, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants';
2
1
  import { ts } from '@esportsplus/typescript';
2
+ import { COMPUTED, SIGNAL, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants';
3
+ import { ReactiveArray } from './reactive';
3
4
 
4
5
 
5
6
  type BindingType = 'array' | 'computed' | 'object' | 'signal';
@@ -37,7 +38,17 @@ interface Link {
37
38
 
38
39
  // If we expose internals optimizing compiler may break api.
39
40
  // Instead we will use this as a shim.
40
- type Reactive<T> = T;
41
+ declare const READONLY: unique symbol;
42
+
43
+ type Reactive<T> = T extends (...args: unknown[]) => Promise<infer R>
44
+ ? (R | undefined) & { readonly [READONLY]: true }
45
+ : T extends (...args: any[]) => infer R
46
+ ? R & { readonly [READONLY]: true }
47
+ : T extends (infer U)[]
48
+ ? U[] & Pick<ReactiveArray<U>, 'clear' | 'on' | 'once'>
49
+ : T extends Record<PropertyKey, unknown>
50
+ ? { [K in keyof T]: T[K] } & { dispose: VoidFunction }
51
+ : T;
41
52
 
42
53
  type Signal<T> = {
43
54
  subs: Link | null;
@@ -54,8 +65,7 @@ interface TransformResult {
54
65
 
55
66
 
56
67
  export type {
57
- BindingType,
58
- Bindings,
68
+ BindingType, Bindings,
59
69
  Computed,
60
70
  Link,
61
71
  Reactive,