@wishknish/knishio-client-js 0.4.39 → 0.4.42

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.
@@ -46,9 +46,7 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
46
46
  License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
47
  */
48
48
  import {
49
- ApolloLink,
50
- Operation,
51
- NextLink
49
+ ApolloLink
52
50
  } from '@apollo/client/core';
53
51
  import Echo from 'laravel-echo';
54
52
  import createRequestHandler from './handler';
@@ -46,8 +46,6 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
46
46
  License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
47
  */
48
48
  import {
49
- Operation,
50
- NextLink,
51
49
  HttpLink as RootHttpLink
52
50
  } from '@apollo/client/core';
53
51
 
@@ -46,10 +46,7 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
46
46
  License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
47
  */
48
48
  import {
49
- Observable,
50
- Operation,
51
- FetchResult,
52
- Observer
49
+ Observable
53
50
  } from '@apollo/client/core';
54
51
 
55
52
  /**
@@ -243,35 +243,31 @@ export default class CheckMolecule {
243
243
 
244
244
  for ( let atom of CheckMolecule.isotopeFilter( 'R', molecule.atoms ) ) {
245
245
  const metas = atom.aggregatedMeta();
246
- for ( let key of [ 'callback', 'conditions', 'rule' ] ) {
247
246
 
248
- if ( !metas.hasOwnProperty( key ) ) {
249
- throw new MetaMissingException( `Check::isotopeR() - Required meta field "${ key }" is missing!` );
247
+ if ( metas.policy ) {
248
+ const policy = JSON.parse( metas.policy );
249
+
250
+ if ( !Object.keys( policy ).every( i => [ 'read', 'write' ].includes( i ) ) ) {
251
+ throw new MetaMissingException( 'Check::isotopeR() - Mixing rules with politics!' );
250
252
  }
251
253
  }
252
254
 
253
- try {
254
- const conditions = JSON.parse( metas[ 'conditions' ] ),
255
- callback = JSON.parse( metas[ 'callback' ] );
256
- } catch ( err ) {
257
- throw new MetaMissingException( 'Check::isotopeR() - Condition is formatted incorrectly!' );
258
- }
255
+ if ( metas.rule ) {
256
+ const rules = JSON.parse( metas.rule );
259
257
 
260
- if ( conditions === 'policy' &&
261
- callback.length &&
262
- !callback.every( i => [ 'read', 'write' ].includes( i[ 'action' ] ) ) ) {
263
- throw new MetaMissingException( 'Check::isotopeR() - Mixing rules with politics!' );
264
- }
258
+ if ( !Array.isArray( rules ) ) {
259
+ throw new MetaMissingException( 'Check::isotopeR() - Incorrect rule format!' );
260
+ }
265
261
 
266
- if ( Array.isArray( conditions ) && conditions.length ) {
262
+ if ( rules.length < 1 ) {
263
+ throw new MetaMissingException( 'Check::isotopeR() - No rules!' );
264
+ }
267
265
 
268
- for ( let condition of conditions ) {
269
- const keys = Object.keys( condition ),
270
- property = keys.filter( n => [ 'key', 'value', 'comparison' ].indexOf( n ) !== -1 ),
271
- property2 = keys.filter( n => [ 'managedBy' ].indexOf( n ) !== -1 );
266
+ for ( const rule of rules ) {
267
+ const keys = Object.keys(rule).filter( value => [ 'key', 'value', 'callback' ].includes( value ) );
272
268
 
273
- if ( property.length < 3 && property2.length ) {
274
- throw new MetaMissingException( 'Check::isotopeR() - Required condition field is missing!' );
269
+ if ( keys.length < 3 ) {
270
+ throw new MetaMissingException( 'Check::isotopeR() - Necessary rule fields are missing!' );
275
271
  }
276
272
  }
277
273
  }
@@ -46,7 +46,6 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
46
46
  License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
47
  */
48
48
  import Query from '../query/Query';
49
- import { Operation } from '@apollo/client/core';
50
49
 
