pqb 0.0.1

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 (122) hide show
  1. package/dist/index.d.ts +3630 -0
  2. package/dist/index.esm.js +4587 -0
  3. package/dist/index.esm.js.map +1 -0
  4. package/dist/index.js +4691 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +59 -0
  7. package/rollup.config.js +35 -0
  8. package/src/adapter.test.ts +10 -0
  9. package/src/adapter.ts +171 -0
  10. package/src/columnSchema/array.ts +21 -0
  11. package/src/columnSchema/boolean.ts +10 -0
  12. package/src/columnSchema/columnType.test.ts +129 -0
  13. package/src/columnSchema/columnType.ts +77 -0
  14. package/src/columnSchema/columnTypes.ts +145 -0
  15. package/src/columnSchema/columnsSchema.test.ts +32 -0
  16. package/src/columnSchema/columnsSchema.ts +100 -0
  17. package/src/columnSchema/commonMethods.ts +130 -0
  18. package/src/columnSchema/dateTime.ts +104 -0
  19. package/src/columnSchema/enum.ts +13 -0
  20. package/src/columnSchema/index.ts +11 -0
  21. package/src/columnSchema/json/array.ts +55 -0
  22. package/src/columnSchema/json/discriminatedUnion.ts +91 -0
  23. package/src/columnSchema/json/enum.ts +29 -0
  24. package/src/columnSchema/json/instanceOf.ts +16 -0
  25. package/src/columnSchema/json/intersection.ts +23 -0
  26. package/src/columnSchema/json/lazy.ts +22 -0
  27. package/src/columnSchema/json/literal.ts +12 -0
  28. package/src/columnSchema/json/map.ts +29 -0
  29. package/src/columnSchema/json/nativeEnum.ts +30 -0
  30. package/src/columnSchema/json/nullable.ts +33 -0
  31. package/src/columnSchema/json/nullish.ts +30 -0
  32. package/src/columnSchema/json/object.ts +206 -0
  33. package/src/columnSchema/json/optional.ts +28 -0
  34. package/src/columnSchema/json/record.ts +40 -0
  35. package/src/columnSchema/json/scalarTypes.ts +117 -0
  36. package/src/columnSchema/json/set.ts +34 -0
  37. package/src/columnSchema/json/tuple.ts +40 -0
  38. package/src/columnSchema/json/typeBase.ts +202 -0
  39. package/src/columnSchema/json/union.ts +16 -0
  40. package/src/columnSchema/json.ts +64 -0
  41. package/src/columnSchema/number.ts +122 -0
  42. package/src/columnSchema/string.ts +222 -0
  43. package/src/columnSchema/utils.ts +27 -0
  44. package/src/common.ts +86 -0
  45. package/src/db.test.ts +67 -0
  46. package/src/db.ts +212 -0
  47. package/src/errors.ts +7 -0
  48. package/src/index.ts +18 -0
  49. package/src/operators.test.ts +608 -0
  50. package/src/operators.ts +177 -0
  51. package/src/query.ts +292 -0
  52. package/src/queryDataUtils.ts +50 -0
  53. package/src/queryMethods/aggregate.test.ts +583 -0
  54. package/src/queryMethods/aggregate.ts +878 -0
  55. package/src/queryMethods/callbacks.test.ts +69 -0
  56. package/src/queryMethods/callbacks.ts +55 -0
  57. package/src/queryMethods/clear.test.ts +64 -0
  58. package/src/queryMethods/clear.ts +58 -0
  59. package/src/queryMethods/columnInfo.test.ts +45 -0
  60. package/src/queryMethods/columnInfo.ts +67 -0
  61. package/src/queryMethods/delete.test.ts +135 -0
  62. package/src/queryMethods/delete.ts +50 -0
  63. package/src/queryMethods/for.test.ts +57 -0
  64. package/src/queryMethods/for.ts +99 -0
  65. package/src/queryMethods/from.test.ts +66 -0
  66. package/src/queryMethods/from.ts +58 -0
  67. package/src/queryMethods/get.test.ts +66 -0
  68. package/src/queryMethods/get.ts +88 -0
  69. package/src/queryMethods/having.test.ts +247 -0
  70. package/src/queryMethods/having.ts +99 -0
  71. package/src/queryMethods/insert.test.ts +555 -0
  72. package/src/queryMethods/insert.ts +453 -0
  73. package/src/queryMethods/join.test.ts +150 -0
  74. package/src/queryMethods/join.ts +508 -0
  75. package/src/queryMethods/json.test.ts +398 -0
  76. package/src/queryMethods/json.ts +259 -0
  77. package/src/queryMethods/log.test.ts +172 -0
  78. package/src/queryMethods/log.ts +123 -0
  79. package/src/queryMethods/queryMethods.test.ts +629 -0
  80. package/src/queryMethods/queryMethods.ts +428 -0
  81. package/src/queryMethods/select.test.ts +479 -0
  82. package/src/queryMethods/select.ts +249 -0
  83. package/src/queryMethods/then.ts +236 -0
  84. package/src/queryMethods/transaction.test.ts +66 -0
  85. package/src/queryMethods/transaction.ts +66 -0
  86. package/src/queryMethods/union.test.ts +59 -0
  87. package/src/queryMethods/union.ts +89 -0
  88. package/src/queryMethods/update.test.ts +417 -0
  89. package/src/queryMethods/update.ts +350 -0
  90. package/src/queryMethods/upsert.test.ts +56 -0
  91. package/src/queryMethods/upsert.ts +43 -0
  92. package/src/queryMethods/where.test.ts +1594 -0
  93. package/src/queryMethods/where.ts +450 -0
  94. package/src/queryMethods/window.test.ts +66 -0
  95. package/src/queryMethods/window.ts +108 -0
  96. package/src/queryMethods/with.test.ts +191 -0
  97. package/src/queryMethods/with.ts +92 -0
  98. package/src/quote.ts +36 -0
  99. package/src/relations.ts +194 -0
  100. package/src/sql/aggregate.ts +80 -0
  101. package/src/sql/columnInfo.ts +22 -0
  102. package/src/sql/common.ts +42 -0
  103. package/src/sql/delete.ts +41 -0
  104. package/src/sql/distinct.ts +19 -0
  105. package/src/sql/fromAndAs.ts +51 -0
  106. package/src/sql/having.ts +140 -0
  107. package/src/sql/index.ts +2 -0
  108. package/src/sql/insert.ts +102 -0
  109. package/src/sql/join.ts +242 -0
  110. package/src/sql/orderBy.ts +41 -0
  111. package/src/sql/select.ts +153 -0
  112. package/src/sql/toSql.ts +153 -0
  113. package/src/sql/truncate.ts +13 -0
  114. package/src/sql/types.ts +355 -0
  115. package/src/sql/update.ts +62 -0
  116. package/src/sql/where.ts +314 -0
  117. package/src/sql/window.ts +38 -0
  118. package/src/sql/with.ts +32 -0
  119. package/src/test-utils.ts +172 -0
  120. package/src/utils.ts +140 -0
  121. package/tsconfig.build.json +6 -0
  122. package/tsconfig.json +8 -0
