akanjs 2.3.1 → 2.3.2-rc.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.
@@ -48,10 +48,10 @@ export type FieldToValue<Field, MapValue = any> = Field extends null
48
48
  export interface FieldInfoObject {
49
49
  [key: string]: FieldInfo<any, ConstantFieldTypeInput | null, any>;
50
50
  }
51
- export type ExtractFieldInfoObject<Obj extends FieldInfoObject> = {
52
- [K in keyof Obj]: Obj[K] extends FieldInfo<any, infer FieldValue, infer ExplicitType, infer MapValue>
51
+ export type ExtractFieldInfoObject<Obj extends FieldInfoObject, NullableType extends string = "hidden" | "secret"> = {
52
+ [K in keyof Obj]: Obj[K] extends FieldInfo<infer FieldType, infer FieldValue, infer ExplicitType, infer MapValue>
53
53
  ? unknown extends ExplicitType
54
- ? FieldToValue<FieldValue, MapValue>
54
+ ? FieldToValue<FieldValue | (FieldType extends NullableType ? null : never), MapValue>
55
55
  : ExplicitType
56
56
  : never;
57
57
  };
@@ -381,7 +381,7 @@ field.hidden = <
381
381
  value: Value,
382
382
  option: FieldOption<Value, MapValue> = {},
383
383
  ) =>
