json-as 0.5.37 → 0.5.39

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.
@@ -2,7 +2,7 @@ import {
2
2
  ClassDeclaration,
3
3
  FieldDeclaration,
4
4
  Source,
5
- Parser
5
+ Parser,
6
6
  } from "assemblyscript/dist/assemblyscript";
7
7
  import { toString, isStdlib } from "visitor-as/dist/utils.js";
8
8
  import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js";
@@ -23,14 +23,19 @@ class AsJSONTransform extends BaseVisitor {
23
23
  public currentClass!: SchemaData;
24
24
  public sources: Source[] = [];
25
25
 
26
- visitMethodDeclaration(): void { }
26
+ visitMethodDeclaration(): void {}
27
27
  visitClassDeclaration(node: ClassDeclaration): void {
28
28
  const className = node.name.text;
29
29
  if (!node.decorators?.length) return;
30
30
  let foundDecorator = false;
31
31
  for (const decorator of node.decorators!) {
32
- // @ts-ignore
33
- if (decorator.name.text.toLowerCase() == "json" || decorator.name.text.toLowerCase() == "serializable") foundDecorator = true;
32
+ if (
33
+ // @ts-ignore
34
+ decorator.name.text.toLowerCase() == "json" ||
35
+ // @ts-ignore
36
+ decorator.name.text.toLowerCase() == "serializable"
37
+ )
38
+ foundDecorator = true;
34
39
  }
35
40
  if (!foundDecorator) return;
36
41
 
@@ -47,38 +52,63 @@ class AsJSONTransform extends BaseVisitor {
47
52
  parent: node.extendsType ? toString(node.extendsType) : "",
48
53
  node: node,
49
54
  encodeStmts: [],
50
- setDataStmts: []
51
- }
55
+ setDataStmts: [],
56
+ };
52
57
 
53
58
  if (this.currentClass.parent.length > 0) {
54
- const parentSchema = this.schemasList.find((v) => v.name == this.currentClass.parent);
59
+ const parentSchema = this.schemasList.find(
60
+ (v) => v.name == this.currentClass.parent
61
+ );
55
62
  if (parentSchema?.encodeStmts) {
56
63
  parentSchema?.encodeStmts.push(parentSchema?.encodeStmts.pop() + ",");
57
64
  this.currentClass.encodeStmts.push(...parentSchema?.encodeStmts);
58
65
  } else {
59
- console.error("Class extends " + this.currentClass.parent + ", but parent class not found. Maybe add the @json decorator over parent class?");
66
+ console.error(
67
+ "Class extends " +
68
+ this.currentClass.parent +
69
+ ", but parent class not found. Maybe add the @json decorator over parent class?"
70
+ );
60
71
  }
61
72
  }
62
73
 
63
- const parentSchema = this.schemasList.find((v) => v.name == this.currentClass.parent);
64
- const members = [...node.members, ...(parentSchema ? parentSchema.node.members : [])];
74
+ const parentSchema = this.schemasList.find(
75
+ (v) => v.name == this.currentClass.parent
76
+ );
77
+ const members = [
78
+ ...node.members,
79
+ ...(parentSchema ? parentSchema.node.members : []),
80
+ ];
65
81
 
66
82
  for (const mem of members) {
83
+ // @ts-ignore
67
84
  if (mem.type && mem.type.name && mem.type.name.identifier.text) {
68
- const member: FieldDeclaration = mem;
85
+ const member = mem as FieldDeclaration;
69
86
  if (toString(member).startsWith("static")) return;
70
87
  const lineText = toString(member);
71
88
  if (lineText.startsWith("private")) return;
72
89
 
73
90
  // @ts-ignore
74
91
  let type = toString(member.type);
75
-
92
+
76
93
  const name = member.name.text;
77
94
  this.currentClass.keys.push(name);
78
95
  // @ts-ignore
79
96
  this.currentClass.types.push(type);
80
97
  // @ts-ignore
81
- if (["u8", "i8", "u16", "i16", "u32", "i32", "f32", "u64", "i64", "f64"].includes(type.toLowerCase())) {
98
+ if (
99
+ [
100
+ "u8",
101
+ "i8",
102
+ "u16",
103
+ "i16",
104
+ "u32",
105
+ "i32",
106
+ "f32",
107
+ "u64",
108
+ "i64",
109
+ "f64",
110
+ ].includes(type.toLowerCase())
111
+ ) {
82
112
  this.currentClass.encodeStmts.push(
83
113
  `"${name}":\${this.${name}.toString()},`
84
114
  );
@@ -101,11 +131,12 @@ class AsJSONTransform extends BaseVisitor {
101
131
  let serializeFunc = "";
102
132
 
103
133
  if (this.currentClass.encodeStmts.length > 0) {
104
- const stmt = this.currentClass.encodeStmts[this.currentClass.encodeStmts.length - 1]!;
105
- this.currentClass.encodeStmts[this.currentClass.encodeStmts.length - 1] = stmt!.slice(
106
- 0,
107
- stmt.length - 1
108
- );
134
+ const stmt =
135
+ this.currentClass.encodeStmts[
136
+ this.currentClass.encodeStmts.length - 1
137
+ ]!;
138
+ this.currentClass.encodeStmts[this.currentClass.encodeStmts.length - 1] =
139
+ stmt!.slice(0, stmt.length - 1);
109
140
  serializeFunc = `
110
141
  @inline
111
142
  __JSON_Serialize(): string {
@@ -125,19 +156,16 @@ class AsJSONTransform extends BaseVisitor {
125
156
  @inline
126
157
  __JSON_Set_Key(key: string, value: string): void {
127
158
  ${
128
- // @ts-ignore
129
- this.currentClass.setDataStmts.join("")
130
- }
159
+ // @ts-ignore
160
+ this.currentClass.setDataStmts.join("")
161
+ }
131
162
  }
132
163
  `;
133
164
 
134
165
  const serializeMethod = SimpleParser.parseClassMember(serializeFunc, node);
135
166
  node.members.push(serializeMethod);
136
167
 
137
- const setDataMethod = SimpleParser.parseClassMember(
138
- setKeyFunc,
139
- node
140
- );
168
+ const setDataMethod = SimpleParser.parseClassMember(setKeyFunc, node);
141
169
  node.members.push(setDataMethod);
142
170
 
143
171
  this.schemasList.push(this.currentClass);
@@ -154,17 +182,19 @@ export default class Transformer extends Transform {
154
182
  const transformer = new AsJSONTransform();
155
183
 
156
184
  // Sort the sources so that user scripts are visited last
157
- const sources = parser.sources.filter(source => !isStdlib(source)).sort((_a, _b) => {
158
- const a = _a.internalPath
159
- const b = _b.internalPath
160
- if (a[0] === "~" && b[0] !== "~") {
161
- return -1;
162
- } else if (a[0] !== "~" && b[0] === "~") {
163
- return 1;
164
- } else {
165
- return 0;
166
- }
167
- });
185
+ const sources = parser.sources
186
+ .filter((source) => !isStdlib(source))
187
+ .sort((_a, _b) => {
188
+ const a = _a.internalPath;
189
+ const b = _b.internalPath;
190
+ if (a[0] === "~" && b[0] !== "~") {
191
+ return -1;
192
+ } else if (a[0] !== "~" && b[0] === "~") {
193
+ return 1;
194
+ } else {
195
+ return 0;
196
+ }
197
+ });
168
198
 
169
199
  // Loop over every source
170
200
  for (const source of sources) {
@@ -174,4 +204,4 @@ export default class Transformer extends Transform {
174
204
  }
175
205
  }
176
206
  }
177
- };
207
+ }
@@ -1,70 +1,70 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
-
5
- /* Basic Options */
6
- // "incremental": true, /* Enable incremental compilation */
7
- "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
8
- "module": "es6" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
9
- // "lib": [], /* Specify library files to be included in the compilation. */
10
- // "allowJs": true, /* Allow javascript files to be compiled. */
11
- // "checkJs": true, /* Report errors in .js files. */
12
- // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
13
- "declaration": false /* Generates corresponding '.d.ts' file. */,
14
- // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
- "sourceMap": false /* Generates corresponding '.map' file. */,
16
- // "outFile": "./", /* Concatenate and emit output to single file. */
17
- "outDir": "./lib" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
18
- // "composite": true, /* Enable project compilation */
19
- // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
20
- // "removeComments": true, /* Do not emit comments to output. */
21
- // "noEmit": true, /* Do not emit outputs. */
22
- // "importHelpers": true, /* Import emit helpers from 'tslib'. */
23
- "downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
24
- // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
25
-
26
- /* Strict Type-Checking Options */
27
- "strict": true /* Enable all strict type-checking options. */,
28
- "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'Unknown' type. */,
29
- "strictNullChecks": true /* Enable strict null checks. */,
30
- "strictFunctionTypes": true /* Enable strict checking of function types. */,
31
- "strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */,
32
- "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
33
- "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'Unknown' type. */,
34
- "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
35
-
36
- /* Additional Checks */
37
- "noUnusedLocals": true /* Report errors on unused locals. */,
38
- "noUnusedParameters": true /* Report errors on unused parameters. */,
39
- "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
40
- // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
41
- "noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */,
42
- "noPropertyAccessFromIndexSignature": true /* Require undeclared properties from index signatures to use element accesses. */,
43
-
44
- /* Module Resolution Options */
45
- "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
46
- // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
47
- // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
48
- // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
49
- // "typeRoots": [], /* List of folders to include type definitions from. */
50
- // "types": [], /* Type declaration files to be included in compilation. */
51
- // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
52
- "esModuleInterop": false /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
53
- // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
54
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
55
-
56
- /* Source Map Options */
57
- // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
58
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
59
- // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
60
- // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
61
-
62
- /* Experimental Options */
63
- // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
64
- // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
65
-
66
- /* Advanced Options */
67
- "skipLibCheck": true /* Skip type checking of declaration files. */,
68
- "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
69
- }
70
- }
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
+
5
+ /* Basic Options */
6
+ // "incremental": true, /* Enable incremental compilation */
7
+ "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
8
+ "module": "es6" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
9
+ // "lib": [], /* Specify library files to be included in the compilation. */
10
+ // "allowJs": true, /* Allow javascript files to be compiled. */
11
+ // "checkJs": true, /* Report errors in .js files. */
12
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
13
+ "declaration": false /* Generates corresponding '.d.ts' file. */,
14
+ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
+ "sourceMap": false /* Generates corresponding '.map' file. */,
16
+ // "outFile": "./", /* Concatenate and emit output to single file. */
17
+ "outDir": "./lib" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
18
+ // "composite": true, /* Enable project compilation */
19
+ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
20
+ // "removeComments": true, /* Do not emit comments to output. */
21
+ // "noEmit": true, /* Do not emit outputs. */
22
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
23
+ "downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
24
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
25
+
26
+ /* Strict Type-Checking Options */
27
+ "strict": true /* Enable all strict type-checking options. */,
28
+ "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'Unknown' type. */,
29
+ "strictNullChecks": true /* Enable strict null checks. */,
30
+ "strictFunctionTypes": true /* Enable strict checking of function types. */,
31
+ "strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */,
32
+ "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
33
+ "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'Unknown' type. */,
34
+ "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
35
+
36
+ /* Additional Checks */
37
+ "noUnusedLocals": true /* Report errors on unused locals. */,
38
+ "noUnusedParameters": true /* Report errors on unused parameters. */,
39
+ "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
40
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
41
+ "noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */,
42
+ "noPropertyAccessFromIndexSignature": true /* Require undeclared properties from index signatures to use element accesses. */,
43
+
44
+ /* Module Resolution Options */
45
+ "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
46
+ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
47
+ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
48
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
49
+ // "typeRoots": [], /* List of folders to include type definitions from. */
50
+ // "types": [], /* Type declaration files to be included in compilation. */
51
+ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
52
+ "esModuleInterop": false /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
53
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
54
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
55
+
56
+ /* Source Map Options */
57
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
58
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
59
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
60
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
61
+
62
+ /* Experimental Options */
63
+ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
64
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
65
+
66
+ /* Advanced Options */
67
+ "skipLibCheck": true /* Skip type checking of declaration files. */,
68
+ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
69
+ }
70
+ }
package/tsconfig.json CHANGED
@@ -11,11 +11,11 @@
11
11
  // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
12
 
13
13
  /* Language and Environment */
14
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
14
+ "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
15
  // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
16
  // "jsx": "preserve", /* Specify what JSX code is generated. */
17
- // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
17
+ "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
+ "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
19
  // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
20
  // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
21
  // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
@@ -25,7 +25,7 @@
25
25
  // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
26
 
27
27
  /* Modules */
28
- "module": "commonjs", /* Specify what module code is generated. */
28
+ "module": "commonjs" /* Specify what module code is generated. */,
29
29
  // "rootDir": "./", /* Specify the root folder within your source files. */
30
30
  // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
31
31
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
@@ -71,22 +71,22 @@
71
71
  /* Interop Constraints */
72
72
  // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
73
73
  // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
74
+ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
75
75
  // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
76
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
76
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
77
77
 
78
78
  /* Type Checking */
79
- "strict": true, /* Enable all strict type-checking options. */
79
+ "strict": true /* Enable all strict type-checking options. */,
80
80
  // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
81
- // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
81
+ "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
82
82
  // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
83
83
  // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
84
84
  // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
85
85
  // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
86
86
  // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
87
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
88
- // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
89
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
87
+ "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
88
+ "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
89
+ "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
90
90
  // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
91
91
  // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
92
92
  // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
@@ -98,6 +98,6 @@
98
98
 
99
99
  /* Completeness */
100
100
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
101
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
101
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
102
102
  }
