@pluv/types 0.2.0 → 0.2.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.
@@ -1,17 +1,18 @@
1
1
 
2
- > @pluv/types@0.2.0 build /home/runner/work/pluv/pluv/packages/types
2
+ > @pluv/types@0.2.2 build /home/runner/work/pluv/pluv/packages/types
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.7.0
7
+ CLI tsup v7.1.0
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- CJS dist/index.js 754.00 B
12
- CJS ⚡️ Build success in 35ms
13
11
  ESM dist/index.mjs 0 B
14
- ESM ⚡️ Build success in 38ms
12
+ ESM ⚡️ Build success in 29ms
13
+ CJS dist/index.js 754.00 B
14
+ CJS ⚡️ Build success in 29ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 1181ms
17
- DTS dist/index.d.ts 7.18 KB
16
+ DTS ⚡️ Build success in 1398ms
17
+ DTS dist/index.d.mts 7.18 KB
18
+ DTS dist/index.d.ts 7.18 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @pluv/types
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 8fba48b: fix including incorrect dependency
8
+ - 8997c65: bumped dependencies
9
+
10
+ ## 0.2.1
11
+
12
+ ### Patch Changes
13
+
14
+ - 8d11672: bumped dependencies to latest
15
+
3
16
  ## 0.2.0
4
17
 
5
18
  ### Minor Changes
