@airdraft/ui-core 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@airdraft/ui-core` will be documented here.
4
+
5
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
@@ -0,0 +1,3 @@
1
+ /** Collection names reserved by built-in API routes. */
2
+ export declare const RESERVED_COLLECTION_NAMES: Set<string>;
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,eAAO,MAAM,yBAAyB,aAOpC,CAAA"}
@@ -0,0 +1,10 @@
1
+ /** Collection names reserved by built-in API routes. */
2
+ export const RESERVED_COLLECTION_NAMES = new Set([
3
+ 'schema',
4
+ 'media',
5
+ 'openapi',
6
+ 'health',
7
+ 'apply',
8
+ 'collections',
9
+ ]);
10
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC;IAC/C,QAAQ;IACR,OAAO;IACP,SAAS;IACT,QAAQ;IACR,OAAO;IACP,aAAa;CACd,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { FieldType } from '@airdraft/core';
2
+ export interface FieldTypeMeta {
3
+ type: FieldType;
4
+ label: string;
5
+ description: string;
6
+ /** Lucide icon name (resolved by @airdraft/react-ui into actual components) */
7
+ icon: string;
8
+ }
9
+ export declare const FIELD_TYPE_META: Record<FieldType, FieldTypeMeta>;
10
+ //# sourceMappingURL=field-type-meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-type-meta.d.ts","sourceRoot":"","sources":["../src/field-type-meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAA;CACb;AAED,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,SAAS,EAAE,aAAa,CAe5D,CAAA"}
@@ -0,0 +1,17 @@
1
+ export const FIELD_TYPE_META = {
2
+ string: { type: 'string', label: 'Short text', description: 'Single line of text', icon: 'Type' },
3
+ text: { type: 'text', label: 'Long text', description: 'Multi-line plain text', icon: 'AlignLeft' },
4
+ number: { type: 'number', label: 'Number', description: 'Integer or decimal value', icon: 'Hash' },
5
+ boolean: { type: 'boolean', label: 'Boolean', description: 'True / false toggle', icon: 'ToggleLeft' },
6
+ date: { type: 'date', label: 'Date', description: 'Calendar date (YYYY-MM-DD)', icon: 'Calendar' },
7
+ datetime: { type: 'datetime', label: 'Date & time', description: 'Date with time (ISO 8601)', icon: 'CalendarClock' },
8
+ list: { type: 'list', label: 'List', description: 'Array of scalar values', icon: 'List' },
9
+ select: { type: 'select', label: 'Select', description: 'One of a set of options', icon: 'ChevronDown' },
10
+ multiselect: { type: 'multiselect', label: 'Multi-select', description: 'Multiple selectable options', icon: 'ListChecks' },
11
+ 'rich-text': { type: 'rich-text', label: 'Rich text', description: 'MDX / rich body content', icon: 'FileText' },
12
+ relation: { type: 'relation', label: 'Relation', description: 'Reference to another entry', icon: 'Link' },
13
+ relations: { type: 'relations', label: 'Relations', description: 'Multiple entry references', icon: 'Network' },
14
+ object: { type: 'object', label: 'Object', description: 'Nested field group', icon: 'Braces' },
15
+ image: { type: 'image', label: 'Image', description: 'Image URL or media asset', icon: 'Image' },
16
+ };
17
+ //# sourceMappingURL=field-type-meta.js.map
@@ -0,0 +1 @@
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IAC9H,WAAW,EAAE,EAAE,IAAI,EAAE,WAAW,EAAI,KAAK,EAAE,WAAW,EAAK,WAAW,EAAE,yBAAyB,EAAS,IAAI,EAAE,UAAU,EAAE;IAC5H,QAAQ,EAAK,EAAE,IAAI,EAAE,UAAU,EAAK,KAAK,EAAE,UAAU,EAAM,WAAW,EAAE,4BAA4B,EAAM,IAAI,EAAE,MAAM,EAAE;IACxH,SAAS,EAAI,EAAE,IAAI,EAAE,WAAW,EAAI,KAAK,EAAE,WAAW,EAAK,WAAW,EAAE,2BAA2B,EAAO,IAAI,EAAE,SAAS,EAAE;IAC3H,MAAM,EAAO,EAAE,IAAI,EAAE,QAAQ,EAAO,KAAK,EAAE,QAAQ,EAAQ,WAAW,EAAE,oBAAoB,EAAc,IAAI,EAAE,QAAQ,EAAE;IAC1H,KAAK,EAAQ,EAAE,IAAI,EAAE,OAAO,EAAQ,KAAK,EAAE,OAAO,EAAS,WAAW,EAAE,0BAA0B,EAAQ,IAAI,EAAE,OAAO,EAAE;CAC1H,CAAA"}
@@ -0,0 +1,6 @@
1
+ export { FIELD_TYPE_META } from './field-type-meta.js';
2
+ export type { FieldTypeMeta } from './field-type-meta.js';
3
+ export { RESERVED_COLLECTION_NAMES } from './constants.js';
4
+ export { validateFieldKey, generateFieldKey, validateCollectionName, } from './validators.js';
5
+ export { applyFieldUpdate, applyFieldDelete, buildDefaultPath } from './mutations.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { FIELD_TYPE_META } from './field-type-meta.js';
2
+ export { RESERVED_COLLECTION_NAMES } from './constants.js';
3
+ export { validateFieldKey, generateFieldKey, validateCollectionName, } from './validators.js';
4
+ export { applyFieldUpdate, applyFieldDelete, buildDefaultPath } from './mutations.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAGtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { CollectionMap, FieldConfig } from '@airdraft/core';
2
+ /** Add or overwrite a field on a collection, returning a new CollectionMap. */
3
+ export declare function applyFieldUpdate(collections: CollectionMap, collectionName: string, fieldKey: string, fieldConfig: FieldConfig): CollectionMap;
4
+ /** Remove a field from a collection, returning a new CollectionMap. */
5
+ export declare function applyFieldDelete(collections: CollectionMap, collectionName: string, fieldKey: string): CollectionMap;
6
+ /** Build the default path template for a new collection. */
7
+ export declare function buildDefaultPath(name: string, format: 'mdx' | 'json' | 'yaml'): string;
8
+ //# sourceMappingURL=mutations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../src/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEhE,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,aAAa,EAC1B,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,GACvB,aAAa,CAUf;AAED,uEAAuE;AACvE,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,aAAa,EAC1B,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,GACf,aAAa,CAOf;AAED,4DAA4D;AAC5D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAEtF"}
@@ -0,0 +1,26 @@
1
+ /** Add or overwrite a field on a collection, returning a new CollectionMap. */
2
+ export function applyFieldUpdate(collections, collectionName, fieldKey, fieldConfig) {
3
+ const col = collections[collectionName];
4
+ if (!col)
5
+ return collections;
6
+ return {
7
+ ...collections,
8
+ [collectionName]: {
9
+ ...col,
10
+ fields: { ...col.fields, [fieldKey]: fieldConfig },
11
+ },
12
+ };
13
+ }
14
+ /** Remove a field from a collection, returning a new CollectionMap. */
15
+ export function applyFieldDelete(collections, collectionName, fieldKey) {
16
+ const col = collections[collectionName];
17
+ if (!col)
18
+ return collections;
19
+ const fields = Object.fromEntries(Object.entries(col.fields ?? {}).filter(([k]) => k !== fieldKey));
20
+ return { ...collections, [collectionName]: { ...col, fields } };
21
+ }
22
+ /** Build the default path template for a new collection. */
23
+ export function buildDefaultPath(name, format) {
24
+ return `${name}/{slug}.${format}`;
25
+ }
26
+ //# sourceMappingURL=mutations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.js","sourceRoot":"","sources":["../src/mutations.ts"],"names":[],"mappings":"AAEA,+EAA+E;AAC/E,MAAM,UAAU,gBAAgB,CAC9B,WAA0B,EAC1B,cAAsB,EACtB,QAAgB,EAChB,WAAwB;IAExB,MAAM,GAAG,GAAG,WAAW,CAAC,cAAc,CAAC,CAAA;IACvC,IAAI,CAAC,GAAG;QAAE,OAAO,WAAW,CAAA;IAC5B,OAAO;QACL,GAAG,WAAW;QACd,CAAC,cAAc,CAAC,EAAE;YAChB,GAAG,GAAG;YACN,MAAM,EAAE,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE;SACnD;KACF,CAAA;AACH,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,gBAAgB,CAC9B,WAA0B,EAC1B,cAAsB,EACtB,QAAgB;IAEhB,MAAM,GAAG,GAAG,WAAW,CAAC,cAAc,CAAC,CAAA;IACvC,IAAI,CAAC,GAAG;QAAE,OAAO,WAAW,CAAA;IAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAC/B,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,CACjE,CAAA;IACD,OAAO,EAAE,GAAG,WAAW,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,EAAE,CAAA;AACjE,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,MAA+B;IAC5E,OAAO,GAAG,IAAI,WAAW,MAAM,EAAE,CAAA;AACnC,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Validate a field key string.
3
+ * Returns an error message string, or null if valid.
4
+ */
5
+ export declare function validateFieldKey(key: string): string | null;
6
+ /**
7
+ * Derive a valid field key from a human-readable label.
8
+ * e.g. "Author Name" → "author_name"
9
+ */
10
+ export declare function generateFieldKey(label: string): string;
11
+ /**
12
+ * Validate a collection name.
13
+ * Returns an error message string, or null if valid.
14
+ */
15
+ export declare function validateCollectionName(name: string): string | null;
16
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO3D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOtD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUlE"}
@@ -0,0 +1,43 @@
1
+ import { RESERVED_COLLECTION_NAMES } from './constants.js';
2
+ /**
3
+ * Validate a field key string.
4
+ * Returns an error message string, or null if valid.
5
+ */
6
+ export function validateFieldKey(key) {
7
+ const trimmed = key.trim();
8
+ if (!trimmed)
9
+ return 'Field key is required.';
10
+ if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(trimmed)) {
11
+ return 'Field key must start with a letter and contain only a-z, A-Z, 0-9, _.';
12
+ }
13
+ return null;
14
+ }
15
+ /**
16
+ * Derive a valid field key from a human-readable label.
17
+ * e.g. "Author Name" → "author_name"
18
+ */
19
+ export function generateFieldKey(label) {
20
+ return label
21
+ .trim()
22
+ .toLowerCase()
23
+ .replace(/[^a-z0-9]+/g, '_')
24
+ .replace(/^_+|_+$/g, '')
25
+ .replace(/^(\d)/, '_$1');
26
+ }
27
+ /**
28
+ * Validate a collection name.
29
+ * Returns an error message string, or null if valid.
30
+ */
31
+ export function validateCollectionName(name) {
32
+ const trimmed = name.trim().toLowerCase();
33
+ if (!trimmed)
34
+ return 'Collection name is required.';
35
+ if (RESERVED_COLLECTION_NAMES.has(trimmed)) {
36
+ return `"${trimmed}" is a reserved collection name.`;
37
+ }
38
+ if (!/^[a-z][a-z0-9-]*$/.test(trimmed)) {
39
+ return 'Collection name must start with a letter and contain only a-z, 0-9, -.';
40
+ }
41
+ return null;
42
+ }
43
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AAE1D;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAA;IAC1B,IAAI,CAAC,OAAO;QAAE,OAAO,wBAAwB,CAAA;IAC7C,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7C,OAAO,uEAAuE,CAAA;IAChF,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,KAAK;SACT,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACzC,IAAI,CAAC,OAAO;QAAE,OAAO,8BAA8B,CAAA;IACnD,IAAI,yBAAyB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3C,OAAO,IAAI,OAAO,kCAAkC,CAAA;IACtD,CAAC;IACD,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,OAAO,wEAAwE,CAAA;IACjF,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@airdraft/ui-core",
3
+ "version": "0.1.0",
4
+ "description": "Airdraft UI core — field type metadata, validators, and schema mutation helpers (zero framework deps)",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": ["dist", "README.md", "CHANGELOG.md"],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "dev": "tsc --watch",
18
+ "clean": "rm -rf dist",
19
+ "typecheck": "tsc --noEmit",
20
+ "prepublishOnly": "npm run build",
21
+ "release": "standard-version",
22
+ "release:patch": "standard-version --release-as patch",
23
+ "release:minor": "standard-version --release-as minor",
24
+ "release:major": "standard-version --release-as major"
25
+ },
26
+ "publishConfig": { "access": "public" },
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "@airdraft/core": "*"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^20.0.0",
33
+ "standard-version": "^9.5.0",
34
+ "typescript": "^5.4.0"
35
+ },
36
+ "engines": { "node": ">=18.0.0" }
37
+ }