remult 3.1.0 → 3.1.1

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/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ArrayEntityDataProvider } from './src/data-providers/array-entity-data-provider.js';
2
+ export { standardSchema } from './src/standard-schema/index.js';
2
3
  export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListInfo, } from './src/remult3/RepositoryImplementation.js';
3
4
  import { LabelTransformer } from './src/remult3/RepositoryImplementation.js';
4
5
  export { LabelTransformer } from './src/remult3/RepositoryImplementation.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Implementation of the [Standard Schema](https://standardschema.dev/) specification
3
+ *
4
+ * @usage
5
+ * ```ts
6
+ * // The schema for the entire entity
7
+ * const schema = standardSchema(repo(User))
8
+ *
9
+ * // The schema for a specific field
10
+ * const schema = standardSchema(repo(User), 'id')
11
+ *
12
+ * // The schema for multiple fields
13
+ * const schema = standardSchema(repo(User), 'name', 'age')
14
+ * ```
15
+ */
16
+ export function standardSchema(repo, ...fields) {
17
+ return {
18
+ '~standard': {
19
+ version: 1,
20
+ vendor: 'remult',
21
+ async validate(value) {
22
+ const item = value;
23
+ try {
24
+ const error = await repo.validate(item, ...fields);
25
+ if (error && error.modelState) {
26
+ return {
27
+ issues: Object.entries(error.modelState).map(([key, message]) => ({
28
+ message: message,
29
+ path: [key],
30
+ })),
31
+ };
32
+ }
33
+ }
34
+ catch (err) {
35
+ if (err instanceof Error) {
36
+ return { issues: [{ message: err.message, path: [] }] };
37
+ }
38
+ }
39
+ if (fields.length > 0) {
40
+ const filteredItem = {};
41
+ for (const field of fields) {
42
+ if (field in item) {
43
+ filteredItem[field] = item[field];
44
+ }
45
+ }
46
+ return { value: filteredItem };
47
+ }
48
+ return { value: item };
49
+ },
50
+ },
51
+ };
52
+ }
package/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { ArrayEntityDataProvider } from './src/data-providers/array-entity-data-
4
4
  export type { ClassType } from './classType.js';
5
5
  export { ValidateFieldEvent, MembersOnly, NumericKeys, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, FindOptionsBase, QueryResult, QueryOptions, UpsertOptions, Repository, GroupByOptions, GroupByResult, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, Subscribable, RefSubscriber, RefSubscriberBase, RelationOptions, ObjectMembersOnly, MembersToInclude, RepositoryRelations, EntityIdFields, ClassFieldDecorator, ClassFieldDecoratorContextStub, //n1 consider removing in ts5
6
6
  LifecycleEvent, FieldsRefBase, FieldsRefForEntityBase, RepositoryRelationsForEntityBase, ControllerRefForControllerBase, ControllerRefBase, ControllerRef, EntityRefForEntityBase, IdMetadata, FindFirstOptionsBase, } from './src/remult3/remult3.js';
7
+ export { standardSchema } from './src/standard-schema/index.js';
7
8
  export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, } from './src/remult3/RepositoryImplementation.js';
8
9
  export { LabelTransformer } from './src/remult3/RepositoryImplementation.js';
