@discord/intl-message-database 0.0.1-rc.0 → 0.0.1-rc.2

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 (46) hide show
  1. package/package.json +18 -10
  2. package/.cargo/config.toml +0 -12
  3. package/Cargo.toml +0 -38
  4. package/bench/keyless-json.js +0 -91
  5. package/bench/native.js +0 -114
  6. package/bench/util.js +0 -55
  7. package/build.rs +0 -5
  8. package/npm/darwin-arm64/README.md +0 -3
  9. package/npm/darwin-arm64/package.json +0 -18
  10. package/npm/darwin-x64/README.md +0 -3
  11. package/npm/darwin-x64/package.json +0 -18
  12. package/npm/linux-arm64-gnu/README.md +0 -3
  13. package/npm/linux-arm64-gnu/package.json +0 -21
  14. package/npm/linux-arm64-musl/README.md +0 -3
  15. package/npm/linux-arm64-musl/package.json +0 -21
  16. package/npm/linux-x64-gnu/README.md +0 -3
  17. package/npm/linux-x64-gnu/package.json +0 -21
  18. package/npm/linux-x64-musl/README.md +0 -3
  19. package/npm/linux-x64-musl/package.json +0 -21
  20. package/npm/win32-arm64-msvc/README.md +0 -3
  21. package/npm/win32-arm64-msvc/package.json +0 -18
  22. package/npm/win32-ia32-msvc/README.md +0 -3
  23. package/npm/win32-ia32-msvc/package.json +0 -18
  24. package/npm/win32-x64-msvc/README.md +0 -3
  25. package/npm/win32-x64-msvc/package.json +0 -18
  26. package/src/lib.rs +0 -14
  27. package/src/messages/database.rs +0 -343
  28. package/src/messages/error.rs +0 -43
  29. package/src/messages/message_definition.rs +0 -169
  30. package/src/messages/message_variables_visitor.rs +0 -299
  31. package/src/messages/meta.rs +0 -38
  32. package/src/messages/mod.rs +0 -27
  33. package/src/messages/source_file.rs +0 -75
  34. package/src/messages/symbols.rs +0 -164
  35. package/src/messages/translation.rs +0 -64
  36. package/src/messages/value.rs +0 -51
  37. package/src/napi.rs +0 -300
  38. package/src/services/mod.rs +0 -9
  39. package/src/services/precompile.rs +0 -91
  40. package/src/services/types.rs +0 -237
  41. package/src/services/validator.rs +0 -104
  42. package/src/sources/definitions_parser.rs +0 -347
  43. package/src/sources/mod.rs +0 -87
  44. package/src/sources/translations.rs +0 -75
  45. package/src/test.rs +0 -67
  46. package/src/threading.rs +0 -61