51
50
  /**
52
51
  * Base class used to construct various GraphQL mutations
@@ -0,0 +1,91 @@
1
+ /*
2
+ (
3
+ (/(
4
+ (//(
5
+ (///(
6
+ (/////(
7
+ (//////( )
8
+ (////////( (/)
9
+ (////////( (///)
10
+ (//////////( (////)
11
+ (//////////( (//////)
12
+ (////////////( (///////)
13
+ (/////////////( (/////////)
14
+ (//////////////( (///////////)
15
+ (///////////////( (/////////////)
16
+ (////////////////( (//////////////)
17
+ ((((((((((((((((((( (((((((((((((((
18
+ ((((((((((((((((((( ((((((((((((((
19
+ ((((((((((((((((((( ((((((((((((((
20
+ (((((((((((((((((((( (((((((((((((
21
+ (((((((((((((((((((( ((((((((((((
22
+ ((((((((((((((((((( ((((((((((((
23
+ ((((((((((((((((((( ((((((((((
24
+ ((((((((((((((((((/ (((((((((
25
+ (((((((((((((((((( ((((((((
26
+ ((((((((((((((((( (((((((
27
+ (((((((((((((((((( (((((
28
+ ################# ##
29
+ ################ #
30
+ ################# ##
31
+ %################ ###
32
+ ###############( ####
33
+ ############### ####
34
+ ############### ######
35
+ %#############( (#######
36
+ %############# #########
37
+ ############( ##########
38
+ ########### #############
39
+ ######### ##############
40
+ %######
41
+
42
+ Powered by Knish.IO: Connecting a Decentralized World
43
+
44
+ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
45
+
46
+ License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
+ */
48
+ import MutationProposeMolecule from './MutationProposeMolecule';
49
+ import ResponseCreateRule from '../response/ResponseCreateRule';
50
+
51
+
52
+ /**
53
+ * Query for creating new Meta attached to some MetaType
54
+ */
55
+ export default class MutationCreateRule extends MutationProposeMolecule {
56
+ /**
57
+ *
58
+ * @param {string} metaType
59
+ * @param {string} metaId
60
+ * @param {object[]} rule
61
+ * @param {object} policy
62
+ */
63
+ fillMolecule ( {
64
+ metaType,
65
+ metaId,
66
+ rule,
67
+ policy
68
+ } ) {
69
+ this.$__molecule.createRule( {
70
+ metaType,
71
+ metaId,
72
+ rule,
73
+ policy
74
+ } );
75
+ this.$__molecule.sign( {} );
76
+ this.$__molecule.check();
77
+ }
78
+
79
+ /**
80
+ * Builds a new Response object from a JSON string
81
+ *
82
+ * @param {object} json
83
+ * @return {ResponseCreateRule}
84
+ */
85
+ createResponse ( json ) {
86
+ return new ResponseCreateRule( {
87
+ query: this,
88
+ json
89
+ } );
90
+ }
91
+ }
@@ -46,7 +46,6 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
46
46
  License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
47
  */
48
48
  import CodeException from '../exception/CodeException';
49
- import { Operation } from '@apollo/client/core';
50
49
  import Response from '../response/Response';
51
50
 
