@snowtop/ent 0.1.0-alpha1 → 0.1.0-alpha2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha1",
3
+ "version": "0.1.0-alpha2",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -3,8 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseSchema = void 0;
4
4
  function processFields(src, patternName) {
5
5
  const ret = [];
6
- for (const name in src) {
7
- const field = src[name];
6
+ let m = {};
7
+ if (Array.isArray(src)) {
8
+ for (const field of src) {
9
+ const name = field.name;
10
+ if (!name) {
11
+ throw new Error(`name is required`);
12
+ }
13
+ m[name] = field;
14
+ }
15
+ }
16
+ else {
17
+ m = src;
18
+ }
19
+ for (const name in m) {
20
+ const field = m[name];
8
21
  let f = { name, ...field };
9
22
  f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
10
23
  f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
@@ -4,7 +4,7 @@ export declare type FieldMap = {
4
4
  [key: string]: Field;
5
5
  };
6
6
  export default interface Schema {
7
- fields: FieldMap;
7
+ fields: FieldMap | Field[];
8
8
  tableName?: string;
9
9
  patterns?: Pattern[];
10
10
  edges?: Edge[];
@@ -60,7 +60,7 @@ export interface AssocEdgeGroup {
60
60
  export declare type Edge = AssocEdge;
61
61
  export interface Pattern {
62
62
  name: string;
63
- fields: FieldMap;
63
+ fields: FieldMap | Field[];
64
64
  edges?: Edge[];
65
65
  }
66
66
  export declare enum DBType {
@@ -139,6 +139,7 @@ export interface FieldOptions {
139
139
  derivedWhenEmbedded?: boolean;
140
140
  polymorphic?: boolean | PolymorphicOptions;
141
141
  getDerivedFields?(name: string): FieldMap;
142
+ [x: string]: any;
142
143
  }
143
144
  export interface PolymorphicOptions {
144
145
  types?: string[];
package/schema/schema.js CHANGED
@@ -37,6 +37,19 @@ function getFields(value) {
37
37
  schema = new value();
38
38
  }
39
39
  function addFields(fields) {
40
+ if (Array.isArray(fields)) {
41
+ for (const field of fields) {
42
+ const name = field.name;
43
+ if (!name) {
44
+ throw new Error(`name required`);
45
+ }
46
+ if (field.getDerivedFields !== undefined) {
47
+ addFields(field.getDerivedFields(name));
48
+ }
49
+ m.set(name, field);
50
+ }
51
+ return;
52
+ }
40
53
  for (const name in fields) {
41
54
  const field = fields[name];
42
55
  if (field.getDerivedFields !== undefined) {