@ryuzaki13/react-foundation-api 1.0.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/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/adt/fetchUserTransports.d.ts +2 -0
- package/dist/adt/fetchUserTransports.d.ts.map +1 -0
- package/dist/adt/index.d.ts +4 -0
- package/dist/adt/index.d.ts.map +1 -0
- package/dist/adt/index.js +70 -0
- package/dist/adt/index.js.map +1 -0
- package/dist/adt/parseUserTransportsXml.d.ts +3 -0
- package/dist/adt/parseUserTransportsXml.d.ts.map +1 -0
- package/dist/adt/types.d.ts +10 -0
- package/dist/adt/types.d.ts.map +1 -0
- package/dist/async/AsyncTasksError.d.ts +6 -0
- package/dist/async/AsyncTasksError.d.ts.map +1 -0
- package/dist/async/ConcurrencyPartialError.d.ts +6 -0
- package/dist/async/ConcurrencyPartialError.d.ts.map +1 -0
- package/dist/async/index.d.ts +5 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/index.js +163 -0
- package/dist/async/index.js.map +1 -0
- package/dist/async/runAsyncTasks.d.ts +32 -0
- package/dist/async/runAsyncTasks.d.ts.map +1 -0
- package/dist/async/runConcurrentTasks.d.ts +127 -0
- package/dist/async/runConcurrentTasks.d.ts.map +1 -0
- package/dist/chunks/fetch-BW2OtCu7.js +508 -0
- package/dist/chunks/fetch-BW2OtCu7.js.map +1 -0
- package/dist/chunks/odata-ZgZGme_K.js +473 -0
- package/dist/chunks/odata-ZgZGme_K.js.map +1 -0
- package/dist/chunks/odataFetchFn-BXVJxOou.js +302 -0
- package/dist/chunks/odataFetchFn-BXVJxOou.js.map +1 -0
- package/dist/error-report/errorReport.d.ts +28 -0
- package/dist/error-report/errorReport.d.ts.map +1 -0
- package/dist/error-report/index.d.ts +2 -0
- package/dist/error-report/index.d.ts.map +1 -0
- package/dist/error-report/index.js +42 -0
- package/dist/error-report/index.js.map +1 -0
- package/dist/http/RouteError.d.ts +5 -0
- package/dist/http/RouteError.d.ts.map +1 -0
- package/dist/http/http.d.ts +20 -0
- package/dist/http/http.d.ts.map +1 -0
- package/dist/http/index.d.ts +4 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +67 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/types.d.ts +23 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/odata/createODataCollectionQueryKey.d.ts +9 -0
- package/dist/odata/createODataCollectionQueryKey.d.ts.map +1 -0
- package/dist/odata/fetchCollectionData.d.ts +15 -0
- package/dist/odata/fetchCollectionData.d.ts.map +1 -0
- package/dist/odata/flattenODataDependentServices.d.ts +6 -0
- package/dist/odata/flattenODataDependentServices.d.ts.map +1 -0
- package/dist/odata/index.d.ts +21 -0
- package/dist/odata/index.d.ts.map +1 -0
- package/dist/odata/index.js +4 -0
- package/dist/odata/metadataVersionCheck.d.ts +49 -0
- package/dist/odata/metadataVersionCheck.d.ts.map +1 -0
- package/dist/odata/odataBaseQueryKey.d.ts +2 -0
- package/dist/odata/odataBaseQueryKey.d.ts.map +1 -0
- package/dist/odata/odataFetch.d.ts +87 -0
- package/dist/odata/odataFetch.d.ts.map +1 -0
- package/dist/odata/odataFetchFn.d.ts +399 -0
- package/dist/odata/odataFetchFn.d.ts.map +1 -0
- package/dist/odata/odataFetchFnDev.d.ts +58 -0
- package/dist/odata/odataFetchFnDev.d.ts.map +1 -0
- package/dist/odata/odataFetchFnHelpers.d.ts +9 -0
- package/dist/odata/odataFetchFnHelpers.d.ts.map +1 -0
- package/dist/odata/odataProjectAdapter.d.ts +22 -0
- package/dist/odata/odataProjectAdapter.d.ts.map +1 -0
- package/dist/odata/parseODataResponseByMetadata.d.ts +4 -0
- package/dist/odata/parseODataResponseByMetadata.d.ts.map +1 -0
- package/dist/odata/sortODataDependentSegmentItemsByChains.d.ts +8 -0
- package/dist/odata/sortODataDependentSegmentItemsByChains.d.ts.map +1 -0
- package/dist/odata/sortODataDependentServicesByChains.d.ts +12 -0
- package/dist/odata/sortODataDependentServicesByChains.d.ts.map +1 -0
- package/dist/odata/transport/SsoRequiredError.d.ts +22 -0
- package/dist/odata/transport/SsoRequiredError.d.ts.map +1 -0
- package/dist/odata/transport/errorReport.d.ts +3 -0
- package/dist/odata/transport/errorReport.d.ts.map +1 -0
- package/dist/odata/transport/fetch.d.ts +43 -0
- package/dist/odata/transport/fetch.d.ts.map +1 -0
- package/dist/odata/transport/index.d.ts +5 -0
- package/dist/odata/transport/index.d.ts.map +1 -0
- package/dist/odata/transport/types.d.ts +12 -0
- package/dist/odata/transport/types.d.ts.map +1 -0
- package/dist/odata/transport/url.d.ts +13 -0
- package/dist/odata/transport/url.d.ts.map +1 -0
- package/dist/odata/types.d.ts +176 -0
- package/dist/odata/types.d.ts.map +1 -0
- package/dist/odata/useODataCollection.d.ts +39 -0
- package/dist/odata/useODataCollection.d.ts.map +1 -0
- package/dist/odata/useODataCollectionChains.d.ts +7 -0
- package/dist/odata/useODataCollectionChains.d.ts.map +1 -0
- package/dist/odata/useODataCollectionModel.d.ts +3 -0
- package/dist/odata/useODataCollectionModel.d.ts.map +1 -0
- package/dist/odata/useODataCollectionQuery.d.ts +34 -0
- package/dist/odata/useODataCollectionQuery.d.ts.map +1 -0
- package/dist/odata/useODataCollectionUpdatesQuery.d.ts +51 -0
- package/dist/odata/useODataCollectionUpdatesQuery.d.ts.map +1 -0
- package/dist/odata/useODataEntity.d.ts +28 -0
- package/dist/odata/useODataEntity.d.ts.map +1 -0
- package/dist/odata/useODataMetadata.d.ts +13 -0
- package/dist/odata/useODataMetadata.d.ts.map +1 -0
- package/dist/odata/useODataMetadataQuery.d.ts +32 -0
- package/dist/odata/useODataMetadataQuery.d.ts.map +1 -0
- package/dist/odata/useODataTableColumns.d.ts +69 -0
- package/dist/odata/useODataTableColumns.d.ts.map +1 -0
- package/dist/odata/useTextServiceQuery.d.ts +3 -0
- package/dist/odata/useTextServiceQuery.d.ts.map +1 -0
- package/dist/persisted/cache.d.ts +29 -0
- package/dist/persisted/cache.d.ts.map +1 -0
- package/dist/persisted/index.d.ts +22 -0
- package/dist/persisted/index.d.ts.map +1 -0
- package/dist/persisted/index.js +339 -0
- package/dist/persisted/index.js.map +1 -0
- package/dist/persisted/keys.d.ts +21 -0
- package/dist/persisted/keys.d.ts.map +1 -0
- package/dist/persisted/odata.d.ts +113 -0
- package/dist/persisted/odata.d.ts.map +1 -0
- package/dist/persisted/payload.d.ts +29 -0
- package/dist/persisted/payload.d.ts.map +1 -0
- package/dist/persisted/resource.d.ts +87 -0
- package/dist/persisted/resource.d.ts.map +1 -0
- package/dist/persisted/rest.d.ts +87 -0
- package/dist/persisted/rest.d.ts.map +1 -0
- package/dist/persisted/types.d.ts +172 -0
- package/dist/persisted/types.d.ts.map +1 -0
- package/dist/resource/cache.d.ts +22 -0
- package/dist/resource/cache.d.ts.map +1 -0
- package/dist/resource/index.d.ts +5 -0
- package/dist/resource/index.d.ts.map +1 -0
- package/dist/resource/index.js +147 -0
- package/dist/resource/index.js.map +1 -0
- package/dist/resource/keys.d.ts +14 -0
- package/dist/resource/keys.d.ts.map +1 -0
- package/dist/resource/resource.d.ts +38 -0
- package/dist/resource/resource.d.ts.map +1 -0
- package/dist/resource/types.d.ts +112 -0
- package/dist/resource/types.d.ts.map +1 -0
- package/dist/s3/constants.d.ts +12 -0
- package/dist/s3/constants.d.ts.map +1 -0
- package/dist/s3/fetchFileFromS3.d.ts +13 -0
- package/dist/s3/fetchFileFromS3.d.ts.map +1 -0
- package/dist/s3/index.d.ts +3 -0
- package/dist/s3/index.d.ts.map +1 -0
- package/dist/s3/index.js +41 -0
- package/dist/s3/index.js.map +1 -0
- package/dist/s3/uploadToS3.d.ts +18 -0
- package/dist/s3/uploadToS3.d.ts.map +1 -0
- package/dist/server-fn/index.d.ts +2 -0
- package/dist/server-fn/index.d.ts.map +1 -0
- package/dist/server-fn/index.js +37 -0
- package/dist/server-fn/index.js.map +1 -0
- package/dist/server-fn/serverFn.d.ts +64 -0
- package/dist/server-fn/serverFn.d.ts.map +1 -0
- package/dist/transport/fetchTransportRequests.d.ts +11 -0
- package/dist/transport/fetchTransportRequests.d.ts.map +1 -0
- package/dist/transport/index.d.ts +4 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +52 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/normalizeTransportRequests.d.ts +3 -0
- package/dist/transport/normalizeTransportRequests.d.ts.map +1 -0
- package/dist/transport/types.d.ts +19 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/package.json +202 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/resource/cache.ts","../../src/resource/keys.ts","../../src/resource/resource.ts"],"sourcesContent":["import type { ResourceCacheStrategy, ResourceCacheStrategyContext, ResourceSetQueryDataStrategyOptions } from \"./types\";\n\n/**\n * Безопасно применяет cache strategy, если она была передана.\n */\nexport async function applyResourceCacheStrategy<TScope, TInput, TResult, TDescriptor>(\n\tstrategy: ResourceCacheStrategy<TScope, TInput, TResult, TDescriptor> | null | undefined,\n\tcontext: ResourceCacheStrategyContext<TScope, TInput, TResult, TDescriptor>\n) {\n\tawait strategy?.onSuccess?.(context);\n}\n\n/**\n * Создаёт стратегию, инвалидирующую все query внутри одного scope ресурса.\n */\nexport function createInvalidateResourceScopeCacheStrategy<\n\tTScope,\n\tTInput,\n\tTResult,\n\tTDescriptor extends { readonly keys: { scope: (scope: TScope) => readonly unknown[] } }\n>(): ResourceCacheStrategy<TScope, TInput, TResult, TDescriptor> {\n\treturn {\n\t\tonSuccess: async ({ client, descriptor, scope }) => {\n\t\t\tawait client.invalidateQueries({ queryKey: descriptor.keys.scope(scope) });\n\t\t}\n\t};\n}\n\n/**\n * Создаёт стратегию точечного обновления одного query через `setQueryData`.\n */\nexport function createSetResourceQueryDataCacheStrategy<TScope, TInput, TResult, TData, TDescriptor>(\n\toptions: ResourceSetQueryDataStrategyOptions<TScope, TInput, TResult, TData, TDescriptor>\n): ResourceCacheStrategy<TScope, TInput, TResult, TDescriptor> {\n\treturn {\n\t\tonSuccess: ({ client, ...context }) => {\n\t\t\tclient.setQueryData<TData>(options.getQueryKey({ client, ...context }), (current) =>\n\t\t\t\toptions.update(current, { client, ...context })\n\t\t\t);\n\t\t}\n\t};\n}\n\n/**\n * Комбинирует несколько cache strategy в одну последовательную стратегию.\n */\nexport function composeResourceCacheStrategies<TScope, TInput, TResult, TDescriptor>(\n\t...strategies: Array<ResourceCacheStrategy<TScope, TInput, TResult, TDescriptor> | null | undefined>\n): ResourceCacheStrategy<TScope, TInput, TResult, TDescriptor> {\n\treturn {\n\t\tonSuccess: async (context) => {\n\t\t\tfor (const strategy of strategies) {\n\t\t\t\tawait strategy?.onSuccess?.(context);\n\t\t\t}\n\t\t}\n\t};\n}\n","import type { ResourceKeys, ResourceKeyValue } from \"./types\";\n\n/**\n * Рекурсивно нормализует значение для стабильного query key.\n */\nexport function normalizeResourceKeyValue(value: unknown): ResourceKeyValue {\n\tif (value === null || value === undefined) return null;\n\n\tif (typeof value === \"string\") {\n\t\treturn value.trim();\n\t}\n\n\tif (typeof value === \"number\" || typeof value === \"boolean\") {\n\t\treturn value;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value.map((item) => normalizeResourceKeyValue(item));\n\t}\n\n\tif (typeof value === \"object\") {\n\t\treturn Object.keys(value)\n\t\t\t.sort()\n\t\t\t.reduce<Record<string, ResourceKeyValue>>((acc, key) => {\n\t\t\t\tacc[key] = normalizeResourceKeyValue((value as Record<string, unknown>)[key]);\n\t\t\t\treturn acc;\n\t\t\t}, {});\n\t}\n\n\treturn String(value);\n}\n\nconst defaultNormalizeScope = <TScope>(scope: TScope | null | undefined) => normalizeResourceKeyValue(scope ?? null);\n\n/**\n * Создаёт фабрики query key для ресурса с произвольными operation names.\n */\nexport function createResourceKeys<TScope, TOperationName extends string = string>(options: {\n\treadonly namespace: string;\n\treadonly resource: string;\n\treadonly normalizeScope?: (scope: TScope | null | undefined) => unknown;\n}): ResourceKeys<TScope, TOperationName> {\n\tconst all = [options.namespace, options.resource] as const;\n\tconst normalizeScope = options.normalizeScope ?? defaultNormalizeScope<TScope>;\n\n\tconst scope = (value: TScope | null | undefined) => [...all, normalizeResourceKeyValue(normalizeScope(value))] as const;\n\tconst operation = (name: TOperationName, value: TScope | null | undefined, args?: unknown) =>\n\t\targs === undefined ? ([...scope(value), name] as const) : ([...scope(value), name, normalizeResourceKeyValue(args)] as const);\n\n\treturn {\n\t\tall,\n\t\tscope,\n\t\toperation\n\t};\n}\n","import { queryOptions, useMutation, useQuery, useQueryClient, type QueryClient } from \"@tanstack/react-query\";\n\nimport { applyResourceCacheStrategy } from \"./cache\";\nimport { createResourceKeys } from \"./keys\";\n\nimport type {\n\tCreateResourceDescriptorOptions,\n\tResourceDescriptor,\n\tResourceMutationInput,\n\tResourceMutationOperation,\n\tResourceMutationResult,\n\tResourceQueryArgs,\n\tResourceQueryOperation,\n\tResourceQueryResult,\n\tUseResourceMutationOptions\n} from \"./types\";\n\nfunction assertResourceScope<TScope, TQueries extends object, TMutations extends object>(\n\tdescriptor: ResourceDescriptor<TScope, TQueries, TMutations>,\n\tscope: TScope | null | undefined\n): TScope {\n\tif (scope !== null && scope !== undefined && (descriptor.isEnabled?.(scope) ?? true)) {\n\t\treturn scope;\n\t}\n\n\tthrow new Error(descriptor.getScopeError?.(scope) ?? `Недостаточно данных scope для ресурса '${descriptor.resource}'.`);\n}\n\nfunction hasExecuteFunction(value: unknown): value is { readonly execute: (...args: readonly unknown[]) => unknown } {\n\treturn typeof value === \"object\" && value !== null && \"execute\" in value && typeof value.execute === \"function\";\n}\n\nfunction isResourceQueryOperation<TScope, TArgs, TResult>(value: unknown): value is ResourceQueryOperation<TScope, TArgs, TResult> {\n\treturn hasExecuteFunction(value);\n}\n\nfunction isResourceMutationOperation<TScope, TInput, TResult, TDescriptor>(\n\tvalue: unknown\n): value is ResourceMutationOperation<TScope, TInput, TResult, TDescriptor> {\n\treturn hasExecuteFunction(value);\n}\n\nfunction assertResourceQueryOperation<\n\tTScope,\n\tTQueries extends object,\n\tTMutations extends object,\n\tTOperationName extends Extract<keyof TQueries, string>\n>(\n\tdescriptor: ResourceDescriptor<TScope, TQueries, TMutations>,\n\toperationName: TOperationName\n): ResourceQueryOperation<TScope, ResourceQueryArgs<TQueries[TOperationName]>, ResourceQueryResult<TQueries[TOperationName]>> {\n\tconst operation = descriptor.operations.queries[operationName];\n\tif (\n\t\t!isResourceQueryOperation<TScope, ResourceQueryArgs<TQueries[TOperationName]>, ResourceQueryResult<TQueries[TOperationName]>>(\n\t\t\toperation\n\t\t)\n\t) {\n\t\tthrow new Error(`Ресурс '${descriptor.resource}' не поддерживает read-операцию '${operationName}'.`);\n\t}\n\n\treturn operation;\n}\n\nfunction assertResourceMutationOperation<\n\tTScope,\n\tTQueries extends object,\n\tTMutations extends object,\n\tTOperationName extends Extract<keyof TMutations, string>\n>(\n\tdescriptor: ResourceDescriptor<TScope, TQueries, TMutations>,\n\toperationName: TOperationName\n): ResourceMutationOperation<\n\tTScope,\n\tResourceMutationInput<TMutations[TOperationName]>,\n\tResourceMutationResult<TMutations[TOperationName]>,\n\tResourceDescriptor<TScope, TQueries, TMutations>\n> {\n\tconst operation = descriptor.operations.mutations[operationName];\n\tif (\n\t\t!isResourceMutationOperation<\n\t\t\tTScope,\n\t\t\tResourceMutationInput<TMutations[TOperationName]>,\n\t\t\tResourceMutationResult<TMutations[TOperationName]>,\n\t\t\tResourceDescriptor<TScope, TQueries, TMutations>\n\t\t>(operation)\n\t) {\n\t\tthrow new Error(`Ресурс '${descriptor.resource}' не поддерживает write-операцию '${operationName}'.`);\n\t}\n\n\treturn operation;\n}\n\nfunction resolveResourceQueryEnabled<TScope, TArgs, TQueries extends object, TMutations extends object>(\n\tdescriptor: ResourceDescriptor<TScope, TQueries, TMutations>,\n\toperation: ResourceQueryOperation<TScope, TArgs, unknown>,\n\tscope: TScope | null | undefined,\n\targs: TArgs\n) {\n\tif (!(descriptor.isEnabled?.(scope) ?? true)) {\n\t\treturn false;\n\t}\n\n\treturn operation.isEnabled?.(scope, args) ?? true;\n}\n\n/**\n * Создаёт descriptor ресурса с произвольными read/write operation names.\n */\nexport function createResourceDescriptor<TScope, TQueries extends object = object, TMutations extends object = object>(\n\toptions: CreateResourceDescriptorOptions<TScope, TQueries, TMutations>\n): ResourceDescriptor<TScope, TQueries, TMutations> {\n\treturn {\n\t\tnamespace: options.namespace,\n\t\tresource: options.resource,\n\t\tkeys:\n\t\t\toptions.keys ??\n\t\t\tcreateResourceKeys<TScope, Extract<keyof TQueries | keyof TMutations, string>>({\n\t\t\t\tnamespace: options.namespace,\n\t\t\t\tresource: options.resource,\n\t\t\t\tnormalizeScope: options.normalizeScope\n\t\t\t}),\n\t\toperations: {\n\t\t\tqueries: options.operations.queries ?? ({} as TQueries),\n\t\t\tmutations: options.operations.mutations ?? ({} as TMutations)\n\t\t},\n\t\tisEnabled: options.isEnabled,\n\t\tgetScopeError: options.getScopeError\n\t};\n}\n\n/**\n * Создаёт read-operation без привязки к transport.\n */\nexport function createResourceQueryOperation<TScope, TArgs, TResult>(operation: ResourceQueryOperation<TScope, TArgs, TResult>) {\n\treturn operation;\n}\n\n/**\n * Создаёт write-operation без привязки к transport.\n */\nexport function createResourceMutationOperation<TScope, TInput, TResult, TDescriptor>(\n\toperation: ResourceMutationOperation<TScope, TInput, TResult, TDescriptor>\n) {\n\treturn operation;\n}\n\n/**\n * Собирает `queryOptions` для read-операции ресурса.\n */\nexport function buildResourceQueryOptions<\n\tTScope,\n\tTQueries extends object,\n\tTMutations extends object,\n\tTOperationName extends Extract<keyof TQueries, string>\n>(\n\tdescriptor: ResourceDescriptor<TScope, TQueries, TMutations>,\n\toperationName: TOperationName,\n\tscope: TScope | null | undefined,\n\targs: ResourceQueryArgs<TQueries[TOperationName]>\n) {\n\tconst operation = assertResourceQueryOperation(descriptor, operationName);\n\tconst enabled = resolveResourceQueryEnabled(descriptor, operation, scope, args);\n\n\treturn queryOptions({\n\t\tqueryKey: descriptor.keys.operation(operationName as Extract<keyof TQueries | keyof TMutations, string>, scope, args),\n\t\tqueryFn: ({ client, signal }) => {\n\t\t\tconst resolvedScope = assertResourceScope(descriptor, scope);\n\t\t\treturn operation.execute({ scope: resolvedScope, args, client, signal });\n\t\t},\n\t\tenabled,\n\t\tstaleTime: operation.staleTime,\n\t\tgcTime: operation.gcTime\n\t});\n}\n\n/**\n * Подключает read-операцию ресурса к `useQuery`.\n */\nexport function useResourceQuery<\n\tTScope,\n\tTQueries extends object,\n\tTMutations extends object,\n\tTOperationName extends Extract<keyof TQueries, string>\n>(\n\tdescriptor: ResourceDescriptor<TScope, TQueries, TMutations>,\n\toperationName: TOperationName,\n\tscope: TScope | null | undefined,\n\targs: ResourceQueryArgs<TQueries[TOperationName]>\n) {\n\treturn useQuery(buildResourceQueryOptions(descriptor, operationName, scope, args));\n}\n\n/**\n * Императивно загружает read-операцию ресурса через `QueryClient`.\n */\nexport async function getResourceQueryData<\n\tTScope,\n\tTQueries extends object,\n\tTMutations extends object,\n\tTOperationName extends Extract<keyof TQueries, string>\n>(\n\tdescriptor: ResourceDescriptor<TScope, TQueries, TMutations>,\n\toperationName: TOperationName,\n\tscope: TScope | null | undefined,\n\targs: ResourceQueryArgs<TQueries[TOperationName]>,\n\tqueryClient: QueryClient\n) {\n\treturn await queryClient.fetchQuery(buildResourceQueryOptions(descriptor, operationName, scope, args));\n}\n\n/**\n * Подключает write-операцию ресурса к `useMutation`.\n */\nexport function useResourceMutation<\n\tTScope,\n\tTQueries extends object,\n\tTMutations extends object,\n\tTOperationName extends Extract<keyof TMutations, string>\n>(\n\tdescriptor: ResourceDescriptor<TScope, TQueries, TMutations>,\n\toperationName: TOperationName,\n\tscope: TScope | null | undefined,\n\toptions?: UseResourceMutationOptions<\n\t\tTScope,\n\t\tResourceMutationInput<TMutations[TOperationName]>,\n\t\tResourceMutationResult<TMutations[TOperationName]>,\n\t\tResourceDescriptor<TScope, TQueries, TMutations>\n\t>\n) {\n\tconst client = useQueryClient();\n\tconst operation = assertResourceMutationOperation(descriptor, operationName);\n\n\treturn useMutation({\n\t\tmutationKey: descriptor.keys.operation(operationName as Extract<keyof TQueries | keyof TMutations, string>, scope),\n\t\tmutationFn: async (input: ResourceMutationInput<TMutations[TOperationName]>) => {\n\t\t\tconst resolvedScope = assertResourceScope(descriptor, scope);\n\t\t\treturn await operation.execute({ scope: resolvedScope, input, client });\n\t\t},\n\t\tonSuccess: async (result, input) => {\n\t\t\tconst resolvedScope = assertResourceScope(descriptor, scope);\n\t\t\tconst cacheStrategy = options?.cacheStrategy === undefined ? operation.cacheStrategy : options.cacheStrategy;\n\n\t\t\tawait applyResourceCacheStrategy(cacheStrategy, {\n\t\t\t\tclient,\n\t\t\t\tdescriptor,\n\t\t\t\tscope: resolvedScope,\n\t\t\t\tinput,\n\t\t\t\tresult\n\t\t\t});\n\t\t\tawait options?.onSuccess?.(result, input);\n\t\t}\n\t});\n}\n"],"mappings":";;AAKA,eAAsB,EACrB,GACA,GACC;CACD,MAAM,GAAU,YAAY,CAAO;AACpC;AAKA,SAAgB,IAKiD;CAChE,OAAO,EACN,WAAW,OAAO,EAAE,WAAQ,eAAY,eAAY;EACnD,MAAM,EAAO,kBAAkB,EAAE,UAAU,EAAW,KAAK,MAAM,CAAK,EAAE,CAAC;CAC1E,EACD;AACD;AAKA,SAAgB,EACf,GAC8D;CAC9D,OAAO,EACN,YAAY,EAAE,WAAQ,GAAG,QAAc;EACtC,EAAO,aAAoB,EAAQ,YAAY;GAAE;GAAQ,GAAG;EAAQ,CAAC,IAAI,MACxE,EAAQ,OAAO,GAAS;GAAE;GAAQ,GAAG;EAAQ,CAAC,CAC/C;CACD,EACD;AACD;AAKA,SAAgB,EACf,GAAG,GAC2D;CAC9D,OAAO,EACN,WAAW,OAAO,MAAY;EAC7B,KAAK,IAAM,KAAY,GACtB,MAAM,GAAU,YAAY,CAAO;CAErC,EACD;AACD;;;ACnDA,SAAgB,EAA0B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AY,GAAe,GAAO,CAAI,CAAC;AAClF;AAKA,eAAsB,EAMrB,GACA,GACA,GACA,GACA,GACC;CACD,OAAO,MAAM,EAAY,WAAW,EAA0B,GAAY,GAAe,GAAO,CAAI,CAAC;AACtG;AAKA,SAAgB,EAMf,GACA,GACA,GACA,GAMC;CACD,IAAM,IAAS,EAAe,GACxB,IAAY,EAAgC,GAAY,CAAa;CAE3E,OAAO,EAAY;EAClB,aAAa,EAAW,KAAK,UAAU,GAAqE,CAAK;EACjH,YAAY,OAAO,MAA6D;GAC/E,IAAM,IAAgB,EAAoB,GAAY,CAAK;GAC3D,OAAO,MAAM,EAAU,QAAQ;IAAE,OAAO;IAAe;IAAO;GAAO,CAAC;EACvE;EACA,WAAW,OAAO,GAAQ,MAAU;GACnC,IAAM,IAAgB,EAAoB,GAAY,CAAK;GAU3D,AAPA,MAAM,EAFgB,GAAS,kBAAkB,KAAA,IAAY,EAAU,gBAAgB,EAAQ,eAE/C;IAC/C;IACA;IACA,OAAO;IACP;IACA;GACD,CAAC,GACD,MAAM,GAAS,YAAY,GAAQ,CAAK;EACzC;CACD,CAAC;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ResourceKeys, ResourceKeyValue } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Рекурсивно нормализует значение для стабильного query key.
|
|
4
|
+
*/
|
|
5
|
+
export declare function normalizeResourceKeyValue(value: unknown): ResourceKeyValue;
|
|
6
|
+
/**
|
|
7
|
+
* Создаёт фабрики query key для ресурса с произвольными operation names.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createResourceKeys<TScope, TOperationName extends string = string>(options: {
|
|
10
|
+
readonly namespace: string;
|
|
11
|
+
readonly resource: string;
|
|
12
|
+
readonly normalizeScope?: (scope: TScope | null | undefined) => unknown;
|
|
13
|
+
}): ResourceKeys<TScope, TOperationName>;
|
|
14
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/resource/keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE9D;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAyB1E;AAID;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE;IAC3F,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,KAAK,OAAO,CAAC;CACxE,GAAG,YAAY,CAAC,MAAM,EAAE,cAAc,CAAC,CAavC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type QueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { CreateResourceDescriptorOptions, ResourceDescriptor, ResourceMutationInput, ResourceMutationOperation, ResourceMutationResult, ResourceQueryArgs, ResourceQueryOperation, ResourceQueryResult, UseResourceMutationOptions } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Создаёт descriptor ресурса с произвольными read/write operation names.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createResourceDescriptor<TScope, TQueries extends object = object, TMutations extends object = object>(options: CreateResourceDescriptorOptions<TScope, TQueries, TMutations>): ResourceDescriptor<TScope, TQueries, TMutations>;
|
|
7
|
+
/**
|
|
8
|
+
* Создаёт read-operation без привязки к transport.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createResourceQueryOperation<TScope, TArgs, TResult>(operation: ResourceQueryOperation<TScope, TArgs, TResult>): ResourceQueryOperation<TScope, TArgs, TResult>;
|
|
11
|
+
/**
|
|
12
|
+
* Создаёт write-operation без привязки к transport.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createResourceMutationOperation<TScope, TInput, TResult, TDescriptor>(operation: ResourceMutationOperation<TScope, TInput, TResult, TDescriptor>): ResourceMutationOperation<TScope, TInput, TResult, TDescriptor>;
|
|
15
|
+
/**
|
|
16
|
+
* Собирает `queryOptions` для read-операции ресурса.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildResourceQueryOptions<TScope, TQueries extends object, TMutations extends object, TOperationName extends Extract<keyof TQueries, string>>(descriptor: ResourceDescriptor<TScope, TQueries, TMutations>, operationName: TOperationName, scope: TScope | null | undefined, args: ResourceQueryArgs<TQueries[TOperationName]>): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<ResourceQueryResult<TQueries[TOperationName]>, Error, ResourceQueryResult<TQueries[TOperationName]>, readonly unknown[]>, "queryFn"> & {
|
|
19
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<ResourceQueryResult<TQueries[TOperationName]>, readonly unknown[], never> | undefined;
|
|
20
|
+
} & {
|
|
21
|
+
queryKey: readonly unknown[] & {
|
|
22
|
+
[dataTagSymbol]: ResourceQueryResult<TQueries[TOperationName]>;
|
|
23
|
+
[dataTagErrorSymbol]: Error;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Подключает read-операцию ресурса к `useQuery`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function useResourceQuery<TScope, TQueries extends object, TMutations extends object, TOperationName extends Extract<keyof TQueries, string>>(descriptor: ResourceDescriptor<TScope, TQueries, TMutations>, operationName: TOperationName, scope: TScope | null | undefined, args: ResourceQueryArgs<TQueries[TOperationName]>): import("@tanstack/react-query").UseQueryResult<NoInfer<ResourceQueryResult<TQueries[TOperationName]>>, Error>;
|
|
30
|
+
/**
|
|
31
|
+
* Императивно загружает read-операцию ресурса через `QueryClient`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getResourceQueryData<TScope, TQueries extends object, TMutations extends object, TOperationName extends Extract<keyof TQueries, string>>(descriptor: ResourceDescriptor<TScope, TQueries, TMutations>, operationName: TOperationName, scope: TScope | null | undefined, args: ResourceQueryArgs<TQueries[TOperationName]>, queryClient: QueryClient): Promise<ResourceQueryResult<TQueries[TOperationName]>>;
|
|
34
|
+
/**
|
|
35
|
+
* Подключает write-операцию ресурса к `useMutation`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function useResourceMutation<TScope, TQueries extends object, TMutations extends object, TOperationName extends Extract<keyof TMutations, string>>(descriptor: ResourceDescriptor<TScope, TQueries, TMutations>, operationName: TOperationName, scope: TScope | null | undefined, options?: UseResourceMutationOptions<TScope, ResourceMutationInput<TMutations[TOperationName]>, ResourceMutationResult<TMutations[TOperationName]>, ResourceDescriptor<TScope, TQueries, TMutations>>): import("@tanstack/react-query").UseMutationResult<ResourceMutationResult<TMutations[TOperationName]>, Error, ResourceMutationInput<TMutations[TOperationName]>, unknown>;
|
|
38
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/resource/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuD,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAK9G,OAAO,KAAK,EACX,+BAA+B,EAC/B,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,0BAA0B,EAC1B,MAAM,SAAS,CAAC;AA0FjB;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,UAAU,SAAS,MAAM,GAAG,MAAM,EACpH,OAAO,EAAE,+BAA+B,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,GACpE,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAkBlD;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAA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E,UAAU,CAAC,EAC5D,aAAa,EAAE,cAAc,EAC7B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,IAAI,EAAE,iBAAiB,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,EACjD,WAAW,EAAE,WAAW,0DAGxB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EACN,QAAQ,SAAS,MAAM,EACvB,UAAU,SAAS,MAAM,EACzB,cAAc,SAAS,OAAO,CAAC,MAAM,UAAU,EAAE,MAAM,CAAC,EAExD,UAAU,EAAE,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,EAC5D,aAAa,EAAE,cAAc,EAC7B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,CAAC,EAAE,0BAA0B,CACnC,MAAM,EACN,qBAAqB,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,EACjD,sBAAsB,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,EAClD,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAChD,4KAyBD"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { QueryClient, QueryKey } from "@tanstack/react-query";
|
|
2
|
+
/**
|
|
3
|
+
* Значение, безопасное для включения в TanStack Query key.
|
|
4
|
+
*/
|
|
5
|
+
export type ResourceKeyValue = null | string | number | boolean | readonly ResourceKeyValue[] | {
|
|
6
|
+
readonly [key: string]: ResourceKeyValue;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Фабрика ключей generic-ресурса.
|
|
10
|
+
*/
|
|
11
|
+
export interface ResourceKeys<TScope, TOperationName extends string = string> {
|
|
12
|
+
readonly all: readonly unknown[];
|
|
13
|
+
scope: (scope: TScope | null | undefined) => readonly unknown[];
|
|
14
|
+
operation: (name: TOperationName, scope: TScope | null | undefined, args?: unknown) => readonly unknown[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Контекст read-операции ресурса.
|
|
18
|
+
*/
|
|
19
|
+
export interface ResourceQueryOperationContext<TScope, TArgs> {
|
|
20
|
+
readonly scope: TScope;
|
|
21
|
+
readonly args: TArgs;
|
|
22
|
+
readonly client: QueryClient;
|
|
23
|
+
readonly signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Контекст write-операции ресурса.
|
|
27
|
+
*/
|
|
28
|
+
export interface ResourceMutationOperationContext<TScope, TInput> {
|
|
29
|
+
readonly scope: TScope;
|
|
30
|
+
readonly input: TInput;
|
|
31
|
+
readonly client: QueryClient;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read-операция ресурса с произвольным именем.
|
|
35
|
+
*/
|
|
36
|
+
export interface ResourceQueryOperation<TScope, TArgs, TResult> {
|
|
37
|
+
execute(context: ResourceQueryOperationContext<TScope, TArgs>): Promise<TResult>;
|
|
38
|
+
isEnabled?(scope: TScope | null | undefined, args: TArgs): boolean;
|
|
39
|
+
readonly staleTime?: number;
|
|
40
|
+
readonly gcTime?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Контекст cache strategy после успешной write-операции.
|
|
44
|
+
*/
|
|
45
|
+
export interface ResourceCacheStrategyContext<TScope, TInput, TResult, TDescriptor> {
|
|
46
|
+
readonly client: QueryClient;
|
|
47
|
+
readonly descriptor: TDescriptor;
|
|
48
|
+
readonly scope: TScope;
|
|
49
|
+
readonly input: TInput;
|
|
50
|
+
readonly result: TResult;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Политика синхронизации TanStack Query cache после write-операции.
|
|
54
|
+
*/
|
|
55
|
+
export interface ResourceCacheStrategy<TScope, TInput, TResult, TDescriptor> {
|
|
56
|
+
onSuccess?(context: ResourceCacheStrategyContext<TScope, TInput, TResult, TDescriptor>): void | Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Write-операция ресурса с произвольным именем.
|
|
60
|
+
*/
|
|
61
|
+
export interface ResourceMutationOperation<TScope, TInput, TResult, TDescriptor> {
|
|
62
|
+
execute(context: ResourceMutationOperationContext<TScope, TInput>): Promise<TResult>;
|
|
63
|
+
readonly cacheStrategy?: ResourceCacheStrategy<TScope, TInput, TResult, TDescriptor>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Descriptor ресурса: scope policy, query keys и произвольные read/write операции.
|
|
67
|
+
*/
|
|
68
|
+
export interface ResourceDescriptor<TScope, TQueries extends object = object, TMutations extends object = object> {
|
|
69
|
+
readonly namespace: string;
|
|
70
|
+
readonly resource: string;
|
|
71
|
+
readonly keys: ResourceKeys<TScope, Extract<keyof TQueries | keyof TMutations, string>>;
|
|
72
|
+
readonly operations: {
|
|
73
|
+
readonly queries: TQueries;
|
|
74
|
+
readonly mutations: TMutations;
|
|
75
|
+
};
|
|
76
|
+
readonly isEnabled?: (scope: TScope | null | undefined) => boolean;
|
|
77
|
+
readonly getScopeError?: (scope: TScope | null | undefined) => string | null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Параметры создания generic-resource descriptor-а.
|
|
81
|
+
*/
|
|
82
|
+
export interface CreateResourceDescriptorOptions<TScope, TQueries extends object = object, TMutations extends object = object> {
|
|
83
|
+
readonly namespace: string;
|
|
84
|
+
readonly resource: string;
|
|
85
|
+
readonly operations: {
|
|
86
|
+
readonly queries?: TQueries;
|
|
87
|
+
readonly mutations?: TMutations;
|
|
88
|
+
};
|
|
89
|
+
readonly keys?: ResourceKeys<TScope, Extract<keyof TQueries | keyof TMutations, string>>;
|
|
90
|
+
readonly normalizeScope?: (scope: TScope | null | undefined) => unknown;
|
|
91
|
+
readonly isEnabled?: (scope: TScope | null | undefined) => boolean;
|
|
92
|
+
readonly getScopeError?: (scope: TScope | null | undefined) => string | null;
|
|
93
|
+
}
|
|
94
|
+
export type ResourceQueryArgs<TOperation> = TOperation extends ResourceQueryOperation<unknown, infer TArgs, unknown> ? TArgs : never;
|
|
95
|
+
export type ResourceQueryResult<TOperation> = TOperation extends ResourceQueryOperation<unknown, unknown, infer TResult> ? TResult : never;
|
|
96
|
+
export type ResourceMutationInput<TOperation> = TOperation extends ResourceMutationOperation<unknown, infer TInput, unknown, unknown> ? TInput : never;
|
|
97
|
+
export type ResourceMutationResult<TOperation> = TOperation extends ResourceMutationOperation<unknown, unknown, infer TResult, unknown> ? TResult : never;
|
|
98
|
+
/**
|
|
99
|
+
* Настройки mutation-хука ресурса.
|
|
100
|
+
*/
|
|
101
|
+
export interface UseResourceMutationOptions<TScope, TInput, TResult, TDescriptor> {
|
|
102
|
+
readonly cacheStrategy?: ResourceCacheStrategy<TScope, TInput, TResult, TDescriptor> | null;
|
|
103
|
+
readonly onSuccess?: (result: TResult, input: TInput) => void | Promise<void>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Настройки стратегии точечного обновления одного query.
|
|
107
|
+
*/
|
|
108
|
+
export interface ResourceSetQueryDataStrategyOptions<TScope, TInput, TResult, TData, TDescriptor> {
|
|
109
|
+
getQueryKey: (context: ResourceCacheStrategyContext<TScope, TInput, TResult, TDescriptor>) => QueryKey;
|
|
110
|
+
update: (current: TData | undefined, context: ResourceCacheStrategyContext<TScope, TInput, TResult, TDescriptor>) => TData;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resource/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACzB,IAAI,GACJ,MAAM,GACN,MAAM,GACN,OAAO,GACP,SAAS,gBAAgB,EAAE,GAC3B;IACA,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAC;CACxC,CAAC;AAEL;;GAEG;AACH,M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@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const BUCKET = "auditls-4f02df71";
|
|
2
|
+
export declare const BASE_PATH: string;
|
|
3
|
+
/**
|
|
4
|
+
* Имя сервиса (что-то типа прокси) для использования https://files-api.example.test в обход CORS
|
|
5
|
+
*/
|
|
6
|
+
export declare const S3_SERVICE_NAME = "TEXT_FILE_PROXY_SRV";
|
|
7
|
+
/**
|
|
8
|
+
* Имя сущности сервиса `SERVICE_NAME` для заливки файлов в S3
|
|
9
|
+
*/
|
|
10
|
+
export declare const ENTITY_NAME = "TEXT_FILE_UPLOAD";
|
|
11
|
+
export declare const S3_ENTITY_NAME = "s3File";
|
|
12
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/s3/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,eAAO,MAAM,SAAS,QAAmE,CAAC;AAE1F;;GAEG;AACH,eAAO,MAAM,eAAe,wBAAwB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,WAAW,qBAAqB,CAAC;AAG9C,eAAO,MAAM,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
2
|
+
export type S3ResponseData = {
|
|
3
|
+
fileContent: string;
|
|
4
|
+
objectName: string;
|
|
5
|
+
bucketName: string;
|
|
6
|
+
};
|
|
7
|
+
export type FetchS3Params = {
|
|
8
|
+
objectName: string;
|
|
9
|
+
bucketName: string;
|
|
10
|
+
client: QueryClient;
|
|
11
|
+
};
|
|
12
|
+
export declare function fetchFileFromS3({ client, bucketName, objectName }: FetchS3Params): Promise<import("../odata/odataFetchFn").ODataFetchFnRunnerResult<S3ResponseData>>;
|
|
13
|
+
//# sourceMappingURL=fetchFileFromS3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchFileFromS3.d.ts","sourceRoot":"","sources":["../../src/s3/fetchFileFromS3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAMpD,MAAM,MAAM,cAAc,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,WAAW,CAAC;CACpB,CAAC;AAEF,wBAAsB,eAAe,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,aAAa,qFAWtF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/s3/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC"}
|
package/dist/s3/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { r as e } from "../chunks/fetch-BW2OtCu7.js";
|
|
2
|
+
import { o as t } from "../chunks/odataFetchFn-BXVJxOou.js";
|
|
3
|
+
import { wrapODataParams as n } from "@ryuzaki13/react-foundation-lib/odata-service";
|
|
4
|
+
import { uuidv4 as r } from "@ryuzaki13/react-foundation-lib/crypto";
|
|
5
|
+
//#region src/s3/constants.ts
|
|
6
|
+
var i = "TEXT_FILE_PROXY_SRV", a = "TEXT_FILE_UPLOAD", o = "s3File";
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/s3/fetchFileFromS3.ts
|
|
9
|
+
async function s({ client: e, bucketName: r, objectName: a }) {
|
|
10
|
+
return t({
|
|
11
|
+
odata: {
|
|
12
|
+
service: i,
|
|
13
|
+
target: o
|
|
14
|
+
},
|
|
15
|
+
params: n({
|
|
16
|
+
objectName: a,
|
|
17
|
+
bucketName: r
|
|
18
|
+
}),
|
|
19
|
+
autoParse: !0
|
|
20
|
+
})({ client: e });
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/s3/uploadToS3.ts
|
|
24
|
+
async function c(t) {
|
|
25
|
+
let { bucket: n, filename: o, content: s } = t, { service: c, entity: l } = {
|
|
26
|
+
service: i,
|
|
27
|
+
entity: a
|
|
28
|
+
}, u = JSON.stringify({
|
|
29
|
+
fileContent: s,
|
|
30
|
+
bucketName: n ?? "",
|
|
31
|
+
objectName: o ?? `${r()}`
|
|
32
|
+
});
|
|
33
|
+
return e(`/${c}/${l}Set`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
body: JSON.stringify({ ImJson: u })
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { s as fetchFileFromS3, c as uploadToS3 };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/s3/constants.ts","../../src/s3/fetchFileFromS3.ts","../../src/s3/uploadToS3.ts"],"sourcesContent":["export const BUCKET = \"auditls-4f02df71\";\nexport const BASE_PATH = `${__DEV__ ? \"\" : \"https://files-api.example.test\"}/s3/1/object`;\n\n/**\n * Имя сервиса (что-то типа прокси) для использования https://files-api.example.test в обход CORS\n */\nexport const S3_SERVICE_NAME = \"TEXT_FILE_PROXY_SRV\";\n\n/**\n * Имя сущности сервиса `SERVICE_NAME` для заливки файлов в S3\n */\nexport const ENTITY_NAME = \"TEXT_FILE_UPLOAD\";\n\n// FIXME: теперь нужно понять, нужен ли вообще TEXT_FILE_UPLOAD?\nexport const S3_ENTITY_NAME = \"s3File\";\n","import { wrapODataParams } from \"@ryuzaki13/react-foundation-lib/odata-service\";\nimport { QueryClient } from \"@tanstack/react-query\";\n\nimport { odataReadFn } from \"../odata\";\n\nimport { S3_ENTITY_NAME, S3_SERVICE_NAME } from \"./constants\";\n\nexport type S3ResponseData = {\n\tfileContent: string;\n\tobjectName: string;\n\tbucketName: string;\n};\n\nexport type FetchS3Params = {\n\tobjectName: string;\n\tbucketName: string;\n\tclient: QueryClient;\n};\n\nexport async function fetchFileFromS3({ client, bucketName, objectName }: FetchS3Params) {\n\tconst queryFn = odataReadFn<S3ResponseData, S3ResponseData>({\n\t\todata: { service: S3_SERVICE_NAME, target: S3_ENTITY_NAME },\n\t\tparams: wrapODataParams({\n\t\t\tobjectName: objectName,\n\t\t\tbucketName: bucketName\n\t\t}),\n\t\tautoParse: true\n\t});\n\n\treturn queryFn({ client });\n}\n","import { uuidv4 } from \"@ryuzaki13/react-foundation-lib/crypto\";\n\nimport { fetchJson } from \"../odata/transport\";\n\nimport { ENTITY_NAME, S3_SERVICE_NAME } from \"./constants\";\n\n/**\n * Загрузка файла в виде base64 в хранилище S3\n */\nexport async function uploadToS3<R>(options: {\n\t// TODO: если будет необходимость в вариативности этих параметров, тогда раскоментировать код, связанный с odata\n\t/**\n\t * Если не указан, то используются значения по умолчанию:\n\t *\n\t * - service = \"TEXT_FILE_PROXY_SRV\"\n\t * - entity = \"TEXT_FILE_UPLOAD\"\n\t */\n\t// odata?: ODataServiceConfig;\n\n\tbucket?: string;\n\n\tfilename?: string;\n\t/**\n\t * Base64 file content\n\t */\n\tcontent: string;\n}) {\n\tconst { /*odata,*/ bucket, filename, content } = options;\n\tconst { service, entity } = /* odata ?? */ { service: S3_SERVICE_NAME, entity: ENTITY_NAME };\n\n\tconst requestBody = JSON.stringify({\n\t\tfileContent: content,\n\t\tbucketName: bucket ?? \"\",\n\t\tobjectName: filename ?? `${uuidv4()}`\n\t});\n\n\t// TODO: обновить на odataCreateFn\n\treturn fetchJson<R>(`/${service}/${entity}Set`, {\n\t\tmethod: \"POST\",\n\t\tbody: JSON.stringify({\n\t\t\tImJson: requestBody\n\t\t})\n\t});\n}\n"],"mappings":";;;;;AAMA,IAAa,IAAkB,uBAKlB,IAAc,oBAGd,IAAiB;;;ACK9B,eAAsB,EAAgB,EAAE,WAAQ,eAAY,iBAA6B;CAUxF,OATgB,EAA4C;EAC3D,OAAO;GAAE,SAAS;GAAiB,QAAQ;EAAe;EAC1D,QAAQ,EAAgB;GACX;GACA;EACb,CAAC;EACD,WAAW;CACZ,CAEO,CAAA,CAAQ,EAAE,UAAO,CAAC;AAC1B;;;ACrBA,eAAsB,EAAc,GAiBjC;CACF,IAAM,EAAa,WAAQ,aAAU,eAAY,GAC3C,EAAE,YAAS,cAA0B;EAAE,SAAS;EAAiB,QAAQ;CAAY,GAErF,IAAc,KAAK,UAAU;EAClC,aAAa;EACb,YAAY,KAAU;EACtB,YAAY,KAAY,GAAG,EAAO;CACnC,CAAC;CAGD,OAAO,EAAa,IAAI,EAAQ,GAAG,EAAO,MAAM;EAC/C,QAAQ;EACR,MAAM,KAAK,UAAU,EACpB,QAAQ,EACT,CAAC;CACF,CAAC;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Загрузка файла в виде base64 в хранилище S3
|
|
3
|
+
*/
|
|
4
|
+
export declare function uploadToS3<R>(options: {
|
|
5
|
+
/**
|
|
6
|
+
* Если не указан, то используются значения по умолчанию:
|
|
7
|
+
*
|
|
8
|
+
* - service = "TEXT_FILE_PROXY_SRV"
|
|
9
|
+
* - entity = "TEXT_FILE_UPLOAD"
|
|
10
|
+
*/
|
|
11
|
+
bucket?: string;
|
|
12
|
+
filename?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Base64 file content
|
|
15
|
+
*/
|
|
16
|
+
content: string;
|
|
17
|
+
}): Promise<R>;
|
|
18
|
+
//# sourceMappingURL=uploadToS3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadToS3.d.ts","sourceRoot":"","sources":["../../src/s3/uploadToS3.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE;IAE5C;;;;;OAKG;IAGH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CAChB,cAiBA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server-fn/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/server-fn/serverFn.ts
|
|
2
|
+
async function e(e, t, n, r) {
|
|
3
|
+
return await (r ?? ((e, t) => e(t)))(e, t, n);
|
|
4
|
+
}
|
|
5
|
+
function t(t) {
|
|
6
|
+
return {
|
|
7
|
+
isEnabled: t.isEnabled,
|
|
8
|
+
staleTime: t.staleTime,
|
|
9
|
+
gcTime: t.gcTime,
|
|
10
|
+
execute: async ({ scope: n, args: r, client: i, signal: a }) => {
|
|
11
|
+
let o = await e(t.serverFn, { data: t.buildData(n, r) }, {
|
|
12
|
+
client: i,
|
|
13
|
+
signal: a
|
|
14
|
+
}, t.executor);
|
|
15
|
+
return "transform" in t ? t.transform(o, {
|
|
16
|
+
scope: n,
|
|
17
|
+
args: r
|
|
18
|
+
}) : o;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function n(t) {
|
|
23
|
+
return {
|
|
24
|
+
cacheStrategy: t.cacheStrategy,
|
|
25
|
+
execute: async ({ scope: n, input: r, client: i }) => {
|
|
26
|
+
let a = await e(t.serverFn, { data: t.buildData(n, r) }, { client: i }, t.executor);
|
|
27
|
+
return "transform" in t ? t.transform(a, {
|
|
28
|
+
scope: n,
|
|
29
|
+
input: r
|
|
30
|
+
}) : a;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { n as createServerFnMutationOperation, t as createServerFnQueryOperation };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/server-fn/serverFn.ts"],"sourcesContent":["import { type QueryClient } from \"@tanstack/react-query\";\n\nimport { type ResourceMutationOperation, type ResourceQueryOperation } from \"../resource\";\n\n/**\n * Минимальный client-safe контракт TanStack Start server function.\n *\n * Shared-слой намеренно не импортирует `@tanstack/react-start`: в `SAP`\n * этот пакет не является зависимостью, а в SSR-проекте конкретная serverFn\n * вызывается с публичной формой `{ data }`.\n */\nexport type ServerFnTransport<TData, TResponse> = (request: ServerFnTransportRequest<TData>) => Promise<TResponse>;\n\n/**\n * Нормализованная форма вызова serverFn.\n */\nexport interface ServerFnTransportRequest<TData> {\n\treadonly data: TData;\n}\n\n/**\n * Контекст низкоуровневого serverFn executor.\n */\nexport interface ServerFnTransportExecutorContext {\n\treadonly client: QueryClient;\n\treadonly signal?: AbortSignal;\n}\n\n/**\n * Низкоуровневый executor нужен для тестов и нестандартных сценариев, где\n * вызов serverFn должен быть обёрнут дополнительной инфраструктурой проекта.\n */\nexport type ServerFnTransportExecutor<TData, TResponse> = (\n\tserverFn: ServerFnTransport<TData, TResponse>,\n\trequest: ServerFnTransportRequest<TData>,\n\tcontext: ServerFnTransportExecutorContext\n) => Promise<TResponse>;\n\ninterface ServerFnQueryOperationBaseOptions<TScope, TArgs, TData, TResponse> {\n\treadonly serverFn: ServerFnTransport<TData, TResponse>;\n\treadonly buildData: (scope: TScope, args: TArgs) => TData;\n\treadonly executor?: ServerFnTransportExecutor<TData, TResponse>;\n\treadonly staleTime?: number;\n\treadonly gcTime?: number;\n\treadonly isEnabled?: (scope: TScope | null | undefined, args: TArgs) => boolean;\n}\n\ntype ServerFnQueryOperationOptions<TScope, TArgs, TData, TResponse> = ServerFnQueryOperationBaseOptions<TScope, TArgs, TData, TResponse>;\n\ntype ServerFnMappedQueryOperationOptions<TScope, TArgs, TData, TResponse, TResult> = ServerFnQueryOperationBaseOptions<\n\tTScope,\n\tTArgs,\n\tTData,\n\tTResponse\n> & {\n\treadonly transform: (data: TResponse, context: { readonly scope: TScope; readonly args: TArgs }) => TResult;\n};\n\ninterface ServerFnMutationOperationBaseOptions<TScope, TInput, TData, TResponse> {\n\treadonly serverFn: ServerFnTransport<TData, TResponse>;\n\treadonly buildData: (scope: TScope, input: TInput) => TData;\n\treadonly executor?: ServerFnTransportExecutor<TData, TResponse>;\n}\n\ntype ServerFnMutationOperationOptions<TScope, TInput, TData, TResponse, TDescriptor> = ServerFnMutationOperationBaseOptions<\n\tTScope,\n\tTInput,\n\tTData,\n\tTResponse\n> & {\n\treadonly cacheStrategy?: ResourceMutationOperation<TScope, TInput, TResponse, TDescriptor>[\"cacheStrategy\"];\n};\n\ntype ServerFnMappedMutationOperationOptions<TScope, TInput, TData, TResponse, TResult, TDescriptor> = ServerFnMutationOperationBaseOptions<\n\tTScope,\n\tTInput,\n\tTData,\n\tTResponse\n> & {\n\treadonly transform: (data: TResponse, context: { readonly scope: TScope; readonly input: TInput }) => TResult;\n\treadonly cacheStrategy?: ResourceMutationOperation<TScope, TInput, TResult, TDescriptor>[\"cacheStrategy\"];\n};\n\nasync function executeServerFnTransport<TData, TResponse>(\n\tserverFn: ServerFnTransport<TData, TResponse>,\n\trequest: ServerFnTransportRequest<TData>,\n\tcontext: ServerFnTransportExecutorContext,\n\texecutor?: ServerFnTransportExecutor<TData, TResponse>\n) {\n\tconst run =\n\t\texecutor ??\n\t\t((currentServerFn: ServerFnTransport<TData, TResponse>, currentRequest: ServerFnTransportRequest<TData>) =>\n\t\t\tcurrentServerFn(currentRequest));\n\n\treturn await run(serverFn, request, context);\n}\n\nexport function createServerFnQueryOperation<TScope, TArgs, TData, TResponse>(\n\toptions: ServerFnQueryOperationOptions<TScope, TArgs, TData, TResponse>\n): ResourceQueryOperation<TScope, TArgs, TResponse>;\n\nexport function createServerFnQueryOperation<TScope, TArgs, TData, TResponse, TResult>(\n\toptions: ServerFnMappedQueryOperationOptions<TScope, TArgs, TData, TResponse, TResult>\n): ResourceQueryOperation<TScope, TArgs, TResult>;\n\n/**\n * Создаёт read-operation поверх TanStack Start serverFn.\n */\nexport function createServerFnQueryOperation<TScope, TArgs, TData, TResponse, TResult>(\n\toptions:\n\t\t| ServerFnQueryOperationOptions<TScope, TArgs, TData, TResponse>\n\t\t| ServerFnMappedQueryOperationOptions<TScope, TArgs, TData, TResponse, TResult>\n): ResourceQueryOperation<TScope, TArgs, TResponse | TResult> {\n\treturn {\n\t\tisEnabled: options.isEnabled,\n\t\tstaleTime: options.staleTime,\n\t\tgcTime: options.gcTime,\n\t\texecute: async ({ scope, args, client, signal }) => {\n\t\t\tconst response = await executeServerFnTransport(\n\t\t\t\toptions.serverFn,\n\t\t\t\t{ data: options.buildData(scope, args) },\n\t\t\t\t{ client, signal },\n\t\t\t\toptions.executor\n\t\t\t);\n\n\t\t\tif (\"transform\" in options) {\n\t\t\t\treturn options.transform(response, { scope, args });\n\t\t\t}\n\n\t\t\treturn response;\n\t\t}\n\t};\n}\n\nexport function createServerFnMutationOperation<TScope, TInput, TData, TResponse, TDescriptor>(\n\toptions: ServerFnMutationOperationOptions<TScope, TInput, TData, TResponse, TDescriptor>\n): ResourceMutationOperation<TScope, TInput, TResponse, TDescriptor>;\n\nexport function createServerFnMutationOperation<TScope, TInput, TData, TResponse, TResult, TDescriptor>(\n\toptions: ServerFnMappedMutationOperationOptions<TScope, TInput, TData, TResponse, TResult, TDescriptor>\n): ResourceMutationOperation<TScope, TInput, TResult, TDescriptor>;\n\n/**\n * Создаёт write-operation поверх TanStack Start serverFn.\n */\nexport function createServerFnMutationOperation<TScope, TInput, TData, TResponse, TResult, TDescriptor>(\n\toptions:\n\t\t| ServerFnMutationOperationOptions<TScope, TInput, TData, TResponse, TDescriptor>\n\t\t| ServerFnMappedMutationOperationOptions<TScope, TInput, TData, TResponse, TResult, TDescriptor>\n): ResourceMutationOperation<TScope, TInput, TResponse | TResult, TDescriptor> {\n\treturn {\n\t\tcacheStrategy: options.cacheStrategy,\n\t\texecute: async ({ scope, input, client }) => {\n\t\t\tconst response = await executeServerFnTransport(\n\t\t\t\toptions.serverFn,\n\t\t\t\t{ data: options.buildData(scope, input) },\n\t\t\t\t{ client },\n\t\t\t\toptions.executor\n\t\t\t);\n\n\t\t\tif (\"transform\" in options) {\n\t\t\t\treturn options.transform(response, { scope, input });\n\t\t\t}\n\n\t\t\treturn response;\n\t\t}\n\t};\n}\n"],"mappings":";AAmFA,eAAe,EACd,GACA,GACA,GACA,GACC;CAMD,OAAO,OAJN,OACE,GAAsD,MACvD,EAAgB,CAAc,GAAA,CAEf,GAAU,GAAS,CAAO;AAC5C;AAaA,SAAgB,EACf,GAG6D;CAC7D,OAAO;EACN,WAAW,EAAQ;EACnB,WAAW,EAAQ;EACnB,QAAQ,EAAQ;EAChB,SAAS,OAAO,EAAE,UAAO,SAAM,WAAQ,gBAAa;GACnD,IAAM,IAAW,MAAM,EACtB,EAAQ,UACR,EAAE,MAAM,EAAQ,UAAU,GAAO,CAAI,EAAE,GACvC;IAAE;IAAQ;GAAO,GACjB,EAAQ,QACT;GAMA,OAJI,eAAe,IACX,EAAQ,UAAU,GAAU;IAAE;IAAO;GAAK,CAAC,IAG5C;EACR;CACD;AACD;AAaA,SAAgB,EACf,GAG8E;CAC9E,OAAO;EACN,eAAe,EAAQ;EACvB,SAAS,OAAO,EAAE,UAAO,UAAO,gBAAa;GAC5C,IAAM,IAAW,MAAM,EACtB,EAAQ,UACR,EAAE,MAAM,EAAQ,UAAU,GAAO,CAAK,EAAE,GACxC,EAAE,UAAO,GACT,EAAQ,QACT;GAMA,OAJI,eAAe,IACX,EAAQ,UAAU,GAAU;IAAE;IAAO;GAAM,CAAC,IAG7C;EACR;CACD;AACD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type QueryClient } from "@tanstack/react-query";
|
|
2
|
+
import { type ResourceMutationOperation, type ResourceQueryOperation } from "../resource";
|
|
3
|
+
/**
|
|
4
|
+
* Минимальный client-safe контракт TanStack Start server function.
|
|
5
|
+
*
|
|
6
|
+
* Shared-слой намеренно не импортирует `@tanstack/react-start`: в `SAP`
|
|
7
|
+
* этот пакет не является зависимостью, а в SSR-проекте конкретная serverFn
|
|
8
|
+
* вызывается с публичной формой `{ data }`.
|
|
9
|
+
*/
|
|
10
|
+
export type ServerFnTransport<TData, TResponse> = (request: ServerFnTransportRequest<TData>) => Promise<TResponse>;
|
|
11
|
+
/**
|
|
12
|
+
* Нормализованная форма вызова serverFn.
|
|
13
|
+
*/
|
|
14
|
+
export interface ServerFnTransportRequest<TData> {
|
|
15
|
+
readonly data: TData;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Контекст низкоуровневого serverFn executor.
|
|
19
|
+
*/
|
|
20
|
+
export interface ServerFnTransportExecutorContext {
|
|
21
|
+
readonly client: QueryClient;
|
|
22
|
+
readonly signal?: AbortSignal;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Низкоуровневый executor нужен для тестов и нестандартных сценариев, где
|
|
26
|
+
* вызов serverFn должен быть обёрнут дополнительной инфраструктурой проекта.
|
|
27
|
+
*/
|
|
28
|
+
export type ServerFnTransportExecutor<TData, TResponse> = (serverFn: ServerFnTransport<TData, TResponse>, request: ServerFnTransportRequest<TData>, context: ServerFnTransportExecutorContext) => Promise<TResponse>;
|
|
29
|
+
interface ServerFnQueryOperationBaseOptions<TScope, TArgs, TData, TResponse> {
|
|
30
|
+
readonly serverFn: ServerFnTransport<TData, TResponse>;
|
|
31
|
+
readonly buildData: (scope: TScope, args: TArgs) => TData;
|
|
32
|
+
readonly executor?: ServerFnTransportExecutor<TData, TResponse>;
|
|
33
|
+
readonly staleTime?: number;
|
|
34
|
+
readonly gcTime?: number;
|
|
35
|
+
readonly isEnabled?: (scope: TScope | null | undefined, args: TArgs) => boolean;
|
|
36
|
+
}
|
|
37
|
+
type ServerFnQueryOperationOptions<TScope, TArgs, TData, TResponse> = ServerFnQueryOperationBaseOptions<TScope, TArgs, TData, TResponse>;
|
|
38
|
+
type ServerFnMappedQueryOperationOptions<TScope, TArgs, TData, TResponse, TResult> = ServerFnQueryOperationBaseOptions<TScope, TArgs, TData, TResponse> & {
|
|
39
|
+
readonly transform: (data: TResponse, context: {
|
|
40
|
+
readonly scope: TScope;
|
|
41
|
+
readonly args: TArgs;
|
|
42
|
+
}) => TResult;
|
|
43
|
+
};
|
|
44
|
+
interface ServerFnMutationOperationBaseOptions<TScope, TInput, TData, TResponse> {
|
|
45
|
+
readonly serverFn: ServerFnTransport<TData, TResponse>;
|
|
46
|
+
readonly buildData: (scope: TScope, input: TInput) => TData;
|
|
47
|
+
readonly executor?: ServerFnTransportExecutor<TData, TResponse>;
|
|
48
|
+
}
|
|
49
|
+
type ServerFnMutationOperationOptions<TScope, TInput, TData, TResponse, TDescriptor> = ServerFnMutationOperationBaseOptions<TScope, TInput, TData, TResponse> & {
|
|
50
|
+
readonly cacheStrategy?: ResourceMutationOperation<TScope, TInput, TResponse, TDescriptor>["cacheStrategy"];
|
|
51
|
+
};
|
|
52
|
+
type ServerFnMappedMutationOperationOptions<TScope, TInput, TData, TResponse, TResult, TDescriptor> = ServerFnMutationOperationBaseOptions<TScope, TInput, TData, TResponse> & {
|
|
53
|
+
readonly transform: (data: TResponse, context: {
|
|
54
|
+
readonly scope: TScope;
|
|
55
|
+
readonly input: TInput;
|
|
56
|
+
}) => TResult;
|
|
57
|
+
readonly cacheStrategy?: ResourceMutationOperation<TScope, TInput, TResult, TDescriptor>["cacheStrategy"];
|
|
58
|
+
};
|
|
59
|
+
export declare function createServerFnQueryOperation<TScope, TArgs, TData, TResponse>(options: ServerFnQueryOperationOptions<TScope, TArgs, TData, TResponse>): ResourceQueryOperation<TScope, TArgs, TResponse>;
|
|
60
|
+
export declare function createServerFnQueryOperation<TScope, TArgs, TData, TResponse, TResult>(options: ServerFnMappedQueryOperationOptions<TScope, TArgs, TData, TResponse, TResult>): ResourceQueryOperation<TScope, TArgs, TResult>;
|
|
61
|
+
export declare function createServerFnMutationOperation<TScope, TInput, TData, TResponse, TDescriptor>(options: ServerFnMutationOperationOptions<TScope, TInput, TData, TResponse, TDescriptor>): ResourceMutationOperation<TScope, TInput, TResponse, TDescriptor>;
|
|
62
|
+
export declare function createServerFnMutationOperation<TScope, TInput, TData, TResponse, TResult, TDescriptor>(options: ServerFnMappedMutationOperationOptions<TScope, TInput, TData, TResponse, TResult, TDescriptor>): ResourceMutationOperation<TScope, TInput, TResult, TDescriptor>;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=serverFn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverFn.d.ts","sourceRoot":"","sources":["../../src/server-fn/serverFn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,KAAK,yBAAyB,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1F;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC,OAAO,EAAE,wBAAwB,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAEnH;;GAEG;AACH,MAAM,WAAW,wBAAwB,CAAC,KAAK;IAC9C,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAChD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,CAAC,KAAK,EAAE,SAAS,IAAI,CACzD,QAAQ,EAAE,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,EAC7C,OAAO,EAAE,wBAAwB,CAAC,KAAK,CAAC,EACxC,OAAO,EAAE,gCAAgC,KACrC,OAAO,CAAC,SA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E,OAAO,EACpF,OAAO,EAAE,mCAAmC,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,GACpF,sBAAsB,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AA+BlD,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAC5F,OAAO,EAAE,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC,GACtF,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AAErE,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EACrG,OAAO,EAAE,sCAAsC,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,GACrG,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TransportRequest, TransportRequestScope, UserTransportRequests } from "./types";
|
|
2
|
+
export declare const transportRequestKeys: {
|
|
3
|
+
all: readonly ["transportRequests"];
|
|
4
|
+
list: (scope?: TransportRequestScope) => readonly ["transportRequests", TransportRequestScope];
|
|
5
|
+
};
|
|
6
|
+
export declare function getTransportRequestKey(request: Pick<TransportRequest, "id" | "type">): string;
|
|
7
|
+
export declare function fetchWorkbenchTransportRequests(): Promise<TransportRequest[]>;
|
|
8
|
+
export declare function fetchCustomizingTransportRequests(): Promise<TransportRequest[]>;
|
|
9
|
+
export declare function fetchUserTransportRequests(): Promise<UserTransportRequests>;
|
|
10
|
+
export declare function fetchTransportRequests(scope?: TransportRequestScope): Promise<TransportRequest[]>;
|
|
11
|
+
//# sourceMappingURL=fetchTransportRequests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchTransportRequests.d.ts","sourceRoot":"","sources":["../../src/transport/fetchTransportRequests.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAuB,qBAAqB,EAAwB,qBAAqB,EAAE,MAAM,SAAS,CAAC;AASzI,eAAO,MAAM,oBAAoB;;mBAElB,qBAAqB;CACnC,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,GAAG,MAAM,CAAC,UAEpF;AAOD,wBAAsB,+BAA+B,gCAEpD;AAED,wBAAsB,iCAAiC,gCAEtD;AAED,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAQjF;AAED,wBAAsB,sBAAsB,CAAC,KAAK,GAAE,qBAAmC,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAUpH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { r as e } from "../chunks/fetch-BW2OtCu7.js";
|
|
2
|
+
import { normalizeTextWithFallback as t } from "@ryuzaki13/react-foundation-lib/formatters";
|
|
3
|
+
//#region src/transport/normalizeTransportRequests.ts
|
|
4
|
+
function n(e, n) {
|
|
5
|
+
let r = /* @__PURE__ */ new Set();
|
|
6
|
+
return e.flatMap((e) => {
|
|
7
|
+
let i = t(e.id);
|
|
8
|
+
return !i || r.has(i) ? [] : (r.add(i), [{
|
|
9
|
+
id: i,
|
|
10
|
+
type: n,
|
|
11
|
+
text: t(e.description),
|
|
12
|
+
isDefaultRequest: e.isDefaultRequest === !0
|
|
13
|
+
}]);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/transport/fetchTransportRequests.ts
|
|
18
|
+
var r = "odataUi2", i = {
|
|
19
|
+
workbench: "/TRANSPORT/WorkbenchRequests",
|
|
20
|
+
customizing: "/TRANSPORT/CustomizingRequests"
|
|
21
|
+
}, a = {
|
|
22
|
+
all: ["transportRequests"],
|
|
23
|
+
list: (e = "workbench") => [...a.all, e]
|
|
24
|
+
};
|
|
25
|
+
function o(e) {
|
|
26
|
+
return `${e.type}:${e.id}`;
|
|
27
|
+
}
|
|
28
|
+
async function s(t) {
|
|
29
|
+
let a = await e(i[t], void 0, r);
|
|
30
|
+
return a ? n(a, t) : [];
|
|
31
|
+
}
|
|
32
|
+
async function c() {
|
|
33
|
+
return s("workbench");
|
|
34
|
+
}
|
|
35
|
+
async function l() {
|
|
36
|
+
return s("customizing");
|
|
37
|
+
}
|
|
38
|
+
async function u() {
|
|
39
|
+
let [e, t] = await Promise.all([c(), l()]);
|
|
40
|
+
return {
|
|
41
|
+
workbench: e,
|
|
42
|
+
customizing: t,
|
|
43
|
+
all: [...e, ...t]
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function d(e = "workbench") {
|
|
47
|
+
return e === "workbench" ? c() : e === "customizing" ? l() : (await u()).all;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { l as fetchCustomizingTransportRequests, d as fetchTransportRequests, u as fetchUserTransportRequests, c as fetchWorkbenchTransportRequests, o as getTransportRequestKey, n as normalizeTransportRequests, a as transportRequestKeys };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/transport/normalizeTransportRequests.ts","../../src/transport/fetchTransportRequests.ts"],"sourcesContent":["import { normalizeTextWithFallback } from \"@ryuzaki13/react-foundation-lib/formatters\";\n\nimport type { TransportRequest, TransportRequestRaw, TransportRequestType } from \"./types\";\n\nexport function normalizeTransportRequests(items: TransportRequestRaw[], type: TransportRequestType): TransportRequest[] {\n\tconst seen = new Set<string>();\n\n\treturn items.flatMap((item) => {\n\t\tconst id = normalizeTextWithFallback(item.id);\n\t\tif (!id || seen.has(id)) return [];\n\n\t\tseen.add(id);\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\ttype,\n\t\t\t\ttext: normalizeTextWithFallback(item.description),\n\t\t\t\tisDefaultRequest: item.isDefaultRequest === true\n\t\t\t}\n\t\t];\n\t});\n}\n","import { fetchJson } from \"../odata/transport\";\n\nimport { normalizeTransportRequests } from \"./normalizeTransportRequests\";\n\nimport type { TransportRequest, TransportRequestRaw, TransportRequestScope, TransportRequestType, UserTransportRequests } from \"./types\";\n\nconst TRANSPORT_SERVICE_BASE_URL = \"odataUi2\";\n\nconst TRANSPORT_REQUEST_PATHS: Record<TransportRequestType, string> = {\n\tworkbench: \"/TRANSPORT/WorkbenchRequests\",\n\tcustomizing: \"/TRANSPORT/CustomizingRequests\"\n};\n\nexport const transportRequestKeys = {\n\tall: [\"transportRequests\"] as const,\n\tlist: (scope: TransportRequestScope = \"workbench\") => [...transportRequestKeys.all, scope] as const\n};\n\nexport function getTransportRequestKey(request: Pick<TransportRequest, \"id\" | \"type\">) {\n\treturn `${request.type}:${request.id}`;\n}\n\nasync function fetchTransportRequestsByType(type: TransportRequestType): Promise<TransportRequest[]> {\n\tconst items = await fetchJson<TransportRequestRaw[]>(TRANSPORT_REQUEST_PATHS[type], undefined, TRANSPORT_SERVICE_BASE_URL);\n\treturn items ? normalizeTransportRequests(items, type) : [];\n}\n\nexport async function fetchWorkbenchTransportRequests() {\n\treturn fetchTransportRequestsByType(\"workbench\");\n}\n\nexport async function fetchCustomizingTransportRequests() {\n\treturn fetchTransportRequestsByType(\"customizing\");\n}\n\nexport async function fetchUserTransportRequests(): Promise<UserTransportRequests> {\n\tconst [workbench, customizing] = await Promise.all([fetchWorkbenchTransportRequests(), fetchCustomizingTransportRequests()]);\n\n\treturn {\n\t\tworkbench,\n\t\tcustomizing,\n\t\tall: [...workbench, ...customizing]\n\t};\n}\n\nexport async function fetchTransportRequests(scope: TransportRequestScope = \"workbench\"): Promise<TransportRequest[]> {\n\tif (scope === \"workbench\") {\n\t\treturn fetchWorkbenchTransportRequests();\n\t}\n\n\tif (scope === \"customizing\") {\n\t\treturn fetchCustomizingTransportRequests();\n\t}\n\n\treturn (await fetchUserTransportRequests()).all;\n}\n"],"mappings":";;;AAIA,SAAgB,EAA2B,GAA8B,GAAgD;CACxH,IAAM,oBAAO,IAAI,IAAY;CAE7B,OAAO,EAAM,SAAS,MAAS;EAC9B,IAAM,IAAK,EAA0B,EAAK,EAAE;EAK5C,OAJI,CAAC,KAAM,EAAK,IAAI,CAAE,IAAU,CAAC,KAEjC,EAAK,IAAI,CAAE,GAEJ,CACN;GACC;GACA;GACA,MAAM,EAA0B,EAAK,WAAW;GAChD,kBAAkB,EAAK,qBAAqB;EAC7C,CACD;CACD,CAAC;AACF;;;AChBA,IAAM,IAA6B,YAE7B,IAAgE;CACrE,WAAW;CACX,aAAa;AACd,GAEa,IAAuB;CACnC,KAAK,CAAC,mBAAmB;CACzB,OAAO,IAA+B,gBAAgB,CAAC,GAAG,EAAqB,KAAK,CAAK;AAC1F;AAEA,SAAgB,EAAuB,GAAgD;CACtF,OAAO,GAAG,EAAQ,KAAK,GAAG,EAAQ;AACnC;AAEA,eAAe,EAA6B,GAAyD;CACpG,IAAM,IAAQ,MAAM,EAAiC,EAAwB,IAAO,KAAA,GAAW,CAA0B;CACzH,OAAO,IAAQ,EAA2B,GAAO,CAAI,IAAI,CAAC;AAC3D;AAEA,eAAsB,IAAkC;CACvD,OAAO,EAA6B,WAAW;AAChD;AAEA,eAAsB,IAAoC;CACzD,OAAO,EAA6B,aAAa;AAClD;AAEA,eAAsB,IAA6D;CAClF,IAAM,CAAC,GAAW,KAAe,MAAM,QAAQ,IAAI,CAAC,EAAgC,GAAG,EAAkC,CAAC,CAAC;CAE3H,OAAO;EACN;EACA;EACA,KAAK,CAAC,GAAG,GAAW,GAAG,CAAW;CACnC;AACD;AAEA,eAAsB,EAAuB,IAA+B,aAA0C;CASrH,OARI,MAAU,cACN,EAAgC,IAGpC,MAAU,gBACN,EAAkC,KAGlC,MAAM,EAA2B,EAAA,CAAG;AAC7C"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TransportRequest, TransportRequestRaw, TransportRequestType } from "./types";
|
|
2
|
+
export declare function normalizeTransportRequests(items: TransportRequestRaw[], type: TransportRequestType): TransportRequest[];
|
|
3
|
+
//# sourceMappingURL=normalizeTransportRequests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeTransportRequests.d.ts","sourceRoot":"","sources":["../../src/transport/normalizeTransportRequests.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE3F,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,mBAAmB,EAAE,EAAE,IAAI,EAAE,oBAAoB,GAAG,gBAAgB,EAAE,CAkBvH"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type TransportRequestType = "workbench" | "customizing";
|
|
2
|
+
export type TransportRequestScope = TransportRequestType | "all";
|
|
3
|
+
export interface TransportRequest {
|
|
4
|
+
id: string;
|
|
5
|
+
type: TransportRequestType;
|
|
6
|
+
text: string;
|
|
7
|
+
isDefaultRequest: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface TransportRequestRaw {
|
|
10
|
+
id?: string | null;
|
|
11
|
+
description?: string | null;
|
|
12
|
+
isDefaultRequest?: boolean | null;
|
|
13
|
+
}
|
|
14
|
+
export interface UserTransportRequests {
|
|
15
|
+
workbench: TransportRequest[];
|
|
16
|
+
customizing: TransportRequest[];
|
|
17
|
+
all: TransportRequest[];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/transport/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG,aAAa,CAAC;AAC/D,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,GAAG,KAAK,CAAC;AAEjE,MAAM,WAAW,gBAAgB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,oBAAoB,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IACnC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,qBAAqB;IACrC,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC9B,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,GAAG,EAAE,gBAAgB,EAAE,CAAC;CACxB"}
|