@marianmeres/collection-types 1.33.0 → 1.34.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/AGENTS.md CHANGED
@@ -1,59 +1,313 @@
1
- # @marianmeres/collection-types — Agent Guide
1
+ # AGENTS.md - @marianmeres/collection-types
2
+
3
+ Machine-readable documentation for AI agents and automated tools.
4
+
5
+ ## Package Identity
6
+
7
+ ```yaml
8
+ name: "@marianmeres/collection-types"
9
+ version: "1.x"
10
+ type: "workspace-package"
11
+ runtime: "deno"
12
+ entry: "./src/mod.ts"
13
+ ```
14
+
15
+ ## Purpose
16
+
17
+ Type definitions and schema utilities for the collection management system:
18
+ - Core types: Model, Collection, Relation
19
+ - Branded types: UUID, ISODateString, LtreePath
20
+ - Domain types: Account, Product, Order, Customer, Session, etc.
21
+ - Schema builder: `createObjectSchema<T>()` for type-safe schema definitions
22
+ - Admin UI types: Navigation, FormRoutes, AreaPages, JoyConfig
2
23
 
3
24
  ## Quick Reference
4
25
 
5
- | | |
6
- |-|-|
7
- | **Stack** | TypeScript (type definitions only) |
8
- | **Runtime** | Deno (dev), publishes to JSR + npm |
9
- | **Type check** | `deno check src/mod.ts` |
10
- | **Release** | `deno task rp` (patch) / `deno task rpm` (minor) |
26
+ | Task | File | Key Export |
27
+ |------|------|------------|
28
+ | Branded types | `src/utils.ts` | `UUID`, `ISODateString`, `LtreePath` |
29
+ | Model types | `src/model.ts` | `Model<T>`, `ModelDTOIn`, `ModelDTOOut` |
30
+ | Collection types | `src/collection.ts` | `Collection`, `CollectionDTOIn` |
31
+ | Relation types | `src/relation.ts` | `Relation`, `RelationType` |
32
+ | Schema types | `src/schema.ts` | `PropertyDefinition`, `JsonSchema` |
33
+ | Schema builder | `src/schema-builder.ts` | `createObjectSchema<T>()` |
34
+ | API types | `src/api.ts` | `ApiResponse`, `PaginatedResponse` |
35
+ | Asset types | `src/asset.ts` | `AssetData`, `AssetVariant` |
36
+ | Navigation types | `src/navigation.ts` | `NavItem`, `UnifiedNavigation` |
11
37
 
12
- ## Project Structure
38
+ ## File Map
13
39
 
