@spoosh/core 0.17.1 → 0.18.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/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
 
@@ -2605,4 +2633,4 @@ interface CreateSubscriptionControllerOptions<TData, TError> {
2605
2633
  }
2606
2634
  declare function createSubscriptionController<TData, TError>(options: CreateSubscriptionControllerOptions<TData, TError>): SubscriptionController<TData, TError>;
2607
2635
 
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 };
2636
+ 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, 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
 
@@ -2605,4 +2633,4 @@ interface CreateSubscriptionControllerOptions<TData, TError> {
2605
2633
  }
2606
2634
  declare function createSubscriptionController<TData, TError>(options: CreateSubscriptionControllerOptions<TData, TError>): SubscriptionController<TData, TError>;
2607
2635
 
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 };
2636
+ 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, 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
@@ -55,7 +55,10 @@ __export(src_exports, {
55
55
  isNetworkError: () => isNetworkError,
56
56
  isSpooshBody: () => isSpooshBody,
57
57
  json: () => json,
58
+ matchTag: () => matchTag,
59
+ matchTags: () => matchTags,
58
60
  mergeHeaders: () => mergeHeaders,
61
+ normalizeTag: () => normalizeTag,
59
62
  objectToFormData: () => objectToFormData,
60
63
  objectToUrlEncoded: () => objectToUrlEncoded,
61
64
  removeHeaderKeys: () => removeHeaderKeys,
@@ -326,41 +329,38 @@ function resolveRequestBody(rawBody) {
326
329
  return { body: rawBody };
327
330
  }
328
331
 
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 [];
332
+ // src/utils/matchTag.ts
333
+ function normalizeTag(tag) {
334
+ return tag.startsWith("/") ? tag.slice(1) : tag;
335
+ }
336
+ function matchTag(entryTag, pattern) {
337
+ const normalizedTag = normalizeTag(entryTag);
338
+ const normalizedPattern = normalizeTag(pattern);
339
+ if (normalizedPattern.endsWith("/*")) {
340
+ const prefix = normalizedPattern.slice(0, -2);
341
+ return prefix === "" ? normalizedTag.length > 0 : normalizedTag.startsWith(prefix + "/");
338
342
  }
343
+ return normalizedTag === normalizedPattern;
339
344
  }
345
+ function matchTags(entryTag, patterns) {
346
+ return patterns.some((pattern) => matchTag(entryTag, pattern));
347
+ }
348
+
349
+ // src/utils/path-utils.ts
340
350
  function resolveTags(options, resolvedPath) {
341
351
  const tagsOption = options?.tags;
342
352
  if (!tagsOption) {
343
- return generateTags(resolvedPath);
353
+ const tag2 = resolvedPath.join("/");
354
+ return tag2 ? [normalizeTag(tag2)] : [];
344
355
  }
345
356
  if (typeof tagsOption === "string") {
346
- return resolveTagMode(tagsOption, resolvedPath);
357
+ return [normalizeTag(tagsOption)];
347
358
  }
348
359
  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)];
360
+ return [...new Set(tagsOption.map(normalizeTag))];
362
361
  }
363
- return generateTags(resolvedPath);
362
+ const tag = resolvedPath.join("/");
363
+ return tag ? [normalizeTag(tag)] : [];
364
364
  }
365
365
  function resolvePath(path, params) {
366
366
  if (!params) return path;
@@ -856,19 +856,19 @@ function createStateManager() {
856
856
  }
857
857
  };
858
858
  },
859
- getCacheByTags(tags) {
859
+ getCacheByTags(patterns) {
860
860
  for (const entry of cache.values()) {
861
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
861
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
862
862
  if (hasMatch && entry.state.data !== void 0) {
863
863
  return entry;
864
864
  }
865
865
  }
866
866
  return void 0;
867
867
  },
868
- getCacheEntriesByTags(tags) {
868
+ getCacheEntriesByTags(patterns) {
869
869
  const entries = [];
870
870
  cache.forEach((entry, key) => {
871
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
871
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
872
872
  if (hasMatch) {
873
873
  entries.push({
874
874
  key,
@@ -907,9 +907,9 @@ function createStateManager() {
907
907
  entry.state = { ...entry.state };
908
908
  notifySubscribers(key);
909
909
  },
910
- markStale(tags) {
910
+ markStale(patterns) {
911
911
  cache.forEach((entry) => {
912
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
912
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
913
913
  if (hasMatch) {
914
914
  entry.stale = true;
915
915
  }
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;
266
268
  }
269
+ function matchTags(entryTag, patterns) {
270
+ return patterns.some((pattern) => matchTag(entryTag, pattern));
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;
@@ -783,19 +780,19 @@ function createStateManager() {
783
780
  }
784
781
  };
785
782
  },
786
- getCacheByTags(tags) {
783
+ getCacheByTags(patterns) {
787
784
  for (const entry of cache.values()) {
788
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
785
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
789
786
  if (hasMatch && entry.state.data !== void 0) {
790
787
  return entry;
791
788
  }
792
789
  }
793
790
  return void 0;
794
791
  },
795
- getCacheEntriesByTags(tags) {
792
+ getCacheEntriesByTags(patterns) {
796
793
  const entries = [];
797
794
  cache.forEach((entry, key) => {
798
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
795
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
799
796
  if (hasMatch) {
800
797
  entries.push({
801
798
  key,
@@ -834,9 +831,9 @@ function createStateManager() {
834
831
  entry.state = { ...entry.state };
835
832
  notifySubscribers(key);
836
833
  },
837
- markStale(tags) {
834
+ markStale(patterns) {
838
835
  cache.forEach((entry) => {
839
- const hasMatch = entry.tags.some((tag) => tags.includes(tag));
836
+ const hasMatch = entry.tags.some((tag) => matchTags(tag, patterns));
840
837
  if (hasMatch) {
841
838
  entry.stale = true;
842
839
  }
@@ -2470,7 +2467,10 @@ export {
2470
2467
  isNetworkError,
2471
2468
  isSpooshBody,
2472
2469
  json,
2470
+ matchTag,
2471
+ matchTags,
2473
2472
  mergeHeaders,
2473
+ normalizeTag,
2474
2474
  objectToFormData,
2475
2475
  objectToUrlEncoded,
2476
2476
  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.0",
4
4
  "license": "MIT",
5
5
  "description": "Type-safe API toolkit with plugin middleware system",
6
6
  "keywords": [