inibase 1.0.0-rc.5 → 1.0.0-rc.7
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 +4 -62
- package/file.ts +114 -74
- package/index.test.ts +141 -179
- package/index.ts +295 -324
- package/package.json +2 -2
- package/utils.server.ts +79 -0
- package/utils.ts +124 -77
package/index.test.ts
CHANGED
|
@@ -2,9 +2,8 @@ import Inibase, { Schema, Data } from "./index";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
// import os from "os";
|
|
4
4
|
// Create a new instance of Inibase with the database path
|
|
5
|
-
const db = new Inibase("
|
|
5
|
+
const db = new Inibase("inicontent", join("..", "inicontent", "databases"));
|
|
6
6
|
|
|
7
|
-
// test with edited schema
|
|
8
7
|
const schema_1: Schema = [
|
|
9
8
|
{
|
|
10
9
|
key: "username",
|
|
@@ -12,237 +11,200 @@ const schema_1: Schema = [
|
|
|
12
11
|
required: true,
|
|
13
12
|
},
|
|
14
13
|
{
|
|
15
|
-
key: "
|
|
16
|
-
type: "
|
|
14
|
+
key: "password",
|
|
15
|
+
type: "password",
|
|
17
16
|
required: true,
|
|
18
17
|
},
|
|
19
18
|
{
|
|
20
|
-
key: "
|
|
21
|
-
type: "
|
|
19
|
+
key: "email",
|
|
20
|
+
type: "email",
|
|
22
21
|
required: true,
|
|
23
22
|
},
|
|
24
23
|
{
|
|
25
|
-
key: "
|
|
26
|
-
type: "
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
key: "hobbies",
|
|
30
|
-
type: "array",
|
|
31
|
-
children: [
|
|
32
|
-
{
|
|
33
|
-
key: "name",
|
|
34
|
-
type: "string",
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
key: "level",
|
|
38
|
-
type: "string",
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
key: "favoriteFoods",
|
|
44
|
-
type: "array",
|
|
45
|
-
children: "string",
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
key: "address",
|
|
49
|
-
type: "object",
|
|
50
|
-
children: [
|
|
51
|
-
{
|
|
52
|
-
key: "street",
|
|
53
|
-
type: "string",
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
key: "city",
|
|
57
|
-
type: "string",
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
key: "country",
|
|
61
|
-
type: "string",
|
|
62
|
-
},
|
|
63
|
-
],
|
|
24
|
+
key: "role",
|
|
25
|
+
type: "string",
|
|
26
|
+
required: true,
|
|
64
27
|
},
|
|
65
28
|
];
|
|
66
29
|
|
|
67
30
|
const data_1: Data = [
|
|
68
31
|
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
email: "
|
|
72
|
-
|
|
73
|
-
isActive: true,
|
|
74
|
-
hobbies: [
|
|
75
|
-
{ name: "Reading", level: "Intermediate" },
|
|
76
|
-
{ name: "Cooking", level: "Beginner" },
|
|
77
|
-
],
|
|
78
|
-
favoriteFoods: ["Pizza", "Sushi", "Chocolate"],
|
|
79
|
-
address: {
|
|
80
|
-
street: "123 Main St",
|
|
81
|
-
city: "Exampleville",
|
|
82
|
-
country: "Sampleland",
|
|
83
|
-
},
|
|
32
|
+
username: "admin",
|
|
33
|
+
password: "admina",
|
|
34
|
+
email: "karim.amahtil@gmail.com",
|
|
35
|
+
role: "admin",
|
|
84
36
|
},
|
|
85
37
|
{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
email: "
|
|
89
|
-
|
|
90
|
-
isActive: false,
|
|
91
|
-
hobbies: [
|
|
92
|
-
{ name: "Gardening", level: "Advanced" },
|
|
93
|
-
{ name: "Photography", level: "Intermediate" },
|
|
94
|
-
],
|
|
95
|
-
favoriteFoods: ["Burgers", null, "Salad"],
|
|
96
|
-
address: {
|
|
97
|
-
street: "456 Elm Rd",
|
|
98
|
-
city: "Testington",
|
|
99
|
-
country: "Demo Country",
|
|
100
|
-
},
|
|
38
|
+
username: "kamatil",
|
|
39
|
+
password: "admina",
|
|
40
|
+
email: "karim.amahtil21@gmail.com",
|
|
41
|
+
role: "user",
|
|
101
42
|
},
|
|
102
43
|
{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
email: "
|
|
106
|
-
|
|
107
|
-
isActive: true,
|
|
108
|
-
hobbies: [
|
|
109
|
-
{ name: "Painting", level: "Beginner" },
|
|
110
|
-
{ name: "Hiking", level: null },
|
|
111
|
-
],
|
|
112
|
-
favoriteFoods: ["Pasta", "Fruit", "Cakes"],
|
|
113
|
-
address: {
|
|
114
|
-
street: "789 Oak Ave",
|
|
115
|
-
city: "Sampletown",
|
|
116
|
-
country: "Testland",
|
|
117
|
-
},
|
|
44
|
+
username: "tvonthego",
|
|
45
|
+
password: "azqswx",
|
|
46
|
+
email: "vip72abdo@gmail.com",
|
|
47
|
+
role: "user",
|
|
118
48
|
},
|
|
119
49
|
];
|
|
120
50
|
|
|
121
51
|
const schema_2: Schema = [
|
|
122
52
|
{
|
|
123
|
-
key: "
|
|
53
|
+
key: "name",
|
|
124
54
|
type: "string",
|
|
125
55
|
required: true,
|
|
126
56
|
},
|
|
127
57
|
{
|
|
128
|
-
key: "
|
|
129
|
-
type: "
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
key: "user",
|
|
133
|
-
type: "table",
|
|
58
|
+
key: "slug",
|
|
59
|
+
type: "string",
|
|
134
60
|
required: true,
|
|
135
61
|
},
|
|
136
|
-
];
|
|
137
|
-
|
|
138
|
-
const data_2 = [
|
|
139
|
-
{
|
|
140
|
-
title: "Product 1",
|
|
141
|
-
price: 16,
|
|
142
|
-
user: 1,
|
|
143
|
-
},
|
|
144
62
|
{
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
63
|
+
key: "icon",
|
|
64
|
+
type: "url",
|
|
65
|
+
required: false,
|
|
148
66
|
},
|
|
149
|
-
];
|
|
150
|
-
|
|
151
|
-
const schema_3: Schema = [
|
|
152
67
|
{
|
|
153
|
-
key: "
|
|
154
|
-
type: "
|
|
68
|
+
key: "languages",
|
|
69
|
+
type: "array",
|
|
70
|
+
children: "string",
|
|
71
|
+
required: false,
|
|
155
72
|
},
|
|
156
73
|
{
|
|
157
|
-
key: "
|
|
158
|
-
type: "
|
|
74
|
+
key: "allowed_domains",
|
|
75
|
+
type: "array",
|
|
76
|
+
children: "url",
|
|
77
|
+
required: false,
|
|
159
78
|
},
|
|
160
79
|
{
|
|
161
|
-
key: "
|
|
80
|
+
key: "tables",
|
|
162
81
|
type: "array",
|
|
163
82
|
children: [
|
|
164
83
|
{
|
|
165
84
|
key: "name",
|
|
166
85
|
type: "string",
|
|
86
|
+
required: true,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
key: "slug",
|
|
90
|
+
type: "string",
|
|
91
|
+
required: true,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
key: "allowed_methods",
|
|
95
|
+
type: "array",
|
|
96
|
+
children: [
|
|
97
|
+
{
|
|
98
|
+
key: "role",
|
|
99
|
+
type: "string",
|
|
100
|
+
required: true,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
key: "methods",
|
|
104
|
+
type: "string",
|
|
105
|
+
required: true,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
required: true,
|
|
167
109
|
},
|
|
168
110
|
{
|
|
169
|
-
key: "
|
|
111
|
+
key: "schema",
|
|
170
112
|
type: "array",
|
|
171
113
|
children: [
|
|
172
114
|
{
|
|
173
|
-
key: "
|
|
115
|
+
key: "id",
|
|
116
|
+
type: "id",
|
|
117
|
+
required: true,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
key: "subtype",
|
|
121
|
+
type: "string",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
key: "accept",
|
|
125
|
+
type: "array",
|
|
126
|
+
children: "string",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
key: "search",
|
|
130
|
+
type: "array",
|
|
131
|
+
children: "string",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
key: "label",
|
|
135
|
+
type: "array",
|
|
136
|
+
children: "string",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
key: "image",
|
|
174
140
|
type: "string",
|
|
175
141
|
},
|
|
176
142
|
{
|
|
177
|
-
key: "
|
|
178
|
-
type: "
|
|
143
|
+
key: "values",
|
|
144
|
+
type: "array",
|
|
145
|
+
children: "string",
|
|
179
146
|
},
|
|
180
147
|
],
|
|
181
148
|
},
|
|
182
149
|
],
|
|
183
150
|
},
|
|
151
|
+
{
|
|
152
|
+
key: "user",
|
|
153
|
+
type: ["array", "table"],
|
|
154
|
+
children: "table",
|
|
155
|
+
required: false,
|
|
156
|
+
},
|
|
184
157
|
];
|
|
185
158
|
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
// const DATA = await db.post("user", data_1);
|
|
221
|
-
// const DATA = await db.get("user", { favoriteFoods: "![]Pizza" });
|
|
222
|
-
// db.setTableSchema("user", schema_1);
|
|
223
|
-
// const DATA = await db.get("product", "4", {
|
|
224
|
-
// columns: [
|
|
225
|
-
// "title",
|
|
226
|
-
// "user",
|
|
227
|
-
// "user.username",
|
|
228
|
-
// "user.address.street",
|
|
229
|
-
// "user.hobbies.*.name",
|
|
230
|
-
// ],
|
|
231
|
-
// });
|
|
232
|
-
// return os.platform();
|
|
233
|
-
// const DATA = await db.get("user", {
|
|
234
|
-
// "hobbies.*.name": "*Reading,",
|
|
235
|
-
// });
|
|
236
|
-
// db.setTableSchema("order", schema_3);
|
|
237
|
-
const DATA = await db.get("product", "7a6f37d12fac6d4dd082a69e92fc1f07", {
|
|
238
|
-
columns: [
|
|
239
|
-
"!user.favoriteFoods",
|
|
240
|
-
"!user.username",
|
|
241
|
-
"*",
|
|
242
|
-
"!user.hobbies.*.name",
|
|
159
|
+
const data_2 = [
|
|
160
|
+
{
|
|
161
|
+
name: "Inicontent",
|
|
162
|
+
slug: "inicontent",
|
|
163
|
+
allowed_domains: ["http://localhost:3000"],
|
|
164
|
+
tables: [
|
|
165
|
+
{
|
|
166
|
+
name: "User",
|
|
167
|
+
slug: "user",
|
|
168
|
+
allowed_methods: [
|
|
169
|
+
{
|
|
170
|
+
role: "user",
|
|
171
|
+
methods: "cru",
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
role: "guest",
|
|
175
|
+
methods: "c",
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: "Database",
|
|
181
|
+
slug: "database",
|
|
182
|
+
allowed_methods: [
|
|
183
|
+
{
|
|
184
|
+
role: "user",
|
|
185
|
+
methods: "crud",
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
role: "guest",
|
|
189
|
+
methods: "c",
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
},
|
|
243
193
|
],
|
|
244
|
-
|
|
245
|
-
|
|
194
|
+
user: 1,
|
|
195
|
+
},
|
|
196
|
+
];
|
|
197
|
+
try {
|
|
198
|
+
// db.setTableSchema("database", schema_2);
|
|
199
|
+
// const DATA = await db.post("database", data_2);
|
|
200
|
+
const DATA = await db.get("database", 1);
|
|
201
|
+
console.log(
|
|
202
|
+
JSON.stringify(
|
|
203
|
+
(DATA as Data).tables.find((table: any) => table.slug === "session"),
|
|
204
|
+
null,
|
|
205
|
+
4
|
|
206
|
+
)
|
|
207
|
+
);
|
|
246
208
|
} catch (er) {
|
|
247
209
|
console.log(er);
|
|
248
210
|
}
|