@gqlbase/plugins 0.0.1 → 0.0.4

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 (68) hide show
  1. package/dist/base/ModelPlugin/ModelPlugin.d.ts +97 -0
  2. package/dist/base/ModelPlugin/ModelPlugin.d.ts.map +1 -0
  3. package/dist/base/ModelPlugin/ModelPlugin.js +405 -0
  4. package/dist/base/ModelPlugin/ModelPlugin.js.map +1 -0
  5. package/dist/base/ModelPlugin/ModelPlugin.utils.d.ts +31 -0
  6. package/dist/base/ModelPlugin/ModelPlugin.utils.d.ts.map +1 -0
  7. package/dist/base/ModelPlugin/ModelPlugin.utils.js +57 -0
  8. package/dist/base/ModelPlugin/ModelPlugin.utils.js.map +1 -0
  9. package/dist/base/ModelPlugin/index.d.ts +3 -0
  10. package/dist/base/ModelPlugin/index.d.ts.map +1 -0
  11. package/dist/base/ModelPlugin/index.js +3 -0
  12. package/dist/base/ModelPlugin/index.js.map +1 -0
  13. package/dist/base/RelationsPlugin/RelationsPlugin.d.ts +60 -0
  14. package/dist/base/RelationsPlugin/RelationsPlugin.d.ts.map +1 -0
  15. package/dist/base/RelationsPlugin/RelationsPlugin.js +188 -0
  16. package/dist/base/RelationsPlugin/RelationsPlugin.js.map +1 -0
  17. package/dist/base/RelationsPlugin/RelationsPlugin.utils.d.ts +19 -0
  18. package/dist/base/RelationsPlugin/RelationsPlugin.utils.d.ts.map +1 -0
  19. package/dist/base/RelationsPlugin/RelationsPlugin.utils.js +30 -0
  20. package/dist/base/RelationsPlugin/RelationsPlugin.utils.js.map +1 -0
  21. package/dist/base/RelationsPlugin/index.d.ts +3 -0
  22. package/dist/base/RelationsPlugin/index.d.ts.map +1 -0
  23. package/dist/base/RelationsPlugin/index.js +3 -0
  24. package/dist/base/RelationsPlugin/index.js.map +1 -0
  25. package/dist/base/SchemaGeneratorPlugin.d.ts +7 -0
  26. package/dist/base/SchemaGeneratorPlugin.d.ts.map +1 -0
  27. package/dist/base/SchemaGeneratorPlugin.js +13 -0
  28. package/dist/base/SchemaGeneratorPlugin.js.map +1 -0
  29. package/dist/base/UtilitiesPlugin/UtilitiesPlugin.d.ts +17 -0
  30. package/dist/base/UtilitiesPlugin/UtilitiesPlugin.d.ts.map +1 -0
  31. package/dist/base/UtilitiesPlugin/UtilitiesPlugin.js +66 -0
  32. package/dist/base/UtilitiesPlugin/UtilitiesPlugin.js.map +1 -0
  33. package/dist/base/UtilitiesPlugin/UtilitiesPlugin.utils.d.ts +25 -0
  34. package/dist/base/UtilitiesPlugin/UtilitiesPlugin.utils.d.ts.map +1 -0
  35. package/dist/base/UtilitiesPlugin/UtilitiesPlugin.utils.js +38 -0
  36. package/dist/base/UtilitiesPlugin/UtilitiesPlugin.utils.js.map +1 -0
  37. package/dist/base/UtilitiesPlugin/index.d.ts +3 -0
  38. package/dist/base/UtilitiesPlugin/index.d.ts.map +1 -0
  39. package/dist/base/UtilitiesPlugin/index.js +3 -0
  40. package/dist/base/UtilitiesPlugin/index.js.map +1 -0
  41. package/dist/base/basePreset.d.ts +13 -0
  42. package/dist/base/basePreset.d.ts.map +1 -0
  43. package/dist/base/basePreset.js +19 -0
  44. package/dist/base/basePreset.js.map +1 -0
  45. package/dist/base/index.d.ts +5 -1
  46. package/dist/base/index.d.ts.map +1 -1
  47. package/dist/base/index.js +6 -1
  48. package/dist/base/index.js.map +1 -0
  49. package/dist/relay/ConnectionPlugin.d.ts +46 -0
  50. package/dist/relay/ConnectionPlugin.d.ts.map +1 -0
  51. package/dist/relay/ConnectionPlugin.js +200 -0
  52. package/dist/relay/ConnectionPlugin.js.map +1 -0
  53. package/dist/relay/NodeInterfacePlugin.d.ts +20 -0
  54. package/dist/relay/NodeInterfacePlugin.d.ts.map +1 -0
  55. package/dist/relay/NodeInterfacePlugin.js +84 -0
  56. package/dist/relay/NodeInterfacePlugin.js.map +1 -0
  57. package/dist/relay/index.d.ts +3 -0
  58. package/dist/relay/index.d.ts.map +1 -0
  59. package/dist/relay/index.js +3 -0
  60. package/dist/relay/index.js.map +1 -0
  61. package/dist/relay/relayPreset.d.ts +11 -0
  62. package/dist/relay/relayPreset.d.ts.map +1 -0
  63. package/dist/relay/relayPreset.js +15 -0
  64. package/dist/relay/relayPreset.js.map +1 -0
  65. package/package.json +3 -3
  66. package/dist/base/ModelPlugin.d.ts +0 -59
  67. package/dist/base/ModelPlugin.d.ts.map +0 -1
  68. package/dist/base/ModelPlugin.js +0 -222
