@pgpmjs/migrate-client 0.1.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.
Files changed (51) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +112 -0
  3. package/esm/index.d.ts +1 -0
  4. package/esm/index.js +1 -0
  5. package/esm/migrate/index.d.ts +5 -0
  6. package/esm/migrate/index.js +5 -0
  7. package/esm/migrate/orm/client.d.ts +55 -0
  8. package/esm/migrate/orm/client.js +99 -0
  9. package/esm/migrate/orm/index.d.ts +48 -0
  10. package/esm/migrate/orm/index.js +45 -0
  11. package/esm/migrate/orm/input-types.d.ts +513 -0
  12. package/esm/migrate/orm/input-types.js +2 -0
  13. package/esm/migrate/orm/models/index.d.ts +7 -0
  14. package/esm/migrate/orm/models/index.js +7 -0
  15. package/esm/migrate/orm/models/migrateFile.d.ts +56 -0
  16. package/esm/migrate/orm/models/migrateFile.js +94 -0
  17. package/esm/migrate/orm/models/sqlAction.d.ts +56 -0
  18. package/esm/migrate/orm/models/sqlAction.js +94 -0
  19. package/esm/migrate/orm/mutation/index.d.ts +27 -0
  20. package/esm/migrate/orm/mutation/index.js +30 -0
  21. package/esm/migrate/orm/query-builder.d.ts +91 -0
  22. package/esm/migrate/orm/query-builder.js +572 -0
  23. package/esm/migrate/orm/select-types.d.ts +103 -0
  24. package/esm/migrate/orm/select-types.js +1 -0
  25. package/esm/migrate/orm/types.d.ts +6 -0
  26. package/esm/migrate/orm/types.js +7 -0
  27. package/index.d.ts +1 -0
  28. package/index.js +17 -0
  29. package/migrate/index.d.ts +5 -0
  30. package/migrate/index.js +21 -0
  31. package/migrate/orm/client.d.ts +55 -0
  32. package/migrate/orm/client.js +105 -0
  33. package/migrate/orm/index.d.ts +48 -0
  34. package/migrate/orm/index.js +66 -0
  35. package/migrate/orm/input-types.d.ts +513 -0
  36. package/migrate/orm/input-types.js +5 -0
  37. package/migrate/orm/models/index.d.ts +7 -0
  38. package/migrate/orm/models/index.js +12 -0
  39. package/migrate/orm/models/migrateFile.d.ts +56 -0
  40. package/migrate/orm/models/migrateFile.js +98 -0
  41. package/migrate/orm/models/sqlAction.d.ts +56 -0
  42. package/migrate/orm/models/sqlAction.js +98 -0
  43. package/migrate/orm/mutation/index.d.ts +27 -0
  44. package/migrate/orm/mutation/index.js +33 -0
  45. package/migrate/orm/query-builder.d.ts +91 -0
  46. package/migrate/orm/query-builder.js +619 -0
  47. package/migrate/orm/select-types.d.ts +103 -0
  48. package/migrate/orm/select-types.js +2 -0
  49. package/migrate/orm/types.d.ts +6 -0
  50. package/migrate/orm/types.js +23 -0
  51. package/package.json +53 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * SqlAction model for ORM client
