@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
package/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./migrate/orm"), exports);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * GraphQL SDK - auto-generated, do not edit
3
+ * @generated by @constructive-io/graphql-codegen
4
+ */
5
+ export * from './orm';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * GraphQL SDK - auto-generated, do not edit
19
+ * @generated by @constructive-io/graphql-codegen
20
+ */
21
+ __exportStar(require("./orm"), exports);
@@ -0,0 +1,55 @@
1
+ /**
2
+ * ORM Client - Runtime GraphQL executor
3
+ * @generated by @constructive-io/graphql-codegen
4
+ * DO NOT EDIT - changes will be overwritten
5
+ */
6
+ import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-types';
7
+ export type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-types';
8
+ /**
9
+ * Default adapter that uses fetch for HTTP requests.
10
+ * This is used when no custom adapter is provided.
11
+ */
12
+ export declare class FetchAdapter implements GraphQLAdapter {
13
+ private endpoint;
14
+ private headers;
15
+ constructor(endpoint: string, headers?: Record<string, string>);
16
+ execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
17
+ setHeaders(headers: Record<string, string>): void;
18
+ getEndpoint(): string;
19
+ }
20
+ /**
21
+ * Configuration for creating an ORM client.
22
+ * Either provide endpoint (and optional headers) for HTTP requests,
23
+ * or provide a custom adapter for alternative execution strategies.
24
+ */
25
+ export interface OrmClientConfig {
26
+ /** GraphQL endpoint URL (required if adapter not provided) */
27
+ endpoint?: string;
28
+ /** Default headers for HTTP requests (only used with endpoint) */
29
+ headers?: Record<string, string>;
30
+ /** Custom adapter for GraphQL execution (overrides endpoint/headers) */
31
+ adapter?: GraphQLAdapter;
32
+ }
33
+ /**
34
+ * Error thrown when GraphQL request fails
35
+ */
36
+ export declare class GraphQLRequestError extends Error {
37
+ readonly errors: GraphQLError[];
38
+ readonly data: unknown;
39
+ constructor(errors: GraphQLError[], data?: unknown);
40
+ }
41
+ export declare class OrmClient {
42
+ private adapter;
43
+ constructor(config: OrmClientConfig);
44
+ execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
45
+ /**
46
+ * Set headers for requests.
47
+ * Only works if the adapter supports headers.
48
+ */
49
+ setHeaders(headers: Record<string, string>): void;
50
+ /**
51
+ * Get the endpoint URL.
52
+ * Returns empty string if the adapter doesn't have an endpoint.
53
+ */
54
+ getEndpoint(): string;
55
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrmClient = exports.GraphQLRequestError = exports.FetchAdapter = void 0;
4
+ /**
5
+ * Default adapter that uses fetch for HTTP requests.
6
+ * This is used when no custom adapter is provided.
7
+ */
8
+ class FetchAdapter {
9
+ endpoint;
10
+ headers;
11
+ constructor(endpoint, headers) {
12
+ this.endpoint = endpoint;
13
+ this.headers = headers ?? {};
14
+ }
15
+ async execute(document, variables) {
16
+ const response = await fetch(this.endpoint, {
17
+ method: 'POST',
18
+ headers: {
19
+ 'Content-Type': 'application/json',
20
+ Accept: 'application/json',
21
+ ...this.headers,
22
+ },
23
+ body: JSON.stringify({
24
+ query: document,
25
+ variables: variables ?? {},
26
+ }),
27
+ });
28
+ if (!response.ok) {
29
+ return {
30
+ ok: false,
31
+ data: null,
32
+ errors: [{ message: `HTTP ${response.status}: ${response.statusText}` }],
33
+ };
34
+ }
35
+ const json = (await response.json());
36
+ if (json.errors && json.errors.length > 0) {
37
+ return {
38
+ ok: false,
39
+ data: null,
40
+ errors: json.errors,
41
+ };
42
+ }
43
+ return {
44
+ ok: true,
45
+ data: json.data,
46
+ errors: undefined,
47
+ };
48
+ }
49
+ setHeaders(headers) {
50
+ this.headers = { ...this.headers, ...headers };
51
+ }
52
+ getEndpoint() {
53
+ return this.endpoint;
54
+ }
55
+ }
56
+ exports.FetchAdapter = FetchAdapter;
57
+ /**
58
+ * Error thrown when GraphQL request fails
59
+ */
60
+ class GraphQLRequestError extends Error {
61
+ errors;
62
+ data;
63
+ constructor(errors, data = null) {
64
+ const messages = errors.map((e) => e.message).join('; ');
65
+ super(`GraphQL Error: ${messages}`);
66
+ this.errors = errors;
67
+ this.data = data;
68
+ this.name = 'GraphQLRequestError';
69
+ }
70
+ }
71
+ exports.GraphQLRequestError = GraphQLRequestError;
72
+ class OrmClient {
73
+ adapter;
74
+ constructor(config) {
75
+ if (config.adapter) {
76
+ this.adapter = config.adapter;
77
+ }
78
+ else if (config.endpoint) {
79
+ this.adapter = new FetchAdapter(config.endpoint, config.headers);
80
+ }
81
+ else {
82
+ throw new Error('OrmClientConfig requires either an endpoint or a custom adapter');
83
+ }
84
+ }
85
+ async execute(document, variables) {
86
+ return this.adapter.execute(document, variables);
87
+ }
88
+ /**
89
+ * Set headers for requests.
90
+ * Only works if the adapter supports headers.
91
+ */
92
+ setHeaders(headers) {
93
+ if (this.adapter.setHeaders) {
94
+ this.adapter.setHeaders(headers);
95
+ }
96
+ }
97
+ /**
98
+ * Get the endpoint URL.
99
+ * Returns empty string if the adapter doesn't have an endpoint.
100
+ */
101
+ getEndpoint() {
102
+ return this.adapter.getEndpoint?.() ?? '';
103
+ }
104
+ }
105
+ exports.OrmClient = OrmClient;
@@ -0,0 +1,48 @@
1
+ import type { OrmClientConfig } from './client';
2
+ import { MigrateFileModel } from './models/migrateFile';
3
+ import { SqlActionModel } from './models/sqlAction';
4
+ export type { OrmClientConfig, QueryResult, GraphQLError, GraphQLAdapter } from './client';
5
+ export { GraphQLRequestError } from './client';
6
+ export { QueryBuilder } from './query-builder';
7
+ export * from './select-types';
8
+ export * from './models';
9
+ export { createMutationOperations } from './mutation';
10
+ /**
11
+ * Create an ORM client instance
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const db = createClient({
16
+ * endpoint: 'https://api.example.com/graphql',
17
+ * headers: { Authorization: 'Bearer token' },
18
+ * });
19
+ *
20
+ * // Query users
21
+ * const users = await db.user.findMany({
22
+ * select: { id: true, name: true },
23
+ * first: 10,
24
+ * }).execute();
25
+ *
26
+ * // Create a user
27
+ * const newUser = await db.user.create({
28
+ * data: { name: 'John', email: 'john@example.com' },
29
+ * select: { id: true },
30
+ * }).execute();
31
+ * ```
32
+ */
33
+ export declare function createClient(config: OrmClientConfig): {
34
+ migrateFile: MigrateFileModel;
35
+ sqlAction: SqlActionModel;
36
+ mutation: {
37
+ executeSql: <S extends import("./input-types").ExecuteSqlPayloadSelect>(args: import("./mutation").ExecuteSqlVariables, options: {
38
+ select: S;
39
+ } & import("./select-types").StrictSelect<S, import("./input-types").ExecuteSqlPayloadSelect>) => import("./query-builder").QueryBuilder<{
40
+ executeSql: import("./select-types").InferSelectResult<import("./input-types").ExecuteSqlPayload, S> | null;
41
+ }>;
42
+ runMigration: <S extends import("./input-types").RunMigrationPayloadSelect>(args: import("./mutation").RunMigrationVariables, options: {
43
+ select: S;
44
+ } & import("./select-types").StrictSelect<S, import("./input-types").RunMigrationPayloadSelect>) => import("./query-builder").QueryBuilder<{
45
+ runMigration: import("./select-types").InferSelectResult<import("./input-types").RunMigrationPayload, S> | null;
46
+ }>;
47
+ };
48
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.createMutationOperations = exports.QueryBuilder = exports.GraphQLRequestError = void 0;
18
+ exports.createClient = createClient;
19
+ /**
20
+ * ORM Client - createClient factory
21
+ * @generated by @constructive-io/graphql-codegen
22
+ * DO NOT EDIT - changes will be overwritten
23
+ */
24
+ const client_1 = require("./client");
25
+ const migrateFile_1 = require("./models/migrateFile");
26
+ const sqlAction_1 = require("./models/sqlAction");
27
+ const mutation_1 = require("./mutation");
28
+ var client_2 = require("./client");
29
+ Object.defineProperty(exports, "GraphQLRequestError", { enumerable: true, get: function () { return client_2.GraphQLRequestError; } });
30
+ var query_builder_1 = require("./query-builder");
31
+ Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return query_builder_1.QueryBuilder; } });
32
+ __exportStar(require("./select-types"), exports);
33
+ __exportStar(require("./models"), exports);
34
+ var mutation_2 = require("./mutation");
35
+ Object.defineProperty(exports, "createMutationOperations", { enumerable: true, get: function () { return mutation_2.createMutationOperations; } });
36
+ /**
37
+ * Create an ORM client instance
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const db = createClient({
42
+ * endpoint: 'https://api.example.com/graphql',
43
+ * headers: { Authorization: 'Bearer token' },
44
+ * });
45
+ *
46
+ * // Query users
47
+ * const users = await db.user.findMany({
48
+ * select: { id: true, name: true },
49
+ * first: 10,
50
+ * }).execute();
51
+ *
52
+ * // Create a user
53
+ * const newUser = await db.user.create({
54
+ * data: { name: 'John', email: 'john@example.com' },
55
+ * select: { id: true },
56
+ * }).execute();
57
+ * ```
58
+ */
59
+ function createClient(config) {
60
+ const client = new client_1.OrmClient(config);
61
+ return {
62
+ migrateFile: new migrateFile_1.MigrateFileModel(client),
63
+ sqlAction: new sqlAction_1.SqlActionModel(client),
64
+ mutation: (0, mutation_1.createMutationOperations)(client),
65
+ };
66
+ }