14
40
  ```
15
41
  src/
16
42
  ├── mod.ts # Entry point (barrel export)
17
43
  ├── utils.ts # Branded types (UUID, ISODateString, LtreePath)
18
- ├── model.ts # Model entity types
44
+ ├── model.ts # Model entity types (ModelDTOIn/Out/DbRow)
19
45
  ├── collection.ts # Collection container types
20
- ├── relation.ts # Relation and RelationType entity types
21
- ├── schema.ts # JSON Schema extensions for UI/form generation
22
- ├── schema-builder.ts # Type-safe schema builder (createObjectSchema)
23
- ├── api.ts # API response wrappers, pagination, query syntax
46
+ ├── relation.ts # Relation and RelationType types
47
+ ├── schema.ts # JSON Schema extensions for UI/form
48
+ ├── schema-builder.ts # Type-safe schema builder
49
+ ├── api.ts # API response wrappers, pagination
24
50
  ├── asset.ts # File attachment types
25
51
  ├── adapter.ts # Database adapter interface types
26
- ├── linked.ts # Metadata-based asset linking configuration
52
+ ├── linked.ts # Metadata-based asset linking config
27
53
  ├── navigation.ts # Admin UI navigation menu types
28
- ├── form-routes.ts # Form route override configuration types
29
- └── [domain].ts # Domain-specific data types (account, customer, order, etc.)
54
+ ├── form-routes.ts # Form route override configuration
55
+ ├── area-pages.ts # Custom/Customer area page definitions
56
+ ├── joy-config.ts # Admin UI configuration types
57
+ ├── joy-response.ts # Unified config endpoint response
58
+ ├── external-domain.ts # Cross-domain reference support
59
+ └── [domain].ts # Domain-specific data types:
60
+ ├── account.ts # AccountData, AccountSession
61
+ ├── customer.ts # CustomerData
62
+ ├── order.ts # OrderData, OrderItemData
63
+ ├── payment.ts # PaymentData
64
+ ├── product.ts # ProductData, CategoryData
65
+ ├── session.ts # SessionData, CartItem
66
+ ├── template.ts # TemplateData
67
+ ├── email.ts # EmailData, EmailPayload
68
+ ├── project.ts # ProjectData
69
+ ├── country.ts # CountryData
70
+ └── example.ts # ExampleData (reference)
71
+ ```
72
+
73
+ ## Primary Exports
74
+
75
+ ```typescript
76
+ // Branded types
77
+ export type { UUID, ISODateString, LtreePath, MaybeLocalized } from "./utils.ts";
78
+ export type { JsonPrimitive, JsonObject, JsonArray, JsonValue, UserData } from "./utils.ts";
79
+
80
+ // Core entities
81
+ export type { Model, ModelDTOIn, ModelDTOOut, ModelDbRow, ModelUpsertData } from "./model.ts";
82
+ export type { Collection, CollectionDTOIn, CollectionDTOOut, CollectionDbRow } from "./collection.ts";
83
+ export type { Relation, RelationType, RelationDTOIn, RelationTypeDTOIn } from "./relation.ts";
84
+
85
+ // Schema
86
+ export type { PropertyDefinition, JsonSchema, HtmlSpec } from "./schema.ts";
87
+ export type { ObjectSchema, ExtendedSchema } from "./schema-builder.ts";
88
+ export { createObjectSchema } from "./schema-builder.ts"; // Runtime function
89
+
90
+ // API
91
+ export type { ApiResponse, PaginatedResponse, ApiMeta } from "./api.ts";
92
+
93
+ // Assets
94
+ export type { AssetData, AssetVariant } from "./asset.ts";
95
+
96
+ // Domain types
97
+ export type { AccountData, AccountSession } from "./account.ts";
98
+ export type { ProductData, CategoryData } from "./product.ts";
99
+ export type { CustomerData } from "./customer.ts";
100
+ export type { OrderData, OrderItemData } from "./order.ts";
101
+ export type { PaymentData } from "./payment.ts";
102
+ export type { SessionData, CartItem } from "./session.ts";
103
+ export type { TemplateData } from "./template.ts";
104
+ export type { EmailData } from "./email.ts";
105
+
106
+ // Admin UI
107
+ export type { NavItem, UnifiedNavigation } from "./navigation.ts";
108
+ export type { FormRouteConfig } from "./form-routes.ts";
109
+ export type { AreaPageConfig } from "./area-pages.ts";
110
+ export type { JoyConfig } from "./joy-config.ts";
111
+ ```
112
+
113
+ ## Key Types
114
+
115
+ ### Branded Types
116
+
117
+ ```typescript
118
+ type UUID = string; // UUID string
119
+ type ISODateString = string; // ISO 8601 date string
120
+ type LtreePath = string; // PostgreSQL ltree path
121
+ type MaybeLocalized<T> = T | Record<string, T>; // i18n support
122
+ ```
123
+
124
+ ### Model Layer Types
125
+
126
+ ```typescript
127
+ // Input (user-provided)
128
+ interface ModelDTOIn {
129
+ type?: string;
130
+ parent_id?: UUID | null;
131
+ path?: LtreePath | null;
132
+ folder?: string | null;
133
+ tags?: string[];
134
+ data?: UserData;
135
+ meta?: UserData;
136
+ is_unlisted?: boolean;
137
+ is_deletable?: boolean;
138
+ is_readonly?: boolean;
139
+ is_starred?: boolean;
140
+ is_enabled?: boolean;
141
+ red?, orange?, yellow?, green?, blue?, purple?, gray?: boolean;
142
+ }
143
+
144
+ // Output (+ server fields)
145
+ interface ModelDTOOut extends ModelDTOIn {
146
+ model_id: UUID;
147
+ collection_id: UUID;
148
+ type: string;
149
+ depth: number;
150
+ _label?: MaybeLocalized<string> | null;
151
+ _hierarchy_label?: string | null;
152
+ _created_at: ISODateString;
153
+ _updated_at: ISODateString;
154
+ }
155
+
156
+ // Database (+ internal fields)
157
+ interface ModelDbRow extends ModelDTOOut {
158
+ __is_rest_disabled: boolean;
159
+ __searchable: Record<string, unknown>;
160
+ __searchable2: string;
161
+ __hierarchy_path: LtreePath | null;
162
+ }
163
+
164
+ // Generic typed model
165
+ type Model<TData extends UserData = UserData> = ModelDbRow & { data: TData };
30
166
  ```
