@cedarjs/internal 4.0.1-next.0 → 4.0.1-next.67

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.
@@ -23,7 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  mod
24
24
  ));
25
25
  var import_node_fs = __toESM(require("node:fs"), 1);
26
- var import_path = __toESM(require("path"), 1);
26
+ var import_node_path = __toESM(require("node:path"), 1);
27
27
  var import_ansis = __toESM(require("ansis"), 1);
28
28
  var import_chokidar = __toESM(require("chokidar"), 1);
29
29
  var import_project_config = require("@cedarjs/project-config");
@@ -32,18 +32,22 @@ var import_files = require("../files.js");
32
32
  var import_routes = require("../routes.js");
33
33
  var import_clientPreset = require("./clientPreset.js");
34
34
  var import_generate = require("./generate.js");
35
+ var import_gqlormSchema = require("./gqlormSchema.js");
35
36
  var import_graphqlCodeGen = require("./graphqlCodeGen.js");
36
37
  var import_graphqlSchema = require("./graphqlSchema.js");
37
38
  var import_typeDefinitions = require("./typeDefinitions.js");
38
39
  const rwjsPaths = (0, import_project_config.getPaths)();
39
- const generatedDirName = import_path.default.basename(rwjsPaths.generated.base);
40
- const watcher = import_chokidar.default.watch("(web|api)/src/**/*.{ts,js,jsx,tsx}", {
41
- persistent: true,
42
- ignored: ["node_modules", generatedDirName],
43
- ignoreInitial: true,
44
- cwd: rwjsPaths.base,
45
- awaitWriteFinish: true
46
- });
40
+ const generatedDirName = import_node_path.default.basename(rwjsPaths.generated.base);
41
+ const watcher = import_chokidar.default.watch(
42
+ ["(web|api)/src/**/*.{ts,js,jsx,tsx}", "api/db/**/*.prisma"],
43
+ {
44
+ persistent: true,
45
+ ignored: ["node_modules", generatedDirName],
46
+ ignoreInitial: true,
47
+ cwd: rwjsPaths.base,
48
+ awaitWriteFinish: true
49
+ }
50
+ );
47
51
  const action = {
48
52
  add: "Created",
49
53
  unlink: "Deleted",
@@ -83,7 +87,7 @@ Created ${files.length} in ${Date.now() - start} ms`);
83
87
  return;
84
88
  }
85
89
  const eventTigger = eventName;
86
- const absPath = import_path.default.join(rwjsPaths.base, p);
90
+ const absPath = import_node_path.default.join(rwjsPaths.base, p);
87
91
  const start = Date.now();
88
92
  const finished = (type) => import_cliLogger.cliLogger.debug(
89
93
  action[eventTigger],
@@ -118,6 +122,9 @@ Created ${files.length} in ${Date.now() - start} ms`);
118
122
  await (0, import_graphqlSchema.generateGraphQLSchema)();
119
123
  await (0, import_graphqlCodeGen.generateTypeDefGraphQLApi)();
120
124
  finished("GraphQL Schema");
125
+ } else if (absPath.startsWith(import_node_path.default.join(rwjsPaths.base, "api/db/")) && absPath.endsWith(".prisma")) {
126
+ await (0, import_gqlormSchema.generateGqlormArtifacts)();
127
+ finished("Prisma Schema");
121
128
  }