3
+ * @generated by @constructive-io/graphql-codegen
4
+ * DO NOT EDIT - changes will be overwritten
5
+ */
6
+ import { OrmClient } from '../client';
7
+ import { QueryBuilder } from '../query-builder';
8
+ import type { ConnectionResult, FindManyArgs, FindFirstArgs, CreateArgs, UpdateArgs, DeleteArgs, InferSelectResult, StrictSelect } from '../select-types';
9
+ import type { SqlActionWithRelations, SqlActionSelect, SqlActionFilter, SqlActionOrderBy, CreateSqlActionInput, SqlActionPatch } from '../input-types';
10
+ export declare class SqlActionModel {
11
+ private client;
12
+ constructor(client: OrmClient);
13
+ findMany<S extends SqlActionSelect>(args: FindManyArgs<S, SqlActionFilter, never, SqlActionOrderBy> & {
14
+ select: S;
15
+ } & StrictSelect<S, SqlActionSelect>): QueryBuilder<{
16
+ sqlActions: ConnectionResult<InferSelectResult<SqlActionWithRelations, S>>;
17
+ }>;
18
+ findFirst<S extends SqlActionSelect>(args: FindFirstArgs<S, SqlActionFilter> & {
19
+ select: S;
20
+ } & StrictSelect<S, SqlActionSelect>): QueryBuilder<{
21
+ sqlActions: {
22
+ nodes: InferSelectResult<SqlActionWithRelations, S>[];
23
+ };
24
+ }>;
25
+ findOne<S extends SqlActionSelect>(args: {
26
+ id: number;
27
+ select: S;
28
+ } & StrictSelect<S, SqlActionSelect>): QueryBuilder<{
29
+ sqlAction: InferSelectResult<SqlActionWithRelations, S> | null;
30
+ }>;
31
+ create<S extends SqlActionSelect>(args: CreateArgs<S, CreateSqlActionInput['sqlAction']> & {
32
+ select: S;
33
+ } & StrictSelect<S, SqlActionSelect>): QueryBuilder<{
34
+ createSqlAction: {
35
+ sqlAction: InferSelectResult<SqlActionWithRelations, S>;
36
+ };
37
+ }>;
38
+ update<S extends SqlActionSelect>(args: UpdateArgs<S, {
39
+ id: number;
40
+ }, SqlActionPatch> & {
41
+ select: S;
42
+ } & StrictSelect<S, SqlActionSelect>): QueryBuilder<{
43
+ updateSqlAction: {
44
+ sqlAction: InferSelectResult<SqlActionWithRelations, S>;
45
+ };
46
+ }>;
47
+ delete<S extends SqlActionSelect>(args: DeleteArgs<{
48
+ id: number;
49
+ }, S> & {
50
+ select: S;
51
+ } & StrictSelect<S, SqlActionSelect>): QueryBuilder<{
52
+ deleteSqlAction: {
53
+ sqlAction: InferSelectResult<SqlActionWithRelations, S>;
54
+ };
55
+ }>;
56
+ }
@@ -0,0 +1,94 @@
1
+ import { QueryBuilder, buildFindManyDocument, buildFindFirstDocument, buildCreateDocument, buildUpdateByPkDocument, buildDeleteByPkDocument, } from '../query-builder';
2
+ import { connectionFieldsMap } from '../input-types';
3
+ export class SqlActionModel {
4
+ client;
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ findMany(args) {
9
+ const { document, variables } = buildFindManyDocument('SqlAction', 'sqlActions', args.select, {
10
+ where: args?.where,
11
+ orderBy: args?.orderBy,
12
+ first: args?.first,
13
+ last: args?.last,
14
+ after: args?.after,
15
+ before: args?.before,
16
+ offset: args?.offset,
17
+ }, 'SqlActionFilter', 'SqlActionOrderBy', connectionFieldsMap);
18
+ return new QueryBuilder({
19
+ client: this.client,
20
+ operation: 'query',
21
+ operationName: 'SqlAction',
22
+ fieldName: 'sqlActions',
23
+ document,
24
+ variables,
25
+ });
26
+ }
27
+ findFirst(args) {
28
+ const { document, variables } = buildFindFirstDocument('SqlAction', 'sqlActions', args.select, {
29
+ where: args?.where,
30
+ }, 'SqlActionFilter', connectionFieldsMap);
31
+ return new QueryBuilder({
32
+ client: this.client,
33
+ operation: 'query',
34
+ operationName: 'SqlAction',
35
+ fieldName: 'sqlActions',
36
+ document,
37
+ variables,
38
+ });
39
+ }
40
+ findOne(args) {
41
+ const { document, variables } = buildFindManyDocument('SqlAction', 'sqlActions', args.select, {
42
+ where: {
43
+ id: {
44
+ equalTo: args.id,
45
+ },
46
+ },
47
+ first: 1,
48
+ }, 'SqlActionFilter', 'SqlActionOrderBy', connectionFieldsMap);
49
+ return new QueryBuilder({
50
+ client: this.client,
51
+ operation: 'query',
52
+ operationName: 'SqlAction',
53
+ fieldName: 'sqlAction',
54
+ document,
55
+ variables,
56
+ transform: (data) => ({
57
+ sqlAction: data.sqlActions?.nodes?.[0] ?? null,
58
+ }),
59
+ });
60
+ }
61
+ create(args) {
62
+ const { document, variables } = buildCreateDocument('SqlAction', 'createSqlAction', 'sqlAction', args.select, args.data, 'CreateSqlActionInput', connectionFieldsMap);
63
+ return new QueryBuilder({
64
+ client: this.client,
65
+ operation: 'mutation',
66
+ operationName: 'SqlAction',
67
+ fieldName: 'createSqlAction',
68
+ document,
69
+ variables,
70
+ });
71
+ }
72
+ update(args) {
73
+ const { document, variables } = buildUpdateByPkDocument('SqlAction', 'updateSqlAction', 'sqlAction', args.select, args.where.id, args.data, 'UpdateSqlActionInput', 'id', 'sqlActionPatch', connectionFieldsMap);
74
+ return new QueryBuilder({
75
+ client: this.client,
76
+ operation: 'mutation',
77
+ operationName: 'SqlAction',
78
+ fieldName: 'updateSqlAction',
79
+ document,
80
+ variables,
81
+ });
82
+ }
83
+ delete(args) {
84
+ const { document, variables } = buildDeleteByPkDocument('SqlAction', 'deleteSqlAction', 'sqlAction', args.where.id, 'DeleteSqlActionInput', 'id', args.select, connectionFieldsMap);
85
+ return new QueryBuilder({
86
+ client: this.client,
87
+ operation: 'mutation',
88
+ operationName: 'SqlAction',
89
+ fieldName: 'deleteSqlAction',
90
+ document,
91
+ variables,
92
+ });
93
+ }
94
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Custom mutation operations
3
+ * @generated by @constructive-io/graphql-codegen
4
+ * DO NOT EDIT - changes will be overwritten
5
+ */
6
+ import { OrmClient } from '../client';
7
+ import { QueryBuilder } from '../query-builder';
8
+ import type { InferSelectResult, StrictSelect } from '../select-types';
9
+ import type { ExecuteSqlInput, RunMigrationInput, ExecuteSqlPayload, RunMigrationPayload, ExecuteSqlPayloadSelect, RunMigrationPayloadSelect } from '../input-types';
10
+ export interface ExecuteSqlVariables {
11
+ input: ExecuteSqlInput;
12
+ }
13
+ export interface RunMigrationVariables {
14
+ input: RunMigrationInput;
15
+ }
16
+ export declare function createMutationOperations(client: OrmClient): {
17
+ executeSql: <S extends ExecuteSqlPayloadSelect>(args: ExecuteSqlVariables, options: {
18
+ select: S;
19
+ } & StrictSelect<S, ExecuteSqlPayloadSelect>) => QueryBuilder<{
20
+ executeSql: InferSelectResult<ExecuteSqlPayload, S> | null;
21
+ }>;
22
+ runMigration: <S extends RunMigrationPayloadSelect>(args: RunMigrationVariables, options: {
23
+ select: S;
24
+ } & StrictSelect<S, RunMigrationPayloadSelect>) => QueryBuilder<{
25
+ runMigration: InferSelectResult<RunMigrationPayload, S> | null;
26
+ }>;
27
+ };
@@ -0,0 +1,30 @@
1
+ import { QueryBuilder, buildCustomDocument } from '../query-builder';
2
+ import { connectionFieldsMap } from '../input-types';
3
+ export function createMutationOperations(client) {
4
+ return {
5
+ executeSql: (args, options) => new QueryBuilder({
6
+ client,
7
+ operation: 'mutation',
8
+ operationName: 'ExecuteSql',
9
+ fieldName: 'executeSql',
10
+ ...buildCustomDocument('mutation', 'ExecuteSql', 'executeSql', options.select, args, [
11
+ {
12
+ name: 'input',
13
+ type: 'ExecuteSqlInput!',
14
+ },
15
+ ], connectionFieldsMap, 'ExecuteSqlPayload'),
16
+ }),
17
+ runMigration: (args, options) => new QueryBuilder({
18
+ client,
19
+ operation: 'mutation',
20
+ operationName: 'RunMigration',
21
+ fieldName: 'runMigration',
22
+ ...buildCustomDocument('mutation', 'RunMigration', 'runMigration', options.select, args, [
23
+ {
24
+ name: 'input',
25
+ type: 'RunMigrationInput!',
26
+ },
27
+ ], connectionFieldsMap, 'RunMigrationPayload'),
28
+ }),
29
+ };
30
+ }
@@ -0,0 +1,91 @@
1
+ import type { FieldNode } from 'graphql';
2
+ import { OrmClient, QueryResult } from './client';
3
+ export interface QueryBuilderConfig<TResult> {
4
+ client: OrmClient;
5
+ operation: 'query' | 'mutation';
6
+ operationName: string;
7
+ fieldName: string;
8
+ document: string;
9
+ variables?: Record<string, unknown>;
10
+ transform?: (data: any) => TResult;
11
+ }
12
+ export declare class QueryBuilder<TResult> {
13
+ private config;
14
+ constructor(config: QueryBuilderConfig<TResult>);
15
+ /**
16
+ * Execute the query and return a discriminated union result
17
+ * Use result.ok to check success, or .unwrap() to throw on error
18
+ */
19
+ execute(): Promise<QueryResult<TResult>>;
20
+ /**
21
+ * Execute and unwrap the result, throwing GraphQLRequestError on failure
22
+ * @throws {GraphQLRequestError} If the query returns errors
23
+ */
24
+ unwrap(): Promise<TResult>;
25
+ /**
26
+ * Execute and unwrap, returning defaultValue on error instead of throwing
27
+ */
28
+ unwrapOr<D>(defaultValue: D): Promise<TResult | D>;
29
+ /**
30
+ * Execute and unwrap, calling onError callback on failure
31
+ */
32
+ unwrapOrElse<D>(onError: (errors: import('./client').GraphQLError[]) => D): Promise<TResult | D>;
33
+ toGraphQL(): string;
34
+ getVariables(): Record<string, unknown> | undefined;
35
+ }
36
+ export declare function buildSelections(select: Record<string, unknown> | undefined, connectionFieldsMap?: Record<string, Record<string, string>>, entityType?: string): FieldNode[];
37
+ export declare function buildFindManyDocument<TSelect, TWhere, TCondition = never>(operationName: string, queryField: string, select: TSelect, args: {
38
+ where?: TWhere;
39
+ condition?: TCondition;
40
+ orderBy?: string[];
41
+ first?: number;
42
+ last?: number;
43
+ after?: string;
44
+ before?: string;
45
+ offset?: number;
46
+ }, filterTypeName: string, orderByTypeName: string, connectionFieldsMap?: Record<string, Record<string, string>>, conditionTypeName?: string): {
47
+ document: string;
48
+ variables: Record<string, unknown>;
49
+ };
50
+ export declare function buildFindFirstDocument<TSelect, TWhere, TCondition = never>(operationName: string, queryField: string, select: TSelect, args: {
51
+ where?: TWhere;
52
+ condition?: TCondition;
53
+ }, filterTypeName: string, connectionFieldsMap?: Record<string, Record<string, string>>, conditionTypeName?: string): {
54
+ document: string;
55
+ variables: Record<string, unknown>;
56
+ };
57
+ export declare function buildCreateDocument<TSelect, TData>(operationName: string, mutationField: string, entityField: string, select: TSelect, data: TData, inputTypeName: string, connectionFieldsMap?: Record<string, Record<string, string>>): {
58
+ document: string;
59
+ variables: Record<string, unknown>;
60
+ };
61
+ export declare function buildUpdateDocument<TSelect, TWhere extends {
62
+ id: string;
63
+ }, TData>(operationName: string, mutationField: string, entityField: string, select: TSelect, where: TWhere, data: TData, inputTypeName: string, patchFieldName: string, connectionFieldsMap?: Record<string, Record<string, string>>): {
64
+ document: string;
65
+ variables: Record<string, unknown>;
66
+ };
67
+ export declare function buildUpdateByPkDocument<TSelect, TData>(operationName: string, mutationField: string, entityField: string, select: TSelect, id: string | number, data: TData, inputTypeName: string, idFieldName: string, patchFieldName: string, connectionFieldsMap?: Record<string, Record<string, string>>): {
68
+ document: string;
69
+ variables: Record<string, unknown>;
70
+ };
71
+ export declare function buildFindOneDocument<TSelect>(operationName: string, queryField: string, id: string | number, select: TSelect, idArgName: string, idTypeName: string, connectionFieldsMap?: Record<string, Record<string, string>>): {
72
+ document: string;
73
+ variables: Record<string, unknown>;
74
+ };
75
+ export declare function buildDeleteDocument<TWhere extends {
76
+ id: string;
77
+ }, TSelect = undefined>(operationName: string, mutationField: string, entityField: string, where: TWhere, inputTypeName: string, select?: TSelect, connectionFieldsMap?: Record<string, Record<string, string>>): {
78
+ document: string;
79
+ variables: Record<string, unknown>;
80
+ };
81
+ export declare function buildDeleteByPkDocument<TSelect = undefined>(operationName: string, mutationField: string, entityField: string, id: string | number, inputTypeName: string, idFieldName: string, select?: TSelect, connectionFieldsMap?: Record<string, Record<string, string>>): {
82
+ document: string;
83
+ variables: Record<string, unknown>;
84
+ };
85
+ export declare function buildCustomDocument<TSelect, TArgs>(operationType: 'query' | 'mutation', operationName: string, fieldName: string, select: TSelect, args: TArgs, variableDefinitions: Array<{
86
+ name: string;
87
+ type: string;
88
+ }>, connectionFieldsMap?: Record<string, Record<string, string>>, entityType?: string): {
89
+ document: string;
90
+ variables: Record<string, unknown>;
91
+ };