103
103
  }
@@ -1,74 +0,0 @@
1
- // XXHash 32-bit as a starting point, see: https://cyan4973.github.io/xxHash
2
- // primes
3
- // @ts-ignore: decorator
4
- const XXH32_P1 = 2654435761;
5
- // @ts-ignore: decorator
6
- const XXH32_P2 = 2246822519;
7
- // @ts-ignore: decorator
8
- const XXH32_P3 = 3266489917;
9
- // @ts-ignore: decorator
10
- const XXH32_P4 = 668265263;
11
- // @ts-ignore: decorator
12
- const XXH32_P5 = 374761393;
13
- // @ts-ignore: decorator
14
- const XXH32_SEED = 0;
15
- function hash32(key, len = 4) {
16
- let h = XXH32_SEED + XXH32_P5 + len;
17
- h += key * XXH32_P3;
18
- h = rotl(h, 17) * XXH32_P4;
19
- h ^= h >> 15;
20
- h *= XXH32_P2;
21
- h ^= h >> 13;
22
- h *= XXH32_P3;
23
- h ^= h >> 16;
24
- return h;
25
- }
26
- function rotl(x, r) {
27
- return (x << r) | (x >>> (32 - r));
28
- }
29
- function mix(h, key) {
30
- return rotl(h + key * XXH32_P2, 13) * XXH32_P1;
31
- }
32
- export function hashStr(key) {
33
- if (key == null)
34
- return XXH32_SEED;
35
- let h = key.length;
36
- let len = h;
37
- let pos = 0;
38
- if (len >= 16) {
39
- let s1 = XXH32_SEED + XXH32_P1 + XXH32_P2;
40
- let s2 = XXH32_SEED + XXH32_P2;
41
- let s3 = XXH32_SEED;
42
- let s4 = XXH32_SEED - XXH32_P1;
43
- let end = len + pos - 16;
44
- while (pos <= end) {
45
- s1 = mix(s1, key.charCodeAt(pos));
46
- s2 = mix(s2, key.charCodeAt(pos + 1));
47
- s3 = mix(s3, key.charCodeAt(pos + 2));
48
- s4 = mix(s4, load(pos, 12));
49
- pos += 16;
50
- }
51
- h += rotl(s1, 1) + rotl(s2, 7) + rotl(s3, 12) + rotl(s4, 18);
52
- }
53
- else {
54
- h += XXH32_SEED + XXH32_P5;
55
- }
56
- let end = changetype(key) + len - 4;
57
- while (pos <= end) {
58
- h += load(pos) * XXH32_P3;
59
- h = rotl(h, 17) * XXH32_P4;
60
- pos += 4;
61
- }
62
- end = changetype(key) + len;
63
- while (pos < end) {
64
- h += load(pos) * XXH32_P5;
65
- h = rotl(h, 11) * XXH32_P1;
66
- pos++;
67
- }
68
- h ^= h >> 15;
69
- h *= XXH32_P2;
70
- h ^= h >> 13;
71
- h *= XXH32_P3;
72
- h ^= h >> 16;
73
- return h;
74
- }
@@ -1,15 +0,0 @@
1
- export var Types;
2
- (function (Types) {
3
- Types[Types["String"] = 0] = "String";
4
- Types[Types["u8"] = 1] = "u8";
5
- Types[Types["i8"] = 2] = "i8";
6
- Types[Types["u16"] = 3] = "u16";
7
- Types[Types["i16"] = 4] = "i16";
8
- Types[Types["u32"] = 5] = "u32";
9
- Types[Types["i32"] = 6] = "i32";
10
- Types[Types["u64"] = 7] = "u64";
11
- Types[Types["i64"] = 8] = "i64";
12
- Types[Types["f32"] = 9] = "f32";
13
- Types[Types["f64"] = 10] = "f64";
14
- Types[Types["boolean"] = 11] = "boolean";
15
- })(Types || (Types = {}));
@@ -1,83 +0,0 @@
1
- // XXHash 32-bit as a starting point, see: https://cyan4973.github.io/xxHash
2
-
3
- // primes
4
- // @ts-ignore: decorator
5
- const XXH32_P1: number = 2654435761;
6
- // @ts-ignore: decorator
7
- const XXH32_P2: number = 2246822519;
8
- // @ts-ignore: decorator
9
- const XXH32_P3: number = 3266489917;
10
- // @ts-ignore: decorator
11
- const XXH32_P4: number = 668265263;
12
- // @ts-ignore: decorator
13
- const XXH32_P5: number = 374761393;
14
- // @ts-ignore: decorator
15
- const XXH32_SEED: number = 0;
16
-
17
- function hash32(key: number, len: number = 4): number {
18
- let h: number = XXH32_SEED + XXH32_P5 + len;
19
- h += key * XXH32_P3;
20
- h = rotl(h, 17) * XXH32_P4;
21
- h ^= h >> 15;
22
- h *= XXH32_P2;
23
- h ^= h >> 13;
24
- h *= XXH32_P3;
25
- h ^= h >> 16;
26
- return h;
27
- }
28
-
29
- function rotl(x: number, r: number): number {
30
- return (x << r) | (x >>> (32 - r));
31
- }
32
-
33
- function mix(h: number, key: number): number {
34
- return rotl(h + key * XXH32_P2, 13) * XXH32_P1;
35
- }
36
-
37
- export function hashStr(key: string): number {
38
- if (key == null) return XXH32_SEED;
39
-
40
- let h: number = key.length;
41
- let len: number = h;
42
- let pos = 0;
43
-
44
- if (len >= 16) {
45
- let s1 = XXH32_SEED + XXH32_P1 + XXH32_P2;
46
- let s2 = XXH32_SEED + XXH32_P2;
47
- let s3 = XXH32_SEED;
48
- let s4 = XXH32_SEED - XXH32_P1;
49
-
50
- let end = len + pos - 16;
51
- while (pos <= end) {
52
- s1 = mix(s1, key.charCodeAt(pos));
53
- s2 = mix(s2, key.charCodeAt(pos + 1));
54
- s3 = mix(s3, key.charCodeAt(pos + 2));
55
- s4 = mix(s4, load<number>(pos, 12));
56
- pos += 16;
57
- }
58
- h += rotl(s1, 1) + rotl(s2, 7) + rotl(s3, 12) + rotl(s4, 18);
59
- } else {
60
- h += XXH32_SEED + XXH32_P5;
61
- }
62
-
63
- let end = changetype<number>(key) + len - 4;
64
- while (pos <= end) {
65
- h += load<number>(pos) * XXH32_P3;
66
- h = rotl(h, 17) * XXH32_P4;
67
- pos += 4;
68
- }
69
-
70
- end = changetype<number>(key) + len;
71
- while (pos < end) {
72
- h += <number>load<u8>(pos) * XXH32_P5;
73
- h = rotl(h, 11) * XXH32_P1;
74
- pos++;
75
- }
76
-
77
- h ^= h >> 15;
78
- h *= XXH32_P2;
79
- h ^= h >> 13;
80
- h *= XXH32_P3;
81
- h ^= h >> 16;
82
- return h;
83
- }