wabe-postgres 0.5.1 → 0.5.2

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/tsconfig.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": ["ESNext"],
5
+ "target": "ESNext",
6
+ "module": "Preserve",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+
11
+ // Bundler mode
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": false,
15
+ "noEmit": true,
16
+
17
+ // Best practices
18
+ "strict": true,
19
+ "skipLibCheck": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedIndexedAccess": true,
22
+ "noImplicitOverride": true,
23
+
24
+ // Some stricter flags (disabled by default)
25
+ "noUnusedLocals": false,
26
+ "noUnusedParameters": false,
27
+ "noPropertyAccessFromIndexSignature": false,
28
+ "baseUrl": "."
29
+ },
30
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
31
+ }
package/utils/preload.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  const setupEnvironment = () => {
2
- process.env.TEST = 'true'
2
+ process.env.TEST = 'true'
3
3
  }
4
4
 
5
5
  setupEnvironment()
@@ -4,121 +4,123 @@ import { type ClassInterface, Wabe } from 'wabe'
4
4
  import getPort from 'get-port'
5
5
  import { PostgresAdapter } from '../src'
6
6
 
7
- export const setupTests = async (
8
- additionalClasses: ClassInterface<any>[] = [],
9
- ) => {
10
- const databaseId = uuid()
7
+ export const setupTests = async (additionalClasses: ClassInterface<any>[] = []) => {
8
+ const databaseId = uuid()
11
9
 
12
- const port = await getPort()
10
+ const port = await getPort()
13
11
 
14
- await runDatabase()
12
+ await runDatabase()
15
13
 
16
- const wabe = new Wabe<any>({
17
- isProduction: false,
18
- rootKey:
19
- '0uwFvUxM$ceFuF1aEtTtZMa7DUN2NZudqgY5ve5W*QCyb58cwMj9JeoaV@d#%29v&aJzswuudVU1%nAT+rxS0Bh&OkgBYc0PH18*',
20
- database: {
21
- adapter: new PostgresAdapter({
22
- databaseUrl: 'postgresql://wabe:wabe@localhost:5432',
23
- databaseName: databaseId,
24
- }),
25
- },
26
- authentication: {
27
- roles: ['Client', 'Client2', 'Client3', 'Admin'],
28
- session: {
29
- jwtSecret: 'dev',
30
- cookieSession: true,
31
- },
32
- },
33
- port,
34
- schema: {
35
- classes: [
36
- ...additionalClasses,
37
- {
38
- name: 'Test',
39
- fields: {
40
- field1: { type: 'String' },
41
- int: { type: 'Int' },
42
- array: { type: 'Array', typeValue: 'String' },
43
- date: { type: 'Date' },
44
- enum: { type: 'AuthenticationProvider' },
45
- object: {
46
- type: 'Object',
47
- object: {
48
- name: 'Object',
49
- fields: {
50
- array: {
51
- type: 'Array',
52
- typeValue: 'Object',
53
- object: {
54
- name: 'SubObject',
55
- fields: {
56
- string: {
57
- type: 'String',
58
- },
59
- },
60
- },
61
- },
62
- },
63
- },
64
- },
65
- },
66
- },
67
- {
68
- name: 'User',
69
- fields: {
70
- name: { type: 'String' },
71
- age: { type: 'Int' },
72
- isAdmin: { type: 'Boolean', defaultValue: false },
73
- floatValue: { type: 'Float' },
74
- birthDate: { type: 'Date' },
75
- arrayValue: {
76
- type: 'Array',
77
- typeValue: 'String',
78
- },
79
- test: { type: 'TestScalar' },
80
- },
81
- searchableFields: ['email'],
82
- permissions: {
83
- create: {
84
- requireAuthentication: false,
85
- },
86
- delete: {
87
- requireAuthentication: true,
88
- },
89
- update: {
90
- requireAuthentication: false,
91
- },
92
- read: {
93
- requireAuthentication: false,
94
- },
95
- acl: async (hookObject) => {
96
- await hookObject.addACL('users', {
97
- userId: hookObject.object?.id,
98
- read: true,
99
- write: true,
100
- })
14
+ const wabe = new Wabe<any>({
15
+ isProduction: false,
16
+ rootKey:
17
+ '0uwFvUxM$ceFuF1aEtTtZMa7DUN2NZudqgY5ve5W*QCyb58cwMj9JeoaV@d#%29v&aJzswuudVU1%nAT+rxS0Bh&OkgBYc0PH18*',
18
+ database: {
19
+ adapter: new PostgresAdapter({
20
+ databaseUrl: 'postgresql://wabe:wabe@localhost:5432',
21
+ databaseName: databaseId,
22
+ }),
23
+ },
24
+ authentication: {
25
+ roles: ['Client', 'Client2', 'Client3', 'Admin'],
26
+ session: {
27
+ jwtSecret: 'dev',
28
+ cookieSession: true,
29
+ },
30
+ },
31
+ security: {
32
+ disableCSRFProtection: true,
33
+ },
34
+ port,
35
+ schema: {
36
+ classes: [
37
+ ...additionalClasses,
38
+ {
39
+ name: 'Test',
40
+ fields: {
41
+ field1: { type: 'String' },
42
+ int: { type: 'Int' },
43
+ float: { type: 'Float' },
44
+ array: { type: 'Array', typeValue: 'String' },
45
+ date: { type: 'Date' },
46
+ enum: { type: 'AuthenticationProvider' },
47
+ object: {
48
+ type: 'Object',
49
+ object: {
50
+ name: 'Object',
51
+ fields: {
52
+ array: {
53
+ type: 'Array',
54
+ typeValue: 'Object',
55
+ object: {
56
+ name: 'SubObject',
57
+ fields: {
58
+ string: {
59
+ type: 'String',
60
+ },
61
+ },
62
+ },
63
+ },
64
+ },
65
+ },
66
+ },
67
+ },
68
+ },
69
+ {
70
+ name: 'User',
71
+ fields: {
72
+ name: { type: 'String' },
73
+ age: { type: 'Int' },
74
+ isAdmin: { type: 'Boolean', defaultValue: false },
75
+ floatValue: { type: 'Float' },
76
+ birthDate: { type: 'Date' },
77
+ arrayValue: {
78
+ type: 'Array',
79
+ typeValue: 'String',
80
+ },
81
+ test: { type: 'TestScalar' },
82
+ },
83
+ searchableFields: ['email'],
84
+ permissions: {
85
+ create: {
86
+ requireAuthentication: false,
87
+ },
88
+ delete: {
89
+ requireAuthentication: true,
90
+ },
91
+ update: {
92
+ requireAuthentication: false,
93
+ },
94
+ read: {
95
+ requireAuthentication: false,
96
+ },
97
+ acl: async (hookObject) => {
98
+ await hookObject.addACL('users', {
99
+ userId: hookObject.object?.id,
100
+ read: true,
101
+ write: true,
102
+ })
101
103
 
102
- await hookObject.addACL('roles', null)
103
- },
104
- },
105
- },
106
- ],
107
- scalars: [
108
- {
109
- name: 'TestScalar',
110
- description: 'Test scalar',
111
- },
112
- ],
113
- },
114
- })
104
+ await hookObject.addACL('roles', null)
105
+ },
106
+ },
107
+ },
108
+ ],
109
+ scalars: [
110
+ {
111
+ name: 'TestScalar',
112
+ description: 'Test scalar',
113
+ },
114
+ ],
115
+ },
116
+ })
115
117
 
116
- await wabe.start()
118
+ await wabe.start()
117
119
 
118
- return { wabe, port }
120
+ return { wabe, port }
119
121
  }
120
122
 
121
123
  export const closeTests = async (wabe: Wabe<any>) => {
122
- await wabe.controllers.database.adapter?.close()
123
- await wabe.close()
124
+ await wabe.controllers?.database?.adapter?.close()
125
+ await wabe.close()
124
126
  }
package/bunfig.toml DELETED
@@ -1,4 +0,0 @@
1
- telemetry = false
2
-
3
- [test]
4
- preload = ['./utils/preload.ts']
package/dist/index.d.ts DELETED
@@ -1,74 +0,0 @@
1
- import { Pool } from "pg";
2
- import { type AdapterOptions, type DatabaseAdapter, type GetObjectOptions, type CreateObjectOptions, type UpdateObjectOptions, type GetObjectsOptions, type CreateObjectsOptions, type UpdateObjectsOptions, type DeleteObjectsOptions, type WhereType, type DeleteObjectOptions, type OutputType, type CountOptions, type OrderType, type WabeTypes, type SchemaInterface } from "wabe";
3
- export declare const buildPostgresOrderQuery: <
4
- T extends WabeTypes,
5
- K extends keyof T["types"],
6
- U extends keyof T["types"][K]
7
- >(order?: OrderType<T, K, U>) => string;
8
- export declare const buildPostgresWhereQueryAndValues: <
9
- T extends WabeTypes,
10
- K extends keyof T["types"]
11
- >(where?: WhereType<T, K>, startParamIndex?: number, parentKey?: string) => {
12
- query: string;
13
- values: any[];
14
- paramIndex: number;
15
- };
16
- export declare class PostgresAdapter<T extends WabeTypes> implements DatabaseAdapter<T> {
17
- options: AdapterOptions;
18
- postgresPool: Pool;
19
- pool: Pool;
20
- constructor(options: AdapterOptions);
21
- initializeDatabase(schema: SchemaInterface<T>);
22
- clearDatabase();
23
- close();
24
- createClassIfNotExist(className: keyof T["types"], schema: SchemaInterface<T>);
25
- count<K extends keyof T["types"]>(params: CountOptions<T, K>);
26
- getObject<
27
- K extends keyof T["types"],
28
- U extends keyof T["types"][K]
29
- >(params: GetObjectOptions<T, K, U>): Promise<OutputType<T, K, U>>;
30
- getObjects<
31
- K extends keyof T["types"],
32
- U extends keyof T["types"][K],
33
- W extends keyof T["types"][K]
34
- >(params: GetObjectsOptions<T, K, U, W>): Promise<OutputType<T, K, W>[]>;
35
- createObject<
36
- K extends keyof T["types"],
37
- U extends keyof T["types"][K],
38
- W extends keyof T["types"][K]
39
- >(params: CreateObjectOptions<T, K, U, W>): Promise<{
40
- id: string;
41
- }>;
42
- createObjects<
43
- K extends keyof T["types"],
44
- U extends keyof T["types"][K],
45
- W extends keyof T["types"][K],
46
- X extends keyof T["types"][K]
47
- >(params: CreateObjectsOptions<T, K, U, W, X>): Promise<Array<{
48
- id: string;
49
- }>>;
50
- updateObject<
51
- K extends keyof T["types"],
52
- U extends keyof T["types"][K],
53
- W extends keyof T["types"][K]
54
- >(params: UpdateObjectOptions<T, K, U, W>): Promise<{
55
- id: string;
56
- }>;
57
- updateObjects<
58
- K extends keyof T["types"],
59
- U extends keyof T["types"][K],
60
- W extends keyof T["types"][K],
61
- X extends keyof T["types"][K]
62
- >(params: UpdateObjectsOptions<T, K, U, W, X>): Promise<Array<{
63
- id: string;
64
- }>>;
65
- deleteObject<
66
- K extends keyof T["types"],
67
- U extends keyof T["types"][K]
68
- >(params: DeleteObjectOptions<T, K, U>): Promise<void>;
69
- deleteObjects<
70
- K extends keyof T["types"],
71
- U extends keyof T["types"][K],
72
- W extends keyof T["types"][K]
73
- >(params: DeleteObjectsOptions<T, K, U, W>): Promise<void>;
74
- }