@axium/core 0.5.5 → 0.6.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.
- package/dist/api.d.ts +5 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/preferences.d.ts +39 -0
- package/dist/preferences.js +27 -0
- package/dist/schemas.d.ts +4 -0
- package/dist/schemas.js +4 -0
- package/dist/user.d.ts +4 -7
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export interface AppMetadata {
|
|
|
39
39
|
* Types for all API endpoints
|
|
40
40
|
* @internal
|
|
41
41
|
*/
|
|
42
|
-
export interface
|
|
42
|
+
export interface $API {
|
|
43
43
|
metadata: {
|
|
44
44
|
GET: {
|
|
45
45
|
version: string;
|
|
@@ -118,8 +118,8 @@ export interface _apiTypes {
|
|
|
118
118
|
}, AccessControl];
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
export type Endpoint = keyof
|
|
122
|
-
export type APIFunction<Method extends RequestMethod, E extends Endpoint> = Method extends keyof
|
|
123
|
-
export type RequestBody<Method extends RequestMethod, E extends Endpoint> = Method extends keyof
|
|
124
|
-
export type Result<Method extends RequestMethod, E extends Endpoint> = Promise<Method extends keyof
|
|
121
|
+
export type Endpoint = keyof $API;
|
|
122
|
+
export type APIFunction<Method extends RequestMethod, E extends Endpoint> = Method extends keyof $API[E] ? $API[E][Method] extends [infer Body, infer Result] ? (body: Body) => Promise<Result> : () => $API[E][Method] : unknown;
|
|
123
|
+
export type RequestBody<Method extends RequestMethod, E extends Endpoint> = Method extends keyof $API[E] ? $API[E][Method] extends [infer Body, unknown] ? Body : any : unknown;
|
|
124
|
+
export type Result<Method extends RequestMethod, E extends Endpoint> = Promise<Method extends keyof $API[E] ? ($API[E][Method] extends [unknown, infer R] ? R : $API[E][Method]) : unknown>;
|
|
125
125
|
export type APIParameters<S extends string> = S extends `${string}/:${infer Right}` ? [string, ...APIParameters<Right>] : [];
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
/** @internal Used so we can narrow using `type` and get access to type-specific properties (e.g. `ZodNumber.minValue`) */
|
|
3
|
+
type StringFormatTypes = z.ZodGUID | z.ZodUUID | z.ZodEmail | z.ZodURL | z.ZodEmoji | z.ZodNanoID | z.ZodCUID | z.ZodCUID2 | z.ZodULID | z.ZodXID | z.ZodKSUID | z.ZodISODateTime | z.ZodISODate | z.ZodISOTime | z.ZodISODuration | z.ZodIPv4 | z.ZodIPv6 | z.ZodCIDRv4 | z.ZodCIDRv6 | z.ZodBase64 | z.ZodBase64URL | z.ZodE164 | z.ZodJWT;
|
|
4
|
+
type ZodPrefPrimitive = z.ZodString | z.ZodNumber | z.ZodBigInt | z.ZodBoolean | z.ZodDate | z.ZodLiteral | z.ZodTemplateLiteral | z.ZodFile | z.ZodEnum | StringFormatTypes;
|
|
5
|
+
type ZodPrefComposite = ZodPrefPrimitive | z.ZodNullable<ZodPrefPrimitive> | z.ZodOptional<ZodPrefPrimitive> | z.ZodArray<ZodPrefPrimitive> | z.ZodTuple<ZodPrefPrimitive[]> | z.ZodRecord<z.ZodString, ZodPrefPrimitive> | z.ZodObject<Readonly<Record<string, ZodPrefPrimitive>>>;
|
|
6
|
+
/** @internal Used so we can narrow using `type` and get access to type-specific properties (e.g. `ZodNumber.minValue`) */
|
|
7
|
+
export type ZodPref = ZodPrefComposite | z.ZodObject<Readonly<Record<string, ZodPrefComposite>>>;
|
|
8
|
+
/**
|
|
9
|
+
* Interface for the user preferences schema shape.
|
|
10
|
+
* Modify with `declare module ...`.
|
|
11
|
+
*/
|
|
12
|
+
export interface PreferenceSchemas {
|
|
13
|
+
debug: z.ZodBoolean;
|
|
14
|
+
}
|
|
15
|
+
export type PreferenceName = keyof PreferenceSchemas & string;
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare const preferenceSchemas: PreferenceSchemas;
|
|
20
|
+
export type Preferences = z.infer<z.ZodObject<Readonly<PreferenceSchemas>>>;
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare const preferenceDefaults: Preferences;
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
* @todo Implement proper localization
|
|
28
|
+
*/
|
|
29
|
+
export declare const preferenceLabels: Record<PreferenceName, string>;
|
|
30
|
+
export declare const preferenceDescriptions: Partial<Record<PreferenceName, string>>;
|
|
31
|
+
export interface PreferenceInit<T extends PreferenceName = PreferenceName> {
|
|
32
|
+
name: T;
|
|
33
|
+
schema: PreferenceSchemas[T] & ZodPref;
|
|
34
|
+
initial: z.infer<PreferenceSchemas[T] & ZodPref>;
|
|
35
|
+
label: string;
|
|
36
|
+
descriptions?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare function addPreference<T extends PreferenceName = PreferenceName>(init: PreferenceInit<T>): void;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export const preferenceSchemas = {
|
|
6
|
+
debug: z.boolean(),
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const preferenceDefaults = {
|
|
12
|
+
debug: false,
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
* @todo Implement proper localization
|
|
17
|
+
*/
|
|
18
|
+
export const preferenceLabels = {
|
|
19
|
+
debug: 'Debug mode',
|
|
20
|
+
};
|
|
21
|
+
export const preferenceDescriptions = {};
|
|
22
|
+
export function addPreference(init) {
|
|
23
|
+
preferenceSchemas[init.name] = init.schema;
|
|
24
|
+
preferenceDefaults[init.name] = init.initial;
|
|
25
|
+
preferenceLabels[init.name] = init.label;
|
|
26
|
+
preferenceDescriptions[init.name] = init.descriptions;
|
|
27
|
+
}
|
package/dist/schemas.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
+
/** Needed for discriminated union type narrowing */
|
|
3
|
+
export declare function zIs<const T extends z.core.$ZodTypeDef['type']>(schema: z.ZodType, type: T): schema is z.ZodType & {
|
|
4
|
+
type: T;
|
|
5
|
+
};
|
|
2
6
|
export declare function zFunction<T extends z.core.$ZodFunction>(schema: T): z.ZodCustom<Parameters<T["implement"]>[0], Parameters<T["implement"]>[0]>;
|
|
3
7
|
export declare function zAsyncFunction<T extends z.core.$ZodFunction>(schema: T): z.ZodCustom<Parameters<T["implementAsync"]>[0], Parameters<T["implementAsync"]>[0]>;
|
|
4
8
|
export declare const authenticatorAttachment: z.ZodOptional<z.ZodLiteral<"cross-platform" | "platform">>;
|
package/dist/schemas.js
CHANGED
package/dist/user.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
|
|
3
|
-
* User preferences.
|
|
4
|
-
* Modify with `declare module ...`
|
|
5
|
-
*/
|
|
6
|
-
export interface Preferences {
|
|
7
|
-
}
|
|
2
|
+
import type { Preferences } from './preferences.js';
|
|
8
3
|
export declare const User: z.ZodObject<{
|
|
9
4
|
id: z.ZodUUID;
|
|
10
5
|
name: z.ZodString;
|
|
@@ -29,6 +24,8 @@ export declare const UserChangeable: z.ZodObject<{
|
|
|
29
24
|
image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
|
|
30
25
|
preferences: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
31
26
|
}, z.core.$strip>;
|
|
32
|
-
export
|
|
27
|
+
export interface UserChangeable extends z.infer<typeof UserChangeable> {
|
|
28
|
+
preferences?: Preferences;
|
|
29
|
+
}
|
|
33
30
|
export declare function getUserImage(user: Partial<User>): string;
|
|
34
31
|
export {};
|