9
10
  /**
package/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InMemoryLiveQueryStorage = exports.remult = exports.ValueConverters = exports.createValueValidator = exports.createValueValidatorWithArgs = exports.createValidatorWithArgs = exports.createValidator = exports.valueValidator = exports.Validators = exports.UrlBuilder = exports.Filter = exports.CompoundIdField = exports.Sort = exports.EventSource = exports.isBackend = exports.withRemult = exports.Remult = exports.Allow = exports.ForbiddenError = exports.ProgressListener = exports.BackendMethod = exports.Controller = exports.JsonEntityIndexedDbStorage = exports.JsonEntityOpfsStorage = exports.JsonDataProvider = exports.dbNamesOf = exports.CustomSqlFilterBuilder = exports.SqlDatabase = exports.InMemoryDataProvider = exports.RestDataProvider = exports.EntityError = exports.describeEntity = exports.describeBackendMethods = exports.describeClass = exports.IdEntity = exports.Relations = exports.Fields = exports.Field = exports.getEntityRef = exports.Entity = exports.CaptionTransformer = exports.LabelTransformer = exports.ValueListInfo = exports.getValueList = exports.ValueListFieldType = exports.getFields = exports.FieldType = exports.ControllerBase = exports.EntityBase = exports.ArrayEntityDataProvider = void 0;
4
- exports.SubscriptionChannel = void 0;
3
+ exports.remult = exports.ValueConverters = exports.createValueValidator = exports.createValueValidatorWithArgs = exports.createValidatorWithArgs = exports.createValidator = exports.valueValidator = exports.Validators = exports.UrlBuilder = exports.Filter = exports.CompoundIdField = exports.Sort = exports.EventSource = exports.isBackend = exports.withRemult = exports.Remult = exports.Allow = exports.ForbiddenError = exports.ProgressListener = exports.BackendMethod = exports.Controller = exports.JsonEntityIndexedDbStorage = exports.JsonEntityOpfsStorage = exports.JsonDataProvider = exports.dbNamesOf = exports.CustomSqlFilterBuilder = exports.SqlDatabase = exports.InMemoryDataProvider = exports.RestDataProvider = exports.EntityError = exports.describeEntity = exports.describeBackendMethods = exports.describeClass = exports.IdEntity = exports.Relations = exports.Fields = exports.Field = exports.getEntityRef = exports.Entity = exports.CaptionTransformer = exports.LabelTransformer = exports.ValueListInfo = exports.getValueList = exports.ValueListFieldType = exports.getFields = exports.FieldType = exports.ControllerBase = exports.EntityBase = exports.standardSchema = exports.ArrayEntityDataProvider = void 0;
4
+ exports.SubscriptionChannel = exports.InMemoryLiveQueryStorage = void 0;
5
5
  exports.repo = repo;
6
6
  var array_entity_data_provider_js_1 = require("./src/data-providers/array-entity-data-provider.js");
7
7
  Object.defineProperty(exports, "ArrayEntityDataProvider", { enumerable: true, get: function () { return array_entity_data_provider_js_1.ArrayEntityDataProvider; } });
8
+ var index_js_1 = require("./src/standard-schema/index.js");
9
+ Object.defineProperty(exports, "standardSchema", { enumerable: true, get: function () { return index_js_1.standardSchema; } });
8
10
  var RepositoryImplementation_js_1 = require("./src/remult3/RepositoryImplementation.js");
9
11
  Object.defineProperty(exports, "EntityBase", { enumerable: true, get: function () { return RepositoryImplementation_js_1.EntityBase; } });
10
12
  Object.defineProperty(exports, "ControllerBase", { enumerable: true, get: function () { return RepositoryImplementation_js_1.ControllerBase; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {
@@ -0,0 +1,56 @@
1
+ /** The Standard Schema interface. */
2
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
3
+ /** The Standard Schema properties. */
4
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
5
+ }
6
+ export declare namespace StandardSchemaV1 {
7
+ /** The Standard Schema properties interface. */
8
+ export interface Props<Input = unknown, Output = Input> {
9
+ /** The version number of the standard. */
10
+ readonly version: 1;
11
+ /** The vendor name of the schema library. */
12
+ readonly vendor: string;
13
+ /** Validates unknown input values. */
14
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
15
+ /** Inferred types associated with the schema. */
16
+ readonly types?: Types<Input, Output> | undefined;
17
+ }
18
+ /** The result interface of the validate function. */
19
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
20
+ /** The result interface if validation succeeds. */
21
+ export interface SuccessResult<Output> {
22
+ /** The typed output value. */
23
+ readonly value: Output;
24
+ /** The non-existent issues. */
25
+ readonly issues?: undefined;
26
+ }
27
+ /** The result interface if validation fails. */
28
+ export interface FailureResult {
29
+ /** The issues of failed validation. */
30
+ readonly issues: ReadonlyArray<Issue>;
31
+ }
32
+ /** The issue interface of the failure output. */
33
+ export interface Issue {
34
+ /** The error message of the issue. */
35
+ readonly message: string;
36
+ /** The path of the issue, if any. */
37
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
38
+ }
39
+ /** The path segment interface of the issue. */
40
+ export interface PathSegment {
41
+ /** The key representing a path segment. */
42
+ readonly key: PropertyKey;
43
+ }
44
+ /** The Standard Schema types interface. */
45
+ export interface Types<Input = unknown, Output = Input> {
46
+ /** The input type of the schema. */
47
+ readonly input: Input;
48
+ /** The output type of the schema. */
49
+ readonly output: Output;
50
+ }
51
+ /** Infers the input type of a Standard Schema. */
52
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
53
+ /** Infers the output type of a Standard Schema. */
54
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
55
+ export {};
56
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ import type { MembersOnly, Repository } from '../../index.js';
2
+ import type { StandardSchemaV1 } from './StandardSchemaV1.js';
3
+ type OutputType<entityType, fields extends string[]> = fields extends [] ? Partial<entityType> : Pick<entityType, Extract<keyof entityType, fields[number]>>;
4
+ interface RemultEntitySchema<entityType, fields extends string[] = []> extends StandardSchemaV1<Partial<entityType>, OutputType<entityType, fields>> {
5
+ }
6
+ /**
7
+ * Implementation of the [Standard Schema](https://standardschema.dev/) specification
8
+ *
9
+ * @usage
10
+ * ```ts
11
+ * // The schema for the entire entity
12
+ * const schema = standardSchema(repo(User))
13
+ *
14
+ * // The schema for a specific field
15
+ * const schema = standardSchema(repo(User), 'id')
16
+ *
17
+ * // The schema for multiple fields
18
+ * const schema = standardSchema(repo(User), 'name', 'age')
19
+ * ```
20
+ */
21
+ export declare function standardSchema<entityType, fieldsType extends Extract<keyof MembersOnly<entityType>, string>[] = []>(repo: Repository<entityType>, ...fields: fieldsType): RemultEntitySchema<entityType, fieldsType>;
22
+ export {};
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.standardSchema = standardSchema;
4
+ var tslib_1 = require("tslib");
5
+ /**
6
+ * Implementation of the [Standard Schema](https://standardschema.dev/) specification
7
+ *
8
+ * @usage
9
+ * ```ts
10
+ * // The schema for the entire entity
11
+ * const schema = standardSchema(repo(User))
12
+ *
13
+ * // The schema for a specific field
14
+ * const schema = standardSchema(repo(User), 'id')
15
+ *
16
+ * // The schema for multiple fields
17
+ * const schema = standardSchema(repo(User), 'name', 'age')
18
+ * ```
19
+ */
20
+ function standardSchema(repo) {
21
+ var fields = [];
22
+ for (var _i = 1; _i < arguments.length; _i++) {
23
+ fields[_i - 1] = arguments[_i];
24
+ }
25
+ return {
26
+ '~standard': {
27
+ version: 1,
28
+ vendor: 'remult',
29
+ validate: function (value) {
30
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
31
+ var item, error, err_1, filteredItem, fields_1, fields_1_1, field;
32
+ var e_1, _a;
33
+ return tslib_1.__generator(this, function (_b) {
34
+ switch (_b.label) {
35
+ case 0:
36
+ item = value;
37
+ _b.label = 1;
38
+ case 1:
39
+ _b.trys.push([1, 3, , 4]);
40
+ return [4 /*yield*/, repo.validate.apply(repo, tslib_1.__spreadArray([item], tslib_1.__read(fields), false))];
41
+ case 2:
42
+ error = _b.sent();
43
+ if (error && error.modelState) {
44
+ return [2 /*return*/, {
45
+ issues: Object.entries(error.modelState).map(function (_a) {
46
+ var _b = tslib_1.__read(_a, 2), key = _b[0], message = _b[1];
47
+ return ({
48
+ message: message,
49
+ path: [key],
50
+ });
51
+ }),
52
+ }];
53
+ }
54
+ return [3 /*break*/, 4];
55
+ case 3:
56
+ err_1 = _b.sent();
57
+ if (err_1 instanceof Error) {
58
+ return [2 /*return*/, { issues: [{ message: err_1.message, path: [] }] }];
59
+ }
60
+ return [3 /*break*/, 4];
61
+ case 4:
62
+ if (fields.length > 0) {
63
+ filteredItem = {};
64
+ try {
65
+ for (fields_1 = tslib_1.__values(fields), fields_1_1 = fields_1.next(); !fields_1_1.done; fields_1_1 = fields_1.next()) {
66
+ field = fields_1_1.value;
67
+ if (field in item) {
68
+ filteredItem[field] = item[field];
69
+ }
70
+ }
71
+ }
72
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
73
+ finally {
74
+ try {
75
+ if (fields_1_1 && !fields_1_1.done && (_a = fields_1.return)) _a.call(fields_1);
76
+ }
77
+ finally { if (e_1) throw e_1.error; }
78
+ }
79
+ return [2 /*return*/, { value: filteredItem }];
80
+ }
81
+ return [2 /*return*/, { value: item }];
82
+ }
83
+ });
84
+ });
85
+ },
86
+ },
87
+ };
88
+ }