rads-db 3.0.10 → 3.0.11

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.
package/dist/index.cjs CHANGED
@@ -45,7 +45,7 @@ function getZodSchema(zodSchemas, schema, key) {
45
45
  return zodSchemas[key];
46
46
  const type = schema[key];
47
47
  if (type.enumValues) {
48
- const enums = ___default.fromPairs(type.enumValues.map((x) => [x, x]));
48
+ const enums = ___default.mapValues(type.enumValues, (v) => v.name);
49
49
  return zod.z.nativeEnum(enums);
50
50
  }
51
51
  const objectSchema = {};
@@ -603,7 +603,7 @@ function validateEventSourcingSetup(schema, entityName, eventEntityName, aggrega
603
603
  if (!field)
604
604
  throw new Error(`"${eventEntityName}" must have field "${f}"`);
605
605
  if (expectedFields[f] === "enum") {
606
- if (!schema[field.type]?.enumValues?.includes("creation"))
606
+ if (!schema[field.type]?.enumValues?.creation)
607
607
  throw new Error(`Field "${eventEntityName}.${f}" must be enum that accepts value 'creation'`);
608
608
  } else {
609
609
  if (field.type !== expectedFields[f])
package/dist/index.d.ts CHANGED
@@ -199,7 +199,7 @@ interface TypeDefinition {
199
199
  computedFields?: string[];
200
200
  nestedTypeFields?: string[];
201
201
  fields?: Record<string, FieldDefinition>;
202
- enumValues?: string[];
202
+ enumValues?: Record<string, EnumDefinition>;
203
203
  handle?: string;
204
204
  handlePlural?: string;
205
205
  }
@@ -260,6 +260,11 @@ interface FieldDefinition {
260
260
  comment?: string;
261
261
  decorators?: Record<string, Record<string, any>>;
262
262
  }
263
+ interface EnumDefinition {
264
+ name: string;
265
+ comment?: string;
266
+ decorators?: Record<string, Record<string, any>>;
267
+ }
263
268
  interface ComputedContextGlobal {
264
269
  db: RadsDb;
265
270
  schema: Schema;
@@ -380,4 +385,4 @@ declare function createRadsDb(args?: CreateRadsDbArgs): RadsDb;
380
385
  */
381
386
  declare function createRadsDbClient(args?: CreateRadsDbClientArgs): RadsDb;
382
387
 
383
- export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepPartial, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsFeature, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, computed, createRadsDb, createRadsDbClient, entity, field, getDriverInstance, precomputed, ui, validate };
388
+ export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepPartial, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, EnumDefinition, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsFeature, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, computed, createRadsDb, createRadsDbClient, entity, field, getDriverInstance, precomputed, ui, validate };
package/dist/index.mjs CHANGED
@@ -37,7 +37,7 @@ function getZodSchema(zodSchemas, schema, key) {
37
37
  return zodSchemas[key];
38
38
  const type = schema[key];
39
39
  if (type.enumValues) {
40
- const enums = _.fromPairs(type.enumValues.map((x) => [x, x]));
40
+ const enums = _.mapValues(type.enumValues, (v) => v.name);
41
41
  return z.nativeEnum(enums);
42
42
  }
43
43
  const objectSchema = {};
@@ -595,7 +595,7 @@ function validateEventSourcingSetup(schema, entityName, eventEntityName, aggrega
595
595
  if (!field)
596
596
  throw new Error(`"${eventEntityName}" must have field "${f}"`);
597
597
  if (expectedFields[f] === "enum") {
598
- if (!schema[field.type]?.enumValues?.includes("creation"))
598
+ if (!schema[field.type]?.enumValues?.creation)
599
599
  throw new Error(`Field "${eventEntityName}.${f}" must be enum that accepts value 'creation'`);
600
600
  } else {
601
601
  if (field.type !== expectedFields[f])
@@ -191,7 +191,7 @@ function parseDecorators(modifiers, ctx) {
191
191
  return decorators;
192
192
  }
193
193
  function getEnumValues(node, parentNode, ctx) {
194
- return node.types.map(node2 => {
194
+ const enumValuesArray = node.types.map(node2 => {
195
195
  if (node2.kind !== _typescript.SyntaxKind.LiteralType) {
196
196
  throw new Error(`Unexpected type definition - ${parentNode.getText(ctx.sourceFile)}`);
197
197
  }
@@ -199,8 +199,11 @@ function getEnumValues(node, parentNode, ctx) {
199
199
  literal
200
200
  } = node2;
201
201
  if (literal.kind !== _typescript.SyntaxKind.StringLiteral) throw new Error(`Unexpected type definition - ${parentNode.getText(ctx.sourceFile)}`);
202
- return literal.text;
202
+ return {
203
+ name: literal.text
204
+ };
203
205
  });
206
+ return _lodash.default.keyBy(enumValuesArray, "name");
204
207
  }
205
208
  function parseClassMember(node, parentName, ctx) {
206
209
  const name = node.name.getText(ctx.sourceFile);
@@ -289,8 +292,8 @@ function parseFieldTypeRecordEnum(parsedType, parentName, fieldName, ctx) {
289
292
  const enumValues = ctx.result[keyTypeName].enumValues;
290
293
  if (!enumValues) throw new Error(`Unexpected type - ${keyTypeName}`);
291
294
  const newTypeName = `${parentName}_${_lodash.default.upperFirst(fieldName)}`;
292
- const fieldsArray = enumValues.map(v => ({
293
- name: v,
295
+ const fieldsArray = _lodash.default.values(enumValues).map(v => ({
296
+ name: v.name,
294
297
  type: valueTypeName,
295
298
  isRequired: true
296
299
  }));
@@ -365,7 +368,11 @@ function getEnumValuesFromKeyOf(nodeType, ctx) {
365
368
  }
366
369
  if (!ctx.result[typeName]) ctx.result[typeName] = parseType(type.node, typeName, ctx);
367
370
  if (!ctx.result[typeName].fields) throw new Error(`Unexpected type - ${typeName}`);
368
- return Object.keys(ctx.result[typeName].fields);
371
+ return _lodash.default.mapValues(ctx.result[typeName].fields || {}, v => ({
372
+ name: v.name,
373
+ comment: v.comment,
374
+ decorators: v.decorators
375
+ }));
369
376
  }
370
377
  function getRelationDenormFields(ctx, node) {
371
378
  if (node.kind === _typescript.SyntaxKind.LiteralType) {
@@ -392,8 +399,8 @@ function verifyDefaultValueType(isArray, defaultValueDescription, type, supporte
392
399
  }
393
400
  if (!ctx.result[type] && ctx.typesMap[type]) ctx.result[type] = parseType(ctx.typesMap[type].node, type, ctx);
394
401
  const enumValues = ctx.result[type]?.enumValues;
395
- if (enumValues && !enumValues.includes(defaultValueDescription.value)) {
396
- const enumValuesStr = enumValues.map(x => `'x'`).join(", ");
402
+ if (enumValues && !enumValues[defaultValueDescription.value]) {
403
+ const enumValuesStr = _lodash.default.keys(enumValues).map(x => `'x'`).join(", ");
397
404
  throw new Error(`Default value must be one of: ${enumValuesStr}`);
398
405
  }
399
406
  }
@@ -164,15 +164,16 @@ function parseDecorators(modifiers, ctx) {
164
164
  return decorators;
165
165
  }
166
166
  function getEnumValues(node, parentNode, ctx) {
167
- return node.types.map((node2) => {
167
+ const enumValuesArray = node.types.map((node2) => {
168
168
  if (node2.kind !== SyntaxKind.LiteralType) {
169
169
  throw new Error(`Unexpected type definition - ${parentNode.getText(ctx.sourceFile)}`);
170
170
  }
171
171
  const { literal } = node2;
172
172
  if (literal.kind !== SyntaxKind.StringLiteral)
173
173
  throw new Error(`Unexpected type definition - ${parentNode.getText(ctx.sourceFile)}`);
174
- return literal.text;
174
+ return { name: literal.text };
175
175
  });
176
+ return _.keyBy(enumValuesArray, "name");
176
177
  }
177
178
  function parseClassMember(node, parentName, ctx) {
178
179
  const name = node.name.getText(ctx.sourceFile);
@@ -270,7 +271,7 @@ function parseFieldTypeRecordEnum(parsedType, parentName, fieldName, ctx) {
270
271
  if (!enumValues)
271
272
  throw new Error(`Unexpected type - ${keyTypeName}`);
272
273
  const newTypeName = `${parentName}_${_.upperFirst(fieldName)}`;
273
- const fieldsArray = enumValues.map((v) => ({ name: v, type: valueTypeName, isRequired: true }));
274
+ const fieldsArray = _.values(enumValues).map((v) => ({ name: v.name, type: valueTypeName, isRequired: true }));
274
275
  ctx.result[newTypeName] = {
275
276
  name: newTypeName,
276
277
  decorators: {},
@@ -342,7 +343,11 @@ function getEnumValuesFromKeyOf(nodeType, ctx) {
342
343
  ctx.result[typeName] = parseType(type.node, typeName, ctx);
343
344
  if (!ctx.result[typeName].fields)
344
345
  throw new Error(`Unexpected type - ${typeName}`);
345
- return Object.keys(ctx.result[typeName].fields);
346
+ return _.mapValues(ctx.result[typeName].fields || {}, (v) => ({
347
+ name: v.name,
348
+ comment: v.comment,
349
+ decorators: v.decorators
350
+ }));
346
351
  }
347
352
  function getRelationDenormFields(ctx, node) {
348
353
  if (node.kind === SyntaxKind.LiteralType) {
@@ -370,8 +375,8 @@ function verifyDefaultValueType(isArray, defaultValueDescription, type, supporte
370
375
  if (!ctx.result[type] && ctx.typesMap[type])
371
376
  ctx.result[type] = parseType(ctx.typesMap[type].node, type, ctx);
372
377
  const enumValues = ctx.result[type]?.enumValues;
373
- if (enumValues && !enumValues.includes(defaultValueDescription.value)) {
374
- const enumValuesStr = enumValues.map((x) => `'x'`).join(", ");
378
+ if (enumValues && !enumValues[defaultValueDescription.value]) {
379
+ const enumValuesStr = _.keys(enumValues).map((x) => `'x'`).join(", ");
375
380
  throw new Error(`Default value must be one of: ${enumValuesStr}`);
376
381
  }
377
382
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "files": [
5
5
  "dist",
6
6
  "drivers",