wabe 0.5.3 → 0.5.4
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/README.md +2 -0
- package/dist/index.d.ts +109 -78
- package/dist/index.js +3254 -3010
- package/generated/schema.graphql +2 -1
- package/generated/wabe.ts +2 -1
- package/package.json +2 -2
- package/dist/generated/wabe.d.ts +0 -1692
package/README.md
CHANGED
|
@@ -52,6 +52,8 @@ await run();
|
|
|
52
52
|
- **Database**: A powerful, scalable database to store and manage you data.
|
|
53
53
|
- **GraphQL API**: A flexible and powerful GraphQL API (following GraphQL Relay standard) to interact with your data.
|
|
54
54
|
- **Hooks**: Powerful hooks system to execute custom actions before or after database requests.
|
|
55
|
+
- **Email**: Send emails with your favorite provider with very simple integration.
|
|
56
|
+
- **Payment**: Accept payments with Stripe or create your own payment provider adapter.
|
|
55
57
|
|
|
56
58
|
## Contributing
|
|
57
59
|
|
package/dist/index.d.ts
CHANGED
|
@@ -60,7 +60,8 @@ export type Scalars = {
|
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
62
|
declare enum AuthenticationProvider {
|
|
63
|
-
Google = "
|
|
63
|
+
Google = "google",
|
|
64
|
+
EmailPassword = "emailPassword"
|
|
64
65
|
}
|
|
65
66
|
declare enum SecondaryFactor {
|
|
66
67
|
EmailOtp = "EmailOTP"
|
|
@@ -328,7 +329,7 @@ export interface AdapterOptions {
|
|
|
328
329
|
databaseUrl: string;
|
|
329
330
|
databaseName: string;
|
|
330
331
|
}
|
|
331
|
-
export type MutationData<T extends keyof WabeTypes["types"]
|
|
332
|
+
export type MutationData<T extends keyof WabeTypes["types"], K extends keyof WabeTypes["types"][T]> = Record<K, any>;
|
|
332
333
|
export interface CountOptions<T extends keyof WabeTypes["types"], K extends keyof WabeTypes["types"][T]> {
|
|
333
334
|
className: T;
|
|
334
335
|
where?: WhereType<T, K>;
|
|
@@ -354,13 +355,13 @@ export interface GetObjectsOptions<T extends keyof WabeTypes["types"], K extends
|
|
|
354
355
|
}
|
|
355
356
|
export interface CreateObjectOptions<T extends keyof WabeTypes["types"], K extends keyof WabeTypes["types"][T], W extends keyof WabeTypes["types"][T]> {
|
|
356
357
|
className: T;
|
|
357
|
-
data: MutationData<W>;
|
|
358
|
+
data: MutationData<T, W>;
|
|
358
359
|
fields: Array<K | "*">;
|
|
359
360
|
context: WabeContext<any>;
|
|
360
361
|
}
|
|
361
362
|
export interface CreateObjectsOptions<T extends keyof WabeTypes["types"], K extends keyof WabeTypes["types"][T], W extends keyof WabeTypes["types"][T], X extends keyof WabeTypes["types"][T]> {
|
|
362
363
|
className: T;
|
|
363
|
-
data: Array<MutationData<W>>;
|
|
364
|
+
data: Array<MutationData<T, W>>;
|
|
364
365
|
fields: Array<K | "*">;
|
|
365
366
|
offset?: number;
|
|
366
367
|
first?: number;
|
|
@@ -371,7 +372,7 @@ export interface UpdateObjectOptions<T extends keyof WabeTypes["types"], K exten
|
|
|
371
372
|
className: T;
|
|
372
373
|
id: string;
|
|
373
374
|
where?: WhereType<T, W>;
|
|
374
|
-
data: MutationData<W>;
|
|
375
|
+
data: MutationData<T, W>;
|
|
375
376
|
fields: Array<K | "*">;
|
|
376
377
|
context: WabeContext<any>;
|
|
377
378
|
}
|
|
@@ -379,7 +380,7 @@ export interface UpdateObjectsOptions<T extends keyof WabeTypes["types"], K exte
|
|
|
379
380
|
className: T;
|
|
380
381
|
where: WhereType<T, W>;
|
|
381
382
|
order?: OrderType<T, X>;
|
|
382
|
-
data: MutationData<W>;
|
|
383
|
+
data: MutationData<T, W>;
|
|
383
384
|
fields: Array<K | "*">;
|
|
384
385
|
offset?: number;
|
|
385
386
|
first?: number;
|
|
@@ -500,9 +501,9 @@ export declare class DatabaseController<T extends WabeTypes> {
|
|
|
500
501
|
getObject<U extends keyof T["types"], K extends keyof T["types"][U]>({ fields, className, context, skipHooks, id, where, }: GetObjectOptions<U, K>): Promise<OutputType<U, K>>;
|
|
501
502
|
getObjects<U extends keyof T["types"], K extends keyof T["types"][U], W extends keyof T["types"][U], X extends keyof T["types"][U]>({ className, fields, context, where, skipHooks, first, offset, order, }: GetObjectsOptions<U, K, W, X>): Promise<OutputType<U, K>[]>;
|
|
502
503
|
createObject<U extends keyof T["types"], K extends keyof T["types"][U], W extends keyof T["types"][U]>({ className, context, data, fields }: CreateObjectOptions<U, K, W>): Promise<OutputType<U, K>>;
|
|
503
|
-
createObjects<U extends keyof T["types"], K extends keyof T["types"][U], W extends keyof T["types"][U], X extends keyof T["types"][U]>({ data, fields, className, context, first, offset, order, }: CreateObjectsOptions<U, K, W, X>): Promise<OutputType<
|
|
504
|
+
createObjects<U extends keyof T["types"], K extends keyof T["types"][U], W extends keyof T["types"][U], X extends keyof T["types"][U]>({ data, fields, className, context, first, offset, order, }: CreateObjectsOptions<U, K, W, X>): Promise<OutputType<any, K>[]>;
|
|
504
505
|
updateObject<U extends keyof T["types"], K extends keyof T["types"][U], W extends keyof T["types"][U]>({ id, className, context, data, fields }: UpdateObjectOptions<U, K, W>): Promise<OutputType<keyof T["types"], K>>;
|
|
505
|
-
updateObjects<U extends keyof T["types"], K extends keyof T["types"][U], W extends keyof T["types"][U], X extends keyof T["types"][U]>({ className, where, context, fields, data, first, offset, order, }: UpdateObjectsOptions<U, K, W, X>): Promise<OutputType<
|
|
506
|
+
updateObjects<U extends keyof T["types"], K extends keyof T["types"][U], W extends keyof T["types"][U], X extends keyof T["types"][U]>({ className, where, context, fields, data, first, offset, order, }: UpdateObjectsOptions<U, K, W, X>): Promise<OutputType<any, K>[]>;
|
|
506
507
|
deleteObject<U extends keyof T["types"], K extends keyof T["types"][U], W extends keyof T["types"][U]>({ context, className, id, fields }: DeleteObjectOptions<U, K, W>): Promise<OutputType<U, K>>;
|
|
507
508
|
deleteObjects<U extends keyof T["types"], K extends keyof T["types"][U], W extends keyof T["types"][U], X extends keyof T["types"][U]>({ className, context, fields, where, first, offset, order, }: DeleteObjectsOptions<U, K, W, X>): Promise<OutputType<U, K>[]>;
|
|
508
509
|
}
|
|
@@ -514,6 +515,75 @@ export interface DatabaseConfig {
|
|
|
514
515
|
url: string;
|
|
515
516
|
name: string;
|
|
516
517
|
}
|
|
518
|
+
export declare enum OperationType {
|
|
519
|
+
AfterCreate = "AfterCreate",
|
|
520
|
+
AfterUpdate = "afterUpdate",
|
|
521
|
+
AfterDelete = "afterDelete",
|
|
522
|
+
AfterRead = "afterRead",
|
|
523
|
+
BeforeCreate = "beforeInsert",
|
|
524
|
+
BeforeUpdate = "beforeUpdate",
|
|
525
|
+
BeforeDelete = "beforeDelete",
|
|
526
|
+
BeforeRead = "beforeRead"
|
|
527
|
+
}
|
|
528
|
+
export type Hook<T extends WabeTypes, K extends keyof WabeTypes["types"]> = {
|
|
529
|
+
operationType: OperationType;
|
|
530
|
+
className?: K;
|
|
531
|
+
priority: number;
|
|
532
|
+
callback: (hookObject: HookObject<T, K>) => Promise<void> | void;
|
|
533
|
+
};
|
|
534
|
+
export declare const _findHooksByPriority: <T extends unknown>({ className, operationType, priority, config, }: {
|
|
535
|
+
operationType: OperationType;
|
|
536
|
+
className: T;
|
|
537
|
+
priority: number;
|
|
538
|
+
config: WabeConfig<any>;
|
|
539
|
+
}) => Promise<Hook<any, any>[]>;
|
|
540
|
+
export declare const initializeHook: <T extends unknown>({ className, newData, context, }: {
|
|
541
|
+
className: T;
|
|
542
|
+
newData?: MutationData<any, any> | undefined;
|
|
543
|
+
context: WabeContext<any>;
|
|
544
|
+
}) => {
|
|
545
|
+
runOnSingleObject: ({ operationType, id, object: inputObject, }: {
|
|
546
|
+
operationType: OperationType;
|
|
547
|
+
id?: string | undefined;
|
|
548
|
+
object?: OutputType<any, any> | undefined;
|
|
549
|
+
}) => Promise<{
|
|
550
|
+
object: undefined;
|
|
551
|
+
newData: {};
|
|
552
|
+
} | {
|
|
553
|
+
object: OutputType<any, any>;
|
|
554
|
+
newData: MutationData<T, keyof WabeSchemaTypes[T]>;
|
|
555
|
+
}>;
|
|
556
|
+
runOnMultipleObjects: ({ operationType, where, objects: inputObjects, }: {
|
|
557
|
+
operationType: OperationType;
|
|
558
|
+
where?: WhereType<any, any> | undefined;
|
|
559
|
+
objects?: OutputType<any, any>[] | undefined;
|
|
560
|
+
}) => Promise<{
|
|
561
|
+
objects: never[];
|
|
562
|
+
newData: MutationData<any, any>[];
|
|
563
|
+
} | {
|
|
564
|
+
objects: OutputType<any, any>[];
|
|
565
|
+
newData: Awaited<MutationData<T, keyof WabeSchemaTypes[T]>>[];
|
|
566
|
+
}>;
|
|
567
|
+
};
|
|
568
|
+
export declare const getDefaultHooks: () => Hook<any, any>[];
|
|
569
|
+
declare class HookObject<T extends WabeTypes, K extends keyof WabeTypes["types"]> {
|
|
570
|
+
className: K;
|
|
571
|
+
private newData;
|
|
572
|
+
private operationType;
|
|
573
|
+
context: WabeContext<T>;
|
|
574
|
+
object: Partial<Record<keyof T["types"][K], any>>;
|
|
575
|
+
constructor({ newData, className, operationType, context, object, }: {
|
|
576
|
+
className: K;
|
|
577
|
+
newData?: MutationData<K, keyof T["types"][K]>;
|
|
578
|
+
operationType: OperationType;
|
|
579
|
+
context: WabeContext<T>;
|
|
580
|
+
object: Partial<Record<keyof T["types"][K], any>>;
|
|
581
|
+
});
|
|
582
|
+
getUser(): User | null | undefined;
|
|
583
|
+
isFieldUpdate(field: keyof T["types"][K]): boolean | undefined;
|
|
584
|
+
upsertNewData(field: keyof T["types"][K], value: any): void;
|
|
585
|
+
getNewData(): MutationData<K, keyof T["types"][K]>;
|
|
586
|
+
}
|
|
517
587
|
export type WabePrimaryTypes = "String" | "Int" | "Float" | "Boolean" | "Email" | "Date" | "File";
|
|
518
588
|
export type WabeCustomTypes = "Array" | "Object";
|
|
519
589
|
export type WabeRelationTypes = "Pointer" | "Relation";
|
|
@@ -623,7 +693,34 @@ export interface PermissionProperties {
|
|
|
623
693
|
*/
|
|
624
694
|
authorizedRoles?: Array<string>;
|
|
625
695
|
}
|
|
626
|
-
|
|
696
|
+
/**
|
|
697
|
+
* ACL properties
|
|
698
|
+
* Automatically create ACL object before insert of the object in the database
|
|
699
|
+
* Allow you to specify which user can read or write the object
|
|
700
|
+
* You can specify "self" to allow only the user that created the object to read or write it
|
|
701
|
+
* You can specify "all" to allow all users to read or write the object
|
|
702
|
+
* For some custom use cases, you can specify a callback function that will be called before
|
|
703
|
+
* inserting the object in the database.
|
|
704
|
+
* Authorized roles is more restristive that at the class level. You can have a role access on all the class
|
|
705
|
+
* except one object.
|
|
706
|
+
* If the array of authorized users is empty, no user is authorized
|
|
707
|
+
* If the array of authorized users is undefined, everyone is authorized
|
|
708
|
+
*/
|
|
709
|
+
export type ACLProperties = {
|
|
710
|
+
authorizedUsers: {
|
|
711
|
+
read: Array<"self">;
|
|
712
|
+
write: Array<"self">;
|
|
713
|
+
};
|
|
714
|
+
authorizedRoles: {
|
|
715
|
+
read: Array<string>;
|
|
716
|
+
write: Array<string>;
|
|
717
|
+
};
|
|
718
|
+
} | {
|
|
719
|
+
callback?: (hookObject: HookObject<any, any>) => void | Promise<void>;
|
|
720
|
+
};
|
|
721
|
+
export type ClassPermissions = Partial<Record<PermissionsOperations, PermissionProperties> & {
|
|
722
|
+
acl: ACLProperties;
|
|
723
|
+
}>;
|
|
627
724
|
export type SearchableFields = Array<string>;
|
|
628
725
|
export type ClassIndexes = Array<{
|
|
629
726
|
field: string;
|
|
@@ -742,80 +839,14 @@ export interface Provider {
|
|
|
742
839
|
refreshToken(options: refreshTokenOptions): Promise<void>;
|
|
743
840
|
}
|
|
744
841
|
declare enum AuthenticationProvider$1 {
|
|
745
|
-
Google = "
|
|
842
|
+
Google = "google",
|
|
843
|
+
EmailPassword = "emailPassword"
|
|
746
844
|
}
|
|
747
845
|
export interface WabeRoute {
|
|
748
846
|
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
749
847
|
path: string;
|
|
750
848
|
handler: WobeHandler<WobeCustomContext<any>>;
|
|
751
849
|
}
|
|
752
|
-
declare class HookObject<T extends WabeTypes, K = keyof T["types"]> {
|
|
753
|
-
className: string;
|
|
754
|
-
private newData;
|
|
755
|
-
private operationType;
|
|
756
|
-
context: WabeContext<T>;
|
|
757
|
-
object: Record<keyof WabeTypes["types"][T], any>;
|
|
758
|
-
constructor({ newData, className, operationType, context, object, }: {
|
|
759
|
-
className: K;
|
|
760
|
-
newData?: MutationData<T>;
|
|
761
|
-
operationType: OperationType;
|
|
762
|
-
context: WabeContext<T>;
|
|
763
|
-
object: Record<keyof WabeTypes["types"][T], any>;
|
|
764
|
-
});
|
|
765
|
-
getUser(): User | null | undefined;
|
|
766
|
-
isFieldUpdate(field: keyof WabeTypes["types"][T]): boolean | undefined;
|
|
767
|
-
upsertNewData(field: keyof WabeTypes["types"][T], value: any): void;
|
|
768
|
-
getNewData(): MutationData<T>;
|
|
769
|
-
}
|
|
770
|
-
export declare enum OperationType {
|
|
771
|
-
AfterCreate = "AfterCreate",
|
|
772
|
-
AfterUpdate = "afterUpdate",
|
|
773
|
-
AfterDelete = "afterDelete",
|
|
774
|
-
AfterRead = "afterRead",
|
|
775
|
-
BeforeCreate = "beforeInsert",
|
|
776
|
-
BeforeUpdate = "beforeUpdate",
|
|
777
|
-
BeforeDelete = "beforeDelete",
|
|
778
|
-
BeforeRead = "beforeRead"
|
|
779
|
-
}
|
|
780
|
-
export type Hook<T extends WabeTypes> = {
|
|
781
|
-
operationType: OperationType;
|
|
782
|
-
className?: T;
|
|
783
|
-
priority: number;
|
|
784
|
-
callback: (hookObject: HookObject<T>) => Promise<void> | void;
|
|
785
|
-
};
|
|
786
|
-
export type TypedNewData<T extends keyof WabeTypes["types"]> = Record<keyof WabeTypes["types"][T], any>;
|
|
787
|
-
export declare const _findHooksByPriority: <T extends unknown>({ className, operationType, priority, config, }: {
|
|
788
|
-
operationType: OperationType;
|
|
789
|
-
className: T;
|
|
790
|
-
priority: number;
|
|
791
|
-
config: WabeConfig<any>;
|
|
792
|
-
}) => Promise<Hook<any>[]>;
|
|
793
|
-
export declare const initializeHook: <T extends unknown>({ className, newData, context, }: {
|
|
794
|
-
className: T;
|
|
795
|
-
newData?: TypedNewData<any> | undefined;
|
|
796
|
-
context: WabeContext<any>;
|
|
797
|
-
}) => {
|
|
798
|
-
runOnSingleObject: ({ operationType, id, object: inputObject, }: {
|
|
799
|
-
operationType: OperationType;
|
|
800
|
-
id?: string | undefined;
|
|
801
|
-
object?: OutputType<any, any> | undefined;
|
|
802
|
-
}) => Promise<{
|
|
803
|
-
object: undefined;
|
|
804
|
-
newData: {};
|
|
805
|
-
} | {
|
|
806
|
-
object: OutputType<any, any>;
|
|
807
|
-
newData: MutationData<any>;
|
|
808
|
-
}>;
|
|
809
|
-
runOnMultipleObjects: ({ operationType, where, objects: inputObjects, }: {
|
|
810
|
-
operationType: OperationType;
|
|
811
|
-
where?: WhereType<any, any> | undefined;
|
|
812
|
-
objects?: OutputType<any, any>[] | undefined;
|
|
813
|
-
}) => Promise<{
|
|
814
|
-
objects: OutputType<any, any>[];
|
|
815
|
-
newData: MutationData<any>[];
|
|
816
|
-
}>;
|
|
817
|
-
};
|
|
818
|
-
export declare const getDefaultHooks: () => Hook<any>[];
|
|
819
850
|
export type DevWabeTypes = {
|
|
820
851
|
types: WabeSchemaTypes;
|
|
821
852
|
scalars: WabeSchemaScalars;
|
|
@@ -1062,7 +1093,7 @@ export interface WabeConfig<T extends WabeTypes> {
|
|
|
1062
1093
|
authentication?: AuthenticationConfig<T>;
|
|
1063
1094
|
routes?: WabeRoute[];
|
|
1064
1095
|
rootKey: string;
|
|
1065
|
-
hooks?: Hook<any>[];
|
|
1096
|
+
hooks?: Hook<T, any>[];
|
|
1066
1097
|
email?: EmailConfig;
|
|
1067
1098
|
payment?: PaymentConfig;
|
|
1068
1099
|
file?: FileConfig;
|