@aromix/core 0.2.0 → 0.3.0
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/dist/index.d.ts +83 -198
- package/dist/index.js +67 -221
- package/package.json +9 -11
- package/README.md +0 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,211 +1,96 @@
|
|
|
1
|
-
import { AnySchema
|
|
1
|
+
import { AnySchema } from '@aromix/validator';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
sourcemap: boolean;
|
|
9
|
-
minify: boolean;
|
|
10
|
-
tsConfig: string;
|
|
3
|
+
interface KvAdapter {
|
|
4
|
+
get(key: string): Promise<unknown>;
|
|
5
|
+
set(key: string, value: unknown): Promise<void>;
|
|
6
|
+
delete(key: string): Promise<void>;
|
|
7
|
+
has(key: string): Promise<boolean>;
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
declare function build(options: BuildConfig): BuildConfig;
|
|
9
|
+
declare function KvAdapter(adapter: KvAdapter): KvAdapter;
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
interface KvEntityInput<Schema extends AnySchema> {
|
|
12
|
+
name: string;
|
|
13
|
+
adapter: KvAdapter;
|
|
14
|
+
model: Schema;
|
|
15
|
+
}
|
|
16
|
+
interface KvEntityOutput<Schema extends AnySchema> {
|
|
17
|
+
get(key: string): Promise<Schema['$infer']>;
|
|
18
|
+
set(key: string, value: Schema['$infer']): Promise<void>;
|
|
19
|
+
delete(key: string): Promise<void>;
|
|
20
|
+
has(key: string): Promise<boolean>;
|
|
21
|
+
state: {
|
|
24
22
|
name: string;
|
|
25
|
-
adapter:
|
|
23
|
+
adapter: KvAdapter;
|
|
26
24
|
model: Schema;
|
|
27
|
-
}
|
|
28
|
-
interface EntityOutput<Schema extends AnySchema> {
|
|
29
|
-
get(key: string): Promise<Schema['$infer']>;
|
|
30
|
-
set(key: string, value: Schema['$infer']): Promise<void>;
|
|
31
|
-
delete(key: string): Promise<void>;
|
|
32
|
-
has(key: string): Promise<boolean>;
|
|
33
|
-
state: {
|
|
34
|
-
name: string;
|
|
35
|
-
adapter: Kv.Adapter;
|
|
36
|
-
model: Schema;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function entity<Schema extends AnySchema>(input: Kv.EntityInput<Schema>): Kv.EntityOutput<Schema>;
|
|
25
|
+
};
|
|
40
26
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
declare function KvEntity<Schema extends AnySchema>(input: KvEntityInput<Schema>): KvEntityOutput<Schema>;
|
|
28
|
+
|
|
29
|
+
interface MongoCollectionAdapter {
|
|
30
|
+
insertOne(doc: unknown): Promise<{
|
|
31
|
+
insertedId: unknown;
|
|
32
|
+
}>;
|
|
33
|
+
insertMany(docs: unknown[]): Promise<{
|
|
34
|
+
insertedIds: unknown[];
|
|
35
|
+
}>;
|
|
36
|
+
findOne(filter: unknown): Promise<unknown | null>;
|
|
37
|
+
find(filter: unknown): Promise<unknown[]>;
|
|
38
|
+
updateOne(filter: unknown, update: unknown): Promise<{
|
|
39
|
+
matchedCount: number;
|
|
40
|
+
modifiedCount: number;
|
|
41
|
+
}>;
|
|
42
|
+
updateMany(filter: unknown, update: unknown): Promise<{
|
|
43
|
+
matchedCount: number;
|
|
44
|
+
modifiedCount: number;
|
|
45
|
+
}>;
|
|
46
|
+
deleteOne(filter: unknown): Promise<{
|
|
47
|
+
deletedCount: number;
|
|
48
|
+
}>;
|
|
49
|
+
deleteMany(filter: unknown): Promise<{
|
|
50
|
+
deletedCount: number;
|
|
51
|
+
}>;
|
|
52
|
+
countDocuments(filter?: unknown): Promise<number>;
|
|
47
53
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
type UniqueConflict = 'conflict:error' | 'conflict:replace' | 'conflict:ignore'
|
|
52
|
-
type Collation = 'binary' | 'nocase' | 'rtrim'
|
|
53
|
-
|
|
54
|
-
type ReferenceAction =
|
|
55
|
-
| 'delete:noAction'
|
|
56
|
-
| 'update:noAction'
|
|
57
|
-
| 'delete:restrict'
|
|
58
|
-
| 'update:restrict'
|
|
59
|
-
| 'delete:cascade'
|
|
60
|
-
| 'update:cascade'
|
|
61
|
-
| 'delete:setNull'
|
|
62
|
-
| 'update:setNull'
|
|
63
|
-
| 'delete:setDefault'
|
|
64
|
-
| 'update:setDefault'
|
|
65
|
-
|
|
66
|
-
interface CheckEntry {
|
|
67
|
-
op: 'gt' | 'gte' | 'lt' | 'lte' | 'minLength' | 'maxLength'
|
|
68
|
-
val: number
|
|
54
|
+
interface MongoAdapter {
|
|
55
|
+
collection(name: string): MongoCollectionAdapter;
|
|
69
56
|
}
|
|
57
|
+
declare function MongoAdapter(adapter: MongoAdapter): MongoAdapter;
|
|
70
58
|
|
|
71
|
-
interface
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
interface ColumnState {
|
|
77
|
-
colType: ColumnType
|
|
78
|
-
primaryKey: boolean
|
|
79
|
-
autoIncrement: boolean
|
|
80
|
-
notNull: boolean
|
|
81
|
-
unique: boolean
|
|
82
|
-
uniqueConflict: UniqueConflict
|
|
83
|
-
index: boolean
|
|
84
|
-
checks: CheckEntry[]
|
|
85
|
-
in: string[]
|
|
86
|
-
collate?: Collation
|
|
87
|
-
references?: { col: ColumnReference; actions: ReferenceAction[] }
|
|
88
|
-
default?: unknown
|
|
89
|
-
defaultFn?: () => unknown
|
|
90
|
-
onUpdate?: () => unknown
|
|
91
|
-
pipes: Operator<any, any>[]
|
|
59
|
+
interface MongoEntityInput<Schema extends AnySchema> {
|
|
60
|
+
name: string;
|
|
61
|
+
adapter: MongoAdapter;
|
|
62
|
+
model: Schema;
|
|
92
63
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
type TableState = Record<string, { readonly state: ColumnState }>
|
|
120
|
-
|
|
121
|
-
interface CheckExpression {
|
|
122
|
-
left: string
|
|
123
|
-
op: 'gt' | 'gte' | 'lt' | 'lte'
|
|
124
|
-
right: string
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
type ColumnKey<State extends TableState> = keyof State & string
|
|
128
|
-
|
|
129
|
-
interface TableOptionsCtx<State extends TableState> {
|
|
130
|
-
unique(cols: ColumnKey<State>[], conflict: UniqueConflict): void
|
|
131
|
-
primaryKey(cols: ColumnKey<State>[]): void
|
|
132
|
-
index(cols: ColumnKey<State>[]): void
|
|
133
|
-
uniqueIndex(cols: ColumnKey<State>[]): void
|
|
134
|
-
checks(exprs: CheckExpression[]): void
|
|
135
|
-
gt(left: ColumnKey<State>, right: ColumnKey<State>): CheckExpression
|
|
136
|
-
gte(left: ColumnKey<State>, right: ColumnKey<State>): CheckExpression
|
|
137
|
-
lt(left: ColumnKey<State>, right: ColumnKey<State>): CheckExpression
|
|
138
|
-
lte(left: ColumnKey<State>, right: ColumnKey<State>): CheckExpression
|
|
139
|
-
withoutRowId(): void
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
declare class Column<Type extends ColumnType> {
|
|
143
|
-
readonly state: ColumnState;
|
|
144
|
-
private constructor();
|
|
145
|
-
static create<Type extends ColumnType>(colType: Type): Chain<Type>;
|
|
146
|
-
primaryKey(): this;
|
|
147
|
-
autoIncrement(): this;
|
|
148
|
-
notNull(): this;
|
|
149
|
-
unique(conflict: UniqueConflict): this;
|
|
150
|
-
index(): this;
|
|
151
|
-
collate(value: Collation): this;
|
|
152
|
-
gt(value: number): this;
|
|
153
|
-
gte(value: number): this;
|
|
154
|
-
lt(value: number): this;
|
|
155
|
-
lte(value: number): this;
|
|
156
|
-
minLength(value: number): this;
|
|
157
|
-
maxLength(value: number): this;
|
|
158
|
-
in(values: string[]): this;
|
|
159
|
-
references(col: ColumnReference, actions?: ReferenceAction[]): this;
|
|
160
|
-
default(value: ColumnTypeMap[Type]): this;
|
|
161
|
-
defaultFn(fn: () => ColumnTypeMap[Type]): this;
|
|
162
|
-
onUpdate(fn: () => ColumnTypeMap[Type]): this;
|
|
163
|
-
pipe<Next>(operator: Operator<ColumnTypeMap[Type], Next>): this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
declare const lite: {
|
|
167
|
-
int(): Chain<"int">;
|
|
168
|
-
real(): Chain<"real">;
|
|
169
|
-
text(): Chain<"text">;
|
|
170
|
-
blob(): Chain<"blob">;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
declare namespace Sqlite {
|
|
174
|
-
interface Adapter {
|
|
175
|
-
query(sql: string): Promise<unknown>;
|
|
176
|
-
}
|
|
177
|
-
function adapter(adapter: Sqlite.Adapter): Adapter;
|
|
178
|
-
interface EntityInput<State extends TableState> {
|
|
64
|
+
interface MongoEntityOutput<Schema extends AnySchema> {
|
|
65
|
+
insertOne(doc: Schema['$infer']): Promise<{
|
|
66
|
+
insertedId: unknown;
|
|
67
|
+
}>;
|
|
68
|
+
insertMany(docs: Schema['$infer'][]): Promise<{
|
|
69
|
+
insertedIds: unknown[];
|
|
70
|
+
}>;
|
|
71
|
+
findOne(filter: Record<string, unknown>): Promise<Schema['$infer'] | null>;
|
|
72
|
+
find(filter: Record<string, unknown>): Promise<Schema['$infer'][]>;
|
|
73
|
+
updateOne(filter: Record<string, unknown>, update: Record<string, unknown>): Promise<{
|
|
74
|
+
matchedCount: number;
|
|
75
|
+
modifiedCount: number;
|
|
76
|
+
}>;
|
|
77
|
+
updateMany(filter: Record<string, unknown>, update: Record<string, unknown>): Promise<{
|
|
78
|
+
matchedCount: number;
|
|
79
|
+
modifiedCount: number;
|
|
80
|
+
}>;
|
|
81
|
+
deleteOne(filter: Record<string, unknown>): Promise<{
|
|
82
|
+
deletedCount: number;
|
|
83
|
+
}>;
|
|
84
|
+
deleteMany(filter: Record<string, unknown>): Promise<{
|
|
85
|
+
deletedCount: number;
|
|
86
|
+
}>;
|
|
87
|
+
countDocuments(filter?: Record<string, unknown>): Promise<number>;
|
|
88
|
+
state: {
|
|
179
89
|
name: string;
|
|
180
|
-
adapter:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
interface EntityOutput<State extends TableState> {
|
|
185
|
-
state: {
|
|
186
|
-
name: string;
|
|
187
|
-
columns: {
|
|
188
|
-
[Key in keyof State]: ColumnState;
|
|
189
|
-
};
|
|
190
|
-
unique: {
|
|
191
|
-
cols: string[];
|
|
192
|
-
conflict?: UniqueConflict;
|
|
193
|
-
}[];
|
|
194
|
-
primaryKey: {
|
|
195
|
-
cols: string[];
|
|
196
|
-
}[];
|
|
197
|
-
index: {
|
|
198
|
-
cols: string[];
|
|
199
|
-
}[];
|
|
200
|
-
uniqueIndex: {
|
|
201
|
-
cols: string[];
|
|
202
|
-
}[];
|
|
203
|
-
checks: CheckExpression[];
|
|
204
|
-
withoutRowId: boolean;
|
|
205
|
-
};
|
|
206
|
-
col(columnName: ColumnKey<State>): ColumnReference;
|
|
207
|
-
}
|
|
208
|
-
function entity<State extends TableState>(input: Sqlite.EntityInput<State>): Sqlite.EntityOutput<State>;
|
|
90
|
+
adapter: MongoAdapter;
|
|
91
|
+
model: Schema;
|
|
92
|
+
};
|
|
209
93
|
}
|
|
94
|
+
declare function MongoEntity<Schema extends AnySchema>(input: MongoEntityInput<Schema>): MongoEntityOutput<Schema>;
|
|
210
95
|
|
|
211
|
-
export {
|
|
96
|
+
export { KvAdapter, KvEntity, type KvEntityInput, type KvEntityOutput, MongoAdapter, type MongoCollectionAdapter, MongoEntity, type MongoEntityInput, type MongoEntityOutput };
|
package/dist/index.js
CHANGED
|
@@ -1,228 +1,74 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
// src/kv/adapter.ts
|
|
2
|
+
function KvAdapter(adapter) {
|
|
3
|
+
return adapter;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
// src/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return await adapter2.has(formattedKey);
|
|
33
|
-
},
|
|
34
|
-
state: {
|
|
35
|
-
adapter: adapter2,
|
|
36
|
-
model: input.model,
|
|
37
|
-
name: input.name
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
Kv2.entity = entity;
|
|
42
|
-
})(Kv || (Kv = {}));
|
|
43
|
-
|
|
44
|
-
// src/drivers/sqlite.ts
|
|
45
|
-
var Sqlite;
|
|
46
|
-
((Sqlite2) => {
|
|
47
|
-
function adapter(adapter2) {
|
|
48
|
-
return adapter2;
|
|
49
|
-
}
|
|
50
|
-
Sqlite2.adapter = adapter;
|
|
51
|
-
function entity(input) {
|
|
52
|
-
const columns = {};
|
|
53
|
-
for (const key of Object.keys(input.columns)) {
|
|
54
|
-
columns[key] = input.columns[key].state;
|
|
6
|
+
// src/kv/entity.ts
|
|
7
|
+
function KvEntity(input) {
|
|
8
|
+
const adapter = input.adapter;
|
|
9
|
+
return {
|
|
10
|
+
async get(key) {
|
|
11
|
+
const formattedKey = `${input.name}:${key}`;
|
|
12
|
+
const raw = await adapter.get(formattedKey);
|
|
13
|
+
return input.model.parse(raw);
|
|
14
|
+
},
|
|
15
|
+
async set(key, value) {
|
|
16
|
+
const formattedKey = `${input.name}:${key}`;
|
|
17
|
+
const validated = input.model.parse(value);
|
|
18
|
+
await adapter.set(formattedKey, validated);
|
|
19
|
+
},
|
|
20
|
+
async delete(key) {
|
|
21
|
+
const formattedKey = `${input.name}:${key}`;
|
|
22
|
+
await adapter.delete(formattedKey);
|
|
23
|
+
},
|
|
24
|
+
async has(key) {
|
|
25
|
+
const formattedKey = `${input.name}:${key}`;
|
|
26
|
+
return await adapter.has(formattedKey);
|
|
27
|
+
},
|
|
28
|
+
state: {
|
|
29
|
+
adapter,
|
|
30
|
+
model: input.model,
|
|
31
|
+
name: input.name
|
|
55
32
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
columns,
|
|
59
|
-
unique: [],
|
|
60
|
-
primaryKey: [],
|
|
61
|
-
index: [],
|
|
62
|
-
uniqueIndex: [],
|
|
63
|
-
checks: [],
|
|
64
|
-
withoutRowId: false
|
|
65
|
-
};
|
|
66
|
-
input.options({
|
|
67
|
-
unique(cols, conflict) {
|
|
68
|
-
state.unique.push({ cols, conflict });
|
|
69
|
-
},
|
|
70
|
-
primaryKey(cols) {
|
|
71
|
-
state.primaryKey.push({ cols });
|
|
72
|
-
},
|
|
73
|
-
index(cols) {
|
|
74
|
-
state.index.push({ cols });
|
|
75
|
-
},
|
|
76
|
-
uniqueIndex(cols) {
|
|
77
|
-
state.uniqueIndex.push({ cols });
|
|
78
|
-
},
|
|
79
|
-
checks(exprs) {
|
|
80
|
-
state.checks = exprs;
|
|
81
|
-
},
|
|
82
|
-
gt(left, right) {
|
|
83
|
-
return { left, op: "gt", right };
|
|
84
|
-
},
|
|
85
|
-
gte(left, right) {
|
|
86
|
-
return { left, op: "gte", right };
|
|
87
|
-
},
|
|
88
|
-
lt(left, right) {
|
|
89
|
-
return { left, op: "lt", right };
|
|
90
|
-
},
|
|
91
|
-
lte(left, right) {
|
|
92
|
-
return { left, op: "lte", right };
|
|
93
|
-
},
|
|
94
|
-
withoutRowId() {
|
|
95
|
-
state.withoutRowId = true;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
return {
|
|
99
|
-
state,
|
|
100
|
-
col(columnName) {
|
|
101
|
-
return {
|
|
102
|
-
entityName: input.name,
|
|
103
|
-
columnName,
|
|
104
|
-
tableState: columns
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
Sqlite2.entity = entity;
|
|
110
|
-
})(Sqlite || (Sqlite = {}));
|
|
33
|
+
};
|
|
34
|
+
}
|
|
111
35
|
|
|
112
|
-
// src/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
state;
|
|
118
|
-
static create(colType) {
|
|
119
|
-
return new _Column({
|
|
120
|
-
colType,
|
|
121
|
-
primaryKey: false,
|
|
122
|
-
autoIncrement: false,
|
|
123
|
-
notNull: false,
|
|
124
|
-
unique: false,
|
|
125
|
-
uniqueConflict: "conflict:error",
|
|
126
|
-
index: false,
|
|
127
|
-
checks: [],
|
|
128
|
-
in: [],
|
|
129
|
-
pipes: []
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
primaryKey() {
|
|
133
|
-
this.state.primaryKey = true;
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
autoIncrement() {
|
|
137
|
-
this.state.autoIncrement = true;
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
notNull() {
|
|
141
|
-
this.state.notNull = true;
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
unique(conflict) {
|
|
145
|
-
this.state.unique = true;
|
|
146
|
-
this.state.uniqueConflict = conflict;
|
|
147
|
-
return this;
|
|
148
|
-
}
|
|
149
|
-
index() {
|
|
150
|
-
this.state.index = true;
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
collate(value) {
|
|
154
|
-
this.state.collate = value;
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
gt(value) {
|
|
158
|
-
this.state.checks.push({ op: "gt", val: value });
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
gte(value) {
|
|
162
|
-
this.state.checks.push({ op: "gte", val: value });
|
|
163
|
-
return this;
|
|
164
|
-
}
|
|
165
|
-
lt(value) {
|
|
166
|
-
this.state.checks.push({ op: "lt", val: value });
|
|
167
|
-
return this;
|
|
168
|
-
}
|
|
169
|
-
lte(value) {
|
|
170
|
-
this.state.checks.push({ op: "lte", val: value });
|
|
171
|
-
return this;
|
|
172
|
-
}
|
|
173
|
-
minLength(value) {
|
|
174
|
-
this.state.checks.push({ op: "minLength", val: value });
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
maxLength(value) {
|
|
178
|
-
this.state.checks.push({ op: "maxLength", val: value });
|
|
179
|
-
return this;
|
|
180
|
-
}
|
|
181
|
-
in(values) {
|
|
182
|
-
this.state.in = values;
|
|
183
|
-
return this;
|
|
184
|
-
}
|
|
185
|
-
references(col, actions = []) {
|
|
186
|
-
this.state.references = { col, actions };
|
|
187
|
-
return this;
|
|
188
|
-
}
|
|
189
|
-
default(value) {
|
|
190
|
-
this.state.default = value;
|
|
191
|
-
return this;
|
|
192
|
-
}
|
|
193
|
-
defaultFn(fn) {
|
|
194
|
-
this.state.defaultFn = fn;
|
|
195
|
-
return this;
|
|
196
|
-
}
|
|
197
|
-
onUpdate(fn) {
|
|
198
|
-
this.state.onUpdate = fn;
|
|
199
|
-
return this;
|
|
200
|
-
}
|
|
201
|
-
pipe(operator) {
|
|
202
|
-
this.state.pipes.push(operator);
|
|
203
|
-
return this;
|
|
204
|
-
}
|
|
205
|
-
};
|
|
36
|
+
// src/mongo/adapter.ts
|
|
37
|
+
function MongoAdapter(adapter) {
|
|
38
|
+
return adapter;
|
|
39
|
+
}
|
|
206
40
|
|
|
207
|
-
// src/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
41
|
+
// src/mongo/entity.ts
|
|
42
|
+
function MongoEntity(input) {
|
|
43
|
+
const collection = input.adapter.collection(input.name);
|
|
44
|
+
return {
|
|
45
|
+
async insertOne(doc) {
|
|
46
|
+
const validated = input.model.parse(doc);
|
|
47
|
+
return collection.insertOne(validated);
|
|
48
|
+
},
|
|
49
|
+
async insertMany(docs) {
|
|
50
|
+
const validated = docs.map((d) => input.model.parse(d));
|
|
51
|
+
return collection.insertMany(validated);
|
|
52
|
+
},
|
|
53
|
+
async findOne(filter) {
|
|
54
|
+
const raw = await collection.findOne(filter);
|
|
55
|
+
return raw === null ? null : input.model.parse(raw);
|
|
56
|
+
},
|
|
57
|
+
async find(filter) {
|
|
58
|
+
const raw = await collection.find(filter);
|
|
59
|
+
return raw.map((r) => input.model.parse(r));
|
|
60
|
+
},
|
|
61
|
+
updateOne: (filter, update) => collection.updateOne(filter, update),
|
|
62
|
+
updateMany: (filter, update) => collection.updateMany(filter, update),
|
|
63
|
+
deleteOne: (filter) => collection.deleteOne(filter),
|
|
64
|
+
deleteMany: (filter) => collection.deleteMany(filter),
|
|
65
|
+
countDocuments: (filter) => collection.countDocuments(filter),
|
|
66
|
+
state: { name: input.name, adapter: input.adapter, model: input.model }
|
|
67
|
+
};
|
|
68
|
+
}
|
|
222
69
|
export {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
lite
|
|
70
|
+
KvAdapter,
|
|
71
|
+
KvEntity,
|
|
72
|
+
MongoAdapter,
|
|
73
|
+
MongoEntity
|
|
228
74
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aromix/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The Core Package For Aromix",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,9 +19,7 @@
|
|
|
19
19
|
"server",
|
|
20
20
|
"framework",
|
|
21
21
|
"runtime-agnostic",
|
|
22
|
-
"bun",
|
|
23
22
|
"deno",
|
|
24
|
-
"cloudflare",
|
|
25
23
|
"node"
|
|
26
24
|
],
|
|
27
25
|
"files": [
|
|
@@ -37,18 +35,18 @@
|
|
|
37
35
|
"access": "public",
|
|
38
36
|
"registry": "https://registry.npmjs.org"
|
|
39
37
|
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup",
|
|
40
|
+
"dev": "tsup --watch",
|
|
41
|
+
"typecheck": "tsc --noEmit"
|
|
42
|
+
},
|
|
40
43
|
"peerDependencies": {
|
|
41
44
|
"@aromix/validator": "^0.2.0"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
47
|
+
"@aromix/validator": "^0.2.0",
|
|
44
48
|
"@types/node": "^22.10.2",
|
|
45
49
|
"tsup": "^8.3.5",
|
|
46
|
-
"typescript": "^5.7.2"
|
|
47
|
-
"@aromix/validator": "^0.2.0"
|
|
48
|
-
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "tsup",
|
|
51
|
-
"dev": "tsup --watch",
|
|
52
|
-
"typecheck": "tsc --noEmit"
|
|
50
|
+
"typescript": "^5.7.2"
|
|
53
51
|
}
|
|
54
|
-
}
|
|
52
|
+
}
|
package/README.md
DELETED