wowok 1.1.4 → 1.2.0

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 (63) hide show
  1. package/README.md +7 -2
  2. package/dist/demand.d.ts +6 -6
  3. package/dist/demand.d.ts.map +1 -1
  4. package/dist/demand.js +38 -38
  5. package/dist/entity.d.ts +23 -0
  6. package/dist/entity.d.ts.map +1 -0
  7. package/dist/entity.js +71 -0
  8. package/dist/exception.d.ts +2 -1
  9. package/dist/exception.d.ts.map +1 -1
  10. package/dist/exception.js +1 -0
  11. package/dist/guard.d.ts +12 -12
  12. package/dist/guard.d.ts.map +1 -1
  13. package/dist/guard.js +66 -58
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -0
  17. package/dist/machine.d.ts.map +1 -1
  18. package/dist/machine.js +1 -1
  19. package/dist/passport.d.ts +16 -9
  20. package/dist/passport.d.ts.map +1 -1
  21. package/dist/passport.js +69 -59
  22. package/dist/permission.d.ts.map +1 -1
  23. package/dist/permission.js +1 -1
  24. package/dist/progress.d.ts.map +1 -1
  25. package/dist/progress.js +10 -1
  26. package/dist/protocol.d.ts +19 -8
  27. package/dist/protocol.d.ts.map +1 -1
  28. package/dist/protocol.js +31 -26
  29. package/dist/repository.d.ts.map +1 -1
  30. package/dist/repository.js +11 -1
  31. package/dist/resource.d.ts +16 -0
  32. package/dist/resource.d.ts.map +1 -0
  33. package/dist/resource.js +83 -0
  34. package/dist/reward.d.ts.map +1 -1
  35. package/dist/reward.js +10 -1
  36. package/dist/service.d.ts.map +1 -1
  37. package/dist/service.js +11 -1
  38. package/dist/utils.d.ts +1 -0
  39. package/dist/utils.d.ts.map +1 -1
  40. package/dist/utils.js +10 -0
  41. package/dist/vote.d.ts.map +1 -1
  42. package/dist/vote.js +1 -1
  43. package/dist/wowok.d.ts +12 -0
  44. package/dist/wowok.d.ts.map +1 -0
  45. package/dist/wowok.js +48 -0
  46. package/package.json +10 -3
  47. package/src/demand.ts +42 -42
  48. package/src/entity.ts +83 -0
  49. package/src/exception.ts +1 -0
  50. package/src/guard.ts +71 -57
  51. package/src/index.ts +11 -8
  52. package/src/machine.ts +3 -2
  53. package/src/passport.ts +70 -65
  54. package/src/permission.ts +5 -4
  55. package/src/progress.ts +11 -3
  56. package/src/protocol.ts +41 -31
  57. package/src/repository.ts +12 -2
  58. package/src/resource.ts +90 -0
  59. package/src/reward.ts +11 -2
  60. package/src/service.ts +12 -1
  61. package/src/utils.ts +12 -1
  62. package/src/vote.ts +2 -1
  63. package/src/wowok.ts +56 -0
package/src/reward.ts CHANGED
@@ -3,6 +3,7 @@ import { BCS} from '@mysten/bcs';
3
3
  import { FnCallType, GuardObject, PassportObject, PermissionObject, RewardAddress, Protocol, TxbObject, } from './protocol';
4
4
  import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidUint, } from './utils';
5
5
  import { ERROR, Errors } from './exception';
6
+ import { Resource } from './resource';
6
7
 
7
8
  export type CoinReward = TransactionResult;
