@snapshot-labs/snapshot.js 0.9.9 → 0.10.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.
package/dist/utils.d.ts CHANGED
@@ -31,9 +31,11 @@ export declare function sendTransaction(web3: any, contractAddress: string, abi:
31
31
  export declare function getScores(space: string, strategies: Strategy[], network: string, addresses: string[], snapshot?: number | string, scoreApiUrl?: string, options?: any): Promise<any>;
32
32
  export declare function getVp(address: string, network: string, strategies: Strategy[], snapshot: number | 'latest', space: string, delegation: boolean, options?: Options): Promise<any>;
33
33
  export declare function validate(validation: string, author: string, space: string, network: string, snapshot: number | 'latest', params: any, options: any): Promise<any>;
34
- export declare function validateSchema(schema: any, data: any, options?: {
35
- snapshotEnv: string;
36
- }): true | import("ajv").ErrorObject<string, Record<string, any>, unknown>[] | null | undefined;
34
+ interface validateSchemaOptions {
35
+ snapshotEnv?: string;
36
+ spaceType?: string;
37
+ }
38
+ export declare function validateSchema(schema: any, data: any, options?: validateSchemaOptions): true | import("ajv").ErrorObject<string, Record<string, any>, unknown>[] | null | undefined;
37
39
  export declare function getEnsTextRecord(ens: string, record: string, network?: string, options?: any): Promise<any>;
38
40
  export declare function getSpaceUri(id: string, network?: string, options?: any): Promise<string | null>;
39
41
  export declare function getEnsOwner(ens: string, network?: string, options?: any): Promise<string | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapshot-labs/snapshot.js",
3
- "version": "0.9.9",
3
+ "version": "0.10.0",
4
4
  "repository": "snapshot-labs/snapshot.js",
5
5
  "license": "MIT",
6
6
  "main": "dist/snapshot.cjs.js",
package/src/networks.json CHANGED
@@ -735,13 +735,13 @@
735
735
  "network": "mainnet",
736
736
  "multicall": "0x024f0041b76B598c2A0a75004F8447FaF67BD004",
737
737
  "rpc": [
738
- "https://rpc.coredao.org/"
738
+ "https://rpcar.coredao.org/"
739
739
  ],
740
740
  "explorer": {
741
741
  "url": "https://scan.coredao.org"
742
742
  },
743
743
  "start": 853908,
744
- "logo": "ipfs://QmVctLQ44vhkwejja9DDjDYUdYgVRBEWs242mhd95SeM5q"
744
+ "logo": "ipfs://bafkreigjv5yb7uhlrryzib7j2f73nnwqan2tmfnwjdu26vkk365fyesoiu"
745
745
  },
746
746
  "1284": {
747
747
  "key": "1284",
@@ -16,7 +16,10 @@
16
16
  "type": "string",
17
17
  "title": "body",
18
18
  "minLength": 0,
19
- "maxLength": 20000
19
+ "maxLengthWithSpaceType": {
20
+ "default": 10000,
21
+ "turbo": 20000
22
+ }
20
23
  },
21
24
  "discussion": {
22
25
  "type": "string",
@@ -103,7 +103,11 @@
103
103
  "strategies": {
104
104
  "type": "array",
105
105
  "minItems": 1,
106
- "maxItems": 8,
106
+ "maxItemsWithSpaceType": {
107
+ "default": 8,
108
+ "turbo": 10
109
+ },
110
+ "uniqueItems": true,
107
111
  "items": {
108
112
  "type": "object",
109
113
  "properties": {
package/src/utils.ts CHANGED
@@ -92,6 +92,49 @@ ajv.addKeyword({
92
92
  }
93
93
  });
94
94
 
95
+ ajv.addKeyword({
96
+ keyword: 'maxLengthWithSpaceType',
97
+ validate: function validate(schema, data) {
98
+ // @ts-ignore
99
+ const spaceType = this.spaceType || 'default';
100
+ const isValid = data.length <= schema[spaceType];
101
+ if (!isValid) {
102
+ // @ts-ignore
103
+ validate.errors = [
104
+ {
105
+ keyword: 'maxLengthWithSpaceType',
106
+ message: `must NOT have more than ${schema[spaceType]} characters`,
107
+ params: { limit: schema[spaceType] }
108
+ }
109
+ ];
110
+ }
111
+ return isValid;
112
+ },
113
+ errors: true
114
+ });
115
+
116
+ ajv.addKeyword({
117
+ keyword: 'maxItemsWithSpaceType',
118
+ validate: function validate(schema, data) {
119
+ // @ts-ignore
120
+ const spaceType = this.spaceType || 'default';
121
+ const isValid = data.length <= schema[spaceType];
122
+ if (!isValid) {
123
+ // @ts-ignore
124
+ validate.errors = [
125
+ {
126
+ keyword: 'maxItemsWithSpaceType',
127
+ message: `must NOT have more than ${schema[spaceType]} items`,
128
+ params: { limit: schema[spaceType] }
129
+ }
130
+ ];
131
+ }
132
+ return isValid;
133
+ },
134
+ errors: true
135
+ });
136
+
137
+
95
138
  // Custom URL format to allow empty string values
96
139
  // https://github.com/snapshot-labs/snapshot.js/pull/541/files
97
140
  ajv.addFormat('customUrl', {
@@ -423,11 +466,17 @@ export async function validate(
423
466
  }
424
467
  }
425
468
 
469
+ interface validateSchemaOptions {
470
+ snapshotEnv?: string;
471
+ spaceType?: string;
472
+ }
473
+
426
474
  export function validateSchema(
427
475
  schema,
428
476
  data,
429
- options = {
430
- snapshotEnv: 'default'
477
+ options: validateSchemaOptions = {
478
+ snapshotEnv: 'default',
479
+ spaceType: 'default'
431
480
  }
432
481
  ) {
433
482
  const ajvValidate = ajv.compile(schema);