@spoosh/core 0.17.1 → 0.18.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/dist/index.d.mts CHANGED
@@ -2146,22 +2146,25 @@ declare function objectToUrlEncoded(obj: Record<string, unknown>): string;
2146
2146
 
2147
2147
  declare function sortObjectKeys(obj: unknown, seen?: WeakSet<object>): unknown;
2148
2148
 
2149
- type TagMode = "all" | "self" | "none";
2150
- type TagModeInArray = "all" | "self";
2151
2149
  /**
2152
2150
  * Common tag options used across plugins and operations.
2153
2151
  */
2154
2152
  type TagOptions = {
2155
2153
  /**
2156
- * Unified tag option (follows invalidation pattern)
2157
- * - String: mode only ('all' | 'self' | 'none')
2158
- * - Array: custom tags only OR [mode keyword mixed with custom tags]
2159
- * - If array contains 'all' or 'self', it's treated as mode + tags
2160
- * - Otherwise, it's custom tags only (replaces auto-generated tags)
2161
- * - 'none' keyword should NOT be used in arrays (use string 'none' instead)
2154
+ * Custom tags to use instead of auto-generated tag.
2155
+ * Can be a single tag string or an array of tags.
2162
2156
  */
2163
- tags?: TagMode | (TagModeInArray | (string & {}))[];
2157
+ tags?: string | string[];
2164
2158
  };
2159
+ /**
2160
+ * Resolves tags for a cache entry.
2161
+ * Returns a single tag by default (the joined path), or custom tags if provided.
2162
+ * All tags are normalized (leading "/" removed) for consistency.
2163
+ *
2164
+ * @param options - Tag options containing optional custom tags
2165
+ * @param resolvedPath - The resolved path segments
2166
+ * @returns Array of normalized tags
2167
+ */
2165
2168
  declare function resolveTags(options: TagOptions | undefined, resolvedPath: string[]): string[];
2166
2169
  declare function resolvePath(path: string[], params: Record<string, string | number> | undefined): string[];
2167
2170
  /**
@@ -2180,6 +2183,31 @@ declare function resolvePath(path: string[], params: Record<string, string | num
2180
2183
  */
2181
2184
  declare function resolvePathString(path: string, params: Record<string, string | number> | undefined): string;
2182
2185
 
2186
+ /**
2187
+ * Normalizes a tag or pattern by removing leading slashes.
2188
+ * Ensures consistency between "/hello" and "hello".
2189
+ */
2190
+ declare function normalizeTag(tag: string): string;
2191
+ /**
2192
+ * Checks if an entry's tag matches a given invalidation pattern.
2193
+ * Both tag and pattern are normalized (leading "/" removed) before comparison.
2194
+ *
2195
+ * @param entryTag - The tag from a cache entry (e.g., "posts", "posts/1", "posts/1/comments")
2196
+ * @param pattern - The pattern to match against:
2197
+ * - "posts" - Exact match only
2198
+ * - "posts/*" - Children only (matches posts/1, posts/1/comments, but NOT posts)
2199
+ * @returns true if the entry tag matches the pattern
2200
+ */
2201
+ declare function matchTag(entryTag: string, pattern: string): boolean;
2202
+ /**
2203
+ * Checks if an entry's tag matches any of the given invalidation patterns.
2204
+ *
2205
+ * @param entryTag - The tag from a cache entry
2206
+ * @param patterns - Array of patterns to match against
2207
+ * @returns true if the entry tag matches any of the patterns
2208
+ */
2209
+ declare function matchTags(entryTag: string, patterns: string[]): boolean;
2210
+
2183
2211
  declare const isNetworkError: (err: unknown) => boolean;
2184
2212
  declare const isAbortError: (err: unknown) => boolean;
2185
2213
 
@@ -2199,6 +2227,13 @@ declare function clone<T>(value: T, seen?: WeakMap<WeakKey, any>): T;
2199
2227
  */
2200
2228
  declare function createTracer(plugin: string, trace: Trace | undefined): RequestTracer;
