rads-db 3.0.31 → 3.0.32

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.
@@ -138,7 +138,7 @@ function fillComputedDefinitionsForType(result) {
138
138
  const precomputedFields = _lodash.default.values(fields).filter(f => !!f.decorators?.precomputed).sort((f1, f2) => getOrder(f1) - getOrder(f2)).map(f => f.name);
139
139
  const computedFields = _lodash.default.values(fields).filter(f => !!f.decorators?.computed).sort((f1, f2) => getOrder(f1) - getOrder(f2)).map(f => f.name);
140
140
  const nestedTypeFields = _lodash.default.values(fields).filter(f => result[f.type] && result[f.type].fields && !result[f.type].decorators.entity).map(f => f.name);
141
- const keepHistoryFields = _lodash.default.values(fields).filter(f => !!f.decorators?.keepHistory).sort((f1, f2) => getOrder(f1) - getOrder(f2)).map(f => f.name);
141
+ const keepHistoryFields = _lodash.default.values(fields).filter(f => !!f.decorators?.keepHistory).map(f => f.name);
142
142
  if (precomputedFields.length) type.precomputedFields = precomputedFields;
143
143
  if (computedFields.length) type.computedFields = computedFields;
144
144
  if (nestedTypeFields.length) type.nestedTypeFields = nestedTypeFields;
@@ -112,7 +112,7 @@ function fillComputedDefinitionsForType(result) {
112
112
  const precomputedFields = _.values(fields).filter((f) => !!f.decorators?.precomputed).sort((f1, f2) => getOrder(f1) - getOrder(f2)).map((f) => f.name);
113
113
  const computedFields = _.values(fields).filter((f) => !!f.decorators?.computed).sort((f1, f2) => getOrder(f1) - getOrder(f2)).map((f) => f.name);
114
114
  const nestedTypeFields = _.values(fields).filter((f) => result[f.type] && result[f.type].fields && !result[f.type].decorators.entity).map((f) => f.name);
115
- const keepHistoryFields = _.values(fields).filter((f) => !!f.decorators?.keepHistory).sort((f1, f2) => getOrder(f1) - getOrder(f2)).map((f) => f.name);
115
+ const keepHistoryFields = _.values(fields).filter((f) => !!f.decorators?.keepHistory).map((f) => f.name);
116
116
  if (precomputedFields.length)
117
117
  type.precomputedFields = precomputedFields;
118
118
  if (computedFields.length)
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.generateClient = generateClient;
7
+ exports.getEntityTypesStrFromSchema = getEntityTypesStrFromSchema;
7
8
  exports.getIndexDts = getIndexDts;
8
9
  exports.getSchema = getSchema;
9
10
  var _promises = _interopRequireDefault(require("node:fs/promises"));
@@ -31,9 +32,10 @@ exports.schema=${JSON.stringify(schema)}
31
32
  const indexMjsText = `
32
33
  export const schema = ${JSON.stringify(schema)}
33
34
  `.trim();
35
+ const indexDtsText = getIndexDts(schema, normalizedOptions);
34
36
  await _promises.default.writeFile(_nodePath.default.join(radsDbPath, "./index.js"), indexJsText);
35
37
  await _promises.default.writeFile(_nodePath.default.join(radsDbPath, "./index.mjs"), indexMjsText);
36
- await _promises.default.writeFile(_nodePath.default.join(radsDbPath, "./index.d.ts"), getIndexDts(schema, normalizedOptions));
38
+ await _promises.default.writeFile(_nodePath.default.join(radsDbPath, "./index.d.ts"), indexDtsText);
37
39
  await _promises.default.writeFile(_nodePath.default.join(radsDbPath, "./package.json"), JSON.stringify({
38
40
  name: "_rads-db",
39
41
  main: "./index.js",
@@ -95,10 +97,13 @@ function getIndexDts(schema, options) {
95
97
  const rootFields = [];
96
98
  const whereTypes = [];
97
99
  const entityMeta = [];
100
+ const schemaTypesStr = options.entitiesDir ? "" : getEntityTypesStrFromSchema(schema);
98
101
  for (const key in schema) {
99
102
  const type = schema[key];
100
- if (!type.fields) continue;
101
- imports.push(`import type { ${type.name} } from '../../${options.entitiesDir}/${key}'`);
103
+ if (!type.decorators.entity) continue;
104
+ if (options.entitiesDir) {
105
+ imports.push(`import type { ${type.name} } from '../../${options.entitiesDir}/${key}'`);
106
+ }
102
107
  rootFields.push(`${type.handle}: EntityMethods<${type.name}, '${type.name}', ${type.name}_Where>`);
103
108
  const fieldsArray = Object.values(type.fields);
104
109
  const relations = _lodash.default.fromPairs(fieldsArray.filter(f => f.isRelation).map(f => [f.name, {
@@ -111,6 +116,10 @@ function getIndexDts(schema, options) {
111
116
  aggregates: fieldsArray.filter(f => f.type === "number" && !f.isArray).map(x => `'${x.name}'`).join(" | "),
112
117
  primitives: fieldsArray.filter(f => !schema[f.type]?.decorators?.entity).map(x => `'${x.name}'`).join(" | ")
113
118
  });
119
+ }
120
+ for (const key in schema) {
121
+ const type = schema[key];
122
+ if (!type.fields) continue;
114
123
  const whereFields = getWhereFields(schema, type);
115
124
  whereTypes.push(`
116
125
  export interface ${type.name}_Where {
@@ -128,6 +137,7 @@ ${whereFields.join("\n")}
128
137
  return `
129
138
  import type { EntityMethods, FileUploadArgs, RadsRequestContext } from 'rads-db'
130
139
  ${imports.join("\n")}
140
+ ${schemaTypesStr}
131
141
 
132
142
  export interface EntityMeta {
133
143
  ${entityMetaStr}
@@ -147,6 +157,9 @@ export interface RadsDb {
147
157
  }
148
158
  `.trim();
149
159
  }
160
+ function getEntityTypesStrFromSchema(schema) {
161
+ return "";
162
+ }
150
163
  function getWhereFields(schema, type) {
151
164
  const result = [];
152
165
  for (const f in type.fields) {
@@ -2,3 +2,4 @@ import type { GenerateClientNormalizedOptions, GenerateClientOptions, Schema } f
2
2
  export declare function generateClient(options?: GenerateClientOptions): Promise<void>;
3
3
  export declare function getSchema(normalizedOptions: GenerateClientNormalizedOptions): Promise<any>;
4
4
  export declare function getIndexDts(schema: Schema, options: GenerateClientNormalizedOptions): string;
5
+ export declare function getEntityTypesStrFromSchema(schema: Schema): string;
@@ -24,9 +24,10 @@ exports.schema=${JSON.stringify(schema)}
24
24
  const indexMjsText = `
25
25
  export const schema = ${JSON.stringify(schema)}
26
26
  `.trim();
27
+ const indexDtsText = getIndexDts(schema, normalizedOptions);
27
28
  await fs.writeFile(path.join(radsDbPath, "./index.js"), indexJsText);
28
29
  await fs.writeFile(path.join(radsDbPath, "./index.mjs"), indexMjsText);
29
- await fs.writeFile(path.join(radsDbPath, "./index.d.ts"), getIndexDts(schema, normalizedOptions));
30
+ await fs.writeFile(path.join(radsDbPath, "./index.d.ts"), indexDtsText);
30
31
  await fs.writeFile(
31
32
  path.join(radsDbPath, "./package.json"),
32
33
  JSON.stringify(
@@ -88,11 +89,14 @@ export function getIndexDts(schema, options) {
88
89
  const rootFields = [];
89
90
  const whereTypes = [];
90
91
  const entityMeta = [];
92
+ const schemaTypesStr = options.entitiesDir ? "" : getEntityTypesStrFromSchema(schema);
91
93
  for (const key in schema) {
92
94
  const type = schema[key];
93
- if (!type.fields)
95
+ if (!type.decorators.entity)
94
96
  continue;
95
- imports.push(`import type { ${type.name} } from '../../${options.entitiesDir}/${key}'`);
97
+ if (options.entitiesDir) {
98
+ imports.push(`import type { ${type.name} } from '../../${options.entitiesDir}/${key}'`);
99
+ }
96
100
  rootFields.push(`${type.handle}: EntityMethods<${type.name}, '${type.name}', ${type.name}_Where>`);
97
101
  const fieldsArray = Object.values(type.fields);
98
102
  const relations = _.fromPairs(
@@ -109,6 +113,11 @@ export function getIndexDts(schema, options) {
109
113
  aggregates: fieldsArray.filter((f) => f.type === "number" && !f.isArray).map((x) => `'${x.name}'`).join(" | "),
110
114
  primitives: fieldsArray.filter((f) => !schema[f.type]?.decorators?.entity).map((x) => `'${x.name}'`).join(" | ")
111
115
  });
116
+ }
117
+ for (const key in schema) {
118
+ const type = schema[key];
119
+ if (!type.fields)
120
+ continue;
112
121
  const whereFields = getWhereFields(schema, type);
113
122
  whereTypes.push(
114
123
  `
@@ -130,6 +139,7 @@ ${whereFields.join("\n")}
130
139
  return `
131
140
  import type { EntityMethods, FileUploadArgs, RadsRequestContext } from 'rads-db'
132
141
  ${imports.join("\n")}
142
+ ${schemaTypesStr}
133
143
 
134
144
  export interface EntityMeta {
135
145
  ${entityMetaStr}
@@ -149,6 +159,9 @@ export interface RadsDb {
149
159
  }
150
160
  `.trim();
151
161
  }
162
+ export function getEntityTypesStrFromSchema(schema) {
163
+ return "";
164
+ }
152
165
  function getWhereFields(schema, type) {
153
166
  const result = [];
154
167
  for (const f in type.fields) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.0.31",
3
+ "version": "3.0.32",
4
4
  "files": [
5
5
  "dist",
6
6
  "drivers",
@@ -105,7 +105,7 @@
105
105
  "scripts": {
106
106
  "test": "vitest --run && vitest typecheck --run",
107
107
  "link-rads-db": "symlink-dir ./test/_rads-db ./node_modules/_rads-db",
108
- "generate-test-schema": "rads-db",
108
+ "generate-test-schema": "rads-db -d './test/entities'",
109
109
  "dev": "pnpm install && pnpm link-rads-db && pnpm build && pnpm generate-test-schema && vitest --ui --test-timeout 300000",
110
110
  "lint": "cross-env NODE_ENV=production eslint src/**/*.* test/**/*.*",
111
111
  "dev-typecheck": "pnpm install && pnpm build && pnpm generate-test-schema && pnpm link-rads-db && vitest typecheck --ui",