52
51
  export default class Query {
@@ -59,11 +59,11 @@ export default class QueryMetaTypeViaAtom extends Query {
59
59
  constructor ( apolloClient ) {
60
60
  super( apolloClient );
61
61
 
62
- this.$__query = gql`query ($metaTypes: [String!], $metaIds: [String!], $values: [String!], $latest: Boolean, $filter: [MetaFilter!], $queryArgs: QueryArgs, $countBy: String) {
62
+ this.$__query = gql`query ($metaTypes: [String!], $metaIds: [String!], $values: [String!], $keys: [String!], $latest: Boolean, $filter: [MetaFilter!], $queryArgs: QueryArgs, $countBy: String, $atomValues: [String!] ) {
63
63
  MetaTypeViaAtom(
64
64
  metaTypes: $metaTypes
65
65
  metaIds: $metaIds
66
- values: $values
66
+ atomValues: $atomValues
67
67
  filter: $filter,
68
68
  latest: $latest,
69
69
  queryArgs: $queryArgs
@@ -78,7 +78,7 @@ export default class QueryMetaTypeViaAtom extends Query {
78
78
  metaType,
79
79
  metaId,
80
80
  createdAt,
81
- metas {
81
+ metas( values: $values, keys: $keys ) {
82
82
  molecularHash,
83
83
  position,
84
84
  key,
@@ -114,6 +114,9 @@ export default class QueryMetaTypeViaAtom extends Query {
114
114
  * @param {string|array|null} metaId
115
115
  * @param {string|null} key
116
116
  * @param {string|null} value
117
+ * @param {array|null} values
118
+ * @param {array|null} keys
119
+ * @param {array|null} atomValues
117
120
  * @param {boolean|null} latest
118
121
  * @param {boolean|null} latestMetas
119
122
  * @param {array|null} filter
@@ -126,6 +129,9 @@ export default class QueryMetaTypeViaAtom extends Query {
126
129
  metaId = null,
127
130
  key = null,
128
131
  value = null,
132
+ keys = null,
133
+ values = null,
134
+ atomValues = null,
129
135
  latest = null,
130
136
  latestMetas = true,
131
137
  filter = null,
@@ -134,12 +140,24 @@ export default class QueryMetaTypeViaAtom extends Query {
134
140
  } ) {
135
141
  const variables = {};
136
142
 
143
+ if ( atomValues ) {
144
+ variables[ 'atomValues' ] = atomValues;
145
+ }
146
+
147
+ if ( keys ) {
148
+ variables[ 'keys' ] = keys;
149
+ }
150
+
151
+ if ( values ) {
152
+ variables[ 'values' ] = values;
153
+ }
154
+
137
155
  if ( metaType ) {
138
- variables[ 'metaTypes' ] = [ metaType ];
156
+ variables[ 'metaTypes' ] = typeof metaType === 'string' ? [ metaType ] : metaType;
139
157
  }
140
158
 
141
159
  if ( metaId ) {
142
- variables[ 'metaIds' ] = [ metaId ];
160
+ variables[ 'metaIds' ] = typeof metaId === 'string' ? [ metaId ] : metaId;
143
161
  }
144
162
 
145
163
  if ( countBy ) {
@@ -0,0 +1,55 @@
1
+ /*
2
+ (
3
+ (/(
4
+ (//(
5
+ (///(
6
+ (/////(
7
+ (//////( )
8
+ (////////( (/)
9
+ (////////( (///)
10
+ (//////////( (////)
11
+ (//////////( (//////)
12
+ (////////////( (///////)
13
+ (/////////////( (/////////)
14
+ (//////////////( (///////////)
15
+ (///////////////( (/////////////)
16
+ (////////////////( (//////////////)
17
+ ((((((((((((((((((( (((((((((((((((
18
+ ((((((((((((((((((( ((((((((((((((
19
+ ((((((((((((((((((( ((((((((((((((
20
+ (((((((((((((((((((( (((((((((((((
21
+ (((((((((((((((((((( ((((((((((((
22
+ ((((((((((((((((((( ((((((((((((
23
+ ((((((((((((((((((( ((((((((((
24
+ ((((((((((((((((((/ (((((((((
25
+ (((((((((((((((((( ((((((((
26
+ ((((((((((((((((( (((((((
27
+ (((((((((((((((((( (((((
28
+ ################# ##
29
+ ################ #
30
+ ################# ##
31
+ %################ ###
32
+ ###############( ####
33
+ ############### ####
34
+ ############### ######
35
+ %#############( (#######
36
+ %############# #########
37
+ ############( ##########
38
+ ########### #############
39
+ ######### ##############
40
+ %######
41
+
42
+ Powered by Knish.IO: Connecting a Decentralized World
43
+
44
+ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
45
+
46
+ License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
+ */
48
+ import ResponseProposeMolecule from './ResponseProposeMolecule';
49
+
50
+ /**
51
+ * Response for rule creation
52
+ */
53
+ export default class ResponseCreateRule extends ResponseProposeMolecule {
54
+
55
+ }
@@ -1,5 +1,4 @@
1
1
  import CodeException from '../exception/CodeException';
2
- import { Operation } from '@apollo/client/core';
3
2
 
4
3
  export default class Subscribe {
5
4
  /**
package/src/test/Test.js CHANGED
@@ -58,6 +58,12 @@ export default class Test {
58
58
  [ 'unit_id_10' ],
59
59
  [ 'unit_id_11' ]
60
60
  ];
61
+ this.replenishTokenUnits = [
62
+ [ 'unit_id_12' ],
63
+ [ 'unit_id_13' ],
64
+ [ 'unit_id_14' ],
65
+ [ 'unit_id_15' ]
66
+ ];
61
67
  }
62
68
 
63
69
 
@@ -65,8 +71,12 @@ export default class Test {
65
71
  * Test all KnishIOClient functions
66
72
  */
67
73
  async testAll () {
68
- await this.client( this.secrets[ 0 ] );
74
+ /*
75
+ await this.testTokenExpiration();
69
76
  return;
77
+ */
78
+
79
+ await this.client( this.secrets[ 0 ] );
70
80
  await this.client( this.secrets[ 1 ] );
71
81
 
72
82
  await this.testCreateToken();
@@ -76,6 +86,7 @@ export default class Test {
76
86
  await this.testRequestTokens();
77
87
  await this.testTransferToken();
78
88
  await this.testBurnToken();
89
+ await this.testReplenishToken();
79
90
  await this.testClaimShadowWallet();
80
91
  await this.testQueryMeta();
81
92
  await this.testQueryWallets();
@@ -84,6 +95,28 @@ export default class Test {
84
95
  await this.testQueryBalance();
85
96
  }
86
97
 
98
+
99
+ /**
100
+ *
101
+ * @returns {Promise<void>}
102
+ */
103
+ async testTokenExpiration () {
104
+ const client = await this.client( this.secrets[ 0 ] );
105
+ const fnTimeout = ( timeout ) => {
106
+ setTimeout( client => {
107
+ console.warn( `setTimeout ${ timeout }` );
108
+ client.queryMeta( {
109
+ metaType: 'metaType',
110
+ metaId: 'metaId'
111
+ } );
112
+ }, timeout, client, timeout );
113
+ };
114
+ fnTimeout( 3000 );
115
+ fnTimeout( 30000 );
116
+ fnTimeout( 61000 );
117
+ fnTimeout( 64000 );
118
+ }
119
+
87
120
  /**
88
121
  * @throws \Exception
89
122
  */
@@ -252,26 +285,45 @@ export default class Test {
252
285
  *
253
286
  */
254
287
  async testBurnToken () {
255
-
256
- let bundleHash = generateBundleHash( this.secrets[ 1 ] );
257
288
  let response;
258
289
 
259
290
  let client = await this.client( this.secrets[ 0 ] );
260
291
  response = await client.burnTokens( {
261
292
  token: this.tokenSlugs[ 0 ],
262
- amount: 10,
263
- batchId: 'batch_3'
293
+ amount: 10
264
294
  } );
265
295
  this.checkResponse( response, 'testBurnToken' );
266
296
 
267
297
  response = await client.burnTokens( {
268
298
  token: this.tokenSlugs[ 2 ],
269
- units: [ 'unit_id_3', 'unit_id_4' ],
270
- batchId: 'batch_4'
299
+ units: [ 'unit_id_3', 'unit_id_4' ]
271
300
  } );
272
301
  this.checkResponse( response, 'testBurnUnitToken' );
273
302
  }
274
303
 
304
+
305
+ /**
306
+ *
307
+ */
308
+ async testReplenishToken () {
309
+
310
+ let response;
311
+
312
+ let client = await this.client( this.secrets[ 0 ] );
313
+ response = await client.replenishToken( {
314
+ token: this.tokenSlugs[ 0 ],
315
+ amount: 25
316
+ } );
317
+ this.checkResponse( response, 'testReplenishToken' );
318
+
319
+ response = await client.replenishToken( {
320
+ token: this.tokenSlugs[ 2 ],
321
+ amount: 0,
322
+ units: this.replenishTokenUnits
323
+ } );
324
+ this.checkResponse( response, 'testReplenishUnitToken' );
325
+ }
326
+
275
327
  /**
276
328
  *
277
329
  */