@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 CHANGED
@@ -39,7 +39,7 @@ export interface AppMetadata {
39
39
  * Types for all API endpoints
40
40
  * @internal
41
41
  */
42
- export interface _apiTypes {
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 _apiTypes;
122
- export type APIFunction<Method extends RequestMethod, E extends Endpoint> = Method extends keyof _apiTypes[E] ? _apiTypes[E][Method] extends [infer Body, infer Result] ? (body: Body) => Promise<Result> : () => _apiTypes[E][Method] : unknown;
123
- export type RequestBody<Method extends RequestMethod, E extends Endpoint> = Method extends keyof _apiTypes[E] ? _apiTypes[E][Method] extends [infer Body, unknown] ? Body : any : unknown;
124
- export type Result<Method extends RequestMethod, E extends Endpoint> = Promise<Method extends keyof _apiTypes[E] ? (_apiTypes[E][Method] extends [unknown, infer R] ? R : _apiTypes[E][Method]) : unknown>;
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
@@ -1,6 +1,7 @@
1
1
  export * from './access.js';
2
2
  export * from './api.js';
3
3
  export * as icons from './icons.js';
4
+ export * from './preferences.js';
4
5
  export * from './requests.js';
5
6
  export * from './schemas.js';
6
7
  export * from './user.js';
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './access.js';
2
2
  export * from './api.js';
3
3
  export * as icons from './icons.js';
4
+ export * from './preferences.js';
4
5
  export * from './requests.js';
5
6
  export * from './schemas.js';
6
7
  export * from './user.js';
@@ -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
@@ -1,4 +1,8 @@
1
1
  import * as z from 'zod';
2
+ /** Needed for discriminated union type narrowing */
3
+ export function zIs(schema, type) {
4
+ return schema.def.type == type;
5
+ }
2
6
  export function zFunction(schema) {
3
7
  return z.custom((fn) => schema.implement(fn));
4
8
  }
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 type UserChangeable = z.infer<typeof UserChangeable>;
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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/core",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "funding": {
6
6
  "type": "individual",