@distilled.cloud/core 1.0.0-rc.3 → 1.0.0-rc.5

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.
Files changed (42) hide show
  1. package/lib/api.d.ts.map +1 -1
  2. package/lib/api.js +16 -4
  3. package/lib/api.js.map +1 -1
  4. package/lib/category.d.ts +4 -4
  5. package/lib/category.js +4 -4
  6. package/lib/codegen/emit.d.ts +2 -2
  7. package/lib/codegen/emit.js +4 -4
  8. package/lib/codegen/emit.js.map +1 -1
  9. package/lib/codegen/generator.d.ts.map +1 -1
  10. package/lib/codegen/generator.js +16 -3
  11. package/lib/codegen/generator.js.map +1 -1
  12. package/lib/codegen/graphql.d.ts +201 -0
  13. package/lib/codegen/graphql.d.ts.map +1 -0
  14. package/lib/codegen/graphql.js +789 -0
  15. package/lib/codegen/graphql.js.map +1 -0
  16. package/lib/codegen/openapi.d.ts +43 -6
  17. package/lib/codegen/openapi.d.ts.map +1 -1
  18. package/lib/codegen/openapi.js +81 -12
  19. package/lib/codegen/openapi.js.map +1 -1
  20. package/lib/errors.d.ts.map +1 -1
  21. package/lib/errors.js +17 -13
  22. package/lib/errors.js.map +1 -1
  23. package/lib/pagination.d.ts +43 -3
  24. package/lib/pagination.d.ts.map +1 -1
  25. package/lib/pagination.js +84 -5
  26. package/lib/pagination.js.map +1 -1
  27. package/lib/protocol-http.d.ts.map +1 -1
  28. package/lib/protocol-http.js +12 -3
  29. package/lib/protocol-http.js.map +1 -1
  30. package/lib/schema.js +1 -1
  31. package/lib/schema.js.map +1 -1
  32. package/package.json +8 -8
  33. package/src/api.ts +18 -4
  34. package/src/category.ts +4 -4
  35. package/src/codegen/emit.ts +4 -4
  36. package/src/codegen/generator.ts +15 -3
  37. package/src/codegen/graphql.ts +1195 -0
  38. package/src/codegen/openapi.ts +126 -11
  39. package/src/errors.ts +20 -25
  40. package/src/pagination.ts +125 -7
  41. package/src/protocol-http.ts +11 -3
  42. package/src/schema.ts +1 -1
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Shared GraphQL → Smithy 2.0 converter (dev-time only).
3
+ *
4
+ * A GraphQL endpoint has no per-operation URLs, no path/query/header bindings
5
+ * and no response shapes to speak of: there is one POST, one request envelope
6
+ * (`{ query, operationName, variables }`) and one response envelope
7
+ * (`{ data, errors }`). What varies per operation is the *document* — which
8
+ * root field is called, which variables it takes, and which selection set
9
+ * comes back. This module turns an introspection schema into a Smithy model
10
+ * carrying exactly that:
11
+ *
12
+ * • operation → `smithy.api#http` (POST <endpoint>) + the op shape
13
+ * • input struct → `<traits.operation>` { query, operationName, type } —
14
+ * the baked GraphQL document for the op
15
+ * • output struct → `<traits.responsePath>` ("account.byId") — the path
16
+ * under `data` the protocol unwraps
17
+ * • nullability → `<traits.nullable>` on members,
18
+ * `<traits.nullableItems>` on list shapes (GraphQL
19
+ * nullability is not Smithy optionality: a selected
20
+ * field is always *delivered*, it just may be `null`)
21
+ * • bare results → `<traits.payload>` on the sole `result` member when
22
+ * the leaf returns a list/scalar (the response IS that
23
+ * value)
24
+ * • connections → `smithy.api#paginated` when a root field looks like a
25
+ * Relay connection (see {@link RelayOptions})
26
+ *
27
+ * Trait *ids* are caller-supplied so each SDK keeps its own vocabulary
28
+ * namespace; the generator side maps them back to that SDK's trait module.
29
+ *
30
+ * ─── Operation discovery ────────────────────────────────────────────────────
31
+ * Most schemas put operations directly on Query/Mutation, but some namespace
32
+ * them behind objects whose fields are the real operations (`account.byId`).
33
+ * `maxNamespaceDepth` bounds how far that expansion goes; set it to 1 for a
34
+ * flat schema. Selection sets are expanded to `maxDepth` levels, cycles
35
+ * short-circuit, and fields that themselves take arguments are not selected
36
+ * (we have no value to pass them).
37
+ *
38
+ * Originally distilled v0's `core/scripts/generate-graphql.ts`, generalized
39
+ * out of packages/expo-eas.
40
+ */
41
+ export type TypeKind = "SCALAR" | "OBJECT" | "INTERFACE" | "UNION" | "ENUM" | "INPUT_OBJECT" | "LIST" | "NON_NULL";
42
+ export interface TypeRef {
43
+ kind: TypeKind;
44
+ name?: string | null;
45
+ ofType?: TypeRef | null;
46
+ }
47
+ export interface InputValue {
48
+ name: string;
49
+ description?: string | null;
50
+ type: TypeRef;
51
+ defaultValue?: string | null;
52
+ }
53
+ export interface Field {
54
+ name: string;
55
+ description?: string | null;
56
+ args: InputValue[];
57
+ type: TypeRef;
58
+ isDeprecated?: boolean;
59
+ }
60
+ export interface IntrospectionType {
61
+ kind: TypeKind;
62
+ name: string;
63
+ description?: string | null;
64
+ fields?: Field[] | null;
65
+ inputFields?: InputValue[] | null;
66
+ enumValues?: Array<{
67
+ name: string;
68
+ isDeprecated?: boolean;
69
+ }> | null;
70
+ possibleTypes?: TypeRef[] | null;
71
+ }
72
+ export interface IntrospectionSchema {
73
+ queryType: {
74
+ name: string;
75
+ };
76
+ mutationType?: {
77
+ name: string;
78
+ } | null;
79
+ subscriptionType?: {
80
+ name: string;
81
+ } | null;
82
+ types: IntrospectionType[];
83
+ }
84
+ /**
85
+ * Pull the `__schema` out of an introspection response, accepting either the
86
+ * bare schema, `{ __schema }`, or a full `{ data: { __schema } }` envelope —
87
+ * all three are shipped by real mirrors.
88
+ */
89
+ export declare const readIntrospection: (json: unknown) => IntrospectionSchema;
90
+ export declare const PRELUDE: {
91
+ readonly String: "smithy.api#String";
92
+ readonly Boolean: "smithy.api#Boolean";
93
+ readonly Integer: "smithy.api#Integer";
94
+ readonly Long: "smithy.api#Long";
95
+ readonly Double: "smithy.api#Double";
96
+ readonly Timestamp: "smithy.api#Timestamp";
97
+ readonly Document: "smithy.api#Document";
98
+ };
99
+ /**
100
+ * The Smithy trait ids this converter stamps. Each SDK owns its own trait
101
+ * namespace (`com.expo.graphql#operation`, `com.railway.graphql#operation`,
102
+ * …) and maps them back to its trait module in its `generate.ts`.
103
+ */
104
+ export interface GraphQLTraitIds {
105
+ /** On the input struct: the baked `{ query, operationName, type }`. */
106
+ readonly operation: string;
107
+ /** On the output struct: the dotted path under `data` to unwrap. */
108
+ readonly responsePath: string;
109
+ /** On members: the GraphQL type was nullable. */
110
+ readonly nullable: string;
111
+ /** On list shapes: the GraphQL *element* type was nullable. */
112
+ readonly nullableItems: string;
113
+ /** On the sole `result` member: the response IS this value. */
114
+ readonly payload: string;
115
+ }
116
+ /**
117
+ * Relay connection detection. A root field paginates when its return type
118
+ * looks like a connection (an `edges` list of objects with a `node`, plus a
119
+ * `pageInfo`) AND it accepts the forward-pagination arguments.
120
+ *
121
+ * The emitted `smithy.api#paginated` trait drives `.pages()` / `.items()` in
122
+ * the generated SDK; `items` deliberately points *through* the edges
123
+ * (`edges.node`) so `.items()` streams nodes rather than edge wrappers.
124
+ */
125
+ export interface RelayOptions {
126
+ /** Cursor argument fed the previous page's `endCursor`. Default `"after"`. */
127
+ readonly after?: string;
128
+ /** Page-size argument. Default `"first"`. */
129
+ readonly first?: string;
130
+ /** Connection field holding the edge list. Default `"edges"`. */
131
+ readonly edges?: string;
132
+ /** Edge field holding the item. Default `"node"`. */
133
+ readonly node?: string;
134
+ /** Connection field holding the cursor/termination block. Default `"pageInfo"`. */
135
+ readonly pageInfo?: string;
136
+ /** `pageInfo` field holding the next cursor. Default `"endCursor"`. */
137
+ readonly endCursor?: string;
138
+ /** `pageInfo` field saying whether more pages exist. Default `"hasNextPage"`. */
139
+ readonly hasNextPage?: string;
140
+ /** Pagination mode written into the trait. Default `"relay"`. */
141
+ readonly mode?: string;
142
+ }
143
+ export interface GraphQLConvertOptions {
144
+ /** The introspection schema (see {@link readIntrospection}). */
145
+ readonly schema: IntrospectionSchema;
146
+ /** Smithy namespace for every generated shape, e.g. `"com.railway.api"`. */
147
+ readonly namespace: string;
148
+ /** Local name of the service shape, e.g. `"Railway"`. */
149
+ readonly serviceName: string;
150
+ /** `smithy.api#title` on the service shape. */
151
+ readonly serviceTitle: string;
152
+ /** `smithy.api#documentation` on the service shape. */
153
+ readonly serviceDocumentation?: string;
154
+ /** Service `version` field. Default `"1.0"`. */
155
+ readonly serviceVersion?: string;
156
+ /** HTTP path every operation POSTs to, e.g. `"/graphql/v2"`. */
157
+ readonly endpoint: string;
158
+ /** Trait ids to stamp (see {@link GraphQLTraitIds}). */
159
+ readonly traits: GraphQLTraitIds;
160
+ /** How many levels of selection set to expand. Default `3`. */
161
+ readonly maxDepth?: number;
162
+ /**
163
+ * How many namespace objects an operation may sit behind. `1` means the
164
+ * schema is flat (every operation is a direct Query/Mutation field).
165
+ * Default `3`.
166
+ */
167
+ readonly maxNamespaceDepth?: number;
168
+ /** Skip `@deprecated` root fields and namespace subfields. Default `true`. */
169
+ readonly skipDeprecated?: boolean;
170
+ /** Drop root fields by name (placeholders like `_doNotUse`). */
171
+ readonly skipRootField?: (name: string) => boolean;
172
+ /**
173
+ * Custom (non-builtin) scalar name → Smithy prelude target. Unmapped
174
+ * customs fall back to `smithy.api#Document` so nothing hard-fails, but
175
+ * mapping them keeps the generated types honest.
176
+ */
177
+ readonly customScalars?: Record<string, string>;
178
+ /** Relay connection pagination. Omit (or `false`) to emit no `paginated`. */
179
+ readonly relay?: RelayOptions | false;
180
+ }
181
+ export interface GraphQLConvertResult {
182
+ /** The Smithy 2.0 model, ready to `JSON.stringify`. */
183
+ readonly model: {
184
+ smithy: "2.0";
185
+ metadata: Record<string, unknown>;
186
+ shapes: Record<string, any>;
187
+ };
188
+ readonly converted: number;
189
+ readonly failed: number;
190
+ readonly paginated: number;
191
+ readonly shapeCount: number;
192
+ }
193
+ /**
194
+ * Turn a GraphQL introspection schema into a Smithy 2.0 model.
195
+ *
196
+ * Subscriptions are ignored: they are a streaming transport, not a
197
+ * `POST /graphql` request/response pair, and nothing in the generated SDK
198
+ * could speak them.
199
+ */
200
+ export declare const convertGraphQLToSmithy: (options: GraphQLConvertOptions) => GraphQLConvertResult;
201
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/codegen/graphql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;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