@rwillians/qx 0.1.20 → 0.2.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.
@@ -0,0 +1,189 @@
1
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
2
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
3
+ }
4
+ declare namespace StandardSchemaV1 {
5
+ export interface Props<Input = unknown, Output = Input> {
6
+ readonly version: 1;
7
+ readonly vendor: string;
8
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
9
+ readonly types?: Types<Input, Output> | undefined;
10
+ }
11
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
12
+ export interface SuccessResult<Output> {
13
+ readonly value: Output;
14
+ readonly issues?: undefined;
15
+ }
16
+ export interface FailureResult {
17
+ readonly issues: ReadonlyArray<Issue>;
18
+ }
19
+ export interface Issue {
20
+ readonly message: string;
21
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
22
+ }
23
+ export interface PathSegment {
24
+ readonly key: PropertyKey;
25
+ }
26
+ export interface Types<Input = unknown, Output = Input> {
27
+ readonly input: Input;
28
+ readonly output: Output;
29
+ }
30
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
31
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
32
+ export {};
33
+ }
34
+ /**
35
+ * @public The Standard Schema interface.
36
+ * @since 0.1.0
37
+ * @version 1
38
+ */
39
+ export { type StandardSchemaV1 as Schema };
40
+ /**
41
+ * @public Infers the input type of a Standard Schema.
42
+ * @since 0.1.0
43
+ * @version 1
44
+ */
45
+ export type input<T extends StandardSchemaV1> = StandardSchemaV1.InferInput<T>;
46
+ /**
47
+ * @public Infers the Input type of a Standard Schema.
48
+ * @since 0.1.0
49
+ * @version 1
50
+ */
51
+ export type output<T extends StandardSchemaV1> = StandardSchemaV1.InferOutput<T>;
52
+ /**
53
+ * @public Use any standard schema to parse a value.
54
+ * @since 0.1.0
55
+ * @version 1
56
+ */
57
+ export declare const parse: <T extends StandardSchemaV1>(schema: T, value: unknown) => StandardSchemaV1.Result<output<T>>;
58
+ /**
59
+ * @public Defines an array of a given standard schema.
60
+ * @since 0.1.0
61
+ * @version 1
62
+ */
63
+ export type QxArray<T extends StandardSchemaV1> = StandardSchemaV1<input<T>[], output<T>[]>;
64
+ /**
65
+ * @public Defines an array of a given standard schema.
66
+ * @since 0.1.0
67
+ * @version 1
68
+ */
69
+ export declare const array: <T extends StandardSchemaV1>(schema: T) => QxArray<T>;
70
+ /**
71
+ * @public Defines a standard schema for boolean values.
72
+ * @since 0.1.0
73
+ * @version 1
74
+ */
75
+ export type QxBoolean = StandardSchemaV1<boolean, boolean>;
76
+ /**
77
+ * @public Defines a standard schema for boolean values.
78
+ * @since 0.1.0
79
+ * @version 1
80
+ */
81
+ export declare const boolean: () => QxBoolean;
82
+ /**
83
+ * @public Defines a standard schema for Date values that can be
84
+ * coerced from ISO 8601 strings or epoch timestamps in
85
+ * milliseconds.
86
+ * @since 0.1.0
87
+ * @version 1
88
+ */
89
+ export type QxCoercibleDate = StandardSchemaV1<Date | string | number, Date>;
90
+ /**
91
+ * @public Defines a standard schema for Date values that can be
92
+ * coerced from ISO 8601 strings or epoch timestamps in
93
+ * milliseconds.
94
+ * @since 0.1.0
95
+ * @version 1
96
+ */
97
+ export declare const date: () => QxCoercibleDate;
98
+ /**
99
+ * @public Defines a standard schema that validates instances of a
100
+ * given class.
101
+ * @since 0.1.0
102
+ * @version 1
103
+ */
104
+ export type QxInstanceOf<T> = StandardSchemaV1<T, T>;
105
+ /**
106
+ * @public Defines a standard schema that validates instances of a
107
+ * given class.
108
+ * @since 0.1.0
109
+ * @version 1
110
+ */
111
+ export declare const instanceOf: <T>(ctor: new (...args: any[]) => T) => QxInstanceOf<T>;
112
+ /**
113
+ * @public Defines a standard schema for integers with optional min
114
+ * and max constraints.
115
+ * @since 0.1.0
116
+ * @version 1
117
+ */
118
+ export type QxInteger = StandardSchemaV1<number, number>;
119
+ /**
120
+ * @public Defines a standard schema for integers with optional min and max constraints.
121
+ * @since 0.1.0
122
+ * @version 1
123
+ */
124
+ export declare const integer: ({ min, max }?: {
125
+ min?: number;
126
+ max?: number;
127
+ }) => QxInteger;
128
+ /**
129
+ * @public Makes any standard schema nullable.
130
+ * @since 0.1.0
131
+ * @version 1
132
+ */
133
+ export type QxNullable<T extends StandardSchemaV1 = StandardSchemaV1> = StandardSchemaV1<input<T> | null, output<T> | null>;
134
+ /**
135
+ * @public Makes any standard schema accepts `null` as a valid value.
136
+ * @since 0.1.0
137
+ * @version 1
138
+ */
139
+ export declare const nullable: <T extends StandardSchemaV1>(schema: T) => QxNullable<T>;
140
+ /**
141
+ * @public Defines a standard schema for numbers with optional min
142
+ * and max constraints.
143
+ * @since 0.1.0
144
+ * @version 1
145
+ */
146
+ export type QxNumber = StandardSchemaV1<number, number>;
147
+ /**
148
+ * @public Defines a standard schema for numbers with optional min
149
+ * and max constraints.
150
+ * @since 0.1.0
151
+ * @version 1
152
+ */
153
+ export declare const number: ({ min, max }?: {
154
+ min?: number;
155
+ max?: number;
156
+ }) => QxNumber;
157
+ /**
158
+ * @public Defines an object schema that does not allow extra fields.
159
+ * @since 0.1.0
160
+ * @version 1
161
+ */
162
+ type QxStrictObject<T extends Record<string, StandardSchemaV1>> = StandardSchemaV1<{
163
+ [K in keyof T]: input<T[K]>;
164
+ }, {
165
+ [K in keyof T]: output<T[K]>;
166
+ }>;
167
+ /**
168
+ * @public Defines an object schema that does not allow extra fields.
169
+ * @since 0.1.0
170
+ * @version 1
171
+ */
172
+ export declare const strictObject: <T extends Record<string, StandardSchemaV1>>(shape: T) => QxStrictObject<T>;
173
+ /**
174
+ * @public Defines a standard schema for strings with optional min
175
+ * and max length constraints.
176
+ * @since 0.1.0
177
+ * @version 1
178
+ */
179
+ export type QxString = StandardSchemaV1<string, string>;
180
+ /**
181
+ * @public Defines a standard schema for strings with optional min
182
+ * and max length constraints.
183
+ * @since 0.1.0
184
+ * @version 1
185
+ */
186
+ export declare const string: ({ min, max }?: {
187
+ min?: number;
188
+ max?: number;
189
+ }) => QxString;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @private Converts a snake_case string to camelCase at the type
3
+ * level.
4
+ * @since 0.1.17
5
+ * @version 1
6
+ */
7
+ type CamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<CamelCase<U>>}` : S;
8
+ /**
9
+ * @private Converts a camelCase string to snake_case at the type
10
+ * level.
11
+ * @since 0.1.17
12
+ * @version 1
13
+ */
14
+ type SnakeCase<S extends string> = S extends `${infer T}${infer U}` ? U extends Uncapitalize<U> ? `${Lowercase<T>}${SnakeCase<U>}` : `${Lowercase<T>}_${SnakeCase<Uncapitalize<U>>}` : S;
15
+ /**
16
+ * @private Converts a snake_case string to camelCase.
17
+ * @since 0.1.0
18
+ * @version 2
19
+ */
20
+ export declare const camelCase: <T extends string>(str: T) => CamelCase<T>;
21
+ /**
22
+ * @private Same as {@link Object.prototype.entries} but with better
23
+ * types.
24
+ * @since 0.1.17
25
+ * @version 1
26
+ */
27
+ export declare const entries: <T extends Record<string, any>>(obj: T) => [keyof T, T[keyof T]][];
28
+ /**
29
+ * @private Simplified check for plain objects.
30
+ * @since 0.1.0
31
+ * @version 1
32
+ */
33
+ export declare const isPlainObject: (value: unknown) => value is Record<string, any>;
34
+ /**
35
+ * @private Same as {@link Object.prototype.keys} but with better
36
+ * types.
37
+ * @since 0.1.17
38
+ * @version 1
39
+ */
40
+ export declare const keys: <T extends Record<string, any>>(obj: T) => (keyof T)[];
41
+ /**
42
+ * @private Throws an error if the given number is greater than the
43
+ * specified maximum.
44
+ * @since 0.1.0
45
+ * @version 1
46
+ */
47
+ export declare const lte: (n: number, max: number) => number;
48
+ /**
49
+ * @public Maps over the keys of an object.
50
+ * @since 0.1.0
51
+ * @version 1
52
+ */
53
+ export declare const mapKeys: <T extends Record<string, any>, U extends string>(obj: T, fn: (key: keyof T) => U) => { [K in U]: T[keyof T]; };
54
+ /**
55
+ * @private Maps over the values of an object.
56
+ * @since 0.1.0
57
+ * @version 1
58
+ */
59
+ export declare const mapValues: <T extends Record<string, any>, U>(obj: T, fn: (value: T[keyof T], key: keyof T) => U) => { [K in keyof T]: U; };
60
+ /**
61
+ * @private Resolves the given value or function to a value.
62
+ * @since 0.1.0
63
+ * @version 1
64
+ */
65
+ export declare const resolve: <T>(value: T | (() => T)) => T;
66
+ /**
67
+ * @private Converts a camelCase string to snake_case.
68
+ * @since 0.1.0
69
+ * @version 1
70
+ */
71
+ export declare const snakeCase: <T extends string>(str: T) => SnakeCase<T>;
72
+ /**
73
+ * @public Wraps the given value in an array, unless it's already an
74
+ * array.
75
+ * @since 0.1.0
76
+ * @version 1
77
+ */
78
+ export declare const wrap: <T>(value: T | T[]) => T[];
79
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rwillians/qx",
3
3
  "description": "A zero-dependencies teeny tiny ORM for SQLite.",
4
- "version": "0.1.20",
4
+ "version": "0.2.0",
5
5
  "author": "Rafael Willians <me@rwillians.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -62,9 +62,10 @@
62
62
  "build:esm": "bun run --bun tsc --project tsconfig-esm.json"
63
63
  },
64
64
  "devDependencies": {
65
- "@types/bun": "latest"
65
+ "@types/bun": "^1.3.9",
66
+ "@types/node": "^25.3.0"
66
67
  },
67
68
  "peerDependencies": {
68
- "typescript": "latest"
69
+ "typescript": "^5.9.3"
69
70
  }
70
71
  }