@aromix/core 0.1.3 → 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 CHANGED
@@ -1,156 +1,96 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
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;
11
- }
12
- /** Identity fn :: exists purely for autocomplete and type safety */
13
- declare function build(options: BuildConfig): BuildConfig;
14
-
15
- declare namespace Adapter {
16
- interface kv {
17
- readonly type: 'kv';
18
- get(key: string): Promise<unknown>;
19
- set(key: string, value: unknown): Promise<void>;
20
- delete(key: string): Promise<void>;
21
- has(key: string): Promise<boolean>;
22
- }
23
- }
24
-
25
- declare namespace Entity {
26
- const $meta: unique symbol;
27
- function kv<Schema extends StandardSchemaV1>(configuration: EntityConfig<Schema>): {
28
- get(key: string): Promise<SchemaOutput<Schema>>;
29
- set(key: string, value: SchemaInput<Schema>): Promise<void>;
30
- delete(key: string): Promise<void>;
31
- has(key: string): Promise<boolean>;
32
- [$meta]: {
33
- adapter: Adapter.kv;
34
- model: Schema;
35
- readAccess: Record<string, boolean>;
36
- writeAccess: Record<string, boolean>;
37
- };
38
- };
39
- }
40
-
41
- declare namespace Type {
42
- /** Resolves a mapped/generic type into a plain object shape — improves IDE hover readability. */
43
- export type Prettify<TargetType> = {
44
- [Key in keyof TargetType]: TargetType[Key];
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 { };
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>;
53
8
  }
9
+ declare function KvAdapter(adapter: KvAdapter): KvAdapter;
54
10
 
55
- type SchemaInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
56
- type SchemaOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
57
- interface EntityConfig<Schema extends StandardSchemaV1> {
11
+ interface KvEntityInput<Schema extends AnySchema> {
58
12
  name: string;
59
- storage: Adapter.kv;
60
- guards?: any[];
61
- effects?: any[];
13
+ adapter: KvAdapter;
62
14
  model: Schema;
63
- access: (can: PermissionSet<SchemaOutput<Schema>>) => void;
64
- }
65
- interface Operation<Model> {
66
- (fields: Type.CrushKeys<Model>[]): void;
67
- omit(fields: Type.CrushKeys<Model>[]): void;
68
15
  }
69
- interface PermissionSet<Model> {
70
- read: Operation<Model>;
71
- write: Operation<Model>;
72
- }
73
- interface EntityKV<Schema extends StandardSchemaV1> {
74
- get(key: string): Promise<SchemaOutput<Schema>>;
75
- set(key: string, value: SchemaInput<Schema>): Promise<void>;
16
+ interface KvEntityOutput<Schema extends AnySchema> {
17
+ get(key: string): Promise<Schema['$infer']>;
18
+ set(key: string, value: Schema['$infer']): Promise<void>;
76
19
  delete(key: string): Promise<void>;
77
- [Entity.$meta]: {
78
- adapter: Adapter.kv;
20
+ has(key: string): Promise<boolean>;
21
+ state: {
22
+ name: string;
23
+ adapter: KvAdapter;
79
24
  model: Schema;
80
- readAccess: Record<string, boolean>;
81
- writeAccess: Record<string, boolean>;
82
25
  };
83
26
  }
84
-
85
- interface ComposeConfig {
86
- entities: EntityKV<StandardSchemaV1>[];
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>;
87
53
  }
88
- interface ResolvedModule {
89
- entities: EntityKV<StandardSchemaV1>[];
90
- }
91
-
92
- declare function compose(config: ComposeConfig): ResolvedModule;
93
-
94
- /**
95
- * DDL IMPLEMENTATION FOR SQL LITE
96
- */
97
- declare class lite {
98
- private constructor();
99
- static table(): void;
100
- static integer(): void;
101
- static int(): void;
102
- static real(): void;
103
- static text(): void;
104
- static blob(): void;
105
- static numeric(): void;
106
- static any(): void;
54
+ interface MongoAdapter {
55
+ collection(name: string): MongoCollectionAdapter;
107
56
  }
57
+ declare function MongoAdapter(adapter: MongoAdapter): MongoAdapter;
108
58
 
109
- /**
110
- * DML IMPLEMENTATION FOR SQL LITE
111
- */
112
- declare class LiteDml {
113
- }
114
-
115
- declare function createOperation<Model>(): Operation<Model> & {
116
- state: Record<string, boolean>;
117
- };
118
- declare function validate<Schema extends StandardSchemaV1>(schema: Schema, value: unknown): Promise<SchemaOutput<Schema>>;
119
-
120
- declare const Codec: {
121
- encode(data: unknown): Uint8Array;
122
- decode(buf: Uint8Array): unknown;
123
- fromRequest(req: Request): Promise<unknown>;
124
- response(data: unknown): Response;
125
- };
126
-
127
- declare function toFetchHandler(): void;
128
-
129
- /**
130
- * Global utility namespace.
131
- * Holds internal helper functions that are not bound to any specific feature.
132
- */
133
- declare namespace Kit {
134
- /**
135
- * Returns a shallow clone of `input` with the specified keys removed.
136
- * Preserves the prototype chain.
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>[];
145
- }
146
-
147
- declare function make(app: ResolvedModule): void;
148
-
149
- interface ResolvedApp {
59
+ interface MongoEntityInput<Schema extends AnySchema> {
60
+ name: string;
61
+ adapter: MongoAdapter;
62
+ model: Schema;
150
63
  }
151
-
152
- declare namespace Storage {
153
- function kv(adapter: Adapter.kv): Adapter.kv;
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: {
89
+ name: string;
90
+ adapter: MongoAdapter;
91
+ model: Schema;
92
+ };
154
93
  }
94
+ declare function MongoEntity<Schema extends AnySchema>(input: MongoEntityInput<Schema>): MongoEntityOutput<Schema>;
155
95
 
156
- export { Adapter, type BuildConfig, Codec, type ComposeConfig, Entity, type EntityConfig, type EntityKV, Kit, LiteDml, type Operation, type PermissionSet, type Platform, type ResolvedApp, type ResolvedModule, type SchemaInput, type SchemaOutput, Storage, Type, build, compose, createOperation, lite, make, toFetchHandler, validate };
96
+ export { KvAdapter, KvEntity, type KvEntityInput, type KvEntityOutput, MongoAdapter, type MongoCollectionAdapter, MongoEntity, type MongoEntityInput, type MongoEntityOutput };
package/dist/index.js CHANGED
@@ -1,189 +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/compose/compose.def.ts
7
- function compose(config) {
8
- return config;
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;
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
48
32
  }
49
33
  };
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)}`);
56
- }
57
- return result.value;
58
34
  }
59
35
 
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;
69
- return {
70
- async get(key) {
71
- const formattedKey = `${configuration.name}:${key}`;
72
- const raw = await adapter.get(formattedKey);
73
- const validated = await validate(configuration.model, raw);
74
- return validated;
75
- },
76
- async set(key, value) {
77
- const formattedKey = `${configuration.name}:${key}`;
78
- const validated = await validate(configuration.model, value);
79
- await adapter.set(formattedKey, validated);
80
- },
81
- async delete(key) {
82
- const formattedKey = `${configuration.name}:${key}`;
83
- await adapter.delete(formattedKey);
84
- },
85
- async has(key) {
86
- const formattedKey = `${configuration.name}:${key}`;
87
- return await adapter.has(formattedKey);
88
- },
89
- [Entity2.$meta]: {
90
- adapter,
91
- model: configuration.model,
92
- readAccess: readOperation.state,
93
- writeAccess: writeOperation.state
94
- }
95
- };
96
- }
97
- Entity2.kv = kv;
98
- })(Entity || (Entity = {}));
99
-
100
- // src/fetch/codec.ts
101
- import { decode, encode } from "@msgpack/msgpack";
102
- var Codec = {
103
- encode(data) {
104
- return encode(data);
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
- });
125
- }
126
- };
127
-
128
- // src/fetch/fetch.ts
129
- function toFetchHandler() {
36
+ // src/mongo/adapter.ts
37
+ function MongoAdapter(adapter) {
38
+ return adapter;
130
39
  }
131
40
 
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];
141
- }
142
- return clone;
143
- }
144
- Kit2.omit = omit;
145
- function crushKeys(input) {
146
- const keys = [];
147
- const walk = (value, prefix) => {
148
- if (prefix) {
149
- keys.push(prefix);
150
- }
151
- if (value !== null && typeof value === "object" && value.constructor === Object) {
152
- for (const [entryKey, entryValue] of Object.entries(value)) {
153
- const path = prefix ? `${prefix}.${entryKey}` : entryKey;
154
- walk(entryValue, path);
155
- }
156
- }
157
- };
158
- walk(input, "");
159
- return keys;
160
- }
161
- Kit2.crushKeys = crushKeys;
162
- })(Kit || (Kit = {}));
163
-
164
- // src/make/make.def.ts
165
- function make(app) {
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
+ };
166
68
  }
167
-
168
- // src/storage/storage.ts
169
- var Storage;
170
- ((Storage2) => {
171
- function kv(adapter) {
172
- return adapter;
173
- }
174
- Storage2.kv = kv;
175
- })(Storage || (Storage = {}));
176
69
  export {
177
- Codec,
178
- Entity,
179
- Kit,
180
- LiteDml,
181
- Storage,
182
- build,
183
- compose,
184
- createOperation,
185
- lite,
186
- make,
187
- toFetchHandler,
188
- validate
70
+ KvAdapter,
71
+ KvEntity,
72
+ MongoAdapter,
73
+ MongoEntity
189
74
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aromix/core",
3
- "version": "0.1.3",
4
- "description": "Core runtime-agnostic framework for Aromix",
3
+ "version": "0.3.0",
4
+ "description": "The Core Package For Aromix",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "homepage": "https://aromixjs.github.io/aromix",
@@ -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
  },
40
- "dependencies": {
41
- "@msgpack/msgpack": "^3.1.3",
42
- "@standard-schema/spec": "^1.1.0"
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "dev": "tsup --watch",
41
+ "typecheck": "tsc --noEmit"
42
+ },
43
+ "peerDependencies": {
44
+ "@aromix/validator": "^0.2.0"
43
45
  },
44
46
  "devDependencies": {
47
+ "@aromix/validator": "^0.2.0",
45
48
  "@types/node": "^22.10.2",
46
49
  "tsup": "^8.3.5",
47
50
  "typescript": "^5.7.2"
48
- },
49
- "scripts": {
50
- "build": "tsup",
51
- "dev": "tsup --watch",
52
- "typecheck": "tsc --noEmit"
53
51
  }
54
- }
52
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # @aromix/core
2
-
3
- Core runtime-agnostic framework for Aromix.