From 5e1efe9149bfc06f7b80f65d9881acdcb6376e94 Mon Sep 17 00:00:00 2001 From: Martin Lysk Date: Fri, 19 Jul 2024 11:19:36 +0200 Subject: [PATCH 01/35] WIP - api with types before exposing kisly directly --- inlang/source-code/sdk-v2/.eslintrc.json | 21 + inlang/source-code/sdk-v2/LICENSE | 201 ++ inlang/source-code/sdk-v2/README.md | 16 + inlang/source-code/sdk-v2/package.json | 64 + .../source-code/sdk-v2/sample-app/.gitignore | 26 + .../source-code/sdk-v2/sample-app/README.md | 10 + .../source-code/sdk-v2/sample-app/index.html | 96 + .../sdk-v2/sample-app/package.json | 40 + .../sample-app/src/MessageBundleView.tsx | 81 + .../sdk-v2/sample-app/src/PageView.tsx | 95 + .../sdk-v2/sample-app/src/main.tsx | 26 + .../sdk-v2/sample-app/src/mainView.tsx | 101 + .../sdk-v2/sample-app/src/mainViewIframe.tsx | 136 + .../sample-app/src/messageBundleListReact.tsx | 141 + .../src/messageBundleListSummary.tsx | 112 + .../sdk-v2/sample-app/src/mock/bundle.ts | 26 + .../sdk-v2/sample-app/src/mock/settings.ts | 14 + .../sdk-v2/sample-app/src/settingsView.tsx | 67 + .../sdk-v2/sample-app/src/style.css | 0 .../sdk-v2/sample-app/src/vite-env.d.ts | 1 + .../sdk-v2/sample-app/tsconfig.json | 20 + .../sdk-v2/sample-app/vite.config.ts | 32 + .../sdk-v2/src/defaultProjectSettings.ts | 28 + .../sdk-v2/src/dev-modules/lint-rule.js | 56 + .../dev-modules/missing-selector-lint-rule.ts | 57 + .../dev-modules/missing-varint-lint-rule.ts | 16 + .../sdk-v2/src/dev-modules/missingCatchall.ts | 46 + .../dev-modules/opral-uppercase-lint-rule.ts | 69 + inlang/source-code/sdk-v2/src/errors.ts | 84 + .../sdk-v2/src/human-id/human-readable-id.ts | 27 + .../sdk-v2/src/human-id/words.test.ts | 27 + .../source-code/sdk-v2/src/human-id/words.ts | 1035 +++++++ inlang/source-code/sdk-v2/src/import-utils.ts | 44 + inlang/source-code/sdk-v2/src/index.ts | 5 + .../sdk-v2/src/lint/createLinter.ts | 98 + inlang/source-code/sdk-v2/src/lint/host.ts | 26 + inlang/source-code/sdk-v2/src/lint/import.ts | 136 + .../sdk-v2/src/lint/populateLintLevel.ts | 38 + .../source-code/sdk-v2/src/loadProjectOpfs.ts | 357 +++ .../source-code/sdk-v2/src/mock/mockdata.ts | 465 +++ .../source-code/sdk-v2/src/mock/mockhelper.ts | 223 ++ .../source-code/sdk-v2/src/newProjectOpfs.ts | 71 + .../sdk-v2/src/resolve-modules/cache.ts | 106 + .../sdk-v2/src/resolve-modules/errors.ts | 69 + .../sdk-v2/src/resolve-modules/import.test.ts | 62 + .../sdk-v2/src/resolve-modules/import.ts | 134 + .../sdk-v2/src/resolve-modules/index.ts | 2 + .../message-lint-rules/errors.ts | 9 + .../resolveMessageLintRules.ts | 27 + .../src/resolve-modules/plugins/errors.ts | 56 + .../plugins/resolvePlugins.test.ts | 301 ++ .../resolve-modules/plugins/resolvePlugins.ts | 129 + .../src/resolve-modules/plugins/types.test.ts | 53 + .../src/resolve-modules/plugins/types.ts | 76 + .../resolve-modules/resolveModules.test.ts | 224 ++ .../src/resolve-modules/resolveModules.ts | 113 + .../sdk-v2/src/resolve-modules/types.ts | 72 + .../validateModuleSettings.test.ts | 85 + .../validatedModuleSettings.ts | 19 + .../src/resolveMessageBundleLintRules.ts | 29 + .../sdk-v2/src/resolveModules2.test.ts | 224 ++ .../source-code/sdk-v2/src/resolveModules2.ts | 110 + .../source-code/sdk-v2/src/resolvePlugins2.ts | 126 + inlang/source-code/sdk-v2/src/settings.ts | 65 + .../customApis/app.inlang.ideExtension.ts | 92 + inlang/source-code/sdk-v2/src/types/index.ts | 11 + .../sdk-v2/src/types/inlang-module.ts | 16 + .../sdk-v2/src/types/language-tag.ts | 22 + .../sdk-v2/src/types/lint-errors.ts | 9 + inlang/source-code/sdk-v2/src/types/lint.ts | 178 ++ .../sdk-v2/src/types/module-errors.ts | 67 + inlang/source-code/sdk-v2/src/types/module.ts | 79 + .../sdk-v2/src/types/plugin-errors.ts | 56 + inlang/source-code/sdk-v2/src/types/plugin.ts | 151 + .../sdk-v2/src/types/project-settings.ts | 125 + .../source-code/sdk-v2/src/types/project.ts | 75 + inlang/source-code/sdk-v2/src/types/schema.ts | 127 + .../source-code/sdk-v2/src/types/sdkTypes.ts | 9 + .../sdk-v2/src/validatedModuleSettings.ts | 19 + inlang/source-code/sdk-v2/src/x.ts | 42 + inlang/source-code/sdk-v2/tsconfig.json | 14 + inlang/source-code/sdk-v2/vitest.config.ts | 12 + pnpm-lock.yaml | 2598 ++++++++++++++--- pnpm-workspace.yaml | 1 + 84 files changed, 9691 insertions(+), 337 deletions(-) create mode 100644 inlang/source-code/sdk-v2/.eslintrc.json create mode 100644 inlang/source-code/sdk-v2/LICENSE create mode 100644 inlang/source-code/sdk-v2/README.md create mode 100644 inlang/source-code/sdk-v2/package.json create mode 100644 inlang/source-code/sdk-v2/sample-app/.gitignore create mode 100644 inlang/source-code/sdk-v2/sample-app/README.md create mode 100644 inlang/source-code/sdk-v2/sample-app/index.html create mode 100644 inlang/source-code/sdk-v2/sample-app/package.json create mode 100644 inlang/source-code/sdk-v2/sample-app/src/MessageBundleView.tsx create mode 100644 inlang/source-code/sdk-v2/sample-app/src/PageView.tsx create mode 100644 inlang/source-code/sdk-v2/sample-app/src/main.tsx create mode 100644 inlang/source-code/sdk-v2/sample-app/src/mainView.tsx create mode 100644 inlang/source-code/sdk-v2/sample-app/src/mainViewIframe.tsx create mode 100644 inlang/source-code/sdk-v2/sample-app/src/messageBundleListReact.tsx create mode 100644 inlang/source-code/sdk-v2/sample-app/src/messageBundleListSummary.tsx create mode 100644 inlang/source-code/sdk-v2/sample-app/src/mock/bundle.ts create mode 100644 inlang/source-code/sdk-v2/sample-app/src/mock/settings.ts create mode 100644 inlang/source-code/sdk-v2/sample-app/src/settingsView.tsx create mode 100644 inlang/source-code/sdk-v2/sample-app/src/style.css create mode 100644 inlang/source-code/sdk-v2/sample-app/src/vite-env.d.ts create mode 100644 inlang/source-code/sdk-v2/sample-app/tsconfig.json create mode 100644 inlang/source-code/sdk-v2/sample-app/vite.config.ts create mode 100644 inlang/source-code/sdk-v2/src/defaultProjectSettings.ts create mode 100644 inlang/source-code/sdk-v2/src/dev-modules/lint-rule.js create mode 100644 inlang/source-code/sdk-v2/src/dev-modules/missing-selector-lint-rule.ts create mode 100644 inlang/source-code/sdk-v2/src/dev-modules/missing-varint-lint-rule.ts create mode 100644 inlang/source-code/sdk-v2/src/dev-modules/missingCatchall.ts create mode 100644 inlang/source-code/sdk-v2/src/dev-modules/opral-uppercase-lint-rule.ts create mode 100644 inlang/source-code/sdk-v2/src/errors.ts create mode 100644 inlang/source-code/sdk-v2/src/human-id/human-readable-id.ts create mode 100644 inlang/source-code/sdk-v2/src/human-id/words.test.ts create mode 100644 inlang/source-code/sdk-v2/src/human-id/words.ts create mode 100644 inlang/source-code/sdk-v2/src/import-utils.ts create mode 100644 inlang/source-code/sdk-v2/src/index.ts create mode 100644 inlang/source-code/sdk-v2/src/lint/createLinter.ts create mode 100644 inlang/source-code/sdk-v2/src/lint/host.ts create mode 100644 inlang/source-code/sdk-v2/src/lint/import.ts create mode 100644 inlang/source-code/sdk-v2/src/lint/populateLintLevel.ts create mode 100644 inlang/source-code/sdk-v2/src/loadProjectOpfs.ts create mode 100644 inlang/source-code/sdk-v2/src/mock/mockdata.ts create mode 100644 inlang/source-code/sdk-v2/src/mock/mockhelper.ts create mode 100644 inlang/source-code/sdk-v2/src/newProjectOpfs.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/cache.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/errors.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/import.test.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/import.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/index.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/message-lint-rules/errors.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/plugins/errors.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/plugins/resolvePlugins.test.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/plugins/resolvePlugins.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/plugins/types.test.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/plugins/types.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/resolveModules.test.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/resolveModules.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/types.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/validateModuleSettings.test.ts create mode 100644 inlang/source-code/sdk-v2/src/resolve-modules/validatedModuleSettings.ts create mode 100644 inlang/source-code/sdk-v2/src/resolveMessageBundleLintRules.ts create mode 100644 inlang/source-code/sdk-v2/src/resolveModules2.test.ts create mode 100644 inlang/source-code/sdk-v2/src/resolveModules2.ts create mode 100644 inlang/source-code/sdk-v2/src/resolvePlugins2.ts create mode 100644 inlang/source-code/sdk-v2/src/settings.ts create mode 100644 inlang/source-code/sdk-v2/src/types/customApis/app.inlang.ideExtension.ts create mode 100644 inlang/source-code/sdk-v2/src/types/index.ts create mode 100644 inlang/source-code/sdk-v2/src/types/inlang-module.ts create mode 100644 inlang/source-code/sdk-v2/src/types/language-tag.ts create mode 100644 inlang/source-code/sdk-v2/src/types/lint-errors.ts create mode 100644 inlang/source-code/sdk-v2/src/types/lint.ts create mode 100644 inlang/source-code/sdk-v2/src/types/module-errors.ts create mode 100644 inlang/source-code/sdk-v2/src/types/module.ts create mode 100644 inlang/source-code/sdk-v2/src/types/plugin-errors.ts create mode 100644 inlang/source-code/sdk-v2/src/types/plugin.ts create mode 100644 inlang/source-code/sdk-v2/src/types/project-settings.ts create mode 100644 inlang/source-code/sdk-v2/src/types/project.ts create mode 100644 inlang/source-code/sdk-v2/src/types/schema.ts create mode 100644 inlang/source-code/sdk-v2/src/types/sdkTypes.ts create mode 100644 inlang/source-code/sdk-v2/src/validatedModuleSettings.ts create mode 100644 inlang/source-code/sdk-v2/src/x.ts create mode 100644 inlang/source-code/sdk-v2/tsconfig.json create mode 100644 inlang/source-code/sdk-v2/vitest.config.ts diff --git a/inlang/source-code/sdk-v2/.eslintrc.json b/inlang/source-code/sdk-v2/.eslintrc.json new file mode 100644 index 0000000000..2b51924587 --- /dev/null +++ b/inlang/source-code/sdk-v2/.eslintrc.json @@ -0,0 +1,21 @@ +{ + "overrides": [ + { + "files": ["**/*.ts"], + "excludedFiles": ["**/*.test.ts"], + "rules": { + "no-restricted-imports": [ + "error", + { + "patterns": [ + { + "group": ["node:*"], + "message": "Keep in mind that node API's don't work inside the browser" + } + ] + } + ] + } + } + ] +} diff --git a/inlang/source-code/sdk-v2/LICENSE b/inlang/source-code/sdk-v2/LICENSE new file mode 100644 index 0000000000..ecc0047717 --- /dev/null +++ b/inlang/source-code/sdk-v2/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [2024] [Opral US Inc.] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/inlang/source-code/sdk-v2/README.md b/inlang/source-code/sdk-v2/README.md new file mode 100644 index 0000000000..259198566e --- /dev/null +++ b/inlang/source-code/sdk-v2/README.md @@ -0,0 +1,16 @@ +Developer-first localization infrastructure that is built on lix. Your lix is the single source of truth for localization for collaboration and automation. + +
+