8
9
  export type RewardGuardPortions = {
@@ -31,7 +32,6 @@ export class Reward {
31
32
  }
32
33
  static New(protocol:Protocol, earnest_type:string, permission:PermissionObject, description:string,
33
34
  minutes_duration:number, passport?:PassportObject) : Reward {
34
- let r = new Reward(protocol, earnest_type, permission);
35
35
  if (!Protocol.IsValidObjects([permission])) {
36
36
  ERROR(Errors.IsValidObjects, 'permission')
37
37
  }
@@ -45,6 +45,7 @@ export class Reward {
45
45
  ERROR(Errors.IsValidUint, 'minutes_duration')
46
46
  }
47
47
 
48
+ let r = new Reward(protocol, earnest_type, permission);
48
49
  let txb = protocol.CurrentSession()
49
50
 
50
51
  if (passport) {
@@ -81,7 +82,15 @@ export class Reward {
81
82
  arguments: [Protocol.TXB_OBJECT(txb, this.object)],
82
83
  })
83
84
  }
84
-
85
+ /*
86
+ mark(like:'like' | 'unlike', resource:Resource) {
87
+ let txb = this.protocol.CurrentSession();
88
+ txb.moveCall({
89
+ target:this.protocol.RewardFn(like) as FnCallType,
90
+ arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
91
+ })
92
+ }
93
+ */
85
94
  refund(passport?:PassportObject) {
86
95
  let txb = this.protocol.CurrentSession();
87
96
  if (passport) {
package/src/service.ts CHANGED
@@ -5,6 +5,7 @@ import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryOb
5
5
  ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol,
6
6
  TxbObject} from './protocol';
7
7
  import { ERROR, Errors } from './exception';
8
+ import { Resource } from './resource';
8
9
 
9
10
  export type Service_Guard_Percent = {
10
11
  guard:GuardObject;
@@ -76,7 +77,6 @@ export class Service {
76
77
  }
77
78
  static New(protocol: Protocol, pay_token_type:string, permission:PermissionObject, description:string,
78
79
  payee_address:string, endpoint?:string, passport?:PassportObject) : Service {
79
- let s = new Service(protocol, pay_token_type, permission);
80
80
  if (!Protocol.IsValidObjects([permission])) {
81
81
  ERROR(Errors.IsValidObjects)
82
82
  }
@@ -94,6 +94,7 @@ export class Service {
94
94
  ERROR(Errors.IsValidEndpoint)
95
95
  }
96
96
 
97
+ let s = new Service(protocol, pay_token_type, permission);
97
98
  let txb = protocol.CurrentSession();
98
99
  let ep = endpoint? txb.pure(Bcs.getInstance().ser_option_string(endpoint)) : OptionNone(txb);
99
100
 
@@ -129,6 +130,16 @@ export class Service {
129
130
  typeArguments:[this.pay_token_type]
130
131
  })
131
132
  }
133
+ /* move to: Entity.mark
134
+ mark(like:'like' | 'unlike', resource:Resource) {
135
+ let txb = this.protocol.CurrentSession();
136
+ txb.moveCall({
137
+ target:this.protocol.ServiceFn(like) as FnCallType,
138
+ arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
139
+ typeArguments:[this.pay_token_type]
140
+ })
141
+ }
142
+ */
132
143
  set_description(description:string, passport?:PassportObject) {
133
144
  if (!IsValidDesription(description)) {
134
145
  ERROR(Errors.IsValidDesription)
package/src/utils.ts CHANGED
@@ -290,4 +290,15 @@ export function toFixed(x:number) {
290
290
  }
291
291
  }
292
292
  return res;
293
- }
293
+ }
294
+
295
+ export function isValidHttpUrl(url:string) : boolean {
296
+ let r:any;
297
+ try {
298
+ r = new URL(url);
299
+ } catch (_) {
300
+ return false;
301
+ }
302
+
303
+ return r.protocol === "http:" || r.protocol === "https:";
304
+ }
package/src/vote.ts CHANGED
@@ -2,6 +2,7 @@ import { BCS } from '@mysten/bcs';
2
2
  import { FnCallType, PassportObject, PermissionObject, GuardObject, VoteAddress, Protocol, TxbObject} from './protocol';
3
3
  import { IsValidDesription, IsValidUint, IsValidAddress, OptionNone, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
4
4
  import { ERROR, Errors } from './exception';
5
+ import { Resource } from './resource';
5
6
 
6
7
  export const MAX_AGREES_COUNT = 200;
7
8
  export const MAX_CHOICE_COUNT = 200;
@@ -29,7 +30,6 @@ export class Vote {
29
30
  }
30
31
  static New(protocol:Protocol, permission:PermissionObject, description:string, minutes_duration:number,
31
32
  max_choice_count?:number, reference_address?:string, passport?:PassportObject) : Vote {
32
- let v = new Vote(protocol, permission);
33
33
  if (!Protocol.IsValidObjects([permission])) {
34
34
  ERROR(Errors.IsValidObjects, 'permission')
35
35
  }
@@ -49,6 +49,7 @@ export class Vote {
49
49
  ERROR(Errors.IsValidAddress, 'reference_address')
50
50
  }
51
51
 
52
+ let v = new Vote(protocol, permission);
52
53
  let txb = protocol.CurrentSession();
53
54
  let reference = reference_address? txb.pure(Bcs.getInstance().ser_option_address(reference_address)) : OptionNone(txb);
54
55
  let choice_count = max_choice_count ? max_choice_count : 1;
package/src/wowok.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { BCS } from '@mysten/bcs';
2
+ import { Protocol, FnCallType, TxbObject, ResourceAddress, PermissionObject} from './protocol';
3
+ import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, } from './utils';
4
+ import { ERROR, Errors } from './exception';
5
+
6
+
7
+ export class Wowok {
8
+
9
+ protected object:TxbObject;
10
+ protected protocol;
11
+
12
+ get_object() { return this.object }
13
+ private constructor(protocol:Protocol) {
14
+ this.protocol = protocol;
15
+ this.object = '';
16
+ }
17
+
18
+ static From(protocol:Protocol) : Wowok {
19
+ let r = new Wowok(protocol);
20
+ r.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), protocol.WowokObject());
21
+ return r
22
+ }
23
+
24
+ register_grantor(name:string, grantee_permission:PermissionObject) {
25
+ if (!IsValidName(name)) ERROR(Errors.IsValidName, 'register_grantor');
26
+ if (!Protocol.IsValidObjects([grantee_permission])) ERROR(Errors.IsValidObjects, 'register_grantor');
27
+
28
+ let txb = this.protocol.CurrentSession();
29
+ txb.moveCall({
30
+ target:this.protocol.WowokFn('grantor_register') as FnCallType,
31
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name, BCS.STRING), txb.object(Protocol.CLOCK_OBJECT),
32
+ Protocol.TXB_OBJECT(txb, grantee_permission)]
33
+ })
34
+ }
35
+
36
+ grantor_time_expand_1year(grantor:string) {
37
+ if (!IsValidAddress(grantor)) ERROR(Errors.IsValidAddress, 'grantor_time_expand_1year');
38
+
39
+ let txb = this.protocol.CurrentSession();
40
+ txb.moveCall({
41
+ target:this.protocol.WowokFn('grantor_time_expand_1year') as FnCallType,
42
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(grantor, BCS.ADDRESS)]
43
+ })
44
+ }
45
+
46
+ grantor_rename(new_name:string) {
47
+ if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'grantor_rename');
48
+
49
+ let txb = this.protocol.CurrentSession();
50
+ txb.moveCall({
51
+ target:this.protocol.WowokFn('grantor_time_expand_1year') as FnCallType,
52
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(new_name, BCS.STRING)]
53
+ })
54
+ }
55
+ }
56
+