@@ -0,0 +1,33 @@
1
+ import { JSONTypeAny } from './typeBase';
2
+
3
+ export type JSONNullable<T extends JSONTypeAny> = Omit<T, 'type' | 'data'> & {
4
+ type: T['type'] | null;
5
+ data: T['data'] & { nullable: true };
6
+ };
7
+
8
+ export const nullable = <T extends JSONTypeAny>(type: T): JSONNullable<T> => {
9
+ return {
10
+ ...type,
11
+ data: { ...type.data, nullable: true },
12
+ };
13
+ };
14
+
15
+ export type JSONNotNullable<T extends JSONTypeAny> = Omit<
16
+ T,
17
+ 'type' | 'data'
18
+ > & {
19
+ type: Exclude<T['type'], null>;
20
+ data: Omit<T['data'], 'nullable'>;
21
+ };
22
+
23
+ export const notNullable = <T extends JSONTypeAny>(
24
+ type: T,
25
+ ): JSONNotNullable<T> => {
26
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
+ const { nullable: _, ...data } = type.data;
28
+
29
+ return {
30
+ ...type,
31
+ data,
32
+ } as JSONNotNullable<T>;
33
+ };
@@ -0,0 +1,30 @@
1
+ import { JSONTypeAny } from './typeBase';
2
+
3
+ export type JSONNullish<T extends JSONTypeAny> = Omit<T, 'type' | 'data'> & {
4
+ type: T['type'] | undefined | null;
5
+ data: T['data'] & { nullable: true };
6
+ };
7
+
8
+ export const nullish = <T extends JSONTypeAny>(type: T): JSONNullish<T> => {
9
+ return {
10
+ ...type,
11
+ data: { ...type.data, nullable: true, optional: true },
12
+ };
13
+ };
14
+
15
+ export type JSONNotNullish<T extends JSONTypeAny> = Omit<T, 'type' | 'data'> & {
16
+ type: Exclude<T['type'], undefined | null>;
17
+ data: Omit<T['data'], 'nullable'>;
18
+ };
19
+
20
+ export const notNullish = <T extends JSONTypeAny>(
21
+ type: T,
22
+ ): JSONNotNullish<T> => {
23
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
+ const { nullable, optional, ...data } = type.data;
25
+
26
+ return {
27
+ ...type,
28
+ data,
29
+ } as JSONNotNullish<T>;
30
+ };
@@ -0,0 +1,206 @@
1
+ import { constructType, DeepPartial, JSONType, JSONTypeAny } from './typeBase';
2
+ import { JSONOptional, optional } from './optional';
3
+
4
+ export type JSONObjectShape = Record<string, JSONTypeAny>;
5
+
6
+ export type UnknownKeysParam = 'passthrough' | 'strict' | 'strip';
7
+
8
+ type FullyPartial<T extends JSONObjectShape> = {
9
+ [K in keyof T]: JSONOptional<T[K]>;
10
+ };
11
+
12
+ type PartiallyPartial<T extends JSONObjectShape, P extends keyof T> = {
13
+ [K in keyof T]: K extends P ? JSONOptional<T[K]> : T[K];
14
+ };
15
+
16
+ export type identity<T> = T;
17
+
18
+ export type flatten<T extends object> = identity<{ [k in keyof T]: T[k] }>;
19
+
20
+ type optionalKeys<T extends object> = {
21
+ [k in keyof T]: undefined extends T[k] ? k : never;
22
+ }[keyof T];
23
+
24
+ type requiredKeys<T extends object> = {
25
+ [k in keyof T]: undefined extends T[k] ? never : k;
26
+ }[keyof T];
27
+
28
+ export type addQuestionMarks<T extends object> = Partial<
29
+ Pick<T, optionalKeys<T>>
30
+ > &
31
+ Pick<T, requiredKeys<T>>;
32
+
33
+ export type baseObjectOutputType<Shape extends JSONObjectShape> = flatten<
34
+ addQuestionMarks<{
35
+ [k in keyof Shape]: Shape[k]['type'];
36
+ }>
37
+ >;
38
+
39
+ type objectOutputType<
40
+ Shape extends JSONObjectShape,
41
+ Catchall extends JSONTypeAny,
42
+ > = JSONTypeAny extends Catchall
43
+ ? baseObjectOutputType<Shape>
44
+ : flatten<baseObjectOutputType<Shape> & { [k: string]: Catchall['type'] }>;
45
+
46
+ export type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <
47
+ G,
48
+ >() => G extends U ? 1 : 2
49
+ ? true
50
+ : false;
51
+
52
+ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true
53
+ ? never
54
+ : KeyType extends ExcludeType
55
+ ? never
56
+ : KeyType;
57
+
58
+ export type Except<ObjectType, KeysType extends keyof ObjectType> = {
59
+ [KeyType in keyof ObjectType as Filter<
60
+ KeyType,
61
+ KeysType
62
+ >]: ObjectType[KeyType];
63
+ };
64
+
65
+ export type Merge<FirstType, SecondType> = Except<
66
+ FirstType,
67
+ Extract<keyof FirstType, keyof SecondType>
68
+ > &
69
+ SecondType;
70
+
71
+ export interface JSONObject<
72
+ T extends JSONObjectShape,
73
+ UnknownKeys extends UnknownKeysParam = 'strip',
74
+ Catchall extends JSONTypeAny = JSONTypeAny,
75
+ Output = objectOutputType<T, Catchall>,
76
+ > extends JSONType<Output, 'object'> {
77
+ shape: T;
78
+ unknownKeys: UnknownKeys;
79
+ catchAllType: Catchall;
80
+ extend<S extends JSONObjectShape>(
81
+ shape: S,
82
+ ): JSONObject<Merge<T, S>, UnknownKeys, Catchall>;
83
+ merge<
84
+ S extends JSONObjectShape,
85
+ U extends UnknownKeysParam,
86
+ C extends JSONTypeAny,
87
+ >(
88
+ obj: JSONObject<S, U, C>,
89
+ ): JSONObject<Merge<T, S>, U, C>;
90
+ pick<K extends keyof T>(
91
+ ...arr: K[]
92
+ ): JSONObject<Pick<T, K>, UnknownKeys, Catchall>;
93
+ omit<K extends keyof T>(
94
+ ...arr: K[]
95
+ ): JSONObject<Omit<T, K>, UnknownKeys, Catchall>;
96
+ partial(): JSONObject<FullyPartial<T>, UnknownKeys, Catchall>;
97
+ partial<P extends keyof T>(
98
+ ...arr: P[]
99
+ ): JSONObject<PartiallyPartial<T, P>, UnknownKeys, Catchall>;
100
+ deepPartial(): JSONObject<
101
+ { [k in keyof T]: JSONOptional<DeepPartial<T[k]>> },
102
+ UnknownKeys,
103
+ Catchall
104
+ >;
105
+ passthrough(): JSONObject<T, 'passthrough', Catchall>;
106
+ strict(): JSONObject<T, 'strict', Catchall>;
107
+ strip(): JSONObject<T, 'strip', Catchall>;
108
+ catchAll<C extends JSONTypeAny>(type: C): JSONObject<T, UnknownKeys, C>;
109
+ }
110
+
111
+ export const object = <
112
+ T extends JSONObjectShape,
113
+ UnknownKeys extends UnknownKeysParam = 'strip',
114
+ Catchall extends JSONTypeAny = JSONTypeAny,
115
+ >(
116
+ shape: T,
117
+ ): JSONObject<T, UnknownKeys, Catchall> => {
118
+ return constructType<JSONObject<T, UnknownKeys, Catchall>>({
119
+ dataType: 'object' as const,
120
+ shape,
121
+ unknownKeys: 'strip' as UnknownKeys,
122
+ catchAllType: undefined as unknown as Catchall,
123
+ extend<S extends JSONObjectShape>(add: S) {
124
+ return object<Merge<T, S>, UnknownKeys, Catchall>(
125
+ Object.assign({ ...this.shape }, add),
126
+ );
127
+ },
128
+ merge<
129
+ S extends JSONObjectShape,
130
+ U extends UnknownKeysParam,
131
+ C extends JSONTypeAny,
132
+ >(obj: JSONObject<S, U, C>) {
133
+ return object<Merge<T, S>, U, C>(
134
+ Object.assign({ ...this.shape }, obj.shape),
135
+ );
136
+ },
137
+ pick<K extends keyof T>(...arr: K[]) {
138
+ const picked = {} as Pick<T, K>;
139
+ arr.forEach((key) => (picked[key] = this.shape[key]));
140
+ return object<Pick<T, K>, UnknownKeys, Catchall>(picked);
141
+ },
142
+ omit<K extends keyof T>(...arr: K[]) {
143
+ const picked = {} as Omit<T, K>;
144
+ for (const key in this.shape) {
145
+ if (!arr.includes(key as unknown as K)) {
146
+ (picked as T)[key] = this.shape[key];
147
+ }
148
+ }
149
+ return object<Omit<T, K>, UnknownKeys, Catchall>(picked);
150
+ },
151
+ partial<P extends keyof T>(...arr: P[]) {
152
+ const mapped = { ...this.shape };
153
+
154
+ if (arr.length) {
155
+ arr.forEach((key) => {
156
+ mapped[key] = mapped[key].optional();
157
+ });
158
+ } else {
159
+ for (const key in mapped) {
160
+ mapped[key] = mapped[key].optional();
161
+ }
162
+ }
163
+
164
+ return object<typeof mapped, UnknownKeys, Catchall>(mapped);
165
+ },
166
+ deepPartial(this: JSONObject<T, UnknownKeys, Catchall>) {
167
+ const newShape: JSONObjectShape = {};
168
+
169
+ for (const key in this.shape) {
170
+ newShape[key] = optional(this.shape[key].deepPartial());
171
+ }
172
+
173
+ return {
174
+ ...this,
175
+ shape: newShape,
176
+ };
177
+ },
178
+ passthrough(this: JSONObject<T, UnknownKeys, Catchall>) {
179
+ return {
180
+ ...this,
181
+ unknownKeys: 'passthrough',
182
+ } as JSONObject<T, 'passthrough', Catchall>;
183
+ },
184
+ strict(this: JSONObject<T, UnknownKeys, Catchall>) {
185
+ return {
186
+ ...this,
187
+ unknownKeys: 'strict',
188
+ } as JSONObject<T, 'strict', Catchall>;
189
+ },
190
+ strip(this: JSONObject<T, UnknownKeys, Catchall>) {
191
+ return {
192
+ ...this,
193
+ unknownKeys: 'strip',
194
+ } as JSONObject<T, 'strip', Catchall>;
195
+ },
196
+ catchAll<C extends JSONTypeAny>(
197
+ this: JSONObject<T, UnknownKeys, C>,
198
+ type: C,
199
+ ) {
200
+ return {
201
+ ...this,
202
+ catchAllType: type,
203
+ };
204
+ },
205
+ });
206
+ };
@@ -0,0 +1,28 @@
1
+ import { JSONTypeAny } from './typeBase';
2
+
3
+ export type JSONOptional<T extends JSONTypeAny> = Omit<T, 'type' | 'data'> & {
4
+ type: T['type'] | undefined;
5
+ data: T['data'] & { optional: true };
6
+ };
7
+
8
+ export const optional = <T extends JSONTypeAny>(type: T): JSONOptional<T> => {
9
+ return {
10
+ ...type,
11
+ data: { ...type.data, optional: true },
12
+ };
13
+ };
14
+
15
+ export type JSONRequired<T extends JSONTypeAny> = Omit<T, 'type' | 'data'> & {
16
+ type: Exclude<T['type'], undefined>;
17
+ data: Omit<T['data'], 'optional'>;
18
+ };
19
+
20
+ export const required = <T extends JSONTypeAny>(type: T): JSONRequired<T> => {
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+ const { optional: _, ...data } = type.data;
23
+
24
+ return {
25
+ ...type,
26
+ data,
27
+ } as JSONRequired<T>;
28
+ };
@@ -0,0 +1,40 @@
1
+ import { constructType, JSONType, JSONTypeAny } from './typeBase';
2
+ import { JSONNumber, JSONString, scalarTypes } from './scalarTypes';
3
+
4
+ export interface JSONRecord<Key extends KeyType, Value extends JSONTypeAny>
5
+ extends JSONType<Record<Key['type'], Value['type']>, 'record'> {
6
+ keyType: Key;
7
+ valueType: Value;
8
+ deepPartial(): JSONRecord<Key, ReturnType<Value['deepPartial']>>;
9
+ }
10
+
11
+ type KeyType = JSONType<string | number, 'string' | 'number'>;
12
+ type Args<Key extends KeyType, Value extends JSONTypeAny> =
13
+ | Args2<Key, Value>
14
+ | Args1<Key>;
15
+
16
+ type Args2<Key extends KeyType, Value extends JSONTypeAny> = [
17
+ key: Key,
18
+ value: Value,
19
+ ];
20
+ type Args1<Value extends JSONTypeAny> = [value: Value];
21
+
22
+ export function record(
23
+ ...args: Args<JSONString | JSONNumber, JSONTypeAny>
24
+ ): JSONRecord<JSONString | JSONNumber, JSONTypeAny> {
25
+ const [keyType, valueType] = (
26
+ args.length === 1 ? [scalarTypes.string(), args[0]] : args
27
+ ) as Args2<JSONString | JSONNumber, JSONTypeAny>;
28
+
29
+ return constructType<JSONRecord<JSONString | JSONNumber, JSONTypeAny>>({
30
+ dataType: 'record',
31
+ keyType,
32
+ valueType,
33
+ deepPartial(this: JSONRecord<JSONString, JSONTypeAny>) {
34
+ return {
35
+ ...this,
36
+ valueType: this.valueType.deepPartial(),
37
+ };
38
+ },
39
+ });
40
+ }
@@ -0,0 +1,117 @@
1
+ import { constructType, JSONType, JSONTypeAny } from './typeBase';
2
+ import { BaseNumberData } from '../number';
3
+ import { BaseStringData } from '../string';
4
+ import { numberTypeMethods, stringTypeMethods } from '../commonMethods';
5
+
6
+ export type JSONAny = JSONTypeAny & {
7
+ dataType: 'any';
8
+ };
9
+ const any = () => {
10
+ return constructType<JSONAny>({
11
+ dataType: 'any',
12
+ });
13
+ };
14
+
15
+ export type JSONBigInt = JSONType<bigint, 'bigint'> & {
16
+ data: BaseNumberData;
17
+ } & typeof bigIntMethods;
18
+ const bigIntMethods = {
19
+ dataType: 'bigint' as const,
20
+ ...numberTypeMethods<JSONType<bigint, 'bigint'> & { data: BaseNumberData }>(),
21
+ };
22
+ const bigint = () => {
23
+ return constructType<JSONBigInt>(bigIntMethods);
24
+ };
25
+
26
+ export type JSONBoolean = JSONType<boolean, 'boolean'>;
27
+ const boolean = () => {
28
+ return constructType<JSONBoolean>({
29
+ dataType: 'boolean',
30
+ });
31
+ };
32
+
33
+ export type JSONNaN = JSONType<number, 'nan'>;
34
+ const nan = () => {
35
+ return constructType<JSONNaN>({
36
+ dataType: 'nan',
37
+ });
38
+ };
39
+
40
+ export type JSONNever = JSONType<unknown, 'never'>;
41
+ const never = () => {
42
+ return constructType<JSONNever>({
43
+ dataType: 'never',
44
+ });
45
+ };
46
+
47
+ export type JSONNull = JSONType<null, 'null'>;
48
+ const nullType = () => {
49
+ return constructType<JSONNull>({
50
+ dataType: 'null',
51
+ });
52
+ };
53
+
54
+ export type JSONNumber = JSONType<number, 'number'> & {
55
+ data: BaseNumberData;
56
+ } & typeof numberMethods;
57
+ const numberMethods = {
58
+ ...numberTypeMethods<JSONType<number, 'number'> & { data: BaseNumberData }>(),
59
+ dataType: 'number' as const,
60
+ };
61
+ const number = () => {
62
+ return constructType<JSONNumber>(numberMethods);
63
+ };
64
+
65
+ export type JSONDate = JSONType<Date, 'date'>;
66
+ const date = () => {
67
+ return constructType<JSONDate>({
68
+ dataType: 'date',
69
+ });
70
+ };
71
+
72
+ export type JSONString = JSONType<string, 'string'> & {
73
+ data: BaseStringData;
74
+ } & typeof stringMethods;
75
+ const stringMethods = {
76
+ ...stringTypeMethods<JSONType<number, 'string'> & { data: BaseStringData }>(),
77
+ dataType: 'string' as const,
78
+ };
79
+ const string = () => {
80
+ return constructType<JSONString>(stringMethods);
81
+ };
82
+
83
+ export type JSONUndefined = JSONType<undefined, 'undefined'>;
84
+ const undefinedType = () => {
85
+ return constructType<JSONUndefined>({
86
+ dataType: 'undefined',
87
+ });
88
+ };
89
+
90
+ export type JSONUnknown = JSONType<unknown, 'unknown'>;
91
+ const unknown = () => {
92
+ return constructType<JSONUnknown>({
93
+ dataType: 'unknown',
94
+ });
95
+ };
96
+
97
+ export type JSONVoid = JSONType<void, 'void'>;
98
+ const voidType = () => {
99
+ return constructType<JSONVoid>({
100
+ dataType: 'void',
101
+ });
102
+ };
103
+
104
+ export const scalarTypes = {
105
+ any,
106
+ bigint,
107
+ boolean,
108
+ date,
109
+ nan,
110
+ never,
111
+ null: nullType,
112
+ number,
113
+ string,
114
+ undefined: undefinedType,
115
+ unknown,
116
+ void: voidType,
117
+ };
@@ -0,0 +1,34 @@
1
+ import { constructType, JSONType, JSONTypeAny, JSONTypeData } from './typeBase';
2
+ import { ArrayMethods, arrayMethods } from '../commonMethods';
3
+
4
+ export interface JSONSet<Value extends JSONTypeAny>
5
+ extends JSONType<Set<Value['type']>, 'set'>,
6
+ ArrayMethods {
7
+ data: JSONTypeData & {
8
+ min?: number;
9
+ max?: number;
10
+ length?: number;
11
+ };
12
+ valueType: Value;
13
+ deepPartial(): JSONSet<ReturnType<Value['deepPartial']>>;
14
+ nonEmpty(this: JSONSet<Value>): JSONSet<Value> & { data: { min: 1 } };
15
+ }
16
+
17
+ export const set = <Value extends JSONTypeAny>(valueType: Value) => {
18
+ return constructType<JSONSet<Value>>({
19
+ dataType: 'set',
20
+ valueType,
21
+ deepPartial(this: JSONSet<Value>) {
22
+ return {
23
+ ...this,
24
+ valueType: this.valueType.deepPartial(),
25
+ };
26
+ },
27
+ nonEmpty(this: JSONSet<Value>) {
28
+ return this.min(1) as unknown as JSONSet<Value> & {
29
+ data: { min: 1 };
30
+ };
31
+ },
32
+ ...arrayMethods,
33
+ });
34
+ };
@@ -0,0 +1,40 @@
1
+ import { constructType, DeepPartial, JSONType, JSONTypeAny } from './typeBase';
2
+
3
+ export interface JSONTuple<
4
+ T extends JSONTupleItems | [] = JSONTupleItems,
5
+ Rest extends JSONTypeAny | null = null,
6
+ > extends JSONType<OutputTypeOfTupleWithRest<T, Rest>, 'tuple'> {
7
+ items: T;
8
+ deepPartial(): {
9
+ [k in keyof T]: T[k] extends JSONTypeAny ? DeepPartial<T[k]> : never;
10
+ } extends infer PI
11
+ ? PI extends JSONTupleItems
12
+ ? JSONTuple<PI>
13
+ : never
14
+ : never;
15
+ }
16
+
17
+ export type JSONTupleItems = [JSONTypeAny, ...JSONTypeAny[]];
18
+ export type AssertArray<T> = T extends unknown[] ? T : never;
19
+ export type OutputTypeOfTuple<T extends JSONTupleItems | []> = AssertArray<{
20
+ [k in keyof T]: T[k] extends JSONTypeAny ? T[k]['type'] : never;
21
+ }>;
22
+ export type OutputTypeOfTupleWithRest<
23
+ T extends JSONTupleItems | [],
24
+ Rest extends JSONTypeAny | null = null,
25
+ > = Rest extends JSONTypeAny
26
+ ? [...OutputTypeOfTuple<T>, ...Rest['type'][]]
27
+ : OutputTypeOfTuple<T>;
28
+
29
+ export const tuple = <T extends JSONTupleItems | []>(items: T) => {
30
+ return constructType<JSONTuple<T>>({
31
+ dataType: 'tuple',
32
+ items,
33
+ deepPartial(this: JSONTuple<T>) {
34
+ return {
35
+ ...this,
36
+ items: this.items.map((item) => item.deepPartial()),
37
+ };
38
+ },
39
+ });
40
+ };