@@ -0,0 +1,60 @@
1
+ import { ITransformerContext, ITransformerPlugin } from "@gqlbase/core";
2
+ import { DefinitionNode, InterfaceNode, ObjectNode } from "@gqlbase/core/definition";
3
+ import { RelationPluginOptions } from "./RelationsPlugin.utils.js";
4
+ /**
5
+ * This plugin is responsible for adding the `@hasOne` and `@hasMany` directives to the schema, which can be used to define relationships between types. It also adds the necessary fields and arguments to the schema to support these directives.
6
+ *
7
+ * @example
8
+ *
9
+ * ```graphql
10
+ *
11
+ * # Before
12
+ * type User {
13
+ * id: ID!
14
+ * name: String!
15
+ * posts: Post `@hasMany(key: "authorId")`
16
+ * }
17
+ *
18
+ * type Post {
19
+ * id: ID!
20
+ * title: String!
21
+ * author: User `@hasOne`
22
+ * }
23
+ *
24
+ * # After
25
+ * type User {
26
+ * id: ID!
27
+ * name: String!
28
+ * posts: [Post]
29
+ * }
30
+ *
31
+ * type Post {
32
+ * id: ID!
33
+ * title: String!
34
+ * authorId: ID
35
+ * author: User
36
+ * }
37
+ * ```
38
+ *
39
+ * In the above example, the `User` type has a `posts` field that is decorated with the `@hasMany` directive, indicating that a user can have many posts. The plugin will automatically add the necessary fields and arguments to support this relationship in the schema.
40
+ *
41
+ */
42
+ export declare class RelationsPlugin implements ITransformerPlugin {
43
+ readonly name = "RelationsPlugin";
44
+ readonly context: ITransformerContext;
45
+ private readonly _useConnections;
46
+ constructor(context: ITransformerContext, options?: RelationPluginOptions);
47
+ private _getRelationshipTarget;
48
+ private _getFieldRelation;
49
+ private _setRelationKey;
50
+ private _setConnectionArguments;
51
+ private _createFieldConnection;
52
+ init(): void;
53
+ match(definition: DefinitionNode): boolean;
54
+ normalize(definition: ObjectNode | InterfaceNode): void;
55
+ execute(definition: ObjectNode | InterfaceNode): void;
56
+ cleanup(definition: ObjectNode | InterfaceNode): void;
57
+ after(): void;
58
+ }
59
+ export declare const relationPlugin: (options?: RelationPluginOptions | undefined) => import("@gqlbase/core").IPluginFactory;
60
+ //# sourceMappingURL=RelationsPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelationsPlugin.d.ts","sourceRoot":"","sources":["../../../src/base/RelationsPlugin/RelationsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7F,OAAO,EACL,cAAc,EAId,aAAa,EAGb,UAAU,EAEX,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAQL,qBAAqB,EACtB,MAAM,4BAA4B,CAAC;AAGpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,qBAAa,eAAgB,YAAW,kBAAkB;IACxD,QAAQ,CAAC,IAAI,qBAAqB;IAClC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;gBAGxC,OAAO,EAAE,mBAAmB,EAC5B,OAAO,GAAE,qBAAiD;IAM5D,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,iBAAiB;IAmDzB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,sBAAsB;IAiBvB,IAAI;IAkBJ,KAAK,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO;IAW1C,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa,GAAG,IAAI;IAiC9D,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa,GAAG,IAAI;IAoB9C,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa,GAAG,IAAI;IAY5D,KAAK,IAAI,IAAI;CAKd;AAED,eAAO,MAAM,cAAc,yFAAuC,CAAC"}
@@ -0,0 +1,188 @@
1
+ import { createPluginFactory } from "@gqlbase/core";
2
+ import { DirectiveDefinitionNode, FieldNode, InputValueNode, InterfaceNode, ListTypeNode, NamedTypeNode, ObjectNode, UnionNode, } from "@gqlbase/core/definition";
3
+ import { TransformerPluginExecutionError } from "@gqlbase/shared/errors";
4
+ import { camelCase, pascalCase } from "@gqlbase/shared/format";
5
+ import { isConnectionNode, isManyRelationship, isOneRelationship, isRelationField, isValidRelationTarget, RelationDirective, } from "./RelationsPlugin.utils.js";
6
+ import { isListTypeNode } from "../ModelPlugin/ModelPlugin.utils.js";
7
+ /**
8
+ * This plugin is responsible for adding the `@hasOne` and `@hasMany` directives to the schema, which can be used to define relationships between types. It also adds the necessary fields and arguments to the schema to support these directives.
9
+ *
10
+ * @example
11
+ *
12
+ * ```graphql
13
+ *
14
+ * # Before
15
+ * type User {
16
+ * id: ID!
17
+ * name: String!
18
+ * posts: Post `@hasMany(key: "authorId")`
19
+ * }
20
+ *
21
+ * type Post {
22
+ * id: ID!
23
+ * title: String!
24
+ * author: User `@hasOne`
25
+ * }
26
+ *
27
+ * # After
28
+ * type User {
29
+ * id: ID!
30
+ * name: String!
31
+ * posts: [Post]
32
+ * }
33
+ *
34
+ * type Post {
35
+ * id: ID!
36
+ * title: String!
37
+ * authorId: ID
38
+ * author: User
39
+ * }
40
+ * ```
41
+ *
42
+ * In the above example, the `User` type has a `posts` field that is decorated with the `@hasMany` directive, indicating that a user can have many posts. The plugin will automatically add the necessary fields and arguments to support this relationship in the schema.
43
+ *
44
+ */
45
+ export class RelationsPlugin {
46
+ name = "RelationsPlugin";
47
+ context;
48
+ _useConnections;
49
+ constructor(context, options = { useConnections: false }) {
50
+ this.context = context;
51
+ this._useConnections = options.useConnections ?? false;
52
+ }
53
+ _getRelationshipTarget(field) {
54
+ const fieldType = this.context.document.getNode(field.type.getTypeName());
55
+ if (isRelationField(field)) {
56
+ return fieldType;
57
+ }
58
+ return undefined;
59
+ }
60
+ _getFieldRelation(object, field) {
61
+ const target = this._getRelationshipTarget(field);
62
+ if (!target)
63
+ return null;
64
+ if (!isValidRelationTarget(target)) {
65
+ throw new TransformerPluginExecutionError(this.name, `Type ${target.name} is not a valid relationship target for ${object.name}.${field.name}`);
66
+ }
67
+ let directive = field.getDirective(RelationDirective.HAS_ONE);
68
+ if (directive) {
69
+ if (field.hasDirective(RelationDirective.HAS_MANY)) {
70
+ throw new TransformerPluginExecutionError(this.name, `Multiple relationship directives detected for ${object.name}.${field.name}`);
71
+ }
72
+ const args = directive.getArgumentsJSON();
73
+ return {
74
+ type: "oneToOne",
75
+ target: target,
76
+ key: args.key ?? camelCase(field.name, "id"),
77
+ };
78
+ }
79
+ directive = field.getDirective(RelationDirective.HAS_MANY);
80
+ if (directive) {
81
+ const args = directive.getArgumentsJSON();
82
+ return {
83
+ type: "oneToMany",
84
+ target: target,
85
+ key: args.key ?? camelCase(object.name, "id"),
86
+ };
87
+ }
88
+ throw new TransformerPluginExecutionError(this.name, `Could not find connection directive: ${field.name}`);
89
+ }
90
+ _setRelationKey(node, key) {
91
+ if (!node.hasField(key)) {
92
+ node.addField(FieldNode.create(key, NamedTypeNode.create("ID")));
93
+ }
94
+ }
95
+ _setConnectionArguments(field) {
96
+ if (!field.hasArgument("limit")) {
97
+ field.addArgument(InputValueNode.create("limit", NamedTypeNode.create("Int")));
98
+ }
99
+ if (!field.hasArgument("nextToken")) {
100
+ field.addArgument(InputValueNode.create("nextToken", NamedTypeNode.create("String")));
101
+ }
102
+ }
103
+ _createFieldConnection(field, target) {
104
+ this._setConnectionArguments(field);
105
+ if (isConnectionNode(target)) {
106
+ return target;
107
+ }
108
+ const connectionTypeName = pascalCase(target.name, "Connection");
109
+ return this.context.document.getOrCreateNode(connectionTypeName, ObjectNode.create(connectionTypeName)
110
+ .addField(FieldNode.create("items", ListTypeNode.create(NamedTypeNode.create(target.name))))
111
+ .addField(FieldNode.create("nextToken", NamedTypeNode.create("String"))));
112
+ }
113
+ init() {
114
+ this.context.base
115
+ .addNode(DirectiveDefinitionNode.create(RelationDirective.HAS_ONE, ["FIELD_DEFINITION"], [InputValueNode.create("key", "String")]))
116
+ .addNode(DirectiveDefinitionNode.create(RelationDirective.HAS_MANY, ["FIELD_DEFINITION"], [InputValueNode.create("key", "String")]));
117
+ }
118
+ match(definition) {
119
+ if (definition instanceof InterfaceNode || definition instanceof ObjectNode) {
120
+ if (definition.name === "Mutation")
121
+ return false;
122
+ if (isConnectionNode(definition))
123
+ return false;
124
+ if (!definition.fields?.length)
125
+ return false;
126
+ return true;
127
+ }
128
+ return false;
129
+ }
130
+ normalize(definition) {
131
+ for (const field of definition.fields ?? []) {
132
+ const relation = this._getFieldRelation(definition, field);
133
+ if (!relation) {
134
+ continue;
135
+ }
136
+ if (relation.type === "oneToOne") {
137
+ this._setRelationKey(definition, relation.key);
138
+ continue;
139
+ }
140
+ if (relation.target instanceof UnionNode) {
141
+ for (const type of relation.target.types ?? []) {
142
+ const unionType = this.context.document.getNode(type.getTypeName());
143
+ if (unionType instanceof ObjectNode || unionType instanceof InterfaceNode) {
144
+ this._setRelationKey(unionType, relation.key);
145
+ continue;
146
+ }
147
+ throw new TransformerPluginExecutionError(this.name, `Invalid relation union target: ${relation.target.name}`);
148
+ }
149
+ }
150
+ else {
151
+ this._setRelationKey(relation.target, relation.key);
152
+ }
153
+ }
154
+ }
155
+ execute(definition) {
156
+ for (const field of definition.fields ?? []) {
157
+ const relation = this._getFieldRelation(definition, field);
158
+ if (!relation || relation.type === "oneToOne") {
159
+ continue;
160
+ }
161
+ if (this._useConnections) {
162
+ const connection = this._createFieldConnection(field, relation.target);
163
+ field.setType(NamedTypeNode.create(connection.name));
164
+ continue;
165
+ }
166
+ if (!isListTypeNode(field.type)) {
167
+ field.setType(ListTypeNode.create(field.type));
168
+ }
169
+ }
170
+ }
171
+ cleanup(definition) {
172
+ for (const field of definition.fields ?? []) {
173
+ if (isOneRelationship(field)) {
174
+ field.removeDirective(RelationDirective.HAS_ONE);
175
+ }
176
+ if (isManyRelationship(field)) {
177
+ field.removeDirective(RelationDirective.HAS_MANY);
178
+ }
179
+ }
180
+ }
181
+ after() {
182
+ this.context.document
183
+ .removeNode(RelationDirective.HAS_ONE)
184
+ .removeNode(RelationDirective.HAS_MANY);
185
+ }
186
+ }
187
+ export const relationPlugin = createPluginFactory(RelationsPlugin);
188
+ //# sourceMappingURL=RelationsPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelationsPlugin.js","sourceRoot":"","sources":["../../../src/base/RelationsPlugin/RelationsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAA2C,MAAM,eAAe,CAAC;AAC7F,OAAO,EAEL,uBAAuB,EACvB,SAAS,EACT,cAAc,EACd,aAAa,EACb,YAAY,EACZ,aAAa,EACb,UAAU,EACV,SAAS,GACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAEL,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,GAElB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,MAAM,OAAO,eAAe;IACjB,IAAI,GAAG,iBAAiB,CAAC;IACzB,OAAO,CAAsB;IACrB,eAAe,CAAU;IAE1C,YACE,OAA4B,EAC5B,UAAiC,EAAE,cAAc,EAAE,KAAK,EAAE;QAE1D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,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ED,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { DefinitionNode, FieldNode, InterfaceNode, ObjectNode, UnionNode } from "@gqlbase/core/definition";
2
+ export interface RelationPluginOptions {
3
+ useConnections?: boolean;
4
+ }
5
+ export declare const RelationDirective: {
6
+ readonly HAS_ONE: "hasOne";
7
+ readonly HAS_MANY: "hasMany";
8
+ };
9
+ export interface FieldRelationship {
10
+ type: "oneToOne" | "oneToMany";
11
+ target: ObjectNode | InterfaceNode | UnionNode;
12
+ key?: string;
13
+ }
14
+ export declare const isOneRelationship: (field: FieldNode) => boolean;
15
+ export declare const isManyRelationship: (field: FieldNode) => boolean;
16
+ export declare const isRelationField: (field: FieldNode) => boolean;
17
+ export declare const isConnectionNode: (node: DefinitionNode) => boolean;
18
+ export declare const isValidRelationTarget: (node: DefinitionNode) => node is ObjectNode | InterfaceNode | UnionNode;
19
+ //# sourceMappingURL=RelationsPlugin.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelationsPlugin.utils.d.ts","sourceRoot":"","sources":["../../../src/base/RelationsPlugin/RelationsPlugin.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,aAAa,EACb,UAAU,EACV,SAAS,EACV,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,qBAAqB;IACpC,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;IAC/B,MAAM,EAAE,UAAU,GAAG,aAAa,GAAG,SAAS,CAAC;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,iBAAiB,GAAI,OAAO,SAAS,KAAG,OAEpD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,OAAO,SAAS,KAAG,OAErD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,OAAO,SAAS,KAAG,OAElD,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,MAAM,cAAc,KAAG,OASvD,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,MAAM,cAAc,KACnB,IAAI,IAAI,UAAU,GAAG,aAAa,GAAG,SAEvC,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { InterfaceNode, ObjectNode, UnionNode, } from "@gqlbase/core/definition";
2
+ export const RelationDirective = {
3
+ HAS_ONE: "hasOne",
4
+ HAS_MANY: "hasMany",
5
+ };
6
+ export const isOneRelationship = (field) => {
7
+ return field.hasDirective(RelationDirective.HAS_ONE);
8
+ };
9
+ export const isManyRelationship = (field) => {
10
+ return field.hasDirective(RelationDirective.HAS_MANY);
11
+ };
12
+ export const isRelationField = (field) => {
13
+ return isOneRelationship(field) || isManyRelationship(field);
14
+ };
15
+ export const isConnectionNode = (node) => {
16
+ if (node instanceof ObjectNode) {
17
+ if (!node.name.endsWith("Connection"))
18
+ return false;
19
+ if (!node.fields || node.fields.length < 2)
20
+ return false;
21
+ if (!node.hasField("items") || !node.hasField("nextToken"))
22
+ return false;
23
+ return true;
24
+ }
25
+ return false;
26
+ };
27
+ export const isValidRelationTarget = (node) => {
28
+ return node instanceof ObjectNode || node instanceof InterfaceNode || node instanceof UnionNode;
29
+ };
30
+ //# sourceMappingURL=RelationsPlugin.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelationsPlugin.utils.js","sourceRoot":"","sources":["../../../src/base/RelationsPlugin/RelationsPlugin.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACb,UAAU,EACV,SAAS,GACV,MAAM,0BAA0B,CAAC;AAMlC,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,SAAS;CACX,CAAC;AAQX,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAgB,EAAW,EAAE;IAC7D,OAAO,KAAK,CAAC,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAgB,EAAW,EAAE;IAC9D,OAAO,KAAK,CAAC,YAAY,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAgB,EAAW,EAAE;IAC3D,OAAO,iBAAiB,CAAC,KAAK,CAAC,IAAI,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAoB,EAAW,EAAE;IAChE,IAAI,IAAI,YAAY,UAAU,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;YAAE,OAAO,KAAK,CAAC;QACpD,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACzD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;YAAE,OAAO,KAAK,CAAC;QACzE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,IAAoB,EAC4B,EAAE;IAClD,OAAO,IAAI,YAAY,UAAU,IAAI,IAAI,YAAY,aAAa,IAAI,IAAI,YAAY,SAAS,CAAC;AAClG,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { RelationsPlugin, relationPlugin } from "./RelationsPlugin.js";
2
+ export { type RelationPluginOptions, type FieldRelationship, RelationDirective, isConnectionNode, isManyRelationship, isOneRelationship, isRelationField, isValidRelationTarget, } from "./RelationsPlugin.utils.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/base/RelationsPlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,GACtB,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { RelationsPlugin, relationPlugin } from "./RelationsPlugin.js";
2
+ export { RelationDirective, isConnectionNode, isManyRelationship, isOneRelationship, isRelationField, isValidRelationTarget, } from "./RelationsPlugin.utils.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/base/RelationsPlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAGL,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,GACtB,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { ITransformerContext, TransformerPluginBase } from "@gqlbase/core";
2
+ export declare class SchemaGeneratorPlugin extends TransformerPluginBase {
3
+ constructor(context: ITransformerContext);
4
+ generate(): void;
5
+ }
6
+ export declare const schemaGeneratorPlugin: (options?: unknown) => import("@gqlbase/core").IPluginFactory;
7
+ //# sourceMappingURL=SchemaGeneratorPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaGeneratorPlugin.d.ts","sourceRoot":"","sources":["../../src/base/SchemaGeneratorPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGhG,qBAAa,qBAAsB,SAAQ,qBAAqB;gBAClD,OAAO,EAAE,mBAAmB;IAIjC,QAAQ;CAIhB;AAED,eAAO,MAAM,qBAAqB,+DAA6C,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { createPluginFactory, TransformerPluginBase } from "@gqlbase/core";
2
+ import { writeOutputFile } from "@gqlbase/shared/files";
3
+ export class SchemaGeneratorPlugin extends TransformerPluginBase {
4
+ constructor(context) {
5
+ super("SchemaGeneratorPlugin", context);
6
+ }
7
+ generate() {
8
+ const schema = this.context.document.print();
9
+ writeOutputFile(this.context.outputDirectory, "schema.graphql", schema);
10
+ }
11
+ }
12
+ export const schemaGeneratorPlugin = createPluginFactory(SchemaGeneratorPlugin);
13
+ //# sourceMappingURL=SchemaGeneratorPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaGeneratorPlugin.js","sourceRoot":"","sources":["../../src/base/SchemaGeneratorPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAuB,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,OAAO,qBAAsB,SAAQ,qBAAqB;IAC9D,YAAY,OAA4B;QACtC,KAAK,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IAEM,QAAQ;QACb,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAC7C,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAC1E,CAAC;CACF;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,mBAAmB,CAAC,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { ITransformerContext } from "@gqlbase/core/context";
2
+ import { ITransformerPlugin } from "@gqlbase/core/plugins";
3
+ import { DefinitionNode, InterfaceNode, ObjectNode } from "@gqlbase/core/definition";
4
+ /**
5
+ * Adds utility directives to the schema that can be used to mark fields as server-only, client-only, read-only, write-only, filter-only, create-only, or update-only.
6
+ */
7
+ export declare class UtilitiesPlugin implements ITransformerPlugin {
8
+ readonly name = "UtilitiesPlugin";
9
+ readonly context: ITransformerContext;
10
+ constructor(context: ITransformerContext);
11
+ init(): void;
12
+ match(definition: DefinitionNode): boolean;
13
+ cleanup(definition: ObjectNode | InterfaceNode): void;
14
+ after(): void;
15
+ }
16
+ export declare const utilsPlugin: (options?: unknown) => import("@gqlbase/core/plugins").IPluginFactory;
17
+ //# sourceMappingURL=UtilitiesPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UtilitiesPlugin.d.ts","sourceRoot":"","sources":["../../../src/base/UtilitiesPlugin/UtilitiesPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAuB,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EACL,cAAc,EAEd,aAAa,EACb,UAAU,EACX,MAAM,0BAA0B,CAAC;AAGlC;;GAEG;AAEH,qBAAa,eAAgB,YAAW,kBAAkB;IACxD,SAAgB,IAAI,qBAAqB;IACzC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;gBAE1B,OAAO,EAAE,mBAAmB;IAIjC,IAAI,IAAI,IAAI;IAWZ,KAAK,CAAC,UAAU,EAAE,cAAc;IAQhC,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa,GAAG,IAAI;IAgCrD,KAAK,IAAI,IAAI;CAUrB;AAED,eAAO,MAAM,WAAW,uEAAuC,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { createPluginFactory } from "@gqlbase/core/plugins";
2
+ import { DirectiveDefinitionNode, InterfaceNode, ObjectNode, } from "@gqlbase/core/definition";
3
+ import { UtilityDirective } from "./UtilitiesPlugin.utils.js";
4
+ /**
5
+ * Adds utility directives to the schema that can be used to mark fields as server-only, client-only, read-only, write-only, filter-only, create-only, or update-only.
6
+ */
7
+ export class UtilitiesPlugin {
8
+ name = "UtilitiesPlugin";
9
+ context;
10
+ constructor(context) {
11
+ this.context = context;
12
+ }
13
+ init() {
14
+ this.context.base
15
+ .addNode(DirectiveDefinitionNode.create(UtilityDirective.READ_ONLY, ["FIELD_DEFINITION"]))
16
+ .addNode(DirectiveDefinitionNode.create(UtilityDirective.WRITE_ONLY, ["FIELD_DEFINITION"]))
17
+ .addNode(DirectiveDefinitionNode.create(UtilityDirective.SERVER_ONLY, ["FIELD_DEFINITION"]))
18
+ .addNode(DirectiveDefinitionNode.create(UtilityDirective.CLIENT_ONLY, ["FIELD_DEFINITION"]))
19
+ .addNode(DirectiveDefinitionNode.create(UtilityDirective.FILTER_ONLY, ["FIELD_DEFINITION"]))
20
+ .addNode(DirectiveDefinitionNode.create(UtilityDirective.CREATE_ONLY, ["FIELD_DEFINITION"]))
21
+ .addNode(DirectiveDefinitionNode.create(UtilityDirective.UPDATE_ONLY, ["FIELD_DEFINITION"]));
22
+ }
23
+ match(definition) {
24
+ if (definition instanceof ObjectNode || definition instanceof InterfaceNode) {
25
+ return true;
26
+ }
27
+ return false;
28
+ }
29
+ cleanup(definition) {
30
+ for (const field of definition.fields ?? []) {
31
+ if (field.hasDirective(UtilityDirective.READ_ONLY)) {
32
+ field.removeDirective(UtilityDirective.READ_ONLY);
33
+ }
34
+ if (field.hasDirective(UtilityDirective.CLIENT_ONLY)) {
35
+ field.removeDirective(UtilityDirective.CLIENT_ONLY);
36
+ }
37
+ if (field.hasDirective(UtilityDirective.FILTER_ONLY)) {
38
+ definition.removeField(field.name);
39
+ }
40
+ if (field.hasDirective(UtilityDirective.CREATE_ONLY)) {
41
+ definition.removeField(field.name);
42
+ }
43
+ if (field.hasDirective(UtilityDirective.UPDATE_ONLY)) {
44
+ definition.removeField(field.name);
45
+ }
46
+ if (field.hasDirective(UtilityDirective.WRITE_ONLY)) {
47
+ definition.removeField(field.name);
48
+ }
49
+ if (field.hasDirective(UtilityDirective.SERVER_ONLY)) {
50
+ definition.removeField(field.name);
51
+ }
52
+ }
53
+ }
54
+ after() {
55
+ this.context.document
56
+ .removeNode(UtilityDirective.READ_ONLY)
57
+ .removeNode(UtilityDirective.WRITE_ONLY)
58
+ .removeNode(UtilityDirective.SERVER_ONLY)
59
+ .removeNode(UtilityDirective.CLIENT_ONLY)
60
+ .removeNode(UtilityDirective.FILTER_ONLY)
61
+ .removeNode(UtilityDirective.CREATE_ONLY)
62
+ .removeNode(UtilityDirective.UPDATE_ONLY);
63
+ }
64
+ }
65
+ export const utilsPlugin = createPluginFactory(UtilitiesPlugin);
66
+ //# sourceMappingURL=UtilitiesPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UtilitiesPlugin.js","sourceRoot":"","sources":["../../../src/base/UtilitiesPlugin/UtilitiesPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAsB,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAEL,uBAAuB,EACvB,aAAa,EACb,UAAU,GACX,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;GAEG;AAEH,MAAM,OAAO,eAAe;IACV,IAAI,GAAG,iBAAiB,CAAC;IAChC,OAAO,CAAsB;IAEtC,YAAY,OAA4B;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,IAAI;QACT,IAAI,CAAC,OAAO,CAAC,IAAI;aACd,OAAO,CAAC,uBAAuB,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC;aACzF,OAAO,CAAC,uBAAuB,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC,kBAAkB,CAAC,C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I,CAAC,CAAC;YACrC,CAAC;YAED,IAAI,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAAE,CAAC;gBACrD,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;YAED,IAAI,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAAE,CAAC;gBACrD,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;YAED,IAAI,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;gBACpD,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;YAED,IAAI,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAAE,CAAC;gBACrD,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;IACH,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,OAAO,CAAC,QAAQ;aAClB,UAAU,CAAC,gBAAgB,CAAC,SAAS,CAAC;aACtC,UAAU,CAAC,gBAAgB,CAAC,UAAU,CAAC;aACvC,UAAU,CAAC,gBAAgB,CAAC,WAAW,CAAC;aACxC,UAAU,CAAC,gBAAgB,CAAC,WAAW,CAAC;aACxC,UAAU,CAAC,gBAAgB,CAAC,WAAW,CAAC;aACxC,UAAU,CAAC,gBAAgB,CAAC,WAAW,CAAC;aACxC,UAAU,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;CACF;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { FieldNode } from "@gqlbase/core/definition";
2
+ export declare const UtilityDirective: {
3
+ /** @serverOnly Marks a field as server-only, meaning it should only be resolved on the server and not exposed to the client. The field will be removed from the final schema */
4
+ readonly SERVER_ONLY: "serverOnly";
5
+ /** @clientOnly Marks a field as client-only, meaning it will be resolved at runtime. This field does not get added to inputs. */
6
+ readonly CLIENT_ONLY: "clientOnly";
7
+ /** @readOnly Marks a field as read-only, meaning it will be included in the schema but cannot be modified by the user. This field does not get added to inputs. */
8
+ readonly READ_ONLY: "readOnly";
9
+ /** @writeOnly Marks a field as write-only, meaning it will only be available in inputs. */
10
+ readonly WRITE_ONLY: "writeOnly";
11
+ /** @filterOnly Marks a field as filter-only, meaning it will only be available in the filter input */
12
+ readonly FILTER_ONLY: "filterOnly";
13
+ /** @createOnly Marks a field as create-only, meaning it will only be available in the create input */
14
+ readonly CREATE_ONLY: "createOnly";
15
+ /** @updateOnly Marks a field as update-only, meaning it will only be available in the update input */
16
+ readonly UPDATE_ONLY: "updateOnly";
17
+ };
18
+ export declare const isReadOnly: (node: FieldNode) => boolean;
19
+ export declare const isWriteOnly: (node: FieldNode) => boolean;
20
+ export declare const isServerOnly: (node: FieldNode) => boolean;
21
+ export declare const isClientOnly: (node: FieldNode) => boolean;
22
+ export declare const isFilterOnly: (node: FieldNode) => boolean;
23
+ export declare const isCreateOnly: (node: FieldNode) => boolean;
24
+ export declare const isUpdateOnly: (node: FieldNode) => boolean;
25
+ //# sourceMappingURL=UtilitiesPlugin.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UtilitiesPlugin.utils.d.ts","sourceRoot":"","sources":["../../../src/base/UtilitiesPlugin/UtilitiesPlugin.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,eAAO,MAAM,gBAAgB;IAC3B,gLAAgL;;IAGhL,iIAAiI;;IAGjI,mKAAmK;;IAGnK,2FAA2F;;IAG3F,sGAAsG;;IAGtG,sGAAsG;;IAGtG,sGAAsG;;CAE9F,CAAC;AAEX,eAAO,MAAM,UAAU,GAAI,MAAM,SAAS,KAAG,OAE5C,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,KAAG,OAE7C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,MAAM,SAAS,KAAG,OAE9C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,MAAM,SAAS,KAAG,OAE9C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,MAAM,SAAS,KAAG,OAE9C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,MAAM,SAAS,KAAG,OAE9C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,MAAM,SAAS,KAAG,OAE9C,CAAC"}
@@ -0,0 +1,38 @@
1
+ export const UtilityDirective = {
2
+ /** @serverOnly Marks a field as server-only, meaning it should only be resolved on the server and not exposed to the client. The field will be removed from the final schema */
3
+ SERVER_ONLY: "serverOnly",
4
+ /** @clientOnly Marks a field as client-only, meaning it will be resolved at runtime. This field does not get added to inputs. */
5
+ CLIENT_ONLY: "clientOnly",
6
+ /** @readOnly Marks a field as read-only, meaning it will be included in the schema but cannot be modified by the user. This field does not get added to inputs. */
7
+ READ_ONLY: "readOnly",
8
+ /** @writeOnly Marks a field as write-only, meaning it will only be available in inputs. */
9
+ WRITE_ONLY: "writeOnly",
10
+ /** @filterOnly Marks a field as filter-only, meaning it will only be available in the filter input */
11
+ FILTER_ONLY: "filterOnly",
12
+ /** @createOnly Marks a field as create-only, meaning it will only be available in the create input */
13
+ CREATE_ONLY: "createOnly",
14
+ /** @updateOnly Marks a field as update-only, meaning it will only be available in the update input */
15
+ UPDATE_ONLY: "updateOnly",
16
+ };
17
+ export const isReadOnly = (node) => {
18
+ return node.hasDirective(UtilityDirective.READ_ONLY);
19
+ };
20
+ export const isWriteOnly = (node) => {
21
+ return node.hasDirective(UtilityDirective.WRITE_ONLY);
22
+ };
23
+ export const isServerOnly = (node) => {
24
+ return node.hasDirective(UtilityDirective.SERVER_ONLY);
25
+ };
26
+ export const isClientOnly = (node) => {
27
+ return node.hasDirective(UtilityDirective.CLIENT_ONLY);
28
+ };
29
+ export const isFilterOnly = (node) => {
30
+ return node.hasDirective(UtilityDirective.FILTER_ONLY);
31
+ };
32
+ export const isCreateOnly = (node) => {
33
+ return node.hasDirective(UtilityDirective.CREATE_ONLY);
34
+ };
35
+ export const isUpdateOnly = (node) => {
36
+ return node.hasDirective(UtilityDirective.UPDATE_ONLY);
37
+ };
38
+ //# sourceMappingURL=UtilitiesPlugin.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UtilitiesPlugin.utils.js","sourceRoot":"","sources":["../../../src/base/UtilitiesPlugin/UtilitiesPlugin.utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,gLAAgL;IAChL,WAAW,EAAE,YAAY;IAEzB,iIAAiI;IACjI,WAAW,EAAE,YAAY;IAEzB,mKAAmK;IACnK,SAAS,EAAE,UAAU;IAErB,2FAA2F;IAC3F,UAAU,EAAE,WAAW;IAEvB,sGAAsG;IACtG,WAAW,EAAE,YAAY;IAEzB,sGAAsG;IACtG,WAAW,EAAE,YAAY;IAEzB,sGAAsG;IACtG,WAAW,EAAE,YAAY;CACjB,CAAC;AAEX,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAe,EAAW,EAAE;IACrD,OAAO,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAe,EAAW,EAAE;IACtD,OAAO,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAe,EAAW,EAAE;IACvD,OAAO,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAe,EAAW,EAAE;IACvD,OAAO,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAe,EAAW,EAAE;IACvD,OAAO,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAe,EAAW,EAAE;IACvD,OAAO,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAe,EAAW,EAAE;IACvD,OAAO,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACzD,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { UtilitiesPlugin, utilsPlugin } from "./UtilitiesPlugin.js";
2
+ export { UtilityDirective, isReadOnly, isClientOnly, isCreateOnly, isFilterOnly, isServerOnly, isUpdateOnly, isWriteOnly, } from "./UtilitiesPlugin.utils.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/base/UtilitiesPlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { UtilitiesPlugin, utilsPlugin } from "./UtilitiesPlugin.js";
2
+ export { UtilityDirective, isReadOnly, isClientOnly, isCreateOnly, isFilterOnly, isServerOnly, isUpdateOnly, isWriteOnly, } from "./UtilitiesPlugin.utils.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/base/UtilitiesPlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A preset that includes all the base plugins
3
+ *
4
+ * Inludes:
5
+ * - `UtilitiesPlugin`
6
+ * - `ModelPlugin`
7
+ * - `RelationsPlugin`
8
+ * - `SchemaGeneratorPlugin`
9
+ *
10
+ * @returns An array of plugin factories for the base plugins.
11
+ */
12
+ export declare function basePreset(): import("@gqlbase/core").IPluginFactory[];
13
+ //# sourceMappingURL=basePreset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basePreset.d.ts","sourceRoot":"","sources":["../../src/base/basePreset.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AAEH,wBAAgB,UAAU,6CAEzB"}
@@ -0,0 +1,19 @@
1
+ import { utilsPlugin } from "./UtilitiesPlugin/index.js";
2
+ import { modelPlugin } from "./ModelPlugin/index.js";
3
+ import { relationPlugin } from "./RelationsPlugin/index.js";
4
+ import { schemaGeneratorPlugin } from "./SchemaGeneratorPlugin.js";
5
+ /**
6
+ * A preset that includes all the base plugins
7
+ *
8
+ * Inludes:
9
+ * - `UtilitiesPlugin`
10
+ * - `ModelPlugin`
11
+ * - `RelationsPlugin`
12
+ * - `SchemaGeneratorPlugin`
13
+ *
14
+ * @returns An array of plugin factories for the base plugins.
15
+ */
16
+ export function basePreset() {
17
+ return [utilsPlugin(), modelPlugin(), relationPlugin(), schemaGeneratorPlugin()];
18
+ }
19
+ //# sourceMappingURL=basePreset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basePreset.js","sourceRoot":"","sources":["../../src/base/basePreset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;;;;;;;GAUG;AAEH,MAAM,UAAU,UAAU;IACxB,OAAO,CAAC,WAAW,EAAE,EAAE,WAAW,EAAE,EAAE,cAAc,EAAE,EAAE,qBAAqB,EAAE,CAAC,CAAC;AACnF,CAAC"}
@@ -1,2 +1,6 @@
1
- export { modelPlugin, isModel, ModelPlugin, type ModelPluginOptions, ModelOperation, ModelDirective, } from "./ModelPlugin.js";
1
+ export { ModelPlugin, type ModelPluginOptions, ModelDirective, ModelOperation, modelPlugin, isModel, } from "./ModelPlugin/index.js";
2
+ export { RelationsPlugin, relationPlugin, RelationDirective, isRelationField, isOneRelationship, isManyRelationship, type FieldRelationship, type RelationPluginOptions, } from "./RelationsPlugin/index.js";
3
+ export { UtilitiesPlugin, UtilityDirective, utilsPlugin, isReadOnly, isClientOnly, isCreateOnly, isFilterOnly, isServerOnly, isUpdateOnly, isWriteOnly, } from "./UtilitiesPlugin/index.js";
4
+ export { SchemaGeneratorPlugin, schemaGeneratorPlugin } from "./SchemaGeneratorPlugin.js";
5
+ export { basePreset } from "./basePreset.js";
2
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,OAAO,EACP,WAAW,EACX,KAAK,kBAAkB,EACvB,cAAc,EACd,cAAc,GACf,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,KAAK,kBAAkB,EACvB,cAAc,EACd,cAAc,EACd,WAAW,EACX,OAAO,GACR,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}