@contember/bindx 0.1.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/bindx",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Type-safe data binding framework (core)",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -36,7 +36,7 @@ const BASE_ENTITY_PROPERTIES: (string | symbol)[] = [
36
36
  export const ENTITY_HANDLE_PROPERTIES = new Set<string | symbol>([
37
37
  ...BASE_ENTITY_PROPERTIES,
38
38
  // Entity-specific internals
39
- 'fieldHandleCache', 'relationHandleCache',
39
+ 'type', 'fieldHandleCache', 'relationHandleCache',
40
40
  // Internal methods (unlikely to be field names)
41
41
  'field', 'hasOne', 'hasMany', 'getSnapshot',
42
42
  'reset', 'commit',
@@ -1,126 +0,0 @@
1
- import type { BackendAdapter } from '../adapter/types.js';
2
- import type { SnapshotStore } from '../store/SnapshotStore.js';
3
- import type { ActionDispatcher } from './ActionDispatcher.js';
4
- import type { UndoManager } from '../undo/UndoManager.js';
5
- import type { SchemaRegistry } from '../schema/SchemaRegistry.js';
6
- import { type ContemberMutationResult } from '../errors/pathMapper.js';
7
- import type { MutationDataCollector } from '../persistence/types.js';
8
- export type { MutationDataCollector } from '../persistence/types.js';
9
- /**
10
- * Options for PersistenceManager
11
- */
12
- export interface PersistenceManagerOptions {
13
- /**
14
- * Custom mutation collector for building complex mutation inputs.
15
- * If provided, will be used instead of simple field diff.
16
- */
17
- mutationCollector?: MutationDataCollector;
18
- /**
19
- * UndoManager instance to block during persist operations.
20
- * When provided, undo/redo will be blocked during persistence.
21
- */
22
- undoManager?: UndoManager;
23
- /**
24
- * Schema registry for mapping server errors to fields.
25
- * Required for detailed error mapping.
26
- */
27
- schema?: SchemaRegistry;
28
- }
29
- /**
30
- * Error thrown when persist fails due to client validation errors.
31
- */
32
- export declare class ClientValidationError extends Error {
33
- constructor(entityType: string, id: string);
34
- }
35
- /**
36
- * Error thrown when persist fails due to server errors.
37
- * Contains the detailed mutation result for inspection.
38
- */
39
- export declare class PersistError extends Error {
40
- readonly entityType: string;
41
- readonly entityId: string;
42
- readonly mutationResult?: ContemberMutationResult | undefined;
43
- constructor(message: string, entityType: string, entityId: string, mutationResult?: ContemberMutationResult | undefined);
44
- }
45
- /**
46
- * PersistenceManager handles entity persistence with concurrency control.
47
- *
48
- * Key features:
49
- * - One persist operation per entity at a time (concurrent requests are queued)
50
- * - Optimistic updates (changes visible immediately)
51
- * - Abort support for cleanup
52
- * - Proper error handling with field-level error mapping
53
- * - Optional custom mutation collector for nested operations
54
- * - Blocks persist when client validation errors exist
55
- */
56
- export declare class PersistenceManager {
57
- private readonly adapter;
58
- private readonly store;
59
- private readonly dispatcher;
60
- /** Pending persist operations keyed by "entityType:id" */
61
- private readonly pending;
62
- private readonly mutationCollector?;
63
- private readonly undoManager?;
64
- private readonly schema?;
65
- constructor(adapter: BackendAdapter, store: SnapshotStore, dispatcher: ActionDispatcher, options?: PersistenceManagerOptions);
66
- /**
67
- * Gets the key for an entity.
68
- */
69
- private getKey;
70
- /**
71
- * Checks if an entity is currently being persisted.
72
- */
73
- isPersisting(entityType: string, id: string): boolean;
74
- /**
75
- * Persists an entity's changes to the backend.
76
- * Handles both create (new entities) and update (existing entities) operations.
77
- *
78
- * If already persisting, waits for the existing operation to complete.
79
- * This prevents duplicate requests and ensures consistency.
80
- *
81
- * @throws {ClientValidationError} If entity has client validation errors
82
- * @throws {PersistError} If server returns an error
83
- */
84
- persist(entityType: string, id: string): Promise<void>;
85
- /**
86
- * Performs the actual persist operation.
87
- */
88
- private doPersist;
89
- /**
90
- * Performs the create operation for new entities.
91
- */
92
- private doCreate;
93
- /**
94
- * Collects data for creating a new entity.
95
- * Excludes the temporary ID.
96
- */
97
- private collectCreateData;
98
- /**
99
- * Collects changed fields by comparing data to serverData.
100
- */
101
- private collectChanges;
102
- /**
103
- * Maps server errors from mutation result to entity fields/relations.
104
- */
105
- private mapServerErrors;
106
- /**
107
- * Cancels a pending persist operation.
108
- */
109
- cancel(entityType: string, id: string): void;
110
- /**
111
- * Cancels all pending persist operations.
112
- */
113
- cancelAll(): void;
114
- /**
115
- * Creates a new entity on the backend.
116
- */
117
- create(entityType: string, data: Record<string, unknown>): Promise<{
118
- id: string;
119
- data: Record<string, unknown>;
120
- }>;
121
- /**
122
- * Deletes an entity on the backend.
123
- */
124
- delete(entityType: string, id: string): Promise<void>;
125
- }
126
- //# sourceMappingURL=PersistenceManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PersistenceManager.d.ts","sourceRoot":"","sources":["../../src/core/PersistenceManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAG7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,EAAuB,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAO3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAGpE,YAAY,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAUpE;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,qBAAqB,CAAA;IACzC;;;OAGG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,cAAc,CAAA;CACvB;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;gBACnC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM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IAW5C;;OAEG;IACH,SAAS,IAAI,IAAI;IAOjB;;OAEG;IACG,MAAM,CACX,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAyBzD;;OAEG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAmB3D"}
@@ -1,77 +0,0 @@
1
- /**
2
- * Runtime registry for role-based schemas.
3
- *
4
- * Manages multiple schema registries (one per role) and provides
5
- * utilities for role-aware field access and query building.
6
- */
7
- import { SchemaRegistry } from '../schema/SchemaRegistry.js';
8
- import type { RoleSchemaDefinitions } from './types.js';
9
- /**
10
- * Registry that manages multiple schemas, one for each role.
11
- *
12
- * @typeParam TRoleSchemas - Map of role names to their model types
13
- *
14
- * @example
15
- * ```typescript
16
- * interface RoleSchemas {
17
- * public: { Article: PublicArticle; Author: PublicAuthor }
18
- * editor: { Article: EditorArticle; Author: EditorAuthor }
19
- * admin: { Article: AdminArticle; Author: AdminAuthor }
20
- * }
21
- *
22
- * const registry = new RoleSchemaRegistry<RoleSchemas>({
23
- * public: publicSchemaDefinition,
24
- * editor: editorSchemaDefinition,
25
- * admin: adminSchemaDefinition,
26
- * })
27
- * ```
28
- */
29
- export declare class RoleSchemaRegistry<TRoleSchemas extends {
30
- [K in keyof TRoleSchemas]: {
31
- [E: string]: object;
32
- };
33
- }> {
34
- private readonly registries;
35
- private readonly roleNames;
36
- constructor(schemas: RoleSchemaDefinitions<TRoleSchemas>);
37
- /**
38
- * Gets all registered role names.
39
- */
40
- getRoleNames(): readonly (keyof TRoleSchemas)[];
41
- /**
42
- * Gets the SchemaRegistry for a specific role.
43
- */
44
- getSchemaForRole<TRole extends keyof TRoleSchemas>(role: TRole): SchemaRegistry;
45
- /**
46
- * Checks if a role exists in the registry.
47
- */
48
- hasRole(role: keyof TRoleSchemas): boolean;
49
- /**
50
- * Gets field names available for an entity across ALL specified roles (intersection).
51
- *
52
- * @param roles - Roles to check
53
- * @param entityName - Entity to get fields for
54
- * @returns Array of field names available in ALL specified roles
55
- */
56
- getFieldsForRoles(roles: readonly (keyof TRoleSchemas)[], entityName: string): string[];
57
- /**
58
- * Gets entity names available across ALL specified roles (intersection).
59
- *
60
- * @param roles - Roles to check
61
- * @returns Array of entity names available in ALL specified roles
62
- */
63
- getEntityNamesForRoles(roles: readonly (keyof TRoleSchemas)[]): string[];
64
- /**
65
- * Checks if a field is accessible for all specified roles.
66
- */
67
- isFieldAccessible(roles: readonly (keyof TRoleSchemas)[], entityName: string, fieldName: string): boolean;
68
- /**
69
- * Checks if an entity is accessible for all specified roles.
70
- */
71
- isEntityAccessible(roles: readonly (keyof TRoleSchemas)[], entityName: string): boolean;
72
- /**
73
- * Validates all registered schemas.
74
- */
75
- validate(): void;
76
- }
77
- //# sourceMappingURL=RoleSchemaRegistry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RoleSchemaRegistry.d.ts","sourceRoot":"","sources":["../../src/roles/RoleSchemaRegistry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D,OAAO,KAAK,EAAE,qBAAqB,EAAa,MAAM,YAAY,CAAA;AAElE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,kBAAkB,CAAC,YAAY,SAAS;KAAG,CAAC,IAAI,MAAM,YAAY,GAAG;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;CAAE;IAC1G,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyC;IACpE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiC;gBAE/C,OAAO,EAAE,qBAAqB,CAAC,YAAY,CAAC;IAUxD;;OAEG;IACH,YAAY,IAAI,SAAS,CAAC,MAAM,YAAY,CAAC,EAAE;IAI/C;;OAEG;IACH,gBAAgB,CAAC,KAAK,SAAS,MAAM,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,cAAc;IAQ/E;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,YAAY,GAAG,OAAO;IAI1C;;;;;;OAMG;IACH,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,YAAY,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;IA6BvF;;;;;OAKG;IACH,sBAAsB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,YAAY,CAAC,EAAE,GAAG,MAAM,EAAE;IA6BxE;;OAEG;IACH,iBAAiB,CAChB,KAAK,EAAE,SAAS,CAAC,MAAM,YAAY,CAAC,EAAE,EACtC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GACf,OAAO;IAgBV;;OAEG;IACH,kBAAkB,CACjB,KAAK,EAAE,SAAS,CAAC,MAAM,YAAY,CAAC,EAAE,EACtC,UAAU,EAAE,MAAM,GAChB,OAAO;IAWV;;OAEG;IACH,QAAQ,IAAI,IAAI;CAWhB"}
@@ -1,11 +0,0 @@
1
- /**
2
- * Role-based schema module for Bindx.
3
- *
4
- * Provides type-safe role-aware entity access with schema narrowing.
5
- *
6
- * @packageDocumentation
7
- */
8
- export type { UnionToIntersection, RoleSchemaMap, RoleNames, IntersectRoleSchemas, IntersectSchemaEntities, PickCommonProperties, EntityForRoles, SchemaForRole, EntityNamesForRoles, RoleSchemaDefinitions, RoleBindxConfig, RolesAreSubset, RequireRoleSubset, AssertRoleCompatibility, SingleSchemaRoles, IsSingleSchema, AllRoles, DefaultRole, } from './types.js';
9
- export { isValidRole, DEFAULT_ROLE } from './types.js';
10
- export { RoleSchemaRegistry } from './RoleSchemaRegistry.js';
11
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/roles/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,EACX,mBAAmB,EACnB,aAAa,EACb,SAAS,EACT,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,WAAW,GACX,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA"}
@@ -1,242 +0,0 @@
1
- /**
2
- * Role-based schema types for Bindx.
3
- *
4
- * Provides type-safe role-aware entity access with schema narrowing
5
- * based on user roles.
6
- */
7
- import type { SchemaDefinition, EntitySchemaDef } from '../schema/types.js';
8
- /**
9
- * Converts a union type to an intersection type.
10
- *
11
- * @example
12
- * ```typescript
13
- * type Union = { a: string } | { b: number }
14
- * type Intersection = UnionToIntersection<Union>
15
- * // Result: { a: string } & { b: number }
16
- * ```
17
- */
18
- export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
19
- /**
20
- * Extracts keys that exist in ALL members of a union type.
21
- * Uses distributive conditional to check each union member.
22
- *
23
- * @example
24
- * ```typescript
25
- * type A = { id: string; title: string; content: string }
26
- * type B = { id: string; title: string; notes: string }
27
- * type Common = KeysInAll<A | B>
28
- * // Result: 'id' | 'title'
29
- * ```
30
- */
31
- type KeysInAll<T, K = keyof T> = T extends unknown ? K extends keyof T ? K : never : never;
32
- /**
33
- * Picks only the common properties from a union of object types.
34
- * Returns an object with only keys that exist in ALL union members.
35
- * Property values are unions of the original types.
36
- *
37
- * @example
38
- * ```typescript
39
- * type A = { id: string; title: string; content: string }
40
- * type B = { id: string; title: string; notes: string }
41
- * type Common = PickCommonProperties<A | B>
42
- * // Result: { id: string; title: string }
43
- * ```
44
- */
45
- export type PickCommonProperties<T> = {
46
- [K in KeysInAll<T>]: T extends {
47
- readonly [P in K]: infer V;
48
- } ? V : never;
49
- };
50
- /**
51
- * Applies PickCommonProperties to each entity in a schema union.
52
- * For a union of schemas, extracts only common entity names and their common properties.
53
- *
54
- * @example
55
- * ```typescript
56
- * type SchemaA = { Article: { id: string; title: string }; Author: { id: string } }
57
- * type SchemaB = { Article: { id: string; content: string }; Author: { id: string } }
58
- * type Common = IntersectSchemaEntities<SchemaA | SchemaB>
59
- * // Result: { Article: { id: string }; Author: { id: string } }
60
- * ```
61
- */
62
- export type IntersectSchemaEntities<TSchemaUnion> = {
63
- [K in KeysInAll<TSchemaUnion>]: PickCommonProperties<TSchemaUnion extends {
64
- readonly [P in K]: infer V;
65
- } ? V : never>;
66
- };
67
- /**
68
- * Base constraint for role schema maps.
69
- * Uses a mapped type to allow interfaces without index signatures.
70
- */
71
- export type RoleSchemasConstraint = {
72
- [role: string]: {
73
- [entity: string]: object;
74
- };
75
- };
76
- /**
77
- * Mapping of role names to their respective schema types.
78
- *
79
- * @example
80
- * ```typescript
81
- * interface MyRoleSchemas {
82
- * public: PublicSchema
83
- * editor: EditorSchema
84
- * admin: AdminSchema
85
- * }
86
- * ```
87
- */
88
- export type RoleSchemaMap<TRoleSchemas> = {
89
- [K in keyof TRoleSchemas]: TRoleSchemas[K];
90
- };
91
- /**
92
- * Extracts all role names from a role schema map.
93
- */
94
- export type RoleNames<TRoleSchemas> = keyof TRoleSchemas & string;
95
- /**
96
- * Intersects schemas from multiple roles.
97
- * Used when multiple roles are specified - returns fields accessible to ALL roles.
98
- *
99
- * This performs a TRUE property intersection: only properties that exist in ALL
100
- * role schemas are accessible. This is different from TypeScript's & operator
101
- * which creates a type with ALL properties from all schemas.
102
- *
103
- * @example
104
- * ```typescript
105
- * interface EditorSchema { Article: { id: string; title: string; content: string } }
106
- * interface ReviewerSchema { Article: { id: string; title: string; status: string } }
107
- *
108
- * type Combined = IntersectRoleSchemas<{ editor: EditorSchema; reviewer: ReviewerSchema }, ['editor', 'reviewer']>
109
- * // Result: { Article: { id: string; title: string } } (only common properties)
110
- * ```
111
- */
112
- export type IntersectRoleSchemas<TRoleSchemas, TRoles extends readonly (keyof TRoleSchemas)[]> = IntersectSchemaEntities<TRoleSchemas[TRoles[number]]>;
113
- /**
114
- * Gets the entity type for specific roles.
115
- *
116
- * @typeParam TRoleSchemas - Map of role names to their schemas
117
- * @typeParam TRoles - Tuple of role names to intersect
118
- * @typeParam TEntityName - Name of the entity to extract
119
- */
120
- export type EntityForRoles<TRoleSchemas, TRoles extends readonly (keyof TRoleSchemas)[], TEntityName extends string> = TEntityName extends keyof IntersectRoleSchemas<TRoleSchemas, TRoles> ? IntersectRoleSchemas<TRoleSchemas, TRoles>[TEntityName] : never;
121
- /**
122
- * Gets the schema type for a specific role.
123
- */
124
- export type SchemaForRole<TRoleSchemas, TRole extends keyof TRoleSchemas> = TRoleSchemas[TRole];
125
- /**
126
- * Extracts all entity names that exist in ALL specified roles.
127
- */
128
- export type EntityNamesForRoles<TRoleSchemas, TRoles extends readonly (keyof TRoleSchemas)[]> = keyof IntersectRoleSchemas<TRoleSchemas, TRoles> & string;
129
- /**
130
- * Maps role names to their schema definitions (runtime structure).
131
- */
132
- export type RoleSchemaDefinitions<TRoleSchemas> = {
133
- [K in keyof TRoleSchemas]: TRoleSchemas[K] extends {
134
- [E: string]: object;
135
- } ? SchemaDefinition<TRoleSchemas[K]> : never;
136
- };
137
- /**
138
- * Configuration for role-aware bindx.
139
- */
140
- export interface RoleBindxConfig<TRoleSchemas> {
141
- /**
142
- * Schema definitions for each role.
143
- */
144
- readonly schemas: RoleSchemaDefinitions<TRoleSchemas>;
145
- /**
146
- * Function to check if the current user has a specific role.
147
- * Used at runtime to determine which branches to render.
148
- */
149
- readonly hasRole: (role: keyof TRoleSchemas) => boolean;
150
- /**
151
- * Current roles of the user.
152
- * Used for query building - determines which fields to fetch.
153
- */
154
- readonly currentRoles: readonly (keyof TRoleSchemas)[];
155
- }
156
- /**
157
- * Check if TRequired roles are a subset of TAvailable roles.
158
- * Returns true if every role in TRequired exists in TAvailable.
159
- *
160
- * @example
161
- * ```typescript
162
- * type Test1 = RolesAreSubset<['admin'], ['editor', 'admin']> // true
163
- * type Test2 = RolesAreSubset<['admin'], ['editor']> // false
164
- * type Test3 = RolesAreSubset<[], ['editor']> // true (empty is subset of all)
165
- * ```
166
- */
167
- export type RolesAreSubset<TRequired extends readonly string[], TAvailable extends readonly string[]> = TRequired extends readonly [] ? true : TRequired extends readonly [infer First extends string, ...infer Rest extends string[]] ? First extends TAvailable[number] ? RolesAreSubset<Rest, TAvailable> : false : boolean;
168
- /**
169
- * Enforces that TRequired roles must be a subset of TAvailable roles.
170
- * Returns TRequired if valid, never if not.
171
- *
172
- * @example
173
- * ```typescript
174
- * type Valid = RequireRoleSubset<['admin'], ['editor', 'admin']> // ['admin']
175
- * type Invalid = RequireRoleSubset<['admin'], ['editor']> // never
176
- * ```
177
- */
178
- export type RequireRoleSubset<TRequired extends readonly string[], TAvailable extends readonly string[]> = RolesAreSubset<TRequired, TAvailable> extends true ? TRequired : never;
179
- /**
180
- * Asserts that TComponentRoles are compatible with TAvailableRoles.
181
- * Used for type-level validation when using role-aware components.
182
- *
183
- * When component requires ['admin'] and scope has ['editor', 'admin']:
184
- * - ['admin'] ⊆ ['editor', 'admin'] = true (compatible)
185
- *
186
- * When component requires ['admin'] and scope has ['editor']:
187
- * - ['admin'] ⊆ ['editor'] = false (incompatible)
188
- */
189
- export type AssertRoleCompatibility<TComponentRoles extends readonly string[], TAvailableRoles extends readonly string[]> = RolesAreSubset<TComponentRoles, TAvailableRoles> extends true ? TComponentRoles : ['Error: Component requires roles', TComponentRoles, 'but available roles are', TAvailableRoles];
190
- /**
191
- * Type predicate to check if a value is a valid role.
192
- */
193
- export declare function isValidRole<TRoleSchemas>(roleSchemas: TRoleSchemas, role: unknown): role is keyof TRoleSchemas;
194
- export type { SchemaDefinition, EntitySchemaDef };
195
- /**
196
- * Wraps a single schema as a role schema map with a default role.
197
- * This allows single-schema usage to be a special case of role-aware bindx.
198
- *
199
- * @example
200
- * ```typescript
201
- * type Models = { Article: ArticleType; Author: AuthorType }
202
- *
203
- * // Single schema becomes:
204
- * type RoleSchemas = SingleSchemaRoles<Models>
205
- * // = { _default: { Article: ArticleType; Author: AuthorType } }
206
- *
207
- * // IntersectRoleSchemas<RoleSchemas, ['_default']> = Models
208
- * ```
209
- */
210
- export type SingleSchemaRoles<TModels extends Record<string, object>> = {
211
- _default: TModels;
212
- };
213
- /**
214
- * Check if TRoleSchemas represents a single-schema case.
215
- * Returns true if the only key is '_default'.
216
- *
217
- * @example
218
- * ```typescript
219
- * type Test1 = IsSingleSchema<{ _default: Models }> // true
220
- * type Test2 = IsSingleSchema<{ admin: AdminModels; public: PublicModels }> // false
221
- * ```
222
- */
223
- export type IsSingleSchema<TRoleSchemas> = keyof TRoleSchemas extends '_default' ? '_default' extends keyof TRoleSchemas ? true : false : false;
224
- /**
225
- * Gets all role names from a role schema map as a readonly array type.
226
- *
227
- * @example
228
- * ```typescript
229
- * type Roles = AllRoles<{ admin: AdminModels; public: PublicModels }>
230
- * // = readonly ('admin' | 'public')[]
231
- * ```
232
- */
233
- export type AllRoles<TRoleSchemas> = readonly (keyof TRoleSchemas & string)[];
234
- /**
235
- * Default role name for single-schema case.
236
- */
237
- export declare const DEFAULT_ROLE: "_default";
238
- /**
239
- * Type for the default role name.
240
- */
241
- export type DefaultRole = typeof DEFAULT_ROLE;
242
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/roles/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAM3E;;;;;;;;;GASG;AACH,MAAM,MAAM,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