@nx-ddd/hasura 19.0.0-preview-enable-npm-publish.3

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/index.d.ts ADDED
@@ -0,0 +1,391 @@
1
+ import * as _nx_ddd_core from '@nx-ddd/core';
2
+ import { ApolloClient, ApolloLink, InMemoryCache, OperationVariables, FetchPolicy, FetchResult, ApolloQueryResult } from '@apollo/client/core';
3
+ import { ApolloLinkService as ApolloLinkService$1, GetHeaders as GetHeaders$1 } from '@nx-ddd/hasura/apollo/link';
4
+ import * as apollo_angular from 'apollo-angular';
5
+ import { Apollo, ApolloBase } from 'apollo-angular';
6
+ import { Observable } from 'rxjs';
7
+ import * as i0 from '@angular/core';
8
+ import { InjectionToken, Provider, EnvironmentProviders } from '@angular/core';
9
+ import { HttpLink } from 'apollo-angular/http';
10
+ import { Type, Repository } from '@nx-ddd/common/domain';
11
+ export { DeepPartial, TransformToDayjs } from '@nx-ddd/common/domain';
12
+ import dayjs from 'dayjs';
13
+ import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
14
+ import * as _nx_ddd_hasura from '@nx-ddd/hasura';
15
+ import * as lodash from 'lodash';
16
+ export { IsDayjs } from 'class-validator-extended';
17
+
18
+ interface HasuraConfig {
19
+ adminSecret?: string;
20
+ url: string;
21
+ }
22
+ declare const HASURA_CONFIG: InjectionToken<HasuraConfig>;
23
+ declare function provideHasuraConfig(config: HasuraConfig): Provider[];
24
+
25
+ /** @deprecated use ApolloClientManagerService instead */
26
+ declare class ApolloMultiService {
27
+ readonly apollo: Apollo;
28
+ protected readonly linkService: ApolloLinkService$1;
29
+ protected createClient(name: string, baseUrl: string, getHeaders: GetHeaders$1): void;
30
+ getClient(endpoint: string, getHeaders: GetHeaders$1): ApolloBase;
31
+ static ɵfac: i0.ɵɵFactoryDeclaration<ApolloMultiService, never>;
32
+ static ɵprov: i0.ɵɵInjectableDeclaration<ApolloMultiService>;
33
+ }
34
+ type GetApolloClient<E extends {
35
+ id: string;
36
+ }> = (config: HasuraConfig) => ApolloClient | Promise<ApolloClient> | Observable<ApolloClient>;
37
+ declare const GET_APOLLO_CLIENT: _nx_ddd_core.DiToken<GetApolloClient<any>>;
38
+
39
+ type PromiseOrObservable$1<T> = Promise<T> | Observable<T> | T;
40
+ type GetHeaders = () => PromiseOrObservable$1<Record<string, string>>;
41
+ declare function wrap<T>(obsOrPromiseOrValue: Promise<T> | Observable<T> | T): Observable<T>;
42
+ declare function resolve(getHeaders: GetHeaders): Promise<Record<string, string>>;
43
+
44
+ declare class ApolloLinkService {
45
+ readonly httpLink: HttpLink;
46
+ readonly WebSocketImpl: {
47
+ new (url: string | URL, protocols?: string | string[]): WebSocket;
48
+ prototype: WebSocket;
49
+ readonly CONNECTING: 0;
50
+ readonly OPEN: 1;
51
+ readonly CLOSING: 2;
52
+ readonly CLOSED: 3;
53
+ };
54
+ private createGraphQLWsClient;
55
+ createHttpLink(baseUrl: string, getHeaders: GetHeaders): ApolloLink;
56
+ createWebSocketLink(baseUrl: string, getHeaders: GetHeaders): ApolloLink;
57
+ createAutoSplitLink(baseUrl: string, getHeaders: GetHeaders): ApolloLink;
58
+ createLink(baseUrl: string, getHeaders: GetHeaders): ApolloLink;
59
+ static ɵfac: i0.ɵɵFactoryDeclaration<ApolloLinkService, never>;
60
+ static ɵprov: i0.ɵɵInjectableDeclaration<ApolloLinkService>;
61
+ }
62
+
63
+ declare class ApolloClientManagerService {
64
+ readonly apollo: Apollo;
65
+ protected readonly linkService: ApolloLinkService;
66
+ protected readonly crypto: webcrypto.Crypto;
67
+ protected buildClientName(endpoint: string, headers: Record<string, string>): Promise<string>;
68
+ getClient(endpoint: string, getHeaders: GetHeaders): Observable<ApolloBase<any>>;
69
+ static ɵfac: i0.ɵɵFactoryDeclaration<ApolloClientManagerService, never>;
70
+ static ɵprov: i0.ɵɵInjectableDeclaration<ApolloClientManagerService>;
71
+ }
72
+
73
+ interface HasuraConverter<E> {
74
+ toHasura(entity: E): object;
75
+ toHasuraMany(entities: E[]): object[];
76
+ fromHasura(entity: object): E;
77
+ fromHasuraMany(entities: object[]): E[];
78
+ }
79
+ type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? U extends Uncapitalize<U> ? `${Lowercase<T>}${CamelToSnakeCase<U>}` : `${Lowercase<T>}_${CamelToSnakeCase<U>}` : S;
80
+ type DeepCamelToSnake<T> = T extends Date ? T : T extends Array<infer U> ? DeepCamelToSnake<U>[] : T extends object ? {
81
+ [K in keyof T as K extends string ? CamelToSnakeCase<K> : K]: DeepCamelToSnake<T[K]>;
82
+ } : T;
83
+ declare function deepCamelToSnakeCase<T>(obj: T): DeepCamelToSnake<T>;
84
+ type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<SnakeToCamelCase<U>>}` : S;
85
+ type DeepSnakeToCamel<T> = T extends Date ? T : T extends Array<infer U> ? DeepSnakeToCamel<U>[] : T extends object ? {
86
+ [K in keyof T as K extends string ? SnakeToCamelCase<K> : K]: DeepSnakeToCamel<T[K]>;
87
+ } : T;
88
+ declare function deepSnakeToCamelCase<T>(obj: T): DeepSnakeToCamel<T>;
89
+ declare function getConverter<T>(type: Type<T>): HasuraConverter<T>;
90
+ /** @deprecated use `getConverter` instead */
91
+ declare const makeConverter: typeof getConverter;
92
+ declare class HasuraUtils {
93
+ static toTimestamp(date: dayjs.Dayjs | Date | null): string | null;
94
+ static toDate(date: dayjs.Dayjs | Date | string | null | undefined): string | null | undefined;
95
+ static fromHasura<T>(_object: any, type: Type<T>): T;
96
+ static toNumber(value: any): number | null | undefined;
97
+ static toHasuraLocation(position: {
98
+ lat: number;
99
+ lng: number;
100
+ } | null | undefined): {
101
+ type: string;
102
+ crs: {
103
+ type: string;
104
+ properties: {
105
+ name: string;
106
+ };
107
+ };
108
+ coordinates: number[];
109
+ };
110
+ static fromHasuraLocation(location: {
111
+ type: 'Point';
112
+ crs: {
113
+ type: 'name';
114
+ properties: {
115
+ name: 'urn:ogc:def:crs:EPSG::4326';
116
+ };
117
+ };
118
+ coordinates: [number, number];
119
+ }): {
120
+ lat: number;
121
+ lng: number;
122
+ };
123
+ static toHasura<E>(object: E, type: Type<E>, { extraFunc }?: {
124
+ extraFunc?: (obj: any) => any;
125
+ }): any;
126
+ }
127
+
128
+ declare function getFieldAnnotationMap<Annotation>(T: any, prefix?: string): Record<string, Annotation>;
129
+ declare function getFlattenFieldAnnotations<Annotation>(T: any, prefix?: string): Record<string, Annotation>;
130
+ declare function getFields(T: any, options?: {
131
+ prefix?: string;
132
+ case?: 'snake' | 'camel';
133
+ }): string[];
134
+ declare function getTableName(target: any): string;
135
+ declare const Hasura: {
136
+ Table: (nameOrProps: {
137
+ name: string;
138
+ } | string) => (target: any) => void;
139
+ Text: (nameOrProps?: {
140
+ name?: string;
141
+ } | string) => (target: any, propName: string) => void;
142
+ Timestamp: (nameOrProps?: {
143
+ name?: string;
144
+ } | string) => (target: any, propName: string) => void;
145
+ Date: (nameOrProps?: {
146
+ name?: string;
147
+ } | string) => (target: any, propName: string) => void;
148
+ Integer: (nameOrProps?: {
149
+ name?: string;
150
+ } | string) => (target: any, propName: string) => void;
151
+ Numeric: (nameOrProps?: {
152
+ name?: string;
153
+ } | string) => (target: any, propName: string) => void;
154
+ Boolean: (nameOrProps?: {
155
+ name?: string;
156
+ } | string) => (target: any, propName: string) => void;
157
+ Map: (childType: () => any) => (target: any, propName: string) => void;
158
+ JSON: (nameOrProps?: {
159
+ name?: string;
160
+ } | string) => (target: any, propName: string) => void;
161
+ Location: (nameOrProps?: {
162
+ name?: string;
163
+ } | string) => (target: any, propName: string) => void;
164
+ getAnnotations: (target: any) => {
165
+ type: string;
166
+ fieldName: string;
167
+ propName: string;
168
+ childType: any;
169
+ }[];
170
+ };
171
+
172
+ type PromiseOrObservable<T> = Promise<T> | Observable<T> | T;
173
+ declare const GRAPHQL_HEADERS: InjectionToken<GetHeaders>;
174
+ declare function provideHasuraGetHeaders(useFactory: () => () => PromiseOrObservable<Record<string, string>>): Provider;
175
+ /**
176
+ * @deprecated use provideHasuraGetHeaders instead
177
+ */
178
+ declare const provideGraphqlHeaders: typeof provideHasuraGetHeaders;
179
+ declare function provideApolloOptions(): {
180
+ provide: InjectionToken<any>;
181
+ useFactory: (link: ApolloLink) => {
182
+ cache: InMemoryCache;
183
+ link: ApolloLink;
184
+ };
185
+ deps: (typeof ApolloLink)[];
186
+ };
187
+ declare function provideHasura(config: HasuraConfig): (Provider | EnvironmentProviders)[];
188
+ declare function provideHasuraWithWebSocket(config: HasuraConfig): (Provider | EnvironmentProviders)[];
189
+
190
+ declare class HasuraInterceptor implements HttpInterceptor {
191
+ private config;
192
+ intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
193
+ static ɵfac: i0.ɵɵFactoryDeclaration<HasuraInterceptor, never>;
194
+ static ɵprov: i0.ɵɵInjectableDeclaration<HasuraInterceptor>;
195
+ }
196
+
197
+ interface TransactionQueryPart {
198
+ queryPart: string;
199
+ variableDefinitions: string[];
200
+ variables: Record<string, any>;
201
+ operationName: string;
202
+ alias?: string;
203
+ }
204
+ interface TableConfig {
205
+ tableName: string;
206
+ columns: string[];
207
+ pk: string;
208
+ }
209
+
210
+ type CreateData<E> = Omit<E, 'id' | 'createdAt' | 'updatedAt'>;
211
+ declare class CreateMutationBuilder<E extends {
212
+ id: string;
213
+ }> {
214
+ protected readonly config: TableConfig;
215
+ constructor(config: TableConfig);
216
+ build(data: CreateData<E>, alias?: string): TransactionQueryPart;
217
+ buildMany(data: CreateData<E>[], alias?: string): TransactionQueryPart;
218
+ protected convertToObject(item: CreateData<E>): lodash.Dictionary<unknown>;
219
+ protected convertToObjects(items: CreateData<E>[]): lodash.Dictionary<unknown>[];
220
+ }
221
+
222
+ declare class DeleteMutationBuilder {
223
+ protected readonly config: TableConfig;
224
+ constructor(config: TableConfig);
225
+ build({ id }: {
226
+ id: any;
227
+ }): TransactionQueryPart;
228
+ buildMany(params: {
229
+ id: string;
230
+ }[], alias?: string): TransactionQueryPart;
231
+ buildAll(alias?: string): TransactionQueryPart;
232
+ }
233
+
234
+ interface Options {
235
+ operationName?: string;
236
+ constraint?: string;
237
+ columns?: string[];
238
+ returningColumns?: string[];
239
+ alias?: string;
240
+ }
241
+ declare class SaveMutationBuilder<E = any> {
242
+ protected readonly config: TableConfig;
243
+ constructor(config: TableConfig);
244
+ build(data: Omit<E, 'createdAt' | 'updatedAt'>, { operationName, constraint, columns, returningColumns, alias, }?: Options): TransactionQueryPart;
245
+ buildMany(entities: E[], { operationName, constraint, columns, returningColumns, alias }?: Options): TransactionQueryPart;
246
+ protected buildObject(item: Omit<E, 'createdAt' | 'updatedAt'>): lodash.Dictionary<unknown>;
247
+ protected buildObjects(items: Omit<E, 'createdAt' | 'updatedAt'>[]): lodash.Dictionary<unknown>[];
248
+ protected buildOnConflict(data: Omit<E, 'createdAt' | 'updatedAt'>, constraint: string, columns: string[]): {
249
+ constraint: string;
250
+ update_columns: string[];
251
+ };
252
+ }
253
+
254
+ declare class UpdateMutationBuilder<E extends {
255
+ id: string;
256
+ } = any> {
257
+ protected readonly config: TableConfig;
258
+ constructor(config: TableConfig);
259
+ build(data: Partial<E> & {
260
+ id: string;
261
+ }, alias?: string): TransactionQueryPart;
262
+ buildMany(data: Partial<E>[], alias?: string): TransactionQueryPart;
263
+ protected buildObject(item: Partial<E>): any;
264
+ protected buildObjects(items: Partial<E>[]): any[];
265
+ }
266
+
267
+ declare class HasuraMutationBuilder<E extends {
268
+ id: string;
269
+ }> {
270
+ readonly create: CreateMutationBuilder<E>;
271
+ readonly update: UpdateMutationBuilder<E>;
272
+ readonly save: SaveMutationBuilder<E>;
273
+ readonly delete_: DeleteMutationBuilder;
274
+ constructor(config: TableConfig);
275
+ }
276
+
277
+ declare class GetQueryPartBuilder {
278
+ protected config: TableConfig;
279
+ constructor(config: TableConfig);
280
+ build(params: {
281
+ id: string;
282
+ }): TransactionQueryPart;
283
+ buildMany(): TransactionQueryPart;
284
+ }
285
+
286
+ declare class QueriesBuilder<E extends {
287
+ id: string;
288
+ }> {
289
+ readonly get: GetQueryPartBuilder;
290
+ constructor(config: TableConfig);
291
+ makeSubscription(query: any): {
292
+ kind: any;
293
+ definitions: any;
294
+ };
295
+ }
296
+
297
+ declare class HasuraQueryPartsBuilder<E extends {
298
+ id: string;
299
+ }> {
300
+ readonly mutations: HasuraMutationBuilder<E>;
301
+ readonly queries: QueriesBuilder<E>;
302
+ constructor(config: TableConfig);
303
+ }
304
+
305
+ declare class HasuraQueryBuilder<E extends {
306
+ id: string;
307
+ }> {
308
+ readonly parts: HasuraQueryPartsBuilder<E>;
309
+ constructor(config: TableConfig);
310
+ buildQuery(part: TransactionQueryPart): string;
311
+ static buildMutation(part: TransactionQueryPart): string;
312
+ buildMutation(part: TransactionQueryPart): string;
313
+ buildTransactionQuery(parts: TransactionQueryPart[]): {
314
+ query: string;
315
+ variables: Record<string, any>;
316
+ };
317
+ }
318
+
319
+ declare class HasuraService {
320
+ protected readonly getHeaders: _nx_ddd_hasura.GetHeaders;
321
+ protected readonly apolloClientManager: ApolloClientManagerService;
322
+ protected readonly config: HasuraConfig;
323
+ getApolloClient(): Observable<ApolloBase<any>>;
324
+ subscribe<T = any, TVariables extends OperationVariables = OperationVariables>({ query, variables, fetchPolicy, context }: {
325
+ query: any;
326
+ variables: TVariables;
327
+ fetchPolicy?: FetchPolicy;
328
+ context?: Record<string, unknown>;
329
+ }): Observable<FetchResult<T>>;
330
+ mutate<T = any>(...args: Parameters<ApolloBase['mutate']>): Promise<apollo_angular.MutationResult<unknown>>;
331
+ mutateByQueryPart<T = any>(part: TransactionQueryPart): Promise<T>;
332
+ query<T = any>(...args: Parameters<ApolloBase['query']>): Promise<ApolloQueryResult<T>>;
333
+ watchQuery<T = any, TVariables extends OperationVariables = OperationVariables>(options: {
334
+ query: any;
335
+ variables?: TVariables;
336
+ fetchPolicy?: FetchPolicy;
337
+ }): Observable<any>;
338
+ static ɵfac: i0.ɵɵFactoryDeclaration<HasuraService, never>;
339
+ static ɵprov: i0.ɵɵInjectableDeclaration<HasuraService>;
340
+ }
341
+
342
+ declare abstract class _HasuraRepository<E extends {
343
+ id: string;
344
+ }> extends Repository<E> {
345
+ protected abstract hasura: HasuraService;
346
+ protected abstract converter: HasuraConverter<E>;
347
+ readonly abstract updateColumns: string[];
348
+ readonly abstract tableName: string;
349
+ get pkey(): string;
350
+ getQueryBuilder(): HasuraQueryBuilder<{
351
+ id: string;
352
+ }>;
353
+ get(params: {
354
+ id: string;
355
+ }): Promise<E>;
356
+ list(): Promise<E[]>;
357
+ listChanges(): Observable<E[]>;
358
+ create(data: Omit<E, 'id' | 'createdAt' | 'updatedAt'> & Partial<Pick<E, 'id'>>): Promise<E>;
359
+ createMany(data: Omit<E, 'id' | 'createdAt' | 'updatedAt'>[]): Promise<E[]>;
360
+ update(data: Partial<E> & {
361
+ id: string;
362
+ }): Promise<void>;
363
+ updateMany(data: Partial<E>[]): Promise<void>;
364
+ delete(params: {
365
+ id: string;
366
+ }): Promise<void>;
367
+ deleteMany(params: {
368
+ id: string;
369
+ }[]): Promise<number>;
370
+ deleteAll(): Promise<void>;
371
+ save(data: Partial<E>): Promise<any>;
372
+ saveMany(entities: E[]): Promise<void>;
373
+ }
374
+ declare abstract class HasuraRepository<E extends {
375
+ id: string;
376
+ }> extends _HasuraRepository<E> {
377
+ protected hasura: HasuraService;
378
+ static ɵfac: i0.ɵɵFactoryDeclaration<HasuraRepository<any>, never>;
379
+ static ɵprov: i0.ɵɵInjectableDeclaration<HasuraRepository<any>>;
380
+ }
381
+ declare function getHasuraRepository<E extends {
382
+ id: string;
383
+ }>(Entity: Type<E>, deps: {
384
+ hasura: HasuraService;
385
+ }): _HasuraRepository<E>;
386
+ declare function injectHasuraRepository<E extends {
387
+ id: string;
388
+ }>(Entity: Type<E>): _HasuraRepository<E>;
389
+
390
+ export { ApolloClientManagerService, ApolloMultiService, GET_APOLLO_CLIENT, GRAPHQL_HEADERS, HASURA_CONFIG, Hasura, HasuraInterceptor, HasuraQueryBuilder, HasuraRepository, HasuraService, HasuraUtils, _HasuraRepository, deepCamelToSnakeCase, deepSnakeToCamelCase, getConverter, getFieldAnnotationMap, getFields, getFlattenFieldAnnotations, getHasuraRepository, getTableName, injectHasuraRepository, makeConverter, provideApolloOptions, provideGraphqlHeaders, provideHasura, provideHasuraConfig, provideHasuraGetHeaders, provideHasuraWithWebSocket, resolve, wrap };
391
+ export type { GetApolloClient, GetHeaders, HasuraConfig, HasuraConverter, TableConfig, TransactionQueryPart };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@nx-ddd/hasura",
3
+ "version": "19.0.0-preview-enable-npm-publish.3",
4
+ "license": "MIT",
5
+ "peerDependencies": {
6
+ "@nx-ddd/core": "19.0.0-preview-enable-npm-publish.3"
7
+ },
8
+ "dependencies": {
9
+ "tslib": "^2.3.0"
10
+ },
11
+ "module": "fesm2022/nx-ddd-hasura.mjs",
12
+ "typings": "index.d.ts",
13
+ "exports": {
14
+ "./package.json": {
15
+ "default": "./package.json"
16
+ },
17
+ ".": {
18
+ "types": "./index.d.ts",
19
+ "default": "./fesm2022/nx-ddd-hasura.mjs"
20
+ },
21
+ "./browser": {
22
+ "types": "./browser/index.d.ts",
23
+ "default": "./fesm2022/nx-ddd-hasura-browser.mjs"
24
+ },
25
+ "./server": {
26
+ "types": "./server/index.d.ts",
27
+ "default": "./fesm2022/nx-ddd-hasura-server.mjs"
28
+ },
29
+ "./apollo/link": {
30
+ "types": "./apollo/link/index.d.ts",
31
+ "default": "./fesm2022/nx-ddd-hasura-apollo-link.mjs"
32
+ }
33
+ },
34
+ "sideEffects": false
35
+ }
@@ -0,0 +1,8 @@
1
+ import { Provider } from '@angular/core';
2
+
3
+ /**
4
+ * Provides all necessary dependencies for Hasura in Node.js/server environments
5
+ */
6
+ declare function provideHasuraServer(): Provider[];
7
+
8
+ export { provideHasuraServer };