oak-domain 4.2.2 → 4.2.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.
Files changed (53) hide show
  1. package/lib/base-app-domain/ActionDefDict.d.ts +8 -8
  2. package/lib/base-app-domain/Oper/Schema.d.ts +158 -158
  3. package/lib/base-app-domain/Oper/Storage.js +56 -56
  4. package/lib/base-app-domain/User/Action.d.ts +11 -11
  5. package/lib/base-app-domain/User/Action.js +12 -12
  6. package/lib/base-app-domain/UserEntityGrant/Action.d.ts +5 -5
  7. package/lib/base-app-domain/UserEntityGrant/Action.js +5 -5
  8. package/lib/compiler/schemalBuilder.js +4167 -4167
  9. package/lib/entities/Oper.d.ts +12 -12
  10. package/lib/entities/Oper.js +36 -36
  11. package/lib/entities/User.d.ts +18 -18
  12. package/lib/entities/User.js +32 -32
  13. package/lib/index.d.ts +1 -1
  14. package/lib/index.js +3 -3
  15. package/lib/store/AsyncRowStore.d.ts +66 -66
  16. package/lib/store/CascadeStore.d.ts +109 -109
  17. package/lib/store/CascadeStore.js +1728 -1726
  18. package/lib/store/RelationAuth.js +1209 -1209
  19. package/lib/store/TriggerExecutor.js +468 -468
  20. package/lib/store/actionDef.js +278 -278
  21. package/lib/store/checker.js +487 -487
  22. package/lib/store/relation.d.ts +12 -12
  23. package/lib/store/relation.js +74 -74
  24. package/lib/triggers/index.d.ts +5 -5
  25. package/lib/triggers/index.js +28 -28
  26. package/lib/types/Configuration.d.ts +42 -42
  27. package/lib/types/Configuration.js +3 -3
  28. package/lib/types/Connector.d.ts +39 -38
  29. package/lib/types/Entity.d.ts +209 -209
  30. package/lib/types/Sync.d.ts +74 -69
  31. package/lib/types/Sync.js +9 -9
  32. package/lib/types/index.d.ts +27 -27
  33. package/lib/types/index.js +30 -30
  34. package/lib/utils/SimpleConnector.d.ts +81 -64
  35. package/lib/utils/SimpleConnector.js +217 -206
  36. package/lib/utils/assert.d.ts +5 -5
  37. package/lib/utils/projection.d.ts +4 -4
  38. package/lib/utils/relationPath.d.ts +31 -31
  39. package/lib/utils/relationPath.js +202 -202
  40. package/package.json +51 -51
  41. package/src/entities/ActionAuth.ts +41 -41
  42. package/src/entities/I18n.ts +45 -45
  43. package/src/entities/Modi.ts +69 -69
  44. package/src/entities/ModiEntity.ts +26 -26
  45. package/src/entities/Oper.ts +48 -48
  46. package/src/entities/OperEntity.ts +27 -27
  47. package/src/entities/Path.ts +43 -43
  48. package/src/entities/Relation.ts +43 -43
  49. package/src/entities/RelationAuth.ts +44 -44
  50. package/src/entities/User.ts +48 -48
  51. package/src/entities/UserEntityClaim.ts +29 -29
  52. package/src/entities/UserEntityGrant.ts +24 -24
  53. package/src/entities/UserRelation.ts +50 -50