package/package.json CHANGED
@@ -1,21 +1,29 @@
1
1
  {
2
2
  "name": "@discord/intl-message-database",
3
- "version": "0.0.1-rc.0",
3
+ "version": "0.0.1-rc.2",
4
4
  "license": "MIT",
5
5
  "description": "Rust-based Node extension module for parsing, extracting, and managing messages and translations across a project.",
6
6
  "author": "Jon Egeland",
7
7
  "main": "./index.js",
8
8
  "types": "./index.d.ts",
9
+ "files": [
10
+ "index.d.ts",
11
+ "index.js"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/discord/discord-intl"
16
+ },
9
17
  "optionalDependencies": {
10
- "@discord/intl-message-database-darwin-arm64": "0.0.1-rc.0",
11
- "@discord/intl-message-database-darwin-x64": "0.0.1-rc.0",
12
- "@discord/intl-message-database-linux-arm64-gnu": "0.0.1-rc.0",
13
- "@discord/intl-message-database-linux-arm64-musl": "0.0.1-rc.0",
14
- "@discord/intl-message-database-linux-x64-gnu": "0.0.1-rc.0",
15
- "@discord/intl-message-database-linux-x64-musl": "0.0.1-rc.0",
16
- "@discord/intl-message-database-win32-arm64-msvc": "0.0.1-rc.0",
17
- "@discord/intl-message-database-win32-ia32-msvc": "0.0.1-rc.0",
18
- "@discord/intl-message-database-win32-x64-msvc": "0.0.1-rc.0"
18
+ "@discord/intl-message-database-darwin-arm64": "0.0.1-rc.2",
19
+ "@discord/intl-message-database-darwin-x64": "0.0.1-rc.2",
20
+ "@discord/intl-message-database-linux-arm64-gnu": "0.0.1-rc.2",
21
+ "@discord/intl-message-database-linux-arm64-musl": "0.0.1-rc.2",
22
+ "@discord/intl-message-database-linux-x64-gnu": "0.0.1-rc.2",
23
+ "@discord/intl-message-database-linux-x64-musl": "0.0.1-rc.2",
24
+ "@discord/intl-message-database-win32-arm64-msvc": "0.0.1-rc.2",
25
+ "@discord/intl-message-database-win32-ia32-msvc": "0.0.1-rc.2",
26
+ "@discord/intl-message-database-win32-x64-msvc": "0.0.1-rc.2"
19
27
  },
20
28
  "devDependencies": {
21
29
  "@napi-rs/cli": "^2.18.3"
@@ -1,12 +0,0 @@
1
- [target.x86_64-pc-windows-msvc]
2
- rustflags = ["-C", "target-feature=+crt-static"]
3
-
4
- [target.aarch64-unknown-linux-musl]
5
- linker = "aarch64-linux-musl-gcc"
6
- rustflags = ["-C", "target-feature=-crt-static"]
7
-
8
- [target.aarch64-apple-darwin.env]
9
- MACOSX_DEPLOYMENT_TARGET = "11"
10
-
11
- [target.x86_64-apple-darwin.env]
12
- MACOSX_DEPLOYMENT_TARGET = "10.13"
package/Cargo.toml DELETED
@@ -1,38 +0,0 @@
1
- [package]
2
- name = "intl_message_database"
3
- description = "A core intl message management databae, supporting CRUD for messages with attribution to their source files."
4
- version = "0.1.0"
5
- edition = "2021"
6
- publish = false
7
-
8
- [lib]
9
- crate-type = ["cdylib"]
10
-
11
- [dependencies]
12
- arcstr = "1"
13
- anyhow = "1"
14
- bitflags = "2"
15
- codespan-reporting = { version = "0.11.1", features = ["serialization"] }
16
- intl_markdown = { path = "../intl_markdown" }
17
- intl_message_utils = { path = "../intl_message_utils" }
18
- keyless_json = { path = "../keyless_json" }
19
- napi = { version = "2", features = ["error_anyhow", "serde-json"] }
20
- napi-derive = "2"
21
- num_cpus = "1"
22
- rustc-hash = "1"
23
- serde = "1"
24
- serde_json = "1"
25
- string-interner = "0.15.0"
26
- swc_common = "0.33.25"
27
- swc_core = { version = "0.90.x", features = [
28
- "ecma_parser",
29
- "ecma_ast",
30
- "ecma_visit",
31
- ] }
32
- thiserror = "1"
33
- threadpool = "1.8.1"
34
- xxhash-rust = { version = "0.8.10", features = ["xxh64"] }
35
- mimalloc = "0.1"
36
-
37
- [build-dependencies]
38
- napi-build = "2"
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FORMAT_JS_POUND = exports.FormatJsNodeType = void 0;
4
- exports.hydrateFormatJsAst = hydrateFormatJsAst;
5
- exports.hydrateMessages = hydrateMessages;
6
- var FormatJsNodeType;
7
- (function (FormatJsNodeType) {
8
- FormatJsNodeType[FormatJsNodeType["Literal"] = 0] = "Literal";
9
- FormatJsNodeType[FormatJsNodeType["Argument"] = 1] = "Argument";
10
- FormatJsNodeType[FormatJsNodeType["Number"] = 2] = "Number";
11
- FormatJsNodeType[FormatJsNodeType["Date"] = 3] = "Date";
12
- FormatJsNodeType[FormatJsNodeType["Time"] = 4] = "Time";
13
- FormatJsNodeType[FormatJsNodeType["Select"] = 5] = "Select";
14
- FormatJsNodeType[FormatJsNodeType["Plural"] = 6] = "Plural";
15
- FormatJsNodeType[FormatJsNodeType["Pound"] = 7] = "Pound";
16
- FormatJsNodeType[FormatJsNodeType["Tag"] = 8] = "Tag";
17
- })(FormatJsNodeType || (exports.FormatJsNodeType = FormatJsNodeType = {}));
18
- // Using a static object here ensures there's only one allocation for it, which
19
- // will likely appear in many, many messages. Freezing ensures that the shared
20
- // object can't be accidentally modified if a consumer tries to transform the
21
- // AST.
22
- exports.FORMAT_JS_POUND = Object.freeze({ type: 7 });
23
- function hydrateArray(elements) {
24
- for (var i = 0; i < elements.length; i++) {
25
- elements[i] = hydrateFormatJsAst(elements[i]);
26
- }
27
- }
28
- function hydratePlural(keyless) {
29
- var type = keyless[0], value = keyless[1], options = keyless[2], offset = keyless[3], pluralType = keyless[4];
30
- // This tries to be efficient about updating the value for each option
31
- // with a parsed version, reusing the same receiving object, and even
32
- // the inner key within it, just replacing the end value with the
33
- // parsed version.
34
- // This saves multiple allocations compared to building a new object
35
- // from scratch, either for the whole options object or for each value.
36
- for (var key in options) {
37
- hydrateArray(options[key].value);
38
- }
39
- // `pluralType` is technically only valid on `Plural` nodes, even
40
- // though the structure is identical to `Select`.
41
- if (type === FormatJsNodeType.Plural) {
42
- return { type: type, value: value, options: options, offset: offset, pluralType: pluralType };
43
- }
44
- else {
45
- return { type: type, value: value, options: options, offset: offset };
46
- }
47
- }
48
- function hydrateSingle(keyless) {
49
- var type = keyless[0];
50
- switch (type) {
51
- case FormatJsNodeType.Literal:
52
- case FormatJsNodeType.Argument:
53
- return { type: type, value: keyless[1] };
54
- case FormatJsNodeType.Number:
55
- case FormatJsNodeType.Date:
56
- case FormatJsNodeType.Time:
57
- return { type: type, value: keyless[1], style: keyless[2] };
58
- case FormatJsNodeType.Select:
59
- case FormatJsNodeType.Plural:
60
- return hydratePlural(keyless);
61
- case FormatJsNodeType.Pound:
62
- return exports.FORMAT_JS_POUND;
63
- case FormatJsNodeType.Tag: {
64
- var type_1 = keyless[0], value = keyless[1], children = keyless[2];
65
- hydrateArray(children);
66
- return { type: type_1, value: value, children: children };
67
- }
68
- default:
69
- throw new Error("FormatJS keyless JSON encountered an unknown type: ".concat(type));
70
- }
71
- }
72
- function hydrateFormatJsAst(keyless) {
73
- // If the first element of the array is itself an array, then we have a list
74
- // of elements to parse rather than a single object.
75
- if (Array.isArray(keyless[0])) {
76
- hydrateArray(keyless);
77
- return keyless;
78
- }
79
- else if (keyless.length === 0) {
80
- // Some entries can be empty arrays, like an empty set of children, and those can
81
- // be preserved.
82
- return keyless;
83
- }
84
- return hydrateSingle(keyless);
85
- }
86
- function hydrateMessages(messages) {
87
- for (var key in messages) {
88
- messages[key] = hydrateFormatJsAst(messages[key]);
89
- }
90
- return messages;
91
- }
package/bench/native.js DELETED
@@ -1,114 +0,0 @@
1
- /* eslint-disable no-console */
2
- // @ts-check
3
-
4
- const { IntlMessagesDatabase, IntlCompiledMessageFormat } = require('..');
5
- const fs = require('node:fs');
6
- const path = require('node:path');
7
- const util = require('node:util');
8
- const { bench, locales: allLocales } = require('./util');
9
- const { hydrateMessages } = require('./keyless-json');
10
-
11
- const locales = allLocales;
12
-
13
- const database = new IntlMessagesDatabase();
14
-
15
- /** @type {IntlCompiledMessageFormat} */
16
- const COMPILATION_FORMAT = IntlCompiledMessageFormat.KeylessJson;
17
-
18
- bench('processing', () => {
19
- database.processDefinitionsFile('./data/input/en-US.js');
20
- // native.processDefinitionsFile(database, './data/input/en-US.untranslated.js');
21
- // native.processDefinitionsFile(database, './data/input/international.untranslated.js');
22
-
23
- // // Single threaded:
24
- // for (const locale of locales) {
25
- // native.processTranslationsFile(database, `./data/input/${locale}.jsona`, locale);
26
- // }
27
-
28
- // Multithreaded:
29
- /** @type {Record<string, string>} */
30
- const localeMap = {};
31
- for (const locale of locales) {
32
- localeMap[locale] = `./data/input/${locale}.jsona`;
33
- }
34
-
35
- database.processAllTranslationFiles(localeMap);
36
- });
37
-
38
- bench('get a message', () => {
39
- // console.log(
40
- util.inspect(
41
- database.getMessage('GUILD_SETTINGS_AUDIT_LOG_CHANNEL_PERMISSION_OVERRIDES_DENIED'),
42
- {
43
- depth: null,
44
- },
45
- );
46
- // );
47
- });
48
-
49
- bench('get source file', () => {
50
- const source = database.getSourceFile('./data/input/en-US.js');
51
- });
52
-
53
- bench('validate', () => {
54
- database.validateMessages();
55
- // const allDiagnostics = validations.flatMap((v) => v.diagnostics);
56
- // console.log(
57
- // util.inspect(
58
- // allDiagnostics.filter((d) => d.severity === 'Error'),
59
- // {depth: null},
60
- // ),
61
- // );
62
- // console.log(util.inspect(validations, {depth: null}));
63
- });
64
-
65
- bench('generate types', () => {
66
- const paths = database.getAllSourceFilePaths();
67
- database.generateTypes(paths[0], './data/output/generated.d.ts');
68
- });
69
-
70
- /**
71
- * @param {IntlCompiledMessageFormat} format
72
- */
73
- function getPrecompileFormat(format) {
74
- switch (format) {
75
- case IntlCompiledMessageFormat.Json:
76
- return 'json';
77
- case IntlCompiledMessageFormat.KeylessJson:
78
- return 'keyless';
79
- }
80
- }
81
-
82
- bench(`precompile (${getPrecompileFormat(COMPILATION_FORMAT)})`, () => {
83
- const locales = database.getKnownLocales();
84
- for (const locale of locales) {
85
- database.precompile(locale, `./data/output/${locale}.json`, COMPILATION_FORMAT);
86
- }
87
- });
88
-
89
- /** @type {Record<string, any>} */
90
- const COMPILED_FILES = {};
91
-
92
- bench('read compiled files', () => {
93
- const files = fs.readdirSync('./data/output/');
94
- for (const file of files) {
95
- if (path.extname(file) === '.json') {
96
- // if (file === 'en-US.json') {
97
- COMPILED_FILES[path.basename(file)] = fs.readFileSync(`./data/output/${file}`).toString();
98
- }
99
- }
100
- });
101
-
102
- bench('parse json', () => {
103
- for (const [locale, data] of Object.entries(COMPILED_FILES)) {
104
- COMPILED_FILES[locale] = JSON.parse(data);
105
- }
106
- });
107
-
108
- if (COMPILATION_FORMAT === IntlCompiledMessageFormat.KeylessJson) {
109
- bench('hydrate json', () => {
110
- for (const [, data] of Object.entries(COMPILED_FILES)) {
111
- hydrateMessages(data);
112
- }
113
- });
114
- }
package/bench/util.js DELETED
@@ -1,55 +0,0 @@
1
- globalThis.window = globalThis;
2
- globalThis.navigator = { languages: ['en-US'] };
3
-
4
- /**
5
- * @param {string} title
6
- * @param {() => unknown} callback
7
- * @param {boolean} log
8
- */
9
- function bench(title, callback, log = true) {
10
- const start = performance.now();
11
- callback();
12
- const end = performance.now();
13
- if (log) {
14
- console.log(title + ': ', end - start);
15
- }
16
- }
17
-
18
- const locales = [
19
- 'bg',
20
- 'cs',
21
- 'da',
22
- 'de',
23
- 'el',
24
- 'en-GB',
25
- 'es-419',
26
- 'es-ES',
27
- 'fi',
28
- 'fr',
29
- 'hi',
30
- 'hr',
31
- 'hu',
32
- 'id',
33
- 'it',
34
- 'ja',
35
- 'ko',
36
- 'lt',
37
- 'nl',
38
- 'no',
39
- 'pl',
40
- 'pt-BR',
41
- 'ro',
42
- 'ru',
43
- 'sv-SE',
44
- 'th',
45
- 'tr',
46
- 'uk',
47
- 'vi',
48
- 'zh-CN',
49
- 'zh-TW',
50
- ];
51
-
52
- module.exports = {
53
- bench,
54
- locales,
55
- };
package/build.rs DELETED
@@ -1,5 +0,0 @@
1
- extern crate napi_build;
2
-
3
- fn main() {
4
- napi_build::setup();
5
- }
@@ -1,3 +0,0 @@
1
- # `intl-message-database-darwin-arm64`
2
-
3
- This is the **aarch64-apple-darwin** binary for `intl-message-database`
@@ -1,18 +0,0 @@
1
- {
2
- "name": "@discord/intl-message-database-darwin-arm64",
3
- "version": "0.0.1-rc.0",
4
- "license": "MIT",
5
- "os": [
6
- "darwin"
7
- ],
8
- "cpu": [
9
- "arm64"
10
- ],
11
- "main": "intl-message-database.darwin-arm64.node",
12
- "files": [
13
- "intl-message-database.darwin-arm64.node"
14
- ],
15
- "engines": {
16
- "node": ">= 10"
17
- }
18
- }
@@ -1,3 +0,0 @@
1
- # `intl-message-database-darwin-x64`
2
-
3
- This is the **x86_64-apple-darwin** binary for `intl-message-database`
@@ -1,18 +0,0 @@
1
- {
2
- "name": "@discord/intl-message-database-darwin-x64",
3
- "version": "0.0.1-rc.0",
4
- "license": "MIT",
5
- "os": [
6
- "darwin"
7
- ],
8
- "cpu": [
9
- "x64"
10
- ],
11
- "main": "intl-message-database.darwin-x64.node",
12
- "files": [
13
- "intl-message-database.darwin-x64.node"
14
- ],
15
- "engines": {
16
- "node": ">= 10"
17
- }
18
- }
@@ -1,3 +0,0 @@
1
- # `intl-message-database-linux-arm64-gnu`
2
-
3
- This is the **aarch64-unknown-linux-gnu** binary for `intl-message-database`
@@ -1,21 +0,0 @@
1
- {
2
- "name": "@discord/intl-message-database-linux-arm64-gnu",
3
- "version": "0.0.1-rc.0",
4
- "license": "MIT",
5
- "os": [
6
- "linux"
7
- ],
8
- "cpu": [
9
- "arm64"
10
- ],
11
- "main": "intl-message-database.linux-arm64-gnu.node",
12
- "files": [
13
- "intl-message-database.linux-arm64-gnu.node"
14
- ],
15
- "engines": {
16
- "node": ">= 10"
17
- },
18
- "libc": [
19
- "glibc"
20
- ]
21
- }
@@ -1,3 +0,0 @@
1
- # `intl-message-database-linux-arm64-musl`
2
-
3
- This is the **aarch64-unknown-linux-musl** binary for `intl-message-database`
@@ -1,21 +0,0 @@
1
- {
2
- "name": "@discord/intl-message-database-linux-arm64-musl",
3
- "version": "0.0.1-rc.0",
4
- "license": "MIT",
5
- "os": [
6
- "linux"
7
- ],
8
- "cpu": [
9
- "arm64"
10
- ],
11
- "main": "intl-message-database.linux-arm64-musl.node",
12
- "files": [
13
- "intl-message-database.linux-arm64-musl.node"
14
- ],
15
- "engines": {
16
- "node": ">= 10"
17
- },
18
- "libc": [
19
- "musl"
20
- ]
21
- }
@@ -1,3 +0,0 @@
1
- # `intl-message-database-linux-x64-gnu`
2
-
3
- This is the **x86_64-unknown-linux-gnu** binary for `intl-message-database`
@@ -1,21 +0,0 @@
1
- {
2
- "name": "@discord/intl-message-database-linux-x64-gnu",
3
- "version": "0.0.1-rc.0",
4
- "license": "MIT",
5
- "os": [
6
- "linux"
7
- ],
8
- "cpu": [
9
- "x64"
10
- ],
11
- "main": "intl-message-database.linux-x64-gnu.node",
12
- "files": [
13
- "intl-message-database.linux-x64-gnu.node"
14
- ],
15
- "engines": {
16
- "node": ">= 10"
17
- },
18
- "libc": [
19
- "glibc"
20
- ]
21
- }
@@ -1,3 +0,0 @@
1
- # `intl-message-database-linux-x64-musl`
2
-
3
- This is the **x86_64-unknown-linux-musl** binary for `intl-message-database`
@@ -1,21 +0,0 @@
1
- {
2
- "name": "@discord/intl-message-database-linux-x64-musl",
3
- "version": "0.0.1-rc.0",
4
- "license": "MIT",
5
- "os": [
6
- "linux"
7
- ],
8
- "cpu": [
9
- "x64"
10
- ],
11
- "main": "intl-message-database.linux-x64-musl.node",
12
- "files": [
13
- "intl-message-database.linux-x64-musl.node"
14
- ],
15
- "engines": {
16
- "node": ">= 10"
17
- },
18
- "libc": [
19
- "musl"
20
- ]
21
- }
@@ -1,3 +0,0 @@
1
- # `intl-message-database-win32-arm64-msvc`
2
-
3
- This is the **aarch64-pc-windows-msvc** binary for `intl-message-database`
@@ -1,18 +0,0 @@
1
- {
2
- "name": "@discord/intl-message-database-win32-arm64-msvc",
3
- "version": "0.0.1-rc.0",
4
- "license": "MIT",
5
- "os": [
6
- "win32"
7
- ],
8
- "cpu": [
9
- "arm64"
10
- ],
11
- "main": "intl-message-database.win32-arm64-msvc.node",
12
- "files": [
13
- "intl-message-database.win32-arm64-msvc.node"
14
- ],
15
- "engines": {
16
- "node": ">= 10"
17
- }
18
- }
@@ -1,3 +0,0 @@
1
- # `intl-message-database-win32-ia32-msvc`
2
-
3
- This is the **i686-pc-windows-msvc** binary for `intl-message-database`
@@ -1,18 +0,0 @@
1
- {
2
- "name": "@discord/intl-message-database-win32-ia32-msvc",
3
- "version": "0.0.1-rc.0",
4
- "license": "MIT",
5
- "os": [
6
- "win32"
7
- ],
8
- "cpu": [
9
- "ia32"
10
- ],
11
- "main": "intl-message-database.win32-ia32-msvc.node",
12
- "files": [
13
- "intl-message-database.win32-ia32-msvc.node"
14
- ],
15
- "engines": {
16
- "node": ">= 10"
17
- }
18
- }
@@ -1,3 +0,0 @@
1
- # `intl-message-database-win32-x64-msvc`
2
-
3
- This is the **x86_64-pc-windows-msvc** binary for `intl-message-database`
@@ -1,18 +0,0 @@
1
- {
2
- "name": "@discord/intl-message-database-win32-x64-msvc",
3
- "version": "0.0.1-rc.0",
4
- "license": "MIT",
5
- "os": [
6
- "win32"
7
- ],
8
- "cpu": [
9
- "x64"
10
- ],
11
- "main": "intl-message-database.win32-x64-msvc.node",
12
- "files": [
13
- "intl-message-database.win32-x64-msvc.node"
14
- ],
15
- "engines": {
16
- "node": ">= 10"
17
- }
18
- }
package/src/lib.rs DELETED
@@ -1,14 +0,0 @@
1
- use mimalloc::MiMalloc;
2
-
3
- #[global_allocator]
4
- static GLOBAL: MiMalloc = MiMalloc;
5
-
6
- pub mod messages;
7
- pub mod services;
8
- pub mod sources;
9
- mod threading;
10
-
11
- pub mod napi;
12
-
13
- #[cfg(test)]
14
- pub mod test;