@aeriajs/types 0.0.131 → 0.0.133

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/config.d.ts CHANGED
@@ -4,11 +4,18 @@ import type { RateLimitingParams } from './security.js';
4
4
  import type { CollectionItem } from './collection.js';
5
5
  import type { UserRole } from './token.js';
6
6
  export type RolesHierarchy = Record<UserRole, readonly UserRole[] | boolean>;
7
+ export type CorsConfig = {
8
+ allowOrigin?: readonly string[];
9
+ allowMethods?: readonly string[];
10
+ allowHeaders?: readonly string[];
11
+ maxAge: string;
12
+ };
7
13
  export type ServerOptions = {
8
14
  host?: string;
9
15
  port?: number;
10
16
  enableLogging?: boolean;
11
17
  noWarmup?: boolean;
18
+ cors?: CorsConfig | null;
12
19
  };
13
20
  export type ApiConfig = {
14
21
  name?: string;
package/dist/schema.d.ts CHANGED
@@ -13,11 +13,17 @@ type CaseTimestamped<TSchema, TType> = TSchema extends {
13
13
  timestamps: false;
14
14
  } ? TType : TType & Timestamped;
15
15
  type TestType<T> = T & Record<string, unknown>;
16
- export type InferProperty<T> = T extends TestType<{
16
+ type SchemaOptions = {
17
+ readonly keepTempIds?: boolean;
18
+ readonly useObjectIds?: boolean;
19
+ };
20
+ export type InferProperty<T, TSchemaOptions extends SchemaOptions = {}> = T extends TestType<{
17
21
  format: 'date' | 'date-time';
18
22
  }> ? Date : T extends TestType<{
19
23
  format: 'objectid';
20
- }> ? ObjectId : T extends TestType<{
24
+ }> ? TSchemaOptions extends {
25
+ useObjectIds: false;
26
+ } ? string : ObjectId : T extends TestType<{
21
27
  enum: ReadonlyArray<infer K>;
22
28
  }> ? K : T extends TestType<{
23
29
  type: 'string';
@@ -29,15 +35,15 @@ export type InferProperty<T> = T extends TestType<{
29
35
  properties: unknown;
30
36
  }> ? Schema<T & {
31
37
  timestamps: false;
32
- }> : T extends TestType<{
38
+ }, TSchemaOptions> : T extends TestType<{
33
39
  additionalProperties: true;
34
40
  }> ? any : T extends TestType<{
35
41
  additionalProperties: infer K;
36
42
  }> ? {
37
- [P: string]: InferProperty<K> | undefined;
43
+ [P: string]: InferProperty<K, TSchemaOptions> | undefined;
38
44
  } : T extends TestType<{
39
45
  items: infer K;
40
- }> ? InferProperty<K>[] : T extends TestType<{
46
+ }> ? InferProperty<K, TSchemaOptions>[] : T extends TestType<{
41
47
  getter: (doc: unknown) => infer K;
42
48
  }> ? Awaited<K> : T extends TestType<{
43
49
  const: infer K;
@@ -47,9 +53,6 @@ export type InferProperty<T> = T extends TestType<{
47
53
  type ExtractRequiredPropNames<T> = T extends readonly (infer PropName)[] ? PropName : Record<never, never> extends T ? null : keyof {
48
54
  [K in keyof T as T[K] extends true ? K : never]: never;
49
55
  };
50
- type SchemaOptions = {
51
- readonly keepTempIds?: boolean;
52
- };
53
56
  export type InferSchema<TSchema, TSchemaOptions extends SchemaOptions = {}> = MergeReferences<TSchema, TSchemaOptions> extends infer MappedTypes ? TSchema extends {
54
57
  required: readonly [];
55
58
  } ? Partial<MappedTypes> : TSchema extends {
@@ -57,22 +60,24 @@ export type InferSchema<TSchema, TSchemaOptions extends SchemaOptions = {}> = Me
57
60
  } ? ExtractRequiredPropNames<InferredRequired> extends infer RequiredPropName ? Pick<MappedTypes, Extract<keyof MappedTypes, RequiredPropName>> extends infer RequiredProps ? RequiredProps & Partial<Exclude<MappedTypes, keyof RequiredProps>> : never : Partial<MappedTypes> : MappedTypes : never;
58
61
  export type Schema<TSchema, TSchemaOptions extends SchemaOptions = {}> = CaseTimestamped<TSchema, CaseOwned<TSchema, InferSchema<TSchema, TSchemaOptions>>>;
59
62
  export type SchemaWithId<TSchema, TSchemaOptions extends SchemaOptions = {}> = Schema<TSchema, TSchemaOptions> & {
60
- _id: ObjectId;
63
+ _id: TSchemaOptions extends {
64
+ useObjectIds: false;
65
+ } ? string : ObjectId;
61
66
  };
62
- export type InferProperties<TSchema> = (TSchema extends readonly unknown[] ? TSchema extends readonly (infer SchemaOption)[] ? SchemaOption extends unknown ? SchemaOption : never : never : TSchema) extends infer InferredSchema ? InferredSchema extends {
67
+ export type InferProperties<TSchema, TSchemaOptions extends SchemaOptions = {}> = (TSchema extends readonly unknown[] ? TSchema extends readonly (infer SchemaOption)[] ? SchemaOption extends unknown ? SchemaOption : never : never : TSchema) extends infer InferredSchema ? InferredSchema extends {
63
68
  $ref: infer K;
64
69
  } | {
65
70
  items: {
66
71
  $ref: infer K;
67
72
  };
68
- } ? K extends keyof Collections ? 'items' extends keyof InferredSchema ? Collections[K]['item'][] : Collections[K]['item'] : never : InferProperty<InferredSchema> : never;
73
+ } ? K extends keyof Collections ? 'items' extends keyof InferredSchema ? Collections[K]['item'][] : Collections[K]['item'] : never : InferProperty<InferredSchema, TSchemaOptions> : never;
69
74
  export type PackReferences<T> = {
70
75
  [P in keyof T]: PackReferencesAux<T[P]>;
71
76
  };
72
- export type FilterReadonlyProperties<TProperties> = {
77
+ export type FilterReadonlyProperties<TProperties, TSchemaOptions extends SchemaOptions = {}> = {
73
78
  [P in keyof TProperties as TProperties[P] extends {
74
79
  readOnly: true;
75
- } ? P : never]: InferProperty<TProperties[P]>;
80
+ } ? P : never]: InferProperty<TProperties[P], TSchemaOptions>;
76
81
  };
77
82
  type MapReferences<TSchema, TSchemaOptions extends SchemaOptions> = TSchema extends {
78
83
  properties: infer Properties;
@@ -102,10 +107,10 @@ type MapReferences<TSchema, TSchemaOptions extends SchemaOptions> = TSchema exte
102
107
  type PackReferencesAux<T> = T extends (...args: unknown[]) => unknown ? T : T extends ObjectId ? T : T extends {
103
108
  _id: infer Id;
104
109
  } ? Id : T extends Record<string, unknown> ? PackReferences<T> : T extends unknown[] | readonly unknown[] ? PackReferencesAux<T[number]>[] : T;
105
- type CombineProperties<TSchema> = TSchema extends {
110
+ type CombineProperties<TSchema, TSchemaOptions extends SchemaOptions> = TSchema extends {
106
111
  properties: infer Properties;
107
- } ? FilterReadonlyProperties<Properties> extends infer ReadonlyProperties ? Readonly<ReadonlyProperties> & {
108
- [P in Exclude<keyof Properties, keyof ReadonlyProperties>]: InferProperty<Properties[P]>;
112
+ } ? FilterReadonlyProperties<Properties, TSchemaOptions> extends infer ReadonlyProperties ? Readonly<ReadonlyProperties> & {
113
+ [P in Exclude<keyof Properties, keyof ReadonlyProperties>]: InferProperty<Properties[P], TSchemaOptions>;
109
114
  } : never : never;
110
- type MergeReferences<TSchema, TSchemaOptions extends SchemaOptions> = CombineProperties<TSchema> extends infer CombinedProperties ? MapReferences<TSchema, TSchemaOptions> extends infer MappedReferences ? MappedReferences & Omit<CombinedProperties, keyof MappedReferences> : never : never;
115
+ type MergeReferences<TSchema, TSchemaOptions extends SchemaOptions> = CombineProperties<TSchema, TSchemaOptions> extends infer CombinedProperties ? MapReferences<TSchema, TSchemaOptions> extends infer MappedReferences ? MappedReferences & Omit<CombinedProperties, keyof MappedReferences> : never : never;
111
116
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.131",
3
+ "version": "0.0.133",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",