31
167
 
32
- ## Critical Conventions
168
+ ### Schema Builder
169
+
170
+ ```typescript
171
+ interface ObjectSchema<T> {
172
+ type: "object";
173
+ required?: (keyof T)[];
174
+ properties: { [K in keyof T]?: PropertyDefinition };
175
+ additionalProperties?: boolean;
176
+ _title?: MaybeLocalized<string>;
177
+ _description?: MaybeLocalized<string>;
178
+ _extra_form_fields?: Record<string, PropertyDefinition>;
179
+ }
180
+
181
+ // Type-safe schema creation
182
+ function createObjectSchema<T>(schema: ObjectSchema<T>): ObjectSchema<T>;
183
+
184
+ // Inheritance pattern
185
+ type ExtendedSchema = {
186
+ __extends: string;
187
+ properties?: Record<string, PropertyDefinition>;
188
+ };
189
+ ```
190
+
191
+ ## Type Hierarchy
192
+
193
+ ```
194
+ DTOIn (user input)
195
+
196
+ ├─► DTOOut (+ server fields: id, timestamps)
197
+ │ │
198
+ │ └─► DbRow (+ internal fields: __searchable, __is_rest_disabled)
199
+ │ │
200
+ │ └─► Model<T> (typed data access)
201
+
202
+ Field Prefixes:
203
+ - (none) = user-provided, mutable
204
+ - _ = server-managed, read-only
205
+ - __ = internal, not exposed via API
206
+ ```
207
+
208
+ ## Common Operations
209
+
210
+ ### Type-Safe Schema Definition
211
+
212
+ ```typescript
213
+ import { createObjectSchema, type Model } from "@marianmeres/collection-types";
214
+
215
+ interface ProductData {
216
+ name: string;
217
+ price: number;
218
+ sku: string;
219
+ }
220
+
221
+ // TypeScript validates property keys match interface
222
+ const productSchema = createObjectSchema<ProductData>({
223
+ type: "object",
224
+ required: ["name", "price"],
225
+ properties: {
226
+ name: { type: "string", _label_source: true },
227
+ price: { type: "number" },
228
+ sku: { type: "string", _unique: true }
229
+ }
230
+ });
231
+
232
+ // Typed model usage
233
+ type Product = Model<ProductData>;
234
+ const product: Product = await service.findOne(id);
235
+ console.log(product.data.price); // TypeScript knows this is number
236
+ ```
237
+
238
+ ### Schema Inheritance
239
+
240
+ ```typescript
241
+ import type { ExtendedSchema } from "@marianmeres/collection-types";
242
+
243
+ // Base schema
244
+ const baseSchema = createObjectSchema<{ name: string }>({
245
+ type: "object",
246
+ properties: { name: { type: "string" } }
247
+ });
248
+
249
+ // Extended schema
250
+ const featuredSchema: ExtendedSchema = {
251
+ __extends: "default",
252
+ properties: {
253
+ featured_until: { type: "string", format: "date" }
254
+ }
255
+ };
256
+ ```
257
+
258
+ ### API Response Types
259
+
260
+ ```typescript
261
+ import type { ApiResponse, PaginatedResponse, Model } from "@marianmeres/collection-types";
262
+
263
+ // Single item response
264
+ type ProductResponse = ApiResponse<Model<ProductData>>;
265
+
266
+ // Paginated list response
267
+ type ProductListResponse = PaginatedResponse<Model<ProductData>>;
268
+ // { data: Product[], meta: { total, limit, offset, ... } }
269
+ ```
270
+
271
+ ## Testing
272
+
273
+ ```bash
274
+ deno check src/mod.ts # Type check
275
+ deno task rp # Release patch
276
+ deno task rpm # Release minor
277
+ ```
278
+
279
+ ## Dependencies
280
+
281
+ This is a types-only package with minimal dependencies:
282
+ - None (pure TypeScript types)
33
283
 
