Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db: Fixed typing, docs and a simple error #281

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions examples/schemas/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import { setDefaultAdapter, getSchemasWithDefaultAdapter, object, string, schema } from '@palmares/schemas';
import { getSchemasWithDefaultAdapter, object, schema, setDefaultAdapter, string } from '@palmares/schemas';
import { ZodSchemaAdapter, z } from '@palmares/zod-schema';


setDefaultAdapter(new ZodSchemaAdapter());
const p = getSchemasWithDefaultAdapter<ZodSchemaAdapter>();

Expand All @@ -13,10 +11,11 @@ const userSchema = p.object({
password: p.string().minLength(6),
company: p.object({
id: p.number(),
name: p.string(),
}),
})
name: p.string()
})
});

/*
const main = async () => {
const testSchema = p.object({
companyId: p.number().toRepresentation(async (value) => {
Expand Down Expand Up @@ -56,7 +55,7 @@ const main = async () => {
},
});
console.log(value.test.isTest);*/
/*const [testeResult, teste2Result, teste3Result, teste4Result] = await Promise.all([
/*const [testeResult, teste2Result, teste3Result, teste4Result] = await Promise.all([
objectSchema.parse({
teste: 10,
}),
Expand All @@ -74,13 +73,13 @@ const main = async () => {
},
}),
]);*/
/*
/*
const teste4Result = await objectSchema.parse({
teste: {
age: 10,
},
});*/
/*
/*
console.log('______//_______');
console.log(testeResult.errors);
console.log(testeResult.parsed);
Expand All @@ -93,14 +92,15 @@ const main = async () => {
console.log(teste3Result.errors);
console.log(teste3Result.parsed);
*/
/*
/*
console.log('______//_______');
console.log(teste4Result.errors);
console.log(teste4Result.parsed);
*/
/*.compile({
/*.compile({
testSchema: objectSchema,
});*/
});* /
};

main();
*/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build:watch": "turbo run build:watch --concurrency 20",
"build:watch:tests": "turbo run build:watch --filter=@palmares/core --filter=@palmares/tests --filter=@palmares/jest-tests",
"build:watch:schemas": "turbo run build:watch --filter=@palmares/core --filter=@palmares/schemas --filter=@palmares/zod-schema",
"build:watch:databases": "turbo run build:watch --filter=@palmares/core --filter=@palmares/databases --filter=@palmares/drizzle-engine --filter=@palmares/sequelize-engine",
"build:watch:databases": "turbo run build:watch --filter=@palmares/core --filter=@palmares/databases",
"build:watch:server": "turbo run build:watch --filter=@palmares/core --filter=@palmares/server --filter=@palmares/express-adapter",
"dev": "turbo run dev --parallel",
"examples:server-express-only": "turbo run dev --parallel --filter=@examples/server-express-only --filter=@palmares/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/databases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default setDatabaseConfig({
// @ts-ignore
path: import.meta.dirname, // If your package.json does not contain the "type": "module" in it, change that to __dirname
getMigrations: () => [],
getModels: () => [authenticatedUsers, questions],
getModels: () => [User, Company],
},
],
std: new NodeStd(),
Expand Down
4 changes: 2 additions & 2 deletions packages/databases/__tests__/src/drizzle/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@palmares/databases';

import type * as d /*{ Company as DCompany, User as DUser }*/ from '../../.drizzle/schema';
import { ModelOptionsType } from '@palmares/databases';
import type { ModelOptionsType } from '@palmares/databases';