+ +

+

+ + Discussions · Twitter +

+
+ +# @inlang/sdk + +The core module bundles "sdk" modules that depend on each other and is everything one needs to build [plugins](https://inlang.com/documentation/plugin) or entire [apps](https://inlang.com/documentation/build-app) on inlang. diff --git a/inlang/source-code/sdk-v2/package.json b/inlang/source-code/sdk-v2/package.json new file mode 100644 index 0000000000..a3379542a7 --- /dev/null +++ b/inlang/source-code/sdk-v2/package.json @@ -0,0 +1,64 @@ +{ + "name": "@inlang/sdk-v2", + "type": "module", + "version": "0.0.1", + "license": "Apache-2.0", + "publishConfig": { + "access": "public" + }, + "homepage": "https://inlang.com/documentation/sdk", + "repository": { + "type": "git", + "url": "https://github.com/opral/inlang-message-sdk" + }, + "exports": { + ".": "./dist/index.js", + "./test-utilities": "./dist/test-utilities/index.js", + "./lint": "./dist/lint/index.js" + }, + "files": [ + "./dist", + "./src" + ], + "scripts": { + "build": "npm run prepare-env-variables && tsc --build", + "dev": "npm run prepare-env-variables && tsc --watch", + "prepare-env-variables": "node ./src/env-variables/createIndexFile.js", + "test": "npm run prepare-env-variables && tsc --noEmit && vitest run --passWithNoTests --coverage", + "lint": "eslint ./src --fix", + "format": "prettier ./src --write", + "clean": "rm -rf ./dist ./node_modules" + }, + "engines": { + "node": ">=18.0.0" + }, + "dependencies": { + "@inlang/result": "workspace:*", + "@inlang/module": "workspace:*", + "@inlang/json-types": "workspace:*", + "@inlang/translatable": "workspace:*", + "@inlang/plugin": "workspace:*", + "@sqlite.org/sqlite-wasm": "^3.46.0-build2", + "deepmerge-ts": "^5.1.0", + "kysely": "^0.27.4", + "sqlocal": "^0.10.1", + "rxjs": "7.8.1", + "@sinclair/typebox": "^0.31.17", + "uuid": "^10.0.0", + "murmurhash3js": "^3.0.1" + }, + "devDependencies": { + "@types/debug": "^4.1.12", + "@types/murmurhash3js": "^3.0.7", + "@types/throttle-debounce": "5.0.0", + "@types/uuid": "^9.0.8", + "@vitest/coverage-v8": "^0.33.0", + "@vitest/web-worker": "^1.6.0", + "jsdom": "22.1.0", + "patch-package": "6.5.1", + "tsd": "^0.25.0", + "typescript": "^5.5.2", + "vite": "^5.3.2", + "vitest": "^0.33.0" + } +} diff --git a/inlang/source-code/sdk-v2/sample-app/.gitignore b/inlang/source-code/sdk-v2/sample-app/.gitignore new file mode 100644 index 0000000000..ac43eed893 --- /dev/null +++ b/inlang/source-code/sdk-v2/sample-app/.gitignore @@ -0,0 +1,26 @@ +rxdb-local.tgz + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/inlang/source-code/sdk-v2/sample-app/README.md b/inlang/source-code/sdk-v2/sample-app/README.md new file mode 100644 index 0000000000..ad7730d68d --- /dev/null +++ b/inlang/source-code/sdk-v2/sample-app/README.md @@ -0,0 +1,10 @@ +# Slot storage, git, RxDB in Vite Typescript Demo + +This is a quick crud app that showcases the slot file with query capabilities of rxdb + +# Try it out +1. replace the github token in src/storage/db.ts +2. create a repo you have access to and and set the repo url in src/storage/db.ts +3. run `pnpm install` +4. run `pnpm run proxy` to start the cors proxy localy +5. run `pnpm run dev` to start the app diff --git a/inlang/source-code/sdk-v2/sample-app/index.html b/inlang/source-code/sdk-v2/sample-app/index.html new file mode 100644 index 0000000000..5d93aee715 --- /dev/null +++ b/inlang/source-code/sdk-v2/sample-app/index.html @@ -0,0 +1,96 @@ + + + + + + + + + + Message Format + rxdb + Slotstorage + lix + + +
+ + + diff --git a/inlang/source-code/sdk-v2/sample-app/package.json b/inlang/source-code/sdk-v2/sample-app/package.json new file mode 100644 index 0000000000..dc356ab546 --- /dev/null +++ b/inlang/source-code/sdk-v2/sample-app/package.json @@ -0,0 +1,40 @@ +{ + "name": "inlang-sdk-v2-sampleapp", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "preview": "vite preview", + "test": "pnpm run build && concurrently \"pnpm run preview\" \"pnpm run test:e2e\" --kill-others --success first", + "proxy": "node ./proxy/index.js" + }, + "devDependencies": { + "@types/react": "^18.3.3", + "@types/react-dom": "^18.3.0", + "async-test-util": "2.5.0", + "concurrently": "8.2.2", + "copyfiles": "2.4.1", + "testcafe": "3.6.0", + "typescript": "5.4.5", + "vite": "5.2.12", + "vite-plugin-top-level-await": "1.4.1" + }, + "dependencies": { + "process": "^0.11.10", + "express": "^4.19.2", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "react-window": "^1.8.10", + "@lit/react": "^1.0.5", + "vite-plugin-node-polyfills": "0.17.0", + "@esbuild-plugins/node-globals-polyfill": "^0.2.3", + "@esbuild-plugins/node-modules-polyfill": "^0.2.2", + "comlink": "^4.4.1", + "@types/react-dom": "^18.3.0", + "@inlang/sdk-v2": "workspace:*", + "@inlang/message-bundle-component": "workspace:*", + "@inlang/settings-component": "workspace:*" + } +} diff --git a/inlang/source-code/sdk-v2/sample-app/src/MessageBundleView.tsx b/inlang/source-code/sdk-v2/sample-app/src/MessageBundleView.tsx new file mode 100644 index 0000000000..b9719cb936 --- /dev/null +++ b/inlang/source-code/sdk-v2/sample-app/src/MessageBundleView.tsx @@ -0,0 +1,81 @@ +import React, { useEffect, useState } from "react" +import { createComponent } from "@lit/react" +import { InlangMessageBundle } from "@inlang/message-bundle-component" +import { BundleWithMessages } from "../../src/types/sdkTypes.js" +import { ProjectSettings2 } from "../../src/types/project-settings.js" +import { InlangProject } from "../../src/types/project.js" +import { LintReport } from "../../src/types/lint.js" +import { LanguageTag } from "../../src/types/language-tag.js" + +export const MessageBundleComponent = createComponent({ + tagName: "inlang-message-bundle", + elementClass: InlangMessageBundle, + react: React, + events: { + changeMessageBundle: "change-message-bundle", + fixLint: "fix-lint", + }, +}) +type MessageBundleViewProps = { + bundle: BundleWithMessages // TODO SDK2 make SDK Bundle a reactive query that delivers the bundle instead + // reports: Subject + projectSettings: ProjectSettings2 + project: InlangProject + filteredLocales: LanguageTag[] +} +function MessageBundleView({ + bundle, + // reports, + projectSettings, + project, + filteredLocales, +}: MessageBundleViewProps) { + const [currentBundle, setBundle] = useState(bundle) + + console.log("render MessageBundle View") + useEffect(() => { + // Assume bundle$ is an RxJS Subject or Observable + // const subscription = bundle.$.subscribe((updatedBundle) => { + // console.log("updateing Bundle from subscribe", updatedBundle) + // // Handle the bundle update + // setBundle(updatedBundle) + // }) + // return () => { + // // Clean up the subscription when the component unmounts or when bundle changes + // subscription.unsubscribe() + // } + }, [bundle]) + + const onBundleChange = (messageBundle: { detail: { argument: BundleWithMessages } }) => { + // eslint-disable-next-line no-console + // TODO SDK-V2 check how we update the bundle in v2 sql + // project.messageBundleCollection?.upsert(messageBundle.detail.argument) + } + + return ( + 0 ? filteredLocales : undefined} + fixLint={(e: any) => { + const { fix, lintReport } = e.detail.argument as { + fix: string + lintReport: LintReport + } + + project.fix(lintReport, { title: fix }) + }} + /> + ) +} +// Custom comparison function to compare the logical contents of the bundle +const areEqual = (prevProps: MessageBundleViewProps, nextProps: MessageBundleViewProps) => { + console.log("check") + // Assuming bundle has an id property to identify the logical record + return ( + prevProps.bundle.id === nextProps.bundle.id && true // deepEqual(prevProps.filteredLocales, nextProps.filteredLocales) + ) +} +export const MessageBundleViewMemoed = React.memo(MessageBundleView, areEqual) diff --git a/inlang/source-code/sdk-v2/sample-app/src/PageView.tsx b/inlang/source-code/sdk-v2/sample-app/src/PageView.tsx new file mode 100644 index 0000000000..8ed3c093c1 --- /dev/null +++ b/inlang/source-code/sdk-v2/sample-app/src/PageView.tsx @@ -0,0 +1,95 @@ +import { useEffect, useState } from "react" +import { loadProjectOpfs, newProjectOpfs } from "../../src/index.js" +import { MainView } from "./mainView.js" + +const projectPath = "workingCopy.inlang" + +export function PageView() { + const [loadingProjectState, setLoadingProjectState] = useState("") + const [currentProject, setCurrentProject] = useState< + Awaited> | undefined + >(undefined) + + const newProject = async () => { + await newProjectOpfs({ + inlangFolderPath: projectPath, + }) + await loadProject() + } + + const loadProject = async () => { + setLoadingProjectState("Loading") + try { + const loadedProject = await loadProjectOpfs({ + inlangFolderPath: projectPath, + }) + setCurrentProject(loadedProject) + } catch (e) { + setLoadingProjectState((e as any).message) + return + } + + setLoadingProjectState("") + } + + return ( +
+

{"Fink 2"}

+
+ + +
+ {loadingProjectState} + {currentProject && ( + <> +
+
+ {/* + +
+
+ */} +
+
+ +
+ {/*
+