@aromix/core 0.1.1 → 0.1.3

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 ADDED
@@ -0,0 +1,3 @@
1
+ # @aromix/core
2
+
3
+ Core runtime-agnostic framework for Aromix.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
 
3
- type Platform = "node" | "bun" | "cloudflare:worker";
4
- interface AromixBuildConfig {
3
+ type Platform = 'node' | 'bun' | 'cloudflare:worker';
4
+ interface BuildConfig {
5
5
  entry: string;
6
6
  outDir: string;
7
7
  platform: Platform;
@@ -10,35 +10,112 @@ interface AromixBuildConfig {
10
10
  tsConfig: string;
11
11
  }
12
12
  /** Identity fn :: exists purely for autocomplete and type safety */
13
- declare function build(options: AromixBuildConfig): AromixBuildConfig;
13
+ declare function build(options: BuildConfig): BuildConfig;
14
14
 
15
- interface Config {
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 { };
16
53
  }
17
- declare function config<T extends Config>(config: T | (() => T)): T;
18
54
 
19
- interface BaseCtx {
20
- id: string;
21
- payload: unknown;
22
- args<T>(schema: StandardSchemaV1<T>): T;
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> {
58
+ name: string;
59
+ storage: Adapter.kv;
60
+ guards?: any[];
61
+ effects?: any[];
62
+ model: Schema;
63
+ access: (can: PermissionSet<SchemaOutput<Schema>>) => void;
23
64
  }
24
- interface CommandCtx extends BaseCtx {
65
+ interface Operation<Model> {
66
+ (fields: Type.CrushKeys<Model>[]): void;
67
+ omit(fields: Type.CrushKeys<Model>[]): void;
25
68
  }
26
- interface StreamCtx extends BaseCtx {
69
+ interface PermissionSet<Model> {
70
+ read: Operation<Model>;
71
+ write: Operation<Model>;
27
72
  }
28
- interface SocketCtx<Receive extends EventMap, Send extends EventMap> extends BaseCtx {
29
- on<E extends keyof Receive>(event: E, handler: (data: Receive[E]) => void | Promise<void>): void;
30
- send<E extends keyof Send>(event: E, data: Send[E]): void;
31
- onClose(handler: () => void): void;
32
- close(): void;
73
+ interface EntityKV<Schema extends StandardSchemaV1> {
74
+ get(key: string): Promise<SchemaOutput<Schema>>;
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
+ };
33
83
  }
34
- type EventMap = Record<string, unknown>;
35
84
 
36
- declare class Builder {
85
+ interface ComposeConfig {
86
+ entities: EntityKV<StandardSchemaV1>[];
87
+ }
88
+ interface ResolvedModule {
89
+ entities: EntityKV<StandardSchemaV1>[];
37
90
  }
38
91
 
39
- interface Entity {
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;
40
107
  }
41
- declare function entity(options: Entity): void;
108
+
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>>;
42
119
 
43
120
  declare const Codec: {
44
121
  encode(data: unknown): Uint8Array;
@@ -49,15 +126,31 @@ declare const Codec: {
49
126
 
50
127
  declare function toFetchHandler(): void;
51
128
 
52
- declare function make(): void;
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
+ }
53
146
 
54
- declare function plugin(): void;
147
+ declare function make(app: ResolvedModule): void;
55
148
 
56
- declare global {
57
- namespace Aromix {
58
- type GlobPattern = string | string[];
59
- function load(pattern: GlobPattern): string[];
60
- }
149
+ interface ResolvedApp {
150
+ }
151
+
152
+ declare namespace Storage {
153
+ function kv(adapter: Adapter.kv): Adapter.kv;
61
154
  }
62
155
 
63
- export { type AromixBuildConfig, type BaseCtx, Builder, Codec, type CommandCtx, type Config, type EventMap, type Platform, type SocketCtx, type StreamCtx, build, config, entity, make, plugin, toFetchHandler };
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 };
package/dist/index.js CHANGED
@@ -3,21 +3,102 @@ function build(options) {
3
3
  return options;
4
4
  }
5
5
 
6
- // src/config.ts
7
- function config(config2) {
8
- return typeof config2 === "function" ? config2() : config2;
6
+ // src/compose/compose.def.ts
7
+ function compose(config) {
8
+ return config;
9
9
  }
10
10
 
11
- // src/entity/builder.ts
12
- var Builder = class {
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
+ }
13
31
  };
14
32
 
15
- // src/entity/entity.ts
16
- function entity(options) {
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)}`);
56
+ }
57
+ return result.value;
17
58
  }
18
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;
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
+
19
100
  // src/fetch/codec.ts
20
- import { encode, decode } from "@msgpack/msgpack";
101
+ import { decode, encode } from "@msgpack/msgpack";
21
102
  var Codec = {
22
103
  encode(data) {
23
104
  return encode(data);
@@ -31,7 +112,9 @@ var Codec = {
31
112
  throw new Error(`Invalid content-type "${contentType}" \u2014 only application/x-msgpack is accepted`);
32
113
  }
33
114
  const buf = await req.arrayBuffer();
34
- if (buf.byteLength === 0) return void 0;
115
+ if (buf.byteLength === 0) {
116
+ return void 0;
117
+ }
35
118
  return decode(new Uint8Array(buf));
36
119
  },
37
120
  response(data) {
@@ -46,20 +129,61 @@ var Codec = {
46
129
  function toFetchHandler() {
47
130
  }
48
131
 
49
- // src/make/impl.ts
50
- function make() {
51
- }
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 = {}));
52
163
 
53
- // src/plugin.ts
54
- function plugin() {
164
+ // src/make/make.def.ts
165
+ function make(app) {
55
166
  }
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 = {}));
56
176
  export {
57
- Builder,
58
177
  Codec,
178
+ Entity,
179
+ Kit,
180
+ LiteDml,
181
+ Storage,
59
182
  build,
60
- config,
61
- entity,
183
+ compose,
184
+ createOperation,
185
+ lite,
62
186
  make,
63
- plugin,
64
- toFetchHandler
187
+ toFetchHandler,
188
+ validate
65
189
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aromix/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Core runtime-agnostic framework for Aromix",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,12 +27,10 @@
27
27
  "files": [
28
28
  "dist"
29
29
  ],
30
- "types": "./dist/index.d.ts",
31
30
  "exports": {
32
31
  ".": {
33
32
  "types": "./dist/index.d.ts",
34
- "import": "./dist/index.js",
35
- "require": "./dist/index.cjs"
33
+ "import": "./dist/index.js"
36
34
  }
37
35
  },
38
36
  "publishConfig": {
package/dist/index.cjs DELETED
@@ -1,65 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/build.ts
2
- function build(options) {
3
- return options;
4
- }
5
-
6
- // src/config.ts
7
- function config(config2) {
8
- return typeof config2 === "function" ? config2() : config2;
9
- }
10
-
11
- // src/entity/builder.ts
12
- var Builder = class {
13
- };
14
-
15
- // src/entity/entity.ts
16
- function entity(options) {
17
- }
18
-
19
- // src/fetch/codec.ts
20
- var _msgpack = require('@msgpack/msgpack');
21
- var Codec = {
22
- encode(data) {
23
- return _msgpack.encode.call(void 0, data);
24
- },
25
- decode(buf) {
26
- return _msgpack.decode.call(void 0, buf);
27
- },
28
- async fromRequest(req) {
29
- const contentType = req.headers.get("content-type");
30
- if (contentType !== "application/x-msgpack") {
31
- throw new Error(`Invalid content-type "${contentType}" \u2014 only application/x-msgpack is accepted`);
32
- }
33
- const buf = await req.arrayBuffer();
34
- if (buf.byteLength === 0) return void 0;
35
- return _msgpack.decode.call(void 0, new Uint8Array(buf));
36
- },
37
- response(data) {
38
- return new Response(_msgpack.encode.call(void 0, data), {
39
- status: 200,
40
- headers: { "Content-Type": "application/x-msgpack" }
41
- });
42
- }
43
- };
44
-
45
- // src/fetch/fetch.ts
46
- function toFetchHandler() {
47
- }
48
-
49
- // src/make/impl.ts
50
- function make() {
51
- }
52
-
53
- // src/plugin.ts
54
- function plugin() {
55
- }
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
- exports.Builder = Builder; exports.Codec = Codec; exports.build = build; exports.config = config; exports.entity = entity; exports.make = make; exports.plugin = plugin; exports.toFetchHandler = toFetchHandler;
package/dist/index.d.cts DELETED
@@ -1,63 +0,0 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
-
3
- type Platform = "node" | "bun" | "cloudflare:worker";
4
- interface AromixBuildConfig {
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: AromixBuildConfig): AromixBuildConfig;
14
-
15
- interface Config {
16
- }
17
- declare function config<T extends Config>(config: T | (() => T)): T;
18
-
19
- interface BaseCtx {
20
- id: string;
21
- payload: unknown;
22
- args<T>(schema: StandardSchemaV1<T>): T;
23
- }
24
- interface CommandCtx extends BaseCtx {
25
- }
26
- interface StreamCtx extends BaseCtx {
27
- }
28
- interface SocketCtx<Receive extends EventMap, Send extends EventMap> extends BaseCtx {
29
- on<E extends keyof Receive>(event: E, handler: (data: Receive[E]) => void | Promise<void>): void;
30
- send<E extends keyof Send>(event: E, data: Send[E]): void;
31
- onClose(handler: () => void): void;
32
- close(): void;
33
- }
34
- type EventMap = Record<string, unknown>;
35
-
36
- declare class Builder {
37
- }
38
-
39
- interface Entity {
40
- }
41
- declare function entity(options: Entity): void;
42
-
43
- declare const Codec: {
44
- encode(data: unknown): Uint8Array;
45
- decode(buf: Uint8Array): unknown;
46
- fromRequest(req: Request): Promise<unknown>;
47
- response(data: unknown): Response;
48
- };
49
-
50
- declare function toFetchHandler(): void;
51
-
52
- declare function make(): void;
53
-
54
- declare function plugin(): void;
55
-
56
- declare global {
57
- namespace Aromix {
58
- type GlobPattern = string | string[];
59
- function load(pattern: GlobPattern): string[];
60
- }
61
- }
62
-
63
- export { type AromixBuildConfig, type BaseCtx, Builder, Codec, type CommandCtx, type Config, type EventMap, type Platform, type SocketCtx, type StreamCtx, build, config, entity, make, plugin, toFetchHandler };