@aromix/core 0.1.3 → 0.2.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 +171 -116
- package/dist/index.js +198 -159
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnySchema, Operator } from '@aromix/validator';
|
|
2
2
|
|
|
3
3
|
type Platform = 'node' | 'bun' | 'cloudflare:worker';
|
|
4
4
|
interface BuildConfig {
|
|
@@ -12,145 +12,200 @@ interface BuildConfig {
|
|
|
12
12
|
/** Identity fn :: exists purely for autocomplete and type safety */
|
|
13
13
|
declare function build(options: BuildConfig): BuildConfig;
|
|
14
14
|
|
|
15
|
-
declare namespace
|
|
16
|
-
interface
|
|
17
|
-
readonly type: 'kv';
|
|
15
|
+
declare namespace Kv {
|
|
16
|
+
interface Adapter {
|
|
18
17
|
get(key: string): Promise<unknown>;
|
|
19
18
|
set(key: string, value: unknown): Promise<void>;
|
|
20
19
|
delete(key: string): Promise<void>;
|
|
21
20
|
has(key: string): Promise<boolean>;
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
function adapter(adapter: Kv.Adapter): Adapter;
|
|
23
|
+
interface EntityInput<Schema extends AnySchema> {
|
|
24
|
+
name: string;
|
|
25
|
+
adapter: Kv.Adapter;
|
|
26
|
+
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>;
|
|
30
31
|
delete(key: string): Promise<void>;
|
|
31
32
|
has(key: string): Promise<boolean>;
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
state: {
|
|
34
|
+
name: string;
|
|
35
|
+
adapter: Kv.Adapter;
|
|
34
36
|
model: Schema;
|
|
35
|
-
readAccess: Record<string, boolean>;
|
|
36
|
-
writeAccess: Record<string, boolean>;
|
|
37
37
|
};
|
|
38
|
-
}
|
|
38
|
+
}
|
|
39
|
+
function entity<Schema extends AnySchema>(input: Kv.EntityInput<Schema>): Kv.EntityOutput<Schema>;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/** Recursively walks object keys, producing all dot-joined paths. Returns `never` for primitives, null, and undefined. */
|
|
47
|
-
type WalkKeys<Input> = Input extends object ? {
|
|
48
|
-
[Key in keyof Input & string]: Key | `${Key}.${CrushKeys<Input[Key]>}`;
|
|
49
|
-
}[keyof Input & string] : never;
|
|
50
|
-
/** Returns all dot-joined key paths for a given object. Stops at arrays and `Date`. e.g. `{ a: { b: 1 } }` → `"a" | "a.b"` */
|
|
51
|
-
export type CrushKeys<Input> = Input extends unknown[] | Date ? never : WalkKeys<Input>;
|
|
52
|
-
export { };
|
|
42
|
+
interface ColumnTypeMap {
|
|
43
|
+
int: number
|
|
44
|
+
real: number
|
|
45
|
+
text: string
|
|
46
|
+
blob: Uint8Array
|
|
53
47
|
}
|
|
54
48
|
|
|
55
|
-
type
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
set(key: string, value: SchemaInput<Schema>): Promise<void>;
|
|
76
|
-
delete(key: string): Promise<void>;
|
|
77
|
-
[Entity.$meta]: {
|
|
78
|
-
adapter: Adapter.kv;
|
|
79
|
-
model: Schema;
|
|
80
|
-
readAccess: Record<string, boolean>;
|
|
81
|
-
writeAccess: Record<string, boolean>;
|
|
82
|
-
};
|
|
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
|
|
83
69
|
}
|
|
84
70
|
|
|
85
|
-
interface
|
|
86
|
-
|
|
71
|
+
interface ColumnReference {
|
|
72
|
+
entityName: string
|
|
73
|
+
columnName: string
|
|
74
|
+
tableState: Record<string, ColumnState>
|
|
87
75
|
}
|
|
88
|
-
interface
|
|
89
|
-
|
|
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>[]
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
|
107
125
|
}
|
|
108
126
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
|
113
140
|
}
|
|
114
141
|
|
|
115
|
-
declare
|
|
116
|
-
state:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
*/
|
|
138
|
-
function omit<Input, Keys extends keyof Input>(input: Input, remove: Keys[]): Type.Prettify<Omit<Input, Keys>>;
|
|
139
|
-
/**
|
|
140
|
-
* Walks an object recursively and returns all dot-joined key paths.
|
|
141
|
-
* e.g. `{ a: { b: 1 } }` → `["a", "a.b"]`
|
|
142
|
-
* Stops at arrays and non-plain objects.
|
|
143
|
-
*/
|
|
144
|
-
function crushKeys<Input>(input: Input): Type.CrushKeys<Input>[];
|
|
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;
|
|
145
164
|
}
|
|
146
165
|
|
|
147
|
-
declare
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
166
|
+
declare const lite: {
|
|
167
|
+
int(): Chain<"int">;
|
|
168
|
+
real(): Chain<"real">;
|
|
169
|
+
text(): Chain<"text">;
|
|
170
|
+
blob(): Chain<"blob">;
|
|
171
|
+
};
|
|
151
172
|
|
|
152
|
-
declare namespace
|
|
153
|
-
|
|
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> {
|
|
179
|
+
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>;
|
|
154
209
|
}
|
|
155
210
|
|
|
156
|
-
export {
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -3,187 +3,226 @@ function build(options) {
|
|
|
3
3
|
return options;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
// src/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// src/ddl/lite.ddl.ts
|
|
12
|
-
var lite = class {
|
|
13
|
-
constructor() {
|
|
14
|
-
}
|
|
15
|
-
static table() {
|
|
16
|
-
}
|
|
17
|
-
static integer() {
|
|
18
|
-
}
|
|
19
|
-
static int() {
|
|
20
|
-
}
|
|
21
|
-
static real() {
|
|
22
|
-
}
|
|
23
|
-
static text() {
|
|
24
|
-
}
|
|
25
|
-
static blob() {
|
|
26
|
-
}
|
|
27
|
-
static numeric() {
|
|
28
|
-
}
|
|
29
|
-
static any() {
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// src/dml/lite.dml.ts
|
|
34
|
-
var LiteDml = class {
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// src/entity/entity.util.ts
|
|
38
|
-
function createOperation() {
|
|
39
|
-
const state = {};
|
|
40
|
-
const handler = (fields) => {
|
|
41
|
-
for (const field of fields) {
|
|
42
|
-
state[field] = true;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
handler.omit = (fields) => {
|
|
46
|
-
for (const field of fields) {
|
|
47
|
-
state[field] = false;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
return Object.assign(handler, { omit: handler.omit, state });
|
|
51
|
-
}
|
|
52
|
-
async function validate(schema, value) {
|
|
53
|
-
const result = await schema["~standard"].validate(value);
|
|
54
|
-
if ("issues" in result) {
|
|
55
|
-
throw new Error(`Validation failed: ${JSON.stringify(result.issues)}`);
|
|
6
|
+
// src/drivers/kv.ts
|
|
7
|
+
var Kv;
|
|
8
|
+
((Kv2) => {
|
|
9
|
+
function adapter(adapter2) {
|
|
10
|
+
return adapter2;
|
|
56
11
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// src/entity/entity.def.ts
|
|
61
|
-
var Entity;
|
|
62
|
-
((Entity2) => {
|
|
63
|
-
Entity2.$meta = /* @__PURE__ */ Symbol.for("entity:meta");
|
|
64
|
-
function kv(configuration) {
|
|
65
|
-
const readOperation = createOperation();
|
|
66
|
-
const writeOperation = createOperation();
|
|
67
|
-
configuration.access({ read: readOperation, write: writeOperation });
|
|
68
|
-
const adapter = configuration.storage;
|
|
12
|
+
Kv2.adapter = adapter;
|
|
13
|
+
function entity(input) {
|
|
14
|
+
const adapter2 = input.adapter;
|
|
69
15
|
return {
|
|
70
16
|
async get(key) {
|
|
71
|
-
const formattedKey = `${
|
|
72
|
-
const raw = await
|
|
73
|
-
|
|
74
|
-
return validated;
|
|
17
|
+
const formattedKey = `${input.name}:${key}`;
|
|
18
|
+
const raw = await adapter2.get(formattedKey);
|
|
19
|
+
return input.model.parse(raw);
|
|
75
20
|
},
|
|
76
21
|
async set(key, value) {
|
|
77
|
-
const formattedKey = `${
|
|
78
|
-
const validated =
|
|
79
|
-
await
|
|
22
|
+
const formattedKey = `${input.name}:${key}`;
|
|
23
|
+
const validated = input.model.parse(value);
|
|
24
|
+
await adapter2.set(formattedKey, validated);
|
|
80
25
|
},
|
|
81
26
|
async delete(key) {
|
|
82
|
-
const formattedKey = `${
|
|
83
|
-
await
|
|
27
|
+
const formattedKey = `${input.name}:${key}`;
|
|
28
|
+
await adapter2.delete(formattedKey);
|
|
84
29
|
},
|
|
85
30
|
async has(key) {
|
|
86
|
-
const formattedKey = `${
|
|
87
|
-
return await
|
|
31
|
+
const formattedKey = `${input.name}:${key}`;
|
|
32
|
+
return await adapter2.has(formattedKey);
|
|
88
33
|
},
|
|
89
|
-
|
|
90
|
-
adapter,
|
|
91
|
-
model:
|
|
92
|
-
|
|
93
|
-
writeAccess: writeOperation.state
|
|
34
|
+
state: {
|
|
35
|
+
adapter: adapter2,
|
|
36
|
+
model: input.model,
|
|
37
|
+
name: input.name
|
|
94
38
|
}
|
|
95
39
|
};
|
|
96
40
|
}
|
|
97
|
-
|
|
98
|
-
})(
|
|
41
|
+
Kv2.entity = entity;
|
|
42
|
+
})(Kv || (Kv = {}));
|
|
99
43
|
|
|
100
|
-
// src/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return
|
|
105
|
-
},
|
|
106
|
-
decode(buf) {
|
|
107
|
-
return decode(buf);
|
|
108
|
-
},
|
|
109
|
-
async fromRequest(req) {
|
|
110
|
-
const contentType = req.headers.get("content-type");
|
|
111
|
-
if (contentType !== "application/x-msgpack") {
|
|
112
|
-
throw new Error(`Invalid content-type "${contentType}" \u2014 only application/x-msgpack is accepted`);
|
|
113
|
-
}
|
|
114
|
-
const buf = await req.arrayBuffer();
|
|
115
|
-
if (buf.byteLength === 0) {
|
|
116
|
-
return void 0;
|
|
117
|
-
}
|
|
118
|
-
return decode(new Uint8Array(buf));
|
|
119
|
-
},
|
|
120
|
-
response(data) {
|
|
121
|
-
return new Response(encode(data), {
|
|
122
|
-
status: 200,
|
|
123
|
-
headers: { "Content-Type": "application/x-msgpack" }
|
|
124
|
-
});
|
|
44
|
+
// src/drivers/sqlite.ts
|
|
45
|
+
var Sqlite;
|
|
46
|
+
((Sqlite2) => {
|
|
47
|
+
function adapter(adapter2) {
|
|
48
|
+
return adapter2;
|
|
125
49
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// src/global/kit.ts
|
|
133
|
-
var Kit;
|
|
134
|
-
((Kit2) => {
|
|
135
|
-
function omit(input, remove) {
|
|
136
|
-
const proto = Object.getPrototypeOf(input);
|
|
137
|
-
const clone = Object.create(proto);
|
|
138
|
-
Object.assign(clone, input);
|
|
139
|
-
for (const key of remove) {
|
|
140
|
-
delete clone[key];
|
|
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;
|
|
141
55
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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;
|
|
150
96
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
state,
|
|
100
|
+
col(columnName) {
|
|
101
|
+
return {
|
|
102
|
+
entityName: input.name,
|
|
103
|
+
columnName,
|
|
104
|
+
tableState: columns
|
|
105
|
+
};
|
|
156
106
|
}
|
|
157
107
|
};
|
|
158
|
-
walk(input, "");
|
|
159
|
-
return keys;
|
|
160
108
|
}
|
|
161
|
-
|
|
162
|
-
})(
|
|
109
|
+
Sqlite2.entity = entity;
|
|
110
|
+
})(Sqlite || (Sqlite = {}));
|
|
163
111
|
|
|
164
|
-
// src/
|
|
165
|
-
|
|
166
|
-
|
|
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
|
+
};
|
|
167
206
|
|
|
168
|
-
// src/
|
|
169
|
-
var
|
|
170
|
-
(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
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
|
+
};
|
|
176
222
|
export {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
LiteDml,
|
|
181
|
-
Storage,
|
|
223
|
+
Column,
|
|
224
|
+
Kv,
|
|
225
|
+
Sqlite,
|
|
182
226
|
build,
|
|
183
|
-
|
|
184
|
-
createOperation,
|
|
185
|
-
lite,
|
|
186
|
-
make,
|
|
187
|
-
toFetchHandler,
|
|
188
|
-
validate
|
|
227
|
+
lite
|
|
189
228
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aromix/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Core
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The Core Package For Aromix",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://aromixjs.github.io/aromix",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"access": "public",
|
|
38
38
|
"registry": "https://registry.npmjs.org"
|
|
39
39
|
},
|
|
40
|
-
"
|
|
41
|
-
"@
|
|
42
|
-
"@standard-schema/spec": "^1.1.0"
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@aromix/validator": "^0.2.0"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@types/node": "^22.10.2",
|
|
46
45
|
"tsup": "^8.3.5",
|
|
47
|
-
"typescript": "^5.7.2"
|
|
46
|
+
"typescript": "^5.7.2",
|
|
47
|
+
"@aromix/validator": "^0.2.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsup",
|