inibase 1.0.0-rc.4 → 1.0.0-rc.6
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 +17 -11
- package/file.ts +230 -84
- package/index.test.ts +204 -0
- package/index.ts +715 -417
- package/package.json +4 -3
- package/tsconfig.json +2 -1
- package/utils.ts +156 -45
package/index.test.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import Inibase, { Schema, Data } from "./index";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
// import os from "os";
|
|
4
|
+
// Create a new instance of Inibase with the database path
|
|
5
|
+
const db = new Inibase("inicontent", join("..", "inicontent", "databases"));
|
|
6
|
+
|
|
7
|
+
const schema_1: Schema = [
|
|
8
|
+
{
|
|
9
|
+
key: "username",
|
|
10
|
+
type: "string",
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
key: "password",
|
|
15
|
+
type: "password",
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
key: "email",
|
|
20
|
+
type: "email",
|
|
21
|
+
required: true,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: "role",
|
|
25
|
+
type: "string",
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const data_1: Data = [
|
|
31
|
+
{
|
|
32
|
+
username: "admin",
|
|
33
|
+
password: "admina",
|
|
34
|
+
email: "karim.amahtil@gmail.com",
|
|
35
|
+
role: "admin",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
username: "kamatil",
|
|
39
|
+
password: "admina",
|
|
40
|
+
email: "karim.amahtil21@gmail.com",
|
|
41
|
+
role: "user",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
username: "tvonthego",
|
|
45
|
+
password: "azqswx",
|
|
46
|
+
email: "vip72abdo@gmail.com",
|
|
47
|
+
role: "user",
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const schema_2: Schema = [
|
|
52
|
+
{
|
|
53
|
+
key: "name",
|
|
54
|
+
type: "string",
|
|
55
|
+
required: true,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
key: "slug",
|
|
59
|
+
type: "string",
|
|
60
|
+
required: true,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: "icon",
|
|
64
|
+
type: "url",
|
|
65
|
+
required: false,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
key: "languages",
|
|
69
|
+
type: "array",
|
|
70
|
+
children: "string",
|
|
71
|
+
required: false,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: "allowed_domains",
|
|
75
|
+
type: "array",
|
|
76
|
+
children: "url",
|
|
77
|
+
required: false,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: "tables",
|
|
81
|
+
type: "array",
|
|
82
|
+
children: [
|
|
83
|
+
{
|
|
84
|
+
key: "name",
|
|
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,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
key: "schema",
|
|
112
|
+
type: "array",
|
|
113
|
+
children: [
|
|
114
|
+
{
|
|
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",
|
|
140
|
+
type: "string",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
key: "values",
|
|
144
|
+
type: "array",
|
|
145
|
+
children: "string",
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
key: "user",
|
|
153
|
+
type: ["array", "table"],
|
|
154
|
+
children: "table",
|
|
155
|
+
required: false,
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
|
|
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
|
+
},
|
|
193
|
+
],
|
|
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", "4f928b04e660de92dc904580055dbe23");
|
|
201
|
+
console.log(JSON.stringify(DATA, null, 4));
|
|
202
|
+
} catch (er) {
|
|
203
|
+
console.log(er);
|
|
204
|
+
}
|