rads-db 3.0.32 → 3.0.33

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.
@@ -158,7 +158,32 @@ export interface RadsDb {
158
158
  `.trim();
159
159
  }
160
160
  function getEntityTypesStrFromSchema(schema) {
161
- return "";
161
+ const definitions = [];
162
+ for (const key in schema) {
163
+ const type = schema[key];
164
+ if (!type.fields) {
165
+ definitions.push(`export type ${type.name} = ${_lodash.default.keys(type.enumValues).map(x => `'${x}'`).join(" | ")}`);
166
+ } else {
167
+ const fields = Object.values(type.fields);
168
+ const fieldsStr = fields.map(f => {
169
+ if (type.isExtending && schema[type.isExtending]?.fields?.[f.name]) return "";
170
+ let fieldTypeStr = f.type;
171
+ if (f.isChange) fieldTypeStr = `Change<${fieldTypeStr}>`;
172
+ if (f.isRelation) fieldTypeStr = `Relation<${fieldTypeStr}>`;
173
+ if (f.isArray) fieldTypeStr = `${fieldTypeStr}[]`;
174
+ const fieldStr = ` ${f.name}${f.isRequired ? "!" : "?"}: ${fieldTypeStr}`;
175
+ const commentStr2 = f.comment ? ` /** ${f.comment} */` : "";
176
+ return [fieldStr, commentStr2].filter(x => x).join("\n");
177
+ }).filter(x => x).join("\n");
178
+ const commentStr = type.comment ? `/** ${type.comment} */
179
+ ` : "";
180
+ definitions.push(`
181
+ ${commentStr}export class ${type.name}${type.isExtending ? ` extends ${type.isExtending}` : ""} {
182
+ ${fieldsStr}
183
+ }`.trim());
184
+ }
185
+ }
186
+ return definitions.join("\n\n");
162
187
  }
163
188
  function getWhereFields(schema, type) {
164
189
  const result = [];
@@ -160,7 +160,40 @@ export interface RadsDb {
160
160
  `.trim();
161
161
  }
162
162
  export function getEntityTypesStrFromSchema(schema) {
163
- return "";
163
+ const definitions = [];
164
+ for (const key in schema) {
165
+ const type = schema[key];
166
+ if (!type.fields) {
167
+ definitions.push(
168
+ `export type ${type.name} = ${_.keys(type.enumValues).map((x) => `'${x}'`).join(" | ")}`
169
+ );
170
+ } else {
171
+ const fields = Object.values(type.fields);
172
+ const fieldsStr = fields.map((f) => {
173
+ if (type.isExtending && schema[type.isExtending]?.fields?.[f.name])
174
+ return "";
175
+ let fieldTypeStr = f.type;
176
+ if (f.isChange)
177
+ fieldTypeStr = `Change<${fieldTypeStr}>`;
178
+ if (f.isRelation)
179
+ fieldTypeStr = `Relation<${fieldTypeStr}>`;
180
+ if (f.isArray)
181
+ fieldTypeStr = `${fieldTypeStr}[]`;
182
+ const fieldStr = ` ${f.name}${f.isRequired ? "!" : "?"}: ${fieldTypeStr}`;
183
+ const commentStr2 = f.comment ? ` /** ${f.comment} */` : "";
184
+ return [fieldStr, commentStr2].filter((x) => x).join("\n");
185
+ }).filter((x) => x).join("\n");
186
+ const commentStr = type.comment ? `/** ${type.comment} */
187
+ ` : "";
188
+ definitions.push(
189
+ `
190
+ ${commentStr}export class ${type.name}${type.isExtending ? ` extends ${type.isExtending}` : ""} {
191
+ ${fieldsStr}
192
+ }`.trim()
193
+ );
194
+ }
195
+ }
196
+ return definitions.join("\n\n");
164
197
  }
165
198
  function getWhereFields(schema, type) {
166
199
  const result = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.0.32",
3
+ "version": "3.0.33",
4
4
  "files": [
5
5
  "dist",
6
6
  "drivers",