384
- new FieldInfo<"hidden", Value | null, ExplicitType | null, MapValue>(value, {
384
+ new FieldInfo<"hidden", Value, ExplicitType, MapValue>(value, {
385
385
  ...option,
386
386
  fieldType: "hidden",
387
387
  nullable: true,
@@ -394,7 +394,7 @@ field.secret = <
394
394
  value: Value,
395
395
  option: FieldOption<Value, MapValue> = {},
396
396
  ) =>
397
- new FieldInfo<"secret", Value | null, ExplicitType | null, MapValue>(value, {
397
+ new FieldInfo<"secret", Value, ExplicitType, MapValue>(value, {
398
398
  ...option,
399
399
  fieldType: "secret",
400
400
  select: false,
package/constant/via.ts CHANGED
@@ -129,7 +129,7 @@ const getBaseConstantClass = (field: FieldObject, modelType: ConstantType = "sca
129
129
  static relations: Set<ConstantCls> = new Set();
130
130
  static enums: Set<EnumInstance> = new Set();
131
131
  [immerable] = true;
132
- constructor(obj?: Partial<typeof this>) {
132
+ constructor(obj?: Partial<unknown>) {
133
133
  this.set({
134
134
  ...(this.constructor as ConstantCls).getDefault(),
135
135
  ...((obj ?? {}) as Partial<typeof this>),
package/document/by.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { type Cls, FIELD_META, type MergeAllActionTypes, type UnCls } from "akanjs/base";
1
+ import { type Cls, FIELD_META, type MergeAllActionTypes } from "akanjs/base";
2
2
  import { applyMixins } from "akanjs/common";
3
3
  import {
4
4
  type BaseObject,
5
5
  type ConstantCls,
6
+ type ConstantField,
6
7
  ConstantRegistry,
7
8
  type DocumentModel,
8
9
  type FieldObject,
@@ -22,11 +23,19 @@ type HydratedDocumentWithId<TDocument> = TDocument & { id: string } & DefaultDoc
22
23
  export type Doc<M = any> = HydratedDocumentWithId<DocumentModel<M>>;
23
24
 
24
25
  export const by = <
25
- ModelCls,
26
+ Schema,
27
+ FieldObj extends FieldObject,
26
28
  AddDbModels extends DatabaseCls[],
27
- _DocModel = UnCls<ModelCls> extends BaseObject ? Doc<UnCls<ModelCls>> : DocumentModel<UnCls<ModelCls>>,
29
+ _DatabaseSchema = Schema & {
30
+ [K in keyof FieldObj & keyof Schema as FieldObj[K] extends ConstantField<infer FieldType, any, any, any, any, any>
31
+ ? FieldType extends "hidden"
32
+ ? K
33
+ : never
34
+ : never]: NonNullable<Schema[K]>;
35
+ },
36
+ _DocModel = Schema extends BaseObject ? Doc<_DatabaseSchema> : DocumentModel<_DatabaseSchema>,
28
37
  >(
29
- modelRef: ModelCls,
38
+ modelRef: ConstantCls<Schema, FieldObj>,
30
39
  ...addRefs: AddDbModels
31
40
  ): DatabaseCls<MergeAllActionTypes<AddDbModels, keyof _DocModel & string> & _DocModel> => {
32
41
  const refName = ConstantRegistry.getRefName(modelRef as Cls);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "2.3.1",
3
+ "version": "2.3.2-rc.0",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -11,8 +11,8 @@ export type FieldToValue<Field, MapValue = any> = Field extends null ? FieldToVa
11
11
  export interface FieldInfoObject {
12
12
  [key: string]: FieldInfo<any, ConstantFieldTypeInput | null, any>;
13
13
  }
14
- export type ExtractFieldInfoObject<Obj extends FieldInfoObject> = {
15
- [K in keyof Obj]: Obj[K] extends FieldInfo<any, infer FieldValue, infer ExplicitType, infer MapValue> ? unknown extends ExplicitType ? FieldToValue<FieldValue, MapValue> : ExplicitType : never;
14
+ export type ExtractFieldInfoObject<Obj extends FieldInfoObject, NullableType extends string = "hidden" | "secret"> = {
15
+ [K in keyof Obj]: Obj[K] extends FieldInfo<infer FieldType, infer FieldValue, infer ExplicitType, infer MapValue> ? unknown extends ExplicitType ? FieldToValue<FieldValue | (FieldType extends NullableType ? null : never), MapValue> : ExplicitType : never;
16
16
  };
17
17
  export type ConstantFieldKind = "property" | "hidden" | "secret" | "resolve";
18
18
  export interface ConstantFieldProps<FieldType extends ConstantFieldKind = ConstantFieldKind, FieldValue = any, MapValue = any, Metadata = {
@@ -144,8 +144,8 @@ export type PlainTypeToFieldType<PlainType> = PlainType extends [infer First, ..
144
144
  /** Builds a stored property field with optional validation, default, ref, text, and metadata options. */
145
145
  export declare const field: {
146
146
  <ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<"property", Value, ExplicitType, MapValue>;
147
- hidden<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<"hidden", Value | null, ExplicitType | null, MapValue>;
148
- secret<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<"secret", Value | null, ExplicitType | null, MapValue>;
147
+ hidden<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<"hidden", Value, ExplicitType, MapValue>;
148
+ secret<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<"secret", Value, ExplicitType, MapValue>;
149
149
  };
150
150
  /** Builds a resolved field that is derived rather than treated as a stored property. */
151
151
  export declare const resolve: <ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>) => FieldInfo<"resolve", Value, ExplicitType, MapValue>;
@@ -1,5 +1,5 @@
1
- import { type Cls, FIELD_META, type MergeAllActionTypes, type UnCls } from "akanjs/base";
2
- import { type BaseObject, type DocumentModel, type FieldObject } from "akanjs/constant";
1
+ import { type Cls, FIELD_META, type MergeAllActionTypes } from "akanjs/base";
2
+ import { type BaseObject, type ConstantCls, type ConstantField, type DocumentModel, type FieldObject } from "akanjs/constant";
3
3
  export type DatabaseCls<Schema = any> = Cls<Schema, {
4
4
  refName: string;
5
5
  [FIELD_META]: FieldObject;
@@ -16,5 +16,5 @@ type HydratedDocumentWithId<TDocument> = TDocument & {
16
16
  id: string;
17
17
  } & DefaultDocMtds<TDocument>;
18
18
  export type Doc<M = any> = HydratedDocumentWithId<DocumentModel<M>>;
19
- export declare const by: <ModelCls, AddDbModels extends DatabaseCls[], _DocModel = UnCls<ModelCls> extends BaseObject ? Doc<UnCls<ModelCls>> : DocumentModel<UnCls<ModelCls>>>(modelRef: ModelCls, ...addRefs: AddDbModels) => DatabaseCls<MergeAllActionTypes<AddDbModels, keyof _DocModel & string> & _DocModel>;
19
+ export declare const by: <Schema, FieldObj extends FieldObject, AddDbModels extends DatabaseCls[], _DatabaseSchema = Schema & { [K in keyof FieldObj & keyof Schema as FieldObj[K] extends ConstantField<infer FieldType, any, any, any, any, any> ? FieldType extends "hidden" ? K : never : never]: NonNullable<Schema[K]>; }, _DocModel = Schema extends BaseObject ? Doc<_DatabaseSchema> : DocumentModel<_DatabaseSchema>>(modelRef: ConstantCls<Schema, FieldObj>, ...addRefs: AddDbModels) => DatabaseCls<MergeAllActionTypes<AddDbModels, keyof _DocModel & string> & _DocModel>;
20
20
  export {};