2201
2229
 
2230
+ /**
2231
+ * Generates a UUID v4 string.
2232
+ * Uses crypto.randomUUID() when available (secure contexts),
2233
+ * falls back to Math.random() for non-secure contexts (HTTP).
2234
+ */
2235
+ declare function generateUUID(): string;
2236
+
2202
2237
  type ProxyHandlerConfig<TOptions = SpooshOptions> = {
2203
2238
  baseUrl: string;
2204
2239
  defaultOptions: TOptions;
@@ -2605,4 +2640,4 @@ interface CreateSubscriptionControllerOptions<TData, TError> {
2605
2640
  }
2606
2641
  declare function createSubscriptionController<TData, TError>(options: CreateSubscriptionControllerOptions<TData, TError>): SubscriptionController<TData, TError>;
2607
2642
 
2608
- export { type AnyMethod, type AnyRequestOptions, type ApiContext, type ApiPluginExecutor, type ApiResolvers, type ApiSchema, type BaseSubscriptionResponse, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type CreateSubscriptionControllerOptions, type DataAwareCallback, type DataAwareTransform, type DataChangeCallback, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExecuteOptions, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type ExtractTriggerBody, type ExtractTriggerParams, type ExtractTriggerQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasSubscriptionMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteNextContext, type InfinitePage, type InfinitePageStatus, type InfinitePrevContext, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InfiniteTriggerOptions, type LifecyclePhase, type MergePluginApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginFactory, type PluginHandler, type PluginInternalRegistry, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type QueueController, type QueueControllerConfig, type QueueControllerContext, type QueueItem, type QueueItemStatus, type QueueSelectorClient, type QueueStats, type QueueTriggerInput, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, Semaphore, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type SpooshSubscriptionMethodRegistry, type SpooshTransport, type SpooshTransportRegistry, type StandaloneEvent, type StateManager, type StripPrefix, type Subscriber, type SubscriptionAccumulateEvent, type SubscriptionAdapter, type SubscriptionClient, type SubscriptionConnectEvent, type SubscriptionConnectedEvent, type SubscriptionContext, type SubscriptionController, type SubscriptionDisconnectEvent, type SubscriptionErrorEvent, type SubscriptionHandle, type SubscriptionMessageEvent, type SubscriptionMethod, type SubscriptionPaths, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportName, type TransportOption, type TransportOptionsMap, type TransportResponse, type TypedPluginContext, type TypedPluginDefinition, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, composeAdapter, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createQueueController, createSelectorProxy, createSpooshPlugin, createStateManager, createSubscriptionController, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateSelfTagFromKey, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, removeHeaderKeys, resolveHeadersToRecord, resolvePath, resolvePathString, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
2643
+ export { type AnyMethod, type AnyRequestOptions, type ApiContext, type ApiPluginExecutor, type ApiResolvers, type ApiSchema, type BaseSubscriptionResponse, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type CreateSubscriptionControllerOptions, type DataAwareCallback, type DataAwareTransform, type DataChangeCallback, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExecuteOptions, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type ExtractTriggerBody, type ExtractTriggerParams, type ExtractTriggerQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasSubscriptionMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteNextContext, type InfinitePage, type InfinitePageStatus, type InfinitePrevContext, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InfiniteTriggerOptions, type LifecyclePhase, type MergePluginApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginFactory, type PluginHandler, type PluginInternalRegistry, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type QueueController, type QueueControllerConfig, type QueueControllerContext, type QueueItem, type QueueItemStatus, type QueueSelectorClient, type QueueStats, type QueueTriggerInput, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, Semaphore, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type SpooshSubscriptionMethodRegistry, type SpooshTransport, type SpooshTransportRegistry, type StandaloneEvent, type StateManager, type StripPrefix, type Subscriber, type SubscriptionAccumulateEvent, type SubscriptionAdapter, type SubscriptionClient, type SubscriptionConnectEvent, type SubscriptionConnectedEvent, type SubscriptionContext, type SubscriptionController, type SubscriptionDisconnectEvent, type SubscriptionErrorEvent, type SubscriptionHandle, type SubscriptionMessageEvent, type SubscriptionMethod, type SubscriptionPaths, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportName, type TransportOption, type TransportOptionsMap, type TransportResponse, type TypedPluginContext, type TypedPluginDefinition, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, composeAdapter, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createQueueController, createSelectorProxy, createSpooshPlugin, createStateManager, createSubscriptionController, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateSelfTagFromKey, generateTags, generateUUID, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, matchTag, matchTags, mergeHeaders, normalizeTag, objectToFormData, objectToUrlEncoded, removeHeaderKeys, resolveHeadersToRecord, resolvePath, resolvePathString, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
package/dist/index.d.ts CHANGED
@@ -2146,22 +2146,25 @@ declare function objectToUrlEncoded(obj: Record<string, unknown>): string;
2146
2146
 
2147
2147
  declare function sortObjectKeys(obj: unknown, seen?: WeakSet<object>): unknown;
2148
2148
 
2149
- type TagMode = "all" | "self" | "none";
2150
- type TagModeInArray = "all" | "self";
2151
2149
  /**
2152
2150
  * Common tag options used across plugins and operations.
2153
2151
  */
2154
2152
  type TagOptions = {
2155
2153
  /**
2156
- * Unified tag option (follows invalidation pattern)
2157
- * - String: mode only ('all' | 'self' | 'none')
2158
- * - Array: custom tags only OR [mode keyword mixed with custom tags]
2159
- * - If array contains 'all' or 'self', it's treated as mode + tags
2160
- * - Otherwise, it's custom tags only (replaces auto-generated tags)
2161
- * - 'none' keyword should NOT be used in arrays (use string 'none' instead)
2154
+ * Custom tags to use instead of auto-generated tag.
2155
+ * Can be a single tag string or an array of tags.
2162
2156
  */
2163
- tags?: TagMode | (TagModeInArray | (string & {}))[];
2157
+ tags?: string | string[];
2164
2158
  };
2159
+ /**
2160
+ * Resolves tags for a cache entry.
2161
+ * Returns a single tag by default (the joined path), or custom tags if provided.
2162
+ * All tags are normalized (leading "/" removed) for consistency.
2163
+ *
2164
+ * @param options - Tag options containing optional custom tags
2165
+ * @param resolvedPath - The resolved path segments
2166
+ * @returns Array of normalized tags
2167
+ */
2165
2168
  declare function resolveTags(options: TagOptions | undefined, resolvedPath: string[]): string[];
2166
2169
  declare function resolvePath(path: string[], params: Record<string, string | number> | undefined): string[];
2167
2170
  /**
@@ -2180,6 +2183,31 @@ declare function resolvePath(path: string[], params: Record<string, string | num
2180
2183
  */
2181
2184
  declare function resolvePathString(path: string, params: Record<string, string | number> | undefined): string;
2182
2185
 
2186
+ /**
2187
+ * Normalizes a tag or pattern by removing leading slashes.
2188
+ * Ensures consistency between "/hello" and "hello".
2189
+ */
2190
+ declare function normalizeTag(tag: string): string;
2191
+ /**
2192
+ * Checks if an entry's tag matches a given invalidation pattern.
2193
+ * Both tag and pattern are normalized (leading "/" removed) before comparison.
2194
+ *
2195
+ * @param entryTag - The tag from a cache entry (e.g., "posts", "posts/1", "posts/1/comments")
2196
+ * @param pattern - The pattern to match against:
2197
+ * - "posts" - Exact match only
2198
+ * - "posts/*" - Children only (matches posts/1, posts/1/comments, but NOT posts)
2199
+ * @returns true if the entry tag matches the pattern
2200
+ */
2201
+ declare function matchTag(entryTag: string, pattern: string): boolean;
2202
+ /**
2203
+ * Checks if an entry's tag matches any of the given invalidation patterns.
2204
+ *
2205
+ * @param entryTag - The tag from a cache entry
2206
+ * @param patterns - Array of patterns to match against
2207
+ * @returns true if the entry tag matches any of the patterns
2208
+ */
2209
+ declare function matchTags(entryTag: string, patterns: string[]): boolean;
2210
+
2183
2211
  declare const isNetworkError: (err: unknown) => boolean;
2184
2212
  declare const isAbortError: (err: unknown) => boolean;
2185
2213
 
@@ -2199,6 +2227,13 @@ declare function clone<T>(value: T, seen?: WeakMap<WeakKey, any>): T;
2199
2227
  */
2200
2228
  declare function createTracer(plugin: string, trace: Trace | undefined): RequestTracer;
2201
2229
 
2230
+ /**
2231
+ * Generates a UUID v4 string.
2232
+ * Uses crypto.randomUUID() when available (secure contexts),
2233
+ * falls back to Math.random() for non-secure contexts (HTTP).
2234
+ */
2235
+ declare function generateUUID(): string;
2236
+
2202
2237
  type ProxyHandlerConfig<TOptions = SpooshOptions> = {
2203
2238
  baseUrl: string;
2204
2239
  defaultOptions: TOptions;
@@ -2605,4 +2640,4 @@ interface CreateSubscriptionControllerOptions<TData, TError> {
2605
2640
  }
2606
2641
  declare function createSubscriptionController<TData, TError>(options: CreateSubscriptionControllerOptions<TData, TError>): SubscriptionController<TData, TError>;
2607
2642
 
2608
- export { type AnyMethod, type AnyRequestOptions, type ApiContext, type ApiPluginExecutor, type ApiResolvers, type ApiSchema, type BaseSubscriptionResponse, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type CreateSubscriptionControllerOptions, type DataAwareCallback, type DataAwareTransform, type DataChangeCallback, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExecuteOptions, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type ExtractTriggerBody, type ExtractTriggerParams, type ExtractTriggerQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasSubscriptionMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteNextContext, type InfinitePage, type InfinitePageStatus, type InfinitePrevContext, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InfiniteTriggerOptions, type LifecyclePhase, type MergePluginApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginFactory, type PluginHandler, type PluginInternalRegistry, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type QueueController, type QueueControllerConfig, type QueueControllerContext, type QueueItem, type QueueItemStatus, type QueueSelectorClient, type QueueStats, type QueueTriggerInput, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, Semaphore, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type SpooshSubscriptionMethodRegistry, type SpooshTransport, type SpooshTransportRegistry, type StandaloneEvent, type StateManager, type StripPrefix, type Subscriber, type SubscriptionAccumulateEvent, type SubscriptionAdapter, type SubscriptionClient, type SubscriptionConnectEvent, type SubscriptionConnectedEvent, type SubscriptionContext, type SubscriptionController, type SubscriptionDisconnectEvent, type SubscriptionErrorEvent, type SubscriptionHandle, type SubscriptionMessageEvent, type SubscriptionMethod, type SubscriptionPaths, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportName, type TransportOption, type TransportOptionsMap, type TransportResponse, type TypedPluginContext, type TypedPluginDefinition, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, composeAdapter, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createQueueController, createSelectorProxy, createSpooshPlugin, createStateManager, createSubscriptionController, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateSelfTagFromKey, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, removeHeaderKeys, resolveHeadersToRecord, resolvePath, resolvePathString, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
2643
+ export { type AnyMethod, type AnyRequestOptions, type ApiContext, type ApiPluginExecutor, type ApiResolvers, type ApiSchema, type BaseSubscriptionResponse, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type CreateSubscriptionControllerOptions, type DataAwareCallback, type DataAwareTransform, type DataChangeCallback, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExecuteOptions, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type ExtractTriggerBody, type ExtractTriggerParams, type ExtractTriggerQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasSubscriptionMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteNextContext, type InfinitePage, type InfinitePageStatus, type InfinitePrevContext, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InfiniteTriggerOptions, type LifecyclePhase, type MergePluginApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginFactory, type PluginHandler, type PluginInternalRegistry, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type QueueController, type QueueControllerConfig, type QueueControllerContext, type QueueItem, type QueueItemStatus, type QueueSelectorClient, type QueueStats, type QueueTriggerInput, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, Semaphore, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type SpooshSubscriptionMethodRegistry, type SpooshTransport, type SpooshTransportRegistry, type StandaloneEvent, type StateManager, type StripPrefix, type Subscriber, type SubscriptionAccumulateEvent, type SubscriptionAdapter, type SubscriptionClient, type SubscriptionConnectEvent, type SubscriptionConnectedEvent, type SubscriptionContext, type SubscriptionController, type SubscriptionDisconnectEvent, type SubscriptionErrorEvent, type SubscriptionHandle, type SubscriptionMessageEvent, type SubscriptionMethod, type SubscriptionPaths, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportName, type TransportOption, type TransportOptionsMap, type TransportResponse, type TypedPluginContext, type TypedPluginDefinition, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, composeAdapter, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createQueueController, createSelectorProxy, createSpooshPlugin, createStateManager, createSubscriptionController, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateSelfTagFromKey, generateTags, generateUUID, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, matchTag, matchTags, mergeHeaders, normalizeTag, objectToFormData, objectToUrlEncoded, removeHeaderKeys, resolveHeadersToRecord, resolvePath, resolvePathString, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
package/dist/index.js CHANGED
@@ -49,13 +49,17 @@ __export(src_exports, {
49
49
  form: () => form,
50
50
  generateSelfTagFromKey: () => generateSelfTagFromKey,
51
51
  generateTags: () => generateTags,
52
+ generateUUID: () => generateUUID,
52
53
  getContentType: () => getContentType,
53
54
  isAbortError: () => isAbortError,
54
55
  isJsonBody: () => isJsonBody,
55
56
  isNetworkError: () => isNetworkError,
56
57
  isSpooshBody: () => isSpooshBody,
57
58
  json: () => json,
59
+ matchTag: () => matchTag,
60
+ matchTags: () => matchTags,
58
61
  mergeHeaders: () => mergeHeaders,
62
+ normalizeTag: () => normalizeTag,
59
63
  objectToFormData: () => objectToFormData,
60
64
  objectToUrlEncoded: () => objectToUrlEncoded,
61
65
  removeHeaderKeys: () => removeHeaderKeys,
@@ -326,41 +330,38 @@ function resolveRequestBody(rawBody) {
326
330
  return { body: rawBody };
327
331
  }
328
332
 
329
- // src/utils/path-utils.ts
330
- function resolveTagMode(mode, path) {
331
- switch (mode) {
332
- case "all":
333
- return generateTags(path);
334
- case "self":
335
- return [path.join("/")];
336
- case "none":
337
- return [];
333
+ // src/utils/matchTag.ts
334
+ function normalizeTag(tag) {
335
+ return tag.startsWith("/") ? tag.slice(1) : tag;
336
+ }
337
+ function matchTag(entryTag, pattern) {
338
+ const normalizedTag = normalizeTag(entryTag);
339
+ const normalizedPattern = normalizeTag(pattern);
340
+ if (normalizedPattern.endsWith("/*")) {
341
+ const prefix = normalizedPattern.slice(0, -2);
342
+ return prefix === "" ? normalizedTag.length > 0 : normalizedTag.startsWith(prefix + "/");
338
343
  }
344
+ return normalizedTag === normalizedPattern;
345
+ }
346
+ function matchTags(entryTag, patterns) {
347
+ return patterns.some((pattern) => matchTag(entryTag, pattern));
339
348
  }
349
+
350
+ // src/utils/path-utils.ts
340
351
  function resolveTags(options, resolvedPath) {
341
352
  const tagsOption = options?.tags;
342
353
  if (!tagsOption) {
343
- return generateTags(resolvedPath);
354
+ const tag2 = resolvedPath.join("/");
355
+ return tag2 ? [normalizeTag(tag2)] : [];
344
356
  }
345
357
  if (typeof tagsOption === "string") {
346
- return resolveTagMode(tagsOption, resolvedPath);
358
+ return [normalizeTag(tagsOption)];
347
359
  }
348
360
  if (Array.isArray(tagsOption)) {
349
- const tags = [];
350
- let mode = null;
351
- for (const item of tagsOption) {
352
- if (item === "all" || item === "self") {
353
- mode = item;
354
- } else if (typeof item === "string") {
355
- tags.push(item);
356
- }
357
- }
358
- if (mode) {
359
- tags.push(...resolveTagMode(mode, resolvedPath));
360
- }
361
- return [...new Set(tags)];
361
+ return [...new Set(tagsOption.map(normalizeTag))];
362
362
  }
363
- return generateTags(resolvedPath);
363
+ const tag = resolvedPath.join("/");
364
+ return tag ? [normalizeTag(tag)] : [];
364
365
  }
365
366
  function resolvePath(path, params) {
366
367
  if (!params) return path;
@@ -442,6 +443,18 @@ function createTracer(plugin, trace) {
442
443
  };
443
444
  }
444
445
 
446
+ // src/utils/uuid.ts
447
+ function generateUUID() {
448
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
449
+ return crypto.randomUUID();
450
+ }
451
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
452
+ const r = Math.random() * 16 | 0;
453
+ const v = c === "x" ? r : r & 3 | 8;
454
+ return v.toString(16);
455
+ });
456
+ }
457
+
445
458
  // src/transport/fetch.ts
446
459
  var fetchTransport = async (url, init) => {
447
460
  const res = await fetch(url, init);
@@ -856,19 +869,19 @@ function createStateManager() {
856
869
  }
857
870
  };
858
871
  },
859
- getCacheByTags(tags) {
872
+ getCacheByTags(patterns) {
860
873
  for (const entry of cache.values()) {
861
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
874
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
862
875
  if (hasMatch && entry.state.data !== void 0) {
863
876
  return entry;
864
877
  }
865
878
  }
866
879
  return void 0;
867
880
  },
868
- getCacheEntriesByTags(tags) {
881
+ getCacheEntriesByTags(patterns) {
869
882
  const entries = [];
870
883
  cache.forEach((entry, key) => {
871
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
884
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
872
885
  if (hasMatch) {
873
886
  entries.push({
874
887
  key,
@@ -907,9 +920,9 @@ function createStateManager() {
907
920
  entry.state = { ...entry.state };
908
921
  notifySubscribers(key);
909
922
  },
910
- markStale(tags) {
923
+ markStale(patterns) {
911
924
  cache.forEach((entry) => {
912
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
925
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
913
926
  if (hasMatch) {
914
927
  entry.stale = true;
915
928
  }
package/dist/index.mjs CHANGED
@@ -253,41 +253,38 @@ function resolveRequestBody(rawBody) {
253
253
  return { body: rawBody };
254
254
  }
255
255
 
256
- // src/utils/path-utils.ts
257
- function resolveTagMode(mode, path) {
258
- switch (mode) {
259
- case "all":
260
- return generateTags(path);
261
- case "self":
262
- return [path.join("/")];
263
- case "none":
264
- return [];
256
+ // src/utils/matchTag.ts
257
+ function normalizeTag(tag) {
258
+ return tag.startsWith("/") ? tag.slice(1) : tag;
259
+ }
260
+ function matchTag(entryTag, pattern) {
261
+ const normalizedTag = normalizeTag(entryTag);
262
+ const normalizedPattern = normalizeTag(pattern);
263
+ if (normalizedPattern.endsWith("/*")) {
264
+ const prefix = normalizedPattern.slice(0, -2);
265
+ return prefix === "" ? normalizedTag.length > 0 : normalizedTag.startsWith(prefix + "/");
265
266
  }
267
+ return normalizedTag === normalizedPattern;
268
+ }
269
+ function matchTags(entryTag, patterns) {
270
+ return patterns.some((pattern) => matchTag(entryTag, pattern));
266
271
  }
272
+
273
+ // src/utils/path-utils.ts
267
274
  function resolveTags(options, resolvedPath) {
268
275
  const tagsOption = options?.tags;
269
276
  if (!tagsOption) {
270
- return generateTags(resolvedPath);
277
+ const tag2 = resolvedPath.join("/");
278
+ return tag2 ? [normalizeTag(tag2)] : [];
271
279
  }
272
280
  if (typeof tagsOption === "string") {
273
- return resolveTagMode(tagsOption, resolvedPath);
281
+ return [normalizeTag(tagsOption)];
274
282
  }
275
283
  if (Array.isArray(tagsOption)) {
276
- const tags = [];
277
- let mode = null;
278
- for (const item of tagsOption) {
279
- if (item === "all" || item === "self") {
280
- mode = item;
281
- } else if (typeof item === "string") {
282
- tags.push(item);
283
- }
284
- }
285
- if (mode) {
286
- tags.push(...resolveTagMode(mode, resolvedPath));
287
- }
288
- return [...new Set(tags)];
284
+ return [...new Set(tagsOption.map(normalizeTag))];
289
285
  }
290
- return generateTags(resolvedPath);
286
+ const tag = resolvedPath.join("/");
287
+ return tag ? [normalizeTag(tag)] : [];
291
288
  }
292
289
  function resolvePath(path, params) {
293
290
  if (!params) return path;
@@ -369,6 +366,18 @@ function createTracer(plugin, trace) {
369
366
  };
370
367
  }
371
368
 
369
+ // src/utils/uuid.ts
370
+ function generateUUID() {
371
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
372
+ return crypto.randomUUID();
373
+ }
374
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
375
+ const r = Math.random() * 16 | 0;
376
+ const v = c === "x" ? r : r & 3 | 8;
377
+ return v.toString(16);
378
+ });
379
+ }
380
+
372
381
  // src/transport/fetch.ts
373
382
  var fetchTransport = async (url, init) => {
374
383
  const res = await fetch(url, init);
@@ -783,19 +792,19 @@ function createStateManager() {
783
792
  }
784
793
  };
785
794
  },
786
- getCacheByTags(tags) {
795
+ getCacheByTags(patterns) {
787
796
  for (const entry of cache.values()) {
788
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
797
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
789
798
  if (hasMatch && entry.state.data !== void 0) {
790
799
  return entry;
791
800
  }
792
801
  }
793
802
  return void 0;
794
803
  },
795
- getCacheEntriesByTags(tags) {
804
+ getCacheEntriesByTags(patterns) {
796
805
  const entries = [];
797
806
  cache.forEach((entry, key) => {
798
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
807
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
799
808
  if (hasMatch) {
800
809
  entries.push({
801
810
  key,
@@ -834,9 +843,9 @@ function createStateManager() {
834
843
  entry.state = { ...entry.state };
835
844
  notifySubscribers(key);
836
845
  },
837
- markStale(tags) {
846
+ markStale(patterns) {
838
847
  cache.forEach((entry) => {
839
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
848
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
840
849
  if (hasMatch) {
841
850
  entry.stale = true;
842
851
  }
@@ -2464,13 +2473,17 @@ export {
2464
2473
  form,
2465
2474
  generateSelfTagFromKey,
2466
2475
  generateTags,
2476
+ generateUUID,
2467
2477
  getContentType,
2468
2478
  isAbortError,
2469
2479
  isJsonBody,
2470
2480
  isNetworkError,
2471
2481
  isSpooshBody,
2472
2482
  json,
2483
+ matchTag,
2484
+ matchTags,
2473
2485
  mergeHeaders,
2486
+ normalizeTag,
2474
2487
  objectToFormData,
2475
2488
  objectToUrlEncoded,
2476
2489
  removeHeaderKeys,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/core",
3
- "version": "0.17.1",
3
+ "version": "0.18.1",
4
4
  "license": "MIT",
5
5
  "description": "Type-safe API toolkit with plugin middleware system",
6
6
  "keywords": [