kernelcms 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.
@@ -0,0 +1,224 @@
1
+ import { T as SanitizedConfig, E as KernelConfig, K as Kernel, m as CollectionConfig, G as GlobalConfig, b as AccessResult, a as AccessFn, A as AccessArgs, c as AnyField, W as SelectOption, Q as RequestContext, r as Doc, p as CreateOptions, y as FindOptions, w as FindByIDOptions, Z as UpdateOptions, q as DeleteOptions, o as CountOptions, I as LoginOptions, f as AuthResult, g as AuthUser, x as FindGlobalOptions, Y as UpdateGlobalOptions, u as FieldType, s as FieldAdmin } from './types-DMOX4FIP.js';
2
+ export { d as ArrayField, e as AuthOptions, B as BooleanField, C as CollectionAccess, h as CollectionAfterChangeHook, i as CollectionAfterDeleteHook, j as CollectionAfterReadHook, k as CollectionBeforeChangeHook, l as CollectionBeforeDeleteHook, n as CollectionHooks, D as DateField, F as FieldAccess, t as FieldBase, v as FieldValidateArgs, z as GroupField, H as HookArgs, J as JSONField, L as LocalizationConfig, N as NumberField, O as Operation, M as OperationBase, P as PointField, R as RelationshipField, S as RichTextField, U as SanitizedLocalization, V as SelectField, X as TextField, _ as ValidateFn } from './types-DMOX4FIP.js';
3
+ import { L as Logger, K as KernelSchema, R as Row, W as Where, S as SortSpec, C as ColumnSchema, d as StorageType, D as DatabaseAdapter, P as PaginatedResult } from './index-BxvPeUO2.js';
4
+ export { A as Adapter, a as AdapterContext, b as DatabaseAdapterFactory, c as DatabaseCapabilities, M as MigrationReport, T as TableSchema, e as WhereCondition, f as WhereOperator } from './index-BxvPeUO2.js';
5
+
6
+ /** Identity helper that gives `kernel.config.ts` full type-checking and inference. */
7
+ declare function defineConfig(config: KernelConfig): KernelConfig;
8
+ declare function sanitizeConfig(config: KernelConfig): SanitizedConfig;
9
+ declare function defaultLocaleOf(config: SanitizedConfig): string;
10
+
11
+ declare const LEVELS: {
12
+ readonly debug: 10;
13
+ readonly info: 20;
14
+ readonly warn: 30;
15
+ readonly error: 40;
16
+ };
17
+ declare function createLogger(level?: keyof typeof LEVELS): Logger;
18
+ interface InitOptions {
19
+ /** Apply the schema (create/alter tables) during init. Default false. */
20
+ autoMigrate?: boolean;
21
+ logLevel?: keyof typeof LEVELS;
22
+ }
23
+ /** Boot a Kernel instance: sanitize config, init the adapter, expose the Local API. */
24
+ declare function initKernel(config: KernelConfig, options?: InitOptions): Promise<Kernel>;
25
+
26
+ declare function tableForCollection(slug: string): string;
27
+ declare function tableForGlobal(slug: string): string;
28
+ /** The fixed primary-key id used for the single row backing a global. */
29
+ declare const GLOBAL_ROW_ID = "singleton";
30
+ /** Compile the sanitized config into the storage-facing schema for the adapter. */
31
+ declare function compileSchema(config: SanitizedConfig): KernelSchema;
32
+
33
+ interface CodegenInput {
34
+ collections: CollectionConfig[];
35
+ globals: GlobalConfig[];
36
+ }
37
+ /** Generate a TypeScript declaration string describing every collection and global. */
38
+ declare function generateTypes(input: CodegenInput): string;
39
+
40
+ /** Parse Payload-style sort strings ("-createdAt,title") into a SortSpec list. */
41
+ declare function parseSort(sort: string | string[] | undefined): SortSpec[];
42
+ declare function mergeWhere(a: Where | undefined, b: Where | undefined): Where | undefined;
43
+ /** In-memory evaluation of a Where clause against a row (used for access guards/population). */
44
+ declare function matchesWhere(row: Row, where: Where | undefined): boolean;
45
+
46
+ /**
47
+ * Evaluate an access rule. When no rule is defined, KernelCMS is secure by
48
+ * default: the operation is allowed only for authenticated users. Collections
49
+ * that should be publicly readable must opt in with `access.read: () => true`.
50
+ */
51
+ declare function evalAccess(fn: AccessFn | undefined, args: AccessArgs): Promise<AccessResult>;
52
+ /** A result is "allowed" unless it is explicitly `false`. A `Where` means allowed-but-scoped. */
53
+ declare function isAllowed(result: AccessResult): boolean;
54
+ declare function asWhere(result: AccessResult): Where | undefined;
55
+
56
+ /** Typed error hierarchy. Every failure crossing an API boundary is a KernelError. */
57
+ type ErrorCode = 'VALIDATION' | 'NOT_FOUND' | 'FORBIDDEN' | 'UNAUTHORIZED' | 'CONFLICT' | 'BAD_REQUEST' | 'TOO_MANY_REQUESTS' | 'INTERNAL';
58
+ interface FieldError {
59
+ path: string;
60
+ message: string;
61
+ }
62
+ declare class KernelError extends Error {
63
+ readonly code: ErrorCode;
64
+ readonly status: number;
65
+ readonly details: unknown;
66
+ constructor(message: string, code: ErrorCode, status: number, details?: unknown);
67
+ toJSON(): {
68
+ error: {
69
+ code: ErrorCode;
70
+ message: string;
71
+ details?: unknown;
72
+ };
73
+ };
74
+ }
75
+ declare class ValidationError extends KernelError {
76
+ readonly errors: FieldError[];
77
+ constructor(errors: FieldError[]);
78
+ }
79
+ declare class NotFoundError extends KernelError {
80
+ constructor(message?: string);
81
+ }
82
+ declare class ForbiddenError extends KernelError {
83
+ constructor(message?: string);
84
+ }
85
+ declare class UnauthorizedError extends KernelError {
86
+ constructor(message?: string);
87
+ }
88
+ declare class BadRequestError extends KernelError {
89
+ constructor(message?: string, details?: unknown);
90
+ }
91
+ declare class ConflictError extends KernelError {
92
+ constructor(message?: string, details?: unknown);
93
+ }
94
+ declare class TooManyRequestsError extends KernelError {
95
+ /** Seconds the client should wait before retrying, surfaced as Retry-After. */
96
+ readonly retryAfter?: number;
97
+ constructor(message?: string, retryAfter?: number);
98
+ }
99
+ declare function isKernelError(err: unknown): err is KernelError;
100
+
101
+ declare function humanize(name: string): string;
102
+ declare function fieldLabel(field: AnyField): string;
103
+ declare function optionValue(opt: SelectOption): string;
104
+ declare function optionLabel(opt: SelectOption): string;
105
+ /** The physical storage type for a field, accounting for localization and arity. */
106
+ declare function storageTypeForField(field: AnyField): StorageType;
107
+ declare function columnForField(field: AnyField): ColumnSchema;
108
+ /** Resolve a field's default value (supports literal or factory). */
109
+ declare function defaultForField(field: AnyField): unknown;
110
+ declare function applyDefaults(fields: AnyField[], data: Row): Row;
111
+ interface ValidateContext {
112
+ req: RequestContext;
113
+ operation: 'create' | 'update';
114
+ }
115
+ declare function validateFields(fields: AnyField[], data: Row, ctx: ValidateContext, prefix?: string): Promise<FieldError[]>;
116
+ interface SerializeOptions {
117
+ locale: string;
118
+ existingRow?: Row | null;
119
+ }
120
+ /** Build a storage row from public field data, merging localized values. */
121
+ declare function serializeDoc(fields: AnyField[], data: Row, opts: SerializeOptions): Row;
122
+ interface DeserializeOptions {
123
+ locale: string;
124
+ fallbackLocale: string | false;
125
+ }
126
+ /** Resolve a storage row into a public document body (localized values resolved). */
127
+ declare function deserializeDoc(fields: AnyField[], row: Row, opts: DeserializeOptions): Row;
128
+ /** Top-level relationship fields that can be populated. */
129
+ declare function relationshipFields(fields: AnyField[]): Array<{
130
+ name: string;
131
+ relationTo: string;
132
+ hasMany: boolean;
133
+ }>;
134
+
135
+ interface OperationCtx {
136
+ config: SanitizedConfig;
137
+ db: DatabaseAdapter;
138
+ }
139
+ declare function createOperations(ctx: OperationCtx): {
140
+ create: <T extends Doc = Doc>(opts: CreateOptions) => Promise<T>;
141
+ find: <T extends Doc = Doc>(opts: FindOptions) => Promise<PaginatedResult<T>>;
142
+ findByID: <T extends Doc = Doc>(opts: FindByIDOptions) => Promise<T | null>;
143
+ update: <T extends Doc = Doc>(opts: UpdateOptions) => Promise<T | null>;
144
+ delete: <T extends Doc = Doc>(opts: DeleteOptions) => Promise<T | null>;
145
+ count: (opts: CountOptions) => Promise<number>;
146
+ login: (opts: LoginOptions) => Promise<AuthResult>;
147
+ authenticate: (token: string) => Promise<AuthUser | null>;
148
+ findGlobal: <T extends Row = Row>(opts: FindGlobalOptions) => Promise<T>;
149
+ updateGlobal: <T extends Row = Row>(opts: UpdateGlobalOptions) => Promise<T>;
150
+ };
151
+ type Operations = ReturnType<typeof createOperations>;
152
+
153
+ declare function hashPassword(password: string): Promise<string>;
154
+ declare function verifyPassword(password: string, stored: string): Promise<boolean>;
155
+ interface TokenPayload {
156
+ sub: string;
157
+ collection: string;
158
+ iat?: number;
159
+ exp?: number;
160
+ [key: string]: unknown;
161
+ }
162
+ declare function signToken(payload: Omit<TokenPayload, 'iat' | 'exp'>, secret: string, expiresInSec?: number): string;
163
+ declare function verifyToken(token: string, secret: string): TokenPayload | null;
164
+
165
+ /**
166
+ * Produce a serializable description of the content model for the admin UI and
167
+ * external tooling. Access functions, validators, and hooks are intentionally
168
+ * omitted — only data needed to render forms and tables is included.
169
+ */
170
+
171
+ interface AdminFieldOption {
172
+ label: string;
173
+ value: string;
174
+ }
175
+ interface AdminField {
176
+ name: string;
177
+ type: FieldType | 'password';
178
+ label: string;
179
+ required: boolean;
180
+ unique: boolean;
181
+ localized: boolean;
182
+ hasMany?: boolean;
183
+ relationTo?: string;
184
+ options?: AdminFieldOption[];
185
+ fields?: AdminField[];
186
+ min?: number;
187
+ max?: number;
188
+ minLength?: number;
189
+ maxLength?: number;
190
+ admin?: Omit<FieldAdmin, 'condition'>;
191
+ }
192
+ interface AdminCollection {
193
+ slug: string;
194
+ labels: {
195
+ singular: string;
196
+ plural: string;
197
+ };
198
+ useAsTitle: string;
199
+ defaultColumns?: string[];
200
+ group?: string;
201
+ description?: string;
202
+ auth: boolean;
203
+ hidden: boolean;
204
+ fields: AdminField[];
205
+ }
206
+ interface AdminGlobal {
207
+ slug: string;
208
+ label: string;
209
+ fields: AdminField[];
210
+ }
211
+ interface AdminSchema {
212
+ collections: AdminCollection[];
213
+ globals: AdminGlobal[];
214
+ localization: {
215
+ locales: string[];
216
+ defaultLocale: string;
217
+ } | null;
218
+ routes: {
219
+ api: string;
220
+ };
221
+ }
222
+ declare function describeConfig(config: SanitizedConfig): AdminSchema;
223
+
224
+ export { AccessArgs, AccessFn, AccessResult, type AdminCollection, type AdminField, type AdminFieldOption, type AdminGlobal, type AdminSchema, AnyField, AuthResult, AuthUser, BadRequestError, type CodegenInput, CollectionConfig, ColumnSchema, ConflictError, CountOptions, CreateOptions, DatabaseAdapter, DeleteOptions, Doc, type ErrorCode, FieldAdmin, type FieldError, FieldType, FindByIDOptions, FindGlobalOptions, FindOptions, ForbiddenError, GLOBAL_ROW_ID, GlobalConfig, type InitOptions, Kernel, KernelConfig, KernelError, KernelSchema, Logger, LoginOptions, NotFoundError, type OperationCtx, type Operations, PaginatedResult, RequestContext, Row, SanitizedConfig, SelectOption, SortSpec, StorageType, type TokenPayload, TooManyRequestsError, UnauthorizedError, UpdateGlobalOptions, UpdateOptions, ValidationError, Where, applyDefaults, asWhere, columnForField, compileSchema, createLogger, createOperations, defaultForField, defaultLocaleOf, defineConfig, describeConfig, deserializeDoc, evalAccess, fieldLabel, generateTypes, hashPassword, humanize, initKernel, isAllowed, isKernelError, matchesWhere, mergeWhere, optionLabel, optionValue, parseSort, relationshipFields, sanitizeConfig, serializeDoc, signToken, storageTypeForField, tableForCollection, tableForGlobal, validateFields, verifyPassword, verifyToken };
package/dist/index.js ADDED
@@ -0,0 +1,90 @@
1
+ import {
2
+ BadRequestError,
3
+ ConflictError,
4
+ ForbiddenError,
5
+ GLOBAL_ROW_ID,
6
+ KernelError,
7
+ NotFoundError,
8
+ TooManyRequestsError,
9
+ UnauthorizedError,
10
+ ValidationError,
11
+ applyDefaults,
12
+ asWhere,
13
+ columnForField,
14
+ compileSchema,
15
+ createLogger,
16
+ createOperations,
17
+ defaultForField,
18
+ defaultLocaleOf,
19
+ defineConfig,
20
+ describeConfig,
21
+ deserializeDoc,
22
+ evalAccess,
23
+ fieldLabel,
24
+ generateTypes,
25
+ hashPassword,
26
+ humanize,
27
+ initKernel,
28
+ isAllowed,
29
+ isKernelError,
30
+ matchesWhere,
31
+ mergeWhere,
32
+ optionLabel,
33
+ optionValue,
34
+ parseSort,
35
+ relationshipFields,
36
+ sanitizeConfig,
37
+ serializeDoc,
38
+ signToken,
39
+ storageTypeForField,
40
+ tableForCollection,
41
+ tableForGlobal,
42
+ validateFields,
43
+ verifyPassword,
44
+ verifyToken
45
+ } from "./chunk-O5TO5JFA.js";
46
+ export {
47
+ BadRequestError,
48
+ ConflictError,
49
+ ForbiddenError,
50
+ GLOBAL_ROW_ID,
51
+ KernelError,
52
+ NotFoundError,
53
+ TooManyRequestsError,
54
+ UnauthorizedError,
55
+ ValidationError,
56
+ applyDefaults,
57
+ asWhere,
58
+ columnForField,
59
+ compileSchema,
60
+ createLogger,
61
+ createOperations,
62
+ defaultForField,
63
+ defaultLocaleOf,
64
+ defineConfig,
65
+ describeConfig,
66
+ deserializeDoc,
67
+ evalAccess,
68
+ fieldLabel,
69
+ generateTypes,
70
+ hashPassword,
71
+ humanize,
72
+ initKernel,
73
+ isAllowed,
74
+ isKernelError,
75
+ matchesWhere,
76
+ mergeWhere,
77
+ optionLabel,
78
+ optionValue,
79
+ parseSort,
80
+ relationshipFields,
81
+ sanitizeConfig,
82
+ serializeDoc,
83
+ signToken,
84
+ storageTypeForField,
85
+ tableForCollection,
86
+ tableForGlobal,
87
+ validateFields,
88
+ verifyPassword,
89
+ verifyToken
90
+ };
@@ -0,0 +1,21 @@
1
+ import { PoolConfig } from 'pg';
2
+ import { D as DatabaseAdapter } from './index-BxvPeUO2.js';
3
+
4
+ interface PostgresAdapterOptions {
5
+ /** Connection string. Defaults to `process.env.DATABASE_URL`. */
6
+ url?: string;
7
+ /**
8
+ * TLS. `true` is a convenience for hosted Postgres that presents a cert the
9
+ * system store doesn't verify (`{ rejectUnauthorized: false }`); pass a full
10
+ * object for stricter setups.
11
+ */
12
+ ssl?: boolean | PoolConfig['ssl'];
13
+ /** Maximum pooled clients. Default 10. */
14
+ max?: number;
15
+ /** Escape hatch: a full pg PoolConfig, merged last. */
16
+ pool?: PoolConfig;
17
+ }
18
+ /** Create a PostgreSQL database adapter. */
19
+ declare function postgresAdapter(options?: PostgresAdapterOptions): DatabaseAdapter;
20
+
21
+ export { type PostgresAdapterOptions, postgresAdapter };