34
- 1. **DTO Layering**: `DTOIn` (input) → `DTOOut` (+ server fields) → `DbRow` (+ internal fields)
35
- 2. **Field Prefixes**: `__` internal (not exposed), `_` server-managed (read-only), none user-provided
36
- 3. **Branded Types**: Use `UUID`, `ISODateString`, `LtreePath` for compile-time safety
37
- 4. **Flat Structure**: All types in src/, no subdirectories
38
- 5. **JSDoc Comments**: All exports documented inline
39
- 6. **Generic Models**: Use `Model<TData>` for typed data access
284
+ ## Conventions
40
285
 
41
- ## Before Making Changes
286
+ 1. **DTO Layering**: `DTOIn` → `DTOOut` → `DbRow` → `Model<T>`
287
+ 2. **Field Prefixes**:
288
+ - `__` = internal (not exposed via API)
289
+ - `_` = server-managed (read-only to clients)
290
+ - (none) = user-provided
291
+ 3. **Branded Types**: Use `UUID`, `ISODateString`, `LtreePath` for type safety
292
+ 4. **Generic Models**: Use `Model<TData>` for typed data access
293
+ 5. **Flat Structure**: All types in `src/`, no subdirectories
294
+ 6. **JSDoc Comments**: All exports documented inline
42
295
 
43
- - [ ] Read existing types in target file first
44
- - [ ] Follow DTO layering pattern if adding entity types
45
- - [ ] Add JSDoc comments to new exports
46
- - [ ] Run `deno check src/mod.ts`
47
- - [ ] Export from mod.ts if adding new public types
48
- - [ ] Formatting: tabs, 4-space indent width, 90 char line width
296
+ ## Gotchas/Notes
49
297
 
50
- ## Related Packages
298
+ 1. **Index signature requirement**: When using `Model<T>`, your interface needs `[key: string]: unknown` for compatibility with `UserData`. The `createObjectSchema` helper uses `KnownKeys<T>` to still validate property names.
51
299
 
52
- - `@marianmeres/condition-builder` QueryOperator type is mirrored from here
300
+ 2. **Import style**: Use `import type` for type-only imports to ensure tree-shaking:
301
+ ```typescript
302
+ import type { Model, UUID } from "@marianmeres/collection-types";
303
+ import { createObjectSchema } from "@marianmeres/collection-types"; // Runtime
304
+ ```
53
305
 
54
- ## Documentation Index
306
+ 3. **MaybeLocalized**: Fields that support i18n can be either a direct value or a `Record<lang, value>`:
307
+ ```typescript
308
+ // Both valid:
309
+ _label: "Product Name"
310
+ _label: { en: "Product Name", de: "Produktname" }
311
+ ```
55
312
 
