@reactionary/source 0.0.51 → 0.0.52
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/core/package.json +4 -3
- package/core/src/cache/cache.interface.ts +1 -1
- package/core/src/cache/memory-cache.ts +2 -2
- package/core/src/cache/noop-cache.ts +1 -1
- package/core/src/cache/redis-cache.ts +1 -1
- package/core/src/client/client-builder.ts +4 -4
- package/core/src/client/client.ts +11 -11
- package/core/src/decorators/reactionary.decorator.ts +22 -2
- package/core/src/index.ts +14 -14
- package/core/src/initialization.ts +1 -1
- package/core/src/providers/analytics.provider.ts +2 -2
- package/core/src/providers/base.provider.ts +5 -5
- package/core/src/providers/cart.provider.ts +6 -6
- package/core/src/providers/category.provider.ts +4 -9
- package/core/src/providers/checkout.provider.ts +5 -5
- package/core/src/providers/identity.provider.ts +5 -5
- package/core/src/providers/index.ts +13 -13
- package/core/src/providers/inventory.provider.ts +4 -4
- package/core/src/providers/order.provider.ts +4 -4
- package/core/src/providers/price.provider.ts +5 -5
- package/core/src/providers/product.provider.ts +4 -4
- package/core/src/providers/profile.provider.ts +5 -5
- package/core/src/providers/search.provider.ts +4 -4
- package/core/src/providers/store.provider.ts +4 -4
- package/core/src/schemas/models/analytics.model.ts +1 -1
- package/core/src/schemas/models/cart.model.ts +3 -9
- package/core/src/schemas/models/category.model.ts +2 -2
- package/core/src/schemas/models/checkout.model.ts +6 -8
- package/core/src/schemas/models/cost.model.ts +1 -1
- package/core/src/schemas/models/identity.model.ts +2 -2
- package/core/src/schemas/models/index.ts +19 -19
- package/core/src/schemas/models/inventory.model.ts +2 -2
- package/core/src/schemas/models/order.model.ts +6 -7
- package/core/src/schemas/models/payment.model.ts +3 -3
- package/core/src/schemas/models/price.model.ts +3 -3
- package/core/src/schemas/models/product.model.ts +2 -2
- package/core/src/schemas/models/profile.model.ts +2 -2
- package/core/src/schemas/models/search.model.ts +2 -3
- package/core/src/schemas/models/shipping-method.model.ts +4 -4
- package/core/src/schemas/models/store.model.ts +2 -2
- package/core/src/schemas/mutations/analytics.mutation.ts +2 -2
- package/core/src/schemas/mutations/cart.mutation.ts +5 -5
- package/core/src/schemas/mutations/checkout.mutation.ts +2 -2
- package/core/src/schemas/mutations/identity.mutation.ts +1 -1
- package/core/src/schemas/mutations/index.ts +10 -10
- package/core/src/schemas/mutations/profile.mutation.ts +1 -1
- package/core/src/schemas/queries/cart.query.ts +2 -2
- package/core/src/schemas/queries/category.query.ts +3 -3
- package/core/src/schemas/queries/checkout.query.ts +2 -2
- package/core/src/schemas/queries/identity.query.ts +1 -1
- package/core/src/schemas/queries/index.ts +13 -13
- package/core/src/schemas/queries/inventory.query.ts +2 -2
- package/core/src/schemas/queries/order.query.ts +2 -2
- package/core/src/schemas/queries/price.query.ts +2 -2
- package/core/src/schemas/queries/product.query.ts +2 -2
- package/core/src/schemas/queries/profile.query.ts +1 -1
- package/core/src/schemas/queries/search.query.ts +2 -2
- package/core/src/schemas/queries/store.query.ts +1 -1
- package/core/src/schemas/session.schema.ts +3 -3
- package/core/tsconfig.json +3 -2
- package/examples/next/next.config.js +17 -6
- package/examples/next/src/app/page.tsx +1 -2
- package/examples/node/package.json +2 -1
- package/examples/node/src/basic/basic-node-setup.spec.ts +1 -1
- package/examples/node/tsconfig.json +2 -1
- package/examples/node/tsconfig.spec.json +3 -2
- package/package.json +1 -1
- package/providers/algolia/package.json +2 -1
- package/providers/algolia/src/core/initialize.ts +5 -5
- package/providers/algolia/src/index.ts +5 -5
- package/providers/algolia/src/providers/product.provider.ts +1 -1
- package/providers/algolia/src/providers/search.provider.ts +1 -1
- package/providers/algolia/src/test/search.provider.spec.ts +1 -1
- package/providers/algolia/tsconfig.json +2 -1
- package/providers/algolia/tsconfig.spec.json +3 -2
- package/providers/commercetools/{jest.config.ts → jest.config.cjs} +1 -1
- package/providers/commercetools/package.json +2 -2
- package/providers/commercetools/src/core/client.ts +1 -1
- package/providers/commercetools/src/core/initialize.ts +10 -10
- package/providers/commercetools/src/index.ts +10 -10
- package/providers/commercetools/src/providers/cart.provider.ts +4 -18
- package/providers/commercetools/src/providers/category.provider.ts +3 -12
- package/providers/commercetools/src/providers/checkout.provider.ts +5 -5
- package/providers/commercetools/src/providers/identity.provider.ts +2 -2
- package/providers/commercetools/src/providers/index.ts +11 -11
- package/providers/commercetools/src/providers/inventory.provider.ts +2 -4
- package/providers/commercetools/src/providers/order.provider.ts +4 -6
- package/providers/commercetools/src/providers/price.provider.ts +2 -2
- package/providers/commercetools/src/providers/product.provider.ts +2 -7
- package/providers/commercetools/src/providers/profile.provider.ts +2 -2
- package/providers/commercetools/src/providers/search.provider.ts +3 -5
- package/providers/commercetools/src/providers/store.provider.ts +3 -3
- package/providers/commercetools/src/schema/commercetools.schema.ts +1 -1
- package/providers/commercetools/src/test/cart.provider.spec.ts +4 -4
- package/providers/commercetools/src/test/category.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/checkout.provider.spec.ts +4 -4
- package/providers/commercetools/src/test/identity.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/inventory.provider.spec.ts +2 -2
- package/providers/commercetools/src/test/price.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/product.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/profile.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/search.provider.spec.ts +2 -2
- package/providers/commercetools/src/test/store.provider.spec.ts +2 -2
- package/providers/commercetools/tsconfig.json +2 -1
- package/providers/commercetools/tsconfig.spec.json +4 -3
- package/providers/fake/{jest.config.ts → jest.config.cjs} +1 -1
- package/providers/fake/package.json +2 -2
- package/providers/fake/src/core/initialize.ts +6 -6
- package/providers/fake/src/index.ts +4 -4
- package/providers/fake/src/providers/analytics.provider.ts +1 -1
- package/providers/fake/src/providers/cart.provider.ts +2 -2
- package/providers/fake/src/providers/category.provider.ts +2 -2
- package/providers/fake/src/providers/identity.provider.ts +1 -1
- package/providers/fake/src/providers/index.ts +9 -9
- package/providers/fake/src/providers/inventory.provider.ts +1 -1
- package/providers/fake/src/providers/price.provider.ts +1 -1
- package/providers/fake/src/providers/product.provider.ts +1 -1
- package/providers/fake/src/providers/search.provider.ts +2 -5
- package/providers/fake/src/providers/store.provider.ts +2 -3
- package/providers/fake/src/test/cart.provider.spec.ts +3 -3
- package/providers/fake/src/test/category.provider.spec.ts +2 -2
- package/providers/fake/src/test/price.provider.spec.ts +2 -2
- package/providers/fake/src/test/product.provider.spec.ts +3 -3
- package/providers/fake/src/test/test-utils.ts +1 -1
- package/providers/fake/tsconfig.json +2 -1
- package/providers/fake/tsconfig.spec.json +1 -3
- package/providers/posthog/package.json +4 -4
- package/providers/posthog/project.json +2 -2
- package/providers/posthog/src/core/initialize.ts +2 -2
- package/providers/posthog/src/index.ts +3 -3
- package/providers/posthog/tsconfig.json +2 -1
- package/tsconfig.base.json +3 -4
- package/otel/README.md +0 -227
- package/otel/eslint.config.mjs +0 -23
- package/otel/package.json +0 -11
- package/otel/pnpm-lock.yaml +0 -805
- package/otel/project.json +0 -33
- package/otel/src/index.ts +0 -22
- package/otel/src/metrics.ts +0 -76
- package/otel/src/provider-instrumentation.ts +0 -108
- package/otel/src/test/otel.spec.ts +0 -8
- package/otel/src/trace-decorator.ts +0 -226
- package/otel/src/tracer.ts +0 -83
- package/otel/src/trpc-middleware.ts +0 -128
- package/otel/tsconfig.json +0 -23
- package/otel/tsconfig.lib.json +0 -23
- package/otel/tsconfig.spec.json +0 -28
- package/otel/vite.config.ts +0 -24
- package/trpc/README.md +0 -7
- package/trpc/__mocks__/superjson.js +0 -25
- package/trpc/eslint.config.mjs +0 -19
- package/trpc/jest.config.ts +0 -14
- package/trpc/package.json +0 -14
- package/trpc/project.json +0 -31
- package/trpc/src/client.ts +0 -175
- package/trpc/src/index.ts +0 -44
- package/trpc/src/integration.spec.ts +0 -223
- package/trpc/src/server.ts +0 -125
- package/trpc/src/transparent-client.spec.ts +0 -161
- package/trpc/src/types.ts +0 -144
- package/trpc/tsconfig.json +0 -16
- package/trpc/tsconfig.lib.json +0 -10
- package/trpc/tsconfig.spec.json +0 -15
package/otel/tsconfig.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"forceConsistentCasingInFileNames": true,
|
|
6
|
-
"strict": true,
|
|
7
|
-
"importHelpers": true,
|
|
8
|
-
"noImplicitOverride": true,
|
|
9
|
-
"noImplicitReturns": true,
|
|
10
|
-
"noFallthroughCasesInSwitch": true,
|
|
11
|
-
"noPropertyAccessFromIndexSignature": true
|
|
12
|
-
},
|
|
13
|
-
"files": [],
|
|
14
|
-
"include": [],
|
|
15
|
-
"references": [
|
|
16
|
-
{
|
|
17
|
-
"path": "./tsconfig.lib.json"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"path": "./tsconfig.spec.json"
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
}
|
package/otel/tsconfig.lib.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../dist/out-tsc",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"types": ["node"]
|
|
7
|
-
},
|
|
8
|
-
"include": ["src/**/*.ts"],
|
|
9
|
-
"exclude": [
|
|
10
|
-
"vite.config.ts",
|
|
11
|
-
"vite.config.mts",
|
|
12
|
-
"vitest.config.ts",
|
|
13
|
-
"vitest.config.mts",
|
|
14
|
-
"src/**/*.test.ts",
|
|
15
|
-
"src/**/*.spec.ts",
|
|
16
|
-
"src/**/*.test.tsx",
|
|
17
|
-
"src/**/*.spec.tsx",
|
|
18
|
-
"src/**/*.test.js",
|
|
19
|
-
"src/**/*.spec.js",
|
|
20
|
-
"src/**/*.test.jsx",
|
|
21
|
-
"src/**/*.spec.jsx"
|
|
22
|
-
]
|
|
23
|
-
}
|
package/otel/tsconfig.spec.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../dist/out-tsc",
|
|
5
|
-
"types": [
|
|
6
|
-
"vitest/globals",
|
|
7
|
-
"vitest/importMeta",
|
|
8
|
-
"vite/client",
|
|
9
|
-
"node",
|
|
10
|
-
"vitest"
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
"include": [
|
|
14
|
-
"vite.config.ts",
|
|
15
|
-
"vite.config.mts",
|
|
16
|
-
"vitest.config.ts",
|
|
17
|
-
"vitest.config.mts",
|
|
18
|
-
"src/**/*.test.ts",
|
|
19
|
-
"src/**/*.spec.ts",
|
|
20
|
-
"src/**/*.test.tsx",
|
|
21
|
-
"src/**/*.spec.tsx",
|
|
22
|
-
"src/**/*.test.js",
|
|
23
|
-
"src/**/*.spec.js",
|
|
24
|
-
"src/**/*.test.jsx",
|
|
25
|
-
"src/**/*.spec.jsx",
|
|
26
|
-
"src/**/*.d.ts"
|
|
27
|
-
]
|
|
28
|
-
}
|
package/otel/vite.config.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
3
|
-
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
|
|
4
|
-
|
|
5
|
-
export default defineConfig(() => ({
|
|
6
|
-
root: __dirname,
|
|
7
|
-
cacheDir: '../node_modules/.vite/otel',
|
|
8
|
-
plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
|
|
9
|
-
// Uncomment this if you are using workers.
|
|
10
|
-
// worker: {
|
|
11
|
-
// plugins: [ nxViteTsPaths() ],
|
|
12
|
-
// },
|
|
13
|
-
test: {
|
|
14
|
-
watch: false,
|
|
15
|
-
globals: true,
|
|
16
|
-
environment: 'node',
|
|
17
|
-
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
18
|
-
reporters: ['default'],
|
|
19
|
-
coverage: {
|
|
20
|
-
reportsDirectory: '../coverage/otel',
|
|
21
|
-
provider: 'v8' as const,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
}));
|
package/trpc/README.md
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Mock superjson for Jest testing
|
|
2
|
-
module.exports = {
|
|
3
|
-
default: {
|
|
4
|
-
stringify: JSON.stringify,
|
|
5
|
-
parse: JSON.parse,
|
|
6
|
-
serialize: (obj) => ({ json: obj, meta: undefined }),
|
|
7
|
-
deserialize: (data) => data.json,
|
|
8
|
-
output: {
|
|
9
|
-
serialize: (obj) => ({ json: obj, meta: undefined })
|
|
10
|
-
},
|
|
11
|
-
input: {
|
|
12
|
-
deserialize: (data) => data.json
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
stringify: JSON.stringify,
|
|
16
|
-
parse: JSON.parse,
|
|
17
|
-
serialize: (obj) => ({ json: obj, meta: undefined }),
|
|
18
|
-
deserialize: (data) => data.json,
|
|
19
|
-
output: {
|
|
20
|
-
serialize: (obj) => ({ json: obj, meta: undefined })
|
|
21
|
-
},
|
|
22
|
-
input: {
|
|
23
|
-
deserialize: (data) => data.json
|
|
24
|
-
}
|
|
25
|
-
};
|
package/trpc/eslint.config.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import baseConfig from '../eslint.config.mjs';
|
|
2
|
-
|
|
3
|
-
export default [
|
|
4
|
-
...baseConfig,
|
|
5
|
-
{
|
|
6
|
-
files: ['**/*.json'],
|
|
7
|
-
rules: {
|
|
8
|
-
'@nx/dependency-checks': [
|
|
9
|
-
'error',
|
|
10
|
-
{
|
|
11
|
-
ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'],
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
},
|
|
15
|
-
languageOptions: {
|
|
16
|
-
parser: await import('jsonc-eslint-parser'),
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
];
|
package/trpc/jest.config.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
displayName: 'trpc',
|
|
3
|
-
preset: '../jest.preset.js',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
testTimeout: 15000,
|
|
6
|
-
transform: {
|
|
7
|
-
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
|
8
|
-
},
|
|
9
|
-
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
10
|
-
moduleNameMapper: {
|
|
11
|
-
'^superjson$': '<rootDir>/__mocks__/superjson.js',
|
|
12
|
-
},
|
|
13
|
-
coverageDirectory: '../coverage/trpc',
|
|
14
|
-
};
|
package/trpc/package.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@reactionary/trpc",
|
|
3
|
-
"version": "0.0.1",
|
|
4
|
-
"type": "commonjs",
|
|
5
|
-
"main": "./src/index.js",
|
|
6
|
-
"types": "./src/index.d.ts",
|
|
7
|
-
"dependencies": {
|
|
8
|
-
"@trpc/server": "^11.1.2",
|
|
9
|
-
"@reactionary/core": "0.0.1",
|
|
10
|
-
"@reactionary/otel": "0.0.1",
|
|
11
|
-
"superjson": "^2.2.2",
|
|
12
|
-
"zod": "4.1.9"
|
|
13
|
-
}
|
|
14
|
-
}
|
package/trpc/project.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "trpc",
|
|
3
|
-
"$schema": "../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "trpc/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"release": {
|
|
7
|
-
"version": {
|
|
8
|
-
"manifestRootsToUpdate": ["dist/{projectRoot}"],
|
|
9
|
-
"currentVersionResolver": "git-tag",
|
|
10
|
-
"fallbackCurrentVersionResolver": "disk"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"tags": [],
|
|
14
|
-
"targets": {
|
|
15
|
-
"build": {
|
|
16
|
-
"executor": "@nx/esbuild:esbuild",
|
|
17
|
-
"outputs": ["{options.outputPath}"],
|
|
18
|
-
"options": {
|
|
19
|
-
"outputPath": "dist/trpc",
|
|
20
|
-
"main": "trpc/src/index.ts",
|
|
21
|
-
"tsConfig": "trpc/tsconfig.lib.json",
|
|
22
|
-
"format": ["esm"]
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"nx-release-publish": {
|
|
26
|
-
"options": {
|
|
27
|
-
"packageRoot": "dist/{projectRoot}"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
package/trpc/src/client.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import type { Client, RequestContext} from '@reactionary/core';
|
|
2
|
-
import { Session } from '@reactionary/core';
|
|
3
|
-
import type { TransparentClient } from './types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Configuration options for TRPC client creation
|
|
7
|
-
*/
|
|
8
|
-
export interface TRPCClientOptions {
|
|
9
|
-
/** Default session to use if not provided in method calls */
|
|
10
|
-
defaultRequestContext?: RequestContext
|
|
11
|
-
/** Whether to automatically provide request context from defaultRequestContext\ */
|
|
12
|
-
autoRequestContext?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Create a type-safe client proxy that uses the original client's type interface
|
|
17
|
-
* while routing all calls through TRPC
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { createTRPCProxyClient } from '@trpc/client';
|
|
22
|
-
* import { createTRPCClient } from '@reactionary/trpc/client';
|
|
23
|
-
*
|
|
24
|
-
* const trpc = createTRPCProxyClient<AppRouter>({
|
|
25
|
-
* url: 'http://localhost:3000',
|
|
26
|
-
* });
|
|
27
|
-
*
|
|
28
|
-
* // Pass the original client type as the generic parameter
|
|
29
|
-
* const client = createTRPCClient<typeof serverClient>(trpc, {
|
|
30
|
-
* defaultSession: mySession,
|
|
31
|
-
* autoSession: true
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* // Fully typed using the original client interface!
|
|
35
|
-
* const product = await client.product.getById({ id: '123' }, reqCtx);
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export function createTRPCClient<TOriginalClient extends Partial<Client>>(
|
|
39
|
-
trpcClient: any,
|
|
40
|
-
options: TRPCClientOptions = {}
|
|
41
|
-
): TransparentClient<TOriginalClient> {
|
|
42
|
-
const { defaultRequestContext, autoRequestContext = false } = options;
|
|
43
|
-
|
|
44
|
-
return new Proxy({} as TransparentClient<TOriginalClient>, {
|
|
45
|
-
get(target, providerName: string | symbol) {
|
|
46
|
-
if (typeof providerName !== 'string') {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Return a typed proxy for the provider that intercepts method calls
|
|
51
|
-
return new Proxy({}, {
|
|
52
|
-
get(providerTarget, methodName: string | symbol) {
|
|
53
|
-
if (typeof methodName !== 'string') {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Only expose methods that are marked with TRPC decorators
|
|
58
|
-
// This eliminates the need to filter TRPC-specific properties
|
|
59
|
-
return async (payload: any, reqCtxArg?: RequestContext) => {
|
|
60
|
-
// Determine request context to use
|
|
61
|
-
let reqCtx = reqCtxArg;
|
|
62
|
-
if (!reqCtx && autoRequestContext && defaultRequestContext) {
|
|
63
|
-
reqCtx = defaultRequestContext;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Prepare input for TRPC call
|
|
67
|
-
const input = {
|
|
68
|
-
payload,
|
|
69
|
-
reqCtx
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// Access TRPC provider and method lazily
|
|
73
|
-
const trpcProvider = trpcClient[providerName];
|
|
74
|
-
const trpcMethod = trpcProvider[methodName];
|
|
75
|
-
|
|
76
|
-
// Use decorator metadata to determine if this is a query or mutation
|
|
77
|
-
// Note: We can't directly check the original provider here since we only have
|
|
78
|
-
// the TRPC client, so we'll fall back to the router's procedure type detection
|
|
79
|
-
if (trpcMethod?.query) {
|
|
80
|
-
return await trpcMethod.query(input);
|
|
81
|
-
} else if (trpcMethod?.mutate) {
|
|
82
|
-
return await trpcMethod.mutate(input);
|
|
83
|
-
} else {
|
|
84
|
-
throw new Error(`Method ${String(providerName)}.${String(methodName)} not found on TRPC client`);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Session provider interface for dependency injection
|
|
95
|
-
*/
|
|
96
|
-
export interface SessionProvider {
|
|
97
|
-
getRequestContext(): Promise<RequestContext> | RequestContext;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Create a TRPC client with session provider for automatic session management
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* ```typescript
|
|
105
|
-
* const sessionProvider: SessionProvider = {
|
|
106
|
-
* getSession: () => getCurrentUserSession()
|
|
107
|
-
* };
|
|
108
|
-
*
|
|
109
|
-
* const client = createTRPCClientWithSessionProvider(trpc, reqCtxProvider);
|
|
110
|
-
*
|
|
111
|
-
* // Session is automatically provided, fully typed
|
|
112
|
-
* const product = await client.product.getById({ id: '123' });
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
export function createTRPCClientWithSessionProvider<TOriginalClient extends Partial<Client>>(
|
|
116
|
-
trpcClient: any,
|
|
117
|
-
sessionProvider: SessionProvider
|
|
118
|
-
): TransparentClient<TOriginalClient> {
|
|
119
|
-
return new Proxy({} as TransparentClient<TOriginalClient>, {
|
|
120
|
-
get(target, providerName: string | symbol) {
|
|
121
|
-
if (typeof providerName !== 'string') {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return new Proxy({}, {
|
|
126
|
-
get(providerTarget, methodName: string | symbol) {
|
|
127
|
-
if (typeof methodName !== 'string') {
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return async (payload: any, reqCtxArg?: RequestContext) => {
|
|
132
|
-
// If no session provided, get from provider
|
|
133
|
-
let reqCtx = reqCtxArg;
|
|
134
|
-
if (!reqCtx) {
|
|
135
|
-
reqCtx = await sessionProvider.getRequestContext();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const input = {
|
|
139
|
-
payload,
|
|
140
|
-
reqCtx
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
// Access TRPC provider and method lazily
|
|
144
|
-
const trpcProvider = trpcClient[providerName];
|
|
145
|
-
const trpcMethod = trpcProvider[methodName];
|
|
146
|
-
|
|
147
|
-
// Use TRPC client's procedure type detection
|
|
148
|
-
if (trpcMethod?.query) {
|
|
149
|
-
return await trpcMethod.query(input);
|
|
150
|
-
} else if (trpcMethod?.mutate) {
|
|
151
|
-
return await trpcMethod.mutate(input);
|
|
152
|
-
} else {
|
|
153
|
-
throw new Error(`Method ${String(providerName)}.${String(methodName)} not found on TRPC client`);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Type alias for creating typed TRPC clients
|
|
164
|
-
* Use the original client type, not the router type
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```typescript
|
|
168
|
-
* type MyClient = typeof serverClient;
|
|
169
|
-
*
|
|
170
|
-
* function useClient(): MyClient {
|
|
171
|
-
* return createTRPCClient<MyClient>(trpcProxyClient);
|
|
172
|
-
* }
|
|
173
|
-
* ```
|
|
174
|
-
*/
|
|
175
|
-
export type TRPCClientFromRouter<TOriginalClient> = TOriginalClient;
|
package/trpc/src/index.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Re-export server utilities
|
|
2
|
-
export {
|
|
3
|
-
createTRPCServerRouter,
|
|
4
|
-
createTRPCContext,
|
|
5
|
-
router,
|
|
6
|
-
mergeRouters,
|
|
7
|
-
type TRPCRouterFromClient
|
|
8
|
-
} from './server';
|
|
9
|
-
|
|
10
|
-
// Re-export client utilities
|
|
11
|
-
export {
|
|
12
|
-
createTRPCClient,
|
|
13
|
-
createTRPCClientWithSessionProvider,
|
|
14
|
-
type TRPCClientOptions,
|
|
15
|
-
type SessionProvider,
|
|
16
|
-
type TRPCClientFromRouter
|
|
17
|
-
} from './client';
|
|
18
|
-
|
|
19
|
-
// Re-export type utilities
|
|
20
|
-
export {
|
|
21
|
-
type ClientMethodMap,
|
|
22
|
-
type MethodInfo,
|
|
23
|
-
type TRPCMethodInput,
|
|
24
|
-
type TransparentClient,
|
|
25
|
-
introspectClient,
|
|
26
|
-
isQueryMethod,
|
|
27
|
-
isMutationMethod
|
|
28
|
-
} from './types';
|
|
29
|
-
|
|
30
|
-
// Legacy exports for backward compatibility
|
|
31
|
-
import { initTRPC } from '@trpc/server';
|
|
32
|
-
import type { Client, RequestContext} from '@reactionary/core';
|
|
33
|
-
import { Session } from '@reactionary/core';
|
|
34
|
-
import { createTRPCTracing } from '@reactionary/otel';
|
|
35
|
-
|
|
36
|
-
const t = initTRPC.context<{ client: Client; reqCtx: RequestContext }>().create({});
|
|
37
|
-
|
|
38
|
-
// Always apply tracing middleware - exporters controlled via OTEL env vars
|
|
39
|
-
const basePublicProcedure = t.procedure;
|
|
40
|
-
export const publicProcedure = basePublicProcedure.use(createTRPCTracing());
|
|
41
|
-
|
|
42
|
-
// Legacy function - deprecated, use createTRPCServerRouter instead
|
|
43
|
-
import { createTRPCServerRouter } from './server';
|
|
44
|
-
export const createTRPCRouter = createTRPCServerRouter;
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { ClientBuilder, NoOpCache } from '@reactionary/core';
|
|
2
|
-
import { withFakeCapabilities } from '@reactionary/provider-fake';
|
|
3
|
-
import { createTRPCServerRouter, createTRPCContext } from './server';
|
|
4
|
-
import { createTRPCClient } from './client';
|
|
5
|
-
import type { TransparentClient } from './types';
|
|
6
|
-
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
|
|
7
|
-
import { createHTTPHandler } from '@trpc/server/adapters/standalone';
|
|
8
|
-
import * as http from 'http';
|
|
9
|
-
import { createInitialRequestContext } from '@reactionary/core';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Integration test that actually starts an HTTP server and makes real network calls
|
|
13
|
-
* This is the real test that verifies the TRPC transparent transport works end-to-end
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
// Polyfill fetch for Node.js
|
|
17
|
-
global.fetch = global.fetch || require('node-fetch');
|
|
18
|
-
|
|
19
|
-
// Create the server-side client
|
|
20
|
-
const serverClient = new ClientBuilder()
|
|
21
|
-
.withCapability(
|
|
22
|
-
withFakeCapabilities(
|
|
23
|
-
{
|
|
24
|
-
jitter: {
|
|
25
|
-
mean: 0,
|
|
26
|
-
deviation: 0,
|
|
27
|
-
},
|
|
28
|
-
seeds: {
|
|
29
|
-
category: 1,
|
|
30
|
-
product: 1,
|
|
31
|
-
search: 1
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
{ search: true, product: true, identity: false }
|
|
35
|
-
)
|
|
36
|
-
)
|
|
37
|
-
.withCache(new NoOpCache())
|
|
38
|
-
.build();
|
|
39
|
-
|
|
40
|
-
// Create TRPC router from the client (do this at module level for type inference)
|
|
41
|
-
const router = createTRPCServerRouter(serverClient);
|
|
42
|
-
type AppRouter = typeof router;
|
|
43
|
-
|
|
44
|
-
xdescribe('TRPC Integration Test - Real HTTP Server', () => {
|
|
45
|
-
let server: http.Server;
|
|
46
|
-
let serverPort: number;
|
|
47
|
-
let trpcProxyClient: ReturnType<typeof createTRPCProxyClient<AppRouter>>;
|
|
48
|
-
let transparentClient: TransparentClient<typeof serverClient>;
|
|
49
|
-
|
|
50
|
-
beforeAll(async () => {
|
|
51
|
-
|
|
52
|
-
// Create TRPC HTTP handler
|
|
53
|
-
const handler = createHTTPHandler({
|
|
54
|
-
router,
|
|
55
|
-
createContext: createTRPCContext,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// Start HTTP server with TRPC handler
|
|
59
|
-
server = http.createServer(handler);
|
|
60
|
-
|
|
61
|
-
// Find available port
|
|
62
|
-
serverPort = 3001;
|
|
63
|
-
await new Promise<void>((resolve, reject) => {
|
|
64
|
-
const tryPort = (port: number) => {
|
|
65
|
-
server.listen(port, (err?: Error) => {
|
|
66
|
-
if (err) {
|
|
67
|
-
if (port < 3010) {
|
|
68
|
-
tryPort(port + 1);
|
|
69
|
-
} else {
|
|
70
|
-
reject(err);
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
serverPort = port;
|
|
74
|
-
resolve();
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
tryPort(serverPort);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Create real TRPC proxy client (no transformer for testing)
|
|
82
|
-
trpcProxyClient = createTRPCProxyClient<AppRouter>({
|
|
83
|
-
links: [
|
|
84
|
-
httpBatchLink({
|
|
85
|
-
url: `http://localhost:${serverPort}`,
|
|
86
|
-
}),
|
|
87
|
-
],
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Create transparent client using the real implementation - now properly typed!
|
|
91
|
-
transparentClient = createTRPCClient<typeof serverClient>(trpcProxyClient);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
afterAll(async () => {
|
|
95
|
-
if (server) {
|
|
96
|
-
await new Promise<void>((resolve) => {
|
|
97
|
-
server.close(() => resolve());
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const reqCtx = createInitialRequestContext();
|
|
103
|
-
|
|
104
|
-
describe('Product Provider via HTTP', () => {
|
|
105
|
-
it('should fetch product by slug through real HTTP calls', async () => {
|
|
106
|
-
const slug = 'integration-test-product';
|
|
107
|
-
|
|
108
|
-
// Get result from transparent client (through HTTP/TRPC)
|
|
109
|
-
const trpcResult = await transparentClient.product.getBySlug(
|
|
110
|
-
{ slug },
|
|
111
|
-
reqCtx
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
// Get result from server client (direct call)
|
|
115
|
-
const directResult = await serverClient.product.getBySlug(
|
|
116
|
-
{ slug },
|
|
117
|
-
reqCtx
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
// Results should have the same structure
|
|
121
|
-
expect(trpcResult).toBeDefined();
|
|
122
|
-
expect(trpcResult.slug).toBe(slug);
|
|
123
|
-
expect(trpcResult.name).toBeDefined();
|
|
124
|
-
expect(trpcResult.description).toBeDefined();
|
|
125
|
-
expect(trpcResult.image).toBeDefined();
|
|
126
|
-
|
|
127
|
-
// Both should have the same slug (faker uses seed for consistency)
|
|
128
|
-
expect(trpcResult.slug).toBe(directResult.slug);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should fetch product by id through real HTTP calls', async () => {
|
|
132
|
-
const productId = 'integration-test-id';
|
|
133
|
-
|
|
134
|
-
const trpcResult = await transparentClient.product.getById(
|
|
135
|
-
{ id: productId },
|
|
136
|
-
reqCtx
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
const directResult = await serverClient.product.getById(
|
|
140
|
-
{ id: productId },
|
|
141
|
-
reqCtx
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
expect(trpcResult).toBeDefined();
|
|
145
|
-
expect(trpcResult.identifier.key).toBe(productId);
|
|
146
|
-
expect(trpcResult.name).toBeDefined();
|
|
147
|
-
expect(trpcResult.description).toBeDefined();
|
|
148
|
-
|
|
149
|
-
// Should match direct call
|
|
150
|
-
expect(trpcResult.identifier?.key).toBe(directResult.identifier?.key);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe('Search Provider via HTTP', () => {
|
|
155
|
-
it('should perform search through real HTTP calls', async () => {
|
|
156
|
-
const searchTerm = 'integration test search';
|
|
157
|
-
|
|
158
|
-
const trpcResult = await transparentClient.search.queryByTerm(
|
|
159
|
-
{
|
|
160
|
-
search: {
|
|
161
|
-
term: searchTerm,
|
|
162
|
-
page: 0,
|
|
163
|
-
pageSize: 10,
|
|
164
|
-
facets: []
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
reqCtx
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
const directResult = await serverClient.search.queryByTerm(
|
|
171
|
-
{
|
|
172
|
-
search: {
|
|
173
|
-
term: searchTerm,
|
|
174
|
-
page: 0,
|
|
175
|
-
pageSize: 10,
|
|
176
|
-
facets: []
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
reqCtx
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
expect(trpcResult).toBeDefined();
|
|
183
|
-
expect(trpcResult.products).toBeDefined();
|
|
184
|
-
expect(Array.isArray(trpcResult.products)).toBe(true);
|
|
185
|
-
expect(trpcResult.facets).toBeDefined();
|
|
186
|
-
|
|
187
|
-
// Should match direct call structure
|
|
188
|
-
expect(trpcResult.products.length).toBe(directResult.products.length);
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
describe('Network Error Handling', () => {
|
|
193
|
-
it('should handle HTTP errors gracefully', async () => {
|
|
194
|
-
// This should work normally first
|
|
195
|
-
const result = await transparentClient.product.getById(
|
|
196
|
-
{ id: 'test-error-handling' },
|
|
197
|
-
reqCtx
|
|
198
|
-
);
|
|
199
|
-
expect(result).toBeDefined();
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe('API Equivalence', () => {
|
|
204
|
-
it('should produce identical results for TRPC vs direct calls', async () => {
|
|
205
|
-
const testId = 'equivalence-test';
|
|
206
|
-
|
|
207
|
-
// Make same call through both paths
|
|
208
|
-
const [trpcResult, directResult] = await Promise.all([
|
|
209
|
-
transparentClient.product.getById(
|
|
210
|
-
{ id: testId },
|
|
211
|
-
reqCtx
|
|
212
|
-
),
|
|
213
|
-
serverClient.product.getById({ id: testId }, reqCtx)
|
|
214
|
-
]);
|
|
215
|
-
|
|
216
|
-
// Results should be structurally equivalent
|
|
217
|
-
expect(trpcResult.identifier.key).toBe(directResult.identifier.key);
|
|
218
|
-
expect(trpcResult.name).toBe(directResult.name);
|
|
219
|
-
expect(trpcResult.slug).toBe(directResult.slug);
|
|
220
|
-
expect(trpcResult.description).toBe(directResult.description);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
});
|