@contello/client 3.4.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- //#region src/cli.ts
2
+ // src/cli.ts
3
3
  const command = process.argv[2];
4
4
  switch (command) {
5
5
  case "generate": {
6
- const { run } = await import("./generate-CwfbsOys.js");
6
+ const { run } = await import("./generate-IysMI3VF.js");
7
7
  try {
8
8
  await run();
9
9
  } catch (error) {
@@ -19,7 +19,6 @@ switch (command) {
19
19
  console.error(" generate generate TypeScript types from GraphQL schema");
20
20
  process.exit(1);
21
21
  }
22
- //#endregion
23
22
  export {};
24
23
 
25
24
  //# sourceMappingURL=cli.js.map
@@ -0,0 +1,279 @@
1
+ import "undici";
2
+ import { MaybePromise } from "@entwico/dash";
3
+ import { ReadableStream as ReadableStream$1 } from "node:stream/web";
4
+ type HttpAgentOptions = {
5
+ pipelining?: number | undefined;
6
+ allowH2?: boolean | undefined;
7
+ maxConcurrentStreams?: number | undefined;
8
+ keepAliveTimeout?: number | undefined;
9
+ };
10
+ type DownloadResult = {
11
+ mimeType: string;
12
+ size: number;
13
+ bytes(): Promise<Uint8Array>;
14
+ stream(): ReadableStream<Uint8Array>;
15
+ };
16
+ type ProxyResult = {
17
+ status: number;
18
+ headers: Headers;
19
+ stream(): ReadableStream<Uint8Array>;
20
+ };
21
+ type SitemapProxyOptions = {
22
+ /** chunk source as received from the query string; core decides whether the source/page pair is valid */
23
+ source?: string | undefined;
24
+ /** chunk page as received from the query string */
25
+ page?: string | undefined;
26
+ /** the incoming request's Accept-Encoding, so stored gzip bytes pass through untouched */
27
+ acceptEncoding?: string | undefined;
28
+ /** the incoming request's If-None-Match, so core can answer 304 */
29
+ ifNoneMatch?: string | undefined;
30
+ };
31
+ type ResourceAction = 'READ' | 'CREATE' | 'UPDATE' | 'DELETE';
32
+ type ResourcePermissions = {
33
+ resourceType: 'ENTITY' | 'ASSET' | 'ROUTE' | 'I18N_MESSAGE_COLLECTION' | 'MODELLING' | 'EXTENSION' | (string & {});
34
+ scope: string | null;
35
+ actions: ResourceAction[];
36
+ };
37
+ type IntrospectedUser = {
38
+ id: string;
39
+ username: string;
40
+ firstName: string;
41
+ lastName: string;
42
+ email: string;
43
+ };
44
+ type TokenIntrospection = {
45
+ active: false;
46
+ } | {
47
+ active: true;
48
+ audience: string;
49
+ expiresAt: Date;
50
+ user: IntrospectedUser;
51
+ permissions: ResourcePermissions[];
52
+ };
53
+ type TokenIntrospectorOptions = {
54
+ audiences: string[];
55
+ maxAgeMs?: number | undefined;
56
+ maxEntries?: number | undefined;
57
+ };
58
+ type TokenIntrospector = {
59
+ introspect: (token: string) => MaybePromise<TokenIntrospection>;
60
+ };
61
+ declare function createTokenIntrospector(introspect: (token: string) => Promise<TokenIntrospection>, options: TokenIntrospectorOptions): TokenIntrospector;
62
+ type OperationKind = 'query' | 'mutation' | 'subscription';
63
+ type OperationDef<TResult = unknown, TVariables = Record<string, unknown>, TKind extends OperationKind = OperationKind> = {
64
+ document: string;
65
+ kind: TKind;
66
+ /** phantom type — exists only at the type level */
67
+ __result?: TResult | undefined;
68
+ /** phantom type — exists only at the type level */
69
+ __variables?: TVariables | undefined;
70
+ };
71
+ type OperationMap = Record<string, OperationDef>;
72
+ type InferResult<T extends OperationDef> = NonNullable<T['__result']>;
73
+ type InferVariables<T extends OperationDef> = NonNullable<T['__variables']>;
74
+ type RpcMethod<T extends OperationDef> = T['kind'] extends 'subscription' ? InferVariables<T> extends Record<string, never> ? () => AsyncIterable<InferResult<T>> : (variables: InferVariables<T>) => AsyncIterable<InferResult<T>> : InferVariables<T> extends Record<string, never> ? () => Promise<InferResult<T>> : (variables: InferVariables<T>) => Promise<InferResult<T>>;
75
+ type Rpc<T extends OperationMap> = { [K in keyof T]: RpcMethod<T[K]>; };
76
+ /**
77
+ * Discriminator for how a SourceDef binds to a Subscription field:
78
+ * - `entity` — a Contello entity model collection (`categoriesBatch` etc.), accepts optional `{ ids }` filter
79
+ * - `singleton` — a single Contello entity (`config` etc.), no args
80
+ * - `route` — built-in: `contelloRoutesBatch`, optional `{ ids, paths }` filter
81
+ * - `asset` — built-in: `contelloAssetsBatch`, optional `{ ids }` filter
82
+ * - `i18nMessage` — built-in: `contelloI18nMessagesBatch`, requires `{ collection }` and optional `{ ids }` filter
83
+ */
84
+ type SourceCardinality = 'entity' | 'singleton' | 'route' | 'asset' | 'i18nMessage';
85
+ /**
86
+ * One argument of a write mutation and what fills it. Entity mutations take a single input
87
+ * object; the built-ins vary — `createContelloRoute` takes `route:`, `deleteContelloRoute`
88
+ * takes a bare `id:`.
89
+ */
90
+ type SourceMutationArgument = {
91
+ /** the GQL argument name — `request`, `route`, `id` */
92
+ name: string;
93
+ /** the rendered GQL type, including nullability — `CreateCategoryRequestInput!`, `String` */
94
+ type: string;
95
+ /** `input` takes the caller's input, `id` the id passed to a delete */
96
+ from: 'input' | 'id';
97
+ /**
98
+ * the single field of a one-field envelope argument (`CreateCategoryRequestInput { entity }`).
99
+ * When set, the accessor takes the inner input and the runtime nests it under this key.
100
+ */
101
+ envelope?: string | undefined;
102
+ };
103
+ /**
104
+ * What a write mutation answers with:
105
+ * - `entity` — the entity itself, selected through the source's fragment
106
+ * - `idObject` — an object carrying `id` (`ContelloEntityDeleteResponse`)
107
+ * - `idScalar` — a bare id (`deleteContelloRoute: String!`)
108
+ */
109
+ type SourceMutationResult = 'entity' | 'idObject' | 'idScalar';
110
+ /**
111
+ * How one write operation of a source binds to a Mutation field. Emitted by the generator
112
+ * from introspection — the runtime never derives field or argument names by string munging.
113
+ */
114
+ type SourceMutationBinding = {
115
+ /** the mutation field — `createCategory` */
116
+ field: string;
117
+ arguments: SourceMutationArgument[];
118
+ result: SourceMutationResult;
119
+ };
120
+ /** Mutation bindings of a source. Absent operations are simply missing (singletons have no `create`). */
121
+ type SourceMutations = {
122
+ create?: SourceMutationBinding | undefined;
123
+ update?: SourceMutationBinding | undefined;
124
+ delete?: SourceMutationBinding | undefined;
125
+ };
126
+ /**
127
+ * Phantom shape carrying the input types of a source's write operations. A key is present
128
+ * only when the schema exposes the matching mutation, so `client.sources.x.create` exists
129
+ * exactly when `createX` does.
130
+ */
131
+ type SourceWrites = {
132
+ create?: unknown;
133
+ update?: unknown;
134
+ delete?: unknown;
135
+ };
136
+ type SourceDef<TModel extends string = string, TCardinality extends SourceCardinality = SourceCardinality, TResult = unknown, TWrites = unknown> = {
137
+ /** the GQL fragment text — bundled with transitive deps if any */
138
+ document: string;
139
+ /** the fragment name to spread inside the source subscription — e.g. `Category` */
140
+ fragment: string;
141
+ /** the subscription field this fragment is bound to — `categoriesBatch`, `config`, etc */
142
+ subscription: string;
143
+ /** write bindings — present only for sources whose model exposes entity mutations */
144
+ mutations?: SourceMutations | undefined;
145
+ __model: TModel;
146
+ __cardinality: TCardinality;
147
+ /** phantom type — exists only at the type level */
148
+ __result?: TResult | undefined;
149
+ /** phantom type — exists only at the type level */
150
+ __writes?: TWrites | undefined;
151
+ };
152
+ type SourceMap = Record<string, SourceDef>;
153
+ /**
154
+ * The bundle emitted by `contello-client generate`. Pass to `createContelloClient({ schema })`
155
+ * (and to `createStore`, `createContello`). Each layer reads what it needs:
156
+ * - client uses `operations` (for `client.rpc.*`) and `sources` (for `client.sources.*`).
157
+ * - store uses `models` (for the dependency resolver) on top of what client uses.
158
+ */
159
+ type Schema<TOps extends OperationMap = OperationMap, TSources extends SourceMap = SourceMap, TModels extends string = string> = {
160
+ operations: TOps;
161
+ sources: TSources;
162
+ models: Record<TModels, string>;
163
+ };
164
+ type SourceFetcherFor<S> = S extends SourceDef<string, 'singleton', infer R> ? () => Promise<R> : S extends SourceDef<string, 'entity', infer R> ? (vars?: {
165
+ ids?: string[];
166
+ }) => Promise<R[]> : S extends SourceDef<string, 'route', infer R> ? (vars?: {
167
+ ids?: string[] | undefined;
168
+ paths?: string[] | undefined;
169
+ } | undefined) => Promise<R[]> : S extends SourceDef<string, 'asset', infer R> ? (vars?: {
170
+ ids?: string[] | undefined;
171
+ } | undefined) => Promise<R[]> : S extends SourceDef<string, 'i18nMessage', infer R> ? (vars: {
172
+ collection: string;
173
+ ids?: string[] | undefined;
174
+ }) => Promise<R[]> : never;
175
+ /** Extracts the phantom write-input shape of a SourceDef. */
176
+ type WritesOf<S> = S extends SourceDef<string, SourceCardinality, any, infer W> ? W : unknown;
177
+ /** Extracts the phantom result shape of a SourceDef — what its fragment selects. */
178
+ type ResultOf<S> = S extends SourceDef<string, SourceCardinality, infer R, any> ? R : unknown;
179
+ /**
180
+ * Per-source write accessors. Each method exists only when the generator found the matching
181
+ * mutation. A `create`/`update` selects the source's own fragment, so it answers with the entity
182
+ * in exactly the shape `fetch` yields; a `delete` answers with the id it removed. Nothing is
183
+ * cached here — that is the job of the collection that owns the source in `@contello/store`.
184
+ */
185
+ type SourceWritersFor<S> = (WritesOf<S> extends {
186
+ create: infer TCreate;
187
+ } ? {
188
+ create: (input: TCreate) => Promise<ResultOf<S>>;
189
+ } : Record<never, never>) & (WritesOf<S> extends {
190
+ update: infer TUpdate;
191
+ } ? {
192
+ update: (input: TUpdate) => Promise<ResultOf<S>>;
193
+ } : Record<never, never>) & (WritesOf<S> extends {
194
+ delete: infer TDelete;
195
+ } ? {
196
+ delete: (input: TDelete) => Promise<string>;
197
+ } : Record<never, never>);
198
+ /** Per-source runtime accessor: `client.sources.category.fetch()` → `Promise<CategoryFragment[]>` etc. */
199
+ type SourceAccessors<TSources extends SourceMap> = { [K in keyof TSources]: {
200
+ fetch: SourceFetcherFor<TSources[K]>;
201
+ } & SourceWritersFor<TSources[K]>; };
202
+ type UploadMetadata = {
203
+ name: string;
204
+ mimeType?: string | undefined;
205
+ size?: number | undefined;
206
+ annotations?: {
207
+ key: string;
208
+ value: string;
209
+ }[] | undefined;
210
+ collectionRefs?: string[] | undefined;
211
+ /**
212
+ * `deleteIfNotUsed` lets the server delete the asset once nothing references it.
213
+ * @default 'retain'
214
+ */
215
+ retentionPolicy?: 'retain' | 'deleteIfNotUsed' | undefined;
216
+ };
217
+ type UploadData = Uint8Array | ReadableStream$1<Uint8Array> | ReadableStream<Uint8Array>;
218
+ type UploadOptions = {
219
+ chunkSize?: number | undefined;
220
+ abort?: AbortSignal | undefined;
221
+ };
222
+ type ConnectionContext = {
223
+ connectionId: string;
224
+ websocketUrl: string;
225
+ };
226
+ type ConnectionEvents = {
227
+ onConnected?: ((context: ConnectionContext) => void) | undefined;
228
+ onConnecting?: ((context: ConnectionContext) => void) | undefined;
229
+ onClosed?: ((context: ConnectionContext) => void) | undefined;
230
+ onError?: ((context: ConnectionContext, error: unknown) => void) | undefined;
231
+ };
232
+ type ContelloClientOptions<TSchema extends Schema | undefined = undefined> = {
233
+ url: string;
234
+ project: string;
235
+ token: string;
236
+ schema?: TSchema | undefined;
237
+ connections?: number | undefined;
238
+ http?: HttpAgentOptions | undefined;
239
+ onConnected?: (() => void) | undefined;
240
+ onReconnecting?: (() => void) | undefined;
241
+ onError?: ((error: unknown) => void) | undefined;
242
+ connectionEvents?: ConnectionEvents | undefined;
243
+ };
244
+ declare class ContelloClient<TSchema extends Schema | undefined = undefined> {
245
+ private _pool;
246
+ private _rpc;
247
+ private _sources;
248
+ private _url;
249
+ private _project;
250
+ private _token;
251
+ private _agent;
252
+ constructor(options: ContelloClientOptions<TSchema>);
253
+ get rpc(): TSchema extends Schema<infer TOps, any, any> ? Rpc<TOps> : never;
254
+ get sources(): TSchema extends Schema<any, infer TSources, any> ? SourceAccessors<TSources> : never;
255
+ init(): Promise<void>;
256
+ destroy(): Promise<void>;
257
+ ping(): Promise<void>;
258
+ /**
259
+ * What a temporary token the Contello ui handed to an extension page stands for in the project of
260
+ * this client: the user and the user's effective permissions, or inactive. The client's
261
+ * application needs read access to the project. See `createTokenIntrospector` for the caching
262
+ * wrapper a backend puts in front of its requests.
263
+ */
264
+ introspectToken(token: string): Promise<TokenIntrospection>;
265
+ /**
266
+ * Open a subscription on the websocket. Each `[Symbol.asyncIterator]()` call (the implicit one
267
+ * from `for await`, or via `rxjs.from(this)`) starts a fresh server subscription and tears it
268
+ * down when the iterator is returned (`break`, error, or explicit stop).
269
+ */
270
+ subscribe<TData>(query: string, variables?: Record<string, unknown> | undefined): AsyncIterable<TData>;
271
+ download(fileId: string): Promise<DownloadResult>;
272
+ proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
273
+ proxySitemap(sitemapId: string, options: SitemapProxyOptions, signal?: AbortSignal | undefined): Promise<ProxyResult>;
274
+ upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
275
+ execute<TData>(query: string, variables?: Record<string, unknown> | undefined): Promise<TData>;
276
+ }
277
+ declare function createContelloClient<TSchema extends Schema | undefined = undefined>(options: ContelloClientOptions<TSchema>): ContelloClient<TSchema>;
278
+ export { DownloadResult as A, IntrospectedUser as C, TokenIntrospector as D, TokenIntrospection as E, ProxyResult as M, SitemapProxyOptions as N, TokenIntrospectorOptions as O, SourceWrites as S, ResourcePermissions as T, SourceMap as _, createContelloClient as a, SourceMutationResult as b, UploadOptions as c, OperationMap as d, Rpc as f, SourceDef as g, SourceCardinality as h, ContelloClientOptions as i, HttpAgentOptions as j, createTokenIntrospector as k, OperationDef as l, SourceAccessors as m, ConnectionEvents as n, UploadData as o, Schema as p, ContelloClient as r, UploadMetadata as s, ConnectionContext as t, OperationKind as u, SourceMutationArgument as v, ResourceAction as w, SourceMutations as x, SourceMutationBinding as y };
279
+ //# sourceMappingURL=client-AMuKG0mv.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-AMuKG0mv.d.cts","names":["NodeReadableStream"],"sources":["../src/http.ts","../src/introspection.ts","../src/types.ts","../src/upload.ts","../src/client.ts"],"mappings":";;;KAkCY;EACV;EACA;EACA;EACA;;KAcU;EACV;EACA;EACA,SAAS,QAAQ;EACjB,UAAU,eAAe;;KAiCf;EACV;EACA,SAAS;EACT,UAAU,eAAe;;KAqBf;;EAE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AAS,cAAc,SAAS,0BAA0B,QAAQ;EAIlE,aACE,mBACA,SAAS,qBACT,SAAS,0BACR,QAAQ;EAOX,OAAO,MAAM,YAAY,MAAM,gBAAgB,UAAU,4BAA4B;EAOrF,QAAQ,OAAO,eAAe,YAAY,sCAAsC,QAAQ;;iBAS1E,qBAAqB,gBAAgB,gCACnD,SAAS,sBAAsB,WAC9B,eAAe"}
@@ -0,0 +1,279 @@
1
+ import { Agent } from "undici";
2
+ import { MaybePromise } from "@entwico/dash";
3
+ import { ReadableStream as ReadableStream$1 } from "node:stream/web";
4
+ type HttpAgentOptions = {
5
+ pipelining?: number | undefined;
6
+ allowH2?: boolean | undefined;
7
+ maxConcurrentStreams?: number | undefined;
8
+ keepAliveTimeout?: number | undefined;
9
+ };
10
+ type DownloadResult = {
11
+ mimeType: string;
12
+ size: number;
13
+ bytes(): Promise<Uint8Array>;
14
+ stream(): ReadableStream<Uint8Array>;
15
+ };
16
+ type ProxyResult = {
17
+ status: number;
18
+ headers: Headers;
19
+ stream(): ReadableStream<Uint8Array>;
20
+ };
21
+ type SitemapProxyOptions = {
22
+ /** chunk source as received from the query string; core decides whether the source/page pair is valid */
23
+ source?: string | undefined;
24
+ /** chunk page as received from the query string */
25
+ page?: string | undefined;
26
+ /** the incoming request's Accept-Encoding, so stored gzip bytes pass through untouched */
27
+ acceptEncoding?: string | undefined;
28
+ /** the incoming request's If-None-Match, so core can answer 304 */
29
+ ifNoneMatch?: string | undefined;
30
+ };
31
+ type ResourceAction = 'READ' | 'CREATE' | 'UPDATE' | 'DELETE';
32
+ type ResourcePermissions = {
33
+ resourceType: 'ENTITY' | 'ASSET' | 'ROUTE' | 'I18N_MESSAGE_COLLECTION' | 'MODELLING' | 'EXTENSION' | (string & {});
34
+ scope: string | null;
35
+ actions: ResourceAction[];
36
+ };
37
+ type IntrospectedUser = {
38
+ id: string;
39
+ username: string;
40
+ firstName: string;
41
+ lastName: string;
42
+ email: string;
43
+ };
44
+ type TokenIntrospection = {
45
+ active: false;
46
+ } | {
47
+ active: true;
48
+ audience: string;
49
+ expiresAt: Date;
50
+ user: IntrospectedUser;
51
+ permissions: ResourcePermissions[];
52
+ };
53
+ type TokenIntrospectorOptions = {
54
+ audiences: string[];
55
+ maxAgeMs?: number | undefined;
56
+ maxEntries?: number | undefined;
57
+ };
58
+ type TokenIntrospector = {
59
+ introspect: (token: string) => MaybePromise<TokenIntrospection>;
60
+ };
61
+ declare function createTokenIntrospector(introspect: (token: string) => Promise<TokenIntrospection>, options: TokenIntrospectorOptions): TokenIntrospector;
62
+ type OperationKind = 'query' | 'mutation' | 'subscription';
63
+ type OperationDef<TResult = unknown, TVariables = Record<string, unknown>, TKind extends OperationKind = OperationKind> = {
64
+ document: string;
65
+ kind: TKind;
66
+ /** phantom type — exists only at the type level */
67
+ __result?: TResult | undefined;
68
+ /** phantom type — exists only at the type level */
69
+ __variables?: TVariables | undefined;
70
+ };
71
+ type OperationMap = Record<string, OperationDef>;
72
+ type InferResult<T extends OperationDef> = NonNullable<T['__result']>;
73
+ type InferVariables<T extends OperationDef> = NonNullable<T['__variables']>;
74
+ type RpcMethod<T extends OperationDef> = T['kind'] extends 'subscription' ? InferVariables<T> extends Record<string, never> ? () => AsyncIterable<InferResult<T>> : (variables: InferVariables<T>) => AsyncIterable<InferResult<T>> : InferVariables<T> extends Record<string, never> ? () => Promise<InferResult<T>> : (variables: InferVariables<T>) => Promise<InferResult<T>>;
75
+ type Rpc<T extends OperationMap> = { [K in keyof T]: RpcMethod<T[K]>; };
76
+ /**
77
+ * Discriminator for how a SourceDef binds to a Subscription field:
78
+ * - `entity` — a Contello entity model collection (`categoriesBatch` etc.), accepts optional `{ ids }` filter
79
+ * - `singleton` — a single Contello entity (`config` etc.), no args
80
+ * - `route` — built-in: `contelloRoutesBatch`, optional `{ ids, paths }` filter
81
+ * - `asset` — built-in: `contelloAssetsBatch`, optional `{ ids }` filter
82
+ * - `i18nMessage` — built-in: `contelloI18nMessagesBatch`, requires `{ collection }` and optional `{ ids }` filter
83
+ */
84
+ type SourceCardinality = 'entity' | 'singleton' | 'route' | 'asset' | 'i18nMessage';
85
+ /**
86
+ * One argument of a write mutation and what fills it. Entity mutations take a single input
87
+ * object; the built-ins vary — `createContelloRoute` takes `route:`, `deleteContelloRoute`
88
+ * takes a bare `id:`.
89
+ */
90
+ type SourceMutationArgument = {
91
+ /** the GQL argument name — `request`, `route`, `id` */
92
+ name: string;
93
+ /** the rendered GQL type, including nullability — `CreateCategoryRequestInput!`, `String` */
94
+ type: string;
95
+ /** `input` takes the caller's input, `id` the id passed to a delete */
96
+ from: 'input' | 'id';
97
+ /**
98
+ * the single field of a one-field envelope argument (`CreateCategoryRequestInput { entity }`).
99
+ * When set, the accessor takes the inner input and the runtime nests it under this key.
100
+ */
101
+ envelope?: string | undefined;
102
+ };
103
+ /**
104
+ * What a write mutation answers with:
105
+ * - `entity` — the entity itself, selected through the source's fragment
106
+ * - `idObject` — an object carrying `id` (`ContelloEntityDeleteResponse`)
107
+ * - `idScalar` — a bare id (`deleteContelloRoute: String!`)
108
+ */
109
+ type SourceMutationResult = 'entity' | 'idObject' | 'idScalar';
110
+ /**
111
+ * How one write operation of a source binds to a Mutation field. Emitted by the generator
112
+ * from introspection — the runtime never derives field or argument names by string munging.
113
+ */
114
+ type SourceMutationBinding = {
115
+ /** the mutation field — `createCategory` */
116
+ field: string;
117
+ arguments: SourceMutationArgument[];
118
+ result: SourceMutationResult;
119
+ };
120
+ /** Mutation bindings of a source. Absent operations are simply missing (singletons have no `create`). */
121
+ type SourceMutations = {
122
+ create?: SourceMutationBinding | undefined;
123
+ update?: SourceMutationBinding | undefined;
124
+ delete?: SourceMutationBinding | undefined;
125
+ };
126
+ /**
127
+ * Phantom shape carrying the input types of a source's write operations. A key is present
128
+ * only when the schema exposes the matching mutation, so `client.sources.x.create` exists
129
+ * exactly when `createX` does.
130
+ */
131
+ type SourceWrites = {
132
+ create?: unknown;
133
+ update?: unknown;
134
+ delete?: unknown;
135
+ };
136
+ type SourceDef<TModel extends string = string, TCardinality extends SourceCardinality = SourceCardinality, TResult = unknown, TWrites = unknown> = {
137
+ /** the GQL fragment text — bundled with transitive deps if any */
138
+ document: string;
139
+ /** the fragment name to spread inside the source subscription — e.g. `Category` */
140
+ fragment: string;
141
+ /** the subscription field this fragment is bound to — `categoriesBatch`, `config`, etc */
142
+ subscription: string;
143
+ /** write bindings — present only for sources whose model exposes entity mutations */
144
+ mutations?: SourceMutations | undefined;
145
+ __model: TModel;
146
+ __cardinality: TCardinality;
147
+ /** phantom type — exists only at the type level */
148
+ __result?: TResult | undefined;
149
+ /** phantom type — exists only at the type level */
150
+ __writes?: TWrites | undefined;
151
+ };
152
+ type SourceMap = Record<string, SourceDef>;
153
+ /**
154
+ * The bundle emitted by `contello-client generate`. Pass to `createContelloClient({ schema })`
155
+ * (and to `createStore`, `createContello`). Each layer reads what it needs:
156
+ * - client uses `operations` (for `client.rpc.*`) and `sources` (for `client.sources.*`).
157
+ * - store uses `models` (for the dependency resolver) on top of what client uses.
158
+ */
159
+ type Schema<TOps extends OperationMap = OperationMap, TSources extends SourceMap = SourceMap, TModels extends string = string> = {
160
+ operations: TOps;
161
+ sources: TSources;
162
+ models: Record<TModels, string>;
163
+ };
164
+ type SourceFetcherFor<S> = S extends SourceDef<string, 'singleton', infer R> ? () => Promise<R> : S extends SourceDef<string, 'entity', infer R> ? (vars?: {
165
+ ids?: string[];
166
+ }) => Promise<R[]> : S extends SourceDef<string, 'route', infer R> ? (vars?: {
167
+ ids?: string[] | undefined;
168
+ paths?: string[] | undefined;
169
+ } | undefined) => Promise<R[]> : S extends SourceDef<string, 'asset', infer R> ? (vars?: {
170
+ ids?: string[] | undefined;
171
+ } | undefined) => Promise<R[]> : S extends SourceDef<string, 'i18nMessage', infer R> ? (vars: {
172
+ collection: string;
173
+ ids?: string[] | undefined;
174
+ }) => Promise<R[]> : never;
175
+ /** Extracts the phantom write-input shape of a SourceDef. */
176
+ type WritesOf<S> = S extends SourceDef<string, SourceCardinality, any, infer W> ? W : unknown;
177
+ /** Extracts the phantom result shape of a SourceDef — what its fragment selects. */
178
+ type ResultOf<S> = S extends SourceDef<string, SourceCardinality, infer R, any> ? R : unknown;
179
+ /**
180
+ * Per-source write accessors. Each method exists only when the generator found the matching
181
+ * mutation. A `create`/`update` selects the source's own fragment, so it answers with the entity
182
+ * in exactly the shape `fetch` yields; a `delete` answers with the id it removed. Nothing is
183
+ * cached here — that is the job of the collection that owns the source in `@contello/store`.
184
+ */
185
+ type SourceWritersFor<S> = (WritesOf<S> extends {
186
+ create: infer TCreate;
187
+ } ? {
188
+ create: (input: TCreate) => Promise<ResultOf<S>>;
189
+ } : Record<never, never>) & (WritesOf<S> extends {
190
+ update: infer TUpdate;
191
+ } ? {
192
+ update: (input: TUpdate) => Promise<ResultOf<S>>;
193
+ } : Record<never, never>) & (WritesOf<S> extends {
194
+ delete: infer TDelete;
195
+ } ? {
196
+ delete: (input: TDelete) => Promise<string>;
197
+ } : Record<never, never>);
198
+ /** Per-source runtime accessor: `client.sources.category.fetch()` → `Promise<CategoryFragment[]>` etc. */
199
+ type SourceAccessors<TSources extends SourceMap> = { [K in keyof TSources]: {
200
+ fetch: SourceFetcherFor<TSources[K]>;
201
+ } & SourceWritersFor<TSources[K]>; };
202
+ type UploadMetadata = {
203
+ name: string;
204
+ mimeType?: string | undefined;
205
+ size?: number | undefined;
206
+ annotations?: {
207
+ key: string;
208
+ value: string;
209
+ }[] | undefined;
210
+ collectionRefs?: string[] | undefined;
211
+ /**
212
+ * `deleteIfNotUsed` lets the server delete the asset once nothing references it.
213
+ * @default 'retain'
214
+ */
215
+ retentionPolicy?: 'retain' | 'deleteIfNotUsed' | undefined;
216
+ };
217
+ type UploadData = Uint8Array | ReadableStream$1<Uint8Array> | ReadableStream<Uint8Array>;
218
+ type UploadOptions = {
219
+ chunkSize?: number | undefined;
220
+ abort?: AbortSignal | undefined;
221
+ };
222
+ type ConnectionContext = {
223
+ connectionId: string;
224
+ websocketUrl: string;
225
+ };
226
+ type ConnectionEvents = {
227
+ onConnected?: ((context: ConnectionContext) => void) | undefined;
228
+ onConnecting?: ((context: ConnectionContext) => void) | undefined;
229
+ onClosed?: ((context: ConnectionContext) => void) | undefined;
230
+ onError?: ((context: ConnectionContext, error: unknown) => void) | undefined;
231
+ };
232
+ type ContelloClientOptions<TSchema extends Schema | undefined = undefined> = {
233
+ url: string;
234
+ project: string;
235
+ token: string;
236
+ schema?: TSchema | undefined;
237
+ connections?: number | undefined;
238
+ http?: HttpAgentOptions | undefined;
239
+ onConnected?: (() => void) | undefined;
240
+ onReconnecting?: (() => void) | undefined;
241
+ onError?: ((error: unknown) => void) | undefined;
242
+ connectionEvents?: ConnectionEvents | undefined;
243
+ };
244
+ declare class ContelloClient<TSchema extends Schema | undefined = undefined> {
245
+ private _pool;
246
+ private _rpc;
247
+ private _sources;
248
+ private _url;
249
+ private _project;
250
+ private _token;
251
+ private _agent;
252
+ constructor(options: ContelloClientOptions<TSchema>);
253
+ get rpc(): TSchema extends Schema<infer TOps, any, any> ? Rpc<TOps> : never;
254
+ get sources(): TSchema extends Schema<any, infer TSources, any> ? SourceAccessors<TSources> : never;
255
+ init(): Promise<void>;
256
+ destroy(): Promise<void>;
257
+ ping(): Promise<void>;
258
+ /**
259
+ * What a temporary token the Contello ui handed to an extension page stands for in the project of
260
+ * this client: the user and the user's effective permissions, or inactive. The client's
261
+ * application needs read access to the project. See `createTokenIntrospector` for the caching
262
+ * wrapper a backend puts in front of its requests.
263
+ */
264
+ introspectToken(token: string): Promise<TokenIntrospection>;
265
+ /**
266
+ * Open a subscription on the websocket. Each `[Symbol.asyncIterator]()` call (the implicit one
267
+ * from `for await`, or via `rxjs.from(this)`) starts a fresh server subscription and tears it
268
+ * down when the iterator is returned (`break`, error, or explicit stop).
269
+ */
270
+ subscribe<TData>(query: string, variables?: Record<string, unknown> | undefined): AsyncIterable<TData>;
271
+ download(fileId: string): Promise<DownloadResult>;
272
+ proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
273
+ proxySitemap(sitemapId: string, options: SitemapProxyOptions, signal?: AbortSignal | undefined): Promise<ProxyResult>;
274
+ upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
275
+ execute<TData>(query: string, variables?: Record<string, unknown> | undefined): Promise<TData>;
276
+ }
277
+ declare function createContelloClient<TSchema extends Schema | undefined = undefined>(options: ContelloClientOptions<TSchema>): ContelloClient<TSchema>;
278
+ export { DownloadResult as A, IntrospectedUser as C, TokenIntrospector as D, TokenIntrospection as E, ProxyResult as M, SitemapProxyOptions as N, TokenIntrospectorOptions as O, SourceWrites as S, ResourcePermissions as T, SourceMap as _, createContelloClient as a, SourceMutationResult as b, UploadOptions as c, OperationMap as d, Rpc as f, SourceDef as g, SourceCardinality as h, ContelloClientOptions as i, HttpAgentOptions as j, createTokenIntrospector as k, OperationDef as l, SourceAccessors as m, ConnectionEvents as n, UploadData as o, Schema as p, ContelloClient as r, UploadMetadata as s, ConnectionContext as t, OperationKind as u, SourceMutationArgument as v, ResourceAction as w, SourceMutations as x, SourceMutationBinding as y };
279
+ //# sourceMappingURL=client-BxOONMjD.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-BxOONMjD.d.ts","names":["NodeReadableStream"],"sources":["../src/http.ts","../src/introspection.ts","../src/types.ts","../src/upload.ts","../src/client.ts"],"mappings":";;;KAkCY;EACV;EACA;EACA;EACA;;KAcU;EACV;EACA;EACA,SAAS,QAAQ;EACjB,UAAU,eAAe;;KAiCf;EACV;EACA,SAAS;EACT,UAAU,eAAe;;KAqBf;;EAEV;;EAEA;;EAEA;;EAEA;;KC/GU;KAKA;EACV;EACA;EACA,SAAS;;KAGC;EACV;EACA;EACA;EACA;EACA;;KAKU;EACN;;EAEF;EAEA;EACA,WAAW;EACX,MAAM;EACN,aAAa;;KAgCL;EAGV;EAGA;EAEA;;KAGU;EAEV,aAAa,kBAAkB,aAAa;;iBAU9B,wBACd,aAAa,kBAAkB,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