@aidc-toolkit/core 1.0.43-beta → 1.0.44
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/README.md +8 -9
- package/dist/browser-app-data-storage-G62WSQ5Z.js +1 -0
- package/dist/chunk-FIUBVWNN.js +1 -0
- package/dist/file-app-data-storage-M6RA7QOG.js +1 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +801 -0
- package/dist/index.d.ts +801 -30
- package/dist/index.js +2 -12
- package/package.json +2 -2
- package/src/locale/fr/locale-resources.ts +1 -1
- package/src/locale/i18n.ts +25 -45
- package/src/version.ts +4 -0
- package/tsconfig-src.tsbuildinfo +1 -1
- package/dist/app-data-storage.d.ts +0 -118
- package/dist/app-data-storage.d.ts.map +0 -1
- package/dist/app-data-storage.js +0 -117
- package/dist/app-data-storage.js.map +0 -1
- package/dist/app-data.d.ts +0 -26
- package/dist/app-data.d.ts.map +0 -1
- package/dist/app-data.js +0 -79
- package/dist/app-data.js.map +0 -1
- package/dist/browser-app-data-storage.d.ts +0 -26
- package/dist/browser-app-data-storage.d.ts.map +0 -1
- package/dist/browser-app-data-storage.js +0 -34
- package/dist/browser-app-data-storage.js.map +0 -1
- package/dist/cache.d.ts +0 -58
- package/dist/cache.d.ts.map +0 -1
- package/dist/cache.js +0 -12
- package/dist/cache.js.map +0 -1
- package/dist/file-app-data-storage.d.ts +0 -27
- package/dist/file-app-data-storage.d.ts.map +0 -1
- package/dist/file-app-data-storage.js +0 -52
- package/dist/file-app-data-storage.js.map +0 -1
- package/dist/http-fetch.d.ts +0 -45
- package/dist/http-fetch.d.ts.map +0 -1
- package/dist/http-fetch.js +0 -26
- package/dist/http-fetch.js.map +0 -1
- package/dist/hyperlink.d.ts +0 -18
- package/dist/hyperlink.d.ts.map +0 -1
- package/dist/hyperlink.js +0 -2
- package/dist/hyperlink.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/local-app-data-storage.d.ts +0 -8
- package/dist/local-app-data-storage.d.ts.map +0 -1
- package/dist/local-app-data-storage.js +0 -11
- package/dist/local-app-data-storage.js.map +0 -1
- package/dist/locale/en/locale-resources.d.ts +0 -10
- package/dist/locale/en/locale-resources.d.ts.map +0 -1
- package/dist/locale/en/locale-resources.js +0 -9
- package/dist/locale/en/locale-resources.js.map +0 -1
- package/dist/locale/fr/locale-resources.d.ts +0 -10
- package/dist/locale/fr/locale-resources.d.ts.map +0 -1
- package/dist/locale/fr/locale-resources.js +0 -9
- package/dist/locale/fr/locale-resources.js.map +0 -1
- package/dist/locale/i18n.d.ts +0 -83
- package/dist/locale/i18n.d.ts.map +0 -1
- package/dist/locale/i18n.js +0 -157
- package/dist/locale/i18n.js.map +0 -1
- package/dist/logger.d.ts +0 -136
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -256
- package/dist/logger.js.map +0 -1
- package/dist/parse-version.d.ts +0 -36
- package/dist/parse-version.d.ts.map +0 -1
- package/dist/parse-version.js +0 -23
- package/dist/parse-version.js.map +0 -1
- package/dist/remote-app-data-storage.d.ts +0 -23
- package/dist/remote-app-data-storage.d.ts.map +0 -1
- package/dist/remote-app-data-storage.js +0 -42
- package/dist/remote-app-data-storage.js.map +0 -1
- package/dist/type-helper.d.ts +0 -115
- package/dist/type-helper.d.ts.map +0 -1
- package/dist/type-helper.js +0 -163
- package/dist/type-helper.js.map +0 -1
- package/dist/type.d.ts +0 -111
- package/dist/type.d.ts.map +0 -1
- package/dist/type.js +0 -2
- package/dist/type.js.map +0 -1
- package/dist/website-url.d.ts +0 -29
- package/dist/website-url.d.ts.map +0 -1
- package/dist/website-url.js +0 -60
- package/dist/website-url.js.map +0 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ All AIDC Toolkit packages require internationalization. The localization functio
|
|
|
37
37
|
Packages initialize their resources as follows in `i18n.ts` or similar. Note that "dependency1" and "dependency2" are placeholders for the names of the packages on which the package depends, and "package" is the package itself.
|
|
38
38
|
|
|
39
39
|
```typescript
|
|
40
|
-
import { i18nCoreInit, type
|
|
40
|
+
import { i18nCoreInit, i18nInit, type I18nLanguageDetector } from "@aidc-toolkit/core";
|
|
41
41
|
import { i18nDependency1Init } from "@aidc-toolkit/dependency1";
|
|
42
42
|
import { i18nDependency2Init } from "@aidc-toolkit/dependency2";
|
|
43
43
|
import i18next, { type i18n, type Resource } from "i18next";
|
|
@@ -69,8 +69,8 @@ export const i18nextPackage: i18n = i18next.createInstance();
|
|
|
69
69
|
/**
|
|
70
70
|
* Initialize internationalization.
|
|
71
71
|
*
|
|
72
|
-
* @param
|
|
73
|
-
*
|
|
72
|
+
* @param languageDetector
|
|
73
|
+
* Language detector.
|
|
74
74
|
*
|
|
75
75
|
* @param debug
|
|
76
76
|
* Debug setting.
|
|
@@ -78,8 +78,8 @@ export const i18nextPackage: i18n = i18next.createInstance();
|
|
|
78
78
|
* @returns
|
|
79
79
|
* Package resource bundle.
|
|
80
80
|
*/
|
|
81
|
-
export async function i18nPackageInit(
|
|
82
|
-
return i18nInit(i18nextPackage,
|
|
81
|
+
export async function i18nPackageInit(languageDetector: I18nLanguageDetector, debug = false): Promise<Resource> {
|
|
82
|
+
return i18nInit(i18nextPackage, languageDetector, debug, packageNS, packageResourceBundle, i18nCoreInit, i18nDependency2Init, i18nDependency1Init);
|
|
83
83
|
}
|
|
84
84
|
```
|
|
85
85
|
|
|
@@ -119,7 +119,6 @@ Language detection is available for the following environments:
|
|
|
119
119
|
- [Command-line interface](#command-line-interface)
|
|
120
120
|
- Unit tests
|
|
121
121
|
- Command-line or helper applications
|
|
122
|
-
- Web server - **NOT YET IMPLEMENTED**
|
|
123
122
|
- [Web browser](#web-browser)
|
|
124
123
|
|
|
125
124
|
When a package's `i18next` object is initialized:
|
|
@@ -139,7 +138,7 @@ Language detection is implemented using [I18nextCLILanguageDetector](https://git
|
|
|
139
138
|
Initializing internationalization for a command-line interface application is straightforward:
|
|
140
139
|
|
|
141
140
|
```typescript
|
|
142
|
-
await i18nPackageInit(
|
|
141
|
+
await i18nPackageInit(I18nLanguageDetectors.CLI);
|
|
143
142
|
```
|
|
144
143
|
|
|
145
144
|
#### Web Browser
|
|
@@ -149,13 +148,13 @@ Language detection is implemented using [I18nextBrowserLanguageDetector](https:/
|
|
|
149
148
|
Initializing internationalization for a web browser requires awaiting the fulfillment of the `Promise` returned by the call to the initialization function before rendering any content. For example, in the React framework, this would be done before creating the root:
|
|
150
149
|
|
|
151
150
|
```typescript jsx
|
|
152
|
-
import {
|
|
151
|
+
import { I18nLanguageDetectors } from "@aidc-toolkit/core";
|
|
153
152
|
import { StrictMode } from "react";
|
|
154
153
|
import { createRoot } from "react-dom/client";
|
|
155
154
|
import { App } from "./App.jsx";
|
|
156
155
|
import { i18nPackageInit, i18nextPackage } from "./locale/i18n.js";
|
|
157
156
|
|
|
158
|
-
i18nPackageInit(
|
|
157
|
+
i18nPackageInit(I18nLanguageDetectors.Browser).then(() => {
|
|
159
158
|
// Set the page title.
|
|
160
159
|
document.title = i18nextPackage.t("App.title");
|
|
161
160
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as t}from"./chunk-FIUBVWNN.js";var r=class extends t{constructor(e){super(!1,e)}doRead(e){return localStorage.getItem(e)??void 0}doWrite(e,o){localStorage.setItem(e,o)}doDelete(e){localStorage.removeItem(e)}};export{r as BrowserAppDataStorage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{fromByteArray as f,toByteArray as b}from"base64-js";function p(n){let t;try{t=JSON.parse(n,(r,e)=>{let i=e;if(typeof e=="string"){let s=/^(?<type>\w+):(?<data>.*)$/u.exec(e)?.groups;if(s!==void 0){let u=s.type,a=s.data;switch(u){case"dateTime":i=new Date(a);break;case"binary":i=b(a);break}}}return i})}catch{t=void 0}return t}function d(n){let t;return n instanceof Date?t=`dateTime:${n.toISOString()}`:n instanceof Uint8Array?t=`binary:${f(n)}`:t=Object.fromEntries(Object.entries(n).map(([r,e])=>[r,typeof e=="object"&&e!==null?d(e):e])),t}function c(n){return JSON.stringify(typeof n!="object"?n:d(n))}var o=class n{static BINARY_EXTENSION=".bin";static JSON_EXTENSION=".json";#t;#e;constructor(t,r){this.#t=t,this.#e=r!==void 0?`${r}/`:""}get supportsBinary(){return this.#t}get path(){return this.#e}fullKey(t,r){let e=`${this.path}${t}`;return this.supportsBinary?`${e}${r?n.BINARY_EXTENSION:n.JSON_EXTENSION}`:e}async read(t,r){let e=await this.doRead(this.fullKey(t,r===!0),r);return typeof e=="string"?p(e):e}},y=class extends o{async write(t,r){let e=r instanceof Uint8Array;await this.doWrite(this.fullKey(t,e),this.supportsBinary&&e?r:c(r))}async delete(t,r){await this.doDelete(this.fullKey(t,r===!0))}};export{p as a,c as b,o as c,y as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as s}from"./chunk-FIUBVWNN.js";import*as r from"fs";import*as o from"path";var n=class extends s{#e;constructor(e){super(!0,e),this.#e=r?.promises?.readFile===void 0}async doRead(e,i){return this.#e?void 0:r.promises.readFile(e).then(t=>i===!0?t:t.toString()).catch(()=>{})}async doWrite(e,i){return this.#e?void 0:r.promises.mkdir(o.dirname(e),{recursive:!0}).then(async()=>r.promises.writeFile(e,i))}async doDelete(e){return this.#e?void 0:r.promises.rm(e,{force:!0})}};export{n as FileAppDataStorage};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";var ce=Object.create;var T=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var h=(t,e)=>()=>(t&&(e=t(t=0)),e);var w=(t,e)=>{for(var r in e)T(t,r,{get:e[r],enumerable:!0})},_=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of pe(e))!le.call(t,o)&&o!==r&&T(t,o,{get:()=>e[o],enumerable:!(n=de(e,o))||n.enumerable});return t};var y=(t,e,r)=>(r=t!=null?ce(ue(t)):{},_(e||!t||!t.__esModule?T(r,"default",{value:t,enumerable:!0}):r,t)),fe=t=>_(T({},"__esModule",{value:!0}),t);function R(t){let e;try{e=JSON.parse(t,(r,n)=>{let o=n;if(typeof n=="string"){let i=/^(?<type>\w+):(?<data>.*)$/u.exec(n)?.groups;if(i!==void 0){let s=i.type,g=i.data;switch(s){case"dateTime":o=new Date(g);break;case"binary":o=(0,L.toByteArray)(g);break}}}return o})}catch{e=void 0}return e}function Q(t){let e;return t instanceof Date?e=`dateTime:${t.toISOString()}`:t instanceof Uint8Array?e=`binary:${(0,L.fromByteArray)(t)}`:e=Object.fromEntries(Object.entries(t).map(([r,n])=>[r,typeof n=="object"&&n!==null?Q(n):n])),e}function N(t){return JSON.stringify(typeof t!="object"?t:Q(t))}var L,S=h(()=>{"use strict";L=require("base64-js")});var l,p,b=h(()=>{"use strict";S();l=class t{static BINARY_EXTENSION=".bin";static JSON_EXTENSION=".json";#e;#t;constructor(e,r){this.#e=e,this.#t=r!==void 0?`${r}/`:""}get supportsBinary(){return this.#e}get path(){return this.#t}fullKey(e,r){let n=`${this.path}${e}`;return this.supportsBinary?`${n}${r?t.BINARY_EXTENSION:t.JSON_EXTENSION}`:n}async read(e,r){let n=await this.doRead(this.fullKey(e,r===!0),r);return typeof n=="string"?R(n):n}},p=class extends l{async write(e,r){let n=r instanceof Uint8Array;await this.doWrite(this.fullKey(e,n),this.supportsBinary&&n?r:N(r))}async delete(e,r){await this.doDelete(this.fullKey(e,r===!0))}}});var ee={};w(ee,{FileAppDataStorage:()=>O});var f,Z,O,te=h(()=>{"use strict";f=y(require("fs"),1),Z=y(require("path"),1);b();O=class extends p{#e;constructor(e){super(!0,e),this.#e=f?.promises?.readFile===void 0}async doRead(e,r){return this.#e?void 0:f.promises.readFile(e).then(n=>r===!0?n:n.toString()).catch(()=>{})}async doWrite(e,r){return this.#e?void 0:f.promises.mkdir(Z.dirname(e),{recursive:!0}).then(async()=>f.promises.writeFile(e,r))}async doDelete(e){return this.#e?void 0:f.promises.rm(e,{force:!0})}}});var re={};w(re,{BrowserAppDataStorage:()=>j});var j,ne=h(()=>{"use strict";b();j=class extends p{constructor(e){super(!1,e)}doRead(e){return localStorage.getItem(e)??void 0}doWrite(e,r){localStorage.setItem(e,r)}doDelete(e){localStorage.removeItem(e)}}});var Re={};w(Re,{ALPHA_URL:()=>ke,AppDataStorage:()=>p,Cache:()=>B,HTTP_NOT_FOUND:()=>se,HTTP_OK:()=>Je,I18nLanguageDetectors:()=>Te,LocalAppDataStorage:()=>I,LogLevels:()=>u,MemoryTransport:()=>k,ReadOnlyAppDataStorage:()=>l,RemoteAppDataStorage:()=>K,WEBSITE_BASE_URL:()=>oe,coreNS:()=>J,coreResourceBundle:()=>X,decodeAppData:()=>R,defaultHTTPFetch:()=>E,encodeAppData:()=>N,exclude:()=>ge,getLogger:()=>Le,i18nCoreInit:()=>xe,i18nInit:()=>z,i18nextCore:()=>d,include:()=>me,isNullish:()=>be,logLevelOf:()=>q,loggableValue:()=>x,omit:()=>$,parseVersion:()=>A,pick:()=>U,propertyAs:()=>ye,websiteURL:()=>Ae});module.exports=fe(Re);function C(t,e,...r){return Object.fromEntries(Object.entries(e).filter(([n])=>r.includes(n)!==t))}function $(t,...e){return C(!0,t,...e)}function U(t,...e){return C(!1,t,...e)}function ge(t,e){return $(t,...Object.keys(e))}function me(t,e){return U(t,...Object.keys(e))}function ye(t,e){return e in t?{[e]:t[e]}:{}}function be(t){return t==null}var Y=require("tslog");var M=y(require("i18next"),1),W=y(require("i18next-browser-languagedetector"),1),G=y(require("i18next-cli-language-detector"),1);var F={Logger:{unknownLogLevel:'Unknown log level "{{logLevel}}"'},RemoteAppDataStorage:{httpError:"HTTP error {{status, number}} retrieving file"}};var H={Logger:{unknownLogLevel:"Niveau de journalisation inconnu \xAB\xA0{{logLevel}}\xA0\xBB"},RemoteAppDataStorage:{httpError:"Erreur HTTP {{status, number}} lors de la r\xE9cup\xE9ration du fichier"}};var Te={CLI:G.default,Browser:W.default};function he(t){return typeof t=="string"?t.split(" ").map(e=>/[a-z]/u.test(e)?e.toLowerCase():e).join(" "):String(t)}var J="aidct_core",X={en:{aidct_core:F},fr:{aidct_core:H}},d=M.default.createInstance();async function z(t,e,r,n,o,...i){let s;if(!t.isInitialized){let m=function(P){for(let[c,ie]of Object.entries(P)){c in a||(a[c]={});let V=a[c];for(let[D,ae]of Object.entries(ie)){if(D in V)throw new Error(`Duplicate namespace ${D} in merged resource bundle for language ${c}`);V[D]=ae}}};var g=m;let a={};m(o);for(let P of i){let c=P(e,r).then(m);s=s===void 0?c:s.then(async()=>c)}let v=t.use(e).init({debug:r,defaultNS:n,resources:a,nonExplicitSupportedLngs:!0,fallbackLng:Object.keys(a)[0],detection:{caches:[]}}).then(()=>{t.services.formatter?.add("toLowerCase",he)});s=s===void 0?v:s.then(async()=>v)}return s!==void 0?s.then(()=>o):o}async function xe(t,e=!1){return z(d,t,e,J,X)}var u={Silly:0,Trace:1,Debug:2,Info:3,Warn:4,Error:5,Fatal:6};function q(t){let e;if(typeof t=="string")if(t in u)e=u[t];else throw new RangeError(d.t("Logger.unknownLogLevel",{logLevel:t}));else if(t!==void 0)if(Object.values(u).includes(t))e=t;else throw new RangeError(d.t("Logger.unknownLogLevel",{logLevel:t}));else e=u.Info;return e}function Le(t,e,r){let n=q(t);return new Y.Logger({hideLogPositionForProduction:n>=u.Info,...e??{},minLevel:n},r)}function x(t){let e;switch(typeof t){case"string":case"number":case"boolean":case"undefined":e=t;break;case"bigint":e=t>=Number.MIN_SAFE_INTEGER&&t<=Number.MAX_SAFE_INTEGER?Number(t):t.toString(10);break;case"object":t===null?e=t:Array.isArray(t)?e=(t.length<=10?t:[...t.slice(0,4),"...",...t.slice(-4)]).map(r=>x(r)):t instanceof Error?e=x({name:t.name,message:t.message,stack:t.stack?.split(`
|
|
2
|
+
`)}):e=Object.fromEntries(Object.entries(t).map(([r,n])=>[r,x(n)]));break;case"symbol":e=t.toString();break;case"function":e=`Function(${t.name})`;break}return e}var k=class{#e=new Map;#t=[];#r=0;#n=0;constructor(e,r,n){this.resize(r,n),e.attachTransport(o=>{this.#t.length>=this.#r&&this.#t.splice(0,this.#r-this.#n);let i=JSON.stringify(o);this.#t.push(i);for(let s of this.#e.values())s(i,this.#t)})}get messages(){return this.#t}get maximumLength(){return this.#r}get truncateLength(){return this.#n}addNotificationCallback(e,r){let n=!this.#e.has(e);return n&&(this.#e.set(e,r),r(void 0,this.#t)),n}removeNotificationCallback(e){this.#e.delete(e)}resize(e,r){this.#r=e,this.#n=r!==void 0?Math.min(r,Math.floor(e*.8)):Math.floor(e/2)}};function A(t){let e=/^(?<majorVersion>\d+)\.(?<minorVersion>\d+)\.(?<patchVersion>\d+)(?:-(?<preReleaseIdentifier>alpha|beta)(?:\.(?<dateTime>\d{12}))?)?$/u.exec(t)?.groups;if(e===void 0)throw new Error(`Invalid package version ${t}`);return{majorVersion:Number(e.majorVersion),minorVersion:Number(e.minorVersion),patchVersion:Number(e.patchVersion),preReleaseIdentifier:e.preReleaseIdentifier,dateTime:e.dateTime}}var I=globalThis.localStorage===void 0?Promise.resolve().then(()=>(te(),ee)).then(t=>t.FileAppDataStorage):Promise.resolve().then(()=>(ne(),re)).then(t=>t.BrowserAppDataStorage);var Pe="http://localhost:5173",De="config",we="resources.local",ke=I.then(async t=>new t(De).read(we)).then(t=>t?.alphaURL??Pe),oe="https://aidc-toolkit.com";function Ae(t,e,r,n){let o=A(t),i=o.preReleaseIdentifier,s;if(i==="alpha")s=r;else{let g=i!==void 0?`/${i}`:"",a=i!==void 0||e?`/v${o.majorVersion}.${o.minorVersion}`:"",m=n!==void 0&&n!==""?`/${n}`:"";s=`${oe}${g}${a}${m}`}return s}S();b();var Je=200,se=404;async function E(t){return fetch(t).then(e=>({ok:e.ok,status:e.status,arrayBuffer:async()=>e.arrayBuffer(),text:async()=>e.text()}))}b();var K=class extends l{#e;constructor(e,r=E){super(!0,e),this.#e=r}async doRead(e,r){let n=await this.#e(e),o;if(n.ok)o=r===!0?new Uint8Array(await n.arrayBuffer()):await n.text();else if(n.status===404)o=void 0;else throw new RangeError(d.t("RemoteAppDataStorage.httpError",{status:n.status}));return o}};var B=class{};0&&(module.exports={ALPHA_URL,AppDataStorage,Cache,HTTP_NOT_FOUND,HTTP_OK,I18nLanguageDetectors,LocalAppDataStorage,LogLevels,MemoryTransport,ReadOnlyAppDataStorage,RemoteAppDataStorage,WEBSITE_BASE_URL,coreNS,coreResourceBundle,decodeAppData,defaultHTTPFetch,encodeAppData,exclude,getLogger,i18nCoreInit,i18nInit,i18nextCore,include,isNullish,logLevelOf,loggableValue,omit,parseVersion,pick,propertyAs,websiteURL});
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright © 2024-2026 Dolphin Data Development Ltd. and AIDC Toolkit
|
|
5
|
+
* contributors
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|