56
- | Document | Purpose |
57
- |----------|---------|
58
- | [docs/type-catalog.md](./docs/type-catalog.md) | Complete type reference (100+ types) |
59
- | [README.md](./README.md) | Installation, user guide, best practices |
313
+ 4. **ExtendedSchema**: For inheritance patterns (`__extends`), use the loose `ExtendedSchema` type instead of `ObjectSchema<T>` since the final shape is computed at runtime.
package/CLAUDE.md ADDED
@@ -0,0 +1,3 @@
1
+ # Project Instructions
2
+
3
+ See [AGENTS.md](./AGENTS.md) for complete project documentation and AI agent instructions.
package/dist/order.d.ts CHANGED
@@ -103,3 +103,10 @@ export interface OrderEventData {
103
103
  export type OrderType = "order";
104
104
  /** Order event type identifier */
105
105
  export type OrderEventModelType = "event";
106
+ /** Result of order creation, includes server-assigned metadata */
107
+ export interface OrderCreateResult {
108
+ /** Server-assigned model ID */
109
+ model_id: UUID;
110
+ /** The order data payload */
111
+ data: OrderData;
112
+ }
package/dist/payment.d.ts CHANGED
@@ -30,6 +30,19 @@ export interface PaymentData {
30
30
  }
31
31
  /** Payment type identifier */
32
32
  export type PaymentType = "payment";
33
+ /** Configuration for initiating a payment */
34
+ export interface PaymentInitConfig {
35
+ /** Payment provider identifier (e.g. "stripe", "paypal") */
36
+ provider: string;
37
+ /** Amount in smallest currency unit (e.g. cents) */
38
+ amount: number;
39
+ /** ISO 4217 currency code */
40
+ currency: string;
41
+ /** URL to redirect after payment completion */
42
+ return_url?: string;
43
+ /** Provider-specific additional configuration */
44
+ [key: string]: unknown;
45
+ }
33
46
  /** Result of initiating a payment */
34
47
  export interface PaymentIntent {
35
48
  /** Internal payment ID */
package/dist/session.d.ts CHANGED
@@ -20,9 +20,16 @@ export interface CartItem {
20
20
  export interface CartData {
21
21
  items: CartItem[];
22
22
  }
23
- /** Wishlist contents - simple array of product IDs */
23
+ /** Single wishlist item */
24
+ export interface WishlistItem {
25
+ /** Product reference */
26
+ product_id: UUID;
27
+ /** Timestamp when item was added */
28
+ added_at?: number;
29
+ }
30
+ /** Wishlist contents */
24
31
  export interface WishlistData {
25
- items: UUID[];
32
+ items: WishlistItem[];
26
33
  }
27
34
  /** Session data field schema */
28
35
  export interface SessionData {
@@ -134,3 +134,44 @@ Relation: RelationDTOIn → RelationDTOOut → RelationDbRow (= Relation)
134
134
  | `FormRouteRule` | Single override rule (id, description, match, endpoint, enabled, priority) |
135
135
  | `FormRoutesConfig` | Complete config with version and rules array |
136
136
  | `FormRouteContext` | Runtime lookup context for route resolution |
137
+
138
+ ## session.ts — Session & Cart Types
139
+
140
+ | Type | Description |
141
+ |------|-------------|
142
+ | `CartItem` | Single cart item (product_id, quantity) |
143
+ | `CartData` | Cart contents (items: CartItem[]) |
144
+ | `WishlistItem` | Single wishlist item (product_id, added_at?) |
145
+ | `WishlistData` | Wishlist contents (items: WishlistItem[]) |
146
+ | `SessionData` | Session data (cart, wishlist) |
147
+ | `SessionType` | Type identifier: "session" |
148
+
149
+ ## payment.ts — Payment Types
150
+
151
+ | Type | Description |
152
+ |------|-------------|
153
+ | `PaymentStatus` | Status: pending, completed, failed, refunded |
154
+ | `PaymentData` | Payment data (provider, status, amount, currency, provider_reference) |
155
+ | `PaymentType` | Type identifier: "payment" |
156
+ | `PaymentInitConfig` | Payment initiation config (provider, amount, currency, return_url?) |
157
+ | `PaymentIntent` | Payment initiation result (id, redirect_url, provider_data?) |
158
+ | `PaymentResult` | Payment capture result (provider_reference) |
159
+ | `RefundResult` | Refund result (refund_id) |
160
+ | `WebhookResult` | Webhook processing result (event_type, payment_id?) |
161
+
162
+ ## order.ts — Order Types
163
+
164
+ | Type | Description |
165
+ |------|-------------|
166
+ | `OrderStatus` | Status: pending, paid, processing, shipped, delivered, cancelled |
167
+ | `CheckoutStage` | Checkout stages: cart, addresses, delivery, confirm, payment, complete |
168
+ | `OrderLineItem` | Line item snapshot (product_id, sku?, name, price, quantity) |
169
+ | `OrderTotals` | Price totals (subtotal, tax, shipping, discount, total) |
170
+ | `DeliveryOptionSnapshot` | Delivery option snapshot (id, name, price, estimated_time?) |
171
+ | `OrderData` | Order data (status, items, currency, totals, addresses, delivery, checkout) |
172
+ | `OrderEventType` | Event types: created, status_changed, payment_added, note_added, cancelled |
173
+ | `OrderEventActor` | Event actor (type: customer/admin/system, id?) |
174
+ | `OrderEventData` | Order event audit trail (event_type, statuses, actor, details?) |
175
+ | `OrderType` | Type identifier: "order" |
176
+ | `OrderEventModelType` | Event type identifier: "event" |
177
+ | `OrderCreateResult` | Order creation result (model_id, data: OrderData) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/collection-types",
3
- "version": "1.33.0",
3
+ "version": "1.34.0",
4
4
  "type": "module",
5
5
  "main": "dist/mod.js",
6
6
  "types": "dist/mod.d.ts",