122
129
  if (routesWarningMessage) {
123
130
  console.warn(routesWarningMessage);
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/generate/generate.ts"],"names":[],"mappings":";AAWA,eAAO,MAAM,QAAQ;;;;;;EA6CpB,CAAA;AAED,eAAO,MAAM,GAAG,qBAoCf,CAAA"}
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/generate/generate.ts"],"names":[],"mappings":";AAWA,eAAO,MAAM,QAAQ;;;;;;EA2CpB,CAAA;AAED,eAAO,MAAM,GAAG,qBAoCf,CAAA"}
@@ -12,7 +12,7 @@ const generate = async () => {
12
12
  const { typeDefFiles, errors: generateTypeDefsErrors } = await generateTypeDefs();
13
13
  const clientPresetFiles = [];
14
14
  const { possibleTypesFiles, errors: generatePossibleTypesErrors } = await generatePossibleTypes();
15
- const { files: gqlormFiles, errors: gqlormErrors } = config.experimental?.gqlorm?.enabled ? await generateGqlormArtifacts() : { files: [], errors: [] };
15
+ const { files: gqlormFiles, errors: gqlormErrors } = await generateGqlormArtifacts();
16
16
  if (config.graphql.trustedDocuments) {
17
17
  const preset = await generateClientPreset();
18
18
  clientPresetFiles.push(...preset.clientPresetFiles);
@@ -1,5 +1,43 @@
1
1
  import type * as DMMF from '@prisma/dmmf';
2
2
  type ModelSchema = Record<string, string[]>;
3
+ interface FrontendFieldInfo {
4
+ name: string;
5
+ tsType: string;
6
+ }
7
+ interface FrontendModelInfo {
8
+ modelName: string;
9
+ camelName: string;
10
+ fields: FrontendFieldInfo[];
11
+ }
12
+ export interface BackendFieldInfo {
13
+ name: string;
14
+ graphqlType: string;
15
+ isRequired: boolean;
16
+ isId: boolean;
17
+ }
18
+ export interface BackendModelInfo {
19
+ modelName: string;
20
+ camelName: string;
21
+ pluralName: string;
22
+ fields: BackendFieldInfo[];
23
+ idField: BackendFieldInfo | undefined;
24
+ }
25
+ export interface GqlormBackendConfig {
26
+ membershipModel: string;
27
+ membershipModelCamel: string;
28
+ membershipUserField: string;
29
+ membershipOrganizationField: string;
30
+ membershipModelExists: boolean;
31
+ }
32
+ /**
33
+ * Map a DMMF field type to its GraphQL SDL equivalent.
34
+ *
35
+ * Enum fields (kind === 'enum') are mapped to String. Unknown scalar types
36
+ * fall back to String.
37
+ */
38
+ export declare function mapDmmfTypeToGraphql(type: string, kind: string): string;
39
+ export declare function buildFrontendModelInfo(dmmf: DMMF.Document): FrontendModelInfo[];
40
+ export declare function generateWebGqlormModelsContent(models: FrontendModelInfo[]): string;
3
41
  /**
4
42
  * Build a ModelSchema from a Prisma DMMF document.
5
43
  *
@@ -7,12 +45,57 @@ type ModelSchema = Record<string, string[]>;
7
45
  * with a mock DMMF object.
8
46
  */
9
47
  export declare function buildModelSchema(dmmf: DMMF.Document): ModelSchema;
48
+ /**
49
+ * Build enriched model information from the DMMF, applying the same visibility
50
+ * rules as `buildModelSchema()` but also collecting type, nullability, and
51
+ * @id flag per field.
52
+ *
53
+ * **Note:** This function silently excludes sensitive fields without emitting
54
+ * warnings. It is designed to run after `buildModelSchema()` (which emits the
55
+ * warnings). In `generateGqlormArtifacts()` the call order is guaranteed, but
56
+ * callers using this function standalone should be aware that no warnings will
57
+ * be printed for auto-hidden sensitive fields.
58
+ *
59
+ * This is a pure function — safe for testing.
60
+ */
61
+ export declare function buildBackendModelInfo(dmmf: DMMF.Document): BackendModelInfo[];
62
+ /**
63
+ * Scan all SDL files in the given directory and return the set of GraphQL type
64
+ * names that are already defined by user-authored SDLs.
65
+ *
66
+ * This prevents gqlorm from generating duplicate type definitions that would
67
+ * cause merge conflicts in `makeMergedSchema`.
68
+ */
69
+ export declare function getExistingSdlTypeNames(graphqlDir: string): Set<string>;
70
+ /**
71
+ * Generate the full TypeScript source for `.cedar/gqlorm/backend.ts`.
72
+ *
73
+ * The generated file exports:
74
+ * - `schema`: a gql DocumentNode with type defs and Query fields
75
+ * - `createGqlormResolvers(db: GqlormDb)`: a factory function that takes a
76
+ * Prisma client-like object and returns a resolvers object
77
+ *
78
+ * The file does NOT import `db` directly. Instead, the Babel inject plugin
79
+ * imports `db` from `src/lib/db` in `graphql.ts` (where that alias resolves
80
+ * correctly) and passes it to `createGqlormResolvers`.
81
+ *
82
+ * The generated `GqlormDb` interface is scoped to exactly the visible models
83
+ * and fields — no hidden/sensitive fields, no @gqlorm hide models, no
84
+ * dependency on the generated Prisma client path or @prisma/client.
85
+ */
86
+ export declare function generateGqlormBackendContent(models: BackendModelInfo[], config?: GqlormBackendConfig): string;
10
87
  /**
11
88
  * Generate gqlorm artifacts from the Prisma schema.
12
89
  *
13
90
  * 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`.
91
+ * (@gqlorm directives + sensitivity heuristics), and writes:
92
+ *
93
+ * 1. `.cedar/gqlorm-schema.json` — the frontend ModelSchema (field names only)
94
+ * 2. `.cedar/gqlorm/backend.ts` — auto-generated GraphQL types and resolvers
95
+ * for models that don't already have manually-written SDL files
96
+ *
97
+ * Cedar targets Node.js 24, which strips TypeScript types natively without any
98
+ * flags, so backend.ts can be imported directly at runtime
16
99
  *
17
100
  * Returns the same `{ files, errors }` shape used by other generators so it
18
101
  * can be integrated into `generate.ts` without special handling.
@@ -1 +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"}
1
+ {"version":3,"file":"gqlormSchema.d.ts","sourceRoot":"","sources":["../../src/generate/gqlormSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,IAAI,MAAM,cAAc,CAAA;AA8BzC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAE3C,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,iBAAiB,EAAE,CAAA;CAC5B;AAMD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,OAAO,CAAA;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM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