@@ -0,0 +1,152 @@
1
+ type Constructable = {
2
+ new (...args: any[]): any;
3
+ };
4
+ type Maybe<T> = T | null | undefined;
5
+ type MaybePromise<T> = Promise<T> | T;
6
+ type MaybeReadonlyArray<T> = T[] | readonly T[];
7
+ type OptionalPropertyNames<T> = {
8
+ [K in keyof T]-?: {} extends {
9
+ [P in K]: T[K];
10
+ } ? K : never;
11
+ }[keyof T];
12
+ type SpreadProperties<L, R, K extends keyof L & keyof R> = {
13
+ [P in K]: L[P] | Exclude<R[P], undefined>;
14
+ };
15
+ type Id<T> = T extends infer U ? U extends Constructable ? U : {
16
+ [K in keyof U]: U[K];
17
+ } : never;
18
+ type SpreadTwo<L, R> = Id<Pick<L, Exclude<keyof L, keyof R>> & Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>> & Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>> & SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>>;
19
+ type Spread<A extends readonly [...any]> = A extends [
20
+ infer L,
21
+ ...infer R
22
+ ] ? SpreadTwo<L, Spread<R>> : unknown;
23
+ type DeepPartial<T> = {
24
+ [P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]>;
25
+ };
26
+ type DeepWriteable<T> = {
27
+ -readonly [P in keyof T]: DeepWriteable<T[P]>;
28
+ };
29
+ type OptionalProps<T extends Record<string, any>, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
30
+ type NonNilProps<T extends Record<string, any>, K extends keyof T = keyof T> = Omit<T, K> & {
31
+ [P in K]-?: NonNullable<T[P]>;
32
+ };
33
+ type JsonPrimitive = string | number | boolean | null;
34
+ type Json = JsonPrimitive | Json[] | readonly Json[] | {
35
+ [key: string]: Json;
36
+ };
37
+ type JsonObject = Record<string, Json>;
38
+
39
+ type BaseUser = {
40
+ id: string;
41
+ };
42
+ interface BaseClientEventRecord {
43
+ $GET_OTHERS: {};
44
+ $INITIALIZE_SESSION: {
45
+ presence: JsonObject;
46
+ update: string | null;
47
+ };
48
+ $PING: {};
49
+ $UPDATE_PRESENCE: {
50
+ presence: JsonObject;
51
+ };
52
+ $UPDATE_STORAGE: {
53
+ origin: string | null;
54
+ update: string;
55
+ };
56
+ }
57
+ type BaseClientMessage = InferEventMessage<BaseClientEventRecord>;
58
+ interface BaseIOAuthorize {
59
+ required: false;
60
+ secret: string;
61
+ user: InputZodLike<BaseUser>;
62
+ }
63
+ interface BaseIOAuthorizeEventRecord<TAuthorize extends IOAuthorize<any, any>> {
64
+ $OTHERS_RECEIVED: {
65
+ others: {
66
+ [connectionId: string]: {
67
+ connectionId: string;
68
+ presence: JsonObject | null;
69
+ room: string | null;
70
+ user: InferIOAuthorizeUser<TAuthorize>;
71
+ };
72
+ };
73
+ };
74
+ $USER_JOINED: {
75
+ connectionId: string;
76
+ user: NonNullable<InferIOAuthorizeUser<TAuthorize>>;
77
+ presence: JsonObject;
78
+ };
79
+ }
80
+ type BaseIOEventRecord<TAuthorize extends IOAuthorize<any, any>> = BaseIOAuthorizeEventRecord<TAuthorize> & {
81
+ $ERROR: {
82
+ message: string;
83
+ stack?: string | null;
84
+ };
85
+ $EXIT: {
86
+ sessionId: string;
87
+ };
88
+ $PONG: {};
89
+ $PRESENCE_UPDATED: {
90
+ presence: JsonObject;
91
+ };
92
+ $REGISTERED: {
93
+ sessionId: string;
94
+ };
95
+ $STORAGE_RECEIVED: {
96
+ state: string;
97
+ };
98
+ $STORAGE_UPDATED: {
99
+ state: string;
100
+ };
101
+ };
102
+ interface EventMessage<TEvent extends string, TData extends JsonObject = {}> {
103
+ data: TData;
104
+ type: TEvent;
105
+ }
106
+ type EventRecord<TEvent extends string, TData extends JsonObject> = {
107
+ [key in `${TEvent}`]: TData;
108
+ };
109
+ type GetEventMessage<T extends EventRecord<string, any>, TEvent extends keyof T> = TEvent extends string ? EventMessage<TEvent, T[TEvent]> : never;
110
+ type InferEventMessage<TEvents extends EventRecord<string, any> = EventRecord<string, any>, TEvent extends keyof TEvents = keyof TEvents> = {
111
+ [P in TEvent]: P extends string ? Id<EventMessage<P, TEvents[P]>> : never;
112
+ }[TEvent];
113
+ type InferIOAuthorize<TIO extends IOLike> = TIO extends IOLike<infer IAuthorize> ? IAuthorize : never;
114
+ type InferIOAuthorizeRequired<TAuthorize extends IOAuthorize<any, any>> = TAuthorize extends IOAuthorize<any, infer IRequired> ? IRequired : never;
115
+ type InferIOAuthorizeUser<TAuthorize extends IOAuthorize<any, any>> = TAuthorize extends IOAuthorize<infer IUser, infer IRequired> ? IRequired extends true ? IUser : IUser | null : never;
116
+ type InferIOInput<TIO extends IOLike> = TIO extends IOLike<any, infer IInput> ? IInput : never;
117
+ type InferIOOutput<TIO extends IOLike> = TIO extends IOLike<any, any, infer IOutputBroadcast, infer IOutputSelf, infer IOutputSync> ? Spread<[IOutputBroadcast, IOutputSelf, IOutputSync]> : never;
118
+ type InferIOOutputBroadcast<TIO extends IOLike> = TIO extends IOLike<any, any, infer IOutput> ? IOutput : never;
119
+ type InferIOOutputSelf<TIO extends IOLike> = TIO extends IOLike<any, any, any, infer IOutput> ? IOutput : never;
120
+ type InferIOOutputSync<TIO extends IOLike> = TIO extends IOLike<any, any, any, any, infer IOutput> ? IOutput : never;
121
+ type InputZodLike<TData extends JsonObject> = {
122
+ _input: TData;
123
+ parse: (data: unknown) => TData;
124
+ };
125
+ interface IOAuthorize<TUser extends BaseUser = any, TRequired extends boolean = false> {
126
+ required: TRequired;
127
+ secret: string;
128
+ user: InputZodLike<TUser>;
129
+ }
130
+ type IOAuthorizeEventMessage<TIO extends IOLike> = InferIOAuthorizeRequired<InferIOAuthorize<TIO>> extends false ? IOAuthorizeOptionalEventMessage<TIO> : IOAuthorizeRequiredEventMessage<TIO>;
131
+ interface IOAuthorizeOptionalEventMessage<TIO extends IOLike> {
132
+ connectionId: string | null;
133
+ user: InferIOAuthorizeUser<InferIOAuthorize<TIO>> | null;
134
+ }
135
+ type IOAuthorizeRequiredEventMessage<TIO extends IOLike> = NonNilProps<IOAuthorizeOptionalEventMessage<TIO>, "connectionId" | "user">;
136
+ type IOEventMessage<TIO extends IOLike, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = Id<{
137
+ room: string;
138
+ } & InferEventMessage<InferIOOutput<TIO>, TEvent> & (InferEventMessage<InferIOOutput<TIO>, TEvent>["type"] extends "$ERROR" ? IOAuthorizeOptionalEventMessage<TIO> : IOAuthorizeEventMessage<TIO>)>;
139
+ interface IOLike<TAuthorize extends IOAuthorize<any, any> = IOAuthorize<any, any>, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> {
140
+ _authorize: TAuthorize | null;
141
+ _events: {
142
+ [P in keyof TInput]: P extends string ? {
143
+ resolver: ((data: TInput[P], ...args: any[]) => MaybePromise<TOutputBroadcast | void>) | {
144
+ broadcast?: (data: TInput[P], ...args: any[]) => MaybePromise<TOutputBroadcast | void>;
145
+ self?: (data: TInput[P], ...args: any[]) => MaybePromise<TOutputSelf | void>;
146
+ sync?: (data: TInput[P], ...args: any[]) => MaybePromise<TOutputSync | void>;
147
+ };
148
+ } : never;
149
+ };
150
+ }
151
+
152
+ export { BaseClientEventRecord, BaseClientMessage, BaseIOAuthorize, BaseIOAuthorizeEventRecord, BaseIOEventRecord, BaseUser, Constructable, DeepPartial, DeepWriteable, EventMessage, EventRecord, GetEventMessage, IOAuthorize, IOAuthorizeEventMessage, IOAuthorizeOptionalEventMessage, IOAuthorizeRequiredEventMessage, IOEventMessage, IOLike, Id, InferEventMessage, InferIOAuthorize, InferIOAuthorizeRequired, InferIOAuthorizeUser, InferIOInput, InferIOOutput, InferIOOutputBroadcast, InferIOOutputSelf, InferIOOutputSync, InputZodLike, Json, JsonObject, JsonPrimitive, Maybe, MaybePromise, MaybeReadonlyArray, NonNilProps, OptionalProps, Spread, SpreadProperties };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/types",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "@pluv/io shared types",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -16,10 +16,13 @@
16
16
  "access": "public"
