@marianmeres/collection-types 1.0.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/AGENTS.md ADDED
@@ -0,0 +1,46 @@
1
+ # CLAUDE.md
2
+
3
+ ## Project Overview
4
+
5
+ Type-only package for the @marianmeres ecosystem. No runtime code - pure TypeScript type definitions.
6
+
7
+ ## Structure
8
+
9
+ ```
10
+ src/
11
+ ├── mod.ts # Main entry point, re-exports all modules
12
+ ├── utils.ts # Branded types (UUID, ISODateString, LtreePath) and helpers
13
+ ├── model.ts # Model entity types (DTOIn → DTOOut → DbRow pattern)
14
+ ├── collection.ts # Collection entity types
15
+ ├── relation.ts # Relation and RelationType entity types
16
+ ├── schema.ts # JSON Schema extensions for UI/form generation
17
+ ├── api.ts # API response wrappers, pagination, query syntax
18
+ ├── asset.ts # File attachment types
19
+ └── adapter.ts # Database adapter interface types
20
+ ```
21
+
22
+ ## Key Patterns
23
+
24
+ - **DTO Layering**: `DTOIn` (input) → `DTOOut` (+ server fields) → `DbRow` (+ internal fields)
25
+ - **Branded Types**: `UUID`, `ISODateString`, `LtreePath` for compile-time safety
26
+ - **Internal Fields**: Prefixed with `__` (e.g., `__is_rest_disabled`, `__searchable`)
27
+ - **Server Fields**: Prefixed with `_` (e.g., `_created_at`, `_updated_at`)
28
+
29
+ ## Build & Publish
30
+
31
+ ```bash
32
+ deno task rp # Release patch + publish to JSR and npm
33
+ deno task rpm # Release minor + publish
34
+ deno check src/mod.ts # Type check
35
+ ```
36
+
37
+ ## Related Packages
38
+
39
+ - `@marianmeres/condition-builder` - QueryOperator type is mirrored from here
40
+ - Uses Deno for development, publishes to both JSR and npm
41
+
42
+ ## Notes
43
+
44
+ - All exports have JSDoc comments
45
+ - Flat file structure (no subdirectories in src/)
46
+ - Formatting: tabs, 4-space indent width, 90 char line width
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Marian Meres
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @marianmeres/collection-types
2
+
3
+ Shared type definitions for internal use within the @marianmeres ecosystem. Type-only package with no runtime code.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Adapter types for the collection system.
3
+ * Defines database query provider and adapter configuration.
4
+ */
5
+ /**
6
+ * Generic database query result.
7
+ * Modeled after pg.QueryResult but adapter-agnostic.
8
+ */
9
+ export interface DbQueryResult<T = Record<string, unknown>> {
10
+ /** Result rows */
11
+ rows: T[];
12
+ /** Number of rows affected (for INSERT/UPDATE/DELETE) */
13
+ rowCount?: number;
14
+ }
15
+ /**
16
+ * Database query provider interface.
17
+ * Abstracts the underlying database implementation.
18
+ */
19
+ export interface QueryProvider {
20
+ /** Query provider type */
21
+ type: "pg" | "sqlite";
22
+ /** Execute a query and return results */
23
+ query(sql: string, params?: unknown[]): Promise<DbQueryResult>;
24
+ /** Execute a query with cursor-style row iteration */
25
+ each(sql: string, params: unknown[], onRow: (row: Record<string, unknown>) => Promise<void>): Promise<void>;
26
+ }
27
+ /**
28
+ * Adapter configuration options.
29
+ */
30
+ export interface AdapterOptions {
31
+ /** Prefix for table names */
32
+ tablePrefix: string;
33
+ /** SQL to execute before initialization */
34
+ preInitSql: string;
35
+ /** SQL to execute after initialization */
36
+ postInitSql: string;
37
+ /** Custom SQL for userland initialization */
38
+ customPreInitSql: string;
39
+ /** Foreign key constraint to project table */
40
+ projectIdFk: null | {
41
+ table: string;
42
+ column: string;
43
+ };
44
+ /** Reset all data before initialization (tests only) */
45
+ resetAll: boolean;
46
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Adapter types for the collection system.
3
+ * Defines database query provider and adapter configuration.
4
+ */
5
+ export {};
package/dist/api.d.ts ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * API types for the collection system.
3
+ * Defines response structures and query syntax.
4
+ */
5
+ import type { Collection } from "./collection.js";
6
+ import type { Model } from "./model.js";
7
+ import type { RelationType } from "./relation.js";
8
+ /**
9
+ * Pagination metadata for list responses.
10
+ */
11
+ export interface PaginationMeta {
12
+ /** Number of items per page */
13
+ limit: number;
14
+ /** Number of items skipped */
15
+ offset: number;
16
+ /** Total number of items available */
17
+ total?: number;
18
+ /** Whether more items exist beyond this page */
19
+ hasMore?: boolean;
20
+ }
21
+ /**
22
+ * Standard API response wrapper.
23
+ */
24
+ export interface ApiResponse<T = unknown> {
25
+ /** Response payload */
26
+ data: T;
27
+ /** Response metadata */
28
+ meta?: Record<string, unknown>;
29
+ }
30
+ /**
31
+ * API response for list endpoints with pagination.
32
+ */
33
+ export interface ApiListResponse<T = unknown> extends ApiResponse<T[]> {
34
+ /** Pagination and additional metadata */
35
+ meta: PaginationMeta & Record<string, unknown>;
36
+ /** Related data included in response */
37
+ included?: {
38
+ collection?: Record<string, Collection>;
39
+ relation_type?: Record<string, RelationType>;
40
+ model?: Record<string, Model>;
41
+ };
42
+ }
43
+ /**
44
+ * Query operators for filtering.
45
+ * Mirrored from @marianmeres/condition-builder OPERATOR.
46
+ */
47
+ export type QueryOperator = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like" | "nlike" | "match" | "nmatch" | "is" | "nis" | "in" | "nin" | "ltree" | "ancestor" | "descendant";
48
+ /**
49
+ * Single query condition.
50
+ */
51
+ export interface QueryCondition {
52
+ /** Field name to filter on */
53
+ field: string;
54
+ /** Comparison operator */
55
+ operator: QueryOperator;
56
+ /** Value to compare against */
57
+ value: unknown;
58
+ }
59
+ /**
60
+ * Query syntax for list endpoints.
61
+ * Defines filtering, sorting, and pagination.
62
+ */
63
+ export interface QuerySyntax {
64
+ /** Filter conditions */
65
+ where?: QueryCondition | QueryCondition[];
66
+ /** Full-text search query */
67
+ search?: string;
68
+ /** Field to sort by */
69
+ order?: string;
70
+ /** Sort ascending (true) or descending (false) */
71
+ asc?: boolean;
72
+ /** Number of items to return */
73
+ limit?: number;
74
+ /** Number of items to skip */
75
+ offset?: number;
76
+ }
package/dist/api.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * API types for the collection system.
3
+ * Defines response structures and query syntax.
4
+ */
5
+ export {};
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Asset types for the collection system.
3
+ * Assets are file attachments associated with models.
4
+ */
5
+ import type { UUID, ISODateString } from "./utils.js";
6
+ /**
7
+ * Variant of an asset (e.g., thumbnail, preview).
8
+ */
9
+ export interface AssetVariant {
10
+ /** Variant name (e.g., "thumbnail", "large") */
11
+ name: string;
12
+ /** Width in pixels */
13
+ width?: number;
14
+ /** Height in pixels */
15
+ height?: number;
16
+ /** File format (e.g., "webp", "jpg") */
17
+ format?: string;
18
+ /** URL to access this variant */
19
+ url: string;
20
+ }
21
+ /**
22
+ * Asset data including file metadata and variants.
23
+ */
24
+ export interface AssetData {
25
+ /** Original filename */
26
+ filename: string;
27
+ /** MIME type */
28
+ mimetype: string;
29
+ /** File size in bytes */
30
+ size: number;
31
+ /** URL to access the original file */
32
+ url: string;
33
+ /** Generated variants (thumbnails, previews, etc.) */
34
+ variants?: AssetVariant[];
35
+ /** Additional file metadata */
36
+ metadata?: Record<string, unknown>;
37
+ }
38
+ /**
39
+ * Asset attached to a model.
40
+ */
41
+ export interface ModelAsset {
42
+ /** Unique asset identifier */
43
+ asset_id: UUID;
44
+ /** Model this asset belongs to */
45
+ model_id: UUID;
46
+ /** Field name in the model schema */
47
+ field_name: string;
48
+ /** Sort order for multiple assets */
49
+ sort_order: number;
50
+ /** Asset file data */
51
+ data: AssetData;
52
+ /** Creation timestamp */
53
+ _created_at: ISODateString;
54
+ /** Last update timestamp */
55
+ _updated_at: ISODateString;
56
+ }
package/dist/asset.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Asset types for the collection system.
3
+ * Assets are file attachments associated with models.
4
+ */
5
+ export {};
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Collection types for the collection system.
3
+ * Collections are containers for models with schema definitions.
4
+ */
5
+ import type { UUID, ISODateString, LtreePath, UserData } from "./utils.js";
6
+ import type { PropertyDefinition } from "./schema.js";
7
+ /**
8
+ * Definition for a folder within a collection.
9
+ * Folders organize models hierarchically.
10
+ */
11
+ export interface FolderDefinition {
12
+ label?: string;
13
+ description?: string;
14
+ color?: string;
15
+ }
16
+ /**
17
+ * Definition for a tag within a collection.
18
+ * Tags provide cross-cutting categorization.
19
+ */
20
+ export interface TagDefinition {
21
+ label?: string;
22
+ color?: string;
23
+ }
24
+ /**
25
+ * Input DTO for creating/updating a collection.
26
+ */
27
+ export interface CollectionDTOIn {
28
+ /** Unique path identifier (ltree format) */
29
+ path: LtreePath;
30
+ /** Maximum number of models allowed (-1 for unlimited) */
31
+ cardinality?: number;
32
+ /** Model types allowed in this collection */
33
+ types?: string[];
34
+ /** JSON Schema definitions per model type */
35
+ schemas?: Record<string, Record<string, PropertyDefinition>>;
36
+ /** Default values per model type */
37
+ defaults?: Record<string, UserData>;
38
+ /** User-defined data */
39
+ data?: UserData;
40
+ /** User-defined metadata */
41
+ meta?: UserData;
42
+ /** Whether collection is hidden from listings */
43
+ is_unlisted?: boolean;
44
+ /** Whether collection can be deleted */
45
+ is_deletable?: boolean;
46
+ /** Whether collection is read-only */
47
+ is_readonly?: boolean;
48
+ /** Folder definitions */
49
+ folders?: Record<string, FolderDefinition>;
50
+ /** Tag definitions */
51
+ tags?: Record<string, TagDefinition>;
52
+ }
53
+ /**
54
+ * Output DTO for collection responses.
55
+ * Extends input fields with server-generated identifiers.
56
+ */
57
+ export interface CollectionDTOOut extends CollectionDTOIn {
58
+ /** Unique collection identifier */
59
+ collection_id: UUID;
60
+ /** Project this collection belongs to */
61
+ project_id: UUID;
62
+ /** Creation timestamp */
63
+ _created_at: ISODateString;
64
+ /** Last update timestamp */
65
+ _updated_at: ISODateString;
66
+ }
67
+ /**
68
+ * Full database row representation of a collection.
69
+ */
70
+ export interface CollectionDbRow extends CollectionDTOOut {
71
+ /** @internal Disables REST API access for entire collection */
72
+ __is_rest_disabled?: boolean;
73
+ }
74
+ /**
75
+ * Primary Collection type alias.
76
+ */
77
+ export type Collection = CollectionDbRow;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Collection types for the collection system.
3
+ * Collections are containers for models with schema definitions.
4
+ */
5
+ export {};
package/dist/mod.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @module @marianmeres/collection-types
3
+ *
4
+ * Type definitions for the collection management system.
5
+ * Pure interfaces with no runtime code - safe for type-only imports.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import type {
10
+ * Model,
11
+ * Collection,
12
+ * Relation,
13
+ * RelationType,
14
+ * PropertyDefinition,
15
+ * ApiResponse,
16
+ * UUID,
17
+ * } from "@marianmeres/collection-types";
18
+ * ```
19
+ */
20
+ export * from "./utils.js";
21
+ export * from "./model.js";
22
+ export * from "./collection.js";
23
+ export * from "./relation.js";
24
+ export * from "./schema.js";
25
+ export * from "./api.js";
26
+ export * from "./asset.js";
27
+ export * from "./adapter.js";
package/dist/mod.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @module @marianmeres/collection-types
3
+ *
4
+ * Type definitions for the collection management system.
5
+ * Pure interfaces with no runtime code - safe for type-only imports.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import type {
10
+ * Model,
11
+ * Collection,
12
+ * Relation,
13
+ * RelationType,
14
+ * PropertyDefinition,
15
+ * ApiResponse,
16
+ * UUID,
17
+ * } from "@marianmeres/collection-types";
18
+ * ```
19
+ */
20
+ // Utils (branded types, helpers)
21
+ export * from "./utils.js";
22
+ // Core entities
23
+ export * from "./model.js";
24
+ export * from "./collection.js";
25
+ export * from "./relation.js";
26
+ // Schema system
27
+ export * from "./schema.js";
28
+ // API layer
29
+ export * from "./api.js";
30
+ // Assets
31
+ export * from "./asset.js";
32
+ // Adapter (database layer)
33
+ export * from "./adapter.js";
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Model types for the collection system.
3
+ * Defines the structure of model records at different layers (input, output, database).
4
+ */
5
+ import type { UUID, ISODateString, LtreePath, UserData, MaybeLocalized } from "./utils.js";
6
+ /**
7
+ * Input DTO for creating/updating a model.
8
+ * Contains user-provided fields for model creation.
9
+ */
10
+ export interface ModelDTOIn {
11
+ /** Model type within collection */
12
+ type?: string;
13
+ /** Parent model ID for hierarchy */
14
+ parent_id?: UUID | null;
15
+ /** Unique path identifier (ltree format) */
16
+ path?: LtreePath | null;
17
+ /** Folder for organization */
18
+ folder?: string | null;
19
+ /** Tags for categorization */
20
+ tags?: string[];
21
+ /** User-defined data */
22
+ data?: UserData;
23
+ /** User-defined metadata */
24
+ meta?: UserData;
25
+ /** Whether model is hidden from listings */
26
+ is_unlisted?: boolean;
27
+ /** Whether model can be deleted */
28
+ is_deletable?: boolean;
29
+ /** Whether model is read-only */
30
+ is_readonly?: boolean;
31
+ /** Whether model is starred/favorited */
32
+ is_starred?: boolean;
33
+ /** Whether model is enabled/active */
34
+ is_enabled?: boolean;
35
+ /** Color flags */
36
+ red?: boolean;
37
+ orange?: boolean;
38
+ yellow?: boolean;
39
+ green?: boolean;
40
+ blue?: boolean;
41
+ purple?: boolean;
42
+ gray?: boolean;
43
+ }
44
+ /**
45
+ * Output DTO for model responses.
46
+ * Extends input fields with server-generated identifiers and timestamps.
47
+ */
48
+ export interface ModelDTOOut extends ModelDTOIn {
49
+ /** Unique model identifier */
50
+ model_id: UUID;
51
+ /** Collection this model belongs to */
52
+ collection_id: UUID;
53
+ /** Auto-generated label from schema _label_source fields */
54
+ _label?: MaybeLocalized<string> | null;
55
+ /** Computed label for hierarchy display */
56
+ _hierarchy_label?: string | null;
57
+ /** Creation timestamp */
58
+ _created_at: ISODateString;
59
+ /** Last update timestamp */
60
+ _updated_at: ISODateString;
61
+ }
62
+ /**
63
+ * Full database row representation of a model.
64
+ * Includes internal fields for search indexing and REST control.
65
+ */
66
+ export interface ModelDbRow extends ModelDTOOut {
67
+ /** @internal Disables REST API access */
68
+ __is_rest_disabled?: boolean;
69
+ /** @internal Structured search index data */
70
+ __searchable?: Record<string, unknown>;
71
+ /** @internal Full-text search string */
72
+ __searchable2?: string;
73
+ /** @internal Cached hierarchy path for ancestor queries */
74
+ __hierarchy_path?: LtreePath | null;
75
+ }
76
+ /**
77
+ * Model data with relation definitions for upsert operations.
78
+ * The __relations__ field is processed separately during save.
79
+ */
80
+ export interface ModelUpsertData extends ModelDbRow {
81
+ /** Relations to save with model (relation_type -> array of related model IDs) */
82
+ __relations__?: Record<string, UUID[]>;
83
+ }
84
+ /**
85
+ * Primary Model type with generic data typing.
86
+ * Use Model<MyDataType> for type-safe data access.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * interface BookData {
91
+ * title: string;
92
+ * author: string;
93
+ * isbn: string;
94
+ * }
95
+ * type Book = Model<BookData>;
96
+ * ```
97
+ */
98
+ export type Model<TData extends UserData = UserData> = ModelDbRow & {
99
+ data: TData;
100
+ };
package/dist/model.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Model types for the collection system.
3
+ * Defines the structure of model records at different layers (input, output, database).
4
+ */
5
+ export {};
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Relation types for the collection system.
3
+ * Relations link models across collections with typed relationships.
4
+ */
5
+ import type { UUID, ISODateString, UserData } from "./utils.js";
6
+ /**
7
+ * Input DTO for creating/updating a relation type.
8
+ * A RelationType defines a typed relationship between models from different collections.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const input: RelationTypeDTOIn = {
13
+ * relation_type: "author",
14
+ * model_collection_id: "books",
15
+ * related_collection_id: "people",
16
+ * };
17
+ * ```
18
+ */
19
+ export interface RelationTypeDTOIn {
20
+ /** Project identifier */
21
+ project_id?: UUID;
22
+ /** Unique relation type name (business key) */
23
+ relation_type?: string;
24
+ /** Collection ID of the "from" models */
25
+ model_collection_id?: UUID;
26
+ /** Collection ID of the "to" models (for strong relations) */
27
+ related_collection_id?: UUID;
28
+ /** Optional type filter for related models */
29
+ related_collection_model_type?: string;
30
+ /** Maximum number of relations allowed (-1 for unlimited) */
31
+ cardinality?: number;
32
+ /** Cardinality on the model side (1 = one-to-many, -1 = many-to-many) */
33
+ model_cardinality?: number;
34
+ /** Cardinality on the related side */
35
+ related_cardinality?: number;
36
+ /** Whether relation type is hidden from listings */
37
+ is_unlisted?: boolean;
38
+ /** Whether relation type can be deleted */
39
+ is_deletable?: boolean;
40
+ /** Whether relation type is read-only */
41
+ is_readonly?: boolean;
42
+ /** Additional metadata */
43
+ meta?: UserData;
44
+ }
45
+ /**
46
+ * Output DTO for relation type responses.
47
+ */
48
+ export interface RelationTypeDTOOut extends RelationTypeDTOIn {
49
+ /** Unique relation type identifier */
50
+ _relation_type_id: UUID;
51
+ /** Creation timestamp */
52
+ _created_at: ISODateString;
53
+ /** Last update timestamp */
54
+ _updated_at: ISODateString;
55
+ }
56
+ /**
57
+ * Full database row representation of a relation type.
58
+ */
59
+ export interface RelationTypeDbRow extends RelationTypeDTOOut {
60
+ /** @internal Disables REST API access */
61
+ __is_rest_disabled?: boolean;
62
+ }
63
+ /**
64
+ * Primary RelationType type alias.
65
+ */
66
+ export type RelationType = RelationTypeDbRow;
67
+ /**
68
+ * Input DTO for creating/updating a relation instance.
69
+ * A Relation is a link between two models through a RelationType.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const input: RelationDTOIn = {
74
+ * related_id: "uuid-of-related-model",
75
+ * sort_order: 1,
76
+ * };
77
+ * ```
78
+ */
79
+ export interface RelationDTOIn {
80
+ /** UUID of the strongly-related model (must exist in related collection) */
81
+ related_id?: UUID;
82
+ /** Arbitrary string for weak references (when related item doesn't exist as model) */
83
+ weak_related_id?: string;
84
+ /** Sort order for displaying relations */
85
+ sort_order?: number;
86
+ /** Whether relation is hidden from listings */
87
+ is_unlisted?: boolean;
88
+ /** Whether relation can be deleted */
89
+ is_deletable?: boolean;
90
+ /** Whether relation is read-only */
91
+ is_readonly?: boolean;
92
+ /** Additional metadata */
93
+ meta?: UserData;
94
+ }
95
+ /**
96
+ * Output DTO for relation responses.
97
+ */
98
+ export interface RelationDTOOut extends RelationDTOIn {
99
+ /** Unique relation identifier */
100
+ relation_id: UUID;
101
+ /** Relation type identifier */
102
+ _relation_type_id: UUID;
103
+ /** Source model identifier */
104
+ model_id: UUID;
105
+ /** Creation timestamp */
106
+ _created_at: ISODateString;
107
+ /** Last update timestamp */
108
+ _updated_at: ISODateString;
109
+ }
110
+ /**
111
+ * Full database row representation of a relation.
112
+ */
113
+ export interface RelationDbRow extends RelationDTOOut {
114
+ }
115
+ /**
116
+ * Primary Relation type alias.
117
+ */
118
+ export type Relation = RelationDbRow;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Relation types for the collection system.
3
+ * Relations link models across collections with typed relationships.
4
+ */
5
+ export {};
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Schema types for the collection system.
3
+ * Defines JSON Schema extensions and UI configuration.
4
+ */
5
+ /** HTML field type for UI rendering */
6
+ export type SchemaHtmlType = "text" | "textarea" | "wysiwyg" | "number" | "boolean" | "select" | "multiselect" | "date" | "datetime" | "time" | "color" | "relation" | "asset" | "json" | "code";
7
+ /** Configuration for relation-type fields in schema */
8
+ export interface RelationTypeConfig {
9
+ relation_type: string;
10
+ domain?: string;
11
+ entity?: string;
12
+ cardinality?: number;
13
+ }
14
+ /** Configuration for asset-type fields in schema */
15
+ export interface AssetTypeConfig {
16
+ accept?: string[];
17
+ maxSize?: number;
18
+ variants?: string[];
19
+ }
20
+ /** Configuration for select/multiselect fields */
21
+ export interface SelectConfig {
22
+ options: Array<{
23
+ value: string;
24
+ label: string;
25
+ }>;
26
+ multiple?: boolean;
27
+ }
28
+ /** Configuration for _html schema keyword */
29
+ export interface SchemaHtmlConfig {
30
+ type: SchemaHtmlType;
31
+ _type_config?: RelationTypeConfig | AssetTypeConfig | SelectConfig;
32
+ rows?: number;
33
+ placeholder?: string;
34
+ help?: string;
35
+ readonly?: boolean;
36
+ hidden?: boolean;
37
+ }
38
+ /**
39
+ * Custom JSON Schema keywords for collection system.
40
+ * These extend standard JSON Schema with collection-specific metadata.
41
+ */
42
+ export interface CustomSchemaKeywords {
43
+ /** Default value for property */
44
+ _default?: unknown;
45
+ /** UI hint configuration object */
46
+ _html?: SchemaHtmlConfig;
47
+ /** Property title for display */
48
+ _title?: string;
49
+ /** Property description for display */
50
+ _description?: string;
51
+ /** Property used as model label (number, priority 1=highest) */
52
+ _label_source?: number;
53
+ /** Allow building hierarchy from label slashes */
54
+ _label_source_allow_build_hierarchy?: boolean;
55
+ /** Path uniqueness constraint */
56
+ _unique?: boolean;
57
+ /** Include in full-text search */
58
+ _searchable?: boolean;
59
+ /** Array of filters to apply before indexing */
60
+ _searchable_filters?: string[];
61
+ /** Type ordering */
62
+ _order?: number;
63
+ }
64
+ /**
65
+ * Property definition extending JSON Schema with custom keywords.
66
+ * Used in collection schemas to define model fields.
67
+ */
68
+ export interface PropertyDefinition extends CustomSchemaKeywords {
69
+ type?: "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
70
+ format?: string;
71
+ enum?: unknown[];
72
+ items?: PropertyDefinition;
73
+ properties?: Record<string, PropertyDefinition>;
74
+ required?: string[];
75
+ minimum?: number;
76
+ maximum?: number;
77
+ minLength?: number;
78
+ maxLength?: number;
79
+ pattern?: string;
80
+ default?: unknown;
81
+ }
82
+ /**
83
+ * Model type definition within a collection.
84
+ * Defines the schema for a specific model type.
85
+ */
86
+ export interface ModelDefinition {
87
+ properties: Record<string, PropertyDefinition>;
88
+ required?: string[];
89
+ }
package/dist/schema.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Schema types for the collection system.
3
+ * Defines JSON Schema extensions and UI configuration.
4
+ */
5
+ export {};
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Utility types for the collection system.
3
+ * Includes branded types for compile-time safety and common helper types.
4
+ */
5
+ /** Branded type for UUID strings */
6
+ export type UUID = string & {
7
+ readonly __brand: "UUID";
8
+ };
9
+ /** Branded type for ISO 8601 date strings */
10
+ export type ISODateString = string & {
11
+ readonly __brand: "ISODateString";
12
+ };
13
+ /** Branded type for PostgreSQL ltree paths */
14
+ export type LtreePath = string & {
15
+ readonly __brand: "LtreePath";
16
+ };
17
+ /** Value that may be localized with language keys */
18
+ export type MaybeLocalized<T> = T | Record<string, T>;
19
+ /** JSON-compatible primitive */
20
+ export type JsonPrimitive = string | number | boolean | null;
21
+ /** JSON-compatible object */
22
+ export type JsonObject = {
23
+ [key: string]: JsonValue;
24
+ };
25
+ /** JSON-compatible array */
26
+ export type JsonArray = JsonValue[];
27
+ /** JSON-compatible value (recursive) */
28
+ export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
29
+ /** User-provided flexible data */
30
+ export type UserData = Record<string, unknown>;
31
+ /** Helper to create a branded type */
32
+ export type Brand<T, B extends string> = T & {
33
+ readonly __brand: B;
34
+ };
package/dist/utils.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Utility types for the collection system.
3
+ * Includes branded types for compile-time safety and common helper types.
4
+ */
5
+ export {};
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@marianmeres/collection-types",
3
+ "version": "1.0.1",
4
+ "type": "module",
5
+ "main": "dist/mod.js",
6
+ "types": "dist/mod.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/mod.d.ts",
10
+ "import": "./dist/mod.js"
11
+ }
12
+ },
13
+ "author": "Marian Meres",
14
+ "license": "MIT",
15
+ "dependencies": {},
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/marianmeres/collection-types.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/marianmeres/collection-types/issues"
22
+ }
23
+ }