@cedarjs/internal 4.0.0-canary.13776 → 4.0.0-canary.13779

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.
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/generate/generate.ts"],"names":[],"mappings":";AASA,eAAO,MAAM,QAAQ;;;;;;EAsCpB,CAAA;AAED,eAAO,MAAM,GAAG,qBA4Bf,CAAA"}
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/generate/generate.ts"],"names":[],"mappings":";AAUA,eAAO,MAAM,QAAQ;;;;;;EA2CpB,CAAA;AAED,eAAO,MAAM,GAAG,qBA4Bf,CAAA"}
@@ -25,6 +25,7 @@ __export(generate_exports, {
25
25
  module.exports = __toCommonJS(generate_exports);
26
26
  var import_project_config = require("@cedarjs/project-config");
27
27
  var import_clientPreset = require("./clientPreset.js");
28
+ var import_gqlormSchema = require("./gqlormSchema.js");
28
29
  var import_graphqlSchema = require("./graphqlSchema.js");
29
30
  var import_possibleTypes = require("./possibleTypes.js");
30
31
  var import_typeDefinitions = require("./typeDefinitions.js");
@@ -34,6 +35,7 @@ const generate = async () => {
34
35
  const { typeDefFiles, errors: generateTypeDefsErrors } = await (0, import_typeDefinitions.generateTypeDefs)();
35
36
  const clientPresetFiles = [];
36
37
  const { possibleTypesFiles, errors: generatePossibleTypesErrors } = await (0, import_possibleTypes.generatePossibleTypes)();
38
+ const { files: gqlormFiles, errors: gqlormErrors } = await (0, import_gqlormSchema.generateGqlormArtifacts)();
37
39
  if (config.graphql.trustedDocuments) {
38
40
  const preset = await (0, import_clientPreset.generateClientPreset)();
39
41
  clientPresetFiles.push(...preset.clientPresetFiles);
@@ -46,14 +48,16 @@ const generate = async () => {
46
48
  ...files,
47
49
  ...typeDefFiles,
48
50
  ...clientPresetFiles,
49
- ...possibleTypesFiles
51
+ ...possibleTypesFiles,
52
+ ...gqlormFiles
50
53
  ].filter((x) => typeof x === "string");
51
54
  return {
52
55
  files,
53
56
  errors: [
54
57
  ...generateGraphQLSchemaErrors,
55
58
  ...generateTypeDefsErrors,
56
- ...generatePossibleTypesErrors
59
+ ...generatePossibleTypesErrors,
60
+ ...gqlormErrors
57
61
  ]
58
62
  };
59
63
  };
@@ -0,0 +1,28 @@
1
+ import type * as DMMF from '@prisma/dmmf';
2
+ type ModelSchema = Record<string, string[]>;
3
+ /**
4
+ * Build a ModelSchema from a Prisma DMMF document.
5
+ *
6
+ * This is a pure function with no I/O — it can be called directly in tests
7
+ * with a mock DMMF object.
8
+ */
9
+ export declare function buildModelSchema(dmmf: DMMF.Document): ModelSchema;
10
+ /**
11
+ * Generate gqlorm artifacts from the Prisma schema.
12
+ *
13
+ * Reads the project's Prisma schema via DMMF, applies visibility rules
14
+ * (@gqlorm directives + sensitivity heuristics), and writes the resulting
15
+ * ModelSchema to `.cedar/gqlorm-schema.json`.
16
+ *
17
+ * Returns the same `{ files, errors }` shape used by other generators so it
18
+ * can be integrated into `generate.ts` without special handling.
19
+ */
20
+ export declare function generateGqlormArtifacts(): Promise<{
21
+ files: string[];
22
+ errors: {
23
+ message: string;
24
+ error: unknown;
25
+ }[];
26
+ }>;
27
+ export {};
28
+ //# sourceMappingURL=gqlormSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gqlormSchema.d.ts","sourceRoot":"","sources":["../../../src/generate/gqlormSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,IAAI,MAAM,cAAc,CAAA;AAgBzC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAiC3C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,GAAG,WAAW,CAkDjE;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC;IACvD,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAC9C,CAAC,CA+BD"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var gqlormSchema_exports = {};
30
+ __export(gqlormSchema_exports, {
31
+ buildModelSchema: () => buildModelSchema,
32
+ generateGqlormArtifacts: () => generateGqlormArtifacts
33
+ });
34
+ module.exports = __toCommonJS(gqlormSchema_exports);
35
+ var import_node_fs = __toESM(require("node:fs"), 1);
36
+ var import_node_path = __toESM(require("node:path"), 1);
37
+ var import_project_config = require("@cedarjs/project-config");
38
+ const INTERNAL_MODEL_NAMES = /* @__PURE__ */ new Set(["RW_DataMigration"]);
39
+ const SENSITIVE_PATTERNS = ["password", "secret", "token", "hash", "salt"];
40
+ function hasDirective(doc, directive) {
41
+ if (!doc) {
42
+ return false;
43
+ }
44
+ return doc.split("\n").some((line) => line.trimStart().startsWith(`@gqlorm ${directive}`));
45
+ }
46
+ function isSensitiveField(fieldName) {
47
+ const lower = fieldName.toLowerCase();
48
+ return SENSITIVE_PATTERNS.some((pattern) => lower.includes(pattern));
49
+ }
50
+ function emitSensitivityWarning(modelName, fieldName) {
51
+ console.warn(
52
+ `[gqlorm] ${modelName}.${fieldName} was automatically hidden because its name appears sensitive. Add a directive to suppress this warning:
53
+
54
+ /// @gqlorm hide \u2013 to confirm it should stay hidden
55
+ /// @gqlorm show \u2013 to explicitly expose it
56
+ `
57
+ );
58
+ }
59
+ function buildModelSchema(dmmf) {
60
+ const schema = {};
61
+ for (const model of dmmf.datamodel.models) {
62
+ if (INTERNAL_MODEL_NAMES.has(model.name)) {
63
+ continue;
64
+ }
65
+ if (hasDirective(model.documentation, "hide")) {
66
+ continue;
67
+ }
68
+ const visibleFields = [];
69
+ for (const field of model.fields) {
70
+ if (field.kind !== "scalar" && field.kind !== "enum") {
71
+ continue;
72
+ }
73
+ if (hasDirective(field.documentation, "hide")) {
74
+ continue;
75
+ }
76
+ if (hasDirective(field.documentation, "show")) {
77
+ visibleFields.push(field.name);
78
+ continue;
79
+ }
80
+ if (isSensitiveField(field.name)) {
81
+ emitSensitivityWarning(model.name, field.name);
82
+ continue;
83
+ }
84
+ visibleFields.push(field.name);
85
+ }
86
+ if (visibleFields.length > 0) {
87
+ const camelCaseName = model.name.charAt(0).toLowerCase() + model.name.slice(1);
88
+ schema[camelCaseName] = visibleFields;
89
+ }
90
+ }
91
+ return schema;
92
+ }
93
+ async function generateGqlormArtifacts() {
94
+ const files = [];
95
+ const errors = [];
96
+ try {
97
+ const { schemas } = await (0, import_project_config.getPrismaSchemas)();
98
+ const mod = await import("@prisma/internals");
99
+ const { getDMMF } = mod.default || mod;
100
+ const dmmf = await getDMMF({ datamodel: schemas });
101
+ const modelSchema = buildModelSchema(dmmf);
102
+ const outputPath = import_node_path.default.join(
103
+ (0, import_project_config.getPaths)().generated.base,
104
+ "gqlorm-schema.json"
105
+ );
106
+ import_node_fs.default.mkdirSync(import_node_path.default.dirname(outputPath), { recursive: true });
107
+ import_node_fs.default.writeFileSync(outputPath, JSON.stringify(modelSchema, null, 2));
108
+ files.push(outputPath);
109
+ } catch (error) {
110
+ errors.push({
111
+ message: "Failed to generate gqlorm schema artifacts",
112
+ error
113
+ });
114
+ }
115
+ return { files, errors };
116
+ }
117
+ // Annotate the CommonJS export names for ESM import in node:
118
+ 0 && (module.exports = {
119
+ buildModelSchema,
120
+ generateGqlormArtifacts
121
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/generate/generate.ts"],"names":[],"mappings":";AASA,eAAO,MAAM,QAAQ;;;;;;EAsCpB,CAAA;AAED,eAAO,MAAM,GAAG,qBA4Bf,CAAA"}
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/generate/generate.ts"],"names":[],"mappings":";AAUA,eAAO,MAAM,QAAQ;;;;;;EA2CpB,CAAA;AAED,eAAO,MAAM,GAAG,qBA4Bf,CAAA"}
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { getConfig, getPaths } from "@cedarjs/project-config";
3
3
  import { generateClientPreset } from "./clientPreset.js";
4
+ import { generateGqlormArtifacts } from "./gqlormSchema.js";
4
5
  import { generateGraphQLSchema } from "./graphqlSchema.js";
5
6
  import { generatePossibleTypes } from "./possibleTypes.js";
6
7
  import { generateTypeDefs } from "./typeDefinitions.js";
@@ -10,6 +11,7 @@ const generate = async () => {
10
11
  const { typeDefFiles, errors: generateTypeDefsErrors } = await generateTypeDefs();
11
12
  const clientPresetFiles = [];
12
13
  const { possibleTypesFiles, errors: generatePossibleTypesErrors } = await generatePossibleTypes();
14
+ const { files: gqlormFiles, errors: gqlormErrors } = await generateGqlormArtifacts();
13
15
  if (config.graphql.trustedDocuments) {
14
16
  const preset = await generateClientPreset();
15
17
  clientPresetFiles.push(...preset.clientPresetFiles);
@@ -22,14 +24,16 @@ const generate = async () => {
22
24
  ...files,
23
25
  ...typeDefFiles,
24
26
  ...clientPresetFiles,
25
- ...possibleTypesFiles
27
+ ...possibleTypesFiles,
28
+ ...gqlormFiles
26
29
  ].filter((x) => typeof x === "string");
27
30
  return {
28
31
  files,
29
32
  errors: [
30
33
  ...generateGraphQLSchemaErrors,
31
34
  ...generateTypeDefsErrors,
32
- ...generatePossibleTypesErrors
35
+ ...generatePossibleTypesErrors,
36
+ ...gqlormErrors
33
37
  ]
34
38
  };
35
39
  };
@@ -0,0 +1,28 @@
1
+ import type * as DMMF from '@prisma/dmmf';
2
+ type ModelSchema = Record<string, string[]>;
3
+ /**
4
+ * Build a ModelSchema from a Prisma DMMF document.
5
+ *
6
+ * This is a pure function with no I/O — it can be called directly in tests
7
+ * with a mock DMMF object.
8
+ */
9
+ export declare function buildModelSchema(dmmf: DMMF.Document): ModelSchema;
10
+ /**
11
+ * Generate gqlorm artifacts from the Prisma schema.
12
+ *
13
+ * Reads the project's Prisma schema via DMMF, applies visibility rules
14
+ * (@gqlorm directives + sensitivity heuristics), and writes the resulting
15
+ * ModelSchema to `.cedar/gqlorm-schema.json`.
16
+ *
17
+ * Returns the same `{ files, errors }` shape used by other generators so it
18
+ * can be integrated into `generate.ts` without special handling.
19
+ */
20
+ export declare function generateGqlormArtifacts(): Promise<{
21
+ files: string[];
22
+ errors: {
23
+ message: string;
24
+ error: unknown;
25
+ }[];
26
+ }>;
27
+ export {};
28
+ //# sourceMappingURL=gqlormSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gqlormSchema.d.ts","sourceRoot":"","sources":["../../src/generate/gqlormSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,IAAI,MAAM,cAAc,CAAA;AAgBzC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAiC3C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,GAAG,WAAW,CAkDjE;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC;IACvD,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAC9C,CAAC,CA+BD"}
@@ -0,0 +1,86 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { getPaths, getPrismaSchemas } from "@cedarjs/project-config";
4
+ const INTERNAL_MODEL_NAMES = /* @__PURE__ */ new Set(["RW_DataMigration"]);
5
+ const SENSITIVE_PATTERNS = ["password", "secret", "token", "hash", "salt"];
6
+ function hasDirective(doc, directive) {
7
+ if (!doc) {
8
+ return false;
9
+ }
10
+ return doc.split("\n").some((line) => line.trimStart().startsWith(`@gqlorm ${directive}`));
11
+ }
12
+ function isSensitiveField(fieldName) {
13
+ const lower = fieldName.toLowerCase();
14
+ return SENSITIVE_PATTERNS.some((pattern) => lower.includes(pattern));
15
+ }
16
+ function emitSensitivityWarning(modelName, fieldName) {
17
+ console.warn(
18
+ `[gqlorm] ${modelName}.${fieldName} was automatically hidden because its name appears sensitive. Add a directive to suppress this warning:
19
+
20
+ /// @gqlorm hide \u2013 to confirm it should stay hidden
21
+ /// @gqlorm show \u2013 to explicitly expose it
22
+ `
23
+ );
24
+ }
25
+ function buildModelSchema(dmmf) {
26
+ const schema = {};
27
+ for (const model of dmmf.datamodel.models) {
28
+ if (INTERNAL_MODEL_NAMES.has(model.name)) {
29
+ continue;
30
+ }
31
+ if (hasDirective(model.documentation, "hide")) {
32
+ continue;
33
+ }
34
+ const visibleFields = [];
35
+ for (const field of model.fields) {
36
+ if (field.kind !== "scalar" && field.kind !== "enum") {
37
+ continue;
38
+ }
39
+ if (hasDirective(field.documentation, "hide")) {
40
+ continue;
41
+ }
42
+ if (hasDirective(field.documentation, "show")) {
43
+ visibleFields.push(field.name);
44
+ continue;
45
+ }
46
+ if (isSensitiveField(field.name)) {
47
+ emitSensitivityWarning(model.name, field.name);
48
+ continue;
49
+ }
50
+ visibleFields.push(field.name);
51
+ }
52
+ if (visibleFields.length > 0) {
53
+ const camelCaseName = model.name.charAt(0).toLowerCase() + model.name.slice(1);
54
+ schema[camelCaseName] = visibleFields;
55
+ }
56
+ }
57
+ return schema;
58
+ }
59
+ async function generateGqlormArtifacts() {
60
+ const files = [];
61
+ const errors = [];
62
+ try {
63
+ const { schemas } = await getPrismaSchemas();
64
+ const mod = await import("@prisma/internals");
65
+ const { getDMMF } = mod.default || mod;
66
+ const dmmf = await getDMMF({ datamodel: schemas });
67
+ const modelSchema = buildModelSchema(dmmf);
68
+ const outputPath = path.join(
69
+ getPaths().generated.base,
70
+ "gqlorm-schema.json"
71
+ );
72
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
73
+ fs.writeFileSync(outputPath, JSON.stringify(modelSchema, null, 2));
74
+ files.push(outputPath);
75
+ } catch (error) {
76
+ errors.push({
77
+ message: "Failed to generate gqlorm schema artifacts",
78
+ error
79
+ });
80
+ }
81
+ return { files, errors };
82
+ }
83
+ export {
84
+ buildModelSchema,
85
+ generateGqlormArtifacts
86
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/internal",
3
- "version": "4.0.0-canary.13776+c89b50442",
3
+ "version": "4.0.0-canary.13779+0c5740a9f",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -119,6 +119,16 @@
119
119
  "types": "./dist/cjs/generate/generate.d.ts",
120
120
  "default": "./dist/cjs/generate/generate.js"
121
121
  }
122
+ },
123
+ "./dist/generate/gqlormSchema": {
124
+ "import": {
125
+ "types": "./dist/generate/gqlormSchema.d.ts",
126
+ "default": "./dist/generate/gqlormSchema.js"
127
+ },
128
+ "require": {
129
+ "types": "./dist/cjs/generate/gqlormSchema.d.ts",
130
+ "default": "./dist/cjs/generate/gqlormSchema.js"
131
+ }
122
132
  }
123
133
  },
124
134
  "types": "dist/index.d.ts",
@@ -149,11 +159,11 @@
149
159
  "@babel/plugin-transform-react-jsx": "7.28.6",
150
160
  "@babel/plugin-transform-typescript": "^7.26.8",
151
161
  "@babel/traverse": "7.29.0",
152
- "@cedarjs/babel-config": "4.0.0-canary.13776",
153
- "@cedarjs/graphql-server": "4.0.0-canary.13776",
154
- "@cedarjs/project-config": "4.0.0-canary.13776",
155
- "@cedarjs/router": "4.0.0-canary.13776",
156
- "@cedarjs/structure": "4.0.0-canary.13776",
162
+ "@cedarjs/babel-config": "4.0.0-canary.13779",
163
+ "@cedarjs/graphql-server": "4.0.0-canary.13779",
164
+ "@cedarjs/project-config": "4.0.0-canary.13779",
165
+ "@cedarjs/router": "4.0.0-canary.13779",
166
+ "@cedarjs/structure": "4.0.0-canary.13779",
157
167
  "@graphql-codegen/add": "6.0.0",
158
168
  "@graphql-codegen/cli": "6.2.1",
159
169
  "@graphql-codegen/client-preset": "5.2.4",
@@ -166,6 +176,8 @@
166
176
  "@graphql-codegen/typescript-react-apollo": "4.4.1",
167
177
  "@graphql-codegen/typescript-resolvers": "5.1.7",
168
178
  "@graphql-tools/documents": "1.0.1",
179
+ "@prisma/dmmf": "7.6.0",
180
+ "@prisma/internals": "7.6.0",
169
181
  "@sdl-codegen/node": "2.0.1",
170
182
  "ansis": "4.2.0",
171
183
  "deepmerge": "4.3.1",
@@ -184,7 +196,7 @@
184
196
  },
185
197
  "devDependencies": {
186
198
  "@arethetypeswrong/cli": "0.18.2",
187
- "@cedarjs/framework-tools": "4.0.0-canary.13776",
199
+ "@cedarjs/framework-tools": "4.0.0-canary.13779",
188
200
  "concurrently": "9.2.1",
189
201
  "graphql-tag": "2.12.6",
190
202
  "publint": "0.3.18",
@@ -197,5 +209,5 @@
197
209
  "publishConfig": {
198
210
  "access": "public"
199
211
  },
200
- "gitHead": "c89b504429437540b873e933d678d021e855cd48"
212
+ "gitHead": "0c5740a9f02db6aa1583c5d8212702deb910d175"
201
213
  }