class Authentication extends Manager<CompanyAbstract> {
authenticate(username: string, password: string) {
Expand Down Expand Up @@ -79,7 +79,7 @@ export class User extends Model<User>() {
companyId: ForeignKeyField.new({
onDelete: ON_DELETE.CASCADE,
relatedName: 'usersOfCompany',
relationName: 'company',
relationName: 'company2',
toField: 'id',
relatedTo: () => Company
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/databases/docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default setDatabaseConfig({
// @ts-ignore
path: import.meta.dirname, // If your package.json does not contain the "type": "module" in it, change that to __dirname
getMigrations: () => [],
getModels: () => [authenticatedUsers, questions],
getModels: () => [User, Company],
},
],
std: new NodeStd(),
Expand Down
6 changes: 3 additions & 3 deletions packages/databases/src/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function loadDatabases(databaseDomains?: DatabaseDomainInterface[]) {

const databaseDomainModifier = domain<{
getModels: (
engineInstance: DatabaseAdapter
engineInstance: DatabaseAdapter<any>
) =>
| Promise<Record<string, ReturnType<typeof BaseModel>> | ReturnType<typeof BaseModel>[]>
| Record<string, ReturnType<typeof BaseModel>>
Expand Down Expand Up @@ -99,8 +99,8 @@ export const databasesDomain = domain('@palmares/database', '', {
// eslint-disable-next-line ts/require-await
getMigrations: async () => defaultMigrations,
// eslint-disable-next-line ts/require-await
getModels: async (engineInstance: DatabaseAdapter) => {
if (engineInstance.migrations) return defaultModels;
getModels: async (engineInstance: DatabaseAdapter<any>) => {
if (engineInstance.migrations) return defaultModels as any;
else return [];
}
});
6 changes: 3 additions & 3 deletions packages/databases/src/models/fields/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export function auto(): AutoField<
* ```
*/
export class AutoField<
TType extends { create: any; read: any; update: any } = {
out TType extends { create: any; read: any; update: any } = {
create: number | undefined | null;
read: number;
update: number | undefined | null;
},
TDefinitions extends {
out TDefinitions extends {
hasDefaultValue: boolean;
unique: boolean;
auto: boolean;
Expand All @@ -97,7 +97,7 @@ export class AutoField<
engineInstance: DatabaseAdapter;
customAttributes: any;
},
TFieldOperationTypes = Pick<
out TFieldOperationTypes = Pick<
FieldWithOperationTypeForSearch<number>,
'lessThan' | 'greaterThan' | 'and' | 'in' | 'or' | 'eq' | 'is' | 'between'
>
Expand Down
6 changes: 3 additions & 3 deletions packages/databases/src/models/fields/big-auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export function bigAuto(): BigAutoField<
* ```
*/
export class BigAutoField<
TType extends { create: any; read: any; update: any } = {
out TType extends { create: any; read: any; update: any } = {
create: bigint | number | undefined;
read: bigint | number;
update: bigint | number | undefined;
},
TDefinitions extends {
out TDefinitions extends {
unique: boolean;
auto: boolean;
allowNull: boolean;
Expand All @@ -97,7 +97,7 @@ export class BigAutoField<
engineInstance: DatabaseAdapter;
customAttributes: any;
},
TFieldOperationTypes = Pick<
out TFieldOperationTypes = Pick<
FieldWithOperationTypeForSearch<number | bigint>,
'lessThan' | 'greaterThan' | 'and' | 'in' | 'or' | 'eq' | 'is' | 'between'
>
Expand Down
40 changes: 4 additions & 36 deletions packages/databases/src/models/fields/big-integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ export function bigInt(): BigIntegerField<
* ```
*/
export class BigIntegerField<
TType extends { create: any; read: any; update: any } = {
out TType extends { create: any; read: any; update: any } = {
create: bigint | number;
read: bigint | number;
update: bigint | number;
},
TDefinitions extends {
out TDefinitions extends {
unique: boolean;
auto: boolean;
allowNull: boolean;
Expand All @@ -94,7 +94,7 @@ export class BigIntegerField<
engineInstance: DatabaseAdapter;
customAttributes: any;
},
TFieldOperationTypes = Pick<
out TFieldOperationTypes = Pick<
FieldWithOperationTypeForSearch<number | bigint>,
'lessThan' | 'greaterThan' | 'and' | 'in' | 'or' | 'eq' | 'is' | 'between'
>
Expand Down Expand Up @@ -350,39 +350,7 @@ export class BigIntegerField<
> {
(this.__customAttributes as any) = customAttributes as any;

return this as unknown as BigIntegerField<
TType,
{
[TKey in Exclude<
keyof TDefinitions,
| 'underscored'
| 'allowNull'
| 'dbIndex'
| 'unique'
| 'isPrimaryKey'
| 'auto'
| 'defaultValue'
| 'databaseName'
| 'typeName'
| 'engineInstance'
| 'customAttributes'
>]: TDefinitions[TKey];
} & {
unique: TDefinitions['unique'];
allowNull: TDefinitions['allowNull'];
dbIndex: TDefinitions['dbIndex'];
underscored: TDefinitions['underscored'];
isPrimaryKey: TDefinitions['isPrimaryKey'];
auto: TDefinitions['auto'];
hasDefaultValue: TDefinitions['hasDefaultValue'];
defaultValue: TDefinitions['defaultValue'];
databaseName: TDefinitions['databaseName'];
typeName: TDefinitions['typeName'];
engineInstance: TDefinitions['engineInstance'];
customAttributes: TCustomAttributes;
},
TFieldOperationTypes
>;
return this as unknown as any;
}

unique<TUnique extends boolean = true>(
Expand Down
6 changes: 3 additions & 3 deletions packages/databases/src/models/fields/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ export function bool(): BooleanField<
* ```
*/
export class BooleanField<
TType extends { create: any; read: any; update: any } = {
out TType extends { create: any; read: any; update: any } = {
create: boolean;
read: boolean;
update: boolean;
},
TDefinitions extends {
out TDefinitions extends {
unique: boolean;
auto: boolean;
allowNull: boolean;
Expand All @@ -92,7 +92,7 @@ export class BooleanField<
engineInstance: DatabaseAdapter;
customAttributes: any;
},
TFieldOperationTypes = Pick<FieldWithOperationTypeForSearch<boolean>, 'and' | 'in' | 'or' | 'eq' | 'is'>
out TFieldOperationTypes = Pick<FieldWithOperationTypeForSearch<boolean>, 'and' | 'in' | 'or' | 'eq' | 'is'>
> extends Field<TType, TDefinitions, TFieldOperationTypes> {
protected $$type = '$PBooleanField';
protected __typeName = 'BooleanField';
Expand Down
6 changes: 3 additions & 3 deletions packages/databases/src/models/fields/char.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export function char<const TMaxCharLength extends number>(args: {
* ```
*/
export class CharField<
TType extends { create: any; read: any; update: any } = {
out TType extends { create: any; read: any; update: any } = {
create: string;
read: string;
update: string;
},
TDefinitions extends {
out TDefinitions extends {
unique: boolean;
auto: boolean;
allowNull: boolean;
Expand Down Expand Up @@ -107,7 +107,7 @@ export class CharField<
customAttributes: any;
maxLength: number;
},
TFieldOperationTypes = Pick<FieldWithOperationTypeForSearch<string>, 'like' | 'and' | 'in' | 'or' | 'eq' | 'is'>
out TFieldOperationTypes = Pick<FieldWithOperationTypeForSearch<string>, 'like' | 'and' | 'in' | 'or' | 'eq' | 'is'>
> extends TextField<TType, TDefinitions, TFieldOperationTypes> {
protected $$type = '$PCharField';
protected __typeName = 'CharField';
Expand Down
6 changes: 3 additions & 3 deletions packages/databases/src/models/fields/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ export function date(): DateField<
* ```
*/
export class DateField<
TType extends { create: any; read: any; update: any } = {
out TType extends { create: any; read: any; update: any } = {
create: string | Date;
read: string | Date;
update: string | Date;
},
TDefinitions extends {
out TDefinitions extends {
unique: boolean;
auto: boolean;
allowNull: boolean;
Expand Down Expand Up @@ -108,7 +108,7 @@ export class DateField<
autoNow: boolean;
autoNowAdd: boolean;
},
TFieldOperationTypes = Pick<
out TFieldOperationTypes = Pick<
FieldWithOperationTypeForSearch<string | Date>,
'eq' | 'is' | 'greaterThan' | 'lessThan' | 'between' | 'and' | 'or'
>
Expand Down
6 changes: 3 additions & 3 deletions packages/databases/src/models/fields/decimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ export function decimal<const TMaxDigits extends number, const TDecimalPlaces ex
* ```
*/
export class DecimalField<
TType extends { create: any; read: any; update: any } = {
out TType extends { create: any; read: any; update: any } = {
create: number | string;
read: number | string;
update: number | string;
},
TDefinitions extends {
out TDefinitions extends {
unique: boolean;
auto: boolean;
allowNull: boolean;
Expand Down Expand Up @@ -112,7 +112,7 @@ export class DecimalField<
maxDigits: number;
decimalPlaces: number;
},
TFieldOperationTypes = Pick<
out TFieldOperationTypes = Pick<
FieldWithOperationTypeForSearch<number | string>,
'greaterThan' | 'lessThan' | 'between' | 'and' | 'in' | 'or' | 'eq' | 'is'
>
Expand Down
6 changes: 3 additions & 3 deletions packages/databases/src/models/fields/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ export function choice<const TChoices extends string[]>(params: {
* ```
*/
export class EnumField<
TType extends { create: any; read: any; update: any } = {
out TType extends { create: any; read: any; update: any } = {
create: string;
read: string;
update: string;
},
TDefinitions extends {
out TDefinitions extends {
unique: boolean;
auto: boolean;
allowNull: boolean;
Expand Down Expand Up @@ -100,7 +100,7 @@ export class EnumField<
customAttributes: any;
choices: string[];
},
TFieldOperationTypes = Pick<FieldWithOperationTypeForSearch<string>, 'and' | 'in' | 'or' | 'eq' | 'is'>
out TFieldOperationTypes = Pick<FieldWithOperationTypeForSearch<string>, 'and' | 'in' | 'or' | 'eq' | 'is'>
> extends Field<TType, TDefinitions, TFieldOperationTypes> {
protected $$type = '$PEnumField';
protected __typeName = 'EnumField';
Expand Down
6 changes: 3 additions & 3 deletions packages/databases/src/models/fields/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ type AllowedQuery =
* Generally we do not offer any translation to this type of field.
*/
export class Field<
TType extends { create: any; read: any; update: any } = { create: any; read: any; update: any },
TDefinitions extends {
in out TType extends { create: any; read: any; update: any } = { create: any; read: any; update: any },
in out TDefinitions extends {
unique: boolean;
auto: boolean;
allowNull: boolean;
Expand All @@ -106,7 +106,7 @@ export class Field<
engineInstance: DatabaseAdapter;
customAttributes: any;
},
TFieldOperationTypes = FieldWithOperationTypeForSearch<any>
in out TFieldOperationTypes = FieldWithOperationTypeForSearch<any>
> {
protected $$type = '$PField';
protected __typeName = 'Field';
Expand Down
Loading