@aromix/core 0.2.0 → 0.3.1

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 CHANGED
@@ -1,211 +1,96 @@
1
- import { AnySchema, Operator } from '@aromix/validator';
1
+ import { AnySchema } from '@aromix/validator';
2
2
 
3
- type Platform = 'node' | 'bun' | 'cloudflare:worker';
4
- interface BuildConfig {
5
- entry: string;
6
- outDir: string;
7
- platform: Platform;
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
- /** Identity fn :: exists purely for autocomplete and type safety */
13
- declare function build(options: BuildConfig): BuildConfig;
9
+ declare function KvAdapter(adapter: KvAdapter): KvAdapter;
14
10
 
15
- declare namespace Kv {
16
- interface Adapter {
17
- get(key: string): Promise<unknown>;
18
- set(key: string, value: unknown): Promise<void>;
19
- delete(key: string): Promise<void>;
20
- has(key: string): Promise<boolean>;
21
- }
22
- function adapter(adapter: Kv.Adapter): Adapter;
23
- interface EntityInput<Schema extends AnySchema> {
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: Kv.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
- interface ColumnTypeMap {
43
- int: number
44
- real: number
45
- text: string
46
- blob: Uint8Array
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
- type ColumnType = keyof ColumnTypeMap
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 ColumnReference {
72
- entityName: string
73
- columnName: string
74
- tableState: Record<string, ColumnState>
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
- type Chain<Type extends ColumnType, Used extends string = never, Output = ColumnTypeMap[Type]> = Omit<
95
- {
96
- readonly state: ColumnState
97
- primaryKey(): Chain<Type, Used | 'primaryKey'>
98
- autoIncrement(): Chain<Type, Used | 'autoIncrement'>
99
- notNull(): Chain<Type, Used | 'notNull'>
100
- unique(conflict?: UniqueConflict): Chain<Type, Used | 'unique'>
101
- index(): Chain<Type, Used | 'index'>
102
- collate(value: Collation): Chain<Type, Used | 'collate'>
103
- gt(value: number): Chain<Type, Used>
104
- gte(value: number): Chain<Type, Used>
105
- lt(value: number): Chain<Type, Used>
106
- lte(value: number): Chain<Type, Used>
107
- minLength(value: number): Chain<Type, Used>
108
- maxLength(value: number): Chain<Type, Used>
109
- in(values: string[]): Chain<Type, Used | 'in'>
110
- references(col: unknown, actions?: ReferenceAction[]): Chain<Type, Used | 'references'>
111
- default(value: ColumnTypeMap[Type]): Chain<Type, Used | 'default'>
112
- defaultFn(fn: () => ColumnTypeMap[Type]): Chain<Type, Used | 'defaultFn'>
113
- onUpdate(fn: () => ColumnTypeMap[Type]): Chain<Type, Used | 'onUpdate'>
114
- pipe<Next>(operator: Operator<Output, Next>): Chain<Type, Used, Next>
115
- },
116
- Used
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: Sqlite.Adapter;
181
- columns: State;
182
- options(ctx: TableOptionsCtx<State>): void;
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 { type BuildConfig, type Chain, type CheckExpression, Column, type ColumnKey, type ColumnReference, type ColumnState, Kv, type Platform, Sqlite, type TableOptionsCtx, type TableState, type UniqueConflict, build, lite };
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/build.ts
2
- function build(options) {
3
- return options;
1
+ // src/kv/adapter.ts
2
+ function KvAdapter(adapter) {
3
+ return adapter;
4
4
  }
5
5
 
6
- // src/drivers/kv.ts
7
- var Kv;
8
- ((Kv2) => {
9
- function adapter(adapter2) {
10
- return adapter2;
11
- }
12
- Kv2.adapter = adapter;
13
- function entity(input) {
14
- const adapter2 = input.adapter;
15
- return {
16
- async get(key) {
17
- const formattedKey = `${input.name}:${key}`;
18
- const raw = await adapter2.get(formattedKey);
19
- return input.model.parse(raw);
20
- },
21
- async set(key, value) {
22
- const formattedKey = `${input.name}:${key}`;
23
- const validated = input.model.parse(value);
24
- await adapter2.set(formattedKey, validated);
25
- },
26
- async delete(key) {
27
- const formattedKey = `${input.name}:${key}`;
28
- await adapter2.delete(formattedKey);
29
- },
30
- async has(key) {
31
- const formattedKey = `${input.name}:${key}`;
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
- const state = {
57
- name: input.name,
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/lite/column.ts
113
- var Column = class _Column {
114
- constructor(state) {
115
- this.state = state;
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/lite/index.ts
208
- var lite = {
209
- int() {
210
- return Column.create("int");
211
- },
212
- real() {
213
- return Column.create("real");
214
- },
215
- text() {
216
- return Column.create("text");
217
- },
218
- blob() {
219
- return Column.create("blob");
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
- Column,
224
- Kv,
225
- Sqlite,
226
- build,
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.2.0",
3
+ "version": "0.3.1",
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
@@ -1,3 +0,0 @@
1
- # @aromix/core
2
-
3
- Core runtime-agnostic framework for Aromix.