17
17
  },
18
18
  "devDependencies": {
19
- "tsup": "^6.7.0",
20
- "typescript": "^5.0.4",
21
- "@pluv/tsconfig": "^0.1.6",
22
- "eslint-config-pluv": "^0.1.11"
19
+ "tsup": "^7.1.0",
20
+ "typescript": "^5.1.6",
21
+ "@pluv/tsconfig": "^0.1.8",
22
+ "eslint-config-pluv": "^0.1.14"
23
+ },
24
+ "dependencies": {
25
+ "@types/react": "^18.2.15"
23
26
  },
24
27
  "scripts": {
25
28
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/general.ts CHANGED
@@ -27,7 +27,7 @@ type SpreadTwo<L, R> = Id<
27
27
 
28
28
  export type Spread<A extends readonly [...any]> = A extends [
29
29
  infer L,
30
- ...infer R
30
+ ...infer R,
31
31
  ]
32
32
  ? SpreadTwo<L, Spread<R>>
33
33
  : unknown;
@@ -46,12 +46,12 @@ export type DeepWriteable<T> = {
46
46
 
47
47
  export type OptionalProps<
48
48
  T extends Record<string, any>,
49
- K extends keyof T = keyof T
49
+ K extends keyof T = keyof T,
50
50
  > = Omit<T, K> & Partial<Pick<T, K>>;
51
51
 
52
52
  export type NonNilProps<
53
53
  T extends Record<string, any>,
54
- K extends keyof T = keyof T
54
+ K extends keyof T = keyof T,
55
55
  > = Omit<T, K> & { [P in K]-?: NonNullable<T[P]> };
56
56
 
57
57
  export type JsonPrimitive = string | number | boolean | null;
package/src/pluv.ts CHANGED
@@ -29,7 +29,7 @@ export interface BaseIOAuthorize {
29
29
  }
30
30
 
31
31
  export interface BaseIOAuthorizeEventRecord<
32
- TAuthorize extends IOAuthorize<any, any>
32
+ TAuthorize extends IOAuthorize<any, any>,
33
33
  > {
34
34
  $OTHERS_RECEIVED: {
35
35
  others: {
@@ -74,7 +74,7 @@ export type BaseIOEventRecord<TAuthorize extends IOAuthorize<any, any>> =
74
74
 
75
75
  export interface EventMessage<
76
76
  TEvent extends string,
77
- TData extends JsonObject = {}
77
+ TData extends JsonObject = {},
78
78
  > {
79
79
  data: TData;
80
80
  type: TEvent;
@@ -86,12 +86,12 @@ export type EventRecord<TEvent extends string, TData extends JsonObject> = {
86
86
 
87
87
  export type GetEventMessage<
88
88
  T extends EventRecord<string, any>,
89
- TEvent extends keyof T
89
+ TEvent extends keyof T,
90
90
  > = TEvent extends string ? EventMessage<TEvent, T[TEvent]> : never;
91
91
 
92
92
  export type InferEventMessage<
93
93
  TEvents extends EventRecord<string, any> = EventRecord<string, any>,
94
- TEvent extends keyof TEvents = keyof TEvents
94
+ TEvent extends keyof TEvents = keyof TEvents,
95
95
  > = {
96
96
  [P in TEvent]: P extends string ? Id<EventMessage<P, TEvents[P]>> : never;
97
97
  }[TEvent];
@@ -163,7 +163,7 @@ export type InputZodLike<TData extends JsonObject> = {
163
163
 
164
164
  export interface IOAuthorize<
165
165
  TUser extends BaseUser = any,
166
- TRequired extends boolean = false
166
+ TRequired extends boolean = false,
167
167
  > {
168
168
  required: TRequired;
169
169
  secret: string;
@@ -187,7 +187,7 @@ export type IOAuthorizeRequiredEventMessage<TIO extends IOLike> = NonNilProps<
187
187
 
188
188
  export type IOEventMessage<
189
189
  TIO extends IOLike,
190
- TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>
190
+ TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>,
191
191
  > = Id<
192
192
  { room: string } & InferEventMessage<InferIOOutput<TIO>, TEvent> &
193
193
  (InferEventMessage<InferIOOutput<TIO>, TEvent>["type"] extends "$ERROR"
@@ -200,7 +200,7 @@ export interface IOLike<
200
200
  TInput extends EventRecord<string, any> = {},
201
201
  TOutputBroadcast extends EventRecord<string, any> = {},
202
202
  TOutputSelf extends EventRecord<string, any> = {},
203
- TOutputSync extends EventRecord<string, any> = {}
203
+ TOutputSync extends EventRecord<string, any> = {},
204
204
  > {
205
205
  _authorize: TAuthorize | null;
206
206
  _events: {