@soda-gql/colocation-tools 0.2.0 → 0.3.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/README.md +20 -18
- package/dist/index.cjs +6 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -50,9 +50,10 @@ import { gql } from "./graphql-system";
|
|
|
50
50
|
import { userFragment } from "./UserCard";
|
|
51
51
|
|
|
52
52
|
export const getUserQuery = gql.default(({ query }) =>
|
|
53
|
-
query.operation({
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
query.operation({
|
|
54
|
+
name: "GetUser",
|
|
55
|
+
fields: ({ f }) => ({ ...f.user({ id: "1" })(({ f }) => ({ ...userFragment.embed() })) }),
|
|
56
|
+
}),
|
|
56
57
|
);
|
|
57
58
|
```
|
|
58
59
|
|
|
@@ -67,9 +68,10 @@ When composing multiple fragments in a single operation, use `$colocate` to pref
|
|
|
67
68
|
```typescript
|
|
68
69
|
// UserCard.tsx
|
|
69
70
|
export const userCardFragment = gql.default(({ fragment }, { $var }) =>
|
|
70
|
-
fragment.Query({
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
fragment.Query({
|
|
72
|
+
variables: { ...$var("userId").ID("!") },
|
|
73
|
+
fields: ({ f, $ }) => ({ ...f.user({ id: $.userId })(({ f }) => ({ ...f.id(), ...f.name(), ...f.email() })) }),
|
|
74
|
+
}),
|
|
73
75
|
);
|
|
74
76
|
|
|
75
77
|
export const userCardProjection = createProjection(userCardFragment, {
|
|
@@ -90,15 +92,14 @@ import { userCardFragment, userCardProjection } from "./UserCard";
|
|
|
90
92
|
import { postListFragment, postListProjection } from "./PostList";
|
|
91
93
|
|
|
92
94
|
export const userPageQuery = gql.default(({ query }, { $var, $colocate }) =>
|
|
93
|
-
query.operation(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
),
|
|
95
|
+
query.operation({
|
|
96
|
+
name: "UserPage",
|
|
97
|
+
variables: { ...$var("userId").ID("!") },
|
|
98
|
+
fields: ({ $ }) => $colocate({
|
|
99
|
+
userCard: userCardFragment.embed({ userId: $.userId }),
|
|
100
|
+
postList: postListFragment.embed({ userId: $.userId }),
|
|
101
|
+
}),
|
|
102
|
+
}),
|
|
102
103
|
);
|
|
103
104
|
```
|
|
104
105
|
|
|
@@ -152,9 +153,10 @@ import { gql } from "./graphql-system";
|
|
|
152
153
|
|
|
153
154
|
export const postListFragment = gql
|
|
154
155
|
.default(({ fragment }, { $var }) =>
|
|
155
|
-
fragment.Query({
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
fragment.Query({
|
|
157
|
+
variables: { ...$var("userId").ID("!") },
|
|
158
|
+
fields: ({ f, $ }) => ({ ...f.user({ id: $.userId })(({ f }) => ({ ...f.posts({})(({ f }) => ({ ...f.id(), ...f.title() })) })) }),
|
|
159
|
+
}),
|
|
158
160
|
)
|
|
159
161
|
.attach(
|
|
160
162
|
createProjectionAttachment({
|
package/dist/index.cjs
CHANGED
|
@@ -42,9 +42,12 @@ function createProjectionPath(path) {
|
|
|
42
42
|
* @example
|
|
43
43
|
* ```typescript
|
|
44
44
|
* const userFragment = gql(({ fragment }) =>
|
|
45
|
-
* fragment.Query({
|
|
46
|
-
*
|
|
47
|
-
*
|
|
45
|
+
* fragment.Query({
|
|
46
|
+
* variables: { ... },
|
|
47
|
+
* fields: ({ f, $ }) => ({
|
|
48
|
+
* ...f.user({ id: $.userId })(({ f }) => ({ ...f.id(), ...f.name() })),
|
|
49
|
+
* }),
|
|
50
|
+
* })
|
|
48
51
|
* );
|
|
49
52
|
*
|
|
50
53
|
* const userProjection = createProjection(userFragment, {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["projector: (result: AnySlicedExecutionResult) => TProjected","paths","type: \"success\" | \"error\" | \"empty\"","data: TData","extensions?: unknown","error: NormalizedError","errorMaps: { [label: string]: { [path: string]: { error: GraphQLFormattedError }[] } }","current: unknown"],"sources":["../src/projection.ts","../src/create-projection.ts","../src/utils/map-values.ts","../src/projection-path-graph.ts","../src/sliced-execution-result.ts","../src/parse-execution-result.ts"],"sourcesContent":["import type { AnySlicedExecutionResult } from \"./sliced-execution-result\";\nimport type { Tuple } from \"./utils/type-utils\";\n\n/** Shape of a single selection slice projection. */\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any Projection regardless of projected type\nexport type AnyProjection = Projection<any>;\n\ndeclare const __PROJECTION_BRAND__: unique symbol;\n/**\n * Nominal type representing any slice selection regardless of schema specifics.\n * Encodes how individual slices map a concrete field path to a projection\n * function. Multiple selections allow slices to expose several derived values.\n */\nexport class Projection<TProjected> {\n declare readonly [__PROJECTION_BRAND__]: void;\n\n declare readonly $infer: { readonly output: TProjected };\n\n constructor(\n paths: Tuple<string>,\n public readonly projector: (result: AnySlicedExecutionResult) => TProjected,\n ) {\n this.paths = paths.map((path) => createProjectionPath(path));\n\n Object.defineProperty(this, \"$infer\", {\n get() {\n throw new Error(\"This property is only for type meta. Do not access this property directly.\");\n },\n });\n }\n\n public readonly paths: ProjectionPath[];\n}\n\nexport type ProjectionPath = {\n full: string;\n segments: Tuple<string>;\n};\n\nfunction createProjectionPath(path: string): ProjectionPath {\n const segments = path.split(\".\");\n if (path === \"$\" || segments.length <= 1) {\n throw new Error(\"Field path must not be only $ or empty\");\n }\n\n return {\n full: path,\n segments: segments.slice(1) as Tuple<string>,\n };\n}\n\nexport type InferExecutionResultProjection<TProjection extends AnyProjection> = ReturnType<TProjection[\"projector\"]>;\n","import type { Fragment, GqlElementAttachment } from \"@soda-gql/core\";\nimport { Projection } from \"./projection\";\nimport type { SlicedExecutionResult } from \"./sliced-execution-result\";\nimport type { Tuple } from \"./utils/type-utils\";\n\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any Fragment regardless of type parameters\ntype AnyFragment = Fragment<string, any, any, any>;\n\n/**\n * Options for creating a projection from a Fragment.\n */\nexport type CreateProjectionOptions<TOutput extends object, TProjected> = {\n /**\n * Field paths to extract from the execution result.\n * Each path starts with \"$.\" and follows the field selection structure.\n *\n * @example\n * ```typescript\n * paths: [\"$.user.id\", \"$.user.name\"]\n * ```\n */\n paths: Tuple<string>;\n\n /**\n * Handler function to transform the sliced execution result.\n * Receives a SlicedExecutionResult with the Fragment's output type.\n * Handles all cases: success, error, and empty.\n *\n * @example\n * ```typescript\n * handle: (result) => {\n * if (result.isError()) return { error: result.error, data: null };\n * if (result.isEmpty()) return { error: null, data: null };\n * const data = result.unwrap();\n * return { error: null, data: { userId: data.user.id } };\n * }\n * ```\n */\n handle: (result: SlicedExecutionResult<TOutput>) => TProjected;\n};\n\n/**\n * Creates a type-safe projection from a Fragment.\n *\n * The projection extracts and transforms data from GraphQL execution results,\n * with full type inference from the Fragment's output type.\n *\n * Note: The Fragment parameter is used only for type inference.\n * The actual paths must be specified explicitly.\n *\n * @param _fragment - The Fragment to infer types from (used for type inference only)\n * @param options - Projection options including paths and handle function\n * @returns A Projection that can be used with createExecutionResultParser\n *\n * @example\n * ```typescript\n * const userFragment = gql(({ fragment }) =>\n * fragment.Query({ variables: [...] }, ({ f, $ }) => [\n * f.user({ id: $.userId })(({ f }) => [f.id(), f.name()]),\n * ])\n * );\n *\n * const userProjection = createProjection(userFragment, {\n * paths: [\"$.user\"],\n * handle: (result) => {\n * if (result.isError()) return { error: result.error, user: null };\n * if (result.isEmpty()) return { error: null, user: null };\n * const data = result.unwrap();\n * return { error: null, user: data.user };\n * },\n * });\n * ```\n */\nexport const createProjection = <TFragment extends AnyFragment, TProjected>(\n _fragment: TFragment,\n options: CreateProjectionOptions<TFragment[\"$infer\"][\"output\"], TProjected>,\n): Projection<TProjected> => {\n return new Projection(options.paths, options.handle);\n};\n\nexport const createProjectionAttachment = <TFragment extends AnyFragment, TProjected>(\n options: CreateProjectionOptions<NoInfer<TFragment>[\"$infer\"][\"output\"], TProjected>,\n): GqlElementAttachment<TFragment, \"projection\", Projection<TProjected>> => {\n return {\n name: \"projection\",\n createValue: (fragment) => createProjection(fragment, options),\n };\n};\n","type ArgEntries<T extends object> = { [K in keyof T]-?: [value: T[K], key: K] }[keyof T];\ntype Entries<T extends object> = { [K in keyof T]: [key: K, value: T[K]] }[keyof T];\n\nexport function mapValues<TObject extends object, TMappedValue>(\n obj: TObject,\n fn: (...args: ArgEntries<TObject>) => TMappedValue,\n): {\n [K in keyof TObject]: TMappedValue;\n} {\n return Object.fromEntries((Object.entries(obj) as Entries<TObject>[]).map(([key, value]) => [key, fn(value, key)])) as {\n [K in keyof TObject]: TMappedValue;\n };\n}\n","import type { AnyProjection } from \"./projection\";\nimport { mapValues } from \"./utils/map-values\";\n\n/**\n * Node in the projection path graph tree.\n * Used for mapping GraphQL errors and data to their corresponding slices.\n */\nexport type ProjectionPathGraphNode = {\n readonly matches: { label: string; path: string; exact: boolean }[];\n readonly children: { readonly [segment: string]: ProjectionPathGraphNode };\n};\n\n/**\n * Payload from a slice that contains projection.\n */\nexport type AnySlicePayload = {\n readonly projection: AnyProjection;\n};\n\nexport type AnySlicePayloads = Record<string, AnySlicePayload>;\n\ntype ExecutionResultProjectionPathGraphIntermediate = {\n [segment: string]: { label: string; raw: string; segments: string[] }[];\n};\n\nfunction createPathGraph(paths: ExecutionResultProjectionPathGraphIntermediate[string]): ProjectionPathGraphNode {\n const intermediate = paths.reduce(\n (acc: ExecutionResultProjectionPathGraphIntermediate, { label, raw, segments: [segment, ...segments] }) => {\n if (segment) {\n (acc[segment] || (acc[segment] = [])).push({ label, raw, segments });\n }\n return acc;\n },\n {},\n );\n\n return {\n matches: paths.map(({ label, raw, segments }) => ({ label, path: raw, exact: segments.length === 0 })),\n children: mapValues(intermediate, (paths) => createPathGraph(paths)),\n } satisfies ProjectionPathGraphNode;\n}\n\n/**\n * Creates a projection path graph from slice entries with field prefixing.\n * Each slice's paths are prefixed with the slice label for disambiguation.\n */\nexport function createPathGraphFromSliceEntries(fragments: AnySlicePayloads) {\n const paths = Object.entries(fragments).flatMap(([label, slice]) =>\n Array.from(\n new Map(\n slice.projection.paths.map(({ full: raw, segments }) => {\n const [first, ...rest] = segments;\n return [raw, { label, raw, segments: [`${label}_${first}`, ...rest] }];\n }),\n ).values(),\n ),\n );\n\n return createPathGraph(paths);\n}\n","/** Result-like wrapper types returned from slice projections. */\n\nimport type { NormalizedError } from \"./types\";\n\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any SlicedExecutionResult regardless of data type\nexport type AnySlicedExecutionResult = SlicedExecutionResult<any>;\n\n/**\n * Internal discriminated union describing the Result-like wrapper exposed to\n * slice selection callbacks.\n */\nexport type AnySlicedExecutionResultRecord = {\n [path: string]: AnySlicedExecutionResult;\n};\n\nexport type SafeUnwrapResult<TTransformed, TError> =\n | {\n data?: never;\n error?: never;\n }\n | {\n data: TTransformed;\n error?: never;\n }\n | {\n data?: never;\n error: TError;\n };\n\n/** Utility signature returned by the safe unwrap helper. */\ntype SlicedExecutionResultCommon<TData, TError> = {\n safeUnwrap<TTransformed>(transform: (data: TData) => TTransformed): SafeUnwrapResult<TTransformed, TError>;\n};\n\n/** Public union used by selection callbacks to inspect data, empty, or error states. */\nexport type SlicedExecutionResult<TData> =\n | SlicedExecutionResultEmpty<TData>\n | SlicedExecutionResultSuccess<TData>\n | SlicedExecutionResultError<TData>;\n\n/** Runtime guard interface shared by all slice result variants. */\nclass SlicedExecutionResultGuards<TData> {\n isSuccess(): this is SlicedExecutionResultSuccess<TData> {\n return this.type === \"success\";\n }\n isError(): this is SlicedExecutionResultError<TData> {\n return this.type === \"error\";\n }\n isEmpty(): this is SlicedExecutionResultEmpty<TData> {\n return this.type === \"empty\";\n }\n\n constructor(private readonly type: \"success\" | \"error\" | \"empty\") {}\n}\n\n/** Variant representing an empty payload (no data, no error). */\nexport class SlicedExecutionResultEmpty<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor() {\n super(\"empty\");\n }\n\n unwrap(): null {\n return null;\n }\n\n safeUnwrap() {\n return {\n data: undefined,\n error: undefined,\n };\n }\n}\n\n/** Variant representing a successful payload. */\nexport class SlicedExecutionResultSuccess<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor(\n public readonly data: TData,\n public readonly extensions?: unknown,\n ) {\n super(\"success\");\n }\n\n unwrap(): TData {\n return this.data;\n }\n\n safeUnwrap<TTransformed>(transform: (data: TData) => TTransformed) {\n return {\n data: transform(this.data),\n error: undefined,\n };\n }\n}\n\n/** Variant representing an error payload. */\nexport class SlicedExecutionResultError<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor(\n public readonly error: NormalizedError,\n public readonly extensions?: unknown,\n ) {\n super(\"error\");\n }\n\n unwrap(): never {\n throw this.error;\n }\n\n safeUnwrap() {\n return {\n data: undefined,\n error: this.error,\n };\n }\n}\n","import type { GraphQLFormattedError } from \"graphql\";\nimport { type AnySlicePayloads, createPathGraphFromSliceEntries, type ProjectionPathGraphNode } from \"./projection-path-graph\";\nimport { SlicedExecutionResultEmpty, SlicedExecutionResultError, SlicedExecutionResultSuccess } from \"./sliced-execution-result\";\nimport type { NormalizedExecutionResult } from \"./types\";\n\n// Internal function to build path graph from slices\nconst createPathGraphFromSlices = createPathGraphFromSliceEntries;\n\nfunction* generateErrorMapEntries(errors: readonly GraphQLFormattedError[], projectionPathGraph: ProjectionPathGraphNode) {\n for (const error of errors) {\n const errorPath = error.path ?? [];\n let stack = projectionPathGraph;\n\n for (\n let i = 0;\n // i <= errorPath.length to handle the case where the error path is empty\n i <= errorPath.length;\n i++\n ) {\n const segment = errorPath[i];\n\n if (\n // the end of the path\n segment == null ||\n // FieldPath does not support index access. We treat it as the end of the path.\n typeof segment === \"number\"\n ) {\n yield* stack.matches.map(({ label, path }) => ({ label, path, error }));\n break;\n }\n\n yield* stack.matches.filter(({ exact }) => exact).map(({ label, path }) => ({ label, path, error }));\n\n const next = stack.children[segment];\n if (!next) {\n break;\n }\n\n stack = next;\n }\n }\n}\n\nconst createErrorMaps = (errors: readonly GraphQLFormattedError[] | undefined, projectionPathGraph: ProjectionPathGraphNode) => {\n const errorMaps: { [label: string]: { [path: string]: { error: GraphQLFormattedError }[] } } = {};\n for (const { label, path, error } of generateErrorMapEntries(errors ?? [], projectionPathGraph)) {\n const mapPerLabel = errorMaps[label] || (errorMaps[label] = {});\n const mapPerPath = mapPerLabel[path] || (mapPerLabel[path] = []);\n mapPerPath.push({ error });\n }\n return errorMaps;\n};\n\nconst accessDataByPathSegments = (data: object, pathSegments: string[]) => {\n let current: unknown = data;\n\n for (const segment of pathSegments) {\n if (current == null) {\n return { error: new Error(\"No data\") };\n }\n\n if (typeof current !== \"object\") {\n return { error: new Error(\"Incorrect data type\") };\n }\n\n if (Array.isArray(current)) {\n return { error: new Error(\"Incorrect data type\") };\n }\n\n current = (current as Record<string, unknown>)[segment];\n }\n\n return { data: current };\n};\n\n/**\n * Creates an execution result parser for composed operations.\n * The parser maps GraphQL errors and data to their corresponding slices\n * based on the projection path graph.\n *\n * @param slices - Object mapping labels to projections\n * @returns A parser function that takes a NormalizedExecutionResult and returns parsed slices\n *\n * @example\n * ```typescript\n * const parser = createExecutionResultParser({\n * userCard: userCardProjection,\n * posts: postsProjection,\n * });\n *\n * const results = parser({\n * type: \"graphql\",\n * body: { data, errors },\n * });\n * ```\n */\nexport const createExecutionResultParser = <TSlices extends AnySlicePayloads>(slices: TSlices) => {\n // Build path graph from slices\n const projectionPathGraph = createPathGraphFromSlices(slices);\n const fragments = slices;\n const prepare = (result: NormalizedExecutionResult<object, object>) => {\n if (result.type === \"graphql\") {\n const errorMaps = createErrorMaps(result.body.errors, projectionPathGraph);\n\n return { ...result, errorMaps };\n }\n\n if (result.type === \"non-graphql-error\") {\n return { ...result, error: new SlicedExecutionResultError({ type: \"non-graphql-error\", error: result.error }) };\n }\n\n if (result.type === \"empty\") {\n return { ...result, error: new SlicedExecutionResultEmpty() };\n }\n\n throw new Error(\"Invalid result type\", { cause: result satisfies never });\n };\n\n return (result: NormalizedExecutionResult<object, object>) => {\n const prepared = prepare(result);\n\n const entries = Object.entries(fragments).map(([label, fragment]) => {\n const { projection } = fragment;\n\n if (prepared.type === \"graphql\") {\n const matchedErrors = projection.paths.flatMap(({ full: raw }) => prepared.errorMaps[label]?.[raw] ?? []);\n const uniqueErrors = Array.from(new Set(matchedErrors.map(({ error }) => error)).values());\n\n if (uniqueErrors.length > 0) {\n return [label, projection.projector(new SlicedExecutionResultError({ type: \"graphql-error\", errors: uniqueErrors }))];\n }\n\n // Apply label prefix to first segment for data access (matching $colocate prefix pattern)\n const dataResults = projection.paths.map(({ segments }) => {\n const [first, ...rest] = segments;\n const prefixedSegments = [`${label}_${first}`, ...rest];\n return prepared.body.data\n ? accessDataByPathSegments(prepared.body.data, prefixedSegments)\n : { error: new Error(\"No data\") };\n });\n if (dataResults.some(({ error }) => error)) {\n const errors = dataResults.flatMap(({ error }) => (error ? [error] : []));\n return [label, projection.projector(new SlicedExecutionResultError({ type: \"parse-error\", errors }))];\n }\n\n const dataList = dataResults.map(({ data }) => data);\n return [label, projection.projector(new SlicedExecutionResultSuccess(dataList))];\n }\n\n if (prepared.type === \"non-graphql-error\") {\n return [label, projection.projector(prepared.error)];\n }\n\n if (prepared.type === \"empty\") {\n return [label, projection.projector(prepared.error)];\n }\n\n throw new Error(\"Invalid result type\", { cause: prepared satisfies never });\n });\n\n return Object.fromEntries(entries);\n };\n};\n"],"mappings":";;;;;;;AAaA,IAAa,aAAb,MAAoC;CAKlC,YACE,OACA,AAAgBA,WAChB;EADgB;AAEhB,OAAK,QAAQ,MAAM,K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;;IAGvG,MAAM,WAAW,YAAY,KAAK,EAAE,WAAW,KAAK;AACpD,WAAO,CAAC,OAAO,WAAW,UAAU,IAAI,6BAA6B,SAAS,CAAC,CAAC;;AAGlF,OAAI,SAAS,SAAS,oBACpB,QAAO,CAAC,OAAO,WAAW,UAAU,SAAS,MAAM,CAAC;AAGtD,OAAI,SAAS,SAAS,QACpB,QAAO,CAAC,OAAO,WAAW,UAAU,SAAS,MAAM,CAAC;AAGtD,SAAM,IAAI,MAAM,uBAAuB,EAAE,OAAO,UAA0B,CAAC;IAC3E;AAEF,SAAO,OAAO,YAAY,QAAQ"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["projector: (result: AnySlicedExecutionResult) => TProjected","paths","type: \"success\" | \"error\" | \"empty\"","data: TData","extensions?: unknown","error: NormalizedError","errorMaps: { [label: string]: { [path: string]: { error: GraphQLFormattedError }[] } }","current: unknown"],"sources":["../src/projection.ts","../src/create-projection.ts","../src/utils/map-values.ts","../src/projection-path-graph.ts","../src/sliced-execution-result.ts","../src/parse-execution-result.ts"],"sourcesContent":["import type { AnySlicedExecutionResult } from \"./sliced-execution-result\";\nimport type { Tuple } from \"./utils/type-utils\";\n\n/** Shape of a single selection slice projection. */\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any Projection regardless of projected type\nexport type AnyProjection = Projection<any>;\n\ndeclare const __PROJECTION_BRAND__: unique symbol;\n/**\n * Nominal type representing any slice selection regardless of schema specifics.\n * Encodes how individual slices map a concrete field path to a projection\n * function. Multiple selections allow slices to expose several derived values.\n */\nexport class Projection<TProjected> {\n declare readonly [__PROJECTION_BRAND__]: void;\n\n declare readonly $infer: { readonly output: TProjected };\n\n constructor(\n paths: Tuple<string>,\n public readonly projector: (result: AnySlicedExecutionResult) => TProjected,\n ) {\n this.paths = paths.map((path) => createProjectionPath(path));\n\n Object.defineProperty(this, \"$infer\", {\n get() {\n throw new Error(\"This property is only for type meta. Do not access this property directly.\");\n },\n });\n }\n\n public readonly paths: ProjectionPath[];\n}\n\nexport type ProjectionPath = {\n full: string;\n segments: Tuple<string>;\n};\n\nfunction createProjectionPath(path: string): ProjectionPath {\n const segments = path.split(\".\");\n if (path === \"$\" || segments.length <= 1) {\n throw new Error(\"Field path must not be only $ or empty\");\n }\n\n return {\n full: path,\n segments: segments.slice(1) as Tuple<string>,\n };\n}\n\nexport type InferExecutionResultProjection<TProjection extends AnyProjection> = ReturnType<TProjection[\"projector\"]>;\n","import type { Fragment, GqlElementAttachment } from \"@soda-gql/core\";\nimport { Projection } from \"./projection\";\nimport type { SlicedExecutionResult } from \"./sliced-execution-result\";\nimport type { Tuple } from \"./utils/type-utils\";\n\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any Fragment regardless of type parameters\ntype AnyFragment = Fragment<string, any, any, any>;\n\n/**\n * Options for creating a projection from a Fragment.\n */\nexport type CreateProjectionOptions<TOutput extends object, TProjected> = {\n /**\n * Field paths to extract from the execution result.\n * Each path starts with \"$.\" and follows the field selection structure.\n *\n * @example\n * ```typescript\n * paths: [\"$.user.id\", \"$.user.name\"]\n * ```\n */\n paths: Tuple<string>;\n\n /**\n * Handler function to transform the sliced execution result.\n * Receives a SlicedExecutionResult with the Fragment's output type.\n * Handles all cases: success, error, and empty.\n *\n * @example\n * ```typescript\n * handle: (result) => {\n * if (result.isError()) return { error: result.error, data: null };\n * if (result.isEmpty()) return { error: null, data: null };\n * const data = result.unwrap();\n * return { error: null, data: { userId: data.user.id } };\n * }\n * ```\n */\n handle: (result: SlicedExecutionResult<TOutput>) => TProjected;\n};\n\n/**\n * Creates a type-safe projection from a Fragment.\n *\n * The projection extracts and transforms data from GraphQL execution results,\n * with full type inference from the Fragment's output type.\n *\n * Note: The Fragment parameter is used only for type inference.\n * The actual paths must be specified explicitly.\n *\n * @param _fragment - The Fragment to infer types from (used for type inference only)\n * @param options - Projection options including paths and handle function\n * @returns A Projection that can be used with createExecutionResultParser\n *\n * @example\n * ```typescript\n * const userFragment = gql(({ fragment }) =>\n * fragment.Query({\n * variables: { ... },\n * fields: ({ f, $ }) => ({\n * ...f.user({ id: $.userId })(({ f }) => ({ ...f.id(), ...f.name() })),\n * }),\n * })\n * );\n *\n * const userProjection = createProjection(userFragment, {\n * paths: [\"$.user\"],\n * handle: (result) => {\n * if (result.isError()) return { error: result.error, user: null };\n * if (result.isEmpty()) return { error: null, user: null };\n * const data = result.unwrap();\n * return { error: null, user: data.user };\n * },\n * });\n * ```\n */\nexport const createProjection = <TFragment extends AnyFragment, TProjected>(\n _fragment: TFragment,\n options: CreateProjectionOptions<TFragment[\"$infer\"][\"output\"], TProjected>,\n): Projection<TProjected> => {\n return new Projection(options.paths, options.handle);\n};\n\nexport const createProjectionAttachment = <TFragment extends AnyFragment, TProjected>(\n options: CreateProjectionOptions<NoInfer<TFragment>[\"$infer\"][\"output\"], TProjected>,\n): GqlElementAttachment<TFragment, \"projection\", Projection<TProjected>> => {\n return {\n name: \"projection\",\n createValue: (fragment) => createProjection(fragment, options),\n };\n};\n","type ArgEntries<T extends object> = { [K in keyof T]-?: [value: T[K], key: K] }[keyof T];\ntype Entries<T extends object> = { [K in keyof T]: [key: K, value: T[K]] }[keyof T];\n\nexport function mapValues<TObject extends object, TMappedValue>(\n obj: TObject,\n fn: (...args: ArgEntries<TObject>) => TMappedValue,\n): {\n [K in keyof TObject]: TMappedValue;\n} {\n return Object.fromEntries((Object.entries(obj) as Entries<TObject>[]).map(([key, value]) => [key, fn(value, key)])) as {\n [K in keyof TObject]: TMappedValue;\n };\n}\n","import type { AnyProjection } from \"./projection\";\nimport { mapValues } from \"./utils/map-values\";\n\n/**\n * Node in the projection path graph tree.\n * Used for mapping GraphQL errors and data to their corresponding slices.\n */\nexport type ProjectionPathGraphNode = {\n readonly matches: { label: string; path: string; exact: boolean }[];\n readonly children: { readonly [segment: string]: ProjectionPathGraphNode };\n};\n\n/**\n * Payload from a slice that contains projection.\n */\nexport type AnySlicePayload = {\n readonly projection: AnyProjection;\n};\n\nexport type AnySlicePayloads = Record<string, AnySlicePayload>;\n\ntype ExecutionResultProjectionPathGraphIntermediate = {\n [segment: string]: { label: string; raw: string; segments: string[] }[];\n};\n\nfunction createPathGraph(paths: ExecutionResultProjectionPathGraphIntermediate[string]): ProjectionPathGraphNode {\n const intermediate = paths.reduce(\n (acc: ExecutionResultProjectionPathGraphIntermediate, { label, raw, segments: [segment, ...segments] }) => {\n if (segment) {\n (acc[segment] || (acc[segment] = [])).push({ label, raw, segments });\n }\n return acc;\n },\n {},\n );\n\n return {\n matches: paths.map(({ label, raw, segments }) => ({ label, path: raw, exact: segments.length === 0 })),\n children: mapValues(intermediate, (paths) => createPathGraph(paths)),\n } satisfies ProjectionPathGraphNode;\n}\n\n/**\n * Creates a projection path graph from slice entries with field prefixing.\n * Each slice's paths are prefixed with the slice label for disambiguation.\n */\nexport function createPathGraphFromSliceEntries(fragments: AnySlicePayloads) {\n const paths = Object.entries(fragments).flatMap(([label, slice]) =>\n Array.from(\n new Map(\n slice.projection.paths.map(({ full: raw, segments }) => {\n const [first, ...rest] = segments;\n return [raw, { label, raw, segments: [`${label}_${first}`, ...rest] }];\n }),\n ).values(),\n ),\n );\n\n return createPathGraph(paths);\n}\n","/** Result-like wrapper types returned from slice projections. */\n\nimport type { NormalizedError } from \"./types\";\n\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any SlicedExecutionResult regardless of data type\nexport type AnySlicedExecutionResult = SlicedExecutionResult<any>;\n\n/**\n * Internal discriminated union describing the Result-like wrapper exposed to\n * slice selection callbacks.\n */\nexport type AnySlicedExecutionResultRecord = {\n [path: string]: AnySlicedExecutionResult;\n};\n\nexport type SafeUnwrapResult<TTransformed, TError> =\n | {\n data?: never;\n error?: never;\n }\n | {\n data: TTransformed;\n error?: never;\n }\n | {\n data?: never;\n error: TError;\n };\n\n/** Utility signature returned by the safe unwrap helper. */\ntype SlicedExecutionResultCommon<TData, TError> = {\n safeUnwrap<TTransformed>(transform: (data: TData) => TTransformed): SafeUnwrapResult<TTransformed, TError>;\n};\n\n/** Public union used by selection callbacks to inspect data, empty, or error states. */\nexport type SlicedExecutionResult<TData> =\n | SlicedExecutionResultEmpty<TData>\n | SlicedExecutionResultSuccess<TData>\n | SlicedExecutionResultError<TData>;\n\n/** Runtime guard interface shared by all slice result variants. */\nclass SlicedExecutionResultGuards<TData> {\n isSuccess(): this is SlicedExecutionResultSuccess<TData> {\n return this.type === \"success\";\n }\n isError(): this is SlicedExecutionResultError<TData> {\n return this.type === \"error\";\n }\n isEmpty(): this is SlicedExecutionResultEmpty<TData> {\n return this.type === \"empty\";\n }\n\n constructor(private readonly type: \"success\" | \"error\" | \"empty\") {}\n}\n\n/** Variant representing an empty payload (no data, no error). */\nexport class SlicedExecutionResultEmpty<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor() {\n super(\"empty\");\n }\n\n unwrap(): null {\n return null;\n }\n\n safeUnwrap() {\n return {\n data: undefined,\n error: undefined,\n };\n }\n}\n\n/** Variant representing a successful payload. */\nexport class SlicedExecutionResultSuccess<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor(\n public readonly data: TData,\n public readonly extensions?: unknown,\n ) {\n super(\"success\");\n }\n\n unwrap(): TData {\n return this.data;\n }\n\n safeUnwrap<TTransformed>(transform: (data: TData) => TTransformed) {\n return {\n data: transform(this.data),\n error: undefined,\n };\n }\n}\n\n/** Variant representing an error payload. */\nexport class SlicedExecutionResultError<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor(\n public readonly error: NormalizedError,\n public readonly extensions?: unknown,\n ) {\n super(\"error\");\n }\n\n unwrap(): never {\n throw this.error;\n }\n\n safeUnwrap() {\n return {\n data: undefined,\n error: this.error,\n };\n }\n}\n","import type { GraphQLFormattedError } from \"graphql\";\nimport { type AnySlicePayloads, createPathGraphFromSliceEntries, type ProjectionPathGraphNode } from \"./projection-path-graph\";\nimport { SlicedExecutionResultEmpty, SlicedExecutionResultError, SlicedExecutionResultSuccess } from \"./sliced-execution-result\";\nimport type { NormalizedExecutionResult } from \"./types\";\n\n// Internal function to build path graph from slices\nconst createPathGraphFromSlices = createPathGraphFromSliceEntries;\n\nfunction* generateErrorMapEntries(errors: readonly GraphQLFormattedError[], projectionPathGraph: ProjectionPathGraphNode) {\n for (const error of errors) {\n const errorPath = error.path ?? [];\n let stack = projectionPathGraph;\n\n for (\n let i = 0;\n // i <= errorPath.length to handle the case where the error path is empty\n i <= errorPath.length;\n i++\n ) {\n const segment = errorPath[i];\n\n if (\n // the end of the path\n segment == null ||\n // FieldPath does not support index access. We treat it as the end of the path.\n typeof segment === \"number\"\n ) {\n yield* stack.matches.map(({ label, path }) => ({ label, path, error }));\n break;\n }\n\n yield* stack.matches.filter(({ exact }) => exact).map(({ label, path }) => ({ label, path, error }));\n\n const next = stack.children[segment];\n if (!next) {\n break;\n }\n\n stack = next;\n }\n }\n}\n\nconst createErrorMaps = (errors: readonly GraphQLFormattedError[] | undefined, projectionPathGraph: ProjectionPathGraphNode) => {\n const errorMaps: { [label: string]: { [path: string]: { error: GraphQLFormattedError }[] } } = {};\n for (const { label, path, error } of generateErrorMapEntries(errors ?? [], projectionPathGraph)) {\n const mapPerLabel = errorMaps[label] || (errorMaps[label] = {});\n const mapPerPath = mapPerLabel[path] || (mapPerLabel[path] = []);\n mapPerPath.push({ error });\n }\n return errorMaps;\n};\n\nconst accessDataByPathSegments = (data: object, pathSegments: string[]) => {\n let current: unknown = data;\n\n for (const segment of pathSegments) {\n if (current == null) {\n return { error: new Error(\"No data\") };\n }\n\n if (typeof current !== \"object\") {\n return { error: new Error(\"Incorrect data type\") };\n }\n\n if (Array.isArray(current)) {\n return { error: new Error(\"Incorrect data type\") };\n }\n\n current = (current as Record<string, unknown>)[segment];\n }\n\n return { data: current };\n};\n\n/**\n * Creates an execution result parser for composed operations.\n * The parser maps GraphQL errors and data to their corresponding slices\n * based on the projection path graph.\n *\n * @param slices - Object mapping labels to projections\n * @returns A parser function that takes a NormalizedExecutionResult and returns parsed slices\n *\n * @example\n * ```typescript\n * const parser = createExecutionResultParser({\n * userCard: userCardProjection,\n * posts: postsProjection,\n * });\n *\n * const results = parser({\n * type: \"graphql\",\n * body: { data, errors },\n * });\n * ```\n */\nexport const createExecutionResultParser = <TSlices extends AnySlicePayloads>(slices: TSlices) => {\n // Build path graph from slices\n const projectionPathGraph = createPathGraphFromSlices(slices);\n const fragments = slices;\n const prepare = (result: NormalizedExecutionResult<object, object>) => {\n if (result.type === \"graphql\") {\n const errorMaps = createErrorMaps(result.body.errors, projectionPathGraph);\n\n return { ...result, errorMaps };\n }\n\n if (result.type === \"non-graphql-error\") {\n return { ...result, error: new SlicedExecutionResultError({ type: \"non-graphql-error\", error: result.error }) };\n }\n\n if (result.type === \"empty\") {\n return { ...result, error: new SlicedExecutionResultEmpty() };\n }\n\n throw new Error(\"Invalid result type\", { cause: result satisfies never });\n };\n\n return (result: NormalizedExecutionResult<object, object>) => {\n const prepared = prepare(result);\n\n const entries = Object.entries(fragments).map(([label, fragment]) => {\n const { projection } = fragment;\n\n if (prepared.type === \"graphql\") {\n const matchedErrors = projection.paths.flatMap(({ full: raw }) => prepared.errorMaps[label]?.[raw] ?? []);\n const uniqueErrors = Array.from(new Set(matchedErrors.map(({ error }) => error)).values());\n\n if (uniqueErrors.length > 0) {\n return [label, projection.projector(new SlicedExecutionResultError({ type: \"graphql-error\", errors: uniqueErrors }))];\n }\n\n // Apply label prefix to first segment for data access (matching $colocate prefix pattern)\n const dataResults = projection.paths.map(({ segments }) => {\n const [first, ...rest] = segments;\n const prefixedSegments = [`${label}_${first}`, ...rest];\n return prepared.body.data\n ? accessDataByPathSegments(prepared.body.data, prefixedSegments)\n : { error: new Error(\"No data\") };\n });\n if (dataResults.some(({ error }) => error)) {\n const errors = dataResults.flatMap(({ error }) => (error ? [error] : []));\n return [label, projection.projector(new SlicedExecutionResultError({ type: \"parse-error\", errors }))];\n }\n\n const dataList = dataResults.map(({ data }) => data);\n return [label, projection.projector(new SlicedExecutionResultSuccess(dataList))];\n }\n\n if (prepared.type === \"non-graphql-error\") {\n return [label, projection.projector(prepared.error)];\n }\n\n if (prepared.type === \"empty\") {\n return [label, projection.projector(prepared.error)];\n }\n\n throw new Error(\"Invalid result type\", { cause: prepared satisfies never });\n });\n\n return Object.fromEntries(entries);\n };\n};\n"],"mappings":";;;;;;;AAaA,IAAa,aAAb,MAAoC;CAKlC,YACE,OACA,AAAgBA,WAChB;EADgB;AAEhB,OAAK,QAAQ,MAAM,KAAK,SAAS,qBAAqB,KAAK,CAAC;AAE5D,SAAO,eAAe,MAAM,UAAU,EACpC,MAAM;AACJ,SAAM,IAAI,MAAM,6EAA6E;KAEhG,CAAC;;CAGJ,AAAgB;;AAQlB,SAAS,qBAAqB,MAA8B;CAC1D,MAAM,WAAW,KAAK,MAAM,IAAI;AAChC,KAAI,SAAS,OAAO,SAAS,UAAU,EACrC,OAAM,IAAI,MAAM,yCAAyC;AAG3D,QAAO;EACL,MAAM;EACN,UAAU,SAAS,MAAM,EAAE;EAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC4BH,MAAa,oBACX,WACA,YAC2B;AAC3B,QAAO,IAAI,WAAW,QAAQ,OAAO,QAAQ,OAAO;;AAGtD,MAAa,8BACX,YAC0E;AAC1E,QAAO;EACL,MAAM;EACN,cAAc,aAAa,iBAAiB,UAAU,QAAQ;EAC/D;;;;;ACtFH,SAAgB,UACd,KACA,IAGA;AACA,QAAO,OAAO,YAAa,OAAO,QAAQ,IAAI,CAAwB,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC;;;;;ACgBrH,SAAS,gBAAgB,OAAwF;CAC/G,MAAM,eAAe,MAAM,QACxB,KAAqD,EAAE,OAAO,KAAK,UAAU,CAAC,SAAS,GAAG,gBAAgB;AACzG,MAAI,QACF,EAAC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C,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK;AACvD,YAAO,SAAS,KAAK,OACjB,yBAAyB,SAAS,KAAK,MAAM,iBAAiB,GAC9D,EAAE,uBAAO,IAAI,MAAM,UAAU,EAAE;MACnC;AACF,QAAI,YAAY,MAAM,EAAE,YAAY,MAAM,EAAE;KAC1C,MAAM,SAAS,YAAY,SAAS,EAAE,YAAa,QAAQ,CAAC,MAAM,GAAG,EAAE,CAAE;AACzE,YAAO,CAAC,OAAO,WAAW,UAAU,IAAI,2BAA2B;MAAE,MAAM;MAAe;MAAQ,CAAC,CAAC,CAAC;;IAGvG,MAAM,WAAW,YAAY,KAAK,EAAE,WAAW,KAAK;AACpD,WAAO,CAAC,OAAO,WAAW,UAAU,IAAI,6BAA6B,SAAS,CAAC,CAAC;;AAGlF,OAAI,SAAS,SAAS,oBACpB,QAAO,CAAC,OAAO,WAAW,UAAU,SAAS,MAAM,CAAC;AAGtD,OAAI,SAAS,SAAS,QACpB,QAAO,CAAC,OAAO,WAAW,UAAU,SAAS,MAAM,CAAC;AAGtD,SAAM,IAAI,MAAM,uBAAuB,EAAE,OAAO,UAA0B,CAAC;IAC3E;AAEF,SAAO,OAAO,YAAY,QAAQ"}
|
package/dist/index.d.cts
CHANGED
|
@@ -179,9 +179,12 @@ type CreateProjectionOptions<TOutput extends object, TProjected> = {
|
|
|
179
179
|
* @example
|
|
180
180
|
* ```typescript
|
|
181
181
|
* const userFragment = gql(({ fragment }) =>
|
|
182
|
-
* fragment.Query({
|
|
183
|
-
*
|
|
184
|
-
*
|
|
182
|
+
* fragment.Query({
|
|
183
|
+
* variables: { ... },
|
|
184
|
+
* fields: ({ f, $ }) => ({
|
|
185
|
+
* ...f.user({ id: $.userId })(({ f }) => ({ ...f.id(), ...f.name() })),
|
|
186
|
+
* }),
|
|
187
|
+
* })
|
|
185
188
|
* );
|
|
186
189
|
*
|
|
187
190
|
* const userProjection = createProjection(userFragment, {
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/sliced-execution-result.ts","../src/utils/type-utils.ts","../src/projection.ts","../src/create-projection.ts","../src/projection-path-graph.ts","../src/parse-execution-result.ts","../src/types/field-path.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAMA;AAMY,KANA,eAAA,GAMA,OAAyB;;;;;AAGjC,KAHQ,yBAGR,CAAA,KAAA,EAAA,WAAA,CAAA,GAFA,WAEA,GADA,sBACA,CADuB,KACvB,EAD8B,WAC9B,CAAA,GAAA,qBAAA;AAAqB,KAEb,WAAA,GAFa;EAEb,IAAA,EAAA,OAAA;AAIZ,CAAA;AAEiC,KAFrB,sBAEqB,CAAA,KAAA,EAAA,WAAA,CAAA,GAAA;EAAO,IAAA,EAAA,SAAA;EAAhC,IAAA,EAAA,wBAAA,CAAyB,KAAzB,EAAgC,WAAhC,CAAA;CAAwB;AAGpB,KAAA,qBAAA,GAAqB;EAQrB,IAAA,EAAA,mBAAe;EAGb,KAAA,EATL,eASK;CAID;;;;KAPD,eAAA;;EC7BA,MAAA,EDgCE,qBChCsB,EAAA;AAMpC,CAAA,GAAY;EAIA,IAAA,EAAA,mBAAgB;EAevB,KAAA,EDWQ,eCXR;CACwC,GAAA;EAAU,IAAA,EAAA,aAAA;EAAgC,MAAA,EDczE,KCdyE,EAAA;CAAc;;;KA1BzF,wBAAA,GAA2B;;ADCvC;AAMA;;AAE2B,KCHf,8BAAA,GDGe;EAAO,CAAA,IAAA,EAAA,MAAA,CAAA,ECFhB,wBDEgB;CAA9B;AACA,KCAQ,gBDAR,CAAA,YAAA,EAAA,MAAA,CAAA,GAAA;EAAqB,IAAA,CAAA,EAAA,KAAA;EAEb,KAAA,CAAA,EAAA,KAAA;AAIZ,CAAA,GAAY;EAEqB,IAAA,ECFrB,YDEqB;EAAO,KAAA,CAAA,EAAA,KAAA;CAAhC,GAAA;EAAwB,IAAA,CAAA,EAAA,KAAA;EAGpB,KAAA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IC;AAAK,KGMP,8BHNO,CAAA,oBGM4C,aHN5C,CAAA,GGM6D,UHN7D,CGMwE,WHNxE,CAAA,WAAA,CAAA,CAAA;;;AAvCnB,KIAK,WAAA,GAAc,QJAQ,CAAA,MAAA,EAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA;AAM3B;;;AAEkC,KIHtB,uBJGsB,CAAA,gBAAA,MAAA,EAAA,UAAA,CAAA,GAAA;EAA9B;;;AAGJ;AAIA;;;;;EAKY,KAAA,EILH,KJKG,CAAA,MAAA,CAAA;EAQA;;;;;;;;AC7BZ;AAMA;AAIA;AAYM;;;;EAI+F,MAAA,EAAA,CAAA,MAAA,EGOlF,qBHPkF,CGO5D,OHP4D,CAAA,EAAA,GGO/C,UHP+C;CAA/B;;AAItE;;;;;;;;AAGsC;;;;;;;;AAkBtC;;;;;;;AAqBA
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/sliced-execution-result.ts","../src/utils/type-utils.ts","../src/projection.ts","../src/create-projection.ts","../src/projection-path-graph.ts","../src/parse-execution-result.ts","../src/types/field-path.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAMA;AAMY,KANA,eAAA,GAMA,OAAyB;;;;;AAGjC,KAHQ,yBAGR,CAAA,KAAA,EAAA,WAAA,CAAA,GAFA,WAEA,GADA,sBACA,CADuB,KACvB,EAD8B,WAC9B,CAAA,GAAA,qBAAA;AAAqB,KAEb,WAAA,GAFa;EAEb,IAAA,EAAA,OAAA;AAIZ,CAAA;AAEiC,KAFrB,sBAEqB,CAAA,KAAA,EAAA,WAAA,CAAA,GAAA;EAAO,IAAA,EAAA,SAAA;EAAhC,IAAA,EAAA,wBAAA,CAAyB,KAAzB,EAAgC,WAAhC,CAAA;CAAwB;AAGpB,KAAA,qBAAA,GAAqB;EAQrB,IAAA,EAAA,mBAAe;EAGb,KAAA,EATL,eASK;CAID;;;;KAPD,eAAA;;EC7BA,MAAA,EDgCE,qBChCsB,EAAA;AAM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GAAA,0BACA,MOG4B,OPH5B,GAAA,MAAA,GAAA,GOIK,KPJL,IOIc,UPJd,EAAA,GAAA,COKG,OPLH,COKW,UPLX,CAAA,SAAA;EAAqB,MAAA,EAAA,KAAA,iBOK0C,ePL1C;AAEb,CAAA,GOIF,wBPJa,COIY,OPJZ,EOIqB,OPJrB,EAAA,GOIiC,KPJjC,IOI0C,UPJ1C,EAAA,CAAA,GAAA,KAAA,CAAA,EAIvB,CAAA,MOEQ,OPFI,GAAA,MAAA,CAAA;;AAE4B,KOG5B,gBPH4B,CAAA,gBOItB,gBPJsB,EAAA,gBOKtB,SPLsB,EAAA,cOMxB,YPNwB,CAAA,GAAA,MAAA,SAAA,MOQf,OPRe,GAAA,GAAA,GOQC,KPRD,SAAA,GAAA,GAAA,KAAA,GOQ6B,qBPR7B,COQmD,OPRnD,EOQ4D,OPR5D,EOQqE,KPRrE,EAAA,GAAA,CAAA;;KOWnC,qBPX2B,CAAA,gBOYd,gBPZc,EAAA,gBOad,SPbc,EAAA,oBOcV,YPdU,EAAA,qBOeT,YPfS,CAAA,GAAA,0BAGC,MOcD,OPZvB,GOYiC,UPZjC,SAAe,MAAA,GAAA,GOaf,YPbe,IOaC,UPbD,EAAA,SOasB,WPbtB,GOchB,UPdgB,COcL,OPdK,EOcI,OPdJ,COcY,UPdZ,CAAA,CAAA,GOehB,OPfgB,COeR,UPfQ,CAAA,SAAA;EAMZ,MAAA,EAAA,KAAe,iBOSyC,ePTzC;AAGb,CAAA,GOOJ,qBPPI,COOkB,OPPlB,EOO2B,OPP3B,EOOoC,WPPpC,EAAA,GOOoD,YPPpD,IOOoE,UPPpE,EAAA,CAAA,GAAA,KAAA,GAAA,KAAA,EAID,CAAA,MOML,OPNK,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -179,9 +179,12 @@ type CreateProjectionOptions<TOutput extends object, TProjected> = {
|
|
|
179
179
|
* @example
|
|
180
180
|
* ```typescript
|
|
181
181
|
* const userFragment = gql(({ fragment }) =>
|
|
182
|
-
* fragment.Query({
|
|
183
|
-
*
|
|
184
|
-
*
|
|
182
|
+
* fragment.Query({
|
|
183
|
+
* variables: { ... },
|
|
184
|
+
* fields: ({ f, $ }) => ({
|
|
185
|
+
* ...f.user({ id: $.userId })(({ f }) => ({ ...f.id(), ...f.name() })),
|
|
186
|
+
* }),
|
|
187
|
+
* })
|
|
185
188
|
* );
|
|
186
189
|
*
|
|
187
190
|
* const userProjection = createProjection(userFragment, {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/sliced-execution-result.ts","../src/utils/type-utils.ts","../src/projection.ts","../src/create-projection.ts","../src/projection-path-graph.ts","../src/parse-execution-result.ts","../src/types/field-path.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAMA;AAMY,KANA,eAAA,GAMA,OAAyB;;;;;AAGjC,KAHQ,yBAGR,CAAA,KAAA,EAAA,WAAA,CAAA,GAFA,WAEA,GADA,sBACA,CADuB,KACvB,EAD8B,WAC9B,CAAA,GAAA,qBAAA;AAAqB,KAEb,WAAA,GAFa;EAEb,IAAA,EAAA,OAAA;AAIZ,CAAA;AAEiC,KAFrB,sBAEqB,CAAA,KAAA,EAAA,WAAA,CAAA,GAAA;EAAO,IAAA,EAAA,SAAA;EAAhC,IAAA,EAAA,wBAAA,CAAyB,KAAzB,EAAgC,WAAhC,CAAA;CAAwB;AAGpB,KAAA,qBAAA,GAAqB;EAQrB,IAAA,EAAA,mBAAe;EAGb,KAAA,EATL,eASK;CAID;;;;KAPD,eAAA;;EC7BA,MAAA,EDgCE,qBChCsB,EAAA;AAMpC,CAAA,GAAY;EAIA,IAAA,EAAA,mBAAgB;EAevB,KAAA,EDWQ,eCXR;CACwC,GAAA;EAAU,IAAA,EAAA,aAAA;EAAgC,MAAA,EDczE,KCdyE,EAAA;CAAc;;;KA1BzF,wBAAA,GAA2B;;ADCvC;AAMA;;AAE2B,KCHf,8BAAA,GDGe;EAAO,CAAA,IAAA,EAAA,MAAA,CAAA,ECFhB,wBDEgB;CAA9B;AACA,KCAQ,gBDAR,CAAA,YAAA,EAAA,MAAA,CAAA,GAAA;EAAqB,IAAA,CAAA,EAAA,KAAA;EAEb,KAAA,CAAA,EAAA,KAAA;AAIZ,CAAA,GAAY;EAEqB,IAAA,ECFrB,YDEqB;EAAO,KAAA,CAAA,EAAA,KAAA;CAAhC,GAAA;EAAwB,IAAA,CAAA,EAAA,KAAA;EAGpB,KAAA,ECAC,MDAD;AAQZ,CAAA;;KCJK,2BDWQ,CAAA,KAAA,EAAA,MAAA,CAAA,GAAA;EAIC,UAAA,CAAA,YAAA,CAAA,CAAA,SAAA,EAAA,CAAA,IAAA,ECd+B,KDc/B,EAAA,GCdyC,YDczC,CAAA,ECdwD,gBDcxD,CCdyE,YDczE,ECduF,MDcvF,CAAA;CAAK;;KCVP,+BACR,2BAA2B,SAC3B,6BAA6B,SAC7B,2BAA2B;;AAjC/B,cAoCM,2BApC8B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/sliced-execution-result.ts","../src/utils/type-utils.ts","../src/projection.ts","../src/create-projection.ts","../src/projection-path-graph.ts","../src/parse-execution-result.ts","../src/types/field-path.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAMA;AAMY,KANA,eAAA,GAMA,OAAyB;;;;;AAGjC,KAHQ,yBAGR,CAAA,KAAA,EAAA,WAAA,CAAA,GAFA,WAEA,GADA,sBACA,CADuB,KACvB,EAD8B,WAC9B,CAAA,GAAA,qBAAA;AAAqB,KAEb,WAAA,GAFa;EAEb,IAAA,EAAA,OAAA;AAIZ,CAAA;AAEiC,KAFrB,sBAEqB,CAAA,KAAA,EAAA,WAAA,CAAA,GAAA;EAAO,IAAA,EAAA,SAAA;EAAhC,IAAA,EAAA,wBAAA,CAAyB,KAAzB,EAAgC,WAAhC,CAAA;CAAwB;AAGpB,KAAA,qBAAA,GAAqB;EAQr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Path(path) {
|
|
|
41
41
|
* @example
|
|
42
42
|
* ```typescript
|
|
43
43
|
* const userFragment = gql(({ fragment }) =>
|
|
44
|
-
* fragment.Query({
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* fragment.Query({
|
|
45
|
+
* variables: { ... },
|
|
46
|
+
* fields: ({ f, $ }) => ({
|
|
47
|
+
* ...f.user({ id: $.userId })(({ f }) => ({ ...f.id(), ...f.name() })),
|
|
48
|
+
* }),
|
|
49
|
+
* })
|
|
47
50
|
* );
|
|
48
51
|
*
|
|
49
52
|
* const userProjection = createProjection(userFragment, {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["projector: (result: AnySlicedExecutionResult) => TProjected","paths","type: \"success\" | \"error\" | \"empty\"","data: TData","extensions?: unknown","error: NormalizedError","errorMaps: { [label: string]: { [path: string]: { error: GraphQLFormattedError }[] } }","current: unknown"],"sources":["../src/projection.ts","../src/create-projection.ts","../src/utils/map-values.ts","../src/projection-path-graph.ts","../src/sliced-execution-result.ts","../src/parse-execution-result.ts"],"sourcesContent":["import type { AnySlicedExecutionResult } from \"./sliced-execution-result\";\nimport type { Tuple } from \"./utils/type-utils\";\n\n/** Shape of a single selection slice projection. */\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any Projection regardless of projected type\nexport type AnyProjection = Projection<any>;\n\ndeclare const __PROJECTION_BRAND__: unique symbol;\n/**\n * Nominal type representing any slice selection regardless of schema specifics.\n * Encodes how individual slices map a concrete field path to a projection\n * function. Multiple selections allow slices to expose several derived values.\n */\nexport class Projection<TProjected> {\n declare readonly [__PROJECTION_BRAND__]: void;\n\n declare readonly $infer: { readonly output: TProjected };\n\n constructor(\n paths: Tuple<string>,\n public readonly projector: (result: AnySlicedExecutionResult) => TProjected,\n ) {\n this.paths = paths.map((path) => createProjectionPath(path));\n\n Object.defineProperty(this, \"$infer\", {\n get() {\n throw new Error(\"This property is only for type meta. Do not access this property directly.\");\n },\n });\n }\n\n public readonly paths: ProjectionPath[];\n}\n\nexport type ProjectionPath = {\n full: string;\n segments: Tuple<string>;\n};\n\nfunction createProjectionPath(path: string): ProjectionPath {\n const segments = path.split(\".\");\n if (path === \"$\" || segments.length <= 1) {\n throw new Error(\"Field path must not be only $ or empty\");\n }\n\n return {\n full: path,\n segments: segments.slice(1) as Tuple<string>,\n };\n}\n\nexport type InferExecutionResultProjection<TProjection extends AnyProjection> = ReturnType<TProjection[\"projector\"]>;\n","import type { Fragment, GqlElementAttachment } from \"@soda-gql/core\";\nimport { Projection } from \"./projection\";\nimport type { SlicedExecutionResult } from \"./sliced-execution-result\";\nimport type { Tuple } from \"./utils/type-utils\";\n\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any Fragment regardless of type parameters\ntype AnyFragment = Fragment<string, any, any, any>;\n\n/**\n * Options for creating a projection from a Fragment.\n */\nexport type CreateProjectionOptions<TOutput extends object, TProjected> = {\n /**\n * Field paths to extract from the execution result.\n * Each path starts with \"$.\" and follows the field selection structure.\n *\n * @example\n * ```typescript\n * paths: [\"$.user.id\", \"$.user.name\"]\n * ```\n */\n paths: Tuple<string>;\n\n /**\n * Handler function to transform the sliced execution result.\n * Receives a SlicedExecutionResult with the Fragment's output type.\n * Handles all cases: success, error, and empty.\n *\n * @example\n * ```typescript\n * handle: (result) => {\n * if (result.isError()) return { error: result.error, data: null };\n * if (result.isEmpty()) return { error: null, data: null };\n * const data = result.unwrap();\n * return { error: null, data: { userId: data.user.id } };\n * }\n * ```\n */\n handle: (result: SlicedExecutionResult<TOutput>) => TProjected;\n};\n\n/**\n * Creates a type-safe projection from a Fragment.\n *\n * The projection extracts and transforms data from GraphQL execution results,\n * with full type inference from the Fragment's output type.\n *\n * Note: The Fragment parameter is used only for type inference.\n * The actual paths must be specified explicitly.\n *\n * @param _fragment - The Fragment to infer types from (used for type inference only)\n * @param options - Projection options including paths and handle function\n * @returns A Projection that can be used with createExecutionResultParser\n *\n * @example\n * ```typescript\n * const userFragment = gql(({ fragment }) =>\n * fragment.Query({ variables: [...] }, ({ f, $ }) => [\n * f.user({ id: $.userId })(({ f }) => [f.id(), f.name()]),\n * ])\n * );\n *\n * const userProjection = createProjection(userFragment, {\n * paths: [\"$.user\"],\n * handle: (result) => {\n * if (result.isError()) return { error: result.error, user: null };\n * if (result.isEmpty()) return { error: null, user: null };\n * const data = result.unwrap();\n * return { error: null, user: data.user };\n * },\n * });\n * ```\n */\nexport const createProjection = <TFragment extends AnyFragment, TProjected>(\n _fragment: TFragment,\n options: CreateProjectionOptions<TFragment[\"$infer\"][\"output\"], TProjected>,\n): Projection<TProjected> => {\n return new Projection(options.paths, options.handle);\n};\n\nexport const createProjectionAttachment = <TFragment extends AnyFragment, TProjected>(\n options: CreateProjectionOptions<NoInfer<TFragment>[\"$infer\"][\"output\"], TProjected>,\n): GqlElementAttachment<TFragment, \"projection\", Projection<TProjected>> => {\n return {\n name: \"projection\",\n createValue: (fragment) => createProjection(fragment, options),\n };\n};\n","type ArgEntries<T extends object> = { [K in keyof T]-?: [value: T[K], key: K] }[keyof T];\ntype Entries<T extends object> = { [K in keyof T]: [key: K, value: T[K]] }[keyof T];\n\nexport function mapValues<TObject extends object, TMappedValue>(\n obj: TObject,\n fn: (...args: ArgEntries<TObject>) => TMappedValue,\n): {\n [K in keyof TObject]: TMappedValue;\n} {\n return Object.fromEntries((Object.entries(obj) as Entries<TObject>[]).map(([key, value]) => [key, fn(value, key)])) as {\n [K in keyof TObject]: TMappedValue;\n };\n}\n","import type { AnyProjection } from \"./projection\";\nimport { mapValues } from \"./utils/map-values\";\n\n/**\n * Node in the projection path graph tree.\n * Used for mapping GraphQL errors and data to their corresponding slices.\n */\nexport type ProjectionPathGraphNode = {\n readonly matches: { label: string; path: string; exact: boolean }[];\n readonly children: { readonly [segment: string]: ProjectionPathGraphNode };\n};\n\n/**\n * Payload from a slice that contains projection.\n */\nexport type AnySlicePayload = {\n readonly projection: AnyProjection;\n};\n\nexport type AnySlicePayloads = Record<string, AnySlicePayload>;\n\ntype ExecutionResultProjectionPathGraphIntermediate = {\n [segment: string]: { label: string; raw: string; segments: string[] }[];\n};\n\nfunction createPathGraph(paths: ExecutionResultProjectionPathGraphIntermediate[string]): ProjectionPathGraphNode {\n const intermediate = paths.reduce(\n (acc: ExecutionResultProjectionPathGraphIntermediate, { label, raw, segments: [segment, ...segments] }) => {\n if (segment) {\n (acc[segment] || (acc[segment] = [])).push({ label, raw, segments });\n }\n return acc;\n },\n {},\n );\n\n return {\n matches: paths.map(({ label, raw, segments }) => ({ label, path: raw, exact: segments.length === 0 })),\n children: mapValues(intermediate, (paths) => createPathGraph(paths)),\n } satisfies ProjectionPathGraphNode;\n}\n\n/**\n * Creates a projection path graph from slice entries with field prefixing.\n * Each slice's paths are prefixed with the slice label for disambiguation.\n */\nexport function createPathGraphFromSliceEntries(fragments: AnySlicePayloads) {\n const paths = Object.entries(fragments).flatMap(([label, slice]) =>\n Array.from(\n new Map(\n slice.projection.paths.map(({ full: raw, segments }) => {\n const [first, ...rest] = segments;\n return [raw, { label, raw, segments: [`${label}_${first}`, ...rest] }];\n }),\n ).values(),\n ),\n );\n\n return createPathGraph(paths);\n}\n","/** Result-like wrapper types returned from slice projections. */\n\nimport type { NormalizedError } from \"./types\";\n\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any SlicedExecutionResult regardless of data type\nexport type AnySlicedExecutionResult = SlicedExecutionResult<any>;\n\n/**\n * Internal discriminated union describing the Result-like wrapper exposed to\n * slice selection callbacks.\n */\nexport type AnySlicedExecutionResultRecord = {\n [path: string]: AnySlicedExecutionResult;\n};\n\nexport type SafeUnwrapResult<TTransformed, TError> =\n | {\n data?: never;\n error?: never;\n }\n | {\n data: TTransformed;\n error?: never;\n }\n | {\n data?: never;\n error: TError;\n };\n\n/** Utility signature returned by the safe unwrap helper. */\ntype SlicedExecutionResultCommon<TData, TError> = {\n safeUnwrap<TTransformed>(transform: (data: TData) => TTransformed): SafeUnwrapResult<TTransformed, TError>;\n};\n\n/** Public union used by selection callbacks to inspect data, empty, or error states. */\nexport type SlicedExecutionResult<TData> =\n | SlicedExecutionResultEmpty<TData>\n | SlicedExecutionResultSuccess<TData>\n | SlicedExecutionResultError<TData>;\n\n/** Runtime guard interface shared by all slice result variants. */\nclass SlicedExecutionResultGuards<TData> {\n isSuccess(): this is SlicedExecutionResultSuccess<TData> {\n return this.type === \"success\";\n }\n isError(): this is SlicedExecutionResultError<TData> {\n return this.type === \"error\";\n }\n isEmpty(): this is SlicedExecutionResultEmpty<TData> {\n return this.type === \"empty\";\n }\n\n constructor(private readonly type: \"success\" | \"error\" | \"empty\") {}\n}\n\n/** Variant representing an empty payload (no data, no error). */\nexport class SlicedExecutionResultEmpty<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor() {\n super(\"empty\");\n }\n\n unwrap(): null {\n return null;\n }\n\n safeUnwrap() {\n return {\n data: undefined,\n error: undefined,\n };\n }\n}\n\n/** Variant representing a successful payload. */\nexport class SlicedExecutionResultSuccess<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor(\n public readonly data: TData,\n public readonly extensions?: unknown,\n ) {\n super(\"success\");\n }\n\n unwrap(): TData {\n return this.data;\n }\n\n safeUnwrap<TTransformed>(transform: (data: TData) => TTransformed) {\n return {\n data: transform(this.data),\n error: undefined,\n };\n }\n}\n\n/** Variant representing an error payload. */\nexport class SlicedExecutionResultError<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor(\n public readonly error: NormalizedError,\n public readonly extensions?: unknown,\n ) {\n super(\"error\");\n }\n\n unwrap(): never {\n throw this.error;\n }\n\n safeUnwrap() {\n return {\n data: undefined,\n error: this.error,\n };\n }\n}\n","import type { GraphQLFormattedError } from \"graphql\";\nimport { type AnySlicePayloads, createPathGraphFromSliceEntries, type ProjectionPathGraphNode } from \"./projection-path-graph\";\nimport { SlicedExecutionResultEmpty, SlicedExecutionResultError, SlicedExecutionResultSuccess } from \"./sliced-execution-result\";\nimport type { NormalizedExecutionResult } from \"./types\";\n\n// Internal function to build path graph from slices\nconst createPathGraphFromSlices = createPathGraphFromSliceEntries;\n\nfunction* generateErrorMapEntries(errors: readonly GraphQLFormattedError[], projectionPathGraph: ProjectionPathGraphNode) {\n for (const error of errors) {\n const errorPath = error.path ?? [];\n let stack = projectionPathGraph;\n\n for (\n let i = 0;\n // i <= errorPath.length to handle the case where the error path is empty\n i <= errorPath.length;\n i++\n ) {\n const segment = errorPath[i];\n\n if (\n // the end of the path\n segment == null ||\n // FieldPath does not support index access. We treat it as the end of the path.\n typeof segment === \"number\"\n ) {\n yield* stack.matches.map(({ label, path }) => ({ label, path, error }));\n break;\n }\n\n yield* stack.matches.filter(({ exact }) => exact).map(({ label, path }) => ({ label, path, error }));\n\n const next = stack.children[segment];\n if (!next) {\n break;\n }\n\n stack = next;\n }\n }\n}\n\nconst createErrorMaps = (errors: readonly GraphQLFormattedError[] | undefined, projectionPathGraph: ProjectionPathGraphNode) => {\n const errorMaps: { [label: string]: { [path: string]: { error: GraphQLFormattedError }[] } } = {};\n for (const { label, path, error } of generateErrorMapEntries(errors ?? [], projectionPathGraph)) {\n const mapPerLabel = errorMaps[label] || (errorMaps[label] = {});\n const mapPerPath = mapPerLabel[path] || (mapPerLabel[path] = []);\n mapPerPath.push({ error });\n }\n return errorMaps;\n};\n\nconst accessDataByPathSegments = (data: object, pathSegments: string[]) => {\n let current: unknown = data;\n\n for (const segment of pathSegments) {\n if (current == null) {\n return { error: new Error(\"No data\") };\n }\n\n if (typeof current !== \"object\") {\n return { error: new Error(\"Incorrect data type\") };\n }\n\n if (Array.isArray(current)) {\n return { error: new Error(\"Incorrect data type\") };\n }\n\n current = (current as Record<string, unknown>)[segment];\n }\n\n return { data: current };\n};\n\n/**\n * Creates an execution result parser for composed operations.\n * The parser maps GraphQL errors and data to their corresponding slices\n * based on the projection path graph.\n *\n * @param slices - Object mapping labels to projections\n * @returns A parser function that takes a NormalizedExecutionResult and returns parsed slices\n *\n * @example\n * ```typescript\n * const parser = createExecutionResultParser({\n * userCard: userCardProjection,\n * posts: postsProjection,\n * });\n *\n * const results = parser({\n * type: \"graphql\",\n * body: { data, errors },\n * });\n * ```\n */\nexport const createExecutionResultParser = <TSlices extends AnySlicePayloads>(slices: TSlices) => {\n // Build path graph from slices\n const projectionPathGraph = createPathGraphFromSlices(slices);\n const fragments = slices;\n const prepare = (result: NormalizedExecutionResult<object, object>) => {\n if (result.type === \"graphql\") {\n const errorMaps = createErrorMaps(result.body.errors, projectionPathGraph);\n\n return { ...result, errorMaps };\n }\n\n if (result.type === \"non-graphql-error\") {\n return { ...result, error: new SlicedExecutionResultError({ type: \"non-graphql-error\", error: result.error }) };\n }\n\n if (result.type === \"empty\") {\n return { ...result, error: new SlicedExecutionResultEmpty() };\n }\n\n throw new Error(\"Invalid result type\", { cause: result satisfies never });\n };\n\n return (result: NormalizedExecutionResult<object, object>) => {\n const prepared = prepare(result);\n\n const entries = Object.entries(fragments).map(([label, fragment]) => {\n const { projection } = fragment;\n\n if (prepared.type === \"graphql\") {\n const matchedErrors = projection.paths.flatMap(({ full: raw }) => prepared.errorMaps[label]?.[raw] ?? []);\n const uniqueErrors = Array.from(new Set(matchedErrors.map(({ error }) => error)).values());\n\n if (uniqueErrors.length > 0) {\n return [label, projection.projector(new SlicedExecutionResultError({ type: \"graphql-error\", errors: uniqueErrors }))];\n }\n\n // Apply label prefix to first segment for data access (matching $colocate prefix pattern)\n const dataResults = projection.paths.map(({ segments }) => {\n const [first, ...rest] = segments;\n const prefixedSegments = [`${label}_${first}`, ...rest];\n return prepared.body.data\n ? accessDataByPathSegments(prepared.body.data, prefixedSegments)\n : { error: new Error(\"No data\") };\n });\n if (dataResults.some(({ error }) => error)) {\n const errors = dataResults.flatMap(({ error }) => (error ? [error] : []));\n return [label, projection.projector(new SlicedExecutionResultError({ type: \"parse-error\", errors }))];\n }\n\n const dataList = dataResults.map(({ data }) => data);\n return [label, projection.projector(new SlicedExecutionResultSuccess(dataList))];\n }\n\n if (prepared.type === \"non-graphql-error\") {\n return [label, projection.projector(prepared.error)];\n }\n\n if (prepared.type === \"empty\") {\n return [label, projection.projector(prepared.error)];\n }\n\n throw new Error(\"Invalid result type\", { cause: prepared satisfies never });\n });\n\n return Object.fromEntries(entries);\n };\n};\n"],"mappings":";;;;;;AAaA,IAAa,aAAb,MAAoC;CAKlC,YACE,OACA,AAAgBA,WAChB;EADgB;AAEhB,OAAK,QAAQ,MAAM,KAAK,SAAS,qBAAqB,KAAK,CAAC;AAE5D,SAAO,eAAe,MAAM,UAAU,EACpC,MAAM;AACJ,SAAM,IAAI,MAAM,6EAA6E;KAEhG,CAAC;;CAGJ,AAAgB;;AAQlB,SAAS,qBAAqB,MAA8B;CAC1D,MAAM,WAAW,KAAK,MAAM,IAAI;AAChC,KAAI,SAAS,OAAO,SAAS,UAAU,EACrC,OAAM,IAAI,MAAM,yCAAyC;AAG3D,QAAO;EACL,MAAM;EACN,UAAU,SAAS,MAAM,EAAE;EAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACyBH,MAAa,oBACX,WACA,YAC2B;AAC3B,QAAO,IAAI,WAAW,QAAQ,OAAO,QAAQ,OAAO;;AAGtD,MAAa,8BACX,YAC0E;AAC1E,QAAO;EACL,MAAM;EACN,cAAc,aAAa,iBAAiB,UAAU,QAAQ;EAC/D;;;;;ACnFH,SAAgB,UACd,KACA,IAGA;AACA,QAAO,OAAO,YAAa,OAAO,QAAQ,IAAI,CAAwB,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC;;;;;ACgBrH,SAAS,gBAAgB,OAAwF;CAC/G,MAAM,eAAe,MAAM,QACxB,KAAqD,EAAE,OAAO,KAAK,UAAU,CAAC,SAAS,GAAG,gBAAgB;AACzG,MAAI,QACF,EA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AAC,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK;AACvD,YAAO,SAAS,KAAK,OACjB,yBAAyB,SAAS,KAAK,MAAM,iBAAiB,GAC9D,EAAE,uBAAO,IAAI,MAAM,UAAU,EAAE;MACnC;AACF,QAAI,YAAY,MAAM,EAAE,YAAY,MAAM,EAAE;KAC1C,MAAM,SAAS,YAAY,SAAS,EAAE,YAAa,QAAQ,CAAC,MAAM,GAAG,EAAE,CAAE;AACzE,YAAO,CAAC,OAAO,WAAW,UAAU,IAAI,2BAA2B;MAAE,MAAM;MAAe;MAAQ,CAAC,CAAC,CAAC;;IAGvG,MAAM,WAAW,YAAY,KAAK,EAAE,WAAW,KAAK;AACpD,WAAO,CAAC,OAAO,WAAW,UAAU,IAAI,6BAA6B,SAAS,CAAC,CAAC;;AAGlF,OAAI,SAAS,SAAS,oBACpB,QAAO,CAAC,OAAO,WAAW,UAAU,SAAS,MAAM,CAAC;AAGtD,OAAI,SAAS,SAAS,QACpB,QAAO,CAAC,OAAO,WAAW,UAAU,SAAS,MAAM,CAAC;AAGtD,SAAM,IAAI,MAAM,uBAAuB,EAAE,OAAO,UAA0B,CAAC;IAC3E;AAEF,SAAO,OAAO,YAAY,QAAQ"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["projector: (result: AnySlicedExecutionResult) => TProjected","paths","type: \"success\" | \"error\" | \"empty\"","data: TData","extensions?: unknown","error: NormalizedError","errorMaps: { [label: string]: { [path: string]: { error: GraphQLFormattedError }[] } }","current: unknown"],"sources":["../src/projection.ts","../src/create-projection.ts","../src/utils/map-values.ts","../src/projection-path-graph.ts","../src/sliced-execution-result.ts","../src/parse-execution-result.ts"],"sourcesContent":["import type { AnySlicedExecutionResult } from \"./sliced-execution-result\";\nimport type { Tuple } from \"./utils/type-utils\";\n\n/** Shape of a single selection slice projection. */\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any Projection regardless of projected type\nexport type AnyProjection = Projection<any>;\n\ndeclare const __PROJECTION_BRAND__: unique symbol;\n/**\n * Nominal type representing any slice selection regardless of schema specifics.\n * Encodes how individual slices map a concrete field path to a projection\n * function. Multiple selections allow slices to expose several derived values.\n */\nexport class Projection<TProjected> {\n declare readonly [__PROJECTION_BRAND__]: void;\n\n declare readonly $infer: { readonly output: TProjected };\n\n constructor(\n paths: Tuple<string>,\n public readonly projector: (result: AnySlicedExecutionResult) => TProjected,\n ) {\n this.paths = paths.map((path) => createProjectionPath(path));\n\n Object.defineProperty(this, \"$infer\", {\n get() {\n throw new Error(\"This property is only for type meta. Do not access this property directly.\");\n },\n });\n }\n\n public readonly paths: ProjectionPath[];\n}\n\nexport type ProjectionPath = {\n full: string;\n segments: Tuple<string>;\n};\n\nfunction createProjectionPath(path: string): ProjectionPath {\n const segments = path.split(\".\");\n if (path === \"$\" || segments.length <= 1) {\n throw new Error(\"Field path must not be only $ or empty\");\n }\n\n return {\n full: path,\n segments: segments.slice(1) as Tuple<string>,\n };\n}\n\nexport type InferExecutionResultProjection<TProjection extends AnyProjection> = ReturnType<TProjection[\"projector\"]>;\n","import type { Fragment, GqlElementAttachment } from \"@soda-gql/core\";\nimport { Projection } from \"./projection\";\nimport type { SlicedExecutionResult } from \"./sliced-execution-result\";\nimport type { Tuple } from \"./utils/type-utils\";\n\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any Fragment regardless of type parameters\ntype AnyFragment = Fragment<string, any, any, any>;\n\n/**\n * Options for creating a projection from a Fragment.\n */\nexport type CreateProjectionOptions<TOutput extends object, TProjected> = {\n /**\n * Field paths to extract from the execution result.\n * Each path starts with \"$.\" and follows the field selection structure.\n *\n * @example\n * ```typescript\n * paths: [\"$.user.id\", \"$.user.name\"]\n * ```\n */\n paths: Tuple<string>;\n\n /**\n * Handler function to transform the sliced execution result.\n * Receives a SlicedExecutionResult with the Fragment's output type.\n * Handles all cases: success, error, and empty.\n *\n * @example\n * ```typescript\n * handle: (result) => {\n * if (result.isError()) return { error: result.error, data: null };\n * if (result.isEmpty()) return { error: null, data: null };\n * const data = result.unwrap();\n * return { error: null, data: { userId: data.user.id } };\n * }\n * ```\n */\n handle: (result: SlicedExecutionResult<TOutput>) => TProjected;\n};\n\n/**\n * Creates a type-safe projection from a Fragment.\n *\n * The projection extracts and transforms data from GraphQL execution results,\n * with full type inference from the Fragment's output type.\n *\n * Note: The Fragment parameter is used only for type inference.\n * The actual paths must be specified explicitly.\n *\n * @param _fragment - The Fragment to infer types from (used for type inference only)\n * @param options - Projection options including paths and handle function\n * @returns A Projection that can be used with createExecutionResultParser\n *\n * @example\n * ```typescript\n * const userFragment = gql(({ fragment }) =>\n * fragment.Query({\n * variables: { ... },\n * fields: ({ f, $ }) => ({\n * ...f.user({ id: $.userId })(({ f }) => ({ ...f.id(), ...f.name() })),\n * }),\n * })\n * );\n *\n * const userProjection = createProjection(userFragment, {\n * paths: [\"$.user\"],\n * handle: (result) => {\n * if (result.isError()) return { error: result.error, user: null };\n * if (result.isEmpty()) return { error: null, user: null };\n * const data = result.unwrap();\n * return { error: null, user: data.user };\n * },\n * });\n * ```\n */\nexport const createProjection = <TFragment extends AnyFragment, TProjected>(\n _fragment: TFragment,\n options: CreateProjectionOptions<TFragment[\"$infer\"][\"output\"], TProjected>,\n): Projection<TProjected> => {\n return new Projection(options.paths, options.handle);\n};\n\nexport const createProjectionAttachment = <TFragment extends AnyFragment, TProjected>(\n options: CreateProjectionOptions<NoInfer<TFragment>[\"$infer\"][\"output\"], TProjected>,\n): GqlElementAttachment<TFragment, \"projection\", Projection<TProjected>> => {\n return {\n name: \"projection\",\n createValue: (fragment) => createProjection(fragment, options),\n };\n};\n","type ArgEntries<T extends object> = { [K in keyof T]-?: [value: T[K], key: K] }[keyof T];\ntype Entries<T extends object> = { [K in keyof T]: [key: K, value: T[K]] }[keyof T];\n\nexport function mapValues<TObject extends object, TMappedValue>(\n obj: TObject,\n fn: (...args: ArgEntries<TObject>) => TMappedValue,\n): {\n [K in keyof TObject]: TMappedValue;\n} {\n return Object.fromEntries((Object.entries(obj) as Entries<TObject>[]).map(([key, value]) => [key, fn(value, key)])) as {\n [K in keyof TObject]: TMappedValue;\n };\n}\n","import type { AnyProjection } from \"./projection\";\nimport { mapValues } from \"./utils/map-values\";\n\n/**\n * Node in the projection path graph tree.\n * Used for mapping GraphQL errors and data to their corresponding slices.\n */\nexport type ProjectionPathGraphNode = {\n readonly matches: { label: string; path: string; exact: boolean }[];\n readonly children: { readonly [segment: string]: ProjectionPathGraphNode };\n};\n\n/**\n * Payload from a slice that contains projection.\n */\nexport type AnySlicePayload = {\n readonly projection: AnyProjection;\n};\n\nexport type AnySlicePayloads = Record<string, AnySlicePayload>;\n\ntype ExecutionResultProjectionPathGraphIntermediate = {\n [segment: string]: { label: string; raw: string; segments: string[] }[];\n};\n\nfunction createPathGraph(paths: ExecutionResultProjectionPathGraphIntermediate[string]): ProjectionPathGraphNode {\n const intermediate = paths.reduce(\n (acc: ExecutionResultProjectionPathGraphIntermediate, { label, raw, segments: [segment, ...segments] }) => {\n if (segment) {\n (acc[segment] || (acc[segment] = [])).push({ label, raw, segments });\n }\n return acc;\n },\n {},\n );\n\n return {\n matches: paths.map(({ label, raw, segments }) => ({ label, path: raw, exact: segments.length === 0 })),\n children: mapValues(intermediate, (paths) => createPathGraph(paths)),\n } satisfies ProjectionPathGraphNode;\n}\n\n/**\n * Creates a projection path graph from slice entries with field prefixing.\n * Each slice's paths are prefixed with the slice label for disambiguation.\n */\nexport function createPathGraphFromSliceEntries(fragments: AnySlicePayloads) {\n const paths = Object.entries(fragments).flatMap(([label, slice]) =>\n Array.from(\n new Map(\n slice.projection.paths.map(({ full: raw, segments }) => {\n const [first, ...rest] = segments;\n return [raw, { label, raw, segments: [`${label}_${first}`, ...rest] }];\n }),\n ).values(),\n ),\n );\n\n return createPathGraph(paths);\n}\n","/** Result-like wrapper types returned from slice projections. */\n\nimport type { NormalizedError } from \"./types\";\n\n// biome-ignore lint/suspicious/noExplicitAny: Type alias for any SlicedExecutionResult regardless of data type\nexport type AnySlicedExecutionResult = SlicedExecutionResult<any>;\n\n/**\n * Internal discriminated union describing the Result-like wrapper exposed to\n * slice selection callbacks.\n */\nexport type AnySlicedExecutionResultRecord = {\n [path: string]: AnySlicedExecutionResult;\n};\n\nexport type SafeUnwrapResult<TTransformed, TError> =\n | {\n data?: never;\n error?: never;\n }\n | {\n data: TTransformed;\n error?: never;\n }\n | {\n data?: never;\n error: TError;\n };\n\n/** Utility signature returned by the safe unwrap helper. */\ntype SlicedExecutionResultCommon<TData, TError> = {\n safeUnwrap<TTransformed>(transform: (data: TData) => TTransformed): SafeUnwrapResult<TTransformed, TError>;\n};\n\n/** Public union used by selection callbacks to inspect data, empty, or error states. */\nexport type SlicedExecutionResult<TData> =\n | SlicedExecutionResultEmpty<TData>\n | SlicedExecutionResultSuccess<TData>\n | SlicedExecutionResultError<TData>;\n\n/** Runtime guard interface shared by all slice result variants. */\nclass SlicedExecutionResultGuards<TData> {\n isSuccess(): this is SlicedExecutionResultSuccess<TData> {\n return this.type === \"success\";\n }\n isError(): this is SlicedExecutionResultError<TData> {\n return this.type === \"error\";\n }\n isEmpty(): this is SlicedExecutionResultEmpty<TData> {\n return this.type === \"empty\";\n }\n\n constructor(private readonly type: \"success\" | \"error\" | \"empty\") {}\n}\n\n/** Variant representing an empty payload (no data, no error). */\nexport class SlicedExecutionResultEmpty<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor() {\n super(\"empty\");\n }\n\n unwrap(): null {\n return null;\n }\n\n safeUnwrap() {\n return {\n data: undefined,\n error: undefined,\n };\n }\n}\n\n/** Variant representing a successful payload. */\nexport class SlicedExecutionResultSuccess<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor(\n public readonly data: TData,\n public readonly extensions?: unknown,\n ) {\n super(\"success\");\n }\n\n unwrap(): TData {\n return this.data;\n }\n\n safeUnwrap<TTransformed>(transform: (data: TData) => TTransformed) {\n return {\n data: transform(this.data),\n error: undefined,\n };\n }\n}\n\n/** Variant representing an error payload. */\nexport class SlicedExecutionResultError<TData>\n extends SlicedExecutionResultGuards<TData>\n implements SlicedExecutionResultCommon<TData, NormalizedError>\n{\n constructor(\n public readonly error: NormalizedError,\n public readonly extensions?: unknown,\n ) {\n super(\"error\");\n }\n\n unwrap(): never {\n throw this.error;\n }\n\n safeUnwrap() {\n return {\n data: undefined,\n error: this.error,\n };\n }\n}\n","import type { GraphQLFormattedError } from \"graphql\";\nimport { type AnySlicePayloads, createPathGraphFromSliceEntries, type ProjectionPathGraphNode } from \"./projection-path-graph\";\nimport { SlicedExecutionResultEmpty, SlicedExecutionResultError, SlicedExecutionResultSuccess } from \"./sliced-execution-result\";\nimport type { NormalizedExecutionResult } from \"./types\";\n\n// Internal function to build path graph from slices\nconst createPathGraphFromSlices = createPathGraphFromSliceEntries;\n\nfunction* generateErrorMapEntries(errors: readonly GraphQLFormattedError[], projectionPathGraph: ProjectionPathGraphNode) {\n for (const error of errors) {\n const errorPath = error.path ?? [];\n let stack = projectionPathGraph;\n\n for (\n let i = 0;\n // i <= errorPath.length to handle the case where the error path is empty\n i <= errorPath.length;\n i++\n ) {\n const segment = errorPath[i];\n\n if (\n // the end of the path\n segment == null ||\n // FieldPath does not support index access. We treat it as the end of the path.\n typeof segment === \"number\"\n ) {\n yield* stack.matches.map(({ label, path }) => ({ label, path, error }));\n break;\n }\n\n yield* stack.matches.filter(({ exact }) => exact).map(({ label, path }) => ({ label, path, error }));\n\n const next = stack.children[segment];\n if (!next) {\n break;\n }\n\n stack = next;\n }\n }\n}\n\nconst createErrorMaps = (errors: readonly GraphQLFormattedError[] | undefined, projectionPathGraph: ProjectionPathGraphNode) => {\n const errorMaps: { [label: string]: { [path: string]: { error: GraphQLFormattedError }[] } } = {};\n for (const { label, path, error } of generateErrorMapEntries(errors ?? [], projectionPathGraph)) {\n const mapPerLabel = errorMaps[label] || (errorMaps[label] = {});\n const mapPerPath = mapPerLabel[path] || (mapPerLabel[path] = []);\n mapPerPath.push({ error });\n }\n return errorMaps;\n};\n\nconst accessDataByPathSegments = (data: object, pathSegments: string[]) => {\n let current: unknown = data;\n\n for (const segment of pathSegments) {\n if (current == null) {\n return { error: new Error(\"No data\") };\n }\n\n if (typeof current !== \"object\") {\n return { error: new Error(\"Incorrect data type\") };\n }\n\n if (Array.isArray(current)) {\n return { error: new Error(\"Incorrect data type\") };\n }\n\n current = (current as Record<string, unknown>)[segment];\n }\n\n return { data: current };\n};\n\n/**\n * Creates an execution result parser for composed operations.\n * The parser maps GraphQL errors and data to their corresponding slices\n * based on the projection path graph.\n *\n * @param slices - Object mapping labels to projections\n * @returns A parser function that takes a NormalizedExecutionResult and returns parsed slices\n *\n * @example\n * ```typescript\n * const parser = createExecutionResultParser({\n * userCard: userCardProjection,\n * posts: postsProjection,\n * });\n *\n * const results = parser({\n * type: \"graphql\",\n * body: { data, errors },\n * });\n * ```\n */\nexport const createExecutionResultParser = <TSlices extends AnySlicePayloads>(slices: TSlices) => {\n // Build path graph from slices\n const projectionPathGraph = createPathGraphFromSlices(slices);\n const fragments = slices;\n const prepare = (result: NormalizedExecutionResult<object, object>) => {\n if (result.type === \"graphql\") {\n const errorMaps = createErrorMaps(result.body.errors, projectionPathGraph);\n\n return { ...result, errorMaps };\n }\n\n if (result.type === \"non-graphql-error\") {\n return { ...result, error: new SlicedExecutionResultError({ type: \"non-graphql-error\", error: result.error }) };\n }\n\n if (result.type === \"empty\") {\n return { ...result, error: new SlicedExecutionResultEmpty() };\n }\n\n throw new Error(\"Invalid result type\", { cause: result satisfies never });\n };\n\n return (result: NormalizedExecutionResult<object, object>) => {\n const prepared = prepare(result);\n\n const entries = Object.entries(fragments).map(([label, fragment]) => {\n const { projection } = fragment;\n\n if (prepared.type === \"graphql\") {\n const matchedErrors = projection.paths.flatMap(({ full: raw }) => prepared.errorMaps[label]?.[raw] ?? []);\n const uniqueErrors = Array.from(new Set(matchedErrors.map(({ error }) => error)).values());\n\n if (uniqueErrors.length > 0) {\n return [label, projection.projector(new SlicedExecutionResultError({ type: \"graphql-error\", errors: uniqueErrors }))];\n }\n\n // Apply label prefix to first segment for data access (matching $colocate prefix pattern)\n const dataResults = projection.paths.map(({ segments }) => {\n const [first, ...rest] = segments;\n const prefixedSegments = [`${label}_${first}`, ...rest];\n return prepared.body.data\n ? accessDataByPathSegments(prepared.body.data, prefixedSegments)\n : { error: new Error(\"No data\") };\n });\n if (dataResults.some(({ error }) => error)) {\n const errors = dataResults.flatMap(({ error }) => (error ? [error] : []));\n return [label, projection.projector(new SlicedExecutionResultError({ type: \"parse-error\", errors }))];\n }\n\n const dataList = dataResults.map(({ data }) => data);\n return [label, projection.projector(new SlicedExecutionResultSuccess(dataList))];\n }\n\n if (prepared.type === \"non-graphql-error\") {\n return [label, projection.projector(prepared.error)];\n }\n\n if (prepared.type === \"empty\") {\n return [label, projection.projector(prepared.error)];\n }\n\n throw new Error(\"Invalid result type\", { cause: prepared satisfies never });\n });\n\n return Object.fromEntries(entries);\n };\n};\n"],"mappings":";;;;;;AAaA,IAAa,aAAb,MAAoC;CAKlC,YACE,OACA,AAAgBA,WAChB;EADgB;AAEhB,OAAK,QAAQ,MAAM,KAAK,SAAS,qBAAqB,KAAK,CAAC;AAE5D,SAAO,eAAe,MAAM,UAAU,EACpC,MAAM;AACJ,SAAM,IAAI,MAAM,6EAA6E;KAEhG,CAAC;;CAGJ,AAAgB;;AAQlB,SAAS,qBAAqB,MAA8B;CAC1D,MAAM,WAAW,KAAK,MAAM,IAAI;AAChC,KAAI,SAAS,OAAO,SAAS,UAAU,EACrC,OAAM,IAAI,MAAM,yCAAyC;AAG3D,QAAO;EACL,MAAM;EACN,UAAU,SAAS,MAAM,EAAE;EAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC4BH,MAAa,oBACX,WACA,YAC2B;AAC3B,QAAO,IAAI,WAAW,QAAQ,OAAO,QAAQ,OAAO;;AAGtD,MAAa,8BACX,YAC0E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version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Colocation utilities for soda-gql fragments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"./package.json": "./package.json"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@soda-gql/core": "0.
|
|
50
|
+
"@soda-gql/core": "0.3.0",
|
|
51
51
|
"graphql": "^16.11.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {},
|