remult 0.26.3-exp.0 → 0.26.4

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,8 +1,8 @@
1
1
  import { createId } from '@paralleldrive/cuid2';
2
2
  import { v4 as uuid } from 'uuid';
3
3
  import { ValueConverters } from '../valueConverters.js';
4
- import { buildOptions } from './RepositoryImplementation.js';
5
- import { Validators, createValueValidator, getEnumValues } from '../validators.js';
4
+ import { buildOptions, fieldOptionalValuesFunctionKey, } from './RepositoryImplementation.js';
5
+ import { Validators, createValueValidator, getEnumValues, } from '../validators.js';
6
6
  import { relationInfoMemberInOptions } from './relationInfoMember.js';
7
7
  import { remultStatic } from '../remult-static.js';
8
8
  import { addValidator } from './addValidator.js';
@@ -84,10 +84,10 @@ export class Fields {
84
84
  }, ...options);
85
85
  }
86
86
  /**
87
- * A CUID (Collision Resistant Unique Identifier) field.
88
- * This id value is determined on the backend on insert, and can't be updated through the API.
89
- * The CUID is generated using the `@paralleldrive/cuid2` npm package.
90
- */
87
+ * A CUID (Collision Resistant Unique Identifier) field.
88
+ * This id value is determined on the backend on insert, and can't be updated through the API.
89
+ * The CUID is generated using the `@paralleldrive/cuid2` npm package.
90
+ */
91
91
  static cuid(...options) {
92
92
  return Field(() => String, {
93
93
  allowApiUpdate: false,
@@ -129,7 +129,9 @@ export class Fields {
129
129
  */
130
130
  static literal(optionalValues, ...options) {
131
131
  return Fields.string({
132
- validate: (entity, event) => Validators.in(optionalValues())(entity, event)
132
+ validate: (entity, event) => Validators.in(optionalValues())(entity, event),
133
+ //@ts-expect-error as we are adding this to options without it being defined in options
134
+ [fieldOptionalValuesFunctionKey]: optionalValues,
133
135
  }, ...options);
134
136
  }
135
137
  static enum(enumType, ...options) {
@@ -137,12 +139,16 @@ export class Fields {
137
139
  return Field(() =>
138
140
  //@ts-ignore
139
141
  enumType(), {
140
- validate: (entity, event) => Validators.enum(enumType())(entity, event)
142
+ validate: (entity, event) => Validators.enum(enumType())(entity, event),
143
+ [fieldOptionalValuesFunctionKey]: () => getEnumValues(enumType()),
141
144
  }, ...options, (options) => {
145
+ options[fieldOptionalValuesFunctionKey] = () => getEnumValues(enumType());
142
146
  if (valueConverter === undefined) {
143
147
  let enumObj = enumType();
144
148
  let enumValues = getEnumValues(enumObj);
145
- valueConverter = enumValues.find(x => typeof x === "string") ? ValueConverters.String : ValueConverters.Integer;
149
+ valueConverter = enumValues.find((x) => typeof x === 'string')
150
+ ? ValueConverters.String
151
+ : ValueConverters.Integer;
146
152
  }
147
153
  if (!options.valueConverter) {
148
154
  options.valueConverter = valueConverter;
@@ -16,6 +16,7 @@ import { entityDbName, fieldDbName, } from '../filter/filter-consumer-bridge-to-
16
16
  import { remultStatic } from '../remult-static.js';
17
17
  import { Validators } from '../validators.js';
18
18
  import { addValidator } from './addValidator.js';
19
+ import { isOfType } from '../isOfType.js';
19
20
  //import { remult } from "../remult-proxy";
20
21
  let classValidatorValidate = undefined;
21
22
  // import ("class-validator".toString())
@@ -2079,19 +2080,22 @@ export class ValueListInfo {
2079
2080
  }
2080
2081
  const typeCache = new Map();
2081
2082
  export function getValueList(type) {
2082
- {
2083
- const fr = type?.metadata?.valueType;
2084
- if (fr)
2085
- return ValueListInfo.get(fr).getValues();
2086
- }
2087
- {
2088
- const fr = type?.valueType;
2089
- if (fr)
2090
- return ValueListInfo.get(fr).getValues();
2091
- }
2092
- return ValueListInfo.get(type).getValues();
2083
+ let meta = type?.metadata;
2084
+ if (!meta && isOfType(type, 'options'))
2085
+ meta = type;
2086
+ type = meta?.valueType || type;
2087
+ if (type) {
2088
+ var options = type[storableMember];
2089
+ if (options)
2090
+ return ValueListInfo.get(type).getValues();
2091
+ }
2092
+ let optionalValues = meta?.options[fieldOptionalValuesFunctionKey];
2093
+ if (optionalValues)
2094
+ return optionalValues();
2095
+ return undefined;
2093
2096
  }
2094
2097
  export const storableMember = Symbol.for('storableMember');
2098
+ export const fieldOptionalValuesFunctionKey = Symbol.for('fieldOptionalValues');
2095
2099
  export function buildOptions(options, remult) {
2096
2100
  let r = {};
2097
2101
  for (const o of options) {
@@ -4,6 +4,10 @@ export {};
4
4
  //p1 - consider upsert (where,set)
5
5
  //p1 - consider id to also support keyof (id:['company','index'])
6
6
  //p1 - wait a second to close stream
7
+ //p1 - add solid tutorial to the getting started page
8
+ //p1 - update the examples section
9
+ //p1 - support dbnamesof in sqlexpression of entity
10
+ //p1 - adjust sql expression of entity docs to include a union example
7
11
  //p1 - reconsider update many, maybe the second parameter should be in a set option - break existing
8
12
  //p1 - add documentation for bun sqlite
9
13
  //p1 - describe entity
@@ -16,7 +20,7 @@ export {};
16
20
  //y2 - JY suggestion of having generate as part of the ensure schema - not sure
17
21
  //y2 - currently for string fields we default for 255 in knex (which is their default) why not just use text (varchar max) - and only use exact length when one is provided?
18
22
  //p2 - create foreign key constraints in user code - https://codesandbox.io/p/devbox/fk-validator-tdshcs
19
- //p1 - admin url1 - pocketbase use /_ for the admin //{allowed?:Allowed,url?:string} also checkout the admin* as it should probably be something else and didn't work in hono
23
+ //p2 - admin url1 - pocketbase use /_ for the admin //{allowed?:Allowed,url?:string} also checkout the admin* as it should probably be something else and didn't work in hono
20
24
  //p1 - article auth.js with express - played with it, requires type="module" and a few more configurations - https://github.com/noam-honig/express-auth
21
25
  //y2 - fix validators cache
22
26
  //y2 - should we validate relations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.26.3-exp.0",
3
+ "version": "0.26.4",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {
@@ -50,7 +50,10 @@ export interface RemultServerOptions<RequestType> {
50
50
  /** When set to true, will display an admin ui in the `/api/admin` url.
51
51
  * Can also be set to an arrow function for fine grained control
52
52
  * @example
53
- * allowed: ()=> remult.isAllowed('admin')
53
+ * admin: true
54
+ * @example
55
+ * admin: ()=> remult.isAllowed('admin')
56
+ * @see [allowed](http://remult.dev/docs/allowed.html)
54
57
  */
55
58
  admin?: Allowed;
56
59
  /** Storage to use for backend methods that use queue */
@@ -17,10 +17,10 @@ export declare class Fields {
17
17
  static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
18
18
  static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
19
19
  /**
20
- * A CUID (Collision Resistant Unique Identifier) field.
21
- * This id value is determined on the backend on insert, and can't be updated through the API.
22
- * The CUID is generated using the `@paralleldrive/cuid2` npm package.
23
- */
20
+ * A CUID (Collision Resistant Unique Identifier) field.
21
+ * This id value is determined on the backend on insert, and can't be updated through the API.
22
+ * The CUID is generated using the `@paralleldrive/cuid2` npm package.
23
+ */
24
24
  static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
25
25
  /**
26
26
  * Defines a field that can hold a value from a specified set of string literals.
@@ -87,7 +87,8 @@ var Fields = /** @class */ (function () {
87
87
  for (var _i = 0; _i < arguments.length; _i++) {
88
88
  options[_i] = arguments[_i];
89
89
  }
90
- return Field.apply(void 0, tslib_1.__spreadArray([function () { return Number; }, {
90
+ return Field.apply(void 0, tslib_1.__spreadArray([function () { return Number; },
91
+ {
91
92
  validate: validateNumber,
92
93
  }], tslib_1.__read(options), false));
93
94
  };
@@ -135,10 +136,10 @@ var Fields = /** @class */ (function () {
135
136
  }], tslib_1.__read(options), false));
136
137
  };
137
138
  /**
138
- * A CUID (Collision Resistant Unique Identifier) field.
139
- * This id value is determined on the backend on insert, and can't be updated through the API.
140
- * The CUID is generated using the `@paralleldrive/cuid2` npm package.
141
- */
139
+ * A CUID (Collision Resistant Unique Identifier) field.
140
+ * This id value is determined on the backend on insert, and can't be updated through the API.
141
+ * The CUID is generated using the `@paralleldrive/cuid2` npm package.
142
+ */
142
143
  Fields.cuid = function () {
143
144
  var options = [];
144
145
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -184,15 +185,22 @@ var Fields = /** @class */ (function () {
184
185
  * // This approach allows easy management and updates of the allowed values for the `status` field.
185
186
  */
186
187
  Fields.literal = function (optionalValues) {
188
+ var _a;
187
189
  var options = [];
188
190
  for (var _i = 1; _i < arguments.length; _i++) {
189
191
  options[_i - 1] = arguments[_i];
190
192
  }
191
- return Fields.string.apply(Fields, tslib_1.__spreadArray([{
192
- validate: function (entity, event) { return validators_js_1.Validators.in(optionalValues())(entity, event); }
193
- }], tslib_1.__read(options), false));
193
+ return Fields.string.apply(Fields, tslib_1.__spreadArray([(_a = {
194
+ validate: function (entity, event) {
195
+ return validators_js_1.Validators.in(optionalValues())(entity, event);
196
+ }
197
+ },
198
+ //@ts-expect-error as we are adding this to options without it being defined in options
199
+ _a[RepositoryImplementation_js_1.fieldOptionalValuesFunctionKey] = optionalValues,
200
+ _a)], tslib_1.__read(options), false));
194
201
  };
195
202
  Fields.enum = function (enumType) {
203
+ var _a;
196
204
  var options = [];
197
205
  for (var _i = 1; _i < arguments.length; _i++) {
198
206
  options[_i - 1] = arguments[_i];
@@ -201,14 +209,20 @@ var Fields = /** @class */ (function () {
201
209
  return Field.apply(void 0, tslib_1.__spreadArray(tslib_1.__spreadArray([function () {
202
210
  //@ts-ignore
203
211
  return (enumType());
204
- },
205
- {
206
- validate: function (entity, event) { return validators_js_1.Validators.enum(enumType())(entity, event); }
207
- }], tslib_1.__read(options), false), [function (options) {
212
+ }, (_a = {
213
+ validate: function (entity, event) { return validators_js_1.Validators.enum(enumType())(entity, event); }
214
+ },
215
+ _a[RepositoryImplementation_js_1.fieldOptionalValuesFunctionKey] = function () { return (0, validators_js_1.getEnumValues)(enumType()); },
216
+ _a)], tslib_1.__read(options), false), [function (options) {
217
+ options[RepositoryImplementation_js_1.fieldOptionalValuesFunctionKey] = function () {
218
+ return (0, validators_js_1.getEnumValues)(enumType());
219
+ };
208
220
  if (valueConverter === undefined) {
209
221
  var enumObj = enumType();
210
222
  var enumValues = (0, validators_js_1.getEnumValues)(enumObj);
211
- valueConverter = enumValues.find(function (x) { return typeof x === "string"; }) ? valueConverters_js_1.ValueConverters.String : valueConverters_js_1.ValueConverters.Integer;
223
+ valueConverter = enumValues.find(function (x) { return typeof x === 'string'; })
224
+ ? valueConverters_js_1.ValueConverters.String
225
+ : valueConverters_js_1.ValueConverters.Integer;
212
226
  }
213
227
  if (!options.valueConverter) {
214
228
  options.valueConverter = valueConverter;
@@ -295,6 +295,7 @@ export declare function getValueList<T>(field: FieldRef<T>): T[];
295
295
  export declare function getValueList<T>(field: FieldMetadata<T>): T[];
296
296
  export declare function getValueList<T>(type: ClassType<T>): T[];
297
297
  export declare const storableMember: unique symbol;
298
+ export declare const fieldOptionalValuesFunctionKey: unique symbol;
298
299
  export declare function buildOptions<entityType = any, valueType = any>(options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[], remult: Remult): FieldOptions<entityType, valueType>;
299
300
  export declare function decorateColumnSettings<valueType>(settings: FieldOptions<any, valueType>, remult: Remult): FieldOptions<any, valueType>;
300
301
  export declare class EntityBase {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRepository = exports.getEntityMetadata = exports.ControllerBase = exports.EntityBase = exports.decorateColumnSettings = exports.buildOptions = exports.storableMember = exports.getValueList = exports.ValueListInfo = exports.ValueListFieldType = exports.isAutoIncrement = exports.FieldType = exports.columnDefsImpl = exports.buildCaption = exports.CaptionTransformer = exports.FieldRefImplementation = exports.controllerRefImpl = exports.getControllerRef = exports.getFields = exports.rowHelperImplementation = exports.createOldEntity = exports.RepositoryImplementation = void 0;
3
+ exports.getRepository = exports.getEntityMetadata = exports.ControllerBase = exports.EntityBase = exports.decorateColumnSettings = exports.buildOptions = exports.fieldOptionalValuesFunctionKey = exports.storableMember = exports.getValueList = exports.ValueListInfo = exports.ValueListFieldType = exports.isAutoIncrement = exports.FieldType = exports.columnDefsImpl = exports.buildCaption = exports.CaptionTransformer = exports.FieldRefImplementation = exports.controllerRefImpl = exports.getControllerRef = exports.getFields = exports.rowHelperImplementation = exports.createOldEntity = exports.RepositoryImplementation = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var column_js_1 = require("../column.js");
6
6
  var CompoundIdField_js_1 = require("../CompoundIdField.js");
@@ -20,6 +20,7 @@ var filter_consumer_bridge_to_sql_request_js_1 = require("../filter/filter-consu
20
20
  var remult_static_js_1 = require("../remult-static.js");
21
21
  var validators_js_1 = require("../validators.js");
22
22
  var addValidator_js_1 = require("./addValidator.js");
23
+ var isOfType_js_1 = require("../isOfType.js");
23
24
  //import { remult } from "../remult-proxy";
24
25
  var classValidatorValidate = undefined;
25
26
  // import ("class-validator".toString())
@@ -3385,21 +3386,23 @@ var ValueListInfo = /** @class */ (function () {
3385
3386
  exports.ValueListInfo = ValueListInfo;
3386
3387
  var typeCache = new Map();
3387
3388
  function getValueList(type) {
3388
- var _a;
3389
- {
3390
- var fr = (_a = type === null || type === void 0 ? void 0 : type.metadata) === null || _a === void 0 ? void 0 : _a.valueType;
3391
- if (fr)
3392
- return ValueListInfo.get(fr).getValues();
3389
+ var meta = type === null || type === void 0 ? void 0 : type.metadata;
3390
+ if (!meta && (0, isOfType_js_1.isOfType)(type, 'options'))
3391
+ meta = type;
3392
+ type = (meta === null || meta === void 0 ? void 0 : meta.valueType) || type;
3393
+ if (type) {
3394
+ var options = type[exports.storableMember];
3395
+ if (options)
3396
+ return ValueListInfo.get(type).getValues();
3393
3397
  }
3394
- {
3395
- var fr = type === null || type === void 0 ? void 0 : type.valueType;
3396
- if (fr)
3397
- return ValueListInfo.get(fr).getValues();
3398
- }
3399
- return ValueListInfo.get(type).getValues();
3398
+ var optionalValues = meta === null || meta === void 0 ? void 0 : meta.options[exports.fieldOptionalValuesFunctionKey];
3399
+ if (optionalValues)
3400
+ return optionalValues();
3401
+ return undefined;
3400
3402
  }
3401
3403
  exports.getValueList = getValueList;
3402
3404
  exports.storableMember = Symbol.for('storableMember');
3405
+ exports.fieldOptionalValuesFunctionKey = Symbol.for('fieldOptionalValues');
3403
3406
  function buildOptions(options, remult) {
3404
3407
  var e_47, _a;
3405
3408
  var r = {};
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  //p1 - consider upsert (where,set)
6
6
  //p1 - consider id to also support keyof (id:['company','index'])
7
7
  //p1 - wait a second to close stream
8
+ //p1 - add solid tutorial to the getting started page
9
+ //p1 - update the examples section
10
+ //p1 - support dbnamesof in sqlexpression of entity
11
+ //p1 - adjust sql expression of entity docs to include a union example
8
12
  //p1 - reconsider update many, maybe the second parameter should be in a set option - break existing
9
13
  //p1 - add documentation for bun sqlite
10
14
  //p1 - describe entity
@@ -17,7 +21,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
21
  //y2 - JY suggestion of having generate as part of the ensure schema - not sure
18
22
  //y2 - currently for string fields we default for 255 in knex (which is their default) why not just use text (varchar max) - and only use exact length when one is provided?
19
23
  //p2 - create foreign key constraints in user code - https://codesandbox.io/p/devbox/fk-validator-tdshcs
20
- //p1 - admin url1 - pocketbase use /_ for the admin //{allowed?:Allowed,url?:string} also checkout the admin* as it should probably be something else and didn't work in hono
24
+ //p2 - admin url1 - pocketbase use /_ for the admin //{allowed?:Allowed,url?:string} also checkout the admin* as it should probably be something else and didn't work in hono
21
25
  //p1 - article auth.js with express - played with it, requires type="module" and a few more configurations - https://github.com/noam-honig/express-auth
22
26
  //y2 - fix validators cache
23
27
  //y2 - should we validate relations