@@ -1,209 +1,209 @@
1
- import { OneOf } from '.';
2
- import { ReadOnlyAction } from '../actions/action';
3
- import { PrimaryKey, Sequence } from './DataType';
4
- type TriggerDataAttributeType = '$$triggerData$$';
5
- type TriggerUuidAttributeType = '$$triggerUuid$$';
6
- type PrimaryKeyAttributeType = 'id';
7
- type CreateAtAttributeType = '$$createAt$$';
8
- type UpdateAtAttributeType = '$$updateAt$$';
9
- type DeleteAtAttributeType = '$$deleteAt$$';
10
- type SeqAttributeType = '$$seq$$';
11
- export declare const TriggerDataAttribute = "$$triggerData$$";
12
- export declare const TriggerUuidAttribute = "$$triggerUuid$$";
13
- export declare const PrimaryKeyAttribute = "id";
14
- export declare const CreateAtAttribute = "$$createAt$$";
15
- export declare const UpdateAtAttribute = "$$updateAt$$";
16
- export declare const DeleteAtAttribute = "$$deleteAt$$";
17
- export declare const SeqAttribute = "$$seq$$";
18
- export type InstinctiveAttributes = PrimaryKeyAttributeType | CreateAtAttributeType | UpdateAtAttributeType | DeleteAtAttributeType | TriggerDataAttributeType | SeqAttributeType | TriggerUuidAttributeType;
19
- export declare const initinctiveAttributes: string[];
20
- type FilterPart<A extends string, F extends Object | undefined> = {
21
- filter?: A extends 'create' ? undefined : F;
22
- indexFrom?: A extends 'create' ? undefined : number;
23
- count?: A extends 'create' ? undefined : number;
24
- };
25
- export type SelectOption = {
26
- dontCollect?: boolean;
27
- blockTrigger?: true;
28
- obscure?: boolean;
29
- forUpdate?: true;
30
- includedDeleted?: true;
31
- ignoreAttrMiss?: true;
32
- dummy?: 1;
33
- };
34
- export type OperateOption = {
35
- blockTrigger?: true;
36
- dontCollect?: boolean;
37
- dontCreateOper?: boolean;
38
- includedDeleted?: true;
39
- allowExists?: boolean;
40
- modiParentId?: string;
41
- modiParentEntity?: string;
42
- deletePhysically?: boolean;
43
- applyingModi?: boolean;
44
- dummy?: 1;
45
- };
46
- export type FormUpdateData<SH extends GeneralEntityShape> = Partial<{
47
- [K in keyof Omit<SH, "id" | "$$createAt$$" | "$$seq$$">]: SH[K] | null;
48
- }>;
49
- export type FormCreateData<SH extends GeneralEntityShape> = Partial<SH> & {
50
- id: string;
51
- };
52
- export type Operation<A extends string, D extends Projection, F extends Filter | undefined = undefined, S extends Sorter | undefined = undefined> = {
53
- id: string;
54
- action: A;
55
- data: D;
56
- sorter?: S;
57
- bornAt?: number;
58
- } & FilterPart<A, F>;
59
- export type Selection<A extends ReadOnlyAction, D extends Projection, F extends Filter | undefined = undefined, S extends Sorter | undefined = undefined> = {
60
- id?: string;
61
- action?: A;
62
- data: D;
63
- sorter?: S;
64
- } & FilterPart<A, F> & {
65
- randomRange?: number;
66
- total?: number;
67
- distinct?: true;
68
- };
69
- export interface EntityShape {
70
- id: PrimaryKey;
71
- $$seq$$: Sequence;
72
- $$createAt$$: number | Date;
73
- $$updateAt$$: number | Date;
74
- $$deleteAt$$?: number | Date | null;
75
- }
76
- export interface GeneralEntityShape extends EntityShape {
77
- [K: string]: any;
78
- }
79
- export type MakeAction<A extends string> = A;
80
- export interface EntityDef {
81
- Schema: GeneralEntityShape;
82
- OpSchema: GeneralEntityShape;
83
- Action: string;
84
- ParticularAction?: string;
85
- Selection: Selection<'select', Projection, Filter, Sorter>;
86
- Aggregation: DeduceAggregation<Projection, Filter, Sorter>;
87
- Operation: CUDOperation;
88
- Create: CreateOperation;
89
- CreateSingle: CreateSingleOperation;
90
- CreateMulti: CreateMultipleOperation;
91
- Update: UpdateOperation;
92
- Remove: RemoveOperation;
93
- Relation?: string;
94
- }
95
- export interface EntityDict {
96
- [E: string]: EntityDef;
97
- }
98
- export interface OtmSubProjection extends Omit<Operation<'select', any, any, any>, 'action'> {
99
- $entity: string;
100
- }
101
- export type AggregationOp = `#max-${number}` | `#min-${number}` | `#avg-${number}` | `#count-${number}` | `#sum-${number}`;
102
- export type DeduceAggregationData<P extends Projection> = {
103
- [A in AggregationOp]?: P;
104
- } & OneOf<{
105
- distinct?: true;
106
- '#aggr'?: P;
107
- }>;
108
- export type AggregationResult<SH extends GeneralEntityShape> = Array<{
109
- [A in AggregationOp]?: number | string;
110
- } & {
111
- '#data'?: Partial<SH>;
112
- }>;
113
- export type AttrFilter<SH extends GeneralEntityShape> = {
114
- [K in keyof SH]?: any;
115
- };
116
- type SortAttr = {
117
- [K: string]: any;
118
- };
119
- type SorterItem = {
120
- $attr: SortAttr;
121
- $direction?: "asc" | "desc";
122
- };
123
- type Sorter = Array<SorterItem>;
124
- type Filter = {
125
- [K: string]: any;
126
- };
127
- type Projection = {
128
- [K: string]: any;
129
- };
130
- export type DeduceAggregation<P extends Projection, F extends Filter, S extends Sorter> = Omit<Selection<'aggregate', DeduceAggregationData<P>, F, S>, 'action'>;
131
- type CreateOperationData = {
132
- id: string;
133
- [K: string]: any;
134
- };
135
- type CreateSingleOperation = Operation<'create', CreateOperationData, undefined, undefined>;
136
- type CreateMultipleOperation = Operation<'create', Array<CreateOperationData>, undefined, undefined>;
137
- type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
138
- type UpdateOperationData = {
139
- id?: never;
140
- [k: string]: any;
141
- };
142
- export type UpdateOperation = Operation<string, UpdateOperationData, Filter, Sorter>;
143
- type RemoveOperationData = {
144
- [k: string]: any;
145
- };
146
- export type RemoveOperation = Operation<'remove', RemoveOperationData, Filter, Sorter>;
147
- export type CUDOperation = CreateOperation | UpdateOperation | RemoveOperation;
148
- export type CreateOpResult<ED extends EntityDict, T extends keyof ED> = {
149
- id: string;
150
- a: 'c';
151
- e: T;
152
- d: ED[T]['OpSchema'] | ED[T]['OpSchema'][];
153
- };
154
- export type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
155
- id: string;
156
- a: 'u';
157
- e: T;
158
- d: UpdateOperationData;
159
- f?: Filter;
160
- };
161
- export type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = {
162
- id: string;
163
- a: 'r';
164
- e: T;
165
- f?: Filter;
166
- };
167
- export type RelationHierarchy<R extends string> = {
168
- [K in R]?: R[];
169
- };
170
- export type CascadeRelationItem = {
171
- cascadePath: string;
172
- relations?: string[];
173
- };
174
- export type CascadeRelationAuth<R extends string> = {
175
- [K in R]?: CascadeRelationItem | (CascadeRelationItem | CascadeRelationItem[])[];
176
- };
177
- export type SelectOpResult<ED extends EntityDict> = {
178
- a: 's';
179
- d: {
180
- [T in keyof ED]?: {
181
- [ID: string]: Partial<ED[T]['OpSchema']>;
182
- };
183
- };
184
- };
185
- export type OpRecord<ED extends EntityDict> = CreateOpResult<ED, keyof ED> | UpdateOpResult<ED, keyof ED> | RemoveOpResult<ED, keyof ED> | SelectOpResult<ED>;
186
- export type OperationResult<ED extends EntityDict> = {
187
- [K in keyof ED]?: {
188
- [A in ED[K]['Action']]?: number;
189
- };
190
- };
191
- export type ActionType = 'readOnly' | 'appendOnly' | 'excludeUpdate' | 'excludeRemove' | 'crud';
192
- export type Configuration = {
193
- actionType?: ActionType;
194
- static?: boolean;
195
- };
196
- export type AuthDeduceRelationMap<ED extends EntityDict> = {
197
- [T in keyof ED]?: keyof ED[T]['OpSchema'];
198
- };
199
- export type SelectFreeEntities<ED extends EntityDict> = (keyof ED)[];
200
- export type UpdateFreeDict<ED extends EntityDict> = {
201
- [A in keyof ED]?: string[];
202
- };
203
- export type OtmKey<K extends string> = K | `${K}$${number}`;
204
- export interface SubDataDef<ED extends EntityDict, T extends keyof ED> {
205
- id: string;
206
- entity: T;
207
- filter: ED[T]['Selection']['filter'];
208
- }
209
- export {};
1
+ import { OneOf } from '.';
2
+ import { ReadOnlyAction } from '../actions/action';
3
+ import { PrimaryKey, Sequence } from './DataType';
4
+ type TriggerDataAttributeType = '$$triggerData$$';
5
+ type TriggerUuidAttributeType = '$$triggerUuid$$';
6
+ type PrimaryKeyAttributeType = 'id';
7
+ type CreateAtAttributeType = '$$createAt$$';
8
+ type UpdateAtAttributeType = '$$updateAt$$';
9
+ type DeleteAtAttributeType = '$$deleteAt$$';
10
+ type SeqAttributeType = '$$seq$$';
11
+ export declare const TriggerDataAttribute = "$$triggerData$$";
12
+ export declare const TriggerUuidAttribute = "$$triggerUuid$$";
13
+ export declare const PrimaryKeyAttribute = "id";
14
+ export declare const CreateAtAttribute = "$$createAt$$";
15
+ export declare const UpdateAtAttribute = "$$updateAt$$";
16
+ export declare const DeleteAtAttribute = "$$deleteAt$$";
17
+ export declare const SeqAttribute = "$$seq$$";
18
+ export type InstinctiveAttributes = PrimaryKeyAttributeType | CreateAtAttributeType | UpdateAtAttributeType | DeleteAtAttributeType | TriggerDataAttributeType | SeqAttributeType | TriggerUuidAttributeType;
19
+ export declare const initinctiveAttributes: string[];
20
+ type FilterPart<A extends string, F extends Object | undefined> = {
21
+ filter?: A extends 'create' ? undefined : F;
22
+ indexFrom?: A extends 'create' ? undefined : number;
23
+ count?: A extends 'create' ? undefined : number;
24
+ };
25
+ export type SelectOption = {
26
+ dontCollect?: boolean;
27
+ blockTrigger?: true;
28
+ obscure?: boolean;
29
+ forUpdate?: true | 'skip locked' | 'nowait';
30
+ includedDeleted?: true;
31
+ ignoreAttrMiss?: true;
32
+ dummy?: 1;
33
+ };
34
+ export type OperateOption = {
35
+ blockTrigger?: true;
36
+ dontCollect?: boolean;
37
+ dontCreateOper?: boolean;
38
+ includedDeleted?: true;
39
+ allowExists?: boolean;
40
+ modiParentId?: string;
41
+ modiParentEntity?: string;
42
+ deletePhysically?: boolean;
43
+ applyingModi?: boolean;
44
+ dummy?: 1;
45
+ };
46
+ export type FormUpdateData<SH extends GeneralEntityShape> = Partial<{
47
+ [K in keyof Omit<SH, "id" | "$$createAt$$" | "$$seq$$">]: SH[K] | null;
48
+ }>;
49
+ export type FormCreateData<SH extends GeneralEntityShape> = Partial<SH> & {
50
+ id: string;
51
+ };
52
+ export type Operation<A extends string, D extends Projection, F extends Filter | undefined = undefined, S extends Sorter | undefined = undefined> = {
53
+ id: string;
54
+ action: A;
55
+ data: D;
56
+ sorter?: S;
57
+ bornAt?: number;
58
+ } & FilterPart<A, F>;
59
+ export type Selection<A extends ReadOnlyAction, D extends Projection, F extends Filter | undefined = undefined, S extends Sorter | undefined = undefined> = {
60
+ id?: string;
61
+ action?: A;
62
+ data: D;
63
+ sorter?: S;
64
+ } & FilterPart<A, F> & {
65
+ randomRange?: number;
66
+ total?: number;
67
+ distinct?: true;
68
+ };
69
+ export interface EntityShape {
70
+ id: PrimaryKey;
71
+ $$seq$$: Sequence;
72
+ $$createAt$$: number | Date;
73
+ $$updateAt$$: number | Date;
74
+ $$deleteAt$$?: number | Date | null;
75
+ }
76
+ export interface GeneralEntityShape extends EntityShape {
77
+ [K: string]: any;
78
+ }
79
+ export type MakeAction<A extends string> = A;
80
+ export interface EntityDef {
81
+ Schema: GeneralEntityShape;
82
+ OpSchema: GeneralEntityShape;
83
+ Action: string;
84
+ ParticularAction?: string;
85
+ Selection: Selection<'select', Projection, Filter, Sorter>;
86
+ Aggregation: DeduceAggregation<Projection, Filter, Sorter>;
87
+ Operation: CUDOperation;
88
+ Create: CreateOperation;
89
+ CreateSingle: CreateSingleOperation;
90
+ CreateMulti: CreateMultipleOperation;
91
+ Update: UpdateOperation;
92
+ Remove: RemoveOperation;
93
+ Relation?: string;
94
+ }
95
+ export interface EntityDict {
96
+ [E: string]: EntityDef;
97
+ }
98
+ export interface OtmSubProjection extends Omit<Operation<'select', any, any, any>, 'action'> {
99
+ $entity: string;
100
+ }
101
+ export type AggregationOp = `#max-${number}` | `#min-${number}` | `#avg-${number}` | `#count-${number}` | `#sum-${number}`;
102
+ export type DeduceAggregationData<P extends Projection> = {
103
+ [A in AggregationOp]?: P;
104
+ } & OneOf<{
105
+ distinct?: true;
106
+ '#aggr'?: P;
107
+ }>;
108
+ export type AggregationResult<SH extends GeneralEntityShape> = Array<{
109
+ [A in AggregationOp]?: number | string;
110
+ } & {
111
+ '#data'?: Partial<SH>;
112
+ }>;
113
+ export type AttrFilter<SH extends GeneralEntityShape> = {
114
+ [K in keyof SH]?: any;
115
+ };
116
+ type SortAttr = {
117
+ [K: string]: any;
118
+ };
119
+ type SorterItem = {
120
+ $attr: SortAttr;
121
+ $direction?: "asc" | "desc";
122
+ };
123
+ type Sorter = Array<SorterItem>;
124
+ type Filter = {
125
+ [K: string]: any;
126
+ };
127
+ type Projection = {
128
+ [K: string]: any;
129
+ };
130
+ export type DeduceAggregation<P extends Projection, F extends Filter, S extends Sorter> = Omit<Selection<'aggregate', DeduceAggregationData<P>, F, S>, 'action'>;
131
+ type CreateOperationData = {
132
+ id: string;
133
+ [K: string]: any;
134
+ };
135
+ type CreateSingleOperation = Operation<'create', CreateOperationData, undefined, undefined>;
136
+ type CreateMultipleOperation = Operation<'create', Array<CreateOperationData>, undefined, undefined>;
137
+ type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
138
+ type UpdateOperationData = {
139
+ id?: never;
140
+ [k: string]: any;
141
+ };
142
+ export type UpdateOperation = Operation<string, UpdateOperationData, Filter, Sorter>;
143
+ type RemoveOperationData = {
144
+ [k: string]: any;
145
+ };
146
+ export type RemoveOperation = Operation<'remove', RemoveOperationData, Filter, Sorter>;
147
+ export type CUDOperation = CreateOperation | UpdateOperation | RemoveOperation;
148
+ export type CreateOpResult<ED extends EntityDict, T extends keyof ED> = {
149
+ id: string;
150
+ a: 'c';
151
+ e: T;
152
+ d: ED[T]['OpSchema'] | ED[T]['OpSchema'][];
153
+ };
154
+ export type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
155
+ id: string;
156
+ a: 'u';
157
+ e: T;
158
+ d: UpdateOperationData;
159
+ f?: Filter;
160
+ };
161
+ export type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = {
162
+ id: string;
163
+ a: 'r';
164
+ e: T;
165
+ f?: Filter;
166
+ };
167
+ export type RelationHierarchy<R extends string> = {
168
+ [K in R]?: R[];
169
+ };
170
+ export type CascadeRelationItem = {
171
+ cascadePath: string;
172
+ relations?: string[];
173
+ };
174
+ export type CascadeRelationAuth<R extends string> = {
175
+ [K in R]?: CascadeRelationItem | (CascadeRelationItem | CascadeRelationItem[])[];
176
+ };
177
+ export type SelectOpResult<ED extends EntityDict> = {
178
+ a: 's';
179
+ d: {
180
+ [T in keyof ED]?: {
181
+ [ID: string]: Partial<ED[T]['OpSchema']>;
182
+ };
183
+ };
184
+ };
185
+ export type OpRecord<ED extends EntityDict> = CreateOpResult<ED, keyof ED> | UpdateOpResult<ED, keyof ED> | RemoveOpResult<ED, keyof ED> | SelectOpResult<ED>;
186
+ export type OperationResult<ED extends EntityDict> = {
187
+ [K in keyof ED]?: {
188
+ [A in ED[K]['Action']]?: number;
189
+ };
190
+ };
191
+ export type ActionType = 'readOnly' | 'appendOnly' | 'excludeUpdate' | 'excludeRemove' | 'crud';
192
+ export type Configuration = {
193
+ actionType?: ActionType;
194
+ static?: boolean;
195
+ };
196
+ export type AuthDeduceRelationMap<ED extends EntityDict> = {
197
+ [T in keyof ED]?: keyof ED[T]['OpSchema'];
198
+ };
199
+ export type SelectFreeEntities<ED extends EntityDict> = (keyof ED)[];
200
+ export type UpdateFreeDict<ED extends EntityDict> = {
201
+ [A in keyof ED]?: string[];
202
+ };
203
+ export type OtmKey<K extends string> = K | `${K}$${number}`;
204
+ export interface SubDataDef<ED extends EntityDict, T extends keyof ED> {
205
+ id: string;
206
+ entity: T;
207
+ filter: ED[T]['Selection']['filter'];
208
+ }
209
+ export {};
@@ -1,69 +1,74 @@
1
- import { EntityDict } from './Entity';
2
- import { EntityDict as BaseEntityDict } from '../base-app-domain';
3
- import { AsyncContext } from '../store/AsyncRowStore';
4
- export type Algorithm = 'rsa' | 'ec' | 'ed25519';
5
- export type RemotePushInfo = {
6
- url: string;
7
- userId: string;
8
- };
9
- export type RemotePullInfo = {
10
- id: string;
11
- publicKey: string;
12
- algorithm: Algorithm;
13
- userId: string;
14
- };
15
- export type SelfEncryptInfo = {
16
- id: string;
17
- privateKey: string;
18
- algorithm: Algorithm;
19
- };
20
- export interface PullEntityDef<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> {
21
- direction: 'pull';
22
- entity: T;
23
- path: string;
24
- recursive?: boolean;
25
- relationName?: string;
26
- process?: <A extends ED[T]['Action']>(action: A, data: ED[T]['Operation']['data'], context: Cxt) => Promise<void>;
27
- }
28
- export interface PushEntityDef<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> {
29
- direction: 'push';
30
- entity: T;
31
- path: string;
32
- recursive?: boolean;
33
- relationName?: string;
34
- actions?: ED[T]['Action'][];
35
- onSynchronized?: (result: {
36
- action: ED[T]['Action'];
37
- data: ED[T]['Operation']['data'];
38
- result: Array<{
39
- userId: string;
40
- rowIds: string[];
41
- error?: Error;
42
- }>;
43
- }, context: Cxt) => Promise<void>;
44
- }
45
- export interface SyncRemoteConfigBase<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> {
46
- entity: keyof ED;
47
- entitySelf?: keyof ED;
48
- endpoint?: string;
49
- pathToUser?: string;
50
- relationName?: string;
51
- pushEntities?: Array<PushEntityDef<ED, keyof ED, Cxt>>;
52
- pullEntities?: Array<PullEntityDef<ED, keyof ED, Cxt>>;
53
- }
54
- interface SyncRemoteConfig<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends SyncRemoteConfigBase<ED, Cxt> {
55
- getPushInfo: (userId: string, context: Cxt) => Promise<RemotePushInfo>;
56
- getPullInfo: (id: string, context: Cxt) => Promise<RemotePullInfo>;
57
- }
58
- export interface SyncSelfConfigBase<ED extends EntityDict & BaseEntityDict> {
59
- endpoint?: string;
60
- entitySelf: keyof ED;
61
- }
62
- interface SyncSelfConfig<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends SyncSelfConfigBase<ED> {
63
- getSelfEncryptInfo: (context: Cxt) => Promise<SelfEncryptInfo>;
64
- }
65
- export interface SyncConfig<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> {
66
- self: SyncSelfConfig<ED, Cxt>;
67
- remotes: Array<SyncRemoteConfig<ED, Cxt>>;
68
- }
69
- export {};
1
+ import { EntityDict } from './Entity';
2
+ import { EntityDict as BaseEntityDict } from '../base-app-domain';
3
+ import { AsyncContext } from '../store/AsyncRowStore';
4
+ export type Algorithm = 'rsa' | 'ec' | 'ed25519';
5
+ export type RemotePushInfo = {
6
+ url: string;
7
+ userId: string;
8
+ };
9
+ export type RemotePullInfo = {
10
+ id: string;
11
+ publicKey: string;
12
+ algorithm: Algorithm;
13
+ userId: string;
14
+ cxtInfo?: any;
15
+ };
16
+ export type SelfEncryptInfo = {
17
+ id: string;
18
+ privateKey: string;
19
+ algorithm: Algorithm;
20
+ };
21
+ export interface PullEntityDef<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> {
22
+ direction: 'pull';
23
+ entity: T;
24
+ path: string;
25
+ recursive?: boolean;
26
+ relationName?: string;
27
+ process?: <A extends ED[T]['Action']>(action: A, data: ED[T]['Operation']['data'], context: Cxt) => Promise<void>;
28
+ }
29
+ export interface PushEntityDef<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> {
30
+ direction: 'push';
31
+ entity: T;
32
+ path: string;
33
+ recursive?: boolean;
34
+ relationName?: string;
35
+ actions?: ED[T]['Action'][];
36
+ /**
37
+ * 同步结果回调,根据接口的幂等原理,同步一定要完全成功再回调
38
+ */
39
+ onSynchronized?: (result: {
40
+ action: ED[T]['Action'];
41
+ data: ED[T]['Operation']['data'];
42
+ rowIds: string[];
43
+ }, context: Cxt) => Promise<void>;
44
+ }
45
+ export interface SyncRemoteConfigBase<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> {
46
+ entity: keyof ED;
47
+ endpoint?: string;
48
+ pathToUser?: string;
49
+ relationName?: string;
50
+ pushEntities?: Array<PushEntityDef<ED, keyof ED, Cxt>>;
51
+ pullEntities?: Array<PullEntityDef<ED, keyof ED, Cxt>>;
52
+ }
53
+ interface SyncRemoteConfig<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends SyncRemoteConfigBase<ED, Cxt> {
54
+ getPushInfo: (context: Cxt, option: {
55
+ remoteEntityId: string;
56
+ userId: string;
57
+ }) => Promise<RemotePushInfo>;
58
+ getPullInfo: (context: Cxt, option: {
59
+ selfId: string;
60
+ remoteEntityId: string;
61
+ }) => Promise<RemotePullInfo>;
62
+ }
63
+ export interface SyncSelfConfigBase<ED extends EntityDict & BaseEntityDict> {
64
+ endpoint?: string;
65
+ entity: keyof ED;
66
+ }
67
+ interface SyncSelfConfig<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends SyncSelfConfigBase<ED> {
68
+ getSelfEncryptInfo: (context: Cxt) => Promise<SelfEncryptInfo>;
69
+ }
70
+ export interface SyncConfig<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> {
71
+ self: SyncSelfConfig<ED, Cxt>;
72
+ remotes: Array<SyncRemoteConfig<ED, Cxt>>;
73
+ }
74
+ export {};
package/lib/types/Sync.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- ;
4
- ;
5
- ;
6
- ;
7
- ;
8
- ;
9
- ;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
4
+ ;
5
+ ;
6
+ ;
7
+ ;
8
+ ;
9
+ ;
@@ -1,27 +1,27 @@
1
- export * from './Action';
2
- export * from './Aspect';
3
- export * from './Auth';
4
- export * from './Context';
5
- export * from './DataType';
6
- export * from './Demand';
7
- export * from './Entity';
8
- export * from './Expression';
9
- export * from './Geo';
10
- export * from './Logger';
11
- export * from './Polyfill';
12
- export * from './RowStore';
13
- export * from './Storage';
14
- export * from './Trigger';
15
- export * from './Exception';
16
- export * from './Watcher';
17
- export * from './AppLoader';
18
- export * from './Connector';
19
- export * from './Timer';
20
- export * from './Port';
21
- export * from './Endpoint';
22
- export * from './Style';
23
- export * from './EntityDesc';
24
- export * from './Environment';
25
- export * from './Locale';
26
- export * from './Cluster';
27
- export * from './Sync';
1
+ export * from './Action';
2
+ export * from './Aspect';
3
+ export * from './Auth';
4
+ export * from './Context';
5
+ export * from './DataType';
6
+ export * from './Demand';
7
+ export * from './Entity';
8
+ export * from './Expression';
9
+ export * from './Geo';
10
+ export * from './Logger';
11
+ export * from './Polyfill';
12
+ export * from './RowStore';
13
+ export * from './Storage';
14
+ export * from './Trigger';
15
+ export * from './Exception';
16
+ export * from './Watcher';
17
+ export * from './AppLoader';
18
+ export * from './Connector';
19
+ export * from './Timer';
20
+ export * from './Port';
21
+ export * from './Endpoint';
22
+ export * from './Style';
23
+ export * from './EntityDesc';
24
+ export * from './Environment';
25
+ export * from './Locale';
26
+ export * from './Cluster';
27
+ export * from './Sync';