@craft-ng/core 0.1.2 → 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/fesm2022/craft-ng-core.mjs +159 -1
- package/fesm2022/craft-ng-core.mjs.map +1 -1
- package/package.json +1 -1
- package/types/craft-ng-core.d.ts +126 -1
package/package.json
CHANGED
package/types/craft-ng-core.d.ts
CHANGED
|
@@ -9265,5 +9265,130 @@ declare function insertFormSubmit<FormValue, MutationValue, MutationParams, Muta
|
|
|
9265
9265
|
submitExceptions: Signal<ToSubmitExceptions<InsertMetaInCraftExceptionIfExists<MutationExceptions['params'], 'params', MutationIdentifier> | InsertMetaInCraftExceptionIfExists<MutationExceptions['loader'], 'loader', MutationIdentifier>, SuccessExceptions, ErrorExceptions, ExceptionExceptions, FormIdentifier>[]>;
|
|
9266
9266
|
}>;
|
|
9267
9267
|
|
|
9268
|
-
|
|
9268
|
+
type ArrayObjectDeepPath<State extends object> = ObjectDeepPath<State> extends infer Path ? Path extends string ? AccessTypeObjectPropertyByDottedPath<State, DottedPathPathToTuple<Path>> extends Array<any> ? Path : never : never : never;
|
|
9269
|
+
type DottedPathToCamel<Path extends string> = Path extends `${infer Head}.${infer Tail}` ? `${Head}${Capitalize<DottedPathToCamel<Tail>>}` : Path;
|
|
9270
|
+
type EntitiesUtilsToMap<EntityHelperFns, Entity, K, HasStateIdentifier, StateIdentifier, HasPath, Path, Acc = {}> = EntityHelperFns extends [infer First, ...infer Rest] ? First extends (data: infer Payload) => infer R ? R extends EntitiesUtilBrand<infer Name> ? EntitiesUtilsToMap<Rest, Entity, K, HasStateIdentifier, StateIdentifier, HasPath, Path, Acc & {
|
|
9271
|
+
[key in Name as `${HasPath extends true ? `${DottedPathToCamel<Path & string>}${Capitalize<string & key>}` : key & string}`]: (payload: MergeObject$1<{
|
|
9272
|
+
[key in Exclude<keyof Payload, 'identifier'> as `${key extends 'entities' ? never : key & string}`]: key extends 'entity' ? Entity : key extends 'ids' ? K[] : key extends 'newEntities' ? Entity[] : `Not implemented mapping for ${key & string}`;
|
|
9273
|
+
}, HasStateIdentifier extends true ? {
|
|
9274
|
+
select: StateIdentifier extends (...args: any) => infer R ? R : never;
|
|
9275
|
+
} : {}>) => void;
|
|
9276
|
+
}> : 'No EntitiesBranded Name Detected' : false : Acc;
|
|
9277
|
+
/**
|
|
9278
|
+
* Creates an insertion that adds entity collection management methods to state, query, or queryParam primitives.
|
|
9279
|
+
*
|
|
9280
|
+
* Provides type-safe manipulation of arrays of entities with operations like add, remove, update, and upsert.
|
|
9281
|
+
* Supports nested properties via dot notation paths and custom entity identifiers.
|
|
9282
|
+
*
|
|
9283
|
+
* @template State - The state type (array or object containing arrays)
|
|
9284
|
+
* @template K - The type of entity identifiers (string or number)
|
|
9285
|
+
* @template PreviousInsertionsOutputs - Combined outputs from previous insertions
|
|
9286
|
+
* @template EntityHelperFns - Tuple type of entity utility functions to expose
|
|
9287
|
+
* @template StateIdentifier - Type of identifier function for parallel queries
|
|
9288
|
+
* @template Path - Dot-notation path to nested array (inferred from state structure)
|
|
9289
|
+
*
|
|
9290
|
+
* @param config - Configuration object
|
|
9291
|
+
* @param config.methods - Array of entity utility functions (addOne, removeOne, updateOne, etc.) to expose as methods
|
|
9292
|
+
* @param config.identifier - Optional custom function to extract unique ID from entities.
|
|
9293
|
+
* Defaults to `entity.id` for objects or `entity` for primitives
|
|
9294
|
+
* @param config.path - Optional dot-notation path to nested array property (e.g., 'catalog.products').
|
|
9295
|
+
* Method names are prefixed with camelCase path when provided
|
|
9296
|
+
*
|
|
9297
|
+
* @returns Insertion function that adds entity management methods to the primitive
|
|
9298
|
+
*
|
|
9299
|
+
* @example
|
|
9300
|
+
* // Basic usage with primitives
|
|
9301
|
+
* const tags = state(
|
|
9302
|
+
* [] as string[],
|
|
9303
|
+
* insertEntities({
|
|
9304
|
+
* methods: [addOne, addMany, removeOne],
|
|
9305
|
+
* })
|
|
9306
|
+
* );
|
|
9307
|
+
* tags.addOne({ entity: 'typescript' });
|
|
9308
|
+
* tags.addMany({ newEntities: ['angular', 'signals'] });
|
|
9309
|
+
*
|
|
9310
|
+
* @example
|
|
9311
|
+
* // With objects having default id property
|
|
9312
|
+
* interface Product {
|
|
9313
|
+
* id: string;
|
|
9314
|
+
* name: string;
|
|
9315
|
+
* price: number;
|
|
9316
|
+
* }
|
|
9317
|
+
* const products = state(
|
|
9318
|
+
* [] as Product[],
|
|
9319
|
+
* insertEntities({
|
|
9320
|
+
* methods: [addOne, setOne, removeOne],
|
|
9321
|
+
* })
|
|
9322
|
+
* );
|
|
9323
|
+
* products.addOne({ entity: { id: '1', name: 'Laptop', price: 999 } });
|
|
9324
|
+
*
|
|
9325
|
+
* @example
|
|
9326
|
+
* // With custom identifier
|
|
9327
|
+
* interface User {
|
|
9328
|
+
* uuid: string;
|
|
9329
|
+
* name: string;
|
|
9330
|
+
* }
|
|
9331
|
+
* const users = state(
|
|
9332
|
+
* [] as User[],
|
|
9333
|
+
* insertEntities({
|
|
9334
|
+
* methods: [setOne, removeOne],
|
|
9335
|
+
* identifier: (user) => user.uuid,
|
|
9336
|
+
* })
|
|
9337
|
+
* );
|
|
9338
|
+
*
|
|
9339
|
+
* @example
|
|
9340
|
+
* // With nested path
|
|
9341
|
+
* interface Catalog {
|
|
9342
|
+
* total: number;
|
|
9343
|
+
* products: Array<{ id: string; name: string }>;
|
|
9344
|
+
* }
|
|
9345
|
+
* const catalog = state(
|
|
9346
|
+
* { total: 0, products: [] } as Catalog,
|
|
9347
|
+
* insertEntities({
|
|
9348
|
+
* methods: [addMany, removeOne],
|
|
9349
|
+
* path: 'products',
|
|
9350
|
+
* })
|
|
9351
|
+
* );
|
|
9352
|
+
* catalog.productsAddMany({ newEntities: [{ id: '1', name: 'Item' }] });
|
|
9353
|
+
*
|
|
9354
|
+
* @example
|
|
9355
|
+
* // With parallel queries
|
|
9356
|
+
* const userQuery = query(
|
|
9357
|
+
* {
|
|
9358
|
+
* params: () => 'userId',
|
|
9359
|
+
* identifier: (params) => params,
|
|
9360
|
+
* loader: async ({ params }) => fetchUserPosts(params),
|
|
9361
|
+
* },
|
|
9362
|
+
* insertEntities({
|
|
9363
|
+
* methods: [addOne],
|
|
9364
|
+
* })
|
|
9365
|
+
* );
|
|
9366
|
+
* userQuery.addOne({
|
|
9367
|
+
* select: 'user-123', // Target specific query instance
|
|
9368
|
+
* entity: { id: 'post-1', title: 'New Post' },
|
|
9369
|
+
* });
|
|
9370
|
+
*
|
|
9371
|
+
* @see {@link https://github.com/ng-angular-stack/ng-craft/blob/main/apps/docs/insertions/insert-entities.md | insertEntities Documentation}
|
|
9372
|
+
*/
|
|
9373
|
+
declare function insertEntities<State, K extends string | number, PreviousInsertionsOutputs, const EntityHelperFns extends unknown[], StateIdentifier, const Path = State extends Array<infer Entity> ? never : State extends object ? ArrayObjectDeepPath<State> : never, StateType = State extends Array<infer R> ? R : State extends object ? Path extends string ? AccessTypeObjectPropertyByDottedPath<State, DottedPathPathToTuple<Path>> extends Array<infer Entity> ? Entity : never : never : never, HasStateIdentifier = [unknown] extends [StateIdentifier] ? false : StateIdentifier extends (...args: any) => infer R ? [unknown] extends [R] ? false : true : false, IsEntityIdentifierOptional = StateType extends {
|
|
9374
|
+
id: NoInfer<K>;
|
|
9375
|
+
} ? true : StateType extends string | number ? true : false>(config: {
|
|
9376
|
+
methods: EntityHelperFns;
|
|
9377
|
+
} & MergeObject$1<IsEntityIdentifierOptional extends true ? {
|
|
9378
|
+
identifier?: IdSelector<NoInfer<StateType>, NoInfer<K>>;
|
|
9379
|
+
} : {
|
|
9380
|
+
identifier: IdSelector<NoInfer<StateType>, NoInfer<K>>;
|
|
9381
|
+
}, [
|
|
9382
|
+
Path
|
|
9383
|
+
] extends [never] ? {} : {
|
|
9384
|
+
path: Path;
|
|
9385
|
+
}>): (context: InsertionStateFactoryContext<State, PreviousInsertionsOutputs> & {
|
|
9386
|
+
identifier?: StateIdentifier;
|
|
9387
|
+
}) => Prettify<EntitiesUtilsToMap<EntityHelperFns, StateType, K, HasStateIdentifier, StateIdentifier, "path" extends keyof typeof config ? true : false, Path>> & {
|
|
9388
|
+
testState: State;
|
|
9389
|
+
testPath: Path;
|
|
9390
|
+
testHasPath: "path" extends keyof typeof config ? true : false;
|
|
9391
|
+
};
|
|
9392
|
+
|
|
9393
|
+
export { CRAFT_EXCEPTION_SYMBOL, EXTERNALLY_PROVIDED, EmptyContext, GlobalPersisterHandlerService, STORE_CONFIG_TOKEN, SourceBrand, SourceBranded, VALIDATOR_OUTPUT_SYMBOL, addMany, addOne, afterRecomputation, asyncProcess, cAsyncValidate, cAsyncValidator, cEmail, cMax, cMaxLength, cMin, cMinLength, cPattern, cRequired, cValidate, cValidator, capitalize, computedIds, computedSource, computedTotal, contract, craft, craftAsyncProcesses, craftComputedStates, craftException, craftFactoryEntries, craftInject, craftInputs, craftMutations, craftQuery, craftQueryParam, craftQueryParams, craftSetAllQueriesParamsStandalone, craftSources, craftState, createMethodHandlers, fromEventToSource$, injectService, insertEntities, insertForm, insertFormAttributes, insertFormSubmit, insertLocalStoragePersister, insertNoopTypingAnchor, insertPaginationPlaceholderData, insertReactOnMutation, insertSelect, insertSelectFormTree, isCraftException, isSource, linkedSource, localStoragePersister, map, mapOne, mutation, on$, partialContext, query, queryParam, reactiveWritableSignal, removeAll, removeMany, removeOne, resourceById, serializeQueryParams, serializedQueryParamsObjectToString, setAll, setMany, setOne, signalSource, source$, sourceFromEvent, stackedSource, state, toInject, toSource, toggleMany, toggleOne, updateMany, updateOne, upsertMany, upsertOne, validatedFormValueSymbol };
|
|
9269
9394
|
export type { AnyCraftException, AsyncProcessExceptionConstraints, AsyncProcessOutput, AsyncProcessRef, CEmailException, CMaxException, CMaxLengthException, CMinException, CMinLengthException, CRequiredException, CloudProxy, CloudProxySource, ContextConstraints, ContextInput, CraftException, CraftExceptionMeta, CraftExceptionResult, CraftFactory, CraftFactoryEntries, CraftFactoryUtility, DeferredExtract, EntitiesUtilBrand, EqualParams, ExcludeByCode, ExcludeCommonKeys, ExposedStateInsertions, ExtractCodeFromCraftResultUnion, ExtractCraftException, ExtractSignalPropsAndMethods, FilterMethodsBoundToSources, FilterPrivateFields, FilterSource, FlatRecord, FormNodeExceptions, FormWithInsertions, FromEventToSource$, HasChild$1 as HasChild, HasKeys, IdSelector, Identifier, InferInjectedType, InjectService2InsertionContext, InjectService2InsertionFactory, InjectService2Insertions, InjectService2Output, InjectService2Public, InsertFormAttributesConfig, InsertFormAttributesContext, InsertMetaInCraftExceptionIfExists, InsertionFormFactoryContext, InsertionsFormFactory, IsAny, IsEmptyObject, IsNever, IsUnknown, MakeOptionalPropertiesRequired$1 as MakeOptionalPropertiesRequired, MergeObject$1 as MergeObject, MergeObjects$1 as MergeObjects, MergeTwoContexts, MutationOutput, MutationRef, Not, OmitStrict, PartialContext, Prettify, QueryOutput, QueryParamConfig, QueryParamExceptions, QueryParamNavigationOptions$1 as QueryParamNavigationOptions, QueryParamOutput, QueryParamsToState, QueryRef, ReadonlySource, ReadonlySource$, RemoveIndexSignature, ReplaceStoreConfigToken, ResourceByIdHandler, ResourceByIdLikeAsyncProcessExceptions, ResourceByIdLikeExceptions, ResourceByIdLikeMutationExceptions, ResourceByIdLikeMutationRef, ResourceByIdLikeQueryRef, ResourceByIdRef, ResourceLikeAsyncProcessExceptions, ResourceLikeExceptions, ResourceLikeMutationExceptions, ResourceLikeMutationRef, ResourceLikeQueryRef, SignalSource, Source$, SourceFromEvent, SourceSetterMethods, SourceSubscribe, SpecificCraftQueryParamOutputs, SpecificCraftQueryParamsOutputs, StackSource, StateOutput, StoreConfigConstraints, StoreConfigToken, StripCraftException, ToConnectableMethodFromInject, ToConnectableSourceFromInject, ToInjectBindings, UnionToIntersection$1 as UnionToIntersection, UnionToTuple$1 as UnionToTuple, Update, ValidatedFormValue, ValidatorBindingContext, ValidatorModel, ValidatorOutput, ValidatorPending, ValidatorSuccess, ValidatorType, ValidatorUtilBrand };
|